aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaroslav Kysela <perex@suse.cz>2006-03-22 05:02:08 -0500
committerJaroslav Kysela <perex@suse.cz>2006-03-22 05:02:08 -0500
commit5501972e0b5857bc8354770d900ceb9b40c7f6b7 (patch)
treeff239422827c4cd54d2998f8851304255de31b38
parent9d2f928ddf64ca0361562e30faf584cd33055c60 (diff)
parente952f31bce6e9f64db01f607abc46529ba57ac9e (diff)
Merge with rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
-rw-r--r--.gitignore2
-rw-r--r--CREDITS2
-rw-r--r--Documentation/Changes18
-rw-r--r--Documentation/connector/connector.txt5
-rw-r--r--Documentation/dvb/avermedia.txt10
-rw-r--r--Documentation/dvb/bt8xx.txt140
-rw-r--r--Documentation/dvb/get_dvb_firmware23
-rw-r--r--Documentation/dvb/readme.txt32
-rw-r--r--Documentation/feature-removal-schedule.txt18
-rw-r--r--Documentation/networking/e100.txt158
-rw-r--r--Documentation/networking/e1000.txt620
-rw-r--r--Documentation/networking/ip-sysctl.txt49
-rw-r--r--Documentation/usb/et61x251.txt10
-rw-r--r--Documentation/usb/sn9c102.txt11
-rw-r--r--Documentation/usb/zc0301.txt254
-rw-r--r--Documentation/video4linux/CARDLIST.cx882
-rw-r--r--Documentation/video4linux/CARDLIST.em28xx1
-rw-r--r--Documentation/video4linux/CARDLIST.saa71349
-rw-r--r--Documentation/video4linux/CARDLIST.tuner6
-rw-r--r--Documentation/video4linux/README.cpia2130
-rw-r--r--Documentation/video4linux/cpia2_overview.txt38
-rw-r--r--MAINTAINERS30
-rw-r--r--README2
-rw-r--r--arch/arm/common/locomo.c2
-rw-r--r--arch/arm/common/sa1111.c2
-rw-r--r--arch/arm/mach-realview/core.c28
-rw-r--r--arch/i386/defconfig1172
-rw-r--r--arch/ia64/Kconfig19
-rw-r--r--arch/ia64/configs/tiger_defconfig2
-rw-r--r--arch/ia64/kernel/acpi.c14
-rw-r--r--arch/ia64/kernel/entry.S14
-rw-r--r--arch/ia64/kernel/iosapic.c6
-rw-r--r--arch/ia64/kernel/irq.c13
-rw-r--r--arch/ia64/kernel/mca.c90
-rw-r--r--arch/ia64/kernel/perfmon.c5
-rw-r--r--arch/ia64/kernel/signal.c101
-rw-r--r--arch/ia64/kernel/smpboot.c114
-rw-r--r--arch/ia64/kernel/time.c9
-rw-r--r--arch/ia64/kernel/topology.c2
-rw-r--r--arch/ia64/mm/contig.c4
-rw-r--r--arch/ia64/mm/discontig.c9
-rw-r--r--arch/ia64/sn/kernel/Makefile3
-rw-r--r--arch/ia64/sn/kernel/pio_phys.S71
-rw-r--r--arch/ia64/sn/kernel/setup.c6
-rw-r--r--arch/ia64/sn/kernel/sn2/sn2_smp.c21
-rw-r--r--arch/ia64/sn/kernel/xpc_channel.c102
-rw-r--r--arch/ia64/sn/kernel/xpc_main.c1
-rw-r--r--arch/ia64/sn/kernel/xpc_partition.c28
-rw-r--r--arch/ia64/sn/pci/tioce_provider.c326
-rw-r--r--arch/m68knommu/kernel/vmlinux.lds.S10
-rw-r--r--arch/mips/Kconfig6
-rw-r--r--arch/mips/Makefile231
-rw-r--r--arch/mips/au1000/common/cputable.c2
-rw-r--r--arch/mips/au1000/common/dbdma.c4
-rw-r--r--arch/mips/au1000/common/dma.c2
-rw-r--r--arch/mips/au1000/common/platform.c8
-rw-r--r--arch/mips/au1000/common/setup.c2
-rw-r--r--arch/mips/au1000/common/time.c2
-rw-r--r--arch/mips/cobalt/Kconfig7
-rw-r--r--arch/mips/cobalt/Makefile2
-rw-r--r--arch/mips/cobalt/console.c43
-rw-r--r--arch/mips/cobalt/setup.c13
-rw-r--r--arch/mips/configs/atlas_defconfig101
-rw-r--r--arch/mips/configs/bigsur_defconfig37
-rw-r--r--arch/mips/configs/capcella_defconfig54
-rw-r--r--arch/mips/configs/cobalt_defconfig78
-rw-r--r--arch/mips/configs/db1000_defconfig52
-rw-r--r--arch/mips/configs/db1100_defconfig52
-rw-r--r--arch/mips/configs/db1200_defconfig51
-rw-r--r--arch/mips/configs/db1500_defconfig99
-rw-r--r--arch/mips/configs/db1550_defconfig56
-rw-r--r--arch/mips/configs/ddb5476_defconfig35
-rw-r--r--arch/mips/configs/ddb5477_defconfig34
-rw-r--r--arch/mips/configs/decstation_defconfig33
-rw-r--r--arch/mips/configs/e55_defconfig50
-rw-r--r--arch/mips/configs/ev64120_defconfig34
-rw-r--r--arch/mips/configs/ev96100_defconfig30
-rw-r--r--arch/mips/configs/ip22_defconfig80
-rw-r--r--arch/mips/configs/ip27_defconfig42
-rw-r--r--arch/mips/configs/ip32_defconfig46
-rw-r--r--arch/mips/configs/it8172_defconfig32
-rw-r--r--arch/mips/configs/ivr_defconfig34
-rw-r--r--arch/mips/configs/jaguar-atx_defconfig26
-rw-r--r--arch/mips/configs/jmr3927_defconfig35
-rw-r--r--arch/mips/configs/lasat200_defconfig35
-rw-r--r--arch/mips/configs/malta_defconfig95
-rw-r--r--arch/mips/configs/mipssim_defconfig31
-rw-r--r--arch/mips/configs/mpc30x_defconfig53
-rw-r--r--arch/mips/configs/ocelot_3_defconfig64
-rw-r--r--arch/mips/configs/ocelot_c_defconfig35
-rw-r--r--arch/mips/configs/ocelot_defconfig30
-rw-r--r--arch/mips/configs/ocelot_g_defconfig35
-rw-r--r--arch/mips/configs/pb1100_defconfig52
-rw-r--r--arch/mips/configs/pb1500_defconfig56
-rw-r--r--arch/mips/configs/pb1550_defconfig56
-rw-r--r--arch/mips/configs/pnx8550-jbs_defconfig48
-rw-r--r--arch/mips/configs/pnx8550-v2pci_defconfig68
-rw-r--r--arch/mips/configs/qemu_defconfig16
-rw-r--r--arch/mips/configs/rbhma4500_defconfig58
-rw-r--r--arch/mips/configs/rm200_defconfig103
-rw-r--r--arch/mips/configs/sb1250-swarm_defconfig37
-rw-r--r--arch/mips/configs/sead_defconfig22
-rw-r--r--arch/mips/configs/tb0226_defconfig68
-rw-r--r--arch/mips/configs/tb0229_defconfig56
-rw-r--r--arch/mips/configs/tb0287_defconfig1105
-rw-r--r--arch/mips/configs/workpad_defconfig50
-rw-r--r--arch/mips/configs/yosemite_defconfig29
-rw-r--r--arch/mips/dec/prom/memory.c2
-rw-r--r--arch/mips/defconfig80
-rw-r--r--arch/mips/jazz/int-handler.S12
-rw-r--r--arch/mips/kernel/cpu-probe.c6
-rw-r--r--arch/mips/kernel/gdb-low.S2
-rw-r--r--arch/mips/kernel/linux32.c180
-rw-r--r--arch/mips/kernel/proc.c1
-rw-r--r--arch/mips/kernel/process.c16
-rw-r--r--arch/mips/kernel/setup.c11
-rw-r--r--arch/mips/kernel/signal-common.h10
-rw-r--r--arch/mips/kernel/signal.c6
-rw-r--r--arch/mips/kernel/signal32.c46
-rw-r--r--arch/mips/kernel/signal_n32.c5
-rw-r--r--arch/mips/kernel/syscall.c7
-rw-r--r--arch/mips/kernel/traps.c2
-rw-r--r--arch/mips/lasat/image/romscript.normal5
-rw-r--r--arch/mips/mips-boards/generic/mipsIRQ.S2
-rw-r--r--arch/mips/mips-boards/sim/sim_IRQ.c2
-rw-r--r--arch/mips/mips-boards/sim/sim_irq.S2
-rw-r--r--arch/mips/mips-boards/sim/sim_smp.c2
-rw-r--r--arch/mips/mm/Makefile2
-rw-r--r--arch/mips/mm/c-r3k.c18
-rw-r--r--arch/mips/mm/c-r4k.c1
-rw-r--r--arch/mips/mm/pg-r4k.c10
-rw-r--r--arch/mips/mm/sc-rm7k.c25
-rw-r--r--arch/mips/mm/tlb-andes.c259
-rw-r--r--arch/mips/mm/tlb-r4k.c5
-rw-r--r--arch/mips/mm/tlbex.c13
-rw-r--r--arch/mips/momentum/jaguar_atx/reset.c2
-rw-r--r--arch/mips/momentum/jaguar_atx/setup.c2
-rw-r--r--arch/mips/momentum/ocelot_3/reset.c2
-rw-r--r--arch/mips/momentum/ocelot_c/reset.c2
-rw-r--r--arch/mips/pci/fixup-vr4133.c2
-rw-r--r--arch/mips/pci/ops-ddb5477.c4
-rw-r--r--arch/mips/pci/ops-tx4938.c16
-rw-r--r--arch/mips/pci/pci-bcm1480.c2
-rw-r--r--arch/mips/pci/pci-bcm1480ht.c2
-rw-r--r--arch/mips/pci/pci-ip27.c12
-rw-r--r--arch/mips/philips/pnx8550/common/int.c2
-rw-r--r--arch/mips/qemu/Makefile2
-rw-r--r--arch/mips/qemu/q-smp.c48
-rw-r--r--arch/mips/sgi-ip27/ip27-memory.c4
-rw-r--r--arch/mips/sgi-ip32/ip32-setup.c2
-rw-r--r--arch/mips/tx4927/toshiba_rbtx4927/toshiba_rbtx4927_prom.c4
-rw-r--r--arch/mips/tx4938/toshiba_rbtx4938/setup.c2
-rw-r--r--arch/mips/vr41xx/common/bcu.c6
-rw-r--r--arch/v850/kernel/vmlinux.lds.S8
-rw-r--r--arch/x86_64/crypto/aes.c7
-rw-r--r--block/genhd.c31
-rw-r--r--crypto/aes.c7
-rw-r--r--crypto/api.c6
-rw-r--r--crypto/deflate.c3
-rw-r--r--crypto/des.c1
-rw-r--r--crypto/serpent.c1
-rw-r--r--crypto/tcrypt.h25
-rw-r--r--crypto/twofish.c21
-rw-r--r--drivers/atm/suni.c2
-rw-r--r--drivers/base/cpu.c2
-rw-r--r--drivers/base/firmware_class.c6
-rw-r--r--drivers/base/map.c21
-rw-r--r--drivers/base/platform.c4
-rw-r--r--drivers/block/ub.c245
-rw-r--r--drivers/char/Makefile2
-rw-r--r--drivers/char/drm/Kconfig4
-rw-r--r--drivers/char/ip2/Makefile8
-rw-r--r--drivers/char/ip2/ip2base.c (renamed from drivers/char/ip2.c)6
-rw-r--r--drivers/char/ip2/ip2main.c (renamed from drivers/char/ip2main.c)20
-rw-r--r--drivers/char/s3c2410-rtc.c4
-rw-r--r--drivers/char/snsc.h5
-rw-r--r--drivers/char/snsc_event.c32
-rw-r--r--drivers/char/watchdog/mpcore_wdt.c4
-rw-r--r--drivers/connector/connector.c7
-rw-r--r--drivers/crypto/padlock-aes.c6
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c9
-rw-r--r--drivers/i2c/busses/i2c-mpc.c5
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c4
-rw-r--r--drivers/ide/mips/au1xxx-ide.c5
-rw-r--r--drivers/infiniband/core/agent.c19
-rw-r--r--drivers/infiniband/core/cm.c42
-rw-r--r--drivers/infiniband/core/fmr_pool.c6
-rw-r--r--drivers/infiniband/core/mad.c195
-rw-r--r--drivers/infiniband/core/mad_priv.h16
-rw-r--r--drivers/infiniband/core/mad_rmpp.c148
-rw-r--r--drivers/infiniband/core/smi.h9
-rw-r--r--drivers/infiniband/core/sysfs.c36
-rw-r--r--drivers/infiniband/core/user_mad.c225
-rw-r--r--drivers/infiniband/core/uverbs.h5
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c202
-rw-r--r--drivers/infiniband/core/uverbs_main.c6
-rw-r--r--drivers/infiniband/core/verbs.c259
-rw-r--r--drivers/infiniband/hw/mthca/mthca_av.c33
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.c323
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.h14
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cq.c161
-rw-r--r--drivers/infiniband/hw/mthca/mthca_dev.h33
-rw-r--r--drivers/infiniband/hw/mthca/mthca_eq.c6
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mad.c17
-rw-r--r--drivers/infiniband/hw/mthca/mthca_main.c23
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mcg.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.c29
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.h10
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mr.c42
-rw-r--r--drivers/infiniband/hw/mthca/mthca_pd.c3
-rw-r--r--drivers/infiniband/hw/mthca/mthca_profile.c10
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c170
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.h53
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c448
-rw-r--r--drivers/infiniband/hw/mthca/mthca_srq.c43
-rw-r--r--drivers/infiniband/hw/mthca/mthca_user.h7
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib.h12
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c10
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c31
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c25
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_verbs.c2
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c85
-rw-r--r--drivers/media/common/Makefile1
-rw-r--r--drivers/media/common/ir-common.c519
-rw-r--r--drivers/media/common/ir-functions.c272
-rw-r--r--drivers/media/common/ir-keymaps.c1415
-rw-r--r--drivers/media/common/saa7146_core.c9
-rw-r--r--drivers/media/common/saa7146_fops.c24
-rw-r--r--drivers/media/common/saa7146_i2c.c4
-rw-r--r--drivers/media/common/saa7146_vbi.c2
-rw-r--r--drivers/media/common/saa7146_video.c30
-rw-r--r--drivers/media/dvb/b2c2/flexcop-common.h4
-rw-r--r--drivers/media/dvb/b2c2/flexcop-i2c.c6
-rw-r--r--drivers/media/dvb/bt8xx/bt878.c4
-rw-r--r--drivers/media/dvb/bt8xx/bt878.h4
-rw-r--r--drivers/media/dvb/bt8xx/dst.c14
-rw-r--r--drivers/media/dvb/bt8xx/dst_ca.c6
-rw-r--r--drivers/media/dvb/bt8xx/dst_common.h3
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.c45
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.h3
-rw-r--r--drivers/media/dvb/cinergyT2/cinergyT2.c51
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.c795
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.h36
-rw-r--r--drivers/media/dvb/dvb-core/dvb_demux.c104
-rw-r--r--drivers/media/dvb/dvb-core/dvb_demux.h4
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c21
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.h1
-rw-r--r--drivers/media/dvb/dvb-core/dvb_net.c14
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ringbuffer.c2
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ringbuffer.h1
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c4
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-common.c4
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.c4
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-init.c4
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-urb.c4
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb.h9
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x.c4
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.c4
-rw-r--r--drivers/media/dvb/frontends/Kconfig12
-rw-r--r--drivers/media/dvb/frontends/Makefile1
-rw-r--r--drivers/media/dvb/frontends/bcm3510.c9
-rw-r--r--drivers/media/dvb/frontends/bsbe1.h123
-rw-r--r--drivers/media/dvb/frontends/bsru6.h140
-rw-r--r--drivers/media/dvb/frontends/cx24110.c13
-rw-r--r--drivers/media/dvb/frontends/cx24110.h1
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.c61
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.h7
-rw-r--r--drivers/media/dvb/frontends/lnbp21.h139
-rw-r--r--drivers/media/dvb/frontends/tda1004x.c25
-rw-r--r--drivers/media/dvb/frontends/tda1004x.h3
-rw-r--r--drivers/media/dvb/frontends/zl10353.c311
-rw-r--r--drivers/media/dvb/frontends/zl10353.h43
-rw-r--r--drivers/media/dvb/frontends/zl10353_priv.h42
-rw-r--r--drivers/media/dvb/ttpci/av7110.c260
-rw-r--r--drivers/media/dvb/ttpci/av7110.h7
-rw-r--r--drivers/media/dvb/ttpci/av7110_hw.c40
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c11
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c4
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c136
-rw-r--r--drivers/media/dvb/ttpci/budget-patch.c99
-rw-r--r--drivers/media/dvb/ttpci/budget.c250
-rw-r--r--drivers/media/dvb/ttpci/budget.h4
-rw-r--r--drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c35
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusb_dec.c31
-rw-r--r--drivers/media/radio/miropcm20-rds-core.c11
-rw-r--r--drivers/media/radio/radio-aimslab.c20
-rw-r--r--drivers/media/radio/radio-aztech.c12
-rw-r--r--drivers/media/radio/radio-maestro.c11
-rw-r--r--drivers/media/radio/radio-maxiradio.c11
-rw-r--r--drivers/media/radio/radio-sf16fmi.c22
-rw-r--r--drivers/media/radio/radio-sf16fmr2.c22
-rw-r--r--drivers/media/radio/radio-typhoon.c12
-rw-r--r--drivers/media/radio/radio-zoltrix.c26
-rw-r--r--drivers/media/video/Kconfig54
-rw-r--r--drivers/media/video/Makefile15
-rw-r--r--drivers/media/video/arv.c16
-rw-r--r--drivers/media/video/bttv-cards.c16
-rw-r--r--drivers/media/video/bttv-driver.c48
-rw-r--r--drivers/media/video/bttv-input.c248
-rw-r--r--drivers/media/video/bttv-risc.c17
-rw-r--r--drivers/media/video/bw-qcam.c16
-rw-r--r--drivers/media/video/bw-qcam.h2
-rw-r--r--drivers/media/video/c-qcam.c19
-rw-r--r--drivers/media/video/cpia.c102
-rw-r--r--drivers/media/video/cpia.h5
-rw-r--r--drivers/media/video/cpia2/Kconfig9
-rw-r--r--drivers/media/video/cpia2/Makefile3
-rw-r--r--drivers/media/video/cpia2/cpia2.h497
-rw-r--r--drivers/media/video/cpia2/cpia2_core.c2525
-rw-r--r--drivers/media/video/cpia2/cpia2_registers.h476
-rw-r--r--drivers/media/video/cpia2/cpia2_usb.c907
-rw-r--r--drivers/media/video/cpia2/cpia2_v4l.c2079
-rw-r--r--drivers/media/video/cpia2/cpia2dev.h50
-rw-r--r--drivers/media/video/cpia2/cpia2patch.h233
-rw-r--r--drivers/media/video/cx25840/Kconfig9
-rw-r--r--drivers/media/video/cx25840/Makefile2
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c46
-rw-r--r--drivers/media/video/cx25840/cx25840-vbi.c6
-rw-r--r--drivers/media/video/cx25840/cx25840.h1
-rw-r--r--drivers/media/video/cx88/Kconfig11
-rw-r--r--drivers/media/video/cx88/Makefile1
-rw-r--r--drivers/media/video/cx88/cx88-alsa.c10
-rw-r--r--drivers/media/video/cx88/cx88-cards.c111
-rw-r--r--drivers/media/video/cx88/cx88-core.c9
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c108
-rw-r--r--drivers/media/video/cx88/cx88-input.c339
-rw-r--r--drivers/media/video/cx88/cx88-video.c57
-rw-r--r--drivers/media/video/cx88/cx88.h8
-rw-r--r--drivers/media/video/dpc7146.c58
-rw-r--r--drivers/media/video/em28xx/Kconfig1
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c72
-rw-r--r--drivers/media/video/em28xx/em28xx-i2c.c1
-rw-r--r--drivers/media/video/em28xx/em28xx-input.c85
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c1613
-rw-r--r--drivers/media/video/em28xx/em28xx.h9
-rw-r--r--drivers/media/video/hexium_gemini.c10
-rw-r--r--drivers/media/video/hexium_orion.c18
-rw-r--r--drivers/media/video/ir-kbd-i2c.c50
-rw-r--r--drivers/media/video/meye.c112
-rw-r--r--drivers/media/video/meye.h4
-rw-r--r--drivers/media/video/msp3400-driver.c76
-rw-r--r--drivers/media/video/msp3400-kthreads.c333
-rw-r--r--drivers/media/video/msp3400.h10
-rw-r--r--drivers/media/video/mxb.c150
-rw-r--r--drivers/media/video/mxb.h2
-rw-r--r--drivers/media/video/planb.c8
-rw-r--r--drivers/media/video/planb.h2
-rw-r--r--drivers/media/video/pms.c28
-rw-r--r--drivers/media/video/saa5246a.c10
-rw-r--r--drivers/media/video/saa5249.c10
-rw-r--r--drivers/media/video/saa7115.c107
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c9
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c294
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c31
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c182
-rw-r--r--drivers/media/video/saa7134/saa7134-empress.c8
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c507
-rw-r--r--drivers/media/video/saa7134/saa7134-oss.c46
-rw-r--r--drivers/media/video/saa7134/saa7134-tvaudio.c14
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c70
-rw-r--r--drivers/media/video/saa7134/saa7134.h16
-rw-r--r--drivers/media/video/tda8290.c8
-rw-r--r--drivers/media/video/tda9840.c3
-rw-r--r--drivers/media/video/tea6415c.c5
-rw-r--r--drivers/media/video/tea6420.c5
-rw-r--r--drivers/media/video/tuner-core.c69
-rw-r--r--drivers/media/video/tuner-simple.c166
-rw-r--r--drivers/media/video/tuner-types.c599
-rw-r--r--drivers/media/video/tvaudio.c26
-rw-r--r--drivers/media/video/tvp5150.c681
-rw-r--r--drivers/media/video/tvp5150_reg.h125
-rw-r--r--drivers/media/video/v4l2-common.c558
-rw-r--r--drivers/media/video/video-buf-dvb.c10
-rw-r--r--drivers/media/video/video-buf.c59
-rw-r--r--drivers/media/video/videodev.c22
-rw-r--r--drivers/media/video/vino.c33
-rw-r--r--drivers/mmc/pxamci.c2
-rw-r--r--drivers/net/8139too.c2
-rw-r--r--drivers/net/arm/am79c961a.c4
-rw-r--r--drivers/net/bnx2.c477
-rw-r--r--drivers/net/bnx2.h37
-rw-r--r--drivers/net/cassini.c40
-rw-r--r--drivers/net/cassini.h2
-rw-r--r--drivers/net/e1000/e1000_main.c2
-rw-r--r--drivers/net/fs_enet/mac-fcc.c2
-rw-r--r--drivers/net/fs_enet/mac-fec.c2
-rw-r--r--drivers/net/fs_enet/mac-scc.c2
-rw-r--r--drivers/net/gianfar.c4
-rw-r--r--drivers/net/irda/Kconfig8
-rw-r--r--drivers/net/irda/Makefile1
-rw-r--r--drivers/net/irda/donauboe.c2
-rw-r--r--drivers/net/irda/ep7211_ir.c11
-rw-r--r--drivers/net/irda/irda-usb.c5
-rw-r--r--drivers/net/irda/irtty-sir.c19
-rw-r--r--drivers/net/irda/nsc-ircc.c320
-rw-r--r--drivers/net/irda/nsc-ircc.h2
-rw-r--r--drivers/net/irda/sir_dongle.c19
-rw-r--r--drivers/net/irda/toim3232-sir.c375
-rw-r--r--drivers/net/irda/vlsi_ir.c2
-rw-r--r--drivers/net/mv643xx_eth.h18
-rw-r--r--drivers/net/pcnet32.c4143
-rw-r--r--drivers/net/ppp_generic.c4
-rw-r--r--drivers/net/pppoe.c3
-rw-r--r--drivers/net/skfp/fplustm.c12
-rw-r--r--drivers/net/skge.c275
-rw-r--r--drivers/net/skge.h1
-rw-r--r--drivers/net/sky2.c583
-rw-r--r--drivers/net/sky2.h22
-rw-r--r--drivers/net/smc91x.c57
-rw-r--r--drivers/net/smc91x.h474
-rw-r--r--drivers/net/sungem.c37
-rw-r--r--drivers/net/sungem.h6
-rw-r--r--drivers/net/tg3.c648
-rw-r--r--drivers/net/tg3.h19
-rw-r--r--drivers/net/wan/sbni.c3
-rw-r--r--drivers/pcmcia/omap_cf.c2
-rw-r--r--drivers/scsi/Kconfig8
-rw-r--r--drivers/scsi/Makefile2
-rw-r--r--drivers/scsi/ahci.c197
-rw-r--r--drivers/scsi/ata_piix.c392
-rw-r--r--drivers/scsi/libata-bmdma.c703
-rw-r--r--drivers/scsi/libata-core.c2794
-rw-r--r--drivers/scsi/libata-scsi.c240
-rw-r--r--drivers/scsi/libata.h3
-rw-r--r--drivers/scsi/pdc_adma.c6
-rw-r--r--drivers/scsi/sata_mv.c281
-rw-r--r--drivers/scsi/sata_nv.c2
-rw-r--r--drivers/scsi/sata_promise.c129
-rw-r--r--drivers/scsi/sata_qstor.c10
-rw-r--r--drivers/scsi/sata_sil.c126
-rw-r--r--drivers/scsi/sata_sil24.c102
-rw-r--r--drivers/scsi/sata_sis.c2
-rw-r--r--drivers/scsi/sata_svw.c2
-rw-r--r--drivers/scsi/sata_sx4.c25
-rw-r--r--drivers/scsi/sata_uli.c2
-rw-r--r--drivers/scsi/sata_via.c2
-rw-r--r--drivers/scsi/sata_vsc.c2
-rw-r--r--drivers/scsi/scsi_error.c7
-rw-r--r--drivers/serial/s3c2410.c2
-rw-r--r--drivers/sn/ioc4.c41
-rw-r--r--drivers/usb/Kconfig9
-rw-r--r--drivers/usb/Makefile4
-rw-r--r--drivers/usb/class/Kconfig47
-rw-r--r--drivers/usb/class/Makefile2
-rw-r--r--drivers/usb/class/audio.c3869
-rw-r--r--drivers/usb/class/audio.h110
-rw-r--r--drivers/usb/class/cdc-acm.c23
-rw-r--r--drivers/usb/class/usb-midi.c2153
-rw-r--r--drivers/usb/class/usb-midi.h164
-rw-r--r--drivers/usb/class/usblp.c15
-rw-r--r--drivers/usb/core/devices.c7
-rw-r--r--drivers/usb/core/devio.c24
-rw-r--r--drivers/usb/core/driver.c6
-rw-r--r--drivers/usb/core/hcd-pci.c11
-rw-r--r--drivers/usb/core/hcd.c153
-rw-r--r--drivers/usb/core/hcd.h4
-rw-r--r--drivers/usb/core/hub.c45
-rw-r--r--drivers/usb/core/message.c17
-rw-r--r--drivers/usb/core/notify.c15
-rw-r--r--drivers/usb/core/usb.c5
-rw-r--r--drivers/usb/gadget/Kconfig17
-rw-r--r--drivers/usb/gadget/Makefile1
-rw-r--r--drivers/usb/gadget/at91_udc.c1773
-rw-r--r--drivers/usb/gadget/at91_udc.h181
-rw-r--r--drivers/usb/gadget/dummy_hcd.c3
-rw-r--r--drivers/usb/gadget/ether.c53
-rw-r--r--drivers/usb/gadget/file_storage.c4
-rw-r--r--drivers/usb/gadget/gadget_chips.h30
-rw-r--r--drivers/usb/gadget/goku_udc.c3
-rw-r--r--drivers/usb/gadget/inode.c6
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c3
-rw-r--r--drivers/usb/gadget/net2280.c3
-rw-r--r--drivers/usb/gadget/omap_udc.c6
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c3
-rw-r--r--drivers/usb/gadget/serial.c9
-rw-r--r--drivers/usb/gadget/zero.c15
-rw-r--r--drivers/usb/host/Kconfig2
-rw-r--r--drivers/usb/host/ehci-au1xxx.c297
-rw-r--r--drivers/usb/host/ehci-fsl.c366
-rw-r--r--drivers/usb/host/ehci-fsl.h37
-rw-r--r--drivers/usb/host/ehci-hcd.c13
-rw-r--r--drivers/usb/host/ehci-hub.c4
-rw-r--r--drivers/usb/host/ehci-mem.c11
-rw-r--r--drivers/usb/host/ehci-pci.c25
-rw-r--r--drivers/usb/host/ehci-q.c17
-rw-r--r--drivers/usb/host/ehci-sched.c20
-rw-r--r--drivers/usb/host/ehci.h18
-rw-r--r--drivers/usb/host/hc_crisv10.c12
-rw-r--r--drivers/usb/host/isp116x-hcd.c5
-rw-r--r--drivers/usb/host/ohci-at91.c306
-rw-r--r--drivers/usb/host/ohci-au1xxx.c102
-rw-r--r--drivers/usb/host/ohci-hcd.c54
-rw-r--r--drivers/usb/host/ohci-hub.c12
-rw-r--r--drivers/usb/host/ohci-omap.c9
-rw-r--r--drivers/usb/host/ohci-pci.c15
-rw-r--r--drivers/usb/host/sl811-hcd.c3
-rw-r--r--drivers/usb/host/uhci-debug.c356
-rw-r--r--drivers/usb/host/uhci-hcd.c127
-rw-r--r--drivers/usb/host/uhci-hcd.h188
-rw-r--r--drivers/usb/host/uhci-hub.c21
-rw-r--r--drivers/usb/host/uhci-q.c1294
-rw-r--r--drivers/usb/image/mdc800.c67
-rw-r--r--drivers/usb/input/ati_remote.c2
-rw-r--r--drivers/usb/input/hid-core.c175
-rw-r--r--drivers/usb/input/hid-lgff.c6
-rw-r--r--drivers/usb/input/hid-tmff.c3
-rw-r--r--drivers/usb/input/hid.h10
-rw-r--r--drivers/usb/input/hiddev.c6
-rw-r--r--drivers/usb/media/Kconfig15
-rw-r--r--drivers/usb/media/Makefile7
-rw-r--r--drivers/usb/media/dabusb.c36
-rw-r--r--drivers/usb/media/dabusb.h2
-rw-r--r--drivers/usb/media/et61x251.h28
-rw-r--r--drivers/usb/media/et61x251_core.c321
-rw-r--r--drivers/usb/media/et61x251_sensor.h5
-rw-r--r--drivers/usb/media/et61x251_tas5130d1b.c10
-rw-r--r--drivers/usb/media/ov511.c97
-rw-r--r--drivers/usb/media/ov511.h11
-rw-r--r--drivers/usb/media/pwc/pwc-ctrl.c1
-rw-r--r--drivers/usb/media/pwc/pwc-if.c9
-rw-r--r--drivers/usb/media/se401.c16
-rw-r--r--drivers/usb/media/se401.h3
-rw-r--r--drivers/usb/media/sn9c102.h28
-rw-r--r--drivers/usb/media/sn9c102_core.c326
-rw-r--r--drivers/usb/media/sn9c102_ov7630.c33
-rw-r--r--drivers/usb/media/sn9c102_pas202bca.c238
-rw-r--r--drivers/usb/media/sn9c102_pas202bcb.c2
-rw-r--r--drivers/usb/media/sn9c102_sensor.h15
-rw-r--r--drivers/usb/media/sn9c102_tas5110c1b.c14
-rw-r--r--drivers/usb/media/sn9c102_tas5130d1b.c12
-rw-r--r--drivers/usb/media/stv680.c20
-rw-r--r--drivers/usb/media/stv680.h2
-rw-r--r--drivers/usb/media/usbvideo.c31
-rw-r--r--drivers/usb/media/usbvideo.h5
-rw-r--r--drivers/usb/media/vicam.c22
-rw-r--r--drivers/usb/media/w9968cf.c88
-rw-r--r--drivers/usb/media/w9968cf.h14
-rw-r--r--drivers/usb/media/zc0301.h192
-rw-r--r--drivers/usb/media/zc0301_core.c2055
-rw-r--r--drivers/usb/media/zc0301_pas202bcb.c361
-rw-r--r--drivers/usb/media/zc0301_sensor.h103
-rw-r--r--drivers/usb/misc/auerswald.c6
-rw-r--r--drivers/usb/misc/cytherm.c3
-rw-r--r--drivers/usb/misc/idmouse.c28
-rw-r--r--drivers/usb/misc/ldusb.c14
-rw-r--r--drivers/usb/misc/legousbtower.c11
-rw-r--r--drivers/usb/misc/phidgetkit.c9
-rw-r--r--drivers/usb/misc/phidgetservo.c3
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c5
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.h8
-rw-r--r--drivers/usb/misc/usblcd.c3
-rw-r--r--drivers/usb/misc/usbled.c3
-rw-r--r--drivers/usb/misc/usbtest.c9
-rw-r--r--drivers/usb/mon/mon_main.c22
-rw-r--r--drivers/usb/mon/mon_text.c24
-rw-r--r--drivers/usb/mon/usb_mon.h2
-rw-r--r--drivers/usb/net/pegasus.c1
-rw-r--r--drivers/usb/net/pegasus.h26
-rw-r--r--drivers/usb/net/rtl8150.c4
-rw-r--r--drivers/usb/net/zd1201.c9
-rw-r--r--drivers/usb/serial/Kconfig7
-rw-r--r--drivers/usb/serial/Makefile1
-rw-r--r--drivers/usb/serial/cp2101.c7
-rw-r--r--drivers/usb/serial/cypress_m8.c73
-rw-r--r--drivers/usb/serial/cypress_m8.h5
-rw-r--r--drivers/usb/serial/ftdi_sio.c4
-rw-r--r--drivers/usb/serial/ftdi_sio.h7
-rw-r--r--drivers/usb/serial/garmin_gps.c3
-rw-r--r--drivers/usb/serial/io_edgeport.c3
-rw-r--r--drivers/usb/serial/io_ti.c6
-rw-r--r--drivers/usb/serial/ir-usb.c3
-rw-r--r--drivers/usb/serial/keyspan.c6
-rw-r--r--drivers/usb/serial/kobil_sct.c16
-rw-r--r--drivers/usb/serial/mct_u232.c3
-rw-r--r--drivers/usb/serial/navman.c157
-rw-r--r--drivers/usb/serial/omninet.c10
-rw-r--r--drivers/usb/serial/option.c3
-rw-r--r--drivers/usb/serial/pl2303.c8
-rw-r--r--drivers/usb/serial/pl2303.h4
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c3
-rw-r--r--drivers/usb/serial/usb-serial.c6
-rw-r--r--drivers/usb/serial/visor.c3
-rw-r--r--drivers/usb/storage/datafab.c3
-rw-r--r--drivers/usb/storage/isd200.c10
-rw-r--r--drivers/usb/storage/jumpshot.c3
-rw-r--r--drivers/usb/storage/scsiglue.c9
-rw-r--r--drivers/usb/storage/sddr55.c3
-rw-r--r--drivers/usb/storage/shuttle_usbat.c3
-rw-r--r--drivers/usb/storage/unusual_devs.h32
-rw-r--r--drivers/usb/storage/usb.c25
-rw-r--r--drivers/usb/storage/usb.h5
-rw-r--r--drivers/video/Kconfig2
-rw-r--r--drivers/video/epson1355fb.c1
-rw-r--r--drivers/video/sa1100fb.c2
-rw-r--r--drivers/video/vfb.c1
-rw-r--r--fs/char_dev.c17
-rw-r--r--fs/debugfs/file.c46
-rw-r--r--fs/sysfs/dir.c37
-rw-r--r--fs/sysfs/file.c9
-rw-r--r--fs/sysfs/inode.c9
-rw-r--r--fs/sysfs/symlink.c6
-rw-r--r--fs/sysfs/sysfs.h1
-rw-r--r--include/asm-arm/irq.h2
-rw-r--r--include/asm-generic/vmlinux.lds.h14
-rw-r--r--include/asm-ia64/intel_intrin.h134
-rw-r--r--include/asm-ia64/machvec.h13
-rw-r--r--include/asm-ia64/machvec_sn2.h4
-rw-r--r--include/asm-ia64/mca.h2
-rw-r--r--include/asm-ia64/mutex.h93
-rw-r--r--include/asm-ia64/processor.h3
-rw-r--r--include/asm-ia64/signal.h2
-rw-r--r--include/asm-ia64/sn/addrs.h8
-rw-r--r--include/asm-ia64/sn/rw_mmr.h56
-rw-r--r--include/asm-ia64/sn/tioce.h36
-rw-r--r--include/asm-ia64/sn/xpc.h22
-rw-r--r--include/asm-ia64/system.h7
-rw-r--r--include/asm-ia64/thread_info.h12
-rw-r--r--include/asm-mips/byteorder.h18
-rw-r--r--include/asm-mips/compat.h8
-rw-r--r--include/asm-mips/io.h69
-rw-r--r--include/asm-mips/mach-cobalt/cobalt.h2
-rw-r--r--include/asm-mips/mach-generic/mangle-port.h36
-rw-r--r--include/asm-mips/mach-ip27/mangle-port.h9
-rw-r--r--include/asm-mips/mach-ip32/mangle-port.h9
-rw-r--r--include/asm-mips/mach-mips/cpu-feature-overrides.h4
-rw-r--r--include/asm-mips/mmu_context.h7
-rw-r--r--include/asm-mips/pgtable-32.h2
-rw-r--r--include/asm-mips/r4kcache.h1
-rw-r--r--include/asm-mips/signal.h20
-rw-r--r--include/asm-mips/sn/klconfig.h2
-rw-r--r--include/asm-mips/sn/mapped_kernel.h4
-rw-r--r--include/asm-mips/sn/sn0/hubio.h12
-rw-r--r--include/asm-mips/stackframe.h20
-rw-r--r--include/asm-mips/system.h8
-rw-r--r--include/asm-mips/thread_info.h2
-rw-r--r--include/asm-sparc/socket.h2
-rw-r--r--include/linux/amba/clcd.h12
-rw-r--r--include/linux/ata.h22
-rw-r--r--include/linux/cpu.h2
-rw-r--r--include/linux/crypto.h10
-rw-r--r--include/linux/dccp.h132
-rw-r--r--include/linux/debugfs.h15
-rw-r--r--include/linux/device.h2
-rw-r--r--include/linux/dn.h44
-rw-r--r--include/linux/dvb/audio.h13
-rw-r--r--include/linux/dvb/video.h13
-rw-r--r--include/linux/fsl_devices.h27
-rw-r--r--include/linux/icmpv6.h11
-rw-r--r--include/linux/if.h26
-rw-r--r--include/linux/in.h1
-rw-r--r--include/linux/inetdevice.h1
-rw-r--r--include/linux/ipv6.h14
-rw-r--r--include/linux/ipv6_route.h10
-rw-r--r--include/linux/irda.h1
-rw-r--r--include/linux/kobj_map.h4
-rw-r--r--include/linux/kobject.h4
-rw-r--r--include/linux/libata.h180
-rw-r--r--include/linux/list.h24
-rw-r--r--include/linux/module.h10
-rw-r--r--include/linux/net.h4
-rw-r--r--include/linux/netdevice.h41
-rw-r--r--include/linux/netfilter.h9
-rw-r--r--include/linux/netfilter/nfnetlink.h1
-rw-r--r--include/linux/netfilter/nfnetlink_log.h6
-rw-r--r--include/linux/netfilter/x_tables.h37
-rw-r--r--include/linux/netfilter/xt_policy.h58
-rw-r--r--include/linux/netfilter_bridge.h27
-rw-r--r--include/linux/netfilter_ipv4/ip_conntrack.h2
-rw-r--r--include/linux/netfilter_ipv4/ip_conntrack_h323.h30
-rw-r--r--include/linux/netfilter_ipv4/ip_nat.h2
-rw-r--r--include/linux/netfilter_ipv4/ipt_policy.h69
-rw-r--r--include/linux/netfilter_ipv6/ip6t_policy.h69
-rw-r--r--include/linux/netlink.h1
-rw-r--r--include/linux/pci_ids.h6
-rw-r--r--include/linux/rtnetlink.h23
-rw-r--r--include/linux/security.h25
-rw-r--r--include/linux/skbuff.h47
-rw-r--r--include/linux/socket.h1
-rw-r--r--include/linux/sunrpc/svcsock.h2
-rw-r--r--include/linux/sysctl.h27
-rw-r--r--include/linux/tcp.h6
-rw-r--r--include/linux/usb.h2
-rw-r--r--include/linux/usb_gadget.h7
-rw-r--r--include/linux/videodev2.h84
-rw-r--r--include/linux/xfrm.h30
-rw-r--r--include/media/ir-common.h40
-rw-r--r--include/media/saa7146.h21
-rw-r--r--include/media/tuner-types.h3
-rw-r--r--include/media/tuner.h6
-rw-r--r--include/media/v4l2-common.h62
-rw-r--r--include/media/video-buf-dvb.h2
-rw-r--r--include/media/video-buf.h2
-rw-r--r--include/net/af_unix.h3
-rw-r--r--include/net/dn.h105
-rw-r--r--include/net/dn_dev.h88
-rw-r--r--include/net/dn_fib.h22
-rw-r--r--include/net/dn_neigh.h4
-rw-r--r--include/net/dn_nsp.h72
-rw-r--r--include/net/dn_route.h12
-rw-r--r--include/net/flow.h8
-rw-r--r--include/net/if_inet6.h3
-rw-r--r--include/net/inet_connection_sock.h26
-rw-r--r--include/net/ip.h4
-rw-r--r--include/net/ip6_route.h24
-rw-r--r--include/net/ipv6.h22
-rw-r--r--include/net/llc.h2
-rw-r--r--include/net/ndisc.h2
-rw-r--r--include/net/neighbour.h2
-rw-r--r--include/net/netfilter/nf_conntrack.h56
-rw-r--r--include/net/scm.h10
-rw-r--r--include/net/sctp/structs.h10
-rw-r--r--include/net/sock.h12
-rw-r--r--include/net/tcp.h16
-rw-r--r--include/net/xfrm.h62
-rw-r--r--include/rdma/ib_fmr_pool.h2
-rw-r--r--include/rdma/ib_mad.h48
-rw-r--r--include/rdma/ib_user_verbs.h79
-rw-r--r--include/rdma/ib_verbs.h38
-rw-r--r--include/scsi/scsi_eh.h3
-rw-r--r--kernel/ksysfs.c3
-rw-r--r--kernel/module.c199
-rw-r--r--kernel/params.c10
-rw-r--r--kernel/rcupdate.c6
-rw-r--r--lib/kobject.c60
-rw-r--r--lib/kobject_uevent.c2
-rw-r--r--lib/kref.c7
-rw-r--r--net/802/psnap.c4
-rw-r--r--net/8021q/vlan.c43
-rw-r--r--net/8021q/vlan_dev.c6
-rw-r--r--net/atm/clip.c2
-rw-r--r--net/atm/common.c4
-rw-r--r--net/atm/ioctl.c15
-rw-r--r--net/atm/resources.c32
-rw-r--r--net/atm/resources.h3
-rw-r--r--net/bluetooth/rfcomm/core.c8
-rw-r--r--net/bridge/Kconfig1
-rw-r--r--net/bridge/br.c12
-rw-r--r--net/bridge/br_device.c3
-rw-r--r--net/bridge/br_fdb.c6
-rw-r--r--net/bridge/br_if.c9
-rw-r--r--net/bridge/br_input.c43
-rw-r--r--net/bridge/br_netfilter.c225
-rw-r--r--net/bridge/br_private.h6
-rw-r--r--net/bridge/br_stp_bpdu.c196
-rw-r--r--net/bridge/br_stp_timer.c47
-rw-r--r--net/bridge/br_sysfs_br.c49
-rw-r--r--net/bridge/netfilter/ebtables.c101
-rw-r--r--net/compat.c95
-rw-r--r--net/core/dev.c32
-rw-r--r--net/core/flow.c7
-rw-r--r--net/core/link_watch.c44
-rw-r--r--net/core/neighbour.c12
-rw-r--r--net/core/net-sysfs.c41
-rw-r--r--net/core/netpoll.c6
-rw-r--r--net/core/pktgen.c2842
-rw-r--r--net/core/rtnetlink.c78
-rw-r--r--net/core/skbuff.c42
-rw-r--r--net/core/sock.c30
-rw-r--r--net/core/sysctl_net_core.c23
-rw-r--r--net/dccp/Kconfig13
-rw-r--r--net/dccp/Makefile9
-rw-r--r--net/dccp/ackvec.c296
-rw-r--r--net/dccp/ackvec.h53
-rw-r--r--net/dccp/ccid.c189
-rw-r--r--net/dccp/ccid.h129
-rw-r--r--net/dccp/ccids/Kconfig43
-rw-r--r--net/dccp/ccids/Makefile4
-rw-r--r--net/dccp/ccids/ccid2.c779
-rw-r--r--net/dccp/ccids/ccid2.h85
-rw-r--r--net/dccp/ccids/ccid3.c112
-rw-r--r--net/dccp/ccids/ccid3.h5
-rw-r--r--net/dccp/dccp.h133
-rw-r--r--net/dccp/diag.c2
-rw-r--r--net/dccp/feat.c586
-rw-r--r--net/dccp/feat.h29
-rw-r--r--net/dccp/input.c28
-rw-r--r--net/dccp/ipv4.c333
-rw-r--r--net/dccp/ipv6.c371
-rw-r--r--net/dccp/minisocks.c37
-rw-r--r--net/dccp/options.c291
-rw-r--r--net/dccp/output.c88
-rw-r--r--net/dccp/proto.c440
-rw-r--r--net/dccp/sysctl.c124
-rw-r--r--net/dccp/timer.c14
-rw-r--r--net/decnet/af_decnet.c18
-rw-r--r--net/decnet/dn_dev.c34
-rw-r--r--net/decnet/dn_fib.c8
-rw-r--r--net/decnet/dn_neigh.c24
-rw-r--r--net/decnet/dn_nsp_in.c28
-rw-r--r--net/decnet/dn_nsp_out.c38
-rw-r--r--net/decnet/dn_route.c60
-rw-r--r--net/decnet/dn_rules.c115
-rw-r--r--net/decnet/dn_table.c12
-rw-r--r--net/decnet/sysctl_net_decnet.c12
-rw-r--r--net/ipv4/af_inet.c120
-rw-r--r--net/ipv4/ah4.c1
-rw-r--r--net/ipv4/arp.c20
-rw-r--r--net/ipv4/devinet.c8
-rw-r--r--net/ipv4/esp4.c1
-rw-r--r--net/ipv4/fib_rules.c113
-rw-r--r--net/ipv4/fib_trie.c24
-rw-r--r--net/ipv4/igmp.c26
-rw-r--r--net/ipv4/inet_connection_sock.c49
-rw-r--r--net/ipv4/ip_sockglue.c170
-rw-r--r--net/ipv4/ipcomp.c17
-rw-r--r--net/ipv4/ipconfig.c10
-rw-r--r--net/ipv4/ipmr.c4
-rw-r--r--net/ipv4/ipvs/ip_vs_app.c19
-rw-r--r--net/ipv4/netfilter/Kconfig36
-rw-r--r--net/ipv4/netfilter/Makefile6
-rw-r--r--net/ipv4/netfilter/arp_tables.c21
-rw-r--r--net/ipv4/netfilter/arpt_mangle.c23
-rw-r--r--net/ipv4/netfilter/ip_conntrack_helper_h323.c1731
-rw-r--r--net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.c870
-rw-r--r--net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.h98
-rw-r--r--net/ipv4/netfilter/ip_conntrack_helper_h323_types.c1926
-rw-r--r--net/ipv4/netfilter/ip_conntrack_helper_h323_types.h938
-rw-r--r--net/ipv4/netfilter/ip_conntrack_netlink.c7
-rw-r--r--net/ipv4/netfilter/ip_nat_helper_h323.c605
-rw-r--r--net/ipv4/netfilter/ip_nat_helper_pptp.c8
-rw-r--r--net/ipv4/netfilter/ip_nat_rule.c45
-rw-r--r--net/ipv4/netfilter/ip_nat_snmp_basic.c5
-rw-r--r--net/ipv4/netfilter/ip_queue.c11
-rw-r--r--net/ipv4/netfilter/ip_tables.c69
-rw-r--r--net/ipv4/netfilter/ipt_CLUSTERIP.c27
-rw-r--r--net/ipv4/netfilter/ipt_DSCP.c17
-rw-r--r--net/ipv4/netfilter/ipt_ECN.c18
-rw-r--r--net/ipv4/netfilter/ipt_LOG.c11
-rw-r--r--net/ipv4/netfilter/ipt_MASQUERADE.c18
-rw-r--r--net/ipv4/netfilter/ipt_NETMAP.c19
-rw-r--r--net/ipv4/netfilter/ipt_REDIRECT.c17
-rw-r--r--net/ipv4/netfilter/ipt_REJECT.c28
-rw-r--r--net/ipv4/netfilter/ipt_SAME.c19
-rw-r--r--net/ipv4/netfilter/ipt_TCPMSS.c16
-rw-r--r--net/ipv4/netfilter/ipt_TOS.c17
-rw-r--r--net/ipv4/netfilter/ipt_TTL.c25
-rw-r--r--net/ipv4/netfilter/ipt_ULOG.c12
-rw-r--r--net/ipv4/netfilter/ipt_addrtype.c20
-rw-r--r--net/ipv4/netfilter/ipt_ah.c25
-rw-r--r--net/ipv4/netfilter/ipt_dscp.c19
-rw-r--r--net/ipv4/netfilter/ipt_ecn.c14
-rw-r--r--net/ipv4/netfilter/ipt_esp.c25
-rw-r--r--net/ipv4/netfilter/ipt_hashlimit.c21
-rw-r--r--net/ipv4/netfilter/ipt_iprange.c28
-rw-r--r--net/ipv4/netfilter/ipt_multiport.c31
-rw-r--r--net/ipv4/netfilter/ipt_owner.c21
-rw-r--r--net/ipv4/netfilter/ipt_policy.c176
-rw-r--r--net/ipv4/netfilter/ipt_recent.c22
-rw-r--r--net/ipv4/netfilter/ipt_tos.c18
-rw-r--r--net/ipv4/netfilter/ipt_ttl.c19
-rw-r--r--net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c22
-rw-r--r--net/ipv4/raw.c80
-rw-r--r--net/ipv4/sysctl_net_ipv4.c25
-rw-r--r--net/ipv4/tcp.c63
-rw-r--r--net/ipv4/tcp_htcp.c66
-rw-r--r--net/ipv4/tcp_input.c49
-rw-r--r--net/ipv4/tcp_ipv4.c44
-rw-r--r--net/ipv4/tcp_output.c259
-rw-r--r--net/ipv4/tcp_timer.c36
-rw-r--r--net/ipv4/udp.c83
-rw-r--r--net/ipv4/xfrm4_tunnel.c11
-rw-r--r--net/ipv6/Kconfig26
-rw-r--r--net/ipv6/addrconf.c346
-rw-r--r--net/ipv6/af_inet6.c120
-rw-r--r--net/ipv6/ah6.c5
-rw-r--r--net/ipv6/anycast.c7
-rw-r--r--net/ipv6/esp6.c5
-rw-r--r--net/ipv6/ip6_fib.c1
-rw-r--r--net/ipv6/ip6_flowlabel.c6
-rw-r--r--net/ipv6/ip6_output.c43
-rw-r--r--net/ipv6/ipcomp6.c22
-rw-r--r--net/ipv6/ipv6_sockglue.c163
-rw-r--r--net/ipv6/mcast.c17
-rw-r--r--net/ipv6/ndisc.c49
-rw-r--r--net/ipv6/netfilter/Kconfig10
-rw-r--r--net/ipv6/netfilter/Makefile1
-rw-r--r--net/ipv6/netfilter/ip6_queue.c11
-rw-r--r--net/ipv6/netfilter/ip6_tables.c87
-rw-r--r--net/ipv6/netfilter/ip6t_HL.c19
-rw-r--r--net/ipv6/netfilter/ip6t_LOG.c11
-rw-r--r--net/ipv6/netfilter/ip6t_REJECT.c25
-rw-r--r--net/ipv6/netfilter/ip6t_ah.c12
-rw-r--r--net/ipv6/netfilter/ip6t_dst.c13
-rw-r--r--net/ipv6/netfilter/ip6t_esp.c12
-rw-r--r--net/ipv6/netfilter/ip6t_eui64.c27
-rw-r--r--net/ipv6/netfilter/ip6t_frag.c13
-rw-r--r--net/ipv6/netfilter/ip6t_hbh.c13
-rw-r--r--net/ipv6/netfilter/ip6t_hl.c22
-rw-r--r--net/ipv6/netfilter/ip6t_ipv6header.c8
-rw-r--r--net/ipv6/netfilter/ip6t_multiport.c11
-rw-r--r--net/ipv6/netfilter/ip6t_owner.c18
-rw-r--r--net/ipv6/netfilter/ip6t_policy.c176
-rw-r--r--net/ipv6/netfilter/ip6t_rt.c12
-rw-r--r--net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c39
-rw-r--r--net/ipv6/netfilter/nf_conntrack_reasm.c8
-rw-r--r--net/ipv6/raw.c145
-rw-r--r--net/ipv6/reassembly.c35
-rw-r--r--net/ipv6/route.c680
-rw-r--r--net/ipv6/tcp_ipv6.c74
-rw-r--r--net/ipv6/udp.c84
-rw-r--r--net/ipv6/xfrm6_tunnel.c11
-rw-r--r--net/key/af_key.c6
-rw-r--r--net/llc/af_llc.c15
-rw-r--r--net/llc/llc_c_ac.c1
-rw-r--r--net/llc/llc_core.c1
-rw-r--r--net/llc/llc_output.c3
-rw-r--r--net/llc/llc_output.h20
-rw-r--r--net/llc/llc_s_ac.c2
-rw-r--r--net/netfilter/Kconfig10
-rw-r--r--net/netfilter/Makefile1
-rw-r--r--net/netfilter/nf_conntrack_core.c135
-rw-r--r--net/netfilter/nf_conntrack_ftp.c2
-rw-r--r--net/netfilter/nf_conntrack_netlink.c46
-rw-r--r--net/netfilter/nf_conntrack_standalone.c1
-rw-r--r--net/netfilter/nf_sockopt.c94
-rw-r--r--net/netfilter/nfnetlink.c6
-rw-r--r--net/netfilter/nfnetlink_log.c46
-rw-r--r--net/netfilter/x_tables.c72
-rw-r--r--net/netfilter/xt_CLASSIFY.c42
-rw-r--r--net/netfilter/xt_CONNMARK.c27
-rw-r--r--net/netfilter/xt_MARK.c37
-rw-r--r--net/netfilter/xt_NFQUEUE.c24
-rw-r--r--net/netfilter/xt_NOTRACK.c45
-rw-r--r--net/netfilter/xt_comment.c18
-rw-r--r--net/netfilter/xt_connbytes.c15
-rw-r--r--net/netfilter/xt_connmark.c28
-rw-r--r--net/netfilter/xt_conntrack.c18
-rw-r--r--net/netfilter/xt_dccp.c45
-rw-r--r--net/netfilter/xt_helper.c26
-rw-r--r--net/netfilter/xt_length.c24
-rw-r--r--net/netfilter/xt_limit.c7
-rw-r--r--net/netfilter/xt_mac.c34
-rw-r--r--net/netfilter/xt_mark.c16
-rw-r--r--net/netfilter/xt_physdev.c14
-rw-r--r--net/netfilter/xt_pkttype.c23
-rw-r--r--net/netfilter/xt_policy.c209
-rw-r--r--net/netfilter/xt_realm.c27
-rw-r--r--net/netfilter/xt_sctp.c66
-rw-r--r--net/netfilter/xt_state.c21
-rw-r--r--net/netfilter/xt_string.c10
-rw-r--r--net/netfilter/xt_tcpmss.c52
-rw-r--r--net/netfilter/xt_tcpudp.c112
-rw-r--r--net/netlink/af_netlink.c52
-rw-r--r--net/sched/Kconfig1
-rw-r--r--net/sched/act_ipt.c10
-rw-r--r--net/sched/sch_atm.c1
-rw-r--r--net/sched/sch_dsmark.c1
-rw-r--r--net/sched/sch_generic.c2
-rw-r--r--net/sched/sch_netem.c4
-rw-r--r--net/sched/sch_prio.c2
-rw-r--r--net/sched/sch_red.c179
-rw-r--r--net/sched/sch_sfq.c5
-rw-r--r--net/sched/sch_tbf.c9
-rw-r--r--net/sctp/ipv6.c92
-rw-r--r--net/sctp/protocol.c94
-rw-r--r--net/socket.c332
-rw-r--r--net/sunrpc/cache.c17
-rw-r--r--net/sunrpc/sched.c11
-rw-r--r--net/sunrpc/svcsock.c8
-rw-r--r--net/tipc/bcast.c58
-rw-r--r--net/tipc/bearer.c20
-rw-r--r--net/tipc/cluster.c22
-rw-r--r--net/tipc/cluster.h2
-rw-r--r--net/tipc/config.c4
-rw-r--r--net/tipc/dbg.c4
-rw-r--r--net/tipc/discover.c8
-rw-r--r--net/tipc/eth_media.c4
-rw-r--r--net/tipc/link.c89
-rw-r--r--net/tipc/name_distr.c6
-rw-r--r--net/tipc/name_table.c62
-rw-r--r--net/tipc/net.c7
-rw-r--r--net/tipc/node.c20
-rw-r--r--net/tipc/node.h2
-rw-r--r--net/tipc/node_subscr.c2
-rw-r--r--net/tipc/port.c57
-rw-r--r--net/tipc/ref.c8
-rw-r--r--net/tipc/ref.h4
-rw-r--r--net/tipc/socket.c28
-rw-r--r--net/tipc/subscr.c30
-rw-r--r--net/tipc/user_reg.c4
-rw-r--r--net/tipc/zone.c12
-rw-r--r--net/unix/af_unix.c32
-rw-r--r--net/unix/garbage.c7
-rw-r--r--net/xfrm/xfrm_policy.c9
-rw-r--r--net/xfrm/xfrm_state.c108
-rw-r--r--net/xfrm/xfrm_user.c397
-rw-r--r--scripts/genksyms/keywords.c_shipped91
-rw-r--r--scripts/genksyms/keywords.gperf1
-rw-r--r--security/dummy.c13
-rw-r--r--security/selinux/hooks.c46
-rw-r--r--security/selinux/include/xfrm.h12
-rw-r--r--security/selinux/nlmsgtab.c7
-rw-r--r--security/selinux/xfrm.c68
993 files changed, 55529 insertions, 31539 deletions
diff --git a/.gitignore b/.gitignore
index 3f8fb686b59c..53e53f2791f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,3 +30,5 @@ include/linux/autoconf.h
30include/linux/compile.h 30include/linux/compile.h
31include/linux/version.h 31include/linux/version.h
32 32
33# stgit generated dirs
34patches-*
diff --git a/CREDITS b/CREDITS
index 1f171f1033bd..af70678a0afd 100644
--- a/CREDITS
+++ b/CREDITS
@@ -2813,6 +2813,8 @@ E: luca.risolia@studio.unibo.it
2813P: 1024D/FCE635A4 88E8 F32F 7244 68BA 3958 5D40 99DA 5D2A FCE6 35A4 2813P: 1024D/FCE635A4 88E8 F32F 7244 68BA 3958 5D40 99DA 5D2A FCE6 35A4
2814D: V4L driver for W996[87]CF JPEG USB Dual Mode Camera Chips 2814D: V4L driver for W996[87]CF JPEG USB Dual Mode Camera Chips
2815D: V4L2 driver for SN9C10x PC Camera Controllers 2815D: V4L2 driver for SN9C10x PC Camera Controllers
2816D: V4L2 driver for ET61X151 and ET61X251 PC Camera Controllers
2817D: V4L2 driver for ZC0301 Image Processor and Control Chip
2816S: Via Liberta' 41/A 2818S: Via Liberta' 41/A
2817S: Osio Sotto, 24046, Bergamo 2819S: Osio Sotto, 24046, Bergamo
2818S: Italy 2820S: Italy
diff --git a/Documentation/Changes b/Documentation/Changes
index fe5ae0f55020..b02f476c2973 100644
--- a/Documentation/Changes
+++ b/Documentation/Changes
@@ -15,24 +15,6 @@ and therefore owes credit to the same people as that file (Jared Mauch,
15Axel Boldt, Alessandro Sigala, and countless other users all over the 15Axel Boldt, Alessandro Sigala, and countless other users all over the
16'net). 16'net).
17 17
18The latest revision of this document, in various formats, can always
19be found at <http://cyberbuzz.gatech.edu/kaboom/linux/Changes-2.4/>.
20
21Feel free to translate this document. If you do so, please send me a
22URL to your translation for inclusion in future revisions of this
23document.
24
25Smotrite file <http://oblom.rnc.ru/linux/kernel/Changes.ru>, yavlyaushisya
26russkim perevodom dannogo documenta.
27
28Visite <http://www2.adi.uam.es/~ender/tecnico/> para obtener la traducción
29al español de este documento en varios formatos.
30
31Eine deutsche Version dieser Datei finden Sie unter
32<http://www.stefan-winter.de/Changes-2.4.0.txt>.
33
34Chris Ricker (kaboom@gatech.edu or chris.ricker@genetics.utah.edu).
35
36Current Minimal Requirements 18Current Minimal Requirements
37============================ 19============================
38 20
diff --git a/Documentation/connector/connector.txt b/Documentation/connector/connector.txt
index 57a314b14cf8..ad6e0ba7b38c 100644
--- a/Documentation/connector/connector.txt
+++ b/Documentation/connector/connector.txt
@@ -69,10 +69,11 @@ Unregisters new callback with connector core.
69 69
70struct cb_id *id - unique connector's user identifier. 70struct cb_id *id - unique connector's user identifier.
71 71
72void cn_netlink_send(struct cn_msg *msg, u32 __groups, int gfp_mask); 72int cn_netlink_send(struct cn_msg *msg, u32 __groups, int gfp_mask);
73 73
74Sends message to the specified groups. It can be safely called from 74Sends message to the specified groups. It can be safely called from
75any context, but may silently fail under strong memory pressure. 75softirq context, but may silently fail under strong memory pressure.
76If there are no listeners for given group -ESRCH can be returned.
76 77
77struct cn_msg * - message header(with attached data). 78struct cn_msg * - message header(with attached data).
78u32 __group - destination group. 79u32 __group - destination group.
diff --git a/Documentation/dvb/avermedia.txt b/Documentation/dvb/avermedia.txt
index 068070ff13cd..8bab8461a4af 100644
--- a/Documentation/dvb/avermedia.txt
+++ b/Documentation/dvb/avermedia.txt
@@ -1,4 +1,3 @@
1
2HOWTO: Get An Avermedia DVB-T working under Linux 1HOWTO: Get An Avermedia DVB-T working under Linux
3 ______________________________________________ 2 ______________________________________________
4 3
@@ -137,11 +136,8 @@ Getting the card going
137 To power up the card, load the following modules in the 136 To power up the card, load the following modules in the
138 following order: 137 following order:
139 138
140 * insmod dvb-core.o 139 * modprobe bttv (normally loaded automatically)
141 * modprobe bttv.o 140 * modprobe dvb-bt8xx (or place dvb-bt8xx in /etc/modules)
142 * insmod bt878.o
143 * insmod dvb-bt8xx.o
144 * insmod sp887x.o
145 141
146 Insertion of these modules into the running kernel will 142 Insertion of these modules into the running kernel will
147 activate the appropriate DVB device nodes. It is then possible 143 activate the appropriate DVB device nodes. It is then possible
@@ -302,4 +298,4 @@ Further Update
302 Many thanks to Nigel Pearson for the updates to this document 298 Many thanks to Nigel Pearson for the updates to this document
303 since the recent revision of the driver. 299 since the recent revision of the driver.
304 300
305 January 29th 2004 301 February 14th 2006
diff --git a/Documentation/dvb/bt8xx.txt b/Documentation/dvb/bt8xx.txt
index 52ed462061df..4e7614e606c5 100644
--- a/Documentation/dvb/bt8xx.txt
+++ b/Documentation/dvb/bt8xx.txt
@@ -1,118 +1,78 @@
1How to get the Nebula, PCTV, FusionHDTV Lite and Twinhan DST cards working 1How to get the bt8xx cards working
2========================================================================== 2==================================
3 3
4This class of cards has a bt878a as the PCI interface, and 41) General information
5require the bttv driver. 5======================
6 6
7Please pay close attention to the warning about the bttv module 7This class of cards has a bt878a as the PCI interface, and require the bttv driver
8options below for the DST card. 8for accessing the i2c bus and the gpio pins of the bt8xx chipset.
9Please see Documentation/dvb/cards.txt => o Cards based on the Conexant Bt8xx PCI bridge:
9 10
101) General informations 11Compiling kernel please enable:
11======================= 12a.)"Device drivers" => "Multimedia devices" => "Video For Linux" => "BT848 Video For Linux"
12 13b.)"Device drivers" => "Multimedia devices" => "Digital Video Broadcasting Devices"
13These drivers require the bttv driver to provide the means to access 14 => "DVB for Linux" "DVB Core Support" "Bt8xx based PCI Cards"
14the i2c bus and the gpio pins of the bt8xx chipset.
15
16Because of this, you need to enable
17"Device drivers" => "Multimedia devices"
18 => "Video For Linux" => "BT848 Video For Linux"
19
20Furthermore you need to enable
21"Device drivers" => "Multimedia devices" => "Digital Video Broadcasting Devices"
22 => "DVB for Linux" "DVB Core Support" "BT8xx based PCI cards"
23 15
242) Loading Modules 162) Loading Modules
25================== 17==================
26 18
27In general you need to load the bttv driver, which will handle the gpio and 19In default cases bttv is loaded automatically.
28i2c communication for us, plus the common dvb-bt8xx device driver. 20To load the backend either place dvb-bt8xx in etc/modules, or apply manually:
29The frontends for Nebula (nxt6000), Pinnacle PCTV (cx24110), TwinHan (dst),
30FusionHDTV DVB-T Lite (mt352) and FusionHDTV5 Lite (lgdt330x) are loaded
31automatically by the dvb-bt8xx device driver.
32
333a) Nebula / Pinnacle PCTV / FusionHDTV Lite
34---------------------------------------------
35
36 $ modprobe bttv (normally bttv is being loaded automatically by kmod)
37 $ modprobe dvb-bt8xx
38
39(or just place dvb-bt8xx in /etc/modules for automatic loading)
40
41
423b) TwinHan and Clones
43--------------------------
44 21
45 $ modprobe bttv card=0x71 22 $ modprobe dvb-bt8xx
46 $ modprobe dvb-bt8xx
47 $ modprobe dst
48 23
49The value 0x71 will override the PCI type detection for dvb-bt8xx, 24All frontends will be loaded automatically.
50which is necessary for TwinHan cards. Omission of this parameter might result 25People running udev please see Documentation/dvb/udev.txt.
51in a system lockup.
52 26
53If you're having an older card (blue color PCB) and card=0x71 locks up 27In the following cases overriding the PCI type detection for dvb-bt8xx might be necessary:
54your machine, try using 0x68, too. If that does not work, ask on the
55mailing list.
56 28
57The DST module takes a couple of useful parameters. 292a) Running TwinHan and Clones
30------------------------------
58 31
59verbose takes values 0 to 4. These values control the verbosity level, 32 $ modprobe bttv card=113
60and can be used to debug also. 33 $ modprobe dvb-bt8xx
34 $ modprobe dst
61 35
62verbose=0 means complete disabling of messages 36Useful parameters for verbosity level and debugging the dst module:
63 1 only error messages are displayed
64 2 notifications are also displayed
65 3 informational messages are also displayed
66 4 debug setting
67 37
68dst_addons takes values 0 and 0x20. A value of 0 means it is a FTA card. 38verbose=0: messages are disabled
690x20 means it has a Conditional Access slot. 39 1: only error messages are displayed
40 2: notifications are displayed
41 3: other useful messages are displayed
42 4: debug setting
43dst_addons=0: card is a free to air (FTA) card only
44 0x20: card has a conditional access slot for scrambled channels
70 45
71The autodetected values are determined by the cards 'response string' 46The autodetected values are determined by the cards' "response string".
72which you can see in your logs e.g. 47In your logs see f. ex.: dst_get_device_id: Recognize [DSTMCI].
48For bug reports please send in a complete log with verbose=4 activated.
49Please also see Documentation/dvb/ci.txt.
73 50
74dst_get_device_id: Recognise [DSTMCI] 512b) Running multiple cards
75
76If you need to sent in bug reports on the dst, please do send in a complete
77log with the verbose=4 module parameter. For general usage, the default setting
78of verbose=1 is ideal.
79
80
814) Multiple cards
82-------------------------- 52--------------------------
83 53
84If you happen to be running multiple cards, it would be advisable to load 54Examples of card ID's:
85the bttv module with the card id. This would help to solve any module loading
86problems that you might face.
87
88For example, if you have a Twinhan and Clones card along with a FusionHDTV5 Lite
89 55
90 $ modprobe bttv card=0x71 card=0x87 56Pinnacle PCTV Sat: 94
91 57Nebula Electronics Digi TV: 104
92Here the order of the card id is important and should be the same as that of the 58pcHDTV HD-2000 TV: 112
93physical order of the cards. Here card=0x71 represents the Twinhan and clones 59Twinhan DST and clones: 113
94and card=0x87 represents Fusion HDTV5 Lite. These arguments can also be 60Avermedia AverTV DVB-T 771: 123
95specified in decimal, rather than hex: 61Avermedia AverTV DVB-T 761: 124
62DViCO FusionHDTV DVB-T Lite: 128
63DViCO FusionHDTV 5 Lite: 135
96 64
65Notice: The order of the card ID should be uprising:
66Example:
97 $ modprobe bttv card=113 card=135 67 $ modprobe bttv card=113 card=135
68 $ modprobe dvb-bt8xx
98 69
99Some examples of card-id's 70For a full list of card ID's please see Documentation/video4linux/CARDLIST.bttv.
100 71In case of further problems send questions to the mailing list: www.linuxdvb.org.
101Pinnacle Sat 0x5e (94)
102Nebula Digi TV 0x68 (104)
103PC HDTV 0x70 (112)
104Twinhan 0x71 (113)
105FusionHDTV DVB-T Lite 0x80 (128)
106FusionHDTV5 Lite 0x87 (135)
107
108For a full list of card-id's, see the V4L Documentation within the kernel
109source: linux/Documentation/video4linux/CARDLIST.bttv
110
111If you have problems with this please do ask on the mailing list.
112 72
113--
114Authors: Richard Walker, 73Authors: Richard Walker,
115 Jamie Honan, 74 Jamie Honan,
116 Michael Hunold, 75 Michael Hunold,
117 Manu Abraham, 76 Manu Abraham,
77 Uwe Bugla,
118 Michael Krufky 78 Michael Krufky
diff --git a/Documentation/dvb/get_dvb_firmware b/Documentation/dvb/get_dvb_firmware
index 75c28a174092..bb55f49f2745 100644
--- a/Documentation/dvb/get_dvb_firmware
+++ b/Documentation/dvb/get_dvb_firmware
@@ -21,8 +21,9 @@
21use File::Temp qw/ tempdir /; 21use File::Temp qw/ tempdir /;
22use IO::Handle; 22use IO::Handle;
23 23
24@components = ( "sp8870", "sp887x", "tda10045", "tda10046", "av7110", "dec2000t", 24@components = ( "sp8870", "sp887x", "tda10045", "tda10046",
25 "dec2540t", "dec3000s", "vp7041", "dibusb", "nxt2002", "nxt2004", 25 "tda10046lifeview", "av7110", "dec2000t", "dec2540t",
26 "dec3000s", "vp7041", "dibusb", "nxt2002", "nxt2004",
26 "or51211", "or51132_qam", "or51132_vsb", "bluebird"); 27 "or51211", "or51132_qam", "or51132_vsb", "bluebird");
27 28
28# Check args 29# Check args
@@ -126,6 +127,24 @@ sub tda10046 {
126 $outfile; 127 $outfile;
127} 128}
128 129
130sub tda10046lifeview {
131 my $sourcefile = "Drv_2.11.02.zip";
132 my $url = "http://www.lifeview.com.tw/drivers/pci_card/FlyDVB-T/$sourcefile";
133 my $hash = "1ea24dee4eea8fe971686981f34fd2e0";
134 my $outfile = "dvb-fe-tda10046.fw";
135 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
136
137 checkstandard();
138
139 wgetfile($sourcefile, $url);
140 unzip($sourcefile, $tmpdir);
141 extract("$tmpdir/LVHybrid.sys", 0x8b088, 24602, "$tmpdir/fwtmp");
142 verify("$tmpdir/fwtmp", $hash);
143 copy("$tmpdir/fwtmp", $outfile);
144
145 $outfile;
146}
147
129sub av7110 { 148sub av7110 {
130 my $sourcefile = "dvb-ttpci-01.fw-261d"; 149 my $sourcefile = "dvb-ttpci-01.fw-261d";
131 my $url = "http://www.linuxtv.org/downloads/firmware/$sourcefile"; 150 my $url = "http://www.linuxtv.org/downloads/firmware/$sourcefile";
diff --git a/Documentation/dvb/readme.txt b/Documentation/dvb/readme.txt
index f5c50b22de3b..0b0380c91990 100644
--- a/Documentation/dvb/readme.txt
+++ b/Documentation/dvb/readme.txt
@@ -20,11 +20,23 @@ http://linuxtv.org/downloads/
20 20
21What's inside this directory: 21What's inside this directory:
22 22
23"avermedia.txt"
24contains detailed information about the
25Avermedia DVB-T cards. See also "bt8xx.txt".
26
27"bt8xx.txt"
28contains detailed information about the
29various bt8xx based "budget" DVB cards.
30
23"cards.txt" 31"cards.txt"
24contains a list of supported hardware. 32contains a list of supported hardware.
25 33
34"ci.txt"
35contains detailed information about the
36CI module as part from TwinHan cards and Clones.
37
26"contributors.txt" 38"contributors.txt"
27is the who-is-who of DVB development 39is the who-is-who of DVB development.
28 40
29"faq.txt" 41"faq.txt"
30contains frequently asked questions and their answers. 42contains frequently asked questions and their answers.
@@ -34,19 +46,17 @@ script to download and extract firmware for those devices
34that require it. 46that require it.
35 47
36"ttusb-dec.txt" 48"ttusb-dec.txt"
37contains detailed informations about the 49contains detailed information about the
38TT DEC2000/DEC3000 USB DVB hardware. 50TT DEC2000/DEC3000 USB DVB hardware.
39 51
40"bt8xx.txt"
41contains detailed installation instructions for the
42various bt8xx based "budget" DVB cards
43(Nebula, Pinnacle PCTV, Twinhan DST)
44
45"README.dibusb"
46contains detailed information about adapters
47based on DiBcom reference design.
48
49"udev.txt" 52"udev.txt"
50how to get DVB and udev up and running. 53how to get DVB and udev up and running.
51 54
55"README.dvb-usb"
56contains detailed information about the DVB USB cards.
57
58"README.flexcop"
59contains detailed information about the
60Technisat- and Flexcop B2C2 drivers.
61
52Good luck and have fun! 62Good luck and have fun!
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 28a31c5e2289..afeaf6218ea2 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -196,3 +196,21 @@ Why: Board specific code doesn't build anymore since ~2.6.0 and no
196 users have complained indicating there is no more need for these 196 users have complained indicating there is no more need for these
197 boards. This should really be considered a last call. 197 boards. This should really be considered a last call.
198Who: Ralf Baechle <ralf@linux-mips.org> 198Who: Ralf Baechle <ralf@linux-mips.org>
199
200---------------------------
201
202What: USB driver API moves to EXPORT_SYMBOL_GPL
203When: Febuary 2008
204Files: include/linux/usb.h, drivers/usb/core/driver.c
205Why: The USB subsystem has changed a lot over time, and it has been
206 possible to create userspace USB drivers using usbfs/libusb/gadgetfs
207 that operate as fast as the USB bus allows. Because of this, the USB
208 subsystem will not be allowing closed source kernel drivers to
209 register with it, after this grace period is over. If anyone needs
210 any help in converting their closed source drivers over to use the
211 userspace filesystems, please contact the
212 linux-usb-devel@lists.sourceforge.net mailing list, and the developers
213 there will be glad to help you out.
214Who: Greg Kroah-Hartman <gregkh@suse.de>
215
216---------------------------
diff --git a/Documentation/networking/e100.txt b/Documentation/networking/e100.txt
index 4ef9f7cd5dc3..944aa55e79f8 100644
--- a/Documentation/networking/e100.txt
+++ b/Documentation/networking/e100.txt
@@ -1,16 +1,17 @@
1Linux* Base Driver for the Intel(R) PRO/100 Family of Adapters 1Linux* Base Driver for the Intel(R) PRO/100 Family of Adapters
2============================================================== 2==============================================================
3 3
4November 17, 2004 4November 15, 2005
5
6 5
7Contents 6Contents
8======== 7========
9 8
10- In This Release 9- In This Release
11- Identifying Your Adapter 10- Identifying Your Adapter
11- Building and Installation
12- Driver Configuration Parameters 12- Driver Configuration Parameters
13- Additional Configurations 13- Additional Configurations
14- Known Issues
14- Support 15- Support
15 16
16 17
@@ -18,18 +19,30 @@ In This Release
18=============== 19===============
19 20
20This file describes the Linux* Base Driver for the Intel(R) PRO/100 Family of 21This file describes the Linux* Base Driver for the Intel(R) PRO/100 Family of
21Adapters, version 3.3.x. This driver supports 2.4.x and 2.6.x kernels. 22Adapters. This driver includes support for Itanium(R)2-based systems.
23
24For questions related to hardware requirements, refer to the documentation
25supplied with your Intel PRO/100 adapter.
26
27The following features are now available in supported kernels:
28 - Native VLANs
29 - Channel Bonding (teaming)
30 - SNMP
31
32Channel Bonding documentation can be found in the Linux kernel source:
33/Documentation/networking/bonding.txt
34
22 35
23Identifying Your Adapter 36Identifying Your Adapter
24======================== 37========================
25 38
26For more information on how to identify your adapter, go to the Adapter & 39For more information on how to identify your adapter, go to the Adapter &
27Driver ID Guide at: 40Driver ID Guide at:
28 41
29 http://support.intel.com/support/network/adapter/pro100/21397.htm 42 http://support.intel.com/support/network/adapter/pro100/21397.htm
30 43
31For the latest Intel network drivers for Linux, refer to the following 44For the latest Intel network drivers for Linux, refer to the following
32website. In the search field, enter your adapter name or type, or use the 45website. In the search field, enter your adapter name or type, or use the
33networking link on the left to search for your adapter: 46networking link on the left to search for your adapter:
34 47
35 http://downloadfinder.intel.com/scripts-df/support_intel.asp 48 http://downloadfinder.intel.com/scripts-df/support_intel.asp
@@ -40,73 +53,75 @@ Driver Configuration Parameters
40The default value for each parameter is generally the recommended setting, 53The default value for each parameter is generally the recommended setting,
41unless otherwise noted. 54unless otherwise noted.
42 55
43Rx Descriptors: Number of receive descriptors. A receive descriptor is a data 56Rx Descriptors: Number of receive descriptors. A receive descriptor is a data
44 structure that describes a receive buffer and its attributes to the network 57 structure that describes a receive buffer and its attributes to the network
45 controller. The data in the descriptor is used by the controller to write 58 controller. The data in the descriptor is used by the controller to write
46 data from the controller to host memory. In the 3.0.x driver the valid 59 data from the controller to host memory. In the 3.x.x driver the valid range
47 range for this parameter is 64-256. The default value is 64. This parameter 60 for this parameter is 64-256. The default value is 64. This parameter can be
48 can be changed using the command 61 changed using the command:
49 62
50 ethtool -G eth? rx n, where n is the number of desired rx descriptors. 63 ethtool -G eth? rx n, where n is the number of desired rx descriptors.
51 64
52Tx Descriptors: Number of transmit descriptors. A transmit descriptor is a 65Tx Descriptors: Number of transmit descriptors. A transmit descriptor is a data
53 data structure that describes a transmit buffer and its attributes to the 66 structure that describes a transmit buffer and its attributes to the network
54 network controller. The data in the descriptor is used by the controller to 67 controller. The data in the descriptor is used by the controller to read
55 read data from the host memory to the controller. In the 3.0.x driver the 68 data from the host memory to the controller. In the 3.x.x driver the valid
56 valid range for this parameter is 64-256. The default value is 64. This 69 range for this parameter is 64-256. The default value is 64. This parameter
57 parameter can be changed using the command 70 can be changed using the command:
58 71
59 ethtool -G eth? tx n, where n is the number of desired tx descriptors. 72 ethtool -G eth? tx n, where n is the number of desired tx descriptors.
60 73
61Speed/Duplex: The driver auto-negotiates the link speed and duplex settings by 74Speed/Duplex: The driver auto-negotiates the link speed and duplex settings by
62 default. Ethtool can be used as follows to force speed/duplex. 75 default. Ethtool can be used as follows to force speed/duplex.
63 76
64 ethtool -s eth? autoneg off speed {10|100} duplex {full|half} 77 ethtool -s eth? autoneg off speed {10|100} duplex {full|half}
65 78
66 NOTE: setting the speed/duplex to incorrect values will cause the link to 79 NOTE: setting the speed/duplex to incorrect values will cause the link to
67 fail. 80 fail.
68 81
69Event Log Message Level: The driver uses the message level flag to log events 82Event Log Message Level: The driver uses the message level flag to log events
70 to syslog. The message level can be set at driver load time. It can also be 83 to syslog. The message level can be set at driver load time. It can also be
71 set using the command 84 set using the command:
72 85
73 ethtool -s eth? msglvl n 86 ethtool -s eth? msglvl n
74 87
88
75Additional Configurations 89Additional Configurations
76========================= 90=========================
77 91
78 Configuring the Driver on Different Distributions 92 Configuring the Driver on Different Distributions
79 ------------------------------------------------- 93 -------------------------------------------------
80 94
81 Configuring a network driver to load properly when the system is started is 95 Configuring a network driver to load properly when the system is started is
82 distribution dependent. Typically, the configuration process involves adding 96 distribution dependent. Typically, the configuration process involves adding
83 an alias line to /etc/modules.conf as well as editing other system startup 97 an alias line to /etc/modules.conf or /etc/modprobe.conf as well as editing
84 scripts and/or configuration files. Many popular Linux distributions ship 98 other system startup scripts and/or configuration files. Many popular Linux
85 with tools to make these changes for you. To learn the proper way to 99 distributions ship with tools to make these changes for you. To learn the
86 configure a network device for your system, refer to your distribution 100 proper way to configure a network device for your system, refer to your
87 documentation. If during this process you are asked for the driver or module 101 distribution documentation. If during this process you are asked for the
88 name, the name for the Linux Base Driver for the Intel PRO/100 Family of 102 driver or module name, the name for the Linux Base Driver for the Intel
89 Adapters is e100. 103 PRO/100 Family of Adapters is e100.
90 104
91 As an example, if you install the e100 driver for two PRO/100 adapters 105 As an example, if you install the e100 driver for two PRO/100 adapters
92 (eth0 and eth1), add the following to modules.conf: 106 (eth0 and eth1), add the following to modules.conf or modprobe.conf:
93 107
94 alias eth0 e100 108 alias eth0 e100
95 alias eth1 e100 109 alias eth1 e100
96 110
97 Viewing Link Messages 111 Viewing Link Messages
98 --------------------- 112 ---------------------
99 In order to see link messages and other Intel driver information on your 113 In order to see link messages and other Intel driver information on your
100 console, you must set the dmesg level up to six. This can be done by 114 console, you must set the dmesg level up to six. This can be done by
101 entering the following on the command line before loading the e100 driver: 115 entering the following on the command line before loading the e100 driver:
102 116
103 dmesg -n 8 117 dmesg -n 8
104 118
105 If you wish to see all messages issued by the driver, including debug 119 If you wish to see all messages issued by the driver, including debug
106 messages, set the dmesg level to eight. 120 messages, set the dmesg level to eight.
107 121
108 NOTE: This setting is not saved across reboots. 122 NOTE: This setting is not saved across reboots.
109 123
124
110 Ethtool 125 Ethtool
111 ------- 126 -------
112 127
@@ -114,29 +129,27 @@ Additional Configurations
114 diagnostics, as well as displaying statistical information. Ethtool 129 diagnostics, as well as displaying statistical information. Ethtool
115 version 1.6 or later is required for this functionality. 130 version 1.6 or later is required for this functionality.
116 131
117 The latest release of ethtool can be found at: 132 The latest release of ethtool can be found from
118 http://sf.net/projects/gkernel. 133 http://sourceforge.net/projects/gkernel.
119 134
120 NOTE: This driver uses mii support from the kernel. As a result, when 135 NOTE: Ethtool 1.6 only supports a limited set of ethtool options. Support
121 there is no link, ethtool will report speed/duplex to be 10/half. 136 for a more complete ethtool feature set can be enabled by upgrading
137 ethtool to ethtool-1.8.1.
122 138
123 NOTE: Ethtool 1.6 only supports a limited set of ethtool options. Support
124 for a more complete ethtool feature set can be enabled by upgrading
125 ethtool to ethtool-1.8.1.
126 139
127 Enabling Wake on LAN* (WoL) 140 Enabling Wake on LAN* (WoL)
128 --------------------------- 141 ---------------------------
129 WoL is provided through the Ethtool* utility. Ethtool is included with Red 142 WoL is provided through the Ethtool* utility. Ethtool is included with Red
130 Hat* 8.0. For other Linux distributions, download and install Ethtool from 143 Hat* 8.0. For other Linux distributions, download and install Ethtool from
131 the following website: http://sourceforge.net/projects/gkernel. 144 the following website: http://sourceforge.net/projects/gkernel.
132 145
133 For instructions on enabling WoL with Ethtool, refer to the Ethtool man 146 For instructions on enabling WoL with Ethtool, refer to the Ethtool man page.
134 page.
135 147
136 WoL will be enabled on the system during the next shut down or reboot. For 148 WoL will be enabled on the system during the next shut down or reboot. For
137 this driver version, in order to enable WoL, the e100 driver must be 149 this driver version, in order to enable WoL, the e100 driver must be
138 loaded when shutting down or rebooting the system. 150 loaded when shutting down or rebooting the system.
139 151
152
140 NAPI 153 NAPI
141 ---- 154 ----
142 155
@@ -144,6 +157,25 @@ Additional Configurations
144 157
145 See www.cyberus.ca/~hadi/usenix-paper.tgz for more information on NAPI. 158 See www.cyberus.ca/~hadi/usenix-paper.tgz for more information on NAPI.
146 159
160 Multiple Interfaces on Same Ethernet Broadcast Network
161 ------------------------------------------------------
162
163 Due to the default ARP behavior on Linux, it is not possible to have
164 one system on two IP networks in the same Ethernet broadcast domain
165 (non-partitioned switch) behave as expected. All Ethernet interfaces
166 will respond to IP traffic for any IP address assigned to the system.
167 This results in unbalanced receive traffic.
168
169 If you have multiple interfaces in a server, either turn on ARP
170 filtering by
171
172 (1) entering: echo 1 > /proc/sys/net/ipv4/conf/all/arp_filter
173 (this only works if your kernel's version is higher than 2.4.5), or
174
175 (2) installing the interfaces in separate broadcast domains (either
176 in different switches or in a switch partitioned to VLANs).
177
178
147Support 179Support
148======= 180=======
149 181
@@ -151,20 +183,24 @@ For general information, go to the Intel support website at:
151 183
152 http://support.intel.com 184 http://support.intel.com
153 185
186 or the Intel Wired Networking project hosted by Sourceforge at:
187
188 http://sourceforge.net/projects/e1000
189
154If an issue is identified with the released source code on the supported 190If an issue is identified with the released source code on the supported
155kernel with a supported adapter, email the specific information related to 191kernel with a supported adapter, email the specific information related to the
156the issue to linux.nics@intel.com. 192issue to e1000-devel@lists.sourceforge.net.
157 193
158 194
159License 195License
160======= 196=======
161 197
162This software program is released under the terms of a license agreement 198This software program is released under the terms of a license agreement
163between you ('Licensee') and Intel. Do not use or load this software or any 199between you ('Licensee') and Intel. Do not use or load this software or any
164associated materials (collectively, the 'Software') until you have carefully 200associated materials (collectively, the 'Software') until you have carefully
165read the full terms and conditions of the LICENSE located in this software 201read the full terms and conditions of the file COPYING located in this software
166package. By loading or using the Software, you agree to the terms of this 202package. By loading or using the Software, you agree to the terms of this
167Agreement. If you do not agree with the terms of this Agreement, do not 203Agreement. If you do not agree with the terms of this Agreement, do not install
168install or use the Software. 204or use the Software.
169 205
170* Other names and brands may be claimed as the property of others. 206* Other names and brands may be claimed as the property of others.
diff --git a/Documentation/networking/e1000.txt b/Documentation/networking/e1000.txt
index 2ebd4058d46d..71fe15af356c 100644
--- a/Documentation/networking/e1000.txt
+++ b/Documentation/networking/e1000.txt
@@ -1,7 +1,7 @@
1Linux* Base Driver for the Intel(R) PRO/1000 Family of Adapters 1Linux* Base Driver for the Intel(R) PRO/1000 Family of Adapters
2=============================================================== 2===============================================================
3 3
4November 17, 2004 4November 15, 2005
5 5
6 6
7Contents 7Contents
@@ -20,254 +20,316 @@ In This Release
20=============== 20===============
21 21
22This file describes the Linux* Base Driver for the Intel(R) PRO/1000 Family 22This file describes the Linux* Base Driver for the Intel(R) PRO/1000 Family
23of Adapters, version 5.x.x. 23of Adapters. This driver includes support for Itanium(R)2-based systems.
24 24
25For questions related to hardware requirements, refer to the documentation 25For questions related to hardware requirements, refer to the documentation
26supplied with your Intel PRO/1000 adapter. All hardware requirements listed 26supplied with your Intel PRO/1000 adapter. All hardware requirements listed
27apply to use with Linux. 27apply to use with Linux.
28 28
29Native VLANs are now available with supported kernels. 29The following features are now available in supported kernels:
30 - Native VLANs
31 - Channel Bonding (teaming)
32 - SNMP
33
34Channel Bonding documentation can be found in the Linux kernel source:
35/Documentation/networking/bonding.txt
36
37The driver information previously displayed in the /proc filesystem is not
38supported in this release. Alternatively, you can use ethtool (version 1.6
39or later), lspci, and ifconfig to obtain the same information.
40
41Instructions on updating ethtool can be found in the section "Additional
42Configurations" later in this document.
43
30 44
31Identifying Your Adapter 45Identifying Your Adapter
32======================== 46========================
33 47
34For more information on how to identify your adapter, go to the Adapter & 48For more information on how to identify your adapter, go to the Adapter &
35Driver ID Guide at: 49Driver ID Guide at:
36 50
37 http://support.intel.com/support/network/adapter/pro100/21397.htm 51 http://support.intel.com/support/network/adapter/pro100/21397.htm
38 52
39For the latest Intel network drivers for Linux, refer to the following 53For the latest Intel network drivers for Linux, refer to the following
40website. In the search field, enter your adapter name or type, or use the 54website. In the search field, enter your adapter name or type, or use the
41networking link on the left to search for your adapter: 55networking link on the left to search for your adapter:
42 56
43 http://downloadfinder.intel.com/scripts-df/support_intel.asp 57 http://downloadfinder.intel.com/scripts-df/support_intel.asp
44 58
45Command Line Parameters
46=======================
47 59
48If the driver is built as a module, the following optional parameters are 60Command Line Parameters =======================
49used by entering them on the command line with the modprobe or insmod command 61
50using this syntax: 62If the driver is built as a module, the following optional parameters
63are used by entering them on the command line with the modprobe or insmod
64command using this syntax:
51 65
52 modprobe e1000 [<option>=<VAL1>,<VAL2>,...] 66 modprobe e1000 [<option>=<VAL1>,<VAL2>,...]
53 67
54 insmod e1000 [<option>=<VAL1>,<VAL2>,...] 68 insmod e1000 [<option>=<VAL1>,<VAL2>,...]
55 69
56For example, with two PRO/1000 PCI adapters, entering: 70For example, with two PRO/1000 PCI adapters, entering:
57 71
58 insmod e1000 TxDescriptors=80,128 72 insmod e1000 TxDescriptors=80,128
59 73
60loads the e1000 driver with 80 TX descriptors for the first adapter and 128 TX 74loads the e1000 driver with 80 TX descriptors for the first adapter and 128
61descriptors for the second adapter. 75TX descriptors for the second adapter.
62 76
63The default value for each parameter is generally the recommended setting, 77The default value for each parameter is generally the recommended setting,
64unless otherwise noted. Also, if the driver is statically built into the 78unless otherwise noted.
65kernel, the driver is loaded with the default values for all the parameters. 79
66Ethtool can be used to change some of the parameters at runtime. 80NOTES: For more information about the AutoNeg, Duplex, and Speed
81 parameters, see the "Speed and Duplex Configuration" section in
82 this document.
67 83
68 NOTES: For more information about the AutoNeg, Duplex, and Speed 84 For more information about the InterruptThrottleRate,
69 parameters, see the "Speed and Duplex Configuration" section in 85 RxIntDelay, TxIntDelay, RxAbsIntDelay, and TxAbsIntDelay
70 this document. 86 parameters, see the application note at:
87 http://www.intel.com/design/network/applnots/ap450.htm
71 88
72 For more information about the InterruptThrottleRate, RxIntDelay, 89 A descriptor describes a data buffer and attributes related to
73 TxIntDelay, RxAbsIntDelay, and TxAbsIntDelay parameters, see the 90 the data buffer. This information is accessed by the hardware.
74 application note at:
75 http://www.intel.com/design/network/applnots/ap450.htm
76 91
77 A descriptor describes a data buffer and attributes related to the
78 data buffer. This information is accessed by the hardware.
79 92
80AutoNeg (adapters using copper connections only) 93AutoNeg
81Valid Range: 0x01-0x0F, 0x20-0x2F 94-------
95(Supported only on adapters with copper connections)
96Valid Range: 0x01-0x0F, 0x20-0x2F
82Default Value: 0x2F 97Default Value: 0x2F
83 This parameter is a bit mask that specifies which speed and duplex 98
84 settings the board advertises. When this parameter is used, the Speed and 99This parameter is a bit mask that specifies which speed and duplex
85 Duplex parameters must not be specified. 100settings the board advertises. When this parameter is used, the Speed
86 NOTE: Refer to the Speed and Duplex section of this readme for more 101and Duplex parameters must not be specified.
87 information on the AutoNeg parameter. 102
88 103NOTE: Refer to the Speed and Duplex section of this readme for more
89Duplex (adapters using copper connections only) 104 information on the AutoNeg parameter.
90Valid Range: 0-2 (0=auto-negotiate, 1=half, 2=full) 105
106
107Duplex
108------
109(Supported only on adapters with copper connections)
110Valid Range: 0-2 (0=auto-negotiate, 1=half, 2=full)
91Default Value: 0 111Default Value: 0
92 Defines the direction in which data is allowed to flow. Can be either one 112
93 or two-directional. If both Duplex and the link partner are set to auto- 113Defines the direction in which data is allowed to flow. Can be either
94 negotiate, the board auto-detects the correct duplex. If the link partner 114one or two-directional. If both Duplex and the link partner are set to
95 is forced (either full or half), Duplex defaults to half-duplex. 115auto-negotiate, the board auto-detects the correct duplex. If the link
116partner is forced (either full or half), Duplex defaults to half-duplex.
117
96 118
97FlowControl 119FlowControl
98Valid Range: 0-3 (0=none, 1=Rx only, 2=Tx only, 3=Rx&Tx) 120----------
99Default: Read flow control settings from the EEPROM 121Valid Range: 0-3 (0=none, 1=Rx only, 2=Tx only, 3=Rx&Tx)
100 This parameter controls the automatic generation(Tx) and response(Rx) to 122Default Value: Reads flow control settings from the EEPROM
101 Ethernet PAUSE frames. 123
124This parameter controls the automatic generation(Tx) and response(Rx)
125to Ethernet PAUSE frames.
126
102 127
103InterruptThrottleRate 128InterruptThrottleRate
104Valid Range: 100-100000 (0=off, 1=dynamic) 129---------------------
130(not supported on Intel 82542, 82543 or 82544-based adapters)
131Valid Range: 100-100000 (0=off, 1=dynamic)
105Default Value: 8000 132Default Value: 8000
106 This value represents the maximum number of interrupts per second the 133
107 controller generates. InterruptThrottleRate is another setting used in 134This value represents the maximum number of interrupts per second the
108 interrupt moderation. Dynamic mode uses a heuristic algorithm to adjust 135controller generates. InterruptThrottleRate is another setting used in
109 InterruptThrottleRate based on the current traffic load. 136interrupt moderation. Dynamic mode uses a heuristic algorithm to adjust
110Un-supported Adapters: InterruptThrottleRate is NOT supported by 82542, 82543 137InterruptThrottleRate based on the current traffic load.
111 or 82544-based adapters. 138
112 139NOTE: InterruptThrottleRate takes precedence over the TxAbsIntDelay and
113 NOTE: InterruptThrottleRate takes precedence over the TxAbsIntDelay and 140 RxAbsIntDelay parameters. In other words, minimizing the receive
114 RxAbsIntDelay parameters. In other words, minimizing the receive 141 and/or transmit absolute delays does not force the controller to
115 and/or transmit absolute delays does not force the controller to 142 generate more interrupts than what the Interrupt Throttle Rate
116 generate more interrupts than what the Interrupt Throttle Rate 143 allows.
117 allows. 144
118 CAUTION: If you are using the Intel PRO/1000 CT Network Connection 145CAUTION: If you are using the Intel PRO/1000 CT Network Connection
119 (controller 82547), setting InterruptThrottleRate to a value 146 (controller 82547), setting InterruptThrottleRate to a value
120 greater than 75,000, may hang (stop transmitting) adapters under 147 greater than 75,000, may hang (stop transmitting) adapters
121 certain network conditions. If this occurs a NETDEV WATCHDOG 148 under certain network conditions. If this occurs a NETDEV
122 message is logged in the system event log. In addition, the 149 WATCHDOG message is logged in the system event log. In
123 controller is automatically reset, restoring the network 150 addition, the controller is automatically reset, restoring
124 connection. To eliminate the potential for the hang, ensure 151 the network connection. To eliminate the potential for the
125 that InterruptThrottleRate is set no greater than 75,000 and is 152 hang, ensure that InterruptThrottleRate is set no greater
126 not set to 0. 153 than 75,000 and is not set to 0.
127 NOTE: When e1000 is loaded with default settings and multiple adapters are 154
128 in use simultaneously, the CPU utilization may increase non-linearly. 155NOTE: When e1000 is loaded with default settings and multiple adapters
129 In order to limit the CPU utilization without impacting the overall 156 are in use simultaneously, the CPU utilization may increase non-
130 throughput, we recommend that you load the driver as follows: 157 linearly. In order to limit the CPU utilization without impacting
131 158 the overall throughput, we recommend that you load the driver as
132 insmod e1000.o InterruptThrottleRate=3000,3000,3000 159 follows:
133 160
134 This sets the InterruptThrottleRate to 3000 interrupts/sec for the 161 insmod e1000.o InterruptThrottleRate=3000,3000,3000
135 first, second, and third instances of the driver. The range of 2000 to 162
136 3000 interrupts per second works on a majority of systems and is a 163 This sets the InterruptThrottleRate to 3000 interrupts/sec for
137 good starting point, but the optimal value will be platform-specific. 164 the first, second, and third instances of the driver. The range
138 If CPU utilization is not a concern, use RX_POLLING (NAPI) and default 165 of 2000 to 3000 interrupts per second works on a majority of
139 driver settings. 166 systems and is a good starting point, but the optimal value will
167 be platform-specific. If CPU utilization is not a concern, use
168 RX_POLLING (NAPI) and default driver settings.
169
140 170
141RxDescriptors 171RxDescriptors
142Valid Range: 80-256 for 82542 and 82543-based adapters 172-------------
143 80-4096 for all other supported adapters 173Valid Range: 80-256 for 82542 and 82543-based adapters
174 80-4096 for all other supported adapters
144Default Value: 256 175Default Value: 256
145 This value is the number of receive descriptors allocated by the driver.
146 Increasing this value allows the driver to buffer more incoming packets.
147 Each descriptor is 16 bytes. A receive buffer is allocated for each
148 descriptor and can either be 2048 or 4096 bytes long, depending on the MTU
149 176
150 setting. An incoming packet can span one or more receive descriptors. 177This value specifies the number of receive descriptors allocated by the
151 The maximum MTU size is 16110. 178driver. Increasing this value allows the driver to buffer more incoming
179packets. Each descriptor is 16 bytes. A receive buffer is also
180allocated for each descriptor and is 2048.
152 181
153 NOTE: MTU designates the frame size. It only needs to be set for Jumbo
154 Frames.
155 NOTE: Depending on the available system resources, the request for a
156 higher number of receive descriptors may be denied. In this case,
157 use a lower number.
158 182
159RxIntDelay 183RxIntDelay
160Valid Range: 0-65535 (0=off) 184----------
185Valid Range: 0-65535 (0=off)
161Default Value: 0 186Default Value: 0
162 This value delays the generation of receive interrupts in units of 1.024 187
163 microseconds. Receive interrupt reduction can improve CPU efficiency if 188This value delays the generation of receive interrupts in units of 1.024
164 properly tuned for specific network traffic. Increasing this value adds 189microseconds. Receive interrupt reduction can improve CPU efficiency if
165 extra latency to frame reception and can end up decreasing the throughput 190properly tuned for specific network traffic. Increasing this value adds
166 of TCP traffic. If the system is reporting dropped receives, this value 191extra latency to frame reception and can end up decreasing the throughput
167 may be set too high, causing the driver to run out of available receive 192of TCP traffic. If the system is reporting dropped receives, this value
168 descriptors. 193may be set too high, causing the driver to run out of available receive
169 194descriptors.
170 CAUTION: When setting RxIntDelay to a value other than 0, adapters may 195
171 hang (stop transmitting) under certain network conditions. If 196CAUTION: When setting RxIntDelay to a value other than 0, adapters may
172 this occurs a NETDEV WATCHDOG message is logged in the system 197 hang (stop transmitting) under certain network conditions. If
173 event log. In addition, the controller is automatically reset, 198 this occurs a NETDEV WATCHDOG message is logged in the system
174 restoring the network connection. To eliminate the potential for 199 event log. In addition, the controller is automatically reset,
175 the hang ensure that RxIntDelay is set to 0. 200 restoring the network connection. To eliminate the potential
176 201 for the hang ensure that RxIntDelay is set to 0.
177RxAbsIntDelay (82540, 82545 and later adapters only) 202
178Valid Range: 0-65535 (0=off) 203
204RxAbsIntDelay
205-------------
206(This parameter is supported only on 82540, 82545 and later adapters.)
207Valid Range: 0-65535 (0=off)
179Default Value: 128 208Default Value: 128
180 This value, in units of 1.024 microseconds, limits the delay in which a 209
181 receive interrupt is generated. Useful only if RxIntDelay is non-zero, 210This value, in units of 1.024 microseconds, limits the delay in which a
182 this value ensures that an interrupt is generated after the initial 211receive interrupt is generated. Useful only if RxIntDelay is non-zero,
183 packet is received within the set amount of time. Proper tuning, 212this value ensures that an interrupt is generated after the initial
184 along with RxIntDelay, may improve traffic throughput in specific network 213packet is received within the set amount of time. Proper tuning,
185 conditions. 214along with RxIntDelay, may improve traffic throughput in specific network
186 215conditions.
187Speed (adapters using copper connections only) 216
217
218Speed
219-----
220(This parameter is supported only on adapters with copper connections.)
188Valid Settings: 0, 10, 100, 1000 221Valid Settings: 0, 10, 100, 1000
189Default Value: 0 (auto-negotiate at all supported speeds) 222Default Value: 0 (auto-negotiate at all supported speeds)
190 Speed forces the line speed to the specified value in megabits per second 223
191 (Mbps). If this parameter is not specified or is set to 0 and the link 224Speed forces the line speed to the specified value in megabits per second
192 partner is set to auto-negotiate, the board will auto-detect the correct 225(Mbps). If this parameter is not specified or is set to 0 and the link
193 speed. Duplex should also be set when Speed is set to either 10 or 100. 226partner is set to auto-negotiate, the board will auto-detect the correct
227speed. Duplex should also be set when Speed is set to either 10 or 100.
228
194 229
195TxDescriptors 230TxDescriptors
196Valid Range: 80-256 for 82542 and 82543-based adapters 231-------------
197 80-4096 for all other supported adapters 232Valid Range: 80-256 for 82542 and 82543-based adapters
233 80-4096 for all other supported adapters
198Default Value: 256 234Default Value: 256
199 This value is the number of transmit descriptors allocated by the driver.
200 Increasing this value allows the driver to queue more transmits. Each
201 descriptor is 16 bytes.
202 235
203 NOTE: Depending on the available system resources, the request for a 236This value is the number of transmit descriptors allocated by the driver.
204 higher number of transmit descriptors may be denied. In this case, 237Increasing this value allows the driver to queue more transmits. Each
205 use a lower number. 238descriptor is 16 bytes.
239
240NOTE: Depending on the available system resources, the request for a
241 higher number of transmit descriptors may be denied. In this case,
242 use a lower number.
243
206 244
207TxIntDelay 245TxIntDelay
208Valid Range: 0-65535 (0=off) 246----------
247Valid Range: 0-65535 (0=off)
209Default Value: 64 248Default Value: 64
210 This value delays the generation of transmit interrupts in units of 249
211 1.024 microseconds. Transmit interrupt reduction can improve CPU 250This value delays the generation of transmit interrupts in units of
212 efficiency if properly tuned for specific network traffic. If the 2511.024 microseconds. Transmit interrupt reduction can improve CPU
213 system is reporting dropped transmits, this value may be set too high 252efficiency if properly tuned for specific network traffic. If the
214 causing the driver to run out of available transmit descriptors. 253system is reporting dropped transmits, this value may be set too high
215 254causing the driver to run out of available transmit descriptors.
216TxAbsIntDelay (82540, 82545 and later adapters only) 255
217Valid Range: 0-65535 (0=off) 256
257TxAbsIntDelay
258-------------
259(This parameter is supported only on 82540, 82545 and later adapters.)
260Valid Range: 0-65535 (0=off)
218Default Value: 64 261Default Value: 64
219 This value, in units of 1.024 microseconds, limits the delay in which a 262
220 transmit interrupt is generated. Useful only if TxIntDelay is non-zero, 263This value, in units of 1.024 microseconds, limits the delay in which a
221 this value ensures that an interrupt is generated after the initial 264transmit interrupt is generated. Useful only if TxIntDelay is non-zero,
222 packet is sent on the wire within the set amount of time. Proper tuning, 265this value ensures that an interrupt is generated after the initial
223 along with TxIntDelay, may improve traffic throughput in specific 266packet is sent on the wire within the set amount of time. Proper tuning,
224 network conditions. 267along with TxIntDelay, may improve traffic throughput in specific
225 268network conditions.
226XsumRX (not available on the 82542-based adapter) 269
227Valid Range: 0-1 270XsumRX
271------
272(This parameter is NOT supported on the 82542-based adapter.)
273Valid Range: 0-1
228Default Value: 1 274Default Value: 1
229 A value of '1' indicates that the driver should enable IP checksum 275
230 offload for received packets (both UDP and TCP) to the adapter hardware. 276A value of '1' indicates that the driver should enable IP checksum
277offload for received packets (both UDP and TCP) to the adapter hardware.
278
231 279
232Speed and Duplex Configuration 280Speed and Duplex Configuration
233============================== 281==============================
234 282
235Three keywords are used to control the speed and duplex configuration. These 283Three keywords are used to control the speed and duplex configuration.
236keywords are Speed, Duplex, and AutoNeg. 284These keywords are Speed, Duplex, and AutoNeg.
237 285
238If the board uses a fiber interface, these keywords are ignored, and the 286If the board uses a fiber interface, these keywords are ignored, and the
239fiber interface board only links at 1000 Mbps full-duplex. 287fiber interface board only links at 1000 Mbps full-duplex.
240 288
241For copper-based boards, the keywords interact as follows: 289For copper-based boards, the keywords interact as follows:
242 290
243 The default operation is auto-negotiate. The board advertises all supported 291 The default operation is auto-negotiate. The board advertises all
244 speed and duplex combinations, and it links at the highest common speed and 292 supported speed and duplex combinations, and it links at the highest
245 duplex mode IF the link partner is set to auto-negotiate. 293 common speed and duplex mode IF the link partner is set to auto-negotiate.
246 294
247 If Speed = 1000, limited auto-negotiation is enabled and only 1000 Mbps is 295 If Speed = 1000, limited auto-negotiation is enabled and only 1000 Mbps
248 advertised (The 1000BaseT spec requires auto-negotiation.) 296 is advertised (The 1000BaseT spec requires auto-negotiation.)
249 297
250 If Speed = 10 or 100, then both Speed and Duplex should be set. Auto- 298 If Speed = 10 or 100, then both Speed and Duplex should be set. Auto-
251 negotiation is disabled, and the AutoNeg parameter is ignored. Partner SHOULD 299 negotiation is disabled, and the AutoNeg parameter is ignored. Partner
252 also be forced. 300 SHOULD also be forced.
301
302The AutoNeg parameter is used when more control is required over the
303auto-negotiation process. It should be used when you wish to control which
304speed and duplex combinations are advertised during the auto-negotiation
305process.
306
307The parameter may be specified as either a decimal or hexidecimal value as
308determined by the bitmap below.
253 309
254The AutoNeg parameter is used when more control is required over the auto- 310Bit position 7 6 5 4 3 2 1 0
255negotiation process. When this parameter is used, Speed and Duplex parameters 311Decimal Value 128 64 32 16 8 4 2 1
256must not be specified. The following table describes supported values for the 312Hex value 80 40 20 10 8 4 2 1
257AutoNeg parameter: 313Speed (Mbps) N/A N/A 1000 N/A 100 100 10 10
314Duplex Full Full Half Full Half
258 315
259Speed (Mbps) 1000 100 100 10 10 316Some examples of using AutoNeg:
260Duplex Full Full Half Full Half
261Value (in base 16) 0x20 0x08 0x04 0x02 0x01
262 317
263Example: insmod e1000 AutoNeg=0x03, loads e1000 and specifies (10 full duplex, 318 modprobe e1000 AutoNeg=0x01 (Restricts autonegotiation to 10 Half)
26410 half duplex) for negotiation with the peer. 319 modprobe e1000 AutoNeg=1 (Same as above)
320 modprobe e1000 AutoNeg=0x02 (Restricts autonegotiation to 10 Full)
321 modprobe e1000 AutoNeg=0x03 (Restricts autonegotiation to 10 Half or 10 Full)
322 modprobe e1000 AutoNeg=0x04 (Restricts autonegotiation to 100 Half)
323 modprobe e1000 AutoNeg=0x05 (Restricts autonegotiation to 10 Half or 100
324 Half)
325 modprobe e1000 AutoNeg=0x020 (Restricts autonegotiation to 1000 Full)
326 modprobe e1000 AutoNeg=32 (Same as above)
265 327
266Note that setting AutoNeg does not guarantee that the board will link at the 328Note that when this parameter is used, Speed and Duplex must not be specified.
267highest specified speed or duplex mode, but the board will link at the 329
268highest possible speed/duplex of the link partner IF the link partner is also 330If the link partner is forced to a specific speed and duplex, then this
269set to auto-negotiate. If the link partner is forced speed/duplex, the 331parameter should not be used. Instead, use the Speed and Duplex parameters
270adapter MUST be forced to the same speed/duplex. 332previously mentioned to force the adapter to the same speed and duplex.
271 333
272 334
273Additional Configurations 335Additional Configurations
@@ -276,19 +338,19 @@ Additional Configurations
276 Configuring the Driver on Different Distributions 338 Configuring the Driver on Different Distributions
277 ------------------------------------------------- 339 -------------------------------------------------
278 340
279 Configuring a network driver to load properly when the system is started is 341 Configuring a network driver to load properly when the system is started
280 distribution dependent. Typically, the configuration process involves adding 342 is distribution dependent. Typically, the configuration process involves
281 an alias line to /etc/modules.conf as well as editing other system startup 343 adding an alias line to /etc/modules.conf or /etc/modprobe.conf as well
282 scripts and/or configuration files. Many popular Linux distributions ship 344 as editing other system startup scripts and/or configuration files. Many
283 with tools to make these changes for you. To learn the proper way to 345 popular Linux distributions ship with tools to make these changes for you.
284 configure a network device for your system, refer to your distribution 346 To learn the proper way to configure a network device for your system,
285 documentation. If during this process you are asked for the driver or module 347 refer to your distribution documentation. If during this process you are
286 name, the name for the Linux Base Driver for the Intel PRO/1000 Family of 348 asked for the driver or module name, the name for the Linux Base Driver
287 Adapters is e1000. 349 for the Intel PRO/1000 Family of Adapters is e1000.
288 350
289 As an example, if you install the e1000 driver for two PRO/1000 adapters 351 As an example, if you install the e1000 driver for two PRO/1000 adapters
290 (eth0 and eth1) and set the speed and duplex to 10full and 100half, add the 352 (eth0 and eth1) and set the speed and duplex to 10full and 100half, add
291 following to modules.conf: 353 the following to modules.conf or or modprobe.conf:
292 354
293 alias eth0 e1000 355 alias eth0 e1000
294 alias eth1 e1000 356 alias eth1 e1000
@@ -297,9 +359,9 @@ Additional Configurations
297 Viewing Link Messages 359 Viewing Link Messages
298 --------------------- 360 ---------------------
299 361
300 Link messages will not be displayed to the console if the distribution is 362 Link messages will not be displayed to the console if the distribution is
301 restricting system messages. In order to see network driver link messages on 363 restricting system messages. In order to see network driver link messages
302 your console, set dmesg to eight by entering the following: 364 on your console, set dmesg to eight by entering the following:
303 365
304 dmesg -n 8 366 dmesg -n 8
305 367
@@ -308,22 +370,42 @@ Additional Configurations
308 Jumbo Frames 370 Jumbo Frames
309 ------------ 371 ------------
310 372
311 The driver supports Jumbo Frames for all adapters except 82542-based 373 The driver supports Jumbo Frames for all adapters except 82542 and
312 adapters. Jumbo Frames support is enabled by changing the MTU to a value 374 82573-based adapters. Jumbo Frames support is enabled by changing the
313 larger than the default of 1500. Use the ifconfig command to increase the 375 MTU to a value larger than the default of 1500. Use the ifconfig command
314 MTU size. For example: 376 to increase the MTU size. For example:
377
378 ifconfig eth<x> mtu 9000 up
379
380 This setting is not saved across reboots. It can be made permanent if
381 you add:
382
383 MTU=9000
315 384
316 ifconfig ethx mtu 9000 up 385 to the file /etc/sysconfig/network-scripts/ifcfg-eth<x>. This example
386 applies to the Red Hat distributions; other distributions may store this
387 setting in a different location.
317 388
318 The maximum MTU setting for Jumbo Frames is 16110. This value coincides 389 Notes:
319 with the maximum Jumbo Frames size of 16128.
320 390
321 NOTE: Jumbo Frames are supported at 1000 Mbps only. Using Jumbo Frames at 391 - To enable Jumbo Frames, increase the MTU size on the interface beyond
322 10 or 100 Mbps may result in poor performance or loss of link. 392 1500.
393 - The maximum MTU setting for Jumbo Frames is 16110. This value coincides
394 with the maximum Jumbo Frames size of 16128.
395 - Using Jumbo Frames at 10 or 100 Mbps may result in poor performance or
396 loss of link.
397 - Some Intel gigabit adapters that support Jumbo Frames have a frame size
398 limit of 9238 bytes, with a corresponding MTU size limit of 9216 bytes.
399 The adapters with this limitation are based on the Intel 82571EB and
400 82572EI controllers, which correspond to these product names:
401 Intel® PRO/1000 PT Dual Port Server Adapter
402 Intel® PRO/1000 PF Dual Port Server Adapter
403 Intel® PRO/1000 PT Server Adapter
404 Intel® PRO/1000 PT Desktop Adapter
405 Intel® PRO/1000 PF Server Adapter
323 406
407 - The Intel PRO/1000 PM Network Connection does not support jumbo frames.
324 408
325 NOTE: MTU designates the frame size. To enable Jumbo Frames, increase the
326 MTU size on the interface beyond 1500.
327 409
328 Ethtool 410 Ethtool
329 ------- 411 -------
@@ -333,32 +415,41 @@ Additional Configurations
333 version 1.6 or later is required for this functionality. 415 version 1.6 or later is required for this functionality.
334 416
335 The latest release of ethtool can be found from 417 The latest release of ethtool can be found from
336 http://sf.net/projects/gkernel. 418 http://sourceforge.net/projects/gkernel.
337 419
338 NOTE: Ethtool 1.6 only supports a limited set of ethtool options. Support 420 NOTE: Ethtool 1.6 only supports a limited set of ethtool options. Support
339 for a more complete ethtool feature set can be enabled by upgrading 421 for a more complete ethtool feature set can be enabled by upgrading
340 ethtool to ethtool-1.8.1. 422 ethtool to ethtool-1.8.1.
341 423
342 Enabling Wake on LAN* (WoL) 424 Enabling Wake on LAN* (WoL)
343 --------------------------- 425 ---------------------------
344 426
345 WoL is configured through the Ethtool* utility. Ethtool is included with 427 WoL is configured through the Ethtool* utility. Ethtool is included with
346 all versions of Red Hat after Red Hat 7.2. For other Linux distributions, 428 all versions of Red Hat after Red Hat 7.2. For other Linux distributions,
347 download and install Ethtool from the following website: 429 download and install Ethtool from the following website:
348 http://sourceforge.net/projects/gkernel. 430 http://sourceforge.net/projects/gkernel.
349 431
350 For instructions on enabling WoL with Ethtool, refer to the website listed 432 For instructions on enabling WoL with Ethtool, refer to the website listed
351 above. 433 above.
352 434
353 WoL will be enabled on the system during the next shut down or reboot. 435 WoL will be enabled on the system during the next shut down or reboot.
354 For this driver version, in order to enable WoL, the e1000 driver must be 436 For this driver version, in order to enable WoL, the e1000 driver must be
355 loaded when shutting down or rebooting the system. 437 loaded when shutting down or rebooting the system.
356 438
357 NAPI 439 NAPI
358 ---- 440 ----
359 441
360 NAPI (Rx polling mode) is supported in the e1000 driver. NAPI is enabled 442 NAPI (Rx polling mode) is supported in the e1000 driver. NAPI is enabled
361 or disabled based on the configuration of the kernel. 443 or disabled based on the configuration of the kernel. To override
444 the default, use the following compile-time flags.
445
446 To enable NAPI, compile the driver module, passing in a configuration option:
447
448 make CFLAGS_EXTRA=-DE1000_NAPI install
449
450 To disable NAPI, compile the driver module, passing in a configuration option:
451
452 make CFLAGS_EXTRA=-DE1000_NO_NAPI install
362 453
363 See www.cyberus.ca/~hadi/usenix-paper.tgz for more information on NAPI. 454 See www.cyberus.ca/~hadi/usenix-paper.tgz for more information on NAPI.
364 455
@@ -369,10 +460,85 @@ Known Issues
369 Jumbo Frames System Requirement 460 Jumbo Frames System Requirement
370 ------------------------------- 461 -------------------------------
371 462
372 Memory allocation failures have been observed on Linux systems with 64 MB 463 Memory allocation failures have been observed on Linux systems with 64 MB
373 of RAM or less that are running Jumbo Frames. If you are using Jumbo Frames, 464 of RAM or less that are running Jumbo Frames. If you are using Jumbo
374 your system may require more than the advertised minimum requirement of 64 MB 465 Frames, your system may require more than the advertised minimum
375 of system memory. 466 requirement of 64 MB of system memory.
467
468 Performance Degradation with Jumbo Frames
469 -----------------------------------------
470
471 Degradation in throughput performance may be observed in some Jumbo frames
472 environments. If this is observed, increasing the application's socket
473 buffer size and/or increasing the /proc/sys/net/ipv4/tcp_*mem entry values
474 may help. See the specific application manual and
475 /usr/src/linux*/Documentation/
476 networking/ip-sysctl.txt for more details.
477
478 Jumbo frames on Foundry BigIron 8000 switch
479 -------------------------------------------
480 There is a known issue using Jumbo frames when connected to a Foundry
481 BigIron 8000 switch. This is a 3rd party limitation. If you experience
482 loss of packets, lower the MTU size.
483
484 Multiple Interfaces on Same Ethernet Broadcast Network
485 ------------------------------------------------------
486
487 Due to the default ARP behavior on Linux, it is not possible to have
488 one system on two IP networks in the same Ethernet broadcast domain
489 (non-partitioned switch) behave as expected. All Ethernet interfaces
490 will respond to IP traffic for any IP address assigned to the system.
491 This results in unbalanced receive traffic.
492
493 If you have multiple interfaces in a server, either turn on ARP
494 filtering by entering:
495
496 echo 1 > /proc/sys/net/ipv4/conf/all/arp_filter
497 (this only works if your kernel's version is higher than 2.4.5),
498
499 NOTE: This setting is not saved across reboots. The configuration
500 change can be made permanent by adding the line:
501 net.ipv4.conf.all.arp_filter = 1
502 to the file /etc/sysctl.conf
503
504 or,
505
506 install the interfaces in separate broadcast domains (either in
507 different switches or in a switch partitioned to VLANs).
508
509 82541/82547 can't link or are slow to link with some link partners
510 -----------------------------------------------------------------
511
512 There is a known compatibility issue with 82541/82547 and some
513 low-end switches where the link will not be established, or will
514 be slow to establish. In particular, these switches are known to
515 be incompatible with 82541/82547:
516
517 Planex FXG-08TE
518 I-O Data ETG-SH8
519
520 To workaround this issue, the driver can be compiled with an override
521 of the PHY's master/slave setting. Forcing master or forcing slave
522 mode will improve time-to-link.
523
524 # make EXTRA_CFLAGS=-DE1000_MASTER_SLAVE=<n>
525
526 Where <n> is:
527
528 0 = Hardware default
529 1 = Master mode
530 2 = Slave mode
531 3 = Auto master/slave
532
533 Disable rx flow control with ethtool
534 ------------------------------------
535
536 In order to disable receive flow control using ethtool, you must turn
537 off auto-negotiation on the same command line.
538
539 For example:
540
541 ethtool -A eth? autoneg off rx off
376 542
377 543
378Support 544Support
@@ -382,20 +548,24 @@ For general information, go to the Intel support website at:
382 548
383 http://support.intel.com 549 http://support.intel.com
384 550
551 or the Intel Wired Networking project hosted by Sourceforge at:
552
553 http://sourceforge.net/projects/e1000
554
385If an issue is identified with the released source code on the supported 555If an issue is identified with the released source code on the supported
386kernel with a supported adapter, email the specific information related to 556kernel with a supported adapter, email the specific information related
387the issue to linux.nics@intel.com. 557to the issue to e1000-devel@lists.sourceforge.net
388 558
389 559
390License 560License
391======= 561=======
392 562
393This software program is released under the terms of a license agreement 563This software program is released under the terms of a license agreement
394between you ('Licensee') and Intel. Do not use or load this software or any 564between you ('Licensee') and Intel. Do not use or load this software or any
395associated materials (collectively, the 'Software') until you have carefully 565associated materials (collectively, the 'Software') until you have carefully
396read the full terms and conditions of the LICENSE located in this software 566read the full terms and conditions of the file COPYING located in this software
397package. By loading or using the Software, you agree to the terms of this 567package. By loading or using the Software, you agree to the terms of this
398Agreement. If you do not agree with the terms of this Agreement, do not 568Agreement. If you do not agree with the terms of this Agreement, do not
399install or use the Software. 569install or use the Software.
400 570
401* Other names and brands may be claimed as the property of others. 571* Other names and brands may be claimed as the property of others.
diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt
index 26364d06ae92..f12007b80a46 100644
--- a/Documentation/networking/ip-sysctl.txt
+++ b/Documentation/networking/ip-sysctl.txt
@@ -355,6 +355,13 @@ somaxconn - INTEGER
355 Defaults to 128. See also tcp_max_syn_backlog for additional tuning 355 Defaults to 128. See also tcp_max_syn_backlog for additional tuning
356 for TCP sockets. 356 for TCP sockets.
357 357
358tcp_workaround_signed_windows - BOOLEAN
359 If set, assume no receipt of a window scaling option means the
360 remote TCP is broken and treats the window as a signed quantity.
361 If unset, assume the remote TCP is not broken even if we do
362 not receive a window scaling option from them.
363 Default: 0
364
358IP Variables: 365IP Variables:
359 366
360ip_local_port_range - 2 INTEGERS 367ip_local_port_range - 2 INTEGERS
@@ -619,6 +626,11 @@ arp_ignore - INTEGER
619 The max value from conf/{all,interface}/arp_ignore is used 626 The max value from conf/{all,interface}/arp_ignore is used
620 when ARP request is received on the {interface} 627 when ARP request is received on the {interface}
621 628
629arp_accept - BOOLEAN
630 Define behavior when gratuitous arp replies are received:
631 0 - drop gratuitous arp frames
632 1 - accept gratuitous arp frames
633
622app_solicit - INTEGER 634app_solicit - INTEGER
623 The maximum number of probes to send to the user space ARP daemon 635 The maximum number of probes to send to the user space ARP daemon
624 via netlink before dropping back to multicast probes (see 636 via netlink before dropping back to multicast probes (see
@@ -717,6 +729,33 @@ accept_ra - BOOLEAN
717 Functional default: enabled if local forwarding is disabled. 729 Functional default: enabled if local forwarding is disabled.
718 disabled if local forwarding is enabled. 730 disabled if local forwarding is enabled.
719 731
732accept_ra_defrtr - BOOLEAN
733 Learn default router in Router Advertisement.
734
735 Functional default: enabled if accept_ra is enabled.
736 disabled if accept_ra is disabled.
737
738accept_ra_pinfo - BOOLEAN
739 Learn Prefix Inforamtion in Router Advertisement.
740
741 Functional default: enabled if accept_ra is enabled.
742 disabled if accept_ra is disabled.
743
744accept_ra_rt_info_max_plen - INTEGER
745 Maximum prefix length of Route Information in RA.
746
747 Route Information w/ prefix larger than or equal to this
748 variable shall be ignored.
749
750 Functional default: 0 if accept_ra_rtr_pref is enabled.
751 -1 if accept_ra_rtr_pref is disabled.
752
753accept_ra_rtr_pref - BOOLEAN
754 Accept Router Preference in RA.
755
756 Functional default: enabled if accept_ra is enabled.
757 disabled if accept_ra is disabled.
758
720accept_redirects - BOOLEAN 759accept_redirects - BOOLEAN
721 Accept Redirects. 760 Accept Redirects.
722 761
@@ -727,8 +766,8 @@ autoconf - BOOLEAN
727 Autoconfigure addresses using Prefix Information in Router 766 Autoconfigure addresses using Prefix Information in Router
728 Advertisements. 767 Advertisements.
729 768
730 Functional default: enabled if accept_ra is enabled. 769 Functional default: enabled if accept_ra_pinfo is enabled.
731 disabled if accept_ra is disabled. 770 disabled if accept_ra_pinfo is disabled.
732 771
733dad_transmits - INTEGER 772dad_transmits - INTEGER
734 The amount of Duplicate Address Detection probes to send. 773 The amount of Duplicate Address Detection probes to send.
@@ -771,6 +810,12 @@ mtu - INTEGER
771 Default Maximum Transfer Unit 810 Default Maximum Transfer Unit
772 Default: 1280 (IPv6 required minimum) 811 Default: 1280 (IPv6 required minimum)
773 812
813router_probe_interval - INTEGER
814 Minimum interval (in seconds) between Router Probing described
815 in RFC4191.
816
817 Default: 60
818
774router_solicitation_delay - INTEGER 819router_solicitation_delay - INTEGER
775 Number of seconds to wait after interface is brought up 820 Number of seconds to wait after interface is brought up
776 before sending Router Solicitations. 821 before sending Router Solicitations.
diff --git a/Documentation/usb/et61x251.txt b/Documentation/usb/et61x251.txt
index b44dda407ce2..29340282ab5f 100644
--- a/Documentation/usb/et61x251.txt
+++ b/Documentation/usb/et61x251.txt
@@ -176,6 +176,14 @@ Description: Force the application to unmap previously mapped buffer memory
176 1 = force memory unmapping (save memory) 176 1 = force memory unmapping (save memory)
177Default: 0 177Default: 0
178------------------------------------------------------------------------------- 178-------------------------------------------------------------------------------
179Name: frame_timeout
180Type: uint array (min = 0, max = 64)
181Syntax: <n[,...]>
182Description: Timeout for a video frame in seconds. This parameter is
183 specific for each detected camera. This parameter can be
184 changed at runtime thanks to the /sys filesystem interface.
185Default: 2
186-------------------------------------------------------------------------------
179Name: debug 187Name: debug
180Type: ushort 188Type: ushort
181Syntax: <n> 189Syntax: <n>
@@ -266,7 +274,7 @@ the V4L2 interface.
266 274
267 275
26810. Notes for V4L2 application developers 27610. Notes for V4L2 application developers
269======================================== 277=========================================
270This driver follows the V4L2 API specifications. In particular, it enforces two 278This driver follows the V4L2 API specifications. In particular, it enforces two
271rules: 279rules:
272 280
diff --git a/Documentation/usb/sn9c102.txt b/Documentation/usb/sn9c102.txt
index c6b76414172c..b957beae5607 100644
--- a/Documentation/usb/sn9c102.txt
+++ b/Documentation/usb/sn9c102.txt
@@ -196,6 +196,14 @@ Description: Force the application to unmap previously mapped buffer memory
196 1 = force memory unmapping (save memory) 196 1 = force memory unmapping (save memory)
197Default: 0 197Default: 0
198------------------------------------------------------------------------------- 198-------------------------------------------------------------------------------
199Name: frame_timeout
200Type: uint array (min = 0, max = 64)
201Syntax: <n[,...]>
202Description: Timeout for a video frame in seconds. This parameter is
203 specific for each detected camera. This parameter can be
204 changed at runtime thanks to the /sys filesystem interface.
205Default: 2
206-------------------------------------------------------------------------------
199Name: debug 207Name: debug
200Type: ushort 208Type: ushort
201Syntax: <n> 209Syntax: <n>
@@ -321,6 +329,7 @@ Vendor ID Product ID
321--------- ---------- 329--------- ----------
3220x0c45 0x6001 3300x0c45 0x6001
3230x0c45 0x6005 3310x0c45 0x6005
3320x0c45 0x6007
3240x0c45 0x6009 3330x0c45 0x6009
3250x0c45 0x600d 3340x0c45 0x600d
3260x0c45 0x6024 3350x0c45 0x6024
@@ -370,6 +379,7 @@ HV7131D Hynix Semiconductor, Inc.
370MI-0343 Micron Technology, Inc. 379MI-0343 Micron Technology, Inc.
371OV7630 OmniVision Technologies, Inc. 380OV7630 OmniVision Technologies, Inc.
372PAS106B PixArt Imaging, Inc. 381PAS106B PixArt Imaging, Inc.
382PAS202BCA PixArt Imaging, Inc.
373PAS202BCB PixArt Imaging, Inc. 383PAS202BCB PixArt Imaging, Inc.
374TAS5110C1B Taiwan Advanced Sensor Corporation 384TAS5110C1B Taiwan Advanced Sensor Corporation
375TAS5130D1B Taiwan Advanced Sensor Corporation 385TAS5130D1B Taiwan Advanced Sensor Corporation
@@ -493,6 +503,7 @@ Many thanks to following persons for their contribute (listed in alphabetical
493order): 503order):
494 504
495- Luca Capello for the donation of a webcam; 505- Luca Capello for the donation of a webcam;
506- Philippe Coval for having helped testing the PAS202BCA image sensor;
496- Joao Rodrigo Fuzaro, Joao Limirio, Claudio Filho and Caio Begotti for the 507- Joao Rodrigo Fuzaro, Joao Limirio, Claudio Filho and Caio Begotti for the
497 donation of a webcam; 508 donation of a webcam;
498- Jon Hollstrom for the donation of a webcam; 509- Jon Hollstrom for the donation of a webcam;
diff --git a/Documentation/usb/zc0301.txt b/Documentation/usb/zc0301.txt
new file mode 100644
index 000000000000..f55262c6733b
--- /dev/null
+++ b/Documentation/usb/zc0301.txt
@@ -0,0 +1,254 @@
1
2 ZC0301 Image Processor and Control Chip
3 Driver for Linux
4 =======================================
5
6 - Documentation -
7
8
9Index
10=====
111. Copyright
122. Disclaimer
133. License
144. Overview and features
155. Module dependencies
166. Module loading
177. Module parameters
188. Supported devices
199. Notes for V4L2 application developers
2010. Contact information
2111. Credits
22
23
241. Copyright
25============
26Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it>
27
28
292. Disclaimer
30=============
31This software is not developed or sponsored by Z-Star Microelectronics Corp.
32Trademarks are property of their respective owner.
33
34
353. License
36==========
37This program is free software; you can redistribute it and/or modify
38it under the terms of the GNU General Public License as published by
39the Free Software Foundation; either version 2 of the License, or
40(at your option) any later version.
41
42This program is distributed in the hope that it will be useful,
43but WITHOUT ANY WARRANTY; without even the implied warranty of
44MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45GNU General Public License for more details.
46
47You should have received a copy of the GNU General Public License
48along with this program; if not, write to the Free Software
49Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
50
51
524. Overview and features
53========================
54This driver supports the video interface of the devices mounting the ZC0301
55Image Processor and Control Chip.
56
57The driver relies on the Video4Linux2 and USB core modules. It has been
58designed to run properly on SMP systems as well.
59
60The latest version of the ZC0301 driver can be found at the following URL:
61http://www.linux-projects.org/
62
63Some of the features of the driver are:
64
65- full compliance with the Video4Linux2 API (see also "Notes for V4L2
66 application developers" paragraph);
67- available mmap or read/poll methods for video streaming through isochronous
68 data transfers;
69- automatic detection of image sensor;
70- video format is standard JPEG;
71- dynamic driver control thanks to various module parameters (see "Module
72 parameters" paragraph);
73- up to 64 cameras can be handled at the same time; they can be connected and
74 disconnected from the host many times without turning off the computer, if
75 the system supports hotplugging;
76
77
785. Module dependencies
79======================
80For it to work properly, the driver needs kernel support for Video4Linux and
81USB.
82
83The following options of the kernel configuration file must be enabled and
84corresponding modules must be compiled:
85
86 # Multimedia devices
87 #
88 CONFIG_VIDEO_DEV=m
89
90 # USB support
91 #
92 CONFIG_USB=m
93
94In addition, depending on the hardware being used, the modules below are
95necessary:
96
97 # USB Host Controller Drivers
98 #
99 CONFIG_USB_EHCI_HCD=m
100 CONFIG_USB_UHCI_HCD=m
101 CONFIG_USB_OHCI_HCD=m
102
103The ZC0301 controller also provides a built-in microphone interface. It is
104supported by the USB Audio driver thanks to the ALSA API:
105
106 # Sound
107 #
108 CONFIG_SOUND=y
109
110 # Advanced Linux Sound Architecture
111 #
112 CONFIG_SND=m
113
114 # USB devices
115 #
116 CONFIG_SND_USB_AUDIO=m
117
118And finally:
119
120 # USB Multimedia devices
121 #
122 CONFIG_USB_ZC0301=m
123
124
1256. Module loading
126=================
127To use the driver, it is necessary to load the "zc0301" module into memory
128after every other module required: "videodev", "usbcore" and, depending on
129the USB host controller you have, "ehci-hcd", "uhci-hcd" or "ohci-hcd".
130
131Loading can be done as shown below:
132
133 [root@localhost home]# modprobe zc0301
134
135At this point the devices should be recognized. You can invoke "dmesg" to
136analyze kernel messages and verify that the loading process has gone well:
137
138 [user@localhost home]$ dmesg
139
140
1417. Module parameters
142====================
143Module parameters are listed below:
144-------------------------------------------------------------------------------
145Name: video_nr
146Type: short array (min = 0, max = 64)
147Syntax: <-1|n[,...]>
148Description: Specify V4L2 minor mode number:
149 -1 = use next available
150 n = use minor number n
151 You can specify up to 64 cameras this way.
152 For example:
153 video_nr=-1,2,-1 would assign minor number 2 to the second
154 registered camera and use auto for the first one and for every
155 other camera.
156Default: -1
157-------------------------------------------------------------------------------
158Name: force_munmap
159Type: bool array (min = 0, max = 64)
160Syntax: <0|1[,...]>
161Description: Force the application to unmap previously mapped buffer memory
162 before calling any VIDIOC_S_CROP or VIDIOC_S_FMT ioctl's. Not
163 all the applications support this feature. This parameter is
164 specific for each detected camera.
165 0 = do not force memory unmapping
166 1 = force memory unmapping (save memory)
167Default: 0
168-------------------------------------------------------------------------------
169Name: frame_timeout
170Type: uint array (min = 0, max = 64)
171Syntax: <n[,...]>
172Description: Timeout for a video frame in seconds. This parameter is
173 specific for each detected camera. This parameter can be
174 changed at runtime thanks to the /sys filesystem interface.
175Default: 2
176-------------------------------------------------------------------------------
177Name: debug
178Type: ushort
179Syntax: <n>
180Description: Debugging information level, from 0 to 3:
181 0 = none (use carefully)
182 1 = critical errors
183 2 = significant informations
184 3 = more verbose messages
185 Level 3 is useful for testing only, when only one device
186 is used at the same time. It also shows some more informations
187 about the hardware being detected. This module parameter can be
188 changed at runtime thanks to the /sys filesystem interface.
189Default: 2
190-------------------------------------------------------------------------------
191
192
1938. Supported devices
194====================
195None of the names of the companies as well as their products will be mentioned
196here. They have never collaborated with the author, so no advertising.
197
198From the point of view of a driver, what unambiguously identify a device are
199its vendor and product USB identifiers. Below is a list of known identifiers of
200devices mounting the ZC0301 Image Processor and Control Chips:
201
202Vendor ID Product ID
203--------- ----------
2040x041e 0x4017
2050x041e 0x401c
2060x041e 0x401e
2070x041e 0x4034
2080x041e 0x4035
2090x046d 0x08ae
2100x0ac8 0x0301
2110x10fd 0x8050
212
213The list above does not imply that all those devices work with this driver: up
214until now only the ones that mount the following image sensors are supported;
215kernel messages will always tell you whether this is the case:
216
217Model Manufacturer
218----- ------------
219PAS202BCB PixArt Imaging, Inc.
220
221
2229. Notes for V4L2 application developers
223========================================
224This driver follows the V4L2 API specifications. In particular, it enforces two
225rules:
226
227- exactly one I/O method, either "mmap" or "read", is associated with each
228file descriptor. Once it is selected, the application must close and reopen the
229device to switch to the other I/O method;
230
231- although it is not mandatory, previously mapped buffer memory should always
232be unmapped before calling any "VIDIOC_S_CROP" or "VIDIOC_S_FMT" ioctl's.
233The same number of buffers as before will be allocated again to match the size
234of the new video frames, so you have to map the buffers again before any I/O
235attempts on them.
236
237
23810. Contact information
239=======================
240The author may be contacted by e-mail at <luca.risolia@studio.unibo.it>.
241
242GPG/PGP encrypted e-mail's are accepted. The GPG key ID of the author is
243'FCE635A4'; the public 1024-bit key should be available at any keyserver;
244the fingerprint is: '88E8 F32F 7244 68BA 3958 5D40 99DA 5D2A FCE6 35A4'.
245
246
24711. Credits
248===========
249- Informations about the chip internals needed to enable the I2C protocol have
250 been taken from the documentation of the ZC030x Video4Linux1 driver written
251 by Andrew Birkett <andy@nobugs.org>;
252- The initialization values of the ZC0301 controller connected to the PAS202BCB
253 image sensor have been taken from the SPCA5XX driver maintained by
254 Michel Xhaard <mxhaard@magic.fr>.
diff --git a/Documentation/video4linux/CARDLIST.cx88 b/Documentation/video4linux/CARDLIST.cx88
index 8bea3fbd0548..3b39a91b24bd 100644
--- a/Documentation/video4linux/CARDLIST.cx88
+++ b/Documentation/video4linux/CARDLIST.cx88
@@ -43,3 +43,5 @@
43 42 -> digitalnow DNTV Live! DVB-T Pro [1822:0025] 43 42 -> digitalnow DNTV Live! DVB-T Pro [1822:0025]
44 43 -> KWorld/VStream XPert DVB-T with cx22702 [17de:08a1] 44 43 -> KWorld/VStream XPert DVB-T with cx22702 [17de:08a1]
45 44 -> DViCO FusionHDTV DVB-T Dual Digital [18ac:db50,18ac:db54] 45 44 -> DViCO FusionHDTV DVB-T Dual Digital [18ac:db50,18ac:db54]
46 45 -> KWorld HardwareMpegTV XPert [17de:0840]
47 46 -> DViCO FusionHDTV DVB-T Hybrid [18ac:db40,18ac:db44]
diff --git a/Documentation/video4linux/CARDLIST.em28xx b/Documentation/video4linux/CARDLIST.em28xx
index a0c7cad20971..a3026689bbe6 100644
--- a/Documentation/video4linux/CARDLIST.em28xx
+++ b/Documentation/video4linux/CARDLIST.em28xx
@@ -8,3 +8,4 @@
8 7 -> Leadtek Winfast USB II (em2800) 8 7 -> Leadtek Winfast USB II (em2800)
9 8 -> Kworld USB2800 (em2800) 9 8 -> Kworld USB2800 (em2800)
10 9 -> Pinnacle Dazzle DVC 90 (em2820/em2840) [2304:0207] 10 9 -> Pinnacle Dazzle DVC 90 (em2820/em2840) [2304:0207]
11 12 -> Kworld PVR TV 2800 RF (em2820/em2840)
diff --git a/Documentation/video4linux/CARDLIST.saa7134 b/Documentation/video4linux/CARDLIST.saa7134
index da4fb890165f..8c7195455963 100644
--- a/Documentation/video4linux/CARDLIST.saa7134
+++ b/Documentation/video4linux/CARDLIST.saa7134
@@ -83,3 +83,12 @@
83 82 -> MSI TV@Anywhere plus [1462:6231] 83 82 -> MSI TV@Anywhere plus [1462:6231]
84 83 -> Terratec Cinergy 250 PCI TV [153b:1160] 84 83 -> Terratec Cinergy 250 PCI TV [153b:1160]
85 84 -> LifeView FlyDVB Trio [5168:0319] 85 84 -> LifeView FlyDVB Trio [5168:0319]
86 85 -> AverTV DVB-T 777 [1461:2c05]
87 86 -> LifeView FlyDVB-T [5168:0301]
88 87 -> ADS Instant TV Duo Cardbus PTV331 [0331:1421]
89 88 -> Tevion/KWorld DVB-T 220RF [17de:7201]
90 89 -> ELSA EX-VISION 700TV [1048:226c]
91 90 -> Kworld ATSC110 [17de:7350]
92 91 -> AVerMedia A169 B [1461:7360]
93 92 -> AVerMedia A169 B1 [1461:6360]
94 93 -> Medion 7134 Bridge #2 [16be:0005]
diff --git a/Documentation/video4linux/CARDLIST.tuner b/Documentation/video4linux/CARDLIST.tuner
index f6d0cf7b7922..1bcdac67dd8c 100644
--- a/Documentation/video4linux/CARDLIST.tuner
+++ b/Documentation/video4linux/CARDLIST.tuner
@@ -64,8 +64,10 @@ tuner=62 - Philips TEA5767HN FM Radio
64tuner=63 - Philips FMD1216ME MK3 Hybrid Tuner 64tuner=63 - Philips FMD1216ME MK3 Hybrid Tuner
65tuner=64 - LG TDVS-H062F/TUA6034 65tuner=64 - LG TDVS-H062F/TUA6034
66tuner=65 - Ymec TVF66T5-B/DFF 66tuner=65 - Ymec TVF66T5-B/DFF
67tuner=66 - LG NTSC (TALN mini series) 67tuner=66 - LG TALN series
68tuner=67 - Philips TD1316 Hybrid Tuner 68tuner=67 - Philips TD1316 Hybrid Tuner
69tuner=68 - Philips TUV1236D ATSC/NTSC dual in 69tuner=68 - Philips TUV1236D ATSC/NTSC dual in
70tuner=69 - Tena TNF 5335 MF 70tuner=69 - Tena TNF 5335 and similar models
71tuner=70 - Samsung TCPN 2121P30A 71tuner=70 - Samsung TCPN 2121P30A
72tuner=71 - Xceive xc3028
73tuner=72 - Thomson FE6600
diff --git a/Documentation/video4linux/README.cpia2 b/Documentation/video4linux/README.cpia2
new file mode 100644
index 000000000000..ce8213d28b67
--- /dev/null
+++ b/Documentation/video4linux/README.cpia2
@@ -0,0 +1,130 @@
1$Id: README,v 1.7 2005/08/29 23:39:57 sbertin Exp $
2
31. Introduction
4
5 This is a driver for STMicroelectronics's CPiA2 (second generation
6Colour Processor Interface ASIC) based cameras. This camera outputs an MJPEG
7stream at up to vga size. It implements the Video4Linux interface as much as
8possible. Since the V4L interface does not support compressed formats, only
9an mjpeg enabled application can be used with the camera. We have modified the
10gqcam application to view this stream.
11
12 The driver is implemented as two kernel modules. The cpia2 module
13contains the camera functions and the V4L interface. The cpia2_usb module
14contains usb specific functions. The main reason for this was the size of the
15module was getting out of hand, so I separted them. It is not likely that
16there will be a parallel port version.
17
18FEATURES:
19 - Supports cameras with the Vision stv6410 (CIF) and stv6500 (VGA) cmos
20 sensors. I only have the vga sensor, so can't test the other.
21 - Image formats: VGA, QVGA, CIF, QCIF, and a number of sizes in between.
22 VGA and QVGA are the native image sizes for the VGA camera. CIF is done
23 in the coprocessor by scaling QVGA. All other sizes are done by clipping.
24 - Palette: YCrCb, compressed with MJPEG.
25 - Some compression parameters are settable.
26 - Sensor framerate is adjustable (up to 30 fps CIF, 15 fps VGA).
27 - Adjust brightness, color, contrast while streaming.
28 - Flicker control settable for 50 or 60 Hz mains frequency.
29
302. Making and installing the stv672 driver modules:
31
32 Requirements:
33 -------------
34 This should work with 2.4 (2.4.23 and later) and 2.6 kernels, but has
35only been tested on 2.6. Video4Linux must be either compiled into the kernel or
36available as a module. Video4Linux2 is automatically detected and made
37available at compile time.
38
39 Compiling:
40 ----------
41 As root, do a make install. This will compile and install the modules
42into the media/video directory in the module tree. For 2.4 kernels, use
43Makefile_2.4 (aka do make -f Makefile_2.4 install).
44
45 Setup:
46 ------
47 Use 'modprobe cpia2' to load and 'modprobe -r cpia2' to unload. This
48may be done automatically by your distribution.
49
503. Driver options
51
52 Option Description
53 ------ -----------
54 video_nr video device to register (0=/dev/video0, etc)
55 range -1 to 64. default is -1 (first available)
56 If you have more than 1 camera, this MUST be -1.
57 buffer_size Size for each frame buffer in bytes (default 68k)
58 num_buffers Number of frame buffers (1-32, default 3)
59 alternate USB Alternate (2-7, default 7)
60 flicker_freq Frequency for flicker reduction(50 or 60, default 60)
61 flicker_mode 0 to disable, or 1 to enable flicker reduction.
62 (default 0). This is only effective if the camera
63 uses a stv0672 coprocessor.
64
65 Setting the options:
66 --------------------
67 If you are using modules, edit /etc/modules.conf and add an options
68line like this:
69 options cpia2 num_buffers=3 buffer_size=65535
70
71 If the driver is compiled into the kernel, at boot time specify them
72like this:
73 cpia2.num_buffers=3 cpia2.buffer_size=65535
74
75 What buffer size should I use?
76 ------------------------------
77 The maximum image size depends on the alternate you choose, and the
78frame rate achieved by the camera. If the compression engine is able to
79keep up with the frame rate, the maximum image size is given by the table
80below.
81 The compression engine starts out at maximum compression, and will
82increase image quality until it is close to the size in the table. As long
83as the compression engine can keep up with the frame rate, after a short time
84the images will all be about the size in the table, regardless of resolution.
85 At low alternate settings, the compression engine may not be able to
86compress the image enough and will reduce the frame rate by producing larger
87images.
88 The default of 68k should be good for most users. This will handle
89any alternate at frame rates down to 15fps. For lower frame rates, it may
90be necessary to increase the buffer size to avoid having frames dropped due
91to insufficient space.
92
93 Image size(bytes)
94 Alternate bytes/ms 15fps 30fps
95 2 128 8533 4267
96 3 384 25600 12800
97 4 640 42667 21333
98 5 768 51200 25600
99 6 896 59733 29867
100 7 1023 68200 34100
101
102 How many buffers should I use?
103 ------------------------------
104 For normal streaming, 3 should give the best results. With only 2,
105it is possible for the camera to finish sending one image just after a
106program has started reading the other. If this happens, the driver must drop
107a frame. The exception to this is if you have a heavily loaded machine. In
108this case use 2 buffers. You are probably not reading at the full frame rate.
109If the camera can send multiple images before a read finishes, it could
110overwrite the third buffer before the read finishes, leading to a corrupt
111image. Single and double buffering have extra checks to avoid overwriting.
112
1134. Using the camera
114
115 We are providing a modified gqcam application to view the output. In
116order to avoid confusion, here it is called mview. There is also the qx5view
117program which can also control the lights on the qx5 microscope. MJPEG Tools
118(http://mjpeg.sourceforge.net) can also be used to record from the camera.
119
1205. Notes to developers:
121
122 - This is a driver version stripped of the 2.4 back compatibility
123 and old MJPEG ioctl API. See cpia2.sf.net for 2.4 support.
124
1256. Thanks:
126
127 - Peter Pregler <Peter_Pregler@email.com>,
128 Scott J. Bertin <scottbertin@yahoo.com>, and
129 Jarl Totland <Jarl.Totland@bdc.no> for the original cpia driver, which
130 this one was modelled from.
diff --git a/Documentation/video4linux/cpia2_overview.txt b/Documentation/video4linux/cpia2_overview.txt
new file mode 100644
index 000000000000..a6e53665216b
--- /dev/null
+++ b/Documentation/video4linux/cpia2_overview.txt
@@ -0,0 +1,38 @@
1 Programmer's View of Cpia2
2
3Cpia2 is the second generation video coprocessor from VLSI Vision Ltd (now a
4division of ST Microelectronics). There are two versions. The first is the
5STV0672, which is capable of up to 30 frames per second (fps) in frame sizes
6up to CIF, and 15 fps for VGA frames. The STV0676 is an improved version,
7which can handle up to 30 fps VGA. Both coprocessors can be attached to two
8CMOS sensors - the vvl6410 CIF sensor and the vvl6500 VGA sensor. These will
9be referred to as the 410 and the 500 sensors, or the CIF and VGA sensors.
10
11The two chipsets operate almost identically. The core is an 8051 processor,
12running two different versions of firmware. The 672 runs the VP4 video
13processor code, the 676 runs VP5. There are a few differences in register
14mappings for the two chips. In these cases, the symbols defined in the
15header files are marked with VP4 or VP5 as part of the symbol name.
16
17The cameras appear externally as three sets of registers. Setting register
18values is the only way to control the camera. Some settings are
19interdependant, such as the sequence required to power up the camera. I will
20try to make note of all of these cases.
21
22The register sets are called blocks. Block 0 is the system block. This
23section is always powered on when the camera is plugged in. It contains
24registers that control housekeeping functions such as powering up the video
25processor. The video processor is the VP block. These registers control
26how the video from the sensor is processed. Examples are timing registers,
27user mode (vga, qvga), scaling, cropping, framerates, and so on. The last
28block is the video compressor (VC). The video stream sent from the camera is
29compressed as Motion JPEG (JPEGA). The VC controls all of the compression
30parameters. Looking at the file cpia2_registers.h, you can get a full view
31of these registers and the possible values for most of them.
32
33One or more registers can be set or read by sending a usb control message to
34the camera. There are three modes for this. Block mode requests a number
35of contiguous registers. Random mode reads or writes random registers with
36a tuple structure containing address/value pairs. The repeat mode is only
37used by VP4 to load a firmware patch. It contains a starting address and
38a sequence of bytes to be written into a gpio port. \ No newline at end of file
diff --git a/MAINTAINERS b/MAINTAINERS
index 8db5c339845d..ebef0ae90e2e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1349,10 +1349,10 @@ S: Maintained
1349INTEL PRO/100 ETHERNET SUPPORT 1349INTEL PRO/100 ETHERNET SUPPORT
1350P: John Ronciak 1350P: John Ronciak
1351M: john.ronciak@intel.com 1351M: john.ronciak@intel.com
1352P: Ganesh Venkatesan
1353M: ganesh.venkatesan@intel.com
1354P: Jesse Brandeburg 1352P: Jesse Brandeburg
1355M: jesse.brandeburg@intel.com 1353M: jesse.brandeburg@intel.com
1354P: Jeff Kirsher
1355M: jeffrey.t.kirsher@intel.com
1356W: http://sourceforge.net/projects/e1000/ 1356W: http://sourceforge.net/projects/e1000/
1357S: Supported 1357S: Supported
1358 1358
@@ -1361,18 +1361,22 @@ P: Jeb Cramer
1361M: cramerj@intel.com 1361M: cramerj@intel.com
1362P: John Ronciak 1362P: John Ronciak
1363M: john.ronciak@intel.com 1363M: john.ronciak@intel.com
1364P: Ganesh Venkatesan 1364P: Jesse Brandeburg
1365M: ganesh.venkatesan@intel.com 1365M: jesse.brandeburg@intel.com
1366P: Jeff Kirsher
1367M: jeffrey.t.kirsher@intel.com
1366W: http://sourceforge.net/projects/e1000/ 1368W: http://sourceforge.net/projects/e1000/
1367S: Supported 1369S: Supported
1368 1370
1369INTEL PRO/10GbE SUPPORT 1371INTEL PRO/10GbE SUPPORT
1372P: Jeff Kirsher
1373M: jeffrey.t.kirsher@intel.com
1370P: Ayyappan Veeraiyan 1374P: Ayyappan Veeraiyan
1371M: ayyappan.veeraiyan@intel.com 1375M: ayyappan.veeraiyan@intel.com
1372P: Ganesh Venkatesan
1373M: ganesh.venkatesan@intel.com
1374P: John Ronciak 1376P: John Ronciak
1375M: john.ronciak@intel.com 1377M: john.ronciak@intel.com
1378P: Jesse Brandeburg
1379M: jesse.brandeburg@intel.com
1376W: http://sourceforge.net/projects/e1000/ 1380W: http://sourceforge.net/projects/e1000/
1377S: Supported 1381S: Supported
1378 1382
@@ -1524,12 +1528,6 @@ M: davem@davemloft.net
1524L: linux-kernel@vger.kernel.org 1528L: linux-kernel@vger.kernel.org
1525S: Maintained 1529S: Maintained
1526 1530
1527LANMEDIA WAN CARD DRIVER
1528P: Andrew Stanley-Jones
1529M: asj@lanmedia.com
1530W: http://www.lanmedia.com/
1531S: Supported
1532
1533LAPB module 1531LAPB module
1534P: Henner Eisen 1532P: Henner Eisen
1535M: eis@baty.hanse.de 1533M: eis@baty.hanse.de
@@ -2902,6 +2900,14 @@ L: video4linux-list@redhat.com
2902W: http://www.linux-projects.org 2900W: http://www.linux-projects.org
2903S: Maintained 2901S: Maintained
2904 2902
2903USB ZC0301 DRIVER
2904P: Luca Risolia
2905M: luca.risolia@studio.unibo.it
2906L: linux-usb-devel@lists.sourceforge.net
2907L: video4linux-list@redhat.com
2908W: http://www.linux-projects.org
2909S: Maintained
2910
2905USB ZD1201 DRIVER 2911USB ZD1201 DRIVER
2906P: Jeroen Vreeken 2912P: Jeroen Vreeken
2907M: pe1rxq@amsat.org 2913M: pe1rxq@amsat.org
diff --git a/README b/README
index 0d318abaf7fd..05e055530bbb 100644
--- a/README
+++ b/README
@@ -74,7 +74,7 @@ INSTALLING the kernel:
74 whatever the kernel-du-jour happens to be. 74 whatever the kernel-du-jour happens to be.
75 75
76 - You can also upgrade between 2.6.xx releases by patching. Patches are 76 - You can also upgrade between 2.6.xx releases by patching. Patches are
77 distributed in the traditional gzip and the new bzip2 format. To 77 distributed in the traditional gzip and the newer bzip2 format. To
78 install by patching, get all the newer patch files, enter the 78 install by patching, get all the newer patch files, enter the
79 top level directory of the kernel source (linux-2.6.xx) and execute: 79 top level directory of the kernel source (linux-2.6.xx) and execute:
80 80
diff --git a/arch/arm/common/locomo.c b/arch/arm/common/locomo.c
index d31b1cb7eea0..23609400a8e2 100644
--- a/arch/arm/common/locomo.c
+++ b/arch/arm/common/locomo.c
@@ -788,6 +788,8 @@ static int locomo_probe(struct platform_device *dev)
788 if (!mem) 788 if (!mem)
789 return -EINVAL; 789 return -EINVAL;
790 irq = platform_get_irq(dev, 0); 790 irq = platform_get_irq(dev, 0);
791 if (irq < 0)
792 return -ENXIO;
791 793
792 return __locomo_probe(&dev->dev, mem, irq); 794 return __locomo_probe(&dev->dev, mem, irq);
793} 795}
diff --git a/arch/arm/common/sa1111.c b/arch/arm/common/sa1111.c
index 1475089f9b42..93352f6097c1 100644
--- a/arch/arm/common/sa1111.c
+++ b/arch/arm/common/sa1111.c
@@ -943,6 +943,8 @@ static int sa1111_probe(struct platform_device *pdev)
943 if (!mem) 943 if (!mem)
944 return -EINVAL; 944 return -EINVAL;
945 irq = platform_get_irq(pdev, 0); 945 irq = platform_get_irq(pdev, 0);
946 if (irq < 0)
947 return -ENXIO;
946 948
947 return __sa1111_probe(&pdev->dev, mem, irq); 949 return __sa1111_probe(&pdev->dev, mem, irq);
948} 950}
diff --git a/arch/arm/mach-realview/core.c b/arch/arm/mach-realview/core.c
index 4303d988c4bf..d13270c5d7cd 100644
--- a/arch/arm/mach-realview/core.c
+++ b/arch/arm/mach-realview/core.c
@@ -202,11 +202,6 @@ struct clk realview_clcd_clk = {
202/* 202/*
203 * CLCD support. 203 * CLCD support.
204 */ 204 */
205#define SYS_CLCD_MODE_MASK (3 << 0)
206#define SYS_CLCD_MODE_888 (0 << 0)
207#define SYS_CLCD_MODE_5551 (1 << 0)
208#define SYS_CLCD_MODE_565_RLSB (2 << 0)
209#define SYS_CLCD_MODE_565_BLSB (3 << 0)
210#define SYS_CLCD_NLCDIOON (1 << 2) 205#define SYS_CLCD_NLCDIOON (1 << 2)
211#define SYS_CLCD_VDDPOSSWITCH (1 << 3) 206#define SYS_CLCD_VDDPOSSWITCH (1 << 3)
212#define SYS_CLCD_PWR3V5SWITCH (1 << 4) 207#define SYS_CLCD_PWR3V5SWITCH (1 << 4)
@@ -360,29 +355,10 @@ static void realview_clcd_enable(struct clcd_fb *fb)
360 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET; 355 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
361 u32 val; 356 u32 val;
362 357
363 val = readl(sys_clcd);
364 val &= ~SYS_CLCD_MODE_MASK;
365
366 switch (fb->fb.var.green.length) {
367 case 5:
368 val |= SYS_CLCD_MODE_5551;
369 break;
370 case 6:
371 val |= SYS_CLCD_MODE_565_RLSB;
372 break;
373 case 8:
374 val |= SYS_CLCD_MODE_888;
375 break;
376 }
377
378 /*
379 * Set the MUX
380 */
381 writel(val, sys_clcd);
382
383 /* 358 /*
384 * And now enable the PSUs 359 * Enable the PSUs
385 */ 360 */
361 val = readl(sys_clcd);
386 val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH; 362 val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
387 writel(val, sys_clcd); 363 writel(val, sys_clcd);
388} 364}
diff --git a/arch/i386/defconfig b/arch/i386/defconfig
index 3cbe6e9cb9fc..1629c3ac9bee 100644
--- a/arch/i386/defconfig
+++ b/arch/i386/defconfig
@@ -1,49 +1,87 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# 3#
4CONFIG_X86_32=y
5CONFIG_SEMAPHORE_SLEEPERS=y
4CONFIG_X86=y 6CONFIG_X86=y
5CONFIG_MMU=y 7CONFIG_MMU=y
6CONFIG_UID16=y
7CONFIG_GENERIC_ISA_DMA=y 8CONFIG_GENERIC_ISA_DMA=y
9CONFIG_GENERIC_IOMAP=y
10CONFIG_ARCH_MAY_HAVE_PC_FDC=y
11CONFIG_DMI=y
8 12
9# 13#
10# Code maturity level options 14# Code maturity level options
11# 15#
12CONFIG_EXPERIMENTAL=y 16CONFIG_EXPERIMENTAL=y
13CONFIG_CLEAN_COMPILE=y 17CONFIG_BROKEN_ON_SMP=y
14CONFIG_STANDALONE=y 18CONFIG_INIT_ENV_ARG_LIMIT=32
15 19
16# 20#
17# General setup 21# General setup
18# 22#
23CONFIG_LOCALVERSION=""
24# CONFIG_LOCALVERSION_AUTO is not set
19CONFIG_SWAP=y 25CONFIG_SWAP=y
20CONFIG_SYSVIPC=y 26CONFIG_SYSVIPC=y
21CONFIG_POSIX_MQUEUE=y 27# CONFIG_POSIX_MQUEUE is not set
22# CONFIG_BSD_PROCESS_ACCT is not set 28# CONFIG_BSD_PROCESS_ACCT is not set
23CONFIG_SYSCTL=y 29CONFIG_SYSCTL=y
24CONFIG_AUDIT=y 30# CONFIG_AUDIT is not set
25CONFIG_AUDITSYSCALL=y 31CONFIG_IKCONFIG=y
26CONFIG_LOG_BUF_SHIFT=15 32CONFIG_IKCONFIG_PROC=y
27CONFIG_HOTPLUG=y 33CONFIG_INITRAMFS_SOURCE=""
28# CONFIG_IKCONFIG is not set 34CONFIG_UID16=y
35CONFIG_VM86=y
36CONFIG_CC_OPTIMIZE_FOR_SIZE=y
29# CONFIG_EMBEDDED is not set 37# CONFIG_EMBEDDED is not set
30CONFIG_KALLSYMS=y 38CONFIG_KALLSYMS=y
39# CONFIG_KALLSYMS_EXTRA_PASS is not set
40CONFIG_HOTPLUG=y
41CONFIG_PRINTK=y
42CONFIG_BUG=y
43CONFIG_ELF_CORE=y
44CONFIG_BASE_FULL=y
31CONFIG_FUTEX=y 45CONFIG_FUTEX=y
32CONFIG_EPOLL=y 46CONFIG_EPOLL=y
33CONFIG_IOSCHED_NOOP=y 47CONFIG_SHMEM=y
34CONFIG_IOSCHED_AS=y 48CONFIG_CC_ALIGN_FUNCTIONS=0
35CONFIG_IOSCHED_DEADLINE=y 49CONFIG_CC_ALIGN_LABELS=0
36CONFIG_IOSCHED_CFQ=y 50CONFIG_CC_ALIGN_LOOPS=0
37# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set 51CONFIG_CC_ALIGN_JUMPS=0
52CONFIG_SLAB=y
53# CONFIG_TINY_SHMEM is not set
54CONFIG_BASE_SMALL=0
55# CONFIG_SLOB is not set
38 56
39# 57#
40# Loadable module support 58# Loadable module support
41# 59#
42CONFIG_MODULES=y 60CONFIG_MODULES=y
43# CONFIG_MODULE_UNLOAD is not set 61CONFIG_MODULE_UNLOAD=y
62CONFIG_MODULE_FORCE_UNLOAD=y
44CONFIG_OBSOLETE_MODPARM=y 63CONFIG_OBSOLETE_MODPARM=y
45# CONFIG_MODVERSIONS is not set 64# CONFIG_MODVERSIONS is not set
46CONFIG_KMOD=y 65# CONFIG_MODULE_SRCVERSION_ALL is not set
66# CONFIG_KMOD is not set
67
68#
69# Block layer
70#
71# CONFIG_LBD is not set
72
73#
74# IO Schedulers
75#
76CONFIG_IOSCHED_NOOP=y
77# CONFIG_IOSCHED_AS is not set
78# CONFIG_IOSCHED_DEADLINE is not set
79CONFIG_IOSCHED_CFQ=y
80# CONFIG_DEFAULT_AS is not set
81# CONFIG_DEFAULT_DEADLINE is not set
82CONFIG_DEFAULT_CFQ=y
83# CONFIG_DEFAULT_NOOP is not set
84CONFIG_DEFAULT_IOSCHED="cfq"
47 85
48# 86#
49# Processor type and features 87# Processor type and features
@@ -66,43 +104,50 @@ CONFIG_X86_PC=y
66# CONFIG_MPENTIUMII is not set 104# CONFIG_MPENTIUMII is not set
67# CONFIG_MPENTIUMIII is not set 105# CONFIG_MPENTIUMIII is not set
68# CONFIG_MPENTIUMM is not set 106# CONFIG_MPENTIUMM is not set
69CONFIG_MPENTIUM4=y 107# CONFIG_MPENTIUM4 is not set
70# CONFIG_MK6 is not set 108# CONFIG_MK6 is not set
71# CONFIG_MK7 is not set 109CONFIG_MK7=y
72# CONFIG_MK8 is not set 110# CONFIG_MK8 is not set
73# CONFIG_MCRUSOE is not set 111# CONFIG_MCRUSOE is not set
74# CONFIG_MEFFICEON is not set 112# CONFIG_MEFFICEON is not set
75# CONFIG_MWINCHIPC6 is not set 113# CONFIG_MWINCHIPC6 is not set
76# CONFIG_MWINCHIP2 is not set 114# CONFIG_MWINCHIP2 is not set
77# CONFIG_MWINCHIP3D is not set 115# CONFIG_MWINCHIP3D is not set
116# CONFIG_MGEODEGX1 is not set
117# CONFIG_MGEODE_LX is not set
78# CONFIG_MCYRIXIII is not set 118# CONFIG_MCYRIXIII is not set
79# CONFIG_MVIAC3_2 is not set 119# CONFIG_MVIAC3_2 is not set
80# CONFIG_X86_GENERIC is not set 120# CONFIG_X86_GENERIC is not set
81CONFIG_X86_CMPXCHG=y 121CONFIG_X86_CMPXCHG=y
82CONFIG_X86_XADD=y 122CONFIG_X86_XADD=y
83CONFIG_X86_L1_CACHE_SHIFT=7 123CONFIG_X86_L1_CACHE_SHIFT=6
84CONFIG_RWSEM_XCHGADD_ALGORITHM=y 124CONFIG_RWSEM_XCHGADD_ALGORITHM=y
125CONFIG_GENERIC_CALIBRATE_DELAY=y
85CONFIG_X86_WP_WORKS_OK=y 126CONFIG_X86_WP_WORKS_OK=y
86CONFIG_X86_INVLPG=y 127CONFIG_X86_INVLPG=y
87CONFIG_X86_BSWAP=y 128CONFIG_X86_BSWAP=y
88CONFIG_X86_POPAD_OK=y 129CONFIG_X86_POPAD_OK=y
130CONFIG_X86_CMPXCHG64=y
89CONFIG_X86_GOOD_APIC=y 131CONFIG_X86_GOOD_APIC=y
90CONFIG_X86_INTEL_USERCOPY=y 132CONFIG_X86_INTEL_USERCOPY=y
91CONFIG_X86_USE_PPRO_CHECKSUM=y 133CONFIG_X86_USE_PPRO_CHECKSUM=y
134CONFIG_X86_USE_3DNOW=y
135CONFIG_X86_TSC=y
92# CONFIG_HPET_TIMER is not set 136# CONFIG_HPET_TIMER is not set
93# CONFIG_HPET_EMULATE_RTC is not set 137# CONFIG_SMP is not set
94CONFIG_SMP=y 138CONFIG_PREEMPT_NONE=y
95CONFIG_NR_CPUS=8 139# CONFIG_PREEMPT_VOLUNTARY is not set
96CONFIG_SCHED_SMT=y 140# CONFIG_PREEMPT is not set
97CONFIG_PREEMPT=y 141CONFIG_X86_UP_APIC=y
142CONFIG_X86_UP_IOAPIC=y
98CONFIG_X86_LOCAL_APIC=y 143CONFIG_X86_LOCAL_APIC=y
99CONFIG_X86_IO_APIC=y 144CONFIG_X86_IO_APIC=y
100CONFIG_X86_TSC=y
101CONFIG_X86_MCE=y 145CONFIG_X86_MCE=y
102CONFIG_X86_MCE_NONFATAL=y 146CONFIG_X86_MCE_NONFATAL=y
103CONFIG_X86_MCE_P4THERMAL=y 147# CONFIG_X86_MCE_P4THERMAL is not set
104# CONFIG_TOSHIBA is not set 148# CONFIG_TOSHIBA is not set
105# CONFIG_I8K is not set 149# CONFIG_I8K is not set
150# CONFIG_X86_REBOOTFIXUPS is not set
106# CONFIG_MICROCODE is not set 151# CONFIG_MICROCODE is not set
107# CONFIG_X86_MSR is not set 152# CONFIG_X86_MSR is not set
108# CONFIG_X86_CPUID is not set 153# CONFIG_X86_CPUID is not set
@@ -111,41 +156,71 @@ CONFIG_X86_MCE_P4THERMAL=y
111# Firmware Drivers 156# Firmware Drivers
112# 157#
113# CONFIG_EDD is not set 158# CONFIG_EDD is not set
159# CONFIG_DELL_RBU is not set
160# CONFIG_DCDBAS is not set
114CONFIG_NOHIGHMEM=y 161CONFIG_NOHIGHMEM=y
115# CONFIG_HIGHMEM4G is not set 162# CONFIG_HIGHMEM4G is not set
116# CONFIG_HIGHMEM64G is not set 163# CONFIG_HIGHMEM64G is not set
164CONFIG_VMSPLIT_3G=y
165# CONFIG_VMSPLIT_3G_OPT is not set
166# CONFIG_VMSPLIT_2G is not set
167# CONFIG_VMSPLIT_1G is not set
168CONFIG_PAGE_OFFSET=0xC0000000
169CONFIG_ARCH_FLATMEM_ENABLE=y
170CONFIG_ARCH_SPARSEMEM_ENABLE=y
171CONFIG_ARCH_SELECT_MEMORY_MODEL=y
172CONFIG_SELECT_MEMORY_MODEL=y
173CONFIG_FLATMEM_MANUAL=y
174# CONFIG_DISCONTIGMEM_MANUAL is not set
175# CONFIG_SPARSEMEM_MANUAL is not set
176CONFIG_FLATMEM=y
177CONFIG_FLAT_NODE_MEM_MAP=y
178CONFIG_SPARSEMEM_STATIC=y
179CONFIG_SPLIT_PTLOCK_CPUS=4
117# CONFIG_MATH_EMULATION is not set 180# CONFIG_MATH_EMULATION is not set
118CONFIG_MTRR=y 181CONFIG_MTRR=y
119# CONFIG_EFI is not set 182# CONFIG_EFI is not set
120CONFIG_IRQBALANCE=y 183CONFIG_REGPARM=y
121CONFIG_HAVE_DEC_LOCK=y 184# CONFIG_SECCOMP is not set
122# CONFIG_REGPARM is not set 185CONFIG_HZ_100=y
186# CONFIG_HZ_250 is not set
187# CONFIG_HZ_1000 is not set
188CONFIG_HZ=100
189# CONFIG_KEXEC is not set
190CONFIG_PHYSICAL_START=0x100000
191CONFIG_DOUBLEFAULT=y
123 192
124# 193#
125# Power management options (ACPI, APM) 194# Power management options (ACPI, APM)
126# 195#
127CONFIG_PM=y 196CONFIG_PM=y
197# CONFIG_PM_LEGACY is not set
198# CONFIG_PM_DEBUG is not set
128CONFIG_SOFTWARE_SUSPEND=y 199CONFIG_SOFTWARE_SUSPEND=y
200CONFIG_PM_STD_PARTITION="/dev/hda2"
129 201
130# 202#
131# ACPI (Advanced Configuration and Power Interface) Support 203# ACPI (Advanced Configuration and Power Interface) Support
132# 204#
133CONFIG_ACPI=y 205CONFIG_ACPI=y
134CONFIG_ACPI_SLEEP=y 206# CONFIG_ACPI_SLEEP is not set
135CONFIG_ACPI_SLEEP_PROC_FS=y 207# CONFIG_ACPI_AC is not set
136CONFIG_ACPI_AC=y 208# CONFIG_ACPI_BATTERY is not set
137CONFIG_ACPI_BATTERY=y 209# CONFIG_ACPI_BUTTON is not set
138CONFIG_ACPI_BUTTON=y 210# CONFIG_ACPI_VIDEO is not set
139CONFIG_ACPI_FAN=y 211# CONFIG_ACPI_HOTKEY is not set
140CONFIG_ACPI_PROCESSOR=y 212# CONFIG_ACPI_FAN is not set
141CONFIG_ACPI_THERMAL=y 213# CONFIG_ACPI_PROCESSOR is not set
142# CONFIG_ACPI_ASUS is not set 214# CONFIG_ACPI_ASUS is not set
215# CONFIG_ACPI_IBM is not set
143# CONFIG_ACPI_TOSHIBA is not set 216# CONFIG_ACPI_TOSHIBA is not set
217CONFIG_ACPI_BLACKLIST_YEAR=0
144# CONFIG_ACPI_DEBUG is not set 218# CONFIG_ACPI_DEBUG is not set
145CONFIG_ACPI_EC=y 219CONFIG_ACPI_EC=y
146CONFIG_ACPI_POWER=y 220CONFIG_ACPI_POWER=y
147CONFIG_ACPI_SYSTEM=y 221CONFIG_ACPI_SYSTEM=y
148# CONFIG_X86_PM_TIMER is not set 222# CONFIG_X86_PM_TIMER is not set
223# CONFIG_ACPI_CONTAINER is not set
149 224
150# 225#
151# APM (Advanced Power Management) BIOS Support 226# APM (Advanced Power Management) BIOS Support
@@ -168,19 +243,18 @@ CONFIG_PCI_GOANY=y
168CONFIG_PCI_BIOS=y 243CONFIG_PCI_BIOS=y
169CONFIG_PCI_DIRECT=y 244CONFIG_PCI_DIRECT=y
170CONFIG_PCI_MMCONFIG=y 245CONFIG_PCI_MMCONFIG=y
171# CONFIG_PCI_USE_VECTOR is not set 246# CONFIG_PCIEPORTBUS is not set
172CONFIG_PCI_LEGACY_PROC=y 247# CONFIG_PCI_MSI is not set
173CONFIG_PCI_NAMES=y 248# CONFIG_PCI_LEGACY_PROC is not set
174CONFIG_ISA=y 249CONFIG_ISA_DMA_API=y
175# CONFIG_EISA is not set 250# CONFIG_ISA is not set
176# CONFIG_MCA is not set 251# CONFIG_MCA is not set
177# CONFIG_SCx200 is not set 252# CONFIG_SCx200 is not set
178 253
179# 254#
180# PCMCIA/CardBus support 255# PCCARD (PCMCIA/CardBus) support
181# 256#
182# CONFIG_PCMCIA is not set 257# CONFIG_PCCARD is not set
183CONFIG_PCMCIA_PROBE=y
184 258
185# 259#
186# PCI Hotplug Support 260# PCI Hotplug Support
@@ -191,8 +265,147 @@ CONFIG_PCMCIA_PROBE=y
191# Executable file formats 265# Executable file formats
192# 266#
193CONFIG_BINFMT_ELF=y 267CONFIG_BINFMT_ELF=y
194CONFIG_BINFMT_AOUT=y 268# CONFIG_BINFMT_AOUT is not set
195CONFIG_BINFMT_MISC=y 269# CONFIG_BINFMT_MISC is not set
270
271#
272# Networking
273#
274CONFIG_NET=y
275
276#
277# Networking options
278#
279# CONFIG_NETDEBUG is not set
280CONFIG_PACKET=y
281CONFIG_PACKET_MMAP=y
282CONFIG_UNIX=y
283# CONFIG_NET_KEY is not set
284CONFIG_INET=y
285# CONFIG_IP_MULTICAST is not set
286# CONFIG_IP_ADVANCED_ROUTER is not set
287CONFIG_IP_FIB_HASH=y
288# CONFIG_IP_PNP is not set
289# CONFIG_NET_IPIP is not set
290# CONFIG_NET_IPGRE is not set
291# CONFIG_ARPD is not set
292# CONFIG_SYN_COOKIES is not set
293# CONFIG_INET_AH is not set
294# CONFIG_INET_ESP is not set
295# CONFIG_INET_IPCOMP is not set
296# CONFIG_INET_TUNNEL is not set
297# CONFIG_INET_DIAG is not set
298# CONFIG_TCP_CONG_ADVANCED is not set
299CONFIG_TCP_CONG_BIC=y
300
301#
302# IP: Virtual Server Configuration
303#
304# CONFIG_IP_VS is not set
305# CONFIG_IPV6 is not set
306CONFIG_NETFILTER=y
307# CONFIG_NETFILTER_DEBUG is not set
308
309#
310# Core Netfilter Configuration
311#
312# CONFIG_NETFILTER_NETLINK is not set
313CONFIG_NETFILTER_XTABLES=y
314# CONFIG_NETFILTER_XT_TARGET_CLASSIFY is not set
315# CONFIG_NETFILTER_XT_TARGET_MARK is not set
316# CONFIG_NETFILTER_XT_TARGET_NFQUEUE is not set
317# CONFIG_NETFILTER_XT_MATCH_COMMENT is not set
318# CONFIG_NETFILTER_XT_MATCH_CONNTRACK is not set
319# CONFIG_NETFILTER_XT_MATCH_DCCP is not set
320# CONFIG_NETFILTER_XT_MATCH_HELPER is not set
321# CONFIG_NETFILTER_XT_MATCH_LENGTH is not set
322CONFIG_NETFILTER_XT_MATCH_LIMIT=y
323CONFIG_NETFILTER_XT_MATCH_MAC=y
324# CONFIG_NETFILTER_XT_MATCH_MARK is not set
325# CONFIG_NETFILTER_XT_MATCH_PKTTYPE is not set
326# CONFIG_NETFILTER_XT_MATCH_REALM is not set
327# CONFIG_NETFILTER_XT_MATCH_SCTP is not set
328CONFIG_NETFILTER_XT_MATCH_STATE=y
329# CONFIG_NETFILTER_XT_MATCH_STRING is not set
330# CONFIG_NETFILTER_XT_MATCH_TCPMSS is not set
331
332#
333# IP: Netfilter Configuration
334#
335CONFIG_IP_NF_CONNTRACK=y
336# CONFIG_IP_NF_CT_ACCT is not set
337# CONFIG_IP_NF_CONNTRACK_MARK is not set
338# CONFIG_IP_NF_CONNTRACK_EVENTS is not set
339# CONFIG_IP_NF_CT_PROTO_SCTP is not set
340CONFIG_IP_NF_FTP=y
341# CONFIG_IP_NF_IRC is not set
342# CONFIG_IP_NF_NETBIOS_NS is not set
343# CONFIG_IP_NF_TFTP is not set
344# CONFIG_IP_NF_AMANDA is not set
345# CONFIG_IP_NF_PPTP is not set
346# CONFIG_IP_NF_QUEUE is not set
347CONFIG_IP_NF_IPTABLES=y
348# CONFIG_IP_NF_MATCH_IPRANGE is not set
349# CONFIG_IP_NF_MATCH_MULTIPORT is not set
350# CONFIG_IP_NF_MATCH_TOS is not set
351# CONFIG_IP_NF_MATCH_RECENT is not set
352# CONFIG_IP_NF_MATCH_ECN is not set
353# CONFIG_IP_NF_MATCH_DSCP is not set
354# CONFIG_IP_NF_MATCH_AH_ESP is not set
355# CONFIG_IP_NF_MATCH_TTL is not set
356# CONFIG_IP_NF_MATCH_OWNER is not set
357# CONFIG_IP_NF_MATCH_ADDRTYPE is not set
358# CONFIG_IP_NF_MATCH_HASHLIMIT is not set
359CONFIG_IP_NF_FILTER=y
360# CONFIG_IP_NF_TARGET_REJECT is not set
361CONFIG_IP_NF_TARGET_LOG=y
362# CONFIG_IP_NF_TARGET_ULOG is not set
363# CONFIG_IP_NF_TARGET_TCPMSS is not set
364# CONFIG_IP_NF_NAT is not set
365# CONFIG_IP_NF_MANGLE is not set
366# CONFIG_IP_NF_RAW is not set
367# CONFIG_IP_NF_ARPTABLES is not set
368
369#
370# DCCP Configuration (EXPERIMENTAL)
371#
372# CONFIG_IP_DCCP is not set
373
374#
375# SCTP Configuration (EXPERIMENTAL)
376#
377# CONFIG_IP_SCTP is not set
378
379#
380# TIPC Configuration (EXPERIMENTAL)
381#
382# CONFIG_TIPC is not set
383# CONFIG_ATM is not set
384# CONFIG_BRIDGE is not set
385# CONFIG_VLAN_8021Q is not set
386# CONFIG_DECNET is not set
387# CONFIG_LLC2 is not set
388# CONFIG_IPX is not set
389# CONFIG_ATALK is not set
390# CONFIG_X25 is not set
391# CONFIG_LAPB is not set
392# CONFIG_NET_DIVERT is not set
393# CONFIG_ECONET is not set
394# CONFIG_WAN_ROUTER is not set
395
396#
397# QoS and/or fair queueing
398#
399# CONFIG_NET_SCHED is not set
400
401#
402# Network testing
403#
404# CONFIG_NET_PKTGEN is not set
405# CONFIG_HAMRADIO is not set
406# CONFIG_IRDA is not set
407# CONFIG_BT is not set
408# CONFIG_IEEE80211 is not set
196 409
197# 410#
198# Device Drivers 411# Device Drivers
@@ -201,7 +414,14 @@ CONFIG_BINFMT_MISC=y
201# 414#
202# Generic Driver Options 415# Generic Driver Options
203# 416#
204CONFIG_FW_LOADER=m 417CONFIG_STANDALONE=y
418CONFIG_PREVENT_FIRMWARE_BUILD=y
419# CONFIG_FW_LOADER is not set
420
421#
422# Connector - unified userspace <-> kernelspace linker
423#
424# CONFIG_CONNECTOR is not set
205 425
206# 426#
207# Memory Technology Devices (MTD) 427# Memory Technology Devices (MTD)
@@ -213,40 +433,36 @@ CONFIG_FW_LOADER=m
213# 433#
214CONFIG_PARPORT=y 434CONFIG_PARPORT=y
215CONFIG_PARPORT_PC=y 435CONFIG_PARPORT_PC=y
216CONFIG_PARPORT_PC_CML1=y
217# CONFIG_PARPORT_SERIAL is not set 436# CONFIG_PARPORT_SERIAL is not set
218# CONFIG_PARPORT_PC_FIFO is not set 437# CONFIG_PARPORT_PC_FIFO is not set
219# CONFIG_PARPORT_PC_SUPERIO is not set 438# CONFIG_PARPORT_PC_SUPERIO is not set
220# CONFIG_PARPORT_OTHER is not set 439# CONFIG_PARPORT_GSC is not set
221# CONFIG_PARPORT_1284 is not set 440CONFIG_PARPORT_1284=y
222 441
223# 442#
224# Plug and Play support 443# Plug and Play support
225# 444#
226CONFIG_PNP=y 445# CONFIG_PNP is not set
227# CONFIG_PNP_DEBUG is not set
228
229#
230# Protocols
231#
232# CONFIG_ISAPNP is not set
233# CONFIG_PNPBIOS is not set
234 446
235# 447#
236# Block devices 448# Block devices
237# 449#
238CONFIG_BLK_DEV_FD=y 450# CONFIG_BLK_DEV_FD is not set
239# CONFIG_BLK_DEV_XD is not set
240# CONFIG_PARIDE is not set 451# CONFIG_PARIDE is not set
241# CONFIG_BLK_CPQ_DA is not set 452# CONFIG_BLK_CPQ_DA is not set
242# CONFIG_BLK_CPQ_CISS_DA is not set 453# CONFIG_BLK_CPQ_CISS_DA is not set
243# CONFIG_BLK_DEV_DAC960 is not set 454# CONFIG_BLK_DEV_DAC960 is not set
244# CONFIG_BLK_DEV_UMEM is not set 455# CONFIG_BLK_DEV_UMEM is not set
245# CONFIG_BLK_DEV_LOOP is not set 456# CONFIG_BLK_DEV_COW_COMMON is not set
457CONFIG_BLK_DEV_LOOP=y
458# CONFIG_BLK_DEV_CRYPTOLOOP is not set
246# CONFIG_BLK_DEV_NBD is not set 459# CONFIG_BLK_DEV_NBD is not set
247# CONFIG_BLK_DEV_CARMEL is not set 460# CONFIG_BLK_DEV_SX8 is not set
461# CONFIG_BLK_DEV_UB is not set
248# CONFIG_BLK_DEV_RAM is not set 462# CONFIG_BLK_DEV_RAM is not set
249CONFIG_LBD=y 463CONFIG_BLK_DEV_RAM_COUNT=16
464# CONFIG_CDROM_PKTCDVD is not set
465# CONFIG_ATA_OVER_ETH is not set
250 466
251# 467#
252# ATA/ATAPI/MFM/RLL support 468# ATA/ATAPI/MFM/RLL support
@@ -257,34 +473,31 @@ CONFIG_BLK_DEV_IDE=y
257# 473#
258# Please see Documentation/ide.txt for help/info on IDE drives 474# Please see Documentation/ide.txt for help/info on IDE drives
259# 475#
476# CONFIG_BLK_DEV_IDE_SATA is not set
260# CONFIG_BLK_DEV_HD_IDE is not set 477# CONFIG_BLK_DEV_HD_IDE is not set
261CONFIG_BLK_DEV_IDEDISK=y 478CONFIG_BLK_DEV_IDEDISK=y
262CONFIG_IDEDISK_MULTI_MODE=y 479# CONFIG_IDEDISK_MULTI_MODE is not set
263CONFIG_BLK_DEV_IDECD=y 480CONFIG_BLK_DEV_IDECD=y
264# CONFIG_BLK_DEV_IDETAPE is not set 481# CONFIG_BLK_DEV_IDETAPE is not set
265# CONFIG_BLK_DEV_IDEFLOPPY is not set 482# CONFIG_BLK_DEV_IDEFLOPPY is not set
266# CONFIG_BLK_DEV_IDESCSI is not set 483# CONFIG_BLK_DEV_IDESCSI is not set
267# CONFIG_IDE_TASK_IOCTL is not set 484# CONFIG_IDE_TASK_IOCTL is not set
268CONFIG_IDE_TASKFILE_IO=y
269 485
270# 486#
271# IDE chipset support/bugfixes 487# IDE chipset support/bugfixes
272# 488#
273CONFIG_IDE_GENERIC=y 489# CONFIG_IDE_GENERIC is not set
274CONFIG_BLK_DEV_CMD640=y 490# CONFIG_BLK_DEV_CMD640 is not set
275# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
276# CONFIG_BLK_DEV_IDEPNP is not set
277CONFIG_BLK_DEV_IDEPCI=y 491CONFIG_BLK_DEV_IDEPCI=y
278CONFIG_IDEPCI_SHARE_IRQ=y 492CONFIG_IDEPCI_SHARE_IRQ=y
279# CONFIG_BLK_DEV_OFFBOARD is not set 493# CONFIG_BLK_DEV_OFFBOARD is not set
280CONFIG_BLK_DEV_GENERIC=y 494# CONFIG_BLK_DEV_GENERIC is not set
281# CONFIG_BLK_DEV_OPTI621 is not set 495# CONFIG_BLK_DEV_OPTI621 is not set
282CONFIG_BLK_DEV_RZ1000=y 496# CONFIG_BLK_DEV_RZ1000 is not set
283CONFIG_BLK_DEV_IDEDMA_PCI=y 497CONFIG_BLK_DEV_IDEDMA_PCI=y
284# CONFIG_BLK_DEV_IDEDMA_FORCED is not set 498# CONFIG_BLK_DEV_IDEDMA_FORCED is not set
285CONFIG_IDEDMA_PCI_AUTO=y 499CONFIG_IDEDMA_PCI_AUTO=y
286# CONFIG_IDEDMA_ONLYDISK is not set 500# CONFIG_IDEDMA_ONLYDISK is not set
287CONFIG_BLK_DEV_ADMA=y
288# CONFIG_BLK_DEV_AEC62XX is not set 501# CONFIG_BLK_DEV_AEC62XX is not set
289# CONFIG_BLK_DEV_ALI15X3 is not set 502# CONFIG_BLK_DEV_ALI15X3 is not set
290# CONFIG_BLK_DEV_AMD74XX is not set 503# CONFIG_BLK_DEV_AMD74XX is not set
@@ -294,10 +507,12 @@ CONFIG_BLK_DEV_ADMA=y
294# CONFIG_BLK_DEV_CY82C693 is not set 507# CONFIG_BLK_DEV_CY82C693 is not set
295# CONFIG_BLK_DEV_CS5520 is not set 508# CONFIG_BLK_DEV_CS5520 is not set
296# CONFIG_BLK_DEV_CS5530 is not set 509# CONFIG_BLK_DEV_CS5530 is not set
510# CONFIG_BLK_DEV_CS5535 is not set
297# CONFIG_BLK_DEV_HPT34X is not set 511# CONFIG_BLK_DEV_HPT34X is not set
298# CONFIG_BLK_DEV_HPT366 is not set 512# CONFIG_BLK_DEV_HPT366 is not set
299# CONFIG_BLK_DEV_SC1200 is not set 513# CONFIG_BLK_DEV_SC1200 is not set
300CONFIG_BLK_DEV_PIIX=y 514# CONFIG_BLK_DEV_PIIX is not set
515# CONFIG_BLK_DEV_IT821X is not set
301# CONFIG_BLK_DEV_NS87415 is not set 516# CONFIG_BLK_DEV_NS87415 is not set
302# CONFIG_BLK_DEV_PDC202XX_OLD is not set 517# CONFIG_BLK_DEV_PDC202XX_OLD is not set
303# CONFIG_BLK_DEV_PDC202XX_NEW is not set 518# CONFIG_BLK_DEV_PDC202XX_NEW is not set
@@ -306,9 +521,8 @@ CONFIG_BLK_DEV_PIIX=y
306# CONFIG_BLK_DEV_SIS5513 is not set 521# CONFIG_BLK_DEV_SIS5513 is not set
307# CONFIG_BLK_DEV_SLC90E66 is not set 522# CONFIG_BLK_DEV_SLC90E66 is not set
308# CONFIG_BLK_DEV_TRM290 is not set 523# CONFIG_BLK_DEV_TRM290 is not set
309# CONFIG_BLK_DEV_VIA82CXXX is not set 524CONFIG_BLK_DEV_VIA82CXXX=y
310# CONFIG_IDE_ARM is not set 525# CONFIG_IDE_ARM is not set
311# CONFIG_IDE_CHIPSETS is not set
312CONFIG_BLK_DEV_IDEDMA=y 526CONFIG_BLK_DEV_IDEDMA=y
313# CONFIG_IDEDMA_IVB is not set 527# CONFIG_IDEDMA_IVB is not set
314CONFIG_IDEDMA_AUTO=y 528CONFIG_IDEDMA_AUTO=y
@@ -317,8 +531,9 @@ CONFIG_IDEDMA_AUTO=y
317# 531#
318# SCSI device support 532# SCSI device support
319# 533#
534# CONFIG_RAID_ATTRS is not set
320CONFIG_SCSI=y 535CONFIG_SCSI=y
321CONFIG_SCSI_PROC_FS=y 536# CONFIG_SCSI_PROC_FS is not set
322 537
323# 538#
324# SCSI support type (disk, tape, CD-ROM) 539# SCSI support type (disk, tape, CD-ROM)
@@ -327,7 +542,8 @@ CONFIG_BLK_DEV_SD=y
327# CONFIG_CHR_DEV_ST is not set 542# CONFIG_CHR_DEV_ST is not set
328# CONFIG_CHR_DEV_OSST is not set 543# CONFIG_CHR_DEV_OSST is not set
329# CONFIG_BLK_DEV_SR is not set 544# CONFIG_BLK_DEV_SR is not set
330CONFIG_CHR_DEV_SG=y 545# CONFIG_CHR_DEV_SG is not set
546# CONFIG_CHR_DEV_SCH is not set
331 547
332# 548#
333# Some SCSI devices (e.g. CD jukebox) support multiple LUNs 549# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
@@ -341,79 +557,47 @@ CONFIG_CHR_DEV_SG=y
341# 557#
342# CONFIG_SCSI_SPI_ATTRS is not set 558# CONFIG_SCSI_SPI_ATTRS is not set
343# CONFIG_SCSI_FC_ATTRS is not set 559# CONFIG_SCSI_FC_ATTRS is not set
560# CONFIG_SCSI_ISCSI_ATTRS is not set
561# CONFIG_SCSI_SAS_ATTRS is not set
344 562
345# 563#
346# SCSI low-level drivers 564# SCSI low-level drivers
347# 565#
566# CONFIG_ISCSI_TCP is not set
348# CONFIG_BLK_DEV_3W_XXXX_RAID is not set 567# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
349# CONFIG_SCSI_7000FASST is not set 568# CONFIG_SCSI_3W_9XXX is not set
350# CONFIG_SCSI_ACARD is not set 569# CONFIG_SCSI_ACARD is not set
351# CONFIG_SCSI_AHA152X is not set
352# CONFIG_SCSI_AHA1542 is not set
353# CONFIG_SCSI_AACRAID is not set 570# CONFIG_SCSI_AACRAID is not set
354# CONFIG_SCSI_AIC7XXX is not set 571# CONFIG_SCSI_AIC7XXX is not set
355# CONFIG_SCSI_AIC7XXX_OLD is not set 572# CONFIG_SCSI_AIC7XXX_OLD is not set
356# CONFIG_SCSI_AIC79XX is not set 573# CONFIG_SCSI_AIC79XX is not set
357CONFIG_SCSI_DPT_I2O=m 574# CONFIG_SCSI_DPT_I2O is not set
358# CONFIG_SCSI_ADVANSYS is not set 575# CONFIG_MEGARAID_NEWGEN is not set
359# CONFIG_SCSI_IN2000 is not set 576# CONFIG_MEGARAID_LEGACY is not set
360# CONFIG_SCSI_MEGARAID is not set 577# CONFIG_MEGARAID_SAS is not set
361CONFIG_SCSI_SATA=y 578# CONFIG_SCSI_SATA is not set
362# CONFIG_SCSI_SATA_SVW is not set
363CONFIG_SCSI_ATA_PIIX=y
364# CONFIG_SCSI_SATA_PROMISE is not set
365CONFIG_SCSI_SATA_SX4=m
366# CONFIG_SCSI_SATA_SIL is not set
367CONFIG_SCSI_SATA_SIS=m
368# CONFIG_SCSI_SATA_VIA is not set
369# CONFIG_SCSI_SATA_VITESSE is not set
370# CONFIG_SCSI_BUSLOGIC is not set 579# CONFIG_SCSI_BUSLOGIC is not set
371# CONFIG_SCSI_CPQFCTS is not set
372# CONFIG_SCSI_DMX3191D is not set 580# CONFIG_SCSI_DMX3191D is not set
373# CONFIG_SCSI_DTC3280 is not set
374# CONFIG_SCSI_EATA is not set 581# CONFIG_SCSI_EATA is not set
375# CONFIG_SCSI_EATA_PIO is not set
376# CONFIG_SCSI_FUTURE_DOMAIN is not set 582# CONFIG_SCSI_FUTURE_DOMAIN is not set
377# CONFIG_SCSI_GDTH is not set 583# CONFIG_SCSI_GDTH is not set
378# CONFIG_SCSI_GENERIC_NCR5380 is not set
379# CONFIG_SCSI_GENERIC_NCR5380_MMIO is not set
380# CONFIG_SCSI_IPS is not set 584# CONFIG_SCSI_IPS is not set
585# CONFIG_SCSI_INITIO is not set
381# CONFIG_SCSI_INIA100 is not set 586# CONFIG_SCSI_INIA100 is not set
382# CONFIG_SCSI_PPA is not set 587# CONFIG_SCSI_PPA is not set
383# CONFIG_SCSI_IMM is not set 588# CONFIG_SCSI_IMM is not set
384# CONFIG_SCSI_NCR53C406A is not set
385# CONFIG_SCSI_SYM53C8XX_2 is not set 589# CONFIG_SCSI_SYM53C8XX_2 is not set
386CONFIG_SCSI_IPR=m 590# CONFIG_SCSI_IPR is not set
387# CONFIG_SCSI_IPR_TRACE is not set
388# CONFIG_SCSI_IPR_DUMP is not set
389# CONFIG_SCSI_PAS16 is not set
390# CONFIG_SCSI_PSI240I is not set
391# CONFIG_SCSI_QLOGIC_FAS is not set
392# CONFIG_SCSI_QLOGIC_ISP is not set
393# CONFIG_SCSI_QLOGIC_FC is not set 591# CONFIG_SCSI_QLOGIC_FC is not set
394# CONFIG_SCSI_QLOGIC_1280 is not set 592# CONFIG_SCSI_QLOGIC_1280 is not set
395CONFIG_SCSI_QLA2XXX=y 593# CONFIG_SCSI_QLA_FC is not set
396# CONFIG_SCSI_QLA21XX is not set 594# CONFIG_SCSI_LPFC is not set
397# CONFIG_SCSI_QLA22XX is not set
398# CONFIG_SCSI_QLA2300 is not set
399# CONFIG_SCSI_QLA2322 is not set
400# CONFIG_SCSI_QLA6312 is not set
401# CONFIG_SCSI_QLA6322 is not set
402# CONFIG_SCSI_SYM53C416 is not set
403# CONFIG_SCSI_DC395x is not set 595# CONFIG_SCSI_DC395x is not set
404# CONFIG_SCSI_DC390T is not set 596# CONFIG_SCSI_DC390T is not set
405# CONFIG_SCSI_T128 is not set
406# CONFIG_SCSI_U14_34F is not set
407# CONFIG_SCSI_ULTRASTOR is not set
408# CONFIG_SCSI_NSP32 is not set 597# CONFIG_SCSI_NSP32 is not set
409# CONFIG_SCSI_DEBUG is not set 598# CONFIG_SCSI_DEBUG is not set
410 599
411# 600#
412# Old CD-ROM drivers (not SCSI, not IDE)
413#
414# CONFIG_CD_NO_IDESCSI is not set
415
416#
417# Multi-device support (RAID and LVM) 601# Multi-device support (RAID and LVM)
418# 602#
419# CONFIG_MD is not set 603# CONFIG_MD is not set
@@ -422,37 +606,14 @@ CONFIG_SCSI_QLA2XXX=y
422# Fusion MPT device support 606# Fusion MPT device support
423# 607#
424# CONFIG_FUSION is not set 608# CONFIG_FUSION is not set
609# CONFIG_FUSION_SPI is not set
610# CONFIG_FUSION_FC is not set
611# CONFIG_FUSION_SAS is not set
425 612
426# 613#
427# IEEE 1394 (FireWire) support 614# IEEE 1394 (FireWire) support
428# 615#
429CONFIG_IEEE1394=y 616# CONFIG_IEEE1394 is not set
430
431#
432# Subsystem Options
433#
434# CONFIG_IEEE1394_VERBOSEDEBUG is not set
435# CONFIG_IEEE1394_OUI_DB is not set
436# CONFIG_IEEE1394_EXTRA_CONFIG_ROMS is not set
437
438#
439# Device Drivers
440#
441
442#
443# Texas Instruments PCILynx requires I2C
444#
445CONFIG_IEEE1394_OHCI1394=y
446
447#
448# Protocol Drivers
449#
450# CONFIG_IEEE1394_VIDEO1394 is not set
451# CONFIG_IEEE1394_SBP2 is not set
452# CONFIG_IEEE1394_ETH1394 is not set
453# CONFIG_IEEE1394_DV1394 is not set
454CONFIG_IEEE1394_RAWIO=y
455# CONFIG_IEEE1394_CMP is not set
456 617
457# 618#
458# I2O device support 619# I2O device support
@@ -460,130 +621,13 @@ CONFIG_IEEE1394_RAWIO=y
460# CONFIG_I2O is not set 621# CONFIG_I2O is not set
461 622
462# 623#
463# Networking support 624# Network device support
464#
465CONFIG_NET=y
466
467#
468# Networking options
469#
470CONFIG_PACKET=y
471# CONFIG_PACKET_MMAP is not set
472# CONFIG_NETLINK_DEV is not set
473CONFIG_UNIX=y
474# CONFIG_NET_KEY is not set
475CONFIG_INET=y
476CONFIG_IP_MULTICAST=y
477# CONFIG_IP_ADVANCED_ROUTER is not set
478# CONFIG_IP_PNP is not set
479# CONFIG_NET_IPIP is not set
480# CONFIG_NET_IPGRE is not set
481# CONFIG_IP_MROUTE is not set
482# CONFIG_ARPD is not set
483# CONFIG_SYN_COOKIES is not set
484# CONFIG_INET_AH is not set
485# CONFIG_INET_ESP is not set
486# CONFIG_INET_IPCOMP is not set
487
488#
489# IP: Virtual Server Configuration
490#
491# CONFIG_IP_VS is not set
492# CONFIG_IPV6 is not set
493CONFIG_NETFILTER=y
494# CONFIG_NETFILTER_DEBUG is not set
495
496#
497# IP: Netfilter Configuration
498# 625#
499CONFIG_IP_NF_CONNTRACK=y
500# CONFIG_IP_NF_FTP is not set
501# CONFIG_IP_NF_IRC is not set
502# CONFIG_IP_NF_TFTP is not set
503# CONFIG_IP_NF_AMANDA is not set
504CONFIG_IP_NF_QUEUE=y
505CONFIG_IP_NF_IPTABLES=y
506CONFIG_IP_NF_MATCH_LIMIT=y
507CONFIG_IP_NF_MATCH_IPRANGE=y
508CONFIG_IP_NF_MATCH_MAC=y
509CONFIG_IP_NF_MATCH_PKTTYPE=y
510CONFIG_IP_NF_MATCH_MARK=y
511CONFIG_IP_NF_MATCH_MULTIPORT=y
512CONFIG_IP_NF_MATCH_TOS=y
513CONFIG_IP_NF_MATCH_RECENT=y
514CONFIG_IP_NF_MATCH_ECN=y
515CONFIG_IP_NF_MATCH_DSCP=y
516CONFIG_IP_NF_MATCH_AH_ESP=y
517CONFIG_IP_NF_MATCH_LENGTH=y
518CONFIG_IP_NF_MATCH_TTL=y
519CONFIG_IP_NF_MATCH_TCPMSS=y
520CONFIG_IP_NF_MATCH_HELPER=y
521CONFIG_IP_NF_MATCH_STATE=y
522CONFIG_IP_NF_MATCH_CONNTRACK=y
523CONFIG_IP_NF_MATCH_OWNER=y
524CONFIG_IP_NF_FILTER=y
525CONFIG_IP_NF_TARGET_REJECT=y
526CONFIG_IP_NF_NAT=y
527CONFIG_IP_NF_NAT_NEEDED=y
528CONFIG_IP_NF_TARGET_MASQUERADE=y
529CONFIG_IP_NF_TARGET_REDIRECT=y
530CONFIG_IP_NF_TARGET_NETMAP=y
531CONFIG_IP_NF_TARGET_SAME=y
532# CONFIG_IP_NF_NAT_SNMP_BASIC is not set
533CONFIG_IP_NF_MANGLE=y
534CONFIG_IP_NF_TARGET_TOS=y
535CONFIG_IP_NF_TARGET_ECN=y
536CONFIG_IP_NF_TARGET_DSCP=y
537CONFIG_IP_NF_TARGET_MARK=y
538CONFIG_IP_NF_TARGET_CLASSIFY=y
539CONFIG_IP_NF_TARGET_LOG=y
540CONFIG_IP_NF_TARGET_ULOG=y
541CONFIG_IP_NF_TARGET_TCPMSS=y
542CONFIG_IP_NF_ARPTABLES=y
543CONFIG_IP_NF_ARPFILTER=y
544CONFIG_IP_NF_ARP_MANGLE=y
545CONFIG_IP_NF_TARGET_NOTRACK=m
546CONFIG_IP_NF_RAW=m
547
548#
549# SCTP Configuration (EXPERIMENTAL)
550#
551# CONFIG_IP_SCTP is not set
552# CONFIG_ATM is not set
553# CONFIG_BRIDGE is not set
554# CONFIG_VLAN_8021Q is not set
555# CONFIG_DECNET is not set
556# CONFIG_LLC2 is not set
557# CONFIG_IPX is not set
558# CONFIG_ATALK is not set
559# CONFIG_X25 is not set
560# CONFIG_LAPB is not set
561# CONFIG_NET_DIVERT is not set
562# CONFIG_ECONET is not set
563# CONFIG_WAN_ROUTER is not set
564# CONFIG_NET_FASTROUTE is not set
565# CONFIG_NET_HW_FLOWCONTROL is not set
566
567#
568# QoS and/or fair queueing
569#
570# CONFIG_NET_SCHED is not set
571
572#
573# Network testing
574#
575# CONFIG_NET_PKTGEN is not set
576# CONFIG_NETPOLL is not set
577# CONFIG_NET_POLL_CONTROLLER is not set
578# CONFIG_HAMRADIO is not set
579# CONFIG_IRDA is not set
580# CONFIG_BT is not set
581CONFIG_NETDEVICES=y 626CONFIG_NETDEVICES=y
582CONFIG_DUMMY=m 627# CONFIG_DUMMY is not set
583# CONFIG_BONDING is not set 628# CONFIG_BONDING is not set
584# CONFIG_EQUALIZER is not set 629# CONFIG_EQUALIZER is not set
585# CONFIG_TUN is not set 630# CONFIG_TUN is not set
586# CONFIG_NET_SB1000 is not set
587 631
588# 632#
589# ARCnet devices 633# ARCnet devices
@@ -591,46 +635,39 @@ CONFIG_DUMMY=m
591# CONFIG_ARCNET is not set 635# CONFIG_ARCNET is not set
592 636
593# 637#
638# PHY device support
639#
640# CONFIG_PHYLIB is not set
641
642#
594# Ethernet (10 or 100Mbit) 643# Ethernet (10 or 100Mbit)
595# 644#
596CONFIG_NET_ETHERNET=y 645CONFIG_NET_ETHERNET=y
597CONFIG_MII=y 646CONFIG_MII=y
598# CONFIG_HAPPYMEAL is not set 647# CONFIG_HAPPYMEAL is not set
599# CONFIG_SUNGEM is not set 648# CONFIG_SUNGEM is not set
649# CONFIG_CASSINI is not set
600# CONFIG_NET_VENDOR_3COM is not set 650# CONFIG_NET_VENDOR_3COM is not set
601# CONFIG_LANCE is not set
602# CONFIG_NET_VENDOR_SMC is not set
603# CONFIG_NET_VENDOR_RACAL is not set
604 651
605# 652#
606# Tulip family network device support 653# Tulip family network device support
607# 654#
608# CONFIG_NET_TULIP is not set 655# CONFIG_NET_TULIP is not set
609# CONFIG_AT1700 is not set
610# CONFIG_DEPCA is not set
611# CONFIG_HP100 is not set 656# CONFIG_HP100 is not set
612# CONFIG_NET_ISA is not set
613CONFIG_NET_PCI=y 657CONFIG_NET_PCI=y
614# CONFIG_PCNET32 is not set 658# CONFIG_PCNET32 is not set
615# CONFIG_AMD8111_ETH is not set 659# CONFIG_AMD8111_ETH is not set
616# CONFIG_ADAPTEC_STARFIRE is not set 660# CONFIG_ADAPTEC_STARFIRE is not set
617# CONFIG_AC3200 is not set
618# CONFIG_APRICOT is not set
619# CONFIG_B44 is not set 661# CONFIG_B44 is not set
620# CONFIG_FORCEDETH is not set 662# CONFIG_FORCEDETH is not set
621# CONFIG_CS89x0 is not set
622# CONFIG_DGRS is not set 663# CONFIG_DGRS is not set
623# CONFIG_EEPRO100 is not set 664# CONFIG_EEPRO100 is not set
624# CONFIG_E100 is not set 665CONFIG_E100=y
625# CONFIG_FEALNX is not set 666# CONFIG_FEALNX is not set
626# CONFIG_NATSEMI is not set 667# CONFIG_NATSEMI is not set
627# CONFIG_NE2K_PCI is not set 668# CONFIG_NE2K_PCI is not set
628# CONFIG_8139CP is not set 669# CONFIG_8139CP is not set
629CONFIG_8139TOO=y 670# CONFIG_8139TOO is not set
630CONFIG_8139TOO_PIO=y
631# CONFIG_8139TOO_TUNE_TWISTER is not set
632# CONFIG_8139TOO_8129 is not set
633# CONFIG_8139_OLD_RX_RESET is not set
634# CONFIG_SIS900 is not set 671# CONFIG_SIS900 is not set
635# CONFIG_EPIC100 is not set 672# CONFIG_EPIC100 is not set
636# CONFIG_SUNDANCE is not set 673# CONFIG_SUNDANCE is not set
@@ -644,21 +681,24 @@ CONFIG_8139TOO_PIO=y
644# CONFIG_ACENIC is not set 681# CONFIG_ACENIC is not set
645# CONFIG_DL2K is not set 682# CONFIG_DL2K is not set
646# CONFIG_E1000 is not set 683# CONFIG_E1000 is not set
647# CONFIG_E1000_NAPI is not set
648# CONFIG_E1000_DISABLE_PACKET_SPLIT is not set
649# CONFIG_NS83820 is not set 684# CONFIG_NS83820 is not set
650# CONFIG_HAMACHI is not set 685# CONFIG_HAMACHI is not set
651# CONFIG_YELLOWFIN is not set 686# CONFIG_YELLOWFIN is not set
652# CONFIG_R8169 is not set 687# CONFIG_R8169 is not set
688# CONFIG_SIS190 is not set
689# CONFIG_SKGE is not set
690# CONFIG_SKY2 is not set
653# CONFIG_SK98LIN is not set 691# CONFIG_SK98LIN is not set
692# CONFIG_VIA_VELOCITY is not set
654# CONFIG_TIGON3 is not set 693# CONFIG_TIGON3 is not set
694# CONFIG_BNX2 is not set
655 695
656# 696#
657# Ethernet (10000 Mbit) 697# Ethernet (10000 Mbit)
658# 698#
699# CONFIG_CHELSIO_T1 is not set
659# CONFIG_IXGB is not set 700# CONFIG_IXGB is not set
660CONFIG_S2IO=m 701# CONFIG_S2IO is not set
661# CONFIG_S2IO_NAPI is not set
662 702
663# 703#
664# Token Ring devices 704# Token Ring devices
@@ -682,6 +722,8 @@ CONFIG_S2IO=m
682# CONFIG_NET_FC is not set 722# CONFIG_NET_FC is not set
683# CONFIG_SHAPER is not set 723# CONFIG_SHAPER is not set
684# CONFIG_NETCONSOLE is not set 724# CONFIG_NETCONSOLE is not set
725# CONFIG_NETPOLL is not set
726# CONFIG_NET_POLL_CONTROLLER is not set
685 727
686# 728#
687# ISDN subsystem 729# ISDN subsystem
@@ -703,26 +745,14 @@ CONFIG_INPUT=y
703# 745#
704CONFIG_INPUT_MOUSEDEV=y 746CONFIG_INPUT_MOUSEDEV=y
705CONFIG_INPUT_MOUSEDEV_PSAUX=y 747CONFIG_INPUT_MOUSEDEV_PSAUX=y
706CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024 748CONFIG_INPUT_MOUSEDEV_SCREEN_X=1280
707CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768 749CONFIG_INPUT_MOUSEDEV_SCREEN_Y=1024
708# CONFIG_INPUT_JOYDEV is not set 750# CONFIG_INPUT_JOYDEV is not set
709# CONFIG_INPUT_TSDEV is not set 751# CONFIG_INPUT_TSDEV is not set
710# CONFIG_INPUT_EVDEV is not set 752CONFIG_INPUT_EVDEV=y
711# CONFIG_INPUT_EVBUG is not set 753# CONFIG_INPUT_EVBUG is not set
712 754
713# 755#
714# Input I/O drivers
715#
716# CONFIG_GAMEPORT is not set
717CONFIG_SOUND_GAMEPORT=y
718CONFIG_SERIO=y
719CONFIG_SERIO_I8042=y
720# CONFIG_SERIO_SERPORT is not set
721# CONFIG_SERIO_CT82C710 is not set
722# CONFIG_SERIO_PARKBD is not set
723# CONFIG_SERIO_PCIPS2 is not set
724
725#
726# Input Device Drivers 756# Input Device Drivers
727# 757#
728CONFIG_INPUT_KEYBOARD=y 758CONFIG_INPUT_KEYBOARD=y
@@ -734,15 +764,25 @@ CONFIG_KEYBOARD_ATKBD=y
734CONFIG_INPUT_MOUSE=y 764CONFIG_INPUT_MOUSE=y
735CONFIG_MOUSE_PS2=y 765CONFIG_MOUSE_PS2=y
736# CONFIG_MOUSE_SERIAL is not set 766# CONFIG_MOUSE_SERIAL is not set
737# CONFIG_MOUSE_INPORT is not set
738# CONFIG_MOUSE_LOGIBM is not set
739# CONFIG_MOUSE_PC110PAD is not set
740# CONFIG_MOUSE_VSXXXAA is not set 767# CONFIG_MOUSE_VSXXXAA is not set
741# CONFIG_INPUT_JOYSTICK is not set 768# CONFIG_INPUT_JOYSTICK is not set
742# CONFIG_INPUT_TOUCHSCREEN is not set 769# CONFIG_INPUT_TOUCHSCREEN is not set
743# CONFIG_INPUT_MISC is not set 770# CONFIG_INPUT_MISC is not set
744 771
745# 772#
773# Hardware I/O ports
774#
775CONFIG_SERIO=y
776CONFIG_SERIO_I8042=y
777# CONFIG_SERIO_SERPORT is not set
778# CONFIG_SERIO_CT82C710 is not set
779# CONFIG_SERIO_PARKBD is not set
780# CONFIG_SERIO_PCIPS2 is not set
781CONFIG_SERIO_LIBPS2=y
782# CONFIG_SERIO_RAW is not set
783# CONFIG_GAMEPORT is not set
784
785#
746# Character devices 786# Character devices
747# 787#
748CONFIG_VT=y 788CONFIG_VT=y
@@ -757,12 +797,14 @@ CONFIG_SERIAL_8250=y
757# CONFIG_SERIAL_8250_CONSOLE is not set 797# CONFIG_SERIAL_8250_CONSOLE is not set
758# CONFIG_SERIAL_8250_ACPI is not set 798# CONFIG_SERIAL_8250_ACPI is not set
759CONFIG_SERIAL_8250_NR_UARTS=4 799CONFIG_SERIAL_8250_NR_UARTS=4
800CONFIG_SERIAL_8250_RUNTIME_UARTS=4
760# CONFIG_SERIAL_8250_EXTENDED is not set 801# CONFIG_SERIAL_8250_EXTENDED is not set
761 802
762# 803#
763# Non-8250 serial port support 804# Non-8250 serial port support
764# 805#
765CONFIG_SERIAL_CORE=y 806CONFIG_SERIAL_CORE=y
807# CONFIG_SERIAL_JSM is not set
766CONFIG_UNIX98_PTYS=y 808CONFIG_UNIX98_PTYS=y
767CONFIG_LEGACY_PTYS=y 809CONFIG_LEGACY_PTYS=y
768CONFIG_LEGACY_PTY_COUNT=256 810CONFIG_LEGACY_PTY_COUNT=256
@@ -770,7 +812,6 @@ CONFIG_PRINTER=y
770# CONFIG_LP_CONSOLE is not set 812# CONFIG_LP_CONSOLE is not set
771# CONFIG_PPDEV is not set 813# CONFIG_PPDEV is not set
772# CONFIG_TIPAR is not set 814# CONFIG_TIPAR is not set
773# CONFIG_QIC02_TAPE is not set
774 815
775# 816#
776# IPMI 817# IPMI
@@ -782,9 +823,8 @@ CONFIG_PRINTER=y
782# 823#
783# CONFIG_WATCHDOG is not set 824# CONFIG_WATCHDOG is not set
784# CONFIG_HW_RANDOM is not set 825# CONFIG_HW_RANDOM is not set
785# CONFIG_NVRAM is not set 826CONFIG_NVRAM=y
786# CONFIG_RTC is not set 827CONFIG_RTC=y
787# CONFIG_GEN_RTC is not set
788# CONFIG_DTLK is not set 828# CONFIG_DTLK is not set
789# CONFIG_R3964 is not set 829# CONFIG_R3964 is not set
790# CONFIG_APPLICOM is not set 830# CONFIG_APPLICOM is not set
@@ -793,34 +833,149 @@ CONFIG_PRINTER=y
793# 833#
794# Ftape, the floppy tape device driver 834# Ftape, the floppy tape device driver
795# 835#
836# CONFIG_FTAPE is not set
796CONFIG_AGP=y 837CONFIG_AGP=y
797# CONFIG_AGP_ALI is not set 838# CONFIG_AGP_ALI is not set
798# CONFIG_AGP_ATI is not set 839# CONFIG_AGP_ATI is not set
799# CONFIG_AGP_AMD is not set 840# CONFIG_AGP_AMD is not set
800# CONFIG_AGP_AMD64 is not set 841# CONFIG_AGP_AMD64 is not set
801CONFIG_AGP_INTEL=y 842# CONFIG_AGP_INTEL is not set
802# CONFIG_AGP_NVIDIA is not set 843# CONFIG_AGP_NVIDIA is not set
803# CONFIG_AGP_SIS is not set 844# CONFIG_AGP_SIS is not set
804# CONFIG_AGP_SWORKS is not set 845# CONFIG_AGP_SWORKS is not set
805# CONFIG_AGP_VIA is not set 846CONFIG_AGP_VIA=y
806# CONFIG_AGP_EFFICEON is not set 847# CONFIG_AGP_EFFICEON is not set
807CONFIG_DRM=y 848CONFIG_DRM=y
808# CONFIG_DRM_TDFX is not set 849# CONFIG_DRM_TDFX is not set
809# CONFIG_DRM_GAMMA is not set
810# CONFIG_DRM_R128 is not set 850# CONFIG_DRM_R128 is not set
811# CONFIG_DRM_RADEON is not set 851CONFIG_DRM_RADEON=y
812# CONFIG_DRM_I810 is not set
813CONFIG_DRM_I830=y
814# CONFIG_DRM_MGA is not set 852# CONFIG_DRM_MGA is not set
815# CONFIG_DRM_SIS is not set 853# CONFIG_DRM_SIS is not set
854# CONFIG_DRM_VIA is not set
855# CONFIG_DRM_SAVAGE is not set
816# CONFIG_MWAVE is not set 856# CONFIG_MWAVE is not set
857# CONFIG_CS5535_GPIO is not set
817# CONFIG_RAW_DRIVER is not set 858# CONFIG_RAW_DRIVER is not set
859# CONFIG_HPET is not set
818# CONFIG_HANGCHECK_TIMER is not set 860# CONFIG_HANGCHECK_TIMER is not set
819 861
820# 862#
863# TPM devices
864#
865# CONFIG_TCG_TPM is not set
866# CONFIG_TELCLOCK is not set
867
868#
821# I2C support 869# I2C support
822# 870#
823# CONFIG_I2C is not set 871CONFIG_I2C=y
872CONFIG_I2C_CHARDEV=y
873
874#
875# I2C Algorithms
876#
877CONFIG_I2C_ALGOBIT=y
878# CONFIG_I2C_ALGOPCF is not set
879# CONFIG_I2C_ALGOPCA is not set
880
881#
882# I2C Hardware Bus support
883#
884# CONFIG_I2C_ALI1535 is not set
885# CONFIG_I2C_ALI1563 is not set
886# CONFIG_I2C_ALI15X3 is not set
887# CONFIG_I2C_AMD756 is not set
888# CONFIG_I2C_AMD8111 is not set
889# CONFIG_I2C_I801 is not set
890# CONFIG_I2C_I810 is not set
891# CONFIG_I2C_PIIX4 is not set
892CONFIG_I2C_ISA=y
893# CONFIG_I2C_NFORCE2 is not set
894# CONFIG_I2C_PARPORT is not set
895# CONFIG_I2C_PARPORT_LIGHT is not set
896# CONFIG_I2C_PROSAVAGE is not set
897# CONFIG_I2C_SAVAGE4 is not set
898# CONFIG_SCx200_ACB is not set
899# CONFIG_I2C_SIS5595 is not set
900# CONFIG_I2C_SIS630 is not set
901# CONFIG_I2C_SIS96X is not set
902# CONFIG_I2C_STUB is not set
903# CONFIG_I2C_VIA is not set
904CONFIG_I2C_VIAPRO=y
905# CONFIG_I2C_VOODOO3 is not set
906# CONFIG_I2C_PCA_ISA is not set
907
908#
909# Miscellaneous I2C Chip support
910#
911# CONFIG_SENSORS_DS1337 is not set
912# CONFIG_SENSORS_DS1374 is not set
913# CONFIG_SENSORS_EEPROM is not set
914# CONFIG_SENSORS_PCF8574 is not set
915# CONFIG_SENSORS_PCA9539 is not set
916# CONFIG_SENSORS_PCF8591 is not set
917# CONFIG_SENSORS_RTC8564 is not set
918# CONFIG_SENSORS_MAX6875 is not set
919# CONFIG_RTC_X1205_I2C is not set
920# CONFIG_I2C_DEBUG_CORE is not set
921# CONFIG_I2C_DEBUG_ALGO is not set
922# CONFIG_I2C_DEBUG_BUS is not set
923# CONFIG_I2C_DEBUG_CHIP is not set
924
925#
926# SPI support
927#
928# CONFIG_SPI is not set
929# CONFIG_SPI_MASTER is not set
930
931#
932# Dallas's 1-wire bus
933#
934# CONFIG_W1 is not set
935
936#
937# Hardware Monitoring support
938#
939CONFIG_HWMON=y
940CONFIG_HWMON_VID=y
941# CONFIG_SENSORS_ADM1021 is not set
942# CONFIG_SENSORS_ADM1025 is not set
943# CONFIG_SENSORS_ADM1026 is not set
944# CONFIG_SENSORS_ADM1031 is not set
945# CONFIG_SENSORS_ADM9240 is not set
946# CONFIG_SENSORS_ASB100 is not set
947# CONFIG_SENSORS_ATXP1 is not set
948# CONFIG_SENSORS_DS1621 is not set
949# CONFIG_SENSORS_F71805F is not set
950# CONFIG_SENSORS_FSCHER is not set
951# CONFIG_SENSORS_FSCPOS is not set
952# CONFIG_SENSORS_GL518SM is not set
953# CONFIG_SENSORS_GL520SM is not set
954CONFIG_SENSORS_IT87=y
955# CONFIG_SENSORS_LM63 is not set
956# CONFIG_SENSORS_LM75 is not set
957# CONFIG_SENSORS_LM77 is not set
958# CONFIG_SENSORS_LM78 is not set
959# CONFIG_SENSORS_LM80 is not set
960# CONFIG_SENSORS_LM83 is not set
961# CONFIG_SENSORS_LM85 is not set
962# CONFIG_SENSORS_LM87 is not set
963# CONFIG_SENSORS_LM90 is not set
964# CONFIG_SENSORS_LM92 is not set
965# CONFIG_SENSORS_MAX1619 is not set
966# CONFIG_SENSORS_PC87360 is not set
967# CONFIG_SENSORS_SIS5595 is not set
968# CONFIG_SENSORS_SMSC47M1 is not set
969# CONFIG_SENSORS_SMSC47B397 is not set
970# CONFIG_SENSORS_VIA686A is not set
971# CONFIG_SENSORS_VT8231 is not set
972# CONFIG_SENSORS_W83781D is not set
973# CONFIG_SENSORS_W83792D is not set
974# CONFIG_SENSORS_W83L785TS is not set
975# CONFIG_SENSORS_W83627HF is not set
976# CONFIG_SENSORS_W83627EHF is not set
977# CONFIG_SENSORS_HDAPS is not set
978# CONFIG_HWMON_DEBUG_CHIP is not set
824 979
825# 980#
826# Misc devices 981# Misc devices
@@ -828,27 +983,118 @@ CONFIG_DRM_I830=y
828# CONFIG_IBM_ASM is not set 983# CONFIG_IBM_ASM is not set
829 984
830# 985#
986# Multimedia Capabilities Port drivers
987#
988
989#
831# Multimedia devices 990# Multimedia devices
832# 991#
833# CONFIG_VIDEO_DEV is not set 992CONFIG_VIDEO_DEV=y
993
994#
995# Video For Linux
996#
997
998#
999# Video Adapters
1000#
1001# CONFIG_VIDEO_ADV_DEBUG is not set
1002# CONFIG_VIDEO_BT848 is not set
1003# CONFIG_VIDEO_BWQCAM is not set
1004# CONFIG_VIDEO_CQCAM is not set
1005# CONFIG_VIDEO_W9966 is not set
1006# CONFIG_VIDEO_CPIA is not set
1007# CONFIG_VIDEO_SAA5246A is not set
1008# CONFIG_VIDEO_SAA5249 is not set
1009# CONFIG_TUNER_3036 is not set
1010# CONFIG_VIDEO_STRADIS is not set
1011# CONFIG_VIDEO_ZORAN is not set
1012CONFIG_VIDEO_SAA7134=y
1013# CONFIG_VIDEO_SAA7134_ALSA is not set
1014# CONFIG_VIDEO_MXB is not set
1015# CONFIG_VIDEO_DPC is not set
1016# CONFIG_VIDEO_HEXIUM_ORION is not set
1017# CONFIG_VIDEO_HEXIUM_GEMINI is not set
1018# CONFIG_VIDEO_CX88 is not set
1019# CONFIG_VIDEO_EM28XX is not set
1020# CONFIG_VIDEO_OVCAMCHIP is not set
1021# CONFIG_VIDEO_AUDIO_DECODER is not set
1022# CONFIG_VIDEO_DECODER is not set
1023
1024#
1025# Radio Adapters
1026#
1027# CONFIG_RADIO_GEMTEK_PCI is not set
1028# CONFIG_RADIO_MAXIRADIO is not set
1029# CONFIG_RADIO_MAESTRO is not set
834 1030
835# 1031#
836# Digital Video Broadcasting Devices 1032# Digital Video Broadcasting Devices
837# 1033#
838# CONFIG_DVB is not set 1034# CONFIG_DVB is not set
1035CONFIG_VIDEO_TUNER=y
1036CONFIG_VIDEO_BUF=y
1037CONFIG_VIDEO_IR=y
839 1038
840# 1039#
841# Graphics support 1040# Graphics support
842# 1041#
843# CONFIG_FB is not set 1042CONFIG_FB=y
844# CONFIG_VIDEO_SELECT is not set 1043CONFIG_FB_CFB_FILLRECT=y
1044CONFIG_FB_CFB_COPYAREA=y
1045CONFIG_FB_CFB_IMAGEBLIT=y
1046# CONFIG_FB_MACMODES is not set
1047CONFIG_FB_MODE_HELPERS=y
1048# CONFIG_FB_TILEBLITTING is not set
1049# CONFIG_FB_CIRRUS is not set
1050# CONFIG_FB_PM2 is not set
1051# CONFIG_FB_CYBER2000 is not set
1052# CONFIG_FB_ARC is not set
1053# CONFIG_FB_ASILIANT is not set
1054# CONFIG_FB_IMSTT is not set
1055# CONFIG_FB_VGA16 is not set
1056# CONFIG_FB_VESA is not set
1057CONFIG_VIDEO_SELECT=y
1058# CONFIG_FB_HGA is not set
1059# CONFIG_FB_S1D13XXX is not set
1060# CONFIG_FB_NVIDIA is not set
1061# CONFIG_FB_RIVA is not set
1062# CONFIG_FB_I810 is not set
1063# CONFIG_FB_INTEL is not set
1064# CONFIG_FB_MATROX is not set
1065# CONFIG_FB_RADEON_OLD is not set
1066CONFIG_FB_RADEON=y
1067CONFIG_FB_RADEON_I2C=y
1068# CONFIG_FB_RADEON_DEBUG is not set
1069# CONFIG_FB_ATY128 is not set
1070# CONFIG_FB_ATY is not set
1071# CONFIG_FB_SAVAGE is not set
1072# CONFIG_FB_SIS is not set
1073# CONFIG_FB_NEOMAGIC is not set
1074# CONFIG_FB_KYRO is not set
1075# CONFIG_FB_3DFX is not set
1076# CONFIG_FB_VOODOO1 is not set
1077# CONFIG_FB_CYBLA is not set
1078# CONFIG_FB_TRIDENT is not set
1079# CONFIG_FB_GEODE is not set
1080# CONFIG_FB_VIRTUAL is not set
845 1081
846# 1082#
847# Console display driver support 1083# Console display driver support
848# 1084#
849CONFIG_VGA_CONSOLE=y 1085CONFIG_VGA_CONSOLE=y
850# CONFIG_MDA_CONSOLE is not set
851CONFIG_DUMMY_CONSOLE=y 1086CONFIG_DUMMY_CONSOLE=y
1087CONFIG_FRAMEBUFFER_CONSOLE=y
1088# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
1089# CONFIG_FONTS is not set
1090CONFIG_FONT_8x8=y
1091CONFIG_FONT_8x16=y
1092
1093#
1094# Logo configuration
1095#
1096# CONFIG_LOGO is not set
1097# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
852 1098
853# 1099#
854# Sound 1100# Sound
@@ -864,10 +1110,13 @@ CONFIG_SND_PCM=y
864CONFIG_SND_RAWMIDI=y 1110CONFIG_SND_RAWMIDI=y
865CONFIG_SND_SEQUENCER=y 1111CONFIG_SND_SEQUENCER=y
866# CONFIG_SND_SEQ_DUMMY is not set 1112# CONFIG_SND_SEQ_DUMMY is not set
867CONFIG_SND_OSSEMUL=y 1113# CONFIG_SND_MIXER_OSS is not set
868CONFIG_SND_MIXER_OSS=y 1114# CONFIG_SND_PCM_OSS is not set
869CONFIG_SND_PCM_OSS=y 1115# CONFIG_SND_SEQUENCER_OSS is not set
870CONFIG_SND_SEQUENCER_OSS=y 1116CONFIG_SND_RTCTIMER=y
1117CONFIG_SND_SEQ_RTCTIMER_DEFAULT=y
1118# CONFIG_SND_DYNAMIC_MINORS is not set
1119# CONFIG_SND_SUPPORT_OLD_API is not set
871# CONFIG_SND_VERBOSE_PRINTK is not set 1120# CONFIG_SND_VERBOSE_PRINTK is not set
872# CONFIG_SND_DEBUG is not set 1121# CONFIG_SND_DEBUG is not set
873 1122
@@ -875,6 +1124,8 @@ CONFIG_SND_SEQUENCER_OSS=y
875# Generic devices 1124# Generic devices
876# 1125#
877CONFIG_SND_MPU401_UART=y 1126CONFIG_SND_MPU401_UART=y
1127CONFIG_SND_AC97_CODEC=y
1128CONFIG_SND_AC97_BUS=y
878# CONFIG_SND_DUMMY is not set 1129# CONFIG_SND_DUMMY is not set
879# CONFIG_SND_VIRMIDI is not set 1130# CONFIG_SND_VIRMIDI is not set
880# CONFIG_SND_MTPAV is not set 1131# CONFIG_SND_MTPAV is not set
@@ -882,74 +1133,57 @@ CONFIG_SND_MPU401_UART=y
882# CONFIG_SND_MPU401 is not set 1133# CONFIG_SND_MPU401 is not set
883 1134
884# 1135#
885# ISA devices
886#
887# CONFIG_SND_AD1848 is not set
888# CONFIG_SND_CS4231 is not set
889# CONFIG_SND_CS4232 is not set
890# CONFIG_SND_CS4236 is not set
891# CONFIG_SND_ES1688 is not set
892# CONFIG_SND_ES18XX is not set
893# CONFIG_SND_GUSCLASSIC is not set
894# CONFIG_SND_GUSEXTREME is not set
895# CONFIG_SND_GUSMAX is not set
896# CONFIG_SND_INTERWAVE is not set
897# CONFIG_SND_INTERWAVE_STB is not set
898# CONFIG_SND_OPTI92X_AD1848 is not set
899# CONFIG_SND_OPTI92X_CS4231 is not set
900# CONFIG_SND_OPTI93X is not set
901# CONFIG_SND_SB8 is not set
902# CONFIG_SND_SB16 is not set
903# CONFIG_SND_SBAWE is not set
904# CONFIG_SND_WAVEFRONT is not set
905# CONFIG_SND_CMI8330 is not set
906# CONFIG_SND_OPL3SA2 is not set
907# CONFIG_SND_SGALAXY is not set
908# CONFIG_SND_SSCAPE is not set
909
910#
911# PCI devices 1136# PCI devices
912# 1137#
913CONFIG_SND_AC97_CODEC=y 1138# CONFIG_SND_AD1889 is not set
1139# CONFIG_SND_ALS4000 is not set
914# CONFIG_SND_ALI5451 is not set 1140# CONFIG_SND_ALI5451 is not set
915# CONFIG_SND_ATIIXP is not set 1141# CONFIG_SND_ATIIXP is not set
1142# CONFIG_SND_ATIIXP_MODEM is not set
916# CONFIG_SND_AU8810 is not set 1143# CONFIG_SND_AU8810 is not set
917# CONFIG_SND_AU8820 is not set 1144# CONFIG_SND_AU8820 is not set
918# CONFIG_SND_AU8830 is not set 1145# CONFIG_SND_AU8830 is not set
919# CONFIG_SND_AZT3328 is not set 1146# CONFIG_SND_AZT3328 is not set
920# CONFIG_SND_BT87X is not set 1147# CONFIG_SND_BT87X is not set
921# CONFIG_SND_CS46XX is not set 1148# CONFIG_SND_CA0106 is not set
1149# CONFIG_SND_CMIPCI is not set
922# CONFIG_SND_CS4281 is not set 1150# CONFIG_SND_CS4281 is not set
1151# CONFIG_SND_CS46XX is not set
1152# CONFIG_SND_CS5535AUDIO is not set
923# CONFIG_SND_EMU10K1 is not set 1153# CONFIG_SND_EMU10K1 is not set
924# CONFIG_SND_KORG1212 is not set 1154# CONFIG_SND_EMU10K1X is not set
925# CONFIG_SND_MIXART is not set
926# CONFIG_SND_NM256 is not set
927# CONFIG_SND_RME32 is not set
928# CONFIG_SND_RME96 is not set
929# CONFIG_SND_RME9652 is not set
930# CONFIG_SND_HDSP is not set
931# CONFIG_SND_TRIDENT is not set
932# CONFIG_SND_YMFPCI is not set
933# CONFIG_SND_ALS4000 is not set
934# CONFIG_SND_CMIPCI is not set
935# CONFIG_SND_ENS1370 is not set 1155# CONFIG_SND_ENS1370 is not set
936# CONFIG_SND_ENS1371 is not set 1156# CONFIG_SND_ENS1371 is not set
937# CONFIG_SND_ES1938 is not set 1157# CONFIG_SND_ES1938 is not set
938# CONFIG_SND_ES1968 is not set 1158# CONFIG_SND_ES1968 is not set
939# CONFIG_SND_MAESTRO3 is not set
940# CONFIG_SND_FM801 is not set 1159# CONFIG_SND_FM801 is not set
1160# CONFIG_SND_HDA_INTEL is not set
1161# CONFIG_SND_HDSP is not set
1162# CONFIG_SND_HDSPM is not set
941# CONFIG_SND_ICE1712 is not set 1163# CONFIG_SND_ICE1712 is not set
942# CONFIG_SND_ICE1724 is not set 1164# CONFIG_SND_ICE1724 is not set
943CONFIG_SND_INTEL8X0=y 1165# CONFIG_SND_INTEL8X0 is not set
944# CONFIG_SND_INTEL8X0M is not set 1166# CONFIG_SND_INTEL8X0M is not set
1167# CONFIG_SND_KORG1212 is not set
1168# CONFIG_SND_MAESTRO3 is not set
1169# CONFIG_SND_MIXART is not set
1170# CONFIG_SND_NM256 is not set
1171# CONFIG_SND_PCXHR is not set
1172# CONFIG_SND_RME32 is not set
1173# CONFIG_SND_RME96 is not set
1174# CONFIG_SND_RME9652 is not set
945# CONFIG_SND_SONICVIBES is not set 1175# CONFIG_SND_SONICVIBES is not set
946# CONFIG_SND_VIA82XX is not set 1176# CONFIG_SND_TRIDENT is not set
1177CONFIG_SND_VIA82XX=y
1178# CONFIG_SND_VIA82XX_MODEM is not set
947# CONFIG_SND_VX222 is not set 1179# CONFIG_SND_VX222 is not set
1180# CONFIG_SND_YMFPCI is not set
948 1181
949# 1182#
950# ALSA USB devices 1183# USB devices
951# 1184#
952# CONFIG_SND_USB_AUDIO is not set 1185# CONFIG_SND_USB_AUDIO is not set
1186# CONFIG_SND_USB_USX2Y is not set
953 1187
954# 1188#
955# Open Sound System 1189# Open Sound System
@@ -959,6 +1193,8 @@ CONFIG_SND_INTEL8X0=y
959# 1193#
960# USB support 1194# USB support
961# 1195#
1196CONFIG_USB_ARCH_HAS_HCD=y
1197CONFIG_USB_ARCH_HAS_OHCI=y
962CONFIG_USB=y 1198CONFIG_USB=y
963# CONFIG_USB_DEBUG is not set 1199# CONFIG_USB_DEBUG is not set
964 1200
@@ -968,6 +1204,8 @@ CONFIG_USB=y
968CONFIG_USB_DEVICEFS=y 1204CONFIG_USB_DEVICEFS=y
969# CONFIG_USB_BANDWIDTH is not set 1205# CONFIG_USB_BANDWIDTH is not set
970# CONFIG_USB_DYNAMIC_MINORS is not set 1206# CONFIG_USB_DYNAMIC_MINORS is not set
1207# CONFIG_USB_SUSPEND is not set
1208# CONFIG_USB_OTG is not set
971 1209
972# 1210#
973# USB Host Controller Drivers 1211# USB Host Controller Drivers
@@ -975,68 +1213,93 @@ CONFIG_USB_DEVICEFS=y
975CONFIG_USB_EHCI_HCD=y 1213CONFIG_USB_EHCI_HCD=y
976# CONFIG_USB_EHCI_SPLIT_ISO is not set 1214# CONFIG_USB_EHCI_SPLIT_ISO is not set
977# CONFIG_USB_EHCI_ROOT_HUB_TT is not set 1215# CONFIG_USB_EHCI_ROOT_HUB_TT is not set
1216# CONFIG_USB_ISP116X_HCD is not set
978# CONFIG_USB_OHCI_HCD is not set 1217# CONFIG_USB_OHCI_HCD is not set
979CONFIG_USB_UHCI_HCD=y 1218CONFIG_USB_UHCI_HCD=y
1219# CONFIG_USB_SL811_HCD is not set
980 1220
981# 1221#
982# USB Device Class drivers 1222# USB Device Class drivers
983# 1223#
984# CONFIG_USB_AUDIO is not set 1224# CONFIG_OBSOLETE_OSS_USB_DRIVER is not set
985# CONFIG_USB_BLUETOOTH_TTY is not set
986# CONFIG_USB_MIDI is not set
987# CONFIG_USB_ACM is not set 1225# CONFIG_USB_ACM is not set
988CONFIG_USB_PRINTER=y 1226# CONFIG_USB_PRINTER is not set
1227
1228#
1229# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
1230#
1231
1232#
1233# may also be needed; see USB_STORAGE Help for more information
1234#
989CONFIG_USB_STORAGE=y 1235CONFIG_USB_STORAGE=y
990# CONFIG_USB_STORAGE_DEBUG is not set 1236# CONFIG_USB_STORAGE_DEBUG is not set
991# CONFIG_USB_STORAGE_DATAFAB is not set 1237# CONFIG_USB_STORAGE_DATAFAB is not set
992# CONFIG_USB_STORAGE_FREECOM is not set 1238# CONFIG_USB_STORAGE_FREECOM is not set
993# CONFIG_USB_STORAGE_ISD200 is not set 1239# CONFIG_USB_STORAGE_ISD200 is not set
994# CONFIG_USB_STORAGE_DPCM is not set 1240# CONFIG_USB_STORAGE_DPCM is not set
995# CONFIG_USB_STORAGE_HP8200e is not set 1241# CONFIG_USB_STORAGE_USBAT is not set
996# CONFIG_USB_STORAGE_SDDR09 is not set 1242# CONFIG_USB_STORAGE_SDDR09 is not set
997# CONFIG_USB_STORAGE_SDDR55 is not set 1243# CONFIG_USB_STORAGE_SDDR55 is not set
998# CONFIG_USB_STORAGE_JUMPSHOT is not set 1244# CONFIG_USB_STORAGE_JUMPSHOT is not set
1245# CONFIG_USB_STORAGE_ALAUDA is not set
1246# CONFIG_USB_LIBUSUAL is not set
999 1247
1000# 1248#
1001# USB Human Interface Devices (HID) 1249# USB Input Devices
1250#
1251# CONFIG_USB_HID is not set
1252
1002# 1253#
1003CONFIG_USB_HID=y 1254# USB HID Boot Protocol drivers
1004CONFIG_USB_HIDINPUT=y 1255#
1005# CONFIG_HID_FF is not set 1256# CONFIG_USB_KBD is not set
1006# CONFIG_USB_HIDDEV is not set 1257# CONFIG_USB_MOUSE is not set
1007# CONFIG_USB_AIPTEK is not set 1258# CONFIG_USB_AIPTEK is not set
1008# CONFIG_USB_WACOM is not set 1259# CONFIG_USB_WACOM is not set
1260# CONFIG_USB_ACECAD is not set
1009# CONFIG_USB_KBTAB is not set 1261# CONFIG_USB_KBTAB is not set
1010# CONFIG_USB_POWERMATE is not set 1262# CONFIG_USB_POWERMATE is not set
1011# CONFIG_USB_MTOUCH is not set 1263# CONFIG_USB_MTOUCH is not set
1012CONFIG_USB_EGALAX=m 1264# CONFIG_USB_ITMTOUCH is not set
1265# CONFIG_USB_EGALAX is not set
1266# CONFIG_USB_YEALINK is not set
1013# CONFIG_USB_XPAD is not set 1267# CONFIG_USB_XPAD is not set
1014# CONFIG_USB_ATI_REMOTE is not set 1268# CONFIG_USB_ATI_REMOTE is not set
1269# CONFIG_USB_ATI_REMOTE2 is not set
1270# CONFIG_USB_KEYSPAN_REMOTE is not set
1271# CONFIG_USB_APPLETOUCH is not set
1015 1272
1016# 1273#
1017# USB Imaging devices 1274# USB Imaging devices
1018# 1275#
1019# CONFIG_USB_MDC800 is not set 1276# CONFIG_USB_MDC800 is not set
1020# CONFIG_USB_MICROTEK is not set 1277# CONFIG_USB_MICROTEK is not set
1021# CONFIG_USB_HPUSBSCSI is not set
1022 1278
1023# 1279#
1024# USB Multimedia devices 1280# USB Multimedia devices
1025# 1281#
1026# CONFIG_USB_DABUSB is not set 1282# CONFIG_USB_DABUSB is not set
1283# CONFIG_USB_VICAM is not set
1284# CONFIG_USB_DSBR is not set
1285# CONFIG_USB_ET61X251 is not set
1286# CONFIG_USB_IBMCAM is not set
1287# CONFIG_USB_KONICAWC is not set
1288# CONFIG_USB_OV511 is not set
1289# CONFIG_USB_SE401 is not set
1290# CONFIG_USB_SN9C102 is not set
1291# CONFIG_USB_STV680 is not set
1292# CONFIG_USB_PWC is not set
1027 1293
1028# 1294#
1029# Video4Linux support is needed for USB Multimedia device support 1295# USB Network Adapters
1030#
1031
1032#
1033# USB Network adaptors
1034# 1296#
1035# CONFIG_USB_CATC is not set 1297# CONFIG_USB_CATC is not set
1036# CONFIG_USB_KAWETH is not set 1298# CONFIG_USB_KAWETH is not set
1037# CONFIG_USB_PEGASUS is not set 1299# CONFIG_USB_PEGASUS is not set
1038# CONFIG_USB_RTL8150 is not set 1300# CONFIG_USB_RTL8150 is not set
1039# CONFIG_USB_USBNET is not set 1301# CONFIG_USB_USBNET is not set
1302# CONFIG_USB_MON is not set
1040 1303
1041# 1304#
1042# USB port drivers 1305# USB port drivers
@@ -1053,56 +1316,85 @@ CONFIG_USB_EGALAX=m
1053# 1316#
1054# CONFIG_USB_EMI62 is not set 1317# CONFIG_USB_EMI62 is not set
1055# CONFIG_USB_EMI26 is not set 1318# CONFIG_USB_EMI26 is not set
1056# CONFIG_USB_TIGL is not set
1057# CONFIG_USB_AUERSWALD is not set 1319# CONFIG_USB_AUERSWALD is not set
1058# CONFIG_USB_RIO500 is not set 1320# CONFIG_USB_RIO500 is not set
1059# CONFIG_USB_LEGOTOWER is not set 1321# CONFIG_USB_LEGOTOWER is not set
1060# CONFIG_USB_LCD is not set 1322# CONFIG_USB_LCD is not set
1061# CONFIG_USB_LED is not set 1323# CONFIG_USB_LED is not set
1062CONFIG_USB_CYTHERM=m 1324# CONFIG_USB_CYTHERM is not set
1063CONFIG_USB_PHIDGETSERVO=m 1325# CONFIG_USB_PHIDGETKIT is not set
1326# CONFIG_USB_PHIDGETSERVO is not set
1327# CONFIG_USB_IDMOUSE is not set
1328# CONFIG_USB_SISUSBVGA is not set
1329# CONFIG_USB_LD is not set
1064# CONFIG_USB_TEST is not set 1330# CONFIG_USB_TEST is not set
1065 1331
1066# 1332#
1333# USB DSL modem support
1334#
1335
1336#
1067# USB Gadget Support 1337# USB Gadget Support
1068# 1338#
1069# CONFIG_USB_GADGET is not set 1339# CONFIG_USB_GADGET is not set
1070 1340
1071# 1341#
1342# MMC/SD Card support
1343#
1344# CONFIG_MMC is not set
1345
1346#
1347# InfiniBand support
1348#
1349# CONFIG_INFINIBAND is not set
1350
1351#
1352# SN Devices
1353#
1354
1355#
1356# EDAC - error detection and reporting (RAS)
1357#
1358# CONFIG_EDAC is not set
1359
1360#
1072# File systems 1361# File systems
1073# 1362#
1074CONFIG_EXT2_FS=y 1363CONFIG_EXT2_FS=y
1075# CONFIG_EXT2_FS_XATTR is not set 1364# CONFIG_EXT2_FS_XATTR is not set
1076CONFIG_EXT3_FS=y 1365# CONFIG_EXT2_FS_XIP is not set
1077CONFIG_EXT3_FS_XATTR=y 1366# CONFIG_EXT3_FS is not set
1078# CONFIG_EXT3_FS_POSIX_ACL is not set
1079# CONFIG_EXT3_FS_SECURITY is not set
1080CONFIG_JBD=y
1081# CONFIG_JBD_DEBUG is not set
1082CONFIG_FS_MBCACHE=y
1083# CONFIG_REISERFS_FS is not set 1367# CONFIG_REISERFS_FS is not set
1084# CONFIG_JFS_FS is not set 1368# CONFIG_JFS_FS is not set
1369# CONFIG_FS_POSIX_ACL is not set
1085# CONFIG_XFS_FS is not set 1370# CONFIG_XFS_FS is not set
1371# CONFIG_OCFS2_FS is not set
1086# CONFIG_MINIX_FS is not set 1372# CONFIG_MINIX_FS is not set
1087# CONFIG_ROMFS_FS is not set 1373# CONFIG_ROMFS_FS is not set
1374# CONFIG_INOTIFY is not set
1088# CONFIG_QUOTA is not set 1375# CONFIG_QUOTA is not set
1376CONFIG_DNOTIFY=y
1089# CONFIG_AUTOFS_FS is not set 1377# CONFIG_AUTOFS_FS is not set
1090CONFIG_AUTOFS4_FS=y 1378# CONFIG_AUTOFS4_FS is not set
1379# CONFIG_FUSE_FS is not set
1091 1380
1092# 1381#
1093# CD-ROM/DVD Filesystems 1382# CD-ROM/DVD Filesystems
1094# 1383#
1095CONFIG_ISO9660_FS=y 1384CONFIG_ISO9660_FS=y
1096CONFIG_JOLIET=y 1385CONFIG_JOLIET=y
1097# CONFIG_ZISOFS is not set 1386CONFIG_ZISOFS=y
1098CONFIG_UDF_FS=y 1387CONFIG_ZISOFS_FS=y
1388# CONFIG_UDF_FS is not set
1099 1389
1100# 1390#
1101# DOS/FAT/NT Filesystems 1391# DOS/FAT/NT Filesystems
1102# 1392#
1103CONFIG_FAT_FS=y 1393CONFIG_FAT_FS=y
1104CONFIG_MSDOS_FS=y 1394# CONFIG_MSDOS_FS is not set
1105CONFIG_VFAT_FS=y 1395CONFIG_VFAT_FS=y
1396CONFIG_FAT_DEFAULT_CODEPAGE=850
1397CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
1106# CONFIG_NTFS_FS is not set 1398# CONFIG_NTFS_FS is not set
1107 1399
1108# 1400#
@@ -1111,12 +1403,12 @@ CONFIG_VFAT_FS=y
1111CONFIG_PROC_FS=y 1403CONFIG_PROC_FS=y
1112CONFIG_PROC_KCORE=y 1404CONFIG_PROC_KCORE=y
1113CONFIG_SYSFS=y 1405CONFIG_SYSFS=y
1114# CONFIG_DEVFS_FS is not set
1115# CONFIG_DEVPTS_FS_XATTR is not set
1116CONFIG_TMPFS=y 1406CONFIG_TMPFS=y
1117# CONFIG_HUGETLBFS is not set 1407# CONFIG_HUGETLBFS is not set
1118# CONFIG_HUGETLB_PAGE is not set 1408# CONFIG_HUGETLB_PAGE is not set
1119CONFIG_RAMFS=y 1409CONFIG_RAMFS=y
1410# CONFIG_RELAYFS_FS is not set
1411# CONFIG_CONFIGFS_FS is not set
1120 1412
1121# 1413#
1122# Miscellaneous filesystems 1414# Miscellaneous filesystems
@@ -1138,38 +1430,48 @@ CONFIG_RAMFS=y
1138# 1430#
1139# Network File Systems 1431# Network File Systems
1140# 1432#
1141CONFIG_NFS_FS=y 1433# CONFIG_NFS_FS is not set
1142# CONFIG_NFS_V3 is not set 1434# CONFIG_NFSD is not set
1143# CONFIG_NFS_V4 is not set
1144# CONFIG_NFS_DIRECTIO is not set
1145CONFIG_NFSD=y
1146# CONFIG_NFSD_V3 is not set
1147CONFIG_NFSD_TCP=y
1148CONFIG_LOCKD=y
1149CONFIG_EXPORTFS=y
1150CONFIG_SUNRPC=y
1151# CONFIG_RPCSEC_GSS_KRB5 is not set
1152# CONFIG_SMB_FS is not set 1435# CONFIG_SMB_FS is not set
1153# CONFIG_CIFS is not set 1436CONFIG_CIFS=y
1437# CONFIG_CIFS_STATS is not set
1438# CONFIG_CIFS_XATTR is not set
1439# CONFIG_CIFS_EXPERIMENTAL is not set
1154# CONFIG_NCP_FS is not set 1440# CONFIG_NCP_FS is not set
1155# CONFIG_CODA_FS is not set 1441# CONFIG_CODA_FS is not set
1156# CONFIG_AFS_FS is not set 1442# CONFIG_AFS_FS is not set
1443# CONFIG_9P_FS is not set
1157 1444
1158# 1445#
1159# Partition Types 1446# Partition Types
1160# 1447#
1161# CONFIG_PARTITION_ADVANCED is not set 1448CONFIG_PARTITION_ADVANCED=y
1449# CONFIG_ACORN_PARTITION is not set
1450# CONFIG_OSF_PARTITION is not set
1451# CONFIG_AMIGA_PARTITION is not set
1452# CONFIG_ATARI_PARTITION is not set
1453# CONFIG_MAC_PARTITION is not set
1162CONFIG_MSDOS_PARTITION=y 1454CONFIG_MSDOS_PARTITION=y
1455# CONFIG_BSD_DISKLABEL is not set
1456# CONFIG_MINIX_SUBPARTITION is not set
1457# CONFIG_SOLARIS_X86_PARTITION is not set
1458# CONFIG_UNIXWARE_DISKLABEL is not set
1459# CONFIG_LDM_PARTITION is not set
1460# CONFIG_SGI_PARTITION is not set
1461# CONFIG_ULTRIX_PARTITION is not set
1462# CONFIG_SUN_PARTITION is not set
1463# CONFIG_KARMA_PARTITION is not set
1464# CONFIG_EFI_PARTITION is not set
1163 1465
1164# 1466#
1165# Native Language Support 1467# Native Language Support
1166# 1468#
1167CONFIG_NLS=y 1469CONFIG_NLS=y
1168CONFIG_NLS_DEFAULT="iso8859-1" 1470CONFIG_NLS_DEFAULT="iso8859-15"
1169CONFIG_NLS_CODEPAGE_437=y 1471# CONFIG_NLS_CODEPAGE_437 is not set
1170# CONFIG_NLS_CODEPAGE_737 is not set 1472# CONFIG_NLS_CODEPAGE_737 is not set
1171# CONFIG_NLS_CODEPAGE_775 is not set 1473# CONFIG_NLS_CODEPAGE_775 is not set
1172# CONFIG_NLS_CODEPAGE_850 is not set 1474CONFIG_NLS_CODEPAGE_850=y
1173# CONFIG_NLS_CODEPAGE_852 is not set 1475# CONFIG_NLS_CODEPAGE_852 is not set
1174# CONFIG_NLS_CODEPAGE_855 is not set 1476# CONFIG_NLS_CODEPAGE_855 is not set
1175# CONFIG_NLS_CODEPAGE_857 is not set 1477# CONFIG_NLS_CODEPAGE_857 is not set
@@ -1189,6 +1491,7 @@ CONFIG_NLS_CODEPAGE_437=y
1189# CONFIG_NLS_ISO8859_8 is not set 1491# CONFIG_NLS_ISO8859_8 is not set
1190# CONFIG_NLS_CODEPAGE_1250 is not set 1492# CONFIG_NLS_CODEPAGE_1250 is not set
1191# CONFIG_NLS_CODEPAGE_1251 is not set 1493# CONFIG_NLS_CODEPAGE_1251 is not set
1494# CONFIG_NLS_ASCII is not set
1192CONFIG_NLS_ISO8859_1=y 1495CONFIG_NLS_ISO8859_1=y
1193# CONFIG_NLS_ISO8859_2 is not set 1496# CONFIG_NLS_ISO8859_2 is not set
1194# CONFIG_NLS_ISO8859_3 is not set 1497# CONFIG_NLS_ISO8859_3 is not set
@@ -1199,31 +1502,33 @@ CONFIG_NLS_ISO8859_1=y
1199# CONFIG_NLS_ISO8859_9 is not set 1502# CONFIG_NLS_ISO8859_9 is not set
1200# CONFIG_NLS_ISO8859_13 is not set 1503# CONFIG_NLS_ISO8859_13 is not set
1201# CONFIG_NLS_ISO8859_14 is not set 1504# CONFIG_NLS_ISO8859_14 is not set
1202# CONFIG_NLS_ISO8859_15 is not set 1505CONFIG_NLS_ISO8859_15=y
1203# CONFIG_NLS_KOI8_R is not set 1506# CONFIG_NLS_KOI8_R is not set
1204# CONFIG_NLS_KOI8_U is not set 1507# CONFIG_NLS_KOI8_U is not set
1205# CONFIG_NLS_UTF8 is not set 1508CONFIG_NLS_UTF8=y
1206 1509
1207# 1510#
1208# Profiling support 1511# Instrumentation Support
1209# 1512#
1210CONFIG_PROFILING=y 1513# CONFIG_PROFILING is not set
1211CONFIG_OPROFILE=y 1514# CONFIG_KPROBES is not set
1212 1515
1213# 1516#
1214# Kernel hacking 1517# Kernel hacking
1215# 1518#
1519# CONFIG_PRINTK_TIME is not set
1520CONFIG_MAGIC_SYSRQ=y
1216# CONFIG_DEBUG_KERNEL is not set 1521# CONFIG_DEBUG_KERNEL is not set
1522CONFIG_LOG_BUF_SHIFT=14
1523CONFIG_DEBUG_BUGVERBOSE=y
1217CONFIG_EARLY_PRINTK=y 1524CONFIG_EARLY_PRINTK=y
1218CONFIG_DEBUG_SPINLOCK_SLEEP=y
1219# CONFIG_FRAME_POINTER is not set
1220CONFIG_4KSTACKS=y
1221CONFIG_X86_FIND_SMP_CONFIG=y 1525CONFIG_X86_FIND_SMP_CONFIG=y
1222CONFIG_X86_MPPARSE=y 1526CONFIG_X86_MPPARSE=y
1223 1527
1224# 1528#
1225# Security options 1529# Security options
1226# 1530#
1531# CONFIG_KEYS is not set
1227# CONFIG_SECURITY is not set 1532# CONFIG_SECURITY is not set
1228 1533
1229# 1534#
@@ -1232,13 +1537,18 @@ CONFIG_X86_MPPARSE=y
1232# CONFIG_CRYPTO is not set 1537# CONFIG_CRYPTO is not set
1233 1538
1234# 1539#
1540# Hardware crypto devices
1541#
1542
1543#
1235# Library routines 1544# Library routines
1236# 1545#
1546# CONFIG_CRC_CCITT is not set
1547# CONFIG_CRC16 is not set
1237CONFIG_CRC32=y 1548CONFIG_CRC32=y
1238CONFIG_LIBCRC32C=m 1549# CONFIG_LIBCRC32C is not set
1239CONFIG_X86_SMP=y 1550CONFIG_ZLIB_INFLATE=y
1240CONFIG_X86_HT=y 1551CONFIG_GENERIC_HARDIRQS=y
1552CONFIG_GENERIC_IRQ_PROBE=y
1241CONFIG_X86_BIOS_REBOOT=y 1553CONFIG_X86_BIOS_REBOOT=y
1242CONFIG_X86_TRAMPOLINE=y 1554CONFIG_KTIME_SCALAR=y
1243CONFIG_X86_STD_RESOURCES=y
1244CONFIG_PC=y
diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
index a85ea9d37f05..ff7ae6b664e8 100644
--- a/arch/ia64/Kconfig
+++ b/arch/ia64/Kconfig
@@ -271,6 +271,25 @@ config SCHED_SMT
271 Intel IA64 chips with MultiThreading at a cost of slightly increased 271 Intel IA64 chips with MultiThreading at a cost of slightly increased
272 overhead in some places. If unsure say N here. 272 overhead in some places. If unsure say N here.
273 273
274config PERMIT_BSP_REMOVE
275 bool "Support removal of Bootstrap Processor"
276 depends on HOTPLUG_CPU
277 default n
278 ---help---
279 Say Y here if your platform SAL will support removal of BSP with HOTPLUG_CPU
280 support.
281
282config FORCE_CPEI_RETARGET
283 bool "Force assumption that CPEI can be re-targetted"
284 depends on PERMIT_BSP_REMOVE
285 default n
286 ---help---
287 Say Y if you need to force the assumption that CPEI can be re-targetted to
288 any cpu in the system. This hint is available via ACPI 3.0 specifications.
289 Tiger4 systems are capable of re-directing CPEI to any CPU other than BSP.
290 This option it useful to enable this feature on older BIOS's as well.
291 You can also enable this by using boot command line option force_cpei=1.
292
274config PREEMPT 293config PREEMPT
275 bool "Preemptible Kernel" 294 bool "Preemptible Kernel"
276 help 295 help
diff --git a/arch/ia64/configs/tiger_defconfig b/arch/ia64/configs/tiger_defconfig
index 125568118b84..766bf4955432 100644
--- a/arch/ia64/configs/tiger_defconfig
+++ b/arch/ia64/configs/tiger_defconfig
@@ -116,6 +116,8 @@ CONFIG_FORCE_MAX_ZONEORDER=17
116CONFIG_SMP=y 116CONFIG_SMP=y
117CONFIG_NR_CPUS=4 117CONFIG_NR_CPUS=4
118CONFIG_HOTPLUG_CPU=y 118CONFIG_HOTPLUG_CPU=y
119CONFIG_PERMIT_BSP_REMOVE=y
120CONFIG_FORCE_CPEI_RETARGET=y
119# CONFIG_SCHED_SMT is not set 121# CONFIG_SCHED_SMT is not set
120# CONFIG_PREEMPT is not set 122# CONFIG_PREEMPT is not set
121CONFIG_SELECT_MEMORY_MODEL=y 123CONFIG_SELECT_MEMORY_MODEL=y
diff --git a/arch/ia64/kernel/acpi.c b/arch/ia64/kernel/acpi.c
index ecd44bdc8394..4722ec51c70c 100644
--- a/arch/ia64/kernel/acpi.c
+++ b/arch/ia64/kernel/acpi.c
@@ -284,19 +284,24 @@ acpi_parse_plat_int_src(acpi_table_entry_header * header,
284 return 0; 284 return 0;
285} 285}
286 286
287#ifdef CONFIG_HOTPLUG_CPU
287unsigned int can_cpei_retarget(void) 288unsigned int can_cpei_retarget(void)
288{ 289{
289 extern int cpe_vector; 290 extern int cpe_vector;
291 extern unsigned int force_cpei_retarget;
290 292
291 /* 293 /*
292 * Only if CPEI is supported and the override flag 294 * Only if CPEI is supported and the override flag
293 * is present, otherwise return that its re-targettable 295 * is present, otherwise return that its re-targettable
294 * if we are in polling mode. 296 * if we are in polling mode.
295 */ 297 */
296 if (cpe_vector > 0 && !acpi_cpei_override) 298 if (cpe_vector > 0) {
297 return 0; 299 if (acpi_cpei_override || force_cpei_retarget)
298 else 300 return 1;
299 return 1; 301 else
302 return 0;
303 }
304 return 1;
300} 305}
301 306
302unsigned int is_cpu_cpei_target(unsigned int cpu) 307unsigned int is_cpu_cpei_target(unsigned int cpu)
@@ -315,6 +320,7 @@ void set_cpei_target_cpu(unsigned int cpu)
315{ 320{
316 acpi_cpei_phys_cpuid = cpu_physical_id(cpu); 321 acpi_cpei_phys_cpuid = cpu_physical_id(cpu);
317} 322}
323#endif
318 324
319unsigned int get_cpei_target_cpu(void) 325unsigned int get_cpei_target_cpu(void)
320{ 326{
diff --git a/arch/ia64/kernel/entry.S b/arch/ia64/kernel/entry.S
index 930fdfca6ddb..0e3eda99e549 100644
--- a/arch/ia64/kernel/entry.S
+++ b/arch/ia64/kernel/entry.S
@@ -1102,9 +1102,6 @@ skip_rbs_switch:
1102 st8 [r2]=r8 1102 st8 [r2]=r8
1103 st8 [r3]=r10 1103 st8 [r3]=r10
1104.work_pending: 1104.work_pending:
1105 tbit.nz p6,p0=r31,TIF_SIGDELAYED // signal delayed from MCA/INIT/NMI/PMI context?
1106(p6) br.cond.sptk.few .sigdelayed
1107 ;;
1108 tbit.z p6,p0=r31,TIF_NEED_RESCHED // current_thread_info()->need_resched==0? 1105 tbit.z p6,p0=r31,TIF_NEED_RESCHED // current_thread_info()->need_resched==0?
1109(p6) br.cond.sptk.few .notify 1106(p6) br.cond.sptk.few .notify
1110#ifdef CONFIG_PREEMPT 1107#ifdef CONFIG_PREEMPT
@@ -1131,17 +1128,6 @@ skip_rbs_switch:
1131(pLvSys)br.cond.sptk.few .work_pending_syscall_end 1128(pLvSys)br.cond.sptk.few .work_pending_syscall_end
1132 br.cond.sptk.many .work_processed_kernel // don't re-check 1129 br.cond.sptk.many .work_processed_kernel // don't re-check
1133 1130
1134// There is a delayed signal that was detected in MCA/INIT/NMI/PMI context where
1135// it could not be delivered. Deliver it now. The signal might be for us and
1136// may set TIF_SIGPENDING, so redrive ia64_leave_* after processing the delayed
1137// signal.
1138
1139.sigdelayed:
1140 br.call.sptk.many rp=do_sigdelayed
1141 cmp.eq p6,p0=r0,r0 // p6 <- 1, always re-check
1142(pLvSys)br.cond.sptk.few .work_pending_syscall_end
1143 br.cond.sptk.many .work_processed_kernel // re-check
1144
1145.work_pending_syscall_end: 1131.work_pending_syscall_end:
1146 adds r2=PT(R8)+16,r12 1132 adds r2=PT(R8)+16,r12
1147 adds r3=PT(R10)+16,r12 1133 adds r3=PT(R10)+16,r12
diff --git a/arch/ia64/kernel/iosapic.c b/arch/ia64/kernel/iosapic.c
index 574084f343fa..8832c553230a 100644
--- a/arch/ia64/kernel/iosapic.c
+++ b/arch/ia64/kernel/iosapic.c
@@ -631,6 +631,7 @@ get_target_cpu (unsigned int gsi, int vector)
631{ 631{
632#ifdef CONFIG_SMP 632#ifdef CONFIG_SMP
633 static int cpu = -1; 633 static int cpu = -1;
634 extern int cpe_vector;
634 635
635 /* 636 /*
636 * In case of vector shared by multiple RTEs, all RTEs that 637 * In case of vector shared by multiple RTEs, all RTEs that
@@ -653,6 +654,11 @@ get_target_cpu (unsigned int gsi, int vector)
653 if (!cpu_online(smp_processor_id())) 654 if (!cpu_online(smp_processor_id()))
654 return cpu_physical_id(smp_processor_id()); 655 return cpu_physical_id(smp_processor_id());
655 656
657#ifdef CONFIG_ACPI
658 if (cpe_vector > 0 && vector == IA64_CPEP_VECTOR)
659 return get_cpei_target_cpu();
660#endif
661
656#ifdef CONFIG_NUMA 662#ifdef CONFIG_NUMA
657 { 663 {
658 int num_cpus, cpu_index, iosapic_index, numa_cpu, i = 0; 664 int num_cpus, cpu_index, iosapic_index, numa_cpu, i = 0;
diff --git a/arch/ia64/kernel/irq.c b/arch/ia64/kernel/irq.c
index d33244c32759..5ce908ef9c95 100644
--- a/arch/ia64/kernel/irq.c
+++ b/arch/ia64/kernel/irq.c
@@ -163,8 +163,19 @@ void fixup_irqs(void)
163{ 163{
164 unsigned int irq; 164 unsigned int irq;
165 extern void ia64_process_pending_intr(void); 165 extern void ia64_process_pending_intr(void);
166 extern void ia64_disable_timer(void);
167 extern volatile int time_keeper_id;
168
169 ia64_disable_timer();
170
171 /*
172 * Find a new timesync master
173 */
174 if (smp_processor_id() == time_keeper_id) {
175 time_keeper_id = first_cpu(cpu_online_map);
176 printk ("CPU %d is now promoted to time-keeper master\n", time_keeper_id);
177 }
166 178
167 ia64_set_itv(1<<16);
168 /* 179 /*
169 * Phase 1: Locate irq's bound to this cpu and 180 * Phase 1: Locate irq's bound to this cpu and
170 * relocate them for cpu removal. 181 * relocate them for cpu removal.
diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
index ee7eec9ee576..b57e723f194c 100644
--- a/arch/ia64/kernel/mca.c
+++ b/arch/ia64/kernel/mca.c
@@ -281,14 +281,10 @@ ia64_mca_log_sal_error_record(int sal_info_type)
281 ia64_sal_clear_state_info(sal_info_type); 281 ia64_sal_clear_state_info(sal_info_type);
282} 282}
283 283
284/*
285 * platform dependent error handling
286 */
287#ifndef PLATFORM_MCA_HANDLERS
288
289#ifdef CONFIG_ACPI 284#ifdef CONFIG_ACPI
290 285
291int cpe_vector = -1; 286int cpe_vector = -1;
287int ia64_cpe_irq = -1;
292 288
293static irqreturn_t 289static irqreturn_t
294ia64_mca_cpe_int_handler (int cpe_irq, void *arg, struct pt_regs *ptregs) 290ia64_mca_cpe_int_handler (int cpe_irq, void *arg, struct pt_regs *ptregs)
@@ -377,8 +373,6 @@ ia64_mca_register_cpev (int cpev)
377} 373}
378#endif /* CONFIG_ACPI */ 374#endif /* CONFIG_ACPI */
379 375
380#endif /* PLATFORM_MCA_HANDLERS */
381
382/* 376/*
383 * ia64_mca_cmc_vector_setup 377 * ia64_mca_cmc_vector_setup
384 * 378 *
@@ -630,6 +624,32 @@ copy_reg(const u64 *fr, u64 fnat, u64 *tr, u64 *tnat)
630 *tnat |= (nat << tslot); 624 *tnat |= (nat << tslot);
631} 625}
632 626
627/* Change the comm field on the MCA/INT task to include the pid that
628 * was interrupted, it makes for easier debugging. If that pid was 0
629 * (swapper or nested MCA/INIT) then use the start of the previous comm
630 * field suffixed with its cpu.
631 */
632
633static void
634ia64_mca_modify_comm(const task_t *previous_current)
635{
636 char *p, comm[sizeof(current->comm)];
637 if (previous_current->pid)
638 snprintf(comm, sizeof(comm), "%s %d",
639 current->comm, previous_current->pid);
640 else {
641 int l;
642 if ((p = strchr(previous_current->comm, ' ')))
643 l = p - previous_current->comm;
644 else
645 l = strlen(previous_current->comm);
646 snprintf(comm, sizeof(comm), "%s %*s %d",
647 current->comm, l, previous_current->comm,
648 task_thread_info(previous_current)->cpu);
649 }
650 memcpy(current->comm, comm, sizeof(current->comm));
651}
652
633/* On entry to this routine, we are running on the per cpu stack, see 653/* On entry to this routine, we are running on the per cpu stack, see
634 * mca_asm.h. The original stack has not been touched by this event. Some of 654 * mca_asm.h. The original stack has not been touched by this event. Some of
635 * the original stack's registers will be in the RBS on this stack. This stack 655 * the original stack's registers will be in the RBS on this stack. This stack
@@ -648,7 +668,7 @@ ia64_mca_modify_original_stack(struct pt_regs *regs,
648 struct ia64_sal_os_state *sos, 668 struct ia64_sal_os_state *sos,
649 const char *type) 669 const char *type)
650{ 670{
651 char *p, comm[sizeof(current->comm)]; 671 char *p;
652 ia64_va va; 672 ia64_va va;
653 extern char ia64_leave_kernel[]; /* Need asm address, not function descriptor */ 673 extern char ia64_leave_kernel[]; /* Need asm address, not function descriptor */
654 const pal_min_state_area_t *ms = sos->pal_min_state; 674 const pal_min_state_area_t *ms = sos->pal_min_state;
@@ -721,6 +741,10 @@ ia64_mca_modify_original_stack(struct pt_regs *regs,
721 /* Verify the previous stack state before we change it */ 741 /* Verify the previous stack state before we change it */
722 if (user_mode(regs)) { 742 if (user_mode(regs)) {
723 msg = "occurred in user space"; 743 msg = "occurred in user space";
744 /* previous_current is guaranteed to be valid when the task was
745 * in user space, so ...
746 */
747 ia64_mca_modify_comm(previous_current);
724 goto no_mod; 748 goto no_mod;
725 } 749 }
726 if (r13 != sos->prev_IA64_KR_CURRENT) { 750 if (r13 != sos->prev_IA64_KR_CURRENT) {
@@ -750,25 +774,7 @@ ia64_mca_modify_original_stack(struct pt_regs *regs,
750 goto no_mod; 774 goto no_mod;
751 } 775 }
752 776
753 /* Change the comm field on the MCA/INT task to include the pid that 777 ia64_mca_modify_comm(previous_current);
754 * was interrupted, it makes for easier debugging. If that pid was 0
755 * (swapper or nested MCA/INIT) then use the start of the previous comm
756 * field suffixed with its cpu.
757 */
758 if (previous_current->pid)
759 snprintf(comm, sizeof(comm), "%s %d",
760 current->comm, previous_current->pid);
761 else {
762 int l;
763 if ((p = strchr(previous_current->comm, ' ')))
764 l = p - previous_current->comm;
765 else
766 l = strlen(previous_current->comm);
767 snprintf(comm, sizeof(comm), "%s %*s %d",
768 current->comm, l, previous_current->comm,
769 task_thread_info(previous_current)->cpu);
770 }
771 memcpy(current->comm, comm, sizeof(current->comm));
772 778
773 /* Make the original task look blocked. First stack a struct pt_regs, 779 /* Make the original task look blocked. First stack a struct pt_regs,
774 * describing the state at the time of interrupt. mca_asm.S built a 780 * describing the state at the time of interrupt. mca_asm.S built a
@@ -908,7 +914,7 @@ no_mod:
908static void 914static void
909ia64_wait_for_slaves(int monarch) 915ia64_wait_for_slaves(int monarch)
910{ 916{
911 int c, wait = 0; 917 int c, wait = 0, missing = 0;
912 for_each_online_cpu(c) { 918 for_each_online_cpu(c) {
913 if (c == monarch) 919 if (c == monarch)
914 continue; 920 continue;
@@ -919,15 +925,32 @@ ia64_wait_for_slaves(int monarch)
919 } 925 }
920 } 926 }
921 if (!wait) 927 if (!wait)
922 return; 928 goto all_in;
923 for_each_online_cpu(c) { 929 for_each_online_cpu(c) {
924 if (c == monarch) 930 if (c == monarch)
925 continue; 931 continue;
926 if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) { 932 if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) {
927 udelay(5*1000000); /* wait 5 seconds for slaves (arbitrary) */ 933 udelay(5*1000000); /* wait 5 seconds for slaves (arbitrary) */
934 if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE)
935 missing = 1;
928 break; 936 break;
929 } 937 }
930 } 938 }
939 if (!missing)
940 goto all_in;
941 printk(KERN_INFO "OS MCA slave did not rendezvous on cpu");
942 for_each_online_cpu(c) {
943 if (c == monarch)
944 continue;
945 if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE)
946 printk(" %d", c);
947 }
948 printk("\n");
949 return;
950
951all_in:
952 printk(KERN_INFO "All OS MCA slaves have reached rendezvous\n");
953 return;
931} 954}
932 955
933/* 956/*
@@ -953,6 +976,10 @@ ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw,
953 task_t *previous_current; 976 task_t *previous_current;
954 977
955 oops_in_progress = 1; /* FIXME: make printk NMI/MCA/INIT safe */ 978 oops_in_progress = 1; /* FIXME: make printk NMI/MCA/INIT safe */
979 console_loglevel = 15; /* make sure printks make it to console */
980 printk(KERN_INFO "Entered OS MCA handler. PSP=%lx cpu=%d monarch=%ld\n",
981 sos->proc_state_param, cpu, sos->monarch);
982
956 previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA"); 983 previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA");
957 monarch_cpu = cpu; 984 monarch_cpu = cpu;
958 if (notify_die(DIE_MCA_MONARCH_ENTER, "MCA", regs, 0, 0, 0) 985 if (notify_die(DIE_MCA_MONARCH_ENTER, "MCA", regs, 0, 0, 0)
@@ -1444,11 +1471,13 @@ void __devinit
1444ia64_mca_cpu_init(void *cpu_data) 1471ia64_mca_cpu_init(void *cpu_data)
1445{ 1472{
1446 void *pal_vaddr; 1473 void *pal_vaddr;
1474 static int first_time = 1;
1447 1475
1448 if (smp_processor_id() == 0) { 1476 if (first_time) {
1449 void *mca_data; 1477 void *mca_data;
1450 int cpu; 1478 int cpu;
1451 1479
1480 first_time = 0;
1452 mca_data = alloc_bootmem(sizeof(struct ia64_mca_cpu) 1481 mca_data = alloc_bootmem(sizeof(struct ia64_mca_cpu)
1453 * NR_CPUS + KERNEL_STACK_SIZE); 1482 * NR_CPUS + KERNEL_STACK_SIZE);
1454 mca_data = (void *)(((unsigned long)mca_data + 1483 mca_data = (void *)(((unsigned long)mca_data +
@@ -1704,6 +1733,7 @@ ia64_mca_late_init(void)
1704 desc = irq_descp(irq); 1733 desc = irq_descp(irq);
1705 desc->status |= IRQ_PER_CPU; 1734 desc->status |= IRQ_PER_CPU;
1706 setup_irq(irq, &mca_cpe_irqaction); 1735 setup_irq(irq, &mca_cpe_irqaction);
1736 ia64_cpe_irq = irq;
1707 } 1737 }
1708 ia64_mca_register_cpev(cpe_vector); 1738 ia64_mca_register_cpev(cpe_vector);
1709 IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n", __FUNCTION__); 1739 IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n", __FUNCTION__);
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index 9c5194b385da..077f21216b65 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -6722,6 +6722,7 @@ __initcall(pfm_init);
6722void 6722void
6723pfm_init_percpu (void) 6723pfm_init_percpu (void)
6724{ 6724{
6725 static int first_time=1;
6725 /* 6726 /*
6726 * make sure no measurement is active 6727 * make sure no measurement is active
6727 * (may inherit programmed PMCs from EFI). 6728 * (may inherit programmed PMCs from EFI).
@@ -6734,8 +6735,10 @@ pfm_init_percpu (void)
6734 */ 6735 */
6735 pfm_unfreeze_pmu(); 6736 pfm_unfreeze_pmu();
6736 6737
6737 if (smp_processor_id() == 0) 6738 if (first_time) {
6738 register_percpu_irq(IA64_PERFMON_VECTOR, &perfmon_irqaction); 6739 register_percpu_irq(IA64_PERFMON_VECTOR, &perfmon_irqaction);
6740 first_time=0;
6741 }
6739 6742
6740 ia64_setreg(_IA64_REG_CR_PMV, IA64_PERFMON_VECTOR); 6743 ia64_setreg(_IA64_REG_CR_PMV, IA64_PERFMON_VECTOR);
6741 ia64_srlz_d(); 6744 ia64_srlz_d();
diff --git a/arch/ia64/kernel/signal.c b/arch/ia64/kernel/signal.c
index 463f6bb44d07..1d7903ee2126 100644
--- a/arch/ia64/kernel/signal.c
+++ b/arch/ia64/kernel/signal.c
@@ -588,104 +588,3 @@ ia64_do_signal (sigset_t *oldset, struct sigscratch *scr, long in_syscall)
588 } 588 }
589 return 0; 589 return 0;
590} 590}
591
592/* Set a delayed signal that was detected in MCA/INIT/NMI/PMI context where it
593 * could not be delivered. It is important that the target process is not
594 * allowed to do any more work in user space. Possible cases for the target
595 * process:
596 *
597 * - It is sleeping and will wake up soon. Store the data in the current task,
598 * the signal will be sent when the current task returns from the next
599 * interrupt.
600 *
601 * - It is running in user context. Store the data in the current task, the
602 * signal will be sent when the current task returns from the next interrupt.
603 *
604 * - It is running in kernel context on this or another cpu and will return to
605 * user context. Store the data in the target task, the signal will be sent
606 * to itself when the target task returns to user space.
607 *
608 * - It is running in kernel context on this cpu and will sleep before
609 * returning to user context. Because this is also the current task, the
610 * signal will not get delivered and the task could sleep indefinitely.
611 * Store the data in the idle task for this cpu, the signal will be sent
612 * after the idle task processes its next interrupt.
613 *
614 * To cover all cases, store the data in the target task, the current task and
615 * the idle task on this cpu. Whatever happens, the signal will be delivered
616 * to the target task before it can do any useful user space work. Multiple
617 * deliveries have no unwanted side effects.
618 *
619 * Note: This code is executed in MCA/INIT/NMI/PMI context, with interrupts
620 * disabled. It must not take any locks nor use kernel structures or services
621 * that require locks.
622 */
623
624/* To ensure that we get the right pid, check its start time. To avoid extra
625 * include files in thread_info.h, convert the task start_time to unsigned long,
626 * giving us a cycle time of > 580 years.
627 */
628static inline unsigned long
629start_time_ul(const struct task_struct *t)
630{
631 return t->start_time.tv_sec * NSEC_PER_SEC + t->start_time.tv_nsec;
632}
633
634void
635set_sigdelayed(pid_t pid, int signo, int code, void __user *addr)
636{
637 struct task_struct *t;
638 unsigned long start_time = 0;
639 int i;
640
641 for (i = 1; i <= 3; ++i) {
642 switch (i) {
643 case 1:
644 t = find_task_by_pid(pid);
645 if (t)
646 start_time = start_time_ul(t);
647 break;
648 case 2:
649 t = current;
650 break;
651 default:
652 t = idle_task(smp_processor_id());
653 break;
654 }
655
656 if (!t)
657 return;
658 task_thread_info(t)->sigdelayed.signo = signo;
659 task_thread_info(t)->sigdelayed.code = code;
660 task_thread_info(t)->sigdelayed.addr = addr;
661 task_thread_info(t)->sigdelayed.start_time = start_time;
662 task_thread_info(t)->sigdelayed.pid = pid;
663 wmb();
664 set_tsk_thread_flag(t, TIF_SIGDELAYED);
665 }
666}
667
668/* Called from entry.S when it detects TIF_SIGDELAYED, a delayed signal that
669 * was detected in MCA/INIT/NMI/PMI context where it could not be delivered.
670 */
671
672void
673do_sigdelayed(void)
674{
675 struct siginfo siginfo;
676 pid_t pid;
677 struct task_struct *t;
678
679 clear_thread_flag(TIF_SIGDELAYED);
680 memset(&siginfo, 0, sizeof(siginfo));
681 siginfo.si_signo = current_thread_info()->sigdelayed.signo;
682 siginfo.si_code = current_thread_info()->sigdelayed.code;
683 siginfo.si_addr = current_thread_info()->sigdelayed.addr;
684 pid = current_thread_info()->sigdelayed.pid;
685 t = find_task_by_pid(pid);
686 if (!t)
687 return;
688 if (current_thread_info()->sigdelayed.start_time != start_time_ul(t))
689 return;
690 force_sig_info(siginfo.si_signo, &siginfo, t);
691}
diff --git a/arch/ia64/kernel/smpboot.c b/arch/ia64/kernel/smpboot.c
index b681ef34a86e..c4b633b36dab 100644
--- a/arch/ia64/kernel/smpboot.c
+++ b/arch/ia64/kernel/smpboot.c
@@ -70,6 +70,12 @@
70#endif 70#endif
71 71
72#ifdef CONFIG_HOTPLUG_CPU 72#ifdef CONFIG_HOTPLUG_CPU
73#ifdef CONFIG_PERMIT_BSP_REMOVE
74#define bsp_remove_ok 1
75#else
76#define bsp_remove_ok 0
77#endif
78
73/* 79/*
74 * Store all idle threads, this can be reused instead of creating 80 * Store all idle threads, this can be reused instead of creating
75 * a new thread. Also avoids complicated thread destroy functionality 81 * a new thread. Also avoids complicated thread destroy functionality
@@ -104,7 +110,7 @@ struct sal_to_os_boot *sal_state_for_booting_cpu = &sal_boot_rendez_state[0];
104/* 110/*
105 * ITC synchronization related stuff: 111 * ITC synchronization related stuff:
106 */ 112 */
107#define MASTER 0 113#define MASTER (0)
108#define SLAVE (SMP_CACHE_BYTES/8) 114#define SLAVE (SMP_CACHE_BYTES/8)
109 115
110#define NUM_ROUNDS 64 /* magic value */ 116#define NUM_ROUNDS 64 /* magic value */
@@ -151,6 +157,27 @@ char __initdata no_int_routing;
151 157
152unsigned char smp_int_redirect; /* are INT and IPI redirectable by the chipset? */ 158unsigned char smp_int_redirect; /* are INT and IPI redirectable by the chipset? */
153 159
160#ifdef CONFIG_FORCE_CPEI_RETARGET
161#define CPEI_OVERRIDE_DEFAULT (1)
162#else
163#define CPEI_OVERRIDE_DEFAULT (0)
164#endif
165
166unsigned int force_cpei_retarget = CPEI_OVERRIDE_DEFAULT;
167
168static int __init
169cmdl_force_cpei(char *str)
170{
171 int value=0;
172
173 get_option (&str, &value);
174 force_cpei_retarget = value;
175
176 return 1;
177}
178
179__setup("force_cpei=", cmdl_force_cpei);
180
154static int __init 181static int __init
155nointroute (char *str) 182nointroute (char *str)
156{ 183{
@@ -161,6 +188,27 @@ nointroute (char *str)
161 188
162__setup("nointroute", nointroute); 189__setup("nointroute", nointroute);
163 190
191static void fix_b0_for_bsp(void)
192{
193#ifdef CONFIG_HOTPLUG_CPU
194 int cpuid;
195 static int fix_bsp_b0 = 1;
196
197 cpuid = smp_processor_id();
198
199 /*
200 * Cache the b0 value on the first AP that comes up
201 */
202 if (!(fix_bsp_b0 && cpuid))
203 return;
204
205 sal_boot_rendez_state[0].br[0] = sal_boot_rendez_state[cpuid].br[0];
206 printk ("Fixed BSP b0 value from CPU %d\n", cpuid);
207
208 fix_bsp_b0 = 0;
209#endif
210}
211
164void 212void
165sync_master (void *arg) 213sync_master (void *arg)
166{ 214{
@@ -327,8 +375,9 @@ smp_setup_percpu_timer (void)
327static void __devinit 375static void __devinit
328smp_callin (void) 376smp_callin (void)
329{ 377{
330 int cpuid, phys_id; 378 int cpuid, phys_id, itc_master;
331 extern void ia64_init_itm(void); 379 extern void ia64_init_itm(void);
380 extern volatile int time_keeper_id;
332 381
333#ifdef CONFIG_PERFMON 382#ifdef CONFIG_PERFMON
334 extern void pfm_init_percpu(void); 383 extern void pfm_init_percpu(void);
@@ -336,6 +385,7 @@ smp_callin (void)
336 385
337 cpuid = smp_processor_id(); 386 cpuid = smp_processor_id();
338 phys_id = hard_smp_processor_id(); 387 phys_id = hard_smp_processor_id();
388 itc_master = time_keeper_id;
339 389
340 if (cpu_online(cpuid)) { 390 if (cpu_online(cpuid)) {
341 printk(KERN_ERR "huh, phys CPU#0x%x, CPU#0x%x already present??\n", 391 printk(KERN_ERR "huh, phys CPU#0x%x, CPU#0x%x already present??\n",
@@ -343,6 +393,8 @@ smp_callin (void)
343 BUG(); 393 BUG();
344 } 394 }
345 395
396 fix_b0_for_bsp();
397
346 lock_ipi_calllock(); 398 lock_ipi_calllock();
347 cpu_set(cpuid, cpu_online_map); 399 cpu_set(cpuid, cpu_online_map);
348 unlock_ipi_calllock(); 400 unlock_ipi_calllock();
@@ -365,8 +417,8 @@ smp_callin (void)
365 * calls spin_unlock_bh(), which calls spin_unlock_bh(), which calls 417 * calls spin_unlock_bh(), which calls spin_unlock_bh(), which calls
366 * local_bh_enable(), which bugs out if irqs are not enabled... 418 * local_bh_enable(), which bugs out if irqs are not enabled...
367 */ 419 */
368 Dprintk("Going to syncup ITC with BP.\n"); 420 Dprintk("Going to syncup ITC with ITC Master.\n");
369 ia64_sync_itc(0); 421 ia64_sync_itc(itc_master);
370 } 422 }
371 423
372 /* 424 /*
@@ -635,6 +687,47 @@ remove_siblinginfo(int cpu)
635} 687}
636 688
637extern void fixup_irqs(void); 689extern void fixup_irqs(void);
690
691int migrate_platform_irqs(unsigned int cpu)
692{
693 int new_cpei_cpu;
694 irq_desc_t *desc = NULL;
695 cpumask_t mask;
696 int retval = 0;
697
698 /*
699 * dont permit CPEI target to removed.
700 */
701 if (cpe_vector > 0 && is_cpu_cpei_target(cpu)) {
702 printk ("CPU (%d) is CPEI Target\n", cpu);
703 if (can_cpei_retarget()) {
704 /*
705 * Now re-target the CPEI to a different processor
706 */
707 new_cpei_cpu = any_online_cpu(cpu_online_map);
708 mask = cpumask_of_cpu(new_cpei_cpu);
709 set_cpei_target_cpu(new_cpei_cpu);
710 desc = irq_descp(ia64_cpe_irq);
711 /*
712 * Switch for now, immediatly, we need to do fake intr
713 * as other interrupts, but need to study CPEI behaviour with
714 * polling before making changes.
715 */
716 if (desc) {
717 desc->handler->disable(ia64_cpe_irq);
718 desc->handler->set_affinity(ia64_cpe_irq, mask);
719 desc->handler->enable(ia64_cpe_irq);
720 printk ("Re-targetting CPEI to cpu %d\n", new_cpei_cpu);
721 }
722 }
723 if (!desc) {
724 printk ("Unable to retarget CPEI, offline cpu [%d] failed\n", cpu);
725 retval = -EBUSY;
726 }
727 }
728 return retval;
729}
730
638/* must be called with cpucontrol mutex held */ 731/* must be called with cpucontrol mutex held */
639int __cpu_disable(void) 732int __cpu_disable(void)
640{ 733{
@@ -643,8 +736,17 @@ int __cpu_disable(void)
643 /* 736 /*
644 * dont permit boot processor for now 737 * dont permit boot processor for now
645 */ 738 */
646 if (cpu == 0) 739 if (cpu == 0 && !bsp_remove_ok) {
647 return -EBUSY; 740 printk ("Your platform does not support removal of BSP\n");
741 return (-EBUSY);
742 }
743
744 cpu_clear(cpu, cpu_online_map);
745
746 if (migrate_platform_irqs(cpu)) {
747 cpu_set(cpu, cpu_online_map);
748 return (-EBUSY);
749 }
648 750
649 remove_siblinginfo(cpu); 751 remove_siblinginfo(cpu);
650 cpu_clear(cpu, cpu_online_map); 752 cpu_clear(cpu, cpu_online_map);
diff --git a/arch/ia64/kernel/time.c b/arch/ia64/kernel/time.c
index 307d01e15b2e..ac167436e936 100644
--- a/arch/ia64/kernel/time.c
+++ b/arch/ia64/kernel/time.c
@@ -32,7 +32,7 @@
32 32
33extern unsigned long wall_jiffies; 33extern unsigned long wall_jiffies;
34 34
35#define TIME_KEEPER_ID 0 /* smp_processor_id() of time-keeper */ 35volatile int time_keeper_id = 0; /* smp_processor_id() of time-keeper */
36 36
37#ifdef CONFIG_IA64_DEBUG_IRQ 37#ifdef CONFIG_IA64_DEBUG_IRQ
38 38
@@ -71,7 +71,7 @@ timer_interrupt (int irq, void *dev_id, struct pt_regs *regs)
71 71
72 new_itm += local_cpu_data->itm_delta; 72 new_itm += local_cpu_data->itm_delta;
73 73
74 if (smp_processor_id() == TIME_KEEPER_ID) { 74 if (smp_processor_id() == time_keeper_id) {
75 /* 75 /*
76 * Here we are in the timer irq handler. We have irqs locally 76 * Here we are in the timer irq handler. We have irqs locally
77 * disabled, but we don't know if the timer_bh is running on 77 * disabled, but we don't know if the timer_bh is running on
@@ -236,6 +236,11 @@ static struct irqaction timer_irqaction = {
236 .name = "timer" 236 .name = "timer"
237}; 237};
238 238
239void __devinit ia64_disable_timer(void)
240{
241 ia64_set_itv(1 << 16);
242}
243
239void __init 244void __init
240time_init (void) 245time_init (void)
241{ 246{
diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
index 6e5eea19fa67..3b6fd798c4d6 100644
--- a/arch/ia64/kernel/topology.c
+++ b/arch/ia64/kernel/topology.c
@@ -36,7 +36,7 @@ int arch_register_cpu(int num)
36 parent = &sysfs_nodes[cpu_to_node(num)]; 36 parent = &sysfs_nodes[cpu_to_node(num)];
37#endif /* CONFIG_NUMA */ 37#endif /* CONFIG_NUMA */
38 38
39#ifdef CONFIG_ACPI 39#if defined (CONFIG_ACPI) && defined (CONFIG_HOTPLUG_CPU)
40 /* 40 /*
41 * If CPEI cannot be re-targetted, and this is 41 * If CPEI cannot be re-targetted, and this is
42 * CPEI target, then dont create the control file 42 * CPEI target, then dont create the control file
diff --git a/arch/ia64/mm/contig.c b/arch/ia64/mm/contig.c
index acaaec4e4681..9855ba318094 100644
--- a/arch/ia64/mm/contig.c
+++ b/arch/ia64/mm/contig.c
@@ -181,13 +181,15 @@ per_cpu_init (void)
181{ 181{
182 void *cpu_data; 182 void *cpu_data;
183 int cpu; 183 int cpu;
184 static int first_time=1;
184 185
185 /* 186 /*
186 * get_free_pages() cannot be used before cpu_init() done. BSP 187 * get_free_pages() cannot be used before cpu_init() done. BSP
187 * allocates "NR_CPUS" pages for all CPUs to avoid that AP calls 188 * allocates "NR_CPUS" pages for all CPUs to avoid that AP calls
188 * get_zeroed_page(). 189 * get_zeroed_page().
189 */ 190 */
190 if (smp_processor_id() == 0) { 191 if (first_time) {
192 first_time=0;
191 cpu_data = __alloc_bootmem(PERCPU_PAGE_SIZE * NR_CPUS, 193 cpu_data = __alloc_bootmem(PERCPU_PAGE_SIZE * NR_CPUS,
192 PERCPU_PAGE_SIZE, __pa(MAX_DMA_ADDRESS)); 194 PERCPU_PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
193 for (cpu = 0; cpu < NR_CPUS; cpu++) { 195 for (cpu = 0; cpu < NR_CPUS; cpu++) {
diff --git a/arch/ia64/mm/discontig.c b/arch/ia64/mm/discontig.c
index c87d6d1d5813..573d5cc63e2b 100644
--- a/arch/ia64/mm/discontig.c
+++ b/arch/ia64/mm/discontig.c
@@ -528,12 +528,17 @@ void __init find_memory(void)
528void *per_cpu_init(void) 528void *per_cpu_init(void)
529{ 529{
530 int cpu; 530 int cpu;
531 static int first_time = 1;
532
531 533
532 if (smp_processor_id() != 0) 534 if (smp_processor_id() != 0)
533 return __per_cpu_start + __per_cpu_offset[smp_processor_id()]; 535 return __per_cpu_start + __per_cpu_offset[smp_processor_id()];
534 536
535 for (cpu = 0; cpu < NR_CPUS; cpu++) 537 if (first_time) {
536 per_cpu(local_per_cpu_offset, cpu) = __per_cpu_offset[cpu]; 538 first_time = 0;
539 for (cpu = 0; cpu < NR_CPUS; cpu++)
540 per_cpu(local_per_cpu_offset, cpu) = __per_cpu_offset[cpu];
541 }
537 542
538 return __per_cpu_start + __per_cpu_offset[smp_processor_id()]; 543 return __per_cpu_start + __per_cpu_offset[smp_processor_id()];
539} 544}
diff --git a/arch/ia64/sn/kernel/Makefile b/arch/ia64/sn/kernel/Makefile
index 3e9b4eea7418..ab9c48c88012 100644
--- a/arch/ia64/sn/kernel/Makefile
+++ b/arch/ia64/sn/kernel/Makefile
@@ -10,7 +10,8 @@
10CPPFLAGS += -I$(srctree)/arch/ia64/sn/include 10CPPFLAGS += -I$(srctree)/arch/ia64/sn/include
11 11
12obj-y += setup.o bte.o bte_error.o irq.o mca.o idle.o \ 12obj-y += setup.o bte.o bte_error.o irq.o mca.o idle.o \
13 huberror.o io_init.o iomv.o klconflib.o sn2/ 13 huberror.o io_init.o iomv.o klconflib.o pio_phys.o \
14 sn2/
14obj-$(CONFIG_IA64_GENERIC) += machvec.o 15obj-$(CONFIG_IA64_GENERIC) += machvec.o
15obj-$(CONFIG_SGI_TIOCX) += tiocx.o 16obj-$(CONFIG_SGI_TIOCX) += tiocx.o
16obj-$(CONFIG_IA64_SGI_SN_XP) += xp.o 17obj-$(CONFIG_IA64_SGI_SN_XP) += xp.o
diff --git a/arch/ia64/sn/kernel/pio_phys.S b/arch/ia64/sn/kernel/pio_phys.S
new file mode 100644
index 000000000000..3c7d48d6ecb8
--- /dev/null
+++ b/arch/ia64/sn/kernel/pio_phys.S
@@ -0,0 +1,71 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2000-2005 Silicon Graphics, Inc. All rights reserved.
7 *
8 * This file contains macros used to access MMR registers via
9 * uncached physical addresses.
10 * pio_phys_read_mmr - read an MMR
11 * pio_phys_write_mmr - write an MMR
12 * pio_atomic_phys_write_mmrs - atomically write 1 or 2 MMRs with psr.ic=0
13 * Second MMR will be skipped if address is NULL
14 *
15 * Addresses passed to these routines should be uncached physical addresses
16 * ie., 0x80000....
17 */
18
19
20
21#include <asm/asmmacro.h>
22#include <asm/page.h>
23
24GLOBAL_ENTRY(pio_phys_read_mmr)
25 .prologue
26 .regstk 1,0,0,0
27 .body
28 mov r2=psr
29 rsm psr.i | psr.dt
30 ;;
31 srlz.d
32 ld8.acq r8=[r32]
33 ;;
34 mov psr.l=r2;;
35 srlz.d
36 br.ret.sptk.many rp
37END(pio_phys_read_mmr)
38
39GLOBAL_ENTRY(pio_phys_write_mmr)
40 .prologue
41 .regstk 2,0,0,0
42 .body
43 mov r2=psr
44 rsm psr.i | psr.dt
45 ;;
46 srlz.d
47 st8.rel [r32]=r33
48 ;;
49 mov psr.l=r2;;
50 srlz.d
51 br.ret.sptk.many rp
52END(pio_phys_write_mmr)
53
54GLOBAL_ENTRY(pio_atomic_phys_write_mmrs)
55 .prologue
56 .regstk 4,0,0,0
57 .body
58 mov r2=psr
59 cmp.ne p9,p0=r34,r0;
60 rsm psr.i | psr.dt | psr.ic
61 ;;
62 srlz.d
63 st8.rel [r32]=r33
64(p9) st8.rel [r34]=r35
65 ;;
66 mov psr.l=r2;;
67 srlz.d
68 br.ret.sptk.many rp
69END(pio_atomic_phys_write_mmrs)
70
71
diff --git a/arch/ia64/sn/kernel/setup.c b/arch/ia64/sn/kernel/setup.c
index 5b84836c2171..8b6d5c844708 100644
--- a/arch/ia64/sn/kernel/setup.c
+++ b/arch/ia64/sn/kernel/setup.c
@@ -3,7 +3,7 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (C) 1999,2001-2005 Silicon Graphics, Inc. All rights reserved. 6 * Copyright (C) 1999,2001-2006 Silicon Graphics, Inc. All rights reserved.
7 */ 7 */
8 8
9#include <linux/config.h> 9#include <linux/config.h>
@@ -498,6 +498,7 @@ void __init sn_setup(char **cmdline_p)
498 * for sn. 498 * for sn.
499 */ 499 */
500 pm_power_off = ia64_sn_power_down; 500 pm_power_off = ia64_sn_power_down;
501 current->thread.flags |= IA64_THREAD_MIGRATION;
501} 502}
502 503
503/** 504/**
@@ -660,7 +661,8 @@ void __init sn_cpu_init(void)
660 SH2_PIO_WRITE_STATUS_1, SH2_PIO_WRITE_STATUS_3}; 661 SH2_PIO_WRITE_STATUS_1, SH2_PIO_WRITE_STATUS_3};
661 u64 *pio; 662 u64 *pio;
662 pio = is_shub1() ? pio1 : pio2; 663 pio = is_shub1() ? pio1 : pio2;
663 pda->pio_write_status_addr = (volatile unsigned long *) LOCAL_MMR_ADDR(pio[slice]); 664 pda->pio_write_status_addr =
665 (volatile unsigned long *)GLOBAL_MMR_ADDR(nasid, pio[slice]);
664 pda->pio_write_status_val = is_shub1() ? SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK : 0; 666 pda->pio_write_status_val = is_shub1() ? SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK : 0;
665 } 667 }
666 668
diff --git a/arch/ia64/sn/kernel/sn2/sn2_smp.c b/arch/ia64/sn/kernel/sn2/sn2_smp.c
index b2e1e746b47f..d9d306c79f2d 100644
--- a/arch/ia64/sn/kernel/sn2/sn2_smp.c
+++ b/arch/ia64/sn/kernel/sn2/sn2_smp.c
@@ -93,6 +93,27 @@ static inline unsigned long wait_piowc(void)
93 return (ws & SH_PIO_WRITE_STATUS_WRITE_DEADLOCK_MASK) != 0; 93 return (ws & SH_PIO_WRITE_STATUS_WRITE_DEADLOCK_MASK) != 0;
94} 94}
95 95
96/**
97 * sn_migrate - SN-specific task migration actions
98 * @task: Task being migrated to new CPU
99 *
100 * SN2 PIO writes from separate CPUs are not guaranteed to arrive in order.
101 * Context switching user threads which have memory-mapped MMIO may cause
102 * PIOs to issue from seperate CPUs, thus the PIO writes must be drained
103 * from the previous CPU's Shub before execution resumes on the new CPU.
104 */
105void sn_migrate(struct task_struct *task)
106{
107 pda_t *last_pda = pdacpu(task_thread_info(task)->last_cpu);
108 volatile unsigned long *adr = last_pda->pio_write_status_addr;
109 unsigned long val = last_pda->pio_write_status_val;
110
111 /* Drain PIO writes from old CPU's Shub */
112 while (unlikely((*adr & SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK)
113 != val))
114 cpu_relax();
115}
116
96void sn_tlb_migrate_finish(struct mm_struct *mm) 117void sn_tlb_migrate_finish(struct mm_struct *mm)
97{ 118{
98 /* flush_tlb_mm is inefficient if more than 1 users of mm */ 119 /* flush_tlb_mm is inefficient if more than 1 users of mm */
diff --git a/arch/ia64/sn/kernel/xpc_channel.c b/arch/ia64/sn/kernel/xpc_channel.c
index cdf6856ce089..d0abddd9ffe6 100644
--- a/arch/ia64/sn/kernel/xpc_channel.c
+++ b/arch/ia64/sn/kernel/xpc_channel.c
@@ -21,7 +21,6 @@
21#include <linux/sched.h> 21#include <linux/sched.h>
22#include <linux/cache.h> 22#include <linux/cache.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/slab.h>
25#include <linux/mutex.h> 24#include <linux/mutex.h>
26#include <linux/completion.h> 25#include <linux/completion.h>
27#include <asm/sn/bte.h> 26#include <asm/sn/bte.h>
@@ -30,6 +29,31 @@
30 29
31 30
32/* 31/*
32 * Guarantee that the kzalloc'd memory is cacheline aligned.
33 */
34static void *
35xpc_kzalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
36{
37 /* see if kzalloc will give us cachline aligned memory by default */
38 *base = kzalloc(size, flags);
39 if (*base == NULL) {
40 return NULL;
41 }
42 if ((u64) *base == L1_CACHE_ALIGN((u64) *base)) {
43 return *base;
44 }
45 kfree(*base);
46
47 /* nope, we'll have to do it ourselves */
48 *base = kzalloc(size + L1_CACHE_BYTES, flags);
49 if (*base == NULL) {
50 return NULL;
51 }
52 return (void *) L1_CACHE_ALIGN((u64) *base);
53}
54
55
56/*
33 * Set up the initial values for the XPartition Communication channels. 57 * Set up the initial values for the XPartition Communication channels.
34 */ 58 */
35static void 59static void
@@ -93,20 +117,19 @@ xpc_setup_infrastructure(struct xpc_partition *part)
93 * Allocate all of the channel structures as a contiguous chunk of 117 * Allocate all of the channel structures as a contiguous chunk of
94 * memory. 118 * memory.
95 */ 119 */
96 part->channels = kmalloc(sizeof(struct xpc_channel) * XPC_NCHANNELS, 120 part->channels = kzalloc(sizeof(struct xpc_channel) * XPC_NCHANNELS,
97 GFP_KERNEL); 121 GFP_KERNEL);
98 if (part->channels == NULL) { 122 if (part->channels == NULL) {
99 dev_err(xpc_chan, "can't get memory for channels\n"); 123 dev_err(xpc_chan, "can't get memory for channels\n");
100 return xpcNoMemory; 124 return xpcNoMemory;
101 } 125 }
102 memset(part->channels, 0, sizeof(struct xpc_channel) * XPC_NCHANNELS);
103 126
104 part->nchannels = XPC_NCHANNELS; 127 part->nchannels = XPC_NCHANNELS;
105 128
106 129
107 /* allocate all the required GET/PUT values */ 130 /* allocate all the required GET/PUT values */
108 131
109 part->local_GPs = xpc_kmalloc_cacheline_aligned(XPC_GP_SIZE, 132 part->local_GPs = xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE,
110 GFP_KERNEL, &part->local_GPs_base); 133 GFP_KERNEL, &part->local_GPs_base);
111 if (part->local_GPs == NULL) { 134 if (part->local_GPs == NULL) {
112 kfree(part->channels); 135 kfree(part->channels);
@@ -115,55 +138,51 @@ xpc_setup_infrastructure(struct xpc_partition *part)
115 "values\n"); 138 "values\n");
116 return xpcNoMemory; 139 return xpcNoMemory;
117 } 140 }
118 memset(part->local_GPs, 0, XPC_GP_SIZE);
119 141
120 part->remote_GPs = xpc_kmalloc_cacheline_aligned(XPC_GP_SIZE, 142 part->remote_GPs = xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE,
121 GFP_KERNEL, &part->remote_GPs_base); 143 GFP_KERNEL, &part->remote_GPs_base);
122 if (part->remote_GPs == NULL) { 144 if (part->remote_GPs == NULL) {
123 kfree(part->channels);
124 part->channels = NULL;
125 kfree(part->local_GPs_base);
126 part->local_GPs = NULL;
127 dev_err(xpc_chan, "can't get memory for remote get/put " 145 dev_err(xpc_chan, "can't get memory for remote get/put "
128 "values\n"); 146 "values\n");
147 kfree(part->local_GPs_base);
148 part->local_GPs = NULL;
149 kfree(part->channels);
150 part->channels = NULL;
129 return xpcNoMemory; 151 return xpcNoMemory;
130 } 152 }
131 memset(part->remote_GPs, 0, XPC_GP_SIZE);
132 153
133 154
134 /* allocate all the required open and close args */ 155 /* allocate all the required open and close args */
135 156
136 part->local_openclose_args = xpc_kmalloc_cacheline_aligned( 157 part->local_openclose_args = xpc_kzalloc_cacheline_aligned(
137 XPC_OPENCLOSE_ARGS_SIZE, GFP_KERNEL, 158 XPC_OPENCLOSE_ARGS_SIZE, GFP_KERNEL,
138 &part->local_openclose_args_base); 159 &part->local_openclose_args_base);
139 if (part->local_openclose_args == NULL) { 160 if (part->local_openclose_args == NULL) {
140 kfree(part->channels); 161 dev_err(xpc_chan, "can't get memory for local connect args\n");
141 part->channels = NULL;
142 kfree(part->local_GPs_base);
143 part->local_GPs = NULL;
144 kfree(part->remote_GPs_base); 162 kfree(part->remote_GPs_base);
145 part->remote_GPs = NULL; 163 part->remote_GPs = NULL;
146 dev_err(xpc_chan, "can't get memory for local connect args\n"); 164 kfree(part->local_GPs_base);
165 part->local_GPs = NULL;
166 kfree(part->channels);
167 part->channels = NULL;
147 return xpcNoMemory; 168 return xpcNoMemory;
148 } 169 }
149 memset(part->local_openclose_args, 0, XPC_OPENCLOSE_ARGS_SIZE);
150 170
151 part->remote_openclose_args = xpc_kmalloc_cacheline_aligned( 171 part->remote_openclose_args = xpc_kzalloc_cacheline_aligned(
152 XPC_OPENCLOSE_ARGS_SIZE, GFP_KERNEL, 172 XPC_OPENCLOSE_ARGS_SIZE, GFP_KERNEL,
153 &part->remote_openclose_args_base); 173 &part->remote_openclose_args_base);
154 if (part->remote_openclose_args == NULL) { 174 if (part->remote_openclose_args == NULL) {
155 kfree(part->channels); 175 dev_err(xpc_chan, "can't get memory for remote connect args\n");
156 part->channels = NULL;
157 kfree(part->local_GPs_base);
158 part->local_GPs = NULL;
159 kfree(part->remote_GPs_base);
160 part->remote_GPs = NULL;
161 kfree(part->local_openclose_args_base); 176 kfree(part->local_openclose_args_base);
162 part->local_openclose_args = NULL; 177 part->local_openclose_args = NULL;
163 dev_err(xpc_chan, "can't get memory for remote connect args\n"); 178 kfree(part->remote_GPs_base);
179 part->remote_GPs = NULL;
180 kfree(part->local_GPs_base);
181 part->local_GPs = NULL;
182 kfree(part->channels);
183 part->channels = NULL;
164 return xpcNoMemory; 184 return xpcNoMemory;
165 } 185 }
166 memset(part->remote_openclose_args, 0, XPC_OPENCLOSE_ARGS_SIZE);
167 186
168 187
169 xpc_initialize_channels(part, partid); 188 xpc_initialize_channels(part, partid);
@@ -186,18 +205,18 @@ xpc_setup_infrastructure(struct xpc_partition *part)
186 ret = request_irq(SGI_XPC_NOTIFY, xpc_notify_IRQ_handler, SA_SHIRQ, 205 ret = request_irq(SGI_XPC_NOTIFY, xpc_notify_IRQ_handler, SA_SHIRQ,
187 part->IPI_owner, (void *) (u64) partid); 206 part->IPI_owner, (void *) (u64) partid);
188 if (ret != 0) { 207 if (ret != 0) {
189 kfree(part->channels);
190 part->channels = NULL;
191 kfree(part->local_GPs_base);
192 part->local_GPs = NULL;
193 kfree(part->remote_GPs_base);
194 part->remote_GPs = NULL;
195 kfree(part->local_openclose_args_base);
196 part->local_openclose_args = NULL;
197 kfree(part->remote_openclose_args_base);
198 part->remote_openclose_args = NULL;
199 dev_err(xpc_chan, "can't register NOTIFY IRQ handler, " 208 dev_err(xpc_chan, "can't register NOTIFY IRQ handler, "
200 "errno=%d\n", -ret); 209 "errno=%d\n", -ret);
210 kfree(part->remote_openclose_args_base);
211 part->remote_openclose_args = NULL;
212 kfree(part->local_openclose_args_base);
213 part->local_openclose_args = NULL;
214 kfree(part->remote_GPs_base);
215 part->remote_GPs = NULL;
216 kfree(part->local_GPs_base);
217 part->local_GPs = NULL;
218 kfree(part->channels);
219 part->channels = NULL;
201 return xpcLackOfResources; 220 return xpcLackOfResources;
202 } 221 }
203 222
@@ -446,22 +465,20 @@ xpc_allocate_local_msgqueue(struct xpc_channel *ch)
446 for (nentries = ch->local_nentries; nentries > 0; nentries--) { 465 for (nentries = ch->local_nentries; nentries > 0; nentries--) {
447 466
448 nbytes = nentries * ch->msg_size; 467 nbytes = nentries * ch->msg_size;
449 ch->local_msgqueue = xpc_kmalloc_cacheline_aligned(nbytes, 468 ch->local_msgqueue = xpc_kzalloc_cacheline_aligned(nbytes,
450 GFP_KERNEL, 469 GFP_KERNEL,
451 &ch->local_msgqueue_base); 470 &ch->local_msgqueue_base);
452 if (ch->local_msgqueue == NULL) { 471 if (ch->local_msgqueue == NULL) {
453 continue; 472 continue;
454 } 473 }
455 memset(ch->local_msgqueue, 0, nbytes);
456 474
457 nbytes = nentries * sizeof(struct xpc_notify); 475 nbytes = nentries * sizeof(struct xpc_notify);
458 ch->notify_queue = kmalloc(nbytes, GFP_KERNEL); 476 ch->notify_queue = kzalloc(nbytes, GFP_KERNEL);
459 if (ch->notify_queue == NULL) { 477 if (ch->notify_queue == NULL) {
460 kfree(ch->local_msgqueue_base); 478 kfree(ch->local_msgqueue_base);
461 ch->local_msgqueue = NULL; 479 ch->local_msgqueue = NULL;
462 continue; 480 continue;
463 } 481 }
464 memset(ch->notify_queue, 0, nbytes);
465 482
466 spin_lock_irqsave(&ch->lock, irq_flags); 483 spin_lock_irqsave(&ch->lock, irq_flags);
467 if (nentries < ch->local_nentries) { 484 if (nentries < ch->local_nentries) {
@@ -501,13 +518,12 @@ xpc_allocate_remote_msgqueue(struct xpc_channel *ch)
501 for (nentries = ch->remote_nentries; nentries > 0; nentries--) { 518 for (nentries = ch->remote_nentries; nentries > 0; nentries--) {
502 519
503 nbytes = nentries * ch->msg_size; 520 nbytes = nentries * ch->msg_size;
504 ch->remote_msgqueue = xpc_kmalloc_cacheline_aligned(nbytes, 521 ch->remote_msgqueue = xpc_kzalloc_cacheline_aligned(nbytes,
505 GFP_KERNEL, 522 GFP_KERNEL,
506 &ch->remote_msgqueue_base); 523 &ch->remote_msgqueue_base);
507 if (ch->remote_msgqueue == NULL) { 524 if (ch->remote_msgqueue == NULL) {
508 continue; 525 continue;
509 } 526 }
510 memset(ch->remote_msgqueue, 0, nbytes);
511 527
512 spin_lock_irqsave(&ch->lock, irq_flags); 528 spin_lock_irqsave(&ch->lock, irq_flags);
513 if (nentries < ch->remote_nentries) { 529 if (nentries < ch->remote_nentries) {
diff --git a/arch/ia64/sn/kernel/xpc_main.c b/arch/ia64/sn/kernel/xpc_main.c
index 8cbf16432570..99b123a6421a 100644
--- a/arch/ia64/sn/kernel/xpc_main.c
+++ b/arch/ia64/sn/kernel/xpc_main.c
@@ -52,7 +52,6 @@
52#include <linux/syscalls.h> 52#include <linux/syscalls.h>
53#include <linux/cache.h> 53#include <linux/cache.h>
54#include <linux/interrupt.h> 54#include <linux/interrupt.h>
55#include <linux/slab.h>
56#include <linux/delay.h> 55#include <linux/delay.h>
57#include <linux/reboot.h> 56#include <linux/reboot.h>
58#include <linux/completion.h> 57#include <linux/completion.h>
diff --git a/arch/ia64/sn/kernel/xpc_partition.c b/arch/ia64/sn/kernel/xpc_partition.c
index 88a730e6cfdb..94211429fd0c 100644
--- a/arch/ia64/sn/kernel/xpc_partition.c
+++ b/arch/ia64/sn/kernel/xpc_partition.c
@@ -81,6 +81,31 @@ char ____cacheline_aligned xpc_remote_copy_buffer[XPC_RP_HEADER_SIZE +
81 81
82 82
83/* 83/*
84 * Guarantee that the kmalloc'd memory is cacheline aligned.
85 */
86static void *
87xpc_kmalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
88{
89 /* see if kmalloc will give us cachline aligned memory by default */
90 *base = kmalloc(size, flags);
91 if (*base == NULL) {
92 return NULL;
93 }
94 if ((u64) *base == L1_CACHE_ALIGN((u64) *base)) {
95 return *base;
96 }
97 kfree(*base);
98
99 /* nope, we'll have to do it ourselves */
100 *base = kmalloc(size + L1_CACHE_BYTES, flags);
101 if (*base == NULL) {
102 return NULL;
103 }
104 return (void *) L1_CACHE_ALIGN((u64) *base);
105}
106
107
108/*
84 * Given a nasid, get the physical address of the partition's reserved page 109 * Given a nasid, get the physical address of the partition's reserved page
85 * for that nasid. This function returns 0 on any error. 110 * for that nasid. This function returns 0 on any error.
86 */ 111 */
@@ -1038,13 +1063,12 @@ xpc_discovery(void)
1038 remote_vars = (struct xpc_vars *) remote_rp; 1063 remote_vars = (struct xpc_vars *) remote_rp;
1039 1064
1040 1065
1041 discovered_nasids = kmalloc(sizeof(u64) * xp_nasid_mask_words, 1066 discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words,
1042 GFP_KERNEL); 1067 GFP_KERNEL);
1043 if (discovered_nasids == NULL) { 1068 if (discovered_nasids == NULL) {
1044 kfree(remote_rp_base); 1069 kfree(remote_rp_base);
1045 return; 1070 return;
1046 } 1071 }
1047 memset(discovered_nasids, 0, sizeof(u64) * xp_nasid_mask_words);
1048 1072
1049 rp = (struct xpc_rsvd_page *) xpc_rsvd_page; 1073 rp = (struct xpc_rsvd_page *) xpc_rsvd_page;
1050 1074
diff --git a/arch/ia64/sn/pci/tioce_provider.c b/arch/ia64/sn/pci/tioce_provider.c
index e52831ed93eb..fa073cc4b565 100644
--- a/arch/ia64/sn/pci/tioce_provider.c
+++ b/arch/ia64/sn/pci/tioce_provider.c
@@ -15,6 +15,124 @@
15#include <asm/sn/pcidev.h> 15#include <asm/sn/pcidev.h>
16#include <asm/sn/pcibus_provider_defs.h> 16#include <asm/sn/pcibus_provider_defs.h>
17#include <asm/sn/tioce_provider.h> 17#include <asm/sn/tioce_provider.h>
18#include <asm/sn/sn2/sn_hwperf.h>
19
20/*
21 * 1/26/2006
22 *
23 * WAR for SGI PV 944642. For revA TIOCE, need to use the following recipe
24 * (taken from the above PV) before and after accessing tioce internal MMR's
25 * to avoid tioce lockups.
26 *
27 * The recipe as taken from the PV:
28 *
29 * if(mmr address < 0x45000) {
30 * if(mmr address == 0 or 0x80)
31 * mmr wrt or read address 0xc0
32 * else if(mmr address == 0x148 or 0x200)
33 * mmr wrt or read address 0x28
34 * else
35 * mmr wrt or read address 0x158
36 *
37 * do desired mmr access (rd or wrt)
38 *
39 * if(mmr address == 0x100)
40 * mmr wrt or read address 0x38
41 * mmr wrt or read address 0xb050
42 * } else
43 * do desired mmr access
44 *
45 * According to hw, we can use reads instead of writes to the above addres
46 *
47 * Note this WAR can only to be used for accessing internal MMR's in the
48 * TIOCE Coretalk Address Range 0x0 - 0x07ff_ffff. This includes the
49 * "Local CE Registers and Memories" and "PCI Compatible Config Space" address
50 * spaces from table 2-1 of the "CE Programmer's Reference Overview" document.
51 *
52 * All registers defined in struct tioce will meet that criteria.
53 */
54
55static void inline
56tioce_mmr_war_pre(struct tioce_kernel *kern, void *mmr_addr)
57{
58 u64 mmr_base;
59 u64 mmr_offset;
60
61 if (kern->ce_common->ce_rev != TIOCE_REV_A)
62 return;
63
64 mmr_base = kern->ce_common->ce_pcibus.bs_base;
65 mmr_offset = (u64)mmr_addr - mmr_base;
66
67 if (mmr_offset < 0x45000) {
68 u64 mmr_war_offset;
69
70 if (mmr_offset == 0 || mmr_offset == 0x80)
71 mmr_war_offset = 0xc0;
72 else if (mmr_offset == 0x148 || mmr_offset == 0x200)
73 mmr_war_offset = 0x28;
74 else
75 mmr_war_offset = 0x158;
76
77 readq_relaxed((void *)(mmr_base + mmr_war_offset));
78 }
79}
80
81static void inline
82tioce_mmr_war_post(struct tioce_kernel *kern, void *mmr_addr)
83{
84 u64 mmr_base;
85 u64 mmr_offset;
86
87 if (kern->ce_common->ce_rev != TIOCE_REV_A)
88 return;
89
90 mmr_base = kern->ce_common->ce_pcibus.bs_base;
91 mmr_offset = (u64)mmr_addr - mmr_base;
92
93 if (mmr_offset < 0x45000) {
94 if (mmr_offset == 0x100)
95 readq_relaxed((void *)(mmr_base + 0x38));
96 readq_relaxed((void *)(mmr_base + 0xb050));
97 }
98}
99
100/* load mmr contents into a variable */
101#define tioce_mmr_load(kern, mmrp, varp) do {\
102 tioce_mmr_war_pre(kern, mmrp); \
103 *(varp) = readq_relaxed(mmrp); \
104 tioce_mmr_war_post(kern, mmrp); \
105} while (0)
106
107/* store variable contents into mmr */
108#define tioce_mmr_store(kern, mmrp, varp) do {\
109 tioce_mmr_war_pre(kern, mmrp); \
110 writeq(*varp, mmrp); \
111 tioce_mmr_war_post(kern, mmrp); \
112} while (0)
113
114/* store immediate value into mmr */
115#define tioce_mmr_storei(kern, mmrp, val) do {\
116 tioce_mmr_war_pre(kern, mmrp); \
117 writeq(val, mmrp); \
118 tioce_mmr_war_post(kern, mmrp); \
119} while (0)
120
121/* set bits (immediate value) into mmr */
122#define tioce_mmr_seti(kern, mmrp, bits) do {\
123 u64 tmp; \
124 tioce_mmr_load(kern, mmrp, &tmp); \
125 tmp |= (bits); \
126 tioce_mmr_store(kern, mmrp, &tmp); \
127} while (0)
128
129/* clear bits (immediate value) into mmr */
130#define tioce_mmr_clri(kern, mmrp, bits) do { \
131 u64 tmp; \
132 tioce_mmr_load(kern, mmrp, &tmp); \
133 tmp &= ~(bits); \
134 tioce_mmr_store(kern, mmrp, &tmp); \
135} while (0)
18 136
19/** 137/**
20 * Bus address ranges for the 5 flavors of TIOCE DMA 138 * Bus address ranges for the 5 flavors of TIOCE DMA
@@ -62,9 +180,9 @@
62#define TIOCE_ATE_M40 2 180#define TIOCE_ATE_M40 2
63#define TIOCE_ATE_M40S 3 181#define TIOCE_ATE_M40S 3
64 182
65#define KB(x) ((x) << 10) 183#define KB(x) ((u64)(x) << 10)
66#define MB(x) ((x) << 20) 184#define MB(x) ((u64)(x) << 20)
67#define GB(x) ((x) << 30) 185#define GB(x) ((u64)(x) << 30)
68 186
69/** 187/**
70 * tioce_dma_d64 - create a DMA mapping using 64-bit direct mode 188 * tioce_dma_d64 - create a DMA mapping using 64-bit direct mode
@@ -151,7 +269,7 @@ tioce_alloc_map(struct tioce_kernel *ce_kern, int type, int port,
151 int last; 269 int last;
152 int entries; 270 int entries;
153 int nates; 271 int nates;
154 int pagesize; 272 u64 pagesize;
155 u64 *ate_shadow; 273 u64 *ate_shadow;
156 u64 *ate_reg; 274 u64 *ate_reg;
157 u64 addr; 275 u64 addr;
@@ -228,7 +346,7 @@ tioce_alloc_map(struct tioce_kernel *ce_kern, int type, int port,
228 346
229 ate = ATE_MAKE(addr, pagesize); 347 ate = ATE_MAKE(addr, pagesize);
230 ate_shadow[i + j] = ate; 348 ate_shadow[i + j] = ate;
231 writeq(ate, &ate_reg[i + j]); 349 tioce_mmr_storei(ce_kern, &ate_reg[i + j], ate);
232 addr += pagesize; 350 addr += pagesize;
233 } 351 }
234 352
@@ -272,7 +390,8 @@ tioce_dma_d32(struct pci_dev *pdev, u64 ct_addr)
272 u64 tmp; 390 u64 tmp;
273 391
274 ce_kern->ce_port[port].dirmap_shadow = ct_upper; 392 ce_kern->ce_port[port].dirmap_shadow = ct_upper;
275 writeq(ct_upper, &ce_mmr->ce_ure_dir_map[port]); 393 tioce_mmr_storei(ce_kern, &ce_mmr->ce_ure_dir_map[port],
394 ct_upper);
276 tmp = ce_mmr->ce_ure_dir_map[port]; 395 tmp = ce_mmr->ce_ure_dir_map[port];
277 dma_ok = 1; 396 dma_ok = 1;
278 } else 397 } else
@@ -344,7 +463,8 @@ tioce_dma_unmap(struct pci_dev *pdev, dma_addr_t bus_addr, int dir)
344 if (TIOCE_D32_ADDR(bus_addr)) { 463 if (TIOCE_D32_ADDR(bus_addr)) {
345 if (--ce_kern->ce_port[port].dirmap_refcnt == 0) { 464 if (--ce_kern->ce_port[port].dirmap_refcnt == 0) {
346 ce_kern->ce_port[port].dirmap_shadow = 0; 465 ce_kern->ce_port[port].dirmap_shadow = 0;
347 writeq(0, &ce_mmr->ce_ure_dir_map[port]); 466 tioce_mmr_storei(ce_kern, &ce_mmr->ce_ure_dir_map[port],
467 0);
348 } 468 }
349 } else { 469 } else {
350 struct tioce_dmamap *map; 470 struct tioce_dmamap *map;
@@ -365,7 +485,7 @@ tioce_dma_unmap(struct pci_dev *pdev, dma_addr_t bus_addr, int dir)
365 } else if (--map->refcnt == 0) { 485 } else if (--map->refcnt == 0) {
366 for (i = 0; i < map->ate_count; i++) { 486 for (i = 0; i < map->ate_count; i++) {
367 map->ate_shadow[i] = 0; 487 map->ate_shadow[i] = 0;
368 map->ate_hw[i] = 0; 488 tioce_mmr_storei(ce_kern, &map->ate_hw[i], 0);
369 } 489 }
370 490
371 list_del(&map->ce_dmamap_list); 491 list_del(&map->ce_dmamap_list);
@@ -486,7 +606,7 @@ tioce_do_dma_map(struct pci_dev *pdev, u64 paddr, size_t byte_count,
486 spin_unlock_irqrestore(&ce_kern->ce_lock, flags); 606 spin_unlock_irqrestore(&ce_kern->ce_lock, flags);
487 607
488dma_map_done: 608dma_map_done:
489 if (mapaddr & barrier) 609 if (mapaddr && barrier)
490 mapaddr = tioce_dma_barrier(mapaddr, 1); 610 mapaddr = tioce_dma_barrier(mapaddr, 1);
491 611
492 return mapaddr; 612 return mapaddr;
@@ -541,17 +661,61 @@ tioce_error_intr_handler(int irq, void *arg, struct pt_regs *pt)
541 soft->ce_pcibus.bs_persist_segment, 661 soft->ce_pcibus.bs_persist_segment,
542 soft->ce_pcibus.bs_persist_busnum, 0, 0, 0, 0, 0); 662 soft->ce_pcibus.bs_persist_busnum, 0, 0, 0, 0, 0);
543 663
664 if (ret_stuff.v0)
665 panic("tioce_error_intr_handler: Fatal TIOCE error");
666
544 return IRQ_HANDLED; 667 return IRQ_HANDLED;
545} 668}
546 669
547/** 670/**
671 * tioce_reserve_m32 - reserve M32 ate's for the indicated address range
672 * @tioce_kernel: TIOCE context to reserve ate's for
673 * @base: starting bus address to reserve
674 * @limit: last bus address to reserve
675 *
676 * If base/limit falls within the range of bus space mapped through the
677 * M32 space, reserve the resources corresponding to the range.
678 */
679static void
680tioce_reserve_m32(struct tioce_kernel *ce_kern, u64 base, u64 limit)
681{
682 int ate_index, last_ate, ps;
683 struct tioce *ce_mmr;
684
685 if (!TIOCE_M32_ADDR(base))
686 return;
687
688 ce_mmr = (struct tioce *)ce_kern->ce_common->ce_pcibus.bs_base;
689 ps = ce_kern->ce_ate3240_pagesize;
690 ate_index = ATE_PAGE(base, ps);
691 last_ate = ate_index + ATE_NPAGES(base, limit-base+1, ps) - 1;
692
693 if (ate_index < 64)
694 ate_index = 64;
695
696 while (ate_index <= last_ate) {
697 u64 ate;
698
699 ate = ATE_MAKE(0xdeadbeef, ps);
700 ce_kern->ce_ate3240_shadow[ate_index] = ate;
701 tioce_mmr_storei(ce_kern, &ce_mmr->ce_ure_ate3240[ate_index],
702 ate);
703 ate_index++;
704 }
705}
706
707/**
548 * tioce_kern_init - init kernel structures related to a given TIOCE 708 * tioce_kern_init - init kernel structures related to a given TIOCE
549 * @tioce_common: ptr to a cached tioce_common struct that originated in prom 709 * @tioce_common: ptr to a cached tioce_common struct that originated in prom
550 */ static struct tioce_kernel * 710 */
711static struct tioce_kernel *
551tioce_kern_init(struct tioce_common *tioce_common) 712tioce_kern_init(struct tioce_common *tioce_common)
552{ 713{
553 int i; 714 int i;
715 int ps;
716 int dev;
554 u32 tmp; 717 u32 tmp;
718 unsigned int seg, bus;
555 struct tioce *tioce_mmr; 719 struct tioce *tioce_mmr;
556 struct tioce_kernel *tioce_kern; 720 struct tioce_kernel *tioce_kern;
557 721
@@ -572,9 +736,10 @@ tioce_kern_init(struct tioce_common *tioce_common)
572 * here to use pci_read_config_xxx() so use the raw_pci_ops vector. 736 * here to use pci_read_config_xxx() so use the raw_pci_ops vector.
573 */ 737 */
574 738
575 raw_pci_ops->read(tioce_common->ce_pcibus.bs_persist_segment, 739 seg = tioce_common->ce_pcibus.bs_persist_segment;
576 tioce_common->ce_pcibus.bs_persist_busnum, 740 bus = tioce_common->ce_pcibus.bs_persist_busnum;
577 PCI_DEVFN(2, 0), PCI_SECONDARY_BUS, 1, &tmp); 741
742 raw_pci_ops->read(seg, bus, PCI_DEVFN(2, 0), PCI_SECONDARY_BUS, 1,&tmp);
578 tioce_kern->ce_port1_secondary = (u8) tmp; 743 tioce_kern->ce_port1_secondary = (u8) tmp;
579 744
580 /* 745 /*
@@ -583,18 +748,76 @@ tioce_kern_init(struct tioce_common *tioce_common)
583 */ 748 */
584 749
585 tioce_mmr = (struct tioce *)tioce_common->ce_pcibus.bs_base; 750 tioce_mmr = (struct tioce *)tioce_common->ce_pcibus.bs_base;
586 __sn_clrq_relaxed(&tioce_mmr->ce_ure_page_map, CE_URE_PAGESIZE_MASK); 751 tioce_mmr_clri(tioce_kern, &tioce_mmr->ce_ure_page_map,
587 __sn_setq_relaxed(&tioce_mmr->ce_ure_page_map, CE_URE_256K_PAGESIZE); 752 CE_URE_PAGESIZE_MASK);
588 tioce_kern->ce_ate3240_pagesize = KB(256); 753 tioce_mmr_seti(tioce_kern, &tioce_mmr->ce_ure_page_map,
754 CE_URE_256K_PAGESIZE);
755 ps = tioce_kern->ce_ate3240_pagesize = KB(256);
589 756
590 for (i = 0; i < TIOCE_NUM_M40_ATES; i++) { 757 for (i = 0; i < TIOCE_NUM_M40_ATES; i++) {
591 tioce_kern->ce_ate40_shadow[i] = 0; 758 tioce_kern->ce_ate40_shadow[i] = 0;
592 writeq(0, &tioce_mmr->ce_ure_ate40[i]); 759 tioce_mmr_storei(tioce_kern, &tioce_mmr->ce_ure_ate40[i], 0);
593 } 760 }
594 761
595 for (i = 0; i < TIOCE_NUM_M3240_ATES; i++) { 762 for (i = 0; i < TIOCE_NUM_M3240_ATES; i++) {
596 tioce_kern->ce_ate3240_shadow[i] = 0; 763 tioce_kern->ce_ate3240_shadow[i] = 0;
597 writeq(0, &tioce_mmr->ce_ure_ate3240[i]); 764 tioce_mmr_storei(tioce_kern, &tioce_mmr->ce_ure_ate3240[i], 0);
765 }
766
767 /*
768 * Reserve ATE's corresponding to reserved address ranges. These
769 * include:
770 *
771 * Memory space covered by each PPB mem base/limit register
772 * Memory space covered by each PPB prefetch base/limit register
773 *
774 * These bus ranges are for pio (downstream) traffic only, and so
775 * cannot be used for DMA.
776 */
777
778 for (dev = 1; dev <= 2; dev++) {
779 u64 base, limit;
780
781 /* mem base/limit */
782
783 raw_pci_ops->read(seg, bus, PCI_DEVFN(dev, 0),
784 PCI_MEMORY_BASE, 2, &tmp);
785 base = (u64)tmp << 16;
786
787 raw_pci_ops->read(seg, bus, PCI_DEVFN(dev, 0),
788 PCI_MEMORY_LIMIT, 2, &tmp);
789 limit = (u64)tmp << 16;
790 limit |= 0xfffffUL;
791
792 if (base < limit)
793 tioce_reserve_m32(tioce_kern, base, limit);
794
795 /*
796 * prefetch mem base/limit. The tioce ppb's have 64-bit
797 * decoders, so read the upper portions w/o checking the
798 * attributes.
799 */
800
801 raw_pci_ops->read(seg, bus, PCI_DEVFN(dev, 0),
802 PCI_PREF_MEMORY_BASE, 2, &tmp);
803 base = ((u64)tmp & PCI_PREF_RANGE_MASK) << 16;
804
805 raw_pci_ops->read(seg, bus, PCI_DEVFN(dev, 0),
806 PCI_PREF_BASE_UPPER32, 4, &tmp);
807 base |= (u64)tmp << 32;
808
809 raw_pci_ops->read(seg, bus, PCI_DEVFN(dev, 0),
810 PCI_PREF_MEMORY_LIMIT, 2, &tmp);
811
812 limit = ((u64)tmp & PCI_PREF_RANGE_MASK) << 16;
813 limit |= 0xfffffUL;
814
815 raw_pci_ops->read(seg, bus, PCI_DEVFN(dev, 0),
816 PCI_PREF_LIMIT_UPPER32, 4, &tmp);
817 limit |= (u64)tmp << 32;
818
819 if ((base < limit) && TIOCE_M32_ADDR(base))
820 tioce_reserve_m32(tioce_kern, base, limit);
598 } 821 }
599 822
600 return tioce_kern; 823 return tioce_kern;
@@ -614,6 +837,7 @@ tioce_force_interrupt(struct sn_irq_info *sn_irq_info)
614{ 837{
615 struct pcidev_info *pcidev_info; 838 struct pcidev_info *pcidev_info;
616 struct tioce_common *ce_common; 839 struct tioce_common *ce_common;
840 struct tioce_kernel *ce_kern;
617 struct tioce *ce_mmr; 841 struct tioce *ce_mmr;
618 u64 force_int_val; 842 u64 force_int_val;
619 843
@@ -629,6 +853,29 @@ tioce_force_interrupt(struct sn_irq_info *sn_irq_info)
629 853
630 ce_common = (struct tioce_common *)pcidev_info->pdi_pcibus_info; 854 ce_common = (struct tioce_common *)pcidev_info->pdi_pcibus_info;
631 ce_mmr = (struct tioce *)ce_common->ce_pcibus.bs_base; 855 ce_mmr = (struct tioce *)ce_common->ce_pcibus.bs_base;
856 ce_kern = (struct tioce_kernel *)ce_common->ce_kernel_private;
857
858 /*
859 * TIOCE Rev A workaround (PV 945826), force an interrupt by writing
860 * the TIO_INTx register directly (1/26/2006)
861 */
862 if (ce_common->ce_rev == TIOCE_REV_A) {
863 u64 int_bit_mask = (1ULL << sn_irq_info->irq_int_bit);
864 u64 status;
865
866 tioce_mmr_load(ce_kern, &ce_mmr->ce_adm_int_status, &status);
867 if (status & int_bit_mask) {
868 u64 force_irq = (1 << 8) | sn_irq_info->irq_irq;
869 u64 ctalk = sn_irq_info->irq_xtalkaddr;
870 u64 nasid, offset;
871
872 nasid = (ctalk & CTALK_NASID_MASK) >> CTALK_NASID_SHFT;
873 offset = (ctalk & CTALK_NODE_OFFSET);
874 HUB_S(TIO_IOSPACE_ADDR(nasid, offset), force_irq);
875 }
876
877 return;
878 }
632 879
633 /* 880 /*
634 * irq_int_bit is originally set up by prom, and holds the interrupt 881 * irq_int_bit is originally set up by prom, and holds the interrupt
@@ -666,7 +913,7 @@ tioce_force_interrupt(struct sn_irq_info *sn_irq_info)
666 default: 913 default:
667 return; 914 return;
668 } 915 }
669 writeq(force_int_val, &ce_mmr->ce_adm_force_int); 916 tioce_mmr_storei(ce_kern, &ce_mmr->ce_adm_force_int, force_int_val);
670} 917}
671 918
672/** 919/**
@@ -685,6 +932,7 @@ tioce_target_interrupt(struct sn_irq_info *sn_irq_info)
685{ 932{
686 struct pcidev_info *pcidev_info; 933 struct pcidev_info *pcidev_info;
687 struct tioce_common *ce_common; 934 struct tioce_common *ce_common;
935 struct tioce_kernel *ce_kern;
688 struct tioce *ce_mmr; 936 struct tioce *ce_mmr;
689 int bit; 937 int bit;
690 u64 vector; 938 u64 vector;
@@ -695,14 +943,15 @@ tioce_target_interrupt(struct sn_irq_info *sn_irq_info)
695 943
696 ce_common = (struct tioce_common *)pcidev_info->pdi_pcibus_info; 944 ce_common = (struct tioce_common *)pcidev_info->pdi_pcibus_info;
697 ce_mmr = (struct tioce *)ce_common->ce_pcibus.bs_base; 945 ce_mmr = (struct tioce *)ce_common->ce_pcibus.bs_base;
946 ce_kern = (struct tioce_kernel *)ce_common->ce_kernel_private;
698 947
699 bit = sn_irq_info->irq_int_bit; 948 bit = sn_irq_info->irq_int_bit;
700 949
701 __sn_setq_relaxed(&ce_mmr->ce_adm_int_mask, (1UL << bit)); 950 tioce_mmr_seti(ce_kern, &ce_mmr->ce_adm_int_mask, (1UL << bit));
702 vector = (u64)sn_irq_info->irq_irq << INTR_VECTOR_SHFT; 951 vector = (u64)sn_irq_info->irq_irq << INTR_VECTOR_SHFT;
703 vector |= sn_irq_info->irq_xtalkaddr; 952 vector |= sn_irq_info->irq_xtalkaddr;
704 writeq(vector, &ce_mmr->ce_adm_int_dest[bit]); 953 tioce_mmr_storei(ce_kern, &ce_mmr->ce_adm_int_dest[bit], vector);
705 __sn_clrq_relaxed(&ce_mmr->ce_adm_int_mask, (1UL << bit)); 954 tioce_mmr_clri(ce_kern, &ce_mmr->ce_adm_int_mask, (1UL << bit));
706 955
707 tioce_force_interrupt(sn_irq_info); 956 tioce_force_interrupt(sn_irq_info);
708} 957}
@@ -721,7 +970,11 @@ tioce_target_interrupt(struct sn_irq_info *sn_irq_info)
721static void * 970static void *
722tioce_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *controller) 971tioce_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *controller)
723{ 972{
973 int my_nasid;
974 cnodeid_t my_cnode, mem_cnode;
724 struct tioce_common *tioce_common; 975 struct tioce_common *tioce_common;
976 struct tioce_kernel *tioce_kern;
977 struct tioce *tioce_mmr;
725 978
726 /* 979 /*
727 * Allocate kernel bus soft and copy from prom. 980 * Allocate kernel bus soft and copy from prom.
@@ -734,11 +987,23 @@ tioce_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *cont
734 memcpy(tioce_common, prom_bussoft, sizeof(struct tioce_common)); 987 memcpy(tioce_common, prom_bussoft, sizeof(struct tioce_common));
735 tioce_common->ce_pcibus.bs_base |= __IA64_UNCACHED_OFFSET; 988 tioce_common->ce_pcibus.bs_base |= __IA64_UNCACHED_OFFSET;
736 989
737 if (tioce_kern_init(tioce_common) == NULL) { 990 tioce_kern = tioce_kern_init(tioce_common);
991 if (tioce_kern == NULL) {
738 kfree(tioce_common); 992 kfree(tioce_common);
739 return NULL; 993 return NULL;
740 } 994 }
741 995
996 /*
997 * Clear out any transient errors before registering the error
998 * interrupt handler.
999 */
1000
1001 tioce_mmr = (struct tioce *)tioce_common->ce_pcibus.bs_base;
1002 tioce_mmr_seti(tioce_kern, &tioce_mmr->ce_adm_int_status_alias, ~0ULL);
1003 tioce_mmr_seti(tioce_kern, &tioce_mmr->ce_adm_error_summary_alias,
1004 ~0ULL);
1005 tioce_mmr_seti(tioce_kern, &tioce_mmr->ce_dre_comp_err_addr, ~0ULL);
1006
742 if (request_irq(SGI_PCIASIC_ERROR, 1007 if (request_irq(SGI_PCIASIC_ERROR,
743 tioce_error_intr_handler, 1008 tioce_error_intr_handler,
744 SA_SHIRQ, "TIOCE error", (void *)tioce_common)) 1009 SA_SHIRQ, "TIOCE error", (void *)tioce_common))
@@ -750,6 +1015,21 @@ tioce_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *cont
750 tioce_common->ce_pcibus.bs_persist_segment, 1015 tioce_common->ce_pcibus.bs_persist_segment,
751 tioce_common->ce_pcibus.bs_persist_busnum); 1016 tioce_common->ce_pcibus.bs_persist_busnum);
752 1017
1018 /*
1019 * identify closest nasid for memory allocations
1020 */
1021
1022 my_nasid = NASID_GET(tioce_common->ce_pcibus.bs_base);
1023 my_cnode = nasid_to_cnodeid(my_nasid);
1024
1025 if (sn_hwperf_get_nearest_node(my_cnode, &mem_cnode, NULL) < 0) {
1026 printk(KERN_WARNING "tioce_bus_fixup: failed to find "
1027 "closest node with MEM to TIO node %d\n", my_cnode);
1028 mem_cnode = (cnodeid_t)-1; /* use any node */
1029 }
1030
1031 controller->node = mem_cnode;
1032
753 return tioce_common; 1033 return tioce_common;
754} 1034}
755 1035
diff --git a/arch/m68knommu/kernel/vmlinux.lds.S b/arch/m68knommu/kernel/vmlinux.lds.S
index ac9de2661c0b..a331cc90797c 100644
--- a/arch/m68knommu/kernel/vmlinux.lds.S
+++ b/arch/m68knommu/kernel/vmlinux.lds.S
@@ -269,6 +269,11 @@ SECTIONS {
269 *(__ksymtab_gpl) 269 *(__ksymtab_gpl)
270 __stop___ksymtab_gpl = .; 270 __stop___ksymtab_gpl = .;
271 271
272 /* Kernel symbol table: GPL-future symbols */
273 __start___ksymtab_gpl_future = .;
274 *(__ksymtab_gpl_future)
275 __stop___ksymtab_gpl_future = .;
276
272 /* Kernel symbol table: Normal symbols */ 277 /* Kernel symbol table: Normal symbols */
273 __start___kcrctab = .; 278 __start___kcrctab = .;
274 *(__kcrctab) 279 *(__kcrctab)
@@ -279,6 +284,11 @@ SECTIONS {
279 *(__kcrctab_gpl) 284 *(__kcrctab_gpl)
280 __stop___kcrctab_gpl = .; 285 __stop___kcrctab_gpl = .;
281 286
287 /* Kernel symbol table: GPL-future symbols */
288 __start___kcrctab_gpl_future = .;
289 *(__kcrctab_gpl_future)
290 __stop___kcrctab_gpl_future = .;
291
282 /* Kernel symbol table: strings */ 292 /* Kernel symbol table: strings */
283 *(__ksymtab_strings) 293 *(__ksymtab_strings)
284 294
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 3a0f89d2c8dc..ac2012f033d6 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -602,7 +602,7 @@ config SGI_IP32
602 If you want this kernel to run on SGI O2 workstation, say Y here. 602 If you want this kernel to run on SGI O2 workstation, say Y here.
603 603
604config SIBYTE_BIGSUR 604config SIBYTE_BIGSUR
605 bool "Support for Sibyte BigSur" 605 bool "Support for Sibyte BCM91480B-BigSur"
606 select BOOT_ELF32 606 select BOOT_ELF32
607 select DMA_COHERENT 607 select DMA_COHERENT
608 select PCI_DOMAINS 608 select PCI_DOMAINS
@@ -790,6 +790,7 @@ source "arch/mips/tx4927/Kconfig"
790source "arch/mips/tx4938/Kconfig" 790source "arch/mips/tx4938/Kconfig"
791source "arch/mips/vr41xx/Kconfig" 791source "arch/mips/vr41xx/Kconfig"
792source "arch/mips/philips/pnx8550/common/Kconfig" 792source "arch/mips/philips/pnx8550/common/Kconfig"
793source "arch/mips/cobalt/Kconfig"
793 794
794endmenu 795endmenu
795 796
@@ -1159,6 +1160,7 @@ config CPU_R4X00
1159config CPU_TX49XX 1160config CPU_TX49XX
1160 bool "R49XX" 1161 bool "R49XX"
1161 depends on SYS_HAS_CPU_TX49XX 1162 depends on SYS_HAS_CPU_TX49XX
1163 select CPU_HAS_PREFETCH
1162 select CPU_SUPPORTS_32BIT_KERNEL 1164 select CPU_SUPPORTS_32BIT_KERNEL
1163 select CPU_SUPPORTS_64BIT_KERNEL 1165 select CPU_SUPPORTS_64BIT_KERNEL
1164 1166
@@ -1581,7 +1583,7 @@ source "mm/Kconfig"
1581 1583
1582config SMP 1584config SMP
1583 bool "Multi-Processing support" 1585 bool "Multi-Processing support"
1584 depends on CPU_RM9000 || ((SIBYTE_BCM1x80 || SIBYTE_BCM1x55 || SIBYTE_SB1250) && !SIBYTE_STANDALONE) || SGI_IP27 || MIPS_MT_SMP 1586 depends on CPU_RM9000 || ((SIBYTE_BCM1x80 || SIBYTE_BCM1x55 || SIBYTE_SB1250 || QEMU) && !SIBYTE_STANDALONE) || SGI_IP27 || MIPS_MT_SMP
1585 ---help--- 1587 ---help---
1586 This enables support for systems with more than one CPU. If you have 1588 This enables support for systems with more than one CPU. If you have
1587 a system with only one CPU, like most personal computers, say N. If 1589 a system with only one CPU, like most personal computers, say N. If
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index 3d8dac681c63..9a69e0f0ab76 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -12,10 +12,6 @@
12# for "archclean" cleaning up for this architecture. 12# for "archclean" cleaning up for this architecture.
13# 13#
14 14
15as-option = $(shell if $(CC) $(CFLAGS) $(1) -Wa,-Z -c -o /dev/null \
16 -xassembler /dev/null > /dev/null 2>&1; then echo "$(1)"; \
17 else echo "$(2)"; fi ;)
18
19cflags-y := 15cflags-y :=
20 16
21# 17#
@@ -38,12 +34,10 @@ else
38endif 34endif
39 35
40ifdef CONFIG_32BIT 36ifdef CONFIG_32BIT
41gcc-abi = 32
42tool-prefix = $(32bit-tool-prefix) 37tool-prefix = $(32bit-tool-prefix)
43UTS_MACHINE := mips 38UTS_MACHINE := mips
44endif 39endif
45ifdef CONFIG_64BIT 40ifdef CONFIG_64BIT
46gcc-abi = 64
47tool-prefix = $(64bit-tool-prefix) 41tool-prefix = $(64bit-tool-prefix)
48UTS_MACHINE := mips64 42UTS_MACHINE := mips64
49endif 43endif
@@ -52,37 +46,27 @@ ifdef CONFIG_CROSSCOMPILE
52CROSS_COMPILE := $(tool-prefix) 46CROSS_COMPILE := $(tool-prefix)
53endif 47endif
54 48
55CHECKFLAGS-y += -D__linux__ -D__mips__ \ 49ifdef CONFIG_32BIT
56 -D_MIPS_SZINT=32 \ 50ld-emul = $(32bit-emul)
57 -D_ABIO32=1 \ 51vmlinux-32 = vmlinux
58 -D_ABIN32=2 \ 52vmlinux-64 = vmlinux.64
59 -D_ABI64=3 53
60CHECKFLAGS-$(CONFIG_32BIT) += -D_MIPS_SIM=_ABIO32 \ 54cflags-y += -mabi=32
61 -D_MIPS_SZLONG=32 \ 55endif
62 -D_MIPS_SZPTR=32 \
63 -D__PTRDIFF_TYPE__=int
64CHECKFLAGS-$(CONFIG_64BIT) += -m64 -D_MIPS_SIM=_ABI64 \
65 -D_MIPS_SZLONG=64 \
66 -D_MIPS_SZPTR=64 \
67 -D__PTRDIFF_TYPE__="long int"
68CHECKFLAGS-$(CONFIG_CPU_BIG_ENDIAN) += -D__MIPSEB__
69CHECKFLAGS-$(CONFIG_CPU_LITTLE_ENDIAN) += -D__MIPSEL__
70
71CHECKFLAGS = $(CHECKFLAGS-y)
72 56
73ifdef CONFIG_BUILD_ELF64 57ifdef CONFIG_64BIT
74gas-abi = 64
75ld-emul = $(64bit-emul) 58ld-emul = $(64bit-emul)
76vmlinux-32 = vmlinux.32 59vmlinux-32 = vmlinux.32
77vmlinux-64 = vmlinux 60vmlinux-64 = vmlinux
78else
79gas-abi = 32
80ld-emul = $(32bit-emul)
81vmlinux-32 = vmlinux
82vmlinux-64 = vmlinux.64
83 61
84cflags-$(CONFIG_64BIT) += $(call cc-option,-mno-explicit-relocs) 62cflags-y += -mabi=64
63ifdef CONFIG_BUILD_ELF64
64cflags-y += $(call cc-option,-mno-explicit-relocs)
65else
66cflags-y += $(call cc-option,-msym32)
85endif 67endif
68endif
69
86 70
87# 71#
88# GCC uses -G 0 -mabicalls -fpic as default. We don't want PIC in the kernel 72# GCC uses -G 0 -mabicalls -fpic as default. We don't want PIC in the kernel
@@ -105,162 +89,44 @@ MODFLAGS += -mlong-calls
105# carefully avoid to add it redundantly because gcc 3.3/3.4 complains 89# carefully avoid to add it redundantly because gcc 3.3/3.4 complains
106# when fed the toolchain default! 90# when fed the toolchain default!
107# 91#
108cflags-$(CONFIG_CPU_BIG_ENDIAN) += $(shell $(CC) -dumpmachine |grep -q 'mips.*el-.*' && echo -EB) 92cflags-$(CONFIG_CPU_BIG_ENDIAN) += $(shell $(CC) -dumpmachine |grep -q 'mips.*el-.*' && echo -EB -D__MIPSEB__)
109cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += $(shell $(CC) -dumpmachine |grep -q 'mips.*el-.*' || echo -EL) 93cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += $(shell $(CC) -dumpmachine |grep -q 'mips.*el-.*' || echo -EL -D__MIPSEL__)
110 94
111cflags-$(CONFIG_SB1XXX_CORELIS) += $(call cc-option,-mno-sched-prolog) \ 95cflags-$(CONFIG_SB1XXX_CORELIS) += $(call cc-option,-mno-sched-prolog) \
112 -fno-omit-frame-pointer 96 -fno-omit-frame-pointer
113 97
114# 98#
115# Use: $(call set_gccflags,<cpu0>,<isa0>,<cpu1>,<isa1>,<isa2>)
116#
117# <cpu0>,<isa0> -- preferred CPU and ISA designations (may require
118# recent tools)
119# <cpu1>,<isa1> -- fallback CPU and ISA designations (have to work
120# with up to the oldest supported tools)
121# <isa2> -- an ISA designation used as an ABI selector for
122# gcc versions that do not support "-mabi=32"
123# (depending on the CPU type, either "mips1" or
124# "mips2")
125#
126set_gccflags = $(shell \
127while :; do \
128 cpu=$(1); isa=-$(2); \
129 for gcc_opt in -march= -mcpu=; do \
130 $(CC) $$gcc_opt$$cpu $$isa -S -o /dev/null \
131 -xc /dev/null > /dev/null 2>&1 && \
132 break 2; \
133 done; \
134 cpu=$(3); isa=-$(4); \
135 for gcc_opt in -march= -mcpu=; do \
136 $(CC) $$gcc_opt$$cpu $$isa -S -o /dev/null \
137 -xc /dev/null > /dev/null 2>&1 && \
138 break 2; \
139 done; \
140 break; \
141done; \
142gcc_abi=-mabi=$(gcc-abi); gcc_cpu=$$cpu; \
143if $(CC) $$gcc_abi -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then \
144 gcc_isa=$$isa; \
145else \
146 gcc_abi=; gcc_isa=-$(5); \
147fi; \
148gas_abi=-Wa,-$(gcc-abi); gas_cpu=$$cpu; gas_isa=-Wa,$$isa; \
149while :; do \
150 for gas_opt in -Wa,-march= -Wa,-mcpu=; do \
151 $(CC) $$gas_abi $$gas_opt$$cpu $$gas_isa -Wa,-Z -c \
152 -o /dev/null -xassembler /dev/null > /dev/null 2>&1 && \
153 break 2; \
154 done; \
155 gas_abi=; gas_opt=; gas_cpu=; gas_isa=; \
156 break; \
157done; \
158if test "$(gcc-abi)" != "$(gas-abi)"; then \
159 gas_abi="-Wa,-$(gas-abi) -Wa,-mgp$(gcc-abi)"; \
160fi; \
161if test "$$gcc_opt" = -march= && test -n "$$gcc_abi"; then \
162 $(CC) $$gcc_abi $$gcc_opt$$gcc_cpu -S -o /dev/null \
163 -xc /dev/null > /dev/null 2>&1 && \
164 gcc_isa=; \
165fi; \
166echo $$gcc_abi $$gcc_opt$$gcc_cpu $$gcc_isa $$gas_abi $$gas_opt$$gas_cpu $$gas_isa)
167
168#
169# CPU-dependent compiler/assembler options for optimization. 99# CPU-dependent compiler/assembler options for optimization.
170# 100#
171cflags-$(CONFIG_CPU_R3000) += \ 101cflags-$(CONFIG_CPU_R3000) += -march=r3000
172 $(call set_gccflags,r3000,mips1,r3000,mips1,mips1) 102cflags-$(CONFIG_CPU_TX39XX) += -march=r3900
173CHECKFLAGS-$(CONFIG_CPU_R3000) += -D_MIPS_ISA=_MIPS_ISA_MIPS1 103cflags-$(CONFIG_CPU_R6000) += -march=r6000 -Wa,--trap
174 104cflags-$(CONFIG_CPU_R4300) += -march=r4300 -Wa,--trap
175cflags-$(CONFIG_CPU_TX39XX) += \ 105cflags-$(CONFIG_CPU_VR41XX) += -march=r4100 -Wa,--trap
176 $(call set_gccflags,r3900,mips1,r3000,mips1,mips1) 106cflags-$(CONFIG_CPU_R4X00) += -march=r4600 -Wa,--trap
177CHECKFLAGS-$(CONFIG_CPU_TX39XX) += -D_MIPS_ISA=_MIPS_ISA_MIPS1 107cflags-$(CONFIG_CPU_TX49XX) += -march=r4600 -Wa,--trap
178 108cflags-$(CONFIG_CPU_MIPS32_R1) += $(call cc-option,-march=mips32,-mips2 -mtune=r4600) \
179cflags-$(CONFIG_CPU_R6000) += \ 109 -Wa,-mips32 -Wa,--trap
180 $(call set_gccflags,r6000,mips2,r6000,mips2,mips2) \ 110cflags-$(CONFIG_CPU_MIPS32_R2) += $(call cc-option,-march=mips32r2,-mips2 -mtune=r4600) \
181 -Wa,--trap 111 -Wa,-mips32r2 -Wa,--trap
182CHECKFLAGS-$(CONFIG_CPU_R6000) += -D_MIPS_ISA=_MIPS_ISA_MIPS2 112cflags-$(CONFIG_CPU_MIPS64_R1) += $(call cc-option,-march=mips64,-mips2 -mtune=r4600) \
183 113 -Wa,-mips64 -Wa,--trap
184cflags-$(CONFIG_CPU_R4300) += \ 114cflags-$(CONFIG_CPU_MIPS64_R2) += $(call cc-option,-march=mips64r2,-mips2 -mtune=r4600 ) \
185 $(call set_gccflags,r4300,mips3,r4300,mips3,mips2) \ 115 -Wa,-mips64r2 -Wa,--trap
186 -Wa,--trap 116cflags-$(CONFIG_CPU_R5000) += -march=r5000 -Wa,--trap
187CHECKFLAGS-$(CONFIG_CPU_R4300) += -D_MIPS_ISA=_MIPS_ISA_MIPS3 117cflags-$(CONFIG_CPU_R5432) += $(call cc-options,-march=r5400,-march=r5000) \
188
189cflags-$(CONFIG_CPU_VR41XX) += \
190 $(call set_gccflags,r4100,mips3,r4600,mips3,mips2) \
191 -Wa,--trap
192CHECKFLAGS-$(CONFIG_CPU_VR41XX) += -D_MIPS_ISA=_MIPS_ISA_MIPS3
193
194cflags-$(CONFIG_CPU_R4X00) += \
195 $(call set_gccflags,r4600,mips3,r4600,mips3,mips2) \
196 -Wa,--trap
197CHECKFLAGS-$(CONFIG_CPU_R4X00) += -D_MIPS_ISA=_MIPS_ISA_MIPS3
198
199cflags-$(CONFIG_CPU_TX49XX) += \
200 $(call set_gccflags,r4600,mips3,r4600,mips3,mips2) \
201 -Wa,--trap 118 -Wa,--trap
202CHECKFLAGS-$(CONFIG_CPU_TX49XX) += -D_MIPS_ISA=_MIPS_ISA_MIPS3 119cflags-$(CONFIG_CPU_NEVADA) += $(call cc-options,-march=rm5200,-march=r5000) \
203
204cflags-$(CONFIG_CPU_MIPS32_R1) += \
205 $(call set_gccflags,mips32,mips32,r4600,mips3,mips2) \
206 -Wa,--trap
207CHECKFLAGS-$(CONFIG_CPU_MIPS32_R1) += -D_MIPS_ISA=_MIPS_ISA_MIPS32
208
209cflags-$(CONFIG_CPU_MIPS32_R2) += \
210 $(call set_gccflags,mips32r2,mips32r2,r4600,mips3,mips2) \
211 -Wa,--trap 120 -Wa,--trap
212CHECKFLAGS-$(CONFIG_CPU_MIPS32_R2) += -D_MIPS_ISA=_MIPS_ISA_MIPS32 121cflags-$(CONFIG_CPU_RM7000) += $(call cc-option,-march=rm7000,-march=r5000) \
213
214cflags-$(CONFIG_CPU_MIPS64_R1) += \
215 $(call set_gccflags,mips64,mips64,r4600,mips3,mips2) \
216 -Wa,--trap 122 -Wa,--trap
217CHECKFLAGS-$(CONFIG_CPU_MIPS64_R1) += -D_MIPS_ISA=_MIPS_ISA_MIPS64 123cflags-$(CONFIG_CPU_RM9000) += $(call cc-option,-march=rm9000,-march=r5000) \
218
219cflags-$(CONFIG_CPU_MIPS64_R2) += \
220 $(call set_gccflags,mips64r2,mips64r2,r4600,mips3,mips2) \
221 -Wa,--trap 124 -Wa,--trap
222CHECKFLAGS-$(CONFIG_CPU_MIPS64_R2) += -D_MIPS_ISA=_MIPS_ISA_MIPS64 125cflags-$(CONFIG_CPU_SB1) += $(call cc-option,-march=sb1,-march=r5000) \
223
224cflags-$(CONFIG_CPU_R5000) += \
225 $(call set_gccflags,r5000,mips4,r5000,mips4,mips2) \
226 -Wa,--trap 126 -Wa,--trap
227CHECKFLAGS-$(CONFIG_CPU_R5000) += -D_MIPS_ISA=_MIPS_ISA_MIPS4 127cflags-$(CONFIG_CPU_R8000) += -march=r8000 -Wa,--trap
228 128cflags-$(CONFIG_CPU_R10000) += $(call cc-option,-march=r10000,-march=r8000) \
229cflags-$(CONFIG_CPU_R5432) += \
230 $(call set_gccflags,r5400,mips4,r5000,mips4,mips2) \
231 -Wa,--trap 129 -Wa,--trap
232CHECKFLAGS-$(CONFIG_CPU_R5432) += -D_MIPS_ISA=_MIPS_ISA_MIPS4
233
234cflags-$(CONFIG_CPU_NEVADA) += \
235 $(call set_gccflags,rm5200,mips4,r5000,mips4,mips2) \
236 -Wa,--trap
237CHECKFLAGS-$(CONFIG_CPU_NEVADA) += -D_MIPS_ISA=_MIPS_ISA_MIPS4
238
239cflags-$(CONFIG_CPU_RM7000) += \
240 $(call set_gccflags,rm7000,mips4,r5000,mips4,mips2) \
241 -Wa,--trap
242CHECKFLAGS-$(CONFIG_CPU_RM7000) += -D_MIPS_ISA=_MIPS_ISA_MIPS4
243
244cflags-$(CONFIG_CPU_RM9000) += \
245 $(call set_gccflags,rm9000,mips4,r5000,mips4,mips2) \
246 -Wa,--trap
247CHECKFLAGS-$(CONFIG_CPU_RM9000) += -D_MIPS_ISA=_MIPS_ISA_MIPS4
248
249
250cflags-$(CONFIG_CPU_SB1) += \
251 $(call set_gccflags,sb1,mips64,r5000,mips4,mips2) \
252 -Wa,--trap
253CHECKFLAGS-$(CONFIG_CPU_SB1) += -D_MIPS_ISA=_MIPS_ISA_MIPS64
254
255cflags-$(CONFIG_CPU_R8000) += \
256 $(call set_gccflags,r8000,mips4,r8000,mips4,mips2) \
257 -Wa,--trap
258CHECKFLAGS-$(CONFIG_CPU_R8000) += -D_MIPS_ISA=_MIPS_ISA_MIPS4
259
260cflags-$(CONFIG_CPU_R10000) += \
261 $(call set_gccflags,r10000,mips4,r8000,mips4,mips2) \
262 -Wa,--trap
263CHECKFLAGS-$(CONFIG_CPU_R10000) += -D_MIPS_ISA=_MIPS_ISA_MIPS4
264 130
265ifdef CONFIG_CPU_SB1 131ifdef CONFIG_CPU_SB1
266ifdef CONFIG_SB1_PASS_1_WORKAROUNDS 132ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
@@ -630,7 +496,6 @@ endif
630ifdef CONFIG_SGI_IP27 496ifdef CONFIG_SGI_IP27
631core-$(CONFIG_SGI_IP27) += arch/mips/sgi-ip27/ 497core-$(CONFIG_SGI_IP27) += arch/mips/sgi-ip27/
632cflags-$(CONFIG_SGI_IP27) += -Iinclude/asm-mips/mach-ip27 498cflags-$(CONFIG_SGI_IP27) += -Iinclude/asm-mips/mach-ip27
633ifdef CONFIG_BUILD_ELF64
634ifdef CONFIG_MAPPED_KERNEL 499ifdef CONFIG_MAPPED_KERNEL
635load-$(CONFIG_SGI_IP27) += 0xc00000004001c000 500load-$(CONFIG_SGI_IP27) += 0xc00000004001c000
636OBJCOPYFLAGS := --change-addresses=0x3fffffff80000000 501OBJCOPYFLAGS := --change-addresses=0x3fffffff80000000
@@ -639,16 +504,6 @@ else
639load-$(CONFIG_SGI_IP27) += 0xa80000000001c000 504load-$(CONFIG_SGI_IP27) += 0xa80000000001c000
640OBJCOPYFLAGS := --change-addresses=0x57ffffff80000000 505OBJCOPYFLAGS := --change-addresses=0x57ffffff80000000
641endif 506endif
642else
643ifdef CONFIG_MAPPED_KERNEL
644load-$(CONFIG_SGI_IP27) += 0xffffffffc001c000
645OBJCOPYFLAGS := --change-addresses=0xc000000080000000
646dataoffset-$(CONFIG_SGI_IP27) += 0x01000000
647else
648load-$(CONFIG_SGI_IP27) += 0xffffffff8001c000
649OBJCOPYFLAGS := --change-addresses=0xa800000080000000
650endif
651endif
652endif 507endif
653 508
654# 509#
@@ -757,6 +612,12 @@ CFLAGS += $(cflags-y)
757 612
758LDFLAGS += -m $(ld-emul) 613LDFLAGS += -m $(ld-emul)
759 614
615ifdef CONFIG_MIPS
616CHECKFLAGS += $(shell $(CC) $(CFLAGS) -dM -E -xc /dev/null | \
617 egrep -vw '__GNUC_(MAJOR|MINOR|PATCHLEVEL)__' | \
618 sed -e 's/^\#define /-D/' -e 's/ /="/' -e 's/$$/"/')
619endif
620
760OBJCOPYFLAGS += --remove-section=.reginfo 621OBJCOPYFLAGS += --remove-section=.reginfo
761 622
762# 623#
diff --git a/arch/mips/au1000/common/cputable.c b/arch/mips/au1000/common/cputable.c
index 4dbde82c8215..d8df5fdb045f 100644
--- a/arch/mips/au1000/common/cputable.c
+++ b/arch/mips/au1000/common/cputable.c
@@ -38,7 +38,7 @@ struct cpu_spec cpu_specs[] = {
38 { 0xffffffff, 0x02030204, "Au1100 BE", 0, 1 }, 38 { 0xffffffff, 0x02030204, "Au1100 BE", 0, 1 },
39 { 0xffffffff, 0x03030200, "Au1550 AA", 0, 1 }, 39 { 0xffffffff, 0x03030200, "Au1550 AA", 0, 1 },
40 { 0xffffffff, 0x04030200, "Au1200 AB", 0, 0 }, 40 { 0xffffffff, 0x04030200, "Au1200 AB", 0, 0 },
41 { 0xffffffff, 0x04030201, "Au1200 AC", 0, 1 }, 41 { 0xffffffff, 0x04030201, "Au1200 AC", 1, 0 },
42 { 0x00000000, 0x00000000, "Unknown Au1xxx", 1, 0 }, 42 { 0x00000000, 0x00000000, "Unknown Au1xxx", 1, 0 },
43}; 43};
44 44
diff --git a/arch/mips/au1000/common/dbdma.c b/arch/mips/au1000/common/dbdma.c
index d00e8247d6c2..6ee090bd86c9 100644
--- a/arch/mips/au1000/common/dbdma.c
+++ b/arch/mips/au1000/common/dbdma.c
@@ -214,7 +214,7 @@ au1xxx_ddma_add_device(dbdev_tab_t *dev)
214 if ( NULL != p ) 214 if ( NULL != p )
215 { 215 {
216 memcpy(p, dev, sizeof(dbdev_tab_t)); 216 memcpy(p, dev, sizeof(dbdev_tab_t));
217 p->dev_id = DSCR_DEV2CUSTOM_ID(new_id,dev->dev_id); 217 p->dev_id = DSCR_DEV2CUSTOM_ID(new_id,dev->dev_id);
218 ret = p->dev_id; 218 ret = p->dev_id;
219 new_id++; 219 new_id++;
220#if 0 220#if 0
@@ -260,7 +260,7 @@ au1xxx_dbdma_chan_alloc(u32 srcid, u32 destid,
260 spin_lock_irqsave(&au1xxx_dbdma_spin_lock, flags); 260 spin_lock_irqsave(&au1xxx_dbdma_spin_lock, flags);
261 if (!(stp->dev_flags & DEV_FLAGS_INUSE) || 261 if (!(stp->dev_flags & DEV_FLAGS_INUSE) ||
262 (stp->dev_flags & DEV_FLAGS_ANYUSE)) { 262 (stp->dev_flags & DEV_FLAGS_ANYUSE)) {
263 /* Got source */ 263 /* Got source */
264 stp->dev_flags |= DEV_FLAGS_INUSE; 264 stp->dev_flags |= DEV_FLAGS_INUSE;
265 if (!(dtp->dev_flags & DEV_FLAGS_INUSE) || 265 if (!(dtp->dev_flags & DEV_FLAGS_INUSE) ||
266 (dtp->dev_flags & DEV_FLAGS_ANYUSE)) { 266 (dtp->dev_flags & DEV_FLAGS_ANYUSE)) {
diff --git a/arch/mips/au1000/common/dma.c b/arch/mips/au1000/common/dma.c
index 1905c6b104f2..1d82f2277517 100644
--- a/arch/mips/au1000/common/dma.c
+++ b/arch/mips/au1000/common/dma.c
@@ -174,7 +174,7 @@ int request_au1000_dma(int dev_id, const char *dev_str,
174 return -EINVAL; 174 return -EINVAL;
175#else 175#else
176 if (dev_id < 0 || dev_id >= DMA_NUM_DEV) 176 if (dev_id < 0 || dev_id >= DMA_NUM_DEV)
177 return -EINVAL; 177 return -EINVAL;
178#endif 178#endif
179 179
180 for (i = 0; i < NUM_AU1000_DMA_CHANNELS; i++) { 180 for (i = 0; i < NUM_AU1000_DMA_CHANNELS; i++) {
diff --git a/arch/mips/au1000/common/platform.c b/arch/mips/au1000/common/platform.c
index 48d3f54f88f8..32702e5fbf67 100644
--- a/arch/mips/au1000/common/platform.c
+++ b/arch/mips/au1000/common/platform.c
@@ -20,7 +20,7 @@
20static struct resource au1xxx_usb_ohci_resources[] = { 20static struct resource au1xxx_usb_ohci_resources[] = {
21 [0] = { 21 [0] = {
22 .start = USB_OHCI_BASE, 22 .start = USB_OHCI_BASE,
23 .end = USB_OHCI_BASE + USB_OHCI_LEN, 23 .end = USB_OHCI_BASE + USB_OHCI_LEN - 1,
24 .flags = IORESOURCE_MEM, 24 .flags = IORESOURCE_MEM,
25 }, 25 },
26 [1] = { 26 [1] = {
@@ -264,7 +264,7 @@ static struct resource smc91x_resources[] = {
264 264
265static struct platform_device smc91x_device = { 265static struct platform_device smc91x_device = {
266 .name = "smc91x", 266 .name = "smc91x",
267 .id = -1, 267 .id = -1,
268 .num_resources = ARRAY_SIZE(smc91x_resources), 268 .num_resources = ARRAY_SIZE(smc91x_resources),
269 .resource = smc91x_resources, 269 .resource = smc91x_resources,
270}; 270};
@@ -278,9 +278,7 @@ static struct platform_device *au1xxx_platform_devices[] __initdata = {
278 &au1100_lcd_device, 278 &au1100_lcd_device,
279#endif 279#endif
280#ifdef CONFIG_SOC_AU1200 280#ifdef CONFIG_SOC_AU1200
281#if 0 /* fixme */
282 &au1xxx_usb_ehci_device, 281 &au1xxx_usb_ehci_device,
283#endif
284 &au1xxx_usb_gdt_device, 282 &au1xxx_usb_gdt_device,
285 &au1xxx_usb_otg_device, 283 &au1xxx_usb_otg_device,
286 &au1200_lcd_device, 284 &au1200_lcd_device,
@@ -288,7 +286,7 @@ static struct platform_device *au1xxx_platform_devices[] __initdata = {
288 &au1xxx_mmc_device, 286 &au1xxx_mmc_device,
289#endif 287#endif
290#ifdef CONFIG_MIPS_DB1200 288#ifdef CONFIG_MIPS_DB1200
291 &smc91x_device, 289 &smc91x_device,
292#endif 290#endif
293}; 291};
294 292
diff --git a/arch/mips/au1000/common/setup.c b/arch/mips/au1000/common/setup.c
index eb155c071aa6..1080558c8100 100644
--- a/arch/mips/au1000/common/setup.c
+++ b/arch/mips/au1000/common/setup.c
@@ -90,7 +90,7 @@ void __init plat_setup(void)
90 else { 90 else {
91 /* Clear to obtain best system bus performance */ 91 /* Clear to obtain best system bus performance */
92 clear_c0_config(1<<19); /* Clear Config[OD] */ 92 clear_c0_config(1<<19); /* Clear Config[OD] */
93 } 93 }
94 94
95 argptr = prom_getcmdline(); 95 argptr = prom_getcmdline();
96 96
diff --git a/arch/mips/au1000/common/time.c b/arch/mips/au1000/common/time.c
index 883d3f3d8c53..f85f1524b366 100644
--- a/arch/mips/au1000/common/time.c
+++ b/arch/mips/au1000/common/time.c
@@ -359,7 +359,7 @@ static unsigned long do_fast_cp0_gettimeoffset(void)
359 : "hi", "lo", GCC_REG_ACCUM); 359 : "hi", "lo", GCC_REG_ACCUM);
360 360
361 /* 361 /*
362 * Due to possible jiffies inconsistencies, we need to check 362 * Due to possible jiffies inconsistencies, we need to check
363 * the result so that we'll get a timer that is monotonic. 363 * the result so that we'll get a timer that is monotonic.
364 */ 364 */
365 if (res >= USECS_PER_JIFFY) 365 if (res >= USECS_PER_JIFFY)
diff --git a/arch/mips/cobalt/Kconfig b/arch/mips/cobalt/Kconfig
new file mode 100644
index 000000000000..7c42b088d16c
--- /dev/null
+++ b/arch/mips/cobalt/Kconfig
@@ -0,0 +1,7 @@
1config EARLY_PRINTK
2 bool "Early console support"
3 depends on MIPS_COBALT
4 help
5 Provide early console support by direct access to the
6 on board UART. The UART must have been previously
7 initialised by the boot loader.
diff --git a/arch/mips/cobalt/Makefile b/arch/mips/cobalt/Makefile
index 3b6b7579d1de..720e757b2b64 100644
--- a/arch/mips/cobalt/Makefile
+++ b/arch/mips/cobalt/Makefile
@@ -4,4 +4,6 @@
4 4
5obj-y := irq.o int-handler.o reset.o setup.o 5obj-y := irq.o int-handler.o reset.o setup.o
6 6
7obj-$(CONFIG_EARLY_PRINTK) += console.o
8
7EXTRA_AFLAGS := $(CFLAGS) 9EXTRA_AFLAGS := $(CFLAGS)
diff --git a/arch/mips/cobalt/console.c b/arch/mips/cobalt/console.c
new file mode 100644
index 000000000000..45c2d27c7564
--- /dev/null
+++ b/arch/mips/cobalt/console.c
@@ -0,0 +1,43 @@
1/*
2 * (C) P. Horton 2006
3 */
4
5#include <linux/config.h>
6#include <linux/init.h>
7#include <linux/kernel.h>
8#include <linux/console.h>
9#include <linux/serial_reg.h>
10#include <asm/addrspace.h>
11#include <asm/mach-cobalt/cobalt.h>
12
13static void putchar(int c)
14{
15 if(c == '\n')
16 putchar('\r');
17
18 while(!(COBALT_UART[UART_LSR] & UART_LSR_THRE))
19 ;
20
21 COBALT_UART[UART_TX] = c;
22}
23
24static void cons_write(struct console *c, const char *s, unsigned n)
25{
26 while(n-- && *s)
27 putchar(*s++);
28}
29
30static struct console cons_info =
31{
32 .name = "uart",
33 .write = cons_write,
34 .flags = CON_PRINTBUFFER | CON_BOOT,
35 .index = -1,
36};
37
38void __init cobalt_early_console(void)
39{
40 register_console(&cons_info);
41
42 printk("Cobalt: early console registered\n");
43}
diff --git a/arch/mips/cobalt/setup.c b/arch/mips/cobalt/setup.c
index b9713a723053..4f9ea1210023 100644
--- a/arch/mips/cobalt/setup.c
+++ b/arch/mips/cobalt/setup.c
@@ -31,6 +31,7 @@
31extern void cobalt_machine_restart(char *command); 31extern void cobalt_machine_restart(char *command);
32extern void cobalt_machine_halt(void); 32extern void cobalt_machine_halt(void);
33extern void cobalt_machine_power_off(void); 33extern void cobalt_machine_power_off(void);
34extern void cobalt_early_console(void);
34 35
35int cobalt_board_id; 36int cobalt_board_id;
36 37
@@ -109,14 +110,6 @@ void __init plat_setup(void)
109 /* I/O port resource must include UART and LCD/buttons */ 110 /* I/O port resource must include UART and LCD/buttons */
110 ioport_resource.end = 0x0fffffff; 111 ioport_resource.end = 0x0fffffff;
111 112
112 /*
113 * This is a prom style console. We just poke at the
114 * UART to make it talk.
115 * Only use this console if you really screw up and can't
116 * get to the stage of setting up a real serial console.
117 */
118 /*ns16550_setup_console();*/
119
120 /* request I/O space for devices used on all i[345]86 PCs */ 113 /* request I/O space for devices used on all i[345]86 PCs */
121 for (i = 0; i < COBALT_IO_RESOURCES; i++) 114 for (i = 0; i < COBALT_IO_RESOURCES; i++)
122 request_resource(&ioport_resource, cobalt_io_resources + i); 115 request_resource(&ioport_resource, cobalt_io_resources + i);
@@ -136,6 +129,10 @@ void __init plat_setup(void)
136#ifdef CONFIG_SERIAL_8250 129#ifdef CONFIG_SERIAL_8250
137 if (cobalt_board_id > COBALT_BRD_ID_RAQ1) { 130 if (cobalt_board_id > COBALT_BRD_ID_RAQ1) {
138 131
132#ifdef CONFIG_EARLY_PRINTK
133 cobalt_early_console();
134#endif
135
139 uart.line = 0; 136 uart.line = 0;
140 uart.type = PORT_UNKNOWN; 137 uart.type = PORT_UNKNOWN;
141 uart.uartclk = 18432000; 138 uart.uartclk = 18432000;
diff --git a/arch/mips/configs/atlas_defconfig b/arch/mips/configs/atlas_defconfig
index 89c21572a59c..9e1ae953e966 100644
--- a/arch/mips/configs/atlas_defconfig
+++ b/arch/mips/configs/atlas_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:05:52 2005 4# Fri Jan 27 15:39:52 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -164,26 +164,28 @@ CONFIG_SYSVIPC=y
164# CONFIG_BSD_PROCESS_ACCT is not set 164# CONFIG_BSD_PROCESS_ACCT is not set
165CONFIG_SYSCTL=y 165CONFIG_SYSCTL=y
166# CONFIG_AUDIT is not set 166# CONFIG_AUDIT is not set
167CONFIG_HOTPLUG=y
168CONFIG_KOBJECT_UEVENT=y
169# CONFIG_IKCONFIG is not set 167# CONFIG_IKCONFIG is not set
170CONFIG_INITRAMFS_SOURCE="" 168CONFIG_INITRAMFS_SOURCE=""
169# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
171CONFIG_EMBEDDED=y 170CONFIG_EMBEDDED=y
172CONFIG_KALLSYMS=y 171CONFIG_KALLSYMS=y
173# CONFIG_KALLSYMS_EXTRA_PASS is not set 172# CONFIG_KALLSYMS_EXTRA_PASS is not set
173CONFIG_HOTPLUG=y
174CONFIG_PRINTK=y 174CONFIG_PRINTK=y
175CONFIG_BUG=y 175CONFIG_BUG=y
176CONFIG_ELF_CORE=y
176CONFIG_BASE_FULL=y 177CONFIG_BASE_FULL=y
177CONFIG_FUTEX=y 178CONFIG_FUTEX=y
178CONFIG_EPOLL=y 179CONFIG_EPOLL=y
179# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
180CONFIG_SHMEM=y 180CONFIG_SHMEM=y
181CONFIG_CC_ALIGN_FUNCTIONS=0 181CONFIG_CC_ALIGN_FUNCTIONS=0
182CONFIG_CC_ALIGN_LABELS=0 182CONFIG_CC_ALIGN_LABELS=0
183CONFIG_CC_ALIGN_LOOPS=0 183CONFIG_CC_ALIGN_LOOPS=0
184CONFIG_CC_ALIGN_JUMPS=0 184CONFIG_CC_ALIGN_JUMPS=0
185CONFIG_SLAB=y
185# CONFIG_TINY_SHMEM is not set 186# CONFIG_TINY_SHMEM is not set
186CONFIG_BASE_SMALL=0 187CONFIG_BASE_SMALL=0
188# CONFIG_SLOB is not set
187 189
188# 190#
189# Loadable module support 191# Loadable module support
@@ -335,6 +337,29 @@ CONFIG_BRIDGE_NETFILTER=y
335CONFIG_NETFILTER_NETLINK=m 337CONFIG_NETFILTER_NETLINK=m
336CONFIG_NETFILTER_NETLINK_QUEUE=m 338CONFIG_NETFILTER_NETLINK_QUEUE=m
337CONFIG_NETFILTER_NETLINK_LOG=m 339CONFIG_NETFILTER_NETLINK_LOG=m
340CONFIG_NETFILTER_XTABLES=m
341CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
342CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
343CONFIG_NETFILTER_XT_TARGET_MARK=m
344CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
345CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
346CONFIG_NETFILTER_XT_MATCH_COMMENT=m
347CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
348CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
349CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
350CONFIG_NETFILTER_XT_MATCH_DCCP=m
351CONFIG_NETFILTER_XT_MATCH_HELPER=m
352CONFIG_NETFILTER_XT_MATCH_LENGTH=m
353CONFIG_NETFILTER_XT_MATCH_LIMIT=m
354CONFIG_NETFILTER_XT_MATCH_MAC=m
355CONFIG_NETFILTER_XT_MATCH_MARK=m
356CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
357CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
358CONFIG_NETFILTER_XT_MATCH_REALM=m
359CONFIG_NETFILTER_XT_MATCH_SCTP=m
360CONFIG_NETFILTER_XT_MATCH_STATE=m
361CONFIG_NETFILTER_XT_MATCH_STRING=m
362CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
338 363
339# 364#
340# IP: Netfilter Configuration 365# IP: Netfilter Configuration
@@ -353,47 +378,30 @@ CONFIG_IP_NF_AMANDA=m
353CONFIG_IP_NF_PPTP=m 378CONFIG_IP_NF_PPTP=m
354CONFIG_IP_NF_QUEUE=m 379CONFIG_IP_NF_QUEUE=m
355CONFIG_IP_NF_IPTABLES=m 380CONFIG_IP_NF_IPTABLES=m
356CONFIG_IP_NF_MATCH_LIMIT=m
357CONFIG_IP_NF_MATCH_IPRANGE=m 381CONFIG_IP_NF_MATCH_IPRANGE=m
358CONFIG_IP_NF_MATCH_MAC=m
359CONFIG_IP_NF_MATCH_PKTTYPE=m
360CONFIG_IP_NF_MATCH_MARK=m
361CONFIG_IP_NF_MATCH_MULTIPORT=m 382CONFIG_IP_NF_MATCH_MULTIPORT=m
362CONFIG_IP_NF_MATCH_TOS=m 383CONFIG_IP_NF_MATCH_TOS=m
363CONFIG_IP_NF_MATCH_RECENT=m 384CONFIG_IP_NF_MATCH_RECENT=m
364CONFIG_IP_NF_MATCH_ECN=m 385CONFIG_IP_NF_MATCH_ECN=m
365CONFIG_IP_NF_MATCH_DSCP=m 386CONFIG_IP_NF_MATCH_DSCP=m
366CONFIG_IP_NF_MATCH_AH_ESP=m 387CONFIG_IP_NF_MATCH_AH_ESP=m
367CONFIG_IP_NF_MATCH_LENGTH=m
368CONFIG_IP_NF_MATCH_TTL=m 388CONFIG_IP_NF_MATCH_TTL=m
369CONFIG_IP_NF_MATCH_TCPMSS=m
370CONFIG_IP_NF_MATCH_HELPER=m
371CONFIG_IP_NF_MATCH_STATE=m
372CONFIG_IP_NF_MATCH_CONNTRACK=m
373CONFIG_IP_NF_MATCH_OWNER=m 389CONFIG_IP_NF_MATCH_OWNER=m
374CONFIG_IP_NF_MATCH_PHYSDEV=m
375CONFIG_IP_NF_MATCH_ADDRTYPE=m 390CONFIG_IP_NF_MATCH_ADDRTYPE=m
376CONFIG_IP_NF_MATCH_REALM=m
377CONFIG_IP_NF_MATCH_SCTP=m
378CONFIG_IP_NF_MATCH_DCCP=m
379CONFIG_IP_NF_MATCH_COMMENT=m
380CONFIG_IP_NF_MATCH_CONNMARK=m
381CONFIG_IP_NF_MATCH_CONNBYTES=m
382CONFIG_IP_NF_MATCH_HASHLIMIT=m 391CONFIG_IP_NF_MATCH_HASHLIMIT=m
383CONFIG_IP_NF_MATCH_STRING=m 392CONFIG_IP_NF_MATCH_POLICY=m
384CONFIG_IP_NF_FILTER=m 393CONFIG_IP_NF_FILTER=m
385CONFIG_IP_NF_TARGET_REJECT=m 394CONFIG_IP_NF_TARGET_REJECT=m
386CONFIG_IP_NF_TARGET_LOG=m 395CONFIG_IP_NF_TARGET_LOG=m
387CONFIG_IP_NF_TARGET_ULOG=m 396CONFIG_IP_NF_TARGET_ULOG=m
388CONFIG_IP_NF_TARGET_TCPMSS=m 397CONFIG_IP_NF_TARGET_TCPMSS=m
389CONFIG_IP_NF_TARGET_NFQUEUE=m
390CONFIG_IP_NF_NAT=m 398CONFIG_IP_NF_NAT=m
391CONFIG_IP_NF_NAT_NEEDED=y 399CONFIG_IP_NF_NAT_NEEDED=y
392CONFIG_IP_NF_TARGET_MASQUERADE=m 400CONFIG_IP_NF_TARGET_MASQUERADE=m
393CONFIG_IP_NF_TARGET_REDIRECT=m 401CONFIG_IP_NF_TARGET_REDIRECT=m
394CONFIG_IP_NF_TARGET_NETMAP=m 402CONFIG_IP_NF_TARGET_NETMAP=m
395CONFIG_IP_NF_TARGET_SAME=m 403CONFIG_IP_NF_TARGET_SAME=m
396CONFIG_IP_NF_NAT_SNMP_BASIC=m 404# CONFIG_IP_NF_NAT_SNMP_BASIC is not set
397CONFIG_IP_NF_NAT_IRC=m 405CONFIG_IP_NF_NAT_IRC=m
398CONFIG_IP_NF_NAT_FTP=m 406CONFIG_IP_NF_NAT_FTP=m
399CONFIG_IP_NF_NAT_TFTP=m 407CONFIG_IP_NF_NAT_TFTP=m
@@ -403,13 +411,9 @@ CONFIG_IP_NF_MANGLE=m
403CONFIG_IP_NF_TARGET_TOS=m 411CONFIG_IP_NF_TARGET_TOS=m
404CONFIG_IP_NF_TARGET_ECN=m 412CONFIG_IP_NF_TARGET_ECN=m
405CONFIG_IP_NF_TARGET_DSCP=m 413CONFIG_IP_NF_TARGET_DSCP=m
406CONFIG_IP_NF_TARGET_MARK=m
407CONFIG_IP_NF_TARGET_CLASSIFY=m
408CONFIG_IP_NF_TARGET_TTL=m 414CONFIG_IP_NF_TARGET_TTL=m
409CONFIG_IP_NF_TARGET_CONNMARK=m 415# CONFIG_IP_NF_TARGET_CLUSTERIP is not set
410CONFIG_IP_NF_TARGET_CLUSTERIP=m
411CONFIG_IP_NF_RAW=m 416CONFIG_IP_NF_RAW=m
412CONFIG_IP_NF_TARGET_NOTRACK=m
413CONFIG_IP_NF_ARPTABLES=m 417CONFIG_IP_NF_ARPTABLES=m
414CONFIG_IP_NF_ARPFILTER=m 418CONFIG_IP_NF_ARPFILTER=m
415CONFIG_IP_NF_ARP_MANGLE=m 419CONFIG_IP_NF_ARP_MANGLE=m
@@ -419,26 +423,20 @@ CONFIG_IP_NF_ARP_MANGLE=m
419# 423#
420CONFIG_IP6_NF_QUEUE=m 424CONFIG_IP6_NF_QUEUE=m
421CONFIG_IP6_NF_IPTABLES=m 425CONFIG_IP6_NF_IPTABLES=m
422CONFIG_IP6_NF_MATCH_LIMIT=m
423CONFIG_IP6_NF_MATCH_MAC=m
424CONFIG_IP6_NF_MATCH_RT=m 426CONFIG_IP6_NF_MATCH_RT=m
425CONFIG_IP6_NF_MATCH_OPTS=m 427CONFIG_IP6_NF_MATCH_OPTS=m
426CONFIG_IP6_NF_MATCH_FRAG=m 428CONFIG_IP6_NF_MATCH_FRAG=m
427CONFIG_IP6_NF_MATCH_HL=m 429CONFIG_IP6_NF_MATCH_HL=m
428CONFIG_IP6_NF_MATCH_MULTIPORT=m 430CONFIG_IP6_NF_MATCH_MULTIPORT=m
429CONFIG_IP6_NF_MATCH_OWNER=m 431CONFIG_IP6_NF_MATCH_OWNER=m
430CONFIG_IP6_NF_MATCH_MARK=m
431CONFIG_IP6_NF_MATCH_IPV6HEADER=m 432CONFIG_IP6_NF_MATCH_IPV6HEADER=m
432CONFIG_IP6_NF_MATCH_AHESP=m 433CONFIG_IP6_NF_MATCH_AHESP=m
433CONFIG_IP6_NF_MATCH_LENGTH=m
434CONFIG_IP6_NF_MATCH_EUI64=m 434CONFIG_IP6_NF_MATCH_EUI64=m
435CONFIG_IP6_NF_MATCH_PHYSDEV=m 435CONFIG_IP6_NF_MATCH_POLICY=m
436CONFIG_IP6_NF_FILTER=m 436CONFIG_IP6_NF_FILTER=m
437CONFIG_IP6_NF_TARGET_LOG=m 437CONFIG_IP6_NF_TARGET_LOG=m
438CONFIG_IP6_NF_TARGET_REJECT=m 438CONFIG_IP6_NF_TARGET_REJECT=m
439CONFIG_IP6_NF_TARGET_NFQUEUE=m
440CONFIG_IP6_NF_MANGLE=m 439CONFIG_IP6_NF_MANGLE=m
441CONFIG_IP6_NF_TARGET_MARK=m
442CONFIG_IP6_NF_TARGET_HL=m 440CONFIG_IP6_NF_TARGET_HL=m
443CONFIG_IP6_NF_RAW=m 441CONFIG_IP6_NF_RAW=m
444 442
@@ -494,6 +492,11 @@ CONFIG_IPDDP_ENCAP=y
494CONFIG_IPDDP_DECAP=y 492CONFIG_IPDDP_DECAP=y
495# CONFIG_X25 is not set 493# CONFIG_X25 is not set
496# CONFIG_LAPB is not set 494# CONFIG_LAPB is not set
495
496#
497# TIPC Configuration (EXPERIMENTAL)
498#
499# CONFIG_TIPC is not set
497CONFIG_NET_DIVERT=y 500CONFIG_NET_DIVERT=y
498# CONFIG_ECONET is not set 501# CONFIG_ECONET is not set
499# CONFIG_WAN_ROUTER is not set 502# CONFIG_WAN_ROUTER is not set
@@ -553,7 +556,6 @@ CONFIG_IEEE80211=m
553# CONFIG_IEEE80211_DEBUG is not set 556# CONFIG_IEEE80211_DEBUG is not set
554CONFIG_IEEE80211_CRYPT_WEP=m 557CONFIG_IEEE80211_CRYPT_WEP=m
555CONFIG_IEEE80211_CRYPT_CCMP=m 558CONFIG_IEEE80211_CRYPT_CCMP=m
556CONFIG_IEEE80211_CRYPT_TKIP=m
557 559
558# 560#
559# Device Drivers 561# Device Drivers
@@ -663,7 +665,7 @@ CONFIG_SCSI_LOGGING=y
663# SCSI Transport Attributes 665# SCSI Transport Attributes
664# 666#
665CONFIG_SCSI_SPI_ATTRS=y 667CONFIG_SCSI_SPI_ATTRS=y
666CONFIG_SCSI_FC_ATTRS=m 668CONFIG_SCSI_FC_ATTRS=y
667CONFIG_SCSI_ISCSI_ATTRS=m 669CONFIG_SCSI_ISCSI_ATTRS=m
668CONFIG_SCSI_SAS_ATTRS=m 670CONFIG_SCSI_SAS_ATTRS=m
669 671
@@ -696,13 +698,7 @@ CONFIG_SCSI_SYM53C8XX_MAX_TAGS=64
696# CONFIG_SCSI_IPR is not set 698# CONFIG_SCSI_IPR is not set
697# CONFIG_SCSI_QLOGIC_FC is not set 699# CONFIG_SCSI_QLOGIC_FC is not set
698# CONFIG_SCSI_QLOGIC_1280 is not set 700# CONFIG_SCSI_QLOGIC_1280 is not set
699CONFIG_SCSI_QLA2XXX=y 701# CONFIG_SCSI_QLA_FC is not set
700# CONFIG_SCSI_QLA21XX is not set
701# CONFIG_SCSI_QLA22XX is not set
702# CONFIG_SCSI_QLA2300 is not set
703# CONFIG_SCSI_QLA2322 is not set
704# CONFIG_SCSI_QLA6312 is not set
705# CONFIG_SCSI_QLA24XX is not set
706# CONFIG_SCSI_LPFC is not set 702# CONFIG_SCSI_LPFC is not set
707# CONFIG_SCSI_DC395x is not set 703# CONFIG_SCSI_DC395x is not set
708# CONFIG_SCSI_DC390T is not set 704# CONFIG_SCSI_DC390T is not set
@@ -785,6 +781,7 @@ CONFIG_MII=y
785# CONFIG_SUNGEM is not set 781# CONFIG_SUNGEM is not set
786# CONFIG_CASSINI is not set 782# CONFIG_CASSINI is not set
787# CONFIG_NET_VENDOR_3COM is not set 783# CONFIG_NET_VENDOR_3COM is not set
784# CONFIG_DM9000 is not set
788 785
789# 786#
790# Tulip family network device support 787# Tulip family network device support
@@ -824,6 +821,7 @@ CONFIG_LAN_SAA9730=y
824# CONFIG_R8169 is not set 821# CONFIG_R8169 is not set
825# CONFIG_SIS190 is not set 822# CONFIG_SIS190 is not set
826# CONFIG_SKGE is not set 823# CONFIG_SKGE is not set
824# CONFIG_SKY2 is not set
827# CONFIG_SK98LIN is not set 825# CONFIG_SK98LIN is not set
828# CONFIG_VIA_VELOCITY is not set 826# CONFIG_VIA_VELOCITY is not set
829# CONFIG_TIGON3 is not set 827# CONFIG_TIGON3 is not set
@@ -845,8 +843,6 @@ CONFIG_LAN_SAA9730=y
845# Wireless LAN (non-hamradio) 843# Wireless LAN (non-hamradio)
846# 844#
847# CONFIG_NET_RADIO is not set 845# CONFIG_NET_RADIO is not set
848# CONFIG_IPW_DEBUG is not set
849CONFIG_IPW2200=m
850 846
851# 847#
852# Wan interfaces 848# Wan interfaces
@@ -926,6 +922,7 @@ CONFIG_HW_CONSOLE=y
926CONFIG_SERIAL_8250=y 922CONFIG_SERIAL_8250=y
927CONFIG_SERIAL_8250_CONSOLE=y 923CONFIG_SERIAL_8250_CONSOLE=y
928CONFIG_SERIAL_8250_NR_UARTS=4 924CONFIG_SERIAL_8250_NR_UARTS=4
925CONFIG_SERIAL_8250_RUNTIME_UARTS=4
929# CONFIG_SERIAL_8250_EXTENDED is not set 926# CONFIG_SERIAL_8250_EXTENDED is not set
930 927
931# 928#
@@ -933,7 +930,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
933# 930#
934CONFIG_SERIAL_CORE=y 931CONFIG_SERIAL_CORE=y
935CONFIG_SERIAL_CORE_CONSOLE=y 932CONFIG_SERIAL_CORE_CONSOLE=y
936# CONFIG_SERIAL_JSM is not set
937CONFIG_UNIX98_PTYS=y 933CONFIG_UNIX98_PTYS=y
938CONFIG_LEGACY_PTYS=y 934CONFIG_LEGACY_PTYS=y
939CONFIG_LEGACY_PTY_COUNT=256 935CONFIG_LEGACY_PTY_COUNT=256
@@ -971,6 +967,12 @@ CONFIG_LEGACY_PTY_COUNT=256
971# CONFIG_I2C is not set 967# CONFIG_I2C is not set
972 968
973# 969#
970# SPI support
971#
972# CONFIG_SPI is not set
973# CONFIG_SPI_MASTER is not set
974
975#
974# Dallas's 1-wire bus 976# Dallas's 1-wire bus
975# 977#
976# CONFIG_W1 is not set 978# CONFIG_W1 is not set
@@ -1076,6 +1078,7 @@ CONFIG_XFS_QUOTA=y
1076CONFIG_XFS_SECURITY=y 1078CONFIG_XFS_SECURITY=y
1077CONFIG_XFS_POSIX_ACL=y 1079CONFIG_XFS_POSIX_ACL=y
1078# CONFIG_XFS_RT is not set 1080# CONFIG_XFS_RT is not set
1081# CONFIG_OCFS2_FS is not set
1079CONFIG_MINIX_FS=m 1082CONFIG_MINIX_FS=m
1080CONFIG_ROMFS_FS=m 1083CONFIG_ROMFS_FS=m
1081CONFIG_INOTIFY=y 1084CONFIG_INOTIFY=y
@@ -1118,6 +1121,7 @@ CONFIG_SYSFS=y
1118# CONFIG_HUGETLB_PAGE is not set 1121# CONFIG_HUGETLB_PAGE is not set
1119CONFIG_RAMFS=y 1122CONFIG_RAMFS=y
1120CONFIG_RELAYFS_FS=m 1123CONFIG_RELAYFS_FS=m
1124# CONFIG_CONFIGFS_FS is not set
1121 1125
1122# 1126#
1123# Miscellaneous filesystems 1127# Miscellaneous filesystems
@@ -1225,6 +1229,7 @@ CONFIG_NLS_UTF8=m
1225# Kernel hacking 1229# Kernel hacking
1226# 1230#
1227# CONFIG_PRINTK_TIME is not set 1231# CONFIG_PRINTK_TIME is not set
1232# CONFIG_MAGIC_SYSRQ is not set
1228# CONFIG_DEBUG_KERNEL is not set 1233# CONFIG_DEBUG_KERNEL is not set
1229CONFIG_LOG_BUF_SHIFT=14 1234CONFIG_LOG_BUF_SHIFT=14
1230CONFIG_CROSSCOMPILE=y 1235CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/bigsur_defconfig b/arch/mips/configs/bigsur_defconfig
index 6fd353779813..32984100a75e 100644
--- a/arch/mips/configs/bigsur_defconfig
+++ b/arch/mips/configs/bigsur_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:05:54 2005 4# Fri Jan 27 15:39:53 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -169,29 +169,31 @@ CONFIG_SYSVIPC=y
169# CONFIG_BSD_PROCESS_ACCT is not set 169# CONFIG_BSD_PROCESS_ACCT is not set
170CONFIG_SYSCTL=y 170CONFIG_SYSCTL=y
171# CONFIG_AUDIT is not set 171# CONFIG_AUDIT is not set
172# CONFIG_HOTPLUG is not set
173CONFIG_KOBJECT_UEVENT=y
174CONFIG_IKCONFIG=y 172CONFIG_IKCONFIG=y
175CONFIG_IKCONFIG_PROC=y 173CONFIG_IKCONFIG_PROC=y
176# CONFIG_CPUSETS is not set 174# CONFIG_CPUSETS is not set
177CONFIG_INITRAMFS_SOURCE="" 175CONFIG_INITRAMFS_SOURCE=""
176# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
178CONFIG_EMBEDDED=y 177CONFIG_EMBEDDED=y
179CONFIG_KALLSYMS=y 178CONFIG_KALLSYMS=y
180# CONFIG_KALLSYMS_ALL is not set 179# CONFIG_KALLSYMS_ALL is not set
181# CONFIG_KALLSYMS_EXTRA_PASS is not set 180# CONFIG_KALLSYMS_EXTRA_PASS is not set
181# CONFIG_HOTPLUG is not set
182CONFIG_PRINTK=y 182CONFIG_PRINTK=y
183CONFIG_BUG=y 183CONFIG_BUG=y
184CONFIG_ELF_CORE=y
184CONFIG_BASE_FULL=y 185CONFIG_BASE_FULL=y
185CONFIG_FUTEX=y 186CONFIG_FUTEX=y
186CONFIG_EPOLL=y 187CONFIG_EPOLL=y
187# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
188CONFIG_SHMEM=y 188CONFIG_SHMEM=y
189CONFIG_CC_ALIGN_FUNCTIONS=0 189CONFIG_CC_ALIGN_FUNCTIONS=0
190CONFIG_CC_ALIGN_LABELS=0 190CONFIG_CC_ALIGN_LABELS=0
191CONFIG_CC_ALIGN_LOOPS=0 191CONFIG_CC_ALIGN_LOOPS=0
192CONFIG_CC_ALIGN_JUMPS=0 192CONFIG_CC_ALIGN_JUMPS=0
193CONFIG_SLAB=y
193# CONFIG_TINY_SHMEM is not set 194# CONFIG_TINY_SHMEM is not set
194CONFIG_BASE_SMALL=0 195CONFIG_BASE_SMALL=0
196# CONFIG_SLOB is not set
195 197
196# 198#
197# Loadable module support 199# Loadable module support
@@ -247,7 +249,6 @@ CONFIG_MMU=y
247# 249#
248CONFIG_BINFMT_ELF=y 250CONFIG_BINFMT_ELF=y
249# CONFIG_BINFMT_MISC is not set 251# CONFIG_BINFMT_MISC is not set
250CONFIG_BUILD_ELF64=y
251CONFIG_MIPS32_COMPAT=y 252CONFIG_MIPS32_COMPAT=y
252CONFIG_COMPAT=y 253CONFIG_COMPAT=y
253CONFIG_MIPS32_O32=y 254CONFIG_MIPS32_O32=y
@@ -309,6 +310,11 @@ CONFIG_TCP_CONG_BIC=y
309# CONFIG_ATALK is not set 310# CONFIG_ATALK is not set
310# CONFIG_X25 is not set 311# CONFIG_X25 is not set
311# CONFIG_LAPB is not set 312# CONFIG_LAPB is not set
313
314#
315# TIPC Configuration (EXPERIMENTAL)
316#
317# CONFIG_TIPC is not set
312# CONFIG_NET_DIVERT is not set 318# CONFIG_NET_DIVERT is not set
313# CONFIG_ECONET is not set 319# CONFIG_ECONET is not set
314# CONFIG_WAN_ROUTER is not set 320# CONFIG_WAN_ROUTER is not set
@@ -457,6 +463,7 @@ CONFIG_MII=y
457# CONFIG_SUNGEM is not set 463# CONFIG_SUNGEM is not set
458# CONFIG_CASSINI is not set 464# CONFIG_CASSINI is not set
459# CONFIG_NET_VENDOR_3COM is not set 465# CONFIG_NET_VENDOR_3COM is not set
466# CONFIG_DM9000 is not set
460 467
461# 468#
462# Tulip family network device support 469# Tulip family network device support
@@ -478,6 +485,7 @@ CONFIG_MII=y
478CONFIG_NET_SB1250_MAC=y 485CONFIG_NET_SB1250_MAC=y
479# CONFIG_SIS190 is not set 486# CONFIG_SIS190 is not set
480# CONFIG_SKGE is not set 487# CONFIG_SKGE is not set
488# CONFIG_SKY2 is not set
481# CONFIG_SK98LIN is not set 489# CONFIG_SK98LIN is not set
482# CONFIG_TIGON3 is not set 490# CONFIG_TIGON3 is not set
483# CONFIG_BNX2 is not set 491# CONFIG_BNX2 is not set
@@ -543,12 +551,15 @@ CONFIG_SERIO_RAW=m
543# 551#
544# CONFIG_VT is not set 552# CONFIG_VT is not set
545CONFIG_SERIAL_NONSTANDARD=y 553CONFIG_SERIAL_NONSTANDARD=y
554# CONFIG_COMPUTONE is not set
546# CONFIG_ROCKETPORT is not set 555# CONFIG_ROCKETPORT is not set
547# CONFIG_CYCLADES is not set 556# CONFIG_CYCLADES is not set
548# CONFIG_DIGIEPCA is not set 557# CONFIG_DIGIEPCA is not set
558# CONFIG_MOXA_INTELLIO is not set
549# CONFIG_MOXA_SMARTIO is not set 559# CONFIG_MOXA_SMARTIO is not set
550# CONFIG_ISI is not set 560# CONFIG_ISI is not set
551# CONFIG_SYNCLINKMP is not set 561# CONFIG_SYNCLINKMP is not set
562# CONFIG_SYNCLINK_GT is not set
552# CONFIG_N_HDLC is not set 563# CONFIG_N_HDLC is not set
553# CONFIG_SPECIALIX is not set 564# CONFIG_SPECIALIX is not set
554# CONFIG_SX is not set 565# CONFIG_SX is not set
@@ -564,7 +575,6 @@ CONFIG_SIBYTE_SB1250_DUART_CONSOLE=y
564# 575#
565# Non-8250 serial port support 576# Non-8250 serial port support
566# 577#
567# CONFIG_SERIAL_JSM is not set
568CONFIG_UNIX98_PTYS=y 578CONFIG_UNIX98_PTYS=y
569CONFIG_LEGACY_PTYS=y 579CONFIG_LEGACY_PTYS=y
570CONFIG_LEGACY_PTY_COUNT=256 580CONFIG_LEGACY_PTY_COUNT=256
@@ -655,6 +665,12 @@ CONFIG_I2C_DEBUG_BUS=y
655CONFIG_I2C_DEBUG_CHIP=y 665CONFIG_I2C_DEBUG_CHIP=y
656 666
657# 667#
668# SPI support
669#
670# CONFIG_SPI is not set
671# CONFIG_SPI_MASTER is not set
672
673#
658# Dallas's 1-wire bus 674# Dallas's 1-wire bus
659# 675#
660# CONFIG_W1 is not set 676# CONFIG_W1 is not set
@@ -732,12 +748,12 @@ CONFIG_EXT2_FS_POSIX_ACL=y
732CONFIG_EXT2_FS_SECURITY=y 748CONFIG_EXT2_FS_SECURITY=y
733# CONFIG_EXT2_FS_XIP is not set 749# CONFIG_EXT2_FS_XIP is not set
734# CONFIG_EXT3_FS is not set 750# CONFIG_EXT3_FS is not set
735# CONFIG_JBD is not set
736CONFIG_FS_MBCACHE=y 751CONFIG_FS_MBCACHE=y
737# CONFIG_REISERFS_FS is not set 752# CONFIG_REISERFS_FS is not set
738# CONFIG_JFS_FS is not set 753# CONFIG_JFS_FS is not set
739CONFIG_FS_POSIX_ACL=y 754CONFIG_FS_POSIX_ACL=y
740# CONFIG_XFS_FS is not set 755# CONFIG_XFS_FS is not set
756# CONFIG_OCFS2_FS is not set
741# CONFIG_MINIX_FS is not set 757# CONFIG_MINIX_FS is not set
742# CONFIG_ROMFS_FS is not set 758# CONFIG_ROMFS_FS is not set
743CONFIG_INOTIFY=y 759CONFIG_INOTIFY=y
@@ -770,6 +786,7 @@ CONFIG_SYSFS=y
770# CONFIG_HUGETLB_PAGE is not set 786# CONFIG_HUGETLB_PAGE is not set
771CONFIG_RAMFS=y 787CONFIG_RAMFS=y
772# CONFIG_RELAYFS_FS is not set 788# CONFIG_RELAYFS_FS is not set
789# CONFIG_CONFIGFS_FS is not set
773 790
774# 791#
775# Miscellaneous filesystems 792# Miscellaneous filesystems
@@ -831,18 +848,20 @@ CONFIG_MSDOS_PARTITION=y
831# Kernel hacking 848# Kernel hacking
832# 849#
833CONFIG_PRINTK_TIME=y 850CONFIG_PRINTK_TIME=y
834CONFIG_DEBUG_KERNEL=y
835CONFIG_MAGIC_SYSRQ=y 851CONFIG_MAGIC_SYSRQ=y
852CONFIG_DEBUG_KERNEL=y
836CONFIG_LOG_BUF_SHIFT=16 853CONFIG_LOG_BUF_SHIFT=16
837CONFIG_DETECT_SOFTLOCKUP=y 854CONFIG_DETECT_SOFTLOCKUP=y
838# CONFIG_SCHEDSTATS is not set 855# CONFIG_SCHEDSTATS is not set
839# CONFIG_DEBUG_SLAB is not set 856# CONFIG_DEBUG_SLAB is not set
857CONFIG_DEBUG_MUTEXES=y
840# CONFIG_DEBUG_SPINLOCK is not set 858# CONFIG_DEBUG_SPINLOCK is not set
841# CONFIG_DEBUG_SPINLOCK_SLEEP is not set 859# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
842# CONFIG_DEBUG_KOBJECT is not set 860# CONFIG_DEBUG_KOBJECT is not set
843# CONFIG_DEBUG_INFO is not set 861# CONFIG_DEBUG_INFO is not set
844# CONFIG_DEBUG_FS is not set 862# CONFIG_DEBUG_FS is not set
845# CONFIG_DEBUG_VM is not set 863# CONFIG_DEBUG_VM is not set
864CONFIG_FORCED_INLINING=y
846# CONFIG_RCU_TORTURE_TEST is not set 865# CONFIG_RCU_TORTURE_TEST is not set
847CONFIG_CROSSCOMPILE=y 866CONFIG_CROSSCOMPILE=y
848CONFIG_CMDLINE="" 867CONFIG_CMDLINE=""
diff --git a/arch/mips/configs/capcella_defconfig b/arch/mips/configs/capcella_defconfig
index 5261e29ccf37..6c2961affbd6 100644
--- a/arch/mips/configs/capcella_defconfig
+++ b/arch/mips/configs/capcella_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:05:55 2005 4# Fri Jan 27 15:39:54 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -63,9 +63,9 @@ CONFIG_MACH_VR41XX=y
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
66# CONFIG_NEC_CMBVR4133 is not set
67# CONFIG_CASIO_E55 is not set 66# CONFIG_CASIO_E55 is not set
68# CONFIG_IBM_WORKPAD is not set 67# CONFIG_IBM_WORKPAD is not set
68# CONFIG_NEC_CMBVR4133 is not set
69# CONFIG_TANBAC_TB022X is not set 69# CONFIG_TANBAC_TB022X is not set
70# CONFIG_VICTOR_MPC30X is not set 70# CONFIG_VICTOR_MPC30X is not set
71CONFIG_ZAO_CAPCELLA=y 71CONFIG_ZAO_CAPCELLA=y
@@ -90,7 +90,7 @@ CONFIG_MIPS_L1_CACHE_SHIFT=5
90# CONFIG_CPU_MIPS64_R2 is not set 90# CONFIG_CPU_MIPS64_R2 is not set
91# CONFIG_CPU_R3000 is not set 91# CONFIG_CPU_R3000 is not set
92# CONFIG_CPU_TX39XX is not set 92# CONFIG_CPU_TX39XX is not set
93CONFIG_CPU_VR41XX=y 93# CONFIG_CPU_VR41XX is not set
94# CONFIG_CPU_R4300 is not set 94# CONFIG_CPU_R4300 is not set
95# CONFIG_CPU_R4X00 is not set 95# CONFIG_CPU_R4X00 is not set
96# CONFIG_CPU_TX49XX is not set 96# CONFIG_CPU_TX49XX is not set
@@ -103,23 +103,18 @@ CONFIG_CPU_VR41XX=y
103# CONFIG_CPU_RM7000 is not set 103# CONFIG_CPU_RM7000 is not set
104# CONFIG_CPU_RM9000 is not set 104# CONFIG_CPU_RM9000 is not set
105# CONFIG_CPU_SB1 is not set 105# CONFIG_CPU_SB1 is not set
106CONFIG_SYS_HAS_CPU_VR41XX=y
107CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
108CONFIG_SYS_SUPPORTS_64BIT_KERNEL=y
109CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
110CONFIG_CPU_SUPPORTS_64BIT_KERNEL=y
111 106
112# 107#
113# Kernel type 108# Kernel type
114# 109#
115CONFIG_32BIT=y 110# CONFIG_32BIT is not set
116# CONFIG_64BIT is not set 111# CONFIG_64BIT is not set
117CONFIG_PAGE_SIZE_4KB=y 112CONFIG_PAGE_SIZE_4KB=y
118# CONFIG_PAGE_SIZE_8KB is not set 113# CONFIG_PAGE_SIZE_8KB is not set
119# CONFIG_PAGE_SIZE_16KB is not set 114# CONFIG_PAGE_SIZE_16KB is not set
120# CONFIG_PAGE_SIZE_64KB is not set 115# CONFIG_PAGE_SIZE_64KB is not set
121# CONFIG_MIPS_MT is not set 116# CONFIG_MIPS_MT is not set
122# CONFIG_CPU_ADVANCED is not set 117CONFIG_CPU_HAS_LLSC=y
123CONFIG_CPU_HAS_SYNC=y 118CONFIG_CPU_HAS_SYNC=y
124CONFIG_GENERIC_HARDIRQS=y 119CONFIG_GENERIC_HARDIRQS=y
125CONFIG_GENERIC_IRQ_PROBE=y 120CONFIG_GENERIC_IRQ_PROBE=y
@@ -155,26 +150,28 @@ CONFIG_SYSVIPC=y
155# CONFIG_BSD_PROCESS_ACCT is not set 150# CONFIG_BSD_PROCESS_ACCT is not set
156CONFIG_SYSCTL=y 151CONFIG_SYSCTL=y
157# CONFIG_AUDIT is not set 152# CONFIG_AUDIT is not set
158CONFIG_HOTPLUG=y
159CONFIG_KOBJECT_UEVENT=y
160# CONFIG_IKCONFIG is not set 153# CONFIG_IKCONFIG is not set
161CONFIG_INITRAMFS_SOURCE="" 154CONFIG_INITRAMFS_SOURCE=""
155# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
162CONFIG_EMBEDDED=y 156CONFIG_EMBEDDED=y
163CONFIG_KALLSYMS=y 157CONFIG_KALLSYMS=y
164# CONFIG_KALLSYMS_EXTRA_PASS is not set 158# CONFIG_KALLSYMS_EXTRA_PASS is not set
159CONFIG_HOTPLUG=y
165CONFIG_PRINTK=y 160CONFIG_PRINTK=y
166CONFIG_BUG=y 161CONFIG_BUG=y
162CONFIG_ELF_CORE=y
167CONFIG_BASE_FULL=y 163CONFIG_BASE_FULL=y
168CONFIG_FUTEX=y 164CONFIG_FUTEX=y
169CONFIG_EPOLL=y 165CONFIG_EPOLL=y
170# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
171CONFIG_SHMEM=y 166CONFIG_SHMEM=y
172CONFIG_CC_ALIGN_FUNCTIONS=0 167CONFIG_CC_ALIGN_FUNCTIONS=0
173CONFIG_CC_ALIGN_LABELS=0 168CONFIG_CC_ALIGN_LABELS=0
174CONFIG_CC_ALIGN_LOOPS=0 169CONFIG_CC_ALIGN_LOOPS=0
175CONFIG_CC_ALIGN_JUMPS=0 170CONFIG_CC_ALIGN_JUMPS=0
171CONFIG_SLAB=y
176# CONFIG_TINY_SHMEM is not set 172# CONFIG_TINY_SHMEM is not set
177CONFIG_BASE_SMALL=0 173CONFIG_BASE_SMALL=0
174# CONFIG_SLOB is not set
178 175
179# 176#
180# Loadable module support 177# Loadable module support
@@ -190,7 +187,6 @@ CONFIG_KMOD=y
190# 187#
191# Block layer 188# Block layer
192# 189#
193# CONFIG_LBD is not set
194 190
195# 191#
196# IO Schedulers 192# IO Schedulers
@@ -228,7 +224,6 @@ CONFIG_MMU=y
228# 224#
229CONFIG_BINFMT_ELF=y 225CONFIG_BINFMT_ELF=y
230# CONFIG_BINFMT_MISC is not set 226# CONFIG_BINFMT_MISC is not set
231CONFIG_TRAD_SIGNALS=y
232 227
233# 228#
234# Networking 229# Networking
@@ -286,6 +281,11 @@ CONFIG_TCP_CONG_BIC=y
286# CONFIG_ATALK is not set 281# CONFIG_ATALK is not set
287# CONFIG_X25 is not set 282# CONFIG_X25 is not set
288# CONFIG_LAPB is not set 283# CONFIG_LAPB is not set
284
285#
286# TIPC Configuration (EXPERIMENTAL)
287#
288# CONFIG_TIPC is not set
289# CONFIG_NET_DIVERT is not set 289# CONFIG_NET_DIVERT is not set
290# CONFIG_ECONET is not set 290# CONFIG_ECONET is not set
291# CONFIG_WAN_ROUTER is not set 291# CONFIG_WAN_ROUTER is not set
@@ -306,7 +306,6 @@ CONFIG_IEEE80211=m
306# CONFIG_IEEE80211_DEBUG is not set 306# CONFIG_IEEE80211_DEBUG is not set
307CONFIG_IEEE80211_CRYPT_WEP=m 307CONFIG_IEEE80211_CRYPT_WEP=m
308CONFIG_IEEE80211_CRYPT_CCMP=m 308CONFIG_IEEE80211_CRYPT_CCMP=m
309CONFIG_IEEE80211_CRYPT_TKIP=m
310 309
311# 310#
312# Device Drivers 311# Device Drivers
@@ -444,6 +443,7 @@ CONFIG_MII=y
444# CONFIG_SUNGEM is not set 443# CONFIG_SUNGEM is not set
445# CONFIG_CASSINI is not set 444# CONFIG_CASSINI is not set
446# CONFIG_NET_VENDOR_3COM is not set 445# CONFIG_NET_VENDOR_3COM is not set
446# CONFIG_DM9000 is not set
447 447
448# 448#
449# Tulip family network device support 449# Tulip family network device support
@@ -487,6 +487,7 @@ CONFIG_8139TOO_PIO=y
487# CONFIG_R8169 is not set 487# CONFIG_R8169 is not set
488# CONFIG_SIS190 is not set 488# CONFIG_SIS190 is not set
489# CONFIG_SKGE is not set 489# CONFIG_SKGE is not set
490# CONFIG_SKY2 is not set
490# CONFIG_SK98LIN is not set 491# CONFIG_SK98LIN is not set
491# CONFIG_VIA_VELOCITY is not set 492# CONFIG_VIA_VELOCITY is not set
492# CONFIG_TIGON3 is not set 493# CONFIG_TIGON3 is not set
@@ -508,8 +509,6 @@ CONFIG_8139TOO_PIO=y
508# Wireless LAN (non-hamradio) 509# Wireless LAN (non-hamradio)
509# 510#
510# CONFIG_NET_RADIO is not set 511# CONFIG_NET_RADIO is not set
511# CONFIG_IPW_DEBUG is not set
512CONFIG_IPW2200=m
513 512
514# 513#
515# Wan interfaces 514# Wan interfaces
@@ -579,11 +578,6 @@ CONFIG_HW_CONSOLE=y
579# 578#
580# Non-8250 serial port support 579# Non-8250 serial port support
581# 580#
582CONFIG_SERIAL_CORE=y
583CONFIG_SERIAL_CORE_CONSOLE=y
584CONFIG_SERIAL_VR41XX=y
585CONFIG_SERIAL_VR41XX_CONSOLE=y
586# CONFIG_SERIAL_JSM is not set
587CONFIG_UNIX98_PTYS=y 581CONFIG_UNIX98_PTYS=y
588CONFIG_LEGACY_PTYS=y 582CONFIG_LEGACY_PTYS=y
589CONFIG_LEGACY_PTY_COUNT=256 583CONFIG_LEGACY_PTY_COUNT=256
@@ -599,7 +593,6 @@ CONFIG_LEGACY_PTY_COUNT=256
599# CONFIG_WATCHDOG is not set 593# CONFIG_WATCHDOG is not set
600# CONFIG_RTC is not set 594# CONFIG_RTC is not set
601# CONFIG_GEN_RTC is not set 595# CONFIG_GEN_RTC is not set
602# CONFIG_RTC_VR41XX is not set
603# CONFIG_DTLK is not set 596# CONFIG_DTLK is not set
604# CONFIG_R3964 is not set 597# CONFIG_R3964 is not set
605# CONFIG_APPLICOM is not set 598# CONFIG_APPLICOM is not set
@@ -608,7 +601,6 @@ CONFIG_LEGACY_PTY_COUNT=256
608# Ftape, the floppy tape device driver 601# Ftape, the floppy tape device driver
609# 602#
610# CONFIG_DRM is not set 603# CONFIG_DRM is not set
611CONFIG_GPIO_VR41XX=y
612# CONFIG_RAW_DRIVER is not set 604# CONFIG_RAW_DRIVER is not set
613 605
614# 606#
@@ -623,6 +615,12 @@ CONFIG_GPIO_VR41XX=y
623# CONFIG_I2C is not set 615# CONFIG_I2C is not set
624 616
625# 617#
618# SPI support
619#
620# CONFIG_SPI is not set
621# CONFIG_SPI_MASTER is not set
622
623#
626# Dallas's 1-wire bus 624# Dallas's 1-wire bus
627# 625#
628# CONFIG_W1 is not set 626# CONFIG_W1 is not set
@@ -704,11 +702,11 @@ CONFIG_EXT2_FS=y
704# CONFIG_EXT2_FS_XATTR is not set 702# CONFIG_EXT2_FS_XATTR is not set
705# CONFIG_EXT2_FS_XIP is not set 703# CONFIG_EXT2_FS_XIP is not set
706# CONFIG_EXT3_FS is not set 704# CONFIG_EXT3_FS is not set
707# CONFIG_JBD is not set
708# CONFIG_REISERFS_FS is not set 705# CONFIG_REISERFS_FS is not set
709# CONFIG_JFS_FS is not set 706# CONFIG_JFS_FS is not set
710# CONFIG_FS_POSIX_ACL is not set 707# CONFIG_FS_POSIX_ACL is not set
711# CONFIG_XFS_FS is not set 708# CONFIG_XFS_FS is not set
709# CONFIG_OCFS2_FS is not set
712# CONFIG_MINIX_FS is not set 710# CONFIG_MINIX_FS is not set
713# CONFIG_ROMFS_FS is not set 711# CONFIG_ROMFS_FS is not set
714CONFIG_INOTIFY=y 712CONFIG_INOTIFY=y
@@ -741,6 +739,7 @@ CONFIG_SYSFS=y
741# CONFIG_HUGETLB_PAGE is not set 739# CONFIG_HUGETLB_PAGE is not set
742CONFIG_RAMFS=y 740CONFIG_RAMFS=y
743CONFIG_RELAYFS_FS=m 741CONFIG_RELAYFS_FS=m
742# CONFIG_CONFIGFS_FS is not set
744 743
745# 744#
746# Miscellaneous filesystems 745# Miscellaneous filesystems
@@ -803,6 +802,7 @@ CONFIG_MSDOS_PARTITION=y
803# Kernel hacking 802# Kernel hacking
804# 803#
805# CONFIG_PRINTK_TIME is not set 804# CONFIG_PRINTK_TIME is not set
805# CONFIG_MAGIC_SYSRQ is not set
806# CONFIG_DEBUG_KERNEL is not set 806# CONFIG_DEBUG_KERNEL is not set
807CONFIG_LOG_BUF_SHIFT=14 807CONFIG_LOG_BUF_SHIFT=14
808CONFIG_CROSSCOMPILE=y 808CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/cobalt_defconfig b/arch/mips/configs/cobalt_defconfig
index 1d3ee18ea8bb..8336b21d3db2 100644
--- a/arch/mips/configs/cobalt_defconfig
+++ b/arch/mips/configs/cobalt_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:05:57 2005 4# Fri Jan 27 15:39:55 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -150,26 +150,28 @@ CONFIG_SYSVIPC=y
150# CONFIG_BSD_PROCESS_ACCT is not set 150# CONFIG_BSD_PROCESS_ACCT is not set
151CONFIG_SYSCTL=y 151CONFIG_SYSCTL=y
152# CONFIG_AUDIT is not set 152# CONFIG_AUDIT is not set
153CONFIG_HOTPLUG=y
154CONFIG_KOBJECT_UEVENT=y
155# CONFIG_IKCONFIG is not set 153# CONFIG_IKCONFIG is not set
156CONFIG_INITRAMFS_SOURCE="" 154CONFIG_INITRAMFS_SOURCE=""
155# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
157CONFIG_EMBEDDED=y 156CONFIG_EMBEDDED=y
158CONFIG_KALLSYMS=y 157CONFIG_KALLSYMS=y
159# CONFIG_KALLSYMS_EXTRA_PASS is not set 158# CONFIG_KALLSYMS_EXTRA_PASS is not set
159CONFIG_HOTPLUG=y
160CONFIG_PRINTK=y 160CONFIG_PRINTK=y
161CONFIG_BUG=y 161CONFIG_BUG=y
162CONFIG_ELF_CORE=y
162CONFIG_BASE_FULL=y 163CONFIG_BASE_FULL=y
163CONFIG_FUTEX=y 164CONFIG_FUTEX=y
164CONFIG_EPOLL=y 165CONFIG_EPOLL=y
165# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
166CONFIG_SHMEM=y 166CONFIG_SHMEM=y
167CONFIG_CC_ALIGN_FUNCTIONS=0 167CONFIG_CC_ALIGN_FUNCTIONS=0
168CONFIG_CC_ALIGN_LABELS=0 168CONFIG_CC_ALIGN_LABELS=0
169CONFIG_CC_ALIGN_LOOPS=0 169CONFIG_CC_ALIGN_LOOPS=0
170CONFIG_CC_ALIGN_JUMPS=0 170CONFIG_CC_ALIGN_JUMPS=0
171CONFIG_SLAB=y
171# CONFIG_TINY_SHMEM is not set 172# CONFIG_TINY_SHMEM is not set
172CONFIG_BASE_SMALL=0 173CONFIG_BASE_SMALL=0
174# CONFIG_SLOB is not set
173 175
174# 176#
175# Loadable module support 177# Loadable module support
@@ -271,6 +273,11 @@ CONFIG_TCP_CONG_BIC=y
271# CONFIG_ATALK is not set 273# CONFIG_ATALK is not set
272# CONFIG_X25 is not set 274# CONFIG_X25 is not set
273# CONFIG_LAPB is not set 275# CONFIG_LAPB is not set
276
277#
278# TIPC Configuration (EXPERIMENTAL)
279#
280# CONFIG_TIPC is not set
274# CONFIG_NET_DIVERT is not set 281# CONFIG_NET_DIVERT is not set
275# CONFIG_ECONET is not set 282# CONFIG_ECONET is not set
276# CONFIG_WAN_ROUTER is not set 283# CONFIG_WAN_ROUTER is not set
@@ -291,7 +298,6 @@ CONFIG_IEEE80211=y
291# CONFIG_IEEE80211_DEBUG is not set 298# CONFIG_IEEE80211_DEBUG is not set
292CONFIG_IEEE80211_CRYPT_WEP=y 299CONFIG_IEEE80211_CRYPT_WEP=y
293CONFIG_IEEE80211_CRYPT_CCMP=y 300CONFIG_IEEE80211_CRYPT_CCMP=y
294CONFIG_IEEE80211_CRYPT_TKIP=y
295 301
296# 302#
297# Device Drivers 303# Device Drivers
@@ -364,9 +370,38 @@ CONFIG_BLK_DEV_IDEDISK=y
364# IDE chipset support/bugfixes 370# IDE chipset support/bugfixes
365# 371#
366CONFIG_IDE_GENERIC=y 372CONFIG_IDE_GENERIC=y
367# CONFIG_BLK_DEV_IDEPCI is not set 373CONFIG_BLK_DEV_IDEPCI=y
374# CONFIG_IDEPCI_SHARE_IRQ is not set
375# CONFIG_BLK_DEV_OFFBOARD is not set
376# CONFIG_BLK_DEV_GENERIC is not set
377# CONFIG_BLK_DEV_OPTI621 is not set
378CONFIG_BLK_DEV_IDEDMA_PCI=y
379# CONFIG_BLK_DEV_IDEDMA_FORCED is not set
380# CONFIG_IDEDMA_PCI_AUTO is not set
381# CONFIG_BLK_DEV_AEC62XX is not set
382# CONFIG_BLK_DEV_ALI15X3 is not set
383# CONFIG_BLK_DEV_AMD74XX is not set
384# CONFIG_BLK_DEV_CMD64X is not set
385# CONFIG_BLK_DEV_TRIFLEX is not set
386# CONFIG_BLK_DEV_CY82C693 is not set
387# CONFIG_BLK_DEV_CS5520 is not set
388# CONFIG_BLK_DEV_CS5530 is not set
389# CONFIG_BLK_DEV_HPT34X is not set
390# CONFIG_BLK_DEV_HPT366 is not set
391# CONFIG_BLK_DEV_SC1200 is not set
392# CONFIG_BLK_DEV_PIIX is not set
393# CONFIG_BLK_DEV_IT821X is not set
394# CONFIG_BLK_DEV_NS87415 is not set
395# CONFIG_BLK_DEV_PDC202XX_OLD is not set
396# CONFIG_BLK_DEV_PDC202XX_NEW is not set
397# CONFIG_BLK_DEV_SVWKS is not set
398# CONFIG_BLK_DEV_SIIMAGE is not set
399# CONFIG_BLK_DEV_SLC90E66 is not set
400# CONFIG_BLK_DEV_TRM290 is not set
401CONFIG_BLK_DEV_VIA82CXXX=y
368# CONFIG_IDE_ARM is not set 402# CONFIG_IDE_ARM is not set
369# CONFIG_BLK_DEV_IDEDMA is not set 403CONFIG_BLK_DEV_IDEDMA=y
404# CONFIG_IDEDMA_IVB is not set
370# CONFIG_IDEDMA_AUTO is not set 405# CONFIG_IDEDMA_AUTO is not set
371# CONFIG_BLK_DEV_HD is not set 406# CONFIG_BLK_DEV_HD is not set
372 407
@@ -433,11 +468,21 @@ CONFIG_NET_ETHERNET=y
433# CONFIG_SUNGEM is not set 468# CONFIG_SUNGEM is not set
434# CONFIG_CASSINI is not set 469# CONFIG_CASSINI is not set
435# CONFIG_NET_VENDOR_3COM is not set 470# CONFIG_NET_VENDOR_3COM is not set
471# CONFIG_DM9000 is not set
436 472
437# 473#
438# Tulip family network device support 474# Tulip family network device support
439# 475#
440# CONFIG_NET_TULIP is not set 476CONFIG_NET_TULIP=y
477CONFIG_DE2104X=y
478CONFIG_TULIP=y
479# CONFIG_TULIP_MWI is not set
480# CONFIG_TULIP_MMIO is not set
481# CONFIG_TULIP_NAPI is not set
482# CONFIG_DE4X5 is not set
483# CONFIG_WINBOND_840 is not set
484# CONFIG_DM9102 is not set
485# CONFIG_ULI526X is not set
441# CONFIG_HP100 is not set 486# CONFIG_HP100 is not set
442# CONFIG_NET_PCI is not set 487# CONFIG_NET_PCI is not set
443 488
@@ -453,6 +498,7 @@ CONFIG_NET_ETHERNET=y
453# CONFIG_R8169 is not set 498# CONFIG_R8169 is not set
454# CONFIG_SIS190 is not set 499# CONFIG_SIS190 is not set
455# CONFIG_SKGE is not set 500# CONFIG_SKGE is not set
501# CONFIG_SKY2 is not set
456# CONFIG_SK98LIN is not set 502# CONFIG_SK98LIN is not set
457# CONFIG_TIGON3 is not set 503# CONFIG_TIGON3 is not set
458# CONFIG_BNX2 is not set 504# CONFIG_BNX2 is not set
@@ -473,8 +519,6 @@ CONFIG_NET_ETHERNET=y
473# Wireless LAN (non-hamradio) 519# Wireless LAN (non-hamradio)
474# 520#
475# CONFIG_NET_RADIO is not set 521# CONFIG_NET_RADIO is not set
476# CONFIG_IPW_DEBUG is not set
477CONFIG_IPW2200=y
478 522
479# 523#
480# Wan interfaces 524# Wan interfaces
@@ -550,6 +594,7 @@ CONFIG_HW_CONSOLE=y
550CONFIG_SERIAL_8250=y 594CONFIG_SERIAL_8250=y
551CONFIG_SERIAL_8250_CONSOLE=y 595CONFIG_SERIAL_8250_CONSOLE=y
552CONFIG_SERIAL_8250_NR_UARTS=4 596CONFIG_SERIAL_8250_NR_UARTS=4
597CONFIG_SERIAL_8250_RUNTIME_UARTS=4
553# CONFIG_SERIAL_8250_EXTENDED is not set 598# CONFIG_SERIAL_8250_EXTENDED is not set
554 599
555# 600#
@@ -557,7 +602,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
557# 602#
558CONFIG_SERIAL_CORE=y 603CONFIG_SERIAL_CORE=y
559CONFIG_SERIAL_CORE_CONSOLE=y 604CONFIG_SERIAL_CORE_CONSOLE=y
560# CONFIG_SERIAL_JSM is not set
561CONFIG_UNIX98_PTYS=y 605CONFIG_UNIX98_PTYS=y
562CONFIG_LEGACY_PTYS=y 606CONFIG_LEGACY_PTYS=y
563CONFIG_LEGACY_PTY_COUNT=256 607CONFIG_LEGACY_PTY_COUNT=256
@@ -595,6 +639,12 @@ CONFIG_COBALT_LCD=y
595# CONFIG_I2C is not set 639# CONFIG_I2C is not set
596 640
597# 641#
642# SPI support
643#
644# CONFIG_SPI is not set
645# CONFIG_SPI_MASTER is not set
646
647#
598# Dallas's 1-wire bus 648# Dallas's 1-wire bus
599# 649#
600# CONFIG_W1 is not set 650# CONFIG_W1 is not set
@@ -678,12 +728,12 @@ CONFIG_EXT2_FS_POSIX_ACL=y
678CONFIG_EXT2_FS_SECURITY=y 728CONFIG_EXT2_FS_SECURITY=y
679# CONFIG_EXT2_FS_XIP is not set 729# CONFIG_EXT2_FS_XIP is not set
680# CONFIG_EXT3_FS is not set 730# CONFIG_EXT3_FS is not set
681# CONFIG_JBD is not set
682CONFIG_FS_MBCACHE=y 731CONFIG_FS_MBCACHE=y
683# CONFIG_REISERFS_FS is not set 732# CONFIG_REISERFS_FS is not set
684# CONFIG_JFS_FS is not set 733# CONFIG_JFS_FS is not set
685CONFIG_FS_POSIX_ACL=y 734CONFIG_FS_POSIX_ACL=y
686# CONFIG_XFS_FS is not set 735# CONFIG_XFS_FS is not set
736# CONFIG_OCFS2_FS is not set
687# CONFIG_MINIX_FS is not set 737# CONFIG_MINIX_FS is not set
688# CONFIG_ROMFS_FS is not set 738# CONFIG_ROMFS_FS is not set
689CONFIG_INOTIFY=y 739CONFIG_INOTIFY=y
@@ -716,6 +766,7 @@ CONFIG_SYSFS=y
716# CONFIG_HUGETLB_PAGE is not set 766# CONFIG_HUGETLB_PAGE is not set
717CONFIG_RAMFS=y 767CONFIG_RAMFS=y
718CONFIG_RELAYFS_FS=y 768CONFIG_RELAYFS_FS=y
769# CONFIG_CONFIGFS_FS is not set
719 770
720# 771#
721# Miscellaneous filesystems 772# Miscellaneous filesystems
@@ -774,6 +825,7 @@ CONFIG_MSDOS_PARTITION=y
774# Kernel hacking 825# Kernel hacking
775# 826#
776# CONFIG_PRINTK_TIME is not set 827# CONFIG_PRINTK_TIME is not set
828# CONFIG_MAGIC_SYSRQ is not set
777# CONFIG_DEBUG_KERNEL is not set 829# CONFIG_DEBUG_KERNEL is not set
778CONFIG_LOG_BUF_SHIFT=14 830CONFIG_LOG_BUF_SHIFT=14
779CONFIG_CROSSCOMPILE=y 831CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/db1000_defconfig b/arch/mips/configs/db1000_defconfig
index 18ac7926c058..7f071403c8e3 100644
--- a/arch/mips/configs/db1000_defconfig
+++ b/arch/mips/configs/db1000_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:05:59 2005 4# Fri Jan 27 15:39:56 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -151,26 +151,29 @@ CONFIG_SYSVIPC=y
151# CONFIG_BSD_PROCESS_ACCT is not set 151# CONFIG_BSD_PROCESS_ACCT is not set
152CONFIG_SYSCTL=y 152CONFIG_SYSCTL=y
153# CONFIG_AUDIT is not set 153# CONFIG_AUDIT is not set
154CONFIG_HOTPLUG=y
155CONFIG_KOBJECT_UEVENT=y
156# CONFIG_IKCONFIG is not set 154# CONFIG_IKCONFIG is not set
157CONFIG_INITRAMFS_SOURCE="" 155CONFIG_INITRAMFS_SOURCE=""
156# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
158CONFIG_EMBEDDED=y 157CONFIG_EMBEDDED=y
159CONFIG_KALLSYMS=y 158CONFIG_KALLSYMS=y
160# CONFIG_KALLSYMS_EXTRA_PASS is not set 159# CONFIG_KALLSYMS_EXTRA_PASS is not set
160CONFIG_HOTPLUG=y
161CONFIG_PRINTK=y 161CONFIG_PRINTK=y
162CONFIG_BUG=y 162CONFIG_BUG=y
163CONFIG_ELF_CORE=y
163CONFIG_BASE_FULL=y 164CONFIG_BASE_FULL=y
164CONFIG_FUTEX=y 165CONFIG_FUTEX=y
165CONFIG_EPOLL=y 166CONFIG_EPOLL=y
166# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
167CONFIG_SHMEM=y 167CONFIG_SHMEM=y
168CONFIG_CC_ALIGN_FUNCTIONS=0 168CONFIG_CC_ALIGN_FUNCTIONS=0
169CONFIG_CC_ALIGN_LABELS=0 169CONFIG_CC_ALIGN_LABELS=0
170CONFIG_CC_ALIGN_LOOPS=0 170CONFIG_CC_ALIGN_LOOPS=0
171CONFIG_CC_ALIGN_JUMPS=0 171CONFIG_CC_ALIGN_JUMPS=0
172CONFIG_SLAB=y
172# CONFIG_TINY_SHMEM is not set 173# CONFIG_TINY_SHMEM is not set
173CONFIG_BASE_SMALL=0 174CONFIG_BASE_SMALL=0
175# CONFIG_SLOB is not set
176CONFIG_OBSOLETE_INTERMODULE=y
174 177
175# 178#
176# Loadable module support 179# Loadable module support
@@ -285,6 +288,21 @@ CONFIG_NETFILTER_NETLINK=m
285CONFIG_NETFILTER_NETLINK_QUEUE=m 288CONFIG_NETFILTER_NETLINK_QUEUE=m
286CONFIG_NETFILTER_NETLINK_LOG=m 289CONFIG_NETFILTER_NETLINK_LOG=m
287# CONFIG_NF_CONNTRACK is not set 290# CONFIG_NF_CONNTRACK is not set
291CONFIG_NETFILTER_XTABLES=m
292CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
293CONFIG_NETFILTER_XT_TARGET_MARK=m
294CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
295CONFIG_NETFILTER_XT_MATCH_COMMENT=m
296CONFIG_NETFILTER_XT_MATCH_DCCP=m
297CONFIG_NETFILTER_XT_MATCH_LENGTH=m
298CONFIG_NETFILTER_XT_MATCH_LIMIT=m
299CONFIG_NETFILTER_XT_MATCH_MAC=m
300CONFIG_NETFILTER_XT_MATCH_MARK=m
301CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
302CONFIG_NETFILTER_XT_MATCH_REALM=m
303CONFIG_NETFILTER_XT_MATCH_SCTP=m
304CONFIG_NETFILTER_XT_MATCH_STRING=m
305CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
288 306
289# 307#
290# IP: Netfilter Configuration 308# IP: Netfilter Configuration
@@ -312,6 +330,11 @@ CONFIG_NETFILTER_NETLINK_LOG=m
312# CONFIG_ATALK is not set 330# CONFIG_ATALK is not set
313# CONFIG_X25 is not set 331# CONFIG_X25 is not set
314# CONFIG_LAPB is not set 332# CONFIG_LAPB is not set
333
334#
335# TIPC Configuration (EXPERIMENTAL)
336#
337# CONFIG_TIPC is not set
315# CONFIG_NET_DIVERT is not set 338# CONFIG_NET_DIVERT is not set
316# CONFIG_ECONET is not set 339# CONFIG_ECONET is not set
317# CONFIG_WAN_ROUTER is not set 340# CONFIG_WAN_ROUTER is not set
@@ -320,6 +343,7 @@ CONFIG_NETFILTER_NETLINK_LOG=m
320# QoS and/or fair queueing 343# QoS and/or fair queueing
321# 344#
322# CONFIG_NET_SCHED is not set 345# CONFIG_NET_SCHED is not set
346CONFIG_NET_CLS_ROUTE=y
323 347
324# 348#
325# Network testing 349# Network testing
@@ -332,7 +356,6 @@ CONFIG_IEEE80211=m
332# CONFIG_IEEE80211_DEBUG is not set 356# CONFIG_IEEE80211_DEBUG is not set
333CONFIG_IEEE80211_CRYPT_WEP=m 357CONFIG_IEEE80211_CRYPT_WEP=m
334CONFIG_IEEE80211_CRYPT_CCMP=m 358CONFIG_IEEE80211_CRYPT_CCMP=m
335CONFIG_IEEE80211_CRYPT_TKIP=m
336 359
337# 360#
338# Device Drivers 361# Device Drivers
@@ -395,6 +418,7 @@ CONFIG_MTD_CFI_UTIL=y
395# CONFIG_MTD_RAM is not set 418# CONFIG_MTD_RAM is not set
396# CONFIG_MTD_ROM is not set 419# CONFIG_MTD_ROM is not set
397# CONFIG_MTD_ABSENT is not set 420# CONFIG_MTD_ABSENT is not set
421# CONFIG_MTD_OBSOLETE_CHIPS is not set
398 422
399# 423#
400# Mapping drivers for chip access 424# Mapping drivers for chip access
@@ -512,6 +536,7 @@ CONFIG_NET_ETHERNET=y
512CONFIG_MII=m 536CONFIG_MII=m
513CONFIG_MIPS_AU1X00_ENET=y 537CONFIG_MIPS_AU1X00_ENET=y
514# CONFIG_SMC91X is not set 538# CONFIG_SMC91X is not set
539# CONFIG_DM9000 is not set
515 540
516# 541#
517# Ethernet (1000 Mbit) 542# Ethernet (1000 Mbit)
@@ -625,13 +650,13 @@ CONFIG_SERIAL_8250=y
625CONFIG_SERIAL_8250_CONSOLE=y 650CONFIG_SERIAL_8250_CONSOLE=y
626CONFIG_SERIAL_8250_CS=m 651CONFIG_SERIAL_8250_CS=m
627CONFIG_SERIAL_8250_NR_UARTS=4 652CONFIG_SERIAL_8250_NR_UARTS=4
653CONFIG_SERIAL_8250_RUNTIME_UARTS=4
628# CONFIG_SERIAL_8250_EXTENDED is not set 654# CONFIG_SERIAL_8250_EXTENDED is not set
629CONFIG_SERIAL_8250_AU1X00=y 655CONFIG_SERIAL_8250_AU1X00=y
630 656
631# 657#
632# Non-8250 serial port support 658# Non-8250 serial port support
633# 659#
634# CONFIG_SERIAL_AU1X00 is not set
635CONFIG_SERIAL_CORE=y 660CONFIG_SERIAL_CORE=y
636CONFIG_SERIAL_CORE_CONSOLE=y 661CONFIG_SERIAL_CORE_CONSOLE=y
637CONFIG_UNIX98_PTYS=y 662CONFIG_UNIX98_PTYS=y
@@ -676,6 +701,12 @@ CONFIG_SYNCLINK_CS=m
676# CONFIG_I2C is not set 701# CONFIG_I2C is not set
677 702
678# 703#
704# SPI support
705#
706# CONFIG_SPI is not set
707# CONFIG_SPI_MASTER is not set
708
709#
679# Dallas's 1-wire bus 710# Dallas's 1-wire bus
680# 711#
681# CONFIG_W1 is not set 712# CONFIG_W1 is not set
@@ -773,6 +804,7 @@ CONFIG_REISERFS_FS_SECURITY=y
773# CONFIG_JFS_FS is not set 804# CONFIG_JFS_FS is not set
774CONFIG_FS_POSIX_ACL=y 805CONFIG_FS_POSIX_ACL=y
775# CONFIG_XFS_FS is not set 806# CONFIG_XFS_FS is not set
807# CONFIG_OCFS2_FS is not set
776# CONFIG_MINIX_FS is not set 808# CONFIG_MINIX_FS is not set
777# CONFIG_ROMFS_FS is not set 809# CONFIG_ROMFS_FS is not set
778CONFIG_INOTIFY=y 810CONFIG_INOTIFY=y
@@ -805,6 +837,7 @@ CONFIG_TMPFS=y
805# CONFIG_HUGETLB_PAGE is not set 837# CONFIG_HUGETLB_PAGE is not set
806CONFIG_RAMFS=y 838CONFIG_RAMFS=y
807CONFIG_RELAYFS_FS=m 839CONFIG_RELAYFS_FS=m
840# CONFIG_CONFIGFS_FS is not set
808 841
809# 842#
810# Miscellaneous filesystems 843# Miscellaneous filesystems
@@ -909,6 +942,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
909# Kernel hacking 942# Kernel hacking
910# 943#
911# CONFIG_PRINTK_TIME is not set 944# CONFIG_PRINTK_TIME is not set
945# CONFIG_MAGIC_SYSRQ is not set
912# CONFIG_DEBUG_KERNEL is not set 946# CONFIG_DEBUG_KERNEL is not set
913CONFIG_LOG_BUF_SHIFT=14 947CONFIG_LOG_BUF_SHIFT=14
914CONFIG_CROSSCOMPILE=y 948CONFIG_CROSSCOMPILE=y
@@ -963,3 +997,7 @@ CONFIG_CRC32=y
963CONFIG_LIBCRC32C=m 997CONFIG_LIBCRC32C=m
964CONFIG_ZLIB_INFLATE=m 998CONFIG_ZLIB_INFLATE=m
965CONFIG_ZLIB_DEFLATE=m 999CONFIG_ZLIB_DEFLATE=m
1000CONFIG_TEXTSEARCH=y
1001CONFIG_TEXTSEARCH_KMP=m
1002CONFIG_TEXTSEARCH_BM=m
1003CONFIG_TEXTSEARCH_FSM=m
diff --git a/arch/mips/configs/db1100_defconfig b/arch/mips/configs/db1100_defconfig
index 4f55f7414c9c..98590cac1ec5 100644
--- a/arch/mips/configs/db1100_defconfig
+++ b/arch/mips/configs/db1100_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:00 2005 4# Fri Jan 27 15:39:57 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -151,26 +151,29 @@ CONFIG_SYSVIPC=y
151# CONFIG_BSD_PROCESS_ACCT is not set 151# CONFIG_BSD_PROCESS_ACCT is not set
152CONFIG_SYSCTL=y 152CONFIG_SYSCTL=y
153# CONFIG_AUDIT is not set 153# CONFIG_AUDIT is not set
154CONFIG_HOTPLUG=y
155CONFIG_KOBJECT_UEVENT=y
156# CONFIG_IKCONFIG is not set 154# CONFIG_IKCONFIG is not set
157CONFIG_INITRAMFS_SOURCE="" 155CONFIG_INITRAMFS_SOURCE=""
156# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
158CONFIG_EMBEDDED=y 157CONFIG_EMBEDDED=y
159CONFIG_KALLSYMS=y 158CONFIG_KALLSYMS=y
160# CONFIG_KALLSYMS_EXTRA_PASS is not set 159# CONFIG_KALLSYMS_EXTRA_PASS is not set
160CONFIG_HOTPLUG=y
161CONFIG_PRINTK=y 161CONFIG_PRINTK=y
162CONFIG_BUG=y 162CONFIG_BUG=y
163CONFIG_ELF_CORE=y
163CONFIG_BASE_FULL=y 164CONFIG_BASE_FULL=y
164CONFIG_FUTEX=y 165CONFIG_FUTEX=y
165CONFIG_EPOLL=y 166CONFIG_EPOLL=y
166# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
167CONFIG_SHMEM=y 167CONFIG_SHMEM=y
168CONFIG_CC_ALIGN_FUNCTIONS=0 168CONFIG_CC_ALIGN_FUNCTIONS=0
169CONFIG_CC_ALIGN_LABELS=0 169CONFIG_CC_ALIGN_LABELS=0
170CONFIG_CC_ALIGN_LOOPS=0 170CONFIG_CC_ALIGN_LOOPS=0
171CONFIG_CC_ALIGN_JUMPS=0 171CONFIG_CC_ALIGN_JUMPS=0
172CONFIG_SLAB=y
172# CONFIG_TINY_SHMEM is not set 173# CONFIG_TINY_SHMEM is not set
173CONFIG_BASE_SMALL=0 174CONFIG_BASE_SMALL=0
175# CONFIG_SLOB is not set
176CONFIG_OBSOLETE_INTERMODULE=y
174 177
175# 178#
176# Loadable module support 179# Loadable module support
@@ -274,6 +277,21 @@ CONFIG_NETFILTER_NETLINK=m
274CONFIG_NETFILTER_NETLINK_QUEUE=m 277CONFIG_NETFILTER_NETLINK_QUEUE=m
275CONFIG_NETFILTER_NETLINK_LOG=m 278CONFIG_NETFILTER_NETLINK_LOG=m
276# CONFIG_NF_CONNTRACK is not set 279# CONFIG_NF_CONNTRACK is not set
280CONFIG_NETFILTER_XTABLES=m
281CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
282CONFIG_NETFILTER_XT_TARGET_MARK=m
283CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
284CONFIG_NETFILTER_XT_MATCH_COMMENT=m
285CONFIG_NETFILTER_XT_MATCH_DCCP=m
286CONFIG_NETFILTER_XT_MATCH_LENGTH=m
287CONFIG_NETFILTER_XT_MATCH_LIMIT=m
288CONFIG_NETFILTER_XT_MATCH_MAC=m
289CONFIG_NETFILTER_XT_MATCH_MARK=m
290CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
291CONFIG_NETFILTER_XT_MATCH_REALM=m
292CONFIG_NETFILTER_XT_MATCH_SCTP=m
293CONFIG_NETFILTER_XT_MATCH_STRING=m
294CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
277 295
278# 296#
279# IP: Netfilter Configuration 297# IP: Netfilter Configuration
@@ -301,6 +319,11 @@ CONFIG_NETFILTER_NETLINK_LOG=m
301# CONFIG_ATALK is not set 319# CONFIG_ATALK is not set
302# CONFIG_X25 is not set 320# CONFIG_X25 is not set
303# CONFIG_LAPB is not set 321# CONFIG_LAPB is not set
322
323#
324# TIPC Configuration (EXPERIMENTAL)
325#
326# CONFIG_TIPC is not set
304# CONFIG_NET_DIVERT is not set 327# CONFIG_NET_DIVERT is not set
305# CONFIG_ECONET is not set 328# CONFIG_ECONET is not set
306# CONFIG_WAN_ROUTER is not set 329# CONFIG_WAN_ROUTER is not set
@@ -309,6 +332,7 @@ CONFIG_NETFILTER_NETLINK_LOG=m
309# QoS and/or fair queueing 332# QoS and/or fair queueing
310# 333#
311# CONFIG_NET_SCHED is not set 334# CONFIG_NET_SCHED is not set
335CONFIG_NET_CLS_ROUTE=y
312 336
313# 337#
314# Network testing 338# Network testing
@@ -321,7 +345,6 @@ CONFIG_IEEE80211=m
321# CONFIG_IEEE80211_DEBUG is not set 345# CONFIG_IEEE80211_DEBUG is not set
322CONFIG_IEEE80211_CRYPT_WEP=m 346CONFIG_IEEE80211_CRYPT_WEP=m
323CONFIG_IEEE80211_CRYPT_CCMP=m 347CONFIG_IEEE80211_CRYPT_CCMP=m
324CONFIG_IEEE80211_CRYPT_TKIP=m
325 348
326# 349#
327# Device Drivers 350# Device Drivers
@@ -384,6 +407,7 @@ CONFIG_MTD_CFI_UTIL=y
384# CONFIG_MTD_RAM is not set 407# CONFIG_MTD_RAM is not set
385# CONFIG_MTD_ROM is not set 408# CONFIG_MTD_ROM is not set
386# CONFIG_MTD_ABSENT is not set 409# CONFIG_MTD_ABSENT is not set
410# CONFIG_MTD_OBSOLETE_CHIPS is not set
387 411
388# 412#
389# Mapping drivers for chip access 413# Mapping drivers for chip access
@@ -501,6 +525,7 @@ CONFIG_NET_ETHERNET=y
501CONFIG_MII=m 525CONFIG_MII=m
502CONFIG_MIPS_AU1X00_ENET=y 526CONFIG_MIPS_AU1X00_ENET=y
503# CONFIG_SMC91X is not set 527# CONFIG_SMC91X is not set
528# CONFIG_DM9000 is not set
504 529
505# 530#
506# Ethernet (1000 Mbit) 531# Ethernet (1000 Mbit)
@@ -600,13 +625,13 @@ CONFIG_HW_CONSOLE=y
600CONFIG_SERIAL_8250=y 625CONFIG_SERIAL_8250=y
601CONFIG_SERIAL_8250_CONSOLE=y 626CONFIG_SERIAL_8250_CONSOLE=y
602CONFIG_SERIAL_8250_NR_UARTS=4 627CONFIG_SERIAL_8250_NR_UARTS=4
628CONFIG_SERIAL_8250_RUNTIME_UARTS=4
603# CONFIG_SERIAL_8250_EXTENDED is not set 629# CONFIG_SERIAL_8250_EXTENDED is not set
604CONFIG_SERIAL_8250_AU1X00=y 630CONFIG_SERIAL_8250_AU1X00=y
605 631
606# 632#
607# Non-8250 serial port support 633# Non-8250 serial port support
608# 634#
609# CONFIG_SERIAL_AU1X00 is not set
610CONFIG_SERIAL_CORE=y 635CONFIG_SERIAL_CORE=y
611CONFIG_SERIAL_CORE_CONSOLE=y 636CONFIG_SERIAL_CORE_CONSOLE=y
612CONFIG_UNIX98_PTYS=y 637CONFIG_UNIX98_PTYS=y
@@ -644,6 +669,12 @@ CONFIG_LEGACY_PTY_COUNT=256
644# CONFIG_I2C is not set 669# CONFIG_I2C is not set
645 670
646# 671#
672# SPI support
673#
674# CONFIG_SPI is not set
675# CONFIG_SPI_MASTER is not set
676
677#
647# Dallas's 1-wire bus 678# Dallas's 1-wire bus
648# 679#
649# CONFIG_W1 is not set 680# CONFIG_W1 is not set
@@ -772,6 +803,7 @@ CONFIG_REISERFS_FS_SECURITY=y
772# CONFIG_JFS_FS is not set 803# CONFIG_JFS_FS is not set
773CONFIG_FS_POSIX_ACL=y 804CONFIG_FS_POSIX_ACL=y
774# CONFIG_XFS_FS is not set 805# CONFIG_XFS_FS is not set
806# CONFIG_OCFS2_FS is not set
775# CONFIG_MINIX_FS is not set 807# CONFIG_MINIX_FS is not set
776# CONFIG_ROMFS_FS is not set 808# CONFIG_ROMFS_FS is not set
777CONFIG_INOTIFY=y 809CONFIG_INOTIFY=y
@@ -804,6 +836,7 @@ CONFIG_TMPFS=y
804# CONFIG_HUGETLB_PAGE is not set 836# CONFIG_HUGETLB_PAGE is not set
805CONFIG_RAMFS=y 837CONFIG_RAMFS=y
806CONFIG_RELAYFS_FS=m 838CONFIG_RELAYFS_FS=m
839# CONFIG_CONFIGFS_FS is not set
807 840
808# 841#
809# Miscellaneous filesystems 842# Miscellaneous filesystems
@@ -908,6 +941,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
908# Kernel hacking 941# Kernel hacking
909# 942#
910# CONFIG_PRINTK_TIME is not set 943# CONFIG_PRINTK_TIME is not set
944# CONFIG_MAGIC_SYSRQ is not set
911# CONFIG_DEBUG_KERNEL is not set 945# CONFIG_DEBUG_KERNEL is not set
912CONFIG_LOG_BUF_SHIFT=14 946CONFIG_LOG_BUF_SHIFT=14
913CONFIG_CROSSCOMPILE=y 947CONFIG_CROSSCOMPILE=y
@@ -962,3 +996,7 @@ CONFIG_CRC32=y
962CONFIG_LIBCRC32C=m 996CONFIG_LIBCRC32C=m
963CONFIG_ZLIB_INFLATE=m 997CONFIG_ZLIB_INFLATE=m
964CONFIG_ZLIB_DEFLATE=m 998CONFIG_ZLIB_DEFLATE=m
999CONFIG_TEXTSEARCH=y
1000CONFIG_TEXTSEARCH_KMP=m
1001CONFIG_TEXTSEARCH_BM=m
1002CONFIG_TEXTSEARCH_FSM=m
diff --git a/arch/mips/configs/db1200_defconfig b/arch/mips/configs/db1200_defconfig
index 0e5de7d05f23..92888472dca0 100644
--- a/arch/mips/configs/db1200_defconfig
+++ b/arch/mips/configs/db1200_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:03 2005 4# Fri Jan 27 15:39:58 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -151,27 +151,30 @@ CONFIG_SYSVIPC=y
151# CONFIG_BSD_PROCESS_ACCT is not set 151# CONFIG_BSD_PROCESS_ACCT is not set
152CONFIG_SYSCTL=y 152CONFIG_SYSCTL=y
153# CONFIG_AUDIT is not set 153# CONFIG_AUDIT is not set
154CONFIG_HOTPLUG=y
155CONFIG_KOBJECT_UEVENT=y
156CONFIG_IKCONFIG=y 154CONFIG_IKCONFIG=y
157CONFIG_IKCONFIG_PROC=y 155CONFIG_IKCONFIG_PROC=y
158CONFIG_INITRAMFS_SOURCE="" 156CONFIG_INITRAMFS_SOURCE=""
157# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
159CONFIG_EMBEDDED=y 158CONFIG_EMBEDDED=y
160CONFIG_KALLSYMS=y 159CONFIG_KALLSYMS=y
161# CONFIG_KALLSYMS_EXTRA_PASS is not set 160# CONFIG_KALLSYMS_EXTRA_PASS is not set
161CONFIG_HOTPLUG=y
162CONFIG_PRINTK=y 162CONFIG_PRINTK=y
163CONFIG_BUG=y 163CONFIG_BUG=y
164CONFIG_ELF_CORE=y
164CONFIG_BASE_FULL=y 165CONFIG_BASE_FULL=y
165CONFIG_FUTEX=y 166CONFIG_FUTEX=y
166CONFIG_EPOLL=y 167CONFIG_EPOLL=y
167# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
168CONFIG_SHMEM=y 168CONFIG_SHMEM=y
169CONFIG_CC_ALIGN_FUNCTIONS=0 169CONFIG_CC_ALIGN_FUNCTIONS=0
170CONFIG_CC_ALIGN_LABELS=0 170CONFIG_CC_ALIGN_LABELS=0
171CONFIG_CC_ALIGN_LOOPS=0 171CONFIG_CC_ALIGN_LOOPS=0
172CONFIG_CC_ALIGN_JUMPS=0 172CONFIG_CC_ALIGN_JUMPS=0
173CONFIG_SLAB=y
173# CONFIG_TINY_SHMEM is not set 174# CONFIG_TINY_SHMEM is not set
174CONFIG_BASE_SMALL=0 175CONFIG_BASE_SMALL=0
176# CONFIG_SLOB is not set
177CONFIG_OBSOLETE_INTERMODULE=y
175 178
176# 179#
177# Loadable module support 180# Loadable module support
@@ -279,6 +282,21 @@ CONFIG_NETFILTER=y
279# 282#
280# CONFIG_NETFILTER_NETLINK is not set 283# CONFIG_NETFILTER_NETLINK is not set
281# CONFIG_NF_CONNTRACK is not set 284# CONFIG_NF_CONNTRACK is not set
285CONFIG_NETFILTER_XTABLES=m
286CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
287CONFIG_NETFILTER_XT_TARGET_MARK=m
288CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
289CONFIG_NETFILTER_XT_MATCH_COMMENT=m
290CONFIG_NETFILTER_XT_MATCH_DCCP=m
291CONFIG_NETFILTER_XT_MATCH_LENGTH=m
292CONFIG_NETFILTER_XT_MATCH_LIMIT=m
293CONFIG_NETFILTER_XT_MATCH_MAC=m
294CONFIG_NETFILTER_XT_MATCH_MARK=m
295CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
296CONFIG_NETFILTER_XT_MATCH_REALM=m
297CONFIG_NETFILTER_XT_MATCH_SCTP=m
298CONFIG_NETFILTER_XT_MATCH_STRING=m
299CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
282 300
283# 301#
284# IP: Netfilter Configuration 302# IP: Netfilter Configuration
@@ -306,6 +324,11 @@ CONFIG_NETFILTER=y
306# CONFIG_ATALK is not set 324# CONFIG_ATALK is not set
307# CONFIG_X25 is not set 325# CONFIG_X25 is not set
308# CONFIG_LAPB is not set 326# CONFIG_LAPB is not set
327
328#
329# TIPC Configuration (EXPERIMENTAL)
330#
331# CONFIG_TIPC is not set
309# CONFIG_NET_DIVERT is not set 332# CONFIG_NET_DIVERT is not set
310# CONFIG_ECONET is not set 333# CONFIG_ECONET is not set
311# CONFIG_WAN_ROUTER is not set 334# CONFIG_WAN_ROUTER is not set
@@ -314,6 +337,7 @@ CONFIG_NETFILTER=y
314# QoS and/or fair queueing 337# QoS and/or fair queueing
315# 338#
316# CONFIG_NET_SCHED is not set 339# CONFIG_NET_SCHED is not set
340CONFIG_NET_CLS_ROUTE=y
317 341
318# 342#
319# Network testing 343# Network testing
@@ -385,6 +409,7 @@ CONFIG_MTD_CFI_UTIL=y
385# CONFIG_MTD_RAM is not set 409# CONFIG_MTD_RAM is not set
386# CONFIG_MTD_ROM is not set 410# CONFIG_MTD_ROM is not set
387# CONFIG_MTD_ABSENT is not set 411# CONFIG_MTD_ABSENT is not set
412# CONFIG_MTD_OBSOLETE_CHIPS is not set
388 413
389# 414#
390# Mapping drivers for chip access 415# Mapping drivers for chip access
@@ -568,6 +593,7 @@ CONFIG_NET_ETHERNET=y
568CONFIG_MII=m 593CONFIG_MII=m
569# CONFIG_MIPS_AU1X00_ENET is not set 594# CONFIG_MIPS_AU1X00_ENET is not set
570# CONFIG_SMC91X is not set 595# CONFIG_SMC91X is not set
596# CONFIG_DM9000 is not set
571 597
572# 598#
573# Ethernet (1000 Mbit) 599# Ethernet (1000 Mbit)
@@ -665,13 +691,13 @@ CONFIG_SERIAL_8250=y
665CONFIG_SERIAL_8250_CONSOLE=y 691CONFIG_SERIAL_8250_CONSOLE=y
666# CONFIG_SERIAL_8250_CS is not set 692# CONFIG_SERIAL_8250_CS is not set
667CONFIG_SERIAL_8250_NR_UARTS=4 693CONFIG_SERIAL_8250_NR_UARTS=4
694CONFIG_SERIAL_8250_RUNTIME_UARTS=4
668# CONFIG_SERIAL_8250_EXTENDED is not set 695# CONFIG_SERIAL_8250_EXTENDED is not set
669CONFIG_SERIAL_8250_AU1X00=y 696CONFIG_SERIAL_8250_AU1X00=y
670 697
671# 698#
672# Non-8250 serial port support 699# Non-8250 serial port support
673# 700#
674# CONFIG_SERIAL_AU1X00 is not set
675CONFIG_SERIAL_CORE=y 701CONFIG_SERIAL_CORE=y
676CONFIG_SERIAL_CORE_CONSOLE=y 702CONFIG_SERIAL_CORE_CONSOLE=y
677CONFIG_UNIX98_PTYS=y 703CONFIG_UNIX98_PTYS=y
@@ -716,6 +742,12 @@ CONFIG_LEGACY_PTY_COUNT=256
716# CONFIG_I2C is not set 742# CONFIG_I2C is not set
717 743
718# 744#
745# SPI support
746#
747# CONFIG_SPI is not set
748# CONFIG_SPI_MASTER is not set
749
750#
719# Dallas's 1-wire bus 751# Dallas's 1-wire bus
720# 752#
721# CONFIG_W1 is not set 753# CONFIG_W1 is not set
@@ -842,6 +874,7 @@ CONFIG_JFS_FS=y
842# CONFIG_JFS_STATISTICS is not set 874# CONFIG_JFS_STATISTICS is not set
843CONFIG_FS_POSIX_ACL=y 875CONFIG_FS_POSIX_ACL=y
844# CONFIG_XFS_FS is not set 876# CONFIG_XFS_FS is not set
877# CONFIG_OCFS2_FS is not set
845# CONFIG_MINIX_FS is not set 878# CONFIG_MINIX_FS is not set
846# CONFIG_ROMFS_FS is not set 879# CONFIG_ROMFS_FS is not set
847CONFIG_INOTIFY=y 880CONFIG_INOTIFY=y
@@ -881,6 +914,7 @@ CONFIG_TMPFS=y
881# CONFIG_HUGETLB_PAGE is not set 914# CONFIG_HUGETLB_PAGE is not set
882CONFIG_RAMFS=y 915CONFIG_RAMFS=y
883# CONFIG_RELAYFS_FS is not set 916# CONFIG_RELAYFS_FS is not set
917# CONFIG_CONFIGFS_FS is not set
884 918
885# 919#
886# Miscellaneous filesystems 920# Miscellaneous filesystems
@@ -990,6 +1024,7 @@ CONFIG_NLS_UTF8=m
990# Kernel hacking 1024# Kernel hacking
991# 1025#
992# CONFIG_PRINTK_TIME is not set 1026# CONFIG_PRINTK_TIME is not set
1027# CONFIG_MAGIC_SYSRQ is not set
993# CONFIG_DEBUG_KERNEL is not set 1028# CONFIG_DEBUG_KERNEL is not set
994CONFIG_LOG_BUF_SHIFT=14 1029CONFIG_LOG_BUF_SHIFT=14
995CONFIG_CROSSCOMPILE=y 1030CONFIG_CROSSCOMPILE=y
@@ -1020,3 +1055,7 @@ CONFIG_CRC32=y
1020CONFIG_LIBCRC32C=y 1055CONFIG_LIBCRC32C=y
1021CONFIG_ZLIB_INFLATE=y 1056CONFIG_ZLIB_INFLATE=y
1022CONFIG_ZLIB_DEFLATE=y 1057CONFIG_ZLIB_DEFLATE=y
1058CONFIG_TEXTSEARCH=y
1059CONFIG_TEXTSEARCH_KMP=m
1060CONFIG_TEXTSEARCH_BM=m
1061CONFIG_TEXTSEARCH_FSM=m
diff --git a/arch/mips/configs/db1500_defconfig b/arch/mips/configs/db1500_defconfig
index 86e7be8412f3..5a415b1d4af0 100644
--- a/arch/mips/configs/db1500_defconfig
+++ b/arch/mips/configs/db1500_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:05 2005 4# Fri Jan 27 15:39:59 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -153,26 +153,29 @@ CONFIG_SYSVIPC=y
153# CONFIG_BSD_PROCESS_ACCT is not set 153# CONFIG_BSD_PROCESS_ACCT is not set
154CONFIG_SYSCTL=y 154CONFIG_SYSCTL=y
155# CONFIG_AUDIT is not set 155# CONFIG_AUDIT is not set
156CONFIG_HOTPLUG=y
157CONFIG_KOBJECT_UEVENT=y
158# CONFIG_IKCONFIG is not set 156# CONFIG_IKCONFIG is not set
159CONFIG_INITRAMFS_SOURCE="" 157CONFIG_INITRAMFS_SOURCE=""
158# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
160CONFIG_EMBEDDED=y 159CONFIG_EMBEDDED=y
161CONFIG_KALLSYMS=y 160CONFIG_KALLSYMS=y
162# CONFIG_KALLSYMS_EXTRA_PASS is not set 161# CONFIG_KALLSYMS_EXTRA_PASS is not set
162CONFIG_HOTPLUG=y
163CONFIG_PRINTK=y 163CONFIG_PRINTK=y
164CONFIG_BUG=y 164CONFIG_BUG=y
165CONFIG_ELF_CORE=y
165CONFIG_BASE_FULL=y 166CONFIG_BASE_FULL=y
166CONFIG_FUTEX=y 167CONFIG_FUTEX=y
167CONFIG_EPOLL=y 168CONFIG_EPOLL=y
168# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
169CONFIG_SHMEM=y 169CONFIG_SHMEM=y
170CONFIG_CC_ALIGN_FUNCTIONS=0 170CONFIG_CC_ALIGN_FUNCTIONS=0
171CONFIG_CC_ALIGN_LABELS=0 171CONFIG_CC_ALIGN_LABELS=0
172CONFIG_CC_ALIGN_LOOPS=0 172CONFIG_CC_ALIGN_LOOPS=0
173CONFIG_CC_ALIGN_JUMPS=0 173CONFIG_CC_ALIGN_JUMPS=0
174CONFIG_SLAB=y
174# CONFIG_TINY_SHMEM is not set 175# CONFIG_TINY_SHMEM is not set
175CONFIG_BASE_SMALL=0 176CONFIG_BASE_SMALL=0
177# CONFIG_SLOB is not set
178CONFIG_OBSOLETE_INTERMODULE=y
176 179
177# 180#
178# Loadable module support 181# Loadable module support
@@ -293,6 +296,21 @@ CONFIG_NETFILTER_NETLINK=m
293CONFIG_NETFILTER_NETLINK_QUEUE=m 296CONFIG_NETFILTER_NETLINK_QUEUE=m
294CONFIG_NETFILTER_NETLINK_LOG=m 297CONFIG_NETFILTER_NETLINK_LOG=m
295# CONFIG_NF_CONNTRACK is not set 298# CONFIG_NF_CONNTRACK is not set
299CONFIG_NETFILTER_XTABLES=m
300CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
301CONFIG_NETFILTER_XT_TARGET_MARK=m
302CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
303CONFIG_NETFILTER_XT_MATCH_COMMENT=m
304CONFIG_NETFILTER_XT_MATCH_DCCP=m
305CONFIG_NETFILTER_XT_MATCH_LENGTH=m
306CONFIG_NETFILTER_XT_MATCH_LIMIT=m
307CONFIG_NETFILTER_XT_MATCH_MAC=m
308CONFIG_NETFILTER_XT_MATCH_MARK=m
309CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
310CONFIG_NETFILTER_XT_MATCH_REALM=m
311CONFIG_NETFILTER_XT_MATCH_SCTP=m
312CONFIG_NETFILTER_XT_MATCH_STRING=m
313CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
296 314
297# 315#
298# IP: Netfilter Configuration 316# IP: Netfilter Configuration
@@ -320,6 +338,11 @@ CONFIG_NETFILTER_NETLINK_LOG=m
320# CONFIG_ATALK is not set 338# CONFIG_ATALK is not set
321# CONFIG_X25 is not set 339# CONFIG_X25 is not set
322# CONFIG_LAPB is not set 340# CONFIG_LAPB is not set
341
342#
343# TIPC Configuration (EXPERIMENTAL)
344#
345# CONFIG_TIPC is not set
323# CONFIG_NET_DIVERT is not set 346# CONFIG_NET_DIVERT is not set
324# CONFIG_ECONET is not set 347# CONFIG_ECONET is not set
325# CONFIG_WAN_ROUTER is not set 348# CONFIG_WAN_ROUTER is not set
@@ -328,6 +351,7 @@ CONFIG_NETFILTER_NETLINK_LOG=m
328# QoS and/or fair queueing 351# QoS and/or fair queueing
329# 352#
330# CONFIG_NET_SCHED is not set 353# CONFIG_NET_SCHED is not set
354CONFIG_NET_CLS_ROUTE=y
331 355
332# 356#
333# Network testing 357# Network testing
@@ -340,7 +364,6 @@ CONFIG_IEEE80211=m
340# CONFIG_IEEE80211_DEBUG is not set 364# CONFIG_IEEE80211_DEBUG is not set
341CONFIG_IEEE80211_CRYPT_WEP=m 365CONFIG_IEEE80211_CRYPT_WEP=m
342CONFIG_IEEE80211_CRYPT_CCMP=m 366CONFIG_IEEE80211_CRYPT_CCMP=m
343CONFIG_IEEE80211_CRYPT_TKIP=m
344 367
345# 368#
346# Device Drivers 369# Device Drivers
@@ -403,6 +426,7 @@ CONFIG_MTD_CFI_UTIL=y
403# CONFIG_MTD_RAM is not set 426# CONFIG_MTD_RAM is not set
404# CONFIG_MTD_ROM is not set 427# CONFIG_MTD_ROM is not set
405# CONFIG_MTD_ABSENT is not set 428# CONFIG_MTD_ABSENT is not set
429# CONFIG_MTD_OBSOLETE_CHIPS is not set
406 430
407# 431#
408# Mapping drivers for chip access 432# Mapping drivers for chip access
@@ -561,6 +585,7 @@ CONFIG_MIPS_AU1X00_ENET=y
561# CONFIG_CASSINI is not set 585# CONFIG_CASSINI is not set
562# CONFIG_NET_VENDOR_3COM is not set 586# CONFIG_NET_VENDOR_3COM is not set
563# CONFIG_SMC91X is not set 587# CONFIG_SMC91X is not set
588# CONFIG_DM9000 is not set
564 589
565# 590#
566# Tulip family network device support 591# Tulip family network device support
@@ -581,6 +606,7 @@ CONFIG_MIPS_AU1X00_ENET=y
581# CONFIG_R8169 is not set 606# CONFIG_R8169 is not set
582# CONFIG_SIS190 is not set 607# CONFIG_SIS190 is not set
583# CONFIG_SKGE is not set 608# CONFIG_SKGE is not set
609# CONFIG_SKY2 is not set
584# CONFIG_SK98LIN is not set 610# CONFIG_SK98LIN is not set
585# CONFIG_TIGON3 is not set 611# CONFIG_TIGON3 is not set
586# CONFIG_BNX2 is not set 612# CONFIG_BNX2 is not set
@@ -601,8 +627,6 @@ CONFIG_MIPS_AU1X00_ENET=y
601# Wireless LAN (non-hamradio) 627# Wireless LAN (non-hamradio)
602# 628#
603# CONFIG_NET_RADIO is not set 629# CONFIG_NET_RADIO is not set
604# CONFIG_IPW_DEBUG is not set
605CONFIG_IPW2200=m
606 630
607# 631#
608# PCMCIA network device support 632# PCMCIA network device support
@@ -692,16 +716,15 @@ CONFIG_SERIAL_8250=y
692CONFIG_SERIAL_8250_CONSOLE=y 716CONFIG_SERIAL_8250_CONSOLE=y
693# CONFIG_SERIAL_8250_CS is not set 717# CONFIG_SERIAL_8250_CS is not set
694CONFIG_SERIAL_8250_NR_UARTS=4 718CONFIG_SERIAL_8250_NR_UARTS=4
719CONFIG_SERIAL_8250_RUNTIME_UARTS=4
695# CONFIG_SERIAL_8250_EXTENDED is not set 720# CONFIG_SERIAL_8250_EXTENDED is not set
696CONFIG_SERIAL_8250_AU1X00=y 721CONFIG_SERIAL_8250_AU1X00=y
697 722
698# 723#
699# Non-8250 serial port support 724# Non-8250 serial port support
700# 725#
701# CONFIG_SERIAL_AU1X00 is not set
702CONFIG_SERIAL_CORE=y 726CONFIG_SERIAL_CORE=y
703CONFIG_SERIAL_CORE_CONSOLE=y 727CONFIG_SERIAL_CORE_CONSOLE=y
704# CONFIG_SERIAL_JSM is not set
705CONFIG_UNIX98_PTYS=y 728CONFIG_UNIX98_PTYS=y
706CONFIG_LEGACY_PTYS=y 729CONFIG_LEGACY_PTYS=y
707CONFIG_LEGACY_PTY_COUNT=256 730CONFIG_LEGACY_PTY_COUNT=256
@@ -746,6 +769,12 @@ CONFIG_SYNCLINK_CS=m
746# CONFIG_I2C is not set 769# CONFIG_I2C is not set
747 770
748# 771#
772# SPI support
773#
774# CONFIG_SPI is not set
775# CONFIG_SPI_MASTER is not set
776
777#
749# Dallas's 1-wire bus 778# Dallas's 1-wire bus
750# 779#
751# CONFIG_W1 is not set 780# CONFIG_W1 is not set
@@ -788,8 +817,6 @@ CONFIG_SOUND=y
788# Advanced Linux Sound Architecture 817# Advanced Linux Sound Architecture
789# 818#
790CONFIG_SND=m 819CONFIG_SND=m
791CONFIG_SND_AC97_CODEC=m
792CONFIG_SND_AC97_BUS=m
793CONFIG_SND_TIMER=m 820CONFIG_SND_TIMER=m
794CONFIG_SND_PCM=m 821CONFIG_SND_PCM=m
795CONFIG_SND_RAWMIDI=m 822CONFIG_SND_RAWMIDI=m
@@ -799,13 +826,16 @@ CONFIG_SND_OSSEMUL=y
799CONFIG_SND_MIXER_OSS=m 826CONFIG_SND_MIXER_OSS=m
800CONFIG_SND_PCM_OSS=m 827CONFIG_SND_PCM_OSS=m
801CONFIG_SND_SEQUENCER_OSS=y 828CONFIG_SND_SEQUENCER_OSS=y
829# CONFIG_SND_DYNAMIC_MINORS is not set
830CONFIG_SND_SUPPORT_OLD_API=y
802# CONFIG_SND_VERBOSE_PRINTK is not set 831# CONFIG_SND_VERBOSE_PRINTK is not set
803# CONFIG_SND_DEBUG is not set 832# CONFIG_SND_DEBUG is not set
804CONFIG_SND_GENERIC_DRIVER=y
805 833
806# 834#
807# Generic devices 835# Generic devices
808# 836#
837CONFIG_SND_AC97_CODEC=m
838CONFIG_SND_AC97_BUS=m
809# CONFIG_SND_DUMMY is not set 839# CONFIG_SND_DUMMY is not set
810CONFIG_SND_VIRMIDI=m 840CONFIG_SND_VIRMIDI=m
811CONFIG_SND_MTPAV=m 841CONFIG_SND_MTPAV=m
@@ -815,6 +845,7 @@ CONFIG_SND_MTPAV=m
815# 845#
816# PCI devices 846# PCI devices
817# 847#
848# CONFIG_SND_AD1889 is not set
818# CONFIG_SND_ALI5451 is not set 849# CONFIG_SND_ALI5451 is not set
819# CONFIG_SND_ATIIXP is not set 850# CONFIG_SND_ATIIXP is not set
820# CONFIG_SND_ATIIXP_MODEM is not set 851# CONFIG_SND_ATIIXP_MODEM is not set
@@ -823,38 +854,38 @@ CONFIG_SND_MTPAV=m
823# CONFIG_SND_AU8830 is not set 854# CONFIG_SND_AU8830 is not set
824# CONFIG_SND_AZT3328 is not set 855# CONFIG_SND_AZT3328 is not set
825# CONFIG_SND_BT87X is not set 856# CONFIG_SND_BT87X is not set
826# CONFIG_SND_CS46XX is not set 857# CONFIG_SND_CA0106 is not set
858# CONFIG_SND_CMIPCI is not set
827# CONFIG_SND_CS4281 is not set 859# CONFIG_SND_CS4281 is not set
860# CONFIG_SND_CS46XX is not set
828# CONFIG_SND_EMU10K1 is not set 861# CONFIG_SND_EMU10K1 is not set
829# CONFIG_SND_EMU10K1X is not set 862# CONFIG_SND_EMU10K1X is not set
830# CONFIG_SND_CA0106 is not set
831# CONFIG_SND_KORG1212 is not set
832# CONFIG_SND_MIXART is not set
833# CONFIG_SND_NM256 is not set
834# CONFIG_SND_RME32 is not set
835# CONFIG_SND_RME96 is not set
836# CONFIG_SND_RME9652 is not set
837# CONFIG_SND_HDSP is not set
838# CONFIG_SND_HDSPM is not set
839# CONFIG_SND_TRIDENT is not set
840# CONFIG_SND_YMFPCI is not set
841# CONFIG_SND_AD1889 is not set
842# CONFIG_SND_CMIPCI is not set
843# CONFIG_SND_ENS1370 is not set 863# CONFIG_SND_ENS1370 is not set
844# CONFIG_SND_ENS1371 is not set 864# CONFIG_SND_ENS1371 is not set
845# CONFIG_SND_ES1938 is not set 865# CONFIG_SND_ES1938 is not set
846# CONFIG_SND_ES1968 is not set 866# CONFIG_SND_ES1968 is not set
847# CONFIG_SND_MAESTRO3 is not set
848# CONFIG_SND_FM801 is not set 867# CONFIG_SND_FM801 is not set
868# CONFIG_SND_HDA_INTEL is not set
869# CONFIG_SND_HDSP is not set
870# CONFIG_SND_HDSPM is not set
849# CONFIG_SND_ICE1712 is not set 871# CONFIG_SND_ICE1712 is not set
850# CONFIG_SND_ICE1724 is not set 872# CONFIG_SND_ICE1724 is not set
851# CONFIG_SND_INTEL8X0 is not set 873# CONFIG_SND_INTEL8X0 is not set
852# CONFIG_SND_INTEL8X0M is not set 874# CONFIG_SND_INTEL8X0M is not set
875# CONFIG_SND_KORG1212 is not set
876# CONFIG_SND_MAESTRO3 is not set
877# CONFIG_SND_MIXART is not set
878# CONFIG_SND_NM256 is not set
879# CONFIG_SND_PCXHR is not set
880# CONFIG_SND_RME32 is not set
881# CONFIG_SND_RME96 is not set
882# CONFIG_SND_RME9652 is not set
853# CONFIG_SND_SONICVIBES is not set 883# CONFIG_SND_SONICVIBES is not set
884# CONFIG_SND_TRIDENT is not set
854# CONFIG_SND_VIA82XX is not set 885# CONFIG_SND_VIA82XX is not set
855# CONFIG_SND_VIA82XX_MODEM is not set 886# CONFIG_SND_VIA82XX_MODEM is not set
856# CONFIG_SND_VX222 is not set 887# CONFIG_SND_VX222 is not set
857# CONFIG_SND_HDA_INTEL is not set 888# CONFIG_SND_YMFPCI is not set
858 889
859# 890#
860# ALSA MIPS devices 891# ALSA MIPS devices
@@ -939,12 +970,14 @@ CONFIG_USB_OHCI_LITTLE_ENDIAN=y
939# may also be needed; see USB_STORAGE Help for more information 970# may also be needed; see USB_STORAGE Help for more information
940# 971#
941# CONFIG_USB_STORAGE is not set 972# CONFIG_USB_STORAGE is not set
973# CONFIG_USB_LIBUSUAL is not set
942 974
943# 975#
944# USB Input Devices 976# USB Input Devices
945# 977#
946CONFIG_USB_HID=y 978CONFIG_USB_HID=y
947CONFIG_USB_HIDINPUT=y 979CONFIG_USB_HIDINPUT=y
980# CONFIG_USB_HIDINPUT_POWERBOOK is not set
948# CONFIG_HID_FF is not set 981# CONFIG_HID_FF is not set
949# CONFIG_USB_HIDDEV is not set 982# CONFIG_USB_HIDDEV is not set
950# CONFIG_USB_AIPTEK is not set 983# CONFIG_USB_AIPTEK is not set
@@ -958,6 +991,7 @@ CONFIG_USB_HIDINPUT=y
958CONFIG_USB_YEALINK=m 991CONFIG_USB_YEALINK=m
959# CONFIG_USB_XPAD is not set 992# CONFIG_USB_XPAD is not set
960# CONFIG_USB_ATI_REMOTE is not set 993# CONFIG_USB_ATI_REMOTE is not set
994# CONFIG_USB_ATI_REMOTE2 is not set
961# CONFIG_USB_KEYSPAN_REMOTE is not set 995# CONFIG_USB_KEYSPAN_REMOTE is not set
962# CONFIG_USB_APPLETOUCH is not set 996# CONFIG_USB_APPLETOUCH is not set
963 997
@@ -1057,6 +1091,7 @@ CONFIG_REISERFS_FS_SECURITY=y
1057# CONFIG_JFS_FS is not set 1091# CONFIG_JFS_FS is not set
1058CONFIG_FS_POSIX_ACL=y 1092CONFIG_FS_POSIX_ACL=y
1059# CONFIG_XFS_FS is not set 1093# CONFIG_XFS_FS is not set
1094# CONFIG_OCFS2_FS is not set
1060# CONFIG_MINIX_FS is not set 1095# CONFIG_MINIX_FS is not set
1061# CONFIG_ROMFS_FS is not set 1096# CONFIG_ROMFS_FS is not set
1062CONFIG_INOTIFY=y 1097CONFIG_INOTIFY=y
@@ -1089,6 +1124,7 @@ CONFIG_TMPFS=y
1089# CONFIG_HUGETLB_PAGE is not set 1124# CONFIG_HUGETLB_PAGE is not set
1090CONFIG_RAMFS=y 1125CONFIG_RAMFS=y
1091CONFIG_RELAYFS_FS=m 1126CONFIG_RELAYFS_FS=m
1127# CONFIG_CONFIGFS_FS is not set
1092 1128
1093# 1129#
1094# Miscellaneous filesystems 1130# Miscellaneous filesystems
@@ -1193,6 +1229,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
1193# Kernel hacking 1229# Kernel hacking
1194# 1230#
1195# CONFIG_PRINTK_TIME is not set 1231# CONFIG_PRINTK_TIME is not set
1232# CONFIG_MAGIC_SYSRQ is not set
1196# CONFIG_DEBUG_KERNEL is not set 1233# CONFIG_DEBUG_KERNEL is not set
1197CONFIG_LOG_BUF_SHIFT=14 1234CONFIG_LOG_BUF_SHIFT=14
1198CONFIG_CROSSCOMPILE=y 1235CONFIG_CROSSCOMPILE=y
@@ -1247,3 +1284,7 @@ CONFIG_CRC32=y
1247CONFIG_LIBCRC32C=m 1284CONFIG_LIBCRC32C=m
1248CONFIG_ZLIB_INFLATE=m 1285CONFIG_ZLIB_INFLATE=m
1249CONFIG_ZLIB_DEFLATE=m 1286CONFIG_ZLIB_DEFLATE=m
1287CONFIG_TEXTSEARCH=y
1288CONFIG_TEXTSEARCH_KMP=m
1289CONFIG_TEXTSEARCH_BM=m
1290CONFIG_TEXTSEARCH_FSM=m
diff --git a/arch/mips/configs/db1550_defconfig b/arch/mips/configs/db1550_defconfig
index ea5ab0ca5774..8dc1f18badfe 100644
--- a/arch/mips/configs/db1550_defconfig
+++ b/arch/mips/configs/db1550_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:07 2005 4# Fri Jan 27 15:40:00 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -152,26 +152,29 @@ CONFIG_SYSVIPC=y
152# CONFIG_BSD_PROCESS_ACCT is not set 152# CONFIG_BSD_PROCESS_ACCT is not set
153CONFIG_SYSCTL=y 153CONFIG_SYSCTL=y
154# CONFIG_AUDIT is not set 154# CONFIG_AUDIT is not set
155CONFIG_HOTPLUG=y
156CONFIG_KOBJECT_UEVENT=y
157# CONFIG_IKCONFIG is not set 155# CONFIG_IKCONFIG is not set
158CONFIG_INITRAMFS_SOURCE="" 156CONFIG_INITRAMFS_SOURCE=""
157# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
159CONFIG_EMBEDDED=y 158CONFIG_EMBEDDED=y
160CONFIG_KALLSYMS=y 159CONFIG_KALLSYMS=y
161# CONFIG_KALLSYMS_EXTRA_PASS is not set 160# CONFIG_KALLSYMS_EXTRA_PASS is not set
161CONFIG_HOTPLUG=y
162CONFIG_PRINTK=y 162CONFIG_PRINTK=y
163CONFIG_BUG=y 163CONFIG_BUG=y
164CONFIG_ELF_CORE=y
164CONFIG_BASE_FULL=y 165CONFIG_BASE_FULL=y
165CONFIG_FUTEX=y 166CONFIG_FUTEX=y
166CONFIG_EPOLL=y 167CONFIG_EPOLL=y
167# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
168CONFIG_SHMEM=y 168CONFIG_SHMEM=y
169CONFIG_CC_ALIGN_FUNCTIONS=0 169CONFIG_CC_ALIGN_FUNCTIONS=0
170CONFIG_CC_ALIGN_LABELS=0 170CONFIG_CC_ALIGN_LABELS=0
171CONFIG_CC_ALIGN_LOOPS=0 171CONFIG_CC_ALIGN_LOOPS=0
172CONFIG_CC_ALIGN_JUMPS=0 172CONFIG_CC_ALIGN_JUMPS=0
173CONFIG_SLAB=y
173# CONFIG_TINY_SHMEM is not set 174# CONFIG_TINY_SHMEM is not set
174CONFIG_BASE_SMALL=0 175CONFIG_BASE_SMALL=0
176# CONFIG_SLOB is not set
177CONFIG_OBSOLETE_INTERMODULE=y
175 178
176# 179#
177# Loadable module support 180# Loadable module support
@@ -292,6 +295,21 @@ CONFIG_NETFILTER_NETLINK=m
292CONFIG_NETFILTER_NETLINK_QUEUE=m 295CONFIG_NETFILTER_NETLINK_QUEUE=m
293CONFIG_NETFILTER_NETLINK_LOG=m 296CONFIG_NETFILTER_NETLINK_LOG=m
294# CONFIG_NF_CONNTRACK is not set 297# CONFIG_NF_CONNTRACK is not set
298CONFIG_NETFILTER_XTABLES=m
299CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
300CONFIG_NETFILTER_XT_TARGET_MARK=m
301CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
302CONFIG_NETFILTER_XT_MATCH_COMMENT=m
303CONFIG_NETFILTER_XT_MATCH_DCCP=m
304CONFIG_NETFILTER_XT_MATCH_LENGTH=m
305CONFIG_NETFILTER_XT_MATCH_LIMIT=m
306CONFIG_NETFILTER_XT_MATCH_MAC=m
307CONFIG_NETFILTER_XT_MATCH_MARK=m
308CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
309CONFIG_NETFILTER_XT_MATCH_REALM=m
310CONFIG_NETFILTER_XT_MATCH_SCTP=m
311CONFIG_NETFILTER_XT_MATCH_STRING=m
312CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
295 313
296# 314#
297# IP: Netfilter Configuration 315# IP: Netfilter Configuration
@@ -319,6 +337,11 @@ CONFIG_NETFILTER_NETLINK_LOG=m
319# CONFIG_ATALK is not set 337# CONFIG_ATALK is not set
320# CONFIG_X25 is not set 338# CONFIG_X25 is not set
321# CONFIG_LAPB is not set 339# CONFIG_LAPB is not set
340
341#
342# TIPC Configuration (EXPERIMENTAL)
343#
344# CONFIG_TIPC is not set
322# CONFIG_NET_DIVERT is not set 345# CONFIG_NET_DIVERT is not set
323# CONFIG_ECONET is not set 346# CONFIG_ECONET is not set
324# CONFIG_WAN_ROUTER is not set 347# CONFIG_WAN_ROUTER is not set
@@ -327,6 +350,7 @@ CONFIG_NETFILTER_NETLINK_LOG=m
327# QoS and/or fair queueing 350# QoS and/or fair queueing
328# 351#
329# CONFIG_NET_SCHED is not set 352# CONFIG_NET_SCHED is not set
353CONFIG_NET_CLS_ROUTE=y
330 354
331# 355#
332# Network testing 356# Network testing
@@ -339,7 +363,6 @@ CONFIG_IEEE80211=m
339# CONFIG_IEEE80211_DEBUG is not set 363# CONFIG_IEEE80211_DEBUG is not set
340CONFIG_IEEE80211_CRYPT_WEP=m 364CONFIG_IEEE80211_CRYPT_WEP=m
341CONFIG_IEEE80211_CRYPT_CCMP=m 365CONFIG_IEEE80211_CRYPT_CCMP=m
342CONFIG_IEEE80211_CRYPT_TKIP=m
343 366
344# 367#
345# Device Drivers 368# Device Drivers
@@ -402,6 +425,7 @@ CONFIG_MTD_CFI_UTIL=y
402# CONFIG_MTD_RAM is not set 425# CONFIG_MTD_RAM is not set
403# CONFIG_MTD_ROM is not set 426# CONFIG_MTD_ROM is not set
404# CONFIG_MTD_ABSENT is not set 427# CONFIG_MTD_ABSENT is not set
428# CONFIG_MTD_OBSOLETE_CHIPS is not set
405 429
406# 430#
407# Mapping drivers for chip access 431# Mapping drivers for chip access
@@ -593,6 +617,7 @@ CONFIG_MIPS_AU1X00_ENET=y
593# CONFIG_CASSINI is not set 617# CONFIG_CASSINI is not set
594# CONFIG_NET_VENDOR_3COM is not set 618# CONFIG_NET_VENDOR_3COM is not set
595# CONFIG_SMC91X is not set 619# CONFIG_SMC91X is not set
620# CONFIG_DM9000 is not set
596 621
597# 622#
598# Tulip family network device support 623# Tulip family network device support
@@ -613,6 +638,7 @@ CONFIG_MIPS_AU1X00_ENET=y
613# CONFIG_R8169 is not set 638# CONFIG_R8169 is not set
614# CONFIG_SIS190 is not set 639# CONFIG_SIS190 is not set
615# CONFIG_SKGE is not set 640# CONFIG_SKGE is not set
641# CONFIG_SKY2 is not set
616# CONFIG_SK98LIN is not set 642# CONFIG_SK98LIN is not set
617# CONFIG_TIGON3 is not set 643# CONFIG_TIGON3 is not set
618# CONFIG_BNX2 is not set 644# CONFIG_BNX2 is not set
@@ -633,8 +659,6 @@ CONFIG_MIPS_AU1X00_ENET=y
633# Wireless LAN (non-hamradio) 659# Wireless LAN (non-hamradio)
634# 660#
635# CONFIG_NET_RADIO is not set 661# CONFIG_NET_RADIO is not set
636# CONFIG_IPW_DEBUG is not set
637CONFIG_IPW2200=m
638 662
639# 663#
640# PCMCIA network device support 664# PCMCIA network device support
@@ -732,16 +756,15 @@ CONFIG_SERIAL_8250=y
732CONFIG_SERIAL_8250_CONSOLE=y 756CONFIG_SERIAL_8250_CONSOLE=y
733# CONFIG_SERIAL_8250_CS is not set 757# CONFIG_SERIAL_8250_CS is not set
734CONFIG_SERIAL_8250_NR_UARTS=4 758CONFIG_SERIAL_8250_NR_UARTS=4
759CONFIG_SERIAL_8250_RUNTIME_UARTS=4
735# CONFIG_SERIAL_8250_EXTENDED is not set 760# CONFIG_SERIAL_8250_EXTENDED is not set
736CONFIG_SERIAL_8250_AU1X00=y 761CONFIG_SERIAL_8250_AU1X00=y
737 762
738# 763#
739# Non-8250 serial port support 764# Non-8250 serial port support
740# 765#
741# CONFIG_SERIAL_AU1X00 is not set
742CONFIG_SERIAL_CORE=y 766CONFIG_SERIAL_CORE=y
743CONFIG_SERIAL_CORE_CONSOLE=y 767CONFIG_SERIAL_CORE_CONSOLE=y
744# CONFIG_SERIAL_JSM is not set
745CONFIG_UNIX98_PTYS=y 768CONFIG_UNIX98_PTYS=y
746CONFIG_LEGACY_PTYS=y 769CONFIG_LEGACY_PTYS=y
747CONFIG_LEGACY_PTY_COUNT=256 770CONFIG_LEGACY_PTY_COUNT=256
@@ -786,6 +809,12 @@ CONFIG_SYNCLINK_CS=m
786# CONFIG_I2C is not set 809# CONFIG_I2C is not set
787 810
788# 811#
812# SPI support
813#
814# CONFIG_SPI is not set
815# CONFIG_SPI_MASTER is not set
816
817#
789# Dallas's 1-wire bus 818# Dallas's 1-wire bus
790# 819#
791# CONFIG_W1 is not set 820# CONFIG_W1 is not set
@@ -878,6 +907,7 @@ CONFIG_REISERFS_FS_SECURITY=y
878# CONFIG_JFS_FS is not set 907# CONFIG_JFS_FS is not set
879CONFIG_FS_POSIX_ACL=y 908CONFIG_FS_POSIX_ACL=y
880# CONFIG_XFS_FS is not set 909# CONFIG_XFS_FS is not set
910# CONFIG_OCFS2_FS is not set
881# CONFIG_MINIX_FS is not set 911# CONFIG_MINIX_FS is not set
882# CONFIG_ROMFS_FS is not set 912# CONFIG_ROMFS_FS is not set
883CONFIG_INOTIFY=y 913CONFIG_INOTIFY=y
@@ -910,6 +940,7 @@ CONFIG_TMPFS=y
910# CONFIG_HUGETLB_PAGE is not set 940# CONFIG_HUGETLB_PAGE is not set
911CONFIG_RAMFS=y 941CONFIG_RAMFS=y
912CONFIG_RELAYFS_FS=m 942CONFIG_RELAYFS_FS=m
943# CONFIG_CONFIGFS_FS is not set
913 944
914# 945#
915# Miscellaneous filesystems 946# Miscellaneous filesystems
@@ -1014,6 +1045,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
1014# Kernel hacking 1045# Kernel hacking
1015# 1046#
1016# CONFIG_PRINTK_TIME is not set 1047# CONFIG_PRINTK_TIME is not set
1048# CONFIG_MAGIC_SYSRQ is not set
1017# CONFIG_DEBUG_KERNEL is not set 1049# CONFIG_DEBUG_KERNEL is not set
1018CONFIG_LOG_BUF_SHIFT=14 1050CONFIG_LOG_BUF_SHIFT=14
1019CONFIG_CROSSCOMPILE=y 1051CONFIG_CROSSCOMPILE=y
@@ -1068,3 +1100,7 @@ CONFIG_CRC32=y
1068CONFIG_LIBCRC32C=m 1100CONFIG_LIBCRC32C=m
1069CONFIG_ZLIB_INFLATE=m 1101CONFIG_ZLIB_INFLATE=m
1070CONFIG_ZLIB_DEFLATE=m 1102CONFIG_ZLIB_DEFLATE=m
1103CONFIG_TEXTSEARCH=y
1104CONFIG_TEXTSEARCH_KMP=m
1105CONFIG_TEXTSEARCH_BM=m
1106CONFIG_TEXTSEARCH_FSM=m
diff --git a/arch/mips/configs/ddb5476_defconfig b/arch/mips/configs/ddb5476_defconfig
index a81e2de6947f..8fae63e47e5e 100644
--- a/arch/mips/configs/ddb5476_defconfig
+++ b/arch/mips/configs/ddb5476_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:09 2005 4# Fri Jan 27 15:40:02 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -151,26 +151,28 @@ CONFIG_SYSVIPC=y
151# CONFIG_BSD_PROCESS_ACCT is not set 151# CONFIG_BSD_PROCESS_ACCT is not set
152CONFIG_SYSCTL=y 152CONFIG_SYSCTL=y
153# CONFIG_AUDIT is not set 153# CONFIG_AUDIT is not set
154CONFIG_HOTPLUG=y
155CONFIG_KOBJECT_UEVENT=y
156# CONFIG_IKCONFIG is not set 154# CONFIG_IKCONFIG is not set
157CONFIG_INITRAMFS_SOURCE="" 155CONFIG_INITRAMFS_SOURCE=""
156# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
158CONFIG_EMBEDDED=y 157CONFIG_EMBEDDED=y
159CONFIG_KALLSYMS=y 158CONFIG_KALLSYMS=y
160# CONFIG_KALLSYMS_EXTRA_PASS is not set 159# CONFIG_KALLSYMS_EXTRA_PASS is not set
160CONFIG_HOTPLUG=y
161CONFIG_PRINTK=y 161CONFIG_PRINTK=y
162CONFIG_BUG=y 162CONFIG_BUG=y
163CONFIG_ELF_CORE=y
163CONFIG_BASE_FULL=y 164CONFIG_BASE_FULL=y
164CONFIG_FUTEX=y 165CONFIG_FUTEX=y
165CONFIG_EPOLL=y 166CONFIG_EPOLL=y
166# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
167CONFIG_SHMEM=y 167CONFIG_SHMEM=y
168CONFIG_CC_ALIGN_FUNCTIONS=0 168CONFIG_CC_ALIGN_FUNCTIONS=0
169CONFIG_CC_ALIGN_LABELS=0 169CONFIG_CC_ALIGN_LABELS=0
170CONFIG_CC_ALIGN_LOOPS=0 170CONFIG_CC_ALIGN_LOOPS=0
171CONFIG_CC_ALIGN_JUMPS=0 171CONFIG_CC_ALIGN_JUMPS=0
172CONFIG_SLAB=y
172# CONFIG_TINY_SHMEM is not set 173# CONFIG_TINY_SHMEM is not set
173CONFIG_BASE_SMALL=0 174CONFIG_BASE_SMALL=0
175# CONFIG_SLOB is not set
174 176
175# 177#
176# Loadable module support 178# Loadable module support
@@ -276,6 +278,11 @@ CONFIG_TCP_CONG_BIC=y
276# CONFIG_ATALK is not set 278# CONFIG_ATALK is not set
277# CONFIG_X25 is not set 279# CONFIG_X25 is not set
278# CONFIG_LAPB is not set 280# CONFIG_LAPB is not set
281
282#
283# TIPC Configuration (EXPERIMENTAL)
284#
285# CONFIG_TIPC is not set
279# CONFIG_NET_DIVERT is not set 286# CONFIG_NET_DIVERT is not set
280# CONFIG_ECONET is not set 287# CONFIG_ECONET is not set
281# CONFIG_WAN_ROUTER is not set 288# CONFIG_WAN_ROUTER is not set
@@ -296,7 +303,6 @@ CONFIG_IEEE80211=y
296# CONFIG_IEEE80211_DEBUG is not set 303# CONFIG_IEEE80211_DEBUG is not set
297CONFIG_IEEE80211_CRYPT_WEP=y 304CONFIG_IEEE80211_CRYPT_WEP=y
298CONFIG_IEEE80211_CRYPT_CCMP=y 305CONFIG_IEEE80211_CRYPT_CCMP=y
299CONFIG_IEEE80211_CRYPT_TKIP=y
300 306
301# 307#
302# Device Drivers 308# Device Drivers
@@ -445,6 +451,7 @@ CONFIG_NET_ETHERNET=y
445# CONFIG_CASSINI is not set 451# CONFIG_CASSINI is not set
446# CONFIG_NET_VENDOR_3COM is not set 452# CONFIG_NET_VENDOR_3COM is not set
447# CONFIG_NET_VENDOR_SMC is not set 453# CONFIG_NET_VENDOR_SMC is not set
454# CONFIG_DM9000 is not set
448# CONFIG_NET_VENDOR_RACAL is not set 455# CONFIG_NET_VENDOR_RACAL is not set
449 456
450# 457#
@@ -469,6 +476,7 @@ CONFIG_NET_ETHERNET=y
469# CONFIG_R8169 is not set 476# CONFIG_R8169 is not set
470# CONFIG_SIS190 is not set 477# CONFIG_SIS190 is not set
471# CONFIG_SKGE is not set 478# CONFIG_SKGE is not set
479# CONFIG_SKY2 is not set
472# CONFIG_SK98LIN is not set 480# CONFIG_SK98LIN is not set
473# CONFIG_TIGON3 is not set 481# CONFIG_TIGON3 is not set
474# CONFIG_BNX2 is not set 482# CONFIG_BNX2 is not set
@@ -489,8 +497,6 @@ CONFIG_NET_ETHERNET=y
489# Wireless LAN (non-hamradio) 497# Wireless LAN (non-hamradio)
490# 498#
491# CONFIG_NET_RADIO is not set 499# CONFIG_NET_RADIO is not set
492# CONFIG_IPW_DEBUG is not set
493CONFIG_IPW2200=y
494 500
495# 501#
496# Wan interfaces 502# Wan interfaces
@@ -566,6 +572,7 @@ CONFIG_HW_CONSOLE=y
566CONFIG_SERIAL_8250=y 572CONFIG_SERIAL_8250=y
567CONFIG_SERIAL_8250_CONSOLE=y 573CONFIG_SERIAL_8250_CONSOLE=y
568CONFIG_SERIAL_8250_NR_UARTS=4 574CONFIG_SERIAL_8250_NR_UARTS=4
575CONFIG_SERIAL_8250_RUNTIME_UARTS=4
569# CONFIG_SERIAL_8250_EXTENDED is not set 576# CONFIG_SERIAL_8250_EXTENDED is not set
570 577
571# 578#
@@ -573,7 +580,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
573# 580#
574CONFIG_SERIAL_CORE=y 581CONFIG_SERIAL_CORE=y
575CONFIG_SERIAL_CORE_CONSOLE=y 582CONFIG_SERIAL_CORE_CONSOLE=y
576# CONFIG_SERIAL_JSM is not set
577CONFIG_UNIX98_PTYS=y 583CONFIG_UNIX98_PTYS=y
578CONFIG_LEGACY_PTYS=y 584CONFIG_LEGACY_PTYS=y
579CONFIG_LEGACY_PTY_COUNT=256 585CONFIG_LEGACY_PTY_COUNT=256
@@ -611,6 +617,12 @@ CONFIG_LEGACY_PTY_COUNT=256
611# CONFIG_I2C is not set 617# CONFIG_I2C is not set
612 618
613# 619#
620# SPI support
621#
622# CONFIG_SPI is not set
623# CONFIG_SPI_MASTER is not set
624
625#
614# Dallas's 1-wire bus 626# Dallas's 1-wire bus
615# 627#
616# CONFIG_W1 is not set 628# CONFIG_W1 is not set
@@ -669,7 +681,6 @@ CONFIG_FB=y
669# CONFIG_FB_3DFX is not set 681# CONFIG_FB_3DFX is not set
670# CONFIG_FB_VOODOO1 is not set 682# CONFIG_FB_VOODOO1 is not set
671# CONFIG_FB_SMIVGX is not set 683# CONFIG_FB_SMIVGX is not set
672# CONFIG_FB_CYBLA is not set
673# CONFIG_FB_TRIDENT is not set 684# CONFIG_FB_TRIDENT is not set
674# CONFIG_FB_VIRTUAL is not set 685# CONFIG_FB_VIRTUAL is not set
675 686
@@ -729,11 +740,11 @@ CONFIG_EXT2_FS=y
729# CONFIG_EXT2_FS_XATTR is not set 740# CONFIG_EXT2_FS_XATTR is not set
730# CONFIG_EXT2_FS_XIP is not set 741# CONFIG_EXT2_FS_XIP is not set
731# CONFIG_EXT3_FS is not set 742# CONFIG_EXT3_FS is not set
732# CONFIG_JBD is not set
733# CONFIG_REISERFS_FS is not set 743# CONFIG_REISERFS_FS is not set
734# CONFIG_JFS_FS is not set 744# CONFIG_JFS_FS is not set
735# CONFIG_FS_POSIX_ACL is not set 745# CONFIG_FS_POSIX_ACL is not set
736# CONFIG_XFS_FS is not set 746# CONFIG_XFS_FS is not set
747# CONFIG_OCFS2_FS is not set
737# CONFIG_MINIX_FS is not set 748# CONFIG_MINIX_FS is not set
738# CONFIG_ROMFS_FS is not set 749# CONFIG_ROMFS_FS is not set
739CONFIG_INOTIFY=y 750CONFIG_INOTIFY=y
@@ -766,6 +777,7 @@ CONFIG_SYSFS=y
766# CONFIG_HUGETLB_PAGE is not set 777# CONFIG_HUGETLB_PAGE is not set
767CONFIG_RAMFS=y 778CONFIG_RAMFS=y
768CONFIG_RELAYFS_FS=y 779CONFIG_RELAYFS_FS=y
780# CONFIG_CONFIGFS_FS is not set
769 781
770# 782#
771# Miscellaneous filesystems 783# Miscellaneous filesystems
@@ -825,6 +837,7 @@ CONFIG_MSDOS_PARTITION=y
825# Kernel hacking 837# Kernel hacking
826# 838#
827# CONFIG_PRINTK_TIME is not set 839# CONFIG_PRINTK_TIME is not set
840# CONFIG_MAGIC_SYSRQ is not set
828# CONFIG_DEBUG_KERNEL is not set 841# CONFIG_DEBUG_KERNEL is not set
829CONFIG_LOG_BUF_SHIFT=14 842CONFIG_LOG_BUF_SHIFT=14
830CONFIG_CROSSCOMPILE=y 843CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/ddb5477_defconfig b/arch/mips/configs/ddb5477_defconfig
index f1c27c2fb033..a0fcd44e7709 100644
--- a/arch/mips/configs/ddb5477_defconfig
+++ b/arch/mips/configs/ddb5477_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:11 2005 4# Fri Jan 27 15:40:02 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -151,26 +151,28 @@ CONFIG_SYSVIPC=y
151# CONFIG_BSD_PROCESS_ACCT is not set 151# CONFIG_BSD_PROCESS_ACCT is not set
152CONFIG_SYSCTL=y 152CONFIG_SYSCTL=y
153# CONFIG_AUDIT is not set 153# CONFIG_AUDIT is not set
154CONFIG_HOTPLUG=y
155CONFIG_KOBJECT_UEVENT=y
156# CONFIG_IKCONFIG is not set 154# CONFIG_IKCONFIG is not set
157CONFIG_INITRAMFS_SOURCE="" 155CONFIG_INITRAMFS_SOURCE=""
156# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
158CONFIG_EMBEDDED=y 157CONFIG_EMBEDDED=y
159CONFIG_KALLSYMS=y 158CONFIG_KALLSYMS=y
160# CONFIG_KALLSYMS_EXTRA_PASS is not set 159# CONFIG_KALLSYMS_EXTRA_PASS is not set
160CONFIG_HOTPLUG=y
161CONFIG_PRINTK=y 161CONFIG_PRINTK=y
162CONFIG_BUG=y 162CONFIG_BUG=y
163CONFIG_ELF_CORE=y
163CONFIG_BASE_FULL=y 164CONFIG_BASE_FULL=y
164CONFIG_FUTEX=y 165CONFIG_FUTEX=y
165CONFIG_EPOLL=y 166CONFIG_EPOLL=y
166# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
167CONFIG_SHMEM=y 167CONFIG_SHMEM=y
168CONFIG_CC_ALIGN_FUNCTIONS=0 168CONFIG_CC_ALIGN_FUNCTIONS=0
169CONFIG_CC_ALIGN_LABELS=0 169CONFIG_CC_ALIGN_LABELS=0
170CONFIG_CC_ALIGN_LOOPS=0 170CONFIG_CC_ALIGN_LOOPS=0
171CONFIG_CC_ALIGN_JUMPS=0 171CONFIG_CC_ALIGN_JUMPS=0
172CONFIG_SLAB=y
172# CONFIG_TINY_SHMEM is not set 173# CONFIG_TINY_SHMEM is not set
173CONFIG_BASE_SMALL=0 174CONFIG_BASE_SMALL=0
175# CONFIG_SLOB is not set
174 176
175# 177#
176# Loadable module support 178# Loadable module support
@@ -275,6 +277,11 @@ CONFIG_TCP_CONG_BIC=y
275# CONFIG_ATALK is not set 277# CONFIG_ATALK is not set
276# CONFIG_X25 is not set 278# CONFIG_X25 is not set
277# CONFIG_LAPB is not set 279# CONFIG_LAPB is not set
280
281#
282# TIPC Configuration (EXPERIMENTAL)
283#
284# CONFIG_TIPC is not set
278# CONFIG_NET_DIVERT is not set 285# CONFIG_NET_DIVERT is not set
279# CONFIG_ECONET is not set 286# CONFIG_ECONET is not set
280# CONFIG_WAN_ROUTER is not set 287# CONFIG_WAN_ROUTER is not set
@@ -295,7 +302,6 @@ CONFIG_IEEE80211=y
295# CONFIG_IEEE80211_DEBUG is not set 302# CONFIG_IEEE80211_DEBUG is not set
296CONFIG_IEEE80211_CRYPT_WEP=y 303CONFIG_IEEE80211_CRYPT_WEP=y
297CONFIG_IEEE80211_CRYPT_CCMP=y 304CONFIG_IEEE80211_CRYPT_CCMP=y
298CONFIG_IEEE80211_CRYPT_TKIP=y
299 305
300# 306#
301# Device Drivers 307# Device Drivers
@@ -414,6 +420,7 @@ CONFIG_MII=y
414# CONFIG_SUNGEM is not set 420# CONFIG_SUNGEM is not set
415# CONFIG_CASSINI is not set 421# CONFIG_CASSINI is not set
416# CONFIG_NET_VENDOR_3COM is not set 422# CONFIG_NET_VENDOR_3COM is not set
423# CONFIG_DM9000 is not set
417 424
418# 425#
419# Tulip family network device support 426# Tulip family network device support
@@ -453,6 +460,7 @@ CONFIG_PCNET32=y
453# CONFIG_R8169 is not set 460# CONFIG_R8169 is not set
454# CONFIG_SIS190 is not set 461# CONFIG_SIS190 is not set
455# CONFIG_SKGE is not set 462# CONFIG_SKGE is not set
463# CONFIG_SKY2 is not set
456# CONFIG_SK98LIN is not set 464# CONFIG_SK98LIN is not set
457# CONFIG_VIA_VELOCITY is not set 465# CONFIG_VIA_VELOCITY is not set
458# CONFIG_TIGON3 is not set 466# CONFIG_TIGON3 is not set
@@ -474,8 +482,6 @@ CONFIG_PCNET32=y
474# Wireless LAN (non-hamradio) 482# Wireless LAN (non-hamradio)
475# 483#
476# CONFIG_NET_RADIO is not set 484# CONFIG_NET_RADIO is not set
477# CONFIG_IPW_DEBUG is not set
478CONFIG_IPW2200=y
479 485
480# 486#
481# Wan interfaces 487# Wan interfaces
@@ -551,6 +557,7 @@ CONFIG_HW_CONSOLE=y
551CONFIG_SERIAL_8250=y 557CONFIG_SERIAL_8250=y
552CONFIG_SERIAL_8250_CONSOLE=y 558CONFIG_SERIAL_8250_CONSOLE=y
553CONFIG_SERIAL_8250_NR_UARTS=4 559CONFIG_SERIAL_8250_NR_UARTS=4
560CONFIG_SERIAL_8250_RUNTIME_UARTS=4
554# CONFIG_SERIAL_8250_EXTENDED is not set 561# CONFIG_SERIAL_8250_EXTENDED is not set
555 562
556# 563#
@@ -558,7 +565,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
558# 565#
559CONFIG_SERIAL_CORE=y 566CONFIG_SERIAL_CORE=y
560CONFIG_SERIAL_CORE_CONSOLE=y 567CONFIG_SERIAL_CORE_CONSOLE=y
561# CONFIG_SERIAL_JSM is not set
562CONFIG_UNIX98_PTYS=y 568CONFIG_UNIX98_PTYS=y
563CONFIG_LEGACY_PTYS=y 569CONFIG_LEGACY_PTYS=y
564CONFIG_LEGACY_PTY_COUNT=256 570CONFIG_LEGACY_PTY_COUNT=256
@@ -596,6 +602,12 @@ CONFIG_LEGACY_PTY_COUNT=256
596# CONFIG_I2C is not set 602# CONFIG_I2C is not set
597 603
598# 604#
605# SPI support
606#
607# CONFIG_SPI is not set
608# CONFIG_SPI_MASTER is not set
609
610#
599# Dallas's 1-wire bus 611# Dallas's 1-wire bus
600# 612#
601# CONFIG_W1 is not set 613# CONFIG_W1 is not set
@@ -677,11 +689,11 @@ CONFIG_EXT2_FS=y
677# CONFIG_EXT2_FS_XATTR is not set 689# CONFIG_EXT2_FS_XATTR is not set
678# CONFIG_EXT2_FS_XIP is not set 690# CONFIG_EXT2_FS_XIP is not set
679# CONFIG_EXT3_FS is not set 691# CONFIG_EXT3_FS is not set
680# CONFIG_JBD is not set
681# CONFIG_REISERFS_FS is not set 692# CONFIG_REISERFS_FS is not set
682# CONFIG_JFS_FS is not set 693# CONFIG_JFS_FS is not set
683# CONFIG_FS_POSIX_ACL is not set 694# CONFIG_FS_POSIX_ACL is not set
684# CONFIG_XFS_FS is not set 695# CONFIG_XFS_FS is not set
696# CONFIG_OCFS2_FS is not set
685# CONFIG_MINIX_FS is not set 697# CONFIG_MINIX_FS is not set
686# CONFIG_ROMFS_FS is not set 698# CONFIG_ROMFS_FS is not set
687CONFIG_INOTIFY=y 699CONFIG_INOTIFY=y
@@ -714,6 +726,7 @@ CONFIG_SYSFS=y
714# CONFIG_HUGETLB_PAGE is not set 726# CONFIG_HUGETLB_PAGE is not set
715CONFIG_RAMFS=y 727CONFIG_RAMFS=y
716CONFIG_RELAYFS_FS=y 728CONFIG_RELAYFS_FS=y
729# CONFIG_CONFIGFS_FS is not set
717 730
718# 731#
719# Miscellaneous filesystems 732# Miscellaneous filesystems
@@ -776,6 +789,7 @@ CONFIG_MSDOS_PARTITION=y
776# Kernel hacking 789# Kernel hacking
777# 790#
778# CONFIG_PRINTK_TIME is not set 791# CONFIG_PRINTK_TIME is not set
792# CONFIG_MAGIC_SYSRQ is not set
779# CONFIG_DEBUG_KERNEL is not set 793# CONFIG_DEBUG_KERNEL is not set
780CONFIG_LOG_BUF_SHIFT=14 794CONFIG_LOG_BUF_SHIFT=14
781CONFIG_CROSSCOMPILE=y 795CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/decstation_defconfig b/arch/mips/configs/decstation_defconfig
index 08a4de6ec4a6..5a181eadd437 100644
--- a/arch/mips/configs/decstation_defconfig
+++ b/arch/mips/configs/decstation_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:13 2005 4# Fri Jan 27 15:40:03 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -150,27 +150,29 @@ CONFIG_SYSVIPC=y
150# CONFIG_BSD_PROCESS_ACCT is not set 150# CONFIG_BSD_PROCESS_ACCT is not set
151CONFIG_SYSCTL=y 151CONFIG_SYSCTL=y
152# CONFIG_AUDIT is not set 152# CONFIG_AUDIT is not set
153# CONFIG_HOTPLUG is not set
154CONFIG_KOBJECT_UEVENT=y
155# CONFIG_IKCONFIG is not set 153# CONFIG_IKCONFIG is not set
156CONFIG_INITRAMFS_SOURCE="" 154CONFIG_INITRAMFS_SOURCE=""
155# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
157CONFIG_EMBEDDED=y 156CONFIG_EMBEDDED=y
158CONFIG_KALLSYMS=y 157CONFIG_KALLSYMS=y
159# CONFIG_KALLSYMS_ALL is not set 158# CONFIG_KALLSYMS_ALL is not set
160# CONFIG_KALLSYMS_EXTRA_PASS is not set 159# CONFIG_KALLSYMS_EXTRA_PASS is not set
160# CONFIG_HOTPLUG is not set
161CONFIG_PRINTK=y 161CONFIG_PRINTK=y
162CONFIG_BUG=y 162CONFIG_BUG=y
163CONFIG_ELF_CORE=y
163CONFIG_BASE_FULL=y 164CONFIG_BASE_FULL=y
164CONFIG_FUTEX=y 165CONFIG_FUTEX=y
165CONFIG_EPOLL=y 166CONFIG_EPOLL=y
166# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
167CONFIG_SHMEM=y 167CONFIG_SHMEM=y
168CONFIG_CC_ALIGN_FUNCTIONS=0 168CONFIG_CC_ALIGN_FUNCTIONS=0
169CONFIG_CC_ALIGN_LABELS=0 169CONFIG_CC_ALIGN_LABELS=0
170CONFIG_CC_ALIGN_LOOPS=0 170CONFIG_CC_ALIGN_LOOPS=0
171CONFIG_CC_ALIGN_JUMPS=0 171CONFIG_CC_ALIGN_JUMPS=0
172CONFIG_SLAB=y
172# CONFIG_TINY_SHMEM is not set 173# CONFIG_TINY_SHMEM is not set
173CONFIG_BASE_SMALL=0 174CONFIG_BASE_SMALL=0
175# CONFIG_SLOB is not set
174 176
175# 177#
176# Loadable module support 178# Loadable module support
@@ -278,6 +280,11 @@ CONFIG_TCP_CONG_BIC=y
278# CONFIG_ATALK is not set 280# CONFIG_ATALK is not set
279# CONFIG_X25 is not set 281# CONFIG_X25 is not set
280# CONFIG_LAPB is not set 282# CONFIG_LAPB is not set
283
284#
285# TIPC Configuration (EXPERIMENTAL)
286#
287# CONFIG_TIPC is not set
281# CONFIG_NET_DIVERT is not set 288# CONFIG_NET_DIVERT is not set
282# CONFIG_ECONET is not set 289# CONFIG_ECONET is not set
283# CONFIG_WAN_ROUTER is not set 290# CONFIG_WAN_ROUTER is not set
@@ -298,7 +305,6 @@ CONFIG_IEEE80211=m
298# CONFIG_IEEE80211_DEBUG is not set 305# CONFIG_IEEE80211_DEBUG is not set
299CONFIG_IEEE80211_CRYPT_WEP=m 306CONFIG_IEEE80211_CRYPT_WEP=m
300CONFIG_IEEE80211_CRYPT_CCMP=m 307CONFIG_IEEE80211_CRYPT_CCMP=m
301CONFIG_IEEE80211_CRYPT_TKIP=m
302 308
303# 309#
304# Device Drivers 310# Device Drivers
@@ -436,6 +442,7 @@ CONFIG_CICADA_PHY=m
436# 442#
437CONFIG_NET_ETHERNET=y 443CONFIG_NET_ETHERNET=y
438# CONFIG_MII is not set 444# CONFIG_MII is not set
445# CONFIG_DM9000 is not set
439CONFIG_DECLANCE=y 446CONFIG_DECLANCE=y
440 447
441# 448#
@@ -539,6 +546,12 @@ CONFIG_RTC=y
539# CONFIG_I2C is not set 546# CONFIG_I2C is not set
540 547
541# 548#
549# SPI support
550#
551# CONFIG_SPI is not set
552# CONFIG_SPI_MASTER is not set
553
554#
542# Dallas's 1-wire bus 555# Dallas's 1-wire bus
543# 556#
544# CONFIG_W1 is not set 557# CONFIG_W1 is not set
@@ -636,12 +649,12 @@ CONFIG_EXT2_FS_POSIX_ACL=y
636CONFIG_EXT2_FS_SECURITY=y 649CONFIG_EXT2_FS_SECURITY=y
637# CONFIG_EXT2_FS_XIP is not set 650# CONFIG_EXT2_FS_XIP is not set
638# CONFIG_EXT3_FS is not set 651# CONFIG_EXT3_FS is not set
639# CONFIG_JBD is not set
640CONFIG_FS_MBCACHE=y 652CONFIG_FS_MBCACHE=y
641# CONFIG_REISERFS_FS is not set 653# CONFIG_REISERFS_FS is not set
642# CONFIG_JFS_FS is not set 654# CONFIG_JFS_FS is not set
643CONFIG_FS_POSIX_ACL=y 655CONFIG_FS_POSIX_ACL=y
644# CONFIG_XFS_FS is not set 656# CONFIG_XFS_FS is not set
657# CONFIG_OCFS2_FS is not set
645# CONFIG_MINIX_FS is not set 658# CONFIG_MINIX_FS is not set
646# CONFIG_ROMFS_FS is not set 659# CONFIG_ROMFS_FS is not set
647CONFIG_INOTIFY=y 660CONFIG_INOTIFY=y
@@ -674,6 +687,7 @@ CONFIG_TMPFS=y
674# CONFIG_HUGETLB_PAGE is not set 687# CONFIG_HUGETLB_PAGE is not set
675CONFIG_RAMFS=y 688CONFIG_RAMFS=y
676CONFIG_RELAYFS_FS=m 689CONFIG_RELAYFS_FS=m
690# CONFIG_CONFIGFS_FS is not set
677 691
678# 692#
679# Miscellaneous filesystems 693# Miscellaneous filesystems
@@ -734,6 +748,7 @@ CONFIG_MSDOS_PARTITION=y
734# CONFIG_SGI_PARTITION is not set 748# CONFIG_SGI_PARTITION is not set
735CONFIG_ULTRIX_PARTITION=y 749CONFIG_ULTRIX_PARTITION=y
736# CONFIG_SUN_PARTITION is not set 750# CONFIG_SUN_PARTITION is not set
751# CONFIG_KARMA_PARTITION is not set
737# CONFIG_EFI_PARTITION is not set 752# CONFIG_EFI_PARTITION is not set
738 753
739# 754#
@@ -750,18 +765,20 @@ CONFIG_ULTRIX_PARTITION=y
750# Kernel hacking 765# Kernel hacking
751# 766#
752# CONFIG_PRINTK_TIME is not set 767# CONFIG_PRINTK_TIME is not set
753CONFIG_DEBUG_KERNEL=y
754CONFIG_MAGIC_SYSRQ=y 768CONFIG_MAGIC_SYSRQ=y
769CONFIG_DEBUG_KERNEL=y
755CONFIG_LOG_BUF_SHIFT=14 770CONFIG_LOG_BUF_SHIFT=14
756CONFIG_DETECT_SOFTLOCKUP=y 771CONFIG_DETECT_SOFTLOCKUP=y
757# CONFIG_SCHEDSTATS is not set 772# CONFIG_SCHEDSTATS is not set
758# CONFIG_DEBUG_SLAB is not set 773# CONFIG_DEBUG_SLAB is not set
774CONFIG_DEBUG_MUTEXES=y
759# CONFIG_DEBUG_SPINLOCK is not set 775# CONFIG_DEBUG_SPINLOCK is not set
760# CONFIG_DEBUG_SPINLOCK_SLEEP is not set 776# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
761# CONFIG_DEBUG_KOBJECT is not set 777# CONFIG_DEBUG_KOBJECT is not set
762# CONFIG_DEBUG_INFO is not set 778# CONFIG_DEBUG_INFO is not set
763# CONFIG_DEBUG_FS is not set 779# CONFIG_DEBUG_FS is not set
764# CONFIG_DEBUG_VM is not set 780# CONFIG_DEBUG_VM is not set
781CONFIG_FORCED_INLINING=y
765# CONFIG_RCU_TORTURE_TEST is not set 782# CONFIG_RCU_TORTURE_TEST is not set
766CONFIG_CROSSCOMPILE=y 783CONFIG_CROSSCOMPILE=y
767CONFIG_CMDLINE="" 784CONFIG_CMDLINE=""
diff --git a/arch/mips/configs/e55_defconfig b/arch/mips/configs/e55_defconfig
index c9070cef08b1..8fbfc06a6a2a 100644
--- a/arch/mips/configs/e55_defconfig
+++ b/arch/mips/configs/e55_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:14 2005 4# Fri Jan 27 15:40:04 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -63,9 +63,9 @@ CONFIG_MACH_VR41XX=y
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
66# CONFIG_NEC_CMBVR4133 is not set
67CONFIG_CASIO_E55=y 66CONFIG_CASIO_E55=y
68# CONFIG_IBM_WORKPAD is not set 67# CONFIG_IBM_WORKPAD is not set
68# CONFIG_NEC_CMBVR4133 is not set
69# CONFIG_TANBAC_TB022X is not set 69# CONFIG_TANBAC_TB022X is not set
70# CONFIG_VICTOR_MPC30X is not set 70# CONFIG_VICTOR_MPC30X is not set
71# CONFIG_ZAO_CAPCELLA is not set 71# CONFIG_ZAO_CAPCELLA is not set
@@ -88,7 +88,7 @@ CONFIG_MIPS_L1_CACHE_SHIFT=5
88# CONFIG_CPU_MIPS64_R2 is not set 88# CONFIG_CPU_MIPS64_R2 is not set
89# CONFIG_CPU_R3000 is not set 89# CONFIG_CPU_R3000 is not set
90# CONFIG_CPU_TX39XX is not set 90# CONFIG_CPU_TX39XX is not set
91CONFIG_CPU_VR41XX=y 91# CONFIG_CPU_VR41XX is not set
92# CONFIG_CPU_R4300 is not set 92# CONFIG_CPU_R4300 is not set
93# CONFIG_CPU_R4X00 is not set 93# CONFIG_CPU_R4X00 is not set
94# CONFIG_CPU_TX49XX is not set 94# CONFIG_CPU_TX49XX is not set
@@ -101,23 +101,18 @@ CONFIG_CPU_VR41XX=y
101# CONFIG_CPU_RM7000 is not set 101# CONFIG_CPU_RM7000 is not set
102# CONFIG_CPU_RM9000 is not set 102# CONFIG_CPU_RM9000 is not set
103# CONFIG_CPU_SB1 is not set 103# CONFIG_CPU_SB1 is not set
104CONFIG_SYS_HAS_CPU_VR41XX=y
105CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
106CONFIG_SYS_SUPPORTS_64BIT_KERNEL=y
107CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
108CONFIG_CPU_SUPPORTS_64BIT_KERNEL=y
109 104
110# 105#
111# Kernel type 106# Kernel type
112# 107#
113CONFIG_32BIT=y 108# CONFIG_32BIT is not set
114# CONFIG_64BIT is not set 109# CONFIG_64BIT is not set
115CONFIG_PAGE_SIZE_4KB=y 110CONFIG_PAGE_SIZE_4KB=y
116# CONFIG_PAGE_SIZE_8KB is not set 111# CONFIG_PAGE_SIZE_8KB is not set
117# CONFIG_PAGE_SIZE_16KB is not set 112# CONFIG_PAGE_SIZE_16KB is not set
118# CONFIG_PAGE_SIZE_64KB is not set 113# CONFIG_PAGE_SIZE_64KB is not set
119# CONFIG_MIPS_MT is not set 114# CONFIG_MIPS_MT is not set
120# CONFIG_CPU_ADVANCED is not set 115CONFIG_CPU_HAS_LLSC=y
121CONFIG_CPU_HAS_SYNC=y 116CONFIG_CPU_HAS_SYNC=y
122CONFIG_GENERIC_HARDIRQS=y 117CONFIG_GENERIC_HARDIRQS=y
123CONFIG_GENERIC_IRQ_PROBE=y 118CONFIG_GENERIC_IRQ_PROBE=y
@@ -153,26 +148,28 @@ CONFIG_SYSVIPC=y
153# CONFIG_BSD_PROCESS_ACCT is not set 148# CONFIG_BSD_PROCESS_ACCT is not set
154CONFIG_SYSCTL=y 149CONFIG_SYSCTL=y
155# CONFIG_AUDIT is not set 150# CONFIG_AUDIT is not set
156# CONFIG_HOTPLUG is not set
157CONFIG_KOBJECT_UEVENT=y
158# CONFIG_IKCONFIG is not set 151# CONFIG_IKCONFIG is not set
159CONFIG_INITRAMFS_SOURCE="" 152CONFIG_INITRAMFS_SOURCE=""
153# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
160CONFIG_EMBEDDED=y 154CONFIG_EMBEDDED=y
161CONFIG_KALLSYMS=y 155CONFIG_KALLSYMS=y
162# CONFIG_KALLSYMS_EXTRA_PASS is not set 156# CONFIG_KALLSYMS_EXTRA_PASS is not set
157# CONFIG_HOTPLUG is not set
163CONFIG_PRINTK=y 158CONFIG_PRINTK=y
164CONFIG_BUG=y 159CONFIG_BUG=y
160CONFIG_ELF_CORE=y
165CONFIG_BASE_FULL=y 161CONFIG_BASE_FULL=y
166CONFIG_FUTEX=y 162CONFIG_FUTEX=y
167CONFIG_EPOLL=y 163CONFIG_EPOLL=y
168# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
169CONFIG_SHMEM=y 164CONFIG_SHMEM=y
170CONFIG_CC_ALIGN_FUNCTIONS=0 165CONFIG_CC_ALIGN_FUNCTIONS=0
171CONFIG_CC_ALIGN_LABELS=0 166CONFIG_CC_ALIGN_LABELS=0
172CONFIG_CC_ALIGN_LOOPS=0 167CONFIG_CC_ALIGN_LOOPS=0
173CONFIG_CC_ALIGN_JUMPS=0 168CONFIG_CC_ALIGN_JUMPS=0
169CONFIG_SLAB=y
174# CONFIG_TINY_SHMEM is not set 170# CONFIG_TINY_SHMEM is not set
175CONFIG_BASE_SMALL=0 171CONFIG_BASE_SMALL=0
172# CONFIG_SLOB is not set
176 173
177# 174#
178# Loadable module support 175# Loadable module support
@@ -188,7 +185,6 @@ CONFIG_KMOD=y
188# 185#
189# Block layer 186# Block layer
190# 187#
191# CONFIG_LBD is not set
192 188
193# 189#
194# IO Schedulers 190# IO Schedulers
@@ -223,7 +219,6 @@ CONFIG_MMU=y
223# 219#
224CONFIG_BINFMT_ELF=y 220CONFIG_BINFMT_ELF=y
225# CONFIG_BINFMT_MISC is not set 221# CONFIG_BINFMT_MISC is not set
226CONFIG_TRAD_SIGNALS=y
227 222
228# 223#
229# Networking 224# Networking
@@ -278,6 +273,11 @@ CONFIG_TCP_CONG_BIC=y
278# CONFIG_ATALK is not set 273# CONFIG_ATALK is not set
279# CONFIG_X25 is not set 274# CONFIG_X25 is not set
280# CONFIG_LAPB is not set 275# CONFIG_LAPB is not set
276
277#
278# TIPC Configuration (EXPERIMENTAL)
279#
280# CONFIG_TIPC is not set
281# CONFIG_NET_DIVERT is not set 281# CONFIG_NET_DIVERT is not set
282# CONFIG_ECONET is not set 282# CONFIG_ECONET is not set
283# CONFIG_WAN_ROUTER is not set 283# CONFIG_WAN_ROUTER is not set
@@ -298,7 +298,6 @@ CONFIG_IEEE80211=m
298# CONFIG_IEEE80211_DEBUG is not set 298# CONFIG_IEEE80211_DEBUG is not set
299CONFIG_IEEE80211_CRYPT_WEP=m 299CONFIG_IEEE80211_CRYPT_WEP=m
300CONFIG_IEEE80211_CRYPT_CCMP=m 300CONFIG_IEEE80211_CRYPT_CCMP=m
301CONFIG_IEEE80211_CRYPT_TKIP=m
302 301
303# 302#
304# Device Drivers 303# Device Drivers
@@ -433,6 +432,7 @@ CONFIG_NET_ETHERNET=y
433# CONFIG_MII is not set 432# CONFIG_MII is not set
434# CONFIG_NET_VENDOR_3COM is not set 433# CONFIG_NET_VENDOR_3COM is not set
435# CONFIG_NET_VENDOR_SMC is not set 434# CONFIG_NET_VENDOR_SMC is not set
435# CONFIG_DM9000 is not set
436# CONFIG_NET_VENDOR_RACAL is not set 436# CONFIG_NET_VENDOR_RACAL is not set
437# CONFIG_AT1700 is not set 437# CONFIG_AT1700 is not set
438# CONFIG_DEPCA is not set 438# CONFIG_DEPCA is not set
@@ -531,10 +531,6 @@ CONFIG_HW_CONSOLE=y
531# 531#
532# Non-8250 serial port support 532# Non-8250 serial port support
533# 533#
534CONFIG_SERIAL_CORE=y
535CONFIG_SERIAL_CORE_CONSOLE=y
536CONFIG_SERIAL_VR41XX=y
537CONFIG_SERIAL_VR41XX_CONSOLE=y
538CONFIG_UNIX98_PTYS=y 534CONFIG_UNIX98_PTYS=y
539CONFIG_LEGACY_PTYS=y 535CONFIG_LEGACY_PTYS=y
540CONFIG_LEGACY_PTY_COUNT=256 536CONFIG_LEGACY_PTY_COUNT=256
@@ -563,14 +559,12 @@ CONFIG_WATCHDOG=y
563# CONFIG_WDT is not set 559# CONFIG_WDT is not set
564# CONFIG_RTC is not set 560# CONFIG_RTC is not set
565# CONFIG_GEN_RTC is not set 561# CONFIG_GEN_RTC is not set
566# CONFIG_RTC_VR41XX is not set
567# CONFIG_DTLK is not set 562# CONFIG_DTLK is not set
568# CONFIG_R3964 is not set 563# CONFIG_R3964 is not set
569 564
570# 565#
571# Ftape, the floppy tape device driver 566# Ftape, the floppy tape device driver
572# 567#
573CONFIG_GPIO_VR41XX=y
574# CONFIG_RAW_DRIVER is not set 568# CONFIG_RAW_DRIVER is not set
575 569
576# 570#
@@ -585,6 +579,12 @@ CONFIG_GPIO_VR41XX=y
585# CONFIG_I2C is not set 579# CONFIG_I2C is not set
586 580
587# 581#
582# SPI support
583#
584# CONFIG_SPI is not set
585# CONFIG_SPI_MASTER is not set
586
587#
588# Dallas's 1-wire bus 588# Dallas's 1-wire bus
589# 589#
590# CONFIG_W1 is not set 590# CONFIG_W1 is not set
@@ -665,11 +665,11 @@ CONFIG_EXT2_FS=y
665# CONFIG_EXT2_FS_XATTR is not set 665# CONFIG_EXT2_FS_XATTR is not set
666# CONFIG_EXT2_FS_XIP is not set 666# CONFIG_EXT2_FS_XIP is not set
667# CONFIG_EXT3_FS is not set 667# CONFIG_EXT3_FS is not set
668# CONFIG_JBD is not set
669# CONFIG_REISERFS_FS is not set 668# CONFIG_REISERFS_FS is not set
670# CONFIG_JFS_FS is not set 669# CONFIG_JFS_FS is not set
671# CONFIG_FS_POSIX_ACL is not set 670# CONFIG_FS_POSIX_ACL is not set
672# CONFIG_XFS_FS is not set 671# CONFIG_XFS_FS is not set
672# CONFIG_OCFS2_FS is not set
673# CONFIG_MINIX_FS is not set 673# CONFIG_MINIX_FS is not set
674# CONFIG_ROMFS_FS is not set 674# CONFIG_ROMFS_FS is not set
675CONFIG_INOTIFY=y 675CONFIG_INOTIFY=y
@@ -702,6 +702,7 @@ CONFIG_SYSFS=y
702# CONFIG_HUGETLB_PAGE is not set 702# CONFIG_HUGETLB_PAGE is not set
703CONFIG_RAMFS=y 703CONFIG_RAMFS=y
704CONFIG_RELAYFS_FS=m 704CONFIG_RELAYFS_FS=m
705# CONFIG_CONFIGFS_FS is not set
705 706
706# 707#
707# Miscellaneous filesystems 708# Miscellaneous filesystems
@@ -763,6 +764,7 @@ CONFIG_MSDOS_PARTITION=y
763# Kernel hacking 764# Kernel hacking
764# 765#
765# CONFIG_PRINTK_TIME is not set 766# CONFIG_PRINTK_TIME is not set
767# CONFIG_MAGIC_SYSRQ is not set
766# CONFIG_DEBUG_KERNEL is not set 768# CONFIG_DEBUG_KERNEL is not set
767CONFIG_LOG_BUF_SHIFT=14 769CONFIG_LOG_BUF_SHIFT=14
768CONFIG_CROSSCOMPILE=y 770CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/ev64120_defconfig b/arch/mips/configs/ev64120_defconfig
index aa24d85ea94d..f2d43be69007 100644
--- a/arch/mips/configs/ev64120_defconfig
+++ b/arch/mips/configs/ev64120_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:16 2005 4# Fri Jan 27 15:40:05 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -153,26 +153,28 @@ CONFIG_SYSVIPC=y
153# CONFIG_BSD_PROCESS_ACCT is not set 153# CONFIG_BSD_PROCESS_ACCT is not set
154CONFIG_SYSCTL=y 154CONFIG_SYSCTL=y
155# CONFIG_AUDIT is not set 155# CONFIG_AUDIT is not set
156CONFIG_HOTPLUG=y
157CONFIG_KOBJECT_UEVENT=y
158# CONFIG_IKCONFIG is not set 156# CONFIG_IKCONFIG is not set
159CONFIG_INITRAMFS_SOURCE="" 157CONFIG_INITRAMFS_SOURCE=""
158# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
160CONFIG_EMBEDDED=y 159CONFIG_EMBEDDED=y
161CONFIG_KALLSYMS=y 160CONFIG_KALLSYMS=y
162# CONFIG_KALLSYMS_EXTRA_PASS is not set 161# CONFIG_KALLSYMS_EXTRA_PASS is not set
162CONFIG_HOTPLUG=y
163CONFIG_PRINTK=y 163CONFIG_PRINTK=y
164CONFIG_BUG=y 164CONFIG_BUG=y
165CONFIG_ELF_CORE=y
165CONFIG_BASE_FULL=y 166CONFIG_BASE_FULL=y
166CONFIG_FUTEX=y 167CONFIG_FUTEX=y
167CONFIG_EPOLL=y 168CONFIG_EPOLL=y
168# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
169CONFIG_SHMEM=y 169CONFIG_SHMEM=y
170CONFIG_CC_ALIGN_FUNCTIONS=0 170CONFIG_CC_ALIGN_FUNCTIONS=0
171CONFIG_CC_ALIGN_LABELS=0 171CONFIG_CC_ALIGN_LABELS=0
172CONFIG_CC_ALIGN_LOOPS=0 172CONFIG_CC_ALIGN_LOOPS=0
173CONFIG_CC_ALIGN_JUMPS=0 173CONFIG_CC_ALIGN_JUMPS=0
174CONFIG_SLAB=y
174# CONFIG_TINY_SHMEM is not set 175# CONFIG_TINY_SHMEM is not set
175CONFIG_BASE_SMALL=0 176CONFIG_BASE_SMALL=0
177# CONFIG_SLOB is not set
176 178
177# 179#
178# Loadable module support 180# Loadable module support
@@ -282,6 +284,11 @@ CONFIG_TCP_CONG_BIC=y
282# CONFIG_ATALK is not set 284# CONFIG_ATALK is not set
283# CONFIG_X25 is not set 285# CONFIG_X25 is not set
284# CONFIG_LAPB is not set 286# CONFIG_LAPB is not set
287
288#
289# TIPC Configuration (EXPERIMENTAL)
290#
291# CONFIG_TIPC is not set
285# CONFIG_NET_DIVERT is not set 292# CONFIG_NET_DIVERT is not set
286# CONFIG_ECONET is not set 293# CONFIG_ECONET is not set
287# CONFIG_WAN_ROUTER is not set 294# CONFIG_WAN_ROUTER is not set
@@ -302,7 +309,6 @@ CONFIG_IEEE80211=m
302# CONFIG_IEEE80211_DEBUG is not set 309# CONFIG_IEEE80211_DEBUG is not set
303CONFIG_IEEE80211_CRYPT_WEP=m 310CONFIG_IEEE80211_CRYPT_WEP=m
304CONFIG_IEEE80211_CRYPT_CCMP=m 311CONFIG_IEEE80211_CRYPT_CCMP=m
305CONFIG_IEEE80211_CRYPT_TKIP=m
306 312
307# 313#
308# Device Drivers 314# Device Drivers
@@ -420,6 +426,7 @@ CONFIG_NET_ETHERNET=y
420# CONFIG_SUNGEM is not set 426# CONFIG_SUNGEM is not set
421# CONFIG_CASSINI is not set 427# CONFIG_CASSINI is not set
422# CONFIG_NET_VENDOR_3COM is not set 428# CONFIG_NET_VENDOR_3COM is not set
429# CONFIG_DM9000 is not set
423 430
424# 431#
425# Tulip family network device support 432# Tulip family network device support
@@ -440,6 +447,7 @@ CONFIG_NET_ETHERNET=y
440# CONFIG_R8169 is not set 447# CONFIG_R8169 is not set
441# CONFIG_SIS190 is not set 448# CONFIG_SIS190 is not set
442# CONFIG_SKGE is not set 449# CONFIG_SKGE is not set
450# CONFIG_SKY2 is not set
443# CONFIG_SK98LIN is not set 451# CONFIG_SK98LIN is not set
444# CONFIG_TIGON3 is not set 452# CONFIG_TIGON3 is not set
445# CONFIG_BNX2 is not set 453# CONFIG_BNX2 is not set
@@ -460,8 +468,6 @@ CONFIG_NET_ETHERNET=y
460# Wireless LAN (non-hamradio) 468# Wireless LAN (non-hamradio)
461# 469#
462# CONFIG_NET_RADIO is not set 470# CONFIG_NET_RADIO is not set
463# CONFIG_IPW_DEBUG is not set
464CONFIG_IPW2200=m
465 471
466# 472#
467# Wan interfaces 473# Wan interfaces
@@ -545,6 +551,7 @@ CONFIG_HW_CONSOLE=y
545CONFIG_SERIAL_8250=y 551CONFIG_SERIAL_8250=y
546CONFIG_SERIAL_8250_CONSOLE=y 552CONFIG_SERIAL_8250_CONSOLE=y
547CONFIG_SERIAL_8250_NR_UARTS=4 553CONFIG_SERIAL_8250_NR_UARTS=4
554CONFIG_SERIAL_8250_RUNTIME_UARTS=4
548# CONFIG_SERIAL_8250_EXTENDED is not set 555# CONFIG_SERIAL_8250_EXTENDED is not set
549 556
550# 557#
@@ -552,7 +559,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
552# 559#
553CONFIG_SERIAL_CORE=y 560CONFIG_SERIAL_CORE=y
554CONFIG_SERIAL_CORE_CONSOLE=y 561CONFIG_SERIAL_CORE_CONSOLE=y
555# CONFIG_SERIAL_JSM is not set
556CONFIG_UNIX98_PTYS=y 562CONFIG_UNIX98_PTYS=y
557CONFIG_LEGACY_PTYS=y 563CONFIG_LEGACY_PTYS=y
558CONFIG_LEGACY_PTY_COUNT=256 564CONFIG_LEGACY_PTY_COUNT=256
@@ -590,6 +596,12 @@ CONFIG_LEGACY_PTY_COUNT=256
590# CONFIG_I2C is not set 596# CONFIG_I2C is not set
591 597
592# 598#
599# SPI support
600#
601# CONFIG_SPI is not set
602# CONFIG_SPI_MASTER is not set
603
604#
593# Dallas's 1-wire bus 605# Dallas's 1-wire bus
594# 606#
595# CONFIG_W1 is not set 607# CONFIG_W1 is not set
@@ -671,11 +683,11 @@ CONFIG_EXT2_FS=y
671# CONFIG_EXT2_FS_XATTR is not set 683# CONFIG_EXT2_FS_XATTR is not set
672# CONFIG_EXT2_FS_XIP is not set 684# CONFIG_EXT2_FS_XIP is not set
673# CONFIG_EXT3_FS is not set 685# CONFIG_EXT3_FS is not set
674# CONFIG_JBD is not set
675# CONFIG_REISERFS_FS is not set 686# CONFIG_REISERFS_FS is not set
676# CONFIG_JFS_FS is not set 687# CONFIG_JFS_FS is not set
677# CONFIG_FS_POSIX_ACL is not set 688# CONFIG_FS_POSIX_ACL is not set
678# CONFIG_XFS_FS is not set 689# CONFIG_XFS_FS is not set
690# CONFIG_OCFS2_FS is not set
679# CONFIG_MINIX_FS is not set 691# CONFIG_MINIX_FS is not set
680# CONFIG_ROMFS_FS is not set 692# CONFIG_ROMFS_FS is not set
681CONFIG_INOTIFY=y 693CONFIG_INOTIFY=y
@@ -708,6 +720,7 @@ CONFIG_SYSFS=y
708# CONFIG_HUGETLB_PAGE is not set 720# CONFIG_HUGETLB_PAGE is not set
709CONFIG_RAMFS=y 721CONFIG_RAMFS=y
710CONFIG_RELAYFS_FS=m 722CONFIG_RELAYFS_FS=m
723# CONFIG_CONFIGFS_FS is not set
711 724
712# 725#
713# Miscellaneous filesystems 726# Miscellaneous filesystems
@@ -767,6 +780,7 @@ CONFIG_MSDOS_PARTITION=y
767# Kernel hacking 780# Kernel hacking
768# 781#
769# CONFIG_PRINTK_TIME is not set 782# CONFIG_PRINTK_TIME is not set
783# CONFIG_MAGIC_SYSRQ is not set
770# CONFIG_DEBUG_KERNEL is not set 784# CONFIG_DEBUG_KERNEL is not set
771CONFIG_LOG_BUF_SHIFT=14 785CONFIG_LOG_BUF_SHIFT=14
772CONFIG_CROSSCOMPILE=y 786CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/ev96100_defconfig b/arch/mips/configs/ev96100_defconfig
index eeed0e5ad260..ac5841c4b698 100644
--- a/arch/mips/configs/ev96100_defconfig
+++ b/arch/mips/configs/ev96100_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:18 2005 4# Fri Jan 27 15:40:06 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -157,26 +157,28 @@ CONFIG_SYSVIPC=y
157# CONFIG_BSD_PROCESS_ACCT is not set 157# CONFIG_BSD_PROCESS_ACCT is not set
158CONFIG_SYSCTL=y 158CONFIG_SYSCTL=y
159# CONFIG_AUDIT is not set 159# CONFIG_AUDIT is not set
160# CONFIG_HOTPLUG is not set
161CONFIG_KOBJECT_UEVENT=y
162# CONFIG_IKCONFIG is not set 160# CONFIG_IKCONFIG is not set
163CONFIG_INITRAMFS_SOURCE="" 161CONFIG_INITRAMFS_SOURCE=""
162# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
164CONFIG_EMBEDDED=y 163CONFIG_EMBEDDED=y
165CONFIG_KALLSYMS=y 164CONFIG_KALLSYMS=y
166# CONFIG_KALLSYMS_EXTRA_PASS is not set 165# CONFIG_KALLSYMS_EXTRA_PASS is not set
166# CONFIG_HOTPLUG is not set
167CONFIG_PRINTK=y 167CONFIG_PRINTK=y
168CONFIG_BUG=y 168CONFIG_BUG=y
169CONFIG_ELF_CORE=y
169CONFIG_BASE_FULL=y 170CONFIG_BASE_FULL=y
170CONFIG_FUTEX=y 171CONFIG_FUTEX=y
171CONFIG_EPOLL=y 172CONFIG_EPOLL=y
172# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
173CONFIG_SHMEM=y 173CONFIG_SHMEM=y
174CONFIG_CC_ALIGN_FUNCTIONS=0 174CONFIG_CC_ALIGN_FUNCTIONS=0
175CONFIG_CC_ALIGN_LABELS=0 175CONFIG_CC_ALIGN_LABELS=0
176CONFIG_CC_ALIGN_LOOPS=0 176CONFIG_CC_ALIGN_LOOPS=0
177CONFIG_CC_ALIGN_JUMPS=0 177CONFIG_CC_ALIGN_JUMPS=0
178CONFIG_SLAB=y
178# CONFIG_TINY_SHMEM is not set 179# CONFIG_TINY_SHMEM is not set
179CONFIG_BASE_SMALL=0 180CONFIG_BASE_SMALL=0
181# CONFIG_SLOB is not set
180 182
181# 183#
182# Loadable module support 184# Loadable module support
@@ -284,6 +286,11 @@ CONFIG_TCP_CONG_BIC=y
284# CONFIG_ATALK is not set 286# CONFIG_ATALK is not set
285# CONFIG_X25 is not set 287# CONFIG_X25 is not set
286# CONFIG_LAPB is not set 288# CONFIG_LAPB is not set
289
290#
291# TIPC Configuration (EXPERIMENTAL)
292#
293# CONFIG_TIPC is not set
287# CONFIG_NET_DIVERT is not set 294# CONFIG_NET_DIVERT is not set
288# CONFIG_ECONET is not set 295# CONFIG_ECONET is not set
289# CONFIG_WAN_ROUTER is not set 296# CONFIG_WAN_ROUTER is not set
@@ -304,7 +311,6 @@ CONFIG_IEEE80211=m
304# CONFIG_IEEE80211_DEBUG is not set 311# CONFIG_IEEE80211_DEBUG is not set
305CONFIG_IEEE80211_CRYPT_WEP=m 312CONFIG_IEEE80211_CRYPT_WEP=m
306CONFIG_IEEE80211_CRYPT_CCMP=m 313CONFIG_IEEE80211_CRYPT_CCMP=m
307CONFIG_IEEE80211_CRYPT_TKIP=m
308 314
309# 315#
310# Device Drivers 316# Device Drivers
@@ -407,6 +413,7 @@ CONFIG_CICADA_PHY=m
407CONFIG_NET_ETHERNET=y 413CONFIG_NET_ETHERNET=y
408# CONFIG_MII is not set 414# CONFIG_MII is not set
409CONFIG_MIPS_GT96100ETH=y 415CONFIG_MIPS_GT96100ETH=y
416# CONFIG_DM9000 is not set
410 417
411# 418#
412# Ethernet (1000 Mbit) 419# Ethernet (1000 Mbit)
@@ -496,6 +503,7 @@ CONFIG_HW_CONSOLE=y
496CONFIG_SERIAL_8250=y 503CONFIG_SERIAL_8250=y
497CONFIG_SERIAL_8250_CONSOLE=y 504CONFIG_SERIAL_8250_CONSOLE=y
498CONFIG_SERIAL_8250_NR_UARTS=4 505CONFIG_SERIAL_8250_NR_UARTS=4
506CONFIG_SERIAL_8250_RUNTIME_UARTS=4
499# CONFIG_SERIAL_8250_EXTENDED is not set 507# CONFIG_SERIAL_8250_EXTENDED is not set
500 508
501# 509#
@@ -538,6 +546,12 @@ CONFIG_LEGACY_PTY_COUNT=256
538# CONFIG_I2C is not set 546# CONFIG_I2C is not set
539 547
540# 548#
549# SPI support
550#
551# CONFIG_SPI is not set
552# CONFIG_SPI_MASTER is not set
553
554#
541# Dallas's 1-wire bus 555# Dallas's 1-wire bus
542# 556#
543# CONFIG_W1 is not set 557# CONFIG_W1 is not set
@@ -617,11 +631,11 @@ CONFIG_EXT2_FS=y
617# CONFIG_EXT2_FS_XATTR is not set 631# CONFIG_EXT2_FS_XATTR is not set
618# CONFIG_EXT2_FS_XIP is not set 632# CONFIG_EXT2_FS_XIP is not set
619# CONFIG_EXT3_FS is not set 633# CONFIG_EXT3_FS is not set
620# CONFIG_JBD is not set
621# CONFIG_REISERFS_FS is not set 634# CONFIG_REISERFS_FS is not set
622# CONFIG_JFS_FS is not set 635# CONFIG_JFS_FS is not set
623# CONFIG_FS_POSIX_ACL is not set 636# CONFIG_FS_POSIX_ACL is not set
624# CONFIG_XFS_FS is not set 637# CONFIG_XFS_FS is not set
638# CONFIG_OCFS2_FS is not set
625# CONFIG_MINIX_FS is not set 639# CONFIG_MINIX_FS is not set
626# CONFIG_ROMFS_FS is not set 640# CONFIG_ROMFS_FS is not set
627CONFIG_INOTIFY=y 641CONFIG_INOTIFY=y
@@ -654,6 +668,7 @@ CONFIG_SYSFS=y
654# CONFIG_HUGETLB_PAGE is not set 668# CONFIG_HUGETLB_PAGE is not set
655CONFIG_RAMFS=y 669CONFIG_RAMFS=y
656CONFIG_RELAYFS_FS=m 670CONFIG_RELAYFS_FS=m
671# CONFIG_CONFIGFS_FS is not set
657 672
658# 673#
659# Miscellaneous filesystems 674# Miscellaneous filesystems
@@ -713,6 +728,7 @@ CONFIG_MSDOS_PARTITION=y
713# Kernel hacking 728# Kernel hacking
714# 729#
715# CONFIG_PRINTK_TIME is not set 730# CONFIG_PRINTK_TIME is not set
731# CONFIG_MAGIC_SYSRQ is not set
716# CONFIG_DEBUG_KERNEL is not set 732# CONFIG_DEBUG_KERNEL is not set
717CONFIG_LOG_BUF_SHIFT=14 733CONFIG_LOG_BUF_SHIFT=14
718CONFIG_CROSSCOMPILE=y 734CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/ip22_defconfig b/arch/mips/configs/ip22_defconfig
index e56351abf87a..42d5cd7927cb 100644
--- a/arch/mips/configs/ip22_defconfig
+++ b/arch/mips/configs/ip22_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:20 2005 4# Fri Jan 27 15:39:51 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -158,27 +158,29 @@ CONFIG_SYSVIPC=y
158# CONFIG_BSD_PROCESS_ACCT is not set 158# CONFIG_BSD_PROCESS_ACCT is not set
159CONFIG_SYSCTL=y 159CONFIG_SYSCTL=y
160# CONFIG_AUDIT is not set 160# CONFIG_AUDIT is not set
161# CONFIG_HOTPLUG is not set
162CONFIG_KOBJECT_UEVENT=y
163CONFIG_IKCONFIG=y 161CONFIG_IKCONFIG=y
164CONFIG_IKCONFIG_PROC=y 162CONFIG_IKCONFIG_PROC=y
165CONFIG_INITRAMFS_SOURCE="" 163CONFIG_INITRAMFS_SOURCE=""
164# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
166CONFIG_EMBEDDED=y 165CONFIG_EMBEDDED=y
167CONFIG_KALLSYMS=y 166CONFIG_KALLSYMS=y
168# CONFIG_KALLSYMS_EXTRA_PASS is not set 167# CONFIG_KALLSYMS_EXTRA_PASS is not set
168# CONFIG_HOTPLUG is not set
169CONFIG_PRINTK=y 169CONFIG_PRINTK=y
170CONFIG_BUG=y 170CONFIG_BUG=y
171CONFIG_ELF_CORE=y
171CONFIG_BASE_FULL=y 172CONFIG_BASE_FULL=y
172CONFIG_FUTEX=y 173CONFIG_FUTEX=y
173CONFIG_EPOLL=y 174CONFIG_EPOLL=y
174# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
175CONFIG_SHMEM=y 175CONFIG_SHMEM=y
176CONFIG_CC_ALIGN_FUNCTIONS=0 176CONFIG_CC_ALIGN_FUNCTIONS=0
177CONFIG_CC_ALIGN_LABELS=0 177CONFIG_CC_ALIGN_LABELS=0
178CONFIG_CC_ALIGN_LOOPS=0 178CONFIG_CC_ALIGN_LOOPS=0
179CONFIG_CC_ALIGN_JUMPS=0 179CONFIG_CC_ALIGN_JUMPS=0
180CONFIG_SLAB=y
180# CONFIG_TINY_SHMEM is not set 181# CONFIG_TINY_SHMEM is not set
181CONFIG_BASE_SMALL=0 182CONFIG_BASE_SMALL=0
183# CONFIG_SLOB is not set
182 184
183# 185#
184# Loadable module support 186# Loadable module support
@@ -317,6 +319,28 @@ CONFIG_NETFILTER=y
317CONFIG_NETFILTER_NETLINK=m 319CONFIG_NETFILTER_NETLINK=m
318CONFIG_NETFILTER_NETLINK_QUEUE=m 320CONFIG_NETFILTER_NETLINK_QUEUE=m
319CONFIG_NETFILTER_NETLINK_LOG=m 321CONFIG_NETFILTER_NETLINK_LOG=m
322CONFIG_NETFILTER_XTABLES=m
323CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
324CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
325CONFIG_NETFILTER_XT_TARGET_MARK=m
326CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
327CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
328CONFIG_NETFILTER_XT_MATCH_COMMENT=m
329CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
330CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
331CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
332CONFIG_NETFILTER_XT_MATCH_DCCP=m
333CONFIG_NETFILTER_XT_MATCH_HELPER=m
334CONFIG_NETFILTER_XT_MATCH_LENGTH=m
335CONFIG_NETFILTER_XT_MATCH_LIMIT=m
336CONFIG_NETFILTER_XT_MATCH_MAC=m
337CONFIG_NETFILTER_XT_MATCH_MARK=m
338CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
339CONFIG_NETFILTER_XT_MATCH_REALM=m
340CONFIG_NETFILTER_XT_MATCH_SCTP=m
341CONFIG_NETFILTER_XT_MATCH_STATE=m
342CONFIG_NETFILTER_XT_MATCH_STRING=m
343CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
320 344
321# 345#
322# IP: Netfilter Configuration 346# IP: Netfilter Configuration
@@ -335,39 +359,23 @@ CONFIG_IP_NF_AMANDA=m
335CONFIG_IP_NF_PPTP=m 359CONFIG_IP_NF_PPTP=m
336CONFIG_IP_NF_QUEUE=m 360CONFIG_IP_NF_QUEUE=m
337CONFIG_IP_NF_IPTABLES=m 361CONFIG_IP_NF_IPTABLES=m
338CONFIG_IP_NF_MATCH_LIMIT=m
339CONFIG_IP_NF_MATCH_IPRANGE=m 362CONFIG_IP_NF_MATCH_IPRANGE=m
340CONFIG_IP_NF_MATCH_MAC=m
341CONFIG_IP_NF_MATCH_PKTTYPE=m
342CONFIG_IP_NF_MATCH_MARK=m
343CONFIG_IP_NF_MATCH_MULTIPORT=m 363CONFIG_IP_NF_MATCH_MULTIPORT=m
344CONFIG_IP_NF_MATCH_TOS=m 364CONFIG_IP_NF_MATCH_TOS=m
345CONFIG_IP_NF_MATCH_RECENT=m 365CONFIG_IP_NF_MATCH_RECENT=m
346CONFIG_IP_NF_MATCH_ECN=m 366CONFIG_IP_NF_MATCH_ECN=m
347CONFIG_IP_NF_MATCH_DSCP=m 367CONFIG_IP_NF_MATCH_DSCP=m
348CONFIG_IP_NF_MATCH_AH_ESP=m 368CONFIG_IP_NF_MATCH_AH_ESP=m
349CONFIG_IP_NF_MATCH_LENGTH=m
350CONFIG_IP_NF_MATCH_TTL=m 369CONFIG_IP_NF_MATCH_TTL=m
351CONFIG_IP_NF_MATCH_TCPMSS=m
352CONFIG_IP_NF_MATCH_HELPER=m
353CONFIG_IP_NF_MATCH_STATE=m
354CONFIG_IP_NF_MATCH_CONNTRACK=m
355CONFIG_IP_NF_MATCH_OWNER=m 370CONFIG_IP_NF_MATCH_OWNER=m
356CONFIG_IP_NF_MATCH_ADDRTYPE=m 371CONFIG_IP_NF_MATCH_ADDRTYPE=m
357CONFIG_IP_NF_MATCH_REALM=m
358CONFIG_IP_NF_MATCH_SCTP=m
359CONFIG_IP_NF_MATCH_DCCP=m
360CONFIG_IP_NF_MATCH_COMMENT=m
361CONFIG_IP_NF_MATCH_CONNMARK=m
362CONFIG_IP_NF_MATCH_CONNBYTES=m
363CONFIG_IP_NF_MATCH_HASHLIMIT=m 372CONFIG_IP_NF_MATCH_HASHLIMIT=m
364CONFIG_IP_NF_MATCH_STRING=m 373CONFIG_IP_NF_MATCH_POLICY=m
365CONFIG_IP_NF_FILTER=m 374CONFIG_IP_NF_FILTER=m
366CONFIG_IP_NF_TARGET_REJECT=m 375CONFIG_IP_NF_TARGET_REJECT=m
367CONFIG_IP_NF_TARGET_LOG=m 376CONFIG_IP_NF_TARGET_LOG=m
368CONFIG_IP_NF_TARGET_ULOG=m 377CONFIG_IP_NF_TARGET_ULOG=m
369CONFIG_IP_NF_TARGET_TCPMSS=m 378CONFIG_IP_NF_TARGET_TCPMSS=m
370CONFIG_IP_NF_TARGET_NFQUEUE=m
371CONFIG_IP_NF_NAT=m 379CONFIG_IP_NF_NAT=m
372CONFIG_IP_NF_NAT_NEEDED=y 380CONFIG_IP_NF_NAT_NEEDED=y
373CONFIG_IP_NF_TARGET_MASQUERADE=m 381CONFIG_IP_NF_TARGET_MASQUERADE=m
@@ -384,13 +392,9 @@ CONFIG_IP_NF_MANGLE=m
384CONFIG_IP_NF_TARGET_TOS=m 392CONFIG_IP_NF_TARGET_TOS=m
385CONFIG_IP_NF_TARGET_ECN=m 393CONFIG_IP_NF_TARGET_ECN=m
386CONFIG_IP_NF_TARGET_DSCP=m 394CONFIG_IP_NF_TARGET_DSCP=m
387CONFIG_IP_NF_TARGET_MARK=m
388CONFIG_IP_NF_TARGET_CLASSIFY=m
389CONFIG_IP_NF_TARGET_TTL=m 395CONFIG_IP_NF_TARGET_TTL=m
390CONFIG_IP_NF_TARGET_CONNMARK=m
391CONFIG_IP_NF_TARGET_CLUSTERIP=m 396CONFIG_IP_NF_TARGET_CLUSTERIP=m
392CONFIG_IP_NF_RAW=m 397CONFIG_IP_NF_RAW=m
393CONFIG_IP_NF_TARGET_NOTRACK=m
394CONFIG_IP_NF_ARPTABLES=m 398CONFIG_IP_NF_ARPTABLES=m
395CONFIG_IP_NF_ARPFILTER=m 399CONFIG_IP_NF_ARPFILTER=m
396CONFIG_IP_NF_ARP_MANGLE=m 400CONFIG_IP_NF_ARP_MANGLE=m
@@ -400,25 +404,20 @@ CONFIG_IP_NF_ARP_MANGLE=m
400# 404#
401CONFIG_IP6_NF_QUEUE=m 405CONFIG_IP6_NF_QUEUE=m
402CONFIG_IP6_NF_IPTABLES=m 406CONFIG_IP6_NF_IPTABLES=m
403CONFIG_IP6_NF_MATCH_LIMIT=m
404CONFIG_IP6_NF_MATCH_MAC=m
405CONFIG_IP6_NF_MATCH_RT=m 407CONFIG_IP6_NF_MATCH_RT=m
406CONFIG_IP6_NF_MATCH_OPTS=m 408CONFIG_IP6_NF_MATCH_OPTS=m
407CONFIG_IP6_NF_MATCH_FRAG=m 409CONFIG_IP6_NF_MATCH_FRAG=m
408CONFIG_IP6_NF_MATCH_HL=m 410CONFIG_IP6_NF_MATCH_HL=m
409CONFIG_IP6_NF_MATCH_MULTIPORT=m 411CONFIG_IP6_NF_MATCH_MULTIPORT=m
410CONFIG_IP6_NF_MATCH_OWNER=m 412CONFIG_IP6_NF_MATCH_OWNER=m
411CONFIG_IP6_NF_MATCH_MARK=m
412CONFIG_IP6_NF_MATCH_IPV6HEADER=m 413CONFIG_IP6_NF_MATCH_IPV6HEADER=m
413CONFIG_IP6_NF_MATCH_AHESP=m 414CONFIG_IP6_NF_MATCH_AHESP=m
414CONFIG_IP6_NF_MATCH_LENGTH=m
415CONFIG_IP6_NF_MATCH_EUI64=m 415CONFIG_IP6_NF_MATCH_EUI64=m
416CONFIG_IP6_NF_MATCH_POLICY=m
416CONFIG_IP6_NF_FILTER=m 417CONFIG_IP6_NF_FILTER=m
417CONFIG_IP6_NF_TARGET_LOG=m 418CONFIG_IP6_NF_TARGET_LOG=m
418CONFIG_IP6_NF_TARGET_REJECT=m 419CONFIG_IP6_NF_TARGET_REJECT=m
419CONFIG_IP6_NF_TARGET_NFQUEUE=m
420CONFIG_IP6_NF_MANGLE=m 420CONFIG_IP6_NF_MANGLE=m
421CONFIG_IP6_NF_TARGET_MARK=m
422CONFIG_IP6_NF_TARGET_HL=m 421CONFIG_IP6_NF_TARGET_HL=m
423CONFIG_IP6_NF_RAW=m 422CONFIG_IP6_NF_RAW=m
424 423
@@ -445,6 +444,11 @@ CONFIG_SCTP_HMAC_MD5=y
445# CONFIG_ATALK is not set 444# CONFIG_ATALK is not set
446# CONFIG_X25 is not set 445# CONFIG_X25 is not set
447# CONFIG_LAPB is not set 446# CONFIG_LAPB is not set
447
448#
449# TIPC Configuration (EXPERIMENTAL)
450#
451# CONFIG_TIPC is not set
448CONFIG_NET_DIVERT=y 452CONFIG_NET_DIVERT=y
449# CONFIG_ECONET is not set 453# CONFIG_ECONET is not set
450# CONFIG_WAN_ROUTER is not set 454# CONFIG_WAN_ROUTER is not set
@@ -504,7 +508,6 @@ CONFIG_IEEE80211=m
504# CONFIG_IEEE80211_DEBUG is not set 508# CONFIG_IEEE80211_DEBUG is not set
505CONFIG_IEEE80211_CRYPT_WEP=m 509CONFIG_IEEE80211_CRYPT_WEP=m
506CONFIG_IEEE80211_CRYPT_CCMP=m 510CONFIG_IEEE80211_CRYPT_CCMP=m
507CONFIG_IEEE80211_CRYPT_TKIP=m
508 511
509# 512#
510# Device Drivers 513# Device Drivers
@@ -641,6 +644,7 @@ CONFIG_CICADA_PHY=m
641# 644#
642CONFIG_NET_ETHERNET=y 645CONFIG_NET_ETHERNET=y
643# CONFIG_MII is not set 646# CONFIG_MII is not set
647# CONFIG_DM9000 is not set
644CONFIG_SGISEEQ=y 648CONFIG_SGISEEQ=y
645 649
646# 650#
@@ -787,6 +791,12 @@ CONFIG_MAX_RAW_DEVS=256
787# CONFIG_I2C is not set 791# CONFIG_I2C is not set
788 792
789# 793#
794# SPI support
795#
796# CONFIG_SPI is not set
797# CONFIG_SPI_MASTER is not set
798
799#
790# Dallas's 1-wire bus 800# Dallas's 1-wire bus
791# 801#
792# CONFIG_W1 is not set 802# CONFIG_W1 is not set
@@ -892,6 +902,7 @@ CONFIG_XFS_QUOTA=y
892CONFIG_XFS_SECURITY=y 902CONFIG_XFS_SECURITY=y
893# CONFIG_XFS_POSIX_ACL is not set 903# CONFIG_XFS_POSIX_ACL is not set
894# CONFIG_XFS_RT is not set 904# CONFIG_XFS_RT is not set
905# CONFIG_OCFS2_FS is not set
895CONFIG_MINIX_FS=m 906CONFIG_MINIX_FS=m
896# CONFIG_ROMFS_FS is not set 907# CONFIG_ROMFS_FS is not set
897CONFIG_INOTIFY=y 908CONFIG_INOTIFY=y
@@ -934,6 +945,7 @@ CONFIG_SYSFS=y
934# CONFIG_HUGETLB_PAGE is not set 945# CONFIG_HUGETLB_PAGE is not set
935CONFIG_RAMFS=y 946CONFIG_RAMFS=y
936CONFIG_RELAYFS_FS=m 947CONFIG_RELAYFS_FS=m
948# CONFIG_CONFIGFS_FS is not set
937 949
938# 950#
939# Miscellaneous filesystems 951# Miscellaneous filesystems
@@ -1007,6 +1019,7 @@ CONFIG_MSDOS_PARTITION=y
1007CONFIG_SGI_PARTITION=y 1019CONFIG_SGI_PARTITION=y
1008# CONFIG_ULTRIX_PARTITION is not set 1020# CONFIG_ULTRIX_PARTITION is not set
1009# CONFIG_SUN_PARTITION is not set 1021# CONFIG_SUN_PARTITION is not set
1022# CONFIG_KARMA_PARTITION is not set
1010# CONFIG_EFI_PARTITION is not set 1023# CONFIG_EFI_PARTITION is not set
1011 1024
1012# 1025#
@@ -1062,6 +1075,7 @@ CONFIG_NLS_UTF8=m
1062# Kernel hacking 1075# Kernel hacking
1063# 1076#
1064# CONFIG_PRINTK_TIME is not set 1077# CONFIG_PRINTK_TIME is not set
1078# CONFIG_MAGIC_SYSRQ is not set
1065# CONFIG_DEBUG_KERNEL is not set 1079# CONFIG_DEBUG_KERNEL is not set
1066CONFIG_LOG_BUF_SHIFT=14 1080CONFIG_LOG_BUF_SHIFT=14
1067CONFIG_CROSSCOMPILE=y 1081CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/ip27_defconfig b/arch/mips/configs/ip27_defconfig
index 58c22cd344d3..8c40590737e1 100644
--- a/arch/mips/configs/ip27_defconfig
+++ b/arch/mips/configs/ip27_defconfig
@@ -132,6 +132,7 @@ CONFIG_FLAT_NODE_MEM_MAP=y
132CONFIG_NEED_MULTIPLE_NODES=y 132CONFIG_NEED_MULTIPLE_NODES=y
133# CONFIG_SPARSEMEM_STATIC is not set 133# CONFIG_SPARSEMEM_STATIC is not set
134CONFIG_SPLIT_PTLOCK_CPUS=4 134CONFIG_SPLIT_PTLOCK_CPUS=4
135CONFIG_MIGRATION=y
135CONFIG_SMP=y 136CONFIG_SMP=y
136CONFIG_NR_CPUS=64 137CONFIG_NR_CPUS=64
137CONFIG_PREEMPT_NONE=y 138CONFIG_PREEMPT_NONE=y
@@ -158,28 +159,30 @@ CONFIG_POSIX_MQUEUE=y
158# CONFIG_BSD_PROCESS_ACCT is not set 159# CONFIG_BSD_PROCESS_ACCT is not set
159CONFIG_SYSCTL=y 160CONFIG_SYSCTL=y
160# CONFIG_AUDIT is not set 161# CONFIG_AUDIT is not set
161CONFIG_HOTPLUG=y
162CONFIG_KOBJECT_UEVENT=y
163CONFIG_IKCONFIG=y 162CONFIG_IKCONFIG=y
164CONFIG_IKCONFIG_PROC=y 163CONFIG_IKCONFIG_PROC=y
165CONFIG_CPUSETS=y 164CONFIG_CPUSETS=y
166CONFIG_INITRAMFS_SOURCE="" 165CONFIG_INITRAMFS_SOURCE=""
166# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
167CONFIG_EMBEDDED=y 167CONFIG_EMBEDDED=y
168CONFIG_KALLSYMS=y 168CONFIG_KALLSYMS=y
169# CONFIG_KALLSYMS_EXTRA_PASS is not set 169# CONFIG_KALLSYMS_EXTRA_PASS is not set
170CONFIG_HOTPLUG=y
170CONFIG_PRINTK=y 171CONFIG_PRINTK=y
171CONFIG_BUG=y 172CONFIG_BUG=y
173CONFIG_ELF_CORE=y
172CONFIG_BASE_FULL=y 174CONFIG_BASE_FULL=y
173CONFIG_FUTEX=y 175CONFIG_FUTEX=y
174CONFIG_EPOLL=y 176CONFIG_EPOLL=y
175# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
176CONFIG_SHMEM=y 177CONFIG_SHMEM=y
177CONFIG_CC_ALIGN_FUNCTIONS=0 178CONFIG_CC_ALIGN_FUNCTIONS=0
178CONFIG_CC_ALIGN_LABELS=0 179CONFIG_CC_ALIGN_LABELS=0
179CONFIG_CC_ALIGN_LOOPS=0 180CONFIG_CC_ALIGN_LOOPS=0
180CONFIG_CC_ALIGN_JUMPS=0 181CONFIG_CC_ALIGN_JUMPS=0
182CONFIG_SLAB=y
181# CONFIG_TINY_SHMEM is not set 183# CONFIG_TINY_SHMEM is not set
182CONFIG_BASE_SMALL=0 184CONFIG_BASE_SMALL=0
185# CONFIG_SLOB is not set
183 186
184# 187#
185# Loadable module support 188# Loadable module support
@@ -234,7 +237,6 @@ CONFIG_MMU=y
234# 237#
235CONFIG_BINFMT_ELF=y 238CONFIG_BINFMT_ELF=y
236# CONFIG_BINFMT_MISC is not set 239# CONFIG_BINFMT_MISC is not set
237CONFIG_BUILD_ELF64=y
238CONFIG_MIPS32_COMPAT=y 240CONFIG_MIPS32_COMPAT=y
239CONFIG_COMPAT=y 241CONFIG_COMPAT=y
240CONFIG_MIPS32_O32=y 242CONFIG_MIPS32_O32=y
@@ -290,6 +292,10 @@ CONFIG_TCP_CONG_BIC=y
290# 292#
291# CONFIG_IP_SCTP is not set 293# CONFIG_IP_SCTP is not set
292 294
295#
296# TIPC Configuration (EXPERIMENTAL)
297#
298# CONFIG_TIPC is not set
293# CONFIG_ATM is not set 299# CONFIG_ATM is not set
294# CONFIG_BRIDGE is not set 300# CONFIG_BRIDGE is not set
295# CONFIG_VLAN_8021Q is not set 301# CONFIG_VLAN_8021Q is not set
@@ -357,7 +363,6 @@ CONFIG_IEEE80211=m
357# CONFIG_IEEE80211_DEBUG is not set 363# CONFIG_IEEE80211_DEBUG is not set
358CONFIG_IEEE80211_CRYPT_WEP=m 364CONFIG_IEEE80211_CRYPT_WEP=m
359CONFIG_IEEE80211_CRYPT_CCMP=m 365CONFIG_IEEE80211_CRYPT_CCMP=m
360CONFIG_IEEE80211_CRYPT_TKIP=m
361 366
362# 367#
363# Device Drivers 368# Device Drivers
@@ -368,7 +373,7 @@ CONFIG_IEEE80211_CRYPT_TKIP=m
368# 373#
369CONFIG_STANDALONE=y 374CONFIG_STANDALONE=y
370CONFIG_PREVENT_FIRMWARE_BUILD=y 375CONFIG_PREVENT_FIRMWARE_BUILD=y
371CONFIG_FW_LOADER=m 376CONFIG_FW_LOADER=y
372 377
373# 378#
374# Connector - unified userspace <-> kernelspace linker 379# Connector - unified userspace <-> kernelspace linker
@@ -442,7 +447,7 @@ CONFIG_SCSI_LOGGING=y
442# SCSI Transport Attributes 447# SCSI Transport Attributes
443# 448#
444CONFIG_SCSI_SPI_ATTRS=y 449CONFIG_SCSI_SPI_ATTRS=y
445# CONFIG_SCSI_FC_ATTRS is not set 450CONFIG_SCSI_FC_ATTRS=y
446CONFIG_SCSI_ISCSI_ATTRS=m 451CONFIG_SCSI_ISCSI_ATTRS=m
447CONFIG_SCSI_SAS_ATTRS=m 452CONFIG_SCSI_SAS_ATTRS=m
448 453
@@ -470,13 +475,7 @@ CONFIG_SCSI_SAS_ATTRS=m
470# CONFIG_SCSI_IPR is not set 475# CONFIG_SCSI_IPR is not set
471# CONFIG_SCSI_QLOGIC_FC is not set 476# CONFIG_SCSI_QLOGIC_FC is not set
472CONFIG_SCSI_QLOGIC_1280=y 477CONFIG_SCSI_QLOGIC_1280=y
473CONFIG_SCSI_QLA2XXX=y 478# CONFIG_SCSI_QLA_FC is not set
474# CONFIG_SCSI_QLA21XX is not set
475# CONFIG_SCSI_QLA22XX is not set
476# CONFIG_SCSI_QLA2300 is not set
477# CONFIG_SCSI_QLA2322 is not set
478# CONFIG_SCSI_QLA6312 is not set
479# CONFIG_SCSI_QLA24XX is not set
480# CONFIG_SCSI_LPFC is not set 479# CONFIG_SCSI_LPFC is not set
481# CONFIG_SCSI_DC395x is not set 480# CONFIG_SCSI_DC395x is not set
482# CONFIG_SCSI_DC390T is not set 481# CONFIG_SCSI_DC390T is not set
@@ -561,6 +560,7 @@ CONFIG_SGI_IOC3_ETH_HW_TX_CSUM=y
561# CONFIG_SUNGEM is not set 560# CONFIG_SUNGEM is not set
562# CONFIG_CASSINI is not set 561# CONFIG_CASSINI is not set
563# CONFIG_NET_VENDOR_3COM is not set 562# CONFIG_NET_VENDOR_3COM is not set
563# CONFIG_DM9000 is not set
564 564
565# 565#
566# Tulip family network device support 566# Tulip family network device support
@@ -581,6 +581,7 @@ CONFIG_SGI_IOC3_ETH_HW_TX_CSUM=y
581# CONFIG_R8169 is not set 581# CONFIG_R8169 is not set
582# CONFIG_SIS190 is not set 582# CONFIG_SIS190 is not set
583# CONFIG_SKGE is not set 583# CONFIG_SKGE is not set
584# CONFIG_SKY2 is not set
584# CONFIG_SK98LIN is not set 585# CONFIG_SK98LIN is not set
585# CONFIG_TIGON3 is not set 586# CONFIG_TIGON3 is not set
586# CONFIG_BNX2 is not set 587# CONFIG_BNX2 is not set
@@ -601,8 +602,6 @@ CONFIG_SGI_IOC3_ETH_HW_TX_CSUM=y
601# Wireless LAN (non-hamradio) 602# Wireless LAN (non-hamradio)
602# 603#
603# CONFIG_NET_RADIO is not set 604# CONFIG_NET_RADIO is not set
604# CONFIG_IPW_DEBUG is not set
605CONFIG_IPW2200=m
606 605
607# 606#
608# Wan interfaces 607# Wan interfaces
@@ -656,6 +655,7 @@ CONFIG_SERIO_RAW=m
656CONFIG_SERIAL_8250=y 655CONFIG_SERIAL_8250=y
657CONFIG_SERIAL_8250_CONSOLE=y 656CONFIG_SERIAL_8250_CONSOLE=y
658CONFIG_SERIAL_8250_NR_UARTS=4 657CONFIG_SERIAL_8250_NR_UARTS=4
658CONFIG_SERIAL_8250_RUNTIME_UARTS=4
659CONFIG_SERIAL_8250_EXTENDED=y 659CONFIG_SERIAL_8250_EXTENDED=y
660CONFIG_SERIAL_8250_MANY_PORTS=y 660CONFIG_SERIAL_8250_MANY_PORTS=y
661CONFIG_SERIAL_8250_SHARE_IRQ=y 661CONFIG_SERIAL_8250_SHARE_IRQ=y
@@ -706,6 +706,12 @@ CONFIG_SGI_IP27_RTC=y
706# CONFIG_I2C is not set 706# CONFIG_I2C is not set
707 707
708# 708#
709# SPI support
710#
711# CONFIG_SPI is not set
712# CONFIG_SPI_MASTER is not set
713
714#
709# Dallas's 1-wire bus 715# Dallas's 1-wire bus
710# 716#
711# CONFIG_W1 is not set 717# CONFIG_W1 is not set
@@ -801,6 +807,7 @@ CONFIG_XFS_QUOTA=y
801CONFIG_XFS_SECURITY=y 807CONFIG_XFS_SECURITY=y
802CONFIG_XFS_POSIX_ACL=y 808CONFIG_XFS_POSIX_ACL=y
803# CONFIG_XFS_RT is not set 809# CONFIG_XFS_RT is not set
810# CONFIG_OCFS2_FS is not set
804# CONFIG_MINIX_FS is not set 811# CONFIG_MINIX_FS is not set
805# CONFIG_ROMFS_FS is not set 812# CONFIG_ROMFS_FS is not set
806CONFIG_INOTIFY=y 813CONFIG_INOTIFY=y
@@ -834,6 +841,7 @@ CONFIG_SYSFS=y
834# CONFIG_HUGETLB_PAGE is not set 841# CONFIG_HUGETLB_PAGE is not set
835CONFIG_RAMFS=y 842CONFIG_RAMFS=y
836CONFIG_RELAYFS_FS=m 843CONFIG_RELAYFS_FS=m
844# CONFIG_CONFIGFS_FS is not set
837 845
838# 846#
839# Miscellaneous filesystems 847# Miscellaneous filesystems
@@ -894,6 +902,7 @@ CONFIG_MSDOS_PARTITION=y
894CONFIG_SGI_PARTITION=y 902CONFIG_SGI_PARTITION=y
895# CONFIG_ULTRIX_PARTITION is not set 903# CONFIG_ULTRIX_PARTITION is not set
896# CONFIG_SUN_PARTITION is not set 904# CONFIG_SUN_PARTITION is not set
905# CONFIG_KARMA_PARTITION is not set
897# CONFIG_EFI_PARTITION is not set 906# CONFIG_EFI_PARTITION is not set
898 907
899# 908#
@@ -910,6 +919,7 @@ CONFIG_SGI_PARTITION=y
910# Kernel hacking 919# Kernel hacking
911# 920#
912# CONFIG_PRINTK_TIME is not set 921# CONFIG_PRINTK_TIME is not set
922# CONFIG_MAGIC_SYSRQ is not set
913# CONFIG_DEBUG_KERNEL is not set 923# CONFIG_DEBUG_KERNEL is not set
914CONFIG_LOG_BUF_SHIFT=15 924CONFIG_LOG_BUF_SHIFT=15
915CONFIG_CROSSCOMPILE=y 925CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/ip32_defconfig b/arch/mips/configs/ip32_defconfig
index a34db6e82b27..7fdcaf51face 100644
--- a/arch/mips/configs/ip32_defconfig
+++ b/arch/mips/configs/ip32_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:24 2005 4# Fri Jan 27 15:40:09 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -158,26 +158,28 @@ CONFIG_BSD_PROCESS_ACCT=y
158# CONFIG_BSD_PROCESS_ACCT_V3 is not set 158# CONFIG_BSD_PROCESS_ACCT_V3 is not set
159CONFIG_SYSCTL=y 159CONFIG_SYSCTL=y
160# CONFIG_AUDIT is not set 160# CONFIG_AUDIT is not set
161CONFIG_HOTPLUG=y
162CONFIG_KOBJECT_UEVENT=y
163# CONFIG_IKCONFIG is not set 161# CONFIG_IKCONFIG is not set
164CONFIG_INITRAMFS_SOURCE="" 162CONFIG_INITRAMFS_SOURCE=""
163# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
165CONFIG_EMBEDDED=y 164CONFIG_EMBEDDED=y
166CONFIG_KALLSYMS=y 165CONFIG_KALLSYMS=y
167# CONFIG_KALLSYMS_EXTRA_PASS is not set 166# CONFIG_KALLSYMS_EXTRA_PASS is not set
167CONFIG_HOTPLUG=y
168CONFIG_PRINTK=y 168CONFIG_PRINTK=y
169CONFIG_BUG=y 169CONFIG_BUG=y
170CONFIG_ELF_CORE=y
170CONFIG_BASE_FULL=y 171CONFIG_BASE_FULL=y
171CONFIG_FUTEX=y 172CONFIG_FUTEX=y
172CONFIG_EPOLL=y 173CONFIG_EPOLL=y
173# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
174CONFIG_SHMEM=y 174CONFIG_SHMEM=y
175CONFIG_CC_ALIGN_FUNCTIONS=0 175CONFIG_CC_ALIGN_FUNCTIONS=0
176CONFIG_CC_ALIGN_LABELS=0 176CONFIG_CC_ALIGN_LABELS=0
177CONFIG_CC_ALIGN_LOOPS=0 177CONFIG_CC_ALIGN_LOOPS=0
178CONFIG_CC_ALIGN_JUMPS=0 178CONFIG_CC_ALIGN_JUMPS=0
179CONFIG_SLAB=y
179# CONFIG_TINY_SHMEM is not set 180# CONFIG_TINY_SHMEM is not set
180CONFIG_BASE_SMALL=0 181CONFIG_BASE_SMALL=0
182# CONFIG_SLOB is not set
181 183
182# 184#
183# Loadable module support 185# Loadable module support
@@ -224,7 +226,6 @@ CONFIG_MMU=y
224# 226#
225CONFIG_BINFMT_ELF=y 227CONFIG_BINFMT_ELF=y
226CONFIG_BINFMT_MISC=y 228CONFIG_BINFMT_MISC=y
227# CONFIG_BUILD_ELF64 is not set
228CONFIG_MIPS32_COMPAT=y 229CONFIG_MIPS32_COMPAT=y
229CONFIG_COMPAT=y 230CONFIG_COMPAT=y
230CONFIG_MIPS32_O32=y 231CONFIG_MIPS32_O32=y
@@ -286,6 +287,11 @@ CONFIG_TCP_CONG_BIC=y
286# CONFIG_ATALK is not set 287# CONFIG_ATALK is not set
287# CONFIG_X25 is not set 288# CONFIG_X25 is not set
288# CONFIG_LAPB is not set 289# CONFIG_LAPB is not set
290
291#
292# TIPC Configuration (EXPERIMENTAL)
293#
294# CONFIG_TIPC is not set
289# CONFIG_NET_DIVERT is not set 295# CONFIG_NET_DIVERT is not set
290# CONFIG_ECONET is not set 296# CONFIG_ECONET is not set
291# CONFIG_WAN_ROUTER is not set 297# CONFIG_WAN_ROUTER is not set
@@ -306,7 +312,6 @@ CONFIG_IEEE80211=y
306# CONFIG_IEEE80211_DEBUG is not set 312# CONFIG_IEEE80211_DEBUG is not set
307CONFIG_IEEE80211_CRYPT_WEP=y 313CONFIG_IEEE80211_CRYPT_WEP=y
308CONFIG_IEEE80211_CRYPT_CCMP=y 314CONFIG_IEEE80211_CRYPT_CCMP=y
309CONFIG_IEEE80211_CRYPT_TKIP=y
310 315
311# 316#
312# Device Drivers 317# Device Drivers
@@ -392,7 +397,7 @@ CONFIG_SCSI_LOGGING=y
392# SCSI Transport Attributes 397# SCSI Transport Attributes
393# 398#
394CONFIG_SCSI_SPI_ATTRS=y 399CONFIG_SCSI_SPI_ATTRS=y
395# CONFIG_SCSI_FC_ATTRS is not set 400CONFIG_SCSI_FC_ATTRS=y
396# CONFIG_SCSI_ISCSI_ATTRS is not set 401# CONFIG_SCSI_ISCSI_ATTRS is not set
397CONFIG_SCSI_SAS_ATTRS=y 402CONFIG_SCSI_SAS_ATTRS=y
398 403
@@ -425,13 +430,7 @@ CONFIG_AIC7XXX_REG_PRETTY_PRINT=y
425# CONFIG_SCSI_IPR is not set 430# CONFIG_SCSI_IPR is not set
426# CONFIG_SCSI_QLOGIC_FC is not set 431# CONFIG_SCSI_QLOGIC_FC is not set
427# CONFIG_SCSI_QLOGIC_1280 is not set 432# CONFIG_SCSI_QLOGIC_1280 is not set
428CONFIG_SCSI_QLA2XXX=y 433# CONFIG_SCSI_QLA_FC is not set
429# CONFIG_SCSI_QLA21XX is not set
430# CONFIG_SCSI_QLA22XX is not set
431# CONFIG_SCSI_QLA2300 is not set
432# CONFIG_SCSI_QLA2322 is not set
433# CONFIG_SCSI_QLA6312 is not set
434# CONFIG_SCSI_QLA24XX is not set
435# CONFIG_SCSI_LPFC is not set 434# CONFIG_SCSI_LPFC is not set
436# CONFIG_SCSI_DC395x is not set 435# CONFIG_SCSI_DC395x is not set
437# CONFIG_SCSI_DC390T is not set 436# CONFIG_SCSI_DC390T is not set
@@ -498,6 +497,7 @@ CONFIG_SGI_O2MACE_ETH=y
498# CONFIG_SUNGEM is not set 497# CONFIG_SUNGEM is not set
499# CONFIG_CASSINI is not set 498# CONFIG_CASSINI is not set
500# CONFIG_NET_VENDOR_3COM is not set 499# CONFIG_NET_VENDOR_3COM is not set
500# CONFIG_DM9000 is not set
501 501
502# 502#
503# Tulip family network device support 503# Tulip family network device support
@@ -518,6 +518,7 @@ CONFIG_SGI_O2MACE_ETH=y
518# CONFIG_R8169 is not set 518# CONFIG_R8169 is not set
519# CONFIG_SIS190 is not set 519# CONFIG_SIS190 is not set
520# CONFIG_SKGE is not set 520# CONFIG_SKGE is not set
521# CONFIG_SKY2 is not set
521# CONFIG_SK98LIN is not set 522# CONFIG_SK98LIN is not set
522# CONFIG_TIGON3 is not set 523# CONFIG_TIGON3 is not set
523# CONFIG_BNX2 is not set 524# CONFIG_BNX2 is not set
@@ -538,8 +539,6 @@ CONFIG_SGI_O2MACE_ETH=y
538# Wireless LAN (non-hamradio) 539# Wireless LAN (non-hamradio)
539# 540#
540# CONFIG_NET_RADIO is not set 541# CONFIG_NET_RADIO is not set
541# CONFIG_IPW_DEBUG is not set
542CONFIG_IPW2200=y
543 542
544# 543#
545# Wan interfaces 544# Wan interfaces
@@ -617,6 +616,7 @@ CONFIG_HW_CONSOLE=y
617CONFIG_SERIAL_8250=y 616CONFIG_SERIAL_8250=y
618CONFIG_SERIAL_8250_CONSOLE=y 617CONFIG_SERIAL_8250_CONSOLE=y
619CONFIG_SERIAL_8250_NR_UARTS=4 618CONFIG_SERIAL_8250_NR_UARTS=4
619CONFIG_SERIAL_8250_RUNTIME_UARTS=4
620# CONFIG_SERIAL_8250_EXTENDED is not set 620# CONFIG_SERIAL_8250_EXTENDED is not set
621 621
622# 622#
@@ -624,7 +624,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
624# 624#
625CONFIG_SERIAL_CORE=y 625CONFIG_SERIAL_CORE=y
626CONFIG_SERIAL_CORE_CONSOLE=y 626CONFIG_SERIAL_CORE_CONSOLE=y
627# CONFIG_SERIAL_JSM is not set
628CONFIG_UNIX98_PTYS=y 627CONFIG_UNIX98_PTYS=y
629CONFIG_LEGACY_PTYS=y 628CONFIG_LEGACY_PTYS=y
630CONFIG_LEGACY_PTY_COUNT=256 629CONFIG_LEGACY_PTY_COUNT=256
@@ -662,6 +661,12 @@ CONFIG_LEGACY_PTY_COUNT=256
662# CONFIG_I2C is not set 661# CONFIG_I2C is not set
663 662
664# 663#
664# SPI support
665#
666# CONFIG_SPI is not set
667# CONFIG_SPI_MASTER is not set
668
669#
665# Dallas's 1-wire bus 670# Dallas's 1-wire bus
666# 671#
667# CONFIG_W1 is not set 672# CONFIG_W1 is not set
@@ -743,11 +748,11 @@ CONFIG_EXT2_FS=y
743# CONFIG_EXT2_FS_XATTR is not set 748# CONFIG_EXT2_FS_XATTR is not set
744# CONFIG_EXT2_FS_XIP is not set 749# CONFIG_EXT2_FS_XIP is not set
745# CONFIG_EXT3_FS is not set 750# CONFIG_EXT3_FS is not set
746# CONFIG_JBD is not set
747# CONFIG_REISERFS_FS is not set 751# CONFIG_REISERFS_FS is not set
748# CONFIG_JFS_FS is not set 752# CONFIG_JFS_FS is not set
749# CONFIG_FS_POSIX_ACL is not set 753# CONFIG_FS_POSIX_ACL is not set
750# CONFIG_XFS_FS is not set 754# CONFIG_XFS_FS is not set
755# CONFIG_OCFS2_FS is not set
751# CONFIG_MINIX_FS is not set 756# CONFIG_MINIX_FS is not set
752# CONFIG_ROMFS_FS is not set 757# CONFIG_ROMFS_FS is not set
753CONFIG_INOTIFY=y 758CONFIG_INOTIFY=y
@@ -780,6 +785,7 @@ CONFIG_TMPFS=y
780# CONFIG_HUGETLB_PAGE is not set 785# CONFIG_HUGETLB_PAGE is not set
781CONFIG_RAMFS=y 786CONFIG_RAMFS=y
782CONFIG_RELAYFS_FS=y 787CONFIG_RELAYFS_FS=y
788# CONFIG_CONFIGFS_FS is not set
783 789
784# 790#
785# Miscellaneous filesystems 791# Miscellaneous filesystems
@@ -835,6 +841,7 @@ CONFIG_PARTITION_ADVANCED=y
835CONFIG_SGI_PARTITION=y 841CONFIG_SGI_PARTITION=y
836# CONFIG_ULTRIX_PARTITION is not set 842# CONFIG_ULTRIX_PARTITION is not set
837# CONFIG_SUN_PARTITION is not set 843# CONFIG_SUN_PARTITION is not set
844# CONFIG_KARMA_PARTITION is not set
838# CONFIG_EFI_PARTITION is not set 845# CONFIG_EFI_PARTITION is not set
839 846
840# 847#
@@ -851,6 +858,7 @@ CONFIG_SGI_PARTITION=y
851# Kernel hacking 858# Kernel hacking
852# 859#
853# CONFIG_PRINTK_TIME is not set 860# CONFIG_PRINTK_TIME is not set
861# CONFIG_MAGIC_SYSRQ is not set
854# CONFIG_DEBUG_KERNEL is not set 862# CONFIG_DEBUG_KERNEL is not set
855CONFIG_LOG_BUF_SHIFT=14 863CONFIG_LOG_BUF_SHIFT=14
856CONFIG_CROSSCOMPILE=y 864CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/it8172_defconfig b/arch/mips/configs/it8172_defconfig
index b5fa9639db6f..c716996d9eca 100644
--- a/arch/mips/configs/it8172_defconfig
+++ b/arch/mips/configs/it8172_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:26 2005 4# Fri Jan 27 15:40:10 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -153,26 +153,29 @@ CONFIG_BSD_PROCESS_ACCT=y
153# CONFIG_BSD_PROCESS_ACCT_V3 is not set 153# CONFIG_BSD_PROCESS_ACCT_V3 is not set
154CONFIG_SYSCTL=y 154CONFIG_SYSCTL=y
155# CONFIG_AUDIT is not set 155# CONFIG_AUDIT is not set
156# CONFIG_HOTPLUG is not set
157CONFIG_KOBJECT_UEVENT=y
158# CONFIG_IKCONFIG is not set 156# CONFIG_IKCONFIG is not set
159CONFIG_INITRAMFS_SOURCE="" 157CONFIG_INITRAMFS_SOURCE=""
158# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
160CONFIG_EMBEDDED=y 159CONFIG_EMBEDDED=y
161CONFIG_KALLSYMS=y 160CONFIG_KALLSYMS=y
162# CONFIG_KALLSYMS_EXTRA_PASS is not set 161# CONFIG_KALLSYMS_EXTRA_PASS is not set
162# CONFIG_HOTPLUG is not set
163CONFIG_PRINTK=y 163CONFIG_PRINTK=y
164CONFIG_BUG=y 164CONFIG_BUG=y
165CONFIG_ELF_CORE=y
165CONFIG_BASE_FULL=y 166CONFIG_BASE_FULL=y
166CONFIG_FUTEX=y 167CONFIG_FUTEX=y
167CONFIG_EPOLL=y 168CONFIG_EPOLL=y
168# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
169CONFIG_SHMEM=y 169CONFIG_SHMEM=y
170CONFIG_CC_ALIGN_FUNCTIONS=0 170CONFIG_CC_ALIGN_FUNCTIONS=0
171CONFIG_CC_ALIGN_LABELS=0 171CONFIG_CC_ALIGN_LABELS=0
172CONFIG_CC_ALIGN_LOOPS=0 172CONFIG_CC_ALIGN_LOOPS=0
173CONFIG_CC_ALIGN_JUMPS=0 173CONFIG_CC_ALIGN_JUMPS=0
174CONFIG_SLAB=y
174# CONFIG_TINY_SHMEM is not set 175# CONFIG_TINY_SHMEM is not set
175CONFIG_BASE_SMALL=0 176CONFIG_BASE_SMALL=0
177# CONFIG_SLOB is not set
178CONFIG_OBSOLETE_INTERMODULE=y
176 179
177# 180#
178# Loadable module support 181# Loadable module support
@@ -281,6 +284,11 @@ CONFIG_TCP_CONG_BIC=y
281# CONFIG_ATALK is not set 284# CONFIG_ATALK is not set
282# CONFIG_X25 is not set 285# CONFIG_X25 is not set
283# CONFIG_LAPB is not set 286# CONFIG_LAPB is not set
287
288#
289# TIPC Configuration (EXPERIMENTAL)
290#
291# CONFIG_TIPC is not set
284# CONFIG_NET_DIVERT is not set 292# CONFIG_NET_DIVERT is not set
285# CONFIG_ECONET is not set 293# CONFIG_ECONET is not set
286# CONFIG_WAN_ROUTER is not set 294# CONFIG_WAN_ROUTER is not set
@@ -301,7 +309,6 @@ CONFIG_IEEE80211=m
301# CONFIG_IEEE80211_DEBUG is not set 309# CONFIG_IEEE80211_DEBUG is not set
302CONFIG_IEEE80211_CRYPT_WEP=m 310CONFIG_IEEE80211_CRYPT_WEP=m
303CONFIG_IEEE80211_CRYPT_CCMP=m 311CONFIG_IEEE80211_CRYPT_CCMP=m
304CONFIG_IEEE80211_CRYPT_TKIP=m
305 312
306# 313#
307# Device Drivers 314# Device Drivers
@@ -362,6 +369,7 @@ CONFIG_MTD_CFI_UTIL=y
362# CONFIG_MTD_RAM is not set 369# CONFIG_MTD_RAM is not set
363# CONFIG_MTD_ROM is not set 370# CONFIG_MTD_ROM is not set
364# CONFIG_MTD_ABSENT is not set 371# CONFIG_MTD_ABSENT is not set
372# CONFIG_MTD_OBSOLETE_CHIPS is not set
365 373
366# 374#
367# Mapping drivers for chip access 375# Mapping drivers for chip access
@@ -500,6 +508,7 @@ CONFIG_CICADA_PHY=m
500# 508#
501CONFIG_NET_ETHERNET=y 509CONFIG_NET_ETHERNET=y
502# CONFIG_MII is not set 510# CONFIG_MII is not set
511# CONFIG_DM9000 is not set
503 512
504# 513#
505# Ethernet (1000 Mbit) 514# Ethernet (1000 Mbit)
@@ -593,6 +602,7 @@ CONFIG_HW_CONSOLE=y
593CONFIG_SERIAL_8250=y 602CONFIG_SERIAL_8250=y
594CONFIG_SERIAL_8250_CONSOLE=y 603CONFIG_SERIAL_8250_CONSOLE=y
595CONFIG_SERIAL_8250_NR_UARTS=4 604CONFIG_SERIAL_8250_NR_UARTS=4
605CONFIG_SERIAL_8250_RUNTIME_UARTS=4
596# CONFIG_SERIAL_8250_EXTENDED is not set 606# CONFIG_SERIAL_8250_EXTENDED is not set
597 607
598# 608#
@@ -635,6 +645,12 @@ CONFIG_LEGACY_PTY_COUNT=256
635# CONFIG_I2C is not set 645# CONFIG_I2C is not set
636 646
637# 647#
648# SPI support
649#
650# CONFIG_SPI is not set
651# CONFIG_SPI_MASTER is not set
652
653#
638# Dallas's 1-wire bus 654# Dallas's 1-wire bus
639# 655#
640# CONFIG_W1 is not set 656# CONFIG_W1 is not set
@@ -728,11 +744,11 @@ CONFIG_EXT2_FS=y
728# CONFIG_EXT2_FS_XATTR is not set 744# CONFIG_EXT2_FS_XATTR is not set
729# CONFIG_EXT2_FS_XIP is not set 745# CONFIG_EXT2_FS_XIP is not set
730# CONFIG_EXT3_FS is not set 746# CONFIG_EXT3_FS is not set
731# CONFIG_JBD is not set
732# CONFIG_REISERFS_FS is not set 747# CONFIG_REISERFS_FS is not set
733# CONFIG_JFS_FS is not set 748# CONFIG_JFS_FS is not set
734# CONFIG_FS_POSIX_ACL is not set 749# CONFIG_FS_POSIX_ACL is not set
735# CONFIG_XFS_FS is not set 750# CONFIG_XFS_FS is not set
751# CONFIG_OCFS2_FS is not set
736# CONFIG_MINIX_FS is not set 752# CONFIG_MINIX_FS is not set
737# CONFIG_ROMFS_FS is not set 753# CONFIG_ROMFS_FS is not set
738CONFIG_INOTIFY=y 754CONFIG_INOTIFY=y
@@ -765,6 +781,7 @@ CONFIG_SYSFS=y
765# CONFIG_HUGETLB_PAGE is not set 781# CONFIG_HUGETLB_PAGE is not set
766CONFIG_RAMFS=y 782CONFIG_RAMFS=y
767CONFIG_RELAYFS_FS=m 783CONFIG_RELAYFS_FS=m
784# CONFIG_CONFIGFS_FS is not set
768 785
769# 786#
770# Miscellaneous filesystems 787# Miscellaneous filesystems
@@ -826,6 +843,7 @@ CONFIG_MSDOS_PARTITION=y
826# Kernel hacking 843# Kernel hacking
827# 844#
828# CONFIG_PRINTK_TIME is not set 845# CONFIG_PRINTK_TIME is not set
846# CONFIG_MAGIC_SYSRQ is not set
829# CONFIG_DEBUG_KERNEL is not set 847# CONFIG_DEBUG_KERNEL is not set
830CONFIG_LOG_BUF_SHIFT=14 848CONFIG_LOG_BUF_SHIFT=14
831CONFIG_CROSSCOMPILE=y 849CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/ivr_defconfig b/arch/mips/configs/ivr_defconfig
index 71386938d47f..a8376d125e11 100644
--- a/arch/mips/configs/ivr_defconfig
+++ b/arch/mips/configs/ivr_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:27 2005 4# Fri Jan 27 15:40:11 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -150,26 +150,28 @@ CONFIG_BSD_PROCESS_ACCT=y
150# CONFIG_BSD_PROCESS_ACCT_V3 is not set 150# CONFIG_BSD_PROCESS_ACCT_V3 is not set
151CONFIG_SYSCTL=y 151CONFIG_SYSCTL=y
152# CONFIG_AUDIT is not set 152# CONFIG_AUDIT is not set
153CONFIG_HOTPLUG=y
154CONFIG_KOBJECT_UEVENT=y
155# CONFIG_IKCONFIG is not set 153# CONFIG_IKCONFIG is not set
156CONFIG_INITRAMFS_SOURCE="" 154CONFIG_INITRAMFS_SOURCE=""
155# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
157CONFIG_EMBEDDED=y 156CONFIG_EMBEDDED=y
158CONFIG_KALLSYMS=y 157CONFIG_KALLSYMS=y
159# CONFIG_KALLSYMS_EXTRA_PASS is not set 158# CONFIG_KALLSYMS_EXTRA_PASS is not set
159CONFIG_HOTPLUG=y
160CONFIG_PRINTK=y 160CONFIG_PRINTK=y
161CONFIG_BUG=y 161CONFIG_BUG=y
162CONFIG_ELF_CORE=y
162CONFIG_BASE_FULL=y 163CONFIG_BASE_FULL=y
163CONFIG_FUTEX=y 164CONFIG_FUTEX=y
164CONFIG_EPOLL=y 165CONFIG_EPOLL=y
165# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
166CONFIG_SHMEM=y 166CONFIG_SHMEM=y
167CONFIG_CC_ALIGN_FUNCTIONS=0 167CONFIG_CC_ALIGN_FUNCTIONS=0
168CONFIG_CC_ALIGN_LABELS=0 168CONFIG_CC_ALIGN_LABELS=0
169CONFIG_CC_ALIGN_LOOPS=0 169CONFIG_CC_ALIGN_LOOPS=0
170CONFIG_CC_ALIGN_JUMPS=0 170CONFIG_CC_ALIGN_JUMPS=0
171CONFIG_SLAB=y
171# CONFIG_TINY_SHMEM is not set 172# CONFIG_TINY_SHMEM is not set
172CONFIG_BASE_SMALL=0 173CONFIG_BASE_SMALL=0
174# CONFIG_SLOB is not set
173 175
174# 176#
175# Loadable module support 177# Loadable module support
@@ -280,6 +282,11 @@ CONFIG_TCP_CONG_BIC=y
280# CONFIG_ATALK is not set 282# CONFIG_ATALK is not set
281# CONFIG_X25 is not set 283# CONFIG_X25 is not set
282# CONFIG_LAPB is not set 284# CONFIG_LAPB is not set
285
286#
287# TIPC Configuration (EXPERIMENTAL)
288#
289# CONFIG_TIPC is not set
283# CONFIG_NET_DIVERT is not set 290# CONFIG_NET_DIVERT is not set
284# CONFIG_ECONET is not set 291# CONFIG_ECONET is not set
285# CONFIG_WAN_ROUTER is not set 292# CONFIG_WAN_ROUTER is not set
@@ -300,7 +307,6 @@ CONFIG_IEEE80211=m
300# CONFIG_IEEE80211_DEBUG is not set 307# CONFIG_IEEE80211_DEBUG is not set
301CONFIG_IEEE80211_CRYPT_WEP=m 308CONFIG_IEEE80211_CRYPT_WEP=m
302CONFIG_IEEE80211_CRYPT_CCMP=m 309CONFIG_IEEE80211_CRYPT_CCMP=m
303CONFIG_IEEE80211_CRYPT_TKIP=m
304 310
305# 311#
306# Device Drivers 312# Device Drivers
@@ -440,6 +446,7 @@ CONFIG_NET_ETHERNET=y
440# CONFIG_SUNGEM is not set 446# CONFIG_SUNGEM is not set
441# CONFIG_CASSINI is not set 447# CONFIG_CASSINI is not set
442# CONFIG_NET_VENDOR_3COM is not set 448# CONFIG_NET_VENDOR_3COM is not set
449# CONFIG_DM9000 is not set
443 450
444# 451#
445# Tulip family network device support 452# Tulip family network device support
@@ -460,6 +467,7 @@ CONFIG_NET_ETHERNET=y
460# CONFIG_R8169 is not set 467# CONFIG_R8169 is not set
461# CONFIG_SIS190 is not set 468# CONFIG_SIS190 is not set
462# CONFIG_SKGE is not set 469# CONFIG_SKGE is not set
470# CONFIG_SKY2 is not set
463# CONFIG_SK98LIN is not set 471# CONFIG_SK98LIN is not set
464# CONFIG_TIGON3 is not set 472# CONFIG_TIGON3 is not set
465# CONFIG_BNX2 is not set 473# CONFIG_BNX2 is not set
@@ -480,8 +488,6 @@ CONFIG_NET_ETHERNET=y
480# Wireless LAN (non-hamradio) 488# Wireless LAN (non-hamradio)
481# 489#
482# CONFIG_NET_RADIO is not set 490# CONFIG_NET_RADIO is not set
483# CONFIG_IPW_DEBUG is not set
484CONFIG_IPW2200=m
485 491
486# 492#
487# Wan interfaces 493# Wan interfaces
@@ -560,6 +566,7 @@ CONFIG_IT8172_SCR1=y
560CONFIG_SERIAL_8250=y 566CONFIG_SERIAL_8250=y
561CONFIG_SERIAL_8250_CONSOLE=y 567CONFIG_SERIAL_8250_CONSOLE=y
562CONFIG_SERIAL_8250_NR_UARTS=4 568CONFIG_SERIAL_8250_NR_UARTS=4
569CONFIG_SERIAL_8250_RUNTIME_UARTS=4
563# CONFIG_SERIAL_8250_EXTENDED is not set 570# CONFIG_SERIAL_8250_EXTENDED is not set
564 571
565# 572#
@@ -567,7 +574,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
567# 574#
568CONFIG_SERIAL_CORE=y 575CONFIG_SERIAL_CORE=y
569CONFIG_SERIAL_CORE_CONSOLE=y 576CONFIG_SERIAL_CORE_CONSOLE=y
570# CONFIG_SERIAL_JSM is not set
571CONFIG_UNIX98_PTYS=y 577CONFIG_UNIX98_PTYS=y
572CONFIG_LEGACY_PTYS=y 578CONFIG_LEGACY_PTYS=y
573CONFIG_LEGACY_PTY_COUNT=256 579CONFIG_LEGACY_PTY_COUNT=256
@@ -604,6 +610,12 @@ CONFIG_RTC=y
604# CONFIG_I2C is not set 610# CONFIG_I2C is not set
605 611
606# 612#
613# SPI support
614#
615# CONFIG_SPI is not set
616# CONFIG_SPI_MASTER is not set
617
618#
607# Dallas's 1-wire bus 619# Dallas's 1-wire bus
608# 620#
609# CONFIG_W1 is not set 621# CONFIG_W1 is not set
@@ -685,11 +697,11 @@ CONFIG_EXT2_FS=y
685# CONFIG_EXT2_FS_XATTR is not set 697# CONFIG_EXT2_FS_XATTR is not set
686# CONFIG_EXT2_FS_XIP is not set 698# CONFIG_EXT2_FS_XIP is not set
687# CONFIG_EXT3_FS is not set 699# CONFIG_EXT3_FS is not set
688# CONFIG_JBD is not set
689# CONFIG_REISERFS_FS is not set 700# CONFIG_REISERFS_FS is not set
690# CONFIG_JFS_FS is not set 701# CONFIG_JFS_FS is not set
691# CONFIG_FS_POSIX_ACL is not set 702# CONFIG_FS_POSIX_ACL is not set
692# CONFIG_XFS_FS is not set 703# CONFIG_XFS_FS is not set
704# CONFIG_OCFS2_FS is not set
693# CONFIG_MINIX_FS is not set 705# CONFIG_MINIX_FS is not set
694# CONFIG_ROMFS_FS is not set 706# CONFIG_ROMFS_FS is not set
695CONFIG_INOTIFY=y 707CONFIG_INOTIFY=y
@@ -722,6 +734,7 @@ CONFIG_SYSFS=y
722# CONFIG_HUGETLB_PAGE is not set 734# CONFIG_HUGETLB_PAGE is not set
723CONFIG_RAMFS=y 735CONFIG_RAMFS=y
724CONFIG_RELAYFS_FS=m 736CONFIG_RELAYFS_FS=m
737# CONFIG_CONFIGFS_FS is not set
725 738
726# 739#
727# Miscellaneous filesystems 740# Miscellaneous filesystems
@@ -781,6 +794,7 @@ CONFIG_MSDOS_PARTITION=y
781# Kernel hacking 794# Kernel hacking
782# 795#
783# CONFIG_PRINTK_TIME is not set 796# CONFIG_PRINTK_TIME is not set
797# CONFIG_MAGIC_SYSRQ is not set
784# CONFIG_DEBUG_KERNEL is not set 798# CONFIG_DEBUG_KERNEL is not set
785CONFIG_LOG_BUF_SHIFT=14 799CONFIG_LOG_BUF_SHIFT=14
786CONFIG_CROSSCOMPILE=y 800CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/jaguar-atx_defconfig b/arch/mips/configs/jaguar-atx_defconfig
index 14fb46886708..316015379dbc 100644
--- a/arch/mips/configs/jaguar-atx_defconfig
+++ b/arch/mips/configs/jaguar-atx_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:29 2005 4# Fri Jan 27 15:40:12 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -158,27 +158,28 @@ CONFIG_SYSVIPC=y
158# CONFIG_BSD_PROCESS_ACCT is not set 158# CONFIG_BSD_PROCESS_ACCT is not set
159CONFIG_SYSCTL=y 159CONFIG_SYSCTL=y
160# CONFIG_AUDIT is not set 160# CONFIG_AUDIT is not set
161CONFIG_HOTPLUG=y
162CONFIG_KOBJECT_UEVENT=y
163CONFIG_IKCONFIG=y 161CONFIG_IKCONFIG=y
164CONFIG_IKCONFIG_PROC=y 162CONFIG_IKCONFIG_PROC=y
165CONFIG_INITRAMFS_SOURCE="" 163CONFIG_INITRAMFS_SOURCE=""
166CONFIG_EMBEDDED=y 164CONFIG_EMBEDDED=y
167CONFIG_KALLSYMS=y 165CONFIG_KALLSYMS=y
168# CONFIG_KALLSYMS_EXTRA_PASS is not set 166# CONFIG_KALLSYMS_EXTRA_PASS is not set
167CONFIG_HOTPLUG=y
169CONFIG_PRINTK=y 168CONFIG_PRINTK=y
170CONFIG_BUG=y 169CONFIG_BUG=y
170CONFIG_ELF_CORE=y
171CONFIG_BASE_FULL=y 171CONFIG_BASE_FULL=y
172CONFIG_FUTEX=y 172CONFIG_FUTEX=y
173CONFIG_EPOLL=y 173CONFIG_EPOLL=y
174# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
175CONFIG_SHMEM=y 174CONFIG_SHMEM=y
176CONFIG_CC_ALIGN_FUNCTIONS=0 175CONFIG_CC_ALIGN_FUNCTIONS=0
177CONFIG_CC_ALIGN_LABELS=0 176CONFIG_CC_ALIGN_LABELS=0
178CONFIG_CC_ALIGN_LOOPS=0 177CONFIG_CC_ALIGN_LOOPS=0
179CONFIG_CC_ALIGN_JUMPS=0 178CONFIG_CC_ALIGN_JUMPS=0
179CONFIG_SLAB=y
180# CONFIG_TINY_SHMEM is not set 180# CONFIG_TINY_SHMEM is not set
181CONFIG_BASE_SMALL=0 181CONFIG_BASE_SMALL=0
182# CONFIG_SLOB is not set
182 183
183# 184#
184# Loadable module support 185# Loadable module support
@@ -186,6 +187,7 @@ CONFIG_BASE_SMALL=0
186CONFIG_MODULES=y 187CONFIG_MODULES=y
187CONFIG_MODULE_UNLOAD=y 188CONFIG_MODULE_UNLOAD=y
188CONFIG_OBSOLETE_MODPARM=y 189CONFIG_OBSOLETE_MODPARM=y
190# CONFIG_MODVERSIONS is not set
189CONFIG_MODULE_SRCVERSION_ALL=y 191CONFIG_MODULE_SRCVERSION_ALL=y
190CONFIG_KMOD=y 192CONFIG_KMOD=y
191 193
@@ -294,7 +296,6 @@ CONFIG_IEEE80211=m
294# CONFIG_IEEE80211_DEBUG is not set 296# CONFIG_IEEE80211_DEBUG is not set
295CONFIG_IEEE80211_CRYPT_WEP=m 297CONFIG_IEEE80211_CRYPT_WEP=m
296CONFIG_IEEE80211_CRYPT_CCMP=m 298CONFIG_IEEE80211_CRYPT_CCMP=m
297CONFIG_IEEE80211_CRYPT_TKIP=m
298 299
299# 300#
300# Device Drivers 301# Device Drivers
@@ -411,6 +412,7 @@ CONFIG_MII=y
411# CONFIG_SUNGEM is not set 412# CONFIG_SUNGEM is not set
412# CONFIG_CASSINI is not set 413# CONFIG_CASSINI is not set
413# CONFIG_NET_VENDOR_3COM is not set 414# CONFIG_NET_VENDOR_3COM is not set
415# CONFIG_DM9000 is not set
414 416
415# 417#
416# Tulip family network device support 418# Tulip family network device support
@@ -469,8 +471,6 @@ CONFIG_MV643XX_ETH_2=y
469# Wireless LAN (non-hamradio) 471# Wireless LAN (non-hamradio)
470# 472#
471# CONFIG_NET_RADIO is not set 473# CONFIG_NET_RADIO is not set
472# CONFIG_IPW_DEBUG is not set
473CONFIG_IPW2200=m
474 474
475# 475#
476# Wan interfaces 476# Wan interfaces
@@ -515,6 +515,7 @@ CONFIG_IPW2200=m
515CONFIG_SERIAL_8250=y 515CONFIG_SERIAL_8250=y
516CONFIG_SERIAL_8250_CONSOLE=y 516CONFIG_SERIAL_8250_CONSOLE=y
517CONFIG_SERIAL_8250_NR_UARTS=4 517CONFIG_SERIAL_8250_NR_UARTS=4
518CONFIG_SERIAL_8250_RUNTIME_UARTS=4
518# CONFIG_SERIAL_8250_EXTENDED is not set 519# CONFIG_SERIAL_8250_EXTENDED is not set
519 520
520# 521#
@@ -522,7 +523,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
522# 523#
523CONFIG_SERIAL_CORE=y 524CONFIG_SERIAL_CORE=y
524CONFIG_SERIAL_CORE_CONSOLE=y 525CONFIG_SERIAL_CORE_CONSOLE=y
525# CONFIG_SERIAL_JSM is not set
526CONFIG_UNIX98_PTYS=y 526CONFIG_UNIX98_PTYS=y
527CONFIG_LEGACY_PTYS=y 527CONFIG_LEGACY_PTYS=y
528CONFIG_LEGACY_PTY_COUNT=256 528CONFIG_LEGACY_PTY_COUNT=256
@@ -558,6 +558,12 @@ CONFIG_LEGACY_PTY_COUNT=256
558# CONFIG_I2C is not set 558# CONFIG_I2C is not set
559 559
560# 560#
561# SPI support
562#
563# CONFIG_SPI is not set
564# CONFIG_SPI_MASTER is not set
565
566#
561# Dallas's 1-wire bus 567# Dallas's 1-wire bus
562# 568#
563# CONFIG_W1 is not set 569# CONFIG_W1 is not set
@@ -631,7 +637,6 @@ CONFIG_USB_ARCH_HAS_OHCI=y
631# 637#
632# CONFIG_EXT2_FS is not set 638# CONFIG_EXT2_FS is not set
633# CONFIG_EXT3_FS is not set 639# CONFIG_EXT3_FS is not set
634# CONFIG_JBD is not set
635# CONFIG_REISERFS_FS is not set 640# CONFIG_REISERFS_FS is not set
636# CONFIG_JFS_FS is not set 641# CONFIG_JFS_FS is not set
637# CONFIG_FS_POSIX_ACL is not set 642# CONFIG_FS_POSIX_ACL is not set
@@ -710,6 +715,7 @@ CONFIG_MSDOS_PARTITION=y
710# Kernel hacking 715# Kernel hacking
711# 716#
712# CONFIG_PRINTK_TIME is not set 717# CONFIG_PRINTK_TIME is not set
718# CONFIG_MAGIC_SYSRQ is not set
713# CONFIG_DEBUG_KERNEL is not set 719# CONFIG_DEBUG_KERNEL is not set
714CONFIG_LOG_BUF_SHIFT=14 720CONFIG_LOG_BUF_SHIFT=14
715CONFIG_CROSSCOMPILE=y 721CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/jmr3927_defconfig b/arch/mips/configs/jmr3927_defconfig
index a8ded3d74152..53fbef1ac25d 100644
--- a/arch/mips/configs/jmr3927_defconfig
+++ b/arch/mips/configs/jmr3927_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:31 2005 4# Fri Jan 27 15:40:13 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -148,26 +148,28 @@ CONFIG_SYSVIPC=y
148# CONFIG_BSD_PROCESS_ACCT is not set 148# CONFIG_BSD_PROCESS_ACCT is not set
149CONFIG_SYSCTL=y 149CONFIG_SYSCTL=y
150# CONFIG_AUDIT is not set 150# CONFIG_AUDIT is not set
151CONFIG_HOTPLUG=y
152CONFIG_KOBJECT_UEVENT=y
153# CONFIG_IKCONFIG is not set 151# CONFIG_IKCONFIG is not set
154CONFIG_INITRAMFS_SOURCE="" 152CONFIG_INITRAMFS_SOURCE=""
153# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
155CONFIG_EMBEDDED=y 154CONFIG_EMBEDDED=y
156CONFIG_KALLSYMS=y 155CONFIG_KALLSYMS=y
157# CONFIG_KALLSYMS_EXTRA_PASS is not set 156# CONFIG_KALLSYMS_EXTRA_PASS is not set
157CONFIG_HOTPLUG=y
158CONFIG_PRINTK=y 158CONFIG_PRINTK=y
159CONFIG_BUG=y 159CONFIG_BUG=y
160CONFIG_ELF_CORE=y
160CONFIG_BASE_FULL=y 161CONFIG_BASE_FULL=y
161CONFIG_FUTEX=y 162CONFIG_FUTEX=y
162CONFIG_EPOLL=y 163CONFIG_EPOLL=y
163# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
164CONFIG_SHMEM=y 164CONFIG_SHMEM=y
165CONFIG_CC_ALIGN_FUNCTIONS=0 165CONFIG_CC_ALIGN_FUNCTIONS=0
166CONFIG_CC_ALIGN_LABELS=0 166CONFIG_CC_ALIGN_LABELS=0
167CONFIG_CC_ALIGN_LOOPS=0 167CONFIG_CC_ALIGN_LOOPS=0
168CONFIG_CC_ALIGN_JUMPS=0 168CONFIG_CC_ALIGN_JUMPS=0
169CONFIG_SLAB=y
169# CONFIG_TINY_SHMEM is not set 170# CONFIG_TINY_SHMEM is not set
170CONFIG_BASE_SMALL=0 171CONFIG_BASE_SMALL=0
172# CONFIG_SLOB is not set
171 173
172# 174#
173# Loadable module support 175# Loadable module support
@@ -272,6 +274,11 @@ CONFIG_TCP_CONG_BIC=y
272# CONFIG_ATALK is not set 274# CONFIG_ATALK is not set
273# CONFIG_X25 is not set 275# CONFIG_X25 is not set
274# CONFIG_LAPB is not set 276# CONFIG_LAPB is not set
277
278#
279# TIPC Configuration (EXPERIMENTAL)
280#
281# CONFIG_TIPC is not set
275# CONFIG_NET_DIVERT is not set 282# CONFIG_NET_DIVERT is not set
276# CONFIG_ECONET is not set 283# CONFIG_ECONET is not set
277# CONFIG_WAN_ROUTER is not set 284# CONFIG_WAN_ROUTER is not set
@@ -292,7 +299,6 @@ CONFIG_IEEE80211=y
292# CONFIG_IEEE80211_DEBUG is not set 299# CONFIG_IEEE80211_DEBUG is not set
293CONFIG_IEEE80211_CRYPT_WEP=y 300CONFIG_IEEE80211_CRYPT_WEP=y
294CONFIG_IEEE80211_CRYPT_CCMP=y 301CONFIG_IEEE80211_CRYPT_CCMP=y
295CONFIG_IEEE80211_CRYPT_TKIP=y
296 302
297# 303#
298# Device Drivers 304# Device Drivers
@@ -411,6 +417,7 @@ CONFIG_NET_ETHERNET=y
411# CONFIG_SUNGEM is not set 417# CONFIG_SUNGEM is not set
412# CONFIG_CASSINI is not set 418# CONFIG_CASSINI is not set
413# CONFIG_NET_VENDOR_3COM is not set 419# CONFIG_NET_VENDOR_3COM is not set
420# CONFIG_DM9000 is not set
414 421
415# 422#
416# Tulip family network device support 423# Tulip family network device support
@@ -431,6 +438,7 @@ CONFIG_NET_ETHERNET=y
431# CONFIG_R8169 is not set 438# CONFIG_R8169 is not set
432# CONFIG_SIS190 is not set 439# CONFIG_SIS190 is not set
433# CONFIG_SKGE is not set 440# CONFIG_SKGE is not set
441# CONFIG_SKY2 is not set
434# CONFIG_SK98LIN is not set 442# CONFIG_SK98LIN is not set
435# CONFIG_TIGON3 is not set 443# CONFIG_TIGON3 is not set
436# CONFIG_BNX2 is not set 444# CONFIG_BNX2 is not set
@@ -451,8 +459,6 @@ CONFIG_NET_ETHERNET=y
451# Wireless LAN (non-hamradio) 459# Wireless LAN (non-hamradio)
452# 460#
453# CONFIG_NET_RADIO is not set 461# CONFIG_NET_RADIO is not set
454# CONFIG_IPW_DEBUG is not set
455CONFIG_IPW2200=y
456 462
457# 463#
458# Wan interfaces 464# Wan interfaces
@@ -529,6 +535,7 @@ CONFIG_SERIAL_NONSTANDARD=y
529# CONFIG_MOXA_SMARTIO is not set 535# CONFIG_MOXA_SMARTIO is not set
530# CONFIG_ISI is not set 536# CONFIG_ISI is not set
531# CONFIG_SYNCLINKMP is not set 537# CONFIG_SYNCLINKMP is not set
538# CONFIG_SYNCLINK_GT is not set
532# CONFIG_N_HDLC is not set 539# CONFIG_N_HDLC is not set
533# CONFIG_RISCOM8 is not set 540# CONFIG_RISCOM8 is not set
534# CONFIG_SPECIALIX is not set 541# CONFIG_SPECIALIX is not set
@@ -545,7 +552,6 @@ CONFIG_SERIAL_NONSTANDARD=y
545# Non-8250 serial port support 552# Non-8250 serial port support
546# 553#
547CONFIG_HAS_TXX9_SERIAL=y 554CONFIG_HAS_TXX9_SERIAL=y
548# CONFIG_SERIAL_JSM is not set
549# CONFIG_UNIX98_PTYS is not set 555# CONFIG_UNIX98_PTYS is not set
550CONFIG_LEGACY_PTYS=y 556CONFIG_LEGACY_PTYS=y
551CONFIG_LEGACY_PTY_COUNT=256 557CONFIG_LEGACY_PTY_COUNT=256
@@ -583,6 +589,12 @@ CONFIG_LEGACY_PTY_COUNT=256
583# CONFIG_I2C is not set 589# CONFIG_I2C is not set
584 590
585# 591#
592# SPI support
593#
594# CONFIG_SPI is not set
595# CONFIG_SPI_MASTER is not set
596
597#
586# Dallas's 1-wire bus 598# Dallas's 1-wire bus
587# 599#
588# CONFIG_W1 is not set 600# CONFIG_W1 is not set
@@ -641,7 +653,6 @@ CONFIG_FB=y
641# CONFIG_FB_3DFX is not set 653# CONFIG_FB_3DFX is not set
642# CONFIG_FB_VOODOO1 is not set 654# CONFIG_FB_VOODOO1 is not set
643# CONFIG_FB_SMIVGX is not set 655# CONFIG_FB_SMIVGX is not set
644# CONFIG_FB_CYBLA is not set
645# CONFIG_FB_TRIDENT is not set 656# CONFIG_FB_TRIDENT is not set
646# CONFIG_FB_VIRTUAL is not set 657# CONFIG_FB_VIRTUAL is not set
647 658
@@ -698,11 +709,11 @@ CONFIG_USB_ARCH_HAS_OHCI=y
698# 709#
699# CONFIG_EXT2_FS is not set 710# CONFIG_EXT2_FS is not set
700# CONFIG_EXT3_FS is not set 711# CONFIG_EXT3_FS is not set
701# CONFIG_JBD is not set
702# CONFIG_REISERFS_FS is not set 712# CONFIG_REISERFS_FS is not set
703# CONFIG_JFS_FS is not set 713# CONFIG_JFS_FS is not set
704# CONFIG_FS_POSIX_ACL is not set 714# CONFIG_FS_POSIX_ACL is not set
705# CONFIG_XFS_FS is not set 715# CONFIG_XFS_FS is not set
716# CONFIG_OCFS2_FS is not set
706# CONFIG_MINIX_FS is not set 717# CONFIG_MINIX_FS is not set
707# CONFIG_ROMFS_FS is not set 718# CONFIG_ROMFS_FS is not set
708CONFIG_INOTIFY=y 719CONFIG_INOTIFY=y
@@ -735,6 +746,7 @@ CONFIG_SYSFS=y
735# CONFIG_HUGETLB_PAGE is not set 746# CONFIG_HUGETLB_PAGE is not set
736CONFIG_RAMFS=y 747CONFIG_RAMFS=y
737CONFIG_RELAYFS_FS=y 748CONFIG_RELAYFS_FS=y
749# CONFIG_CONFIGFS_FS is not set
738 750
739# 751#
740# Miscellaneous filesystems 752# Miscellaneous filesystems
@@ -794,6 +806,7 @@ CONFIG_MSDOS_PARTITION=y
794# Kernel hacking 806# Kernel hacking
795# 807#
796# CONFIG_PRINTK_TIME is not set 808# CONFIG_PRINTK_TIME is not set
809# CONFIG_MAGIC_SYSRQ is not set
797# CONFIG_DEBUG_KERNEL is not set 810# CONFIG_DEBUG_KERNEL is not set
798CONFIG_LOG_BUF_SHIFT=14 811CONFIG_LOG_BUF_SHIFT=14
799CONFIG_CROSSCOMPILE=y 812CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/lasat200_defconfig b/arch/mips/configs/lasat200_defconfig
index 6c5df76d48d9..ef0fa9fc79d6 100644
--- a/arch/mips/configs/lasat200_defconfig
+++ b/arch/mips/configs/lasat200_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:33 2005 4# Fri Jan 27 15:40:14 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -156,26 +156,29 @@ CONFIG_SYSVIPC=y
156# CONFIG_BSD_PROCESS_ACCT is not set 156# CONFIG_BSD_PROCESS_ACCT is not set
157CONFIG_SYSCTL=y 157CONFIG_SYSCTL=y
158# CONFIG_AUDIT is not set 158# CONFIG_AUDIT is not set
159CONFIG_HOTPLUG=y
160CONFIG_KOBJECT_UEVENT=y
161# CONFIG_IKCONFIG is not set 159# CONFIG_IKCONFIG is not set
162CONFIG_INITRAMFS_SOURCE="" 160CONFIG_INITRAMFS_SOURCE=""
161# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
163CONFIG_EMBEDDED=y 162CONFIG_EMBEDDED=y
164CONFIG_KALLSYMS=y 163CONFIG_KALLSYMS=y
165# CONFIG_KALLSYMS_EXTRA_PASS is not set 164# CONFIG_KALLSYMS_EXTRA_PASS is not set
165CONFIG_HOTPLUG=y
166CONFIG_PRINTK=y 166CONFIG_PRINTK=y
167CONFIG_BUG=y 167CONFIG_BUG=y
168CONFIG_ELF_CORE=y
168CONFIG_BASE_FULL=y 169CONFIG_BASE_FULL=y
169CONFIG_FUTEX=y 170CONFIG_FUTEX=y
170CONFIG_EPOLL=y 171CONFIG_EPOLL=y
171# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
172CONFIG_SHMEM=y 172CONFIG_SHMEM=y
173CONFIG_CC_ALIGN_FUNCTIONS=0 173CONFIG_CC_ALIGN_FUNCTIONS=0
174CONFIG_CC_ALIGN_LABELS=0 174CONFIG_CC_ALIGN_LABELS=0
175CONFIG_CC_ALIGN_LOOPS=0 175CONFIG_CC_ALIGN_LOOPS=0
176CONFIG_CC_ALIGN_JUMPS=0 176CONFIG_CC_ALIGN_JUMPS=0
177CONFIG_SLAB=y
177# CONFIG_TINY_SHMEM is not set 178# CONFIG_TINY_SHMEM is not set
178CONFIG_BASE_SMALL=0 179CONFIG_BASE_SMALL=0
180# CONFIG_SLOB is not set
181CONFIG_OBSOLETE_INTERMODULE=y
179 182
180# 183#
181# Loadable module support 184# Loadable module support
@@ -282,6 +285,11 @@ CONFIG_TCP_CONG_BIC=y
282# CONFIG_ATALK is not set 285# CONFIG_ATALK is not set
283# CONFIG_X25 is not set 286# CONFIG_X25 is not set
284# CONFIG_LAPB is not set 287# CONFIG_LAPB is not set
288
289#
290# TIPC Configuration (EXPERIMENTAL)
291#
292# CONFIG_TIPC is not set
285# CONFIG_NET_DIVERT is not set 293# CONFIG_NET_DIVERT is not set
286# CONFIG_ECONET is not set 294# CONFIG_ECONET is not set
287# CONFIG_WAN_ROUTER is not set 295# CONFIG_WAN_ROUTER is not set
@@ -302,7 +310,6 @@ CONFIG_IEEE80211=m
302# CONFIG_IEEE80211_DEBUG is not set 310# CONFIG_IEEE80211_DEBUG is not set
303CONFIG_IEEE80211_CRYPT_WEP=m 311CONFIG_IEEE80211_CRYPT_WEP=m
304CONFIG_IEEE80211_CRYPT_CCMP=m 312CONFIG_IEEE80211_CRYPT_CCMP=m
305CONFIG_IEEE80211_CRYPT_TKIP=m
306 313
307# 314#
308# Device Drivers 315# Device Drivers
@@ -365,6 +372,7 @@ CONFIG_MTD_CFI_UTIL=y
365# CONFIG_MTD_RAM is not set 372# CONFIG_MTD_RAM is not set
366# CONFIG_MTD_ROM is not set 373# CONFIG_MTD_ROM is not set
367# CONFIG_MTD_ABSENT is not set 374# CONFIG_MTD_ABSENT is not set
375# CONFIG_MTD_OBSOLETE_CHIPS is not set
368 376
369# 377#
370# Mapping drivers for chip access 378# Mapping drivers for chip access
@@ -548,6 +556,7 @@ CONFIG_NET_ETHERNET=y
548# CONFIG_SUNGEM is not set 556# CONFIG_SUNGEM is not set
549# CONFIG_CASSINI is not set 557# CONFIG_CASSINI is not set
550# CONFIG_NET_VENDOR_3COM is not set 558# CONFIG_NET_VENDOR_3COM is not set
559# CONFIG_DM9000 is not set
551 560
552# 561#
553# Tulip family network device support 562# Tulip family network device support
@@ -568,6 +577,7 @@ CONFIG_NET_ETHERNET=y
568# CONFIG_R8169 is not set 577# CONFIG_R8169 is not set
569# CONFIG_SIS190 is not set 578# CONFIG_SIS190 is not set
570# CONFIG_SKGE is not set 579# CONFIG_SKGE is not set
580# CONFIG_SKY2 is not set
571# CONFIG_SK98LIN is not set 581# CONFIG_SK98LIN is not set
572# CONFIG_TIGON3 is not set 582# CONFIG_TIGON3 is not set
573# CONFIG_BNX2 is not set 583# CONFIG_BNX2 is not set
@@ -588,8 +598,6 @@ CONFIG_NET_ETHERNET=y
588# Wireless LAN (non-hamradio) 598# Wireless LAN (non-hamradio)
589# 599#
590# CONFIG_NET_RADIO is not set 600# CONFIG_NET_RADIO is not set
591# CONFIG_IPW_DEBUG is not set
592CONFIG_IPW2200=m
593 601
594# 602#
595# Wan interfaces 603# Wan interfaces
@@ -665,6 +673,7 @@ CONFIG_HW_CONSOLE=y
665CONFIG_SERIAL_8250=y 673CONFIG_SERIAL_8250=y
666CONFIG_SERIAL_8250_CONSOLE=y 674CONFIG_SERIAL_8250_CONSOLE=y
667CONFIG_SERIAL_8250_NR_UARTS=4 675CONFIG_SERIAL_8250_NR_UARTS=4
676CONFIG_SERIAL_8250_RUNTIME_UARTS=4
668# CONFIG_SERIAL_8250_EXTENDED is not set 677# CONFIG_SERIAL_8250_EXTENDED is not set
669 678
670# 679#
@@ -672,7 +681,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
672# 681#
673CONFIG_SERIAL_CORE=y 682CONFIG_SERIAL_CORE=y
674CONFIG_SERIAL_CORE_CONSOLE=y 683CONFIG_SERIAL_CORE_CONSOLE=y
675# CONFIG_SERIAL_JSM is not set
676CONFIG_UNIX98_PTYS=y 684CONFIG_UNIX98_PTYS=y
677CONFIG_LEGACY_PTYS=y 685CONFIG_LEGACY_PTYS=y
678CONFIG_LEGACY_PTY_COUNT=256 686CONFIG_LEGACY_PTY_COUNT=256
@@ -710,6 +718,12 @@ CONFIG_LEGACY_PTY_COUNT=256
710# CONFIG_I2C is not set 718# CONFIG_I2C is not set
711 719
712# 720#
721# SPI support
722#
723# CONFIG_SPI is not set
724# CONFIG_SPI_MASTER is not set
725
726#
713# Dallas's 1-wire bus 727# Dallas's 1-wire bus
714# 728#
715# CONFIG_W1 is not set 729# CONFIG_W1 is not set
@@ -801,6 +815,7 @@ CONFIG_FS_MBCACHE=y
801# CONFIG_JFS_FS is not set 815# CONFIG_JFS_FS is not set
802# CONFIG_FS_POSIX_ACL is not set 816# CONFIG_FS_POSIX_ACL is not set
803# CONFIG_XFS_FS is not set 817# CONFIG_XFS_FS is not set
818# CONFIG_OCFS2_FS is not set
804# CONFIG_MINIX_FS is not set 819# CONFIG_MINIX_FS is not set
805# CONFIG_ROMFS_FS is not set 820# CONFIG_ROMFS_FS is not set
806CONFIG_INOTIFY=y 821CONFIG_INOTIFY=y
@@ -833,6 +848,7 @@ CONFIG_SYSFS=y
833# CONFIG_HUGETLB_PAGE is not set 848# CONFIG_HUGETLB_PAGE is not set
834CONFIG_RAMFS=y 849CONFIG_RAMFS=y
835CONFIG_RELAYFS_FS=m 850CONFIG_RELAYFS_FS=m
851# CONFIG_CONFIGFS_FS is not set
836 852
837# 853#
838# Miscellaneous filesystems 854# Miscellaneous filesystems
@@ -895,6 +911,7 @@ CONFIG_MSDOS_PARTITION=y
895# Kernel hacking 911# Kernel hacking
896# 912#
897# CONFIG_PRINTK_TIME is not set 913# CONFIG_PRINTK_TIME is not set
914# CONFIG_MAGIC_SYSRQ is not set
898# CONFIG_DEBUG_KERNEL is not set 915# CONFIG_DEBUG_KERNEL is not set
899CONFIG_LOG_BUF_SHIFT=14 916CONFIG_LOG_BUF_SHIFT=14
900CONFIG_CROSSCOMPILE=y 917CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/malta_defconfig b/arch/mips/configs/malta_defconfig
index da0677a03c1d..367d279efdd9 100644
--- a/arch/mips/configs/malta_defconfig
+++ b/arch/mips/configs/malta_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc5 3# Linux kernel version: 2.6.16-rc1
4# Fri Dec 23 02:21:03 2005 4# Fri Jan 27 15:40:15 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -170,26 +170,28 @@ CONFIG_SYSVIPC=y
170# CONFIG_BSD_PROCESS_ACCT is not set 170# CONFIG_BSD_PROCESS_ACCT is not set
171CONFIG_SYSCTL=y 171CONFIG_SYSCTL=y
172# CONFIG_AUDIT is not set 172# CONFIG_AUDIT is not set
173CONFIG_HOTPLUG=y
174CONFIG_KOBJECT_UEVENT=y
175# CONFIG_IKCONFIG is not set 173# CONFIG_IKCONFIG is not set
176CONFIG_INITRAMFS_SOURCE="" 174CONFIG_INITRAMFS_SOURCE=""
175# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
177CONFIG_EMBEDDED=y 176CONFIG_EMBEDDED=y
178CONFIG_KALLSYMS=y 177CONFIG_KALLSYMS=y
179# CONFIG_KALLSYMS_EXTRA_PASS is not set 178# CONFIG_KALLSYMS_EXTRA_PASS is not set
179CONFIG_HOTPLUG=y
180CONFIG_PRINTK=y 180CONFIG_PRINTK=y
181CONFIG_BUG=y 181CONFIG_BUG=y
182CONFIG_ELF_CORE=y
182CONFIG_BASE_FULL=y 183CONFIG_BASE_FULL=y
183CONFIG_FUTEX=y 184CONFIG_FUTEX=y
184CONFIG_EPOLL=y 185CONFIG_EPOLL=y
185# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
186CONFIG_SHMEM=y 186CONFIG_SHMEM=y
187CONFIG_CC_ALIGN_FUNCTIONS=0 187CONFIG_CC_ALIGN_FUNCTIONS=0
188CONFIG_CC_ALIGN_LABELS=0 188CONFIG_CC_ALIGN_LABELS=0
189CONFIG_CC_ALIGN_LOOPS=0 189CONFIG_CC_ALIGN_LOOPS=0
190CONFIG_CC_ALIGN_JUMPS=0 190CONFIG_CC_ALIGN_JUMPS=0
191CONFIG_SLAB=y
191# CONFIG_TINY_SHMEM is not set 192# CONFIG_TINY_SHMEM is not set
192CONFIG_BASE_SMALL=0 193CONFIG_BASE_SMALL=0
194# CONFIG_SLOB is not set
193 195
194# 196#
195# Loadable module support 197# Loadable module support
@@ -341,6 +343,29 @@ CONFIG_BRIDGE_NETFILTER=y
341CONFIG_NETFILTER_NETLINK=m 343CONFIG_NETFILTER_NETLINK=m
342CONFIG_NETFILTER_NETLINK_QUEUE=m 344CONFIG_NETFILTER_NETLINK_QUEUE=m
343CONFIG_NETFILTER_NETLINK_LOG=m 345CONFIG_NETFILTER_NETLINK_LOG=m
346CONFIG_NETFILTER_XTABLES=m
347CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
348CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
349CONFIG_NETFILTER_XT_TARGET_MARK=m
350CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
351CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
352CONFIG_NETFILTER_XT_MATCH_COMMENT=m
353CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
354CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
355CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
356CONFIG_NETFILTER_XT_MATCH_DCCP=m
357CONFIG_NETFILTER_XT_MATCH_HELPER=m
358CONFIG_NETFILTER_XT_MATCH_LENGTH=m
359CONFIG_NETFILTER_XT_MATCH_LIMIT=m
360CONFIG_NETFILTER_XT_MATCH_MAC=m
361CONFIG_NETFILTER_XT_MATCH_MARK=m
362# CONFIG_NETFILTER_XT_MATCH_PHYSDEV is not set
363CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
364CONFIG_NETFILTER_XT_MATCH_REALM=m
365CONFIG_NETFILTER_XT_MATCH_SCTP=m
366CONFIG_NETFILTER_XT_MATCH_STATE=m
367CONFIG_NETFILTER_XT_MATCH_STRING=m
368CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
344 369
345# 370#
346# IP: Netfilter Configuration 371# IP: Netfilter Configuration
@@ -359,40 +384,23 @@ CONFIG_IP_NF_AMANDA=m
359CONFIG_IP_NF_PPTP=m 384CONFIG_IP_NF_PPTP=m
360CONFIG_IP_NF_QUEUE=m 385CONFIG_IP_NF_QUEUE=m
361CONFIG_IP_NF_IPTABLES=m 386CONFIG_IP_NF_IPTABLES=m
362CONFIG_IP_NF_MATCH_LIMIT=m
363CONFIG_IP_NF_MATCH_IPRANGE=m 387CONFIG_IP_NF_MATCH_IPRANGE=m
364CONFIG_IP_NF_MATCH_MAC=m
365CONFIG_IP_NF_MATCH_PKTTYPE=m
366CONFIG_IP_NF_MATCH_MARK=m
367CONFIG_IP_NF_MATCH_MULTIPORT=m 388CONFIG_IP_NF_MATCH_MULTIPORT=m
368CONFIG_IP_NF_MATCH_TOS=m 389CONFIG_IP_NF_MATCH_TOS=m
369CONFIG_IP_NF_MATCH_RECENT=m 390CONFIG_IP_NF_MATCH_RECENT=m
370CONFIG_IP_NF_MATCH_ECN=m 391CONFIG_IP_NF_MATCH_ECN=m
371CONFIG_IP_NF_MATCH_DSCP=m 392CONFIG_IP_NF_MATCH_DSCP=m
372CONFIG_IP_NF_MATCH_AH_ESP=m 393CONFIG_IP_NF_MATCH_AH_ESP=m
373CONFIG_IP_NF_MATCH_LENGTH=m
374CONFIG_IP_NF_MATCH_TTL=m 394CONFIG_IP_NF_MATCH_TTL=m
375CONFIG_IP_NF_MATCH_TCPMSS=m
376CONFIG_IP_NF_MATCH_HELPER=m
377CONFIG_IP_NF_MATCH_STATE=m
378CONFIG_IP_NF_MATCH_CONNTRACK=m
379CONFIG_IP_NF_MATCH_OWNER=m 395CONFIG_IP_NF_MATCH_OWNER=m
380CONFIG_IP_NF_MATCH_PHYSDEV=m
381CONFIG_IP_NF_MATCH_ADDRTYPE=m 396CONFIG_IP_NF_MATCH_ADDRTYPE=m
382CONFIG_IP_NF_MATCH_REALM=m
383CONFIG_IP_NF_MATCH_SCTP=m
384CONFIG_IP_NF_MATCH_DCCP=m
385CONFIG_IP_NF_MATCH_COMMENT=m
386CONFIG_IP_NF_MATCH_CONNMARK=m
387CONFIG_IP_NF_MATCH_CONNBYTES=m
388CONFIG_IP_NF_MATCH_HASHLIMIT=m 397CONFIG_IP_NF_MATCH_HASHLIMIT=m
389CONFIG_IP_NF_MATCH_STRING=m 398CONFIG_IP_NF_MATCH_POLICY=m
390CONFIG_IP_NF_FILTER=m 399CONFIG_IP_NF_FILTER=m
391CONFIG_IP_NF_TARGET_REJECT=m 400CONFIG_IP_NF_TARGET_REJECT=m
392CONFIG_IP_NF_TARGET_LOG=m 401CONFIG_IP_NF_TARGET_LOG=m
393CONFIG_IP_NF_TARGET_ULOG=m 402CONFIG_IP_NF_TARGET_ULOG=m
394CONFIG_IP_NF_TARGET_TCPMSS=m 403CONFIG_IP_NF_TARGET_TCPMSS=m
395CONFIG_IP_NF_TARGET_NFQUEUE=m
396CONFIG_IP_NF_NAT=m 404CONFIG_IP_NF_NAT=m
397CONFIG_IP_NF_NAT_NEEDED=y 405CONFIG_IP_NF_NAT_NEEDED=y
398CONFIG_IP_NF_TARGET_MASQUERADE=m 406CONFIG_IP_NF_TARGET_MASQUERADE=m
@@ -409,13 +417,9 @@ CONFIG_IP_NF_MANGLE=m
409CONFIG_IP_NF_TARGET_TOS=m 417CONFIG_IP_NF_TARGET_TOS=m
410CONFIG_IP_NF_TARGET_ECN=m 418CONFIG_IP_NF_TARGET_ECN=m
411CONFIG_IP_NF_TARGET_DSCP=m 419CONFIG_IP_NF_TARGET_DSCP=m
412CONFIG_IP_NF_TARGET_MARK=m
413CONFIG_IP_NF_TARGET_CLASSIFY=m
414CONFIG_IP_NF_TARGET_TTL=m 420CONFIG_IP_NF_TARGET_TTL=m
415CONFIG_IP_NF_TARGET_CONNMARK=m
416CONFIG_IP_NF_TARGET_CLUSTERIP=m 421CONFIG_IP_NF_TARGET_CLUSTERIP=m
417CONFIG_IP_NF_RAW=m 422CONFIG_IP_NF_RAW=m
418CONFIG_IP_NF_TARGET_NOTRACK=m
419CONFIG_IP_NF_ARPTABLES=m 423CONFIG_IP_NF_ARPTABLES=m
420CONFIG_IP_NF_ARPFILTER=m 424CONFIG_IP_NF_ARPFILTER=m
421CONFIG_IP_NF_ARP_MANGLE=m 425CONFIG_IP_NF_ARP_MANGLE=m
@@ -425,26 +429,20 @@ CONFIG_IP_NF_ARP_MANGLE=m
425# 429#
426CONFIG_IP6_NF_QUEUE=m 430CONFIG_IP6_NF_QUEUE=m
427CONFIG_IP6_NF_IPTABLES=m 431CONFIG_IP6_NF_IPTABLES=m
428CONFIG_IP6_NF_MATCH_LIMIT=m
429CONFIG_IP6_NF_MATCH_MAC=m
430CONFIG_IP6_NF_MATCH_RT=m 432CONFIG_IP6_NF_MATCH_RT=m
431CONFIG_IP6_NF_MATCH_OPTS=m 433CONFIG_IP6_NF_MATCH_OPTS=m
432CONFIG_IP6_NF_MATCH_FRAG=m 434CONFIG_IP6_NF_MATCH_FRAG=m
433CONFIG_IP6_NF_MATCH_HL=m 435CONFIG_IP6_NF_MATCH_HL=m
434CONFIG_IP6_NF_MATCH_MULTIPORT=m 436CONFIG_IP6_NF_MATCH_MULTIPORT=m
435CONFIG_IP6_NF_MATCH_OWNER=m 437CONFIG_IP6_NF_MATCH_OWNER=m
436CONFIG_IP6_NF_MATCH_MARK=m
437CONFIG_IP6_NF_MATCH_IPV6HEADER=m 438CONFIG_IP6_NF_MATCH_IPV6HEADER=m
438CONFIG_IP6_NF_MATCH_AHESP=m 439CONFIG_IP6_NF_MATCH_AHESP=m
439CONFIG_IP6_NF_MATCH_LENGTH=m
440CONFIG_IP6_NF_MATCH_EUI64=m 440CONFIG_IP6_NF_MATCH_EUI64=m
441CONFIG_IP6_NF_MATCH_PHYSDEV=m 441CONFIG_IP6_NF_MATCH_POLICY=m
442CONFIG_IP6_NF_FILTER=m 442CONFIG_IP6_NF_FILTER=m
443CONFIG_IP6_NF_TARGET_LOG=m 443CONFIG_IP6_NF_TARGET_LOG=m
444CONFIG_IP6_NF_TARGET_REJECT=m 444CONFIG_IP6_NF_TARGET_REJECT=m
445CONFIG_IP6_NF_TARGET_NFQUEUE=m
446CONFIG_IP6_NF_MANGLE=m 445CONFIG_IP6_NF_MANGLE=m
447CONFIG_IP6_NF_TARGET_MARK=m
448CONFIG_IP6_NF_TARGET_HL=m 446CONFIG_IP6_NF_TARGET_HL=m
449CONFIG_IP6_NF_RAW=m 447CONFIG_IP6_NF_RAW=m
450 448
@@ -500,6 +498,11 @@ CONFIG_IPDDP_ENCAP=y
500CONFIG_IPDDP_DECAP=y 498CONFIG_IPDDP_DECAP=y
501# CONFIG_X25 is not set 499# CONFIG_X25 is not set
502# CONFIG_LAPB is not set 500# CONFIG_LAPB is not set
501
502#
503# TIPC Configuration (EXPERIMENTAL)
504#
505# CONFIG_TIPC is not set
503CONFIG_NET_DIVERT=y 506CONFIG_NET_DIVERT=y
504# CONFIG_ECONET is not set 507# CONFIG_ECONET is not set
505# CONFIG_WAN_ROUTER is not set 508# CONFIG_WAN_ROUTER is not set
@@ -559,7 +562,6 @@ CONFIG_IEEE80211=m
559# CONFIG_IEEE80211_DEBUG is not set 562# CONFIG_IEEE80211_DEBUG is not set
560CONFIG_IEEE80211_CRYPT_WEP=m 563CONFIG_IEEE80211_CRYPT_WEP=m
561CONFIG_IEEE80211_CRYPT_CCMP=m 564CONFIG_IEEE80211_CRYPT_CCMP=m
562CONFIG_IEEE80211_CRYPT_TKIP=m
563 565
564# 566#
565# Device Drivers 567# Device Drivers
@@ -734,13 +736,7 @@ CONFIG_AIC7XXX_REG_PRETTY_PRINT=y
734# CONFIG_SCSI_IPR is not set 736# CONFIG_SCSI_IPR is not set
735# CONFIG_SCSI_QLOGIC_FC is not set 737# CONFIG_SCSI_QLOGIC_FC is not set
736# CONFIG_SCSI_QLOGIC_1280 is not set 738# CONFIG_SCSI_QLOGIC_1280 is not set
737CONFIG_SCSI_QLA2XXX=m 739# CONFIG_SCSI_QLA_FC is not set
738# CONFIG_SCSI_QLA21XX is not set
739# CONFIG_SCSI_QLA22XX is not set
740# CONFIG_SCSI_QLA2300 is not set
741# CONFIG_SCSI_QLA2322 is not set
742# CONFIG_SCSI_QLA6312 is not set
743# CONFIG_SCSI_QLA24XX is not set
744# CONFIG_SCSI_LPFC is not set 740# CONFIG_SCSI_LPFC is not set
745# CONFIG_SCSI_DC395x is not set 741# CONFIG_SCSI_DC395x is not set
746# CONFIG_SCSI_DC390T is not set 742# CONFIG_SCSI_DC390T is not set
@@ -823,6 +819,7 @@ CONFIG_MII=y
823# CONFIG_SUNGEM is not set 819# CONFIG_SUNGEM is not set
824# CONFIG_CASSINI is not set 820# CONFIG_CASSINI is not set
825# CONFIG_NET_VENDOR_3COM is not set 821# CONFIG_NET_VENDOR_3COM is not set
822# CONFIG_DM9000 is not set
826 823
827# 824#
828# Tulip family network device support 825# Tulip family network device support
@@ -862,6 +859,7 @@ CONFIG_PCNET32=y
862# CONFIG_R8169 is not set 859# CONFIG_R8169 is not set
863# CONFIG_SIS190 is not set 860# CONFIG_SIS190 is not set
864# CONFIG_SKGE is not set 861# CONFIG_SKGE is not set
862# CONFIG_SKY2 is not set
865# CONFIG_SK98LIN is not set 863# CONFIG_SK98LIN is not set
866# CONFIG_VIA_VELOCITY is not set 864# CONFIG_VIA_VELOCITY is not set
867# CONFIG_TIGON3 is not set 865# CONFIG_TIGON3 is not set
@@ -883,8 +881,6 @@ CONFIG_PCNET32=y
883# Wireless LAN (non-hamradio) 881# Wireless LAN (non-hamradio)
884# 882#
885# CONFIG_NET_RADIO is not set 883# CONFIG_NET_RADIO is not set
886# CONFIG_IPW_DEBUG is not set
887CONFIG_IPW2200=m
888 884
889# 885#
890# Wan interfaces 886# Wan interfaces
@@ -961,6 +957,7 @@ CONFIG_HW_CONSOLE=y
961CONFIG_SERIAL_8250=y 957CONFIG_SERIAL_8250=y
962CONFIG_SERIAL_8250_CONSOLE=y 958CONFIG_SERIAL_8250_CONSOLE=y
963CONFIG_SERIAL_8250_NR_UARTS=4 959CONFIG_SERIAL_8250_NR_UARTS=4
960CONFIG_SERIAL_8250_RUNTIME_UARTS=4
964# CONFIG_SERIAL_8250_EXTENDED is not set 961# CONFIG_SERIAL_8250_EXTENDED is not set
965 962
966# 963#
@@ -968,7 +965,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
968# 965#
969CONFIG_SERIAL_CORE=y 966CONFIG_SERIAL_CORE=y
970CONFIG_SERIAL_CORE_CONSOLE=y 967CONFIG_SERIAL_CORE_CONSOLE=y
971# CONFIG_SERIAL_JSM is not set
972CONFIG_UNIX98_PTYS=y 968CONFIG_UNIX98_PTYS=y
973CONFIG_LEGACY_PTYS=y 969CONFIG_LEGACY_PTYS=y
974CONFIG_LEGACY_PTY_COUNT=256 970CONFIG_LEGACY_PTY_COUNT=256
@@ -1005,6 +1001,12 @@ CONFIG_RTC=y
1005# CONFIG_I2C is not set 1001# CONFIG_I2C is not set
1006 1002
1007# 1003#
1004# SPI support
1005#
1006# CONFIG_SPI is not set
1007# CONFIG_SPI_MASTER is not set
1008
1009#
1008# Dallas's 1-wire bus 1010# Dallas's 1-wire bus
1009# 1011#
1010# CONFIG_W1 is not set 1012# CONFIG_W1 is not set
@@ -1110,6 +1112,7 @@ CONFIG_XFS_QUOTA=y
1110CONFIG_XFS_SECURITY=y 1112CONFIG_XFS_SECURITY=y
1111CONFIG_XFS_POSIX_ACL=y 1113CONFIG_XFS_POSIX_ACL=y
1112# CONFIG_XFS_RT is not set 1114# CONFIG_XFS_RT is not set
1115# CONFIG_OCFS2_FS is not set
1113CONFIG_MINIX_FS=m 1116CONFIG_MINIX_FS=m
1114CONFIG_ROMFS_FS=m 1117CONFIG_ROMFS_FS=m
1115CONFIG_INOTIFY=y 1118CONFIG_INOTIFY=y
@@ -1152,6 +1155,7 @@ CONFIG_SYSFS=y
1152# CONFIG_HUGETLB_PAGE is not set 1155# CONFIG_HUGETLB_PAGE is not set
1153CONFIG_RAMFS=y 1156CONFIG_RAMFS=y
1154CONFIG_RELAYFS_FS=m 1157CONFIG_RELAYFS_FS=m
1158# CONFIG_CONFIGFS_FS is not set
1155 1159
1156# 1160#
1157# Miscellaneous filesystems 1161# Miscellaneous filesystems
@@ -1259,6 +1263,7 @@ CONFIG_NLS_UTF8=m
1259# Kernel hacking 1263# Kernel hacking
1260# 1264#
1261# CONFIG_PRINTK_TIME is not set 1265# CONFIG_PRINTK_TIME is not set
1266# CONFIG_MAGIC_SYSRQ is not set
1262# CONFIG_DEBUG_KERNEL is not set 1267# CONFIG_DEBUG_KERNEL is not set
1263CONFIG_LOG_BUF_SHIFT=14 1268CONFIG_LOG_BUF_SHIFT=14
1264CONFIG_CROSSCOMPILE=y 1269CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/mipssim_defconfig b/arch/mips/configs/mipssim_defconfig
index ac39ab7feeb7..fe78961762b8 100644
--- a/arch/mips/configs/mipssim_defconfig
+++ b/arch/mips/configs/mipssim_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:37 2005 4# Fri Jan 27 15:40:16 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -156,27 +156,29 @@ CONFIG_SYSVIPC=y
156# CONFIG_BSD_PROCESS_ACCT is not set 156# CONFIG_BSD_PROCESS_ACCT is not set
157CONFIG_SYSCTL=y 157CONFIG_SYSCTL=y
158# CONFIG_AUDIT is not set 158# CONFIG_AUDIT is not set
159CONFIG_HOTPLUG=y
160CONFIG_KOBJECT_UEVENT=y
161# CONFIG_IKCONFIG is not set 159# CONFIG_IKCONFIG is not set
162CONFIG_INITRAMFS_SOURCE="" 160CONFIG_INITRAMFS_SOURCE=""
161# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
163CONFIG_EMBEDDED=y 162CONFIG_EMBEDDED=y
164CONFIG_KALLSYMS=y 163CONFIG_KALLSYMS=y
165# CONFIG_KALLSYMS_ALL is not set 164# CONFIG_KALLSYMS_ALL is not set
166# CONFIG_KALLSYMS_EXTRA_PASS is not set 165# CONFIG_KALLSYMS_EXTRA_PASS is not set
166CONFIG_HOTPLUG=y
167CONFIG_PRINTK=y 167CONFIG_PRINTK=y
168CONFIG_BUG=y 168CONFIG_BUG=y
169CONFIG_ELF_CORE=y
169CONFIG_BASE_FULL=y 170CONFIG_BASE_FULL=y
170CONFIG_FUTEX=y 171CONFIG_FUTEX=y
171CONFIG_EPOLL=y 172CONFIG_EPOLL=y
172# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
173CONFIG_SHMEM=y 173CONFIG_SHMEM=y
174CONFIG_CC_ALIGN_FUNCTIONS=0 174CONFIG_CC_ALIGN_FUNCTIONS=0
175CONFIG_CC_ALIGN_LABELS=0 175CONFIG_CC_ALIGN_LABELS=0
176CONFIG_CC_ALIGN_LOOPS=0 176CONFIG_CC_ALIGN_LOOPS=0
177CONFIG_CC_ALIGN_JUMPS=0 177CONFIG_CC_ALIGN_JUMPS=0
178CONFIG_SLAB=y
178# CONFIG_TINY_SHMEM is not set 179# CONFIG_TINY_SHMEM is not set
179CONFIG_BASE_SMALL=0 180CONFIG_BASE_SMALL=0
181# CONFIG_SLOB is not set
180 182
181# 183#
182# Loadable module support 184# Loadable module support
@@ -297,6 +299,11 @@ CONFIG_SCTP_HMAC_MD5=y
297# CONFIG_ATALK is not set 299# CONFIG_ATALK is not set
298# CONFIG_X25 is not set 300# CONFIG_X25 is not set
299# CONFIG_LAPB is not set 301# CONFIG_LAPB is not set
302
303#
304# TIPC Configuration (EXPERIMENTAL)
305#
306# CONFIG_TIPC is not set
300CONFIG_NET_DIVERT=y 307CONFIG_NET_DIVERT=y
301# CONFIG_ECONET is not set 308# CONFIG_ECONET is not set
302# CONFIG_WAN_ROUTER is not set 309# CONFIG_WAN_ROUTER is not set
@@ -525,6 +532,7 @@ CONFIG_SERIO_SERPORT=y
525CONFIG_SERIAL_8250=y 532CONFIG_SERIAL_8250=y
526CONFIG_SERIAL_8250_CONSOLE=y 533CONFIG_SERIAL_8250_CONSOLE=y
527CONFIG_SERIAL_8250_NR_UARTS=1 534CONFIG_SERIAL_8250_NR_UARTS=1
535CONFIG_SERIAL_8250_RUNTIME_UARTS=4
528# CONFIG_SERIAL_8250_EXTENDED is not set 536# CONFIG_SERIAL_8250_EXTENDED is not set
529 537
530# 538#
@@ -567,6 +575,12 @@ CONFIG_LEGACY_PTY_COUNT=256
567# CONFIG_I2C is not set 575# CONFIG_I2C is not set
568 576
569# 577#
578# SPI support
579#
580# CONFIG_SPI is not set
581# CONFIG_SPI_MASTER is not set
582
583#
570# Dallas's 1-wire bus 584# Dallas's 1-wire bus
571# 585#
572# CONFIG_W1 is not set 586# CONFIG_W1 is not set
@@ -640,11 +654,11 @@ CONFIG_EXT2_FS=y
640# CONFIG_EXT2_FS_XATTR is not set 654# CONFIG_EXT2_FS_XATTR is not set
641# CONFIG_EXT2_FS_XIP is not set 655# CONFIG_EXT2_FS_XIP is not set
642# CONFIG_EXT3_FS is not set 656# CONFIG_EXT3_FS is not set
643# CONFIG_JBD is not set
644# CONFIG_REISERFS_FS is not set 657# CONFIG_REISERFS_FS is not set
645# CONFIG_JFS_FS is not set 658# CONFIG_JFS_FS is not set
646# CONFIG_FS_POSIX_ACL is not set 659# CONFIG_FS_POSIX_ACL is not set
647# CONFIG_XFS_FS is not set 660# CONFIG_XFS_FS is not set
661# CONFIG_OCFS2_FS is not set
648# CONFIG_MINIX_FS is not set 662# CONFIG_MINIX_FS is not set
649CONFIG_ROMFS_FS=y 663CONFIG_ROMFS_FS=y
650# CONFIG_INOTIFY is not set 664# CONFIG_INOTIFY is not set
@@ -677,6 +691,7 @@ CONFIG_PROC_FS=y
677# CONFIG_HUGETLB_PAGE is not set 691# CONFIG_HUGETLB_PAGE is not set
678CONFIG_RAMFS=y 692CONFIG_RAMFS=y
679# CONFIG_RELAYFS_FS is not set 693# CONFIG_RELAYFS_FS is not set
694# CONFIG_CONFIGFS_FS is not set
680 695
681# 696#
682# Miscellaneous filesystems 697# Miscellaneous filesystems
@@ -738,17 +753,19 @@ CONFIG_MSDOS_PARTITION=y
738# Kernel hacking 753# Kernel hacking
739# 754#
740# CONFIG_PRINTK_TIME is not set 755# CONFIG_PRINTK_TIME is not set
741CONFIG_DEBUG_KERNEL=y
742# CONFIG_MAGIC_SYSRQ is not set 756# CONFIG_MAGIC_SYSRQ is not set
757CONFIG_DEBUG_KERNEL=y
743CONFIG_LOG_BUF_SHIFT=14 758CONFIG_LOG_BUF_SHIFT=14
744# CONFIG_DETECT_SOFTLOCKUP is not set 759# CONFIG_DETECT_SOFTLOCKUP is not set
745# CONFIG_SCHEDSTATS is not set 760# CONFIG_SCHEDSTATS is not set
746# CONFIG_DEBUG_SLAB is not set 761# CONFIG_DEBUG_SLAB is not set
762CONFIG_DEBUG_MUTEXES=y
747# CONFIG_DEBUG_SPINLOCK is not set 763# CONFIG_DEBUG_SPINLOCK is not set
748# CONFIG_DEBUG_SPINLOCK_SLEEP is not set 764# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
749# CONFIG_DEBUG_KOBJECT is not set 765# CONFIG_DEBUG_KOBJECT is not set
750CONFIG_DEBUG_INFO=y 766CONFIG_DEBUG_INFO=y
751# CONFIG_DEBUG_VM is not set 767# CONFIG_DEBUG_VM is not set
768CONFIG_FORCED_INLINING=y
752# CONFIG_RCU_TORTURE_TEST is not set 769# CONFIG_RCU_TORTURE_TEST is not set
753CONFIG_CROSSCOMPILE=y 770CONFIG_CROSSCOMPILE=y
754CONFIG_CMDLINE="nfsroot=192.168.192.169:/u1/mipsel,timeo=20 ip=dhcp" 771CONFIG_CMDLINE="nfsroot=192.168.192.169:/u1/mipsel,timeo=20 ip=dhcp"
diff --git a/arch/mips/configs/mpc30x_defconfig b/arch/mips/configs/mpc30x_defconfig
index 2b5ea37484e4..e4620e7f0a5e 100644
--- a/arch/mips/configs/mpc30x_defconfig
+++ b/arch/mips/configs/mpc30x_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:39 2005 4# Fri Jan 27 15:40:17 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -63,9 +63,9 @@ CONFIG_MACH_VR41XX=y
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
66# CONFIG_NEC_CMBVR4133 is not set
67# CONFIG_CASIO_E55 is not set 66# CONFIG_CASIO_E55 is not set
68# CONFIG_IBM_WORKPAD is not set 67# CONFIG_IBM_WORKPAD is not set
68# CONFIG_NEC_CMBVR4133 is not set
69# CONFIG_TANBAC_TB022X is not set 69# CONFIG_TANBAC_TB022X is not set
70CONFIG_VICTOR_MPC30X=y 70CONFIG_VICTOR_MPC30X=y
71# CONFIG_ZAO_CAPCELLA is not set 71# CONFIG_ZAO_CAPCELLA is not set
@@ -90,7 +90,7 @@ CONFIG_MIPS_L1_CACHE_SHIFT=5
90# CONFIG_CPU_MIPS64_R2 is not set 90# CONFIG_CPU_MIPS64_R2 is not set
91# CONFIG_CPU_R3000 is not set 91# CONFIG_CPU_R3000 is not set
92# CONFIG_CPU_TX39XX is not set 92# CONFIG_CPU_TX39XX is not set
93CONFIG_CPU_VR41XX=y 93# CONFIG_CPU_VR41XX is not set
94# CONFIG_CPU_R4300 is not set 94# CONFIG_CPU_R4300 is not set
95# CONFIG_CPU_R4X00 is not set 95# CONFIG_CPU_R4X00 is not set
96# CONFIG_CPU_TX49XX is not set 96# CONFIG_CPU_TX49XX is not set
@@ -103,23 +103,18 @@ CONFIG_CPU_VR41XX=y
103# CONFIG_CPU_RM7000 is not set 103# CONFIG_CPU_RM7000 is not set
104# CONFIG_CPU_RM9000 is not set 104# CONFIG_CPU_RM9000 is not set
105# CONFIG_CPU_SB1 is not set 105# CONFIG_CPU_SB1 is not set
106CONFIG_SYS_HAS_CPU_VR41XX=y
107CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
108CONFIG_SYS_SUPPORTS_64BIT_KERNEL=y
109CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
110CONFIG_CPU_SUPPORTS_64BIT_KERNEL=y
111 106
112# 107#
113# Kernel type 108# Kernel type
114# 109#
115CONFIG_32BIT=y 110# CONFIG_32BIT is not set
116# CONFIG_64BIT is not set 111# CONFIG_64BIT is not set
117CONFIG_PAGE_SIZE_4KB=y 112CONFIG_PAGE_SIZE_4KB=y
118# CONFIG_PAGE_SIZE_8KB is not set 113# CONFIG_PAGE_SIZE_8KB is not set
119# CONFIG_PAGE_SIZE_16KB is not set 114# CONFIG_PAGE_SIZE_16KB is not set
120# CONFIG_PAGE_SIZE_64KB is not set 115# CONFIG_PAGE_SIZE_64KB is not set
121# CONFIG_MIPS_MT is not set 116# CONFIG_MIPS_MT is not set
122# CONFIG_CPU_ADVANCED is not set 117CONFIG_CPU_HAS_LLSC=y
123CONFIG_CPU_HAS_SYNC=y 118CONFIG_CPU_HAS_SYNC=y
124CONFIG_GENERIC_HARDIRQS=y 119CONFIG_GENERIC_HARDIRQS=y
125CONFIG_GENERIC_IRQ_PROBE=y 120CONFIG_GENERIC_IRQ_PROBE=y
@@ -155,26 +150,28 @@ CONFIG_SYSVIPC=y
155# CONFIG_BSD_PROCESS_ACCT is not set 150# CONFIG_BSD_PROCESS_ACCT is not set
156CONFIG_SYSCTL=y 151CONFIG_SYSCTL=y
157# CONFIG_AUDIT is not set 152# CONFIG_AUDIT is not set
158CONFIG_HOTPLUG=y
159CONFIG_KOBJECT_UEVENT=y
160# CONFIG_IKCONFIG is not set 153# CONFIG_IKCONFIG is not set
161CONFIG_INITRAMFS_SOURCE="" 154CONFIG_INITRAMFS_SOURCE=""
155# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
162CONFIG_EMBEDDED=y 156CONFIG_EMBEDDED=y
163CONFIG_KALLSYMS=y 157CONFIG_KALLSYMS=y
164# CONFIG_KALLSYMS_EXTRA_PASS is not set 158# CONFIG_KALLSYMS_EXTRA_PASS is not set
159CONFIG_HOTPLUG=y
165CONFIG_PRINTK=y 160CONFIG_PRINTK=y
166CONFIG_BUG=y 161CONFIG_BUG=y
162CONFIG_ELF_CORE=y
167CONFIG_BASE_FULL=y 163CONFIG_BASE_FULL=y
168CONFIG_FUTEX=y 164CONFIG_FUTEX=y
169CONFIG_EPOLL=y 165CONFIG_EPOLL=y
170# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
171CONFIG_SHMEM=y 166CONFIG_SHMEM=y
172CONFIG_CC_ALIGN_FUNCTIONS=0 167CONFIG_CC_ALIGN_FUNCTIONS=0
173CONFIG_CC_ALIGN_LABELS=0 168CONFIG_CC_ALIGN_LABELS=0
174CONFIG_CC_ALIGN_LOOPS=0 169CONFIG_CC_ALIGN_LOOPS=0
175CONFIG_CC_ALIGN_JUMPS=0 170CONFIG_CC_ALIGN_JUMPS=0
171CONFIG_SLAB=y
176# CONFIG_TINY_SHMEM is not set 172# CONFIG_TINY_SHMEM is not set
177CONFIG_BASE_SMALL=0 173CONFIG_BASE_SMALL=0
174# CONFIG_SLOB is not set
178 175
179# 176#
180# Loadable module support 177# Loadable module support
@@ -190,7 +187,6 @@ CONFIG_KMOD=y
190# 187#
191# Block layer 188# Block layer
192# 189#
193# CONFIG_LBD is not set
194 190
195# 191#
196# IO Schedulers 192# IO Schedulers
@@ -229,7 +225,6 @@ CONFIG_PCMCIA_IOCTL=y
229# CONFIG_YENTA is not set 225# CONFIG_YENTA is not set
230# CONFIG_PD6729 is not set 226# CONFIG_PD6729 is not set
231# CONFIG_I82092 is not set 227# CONFIG_I82092 is not set
232CONFIG_PCMCIA_VRC4173=y
233 228
234# 229#
235# PCI Hotplug Support 230# PCI Hotplug Support
@@ -241,7 +236,6 @@ CONFIG_PCMCIA_VRC4173=y
241# 236#
242CONFIG_BINFMT_ELF=y 237CONFIG_BINFMT_ELF=y
243# CONFIG_BINFMT_MISC is not set 238# CONFIG_BINFMT_MISC is not set
244CONFIG_TRAD_SIGNALS=y
245 239
246# 240#
247# Networking 241# Networking
@@ -296,6 +290,11 @@ CONFIG_TCP_CONG_BIC=y
296# CONFIG_ATALK is not set 290# CONFIG_ATALK is not set
297# CONFIG_X25 is not set 291# CONFIG_X25 is not set
298# CONFIG_LAPB is not set 292# CONFIG_LAPB is not set
293
294#
295# TIPC Configuration (EXPERIMENTAL)
296#
297# CONFIG_TIPC is not set
299# CONFIG_NET_DIVERT is not set 298# CONFIG_NET_DIVERT is not set
300# CONFIG_ECONET is not set 299# CONFIG_ECONET is not set
301# CONFIG_WAN_ROUTER is not set 300# CONFIG_WAN_ROUTER is not set
@@ -455,6 +454,7 @@ CONFIG_MII=m
455# CONFIG_R8169 is not set 454# CONFIG_R8169 is not set
456# CONFIG_SIS190 is not set 455# CONFIG_SIS190 is not set
457# CONFIG_SKGE is not set 456# CONFIG_SKGE is not set
457# CONFIG_SKY2 is not set
458# CONFIG_SK98LIN is not set 458# CONFIG_SK98LIN is not set
459# CONFIG_TIGON3 is not set 459# CONFIG_TIGON3 is not set
460# CONFIG_BNX2 is not set 460# CONFIG_BNX2 is not set
@@ -604,11 +604,6 @@ CONFIG_HW_CONSOLE=y
604# 604#
605# Non-8250 serial port support 605# Non-8250 serial port support
606# 606#
607CONFIG_SERIAL_CORE=y
608CONFIG_SERIAL_CORE_CONSOLE=y
609CONFIG_SERIAL_VR41XX=y
610CONFIG_SERIAL_VR41XX_CONSOLE=y
611# CONFIG_SERIAL_JSM is not set
612CONFIG_UNIX98_PTYS=y 607CONFIG_UNIX98_PTYS=y
613CONFIG_LEGACY_PTYS=y 608CONFIG_LEGACY_PTYS=y
614CONFIG_LEGACY_PTY_COUNT=256 609CONFIG_LEGACY_PTY_COUNT=256
@@ -624,7 +619,6 @@ CONFIG_LEGACY_PTY_COUNT=256
624# CONFIG_WATCHDOG is not set 619# CONFIG_WATCHDOG is not set
625# CONFIG_RTC is not set 620# CONFIG_RTC is not set
626# CONFIG_GEN_RTC is not set 621# CONFIG_GEN_RTC is not set
627# CONFIG_RTC_VR41XX is not set
628# CONFIG_DTLK is not set 622# CONFIG_DTLK is not set
629# CONFIG_R3964 is not set 623# CONFIG_R3964 is not set
630# CONFIG_APPLICOM is not set 624# CONFIG_APPLICOM is not set
@@ -640,7 +634,6 @@ CONFIG_LEGACY_PTY_COUNT=256
640# CONFIG_SYNCLINK_CS is not set 634# CONFIG_SYNCLINK_CS is not set
641# CONFIG_CARDMAN_4000 is not set 635# CONFIG_CARDMAN_4000 is not set
642# CONFIG_CARDMAN_4040 is not set 636# CONFIG_CARDMAN_4040 is not set
643CONFIG_GPIO_VR41XX=y
644# CONFIG_RAW_DRIVER is not set 637# CONFIG_RAW_DRIVER is not set
645 638
646# 639#
@@ -655,6 +648,12 @@ CONFIG_GPIO_VR41XX=y
655# CONFIG_I2C is not set 648# CONFIG_I2C is not set
656 649
657# 650#
651# SPI support
652#
653# CONFIG_SPI is not set
654# CONFIG_SPI_MASTER is not set
655
656#
658# Dallas's 1-wire bus 657# Dallas's 1-wire bus
659# 658#
660# CONFIG_W1 is not set 659# CONFIG_W1 is not set
@@ -740,6 +739,7 @@ CONFIG_USB_OHCI_LITTLE_ENDIAN=y
740# may also be needed; see USB_STORAGE Help for more information 739# may also be needed; see USB_STORAGE Help for more information
741# 740#
742# CONFIG_USB_STORAGE is not set 741# CONFIG_USB_STORAGE is not set
742# CONFIG_USB_LIBUSUAL is not set
743 743
744# 744#
745# USB Input Devices 745# USB Input Devices
@@ -762,6 +762,7 @@ CONFIG_USB_OHCI_LITTLE_ENDIAN=y
762# CONFIG_USB_YEALINK is not set 762# CONFIG_USB_YEALINK is not set
763# CONFIG_USB_XPAD is not set 763# CONFIG_USB_XPAD is not set
764# CONFIG_USB_ATI_REMOTE is not set 764# CONFIG_USB_ATI_REMOTE is not set
765# CONFIG_USB_ATI_REMOTE2 is not set
765# CONFIG_USB_KEYSPAN_REMOTE is not set 766# CONFIG_USB_KEYSPAN_REMOTE is not set
766# CONFIG_USB_APPLETOUCH is not set 767# CONFIG_USB_APPLETOUCH is not set
767 768
@@ -846,11 +847,11 @@ CONFIG_EXT2_FS=y
846# CONFIG_EXT2_FS_XATTR is not set 847# CONFIG_EXT2_FS_XATTR is not set
847# CONFIG_EXT2_FS_XIP is not set 848# CONFIG_EXT2_FS_XIP is not set
848# CONFIG_EXT3_FS is not set 849# CONFIG_EXT3_FS is not set
849# CONFIG_JBD is not set
850# CONFIG_REISERFS_FS is not set 850# CONFIG_REISERFS_FS is not set
851# CONFIG_JFS_FS is not set 851# CONFIG_JFS_FS is not set
852# CONFIG_FS_POSIX_ACL is not set 852# CONFIG_FS_POSIX_ACL is not set
853# CONFIG_XFS_FS is not set 853# CONFIG_XFS_FS is not set
854# CONFIG_OCFS2_FS is not set
854# CONFIG_MINIX_FS is not set 855# CONFIG_MINIX_FS is not set
855# CONFIG_ROMFS_FS is not set 856# CONFIG_ROMFS_FS is not set
856CONFIG_INOTIFY=y 857CONFIG_INOTIFY=y
@@ -883,6 +884,7 @@ CONFIG_SYSFS=y
883# CONFIG_HUGETLB_PAGE is not set 884# CONFIG_HUGETLB_PAGE is not set
884CONFIG_RAMFS=y 885CONFIG_RAMFS=y
885CONFIG_RELAYFS_FS=m 886CONFIG_RELAYFS_FS=m
887# CONFIG_CONFIGFS_FS is not set
886 888
887# 889#
888# Miscellaneous filesystems 890# Miscellaneous filesystems
@@ -941,6 +943,7 @@ CONFIG_MSDOS_PARTITION=y
941# Kernel hacking 943# Kernel hacking
942# 944#
943# CONFIG_PRINTK_TIME is not set 945# CONFIG_PRINTK_TIME is not set
946# CONFIG_MAGIC_SYSRQ is not set
944# CONFIG_DEBUG_KERNEL is not set 947# CONFIG_DEBUG_KERNEL is not set
945CONFIG_LOG_BUF_SHIFT=14 948CONFIG_LOG_BUF_SHIFT=14
946CONFIG_CROSSCOMPILE=y 949CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/ocelot_3_defconfig b/arch/mips/configs/ocelot_3_defconfig
index 7ad8718c1b69..925d8adef88d 100644
--- a/arch/mips/configs/ocelot_3_defconfig
+++ b/arch/mips/configs/ocelot_3_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:41 2005 4# Fri Jan 27 15:40:18 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -159,27 +159,29 @@ CONFIG_SYSVIPC=y
159# CONFIG_BSD_PROCESS_ACCT is not set 159# CONFIG_BSD_PROCESS_ACCT is not set
160CONFIG_SYSCTL=y 160CONFIG_SYSCTL=y
161# CONFIG_AUDIT is not set 161# CONFIG_AUDIT is not set
162CONFIG_HOTPLUG=y
163CONFIG_KOBJECT_UEVENT=y
164CONFIG_IKCONFIG=y 162CONFIG_IKCONFIG=y
165CONFIG_IKCONFIG_PROC=y 163CONFIG_IKCONFIG_PROC=y
166CONFIG_INITRAMFS_SOURCE="" 164CONFIG_INITRAMFS_SOURCE=""
165# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
167CONFIG_EMBEDDED=y 166CONFIG_EMBEDDED=y
168CONFIG_KALLSYMS=y 167CONFIG_KALLSYMS=y
169# CONFIG_KALLSYMS_EXTRA_PASS is not set 168# CONFIG_KALLSYMS_EXTRA_PASS is not set
169CONFIG_HOTPLUG=y
170CONFIG_PRINTK=y 170CONFIG_PRINTK=y
171CONFIG_BUG=y 171CONFIG_BUG=y
172CONFIG_ELF_CORE=y
172CONFIG_BASE_FULL=y 173CONFIG_BASE_FULL=y
173CONFIG_FUTEX=y 174CONFIG_FUTEX=y
174CONFIG_EPOLL=y 175CONFIG_EPOLL=y
175# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
176CONFIG_SHMEM=y 176CONFIG_SHMEM=y
177CONFIG_CC_ALIGN_FUNCTIONS=0 177CONFIG_CC_ALIGN_FUNCTIONS=0
178CONFIG_CC_ALIGN_LABELS=0 178CONFIG_CC_ALIGN_LABELS=0
179CONFIG_CC_ALIGN_LOOPS=0 179CONFIG_CC_ALIGN_LOOPS=0
180CONFIG_CC_ALIGN_JUMPS=0 180CONFIG_CC_ALIGN_JUMPS=0
181CONFIG_SLAB=y
181# CONFIG_TINY_SHMEM is not set 182# CONFIG_TINY_SHMEM is not set
182CONFIG_BASE_SMALL=0 183CONFIG_BASE_SMALL=0
184# CONFIG_SLOB is not set
183 185
184# 186#
185# Loadable module support 187# Loadable module support
@@ -291,6 +293,21 @@ CONFIG_NETFILTER_NETLINK=m
291CONFIG_NETFILTER_NETLINK_QUEUE=m 293CONFIG_NETFILTER_NETLINK_QUEUE=m
292CONFIG_NETFILTER_NETLINK_LOG=m 294CONFIG_NETFILTER_NETLINK_LOG=m
293# CONFIG_NF_CONNTRACK is not set 295# CONFIG_NF_CONNTRACK is not set
296CONFIG_NETFILTER_XTABLES=m
297CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
298CONFIG_NETFILTER_XT_TARGET_MARK=m
299CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
300CONFIG_NETFILTER_XT_MATCH_COMMENT=m
301CONFIG_NETFILTER_XT_MATCH_DCCP=m
302CONFIG_NETFILTER_XT_MATCH_LENGTH=m
303CONFIG_NETFILTER_XT_MATCH_LIMIT=m
304CONFIG_NETFILTER_XT_MATCH_MAC=m
305CONFIG_NETFILTER_XT_MATCH_MARK=m
306CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
307CONFIG_NETFILTER_XT_MATCH_REALM=m
308CONFIG_NETFILTER_XT_MATCH_SCTP=m
309CONFIG_NETFILTER_XT_MATCH_STRING=m
310CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
294 311
295# 312#
296# IP: Netfilter Configuration 313# IP: Netfilter Configuration
@@ -324,6 +341,11 @@ CONFIG_NETFILTER_NETLINK_LOG=m
324# CONFIG_ATALK is not set 341# CONFIG_ATALK is not set
325# CONFIG_X25 is not set 342# CONFIG_X25 is not set
326# CONFIG_LAPB is not set 343# CONFIG_LAPB is not set
344
345#
346# TIPC Configuration (EXPERIMENTAL)
347#
348# CONFIG_TIPC is not set
327# CONFIG_NET_DIVERT is not set 349# CONFIG_NET_DIVERT is not set
328# CONFIG_ECONET is not set 350# CONFIG_ECONET is not set
329# CONFIG_WAN_ROUTER is not set 351# CONFIG_WAN_ROUTER is not set
@@ -332,6 +354,7 @@ CONFIG_NETFILTER_NETLINK_LOG=m
332# QoS and/or fair queueing 354# QoS and/or fair queueing
333# 355#
334# CONFIG_NET_SCHED is not set 356# CONFIG_NET_SCHED is not set
357CONFIG_NET_CLS_ROUTE=y
335 358
336# 359#
337# Network testing 360# Network testing
@@ -344,7 +367,6 @@ CONFIG_IEEE80211=m
344# CONFIG_IEEE80211_DEBUG is not set 367# CONFIG_IEEE80211_DEBUG is not set
345CONFIG_IEEE80211_CRYPT_WEP=m 368CONFIG_IEEE80211_CRYPT_WEP=m
346CONFIG_IEEE80211_CRYPT_CCMP=m 369CONFIG_IEEE80211_CRYPT_CCMP=m
347CONFIG_IEEE80211_CRYPT_TKIP=m
348 370
349# 371#
350# Device Drivers 372# Device Drivers
@@ -426,7 +448,7 @@ CONFIG_SCSI_PROC_FS=y
426# SCSI Transport Attributes 448# SCSI Transport Attributes
427# 449#
428# CONFIG_SCSI_SPI_ATTRS is not set 450# CONFIG_SCSI_SPI_ATTRS is not set
429# CONFIG_SCSI_FC_ATTRS is not set 451CONFIG_SCSI_FC_ATTRS=m
430CONFIG_SCSI_ISCSI_ATTRS=m 452CONFIG_SCSI_ISCSI_ATTRS=m
431CONFIG_SCSI_SAS_ATTRS=m 453CONFIG_SCSI_SAS_ATTRS=m
432 454
@@ -455,13 +477,7 @@ CONFIG_ISCSI_TCP=m
455# CONFIG_SCSI_IPR is not set 477# CONFIG_SCSI_IPR is not set
456# CONFIG_SCSI_QLOGIC_FC is not set 478# CONFIG_SCSI_QLOGIC_FC is not set
457# CONFIG_SCSI_QLOGIC_1280 is not set 479# CONFIG_SCSI_QLOGIC_1280 is not set
458CONFIG_SCSI_QLA2XXX=m 480# CONFIG_SCSI_QLA_FC is not set
459# CONFIG_SCSI_QLA21XX is not set
460# CONFIG_SCSI_QLA22XX is not set
461# CONFIG_SCSI_QLA2300 is not set
462# CONFIG_SCSI_QLA2322 is not set
463# CONFIG_SCSI_QLA6312 is not set
464# CONFIG_SCSI_QLA24XX is not set
465# CONFIG_SCSI_LPFC is not set 481# CONFIG_SCSI_LPFC is not set
466# CONFIG_SCSI_DC395x is not set 482# CONFIG_SCSI_DC395x is not set
467# CONFIG_SCSI_DC390T is not set 483# CONFIG_SCSI_DC390T is not set
@@ -528,6 +544,7 @@ CONFIG_MII=y
528# CONFIG_SUNGEM is not set 544# CONFIG_SUNGEM is not set
529# CONFIG_CASSINI is not set 545# CONFIG_CASSINI is not set
530# CONFIG_NET_VENDOR_3COM is not set 546# CONFIG_NET_VENDOR_3COM is not set
547# CONFIG_DM9000 is not set
531 548
532# 549#
533# Tulip family network device support 550# Tulip family network device support
@@ -567,6 +584,7 @@ CONFIG_E100=y
567# CONFIG_R8169 is not set 584# CONFIG_R8169 is not set
568# CONFIG_SIS190 is not set 585# CONFIG_SIS190 is not set
569# CONFIG_SKGE is not set 586# CONFIG_SKGE is not set
587# CONFIG_SKY2 is not set
570# CONFIG_SK98LIN is not set 588# CONFIG_SK98LIN is not set
571# CONFIG_VIA_VELOCITY is not set 589# CONFIG_VIA_VELOCITY is not set
572# CONFIG_TIGON3 is not set 590# CONFIG_TIGON3 is not set
@@ -592,8 +610,6 @@ CONFIG_MV643XX_ETH_2=y
592# Wireless LAN (non-hamradio) 610# Wireless LAN (non-hamradio)
593# 611#
594# CONFIG_NET_RADIO is not set 612# CONFIG_NET_RADIO is not set
595# CONFIG_IPW_DEBUG is not set
596CONFIG_IPW2200=m
597 613
598# 614#
599# Wan interfaces 615# Wan interfaces
@@ -675,6 +691,7 @@ CONFIG_HW_CONSOLE=y
675CONFIG_SERIAL_8250=y 691CONFIG_SERIAL_8250=y
676CONFIG_SERIAL_8250_CONSOLE=y 692CONFIG_SERIAL_8250_CONSOLE=y
677CONFIG_SERIAL_8250_NR_UARTS=4 693CONFIG_SERIAL_8250_NR_UARTS=4
694CONFIG_SERIAL_8250_RUNTIME_UARTS=4
678# CONFIG_SERIAL_8250_EXTENDED is not set 695# CONFIG_SERIAL_8250_EXTENDED is not set
679 696
680# 697#
@@ -682,7 +699,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
682# 699#
683CONFIG_SERIAL_CORE=y 700CONFIG_SERIAL_CORE=y
684CONFIG_SERIAL_CORE_CONSOLE=y 701CONFIG_SERIAL_CORE_CONSOLE=y
685# CONFIG_SERIAL_JSM is not set
686CONFIG_UNIX98_PTYS=y 702CONFIG_UNIX98_PTYS=y
687CONFIG_LEGACY_PTYS=y 703CONFIG_LEGACY_PTYS=y
688CONFIG_LEGACY_PTY_COUNT=256 704CONFIG_LEGACY_PTY_COUNT=256
@@ -719,6 +735,12 @@ CONFIG_RTC=y
719# CONFIG_I2C is not set 735# CONFIG_I2C is not set
720 736
721# 737#
738# SPI support
739#
740# CONFIG_SPI is not set
741# CONFIG_SPI_MASTER is not set
742
743#
722# Dallas's 1-wire bus 744# Dallas's 1-wire bus
723# 745#
724# CONFIG_W1 is not set 746# CONFIG_W1 is not set
@@ -777,7 +799,6 @@ CONFIG_FB_MODE_HELPERS=y
777# CONFIG_FB_3DFX is not set 799# CONFIG_FB_3DFX is not set
778# CONFIG_FB_VOODOO1 is not set 800# CONFIG_FB_VOODOO1 is not set
779# CONFIG_FB_SMIVGX is not set 801# CONFIG_FB_SMIVGX is not set
780# CONFIG_FB_CYBLA is not set
781# CONFIG_FB_TRIDENT is not set 802# CONFIG_FB_TRIDENT is not set
782# CONFIG_FB_VIRTUAL is not set 803# CONFIG_FB_VIRTUAL is not set
783 804
@@ -861,6 +882,7 @@ CONFIG_XFS_EXPORT=y
861# CONFIG_XFS_SECURITY is not set 882# CONFIG_XFS_SECURITY is not set
862# CONFIG_XFS_POSIX_ACL is not set 883# CONFIG_XFS_POSIX_ACL is not set
863# CONFIG_XFS_RT is not set 884# CONFIG_XFS_RT is not set
885# CONFIG_OCFS2_FS is not set
864# CONFIG_MINIX_FS is not set 886# CONFIG_MINIX_FS is not set
865# CONFIG_ROMFS_FS is not set 887# CONFIG_ROMFS_FS is not set
866CONFIG_INOTIFY=y 888CONFIG_INOTIFY=y
@@ -893,6 +915,7 @@ CONFIG_TMPFS=y
893# CONFIG_HUGETLB_PAGE is not set 915# CONFIG_HUGETLB_PAGE is not set
894CONFIG_RAMFS=y 916CONFIG_RAMFS=y
895CONFIG_RELAYFS_FS=m 917CONFIG_RELAYFS_FS=m
918# CONFIG_CONFIGFS_FS is not set
896 919
897# 920#
898# Miscellaneous filesystems 921# Miscellaneous filesystems
@@ -999,6 +1022,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
999# Kernel hacking 1022# Kernel hacking
1000# 1023#
1001# CONFIG_PRINTK_TIME is not set 1024# CONFIG_PRINTK_TIME is not set
1025# CONFIG_MAGIC_SYSRQ is not set
1002# CONFIG_DEBUG_KERNEL is not set 1026# CONFIG_DEBUG_KERNEL is not set
1003CONFIG_LOG_BUF_SHIFT=14 1027CONFIG_LOG_BUF_SHIFT=14
1004CONFIG_CROSSCOMPILE=y 1028CONFIG_CROSSCOMPILE=y
@@ -1052,3 +1076,7 @@ CONFIG_CRC32=y
1052CONFIG_LIBCRC32C=m 1076CONFIG_LIBCRC32C=m
1053CONFIG_ZLIB_INFLATE=y 1077CONFIG_ZLIB_INFLATE=y
1054CONFIG_ZLIB_DEFLATE=m 1078CONFIG_ZLIB_DEFLATE=m
1079CONFIG_TEXTSEARCH=y
1080CONFIG_TEXTSEARCH_KMP=m
1081CONFIG_TEXTSEARCH_BM=m
1082CONFIG_TEXTSEARCH_FSM=m
diff --git a/arch/mips/configs/ocelot_c_defconfig b/arch/mips/configs/ocelot_c_defconfig
index e8d6bb3551a2..ee1cf9b9eb9a 100644
--- a/arch/mips/configs/ocelot_c_defconfig
+++ b/arch/mips/configs/ocelot_c_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:43 2005 4# Fri Jan 27 15:40:19 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -154,26 +154,28 @@ CONFIG_SYSVIPC=y
154# CONFIG_BSD_PROCESS_ACCT is not set 154# CONFIG_BSD_PROCESS_ACCT is not set
155CONFIG_SYSCTL=y 155CONFIG_SYSCTL=y
156# CONFIG_AUDIT is not set 156# CONFIG_AUDIT is not set
157CONFIG_HOTPLUG=y
158CONFIG_KOBJECT_UEVENT=y
159# CONFIG_IKCONFIG is not set 157# CONFIG_IKCONFIG is not set
160CONFIG_INITRAMFS_SOURCE="" 158CONFIG_INITRAMFS_SOURCE=""
159# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
161CONFIG_EMBEDDED=y 160CONFIG_EMBEDDED=y
162CONFIG_KALLSYMS=y 161CONFIG_KALLSYMS=y
163# CONFIG_KALLSYMS_EXTRA_PASS is not set 162# CONFIG_KALLSYMS_EXTRA_PASS is not set
163CONFIG_HOTPLUG=y
164CONFIG_PRINTK=y 164CONFIG_PRINTK=y
165CONFIG_BUG=y 165CONFIG_BUG=y
166CONFIG_ELF_CORE=y
166CONFIG_BASE_FULL=y 167CONFIG_BASE_FULL=y
167CONFIG_FUTEX=y 168CONFIG_FUTEX=y
168CONFIG_EPOLL=y 169CONFIG_EPOLL=y
169# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
170CONFIG_SHMEM=y 170CONFIG_SHMEM=y
171CONFIG_CC_ALIGN_FUNCTIONS=0 171CONFIG_CC_ALIGN_FUNCTIONS=0
172CONFIG_CC_ALIGN_LABELS=0 172CONFIG_CC_ALIGN_LABELS=0
173CONFIG_CC_ALIGN_LOOPS=0 173CONFIG_CC_ALIGN_LOOPS=0
174CONFIG_CC_ALIGN_JUMPS=0 174CONFIG_CC_ALIGN_JUMPS=0
175CONFIG_SLAB=y
175# CONFIG_TINY_SHMEM is not set 176# CONFIG_TINY_SHMEM is not set
176CONFIG_BASE_SMALL=0 177CONFIG_BASE_SMALL=0
178# CONFIG_SLOB is not set
177 179
178# 180#
179# Loadable module support 181# Loadable module support
@@ -220,7 +222,6 @@ CONFIG_MMU=y
220# 222#
221CONFIG_BINFMT_ELF=y 223CONFIG_BINFMT_ELF=y
222# CONFIG_BINFMT_MISC is not set 224# CONFIG_BINFMT_MISC is not set
223# CONFIG_BUILD_ELF64 is not set
224CONFIG_MIPS32_COMPAT=y 225CONFIG_MIPS32_COMPAT=y
225CONFIG_COMPAT=y 226CONFIG_COMPAT=y
226CONFIG_MIPS32_O32=y 227CONFIG_MIPS32_O32=y
@@ -281,6 +282,11 @@ CONFIG_TCP_CONG_BIC=y
281# CONFIG_ATALK is not set 282# CONFIG_ATALK is not set
282# CONFIG_X25 is not set 283# CONFIG_X25 is not set
283# CONFIG_LAPB is not set 284# CONFIG_LAPB is not set
285
286#
287# TIPC Configuration (EXPERIMENTAL)
288#
289# CONFIG_TIPC is not set
284# CONFIG_NET_DIVERT is not set 290# CONFIG_NET_DIVERT is not set
285# CONFIG_ECONET is not set 291# CONFIG_ECONET is not set
286# CONFIG_WAN_ROUTER is not set 292# CONFIG_WAN_ROUTER is not set
@@ -301,7 +307,6 @@ CONFIG_IEEE80211=y
301# CONFIG_IEEE80211_DEBUG is not set 307# CONFIG_IEEE80211_DEBUG is not set
302CONFIG_IEEE80211_CRYPT_WEP=y 308CONFIG_IEEE80211_CRYPT_WEP=y
303CONFIG_IEEE80211_CRYPT_CCMP=y 309CONFIG_IEEE80211_CRYPT_CCMP=y
304CONFIG_IEEE80211_CRYPT_TKIP=y
305 310
306# 311#
307# Device Drivers 312# Device Drivers
@@ -420,6 +425,7 @@ CONFIG_NET_ETHERNET=y
420# CONFIG_SUNGEM is not set 425# CONFIG_SUNGEM is not set
421# CONFIG_CASSINI is not set 426# CONFIG_CASSINI is not set
422# CONFIG_NET_VENDOR_3COM is not set 427# CONFIG_NET_VENDOR_3COM is not set
428# CONFIG_DM9000 is not set
423 429
424# 430#
425# Tulip family network device support 431# Tulip family network device support
@@ -440,6 +446,7 @@ CONFIG_NET_ETHERNET=y
440# CONFIG_R8169 is not set 446# CONFIG_R8169 is not set
441# CONFIG_SIS190 is not set 447# CONFIG_SIS190 is not set
442# CONFIG_SKGE is not set 448# CONFIG_SKGE is not set
449# CONFIG_SKY2 is not set
443# CONFIG_SK98LIN is not set 450# CONFIG_SK98LIN is not set
444# CONFIG_TIGON3 is not set 451# CONFIG_TIGON3 is not set
445# CONFIG_BNX2 is not set 452# CONFIG_BNX2 is not set
@@ -461,8 +468,6 @@ CONFIG_NET_ETHERNET=y
461# Wireless LAN (non-hamradio) 468# Wireless LAN (non-hamradio)
462# 469#
463# CONFIG_NET_RADIO is not set 470# CONFIG_NET_RADIO is not set
464# CONFIG_IPW_DEBUG is not set
465CONFIG_IPW2200=y
466 471
467# 472#
468# Wan interfaces 473# Wan interfaces
@@ -538,6 +543,7 @@ CONFIG_HW_CONSOLE=y
538CONFIG_SERIAL_8250=y 543CONFIG_SERIAL_8250=y
539CONFIG_SERIAL_8250_CONSOLE=y 544CONFIG_SERIAL_8250_CONSOLE=y
540CONFIG_SERIAL_8250_NR_UARTS=4 545CONFIG_SERIAL_8250_NR_UARTS=4
546CONFIG_SERIAL_8250_RUNTIME_UARTS=4
541# CONFIG_SERIAL_8250_EXTENDED is not set 547# CONFIG_SERIAL_8250_EXTENDED is not set
542 548
543# 549#
@@ -545,7 +551,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
545# 551#
546CONFIG_SERIAL_CORE=y 552CONFIG_SERIAL_CORE=y
547CONFIG_SERIAL_CORE_CONSOLE=y 553CONFIG_SERIAL_CORE_CONSOLE=y
548# CONFIG_SERIAL_JSM is not set
549CONFIG_UNIX98_PTYS=y 554CONFIG_UNIX98_PTYS=y
550CONFIG_LEGACY_PTYS=y 555CONFIG_LEGACY_PTYS=y
551CONFIG_LEGACY_PTY_COUNT=256 556CONFIG_LEGACY_PTY_COUNT=256
@@ -583,6 +588,12 @@ CONFIG_LEGACY_PTY_COUNT=256
583# CONFIG_I2C is not set 588# CONFIG_I2C is not set
584 589
585# 590#
591# SPI support
592#
593# CONFIG_SPI is not set
594# CONFIG_SPI_MASTER is not set
595
596#
586# Dallas's 1-wire bus 597# Dallas's 1-wire bus
587# 598#
588# CONFIG_W1 is not set 599# CONFIG_W1 is not set
@@ -664,11 +675,11 @@ CONFIG_EXT2_FS=y
664# CONFIG_EXT2_FS_XATTR is not set 675# CONFIG_EXT2_FS_XATTR is not set
665# CONFIG_EXT2_FS_XIP is not set 676# CONFIG_EXT2_FS_XIP is not set
666# CONFIG_EXT3_FS is not set 677# CONFIG_EXT3_FS is not set
667# CONFIG_JBD is not set
668# CONFIG_REISERFS_FS is not set 678# CONFIG_REISERFS_FS is not set
669# CONFIG_JFS_FS is not set 679# CONFIG_JFS_FS is not set
670# CONFIG_FS_POSIX_ACL is not set 680# CONFIG_FS_POSIX_ACL is not set
671# CONFIG_XFS_FS is not set 681# CONFIG_XFS_FS is not set
682# CONFIG_OCFS2_FS is not set
672# CONFIG_MINIX_FS is not set 683# CONFIG_MINIX_FS is not set
673# CONFIG_ROMFS_FS is not set 684# CONFIG_ROMFS_FS is not set
674CONFIG_INOTIFY=y 685CONFIG_INOTIFY=y
@@ -701,6 +712,7 @@ CONFIG_SYSFS=y
701# CONFIG_HUGETLB_PAGE is not set 712# CONFIG_HUGETLB_PAGE is not set
702CONFIG_RAMFS=y 713CONFIG_RAMFS=y
703CONFIG_RELAYFS_FS=y 714CONFIG_RELAYFS_FS=y
715# CONFIG_CONFIGFS_FS is not set
704 716
705# 717#
706# Miscellaneous filesystems 718# Miscellaneous filesystems
@@ -763,6 +775,7 @@ CONFIG_MSDOS_PARTITION=y
763# Kernel hacking 775# Kernel hacking
764# 776#
765# CONFIG_PRINTK_TIME is not set 777# CONFIG_PRINTK_TIME is not set
778# CONFIG_MAGIC_SYSRQ is not set
766# CONFIG_DEBUG_KERNEL is not set 779# CONFIG_DEBUG_KERNEL is not set
767CONFIG_LOG_BUF_SHIFT=14 780CONFIG_LOG_BUF_SHIFT=14
768CONFIG_CROSSCOMPILE=y 781CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/ocelot_defconfig b/arch/mips/configs/ocelot_defconfig
index f3787b68bdd1..d80ff278f2af 100644
--- a/arch/mips/configs/ocelot_defconfig
+++ b/arch/mips/configs/ocelot_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:44 2005 4# Fri Jan 27 15:40:20 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -159,26 +159,28 @@ CONFIG_SYSVIPC=y
159# CONFIG_BSD_PROCESS_ACCT is not set 159# CONFIG_BSD_PROCESS_ACCT is not set
160CONFIG_SYSCTL=y 160CONFIG_SYSCTL=y
161# CONFIG_AUDIT is not set 161# CONFIG_AUDIT is not set
162# CONFIG_HOTPLUG is not set
163CONFIG_KOBJECT_UEVENT=y
164# CONFIG_IKCONFIG is not set 162# CONFIG_IKCONFIG is not set
165CONFIG_INITRAMFS_SOURCE="" 163CONFIG_INITRAMFS_SOURCE=""
164# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
166CONFIG_EMBEDDED=y 165CONFIG_EMBEDDED=y
167CONFIG_KALLSYMS=y 166CONFIG_KALLSYMS=y
168# CONFIG_KALLSYMS_EXTRA_PASS is not set 167# CONFIG_KALLSYMS_EXTRA_PASS is not set
168# CONFIG_HOTPLUG is not set
169CONFIG_PRINTK=y 169CONFIG_PRINTK=y
170CONFIG_BUG=y 170CONFIG_BUG=y
171CONFIG_ELF_CORE=y
171CONFIG_BASE_FULL=y 172CONFIG_BASE_FULL=y
172CONFIG_FUTEX=y 173CONFIG_FUTEX=y
173CONFIG_EPOLL=y 174CONFIG_EPOLL=y
174# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
175CONFIG_SHMEM=y 175CONFIG_SHMEM=y
176CONFIG_CC_ALIGN_FUNCTIONS=0 176CONFIG_CC_ALIGN_FUNCTIONS=0
177CONFIG_CC_ALIGN_LABELS=0 177CONFIG_CC_ALIGN_LABELS=0
178CONFIG_CC_ALIGN_LOOPS=0 178CONFIG_CC_ALIGN_LOOPS=0
179CONFIG_CC_ALIGN_JUMPS=0 179CONFIG_CC_ALIGN_JUMPS=0
180CONFIG_SLAB=y
180# CONFIG_TINY_SHMEM is not set 181# CONFIG_TINY_SHMEM is not set
181CONFIG_BASE_SMALL=0 182CONFIG_BASE_SMALL=0
183# CONFIG_SLOB is not set
182 184
183# 185#
184# Loadable module support 186# Loadable module support
@@ -280,6 +282,11 @@ CONFIG_TCP_CONG_BIC=y
280# CONFIG_ATALK is not set 282# CONFIG_ATALK is not set
281# CONFIG_X25 is not set 283# CONFIG_X25 is not set
282# CONFIG_LAPB is not set 284# CONFIG_LAPB is not set
285
286#
287# TIPC Configuration (EXPERIMENTAL)
288#
289# CONFIG_TIPC is not set
283# CONFIG_NET_DIVERT is not set 290# CONFIG_NET_DIVERT is not set
284# CONFIG_ECONET is not set 291# CONFIG_ECONET is not set
285# CONFIG_WAN_ROUTER is not set 292# CONFIG_WAN_ROUTER is not set
@@ -300,7 +307,6 @@ CONFIG_IEEE80211=y
300# CONFIG_IEEE80211_DEBUG is not set 307# CONFIG_IEEE80211_DEBUG is not set
301CONFIG_IEEE80211_CRYPT_WEP=y 308CONFIG_IEEE80211_CRYPT_WEP=y
302CONFIG_IEEE80211_CRYPT_CCMP=y 309CONFIG_IEEE80211_CRYPT_CCMP=y
303CONFIG_IEEE80211_CRYPT_TKIP=y
304 310
305# 311#
306# Device Drivers 312# Device Drivers
@@ -403,6 +409,7 @@ CONFIG_CICADA_PHY=y
403# 409#
404CONFIG_NET_ETHERNET=y 410CONFIG_NET_ETHERNET=y
405# CONFIG_MII is not set 411# CONFIG_MII is not set
412# CONFIG_DM9000 is not set
406 413
407# 414#
408# Ethernet (1000 Mbit) 415# Ethernet (1000 Mbit)
@@ -492,6 +499,7 @@ CONFIG_HW_CONSOLE=y
492CONFIG_SERIAL_8250=y 499CONFIG_SERIAL_8250=y
493CONFIG_SERIAL_8250_CONSOLE=y 500CONFIG_SERIAL_8250_CONSOLE=y
494CONFIG_SERIAL_8250_NR_UARTS=4 501CONFIG_SERIAL_8250_NR_UARTS=4
502CONFIG_SERIAL_8250_RUNTIME_UARTS=4
495# CONFIG_SERIAL_8250_EXTENDED is not set 503# CONFIG_SERIAL_8250_EXTENDED is not set
496 504
497# 505#
@@ -534,6 +542,12 @@ CONFIG_LEGACY_PTY_COUNT=256
534# CONFIG_I2C is not set 542# CONFIG_I2C is not set
535 543
536# 544#
545# SPI support
546#
547# CONFIG_SPI is not set
548# CONFIG_SPI_MASTER is not set
549
550#
537# Dallas's 1-wire bus 551# Dallas's 1-wire bus
538# 552#
539# CONFIG_W1 is not set 553# CONFIG_W1 is not set
@@ -613,11 +627,11 @@ CONFIG_EXT2_FS=y
613# CONFIG_EXT2_FS_XATTR is not set 627# CONFIG_EXT2_FS_XATTR is not set
614# CONFIG_EXT2_FS_XIP is not set 628# CONFIG_EXT2_FS_XIP is not set
615# CONFIG_EXT3_FS is not set 629# CONFIG_EXT3_FS is not set
616# CONFIG_JBD is not set
617# CONFIG_REISERFS_FS is not set 630# CONFIG_REISERFS_FS is not set
618# CONFIG_JFS_FS is not set 631# CONFIG_JFS_FS is not set
619# CONFIG_FS_POSIX_ACL is not set 632# CONFIG_FS_POSIX_ACL is not set
620# CONFIG_XFS_FS is not set 633# CONFIG_XFS_FS is not set
634# CONFIG_OCFS2_FS is not set
621# CONFIG_MINIX_FS is not set 635# CONFIG_MINIX_FS is not set
622# CONFIG_ROMFS_FS is not set 636# CONFIG_ROMFS_FS is not set
623CONFIG_INOTIFY=y 637CONFIG_INOTIFY=y
@@ -650,6 +664,7 @@ CONFIG_SYSFS=y
650# CONFIG_HUGETLB_PAGE is not set 664# CONFIG_HUGETLB_PAGE is not set
651CONFIG_RAMFS=y 665CONFIG_RAMFS=y
652CONFIG_RELAYFS_FS=y 666CONFIG_RELAYFS_FS=y
667# CONFIG_CONFIGFS_FS is not set
653 668
654# 669#
655# Miscellaneous filesystems 670# Miscellaneous filesystems
@@ -712,6 +727,7 @@ CONFIG_MSDOS_PARTITION=y
712# Kernel hacking 727# Kernel hacking
713# 728#
714# CONFIG_PRINTK_TIME is not set 729# CONFIG_PRINTK_TIME is not set
730# CONFIG_MAGIC_SYSRQ is not set
715# CONFIG_DEBUG_KERNEL is not set 731# CONFIG_DEBUG_KERNEL is not set
716CONFIG_LOG_BUF_SHIFT=14 732CONFIG_LOG_BUF_SHIFT=14
717CONFIG_CROSSCOMPILE=y 733CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/ocelot_g_defconfig b/arch/mips/configs/ocelot_g_defconfig
index b6126ad4d06d..c0f508d180c4 100644
--- a/arch/mips/configs/ocelot_g_defconfig
+++ b/arch/mips/configs/ocelot_g_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:46 2005 4# Fri Jan 27 15:40:21 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -157,26 +157,28 @@ CONFIG_SYSVIPC=y
157# CONFIG_BSD_PROCESS_ACCT is not set 157# CONFIG_BSD_PROCESS_ACCT is not set
158CONFIG_SYSCTL=y 158CONFIG_SYSCTL=y
159# CONFIG_AUDIT is not set 159# CONFIG_AUDIT is not set
160CONFIG_HOTPLUG=y
161CONFIG_KOBJECT_UEVENT=y
162# CONFIG_IKCONFIG is not set 160# CONFIG_IKCONFIG is not set
163CONFIG_INITRAMFS_SOURCE="" 161CONFIG_INITRAMFS_SOURCE=""
162# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
164CONFIG_EMBEDDED=y 163CONFIG_EMBEDDED=y
165CONFIG_KALLSYMS=y 164CONFIG_KALLSYMS=y
166# CONFIG_KALLSYMS_EXTRA_PASS is not set 165# CONFIG_KALLSYMS_EXTRA_PASS is not set
166CONFIG_HOTPLUG=y
167CONFIG_PRINTK=y 167CONFIG_PRINTK=y
168CONFIG_BUG=y 168CONFIG_BUG=y
169CONFIG_ELF_CORE=y
169CONFIG_BASE_FULL=y 170CONFIG_BASE_FULL=y
170CONFIG_FUTEX=y 171CONFIG_FUTEX=y
171CONFIG_EPOLL=y 172CONFIG_EPOLL=y
172# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
173CONFIG_SHMEM=y 173CONFIG_SHMEM=y
174CONFIG_CC_ALIGN_FUNCTIONS=0 174CONFIG_CC_ALIGN_FUNCTIONS=0
175CONFIG_CC_ALIGN_LABELS=0 175CONFIG_CC_ALIGN_LABELS=0
176CONFIG_CC_ALIGN_LOOPS=0 176CONFIG_CC_ALIGN_LOOPS=0
177CONFIG_CC_ALIGN_JUMPS=0 177CONFIG_CC_ALIGN_JUMPS=0
178CONFIG_SLAB=y
178# CONFIG_TINY_SHMEM is not set 179# CONFIG_TINY_SHMEM is not set
179CONFIG_BASE_SMALL=0 180CONFIG_BASE_SMALL=0
181# CONFIG_SLOB is not set
180 182
181# 183#
182# Loadable module support 184# Loadable module support
@@ -223,7 +225,6 @@ CONFIG_MMU=y
223# 225#
224CONFIG_BINFMT_ELF=y 226CONFIG_BINFMT_ELF=y
225# CONFIG_BINFMT_MISC is not set 227# CONFIG_BINFMT_MISC is not set
226# CONFIG_BUILD_ELF64 is not set
227CONFIG_MIPS32_COMPAT=y 228CONFIG_MIPS32_COMPAT=y
228CONFIG_COMPAT=y 229CONFIG_COMPAT=y
229CONFIG_MIPS32_O32=y 230CONFIG_MIPS32_O32=y
@@ -284,6 +285,11 @@ CONFIG_TCP_CONG_BIC=y
284# CONFIG_ATALK is not set 285# CONFIG_ATALK is not set
285# CONFIG_X25 is not set 286# CONFIG_X25 is not set
286# CONFIG_LAPB is not set 287# CONFIG_LAPB is not set
288
289#
290# TIPC Configuration (EXPERIMENTAL)
291#
292# CONFIG_TIPC is not set
287# CONFIG_NET_DIVERT is not set 293# CONFIG_NET_DIVERT is not set
288# CONFIG_ECONET is not set 294# CONFIG_ECONET is not set
289# CONFIG_WAN_ROUTER is not set 295# CONFIG_WAN_ROUTER is not set
@@ -304,7 +310,6 @@ CONFIG_IEEE80211=y
304# CONFIG_IEEE80211_DEBUG is not set 310# CONFIG_IEEE80211_DEBUG is not set
305CONFIG_IEEE80211_CRYPT_WEP=y 311CONFIG_IEEE80211_CRYPT_WEP=y
306CONFIG_IEEE80211_CRYPT_CCMP=y 312CONFIG_IEEE80211_CRYPT_CCMP=y
307CONFIG_IEEE80211_CRYPT_TKIP=y
308 313
309# 314#
310# Device Drivers 315# Device Drivers
@@ -424,6 +429,7 @@ CONFIG_GALILEO_64240_ETH=y
424# CONFIG_SUNGEM is not set 429# CONFIG_SUNGEM is not set
425# CONFIG_CASSINI is not set 430# CONFIG_CASSINI is not set
426# CONFIG_NET_VENDOR_3COM is not set 431# CONFIG_NET_VENDOR_3COM is not set
432# CONFIG_DM9000 is not set
427 433
428# 434#
429# Tulip family network device support 435# Tulip family network device support
@@ -444,6 +450,7 @@ CONFIG_GALILEO_64240_ETH=y
444# CONFIG_R8169 is not set 450# CONFIG_R8169 is not set
445# CONFIG_SIS190 is not set 451# CONFIG_SIS190 is not set
446# CONFIG_SKGE is not set 452# CONFIG_SKGE is not set
453# CONFIG_SKY2 is not set
447# CONFIG_SK98LIN is not set 454# CONFIG_SK98LIN is not set
448# CONFIG_TIGON3 is not set 455# CONFIG_TIGON3 is not set
449# CONFIG_BNX2 is not set 456# CONFIG_BNX2 is not set
@@ -464,8 +471,6 @@ CONFIG_GALILEO_64240_ETH=y
464# Wireless LAN (non-hamradio) 471# Wireless LAN (non-hamradio)
465# 472#
466# CONFIG_NET_RADIO is not set 473# CONFIG_NET_RADIO is not set
467# CONFIG_IPW_DEBUG is not set
468CONFIG_IPW2200=y
469 474
470# 475#
471# Wan interfaces 476# Wan interfaces
@@ -541,6 +546,7 @@ CONFIG_HW_CONSOLE=y
541CONFIG_SERIAL_8250=y 546CONFIG_SERIAL_8250=y
542CONFIG_SERIAL_8250_CONSOLE=y 547CONFIG_SERIAL_8250_CONSOLE=y
543CONFIG_SERIAL_8250_NR_UARTS=4 548CONFIG_SERIAL_8250_NR_UARTS=4
549CONFIG_SERIAL_8250_RUNTIME_UARTS=4
544# CONFIG_SERIAL_8250_EXTENDED is not set 550# CONFIG_SERIAL_8250_EXTENDED is not set
545 551
546# 552#
@@ -548,7 +554,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
548# 554#
549CONFIG_SERIAL_CORE=y 555CONFIG_SERIAL_CORE=y
550CONFIG_SERIAL_CORE_CONSOLE=y 556CONFIG_SERIAL_CORE_CONSOLE=y
551# CONFIG_SERIAL_JSM is not set
552CONFIG_UNIX98_PTYS=y 557CONFIG_UNIX98_PTYS=y
553CONFIG_LEGACY_PTYS=y 558CONFIG_LEGACY_PTYS=y
554CONFIG_LEGACY_PTY_COUNT=256 559CONFIG_LEGACY_PTY_COUNT=256
@@ -586,6 +591,12 @@ CONFIG_LEGACY_PTY_COUNT=256
586# CONFIG_I2C is not set 591# CONFIG_I2C is not set
587 592
588# 593#
594# SPI support
595#
596# CONFIG_SPI is not set
597# CONFIG_SPI_MASTER is not set
598
599#
589# Dallas's 1-wire bus 600# Dallas's 1-wire bus
590# 601#
591# CONFIG_W1 is not set 602# CONFIG_W1 is not set
@@ -667,11 +678,11 @@ CONFIG_EXT2_FS=y
667# CONFIG_EXT2_FS_XATTR is not set 678# CONFIG_EXT2_FS_XATTR is not set
668# CONFIG_EXT2_FS_XIP is not set 679# CONFIG_EXT2_FS_XIP is not set
669# CONFIG_EXT3_FS is not set 680# CONFIG_EXT3_FS is not set
670# CONFIG_JBD is not set
671# CONFIG_REISERFS_FS is not set 681# CONFIG_REISERFS_FS is not set
672# CONFIG_JFS_FS is not set 682# CONFIG_JFS_FS is not set
673# CONFIG_FS_POSIX_ACL is not set 683# CONFIG_FS_POSIX_ACL is not set
674# CONFIG_XFS_FS is not set 684# CONFIG_XFS_FS is not set
685# CONFIG_OCFS2_FS is not set
675# CONFIG_MINIX_FS is not set 686# CONFIG_MINIX_FS is not set
676# CONFIG_ROMFS_FS is not set 687# CONFIG_ROMFS_FS is not set
677CONFIG_INOTIFY=y 688CONFIG_INOTIFY=y
@@ -704,6 +715,7 @@ CONFIG_SYSFS=y
704# CONFIG_HUGETLB_PAGE is not set 715# CONFIG_HUGETLB_PAGE is not set
705CONFIG_RAMFS=y 716CONFIG_RAMFS=y
706CONFIG_RELAYFS_FS=y 717CONFIG_RELAYFS_FS=y
718# CONFIG_CONFIGFS_FS is not set
707 719
708# 720#
709# Miscellaneous filesystems 721# Miscellaneous filesystems
@@ -766,6 +778,7 @@ CONFIG_MSDOS_PARTITION=y
766# Kernel hacking 778# Kernel hacking
767# 779#
768# CONFIG_PRINTK_TIME is not set 780# CONFIG_PRINTK_TIME is not set
781# CONFIG_MAGIC_SYSRQ is not set
769# CONFIG_DEBUG_KERNEL is not set 782# CONFIG_DEBUG_KERNEL is not set
770CONFIG_LOG_BUF_SHIFT=14 783CONFIG_LOG_BUF_SHIFT=14
771CONFIG_CROSSCOMPILE=y 784CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/pb1100_defconfig b/arch/mips/configs/pb1100_defconfig
index 883626afc47d..194b3c772bb7 100644
--- a/arch/mips/configs/pb1100_defconfig
+++ b/arch/mips/configs/pb1100_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:48 2005 4# Fri Jan 27 15:40:22 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -153,26 +153,29 @@ CONFIG_SYSVIPC=y
153# CONFIG_BSD_PROCESS_ACCT is not set 153# CONFIG_BSD_PROCESS_ACCT is not set
154CONFIG_SYSCTL=y 154CONFIG_SYSCTL=y
155# CONFIG_AUDIT is not set 155# CONFIG_AUDIT is not set
156CONFIG_HOTPLUG=y
157CONFIG_KOBJECT_UEVENT=y
158# CONFIG_IKCONFIG is not set 156# CONFIG_IKCONFIG is not set
159CONFIG_INITRAMFS_SOURCE="" 157CONFIG_INITRAMFS_SOURCE=""
158# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
160CONFIG_EMBEDDED=y 159CONFIG_EMBEDDED=y
161CONFIG_KALLSYMS=y 160CONFIG_KALLSYMS=y
162# CONFIG_KALLSYMS_EXTRA_PASS is not set 161# CONFIG_KALLSYMS_EXTRA_PASS is not set
162CONFIG_HOTPLUG=y
163CONFIG_PRINTK=y 163CONFIG_PRINTK=y
164CONFIG_BUG=y 164CONFIG_BUG=y
165CONFIG_ELF_CORE=y
165CONFIG_BASE_FULL=y 166CONFIG_BASE_FULL=y
166CONFIG_FUTEX=y 167CONFIG_FUTEX=y
167CONFIG_EPOLL=y 168CONFIG_EPOLL=y
168# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
169CONFIG_SHMEM=y 169CONFIG_SHMEM=y
170CONFIG_CC_ALIGN_FUNCTIONS=0 170CONFIG_CC_ALIGN_FUNCTIONS=0
171CONFIG_CC_ALIGN_LABELS=0 171CONFIG_CC_ALIGN_LABELS=0
172CONFIG_CC_ALIGN_LOOPS=0 172CONFIG_CC_ALIGN_LOOPS=0
173CONFIG_CC_ALIGN_JUMPS=0 173CONFIG_CC_ALIGN_JUMPS=0
174CONFIG_SLAB=y
174# CONFIG_TINY_SHMEM is not set 175# CONFIG_TINY_SHMEM is not set
175CONFIG_BASE_SMALL=0 176CONFIG_BASE_SMALL=0
177# CONFIG_SLOB is not set
178CONFIG_OBSOLETE_INTERMODULE=y
176 179
177# 180#
178# Loadable module support 181# Loadable module support
@@ -287,6 +290,21 @@ CONFIG_NETFILTER_NETLINK=m
287CONFIG_NETFILTER_NETLINK_QUEUE=m 290CONFIG_NETFILTER_NETLINK_QUEUE=m
288CONFIG_NETFILTER_NETLINK_LOG=m 291CONFIG_NETFILTER_NETLINK_LOG=m
289# CONFIG_NF_CONNTRACK is not set 292# CONFIG_NF_CONNTRACK is not set
293CONFIG_NETFILTER_XTABLES=m
294CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
295CONFIG_NETFILTER_XT_TARGET_MARK=m
296CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
297CONFIG_NETFILTER_XT_MATCH_COMMENT=m
298CONFIG_NETFILTER_XT_MATCH_DCCP=m
299CONFIG_NETFILTER_XT_MATCH_LENGTH=m
300CONFIG_NETFILTER_XT_MATCH_LIMIT=m
301CONFIG_NETFILTER_XT_MATCH_MAC=m
302CONFIG_NETFILTER_XT_MATCH_MARK=m
303CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
304CONFIG_NETFILTER_XT_MATCH_REALM=m
305CONFIG_NETFILTER_XT_MATCH_SCTP=m
306CONFIG_NETFILTER_XT_MATCH_STRING=m
307CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
290 308
291# 309#
292# IP: Netfilter Configuration 310# IP: Netfilter Configuration
@@ -314,6 +332,11 @@ CONFIG_NETFILTER_NETLINK_LOG=m
314# CONFIG_ATALK is not set 332# CONFIG_ATALK is not set
315# CONFIG_X25 is not set 333# CONFIG_X25 is not set
316# CONFIG_LAPB is not set 334# CONFIG_LAPB is not set
335
336#
337# TIPC Configuration (EXPERIMENTAL)
338#
339# CONFIG_TIPC is not set
317# CONFIG_NET_DIVERT is not set 340# CONFIG_NET_DIVERT is not set
318# CONFIG_ECONET is not set 341# CONFIG_ECONET is not set
319# CONFIG_WAN_ROUTER is not set 342# CONFIG_WAN_ROUTER is not set
@@ -322,6 +345,7 @@ CONFIG_NETFILTER_NETLINK_LOG=m
322# QoS and/or fair queueing 345# QoS and/or fair queueing
323# 346#
324# CONFIG_NET_SCHED is not set 347# CONFIG_NET_SCHED is not set
348CONFIG_NET_CLS_ROUTE=y
325 349
326# 350#
327# Network testing 351# Network testing
@@ -334,7 +358,6 @@ CONFIG_IEEE80211=m
334# CONFIG_IEEE80211_DEBUG is not set 358# CONFIG_IEEE80211_DEBUG is not set
335CONFIG_IEEE80211_CRYPT_WEP=m 359CONFIG_IEEE80211_CRYPT_WEP=m
336CONFIG_IEEE80211_CRYPT_CCMP=m 360CONFIG_IEEE80211_CRYPT_CCMP=m
337CONFIG_IEEE80211_CRYPT_TKIP=m
338 361
339# 362#
340# Device Drivers 363# Device Drivers
@@ -397,6 +420,7 @@ CONFIG_MTD_CFI_UTIL=y
397# CONFIG_MTD_RAM is not set 420# CONFIG_MTD_RAM is not set
398# CONFIG_MTD_ROM is not set 421# CONFIG_MTD_ROM is not set
399# CONFIG_MTD_ABSENT is not set 422# CONFIG_MTD_ABSENT is not set
423# CONFIG_MTD_OBSOLETE_CHIPS is not set
400 424
401# 425#
402# Mapping drivers for chip access 426# Mapping drivers for chip access
@@ -514,6 +538,7 @@ CONFIG_NET_ETHERNET=y
514# CONFIG_MII is not set 538# CONFIG_MII is not set
515# CONFIG_MIPS_AU1X00_ENET is not set 539# CONFIG_MIPS_AU1X00_ENET is not set
516# CONFIG_SMC91X is not set 540# CONFIG_SMC91X is not set
541# CONFIG_DM9000 is not set
517 542
518# 543#
519# Ethernet (1000 Mbit) 544# Ethernet (1000 Mbit)
@@ -619,13 +644,13 @@ CONFIG_SERIAL_8250=y
619CONFIG_SERIAL_8250_CONSOLE=y 644CONFIG_SERIAL_8250_CONSOLE=y
620# CONFIG_SERIAL_8250_CS is not set 645# CONFIG_SERIAL_8250_CS is not set
621CONFIG_SERIAL_8250_NR_UARTS=4 646CONFIG_SERIAL_8250_NR_UARTS=4
647CONFIG_SERIAL_8250_RUNTIME_UARTS=4
622# CONFIG_SERIAL_8250_EXTENDED is not set 648# CONFIG_SERIAL_8250_EXTENDED is not set
623CONFIG_SERIAL_8250_AU1X00=y 649CONFIG_SERIAL_8250_AU1X00=y
624 650
625# 651#
626# Non-8250 serial port support 652# Non-8250 serial port support
627# 653#
628# CONFIG_SERIAL_AU1X00 is not set
629CONFIG_SERIAL_CORE=y 654CONFIG_SERIAL_CORE=y
630CONFIG_SERIAL_CORE_CONSOLE=y 655CONFIG_SERIAL_CORE_CONSOLE=y
631CONFIG_UNIX98_PTYS=y 656CONFIG_UNIX98_PTYS=y
@@ -670,6 +695,12 @@ CONFIG_SYNCLINK_CS=m
670# CONFIG_I2C is not set 695# CONFIG_I2C is not set
671 696
672# 697#
698# SPI support
699#
700# CONFIG_SPI is not set
701# CONFIG_SPI_MASTER is not set
702
703#
673# Dallas's 1-wire bus 704# Dallas's 1-wire bus
674# 705#
675# CONFIG_W1 is not set 706# CONFIG_W1 is not set
@@ -767,6 +798,7 @@ CONFIG_REISERFS_FS_SECURITY=y
767# CONFIG_JFS_FS is not set 798# CONFIG_JFS_FS is not set
768CONFIG_FS_POSIX_ACL=y 799CONFIG_FS_POSIX_ACL=y
769# CONFIG_XFS_FS is not set 800# CONFIG_XFS_FS is not set
801# CONFIG_OCFS2_FS is not set
770# CONFIG_MINIX_FS is not set 802# CONFIG_MINIX_FS is not set
771# CONFIG_ROMFS_FS is not set 803# CONFIG_ROMFS_FS is not set
772CONFIG_INOTIFY=y 804CONFIG_INOTIFY=y
@@ -799,6 +831,7 @@ CONFIG_TMPFS=y
799# CONFIG_HUGETLB_PAGE is not set 831# CONFIG_HUGETLB_PAGE is not set
800CONFIG_RAMFS=y 832CONFIG_RAMFS=y
801CONFIG_RELAYFS_FS=m 833CONFIG_RELAYFS_FS=m
834# CONFIG_CONFIGFS_FS is not set
802 835
803# 836#
804# Miscellaneous filesystems 837# Miscellaneous filesystems
@@ -903,6 +936,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
903# Kernel hacking 936# Kernel hacking
904# 937#
905# CONFIG_PRINTK_TIME is not set 938# CONFIG_PRINTK_TIME is not set
939# CONFIG_MAGIC_SYSRQ is not set
906# CONFIG_DEBUG_KERNEL is not set 940# CONFIG_DEBUG_KERNEL is not set
907CONFIG_LOG_BUF_SHIFT=14 941CONFIG_LOG_BUF_SHIFT=14
908CONFIG_CROSSCOMPILE=y 942CONFIG_CROSSCOMPILE=y
@@ -957,3 +991,7 @@ CONFIG_CRC32=y
957CONFIG_LIBCRC32C=m 991CONFIG_LIBCRC32C=m
958CONFIG_ZLIB_INFLATE=m 992CONFIG_ZLIB_INFLATE=m
959CONFIG_ZLIB_DEFLATE=m 993CONFIG_ZLIB_DEFLATE=m
994CONFIG_TEXTSEARCH=y
995CONFIG_TEXTSEARCH_KMP=m
996CONFIG_TEXTSEARCH_BM=m
997CONFIG_TEXTSEARCH_FSM=m
diff --git a/arch/mips/configs/pb1500_defconfig b/arch/mips/configs/pb1500_defconfig
index f8fbc77f924e..8985725e6a98 100644
--- a/arch/mips/configs/pb1500_defconfig
+++ b/arch/mips/configs/pb1500_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:50 2005 4# Fri Jan 27 15:40:24 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -152,26 +152,29 @@ CONFIG_SYSVIPC=y
152# CONFIG_BSD_PROCESS_ACCT is not set 152# CONFIG_BSD_PROCESS_ACCT is not set
153CONFIG_SYSCTL=y 153CONFIG_SYSCTL=y
154# CONFIG_AUDIT is not set 154# CONFIG_AUDIT is not set
155CONFIG_HOTPLUG=y
156CONFIG_KOBJECT_UEVENT=y
157# CONFIG_IKCONFIG is not set 155# CONFIG_IKCONFIG is not set
158CONFIG_INITRAMFS_SOURCE="" 156CONFIG_INITRAMFS_SOURCE=""
157# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
159CONFIG_EMBEDDED=y 158CONFIG_EMBEDDED=y
160CONFIG_KALLSYMS=y 159CONFIG_KALLSYMS=y
161# CONFIG_KALLSYMS_EXTRA_PASS is not set 160# CONFIG_KALLSYMS_EXTRA_PASS is not set
161CONFIG_HOTPLUG=y
162CONFIG_PRINTK=y 162CONFIG_PRINTK=y
163CONFIG_BUG=y 163CONFIG_BUG=y
164CONFIG_ELF_CORE=y
164CONFIG_BASE_FULL=y 165CONFIG_BASE_FULL=y
165CONFIG_FUTEX=y 166CONFIG_FUTEX=y
166CONFIG_EPOLL=y 167CONFIG_EPOLL=y
167# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
168CONFIG_SHMEM=y 168CONFIG_SHMEM=y
169CONFIG_CC_ALIGN_FUNCTIONS=0 169CONFIG_CC_ALIGN_FUNCTIONS=0
170CONFIG_CC_ALIGN_LABELS=0 170CONFIG_CC_ALIGN_LABELS=0
171CONFIG_CC_ALIGN_LOOPS=0 171CONFIG_CC_ALIGN_LOOPS=0
172CONFIG_CC_ALIGN_JUMPS=0 172CONFIG_CC_ALIGN_JUMPS=0
173CONFIG_SLAB=y
173# CONFIG_TINY_SHMEM is not set 174# CONFIG_TINY_SHMEM is not set
174CONFIG_BASE_SMALL=0 175CONFIG_BASE_SMALL=0
176# CONFIG_SLOB is not set
177CONFIG_OBSOLETE_INTERMODULE=y
175 178
176# 179#
177# Loadable module support 180# Loadable module support
@@ -293,6 +296,21 @@ CONFIG_NETFILTER_NETLINK=m
293CONFIG_NETFILTER_NETLINK_QUEUE=m 296CONFIG_NETFILTER_NETLINK_QUEUE=m
294CONFIG_NETFILTER_NETLINK_LOG=m 297CONFIG_NETFILTER_NETLINK_LOG=m
295# CONFIG_NF_CONNTRACK is not set 298# CONFIG_NF_CONNTRACK is not set
299CONFIG_NETFILTER_XTABLES=m
300CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
301CONFIG_NETFILTER_XT_TARGET_MARK=m
302CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
303CONFIG_NETFILTER_XT_MATCH_COMMENT=m
304CONFIG_NETFILTER_XT_MATCH_DCCP=m
305CONFIG_NETFILTER_XT_MATCH_LENGTH=m
306CONFIG_NETFILTER_XT_MATCH_LIMIT=m
307CONFIG_NETFILTER_XT_MATCH_MAC=m
308CONFIG_NETFILTER_XT_MATCH_MARK=m
309CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
310CONFIG_NETFILTER_XT_MATCH_REALM=m
311CONFIG_NETFILTER_XT_MATCH_SCTP=m
312CONFIG_NETFILTER_XT_MATCH_STRING=m
313CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
296 314
297# 315#
298# IP: Netfilter Configuration 316# IP: Netfilter Configuration
@@ -320,6 +338,11 @@ CONFIG_NETFILTER_NETLINK_LOG=m
320# CONFIG_ATALK is not set 338# CONFIG_ATALK is not set
321# CONFIG_X25 is not set 339# CONFIG_X25 is not set
322# CONFIG_LAPB is not set 340# CONFIG_LAPB is not set
341
342#
343# TIPC Configuration (EXPERIMENTAL)
344#
345# CONFIG_TIPC is not set
323# CONFIG_NET_DIVERT is not set 346# CONFIG_NET_DIVERT is not set
324# CONFIG_ECONET is not set 347# CONFIG_ECONET is not set
325# CONFIG_WAN_ROUTER is not set 348# CONFIG_WAN_ROUTER is not set
@@ -328,6 +351,7 @@ CONFIG_NETFILTER_NETLINK_LOG=m
328# QoS and/or fair queueing 351# QoS and/or fair queueing
329# 352#
330# CONFIG_NET_SCHED is not set 353# CONFIG_NET_SCHED is not set
354CONFIG_NET_CLS_ROUTE=y
331 355
332# 356#
333# Network testing 357# Network testing
@@ -340,7 +364,6 @@ CONFIG_IEEE80211=m
340# CONFIG_IEEE80211_DEBUG is not set 364# CONFIG_IEEE80211_DEBUG is not set
341CONFIG_IEEE80211_CRYPT_WEP=m 365CONFIG_IEEE80211_CRYPT_WEP=m
342CONFIG_IEEE80211_CRYPT_CCMP=m 366CONFIG_IEEE80211_CRYPT_CCMP=m
343CONFIG_IEEE80211_CRYPT_TKIP=m
344 367
345# 368#
346# Device Drivers 369# Device Drivers
@@ -403,6 +426,7 @@ CONFIG_MTD_CFI_UTIL=y
403# CONFIG_MTD_RAM is not set 426# CONFIG_MTD_RAM is not set
404# CONFIG_MTD_ROM is not set 427# CONFIG_MTD_ROM is not set
405# CONFIG_MTD_ABSENT is not set 428# CONFIG_MTD_ABSENT is not set
429# CONFIG_MTD_OBSOLETE_CHIPS is not set
406 430
407# 431#
408# Mapping drivers for chip access 432# Mapping drivers for chip access
@@ -589,6 +613,7 @@ CONFIG_MIPS_AU1X00_ENET=y
589# CONFIG_CASSINI is not set 613# CONFIG_CASSINI is not set
590# CONFIG_NET_VENDOR_3COM is not set 614# CONFIG_NET_VENDOR_3COM is not set
591# CONFIG_SMC91X is not set 615# CONFIG_SMC91X is not set
616# CONFIG_DM9000 is not set
592 617
593# 618#
594# Tulip family network device support 619# Tulip family network device support
@@ -609,6 +634,7 @@ CONFIG_MIPS_AU1X00_ENET=y
609# CONFIG_R8169 is not set 634# CONFIG_R8169 is not set
610# CONFIG_SIS190 is not set 635# CONFIG_SIS190 is not set
611# CONFIG_SKGE is not set 636# CONFIG_SKGE is not set
637# CONFIG_SKY2 is not set
612# CONFIG_SK98LIN is not set 638# CONFIG_SK98LIN is not set
613# CONFIG_TIGON3 is not set 639# CONFIG_TIGON3 is not set
614# CONFIG_BNX2 is not set 640# CONFIG_BNX2 is not set
@@ -629,8 +655,6 @@ CONFIG_MIPS_AU1X00_ENET=y
629# Wireless LAN (non-hamradio) 655# Wireless LAN (non-hamradio)
630# 656#
631# CONFIG_NET_RADIO is not set 657# CONFIG_NET_RADIO is not set
632# CONFIG_IPW_DEBUG is not set
633CONFIG_IPW2200=m
634 658
635# 659#
636# PCMCIA network device support 660# PCMCIA network device support
@@ -728,16 +752,15 @@ CONFIG_SERIAL_8250=y
728CONFIG_SERIAL_8250_CONSOLE=y 752CONFIG_SERIAL_8250_CONSOLE=y
729# CONFIG_SERIAL_8250_CS is not set 753# CONFIG_SERIAL_8250_CS is not set
730CONFIG_SERIAL_8250_NR_UARTS=4 754CONFIG_SERIAL_8250_NR_UARTS=4
755CONFIG_SERIAL_8250_RUNTIME_UARTS=4
731# CONFIG_SERIAL_8250_EXTENDED is not set 756# CONFIG_SERIAL_8250_EXTENDED is not set
732CONFIG_SERIAL_8250_AU1X00=y 757CONFIG_SERIAL_8250_AU1X00=y
733 758
734# 759#
735# Non-8250 serial port support 760# Non-8250 serial port support
736# 761#
737# CONFIG_SERIAL_AU1X00 is not set
738CONFIG_SERIAL_CORE=y 762CONFIG_SERIAL_CORE=y
739CONFIG_SERIAL_CORE_CONSOLE=y 763CONFIG_SERIAL_CORE_CONSOLE=y
740# CONFIG_SERIAL_JSM is not set
741CONFIG_UNIX98_PTYS=y 764CONFIG_UNIX98_PTYS=y
742CONFIG_LEGACY_PTYS=y 765CONFIG_LEGACY_PTYS=y
743CONFIG_LEGACY_PTY_COUNT=256 766CONFIG_LEGACY_PTY_COUNT=256
@@ -782,6 +805,12 @@ CONFIG_SYNCLINK_CS=m
782# CONFIG_I2C is not set 805# CONFIG_I2C is not set
783 806
784# 807#
808# SPI support
809#
810# CONFIG_SPI is not set
811# CONFIG_SPI_MASTER is not set
812
813#
785# Dallas's 1-wire bus 814# Dallas's 1-wire bus
786# 815#
787# CONFIG_W1 is not set 816# CONFIG_W1 is not set
@@ -874,6 +903,7 @@ CONFIG_REISERFS_FS_SECURITY=y
874# CONFIG_JFS_FS is not set 903# CONFIG_JFS_FS is not set
875CONFIG_FS_POSIX_ACL=y 904CONFIG_FS_POSIX_ACL=y
876# CONFIG_XFS_FS is not set 905# CONFIG_XFS_FS is not set
906# CONFIG_OCFS2_FS is not set
877# CONFIG_MINIX_FS is not set 907# CONFIG_MINIX_FS is not set
878# CONFIG_ROMFS_FS is not set 908# CONFIG_ROMFS_FS is not set
879CONFIG_INOTIFY=y 909CONFIG_INOTIFY=y
@@ -906,6 +936,7 @@ CONFIG_TMPFS=y
906# CONFIG_HUGETLB_PAGE is not set 936# CONFIG_HUGETLB_PAGE is not set
907CONFIG_RAMFS=y 937CONFIG_RAMFS=y
908CONFIG_RELAYFS_FS=m 938CONFIG_RELAYFS_FS=m
939# CONFIG_CONFIGFS_FS is not set
909 940
910# 941#
911# Miscellaneous filesystems 942# Miscellaneous filesystems
@@ -1010,6 +1041,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
1010# Kernel hacking 1041# Kernel hacking
1011# 1042#
1012# CONFIG_PRINTK_TIME is not set 1043# CONFIG_PRINTK_TIME is not set
1044# CONFIG_MAGIC_SYSRQ is not set
1013# CONFIG_DEBUG_KERNEL is not set 1045# CONFIG_DEBUG_KERNEL is not set
1014CONFIG_LOG_BUF_SHIFT=14 1046CONFIG_LOG_BUF_SHIFT=14
1015CONFIG_CROSSCOMPILE=y 1047CONFIG_CROSSCOMPILE=y
@@ -1064,3 +1096,7 @@ CONFIG_CRC32=y
1064CONFIG_LIBCRC32C=m 1096CONFIG_LIBCRC32C=m
1065CONFIG_ZLIB_INFLATE=m 1097CONFIG_ZLIB_INFLATE=m
1066CONFIG_ZLIB_DEFLATE=m 1098CONFIG_ZLIB_DEFLATE=m
1099CONFIG_TEXTSEARCH=y
1100CONFIG_TEXTSEARCH_KMP=m
1101CONFIG_TEXTSEARCH_BM=m
1102CONFIG_TEXTSEARCH_FSM=m
diff --git a/arch/mips/configs/pb1550_defconfig b/arch/mips/configs/pb1550_defconfig
index 3d694cd68d38..adbf997b540e 100644
--- a/arch/mips/configs/pb1550_defconfig
+++ b/arch/mips/configs/pb1550_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:52 2005 4# Fri Jan 27 15:40:25 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -152,26 +152,29 @@ CONFIG_SYSVIPC=y
152# CONFIG_BSD_PROCESS_ACCT is not set 152# CONFIG_BSD_PROCESS_ACCT is not set
153CONFIG_SYSCTL=y 153CONFIG_SYSCTL=y
154# CONFIG_AUDIT is not set 154# CONFIG_AUDIT is not set
155CONFIG_HOTPLUG=y
156CONFIG_KOBJECT_UEVENT=y
157# CONFIG_IKCONFIG is not set 155# CONFIG_IKCONFIG is not set
158CONFIG_INITRAMFS_SOURCE="" 156CONFIG_INITRAMFS_SOURCE=""
157# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
159CONFIG_EMBEDDED=y 158CONFIG_EMBEDDED=y
160CONFIG_KALLSYMS=y 159CONFIG_KALLSYMS=y
161# CONFIG_KALLSYMS_EXTRA_PASS is not set 160# CONFIG_KALLSYMS_EXTRA_PASS is not set
161CONFIG_HOTPLUG=y
162CONFIG_PRINTK=y 162CONFIG_PRINTK=y
163CONFIG_BUG=y 163CONFIG_BUG=y
164CONFIG_ELF_CORE=y
164CONFIG_BASE_FULL=y 165CONFIG_BASE_FULL=y
165CONFIG_FUTEX=y 166CONFIG_FUTEX=y
166CONFIG_EPOLL=y 167CONFIG_EPOLL=y
167# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
168CONFIG_SHMEM=y 168CONFIG_SHMEM=y
169CONFIG_CC_ALIGN_FUNCTIONS=0 169CONFIG_CC_ALIGN_FUNCTIONS=0
170CONFIG_CC_ALIGN_LABELS=0 170CONFIG_CC_ALIGN_LABELS=0
171CONFIG_CC_ALIGN_LOOPS=0 171CONFIG_CC_ALIGN_LOOPS=0
172CONFIG_CC_ALIGN_JUMPS=0 172CONFIG_CC_ALIGN_JUMPS=0
173CONFIG_SLAB=y
173# CONFIG_TINY_SHMEM is not set 174# CONFIG_TINY_SHMEM is not set
174CONFIG_BASE_SMALL=0 175CONFIG_BASE_SMALL=0
176# CONFIG_SLOB is not set
177CONFIG_OBSOLETE_INTERMODULE=y
175 178
176# 179#
177# Loadable module support 180# Loadable module support
@@ -293,6 +296,21 @@ CONFIG_NETFILTER_NETLINK=m
293CONFIG_NETFILTER_NETLINK_QUEUE=m 296CONFIG_NETFILTER_NETLINK_QUEUE=m
294CONFIG_NETFILTER_NETLINK_LOG=m 297CONFIG_NETFILTER_NETLINK_LOG=m
295# CONFIG_NF_CONNTRACK is not set 298# CONFIG_NF_CONNTRACK is not set
299CONFIG_NETFILTER_XTABLES=m
300CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
301CONFIG_NETFILTER_XT_TARGET_MARK=m
302CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
303CONFIG_NETFILTER_XT_MATCH_COMMENT=m
304CONFIG_NETFILTER_XT_MATCH_DCCP=m
305CONFIG_NETFILTER_XT_MATCH_LENGTH=m
306CONFIG_NETFILTER_XT_MATCH_LIMIT=m
307CONFIG_NETFILTER_XT_MATCH_MAC=m
308CONFIG_NETFILTER_XT_MATCH_MARK=m
309CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
310CONFIG_NETFILTER_XT_MATCH_REALM=m
311CONFIG_NETFILTER_XT_MATCH_SCTP=m
312CONFIG_NETFILTER_XT_MATCH_STRING=m
313CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
296 314
297# 315#
298# IP: Netfilter Configuration 316# IP: Netfilter Configuration
@@ -320,6 +338,11 @@ CONFIG_NETFILTER_NETLINK_LOG=m
320# CONFIG_ATALK is not set 338# CONFIG_ATALK is not set
321# CONFIG_X25 is not set 339# CONFIG_X25 is not set
322# CONFIG_LAPB is not set 340# CONFIG_LAPB is not set
341
342#
343# TIPC Configuration (EXPERIMENTAL)
344#
345# CONFIG_TIPC is not set
323# CONFIG_NET_DIVERT is not set 346# CONFIG_NET_DIVERT is not set
324# CONFIG_ECONET is not set 347# CONFIG_ECONET is not set
325# CONFIG_WAN_ROUTER is not set 348# CONFIG_WAN_ROUTER is not set
@@ -328,6 +351,7 @@ CONFIG_NETFILTER_NETLINK_LOG=m
328# QoS and/or fair queueing 351# QoS and/or fair queueing
329# 352#
330# CONFIG_NET_SCHED is not set 353# CONFIG_NET_SCHED is not set
354CONFIG_NET_CLS_ROUTE=y
331 355
332# 356#
333# Network testing 357# Network testing
@@ -340,7 +364,6 @@ CONFIG_IEEE80211=m
340# CONFIG_IEEE80211_DEBUG is not set 364# CONFIG_IEEE80211_DEBUG is not set
341CONFIG_IEEE80211_CRYPT_WEP=m 365CONFIG_IEEE80211_CRYPT_WEP=m
342CONFIG_IEEE80211_CRYPT_CCMP=m 366CONFIG_IEEE80211_CRYPT_CCMP=m
343CONFIG_IEEE80211_CRYPT_TKIP=m
344 367
345# 368#
346# Device Drivers 369# Device Drivers
@@ -403,6 +426,7 @@ CONFIG_MTD_CFI_UTIL=y
403# CONFIG_MTD_RAM is not set 426# CONFIG_MTD_RAM is not set
404# CONFIG_MTD_ROM is not set 427# CONFIG_MTD_ROM is not set
405# CONFIG_MTD_ABSENT is not set 428# CONFIG_MTD_ABSENT is not set
429# CONFIG_MTD_OBSOLETE_CHIPS is not set
406 430
407# 431#
408# Mapping drivers for chip access 432# Mapping drivers for chip access
@@ -589,6 +613,7 @@ CONFIG_MIPS_AU1X00_ENET=y
589# CONFIG_CASSINI is not set 613# CONFIG_CASSINI is not set
590# CONFIG_NET_VENDOR_3COM is not set 614# CONFIG_NET_VENDOR_3COM is not set
591# CONFIG_SMC91X is not set 615# CONFIG_SMC91X is not set
616# CONFIG_DM9000 is not set
592 617
593# 618#
594# Tulip family network device support 619# Tulip family network device support
@@ -609,6 +634,7 @@ CONFIG_MIPS_AU1X00_ENET=y
609# CONFIG_R8169 is not set 634# CONFIG_R8169 is not set
610# CONFIG_SIS190 is not set 635# CONFIG_SIS190 is not set
611# CONFIG_SKGE is not set 636# CONFIG_SKGE is not set
637# CONFIG_SKY2 is not set
612# CONFIG_SK98LIN is not set 638# CONFIG_SK98LIN is not set
613# CONFIG_TIGON3 is not set 639# CONFIG_TIGON3 is not set
614# CONFIG_BNX2 is not set 640# CONFIG_BNX2 is not set
@@ -629,8 +655,6 @@ CONFIG_MIPS_AU1X00_ENET=y
629# Wireless LAN (non-hamradio) 655# Wireless LAN (non-hamradio)
630# 656#
631# CONFIG_NET_RADIO is not set 657# CONFIG_NET_RADIO is not set
632# CONFIG_IPW_DEBUG is not set
633CONFIG_IPW2200=m
634 658
635# 659#
636# PCMCIA network device support 660# PCMCIA network device support
@@ -720,16 +744,15 @@ CONFIG_SERIAL_8250=y
720CONFIG_SERIAL_8250_CONSOLE=y 744CONFIG_SERIAL_8250_CONSOLE=y
721# CONFIG_SERIAL_8250_CS is not set 745# CONFIG_SERIAL_8250_CS is not set
722CONFIG_SERIAL_8250_NR_UARTS=4 746CONFIG_SERIAL_8250_NR_UARTS=4
747CONFIG_SERIAL_8250_RUNTIME_UARTS=4
723# CONFIG_SERIAL_8250_EXTENDED is not set 748# CONFIG_SERIAL_8250_EXTENDED is not set
724CONFIG_SERIAL_8250_AU1X00=y 749CONFIG_SERIAL_8250_AU1X00=y
725 750
726# 751#
727# Non-8250 serial port support 752# Non-8250 serial port support
728# 753#
729# CONFIG_SERIAL_AU1X00 is not set
730CONFIG_SERIAL_CORE=y 754CONFIG_SERIAL_CORE=y
731CONFIG_SERIAL_CORE_CONSOLE=y 755CONFIG_SERIAL_CORE_CONSOLE=y
732# CONFIG_SERIAL_JSM is not set
733CONFIG_UNIX98_PTYS=y 756CONFIG_UNIX98_PTYS=y
734CONFIG_LEGACY_PTYS=y 757CONFIG_LEGACY_PTYS=y
735CONFIG_LEGACY_PTY_COUNT=256 758CONFIG_LEGACY_PTY_COUNT=256
@@ -774,6 +797,12 @@ CONFIG_SYNCLINK_CS=m
774# CONFIG_I2C is not set 797# CONFIG_I2C is not set
775 798
776# 799#
800# SPI support
801#
802# CONFIG_SPI is not set
803# CONFIG_SPI_MASTER is not set
804
805#
777# Dallas's 1-wire bus 806# Dallas's 1-wire bus
778# 807#
779# CONFIG_W1 is not set 808# CONFIG_W1 is not set
@@ -866,6 +895,7 @@ CONFIG_REISERFS_FS_SECURITY=y
866# CONFIG_JFS_FS is not set 895# CONFIG_JFS_FS is not set
867CONFIG_FS_POSIX_ACL=y 896CONFIG_FS_POSIX_ACL=y
868# CONFIG_XFS_FS is not set 897# CONFIG_XFS_FS is not set
898# CONFIG_OCFS2_FS is not set
869# CONFIG_MINIX_FS is not set 899# CONFIG_MINIX_FS is not set
870# CONFIG_ROMFS_FS is not set 900# CONFIG_ROMFS_FS is not set
871CONFIG_INOTIFY=y 901CONFIG_INOTIFY=y
@@ -898,6 +928,7 @@ CONFIG_TMPFS=y
898# CONFIG_HUGETLB_PAGE is not set 928# CONFIG_HUGETLB_PAGE is not set
899CONFIG_RAMFS=y 929CONFIG_RAMFS=y
900CONFIG_RELAYFS_FS=m 930CONFIG_RELAYFS_FS=m
931# CONFIG_CONFIGFS_FS is not set
901 932
902# 933#
903# Miscellaneous filesystems 934# Miscellaneous filesystems
@@ -1002,6 +1033,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
1002# Kernel hacking 1033# Kernel hacking
1003# 1034#
1004# CONFIG_PRINTK_TIME is not set 1035# CONFIG_PRINTK_TIME is not set
1036# CONFIG_MAGIC_SYSRQ is not set
1005# CONFIG_DEBUG_KERNEL is not set 1037# CONFIG_DEBUG_KERNEL is not set
1006CONFIG_LOG_BUF_SHIFT=14 1038CONFIG_LOG_BUF_SHIFT=14
1007CONFIG_CROSSCOMPILE=y 1039CONFIG_CROSSCOMPILE=y
@@ -1056,3 +1088,7 @@ CONFIG_CRC32=y
1056CONFIG_LIBCRC32C=m 1088CONFIG_LIBCRC32C=m
1057CONFIG_ZLIB_INFLATE=m 1089CONFIG_ZLIB_INFLATE=m
1058CONFIG_ZLIB_DEFLATE=m 1090CONFIG_ZLIB_DEFLATE=m
1091CONFIG_TEXTSEARCH=y
1092CONFIG_TEXTSEARCH_KMP=m
1093CONFIG_TEXTSEARCH_BM=m
1094CONFIG_TEXTSEARCH_FSM=m
diff --git a/arch/mips/configs/pnx8550-jbs_defconfig b/arch/mips/configs/pnx8550-jbs_defconfig
index fba624a792a9..b5db700450ba 100644
--- a/arch/mips/configs/pnx8550-jbs_defconfig
+++ b/arch/mips/configs/pnx8550-jbs_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:54 2005 4# Fri Jan 27 15:40:26 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -151,28 +151,30 @@ CONFIG_SYSVIPC=y
151# CONFIG_BSD_PROCESS_ACCT is not set 151# CONFIG_BSD_PROCESS_ACCT is not set
152CONFIG_SYSCTL=y 152CONFIG_SYSCTL=y
153# CONFIG_AUDIT is not set 153# CONFIG_AUDIT is not set
154# CONFIG_HOTPLUG is not set
155CONFIG_KOBJECT_UEVENT=y
156CONFIG_IKCONFIG=y 154CONFIG_IKCONFIG=y
157CONFIG_IKCONFIG_PROC=y 155CONFIG_IKCONFIG_PROC=y
158CONFIG_INITRAMFS_SOURCE="" 156CONFIG_INITRAMFS_SOURCE=""
157# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
159CONFIG_EMBEDDED=y 158CONFIG_EMBEDDED=y
160CONFIG_KALLSYMS=y 159CONFIG_KALLSYMS=y
161# CONFIG_KALLSYMS_ALL is not set 160# CONFIG_KALLSYMS_ALL is not set
162# CONFIG_KALLSYMS_EXTRA_PASS is not set 161# CONFIG_KALLSYMS_EXTRA_PASS is not set
162CONFIG_HOTPLUG=y
163CONFIG_PRINTK=y 163CONFIG_PRINTK=y
164CONFIG_BUG=y 164CONFIG_BUG=y
165CONFIG_ELF_CORE=y
165CONFIG_BASE_FULL=y 166CONFIG_BASE_FULL=y
166CONFIG_FUTEX=y 167CONFIG_FUTEX=y
167CONFIG_EPOLL=y 168CONFIG_EPOLL=y
168# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
169CONFIG_SHMEM=y 169CONFIG_SHMEM=y
170CONFIG_CC_ALIGN_FUNCTIONS=0 170CONFIG_CC_ALIGN_FUNCTIONS=0
171CONFIG_CC_ALIGN_LABELS=0 171CONFIG_CC_ALIGN_LABELS=0
172CONFIG_CC_ALIGN_LOOPS=0 172CONFIG_CC_ALIGN_LOOPS=0
173CONFIG_CC_ALIGN_JUMPS=0 173CONFIG_CC_ALIGN_JUMPS=0
174CONFIG_SLAB=y
174# CONFIG_TINY_SHMEM is not set 175# CONFIG_TINY_SHMEM is not set
175CONFIG_BASE_SMALL=0 176CONFIG_BASE_SMALL=0
177# CONFIG_SLOB is not set
176 178
177# 179#
178# Loadable module support 180# Loadable module support
@@ -281,6 +283,11 @@ CONFIG_TCP_CONG_BIC=y
281# CONFIG_ATALK is not set 283# CONFIG_ATALK is not set
282# CONFIG_X25 is not set 284# CONFIG_X25 is not set
283# CONFIG_LAPB is not set 285# CONFIG_LAPB is not set
286
287#
288# TIPC Configuration (EXPERIMENTAL)
289#
290# CONFIG_TIPC is not set
284# CONFIG_NET_DIVERT is not set 291# CONFIG_NET_DIVERT is not set
285# CONFIG_ECONET is not set 292# CONFIG_ECONET is not set
286# CONFIG_WAN_ROUTER is not set 293# CONFIG_WAN_ROUTER is not set
@@ -308,7 +315,7 @@ CONFIG_TCP_CONG_BIC=y
308# 315#
309CONFIG_STANDALONE=y 316CONFIG_STANDALONE=y
310CONFIG_PREVENT_FIRMWARE_BUILD=y 317CONFIG_PREVENT_FIRMWARE_BUILD=y
311# CONFIG_FW_LOADER is not set 318CONFIG_FW_LOADER=y
312# CONFIG_DEBUG_DRIVER is not set 319# CONFIG_DEBUG_DRIVER is not set
313 320
314# 321#
@@ -435,7 +442,7 @@ CONFIG_SCSI_CONSTANTS=y
435# SCSI Transport Attributes 442# SCSI Transport Attributes
436# 443#
437# CONFIG_SCSI_SPI_ATTRS is not set 444# CONFIG_SCSI_SPI_ATTRS is not set
438# CONFIG_SCSI_FC_ATTRS is not set 445CONFIG_SCSI_FC_ATTRS=y
439CONFIG_SCSI_ISCSI_ATTRS=m 446CONFIG_SCSI_ISCSI_ATTRS=m
440# CONFIG_SCSI_SAS_ATTRS is not set 447# CONFIG_SCSI_SAS_ATTRS is not set
441 448
@@ -464,13 +471,7 @@ CONFIG_ISCSI_TCP=m
464# CONFIG_SCSI_IPR is not set 471# CONFIG_SCSI_IPR is not set
465# CONFIG_SCSI_QLOGIC_FC is not set 472# CONFIG_SCSI_QLOGIC_FC is not set
466# CONFIG_SCSI_QLOGIC_1280 is not set 473# CONFIG_SCSI_QLOGIC_1280 is not set
467CONFIG_SCSI_QLA2XXX=y 474# CONFIG_SCSI_QLA_FC is not set
468# CONFIG_SCSI_QLA21XX is not set
469# CONFIG_SCSI_QLA22XX is not set
470# CONFIG_SCSI_QLA2300 is not set
471# CONFIG_SCSI_QLA2322 is not set
472# CONFIG_SCSI_QLA6312 is not set
473# CONFIG_SCSI_QLA24XX is not set
474# CONFIG_SCSI_LPFC is not set 475# CONFIG_SCSI_LPFC is not set
475# CONFIG_SCSI_DC395x is not set 476# CONFIG_SCSI_DC395x is not set
476# CONFIG_SCSI_DC390T is not set 477# CONFIG_SCSI_DC390T is not set
@@ -528,6 +529,7 @@ CONFIG_MII=y
528# CONFIG_SUNGEM is not set 529# CONFIG_SUNGEM is not set
529# CONFIG_CASSINI is not set 530# CONFIG_CASSINI is not set
530# CONFIG_NET_VENDOR_3COM is not set 531# CONFIG_NET_VENDOR_3COM is not set
532# CONFIG_DM9000 is not set
531 533
532# 534#
533# Tulip family network device support 535# Tulip family network device support
@@ -571,6 +573,7 @@ CONFIG_8139TOO_8129=y
571# CONFIG_R8169 is not set 573# CONFIG_R8169 is not set
572# CONFIG_SIS190 is not set 574# CONFIG_SIS190 is not set
573# CONFIG_SKGE is not set 575# CONFIG_SKGE is not set
576# CONFIG_SKY2 is not set
574# CONFIG_SK98LIN is not set 577# CONFIG_SK98LIN is not set
575# CONFIG_VIA_VELOCITY is not set 578# CONFIG_VIA_VELOCITY is not set
576# CONFIG_TIGON3 is not set 579# CONFIG_TIGON3 is not set
@@ -668,7 +671,6 @@ CONFIG_HW_CONSOLE=y
668# Non-8250 serial port support 671# Non-8250 serial port support
669# 672#
670# CONFIG_SERIAL_IP3106 is not set 673# CONFIG_SERIAL_IP3106 is not set
671# CONFIG_SERIAL_JSM is not set
672CONFIG_UNIX98_PTYS=y 674CONFIG_UNIX98_PTYS=y
673CONFIG_LEGACY_PTYS=y 675CONFIG_LEGACY_PTYS=y
674CONFIG_LEGACY_PTY_COUNT=256 676CONFIG_LEGACY_PTY_COUNT=256
@@ -706,6 +708,12 @@ CONFIG_LEGACY_PTY_COUNT=256
706# CONFIG_I2C is not set 708# CONFIG_I2C is not set
707 709
708# 710#
711# SPI support
712#
713# CONFIG_SPI is not set
714# CONFIG_SPI_MASTER is not set
715
716#
709# Dallas's 1-wire bus 717# Dallas's 1-wire bus
710# 718#
711# CONFIG_W1 is not set 719# CONFIG_W1 is not set
@@ -801,6 +809,8 @@ CONFIG_USB_STORAGE_USBAT=y
801CONFIG_USB_STORAGE_SDDR09=y 809CONFIG_USB_STORAGE_SDDR09=y
802CONFIG_USB_STORAGE_SDDR55=y 810CONFIG_USB_STORAGE_SDDR55=y
803CONFIG_USB_STORAGE_JUMPSHOT=y 811CONFIG_USB_STORAGE_JUMPSHOT=y
812# CONFIG_USB_STORAGE_ALAUDA is not set
813# CONFIG_USB_LIBUSUAL is not set
804 814
805# 815#
806# USB Input Devices 816# USB Input Devices
@@ -823,6 +833,7 @@ CONFIG_USB_STORAGE_JUMPSHOT=y
823# CONFIG_USB_YEALINK is not set 833# CONFIG_USB_YEALINK is not set
824# CONFIG_USB_XPAD is not set 834# CONFIG_USB_XPAD is not set
825# CONFIG_USB_ATI_REMOTE is not set 835# CONFIG_USB_ATI_REMOTE is not set
836# CONFIG_USB_ATI_REMOTE2 is not set
826# CONFIG_USB_KEYSPAN_REMOTE is not set 837# CONFIG_USB_KEYSPAN_REMOTE is not set
827# CONFIG_USB_APPLETOUCH is not set 838# CONFIG_USB_APPLETOUCH is not set
828 839
@@ -906,11 +917,11 @@ CONFIG_EXT2_FS=y
906# CONFIG_EXT2_FS_XATTR is not set 917# CONFIG_EXT2_FS_XATTR is not set
907# CONFIG_EXT2_FS_XIP is not set 918# CONFIG_EXT2_FS_XIP is not set
908# CONFIG_EXT3_FS is not set 919# CONFIG_EXT3_FS is not set
909# CONFIG_JBD is not set
910# CONFIG_REISERFS_FS is not set 920# CONFIG_REISERFS_FS is not set
911# CONFIG_JFS_FS is not set 921# CONFIG_JFS_FS is not set
912# CONFIG_FS_POSIX_ACL is not set 922# CONFIG_FS_POSIX_ACL is not set
913# CONFIG_XFS_FS is not set 923# CONFIG_XFS_FS is not set
924# CONFIG_OCFS2_FS is not set
914# CONFIG_MINIX_FS is not set 925# CONFIG_MINIX_FS is not set
915# CONFIG_ROMFS_FS is not set 926# CONFIG_ROMFS_FS is not set
916CONFIG_INOTIFY=y 927CONFIG_INOTIFY=y
@@ -946,6 +957,7 @@ CONFIG_TMPFS=y
946# CONFIG_HUGETLB_PAGE is not set 957# CONFIG_HUGETLB_PAGE is not set
947CONFIG_RAMFS=y 958CONFIG_RAMFS=y
948# CONFIG_RELAYFS_FS is not set 959# CONFIG_RELAYFS_FS is not set
960# CONFIG_CONFIGFS_FS is not set
949 961
950# 962#
951# Miscellaneous filesystems 963# Miscellaneous filesystems
@@ -1049,18 +1061,20 @@ CONFIG_NLS_DEFAULT="iso8859-1"
1049# Kernel hacking 1061# Kernel hacking
1050# 1062#
1051# CONFIG_PRINTK_TIME is not set 1063# CONFIG_PRINTK_TIME is not set
1052CONFIG_DEBUG_KERNEL=y
1053CONFIG_MAGIC_SYSRQ=y 1064CONFIG_MAGIC_SYSRQ=y
1065CONFIG_DEBUG_KERNEL=y
1054CONFIG_LOG_BUF_SHIFT=14 1066CONFIG_LOG_BUF_SHIFT=14
1055CONFIG_DETECT_SOFTLOCKUP=y 1067CONFIG_DETECT_SOFTLOCKUP=y
1056# CONFIG_SCHEDSTATS is not set 1068# CONFIG_SCHEDSTATS is not set
1057CONFIG_DEBUG_SLAB=y 1069CONFIG_DEBUG_SLAB=y
1070CONFIG_DEBUG_MUTEXES=y
1058# CONFIG_DEBUG_SPINLOCK is not set 1071# CONFIG_DEBUG_SPINLOCK is not set
1059# CONFIG_DEBUG_SPINLOCK_SLEEP is not set 1072# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
1060# CONFIG_DEBUG_KOBJECT is not set 1073# CONFIG_DEBUG_KOBJECT is not set
1061# CONFIG_DEBUG_INFO is not set 1074# CONFIG_DEBUG_INFO is not set
1062# CONFIG_DEBUG_FS is not set 1075# CONFIG_DEBUG_FS is not set
1063# CONFIG_DEBUG_VM is not set 1076# CONFIG_DEBUG_VM is not set
1077CONFIG_FORCED_INLINING=y
1064# CONFIG_RCU_TORTURE_TEST is not set 1078# CONFIG_RCU_TORTURE_TEST is not set
1065CONFIG_CROSSCOMPILE=y 1079CONFIG_CROSSCOMPILE=y
1066CONFIG_CMDLINE="console=ttyS1,38400n8 kgdb=ttyS0 root=/dev/nfs ip=bootp" 1080CONFIG_CMDLINE="console=ttyS1,38400n8 kgdb=ttyS0 root=/dev/nfs ip=bootp"
diff --git a/arch/mips/configs/pnx8550-v2pci_defconfig b/arch/mips/configs/pnx8550-v2pci_defconfig
index 4c650e708133..4187287f0763 100644
--- a/arch/mips/configs/pnx8550-v2pci_defconfig
+++ b/arch/mips/configs/pnx8550-v2pci_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:06:58 2005 4# Fri Jan 27 15:40:28 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -152,27 +152,29 @@ CONFIG_SYSVIPC=y
152# CONFIG_BSD_PROCESS_ACCT is not set 152# CONFIG_BSD_PROCESS_ACCT is not set
153CONFIG_SYSCTL=y 153CONFIG_SYSCTL=y
154# CONFIG_AUDIT is not set 154# CONFIG_AUDIT is not set
155# CONFIG_HOTPLUG is not set
156CONFIG_KOBJECT_UEVENT=y
157CONFIG_IKCONFIG=y 155CONFIG_IKCONFIG=y
158CONFIG_IKCONFIG_PROC=y 156CONFIG_IKCONFIG_PROC=y
159CONFIG_INITRAMFS_SOURCE="" 157CONFIG_INITRAMFS_SOURCE=""
158# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
160CONFIG_EMBEDDED=y 159CONFIG_EMBEDDED=y
161CONFIG_KALLSYMS=y 160CONFIG_KALLSYMS=y
162# CONFIG_KALLSYMS_EXTRA_PASS is not set 161# CONFIG_KALLSYMS_EXTRA_PASS is not set
162CONFIG_HOTPLUG=y
163CONFIG_PRINTK=y 163CONFIG_PRINTK=y
164CONFIG_BUG=y 164CONFIG_BUG=y
165CONFIG_ELF_CORE=y
165CONFIG_BASE_FULL=y 166CONFIG_BASE_FULL=y
166CONFIG_FUTEX=y 167CONFIG_FUTEX=y
167CONFIG_EPOLL=y 168CONFIG_EPOLL=y
168# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
169CONFIG_SHMEM=y 169CONFIG_SHMEM=y
170CONFIG_CC_ALIGN_FUNCTIONS=0 170CONFIG_CC_ALIGN_FUNCTIONS=0
171CONFIG_CC_ALIGN_LABELS=0 171CONFIG_CC_ALIGN_LABELS=0
172CONFIG_CC_ALIGN_LOOPS=0 172CONFIG_CC_ALIGN_LOOPS=0
173CONFIG_CC_ALIGN_JUMPS=0 173CONFIG_CC_ALIGN_JUMPS=0
174CONFIG_SLAB=y
174# CONFIG_TINY_SHMEM is not set 175# CONFIG_TINY_SHMEM is not set
175CONFIG_BASE_SMALL=0 176CONFIG_BASE_SMALL=0
177# CONFIG_SLOB is not set
176 178
177# 179#
178# Loadable module support 180# Loadable module support
@@ -279,6 +281,21 @@ CONFIG_NETFILTER=y
279# 281#
280# CONFIG_NETFILTER_NETLINK is not set 282# CONFIG_NETFILTER_NETLINK is not set
281# CONFIG_NF_CONNTRACK is not set 283# CONFIG_NF_CONNTRACK is not set
284CONFIG_NETFILTER_XTABLES=m
285CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
286CONFIG_NETFILTER_XT_TARGET_MARK=m
287CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
288CONFIG_NETFILTER_XT_MATCH_COMMENT=m
289CONFIG_NETFILTER_XT_MATCH_DCCP=m
290CONFIG_NETFILTER_XT_MATCH_LENGTH=m
291CONFIG_NETFILTER_XT_MATCH_LIMIT=m
292CONFIG_NETFILTER_XT_MATCH_MAC=m
293CONFIG_NETFILTER_XT_MATCH_MARK=m
294CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
295CONFIG_NETFILTER_XT_MATCH_REALM=m
296CONFIG_NETFILTER_XT_MATCH_SCTP=m
297CONFIG_NETFILTER_XT_MATCH_STRING=m
298CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
282 299
283# 300#
284# IP: Netfilter Configuration 301# IP: Netfilter Configuration
@@ -312,6 +329,11 @@ CONFIG_NETFILTER=y
312# CONFIG_ATALK is not set 329# CONFIG_ATALK is not set
313# CONFIG_X25 is not set 330# CONFIG_X25 is not set
314# CONFIG_LAPB is not set 331# CONFIG_LAPB is not set
332
333#
334# TIPC Configuration (EXPERIMENTAL)
335#
336# CONFIG_TIPC is not set
315# CONFIG_NET_DIVERT is not set 337# CONFIG_NET_DIVERT is not set
316# CONFIG_ECONET is not set 338# CONFIG_ECONET is not set
317# CONFIG_WAN_ROUTER is not set 339# CONFIG_WAN_ROUTER is not set
@@ -320,6 +342,7 @@ CONFIG_NETFILTER=y
320# QoS and/or fair queueing 342# QoS and/or fair queueing
321# 343#
322# CONFIG_NET_SCHED is not set 344# CONFIG_NET_SCHED is not set
345CONFIG_NET_CLS_ROUTE=y
323 346
324# 347#
325# Network testing 348# Network testing
@@ -339,7 +362,7 @@ CONFIG_NETFILTER=y
339# 362#
340CONFIG_STANDALONE=y 363CONFIG_STANDALONE=y
341CONFIG_PREVENT_FIRMWARE_BUILD=y 364CONFIG_PREVENT_FIRMWARE_BUILD=y
342# CONFIG_FW_LOADER is not set 365CONFIG_FW_LOADER=y
343 366
344# 367#
345# Connector - unified userspace <-> kernelspace linker 368# Connector - unified userspace <-> kernelspace linker
@@ -466,7 +489,7 @@ CONFIG_BLK_DEV_SD=y
466# SCSI Transport Attributes 489# SCSI Transport Attributes
467# 490#
468CONFIG_SCSI_SPI_ATTRS=m 491CONFIG_SCSI_SPI_ATTRS=m
469# CONFIG_SCSI_FC_ATTRS is not set 492CONFIG_SCSI_FC_ATTRS=y
470CONFIG_SCSI_ISCSI_ATTRS=m 493CONFIG_SCSI_ISCSI_ATTRS=m
471# CONFIG_SCSI_SAS_ATTRS is not set 494# CONFIG_SCSI_SAS_ATTRS is not set
472 495
@@ -500,13 +523,7 @@ CONFIG_AIC7XXX_DEBUG_MASK=0
500# CONFIG_SCSI_IPR is not set 523# CONFIG_SCSI_IPR is not set
501# CONFIG_SCSI_QLOGIC_FC is not set 524# CONFIG_SCSI_QLOGIC_FC is not set
502# CONFIG_SCSI_QLOGIC_1280 is not set 525# CONFIG_SCSI_QLOGIC_1280 is not set
503CONFIG_SCSI_QLA2XXX=y 526# CONFIG_SCSI_QLA_FC is not set
504# CONFIG_SCSI_QLA21XX is not set
505# CONFIG_SCSI_QLA22XX is not set
506# CONFIG_SCSI_QLA2300 is not set
507# CONFIG_SCSI_QLA2322 is not set
508# CONFIG_SCSI_QLA6312 is not set
509# CONFIG_SCSI_QLA24XX is not set
510# CONFIG_SCSI_LPFC is not set 527# CONFIG_SCSI_LPFC is not set
511# CONFIG_SCSI_DC395x is not set 528# CONFIG_SCSI_DC395x is not set
512# CONFIG_SCSI_DC390T is not set 529# CONFIG_SCSI_DC390T is not set
@@ -564,6 +581,7 @@ CONFIG_MII=y
564# CONFIG_SUNGEM is not set 581# CONFIG_SUNGEM is not set
565# CONFIG_CASSINI is not set 582# CONFIG_CASSINI is not set
566# CONFIG_NET_VENDOR_3COM is not set 583# CONFIG_NET_VENDOR_3COM is not set
584# CONFIG_DM9000 is not set
567 585
568# 586#
569# Tulip family network device support 587# Tulip family network device support
@@ -607,6 +625,7 @@ CONFIG_8139TOO=y
607# CONFIG_R8169 is not set 625# CONFIG_R8169 is not set
608# CONFIG_SIS190 is not set 626# CONFIG_SIS190 is not set
609# CONFIG_SKGE is not set 627# CONFIG_SKGE is not set
628# CONFIG_SKY2 is not set
610# CONFIG_SK98LIN is not set 629# CONFIG_SK98LIN is not set
611# CONFIG_VIA_VELOCITY is not set 630# CONFIG_VIA_VELOCITY is not set
612# CONFIG_TIGON3 is not set 631# CONFIG_TIGON3 is not set
@@ -721,6 +740,7 @@ CONFIG_SERIAL_NONSTANDARD=y
721# CONFIG_MOXA_SMARTIO is not set 740# CONFIG_MOXA_SMARTIO is not set
722# CONFIG_ISI is not set 741# CONFIG_ISI is not set
723# CONFIG_SYNCLINKMP is not set 742# CONFIG_SYNCLINKMP is not set
743# CONFIG_SYNCLINK_GT is not set
724# CONFIG_N_HDLC is not set 744# CONFIG_N_HDLC is not set
725# CONFIG_RISCOM8 is not set 745# CONFIG_RISCOM8 is not set
726# CONFIG_SPECIALIX is not set 746# CONFIG_SPECIALIX is not set
@@ -737,7 +757,6 @@ CONFIG_SERIAL_NONSTANDARD=y
737# Non-8250 serial port support 757# Non-8250 serial port support
738# 758#
739# CONFIG_SERIAL_IP3106 is not set 759# CONFIG_SERIAL_IP3106 is not set
740# CONFIG_SERIAL_JSM is not set
741CONFIG_UNIX98_PTYS=y 760CONFIG_UNIX98_PTYS=y
742CONFIG_LEGACY_PTYS=y 761CONFIG_LEGACY_PTYS=y
743CONFIG_LEGACY_PTY_COUNT=256 762CONFIG_LEGACY_PTY_COUNT=256
@@ -825,6 +844,12 @@ CONFIG_I2C_ALGOBIT=m
825# CONFIG_I2C_DEBUG_CHIP is not set 844# CONFIG_I2C_DEBUG_CHIP is not set
826 845
827# 846#
847# SPI support
848#
849# CONFIG_SPI is not set
850# CONFIG_SPI_MASTER is not set
851
852#
828# Dallas's 1-wire bus 853# Dallas's 1-wire bus
829# 854#
830# CONFIG_W1 is not set 855# CONFIG_W1 is not set
@@ -863,6 +888,7 @@ CONFIG_HWMON=y
863# CONFIG_SENSORS_SMSC47M1 is not set 888# CONFIG_SENSORS_SMSC47M1 is not set
864# CONFIG_SENSORS_SMSC47B397 is not set 889# CONFIG_SENSORS_SMSC47B397 is not set
865# CONFIG_SENSORS_VIA686A is not set 890# CONFIG_SENSORS_VIA686A is not set
891# CONFIG_SENSORS_VT8231 is not set
866# CONFIG_SENSORS_W83781D is not set 892# CONFIG_SENSORS_W83781D is not set
867# CONFIG_SENSORS_W83792D is not set 893# CONFIG_SENSORS_W83792D is not set
868# CONFIG_SENSORS_W83L785TS is not set 894# CONFIG_SENSORS_W83L785TS is not set
@@ -918,7 +944,6 @@ CONFIG_FB=y
918# CONFIG_FB_3DFX is not set 944# CONFIG_FB_3DFX is not set
919# CONFIG_FB_VOODOO1 is not set 945# CONFIG_FB_VOODOO1 is not set
920# CONFIG_FB_SMIVGX is not set 946# CONFIG_FB_SMIVGX is not set
921# CONFIG_FB_CYBLA is not set
922# CONFIG_FB_TRIDENT is not set 947# CONFIG_FB_TRIDENT is not set
923# CONFIG_FB_VIRTUAL is not set 948# CONFIG_FB_VIRTUAL is not set
924 949
@@ -988,13 +1013,16 @@ CONFIG_USB_STORAGE=y
988# CONFIG_USB_STORAGE_SDDR09 is not set 1013# CONFIG_USB_STORAGE_SDDR09 is not set
989# CONFIG_USB_STORAGE_SDDR55 is not set 1014# CONFIG_USB_STORAGE_SDDR55 is not set
990# CONFIG_USB_STORAGE_JUMPSHOT is not set 1015# CONFIG_USB_STORAGE_JUMPSHOT is not set
1016# CONFIG_USB_STORAGE_ALAUDA is not set
991# CONFIG_USB_STORAGE_ONETOUCH is not set 1017# CONFIG_USB_STORAGE_ONETOUCH is not set
1018# CONFIG_USB_LIBUSUAL is not set
992 1019
993# 1020#
994# USB Input Devices 1021# USB Input Devices
995# 1022#
996CONFIG_USB_HID=y 1023CONFIG_USB_HID=y
997CONFIG_USB_HIDINPUT=y 1024CONFIG_USB_HIDINPUT=y
1025# CONFIG_USB_HIDINPUT_POWERBOOK is not set
998# CONFIG_HID_FF is not set 1026# CONFIG_HID_FF is not set
999CONFIG_USB_HIDDEV=y 1027CONFIG_USB_HIDDEV=y
1000# CONFIG_USB_AIPTEK is not set 1028# CONFIG_USB_AIPTEK is not set
@@ -1008,6 +1036,7 @@ CONFIG_USB_HIDDEV=y
1008# CONFIG_USB_YEALINK is not set 1036# CONFIG_USB_YEALINK is not set
1009# CONFIG_USB_XPAD is not set 1037# CONFIG_USB_XPAD is not set
1010# CONFIG_USB_ATI_REMOTE is not set 1038# CONFIG_USB_ATI_REMOTE is not set
1039# CONFIG_USB_ATI_REMOTE2 is not set
1011# CONFIG_USB_KEYSPAN_REMOTE is not set 1040# CONFIG_USB_KEYSPAN_REMOTE is not set
1012# CONFIG_USB_APPLETOUCH is not set 1041# CONFIG_USB_APPLETOUCH is not set
1013 1042
@@ -1107,6 +1136,7 @@ CONFIG_XFS_EXPORT=y
1107# CONFIG_XFS_SECURITY is not set 1136# CONFIG_XFS_SECURITY is not set
1108# CONFIG_XFS_POSIX_ACL is not set 1137# CONFIG_XFS_POSIX_ACL is not set
1109# CONFIG_XFS_RT is not set 1138# CONFIG_XFS_RT is not set
1139# CONFIG_OCFS2_FS is not set
1110# CONFIG_MINIX_FS is not set 1140# CONFIG_MINIX_FS is not set
1111# CONFIG_ROMFS_FS is not set 1141# CONFIG_ROMFS_FS is not set
1112CONFIG_INOTIFY=y 1142CONFIG_INOTIFY=y
@@ -1142,6 +1172,7 @@ CONFIG_TMPFS=y
1142# CONFIG_HUGETLB_PAGE is not set 1172# CONFIG_HUGETLB_PAGE is not set
1143CONFIG_RAMFS=y 1173CONFIG_RAMFS=y
1144# CONFIG_RELAYFS_FS is not set 1174# CONFIG_RELAYFS_FS is not set
1175# CONFIG_CONFIGFS_FS is not set
1145 1176
1146# 1177#
1147# Miscellaneous filesystems 1178# Miscellaneous filesystems
@@ -1246,6 +1277,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
1246# Kernel hacking 1277# Kernel hacking
1247# 1278#
1248# CONFIG_PRINTK_TIME is not set 1279# CONFIG_PRINTK_TIME is not set
1280# CONFIG_MAGIC_SYSRQ is not set
1249# CONFIG_DEBUG_KERNEL is not set 1281# CONFIG_DEBUG_KERNEL is not set
1250CONFIG_LOG_BUF_SHIFT=14 1282CONFIG_LOG_BUF_SHIFT=14
1251CONFIG_CROSSCOMPILE=y 1283CONFIG_CROSSCOMPILE=y
@@ -1299,3 +1331,7 @@ CONFIG_CRC32=y
1299CONFIG_LIBCRC32C=m 1331CONFIG_LIBCRC32C=m
1300CONFIG_ZLIB_INFLATE=y 1332CONFIG_ZLIB_INFLATE=y
1301CONFIG_ZLIB_DEFLATE=m 1333CONFIG_ZLIB_DEFLATE=m
1334CONFIG_TEXTSEARCH=y
1335CONFIG_TEXTSEARCH_KMP=m
1336CONFIG_TEXTSEARCH_BM=m
1337CONFIG_TEXTSEARCH_FSM=m
diff --git a/arch/mips/configs/qemu_defconfig b/arch/mips/configs/qemu_defconfig
index c02becab850b..31f5afabafa8 100644
--- a/arch/mips/configs/qemu_defconfig
+++ b/arch/mips/configs/qemu_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.16-rc2 3# Linux kernel version: 2.6.16-rc2
4# Fri Feb 3 17:14:27 2006 4# Sun Feb 12 19:18:55 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -133,7 +133,6 @@ CONFIG_PREEMPT_NONE=y
133# Code maturity level options 133# Code maturity level options
134# 134#
135# CONFIG_EXPERIMENTAL is not set 135# CONFIG_EXPERIMENTAL is not set
136CONFIG_CLEAN_COMPILE=y
137CONFIG_BROKEN_ON_SMP=y 136CONFIG_BROKEN_ON_SMP=y
138CONFIG_INIT_ENV_ARG_LIMIT=32 137CONFIG_INIT_ENV_ARG_LIMIT=32
139 138
@@ -145,7 +144,7 @@ CONFIG_LOCALVERSION_AUTO=y
145# CONFIG_SWAP is not set 144# CONFIG_SWAP is not set
146# CONFIG_SYSVIPC is not set 145# CONFIG_SYSVIPC is not set
147# CONFIG_BSD_PROCESS_ACCT is not set 146# CONFIG_BSD_PROCESS_ACCT is not set
148# CONFIG_SYSCTL is not set 147CONFIG_SYSCTL=y
149# CONFIG_AUDIT is not set 148# CONFIG_AUDIT is not set
150# CONFIG_IKCONFIG is not set 149# CONFIG_IKCONFIG is not set
151CONFIG_INITRAMFS_SOURCE="" 150CONFIG_INITRAMFS_SOURCE=""
@@ -222,6 +221,7 @@ CONFIG_NET=y
222# 221#
223# Networking options 222# Networking options
224# 223#
224# CONFIG_NETDEBUG is not set
225CONFIG_PACKET=y 225CONFIG_PACKET=y
226CONFIG_PACKET_MMAP=y 226CONFIG_PACKET_MMAP=y
227CONFIG_UNIX=y 227CONFIG_UNIX=y
@@ -476,8 +476,9 @@ CONFIG_SERIAL_8250_RUNTIME_UARTS=4
476# 476#
477CONFIG_SERIAL_CORE=y 477CONFIG_SERIAL_CORE=y
478CONFIG_SERIAL_CORE_CONSOLE=y 478CONFIG_SERIAL_CORE_CONSOLE=y
479# CONFIG_UNIX98_PTYS is not set 479CONFIG_UNIX98_PTYS=y
480# CONFIG_LEGACY_PTYS is not set 480CONFIG_LEGACY_PTYS=y
481CONFIG_LEGACY_PTY_COUNT=256
481 482
482# 483#
483# IPMI 484# IPMI
@@ -627,7 +628,7 @@ CONFIG_FUSE_FS=y
627# 628#
628CONFIG_PROC_FS=y 629CONFIG_PROC_FS=y
629CONFIG_PROC_KCORE=y 630CONFIG_PROC_KCORE=y
630# CONFIG_SYSFS is not set 631CONFIG_SYSFS=y
631# CONFIG_TMPFS is not set 632# CONFIG_TMPFS is not set
632# CONFIG_HUGETLB_PAGE is not set 633# CONFIG_HUGETLB_PAGE is not set
633CONFIG_RAMFS=y 634CONFIG_RAMFS=y
@@ -680,12 +681,13 @@ CONFIG_MSDOS_PARTITION=y
680# CONFIG_DEBUG_KERNEL is not set 681# CONFIG_DEBUG_KERNEL is not set
681CONFIG_LOG_BUF_SHIFT=14 682CONFIG_LOG_BUF_SHIFT=14
682CONFIG_CROSSCOMPILE=y 683CONFIG_CROSSCOMPILE=y
683CONFIG_CMDLINE="console=ttyS0 debug ip=172.20.0.2:172.20.0.1::255.255.0.0" 684CONFIG_CMDLINE=""
684 685
685# 686#
686# Security options 687# Security options
687# 688#
688# CONFIG_KEYS is not set 689# CONFIG_KEYS is not set
690# CONFIG_SECURITY is not set
689 691
690# 692#
691# Cryptographic options 693# Cryptographic options
diff --git a/arch/mips/configs/rbhma4500_defconfig b/arch/mips/configs/rbhma4500_defconfig
index 9aaa43024aec..b126f763cf51 100644
--- a/arch/mips/configs/rbhma4500_defconfig
+++ b/arch/mips/configs/rbhma4500_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:07:03 2005 4# Fri Jan 27 15:40:30 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -160,27 +160,30 @@ CONFIG_SYSVIPC=y
160# CONFIG_BSD_PROCESS_ACCT is not set 160# CONFIG_BSD_PROCESS_ACCT is not set
161CONFIG_SYSCTL=y 161CONFIG_SYSCTL=y
162# CONFIG_AUDIT is not set 162# CONFIG_AUDIT is not set
163CONFIG_HOTPLUG=y
164# CONFIG_KOBJECT_UEVENT is not set
165CONFIG_IKCONFIG=y 163CONFIG_IKCONFIG=y
166CONFIG_IKCONFIG_PROC=y 164CONFIG_IKCONFIG_PROC=y
167CONFIG_INITRAMFS_SOURCE="" 165CONFIG_INITRAMFS_SOURCE=""
166# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
168CONFIG_EMBEDDED=y 167CONFIG_EMBEDDED=y
169CONFIG_KALLSYMS=y 168CONFIG_KALLSYMS=y
170# CONFIG_KALLSYMS_EXTRA_PASS is not set 169# CONFIG_KALLSYMS_EXTRA_PASS is not set
170CONFIG_HOTPLUG=y
171CONFIG_PRINTK=y 171CONFIG_PRINTK=y
172CONFIG_BUG=y 172CONFIG_BUG=y
173CONFIG_ELF_CORE=y
173CONFIG_BASE_FULL=y 174CONFIG_BASE_FULL=y
174# CONFIG_FUTEX is not set 175# CONFIG_FUTEX is not set
175# CONFIG_EPOLL is not set 176# CONFIG_EPOLL is not set
176# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
177CONFIG_SHMEM=y 177CONFIG_SHMEM=y
178CONFIG_CC_ALIGN_FUNCTIONS=0 178CONFIG_CC_ALIGN_FUNCTIONS=0
179CONFIG_CC_ALIGN_LABELS=0 179CONFIG_CC_ALIGN_LABELS=0
180CONFIG_CC_ALIGN_LOOPS=0 180CONFIG_CC_ALIGN_LOOPS=0
181CONFIG_CC_ALIGN_JUMPS=0 181CONFIG_CC_ALIGN_JUMPS=0
182CONFIG_SLAB=y
182# CONFIG_TINY_SHMEM is not set 183# CONFIG_TINY_SHMEM is not set
183CONFIG_BASE_SMALL=0 184CONFIG_BASE_SMALL=0
185# CONFIG_SLOB is not set
186CONFIG_OBSOLETE_INTERMODULE=y
184 187
185# 188#
186# Loadable module support 189# Loadable module support
@@ -291,6 +294,21 @@ CONFIG_NETFILTER_NETLINK=m
291CONFIG_NETFILTER_NETLINK_QUEUE=m 294CONFIG_NETFILTER_NETLINK_QUEUE=m
292CONFIG_NETFILTER_NETLINK_LOG=m 295CONFIG_NETFILTER_NETLINK_LOG=m
293# CONFIG_NF_CONNTRACK is not set 296# CONFIG_NF_CONNTRACK is not set
297CONFIG_NETFILTER_XTABLES=m
298CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
299CONFIG_NETFILTER_XT_TARGET_MARK=m
300CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
301CONFIG_NETFILTER_XT_MATCH_COMMENT=m
302CONFIG_NETFILTER_XT_MATCH_DCCP=m
303CONFIG_NETFILTER_XT_MATCH_LENGTH=m
304CONFIG_NETFILTER_XT_MATCH_LIMIT=m
305CONFIG_NETFILTER_XT_MATCH_MAC=m
306CONFIG_NETFILTER_XT_MATCH_MARK=m
307CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
308CONFIG_NETFILTER_XT_MATCH_REALM=m
309CONFIG_NETFILTER_XT_MATCH_SCTP=m
310CONFIG_NETFILTER_XT_MATCH_STRING=m
311CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
294 312
295# 313#
296# IP: Netfilter Configuration 314# IP: Netfilter Configuration
@@ -324,6 +342,11 @@ CONFIG_NETFILTER_NETLINK_LOG=m
324# CONFIG_ATALK is not set 342# CONFIG_ATALK is not set
325# CONFIG_X25 is not set 343# CONFIG_X25 is not set
326# CONFIG_LAPB is not set 344# CONFIG_LAPB is not set
345
346#
347# TIPC Configuration (EXPERIMENTAL)
348#
349# CONFIG_TIPC is not set
327# CONFIG_NET_DIVERT is not set 350# CONFIG_NET_DIVERT is not set
328# CONFIG_ECONET is not set 351# CONFIG_ECONET is not set
329# CONFIG_WAN_ROUTER is not set 352# CONFIG_WAN_ROUTER is not set
@@ -332,6 +355,7 @@ CONFIG_NETFILTER_NETLINK_LOG=m
332# QoS and/or fair queueing 355# QoS and/or fair queueing
333# 356#
334# CONFIG_NET_SCHED is not set 357# CONFIG_NET_SCHED is not set
358CONFIG_NET_CLS_ROUTE=y
335 359
336# 360#
337# Network testing 361# Network testing
@@ -407,6 +431,7 @@ CONFIG_MTD_CFI_UTIL=y
407# CONFIG_MTD_RAM is not set 431# CONFIG_MTD_RAM is not set
408# CONFIG_MTD_ROM is not set 432# CONFIG_MTD_ROM is not set
409# CONFIG_MTD_ABSENT is not set 433# CONFIG_MTD_ABSENT is not set
434# CONFIG_MTD_OBSOLETE_CHIPS is not set
410 435
411# 436#
412# Mapping drivers for chip access 437# Mapping drivers for chip access
@@ -598,6 +623,7 @@ CONFIG_NET_ETHERNET=y
598# CONFIG_CASSINI is not set 623# CONFIG_CASSINI is not set
599# CONFIG_NET_VENDOR_3COM is not set 624# CONFIG_NET_VENDOR_3COM is not set
600# CONFIG_NET_VENDOR_SMC is not set 625# CONFIG_NET_VENDOR_SMC is not set
626# CONFIG_DM9000 is not set
601# CONFIG_NET_VENDOR_RACAL is not set 627# CONFIG_NET_VENDOR_RACAL is not set
602 628
603# 629#
@@ -654,6 +680,7 @@ CONFIG_NET_PCI=y
654# CONFIG_R8169 is not set 680# CONFIG_R8169 is not set
655# CONFIG_SIS190 is not set 681# CONFIG_SIS190 is not set
656# CONFIG_SKGE is not set 682# CONFIG_SKGE is not set
683# CONFIG_SKY2 is not set
657# CONFIG_SK98LIN is not set 684# CONFIG_SK98LIN is not set
658# CONFIG_VIA_VELOCITY is not set 685# CONFIG_VIA_VELOCITY is not set
659# CONFIG_TIGON3 is not set 686# CONFIG_TIGON3 is not set
@@ -687,8 +714,8 @@ CONFIG_NET_RADIO=y
687# Wireless 802.11b ISA/PCI cards support 714# Wireless 802.11b ISA/PCI cards support
688# 715#
689# CONFIG_IPW2100 is not set 716# CONFIG_IPW2100 is not set
690# CONFIG_IPW_DEBUG is not set
691CONFIG_IPW2200=m 717CONFIG_IPW2200=m
718# CONFIG_IPW2200_DEBUG is not set
692# CONFIG_HERMES is not set 719# CONFIG_HERMES is not set
693# CONFIG_ATMEL is not set 720# CONFIG_ATMEL is not set
694 721
@@ -795,7 +822,6 @@ CONFIG_HW_CONSOLE=y
795# Non-8250 serial port support 822# Non-8250 serial port support
796# 823#
797CONFIG_HAS_TXX9_SERIAL=y 824CONFIG_HAS_TXX9_SERIAL=y
798# CONFIG_SERIAL_JSM is not set
799CONFIG_UNIX98_PTYS=y 825CONFIG_UNIX98_PTYS=y
800CONFIG_LEGACY_PTYS=y 826CONFIG_LEGACY_PTYS=y
801CONFIG_LEGACY_PTY_COUNT=256 827CONFIG_LEGACY_PTY_COUNT=256
@@ -833,6 +859,12 @@ CONFIG_LEGACY_PTY_COUNT=256
833# CONFIG_I2C is not set 859# CONFIG_I2C is not set
834 860
835# 861#
862# SPI support
863#
864# CONFIG_SPI is not set
865# CONFIG_SPI_MASTER is not set
866
867#
836# Dallas's 1-wire bus 868# Dallas's 1-wire bus
837# 869#
838# CONFIG_W1 is not set 870# CONFIG_W1 is not set
@@ -887,7 +919,6 @@ CONFIG_FB_CFB_IMAGEBLIT=y
887CONFIG_FB_ATY=y 919CONFIG_FB_ATY=y
888CONFIG_FB_ATY_CT=y 920CONFIG_FB_ATY_CT=y
889# CONFIG_FB_ATY_GENERIC_LCD is not set 921# CONFIG_FB_ATY_GENERIC_LCD is not set
890# CONFIG_FB_ATY_XL_INIT is not set
891# CONFIG_FB_ATY_GX is not set 922# CONFIG_FB_ATY_GX is not set
892# CONFIG_FB_SAVAGE is not set 923# CONFIG_FB_SAVAGE is not set
893# CONFIG_FB_SIS is not set 924# CONFIG_FB_SIS is not set
@@ -896,7 +927,6 @@ CONFIG_FB_ATY_CT=y
896# CONFIG_FB_3DFX is not set 927# CONFIG_FB_3DFX is not set
897# CONFIG_FB_VOODOO1 is not set 928# CONFIG_FB_VOODOO1 is not set
898# CONFIG_FB_SMIVGX is not set 929# CONFIG_FB_SMIVGX is not set
899# CONFIG_FB_CYBLA is not set
900# CONFIG_FB_TRIDENT is not set 930# CONFIG_FB_TRIDENT is not set
901# CONFIG_FB_VIRTUAL is not set 931# CONFIG_FB_VIRTUAL is not set
902 932
@@ -958,12 +988,14 @@ CONFIG_USB=y
958# may also be needed; see USB_STORAGE Help for more information 988# may also be needed; see USB_STORAGE Help for more information
959# 989#
960# CONFIG_USB_STORAGE is not set 990# CONFIG_USB_STORAGE is not set
991# CONFIG_USB_LIBUSUAL is not set
961 992
962# 993#
963# USB Input Devices 994# USB Input Devices
964# 995#
965CONFIG_USB_HID=y 996CONFIG_USB_HID=y
966CONFIG_USB_HIDINPUT=y 997CONFIG_USB_HIDINPUT=y
998# CONFIG_USB_HIDINPUT_POWERBOOK is not set
967# CONFIG_HID_FF is not set 999# CONFIG_HID_FF is not set
968CONFIG_USB_HIDDEV=y 1000CONFIG_USB_HIDDEV=y
969# CONFIG_USB_AIPTEK is not set 1001# CONFIG_USB_AIPTEK is not set
@@ -977,6 +1009,7 @@ CONFIG_USB_HIDDEV=y
977CONFIG_USB_YEALINK=m 1009CONFIG_USB_YEALINK=m
978# CONFIG_USB_XPAD is not set 1010# CONFIG_USB_XPAD is not set
979# CONFIG_USB_ATI_REMOTE is not set 1011# CONFIG_USB_ATI_REMOTE is not set
1012# CONFIG_USB_ATI_REMOTE2 is not set
980# CONFIG_USB_KEYSPAN_REMOTE is not set 1013# CONFIG_USB_KEYSPAN_REMOTE is not set
981# CONFIG_USB_APPLETOUCH is not set 1014# CONFIG_USB_APPLETOUCH is not set
982 1015
@@ -1078,6 +1111,7 @@ CONFIG_XFS_EXPORT=y
1078# CONFIG_XFS_SECURITY is not set 1111# CONFIG_XFS_SECURITY is not set
1079# CONFIG_XFS_POSIX_ACL is not set 1112# CONFIG_XFS_POSIX_ACL is not set
1080# CONFIG_XFS_RT is not set 1113# CONFIG_XFS_RT is not set
1114# CONFIG_OCFS2_FS is not set
1081# CONFIG_MINIX_FS is not set 1115# CONFIG_MINIX_FS is not set
1082# CONFIG_ROMFS_FS is not set 1116# CONFIG_ROMFS_FS is not set
1083CONFIG_INOTIFY=y 1117CONFIG_INOTIFY=y
@@ -1115,6 +1149,7 @@ CONFIG_TMPFS=y
1115# CONFIG_HUGETLB_PAGE is not set 1149# CONFIG_HUGETLB_PAGE is not set
1116CONFIG_RAMFS=y 1150CONFIG_RAMFS=y
1117CONFIG_RELAYFS_FS=m 1151CONFIG_RELAYFS_FS=m
1152# CONFIG_CONFIGFS_FS is not set
1118 1153
1119# 1154#
1120# Miscellaneous filesystems 1155# Miscellaneous filesystems
@@ -1228,6 +1263,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
1228# Kernel hacking 1263# Kernel hacking
1229# 1264#
1230# CONFIG_PRINTK_TIME is not set 1265# CONFIG_PRINTK_TIME is not set
1266# CONFIG_MAGIC_SYSRQ is not set
1231# CONFIG_DEBUG_KERNEL is not set 1267# CONFIG_DEBUG_KERNEL is not set
1232CONFIG_LOG_BUF_SHIFT=14 1268CONFIG_LOG_BUF_SHIFT=14
1233CONFIG_CROSSCOMPILE=y 1269CONFIG_CROSSCOMPILE=y
@@ -1281,3 +1317,7 @@ CONFIG_CRC32=y
1281CONFIG_LIBCRC32C=m 1317CONFIG_LIBCRC32C=m
1282CONFIG_ZLIB_INFLATE=y 1318CONFIG_ZLIB_INFLATE=y
1283CONFIG_ZLIB_DEFLATE=y 1319CONFIG_ZLIB_DEFLATE=y
1320CONFIG_TEXTSEARCH=y
1321CONFIG_TEXTSEARCH_KMP=m
1322CONFIG_TEXTSEARCH_BM=m
1323CONFIG_TEXTSEARCH_FSM=m
diff --git a/arch/mips/configs/rm200_defconfig b/arch/mips/configs/rm200_defconfig
index abf61095931e..463ed3dbf6ae 100644
--- a/arch/mips/configs/rm200_defconfig
+++ b/arch/mips/configs/rm200_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:07:06 2005 4# Fri Jan 27 15:40:31 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -161,27 +161,29 @@ CONFIG_BSD_PROCESS_ACCT=y
161# CONFIG_BSD_PROCESS_ACCT_V3 is not set 161# CONFIG_BSD_PROCESS_ACCT_V3 is not set
162CONFIG_SYSCTL=y 162CONFIG_SYSCTL=y
163# CONFIG_AUDIT is not set 163# CONFIG_AUDIT is not set
164CONFIG_HOTPLUG=y
165CONFIG_KOBJECT_UEVENT=y
166CONFIG_IKCONFIG=y 164CONFIG_IKCONFIG=y
167CONFIG_IKCONFIG_PROC=y 165CONFIG_IKCONFIG_PROC=y
168CONFIG_INITRAMFS_SOURCE="" 166CONFIG_INITRAMFS_SOURCE=""
167# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
169CONFIG_EMBEDDED=y 168CONFIG_EMBEDDED=y
170CONFIG_KALLSYMS=y 169CONFIG_KALLSYMS=y
171# CONFIG_KALLSYMS_EXTRA_PASS is not set 170# CONFIG_KALLSYMS_EXTRA_PASS is not set
171CONFIG_HOTPLUG=y
172CONFIG_PRINTK=y 172CONFIG_PRINTK=y
173CONFIG_BUG=y 173CONFIG_BUG=y
174CONFIG_ELF_CORE=y
174CONFIG_BASE_FULL=y 175CONFIG_BASE_FULL=y
175CONFIG_FUTEX=y 176CONFIG_FUTEX=y
176CONFIG_EPOLL=y 177CONFIG_EPOLL=y
177# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
178CONFIG_SHMEM=y 178CONFIG_SHMEM=y
179CONFIG_CC_ALIGN_FUNCTIONS=0 179CONFIG_CC_ALIGN_FUNCTIONS=0
180CONFIG_CC_ALIGN_LABELS=0 180CONFIG_CC_ALIGN_LABELS=0
181CONFIG_CC_ALIGN_LOOPS=0 181CONFIG_CC_ALIGN_LOOPS=0
182CONFIG_CC_ALIGN_JUMPS=0 182CONFIG_CC_ALIGN_JUMPS=0
183CONFIG_SLAB=y
183# CONFIG_TINY_SHMEM is not set 184# CONFIG_TINY_SHMEM is not set
184CONFIG_BASE_SMALL=0 185CONFIG_BASE_SMALL=0
186# CONFIG_SLOB is not set
185 187
186# 188#
187# Loadable module support 189# Loadable module support
@@ -297,6 +299,28 @@ CONFIG_BRIDGE_NETFILTER=y
297CONFIG_NETFILTER_NETLINK=m 299CONFIG_NETFILTER_NETLINK=m
298CONFIG_NETFILTER_NETLINK_QUEUE=m 300CONFIG_NETFILTER_NETLINK_QUEUE=m
299CONFIG_NETFILTER_NETLINK_LOG=m 301CONFIG_NETFILTER_NETLINK_LOG=m
302CONFIG_NETFILTER_XTABLES=m
303CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
304CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
305CONFIG_NETFILTER_XT_TARGET_MARK=m
306CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
307CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
308CONFIG_NETFILTER_XT_MATCH_COMMENT=m
309CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
310CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
311CONFIG_NETFILTER_XT_MATCH_DCCP=m
312CONFIG_NETFILTER_XT_MATCH_HELPER=m
313CONFIG_NETFILTER_XT_MATCH_LENGTH=m
314CONFIG_NETFILTER_XT_MATCH_LIMIT=m
315CONFIG_NETFILTER_XT_MATCH_MAC=m
316CONFIG_NETFILTER_XT_MATCH_MARK=m
317CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
318CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
319CONFIG_NETFILTER_XT_MATCH_REALM=m
320CONFIG_NETFILTER_XT_MATCH_SCTP=m
321CONFIG_NETFILTER_XT_MATCH_STATE=m
322CONFIG_NETFILTER_XT_MATCH_STRING=m
323CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
300 324
301# 325#
302# IP: Netfilter Configuration 326# IP: Netfilter Configuration
@@ -315,39 +339,23 @@ CONFIG_IP_NF_AMANDA=m
315CONFIG_IP_NF_PPTP=m 339CONFIG_IP_NF_PPTP=m
316CONFIG_IP_NF_QUEUE=m 340CONFIG_IP_NF_QUEUE=m
317CONFIG_IP_NF_IPTABLES=m 341CONFIG_IP_NF_IPTABLES=m
318CONFIG_IP_NF_MATCH_LIMIT=m
319CONFIG_IP_NF_MATCH_IPRANGE=m 342CONFIG_IP_NF_MATCH_IPRANGE=m
320CONFIG_IP_NF_MATCH_MAC=m
321CONFIG_IP_NF_MATCH_PKTTYPE=m
322CONFIG_IP_NF_MATCH_MARK=m
323CONFIG_IP_NF_MATCH_MULTIPORT=m 343CONFIG_IP_NF_MATCH_MULTIPORT=m
324CONFIG_IP_NF_MATCH_TOS=m 344CONFIG_IP_NF_MATCH_TOS=m
325CONFIG_IP_NF_MATCH_RECENT=m 345CONFIG_IP_NF_MATCH_RECENT=m
326CONFIG_IP_NF_MATCH_ECN=m 346CONFIG_IP_NF_MATCH_ECN=m
327CONFIG_IP_NF_MATCH_DSCP=m 347CONFIG_IP_NF_MATCH_DSCP=m
328CONFIG_IP_NF_MATCH_AH_ESP=m 348CONFIG_IP_NF_MATCH_AH_ESP=m
329CONFIG_IP_NF_MATCH_LENGTH=m
330CONFIG_IP_NF_MATCH_TTL=m 349CONFIG_IP_NF_MATCH_TTL=m
331CONFIG_IP_NF_MATCH_TCPMSS=m
332CONFIG_IP_NF_MATCH_HELPER=m
333CONFIG_IP_NF_MATCH_STATE=m
334CONFIG_IP_NF_MATCH_CONNTRACK=m
335CONFIG_IP_NF_MATCH_OWNER=m 350CONFIG_IP_NF_MATCH_OWNER=m
336CONFIG_IP_NF_MATCH_PHYSDEV=m
337CONFIG_IP_NF_MATCH_ADDRTYPE=m 351CONFIG_IP_NF_MATCH_ADDRTYPE=m
338CONFIG_IP_NF_MATCH_REALM=m
339CONFIG_IP_NF_MATCH_SCTP=m
340CONFIG_IP_NF_MATCH_DCCP=m
341CONFIG_IP_NF_MATCH_COMMENT=m
342CONFIG_IP_NF_MATCH_CONNMARK=m
343CONFIG_IP_NF_MATCH_HASHLIMIT=m 352CONFIG_IP_NF_MATCH_HASHLIMIT=m
344CONFIG_IP_NF_MATCH_STRING=m 353CONFIG_IP_NF_MATCH_POLICY=m
345CONFIG_IP_NF_FILTER=m 354CONFIG_IP_NF_FILTER=m
346CONFIG_IP_NF_TARGET_REJECT=m 355CONFIG_IP_NF_TARGET_REJECT=m
347CONFIG_IP_NF_TARGET_LOG=m 356CONFIG_IP_NF_TARGET_LOG=m
348CONFIG_IP_NF_TARGET_ULOG=m 357CONFIG_IP_NF_TARGET_ULOG=m
349CONFIG_IP_NF_TARGET_TCPMSS=m 358CONFIG_IP_NF_TARGET_TCPMSS=m
350CONFIG_IP_NF_TARGET_NFQUEUE=m
351CONFIG_IP_NF_NAT=m 359CONFIG_IP_NF_NAT=m
352CONFIG_IP_NF_NAT_NEEDED=y 360CONFIG_IP_NF_NAT_NEEDED=y
353CONFIG_IP_NF_TARGET_MASQUERADE=m 361CONFIG_IP_NF_TARGET_MASQUERADE=m
@@ -364,13 +372,9 @@ CONFIG_IP_NF_MANGLE=m
364CONFIG_IP_NF_TARGET_TOS=m 372CONFIG_IP_NF_TARGET_TOS=m
365CONFIG_IP_NF_TARGET_ECN=m 373CONFIG_IP_NF_TARGET_ECN=m
366CONFIG_IP_NF_TARGET_DSCP=m 374CONFIG_IP_NF_TARGET_DSCP=m
367CONFIG_IP_NF_TARGET_MARK=m
368CONFIG_IP_NF_TARGET_CLASSIFY=m
369CONFIG_IP_NF_TARGET_TTL=m 375CONFIG_IP_NF_TARGET_TTL=m
370CONFIG_IP_NF_TARGET_CONNMARK=m
371CONFIG_IP_NF_TARGET_CLUSTERIP=m 376CONFIG_IP_NF_TARGET_CLUSTERIP=m
372CONFIG_IP_NF_RAW=m 377CONFIG_IP_NF_RAW=m
373CONFIG_IP_NF_TARGET_NOTRACK=m
374CONFIG_IP_NF_ARPTABLES=m 378CONFIG_IP_NF_ARPTABLES=m
375CONFIG_IP_NF_ARPFILTER=m 379CONFIG_IP_NF_ARPFILTER=m
376CONFIG_IP_NF_ARP_MANGLE=m 380CONFIG_IP_NF_ARP_MANGLE=m
@@ -380,26 +384,20 @@ CONFIG_IP_NF_ARP_MANGLE=m
380# 384#
381CONFIG_IP6_NF_QUEUE=m 385CONFIG_IP6_NF_QUEUE=m
382CONFIG_IP6_NF_IPTABLES=m 386CONFIG_IP6_NF_IPTABLES=m
383CONFIG_IP6_NF_MATCH_LIMIT=m
384CONFIG_IP6_NF_MATCH_MAC=m
385CONFIG_IP6_NF_MATCH_RT=m 387CONFIG_IP6_NF_MATCH_RT=m
386CONFIG_IP6_NF_MATCH_OPTS=m 388CONFIG_IP6_NF_MATCH_OPTS=m
387CONFIG_IP6_NF_MATCH_FRAG=m 389CONFIG_IP6_NF_MATCH_FRAG=m
388CONFIG_IP6_NF_MATCH_HL=m 390CONFIG_IP6_NF_MATCH_HL=m
389CONFIG_IP6_NF_MATCH_MULTIPORT=m 391CONFIG_IP6_NF_MATCH_MULTIPORT=m
390CONFIG_IP6_NF_MATCH_OWNER=m 392CONFIG_IP6_NF_MATCH_OWNER=m
391CONFIG_IP6_NF_MATCH_MARK=m
392CONFIG_IP6_NF_MATCH_IPV6HEADER=m 393CONFIG_IP6_NF_MATCH_IPV6HEADER=m
393CONFIG_IP6_NF_MATCH_AHESP=m 394CONFIG_IP6_NF_MATCH_AHESP=m
394CONFIG_IP6_NF_MATCH_LENGTH=m
395CONFIG_IP6_NF_MATCH_EUI64=m 395CONFIG_IP6_NF_MATCH_EUI64=m
396CONFIG_IP6_NF_MATCH_PHYSDEV=m 396CONFIG_IP6_NF_MATCH_POLICY=m
397CONFIG_IP6_NF_FILTER=m 397CONFIG_IP6_NF_FILTER=m
398CONFIG_IP6_NF_TARGET_LOG=m 398CONFIG_IP6_NF_TARGET_LOG=m
399CONFIG_IP6_NF_TARGET_REJECT=m 399CONFIG_IP6_NF_TARGET_REJECT=m
400CONFIG_IP6_NF_TARGET_NFQUEUE=m
401CONFIG_IP6_NF_MANGLE=m 400CONFIG_IP6_NF_MANGLE=m
402CONFIG_IP6_NF_TARGET_MARK=m
403CONFIG_IP6_NF_TARGET_HL=m 401CONFIG_IP6_NF_TARGET_HL=m
404CONFIG_IP6_NF_RAW=m 402CONFIG_IP6_NF_RAW=m
405 403
@@ -451,6 +449,11 @@ CONFIG_DECNET=m
451# CONFIG_ATALK is not set 449# CONFIG_ATALK is not set
452# CONFIG_X25 is not set 450# CONFIG_X25 is not set
453# CONFIG_LAPB is not set 451# CONFIG_LAPB is not set
452
453#
454# TIPC Configuration (EXPERIMENTAL)
455#
456# CONFIG_TIPC is not set
454# CONFIG_NET_DIVERT is not set 457# CONFIG_NET_DIVERT is not set
455# CONFIG_ECONET is not set 458# CONFIG_ECONET is not set
456# CONFIG_WAN_ROUTER is not set 459# CONFIG_WAN_ROUTER is not set
@@ -530,7 +533,6 @@ CONFIG_IEEE80211=m
530# CONFIG_IEEE80211_DEBUG is not set 533# CONFIG_IEEE80211_DEBUG is not set
531CONFIG_IEEE80211_CRYPT_WEP=m 534CONFIG_IEEE80211_CRYPT_WEP=m
532CONFIG_IEEE80211_CRYPT_CCMP=m 535CONFIG_IEEE80211_CRYPT_CCMP=m
533CONFIG_IEEE80211_CRYPT_TKIP=m
534 536
535# 537#
536# Device Drivers 538# Device Drivers
@@ -541,7 +543,7 @@ CONFIG_IEEE80211_CRYPT_TKIP=m
541# 543#
542CONFIG_STANDALONE=y 544CONFIG_STANDALONE=y
543CONFIG_PREVENT_FIRMWARE_BUILD=y 545CONFIG_PREVENT_FIRMWARE_BUILD=y
544CONFIG_FW_LOADER=m 546CONFIG_FW_LOADER=y
545 547
546# 548#
547# Connector - unified userspace <-> kernelspace linker 549# Connector - unified userspace <-> kernelspace linker
@@ -657,7 +659,7 @@ CONFIG_SCSI_CONSTANTS=y
657# SCSI Transport Attributes 659# SCSI Transport Attributes
658# 660#
659CONFIG_SCSI_SPI_ATTRS=y 661CONFIG_SCSI_SPI_ATTRS=y
660# CONFIG_SCSI_FC_ATTRS is not set 662CONFIG_SCSI_FC_ATTRS=y
661CONFIG_SCSI_ISCSI_ATTRS=m 663CONFIG_SCSI_ISCSI_ATTRS=m
662CONFIG_SCSI_SAS_ATTRS=m 664CONFIG_SCSI_SAS_ATTRS=m
663 665
@@ -678,6 +680,7 @@ CONFIG_ISCSI_TCP=m
678CONFIG_MEGARAID_NEWGEN=y 680CONFIG_MEGARAID_NEWGEN=y
679CONFIG_MEGARAID_MM=m 681CONFIG_MEGARAID_MM=m
680CONFIG_MEGARAID_MAILBOX=m 682CONFIG_MEGARAID_MAILBOX=m
683# CONFIG_MEGARAID_LEGACY is not set
681# CONFIG_MEGARAID_SAS is not set 684# CONFIG_MEGARAID_SAS is not set
682# CONFIG_SCSI_SATA is not set 685# CONFIG_SCSI_SATA is not set
683# CONFIG_SCSI_DMX3191D is not set 686# CONFIG_SCSI_DMX3191D is not set
@@ -704,13 +707,7 @@ CONFIG_SCSI_SYM53C8XX_MAX_TAGS=64
704# CONFIG_SCSI_QLOGIC_FAS is not set 707# CONFIG_SCSI_QLOGIC_FAS is not set
705# CONFIG_SCSI_QLOGIC_FC is not set 708# CONFIG_SCSI_QLOGIC_FC is not set
706# CONFIG_SCSI_QLOGIC_1280 is not set 709# CONFIG_SCSI_QLOGIC_1280 is not set
707CONFIG_SCSI_QLA2XXX=y 710# CONFIG_SCSI_QLA_FC is not set
708# CONFIG_SCSI_QLA21XX is not set
709# CONFIG_SCSI_QLA22XX is not set
710# CONFIG_SCSI_QLA2300 is not set
711# CONFIG_SCSI_QLA2322 is not set
712# CONFIG_SCSI_QLA6312 is not set
713# CONFIG_SCSI_QLA24XX is not set
714# CONFIG_SCSI_LPFC is not set 711# CONFIG_SCSI_LPFC is not set
715# CONFIG_SCSI_SYM53C416 is not set 712# CONFIG_SCSI_SYM53C416 is not set
716# CONFIG_SCSI_DC395x is not set 713# CONFIG_SCSI_DC395x is not set
@@ -801,6 +798,7 @@ CONFIG_MII=y
801# CONFIG_CASSINI is not set 798# CONFIG_CASSINI is not set
802# CONFIG_NET_VENDOR_3COM is not set 799# CONFIG_NET_VENDOR_3COM is not set
803# CONFIG_NET_VENDOR_SMC is not set 800# CONFIG_NET_VENDOR_SMC is not set
801# CONFIG_DM9000 is not set
804# CONFIG_NET_VENDOR_RACAL is not set 802# CONFIG_NET_VENDOR_RACAL is not set
805 803
806# 804#
@@ -858,6 +856,7 @@ CONFIG_EEPRO100=m
858# CONFIG_R8169 is not set 856# CONFIG_R8169 is not set
859# CONFIG_SIS190 is not set 857# CONFIG_SIS190 is not set
860# CONFIG_SKGE is not set 858# CONFIG_SKGE is not set
859# CONFIG_SKY2 is not set
861# CONFIG_SK98LIN is not set 860# CONFIG_SK98LIN is not set
862CONFIG_VIA_VELOCITY=m 861CONFIG_VIA_VELOCITY=m
863# CONFIG_TIGON3 is not set 862# CONFIG_TIGON3 is not set
@@ -879,8 +878,6 @@ CONFIG_VIA_VELOCITY=m
879# Wireless LAN (non-hamradio) 878# Wireless LAN (non-hamradio)
880# 879#
881# CONFIG_NET_RADIO is not set 880# CONFIG_NET_RADIO is not set
882# CONFIG_IPW_DEBUG is not set
883CONFIG_IPW2200=m
884 881
885# 882#
886# Wan interfaces 883# Wan interfaces
@@ -969,6 +966,7 @@ CONFIG_HW_CONSOLE=y
969# 966#
970CONFIG_SERIAL_8250=m 967CONFIG_SERIAL_8250=m
971CONFIG_SERIAL_8250_NR_UARTS=4 968CONFIG_SERIAL_8250_NR_UARTS=4
969CONFIG_SERIAL_8250_RUNTIME_UARTS=4
972CONFIG_SERIAL_8250_EXTENDED=y 970CONFIG_SERIAL_8250_EXTENDED=y
973# CONFIG_SERIAL_8250_MANY_PORTS is not set 971# CONFIG_SERIAL_8250_MANY_PORTS is not set
974CONFIG_SERIAL_8250_SHARE_IRQ=y 972CONFIG_SERIAL_8250_SHARE_IRQ=y
@@ -979,7 +977,6 @@ CONFIG_SERIAL_8250_RSA=y
979# Non-8250 serial port support 977# Non-8250 serial port support
980# 978#
981CONFIG_SERIAL_CORE=m 979CONFIG_SERIAL_CORE=m
982# CONFIG_SERIAL_JSM is not set
983CONFIG_UNIX98_PTYS=y 980CONFIG_UNIX98_PTYS=y
984CONFIG_LEGACY_PTYS=y 981CONFIG_LEGACY_PTYS=y
985CONFIG_LEGACY_PTY_COUNT=256 982CONFIG_LEGACY_PTY_COUNT=256
@@ -1021,6 +1018,12 @@ CONFIG_RTC=m
1021# CONFIG_I2C is not set 1018# CONFIG_I2C is not set
1022 1019
1023# 1020#
1021# SPI support
1022#
1023# CONFIG_SPI is not set
1024# CONFIG_SPI_MASTER is not set
1025
1026#
1024# Dallas's 1-wire bus 1027# Dallas's 1-wire bus
1025# 1028#
1026CONFIG_W1=m 1029CONFIG_W1=m
@@ -1123,12 +1126,15 @@ CONFIG_USB_STORAGE_DPCM=y
1123CONFIG_USB_STORAGE_SDDR09=y 1126CONFIG_USB_STORAGE_SDDR09=y
1124CONFIG_USB_STORAGE_SDDR55=y 1127CONFIG_USB_STORAGE_SDDR55=y
1125CONFIG_USB_STORAGE_JUMPSHOT=y 1128CONFIG_USB_STORAGE_JUMPSHOT=y
1129# CONFIG_USB_STORAGE_ALAUDA is not set
1130# CONFIG_USB_LIBUSUAL is not set
1126 1131
1127# 1132#
1128# USB Input Devices 1133# USB Input Devices
1129# 1134#
1130CONFIG_USB_HID=m 1135CONFIG_USB_HID=m
1131CONFIG_USB_HIDINPUT=y 1136CONFIG_USB_HIDINPUT=y
1137# CONFIG_USB_HIDINPUT_POWERBOOK is not set
1132CONFIG_HID_FF=y 1138CONFIG_HID_FF=y
1133CONFIG_HID_PID=y 1139CONFIG_HID_PID=y
1134CONFIG_LOGITECH_FF=y 1140CONFIG_LOGITECH_FF=y
@@ -1151,6 +1157,7 @@ CONFIG_USB_EGALAX=m
1151CONFIG_USB_YEALINK=m 1157CONFIG_USB_YEALINK=m
1152CONFIG_USB_XPAD=m 1158CONFIG_USB_XPAD=m
1153# CONFIG_USB_ATI_REMOTE is not set 1159# CONFIG_USB_ATI_REMOTE is not set
1160# CONFIG_USB_ATI_REMOTE2 is not set
1154# CONFIG_USB_KEYSPAN_REMOTE is not set 1161# CONFIG_USB_KEYSPAN_REMOTE is not set
1155# CONFIG_USB_APPLETOUCH is not set 1162# CONFIG_USB_APPLETOUCH is not set
1156 1163
@@ -1309,6 +1316,7 @@ CONFIG_XFS_QUOTA=y
1309CONFIG_XFS_SECURITY=y 1316CONFIG_XFS_SECURITY=y
1310# CONFIG_XFS_POSIX_ACL is not set 1317# CONFIG_XFS_POSIX_ACL is not set
1311# CONFIG_XFS_RT is not set 1318# CONFIG_XFS_RT is not set
1319# CONFIG_OCFS2_FS is not set
1312CONFIG_MINIX_FS=m 1320CONFIG_MINIX_FS=m
1313CONFIG_ROMFS_FS=m 1321CONFIG_ROMFS_FS=m
1314CONFIG_INOTIFY=y 1322CONFIG_INOTIFY=y
@@ -1351,6 +1359,7 @@ CONFIG_SYSFS=y
1351# CONFIG_HUGETLB_PAGE is not set 1359# CONFIG_HUGETLB_PAGE is not set
1352CONFIG_RAMFS=y 1360CONFIG_RAMFS=y
1353CONFIG_RELAYFS_FS=m 1361CONFIG_RELAYFS_FS=m
1362# CONFIG_CONFIGFS_FS is not set
1354 1363
1355# 1364#
1356# Miscellaneous filesystems 1365# Miscellaneous filesystems
@@ -1432,6 +1441,7 @@ CONFIG_MSDOS_PARTITION=y
1432# CONFIG_SGI_PARTITION is not set 1441# CONFIG_SGI_PARTITION is not set
1433# CONFIG_ULTRIX_PARTITION is not set 1442# CONFIG_ULTRIX_PARTITION is not set
1434# CONFIG_SUN_PARTITION is not set 1443# CONFIG_SUN_PARTITION is not set
1444# CONFIG_KARMA_PARTITION is not set
1435# CONFIG_EFI_PARTITION is not set 1445# CONFIG_EFI_PARTITION is not set
1436 1446
1437# 1447#
@@ -1487,6 +1497,7 @@ CONFIG_NLS_UTF8=m
1487# Kernel hacking 1497# Kernel hacking
1488# 1498#
1489# CONFIG_PRINTK_TIME is not set 1499# CONFIG_PRINTK_TIME is not set
1500# CONFIG_MAGIC_SYSRQ is not set
1490# CONFIG_DEBUG_KERNEL is not set 1501# CONFIG_DEBUG_KERNEL is not set
1491CONFIG_LOG_BUF_SHIFT=14 1502CONFIG_LOG_BUF_SHIFT=14
1492CONFIG_CROSSCOMPILE=y 1503CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/sb1250-swarm_defconfig b/arch/mips/configs/sb1250-swarm_defconfig
index 52048c906079..da68c3f72050 100644
--- a/arch/mips/configs/sb1250-swarm_defconfig
+++ b/arch/mips/configs/sb1250-swarm_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:07:09 2005 4# Fri Jan 27 15:40:32 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -173,27 +173,29 @@ CONFIG_SYSVIPC=y
173# CONFIG_BSD_PROCESS_ACCT is not set 173# CONFIG_BSD_PROCESS_ACCT is not set
174CONFIG_SYSCTL=y 174CONFIG_SYSCTL=y
175# CONFIG_AUDIT is not set 175# CONFIG_AUDIT is not set
176CONFIG_HOTPLUG=y
177CONFIG_KOBJECT_UEVENT=y
178# CONFIG_IKCONFIG is not set 176# CONFIG_IKCONFIG is not set
179CONFIG_CPUSETS=y 177CONFIG_CPUSETS=y
180CONFIG_INITRAMFS_SOURCE="" 178CONFIG_INITRAMFS_SOURCE=""
179# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
181CONFIG_EMBEDDED=y 180CONFIG_EMBEDDED=y
182CONFIG_KALLSYMS=y 181CONFIG_KALLSYMS=y
183# CONFIG_KALLSYMS_EXTRA_PASS is not set 182# CONFIG_KALLSYMS_EXTRA_PASS is not set
183CONFIG_HOTPLUG=y
184CONFIG_PRINTK=y 184CONFIG_PRINTK=y
185CONFIG_BUG=y 185CONFIG_BUG=y
186CONFIG_ELF_CORE=y
186CONFIG_BASE_FULL=y 187CONFIG_BASE_FULL=y
187CONFIG_FUTEX=y 188CONFIG_FUTEX=y
188CONFIG_EPOLL=y 189CONFIG_EPOLL=y
189# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
190CONFIG_SHMEM=y 190CONFIG_SHMEM=y
191CONFIG_CC_ALIGN_FUNCTIONS=0 191CONFIG_CC_ALIGN_FUNCTIONS=0
192CONFIG_CC_ALIGN_LABELS=0 192CONFIG_CC_ALIGN_LABELS=0
193CONFIG_CC_ALIGN_LOOPS=0 193CONFIG_CC_ALIGN_LOOPS=0
194CONFIG_CC_ALIGN_JUMPS=0 194CONFIG_CC_ALIGN_JUMPS=0
195CONFIG_SLAB=y
195# CONFIG_TINY_SHMEM is not set 196# CONFIG_TINY_SHMEM is not set
196CONFIG_BASE_SMALL=0 197CONFIG_BASE_SMALL=0
198# CONFIG_SLOB is not set
197 199
198# 200#
199# Loadable module support 201# Loadable module support
@@ -247,7 +249,6 @@ CONFIG_MMU=y
247# 249#
248CONFIG_BINFMT_ELF=y 250CONFIG_BINFMT_ELF=y
249# CONFIG_BINFMT_MISC is not set 251# CONFIG_BINFMT_MISC is not set
250# CONFIG_BUILD_ELF64 is not set
251CONFIG_MIPS32_COMPAT=y 252CONFIG_MIPS32_COMPAT=y
252CONFIG_COMPAT=y 253CONFIG_COMPAT=y
253CONFIG_MIPS32_O32=y 254CONFIG_MIPS32_O32=y
@@ -309,6 +310,11 @@ CONFIG_TCP_CONG_BIC=y
309# CONFIG_ATALK is not set 310# CONFIG_ATALK is not set
310# CONFIG_X25 is not set 311# CONFIG_X25 is not set
311# CONFIG_LAPB is not set 312# CONFIG_LAPB is not set
313
314#
315# TIPC Configuration (EXPERIMENTAL)
316#
317# CONFIG_TIPC is not set
312# CONFIG_NET_DIVERT is not set 318# CONFIG_NET_DIVERT is not set
313# CONFIG_ECONET is not set 319# CONFIG_ECONET is not set
314# CONFIG_WAN_ROUTER is not set 320# CONFIG_WAN_ROUTER is not set
@@ -329,7 +335,6 @@ CONFIG_IEEE80211=m
329# CONFIG_IEEE80211_DEBUG is not set 335# CONFIG_IEEE80211_DEBUG is not set
330CONFIG_IEEE80211_CRYPT_WEP=m 336CONFIG_IEEE80211_CRYPT_WEP=m
331CONFIG_IEEE80211_CRYPT_CCMP=m 337CONFIG_IEEE80211_CRYPT_CCMP=m
332CONFIG_IEEE80211_CRYPT_TKIP=m
333 338
334# 339#
335# Device Drivers 340# Device Drivers
@@ -472,6 +477,7 @@ CONFIG_MII=y
472# CONFIG_SUNGEM is not set 477# CONFIG_SUNGEM is not set
473# CONFIG_CASSINI is not set 478# CONFIG_CASSINI is not set
474# CONFIG_NET_VENDOR_3COM is not set 479# CONFIG_NET_VENDOR_3COM is not set
480# CONFIG_DM9000 is not set
475 481
476# 482#
477# Tulip family network device support 483# Tulip family network device support
@@ -493,6 +499,7 @@ CONFIG_MII=y
493CONFIG_NET_SB1250_MAC=y 499CONFIG_NET_SB1250_MAC=y
494# CONFIG_SIS190 is not set 500# CONFIG_SIS190 is not set
495# CONFIG_SKGE is not set 501# CONFIG_SKGE is not set
502# CONFIG_SKY2 is not set
496# CONFIG_SK98LIN is not set 503# CONFIG_SK98LIN is not set
497# CONFIG_TIGON3 is not set 504# CONFIG_TIGON3 is not set
498# CONFIG_BNX2 is not set 505# CONFIG_BNX2 is not set
@@ -513,8 +520,6 @@ CONFIG_NET_SB1250_MAC=y
513# Wireless LAN (non-hamradio) 520# Wireless LAN (non-hamradio)
514# 521#
515# CONFIG_NET_RADIO is not set 522# CONFIG_NET_RADIO is not set
516# CONFIG_IPW_DEBUG is not set
517CONFIG_IPW2200=m
518 523
519# 524#
520# Wan interfaces 525# Wan interfaces
@@ -560,12 +565,15 @@ CONFIG_SERIO_RAW=m
560# 565#
561# CONFIG_VT is not set 566# CONFIG_VT is not set
562CONFIG_SERIAL_NONSTANDARD=y 567CONFIG_SERIAL_NONSTANDARD=y
568# CONFIG_COMPUTONE is not set
563# CONFIG_ROCKETPORT is not set 569# CONFIG_ROCKETPORT is not set
564# CONFIG_CYCLADES is not set 570# CONFIG_CYCLADES is not set
565# CONFIG_DIGIEPCA is not set 571# CONFIG_DIGIEPCA is not set
572# CONFIG_MOXA_INTELLIO is not set
566# CONFIG_MOXA_SMARTIO is not set 573# CONFIG_MOXA_SMARTIO is not set
567# CONFIG_ISI is not set 574# CONFIG_ISI is not set
568# CONFIG_SYNCLINKMP is not set 575# CONFIG_SYNCLINKMP is not set
576# CONFIG_SYNCLINK_GT is not set
569# CONFIG_N_HDLC is not set 577# CONFIG_N_HDLC is not set
570# CONFIG_SPECIALIX is not set 578# CONFIG_SPECIALIX is not set
571# CONFIG_SX is not set 579# CONFIG_SX is not set
@@ -581,7 +589,6 @@ CONFIG_SIBYTE_SB1250_DUART_CONSOLE=y
581# 589#
582# Non-8250 serial port support 590# Non-8250 serial port support
583# 591#
584# CONFIG_SERIAL_JSM is not set
585CONFIG_UNIX98_PTYS=y 592CONFIG_UNIX98_PTYS=y
586CONFIG_LEGACY_PTYS=y 593CONFIG_LEGACY_PTYS=y
587CONFIG_LEGACY_PTY_COUNT=256 594CONFIG_LEGACY_PTY_COUNT=256
@@ -619,6 +626,12 @@ CONFIG_LEGACY_PTY_COUNT=256
619# CONFIG_I2C is not set 626# CONFIG_I2C is not set
620 627
621# 628#
629# SPI support
630#
631# CONFIG_SPI is not set
632# CONFIG_SPI_MASTER is not set
633
634#
622# Dallas's 1-wire bus 635# Dallas's 1-wire bus
623# 636#
624# CONFIG_W1 is not set 637# CONFIG_W1 is not set
@@ -696,12 +709,12 @@ CONFIG_EXT2_FS_POSIX_ACL=y
696CONFIG_EXT2_FS_SECURITY=y 709CONFIG_EXT2_FS_SECURITY=y
697# CONFIG_EXT2_FS_XIP is not set 710# CONFIG_EXT2_FS_XIP is not set
698# CONFIG_EXT3_FS is not set 711# CONFIG_EXT3_FS is not set
699# CONFIG_JBD is not set
700CONFIG_FS_MBCACHE=y 712CONFIG_FS_MBCACHE=y
701# CONFIG_REISERFS_FS is not set 713# CONFIG_REISERFS_FS is not set
702# CONFIG_JFS_FS is not set 714# CONFIG_JFS_FS is not set
703CONFIG_FS_POSIX_ACL=y 715CONFIG_FS_POSIX_ACL=y
704# CONFIG_XFS_FS is not set 716# CONFIG_XFS_FS is not set
717# CONFIG_OCFS2_FS is not set
705# CONFIG_MINIX_FS is not set 718# CONFIG_MINIX_FS is not set
706# CONFIG_ROMFS_FS is not set 719# CONFIG_ROMFS_FS is not set
707CONFIG_INOTIFY=y 720CONFIG_INOTIFY=y
@@ -734,6 +747,7 @@ CONFIG_SYSFS=y
734# CONFIG_HUGETLB_PAGE is not set 747# CONFIG_HUGETLB_PAGE is not set
735CONFIG_RAMFS=y 748CONFIG_RAMFS=y
736CONFIG_RELAYFS_FS=m 749CONFIG_RELAYFS_FS=m
750# CONFIG_CONFIGFS_FS is not set
737 751
738# 752#
739# Miscellaneous filesystems 753# Miscellaneous filesystems
@@ -795,6 +809,7 @@ CONFIG_MSDOS_PARTITION=y
795# Kernel hacking 809# Kernel hacking
796# 810#
797# CONFIG_PRINTK_TIME is not set 811# CONFIG_PRINTK_TIME is not set
812# CONFIG_MAGIC_SYSRQ is not set
798# CONFIG_DEBUG_KERNEL is not set 813# CONFIG_DEBUG_KERNEL is not set
799CONFIG_LOG_BUF_SHIFT=15 814CONFIG_LOG_BUF_SHIFT=15
800CONFIG_CROSSCOMPILE=y 815CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/sead_defconfig b/arch/mips/configs/sead_defconfig
index 41dd70824976..9a936d7b7c0c 100644
--- a/arch/mips/configs/sead_defconfig
+++ b/arch/mips/configs/sead_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:07:10 2005 4# Fri Jan 27 15:40:33 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -153,25 +153,28 @@ CONFIG_LOCALVERSION_AUTO=y
153CONFIG_SYSVIPC=y 153CONFIG_SYSVIPC=y
154# CONFIG_BSD_PROCESS_ACCT is not set 154# CONFIG_BSD_PROCESS_ACCT is not set
155CONFIG_SYSCTL=y 155CONFIG_SYSCTL=y
156# CONFIG_HOTPLUG is not set
157# CONFIG_IKCONFIG is not set 156# CONFIG_IKCONFIG is not set
158CONFIG_INITRAMFS_SOURCE="" 157CONFIG_INITRAMFS_SOURCE=""
158# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
159CONFIG_EMBEDDED=y 159CONFIG_EMBEDDED=y
160CONFIG_KALLSYMS=y 160CONFIG_KALLSYMS=y
161# CONFIG_KALLSYMS_EXTRA_PASS is not set 161# CONFIG_KALLSYMS_EXTRA_PASS is not set
162# CONFIG_HOTPLUG is not set
162CONFIG_PRINTK=y 163CONFIG_PRINTK=y
163CONFIG_BUG=y 164CONFIG_BUG=y
165CONFIG_ELF_CORE=y
164CONFIG_BASE_FULL=y 166CONFIG_BASE_FULL=y
165CONFIG_FUTEX=y 167CONFIG_FUTEX=y
166CONFIG_EPOLL=y 168CONFIG_EPOLL=y
167# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
168CONFIG_SHMEM=y 169CONFIG_SHMEM=y
169CONFIG_CC_ALIGN_FUNCTIONS=0 170CONFIG_CC_ALIGN_FUNCTIONS=0
170CONFIG_CC_ALIGN_LABELS=0 171CONFIG_CC_ALIGN_LABELS=0
171CONFIG_CC_ALIGN_LOOPS=0 172CONFIG_CC_ALIGN_LOOPS=0
172CONFIG_CC_ALIGN_JUMPS=0 173CONFIG_CC_ALIGN_JUMPS=0
174CONFIG_SLAB=y
173# CONFIG_TINY_SHMEM is not set 175# CONFIG_TINY_SHMEM is not set
174CONFIG_BASE_SMALL=0 176CONFIG_BASE_SMALL=0
177# CONFIG_SLOB is not set
175 178
176# 179#
177# Loadable module support 180# Loadable module support
@@ -330,6 +333,7 @@ CONFIG_RAID_ATTRS=y
330CONFIG_SERIAL_8250=y 333CONFIG_SERIAL_8250=y
331CONFIG_SERIAL_8250_CONSOLE=y 334CONFIG_SERIAL_8250_CONSOLE=y
332CONFIG_SERIAL_8250_NR_UARTS=4 335CONFIG_SERIAL_8250_NR_UARTS=4
336CONFIG_SERIAL_8250_RUNTIME_UARTS=4
333# CONFIG_SERIAL_8250_EXTENDED is not set 337# CONFIG_SERIAL_8250_EXTENDED is not set
334 338
335# 339#
@@ -372,6 +376,12 @@ CONFIG_LEGACY_PTY_COUNT=256
372# CONFIG_I2C is not set 376# CONFIG_I2C is not set
373 377
374# 378#
379# SPI support
380#
381# CONFIG_SPI is not set
382# CONFIG_SPI_MASTER is not set
383
384#
375# Dallas's 1-wire bus 385# Dallas's 1-wire bus
376# 386#
377# CONFIG_W1 is not set 387# CONFIG_W1 is not set
@@ -444,7 +454,6 @@ CONFIG_EXT2_FS=y
444# CONFIG_EXT2_FS_XATTR is not set 454# CONFIG_EXT2_FS_XATTR is not set
445# CONFIG_EXT2_FS_XIP is not set 455# CONFIG_EXT2_FS_XIP is not set
446# CONFIG_EXT3_FS is not set 456# CONFIG_EXT3_FS is not set
447# CONFIG_JBD is not set
448# CONFIG_REISERFS_FS is not set 457# CONFIG_REISERFS_FS is not set
449# CONFIG_JFS_FS is not set 458# CONFIG_JFS_FS is not set
450# CONFIG_FS_POSIX_ACL is not set 459# CONFIG_FS_POSIX_ACL is not set
@@ -481,6 +490,7 @@ CONFIG_SYSFS=y
481# CONFIG_HUGETLB_PAGE is not set 490# CONFIG_HUGETLB_PAGE is not set
482CONFIG_RAMFS=y 491CONFIG_RAMFS=y
483CONFIG_RELAYFS_FS=y 492CONFIG_RELAYFS_FS=y
493# CONFIG_CONFIGFS_FS is not set
484 494
485# 495#
486# Miscellaneous filesystems 496# Miscellaneous filesystems
@@ -513,6 +523,7 @@ CONFIG_PARTITION_ADVANCED=y
513# CONFIG_SGI_PARTITION is not set 523# CONFIG_SGI_PARTITION is not set
514# CONFIG_ULTRIX_PARTITION is not set 524# CONFIG_ULTRIX_PARTITION is not set
515# CONFIG_SUN_PARTITION is not set 525# CONFIG_SUN_PARTITION is not set
526# CONFIG_KARMA_PARTITION is not set
516# CONFIG_EFI_PARTITION is not set 527# CONFIG_EFI_PARTITION is not set
517 528
518# 529#
@@ -529,6 +540,7 @@ CONFIG_PARTITION_ADVANCED=y
529# Kernel hacking 540# Kernel hacking
530# 541#
531# CONFIG_PRINTK_TIME is not set 542# CONFIG_PRINTK_TIME is not set
543# CONFIG_MAGIC_SYSRQ is not set
532# CONFIG_DEBUG_KERNEL is not set 544# CONFIG_DEBUG_KERNEL is not set
533CONFIG_LOG_BUF_SHIFT=14 545CONFIG_LOG_BUF_SHIFT=14
534CONFIG_CROSSCOMPILE=y 546CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/tb0226_defconfig b/arch/mips/configs/tb0226_defconfig
index 83969466ecf6..c2dee0d1c72c 100644
--- a/arch/mips/configs/tb0226_defconfig
+++ b/arch/mips/configs/tb0226_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:07:12 2005 4# Fri Jan 27 15:40:34 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -63,11 +63,12 @@ CONFIG_MACH_VR41XX=y
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
66# CONFIG_NEC_CMBVR4133 is not set
67# CONFIG_CASIO_E55 is not set 66# CONFIG_CASIO_E55 is not set
68# CONFIG_IBM_WORKPAD is not set 67# CONFIG_IBM_WORKPAD is not set
68# CONFIG_NEC_CMBVR4133 is not set
69CONFIG_TANBAC_TB022X=y 69CONFIG_TANBAC_TB022X=y
70CONFIG_TANBAC_TB0226=y 70CONFIG_TANBAC_TB0226=y
71CONFIG_TANBAC_TB0287=y
71# CONFIG_VICTOR_MPC30X is not set 72# CONFIG_VICTOR_MPC30X is not set
72# CONFIG_ZAO_CAPCELLA is not set 73# CONFIG_ZAO_CAPCELLA is not set
73CONFIG_PCI_VR41XX=y 74CONFIG_PCI_VR41XX=y
@@ -91,7 +92,7 @@ CONFIG_MIPS_L1_CACHE_SHIFT=5
91# CONFIG_CPU_MIPS64_R2 is not set 92# CONFIG_CPU_MIPS64_R2 is not set
92# CONFIG_CPU_R3000 is not set 93# CONFIG_CPU_R3000 is not set
93# CONFIG_CPU_TX39XX is not set 94# CONFIG_CPU_TX39XX is not set
94CONFIG_CPU_VR41XX=y 95# CONFIG_CPU_VR41XX is not set
95# CONFIG_CPU_R4300 is not set 96# CONFIG_CPU_R4300 is not set
96# CONFIG_CPU_R4X00 is not set 97# CONFIG_CPU_R4X00 is not set
97# CONFIG_CPU_TX49XX is not set 98# CONFIG_CPU_TX49XX is not set
@@ -104,23 +105,18 @@ CONFIG_CPU_VR41XX=y
104# CONFIG_CPU_RM7000 is not set 105# CONFIG_CPU_RM7000 is not set
105# CONFIG_CPU_RM9000 is not set 106# CONFIG_CPU_RM9000 is not set
106# CONFIG_CPU_SB1 is not set 107# CONFIG_CPU_SB1 is not set
107CONFIG_SYS_HAS_CPU_VR41XX=y
108CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
109CONFIG_SYS_SUPPORTS_64BIT_KERNEL=y
110CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
111CONFIG_CPU_SUPPORTS_64BIT_KERNEL=y
112 108
113# 109#
114# Kernel type 110# Kernel type
115# 111#
116CONFIG_32BIT=y 112# CONFIG_32BIT is not set
117# CONFIG_64BIT is not set 113# CONFIG_64BIT is not set
118CONFIG_PAGE_SIZE_4KB=y 114CONFIG_PAGE_SIZE_4KB=y
119# CONFIG_PAGE_SIZE_8KB is not set 115# CONFIG_PAGE_SIZE_8KB is not set
120# CONFIG_PAGE_SIZE_16KB is not set 116# CONFIG_PAGE_SIZE_16KB is not set
121# CONFIG_PAGE_SIZE_64KB is not set 117# CONFIG_PAGE_SIZE_64KB is not set
122# CONFIG_MIPS_MT is not set 118# CONFIG_MIPS_MT is not set
123# CONFIG_CPU_ADVANCED is not set 119CONFIG_CPU_HAS_LLSC=y
124CONFIG_CPU_HAS_SYNC=y 120CONFIG_CPU_HAS_SYNC=y
125CONFIG_GENERIC_HARDIRQS=y 121CONFIG_GENERIC_HARDIRQS=y
126CONFIG_GENERIC_IRQ_PROBE=y 122CONFIG_GENERIC_IRQ_PROBE=y
@@ -156,26 +152,28 @@ CONFIG_SYSVIPC=y
156# CONFIG_BSD_PROCESS_ACCT is not set 152# CONFIG_BSD_PROCESS_ACCT is not set
157CONFIG_SYSCTL=y 153CONFIG_SYSCTL=y
158# CONFIG_AUDIT is not set 154# CONFIG_AUDIT is not set
159# CONFIG_HOTPLUG is not set
160CONFIG_KOBJECT_UEVENT=y
161# CONFIG_IKCONFIG is not set 155# CONFIG_IKCONFIG is not set
162CONFIG_INITRAMFS_SOURCE="" 156CONFIG_INITRAMFS_SOURCE=""
157# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
163CONFIG_EMBEDDED=y 158CONFIG_EMBEDDED=y
164CONFIG_KALLSYMS=y 159CONFIG_KALLSYMS=y
165# CONFIG_KALLSYMS_EXTRA_PASS is not set 160# CONFIG_KALLSYMS_EXTRA_PASS is not set
161CONFIG_HOTPLUG=y
166CONFIG_PRINTK=y 162CONFIG_PRINTK=y
167CONFIG_BUG=y 163CONFIG_BUG=y
164CONFIG_ELF_CORE=y
168CONFIG_BASE_FULL=y 165CONFIG_BASE_FULL=y
169CONFIG_FUTEX=y 166CONFIG_FUTEX=y
170CONFIG_EPOLL=y 167CONFIG_EPOLL=y
171# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
172CONFIG_SHMEM=y 168CONFIG_SHMEM=y
173CONFIG_CC_ALIGN_FUNCTIONS=0 169CONFIG_CC_ALIGN_FUNCTIONS=0
174CONFIG_CC_ALIGN_LABELS=0 170CONFIG_CC_ALIGN_LABELS=0
175CONFIG_CC_ALIGN_LOOPS=0 171CONFIG_CC_ALIGN_LOOPS=0
176CONFIG_CC_ALIGN_JUMPS=0 172CONFIG_CC_ALIGN_JUMPS=0
173CONFIG_SLAB=y
177# CONFIG_TINY_SHMEM is not set 174# CONFIG_TINY_SHMEM is not set
178CONFIG_BASE_SMALL=0 175CONFIG_BASE_SMALL=0
176# CONFIG_SLOB is not set
179 177
180# 178#
181# Loadable module support 179# Loadable module support
@@ -191,7 +189,6 @@ CONFIG_KMOD=y
191# 189#
192# Block layer 190# Block layer
193# 191#
194# CONFIG_LBD is not set
195 192
196# 193#
197# IO Schedulers 194# IO Schedulers
@@ -229,7 +226,6 @@ CONFIG_MMU=y
229# 226#
230CONFIG_BINFMT_ELF=y 227CONFIG_BINFMT_ELF=y
231# CONFIG_BINFMT_MISC is not set 228# CONFIG_BINFMT_MISC is not set
232CONFIG_TRAD_SIGNALS=y
233 229
234# 230#
235# Networking 231# Networking
@@ -293,6 +289,11 @@ CONFIG_TCP_CONG_BIC=y
293# CONFIG_ATALK is not set 289# CONFIG_ATALK is not set
294# CONFIG_X25 is not set 290# CONFIG_X25 is not set
295# CONFIG_LAPB is not set 291# CONFIG_LAPB is not set
292
293#
294# TIPC Configuration (EXPERIMENTAL)
295#
296# CONFIG_TIPC is not set
296# CONFIG_NET_DIVERT is not set 297# CONFIG_NET_DIVERT is not set
297# CONFIG_ECONET is not set 298# CONFIG_ECONET is not set
298# CONFIG_WAN_ROUTER is not set 299# CONFIG_WAN_ROUTER is not set
@@ -313,7 +314,6 @@ CONFIG_IEEE80211=m
313# CONFIG_IEEE80211_DEBUG is not set 314# CONFIG_IEEE80211_DEBUG is not set
314CONFIG_IEEE80211_CRYPT_WEP=m 315CONFIG_IEEE80211_CRYPT_WEP=m
315CONFIG_IEEE80211_CRYPT_CCMP=m 316CONFIG_IEEE80211_CRYPT_CCMP=m
316CONFIG_IEEE80211_CRYPT_TKIP=m
317 317
318# 318#
319# Device Drivers 319# Device Drivers
@@ -324,7 +324,7 @@ CONFIG_IEEE80211_CRYPT_TKIP=m
324# 324#
325CONFIG_STANDALONE=y 325CONFIG_STANDALONE=y
326CONFIG_PREVENT_FIRMWARE_BUILD=y 326CONFIG_PREVENT_FIRMWARE_BUILD=y
327# CONFIG_FW_LOADER is not set 327CONFIG_FW_LOADER=y
328 328
329# 329#
330# Connector - unified userspace <-> kernelspace linker 330# Connector - unified userspace <-> kernelspace linker
@@ -397,7 +397,7 @@ CONFIG_SCSI_MULTI_LUN=y
397# SCSI Transport Attributes 397# SCSI Transport Attributes
398# 398#
399# CONFIG_SCSI_SPI_ATTRS is not set 399# CONFIG_SCSI_SPI_ATTRS is not set
400# CONFIG_SCSI_FC_ATTRS is not set 400CONFIG_SCSI_FC_ATTRS=y
401CONFIG_SCSI_ISCSI_ATTRS=m 401CONFIG_SCSI_ISCSI_ATTRS=m
402# CONFIG_SCSI_SAS_ATTRS is not set 402# CONFIG_SCSI_SAS_ATTRS is not set
403 403
@@ -426,13 +426,7 @@ CONFIG_ISCSI_TCP=m
426# CONFIG_SCSI_IPR is not set 426# CONFIG_SCSI_IPR is not set
427# CONFIG_SCSI_QLOGIC_FC is not set 427# CONFIG_SCSI_QLOGIC_FC is not set
428# CONFIG_SCSI_QLOGIC_1280 is not set 428# CONFIG_SCSI_QLOGIC_1280 is not set
429CONFIG_SCSI_QLA2XXX=y 429# CONFIG_SCSI_QLA_FC is not set
430# CONFIG_SCSI_QLA21XX is not set
431# CONFIG_SCSI_QLA22XX is not set
432# CONFIG_SCSI_QLA2300 is not set
433# CONFIG_SCSI_QLA2322 is not set
434# CONFIG_SCSI_QLA6312 is not set
435# CONFIG_SCSI_QLA24XX is not set
436# CONFIG_SCSI_LPFC is not set 430# CONFIG_SCSI_LPFC is not set
437# CONFIG_SCSI_DC395x is not set 431# CONFIG_SCSI_DC395x is not set
438# CONFIG_SCSI_DC390T is not set 432# CONFIG_SCSI_DC390T is not set
@@ -499,6 +493,7 @@ CONFIG_MII=y
499# CONFIG_SUNGEM is not set 493# CONFIG_SUNGEM is not set
500# CONFIG_CASSINI is not set 494# CONFIG_CASSINI is not set
501# CONFIG_NET_VENDOR_3COM is not set 495# CONFIG_NET_VENDOR_3COM is not set
496# CONFIG_DM9000 is not set
502 497
503# 498#
504# Tulip family network device support 499# Tulip family network device support
@@ -538,6 +533,7 @@ CONFIG_EEPRO100=y
538# CONFIG_R8169 is not set 533# CONFIG_R8169 is not set
539# CONFIG_SIS190 is not set 534# CONFIG_SIS190 is not set
540# CONFIG_SKGE is not set 535# CONFIG_SKGE is not set
536# CONFIG_SKY2 is not set
541# CONFIG_SK98LIN is not set 537# CONFIG_SK98LIN is not set
542# CONFIG_VIA_VELOCITY is not set 538# CONFIG_VIA_VELOCITY is not set
543# CONFIG_TIGON3 is not set 539# CONFIG_TIGON3 is not set
@@ -559,7 +555,6 @@ CONFIG_EEPRO100=y
559# Wireless LAN (non-hamradio) 555# Wireless LAN (non-hamradio)
560# 556#
561# CONFIG_NET_RADIO is not set 557# CONFIG_NET_RADIO is not set
562# CONFIG_IPW2200 is not set
563 558
564# 559#
565# Wan interfaces 560# Wan interfaces
@@ -630,11 +625,6 @@ CONFIG_HW_CONSOLE=y
630# 625#
631# Non-8250 serial port support 626# Non-8250 serial port support
632# 627#
633CONFIG_SERIAL_CORE=y
634CONFIG_SERIAL_CORE_CONSOLE=y
635CONFIG_SERIAL_VR41XX=y
636CONFIG_SERIAL_VR41XX_CONSOLE=y
637# CONFIG_SERIAL_JSM is not set
638CONFIG_UNIX98_PTYS=y 628CONFIG_UNIX98_PTYS=y
639CONFIG_LEGACY_PTYS=y 629CONFIG_LEGACY_PTYS=y
640CONFIG_LEGACY_PTY_COUNT=256 630CONFIG_LEGACY_PTY_COUNT=256
@@ -650,7 +640,6 @@ CONFIG_LEGACY_PTY_COUNT=256
650# CONFIG_WATCHDOG is not set 640# CONFIG_WATCHDOG is not set
651# CONFIG_RTC is not set 641# CONFIG_RTC is not set
652# CONFIG_GEN_RTC is not set 642# CONFIG_GEN_RTC is not set
653# CONFIG_RTC_VR41XX is not set
654# CONFIG_DTLK is not set 643# CONFIG_DTLK is not set
655# CONFIG_R3964 is not set 644# CONFIG_R3964 is not set
656# CONFIG_APPLICOM is not set 645# CONFIG_APPLICOM is not set
@@ -675,6 +664,12 @@ CONFIG_GPIO_VR41XX=y
675# CONFIG_I2C is not set 664# CONFIG_I2C is not set
676 665
677# 666#
667# SPI support
668#
669# CONFIG_SPI is not set
670# CONFIG_SPI_MASTER is not set
671
672#
678# Dallas's 1-wire bus 673# Dallas's 1-wire bus
679# 674#
680# CONFIG_W1 is not set 675# CONFIG_W1 is not set
@@ -770,6 +765,8 @@ CONFIG_USB_STORAGE=m
770# CONFIG_USB_STORAGE_SDDR09 is not set 765# CONFIG_USB_STORAGE_SDDR09 is not set
771# CONFIG_USB_STORAGE_SDDR55 is not set 766# CONFIG_USB_STORAGE_SDDR55 is not set
772# CONFIG_USB_STORAGE_JUMPSHOT is not set 767# CONFIG_USB_STORAGE_JUMPSHOT is not set
768# CONFIG_USB_STORAGE_ALAUDA is not set
769# CONFIG_USB_LIBUSUAL is not set
773 770
774# 771#
775# USB Input Devices 772# USB Input Devices
@@ -792,6 +789,7 @@ CONFIG_USB_STORAGE=m
792# CONFIG_USB_YEALINK is not set 789# CONFIG_USB_YEALINK is not set
793# CONFIG_USB_XPAD is not set 790# CONFIG_USB_XPAD is not set
794# CONFIG_USB_ATI_REMOTE is not set 791# CONFIG_USB_ATI_REMOTE is not set
792# CONFIG_USB_ATI_REMOTE2 is not set
795# CONFIG_USB_KEYSPAN_REMOTE is not set 793# CONFIG_USB_KEYSPAN_REMOTE is not set
796# CONFIG_USB_APPLETOUCH is not set 794# CONFIG_USB_APPLETOUCH is not set
797 795
@@ -877,11 +875,11 @@ CONFIG_EXT2_FS=y
877# CONFIG_EXT2_FS_XATTR is not set 875# CONFIG_EXT2_FS_XATTR is not set
878# CONFIG_EXT2_FS_XIP is not set 876# CONFIG_EXT2_FS_XIP is not set
879# CONFIG_EXT3_FS is not set 877# CONFIG_EXT3_FS is not set
880# CONFIG_JBD is not set
881# CONFIG_REISERFS_FS is not set 878# CONFIG_REISERFS_FS is not set
882# CONFIG_JFS_FS is not set 879# CONFIG_JFS_FS is not set
883# CONFIG_FS_POSIX_ACL is not set 880# CONFIG_FS_POSIX_ACL is not set
884# CONFIG_XFS_FS is not set 881# CONFIG_XFS_FS is not set
882# CONFIG_OCFS2_FS is not set
885# CONFIG_MINIX_FS is not set 883# CONFIG_MINIX_FS is not set
886CONFIG_ROMFS_FS=m 884CONFIG_ROMFS_FS=m
887CONFIG_INOTIFY=y 885CONFIG_INOTIFY=y
@@ -914,6 +912,7 @@ CONFIG_TMPFS=y
914# CONFIG_HUGETLB_PAGE is not set 912# CONFIG_HUGETLB_PAGE is not set
915CONFIG_RAMFS=y 913CONFIG_RAMFS=y
916CONFIG_RELAYFS_FS=m 914CONFIG_RELAYFS_FS=m
915# CONFIG_CONFIGFS_FS is not set
917 916
918# 917#
919# Miscellaneous filesystems 918# Miscellaneous filesystems
@@ -1021,6 +1020,7 @@ CONFIG_NLS_ISO8859_1=m
1021# Kernel hacking 1020# Kernel hacking
1022# 1021#
1023# CONFIG_PRINTK_TIME is not set 1022# CONFIG_PRINTK_TIME is not set
1023# CONFIG_MAGIC_SYSRQ is not set
1024# CONFIG_DEBUG_KERNEL is not set 1024# CONFIG_DEBUG_KERNEL is not set
1025CONFIG_LOG_BUF_SHIFT=14 1025CONFIG_LOG_BUF_SHIFT=14
1026CONFIG_CROSSCOMPILE=y 1026CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/tb0229_defconfig b/arch/mips/configs/tb0229_defconfig
index ce7b9ed44432..be99261d7997 100644
--- a/arch/mips/configs/tb0229_defconfig
+++ b/arch/mips/configs/tb0229_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:07:15 2005 4# Fri Jan 27 15:40:35 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -63,11 +63,12 @@ CONFIG_MACH_VR41XX=y
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
66# CONFIG_NEC_CMBVR4133 is not set
67# CONFIG_CASIO_E55 is not set 66# CONFIG_CASIO_E55 is not set
68# CONFIG_IBM_WORKPAD is not set 67# CONFIG_IBM_WORKPAD is not set
68# CONFIG_NEC_CMBVR4133 is not set
69CONFIG_TANBAC_TB022X=y 69CONFIG_TANBAC_TB022X=y
70# CONFIG_TANBAC_TB0226 is not set 70# CONFIG_TANBAC_TB0226 is not set
71CONFIG_TANBAC_TB0287=y
71# CONFIG_VICTOR_MPC30X is not set 72# CONFIG_VICTOR_MPC30X is not set
72# CONFIG_ZAO_CAPCELLA is not set 73# CONFIG_ZAO_CAPCELLA is not set
73CONFIG_PCI_VR41XX=y 74CONFIG_PCI_VR41XX=y
@@ -91,7 +92,7 @@ CONFIG_MIPS_L1_CACHE_SHIFT=5
91# CONFIG_CPU_MIPS64_R2 is not set 92# CONFIG_CPU_MIPS64_R2 is not set
92# CONFIG_CPU_R3000 is not set 93# CONFIG_CPU_R3000 is not set
93# CONFIG_CPU_TX39XX is not set 94# CONFIG_CPU_TX39XX is not set
94CONFIG_CPU_VR41XX=y 95# CONFIG_CPU_VR41XX is not set
95# CONFIG_CPU_R4300 is not set 96# CONFIG_CPU_R4300 is not set
96# CONFIG_CPU_R4X00 is not set 97# CONFIG_CPU_R4X00 is not set
97# CONFIG_CPU_TX49XX is not set 98# CONFIG_CPU_TX49XX is not set
@@ -104,23 +105,18 @@ CONFIG_CPU_VR41XX=y
104# CONFIG_CPU_RM7000 is not set 105# CONFIG_CPU_RM7000 is not set
105# CONFIG_CPU_RM9000 is not set 106# CONFIG_CPU_RM9000 is not set
106# CONFIG_CPU_SB1 is not set 107# CONFIG_CPU_SB1 is not set
107CONFIG_SYS_HAS_CPU_VR41XX=y
108CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
109CONFIG_SYS_SUPPORTS_64BIT_KERNEL=y
110CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
111CONFIG_CPU_SUPPORTS_64BIT_KERNEL=y
112 108
113# 109#
114# Kernel type 110# Kernel type
115# 111#
116CONFIG_32BIT=y 112# CONFIG_32BIT is not set
117# CONFIG_64BIT is not set 113# CONFIG_64BIT is not set
118CONFIG_PAGE_SIZE_4KB=y 114CONFIG_PAGE_SIZE_4KB=y
119# CONFIG_PAGE_SIZE_8KB is not set 115# CONFIG_PAGE_SIZE_8KB is not set
120# CONFIG_PAGE_SIZE_16KB is not set 116# CONFIG_PAGE_SIZE_16KB is not set
121# CONFIG_PAGE_SIZE_64KB is not set 117# CONFIG_PAGE_SIZE_64KB is not set
122# CONFIG_MIPS_MT is not set 118# CONFIG_MIPS_MT is not set
123# CONFIG_CPU_ADVANCED is not set 119CONFIG_CPU_HAS_LLSC=y
124CONFIG_CPU_HAS_SYNC=y 120CONFIG_CPU_HAS_SYNC=y
125CONFIG_GENERIC_HARDIRQS=y 121CONFIG_GENERIC_HARDIRQS=y
126CONFIG_GENERIC_IRQ_PROBE=y 122CONFIG_GENERIC_IRQ_PROBE=y
@@ -156,26 +152,28 @@ CONFIG_SYSVIPC=y
156# CONFIG_BSD_PROCESS_ACCT is not set 152# CONFIG_BSD_PROCESS_ACCT is not set
157CONFIG_SYSCTL=y 153CONFIG_SYSCTL=y
158# CONFIG_AUDIT is not set 154# CONFIG_AUDIT is not set
159CONFIG_HOTPLUG=y
160CONFIG_KOBJECT_UEVENT=y
161# CONFIG_IKCONFIG is not set 155# CONFIG_IKCONFIG is not set
162CONFIG_INITRAMFS_SOURCE="" 156CONFIG_INITRAMFS_SOURCE=""
157# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
163CONFIG_EMBEDDED=y 158CONFIG_EMBEDDED=y
164CONFIG_KALLSYMS=y 159CONFIG_KALLSYMS=y
165# CONFIG_KALLSYMS_EXTRA_PASS is not set 160# CONFIG_KALLSYMS_EXTRA_PASS is not set
161CONFIG_HOTPLUG=y
166CONFIG_PRINTK=y 162CONFIG_PRINTK=y
167CONFIG_BUG=y 163CONFIG_BUG=y
164CONFIG_ELF_CORE=y
168CONFIG_BASE_FULL=y 165CONFIG_BASE_FULL=y
169CONFIG_FUTEX=y 166CONFIG_FUTEX=y
170CONFIG_EPOLL=y 167CONFIG_EPOLL=y
171# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
172CONFIG_SHMEM=y 168CONFIG_SHMEM=y
173CONFIG_CC_ALIGN_FUNCTIONS=0 169CONFIG_CC_ALIGN_FUNCTIONS=0
174CONFIG_CC_ALIGN_LABELS=0 170CONFIG_CC_ALIGN_LABELS=0
175CONFIG_CC_ALIGN_LOOPS=0 171CONFIG_CC_ALIGN_LOOPS=0
176CONFIG_CC_ALIGN_JUMPS=0 172CONFIG_CC_ALIGN_JUMPS=0
173CONFIG_SLAB=y
177# CONFIG_TINY_SHMEM is not set 174# CONFIG_TINY_SHMEM is not set
178CONFIG_BASE_SMALL=0 175CONFIG_BASE_SMALL=0
176# CONFIG_SLOB is not set
179 177
180# 178#
181# Loadable module support 179# Loadable module support
@@ -191,7 +189,6 @@ CONFIG_KMOD=y
191# 189#
192# Block layer 190# Block layer
193# 191#
194# CONFIG_LBD is not set
195 192
196# 193#
197# IO Schedulers 194# IO Schedulers
@@ -229,7 +226,6 @@ CONFIG_MMU=y
229# 226#
230CONFIG_BINFMT_ELF=y 227CONFIG_BINFMT_ELF=y
231# CONFIG_BINFMT_MISC is not set 228# CONFIG_BINFMT_MISC is not set
232CONFIG_TRAD_SIGNALS=y
233 229
234# 230#
235# Networking 231# Networking
@@ -294,6 +290,11 @@ CONFIG_TCP_CONG_BIC=y
294# CONFIG_ATALK is not set 290# CONFIG_ATALK is not set
295# CONFIG_X25 is not set 291# CONFIG_X25 is not set
296# CONFIG_LAPB is not set 292# CONFIG_LAPB is not set
293
294#
295# TIPC Configuration (EXPERIMENTAL)
296#
297# CONFIG_TIPC is not set
297# CONFIG_NET_DIVERT is not set 298# CONFIG_NET_DIVERT is not set
298# CONFIG_ECONET is not set 299# CONFIG_ECONET is not set
299# CONFIG_WAN_ROUTER is not set 300# CONFIG_WAN_ROUTER is not set
@@ -314,7 +315,6 @@ CONFIG_IEEE80211=m
314# CONFIG_IEEE80211_DEBUG is not set 315# CONFIG_IEEE80211_DEBUG is not set
315CONFIG_IEEE80211_CRYPT_WEP=m 316CONFIG_IEEE80211_CRYPT_WEP=m
316CONFIG_IEEE80211_CRYPT_CCMP=m 317CONFIG_IEEE80211_CRYPT_CCMP=m
317CONFIG_IEEE80211_CRYPT_TKIP=m
318 318
319# 319#
320# Device Drivers 320# Device Drivers
@@ -436,6 +436,7 @@ CONFIG_MII=y
436# CONFIG_SUNGEM is not set 436# CONFIG_SUNGEM is not set
437# CONFIG_CASSINI is not set 437# CONFIG_CASSINI is not set
438# CONFIG_NET_VENDOR_3COM is not set 438# CONFIG_NET_VENDOR_3COM is not set
439# CONFIG_DM9000 is not set
439 440
440# 441#
441# Tulip family network device support 442# Tulip family network device support
@@ -480,6 +481,7 @@ CONFIG_R8169=y
480# CONFIG_R8169_NAPI is not set 481# CONFIG_R8169_NAPI is not set
481# CONFIG_SIS190 is not set 482# CONFIG_SIS190 is not set
482# CONFIG_SKGE is not set 483# CONFIG_SKGE is not set
484# CONFIG_SKY2 is not set
483# CONFIG_SK98LIN is not set 485# CONFIG_SK98LIN is not set
484# CONFIG_VIA_VELOCITY is not set 486# CONFIG_VIA_VELOCITY is not set
485# CONFIG_TIGON3 is not set 487# CONFIG_TIGON3 is not set
@@ -501,8 +503,6 @@ CONFIG_R8169=y
501# Wireless LAN (non-hamradio) 503# Wireless LAN (non-hamradio)
502# 504#
503# CONFIG_NET_RADIO is not set 505# CONFIG_NET_RADIO is not set
504# CONFIG_IPW_DEBUG is not set
505CONFIG_IPW2200=m
506 506
507# 507#
508# Wan interfaces 508# Wan interfaces
@@ -583,11 +583,6 @@ CONFIG_HW_CONSOLE=y
583# 583#
584# Non-8250 serial port support 584# Non-8250 serial port support
585# 585#
586CONFIG_SERIAL_CORE=y
587CONFIG_SERIAL_CORE_CONSOLE=y
588CONFIG_SERIAL_VR41XX=y
589CONFIG_SERIAL_VR41XX_CONSOLE=y
590# CONFIG_SERIAL_JSM is not set
591CONFIG_UNIX98_PTYS=y 586CONFIG_UNIX98_PTYS=y
592CONFIG_LEGACY_PTYS=y 587CONFIG_LEGACY_PTYS=y
593CONFIG_LEGACY_PTY_COUNT=256 588CONFIG_LEGACY_PTY_COUNT=256
@@ -603,7 +598,6 @@ CONFIG_LEGACY_PTY_COUNT=256
603# CONFIG_WATCHDOG is not set 598# CONFIG_WATCHDOG is not set
604# CONFIG_RTC is not set 599# CONFIG_RTC is not set
605# CONFIG_GEN_RTC is not set 600# CONFIG_GEN_RTC is not set
606# CONFIG_RTC_VR41XX is not set
607# CONFIG_DTLK is not set 601# CONFIG_DTLK is not set
608# CONFIG_R3964 is not set 602# CONFIG_R3964 is not set
609# CONFIG_APPLICOM is not set 603# CONFIG_APPLICOM is not set
@@ -613,7 +607,6 @@ CONFIG_TANBAC_TB0219=y
613# Ftape, the floppy tape device driver 607# Ftape, the floppy tape device driver
614# 608#
615# CONFIG_DRM is not set 609# CONFIG_DRM is not set
616CONFIG_GPIO_VR41XX=y
617# CONFIG_RAW_DRIVER is not set 610# CONFIG_RAW_DRIVER is not set
618 611
619# 612#
@@ -628,6 +621,12 @@ CONFIG_GPIO_VR41XX=y
628# CONFIG_I2C is not set 621# CONFIG_I2C is not set
629 622
630# 623#
624# SPI support
625#
626# CONFIG_SPI is not set
627# CONFIG_SPI_MASTER is not set
628
629#
631# Dallas's 1-wire bus 630# Dallas's 1-wire bus
632# 631#
633# CONFIG_W1 is not set 632# CONFIG_W1 is not set
@@ -715,6 +714,7 @@ CONFIG_USB_OHCI_LITTLE_ENDIAN=y
715# may also be needed; see USB_STORAGE Help for more information 714# may also be needed; see USB_STORAGE Help for more information
716# 715#
717# CONFIG_USB_STORAGE is not set 716# CONFIG_USB_STORAGE is not set
717# CONFIG_USB_LIBUSUAL is not set
718 718
719# 719#
720# USB Input Devices 720# USB Input Devices
@@ -737,6 +737,7 @@ CONFIG_USB_OHCI_LITTLE_ENDIAN=y
737# CONFIG_USB_YEALINK is not set 737# CONFIG_USB_YEALINK is not set
738# CONFIG_USB_XPAD is not set 738# CONFIG_USB_XPAD is not set
739# CONFIG_USB_ATI_REMOTE is not set 739# CONFIG_USB_ATI_REMOTE is not set
740# CONFIG_USB_ATI_REMOTE2 is not set
740# CONFIG_USB_KEYSPAN_REMOTE is not set 741# CONFIG_USB_KEYSPAN_REMOTE is not set
741# CONFIG_USB_APPLETOUCH is not set 742# CONFIG_USB_APPLETOUCH is not set
742 743
@@ -840,6 +841,7 @@ CONFIG_XFS_QUOTA=y
840# CONFIG_XFS_SECURITY is not set 841# CONFIG_XFS_SECURITY is not set
841CONFIG_XFS_POSIX_ACL=y 842CONFIG_XFS_POSIX_ACL=y
842# CONFIG_XFS_RT is not set 843# CONFIG_XFS_RT is not set
844# CONFIG_OCFS2_FS is not set
843# CONFIG_MINIX_FS is not set 845# CONFIG_MINIX_FS is not set
844CONFIG_ROMFS_FS=m 846CONFIG_ROMFS_FS=m
845CONFIG_INOTIFY=y 847CONFIG_INOTIFY=y
@@ -879,6 +881,7 @@ CONFIG_TMPFS=y
879# CONFIG_HUGETLB_PAGE is not set 881# CONFIG_HUGETLB_PAGE is not set
880CONFIG_RAMFS=y 882CONFIG_RAMFS=y
881CONFIG_RELAYFS_FS=m 883CONFIG_RELAYFS_FS=m
884# CONFIG_CONFIGFS_FS is not set
882 885
883# 886#
884# Miscellaneous filesystems 887# Miscellaneous filesystems
@@ -986,6 +989,7 @@ CONFIG_NLS_ISO8859_1=m
986# Kernel hacking 989# Kernel hacking
987# 990#
988# CONFIG_PRINTK_TIME is not set 991# CONFIG_PRINTK_TIME is not set
992# CONFIG_MAGIC_SYSRQ is not set
989# CONFIG_DEBUG_KERNEL is not set 993# CONFIG_DEBUG_KERNEL is not set
990CONFIG_LOG_BUF_SHIFT=14 994CONFIG_LOG_BUF_SHIFT=14
991CONFIG_CROSSCOMPILE=y 995CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/tb0287_defconfig b/arch/mips/configs/tb0287_defconfig
deleted file mode 100644
index 95344832d66e..000000000000
--- a/arch/mips/configs/tb0287_defconfig
+++ /dev/null
@@ -1,1105 +0,0 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.14-rc5-mm1
4# Tue Oct 25 00:20:22 2005
5#
6CONFIG_MIPS=y
7
8#
9# Code maturity level options
10#
11CONFIG_EXPERIMENTAL=y
12CONFIG_CLEAN_COMPILE=y
13CONFIG_BROKEN_ON_SMP=y
14CONFIG_INIT_ENV_ARG_LIMIT=32
15
16#
17# General setup
18#
19CONFIG_LOCALVERSION=""
20CONFIG_LOCALVERSION_AUTO=y
21CONFIG_SWAP=y
22CONFIG_SWAP_PREFETCH=y
23CONFIG_SYSVIPC=y
24# CONFIG_POSIX_MQUEUE is not set
25# CONFIG_BSD_PROCESS_ACCT is not set
26CONFIG_SYSCTL=y
27# CONFIG_AUDIT is not set
28# CONFIG_HOTPLUG is not set
29CONFIG_KOBJECT_UEVENT=y
30# CONFIG_IKCONFIG is not set
31CONFIG_INITRAMFS_SOURCE=""
32CONFIG_EMBEDDED=y
33CONFIG_KALLSYMS=y
34# CONFIG_KALLSYMS_EXTRA_PASS is not set
35CONFIG_PRINTK=y
36CONFIG_BUG=y
37CONFIG_BASE_FULL=y
38CONFIG_FUTEX=y
39CONFIG_EPOLL=y
40# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
41CONFIG_SHMEM=y
42CONFIG_CC_ALIGN_FUNCTIONS=0
43CONFIG_CC_ALIGN_LABELS=0
44CONFIG_CC_ALIGN_LOOPS=0
45CONFIG_CC_ALIGN_JUMPS=0
46# CONFIG_TINY_SHMEM is not set
47CONFIG_BASE_SMALL=0
48
49#
50# Loadable module support
51#
52CONFIG_MODULES=y
53CONFIG_MODULE_UNLOAD=y
54# CONFIG_MODULE_FORCE_UNLOAD is not set
55CONFIG_OBSOLETE_MODPARM=y
56CONFIG_MODVERSIONS=y
57CONFIG_MODULE_SRCVERSION_ALL=y
58CONFIG_KMOD=y
59
60#
61# Machine selection
62#
63# CONFIG_MIPS_MTX1 is not set
64# CONFIG_MIPS_BOSPORUS is not set
65# CONFIG_MIPS_PB1000 is not set
66# CONFIG_MIPS_PB1100 is not set
67# CONFIG_MIPS_PB1500 is not set
68# CONFIG_MIPS_PB1550 is not set
69# CONFIG_MIPS_PB1200 is not set
70# CONFIG_MIPS_DB1000 is not set
71# CONFIG_MIPS_DB1100 is not set
72# CONFIG_MIPS_DB1500 is not set
73# CONFIG_MIPS_DB1550 is not set
74# CONFIG_MIPS_DB1200 is not set
75# CONFIG_MIPS_MIRAGE is not set
76# CONFIG_MIPS_COBALT is not set
77# CONFIG_MACH_DECSTATION is not set
78# CONFIG_MIPS_EV64120 is not set
79# CONFIG_MIPS_EV96100 is not set
80# CONFIG_MIPS_IVR is not set
81# CONFIG_MIPS_ITE8172 is not set
82# CONFIG_MACH_JAZZ is not set
83# CONFIG_LASAT is not set
84# CONFIG_MIPS_ATLAS is not set
85# CONFIG_MIPS_MALTA is not set
86# CONFIG_MIPS_SEAD is not set
87# CONFIG_MIPS_SIM is not set
88# CONFIG_MOMENCO_JAGUAR_ATX is not set
89# CONFIG_MOMENCO_OCELOT is not set
90# CONFIG_MOMENCO_OCELOT_3 is not set
91# CONFIG_MOMENCO_OCELOT_C is not set
92# CONFIG_MOMENCO_OCELOT_G is not set
93# CONFIG_MIPS_XXS1500 is not set
94# CONFIG_PNX8550_V2PCI is not set
95# CONFIG_PNX8550_JBS is not set
96# CONFIG_DDB5074 is not set
97# CONFIG_DDB5476 is not set
98# CONFIG_DDB5477 is not set
99CONFIG_MACH_VR41XX=y
100# CONFIG_PMC_YOSEMITE is not set
101# CONFIG_QEMU is not set
102# CONFIG_SGI_IP22 is not set
103# CONFIG_SGI_IP27 is not set
104# CONFIG_SGI_IP32 is not set
105# CONFIG_SIBYTE_SWARM is not set
106# CONFIG_SIBYTE_SENTOSA is not set
107# CONFIG_SIBYTE_RHONE is not set
108# CONFIG_SIBYTE_CARMEL is not set
109# CONFIG_SIBYTE_PTSWARM is not set
110# CONFIG_SIBYTE_LITTLESUR is not set
111# CONFIG_SIBYTE_CRHINE is not set
112# CONFIG_SIBYTE_CRHONE is not set
113# CONFIG_SNI_RM200_PCI is not set
114# CONFIG_TOSHIBA_JMR3927 is not set
115# CONFIG_TOSHIBA_RBTX4927 is not set
116# CONFIG_TOSHIBA_RBTX4938 is not set
117# CONFIG_CASIO_E55 is not set
118# CONFIG_IBM_WORKPAD is not set
119# CONFIG_NEC_CMBVR4133 is not set
120CONFIG_TANBAC_TB022X=y
121# CONFIG_TANBAC_TB0226 is not set
122CONFIG_TANBAC_TB0287=y
123# CONFIG_VICTOR_MPC30X is not set
124# CONFIG_ZAO_CAPCELLA is not set
125CONFIG_PCI_VR41XX=y
126# CONFIG_VRC4173 is not set
127CONFIG_RWSEM_GENERIC_SPINLOCK=y
128CONFIG_GENERIC_CALIBRATE_DELAY=y
129CONFIG_DMA_NONCOHERENT=y
130CONFIG_DMA_NEED_PCI_MAP_STATE=y
131# CONFIG_CPU_BIG_ENDIAN is not set
132CONFIG_CPU_LITTLE_ENDIAN=y
133CONFIG_SYS_SUPPORTS_LITTLE_ENDIAN=y
134CONFIG_IRQ_CPU=y
135CONFIG_MIPS_L1_CACHE_SHIFT=5
136
137#
138# CPU selection
139#
140# CONFIG_CPU_MIPS32_R1 is not set
141# CONFIG_CPU_MIPS32_R2 is not set
142# CONFIG_CPU_MIPS64_R1 is not set
143# CONFIG_CPU_MIPS64_R2 is not set
144# CONFIG_CPU_R3000 is not set
145# CONFIG_CPU_TX39XX is not set
146CONFIG_CPU_VR41XX=y
147# CONFIG_CPU_R4300 is not set
148# CONFIG_CPU_R4X00 is not set
149# CONFIG_CPU_TX49XX is not set
150# CONFIG_CPU_R5000 is not set
151# CONFIG_CPU_R5432 is not set
152# CONFIG_CPU_R6000 is not set
153# CONFIG_CPU_NEVADA is not set
154# CONFIG_CPU_R8000 is not set
155# CONFIG_CPU_R10000 is not set
156# CONFIG_CPU_RM7000 is not set
157# CONFIG_CPU_RM9000 is not set
158# CONFIG_CPU_SB1 is not set
159CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
160CONFIG_SYS_SUPPORTS_64BIT_KERNEL=y
161CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
162CONFIG_CPU_SUPPORTS_64BIT_KERNEL=y
163
164#
165# Kernel type
166#
167CONFIG_32BIT=y
168# CONFIG_64BIT is not set
169CONFIG_PAGE_SIZE_4KB=y
170# CONFIG_PAGE_SIZE_8KB is not set
171# CONFIG_PAGE_SIZE_16KB is not set
172# CONFIG_PAGE_SIZE_64KB is not set
173# CONFIG_MIPS_MT is not set
174# CONFIG_CPU_ADVANCED is not set
175CONFIG_CPU_HAS_SYNC=y
176CONFIG_GENERIC_HARDIRQS=y
177CONFIG_GENERIC_IRQ_PROBE=y
178CONFIG_ARCH_FLATMEM_ENABLE=y
179CONFIG_SELECT_MEMORY_MODEL=y
180CONFIG_FLATMEM_MANUAL=y
181# CONFIG_DISCONTIGMEM_MANUAL is not set
182# CONFIG_SPARSEMEM_MANUAL is not set
183CONFIG_FLATMEM=y
184CONFIG_FLAT_NODE_MEM_MAP=y
185# CONFIG_SPARSEMEM_STATIC is not set
186CONFIG_SPLIT_PTLOCK_CPUS=4
187CONFIG_PREEMPT_NONE=y
188# CONFIG_PREEMPT_VOLUNTARY is not set
189# CONFIG_PREEMPT is not set
190
191#
192# Bus options (PCI, PCMCIA, EISA, ISA, TC)
193#
194CONFIG_HW_HAS_PCI=y
195CONFIG_PCI=y
196# CONFIG_PCI_LEGACY_PROC is not set
197CONFIG_MMU=y
198
199#
200# PCCARD (PCMCIA/CardBus) support
201#
202# CONFIG_PCCARD is not set
203
204#
205# PCI Hotplug Support
206#
207# CONFIG_HOTPLUG_PCI is not set
208
209#
210# Executable file formats
211#
212CONFIG_BINFMT_ELF=y
213# CONFIG_BINFMT_MISC is not set
214CONFIG_TRAD_SIGNALS=y
215
216#
217# Networking
218#
219CONFIG_NET=y
220
221#
222# Networking options
223#
224CONFIG_PACKET=y
225# CONFIG_PACKET_MMAP is not set
226CONFIG_UNIX=y
227CONFIG_XFRM=y
228CONFIG_XFRM_USER=m
229# CONFIG_NET_KEY is not set
230CONFIG_INET=y
231CONFIG_IP_MULTICAST=y
232CONFIG_IP_ADVANCED_ROUTER=y
233CONFIG_ASK_IP_FIB_HASH=y
234# CONFIG_IP_FIB_TRIE is not set
235CONFIG_IP_FIB_HASH=y
236CONFIG_IP_MULTIPLE_TABLES=y
237CONFIG_IP_ROUTE_MULTIPATH=y
238# CONFIG_IP_ROUTE_MULTIPATH_CACHED is not set
239CONFIG_IP_ROUTE_VERBOSE=y
240CONFIG_IP_PNP=y
241# CONFIG_IP_PNP_DHCP is not set
242CONFIG_IP_PNP_BOOTP=y
243# CONFIG_IP_PNP_RARP is not set
244CONFIG_NET_IPIP=m
245CONFIG_NET_IPGRE=m
246# CONFIG_NET_IPGRE_BROADCAST is not set
247# CONFIG_IP_MROUTE is not set
248# CONFIG_ARPD is not set
249CONFIG_SYN_COOKIES=y
250# CONFIG_INET_AH is not set
251# CONFIG_INET_ESP is not set
252# CONFIG_INET_IPCOMP is not set
253CONFIG_INET_TUNNEL=m
254CONFIG_INET_DIAG=y
255CONFIG_INET_TCP_DIAG=y
256CONFIG_TCP_CONG_ADVANCED=y
257
258#
259# TCP congestion control
260#
261CONFIG_TCP_CONG_BIC=y
262CONFIG_TCP_CONG_WESTWOOD=m
263CONFIG_TCP_CONG_HTCP=m
264# CONFIG_TCP_CONG_HSTCP is not set
265# CONFIG_TCP_CONG_HYBLA is not set
266# CONFIG_TCP_CONG_VEGAS is not set
267# CONFIG_TCP_CONG_SCALABLE is not set
268# CONFIG_IPV6 is not set
269# CONFIG_NETFILTER is not set
270
271#
272# DCCP Configuration (EXPERIMENTAL)
273#
274# CONFIG_IP_DCCP is not set
275
276#
277# SCTP Configuration (EXPERIMENTAL)
278#
279# CONFIG_IP_SCTP is not set
280# CONFIG_ATM is not set
281# CONFIG_BRIDGE is not set
282# CONFIG_VLAN_8021Q is not set
283# CONFIG_DECNET is not set
284# CONFIG_LLC2 is not set
285# CONFIG_IPX is not set
286# CONFIG_ATALK is not set
287# CONFIG_X25 is not set
288# CONFIG_LAPB is not set
289# CONFIG_NET_DIVERT is not set
290# CONFIG_ECONET is not set
291# CONFIG_WAN_ROUTER is not set
292# CONFIG_NET_SCHED is not set
293# CONFIG_NET_CLS_ROUTE is not set
294
295#
296# Network testing
297#
298# CONFIG_NET_PKTGEN is not set
299# CONFIG_HAMRADIO is not set
300# CONFIG_IRDA is not set
301# CONFIG_BT is not set
302# CONFIG_IEEE80211 is not set
303
304#
305# Device Drivers
306#
307
308#
309# Generic Driver Options
310#
311CONFIG_STANDALONE=y
312CONFIG_PREVENT_FIRMWARE_BUILD=y
313# CONFIG_FW_LOADER is not set
314
315#
316# Connector - unified userspace <-> kernelspace linker
317#
318# CONFIG_CONNECTOR is not set
319
320#
321# Memory Technology Devices (MTD)
322#
323# CONFIG_MTD is not set
324
325#
326# Parallel port support
327#
328# CONFIG_PARPORT is not set
329
330#
331# Plug and Play support
332#
333
334#
335# Block devices
336#
337# CONFIG_BLK_CPQ_DA is not set
338# CONFIG_BLK_CPQ_CISS_DA is not set
339# CONFIG_BLK_DEV_DAC960 is not set
340# CONFIG_BLK_DEV_UMEM is not set
341# CONFIG_BLK_DEV_COW_COMMON is not set
342CONFIG_BLK_DEV_LOOP=m
343# CONFIG_BLK_DEV_CRYPTOLOOP is not set
344CONFIG_BLK_DEV_NBD=m
345# CONFIG_BLK_DEV_SX8 is not set
346# CONFIG_BLK_DEV_UB is not set
347CONFIG_BLK_DEV_RAM=y
348CONFIG_BLK_DEV_RAM_COUNT=16
349CONFIG_BLK_DEV_RAM_SIZE=4096
350# CONFIG_BLK_DEV_INITRD is not set
351# CONFIG_LBD is not set
352# CONFIG_BLK_DEV_IO_TRACE is not set
353# CONFIG_CDROM_PKTCDVD is not set
354
355#
356# IO Schedulers
357#
358CONFIG_IOSCHED_NOOP=y
359CONFIG_IOSCHED_AS=y
360CONFIG_IOSCHED_DEADLINE=y
361CONFIG_IOSCHED_CFQ=y
362CONFIG_DEFAULT_AS=y
363# CONFIG_DEFAULT_DEADLINE is not set
364# CONFIG_DEFAULT_CFQ is not set
365# CONFIG_DEFAULT_NOOP is not set
366CONFIG_DEFAULT_IOSCHED="anticipatory"
367# CONFIG_ATA_OVER_ETH is not set
368
369#
370# ATA/ATAPI/MFM/RLL support
371#
372CONFIG_IDE=y
373CONFIG_BLK_DEV_IDE=y
374
375#
376# Please see Documentation/ide.txt for help/info on IDE drives
377#
378# CONFIG_BLK_DEV_IDE_SATA is not set
379CONFIG_BLK_DEV_IDEDISK=y
380# CONFIG_IDEDISK_MULTI_MODE is not set
381# CONFIG_BLK_DEV_IDECD is not set
382# CONFIG_BLK_DEV_IDETAPE is not set
383# CONFIG_BLK_DEV_IDEFLOPPY is not set
384# CONFIG_BLK_DEV_IDESCSI is not set
385# CONFIG_IDE_TASK_IOCTL is not set
386
387#
388# IDE chipset support/bugfixes
389#
390CONFIG_IDE_GENERIC=y
391CONFIG_BLK_DEV_IDEPCI=y
392# CONFIG_IDEPCI_SHARE_IRQ is not set
393# CONFIG_BLK_DEV_OFFBOARD is not set
394# CONFIG_BLK_DEV_GENERIC is not set
395# CONFIG_BLK_DEV_OPTI621 is not set
396CONFIG_BLK_DEV_IDEDMA_PCI=y
397# CONFIG_BLK_DEV_IDEDMA_FORCED is not set
398# CONFIG_IDEDMA_PCI_AUTO is not set
399# CONFIG_BLK_DEV_AEC62XX is not set
400# CONFIG_BLK_DEV_ALI15X3 is not set
401# CONFIG_BLK_DEV_AMD74XX is not set
402# CONFIG_BLK_DEV_CMD64X is not set
403# CONFIG_BLK_DEV_TRIFLEX is not set
404# CONFIG_BLK_DEV_CY82C693 is not set
405# CONFIG_BLK_DEV_CS5520 is not set
406# CONFIG_BLK_DEV_CS5530 is not set
407# CONFIG_BLK_DEV_HPT34X is not set
408# CONFIG_BLK_DEV_HPT366 is not set
409# CONFIG_BLK_DEV_SC1200 is not set
410# CONFIG_BLK_DEV_PIIX is not set
411# CONFIG_BLK_DEV_IT821X is not set
412# CONFIG_BLK_DEV_NS87415 is not set
413# CONFIG_BLK_DEV_PDC202XX_OLD is not set
414# CONFIG_BLK_DEV_PDC202XX_NEW is not set
415# CONFIG_BLK_DEV_SVWKS is not set
416CONFIG_BLK_DEV_SIIMAGE=y
417# CONFIG_BLK_DEV_SLC90E66 is not set
418# CONFIG_BLK_DEV_TRM290 is not set
419# CONFIG_BLK_DEV_VIA82CXXX is not set
420# CONFIG_IDE_ARM is not set
421CONFIG_BLK_DEV_IDEDMA=y
422# CONFIG_IDEDMA_IVB is not set
423# CONFIG_IDEDMA_AUTO is not set
424# CONFIG_BLK_DEV_HD is not set
425
426#
427# SCSI device support
428#
429# CONFIG_RAID_ATTRS is not set
430CONFIG_SCSI=y
431CONFIG_SCSI_PROC_FS=y
432
433#
434# SCSI support type (disk, tape, CD-ROM)
435#
436CONFIG_BLK_DEV_SD=y
437# CONFIG_CHR_DEV_ST is not set
438# CONFIG_CHR_DEV_OSST is not set
439# CONFIG_BLK_DEV_SR is not set
440# CONFIG_CHR_DEV_SG is not set
441# CONFIG_CHR_DEV_SCH is not set
442
443#
444# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
445#
446# CONFIG_SCSI_MULTI_LUN is not set
447# CONFIG_SCSI_CONSTANTS is not set
448# CONFIG_SCSI_LOGGING is not set
449
450#
451# SCSI Transport Attributes
452#
453# CONFIG_SCSI_SPI_ATTRS is not set
454# CONFIG_SCSI_FC_ATTRS is not set
455# CONFIG_SCSI_ISCSI_ATTRS is not set
456# CONFIG_SCSI_SAS_ATTRS is not set
457
458#
459# SCSI Transport Layers
460#
461# CONFIG_SAS_CLASS is not set
462
463#
464# SCSI low-level drivers
465#
466# CONFIG_ISCSI_TCP is not set
467# CONFIG_SCSI_ARCMSR is not set
468# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
469# CONFIG_SCSI_3W_9XXX is not set
470# CONFIG_SCSI_ACARD is not set
471# CONFIG_SCSI_AACRAID is not set
472# CONFIG_SCSI_AIC7XXX is not set
473# CONFIG_SCSI_AIC7XXX_OLD is not set
474# CONFIG_SCSI_AIC79XX is not set
475# CONFIG_SCSI_DPT_I2O is not set
476# CONFIG_MEGARAID_NEWGEN is not set
477# CONFIG_MEGARAID_LEGACY is not set
478# CONFIG_MEGARAID_SAS is not set
479# CONFIG_SCSI_SATA is not set
480# CONFIG_SCSI_DMX3191D is not set
481# CONFIG_SCSI_FUTURE_DOMAIN is not set
482# CONFIG_SCSI_IPS is not set
483# CONFIG_SCSI_INITIO is not set
484# CONFIG_SCSI_INIA100 is not set
485# CONFIG_SCSI_SYM53C8XX_2 is not set
486# CONFIG_SCSI_IPR is not set
487# CONFIG_SCSI_QLOGIC_FC is not set
488# CONFIG_SCSI_QLOGIC_1280 is not set
489CONFIG_SCSI_QLA2XXX=y
490# CONFIG_SCSI_QLA21XX is not set
491# CONFIG_SCSI_QLA22XX is not set
492# CONFIG_SCSI_QLA2300 is not set
493# CONFIG_SCSI_QLA2322 is not set
494# CONFIG_SCSI_QLA6312 is not set
495# CONFIG_SCSI_QLA24XX is not set
496# CONFIG_SCSI_LPFC is not set
497# CONFIG_SCSI_DC395x is not set
498# CONFIG_SCSI_DC390T is not set
499# CONFIG_SCSI_NSP32 is not set
500# CONFIG_SCSI_DEBUG is not set
501
502#
503# Multi-device support (RAID and LVM)
504#
505# CONFIG_MD is not set
506
507#
508# Fusion MPT device support
509#
510# CONFIG_FUSION is not set
511# CONFIG_FUSION_SPI is not set
512# CONFIG_FUSION_FC is not set
513# CONFIG_FUSION_SAS is not set
514
515#
516# IEEE 1394 (FireWire) support
517#
518CONFIG_IEEE1394=m
519
520#
521# Subsystem Options
522#
523# CONFIG_IEEE1394_VERBOSEDEBUG is not set
524# CONFIG_IEEE1394_OUI_DB is not set
525CONFIG_IEEE1394_EXTRA_CONFIG_ROMS=y
526CONFIG_IEEE1394_CONFIG_ROM_IP1394=y
527# CONFIG_IEEE1394_EXPORT_FULL_API is not set
528
529#
530# Device Drivers
531#
532
533#
534# Texas Instruments PCILynx requires I2C
535#
536CONFIG_IEEE1394_OHCI1394=m
537
538#
539# Protocol Drivers
540#
541CONFIG_IEEE1394_VIDEO1394=m
542CONFIG_IEEE1394_SBP2=m
543# CONFIG_IEEE1394_SBP2_PHYS_DMA is not set
544CONFIG_IEEE1394_ETH1394=m
545CONFIG_IEEE1394_DV1394=m
546CONFIG_IEEE1394_RAWIO=m
547CONFIG_IEEE1394_CMP=m
548CONFIG_IEEE1394_AMDTP=m
549
550#
551# I2O device support
552#
553# CONFIG_I2O is not set
554
555#
556# Network device support
557#
558CONFIG_NETDEVICES=y
559CONFIG_DUMMY=m
560# CONFIG_BONDING is not set
561# CONFIG_EQUALIZER is not set
562# CONFIG_TUN is not set
563
564#
565# ARCnet devices
566#
567# CONFIG_ARCNET is not set
568
569#
570# PHY device support
571#
572# CONFIG_PHYLIB is not set
573
574#
575# Ethernet (10 or 100Mbit)
576#
577CONFIG_NET_ETHERNET=y
578CONFIG_MII=y
579# CONFIG_HAPPYMEAL is not set
580# CONFIG_SUNGEM is not set
581# CONFIG_CASSINI is not set
582# CONFIG_NET_VENDOR_3COM is not set
583
584#
585# Tulip family network device support
586#
587# CONFIG_NET_TULIP is not set
588# CONFIG_HP100 is not set
589# CONFIG_NET_PCI is not set
590
591#
592# Ethernet (1000 Mbit)
593#
594# CONFIG_ACENIC is not set
595# CONFIG_DL2K is not set
596# CONFIG_E1000 is not set
597# CONFIG_NS83820 is not set
598# CONFIG_HAMACHI is not set
599# CONFIG_YELLOWFIN is not set
600CONFIG_R8169=y
601# CONFIG_R8169_NAPI is not set
602# CONFIG_SIS190 is not set
603# CONFIG_SKGE is not set
604# CONFIG_SKY2 is not set
605# CONFIG_SK98LIN is not set
606# CONFIG_TIGON3 is not set
607# CONFIG_BNX2 is not set
608
609#
610# Ethernet (10000 Mbit)
611#
612# CONFIG_CHELSIO_T1 is not set
613# CONFIG_IXGB is not set
614# CONFIG_S2IO is not set
615
616#
617# Token Ring devices
618#
619# CONFIG_TR is not set
620
621#
622# Wireless LAN (non-hamradio)
623#
624# CONFIG_NET_RADIO is not set
625# CONFIG_HOSTAP is not set
626
627#
628# Wan interfaces
629#
630# CONFIG_WAN is not set
631# CONFIG_FDDI is not set
632# CONFIG_HIPPI is not set
633# CONFIG_PPP is not set
634# CONFIG_SLIP is not set
635# CONFIG_NET_FC is not set
636# CONFIG_SHAPER is not set
637# CONFIG_NETCONSOLE is not set
638# CONFIG_KGDBOE is not set
639# CONFIG_NETPOLL is not set
640# CONFIG_NETPOLL_RX is not set
641# CONFIG_NETPOLL_TRAP is not set
642# CONFIG_NET_POLL_CONTROLLER is not set
643
644#
645# ISDN subsystem
646#
647# CONFIG_ISDN is not set
648
649#
650# Telephony Support
651#
652# CONFIG_PHONE is not set
653
654#
655# Input device support
656#
657CONFIG_INPUT=y
658
659#
660# Userland interfaces
661#
662# CONFIG_INPUT_MOUSEDEV is not set
663# CONFIG_INPUT_JOYDEV is not set
664# CONFIG_INPUT_TSDEV is not set
665# CONFIG_INPUT_EVDEV is not set
666# CONFIG_INPUT_EVBUG is not set
667
668#
669# Input Device Drivers
670#
671# CONFIG_INPUT_KEYBOARD is not set
672# CONFIG_INPUT_MOUSE is not set
673# CONFIG_INPUT_JOYSTICK is not set
674# CONFIG_INPUT_TOUCHSCREEN is not set
675# CONFIG_INPUT_MISC is not set
676
677#
678# Hardware I/O ports
679#
680# CONFIG_SERIO is not set
681# CONFIG_GAMEPORT is not set
682
683#
684# Character devices
685#
686CONFIG_VT=y
687CONFIG_VT_CONSOLE=y
688CONFIG_HW_CONSOLE=y
689# CONFIG_SERIAL_NONSTANDARD is not set
690
691#
692# Serial drivers
693#
694# CONFIG_SERIAL_8250 is not set
695
696#
697# Non-8250 serial port support
698#
699CONFIG_SERIAL_CORE=y
700CONFIG_SERIAL_CORE_CONSOLE=y
701CONFIG_SERIAL_VR41XX=y
702CONFIG_SERIAL_VR41XX_CONSOLE=y
703# CONFIG_SERIAL_JSM is not set
704CONFIG_UNIX98_PTYS=y
705CONFIG_LEGACY_PTYS=y
706CONFIG_LEGACY_PTY_COUNT=256
707
708#
709# IPMI
710#
711# CONFIG_IPMI_HANDLER is not set
712
713#
714# Watchdog Cards
715#
716# CONFIG_WATCHDOG is not set
717# CONFIG_RTC is not set
718# CONFIG_GEN_RTC is not set
719# CONFIG_RTC_VR41XX is not set
720# CONFIG_DTLK is not set
721# CONFIG_R3964 is not set
722# CONFIG_APPLICOM is not set
723# CONFIG_TANBAC_TB0219 is not set
724
725#
726# Ftape, the floppy tape device driver
727#
728# CONFIG_DRM is not set
729CONFIG_GPIO_VR41XX=y
730# CONFIG_RAW_DRIVER is not set
731
732#
733# TPM devices
734#
735# CONFIG_TCG_TPM is not set
736# CONFIG_TELCLOCK is not set
737
738#
739# I2C support
740#
741# CONFIG_I2C is not set
742
743#
744# Dallas's 1-wire bus
745#
746# CONFIG_W1 is not set
747
748#
749# Hardware Monitoring support
750#
751# CONFIG_HWMON is not set
752# CONFIG_HWMON_VID is not set
753
754#
755# Misc devices
756#
757
758#
759# Multimedia Capabilities Port drivers
760#
761
762#
763# Multimedia devices
764#
765# CONFIG_VIDEO_DEV is not set
766
767#
768# Digital Video Broadcasting Devices
769#
770# CONFIG_DVB is not set
771
772#
773# Graphics support
774#
775# CONFIG_FB is not set
776
777#
778# Console display driver support
779#
780# CONFIG_VGA_CONSOLE is not set
781CONFIG_DUMMY_CONSOLE=y
782
783#
784# Speakup console speech
785#
786# CONFIG_SPEAKUP is not set
787
788#
789# Sound
790#
791# CONFIG_SOUND is not set
792
793#
794# USB support
795#
796CONFIG_USB_ARCH_HAS_HCD=y
797CONFIG_USB_ARCH_HAS_OHCI=y
798CONFIG_USB=m
799# CONFIG_USB_DEBUG is not set
800
801#
802# Miscellaneous USB options
803#
804# CONFIG_USB_DEVICEFS is not set
805# CONFIG_USB_BANDWIDTH is not set
806# CONFIG_USB_DYNAMIC_MINORS is not set
807# CONFIG_USB_OTG is not set
808
809#
810# USB Host Controller Drivers
811#
812CONFIG_USB_EHCI_HCD=m
813# CONFIG_USB_EHCI_SPLIT_ISO is not set
814# CONFIG_USB_EHCI_ROOT_HUB_TT is not set
815# CONFIG_USB_ISP116X_HCD is not set
816CONFIG_USB_OHCI_HCD=m
817# CONFIG_USB_OHCI_BIG_ENDIAN is not set
818CONFIG_USB_OHCI_LITTLE_ENDIAN=y
819# CONFIG_USB_UHCI_HCD is not set
820# CONFIG_USB_SL811_HCD is not set
821
822#
823# USB Device Class drivers
824#
825# CONFIG_USB_ACM is not set
826# CONFIG_USB_PRINTER is not set
827
828#
829# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
830#
831
832#
833# may also be needed; see USB_STORAGE Help for more information
834#
835CONFIG_USB_STORAGE=m
836# CONFIG_USB_STORAGE_DEBUG is not set
837# CONFIG_USB_STORAGE_DATAFAB is not set
838# CONFIG_USB_STORAGE_FREECOM is not set
839# CONFIG_USB_STORAGE_ISD200 is not set
840# CONFIG_USB_STORAGE_DPCM is not set
841# CONFIG_USB_STORAGE_USBAT is not set
842# CONFIG_USB_STORAGE_SDDR09 is not set
843# CONFIG_USB_STORAGE_SDDR55 is not set
844# CONFIG_USB_STORAGE_JUMPSHOT is not set
845
846#
847# USB Input Devices
848#
849CONFIG_USB_HID=m
850CONFIG_USB_HIDINPUT=y
851# CONFIG_HID_FF is not set
852# CONFIG_USB_HIDDEV is not set
853
854#
855# USB HID Boot Protocol drivers
856#
857# CONFIG_USB_KBD is not set
858# CONFIG_USB_MOUSE is not set
859# CONFIG_USB_AIPTEK is not set
860# CONFIG_USB_WACOM is not set
861# CONFIG_USB_ACECAD is not set
862# CONFIG_USB_KBTAB is not set
863# CONFIG_USB_POWERMATE is not set
864# CONFIG_USB_MTOUCH is not set
865# CONFIG_USB_ITMTOUCH is not set
866# CONFIG_USB_EGALAX is not set
867# CONFIG_USB_YEALINK is not set
868# CONFIG_USB_XPAD is not set
869# CONFIG_USB_ATI_REMOTE is not set
870# CONFIG_USB_KEYSPAN_REMOTE is not set
871# CONFIG_USB_APPLETOUCH is not set
872
873#
874# USB Imaging devices
875#
876# CONFIG_USB_MDC800 is not set
877# CONFIG_USB_MICROTEK is not set
878
879#
880# USB Multimedia devices
881#
882# CONFIG_USB_DABUSB is not set
883
884#
885# Video4Linux support is needed for USB Multimedia device support
886#
887
888#
889# USB Network Adapters
890#
891# CONFIG_USB_CATC is not set
892# CONFIG_USB_KAWETH is not set
893# CONFIG_USB_PEGASUS is not set
894# CONFIG_USB_RTL8150 is not set
895# CONFIG_USB_USBNET is not set
896CONFIG_USB_MON=y
897
898#
899# USB port drivers
900#
901
902#
903# USB Serial Converter support
904#
905# CONFIG_USB_SERIAL is not set
906
907#
908# USB Miscellaneous drivers
909#
910# CONFIG_USB_EMI62 is not set
911# CONFIG_USB_EMI26 is not set
912# CONFIG_USB_AUERSWALD is not set
913# CONFIG_USB_RIO500 is not set
914# CONFIG_USB_LEGOTOWER is not set
915# CONFIG_USB_LCD is not set
916# CONFIG_USB_LED is not set
917# CONFIG_USB_CYTHERM is not set
918# CONFIG_USB_GOTEMP is not set
919# CONFIG_USB_PHIDGETKIT is not set
920# CONFIG_USB_PHIDGETSERVO is not set
921# CONFIG_USB_IDMOUSE is not set
922# CONFIG_USB_SISUSBVGA is not set
923# CONFIG_USB_LD is not set
924
925#
926# USB DSL modem support
927#
928
929#
930# USB Gadget Support
931#
932# CONFIG_USB_GADGET is not set
933
934#
935# MMC/SD Card support
936#
937# CONFIG_MMC is not set
938
939#
940# InfiniBand support
941#
942# CONFIG_INFINIBAND is not set
943
944#
945# SN Devices
946#
947
948#
949# EDAC - error detection and reporting (RAS)
950#
951# CONFIG_EDAC is not set
952
953#
954# Distributed Lock Manager
955#
956# CONFIG_DLM is not set
957
958#
959# File systems
960#
961CONFIG_EXT2_FS=y
962# CONFIG_EXT2_FS_XATTR is not set
963# CONFIG_EXT2_FS_XIP is not set
964CONFIG_EXT3_FS=y
965CONFIG_EXT3_FS_XATTR=y
966# CONFIG_EXT3_FS_POSIX_ACL is not set
967# CONFIG_EXT3_FS_SECURITY is not set
968CONFIG_JBD=y
969# CONFIG_JBD_DEBUG is not set
970CONFIG_FS_MBCACHE=y
971# CONFIG_REISER4_FS is not set
972# CONFIG_REISERFS_FS is not set
973# CONFIG_JFS_FS is not set
974# CONFIG_FS_POSIX_ACL is not set
975CONFIG_XFS_FS=y
976CONFIG_XFS_QUOTA=y
977# CONFIG_XFS_SECURITY is not set
978CONFIG_XFS_POSIX_ACL=y
979# CONFIG_XFS_RT is not set
980# CONFIG_OCFS2_FS is not set
981# CONFIG_MINIX_FS is not set
982CONFIG_ROMFS_FS=m
983CONFIG_INOTIFY=y
984# CONFIG_QUOTA is not set
985CONFIG_QUOTACTL=y
986# CONFIG_DNOTIFY is not set
987# CONFIG_AUTOFS_FS is not set
988CONFIG_AUTOFS4_FS=y
989# CONFIG_FUSE_FS is not set
990
991#
992# CD-ROM/DVD Filesystems
993#
994# CONFIG_ISO9660_FS is not set
995# CONFIG_UDF_FS is not set
996
997#
998# DOS/FAT/NT Filesystems
999#
1000# CONFIG_MSDOS_FS is not set
1001# CONFIG_VFAT_FS is not set
1002# CONFIG_NTFS_FS is not set
1003
1004#
1005# Pseudo filesystems
1006#
1007CONFIG_PROC_FS=y
1008CONFIG_PROC_KCORE=y
1009CONFIG_SYSFS=y
1010CONFIG_TMPFS=y
1011# CONFIG_HUGETLB_PAGE is not set
1012CONFIG_RAMFS=y
1013# CONFIG_RELAYFS_FS is not set
1014# CONFIG_CONFIGFS_FS is not set
1015
1016#
1017# Miscellaneous filesystems
1018#
1019# CONFIG_ADFS_FS is not set
1020# CONFIG_AFFS_FS is not set
1021# CONFIG_ASFS_FS is not set
1022# CONFIG_HFS_FS is not set
1023# CONFIG_HFSPLUS_FS is not set
1024# CONFIG_BEFS_FS is not set
1025# CONFIG_BFS_FS is not set
1026# CONFIG_EFS_FS is not set
1027CONFIG_CRAMFS=m
1028# CONFIG_VXFS_FS is not set
1029# CONFIG_HPFS_FS is not set
1030# CONFIG_QNX4FS_FS is not set
1031# CONFIG_SYSV_FS is not set
1032# CONFIG_UFS_FS is not set
1033
1034#
1035# Network File Systems
1036#
1037CONFIG_NFS_FS=y
1038CONFIG_NFS_V3=y
1039# CONFIG_NFS_V3_ACL is not set
1040# CONFIG_NFS_V4 is not set
1041# CONFIG_NFS_DIRECTIO is not set
1042# CONFIG_NFSD is not set
1043CONFIG_ROOT_NFS=y
1044CONFIG_LOCKD=y
1045CONFIG_LOCKD_V4=y
1046CONFIG_NFS_COMMON=y
1047CONFIG_SUNRPC=y
1048# CONFIG_RPCSEC_GSS_KRB5 is not set
1049# CONFIG_RPCSEC_GSS_SPKM3 is not set
1050# CONFIG_SMB_FS is not set
1051# CONFIG_CIFS is not set
1052# CONFIG_NCP_FS is not set
1053# CONFIG_CODA_FS is not set
1054# CONFIG_AFS_FS is not set
1055# CONFIG_9P_FS is not set
1056
1057#
1058# Partition Types
1059#
1060# CONFIG_PARTITION_ADVANCED is not set
1061CONFIG_MSDOS_PARTITION=y
1062
1063#
1064# Native Language Support
1065#
1066# CONFIG_NLS is not set
1067
1068#
1069# Profiling support
1070#
1071# CONFIG_PROFILING is not set
1072
1073#
1074# Kernel hacking
1075#
1076# CONFIG_PRINTK_TIME is not set
1077# CONFIG_DEBUG_KERNEL is not set
1078CONFIG_LOG_BUF_SHIFT=14
1079CONFIG_CROSSCOMPILE=y
1080CONFIG_CMDLINE="mem=64M console=ttyVR0,115200 ip=any root=/dev/nfs"
1081
1082#
1083# Security options
1084#
1085CONFIG_KEYS=y
1086CONFIG_KEYS_DEBUG_PROC_KEYS=y
1087# CONFIG_SECURITY is not set
1088
1089#
1090# Cryptographic options
1091#
1092# CONFIG_CRYPTO is not set
1093
1094#
1095# Hardware crypto devices
1096#
1097
1098#
1099# Library routines
1100#
1101# CONFIG_CRC_CCITT is not set
1102# CONFIG_CRC16 is not set
1103CONFIG_CRC32=y
1104# CONFIG_LIBCRC32C is not set
1105CONFIG_ZLIB_INFLATE=m
diff --git a/arch/mips/configs/workpad_defconfig b/arch/mips/configs/workpad_defconfig
index 02b2551023d4..7132e296d40a 100644
--- a/arch/mips/configs/workpad_defconfig
+++ b/arch/mips/configs/workpad_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:07:17 2005 4# Fri Jan 27 15:40:36 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -63,9 +63,9 @@ CONFIG_MACH_VR41XX=y
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
66# CONFIG_NEC_CMBVR4133 is not set
67# CONFIG_CASIO_E55 is not set 66# CONFIG_CASIO_E55 is not set
68CONFIG_IBM_WORKPAD=y 67CONFIG_IBM_WORKPAD=y
68# CONFIG_NEC_CMBVR4133 is not set
69# CONFIG_TANBAC_TB022X is not set 69# CONFIG_TANBAC_TB022X is not set
70# CONFIG_VICTOR_MPC30X is not set 70# CONFIG_VICTOR_MPC30X is not set
71# CONFIG_ZAO_CAPCELLA is not set 71# CONFIG_ZAO_CAPCELLA is not set
@@ -88,7 +88,7 @@ CONFIG_MIPS_L1_CACHE_SHIFT=5
88# CONFIG_CPU_MIPS64_R2 is not set 88# CONFIG_CPU_MIPS64_R2 is not set
89# CONFIG_CPU_R3000 is not set 89# CONFIG_CPU_R3000 is not set
90# CONFIG_CPU_TX39XX is not set 90# CONFIG_CPU_TX39XX is not set
91CONFIG_CPU_VR41XX=y 91# CONFIG_CPU_VR41XX is not set
92# CONFIG_CPU_R4300 is not set 92# CONFIG_CPU_R4300 is not set
93# CONFIG_CPU_R4X00 is not set 93# CONFIG_CPU_R4X00 is not set
94# CONFIG_CPU_TX49XX is not set 94# CONFIG_CPU_TX49XX is not set
@@ -101,23 +101,18 @@ CONFIG_CPU_VR41XX=y
101# CONFIG_CPU_RM7000 is not set 101# CONFIG_CPU_RM7000 is not set
102# CONFIG_CPU_RM9000 is not set 102# CONFIG_CPU_RM9000 is not set
103# CONFIG_CPU_SB1 is not set 103# CONFIG_CPU_SB1 is not set
104CONFIG_SYS_HAS_CPU_VR41XX=y
105CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
106CONFIG_SYS_SUPPORTS_64BIT_KERNEL=y
107CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
108CONFIG_CPU_SUPPORTS_64BIT_KERNEL=y
109 104
110# 105#
111# Kernel type 106# Kernel type
112# 107#
113CONFIG_32BIT=y 108# CONFIG_32BIT is not set
114# CONFIG_64BIT is not set 109# CONFIG_64BIT is not set
115CONFIG_PAGE_SIZE_4KB=y 110CONFIG_PAGE_SIZE_4KB=y
116# CONFIG_PAGE_SIZE_8KB is not set 111# CONFIG_PAGE_SIZE_8KB is not set
117# CONFIG_PAGE_SIZE_16KB is not set 112# CONFIG_PAGE_SIZE_16KB is not set
118# CONFIG_PAGE_SIZE_64KB is not set 113# CONFIG_PAGE_SIZE_64KB is not set
119# CONFIG_MIPS_MT is not set 114# CONFIG_MIPS_MT is not set
120# CONFIG_CPU_ADVANCED is not set 115CONFIG_CPU_HAS_LLSC=y
121CONFIG_CPU_HAS_SYNC=y 116CONFIG_CPU_HAS_SYNC=y
122CONFIG_GENERIC_HARDIRQS=y 117CONFIG_GENERIC_HARDIRQS=y
123CONFIG_GENERIC_IRQ_PROBE=y 118CONFIG_GENERIC_IRQ_PROBE=y
@@ -153,26 +148,28 @@ CONFIG_SYSVIPC=y
153# CONFIG_BSD_PROCESS_ACCT is not set 148# CONFIG_BSD_PROCESS_ACCT is not set
154CONFIG_SYSCTL=y 149CONFIG_SYSCTL=y
155# CONFIG_AUDIT is not set 150# CONFIG_AUDIT is not set
156CONFIG_HOTPLUG=y
157CONFIG_KOBJECT_UEVENT=y
158# CONFIG_IKCONFIG is not set 151# CONFIG_IKCONFIG is not set
159CONFIG_INITRAMFS_SOURCE="" 152CONFIG_INITRAMFS_SOURCE=""
153# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
160CONFIG_EMBEDDED=y 154CONFIG_EMBEDDED=y
161CONFIG_KALLSYMS=y 155CONFIG_KALLSYMS=y
162# CONFIG_KALLSYMS_EXTRA_PASS is not set 156# CONFIG_KALLSYMS_EXTRA_PASS is not set
157CONFIG_HOTPLUG=y
163CONFIG_PRINTK=y 158CONFIG_PRINTK=y
164CONFIG_BUG=y 159CONFIG_BUG=y
160CONFIG_ELF_CORE=y
165CONFIG_BASE_FULL=y 161CONFIG_BASE_FULL=y
166CONFIG_FUTEX=y 162CONFIG_FUTEX=y
167CONFIG_EPOLL=y 163CONFIG_EPOLL=y
168# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
169CONFIG_SHMEM=y 164CONFIG_SHMEM=y
170CONFIG_CC_ALIGN_FUNCTIONS=0 165CONFIG_CC_ALIGN_FUNCTIONS=0
171CONFIG_CC_ALIGN_LABELS=0 166CONFIG_CC_ALIGN_LABELS=0
172CONFIG_CC_ALIGN_LOOPS=0 167CONFIG_CC_ALIGN_LOOPS=0
173CONFIG_CC_ALIGN_JUMPS=0 168CONFIG_CC_ALIGN_JUMPS=0
169CONFIG_SLAB=y
174# CONFIG_TINY_SHMEM is not set 170# CONFIG_TINY_SHMEM is not set
175CONFIG_BASE_SMALL=0 171CONFIG_BASE_SMALL=0
172# CONFIG_SLOB is not set
176 173
177# 174#
178# Loadable module support 175# Loadable module support
@@ -188,7 +185,6 @@ CONFIG_KMOD=y
188# 185#
189# Block layer 186# Block layer
190# 187#
191# CONFIG_LBD is not set
192 188
193# 189#
194# IO Schedulers 190# IO Schedulers
@@ -234,7 +230,6 @@ CONFIG_PCMCIA_PROBE=y
234# 230#
235CONFIG_BINFMT_ELF=y 231CONFIG_BINFMT_ELF=y
236# CONFIG_BINFMT_MISC is not set 232# CONFIG_BINFMT_MISC is not set
237CONFIG_TRAD_SIGNALS=y
238 233
239# 234#
240# Networking 235# Networking
@@ -289,6 +284,11 @@ CONFIG_TCP_CONG_BIC=y
289# CONFIG_ATALK is not set 284# CONFIG_ATALK is not set
290# CONFIG_X25 is not set 285# CONFIG_X25 is not set
291# CONFIG_LAPB is not set 286# CONFIG_LAPB is not set
287
288#
289# TIPC Configuration (EXPERIMENTAL)
290#
291# CONFIG_TIPC is not set
292# CONFIG_NET_DIVERT is not set 292# CONFIG_NET_DIVERT is not set
293# CONFIG_ECONET is not set 293# CONFIG_ECONET is not set
294# CONFIG_WAN_ROUTER is not set 294# CONFIG_WAN_ROUTER is not set
@@ -309,7 +309,6 @@ CONFIG_IEEE80211=m
309# CONFIG_IEEE80211_DEBUG is not set 309# CONFIG_IEEE80211_DEBUG is not set
310CONFIG_IEEE80211_CRYPT_WEP=m 310CONFIG_IEEE80211_CRYPT_WEP=m
311CONFIG_IEEE80211_CRYPT_CCMP=m 311CONFIG_IEEE80211_CRYPT_CCMP=m
312CONFIG_IEEE80211_CRYPT_TKIP=m
313 312
314# 313#
315# Device Drivers 314# Device Drivers
@@ -445,6 +444,7 @@ CONFIG_NET_ETHERNET=y
445CONFIG_MII=m 444CONFIG_MII=m
446# CONFIG_NET_VENDOR_3COM is not set 445# CONFIG_NET_VENDOR_3COM is not set
447# CONFIG_NET_VENDOR_SMC is not set 446# CONFIG_NET_VENDOR_SMC is not set
447# CONFIG_DM9000 is not set
448# CONFIG_NET_VENDOR_RACAL is not set 448# CONFIG_NET_VENDOR_RACAL is not set
449# CONFIG_AT1700 is not set 449# CONFIG_AT1700 is not set
450# CONFIG_DEPCA is not set 450# CONFIG_DEPCA is not set
@@ -556,10 +556,6 @@ CONFIG_HW_CONSOLE=y
556# 556#
557# Non-8250 serial port support 557# Non-8250 serial port support
558# 558#
559CONFIG_SERIAL_CORE=y
560CONFIG_SERIAL_CORE_CONSOLE=y
561CONFIG_SERIAL_VR41XX=y
562CONFIG_SERIAL_VR41XX_CONSOLE=y
563CONFIG_UNIX98_PTYS=y 559CONFIG_UNIX98_PTYS=y
564CONFIG_LEGACY_PTYS=y 560CONFIG_LEGACY_PTYS=y
565CONFIG_LEGACY_PTY_COUNT=256 561CONFIG_LEGACY_PTY_COUNT=256
@@ -588,7 +584,6 @@ CONFIG_WATCHDOG=y
588# CONFIG_WDT is not set 584# CONFIG_WDT is not set
589# CONFIG_RTC is not set 585# CONFIG_RTC is not set
590# CONFIG_GEN_RTC is not set 586# CONFIG_GEN_RTC is not set
591# CONFIG_RTC_VR41XX is not set
592# CONFIG_DTLK is not set 587# CONFIG_DTLK is not set
593# CONFIG_R3964 is not set 588# CONFIG_R3964 is not set
594 589
@@ -602,7 +597,6 @@ CONFIG_WATCHDOG=y
602# CONFIG_SYNCLINK_CS is not set 597# CONFIG_SYNCLINK_CS is not set
603# CONFIG_CARDMAN_4000 is not set 598# CONFIG_CARDMAN_4000 is not set
604# CONFIG_CARDMAN_4040 is not set 599# CONFIG_CARDMAN_4040 is not set
605# CONFIG_GPIO_VR41XX is not set
606# CONFIG_RAW_DRIVER is not set 600# CONFIG_RAW_DRIVER is not set
607 601
608# 602#
@@ -617,6 +611,12 @@ CONFIG_WATCHDOG=y
617# CONFIG_I2C is not set 611# CONFIG_I2C is not set
618 612
619# 613#
614# SPI support
615#
616# CONFIG_SPI is not set
617# CONFIG_SPI_MASTER is not set
618
619#
620# Dallas's 1-wire bus 620# Dallas's 1-wire bus
621# 621#
622# CONFIG_W1 is not set 622# CONFIG_W1 is not set
@@ -699,12 +699,12 @@ CONFIG_EXT2_FS_POSIX_ACL=y
699CONFIG_EXT2_FS_SECURITY=y 699CONFIG_EXT2_FS_SECURITY=y
700# CONFIG_EXT2_FS_XIP is not set 700# CONFIG_EXT2_FS_XIP is not set
701# CONFIG_EXT3_FS is not set 701# CONFIG_EXT3_FS is not set
702# CONFIG_JBD is not set
703CONFIG_FS_MBCACHE=y 702CONFIG_FS_MBCACHE=y
704# CONFIG_REISERFS_FS is not set 703# CONFIG_REISERFS_FS is not set
705# CONFIG_JFS_FS is not set 704# CONFIG_JFS_FS is not set
706CONFIG_FS_POSIX_ACL=y 705CONFIG_FS_POSIX_ACL=y
707# CONFIG_XFS_FS is not set 706# CONFIG_XFS_FS is not set
707# CONFIG_OCFS2_FS is not set
708# CONFIG_MINIX_FS is not set 708# CONFIG_MINIX_FS is not set
709# CONFIG_ROMFS_FS is not set 709# CONFIG_ROMFS_FS is not set
710CONFIG_INOTIFY=y 710CONFIG_INOTIFY=y
@@ -737,6 +737,7 @@ CONFIG_SYSFS=y
737# CONFIG_HUGETLB_PAGE is not set 737# CONFIG_HUGETLB_PAGE is not set
738CONFIG_RAMFS=y 738CONFIG_RAMFS=y
739CONFIG_RELAYFS_FS=m 739CONFIG_RELAYFS_FS=m
740# CONFIG_CONFIGFS_FS is not set
740 741
741# 742#
742# Miscellaneous filesystems 743# Miscellaneous filesystems
@@ -798,6 +799,7 @@ CONFIG_MSDOS_PARTITION=y
798# Kernel hacking 799# Kernel hacking
799# 800#
800# CONFIG_PRINTK_TIME is not set 801# CONFIG_PRINTK_TIME is not set
802# CONFIG_MAGIC_SYSRQ is not set
801# CONFIG_DEBUG_KERNEL is not set 803# CONFIG_DEBUG_KERNEL is not set
802CONFIG_LOG_BUF_SHIFT=14 804CONFIG_LOG_BUF_SHIFT=14
803CONFIG_CROSSCOMPILE=y 805CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/configs/yosemite_defconfig b/arch/mips/configs/yosemite_defconfig
index 468c2e443d71..67457850941d 100644
--- a/arch/mips/configs/yosemite_defconfig
+++ b/arch/mips/configs/yosemite_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:07:19 2005 4# Fri Jan 27 15:40:37 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -154,8 +154,6 @@ CONFIG_SYSVIPC=y
154# CONFIG_BSD_PROCESS_ACCT is not set 154# CONFIG_BSD_PROCESS_ACCT is not set
155CONFIG_SYSCTL=y 155CONFIG_SYSCTL=y
156# CONFIG_AUDIT is not set 156# CONFIG_AUDIT is not set
157CONFIG_HOTPLUG=y
158CONFIG_KOBJECT_UEVENT=y
159CONFIG_IKCONFIG=y 157CONFIG_IKCONFIG=y
160CONFIG_IKCONFIG_PROC=y 158CONFIG_IKCONFIG_PROC=y
161# CONFIG_CPUSETS is not set 159# CONFIG_CPUSETS is not set
@@ -164,19 +162,22 @@ CONFIG_EMBEDDED=y
164CONFIG_KALLSYMS=y 162CONFIG_KALLSYMS=y
165# CONFIG_KALLSYMS_ALL is not set 163# CONFIG_KALLSYMS_ALL is not set
166# CONFIG_KALLSYMS_EXTRA_PASS is not set 164# CONFIG_KALLSYMS_EXTRA_PASS is not set
165CONFIG_HOTPLUG=y
167CONFIG_PRINTK=y 166CONFIG_PRINTK=y
168CONFIG_BUG=y 167CONFIG_BUG=y
168CONFIG_ELF_CORE=y
169CONFIG_BASE_FULL=y 169CONFIG_BASE_FULL=y
170CONFIG_FUTEX=y 170CONFIG_FUTEX=y
171CONFIG_EPOLL=y 171CONFIG_EPOLL=y
172# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
173CONFIG_SHMEM=y 172CONFIG_SHMEM=y
174CONFIG_CC_ALIGN_FUNCTIONS=0 173CONFIG_CC_ALIGN_FUNCTIONS=0
175CONFIG_CC_ALIGN_LABELS=0 174CONFIG_CC_ALIGN_LABELS=0
176CONFIG_CC_ALIGN_LOOPS=0 175CONFIG_CC_ALIGN_LOOPS=0
177CONFIG_CC_ALIGN_JUMPS=0 176CONFIG_CC_ALIGN_JUMPS=0
177CONFIG_SLAB=y
178# CONFIG_TINY_SHMEM is not set 178# CONFIG_TINY_SHMEM is not set
179CONFIG_BASE_SMALL=0 179CONFIG_BASE_SMALL=0
180# CONFIG_SLOB is not set
180 181
181# 182#
182# Loadable module support 183# Loadable module support
@@ -184,6 +185,7 @@ CONFIG_BASE_SMALL=0
184CONFIG_MODULES=y 185CONFIG_MODULES=y
185CONFIG_MODULE_UNLOAD=y 186CONFIG_MODULE_UNLOAD=y
186CONFIG_OBSOLETE_MODPARM=y 187CONFIG_OBSOLETE_MODPARM=y
188# CONFIG_MODVERSIONS is not set
187# CONFIG_MODULE_SRCVERSION_ALL is not set 189# CONFIG_MODULE_SRCVERSION_ALL is not set
188CONFIG_KMOD=y 190CONFIG_KMOD=y
189CONFIG_STOP_MACHINE=y 191CONFIG_STOP_MACHINE=y
@@ -295,7 +297,6 @@ CONFIG_IEEE80211=m
295# CONFIG_IEEE80211_DEBUG is not set 297# CONFIG_IEEE80211_DEBUG is not set
296CONFIG_IEEE80211_CRYPT_WEP=m 298CONFIG_IEEE80211_CRYPT_WEP=m
297CONFIG_IEEE80211_CRYPT_CCMP=m 299CONFIG_IEEE80211_CRYPT_CCMP=m
298CONFIG_IEEE80211_CRYPT_TKIP=m
299 300
300# 301#
301# Device Drivers 302# Device Drivers
@@ -413,6 +414,7 @@ CONFIG_MII=y
413# CONFIG_SUNGEM is not set 414# CONFIG_SUNGEM is not set
414# CONFIG_CASSINI is not set 415# CONFIG_CASSINI is not set
415# CONFIG_NET_VENDOR_3COM is not set 416# CONFIG_NET_VENDOR_3COM is not set
417# CONFIG_DM9000 is not set
416 418
417# 419#
418# Tulip family network device support 420# Tulip family network device support
@@ -452,8 +454,6 @@ CONFIG_TITAN_GE=y
452# Wireless LAN (non-hamradio) 454# Wireless LAN (non-hamradio)
453# 455#
454# CONFIG_NET_RADIO is not set 456# CONFIG_NET_RADIO is not set
455# CONFIG_IPW_DEBUG is not set
456CONFIG_IPW2200=m
457 457
458# 458#
459# Wan interfaces 459# Wan interfaces
@@ -498,6 +498,7 @@ CONFIG_IPW2200=m
498CONFIG_SERIAL_8250=y 498CONFIG_SERIAL_8250=y
499CONFIG_SERIAL_8250_CONSOLE=y 499CONFIG_SERIAL_8250_CONSOLE=y
500CONFIG_SERIAL_8250_NR_UARTS=4 500CONFIG_SERIAL_8250_NR_UARTS=4
501CONFIG_SERIAL_8250_RUNTIME_UARTS=4
501# CONFIG_SERIAL_8250_EXTENDED is not set 502# CONFIG_SERIAL_8250_EXTENDED is not set
502 503
503# 504#
@@ -505,7 +506,6 @@ CONFIG_SERIAL_8250_NR_UARTS=4
505# 506#
506CONFIG_SERIAL_CORE=y 507CONFIG_SERIAL_CORE=y
507CONFIG_SERIAL_CORE_CONSOLE=y 508CONFIG_SERIAL_CORE_CONSOLE=y
508# CONFIG_SERIAL_JSM is not set
509CONFIG_UNIX98_PTYS=y 509CONFIG_UNIX98_PTYS=y
510CONFIG_LEGACY_PTYS=y 510CONFIG_LEGACY_PTYS=y
511CONFIG_LEGACY_PTY_COUNT=256 511CONFIG_LEGACY_PTY_COUNT=256
@@ -542,6 +542,12 @@ CONFIG_GEN_RTC_X=y
542# CONFIG_I2C is not set 542# CONFIG_I2C is not set
543 543
544# 544#
545# SPI support
546#
547# CONFIG_SPI is not set
548# CONFIG_SPI_MASTER is not set
549
550#
545# Dallas's 1-wire bus 551# Dallas's 1-wire bus
546# 552#
547# CONFIG_W1 is not set 553# CONFIG_W1 is not set
@@ -615,7 +621,6 @@ CONFIG_USB_ARCH_HAS_OHCI=y
615# 621#
616# CONFIG_EXT2_FS is not set 622# CONFIG_EXT2_FS is not set
617# CONFIG_EXT3_FS is not set 623# CONFIG_EXT3_FS is not set
618# CONFIG_JBD is not set
619# CONFIG_REISERFS_FS is not set 624# CONFIG_REISERFS_FS is not set
620# CONFIG_JFS_FS is not set 625# CONFIG_JFS_FS is not set
621# CONFIG_FS_POSIX_ACL is not set 626# CONFIG_FS_POSIX_ACL is not set
@@ -694,12 +699,13 @@ CONFIG_MSDOS_PARTITION=y
694# Kernel hacking 699# Kernel hacking
695# 700#
696# CONFIG_PRINTK_TIME is not set 701# CONFIG_PRINTK_TIME is not set
697CONFIG_DEBUG_KERNEL=y
698# CONFIG_MAGIC_SYSRQ is not set 702# CONFIG_MAGIC_SYSRQ is not set
703CONFIG_DEBUG_KERNEL=y
699CONFIG_LOG_BUF_SHIFT=14 704CONFIG_LOG_BUF_SHIFT=14
700CONFIG_DETECT_SOFTLOCKUP=y 705CONFIG_DETECT_SOFTLOCKUP=y
701# CONFIG_SCHEDSTATS is not set 706# CONFIG_SCHEDSTATS is not set
702# CONFIG_DEBUG_SLAB is not set 707# CONFIG_DEBUG_SLAB is not set
708CONFIG_DEBUG_MUTEXES=y
703# CONFIG_DEBUG_SPINLOCK is not set 709# CONFIG_DEBUG_SPINLOCK is not set
704# CONFIG_DEBUG_SPINLOCK_SLEEP is not set 710# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
705# CONFIG_DEBUG_KOBJECT is not set 711# CONFIG_DEBUG_KOBJECT is not set
@@ -707,6 +713,7 @@ CONFIG_DETECT_SOFTLOCKUP=y
707# CONFIG_DEBUG_INFO is not set 713# CONFIG_DEBUG_INFO is not set
708# CONFIG_DEBUG_FS is not set 714# CONFIG_DEBUG_FS is not set
709# CONFIG_DEBUG_VM is not set 715# CONFIG_DEBUG_VM is not set
716CONFIG_FORCED_INLINING=y
710# CONFIG_RCU_TORTURE_TEST is not set 717# CONFIG_RCU_TORTURE_TEST is not set
711CONFIG_CROSSCOMPILE=y 718CONFIG_CROSSCOMPILE=y
712CONFIG_CMDLINE="" 719CONFIG_CMDLINE=""
diff --git a/arch/mips/dec/prom/memory.c b/arch/mips/dec/prom/memory.c
index 83d4556c3cb5..81cb5a76cfb7 100644
--- a/arch/mips/dec/prom/memory.c
+++ b/arch/mips/dec/prom/memory.c
@@ -45,7 +45,7 @@ static inline void pmax_setup_memory_region(void)
45 */ 45 */
46 for (memory_page = (unsigned char *)CKSEG1 + CHUNK_SIZE; 46 for (memory_page = (unsigned char *)CKSEG1 + CHUNK_SIZE;
47 mem_err == 0 && memory_page < (unsigned char *)CKSEG1 + 0x1e00000; 47 mem_err == 0 && memory_page < (unsigned char *)CKSEG1 + 0x1e00000;
48 memory_page += CHUNK_SIZE) { 48 memory_page += CHUNK_SIZE) {
49 dummy = *memory_page; 49 dummy = *memory_page;
50 } 50 }
51 memcpy((void *)(CKSEG0 + 0x80), &old_handler, 0x80); 51 memcpy((void *)(CKSEG0 + 0x80), &old_handler, 0x80);
diff --git a/arch/mips/defconfig b/arch/mips/defconfig
index 4f125e9e8e0b..42d5cd7927cb 100644
--- a/arch/mips/defconfig
+++ b/arch/mips/defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.15-rc2 3# Linux kernel version: 2.6.16-rc1
4# Thu Nov 24 01:05:49 2005 4# Fri Jan 27 15:39:51 2006
5# 5#
6CONFIG_MIPS=y 6CONFIG_MIPS=y
7 7
@@ -158,27 +158,29 @@ CONFIG_SYSVIPC=y
158# CONFIG_BSD_PROCESS_ACCT is not set 158# CONFIG_BSD_PROCESS_ACCT is not set
159CONFIG_SYSCTL=y 159CONFIG_SYSCTL=y
160# CONFIG_AUDIT is not set 160# CONFIG_AUDIT is not set
161# CONFIG_HOTPLUG is not set
162CONFIG_KOBJECT_UEVENT=y
163CONFIG_IKCONFIG=y 161CONFIG_IKCONFIG=y
164CONFIG_IKCONFIG_PROC=y 162CONFIG_IKCONFIG_PROC=y
165CONFIG_INITRAMFS_SOURCE="" 163CONFIG_INITRAMFS_SOURCE=""
164# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
166CONFIG_EMBEDDED=y 165CONFIG_EMBEDDED=y
167CONFIG_KALLSYMS=y 166CONFIG_KALLSYMS=y
168# CONFIG_KALLSYMS_EXTRA_PASS is not set 167# CONFIG_KALLSYMS_EXTRA_PASS is not set
168# CONFIG_HOTPLUG is not set
169CONFIG_PRINTK=y 169CONFIG_PRINTK=y
170CONFIG_BUG=y 170CONFIG_BUG=y
171CONFIG_ELF_CORE=y
171CONFIG_BASE_FULL=y 172CONFIG_BASE_FULL=y
172CONFIG_FUTEX=y 173CONFIG_FUTEX=y
173CONFIG_EPOLL=y 174CONFIG_EPOLL=y
174# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
175CONFIG_SHMEM=y 175CONFIG_SHMEM=y
176CONFIG_CC_ALIGN_FUNCTIONS=0 176CONFIG_CC_ALIGN_FUNCTIONS=0
177CONFIG_CC_ALIGN_LABELS=0 177CONFIG_CC_ALIGN_LABELS=0
178CONFIG_CC_ALIGN_LOOPS=0 178CONFIG_CC_ALIGN_LOOPS=0
179CONFIG_CC_ALIGN_JUMPS=0 179CONFIG_CC_ALIGN_JUMPS=0
180CONFIG_SLAB=y
180# CONFIG_TINY_SHMEM is not set 181# CONFIG_TINY_SHMEM is not set
181CONFIG_BASE_SMALL=0 182CONFIG_BASE_SMALL=0
183# CONFIG_SLOB is not set
182 184
183# 185#
184# Loadable module support 186# Loadable module support
@@ -317,6 +319,28 @@ CONFIG_NETFILTER=y
317CONFIG_NETFILTER_NETLINK=m 319CONFIG_NETFILTER_NETLINK=m
318CONFIG_NETFILTER_NETLINK_QUEUE=m 320CONFIG_NETFILTER_NETLINK_QUEUE=m
319CONFIG_NETFILTER_NETLINK_LOG=m 321CONFIG_NETFILTER_NETLINK_LOG=m
322CONFIG_NETFILTER_XTABLES=m
323CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
324CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
325CONFIG_NETFILTER_XT_TARGET_MARK=m
326CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
327CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
328CONFIG_NETFILTER_XT_MATCH_COMMENT=m
329CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
330CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
331CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
332CONFIG_NETFILTER_XT_MATCH_DCCP=m
333CONFIG_NETFILTER_XT_MATCH_HELPER=m
334CONFIG_NETFILTER_XT_MATCH_LENGTH=m
335CONFIG_NETFILTER_XT_MATCH_LIMIT=m
336CONFIG_NETFILTER_XT_MATCH_MAC=m
337CONFIG_NETFILTER_XT_MATCH_MARK=m
338CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
339CONFIG_NETFILTER_XT_MATCH_REALM=m
340CONFIG_NETFILTER_XT_MATCH_SCTP=m
341CONFIG_NETFILTER_XT_MATCH_STATE=m
342CONFIG_NETFILTER_XT_MATCH_STRING=m
343CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
320 344
321# 345#
322# IP: Netfilter Configuration 346# IP: Netfilter Configuration
@@ -335,39 +359,23 @@ CONFIG_IP_NF_AMANDA=m
335CONFIG_IP_NF_PPTP=m 359CONFIG_IP_NF_PPTP=m
336CONFIG_IP_NF_QUEUE=m 360CONFIG_IP_NF_QUEUE=m
337CONFIG_IP_NF_IPTABLES=m 361CONFIG_IP_NF_IPTABLES=m
338CONFIG_IP_NF_MATCH_LIMIT=m
339CONFIG_IP_NF_MATCH_IPRANGE=m 362CONFIG_IP_NF_MATCH_IPRANGE=m
340CONFIG_IP_NF_MATCH_MAC=m
341CONFIG_IP_NF_MATCH_PKTTYPE=m
342CONFIG_IP_NF_MATCH_MARK=m
343CONFIG_IP_NF_MATCH_MULTIPORT=m 363CONFIG_IP_NF_MATCH_MULTIPORT=m
344CONFIG_IP_NF_MATCH_TOS=m 364CONFIG_IP_NF_MATCH_TOS=m
345CONFIG_IP_NF_MATCH_RECENT=m 365CONFIG_IP_NF_MATCH_RECENT=m
346CONFIG_IP_NF_MATCH_ECN=m 366CONFIG_IP_NF_MATCH_ECN=m
347CONFIG_IP_NF_MATCH_DSCP=m 367CONFIG_IP_NF_MATCH_DSCP=m
348CONFIG_IP_NF_MATCH_AH_ESP=m 368CONFIG_IP_NF_MATCH_AH_ESP=m
349CONFIG_IP_NF_MATCH_LENGTH=m
350CONFIG_IP_NF_MATCH_TTL=m 369CONFIG_IP_NF_MATCH_TTL=m
351CONFIG_IP_NF_MATCH_TCPMSS=m
352CONFIG_IP_NF_MATCH_HELPER=m
353CONFIG_IP_NF_MATCH_STATE=m
354CONFIG_IP_NF_MATCH_CONNTRACK=m
355CONFIG_IP_NF_MATCH_OWNER=m 370CONFIG_IP_NF_MATCH_OWNER=m
356CONFIG_IP_NF_MATCH_ADDRTYPE=m 371CONFIG_IP_NF_MATCH_ADDRTYPE=m
357CONFIG_IP_NF_MATCH_REALM=m
358CONFIG_IP_NF_MATCH_SCTP=m
359CONFIG_IP_NF_MATCH_DCCP=m
360CONFIG_IP_NF_MATCH_COMMENT=m
361CONFIG_IP_NF_MATCH_CONNMARK=m
362CONFIG_IP_NF_MATCH_CONNBYTES=m
363CONFIG_IP_NF_MATCH_HASHLIMIT=m 372CONFIG_IP_NF_MATCH_HASHLIMIT=m
364CONFIG_IP_NF_MATCH_STRING=m 373CONFIG_IP_NF_MATCH_POLICY=m
365CONFIG_IP_NF_FILTER=m 374CONFIG_IP_NF_FILTER=m
366CONFIG_IP_NF_TARGET_REJECT=m 375CONFIG_IP_NF_TARGET_REJECT=m
367CONFIG_IP_NF_TARGET_LOG=m 376CONFIG_IP_NF_TARGET_LOG=m
368CONFIG_IP_NF_TARGET_ULOG=m 377CONFIG_IP_NF_TARGET_ULOG=m
369CONFIG_IP_NF_TARGET_TCPMSS=m 378CONFIG_IP_NF_TARGET_TCPMSS=m
370CONFIG_IP_NF_TARGET_NFQUEUE=m
371CONFIG_IP_NF_NAT=m 379CONFIG_IP_NF_NAT=m
372CONFIG_IP_NF_NAT_NEEDED=y 380CONFIG_IP_NF_NAT_NEEDED=y
373CONFIG_IP_NF_TARGET_MASQUERADE=m 381CONFIG_IP_NF_TARGET_MASQUERADE=m
@@ -384,13 +392,9 @@ CONFIG_IP_NF_MANGLE=m
384CONFIG_IP_NF_TARGET_TOS=m 392CONFIG_IP_NF_TARGET_TOS=m
385CONFIG_IP_NF_TARGET_ECN=m 393CONFIG_IP_NF_TARGET_ECN=m
386CONFIG_IP_NF_TARGET_DSCP=m 394CONFIG_IP_NF_TARGET_DSCP=m
387CONFIG_IP_NF_TARGET_MARK=m
388CONFIG_IP_NF_TARGET_CLASSIFY=m
389CONFIG_IP_NF_TARGET_TTL=m 395CONFIG_IP_NF_TARGET_TTL=m
390CONFIG_IP_NF_TARGET_CONNMARK=m
391CONFIG_IP_NF_TARGET_CLUSTERIP=m 396CONFIG_IP_NF_TARGET_CLUSTERIP=m
392CONFIG_IP_NF_RAW=m 397CONFIG_IP_NF_RAW=m
393CONFIG_IP_NF_TARGET_NOTRACK=m
394CONFIG_IP_NF_ARPTABLES=m 398CONFIG_IP_NF_ARPTABLES=m
395CONFIG_IP_NF_ARPFILTER=m 399CONFIG_IP_NF_ARPFILTER=m
396CONFIG_IP_NF_ARP_MANGLE=m 400CONFIG_IP_NF_ARP_MANGLE=m
@@ -400,25 +404,20 @@ CONFIG_IP_NF_ARP_MANGLE=m
400# 404#
401CONFIG_IP6_NF_QUEUE=m 405CONFIG_IP6_NF_QUEUE=m
402CONFIG_IP6_NF_IPTABLES=m 406CONFIG_IP6_NF_IPTABLES=m
403CONFIG_IP6_NF_MATCH_LIMIT=m
404CONFIG_IP6_NF_MATCH_MAC=m
405CONFIG_IP6_NF_MATCH_RT=m 407CONFIG_IP6_NF_MATCH_RT=m
406CONFIG_IP6_NF_MATCH_OPTS=m 408CONFIG_IP6_NF_MATCH_OPTS=m
407CONFIG_IP6_NF_MATCH_FRAG=m 409CONFIG_IP6_NF_MATCH_FRAG=m
408CONFIG_IP6_NF_MATCH_HL=m 410CONFIG_IP6_NF_MATCH_HL=m
409CONFIG_IP6_NF_MATCH_MULTIPORT=m 411CONFIG_IP6_NF_MATCH_MULTIPORT=m
410CONFIG_IP6_NF_MATCH_OWNER=m 412CONFIG_IP6_NF_MATCH_OWNER=m
411CONFIG_IP6_NF_MATCH_MARK=m
412CONFIG_IP6_NF_MATCH_IPV6HEADER=m 413CONFIG_IP6_NF_MATCH_IPV6HEADER=m
413CONFIG_IP6_NF_MATCH_AHESP=m 414CONFIG_IP6_NF_MATCH_AHESP=m
414CONFIG_IP6_NF_MATCH_LENGTH=m
415CONFIG_IP6_NF_MATCH_EUI64=m 415CONFIG_IP6_NF_MATCH_EUI64=m
416CONFIG_IP6_NF_MATCH_POLICY=m
416CONFIG_IP6_NF_FILTER=m 417CONFIG_IP6_NF_FILTER=m
417CONFIG_IP6_NF_TARGET_LOG=m 418CONFIG_IP6_NF_TARGET_LOG=m
418CONFIG_IP6_NF_TARGET_REJECT=m 419CONFIG_IP6_NF_TARGET_REJECT=m
419CONFIG_IP6_NF_TARGET_NFQUEUE=m
420CONFIG_IP6_NF_MANGLE=m 420CONFIG_IP6_NF_MANGLE=m
421CONFIG_IP6_NF_TARGET_MARK=m
422CONFIG_IP6_NF_TARGET_HL=m 421CONFIG_IP6_NF_TARGET_HL=m
423CONFIG_IP6_NF_RAW=m 422CONFIG_IP6_NF_RAW=m
424 423
@@ -445,6 +444,11 @@ CONFIG_SCTP_HMAC_MD5=y
445# CONFIG_ATALK is not set 444# CONFIG_ATALK is not set
446# CONFIG_X25 is not set 445# CONFIG_X25 is not set
447# CONFIG_LAPB is not set 446# CONFIG_LAPB is not set
447
448#
449# TIPC Configuration (EXPERIMENTAL)
450#
451# CONFIG_TIPC is not set
448CONFIG_NET_DIVERT=y 452CONFIG_NET_DIVERT=y
449# CONFIG_ECONET is not set 453# CONFIG_ECONET is not set
450# CONFIG_WAN_ROUTER is not set 454# CONFIG_WAN_ROUTER is not set
@@ -504,7 +508,6 @@ CONFIG_IEEE80211=m
504# CONFIG_IEEE80211_DEBUG is not set 508# CONFIG_IEEE80211_DEBUG is not set
505CONFIG_IEEE80211_CRYPT_WEP=m 509CONFIG_IEEE80211_CRYPT_WEP=m
506CONFIG_IEEE80211_CRYPT_CCMP=m 510CONFIG_IEEE80211_CRYPT_CCMP=m
507CONFIG_IEEE80211_CRYPT_TKIP=m
508 511
509# 512#
510# Device Drivers 513# Device Drivers
@@ -641,6 +644,7 @@ CONFIG_CICADA_PHY=m
641# 644#
642CONFIG_NET_ETHERNET=y 645CONFIG_NET_ETHERNET=y
643# CONFIG_MII is not set 646# CONFIG_MII is not set
647# CONFIG_DM9000 is not set
644CONFIG_SGISEEQ=y 648CONFIG_SGISEEQ=y
645 649
646# 650#
@@ -787,6 +791,12 @@ CONFIG_MAX_RAW_DEVS=256
787# CONFIG_I2C is not set 791# CONFIG_I2C is not set
788 792
789# 793#
794# SPI support
795#
796# CONFIG_SPI is not set
797# CONFIG_SPI_MASTER is not set
798
799#
790# Dallas's 1-wire bus 800# Dallas's 1-wire bus
791# 801#
792# CONFIG_W1 is not set 802# CONFIG_W1 is not set
@@ -892,6 +902,7 @@ CONFIG_XFS_QUOTA=y
892CONFIG_XFS_SECURITY=y 902CONFIG_XFS_SECURITY=y
893# CONFIG_XFS_POSIX_ACL is not set 903# CONFIG_XFS_POSIX_ACL is not set
894# CONFIG_XFS_RT is not set 904# CONFIG_XFS_RT is not set
905# CONFIG_OCFS2_FS is not set
895CONFIG_MINIX_FS=m 906CONFIG_MINIX_FS=m
896# CONFIG_ROMFS_FS is not set 907# CONFIG_ROMFS_FS is not set
897CONFIG_INOTIFY=y 908CONFIG_INOTIFY=y
@@ -934,6 +945,7 @@ CONFIG_SYSFS=y
934# CONFIG_HUGETLB_PAGE is not set 945# CONFIG_HUGETLB_PAGE is not set
935CONFIG_RAMFS=y 946CONFIG_RAMFS=y
936CONFIG_RELAYFS_FS=m 947CONFIG_RELAYFS_FS=m
948# CONFIG_CONFIGFS_FS is not set
937 949
938# 950#
939# Miscellaneous filesystems 951# Miscellaneous filesystems
@@ -1007,6 +1019,7 @@ CONFIG_MSDOS_PARTITION=y
1007CONFIG_SGI_PARTITION=y 1019CONFIG_SGI_PARTITION=y
1008# CONFIG_ULTRIX_PARTITION is not set 1020# CONFIG_ULTRIX_PARTITION is not set
1009# CONFIG_SUN_PARTITION is not set 1021# CONFIG_SUN_PARTITION is not set
1022# CONFIG_KARMA_PARTITION is not set
1010# CONFIG_EFI_PARTITION is not set 1023# CONFIG_EFI_PARTITION is not set
1011 1024
1012# 1025#
@@ -1062,6 +1075,7 @@ CONFIG_NLS_UTF8=m
1062# Kernel hacking 1075# Kernel hacking
1063# 1076#
1064# CONFIG_PRINTK_TIME is not set 1077# CONFIG_PRINTK_TIME is not set
1078# CONFIG_MAGIC_SYSRQ is not set
1065# CONFIG_DEBUG_KERNEL is not set 1079# CONFIG_DEBUG_KERNEL is not set
1066CONFIG_LOG_BUF_SHIFT=14 1080CONFIG_LOG_BUF_SHIFT=14
1067CONFIG_CROSSCOMPILE=y 1081CONFIG_CROSSCOMPILE=y
diff --git a/arch/mips/jazz/int-handler.S b/arch/mips/jazz/int-handler.S
index 4dbcf91db884..dc752c67b528 100644
--- a/arch/mips/jazz/int-handler.S
+++ b/arch/mips/jazz/int-handler.S
@@ -248,17 +248,17 @@ loc_call: /*
248 and t2,s1 248 and t2,s1
249 sh t2,JAZZ_IO_IRQ_ENABLE 249 sh t2,JAZZ_IO_IRQ_ENABLE
250 250
251 nor s1,zero,s1 251 nor s1,zero,s1
252 jal do_IRQ 252 jal do_IRQ
253 253
254 /* 254 /*
255 * Reenable interrupt 255 * Reenable interrupt
256 */ 256 */
257 lhu t2,JAZZ_IO_IRQ_ENABLE 257 lhu t2,JAZZ_IO_IRQ_ENABLE
258 or t2,s1 258 or t2,s1
259 sh t2,JAZZ_IO_IRQ_ENABLE 259 sh t2,JAZZ_IO_IRQ_ENABLE
260 260
261 j ret_from_irq 261 j ret_from_irq
262 262
263/* 263/*
264 * "Jump extender" to reach spurious_interrupt 264 * "Jump extender" to reach spurious_interrupt
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index 292f8b243a5e..58b3b14873cb 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -291,7 +291,7 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
291 * for documentation. Commented out because it shares 291 * for documentation. Commented out because it shares
292 * it's c0_prid id number with the TX3900. 292 * it's c0_prid id number with the TX3900.
293 */ 293 */
294 c->cputype = CPU_R4650; 294 c->cputype = CPU_R4650;
295 c->isa_level = MIPS_CPU_ISA_III; 295 c->isa_level = MIPS_CPU_ISA_III;
296 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC; 296 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
297 c->tlbsize = 48; 297 c->tlbsize = 48;
@@ -604,7 +604,7 @@ static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
604 case PRID_IMP_AU1_REV2: 604 case PRID_IMP_AU1_REV2:
605 switch ((c->processor_id >> 24) & 0xff) { 605 switch ((c->processor_id >> 24) & 0xff) {
606 case 0: 606 case 0:
607 c->cputype = CPU_AU1000; 607 c->cputype = CPU_AU1000;
608 break; 608 break;
609 case 1: 609 case 1:
610 c->cputype = CPU_AU1500; 610 c->cputype = CPU_AU1500;
@@ -705,7 +705,7 @@ __init void cpu_probe(void)
705 break; 705 break;
706 case PRID_COMP_PHILIPS: 706 case PRID_COMP_PHILIPS:
707 cpu_probe_philips(c); 707 cpu_probe_philips(c);
708 break; 708 break;
709 default: 709 default:
710 c->cputype = CPU_UNKNOWN; 710 c->cputype = CPU_UNKNOWN;
711 } 711 }
diff --git a/arch/mips/kernel/gdb-low.S b/arch/mips/kernel/gdb-low.S
index 83b8986f9401..235ad9f6bd35 100644
--- a/arch/mips/kernel/gdb-low.S
+++ b/arch/mips/kernel/gdb-low.S
@@ -41,7 +41,7 @@
41 */ 41 */
42 .align 5 42 .align 5
43 NESTED(trap_low, GDB_FR_SIZE, sp) 43 NESTED(trap_low, GDB_FR_SIZE, sp)
44 .set noat 44 .set noat
45 .set noreorder 45 .set noreorder
46 46
47 mfc0 k0, CP0_STATUS 47 mfc0 k0, CP0_STATUS
diff --git a/arch/mips/kernel/linux32.c b/arch/mips/kernel/linux32.c
index e00e5f6e7fdd..013bc93688e8 100644
--- a/arch/mips/kernel/linux32.c
+++ b/arch/mips/kernel/linux32.c
@@ -69,7 +69,7 @@
69 * Revalidate the inode. This is required for proper NFS attribute caching. 69 * Revalidate the inode. This is required for proper NFS attribute caching.
70 */ 70 */
71 71
72int cp_compat_stat(struct kstat *stat, struct compat_stat *statbuf) 72int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
73{ 73{
74 struct compat_stat tmp; 74 struct compat_stat tmp;
75 75
@@ -106,6 +106,10 @@ sys32_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
106 unsigned long error; 106 unsigned long error;
107 107
108 error = -EINVAL; 108 error = -EINVAL;
109 if (pgoff & (~PAGE_MASK >> 12))
110 goto out;
111 pgoff >>= PAGE_SHIFT-12;
112
109 if (!(flags & MAP_ANONYMOUS)) { 113 if (!(flags & MAP_ANONYMOUS)) {
110 error = -EBADF; 114 error = -EBADF;
111 file = fget(fd); 115 file = fget(fd);
@@ -125,7 +129,7 @@ out:
125} 129}
126 130
127 131
128asmlinkage int sys_truncate64(const char *path, unsigned int high, 132asmlinkage int sys_truncate64(const char __user *path, unsigned int high,
129 unsigned int low) 133 unsigned int low)
130{ 134{
131 if ((int)high < 0) 135 if ((int)high < 0)
@@ -161,12 +165,6 @@ out:
161 return error; 165 return error;
162} 166}
163 167
164asmlinkage int
165sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
166{
167 return compat_sys_wait4(pid, stat_addr, options, NULL);
168}
169
170asmlinkage long 168asmlinkage long
171sysn32_waitid(int which, compat_pid_t pid, 169sysn32_waitid(int which, compat_pid_t pid,
172 siginfo_t __user *uinfo, int options, 170 siginfo_t __user *uinfo, int options,
@@ -175,6 +173,7 @@ sysn32_waitid(int which, compat_pid_t pid,
175 struct rusage ru; 173 struct rusage ru;
176 long ret; 174 long ret;
177 mm_segment_t old_fs = get_fs(); 175 mm_segment_t old_fs = get_fs();
176 int si_signo;
178 177
179 if (!access_ok(VERIFY_WRITE, uinfo, sizeof(*uinfo))) 178 if (!access_ok(VERIFY_WRITE, uinfo, sizeof(*uinfo)))
180 return -EFAULT; 179 return -EFAULT;
@@ -184,7 +183,9 @@ sysn32_waitid(int which, compat_pid_t pid,
184 uru ? (struct rusage __user *) &ru : NULL); 183 uru ? (struct rusage __user *) &ru : NULL);
185 set_fs (old_fs); 184 set_fs (old_fs);
186 185
187 if (ret < 0 || uinfo->si_signo == 0) 186 if (__get_user(si_signo, &uinfo->si_signo))
187 return -EFAULT;
188 if (ret < 0 || si_signo == 0)
188 return ret; 189 return ret;
189 190
190 if (uru) 191 if (uru)
@@ -208,14 +209,14 @@ struct sysinfo32 {
208 char _f[8]; 209 char _f[8];
209}; 210};
210 211
211asmlinkage int sys32_sysinfo(struct sysinfo32 *info) 212asmlinkage int sys32_sysinfo(struct sysinfo32 __user *info)
212{ 213{
213 struct sysinfo s; 214 struct sysinfo s;
214 int ret, err; 215 int ret, err;
215 mm_segment_t old_fs = get_fs (); 216 mm_segment_t old_fs = get_fs ();
216 217
217 set_fs (KERNEL_DS); 218 set_fs (KERNEL_DS);
218 ret = sys_sysinfo(&s); 219 ret = sys_sysinfo((struct sysinfo __user *)&s);
219 set_fs (old_fs); 220 set_fs (old_fs);
220 err = put_user (s.uptime, &info->uptime); 221 err = put_user (s.uptime, &info->uptime);
221 err |= __put_user (s.loads[0], &info->loads[0]); 222 err |= __put_user (s.loads[0], &info->loads[0]);
@@ -245,11 +246,11 @@ struct rlimit32 {
245}; 246};
246 247
247#ifdef __MIPSEB__ 248#ifdef __MIPSEB__
248asmlinkage long sys32_truncate64(const char * path, unsigned long __dummy, 249asmlinkage long sys32_truncate64(const char __user * path, unsigned long __dummy,
249 int length_hi, int length_lo) 250 int length_hi, int length_lo)
250#endif 251#endif
251#ifdef __MIPSEL__ 252#ifdef __MIPSEL__
252asmlinkage long sys32_truncate64(const char * path, unsigned long __dummy, 253asmlinkage long sys32_truncate64(const char __user * path, unsigned long __dummy,
253 int length_lo, int length_hi) 254 int length_lo, int length_hi)
254#endif 255#endif
255{ 256{
@@ -277,7 +278,7 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long __dummy,
277} 278}
278 279
279static inline long 280static inline long
280get_tv32(struct timeval *o, struct compat_timeval *i) 281get_tv32(struct timeval *o, struct compat_timeval __user *i)
281{ 282{
282 return (!access_ok(VERIFY_READ, i, sizeof(*i)) || 283 return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
283 (__get_user(o->tv_sec, &i->tv_sec) | 284 (__get_user(o->tv_sec, &i->tv_sec) |
@@ -285,7 +286,7 @@ get_tv32(struct timeval *o, struct compat_timeval *i)
285} 286}
286 287
287static inline long 288static inline long
288put_tv32(struct compat_timeval *o, struct timeval *i) 289put_tv32(struct compat_timeval __user *o, struct timeval *i)
289{ 290{
290 return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) || 291 return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
291 (__put_user(i->tv_sec, &o->tv_sec) | 292 (__put_user(i->tv_sec, &o->tv_sec) |
@@ -295,7 +296,7 @@ put_tv32(struct compat_timeval *o, struct timeval *i)
295extern struct timezone sys_tz; 296extern struct timezone sys_tz;
296 297
297asmlinkage int 298asmlinkage int
298sys32_gettimeofday(struct compat_timeval *tv, struct timezone *tz) 299sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
299{ 300{
300 if (tv) { 301 if (tv) {
301 struct timeval ktv; 302 struct timeval ktv;
@@ -310,7 +311,7 @@ sys32_gettimeofday(struct compat_timeval *tv, struct timezone *tz)
310 return 0; 311 return 0;
311} 312}
312 313
313static inline long get_ts32(struct timespec *o, struct compat_timeval *i) 314static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
314{ 315{
315 long usec; 316 long usec;
316 317
@@ -325,7 +326,7 @@ static inline long get_ts32(struct timespec *o, struct compat_timeval *i)
325} 326}
326 327
327asmlinkage int 328asmlinkage int
328sys32_settimeofday(struct compat_timeval *tv, struct timezone *tz) 329sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
329{ 330{
330 struct timespec kts; 331 struct timespec kts;
331 struct timezone ktz; 332 struct timezone ktz;
@@ -343,7 +344,7 @@ sys32_settimeofday(struct compat_timeval *tv, struct timezone *tz)
343} 344}
344 345
345asmlinkage int sys32_llseek(unsigned int fd, unsigned int offset_high, 346asmlinkage int sys32_llseek(unsigned int fd, unsigned int offset_high,
346 unsigned int offset_low, loff_t * result, 347 unsigned int offset_low, loff_t __user * result,
347 unsigned int origin) 348 unsigned int origin)
348{ 349{
349 return sys_llseek(fd, offset_high, offset_low, result, origin); 350 return sys_llseek(fd, offset_high, offset_low, result, origin);
@@ -353,12 +354,12 @@ asmlinkage int sys32_llseek(unsigned int fd, unsigned int offset_high,
353 lseek back to original location. They fail just like lseek does on 354 lseek back to original location. They fail just like lseek does on
354 non-seekable files. */ 355 non-seekable files. */
355 356
356asmlinkage ssize_t sys32_pread(unsigned int fd, char * buf, 357asmlinkage ssize_t sys32_pread(unsigned int fd, char __user * buf,
357 size_t count, u32 unused, u64 a4, u64 a5) 358 size_t count, u32 unused, u64 a4, u64 a5)
358{ 359{
359 ssize_t ret; 360 ssize_t ret;
360 struct file * file; 361 struct file * file;
361 ssize_t (*read)(struct file *, char *, size_t, loff_t *); 362 ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
362 loff_t pos; 363 loff_t pos;
363 364
364 ret = -EBADF; 365 ret = -EBADF;
@@ -388,12 +389,12 @@ bad_file:
388 return ret; 389 return ret;
389} 390}
390 391
391asmlinkage ssize_t sys32_pwrite(unsigned int fd, const char * buf, 392asmlinkage ssize_t sys32_pwrite(unsigned int fd, const char __user * buf,
392 size_t count, u32 unused, u64 a4, u64 a5) 393 size_t count, u32 unused, u64 a4, u64 a5)
393{ 394{
394 ssize_t ret; 395 ssize_t ret;
395 struct file * file; 396 struct file * file;
396 ssize_t (*write)(struct file *, const char *, size_t, loff_t *); 397 ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
397 loff_t pos; 398 loff_t pos;
398 399
399 ret = -EBADF; 400 ret = -EBADF;
@@ -426,14 +427,14 @@ bad_file:
426} 427}
427 428
428asmlinkage int sys32_sched_rr_get_interval(compat_pid_t pid, 429asmlinkage int sys32_sched_rr_get_interval(compat_pid_t pid,
429 struct compat_timespec *interval) 430 struct compat_timespec __user *interval)
430{ 431{
431 struct timespec t; 432 struct timespec t;
432 int ret; 433 int ret;
433 mm_segment_t old_fs = get_fs (); 434 mm_segment_t old_fs = get_fs ();
434 435
435 set_fs (KERNEL_DS); 436 set_fs (KERNEL_DS);
436 ret = sys_sched_rr_get_interval(pid, &t); 437 ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
437 set_fs (old_fs); 438 set_fs (old_fs);
438 if (put_user (t.tv_sec, &interval->tv_sec) || 439 if (put_user (t.tv_sec, &interval->tv_sec) ||
439 __put_user (t.tv_nsec, &interval->tv_nsec)) 440 __put_user (t.tv_nsec, &interval->tv_nsec))
@@ -551,7 +552,7 @@ struct ipc_kludge32 {
551}; 552};
552 553
553static int 554static int
554do_sys32_semctl(int first, int second, int third, void *uptr) 555do_sys32_semctl(int first, int second, int third, void __user *uptr)
555{ 556{
556 union semun fourth; 557 union semun fourth;
557 u32 pad; 558 u32 pad;
@@ -562,12 +563,12 @@ do_sys32_semctl(int first, int second, int third, void *uptr)
562 if (!uptr) 563 if (!uptr)
563 return -EINVAL; 564 return -EINVAL;
564 err = -EFAULT; 565 err = -EFAULT;
565 if (get_user (pad, (u32 *)uptr)) 566 if (get_user (pad, (u32 __user *)uptr))
566 return err; 567 return err;
567 if ((third & ~IPC_64) == SETVAL) 568 if ((third & ~IPC_64) == SETVAL)
568 fourth.val = (int)pad; 569 fourth.val = (int)pad;
569 else 570 else
570 fourth.__pad = (void *)A(pad); 571 fourth.__pad = (void __user *)A(pad);
571 switch (third & ~IPC_64) { 572 switch (third & ~IPC_64) {
572 case IPC_INFO: 573 case IPC_INFO:
573 case IPC_RMID: 574 case IPC_RMID:
@@ -585,14 +586,14 @@ do_sys32_semctl(int first, int second, int third, void *uptr)
585 586
586 case IPC_STAT: 587 case IPC_STAT:
587 case SEM_STAT: 588 case SEM_STAT:
588 fourth.__pad = &s; 589 fourth.__pad = (struct semid64_ds __user *)&s;
589 old_fs = get_fs(); 590 old_fs = get_fs();
590 set_fs(KERNEL_DS); 591 set_fs(KERNEL_DS);
591 err = sys_semctl(first, second, third | IPC_64, fourth); 592 err = sys_semctl(first, second, third | IPC_64, fourth);
592 set_fs(old_fs); 593 set_fs(old_fs);
593 594
594 if (third & IPC_64) { 595 if (third & IPC_64) {
595 struct semid64_ds32 *usp64 = (struct semid64_ds32 *) A(pad); 596 struct semid64_ds32 __user *usp64 = (struct semid64_ds32 __user *) A(pad);
596 597
597 if (!access_ok(VERIFY_WRITE, usp64, sizeof(*usp64))) { 598 if (!access_ok(VERIFY_WRITE, usp64, sizeof(*usp64))) {
598 err = -EFAULT; 599 err = -EFAULT;
@@ -609,7 +610,7 @@ do_sys32_semctl(int first, int second, int third, void *uptr)
609 err2 |= __put_user(s.sem_ctime, &usp64->sem_ctime); 610 err2 |= __put_user(s.sem_ctime, &usp64->sem_ctime);
610 err2 |= __put_user(s.sem_nsems, &usp64->sem_nsems); 611 err2 |= __put_user(s.sem_nsems, &usp64->sem_nsems);
611 } else { 612 } else {
612 struct semid_ds32 *usp32 = (struct semid_ds32 *) A(pad); 613 struct semid_ds32 __user *usp32 = (struct semid_ds32 __user *) A(pad);
613 614
614 if (!access_ok(VERIFY_WRITE, usp32, sizeof(*usp32))) { 615 if (!access_ok(VERIFY_WRITE, usp32, sizeof(*usp32))) {
615 err = -EFAULT; 616 err = -EFAULT;
@@ -639,9 +640,9 @@ do_sys32_semctl(int first, int second, int third, void *uptr)
639} 640}
640 641
641static int 642static int
642do_sys32_msgsnd (int first, int second, int third, void *uptr) 643do_sys32_msgsnd (int first, int second, int third, void __user *uptr)
643{ 644{
644 struct msgbuf32 *up = (struct msgbuf32 *)uptr; 645 struct msgbuf32 __user *up = (struct msgbuf32 __user *)uptr;
645 struct msgbuf *p; 646 struct msgbuf *p;
646 mm_segment_t old_fs; 647 mm_segment_t old_fs;
647 int err; 648 int err;
@@ -660,7 +661,7 @@ do_sys32_msgsnd (int first, int second, int third, void *uptr)
660 goto out; 661 goto out;
661 old_fs = get_fs (); 662 old_fs = get_fs ();
662 set_fs (KERNEL_DS); 663 set_fs (KERNEL_DS);
663 err = sys_msgsnd (first, p, second, third); 664 err = sys_msgsnd (first, (struct msgbuf __user *)p, second, third);
664 set_fs (old_fs); 665 set_fs (old_fs);
665out: 666out:
666 kfree (p); 667 kfree (p);
@@ -670,15 +671,15 @@ out:
670 671
671static int 672static int
672do_sys32_msgrcv (int first, int second, int msgtyp, int third, 673do_sys32_msgrcv (int first, int second, int msgtyp, int third,
673 int version, void *uptr) 674 int version, void __user *uptr)
674{ 675{
675 struct msgbuf32 *up; 676 struct msgbuf32 __user *up;
676 struct msgbuf *p; 677 struct msgbuf *p;
677 mm_segment_t old_fs; 678 mm_segment_t old_fs;
678 int err; 679 int err;
679 680
680 if (!version) { 681 if (!version) {
681 struct ipc_kludge32 *uipck = (struct ipc_kludge32 *)uptr; 682 struct ipc_kludge32 __user *uipck = (struct ipc_kludge32 __user *)uptr;
682 struct ipc_kludge32 ipck; 683 struct ipc_kludge32 ipck;
683 684
684 err = -EINVAL; 685 err = -EINVAL;
@@ -687,7 +688,7 @@ do_sys32_msgrcv (int first, int second, int msgtyp, int third,
687 err = -EFAULT; 688 err = -EFAULT;
688 if (copy_from_user (&ipck, uipck, sizeof (struct ipc_kludge32))) 689 if (copy_from_user (&ipck, uipck, sizeof (struct ipc_kludge32)))
689 goto out; 690 goto out;
690 uptr = (void *)AA(ipck.msgp); 691 uptr = (void __user *)AA(ipck.msgp);
691 msgtyp = ipck.msgtyp; 692 msgtyp = ipck.msgtyp;
692 } 693 }
693 694
@@ -699,11 +700,11 @@ do_sys32_msgrcv (int first, int second, int msgtyp, int third,
699 goto out; 700 goto out;
700 old_fs = get_fs (); 701 old_fs = get_fs ();
701 set_fs (KERNEL_DS); 702 set_fs (KERNEL_DS);
702 err = sys_msgrcv (first, p, second + 4, msgtyp, third); 703 err = sys_msgrcv (first, (struct msgbuf __user *)p, second + 4, msgtyp, third);
703 set_fs (old_fs); 704 set_fs (old_fs);
704 if (err < 0) 705 if (err < 0)
705 goto free_then_out; 706 goto free_then_out;
706 up = (struct msgbuf32 *)uptr; 707 up = (struct msgbuf32 __user *)uptr;
707 if (put_user (p->mtype, &up->mtype) || 708 if (put_user (p->mtype, &up->mtype) ||
708 __copy_to_user (&up->mtext, p->mtext, err)) 709 __copy_to_user (&up->mtext, p->mtext, err))
709 err = -EFAULT; 710 err = -EFAULT;
@@ -714,19 +715,19 @@ out:
714} 715}
715 716
716static int 717static int
717do_sys32_msgctl (int first, int second, void *uptr) 718do_sys32_msgctl (int first, int second, void __user *uptr)
718{ 719{
719 int err = -EINVAL, err2; 720 int err = -EINVAL, err2;
720 struct msqid64_ds m; 721 struct msqid64_ds m;
721 struct msqid_ds32 *up32 = (struct msqid_ds32 *)uptr; 722 struct msqid_ds32 __user *up32 = (struct msqid_ds32 __user *)uptr;
722 struct msqid64_ds32 *up64 = (struct msqid64_ds32 *)uptr; 723 struct msqid64_ds32 __user *up64 = (struct msqid64_ds32 __user *)uptr;
723 mm_segment_t old_fs; 724 mm_segment_t old_fs;
724 725
725 switch (second & ~IPC_64) { 726 switch (second & ~IPC_64) {
726 case IPC_INFO: 727 case IPC_INFO:
727 case IPC_RMID: 728 case IPC_RMID:
728 case MSG_INFO: 729 case MSG_INFO:
729 err = sys_msgctl (first, second, (struct msqid_ds *)uptr); 730 err = sys_msgctl (first, second, (struct msqid_ds __user *)uptr);
730 break; 731 break;
731 732
732 case IPC_SET: 733 case IPC_SET:
@@ -753,7 +754,7 @@ do_sys32_msgctl (int first, int second, void *uptr)
753 break; 754 break;
754 old_fs = get_fs(); 755 old_fs = get_fs();
755 set_fs(KERNEL_DS); 756 set_fs(KERNEL_DS);
756 err = sys_msgctl(first, second | IPC_64, (struct msqid_ds *)&m); 757 err = sys_msgctl(first, second | IPC_64, (struct msqid_ds __user *)&m);
757 set_fs(old_fs); 758 set_fs(old_fs);
758 break; 759 break;
759 760
@@ -761,7 +762,7 @@ do_sys32_msgctl (int first, int second, void *uptr)
761 case MSG_STAT: 762 case MSG_STAT:
762 old_fs = get_fs(); 763 old_fs = get_fs();
763 set_fs(KERNEL_DS); 764 set_fs(KERNEL_DS);
764 err = sys_msgctl(first, second | IPC_64, (struct msqid_ds *)&m); 765 err = sys_msgctl(first, second | IPC_64, (struct msqid_ds __user *)&m);
765 set_fs(old_fs); 766 set_fs(old_fs);
766 if (second & IPC_64) { 767 if (second & IPC_64) {
767 if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64))) { 768 if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64))) {
@@ -815,10 +816,10 @@ do_sys32_msgctl (int first, int second, void *uptr)
815} 816}
816 817
817static int 818static int
818do_sys32_shmat (int first, int second, int third, int version, void *uptr) 819do_sys32_shmat (int first, int second, int third, int version, void __user *uptr)
819{ 820{
820 unsigned long raddr; 821 unsigned long raddr;
821 u32 *uaddr = (u32 *)A((u32)third); 822 u32 __user *uaddr = (u32 __user *)A((u32)third);
822 int err = -EINVAL; 823 int err = -EINVAL;
823 824
824 if (version == 1) 825 if (version == 1)
@@ -837,11 +838,11 @@ struct shm_info32 {
837}; 838};
838 839
839static int 840static int
840do_sys32_shmctl (int first, int second, void *uptr) 841do_sys32_shmctl (int first, int second, void __user *uptr)
841{ 842{
842 struct shmid64_ds32 *up64 = (struct shmid64_ds32 *)uptr; 843 struct shmid64_ds32 __user *up64 = (struct shmid64_ds32 __user *)uptr;
843 struct shmid_ds32 *up32 = (struct shmid_ds32 *)uptr; 844 struct shmid_ds32 __user *up32 = (struct shmid_ds32 __user *)uptr;
844 struct shm_info32 *uip = (struct shm_info32 *)uptr; 845 struct shm_info32 __user *uip = (struct shm_info32 __user *)uptr;
845 int err = -EFAULT, err2; 846 int err = -EFAULT, err2;
846 struct shmid64_ds s64; 847 struct shmid64_ds s64;
847 mm_segment_t old_fs; 848 mm_segment_t old_fs;
@@ -854,7 +855,7 @@ do_sys32_shmctl (int first, int second, void *uptr)
854 case IPC_RMID: 855 case IPC_RMID:
855 case SHM_LOCK: 856 case SHM_LOCK:
856 case SHM_UNLOCK: 857 case SHM_UNLOCK:
857 err = sys_shmctl(first, second, (struct shmid_ds *)uptr); 858 err = sys_shmctl(first, second, (struct shmid_ds __user *)uptr);
858 break; 859 break;
859 case IPC_SET: 860 case IPC_SET:
860 if (second & IPC_64) { 861 if (second & IPC_64) {
@@ -870,7 +871,7 @@ do_sys32_shmctl (int first, int second, void *uptr)
870 break; 871 break;
871 old_fs = get_fs(); 872 old_fs = get_fs();
872 set_fs(KERNEL_DS); 873 set_fs(KERNEL_DS);
873 err = sys_shmctl(first, second & ~IPC_64, &s); 874 err = sys_shmctl(first, second & ~IPC_64, (struct shmid_ds __user *)&s);
874 set_fs(old_fs); 875 set_fs(old_fs);
875 break; 876 break;
876 877
@@ -878,7 +879,7 @@ do_sys32_shmctl (int first, int second, void *uptr)
878 case SHM_STAT: 879 case SHM_STAT:
879 old_fs = get_fs(); 880 old_fs = get_fs();
880 set_fs(KERNEL_DS); 881 set_fs(KERNEL_DS);
881 err = sys_shmctl(first, second | IPC_64, (void *) &s64); 882 err = sys_shmctl(first, second | IPC_64, (void __user *) &s64);
882 set_fs(old_fs); 883 set_fs(old_fs);
883 if (err < 0) 884 if (err < 0)
884 break; 885 break;
@@ -928,7 +929,7 @@ do_sys32_shmctl (int first, int second, void *uptr)
928 case SHM_INFO: 929 case SHM_INFO:
929 old_fs = get_fs(); 930 old_fs = get_fs();
930 set_fs(KERNEL_DS); 931 set_fs(KERNEL_DS);
931 err = sys_shmctl(first, second, (void *)&si); 932 err = sys_shmctl(first, second, (void __user *)&si);
932 set_fs(old_fs); 933 set_fs(old_fs);
933 if (err < 0) 934 if (err < 0)
934 break; 935 break;
@@ -950,11 +951,11 @@ do_sys32_shmctl (int first, int second, void *uptr)
950 return err; 951 return err;
951} 952}
952 953
953static int sys32_semtimedop(int semid, struct sembuf *tsems, int nsems, 954static int sys32_semtimedop(int semid, struct sembuf __user *tsems, int nsems,
954 const struct compat_timespec *timeout32) 955 const struct compat_timespec __user *timeout32)
955{ 956{
956 struct compat_timespec t32; 957 struct compat_timespec t32;
957 struct timespec *t64 = compat_alloc_user_space(sizeof(*t64)); 958 struct timespec __user *t64 = compat_alloc_user_space(sizeof(*t64));
958 959
959 if (copy_from_user(&t32, timeout32, sizeof(t32))) 960 if (copy_from_user(&t32, timeout32, sizeof(t32)))
960 return -EFAULT; 961 return -EFAULT;
@@ -977,11 +978,11 @@ sys32_ipc (u32 call, int first, int second, int third, u32 ptr, u32 fifth)
977 switch (call) { 978 switch (call) {
978 case SEMOP: 979 case SEMOP:
979 /* struct sembuf is the same on 32 and 64bit :)) */ 980 /* struct sembuf is the same on 32 and 64bit :)) */
980 err = sys_semtimedop (first, (struct sembuf *)AA(ptr), second, 981 err = sys_semtimedop (first, (struct sembuf __user *)AA(ptr), second,
981 NULL); 982 NULL);
982 break; 983 break;
983 case SEMTIMEDOP: 984 case SEMTIMEDOP:
984 err = sys32_semtimedop (first, (struct sembuf *)AA(ptr), second, 985 err = sys32_semtimedop (first, (struct sembuf __user *)AA(ptr), second,
985 (const struct compat_timespec __user *)AA(fifth)); 986 (const struct compat_timespec __user *)AA(fifth));
986 break; 987 break;
987 case SEMGET: 988 case SEMGET:
@@ -989,36 +990,36 @@ sys32_ipc (u32 call, int first, int second, int third, u32 ptr, u32 fifth)
989 break; 990 break;
990 case SEMCTL: 991 case SEMCTL:
991 err = do_sys32_semctl (first, second, third, 992 err = do_sys32_semctl (first, second, third,
992 (void *)AA(ptr)); 993 (void __user *)AA(ptr));
993 break; 994 break;
994 995
995 case MSGSND: 996 case MSGSND:
996 err = do_sys32_msgsnd (first, second, third, 997 err = do_sys32_msgsnd (first, second, third,
997 (void *)AA(ptr)); 998 (void __user *)AA(ptr));
998 break; 999 break;
999 case MSGRCV: 1000 case MSGRCV:
1000 err = do_sys32_msgrcv (first, second, fifth, third, 1001 err = do_sys32_msgrcv (first, second, fifth, third,
1001 version, (void *)AA(ptr)); 1002 version, (void __user *)AA(ptr));
1002 break; 1003 break;
1003 case MSGGET: 1004 case MSGGET:
1004 err = sys_msgget ((key_t) first, second); 1005 err = sys_msgget ((key_t) first, second);
1005 break; 1006 break;
1006 case MSGCTL: 1007 case MSGCTL:
1007 err = do_sys32_msgctl (first, second, (void *)AA(ptr)); 1008 err = do_sys32_msgctl (first, second, (void __user *)AA(ptr));
1008 break; 1009 break;
1009 1010
1010 case SHMAT: 1011 case SHMAT:
1011 err = do_sys32_shmat (first, second, third, 1012 err = do_sys32_shmat (first, second, third,
1012 version, (void *)AA(ptr)); 1013 version, (void __user *)AA(ptr));
1013 break; 1014 break;
1014 case SHMDT: 1015 case SHMDT:
1015 err = sys_shmdt ((char *)A(ptr)); 1016 err = sys_shmdt ((char __user *)A(ptr));
1016 break; 1017 break;
1017 case SHMGET: 1018 case SHMGET:
1018 err = sys_shmget (first, (unsigned)second, third); 1019 err = sys_shmget (first, (unsigned)second, third);
1019 break; 1020 break;
1020 case SHMCTL: 1021 case SHMCTL:
1021 err = do_sys32_shmctl (first, second, (void *)AA(ptr)); 1022 err = do_sys32_shmctl (first, second, (void __user *)AA(ptr));
1022 break; 1023 break;
1023 default: 1024 default:
1024 err = -EINVAL; 1025 err = -EINVAL;
@@ -1029,7 +1030,7 @@ sys32_ipc (u32 call, int first, int second, int third, u32 ptr, u32 fifth)
1029} 1030}
1030 1031
1031asmlinkage long sys32_shmat(int shmid, char __user *shmaddr, 1032asmlinkage long sys32_shmat(int shmid, char __user *shmaddr,
1032 int shmflg, int32_t *addr) 1033 int shmflg, int32_t __user *addr)
1033{ 1034{
1034 unsigned long raddr; 1035 unsigned long raddr;
1035 int err; 1036 int err;
@@ -1054,12 +1055,13 @@ struct sysctl_args32
1054 1055
1055#ifdef CONFIG_SYSCTL 1056#ifdef CONFIG_SYSCTL
1056 1057
1057asmlinkage long sys32_sysctl(struct sysctl_args32 *args) 1058asmlinkage long sys32_sysctl(struct sysctl_args32 __user *args)
1058{ 1059{
1059 struct sysctl_args32 tmp; 1060 struct sysctl_args32 tmp;
1060 int error; 1061 int error;
1061 size_t oldlen, *oldlenp = NULL; 1062 size_t oldlen;
1062 unsigned long addr = (((long)&args->__unused[0]) + 7) & ~7; 1063 size_t __user *oldlenp = NULL;
1064 unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
1063 1065
1064 if (copy_from_user(&tmp, args, sizeof(tmp))) 1066 if (copy_from_user(&tmp, args, sizeof(tmp)))
1065 return -EFAULT; 1067 return -EFAULT;
@@ -1071,20 +1073,20 @@ asmlinkage long sys32_sysctl(struct sysctl_args32 *args)
1071 basically copy the whole sysctl.c here, and 1073 basically copy the whole sysctl.c here, and
1072 glibc's __sysctl uses rw memory for the structure 1074 glibc's __sysctl uses rw memory for the structure
1073 anyway. */ 1075 anyway. */
1074 if (get_user(oldlen, (u32 *)A(tmp.oldlenp)) || 1076 if (get_user(oldlen, (u32 __user *)A(tmp.oldlenp)) ||
1075 put_user(oldlen, (size_t *)addr)) 1077 put_user(oldlen, (size_t __user *)addr))
1076 return -EFAULT; 1078 return -EFAULT;
1077 oldlenp = (size_t *)addr; 1079 oldlenp = (size_t __user *)addr;
1078 } 1080 }
1079 1081
1080 lock_kernel(); 1082 lock_kernel();
1081 error = do_sysctl((int *)A(tmp.name), tmp.nlen, (void *)A(tmp.oldval), 1083 error = do_sysctl((int __user *)A(tmp.name), tmp.nlen, (void __user *)A(tmp.oldval),
1082 oldlenp, (void *)A(tmp.newval), tmp.newlen); 1084 oldlenp, (void __user *)A(tmp.newval), tmp.newlen);
1083 unlock_kernel(); 1085 unlock_kernel();
1084 if (oldlenp) { 1086 if (oldlenp) {
1085 if (!error) { 1087 if (!error) {
1086 if (get_user(oldlen, (size_t *)addr) || 1088 if (get_user(oldlen, (size_t __user *)addr) ||
1087 put_user(oldlen, (u32 *)A(tmp.oldlenp))) 1089 put_user(oldlen, (u32 __user *)A(tmp.oldlenp)))
1088 error = -EFAULT; 1090 error = -EFAULT;
1089 } 1091 }
1090 copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)); 1092 copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
@@ -1094,7 +1096,7 @@ asmlinkage long sys32_sysctl(struct sysctl_args32 *args)
1094 1096
1095#endif /* CONFIG_SYSCTL */ 1097#endif /* CONFIG_SYSCTL */
1096 1098
1097asmlinkage long sys32_newuname(struct new_utsname * name) 1099asmlinkage long sys32_newuname(struct new_utsname __user * name)
1098{ 1100{
1099 int ret = 0; 1101 int ret = 0;
1100 1102
@@ -1129,9 +1131,9 @@ struct ustat32 {
1129 char f_fpack[6]; 1131 char f_fpack[6];
1130}; 1132};
1131 1133
1132extern asmlinkage long sys_ustat(dev_t dev, struct ustat * ubuf); 1134extern asmlinkage long sys_ustat(dev_t dev, struct ustat __user * ubuf);
1133 1135
1134asmlinkage int sys32_ustat(dev_t dev, struct ustat32 * ubuf32) 1136asmlinkage int sys32_ustat(dev_t dev, struct ustat32 __user * ubuf32)
1135{ 1137{
1136 int err; 1138 int err;
1137 struct ustat tmp; 1139 struct ustat tmp;
@@ -1139,7 +1141,7 @@ asmlinkage int sys32_ustat(dev_t dev, struct ustat32 * ubuf32)
1139 mm_segment_t old_fs = get_fs(); 1141 mm_segment_t old_fs = get_fs();
1140 1142
1141 set_fs(KERNEL_DS); 1143 set_fs(KERNEL_DS);
1142 err = sys_ustat(dev, &tmp); 1144 err = sys_ustat(dev, (struct ustat __user *)&tmp);
1143 set_fs (old_fs); 1145 set_fs (old_fs);
1144 1146
1145 if (err) 1147 if (err)
@@ -1172,7 +1174,7 @@ struct timex32 {
1172 1174
1173extern int do_adjtimex(struct timex *); 1175extern int do_adjtimex(struct timex *);
1174 1176
1175asmlinkage int sys32_adjtimex(struct timex32 *utp) 1177asmlinkage int sys32_adjtimex(struct timex32 __user *utp)
1176{ 1178{
1177 struct timex txc; 1179 struct timex txc;
1178 int ret; 1180 int ret;
@@ -1228,7 +1230,7 @@ asmlinkage int sys32_adjtimex(struct timex32 *utp)
1228 return ret; 1230 return ret;
1229} 1231}
1230 1232
1231asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t *offset, 1233asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset,
1232 s32 count) 1234 s32 count)
1233{ 1235{
1234 mm_segment_t old_fs = get_fs(); 1236 mm_segment_t old_fs = get_fs();
@@ -1239,7 +1241,7 @@ asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t *offset,
1239 return -EFAULT; 1241 return -EFAULT;
1240 1242
1241 set_fs(KERNEL_DS); 1243 set_fs(KERNEL_DS);
1242 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count); 1244 ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL, count);
1243 set_fs(old_fs); 1245 set_fs(old_fs);
1244 1246
1245 if (offset && put_user(of, offset)) 1247 if (offset && put_user(of, offset))
@@ -1269,7 +1271,7 @@ static unsigned char socketcall_nargs[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
1269 * it is set by the callees. 1271 * it is set by the callees.
1270 */ 1272 */
1271 1273
1272asmlinkage long sys32_socketcall(int call, unsigned int *args32) 1274asmlinkage long sys32_socketcall(int call, unsigned int __user *args32)
1273{ 1275{
1274 unsigned int a[6]; 1276 unsigned int a[6];
1275 unsigned int a0,a1; 1277 unsigned int a0,a1;
@@ -1291,7 +1293,7 @@ asmlinkage long sys32_socketcall(int call, unsigned int *args32)
1291 struct sockaddr __user *addr, int __user *addr_len); 1293 struct sockaddr __user *addr, int __user *addr_len);
1292 extern asmlinkage long sys_shutdown(int fd, int how); 1294 extern asmlinkage long sys_shutdown(int fd, int how);
1293 extern asmlinkage long sys_setsockopt(int fd, int level, int optname, char __user *optval, int optlen); 1295 extern asmlinkage long sys_setsockopt(int fd, int level, int optname, char __user *optval, int optlen);
1294 extern asmlinkage long sys_getsockopt(int fd, int level, int optname, char __user *optval, int *optlen); 1296 extern asmlinkage long sys_getsockopt(int fd, int level, int optname, char __user *optval, int __user *optlen);
1295 extern asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags); 1297 extern asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
1296 extern asmlinkage long sys_recvmsg(int fd, struct msghdr __user *msg, unsigned int flags); 1298 extern asmlinkage long sys_recvmsg(int fd, struct msghdr __user *msg, unsigned int flags);
1297 1299
@@ -1411,7 +1413,7 @@ _sys32_clone(nabi_no_regargs struct pt_regs regs)
1411 newsp = regs.regs[5]; 1413 newsp = regs.regs[5];
1412 if (!newsp) 1414 if (!newsp)
1413 newsp = regs.regs[29]; 1415 newsp = regs.regs[29];
1414 parent_tidptr = (int *) regs.regs[6]; 1416 parent_tidptr = (int __user *) regs.regs[6];
1415 1417
1416 /* Use __dummy4 instead of getting it off the stack, so that 1418 /* Use __dummy4 instead of getting it off the stack, so that
1417 syscall() works. */ 1419 syscall() works. */
diff --git a/arch/mips/kernel/proc.c b/arch/mips/kernel/proc.c
index 86fe15b273cd..84ab959f924a 100644
--- a/arch/mips/kernel/proc.c
+++ b/arch/mips/kernel/proc.c
@@ -135,6 +135,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
135 cpu_has_vce ? "%u" : "not available"); 135 cpu_has_vce ? "%u" : "not available");
136 seq_printf(m, fmt, 'D', vced_count); 136 seq_printf(m, fmt, 'D', vced_count);
137 seq_printf(m, fmt, 'I', vcei_count); 137 seq_printf(m, fmt, 'I', vcei_count);
138 seq_printf(m, "\n");
138 139
139 return 0; 140 return 0;
140} 141}
diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index 092679c2dca9..a8f435d82940 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -60,17 +60,9 @@ ATTRIB_NORET void cpu_idle(void)
60 } 60 }
61} 61}
62 62
63extern void do_signal(struct pt_regs *regs);
64extern void do_signal32(struct pt_regs *regs);
65
66/* 63/*
67 * Native o32 and N64 ABI without DSP ASE 64 * Native o32 and N64 ABI without DSP ASE
68 */ 65 */
69extern int setup_frame(struct k_sigaction * ka, struct pt_regs *regs,
70 int signr, sigset_t *set);
71extern int setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
72 int signr, sigset_t *set, siginfo_t *info);
73
74struct mips_abi mips_abi = { 66struct mips_abi mips_abi = {
75 .do_signal = do_signal, 67 .do_signal = do_signal,
76#ifdef CONFIG_TRAD_SIGNALS 68#ifdef CONFIG_TRAD_SIGNALS
@@ -83,11 +75,6 @@ struct mips_abi mips_abi = {
83/* 75/*
84 * o32 compatibility on 64-bit kernels, without DSP ASE 76 * o32 compatibility on 64-bit kernels, without DSP ASE
85 */ 77 */
86extern int setup_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
87 int signr, sigset_t *set);
88extern int setup_rt_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
89 int signr, sigset_t *set, siginfo_t *info);
90
91struct mips_abi mips_abi_32 = { 78struct mips_abi mips_abi_32 = {
92 .do_signal = do_signal32, 79 .do_signal = do_signal32,
93 .setup_frame = setup_frame_32, 80 .setup_frame = setup_frame_32,
@@ -99,9 +86,6 @@ struct mips_abi mips_abi_32 = {
99/* 86/*
100 * N32 on 64-bit kernels, without DSP ASE 87 * N32 on 64-bit kernels, without DSP ASE
101 */ 88 */
102extern int setup_rt_frame_n32(struct k_sigaction * ka, struct pt_regs *regs,
103 int signr, sigset_t *set, siginfo_t *info);
104
105struct mips_abi mips_abi_n32 = { 89struct mips_abi mips_abi_n32 = {
106 .do_signal = do_signal, 90 .do_signal = do_signal,
107 .setup_rt_frame = setup_rt_frame_n32 91 .setup_rt_frame = setup_rt_frame_n32
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index d9293c558e41..0cb3b6097e0e 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -447,21 +447,10 @@ static inline void resource_init(void)
447{ 447{
448 int i; 448 int i;
449 449
450#if defined(CONFIG_64BIT) && !defined(CONFIG_BUILD_ELF64)
451 /*
452 * The 64bit code in 32bit object format trick can't represent
453 * 64bit wide relocations for linker script symbols.
454 */
455 code_resource.start = CPHYSADDR(&_text);
456 code_resource.end = CPHYSADDR(&_etext) - 1;
457 data_resource.start = CPHYSADDR(&_etext);
458 data_resource.end = CPHYSADDR(&_edata) - 1;
459#else
460 code_resource.start = virt_to_phys(&_text); 450 code_resource.start = virt_to_phys(&_text);
461 code_resource.end = virt_to_phys(&_etext) - 1; 451 code_resource.end = virt_to_phys(&_etext) - 1;
462 data_resource.start = virt_to_phys(&_etext); 452 data_resource.start = virt_to_phys(&_etext);
463 data_resource.end = virt_to_phys(&_edata) - 1; 453 data_resource.end = virt_to_phys(&_edata) - 1;
464#endif
465 454
466 /* 455 /*
467 * Request address space for all standard RAM. 456 * Request address space for all standard RAM.
diff --git a/arch/mips/kernel/signal-common.h b/arch/mips/kernel/signal-common.h
index 36bfc2588aa3..3ca786215d48 100644
--- a/arch/mips/kernel/signal-common.h
+++ b/arch/mips/kernel/signal-common.h
@@ -166,11 +166,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
166 sp = regs->regs[29]; 166 sp = regs->regs[29];
167 167
168 /* 168 /*
169 * FPU emulator may have it's own trampoline active just 169 * FPU emulator may have it's own trampoline active just
170 * above the user stack, 16-bytes before the next lowest 170 * above the user stack, 16-bytes before the next lowest
171 * 16 byte boundary. Try to avoid trashing it. 171 * 16 byte boundary. Try to avoid trashing it.
172 */ 172 */
173 sp -= 32; 173 sp -= 32;
174 174
175 /* This is the X/Open sanctioned signal stack switching. */ 175 /* This is the X/Open sanctioned signal stack switching. */
176 if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0)) 176 if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index c974cc9b30eb..402efd27c79e 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -100,8 +100,8 @@ _sys_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
100} 100}
101 101
102#ifdef CONFIG_TRAD_SIGNALS 102#ifdef CONFIG_TRAD_SIGNALS
103asmlinkage int sys_sigaction(int sig, const struct sigaction *act, 103asmlinkage int sys_sigaction(int sig, const struct sigaction __user *act,
104 struct sigaction *oact) 104 struct sigaction __user *oact)
105{ 105{
106 struct k_sigaction new_ka, old_ka; 106 struct k_sigaction new_ka, old_ka;
107 int ret; 107 int ret;
@@ -331,7 +331,7 @@ int setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
331 /* Create the ucontext. */ 331 /* Create the ucontext. */
332 err |= __put_user(0, &frame->rs_uc.uc_flags); 332 err |= __put_user(0, &frame->rs_uc.uc_flags);
333 err |= __put_user(NULL, &frame->rs_uc.uc_link); 333 err |= __put_user(NULL, &frame->rs_uc.uc_link);
334 err |= __put_user((void *)current->sas_ss_sp, 334 err |= __put_user((void __user *)current->sas_ss_sp,
335 &frame->rs_uc.uc_stack.ss_sp); 335 &frame->rs_uc.uc_stack.ss_sp);
336 err |= __put_user(sas_ss_flags(regs->regs[29]), 336 err |= __put_user(sas_ss_flags(regs->regs[29]),
337 &frame->rs_uc.uc_stack.ss_flags); 337 &frame->rs_uc.uc_stack.ss_flags);
diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index 237cd8a2cd32..f32a22997c3d 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -163,7 +163,7 @@ static inline int put_sigset(const sigset_t *kbuf, compat_sigset_t __user *ubuf)
163 return err; 163 return err;
164} 164}
165 165
166static inline int get_sigset(sigset_t *kbuf, const compat_sigset_t *ubuf) 166static inline int get_sigset(sigset_t *kbuf, const compat_sigset_t __user *ubuf)
167{ 167{
168 int err = 0; 168 int err = 0;
169 unsigned long sig[4]; 169 unsigned long sig[4];
@@ -195,10 +195,10 @@ save_static_function(sys32_sigsuspend);
195__attribute_used__ noinline static int 195__attribute_used__ noinline static int
196_sys32_sigsuspend(nabi_no_regargs struct pt_regs regs) 196_sys32_sigsuspend(nabi_no_regargs struct pt_regs regs)
197{ 197{
198 compat_sigset_t *uset; 198 compat_sigset_t __user *uset;
199 sigset_t newset; 199 sigset_t newset;
200 200
201 uset = (compat_sigset_t *) regs.regs[4]; 201 uset = (compat_sigset_t __user *) regs.regs[4];
202 if (get_sigset(&newset, uset)) 202 if (get_sigset(&newset, uset))
203 return -EFAULT; 203 return -EFAULT;
204 sigdelsetmask(&newset, ~_BLOCKABLE); 204 sigdelsetmask(&newset, ~_BLOCKABLE);
@@ -219,7 +219,7 @@ save_static_function(sys32_rt_sigsuspend);
219__attribute_used__ noinline static int 219__attribute_used__ noinline static int
220_sys32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs) 220_sys32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
221{ 221{
222 compat_sigset_t *uset; 222 compat_sigset_t __user *uset;
223 sigset_t newset; 223 sigset_t newset;
224 size_t sigsetsize; 224 size_t sigsetsize;
225 225
@@ -228,7 +228,7 @@ _sys32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
228 if (sigsetsize != sizeof(compat_sigset_t)) 228 if (sigsetsize != sizeof(compat_sigset_t))
229 return -EINVAL; 229 return -EINVAL;
230 230
231 uset = (compat_sigset_t *) regs.regs[4]; 231 uset = (compat_sigset_t __user *) regs.regs[4];
232 if (get_sigset(&newset, uset)) 232 if (get_sigset(&newset, uset))
233 return -EFAULT; 233 return -EFAULT;
234 sigdelsetmask(&newset, ~_BLOCKABLE); 234 sigdelsetmask(&newset, ~_BLOCKABLE);
@@ -236,7 +236,7 @@ _sys32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
236 spin_lock_irq(&current->sighand->siglock); 236 spin_lock_irq(&current->sighand->siglock);
237 current->saved_sigmask = current->blocked; 237 current->saved_sigmask = current->blocked;
238 current->blocked = newset; 238 current->blocked = newset;
239 recalc_sigpending(); 239 recalc_sigpending();
240 spin_unlock_irq(&current->sighand->siglock); 240 spin_unlock_irq(&current->sighand->siglock);
241 241
242 current->state = TASK_INTERRUPTIBLE; 242 current->state = TASK_INTERRUPTIBLE;
@@ -245,8 +245,8 @@ _sys32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
245 return -ERESTARTNOHAND; 245 return -ERESTARTNOHAND;
246} 246}
247 247
248asmlinkage int sys32_sigaction(int sig, const struct sigaction32 *act, 248asmlinkage int sys32_sigaction(int sig, const struct sigaction32 __user *act,
249 struct sigaction32 *oact) 249 struct sigaction32 __user *oact)
250{ 250{
251 struct k_sigaction new_ka, old_ka; 251 struct k_sigaction new_ka, old_ka;
252 int ret; 252 int ret;
@@ -272,15 +272,15 @@ asmlinkage int sys32_sigaction(int sig, const struct sigaction32 *act,
272 272
273 if (!ret && oact) { 273 if (!ret && oact) {
274 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact))) 274 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
275 return -EFAULT; 275 return -EFAULT;
276 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags); 276 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
277 err |= __put_user((u32)(u64)old_ka.sa.sa_handler, 277 err |= __put_user((u32)(u64)old_ka.sa.sa_handler,
278 &oact->sa_handler); 278 &oact->sa_handler);
279 err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig); 279 err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
280 err |= __put_user(0, &oact->sa_mask.sig[1]); 280 err |= __put_user(0, &oact->sa_mask.sig[1]);
281 err |= __put_user(0, &oact->sa_mask.sig[2]); 281 err |= __put_user(0, &oact->sa_mask.sig[2]);
282 err |= __put_user(0, &oact->sa_mask.sig[3]); 282 err |= __put_user(0, &oact->sa_mask.sig[3]);
283 if (err) 283 if (err)
284 return -EFAULT; 284 return -EFAULT;
285 } 285 }
286 286
@@ -301,7 +301,7 @@ asmlinkage int sys32_sigaltstack(nabi_no_regargs struct pt_regs regs)
301 if (!access_ok(VERIFY_READ, uss, sizeof(*uss))) 301 if (!access_ok(VERIFY_READ, uss, sizeof(*uss)))
302 return -EFAULT; 302 return -EFAULT;
303 err |= __get_user(sp, &uss->ss_sp); 303 err |= __get_user(sp, &uss->ss_sp);
304 kss.ss_sp = (void *) (long) sp; 304 kss.ss_sp = (void __user *) (long) sp;
305 err |= __get_user(kss.ss_size, &uss->ss_size); 305 err |= __get_user(kss.ss_size, &uss->ss_size);
306 err |= __get_user(kss.ss_flags, &uss->ss_flags); 306 err |= __get_user(kss.ss_flags, &uss->ss_flags);
307 if (err) 307 if (err)
@@ -316,7 +316,7 @@ asmlinkage int sys32_sigaltstack(nabi_no_regargs struct pt_regs regs)
316 if (!ret && uoss) { 316 if (!ret && uoss) {
317 if (!access_ok(VERIFY_WRITE, uoss, sizeof(*uoss))) 317 if (!access_ok(VERIFY_WRITE, uoss, sizeof(*uoss)))
318 return -EFAULT; 318 return -EFAULT;
319 sp = (int) (long) koss.ss_sp; 319 sp = (int) (unsigned long) koss.ss_sp;
320 err |= __put_user(sp, &uoss->ss_sp); 320 err |= __put_user(sp, &uoss->ss_sp);
321 err |= __put_user(koss.ss_size, &uoss->ss_size); 321 err |= __put_user(koss.ss_size, &uoss->ss_size);
322 err |= __put_user(koss.ss_flags, &uoss->ss_flags); 322 err |= __put_user(koss.ss_flags, &uoss->ss_flags);
@@ -527,7 +527,7 @@ _sys32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
527 /* The ucontext contains a stack32_t, so we must convert! */ 527 /* The ucontext contains a stack32_t, so we must convert! */
528 if (__get_user(sp, &frame->rs_uc.uc_stack.ss_sp)) 528 if (__get_user(sp, &frame->rs_uc.uc_stack.ss_sp))
529 goto badframe; 529 goto badframe;
530 st.ss_sp = (void *)(long) sp; 530 st.ss_sp = (void __user *)(long) sp;
531 if (__get_user(st.ss_size, &frame->rs_uc.uc_stack.ss_size)) 531 if (__get_user(st.ss_size, &frame->rs_uc.uc_stack.ss_size))
532 goto badframe; 532 goto badframe;
533 if (__get_user(st.ss_flags, &frame->rs_uc.uc_stack.ss_flags)) 533 if (__get_user(st.ss_flags, &frame->rs_uc.uc_stack.ss_flags))
@@ -624,11 +624,11 @@ static inline void __user *get_sigframe(struct k_sigaction *ka,
624 sp = regs->regs[29]; 624 sp = regs->regs[29];
625 625
626 /* 626 /*
627 * FPU emulator may have it's own trampoline active just 627 * FPU emulator may have it's own trampoline active just
628 * above the user stack, 16-bytes before the next lowest 628 * above the user stack, 16-bytes before the next lowest
629 * 16 byte boundary. Try to avoid trashing it. 629 * 16 byte boundary. Try to avoid trashing it.
630 */ 630 */
631 sp -= 32; 631 sp -= 32;
632 632
633 /* This is the X/Open sanctioned signal stack switching. */ 633 /* This is the X/Open sanctioned signal stack switching. */
634 if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0)) 634 if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
@@ -868,7 +868,7 @@ no_signal:
868 } 868 }
869} 869}
870 870
871asmlinkage int sys32_rt_sigaction(int sig, const struct sigaction32 *act, 871asmlinkage int sys32_rt_sigaction(int sig, const struct sigaction32 __user *act,
872 struct sigaction32 __user *oact, 872 struct sigaction32 __user *oact,
873 unsigned int sigsetsize) 873 unsigned int sigsetsize)
874{ 874{
@@ -912,7 +912,7 @@ out:
912 return ret; 912 return ret;
913} 913}
914 914
915asmlinkage int sys32_rt_sigprocmask(int how, compat_sigset_t *set, 915asmlinkage int sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
916 compat_sigset_t __user *oset, unsigned int sigsetsize) 916 compat_sigset_t __user *oset, unsigned int sigsetsize)
917{ 917{
918 sigset_t old_set, new_set; 918 sigset_t old_set, new_set;
diff --git a/arch/mips/kernel/signal_n32.c b/arch/mips/kernel/signal_n32.c
index 3e168c08a3a8..477c5334ec1b 100644
--- a/arch/mips/kernel/signal_n32.c
+++ b/arch/mips/kernel/signal_n32.c
@@ -87,7 +87,8 @@ save_static_function(sysn32_rt_sigsuspend);
87__attribute_used__ noinline static int 87__attribute_used__ noinline static int
88_sysn32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs) 88_sysn32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
89{ 89{
90 compat_sigset_t __user *unewset, uset; 90 compat_sigset_t __user *unewset;
91 compat_sigset_t uset;
91 size_t sigsetsize; 92 size_t sigsetsize;
92 sigset_t newset; 93 sigset_t newset;
93 94
@@ -141,7 +142,7 @@ _sysn32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
141 /* The ucontext contains a stack32_t, so we must convert! */ 142 /* The ucontext contains a stack32_t, so we must convert! */
142 if (__get_user(sp, &frame->rs_uc.uc_stack.ss_sp)) 143 if (__get_user(sp, &frame->rs_uc.uc_stack.ss_sp))
143 goto badframe; 144 goto badframe;
144 st.ss_sp = (void *)(long) sp; 145 st.ss_sp = (void __user *)(long) sp;
145 if (__get_user(st.ss_size, &frame->rs_uc.uc_stack.ss_size)) 146 if (__get_user(st.ss_size, &frame->rs_uc.uc_stack.ss_size))
146 goto badframe; 147 goto badframe;
147 if (__get_user(st.ss_flags, &frame->rs_uc.uc_stack.ss_flags)) 148 if (__get_user(st.ss_flags, &frame->rs_uc.uc_stack.ss_flags))
diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
index 1da2eeb3ef9e..2aeaa2fd4b32 100644
--- a/arch/mips/kernel/syscall.c
+++ b/arch/mips/kernel/syscall.c
@@ -162,7 +162,10 @@ asmlinkage unsigned long
162sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, 162sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
163 unsigned long flags, unsigned long fd, unsigned long pgoff) 163 unsigned long flags, unsigned long fd, unsigned long pgoff)
164{ 164{
165 return do_mmap2(addr, len, prot, flags, fd, pgoff); 165 if (pgoff & (~PAGE_MASK >> 12))
166 return -EINVAL;
167
168 return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12));
166} 169}
167 170
168save_static_function(sys_fork); 171save_static_function(sys_fork);
@@ -345,7 +348,7 @@ asmlinkage int sys_ipc (uint call, int first, int second,
345 union semun fourth; 348 union semun fourth;
346 if (!ptr) 349 if (!ptr)
347 return -EINVAL; 350 return -EINVAL;
348 if (get_user(fourth.__pad, (void *__user *) ptr)) 351 if (get_user(fourth.__pad, (void __user *__user *) ptr))
349 return -EFAULT; 352 return -EFAULT;
350 return sys_semctl (first, second, third, fourth); 353 return sys_semctl (first, second, third, fourth);
351 } 354 }
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index 005debbfbe84..bed0eb6cf55d 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -576,7 +576,7 @@ asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
576 } 576 }
577#endif 577#endif
578 /* 578 /*
579 * Unimplemented operation exception. If we've got the full 579 * Unimplemented operation exception. If we've got the full
580 * software emulator on-board, let's use it... 580 * software emulator on-board, let's use it...
581 * 581 *
582 * Force FPU to dump state into task/thread context. We're 582 * Force FPU to dump state into task/thread context. We're
diff --git a/arch/mips/lasat/image/romscript.normal b/arch/mips/lasat/image/romscript.normal
index ca22336f6c36..988f8ad189cb 100644
--- a/arch/mips/lasat/image/romscript.normal
+++ b/arch/mips/lasat/image/romscript.normal
@@ -16,7 +16,8 @@ SECTIONS
16 _image_start = ADDR(.data); 16 _image_start = ADDR(.data);
17 _image_size = SIZEOF(.data); 17 _image_size = SIZEOF(.data);
18 18
19 .other : { 19 .other :
20 *(.*) 20 {
21 *(.*)
21 } 22 }
22} 23}
diff --git a/arch/mips/mips-boards/generic/mipsIRQ.S b/arch/mips/mips-boards/generic/mipsIRQ.S
index a397ecb872d6..ddd5c73a2971 100644
--- a/arch/mips/mips-boards/generic/mipsIRQ.S
+++ b/arch/mips/mips-boards/generic/mipsIRQ.S
@@ -98,7 +98,7 @@
98 and s0, s1 98 and s0, s1
99 99
100#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) 100#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
101 .set mips32 101 .set mips32
102 clz a0, s0 102 clz a0, s0
103 .set mips0 103 .set mips0
104 negu a0 104 negu a0
diff --git a/arch/mips/mips-boards/sim/sim_IRQ.c b/arch/mips/mips-boards/sim/sim_IRQ.c
index 9987a85aabeb..5b84c7fe1022 100644
--- a/arch/mips/mips-boards/sim/sim_IRQ.c
+++ b/arch/mips/mips-boards/sim/sim_IRQ.c
@@ -96,7 +96,7 @@
96 andi a0, s0, CAUSEF_IP3 # delay slot, check hw1 interrupt 96 andi a0, s0, CAUSEF_IP3 # delay slot, check hw1 interrupt
97#else 97#else
98 beq a0, zero, 1f # delay slot, check hw3 interrupt 98 beq a0, zero, 1f # delay slot, check hw3 interrupt
99 andi a0, s0, CAUSEF_IP5 99 andi a0, s0, CAUSEF_IP5
100#endif 100#endif
101 101
102 /* Wheee, combined hardware level zero interrupt. */ 102 /* Wheee, combined hardware level zero interrupt. */
diff --git a/arch/mips/mips-boards/sim/sim_irq.S b/arch/mips/mips-boards/sim/sim_irq.S
index 835f0387fcd4..da52297a2216 100644
--- a/arch/mips/mips-boards/sim/sim_irq.S
+++ b/arch/mips/mips-boards/sim/sim_irq.S
@@ -42,7 +42,7 @@
42 and s0, s1 42 and s0, s1
43 43
44#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) 44#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
45 .set mips32 45 .set mips32
46 clz a0, s0 46 clz a0, s0
47 .set mips0 47 .set mips0
48 negu a0 48 negu a0
diff --git a/arch/mips/mips-boards/sim/sim_smp.c b/arch/mips/mips-boards/sim/sim_smp.c
index 19824359f5de..a9f0c2bfe4ad 100644
--- a/arch/mips/mips-boards/sim/sim_smp.c
+++ b/arch/mips/mips-boards/sim/sim_smp.c
@@ -115,7 +115,7 @@ void prom_prepare_cpus(unsigned int max_cpus)
115#ifdef CONFIG_MIPS_MT_SMTC 115#ifdef CONFIG_MIPS_MT_SMTC
116 void mipsmt_prepare_cpus(int c); 116 void mipsmt_prepare_cpus(int c);
117 /* 117 /*
118 * As noted above, we can assume a single CPU for now 118 * As noted above, we can assume a single CPU for now
119 * but it may be multithreaded. 119 * but it may be multithreaded.
120 */ 120 */
121 121
diff --git a/arch/mips/mm/Makefile b/arch/mips/mm/Makefile
index b0178da019f0..4a6220116c96 100644
--- a/arch/mips/mm/Makefile
+++ b/arch/mips/mm/Makefile
@@ -12,7 +12,7 @@ obj-$(CONFIG_HIGHMEM) += highmem.o
12obj-$(CONFIG_CPU_MIPS32) += c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o 12obj-$(CONFIG_CPU_MIPS32) += c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o
13obj-$(CONFIG_CPU_MIPS64) += c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o 13obj-$(CONFIG_CPU_MIPS64) += c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o
14obj-$(CONFIG_CPU_NEVADA) += c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o 14obj-$(CONFIG_CPU_NEVADA) += c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o
15obj-$(CONFIG_CPU_R10000) += c-r4k.o cex-gen.o pg-r4k.o tlb-andes.o 15obj-$(CONFIG_CPU_R10000) += c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o
16obj-$(CONFIG_CPU_R3000) += c-r3k.o tlb-r3k.o pg-r4k.o 16obj-$(CONFIG_CPU_R3000) += c-r3k.o tlb-r3k.o pg-r4k.o
17obj-$(CONFIG_CPU_R4300) += c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o 17obj-$(CONFIG_CPU_R4300) += c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o
18obj-$(CONFIG_CPU_R4X00) += c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o 18obj-$(CONFIG_CPU_R4X00) += c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o
diff --git a/arch/mips/mm/c-r3k.c b/arch/mips/mm/c-r3k.c
index 27f4fa25e8c9..9dd1352d5748 100644
--- a/arch/mips/mm/c-r3k.c
+++ b/arch/mips/mm/c-r3k.c
@@ -129,7 +129,7 @@ static void r3k_flush_icache_range(unsigned long start, unsigned long end)
129 "sb\t$0, 0x014(%0)\n\t" 129 "sb\t$0, 0x014(%0)\n\t"
130 "sb\t$0, 0x018(%0)\n\t" 130 "sb\t$0, 0x018(%0)\n\t"
131 "sb\t$0, 0x01c(%0)\n\t" 131 "sb\t$0, 0x01c(%0)\n\t"
132 "sb\t$0, 0x020(%0)\n\t" 132 "sb\t$0, 0x020(%0)\n\t"
133 "sb\t$0, 0x024(%0)\n\t" 133 "sb\t$0, 0x024(%0)\n\t"
134 "sb\t$0, 0x028(%0)\n\t" 134 "sb\t$0, 0x028(%0)\n\t"
135 "sb\t$0, 0x02c(%0)\n\t" 135 "sb\t$0, 0x02c(%0)\n\t"
@@ -145,7 +145,7 @@ static void r3k_flush_icache_range(unsigned long start, unsigned long end)
145 "sb\t$0, 0x054(%0)\n\t" 145 "sb\t$0, 0x054(%0)\n\t"
146 "sb\t$0, 0x058(%0)\n\t" 146 "sb\t$0, 0x058(%0)\n\t"
147 "sb\t$0, 0x05c(%0)\n\t" 147 "sb\t$0, 0x05c(%0)\n\t"
148 "sb\t$0, 0x060(%0)\n\t" 148 "sb\t$0, 0x060(%0)\n\t"
149 "sb\t$0, 0x064(%0)\n\t" 149 "sb\t$0, 0x064(%0)\n\t"
150 "sb\t$0, 0x068(%0)\n\t" 150 "sb\t$0, 0x068(%0)\n\t"
151 "sb\t$0, 0x06c(%0)\n\t" 151 "sb\t$0, 0x06c(%0)\n\t"
@@ -182,31 +182,31 @@ static void r3k_flush_dcache_range(unsigned long start, unsigned long end)
182 "sb\t$0, 0x004(%0)\n\t" 182 "sb\t$0, 0x004(%0)\n\t"
183 "sb\t$0, 0x008(%0)\n\t" 183 "sb\t$0, 0x008(%0)\n\t"
184 "sb\t$0, 0x00c(%0)\n\t" 184 "sb\t$0, 0x00c(%0)\n\t"
185 "sb\t$0, 0x010(%0)\n\t" 185 "sb\t$0, 0x010(%0)\n\t"
186 "sb\t$0, 0x014(%0)\n\t" 186 "sb\t$0, 0x014(%0)\n\t"
187 "sb\t$0, 0x018(%0)\n\t" 187 "sb\t$0, 0x018(%0)\n\t"
188 "sb\t$0, 0x01c(%0)\n\t" 188 "sb\t$0, 0x01c(%0)\n\t"
189 "sb\t$0, 0x020(%0)\n\t" 189 "sb\t$0, 0x020(%0)\n\t"
190 "sb\t$0, 0x024(%0)\n\t" 190 "sb\t$0, 0x024(%0)\n\t"
191 "sb\t$0, 0x028(%0)\n\t" 191 "sb\t$0, 0x028(%0)\n\t"
192 "sb\t$0, 0x02c(%0)\n\t" 192 "sb\t$0, 0x02c(%0)\n\t"
193 "sb\t$0, 0x030(%0)\n\t" 193 "sb\t$0, 0x030(%0)\n\t"
194 "sb\t$0, 0x034(%0)\n\t" 194 "sb\t$0, 0x034(%0)\n\t"
195 "sb\t$0, 0x038(%0)\n\t" 195 "sb\t$0, 0x038(%0)\n\t"
196 "sb\t$0, 0x03c(%0)\n\t" 196 "sb\t$0, 0x03c(%0)\n\t"
197 "sb\t$0, 0x040(%0)\n\t" 197 "sb\t$0, 0x040(%0)\n\t"
198 "sb\t$0, 0x044(%0)\n\t" 198 "sb\t$0, 0x044(%0)\n\t"
199 "sb\t$0, 0x048(%0)\n\t" 199 "sb\t$0, 0x048(%0)\n\t"
200 "sb\t$0, 0x04c(%0)\n\t" 200 "sb\t$0, 0x04c(%0)\n\t"
201 "sb\t$0, 0x050(%0)\n\t" 201 "sb\t$0, 0x050(%0)\n\t"
202 "sb\t$0, 0x054(%0)\n\t" 202 "sb\t$0, 0x054(%0)\n\t"
203 "sb\t$0, 0x058(%0)\n\t" 203 "sb\t$0, 0x058(%0)\n\t"
204 "sb\t$0, 0x05c(%0)\n\t" 204 "sb\t$0, 0x05c(%0)\n\t"
205 "sb\t$0, 0x060(%0)\n\t" 205 "sb\t$0, 0x060(%0)\n\t"
206 "sb\t$0, 0x064(%0)\n\t" 206 "sb\t$0, 0x064(%0)\n\t"
207 "sb\t$0, 0x068(%0)\n\t" 207 "sb\t$0, 0x068(%0)\n\t"
208 "sb\t$0, 0x06c(%0)\n\t" 208 "sb\t$0, 0x06c(%0)\n\t"
209 "sb\t$0, 0x070(%0)\n\t" 209 "sb\t$0, 0x070(%0)\n\t"
210 "sb\t$0, 0x074(%0)\n\t" 210 "sb\t$0, 0x074(%0)\n\t"
211 "sb\t$0, 0x078(%0)\n\t" 211 "sb\t$0, 0x078(%0)\n\t"
212 "sb\t$0, 0x07c(%0)\n\t" 212 "sb\t$0, 0x07c(%0)\n\t"
diff --git a/arch/mips/mm/c-r4k.c b/arch/mips/mm/c-r4k.c
index 9572ed44f0d5..32b7f6aeb983 100644
--- a/arch/mips/mm/c-r4k.c
+++ b/arch/mips/mm/c-r4k.c
@@ -786,6 +786,7 @@ static void __init probe_pcache(void)
786 c->dcache.waybit = 0; 786 c->dcache.waybit = 0;
787 787
788 c->options |= MIPS_CPU_CACHE_CDEX_P; 788 c->options |= MIPS_CPU_CACHE_CDEX_P;
789 c->options |= MIPS_CPU_PREFETCH;
789 break; 790 break;
790 791
791 case CPU_R4000PC: 792 case CPU_R4000PC:
diff --git a/arch/mips/mm/pg-r4k.c b/arch/mips/mm/pg-r4k.c
index f51e180072e3..e4390dc3eb48 100644
--- a/arch/mips/mm/pg-r4k.c
+++ b/arch/mips/mm/pg-r4k.c
@@ -124,7 +124,7 @@ static inline void build_nop(void)
124 124
125static inline void build_src_pref(int advance) 125static inline void build_src_pref(int advance)
126{ 126{
127 if (!(load_offset & (cpu_dcache_line_size() - 1))) { 127 if (!(load_offset & (cpu_dcache_line_size() - 1)) && advance) {
128 union mips_instruction mi; 128 union mips_instruction mi;
129 129
130 mi.i_format.opcode = pref_op; 130 mi.i_format.opcode = pref_op;
@@ -166,7 +166,7 @@ static inline void build_load_reg(int reg)
166 166
167static inline void build_dst_pref(int advance) 167static inline void build_dst_pref(int advance)
168{ 168{
169 if (!(store_offset & (cpu_dcache_line_size() - 1))) { 169 if (!(store_offset & (cpu_dcache_line_size() - 1)) && advance) {
170 union mips_instruction mi; 170 union mips_instruction mi;
171 171
172 mi.i_format.opcode = pref_op; 172 mi.i_format.opcode = pref_op;
@@ -340,6 +340,12 @@ void __init build_clear_page(void)
340 340
341 if (cpu_has_prefetch) { 341 if (cpu_has_prefetch) {
342 switch (current_cpu_data.cputype) { 342 switch (current_cpu_data.cputype) {
343 case CPU_TX49XX:
344 /* TX49 supports only Pref_Load */
345 pref_offset_clear = 0;
346 pref_offset_copy = 0;
347 break;
348
343 case CPU_RM9000: 349 case CPU_RM9000:
344 /* 350 /*
345 * As a workaround for erratum G105 which make the 351 * As a workaround for erratum G105 which make the
diff --git a/arch/mips/mm/sc-rm7k.c b/arch/mips/mm/sc-rm7k.c
index 9e8ff8badb19..3b6cc9ba1b05 100644
--- a/arch/mips/mm/sc-rm7k.c
+++ b/arch/mips/mm/sc-rm7k.c
@@ -9,6 +9,7 @@
9#include <linux/init.h> 9#include <linux/init.h>
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/mm.h> 11#include <linux/mm.h>
12#include <linux/bitops.h>
12 13
13#include <asm/addrspace.h> 14#include <asm/addrspace.h>
14#include <asm/bcache.h> 15#include <asm/bcache.h>
@@ -43,14 +44,7 @@ static void rm7k_sc_wback_inv(unsigned long addr, unsigned long size)
43 /* Catch bad driver code */ 44 /* Catch bad driver code */
44 BUG_ON(size == 0); 45 BUG_ON(size == 0);
45 46
46 a = addr & ~(sc_lsize - 1); 47 blast_scache_range(addr, addr + size);
47 end = (addr + size - 1) & ~(sc_lsize - 1);
48 while (1) {
49 flush_scache_line(a); /* Hit_Writeback_Inv_SD */
50 if (a == end)
51 break;
52 a += sc_lsize;
53 }
54 48
55 if (!rm7k_tcache_enabled) 49 if (!rm7k_tcache_enabled)
56 return; 50 return;
@@ -74,14 +68,7 @@ static void rm7k_sc_inv(unsigned long addr, unsigned long size)
74 /* Catch bad driver code */ 68 /* Catch bad driver code */
75 BUG_ON(size == 0); 69 BUG_ON(size == 0);
76 70
77 a = addr & ~(sc_lsize - 1); 71 blast_inv_scache_range(addr, addr + size);
78 end = (addr + size - 1) & ~(sc_lsize - 1);
79 while (1) {
80 invalidate_scache_line(a); /* Hit_Invalidate_SD */
81 if (a == end)
82 break;
83 a += sc_lsize;
84 }
85 72
86 if (!rm7k_tcache_enabled) 73 if (!rm7k_tcache_enabled)
87 return; 74 return;
@@ -143,11 +130,17 @@ struct bcache_ops rm7k_sc_ops = {
143 130
144void __init rm7k_sc_init(void) 131void __init rm7k_sc_init(void)
145{ 132{
133 struct cpuinfo_mips *c = &current_cpu_data;
146 unsigned int config = read_c0_config(); 134 unsigned int config = read_c0_config();
147 135
148 if ((config & RM7K_CONF_SC)) 136 if ((config & RM7K_CONF_SC))
149 return; 137 return;
150 138
139 c->scache.linesz = sc_lsize;
140 c->scache.ways = 4;
141 c->scache.waybit= ffs(scache_size / c->scache.ways) - 1;
142 c->scache.waysize = scache_size / c->scache.ways;
143 c->scache.sets = scache_size / (c->scache.linesz * c->scache.ways);
151 printk(KERN_INFO "Secondary cache size %dK, linesize %d bytes.\n", 144 printk(KERN_INFO "Secondary cache size %dK, linesize %d bytes.\n",
152 (scache_size >> 10), sc_lsize); 145 (scache_size >> 10), sc_lsize);
153 146
diff --git a/arch/mips/mm/tlb-andes.c b/arch/mips/mm/tlb-andes.c
deleted file mode 100644
index 3f422a849c41..000000000000
--- a/arch/mips/mm/tlb-andes.c
+++ /dev/null
@@ -1,259 +0,0 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1997, 1998, 1999 Ralf Baechle (ralf@gnu.org)
7 * Copyright (C) 1999 Silicon Graphics, Inc.
8 * Copyright (C) 2000 Kanoj Sarcar (kanoj@sgi.com)
9 */
10#include <linux/init.h>
11#include <linux/kernel.h>
12#include <linux/sched.h>
13#include <linux/mm.h>
14#include <asm/page.h>
15#include <asm/pgtable.h>
16#include <asm/system.h>
17#include <asm/mmu_context.h>
18
19extern void build_tlb_refill_handler(void);
20
21#define NTLB_ENTRIES 64
22#define NTLB_ENTRIES_HALF 32
23
24void local_flush_tlb_all(void)
25{
26 unsigned long flags;
27 unsigned long old_ctx;
28 unsigned long entry;
29
30 local_irq_save(flags);
31 /* Save old context and create impossible VPN2 value */
32 old_ctx = read_c0_entryhi() & ASID_MASK;
33 write_c0_entryhi(CKSEG0);
34 write_c0_entrylo0(0);
35 write_c0_entrylo1(0);
36
37 entry = read_c0_wired();
38
39 /* Blast 'em all away. */
40 while (entry < NTLB_ENTRIES) {
41 write_c0_index(entry);
42 tlb_write_indexed();
43 entry++;
44 }
45 write_c0_entryhi(old_ctx);
46 local_irq_restore(flags);
47}
48
49void local_flush_tlb_mm(struct mm_struct *mm)
50{
51 int cpu = smp_processor_id();
52 if (cpu_context(cpu, mm) != 0) {
53 drop_mmu_context(mm,cpu);
54 }
55}
56
57void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
58 unsigned long end)
59{
60 struct mm_struct *mm = vma->vm_mm;
61 int cpu = smp_processor_id();
62
63 if (cpu_context(cpu, mm) != 0) {
64 unsigned long flags;
65 int size;
66
67 local_irq_save(flags);
68 size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
69 size = (size + 1) >> 1;
70 if (size <= NTLB_ENTRIES_HALF) {
71 int oldpid = (read_c0_entryhi() & ASID_MASK);
72 int newpid = (cpu_context(smp_processor_id(), mm)
73 & ASID_MASK);
74
75 start &= (PAGE_MASK << 1);
76 end += ((PAGE_SIZE << 1) - 1);
77 end &= (PAGE_MASK << 1);
78 while(start < end) {
79 int idx;
80
81 write_c0_entryhi(start | newpid);
82 start += (PAGE_SIZE << 1);
83 tlb_probe();
84 idx = read_c0_index();
85 write_c0_entrylo0(0);
86 write_c0_entrylo1(0);
87 write_c0_entryhi(CKSEG0);
88 if(idx < 0)
89 continue;
90 tlb_write_indexed();
91 }
92 write_c0_entryhi(oldpid);
93 } else {
94 drop_mmu_context(mm, cpu);
95 }
96 local_irq_restore(flags);
97 }
98}
99
100void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
101{
102 unsigned long flags;
103 int size;
104
105 size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
106 size = (size + 1) >> 1;
107
108 local_irq_save(flags);
109 if (size <= NTLB_ENTRIES_HALF) {
110 int pid = read_c0_entryhi();
111
112 start &= (PAGE_MASK << 1);
113 end += ((PAGE_SIZE << 1) - 1);
114 end &= (PAGE_MASK << 1);
115
116 while (start < end) {
117 int idx;
118
119 write_c0_entryhi(start);
120 start += (PAGE_SIZE << 1);
121 tlb_probe();
122 idx = read_c0_index();
123 write_c0_entrylo0(0);
124 write_c0_entrylo1(0);
125 write_c0_entryhi(CKSEG0 + (idx << (PAGE_SHIFT+1)));
126 if (idx < 0)
127 continue;
128 tlb_write_indexed();
129 }
130 write_c0_entryhi(pid);
131 } else {
132 local_flush_tlb_all();
133 }
134 local_irq_restore(flags);
135}
136
137void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
138{
139 if (cpu_context(smp_processor_id(), vma->vm_mm) != 0) {
140 unsigned long flags;
141 int oldpid, newpid, idx;
142
143 newpid = (cpu_context(smp_processor_id(), vma->vm_mm) &
144 ASID_MASK);
145 page &= (PAGE_MASK << 1);
146 local_irq_save(flags);
147 oldpid = (read_c0_entryhi() & ASID_MASK);
148 write_c0_entryhi(page | newpid);
149 tlb_probe();
150 idx = read_c0_index();
151 write_c0_entrylo0(0);
152 write_c0_entrylo1(0);
153 write_c0_entryhi(CKSEG0);
154 if (idx < 0)
155 goto finish;
156 tlb_write_indexed();
157
158 finish:
159 write_c0_entryhi(oldpid);
160 local_irq_restore(flags);
161 }
162}
163
164/*
165 * This one is only used for pages with the global bit set so we don't care
166 * much about the ASID.
167 */
168void local_flush_tlb_one(unsigned long page)
169{
170 unsigned long flags;
171 int oldpid, idx;
172
173 local_irq_save(flags);
174 page &= (PAGE_MASK << 1);
175 oldpid = read_c0_entryhi() & 0xff;
176 write_c0_entryhi(page);
177 tlb_probe();
178 idx = read_c0_index();
179 write_c0_entrylo0(0);
180 write_c0_entrylo1(0);
181 if (idx >= 0) {
182 /* Make sure all entries differ. */
183 write_c0_entryhi(CKSEG0+(idx<<(PAGE_SHIFT+1)));
184 tlb_write_indexed();
185 }
186 write_c0_entryhi(oldpid);
187
188 local_irq_restore(flags);
189}
190
191/* XXX Simplify this. On the R10000 writing a TLB entry for an virtual
192 address that already exists will overwrite the old entry and not result
193 in TLB malfunction or TLB shutdown. */
194void __update_tlb(struct vm_area_struct * vma, unsigned long address, pte_t pte)
195{
196 unsigned long flags;
197 pgd_t *pgdp;
198 pud_t *pudp;
199 pmd_t *pmdp;
200 pte_t *ptep;
201 int idx, pid;
202
203 /*
204 * Handle debugger faulting in for debugee.
205 */
206 if (current->active_mm != vma->vm_mm)
207 return;
208
209 pid = read_c0_entryhi() & ASID_MASK;
210
211 if ((pid != (cpu_context(smp_processor_id(), vma->vm_mm) & ASID_MASK))
212 || (cpu_context(smp_processor_id(), vma->vm_mm) == 0)) {
213 printk(KERN_WARNING
214 "%s: Wheee, bogus tlbpid mmpid=%d tlbpid=%d\n",
215 __FUNCTION__, (int) (cpu_context(smp_processor_id(),
216 vma->vm_mm) & ASID_MASK), pid);
217 }
218
219 local_irq_save(flags);
220 address &= (PAGE_MASK << 1);
221 write_c0_entryhi(address | (pid));
222 pgdp = pgd_offset(vma->vm_mm, address);
223 tlb_probe();
224 pudp = pud_offset(pgdp, address);
225 pmdp = pmd_offset(pudp, address);
226 idx = read_c0_index();
227 ptep = pte_offset_map(pmdp, address);
228 write_c0_entrylo0(pte_val(*ptep++) >> 6);
229 write_c0_entrylo1(pte_val(*ptep) >> 6);
230 write_c0_entryhi(address | pid);
231 if (idx < 0) {
232 tlb_write_random();
233 } else {
234 tlb_write_indexed();
235 }
236 write_c0_entryhi(pid);
237 local_irq_restore(flags);
238}
239
240void __init tlb_init(void)
241{
242 /*
243 * You should never change this register:
244 * - On R4600 1.7 the tlbp never hits for pages smaller than
245 * the value in the c0_pagemask register.
246 * - The entire mm handling assumes the c0_pagemask register to
247 * be set for 4kb pages.
248 */
249 write_c0_pagemask(PM_4K);
250 write_c0_wired(0);
251 write_c0_framemask(0);
252
253 /* From this point on the ARC firmware is dead. */
254 local_flush_tlb_all();
255
256 /* Did I tell you that ARC SUCKS? */
257
258 build_tlb_refill_handler();
259}
diff --git a/arch/mips/mm/tlb-r4k.c b/arch/mips/mm/tlb-r4k.c
index 8297970f0bb1..a865f2394cb0 100644
--- a/arch/mips/mm/tlb-r4k.c
+++ b/arch/mips/mm/tlb-r4k.c
@@ -424,8 +424,13 @@ void __init tlb_init(void)
424 probe_tlb(config); 424 probe_tlb(config);
425 write_c0_pagemask(PM_DEFAULT_MASK); 425 write_c0_pagemask(PM_DEFAULT_MASK);
426 write_c0_wired(0); 426 write_c0_wired(0);
427 write_c0_framemask(0);
427 temp_tlb_entry = current_cpu_data.tlbsize - 1; 428 temp_tlb_entry = current_cpu_data.tlbsize - 1;
429
430 /* From this point on the ARC firmware is dead. */
428 local_flush_tlb_all(); 431 local_flush_tlb_all();
429 432
433 /* Did I tell you that ARC SUCKS? */
434
430 build_tlb_refill_handler(); 435 build_tlb_refill_handler();
431} 436}
diff --git a/arch/mips/mm/tlbex.c b/arch/mips/mm/tlbex.c
index ac4f4bfaae50..599b3c297186 100644
--- a/arch/mips/mm/tlbex.c
+++ b/arch/mips/mm/tlbex.c
@@ -951,7 +951,6 @@ build_get_pmde64(u32 **p, struct label **l, struct reloc **r,
951 /* No i_nop needed here, since the next insn doesn't touch TMP. */ 951 /* No i_nop needed here, since the next insn doesn't touch TMP. */
952 952
953#ifdef CONFIG_SMP 953#ifdef CONFIG_SMP
954# ifdef CONFIG_BUILD_ELF64
955 /* 954 /*
956 * 64 bit SMP running in XKPHYS has smp_processor_id() << 3 955 * 64 bit SMP running in XKPHYS has smp_processor_id() << 3
957 * stored in CONTEXT. 956 * stored in CONTEXT.
@@ -962,18 +961,6 @@ build_get_pmde64(u32 **p, struct label **l, struct reloc **r,
962 i_daddu(p, ptr, ptr, tmp); 961 i_daddu(p, ptr, ptr, tmp);
963 i_dmfc0(p, tmp, C0_BADVADDR); 962 i_dmfc0(p, tmp, C0_BADVADDR);
964 i_ld(p, ptr, rel_lo(pgdc), ptr); 963 i_ld(p, ptr, rel_lo(pgdc), ptr);
965# else
966 /*
967 * 64 bit SMP running in compat space has the lower part of
968 * &pgd_current[smp_processor_id()] stored in CONTEXT.
969 */
970 if (!in_compat_space_p(pgdc))
971 panic("Invalid page directory address!");
972
973 i_dmfc0(p, ptr, C0_CONTEXT);
974 i_dsra(p, ptr, ptr, 23);
975 i_ld(p, ptr, 0, ptr);
976# endif
977#else 964#else
978 i_LA_mostly(p, ptr, pgdc); 965 i_LA_mostly(p, ptr, pgdc);
979 i_ld(p, ptr, rel_lo(pgdc), ptr); 966 i_ld(p, ptr, rel_lo(pgdc), ptr);
diff --git a/arch/mips/momentum/jaguar_atx/reset.c b/arch/mips/momentum/jaguar_atx/reset.c
index c4236b1e59fa..ce9fb2e3d952 100644
--- a/arch/mips/momentum/jaguar_atx/reset.c
+++ b/arch/mips/momentum/jaguar_atx/reset.c
@@ -32,7 +32,7 @@ void momenco_jaguar_restart(char *command)
32#else 32#else
33 void *nvram = (void*) 0xfc807000; 33 void *nvram = (void*) 0xfc807000;
34#endif 34#endif
35 /* Ask the NVRAM/RTC/watchdog chip to assert reset in 1/16 second */ 35 /* Ask the NVRAM/RTC/watchdog chip to assert reset in 1/16 second */
36 writeb(0x84, nvram + 0xff7); 36 writeb(0x84, nvram + 0xff7);
37 37
38 /* wait for the watchdog to go off */ 38 /* wait for the watchdog to go off */
diff --git a/arch/mips/momentum/jaguar_atx/setup.c b/arch/mips/momentum/jaguar_atx/setup.c
index 2699917b640a..3784c898db1a 100644
--- a/arch/mips/momentum/jaguar_atx/setup.c
+++ b/arch/mips/momentum/jaguar_atx/setup.c
@@ -461,7 +461,7 @@ void __init plat_setup(void)
461 unsigned int tbControl; 461 unsigned int tbControl;
462 tbControl = 462 tbControl =
463 0 << 26 | /* post trigger delay 0 */ 463 0 << 26 | /* post trigger delay 0 */
464 0x2 << 16 | /* sequential trace mode */ 464 0x2 << 16 | /* sequential trace mode */
465 // 0x0 << 16 | /* non-sequential trace mode */ 465 // 0x0 << 16 | /* non-sequential trace mode */
466 // 0xf << 4 | /* watchpoints disabled */ 466 // 0xf << 4 | /* watchpoints disabled */
467 2 << 2 | /* armed */ 467 2 << 2 | /* armed */
diff --git a/arch/mips/momentum/ocelot_3/reset.c b/arch/mips/momentum/ocelot_3/reset.c
index 72b4423c0864..9d86d2468376 100644
--- a/arch/mips/momentum/ocelot_3/reset.c
+++ b/arch/mips/momentum/ocelot_3/reset.c
@@ -34,7 +34,7 @@ void momenco_ocelot_restart(char *command)
34 /* base address of timekeeper portion of part */ 34 /* base address of timekeeper portion of part */
35 void *nvram = (void *) 0xfc807000L; 35 void *nvram = (void *) 0xfc807000L;
36 36
37 /* Ask the NVRAM/RTC/watchdog chip to assert reset in 1/16 second */ 37 /* Ask the NVRAM/RTC/watchdog chip to assert reset in 1/16 second */
38 writeb(0x84, nvram + 0xff7); 38 writeb(0x84, nvram + 0xff7);
39 39
40 /* wait for the watchdog to go off */ 40 /* wait for the watchdog to go off */
diff --git a/arch/mips/momentum/ocelot_c/reset.c b/arch/mips/momentum/ocelot_c/reset.c
index 6a2489f3b9a0..9dcd154c7767 100644
--- a/arch/mips/momentum/ocelot_c/reset.c
+++ b/arch/mips/momentum/ocelot_c/reset.c
@@ -34,7 +34,7 @@ void momenco_ocelot_restart(char *command)
34 0xfc807000; 34 0xfc807000;
35#endif 35#endif
36 36
37 /* Ask the NVRAM/RTC/watchdog chip to assert reset in 1/16 second */ 37 /* Ask the NVRAM/RTC/watchdog chip to assert reset in 1/16 second */
38 writeb(0x84, nvram + 0xff7); 38 writeb(0x84, nvram + 0xff7);
39 39
40 /* wait for the watchdog to go off */ 40 /* wait for the watchdog to go off */
diff --git a/arch/mips/pci/fixup-vr4133.c b/arch/mips/pci/fixup-vr4133.c
index 03a0ff2fc993..a8a47b494b23 100644
--- a/arch/mips/pci/fixup-vr4133.c
+++ b/arch/mips/pci/fixup-vr4133.c
@@ -45,7 +45,7 @@ int pcibios_plat_dev_init(struct pci_dev *dev)
45 45
46 /* 46 /*
47 * we have to open the bridges' windows down to 0 because otherwise 47 * we have to open the bridges' windows down to 0 because otherwise
48 * we cannot access ISA south bridge I/O registers that get mapped from 48 * we cannot access ISA south bridge I/O registers that get mapped from
49 * 0. for example, 8259 PIC would be unaccessible without that 49 * 0. for example, 8259 PIC would be unaccessible without that
50 */ 50 */
51 if(dev->vendor == PCI_VENDOR_ID_INTEL && dev->device == PCI_DEVICE_ID_INTEL_S21152BB) { 51 if(dev->vendor == PCI_VENDOR_ID_INTEL && dev->device == PCI_DEVICE_ID_INTEL_S21152BB) {
diff --git a/arch/mips/pci/ops-ddb5477.c b/arch/mips/pci/ops-ddb5477.c
index 0406b50a37d8..8e57d4c5d90f 100644
--- a/arch/mips/pci/ops-ddb5477.c
+++ b/arch/mips/pci/ops-ddb5477.c
@@ -253,9 +253,9 @@ static int write_config_byte(struct pci_config_swap *swap,
253static int prefix##_##rw##_config(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 star val) \ 253static int prefix##_##rw##_config(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 star val) \
254{ \ 254{ \
255 if (size == 1) \ 255 if (size == 1) \
256 return rw##_config_byte(pciswap, bus, devfn, where, (u8 star)val); \ 256 return rw##_config_byte(pciswap, bus, devfn, where, (u8 star)val); \
257 else if (size == 2) \ 257 else if (size == 2) \
258 return rw##_config_word(pciswap, bus, devfn, where, (u16 star)val); \ 258 return rw##_config_word(pciswap, bus, devfn, where, (u16 star)val); \
259 /* Size must be 4 */ \ 259 /* Size must be 4 */ \
260 return rw##_config_dword(pciswap, bus, devfn, where, val); \ 260 return rw##_config_dword(pciswap, bus, devfn, where, val); \
261} 261}
diff --git a/arch/mips/pci/ops-tx4938.c b/arch/mips/pci/ops-tx4938.c
index 4c0dcfce5297..0ff083489efd 100644
--- a/arch/mips/pci/ops-tx4938.c
+++ b/arch/mips/pci/ops-tx4938.c
@@ -34,16 +34,16 @@ struct resource pci_mem_resource = {
34}; 34};
35 35
36struct resource tx4938_pcic1_pci_io_resource = { 36struct resource tx4938_pcic1_pci_io_resource = {
37 .name = "PCI1 IO", 37 .name = "PCI1 IO",
38 .start = 0, 38 .start = 0,
39 .end = 0, 39 .end = 0,
40 .flags = IORESOURCE_IO 40 .flags = IORESOURCE_IO
41}; 41};
42struct resource tx4938_pcic1_pci_mem_resource = { 42struct resource tx4938_pcic1_pci_mem_resource = {
43 .name = "PCI1 mem", 43 .name = "PCI1 mem",
44 .start = 0, 44 .start = 0,
45 .end = 0, 45 .end = 0,
46 .flags = IORESOURCE_MEM 46 .flags = IORESOURCE_MEM
47}; 47};
48 48
49static int mkaddr(int bus, int dev_fn, int where, int *flagsp) 49static int mkaddr(int bus, int dev_fn, int where, int *flagsp)
diff --git a/arch/mips/pci/pci-bcm1480.c b/arch/mips/pci/pci-bcm1480.c
index ca975e7d32ff..f4ef1a35ca18 100644
--- a/arch/mips/pci/pci-bcm1480.c
+++ b/arch/mips/pci/pci-bcm1480.c
@@ -100,7 +100,7 @@ static int bcm1480_pci_can_access(struct pci_bus *bus, int devfn)
100 100
101 if (bus->number == 0) { 101 if (bus->number == 0) {
102 devno = PCI_SLOT(devfn); 102 devno = PCI_SLOT(devfn);
103 if (bcm1480_bus_status & PCI_DEVICE_MODE) 103 if (bcm1480_bus_status & PCI_DEVICE_MODE)
104 return 0; 104 return 0;
105 else 105 else
106 return 1; 106 return 1;
diff --git a/arch/mips/pci/pci-bcm1480ht.c b/arch/mips/pci/pci-bcm1480ht.c
index aca4a2e7a1c6..a3eebe5890a7 100644
--- a/arch/mips/pci/pci-bcm1480ht.c
+++ b/arch/mips/pci/pci-bcm1480ht.c
@@ -95,7 +95,7 @@ static int bcm1480ht_can_access(struct pci_bus *bus, int devfn)
95 95
96 if (bus->number == 0) { 96 if (bus->number == 0) {
97 devno = PCI_SLOT(devfn); 97 devno = PCI_SLOT(devfn);
98 if (bcm1480ht_bus_status & PCI_DEVICE_MODE) 98 if (bcm1480ht_bus_status & PCI_DEVICE_MODE)
99 return 0; 99 return 0;
100 } 100 }
101 return 1; 101 return 1;
diff --git a/arch/mips/pci/pci-ip27.c b/arch/mips/pci/pci-ip27.c
index efc96ce99eeb..6002d2a6a262 100644
--- a/arch/mips/pci/pci-ip27.c
+++ b/arch/mips/pci/pci-ip27.c
@@ -379,18 +379,18 @@ int __init bridge_probe(nasid_t nasid, int widget_id, int masterwid)
379 bridge = (bridge_t *) RAW_NODE_SWIN_BASE(nasid, widget_id); 379 bridge = (bridge_t *) RAW_NODE_SWIN_BASE(nasid, widget_id);
380 380
381 /* 381 /*
382 * Clear all pending interrupts. 382 * Clear all pending interrupts.
383 */ 383 */
384 bridge->b_int_rst_stat = BRIDGE_IRR_ALL_CLR; 384 bridge->b_int_rst_stat = BRIDGE_IRR_ALL_CLR;
385 385
386 /* 386 /*
387 * Until otherwise set up, assume all interrupts are from slot 0 387 * Until otherwise set up, assume all interrupts are from slot 0
388 */ 388 */
389 bridge->b_int_device = 0x0; 389 bridge->b_int_device = 0x0;
390 390
391 /* 391 /*
392 * swap pio's to pci mem and io space (big windows) 392 * swap pio's to pci mem and io space (big windows)
393 */ 393 */
394 bridge->b_wid_control |= BRIDGE_CTRL_IO_SWAP | 394 bridge->b_wid_control |= BRIDGE_CTRL_IO_SWAP |
395 BRIDGE_CTRL_MEM_SWAP; 395 BRIDGE_CTRL_MEM_SWAP;
396 396
diff --git a/arch/mips/philips/pnx8550/common/int.c b/arch/mips/philips/pnx8550/common/int.c
index 546144988bf5..c500e2d41f2c 100644
--- a/arch/mips/philips/pnx8550/common/int.c
+++ b/arch/mips/philips/pnx8550/common/int.c
@@ -251,7 +251,7 @@ void __init arch_init_irq(void)
251 if (gic_int_line == (PNX8550_INT_GPIO0 - PNX8550_INT_GIC_MIN)) { 251 if (gic_int_line == (PNX8550_INT_GPIO0 - PNX8550_INT_GIC_MIN)) {
252 /* PCI INT through gpio 8, which is setup in 252 /* PCI INT through gpio 8, which is setup in
253 * pnx8550_setup.c and routed to GPIO 253 * pnx8550_setup.c and routed to GPIO
254 * Interrupt Level 0 (GPIO Connection 58). 254 * Interrupt Level 0 (GPIO Connection 58).
255 * Set it active low. */ 255 * Set it active low. */
256 256
257 PNX8550_GIC_REQ(gic_int_line) = 0x1E020000; 257 PNX8550_GIC_REQ(gic_int_line) = 0x1E020000;
diff --git a/arch/mips/qemu/Makefile b/arch/mips/qemu/Makefile
index 934944ab9e85..6a8e8bcef552 100644
--- a/arch/mips/qemu/Makefile
+++ b/arch/mips/qemu/Makefile
@@ -3,3 +3,5 @@
3# 3#
4 4
5obj-y = q-firmware.o q-int.o q-irq.o q-mem.o q-setup.o 5obj-y = q-firmware.o q-int.o q-irq.o q-mem.o q-setup.o
6
7obj-$(CONFIG_SMP) += q-smp.o
diff --git a/arch/mips/qemu/q-smp.c b/arch/mips/qemu/q-smp.c
new file mode 100644
index 000000000000..5a12354cd576
--- /dev/null
+++ b/arch/mips/qemu/q-smp.c
@@ -0,0 +1,48 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2006 by Ralf Baechle (ralf@linux-mips.org)
7 *
8 * Symmetric Uniprocessor (TM) Support
9 */
10#include <linux/kernel.h>
11#include <linux/sched.h>
12
13/*
14 * Send inter-processor interrupt
15 */
16void core_send_ipi(int cpu, unsigned int action)
17{
18 panic(KERN_ERR "%s called", __FUNCTION__);
19}
20
21/*
22 * After we've done initial boot, this function is called to allow the
23 * board code to clean up state, if needed
24 */
25void prom_init_secondary(void)
26{
27}
28
29void prom_smp_finish(void)
30{
31}
32
33/* Hook for after all CPUs are online */
34void prom_cpus_done(void)
35{
36}
37
38void __init prom_prepare_cpus(unsigned int max_cpus)
39{
40 cpus_clear(phys_cpu_present_map);
41}
42
43/*
44 * Firmware CPU startup hook
45 */
46void prom_boot_secondary(int cpu, struct task_struct *idle)
47{
48}
diff --git a/arch/mips/sgi-ip27/ip27-memory.c b/arch/mips/sgi-ip27/ip27-memory.c
index ef20d9ac0ba3..ed93a9792959 100644
--- a/arch/mips/sgi-ip27/ip27-memory.c
+++ b/arch/mips/sgi-ip27/ip27-memory.c
@@ -540,8 +540,8 @@ void __init mem_init(void)
540 struct page *end, *p; 540 struct page *end, *p;
541 541
542 /* 542 /*
543 * This will free up the bootmem, ie, slot 0 memory. 543 * This will free up the bootmem, ie, slot 0 memory.
544 */ 544 */
545 totalram_pages += free_all_bootmem_node(NODE_DATA(node)); 545 totalram_pages += free_all_bootmem_node(NODE_DATA(node));
546 546
547 /* 547 /*
diff --git a/arch/mips/sgi-ip32/ip32-setup.c b/arch/mips/sgi-ip32/ip32-setup.c
index 2c38770b1e1b..2f50c79b7887 100644
--- a/arch/mips/sgi-ip32/ip32-setup.c
+++ b/arch/mips/sgi-ip32/ip32-setup.c
@@ -98,7 +98,7 @@ void __init plat_setup(void)
98 board_timer_setup = ip32_timer_setup; 98 board_timer_setup = ip32_timer_setup;
99 99
100#ifdef CONFIG_SERIAL_8250 100#ifdef CONFIG_SERIAL_8250
101 { 101 {
102 static struct uart_port o2_serial[2]; 102 static struct uart_port o2_serial[2];
103 103
104 memset(o2_serial, 0, sizeof(o2_serial)); 104 memset(o2_serial, 0, sizeof(o2_serial));
diff --git a/arch/mips/tx4927/toshiba_rbtx4927/toshiba_rbtx4927_prom.c b/arch/mips/tx4927/toshiba_rbtx4927/toshiba_rbtx4927_prom.c
index e19e2be70f76..efe50562f0ce 100644
--- a/arch/mips/tx4927/toshiba_rbtx4927/toshiba_rbtx4927_prom.c
+++ b/arch/mips/tx4927/toshiba_rbtx4927/toshiba_rbtx4927_prom.c
@@ -70,10 +70,10 @@ void __init prom_init(void)
70 70
71 if ((read_c0_prid() & 0xff) == PRID_REV_TX4927) { 71 if ((read_c0_prid() & 0xff) == PRID_REV_TX4927) {
72 mips_machtype = MACH_TOSHIBA_RBTX4927; 72 mips_machtype = MACH_TOSHIBA_RBTX4927;
73 toshiba_name = "TX4927"; 73 toshiba_name = "TX4927";
74 } else { 74 } else {
75 mips_machtype = MACH_TOSHIBA_RBTX4937; 75 mips_machtype = MACH_TOSHIBA_RBTX4937;
76 toshiba_name = "TX4937"; 76 toshiba_name = "TX4937";
77 } 77 }
78 78
79 msize = tx4927_get_mem_size(); 79 msize = tx4927_get_mem_size();
diff --git a/arch/mips/tx4938/toshiba_rbtx4938/setup.c b/arch/mips/tx4938/toshiba_rbtx4938/setup.c
index 5c7ace982a49..9166cd4557eb 100644
--- a/arch/mips/tx4938/toshiba_rbtx4938/setup.c
+++ b/arch/mips/tx4938/toshiba_rbtx4938/setup.c
@@ -684,7 +684,7 @@ void __init tx4938_board_setup(void)
684 for (i = 0; i < 8; i++) { 684 for (i = 0; i < 8; i++) {
685 if (!(tx4938_ebuscptr->cr[i] & 0x8)) 685 if (!(tx4938_ebuscptr->cr[i] & 0x8))
686 continue; /* disabled */ 686 continue; /* disabled */
687 rbtx4938_ce_base[i] = (unsigned long)TX4938_EBUSC_BA(i); 687 rbtx4938_ce_base[i] = (unsigned long)TX4938_EBUSC_BA(i);
688 txboard_add_phys_region(rbtx4938_ce_base[i], TX4938_EBUSC_SIZE(i)); 688 txboard_add_phys_region(rbtx4938_ce_base[i], TX4938_EBUSC_SIZE(i));
689 } 689 }
690 690
diff --git a/arch/mips/vr41xx/common/bcu.c b/arch/mips/vr41xx/common/bcu.c
index de0c1b35f11c..ff272b2e8395 100644
--- a/arch/mips/vr41xx/common/bcu.c
+++ b/arch/mips/vr41xx/common/bcu.c
@@ -183,11 +183,11 @@ static inline unsigned long calculate_tclock(uint16_t clkspeed, unsigned long pc
183 switch (current_cpu_data.cputype) { 183 switch (current_cpu_data.cputype) {
184 case CPU_VR4111: 184 case CPU_VR4111:
185 if (!(clkspeed & DIV2B)) 185 if (!(clkspeed & DIV2B))
186 tclock = pclock / 2; 186 tclock = pclock / 2;
187 else if (!(clkspeed & DIV3B)) 187 else if (!(clkspeed & DIV3B))
188 tclock = pclock / 3; 188 tclock = pclock / 3;
189 else if (!(clkspeed & DIV4B)) 189 else if (!(clkspeed & DIV4B))
190 tclock = pclock / 4; 190 tclock = pclock / 4;
191 break; 191 break;
192 case CPU_VR4121: 192 case CPU_VR4121:
193 tclock = pclock / DIVT(clkspeed); 193 tclock = pclock / DIVT(clkspeed);
diff --git a/arch/v850/kernel/vmlinux.lds.S b/arch/v850/kernel/vmlinux.lds.S
index 5be05f47109e..5b2ffcc6e2b2 100644
--- a/arch/v850/kernel/vmlinux.lds.S
+++ b/arch/v850/kernel/vmlinux.lds.S
@@ -64,6 +64,10 @@
64 ___start___ksymtab_gpl = .; \ 64 ___start___ksymtab_gpl = .; \
65 *(__ksymtab_gpl) \ 65 *(__ksymtab_gpl) \
66 ___stop___ksymtab_gpl = .; \ 66 ___stop___ksymtab_gpl = .; \
67 /* Kernel symbol table: GPL-future symbols */ \
68 ___start___ksymtab_gpl_future = .; \
69 *(__ksymtab_gpl_future) \
70 ___stop___ksymtab_gpl_future = .; \
67 /* Kernel symbol table: strings */ \ 71 /* Kernel symbol table: strings */ \
68 *(__ksymtab_strings) \ 72 *(__ksymtab_strings) \
69 /* Kernel symbol table: Normal symbols */ \ 73 /* Kernel symbol table: Normal symbols */ \
@@ -74,6 +78,10 @@
74 ___start___kcrctab_gpl = .; \ 78 ___start___kcrctab_gpl = .; \
75 *(__kcrctab_gpl) \ 79 *(__kcrctab_gpl) \
76 ___stop___kcrctab_gpl = .; \ 80 ___stop___kcrctab_gpl = .; \
81 /* Kernel symbol table: GPL-future symbols */ \
82 ___start___kcrctab_gpl_future = .; \
83 *(__kcrctab_gpl_future) \
84 ___stop___kcrctab_gpl_future = .; \
77 /* Built-in module parameters */ \ 85 /* Built-in module parameters */ \
78 . = ALIGN (4) ; \ 86 . = ALIGN (4) ; \
79 ___start___param = .; \ 87 ___start___param = .; \
diff --git a/arch/x86_64/crypto/aes.c b/arch/x86_64/crypto/aes.c
index fb1b961a2e2f..6f77e7700d32 100644
--- a/arch/x86_64/crypto/aes.c
+++ b/arch/x86_64/crypto/aes.c
@@ -77,12 +77,11 @@ static inline u8 byte(const u32 x, const unsigned n)
77struct aes_ctx 77struct aes_ctx
78{ 78{
79 u32 key_length; 79 u32 key_length;
80 u32 E[60]; 80 u32 buf[120];
81 u32 D[60];
82}; 81};
83 82
84#define E_KEY ctx->E 83#define E_KEY (&ctx->buf[0])
85#define D_KEY ctx->D 84#define D_KEY (&ctx->buf[60])
86 85
87static u8 pow_tab[256] __initdata; 86static u8 pow_tab[256] __initdata;
88static u8 log_tab[256] __initdata; 87static u8 log_tab[256] __initdata;
diff --git a/block/genhd.c b/block/genhd.c
index db57546a709d..64510fd88621 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -15,12 +15,13 @@
15#include <linux/kmod.h> 15#include <linux/kmod.h>
16#include <linux/kobj_map.h> 16#include <linux/kobj_map.h>
17#include <linux/buffer_head.h> 17#include <linux/buffer_head.h>
18#include <linux/mutex.h>
18 19
19#define MAX_PROBE_HASH 255 /* random */ 20#define MAX_PROBE_HASH 255 /* random */
20 21
21static struct subsystem block_subsys; 22static struct subsystem block_subsys;
22 23
23static DECLARE_MUTEX(block_subsys_sem); 24static DEFINE_MUTEX(block_subsys_lock);
24 25
25/* 26/*
26 * Can be deleted altogether. Later. 27 * Can be deleted altogether. Later.
@@ -46,7 +47,7 @@ struct blkdev_info {
46/* 47/*
47 * iterate over a list of blkdev_info structures. allows 48 * iterate over a list of blkdev_info structures. allows
48 * the major_names array to be iterated over from outside this file 49 * the major_names array to be iterated over from outside this file
49 * must be called with the block_subsys_sem held 50 * must be called with the block_subsys_lock held
50 */ 51 */
51void *get_next_blkdev(void *dev) 52void *get_next_blkdev(void *dev)
52{ 53{
@@ -85,20 +86,20 @@ out:
85 86
86void *acquire_blkdev_list(void) 87void *acquire_blkdev_list(void)
87{ 88{
88 down(&block_subsys_sem); 89 mutex_lock(&block_subsys_lock);
89 return get_next_blkdev(NULL); 90 return get_next_blkdev(NULL);
90} 91}
91 92
92void release_blkdev_list(void *dev) 93void release_blkdev_list(void *dev)
93{ 94{
94 up(&block_subsys_sem); 95 mutex_unlock(&block_subsys_lock);
95 kfree(dev); 96 kfree(dev);
96} 97}
97 98
98 99
99/* 100/*
100 * Count the number of records in the blkdev_list. 101 * Count the number of records in the blkdev_list.
101 * must be called with the block_subsys_sem held 102 * must be called with the block_subsys_lock held
102 */ 103 */
103int count_blkdev_list(void) 104int count_blkdev_list(void)
104{ 105{
@@ -118,7 +119,7 @@ int count_blkdev_list(void)
118/* 119/*
119 * extract the major and name values from a blkdev_info struct 120 * extract the major and name values from a blkdev_info struct
120 * passed in as a void to *dev. Must be called with 121 * passed in as a void to *dev. Must be called with
121 * block_subsys_sem held 122 * block_subsys_lock held
122 */ 123 */
123int get_blkdev_info(void *dev, int *major, char **name) 124int get_blkdev_info(void *dev, int *major, char **name)
124{ 125{
@@ -138,7 +139,7 @@ int register_blkdev(unsigned int major, const char *name)
138 struct blk_major_name **n, *p; 139 struct blk_major_name **n, *p;
139 int index, ret = 0; 140 int index, ret = 0;
140 141
141 down(&block_subsys_sem); 142 mutex_lock(&block_subsys_lock);
142 143
143 /* temporary */ 144 /* temporary */
144 if (major == 0) { 145 if (major == 0) {
@@ -183,7 +184,7 @@ int register_blkdev(unsigned int major, const char *name)
183 kfree(p); 184 kfree(p);
184 } 185 }
185out: 186out:
186 up(&block_subsys_sem); 187 mutex_unlock(&block_subsys_lock);
187 return ret; 188 return ret;
188} 189}
189 190
@@ -197,7 +198,7 @@ int unregister_blkdev(unsigned int major, const char *name)
197 int index = major_to_index(major); 198 int index = major_to_index(major);
198 int ret = 0; 199 int ret = 0;
199 200
200 down(&block_subsys_sem); 201 mutex_lock(&block_subsys_lock);
201 for (n = &major_names[index]; *n; n = &(*n)->next) 202 for (n = &major_names[index]; *n; n = &(*n)->next)
202 if ((*n)->major == major) 203 if ((*n)->major == major)
203 break; 204 break;
@@ -207,7 +208,7 @@ int unregister_blkdev(unsigned int major, const char *name)
207 p = *n; 208 p = *n;
208 *n = p->next; 209 *n = p->next;
209 } 210 }
210 up(&block_subsys_sem); 211 mutex_unlock(&block_subsys_lock);
211 kfree(p); 212 kfree(p);
212 213
213 return ret; 214 return ret;
@@ -301,7 +302,7 @@ static void *part_start(struct seq_file *part, loff_t *pos)
301 struct list_head *p; 302 struct list_head *p;
302 loff_t l = *pos; 303 loff_t l = *pos;
303 304
304 down(&block_subsys_sem); 305 mutex_lock(&block_subsys_lock);
305 list_for_each(p, &block_subsys.kset.list) 306 list_for_each(p, &block_subsys.kset.list)
306 if (!l--) 307 if (!l--)
307 return list_entry(p, struct gendisk, kobj.entry); 308 return list_entry(p, struct gendisk, kobj.entry);
@@ -318,7 +319,7 @@ static void *part_next(struct seq_file *part, void *v, loff_t *pos)
318 319
319static void part_stop(struct seq_file *part, void *v) 320static void part_stop(struct seq_file *part, void *v)
320{ 321{
321 up(&block_subsys_sem); 322 mutex_unlock(&block_subsys_lock);
322} 323}
323 324
324static int show_partition(struct seq_file *part, void *v) 325static int show_partition(struct seq_file *part, void *v)
@@ -377,7 +378,7 @@ static struct kobject *base_probe(dev_t dev, int *part, void *data)
377 378
378static int __init genhd_device_init(void) 379static int __init genhd_device_init(void)
379{ 380{
380 bdev_map = kobj_map_init(base_probe, &block_subsys_sem); 381 bdev_map = kobj_map_init(base_probe, &block_subsys_lock);
381 blk_dev_init(); 382 blk_dev_init();
382 subsystem_register(&block_subsys); 383 subsystem_register(&block_subsys);
383 return 0; 384 return 0;
@@ -611,7 +612,7 @@ static void *diskstats_start(struct seq_file *part, loff_t *pos)
611 loff_t k = *pos; 612 loff_t k = *pos;
612 struct list_head *p; 613 struct list_head *p;
613 614
614 down(&block_subsys_sem); 615 mutex_lock(&block_subsys_lock);
615 list_for_each(p, &block_subsys.kset.list) 616 list_for_each(p, &block_subsys.kset.list)
616 if (!k--) 617 if (!k--)
617 return list_entry(p, struct gendisk, kobj.entry); 618 return list_entry(p, struct gendisk, kobj.entry);
@@ -628,7 +629,7 @@ static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos)
628 629
629static void diskstats_stop(struct seq_file *part, void *v) 630static void diskstats_stop(struct seq_file *part, void *v)
630{ 631{
631 up(&block_subsys_sem); 632 mutex_unlock(&block_subsys_lock);
632} 633}
633 634
634static int diskstats_show(struct seq_file *s, void *v) 635static int diskstats_show(struct seq_file *s, void *v)
diff --git a/crypto/aes.c b/crypto/aes.c
index 0a6a5c143686..a5017292e066 100644
--- a/crypto/aes.c
+++ b/crypto/aes.c
@@ -75,12 +75,11 @@ byte(const u32 x, const unsigned n)
75 75
76struct aes_ctx { 76struct aes_ctx {
77 int key_length; 77 int key_length;
78 u32 E[60]; 78 u32 buf[120];
79 u32 D[60];
80}; 79};
81 80
82#define E_KEY ctx->E 81#define E_KEY (&ctx->buf[0])
83#define D_KEY ctx->D 82#define D_KEY (&ctx->buf[60])
84 83
85static u8 pow_tab[256] __initdata; 84static u8 pow_tab[256] __initdata;
86static u8 log_tab[256] __initdata; 85static u8 log_tab[256] __initdata;
diff --git a/crypto/api.c b/crypto/api.c
index e26156f71839..80bba637fba7 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -165,7 +165,7 @@ static unsigned int crypto_ctxsize(struct crypto_alg *alg, int flags)
165 break; 165 break;
166 } 166 }
167 167
168 return len + alg->cra_alignmask; 168 return len + (alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1));
169} 169}
170 170
171struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags) 171struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
@@ -179,12 +179,10 @@ struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
179 goto out; 179 goto out;
180 180
181 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, flags); 181 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, flags);
182 tfm = kmalloc(tfm_size, GFP_KERNEL); 182 tfm = kzalloc(tfm_size, GFP_KERNEL);
183 if (tfm == NULL) 183 if (tfm == NULL)
184 goto out_put; 184 goto out_put;
185 185
186 memset(tfm, 0, tfm_size);
187
188 tfm->__crt_alg = alg; 186 tfm->__crt_alg = alg;
189 187
190 if (crypto_init_flags(tfm, flags)) 188 if (crypto_init_flags(tfm, flags))
diff --git a/crypto/deflate.c b/crypto/deflate.c
index bc73342cd1ec..f209368d62ae 100644
--- a/crypto/deflate.c
+++ b/crypto/deflate.c
@@ -73,12 +73,11 @@ static int deflate_decomp_init(struct deflate_ctx *ctx)
73 int ret = 0; 73 int ret = 0;
74 struct z_stream_s *stream = &ctx->decomp_stream; 74 struct z_stream_s *stream = &ctx->decomp_stream;
75 75
76 stream->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL); 76 stream->workspace = kzalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
77 if (!stream->workspace ) { 77 if (!stream->workspace ) {
78 ret = -ENOMEM; 78 ret = -ENOMEM;
79 goto out; 79 goto out;
80 } 80 }
81 memset(stream->workspace, 0, zlib_inflate_workspacesize());
82 ret = zlib_inflateInit2(stream, -DEFLATE_DEF_WINBITS); 81 ret = zlib_inflateInit2(stream, -DEFLATE_DEF_WINBITS);
83 if (ret != Z_OK) { 82 if (ret != Z_OK) {
84 ret = -EINVAL; 83 ret = -EINVAL;
diff --git a/crypto/des.c b/crypto/des.c
index 7bb548653dc6..2d74cab40c3e 100644
--- a/crypto/des.c
+++ b/crypto/des.c
@@ -965,6 +965,7 @@ static struct crypto_alg des3_ede_alg = {
965 .cra_blocksize = DES3_EDE_BLOCK_SIZE, 965 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
966 .cra_ctxsize = sizeof(struct des3_ede_ctx), 966 .cra_ctxsize = sizeof(struct des3_ede_ctx),
967 .cra_module = THIS_MODULE, 967 .cra_module = THIS_MODULE,
968 .cra_alignmask = 3,
968 .cra_list = LIST_HEAD_INIT(des3_ede_alg.cra_list), 969 .cra_list = LIST_HEAD_INIT(des3_ede_alg.cra_list),
969 .cra_u = { .cipher = { 970 .cra_u = { .cipher = {
970 .cia_min_keysize = DES3_EDE_KEY_SIZE, 971 .cia_min_keysize = DES3_EDE_KEY_SIZE,
diff --git a/crypto/serpent.c b/crypto/serpent.c
index 52ad1a492620..e366406ab49d 100644
--- a/crypto/serpent.c
+++ b/crypto/serpent.c
@@ -481,6 +481,7 @@ static struct crypto_alg serpent_alg = {
481 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 481 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
482 .cra_blocksize = SERPENT_BLOCK_SIZE, 482 .cra_blocksize = SERPENT_BLOCK_SIZE,
483 .cra_ctxsize = sizeof(struct serpent_ctx), 483 .cra_ctxsize = sizeof(struct serpent_ctx),
484 .cra_alignmask = 3,
484 .cra_module = THIS_MODULE, 485 .cra_module = THIS_MODULE,
485 .cra_list = LIST_HEAD_INIT(serpent_alg.cra_list), 486 .cra_list = LIST_HEAD_INIT(serpent_alg.cra_list),
486 .cra_u = { .cipher = { 487 .cra_u = { .cipher = {
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h
index 733d07ed75e9..1f683ba794ee 100644
--- a/crypto/tcrypt.h
+++ b/crypto/tcrypt.h
@@ -26,37 +26,38 @@
26#define MAX_IVLEN 32 26#define MAX_IVLEN 32
27 27
28struct hash_testvec { 28struct hash_testvec {
29 /* only used with keyed hash algorithms */
30 char key[128] __attribute__ ((__aligned__(4)));
29 char plaintext[128]; 31 char plaintext[128];
30 unsigned char psize;
31 char digest[MAX_DIGEST_SIZE]; 32 char digest[MAX_DIGEST_SIZE];
32 unsigned char np;
33 unsigned char tap[MAX_TAP]; 33 unsigned char tap[MAX_TAP];
34 char key[128]; /* only used with keyed hash algorithms */ 34 unsigned char psize;
35 unsigned char np;
35 unsigned char ksize; 36 unsigned char ksize;
36}; 37};
37 38
38struct hmac_testvec { 39struct hmac_testvec {
39 char key[128]; 40 char key[128];
40 unsigned char ksize;
41 char plaintext[128]; 41 char plaintext[128];
42 unsigned char psize;
43 char digest[MAX_DIGEST_SIZE]; 42 char digest[MAX_DIGEST_SIZE];
44 unsigned char np;
45 unsigned char tap[MAX_TAP]; 43 unsigned char tap[MAX_TAP];
44 unsigned char ksize;
45 unsigned char psize;
46 unsigned char np;
46}; 47};
47 48
48struct cipher_testvec { 49struct cipher_testvec {
50 char key[MAX_KEYLEN] __attribute__ ((__aligned__(4)));
51 char iv[MAX_IVLEN];
52 char input[48];
53 char result[48];
54 unsigned char tap[MAX_TAP];
55 int np;
49 unsigned char fail; 56 unsigned char fail;
50 unsigned char wk; /* weak key flag */ 57 unsigned char wk; /* weak key flag */
51 char key[MAX_KEYLEN];
52 unsigned char klen; 58 unsigned char klen;
53 char iv[MAX_IVLEN];
54 char input[48];
55 unsigned char ilen; 59 unsigned char ilen;
56 char result[48];
57 unsigned char rlen; 60 unsigned char rlen;
58 int np;
59 unsigned char tap[MAX_TAP];
60}; 61};
61 62
62struct cipher_speed { 63struct cipher_speed {
diff --git a/crypto/twofish.c b/crypto/twofish.c
index a26d885486fb..ddfd5a3fcc5f 100644
--- a/crypto/twofish.c
+++ b/crypto/twofish.c
@@ -44,6 +44,7 @@
44#include <linux/types.h> 44#include <linux/types.h>
45#include <linux/errno.h> 45#include <linux/errno.h>
46#include <linux/crypto.h> 46#include <linux/crypto.h>
47#include <linux/bitops.h>
47 48
48 49
49/* The large precomputed tables for the Twofish cipher (twofish.c) 50/* The large precomputed tables for the Twofish cipher (twofish.c)
@@ -542,9 +543,9 @@ static const u8 calc_sb_tbl[512] = {
542#define CALC_K(a, j, k, l, m, n) \ 543#define CALC_K(a, j, k, l, m, n) \
543 x = CALC_K_2 (k, l, k, l, 0); \ 544 x = CALC_K_2 (k, l, k, l, 0); \
544 y = CALC_K_2 (m, n, m, n, 4); \ 545 y = CALC_K_2 (m, n, m, n, 4); \
545 y = (y << 8) + (y >> 24); \ 546 y = rol32(y, 8); \
546 x += y; y += x; ctx->a[j] = x; \ 547 x += y; y += x; ctx->a[j] = x; \
547 ctx->a[(j) + 1] = (y << 9) + (y >> 23) 548 ctx->a[(j) + 1] = rol32(y, 9)
548 549
549#define CALC_K192_2(a, b, c, d, j) \ 550#define CALC_K192_2(a, b, c, d, j) \
550 CALC_K_2 (q0[a ^ key[(j) + 16]], \ 551 CALC_K_2 (q0[a ^ key[(j) + 16]], \
@@ -555,9 +556,9 @@ static const u8 calc_sb_tbl[512] = {
555#define CALC_K192(a, j, k, l, m, n) \ 556#define CALC_K192(a, j, k, l, m, n) \
556 x = CALC_K192_2 (l, l, k, k, 0); \ 557 x = CALC_K192_2 (l, l, k, k, 0); \
557 y = CALC_K192_2 (n, n, m, m, 4); \ 558 y = CALC_K192_2 (n, n, m, m, 4); \
558 y = (y << 8) + (y >> 24); \ 559 y = rol32(y, 8); \
559 x += y; y += x; ctx->a[j] = x; \ 560 x += y; y += x; ctx->a[j] = x; \
560 ctx->a[(j) + 1] = (y << 9) + (y >> 23) 561 ctx->a[(j) + 1] = rol32(y, 9)
561 562
562#define CALC_K256_2(a, b, j) \ 563#define CALC_K256_2(a, b, j) \
563 CALC_K192_2 (q1[b ^ key[(j) + 24]], \ 564 CALC_K192_2 (q1[b ^ key[(j) + 24]], \
@@ -568,9 +569,9 @@ static const u8 calc_sb_tbl[512] = {
568#define CALC_K256(a, j, k, l, m, n) \ 569#define CALC_K256(a, j, k, l, m, n) \
569 x = CALC_K256_2 (k, l, 0); \ 570 x = CALC_K256_2 (k, l, 0); \
570 y = CALC_K256_2 (m, n, 4); \ 571 y = CALC_K256_2 (m, n, 4); \
571 y = (y << 8) + (y >> 24); \ 572 y = rol32(y, 8); \
572 x += y; y += x; ctx->a[j] = x; \ 573 x += y; y += x; ctx->a[j] = x; \
573 ctx->a[(j) + 1] = (y << 9) + (y >> 23) 574 ctx->a[(j) + 1] = rol32(y, 9)
574 575
575 576
576/* Macros to compute the g() function in the encryption and decryption 577/* Macros to compute the g() function in the encryption and decryption
@@ -594,15 +595,15 @@ static const u8 calc_sb_tbl[512] = {
594 x = G1 (a); y = G2 (b); \ 595 x = G1 (a); y = G2 (b); \
595 x += y; y += x + ctx->k[2 * (n) + 1]; \ 596 x += y; y += x + ctx->k[2 * (n) + 1]; \
596 (c) ^= x + ctx->k[2 * (n)]; \ 597 (c) ^= x + ctx->k[2 * (n)]; \
597 (c) = ((c) >> 1) + ((c) << 31); \ 598 (c) = ror32((c), 1); \
598 (d) = (((d) << 1)+((d) >> 31)) ^ y 599 (d) = rol32((d), 1) ^ y
599 600
600#define DECROUND(n, a, b, c, d) \ 601#define DECROUND(n, a, b, c, d) \
601 x = G1 (a); y = G2 (b); \ 602 x = G1 (a); y = G2 (b); \
602 x += y; y += x; \ 603 x += y; y += x; \
603 (d) ^= y + ctx->k[2 * (n) + 1]; \ 604 (d) ^= y + ctx->k[2 * (n) + 1]; \
604 (d) = ((d) >> 1) + ((d) << 31); \ 605 (d) = ror32((d), 1); \
605 (c) = (((c) << 1)+((c) >> 31)); \ 606 (c) = rol32((c), 1); \
606 (c) ^= (x + ctx->k[2 * (n)]) 607 (c) ^= (x + ctx->k[2 * (n)])
607 608
608/* Encryption and decryption cycles; each one is simply two Feistel rounds 609/* Encryption and decryption cycles; each one is simply two Feistel rounds
diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
index 06817dec0c25..b1d063cc4fbe 100644
--- a/drivers/atm/suni.c
+++ b/drivers/atm/suni.c
@@ -188,7 +188,7 @@ static int suni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
188 case SONET_GETDIAG: 188 case SONET_GETDIAG:
189 return get_diag(dev,arg); 189 return get_diag(dev,arg);
190 case SONET_SETFRAMING: 190 case SONET_SETFRAMING:
191 if (arg != SONET_FRAME_SONET) return -EINVAL; 191 if ((int)(unsigned long)arg != SONET_FRAME_SONET) return -EINVAL;
192 return 0; 192 return 0;
193 case SONET_GETFRAMING: 193 case SONET_GETFRAMING:
194 return put_user(SONET_FRAME_SONET,(int __user *)arg) ? 194 return put_user(SONET_FRAME_SONET,(int __user *)arg) ?
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 07a7f97e1de9..29f3d7504da1 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -141,7 +141,7 @@ int __devinit register_cpu(struct cpu *cpu, int num, struct node *root)
141 return error; 141 return error;
142} 142}
143 143
144struct sys_device *get_cpu_sysdev(int cpu) 144struct sys_device *get_cpu_sysdev(unsigned cpu)
145{ 145{
146 if (cpu < NR_CPUS) 146 if (cpu < NR_CPUS)
147 return cpu_sys_devices[cpu]; 147 return cpu_sys_devices[cpu];
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index e97e911ebf7a..472318205236 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -211,18 +211,20 @@ static int
211fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size) 211fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
212{ 212{
213 u8 *new_data; 213 u8 *new_data;
214 int new_size = fw_priv->alloc_size;
214 215
215 if (min_size <= fw_priv->alloc_size) 216 if (min_size <= fw_priv->alloc_size)
216 return 0; 217 return 0;
217 218
218 new_data = vmalloc(fw_priv->alloc_size + PAGE_SIZE); 219 new_size = ALIGN(min_size, PAGE_SIZE);
220 new_data = vmalloc(new_size);
219 if (!new_data) { 221 if (!new_data) {
220 printk(KERN_ERR "%s: unable to alloc buffer\n", __FUNCTION__); 222 printk(KERN_ERR "%s: unable to alloc buffer\n", __FUNCTION__);
221 /* Make sure that we don't keep incomplete data */ 223 /* Make sure that we don't keep incomplete data */
222 fw_load_abort(fw_priv); 224 fw_load_abort(fw_priv);
223 return -ENOMEM; 225 return -ENOMEM;
224 } 226 }
225 fw_priv->alloc_size += PAGE_SIZE; 227 fw_priv->alloc_size = new_size;
226 if (fw_priv->fw->data) { 228 if (fw_priv->fw->data) {
227 memcpy(new_data, fw_priv->fw->data, fw_priv->fw->size); 229 memcpy(new_data, fw_priv->fw->data, fw_priv->fw->size);
228 vfree(fw_priv->fw->data); 230 vfree(fw_priv->fw->data);
diff --git a/drivers/base/map.c b/drivers/base/map.c
index b449dae6f0d3..e87017f36853 100644
--- a/drivers/base/map.c
+++ b/drivers/base/map.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/mutex.h>
14#include <linux/kdev_t.h> 15#include <linux/kdev_t.h>
15#include <linux/kobject.h> 16#include <linux/kobject.h>
16#include <linux/kobj_map.h> 17#include <linux/kobj_map.h>
@@ -25,7 +26,7 @@ struct kobj_map {
25 int (*lock)(dev_t, void *); 26 int (*lock)(dev_t, void *);
26 void *data; 27 void *data;
27 } *probes[255]; 28 } *probes[255];
28 struct semaphore *sem; 29 struct mutex *lock;
29}; 30};
30 31
31int kobj_map(struct kobj_map *domain, dev_t dev, unsigned long range, 32int kobj_map(struct kobj_map *domain, dev_t dev, unsigned long range,
@@ -53,7 +54,7 @@ int kobj_map(struct kobj_map *domain, dev_t dev, unsigned long range,
53 p->range = range; 54 p->range = range;
54 p->data = data; 55 p->data = data;
55 } 56 }
56 down(domain->sem); 57 mutex_lock(domain->lock);
57 for (i = 0, p -= n; i < n; i++, p++, index++) { 58 for (i = 0, p -= n; i < n; i++, p++, index++) {
58 struct probe **s = &domain->probes[index % 255]; 59 struct probe **s = &domain->probes[index % 255];
59 while (*s && (*s)->range < range) 60 while (*s && (*s)->range < range)
@@ -61,7 +62,7 @@ int kobj_map(struct kobj_map *domain, dev_t dev, unsigned long range,
61 p->next = *s; 62 p->next = *s;
62 *s = p; 63 *s = p;
63 } 64 }
64 up(domain->sem); 65 mutex_unlock(domain->lock);
65 return 0; 66 return 0;
66} 67}
67 68
@@ -75,7 +76,7 @@ void kobj_unmap(struct kobj_map *domain, dev_t dev, unsigned long range)
75 if (n > 255) 76 if (n > 255)
76 n = 255; 77 n = 255;
77 78
78 down(domain->sem); 79 mutex_lock(domain->lock);
79 for (i = 0; i < n; i++, index++) { 80 for (i = 0; i < n; i++, index++) {
80 struct probe **s; 81 struct probe **s;
81 for (s = &domain->probes[index % 255]; *s; s = &(*s)->next) { 82 for (s = &domain->probes[index % 255]; *s; s = &(*s)->next) {
@@ -88,7 +89,7 @@ void kobj_unmap(struct kobj_map *domain, dev_t dev, unsigned long range)
88 } 89 }
89 } 90 }
90 } 91 }
91 up(domain->sem); 92 mutex_unlock(domain->lock);
92 kfree(found); 93 kfree(found);
93} 94}
94 95
@@ -99,7 +100,7 @@ struct kobject *kobj_lookup(struct kobj_map *domain, dev_t dev, int *index)
99 unsigned long best = ~0UL; 100 unsigned long best = ~0UL;
100 101
101retry: 102retry:
102 down(domain->sem); 103 mutex_lock(domain->lock);
103 for (p = domain->probes[MAJOR(dev) % 255]; p; p = p->next) { 104 for (p = domain->probes[MAJOR(dev) % 255]; p; p = p->next) {
104 struct kobject *(*probe)(dev_t, int *, void *); 105 struct kobject *(*probe)(dev_t, int *, void *);
105 struct module *owner; 106 struct module *owner;
@@ -120,7 +121,7 @@ retry:
120 module_put(owner); 121 module_put(owner);
121 continue; 122 continue;
122 } 123 }
123 up(domain->sem); 124 mutex_unlock(domain->lock);
124 kobj = probe(dev, index, data); 125 kobj = probe(dev, index, data);
125 /* Currently ->owner protects _only_ ->probe() itself. */ 126 /* Currently ->owner protects _only_ ->probe() itself. */
126 module_put(owner); 127 module_put(owner);
@@ -128,11 +129,11 @@ retry:
128 return kobj; 129 return kobj;
129 goto retry; 130 goto retry;
130 } 131 }
131 up(domain->sem); 132 mutex_unlock(domain->lock);
132 return NULL; 133 return NULL;
133} 134}
134 135
135struct kobj_map *kobj_map_init(kobj_probe_t *base_probe, struct semaphore *sem) 136struct kobj_map *kobj_map_init(kobj_probe_t *base_probe, struct mutex *lock)
136{ 137{
137 struct kobj_map *p = kmalloc(sizeof(struct kobj_map), GFP_KERNEL); 138 struct kobj_map *p = kmalloc(sizeof(struct kobj_map), GFP_KERNEL);
138 struct probe *base = kzalloc(sizeof(*base), GFP_KERNEL); 139 struct probe *base = kzalloc(sizeof(*base), GFP_KERNEL);
@@ -149,6 +150,6 @@ struct kobj_map *kobj_map_init(kobj_probe_t *base_probe, struct semaphore *sem)
149 base->get = base_probe; 150 base->get = base_probe;
150 for (i = 0; i < 255; i++) 151 for (i = 0; i < 255; i++)
151 p->probes[i] = base; 152 p->probes[i] = base;
152 p->sem = sem; 153 p->lock = lock;
153 return p; 154 return p;
154} 155}
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 461554a02517..89b268321321 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -61,7 +61,7 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
61{ 61{
62 struct resource *r = platform_get_resource(dev, IORESOURCE_IRQ, num); 62 struct resource *r = platform_get_resource(dev, IORESOURCE_IRQ, num);
63 63
64 return r ? r->start : 0; 64 return r ? r->start : -ENXIO;
65} 65}
66EXPORT_SYMBOL_GPL(platform_get_irq); 66EXPORT_SYMBOL_GPL(platform_get_irq);
67 67
@@ -98,7 +98,7 @@ int platform_get_irq_byname(struct platform_device *dev, char *name)
98{ 98{
99 struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name); 99 struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name);
100 100
101 return r ? r->start : 0; 101 return r ? r->start : -ENXIO;
102} 102}
103EXPORT_SYMBOL_GPL(platform_get_irq_byname); 103EXPORT_SYMBOL_GPL(platform_get_irq_byname);
104 104
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index f04d864770ad..f73446f580df 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -8,7 +8,6 @@
8 * and is not licensed separately. See file COPYING for details. 8 * and is not licensed separately. See file COPYING for details.
9 * 9 *
10 * TODO (sorted by decreasing priority) 10 * TODO (sorted by decreasing priority)
11 * -- Kill first_open (Al Viro fixed the block layer now)
12 * -- set readonly flag for CDs, set removable flag for CF readers 11 * -- set readonly flag for CDs, set removable flag for CF readers
13 * -- do inquiry and verify we got a disk and not a tape (for LUN mismatch) 12 * -- do inquiry and verify we got a disk and not a tape (for LUN mismatch)
14 * -- special case some senses, e.g. 3a/0 -> no media present, reduce retries 13 * -- special case some senses, e.g. 3a/0 -> no media present, reduce retries
@@ -181,6 +180,7 @@ struct ub_dev;
181#define UB_DIR_ILLEGAL2 2 180#define UB_DIR_ILLEGAL2 2
182#define UB_DIR_WRITE 3 181#define UB_DIR_WRITE 3
183 182
183/* P3 */
184#define UB_DIR_CHAR(c) (((c)==UB_DIR_WRITE)? 'w': \ 184#define UB_DIR_CHAR(c) (((c)==UB_DIR_WRITE)? 'w': \
185 (((c)==UB_DIR_READ)? 'r': 'n')) 185 (((c)==UB_DIR_READ)? 'r': 'n'))
186 186
@@ -196,24 +196,11 @@ enum ub_scsi_cmd_state {
196 UB_CMDST_DONE /* Final state */ 196 UB_CMDST_DONE /* Final state */
197}; 197};
198 198
199static char *ub_scsi_cmd_stname[] = {
200 ". ",
201 "Cmd",
202 "dat",
203 "c2s",
204 "sts",
205 "clr",
206 "crs",
207 "Sen",
208 "fin"
209};
210
211struct ub_scsi_cmd { 199struct ub_scsi_cmd {
212 unsigned char cdb[UB_MAX_CDB_SIZE]; 200 unsigned char cdb[UB_MAX_CDB_SIZE];
213 unsigned char cdb_len; 201 unsigned char cdb_len;
214 202
215 unsigned char dir; /* 0 - none, 1 - read, 3 - write. */ 203 unsigned char dir; /* 0 - none, 1 - read, 3 - write. */
216 unsigned char trace_index;
217 enum ub_scsi_cmd_state state; 204 enum ub_scsi_cmd_state state;
218 unsigned int tag; 205 unsigned int tag;
219 struct ub_scsi_cmd *next; 206 struct ub_scsi_cmd *next;
@@ -250,28 +237,6 @@ struct ub_capacity {
250}; 237};
251 238
252/* 239/*
253 * The SCSI command tracing structure.
254 */
255
256#define SCMD_ST_HIST_SZ 8
257#define SCMD_TRACE_SZ 63 /* Less than 4KB of 61-byte lines */
258
259struct ub_scsi_cmd_trace {
260 int hcur;
261 unsigned int tag;
262 unsigned int req_size, act_size;
263 unsigned char op;
264 unsigned char dir;
265 unsigned char key, asc, ascq;
266 char st_hst[SCMD_ST_HIST_SZ];
267};
268
269struct ub_scsi_trace {
270 int cur;
271 struct ub_scsi_cmd_trace vec[SCMD_TRACE_SZ];
272};
273
274/*
275 * This is a direct take-off from linux/include/completion.h 240 * This is a direct take-off from linux/include/completion.h
276 * The difference is that I do not wait on this thing, just poll. 241 * The difference is that I do not wait on this thing, just poll.
277 * When I want to wait (ub_probe), I just use the stock completion. 242 * When I want to wait (ub_probe), I just use the stock completion.
@@ -334,7 +299,6 @@ struct ub_lun {
334 int changed; /* Media was changed */ 299 int changed; /* Media was changed */
335 int removable; 300 int removable;
336 int readonly; 301 int readonly;
337 int first_open; /* Kludge. See ub_bd_open. */
338 302
339 struct ub_request urq; 303 struct ub_request urq;
340 304
@@ -390,7 +354,6 @@ struct ub_dev {
390 wait_queue_head_t reset_wait; 354 wait_queue_head_t reset_wait;
391 355
392 int sg_stat[6]; 356 int sg_stat[6];
393 struct ub_scsi_trace tr;
394}; 357};
395 358
396/* 359/*
@@ -460,137 +423,6 @@ static int ub_qlock_next = 0;
460static DEFINE_SPINLOCK(ub_lock); /* Locks globals and ->openc */ 423static DEFINE_SPINLOCK(ub_lock); /* Locks globals and ->openc */
461 424
462/* 425/*
463 * The SCSI command tracing procedures.
464 */
465
466static void ub_cmdtr_new(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
467{
468 int n;
469 struct ub_scsi_cmd_trace *t;
470
471 if ((n = sc->tr.cur + 1) == SCMD_TRACE_SZ) n = 0;
472 t = &sc->tr.vec[n];
473
474 memset(t, 0, sizeof(struct ub_scsi_cmd_trace));
475 t->tag = cmd->tag;
476 t->op = cmd->cdb[0];
477 t->dir = cmd->dir;
478 t->req_size = cmd->len;
479 t->st_hst[0] = cmd->state;
480
481 sc->tr.cur = n;
482 cmd->trace_index = n;
483}
484
485static void ub_cmdtr_state(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
486{
487 int n;
488 struct ub_scsi_cmd_trace *t;
489
490 t = &sc->tr.vec[cmd->trace_index];
491 if (t->tag == cmd->tag) {
492 if ((n = t->hcur + 1) == SCMD_ST_HIST_SZ) n = 0;
493 t->st_hst[n] = cmd->state;
494 t->hcur = n;
495 }
496}
497
498static void ub_cmdtr_act_len(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
499{
500 struct ub_scsi_cmd_trace *t;
501
502 t = &sc->tr.vec[cmd->trace_index];
503 if (t->tag == cmd->tag)
504 t->act_size = cmd->act_len;
505}
506
507static void ub_cmdtr_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd,
508 unsigned char *sense)
509{
510 struct ub_scsi_cmd_trace *t;
511
512 t = &sc->tr.vec[cmd->trace_index];
513 if (t->tag == cmd->tag) {
514 t->key = sense[2] & 0x0F;
515 t->asc = sense[12];
516 t->ascq = sense[13];
517 }
518}
519
520static ssize_t ub_diag_show(struct device *dev, struct device_attribute *attr,
521 char *page)
522{
523 struct usb_interface *intf;
524 struct ub_dev *sc;
525 struct list_head *p;
526 struct ub_lun *lun;
527 int cnt;
528 unsigned long flags;
529 int nc, nh;
530 int i, j;
531 struct ub_scsi_cmd_trace *t;
532
533 intf = to_usb_interface(dev);
534 sc = usb_get_intfdata(intf);
535 if (sc == NULL)
536 return 0;
537
538 cnt = 0;
539 spin_lock_irqsave(sc->lock, flags);
540
541 cnt += sprintf(page + cnt,
542 "poison %d reset %d\n",
543 atomic_read(&sc->poison), sc->reset);
544 cnt += sprintf(page + cnt,
545 "qlen %d qmax %d\n",
546 sc->cmd_queue.qlen, sc->cmd_queue.qmax);
547 cnt += sprintf(page + cnt,
548 "sg %d %d %d %d %d .. %d\n",
549 sc->sg_stat[0],
550 sc->sg_stat[1],
551 sc->sg_stat[2],
552 sc->sg_stat[3],
553 sc->sg_stat[4],
554 sc->sg_stat[5]);
555
556 list_for_each (p, &sc->luns) {
557 lun = list_entry(p, struct ub_lun, link);
558 cnt += sprintf(page + cnt,
559 "lun %u changed %d removable %d readonly %d\n",
560 lun->num, lun->changed, lun->removable, lun->readonly);
561 }
562
563 if ((nc = sc->tr.cur + 1) == SCMD_TRACE_SZ) nc = 0;
564 for (j = 0; j < SCMD_TRACE_SZ; j++) {
565 t = &sc->tr.vec[nc];
566
567 cnt += sprintf(page + cnt, "%08x %02x", t->tag, t->op);
568 if (t->op == REQUEST_SENSE) {
569 cnt += sprintf(page + cnt, " [sense %x %02x %02x]",
570 t->key, t->asc, t->ascq);
571 } else {
572 cnt += sprintf(page + cnt, " %c", UB_DIR_CHAR(t->dir));
573 cnt += sprintf(page + cnt, " [%5d %5d]",
574 t->req_size, t->act_size);
575 }
576 if ((nh = t->hcur + 1) == SCMD_ST_HIST_SZ) nh = 0;
577 for (i = 0; i < SCMD_ST_HIST_SZ; i++) {
578 cnt += sprintf(page + cnt, " %s",
579 ub_scsi_cmd_stname[(int)t->st_hst[nh]]);
580 if (++nh == SCMD_ST_HIST_SZ) nh = 0;
581 }
582 cnt += sprintf(page + cnt, "\n");
583
584 if (++nc == SCMD_TRACE_SZ) nc = 0;
585 }
586
587 spin_unlock_irqrestore(sc->lock, flags);
588 return cnt;
589}
590
591static DEVICE_ATTR(diag, S_IRUGO, ub_diag_show, NULL); /* N.B. World readable */
592
593/*
594 * The id allocator. 426 * The id allocator.
595 * 427 *
596 * This also stores the host for indexing by minor, which is somewhat dirty. 428 * This also stores the host for indexing by minor, which is somewhat dirty.
@@ -1092,7 +924,6 @@ static int ub_scsi_cmd_start(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1092 add_timer(&sc->work_timer); 924 add_timer(&sc->work_timer);
1093 925
1094 cmd->state = UB_CMDST_CMD; 926 cmd->state = UB_CMDST_CMD;
1095 ub_cmdtr_state(sc, cmd);
1096 return 0; 927 return 0;
1097} 928}
1098 929
@@ -1145,12 +976,10 @@ static void ub_scsi_dispatch(struct ub_dev *sc)
1145 ub_cmdq_pop(sc); 976 ub_cmdq_pop(sc);
1146 (*cmd->done)(sc, cmd); 977 (*cmd->done)(sc, cmd);
1147 } else if (cmd->state == UB_CMDST_INIT) { 978 } else if (cmd->state == UB_CMDST_INIT) {
1148 ub_cmdtr_new(sc, cmd);
1149 if ((rc = ub_scsi_cmd_start(sc, cmd)) == 0) 979 if ((rc = ub_scsi_cmd_start(sc, cmd)) == 0)
1150 break; 980 break;
1151 cmd->error = rc; 981 cmd->error = rc;
1152 cmd->state = UB_CMDST_DONE; 982 cmd->state = UB_CMDST_DONE;
1153 ub_cmdtr_state(sc, cmd);
1154 } else { 983 } else {
1155 if (!ub_is_completed(&sc->work_done)) 984 if (!ub_is_completed(&sc->work_done))
1156 break; 985 break;
@@ -1247,7 +1076,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1247 return; 1076 return;
1248 } 1077 }
1249 cmd->state = UB_CMDST_CLEAR; 1078 cmd->state = UB_CMDST_CLEAR;
1250 ub_cmdtr_state(sc, cmd);
1251 return; 1079 return;
1252 case -ESHUTDOWN: /* unplug */ 1080 case -ESHUTDOWN: /* unplug */
1253 case -EILSEQ: /* unplug timeout on uhci */ 1081 case -EILSEQ: /* unplug timeout on uhci */
@@ -1279,7 +1107,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1279 return; 1107 return;
1280 } 1108 }
1281 cmd->state = UB_CMDST_CLR2STS; 1109 cmd->state = UB_CMDST_CLR2STS;
1282 ub_cmdtr_state(sc, cmd);
1283 return; 1110 return;
1284 } 1111 }
1285 if (urb->status == -EOVERFLOW) { 1112 if (urb->status == -EOVERFLOW) {
@@ -1304,7 +1131,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1304 if (urb->status != 0 || 1131 if (urb->status != 0 ||
1305 len != cmd->sgv[cmd->current_sg].length) { 1132 len != cmd->sgv[cmd->current_sg].length) {
1306 cmd->act_len += len; 1133 cmd->act_len += len;
1307 ub_cmdtr_act_len(sc, cmd);
1308 1134
1309 cmd->error = -EIO; 1135 cmd->error = -EIO;
1310 ub_state_stat(sc, cmd); 1136 ub_state_stat(sc, cmd);
@@ -1331,7 +1157,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1331 } 1157 }
1332 1158
1333 cmd->act_len += urb->actual_length; 1159 cmd->act_len += urb->actual_length;
1334 ub_cmdtr_act_len(sc, cmd);
1335 1160
1336 if (++cmd->current_sg < cmd->nsg) { 1161 if (++cmd->current_sg < cmd->nsg) {
1337 ub_data_start(sc, cmd); 1162 ub_data_start(sc, cmd);
@@ -1357,7 +1182,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1357 cmd->error = -EIO; /* A cheap trick... */ 1182 cmd->error = -EIO; /* A cheap trick... */
1358 1183
1359 cmd->state = UB_CMDST_CLRRS; 1184 cmd->state = UB_CMDST_CLRRS;
1360 ub_cmdtr_state(sc, cmd);
1361 return; 1185 return;
1362 } 1186 }
1363 1187
@@ -1441,7 +1265,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1441 return; 1265 return;
1442 } 1266 }
1443 cmd->state = UB_CMDST_DONE; 1267 cmd->state = UB_CMDST_DONE;
1444 ub_cmdtr_state(sc, cmd);
1445 ub_cmdq_pop(sc); 1268 ub_cmdq_pop(sc);
1446 (*cmd->done)(sc, cmd); 1269 (*cmd->done)(sc, cmd);
1447 1270
@@ -1496,7 +1319,6 @@ static void ub_data_start(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1496 add_timer(&sc->work_timer); 1319 add_timer(&sc->work_timer);
1497 1320
1498 cmd->state = UB_CMDST_DATA; 1321 cmd->state = UB_CMDST_DATA;
1499 ub_cmdtr_state(sc, cmd);
1500} 1322}
1501 1323
1502/* 1324/*
@@ -1508,7 +1330,6 @@ static void ub_state_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd, int rc)
1508 1330
1509 cmd->error = rc; 1331 cmd->error = rc;
1510 cmd->state = UB_CMDST_DONE; 1332 cmd->state = UB_CMDST_DONE;
1511 ub_cmdtr_state(sc, cmd);
1512 ub_cmdq_pop(sc); 1333 ub_cmdq_pop(sc);
1513 (*cmd->done)(sc, cmd); 1334 (*cmd->done)(sc, cmd);
1514} 1335}
@@ -1554,7 +1375,6 @@ static void ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1554 1375
1555 cmd->stat_count = 0; 1376 cmd->stat_count = 0;
1556 cmd->state = UB_CMDST_STAT; 1377 cmd->state = UB_CMDST_STAT;
1557 ub_cmdtr_state(sc, cmd);
1558} 1378}
1559 1379
1560/* 1380/*
@@ -1573,7 +1393,6 @@ static void ub_state_stat_counted(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1573 return; 1393 return;
1574 1394
1575 cmd->state = UB_CMDST_STAT; 1395 cmd->state = UB_CMDST_STAT;
1576 ub_cmdtr_state(sc, cmd);
1577} 1396}
1578 1397
1579/* 1398/*
@@ -1611,7 +1430,6 @@ static void ub_state_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1611 scmd->tag = sc->tagcnt++; 1430 scmd->tag = sc->tagcnt++;
1612 1431
1613 cmd->state = UB_CMDST_SENSE; 1432 cmd->state = UB_CMDST_SENSE;
1614 ub_cmdtr_state(sc, cmd);
1615 1433
1616 ub_cmdq_insert(sc, scmd); 1434 ub_cmdq_insert(sc, scmd);
1617 return; 1435 return;
@@ -1668,11 +1486,6 @@ static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd)
1668 struct ub_scsi_cmd *cmd; 1486 struct ub_scsi_cmd *cmd;
1669 1487
1670 /* 1488 /*
1671 * Ignoring scmd->act_len, because the buffer was pre-zeroed.
1672 */
1673 ub_cmdtr_sense(sc, scmd, sense);
1674
1675 /*
1676 * Find the command which triggered the unit attention or a check, 1489 * Find the command which triggered the unit attention or a check,
1677 * save the sense into it, and advance its state machine. 1490 * save the sense into it, and advance its state machine.
1678 */ 1491 */
@@ -1693,6 +1506,9 @@ static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd)
1693 return; 1506 return;
1694 } 1507 }
1695 1508
1509 /*
1510 * Ignoring scmd->act_len, because the buffer was pre-zeroed.
1511 */
1696 cmd->key = sense[2] & 0x0F; 1512 cmd->key = sense[2] & 0x0F;
1697 cmd->asc = sense[12]; 1513 cmd->asc = sense[12];
1698 cmd->ascq = sense[13]; 1514 cmd->ascq = sense[13];
@@ -1849,26 +1665,6 @@ static int ub_bd_open(struct inode *inode, struct file *filp)
1849 sc->openc++; 1665 sc->openc++;
1850 spin_unlock_irqrestore(&ub_lock, flags); 1666 spin_unlock_irqrestore(&ub_lock, flags);
1851 1667
1852 /*
1853 * This is a workaround for a specific problem in our block layer.
1854 * In 2.6.9, register_disk duplicates the code from rescan_partitions.
1855 * However, if we do add_disk with a device which persistently reports
1856 * a changed media, add_disk calls register_disk, which does do_open,
1857 * which will call rescan_paritions for changed media. After that,
1858 * register_disk attempts to do it all again and causes double kobject
1859 * registration and a eventually an oops on module removal.
1860 *
1861 * The bottom line is, Al Viro says that we should not allow
1862 * bdev->bd_invalidated to be set when doing add_disk no matter what.
1863 */
1864 if (lun->first_open) {
1865 lun->first_open = 0;
1866 if (lun->changed) {
1867 rc = -ENOMEDIUM;
1868 goto err_open;
1869 }
1870 }
1871
1872 if (lun->removable || lun->readonly) 1668 if (lun->removable || lun->readonly)
1873 check_disk_change(inode->i_bdev); 1669 check_disk_change(inode->i_bdev);
1874 1670
@@ -2007,9 +1803,8 @@ static int ub_sync_tur(struct ub_dev *sc, struct ub_lun *lun)
2007 init_completion(&compl); 1803 init_completion(&compl);
2008 1804
2009 rc = -ENOMEM; 1805 rc = -ENOMEM;
2010 if ((cmd = kmalloc(ALLOC_SIZE, GFP_KERNEL)) == NULL) 1806 if ((cmd = kzalloc(ALLOC_SIZE, GFP_KERNEL)) == NULL)
2011 goto err_alloc; 1807 goto err_alloc;
2012 memset(cmd, 0, ALLOC_SIZE);
2013 1808
2014 cmd->cdb[0] = TEST_UNIT_READY; 1809 cmd->cdb[0] = TEST_UNIT_READY;
2015 cmd->cdb_len = 6; 1810 cmd->cdb_len = 6;
@@ -2062,9 +1857,8 @@ static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun,
2062 init_completion(&compl); 1857 init_completion(&compl);
2063 1858
2064 rc = -ENOMEM; 1859 rc = -ENOMEM;
2065 if ((cmd = kmalloc(ALLOC_SIZE, GFP_KERNEL)) == NULL) 1860 if ((cmd = kzalloc(ALLOC_SIZE, GFP_KERNEL)) == NULL)
2066 goto err_alloc; 1861 goto err_alloc;
2067 memset(cmd, 0, ALLOC_SIZE);
2068 p = (char *)cmd + sizeof(struct ub_scsi_cmd); 1862 p = (char *)cmd + sizeof(struct ub_scsi_cmd);
2069 1863
2070 cmd->cdb[0] = 0x25; 1864 cmd->cdb[0] = 0x25;
@@ -2405,9 +2199,8 @@ static int ub_probe(struct usb_interface *intf,
2405 return -ENXIO; 2199 return -ENXIO;
2406 2200
2407 rc = -ENOMEM; 2201 rc = -ENOMEM;
2408 if ((sc = kmalloc(sizeof(struct ub_dev), GFP_KERNEL)) == NULL) 2202 if ((sc = kzalloc(sizeof(struct ub_dev), GFP_KERNEL)) == NULL)
2409 goto err_core; 2203 goto err_core;
2410 memset(sc, 0, sizeof(struct ub_dev));
2411 sc->lock = ub_next_lock(); 2204 sc->lock = ub_next_lock();
2412 INIT_LIST_HEAD(&sc->luns); 2205 INIT_LIST_HEAD(&sc->luns);
2413 usb_init_urb(&sc->work_urb); 2206 usb_init_urb(&sc->work_urb);
@@ -2438,9 +2231,6 @@ static int ub_probe(struct usb_interface *intf,
2438 if (ub_get_pipes(sc, sc->dev, intf) != 0) 2231 if (ub_get_pipes(sc, sc->dev, intf) != 0)
2439 goto err_dev_desc; 2232 goto err_dev_desc;
2440 2233
2441 if (device_create_file(&sc->intf->dev, &dev_attr_diag) != 0)
2442 goto err_diag;
2443
2444 /* 2234 /*
2445 * At this point, all USB initialization is done, do upper layer. 2235 * At this point, all USB initialization is done, do upper layer.
2446 * We really hate halfway initialized structures, so from the 2236 * We really hate halfway initialized structures, so from the
@@ -2480,19 +2270,8 @@ static int ub_probe(struct usb_interface *intf,
2480 2270
2481 nluns = 1; 2271 nluns = 1;
2482 for (i = 0; i < 3; i++) { 2272 for (i = 0; i < 3; i++) {
2483 if ((rc = ub_sync_getmaxlun(sc)) < 0) { 2273 if ((rc = ub_sync_getmaxlun(sc)) < 0)
2484 /*
2485 * This segment is taken from usb-storage. They say
2486 * that ZIP-100 needs this, but my own ZIP-100 works
2487 * fine without this.
2488 * Still, it does not seem to hurt anything.
2489 */
2490 if (rc == -EPIPE) {
2491 ub_probe_clear_stall(sc, sc->recv_bulk_pipe);
2492 ub_probe_clear_stall(sc, sc->send_bulk_pipe);
2493 }
2494 break; 2274 break;
2495 }
2496 if (rc != 0) { 2275 if (rc != 0) {
2497 nluns = rc; 2276 nluns = rc;
2498 break; 2277 break;
@@ -2505,8 +2284,6 @@ static int ub_probe(struct usb_interface *intf,
2505 } 2284 }
2506 return 0; 2285 return 0;
2507 2286
2508 /* device_remove_file(&sc->intf->dev, &dev_attr_diag); */
2509err_diag:
2510err_dev_desc: 2287err_dev_desc:
2511 usb_set_intfdata(intf, NULL); 2288 usb_set_intfdata(intf, NULL);
2512 // usb_put_intf(sc->intf); 2289 // usb_put_intf(sc->intf);
@@ -2524,9 +2301,8 @@ static int ub_probe_lun(struct ub_dev *sc, int lnum)
2524 int rc; 2301 int rc;
2525 2302
2526 rc = -ENOMEM; 2303 rc = -ENOMEM;
2527 if ((lun = kmalloc(sizeof(struct ub_lun), GFP_KERNEL)) == NULL) 2304 if ((lun = kzalloc(sizeof(struct ub_lun), GFP_KERNEL)) == NULL)
2528 goto err_alloc; 2305 goto err_alloc;
2529 memset(lun, 0, sizeof(struct ub_lun));
2530 lun->num = lnum; 2306 lun->num = lnum;
2531 2307
2532 rc = -ENOSR; 2308 rc = -ENOSR;
@@ -2541,7 +2317,6 @@ static int ub_probe_lun(struct ub_dev *sc, int lnum)
2541 2317
2542 lun->removable = 1; /* XXX Query this from the device */ 2318 lun->removable = 1; /* XXX Query this from the device */
2543 lun->changed = 1; /* ub_revalidate clears only */ 2319 lun->changed = 1; /* ub_revalidate clears only */
2544 lun->first_open = 1;
2545 ub_revalidate(sc, lun); 2320 ub_revalidate(sc, lun);
2546 2321
2547 rc = -ENOMEM; 2322 rc = -ENOMEM;
@@ -2636,7 +2411,6 @@ static void ub_disconnect(struct usb_interface *intf)
2636 while ((cmd = ub_cmdq_peek(sc)) != NULL) { 2411 while ((cmd = ub_cmdq_peek(sc)) != NULL) {
2637 cmd->error = -ENOTCONN; 2412 cmd->error = -ENOTCONN;
2638 cmd->state = UB_CMDST_DONE; 2413 cmd->state = UB_CMDST_DONE;
2639 ub_cmdtr_state(sc, cmd);
2640 ub_cmdq_pop(sc); 2414 ub_cmdq_pop(sc);
2641 (*cmd->done)(sc, cmd); 2415 (*cmd->done)(sc, cmd);
2642 cnt++; 2416 cnt++;
@@ -2687,7 +2461,6 @@ static void ub_disconnect(struct usb_interface *intf)
2687 * and no URBs left in transit. 2461 * and no URBs left in transit.
2688 */ 2462 */
2689 2463
2690 device_remove_file(&sc->intf->dev, &dev_attr_diag);
2691 usb_set_intfdata(intf, NULL); 2464 usb_set_intfdata(intf, NULL);
2692 // usb_put_intf(sc->intf); 2465 // usb_put_intf(sc->intf);
2693 sc->intf = NULL; 2466 sc->intf = NULL;
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 503dd901d406..090d154098bb 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -31,7 +31,7 @@ obj-$(CONFIG_MOXA_INTELLIO) += moxa.o
31obj-$(CONFIG_A2232) += ser_a2232.o generic_serial.o 31obj-$(CONFIG_A2232) += ser_a2232.o generic_serial.o
32obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o 32obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o
33obj-$(CONFIG_MOXA_SMARTIO) += mxser.o 33obj-$(CONFIG_MOXA_SMARTIO) += mxser.o
34obj-$(CONFIG_COMPUTONE) += ip2.o ip2main.o 34obj-$(CONFIG_COMPUTONE) += ip2/
35obj-$(CONFIG_RISCOM8) += riscom8.o 35obj-$(CONFIG_RISCOM8) += riscom8.o
36obj-$(CONFIG_ISI) += isicom.o 36obj-$(CONFIG_ISI) += isicom.o
37obj-$(CONFIG_SYNCLINK) += synclink.o 37obj-$(CONFIG_SYNCLINK) += synclink.o
diff --git a/drivers/char/drm/Kconfig b/drivers/char/drm/Kconfig
index 56ace9d5e2ae..5278c388d3e7 100644
--- a/drivers/char/drm/Kconfig
+++ b/drivers/char/drm/Kconfig
@@ -37,8 +37,8 @@ config DRM_RADEON
37 help 37 help
38 Choose this option if you have an ATI Radeon graphics card. There 38 Choose this option if you have an ATI Radeon graphics card. There
39 are both PCI and AGP versions. You don't need to choose this to 39 are both PCI and AGP versions. You don't need to choose this to
40 run the Radeon in plain VGA mode. There is a product page at 40 run the Radeon in plain VGA mode.
41 <http://www.ati.com/na/pages/products/pc/radeon32/index.html>. 41
42 If M is selected, the module will be called radeon. 42 If M is selected, the module will be called radeon.
43 43
44config DRM_I810 44config DRM_I810
diff --git a/drivers/char/ip2/Makefile b/drivers/char/ip2/Makefile
new file mode 100644
index 000000000000..6bfe2543ddc2
--- /dev/null
+++ b/drivers/char/ip2/Makefile
@@ -0,0 +1,8 @@
1#
2# Makefile for the Computone IntelliPort Plus Driver
3#
4
5obj-$(CONFIG_COMPUTONE) += ip2.o ip2main.o
6
7ip2-objs := ip2base.o
8
diff --git a/drivers/char/ip2.c b/drivers/char/ip2/ip2base.c
index 7cadfc6ef352..435ccfc74958 100644
--- a/drivers/char/ip2.c
+++ b/drivers/char/ip2/ip2base.c
@@ -20,14 +20,14 @@
20#define __initdata 20#define __initdata
21#endif 21#endif
22 22
23#include "./ip2/ip2types.h" 23#include "ip2types.h"
24#include "./ip2/fip_firm.h" // the meat 24#include "fip_firm.h" // the meat
25 25
26int 26int
27ip2_loadmain(int *, int *, unsigned char *, int ); // ref into ip2main.c 27ip2_loadmain(int *, int *, unsigned char *, int ); // ref into ip2main.c
28 28
29/* Note: Add compiled in defaults to these arrays, not to the structure 29/* Note: Add compiled in defaults to these arrays, not to the structure
30 in ip2/ip2.h any longer. That structure WILL get overridden 30 in ip2.h any longer. That structure WILL get overridden
31 by these values, or command line values, or insmod values!!! =mhw= 31 by these values, or command line values, or insmod values!!! =mhw=
32*/ 32*/
33static int io[IP2_MAX_BOARDS]= { 0, 0, 0, 0 }; 33static int io[IP2_MAX_BOARDS]= { 0, 0, 0, 0 };
diff --git a/drivers/char/ip2main.c b/drivers/char/ip2/ip2main.c
index 48fcfba37bfa..03db1cb3fa95 100644
--- a/drivers/char/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -35,7 +35,7 @@
35// Clean up potential NULL pointer dereferences 35// Clean up potential NULL pointer dereferences
36// Clean up devfs registration 36// Clean up devfs registration
37// Add kernel command line parsing for io and irq 37// Add kernel command line parsing for io and irq
38// Compile defaults for io and irq are now set in ip2.c not ip2/ip2.h! 38// Compile defaults for io and irq are now set in ip2.c not ip2.h!
39// Reworked poll_only hack for explicit parameter setting 39// Reworked poll_only hack for explicit parameter setting
40// You must now EXPLICITLY set poll_only = 1 or set all irqs to 0 40// You must now EXPLICITLY set poll_only = 1 or set all irqs to 0
41// Merged ip2_loadmain and old_ip2_init 41// Merged ip2_loadmain and old_ip2_init
@@ -123,12 +123,12 @@
123 123
124#include <asm/uaccess.h> 124#include <asm/uaccess.h>
125 125
126#include "./ip2/ip2types.h" 126#include "ip2types.h"
127#include "./ip2/ip2trace.h" 127#include "ip2trace.h"
128#include "./ip2/ip2ioctl.h" 128#include "ip2ioctl.h"
129#include "./ip2/ip2.h" 129#include "ip2.h"
130#include "./ip2/i2ellis.h" 130#include "i2ellis.h"
131#include "./ip2/i2lib.h" 131#include "i2lib.h"
132 132
133/***************** 133/*****************
134 * /proc/ip2mem * 134 * /proc/ip2mem *
@@ -282,9 +282,9 @@ static int tracewrap;
282/* Code */ 282/* Code */
283/********/ 283/********/
284 284
285#include "./ip2/i2ellis.c" /* Extremely low-level interface services */ 285#include "i2ellis.c" /* Extremely low-level interface services */
286#include "./ip2/i2cmd.c" /* Standard loadware command definitions */ 286#include "i2cmd.c" /* Standard loadware command definitions */
287#include "./ip2/i2lib.c" /* High level interface services */ 287#include "i2lib.c" /* High level interface services */
288 288
289/* Configuration area for modprobe */ 289/* Configuration area for modprobe */
290 290
diff --git a/drivers/char/s3c2410-rtc.c b/drivers/char/s3c2410-rtc.c
index 2e308657f6f6..b0038b19b505 100644
--- a/drivers/char/s3c2410-rtc.c
+++ b/drivers/char/s3c2410-rtc.c
@@ -448,13 +448,13 @@ static int s3c2410_rtc_probe(struct platform_device *pdev)
448 /* find the IRQs */ 448 /* find the IRQs */
449 449
450 s3c2410_rtc_tickno = platform_get_irq(pdev, 1); 450 s3c2410_rtc_tickno = platform_get_irq(pdev, 1);
451 if (s3c2410_rtc_tickno <= 0) { 451 if (s3c2410_rtc_tickno < 0) {
452 dev_err(&pdev->dev, "no irq for rtc tick\n"); 452 dev_err(&pdev->dev, "no irq for rtc tick\n");
453 return -ENOENT; 453 return -ENOENT;
454 } 454 }
455 455
456 s3c2410_rtc_alarmno = platform_get_irq(pdev, 0); 456 s3c2410_rtc_alarmno = platform_get_irq(pdev, 0);
457 if (s3c2410_rtc_alarmno <= 0) { 457 if (s3c2410_rtc_alarmno < 0) {
458 dev_err(&pdev->dev, "no irq for alarm\n"); 458 dev_err(&pdev->dev, "no irq for alarm\n");
459 return -ENOENT; 459 return -ENOENT;
460 } 460 }
diff --git a/drivers/char/snsc.h b/drivers/char/snsc.h
index a9efc13cc858..8a98169b60c1 100644
--- a/drivers/char/snsc.h
+++ b/drivers/char/snsc.h
@@ -5,7 +5,7 @@
5 * License. See the file "COPYING" in the main directory of this archive 5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details. 6 * for more details.
7 * 7 *
8 * Copyright (C) 2004 Silicon Graphics, Inc. All rights reserved. 8 * Copyright (C) 2004-2006 Silicon Graphics, Inc. All rights reserved.
9 */ 9 */
10 10
11/* 11/*
@@ -70,6 +70,9 @@ struct sysctl_data_s {
70#define EV_CLASS_TEST_WARNING 0x6000ul 70#define EV_CLASS_TEST_WARNING 0x6000ul
71#define EV_CLASS_PWRD_NOTIFY 0x8000ul 71#define EV_CLASS_PWRD_NOTIFY 0x8000ul
72 72
73/* ENV class codes */
74#define ENV_PWRDN_PEND 0x4101ul
75
73#define EV_SEVERITY_POWER_STABLE 0x0000ul 76#define EV_SEVERITY_POWER_STABLE 0x0000ul
74#define EV_SEVERITY_POWER_LOW_WARNING 0x0100ul 77#define EV_SEVERITY_POWER_LOW_WARNING 0x0100ul
75#define EV_SEVERITY_POWER_HIGH_WARNING 0x0200ul 78#define EV_SEVERITY_POWER_HIGH_WARNING 0x0200ul
diff --git a/drivers/char/snsc_event.c b/drivers/char/snsc_event.c
index baaa365285fa..a4fa507eed9e 100644
--- a/drivers/char/snsc_event.c
+++ b/drivers/char/snsc_event.c
@@ -5,7 +5,7 @@
5 * License. See the file "COPYING" in the main directory of this archive 5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details. 6 * for more details.
7 * 7 *
8 * Copyright (C) 2004 Silicon Graphics, Inc. All rights reserved. 8 * Copyright (C) 2004-2006 Silicon Graphics, Inc. All rights reserved.
9 */ 9 */
10 10
11/* 11/*
@@ -187,7 +187,8 @@ scdrv_event_severity(int code)
187static void 187static void
188scdrv_dispatch_event(char *event, int len) 188scdrv_dispatch_event(char *event, int len)
189{ 189{
190 int code, esp_code, src; 190 static int snsc_shutting_down = 0;
191 int code, esp_code, src, class;
191 char desc[CHUNKSIZE]; 192 char desc[CHUNKSIZE];
192 char *severity; 193 char *severity;
193 194
@@ -199,9 +200,25 @@ scdrv_dispatch_event(char *event, int len)
199 /* how urgent is the message? */ 200 /* how urgent is the message? */
200 severity = scdrv_event_severity(code); 201 severity = scdrv_event_severity(code);
201 202
202 if ((code & EV_CLASS_MASK) == EV_CLASS_PWRD_NOTIFY) { 203 class = (code & EV_CLASS_MASK);
204
205 if (class == EV_CLASS_PWRD_NOTIFY || code == ENV_PWRDN_PEND) {
203 struct task_struct *p; 206 struct task_struct *p;
204 207
208 if (snsc_shutting_down)
209 return;
210
211 snsc_shutting_down = 1;
212
213 /* give a message for each type of event */
214 if (class == EV_CLASS_PWRD_NOTIFY)
215 printk(KERN_NOTICE "Power off indication received."
216 " Sending SIGPWR to init...\n");
217 else if (code == ENV_PWRDN_PEND)
218 printk(KERN_CRIT "WARNING: Shutting down the system"
219 " due to a critical environmental condition."
220 " Sending SIGPWR to init...\n");
221
205 /* give a SIGPWR signal to init proc */ 222 /* give a SIGPWR signal to init proc */
206 223
207 /* first find init's task */ 224 /* first find init's task */
@@ -210,12 +227,11 @@ scdrv_dispatch_event(char *event, int len)
210 if (p->pid == 1) 227 if (p->pid == 1)
211 break; 228 break;
212 } 229 }
213 if (p) { /* we found init's task */ 230 if (p) {
214 printk(KERN_EMERG "Power off indication received. Initiating power fail sequence...\n");
215 force_sig(SIGPWR, p); 231 force_sig(SIGPWR, p);
216 } else { /* failed to find init's task - just give message(s) */ 232 } else {
217 printk(KERN_WARNING "Failed to find init proc to handle power off!\n"); 233 printk(KERN_ERR "Failed to signal init!\n");
218 printk("%s|$(0x%x)%s\n", severity, esp_code, desc); 234 snsc_shutting_down = 0; /* so can try again (?) */
219 } 235 }
220 read_unlock(&tasklist_lock); 236 read_unlock(&tasklist_lock);
221 } else { 237 } else {
diff --git a/drivers/char/watchdog/mpcore_wdt.c b/drivers/char/watchdog/mpcore_wdt.c
index b4d843489881..2c2c51773200 100644
--- a/drivers/char/watchdog/mpcore_wdt.c
+++ b/drivers/char/watchdog/mpcore_wdt.c
@@ -338,6 +338,10 @@ static int __devinit mpcore_wdt_probe(struct platform_device *dev)
338 338
339 wdt->dev = &dev->dev; 339 wdt->dev = &dev->dev;
340 wdt->irq = platform_get_irq(dev, 0); 340 wdt->irq = platform_get_irq(dev, 0);
341 if (wdt->irq < 0) {
342 ret = -ENXIO;
343 goto err_free;
344 }
341 wdt->base = ioremap(res->start, res->end - res->start + 1); 345 wdt->base = ioremap(res->start, res->end - res->start + 1);
342 if (!wdt->base) { 346 if (!wdt->base) {
343 ret = -ENOMEM; 347 ret = -ENOMEM;
diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index 505677fb3157..d7125f4d9113 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -97,6 +97,9 @@ int cn_netlink_send(struct cn_msg *msg, u32 __group, gfp_t gfp_mask)
97 group = __group; 97 group = __group;
98 } 98 }
99 99
100 if (!netlink_has_listeners(dev->nls, group))
101 return -ESRCH;
102
100 size = NLMSG_SPACE(sizeof(*msg) + msg->len); 103 size = NLMSG_SPACE(sizeof(*msg) + msg->len);
101 104
102 skb = alloc_skb(size, gfp_mask); 105 skb = alloc_skb(size, gfp_mask);
@@ -111,9 +114,7 @@ int cn_netlink_send(struct cn_msg *msg, u32 __group, gfp_t gfp_mask)
111 114
112 NETLINK_CB(skb).dst_group = group; 115 NETLINK_CB(skb).dst_group = group;
113 116
114 netlink_broadcast(dev->nls, skb, 0, group, gfp_mask); 117 return netlink_broadcast(dev->nls, skb, 0, group, gfp_mask);
115
116 return 0;
117 118
118nlmsg_failure: 119nlmsg_failure:
119 kfree_skb(skb); 120 kfree_skb(skb);
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 0c08c58252be..5158a9db4bc5 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -284,7 +284,11 @@ aes_hw_extkey_available(uint8_t key_len)
284 284
285static inline struct aes_ctx *aes_ctx(void *ctx) 285static inline struct aes_ctx *aes_ctx(void *ctx)
286{ 286{
287 return (struct aes_ctx *)ALIGN((unsigned long)ctx, PADLOCK_ALIGNMENT); 287 unsigned long align = PADLOCK_ALIGNMENT;
288
289 if (align <= crypto_tfm_ctx_alignment())
290 align = 1;
291 return (struct aes_ctx *)ALIGN((unsigned long)ctx, align);
288} 292}
289 293
290static int 294static int
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 1414851a17b8..d00a02fc23e4 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -434,7 +434,7 @@ static int
434iop3xx_i2c_probe(struct platform_device *pdev) 434iop3xx_i2c_probe(struct platform_device *pdev)
435{ 435{
436 struct resource *res; 436 struct resource *res;
437 int ret; 437 int ret, irq;
438 struct i2c_adapter *new_adapter; 438 struct i2c_adapter *new_adapter;
439 struct i2c_algo_iop3xx_data *adapter_data; 439 struct i2c_algo_iop3xx_data *adapter_data;
440 440
@@ -470,7 +470,12 @@ iop3xx_i2c_probe(struct platform_device *pdev)
470 goto release_region; 470 goto release_region;
471 } 471 }
472 472
473 ret = request_irq(platform_get_irq(pdev, 0), iop3xx_i2c_irq_handler, 0, 473 irq = platform_get_irq(pdev, 0);
474 if (irq < 0) {
475 ret = -ENXIO;
476 goto unmap;
477 }
478 ret = request_irq(irq, iop3xx_i2c_irq_handler, 0,
474 pdev->name, adapter_data); 479 pdev->name, adapter_data);
475 480
476 if (ret) { 481 if (ret) {
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 5ccd338a9dc9..2721e4c8184a 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -302,6 +302,10 @@ static int fsl_i2c_probe(struct platform_device *pdev)
302 } 302 }
303 303
304 i2c->irq = platform_get_irq(pdev, 0); 304 i2c->irq = platform_get_irq(pdev, 0);
305 if (i2c->irq < 0) {
306 result = -ENXIO;
307 goto fail_get_irq;
308 }
305 i2c->flags = pdata->device_flags; 309 i2c->flags = pdata->device_flags;
306 init_waitqueue_head(&i2c->queue); 310 init_waitqueue_head(&i2c->queue);
307 311
@@ -340,6 +344,7 @@ static int fsl_i2c_probe(struct platform_device *pdev)
340 fail_irq: 344 fail_irq:
341 iounmap(i2c->base); 345 iounmap(i2c->base);
342 fail_map: 346 fail_map:
347 fail_get_irq:
343 kfree(i2c); 348 kfree(i2c);
344 return result; 349 return result;
345}; 350};
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 22781d84f79f..ac5cde1bbd2b 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -516,6 +516,10 @@ mv64xxx_i2c_probe(struct platform_device *pd)
516 drv_data->freq_m = pdata->freq_m; 516 drv_data->freq_m = pdata->freq_m;
517 drv_data->freq_n = pdata->freq_n; 517 drv_data->freq_n = pdata->freq_n;
518 drv_data->irq = platform_get_irq(pd, 0); 518 drv_data->irq = platform_get_irq(pd, 0);
519 if (drv_data->irq < 0) {
520 rc = -ENXIO;
521 goto exit_unmap_regs;
522 }
519 drv_data->adapter.id = I2C_HW_MV64XXX; 523 drv_data->adapter.id = I2C_HW_MV64XXX;
520 drv_data->adapter.algo = &mv64xxx_i2c_algo; 524 drv_data->adapter.algo = &mv64xxx_i2c_algo;
521 drv_data->adapter.owner = THIS_MODULE; 525 drv_data->adapter.owner = THIS_MODULE;
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
index 32431dcf5d8e..71f27e955d87 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -674,6 +674,11 @@ static int au_ide_probe(struct device *dev)
674 ret = -ENODEV; 674 ret = -ENODEV;
675 goto out; 675 goto out;
676 } 676 }
677 if (ahwif->irq < 0) {
678 pr_debug("%s %d: no IRQ\n", DRV_NAME, pdev->id);
679 ret = -ENODEV;
680 goto out;
681 }
677 682
678 if (!request_mem_region (res->start, res->end-res->start, pdev->name)) { 683 if (!request_mem_region (res->start, res->end-res->start, pdev->name)) {
679 pr_debug("%s: request_mem_region failed\n", DRV_NAME); 684 pr_debug("%s: request_mem_region failed\n", DRV_NAME);
diff --git a/drivers/infiniband/core/agent.c b/drivers/infiniband/core/agent.c
index 34b724afd28d..ecd1a3057c61 100644
--- a/drivers/infiniband/core/agent.c
+++ b/drivers/infiniband/core/agent.c
@@ -78,25 +78,6 @@ ib_get_agent_port(struct ib_device *device, int port_num)
78 return entry; 78 return entry;
79} 79}
80 80
81int smi_check_local_dr_smp(struct ib_smp *smp,
82 struct ib_device *device,
83 int port_num)
84{
85 struct ib_agent_port_private *port_priv;
86
87 if (smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
88 return 1;
89
90 port_priv = ib_get_agent_port(device, port_num);
91 if (!port_priv) {
92 printk(KERN_DEBUG SPFX "smi_check_local_dr_smp %s port %d "
93 "not open\n", device->name, port_num);
94 return 1;
95 }
96
97 return smi_check_local_smp(port_priv->agent[0], smp);
98}
99
100int agent_send_response(struct ib_mad *mad, struct ib_grh *grh, 81int agent_send_response(struct ib_mad *mad, struct ib_grh *grh,
101 struct ib_wc *wc, struct ib_device *device, 82 struct ib_wc *wc, struct ib_device *device,
102 int port_num, int qpn) 83 int port_num, int qpn)
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 2514de3480d8..7cfedb8d9bcd 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -121,7 +121,7 @@ struct cm_id_private {
121 121
122 struct rb_node service_node; 122 struct rb_node service_node;
123 struct rb_node sidr_id_node; 123 struct rb_node sidr_id_node;
124 spinlock_t lock; 124 spinlock_t lock; /* Do not acquire inside cm.lock */
125 wait_queue_head_t wait; 125 wait_queue_head_t wait;
126 atomic_t refcount; 126 atomic_t refcount;
127 127
@@ -1547,40 +1547,46 @@ static int cm_rep_handler(struct cm_work *work)
1547 return -EINVAL; 1547 return -EINVAL;
1548 } 1548 }
1549 1549
1550 cm_format_rep_event(work);
1551
1552 spin_lock_irqsave(&cm_id_priv->lock, flags);
1553 switch (cm_id_priv->id.state) {
1554 case IB_CM_REQ_SENT:
1555 case IB_CM_MRA_REQ_RCVD:
1556 break;
1557 default:
1558 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1559 ret = -EINVAL;
1560 goto error;
1561 }
1562
1550 cm_id_priv->timewait_info->work.remote_id = rep_msg->local_comm_id; 1563 cm_id_priv->timewait_info->work.remote_id = rep_msg->local_comm_id;
1551 cm_id_priv->timewait_info->remote_ca_guid = rep_msg->local_ca_guid; 1564 cm_id_priv->timewait_info->remote_ca_guid = rep_msg->local_ca_guid;
1552 cm_id_priv->timewait_info->remote_qpn = cm_rep_get_local_qpn(rep_msg); 1565 cm_id_priv->timewait_info->remote_qpn = cm_rep_get_local_qpn(rep_msg);
1553 1566
1554 spin_lock_irqsave(&cm.lock, flags); 1567 spin_lock(&cm.lock);
1555 /* Check for duplicate REP. */ 1568 /* Check for duplicate REP. */
1556 if (cm_insert_remote_id(cm_id_priv->timewait_info)) { 1569 if (cm_insert_remote_id(cm_id_priv->timewait_info)) {
1557 spin_unlock_irqrestore(&cm.lock, flags); 1570 spin_unlock(&cm.lock);
1571 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1558 ret = -EINVAL; 1572 ret = -EINVAL;
1559 goto error; 1573 goto error;
1560 } 1574 }
1561 /* Check for a stale connection. */ 1575 /* Check for a stale connection. */
1562 if (cm_insert_remote_qpn(cm_id_priv->timewait_info)) { 1576 if (cm_insert_remote_qpn(cm_id_priv->timewait_info)) {
1563 spin_unlock_irqrestore(&cm.lock, flags); 1577 rb_erase(&cm_id_priv->timewait_info->remote_id_node,
1578 &cm.remote_id_table);
1579 cm_id_priv->timewait_info->inserted_remote_id = 0;
1580 spin_unlock(&cm.lock);
1581 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1564 cm_issue_rej(work->port, work->mad_recv_wc, 1582 cm_issue_rej(work->port, work->mad_recv_wc,
1565 IB_CM_REJ_STALE_CONN, CM_MSG_RESPONSE_REP, 1583 IB_CM_REJ_STALE_CONN, CM_MSG_RESPONSE_REP,
1566 NULL, 0); 1584 NULL, 0);
1567 ret = -EINVAL; 1585 ret = -EINVAL;
1568 goto error; 1586 goto error;
1569 } 1587 }
1570 spin_unlock_irqrestore(&cm.lock, flags); 1588 spin_unlock(&cm.lock);
1571
1572 cm_format_rep_event(work);
1573 1589
1574 spin_lock_irqsave(&cm_id_priv->lock, flags);
1575 switch (cm_id_priv->id.state) {
1576 case IB_CM_REQ_SENT:
1577 case IB_CM_MRA_REQ_RCVD:
1578 break;
1579 default:
1580 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1581 ret = -EINVAL;
1582 goto error;
1583 }
1584 cm_id_priv->id.state = IB_CM_REP_RCVD; 1590 cm_id_priv->id.state = IB_CM_REP_RCVD;
1585 cm_id_priv->id.remote_id = rep_msg->local_comm_id; 1591 cm_id_priv->id.remote_id = rep_msg->local_comm_id;
1586 cm_id_priv->remote_qpn = cm_rep_get_local_qpn(rep_msg); 1592 cm_id_priv->remote_qpn = cm_rep_get_local_qpn(rep_msg);
@@ -1603,7 +1609,7 @@ static int cm_rep_handler(struct cm_work *work)
1603 cm_deref_id(cm_id_priv); 1609 cm_deref_id(cm_id_priv);
1604 return 0; 1610 return 0;
1605 1611
1606error: cm_cleanup_timewait(cm_id_priv->timewait_info); 1612error:
1607 cm_deref_id(cm_id_priv); 1613 cm_deref_id(cm_id_priv);
1608 return ret; 1614 return ret;
1609} 1615}
diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
index d34a6f1c4f4c..838bf54458d2 100644
--- a/drivers/infiniband/core/fmr_pool.c
+++ b/drivers/infiniband/core/fmr_pool.c
@@ -278,9 +278,9 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
278 { 278 {
279 struct ib_pool_fmr *fmr; 279 struct ib_pool_fmr *fmr;
280 struct ib_fmr_attr attr = { 280 struct ib_fmr_attr attr = {
281 .max_pages = params->max_pages_per_fmr, 281 .max_pages = params->max_pages_per_fmr,
282 .max_maps = IB_FMR_MAX_REMAPS, 282 .max_maps = IB_FMR_MAX_REMAPS,
283 .page_size = PAGE_SHIFT 283 .page_shift = params->page_shift
284 }; 284 };
285 285
286 for (i = 0; i < params->pool_size; ++i) { 286 for (i = 0; i < params->pool_size; ++i) {
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index c82f47a66e48..f7854b65fd55 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -31,7 +31,7 @@
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE. 32 * SOFTWARE.
33 * 33 *
34 * $Id: mad.c 2817 2005-07-07 11:29:26Z halr $ 34 * $Id: mad.c 5596 2006-03-03 01:00:07Z sean.hefty $
35 */ 35 */
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37 37
@@ -679,8 +679,8 @@ static int handle_outgoing_dr_smp(struct ib_mad_agent_private *mad_agent_priv,
679 goto out; 679 goto out;
680 } 680 }
681 /* Check to post send on QP or process locally */ 681 /* Check to post send on QP or process locally */
682 ret = smi_check_local_dr_smp(smp, device, port_num); 682 ret = smi_check_local_smp(smp, device);
683 if (!ret || !device->process_mad) 683 if (!ret)
684 goto out; 684 goto out;
685 685
686 local = kmalloc(sizeof *local, GFP_ATOMIC); 686 local = kmalloc(sizeof *local, GFP_ATOMIC);
@@ -765,18 +765,67 @@ out:
765 return ret; 765 return ret;
766} 766}
767 767
768static int get_buf_length(int hdr_len, int data_len) 768static int get_pad_size(int hdr_len, int data_len)
769{ 769{
770 int seg_size, pad; 770 int seg_size, pad;
771 771
772 seg_size = sizeof(struct ib_mad) - hdr_len; 772 seg_size = sizeof(struct ib_mad) - hdr_len;
773 if (data_len && seg_size) { 773 if (data_len && seg_size) {
774 pad = seg_size - data_len % seg_size; 774 pad = seg_size - data_len % seg_size;
775 if (pad == seg_size) 775 return pad == seg_size ? 0 : pad;
776 pad = 0;
777 } else 776 } else
778 pad = seg_size; 777 return seg_size;
779 return hdr_len + data_len + pad; 778}
779
780static void free_send_rmpp_list(struct ib_mad_send_wr_private *mad_send_wr)
781{
782 struct ib_rmpp_segment *s, *t;
783
784 list_for_each_entry_safe(s, t, &mad_send_wr->rmpp_list, list) {
785 list_del(&s->list);
786 kfree(s);
787 }
788}
789
790static int alloc_send_rmpp_list(struct ib_mad_send_wr_private *send_wr,
791 gfp_t gfp_mask)
792{
793 struct ib_mad_send_buf *send_buf = &send_wr->send_buf;
794 struct ib_rmpp_mad *rmpp_mad = send_buf->mad;
795 struct ib_rmpp_segment *seg = NULL;
796 int left, seg_size, pad;
797
798 send_buf->seg_size = sizeof (struct ib_mad) - send_buf->hdr_len;
799 seg_size = send_buf->seg_size;
800 pad = send_wr->pad;
801
802 /* Allocate data segments. */
803 for (left = send_buf->data_len + pad; left > 0; left -= seg_size) {
804 seg = kmalloc(sizeof (*seg) + seg_size, gfp_mask);
805 if (!seg) {
806 printk(KERN_ERR "alloc_send_rmpp_segs: RMPP mem "
807 "alloc failed for len %zd, gfp %#x\n",
808 sizeof (*seg) + seg_size, gfp_mask);
809 free_send_rmpp_list(send_wr);
810 return -ENOMEM;
811 }
812 seg->num = ++send_buf->seg_count;
813 list_add_tail(&seg->list, &send_wr->rmpp_list);
814 }
815
816 /* Zero any padding */
817 if (pad)
818 memset(seg->data + seg_size - pad, 0, pad);
819
820 rmpp_mad->rmpp_hdr.rmpp_version = send_wr->mad_agent_priv->
821 agent.rmpp_version;
822 rmpp_mad->rmpp_hdr.rmpp_type = IB_MGMT_RMPP_TYPE_DATA;
823 ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr, IB_MGMT_RMPP_FLAG_ACTIVE);
824
825 send_wr->cur_seg = container_of(send_wr->rmpp_list.next,
826 struct ib_rmpp_segment, list);
827 send_wr->last_ack_seg = send_wr->cur_seg;
828 return 0;
780} 829}
781 830
782struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent, 831struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
@@ -787,32 +836,40 @@ struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
787{ 836{
788 struct ib_mad_agent_private *mad_agent_priv; 837 struct ib_mad_agent_private *mad_agent_priv;
789 struct ib_mad_send_wr_private *mad_send_wr; 838 struct ib_mad_send_wr_private *mad_send_wr;
790 int buf_size; 839 int pad, message_size, ret, size;
791 void *buf; 840 void *buf;
792 841
793 mad_agent_priv = container_of(mad_agent, struct ib_mad_agent_private, 842 mad_agent_priv = container_of(mad_agent, struct ib_mad_agent_private,
794 agent); 843 agent);
795 buf_size = get_buf_length(hdr_len, data_len); 844 pad = get_pad_size(hdr_len, data_len);
845 message_size = hdr_len + data_len + pad;
796 846
797 if ((!mad_agent->rmpp_version && 847 if ((!mad_agent->rmpp_version &&
798 (rmpp_active || buf_size > sizeof(struct ib_mad))) || 848 (rmpp_active || message_size > sizeof(struct ib_mad))) ||
799 (!rmpp_active && buf_size > sizeof(struct ib_mad))) 849 (!rmpp_active && message_size > sizeof(struct ib_mad)))
800 return ERR_PTR(-EINVAL); 850 return ERR_PTR(-EINVAL);
801 851
802 buf = kzalloc(sizeof *mad_send_wr + buf_size, gfp_mask); 852 size = rmpp_active ? hdr_len : sizeof(struct ib_mad);
853 buf = kzalloc(sizeof *mad_send_wr + size, gfp_mask);
803 if (!buf) 854 if (!buf)
804 return ERR_PTR(-ENOMEM); 855 return ERR_PTR(-ENOMEM);
805 856
806 mad_send_wr = buf + buf_size; 857 mad_send_wr = buf + size;
858 INIT_LIST_HEAD(&mad_send_wr->rmpp_list);
807 mad_send_wr->send_buf.mad = buf; 859 mad_send_wr->send_buf.mad = buf;
860 mad_send_wr->send_buf.hdr_len = hdr_len;
861 mad_send_wr->send_buf.data_len = data_len;
862 mad_send_wr->pad = pad;
808 863
809 mad_send_wr->mad_agent_priv = mad_agent_priv; 864 mad_send_wr->mad_agent_priv = mad_agent_priv;
810 mad_send_wr->sg_list[0].length = buf_size; 865 mad_send_wr->sg_list[0].length = hdr_len;
811 mad_send_wr->sg_list[0].lkey = mad_agent->mr->lkey; 866 mad_send_wr->sg_list[0].lkey = mad_agent->mr->lkey;
867 mad_send_wr->sg_list[1].length = sizeof(struct ib_mad) - hdr_len;
868 mad_send_wr->sg_list[1].lkey = mad_agent->mr->lkey;
812 869
813 mad_send_wr->send_wr.wr_id = (unsigned long) mad_send_wr; 870 mad_send_wr->send_wr.wr_id = (unsigned long) mad_send_wr;
814 mad_send_wr->send_wr.sg_list = mad_send_wr->sg_list; 871 mad_send_wr->send_wr.sg_list = mad_send_wr->sg_list;
815 mad_send_wr->send_wr.num_sge = 1; 872 mad_send_wr->send_wr.num_sge = 2;
816 mad_send_wr->send_wr.opcode = IB_WR_SEND; 873 mad_send_wr->send_wr.opcode = IB_WR_SEND;
817 mad_send_wr->send_wr.send_flags = IB_SEND_SIGNALED; 874 mad_send_wr->send_wr.send_flags = IB_SEND_SIGNALED;
818 mad_send_wr->send_wr.wr.ud.remote_qpn = remote_qpn; 875 mad_send_wr->send_wr.wr.ud.remote_qpn = remote_qpn;
@@ -820,13 +877,11 @@ struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
820 mad_send_wr->send_wr.wr.ud.pkey_index = pkey_index; 877 mad_send_wr->send_wr.wr.ud.pkey_index = pkey_index;
821 878
822 if (rmpp_active) { 879 if (rmpp_active) {
823 struct ib_rmpp_mad *rmpp_mad = mad_send_wr->send_buf.mad; 880 ret = alloc_send_rmpp_list(mad_send_wr, gfp_mask);
824 rmpp_mad->rmpp_hdr.paylen_newwin = cpu_to_be32(hdr_len - 881 if (ret) {
825 IB_MGMT_RMPP_HDR + data_len); 882 kfree(buf);
826 rmpp_mad->rmpp_hdr.rmpp_version = mad_agent->rmpp_version; 883 return ERR_PTR(ret);
827 rmpp_mad->rmpp_hdr.rmpp_type = IB_MGMT_RMPP_TYPE_DATA; 884 }
828 ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr,
829 IB_MGMT_RMPP_FLAG_ACTIVE);
830 } 885 }
831 886
832 mad_send_wr->send_buf.mad_agent = mad_agent; 887 mad_send_wr->send_buf.mad_agent = mad_agent;
@@ -835,14 +890,50 @@ struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
835} 890}
836EXPORT_SYMBOL(ib_create_send_mad); 891EXPORT_SYMBOL(ib_create_send_mad);
837 892
893void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num)
894{
895 struct ib_mad_send_wr_private *mad_send_wr;
896 struct list_head *list;
897
898 mad_send_wr = container_of(send_buf, struct ib_mad_send_wr_private,
899 send_buf);
900 list = &mad_send_wr->cur_seg->list;
901
902 if (mad_send_wr->cur_seg->num < seg_num) {
903 list_for_each_entry(mad_send_wr->cur_seg, list, list)
904 if (mad_send_wr->cur_seg->num == seg_num)
905 break;
906 } else if (mad_send_wr->cur_seg->num > seg_num) {
907 list_for_each_entry_reverse(mad_send_wr->cur_seg, list, list)
908 if (mad_send_wr->cur_seg->num == seg_num)
909 break;
910 }
911 return mad_send_wr->cur_seg->data;
912}
913EXPORT_SYMBOL(ib_get_rmpp_segment);
914
915static inline void *ib_get_payload(struct ib_mad_send_wr_private *mad_send_wr)
916{
917 if (mad_send_wr->send_buf.seg_count)
918 return ib_get_rmpp_segment(&mad_send_wr->send_buf,
919 mad_send_wr->seg_num);
920 else
921 return mad_send_wr->send_buf.mad +
922 mad_send_wr->send_buf.hdr_len;
923}
924
838void ib_free_send_mad(struct ib_mad_send_buf *send_buf) 925void ib_free_send_mad(struct ib_mad_send_buf *send_buf)
839{ 926{
840 struct ib_mad_agent_private *mad_agent_priv; 927 struct ib_mad_agent_private *mad_agent_priv;
928 struct ib_mad_send_wr_private *mad_send_wr;
841 929
842 mad_agent_priv = container_of(send_buf->mad_agent, 930 mad_agent_priv = container_of(send_buf->mad_agent,
843 struct ib_mad_agent_private, agent); 931 struct ib_mad_agent_private, agent);
844 kfree(send_buf->mad); 932 mad_send_wr = container_of(send_buf, struct ib_mad_send_wr_private,
933 send_buf);
845 934
935 free_send_rmpp_list(mad_send_wr);
936 kfree(send_buf->mad);
846 if (atomic_dec_and_test(&mad_agent_priv->refcount)) 937 if (atomic_dec_and_test(&mad_agent_priv->refcount))
847 wake_up(&mad_agent_priv->wait); 938 wake_up(&mad_agent_priv->wait);
848} 939}
@@ -865,10 +956,17 @@ int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr)
865 956
866 mad_agent = mad_send_wr->send_buf.mad_agent; 957 mad_agent = mad_send_wr->send_buf.mad_agent;
867 sge = mad_send_wr->sg_list; 958 sge = mad_send_wr->sg_list;
868 sge->addr = dma_map_single(mad_agent->device->dma_device, 959 sge[0].addr = dma_map_single(mad_agent->device->dma_device,
869 mad_send_wr->send_buf.mad, sge->length, 960 mad_send_wr->send_buf.mad,
870 DMA_TO_DEVICE); 961 sge[0].length,
871 pci_unmap_addr_set(mad_send_wr, mapping, sge->addr); 962 DMA_TO_DEVICE);
963 pci_unmap_addr_set(mad_send_wr, header_mapping, sge[0].addr);
964
965 sge[1].addr = dma_map_single(mad_agent->device->dma_device,
966 ib_get_payload(mad_send_wr),
967 sge[1].length,
968 DMA_TO_DEVICE);
969 pci_unmap_addr_set(mad_send_wr, payload_mapping, sge[1].addr);
872 970
873 spin_lock_irqsave(&qp_info->send_queue.lock, flags); 971 spin_lock_irqsave(&qp_info->send_queue.lock, flags);
874 if (qp_info->send_queue.count < qp_info->send_queue.max_active) { 972 if (qp_info->send_queue.count < qp_info->send_queue.max_active) {
@@ -885,11 +983,14 @@ int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr)
885 list_add_tail(&mad_send_wr->mad_list.list, list); 983 list_add_tail(&mad_send_wr->mad_list.list, list);
886 } 984 }
887 spin_unlock_irqrestore(&qp_info->send_queue.lock, flags); 985 spin_unlock_irqrestore(&qp_info->send_queue.lock, flags);
888 if (ret) 986 if (ret) {
889 dma_unmap_single(mad_agent->device->dma_device, 987 dma_unmap_single(mad_agent->device->dma_device,
890 pci_unmap_addr(mad_send_wr, mapping), 988 pci_unmap_addr(mad_send_wr, header_mapping),
891 sge->length, DMA_TO_DEVICE); 989 sge[0].length, DMA_TO_DEVICE);
892 990 dma_unmap_single(mad_agent->device->dma_device,
991 pci_unmap_addr(mad_send_wr, payload_mapping),
992 sge[1].length, DMA_TO_DEVICE);
993 }
893 return ret; 994 return ret;
894} 995}
895 996
@@ -1661,9 +1762,7 @@ static void ib_mad_recv_done_handler(struct ib_mad_port_private *port_priv,
1661 port_priv->device->node_type, 1762 port_priv->device->node_type,
1662 port_priv->port_num)) 1763 port_priv->port_num))
1663 goto out; 1764 goto out;
1664 if (!smi_check_local_dr_smp(&recv->mad.smp, 1765 if (!smi_check_local_smp(&recv->mad.smp, port_priv->device))
1665 port_priv->device,
1666 port_priv->port_num))
1667 goto out; 1766 goto out;
1668 } 1767 }
1669 1768
@@ -1862,8 +1961,11 @@ static void ib_mad_send_done_handler(struct ib_mad_port_private *port_priv,
1862 1961
1863retry: 1962retry:
1864 dma_unmap_single(mad_send_wr->send_buf.mad_agent->device->dma_device, 1963 dma_unmap_single(mad_send_wr->send_buf.mad_agent->device->dma_device,
1865 pci_unmap_addr(mad_send_wr, mapping), 1964 pci_unmap_addr(mad_send_wr, header_mapping),
1866 mad_send_wr->sg_list[0].length, DMA_TO_DEVICE); 1965 mad_send_wr->sg_list[0].length, DMA_TO_DEVICE);
1966 dma_unmap_single(mad_send_wr->send_buf.mad_agent->device->dma_device,
1967 pci_unmap_addr(mad_send_wr, payload_mapping),
1968 mad_send_wr->sg_list[1].length, DMA_TO_DEVICE);
1867 queued_send_wr = NULL; 1969 queued_send_wr = NULL;
1868 spin_lock_irqsave(&send_queue->lock, flags); 1970 spin_lock_irqsave(&send_queue->lock, flags);
1869 list_del(&mad_list->list); 1971 list_del(&mad_list->list);
@@ -2262,8 +2364,12 @@ static void timeout_sends(void *data)
2262static void ib_mad_thread_completion_handler(struct ib_cq *cq, void *arg) 2364static void ib_mad_thread_completion_handler(struct ib_cq *cq, void *arg)
2263{ 2365{
2264 struct ib_mad_port_private *port_priv = cq->cq_context; 2366 struct ib_mad_port_private *port_priv = cq->cq_context;
2367 unsigned long flags;
2265 2368
2266 queue_work(port_priv->wq, &port_priv->work); 2369 spin_lock_irqsave(&ib_mad_port_list_lock, flags);
2370 if (!list_empty(&port_priv->port_list))
2371 queue_work(port_priv->wq, &port_priv->work);
2372 spin_unlock_irqrestore(&ib_mad_port_list_lock, flags);
2267} 2373}
2268 2374
2269/* 2375/*
@@ -2575,18 +2681,23 @@ static int ib_mad_port_open(struct ib_device *device,
2575 } 2681 }
2576 INIT_WORK(&port_priv->work, ib_mad_completion_handler, port_priv); 2682 INIT_WORK(&port_priv->work, ib_mad_completion_handler, port_priv);
2577 2683
2684 spin_lock_irqsave(&ib_mad_port_list_lock, flags);
2685 list_add_tail(&port_priv->port_list, &ib_mad_port_list);
2686 spin_unlock_irqrestore(&ib_mad_port_list_lock, flags);
2687
2578 ret = ib_mad_port_start(port_priv); 2688 ret = ib_mad_port_start(port_priv);
2579 if (ret) { 2689 if (ret) {
2580 printk(KERN_ERR PFX "Couldn't start port\n"); 2690 printk(KERN_ERR PFX "Couldn't start port\n");
2581 goto error9; 2691 goto error9;
2582 } 2692 }
2583 2693
2584 spin_lock_irqsave(&ib_mad_port_list_lock, flags);
2585 list_add_tail(&port_priv->port_list, &ib_mad_port_list);
2586 spin_unlock_irqrestore(&ib_mad_port_list_lock, flags);
2587 return 0; 2694 return 0;
2588 2695
2589error9: 2696error9:
2697 spin_lock_irqsave(&ib_mad_port_list_lock, flags);
2698 list_del_init(&port_priv->port_list);
2699 spin_unlock_irqrestore(&ib_mad_port_list_lock, flags);
2700
2590 destroy_workqueue(port_priv->wq); 2701 destroy_workqueue(port_priv->wq);
2591error8: 2702error8:
2592 destroy_mad_qp(&port_priv->qp_info[1]); 2703 destroy_mad_qp(&port_priv->qp_info[1]);
@@ -2623,11 +2734,9 @@ static int ib_mad_port_close(struct ib_device *device, int port_num)
2623 printk(KERN_ERR PFX "Port %d not found\n", port_num); 2734 printk(KERN_ERR PFX "Port %d not found\n", port_num);
2624 return -ENODEV; 2735 return -ENODEV;
2625 } 2736 }
2626 list_del(&port_priv->port_list); 2737 list_del_init(&port_priv->port_list);
2627 spin_unlock_irqrestore(&ib_mad_port_list_lock, flags); 2738 spin_unlock_irqrestore(&ib_mad_port_list_lock, flags);
2628 2739
2629 /* Stop processing completions. */
2630 flush_workqueue(port_priv->wq);
2631 destroy_workqueue(port_priv->wq); 2740 destroy_workqueue(port_priv->wq);
2632 destroy_mad_qp(&port_priv->qp_info[1]); 2741 destroy_mad_qp(&port_priv->qp_info[1]);
2633 destroy_mad_qp(&port_priv->qp_info[0]); 2742 destroy_mad_qp(&port_priv->qp_info[0]);
diff --git a/drivers/infiniband/core/mad_priv.h b/drivers/infiniband/core/mad_priv.h
index 570f78682af3..a7125d4b5ccf 100644
--- a/drivers/infiniband/core/mad_priv.h
+++ b/drivers/infiniband/core/mad_priv.h
@@ -31,7 +31,7 @@
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE. 32 * SOFTWARE.
33 * 33 *
34 * $Id: mad_priv.h 2730 2005-06-28 16:43:03Z sean.hefty $ 34 * $Id: mad_priv.h 5596 2006-03-03 01:00:07Z sean.hefty $
35 */ 35 */
36 36
37#ifndef __IB_MAD_PRIV_H__ 37#ifndef __IB_MAD_PRIV_H__
@@ -85,6 +85,12 @@ struct ib_mad_private {
85 } mad; 85 } mad;
86} __attribute__ ((packed)); 86} __attribute__ ((packed));
87 87
88struct ib_rmpp_segment {
89 struct list_head list;
90 u32 num;
91 u8 data[0];
92};
93
88struct ib_mad_agent_private { 94struct ib_mad_agent_private {
89 struct list_head agent_list; 95 struct list_head agent_list;
90 struct ib_mad_agent agent; 96 struct ib_mad_agent agent;
@@ -119,7 +125,8 @@ struct ib_mad_send_wr_private {
119 struct list_head agent_list; 125 struct list_head agent_list;
120 struct ib_mad_agent_private *mad_agent_priv; 126 struct ib_mad_agent_private *mad_agent_priv;
121 struct ib_mad_send_buf send_buf; 127 struct ib_mad_send_buf send_buf;
122 DECLARE_PCI_UNMAP_ADDR(mapping) 128 DECLARE_PCI_UNMAP_ADDR(header_mapping)
129 DECLARE_PCI_UNMAP_ADDR(payload_mapping)
123 struct ib_send_wr send_wr; 130 struct ib_send_wr send_wr;
124 struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG]; 131 struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG];
125 __be64 tid; 132 __be64 tid;
@@ -130,11 +137,12 @@ struct ib_mad_send_wr_private {
130 enum ib_wc_status status; 137 enum ib_wc_status status;
131 138
132 /* RMPP control */ 139 /* RMPP control */
140 struct list_head rmpp_list;
141 struct ib_rmpp_segment *last_ack_seg;
142 struct ib_rmpp_segment *cur_seg;
133 int last_ack; 143 int last_ack;
134 int seg_num; 144 int seg_num;
135 int newwin; 145 int newwin;
136 int total_seg;
137 int data_offset;
138 int pad; 146 int pad;
139}; 147};
140 148
diff --git a/drivers/infiniband/core/mad_rmpp.c b/drivers/infiniband/core/mad_rmpp.c
index 3249e1d8c07b..bacfdd5bddad 100644
--- a/drivers/infiniband/core/mad_rmpp.c
+++ b/drivers/infiniband/core/mad_rmpp.c
@@ -111,14 +111,14 @@ static int data_offset(u8 mgmt_class)
111 return IB_MGMT_RMPP_HDR; 111 return IB_MGMT_RMPP_HDR;
112} 112}
113 113
114static void format_ack(struct ib_rmpp_mad *ack, 114static void format_ack(struct ib_mad_send_buf *msg,
115 struct ib_rmpp_mad *data, 115 struct ib_rmpp_mad *data,
116 struct mad_rmpp_recv *rmpp_recv) 116 struct mad_rmpp_recv *rmpp_recv)
117{ 117{
118 struct ib_rmpp_mad *ack = msg->mad;
118 unsigned long flags; 119 unsigned long flags;
119 120
120 memcpy(&ack->mad_hdr, &data->mad_hdr, 121 memcpy(ack, &data->mad_hdr, msg->hdr_len);
121 data_offset(data->mad_hdr.mgmt_class));
122 122
123 ack->mad_hdr.method ^= IB_MGMT_METHOD_RESP; 123 ack->mad_hdr.method ^= IB_MGMT_METHOD_RESP;
124 ack->rmpp_hdr.rmpp_type = IB_MGMT_RMPP_TYPE_ACK; 124 ack->rmpp_hdr.rmpp_type = IB_MGMT_RMPP_TYPE_ACK;
@@ -135,16 +135,16 @@ static void ack_recv(struct mad_rmpp_recv *rmpp_recv,
135 struct ib_mad_recv_wc *recv_wc) 135 struct ib_mad_recv_wc *recv_wc)
136{ 136{
137 struct ib_mad_send_buf *msg; 137 struct ib_mad_send_buf *msg;
138 int ret; 138 int ret, hdr_len;
139 139
140 hdr_len = data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class);
140 msg = ib_create_send_mad(&rmpp_recv->agent->agent, recv_wc->wc->src_qp, 141 msg = ib_create_send_mad(&rmpp_recv->agent->agent, recv_wc->wc->src_qp,
141 recv_wc->wc->pkey_index, 1, IB_MGMT_RMPP_HDR, 142 recv_wc->wc->pkey_index, 1, hdr_len,
142 IB_MGMT_RMPP_DATA, GFP_KERNEL); 143 0, GFP_KERNEL);
143 if (!msg) 144 if (!msg)
144 return; 145 return;
145 146
146 format_ack(msg->mad, (struct ib_rmpp_mad *) recv_wc->recv_buf.mad, 147 format_ack(msg, (struct ib_rmpp_mad *) recv_wc->recv_buf.mad, rmpp_recv);
147 rmpp_recv);
148 msg->ah = rmpp_recv->ah; 148 msg->ah = rmpp_recv->ah;
149 ret = ib_post_send_mad(msg, NULL); 149 ret = ib_post_send_mad(msg, NULL);
150 if (ret) 150 if (ret)
@@ -156,16 +156,17 @@ static struct ib_mad_send_buf *alloc_response_msg(struct ib_mad_agent *agent,
156{ 156{
157 struct ib_mad_send_buf *msg; 157 struct ib_mad_send_buf *msg;
158 struct ib_ah *ah; 158 struct ib_ah *ah;
159 int hdr_len;
159 160
160 ah = ib_create_ah_from_wc(agent->qp->pd, recv_wc->wc, 161 ah = ib_create_ah_from_wc(agent->qp->pd, recv_wc->wc,
161 recv_wc->recv_buf.grh, agent->port_num); 162 recv_wc->recv_buf.grh, agent->port_num);
162 if (IS_ERR(ah)) 163 if (IS_ERR(ah))
163 return (void *) ah; 164 return (void *) ah;
164 165
166 hdr_len = data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class);
165 msg = ib_create_send_mad(agent, recv_wc->wc->src_qp, 167 msg = ib_create_send_mad(agent, recv_wc->wc->src_qp,
166 recv_wc->wc->pkey_index, 1, 168 recv_wc->wc->pkey_index, 1,
167 IB_MGMT_RMPP_HDR, IB_MGMT_RMPP_DATA, 169 hdr_len, 0, GFP_KERNEL);
168 GFP_KERNEL);
169 if (IS_ERR(msg)) 170 if (IS_ERR(msg))
170 ib_destroy_ah(ah); 171 ib_destroy_ah(ah);
171 else 172 else
@@ -195,8 +196,7 @@ static void nack_recv(struct ib_mad_agent_private *agent,
195 return; 196 return;
196 197
197 rmpp_mad = msg->mad; 198 rmpp_mad = msg->mad;
198 memcpy(rmpp_mad, recv_wc->recv_buf.mad, 199 memcpy(rmpp_mad, recv_wc->recv_buf.mad, msg->hdr_len);
199 data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class));
200 200
201 rmpp_mad->mad_hdr.method ^= IB_MGMT_METHOD_RESP; 201 rmpp_mad->mad_hdr.method ^= IB_MGMT_METHOD_RESP;
202 rmpp_mad->rmpp_hdr.rmpp_version = IB_MGMT_RMPP_VERSION; 202 rmpp_mad->rmpp_hdr.rmpp_version = IB_MGMT_RMPP_VERSION;
@@ -433,44 +433,6 @@ static struct ib_mad_recv_wc * complete_rmpp(struct mad_rmpp_recv *rmpp_recv)
433 return rmpp_wc; 433 return rmpp_wc;
434} 434}
435 435
436void ib_coalesce_recv_mad(struct ib_mad_recv_wc *mad_recv_wc, void *buf)
437{
438 struct ib_mad_recv_buf *seg_buf;
439 struct ib_rmpp_mad *rmpp_mad;
440 void *data;
441 int size, len, offset;
442 u8 flags;
443
444 len = mad_recv_wc->mad_len;
445 if (len <= sizeof(struct ib_mad)) {
446 memcpy(buf, mad_recv_wc->recv_buf.mad, len);
447 return;
448 }
449
450 offset = data_offset(mad_recv_wc->recv_buf.mad->mad_hdr.mgmt_class);
451
452 list_for_each_entry(seg_buf, &mad_recv_wc->rmpp_list, list) {
453 rmpp_mad = (struct ib_rmpp_mad *)seg_buf->mad;
454 flags = ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr);
455
456 if (flags & IB_MGMT_RMPP_FLAG_FIRST) {
457 data = rmpp_mad;
458 size = sizeof(*rmpp_mad);
459 } else {
460 data = (void *) rmpp_mad + offset;
461 if (flags & IB_MGMT_RMPP_FLAG_LAST)
462 size = len;
463 else
464 size = sizeof(*rmpp_mad) - offset;
465 }
466
467 memcpy(buf, data, size);
468 len -= size;
469 buf += size;
470 }
471}
472EXPORT_SYMBOL(ib_coalesce_recv_mad);
473
474static struct ib_mad_recv_wc * 436static struct ib_mad_recv_wc *
475continue_rmpp(struct ib_mad_agent_private *agent, 437continue_rmpp(struct ib_mad_agent_private *agent,
476 struct ib_mad_recv_wc *mad_recv_wc) 438 struct ib_mad_recv_wc *mad_recv_wc)
@@ -570,50 +532,33 @@ start_rmpp(struct ib_mad_agent_private *agent,
570 return mad_recv_wc; 532 return mad_recv_wc;
571} 533}
572 534
573static inline u64 get_seg_addr(struct ib_mad_send_wr_private *mad_send_wr)
574{
575 return mad_send_wr->sg_list[0].addr + mad_send_wr->data_offset +
576 (sizeof(struct ib_rmpp_mad) - mad_send_wr->data_offset) *
577 (mad_send_wr->seg_num - 1);
578}
579
580static int send_next_seg(struct ib_mad_send_wr_private *mad_send_wr) 535static int send_next_seg(struct ib_mad_send_wr_private *mad_send_wr)
581{ 536{
582 struct ib_rmpp_mad *rmpp_mad; 537 struct ib_rmpp_mad *rmpp_mad;
583 int timeout; 538 int timeout;
584 u32 paylen; 539 u32 paylen = 0;
585 540
586 rmpp_mad = mad_send_wr->send_buf.mad; 541 rmpp_mad = mad_send_wr->send_buf.mad;
587 ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr, IB_MGMT_RMPP_FLAG_ACTIVE); 542 ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr, IB_MGMT_RMPP_FLAG_ACTIVE);
588 rmpp_mad->rmpp_hdr.seg_num = cpu_to_be32(mad_send_wr->seg_num); 543 rmpp_mad->rmpp_hdr.seg_num = cpu_to_be32(++mad_send_wr->seg_num);
589 544
590 if (mad_send_wr->seg_num == 1) { 545 if (mad_send_wr->seg_num == 1) {
591 rmpp_mad->rmpp_hdr.rmpp_rtime_flags |= IB_MGMT_RMPP_FLAG_FIRST; 546 rmpp_mad->rmpp_hdr.rmpp_rtime_flags |= IB_MGMT_RMPP_FLAG_FIRST;
592 paylen = mad_send_wr->total_seg * IB_MGMT_RMPP_DATA - 547 paylen = mad_send_wr->send_buf.seg_count * IB_MGMT_RMPP_DATA -
593 mad_send_wr->pad; 548 mad_send_wr->pad;
594 rmpp_mad->rmpp_hdr.paylen_newwin = cpu_to_be32(paylen);
595 mad_send_wr->sg_list[0].length = sizeof(struct ib_rmpp_mad);
596 } else {
597 mad_send_wr->send_wr.num_sge = 2;
598 mad_send_wr->sg_list[0].length = mad_send_wr->data_offset;
599 mad_send_wr->sg_list[1].addr = get_seg_addr(mad_send_wr);
600 mad_send_wr->sg_list[1].length = sizeof(struct ib_rmpp_mad) -
601 mad_send_wr->data_offset;
602 mad_send_wr->sg_list[1].lkey = mad_send_wr->sg_list[0].lkey;
603 rmpp_mad->rmpp_hdr.paylen_newwin = 0;
604 } 549 }
605 550
606 if (mad_send_wr->seg_num == mad_send_wr->total_seg) { 551 if (mad_send_wr->seg_num == mad_send_wr->send_buf.seg_count) {
607 rmpp_mad->rmpp_hdr.rmpp_rtime_flags |= IB_MGMT_RMPP_FLAG_LAST; 552 rmpp_mad->rmpp_hdr.rmpp_rtime_flags |= IB_MGMT_RMPP_FLAG_LAST;
608 paylen = IB_MGMT_RMPP_DATA - mad_send_wr->pad; 553 paylen = IB_MGMT_RMPP_DATA - mad_send_wr->pad;
609 rmpp_mad->rmpp_hdr.paylen_newwin = cpu_to_be32(paylen);
610 } 554 }
555 rmpp_mad->rmpp_hdr.paylen_newwin = cpu_to_be32(paylen);
611 556
612 /* 2 seconds for an ACK until we can find the packet lifetime */ 557 /* 2 seconds for an ACK until we can find the packet lifetime */
613 timeout = mad_send_wr->send_buf.timeout_ms; 558 timeout = mad_send_wr->send_buf.timeout_ms;
614 if (!timeout || timeout > 2000) 559 if (!timeout || timeout > 2000)
615 mad_send_wr->timeout = msecs_to_jiffies(2000); 560 mad_send_wr->timeout = msecs_to_jiffies(2000);
616 mad_send_wr->seg_num++; 561
617 return ib_send_mad(mad_send_wr); 562 return ib_send_mad(mad_send_wr);
618} 563}
619 564
@@ -629,7 +574,7 @@ static void abort_send(struct ib_mad_agent_private *agent, __be64 tid,
629 if (!mad_send_wr) 574 if (!mad_send_wr)
630 goto out; /* Unmatched send */ 575 goto out; /* Unmatched send */
631 576
632 if ((mad_send_wr->last_ack == mad_send_wr->total_seg) || 577 if ((mad_send_wr->last_ack == mad_send_wr->send_buf.seg_count) ||
633 (!mad_send_wr->timeout) || (mad_send_wr->status != IB_WC_SUCCESS)) 578 (!mad_send_wr->timeout) || (mad_send_wr->status != IB_WC_SUCCESS))
634 goto out; /* Send is already done */ 579 goto out; /* Send is already done */
635 580
@@ -645,6 +590,18 @@ out:
645 spin_unlock_irqrestore(&agent->lock, flags); 590 spin_unlock_irqrestore(&agent->lock, flags);
646} 591}
647 592
593static inline void adjust_last_ack(struct ib_mad_send_wr_private *wr,
594 int seg_num)
595{
596 struct list_head *list;
597
598 wr->last_ack = seg_num;
599 list = &wr->last_ack_seg->list;
600 list_for_each_entry(wr->last_ack_seg, list, list)
601 if (wr->last_ack_seg->num == seg_num)
602 break;
603}
604
648static void process_rmpp_ack(struct ib_mad_agent_private *agent, 605static void process_rmpp_ack(struct ib_mad_agent_private *agent,
649 struct ib_mad_recv_wc *mad_recv_wc) 606 struct ib_mad_recv_wc *mad_recv_wc)
650{ 607{
@@ -675,11 +632,12 @@ static void process_rmpp_ack(struct ib_mad_agent_private *agent,
675 if (!mad_send_wr) 632 if (!mad_send_wr)
676 goto out; /* Unmatched ACK */ 633 goto out; /* Unmatched ACK */
677 634
678 if ((mad_send_wr->last_ack == mad_send_wr->total_seg) || 635 if ((mad_send_wr->last_ack == mad_send_wr->send_buf.seg_count) ||
679 (!mad_send_wr->timeout) || (mad_send_wr->status != IB_WC_SUCCESS)) 636 (!mad_send_wr->timeout) || (mad_send_wr->status != IB_WC_SUCCESS))
680 goto out; /* Send is already done */ 637 goto out; /* Send is already done */
681 638
682 if (seg_num > mad_send_wr->total_seg || seg_num > mad_send_wr->newwin) { 639 if (seg_num > mad_send_wr->send_buf.seg_count ||
640 seg_num > mad_send_wr->newwin) {
683 spin_unlock_irqrestore(&agent->lock, flags); 641 spin_unlock_irqrestore(&agent->lock, flags);
684 abort_send(agent, rmpp_mad->mad_hdr.tid, 642 abort_send(agent, rmpp_mad->mad_hdr.tid,
685 IB_MGMT_RMPP_STATUS_S2B); 643 IB_MGMT_RMPP_STATUS_S2B);
@@ -691,11 +649,11 @@ static void process_rmpp_ack(struct ib_mad_agent_private *agent,
691 goto out; /* Old ACK */ 649 goto out; /* Old ACK */
692 650
693 if (seg_num > mad_send_wr->last_ack) { 651 if (seg_num > mad_send_wr->last_ack) {
694 mad_send_wr->last_ack = seg_num; 652 adjust_last_ack(mad_send_wr, seg_num);
695 mad_send_wr->retries = mad_send_wr->send_buf.retries; 653 mad_send_wr->retries = mad_send_wr->send_buf.retries;
696 } 654 }
697 mad_send_wr->newwin = newwin; 655 mad_send_wr->newwin = newwin;
698 if (mad_send_wr->last_ack == mad_send_wr->total_seg) { 656 if (mad_send_wr->last_ack == mad_send_wr->send_buf.seg_count) {
699 /* If no response is expected, the ACK completes the send */ 657 /* If no response is expected, the ACK completes the send */
700 if (!mad_send_wr->send_buf.timeout_ms) { 658 if (!mad_send_wr->send_buf.timeout_ms) {
701 struct ib_mad_send_wc wc; 659 struct ib_mad_send_wc wc;
@@ -714,7 +672,7 @@ static void process_rmpp_ack(struct ib_mad_agent_private *agent,
714 mad_send_wr->send_buf.timeout_ms); 672 mad_send_wr->send_buf.timeout_ms);
715 } else if (mad_send_wr->refcount == 1 && 673 } else if (mad_send_wr->refcount == 1 &&
716 mad_send_wr->seg_num < mad_send_wr->newwin && 674 mad_send_wr->seg_num < mad_send_wr->newwin &&
717 mad_send_wr->seg_num <= mad_send_wr->total_seg) { 675 mad_send_wr->seg_num < mad_send_wr->send_buf.seg_count) {
718 /* Send failure will just result in a timeout/retry */ 676 /* Send failure will just result in a timeout/retry */
719 ret = send_next_seg(mad_send_wr); 677 ret = send_next_seg(mad_send_wr);
720 if (ret) 678 if (ret)
@@ -838,31 +796,19 @@ out:
838int ib_send_rmpp_mad(struct ib_mad_send_wr_private *mad_send_wr) 796int ib_send_rmpp_mad(struct ib_mad_send_wr_private *mad_send_wr)
839{ 797{
840 struct ib_rmpp_mad *rmpp_mad; 798 struct ib_rmpp_mad *rmpp_mad;
841 int i, total_len, ret; 799 int ret;
842 800
843 rmpp_mad = mad_send_wr->send_buf.mad; 801 rmpp_mad = mad_send_wr->send_buf.mad;
844 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & 802 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
845 IB_MGMT_RMPP_FLAG_ACTIVE)) 803 IB_MGMT_RMPP_FLAG_ACTIVE))
846 return IB_RMPP_RESULT_UNHANDLED; 804 return IB_RMPP_RESULT_UNHANDLED;
847 805
848 if (rmpp_mad->rmpp_hdr.rmpp_type != IB_MGMT_RMPP_TYPE_DATA) 806 if (rmpp_mad->rmpp_hdr.rmpp_type != IB_MGMT_RMPP_TYPE_DATA) {
807 mad_send_wr->seg_num = 1;
849 return IB_RMPP_RESULT_INTERNAL; 808 return IB_RMPP_RESULT_INTERNAL;
809 }
850 810
851 if (mad_send_wr->send_wr.num_sge > 1)
852 return -EINVAL; /* TODO: support num_sge > 1 */
853
854 mad_send_wr->seg_num = 1;
855 mad_send_wr->newwin = 1; 811 mad_send_wr->newwin = 1;
856 mad_send_wr->data_offset = data_offset(rmpp_mad->mad_hdr.mgmt_class);
857
858 total_len = 0;
859 for (i = 0; i < mad_send_wr->send_wr.num_sge; i++)
860 total_len += mad_send_wr->send_wr.sg_list[i].length;
861
862 mad_send_wr->total_seg = (total_len - mad_send_wr->data_offset) /
863 (sizeof(struct ib_rmpp_mad) - mad_send_wr->data_offset);
864 mad_send_wr->pad = total_len - IB_MGMT_RMPP_HDR -
865 be32_to_cpu(rmpp_mad->rmpp_hdr.paylen_newwin);
866 812
867 /* We need to wait for the final ACK even if there isn't a response */ 813 /* We need to wait for the final ACK even if there isn't a response */
868 mad_send_wr->refcount += (mad_send_wr->timeout == 0); 814 mad_send_wr->refcount += (mad_send_wr->timeout == 0);
@@ -893,14 +839,14 @@ int ib_process_rmpp_send_wc(struct ib_mad_send_wr_private *mad_send_wr,
893 if (!mad_send_wr->timeout) 839 if (!mad_send_wr->timeout)
894 return IB_RMPP_RESULT_PROCESSED; /* Response received */ 840 return IB_RMPP_RESULT_PROCESSED; /* Response received */
895 841
896 if (mad_send_wr->last_ack == mad_send_wr->total_seg) { 842 if (mad_send_wr->last_ack == mad_send_wr->send_buf.seg_count) {
897 mad_send_wr->timeout = 843 mad_send_wr->timeout =
898 msecs_to_jiffies(mad_send_wr->send_buf.timeout_ms); 844 msecs_to_jiffies(mad_send_wr->send_buf.timeout_ms);
899 return IB_RMPP_RESULT_PROCESSED; /* Send done */ 845 return IB_RMPP_RESULT_PROCESSED; /* Send done */
900 } 846 }
901 847
902 if (mad_send_wr->seg_num > mad_send_wr->newwin || 848 if (mad_send_wr->seg_num == mad_send_wr->newwin ||
903 mad_send_wr->seg_num > mad_send_wr->total_seg) 849 mad_send_wr->seg_num == mad_send_wr->send_buf.seg_count)
904 return IB_RMPP_RESULT_PROCESSED; /* Wait for ACK */ 850 return IB_RMPP_RESULT_PROCESSED; /* Wait for ACK */
905 851
906 ret = send_next_seg(mad_send_wr); 852 ret = send_next_seg(mad_send_wr);
@@ -921,10 +867,12 @@ int ib_retry_rmpp(struct ib_mad_send_wr_private *mad_send_wr)
921 IB_MGMT_RMPP_FLAG_ACTIVE)) 867 IB_MGMT_RMPP_FLAG_ACTIVE))
922 return IB_RMPP_RESULT_UNHANDLED; /* RMPP not active */ 868 return IB_RMPP_RESULT_UNHANDLED; /* RMPP not active */
923 869
924 if (mad_send_wr->last_ack == mad_send_wr->total_seg) 870 if (mad_send_wr->last_ack == mad_send_wr->send_buf.seg_count)
925 return IB_RMPP_RESULT_PROCESSED; 871 return IB_RMPP_RESULT_PROCESSED;
926 872
927 mad_send_wr->seg_num = mad_send_wr->last_ack + 1; 873 mad_send_wr->seg_num = mad_send_wr->last_ack;
874 mad_send_wr->cur_seg = mad_send_wr->last_ack_seg;
875
928 ret = send_next_seg(mad_send_wr); 876 ret = send_next_seg(mad_send_wr);
929 if (ret) 877 if (ret)
930 return IB_RMPP_RESULT_PROCESSED; 878 return IB_RMPP_RESULT_PROCESSED;
diff --git a/drivers/infiniband/core/smi.h b/drivers/infiniband/core/smi.h
index 2b3c40198f81..3011bfd86dc5 100644
--- a/drivers/infiniband/core/smi.h
+++ b/drivers/infiniband/core/smi.h
@@ -49,19 +49,16 @@ extern int smi_check_forward_dr_smp(struct ib_smp *smp);
49extern int smi_handle_dr_smp_send(struct ib_smp *smp, 49extern int smi_handle_dr_smp_send(struct ib_smp *smp,
50 u8 node_type, 50 u8 node_type,
51 int port_num); 51 int port_num);
52extern int smi_check_local_dr_smp(struct ib_smp *smp,
53 struct ib_device *device,
54 int port_num);
55 52
56/* 53/*
57 * Return 1 if the SMP should be handled by the local SMA/SM via process_mad 54 * Return 1 if the SMP should be handled by the local SMA/SM via process_mad
58 */ 55 */
59static inline int smi_check_local_smp(struct ib_mad_agent *mad_agent, 56static inline int smi_check_local_smp(struct ib_smp *smp,
60 struct ib_smp *smp) 57 struct ib_device *device)
61{ 58{
62 /* C14-9:3 -- We're at the end of the DR segment of path */ 59 /* C14-9:3 -- We're at the end of the DR segment of path */
63 /* C14-9:4 -- Hop Pointer = Hop Count + 1 -> give to SMA/SM */ 60 /* C14-9:4 -- Hop Pointer = Hop Count + 1 -> give to SMA/SM */
64 return ((mad_agent->device->process_mad && 61 return ((device->process_mad &&
65 !ib_get_smp_direction(smp) && 62 !ib_get_smp_direction(smp) &&
66 (smp->hop_ptr == smp->hop_cnt + 1))); 63 (smp->hop_ptr == smp->hop_cnt + 1)));
67} 64}
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 5982d687a000..15121cb5a1f6 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -112,7 +112,7 @@ static ssize_t state_show(struct ib_port *p, struct port_attribute *unused,
112 return ret; 112 return ret;
113 113
114 return sprintf(buf, "%d: %s\n", attr.state, 114 return sprintf(buf, "%d: %s\n", attr.state,
115 attr.state >= 0 && attr.state <= ARRAY_SIZE(state_name) ? 115 attr.state >= 0 && attr.state < ARRAY_SIZE(state_name) ?
116 state_name[attr.state] : "UNKNOWN"); 116 state_name[attr.state] : "UNKNOWN");
117} 117}
118 118
@@ -472,8 +472,10 @@ alloc_group_attrs(ssize_t (*show)(struct ib_port *,
472 goto err; 472 goto err;
473 473
474 if (snprintf(element->name, sizeof(element->name), 474 if (snprintf(element->name, sizeof(element->name),
475 "%d", i) >= sizeof(element->name)) 475 "%d", i) >= sizeof(element->name)) {
476 kfree(element);
476 goto err; 477 goto err;
478 }
477 479
478 element->attr.attr.name = element->name; 480 element->attr.attr.name = element->name;
479 element->attr.attr.mode = S_IRUGO; 481 element->attr.attr.mode = S_IRUGO;
@@ -628,14 +630,42 @@ static ssize_t show_node_guid(struct class_device *cdev, char *buf)
628 be16_to_cpu(((__be16 *) &dev->node_guid)[3])); 630 be16_to_cpu(((__be16 *) &dev->node_guid)[3]));
629} 631}
630 632
633static ssize_t show_node_desc(struct class_device *cdev, char *buf)
634{
635 struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
636
637 return sprintf(buf, "%.64s\n", dev->node_desc);
638}
639
640static ssize_t set_node_desc(struct class_device *cdev, const char *buf,
641 size_t count)
642{
643 struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
644 struct ib_device_modify desc = {};
645 int ret;
646
647 if (!dev->modify_device)
648 return -EIO;
649
650 memcpy(desc.node_desc, buf, min_t(int, count, 64));
651 ret = ib_modify_device(dev, IB_DEVICE_MODIFY_NODE_DESC, &desc);
652 if (ret)
653 return ret;
654
655 return count;
656}
657
631static CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL); 658static CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
632static CLASS_DEVICE_ATTR(sys_image_guid, S_IRUGO, show_sys_image_guid, NULL); 659static CLASS_DEVICE_ATTR(sys_image_guid, S_IRUGO, show_sys_image_guid, NULL);
633static CLASS_DEVICE_ATTR(node_guid, S_IRUGO, show_node_guid, NULL); 660static CLASS_DEVICE_ATTR(node_guid, S_IRUGO, show_node_guid, NULL);
661static CLASS_DEVICE_ATTR(node_desc, S_IRUGO | S_IWUSR, show_node_desc,
662 set_node_desc);
634 663
635static struct class_device_attribute *ib_class_attributes[] = { 664static struct class_device_attribute *ib_class_attributes[] = {
636 &class_device_attr_node_type, 665 &class_device_attr_node_type,
637 &class_device_attr_sys_image_guid, 666 &class_device_attr_sys_image_guid,
638 &class_device_attr_node_guid 667 &class_device_attr_node_guid,
668 &class_device_attr_node_desc
639}; 669};
640 670
641static struct class ib_class = { 671static struct class ib_class = {
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
index c908de8db5a9..fb6cd42601f9 100644
--- a/drivers/infiniband/core/user_mad.c
+++ b/drivers/infiniband/core/user_mad.c
@@ -31,7 +31,7 @@
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE. 32 * SOFTWARE.
33 * 33 *
34 * $Id: user_mad.c 4010 2005-11-09 23:11:56Z roland $ 34 * $Id: user_mad.c 5596 2006-03-03 01:00:07Z sean.hefty $
35 */ 35 */
36 36
37#include <linux/module.h> 37#include <linux/module.h>
@@ -121,6 +121,7 @@ struct ib_umad_file {
121 121
122struct ib_umad_packet { 122struct ib_umad_packet {
123 struct ib_mad_send_buf *msg; 123 struct ib_mad_send_buf *msg;
124 struct ib_mad_recv_wc *recv_wc;
124 struct list_head list; 125 struct list_head list;
125 int length; 126 int length;
126 struct ib_user_mad mad; 127 struct ib_user_mad mad;
@@ -176,31 +177,32 @@ static int queue_packet(struct ib_umad_file *file,
176 return ret; 177 return ret;
177} 178}
178 179
180static int data_offset(u8 mgmt_class)
181{
182 if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM)
183 return IB_MGMT_SA_HDR;
184 else if ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
185 (mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END))
186 return IB_MGMT_VENDOR_HDR;
187 else
188 return IB_MGMT_RMPP_HDR;
189}
190
179static void send_handler(struct ib_mad_agent *agent, 191static void send_handler(struct ib_mad_agent *agent,
180 struct ib_mad_send_wc *send_wc) 192 struct ib_mad_send_wc *send_wc)
181{ 193{
182 struct ib_umad_file *file = agent->context; 194 struct ib_umad_file *file = agent->context;
183 struct ib_umad_packet *timeout;
184 struct ib_umad_packet *packet = send_wc->send_buf->context[0]; 195 struct ib_umad_packet *packet = send_wc->send_buf->context[0];
185 196
186 ib_destroy_ah(packet->msg->ah); 197 ib_destroy_ah(packet->msg->ah);
187 ib_free_send_mad(packet->msg); 198 ib_free_send_mad(packet->msg);
188 199
189 if (send_wc->status == IB_WC_RESP_TIMEOUT_ERR) { 200 if (send_wc->status == IB_WC_RESP_TIMEOUT_ERR) {
190 timeout = kzalloc(sizeof *timeout + IB_MGMT_MAD_HDR, GFP_KERNEL); 201 packet->length = IB_MGMT_MAD_HDR;
191 if (!timeout) 202 packet->mad.hdr.status = ETIMEDOUT;
192 goto out; 203 if (!queue_packet(file, agent, packet))
193 204 return;
194 timeout->length = IB_MGMT_MAD_HDR;
195 timeout->mad.hdr.id = packet->mad.hdr.id;
196 timeout->mad.hdr.status = ETIMEDOUT;
197 memcpy(timeout->mad.data, packet->mad.data,
198 sizeof (struct ib_mad_hdr));
199
200 if (queue_packet(file, agent, timeout))
201 kfree(timeout);
202 } 205 }
203out:
204 kfree(packet); 206 kfree(packet);
205} 207}
206 208
@@ -209,22 +211,20 @@ static void recv_handler(struct ib_mad_agent *agent,
209{ 211{
210 struct ib_umad_file *file = agent->context; 212 struct ib_umad_file *file = agent->context;
211 struct ib_umad_packet *packet; 213 struct ib_umad_packet *packet;
212 int length;
213 214
214 if (mad_recv_wc->wc->status != IB_WC_SUCCESS) 215 if (mad_recv_wc->wc->status != IB_WC_SUCCESS)
215 goto out; 216 goto err1;
216 217
217 length = mad_recv_wc->mad_len; 218 packet = kzalloc(sizeof *packet, GFP_KERNEL);
218 packet = kzalloc(sizeof *packet + length, GFP_KERNEL);
219 if (!packet) 219 if (!packet)
220 goto out; 220 goto err1;
221 221
222 packet->length = length; 222 packet->length = mad_recv_wc->mad_len;
223 223 packet->recv_wc = mad_recv_wc;
224 ib_coalesce_recv_mad(mad_recv_wc, packet->mad.data);
225 224
226 packet->mad.hdr.status = 0; 225 packet->mad.hdr.status = 0;
227 packet->mad.hdr.length = length + sizeof (struct ib_user_mad); 226 packet->mad.hdr.length = sizeof (struct ib_user_mad) +
227 mad_recv_wc->mad_len;
228 packet->mad.hdr.qpn = cpu_to_be32(mad_recv_wc->wc->src_qp); 228 packet->mad.hdr.qpn = cpu_to_be32(mad_recv_wc->wc->src_qp);
229 packet->mad.hdr.lid = cpu_to_be16(mad_recv_wc->wc->slid); 229 packet->mad.hdr.lid = cpu_to_be16(mad_recv_wc->wc->slid);
230 packet->mad.hdr.sl = mad_recv_wc->wc->sl; 230 packet->mad.hdr.sl = mad_recv_wc->wc->sl;
@@ -240,12 +240,79 @@ static void recv_handler(struct ib_mad_agent *agent,
240 } 240 }
241 241
242 if (queue_packet(file, agent, packet)) 242 if (queue_packet(file, agent, packet))
243 kfree(packet); 243 goto err2;
244 return;
244 245
245out: 246err2:
247 kfree(packet);
248err1:
246 ib_free_recv_mad(mad_recv_wc); 249 ib_free_recv_mad(mad_recv_wc);
247} 250}
248 251
252static ssize_t copy_recv_mad(char __user *buf, struct ib_umad_packet *packet,
253 size_t count)
254{
255 struct ib_mad_recv_buf *recv_buf;
256 int left, seg_payload, offset, max_seg_payload;
257
258 /* We need enough room to copy the first (or only) MAD segment. */
259 recv_buf = &packet->recv_wc->recv_buf;
260 if ((packet->length <= sizeof (*recv_buf->mad) &&
261 count < sizeof (packet->mad) + packet->length) ||
262 (packet->length > sizeof (*recv_buf->mad) &&
263 count < sizeof (packet->mad) + sizeof (*recv_buf->mad)))
264 return -EINVAL;
265
266 if (copy_to_user(buf, &packet->mad, sizeof (packet->mad)))
267 return -EFAULT;
268
269 buf += sizeof (packet->mad);
270 seg_payload = min_t(int, packet->length, sizeof (*recv_buf->mad));
271 if (copy_to_user(buf, recv_buf->mad, seg_payload))
272 return -EFAULT;
273
274 if (seg_payload < packet->length) {
275 /*
276 * Multipacket RMPP MAD message. Copy remainder of message.
277 * Note that last segment may have a shorter payload.
278 */
279 if (count < sizeof (packet->mad) + packet->length) {
280 /*
281 * The buffer is too small, return the first RMPP segment,
282 * which includes the RMPP message length.
283 */
284 return -ENOSPC;
285 }
286 offset = data_offset(recv_buf->mad->mad_hdr.mgmt_class);
287 max_seg_payload = sizeof (struct ib_mad) - offset;
288
289 for (left = packet->length - seg_payload, buf += seg_payload;
290 left; left -= seg_payload, buf += seg_payload) {
291 recv_buf = container_of(recv_buf->list.next,
292 struct ib_mad_recv_buf, list);
293 seg_payload = min(left, max_seg_payload);
294 if (copy_to_user(buf, ((void *) recv_buf->mad) + offset,
295 seg_payload))
296 return -EFAULT;
297 }
298 }
299 return sizeof (packet->mad) + packet->length;
300}
301
302static ssize_t copy_send_mad(char __user *buf, struct ib_umad_packet *packet,
303 size_t count)
304{
305 ssize_t size = sizeof (packet->mad) + packet->length;
306
307 if (count < size)
308 return -EINVAL;
309
310 if (copy_to_user(buf, &packet->mad, size))
311 return -EFAULT;
312
313 return size;
314}
315
249static ssize_t ib_umad_read(struct file *filp, char __user *buf, 316static ssize_t ib_umad_read(struct file *filp, char __user *buf,
250 size_t count, loff_t *pos) 317 size_t count, loff_t *pos)
251{ 318{
@@ -253,7 +320,7 @@ static ssize_t ib_umad_read(struct file *filp, char __user *buf,
253 struct ib_umad_packet *packet; 320 struct ib_umad_packet *packet;
254 ssize_t ret; 321 ssize_t ret;
255 322
256 if (count < sizeof (struct ib_user_mad) + sizeof (struct ib_mad)) 323 if (count < sizeof (struct ib_user_mad))
257 return -EINVAL; 324 return -EINVAL;
258 325
259 spin_lock_irq(&file->recv_lock); 326 spin_lock_irq(&file->recv_lock);
@@ -276,28 +343,44 @@ static ssize_t ib_umad_read(struct file *filp, char __user *buf,
276 343
277 spin_unlock_irq(&file->recv_lock); 344 spin_unlock_irq(&file->recv_lock);
278 345
279 if (count < packet->length + sizeof (struct ib_user_mad)) { 346 if (packet->recv_wc)
280 /* Return length needed (and first RMPP segment) if too small */ 347 ret = copy_recv_mad(buf, packet, count);
281 if (copy_to_user(buf, &packet->mad,
282 sizeof (struct ib_user_mad) + sizeof (struct ib_mad)))
283 ret = -EFAULT;
284 else
285 ret = -ENOSPC;
286 } else if (copy_to_user(buf, &packet->mad,
287 packet->length + sizeof (struct ib_user_mad)))
288 ret = -EFAULT;
289 else 348 else
290 ret = packet->length + sizeof (struct ib_user_mad); 349 ret = copy_send_mad(buf, packet, count);
350
291 if (ret < 0) { 351 if (ret < 0) {
292 /* Requeue packet */ 352 /* Requeue packet */
293 spin_lock_irq(&file->recv_lock); 353 spin_lock_irq(&file->recv_lock);
294 list_add(&packet->list, &file->recv_list); 354 list_add(&packet->list, &file->recv_list);
295 spin_unlock_irq(&file->recv_lock); 355 spin_unlock_irq(&file->recv_lock);
296 } else 356 } else {
357 if (packet->recv_wc)
358 ib_free_recv_mad(packet->recv_wc);
297 kfree(packet); 359 kfree(packet);
360 }
298 return ret; 361 return ret;
299} 362}
300 363
364static int copy_rmpp_mad(struct ib_mad_send_buf *msg, const char __user *buf)
365{
366 int left, seg;
367
368 /* Copy class specific header */
369 if ((msg->hdr_len > IB_MGMT_RMPP_HDR) &&
370 copy_from_user(msg->mad + IB_MGMT_RMPP_HDR, buf + IB_MGMT_RMPP_HDR,
371 msg->hdr_len - IB_MGMT_RMPP_HDR))
372 return -EFAULT;
373
374 /* All headers are in place. Copy data segments. */
375 for (seg = 1, left = msg->data_len, buf += msg->hdr_len; left > 0;
376 seg++, left -= msg->seg_size, buf += msg->seg_size) {
377 if (copy_from_user(ib_get_rmpp_segment(msg, seg), buf,
378 min(left, msg->seg_size)))
379 return -EFAULT;
380 }
381 return 0;
382}
383
301static ssize_t ib_umad_write(struct file *filp, const char __user *buf, 384static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
302 size_t count, loff_t *pos) 385 size_t count, loff_t *pos)
303{ 386{
@@ -309,14 +392,12 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
309 struct ib_rmpp_mad *rmpp_mad; 392 struct ib_rmpp_mad *rmpp_mad;
310 u8 method; 393 u8 method;
311 __be64 *tid; 394 __be64 *tid;
312 int ret, length, hdr_len, copy_offset; 395 int ret, data_len, hdr_len, copy_offset, rmpp_active;
313 int rmpp_active, has_rmpp_header;
314 396
315 if (count < sizeof (struct ib_user_mad) + IB_MGMT_RMPP_HDR) 397 if (count < sizeof (struct ib_user_mad) + IB_MGMT_RMPP_HDR)
316 return -EINVAL; 398 return -EINVAL;
317 399
318 length = count - sizeof (struct ib_user_mad); 400 packet = kzalloc(sizeof *packet + IB_MGMT_RMPP_HDR, GFP_KERNEL);
319 packet = kmalloc(sizeof *packet + IB_MGMT_RMPP_HDR, GFP_KERNEL);
320 if (!packet) 401 if (!packet)
321 return -ENOMEM; 402 return -ENOMEM;
322 403
@@ -363,35 +444,25 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
363 if (rmpp_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_ADM) { 444 if (rmpp_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_ADM) {
364 hdr_len = IB_MGMT_SA_HDR; 445 hdr_len = IB_MGMT_SA_HDR;
365 copy_offset = IB_MGMT_RMPP_HDR; 446 copy_offset = IB_MGMT_RMPP_HDR;
366 has_rmpp_header = 1; 447 rmpp_active = ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
448 IB_MGMT_RMPP_FLAG_ACTIVE;
367 } else if (rmpp_mad->mad_hdr.mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START && 449 } else if (rmpp_mad->mad_hdr.mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START &&
368 rmpp_mad->mad_hdr.mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END) { 450 rmpp_mad->mad_hdr.mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END) {
369 hdr_len = IB_MGMT_VENDOR_HDR; 451 hdr_len = IB_MGMT_VENDOR_HDR;
370 copy_offset = IB_MGMT_RMPP_HDR; 452 copy_offset = IB_MGMT_RMPP_HDR;
371 has_rmpp_header = 1; 453 rmpp_active = ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
454 IB_MGMT_RMPP_FLAG_ACTIVE;
372 } else { 455 } else {
373 hdr_len = IB_MGMT_MAD_HDR; 456 hdr_len = IB_MGMT_MAD_HDR;
374 copy_offset = IB_MGMT_MAD_HDR; 457 copy_offset = IB_MGMT_MAD_HDR;
375 has_rmpp_header = 0;
376 }
377
378 if (has_rmpp_header)
379 rmpp_active = ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
380 IB_MGMT_RMPP_FLAG_ACTIVE;
381 else
382 rmpp_active = 0; 458 rmpp_active = 0;
383
384 /* Validate that the management class can support RMPP */
385 if (rmpp_active && !agent->rmpp_version) {
386 ret = -EINVAL;
387 goto err_ah;
388 } 459 }
389 460
461 data_len = count - sizeof (struct ib_user_mad) - hdr_len;
390 packet->msg = ib_create_send_mad(agent, 462 packet->msg = ib_create_send_mad(agent,
391 be32_to_cpu(packet->mad.hdr.qpn), 463 be32_to_cpu(packet->mad.hdr.qpn),
392 0, rmpp_active, 464 0, rmpp_active, hdr_len,
393 hdr_len, length - hdr_len, 465 data_len, GFP_KERNEL);
394 GFP_KERNEL);
395 if (IS_ERR(packet->msg)) { 466 if (IS_ERR(packet->msg)) {
396 ret = PTR_ERR(packet->msg); 467 ret = PTR_ERR(packet->msg);
397 goto err_ah; 468 goto err_ah;
@@ -402,14 +473,21 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
402 packet->msg->retries = packet->mad.hdr.retries; 473 packet->msg->retries = packet->mad.hdr.retries;
403 packet->msg->context[0] = packet; 474 packet->msg->context[0] = packet;
404 475
405 /* Copy MAD headers (RMPP header in place) */ 476 /* Copy MAD header. Any RMPP header is already in place. */
406 memcpy(packet->msg->mad, packet->mad.data, IB_MGMT_MAD_HDR); 477 memcpy(packet->msg->mad, packet->mad.data, IB_MGMT_MAD_HDR);
407 /* Now, copy rest of message from user into send buffer */ 478 buf += sizeof (struct ib_user_mad);
408 if (copy_from_user(packet->msg->mad + copy_offset, 479
409 buf + sizeof (struct ib_user_mad) + copy_offset, 480 if (!rmpp_active) {
410 length - copy_offset)) { 481 if (copy_from_user(packet->msg->mad + copy_offset,
411 ret = -EFAULT; 482 buf + copy_offset,
412 goto err_msg; 483 hdr_len + data_len - copy_offset)) {
484 ret = -EFAULT;
485 goto err_msg;
486 }
487 } else {
488 ret = copy_rmpp_mad(packet->msg, buf);
489 if (ret)
490 goto err_msg;
413 } 491 }
414 492
415 /* 493 /*
@@ -433,18 +511,14 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
433 goto err_msg; 511 goto err_msg;
434 512
435 up_read(&file->port->mutex); 513 up_read(&file->port->mutex);
436
437 return count; 514 return count;
438 515
439err_msg: 516err_msg:
440 ib_free_send_mad(packet->msg); 517 ib_free_send_mad(packet->msg);
441
442err_ah: 518err_ah:
443 ib_destroy_ah(ah); 519 ib_destroy_ah(ah);
444
445err_up: 520err_up:
446 up_read(&file->port->mutex); 521 up_read(&file->port->mutex);
447
448err: 522err:
449 kfree(packet); 523 kfree(packet);
450 return ret; 524 return ret;
@@ -627,8 +701,11 @@ static int ib_umad_close(struct inode *inode, struct file *filp)
627 already_dead = file->agents_dead; 701 already_dead = file->agents_dead;
628 file->agents_dead = 1; 702 file->agents_dead = 1;
629 703
630 list_for_each_entry_safe(packet, tmp, &file->recv_list, list) 704 list_for_each_entry_safe(packet, tmp, &file->recv_list, list) {
705 if (packet->recv_wc)
706 ib_free_recv_mad(packet->recv_wc);
631 kfree(packet); 707 kfree(packet);
708 }
632 709
633 list_del(&file->port_list); 710 list_del(&file->port_list);
634 711
diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
index f7eecbc6af6c..3372d67ff139 100644
--- a/drivers/infiniband/core/uverbs.h
+++ b/drivers/infiniband/core/uverbs.h
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 3 * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
5 * Copyright (c) 2005 Voltaire, Inc. All rights reserved. 5 * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
6 * Copyright (c) 2005 PathScale, Inc. All rights reserved. 6 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
@@ -178,10 +178,12 @@ IB_UVERBS_DECLARE_CMD(reg_mr);
178IB_UVERBS_DECLARE_CMD(dereg_mr); 178IB_UVERBS_DECLARE_CMD(dereg_mr);
179IB_UVERBS_DECLARE_CMD(create_comp_channel); 179IB_UVERBS_DECLARE_CMD(create_comp_channel);
180IB_UVERBS_DECLARE_CMD(create_cq); 180IB_UVERBS_DECLARE_CMD(create_cq);
181IB_UVERBS_DECLARE_CMD(resize_cq);
181IB_UVERBS_DECLARE_CMD(poll_cq); 182IB_UVERBS_DECLARE_CMD(poll_cq);
182IB_UVERBS_DECLARE_CMD(req_notify_cq); 183IB_UVERBS_DECLARE_CMD(req_notify_cq);
183IB_UVERBS_DECLARE_CMD(destroy_cq); 184IB_UVERBS_DECLARE_CMD(destroy_cq);
184IB_UVERBS_DECLARE_CMD(create_qp); 185IB_UVERBS_DECLARE_CMD(create_qp);
186IB_UVERBS_DECLARE_CMD(query_qp);
185IB_UVERBS_DECLARE_CMD(modify_qp); 187IB_UVERBS_DECLARE_CMD(modify_qp);
186IB_UVERBS_DECLARE_CMD(destroy_qp); 188IB_UVERBS_DECLARE_CMD(destroy_qp);
187IB_UVERBS_DECLARE_CMD(post_send); 189IB_UVERBS_DECLARE_CMD(post_send);
@@ -193,6 +195,7 @@ IB_UVERBS_DECLARE_CMD(attach_mcast);
193IB_UVERBS_DECLARE_CMD(detach_mcast); 195IB_UVERBS_DECLARE_CMD(detach_mcast);
194IB_UVERBS_DECLARE_CMD(create_srq); 196IB_UVERBS_DECLARE_CMD(create_srq);
195IB_UVERBS_DECLARE_CMD(modify_srq); 197IB_UVERBS_DECLARE_CMD(modify_srq);
198IB_UVERBS_DECLARE_CMD(query_srq);
196IB_UVERBS_DECLARE_CMD(destroy_srq); 199IB_UVERBS_DECLARE_CMD(destroy_srq);
197 200
198#endif /* UVERBS_H */ 201#endif /* UVERBS_H */
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 407b6284d7d5..9f69bd48eb1b 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 3 * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 PathScale, Inc. All rights reserved. 4 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
5 * Copyright (c) 2006 Mellanox Technologies. All rights reserved.
5 * 6 *
6 * This software is available to you under a choice of one of two 7 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU 8 * licenses. You may choose to be licensed under the terms of the GNU
@@ -675,6 +676,46 @@ err:
675 return ret; 676 return ret;
676} 677}
677 678
679ssize_t ib_uverbs_resize_cq(struct ib_uverbs_file *file,
680 const char __user *buf, int in_len,
681 int out_len)
682{
683 struct ib_uverbs_resize_cq cmd;
684 struct ib_uverbs_resize_cq_resp resp;
685 struct ib_udata udata;
686 struct ib_cq *cq;
687 int ret = -EINVAL;
688
689 if (copy_from_user(&cmd, buf, sizeof cmd))
690 return -EFAULT;
691
692 INIT_UDATA(&udata, buf + sizeof cmd,
693 (unsigned long) cmd.response + sizeof resp,
694 in_len - sizeof cmd, out_len - sizeof resp);
695
696 mutex_lock(&ib_uverbs_idr_mutex);
697
698 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
699 if (!cq || cq->uobject->context != file->ucontext || !cq->device->resize_cq)
700 goto out;
701
702 ret = cq->device->resize_cq(cq, cmd.cqe, &udata);
703 if (ret)
704 goto out;
705
706 memset(&resp, 0, sizeof resp);
707 resp.cqe = cq->cqe;
708
709 if (copy_to_user((void __user *) (unsigned long) cmd.response,
710 &resp, sizeof resp))
711 ret = -EFAULT;
712
713out:
714 mutex_unlock(&ib_uverbs_idr_mutex);
715
716 return ret ? ret : in_len;
717}
718
678ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file, 719ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file,
679 const char __user *buf, int in_len, 720 const char __user *buf, int in_len,
680 int out_len) 721 int out_len)
@@ -956,6 +997,106 @@ err_up:
956 return ret; 997 return ret;
957} 998}
958 999
1000ssize_t ib_uverbs_query_qp(struct ib_uverbs_file *file,
1001 const char __user *buf, int in_len,
1002 int out_len)
1003{
1004 struct ib_uverbs_query_qp cmd;
1005 struct ib_uverbs_query_qp_resp resp;
1006 struct ib_qp *qp;
1007 struct ib_qp_attr *attr;
1008 struct ib_qp_init_attr *init_attr;
1009 int ret;
1010
1011 if (copy_from_user(&cmd, buf, sizeof cmd))
1012 return -EFAULT;
1013
1014 attr = kmalloc(sizeof *attr, GFP_KERNEL);
1015 init_attr = kmalloc(sizeof *init_attr, GFP_KERNEL);
1016 if (!attr || !init_attr) {
1017 ret = -ENOMEM;
1018 goto out;
1019 }
1020
1021 mutex_lock(&ib_uverbs_idr_mutex);
1022
1023 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1024 if (qp && qp->uobject->context == file->ucontext)
1025 ret = ib_query_qp(qp, attr, cmd.attr_mask, init_attr);
1026 else
1027 ret = -EINVAL;
1028
1029 mutex_unlock(&ib_uverbs_idr_mutex);
1030
1031 if (ret)
1032 goto out;
1033
1034 memset(&resp, 0, sizeof resp);
1035
1036 resp.qp_state = attr->qp_state;
1037 resp.cur_qp_state = attr->cur_qp_state;
1038 resp.path_mtu = attr->path_mtu;
1039 resp.path_mig_state = attr->path_mig_state;
1040 resp.qkey = attr->qkey;
1041 resp.rq_psn = attr->rq_psn;
1042 resp.sq_psn = attr->sq_psn;
1043 resp.dest_qp_num = attr->dest_qp_num;
1044 resp.qp_access_flags = attr->qp_access_flags;
1045 resp.pkey_index = attr->pkey_index;
1046 resp.alt_pkey_index = attr->alt_pkey_index;
1047 resp.en_sqd_async_notify = attr->en_sqd_async_notify;
1048 resp.max_rd_atomic = attr->max_rd_atomic;
1049 resp.max_dest_rd_atomic = attr->max_dest_rd_atomic;
1050 resp.min_rnr_timer = attr->min_rnr_timer;
1051 resp.port_num = attr->port_num;
1052 resp.timeout = attr->timeout;
1053 resp.retry_cnt = attr->retry_cnt;
1054 resp.rnr_retry = attr->rnr_retry;
1055 resp.alt_port_num = attr->alt_port_num;
1056 resp.alt_timeout = attr->alt_timeout;
1057
1058 memcpy(resp.dest.dgid, attr->ah_attr.grh.dgid.raw, 16);
1059 resp.dest.flow_label = attr->ah_attr.grh.flow_label;
1060 resp.dest.sgid_index = attr->ah_attr.grh.sgid_index;
1061 resp.dest.hop_limit = attr->ah_attr.grh.hop_limit;
1062 resp.dest.traffic_class = attr->ah_attr.grh.traffic_class;
1063 resp.dest.dlid = attr->ah_attr.dlid;
1064 resp.dest.sl = attr->ah_attr.sl;
1065 resp.dest.src_path_bits = attr->ah_attr.src_path_bits;
1066 resp.dest.static_rate = attr->ah_attr.static_rate;
1067 resp.dest.is_global = !!(attr->ah_attr.ah_flags & IB_AH_GRH);
1068 resp.dest.port_num = attr->ah_attr.port_num;
1069
1070 memcpy(resp.alt_dest.dgid, attr->alt_ah_attr.grh.dgid.raw, 16);
1071 resp.alt_dest.flow_label = attr->alt_ah_attr.grh.flow_label;
1072 resp.alt_dest.sgid_index = attr->alt_ah_attr.grh.sgid_index;
1073 resp.alt_dest.hop_limit = attr->alt_ah_attr.grh.hop_limit;
1074 resp.alt_dest.traffic_class = attr->alt_ah_attr.grh.traffic_class;
1075 resp.alt_dest.dlid = attr->alt_ah_attr.dlid;
1076 resp.alt_dest.sl = attr->alt_ah_attr.sl;
1077 resp.alt_dest.src_path_bits = attr->alt_ah_attr.src_path_bits;
1078 resp.alt_dest.static_rate = attr->alt_ah_attr.static_rate;
1079 resp.alt_dest.is_global = !!(attr->alt_ah_attr.ah_flags & IB_AH_GRH);
1080 resp.alt_dest.port_num = attr->alt_ah_attr.port_num;
1081
1082 resp.max_send_wr = init_attr->cap.max_send_wr;
1083 resp.max_recv_wr = init_attr->cap.max_recv_wr;
1084 resp.max_send_sge = init_attr->cap.max_send_sge;
1085 resp.max_recv_sge = init_attr->cap.max_recv_sge;
1086 resp.max_inline_data = init_attr->cap.max_inline_data;
1087 resp.sq_sig_all = init_attr->sq_sig_type == IB_SIGNAL_ALL_WR;
1088
1089 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1090 &resp, sizeof resp))
1091 ret = -EFAULT;
1092
1093out:
1094 kfree(attr);
1095 kfree(init_attr);
1096
1097 return ret ? ret : in_len;
1098}
1099
959ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file, 1100ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file,
960 const char __user *buf, int in_len, 1101 const char __user *buf, int in_len,
961 int out_len) 1102 int out_len)
@@ -990,7 +1131,7 @@ ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file,
990 attr->dest_qp_num = cmd.dest_qp_num; 1131 attr->dest_qp_num = cmd.dest_qp_num;
991 attr->qp_access_flags = cmd.qp_access_flags; 1132 attr->qp_access_flags = cmd.qp_access_flags;
992 attr->pkey_index = cmd.pkey_index; 1133 attr->pkey_index = cmd.pkey_index;
993 attr->alt_pkey_index = cmd.pkey_index; 1134 attr->alt_pkey_index = cmd.alt_pkey_index;
994 attr->en_sqd_async_notify = cmd.en_sqd_async_notify; 1135 attr->en_sqd_async_notify = cmd.en_sqd_async_notify;
995 attr->max_rd_atomic = cmd.max_rd_atomic; 1136 attr->max_rd_atomic = cmd.max_rd_atomic;
996 attr->max_dest_rd_atomic = cmd.max_dest_rd_atomic; 1137 attr->max_dest_rd_atomic = cmd.max_dest_rd_atomic;
@@ -1094,8 +1235,8 @@ out:
1094} 1235}
1095 1236
1096ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file, 1237ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
1097 const char __user *buf, int in_len, 1238 const char __user *buf, int in_len,
1098 int out_len) 1239 int out_len)
1099{ 1240{
1100 struct ib_uverbs_post_send cmd; 1241 struct ib_uverbs_post_send cmd;
1101 struct ib_uverbs_post_send_resp resp; 1242 struct ib_uverbs_post_send_resp resp;
@@ -1323,8 +1464,8 @@ err:
1323} 1464}
1324 1465
1325ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file, 1466ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file,
1326 const char __user *buf, int in_len, 1467 const char __user *buf, int in_len,
1327 int out_len) 1468 int out_len)
1328{ 1469{
1329 struct ib_uverbs_post_recv cmd; 1470 struct ib_uverbs_post_recv cmd;
1330 struct ib_uverbs_post_recv_resp resp; 1471 struct ib_uverbs_post_recv_resp resp;
@@ -1374,8 +1515,8 @@ out:
1374} 1515}
1375 1516
1376ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file, 1517ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file,
1377 const char __user *buf, int in_len, 1518 const char __user *buf, int in_len,
1378 int out_len) 1519 int out_len)
1379{ 1520{
1380 struct ib_uverbs_post_srq_recv cmd; 1521 struct ib_uverbs_post_srq_recv cmd;
1381 struct ib_uverbs_post_srq_recv_resp resp; 1522 struct ib_uverbs_post_srq_recv_resp resp;
@@ -1723,6 +1864,8 @@ retry:
1723 goto err_destroy; 1864 goto err_destroy;
1724 1865
1725 resp.srq_handle = uobj->uobject.id; 1866 resp.srq_handle = uobj->uobject.id;
1867 resp.max_wr = attr.attr.max_wr;
1868 resp.max_sge = attr.attr.max_sge;
1726 1869
1727 if (copy_to_user((void __user *) (unsigned long) cmd.response, 1870 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1728 &resp, sizeof resp)) { 1871 &resp, sizeof resp)) {
@@ -1783,6 +1926,49 @@ out:
1783 return ret ? ret : in_len; 1926 return ret ? ret : in_len;
1784} 1927}
1785 1928
1929ssize_t ib_uverbs_query_srq(struct ib_uverbs_file *file,
1930 const char __user *buf,
1931 int in_len, int out_len)
1932{
1933 struct ib_uverbs_query_srq cmd;
1934 struct ib_uverbs_query_srq_resp resp;
1935 struct ib_srq_attr attr;
1936 struct ib_srq *srq;
1937 int ret;
1938
1939 if (out_len < sizeof resp)
1940 return -ENOSPC;
1941
1942 if (copy_from_user(&cmd, buf, sizeof cmd))
1943 return -EFAULT;
1944
1945 mutex_lock(&ib_uverbs_idr_mutex);
1946
1947 srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle);
1948 if (srq && srq->uobject->context == file->ucontext)
1949 ret = ib_query_srq(srq, &attr);
1950 else
1951 ret = -EINVAL;
1952
1953 mutex_unlock(&ib_uverbs_idr_mutex);
1954
1955 if (ret)
1956 goto out;
1957
1958 memset(&resp, 0, sizeof resp);
1959
1960 resp.max_wr = attr.max_wr;
1961 resp.max_sge = attr.max_sge;
1962 resp.srq_limit = attr.srq_limit;
1963
1964 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1965 &resp, sizeof resp))
1966 ret = -EFAULT;
1967
1968out:
1969 return ret ? ret : in_len;
1970}
1971
1786ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file, 1972ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
1787 const char __user *buf, int in_len, 1973 const char __user *buf, int in_len,
1788 int out_len) 1974 int out_len)
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 903f85a4bc0c..ff092a0a94da 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 3 * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
5 * Copyright (c) 2005 Voltaire, Inc. All rights reserved. 5 * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
6 * Copyright (c) 2005 PathScale, Inc. All rights reserved. 6 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
@@ -91,10 +91,12 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
91 [IB_USER_VERBS_CMD_DEREG_MR] = ib_uverbs_dereg_mr, 91 [IB_USER_VERBS_CMD_DEREG_MR] = ib_uverbs_dereg_mr,
92 [IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL] = ib_uverbs_create_comp_channel, 92 [IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL] = ib_uverbs_create_comp_channel,
93 [IB_USER_VERBS_CMD_CREATE_CQ] = ib_uverbs_create_cq, 93 [IB_USER_VERBS_CMD_CREATE_CQ] = ib_uverbs_create_cq,
94 [IB_USER_VERBS_CMD_RESIZE_CQ] = ib_uverbs_resize_cq,
94 [IB_USER_VERBS_CMD_POLL_CQ] = ib_uverbs_poll_cq, 95 [IB_USER_VERBS_CMD_POLL_CQ] = ib_uverbs_poll_cq,
95 [IB_USER_VERBS_CMD_REQ_NOTIFY_CQ] = ib_uverbs_req_notify_cq, 96 [IB_USER_VERBS_CMD_REQ_NOTIFY_CQ] = ib_uverbs_req_notify_cq,
96 [IB_USER_VERBS_CMD_DESTROY_CQ] = ib_uverbs_destroy_cq, 97 [IB_USER_VERBS_CMD_DESTROY_CQ] = ib_uverbs_destroy_cq,
97 [IB_USER_VERBS_CMD_CREATE_QP] = ib_uverbs_create_qp, 98 [IB_USER_VERBS_CMD_CREATE_QP] = ib_uverbs_create_qp,
99 [IB_USER_VERBS_CMD_QUERY_QP] = ib_uverbs_query_qp,
98 [IB_USER_VERBS_CMD_MODIFY_QP] = ib_uverbs_modify_qp, 100 [IB_USER_VERBS_CMD_MODIFY_QP] = ib_uverbs_modify_qp,
99 [IB_USER_VERBS_CMD_DESTROY_QP] = ib_uverbs_destroy_qp, 101 [IB_USER_VERBS_CMD_DESTROY_QP] = ib_uverbs_destroy_qp,
100 [IB_USER_VERBS_CMD_POST_SEND] = ib_uverbs_post_send, 102 [IB_USER_VERBS_CMD_POST_SEND] = ib_uverbs_post_send,
@@ -106,6 +108,7 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
106 [IB_USER_VERBS_CMD_DETACH_MCAST] = ib_uverbs_detach_mcast, 108 [IB_USER_VERBS_CMD_DETACH_MCAST] = ib_uverbs_detach_mcast,
107 [IB_USER_VERBS_CMD_CREATE_SRQ] = ib_uverbs_create_srq, 109 [IB_USER_VERBS_CMD_CREATE_SRQ] = ib_uverbs_create_srq,
108 [IB_USER_VERBS_CMD_MODIFY_SRQ] = ib_uverbs_modify_srq, 110 [IB_USER_VERBS_CMD_MODIFY_SRQ] = ib_uverbs_modify_srq,
111 [IB_USER_VERBS_CMD_QUERY_SRQ] = ib_uverbs_query_srq,
109 [IB_USER_VERBS_CMD_DESTROY_SRQ] = ib_uverbs_destroy_srq, 112 [IB_USER_VERBS_CMD_DESTROY_SRQ] = ib_uverbs_destroy_srq,
110}; 113};
111 114
@@ -461,7 +464,6 @@ void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr)
461 ib_uverbs_async_handler(uobj->uverbs_file, uobj->uobject.user_handle, 464 ib_uverbs_async_handler(uobj->uverbs_file, uobj->uobject.user_handle,
462 event->event, &uobj->async_list, 465 event->event, &uobj->async_list,
463 &uobj->async_events_reported); 466 &uobj->async_events_reported);
464
465} 467}
466 468
467void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr) 469void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr)
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index c857361be449..cae0845f472a 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -5,7 +5,7 @@
5 * Copyright (c) 2004 Topspin Corporation. All rights reserved. 5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved. 6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
7 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. 7 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
8 * Copyright (c) 2005 Cisco Systems. All rights reserved. 8 * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
9 * 9 *
10 * This software is available to you under a choice of one of two 10 * This software is available to you under a choice of one of two
11 * licenses. You may choose to be licensed under the terms of the GNU 11 * licenses. You may choose to be licensed under the terms of the GNU
@@ -245,6 +245,258 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
245} 245}
246EXPORT_SYMBOL(ib_create_qp); 246EXPORT_SYMBOL(ib_create_qp);
247 247
248static const struct {
249 int valid;
250 enum ib_qp_attr_mask req_param[IB_QPT_RAW_ETY + 1];
251 enum ib_qp_attr_mask opt_param[IB_QPT_RAW_ETY + 1];
252} qp_state_table[IB_QPS_ERR + 1][IB_QPS_ERR + 1] = {
253 [IB_QPS_RESET] = {
254 [IB_QPS_RESET] = { .valid = 1 },
255 [IB_QPS_ERR] = { .valid = 1 },
256 [IB_QPS_INIT] = {
257 .valid = 1,
258 .req_param = {
259 [IB_QPT_UD] = (IB_QP_PKEY_INDEX |
260 IB_QP_PORT |
261 IB_QP_QKEY),
262 [IB_QPT_UC] = (IB_QP_PKEY_INDEX |
263 IB_QP_PORT |
264 IB_QP_ACCESS_FLAGS),
265 [IB_QPT_RC] = (IB_QP_PKEY_INDEX |
266 IB_QP_PORT |
267 IB_QP_ACCESS_FLAGS),
268 [IB_QPT_SMI] = (IB_QP_PKEY_INDEX |
269 IB_QP_QKEY),
270 [IB_QPT_GSI] = (IB_QP_PKEY_INDEX |
271 IB_QP_QKEY),
272 }
273 },
274 },
275 [IB_QPS_INIT] = {
276 [IB_QPS_RESET] = { .valid = 1 },
277 [IB_QPS_ERR] = { .valid = 1 },
278 [IB_QPS_INIT] = {
279 .valid = 1,
280 .opt_param = {
281 [IB_QPT_UD] = (IB_QP_PKEY_INDEX |
282 IB_QP_PORT |
283 IB_QP_QKEY),
284 [IB_QPT_UC] = (IB_QP_PKEY_INDEX |
285 IB_QP_PORT |
286 IB_QP_ACCESS_FLAGS),
287 [IB_QPT_RC] = (IB_QP_PKEY_INDEX |
288 IB_QP_PORT |
289 IB_QP_ACCESS_FLAGS),
290 [IB_QPT_SMI] = (IB_QP_PKEY_INDEX |
291 IB_QP_QKEY),
292 [IB_QPT_GSI] = (IB_QP_PKEY_INDEX |
293 IB_QP_QKEY),
294 }
295 },
296 [IB_QPS_RTR] = {
297 .valid = 1,
298 .req_param = {
299 [IB_QPT_UC] = (IB_QP_AV |
300 IB_QP_PATH_MTU |
301 IB_QP_DEST_QPN |
302 IB_QP_RQ_PSN),
303 [IB_QPT_RC] = (IB_QP_AV |
304 IB_QP_PATH_MTU |
305 IB_QP_DEST_QPN |
306 IB_QP_RQ_PSN |
307 IB_QP_MAX_DEST_RD_ATOMIC |
308 IB_QP_MIN_RNR_TIMER),
309 },
310 .opt_param = {
311 [IB_QPT_UD] = (IB_QP_PKEY_INDEX |
312 IB_QP_QKEY),
313 [IB_QPT_UC] = (IB_QP_ALT_PATH |
314 IB_QP_ACCESS_FLAGS |
315 IB_QP_PKEY_INDEX),
316 [IB_QPT_RC] = (IB_QP_ALT_PATH |
317 IB_QP_ACCESS_FLAGS |
318 IB_QP_PKEY_INDEX),
319 [IB_QPT_SMI] = (IB_QP_PKEY_INDEX |
320 IB_QP_QKEY),
321 [IB_QPT_GSI] = (IB_QP_PKEY_INDEX |
322 IB_QP_QKEY),
323 }
324 }
325 },
326 [IB_QPS_RTR] = {
327 [IB_QPS_RESET] = { .valid = 1 },
328 [IB_QPS_ERR] = { .valid = 1 },
329 [IB_QPS_RTS] = {
330 .valid = 1,
331 .req_param = {
332 [IB_QPT_UD] = IB_QP_SQ_PSN,
333 [IB_QPT_UC] = IB_QP_SQ_PSN,
334 [IB_QPT_RC] = (IB_QP_TIMEOUT |
335 IB_QP_RETRY_CNT |
336 IB_QP_RNR_RETRY |
337 IB_QP_SQ_PSN |
338 IB_QP_MAX_QP_RD_ATOMIC),
339 [IB_QPT_SMI] = IB_QP_SQ_PSN,
340 [IB_QPT_GSI] = IB_QP_SQ_PSN,
341 },
342 .opt_param = {
343 [IB_QPT_UD] = (IB_QP_CUR_STATE |
344 IB_QP_QKEY),
345 [IB_QPT_UC] = (IB_QP_CUR_STATE |
346 IB_QP_ALT_PATH |
347 IB_QP_ACCESS_FLAGS |
348 IB_QP_PATH_MIG_STATE),
349 [IB_QPT_RC] = (IB_QP_CUR_STATE |
350 IB_QP_ALT_PATH |
351 IB_QP_ACCESS_FLAGS |
352 IB_QP_MIN_RNR_TIMER |
353 IB_QP_PATH_MIG_STATE),
354 [IB_QPT_SMI] = (IB_QP_CUR_STATE |
355 IB_QP_QKEY),
356 [IB_QPT_GSI] = (IB_QP_CUR_STATE |
357 IB_QP_QKEY),
358 }
359 }
360 },
361 [IB_QPS_RTS] = {
362 [IB_QPS_RESET] = { .valid = 1 },
363 [IB_QPS_ERR] = { .valid = 1 },
364 [IB_QPS_RTS] = {
365 .valid = 1,
366 .opt_param = {
367 [IB_QPT_UD] = (IB_QP_CUR_STATE |
368 IB_QP_QKEY),
369 [IB_QPT_UC] = (IB_QP_CUR_STATE |
370 IB_QP_ACCESS_FLAGS |
371 IB_QP_ALT_PATH |
372 IB_QP_PATH_MIG_STATE),
373 [IB_QPT_RC] = (IB_QP_CUR_STATE |
374 IB_QP_ACCESS_FLAGS |
375 IB_QP_ALT_PATH |
376 IB_QP_PATH_MIG_STATE |
377 IB_QP_MIN_RNR_TIMER),
378 [IB_QPT_SMI] = (IB_QP_CUR_STATE |
379 IB_QP_QKEY),
380 [IB_QPT_GSI] = (IB_QP_CUR_STATE |
381 IB_QP_QKEY),
382 }
383 },
384 [IB_QPS_SQD] = {
385 .valid = 1,
386 .opt_param = {
387 [IB_QPT_UD] = IB_QP_EN_SQD_ASYNC_NOTIFY,
388 [IB_QPT_UC] = IB_QP_EN_SQD_ASYNC_NOTIFY,
389 [IB_QPT_RC] = IB_QP_EN_SQD_ASYNC_NOTIFY,
390 [IB_QPT_SMI] = IB_QP_EN_SQD_ASYNC_NOTIFY,
391 [IB_QPT_GSI] = IB_QP_EN_SQD_ASYNC_NOTIFY
392 }
393 },
394 },
395 [IB_QPS_SQD] = {
396 [IB_QPS_RESET] = { .valid = 1 },
397 [IB_QPS_ERR] = { .valid = 1 },
398 [IB_QPS_RTS] = {
399 .valid = 1,
400 .opt_param = {
401 [IB_QPT_UD] = (IB_QP_CUR_STATE |
402 IB_QP_QKEY),
403 [IB_QPT_UC] = (IB_QP_CUR_STATE |
404 IB_QP_ALT_PATH |
405 IB_QP_ACCESS_FLAGS |
406 IB_QP_PATH_MIG_STATE),
407 [IB_QPT_RC] = (IB_QP_CUR_STATE |
408 IB_QP_ALT_PATH |
409 IB_QP_ACCESS_FLAGS |
410 IB_QP_MIN_RNR_TIMER |
411 IB_QP_PATH_MIG_STATE),
412 [IB_QPT_SMI] = (IB_QP_CUR_STATE |
413 IB_QP_QKEY),
414 [IB_QPT_GSI] = (IB_QP_CUR_STATE |
415 IB_QP_QKEY),
416 }
417 },
418 [IB_QPS_SQD] = {
419 .valid = 1,
420 .opt_param = {
421 [IB_QPT_UD] = (IB_QP_PKEY_INDEX |
422 IB_QP_QKEY),
423 [IB_QPT_UC] = (IB_QP_AV |
424 IB_QP_ALT_PATH |
425 IB_QP_ACCESS_FLAGS |
426 IB_QP_PKEY_INDEX |
427 IB_QP_PATH_MIG_STATE),
428 [IB_QPT_RC] = (IB_QP_PORT |
429 IB_QP_AV |
430 IB_QP_TIMEOUT |
431 IB_QP_RETRY_CNT |
432 IB_QP_RNR_RETRY |
433 IB_QP_MAX_QP_RD_ATOMIC |
434 IB_QP_MAX_DEST_RD_ATOMIC |
435 IB_QP_ALT_PATH |
436 IB_QP_ACCESS_FLAGS |
437 IB_QP_PKEY_INDEX |
438 IB_QP_MIN_RNR_TIMER |
439 IB_QP_PATH_MIG_STATE),
440 [IB_QPT_SMI] = (IB_QP_PKEY_INDEX |
441 IB_QP_QKEY),
442 [IB_QPT_GSI] = (IB_QP_PKEY_INDEX |
443 IB_QP_QKEY),
444 }
445 }
446 },
447 [IB_QPS_SQE] = {
448 [IB_QPS_RESET] = { .valid = 1 },
449 [IB_QPS_ERR] = { .valid = 1 },
450 [IB_QPS_RTS] = {
451 .valid = 1,
452 .opt_param = {
453 [IB_QPT_UD] = (IB_QP_CUR_STATE |
454 IB_QP_QKEY),
455 [IB_QPT_UC] = (IB_QP_CUR_STATE |
456 IB_QP_ACCESS_FLAGS),
457 [IB_QPT_SMI] = (IB_QP_CUR_STATE |
458 IB_QP_QKEY),
459 [IB_QPT_GSI] = (IB_QP_CUR_STATE |
460 IB_QP_QKEY),
461 }
462 }
463 },
464 [IB_QPS_ERR] = {
465 [IB_QPS_RESET] = { .valid = 1 },
466 [IB_QPS_ERR] = { .valid = 1 }
467 }
468};
469
470int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
471 enum ib_qp_type type, enum ib_qp_attr_mask mask)
472{
473 enum ib_qp_attr_mask req_param, opt_param;
474
475 if (cur_state < 0 || cur_state > IB_QPS_ERR ||
476 next_state < 0 || next_state > IB_QPS_ERR)
477 return 0;
478
479 if (mask & IB_QP_CUR_STATE &&
480 cur_state != IB_QPS_RTR && cur_state != IB_QPS_RTS &&
481 cur_state != IB_QPS_SQD && cur_state != IB_QPS_SQE)
482 return 0;
483
484 if (!qp_state_table[cur_state][next_state].valid)
485 return 0;
486
487 req_param = qp_state_table[cur_state][next_state].req_param[type];
488 opt_param = qp_state_table[cur_state][next_state].opt_param[type];
489
490 if ((mask & req_param) != req_param)
491 return 0;
492
493 if (mask & ~(req_param | opt_param | IB_QP_STATE))
494 return 0;
495
496 return 1;
497}
498EXPORT_SYMBOL(ib_modify_qp_is_ok);
499
248int ib_modify_qp(struct ib_qp *qp, 500int ib_modify_qp(struct ib_qp *qp,
249 struct ib_qp_attr *qp_attr, 501 struct ib_qp_attr *qp_attr,
250 int qp_attr_mask) 502 int qp_attr_mask)
@@ -322,11 +574,10 @@ int ib_destroy_cq(struct ib_cq *cq)
322} 574}
323EXPORT_SYMBOL(ib_destroy_cq); 575EXPORT_SYMBOL(ib_destroy_cq);
324 576
325int ib_resize_cq(struct ib_cq *cq, 577int ib_resize_cq(struct ib_cq *cq, int cqe)
326 int cqe)
327{ 578{
328 return cq->device->resize_cq ? 579 return cq->device->resize_cq ?
329 cq->device->resize_cq(cq, cqe) : -ENOSYS; 580 cq->device->resize_cq(cq, cqe, NULL) : -ENOSYS;
330} 581}
331EXPORT_SYMBOL(ib_resize_cq); 582EXPORT_SYMBOL(ib_resize_cq);
332 583
diff --git a/drivers/infiniband/hw/mthca/mthca_av.c b/drivers/infiniband/hw/mthca/mthca_av.c
index a19e0ed03d7c..f023d3936518 100644
--- a/drivers/infiniband/hw/mthca/mthca_av.c
+++ b/drivers/infiniband/hw/mthca/mthca_av.c
@@ -147,7 +147,7 @@ int mthca_destroy_ah(struct mthca_dev *dev, struct mthca_ah *ah)
147 switch (ah->type) { 147 switch (ah->type) {
148 case MTHCA_AH_ON_HCA: 148 case MTHCA_AH_ON_HCA:
149 mthca_free(&dev->av_table.alloc, 149 mthca_free(&dev->av_table.alloc,
150 (ah->avdma - dev->av_table.ddr_av_base) / 150 (ah->avdma - dev->av_table.ddr_av_base) /
151 MTHCA_AV_SIZE); 151 MTHCA_AV_SIZE);
152 break; 152 break;
153 153
@@ -193,6 +193,37 @@ int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
193 return 0; 193 return 0;
194} 194}
195 195
196int mthca_ah_query(struct ib_ah *ibah, struct ib_ah_attr *attr)
197{
198 struct mthca_ah *ah = to_mah(ibah);
199 struct mthca_dev *dev = to_mdev(ibah->device);
200
201 /* Only implement for MAD and memfree ah for now. */
202 if (ah->type == MTHCA_AH_ON_HCA)
203 return -ENOSYS;
204
205 memset(attr, 0, sizeof *attr);
206 attr->dlid = be16_to_cpu(ah->av->dlid);
207 attr->sl = be32_to_cpu(ah->av->sl_tclass_flowlabel) >> 28;
208 attr->static_rate = ah->av->msg_sr & 0x7;
209 attr->src_path_bits = ah->av->g_slid & 0x7F;
210 attr->port_num = be32_to_cpu(ah->av->port_pd) >> 24;
211 attr->ah_flags = mthca_ah_grh_present(ah) ? IB_AH_GRH : 0;
212
213 if (attr->ah_flags) {
214 attr->grh.traffic_class =
215 be32_to_cpu(ah->av->sl_tclass_flowlabel) >> 20;
216 attr->grh.flow_label =
217 be32_to_cpu(ah->av->sl_tclass_flowlabel) & 0xfffff;
218 attr->grh.hop_limit = ah->av->hop_limit;
219 attr->grh.sgid_index = ah->av->gid_index &
220 (dev->limits.gid_table_len - 1);
221 memcpy(attr->grh.dgid.raw, ah->av->dgid, 16);
222 }
223
224 return 0;
225}
226
196int __devinit mthca_init_av_table(struct mthca_dev *dev) 227int __devinit mthca_init_av_table(struct mthca_dev *dev)
197{ 228{
198 int err; 229 int err;
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
index 2825615ce81c..343eca507870 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 3 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2005 Cisco Systems. All rights reserved. 4 * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
5 * 5 *
6 * This software is available to you under a choice of one of two 6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU 7 * licenses. You may choose to be licensed under the terms of the GNU
@@ -182,25 +182,58 @@ struct mthca_cmd_context {
182 u8 status; 182 u8 status;
183}; 183};
184 184
185static int fw_cmd_doorbell = 1;
186module_param(fw_cmd_doorbell, int, 0644);
187MODULE_PARM_DESC(fw_cmd_doorbell, "post FW commands through doorbell page if nonzero "
188 "(and supported by FW)");
189
185static inline int go_bit(struct mthca_dev *dev) 190static inline int go_bit(struct mthca_dev *dev)
186{ 191{
187 return readl(dev->hcr + HCR_STATUS_OFFSET) & 192 return readl(dev->hcr + HCR_STATUS_OFFSET) &
188 swab32(1 << HCR_GO_BIT); 193 swab32(1 << HCR_GO_BIT);
189} 194}
190 195
191static int mthca_cmd_post(struct mthca_dev *dev, 196static void mthca_cmd_post_dbell(struct mthca_dev *dev,
192 u64 in_param, 197 u64 in_param,
193 u64 out_param, 198 u64 out_param,
194 u32 in_modifier, 199 u32 in_modifier,
195 u8 op_modifier, 200 u8 op_modifier,
196 u16 op, 201 u16 op,
197 u16 token, 202 u16 token)
198 int event)
199{ 203{
200 int err = 0; 204 void __iomem *ptr = dev->cmd.dbell_map;
205 u16 *offs = dev->cmd.dbell_offsets;
201 206
202 mutex_lock(&dev->cmd.hcr_mutex); 207 __raw_writel((__force u32) cpu_to_be32(in_param >> 32), ptr + offs[0]);
208 wmb();
209 __raw_writel((__force u32) cpu_to_be32(in_param & 0xfffffffful), ptr + offs[1]);
210 wmb();
211 __raw_writel((__force u32) cpu_to_be32(in_modifier), ptr + offs[2]);
212 wmb();
213 __raw_writel((__force u32) cpu_to_be32(out_param >> 32), ptr + offs[3]);
214 wmb();
215 __raw_writel((__force u32) cpu_to_be32(out_param & 0xfffffffful), ptr + offs[4]);
216 wmb();
217 __raw_writel((__force u32) cpu_to_be32(token << 16), ptr + offs[5]);
218 wmb();
219 __raw_writel((__force u32) cpu_to_be32((1 << HCR_GO_BIT) |
220 (1 << HCA_E_BIT) |
221 (op_modifier << HCR_OPMOD_SHIFT) |
222 op), ptr + offs[6]);
223 wmb();
224 __raw_writel((__force u32) 0, ptr + offs[7]);
225 wmb();
226}
203 227
228static int mthca_cmd_post_hcr(struct mthca_dev *dev,
229 u64 in_param,
230 u64 out_param,
231 u32 in_modifier,
232 u8 op_modifier,
233 u16 op,
234 u16 token,
235 int event)
236{
204 if (event) { 237 if (event) {
205 unsigned long end = jiffies + GO_BIT_TIMEOUT; 238 unsigned long end = jiffies + GO_BIT_TIMEOUT;
206 239
@@ -210,10 +243,8 @@ static int mthca_cmd_post(struct mthca_dev *dev,
210 } 243 }
211 } 244 }
212 245
213 if (go_bit(dev)) { 246 if (go_bit(dev))
214 err = -EAGAIN; 247 return -EAGAIN;
215 goto out;
216 }
217 248
218 /* 249 /*
219 * We use writel (instead of something like memcpy_toio) 250 * We use writel (instead of something like memcpy_toio)
@@ -236,7 +267,29 @@ static int mthca_cmd_post(struct mthca_dev *dev,
236 (op_modifier << HCR_OPMOD_SHIFT) | 267 (op_modifier << HCR_OPMOD_SHIFT) |
237 op), dev->hcr + 6 * 4); 268 op), dev->hcr + 6 * 4);
238 269
239out: 270 return 0;
271}
272
273static int mthca_cmd_post(struct mthca_dev *dev,
274 u64 in_param,
275 u64 out_param,
276 u32 in_modifier,
277 u8 op_modifier,
278 u16 op,
279 u16 token,
280 int event)
281{
282 int err = 0;
283
284 mutex_lock(&dev->cmd.hcr_mutex);
285
286 if (event && dev->cmd.flags & MTHCA_CMD_POST_DOORBELLS && fw_cmd_doorbell)
287 mthca_cmd_post_dbell(dev, in_param, out_param, in_modifier,
288 op_modifier, op, token);
289 else
290 err = mthca_cmd_post_hcr(dev, in_param, out_param, in_modifier,
291 op_modifier, op, token, event);
292
240 mutex_unlock(&dev->cmd.hcr_mutex); 293 mutex_unlock(&dev->cmd.hcr_mutex);
241 return err; 294 return err;
242} 295}
@@ -275,7 +328,7 @@ static int mthca_cmd_poll(struct mthca_dev *dev,
275 } 328 }
276 329
277 if (out_is_imm) 330 if (out_is_imm)
278 *out_param = 331 *out_param =
279 (u64) be32_to_cpu((__force __be32) 332 (u64) be32_to_cpu((__force __be32)
280 __raw_readl(dev->hcr + HCR_OUT_PARAM_OFFSET)) << 32 | 333 __raw_readl(dev->hcr + HCR_OUT_PARAM_OFFSET)) << 32 |
281 (u64) be32_to_cpu((__force __be32) 334 (u64) be32_to_cpu((__force __be32)
@@ -386,7 +439,7 @@ static int mthca_cmd_box(struct mthca_dev *dev,
386 unsigned long timeout, 439 unsigned long timeout,
387 u8 *status) 440 u8 *status)
388{ 441{
389 if (dev->cmd.use_events) 442 if (dev->cmd.flags & MTHCA_CMD_USE_EVENTS)
390 return mthca_cmd_wait(dev, in_param, &out_param, 0, 443 return mthca_cmd_wait(dev, in_param, &out_param, 0,
391 in_modifier, op_modifier, op, 444 in_modifier, op_modifier, op,
392 timeout, status); 445 timeout, status);
@@ -423,7 +476,7 @@ static int mthca_cmd_imm(struct mthca_dev *dev,
423 unsigned long timeout, 476 unsigned long timeout,
424 u8 *status) 477 u8 *status)
425{ 478{
426 if (dev->cmd.use_events) 479 if (dev->cmd.flags & MTHCA_CMD_USE_EVENTS)
427 return mthca_cmd_wait(dev, in_param, out_param, 1, 480 return mthca_cmd_wait(dev, in_param, out_param, 1,
428 in_modifier, op_modifier, op, 481 in_modifier, op_modifier, op,
429 timeout, status); 482 timeout, status);
@@ -437,7 +490,7 @@ int mthca_cmd_init(struct mthca_dev *dev)
437{ 490{
438 mutex_init(&dev->cmd.hcr_mutex); 491 mutex_init(&dev->cmd.hcr_mutex);
439 sema_init(&dev->cmd.poll_sem, 1); 492 sema_init(&dev->cmd.poll_sem, 1);
440 dev->cmd.use_events = 0; 493 dev->cmd.flags = 0;
441 494
442 dev->hcr = ioremap(pci_resource_start(dev->pdev, 0) + MTHCA_HCR_BASE, 495 dev->hcr = ioremap(pci_resource_start(dev->pdev, 0) + MTHCA_HCR_BASE,
443 MTHCA_HCR_SIZE); 496 MTHCA_HCR_SIZE);
@@ -461,6 +514,8 @@ void mthca_cmd_cleanup(struct mthca_dev *dev)
461{ 514{
462 pci_pool_destroy(dev->cmd.pool); 515 pci_pool_destroy(dev->cmd.pool);
463 iounmap(dev->hcr); 516 iounmap(dev->hcr);
517 if (dev->cmd.flags & MTHCA_CMD_POST_DOORBELLS)
518 iounmap(dev->cmd.dbell_map);
464} 519}
465 520
466/* 521/*
@@ -498,7 +553,8 @@ int mthca_cmd_use_events(struct mthca_dev *dev)
498 ; /* nothing */ 553 ; /* nothing */
499 --dev->cmd.token_mask; 554 --dev->cmd.token_mask;
500 555
501 dev->cmd.use_events = 1; 556 dev->cmd.flags |= MTHCA_CMD_USE_EVENTS;
557
502 down(&dev->cmd.poll_sem); 558 down(&dev->cmd.poll_sem);
503 559
504 return 0; 560 return 0;
@@ -511,7 +567,7 @@ void mthca_cmd_use_polling(struct mthca_dev *dev)
511{ 567{
512 int i; 568 int i;
513 569
514 dev->cmd.use_events = 0; 570 dev->cmd.flags &= ~MTHCA_CMD_USE_EVENTS;
515 571
516 for (i = 0; i < dev->cmd.max_cmds; ++i) 572 for (i = 0; i < dev->cmd.max_cmds; ++i)
517 down(&dev->cmd.event_sem); 573 down(&dev->cmd.event_sem);
@@ -596,8 +652,9 @@ static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm,
596 * address or size and use that as our log2 size. 652 * address or size and use that as our log2 size.
597 */ 653 */
598 lg = ffs(mthca_icm_addr(&iter) | mthca_icm_size(&iter)) - 1; 654 lg = ffs(mthca_icm_addr(&iter) | mthca_icm_size(&iter)) - 1;
599 if (lg < 12) { 655 if (lg < MTHCA_ICM_PAGE_SHIFT) {
600 mthca_warn(dev, "Got FW area not aligned to 4K (%llx/%lx).\n", 656 mthca_warn(dev, "Got FW area not aligned to %d (%llx/%lx).\n",
657 MTHCA_ICM_PAGE_SIZE,
601 (unsigned long long) mthca_icm_addr(&iter), 658 (unsigned long long) mthca_icm_addr(&iter),
602 mthca_icm_size(&iter)); 659 mthca_icm_size(&iter));
603 err = -EINVAL; 660 err = -EINVAL;
@@ -609,8 +666,9 @@ static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm,
609 virt += 1 << lg; 666 virt += 1 << lg;
610 } 667 }
611 668
612 pages[nent * 2 + 1] = cpu_to_be64((mthca_icm_addr(&iter) + 669 pages[nent * 2 + 1] =
613 (i << lg)) | (lg - 12)); 670 cpu_to_be64((mthca_icm_addr(&iter) + (i << lg)) |
671 (lg - MTHCA_ICM_PAGE_SHIFT));
614 ts += 1 << (lg - 10); 672 ts += 1 << (lg - 10);
615 ++tc; 673 ++tc;
616 674
@@ -661,12 +719,41 @@ int mthca_RUN_FW(struct mthca_dev *dev, u8 *status)
661 return mthca_cmd(dev, 0, 0, 0, CMD_RUN_FW, CMD_TIME_CLASS_A, status); 719 return mthca_cmd(dev, 0, 0, 0, CMD_RUN_FW, CMD_TIME_CLASS_A, status);
662} 720}
663 721
722static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
723{
724 unsigned long addr;
725 u16 max_off = 0;
726 int i;
727
728 for (i = 0; i < 8; ++i)
729 max_off = max(max_off, dev->cmd.dbell_offsets[i]);
730
731 if ((base & PAGE_MASK) != ((base + max_off) & PAGE_MASK)) {
732 mthca_warn(dev, "Firmware doorbell region at 0x%016llx, "
733 "length 0x%x crosses a page boundary\n",
734 (unsigned long long) base, max_off);
735 return;
736 }
737
738 addr = pci_resource_start(dev->pdev, 2) +
739 ((pci_resource_len(dev->pdev, 2) - 1) & base);
740 dev->cmd.dbell_map = ioremap(addr, max_off + sizeof(u32));
741 if (!dev->cmd.dbell_map)
742 return;
743
744 dev->cmd.flags |= MTHCA_CMD_POST_DOORBELLS;
745 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
746}
747
664int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status) 748int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
665{ 749{
666 struct mthca_mailbox *mailbox; 750 struct mthca_mailbox *mailbox;
667 u32 *outbox; 751 u32 *outbox;
752 u64 base;
753 u32 tmp;
668 int err = 0; 754 int err = 0;
669 u8 lg; 755 u8 lg;
756 int i;
670 757
671#define QUERY_FW_OUT_SIZE 0x100 758#define QUERY_FW_OUT_SIZE 0x100
672#define QUERY_FW_VER_OFFSET 0x00 759#define QUERY_FW_VER_OFFSET 0x00
@@ -674,6 +761,10 @@ int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
674#define QUERY_FW_ERR_START_OFFSET 0x30 761#define QUERY_FW_ERR_START_OFFSET 0x30
675#define QUERY_FW_ERR_SIZE_OFFSET 0x38 762#define QUERY_FW_ERR_SIZE_OFFSET 0x38
676 763
764#define QUERY_FW_CMD_DB_EN_OFFSET 0x10
765#define QUERY_FW_CMD_DB_OFFSET 0x50
766#define QUERY_FW_CMD_DB_BASE 0x60
767
677#define QUERY_FW_START_OFFSET 0x20 768#define QUERY_FW_START_OFFSET 0x20
678#define QUERY_FW_END_OFFSET 0x28 769#define QUERY_FW_END_OFFSET 0x28
679 770
@@ -702,16 +793,29 @@ int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
702 ((dev->fw_ver & 0xffff0000ull) >> 16) | 793 ((dev->fw_ver & 0xffff0000ull) >> 16) |
703 ((dev->fw_ver & 0x0000ffffull) << 16); 794 ((dev->fw_ver & 0x0000ffffull) << 16);
704 795
796 mthca_dbg(dev, "FW version %012llx, max commands %d\n",
797 (unsigned long long) dev->fw_ver, dev->cmd.max_cmds);
798
705 MTHCA_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET); 799 MTHCA_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET);
706 dev->cmd.max_cmds = 1 << lg; 800 dev->cmd.max_cmds = 1 << lg;
707 MTHCA_GET(dev->catas_err.addr, outbox, QUERY_FW_ERR_START_OFFSET); 801 MTHCA_GET(dev->catas_err.addr, outbox, QUERY_FW_ERR_START_OFFSET);
708 MTHCA_GET(dev->catas_err.size, outbox, QUERY_FW_ERR_SIZE_OFFSET); 802 MTHCA_GET(dev->catas_err.size, outbox, QUERY_FW_ERR_SIZE_OFFSET);
709 803
710 mthca_dbg(dev, "FW version %012llx, max commands %d\n",
711 (unsigned long long) dev->fw_ver, dev->cmd.max_cmds);
712 mthca_dbg(dev, "Catastrophic error buffer at 0x%llx, size 0x%x\n", 804 mthca_dbg(dev, "Catastrophic error buffer at 0x%llx, size 0x%x\n",
713 (unsigned long long) dev->catas_err.addr, dev->catas_err.size); 805 (unsigned long long) dev->catas_err.addr, dev->catas_err.size);
714 806
807 MTHCA_GET(tmp, outbox, QUERY_FW_CMD_DB_EN_OFFSET);
808 if (tmp & 0x1) {
809 mthca_dbg(dev, "FW supports commands through doorbells\n");
810
811 MTHCA_GET(base, outbox, QUERY_FW_CMD_DB_BASE);
812 for (i = 0; i < MTHCA_CMD_NUM_DBELL_DWORDS; ++i)
813 MTHCA_GET(dev->cmd.dbell_offsets[i], outbox,
814 QUERY_FW_CMD_DB_OFFSET + (i << 1));
815
816 mthca_setup_cmd_doorbells(dev, base);
817 }
818
715 if (mthca_is_memfree(dev)) { 819 if (mthca_is_memfree(dev)) {
716 MTHCA_GET(dev->fw.arbel.fw_pages, outbox, QUERY_FW_SIZE_OFFSET); 820 MTHCA_GET(dev->fw.arbel.fw_pages, outbox, QUERY_FW_SIZE_OFFSET);
717 MTHCA_GET(dev->fw.arbel.clr_int_base, outbox, QUERY_FW_CLR_INT_BASE_OFFSET); 821 MTHCA_GET(dev->fw.arbel.clr_int_base, outbox, QUERY_FW_CLR_INT_BASE_OFFSET);
@@ -720,12 +824,12 @@ int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
720 mthca_dbg(dev, "FW size %d KB\n", dev->fw.arbel.fw_pages << 2); 824 mthca_dbg(dev, "FW size %d KB\n", dev->fw.arbel.fw_pages << 2);
721 825
722 /* 826 /*
723 * Arbel page size is always 4 KB; round up number of 827 * Round up number of system pages needed in case
724 * system pages needed. 828 * MTHCA_ICM_PAGE_SIZE < PAGE_SIZE.
725 */ 829 */
726 dev->fw.arbel.fw_pages = 830 dev->fw.arbel.fw_pages =
727 ALIGN(dev->fw.arbel.fw_pages, PAGE_SIZE >> 12) >> 831 ALIGN(dev->fw.arbel.fw_pages, PAGE_SIZE / MTHCA_ICM_PAGE_SIZE) >>
728 (PAGE_SHIFT - 12); 832 (PAGE_SHIFT - MTHCA_ICM_PAGE_SHIFT);
729 833
730 mthca_dbg(dev, "Clear int @ %llx, EQ arm @ %llx, EQ set CI @ %llx\n", 834 mthca_dbg(dev, "Clear int @ %llx, EQ arm @ %llx, EQ set CI @ %llx\n",
731 (unsigned long long) dev->fw.arbel.clr_int_base, 835 (unsigned long long) dev->fw.arbel.clr_int_base,
@@ -1173,7 +1277,8 @@ int mthca_INIT_HCA(struct mthca_dev *dev,
1173 int err; 1277 int err;
1174 1278
1175#define INIT_HCA_IN_SIZE 0x200 1279#define INIT_HCA_IN_SIZE 0x200
1176#define INIT_HCA_FLAGS_OFFSET 0x014 1280#define INIT_HCA_FLAGS1_OFFSET 0x00c
1281#define INIT_HCA_FLAGS2_OFFSET 0x014
1177#define INIT_HCA_QPC_OFFSET 0x020 1282#define INIT_HCA_QPC_OFFSET 0x020
1178#define INIT_HCA_QPC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x10) 1283#define INIT_HCA_QPC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x10)
1179#define INIT_HCA_LOG_QP_OFFSET (INIT_HCA_QPC_OFFSET + 0x17) 1284#define INIT_HCA_LOG_QP_OFFSET (INIT_HCA_QPC_OFFSET + 0x17)
@@ -1216,15 +1321,18 @@ int mthca_INIT_HCA(struct mthca_dev *dev,
1216 1321
1217 memset(inbox, 0, INIT_HCA_IN_SIZE); 1322 memset(inbox, 0, INIT_HCA_IN_SIZE);
1218 1323
1324 if (dev->mthca_flags & MTHCA_FLAG_SINAI_OPT)
1325 MTHCA_PUT(inbox, 0x1, INIT_HCA_FLAGS1_OFFSET);
1326
1219#if defined(__LITTLE_ENDIAN) 1327#if defined(__LITTLE_ENDIAN)
1220 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) &= ~cpu_to_be32(1 << 1); 1328 *(inbox + INIT_HCA_FLAGS2_OFFSET / 4) &= ~cpu_to_be32(1 << 1);
1221#elif defined(__BIG_ENDIAN) 1329#elif defined(__BIG_ENDIAN)
1222 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 1); 1330 *(inbox + INIT_HCA_FLAGS2_OFFSET / 4) |= cpu_to_be32(1 << 1);
1223#else 1331#else
1224#error Host endianness not defined 1332#error Host endianness not defined
1225#endif 1333#endif
1226 /* Check port for UD address vector: */ 1334 /* Check port for UD address vector: */
1227 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1); 1335 *(inbox + INIT_HCA_FLAGS2_OFFSET / 4) |= cpu_to_be32(1);
1228 1336
1229 /* We leave wqe_quota, responder_exu, etc as 0 (default) */ 1337 /* We leave wqe_quota, responder_exu, etc as 0 (default) */
1230 1338
@@ -1438,11 +1546,11 @@ int mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages,
1438 return ret; 1546 return ret;
1439 1547
1440 /* 1548 /*
1441 * Arbel page size is always 4 KB; round up number of system 1549 * Round up number of system pages needed in case
1442 * pages needed. 1550 * MTHCA_ICM_PAGE_SIZE < PAGE_SIZE.
1443 */ 1551 */
1444 *aux_pages = (*aux_pages + (1 << (PAGE_SHIFT - 12)) - 1) >> (PAGE_SHIFT - 12); 1552 *aux_pages = ALIGN(*aux_pages, PAGE_SIZE / MTHCA_ICM_PAGE_SIZE) >>
1445 *aux_pages = ALIGN(*aux_pages, PAGE_SIZE >> 12) >> (PAGE_SHIFT - 12); 1553 (PAGE_SHIFT - MTHCA_ICM_PAGE_SHIFT);
1446 1554
1447 return 0; 1555 return 0;
1448} 1556}
@@ -1514,6 +1622,37 @@ int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1514 CMD_TIME_CLASS_A, status); 1622 CMD_TIME_CLASS_A, status);
1515} 1623}
1516 1624
1625int mthca_RESIZE_CQ(struct mthca_dev *dev, int cq_num, u32 lkey, u8 log_size,
1626 u8 *status)
1627{
1628 struct mthca_mailbox *mailbox;
1629 __be32 *inbox;
1630 int err;
1631
1632#define RESIZE_CQ_IN_SIZE 0x40
1633#define RESIZE_CQ_LOG_SIZE_OFFSET 0x0c
1634#define RESIZE_CQ_LKEY_OFFSET 0x1c
1635
1636 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1637 if (IS_ERR(mailbox))
1638 return PTR_ERR(mailbox);
1639 inbox = mailbox->buf;
1640
1641 memset(inbox, 0, RESIZE_CQ_IN_SIZE);
1642 /*
1643 * Leave start address fields zeroed out -- mthca assumes that
1644 * MRs for CQs always start at virtual address 0.
1645 */
1646 MTHCA_PUT(inbox, log_size, RESIZE_CQ_LOG_SIZE_OFFSET);
1647 MTHCA_PUT(inbox, lkey, RESIZE_CQ_LKEY_OFFSET);
1648
1649 err = mthca_cmd(dev, mailbox->dma, cq_num, 1, CMD_RESIZE_CQ,
1650 CMD_TIME_CLASS_B, status);
1651
1652 mthca_free_mailbox(dev, mailbox);
1653 return err;
1654}
1655
1517int mthca_SW2HW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 1656int mthca_SW2HW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1518 int srq_num, u8 *status) 1657 int srq_num, u8 *status)
1519{ 1658{
@@ -1529,37 +1668,69 @@ int mthca_HW2SW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1529 CMD_TIME_CLASS_A, status); 1668 CMD_TIME_CLASS_A, status);
1530} 1669}
1531 1670
1671int mthca_QUERY_SRQ(struct mthca_dev *dev, u32 num,
1672 struct mthca_mailbox *mailbox, u8 *status)
1673{
1674 return mthca_cmd_box(dev, 0, mailbox->dma, num, 0,
1675 CMD_QUERY_SRQ, CMD_TIME_CLASS_A, status);
1676}
1677
1532int mthca_ARM_SRQ(struct mthca_dev *dev, int srq_num, int limit, u8 *status) 1678int mthca_ARM_SRQ(struct mthca_dev *dev, int srq_num, int limit, u8 *status)
1533{ 1679{
1534 return mthca_cmd(dev, limit, srq_num, 0, CMD_ARM_SRQ, 1680 return mthca_cmd(dev, limit, srq_num, 0, CMD_ARM_SRQ,
1535 CMD_TIME_CLASS_B, status); 1681 CMD_TIME_CLASS_B, status);
1536} 1682}
1537 1683
1538int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num, 1684int mthca_MODIFY_QP(struct mthca_dev *dev, enum ib_qp_state cur,
1539 int is_ee, struct mthca_mailbox *mailbox, u32 optmask, 1685 enum ib_qp_state next, u32 num, int is_ee,
1686 struct mthca_mailbox *mailbox, u32 optmask,
1540 u8 *status) 1687 u8 *status)
1541{ 1688{
1542 static const u16 op[] = { 1689 static const u16 op[IB_QPS_ERR + 1][IB_QPS_ERR + 1] = {
1543 [MTHCA_TRANS_RST2INIT] = CMD_RST2INIT_QPEE, 1690 [IB_QPS_RESET] = {
1544 [MTHCA_TRANS_INIT2INIT] = CMD_INIT2INIT_QPEE, 1691 [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
1545 [MTHCA_TRANS_INIT2RTR] = CMD_INIT2RTR_QPEE, 1692 [IB_QPS_ERR] = CMD_2ERR_QPEE,
1546 [MTHCA_TRANS_RTR2RTS] = CMD_RTR2RTS_QPEE, 1693 [IB_QPS_INIT] = CMD_RST2INIT_QPEE,
1547 [MTHCA_TRANS_RTS2RTS] = CMD_RTS2RTS_QPEE, 1694 },
1548 [MTHCA_TRANS_SQERR2RTS] = CMD_SQERR2RTS_QPEE, 1695 [IB_QPS_INIT] = {
1549 [MTHCA_TRANS_ANY2ERR] = CMD_2ERR_QPEE, 1696 [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
1550 [MTHCA_TRANS_RTS2SQD] = CMD_RTS2SQD_QPEE, 1697 [IB_QPS_ERR] = CMD_2ERR_QPEE,
1551 [MTHCA_TRANS_SQD2SQD] = CMD_SQD2SQD_QPEE, 1698 [IB_QPS_INIT] = CMD_INIT2INIT_QPEE,
1552 [MTHCA_TRANS_SQD2RTS] = CMD_SQD2RTS_QPEE, 1699 [IB_QPS_RTR] = CMD_INIT2RTR_QPEE,
1553 [MTHCA_TRANS_ANY2RST] = CMD_ERR2RST_QPEE 1700 },
1701 [IB_QPS_RTR] = {
1702 [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
1703 [IB_QPS_ERR] = CMD_2ERR_QPEE,
1704 [IB_QPS_RTS] = CMD_RTR2RTS_QPEE,
1705 },
1706 [IB_QPS_RTS] = {
1707 [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
1708 [IB_QPS_ERR] = CMD_2ERR_QPEE,
1709 [IB_QPS_RTS] = CMD_RTS2RTS_QPEE,
1710 [IB_QPS_SQD] = CMD_RTS2SQD_QPEE,
1711 },
1712 [IB_QPS_SQD] = {
1713 [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
1714 [IB_QPS_ERR] = CMD_2ERR_QPEE,
1715 [IB_QPS_RTS] = CMD_SQD2RTS_QPEE,
1716 [IB_QPS_SQD] = CMD_SQD2SQD_QPEE,
1717 },
1718 [IB_QPS_SQE] = {
1719 [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
1720 [IB_QPS_ERR] = CMD_2ERR_QPEE,
1721 [IB_QPS_RTS] = CMD_SQERR2RTS_QPEE,
1722 },
1723 [IB_QPS_ERR] = {
1724 [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
1725 [IB_QPS_ERR] = CMD_2ERR_QPEE,
1726 }
1554 }; 1727 };
1728
1555 u8 op_mod = 0; 1729 u8 op_mod = 0;
1556 int my_mailbox = 0; 1730 int my_mailbox = 0;
1557 int err; 1731 int err;
1558 1732
1559 if (trans < 0 || trans >= ARRAY_SIZE(op)) 1733 if (op[cur][next] == CMD_ERR2RST_QPEE) {
1560 return -EINVAL;
1561
1562 if (trans == MTHCA_TRANS_ANY2RST) {
1563 op_mod = 3; /* don't write outbox, any->reset */ 1734 op_mod = 3; /* don't write outbox, any->reset */
1564 1735
1565 /* For debugging */ 1736 /* For debugging */
@@ -1571,34 +1742,35 @@ int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,
1571 } else 1742 } else
1572 mailbox = NULL; 1743 mailbox = NULL;
1573 } 1744 }
1574 } else { 1745
1575 if (0) { 1746 err = mthca_cmd_box(dev, 0, mailbox ? mailbox->dma : 0,
1747 (!!is_ee << 24) | num, op_mod,
1748 op[cur][next], CMD_TIME_CLASS_C, status);
1749
1750 if (0 && mailbox) {
1576 int i; 1751 int i;
1577 mthca_dbg(dev, "Dumping QP context:\n"); 1752 mthca_dbg(dev, "Dumping QP context:\n");
1578 printk(" opt param mask: %08x\n", be32_to_cpup(mailbox->buf)); 1753 printk(" %08x\n", be32_to_cpup(mailbox->buf));
1579 for (i = 0; i < 0x100 / 4; ++i) { 1754 for (i = 0; i < 0x100 / 4; ++i) {
1580 if (i % 8 == 0) 1755 if (i % 8 == 0)
1581 printk(" [%02x] ", i * 4); 1756 printk("[%02x] ", i * 4);
1582 printk(" %08x", 1757 printk(" %08x",
1583 be32_to_cpu(((__be32 *) mailbox->buf)[i + 2])); 1758 be32_to_cpu(((__be32 *) mailbox->buf)[i + 2]));
1584 if ((i + 1) % 8 == 0) 1759 if ((i + 1) % 8 == 0)
1585 printk("\n"); 1760 printk("\n");
1586 } 1761 }
1587 } 1762 }
1588 }
1589
1590 if (trans == MTHCA_TRANS_ANY2RST) {
1591 err = mthca_cmd_box(dev, 0, mailbox ? mailbox->dma : 0,
1592 (!!is_ee << 24) | num, op_mod,
1593 op[trans], CMD_TIME_CLASS_C, status);
1594 1763
1595 if (0 && mailbox) { 1764 if (my_mailbox)
1765 mthca_free_mailbox(dev, mailbox);
1766 } else {
1767 if (0) {
1596 int i; 1768 int i;
1597 mthca_dbg(dev, "Dumping QP context:\n"); 1769 mthca_dbg(dev, "Dumping QP context:\n");
1598 printk(" %08x\n", be32_to_cpup(mailbox->buf)); 1770 printk(" opt param mask: %08x\n", be32_to_cpup(mailbox->buf));
1599 for (i = 0; i < 0x100 / 4; ++i) { 1771 for (i = 0; i < 0x100 / 4; ++i) {
1600 if (i % 8 == 0) 1772 if (i % 8 == 0)
1601 printk("[%02x] ", i * 4); 1773 printk(" [%02x] ", i * 4);
1602 printk(" %08x", 1774 printk(" %08x",
1603 be32_to_cpu(((__be32 *) mailbox->buf)[i + 2])); 1775 be32_to_cpu(((__be32 *) mailbox->buf)[i + 2]));
1604 if ((i + 1) % 8 == 0) 1776 if ((i + 1) % 8 == 0)
@@ -1606,12 +1778,9 @@ int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,
1606 } 1778 }
1607 } 1779 }
1608 1780
1609 } else 1781 err = mthca_cmd(dev, mailbox->dma, optmask | (!!is_ee << 24) | num,
1610 err = mthca_cmd(dev, mailbox->dma, (!!is_ee << 24) | num, 1782 op_mod, op[cur][next], CMD_TIME_CLASS_C, status);
1611 op_mod, op[trans], CMD_TIME_CLASS_C, status); 1783 }
1612
1613 if (my_mailbox)
1614 mthca_free_mailbox(dev, mailbox);
1615 1784
1616 return err; 1785 return err;
1617} 1786}
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.h b/drivers/infiniband/hw/mthca/mthca_cmd.h
index 18175bec84c2..e4ec35c40dd3 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.h
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.h
@@ -1,6 +1,7 @@
1/* 1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 3 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2006 Cisco Systems. All rights reserved.
4 * 5 *
5 * This software is available to you under a choice of one of two 6 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 7 * licenses. You may choose to be licensed under the terms of the GNU
@@ -73,9 +74,9 @@ enum {
73 MTHCA_CMD_STAT_REG_BOUND = 0x21, 74 MTHCA_CMD_STAT_REG_BOUND = 0x21,
74 /* HCA local attached memory not present: */ 75 /* HCA local attached memory not present: */
75 MTHCA_CMD_STAT_LAM_NOT_PRE = 0x22, 76 MTHCA_CMD_STAT_LAM_NOT_PRE = 0x22,
76 /* Bad management packet (silently discarded): */ 77 /* Bad management packet (silently discarded): */
77 MTHCA_CMD_STAT_BAD_PKT = 0x30, 78 MTHCA_CMD_STAT_BAD_PKT = 0x30,
78 /* More outstanding CQEs in CQ than new CQ size: */ 79 /* More outstanding CQEs in CQ than new CQ size: */
79 MTHCA_CMD_STAT_BAD_SIZE = 0x40 80 MTHCA_CMD_STAT_BAD_SIZE = 0x40
80}; 81};
81 82
@@ -298,13 +299,18 @@ int mthca_SW2HW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
298 int cq_num, u8 *status); 299 int cq_num, u8 *status);
299int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 300int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
300 int cq_num, u8 *status); 301 int cq_num, u8 *status);
302int mthca_RESIZE_CQ(struct mthca_dev *dev, int cq_num, u32 lkey, u8 log_size,
303 u8 *status);
301int mthca_SW2HW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 304int mthca_SW2HW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
302 int srq_num, u8 *status); 305 int srq_num, u8 *status);
303int mthca_HW2SW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 306int mthca_HW2SW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
304 int srq_num, u8 *status); 307 int srq_num, u8 *status);
308int mthca_QUERY_SRQ(struct mthca_dev *dev, u32 num,
309 struct mthca_mailbox *mailbox, u8 *status);
305int mthca_ARM_SRQ(struct mthca_dev *dev, int srq_num, int limit, u8 *status); 310int mthca_ARM_SRQ(struct mthca_dev *dev, int srq_num, int limit, u8 *status);
306int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num, 311int mthca_MODIFY_QP(struct mthca_dev *dev, enum ib_qp_state cur,
307 int is_ee, struct mthca_mailbox *mailbox, u32 optmask, 312 enum ib_qp_state next, u32 num, int is_ee,
313 struct mthca_mailbox *mailbox, u32 optmask,
308 u8 *status); 314 u8 *status);
309int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee, 315int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee,
310 struct mthca_mailbox *mailbox, u8 *status); 316 struct mthca_mailbox *mailbox, u8 *status);
diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
index 96f1a86bf049..76aabc5bf371 100644
--- a/drivers/infiniband/hw/mthca/mthca_cq.c
+++ b/drivers/infiniband/hw/mthca/mthca_cq.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. 3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2005 Cisco Systems, Inc. All rights reserved. 4 * Copyright (c) 2005, 2006 Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 5 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
6 * Copyright (c) 2004 Voltaire, Inc. All rights reserved. 6 * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
7 * 7 *
@@ -150,24 +150,29 @@ struct mthca_err_cqe {
150#define MTHCA_ARBEL_CQ_DB_REQ_NOT (2 << 24) 150#define MTHCA_ARBEL_CQ_DB_REQ_NOT (2 << 24)
151#define MTHCA_ARBEL_CQ_DB_REQ_NOT_MULT (3 << 24) 151#define MTHCA_ARBEL_CQ_DB_REQ_NOT_MULT (3 << 24)
152 152
153static inline struct mthca_cqe *get_cqe(struct mthca_cq *cq, int entry) 153static inline struct mthca_cqe *get_cqe_from_buf(struct mthca_cq_buf *buf,
154 int entry)
154{ 155{
155 if (cq->is_direct) 156 if (buf->is_direct)
156 return cq->queue.direct.buf + (entry * MTHCA_CQ_ENTRY_SIZE); 157 return buf->queue.direct.buf + (entry * MTHCA_CQ_ENTRY_SIZE);
157 else 158 else
158 return cq->queue.page_list[entry * MTHCA_CQ_ENTRY_SIZE / PAGE_SIZE].buf 159 return buf->queue.page_list[entry * MTHCA_CQ_ENTRY_SIZE / PAGE_SIZE].buf
159 + (entry * MTHCA_CQ_ENTRY_SIZE) % PAGE_SIZE; 160 + (entry * MTHCA_CQ_ENTRY_SIZE) % PAGE_SIZE;
160} 161}
161 162
162static inline struct mthca_cqe *cqe_sw(struct mthca_cq *cq, int i) 163static inline struct mthca_cqe *get_cqe(struct mthca_cq *cq, int entry)
164{
165 return get_cqe_from_buf(&cq->buf, entry);
166}
167
168static inline struct mthca_cqe *cqe_sw(struct mthca_cqe *cqe)
163{ 169{
164 struct mthca_cqe *cqe = get_cqe(cq, i);
165 return MTHCA_CQ_ENTRY_OWNER_HW & cqe->owner ? NULL : cqe; 170 return MTHCA_CQ_ENTRY_OWNER_HW & cqe->owner ? NULL : cqe;
166} 171}
167 172
168static inline struct mthca_cqe *next_cqe_sw(struct mthca_cq *cq) 173static inline struct mthca_cqe *next_cqe_sw(struct mthca_cq *cq)
169{ 174{
170 return cqe_sw(cq, cq->cons_index & cq->ibcq.cqe); 175 return cqe_sw(get_cqe(cq, cq->cons_index & cq->ibcq.cqe));
171} 176}
172 177
173static inline void set_cqe_hw(struct mthca_cqe *cqe) 178static inline void set_cqe_hw(struct mthca_cqe *cqe)
@@ -289,7 +294,7 @@ void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn,
289 * from our QP and therefore don't need to be checked. 294 * from our QP and therefore don't need to be checked.
290 */ 295 */
291 for (prod_index = cq->cons_index; 296 for (prod_index = cq->cons_index;
292 cqe_sw(cq, prod_index & cq->ibcq.cqe); 297 cqe_sw(get_cqe(cq, prod_index & cq->ibcq.cqe));
293 ++prod_index) 298 ++prod_index)
294 if (prod_index == cq->cons_index + cq->ibcq.cqe) 299 if (prod_index == cq->cons_index + cq->ibcq.cqe)
295 break; 300 break;
@@ -324,12 +329,58 @@ void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn,
324 wake_up(&cq->wait); 329 wake_up(&cq->wait);
325} 330}
326 331
327static int handle_error_cqe(struct mthca_dev *dev, struct mthca_cq *cq, 332void mthca_cq_resize_copy_cqes(struct mthca_cq *cq)
328 struct mthca_qp *qp, int wqe_index, int is_send, 333{
329 struct mthca_err_cqe *cqe, 334 int i;
330 struct ib_wc *entry, int *free_cqe) 335
336 /*
337 * In Tavor mode, the hardware keeps the consumer and producer
338 * indices mod the CQ size. Since we might be making the CQ
339 * bigger, we need to deal with the case where the producer
340 * index wrapped around before the CQ was resized.
341 */
342 if (!mthca_is_memfree(to_mdev(cq->ibcq.device)) &&
343 cq->ibcq.cqe < cq->resize_buf->cqe) {
344 cq->cons_index &= cq->ibcq.cqe;
345 if (cqe_sw(get_cqe(cq, cq->ibcq.cqe)))
346 cq->cons_index -= cq->ibcq.cqe + 1;
347 }
348
349 for (i = cq->cons_index; cqe_sw(get_cqe(cq, i & cq->ibcq.cqe)); ++i)
350 memcpy(get_cqe_from_buf(&cq->resize_buf->buf,
351 i & cq->resize_buf->cqe),
352 get_cqe(cq, i & cq->ibcq.cqe), MTHCA_CQ_ENTRY_SIZE);
353}
354
355int mthca_alloc_cq_buf(struct mthca_dev *dev, struct mthca_cq_buf *buf, int nent)
356{
357 int ret;
358 int i;
359
360 ret = mthca_buf_alloc(dev, nent * MTHCA_CQ_ENTRY_SIZE,
361 MTHCA_MAX_DIRECT_CQ_SIZE,
362 &buf->queue, &buf->is_direct,
363 &dev->driver_pd, 1, &buf->mr);
364 if (ret)
365 return ret;
366
367 for (i = 0; i < nent; ++i)
368 set_cqe_hw(get_cqe_from_buf(buf, i));
369
370 return 0;
371}
372
373void mthca_free_cq_buf(struct mthca_dev *dev, struct mthca_cq_buf *buf, int cqe)
374{
375 mthca_buf_free(dev, (cqe + 1) * MTHCA_CQ_ENTRY_SIZE, &buf->queue,
376 buf->is_direct, &buf->mr);
377}
378
379static void handle_error_cqe(struct mthca_dev *dev, struct mthca_cq *cq,
380 struct mthca_qp *qp, int wqe_index, int is_send,
381 struct mthca_err_cqe *cqe,
382 struct ib_wc *entry, int *free_cqe)
331{ 383{
332 int err;
333 int dbd; 384 int dbd;
334 __be32 new_wqe; 385 __be32 new_wqe;
335 386
@@ -412,11 +463,9 @@ static int handle_error_cqe(struct mthca_dev *dev, struct mthca_cq *cq,
412 * error case, so we don't have to check the doorbell count, etc. 463 * error case, so we don't have to check the doorbell count, etc.
413 */ 464 */
414 if (mthca_is_memfree(dev)) 465 if (mthca_is_memfree(dev))
415 return 0; 466 return;
416 467
417 err = mthca_free_err_wqe(dev, qp, is_send, wqe_index, &dbd, &new_wqe); 468 mthca_free_err_wqe(dev, qp, is_send, wqe_index, &dbd, &new_wqe);
418 if (err)
419 return err;
420 469
421 /* 470 /*
422 * If we're at the end of the WQE chain, or we've used up our 471 * If we're at the end of the WQE chain, or we've used up our
@@ -424,15 +473,13 @@ static int handle_error_cqe(struct mthca_dev *dev, struct mthca_cq *cq,
424 * the next poll operation. 473 * the next poll operation.
425 */ 474 */
426 if (!(new_wqe & cpu_to_be32(0x3f)) || (!cqe->db_cnt && dbd)) 475 if (!(new_wqe & cpu_to_be32(0x3f)) || (!cqe->db_cnt && dbd))
427 return 0; 476 return;
428 477
429 cqe->db_cnt = cpu_to_be16(be16_to_cpu(cqe->db_cnt) - dbd); 478 cqe->db_cnt = cpu_to_be16(be16_to_cpu(cqe->db_cnt) - dbd);
430 cqe->wqe = new_wqe; 479 cqe->wqe = new_wqe;
431 cqe->syndrome = SYNDROME_WR_FLUSH_ERR; 480 cqe->syndrome = SYNDROME_WR_FLUSH_ERR;
432 481
433 *free_cqe = 0; 482 *free_cqe = 0;
434
435 return 0;
436} 483}
437 484
438static inline int mthca_poll_one(struct mthca_dev *dev, 485static inline int mthca_poll_one(struct mthca_dev *dev,
@@ -518,9 +565,9 @@ static inline int mthca_poll_one(struct mthca_dev *dev,
518 } 565 }
519 566
520 if (is_error) { 567 if (is_error) {
521 err = handle_error_cqe(dev, cq, *cur_qp, wqe_index, is_send, 568 handle_error_cqe(dev, cq, *cur_qp, wqe_index, is_send,
522 (struct mthca_err_cqe *) cqe, 569 (struct mthca_err_cqe *) cqe,
523 entry, &free_cqe); 570 entry, &free_cqe);
524 goto out; 571 goto out;
525 } 572 }
526 573
@@ -614,11 +661,14 @@ int mthca_poll_cq(struct ib_cq *ibcq, int num_entries,
614 661
615 spin_lock_irqsave(&cq->lock, flags); 662 spin_lock_irqsave(&cq->lock, flags);
616 663
617 for (npolled = 0; npolled < num_entries; ++npolled) { 664 npolled = 0;
665repoll:
666 while (npolled < num_entries) {
618 err = mthca_poll_one(dev, cq, &qp, 667 err = mthca_poll_one(dev, cq, &qp,
619 &freed, entry + npolled); 668 &freed, entry + npolled);
620 if (err) 669 if (err)
621 break; 670 break;
671 ++npolled;
622 } 672 }
623 673
624 if (freed) { 674 if (freed) {
@@ -626,6 +676,42 @@ int mthca_poll_cq(struct ib_cq *ibcq, int num_entries,
626 update_cons_index(dev, cq, freed); 676 update_cons_index(dev, cq, freed);
627 } 677 }
628 678
679 /*
680 * If a CQ resize is in progress and we discovered that the
681 * old buffer is empty, then peek in the new buffer, and if
682 * it's not empty, switch to the new buffer and continue
683 * polling there.
684 */
685 if (unlikely(err == -EAGAIN && cq->resize_buf &&
686 cq->resize_buf->state == CQ_RESIZE_READY)) {
687 /*
688 * In Tavor mode, the hardware keeps the producer
689 * index modulo the CQ size. Since we might be making
690 * the CQ bigger, we need to mask our consumer index
691 * using the size of the old CQ buffer before looking
692 * in the new CQ buffer.
693 */
694 if (!mthca_is_memfree(dev))
695 cq->cons_index &= cq->ibcq.cqe;
696
697 if (cqe_sw(get_cqe_from_buf(&cq->resize_buf->buf,
698 cq->cons_index & cq->resize_buf->cqe))) {
699 struct mthca_cq_buf tbuf;
700 int tcqe;
701
702 tbuf = cq->buf;
703 tcqe = cq->ibcq.cqe;
704 cq->buf = cq->resize_buf->buf;
705 cq->ibcq.cqe = cq->resize_buf->cqe;
706
707 cq->resize_buf->buf = tbuf;
708 cq->resize_buf->cqe = tcqe;
709 cq->resize_buf->state = CQ_RESIZE_SWAPPED;
710
711 goto repoll;
712 }
713 }
714
629 spin_unlock_irqrestore(&cq->lock, flags); 715 spin_unlock_irqrestore(&cq->lock, flags);
630 716
631 return err == 0 || err == -EAGAIN ? npolled : err; 717 return err == 0 || err == -EAGAIN ? npolled : err;
@@ -684,24 +770,14 @@ int mthca_arbel_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify notify)
684 return 0; 770 return 0;
685} 771}
686 772
687static void mthca_free_cq_buf(struct mthca_dev *dev, struct mthca_cq *cq)
688{
689 mthca_buf_free(dev, (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE,
690 &cq->queue, cq->is_direct, &cq->mr);
691}
692
693int mthca_init_cq(struct mthca_dev *dev, int nent, 773int mthca_init_cq(struct mthca_dev *dev, int nent,
694 struct mthca_ucontext *ctx, u32 pdn, 774 struct mthca_ucontext *ctx, u32 pdn,
695 struct mthca_cq *cq) 775 struct mthca_cq *cq)
696{ 776{
697 int size = nent * MTHCA_CQ_ENTRY_SIZE;
698 struct mthca_mailbox *mailbox; 777 struct mthca_mailbox *mailbox;
699 struct mthca_cq_context *cq_context; 778 struct mthca_cq_context *cq_context;
700 int err = -ENOMEM; 779 int err = -ENOMEM;
701 u8 status; 780 u8 status;
702 int i;
703
704 might_sleep();
705 781
706 cq->ibcq.cqe = nent - 1; 782 cq->ibcq.cqe = nent - 1;
707 cq->is_kernel = !ctx; 783 cq->is_kernel = !ctx;
@@ -739,14 +815,9 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
739 cq_context = mailbox->buf; 815 cq_context = mailbox->buf;
740 816
741 if (cq->is_kernel) { 817 if (cq->is_kernel) {
742 err = mthca_buf_alloc(dev, size, MTHCA_MAX_DIRECT_CQ_SIZE, 818 err = mthca_alloc_cq_buf(dev, &cq->buf, nent);
743 &cq->queue, &cq->is_direct,
744 &dev->driver_pd, 1, &cq->mr);
745 if (err) 819 if (err)
746 goto err_out_mailbox; 820 goto err_out_mailbox;
747
748 for (i = 0; i < nent; ++i)
749 set_cqe_hw(get_cqe(cq, i));
750 } 821 }
751 822
752 spin_lock_init(&cq->lock); 823 spin_lock_init(&cq->lock);
@@ -765,7 +836,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
765 cq_context->error_eqn = cpu_to_be32(dev->eq_table.eq[MTHCA_EQ_ASYNC].eqn); 836 cq_context->error_eqn = cpu_to_be32(dev->eq_table.eq[MTHCA_EQ_ASYNC].eqn);
766 cq_context->comp_eqn = cpu_to_be32(dev->eq_table.eq[MTHCA_EQ_COMP].eqn); 837 cq_context->comp_eqn = cpu_to_be32(dev->eq_table.eq[MTHCA_EQ_COMP].eqn);
767 cq_context->pd = cpu_to_be32(pdn); 838 cq_context->pd = cpu_to_be32(pdn);
768 cq_context->lkey = cpu_to_be32(cq->mr.ibmr.lkey); 839 cq_context->lkey = cpu_to_be32(cq->buf.mr.ibmr.lkey);
769 cq_context->cqn = cpu_to_be32(cq->cqn); 840 cq_context->cqn = cpu_to_be32(cq->cqn);
770 841
771 if (mthca_is_memfree(dev)) { 842 if (mthca_is_memfree(dev)) {
@@ -803,7 +874,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
803 874
804err_out_free_mr: 875err_out_free_mr:
805 if (cq->is_kernel) 876 if (cq->is_kernel)
806 mthca_free_cq_buf(dev, cq); 877 mthca_free_cq_buf(dev, &cq->buf, cq->ibcq.cqe);
807 878
808err_out_mailbox: 879err_out_mailbox:
809 mthca_free_mailbox(dev, mailbox); 880 mthca_free_mailbox(dev, mailbox);
@@ -832,8 +903,6 @@ void mthca_free_cq(struct mthca_dev *dev,
832 int err; 903 int err;
833 u8 status; 904 u8 status;
834 905
835 might_sleep();
836
837 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 906 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
838 if (IS_ERR(mailbox)) { 907 if (IS_ERR(mailbox)) {
839 mthca_warn(dev, "No memory for mailbox to free CQ.\n"); 908 mthca_warn(dev, "No memory for mailbox to free CQ.\n");
@@ -871,7 +940,7 @@ void mthca_free_cq(struct mthca_dev *dev,
871 wait_event(cq->wait, !atomic_read(&cq->refcount)); 940 wait_event(cq->wait, !atomic_read(&cq->refcount));
872 941
873 if (cq->is_kernel) { 942 if (cq->is_kernel) {
874 mthca_free_cq_buf(dev, cq); 943 mthca_free_cq_buf(dev, &cq->buf, cq->ibcq.cqe);
875 if (mthca_is_memfree(dev)) { 944 if (mthca_is_memfree(dev)) {
876 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index); 945 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index);
877 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_SET_CI, cq->set_ci_db_index); 946 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_SET_CI, cq->set_ci_db_index);
diff --git a/drivers/infiniband/hw/mthca/mthca_dev.h b/drivers/infiniband/hw/mthca/mthca_dev.h
index e481037288d6..ad52edbefe98 100644
--- a/drivers/infiniband/hw/mthca/mthca_dev.h
+++ b/drivers/infiniband/hw/mthca/mthca_dev.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. 3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2005 Cisco Systems. All rights reserved. 4 * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
5 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 5 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
6 * Copyright (c) 2004 Voltaire, Inc. All rights reserved. 6 * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
7 * 7 *
@@ -53,8 +53,8 @@
53 53
54#define DRV_NAME "ib_mthca" 54#define DRV_NAME "ib_mthca"
55#define PFX DRV_NAME ": " 55#define PFX DRV_NAME ": "
56#define DRV_VERSION "0.07" 56#define DRV_VERSION "0.08"
57#define DRV_RELDATE "February 13, 2006" 57#define DRV_RELDATE "February 14, 2006"
58 58
59enum { 59enum {
60 MTHCA_FLAG_DDR_HIDDEN = 1 << 1, 60 MTHCA_FLAG_DDR_HIDDEN = 1 << 1,
@@ -64,7 +64,8 @@ enum {
64 MTHCA_FLAG_NO_LAM = 1 << 5, 64 MTHCA_FLAG_NO_LAM = 1 << 5,
65 MTHCA_FLAG_FMR = 1 << 6, 65 MTHCA_FLAG_FMR = 1 << 6,
66 MTHCA_FLAG_MEMFREE = 1 << 7, 66 MTHCA_FLAG_MEMFREE = 1 << 7,
67 MTHCA_FLAG_PCIE = 1 << 8 67 MTHCA_FLAG_PCIE = 1 << 8,
68 MTHCA_FLAG_SINAI_OPT = 1 << 9
68}; 69};
69 70
70enum { 71enum {
@@ -110,9 +111,17 @@ enum {
110 MTHCA_OPCODE_INVALID = 0xff 111 MTHCA_OPCODE_INVALID = 0xff
111}; 112};
112 113
114enum {
115 MTHCA_CMD_USE_EVENTS = 1 << 0,
116 MTHCA_CMD_POST_DOORBELLS = 1 << 1
117};
118
119enum {
120 MTHCA_CMD_NUM_DBELL_DWORDS = 8
121};
122
113struct mthca_cmd { 123struct mthca_cmd {
114 struct pci_pool *pool; 124 struct pci_pool *pool;
115 int use_events;
116 struct mutex hcr_mutex; 125 struct mutex hcr_mutex;
117 struct semaphore poll_sem; 126 struct semaphore poll_sem;
118 struct semaphore event_sem; 127 struct semaphore event_sem;
@@ -121,6 +130,9 @@ struct mthca_cmd {
121 int free_head; 130 int free_head;
122 struct mthca_cmd_context *context; 131 struct mthca_cmd_context *context;
123 u16 token_mask; 132 u16 token_mask;
133 u32 flags;
134 void __iomem *dbell_map;
135 u16 dbell_offsets[MTHCA_CMD_NUM_DBELL_DWORDS];
124}; 136};
125 137
126struct mthca_limits { 138struct mthca_limits {
@@ -470,12 +482,16 @@ void mthca_cq_event(struct mthca_dev *dev, u32 cqn,
470 enum ib_event_type event_type); 482 enum ib_event_type event_type);
471void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn, 483void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn,
472 struct mthca_srq *srq); 484 struct mthca_srq *srq);
485void mthca_cq_resize_copy_cqes(struct mthca_cq *cq);
486int mthca_alloc_cq_buf(struct mthca_dev *dev, struct mthca_cq_buf *buf, int nent);
487void mthca_free_cq_buf(struct mthca_dev *dev, struct mthca_cq_buf *buf, int cqe);
473 488
474int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd, 489int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
475 struct ib_srq_attr *attr, struct mthca_srq *srq); 490 struct ib_srq_attr *attr, struct mthca_srq *srq);
476void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq); 491void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq);
477int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, 492int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
478 enum ib_srq_attr_mask attr_mask); 493 enum ib_srq_attr_mask attr_mask);
494int mthca_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr);
479void mthca_srq_event(struct mthca_dev *dev, u32 srqn, 495void mthca_srq_event(struct mthca_dev *dev, u32 srqn,
480 enum ib_event_type event_type); 496 enum ib_event_type event_type);
481void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr); 497void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr);
@@ -486,6 +502,8 @@ int mthca_arbel_post_srq_recv(struct ib_srq *srq, struct ib_recv_wr *wr,
486 502
487void mthca_qp_event(struct mthca_dev *dev, u32 qpn, 503void mthca_qp_event(struct mthca_dev *dev, u32 qpn,
488 enum ib_event_type event_type); 504 enum ib_event_type event_type);
505int mthca_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
506 struct ib_qp_init_attr *qp_init_attr);
489int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask); 507int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask);
490int mthca_tavor_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr, 508int mthca_tavor_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
491 struct ib_send_wr **bad_wr); 509 struct ib_send_wr **bad_wr);
@@ -495,8 +513,8 @@ int mthca_arbel_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
495 struct ib_send_wr **bad_wr); 513 struct ib_send_wr **bad_wr);
496int mthca_arbel_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr, 514int mthca_arbel_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
497 struct ib_recv_wr **bad_wr); 515 struct ib_recv_wr **bad_wr);
498int mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send, 516void mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,
499 int index, int *dbd, __be32 *new_wqe); 517 int index, int *dbd, __be32 *new_wqe);
500int mthca_alloc_qp(struct mthca_dev *dev, 518int mthca_alloc_qp(struct mthca_dev *dev,
501 struct mthca_pd *pd, 519 struct mthca_pd *pd,
502 struct mthca_cq *send_cq, 520 struct mthca_cq *send_cq,
@@ -522,6 +540,7 @@ int mthca_create_ah(struct mthca_dev *dev,
522int mthca_destroy_ah(struct mthca_dev *dev, struct mthca_ah *ah); 540int mthca_destroy_ah(struct mthca_dev *dev, struct mthca_ah *ah);
523int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah, 541int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
524 struct ib_ud_header *header); 542 struct ib_ud_header *header);
543int mthca_ah_query(struct ib_ah *ibah, struct ib_ah_attr *attr);
525int mthca_ah_grh_present(struct mthca_ah *ah); 544int mthca_ah_grh_present(struct mthca_ah *ah);
526 545
527int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid); 546int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
diff --git a/drivers/infiniband/hw/mthca/mthca_eq.c b/drivers/infiniband/hw/mthca/mthca_eq.c
index 2eabb27804cd..cbdc348fb689 100644
--- a/drivers/infiniband/hw/mthca/mthca_eq.c
+++ b/drivers/infiniband/hw/mthca/mthca_eq.c
@@ -497,7 +497,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
497 497
498 eq->dev = dev; 498 eq->dev = dev;
499 eq->nent = roundup_pow_of_two(max(nent, 2)); 499 eq->nent = roundup_pow_of_two(max(nent, 2));
500 npages = ALIGN(eq->nent * MTHCA_EQ_ENTRY_SIZE, PAGE_SIZE) / PAGE_SIZE; 500 npages = ALIGN(eq->nent * MTHCA_EQ_ENTRY_SIZE, PAGE_SIZE) / PAGE_SIZE;
501 501
502 eq->page_list = kmalloc(npages * sizeof *eq->page_list, 502 eq->page_list = kmalloc(npages * sizeof *eq->page_list,
503 GFP_KERNEL); 503 GFP_KERNEL);
@@ -825,7 +825,7 @@ void __devexit mthca_unmap_eq_icm(struct mthca_dev *dev)
825{ 825{
826 u8 status; 826 u8 status;
827 827
828 mthca_UNMAP_ICM(dev, dev->eq_table.icm_virt, PAGE_SIZE / 4096, &status); 828 mthca_UNMAP_ICM(dev, dev->eq_table.icm_virt, 1, &status);
829 pci_unmap_page(dev->pdev, dev->eq_table.icm_dma, PAGE_SIZE, 829 pci_unmap_page(dev->pdev, dev->eq_table.icm_dma, PAGE_SIZE,
830 PCI_DMA_BIDIRECTIONAL); 830 PCI_DMA_BIDIRECTIONAL);
831 __free_page(dev->eq_table.icm_page); 831 __free_page(dev->eq_table.icm_page);
@@ -928,7 +928,7 @@ int __devinit mthca_init_eq_table(struct mthca_dev *dev)
928 mthca_warn(dev, "MAP_EQ for cmd EQ %d returned status 0x%02x\n", 928 mthca_warn(dev, "MAP_EQ for cmd EQ %d returned status 0x%02x\n",
929 dev->eq_table.eq[MTHCA_EQ_CMD].eqn, status); 929 dev->eq_table.eq[MTHCA_EQ_CMD].eqn, status);
930 930
931 for (i = 0; i < MTHCA_EQ_CMD; ++i) 931 for (i = 0; i < MTHCA_NUM_EQ; ++i)
932 if (mthca_is_memfree(dev)) 932 if (mthca_is_memfree(dev))
933 arbel_eq_req_not(dev, dev->eq_table.eq[i].eqn_mask); 933 arbel_eq_req_not(dev, dev->eq_table.eq[i].eqn_mask);
934 else 934 else
diff --git a/drivers/infiniband/hw/mthca/mthca_mad.c b/drivers/infiniband/hw/mthca/mthca_mad.c
index 1229c604c6e0..4ace6a392f41 100644
--- a/drivers/infiniband/hw/mthca/mthca_mad.c
+++ b/drivers/infiniband/hw/mthca/mthca_mad.c
@@ -109,6 +109,19 @@ static void smp_snoop(struct ib_device *ibdev,
109 } 109 }
110} 110}
111 111
112static void node_desc_override(struct ib_device *dev,
113 struct ib_mad *mad)
114{
115 if ((mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED ||
116 mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) &&
117 mad->mad_hdr.method == IB_MGMT_METHOD_GET_RESP &&
118 mad->mad_hdr.attr_id == IB_SMP_ATTR_NODE_DESC) {
119 mutex_lock(&to_mdev(dev)->cap_mask_mutex);
120 memcpy(((struct ib_smp *) mad)->data, dev->node_desc, 64);
121 mutex_unlock(&to_mdev(dev)->cap_mask_mutex);
122 }
123}
124
112static void forward_trap(struct mthca_dev *dev, 125static void forward_trap(struct mthca_dev *dev,
113 u8 port_num, 126 u8 port_num,
114 struct ib_mad *mad) 127 struct ib_mad *mad)
@@ -207,8 +220,10 @@ int mthca_process_mad(struct ib_device *ibdev,
207 return IB_MAD_RESULT_FAILURE; 220 return IB_MAD_RESULT_FAILURE;
208 } 221 }
209 222
210 if (!out_mad->mad_hdr.status) 223 if (!out_mad->mad_hdr.status) {
211 smp_snoop(ibdev, port_num, in_mad); 224 smp_snoop(ibdev, port_num, in_mad);
225 node_desc_override(ibdev, out_mad);
226 }
212 227
213 /* set return bit in status of directed route responses */ 228 /* set return bit in status of directed route responses */
214 if (in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) 229 if (in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
index 9c849d27b06e..266f347c6707 100644
--- a/drivers/infiniband/hw/mthca/mthca_main.c
+++ b/drivers/infiniband/hw/mthca/mthca_main.c
@@ -935,13 +935,19 @@ enum {
935 935
936static struct { 936static struct {
937 u64 latest_fw; 937 u64 latest_fw;
938 int is_memfree; 938 u32 flags;
939 int is_pcie;
940} mthca_hca_table[] = { 939} mthca_hca_table[] = {
941 [TAVOR] = { .latest_fw = MTHCA_FW_VER(3, 3, 3), .is_memfree = 0, .is_pcie = 0 }, 940 [TAVOR] = { .latest_fw = MTHCA_FW_VER(3, 4, 0),
942 [ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 7, 0), .is_memfree = 0, .is_pcie = 1 }, 941 .flags = 0 },
943 [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 1, 0), .is_memfree = 1, .is_pcie = 1 }, 942 [ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 7, 400),
944 [SINAI] = { .latest_fw = MTHCA_FW_VER(1, 0, 1), .is_memfree = 1, .is_pcie = 1 } 943 .flags = MTHCA_FLAG_PCIE },
944 [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 1, 0),
945 .flags = MTHCA_FLAG_MEMFREE |
946 MTHCA_FLAG_PCIE },
947 [SINAI] = { .latest_fw = MTHCA_FW_VER(1, 0, 800),
948 .flags = MTHCA_FLAG_MEMFREE |
949 MTHCA_FLAG_PCIE |
950 MTHCA_FLAG_SINAI_OPT }
945}; 951};
946 952
947static int __devinit mthca_init_one(struct pci_dev *pdev, 953static int __devinit mthca_init_one(struct pci_dev *pdev,
@@ -1031,12 +1037,9 @@ static int __devinit mthca_init_one(struct pci_dev *pdev,
1031 1037
1032 mdev->pdev = pdev; 1038 mdev->pdev = pdev;
1033 1039
1040 mdev->mthca_flags = mthca_hca_table[id->driver_data].flags;
1034 if (ddr_hidden) 1041 if (ddr_hidden)
1035 mdev->mthca_flags |= MTHCA_FLAG_DDR_HIDDEN; 1042 mdev->mthca_flags |= MTHCA_FLAG_DDR_HIDDEN;
1036 if (mthca_hca_table[id->driver_data].is_memfree)
1037 mdev->mthca_flags |= MTHCA_FLAG_MEMFREE;
1038 if (mthca_hca_table[id->driver_data].is_pcie)
1039 mdev->mthca_flags |= MTHCA_FLAG_PCIE;
1040 1043
1041 /* 1044 /*
1042 * Now reset the HCA before we touch the PCI capabilities or 1045 * Now reset the HCA before we touch the PCI capabilities or
diff --git a/drivers/infiniband/hw/mthca/mthca_mcg.c b/drivers/infiniband/hw/mthca/mthca_mcg.c
index 321f11e707f2..9965bda9afed 100644
--- a/drivers/infiniband/hw/mthca/mthca_mcg.c
+++ b/drivers/infiniband/hw/mthca/mthca_mcg.c
@@ -187,7 +187,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
187 187
188 for (i = 0; i < MTHCA_QP_PER_MGM; ++i) 188 for (i = 0; i < MTHCA_QP_PER_MGM; ++i)
189 if (mgm->qp[i] == cpu_to_be32(ibqp->qp_num | (1 << 31))) { 189 if (mgm->qp[i] == cpu_to_be32(ibqp->qp_num | (1 << 31))) {
190 mthca_dbg(dev, "QP %06x already a member of MGM\n", 190 mthca_dbg(dev, "QP %06x already a member of MGM\n",
191 ibqp->qp_num); 191 ibqp->qp_num);
192 err = 0; 192 err = 0;
193 goto out; 193 goto out;
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
index d709cb162a72..15cc2f6eb475 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.c
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
@@ -202,7 +202,8 @@ void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int o
202 202
203 if (--table->icm[i]->refcount == 0) { 203 if (--table->icm[i]->refcount == 0) {
204 mthca_UNMAP_ICM(dev, table->virt + i * MTHCA_TABLE_CHUNK_SIZE, 204 mthca_UNMAP_ICM(dev, table->virt + i * MTHCA_TABLE_CHUNK_SIZE,
205 MTHCA_TABLE_CHUNK_SIZE >> 12, &status); 205 MTHCA_TABLE_CHUNK_SIZE / MTHCA_ICM_PAGE_SIZE,
206 &status);
206 mthca_free_icm(dev, table->icm[i]); 207 mthca_free_icm(dev, table->icm[i]);
207 table->icm[i] = NULL; 208 table->icm[i] = NULL;
208 } 209 }
@@ -336,7 +337,8 @@ err:
336 for (i = 0; i < num_icm; ++i) 337 for (i = 0; i < num_icm; ++i)
337 if (table->icm[i]) { 338 if (table->icm[i]) {
338 mthca_UNMAP_ICM(dev, virt + i * MTHCA_TABLE_CHUNK_SIZE, 339 mthca_UNMAP_ICM(dev, virt + i * MTHCA_TABLE_CHUNK_SIZE,
339 MTHCA_TABLE_CHUNK_SIZE >> 12, &status); 340 MTHCA_TABLE_CHUNK_SIZE / MTHCA_ICM_PAGE_SIZE,
341 &status);
340 mthca_free_icm(dev, table->icm[i]); 342 mthca_free_icm(dev, table->icm[i]);
341 } 343 }
342 344
@@ -353,7 +355,8 @@ void mthca_free_icm_table(struct mthca_dev *dev, struct mthca_icm_table *table)
353 for (i = 0; i < table->num_icm; ++i) 355 for (i = 0; i < table->num_icm; ++i)
354 if (table->icm[i]) { 356 if (table->icm[i]) {
355 mthca_UNMAP_ICM(dev, table->virt + i * MTHCA_TABLE_CHUNK_SIZE, 357 mthca_UNMAP_ICM(dev, table->virt + i * MTHCA_TABLE_CHUNK_SIZE,
356 MTHCA_TABLE_CHUNK_SIZE >> 12, &status); 358 MTHCA_TABLE_CHUNK_SIZE / MTHCA_ICM_PAGE_SIZE,
359 &status);
357 mthca_free_icm(dev, table->icm[i]); 360 mthca_free_icm(dev, table->icm[i]);
358 } 361 }
359 362
@@ -364,7 +367,7 @@ static u64 mthca_uarc_virt(struct mthca_dev *dev, struct mthca_uar *uar, int pag
364{ 367{
365 return dev->uar_table.uarc_base + 368 return dev->uar_table.uarc_base +
366 uar->index * dev->uar_table.uarc_size + 369 uar->index * dev->uar_table.uarc_size +
367 page * 4096; 370 page * MTHCA_ICM_PAGE_SIZE;
368} 371}
369 372
370int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar, 373int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
@@ -401,7 +404,7 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
401 if (ret < 0) 404 if (ret < 0)
402 goto out; 405 goto out;
403 406
404 db_tab->page[i].mem.length = 4096; 407 db_tab->page[i].mem.length = MTHCA_ICM_PAGE_SIZE;
405 db_tab->page[i].mem.offset = uaddr & ~PAGE_MASK; 408 db_tab->page[i].mem.offset = uaddr & ~PAGE_MASK;
406 409
407 ret = pci_map_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE); 410 ret = pci_map_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
@@ -455,7 +458,7 @@ struct mthca_user_db_table *mthca_init_user_db_tab(struct mthca_dev *dev)
455 if (!mthca_is_memfree(dev)) 458 if (!mthca_is_memfree(dev))
456 return NULL; 459 return NULL;
457 460
458 npages = dev->uar_table.uarc_size / 4096; 461 npages = dev->uar_table.uarc_size / MTHCA_ICM_PAGE_SIZE;
459 db_tab = kmalloc(sizeof *db_tab + npages * sizeof *db_tab->page, GFP_KERNEL); 462 db_tab = kmalloc(sizeof *db_tab + npages * sizeof *db_tab->page, GFP_KERNEL);
460 if (!db_tab) 463 if (!db_tab)
461 return ERR_PTR(-ENOMEM); 464 return ERR_PTR(-ENOMEM);
@@ -478,7 +481,7 @@ void mthca_cleanup_user_db_tab(struct mthca_dev *dev, struct mthca_uar *uar,
478 if (!mthca_is_memfree(dev)) 481 if (!mthca_is_memfree(dev))
479 return; 482 return;
480 483
481 for (i = 0; i < dev->uar_table.uarc_size / 4096; ++i) { 484 for (i = 0; i < dev->uar_table.uarc_size / MTHCA_ICM_PAGE_SIZE; ++i) {
482 if (db_tab->page[i].uvirt) { 485 if (db_tab->page[i].uvirt) {
483 mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, uar, i), 1, &status); 486 mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, uar, i), 1, &status);
484 pci_unmap_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE); 487 pci_unmap_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
@@ -551,20 +554,20 @@ int mthca_alloc_db(struct mthca_dev *dev, enum mthca_db_type type,
551 page = dev->db_tab->page + end; 554 page = dev->db_tab->page + end;
552 555
553alloc: 556alloc:
554 page->db_rec = dma_alloc_coherent(&dev->pdev->dev, 4096, 557 page->db_rec = dma_alloc_coherent(&dev->pdev->dev, MTHCA_ICM_PAGE_SIZE,
555 &page->mapping, GFP_KERNEL); 558 &page->mapping, GFP_KERNEL);
556 if (!page->db_rec) { 559 if (!page->db_rec) {
557 ret = -ENOMEM; 560 ret = -ENOMEM;
558 goto out; 561 goto out;
559 } 562 }
560 memset(page->db_rec, 0, 4096); 563 memset(page->db_rec, 0, MTHCA_ICM_PAGE_SIZE);
561 564
562 ret = mthca_MAP_ICM_page(dev, page->mapping, 565 ret = mthca_MAP_ICM_page(dev, page->mapping,
563 mthca_uarc_virt(dev, &dev->driver_uar, i), &status); 566 mthca_uarc_virt(dev, &dev->driver_uar, i), &status);
564 if (!ret && status) 567 if (!ret && status)
565 ret = -EINVAL; 568 ret = -EINVAL;
566 if (ret) { 569 if (ret) {
567 dma_free_coherent(&dev->pdev->dev, 4096, 570 dma_free_coherent(&dev->pdev->dev, MTHCA_ICM_PAGE_SIZE,
568 page->db_rec, page->mapping); 571 page->db_rec, page->mapping);
569 goto out; 572 goto out;
570 } 573 }
@@ -612,7 +615,7 @@ void mthca_free_db(struct mthca_dev *dev, int type, int db_index)
612 i >= dev->db_tab->max_group1 - 1) { 615 i >= dev->db_tab->max_group1 - 1) {
613 mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, &dev->driver_uar, i), 1, &status); 616 mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, &dev->driver_uar, i), 1, &status);
614 617
615 dma_free_coherent(&dev->pdev->dev, 4096, 618 dma_free_coherent(&dev->pdev->dev, MTHCA_ICM_PAGE_SIZE,
616 page->db_rec, page->mapping); 619 page->db_rec, page->mapping);
617 page->db_rec = NULL; 620 page->db_rec = NULL;
618 621
@@ -640,7 +643,7 @@ int mthca_init_db_tab(struct mthca_dev *dev)
640 643
641 mutex_init(&dev->db_tab->mutex); 644 mutex_init(&dev->db_tab->mutex);
642 645
643 dev->db_tab->npages = dev->uar_table.uarc_size / 4096; 646 dev->db_tab->npages = dev->uar_table.uarc_size / MTHCA_ICM_PAGE_SIZE;
644 dev->db_tab->max_group1 = 0; 647 dev->db_tab->max_group1 = 0;
645 dev->db_tab->min_group2 = dev->db_tab->npages - 1; 648 dev->db_tab->min_group2 = dev->db_tab->npages - 1;
646 649
@@ -681,7 +684,7 @@ void mthca_cleanup_db_tab(struct mthca_dev *dev)
681 684
682 mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, &dev->driver_uar, i), 1, &status); 685 mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, &dev->driver_uar, i), 1, &status);
683 686
684 dma_free_coherent(&dev->pdev->dev, 4096, 687 dma_free_coherent(&dev->pdev->dev, MTHCA_ICM_PAGE_SIZE,
685 dev->db_tab->page[i].db_rec, 688 dev->db_tab->page[i].db_rec,
686 dev->db_tab->page[i].mapping); 689 dev->db_tab->page[i].mapping);
687 } 690 }
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.h b/drivers/infiniband/hw/mthca/mthca_memfree.h
index 36f1141a08aa..6d42947e1dc4 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.h
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.h
@@ -45,6 +45,12 @@
45 ((256 - sizeof (struct list_head) - 2 * sizeof (int)) / \ 45 ((256 - sizeof (struct list_head) - 2 * sizeof (int)) / \
46 (sizeof (struct scatterlist))) 46 (sizeof (struct scatterlist)))
47 47
48enum {
49 MTHCA_ICM_PAGE_SHIFT = 12,
50 MTHCA_ICM_PAGE_SIZE = 1 << MTHCA_ICM_PAGE_SHIFT,
51 MTHCA_DB_REC_PER_PAGE = MTHCA_ICM_PAGE_SIZE / 8
52};
53
48struct mthca_icm_chunk { 54struct mthca_icm_chunk {
49 struct list_head list; 55 struct list_head list;
50 int npages; 56 int npages;
@@ -131,10 +137,6 @@ static inline unsigned long mthca_icm_size(struct mthca_icm_iter *iter)
131 return sg_dma_len(&iter->chunk->mem[iter->page_idx]); 137 return sg_dma_len(&iter->chunk->mem[iter->page_idx]);
132} 138}
133 139
134enum {
135 MTHCA_DB_REC_PER_PAGE = 4096 / 8
136};
137
138struct mthca_db_page { 140struct mthca_db_page {
139 DECLARE_BITMAP(used, MTHCA_DB_REC_PER_PAGE); 141 DECLARE_BITMAP(used, MTHCA_DB_REC_PER_PAGE);
140 __be64 *db_rec; 142 __be64 *db_rec;
diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
index e995e2aa016d..698b62125765 100644
--- a/drivers/infiniband/hw/mthca/mthca_mr.c
+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
@@ -76,6 +76,8 @@ struct mthca_mpt_entry {
76#define MTHCA_MPT_STATUS_SW 0xF0 76#define MTHCA_MPT_STATUS_SW 0xF0
77#define MTHCA_MPT_STATUS_HW 0x00 77#define MTHCA_MPT_STATUS_HW 0x00
78 78
79#define SINAI_FMR_KEY_INC 0x1000000
80
79/* 81/*
80 * Buddy allocator for MTT segments (currently not very efficient 82 * Buddy allocator for MTT segments (currently not very efficient
81 * since it doesn't keep a free list and just searches linearly 83 * since it doesn't keep a free list and just searches linearly
@@ -330,6 +332,14 @@ static inline u32 key_to_hw_index(struct mthca_dev *dev, u32 key)
330 return tavor_key_to_hw_index(key); 332 return tavor_key_to_hw_index(key);
331} 333}
332 334
335static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
336{
337 if (dev->mthca_flags & MTHCA_FLAG_SINAI_OPT)
338 return ((key << 20) & 0x800000) | (key & 0x7fffff);
339 else
340 return key;
341}
342
333int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift, 343int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
334 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr) 344 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
335{ 345{
@@ -340,13 +350,12 @@ int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
340 int err; 350 int err;
341 u8 status; 351 u8 status;
342 352
343 might_sleep();
344
345 WARN_ON(buffer_size_shift >= 32); 353 WARN_ON(buffer_size_shift >= 32);
346 354
347 key = mthca_alloc(&dev->mr_table.mpt_alloc); 355 key = mthca_alloc(&dev->mr_table.mpt_alloc);
348 if (key == -1) 356 if (key == -1)
349 return -ENOMEM; 357 return -ENOMEM;
358 key = adjust_key(dev, key);
350 mr->ibmr.rkey = mr->ibmr.lkey = hw_index_to_key(dev, key); 359 mr->ibmr.rkey = mr->ibmr.lkey = hw_index_to_key(dev, key);
351 360
352 if (mthca_is_memfree(dev)) { 361 if (mthca_is_memfree(dev)) {
@@ -467,8 +476,6 @@ void mthca_free_mr(struct mthca_dev *dev, struct mthca_mr *mr)
467 int err; 476 int err;
468 u8 status; 477 u8 status;
469 478
470 might_sleep();
471
472 err = mthca_HW2SW_MPT(dev, NULL, 479 err = mthca_HW2SW_MPT(dev, NULL,
473 key_to_hw_index(dev, mr->ibmr.lkey) & 480 key_to_hw_index(dev, mr->ibmr.lkey) &
474 (dev->limits.num_mpts - 1), 481 (dev->limits.num_mpts - 1),
@@ -495,9 +502,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
495 int err = -ENOMEM; 502 int err = -ENOMEM;
496 int i; 503 int i;
497 504
498 might_sleep(); 505 if (mr->attr.page_shift < 12 || mr->attr.page_shift >= 32)
499
500 if (mr->attr.page_size < 12 || mr->attr.page_size >= 32)
501 return -EINVAL; 506 return -EINVAL;
502 507
503 /* For Arbel, all MTTs must fit in the same page. */ 508 /* For Arbel, all MTTs must fit in the same page. */
@@ -510,6 +515,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
510 key = mthca_alloc(&dev->mr_table.mpt_alloc); 515 key = mthca_alloc(&dev->mr_table.mpt_alloc);
511 if (key == -1) 516 if (key == -1)
512 return -ENOMEM; 517 return -ENOMEM;
518 key = adjust_key(dev, key);
513 519
514 idx = key & (dev->limits.num_mpts - 1); 520 idx = key & (dev->limits.num_mpts - 1);
515 mr->ibmr.rkey = mr->ibmr.lkey = hw_index_to_key(dev, key); 521 mr->ibmr.rkey = mr->ibmr.lkey = hw_index_to_key(dev, key);
@@ -523,7 +529,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
523 BUG_ON(!mr->mem.arbel.mpt); 529 BUG_ON(!mr->mem.arbel.mpt);
524 } else 530 } else
525 mr->mem.tavor.mpt = dev->mr_table.tavor_fmr.mpt_base + 531 mr->mem.tavor.mpt = dev->mr_table.tavor_fmr.mpt_base +
526 sizeof *(mr->mem.tavor.mpt) * idx; 532 sizeof *(mr->mem.tavor.mpt) * idx;
527 533
528 mr->mtt = __mthca_alloc_mtt(dev, list_len, dev->mr_table.fmr_mtt_buddy); 534 mr->mtt = __mthca_alloc_mtt(dev, list_len, dev->mr_table.fmr_mtt_buddy);
529 if (IS_ERR(mr->mtt)) 535 if (IS_ERR(mr->mtt))
@@ -549,7 +555,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
549 MTHCA_MPT_FLAG_REGION | 555 MTHCA_MPT_FLAG_REGION |
550 access); 556 access);
551 557
552 mpt_entry->page_size = cpu_to_be32(mr->attr.page_size - 12); 558 mpt_entry->page_size = cpu_to_be32(mr->attr.page_shift - 12);
553 mpt_entry->key = cpu_to_be32(key); 559 mpt_entry->key = cpu_to_be32(key);
554 mpt_entry->pd = cpu_to_be32(pd); 560 mpt_entry->pd = cpu_to_be32(pd);
555 memset(&mpt_entry->start, 0, 561 memset(&mpt_entry->start, 0,
@@ -617,7 +623,7 @@ static inline int mthca_check_fmr(struct mthca_fmr *fmr, u64 *page_list,
617 if (list_len > fmr->attr.max_pages) 623 if (list_len > fmr->attr.max_pages)
618 return -EINVAL; 624 return -EINVAL;
619 625
620 page_mask = (1 << fmr->attr.page_size) - 1; 626 page_mask = (1 << fmr->attr.page_shift) - 1;
621 627
622 /* We are getting page lists, so va must be page aligned. */ 628 /* We are getting page lists, so va must be page aligned. */
623 if (iova & page_mask) 629 if (iova & page_mask)
@@ -665,7 +671,7 @@ int mthca_tavor_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
665 } 671 }
666 672
667 mpt_entry.lkey = cpu_to_be32(key); 673 mpt_entry.lkey = cpu_to_be32(key);
668 mpt_entry.length = cpu_to_be64(list_len * (1ull << fmr->attr.page_size)); 674 mpt_entry.length = cpu_to_be64(list_len * (1ull << fmr->attr.page_shift));
669 mpt_entry.start = cpu_to_be64(iova); 675 mpt_entry.start = cpu_to_be64(iova);
670 676
671 __raw_writel((__force u32) mpt_entry.lkey, &fmr->mem.tavor.mpt->key); 677 __raw_writel((__force u32) mpt_entry.lkey, &fmr->mem.tavor.mpt->key);
@@ -693,7 +699,10 @@ int mthca_arbel_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
693 ++fmr->maps; 699 ++fmr->maps;
694 700
695 key = arbel_key_to_hw_index(fmr->ibmr.lkey); 701 key = arbel_key_to_hw_index(fmr->ibmr.lkey);
696 key += dev->limits.num_mpts; 702 if (dev->mthca_flags & MTHCA_FLAG_SINAI_OPT)
703 key += SINAI_FMR_KEY_INC;
704 else
705 key += dev->limits.num_mpts;
697 fmr->ibmr.lkey = fmr->ibmr.rkey = arbel_hw_index_to_key(key); 706 fmr->ibmr.lkey = fmr->ibmr.rkey = arbel_hw_index_to_key(key);
698 707
699 *(u8 *) fmr->mem.arbel.mpt = MTHCA_MPT_STATUS_SW; 708 *(u8 *) fmr->mem.arbel.mpt = MTHCA_MPT_STATUS_SW;
@@ -706,7 +715,7 @@ int mthca_arbel_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
706 715
707 fmr->mem.arbel.mpt->key = cpu_to_be32(key); 716 fmr->mem.arbel.mpt->key = cpu_to_be32(key);
708 fmr->mem.arbel.mpt->lkey = cpu_to_be32(key); 717 fmr->mem.arbel.mpt->lkey = cpu_to_be32(key);
709 fmr->mem.arbel.mpt->length = cpu_to_be64(list_len * (1ull << fmr->attr.page_size)); 718 fmr->mem.arbel.mpt->length = cpu_to_be64(list_len * (1ull << fmr->attr.page_shift));
710 fmr->mem.arbel.mpt->start = cpu_to_be64(iova); 719 fmr->mem.arbel.mpt->start = cpu_to_be64(iova);
711 720
712 wmb(); 721 wmb();
@@ -766,6 +775,9 @@ int __devinit mthca_init_mr_table(struct mthca_dev *dev)
766 else 775 else
767 dev->mthca_flags |= MTHCA_FLAG_FMR; 776 dev->mthca_flags |= MTHCA_FLAG_FMR;
768 777
778 if (dev->mthca_flags & MTHCA_FLAG_SINAI_OPT)
779 mthca_dbg(dev, "Memory key throughput optimization activated.\n");
780
769 err = mthca_buddy_init(&dev->mr_table.mtt_buddy, 781 err = mthca_buddy_init(&dev->mr_table.mtt_buddy,
770 fls(dev->limits.num_mtt_segs - 1)); 782 fls(dev->limits.num_mtt_segs - 1));
771 783
@@ -785,7 +797,7 @@ int __devinit mthca_init_mr_table(struct mthca_dev *dev)
785 } 797 }
786 798
787 dev->mr_table.tavor_fmr.mpt_base = 799 dev->mr_table.tavor_fmr.mpt_base =
788 ioremap(dev->mr_table.mpt_base, 800 ioremap(dev->mr_table.mpt_base,
789 (1 << i) * sizeof (struct mthca_mpt_entry)); 801 (1 << i) * sizeof (struct mthca_mpt_entry));
790 802
791 if (!dev->mr_table.tavor_fmr.mpt_base) { 803 if (!dev->mr_table.tavor_fmr.mpt_base) {
@@ -813,7 +825,7 @@ int __devinit mthca_init_mr_table(struct mthca_dev *dev)
813 goto err_reserve_fmr; 825 goto err_reserve_fmr;
814 826
815 dev->mr_table.fmr_mtt_buddy = 827 dev->mr_table.fmr_mtt_buddy =
816 &dev->mr_table.tavor_fmr.mtt_buddy; 828 &dev->mr_table.tavor_fmr.mtt_buddy;
817 } else 829 } else
818 dev->mr_table.fmr_mtt_buddy = &dev->mr_table.mtt_buddy; 830 dev->mr_table.fmr_mtt_buddy = &dev->mr_table.mtt_buddy;
819 831
diff --git a/drivers/infiniband/hw/mthca/mthca_pd.c b/drivers/infiniband/hw/mthca/mthca_pd.c
index 3dbf06a6e6f4..105fc5faaddf 100644
--- a/drivers/infiniband/hw/mthca/mthca_pd.c
+++ b/drivers/infiniband/hw/mthca/mthca_pd.c
@@ -43,8 +43,6 @@ int mthca_pd_alloc(struct mthca_dev *dev, int privileged, struct mthca_pd *pd)
43{ 43{
44 int err = 0; 44 int err = 0;
45 45
46 might_sleep();
47
48 pd->privileged = privileged; 46 pd->privileged = privileged;
49 47
50 atomic_set(&pd->sqp_count, 0); 48 atomic_set(&pd->sqp_count, 0);
@@ -66,7 +64,6 @@ int mthca_pd_alloc(struct mthca_dev *dev, int privileged, struct mthca_pd *pd)
66 64
67void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd) 65void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd)
68{ 66{
69 might_sleep();
70 if (pd->privileged) 67 if (pd->privileged)
71 mthca_free_mr(dev, &pd->ntmr); 68 mthca_free_mr(dev, &pd->ntmr);
72 mthca_free(&dev->pd_table.alloc, pd->pd_num); 69 mthca_free(&dev->pd_table.alloc, pd->pd_num);
diff --git a/drivers/infiniband/hw/mthca/mthca_profile.c b/drivers/infiniband/hw/mthca/mthca_profile.c
index 08a909371b0a..58d44aa3c302 100644
--- a/drivers/infiniband/hw/mthca/mthca_profile.c
+++ b/drivers/infiniband/hw/mthca/mthca_profile.c
@@ -152,7 +152,7 @@ u64 mthca_make_profile(struct mthca_dev *dev,
152 } 152 }
153 if (total_size > mem_avail) { 153 if (total_size > mem_avail) {
154 mthca_err(dev, "Profile requires 0x%llx bytes; " 154 mthca_err(dev, "Profile requires 0x%llx bytes; "
155 "won't in 0x%llx bytes of context memory.\n", 155 "won't fit in 0x%llx bytes of context memory.\n",
156 (unsigned long long) total_size, 156 (unsigned long long) total_size,
157 (unsigned long long) mem_avail); 157 (unsigned long long) mem_avail);
158 kfree(profile); 158 kfree(profile);
@@ -262,6 +262,14 @@ u64 mthca_make_profile(struct mthca_dev *dev,
262 */ 262 */
263 dev->limits.num_pds = MTHCA_NUM_PDS; 263 dev->limits.num_pds = MTHCA_NUM_PDS;
264 264
265 if (dev->mthca_flags & MTHCA_FLAG_SINAI_OPT &&
266 init_hca->log_mpt_sz > 23) {
267 mthca_warn(dev, "MPT table too large (requested size 2^%d >= 2^24)\n",
268 init_hca->log_mpt_sz);
269 mthca_warn(dev, "Disabling memory key throughput optimization.\n");
270 dev->mthca_flags &= ~MTHCA_FLAG_SINAI_OPT;
271 }
272
265 /* 273 /*
266 * For Tavor, FMRs use ioremapped PCI memory. For 32 bit 274 * For Tavor, FMRs use ioremapped PCI memory. For 32 bit
267 * systems it may use too much vmalloc space to map all MTT 275 * systems it may use too much vmalloc space to map all MTT
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
index e88e39aef85a..2c250bc11c33 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. 3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2005 Cisco Systems. All rights reserved. 4 * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
5 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 5 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
6 * Copyright (c) 2004 Voltaire, Inc. All rights reserved. 6 * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
7 * 7 *
@@ -108,12 +108,12 @@ static int mthca_query_device(struct ib_device *ibdev,
108 props->max_srq_wr = mdev->limits.max_srq_wqes; 108 props->max_srq_wr = mdev->limits.max_srq_wqes;
109 props->max_srq_sge = mdev->limits.max_sg; 109 props->max_srq_sge = mdev->limits.max_sg;
110 props->local_ca_ack_delay = mdev->limits.local_ca_ack_delay; 110 props->local_ca_ack_delay = mdev->limits.local_ca_ack_delay;
111 props->atomic_cap = mdev->limits.flags & DEV_LIM_FLAG_ATOMIC ? 111 props->atomic_cap = mdev->limits.flags & DEV_LIM_FLAG_ATOMIC ?
112 IB_ATOMIC_HCA : IB_ATOMIC_NONE; 112 IB_ATOMIC_HCA : IB_ATOMIC_NONE;
113 props->max_pkeys = mdev->limits.pkey_table_len; 113 props->max_pkeys = mdev->limits.pkey_table_len;
114 props->max_mcast_grp = mdev->limits.num_mgms + mdev->limits.num_amgms; 114 props->max_mcast_grp = mdev->limits.num_mgms + mdev->limits.num_amgms;
115 props->max_mcast_qp_attach = MTHCA_QP_PER_MGM; 115 props->max_mcast_qp_attach = MTHCA_QP_PER_MGM;
116 props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * 116 props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
117 props->max_mcast_grp; 117 props->max_mcast_grp;
118 118
119 err = 0; 119 err = 0;
@@ -176,6 +176,23 @@ static int mthca_query_port(struct ib_device *ibdev,
176 return err; 176 return err;
177} 177}
178 178
179static int mthca_modify_device(struct ib_device *ibdev,
180 int mask,
181 struct ib_device_modify *props)
182{
183 if (mask & ~IB_DEVICE_MODIFY_NODE_DESC)
184 return -EOPNOTSUPP;
185
186 if (mask & IB_DEVICE_MODIFY_NODE_DESC) {
187 if (mutex_lock_interruptible(&to_mdev(ibdev)->cap_mask_mutex))
188 return -ERESTARTSYS;
189 memcpy(ibdev->node_desc, props->node_desc, 64);
190 mutex_unlock(&to_mdev(ibdev)->cap_mask_mutex);
191 }
192
193 return 0;
194}
195
179static int mthca_modify_port(struct ib_device *ibdev, 196static int mthca_modify_port(struct ib_device *ibdev,
180 u8 port, int port_modify_mask, 197 u8 port, int port_modify_mask,
181 struct ib_port_modify *props) 198 struct ib_port_modify *props)
@@ -669,9 +686,9 @@ static struct ib_cq *mthca_create_cq(struct ib_device *ibdev, int entries,
669 } 686 }
670 687
671 if (context) { 688 if (context) {
672 cq->mr.ibmr.lkey = ucmd.lkey; 689 cq->buf.mr.ibmr.lkey = ucmd.lkey;
673 cq->set_ci_db_index = ucmd.set_db_index; 690 cq->set_ci_db_index = ucmd.set_db_index;
674 cq->arm_db_index = ucmd.arm_db_index; 691 cq->arm_db_index = ucmd.arm_db_index;
675 } 692 }
676 693
677 for (nent = 1; nent <= entries; nent <<= 1) 694 for (nent = 1; nent <= entries; nent <<= 1)
@@ -689,6 +706,8 @@ static struct ib_cq *mthca_create_cq(struct ib_device *ibdev, int entries,
689 goto err_free; 706 goto err_free;
690 } 707 }
691 708
709 cq->resize_buf = NULL;
710
692 return &cq->ibcq; 711 return &cq->ibcq;
693 712
694err_free: 713err_free:
@@ -707,6 +726,121 @@ err_unmap_set:
707 return ERR_PTR(err); 726 return ERR_PTR(err);
708} 727}
709 728
729static int mthca_alloc_resize_buf(struct mthca_dev *dev, struct mthca_cq *cq,
730 int entries)
731{
732 int ret;
733
734 spin_lock_irq(&cq->lock);
735 if (cq->resize_buf) {
736 ret = -EBUSY;
737 goto unlock;
738 }
739
740 cq->resize_buf = kmalloc(sizeof *cq->resize_buf, GFP_ATOMIC);
741 if (!cq->resize_buf) {
742 ret = -ENOMEM;
743 goto unlock;
744 }
745
746 cq->resize_buf->state = CQ_RESIZE_ALLOC;
747
748 ret = 0;
749
750unlock:
751 spin_unlock_irq(&cq->lock);
752
753 if (ret)
754 return ret;
755
756 ret = mthca_alloc_cq_buf(dev, &cq->resize_buf->buf, entries);
757 if (ret) {
758 spin_lock_irq(&cq->lock);
759 kfree(cq->resize_buf);
760 cq->resize_buf = NULL;
761 spin_unlock_irq(&cq->lock);
762 return ret;
763 }
764
765 cq->resize_buf->cqe = entries - 1;
766
767 spin_lock_irq(&cq->lock);
768 cq->resize_buf->state = CQ_RESIZE_READY;
769 spin_unlock_irq(&cq->lock);
770
771 return 0;
772}
773
774static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
775{
776 struct mthca_dev *dev = to_mdev(ibcq->device);
777 struct mthca_cq *cq = to_mcq(ibcq);
778 struct mthca_resize_cq ucmd;
779 u32 lkey;
780 u8 status;
781 int ret;
782
783 if (entries < 1 || entries > dev->limits.max_cqes)
784 return -EINVAL;
785
786 entries = roundup_pow_of_two(entries + 1);
787 if (entries == ibcq->cqe + 1)
788 return 0;
789
790 if (cq->is_kernel) {
791 ret = mthca_alloc_resize_buf(dev, cq, entries);
792 if (ret)
793 return ret;
794 lkey = cq->resize_buf->buf.mr.ibmr.lkey;
795 } else {
796 if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd))
797 return -EFAULT;
798 lkey = ucmd.lkey;
799 }
800
801 ret = mthca_RESIZE_CQ(dev, cq->cqn, lkey, long_log2(entries), &status);
802 if (status)
803 ret = -EINVAL;
804
805 if (ret) {
806 if (cq->resize_buf) {
807 mthca_free_cq_buf(dev, &cq->resize_buf->buf,
808 cq->resize_buf->cqe);
809 kfree(cq->resize_buf);
810 spin_lock_irq(&cq->lock);
811 cq->resize_buf = NULL;
812 spin_unlock_irq(&cq->lock);
813 }
814 return ret;
815 }
816
817 if (cq->is_kernel) {
818 struct mthca_cq_buf tbuf;
819 int tcqe;
820
821 spin_lock_irq(&cq->lock);
822 if (cq->resize_buf->state == CQ_RESIZE_READY) {
823 mthca_cq_resize_copy_cqes(cq);
824 tbuf = cq->buf;
825 tcqe = cq->ibcq.cqe;
826 cq->buf = cq->resize_buf->buf;
827 cq->ibcq.cqe = cq->resize_buf->cqe;
828 } else {
829 tbuf = cq->resize_buf->buf;
830 tcqe = cq->resize_buf->cqe;
831 }
832
833 kfree(cq->resize_buf);
834 cq->resize_buf = NULL;
835 spin_unlock_irq(&cq->lock);
836
837 mthca_free_cq_buf(dev, &tbuf, tcqe);
838 } else
839 ibcq->cqe = entries - 1;
840
841 return 0;
842}
843
710static int mthca_destroy_cq(struct ib_cq *cq) 844static int mthca_destroy_cq(struct ib_cq *cq)
711{ 845{
712 if (cq->uobject) { 846 if (cq->uobject) {
@@ -1070,6 +1204,20 @@ static int mthca_init_node_data(struct mthca_dev *dev)
1070 goto out; 1204 goto out;
1071 1205
1072 init_query_mad(in_mad); 1206 init_query_mad(in_mad);
1207 in_mad->attr_id = IB_SMP_ATTR_NODE_DESC;
1208
1209 err = mthca_MAD_IFC(dev, 1, 1,
1210 1, NULL, NULL, in_mad, out_mad,
1211 &status);
1212 if (err)
1213 goto out;
1214 if (status) {
1215 err = -EINVAL;
1216 goto out;
1217 }
1218
1219 memcpy(dev->ib_dev.node_desc, out_mad->data, 64);
1220
1073 in_mad->attr_id = IB_SMP_ATTR_NODE_INFO; 1221 in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
1074 1222
1075 err = mthca_MAD_IFC(dev, 1, 1, 1223 err = mthca_MAD_IFC(dev, 1, 1,
@@ -1113,14 +1261,17 @@ int mthca_register_device(struct mthca_dev *dev)
1113 (1ull << IB_USER_VERBS_CMD_DEREG_MR) | 1261 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
1114 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | 1262 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
1115 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | 1263 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
1264 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
1116 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | 1265 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
1117 (1ull << IB_USER_VERBS_CMD_CREATE_QP) | 1266 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
1267 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
1118 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | 1268 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
1119 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | 1269 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
1120 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | 1270 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
1121 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | 1271 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
1122 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | 1272 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
1123 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | 1273 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
1274 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
1124 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ); 1275 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
1125 dev->ib_dev.node_type = IB_NODE_CA; 1276 dev->ib_dev.node_type = IB_NODE_CA;
1126 dev->ib_dev.phys_port_cnt = dev->limits.num_ports; 1277 dev->ib_dev.phys_port_cnt = dev->limits.num_ports;
@@ -1128,6 +1279,7 @@ int mthca_register_device(struct mthca_dev *dev)
1128 dev->ib_dev.class_dev.dev = &dev->pdev->dev; 1279 dev->ib_dev.class_dev.dev = &dev->pdev->dev;
1129 dev->ib_dev.query_device = mthca_query_device; 1280 dev->ib_dev.query_device = mthca_query_device;
1130 dev->ib_dev.query_port = mthca_query_port; 1281 dev->ib_dev.query_port = mthca_query_port;
1282 dev->ib_dev.modify_device = mthca_modify_device;
1131 dev->ib_dev.modify_port = mthca_modify_port; 1283 dev->ib_dev.modify_port = mthca_modify_port;
1132 dev->ib_dev.query_pkey = mthca_query_pkey; 1284 dev->ib_dev.query_pkey = mthca_query_pkey;
1133 dev->ib_dev.query_gid = mthca_query_gid; 1285 dev->ib_dev.query_gid = mthca_query_gid;
@@ -1137,11 +1289,13 @@ int mthca_register_device(struct mthca_dev *dev)
1137 dev->ib_dev.alloc_pd = mthca_alloc_pd; 1289 dev->ib_dev.alloc_pd = mthca_alloc_pd;
1138 dev->ib_dev.dealloc_pd = mthca_dealloc_pd; 1290 dev->ib_dev.dealloc_pd = mthca_dealloc_pd;
1139 dev->ib_dev.create_ah = mthca_ah_create; 1291 dev->ib_dev.create_ah = mthca_ah_create;
1292 dev->ib_dev.query_ah = mthca_ah_query;
1140 dev->ib_dev.destroy_ah = mthca_ah_destroy; 1293 dev->ib_dev.destroy_ah = mthca_ah_destroy;
1141 1294
1142 if (dev->mthca_flags & MTHCA_FLAG_SRQ) { 1295 if (dev->mthca_flags & MTHCA_FLAG_SRQ) {
1143 dev->ib_dev.create_srq = mthca_create_srq; 1296 dev->ib_dev.create_srq = mthca_create_srq;
1144 dev->ib_dev.modify_srq = mthca_modify_srq; 1297 dev->ib_dev.modify_srq = mthca_modify_srq;
1298 dev->ib_dev.query_srq = mthca_query_srq;
1145 dev->ib_dev.destroy_srq = mthca_destroy_srq; 1299 dev->ib_dev.destroy_srq = mthca_destroy_srq;
1146 1300
1147 if (mthca_is_memfree(dev)) 1301 if (mthca_is_memfree(dev))
@@ -1152,8 +1306,10 @@ int mthca_register_device(struct mthca_dev *dev)
1152 1306
1153 dev->ib_dev.create_qp = mthca_create_qp; 1307 dev->ib_dev.create_qp = mthca_create_qp;
1154 dev->ib_dev.modify_qp = mthca_modify_qp; 1308 dev->ib_dev.modify_qp = mthca_modify_qp;
1309 dev->ib_dev.query_qp = mthca_query_qp;
1155 dev->ib_dev.destroy_qp = mthca_destroy_qp; 1310 dev->ib_dev.destroy_qp = mthca_destroy_qp;
1156 dev->ib_dev.create_cq = mthca_create_cq; 1311 dev->ib_dev.create_cq = mthca_create_cq;
1312 dev->ib_dev.resize_cq = mthca_resize_cq;
1157 dev->ib_dev.destroy_cq = mthca_destroy_cq; 1313 dev->ib_dev.destroy_cq = mthca_destroy_cq;
1158 dev->ib_dev.poll_cq = mthca_poll_cq; 1314 dev->ib_dev.poll_cq = mthca_poll_cq;
1159 dev->ib_dev.get_dma_mr = mthca_get_dma_mr; 1315 dev->ib_dev.get_dma_mr = mthca_get_dma_mr;
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.h b/drivers/infiniband/hw/mthca/mthca_provider.h
index 1e73947b4702..2e7f52136965 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.h
+++ b/drivers/infiniband/hw/mthca/mthca_provider.h
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 3 * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
5 * 5 *
6 * This software is available to you under a choice of one of two 6 * This software is available to you under a choice of one of two
@@ -164,9 +164,11 @@ struct mthca_ah {
164 * - wait_event until ref count is zero 164 * - wait_event until ref count is zero
165 * 165 *
166 * It is the consumer's responsibilty to make sure that no QP 166 * It is the consumer's responsibilty to make sure that no QP
167 * operations (WQE posting or state modification) are pending when the 167 * operations (WQE posting or state modification) are pending when a
168 * QP is destroyed. Also, the consumer must make sure that calls to 168 * QP is destroyed. Also, the consumer must make sure that calls to
169 * qp_modify are serialized. 169 * qp_modify are serialized. Similarly, the consumer is responsible
170 * for ensuring that no CQ resize operations are pending when a CQ
171 * is destroyed.
170 * 172 *
171 * Possible optimizations (wait for profile data to see if/where we 173 * Possible optimizations (wait for profile data to see if/where we
172 * have locks bouncing between CPUs): 174 * have locks bouncing between CPUs):
@@ -176,25 +178,40 @@ struct mthca_ah {
176 * send queue and one for the receive queue) 178 * send queue and one for the receive queue)
177 */ 179 */
178 180
181struct mthca_cq_buf {
182 union mthca_buf queue;
183 struct mthca_mr mr;
184 int is_direct;
185};
186
187struct mthca_cq_resize {
188 struct mthca_cq_buf buf;
189 int cqe;
190 enum {
191 CQ_RESIZE_ALLOC,
192 CQ_RESIZE_READY,
193 CQ_RESIZE_SWAPPED
194 } state;
195};
196
179struct mthca_cq { 197struct mthca_cq {
180 struct ib_cq ibcq; 198 struct ib_cq ibcq;
181 spinlock_t lock; 199 spinlock_t lock;
182 atomic_t refcount; 200 atomic_t refcount;
183 int cqn; 201 int cqn;
184 u32 cons_index; 202 u32 cons_index;
185 int is_direct; 203 struct mthca_cq_buf buf;
186 int is_kernel; 204 struct mthca_cq_resize *resize_buf;
205 int is_kernel;
187 206
188 /* Next fields are Arbel only */ 207 /* Next fields are Arbel only */
189 int set_ci_db_index; 208 int set_ci_db_index;
190 __be32 *set_ci_db; 209 __be32 *set_ci_db;
191 int arm_db_index; 210 int arm_db_index;
192 __be32 *arm_db; 211 __be32 *arm_db;
193 int arm_sn; 212 int arm_sn;
194 213
195 union mthca_buf queue; 214 wait_queue_head_t wait;
196 struct mthca_mr mr;
197 wait_queue_head_t wait;
198}; 215};
199 216
200struct mthca_srq { 217struct mthca_srq {
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index fba608ed7df2..f673c461e30b 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -2,7 +2,7 @@
2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
5 * Copyright (c) 2004 Voltaire, Inc. All rights reserved. 5 * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
6 * 6 *
7 * This software is available to you under a choice of one of two 7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU 8 * licenses. You may choose to be licensed under the terms of the GNU
@@ -286,207 +286,6 @@ static int to_mthca_st(int transport)
286 } 286 }
287} 287}
288 288
289static const struct {
290 int trans;
291 u32 req_param[NUM_TRANS];
292 u32 opt_param[NUM_TRANS];
293} state_table[IB_QPS_ERR + 1][IB_QPS_ERR + 1] = {
294 [IB_QPS_RESET] = {
295 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
296 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
297 [IB_QPS_INIT] = {
298 .trans = MTHCA_TRANS_RST2INIT,
299 .req_param = {
300 [UD] = (IB_QP_PKEY_INDEX |
301 IB_QP_PORT |
302 IB_QP_QKEY),
303 [UC] = (IB_QP_PKEY_INDEX |
304 IB_QP_PORT |
305 IB_QP_ACCESS_FLAGS),
306 [RC] = (IB_QP_PKEY_INDEX |
307 IB_QP_PORT |
308 IB_QP_ACCESS_FLAGS),
309 [MLX] = (IB_QP_PKEY_INDEX |
310 IB_QP_QKEY),
311 },
312 /* bug-for-bug compatibility with VAPI: */
313 .opt_param = {
314 [MLX] = IB_QP_PORT
315 }
316 },
317 },
318 [IB_QPS_INIT] = {
319 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
320 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
321 [IB_QPS_INIT] = {
322 .trans = MTHCA_TRANS_INIT2INIT,
323 .opt_param = {
324 [UD] = (IB_QP_PKEY_INDEX |
325 IB_QP_PORT |
326 IB_QP_QKEY),
327 [UC] = (IB_QP_PKEY_INDEX |
328 IB_QP_PORT |
329 IB_QP_ACCESS_FLAGS),
330 [RC] = (IB_QP_PKEY_INDEX |
331 IB_QP_PORT |
332 IB_QP_ACCESS_FLAGS),
333 [MLX] = (IB_QP_PKEY_INDEX |
334 IB_QP_QKEY),
335 }
336 },
337 [IB_QPS_RTR] = {
338 .trans = MTHCA_TRANS_INIT2RTR,
339 .req_param = {
340 [UC] = (IB_QP_AV |
341 IB_QP_PATH_MTU |
342 IB_QP_DEST_QPN |
343 IB_QP_RQ_PSN),
344 [RC] = (IB_QP_AV |
345 IB_QP_PATH_MTU |
346 IB_QP_DEST_QPN |
347 IB_QP_RQ_PSN |
348 IB_QP_MAX_DEST_RD_ATOMIC |
349 IB_QP_MIN_RNR_TIMER),
350 },
351 .opt_param = {
352 [UD] = (IB_QP_PKEY_INDEX |
353 IB_QP_QKEY),
354 [UC] = (IB_QP_ALT_PATH |
355 IB_QP_ACCESS_FLAGS |
356 IB_QP_PKEY_INDEX),
357 [RC] = (IB_QP_ALT_PATH |
358 IB_QP_ACCESS_FLAGS |
359 IB_QP_PKEY_INDEX),
360 [MLX] = (IB_QP_PKEY_INDEX |
361 IB_QP_QKEY),
362 }
363 }
364 },
365 [IB_QPS_RTR] = {
366 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
367 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
368 [IB_QPS_RTS] = {
369 .trans = MTHCA_TRANS_RTR2RTS,
370 .req_param = {
371 [UD] = IB_QP_SQ_PSN,
372 [UC] = IB_QP_SQ_PSN,
373 [RC] = (IB_QP_TIMEOUT |
374 IB_QP_RETRY_CNT |
375 IB_QP_RNR_RETRY |
376 IB_QP_SQ_PSN |
377 IB_QP_MAX_QP_RD_ATOMIC),
378 [MLX] = IB_QP_SQ_PSN,
379 },
380 .opt_param = {
381 [UD] = (IB_QP_CUR_STATE |
382 IB_QP_QKEY),
383 [UC] = (IB_QP_CUR_STATE |
384 IB_QP_ALT_PATH |
385 IB_QP_ACCESS_FLAGS |
386 IB_QP_PATH_MIG_STATE),
387 [RC] = (IB_QP_CUR_STATE |
388 IB_QP_ALT_PATH |
389 IB_QP_ACCESS_FLAGS |
390 IB_QP_MIN_RNR_TIMER |
391 IB_QP_PATH_MIG_STATE),
392 [MLX] = (IB_QP_CUR_STATE |
393 IB_QP_QKEY),
394 }
395 }
396 },
397 [IB_QPS_RTS] = {
398 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
399 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
400 [IB_QPS_RTS] = {
401 .trans = MTHCA_TRANS_RTS2RTS,
402 .opt_param = {
403 [UD] = (IB_QP_CUR_STATE |
404 IB_QP_QKEY),
405 [UC] = (IB_QP_ACCESS_FLAGS |
406 IB_QP_ALT_PATH |
407 IB_QP_PATH_MIG_STATE),
408 [RC] = (IB_QP_ACCESS_FLAGS |
409 IB_QP_ALT_PATH |
410 IB_QP_PATH_MIG_STATE |
411 IB_QP_MIN_RNR_TIMER),
412 [MLX] = (IB_QP_CUR_STATE |
413 IB_QP_QKEY),
414 }
415 },
416 [IB_QPS_SQD] = {
417 .trans = MTHCA_TRANS_RTS2SQD,
418 },
419 },
420 [IB_QPS_SQD] = {
421 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
422 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
423 [IB_QPS_RTS] = {
424 .trans = MTHCA_TRANS_SQD2RTS,
425 .opt_param = {
426 [UD] = (IB_QP_CUR_STATE |
427 IB_QP_QKEY),
428 [UC] = (IB_QP_CUR_STATE |
429 IB_QP_ALT_PATH |
430 IB_QP_ACCESS_FLAGS |
431 IB_QP_PATH_MIG_STATE),
432 [RC] = (IB_QP_CUR_STATE |
433 IB_QP_ALT_PATH |
434 IB_QP_ACCESS_FLAGS |
435 IB_QP_MIN_RNR_TIMER |
436 IB_QP_PATH_MIG_STATE),
437 [MLX] = (IB_QP_CUR_STATE |
438 IB_QP_QKEY),
439 }
440 },
441 [IB_QPS_SQD] = {
442 .trans = MTHCA_TRANS_SQD2SQD,
443 .opt_param = {
444 [UD] = (IB_QP_PKEY_INDEX |
445 IB_QP_QKEY),
446 [UC] = (IB_QP_AV |
447 IB_QP_CUR_STATE |
448 IB_QP_ALT_PATH |
449 IB_QP_ACCESS_FLAGS |
450 IB_QP_PKEY_INDEX |
451 IB_QP_PATH_MIG_STATE),
452 [RC] = (IB_QP_AV |
453 IB_QP_TIMEOUT |
454 IB_QP_RETRY_CNT |
455 IB_QP_RNR_RETRY |
456 IB_QP_MAX_QP_RD_ATOMIC |
457 IB_QP_MAX_DEST_RD_ATOMIC |
458 IB_QP_CUR_STATE |
459 IB_QP_ALT_PATH |
460 IB_QP_ACCESS_FLAGS |
461 IB_QP_PKEY_INDEX |
462 IB_QP_MIN_RNR_TIMER |
463 IB_QP_PATH_MIG_STATE),
464 [MLX] = (IB_QP_PKEY_INDEX |
465 IB_QP_QKEY),
466 }
467 }
468 },
469 [IB_QPS_SQE] = {
470 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
471 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
472 [IB_QPS_RTS] = {
473 .trans = MTHCA_TRANS_SQERR2RTS,
474 .opt_param = {
475 [UD] = (IB_QP_CUR_STATE |
476 IB_QP_QKEY),
477 [UC] = (IB_QP_CUR_STATE |
478 IB_QP_ACCESS_FLAGS),
479 [MLX] = (IB_QP_CUR_STATE |
480 IB_QP_QKEY),
481 }
482 }
483 },
484 [IB_QPS_ERR] = {
485 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
486 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR }
487 }
488};
489
490static void store_attrs(struct mthca_sqp *sqp, struct ib_qp_attr *attr, 289static void store_attrs(struct mthca_sqp *sqp, struct ib_qp_attr *attr,
491 int attr_mask) 290 int attr_mask)
492{ 291{
@@ -549,6 +348,141 @@ static __be32 get_hw_access_flags(struct mthca_qp *qp, struct ib_qp_attr *attr,
549 return cpu_to_be32(hw_access_flags); 348 return cpu_to_be32(hw_access_flags);
550} 349}
551 350
351static inline enum ib_qp_state to_ib_qp_state(int mthca_state)
352{
353 switch (mthca_state) {
354 case MTHCA_QP_STATE_RST: return IB_QPS_RESET;
355 case MTHCA_QP_STATE_INIT: return IB_QPS_INIT;
356 case MTHCA_QP_STATE_RTR: return IB_QPS_RTR;
357 case MTHCA_QP_STATE_RTS: return IB_QPS_RTS;
358 case MTHCA_QP_STATE_DRAINING:
359 case MTHCA_QP_STATE_SQD: return IB_QPS_SQD;
360 case MTHCA_QP_STATE_SQE: return IB_QPS_SQE;
361 case MTHCA_QP_STATE_ERR: return IB_QPS_ERR;
362 default: return -1;
363 }
364}
365
366static inline enum ib_mig_state to_ib_mig_state(int mthca_mig_state)
367{
368 switch (mthca_mig_state) {
369 case 0: return IB_MIG_ARMED;
370 case 1: return IB_MIG_REARM;
371 case 3: return IB_MIG_MIGRATED;
372 default: return -1;
373 }
374}
375
376static int to_ib_qp_access_flags(int mthca_flags)
377{
378 int ib_flags = 0;
379
380 if (mthca_flags & MTHCA_QP_BIT_RRE)
381 ib_flags |= IB_ACCESS_REMOTE_READ;
382 if (mthca_flags & MTHCA_QP_BIT_RWE)
383 ib_flags |= IB_ACCESS_REMOTE_WRITE;
384 if (mthca_flags & MTHCA_QP_BIT_RAE)
385 ib_flags |= IB_ACCESS_REMOTE_ATOMIC;
386
387 return ib_flags;
388}
389
390static void to_ib_ah_attr(struct mthca_dev *dev, struct ib_ah_attr *ib_ah_attr,
391 struct mthca_qp_path *path)
392{
393 memset(ib_ah_attr, 0, sizeof *path);
394 ib_ah_attr->port_num = (be32_to_cpu(path->port_pkey) >> 24) & 0x3;
395 ib_ah_attr->dlid = be16_to_cpu(path->rlid);
396 ib_ah_attr->sl = be32_to_cpu(path->sl_tclass_flowlabel) >> 28;
397 ib_ah_attr->src_path_bits = path->g_mylmc & 0x7f;
398 ib_ah_attr->static_rate = path->static_rate & 0x7;
399 ib_ah_attr->ah_flags = (path->g_mylmc & (1 << 7)) ? IB_AH_GRH : 0;
400 if (ib_ah_attr->ah_flags) {
401 ib_ah_attr->grh.sgid_index = path->mgid_index & (dev->limits.gid_table_len - 1);
402 ib_ah_attr->grh.hop_limit = path->hop_limit;
403 ib_ah_attr->grh.traffic_class =
404 (be32_to_cpu(path->sl_tclass_flowlabel) >> 20) & 0xff;
405 ib_ah_attr->grh.flow_label =
406 be32_to_cpu(path->sl_tclass_flowlabel) & 0xfffff;
407 memcpy(ib_ah_attr->grh.dgid.raw,
408 path->rgid, sizeof ib_ah_attr->grh.dgid.raw);
409 }
410}
411
412int mthca_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
413 struct ib_qp_init_attr *qp_init_attr)
414{
415 struct mthca_dev *dev = to_mdev(ibqp->device);
416 struct mthca_qp *qp = to_mqp(ibqp);
417 int err;
418 struct mthca_mailbox *mailbox;
419 struct mthca_qp_param *qp_param;
420 struct mthca_qp_context *context;
421 int mthca_state;
422 u8 status;
423
424 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
425 if (IS_ERR(mailbox))
426 return PTR_ERR(mailbox);
427
428 err = mthca_QUERY_QP(dev, qp->qpn, 0, mailbox, &status);
429 if (err)
430 goto out;
431 if (status) {
432 mthca_warn(dev, "QUERY_QP returned status %02x\n", status);
433 err = -EINVAL;
434 goto out;
435 }
436
437 qp_param = mailbox->buf;
438 context = &qp_param->context;
439 mthca_state = be32_to_cpu(context->flags) >> 28;
440
441 qp_attr->qp_state = to_ib_qp_state(mthca_state);
442 qp_attr->cur_qp_state = qp_attr->qp_state;
443 qp_attr->path_mtu = context->mtu_msgmax >> 5;
444 qp_attr->path_mig_state =
445 to_ib_mig_state((be32_to_cpu(context->flags) >> 11) & 0x3);
446 qp_attr->qkey = be32_to_cpu(context->qkey);
447 qp_attr->rq_psn = be32_to_cpu(context->rnr_nextrecvpsn) & 0xffffff;
448 qp_attr->sq_psn = be32_to_cpu(context->next_send_psn) & 0xffffff;
449 qp_attr->dest_qp_num = be32_to_cpu(context->remote_qpn) & 0xffffff;
450 qp_attr->qp_access_flags =
451 to_ib_qp_access_flags(be32_to_cpu(context->params2));
452 qp_attr->cap.max_send_wr = qp->sq.max;
453 qp_attr->cap.max_recv_wr = qp->rq.max;
454 qp_attr->cap.max_send_sge = qp->sq.max_gs;
455 qp_attr->cap.max_recv_sge = qp->rq.max_gs;
456 qp_attr->cap.max_inline_data = qp->max_inline_data;
457
458 to_ib_ah_attr(dev, &qp_attr->ah_attr, &context->pri_path);
459 to_ib_ah_attr(dev, &qp_attr->alt_ah_attr, &context->alt_path);
460
461 qp_attr->pkey_index = be32_to_cpu(context->pri_path.port_pkey) & 0x7f;
462 qp_attr->alt_pkey_index = be32_to_cpu(context->alt_path.port_pkey) & 0x7f;
463
464 /* qp_attr->en_sqd_async_notify is only applicable in modify qp */
465 qp_attr->sq_draining = mthca_state == MTHCA_QP_STATE_DRAINING;
466
467 qp_attr->max_rd_atomic = 1 << ((be32_to_cpu(context->params1) >> 21) & 0x7);
468
469 qp_attr->max_dest_rd_atomic =
470 1 << ((be32_to_cpu(context->params2) >> 21) & 0x7);
471 qp_attr->min_rnr_timer =
472 (be32_to_cpu(context->rnr_nextrecvpsn) >> 24) & 0x1f;
473 qp_attr->port_num = qp_attr->ah_attr.port_num;
474 qp_attr->timeout = context->pri_path.ackto >> 3;
475 qp_attr->retry_cnt = (be32_to_cpu(context->params1) >> 16) & 0x7;
476 qp_attr->rnr_retry = context->pri_path.rnr_retry >> 5;
477 qp_attr->alt_port_num = qp_attr->alt_ah_attr.port_num;
478 qp_attr->alt_timeout = context->alt_path.ackto >> 3;
479 qp_init_attr->cap = qp_attr->cap;
480
481out:
482 mthca_free_mailbox(dev, mailbox);
483 return err;
484}
485
552static void mthca_path_set(struct ib_ah_attr *ah, struct mthca_qp_path *path) 486static void mthca_path_set(struct ib_ah_attr *ah, struct mthca_qp_path *path)
553{ 487{
554 path->g_mylmc = ah->src_path_bits & 0x7f; 488 path->g_mylmc = ah->src_path_bits & 0x7f;
@@ -559,9 +493,9 @@ static void mthca_path_set(struct ib_ah_attr *ah, struct mthca_qp_path *path)
559 path->g_mylmc |= 1 << 7; 493 path->g_mylmc |= 1 << 7;
560 path->mgid_index = ah->grh.sgid_index; 494 path->mgid_index = ah->grh.sgid_index;
561 path->hop_limit = ah->grh.hop_limit; 495 path->hop_limit = ah->grh.hop_limit;
562 path->sl_tclass_flowlabel = 496 path->sl_tclass_flowlabel =
563 cpu_to_be32((ah->sl << 28) | 497 cpu_to_be32((ah->sl << 28) |
564 (ah->grh.traffic_class << 20) | 498 (ah->grh.traffic_class << 20) |
565 (ah->grh.flow_label)); 499 (ah->grh.flow_label));
566 memcpy(path->rgid, ah->grh.dgid.raw, 16); 500 memcpy(path->rgid, ah->grh.dgid.raw, 16);
567 } else 501 } else
@@ -576,18 +510,12 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
576 struct mthca_mailbox *mailbox; 510 struct mthca_mailbox *mailbox;
577 struct mthca_qp_param *qp_param; 511 struct mthca_qp_param *qp_param;
578 struct mthca_qp_context *qp_context; 512 struct mthca_qp_context *qp_context;
579 u32 req_param, opt_param; 513 u32 sqd_event = 0;
580 u8 status; 514 u8 status;
581 int err; 515 int err;
582 516
583 if (attr_mask & IB_QP_CUR_STATE) { 517 if (attr_mask & IB_QP_CUR_STATE) {
584 if (attr->cur_qp_state != IB_QPS_RTR && 518 cur_state = attr->cur_qp_state;
585 attr->cur_qp_state != IB_QPS_RTS &&
586 attr->cur_qp_state != IB_QPS_SQD &&
587 attr->cur_qp_state != IB_QPS_SQE)
588 return -EINVAL;
589 else
590 cur_state = attr->cur_qp_state;
591 } else { 519 } else {
592 spin_lock_irq(&qp->sq.lock); 520 spin_lock_irq(&qp->sq.lock);
593 spin_lock(&qp->rq.lock); 521 spin_lock(&qp->rq.lock);
@@ -596,44 +524,20 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
596 spin_unlock_irq(&qp->sq.lock); 524 spin_unlock_irq(&qp->sq.lock);
597 } 525 }
598 526
599 if (attr_mask & IB_QP_STATE) { 527 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
600 if (attr->qp_state < 0 || attr->qp_state > IB_QPS_ERR)
601 return -EINVAL;
602 new_state = attr->qp_state;
603 } else
604 new_state = cur_state;
605
606 if (state_table[cur_state][new_state].trans == MTHCA_TRANS_INVALID) {
607 mthca_dbg(dev, "Illegal QP transition "
608 "%d->%d\n", cur_state, new_state);
609 return -EINVAL;
610 }
611
612 req_param = state_table[cur_state][new_state].req_param[qp->transport];
613 opt_param = state_table[cur_state][new_state].opt_param[qp->transport];
614 528
615 if ((req_param & attr_mask) != req_param) { 529 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type, attr_mask)) {
616 mthca_dbg(dev, "QP transition " 530 mthca_dbg(dev, "Bad QP transition (transport %d) "
617 "%d->%d missing req attr 0x%08x\n", 531 "%d->%d with attr 0x%08x\n",
618 cur_state, new_state, 532 qp->transport, cur_state, new_state,
619 req_param & ~attr_mask); 533 attr_mask);
620 return -EINVAL; 534 return -EINVAL;
621 } 535 }
622 536
623 if (attr_mask & ~(req_param | opt_param | IB_QP_STATE)) { 537 if ((attr_mask & IB_QP_PKEY_INDEX) &&
624 mthca_dbg(dev, "QP transition (transport %d) "
625 "%d->%d has extra attr 0x%08x\n",
626 qp->transport,
627 cur_state, new_state,
628 attr_mask & ~(req_param | opt_param |
629 IB_QP_STATE));
630 return -EINVAL;
631 }
632
633 if ((attr_mask & IB_QP_PKEY_INDEX) &&
634 attr->pkey_index >= dev->limits.pkey_table_len) { 538 attr->pkey_index >= dev->limits.pkey_table_len) {
635 mthca_dbg(dev, "PKey index (%u) too large. max is %d\n", 539 mthca_dbg(dev, "P_Key index (%u) too large. max is %d\n",
636 attr->pkey_index,dev->limits.pkey_table_len-1); 540 attr->pkey_index, dev->limits.pkey_table_len-1);
637 return -EINVAL; 541 return -EINVAL;
638 } 542 }
639 543
@@ -733,7 +637,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
733 if (attr_mask & IB_QP_RNR_RETRY) { 637 if (attr_mask & IB_QP_RNR_RETRY) {
734 qp_context->alt_path.rnr_retry = qp_context->pri_path.rnr_retry = 638 qp_context->alt_path.rnr_retry = qp_context->pri_path.rnr_retry =
735 attr->rnr_retry << 5; 639 attr->rnr_retry << 5;
736 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RNR_RETRY | 640 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RNR_RETRY |
737 MTHCA_QP_OPTPAR_ALT_RNR_RETRY); 641 MTHCA_QP_OPTPAR_ALT_RNR_RETRY);
738 } 642 }
739 643
@@ -748,14 +652,20 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
748 } 652 }
749 653
750 if (attr_mask & IB_QP_ALT_PATH) { 654 if (attr_mask & IB_QP_ALT_PATH) {
655 if (attr->alt_pkey_index >= dev->limits.pkey_table_len) {
656 mthca_dbg(dev, "Alternate P_Key index (%u) too large. max is %d\n",
657 attr->alt_pkey_index, dev->limits.pkey_table_len-1);
658 return -EINVAL;
659 }
660
751 if (attr->alt_port_num == 0 || attr->alt_port_num > dev->limits.num_ports) { 661 if (attr->alt_port_num == 0 || attr->alt_port_num > dev->limits.num_ports) {
752 mthca_dbg(dev, "Alternate port number (%u) is invalid\n", 662 mthca_dbg(dev, "Alternate port number (%u) is invalid\n",
753 attr->alt_port_num); 663 attr->alt_port_num);
754 return -EINVAL; 664 return -EINVAL;
755 } 665 }
756 666
757 mthca_path_set(&attr->alt_ah_attr, &qp_context->alt_path); 667 mthca_path_set(&attr->alt_ah_attr, &qp_context->alt_path);
758 qp_context->alt_path.port_pkey |= cpu_to_be32(attr->alt_pkey_index | 668 qp_context->alt_path.port_pkey |= cpu_to_be32(attr->alt_pkey_index |
759 attr->alt_port_num << 24); 669 attr->alt_port_num << 24);
760 qp_context->alt_path.ackto = attr->alt_timeout << 3; 670 qp_context->alt_path.ackto = attr->alt_timeout << 3;
761 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_ALT_ADDR_PATH); 671 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_ALT_ADDR_PATH);
@@ -841,11 +751,16 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
841 qp_context->srqn = cpu_to_be32(1 << 24 | 751 qp_context->srqn = cpu_to_be32(1 << 24 |
842 to_msrq(ibqp->srq)->srqn); 752 to_msrq(ibqp->srq)->srqn);
843 753
844 err = mthca_MODIFY_QP(dev, state_table[cur_state][new_state].trans, 754 if (cur_state == IB_QPS_RTS && new_state == IB_QPS_SQD &&
845 qp->qpn, 0, mailbox, 0, &status); 755 attr_mask & IB_QP_EN_SQD_ASYNC_NOTIFY &&
756 attr->en_sqd_async_notify)
757 sqd_event = 1 << 31;
758
759 err = mthca_MODIFY_QP(dev, cur_state, new_state, qp->qpn, 0,
760 mailbox, sqd_event, &status);
846 if (status) { 761 if (status) {
847 mthca_warn(dev, "modify QP %d returned status %02x.\n", 762 mthca_warn(dev, "modify QP %d->%d returned status %02x.\n",
848 state_table[cur_state][new_state].trans, status); 763 cur_state, new_state, status);
849 err = -EINVAL; 764 err = -EINVAL;
850 } 765 }
851 766
@@ -1078,10 +993,10 @@ static int mthca_map_memfree(struct mthca_dev *dev,
1078 if (ret) 993 if (ret)
1079 goto err_qpc; 994 goto err_qpc;
1080 995
1081 ret = mthca_table_get(dev, dev->qp_table.rdb_table, 996 ret = mthca_table_get(dev, dev->qp_table.rdb_table,
1082 qp->qpn << dev->qp_table.rdb_shift); 997 qp->qpn << dev->qp_table.rdb_shift);
1083 if (ret) 998 if (ret)
1084 goto err_eqpc; 999 goto err_eqpc;
1085 1000
1086 } 1001 }
1087 1002
@@ -1393,7 +1308,8 @@ void mthca_free_qp(struct mthca_dev *dev,
1393 wait_event(qp->wait, !atomic_read(&qp->refcount)); 1308 wait_event(qp->wait, !atomic_read(&qp->refcount));
1394 1309
1395 if (qp->state != IB_QPS_RESET) 1310 if (qp->state != IB_QPS_RESET)
1396 mthca_MODIFY_QP(dev, MTHCA_TRANS_ANY2RST, qp->qpn, 0, NULL, 0, &status); 1311 mthca_MODIFY_QP(dev, qp->state, IB_QPS_RESET, qp->qpn, 0,
1312 NULL, 0, &status);
1397 1313
1398 /* 1314 /*
1399 * If this is a userspace QP, the buffers, MR, CQs and so on 1315 * If this is a userspace QP, the buffers, MR, CQs and so on
@@ -1699,7 +1615,9 @@ int mthca_tavor_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1699 mthca_opcode[wr->opcode]); 1615 mthca_opcode[wr->opcode]);
1700 wmb(); 1616 wmb();
1701 ((struct mthca_next_seg *) prev_wqe)->ee_nds = 1617 ((struct mthca_next_seg *) prev_wqe)->ee_nds =
1702 cpu_to_be32((size0 ? 0 : MTHCA_NEXT_DBD) | size); 1618 cpu_to_be32((size0 ? 0 : MTHCA_NEXT_DBD) | size |
1619 ((wr->send_flags & IB_SEND_FENCE) ?
1620 MTHCA_NEXT_FENCE : 0));
1703 1621
1704 if (!size0) { 1622 if (!size0) {
1705 size0 = size; 1623 size0 = size;
@@ -2061,7 +1979,9 @@ int mthca_arbel_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
2061 mthca_opcode[wr->opcode]); 1979 mthca_opcode[wr->opcode]);
2062 wmb(); 1980 wmb();
2063 ((struct mthca_next_seg *) prev_wqe)->ee_nds = 1981 ((struct mthca_next_seg *) prev_wqe)->ee_nds =
2064 cpu_to_be32(MTHCA_NEXT_DBD | size); 1982 cpu_to_be32(MTHCA_NEXT_DBD | size |
1983 ((wr->send_flags & IB_SEND_FENCE) ?
1984 MTHCA_NEXT_FENCE : 0));
2065 1985
2066 if (!size0) { 1986 if (!size0) {
2067 size0 = size; 1987 size0 = size;
@@ -2115,7 +2035,7 @@ int mthca_arbel_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
2115 int i; 2035 int i;
2116 void *wqe; 2036 void *wqe;
2117 2037
2118 spin_lock_irqsave(&qp->rq.lock, flags); 2038 spin_lock_irqsave(&qp->rq.lock, flags);
2119 2039
2120 /* XXX check that state is OK to post receive */ 2040 /* XXX check that state is OK to post receive */
2121 2041
@@ -2182,8 +2102,8 @@ out:
2182 return err; 2102 return err;
2183} 2103}
2184 2104
2185int mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send, 2105void mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,
2186 int index, int *dbd, __be32 *new_wqe) 2106 int index, int *dbd, __be32 *new_wqe)
2187{ 2107{
2188 struct mthca_next_seg *next; 2108 struct mthca_next_seg *next;
2189 2109
@@ -2193,7 +2113,7 @@ int mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,
2193 */ 2113 */
2194 if (qp->ibqp.srq) { 2114 if (qp->ibqp.srq) {
2195 *new_wqe = 0; 2115 *new_wqe = 0;
2196 return 0; 2116 return;
2197 } 2117 }
2198 2118
2199 if (is_send) 2119 if (is_send)
@@ -2207,8 +2127,6 @@ int mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,
2207 (next->ee_nds & cpu_to_be32(0x3f)); 2127 (next->ee_nds & cpu_to_be32(0x3f));
2208 else 2128 else
2209 *new_wqe = 0; 2129 *new_wqe = 0;
2210
2211 return 0;
2212} 2130}
2213 2131
2214int __devinit mthca_init_qp_table(struct mthca_dev *dev) 2132int __devinit mthca_init_qp_table(struct mthca_dev *dev)
diff --git a/drivers/infiniband/hw/mthca/mthca_srq.c b/drivers/infiniband/hw/mthca/mthca_srq.c
index e7e153d9c4c6..47a6a754a591 100644
--- a/drivers/infiniband/hw/mthca/mthca_srq.c
+++ b/drivers/infiniband/hw/mthca/mthca_srq.c
@@ -49,7 +49,8 @@ struct mthca_tavor_srq_context {
49 __be32 state_pd; 49 __be32 state_pd;
50 __be32 lkey; 50 __be32 lkey;
51 __be32 uar; 51 __be32 uar;
52 __be32 wqe_cnt; 52 __be16 limit_watermark;
53 __be16 wqe_cnt;
53 u32 reserved[2]; 54 u32 reserved[2];
54}; 55};
55 56
@@ -271,6 +272,9 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
271 srq->first_free = 0; 272 srq->first_free = 0;
272 srq->last_free = srq->max - 1; 273 srq->last_free = srq->max - 1;
273 274
275 attr->max_wr = (mthca_is_memfree(dev)) ? srq->max - 1 : srq->max;
276 attr->max_sge = srq->max_gs;
277
274 return 0; 278 return 0;
275 279
276err_out_free_srq: 280err_out_free_srq:
@@ -339,7 +343,7 @@ void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq)
339 343
340int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, 344int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
341 enum ib_srq_attr_mask attr_mask) 345 enum ib_srq_attr_mask attr_mask)
342{ 346{
343 struct mthca_dev *dev = to_mdev(ibsrq->device); 347 struct mthca_dev *dev = to_mdev(ibsrq->device);
344 struct mthca_srq *srq = to_msrq(ibsrq); 348 struct mthca_srq *srq = to_msrq(ibsrq);
345 int ret; 349 int ret;
@@ -360,6 +364,41 @@ int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
360 return 0; 364 return 0;
361} 365}
362 366
367int mthca_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr)
368{
369 struct mthca_dev *dev = to_mdev(ibsrq->device);
370 struct mthca_srq *srq = to_msrq(ibsrq);
371 struct mthca_mailbox *mailbox;
372 struct mthca_arbel_srq_context *arbel_ctx;
373 struct mthca_tavor_srq_context *tavor_ctx;
374 u8 status;
375 int err;
376
377 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
378 if (IS_ERR(mailbox))
379 return PTR_ERR(mailbox);
380
381 err = mthca_QUERY_SRQ(dev, srq->srqn, mailbox, &status);
382 if (err)
383 goto out;
384
385 if (mthca_is_memfree(dev)) {
386 arbel_ctx = mailbox->buf;
387 srq_attr->srq_limit = be16_to_cpu(arbel_ctx->limit_watermark);
388 } else {
389 tavor_ctx = mailbox->buf;
390 srq_attr->srq_limit = be16_to_cpu(tavor_ctx->limit_watermark);
391 }
392
393 srq_attr->max_wr = (mthca_is_memfree(dev)) ? srq->max - 1 : srq->max;
394 srq_attr->max_sge = srq->max_gs;
395
396out:
397 mthca_free_mailbox(dev, mailbox);
398
399 return err;
400}
401
363void mthca_srq_event(struct mthca_dev *dev, u32 srqn, 402void mthca_srq_event(struct mthca_dev *dev, u32 srqn,
364 enum ib_event_type event_type) 403 enum ib_event_type event_type)
365{ 404{
diff --git a/drivers/infiniband/hw/mthca/mthca_user.h b/drivers/infiniband/hw/mthca/mthca_user.h
index bb015c6494c4..02cc0a766f3a 100644
--- a/drivers/infiniband/hw/mthca/mthca_user.h
+++ b/drivers/infiniband/hw/mthca/mthca_user.h
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 3 * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
4 * 4 *
5 * This software is available to you under a choice of one of two 5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 6 * licenses. You may choose to be licensed under the terms of the GNU
@@ -75,6 +75,11 @@ struct mthca_create_cq_resp {
75 __u32 reserved; 75 __u32 reserved;
76}; 76};
77 77
78struct mthca_resize_cq {
79 __u32 lkey;
80 __u32 reserved;
81};
82
78struct mthca_create_srq { 83struct mthca_create_srq {
79 __u32 lkey; 84 __u32 lkey;
80 __u32 db_index; 85 __u32 db_index;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index 2f85a9a831b1..1251f86ec856 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -217,10 +217,16 @@ struct ipoib_neigh {
217 struct list_head list; 217 struct list_head list;
218}; 218};
219 219
220/*
221 * We stash a pointer to our private neighbour information after our
222 * hardware address in neigh->ha. The ALIGN() expression here makes
223 * sure that this pointer is stored aligned so that an unaligned
224 * load is not needed to dereference it.
225 */
220static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh) 226static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh)
221{ 227{
222 return (struct ipoib_neigh **) (neigh->ha + 24 - 228 return (void*) neigh + ALIGN(offsetof(struct neighbour, ha) +
223 (offsetof(struct neighbour, ha) & 4)); 229 INFINIBAND_ALEN, sizeof(void *));
224} 230}
225 231
226extern struct workqueue_struct *ipoib_workqueue; 232extern struct workqueue_struct *ipoib_workqueue;
@@ -253,7 +259,7 @@ void ipoib_ib_dev_cleanup(struct net_device *dev);
253 259
254int ipoib_ib_dev_open(struct net_device *dev); 260int ipoib_ib_dev_open(struct net_device *dev);
255int ipoib_ib_dev_up(struct net_device *dev); 261int ipoib_ib_dev_up(struct net_device *dev);
256int ipoib_ib_dev_down(struct net_device *dev); 262int ipoib_ib_dev_down(struct net_device *dev, int flush);
257int ipoib_ib_dev_stop(struct net_device *dev); 263int ipoib_ib_dev_stop(struct net_device *dev);
258 264
259int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port); 265int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index 86bcdd72a107..a1f5a05f2f36 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -416,6 +416,7 @@ int ipoib_ib_dev_open(struct net_device *dev)
416 ret = ipoib_ib_post_receives(dev); 416 ret = ipoib_ib_post_receives(dev);
417 if (ret) { 417 if (ret) {
418 ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret); 418 ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret);
419 ipoib_ib_dev_stop(dev);
419 return -1; 420 return -1;
420 } 421 }
421 422
@@ -434,7 +435,7 @@ int ipoib_ib_dev_up(struct net_device *dev)
434 return ipoib_mcast_start_thread(dev); 435 return ipoib_mcast_start_thread(dev);
435} 436}
436 437
437int ipoib_ib_dev_down(struct net_device *dev) 438int ipoib_ib_dev_down(struct net_device *dev, int flush)
438{ 439{
439 struct ipoib_dev_priv *priv = netdev_priv(dev); 440 struct ipoib_dev_priv *priv = netdev_priv(dev);
440 441
@@ -449,10 +450,11 @@ int ipoib_ib_dev_down(struct net_device *dev)
449 set_bit(IPOIB_PKEY_STOP, &priv->flags); 450 set_bit(IPOIB_PKEY_STOP, &priv->flags);
450 cancel_delayed_work(&priv->pkey_task); 451 cancel_delayed_work(&priv->pkey_task);
451 mutex_unlock(&pkey_mutex); 452 mutex_unlock(&pkey_mutex);
452 flush_workqueue(ipoib_workqueue); 453 if (flush)
454 flush_workqueue(ipoib_workqueue);
453 } 455 }
454 456
455 ipoib_mcast_stop_thread(dev, 1); 457 ipoib_mcast_stop_thread(dev, flush);
456 ipoib_mcast_dev_flush(dev); 458 ipoib_mcast_dev_flush(dev);
457 459
458 ipoib_flush_paths(dev); 460 ipoib_flush_paths(dev);
@@ -590,7 +592,7 @@ void ipoib_ib_dev_flush(void *_dev)
590 592
591 ipoib_dbg(priv, "flushing\n"); 593 ipoib_dbg(priv, "flushing\n");
592 594
593 ipoib_ib_dev_down(dev); 595 ipoib_ib_dev_down(dev, 0);
594 596
595 /* 597 /*
596 * The device could have been brought down between the start and when 598 * The device could have been brought down between the start and when
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index c3b5f79d1168..37da8d3dc388 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -133,7 +133,13 @@ static int ipoib_stop(struct net_device *dev)
133 133
134 netif_stop_queue(dev); 134 netif_stop_queue(dev);
135 135
136 ipoib_ib_dev_down(dev); 136 /*
137 * Now flush workqueue to make sure a scheduled task doesn't
138 * bring our internal state back up.
139 */
140 flush_workqueue(ipoib_workqueue);
141
142 ipoib_ib_dev_down(dev, 1);
137 ipoib_ib_dev_stop(dev); 143 ipoib_ib_dev_stop(dev);
138 144
139 if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) { 145 if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {
@@ -247,7 +253,6 @@ static void path_free(struct net_device *dev, struct ipoib_path *path)
247 if (neigh->ah) 253 if (neigh->ah)
248 ipoib_put_ah(neigh->ah); 254 ipoib_put_ah(neigh->ah);
249 *to_ipoib_neigh(neigh->neighbour) = NULL; 255 *to_ipoib_neigh(neigh->neighbour) = NULL;
250 neigh->neighbour->ops->destructor = NULL;
251 kfree(neigh); 256 kfree(neigh);
252 } 257 }
253 258
@@ -513,12 +518,7 @@ static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
513 be32_to_cpup((__be32 *) skb->dst->neighbour->ha)); 518 be32_to_cpup((__be32 *) skb->dst->neighbour->ha));
514 } else { 519 } else {
515 neigh->ah = NULL; 520 neigh->ah = NULL;
516 if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) { 521 __skb_queue_tail(&neigh->queue, skb);
517 __skb_queue_tail(&neigh->queue, skb);
518 } else {
519 ++priv->stats.tx_dropped;
520 dev_kfree_skb_any(skb);
521 }
522 522
523 if (!path->query && path_rec_start(dev, path)) 523 if (!path->query && path_rec_start(dev, path))
524 goto err; 524 goto err;
@@ -530,7 +530,6 @@ static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
530err: 530err:
531 *to_ipoib_neigh(skb->dst->neighbour) = NULL; 531 *to_ipoib_neigh(skb->dst->neighbour) = NULL;
532 list_del(&neigh->list); 532 list_del(&neigh->list);
533 neigh->neighbour->ops->destructor = NULL;
534 kfree(neigh); 533 kfree(neigh);
535 534
536 ++priv->stats.tx_dropped; 535 ++priv->stats.tx_dropped;
@@ -769,21 +768,9 @@ static void ipoib_neigh_destructor(struct neighbour *n)
769 ipoib_put_ah(ah); 768 ipoib_put_ah(ah);
770} 769}
771 770
772static int ipoib_neigh_setup(struct neighbour *neigh)
773{
774 /*
775 * Is this kosher? I can't find anybody in the kernel that
776 * sets neigh->destructor, so we should be able to set it here
777 * without trouble.
778 */
779 neigh->ops->destructor = ipoib_neigh_destructor;
780
781 return 0;
782}
783
784static int ipoib_neigh_setup_dev(struct net_device *dev, struct neigh_parms *parms) 771static int ipoib_neigh_setup_dev(struct net_device *dev, struct neigh_parms *parms)
785{ 772{
786 parms->neigh_setup = ipoib_neigh_setup; 773 parms->neigh_destructor = ipoib_neigh_destructor;
787 774
788 return 0; 775 return 0;
789} 776}
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index a2408d7ec598..93c462eaf4fd 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -115,7 +115,6 @@ static void ipoib_mcast_free(struct ipoib_mcast *mcast)
115 if (neigh->ah) 115 if (neigh->ah)
116 ipoib_put_ah(neigh->ah); 116 ipoib_put_ah(neigh->ah);
117 *to_ipoib_neigh(neigh->neighbour) = NULL; 117 *to_ipoib_neigh(neigh->neighbour) = NULL;
118 neigh->neighbour->ops->destructor = NULL;
119 kfree(neigh); 118 kfree(neigh);
120 } 119 }
121 120
@@ -213,6 +212,7 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
213{ 212{
214 struct net_device *dev = mcast->dev; 213 struct net_device *dev = mcast->dev;
215 struct ipoib_dev_priv *priv = netdev_priv(dev); 214 struct ipoib_dev_priv *priv = netdev_priv(dev);
215 struct ipoib_ah *ah;
216 int ret; 216 int ret;
217 217
218 mcast->mcmember = *mcmember; 218 mcast->mcmember = *mcmember;
@@ -269,8 +269,8 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
269 av.static_rate, priv->local_rate, 269 av.static_rate, priv->local_rate,
270 ib_sa_rate_enum_to_int(mcast->mcmember.rate)); 270 ib_sa_rate_enum_to_int(mcast->mcmember.rate));
271 271
272 mcast->ah = ipoib_create_ah(dev, priv->pd, &av); 272 ah = ipoib_create_ah(dev, priv->pd, &av);
273 if (!mcast->ah) { 273 if (!ah) {
274 ipoib_warn(priv, "ib_address_create failed\n"); 274 ipoib_warn(priv, "ib_address_create failed\n");
275 } else { 275 } else {
276 ipoib_dbg_mcast(priv, "MGID " IPOIB_GID_FMT 276 ipoib_dbg_mcast(priv, "MGID " IPOIB_GID_FMT
@@ -280,6 +280,10 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
280 be16_to_cpu(mcast->mcmember.mlid), 280 be16_to_cpu(mcast->mcmember.mlid),
281 mcast->mcmember.sl); 281 mcast->mcmember.sl);
282 } 282 }
283
284 spin_lock_irq(&priv->lock);
285 mcast->ah = ah;
286 spin_unlock_irq(&priv->lock);
283 } 287 }
284 288
285 /* actually send any queued packets */ 289 /* actually send any queued packets */
@@ -432,9 +436,11 @@ static void ipoib_mcast_join_complete(int status,
432 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) 436 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS)
433 mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS; 437 mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS;
434 438
439 mutex_lock(&mcast_mutex);
440
441 spin_lock_irq(&priv->lock);
435 mcast->query = NULL; 442 mcast->query = NULL;
436 443
437 mutex_lock(&mcast_mutex);
438 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) { 444 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) {
439 if (status == -ETIMEDOUT) 445 if (status == -ETIMEDOUT)
440 queue_work(ipoib_workqueue, &priv->mcast_task); 446 queue_work(ipoib_workqueue, &priv->mcast_task);
@@ -443,6 +449,7 @@ static void ipoib_mcast_join_complete(int status,
443 mcast->backoff * HZ); 449 mcast->backoff * HZ);
444 } else 450 } else
445 complete(&mcast->done); 451 complete(&mcast->done);
452 spin_unlock_irq(&priv->lock);
446 mutex_unlock(&mcast_mutex); 453 mutex_unlock(&mcast_mutex);
447 454
448 return; 455 return;
@@ -630,21 +637,27 @@ int ipoib_mcast_stop_thread(struct net_device *dev, int flush)
630 if (flush) 637 if (flush)
631 flush_workqueue(ipoib_workqueue); 638 flush_workqueue(ipoib_workqueue);
632 639
640 spin_lock_irq(&priv->lock);
633 if (priv->broadcast && priv->broadcast->query) { 641 if (priv->broadcast && priv->broadcast->query) {
634 ib_sa_cancel_query(priv->broadcast->query_id, priv->broadcast->query); 642 ib_sa_cancel_query(priv->broadcast->query_id, priv->broadcast->query);
635 priv->broadcast->query = NULL; 643 priv->broadcast->query = NULL;
644 spin_unlock_irq(&priv->lock);
636 ipoib_dbg_mcast(priv, "waiting for bcast\n"); 645 ipoib_dbg_mcast(priv, "waiting for bcast\n");
637 wait_for_completion(&priv->broadcast->done); 646 wait_for_completion(&priv->broadcast->done);
638 } 647 } else
648 spin_unlock_irq(&priv->lock);
639 649
640 list_for_each_entry(mcast, &priv->multicast_list, list) { 650 list_for_each_entry(mcast, &priv->multicast_list, list) {
651 spin_lock_irq(&priv->lock);
641 if (mcast->query) { 652 if (mcast->query) {
642 ib_sa_cancel_query(mcast->query_id, mcast->query); 653 ib_sa_cancel_query(mcast->query_id, mcast->query);
643 mcast->query = NULL; 654 mcast->query = NULL;
655 spin_unlock_irq(&priv->lock);
644 ipoib_dbg_mcast(priv, "waiting for MGID " IPOIB_GID_FMT "\n", 656 ipoib_dbg_mcast(priv, "waiting for MGID " IPOIB_GID_FMT "\n",
645 IPOIB_GID_ARG(mcast->mcmember.mgid)); 657 IPOIB_GID_ARG(mcast->mcmember.mgid));
646 wait_for_completion(&mcast->done); 658 wait_for_completion(&mcast->done);
647 } 659 } else
660 spin_unlock_irq(&priv->lock);
648 } 661 }
649 662
650 return 0; 663 return 0;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
index faaf10e5fc7b..18d2f53ec34c 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
@@ -255,6 +255,6 @@ void ipoib_event(struct ib_event_handler *handler,
255 record->event == IB_EVENT_LID_CHANGE || 255 record->event == IB_EVENT_LID_CHANGE ||
256 record->event == IB_EVENT_SM_CHANGE) { 256 record->event == IB_EVENT_SM_CHANGE) {
257 ipoib_dbg(priv, "Port active event\n"); 257 ipoib_dbg(priv, "Port active event\n");
258 schedule_work(&priv->flush_task); 258 queue_work(ipoib_workqueue, &priv->flush_task);
259 } 259 }
260} 260}
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 960dae5c87d1..a13dcdf90a4f 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -1237,6 +1237,87 @@ static int srp_reset_host(struct scsi_cmnd *scmnd)
1237 return ret; 1237 return ret;
1238} 1238}
1239 1239
1240static ssize_t show_id_ext(struct class_device *cdev, char *buf)
1241{
1242 struct srp_target_port *target = host_to_target(class_to_shost(cdev));
1243
1244 if (target->state == SRP_TARGET_DEAD ||
1245 target->state == SRP_TARGET_REMOVED)
1246 return -ENODEV;
1247
1248 return sprintf(buf, "0x%016llx\n",
1249 (unsigned long long) be64_to_cpu(target->id_ext));
1250}
1251
1252static ssize_t show_ioc_guid(struct class_device *cdev, char *buf)
1253{
1254 struct srp_target_port *target = host_to_target(class_to_shost(cdev));
1255
1256 if (target->state == SRP_TARGET_DEAD ||
1257 target->state == SRP_TARGET_REMOVED)
1258 return -ENODEV;
1259
1260 return sprintf(buf, "0x%016llx\n",
1261 (unsigned long long) be64_to_cpu(target->ioc_guid));
1262}
1263
1264static ssize_t show_service_id(struct class_device *cdev, char *buf)
1265{
1266 struct srp_target_port *target = host_to_target(class_to_shost(cdev));
1267
1268 if (target->state == SRP_TARGET_DEAD ||
1269 target->state == SRP_TARGET_REMOVED)
1270 return -ENODEV;
1271
1272 return sprintf(buf, "0x%016llx\n",
1273 (unsigned long long) be64_to_cpu(target->service_id));
1274}
1275
1276static ssize_t show_pkey(struct class_device *cdev, char *buf)
1277{
1278 struct srp_target_port *target = host_to_target(class_to_shost(cdev));
1279
1280 if (target->state == SRP_TARGET_DEAD ||
1281 target->state == SRP_TARGET_REMOVED)
1282 return -ENODEV;
1283
1284 return sprintf(buf, "0x%04x\n", be16_to_cpu(target->path.pkey));
1285}
1286
1287static ssize_t show_dgid(struct class_device *cdev, char *buf)
1288{
1289 struct srp_target_port *target = host_to_target(class_to_shost(cdev));
1290
1291 if (target->state == SRP_TARGET_DEAD ||
1292 target->state == SRP_TARGET_REMOVED)
1293 return -ENODEV;
1294
1295 return sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
1296 be16_to_cpu(((__be16 *) target->path.dgid.raw)[0]),
1297 be16_to_cpu(((__be16 *) target->path.dgid.raw)[1]),
1298 be16_to_cpu(((__be16 *) target->path.dgid.raw)[2]),
1299 be16_to_cpu(((__be16 *) target->path.dgid.raw)[3]),
1300 be16_to_cpu(((__be16 *) target->path.dgid.raw)[4]),
1301 be16_to_cpu(((__be16 *) target->path.dgid.raw)[5]),
1302 be16_to_cpu(((__be16 *) target->path.dgid.raw)[6]),
1303 be16_to_cpu(((__be16 *) target->path.dgid.raw)[7]));
1304}
1305
1306static CLASS_DEVICE_ATTR(id_ext, S_IRUGO, show_id_ext, NULL);
1307static CLASS_DEVICE_ATTR(ioc_guid, S_IRUGO, show_ioc_guid, NULL);
1308static CLASS_DEVICE_ATTR(service_id, S_IRUGO, show_service_id, NULL);
1309static CLASS_DEVICE_ATTR(pkey, S_IRUGO, show_pkey, NULL);
1310static CLASS_DEVICE_ATTR(dgid, S_IRUGO, show_dgid, NULL);
1311
1312static struct class_device_attribute *srp_host_attrs[] = {
1313 &class_device_attr_id_ext,
1314 &class_device_attr_ioc_guid,
1315 &class_device_attr_service_id,
1316 &class_device_attr_pkey,
1317 &class_device_attr_dgid,
1318 NULL
1319};
1320
1240static struct scsi_host_template srp_template = { 1321static struct scsi_host_template srp_template = {
1241 .module = THIS_MODULE, 1322 .module = THIS_MODULE,
1242 .name = DRV_NAME, 1323 .name = DRV_NAME,
@@ -1249,7 +1330,8 @@ static struct scsi_host_template srp_template = {
1249 .this_id = -1, 1330 .this_id = -1,
1250 .sg_tablesize = SRP_MAX_INDIRECT, 1331 .sg_tablesize = SRP_MAX_INDIRECT,
1251 .cmd_per_lun = SRP_SQ_SIZE, 1332 .cmd_per_lun = SRP_SQ_SIZE,
1252 .use_clustering = ENABLE_CLUSTERING 1333 .use_clustering = ENABLE_CLUSTERING,
1334 .shost_attrs = srp_host_attrs
1253}; 1335};
1254 1336
1255static int srp_add_target(struct srp_host *host, struct srp_target_port *target) 1337static int srp_add_target(struct srp_host *host, struct srp_target_port *target)
@@ -1366,6 +1448,7 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
1366 strlcpy(dgid, p + i * 2, 3); 1448 strlcpy(dgid, p + i * 2, 3);
1367 target->path.dgid.raw[i] = simple_strtoul(dgid, NULL, 16); 1449 target->path.dgid.raw[i] = simple_strtoul(dgid, NULL, 16);
1368 } 1450 }
1451 kfree(p);
1369 break; 1452 break;
1370 1453
1371 case SRP_OPT_PKEY: 1454 case SRP_OPT_PKEY:
diff --git a/drivers/media/common/Makefile b/drivers/media/common/Makefile
index bd458cb9b4ea..61b89617a967 100644
--- a/drivers/media/common/Makefile
+++ b/drivers/media/common/Makefile
@@ -1,5 +1,6 @@
1saa7146-objs := saa7146_i2c.o saa7146_core.o 1saa7146-objs := saa7146_i2c.o saa7146_core.o
2saa7146_vv-objs := saa7146_vv_ksyms.o saa7146_fops.o saa7146_video.o saa7146_hlp.o saa7146_vbi.o 2saa7146_vv-objs := saa7146_vv_ksyms.o saa7146_fops.o saa7146_video.o saa7146_hlp.o saa7146_vbi.o
3ir-common-objs := ir-functions.o ir-keymaps.o
3 4
4obj-$(CONFIG_VIDEO_SAA7146) += saa7146.o 5obj-$(CONFIG_VIDEO_SAA7146) += saa7146.o
5obj-$(CONFIG_VIDEO_SAA7146_VV) += saa7146_vv.o 6obj-$(CONFIG_VIDEO_SAA7146_VV) += saa7146_vv.o
diff --git a/drivers/media/common/ir-common.c b/drivers/media/common/ir-common.c
deleted file mode 100644
index 97fa3fc571c4..000000000000
--- a/drivers/media/common/ir-common.c
+++ /dev/null
@@ -1,519 +0,0 @@
1/*
2 *
3 * some common structs and functions to handle infrared remotes via
4 * input layer ...
5 *
6 * (c) 2003 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/string.h>
26#include <media/ir-common.h>
27
28/* -------------------------------------------------------------------------- */
29
30MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
31MODULE_LICENSE("GPL");
32
33static int repeat = 1;
34module_param(repeat, int, 0444);
35MODULE_PARM_DESC(repeat,"auto-repeat for IR keys (default: on)");
36
37static int debug = 0; /* debug level (0,1,2) */
38module_param(debug, int, 0644);
39
40#define dprintk(level, fmt, arg...) if (debug >= level) \
41 printk(KERN_DEBUG fmt , ## arg)
42
43/* -------------------------------------------------------------------------- */
44
45/* generic RC5 keytable */
46/* see http://users.pandora.be/nenya/electronics/rc5/codes00.htm */
47/* used by old (black) Hauppauge remotes */
48IR_KEYTAB_TYPE ir_codes_rc5_tv[IR_KEYTAB_SIZE] = {
49 /* Keys 0 to 9 */
50 [ 0x00 ] = KEY_KP0,
51 [ 0x01 ] = KEY_KP1,
52 [ 0x02 ] = KEY_KP2,
53 [ 0x03 ] = KEY_KP3,
54 [ 0x04 ] = KEY_KP4,
55 [ 0x05 ] = KEY_KP5,
56 [ 0x06 ] = KEY_KP6,
57 [ 0x07 ] = KEY_KP7,
58 [ 0x08 ] = KEY_KP8,
59 [ 0x09 ] = KEY_KP9,
60
61 [ 0x0b ] = KEY_CHANNEL, /* channel / program (japan: 11) */
62 [ 0x0c ] = KEY_POWER, /* standby */
63 [ 0x0d ] = KEY_MUTE, /* mute / demute */
64 [ 0x0f ] = KEY_TV, /* display */
65 [ 0x10 ] = KEY_VOLUMEUP,
66 [ 0x11 ] = KEY_VOLUMEDOWN,
67 [ 0x12 ] = KEY_BRIGHTNESSUP,
68 [ 0x13 ] = KEY_BRIGHTNESSDOWN,
69 [ 0x1e ] = KEY_SEARCH, /* search + */
70 [ 0x20 ] = KEY_CHANNELUP, /* channel / program + */
71 [ 0x21 ] = KEY_CHANNELDOWN, /* channel / program - */
72 [ 0x22 ] = KEY_CHANNEL, /* alt / channel */
73 [ 0x23 ] = KEY_LANGUAGE, /* 1st / 2nd language */
74 [ 0x26 ] = KEY_SLEEP, /* sleeptimer */
75 [ 0x2e ] = KEY_MENU, /* 2nd controls (USA: menu) */
76 [ 0x30 ] = KEY_PAUSE,
77 [ 0x32 ] = KEY_REWIND,
78 [ 0x33 ] = KEY_GOTO,
79 [ 0x35 ] = KEY_PLAY,
80 [ 0x36 ] = KEY_STOP,
81 [ 0x37 ] = KEY_RECORD, /* recording */
82 [ 0x3c ] = KEY_TEXT, /* teletext submode (Japan: 12) */
83 [ 0x3d ] = KEY_SUSPEND, /* system standby */
84
85};
86EXPORT_SYMBOL_GPL(ir_codes_rc5_tv);
87
88/* Table for Leadtek Winfast Remote Controls - used by both bttv and cx88 */
89IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE] = {
90 /* Keys 0 to 9 */
91 [ 18 ] = KEY_KP0,
92 [ 5 ] = KEY_KP1,
93 [ 6 ] = KEY_KP2,
94 [ 7 ] = KEY_KP3,
95 [ 9 ] = KEY_KP4,
96 [ 10 ] = KEY_KP5,
97 [ 11 ] = KEY_KP6,
98 [ 13 ] = KEY_KP7,
99 [ 14 ] = KEY_KP8,
100 [ 15 ] = KEY_KP9,
101
102 [ 0 ] = KEY_POWER,
103 [ 2 ] = KEY_TUNER, /* TV/FM */
104 [ 30 ] = KEY_VIDEO,
105 [ 4 ] = KEY_VOLUMEUP,
106 [ 8 ] = KEY_VOLUMEDOWN,
107 [ 12 ] = KEY_CHANNELUP,
108 [ 16 ] = KEY_CHANNELDOWN,
109 [ 3 ] = KEY_ZOOM, /* fullscreen */
110 [ 31 ] = KEY_SUBTITLE, /* closed caption/teletext */
111 [ 32 ] = KEY_SLEEP,
112 [ 20 ] = KEY_MUTE,
113 [ 43 ] = KEY_RED,
114 [ 44 ] = KEY_GREEN,
115 [ 45 ] = KEY_YELLOW,
116 [ 46 ] = KEY_BLUE,
117 [ 24 ] = KEY_KPPLUS, /* fine tune + */
118 [ 25 ] = KEY_KPMINUS, /* fine tune - */
119 [ 33 ] = KEY_KPDOT,
120 [ 19 ] = KEY_KPENTER,
121 [ 34 ] = KEY_BACK,
122 [ 35 ] = KEY_PLAYPAUSE,
123 [ 36 ] = KEY_NEXT,
124 [ 38 ] = KEY_STOP,
125 [ 39 ] = KEY_RECORD
126};
127EXPORT_SYMBOL_GPL(ir_codes_winfast);
128
129IR_KEYTAB_TYPE ir_codes_pinnacle[IR_KEYTAB_SIZE] = {
130 [ 0x59 ] = KEY_MUTE,
131 [ 0x4a ] = KEY_POWER,
132
133 [ 0x18 ] = KEY_TEXT,
134 [ 0x26 ] = KEY_TV,
135 [ 0x3d ] = KEY_PRINT,
136
137 [ 0x48 ] = KEY_RED,
138 [ 0x04 ] = KEY_GREEN,
139 [ 0x11 ] = KEY_YELLOW,
140 [ 0x00 ] = KEY_BLUE,
141
142 [ 0x2d ] = KEY_VOLUMEUP,
143 [ 0x1e ] = KEY_VOLUMEDOWN,
144
145 [ 0x49 ] = KEY_MENU,
146
147 [ 0x16 ] = KEY_CHANNELUP,
148 [ 0x17 ] = KEY_CHANNELDOWN,
149
150 [ 0x20 ] = KEY_UP,
151 [ 0x21 ] = KEY_DOWN,
152 [ 0x22 ] = KEY_LEFT,
153 [ 0x23 ] = KEY_RIGHT,
154 [ 0x0d ] = KEY_SELECT,
155
156
157
158 [ 0x08 ] = KEY_BACK,
159 [ 0x07 ] = KEY_REFRESH,
160
161 [ 0x2f ] = KEY_ZOOM,
162 [ 0x29 ] = KEY_RECORD,
163
164 [ 0x4b ] = KEY_PAUSE,
165 [ 0x4d ] = KEY_REWIND,
166 [ 0x2e ] = KEY_PLAY,
167 [ 0x4e ] = KEY_FORWARD,
168 [ 0x53 ] = KEY_PREVIOUS,
169 [ 0x4c ] = KEY_STOP,
170 [ 0x54 ] = KEY_NEXT,
171
172 [ 0x69 ] = KEY_KP0,
173 [ 0x6a ] = KEY_KP1,
174 [ 0x6b ] = KEY_KP2,
175 [ 0x6c ] = KEY_KP3,
176 [ 0x6d ] = KEY_KP4,
177 [ 0x6e ] = KEY_KP5,
178 [ 0x6f ] = KEY_KP6,
179 [ 0x70 ] = KEY_KP7,
180 [ 0x71 ] = KEY_KP8,
181 [ 0x72 ] = KEY_KP9,
182
183 [ 0x74 ] = KEY_CHANNEL,
184 [ 0x0a ] = KEY_BACKSPACE,
185};
186
187EXPORT_SYMBOL_GPL(ir_codes_pinnacle);
188
189/* empty keytable, can be used as placeholder for not-yet created keytables */
190IR_KEYTAB_TYPE ir_codes_empty[IR_KEYTAB_SIZE] = {
191 [ 42 ] = KEY_COFFEE,
192};
193EXPORT_SYMBOL_GPL(ir_codes_empty);
194
195/* Hauppauge: the newer, gray remotes (seems there are multiple
196 * slightly different versions), shipped with cx88+ivtv cards.
197 * almost rc5 coding, but some non-standard keys */
198IR_KEYTAB_TYPE ir_codes_hauppauge_new[IR_KEYTAB_SIZE] = {
199 /* Keys 0 to 9 */
200 [ 0x00 ] = KEY_KP0,
201 [ 0x01 ] = KEY_KP1,
202 [ 0x02 ] = KEY_KP2,
203 [ 0x03 ] = KEY_KP3,
204 [ 0x04 ] = KEY_KP4,
205 [ 0x05 ] = KEY_KP5,
206 [ 0x06 ] = KEY_KP6,
207 [ 0x07 ] = KEY_KP7,
208 [ 0x08 ] = KEY_KP8,
209 [ 0x09 ] = KEY_KP9,
210
211 [ 0x0a ] = KEY_TEXT, /* keypad asterisk as well */
212 [ 0x0b ] = KEY_RED, /* red button */
213 [ 0x0c ] = KEY_RADIO,
214 [ 0x0d ] = KEY_MENU,
215 [ 0x0e ] = KEY_SUBTITLE, /* also the # key */
216 [ 0x0f ] = KEY_MUTE,
217 [ 0x10 ] = KEY_VOLUMEUP,
218 [ 0x11 ] = KEY_VOLUMEDOWN,
219 [ 0x12 ] = KEY_PREVIOUS, /* previous channel */
220 [ 0x14 ] = KEY_UP,
221 [ 0x15 ] = KEY_DOWN,
222 [ 0x16 ] = KEY_LEFT,
223 [ 0x17 ] = KEY_RIGHT,
224 [ 0x18 ] = KEY_VIDEO, /* Videos */
225 [ 0x19 ] = KEY_AUDIO, /* Music */
226 /* 0x1a: Pictures - presume this means
227 "Multimedia Home Platform" -
228 no "PICTURES" key in input.h
229 */
230 [ 0x1a ] = KEY_MHP,
231
232 [ 0x1b ] = KEY_EPG, /* Guide */
233 [ 0x1c ] = KEY_TV,
234 [ 0x1e ] = KEY_NEXTSONG, /* skip >| */
235 [ 0x1f ] = KEY_EXIT, /* back/exit */
236 [ 0x20 ] = KEY_CHANNELUP, /* channel / program + */
237 [ 0x21 ] = KEY_CHANNELDOWN, /* channel / program - */
238 [ 0x22 ] = KEY_CHANNEL, /* source (old black remote) */
239 [ 0x24 ] = KEY_PREVIOUSSONG, /* replay |< */
240 [ 0x25 ] = KEY_ENTER, /* OK */
241 [ 0x26 ] = KEY_SLEEP, /* minimize (old black remote) */
242 [ 0x29 ] = KEY_BLUE, /* blue key */
243 [ 0x2e ] = KEY_GREEN, /* green button */
244 [ 0x30 ] = KEY_PAUSE, /* pause */
245 [ 0x32 ] = KEY_REWIND, /* backward << */
246 [ 0x34 ] = KEY_FASTFORWARD, /* forward >> */
247 [ 0x35 ] = KEY_PLAY,
248 [ 0x36 ] = KEY_STOP,
249 [ 0x37 ] = KEY_RECORD, /* recording */
250 [ 0x38 ] = KEY_YELLOW, /* yellow key */
251 [ 0x3b ] = KEY_SELECT, /* top right button */
252 [ 0x3c ] = KEY_ZOOM, /* full */
253 [ 0x3d ] = KEY_POWER, /* system power (green button) */
254};
255EXPORT_SYMBOL(ir_codes_hauppauge_new);
256
257IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE] = {
258 [ 2 ] = KEY_KP0,
259 [ 1 ] = KEY_KP1,
260 [ 11 ] = KEY_KP2,
261 [ 27 ] = KEY_KP3,
262 [ 5 ] = KEY_KP4,
263 [ 9 ] = KEY_KP5,
264 [ 21 ] = KEY_KP6,
265 [ 6 ] = KEY_KP7,
266 [ 10 ] = KEY_KP8,
267 [ 18 ] = KEY_KP9,
268
269 [ 3 ] = KEY_TUNER, /* TV/FM */
270 [ 7 ] = KEY_SEARCH, /* scan */
271 [ 28 ] = KEY_ZOOM, /* full screen */
272 [ 30 ] = KEY_POWER,
273 [ 23 ] = KEY_VOLUMEDOWN,
274 [ 31 ] = KEY_VOLUMEUP,
275 [ 20 ] = KEY_CHANNELDOWN,
276 [ 22 ] = KEY_CHANNELUP,
277 [ 24 ] = KEY_MUTE,
278
279 [ 0 ] = KEY_LIST, /* source */
280 [ 19 ] = KEY_INFO, /* loop */
281 [ 16 ] = KEY_LAST, /* +100 */
282 [ 13 ] = KEY_CLEAR, /* reset */
283 [ 12 ] = BTN_RIGHT, /* fun++ */
284 [ 4 ] = BTN_LEFT, /* fun-- */
285 [ 14 ] = KEY_GOTO, /* function */
286 [ 15 ] = KEY_STOP, /* freeze */
287};
288EXPORT_SYMBOL(ir_codes_pixelview);
289
290/* -------------------------------------------------------------------------- */
291
292static void ir_input_key_event(struct input_dev *dev, struct ir_input_state *ir)
293{
294 if (KEY_RESERVED == ir->keycode) {
295 printk(KERN_INFO "%s: unknown key: key=0x%02x raw=0x%02x down=%d\n",
296 dev->name,ir->ir_key,ir->ir_raw,ir->keypressed);
297 return;
298 }
299 dprintk(1,"%s: key event code=%d down=%d\n",
300 dev->name,ir->keycode,ir->keypressed);
301 input_report_key(dev,ir->keycode,ir->keypressed);
302 input_sync(dev);
303}
304
305/* -------------------------------------------------------------------------- */
306
307void ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
308 int ir_type, IR_KEYTAB_TYPE *ir_codes)
309{
310 int i;
311
312 ir->ir_type = ir_type;
313 if (ir_codes)
314 memcpy(ir->ir_codes, ir_codes, sizeof(ir->ir_codes));
315
316
317 dev->keycode = ir->ir_codes;
318 dev->keycodesize = sizeof(IR_KEYTAB_TYPE);
319 dev->keycodemax = IR_KEYTAB_SIZE;
320 for (i = 0; i < IR_KEYTAB_SIZE; i++)
321 set_bit(ir->ir_codes[i], dev->keybit);
322 clear_bit(0, dev->keybit);
323
324 set_bit(EV_KEY, dev->evbit);
325 if (repeat)
326 set_bit(EV_REP, dev->evbit);
327}
328
329void ir_input_nokey(struct input_dev *dev, struct ir_input_state *ir)
330{
331 if (ir->keypressed) {
332 ir->keypressed = 0;
333 ir_input_key_event(dev,ir);
334 }
335}
336
337void ir_input_keydown(struct input_dev *dev, struct ir_input_state *ir,
338 u32 ir_key, u32 ir_raw)
339{
340 u32 keycode = IR_KEYCODE(ir->ir_codes, ir_key);
341
342 if (ir->keypressed && ir->keycode != keycode) {
343 ir->keypressed = 0;
344 ir_input_key_event(dev,ir);
345 }
346 if (!ir->keypressed) {
347 ir->ir_key = ir_key;
348 ir->ir_raw = ir_raw;
349 ir->keycode = keycode;
350 ir->keypressed = 1;
351 ir_input_key_event(dev,ir);
352 }
353}
354
355/* -------------------------------------------------------------------------- */
356
357u32 ir_extract_bits(u32 data, u32 mask)
358{
359 int mbit, vbit;
360 u32 value;
361
362 value = 0;
363 vbit = 0;
364 for (mbit = 0; mbit < 32; mbit++) {
365 if (!(mask & ((u32)1 << mbit)))
366 continue;
367 if (data & ((u32)1 << mbit))
368 value |= (1 << vbit);
369 vbit++;
370 }
371 return value;
372}
373
374static int inline getbit(u32 *samples, int bit)
375{
376 return (samples[bit/32] & (1 << (31-(bit%32)))) ? 1 : 0;
377}
378
379/* sump raw samples for visual debugging ;) */
380int ir_dump_samples(u32 *samples, int count)
381{
382 int i, bit, start;
383
384 printk(KERN_DEBUG "ir samples: ");
385 start = 0;
386 for (i = 0; i < count * 32; i++) {
387 bit = getbit(samples,i);
388 if (bit)
389 start = 1;
390 if (0 == start)
391 continue;
392 printk("%s", bit ? "#" : "_");
393 }
394 printk("\n");
395 return 0;
396}
397
398/* decode raw samples, pulse distance coding used by NEC remotes */
399int ir_decode_pulsedistance(u32 *samples, int count, int low, int high)
400{
401 int i,last,bit,len;
402 u32 curBit;
403 u32 value;
404
405 /* find start burst */
406 for (i = len = 0; i < count * 32; i++) {
407 bit = getbit(samples,i);
408 if (bit) {
409 len++;
410 } else {
411 if (len >= 29)
412 break;
413 len = 0;
414 }
415 }
416
417 /* start burst to short */
418 if (len < 29)
419 return 0xffffffff;
420
421 /* find start silence */
422 for (len = 0; i < count * 32; i++) {
423 bit = getbit(samples,i);
424 if (bit) {
425 break;
426 } else {
427 len++;
428 }
429 }
430
431 /* silence to short */
432 if (len < 7)
433 return 0xffffffff;
434
435 /* go decoding */
436 len = 0;
437 last = 1;
438 value = 0; curBit = 1;
439 for (; i < count * 32; i++) {
440 bit = getbit(samples,i);
441 if (last) {
442 if(bit) {
443 continue;
444 } else {
445 len = 1;
446 }
447 } else {
448 if (bit) {
449 if (len > (low + high) /2)
450 value |= curBit;
451 curBit <<= 1;
452 if (curBit == 1)
453 break;
454 } else {
455 len++;
456 }
457 }
458 last = bit;
459 }
460
461 return value;
462}
463
464/* decode raw samples, biphase coding, used by rc5 for example */
465int ir_decode_biphase(u32 *samples, int count, int low, int high)
466{
467 int i,last,bit,len,flips;
468 u32 value;
469
470 /* find start bit (1) */
471 for (i = 0; i < 32; i++) {
472 bit = getbit(samples,i);
473 if (bit)
474 break;
475 }
476
477 /* go decoding */
478 len = 0;
479 flips = 0;
480 value = 1;
481 for (; i < count * 32; i++) {
482 if (len > high)
483 break;
484 if (flips > 1)
485 break;
486 last = bit;
487 bit = getbit(samples,i);
488 if (last == bit) {
489 len++;
490 continue;
491 }
492 if (len < low) {
493 len++;
494 flips++;
495 continue;
496 }
497 value <<= 1;
498 value |= bit;
499 flips = 0;
500 len = 1;
501 }
502 return value;
503}
504
505EXPORT_SYMBOL_GPL(ir_input_init);
506EXPORT_SYMBOL_GPL(ir_input_nokey);
507EXPORT_SYMBOL_GPL(ir_input_keydown);
508
509EXPORT_SYMBOL_GPL(ir_extract_bits);
510EXPORT_SYMBOL_GPL(ir_dump_samples);
511EXPORT_SYMBOL_GPL(ir_decode_biphase);
512EXPORT_SYMBOL_GPL(ir_decode_pulsedistance);
513
514/*
515 * Local variables:
516 * c-basic-offset: 8
517 * End:
518 */
519
diff --git a/drivers/media/common/ir-functions.c b/drivers/media/common/ir-functions.c
new file mode 100644
index 000000000000..397cff8b345b
--- /dev/null
+++ b/drivers/media/common/ir-functions.c
@@ -0,0 +1,272 @@
1/*
2 *
3 * some common structs and functions to handle infrared remotes via
4 * input layer ...
5 *
6 * (c) 2003 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/string.h>
26#include <media/ir-common.h>
27
28/* -------------------------------------------------------------------------- */
29
30MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
31MODULE_LICENSE("GPL");
32
33static int repeat = 1;
34module_param(repeat, int, 0444);
35MODULE_PARM_DESC(repeat,"auto-repeat for IR keys (default: on)");
36
37static int debug = 0; /* debug level (0,1,2) */
38module_param(debug, int, 0644);
39
40#define dprintk(level, fmt, arg...) if (debug >= level) \
41 printk(KERN_DEBUG fmt , ## arg)
42
43/* -------------------------------------------------------------------------- */
44
45static void ir_input_key_event(struct input_dev *dev, struct ir_input_state *ir)
46{
47 if (KEY_RESERVED == ir->keycode) {
48 printk(KERN_INFO "%s: unknown key: key=0x%02x raw=0x%02x down=%d\n",
49 dev->name,ir->ir_key,ir->ir_raw,ir->keypressed);
50 return;
51 }
52 dprintk(1,"%s: key event code=%d down=%d\n",
53 dev->name,ir->keycode,ir->keypressed);
54 input_report_key(dev,ir->keycode,ir->keypressed);
55 input_sync(dev);
56}
57
58/* -------------------------------------------------------------------------- */
59
60void ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
61 int ir_type, IR_KEYTAB_TYPE *ir_codes)
62{
63 int i;
64
65 ir->ir_type = ir_type;
66 if (ir_codes)
67 memcpy(ir->ir_codes, ir_codes, sizeof(ir->ir_codes));
68
69
70 dev->keycode = ir->ir_codes;
71 dev->keycodesize = sizeof(IR_KEYTAB_TYPE);
72 dev->keycodemax = IR_KEYTAB_SIZE;
73 for (i = 0; i < IR_KEYTAB_SIZE; i++)
74 set_bit(ir->ir_codes[i], dev->keybit);
75 clear_bit(0, dev->keybit);
76
77 set_bit(EV_KEY, dev->evbit);
78 if (repeat)
79 set_bit(EV_REP, dev->evbit);
80}
81
82void ir_input_nokey(struct input_dev *dev, struct ir_input_state *ir)
83{
84 if (ir->keypressed) {
85 ir->keypressed = 0;
86 ir_input_key_event(dev,ir);
87 }
88}
89
90void ir_input_keydown(struct input_dev *dev, struct ir_input_state *ir,
91 u32 ir_key, u32 ir_raw)
92{
93 u32 keycode = IR_KEYCODE(ir->ir_codes, ir_key);
94
95 if (ir->keypressed && ir->keycode != keycode) {
96 ir->keypressed = 0;
97 ir_input_key_event(dev,ir);
98 }
99 if (!ir->keypressed) {
100 ir->ir_key = ir_key;
101 ir->ir_raw = ir_raw;
102 ir->keycode = keycode;
103 ir->keypressed = 1;
104 ir_input_key_event(dev,ir);
105 }
106}
107
108/* -------------------------------------------------------------------------- */
109
110u32 ir_extract_bits(u32 data, u32 mask)
111{
112 int mbit, vbit;
113 u32 value;
114
115 value = 0;
116 vbit = 0;
117 for (mbit = 0; mbit < 32; mbit++) {
118 if (!(mask & ((u32)1 << mbit)))
119 continue;
120 if (data & ((u32)1 << mbit))
121 value |= (1 << vbit);
122 vbit++;
123 }
124 return value;
125}
126
127static int inline getbit(u32 *samples, int bit)
128{
129 return (samples[bit/32] & (1 << (31-(bit%32)))) ? 1 : 0;
130}
131
132/* sump raw samples for visual debugging ;) */
133int ir_dump_samples(u32 *samples, int count)
134{
135 int i, bit, start;
136
137 printk(KERN_DEBUG "ir samples: ");
138 start = 0;
139 for (i = 0; i < count * 32; i++) {
140 bit = getbit(samples,i);
141 if (bit)
142 start = 1;
143 if (0 == start)
144 continue;
145 printk("%s", bit ? "#" : "_");
146 }
147 printk("\n");
148 return 0;
149}
150
151/* decode raw samples, pulse distance coding used by NEC remotes */
152int ir_decode_pulsedistance(u32 *samples, int count, int low, int high)
153{
154 int i,last,bit,len;
155 u32 curBit;
156 u32 value;
157
158 /* find start burst */
159 for (i = len = 0; i < count * 32; i++) {
160 bit = getbit(samples,i);
161 if (bit) {
162 len++;
163 } else {
164 if (len >= 29)
165 break;
166 len = 0;
167 }
168 }
169
170 /* start burst to short */
171 if (len < 29)
172 return 0xffffffff;
173
174 /* find start silence */
175 for (len = 0; i < count * 32; i++) {
176 bit = getbit(samples,i);
177 if (bit) {
178 break;
179 } else {
180 len++;
181 }
182 }
183
184 /* silence to short */
185 if (len < 7)
186 return 0xffffffff;
187
188 /* go decoding */
189 len = 0;
190 last = 1;
191 value = 0; curBit = 1;
192 for (; i < count * 32; i++) {
193 bit = getbit(samples,i);
194 if (last) {
195 if(bit) {
196 continue;
197 } else {
198 len = 1;
199 }
200 } else {
201 if (bit) {
202 if (len > (low + high) /2)
203 value |= curBit;
204 curBit <<= 1;
205 if (curBit == 1)
206 break;
207 } else {
208 len++;
209 }
210 }
211 last = bit;
212 }
213
214 return value;
215}
216
217/* decode raw samples, biphase coding, used by rc5 for example */
218int ir_decode_biphase(u32 *samples, int count, int low, int high)
219{
220 int i,last,bit,len,flips;
221 u32 value;
222
223 /* find start bit (1) */
224 for (i = 0; i < 32; i++) {
225 bit = getbit(samples,i);
226 if (bit)
227 break;
228 }
229
230 /* go decoding */
231 len = 0;
232 flips = 0;
233 value = 1;
234 for (; i < count * 32; i++) {
235 if (len > high)
236 break;
237 if (flips > 1)
238 break;
239 last = bit;
240 bit = getbit(samples,i);
241 if (last == bit) {
242 len++;
243 continue;
244 }
245 if (len < low) {
246 len++;
247 flips++;
248 continue;
249 }
250 value <<= 1;
251 value |= bit;
252 flips = 0;
253 len = 1;
254 }
255 return value;
256}
257
258EXPORT_SYMBOL_GPL(ir_input_init);
259EXPORT_SYMBOL_GPL(ir_input_nokey);
260EXPORT_SYMBOL_GPL(ir_input_keydown);
261
262EXPORT_SYMBOL_GPL(ir_extract_bits);
263EXPORT_SYMBOL_GPL(ir_dump_samples);
264EXPORT_SYMBOL_GPL(ir_decode_biphase);
265EXPORT_SYMBOL_GPL(ir_decode_pulsedistance);
266
267/*
268 * Local variables:
269 * c-basic-offset: 8
270 * End:
271 */
272
diff --git a/drivers/media/common/ir-keymaps.c b/drivers/media/common/ir-keymaps.c
new file mode 100644
index 000000000000..a294d5c2c73f
--- /dev/null
+++ b/drivers/media/common/ir-keymaps.c
@@ -0,0 +1,1415 @@
1/*
2
3
4 Keytables for supported remote controls. This file is part of
5 video4linux.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 */
22#include <linux/module.h>
23#include <linux/moduleparam.h>
24
25#include <linux/input.h>
26#include <media/ir-common.h>
27
28/* empty keytable, can be used as placeholder for not-yet created keytables */
29IR_KEYTAB_TYPE ir_codes_empty[IR_KEYTAB_SIZE] = {
30 [ 0x2a ] = KEY_COFFEE,
31};
32
33EXPORT_SYMBOL_GPL(ir_codes_empty);
34
35/* Matt Jesson <dvb@jesson.eclipse.co.uk */
36IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE] = {
37 [ 0x28 ] = KEY_0, //'0' / 'enter'
38 [ 0x22 ] = KEY_1, //'1'
39 [ 0x12 ] = KEY_2, //'2' / 'up arrow'
40 [ 0x32 ] = KEY_3, //'3'
41 [ 0x24 ] = KEY_4, //'4' / 'left arrow'
42 [ 0x14 ] = KEY_5, //'5'
43 [ 0x34 ] = KEY_6, //'6' / 'right arrow'
44 [ 0x26 ] = KEY_7, //'7'
45 [ 0x16 ] = KEY_8, //'8' / 'down arrow'
46 [ 0x36 ] = KEY_9, //'9'
47
48 [ 0x20 ] = KEY_LIST, // 'source'
49 [ 0x10 ] = KEY_TEXT, // 'teletext'
50 [ 0x00 ] = KEY_POWER, // 'power'
51 [ 0x04 ] = KEY_AUDIO, // 'audio'
52 [ 0x06 ] = KEY_ZOOM, // 'full screen'
53 [ 0x18 ] = KEY_VIDEO, // 'display'
54 [ 0x38 ] = KEY_SEARCH, // 'loop'
55 [ 0x08 ] = KEY_INFO, // 'preview'
56 [ 0x2a ] = KEY_REWIND, // 'backward <<'
57 [ 0x1a ] = KEY_FASTFORWARD, // 'forward >>'
58 [ 0x3a ] = KEY_RECORD, // 'capture'
59 [ 0x0a ] = KEY_MUTE, // 'mute'
60 [ 0x2c ] = KEY_RECORD, // 'record'
61 [ 0x1c ] = KEY_PAUSE, // 'pause'
62 [ 0x3c ] = KEY_STOP, // 'stop'
63 [ 0x0c ] = KEY_PLAY, // 'play'
64 [ 0x2e ] = KEY_RED, // 'red'
65 [ 0x01 ] = KEY_BLUE, // 'blue' / 'cancel'
66 [ 0x0e ] = KEY_YELLOW, // 'yellow' / 'ok'
67 [ 0x21 ] = KEY_GREEN, // 'green'
68 [ 0x11 ] = KEY_CHANNELDOWN, // 'channel -'
69 [ 0x31 ] = KEY_CHANNELUP, // 'channel +'
70 [ 0x1e ] = KEY_VOLUMEDOWN, // 'volume -'
71 [ 0x3e ] = KEY_VOLUMEUP, // 'volume +'
72};
73
74EXPORT_SYMBOL_GPL(ir_codes_avermedia_dvbt);
75
76/* Attila Kondoros <attila.kondoros@chello.hu> */
77IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = {
78
79 [ 0x01 ] = KEY_1,
80 [ 0x02 ] = KEY_2,
81 [ 0x03 ] = KEY_3,
82 [ 0x04 ] = KEY_4,
83 [ 0x05 ] = KEY_5,
84 [ 0x06 ] = KEY_6,
85 [ 0x07 ] = KEY_7,
86 [ 0x08 ] = KEY_8,
87 [ 0x09 ] = KEY_9,
88 [ 0x00 ] = KEY_0,
89 [ 0x17 ] = KEY_LAST, // +100
90 [ 0x0a ] = KEY_LIST, // recall
91
92
93 [ 0x1c ] = KEY_TUNER, // TV/FM
94 [ 0x15 ] = KEY_SEARCH, // scan
95 [ 0x12 ] = KEY_POWER, // power
96 [ 0x1f ] = KEY_VOLUMEDOWN, // vol up
97 [ 0x1b ] = KEY_VOLUMEUP, // vol down
98 [ 0x1e ] = KEY_CHANNELDOWN, // chn up
99 [ 0x1a ] = KEY_CHANNELUP, // chn down
100
101 [ 0x11 ] = KEY_VIDEO, // video
102 [ 0x0f ] = KEY_ZOOM, // full screen
103 [ 0x13 ] = KEY_MUTE, // mute/unmute
104 [ 0x10 ] = KEY_TEXT, // min
105
106 [ 0x0d ] = KEY_STOP, // freeze
107 [ 0x0e ] = KEY_RECORD, // record
108 [ 0x1d ] = KEY_PLAYPAUSE, // stop
109 [ 0x19 ] = KEY_PLAY, // play
110
111 [ 0x16 ] = KEY_GOTO, // osd
112 [ 0x14 ] = KEY_REFRESH, // default
113 [ 0x0c ] = KEY_KPPLUS, // fine tune >>>>
114 [ 0x18 ] = KEY_KPMINUS // fine tune <<<<
115};
116
117EXPORT_SYMBOL_GPL(ir_codes_apac_viewcomp);
118
119/* ---------------------------------------------------------------------- */
120
121IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE] = {
122
123 [ 0x1e ] = KEY_POWER, // power
124 [ 0x07 ] = KEY_MEDIA, // source
125 [ 0x1c ] = KEY_SEARCH, // scan
126
127/* FIXME: duplicate keycodes?
128 *
129 * These four keys seem to share the same GPIO as CH+, CH-, <<< and >>>
130 * The GPIO values are
131 * 6397fb for both "Scan <" and "CH -",
132 * 639ffb for "Scan >" and "CH+",
133 * 6384fb for "Tune <" and "<<<",
134 * 638cfb for "Tune >" and ">>>", regardless of the mask.
135 *
136 * [ 0x17 ] = KEY_BACK, // fm scan <<
137 * [ 0x1f ] = KEY_FORWARD, // fm scan >>
138 *
139 * [ 0x04 ] = KEY_LEFT, // fm tuning <
140 * [ 0x0c ] = KEY_RIGHT, // fm tuning >
141 *
142 * For now, these four keys are disabled. Pressing them will generate
143 * the CH+/CH-/<<</>>> events
144 */
145
146 [ 0x03 ] = KEY_TUNER, // TV/FM
147
148 [ 0x00 ] = KEY_RECORD,
149 [ 0x08 ] = KEY_STOP,
150 [ 0x11 ] = KEY_PLAY,
151
152 [ 0x1a ] = KEY_PLAYPAUSE, // freeze
153 [ 0x19 ] = KEY_ZOOM, // zoom
154 [ 0x0f ] = KEY_TEXT, // min
155
156 [ 0x01 ] = KEY_1,
157 [ 0x0b ] = KEY_2,
158 [ 0x1b ] = KEY_3,
159 [ 0x05 ] = KEY_4,
160 [ 0x09 ] = KEY_5,
161 [ 0x15 ] = KEY_6,
162 [ 0x06 ] = KEY_7,
163 [ 0x0a ] = KEY_8,
164 [ 0x12 ] = KEY_9,
165 [ 0x02 ] = KEY_0,
166 [ 0x10 ] = KEY_LAST, // +100
167 [ 0x13 ] = KEY_LIST, // recall
168
169 [ 0x1f ] = KEY_CHANNELUP, // chn down
170 [ 0x17 ] = KEY_CHANNELDOWN, // chn up
171 [ 0x16 ] = KEY_VOLUMEUP, // vol down
172 [ 0x14 ] = KEY_VOLUMEDOWN, // vol up
173
174 [ 0x04 ] = KEY_KPMINUS, // <<<
175 [ 0x0e ] = KEY_SETUP, // function
176 [ 0x0c ] = KEY_KPPLUS, // >>>
177
178 [ 0x0d ] = KEY_GOTO, // mts
179 [ 0x1d ] = KEY_REFRESH, // reset
180 [ 0x18 ] = KEY_MUTE // mute/unmute
181};
182
183EXPORT_SYMBOL_GPL(ir_codes_pixelview);
184
185IR_KEYTAB_TYPE ir_codes_nebula[IR_KEYTAB_SIZE] = {
186 [ 0x00 ] = KEY_0,
187 [ 0x01 ] = KEY_1,
188 [ 0x02 ] = KEY_2,
189 [ 0x03 ] = KEY_3,
190 [ 0x04 ] = KEY_4,
191 [ 0x05 ] = KEY_5,
192 [ 0x06 ] = KEY_6,
193 [ 0x07 ] = KEY_7,
194 [ 0x08 ] = KEY_8,
195 [ 0x09 ] = KEY_9,
196 [ 0x0a ] = KEY_TV,
197 [ 0x0b ] = KEY_AUX,
198 [ 0x0c ] = KEY_DVD,
199 [ 0x0d ] = KEY_POWER,
200 [ 0x0e ] = KEY_MHP, /* labelled 'Picture' */
201 [ 0x0f ] = KEY_AUDIO,
202 [ 0x10 ] = KEY_INFO,
203 [ 0x11 ] = KEY_F13, /* 16:9 */
204 [ 0x12 ] = KEY_F14, /* 14:9 */
205 [ 0x13 ] = KEY_EPG,
206 [ 0x14 ] = KEY_EXIT,
207 [ 0x15 ] = KEY_MENU,
208 [ 0x16 ] = KEY_UP,
209 [ 0x17 ] = KEY_DOWN,
210 [ 0x18 ] = KEY_LEFT,
211 [ 0x19 ] = KEY_RIGHT,
212 [ 0x1a ] = KEY_ENTER,
213 [ 0x1b ] = KEY_CHANNELUP,
214 [ 0x1c ] = KEY_CHANNELDOWN,
215 [ 0x1d ] = KEY_VOLUMEUP,
216 [ 0x1e ] = KEY_VOLUMEDOWN,
217 [ 0x1f ] = KEY_RED,
218 [ 0x20 ] = KEY_GREEN,
219 [ 0x21 ] = KEY_YELLOW,
220 [ 0x22 ] = KEY_BLUE,
221 [ 0x23 ] = KEY_SUBTITLE,
222 [ 0x24 ] = KEY_F15, /* AD */
223 [ 0x25 ] = KEY_TEXT,
224 [ 0x26 ] = KEY_MUTE,
225 [ 0x27 ] = KEY_REWIND,
226 [ 0x28 ] = KEY_STOP,
227 [ 0x29 ] = KEY_PLAY,
228 [ 0x2a ] = KEY_FASTFORWARD,
229 [ 0x2b ] = KEY_F16, /* chapter */
230 [ 0x2c ] = KEY_PAUSE,
231 [ 0x2d ] = KEY_PLAY,
232 [ 0x2e ] = KEY_RECORD,
233 [ 0x2f ] = KEY_F17, /* picture in picture */
234 [ 0x30 ] = KEY_KPPLUS, /* zoom in */
235 [ 0x31 ] = KEY_KPMINUS, /* zoom out */
236 [ 0x32 ] = KEY_F18, /* capture */
237 [ 0x33 ] = KEY_F19, /* web */
238 [ 0x34 ] = KEY_EMAIL,
239 [ 0x35 ] = KEY_PHONE,
240 [ 0x36 ] = KEY_PC
241};
242
243EXPORT_SYMBOL_GPL(ir_codes_nebula);
244
245/* DigitalNow DNTV Live DVB-T Remote */
246IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t[IR_KEYTAB_SIZE] = {
247 [ 0x00 ] = KEY_ESC, /* 'go up a level?' */
248 /* Keys 0 to 9 */
249 [ 0x0a ] = KEY_0,
250 [ 0x01 ] = KEY_1,
251 [ 0x02 ] = KEY_2,
252 [ 0x03 ] = KEY_3,
253 [ 0x04 ] = KEY_4,
254 [ 0x05 ] = KEY_5,
255 [ 0x06 ] = KEY_6,
256 [ 0x07 ] = KEY_7,
257 [ 0x08 ] = KEY_8,
258 [ 0x09 ] = KEY_9,
259
260 [ 0x0b ] = KEY_TUNER, /* tv/fm */
261 [ 0x0c ] = KEY_SEARCH, /* scan */
262 [ 0x0d ] = KEY_STOP,
263 [ 0x0e ] = KEY_PAUSE,
264 [ 0x0f ] = KEY_LIST, /* source */
265
266 [ 0x10 ] = KEY_MUTE,
267 [ 0x11 ] = KEY_REWIND, /* backward << */
268 [ 0x12 ] = KEY_POWER,
269 [ 0x13 ] = KEY_S, /* snap */
270 [ 0x14 ] = KEY_AUDIO, /* stereo */
271 [ 0x15 ] = KEY_CLEAR, /* reset */
272 [ 0x16 ] = KEY_PLAY,
273 [ 0x17 ] = KEY_ENTER,
274 [ 0x18 ] = KEY_ZOOM, /* full screen */
275 [ 0x19 ] = KEY_FASTFORWARD, /* forward >> */
276 [ 0x1a ] = KEY_CHANNELUP,
277 [ 0x1b ] = KEY_VOLUMEUP,
278 [ 0x1c ] = KEY_INFO, /* preview */
279 [ 0x1d ] = KEY_RECORD, /* record */
280 [ 0x1e ] = KEY_CHANNELDOWN,
281 [ 0x1f ] = KEY_VOLUMEDOWN,
282};
283
284EXPORT_SYMBOL_GPL(ir_codes_dntv_live_dvb_t);
285
286/* ---------------------------------------------------------------------- */
287
288/* IO-DATA BCTV7E Remote */
289IR_KEYTAB_TYPE ir_codes_iodata_bctv7e[IR_KEYTAB_SIZE] = {
290 [ 0x40 ] = KEY_TV,
291 [ 0x20 ] = KEY_RADIO, /* FM */
292 [ 0x60 ] = KEY_EPG,
293 [ 0x00 ] = KEY_POWER,
294
295 /* Keys 0 to 9 */
296 [ 0x44 ] = KEY_0, /* 10 */
297 [ 0x50 ] = KEY_1,
298 [ 0x30 ] = KEY_2,
299 [ 0x70 ] = KEY_3,
300 [ 0x48 ] = KEY_4,
301 [ 0x28 ] = KEY_5,
302 [ 0x68 ] = KEY_6,
303 [ 0x58 ] = KEY_7,
304 [ 0x38 ] = KEY_8,
305 [ 0x78 ] = KEY_9,
306
307 [ 0x10 ] = KEY_L, /* Live */
308 [ 0x08 ] = KEY_T, /* Time Shift */
309
310 [ 0x18 ] = KEY_PLAYPAUSE, /* Play */
311
312 [ 0x24 ] = KEY_ENTER, /* 11 */
313 [ 0x64 ] = KEY_ESC, /* 12 */
314 [ 0x04 ] = KEY_M, /* Multi */
315
316 [ 0x54 ] = KEY_VIDEO,
317 [ 0x34 ] = KEY_CHANNELUP,
318 [ 0x74 ] = KEY_VOLUMEUP,
319 [ 0x14 ] = KEY_MUTE,
320
321 [ 0x4c ] = KEY_S, /* SVIDEO */
322 [ 0x2c ] = KEY_CHANNELDOWN,
323 [ 0x6c ] = KEY_VOLUMEDOWN,
324 [ 0x0c ] = KEY_ZOOM,
325
326 [ 0x5c ] = KEY_PAUSE,
327 [ 0x3c ] = KEY_C, /* || (red) */
328 [ 0x7c ] = KEY_RECORD, /* recording */
329 [ 0x1c ] = KEY_STOP,
330
331 [ 0x41 ] = KEY_REWIND, /* backward << */
332 [ 0x21 ] = KEY_PLAY,
333 [ 0x61 ] = KEY_FASTFORWARD, /* forward >> */
334 [ 0x01 ] = KEY_NEXT, /* skip >| */
335};
336
337EXPORT_SYMBOL_GPL(ir_codes_iodata_bctv7e);
338
339/* ---------------------------------------------------------------------- */
340
341/* ADS Tech Instant TV DVB-T PCI Remote */
342IR_KEYTAB_TYPE ir_codes_adstech_dvb_t_pci[IR_KEYTAB_SIZE] = {
343 /* Keys 0 to 9 */
344 [ 0x4d ] = KEY_0,
345 [ 0x57 ] = KEY_1,
346 [ 0x4f ] = KEY_2,
347 [ 0x53 ] = KEY_3,
348 [ 0x56 ] = KEY_4,
349 [ 0x4e ] = KEY_5,
350 [ 0x5e ] = KEY_6,
351 [ 0x54 ] = KEY_7,
352 [ 0x4c ] = KEY_8,
353 [ 0x5c ] = KEY_9,
354
355 [ 0x5b ] = KEY_POWER,
356 [ 0x5f ] = KEY_MUTE,
357 [ 0x55 ] = KEY_GOTO,
358 [ 0x5d ] = KEY_SEARCH,
359 [ 0x17 ] = KEY_EPG, /* Guide */
360 [ 0x1f ] = KEY_MENU,
361 [ 0x0f ] = KEY_UP,
362 [ 0x46 ] = KEY_DOWN,
363 [ 0x16 ] = KEY_LEFT,
364 [ 0x1e ] = KEY_RIGHT,
365 [ 0x0e ] = KEY_SELECT, /* Enter */
366 [ 0x5a ] = KEY_INFO,
367 [ 0x52 ] = KEY_EXIT,
368 [ 0x59 ] = KEY_PREVIOUS,
369 [ 0x51 ] = KEY_NEXT,
370 [ 0x58 ] = KEY_REWIND,
371 [ 0x50 ] = KEY_FORWARD,
372 [ 0x44 ] = KEY_PLAYPAUSE,
373 [ 0x07 ] = KEY_STOP,
374 [ 0x1b ] = KEY_RECORD,
375 [ 0x13 ] = KEY_TUNER, /* Live */
376 [ 0x0a ] = KEY_A,
377 [ 0x12 ] = KEY_B,
378 [ 0x03 ] = KEY_PROG1, /* 1 */
379 [ 0x01 ] = KEY_PROG2, /* 2 */
380 [ 0x00 ] = KEY_PROG3, /* 3 */
381 [ 0x06 ] = KEY_DVD,
382 [ 0x48 ] = KEY_AUX, /* Photo */
383 [ 0x40 ] = KEY_VIDEO,
384 [ 0x19 ] = KEY_AUDIO, /* Music */
385 [ 0x0b ] = KEY_CHANNELUP,
386 [ 0x08 ] = KEY_CHANNELDOWN,
387 [ 0x15 ] = KEY_VOLUMEUP,
388 [ 0x1c ] = KEY_VOLUMEDOWN,
389};
390
391EXPORT_SYMBOL_GPL(ir_codes_adstech_dvb_t_pci);
392
393/* ---------------------------------------------------------------------- */
394
395/* MSI TV@nywhere remote */
396IR_KEYTAB_TYPE ir_codes_msi_tvanywhere[IR_KEYTAB_SIZE] = {
397 /* Keys 0 to 9 */
398 [ 0x00 ] = KEY_0,
399 [ 0x01 ] = KEY_1,
400 [ 0x02 ] = KEY_2,
401 [ 0x03 ] = KEY_3,
402 [ 0x04 ] = KEY_4,
403 [ 0x05 ] = KEY_5,
404 [ 0x06 ] = KEY_6,
405 [ 0x07 ] = KEY_7,
406 [ 0x08 ] = KEY_8,
407 [ 0x09 ] = KEY_9,
408
409 [ 0x0c ] = KEY_MUTE,
410 [ 0x0f ] = KEY_SCREEN, /* Full Screen */
411 [ 0x10 ] = KEY_F, /* Funtion */
412 [ 0x11 ] = KEY_T, /* Time shift */
413 [ 0x12 ] = KEY_POWER,
414 [ 0x13 ] = KEY_MEDIA, /* MTS */
415 [ 0x14 ] = KEY_SLOW,
416 [ 0x16 ] = KEY_REWIND, /* backward << */
417 [ 0x17 ] = KEY_ENTER, /* Return */
418 [ 0x18 ] = KEY_FASTFORWARD, /* forward >> */
419 [ 0x1a ] = KEY_CHANNELUP,
420 [ 0x1b ] = KEY_VOLUMEUP,
421 [ 0x1e ] = KEY_CHANNELDOWN,
422 [ 0x1f ] = KEY_VOLUMEDOWN,
423};
424
425EXPORT_SYMBOL_GPL(ir_codes_msi_tvanywhere);
426
427/* ---------------------------------------------------------------------- */
428
429/* Cinergy 1400 DVB-T */
430IR_KEYTAB_TYPE ir_codes_cinergy_1400[IR_KEYTAB_SIZE] = {
431 [ 0x01 ] = KEY_POWER,
432 [ 0x02 ] = KEY_1,
433 [ 0x03 ] = KEY_2,
434 [ 0x04 ] = KEY_3,
435 [ 0x05 ] = KEY_4,
436 [ 0x06 ] = KEY_5,
437 [ 0x07 ] = KEY_6,
438 [ 0x08 ] = KEY_7,
439 [ 0x09 ] = KEY_8,
440 [ 0x0a ] = KEY_9,
441 [ 0x0c ] = KEY_0,
442
443 [ 0x0b ] = KEY_VIDEO,
444 [ 0x0d ] = KEY_REFRESH,
445 [ 0x0e ] = KEY_SELECT,
446 [ 0x0f ] = KEY_EPG,
447 [ 0x10 ] = KEY_UP,
448 [ 0x11 ] = KEY_LEFT,
449 [ 0x12 ] = KEY_OK,
450 [ 0x13 ] = KEY_RIGHT,
451 [ 0x14 ] = KEY_DOWN,
452 [ 0x15 ] = KEY_TEXT,
453 [ 0x16 ] = KEY_INFO,
454
455 [ 0x17 ] = KEY_RED,
456 [ 0x18 ] = KEY_GREEN,
457 [ 0x19 ] = KEY_YELLOW,
458 [ 0x1a ] = KEY_BLUE,
459
460 [ 0x1b ] = KEY_CHANNELUP,
461 [ 0x1c ] = KEY_VOLUMEUP,
462 [ 0x1d ] = KEY_MUTE,
463 [ 0x1e ] = KEY_VOLUMEDOWN,
464 [ 0x1f ] = KEY_CHANNELDOWN,
465
466 [ 0x40 ] = KEY_PAUSE,
467 [ 0x4c ] = KEY_PLAY,
468 [ 0x58 ] = KEY_RECORD,
469 [ 0x54 ] = KEY_PREVIOUS,
470 [ 0x48 ] = KEY_STOP,
471 [ 0x5c ] = KEY_NEXT,
472};
473
474EXPORT_SYMBOL_GPL(ir_codes_cinergy_1400);
475
476/* ---------------------------------------------------------------------- */
477
478/* AVERTV STUDIO 303 Remote */
479IR_KEYTAB_TYPE ir_codes_avertv_303[IR_KEYTAB_SIZE] = {
480 [ 0x2a ] = KEY_1,
481 [ 0x32 ] = KEY_2,
482 [ 0x3a ] = KEY_3,
483 [ 0x4a ] = KEY_4,
484 [ 0x52 ] = KEY_5,
485 [ 0x5a ] = KEY_6,
486 [ 0x6a ] = KEY_7,
487 [ 0x72 ] = KEY_8,
488 [ 0x7a ] = KEY_9,
489 [ 0x0e ] = KEY_0,
490
491 [ 0x02 ] = KEY_POWER,
492 [ 0x22 ] = KEY_VIDEO,
493 [ 0x42 ] = KEY_AUDIO,
494 [ 0x62 ] = KEY_ZOOM,
495 [ 0x0a ] = KEY_TV,
496 [ 0x12 ] = KEY_CD,
497 [ 0x1a ] = KEY_TEXT,
498
499 [ 0x16 ] = KEY_SUBTITLE,
500 [ 0x1e ] = KEY_REWIND,
501 [ 0x06 ] = KEY_PRINT,
502
503 [ 0x2e ] = KEY_SEARCH,
504 [ 0x36 ] = KEY_SLEEP,
505 [ 0x3e ] = KEY_SHUFFLE,
506 [ 0x26 ] = KEY_MUTE,
507
508 [ 0x4e ] = KEY_RECORD,
509 [ 0x56 ] = KEY_PAUSE,
510 [ 0x5e ] = KEY_STOP,
511 [ 0x46 ] = KEY_PLAY,
512
513 [ 0x6e ] = KEY_RED,
514 [ 0x0b ] = KEY_GREEN,
515 [ 0x66 ] = KEY_YELLOW,
516 [ 0x03 ] = KEY_BLUE,
517
518 [ 0x76 ] = KEY_LEFT,
519 [ 0x7e ] = KEY_RIGHT,
520 [ 0x13 ] = KEY_DOWN,
521 [ 0x1b ] = KEY_UP,
522};
523
524EXPORT_SYMBOL_GPL(ir_codes_avertv_303);
525
526/* ---------------------------------------------------------------------- */
527
528/* DigitalNow DNTV Live! DVB-T Pro Remote */
529IR_KEYTAB_TYPE ir_codes_dntv_live_dvbt_pro[IR_KEYTAB_SIZE] = {
530 [ 0x16 ] = KEY_POWER,
531 [ 0x5b ] = KEY_HOME,
532
533 [ 0x55 ] = KEY_TV, /* live tv */
534 [ 0x58 ] = KEY_TUNER, /* digital Radio */
535 [ 0x5a ] = KEY_RADIO, /* FM radio */
536 [ 0x59 ] = KEY_DVD, /* dvd menu */
537 [ 0x03 ] = KEY_1,
538 [ 0x01 ] = KEY_2,
539 [ 0x06 ] = KEY_3,
540 [ 0x09 ] = KEY_4,
541 [ 0x1d ] = KEY_5,
542 [ 0x1f ] = KEY_6,
543 [ 0x0d ] = KEY_7,
544 [ 0x19 ] = KEY_8,
545 [ 0x1b ] = KEY_9,
546 [ 0x0c ] = KEY_CANCEL,
547 [ 0x15 ] = KEY_0,
548 [ 0x4a ] = KEY_CLEAR,
549 [ 0x13 ] = KEY_BACK,
550 [ 0x00 ] = KEY_TAB,
551 [ 0x4b ] = KEY_UP,
552 [ 0x4e ] = KEY_LEFT,
553 [ 0x4f ] = KEY_OK,
554 [ 0x52 ] = KEY_RIGHT,
555 [ 0x51 ] = KEY_DOWN,
556 [ 0x1e ] = KEY_VOLUMEUP,
557 [ 0x0a ] = KEY_VOLUMEDOWN,
558 [ 0x02 ] = KEY_CHANNELDOWN,
559 [ 0x05 ] = KEY_CHANNELUP,
560 [ 0x11 ] = KEY_RECORD,
561 [ 0x14 ] = KEY_PLAY,
562 [ 0x4c ] = KEY_PAUSE,
563 [ 0x1a ] = KEY_STOP,
564 [ 0x40 ] = KEY_REWIND,
565 [ 0x12 ] = KEY_FASTFORWARD,
566 [ 0x41 ] = KEY_PREVIOUSSONG, /* replay |< */
567 [ 0x42 ] = KEY_NEXTSONG, /* skip >| */
568 [ 0x54 ] = KEY_CAMERA, /* capture */
569 [ 0x50 ] = KEY_LANGUAGE, /* sap */
570 [ 0x47 ] = KEY_TV2, /* pip */
571 [ 0x4d ] = KEY_SCREEN,
572 [ 0x43 ] = KEY_SUBTITLE,
573 [ 0x10 ] = KEY_MUTE,
574 [ 0x49 ] = KEY_AUDIO, /* l/r */
575 [ 0x07 ] = KEY_SLEEP,
576 [ 0x08 ] = KEY_VIDEO, /* a/v */
577 [ 0x0e ] = KEY_PREVIOUS, /* recall */
578 [ 0x45 ] = KEY_ZOOM, /* zoom + */
579 [ 0x46 ] = KEY_ANGLE, /* zoom - */
580 [ 0x56 ] = KEY_RED,
581 [ 0x57 ] = KEY_GREEN,
582 [ 0x5c ] = KEY_YELLOW,
583 [ 0x5d ] = KEY_BLUE,
584};
585
586EXPORT_SYMBOL_GPL(ir_codes_dntv_live_dvbt_pro);
587
588IR_KEYTAB_TYPE ir_codes_em_terratec[IR_KEYTAB_SIZE] = {
589 [ 0x01 ] = KEY_CHANNEL,
590 [ 0x02 ] = KEY_SELECT,
591 [ 0x03 ] = KEY_MUTE,
592 [ 0x04 ] = KEY_POWER,
593 [ 0x05 ] = KEY_1,
594 [ 0x06 ] = KEY_2,
595 [ 0x07 ] = KEY_3,
596 [ 0x08 ] = KEY_CHANNELUP,
597 [ 0x09 ] = KEY_4,
598 [ 0x0a ] = KEY_5,
599 [ 0x0b ] = KEY_6,
600 [ 0x0c ] = KEY_CHANNELDOWN,
601 [ 0x0d ] = KEY_7,
602 [ 0x0e ] = KEY_8,
603 [ 0x0f ] = KEY_9,
604 [ 0x10 ] = KEY_VOLUMEUP,
605 [ 0x11 ] = KEY_0,
606 [ 0x12 ] = KEY_MENU,
607 [ 0x13 ] = KEY_PRINT,
608 [ 0x14 ] = KEY_VOLUMEDOWN,
609 [ 0x16 ] = KEY_PAUSE,
610 [ 0x18 ] = KEY_RECORD,
611 [ 0x19 ] = KEY_REWIND,
612 [ 0x1a ] = KEY_PLAY,
613 [ 0x1b ] = KEY_FORWARD,
614 [ 0x1c ] = KEY_BACKSPACE,
615 [ 0x1e ] = KEY_STOP,
616 [ 0x40 ] = KEY_ZOOM,
617};
618
619EXPORT_SYMBOL_GPL(ir_codes_em_terratec);
620
621IR_KEYTAB_TYPE ir_codes_em_pinnacle_usb[IR_KEYTAB_SIZE] = {
622 [ 0x3a ] = KEY_0,
623 [ 0x31 ] = KEY_1,
624 [ 0x32 ] = KEY_2,
625 [ 0x33 ] = KEY_3,
626 [ 0x34 ] = KEY_4,
627 [ 0x35 ] = KEY_5,
628 [ 0x36 ] = KEY_6,
629 [ 0x37 ] = KEY_7,
630 [ 0x38 ] = KEY_8,
631 [ 0x39 ] = KEY_9,
632
633 [ 0x2f ] = KEY_POWER,
634
635 [ 0x2e ] = KEY_P,
636 [ 0x1f ] = KEY_L,
637 [ 0x2b ] = KEY_I,
638
639 [ 0x2d ] = KEY_ZOOM,
640 [ 0x1e ] = KEY_ZOOM,
641 [ 0x1b ] = KEY_VOLUMEUP,
642 [ 0x0f ] = KEY_VOLUMEDOWN,
643 [ 0x17 ] = KEY_CHANNELUP,
644 [ 0x1c ] = KEY_CHANNELDOWN,
645 [ 0x25 ] = KEY_INFO,
646
647 [ 0x3c ] = KEY_MUTE,
648
649 [ 0x3d ] = KEY_LEFT,
650 [ 0x3b ] = KEY_RIGHT,
651
652 [ 0x3f ] = KEY_UP,
653 [ 0x3e ] = KEY_DOWN,
654 [ 0x1a ] = KEY_PAUSE,
655
656 [ 0x1d ] = KEY_MENU,
657 [ 0x19 ] = KEY_PLAY,
658 [ 0x16 ] = KEY_REWIND,
659 [ 0x13 ] = KEY_FORWARD,
660 [ 0x15 ] = KEY_PAUSE,
661 [ 0x0e ] = KEY_REWIND,
662 [ 0x0d ] = KEY_PLAY,
663 [ 0x0b ] = KEY_STOP,
664 [ 0x07 ] = KEY_FORWARD,
665 [ 0x27 ] = KEY_RECORD,
666 [ 0x26 ] = KEY_TUNER,
667 [ 0x29 ] = KEY_TEXT,
668 [ 0x2a ] = KEY_MEDIA,
669 [ 0x18 ] = KEY_EPG,
670 [ 0x27 ] = KEY_RECORD,
671};
672
673EXPORT_SYMBOL_GPL(ir_codes_em_pinnacle_usb);
674
675IR_KEYTAB_TYPE ir_codes_flyvideo[IR_KEYTAB_SIZE] = {
676 [ 0x0f ] = KEY_0,
677 [ 0x03 ] = KEY_1,
678 [ 0x04 ] = KEY_2,
679 [ 0x05 ] = KEY_3,
680 [ 0x07 ] = KEY_4,
681 [ 0x08 ] = KEY_5,
682 [ 0x09 ] = KEY_6,
683 [ 0x0b ] = KEY_7,
684 [ 0x0c ] = KEY_8,
685 [ 0x0d ] = KEY_9,
686
687 [ 0x0e ] = KEY_MODE, // Air/Cable
688 [ 0x11 ] = KEY_VIDEO, // Video
689 [ 0x15 ] = KEY_AUDIO, // Audio
690 [ 0x00 ] = KEY_POWER, // Power
691 [ 0x18 ] = KEY_TUNER, // AV Source
692 [ 0x02 ] = KEY_ZOOM, // Fullscreen
693 [ 0x1a ] = KEY_LANGUAGE, // Stereo
694 [ 0x1b ] = KEY_MUTE, // Mute
695 [ 0x14 ] = KEY_VOLUMEUP, // Volume +
696 [ 0x17 ] = KEY_VOLUMEDOWN, // Volume -
697 [ 0x12 ] = KEY_CHANNELUP, // Channel +
698 [ 0x13 ] = KEY_CHANNELDOWN, // Channel -
699 [ 0x06 ] = KEY_AGAIN, // Recall
700 [ 0x10 ] = KEY_ENTER, // Enter
701};
702
703EXPORT_SYMBOL_GPL(ir_codes_flyvideo);
704
705IR_KEYTAB_TYPE ir_codes_flydvb[IR_KEYTAB_SIZE] = {
706 [ 0x01 ] = KEY_ZOOM, // Full Screen
707 [ 0x00 ] = KEY_POWER, // Power
708
709 [ 0x03 ] = KEY_1,
710 [ 0x04 ] = KEY_2,
711 [ 0x05 ] = KEY_3,
712 [ 0x07 ] = KEY_4,
713 [ 0x08 ] = KEY_5,
714 [ 0x09 ] = KEY_6,
715 [ 0x0b ] = KEY_7,
716 [ 0x0c ] = KEY_8,
717 [ 0x0d ] = KEY_9,
718 [ 0x06 ] = KEY_AGAIN, // Recall
719 [ 0x0f ] = KEY_0,
720 [ 0x10 ] = KEY_MUTE, // Mute
721 [ 0x02 ] = KEY_RADIO, // TV/Radio
722 [ 0x1b ] = KEY_LANGUAGE, // SAP (Second Audio Program)
723
724 [ 0x14 ] = KEY_VOLUMEUP, // VOL+
725 [ 0x17 ] = KEY_VOLUMEDOWN, // VOL-
726 [ 0x12 ] = KEY_CHANNELUP, // CH+
727 [ 0x13 ] = KEY_CHANNELDOWN, // CH-
728 [ 0x1d ] = KEY_ENTER, // Enter
729
730 [ 0x1a ] = KEY_MODE, // PIP
731 [ 0x18 ] = KEY_TUNER, // Source
732
733 [ 0x1e ] = KEY_RECORD, // Record/Pause
734 [ 0x15 ] = KEY_ANGLE, // Swap (no label on key)
735 [ 0x1c ] = KEY_PAUSE, // Timeshift/Pause
736 [ 0x19 ] = KEY_BACK, // Rewind <<
737 [ 0x0a ] = KEY_PLAYPAUSE, // Play/Pause
738 [ 0x1f ] = KEY_FORWARD, // Forward >>
739 [ 0x16 ] = KEY_PREVIOUS, // Back |<<
740 [ 0x11 ] = KEY_STOP, // Stop
741 [ 0x0e ] = KEY_NEXT, // End >>|
742};
743
744EXPORT_SYMBOL_GPL(ir_codes_flydvb);
745
746IR_KEYTAB_TYPE ir_codes_cinergy[IR_KEYTAB_SIZE] = {
747 [ 0x00 ] = KEY_0,
748 [ 0x01 ] = KEY_1,
749 [ 0x02 ] = KEY_2,
750 [ 0x03 ] = KEY_3,
751 [ 0x04 ] = KEY_4,
752 [ 0x05 ] = KEY_5,
753 [ 0x06 ] = KEY_6,
754 [ 0x07 ] = KEY_7,
755 [ 0x08 ] = KEY_8,
756 [ 0x09 ] = KEY_9,
757
758 [ 0x0a ] = KEY_POWER,
759 [ 0x0b ] = KEY_PROG1, // app
760 [ 0x0c ] = KEY_ZOOM, // zoom/fullscreen
761 [ 0x0d ] = KEY_CHANNELUP, // channel
762 [ 0x0e ] = KEY_CHANNELDOWN, // channel-
763 [ 0x0f ] = KEY_VOLUMEUP,
764 [ 0x10 ] = KEY_VOLUMEDOWN,
765 [ 0x11 ] = KEY_TUNER, // AV
766 [ 0x12 ] = KEY_NUMLOCK, // -/--
767 [ 0x13 ] = KEY_AUDIO, // audio
768 [ 0x14 ] = KEY_MUTE,
769 [ 0x15 ] = KEY_UP,
770 [ 0x16 ] = KEY_DOWN,
771 [ 0x17 ] = KEY_LEFT,
772 [ 0x18 ] = KEY_RIGHT,
773 [ 0x19 ] = BTN_LEFT,
774 [ 0x1a ] = BTN_RIGHT,
775 [ 0x1b ] = KEY_WWW, // text
776 [ 0x1c ] = KEY_REWIND,
777 [ 0x1d ] = KEY_FORWARD,
778 [ 0x1e ] = KEY_RECORD,
779 [ 0x1f ] = KEY_PLAY,
780 [ 0x20 ] = KEY_PREVIOUSSONG,
781 [ 0x21 ] = KEY_NEXTSONG,
782 [ 0x22 ] = KEY_PAUSE,
783 [ 0x23 ] = KEY_STOP,
784};
785
786EXPORT_SYMBOL_GPL(ir_codes_cinergy);
787
788/* Alfons Geser <a.geser@cox.net>
789 * updates from Job D. R. Borges <jobdrb@ig.com.br> */
790IR_KEYTAB_TYPE ir_codes_eztv[IR_KEYTAB_SIZE] = {
791 [ 0x12 ] = KEY_POWER,
792 [ 0x01 ] = KEY_TV, // DVR
793 [ 0x15 ] = KEY_DVD, // DVD
794 [ 0x17 ] = KEY_AUDIO, // music
795 // DVR mode / DVD mode / music mode
796
797 [ 0x1b ] = KEY_MUTE, // mute
798 [ 0x02 ] = KEY_LANGUAGE, // MTS/SAP / audio / autoseek
799 [ 0x1e ] = KEY_SUBTITLE, // closed captioning / subtitle / seek
800 [ 0x16 ] = KEY_ZOOM, // full screen
801 [ 0x1c ] = KEY_VIDEO, // video source / eject / delall
802 [ 0x1d ] = KEY_RESTART, // playback / angle / del
803 [ 0x2f ] = KEY_SEARCH, // scan / menu / playlist
804 [ 0x30 ] = KEY_CHANNEL, // CH surfing / bookmark / memo
805
806 [ 0x31 ] = KEY_HELP, // help
807 [ 0x32 ] = KEY_MODE, // num/memo
808 [ 0x33 ] = KEY_ESC, // cancel
809
810 [ 0x0c ] = KEY_UP, // up
811 [ 0x10 ] = KEY_DOWN, // down
812 [ 0x08 ] = KEY_LEFT, // left
813 [ 0x04 ] = KEY_RIGHT, // right
814 [ 0x03 ] = KEY_SELECT, // select
815
816 [ 0x1f ] = KEY_REWIND, // rewind
817 [ 0x20 ] = KEY_PLAYPAUSE, // play/pause
818 [ 0x29 ] = KEY_FORWARD, // forward
819 [ 0x14 ] = KEY_AGAIN, // repeat
820 [ 0x2b ] = KEY_RECORD, // recording
821 [ 0x2c ] = KEY_STOP, // stop
822 [ 0x2d ] = KEY_PLAY, // play
823 [ 0x2e ] = KEY_SHUFFLE, // snapshot / shuffle
824
825 [ 0x00 ] = KEY_0,
826 [ 0x05 ] = KEY_1,
827 [ 0x06 ] = KEY_2,
828 [ 0x07 ] = KEY_3,
829 [ 0x09 ] = KEY_4,
830 [ 0x0a ] = KEY_5,
831 [ 0x0b ] = KEY_6,
832 [ 0x0d ] = KEY_7,
833 [ 0x0e ] = KEY_8,
834 [ 0x0f ] = KEY_9,
835
836 [ 0x2a ] = KEY_VOLUMEUP,
837 [ 0x11 ] = KEY_VOLUMEDOWN,
838 [ 0x18 ] = KEY_CHANNELUP, // CH.tracking up
839 [ 0x19 ] = KEY_CHANNELDOWN, // CH.tracking down
840
841 [ 0x13 ] = KEY_ENTER, // enter
842 [ 0x21 ] = KEY_DOT, // . (decimal dot)
843};
844
845EXPORT_SYMBOL_GPL(ir_codes_eztv);
846
847/* Alex Hermann <gaaf@gmx.net> */
848IR_KEYTAB_TYPE ir_codes_avermedia[IR_KEYTAB_SIZE] = {
849 [ 0x28 ] = KEY_1,
850 [ 0x18 ] = KEY_2,
851 [ 0x38 ] = KEY_3,
852 [ 0x24 ] = KEY_4,
853 [ 0x14 ] = KEY_5,
854 [ 0x34 ] = KEY_6,
855 [ 0x2c ] = KEY_7,
856 [ 0x1c ] = KEY_8,
857 [ 0x3c ] = KEY_9,
858 [ 0x22 ] = KEY_0,
859
860 [ 0x20 ] = KEY_TV, /* TV/FM */
861 [ 0x10 ] = KEY_CD, /* CD */
862 [ 0x30 ] = KEY_TEXT, /* TELETEXT */
863 [ 0x00 ] = KEY_POWER, /* POWER */
864
865 [ 0x08 ] = KEY_VIDEO, /* VIDEO */
866 [ 0x04 ] = KEY_AUDIO, /* AUDIO */
867 [ 0x0c ] = KEY_ZOOM, /* FULL SCREEN */
868
869 [ 0x12 ] = KEY_SUBTITLE, /* DISPLAY */
870 [ 0x32 ] = KEY_REWIND, /* LOOP */
871 [ 0x02 ] = KEY_PRINT, /* PREVIEW */
872
873 [ 0x2a ] = KEY_SEARCH, /* AUTOSCAN */
874 [ 0x1a ] = KEY_SLEEP, /* FREEZE */
875 [ 0x3a ] = KEY_SHUFFLE, /* SNAPSHOT */
876 [ 0x0a ] = KEY_MUTE, /* MUTE */
877
878 [ 0x26 ] = KEY_RECORD, /* RECORD */
879 [ 0x16 ] = KEY_PAUSE, /* PAUSE */
880 [ 0x36 ] = KEY_STOP, /* STOP */
881 [ 0x06 ] = KEY_PLAY, /* PLAY */
882
883 [ 0x2e ] = KEY_RED, /* RED */
884 [ 0x21 ] = KEY_GREEN, /* GREEN */
885 [ 0x0e ] = KEY_YELLOW, /* YELLOW */
886 [ 0x01 ] = KEY_BLUE, /* BLUE */
887
888 [ 0x1e ] = KEY_VOLUMEDOWN, /* VOLUME- */
889 [ 0x3e ] = KEY_VOLUMEUP, /* VOLUME+ */
890 [ 0x11 ] = KEY_CHANNELDOWN, /* CHANNEL/PAGE- */
891 [ 0x31 ] = KEY_CHANNELUP /* CHANNEL/PAGE+ */
892};
893
894EXPORT_SYMBOL_GPL(ir_codes_avermedia);
895
896IR_KEYTAB_TYPE ir_codes_videomate_tv_pvr[IR_KEYTAB_SIZE] = {
897 [ 0x14 ] = KEY_MUTE,
898 [ 0x24 ] = KEY_ZOOM,
899
900 [ 0x01 ] = KEY_DVD,
901 [ 0x23 ] = KEY_RADIO,
902 [ 0x00 ] = KEY_TV,
903
904 [ 0x0a ] = KEY_REWIND,
905 [ 0x08 ] = KEY_PLAYPAUSE,
906 [ 0x0f ] = KEY_FORWARD,
907
908 [ 0x02 ] = KEY_PREVIOUS,
909 [ 0x07 ] = KEY_STOP,
910 [ 0x06 ] = KEY_NEXT,
911
912 [ 0x0c ] = KEY_UP,
913 [ 0x0e ] = KEY_DOWN,
914 [ 0x0b ] = KEY_LEFT,
915 [ 0x0d ] = KEY_RIGHT,
916 [ 0x11 ] = KEY_OK,
917
918 [ 0x03 ] = KEY_MENU,
919 [ 0x09 ] = KEY_SETUP,
920 [ 0x05 ] = KEY_VIDEO,
921 [ 0x22 ] = KEY_CHANNEL,
922
923 [ 0x12 ] = KEY_VOLUMEUP,
924 [ 0x15 ] = KEY_VOLUMEDOWN,
925 [ 0x10 ] = KEY_CHANNELUP,
926 [ 0x13 ] = KEY_CHANNELDOWN,
927
928 [ 0x04 ] = KEY_RECORD,
929
930 [ 0x16 ] = KEY_1,
931 [ 0x17 ] = KEY_2,
932 [ 0x18 ] = KEY_3,
933 [ 0x19 ] = KEY_4,
934 [ 0x1a ] = KEY_5,
935 [ 0x1b ] = KEY_6,
936 [ 0x1c ] = KEY_7,
937 [ 0x1d ] = KEY_8,
938 [ 0x1e ] = KEY_9,
939 [ 0x1f ] = KEY_0,
940
941 [ 0x20 ] = KEY_LANGUAGE,
942 [ 0x21 ] = KEY_SLEEP,
943};
944
945EXPORT_SYMBOL_GPL(ir_codes_videomate_tv_pvr);
946
947/* Michael Tokarev <mjt@tls.msk.ru>
948 http://www.corpit.ru/mjt/beholdTV/remote_control.jpg
949 keytable is used by MANLI MTV00[ 0x0c ] and BeholdTV 40[13] at
950 least, and probably other cards too.
951 The "ascii-art picture" below (in comments, first row
952 is the keycode in hex, and subsequent row(s) shows
953 the button labels (several variants when appropriate)
954 helps to descide which keycodes to assign to the buttons.
955 */
956IR_KEYTAB_TYPE ir_codes_manli[IR_KEYTAB_SIZE] = {
957
958 /* 0x1c 0x12 *
959 * FUNCTION POWER *
960 * FM (|) *
961 * */
962 [ 0x1c ] = KEY_RADIO, /*XXX*/
963 [ 0x12 ] = KEY_POWER,
964
965 /* 0x01 0x02 0x03 *
966 * 1 2 3 *
967 * *
968 * 0x04 0x05 0x06 *
969 * 4 5 6 *
970 * *
971 * 0x07 0x08 0x09 *
972 * 7 8 9 *
973 * */
974 [ 0x01 ] = KEY_1,
975 [ 0x02 ] = KEY_2,
976 [ 0x03 ] = KEY_3,
977 [ 0x04 ] = KEY_4,
978 [ 0x05 ] = KEY_5,
979 [ 0x06 ] = KEY_6,
980 [ 0x07 ] = KEY_7,
981 [ 0x08 ] = KEY_8,
982 [ 0x09 ] = KEY_9,
983
984 /* 0x0a 0x00 0x17 *
985 * RECALL 0 +100 *
986 * PLUS *
987 * */
988 [ 0x0a ] = KEY_AGAIN, /*XXX KEY_REWIND? */
989 [ 0x00 ] = KEY_0,
990 [ 0x17 ] = KEY_DIGITS, /*XXX*/
991
992 /* 0x14 0x10 *
993 * MENU INFO *
994 * OSD */
995 [ 0x14 ] = KEY_MENU,
996 [ 0x10 ] = KEY_INFO,
997
998 /* 0x0b *
999 * Up *
1000 * *
1001 * 0x18 0x16 0x0c *
1002 * Left Ok Right *
1003 * *
1004 * 0x015 *
1005 * Down *
1006 * */
1007 [ 0x0b ] = KEY_UP, /*XXX KEY_SCROLLUP? */
1008 [ 0x18 ] = KEY_LEFT, /*XXX KEY_BACK? */
1009 [ 0x16 ] = KEY_OK, /*XXX KEY_SELECT? KEY_ENTER? */
1010 [ 0x0c ] = KEY_RIGHT, /*XXX KEY_FORWARD? */
1011 [ 0x15 ] = KEY_DOWN, /*XXX KEY_SCROLLDOWN? */
1012
1013 /* 0x11 0x0d *
1014 * TV/AV MODE *
1015 * SOURCE STEREO *
1016 * */
1017 [ 0x11 ] = KEY_TV, /*XXX*/
1018 [ 0x0d ] = KEY_MODE, /*XXX there's no KEY_STEREO */
1019
1020 /* 0x0f 0x1b 0x1a *
1021 * AUDIO Vol+ Chan+ *
1022 * TIMESHIFT??? *
1023 * *
1024 * 0x0e 0x1f 0x1e *
1025 * SLEEP Vol- Chan- *
1026 * */
1027 [ 0x0f ] = KEY_AUDIO,
1028 [ 0x1b ] = KEY_VOLUMEUP,
1029 [ 0x1a ] = KEY_CHANNELUP,
1030 [ 0x0e ] = KEY_SLEEP, /*XXX maybe KEY_PAUSE */
1031 [ 0x1f ] = KEY_VOLUMEDOWN,
1032 [ 0x1e ] = KEY_CHANNELDOWN,
1033
1034 /* 0x13 0x19 *
1035 * MUTE SNAPSHOT*
1036 * */
1037 [ 0x13 ] = KEY_MUTE,
1038 [ 0x19 ] = KEY_RECORD, /*XXX*/
1039
1040 // 0x1d unused ?
1041};
1042
1043EXPORT_SYMBOL_GPL(ir_codes_manli);
1044
1045/* Mike Baikov <mike@baikov.com> */
1046IR_KEYTAB_TYPE ir_codes_gotview7135[IR_KEYTAB_SIZE] = {
1047
1048 [ 0x21 ] = KEY_POWER,
1049 [ 0x69 ] = KEY_TV,
1050 [ 0x33 ] = KEY_0,
1051 [ 0x51 ] = KEY_1,
1052 [ 0x31 ] = KEY_2,
1053 [ 0x71 ] = KEY_3,
1054 [ 0x3b ] = KEY_4,
1055 [ 0x58 ] = KEY_5,
1056 [ 0x41 ] = KEY_6,
1057 [ 0x48 ] = KEY_7,
1058 [ 0x30 ] = KEY_8,
1059 [ 0x53 ] = KEY_9,
1060 [ 0x73 ] = KEY_AGAIN, /* LOOP */
1061 [ 0x0a ] = KEY_AUDIO,
1062 [ 0x61 ] = KEY_PRINT, /* PREVIEW */
1063 [ 0x7a ] = KEY_VIDEO,
1064 [ 0x20 ] = KEY_CHANNELUP,
1065 [ 0x40 ] = KEY_CHANNELDOWN,
1066 [ 0x18 ] = KEY_VOLUMEDOWN,
1067 [ 0x50 ] = KEY_VOLUMEUP,
1068 [ 0x10 ] = KEY_MUTE,
1069 [ 0x4a ] = KEY_SEARCH,
1070 [ 0x7b ] = KEY_SHUFFLE, /* SNAPSHOT */
1071 [ 0x22 ] = KEY_RECORD,
1072 [ 0x62 ] = KEY_STOP,
1073 [ 0x78 ] = KEY_PLAY,
1074 [ 0x39 ] = KEY_REWIND,
1075 [ 0x59 ] = KEY_PAUSE,
1076 [ 0x19 ] = KEY_FORWARD,
1077 [ 0x09 ] = KEY_ZOOM,
1078
1079 [ 0x52 ] = KEY_F21, /* LIVE TIMESHIFT */
1080 [ 0x1a ] = KEY_F22, /* MIN TIMESHIFT */
1081 [ 0x3a ] = KEY_F23, /* TIMESHIFT */
1082 [ 0x70 ] = KEY_F24, /* NORMAL TIMESHIFT */
1083};
1084
1085EXPORT_SYMBOL_GPL(ir_codes_gotview7135);
1086
1087IR_KEYTAB_TYPE ir_codes_purpletv[IR_KEYTAB_SIZE] = {
1088 [ 0x03 ] = KEY_POWER,
1089 [ 0x6f ] = KEY_MUTE,
1090 [ 0x10 ] = KEY_BACKSPACE, /* Recall */
1091
1092 [ 0x11 ] = KEY_0,
1093 [ 0x04 ] = KEY_1,
1094 [ 0x05 ] = KEY_2,
1095 [ 0x06 ] = KEY_3,
1096 [ 0x08 ] = KEY_4,
1097 [ 0x09 ] = KEY_5,
1098 [ 0x0a ] = KEY_6,
1099 [ 0x0c ] = KEY_7,
1100 [ 0x0d ] = KEY_8,
1101 [ 0x0e ] = KEY_9,
1102 [ 0x12 ] = KEY_DOT, /* 100+ */
1103
1104 [ 0x07 ] = KEY_VOLUMEUP,
1105 [ 0x0b ] = KEY_VOLUMEDOWN,
1106 [ 0x1a ] = KEY_KPPLUS,
1107 [ 0x18 ] = KEY_KPMINUS,
1108 [ 0x15 ] = KEY_UP,
1109 [ 0x1d ] = KEY_DOWN,
1110 [ 0x0f ] = KEY_CHANNELUP,
1111 [ 0x13 ] = KEY_CHANNELDOWN,
1112 [ 0x48 ] = KEY_ZOOM,
1113
1114 [ 0x1b ] = KEY_VIDEO, /* Video source */
1115 [ 0x49 ] = KEY_LANGUAGE, /* MTS Select */
1116 [ 0x19 ] = KEY_SEARCH, /* Auto Scan */
1117
1118 [ 0x4b ] = KEY_RECORD,
1119 [ 0x46 ] = KEY_PLAY,
1120 [ 0x45 ] = KEY_PAUSE, /* Pause */
1121 [ 0x44 ] = KEY_STOP,
1122 [ 0x40 ] = KEY_FORWARD, /* Forward ? */
1123 [ 0x42 ] = KEY_REWIND, /* Backward ? */
1124
1125};
1126
1127EXPORT_SYMBOL_GPL(ir_codes_purpletv);
1128
1129/* Mapping for the 28 key remote control as seen at
1130 http://www.sednacomputer.com/photo/cardbus-tv.jpg
1131 Pavel Mihaylov <bin@bash.info> */
1132IR_KEYTAB_TYPE ir_codes_pctv_sedna[IR_KEYTAB_SIZE] = {
1133 [ 0x00 ] = KEY_0,
1134 [ 0x01 ] = KEY_1,
1135 [ 0x02 ] = KEY_2,
1136 [ 0x03 ] = KEY_3,
1137 [ 0x04 ] = KEY_4,
1138 [ 0x05 ] = KEY_5,
1139 [ 0x06 ] = KEY_6,
1140 [ 0x07 ] = KEY_7,
1141 [ 0x08 ] = KEY_8,
1142 [ 0x09 ] = KEY_9,
1143
1144 [ 0x0a ] = KEY_AGAIN, /* Recall */
1145 [ 0x0b ] = KEY_CHANNELUP,
1146 [ 0x0c ] = KEY_VOLUMEUP,
1147 [ 0x0d ] = KEY_MODE, /* Stereo */
1148 [ 0x0e ] = KEY_STOP,
1149 [ 0x0f ] = KEY_PREVIOUSSONG,
1150 [ 0x10 ] = KEY_ZOOM,
1151 [ 0x11 ] = KEY_TUNER, /* Source */
1152 [ 0x12 ] = KEY_POWER,
1153 [ 0x13 ] = KEY_MUTE,
1154 [ 0x15 ] = KEY_CHANNELDOWN,
1155 [ 0x18 ] = KEY_VOLUMEDOWN,
1156 [ 0x19 ] = KEY_SHUFFLE, /* Snapshot */
1157 [ 0x1a ] = KEY_NEXTSONG,
1158 [ 0x1b ] = KEY_TEXT, /* Time Shift */
1159 [ 0x1c ] = KEY_RADIO, /* FM Radio */
1160 [ 0x1d ] = KEY_RECORD,
1161 [ 0x1e ] = KEY_PAUSE,
1162};
1163
1164EXPORT_SYMBOL_GPL(ir_codes_pctv_sedna);
1165
1166/* Mark Phalan <phalanm@o2.ie> */
1167IR_KEYTAB_TYPE ir_codes_pv951[IR_KEYTAB_SIZE] = {
1168 [ 0x00 ] = KEY_0,
1169 [ 0x01 ] = KEY_1,
1170 [ 0x02 ] = KEY_2,
1171 [ 0x03 ] = KEY_3,
1172 [ 0x04 ] = KEY_4,
1173 [ 0x05 ] = KEY_5,
1174 [ 0x06 ] = KEY_6,
1175 [ 0x07 ] = KEY_7,
1176 [ 0x08 ] = KEY_8,
1177 [ 0x09 ] = KEY_9,
1178
1179 [ 0x12 ] = KEY_POWER,
1180 [ 0x10 ] = KEY_MUTE,
1181 [ 0x1f ] = KEY_VOLUMEDOWN,
1182 [ 0x1b ] = KEY_VOLUMEUP,
1183 [ 0x1a ] = KEY_CHANNELUP,
1184 [ 0x1e ] = KEY_CHANNELDOWN,
1185 [ 0x0e ] = KEY_PAGEUP,
1186 [ 0x1d ] = KEY_PAGEDOWN,
1187 [ 0x13 ] = KEY_SOUND,
1188
1189 [ 0x18 ] = KEY_KPPLUSMINUS, /* CH +/- */
1190 [ 0x16 ] = KEY_SUBTITLE, /* CC */
1191 [ 0x0d ] = KEY_TEXT, /* TTX */
1192 [ 0x0b ] = KEY_TV, /* AIR/CBL */
1193 [ 0x11 ] = KEY_PC, /* PC/TV */
1194 [ 0x17 ] = KEY_OK, /* CH RTN */
1195 [ 0x19 ] = KEY_MODE, /* FUNC */
1196 [ 0x0c ] = KEY_SEARCH, /* AUTOSCAN */
1197
1198 /* Not sure what to do with these ones! */
1199 [ 0x0f ] = KEY_SELECT, /* SOURCE */
1200 [ 0x0a ] = KEY_KPPLUS, /* +100 */
1201 [ 0x14 ] = KEY_EQUAL, /* SYNC */
1202 [ 0x1c ] = KEY_MEDIA, /* PC/TV */
1203};
1204
1205EXPORT_SYMBOL_GPL(ir_codes_pv951);
1206
1207/* generic RC5 keytable */
1208/* see http://users.pandora.be/nenya/electronics/rc5/codes00.htm */
1209/* used by old (black) Hauppauge remotes */
1210IR_KEYTAB_TYPE ir_codes_rc5_tv[IR_KEYTAB_SIZE] = {
1211 /* Keys 0 to 9 */
1212 [ 0x00 ] = KEY_0,
1213 [ 0x01 ] = KEY_1,
1214 [ 0x02 ] = KEY_2,
1215 [ 0x03 ] = KEY_3,
1216 [ 0x04 ] = KEY_4,
1217 [ 0x05 ] = KEY_5,
1218 [ 0x06 ] = KEY_6,
1219 [ 0x07 ] = KEY_7,
1220 [ 0x08 ] = KEY_8,
1221 [ 0x09 ] = KEY_9,
1222
1223 [ 0x0b ] = KEY_CHANNEL, /* channel / program (japan: 11) */
1224 [ 0x0c ] = KEY_POWER, /* standby */
1225 [ 0x0d ] = KEY_MUTE, /* mute / demute */
1226 [ 0x0f ] = KEY_TV, /* display */
1227 [ 0x10 ] = KEY_VOLUMEUP,
1228 [ 0x11 ] = KEY_VOLUMEDOWN,
1229 [ 0x12 ] = KEY_BRIGHTNESSUP,
1230 [ 0x13 ] = KEY_BRIGHTNESSDOWN,
1231 [ 0x1e ] = KEY_SEARCH, /* search + */
1232 [ 0x20 ] = KEY_CHANNELUP, /* channel / program + */
1233 [ 0x21 ] = KEY_CHANNELDOWN, /* channel / program - */
1234 [ 0x22 ] = KEY_CHANNEL, /* alt / channel */
1235 [ 0x23 ] = KEY_LANGUAGE, /* 1st / 2nd language */
1236 [ 0x26 ] = KEY_SLEEP, /* sleeptimer */
1237 [ 0x2e ] = KEY_MENU, /* 2nd controls (USA: menu) */
1238 [ 0x30 ] = KEY_PAUSE,
1239 [ 0x32 ] = KEY_REWIND,
1240 [ 0x33 ] = KEY_GOTO,
1241 [ 0x35 ] = KEY_PLAY,
1242 [ 0x36 ] = KEY_STOP,
1243 [ 0x37 ] = KEY_RECORD, /* recording */
1244 [ 0x3c ] = KEY_TEXT, /* teletext submode (Japan: 12) */
1245 [ 0x3d ] = KEY_SUSPEND, /* system standby */
1246
1247};
1248
1249EXPORT_SYMBOL_GPL(ir_codes_rc5_tv);
1250
1251/* Table for Leadtek Winfast Remote Controls - used by both bttv and cx88 */
1252IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE] = {
1253 /* Keys 0 to 9 */
1254 [ 0x12 ] = KEY_0,
1255 [ 0x05 ] = KEY_1,
1256 [ 0x06 ] = KEY_2,
1257 [ 0x07 ] = KEY_3,
1258 [ 0x09 ] = KEY_4,
1259 [ 0x0a ] = KEY_5,
1260 [ 0x0b ] = KEY_6,
1261 [ 0x0d ] = KEY_7,
1262 [ 0x0e ] = KEY_8,
1263 [ 0x0f ] = KEY_9,
1264
1265 [ 0x00 ] = KEY_POWER,
1266 [ 0x02 ] = KEY_TUNER, /* TV/FM */
1267 [ 0x1e ] = KEY_VIDEO,
1268 [ 0x04 ] = KEY_VOLUMEUP,
1269 [ 0x08 ] = KEY_VOLUMEDOWN,
1270 [ 0x0c ] = KEY_CHANNELUP,
1271 [ 0x10 ] = KEY_CHANNELDOWN,
1272 [ 0x03 ] = KEY_ZOOM, /* fullscreen */
1273 [ 0x1f ] = KEY_SUBTITLE, /* closed caption/teletext */
1274 [ 0x20 ] = KEY_SLEEP,
1275 [ 0x14 ] = KEY_MUTE,
1276 [ 0x2b ] = KEY_RED,
1277 [ 0x2c ] = KEY_GREEN,
1278 [ 0x2d ] = KEY_YELLOW,
1279 [ 0x2e ] = KEY_BLUE,
1280 [ 0x18 ] = KEY_KPPLUS, /* fine tune + */
1281 [ 0x19 ] = KEY_KPMINUS, /* fine tune - */
1282 [ 0x21 ] = KEY_DOT,
1283 [ 0x13 ] = KEY_ENTER,
1284 [ 0x22 ] = KEY_BACK,
1285 [ 0x23 ] = KEY_PLAYPAUSE,
1286 [ 0x24 ] = KEY_NEXT,
1287 [ 0x26 ] = KEY_STOP,
1288 [ 0x27 ] = KEY_RECORD
1289};
1290
1291EXPORT_SYMBOL_GPL(ir_codes_winfast);
1292
1293IR_KEYTAB_TYPE ir_codes_pinnacle[IR_KEYTAB_SIZE] = {
1294 [ 0x59 ] = KEY_MUTE,
1295 [ 0x4a ] = KEY_POWER,
1296
1297 [ 0x18 ] = KEY_TEXT,
1298 [ 0x26 ] = KEY_TV,
1299 [ 0x3d ] = KEY_PRINT,
1300
1301 [ 0x48 ] = KEY_RED,
1302 [ 0x04 ] = KEY_GREEN,
1303 [ 0x11 ] = KEY_YELLOW,
1304 [ 0x00 ] = KEY_BLUE,
1305
1306 [ 0x2d ] = KEY_VOLUMEUP,
1307 [ 0x1e ] = KEY_VOLUMEDOWN,
1308
1309 [ 0x49 ] = KEY_MENU,
1310
1311 [ 0x16 ] = KEY_CHANNELUP,
1312 [ 0x17 ] = KEY_CHANNELDOWN,
1313
1314 [ 0x20 ] = KEY_UP,
1315 [ 0x21 ] = KEY_DOWN,
1316 [ 0x22 ] = KEY_LEFT,
1317 [ 0x23 ] = KEY_RIGHT,
1318 [ 0x0d ] = KEY_SELECT,
1319
1320
1321
1322 [ 0x08 ] = KEY_BACK,
1323 [ 0x07 ] = KEY_REFRESH,
1324
1325 [ 0x2f ] = KEY_ZOOM,
1326 [ 0x29 ] = KEY_RECORD,
1327
1328 [ 0x4b ] = KEY_PAUSE,
1329 [ 0x4d ] = KEY_REWIND,
1330 [ 0x2e ] = KEY_PLAY,
1331 [ 0x4e ] = KEY_FORWARD,
1332 [ 0x53 ] = KEY_PREVIOUS,
1333 [ 0x4c ] = KEY_STOP,
1334 [ 0x54 ] = KEY_NEXT,
1335
1336 [ 0x69 ] = KEY_0,
1337 [ 0x6a ] = KEY_1,
1338 [ 0x6b ] = KEY_2,
1339 [ 0x6c ] = KEY_3,
1340 [ 0x6d ] = KEY_4,
1341 [ 0x6e ] = KEY_5,
1342 [ 0x6f ] = KEY_6,
1343 [ 0x70 ] = KEY_7,
1344 [ 0x71 ] = KEY_8,
1345 [ 0x72 ] = KEY_9,
1346
1347 [ 0x74 ] = KEY_CHANNEL,
1348 [ 0x0a ] = KEY_BACKSPACE,
1349};
1350
1351EXPORT_SYMBOL_GPL(ir_codes_pinnacle);
1352
1353/* Hauppauge: the newer, gray remotes (seems there are multiple
1354 * slightly different versions), shipped with cx88+ivtv cards.
1355 * almost rc5 coding, but some non-standard keys */
1356IR_KEYTAB_TYPE ir_codes_hauppauge_new[IR_KEYTAB_SIZE] = {
1357 /* Keys 0 to 9 */
1358 [ 0x00 ] = KEY_0,
1359 [ 0x01 ] = KEY_1,
1360 [ 0x02 ] = KEY_2,
1361 [ 0x03 ] = KEY_3,
1362 [ 0x04 ] = KEY_4,
1363 [ 0x05 ] = KEY_5,
1364 [ 0x06 ] = KEY_6,
1365 [ 0x07 ] = KEY_7,
1366 [ 0x08 ] = KEY_8,
1367 [ 0x09 ] = KEY_9,
1368
1369 [ 0x0a ] = KEY_TEXT, /* keypad asterisk as well */
1370 [ 0x0b ] = KEY_RED, /* red button */
1371 [ 0x0c ] = KEY_RADIO,
1372 [ 0x0d ] = KEY_MENU,
1373 [ 0x0e ] = KEY_SUBTITLE, /* also the # key */
1374 [ 0x0f ] = KEY_MUTE,
1375 [ 0x10 ] = KEY_VOLUMEUP,
1376 [ 0x11 ] = KEY_VOLUMEDOWN,
1377 [ 0x12 ] = KEY_PREVIOUS, /* previous channel */
1378 [ 0x14 ] = KEY_UP,
1379 [ 0x15 ] = KEY_DOWN,
1380 [ 0x16 ] = KEY_LEFT,
1381 [ 0x17 ] = KEY_RIGHT,
1382 [ 0x18 ] = KEY_VIDEO, /* Videos */
1383 [ 0x19 ] = KEY_AUDIO, /* Music */
1384 /* 0x1a: Pictures - presume this means
1385 "Multimedia Home Platform" -
1386 no "PICTURES" key in input.h
1387 */
1388 [ 0x1a ] = KEY_MHP,
1389
1390 [ 0x1b ] = KEY_EPG, /* Guide */
1391 [ 0x1c ] = KEY_TV,
1392 [ 0x1e ] = KEY_NEXTSONG, /* skip >| */
1393 [ 0x1f ] = KEY_EXIT, /* back/exit */
1394 [ 0x20 ] = KEY_CHANNELUP, /* channel / program + */
1395 [ 0x21 ] = KEY_CHANNELDOWN, /* channel / program - */
1396 [ 0x22 ] = KEY_CHANNEL, /* source (old black remote) */
1397 [ 0x24 ] = KEY_PREVIOUSSONG, /* replay |< */
1398 [ 0x25 ] = KEY_ENTER, /* OK */
1399 [ 0x26 ] = KEY_SLEEP, /* minimize (old black remote) */
1400 [ 0x29 ] = KEY_BLUE, /* blue key */
1401 [ 0x2e ] = KEY_GREEN, /* green button */
1402 [ 0x30 ] = KEY_PAUSE, /* pause */
1403 [ 0x32 ] = KEY_REWIND, /* backward << */
1404 [ 0x34 ] = KEY_FASTFORWARD, /* forward >> */
1405 [ 0x35 ] = KEY_PLAY,
1406 [ 0x36 ] = KEY_STOP,
1407 [ 0x37 ] = KEY_RECORD, /* recording */
1408 [ 0x38 ] = KEY_YELLOW, /* yellow key */
1409 [ 0x3b ] = KEY_SELECT, /* top right button */
1410 [ 0x3c ] = KEY_ZOOM, /* full */
1411 [ 0x3d ] = KEY_POWER, /* system power (green button) */
1412};
1413
1414EXPORT_SYMBOL_GPL(ir_codes_hauppauge_new);
1415
diff --git a/drivers/media/common/saa7146_core.c b/drivers/media/common/saa7146_core.c
index 04c1938b9c91..8cdd4d265ffa 100644
--- a/drivers/media/common/saa7146_core.c
+++ b/drivers/media/common/saa7146_core.c
@@ -21,7 +21,7 @@
21#include <media/saa7146.h> 21#include <media/saa7146.h>
22 22
23LIST_HEAD(saa7146_devices); 23LIST_HEAD(saa7146_devices);
24DECLARE_MUTEX(saa7146_devices_lock); 24DEFINE_MUTEX(saa7146_devices_lock);
25 25
26static int saa7146_num; 26static int saa7146_num;
27 27
@@ -116,8 +116,7 @@ static struct scatterlist* vmalloc_to_sg(unsigned char *virt, int nr_pages)
116 pg = vmalloc_to_page(virt); 116 pg = vmalloc_to_page(virt);
117 if (NULL == pg) 117 if (NULL == pg)
118 goto err; 118 goto err;
119 if (PageHighMem(pg)) 119 BUG_ON(PageHighMem(pg));
120 BUG();
121 sglist[i].page = pg; 120 sglist[i].page = pg;
122 sglist[i].length = PAGE_SIZE; 121 sglist[i].length = PAGE_SIZE;
123 } 122 }
@@ -402,11 +401,11 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
402 401
403 pci_set_drvdata(pci, dev); 402 pci_set_drvdata(pci, dev);
404 403
405 init_MUTEX(&dev->lock); 404 mutex_init(&dev->lock);
406 spin_lock_init(&dev->int_slock); 405 spin_lock_init(&dev->int_slock);
407 spin_lock_init(&dev->slock); 406 spin_lock_init(&dev->slock);
408 407
409 init_MUTEX(&dev->i2c_lock); 408 mutex_init(&dev->i2c_lock);
410 409
411 dev->module = THIS_MODULE; 410 dev->module = THIS_MODULE;
412 init_waitqueue_head(&dev->i2c_wq); 411 init_waitqueue_head(&dev->i2c_wq);
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index f8cf73ed49ad..3870fa948cc0 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -17,18 +17,18 @@ int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit)
17 } 17 }
18 18
19 /* is it free? */ 19 /* is it free? */
20 down(&dev->lock); 20 mutex_lock(&dev->lock);
21 if (vv->resources & bit) { 21 if (vv->resources & bit) {
22 DEB_D(("locked! vv->resources:0x%02x, we want:0x%02x\n",vv->resources,bit)); 22 DEB_D(("locked! vv->resources:0x%02x, we want:0x%02x\n",vv->resources,bit));
23 /* no, someone else uses it */ 23 /* no, someone else uses it */
24 up(&dev->lock); 24 mutex_unlock(&dev->lock);
25 return 0; 25 return 0;
26 } 26 }
27 /* it's free, grab it */ 27 /* it's free, grab it */
28 fh->resources |= bit; 28 fh->resources |= bit;
29 vv->resources |= bit; 29 vv->resources |= bit;
30 DEB_D(("res: get 0x%02x, cur:0x%02x\n",bit,vv->resources)); 30 DEB_D(("res: get 0x%02x, cur:0x%02x\n",bit,vv->resources));
31 up(&dev->lock); 31 mutex_unlock(&dev->lock);
32 return 1; 32 return 1;
33} 33}
34 34
@@ -37,14 +37,13 @@ void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits)
37 struct saa7146_dev *dev = fh->dev; 37 struct saa7146_dev *dev = fh->dev;
38 struct saa7146_vv *vv = dev->vv_data; 38 struct saa7146_vv *vv = dev->vv_data;
39 39
40 if ((fh->resources & bits) != bits) 40 BUG_ON((fh->resources & bits) != bits);
41 BUG();
42 41
43 down(&dev->lock); 42 mutex_lock(&dev->lock);
44 fh->resources &= ~bits; 43 fh->resources &= ~bits;
45 vv->resources &= ~bits; 44 vv->resources &= ~bits;
46 DEB_D(("res: put 0x%02x, cur:0x%02x\n",bits,vv->resources)); 45 DEB_D(("res: put 0x%02x, cur:0x%02x\n",bits,vv->resources));
47 up(&dev->lock); 46 mutex_unlock(&dev->lock);
48} 47}
49 48
50 49
@@ -55,8 +54,7 @@ void saa7146_dma_free(struct saa7146_dev *dev,struct saa7146_buf *buf)
55{ 54{
56 DEB_EE(("dev:%p, buf:%p\n",dev,buf)); 55 DEB_EE(("dev:%p, buf:%p\n",dev,buf));
57 56
58 if (in_interrupt()) 57 BUG_ON(in_interrupt());
59 BUG();
60 58
61 videobuf_waiton(&buf->vb,0,0); 59 videobuf_waiton(&buf->vb,0,0);
62 videobuf_dma_pci_unmap(dev->pci, &buf->vb.dma); 60 videobuf_dma_pci_unmap(dev->pci, &buf->vb.dma);
@@ -204,7 +202,7 @@ static int fops_open(struct inode *inode, struct file *file)
204 202
205 DEB_EE(("inode:%p, file:%p, minor:%d\n",inode,file,minor)); 203 DEB_EE(("inode:%p, file:%p, minor:%d\n",inode,file,minor));
206 204
207 if (down_interruptible(&saa7146_devices_lock)) 205 if (mutex_lock_interruptible(&saa7146_devices_lock))
208 return -ERESTARTSYS; 206 return -ERESTARTSYS;
209 207
210 list_for_each(list,&saa7146_devices) { 208 list_for_each(list,&saa7146_devices) {
@@ -276,7 +274,7 @@ out:
276 kfree(fh); 274 kfree(fh);
277 file->private_data = NULL; 275 file->private_data = NULL;
278 } 276 }
279 up(&saa7146_devices_lock); 277 mutex_unlock(&saa7146_devices_lock);
280 return result; 278 return result;
281} 279}
282 280
@@ -287,7 +285,7 @@ static int fops_release(struct inode *inode, struct file *file)
287 285
288 DEB_EE(("inode:%p, file:%p\n",inode,file)); 286 DEB_EE(("inode:%p, file:%p\n",inode,file));
289 287
290 if (down_interruptible(&saa7146_devices_lock)) 288 if (mutex_lock_interruptible(&saa7146_devices_lock))
291 return -ERESTARTSYS; 289 return -ERESTARTSYS;
292 290
293 if( fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { 291 if( fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
@@ -303,7 +301,7 @@ static int fops_release(struct inode *inode, struct file *file)
303 file->private_data = NULL; 301 file->private_data = NULL;
304 kfree(fh); 302 kfree(fh);
305 303
306 up(&saa7146_devices_lock); 304 mutex_unlock(&saa7146_devices_lock);
307 305
308 return 0; 306 return 0;
309} 307}
diff --git a/drivers/media/common/saa7146_i2c.c b/drivers/media/common/saa7146_i2c.c
index 8aabdd8fb3c5..d9953f7a8b6b 100644
--- a/drivers/media/common/saa7146_i2c.c
+++ b/drivers/media/common/saa7146_i2c.c
@@ -279,7 +279,7 @@ int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *msgs, in
279 int address_err = 0; 279 int address_err = 0;
280 int short_delay = 0; 280 int short_delay = 0;
281 281
282 if (down_interruptible (&dev->i2c_lock)) 282 if (mutex_lock_interruptible(&dev->i2c_lock))
283 return -ERESTARTSYS; 283 return -ERESTARTSYS;
284 284
285 for(i=0;i<num;i++) { 285 for(i=0;i<num;i++) {
@@ -366,7 +366,7 @@ out:
366 } 366 }
367 } 367 }
368 368
369 up(&dev->i2c_lock); 369 mutex_unlock(&dev->i2c_lock);
370 return err; 370 return err;
371} 371}
372 372
diff --git a/drivers/media/common/saa7146_vbi.c b/drivers/media/common/saa7146_vbi.c
index 468d3c959075..500bd3f05e16 100644
--- a/drivers/media/common/saa7146_vbi.c
+++ b/drivers/media/common/saa7146_vbi.c
@@ -410,7 +410,7 @@ static int vbi_open(struct saa7146_dev *dev, struct file *file)
410 V4L2_FIELD_SEQ_TB, // FIXME: does this really work? 410 V4L2_FIELD_SEQ_TB, // FIXME: does this really work?
411 sizeof(struct saa7146_buf), 411 sizeof(struct saa7146_buf),
412 file); 412 file);
413 init_MUTEX(&fh->vbi_q.lock); 413 mutex_init(&fh->vbi_q.lock);
414 414
415 init_timer(&fh->vbi_read_timeout); 415 init_timer(&fh->vbi_read_timeout);
416 fh->vbi_read_timeout.function = vbi_read_timeout; 416 fh->vbi_read_timeout.function = vbi_read_timeout;
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index 7ebac7949df3..6b42713d97f4 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -378,20 +378,20 @@ static int s_fmt(struct saa7146_fh *fh, struct v4l2_format *f)
378 err = try_win(dev,&f->fmt.win); 378 err = try_win(dev,&f->fmt.win);
379 if (0 != err) 379 if (0 != err)
380 return err; 380 return err;
381 down(&dev->lock); 381 mutex_lock(&dev->lock);
382 fh->ov.win = f->fmt.win; 382 fh->ov.win = f->fmt.win;
383 fh->ov.nclips = f->fmt.win.clipcount; 383 fh->ov.nclips = f->fmt.win.clipcount;
384 if (fh->ov.nclips > 16) 384 if (fh->ov.nclips > 16)
385 fh->ov.nclips = 16; 385 fh->ov.nclips = 16;
386 if (copy_from_user(fh->ov.clips,f->fmt.win.clips,sizeof(struct v4l2_clip)*fh->ov.nclips)) { 386 if (copy_from_user(fh->ov.clips,f->fmt.win.clips,sizeof(struct v4l2_clip)*fh->ov.nclips)) {
387 up(&dev->lock); 387 mutex_unlock(&dev->lock);
388 return -EFAULT; 388 return -EFAULT;
389 } 389 }
390 390
391 /* fh->ov.fh is used to indicate that we have valid overlay informations, too */ 391 /* fh->ov.fh is used to indicate that we have valid overlay informations, too */
392 fh->ov.fh = fh; 392 fh->ov.fh = fh;
393 393
394 up(&dev->lock); 394 mutex_unlock(&dev->lock);
395 395
396 /* check if our current overlay is active */ 396 /* check if our current overlay is active */
397 if (IS_OVERLAY_ACTIVE(fh) != 0) { 397 if (IS_OVERLAY_ACTIVE(fh) != 0) {
@@ -516,7 +516,7 @@ static int set_control(struct saa7146_fh *fh, struct v4l2_control *c)
516 return -EINVAL; 516 return -EINVAL;
517 } 517 }
518 518
519 down(&dev->lock); 519 mutex_lock(&dev->lock);
520 520
521 switch (ctrl->type) { 521 switch (ctrl->type) {
522 case V4L2_CTRL_TYPE_BOOLEAN: 522 case V4L2_CTRL_TYPE_BOOLEAN:
@@ -560,7 +560,7 @@ static int set_control(struct saa7146_fh *fh, struct v4l2_control *c)
560 /* fixme: we can support changing VFLIP and HFLIP here... */ 560 /* fixme: we can support changing VFLIP and HFLIP here... */
561 if (IS_CAPTURE_ACTIVE(fh) != 0) { 561 if (IS_CAPTURE_ACTIVE(fh) != 0) {
562 DEB_D(("V4L2_CID_HFLIP while active capture.\n")); 562 DEB_D(("V4L2_CID_HFLIP while active capture.\n"));
563 up(&dev->lock); 563 mutex_unlock(&dev->lock);
564 return -EINVAL; 564 return -EINVAL;
565 } 565 }
566 vv->hflip = c->value; 566 vv->hflip = c->value;
@@ -568,7 +568,7 @@ static int set_control(struct saa7146_fh *fh, struct v4l2_control *c)
568 case V4L2_CID_VFLIP: 568 case V4L2_CID_VFLIP:
569 if (IS_CAPTURE_ACTIVE(fh) != 0) { 569 if (IS_CAPTURE_ACTIVE(fh) != 0) {
570 DEB_D(("V4L2_CID_VFLIP while active capture.\n")); 570 DEB_D(("V4L2_CID_VFLIP while active capture.\n"));
571 up(&dev->lock); 571 mutex_unlock(&dev->lock);
572 return -EINVAL; 572 return -EINVAL;
573 } 573 }
574 vv->vflip = c->value; 574 vv->vflip = c->value;
@@ -577,7 +577,7 @@ static int set_control(struct saa7146_fh *fh, struct v4l2_control *c)
577 return -EINVAL; 577 return -EINVAL;
578 } 578 }
579 } 579 }
580 up(&dev->lock); 580 mutex_unlock(&dev->lock);
581 581
582 if (IS_OVERLAY_ACTIVE(fh) != 0) { 582 if (IS_OVERLAY_ACTIVE(fh) != 0) {
583 saa7146_stop_preview(fh); 583 saa7146_stop_preview(fh);
@@ -939,7 +939,7 @@ int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int
939 } 939 }
940 } 940 }
941 941
942 down(&dev->lock); 942 mutex_lock(&dev->lock);
943 943
944 /* ok, accept it */ 944 /* ok, accept it */
945 vv->ov_fb = *fb; 945 vv->ov_fb = *fb;
@@ -948,7 +948,7 @@ int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int
948 vv->ov_fb.fmt.bytesperline = 948 vv->ov_fb.fmt.bytesperline =
949 vv->ov_fb.fmt.width*fmt->depth/8; 949 vv->ov_fb.fmt.width*fmt->depth/8;
950 950
951 up(&dev->lock); 951 mutex_unlock(&dev->lock);
952 952
953 return 0; 953 return 0;
954 } 954 }
@@ -1086,7 +1086,7 @@ int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int
1086 } 1086 }
1087 } 1087 }
1088 1088
1089 down(&dev->lock); 1089 mutex_lock(&dev->lock);
1090 1090
1091 for(i = 0; i < dev->ext_vv_data->num_stds; i++) 1091 for(i = 0; i < dev->ext_vv_data->num_stds; i++)
1092 if (*id & dev->ext_vv_data->stds[i].id) 1092 if (*id & dev->ext_vv_data->stds[i].id)
@@ -1098,7 +1098,7 @@ int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int
1098 found = 1; 1098 found = 1;
1099 } 1099 }
1100 1100
1101 up(&dev->lock); 1101 mutex_unlock(&dev->lock);
1102 1102
1103 if (vv->ov_suspend != NULL) { 1103 if (vv->ov_suspend != NULL) {
1104 saa7146_start_preview(vv->ov_suspend); 1104 saa7146_start_preview(vv->ov_suspend);
@@ -1201,11 +1201,11 @@ int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int
1201 DEB_D(("VIDIOCGMBUF \n")); 1201 DEB_D(("VIDIOCGMBUF \n"));
1202 1202
1203 q = &fh->video_q; 1203 q = &fh->video_q;
1204 down(&q->lock); 1204 mutex_lock(&q->lock);
1205 err = videobuf_mmap_setup(q,gbuffers,gbufsize, 1205 err = videobuf_mmap_setup(q,gbuffers,gbufsize,
1206 V4L2_MEMORY_MMAP); 1206 V4L2_MEMORY_MMAP);
1207 if (err < 0) { 1207 if (err < 0) {
1208 up(&q->lock); 1208 mutex_unlock(&q->lock);
1209 return err; 1209 return err;
1210 } 1210 }
1211 memset(mbuf,0,sizeof(*mbuf)); 1211 memset(mbuf,0,sizeof(*mbuf));
@@ -1213,7 +1213,7 @@ int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int
1213 mbuf->size = gbuffers * gbufsize; 1213 mbuf->size = gbuffers * gbufsize;
1214 for (i = 0; i < gbuffers; i++) 1214 for (i = 0; i < gbuffers; i++)
1215 mbuf->offsets[i] = i * gbufsize; 1215 mbuf->offsets[i] = i * gbufsize;
1216 up(&q->lock); 1216 mutex_unlock(&q->lock);
1217 return 0; 1217 return 0;
1218 } 1218 }
1219 default: 1219 default:
@@ -1414,7 +1414,7 @@ static int video_open(struct saa7146_dev *dev, struct file *file)
1414 sizeof(struct saa7146_buf), 1414 sizeof(struct saa7146_buf),
1415 file); 1415 file);
1416 1416
1417 init_MUTEX(&fh->video_q.lock); 1417 mutex_init(&fh->video_q.lock);
1418 1418
1419 return 0; 1419 return 0;
1420} 1420}
diff --git a/drivers/media/dvb/b2c2/flexcop-common.h b/drivers/media/dvb/b2c2/flexcop-common.h
index 7d7e1613c5a7..b3dd0603cd92 100644
--- a/drivers/media/dvb/b2c2/flexcop-common.h
+++ b/drivers/media/dvb/b2c2/flexcop-common.h
@@ -10,6 +10,7 @@
10 10
11#include <linux/config.h> 11#include <linux/config.h>
12#include <linux/pci.h> 12#include <linux/pci.h>
13#include <linux/mutex.h>
13 14
14#include "flexcop-reg.h" 15#include "flexcop-reg.h"
15 16
@@ -73,8 +74,7 @@ struct flexcop_device {
73 int (*fe_sleep) (struct dvb_frontend *); 74 int (*fe_sleep) (struct dvb_frontend *);
74 75
75 struct i2c_adapter i2c_adap; 76 struct i2c_adapter i2c_adap;
76 struct semaphore i2c_sem; 77 struct mutex i2c_mutex;
77
78 struct module *owner; 78 struct module *owner;
79 79
80 /* options and status */ 80 /* options and status */
diff --git a/drivers/media/dvb/b2c2/flexcop-i2c.c b/drivers/media/dvb/b2c2/flexcop-i2c.c
index 56495cb6cd02..e0bd2d8f0f0c 100644
--- a/drivers/media/dvb/b2c2/flexcop-i2c.c
+++ b/drivers/media/dvb/b2c2/flexcop-i2c.c
@@ -135,7 +135,7 @@ static int flexcop_master_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs
135 struct flexcop_device *fc = i2c_get_adapdata(i2c_adap); 135 struct flexcop_device *fc = i2c_get_adapdata(i2c_adap);
136 int i, ret = 0; 136 int i, ret = 0;
137 137
138 if (down_interruptible(&fc->i2c_sem)) 138 if (mutex_lock_interruptible(&fc->i2c_mutex))
139 return -ERESTARTSYS; 139 return -ERESTARTSYS;
140 140
141 /* reading */ 141 /* reading */
@@ -161,7 +161,7 @@ static int flexcop_master_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs
161 else 161 else
162 ret = num; 162 ret = num;
163 163
164 up(&fc->i2c_sem); 164 mutex_unlock(&fc->i2c_mutex);
165 165
166 return ret; 166 return ret;
167} 167}
@@ -180,7 +180,7 @@ int flexcop_i2c_init(struct flexcop_device *fc)
180{ 180{
181 int ret; 181 int ret;
182 182
183 sema_init(&fc->i2c_sem,1); 183 mutex_init(&fc->i2c_mutex);
184 184
185 memset(&fc->i2c_adap, 0, sizeof(struct i2c_adapter)); 185 memset(&fc->i2c_adap, 0, sizeof(struct i2c_adapter));
186 strncpy(fc->i2c_adap.name, "B2C2 FlexCop device",I2C_NAME_SIZE); 186 strncpy(fc->i2c_adap.name, "B2C2 FlexCop device",I2C_NAME_SIZE);
diff --git a/drivers/media/dvb/bt8xx/bt878.c b/drivers/media/dvb/bt8xx/bt878.c
index 356f447ee2ab..5500f8a0ffe2 100644
--- a/drivers/media/dvb/bt8xx/bt878.c
+++ b/drivers/media/dvb/bt8xx/bt878.c
@@ -344,7 +344,7 @@ bt878_device_control(struct bt878 *bt, unsigned int cmd, union dst_gpio_packet *
344 int retval; 344 int retval;
345 345
346 retval = 0; 346 retval = 0;
347 if (down_interruptible (&bt->gpio_lock)) 347 if (mutex_lock_interruptible(&bt->gpio_lock))
348 return -ERESTARTSYS; 348 return -ERESTARTSYS;
349 /* special gpio signal */ 349 /* special gpio signal */
350 switch (cmd) { 350 switch (cmd) {
@@ -375,7 +375,7 @@ bt878_device_control(struct bt878 *bt, unsigned int cmd, union dst_gpio_packet *
375 retval = -EINVAL; 375 retval = -EINVAL;
376 break; 376 break;
377 } 377 }
378 up(&bt->gpio_lock); 378 mutex_unlock(&bt->gpio_lock);
379 return retval; 379 return retval;
380} 380}
381 381
diff --git a/drivers/media/dvb/bt8xx/bt878.h b/drivers/media/dvb/bt8xx/bt878.h
index 9faf93770d08..f685bc129609 100644
--- a/drivers/media/dvb/bt8xx/bt878.h
+++ b/drivers/media/dvb/bt8xx/bt878.h
@@ -25,6 +25,8 @@
25#include <linux/pci.h> 25#include <linux/pci.h>
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/mutex.h>
29
28#include "bt848.h" 30#include "bt848.h"
29#include "bttv.h" 31#include "bttv.h"
30 32
@@ -108,7 +110,7 @@ struct cards {
108extern int bt878_num; 110extern int bt878_num;
109 111
110struct bt878 { 112struct bt878 {
111 struct semaphore gpio_lock; 113 struct mutex gpio_lock;
112 unsigned int nr; 114 unsigned int nr;
113 unsigned int bttv_nr; 115 unsigned int bttv_nr;
114 struct i2c_adapter *adapter; 116 struct i2c_adapter *adapter;
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 0310e3dd07e6..1cfa5e5035d8 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -910,7 +910,7 @@ static int dst_get_device_id(struct dst_state *state)
910 910
911static int dst_probe(struct dst_state *state) 911static int dst_probe(struct dst_state *state)
912{ 912{
913 sema_init(&state->dst_mutex, 1); 913 mutex_init(&state->dst_mutex);
914 if ((rdc_8820_reset(state)) < 0) { 914 if ((rdc_8820_reset(state)) < 0) {
915 dprintk(verbose, DST_ERROR, 1, "RDC 8820 RESET Failed."); 915 dprintk(verbose, DST_ERROR, 1, "RDC 8820 RESET Failed.");
916 return -1; 916 return -1;
@@ -962,7 +962,7 @@ int dst_command(struct dst_state *state, u8 *data, u8 len)
962{ 962{
963 u8 reply; 963 u8 reply;
964 964
965 down(&state->dst_mutex); 965 mutex_lock(&state->dst_mutex);
966 if ((dst_comm_init(state)) < 0) { 966 if ((dst_comm_init(state)) < 0) {
967 dprintk(verbose, DST_NOTICE, 1, "DST Communication Initialization Failed."); 967 dprintk(verbose, DST_NOTICE, 1, "DST Communication Initialization Failed.");
968 goto error; 968 goto error;
@@ -1013,11 +1013,11 @@ int dst_command(struct dst_state *state, u8 *data, u8 len)
1013 dprintk(verbose, DST_INFO, 1, "checksum failure"); 1013 dprintk(verbose, DST_INFO, 1, "checksum failure");
1014 goto error; 1014 goto error;
1015 } 1015 }
1016 up(&state->dst_mutex); 1016 mutex_unlock(&state->dst_mutex);
1017 return 0; 1017 return 0;
1018 1018
1019error: 1019error:
1020 up(&state->dst_mutex); 1020 mutex_unlock(&state->dst_mutex);
1021 return -EIO; 1021 return -EIO;
1022 1022
1023} 1023}
@@ -1128,7 +1128,7 @@ static int dst_write_tuna(struct dvb_frontend *fe)
1128 dst_set_voltage(fe, SEC_VOLTAGE_13); 1128 dst_set_voltage(fe, SEC_VOLTAGE_13);
1129 } 1129 }
1130 state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE); 1130 state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
1131 down(&state->dst_mutex); 1131 mutex_lock(&state->dst_mutex);
1132 if ((dst_comm_init(state)) < 0) { 1132 if ((dst_comm_init(state)) < 0) {
1133 dprintk(verbose, DST_DEBUG, 1, "DST Communication initialization failed."); 1133 dprintk(verbose, DST_DEBUG, 1, "DST Communication initialization failed.");
1134 goto error; 1134 goto error;
@@ -1160,11 +1160,11 @@ static int dst_write_tuna(struct dvb_frontend *fe)
1160 state->diseq_flags |= ATTEMPT_TUNE; 1160 state->diseq_flags |= ATTEMPT_TUNE;
1161 retval = dst_get_tuna(state); 1161 retval = dst_get_tuna(state);
1162werr: 1162werr:
1163 up(&state->dst_mutex); 1163 mutex_unlock(&state->dst_mutex);
1164 return retval; 1164 return retval;
1165 1165
1166error: 1166error:
1167 up(&state->dst_mutex); 1167 mutex_unlock(&state->dst_mutex);
1168 return -EIO; 1168 return -EIO;
1169} 1169}
1170 1170
diff --git a/drivers/media/dvb/bt8xx/dst_ca.c b/drivers/media/dvb/bt8xx/dst_ca.c
index c650b4bf7f5f..f6b49a801eba 100644
--- a/drivers/media/dvb/bt8xx/dst_ca.c
+++ b/drivers/media/dvb/bt8xx/dst_ca.c
@@ -81,7 +81,7 @@ static int dst_ci_command(struct dst_state* state, u8 * data, u8 *ca_string, u8
81{ 81{
82 u8 reply; 82 u8 reply;
83 83
84 down(&state->dst_mutex); 84 mutex_lock(&state->dst_mutex);
85 dst_comm_init(state); 85 dst_comm_init(state);
86 msleep(65); 86 msleep(65);
87 87
@@ -110,11 +110,11 @@ static int dst_ci_command(struct dst_state* state, u8 * data, u8 *ca_string, u8
110 goto error; 110 goto error;
111 } 111 }
112 } 112 }
113 up(&state->dst_mutex); 113 mutex_unlock(&state->dst_mutex);
114 return 0; 114 return 0;
115 115
116error: 116error:
117 up(&state->dst_mutex); 117 mutex_unlock(&state->dst_mutex);
118 return -EIO; 118 return -EIO;
119} 119}
120 120
diff --git a/drivers/media/dvb/bt8xx/dst_common.h b/drivers/media/dvb/bt8xx/dst_common.h
index 81557f38fe38..51d4e043716c 100644
--- a/drivers/media/dvb/bt8xx/dst_common.h
+++ b/drivers/media/dvb/bt8xx/dst_common.h
@@ -25,6 +25,7 @@
25#include <linux/smp_lock.h> 25#include <linux/smp_lock.h>
26#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
27#include <linux/device.h> 27#include <linux/device.h>
28#include <linux/mutex.h>
28#include "bt878.h" 29#include "bt878.h"
29 30
30#include "dst_ca.h" 31#include "dst_ca.h"
@@ -121,7 +122,7 @@ struct dst_state {
121 u8 vendor[8]; 122 u8 vendor[8];
122 u8 board_info[8]; 123 u8 board_info[8];
123 124
124 struct semaphore dst_mutex; 125 struct mutex dst_mutex;
125}; 126};
126 127
127struct dst_types { 128struct dst_types {
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index ea27b15007e9..baa8227ef87c 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -76,13 +76,13 @@ static int dvb_bt8xx_start_feed(struct dvb_demux_feed *dvbdmxfeed)
76 if (!dvbdmx->dmx.frontend) 76 if (!dvbdmx->dmx.frontend)
77 return -EINVAL; 77 return -EINVAL;
78 78
79 down(&card->lock); 79 mutex_lock(&card->lock);
80 card->nfeeds++; 80 card->nfeeds++;
81 rc = card->nfeeds; 81 rc = card->nfeeds;
82 if (card->nfeeds == 1) 82 if (card->nfeeds == 1)
83 bt878_start(card->bt, card->gpio_mode, 83 bt878_start(card->bt, card->gpio_mode,
84 card->op_sync_orin, card->irq_err_ignore); 84 card->op_sync_orin, card->irq_err_ignore);
85 up(&card->lock); 85 mutex_unlock(&card->lock);
86 return rc; 86 return rc;
87} 87}
88 88
@@ -96,11 +96,11 @@ static int dvb_bt8xx_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
96 if (!dvbdmx->dmx.frontend) 96 if (!dvbdmx->dmx.frontend)
97 return -EINVAL; 97 return -EINVAL;
98 98
99 down(&card->lock); 99 mutex_lock(&card->lock);
100 card->nfeeds--; 100 card->nfeeds--;
101 if (card->nfeeds == 0) 101 if (card->nfeeds == 0)
102 bt878_stop(card->bt); 102 bt878_stop(card->bt);
103 up(&card->lock); 103 mutex_unlock(&card->lock);
104 104
105 return 0; 105 return 0;
106} 106}
@@ -239,6 +239,20 @@ static int cx24108_pll_set(struct dvb_frontend* fe, struct dvb_frontend_paramete
239 239
240static int pinnsat_pll_init(struct dvb_frontend* fe) 240static int pinnsat_pll_init(struct dvb_frontend* fe)
241{ 241{
242 struct dvb_bt8xx_card *card = fe->dvb->priv;
243
244 bttv_gpio_enable(card->bttv_nr, 1, 1); /* output */
245 bttv_write_gpio(card->bttv_nr, 1, 1); /* relay on */
246
247 return 0;
248}
249
250static int pinnsat_pll_sleep(struct dvb_frontend* fe)
251{
252 struct dvb_bt8xx_card *card = fe->dvb->priv;
253
254 bttv_write_gpio(card->bttv_nr, 1, 0); /* relay off */
255
242 return 0; 256 return 0;
243} 257}
244 258
@@ -246,6 +260,7 @@ static struct cx24110_config pctvsat_config = {
246 .demod_address = 0x55, 260 .demod_address = 0x55,
247 .pll_init = pinnsat_pll_init, 261 .pll_init = pinnsat_pll_init,
248 .pll_set = cx24108_pll_set, 262 .pll_set = cx24108_pll_set,
263 .pll_sleep = pinnsat_pll_sleep,
249}; 264};
250 265
251static int microtune_mt7202dtf_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 266static int microtune_mt7202dtf_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
@@ -788,7 +803,7 @@ static int dvb_bt8xx_probe(struct bttv_sub_device *sub)
788 if (!(card = kzalloc(sizeof(struct dvb_bt8xx_card), GFP_KERNEL))) 803 if (!(card = kzalloc(sizeof(struct dvb_bt8xx_card), GFP_KERNEL)))
789 return -ENOMEM; 804 return -ENOMEM;
790 805
791 init_MUTEX(&card->lock); 806 mutex_init(&card->lock);
792 card->bttv_nr = sub->core->nr; 807 card->bttv_nr = sub->core->nr;
793 strncpy(card->card_name, sub->core->name, sizeof(sub->core->name)); 808 strncpy(card->card_name, sub->core->name, sizeof(sub->core->name));
794 card->i2c_adapter = &sub->core->i2c_adap; 809 card->i2c_adapter = &sub->core->i2c_adap;
@@ -798,14 +813,14 @@ static int dvb_bt8xx_probe(struct bttv_sub_device *sub)
798 card->gpio_mode = 0x0400c060; 813 card->gpio_mode = 0x0400c060;
799 /* should be: BT878_A_GAIN=0,BT878_A_PWRDN,BT878_DA_DPM,BT878_DA_SBR, 814 /* should be: BT878_A_GAIN=0,BT878_A_PWRDN,BT878_DA_DPM,BT878_DA_SBR,
800 BT878_DA_IOM=1,BT878_DA_APP to enable serial highspeed mode. */ 815 BT878_DA_IOM=1,BT878_DA_APP to enable serial highspeed mode. */
801 card->op_sync_orin = 0; 816 card->op_sync_orin = BT878_RISC_SYNC_MASK;
802 card->irq_err_ignore = 0; 817 card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR;
803 break; 818 break;
804 819
805 case BTTV_BOARD_DVICO_DVBT_LITE: 820 case BTTV_BOARD_DVICO_DVBT_LITE:
806 card->gpio_mode = 0x0400C060; 821 card->gpio_mode = 0x0400C060;
807 card->op_sync_orin = 0; 822 card->op_sync_orin = BT878_RISC_SYNC_MASK;
808 card->irq_err_ignore = 0; 823 card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR;
809 /* 26, 15, 14, 6, 5 824 /* 26, 15, 14, 6, 5
810 * A_PWRDN DA_DPM DA_SBR DA_IOM_DA 825 * A_PWRDN DA_DPM DA_SBR DA_IOM_DA
811 * DA_APP(parallel) */ 826 * DA_APP(parallel) */
@@ -820,15 +835,15 @@ static int dvb_bt8xx_probe(struct bttv_sub_device *sub)
820 case BTTV_BOARD_NEBULA_DIGITV: 835 case BTTV_BOARD_NEBULA_DIGITV:
821 case BTTV_BOARD_AVDVBT_761: 836 case BTTV_BOARD_AVDVBT_761:
822 card->gpio_mode = (1 << 26) | (1 << 14) | (1 << 5); 837 card->gpio_mode = (1 << 26) | (1 << 14) | (1 << 5);
823 card->op_sync_orin = 0; 838 card->op_sync_orin = BT878_RISC_SYNC_MASK;
824 card->irq_err_ignore = 0; 839 card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR;
825 /* A_PWRDN DA_SBR DA_APP (high speed serial) */ 840 /* A_PWRDN DA_SBR DA_APP (high speed serial) */
826 break; 841 break;
827 842
828 case BTTV_BOARD_AVDVBT_771: //case 0x07711461: 843 case BTTV_BOARD_AVDVBT_771: //case 0x07711461:
829 card->gpio_mode = 0x0400402B; 844 card->gpio_mode = 0x0400402B;
830 card->op_sync_orin = BT878_RISC_SYNC_MASK; 845 card->op_sync_orin = BT878_RISC_SYNC_MASK;
831 card->irq_err_ignore = 0; 846 card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR;
832 /* A_PWRDN DA_SBR DA_APP[0] PKTP=10 RISC_ENABLE FIFO_ENABLE*/ 847 /* A_PWRDN DA_SBR DA_APP[0] PKTP=10 RISC_ENABLE FIFO_ENABLE*/
833 break; 848 break;
834 849
@@ -852,8 +867,8 @@ static int dvb_bt8xx_probe(struct bttv_sub_device *sub)
852 867
853 case BTTV_BOARD_PC_HDTV: 868 case BTTV_BOARD_PC_HDTV:
854 card->gpio_mode = 0x0100EC7B; 869 card->gpio_mode = 0x0100EC7B;
855 card->op_sync_orin = 0; 870 card->op_sync_orin = BT878_RISC_SYNC_MASK;
856 card->irq_err_ignore = 0; 871 card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR;
857 break; 872 break;
858 873
859 default: 874 default:
@@ -881,7 +896,7 @@ static int dvb_bt8xx_probe(struct bttv_sub_device *sub)
881 return -EFAULT; 896 return -EFAULT;
882 } 897 }
883 898
884 init_MUTEX(&card->bt->gpio_lock); 899 mutex_init(&card->bt->gpio_lock);
885 card->bt->bttv_nr = sub->core->nr; 900 card->bt->bttv_nr = sub->core->nr;
886 901
887 if ( (ret = dvb_bt8xx_load_card(card, sub->core->type)) ) { 902 if ( (ret = dvb_bt8xx_load_card(card, sub->core->type)) ) {
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.h b/drivers/media/dvb/bt8xx/dvb-bt8xx.h
index cf035a80361c..00dd9fa54c82 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.h
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.h
@@ -26,6 +26,7 @@
26#define DVB_BT8XX_H 26#define DVB_BT8XX_H
27 27
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/mutex.h>
29#include "dvbdev.h" 30#include "dvbdev.h"
30#include "dvb_net.h" 31#include "dvb_net.h"
31#include "bttv.h" 32#include "bttv.h"
@@ -38,7 +39,7 @@
38#include "lgdt330x.h" 39#include "lgdt330x.h"
39 40
40struct dvb_bt8xx_card { 41struct dvb_bt8xx_card {
41 struct semaphore lock; 42 struct mutex lock;
42 int nfeeds; 43 int nfeeds;
43 char card_name[32]; 44 char card_name[32];
44 struct dvb_adapter dvb_adapter; 45 struct dvb_adapter dvb_adapter;
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
index c4b4c5b6b7c8..71b575dc22bd 100644
--- a/drivers/media/dvb/cinergyT2/cinergyT2.c
+++ b/drivers/media/dvb/cinergyT2/cinergyT2.c
@@ -30,6 +30,7 @@
30#include <linux/pci.h> 30#include <linux/pci.h>
31#include <linux/input.h> 31#include <linux/input.h>
32#include <linux/dvb/frontend.h> 32#include <linux/dvb/frontend.h>
33#include <linux/mutex.h>
33 34
34#include "dmxdev.h" 35#include "dmxdev.h"
35#include "dvb_demux.h" 36#include "dvb_demux.h"
@@ -116,7 +117,7 @@ static struct dvb_frontend_info cinergyt2_fe_info = {
116struct cinergyt2 { 117struct cinergyt2 {
117 struct dvb_demux demux; 118 struct dvb_demux demux;
118 struct usb_device *udev; 119 struct usb_device *udev;
119 struct semaphore sem; 120 struct mutex sem;
120 struct dvb_adapter adapter; 121 struct dvb_adapter adapter;
121 struct dvb_device *fedev; 122 struct dvb_device *fedev;
122 struct dmxdev dmxdev; 123 struct dmxdev dmxdev;
@@ -345,14 +346,14 @@ static int cinergyt2_start_feed(struct dvb_demux_feed *dvbdmxfeed)
345 struct dvb_demux *demux = dvbdmxfeed->demux; 346 struct dvb_demux *demux = dvbdmxfeed->demux;
346 struct cinergyt2 *cinergyt2 = demux->priv; 347 struct cinergyt2 *cinergyt2 = demux->priv;
347 348
348 if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem)) 349 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
349 return -ERESTARTSYS; 350 return -ERESTARTSYS;
350 351
351 if (cinergyt2->streaming == 0) 352 if (cinergyt2->streaming == 0)
352 cinergyt2_start_stream_xfer(cinergyt2); 353 cinergyt2_start_stream_xfer(cinergyt2);
353 354
354 cinergyt2->streaming++; 355 cinergyt2->streaming++;
355 up(&cinergyt2->sem); 356 mutex_unlock(&cinergyt2->sem);
356 return 0; 357 return 0;
357} 358}
358 359
@@ -361,13 +362,13 @@ static int cinergyt2_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
361 struct dvb_demux *demux = dvbdmxfeed->demux; 362 struct dvb_demux *demux = dvbdmxfeed->demux;
362 struct cinergyt2 *cinergyt2 = demux->priv; 363 struct cinergyt2 *cinergyt2 = demux->priv;
363 364
364 if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem)) 365 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
365 return -ERESTARTSYS; 366 return -ERESTARTSYS;
366 367
367 if (--cinergyt2->streaming == 0) 368 if (--cinergyt2->streaming == 0)
368 cinergyt2_stop_stream_xfer(cinergyt2); 369 cinergyt2_stop_stream_xfer(cinergyt2);
369 370
370 up(&cinergyt2->sem); 371 mutex_unlock(&cinergyt2->sem);
371 return 0; 372 return 0;
372} 373}
373 374
@@ -483,11 +484,11 @@ static int cinergyt2_open (struct inode *inode, struct file *file)
483 struct cinergyt2 *cinergyt2 = dvbdev->priv; 484 struct cinergyt2 *cinergyt2 = dvbdev->priv;
484 int err = -ERESTARTSYS; 485 int err = -ERESTARTSYS;
485 486
486 if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem)) 487 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
487 return -ERESTARTSYS; 488 return -ERESTARTSYS;
488 489
489 if ((err = dvb_generic_open(inode, file))) { 490 if ((err = dvb_generic_open(inode, file))) {
490 up(&cinergyt2->sem); 491 mutex_unlock(&cinergyt2->sem);
491 return err; 492 return err;
492 } 493 }
493 494
@@ -499,12 +500,15 @@ static int cinergyt2_open (struct inode *inode, struct file *file)
499 500
500 atomic_inc(&cinergyt2->inuse); 501 atomic_inc(&cinergyt2->inuse);
501 502
502 up(&cinergyt2->sem); 503 mutex_unlock(&cinergyt2->sem);
503 return 0; 504 return 0;
504} 505}
505 506
506static void cinergyt2_unregister(struct cinergyt2 *cinergyt2) 507static void cinergyt2_unregister(struct cinergyt2 *cinergyt2)
507{ 508{
509 dvb_net_release(&cinergyt2->dvbnet);
510 dvb_dmxdev_release(&cinergyt2->dmxdev);
511 dvb_dmx_release(&cinergyt2->demux);
508 dvb_unregister_device(cinergyt2->fedev); 512 dvb_unregister_device(cinergyt2->fedev);
509 dvb_unregister_adapter(&cinergyt2->adapter); 513 dvb_unregister_adapter(&cinergyt2->adapter);
510 514
@@ -517,7 +521,7 @@ static int cinergyt2_release (struct inode *inode, struct file *file)
517 struct dvb_device *dvbdev = file->private_data; 521 struct dvb_device *dvbdev = file->private_data;
518 struct cinergyt2 *cinergyt2 = dvbdev->priv; 522 struct cinergyt2 *cinergyt2 = dvbdev->priv;
519 523
520 if (down_interruptible(&cinergyt2->sem)) 524 if (mutex_lock_interruptible(&cinergyt2->sem))
521 return -ERESTARTSYS; 525 return -ERESTARTSYS;
522 526
523 if (!cinergyt2->disconnect_pending && (file->f_flags & O_ACCMODE) != O_RDONLY) { 527 if (!cinergyt2->disconnect_pending && (file->f_flags & O_ACCMODE) != O_RDONLY) {
@@ -526,7 +530,7 @@ static int cinergyt2_release (struct inode *inode, struct file *file)
526 cinergyt2_sleep(cinergyt2, 1); 530 cinergyt2_sleep(cinergyt2, 1);
527 } 531 }
528 532
529 up(&cinergyt2->sem); 533 mutex_unlock(&cinergyt2->sem);
530 534
531 if (atomic_dec_and_test(&cinergyt2->inuse) && cinergyt2->disconnect_pending) { 535 if (atomic_dec_and_test(&cinergyt2->inuse) && cinergyt2->disconnect_pending) {
532 warn("delayed unregister in release"); 536 warn("delayed unregister in release");
@@ -541,12 +545,12 @@ static unsigned int cinergyt2_poll (struct file *file, struct poll_table_struct
541 struct dvb_device *dvbdev = file->private_data; 545 struct dvb_device *dvbdev = file->private_data;
542 struct cinergyt2 *cinergyt2 = dvbdev->priv; 546 struct cinergyt2 *cinergyt2 = dvbdev->priv;
543 547
544 if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem)) 548 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
545 return -ERESTARTSYS; 549 return -ERESTARTSYS;
546 550
547 poll_wait(file, &cinergyt2->poll_wq, wait); 551 poll_wait(file, &cinergyt2->poll_wq, wait);
548 552
549 up(&cinergyt2->sem); 553 mutex_unlock(&cinergyt2->sem);
550 554
551 return (POLLIN | POLLRDNORM | POLLPRI); 555 return (POLLIN | POLLRDNORM | POLLPRI);
552} 556}
@@ -613,7 +617,7 @@ static int cinergyt2_ioctl (struct inode *inode, struct file *file,
613 if (copy_from_user(&p, (void __user*) arg, sizeof(p))) 617 if (copy_from_user(&p, (void __user*) arg, sizeof(p)))
614 return -EFAULT; 618 return -EFAULT;
615 619
616 if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem)) 620 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
617 return -ERESTARTSYS; 621 return -ERESTARTSYS;
618 622
619 param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS; 623 param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
@@ -629,7 +633,7 @@ static int cinergyt2_ioctl (struct inode *inode, struct file *file,
629 (char *) param, sizeof(*param), 633 (char *) param, sizeof(*param),
630 NULL, 0); 634 NULL, 0);
631 635
632 up(&cinergyt2->sem); 636 mutex_unlock(&cinergyt2->sem);
633 637
634 return (err < 0) ? err : 0; 638 return (err < 0) ? err : 0;
635 } 639 }
@@ -724,7 +728,7 @@ static void cinergyt2_query_rc (void *data)
724 struct cinergyt2_rc_event rc_events[12]; 728 struct cinergyt2_rc_event rc_events[12];
725 int n, len, i; 729 int n, len, i;
726 730
727 if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem)) 731 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
728 return; 732 return;
729 733
730 len = cinergyt2_command(cinergyt2, buf, sizeof(buf), 734 len = cinergyt2_command(cinergyt2, buf, sizeof(buf),
@@ -784,7 +788,7 @@ out:
784 schedule_delayed_work(&cinergyt2->rc_query_work, 788 schedule_delayed_work(&cinergyt2->rc_query_work,
785 msecs_to_jiffies(RC_QUERY_INTERVAL)); 789 msecs_to_jiffies(RC_QUERY_INTERVAL));
786 790
787 up(&cinergyt2->sem); 791 mutex_unlock(&cinergyt2->sem);
788} 792}
789 793
790static int cinergyt2_register_rc(struct cinergyt2 *cinergyt2) 794static int cinergyt2_register_rc(struct cinergyt2 *cinergyt2)
@@ -849,7 +853,7 @@ static void cinergyt2_query (void *data)
849 uint8_t lock_bits; 853 uint8_t lock_bits;
850 uint32_t unc; 854 uint32_t unc;
851 855
852 if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem)) 856 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
853 return; 857 return;
854 858
855 unc = s->uncorrected_block_count; 859 unc = s->uncorrected_block_count;
@@ -868,7 +872,7 @@ static void cinergyt2_query (void *data)
868 schedule_delayed_work(&cinergyt2->query_work, 872 schedule_delayed_work(&cinergyt2->query_work,
869 msecs_to_jiffies(QUERY_INTERVAL)); 873 msecs_to_jiffies(QUERY_INTERVAL));
870 874
871 up(&cinergyt2->sem); 875 mutex_unlock(&cinergyt2->sem);
872} 876}
873 877
874static int cinergyt2_probe (struct usb_interface *intf, 878static int cinergyt2_probe (struct usb_interface *intf,
@@ -885,7 +889,7 @@ static int cinergyt2_probe (struct usb_interface *intf,
885 memset (cinergyt2, 0, sizeof (struct cinergyt2)); 889 memset (cinergyt2, 0, sizeof (struct cinergyt2));
886 usb_set_intfdata (intf, (void *) cinergyt2); 890 usb_set_intfdata (intf, (void *) cinergyt2);
887 891
888 init_MUTEX(&cinergyt2->sem); 892 mutex_init(&cinergyt2->sem);
889 init_waitqueue_head (&cinergyt2->poll_wq); 893 init_waitqueue_head (&cinergyt2->poll_wq);
890 INIT_WORK(&cinergyt2->query_work, cinergyt2_query, cinergyt2); 894 INIT_WORK(&cinergyt2->query_work, cinergyt2_query, cinergyt2);
891 895
@@ -937,6 +941,7 @@ static int cinergyt2_probe (struct usb_interface *intf,
937 return 0; 941 return 0;
938 942
939bailout: 943bailout:
944 dvb_net_release(&cinergyt2->dvbnet);
940 dvb_dmxdev_release(&cinergyt2->dmxdev); 945 dvb_dmxdev_release(&cinergyt2->dmxdev);
941 dvb_dmx_release(&cinergyt2->demux); 946 dvb_dmx_release(&cinergyt2->demux);
942 dvb_unregister_adapter(&cinergyt2->adapter); 947 dvb_unregister_adapter(&cinergyt2->adapter);
@@ -967,7 +972,7 @@ static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state)
967{ 972{
968 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf); 973 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
969 974
970 if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem)) 975 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
971 return -ERESTARTSYS; 976 return -ERESTARTSYS;
972 977
973 if (state.event > PM_EVENT_ON) { 978 if (state.event > PM_EVENT_ON) {
@@ -981,7 +986,7 @@ static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state)
981 cinergyt2_sleep(cinergyt2, 1); 986 cinergyt2_sleep(cinergyt2, 1);
982 } 987 }
983 988
984 up(&cinergyt2->sem); 989 mutex_unlock(&cinergyt2->sem);
985 return 0; 990 return 0;
986} 991}
987 992
@@ -990,7 +995,7 @@ static int cinergyt2_resume (struct usb_interface *intf)
990 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf); 995 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
991 struct dvbt_set_parameters_msg *param = &cinergyt2->param; 996 struct dvbt_set_parameters_msg *param = &cinergyt2->param;
992 997
993 if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem)) 998 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
994 return -ERESTARTSYS; 999 return -ERESTARTSYS;
995 1000
996 if (!cinergyt2->sleeping) { 1001 if (!cinergyt2->sleeping) {
@@ -1003,7 +1008,7 @@ static int cinergyt2_resume (struct usb_interface *intf)
1003 1008
1004 cinergyt2_resume_rc(cinergyt2); 1009 cinergyt2_resume_rc(cinergyt2);
1005 1010
1006 up(&cinergyt2->sem); 1011 mutex_unlock(&cinergyt2->sem);
1007 return 0; 1012 return 0;
1008} 1013}
1009 1014
diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
index 7b8373ad121b..09e96e9ddbdf 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.c
+++ b/drivers/media/dvb/dvb-core/dmxdev.c
@@ -1,9 +1,8 @@
1/* 1/*
2 * dmxdev.c - DVB demultiplexer device 2 * dmxdev.c - DVB demultiplexer device
3 * 3 *
4 * Copyright (C) 2000 Ralph Metzler <ralph@convergence.de> 4 * Copyright (C) 2000 Ralph Metzler & Marcus Metzler
5 * & Marcus Metzler <marcus@convergence.de> 5 * for convergence integrated media GmbH
6 for convergence integrated media GmbH
7 * 6 *
8 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License 8 * modify it under the terms of the GNU Lesser General Public License
@@ -32,7 +31,6 @@
32#include <linux/wait.h> 31#include <linux/wait.h>
33#include <asm/uaccess.h> 32#include <asm/uaccess.h>
34#include <asm/system.h> 33#include <asm/system.h>
35
36#include "dmxdev.h" 34#include "dmxdev.h"
37 35
38static int debug; 36static int debug;
@@ -42,177 +40,133 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
42 40
43#define dprintk if (debug) printk 41#define dprintk if (debug) printk
44 42
45static inline void dvb_dmxdev_buffer_init(struct dmxdev_buffer *buffer) 43static int dvb_dmxdev_buffer_write(struct dvb_ringbuffer *buf,
44 const u8 *src, size_t len)
46{ 45{
47 buffer->data=NULL; 46 ssize_t free;
48 buffer->size=8192;
49 buffer->pread=0;
50 buffer->pwrite=0;
51 buffer->error=0;
52 init_waitqueue_head(&buffer->queue);
53}
54
55static inline int dvb_dmxdev_buffer_write(struct dmxdev_buffer *buf, const u8 *src, int len)
56{
57 int split;
58 int free;
59 int todo;
60 47
61 if (!len) 48 if (!len)
62 return 0; 49 return 0;
63 if (!buf->data) 50 if (!buf->data)
64 return 0; 51 return 0;
65 52
66 free=buf->pread-buf->pwrite; 53 free = dvb_ringbuffer_free(buf);
67 split=0; 54 if (len > free) {
68 if (free<=0) {
69 free+=buf->size;
70 split=buf->size-buf->pwrite;
71 }
72 if (len>=free) {
73 dprintk("dmxdev: buffer overflow\n"); 55 dprintk("dmxdev: buffer overflow\n");
74 return -1; 56 return -EOVERFLOW;
75 } 57 }
76 if (split>=len) 58
77 split=0; 59 return dvb_ringbuffer_write(buf, src, len);
78 todo=len;
79 if (split) {
80 memcpy(buf->data + buf->pwrite, src, split);
81 todo-=split;
82 buf->pwrite=0;
83 }
84 memcpy(buf->data + buf->pwrite, src+split, todo);
85 buf->pwrite=(buf->pwrite+todo)%buf->size;
86 return len;
87} 60}
88 61
89static ssize_t dvb_dmxdev_buffer_read(struct dmxdev_buffer *src, 62static ssize_t dvb_dmxdev_buffer_read(struct dvb_ringbuffer *src,
90 int non_blocking, char __user *buf, size_t count, loff_t *ppos) 63 int non_blocking, char __user *buf,
64 size_t count, loff_t *ppos)
91{ 65{
92 unsigned long todo=count; 66 size_t todo;
93 int split, avail, error; 67 ssize_t avail;
68 ssize_t ret = 0;
94 69
95 if (!src->data) 70 if (!src->data)
96 return 0; 71 return 0;
97 72
98 if ((error=src->error)) { 73 if (src->error) {
99 src->pwrite=src->pread; 74 ret = src->error;
100 src->error=0; 75 dvb_ringbuffer_flush(src);
101 return error; 76 return ret;
102 } 77 }
103 78
104 if (non_blocking && (src->pwrite==src->pread)) 79 for (todo = count; todo > 0; todo -= ret) {
105 return -EWOULDBLOCK; 80 if (non_blocking && dvb_ringbuffer_empty(src)) {
106 81 ret = -EWOULDBLOCK;
107 while (todo>0) { 82 break;
108 if (non_blocking && (src->pwrite==src->pread)) 83 }
109 return (count-todo) ? (count-todo) : -EWOULDBLOCK;
110 84
111 if (wait_event_interruptible(src->queue, 85 ret = wait_event_interruptible(src->queue,
112 (src->pread!=src->pwrite) || 86 !dvb_ringbuffer_empty(src) ||
113 (src->error))<0) 87 (src->error != 0));
114 return count-todo; 88 if (ret < 0)
89 break;
115 90
116 if ((error=src->error)) { 91 if (src->error) {
117 src->pwrite=src->pread; 92 ret = src->error;
118 src->error=0; 93 dvb_ringbuffer_flush(src);
119 return error; 94 break;
120 } 95 }
121 96
122 split=src->size; 97 avail = dvb_ringbuffer_avail(src);
123 avail=src->pwrite - src->pread; 98 if (avail > todo)
124 if (avail<0) { 99 avail = todo;
125 avail+=src->size; 100
126 split=src->size - src->pread; 101 ret = dvb_ringbuffer_read(src, buf, avail, 1);
127 } 102 if (ret < 0)
128 if (avail>todo) 103 break;
129 avail=todo; 104
130 if (split<avail) { 105 buf += ret;
131 if (copy_to_user(buf, src->data+src->pread, split))
132 return -EFAULT;
133 buf+=split;
134 src->pread=0;
135 todo-=split;
136 avail-=split;
137 }
138 if (avail) {
139 if (copy_to_user(buf, src->data+src->pread, avail))
140 return -EFAULT;
141 src->pread = (src->pread + avail) % src->size;
142 todo-=avail;
143 buf+=avail;
144 }
145 } 106 }
146 return count; 107
108 return (count - todo) ? (count - todo) : ret;
147} 109}
148 110
149static struct dmx_frontend * get_fe(struct dmx_demux *demux, int type) 111static struct dmx_frontend *get_fe(struct dmx_demux *demux, int type)
150{ 112{
151 struct list_head *head, *pos; 113 struct list_head *head, *pos;
152 114
153 head=demux->get_frontends(demux); 115 head = demux->get_frontends(demux);
154 if (!head) 116 if (!head)
155 return NULL; 117 return NULL;
156 list_for_each(pos, head) 118 list_for_each(pos, head)
157 if (DMX_FE_ENTRY(pos)->source==type) 119 if (DMX_FE_ENTRY(pos)->source == type)
158 return DMX_FE_ENTRY(pos); 120 return DMX_FE_ENTRY(pos);
159 121
160 return NULL; 122 return NULL;
161} 123}
162 124
163static inline void dvb_dmxdev_dvr_state_set(struct dmxdev_dvr *dmxdevdvr, int state)
164{
165 spin_lock_irq(&dmxdevdvr->dev->lock);
166 dmxdevdvr->state=state;
167 spin_unlock_irq(&dmxdevdvr->dev->lock);
168}
169
170static int dvb_dvr_open(struct inode *inode, struct file *file) 125static int dvb_dvr_open(struct inode *inode, struct file *file)
171{ 126{
172 struct dvb_device *dvbdev = file->private_data; 127 struct dvb_device *dvbdev = file->private_data;
173 struct dmxdev *dmxdev = dvbdev->priv; 128 struct dmxdev *dmxdev = dvbdev->priv;
174 struct dmx_frontend *front; 129 struct dmx_frontend *front;
175 130
176 dprintk ("function : %s\n", __FUNCTION__); 131 dprintk("function : %s\n", __FUNCTION__);
177 132
178 if (down_interruptible (&dmxdev->mutex)) 133 if (mutex_lock_interruptible(&dmxdev->mutex))
179 return -ERESTARTSYS; 134 return -ERESTARTSYS;
180 135
181 if ((file->f_flags&O_ACCMODE)==O_RDWR) { 136 if ((file->f_flags & O_ACCMODE) == O_RDWR) {
182 if (!(dmxdev->capabilities&DMXDEV_CAP_DUPLEX)) { 137 if (!(dmxdev->capabilities & DMXDEV_CAP_DUPLEX)) {
183 up(&dmxdev->mutex); 138 mutex_unlock(&dmxdev->mutex);
184 return -EOPNOTSUPP; 139 return -EOPNOTSUPP;
185 } 140 }
186 } 141 }
187 142
188 if ((file->f_flags&O_ACCMODE)==O_RDONLY) { 143 if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
189 dvb_dmxdev_buffer_init(&dmxdev->dvr_buffer); 144 void *mem = vmalloc(DVR_BUFFER_SIZE);
190 dmxdev->dvr_buffer.size=DVR_BUFFER_SIZE; 145 if (!mem) {
191 dmxdev->dvr_buffer.data=vmalloc(DVR_BUFFER_SIZE); 146 mutex_unlock(&dmxdev->mutex);
192 if (!dmxdev->dvr_buffer.data) { 147 return -ENOMEM;
193 up(&dmxdev->mutex); 148 }
194 return -ENOMEM; 149 dvb_ringbuffer_init(&dmxdev->dvr_buffer, mem, DVR_BUFFER_SIZE);
195 }
196 } 150 }
197 151
198 if ((file->f_flags&O_ACCMODE)==O_WRONLY) { 152 if ((file->f_flags & O_ACCMODE) == O_WRONLY) {
199 dmxdev->dvr_orig_fe=dmxdev->demux->frontend; 153 dmxdev->dvr_orig_fe = dmxdev->demux->frontend;
200 154
201 if (!dmxdev->demux->write) { 155 if (!dmxdev->demux->write) {
202 up(&dmxdev->mutex); 156 mutex_unlock(&dmxdev->mutex);
203 return -EOPNOTSUPP; 157 return -EOPNOTSUPP;
204 } 158 }
205 159
206 front=get_fe(dmxdev->demux, DMX_MEMORY_FE); 160 front = get_fe(dmxdev->demux, DMX_MEMORY_FE);
207 161
208 if (!front) { 162 if (!front) {
209 up(&dmxdev->mutex); 163 mutex_unlock(&dmxdev->mutex);
210 return -EINVAL; 164 return -EINVAL;
211 } 165 }
212 dmxdev->demux->disconnect_frontend(dmxdev->demux); 166 dmxdev->demux->disconnect_frontend(dmxdev->demux);
213 dmxdev->demux->connect_frontend(dmxdev->demux, front); 167 dmxdev->demux->connect_frontend(dmxdev->demux, front);
214 } 168 }
215 up(&dmxdev->mutex); 169 mutex_unlock(&dmxdev->mutex);
216 return 0; 170 return 0;
217} 171}
218 172
@@ -221,30 +175,30 @@ static int dvb_dvr_release(struct inode *inode, struct file *file)
221 struct dvb_device *dvbdev = file->private_data; 175 struct dvb_device *dvbdev = file->private_data;
222 struct dmxdev *dmxdev = dvbdev->priv; 176 struct dmxdev *dmxdev = dvbdev->priv;
223 177
224 if (down_interruptible (&dmxdev->mutex)) 178 if (mutex_lock_interruptible(&dmxdev->mutex))
225 return -ERESTARTSYS; 179 return -ERESTARTSYS;
226 180
227 if ((file->f_flags&O_ACCMODE)==O_WRONLY) { 181 if ((file->f_flags & O_ACCMODE) == O_WRONLY) {
228 dmxdev->demux->disconnect_frontend(dmxdev->demux); 182 dmxdev->demux->disconnect_frontend(dmxdev->demux);
229 dmxdev->demux->connect_frontend(dmxdev->demux, 183 dmxdev->demux->connect_frontend(dmxdev->demux,
230 dmxdev->dvr_orig_fe); 184 dmxdev->dvr_orig_fe);
231 } 185 }
232 if ((file->f_flags&O_ACCMODE)==O_RDONLY) { 186 if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
233 if (dmxdev->dvr_buffer.data) { 187 if (dmxdev->dvr_buffer.data) {
234 void *mem=dmxdev->dvr_buffer.data; 188 void *mem = dmxdev->dvr_buffer.data;
235 mb(); 189 mb();
236 spin_lock_irq(&dmxdev->lock); 190 spin_lock_irq(&dmxdev->lock);
237 dmxdev->dvr_buffer.data=NULL; 191 dmxdev->dvr_buffer.data = NULL;
238 spin_unlock_irq(&dmxdev->lock); 192 spin_unlock_irq(&dmxdev->lock);
239 vfree(mem); 193 vfree(mem);
240 } 194 }
241 } 195 }
242 up(&dmxdev->mutex); 196 mutex_unlock(&dmxdev->mutex);
243 return 0; 197 return 0;
244} 198}
245 199
246static ssize_t dvb_dvr_write(struct file *file, const char __user *buf, 200static ssize_t dvb_dvr_write(struct file *file, const char __user *buf,
247 size_t count, loff_t *ppos) 201 size_t count, loff_t *ppos)
248{ 202{
249 struct dvb_device *dvbdev = file->private_data; 203 struct dvb_device *dvbdev = file->private_data;
250 struct dmxdev *dmxdev = dvbdev->priv; 204 struct dmxdev *dmxdev = dvbdev->priv;
@@ -252,60 +206,62 @@ static ssize_t dvb_dvr_write(struct file *file, const char __user *buf,
252 206
253 if (!dmxdev->demux->write) 207 if (!dmxdev->demux->write)
254 return -EOPNOTSUPP; 208 return -EOPNOTSUPP;
255 if ((file->f_flags&O_ACCMODE)!=O_WRONLY) 209 if ((file->f_flags & O_ACCMODE) != O_WRONLY)
256 return -EINVAL; 210 return -EINVAL;
257 if (down_interruptible (&dmxdev->mutex)) 211 if (mutex_lock_interruptible(&dmxdev->mutex))
258 return -ERESTARTSYS; 212 return -ERESTARTSYS;
259 ret=dmxdev->demux->write(dmxdev->demux, buf, count); 213 ret = dmxdev->demux->write(dmxdev->demux, buf, count);
260 up(&dmxdev->mutex); 214 mutex_unlock(&dmxdev->mutex);
261 return ret; 215 return ret;
262} 216}
263 217
264static ssize_t dvb_dvr_read(struct file *file, char __user *buf, size_t count, 218static ssize_t dvb_dvr_read(struct file *file, char __user *buf, size_t count,
265 loff_t *ppos) 219 loff_t *ppos)
266{ 220{
267 struct dvb_device *dvbdev = file->private_data; 221 struct dvb_device *dvbdev = file->private_data;
268 struct dmxdev *dmxdev = dvbdev->priv; 222 struct dmxdev *dmxdev = dvbdev->priv;
269 int ret; 223 int ret;
270 224
271 //down(&dmxdev->mutex); 225 //mutex_lock(&dmxdev->mutex);
272 ret= dvb_dmxdev_buffer_read(&dmxdev->dvr_buffer, 226 ret = dvb_dmxdev_buffer_read(&dmxdev->dvr_buffer,
273 file->f_flags&O_NONBLOCK, 227 file->f_flags & O_NONBLOCK,
274 buf, count, ppos); 228 buf, count, ppos);
275 //up(&dmxdev->mutex); 229 //mutex_unlock(&dmxdev->mutex);
276 return ret; 230 return ret;
277} 231}
278 232
279static inline void dvb_dmxdev_filter_state_set(struct dmxdev_filter *dmxdevfilter, int state) 233static inline void dvb_dmxdev_filter_state_set(struct dmxdev_filter
234 *dmxdevfilter, int state)
280{ 235{
281 spin_lock_irq(&dmxdevfilter->dev->lock); 236 spin_lock_irq(&dmxdevfilter->dev->lock);
282 dmxdevfilter->state=state; 237 dmxdevfilter->state = state;
283 spin_unlock_irq(&dmxdevfilter->dev->lock); 238 spin_unlock_irq(&dmxdevfilter->dev->lock);
284} 239}
285 240
286static int dvb_dmxdev_set_buffer_size(struct dmxdev_filter *dmxdevfilter, unsigned long size) 241static int dvb_dmxdev_set_buffer_size(struct dmxdev_filter *dmxdevfilter,
242 unsigned long size)
287{ 243{
288 struct dmxdev_buffer *buf=&dmxdevfilter->buffer; 244 struct dvb_ringbuffer *buf = &dmxdevfilter->buffer;
289 void *mem; 245 void *mem;
290 246
291 if (buf->size==size) 247 if (buf->size == size)
292 return 0; 248 return 0;
293 if (dmxdevfilter->state>=DMXDEV_STATE_GO) 249 if (dmxdevfilter->state >= DMXDEV_STATE_GO)
294 return -EBUSY; 250 return -EBUSY;
295 spin_lock_irq(&dmxdevfilter->dev->lock); 251 spin_lock_irq(&dmxdevfilter->dev->lock);
296 mem=buf->data; 252 mem = buf->data;
297 buf->data=NULL; 253 buf->data = NULL;
298 buf->size=size; 254 buf->size = size;
299 buf->pwrite=buf->pread=0; 255 dvb_ringbuffer_flush(buf);
300 spin_unlock_irq(&dmxdevfilter->dev->lock); 256 spin_unlock_irq(&dmxdevfilter->dev->lock);
301 vfree(mem); 257 vfree(mem);
302 258
303 if (buf->size) { 259 if (buf->size) {
304 mem=vmalloc(dmxdevfilter->buffer.size); 260 mem = vmalloc(dmxdevfilter->buffer.size);
305 if (!mem) 261 if (!mem)
306 return -ENOMEM; 262 return -ENOMEM;
307 spin_lock_irq(&dmxdevfilter->dev->lock); 263 spin_lock_irq(&dmxdevfilter->dev->lock);
308 buf->data=mem; 264 buf->data = mem;
309 spin_unlock_irq(&dmxdevfilter->dev->lock); 265 spin_unlock_irq(&dmxdevfilter->dev->lock);
310 } 266 }
311 return 0; 267 return 0;
@@ -313,31 +269,33 @@ static int dvb_dmxdev_set_buffer_size(struct dmxdev_filter *dmxdevfilter, unsign
313 269
314static void dvb_dmxdev_filter_timeout(unsigned long data) 270static void dvb_dmxdev_filter_timeout(unsigned long data)
315{ 271{
316 struct dmxdev_filter *dmxdevfilter=(struct dmxdev_filter *)data; 272 struct dmxdev_filter *dmxdevfilter = (struct dmxdev_filter *)data;
317 273
318 dmxdevfilter->buffer.error=-ETIMEDOUT; 274 dmxdevfilter->buffer.error = -ETIMEDOUT;
319 spin_lock_irq(&dmxdevfilter->dev->lock); 275 spin_lock_irq(&dmxdevfilter->dev->lock);
320 dmxdevfilter->state=DMXDEV_STATE_TIMEDOUT; 276 dmxdevfilter->state = DMXDEV_STATE_TIMEDOUT;
321 spin_unlock_irq(&dmxdevfilter->dev->lock); 277 spin_unlock_irq(&dmxdevfilter->dev->lock);
322 wake_up(&dmxdevfilter->buffer.queue); 278 wake_up(&dmxdevfilter->buffer.queue);
323} 279}
324 280
325static void dvb_dmxdev_filter_timer(struct dmxdev_filter *dmxdevfilter) 281static void dvb_dmxdev_filter_timer(struct dmxdev_filter *dmxdevfilter)
326{ 282{
327 struct dmx_sct_filter_params *para=&dmxdevfilter->params.sec; 283 struct dmx_sct_filter_params *para = &dmxdevfilter->params.sec;
328 284
329 del_timer(&dmxdevfilter->timer); 285 del_timer(&dmxdevfilter->timer);
330 if (para->timeout) { 286 if (para->timeout) {
331 dmxdevfilter->timer.function=dvb_dmxdev_filter_timeout; 287 dmxdevfilter->timer.function = dvb_dmxdev_filter_timeout;
332 dmxdevfilter->timer.data=(unsigned long) dmxdevfilter; 288 dmxdevfilter->timer.data = (unsigned long)dmxdevfilter;
333 dmxdevfilter->timer.expires=jiffies+1+(HZ/2+HZ*para->timeout)/1000; 289 dmxdevfilter->timer.expires =
290 jiffies + 1 + (HZ / 2 + HZ * para->timeout) / 1000;
334 add_timer(&dmxdevfilter->timer); 291 add_timer(&dmxdevfilter->timer);
335 } 292 }
336} 293}
337 294
338static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len, 295static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len,
339 const u8 *buffer2, size_t buffer2_len, 296 const u8 *buffer2, size_t buffer2_len,
340 struct dmx_section_filter *filter, enum dmx_success success) 297 struct dmx_section_filter *filter,
298 enum dmx_success success)
341{ 299{
342 struct dmxdev_filter *dmxdevfilter = filter->priv; 300 struct dmxdev_filter *dmxdevfilter = filter->priv;
343 int ret; 301 int ret;
@@ -347,68 +305,68 @@ static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len,
347 return 0; 305 return 0;
348 } 306 }
349 spin_lock(&dmxdevfilter->dev->lock); 307 spin_lock(&dmxdevfilter->dev->lock);
350 if (dmxdevfilter->state!=DMXDEV_STATE_GO) { 308 if (dmxdevfilter->state != DMXDEV_STATE_GO) {
351 spin_unlock(&dmxdevfilter->dev->lock); 309 spin_unlock(&dmxdevfilter->dev->lock);
352 return 0; 310 return 0;
353 } 311 }
354 del_timer(&dmxdevfilter->timer); 312 del_timer(&dmxdevfilter->timer);
355 dprintk("dmxdev: section callback %02x %02x %02x %02x %02x %02x\n", 313 dprintk("dmxdev: section callback %02x %02x %02x %02x %02x %02x\n",
356 buffer1[0], buffer1[1], 314 buffer1[0], buffer1[1],
357 buffer1[2], buffer1[3], 315 buffer1[2], buffer1[3], buffer1[4], buffer1[5]);
358 buffer1[4], buffer1[5]); 316 ret = dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer1,
359 ret=dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer1, buffer1_len); 317 buffer1_len);
360 if (ret==buffer1_len) { 318 if (ret == buffer1_len) {
361 ret=dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer2, buffer2_len); 319 ret = dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer2,
320 buffer2_len);
362 } 321 }
363 if (ret<0) { 322 if (ret < 0) {
364 dmxdevfilter->buffer.pwrite=dmxdevfilter->buffer.pread; 323 dvb_ringbuffer_flush(&dmxdevfilter->buffer);
365 dmxdevfilter->buffer.error=-EOVERFLOW; 324 dmxdevfilter->buffer.error = ret;
366 } 325 }
367 if (dmxdevfilter->params.sec.flags&DMX_ONESHOT) 326 if (dmxdevfilter->params.sec.flags & DMX_ONESHOT)
368 dmxdevfilter->state=DMXDEV_STATE_DONE; 327 dmxdevfilter->state = DMXDEV_STATE_DONE;
369 spin_unlock(&dmxdevfilter->dev->lock); 328 spin_unlock(&dmxdevfilter->dev->lock);
370 wake_up(&dmxdevfilter->buffer.queue); 329 wake_up(&dmxdevfilter->buffer.queue);
371 return 0; 330 return 0;
372} 331}
373 332
374static int dvb_dmxdev_ts_callback(const u8 *buffer1, size_t buffer1_len, 333static int dvb_dmxdev_ts_callback(const u8 *buffer1, size_t buffer1_len,
375 const u8 *buffer2, size_t buffer2_len, 334 const u8 *buffer2, size_t buffer2_len,
376 struct dmx_ts_feed *feed, enum dmx_success success) 335 struct dmx_ts_feed *feed,
336 enum dmx_success success)
377{ 337{
378 struct dmxdev_filter *dmxdevfilter = feed->priv; 338 struct dmxdev_filter *dmxdevfilter = feed->priv;
379 struct dmxdev_buffer *buffer; 339 struct dvb_ringbuffer *buffer;
380 int ret; 340 int ret;
381 341
382 spin_lock(&dmxdevfilter->dev->lock); 342 spin_lock(&dmxdevfilter->dev->lock);
383 if (dmxdevfilter->params.pes.output==DMX_OUT_DECODER) { 343 if (dmxdevfilter->params.pes.output == DMX_OUT_DECODER) {
384 spin_unlock(&dmxdevfilter->dev->lock); 344 spin_unlock(&dmxdevfilter->dev->lock);
385 return 0; 345 return 0;
386 } 346 }
387 347
388 if (dmxdevfilter->params.pes.output==DMX_OUT_TAP) 348 if (dmxdevfilter->params.pes.output == DMX_OUT_TAP)
389 buffer=&dmxdevfilter->buffer; 349 buffer = &dmxdevfilter->buffer;
390 else 350 else
391 buffer=&dmxdevfilter->dev->dvr_buffer; 351 buffer = &dmxdevfilter->dev->dvr_buffer;
392 if (buffer->error) { 352 if (buffer->error) {
393 spin_unlock(&dmxdevfilter->dev->lock); 353 spin_unlock(&dmxdevfilter->dev->lock);
394 wake_up(&buffer->queue); 354 wake_up(&buffer->queue);
395 return 0; 355 return 0;
396 } 356 }
397 ret=dvb_dmxdev_buffer_write(buffer, buffer1, buffer1_len); 357 ret = dvb_dmxdev_buffer_write(buffer, buffer1, buffer1_len);
398 if (ret==buffer1_len) 358 if (ret == buffer1_len)
399 ret=dvb_dmxdev_buffer_write(buffer, buffer2, buffer2_len); 359 ret = dvb_dmxdev_buffer_write(buffer, buffer2, buffer2_len);
400 if (ret<0) { 360 if (ret < 0) {
401 buffer->pwrite=buffer->pread; 361 dvb_ringbuffer_flush(buffer);
402 buffer->error=-EOVERFLOW; 362 buffer->error = ret;
403 } 363 }
404 spin_unlock(&dmxdevfilter->dev->lock); 364 spin_unlock(&dmxdevfilter->dev->lock);
405 wake_up(&buffer->queue); 365 wake_up(&buffer->queue);
406 return 0; 366 return 0;
407} 367}
408 368
409
410/* stop feed but only mark the specified filter as stopped (state set) */ 369/* stop feed but only mark the specified filter as stopped (state set) */
411
412static int dvb_dmxdev_feed_stop(struct dmxdev_filter *dmxdevfilter) 370static int dvb_dmxdev_feed_stop(struct dmxdev_filter *dmxdevfilter)
413{ 371{
414 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET); 372 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET);
@@ -427,20 +385,16 @@ static int dvb_dmxdev_feed_stop(struct dmxdev_filter *dmxdevfilter)
427 return 0; 385 return 0;
428} 386}
429 387
430
431/* start feed associated with the specified filter */ 388/* start feed associated with the specified filter */
432
433static int dvb_dmxdev_feed_start(struct dmxdev_filter *filter) 389static int dvb_dmxdev_feed_start(struct dmxdev_filter *filter)
434{ 390{
435 dvb_dmxdev_filter_state_set (filter, DMXDEV_STATE_GO); 391 dvb_dmxdev_filter_state_set(filter, DMXDEV_STATE_GO);
436 392
437 switch (filter->type) { 393 switch (filter->type) {
438 case DMXDEV_TYPE_SEC: 394 case DMXDEV_TYPE_SEC:
439 return filter->feed.sec->start_filtering(filter->feed.sec); 395 return filter->feed.sec->start_filtering(filter->feed.sec);
440 break;
441 case DMXDEV_TYPE_PES: 396 case DMXDEV_TYPE_PES:
442 return filter->feed.ts->start_filtering(filter->feed.ts); 397 return filter->feed.ts->start_filtering(filter->feed.ts);
443 break;
444 default: 398 default:
445 return -EINVAL; 399 return -EINVAL;
446 } 400 }
@@ -448,32 +402,31 @@ static int dvb_dmxdev_feed_start(struct dmxdev_filter *filter)
448 return 0; 402 return 0;
449} 403}
450 404
451
452/* restart section feed if it has filters left associated with it, 405/* restart section feed if it has filters left associated with it,
453 otherwise release the feed */ 406 otherwise release the feed */
454
455static int dvb_dmxdev_feed_restart(struct dmxdev_filter *filter) 407static int dvb_dmxdev_feed_restart(struct dmxdev_filter *filter)
456{ 408{
457 int i; 409 int i;
458 struct dmxdev *dmxdev = filter->dev; 410 struct dmxdev *dmxdev = filter->dev;
459 u16 pid = filter->params.sec.pid; 411 u16 pid = filter->params.sec.pid;
460 412
461 for (i=0; i<dmxdev->filternum; i++) 413 for (i = 0; i < dmxdev->filternum; i++)
462 if (dmxdev->filter[i].state>=DMXDEV_STATE_GO && 414 if (dmxdev->filter[i].state >= DMXDEV_STATE_GO &&
463 dmxdev->filter[i].type==DMXDEV_TYPE_SEC && 415 dmxdev->filter[i].type == DMXDEV_TYPE_SEC &&
464 dmxdev->filter[i].pid==pid) { 416 dmxdev->filter[i].params.sec.pid == pid) {
465 dvb_dmxdev_feed_start(&dmxdev->filter[i]); 417 dvb_dmxdev_feed_start(&dmxdev->filter[i]);
466 return 0; 418 return 0;
467 } 419 }
468 420
469 filter->dev->demux->release_section_feed(dmxdev->demux, filter->feed.sec); 421 filter->dev->demux->release_section_feed(dmxdev->demux,
422 filter->feed.sec);
470 423
471 return 0; 424 return 0;
472} 425}
473 426
474static int dvb_dmxdev_filter_stop(struct dmxdev_filter *dmxdevfilter) 427static int dvb_dmxdev_filter_stop(struct dmxdev_filter *dmxdevfilter)
475{ 428{
476 if (dmxdevfilter->state<DMXDEV_STATE_GO) 429 if (dmxdevfilter->state < DMXDEV_STATE_GO)
477 return 0; 430 return 0;
478 431
479 switch (dmxdevfilter->type) { 432 switch (dmxdevfilter->type) {
@@ -483,36 +436,36 @@ static int dvb_dmxdev_filter_stop(struct dmxdev_filter *dmxdevfilter)
483 dvb_dmxdev_feed_stop(dmxdevfilter); 436 dvb_dmxdev_feed_stop(dmxdevfilter);
484 if (dmxdevfilter->filter.sec) 437 if (dmxdevfilter->filter.sec)
485 dmxdevfilter->feed.sec-> 438 dmxdevfilter->feed.sec->
486 release_filter(dmxdevfilter->feed.sec, 439 release_filter(dmxdevfilter->feed.sec,
487 dmxdevfilter->filter.sec); 440 dmxdevfilter->filter.sec);
488 dvb_dmxdev_feed_restart(dmxdevfilter); 441 dvb_dmxdev_feed_restart(dmxdevfilter);
489 dmxdevfilter->feed.sec=NULL; 442 dmxdevfilter->feed.sec = NULL;
490 break; 443 break;
491 case DMXDEV_TYPE_PES: 444 case DMXDEV_TYPE_PES:
492 if (!dmxdevfilter->feed.ts) 445 if (!dmxdevfilter->feed.ts)
493 break; 446 break;
494 dvb_dmxdev_feed_stop(dmxdevfilter); 447 dvb_dmxdev_feed_stop(dmxdevfilter);
495 dmxdevfilter->dev->demux-> 448 dmxdevfilter->dev->demux->
496 release_ts_feed(dmxdevfilter->dev->demux, 449 release_ts_feed(dmxdevfilter->dev->demux,
497 dmxdevfilter->feed.ts); 450 dmxdevfilter->feed.ts);
498 dmxdevfilter->feed.ts=NULL; 451 dmxdevfilter->feed.ts = NULL;
499 break; 452 break;
500 default: 453 default:
501 if (dmxdevfilter->state==DMXDEV_STATE_ALLOCATED) 454 if (dmxdevfilter->state == DMXDEV_STATE_ALLOCATED)
502 return 0; 455 return 0;
503 return -EINVAL; 456 return -EINVAL;
504 } 457 }
505 dmxdevfilter->buffer.pwrite=dmxdevfilter->buffer.pread=0; 458
459 dvb_ringbuffer_flush(&dmxdevfilter->buffer);
506 return 0; 460 return 0;
507} 461}
508 462
509static inline int dvb_dmxdev_filter_reset(struct dmxdev_filter *dmxdevfilter) 463static inline int dvb_dmxdev_filter_reset(struct dmxdev_filter *dmxdevfilter)
510{ 464{
511 if (dmxdevfilter->state<DMXDEV_STATE_SET) 465 if (dmxdevfilter->state < DMXDEV_STATE_SET)
512 return 0; 466 return 0;
513 467
514 dmxdevfilter->type=DMXDEV_TYPE_NONE; 468 dmxdevfilter->type = DMXDEV_TYPE_NONE;
515 dmxdevfilter->pid=0xffff;
516 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_ALLOCATED); 469 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_ALLOCATED);
517 return 0; 470 return 0;
518} 471}
@@ -529,32 +482,33 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
529 if (filter->state >= DMXDEV_STATE_GO) 482 if (filter->state >= DMXDEV_STATE_GO)
530 dvb_dmxdev_filter_stop(filter); 483 dvb_dmxdev_filter_stop(filter);
531 484
532 if (!(mem = filter->buffer.data)) { 485 if (!filter->buffer.data) {
533 mem = vmalloc(filter->buffer.size); 486 mem = vmalloc(filter->buffer.size);
487 if (!mem)
488 return -ENOMEM;
534 spin_lock_irq(&filter->dev->lock); 489 spin_lock_irq(&filter->dev->lock);
535 filter->buffer.data=mem; 490 filter->buffer.data = mem;
536 spin_unlock_irq(&filter->dev->lock); 491 spin_unlock_irq(&filter->dev->lock);
537 if (!filter->buffer.data)
538 return -ENOMEM;
539 } 492 }
540 493
541 filter->buffer.pwrite = filter->buffer.pread = 0; 494 dvb_ringbuffer_flush(&filter->buffer);
542 495
543 switch (filter->type) { 496 switch (filter->type) {
544 case DMXDEV_TYPE_SEC: 497 case DMXDEV_TYPE_SEC:
545 { 498 {
546 struct dmx_sct_filter_params *para=&filter->params.sec; 499 struct dmx_sct_filter_params *para = &filter->params.sec;
547 struct dmx_section_filter **secfilter=&filter->filter.sec; 500 struct dmx_section_filter **secfilter = &filter->filter.sec;
548 struct dmx_section_feed **secfeed=&filter->feed.sec; 501 struct dmx_section_feed **secfeed = &filter->feed.sec;
502
503 *secfilter = NULL;
504 *secfeed = NULL;
549 505
550 *secfilter=NULL;
551 *secfeed=NULL;
552 506
553 /* find active filter/feed with same PID */ 507 /* find active filter/feed with same PID */
554 for (i=0; i<dmxdev->filternum; i++) { 508 for (i = 0; i < dmxdev->filternum; i++) {
555 if (dmxdev->filter[i].state >= DMXDEV_STATE_GO && 509 if (dmxdev->filter[i].state >= DMXDEV_STATE_GO &&
556 dmxdev->filter[i].pid == para->pid && 510 dmxdev->filter[i].type == DMXDEV_TYPE_SEC &&
557 dmxdev->filter[i].type == DMXDEV_TYPE_SEC) { 511 dmxdev->filter[i].params.sec.pid == para->pid) {
558 *secfeed = dmxdev->filter[i].feed.sec; 512 *secfeed = dmxdev->filter[i].feed.sec;
559 break; 513 break;
560 } 514 }
@@ -562,21 +516,20 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
562 516
563 /* if no feed found, try to allocate new one */ 517 /* if no feed found, try to allocate new one */
564 if (!*secfeed) { 518 if (!*secfeed) {
565 ret=dmxdev->demux->allocate_section_feed(dmxdev->demux, 519 ret = dmxdev->demux->allocate_section_feed(dmxdev->demux,
566 secfeed, 520 secfeed,
567 dvb_dmxdev_section_callback); 521 dvb_dmxdev_section_callback);
568 if (ret<0) { 522 if (ret < 0) {
569 printk ("DVB (%s): could not alloc feed\n", 523 printk("DVB (%s): could not alloc feed\n",
570 __FUNCTION__); 524 __FUNCTION__);
571 return ret; 525 return ret;
572 } 526 }
573 527
574 ret=(*secfeed)->set(*secfeed, para->pid, 32768, 528 ret = (*secfeed)->set(*secfeed, para->pid, 32768,
575 (para->flags & DMX_CHECK_CRC) ? 1 : 0); 529 (para->flags & DMX_CHECK_CRC) ? 1 : 0);
576 530 if (ret < 0) {
577 if (ret<0) { 531 printk("DVB (%s): could not set feed\n",
578 printk ("DVB (%s): could not set feed\n", 532 __FUNCTION__);
579 __FUNCTION__);
580 dvb_dmxdev_feed_restart(filter); 533 dvb_dmxdev_feed_restart(filter);
581 return ret; 534 return ret;
582 } 535 }
@@ -584,41 +537,38 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
584 dvb_dmxdev_feed_stop(filter); 537 dvb_dmxdev_feed_stop(filter);
585 } 538 }
586 539
587 ret=(*secfeed)->allocate_filter(*secfeed, secfilter); 540 ret = (*secfeed)->allocate_filter(*secfeed, secfilter);
588
589 if (ret < 0) { 541 if (ret < 0) {
590 dvb_dmxdev_feed_restart(filter); 542 dvb_dmxdev_feed_restart(filter);
591 filter->feed.sec->start_filtering(*secfeed); 543 filter->feed.sec->start_filtering(*secfeed);
592 dprintk ("could not get filter\n"); 544 dprintk("could not get filter\n");
593 return ret; 545 return ret;
594 } 546 }
595 547
596 (*secfilter)->priv = filter; 548 (*secfilter)->priv = filter;
597 549
598 memcpy(&((*secfilter)->filter_value[3]), 550 memcpy(&((*secfilter)->filter_value[3]),
599 &(para->filter.filter[1]), DMX_FILTER_SIZE-1); 551 &(para->filter.filter[1]), DMX_FILTER_SIZE - 1);
600 memcpy(&(*secfilter)->filter_mask[3], 552 memcpy(&(*secfilter)->filter_mask[3],
601 &para->filter.mask[1], DMX_FILTER_SIZE-1); 553 &para->filter.mask[1], DMX_FILTER_SIZE - 1);
602 memcpy(&(*secfilter)->filter_mode[3], 554 memcpy(&(*secfilter)->filter_mode[3],
603 &para->filter.mode[1], DMX_FILTER_SIZE-1); 555 &para->filter.mode[1], DMX_FILTER_SIZE - 1);
604 556
605 (*secfilter)->filter_value[0]=para->filter.filter[0]; 557 (*secfilter)->filter_value[0] = para->filter.filter[0];
606 (*secfilter)->filter_mask[0]=para->filter.mask[0]; 558 (*secfilter)->filter_mask[0] = para->filter.mask[0];
607 (*secfilter)->filter_mode[0]=para->filter.mode[0]; 559 (*secfilter)->filter_mode[0] = para->filter.mode[0];
608 (*secfilter)->filter_mask[1]=0; 560 (*secfilter)->filter_mask[1] = 0;
609 (*secfilter)->filter_mask[2]=0; 561 (*secfilter)->filter_mask[2] = 0;
610 562
611 filter->todo = 0; 563 filter->todo = 0;
612 564
613 ret = filter->feed.sec->start_filtering (filter->feed.sec); 565 ret = filter->feed.sec->start_filtering(filter->feed.sec);
614
615 if (ret < 0) 566 if (ret < 0)
616 return ret; 567 return ret;
617 568
618 dvb_dmxdev_filter_timer(filter); 569 dvb_dmxdev_filter_timer(filter);
619 break; 570 break;
620 } 571 }
621
622 case DMXDEV_TYPE_PES: 572 case DMXDEV_TYPE_PES:
623 { 573 {
624 struct timespec timeout = { 0 }; 574 struct timespec timeout = { 0 };
@@ -630,41 +580,41 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
630 struct dmx_ts_feed **tsfeed = &filter->feed.ts; 580 struct dmx_ts_feed **tsfeed = &filter->feed.ts;
631 581
632 filter->feed.ts = NULL; 582 filter->feed.ts = NULL;
633 otype=para->output; 583 otype = para->output;
634 584
635 ts_pes=(enum dmx_ts_pes) para->pes_type; 585 ts_pes = (enum dmx_ts_pes)para->pes_type;
636 586
637 if (ts_pes<DMX_PES_OTHER) 587 if (ts_pes < DMX_PES_OTHER)
638 ts_type=TS_DECODER; 588 ts_type = TS_DECODER;
639 else 589 else
640 ts_type=0; 590 ts_type = 0;
641 591
642 if (otype == DMX_OUT_TS_TAP) 592 if (otype == DMX_OUT_TS_TAP)
643 ts_type |= TS_PACKET; 593 ts_type |= TS_PACKET;
644 594
645 if (otype == DMX_OUT_TAP) 595 if (otype == DMX_OUT_TAP)
646 ts_type |= TS_PAYLOAD_ONLY|TS_PACKET; 596 ts_type |= TS_PAYLOAD_ONLY | TS_PACKET;
647 597
648 ret=dmxdev->demux->allocate_ts_feed(dmxdev->demux, 598 ret = dmxdev->demux->allocate_ts_feed(dmxdev->demux,
649 tsfeed, 599 tsfeed,
650 dvb_dmxdev_ts_callback); 600 dvb_dmxdev_ts_callback);
651 if (ret<0) 601 if (ret < 0)
652 return ret; 602 return ret;
653 603
654 (*tsfeed)->priv = (void *) filter; 604 (*tsfeed)->priv = filter;
655 605
656 ret = (*tsfeed)->set(*tsfeed, para->pid, ts_type, ts_pes, 606 ret = (*tsfeed)->set(*tsfeed, para->pid, ts_type, ts_pes,
657 32768, timeout); 607 32768, timeout);
658
659 if (ret < 0) { 608 if (ret < 0) {
660 dmxdev->demux->release_ts_feed(dmxdev->demux, *tsfeed); 609 dmxdev->demux->release_ts_feed(dmxdev->demux,
610 *tsfeed);
661 return ret; 611 return ret;
662 } 612 }
663 613
664 ret = filter->feed.ts->start_filtering(filter->feed.ts); 614 ret = filter->feed.ts->start_filtering(filter->feed.ts);
665
666 if (ret < 0) { 615 if (ret < 0) {
667 dmxdev->demux->release_ts_feed(dmxdev->demux, *tsfeed); 616 dmxdev->demux->release_ts_feed(dmxdev->demux,
617 *tsfeed);
668 return ret; 618 return ret;
669 } 619 }
670 620
@@ -688,41 +638,40 @@ static int dvb_demux_open(struct inode *inode, struct file *file)
688 if (!dmxdev->filter) 638 if (!dmxdev->filter)
689 return -EINVAL; 639 return -EINVAL;
690 640
691 if (down_interruptible(&dmxdev->mutex)) 641 if (mutex_lock_interruptible(&dmxdev->mutex))
692 return -ERESTARTSYS; 642 return -ERESTARTSYS;
693 643
694 for (i=0; i<dmxdev->filternum; i++) 644 for (i = 0; i < dmxdev->filternum; i++)
695 if (dmxdev->filter[i].state==DMXDEV_STATE_FREE) 645 if (dmxdev->filter[i].state == DMXDEV_STATE_FREE)
696 break; 646 break;
697 647
698 if (i==dmxdev->filternum) { 648 if (i == dmxdev->filternum) {
699 up(&dmxdev->mutex); 649 mutex_unlock(&dmxdev->mutex);
700 return -EMFILE; 650 return -EMFILE;
701 } 651 }
702 652
703 dmxdevfilter=&dmxdev->filter[i]; 653 dmxdevfilter = &dmxdev->filter[i];
704 sema_init(&dmxdevfilter->mutex, 1); 654 mutex_init(&dmxdevfilter->mutex);
705 dmxdevfilter->dvbdev=dmxdev->dvbdev; 655 file->private_data = dmxdevfilter;
706 file->private_data=dmxdevfilter;
707 656
708 dvb_dmxdev_buffer_init(&dmxdevfilter->buffer); 657 dvb_ringbuffer_init(&dmxdevfilter->buffer, NULL, 8192);
709 dmxdevfilter->type=DMXDEV_TYPE_NONE; 658 dmxdevfilter->type = DMXDEV_TYPE_NONE;
710 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_ALLOCATED); 659 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_ALLOCATED);
711 dmxdevfilter->feed.ts=NULL; 660 dmxdevfilter->feed.ts = NULL;
712 init_timer(&dmxdevfilter->timer); 661 init_timer(&dmxdevfilter->timer);
713 662
714 up(&dmxdev->mutex); 663 mutex_unlock(&dmxdev->mutex);
715 return 0; 664 return 0;
716} 665}
717 666
718 667static int dvb_dmxdev_filter_free(struct dmxdev *dmxdev,
719static int dvb_dmxdev_filter_free(struct dmxdev *dmxdev, struct dmxdev_filter *dmxdevfilter) 668 struct dmxdev_filter *dmxdevfilter)
720{ 669{
721 if (down_interruptible(&dmxdev->mutex)) 670 if (mutex_lock_interruptible(&dmxdev->mutex))
722 return -ERESTARTSYS; 671 return -ERESTARTSYS;
723 672
724 if (down_interruptible(&dmxdevfilter->mutex)) { 673 if (mutex_lock_interruptible(&dmxdevfilter->mutex)) {
725 up(&dmxdev->mutex); 674 mutex_unlock(&dmxdev->mutex);
726 return -ERESTARTSYS; 675 return -ERESTARTSYS;
727 } 676 }
728 677
@@ -730,18 +679,18 @@ static int dvb_dmxdev_filter_free(struct dmxdev *dmxdev, struct dmxdev_filter *d
730 dvb_dmxdev_filter_reset(dmxdevfilter); 679 dvb_dmxdev_filter_reset(dmxdevfilter);
731 680
732 if (dmxdevfilter->buffer.data) { 681 if (dmxdevfilter->buffer.data) {
733 void *mem=dmxdevfilter->buffer.data; 682 void *mem = dmxdevfilter->buffer.data;
734 683
735 spin_lock_irq(&dmxdev->lock); 684 spin_lock_irq(&dmxdev->lock);
736 dmxdevfilter->buffer.data=NULL; 685 dmxdevfilter->buffer.data = NULL;
737 spin_unlock_irq(&dmxdev->lock); 686 spin_unlock_irq(&dmxdev->lock);
738 vfree(mem); 687 vfree(mem);
739 } 688 }
740 689
741 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_FREE); 690 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_FREE);
742 wake_up(&dmxdevfilter->buffer.queue); 691 wake_up(&dmxdevfilter->buffer.queue);
743 up(&dmxdevfilter->mutex); 692 mutex_unlock(&dmxdevfilter->mutex);
744 up(&dmxdev->mutex); 693 mutex_unlock(&dmxdev->mutex);
745 return 0; 694 return 0;
746} 695}
747 696
@@ -749,173 +698,171 @@ static inline void invert_mode(dmx_filter_t *filter)
749{ 698{
750 int i; 699 int i;
751 700
752 for (i=0; i<DMX_FILTER_SIZE; i++) 701 for (i = 0; i < DMX_FILTER_SIZE; i++)
753 filter->mode[i]^=0xff; 702 filter->mode[i] ^= 0xff;
754} 703}
755 704
756
757static int dvb_dmxdev_filter_set(struct dmxdev *dmxdev, 705static int dvb_dmxdev_filter_set(struct dmxdev *dmxdev,
758 struct dmxdev_filter *dmxdevfilter, 706 struct dmxdev_filter *dmxdevfilter,
759 struct dmx_sct_filter_params *params) 707 struct dmx_sct_filter_params *params)
760{ 708{
761 dprintk ("function : %s\n", __FUNCTION__); 709 dprintk("function : %s\n", __FUNCTION__);
762 710
763 dvb_dmxdev_filter_stop(dmxdevfilter); 711 dvb_dmxdev_filter_stop(dmxdevfilter);
764 712
765 dmxdevfilter->type=DMXDEV_TYPE_SEC; 713 dmxdevfilter->type = DMXDEV_TYPE_SEC;
766 dmxdevfilter->pid=params->pid;
767 memcpy(&dmxdevfilter->params.sec, 714 memcpy(&dmxdevfilter->params.sec,
768 params, sizeof(struct dmx_sct_filter_params)); 715 params, sizeof(struct dmx_sct_filter_params));
769 invert_mode(&dmxdevfilter->params.sec.filter); 716 invert_mode(&dmxdevfilter->params.sec.filter);
770 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET); 717 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET);
771 718
772 if (params->flags&DMX_IMMEDIATE_START) 719 if (params->flags & DMX_IMMEDIATE_START)
773 return dvb_dmxdev_filter_start(dmxdevfilter); 720 return dvb_dmxdev_filter_start(dmxdevfilter);
774 721
775 return 0; 722 return 0;
776} 723}
777 724
778static int dvb_dmxdev_pes_filter_set(struct dmxdev *dmxdev, 725static int dvb_dmxdev_pes_filter_set(struct dmxdev *dmxdev,
779 struct dmxdev_filter *dmxdevfilter, 726 struct dmxdev_filter *dmxdevfilter,
780 struct dmx_pes_filter_params *params) 727 struct dmx_pes_filter_params *params)
781{ 728{
782 dvb_dmxdev_filter_stop(dmxdevfilter); 729 dvb_dmxdev_filter_stop(dmxdevfilter);
783 730
784 if (params->pes_type>DMX_PES_OTHER || params->pes_type<0) 731 if (params->pes_type > DMX_PES_OTHER || params->pes_type < 0)
785 return -EINVAL; 732 return -EINVAL;
786 733
787 dmxdevfilter->type=DMXDEV_TYPE_PES; 734 dmxdevfilter->type = DMXDEV_TYPE_PES;
788 dmxdevfilter->pid=params->pid; 735 memcpy(&dmxdevfilter->params, params,
789 memcpy(&dmxdevfilter->params, params, sizeof(struct dmx_pes_filter_params)); 736 sizeof(struct dmx_pes_filter_params));
790 737
791 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET); 738 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET);
792 739
793 if (params->flags&DMX_IMMEDIATE_START) 740 if (params->flags & DMX_IMMEDIATE_START)
794 return dvb_dmxdev_filter_start(dmxdevfilter); 741 return dvb_dmxdev_filter_start(dmxdevfilter);
795 742
796 return 0; 743 return 0;
797} 744}
798 745
799static ssize_t dvb_dmxdev_read_sec(struct dmxdev_filter *dfil, 746static ssize_t dvb_dmxdev_read_sec(struct dmxdev_filter *dfil,
800 struct file *file, char __user *buf, size_t count, loff_t *ppos) 747 struct file *file, char __user *buf,
748 size_t count, loff_t *ppos)
801{ 749{
802 int result, hcount; 750 int result, hcount;
803 int done=0; 751 int done = 0;
804 752
805 if (dfil->todo<=0) { 753 if (dfil->todo <= 0) {
806 hcount=3+dfil->todo; 754 hcount = 3 + dfil->todo;
807 if (hcount>count) 755 if (hcount > count)
808 hcount=count; 756 hcount = count;
809 result=dvb_dmxdev_buffer_read(&dfil->buffer, file->f_flags&O_NONBLOCK, 757 result = dvb_dmxdev_buffer_read(&dfil->buffer,
810 buf, hcount, ppos); 758 file->f_flags & O_NONBLOCK,
811 if (result<0) { 759 buf, hcount, ppos);
812 dfil->todo=0; 760 if (result < 0) {
761 dfil->todo = 0;
813 return result; 762 return result;
814 } 763 }
815 if (copy_from_user(dfil->secheader-dfil->todo, buf, result)) 764 if (copy_from_user(dfil->secheader - dfil->todo, buf, result))
816 return -EFAULT; 765 return -EFAULT;
817 buf+=result; 766 buf += result;
818 done=result; 767 done = result;
819 count-=result; 768 count -= result;
820 dfil->todo-=result; 769 dfil->todo -= result;
821 if (dfil->todo>-3) 770 if (dfil->todo > -3)
822 return done; 771 return done;
823 dfil->todo=((dfil->secheader[1]<<8)|dfil->secheader[2])&0xfff; 772 dfil->todo = ((dfil->secheader[1] << 8) | dfil->secheader[2]) & 0xfff;
824 if (!count) 773 if (!count)
825 return done; 774 return done;
826 } 775 }
827 if (count>dfil->todo) 776 if (count > dfil->todo)
828 count=dfil->todo; 777 count = dfil->todo;
829 result=dvb_dmxdev_buffer_read(&dfil->buffer, file->f_flags&O_NONBLOCK, 778 result = dvb_dmxdev_buffer_read(&dfil->buffer,
830 buf, count, ppos); 779 file->f_flags & O_NONBLOCK,
831 if (result<0) 780 buf, count, ppos);
781 if (result < 0)
832 return result; 782 return result;
833 dfil->todo-=result; 783 dfil->todo -= result;
834 return (result+done); 784 return (result + done);
835} 785}
836 786
837
838static ssize_t 787static ssize_t
839dvb_demux_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 788dvb_demux_read(struct file *file, char __user *buf, size_t count,
789 loff_t *ppos)
840{ 790{
841 struct dmxdev_filter *dmxdevfilter= file->private_data; 791 struct dmxdev_filter *dmxdevfilter = file->private_data;
842 int ret=0; 792 int ret;
843 793
844 if (down_interruptible(&dmxdevfilter->mutex)) 794 if (mutex_lock_interruptible(&dmxdevfilter->mutex))
845 return -ERESTARTSYS; 795 return -ERESTARTSYS;
846 796
847 if (dmxdevfilter->type==DMXDEV_TYPE_SEC) 797 if (dmxdevfilter->type == DMXDEV_TYPE_SEC)
848 ret=dvb_dmxdev_read_sec(dmxdevfilter, file, buf, count, ppos); 798 ret = dvb_dmxdev_read_sec(dmxdevfilter, file, buf, count, ppos);
849 else 799 else
850 ret=dvb_dmxdev_buffer_read(&dmxdevfilter->buffer, 800 ret = dvb_dmxdev_buffer_read(&dmxdevfilter->buffer,
851 file->f_flags&O_NONBLOCK, 801 file->f_flags & O_NONBLOCK,
852 buf, count, ppos); 802 buf, count, ppos);
853 803
854 up(&dmxdevfilter->mutex); 804 mutex_unlock(&dmxdevfilter->mutex);
855 return ret; 805 return ret;
856} 806}
857 807
858
859static int dvb_demux_do_ioctl(struct inode *inode, struct file *file, 808static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
860 unsigned int cmd, void *parg) 809 unsigned int cmd, void *parg)
861{ 810{
862 struct dmxdev_filter *dmxdevfilter = file->private_data; 811 struct dmxdev_filter *dmxdevfilter = file->private_data;
863 struct dmxdev *dmxdev=dmxdevfilter->dev; 812 struct dmxdev *dmxdev = dmxdevfilter->dev;
864 unsigned long arg=(unsigned long) parg; 813 unsigned long arg = (unsigned long)parg;
865 int ret=0; 814 int ret = 0;
866 815
867 if (down_interruptible (&dmxdev->mutex)) 816 if (mutex_lock_interruptible(&dmxdev->mutex))
868 return -ERESTARTSYS; 817 return -ERESTARTSYS;
869 818
870 switch (cmd) { 819 switch (cmd) {
871 case DMX_START: 820 case DMX_START:
872 if (down_interruptible(&dmxdevfilter->mutex)) { 821 if (mutex_lock_interruptible(&dmxdevfilter->mutex)) {
873 up(&dmxdev->mutex); 822 mutex_unlock(&dmxdev->mutex);
874 return -ERESTARTSYS; 823 return -ERESTARTSYS;
875 } 824 }
876 if (dmxdevfilter->state<DMXDEV_STATE_SET) 825 if (dmxdevfilter->state < DMXDEV_STATE_SET)
877 ret = -EINVAL; 826 ret = -EINVAL;
878 else 827 else
879 ret = dvb_dmxdev_filter_start(dmxdevfilter); 828 ret = dvb_dmxdev_filter_start(dmxdevfilter);
880 up(&dmxdevfilter->mutex); 829 mutex_unlock(&dmxdevfilter->mutex);
881 break; 830 break;
882 831
883 case DMX_STOP: 832 case DMX_STOP:
884 if (down_interruptible(&dmxdevfilter->mutex)) { 833 if (mutex_lock_interruptible(&dmxdevfilter->mutex)) {
885 up(&dmxdev->mutex); 834 mutex_unlock(&dmxdev->mutex);
886 return -ERESTARTSYS; 835 return -ERESTARTSYS;
887 } 836 }
888 ret=dvb_dmxdev_filter_stop(dmxdevfilter); 837 ret = dvb_dmxdev_filter_stop(dmxdevfilter);
889 up(&dmxdevfilter->mutex); 838 mutex_unlock(&dmxdevfilter->mutex);
890 break; 839 break;
891 840
892 case DMX_SET_FILTER: 841 case DMX_SET_FILTER:
893 if (down_interruptible(&dmxdevfilter->mutex)) { 842 if (mutex_lock_interruptible(&dmxdevfilter->mutex)) {
894 up(&dmxdev->mutex); 843 mutex_unlock(&dmxdev->mutex);
895 return -ERESTARTSYS; 844 return -ERESTARTSYS;
896 } 845 }
897 ret = dvb_dmxdev_filter_set(dmxdev, dmxdevfilter, 846 ret = dvb_dmxdev_filter_set(dmxdev, dmxdevfilter, parg);
898 (struct dmx_sct_filter_params *)parg); 847 mutex_unlock(&dmxdevfilter->mutex);
899 up(&dmxdevfilter->mutex);
900 break; 848 break;
901 849
902 case DMX_SET_PES_FILTER: 850 case DMX_SET_PES_FILTER:
903 if (down_interruptible(&dmxdevfilter->mutex)) { 851 if (mutex_lock_interruptible(&dmxdevfilter->mutex)) {
904 up(&dmxdev->mutex); 852 mutex_unlock(&dmxdev->mutex);
905 return -ERESTARTSYS; 853 return -ERESTARTSYS;
906 } 854 }
907 ret=dvb_dmxdev_pes_filter_set(dmxdev, dmxdevfilter, 855 ret = dvb_dmxdev_pes_filter_set(dmxdev, dmxdevfilter, parg);
908 (struct dmx_pes_filter_params *)parg); 856 mutex_unlock(&dmxdevfilter->mutex);
909 up(&dmxdevfilter->mutex);
910 break; 857 break;
911 858
912 case DMX_SET_BUFFER_SIZE: 859 case DMX_SET_BUFFER_SIZE:
913 if (down_interruptible(&dmxdevfilter->mutex)) { 860 if (mutex_lock_interruptible(&dmxdevfilter->mutex)) {
914 up(&dmxdev->mutex); 861 mutex_unlock(&dmxdev->mutex);
915 return -ERESTARTSYS; 862 return -ERESTARTSYS;
916 } 863 }
917 ret=dvb_dmxdev_set_buffer_size(dmxdevfilter, arg); 864 ret = dvb_dmxdev_set_buffer_size(dmxdevfilter, arg);
918 up(&dmxdevfilter->mutex); 865 mutex_unlock(&dmxdevfilter->mutex);
919 break; 866 break;
920 867
921 case DMX_GET_EVENT: 868 case DMX_GET_EVENT:
@@ -923,10 +870,10 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
923 870
924 case DMX_GET_PES_PIDS: 871 case DMX_GET_PES_PIDS:
925 if (!dmxdev->demux->get_pes_pids) { 872 if (!dmxdev->demux->get_pes_pids) {
926 ret=-EINVAL; 873 ret = -EINVAL;
927 break; 874 break;
928 } 875 }
929 dmxdev->demux->get_pes_pids(dmxdev->demux, (u16 *)parg); 876 dmxdev->demux->get_pes_pids(dmxdev->demux, parg);
930 break; 877 break;
931 878
932 case DMX_GET_CAPS: 879 case DMX_GET_CAPS:
@@ -947,19 +894,20 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
947 894
948 case DMX_GET_STC: 895 case DMX_GET_STC:
949 if (!dmxdev->demux->get_stc) { 896 if (!dmxdev->demux->get_stc) {
950 ret=-EINVAL; 897 ret = -EINVAL;
951 break; 898 break;
952 } 899 }
953 ret = dmxdev->demux->get_stc(dmxdev->demux, 900 ret = dmxdev->demux->get_stc(dmxdev->demux,
954 ((struct dmx_stc *)parg)->num, 901 ((struct dmx_stc *)parg)->num,
955 &((struct dmx_stc *)parg)->stc, 902 &((struct dmx_stc *)parg)->stc,
956 &((struct dmx_stc *)parg)->base); 903 &((struct dmx_stc *)parg)->base);
957 break; 904 break;
958 905
959 default: 906 default:
960 ret=-EINVAL; 907 ret = -EINVAL;
908 break;
961 } 909 }
962 up(&dmxdev->mutex); 910 mutex_unlock(&dmxdev->mutex);
963 return ret; 911 return ret;
964} 912}
965 913
@@ -969,8 +917,7 @@ static int dvb_demux_ioctl(struct inode *inode, struct file *file,
969 return dvb_usercopy(inode, file, cmd, arg, dvb_demux_do_ioctl); 917 return dvb_usercopy(inode, file, cmd, arg, dvb_demux_do_ioctl);
970} 918}
971 919
972 920static unsigned int dvb_demux_poll(struct file *file, poll_table *wait)
973static unsigned int dvb_demux_poll (struct file *file, poll_table *wait)
974{ 921{
975 struct dmxdev_filter *dmxdevfilter = file->private_data; 922 struct dmxdev_filter *dmxdevfilter = file->private_data;
976 unsigned int mask = 0; 923 unsigned int mask = 0;
@@ -988,13 +935,12 @@ static unsigned int dvb_demux_poll (struct file *file, poll_table *wait)
988 if (dmxdevfilter->buffer.error) 935 if (dmxdevfilter->buffer.error)
989 mask |= (POLLIN | POLLRDNORM | POLLPRI | POLLERR); 936 mask |= (POLLIN | POLLRDNORM | POLLPRI | POLLERR);
990 937
991 if (dmxdevfilter->buffer.pread != dmxdevfilter->buffer.pwrite) 938 if (!dvb_ringbuffer_empty(&dmxdevfilter->buffer))
992 mask |= (POLLIN | POLLRDNORM | POLLPRI); 939 mask |= (POLLIN | POLLRDNORM | POLLPRI);
993 940
994 return mask; 941 return mask;
995} 942}
996 943
997
998static int dvb_demux_release(struct inode *inode, struct file *file) 944static int dvb_demux_release(struct inode *inode, struct file *file)
999{ 945{
1000 struct dmxdev_filter *dmxdevfilter = file->private_data; 946 struct dmxdev_filter *dmxdevfilter = file->private_data;
@@ -1003,72 +949,67 @@ static int dvb_demux_release(struct inode *inode, struct file *file)
1003 return dvb_dmxdev_filter_free(dmxdev, dmxdevfilter); 949 return dvb_dmxdev_filter_free(dmxdev, dmxdevfilter);
1004} 950}
1005 951
1006
1007static struct file_operations dvb_demux_fops = { 952static struct file_operations dvb_demux_fops = {
1008 .owner = THIS_MODULE, 953 .owner = THIS_MODULE,
1009 .read = dvb_demux_read, 954 .read = dvb_demux_read,
1010 .ioctl = dvb_demux_ioctl, 955 .ioctl = dvb_demux_ioctl,
1011 .open = dvb_demux_open, 956 .open = dvb_demux_open,
1012 .release = dvb_demux_release, 957 .release = dvb_demux_release,
1013 .poll = dvb_demux_poll, 958 .poll = dvb_demux_poll,
1014}; 959};
1015 960
1016
1017static struct dvb_device dvbdev_demux = { 961static struct dvb_device dvbdev_demux = {
1018 .priv = NULL, 962 .priv = NULL,
1019 .users = 1, 963 .users = 1,
1020 .writers = 1, 964 .writers = 1,
1021 .fops = &dvb_demux_fops 965 .fops = &dvb_demux_fops
1022}; 966};
1023 967
1024
1025static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file, 968static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file,
1026 unsigned int cmd, void *parg) 969 unsigned int cmd, void *parg)
1027{ 970{
1028 struct dvb_device *dvbdev = file->private_data; 971 struct dvb_device *dvbdev = file->private_data;
1029 struct dmxdev *dmxdev = dvbdev->priv; 972 struct dmxdev *dmxdev = dvbdev->priv;
973 int ret;
1030 974
1031 int ret=0; 975 if (mutex_lock_interruptible(&dmxdev->mutex))
1032
1033 if (down_interruptible (&dmxdev->mutex))
1034 return -ERESTARTSYS; 976 return -ERESTARTSYS;
1035 977
1036 switch (cmd) { 978 switch (cmd) {
1037 case DMX_SET_BUFFER_SIZE: 979 case DMX_SET_BUFFER_SIZE:
1038 // FIXME: implement 980 // FIXME: implement
1039 ret=0; 981 ret = 0;
1040 break; 982 break;
1041 983
1042 default: 984 default:
1043 ret=-EINVAL; 985 ret = -EINVAL;
986 break;
1044 } 987 }
1045 up(&dmxdev->mutex); 988 mutex_unlock(&dmxdev->mutex);
1046 return ret; 989 return ret;
1047} 990}
1048 991
1049
1050static int dvb_dvr_ioctl(struct inode *inode, struct file *file, 992static int dvb_dvr_ioctl(struct inode *inode, struct file *file,
1051 unsigned int cmd, unsigned long arg) 993 unsigned int cmd, unsigned long arg)
1052{ 994{
1053 return dvb_usercopy(inode, file, cmd, arg, dvb_dvr_do_ioctl); 995 return dvb_usercopy(inode, file, cmd, arg, dvb_dvr_do_ioctl);
1054} 996}
1055 997
1056 998static unsigned int dvb_dvr_poll(struct file *file, poll_table *wait)
1057static unsigned int dvb_dvr_poll (struct file *file, poll_table *wait)
1058{ 999{
1059 struct dvb_device *dvbdev = file->private_data; 1000 struct dvb_device *dvbdev = file->private_data;
1060 struct dmxdev *dmxdev = dvbdev->priv; 1001 struct dmxdev *dmxdev = dvbdev->priv;
1061 unsigned int mask = 0; 1002 unsigned int mask = 0;
1062 1003
1063 dprintk ("function : %s\n", __FUNCTION__); 1004 dprintk("function : %s\n", __FUNCTION__);
1064 1005
1065 poll_wait(file, &dmxdev->dvr_buffer.queue, wait); 1006 poll_wait(file, &dmxdev->dvr_buffer.queue, wait);
1066 1007
1067 if ((file->f_flags&O_ACCMODE) == O_RDONLY) { 1008 if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
1068 if (dmxdev->dvr_buffer.error) 1009 if (dmxdev->dvr_buffer.error)
1069 mask |= (POLLIN | POLLRDNORM | POLLPRI | POLLERR); 1010 mask |= (POLLIN | POLLRDNORM | POLLPRI | POLLERR);
1070 1011
1071 if (dmxdev->dvr_buffer.pread!=dmxdev->dvr_buffer.pwrite) 1012 if (!dvb_ringbuffer_empty(&dmxdev->dvr_buffer))
1072 mask |= (POLLIN | POLLRDNORM | POLLPRI); 1013 mask |= (POLLIN | POLLRDNORM | POLLPRI);
1073 } else 1014 } else
1074 mask |= (POLLOUT | POLLWRNORM | POLLPRI); 1015 mask |= (POLLOUT | POLLWRNORM | POLLPRI);
@@ -1076,73 +1017,63 @@ static unsigned int dvb_dvr_poll (struct file *file, poll_table *wait)
1076 return mask; 1017 return mask;
1077} 1018}
1078 1019
1079
1080static struct file_operations dvb_dvr_fops = { 1020static struct file_operations dvb_dvr_fops = {
1081 .owner = THIS_MODULE, 1021 .owner = THIS_MODULE,
1082 .read = dvb_dvr_read, 1022 .read = dvb_dvr_read,
1083 .write = dvb_dvr_write, 1023 .write = dvb_dvr_write,
1084 .ioctl = dvb_dvr_ioctl, 1024 .ioctl = dvb_dvr_ioctl,
1085 .open = dvb_dvr_open, 1025 .open = dvb_dvr_open,
1086 .release = dvb_dvr_release, 1026 .release = dvb_dvr_release,
1087 .poll = dvb_dvr_poll, 1027 .poll = dvb_dvr_poll,
1088}; 1028};
1089 1029
1090static struct dvb_device dvbdev_dvr = { 1030static struct dvb_device dvbdev_dvr = {
1091 .priv = NULL, 1031 .priv = NULL,
1092 .users = 1, 1032 .users = 1,
1093 .writers = 1, 1033 .writers = 1,
1094 .fops = &dvb_dvr_fops 1034 .fops = &dvb_dvr_fops
1095}; 1035};
1096 1036
1097int 1037int dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *dvb_adapter)
1098dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *dvb_adapter)
1099{ 1038{
1100 int i; 1039 int i;
1101 1040
1102 if (dmxdev->demux->open(dmxdev->demux) < 0) 1041 if (dmxdev->demux->open(dmxdev->demux) < 0)
1103 return -EUSERS; 1042 return -EUSERS;
1104 1043
1105 dmxdev->filter = vmalloc(dmxdev->filternum*sizeof(struct dmxdev_filter)); 1044 dmxdev->filter = vmalloc(dmxdev->filternum * sizeof(struct dmxdev_filter));
1106 if (!dmxdev->filter) 1045 if (!dmxdev->filter)
1107 return -ENOMEM; 1046 return -ENOMEM;
1108 1047
1109 dmxdev->dvr = vmalloc(dmxdev->filternum*sizeof(struct dmxdev_dvr)); 1048 mutex_init(&dmxdev->mutex);
1110 if (!dmxdev->dvr) {
1111 vfree(dmxdev->filter);
1112 dmxdev->filter = NULL;
1113 return -ENOMEM;
1114 }
1115
1116 sema_init(&dmxdev->mutex, 1);
1117 spin_lock_init(&dmxdev->lock); 1049 spin_lock_init(&dmxdev->lock);
1118 for (i=0; i<dmxdev->filternum; i++) { 1050 for (i = 0; i < dmxdev->filternum; i++) {
1119 dmxdev->filter[i].dev=dmxdev; 1051 dmxdev->filter[i].dev = dmxdev;
1120 dmxdev->filter[i].buffer.data=NULL; 1052 dmxdev->filter[i].buffer.data = NULL;
1121 dvb_dmxdev_filter_state_set(&dmxdev->filter[i], DMXDEV_STATE_FREE); 1053 dvb_dmxdev_filter_state_set(&dmxdev->filter[i],
1122 dmxdev->dvr[i].dev=dmxdev; 1054 DMXDEV_STATE_FREE);
1123 dmxdev->dvr[i].buffer.data=NULL;
1124 dvb_dmxdev_dvr_state_set(&dmxdev->dvr[i], DMXDEV_STATE_FREE);
1125 } 1055 }
1126 1056
1127 dvb_register_device(dvb_adapter, &dmxdev->dvbdev, &dvbdev_demux, dmxdev, DVB_DEVICE_DEMUX); 1057 dvb_register_device(dvb_adapter, &dmxdev->dvbdev, &dvbdev_demux, dmxdev,
1128 dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, &dvbdev_dvr, dmxdev, DVB_DEVICE_DVR); 1058 DVB_DEVICE_DEMUX);
1059 dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, &dvbdev_dvr,
1060 dmxdev, DVB_DEVICE_DVR);
1129 1061
1130 dvb_dmxdev_buffer_init(&dmxdev->dvr_buffer); 1062 dvb_ringbuffer_init(&dmxdev->dvr_buffer, NULL, 8192);
1131 1063
1132 return 0; 1064 return 0;
1133} 1065}
1066
1134EXPORT_SYMBOL(dvb_dmxdev_init); 1067EXPORT_SYMBOL(dvb_dmxdev_init);
1135 1068
1136void 1069void dvb_dmxdev_release(struct dmxdev *dmxdev)
1137dvb_dmxdev_release(struct dmxdev *dmxdev)
1138{ 1070{
1139 dvb_unregister_device(dmxdev->dvbdev); 1071 dvb_unregister_device(dmxdev->dvbdev);
1140 dvb_unregister_device(dmxdev->dvr_dvbdev); 1072 dvb_unregister_device(dmxdev->dvr_dvbdev);
1141 1073
1142 vfree(dmxdev->filter); 1074 vfree(dmxdev->filter);
1143 dmxdev->filter=NULL; 1075 dmxdev->filter = NULL;
1144 vfree(dmxdev->dvr);
1145 dmxdev->dvr=NULL;
1146 dmxdev->demux->close(dmxdev->demux); 1076 dmxdev->demux->close(dmxdev->demux);
1147} 1077}
1078
1148EXPORT_SYMBOL(dvb_dmxdev_release); 1079EXPORT_SYMBOL(dvb_dmxdev_release);
diff --git a/drivers/media/dvb/dvb-core/dmxdev.h b/drivers/media/dvb/dvb-core/dmxdev.h
index fd72920c2199..d2bee9ffe43c 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.h
+++ b/drivers/media/dvb/dvb-core/dmxdev.h
@@ -30,14 +30,15 @@
30#include <linux/wait.h> 30#include <linux/wait.h>
31#include <linux/fs.h> 31#include <linux/fs.h>
32#include <linux/string.h> 32#include <linux/string.h>
33#include <asm/semaphore.h> 33#include <linux/mutex.h>
34 34
35#include <linux/dvb/dmx.h> 35#include <linux/dvb/dmx.h>
36 36
37#include "dvbdev.h" 37#include "dvbdev.h"
38#include "demux.h" 38#include "demux.h"
39#include "dvb_ringbuffer.h"
39 40
40enum dmxdevype { 41enum dmxdev_type {
41 DMXDEV_TYPE_NONE, 42 DMXDEV_TYPE_NONE,
42 DMXDEV_TYPE_SEC, 43 DMXDEV_TYPE_SEC,
43 DMXDEV_TYPE_PES, 44 DMXDEV_TYPE_PES,
@@ -52,18 +53,7 @@ enum dmxdev_state {
52 DMXDEV_STATE_TIMEDOUT 53 DMXDEV_STATE_TIMEDOUT
53}; 54};
54 55
55struct dmxdev_buffer {
56 u8 *data;
57 int size;
58 int pread;
59 int pwrite;
60 wait_queue_head_t queue;
61 int error;
62};
63
64struct dmxdev_filter { 56struct dmxdev_filter {
65 struct dvb_device *dvbdev;
66
67 union { 57 union {
68 struct dmx_section_filter *sec; 58 struct dmx_section_filter *sec;
69 } filter; 59 } filter;
@@ -78,26 +68,17 @@ struct dmxdev_filter {
78 struct dmx_pes_filter_params pes; 68 struct dmx_pes_filter_params pes;
79 } params; 69 } params;
80 70
81 int type; 71 enum dmxdev_type type;
82 enum dmxdev_state state; 72 enum dmxdev_state state;
83 struct dmxdev *dev; 73 struct dmxdev *dev;
84 struct dmxdev_buffer buffer; 74 struct dvb_ringbuffer buffer;
85 75
86 struct semaphore mutex; 76 struct mutex mutex;
87 77
88 /* only for sections */ 78 /* only for sections */
89 struct timer_list timer; 79 struct timer_list timer;
90 int todo; 80 int todo;
91 u8 secheader[3]; 81 u8 secheader[3];
92
93 u16 pid;
94};
95
96
97struct dmxdev_dvr {
98 int state;
99 struct dmxdev *dev;
100 struct dmxdev_buffer buffer;
101}; 82};
102 83
103 84
@@ -106,7 +87,6 @@ struct dmxdev {
106 struct dvb_device *dvr_dvbdev; 87 struct dvb_device *dvr_dvbdev;
107 88
108 struct dmxdev_filter *filter; 89 struct dmxdev_filter *filter;
109 struct dmxdev_dvr *dvr;
110 struct dmx_demux *demux; 90 struct dmx_demux *demux;
111 91
112 int filternum; 92 int filternum;
@@ -114,10 +94,10 @@ struct dmxdev {
114#define DMXDEV_CAP_DUPLEX 1 94#define DMXDEV_CAP_DUPLEX 1
115 struct dmx_frontend *dvr_orig_fe; 95 struct dmx_frontend *dvr_orig_fe;
116 96
117 struct dmxdev_buffer dvr_buffer; 97 struct dvb_ringbuffer dvr_buffer;
118#define DVR_BUFFER_SIZE (10*188*1024) 98#define DVR_BUFFER_SIZE (10*188*1024)
119 99
120 struct semaphore mutex; 100 struct mutex mutex;
121 spinlock_t lock; 101 spinlock_t lock;
122}; 102};
123 103
diff --git a/drivers/media/dvb/dvb-core/dvb_demux.c b/drivers/media/dvb/dvb-core/dvb_demux.c
index b4c899b15959..83ec5e06c482 100644
--- a/drivers/media/dvb/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb/dvb-core/dvb_demux.c
@@ -589,18 +589,18 @@ static int dmx_ts_feed_set(struct dmx_ts_feed *ts_feed, u16 pid, int ts_type,
589 if (pid > DMX_MAX_PID) 589 if (pid > DMX_MAX_PID)
590 return -EINVAL; 590 return -EINVAL;
591 591
592 if (down_interruptible(&demux->mutex)) 592 if (mutex_lock_interruptible(&demux->mutex))
593 return -ERESTARTSYS; 593 return -ERESTARTSYS;
594 594
595 if (ts_type & TS_DECODER) { 595 if (ts_type & TS_DECODER) {
596 if (pes_type >= DMX_TS_PES_OTHER) { 596 if (pes_type >= DMX_TS_PES_OTHER) {
597 up(&demux->mutex); 597 mutex_unlock(&demux->mutex);
598 return -EINVAL; 598 return -EINVAL;
599 } 599 }
600 600
601 if (demux->pesfilter[pes_type] && 601 if (demux->pesfilter[pes_type] &&
602 demux->pesfilter[pes_type] != feed) { 602 demux->pesfilter[pes_type] != feed) {
603 up(&demux->mutex); 603 mutex_unlock(&demux->mutex);
604 return -EINVAL; 604 return -EINVAL;
605 } 605 }
606 606
@@ -622,14 +622,14 @@ static int dmx_ts_feed_set(struct dmx_ts_feed *ts_feed, u16 pid, int ts_type,
622#else 622#else
623 feed->buffer = vmalloc(feed->buffer_size); 623 feed->buffer = vmalloc(feed->buffer_size);
624 if (!feed->buffer) { 624 if (!feed->buffer) {
625 up(&demux->mutex); 625 mutex_unlock(&demux->mutex);
626 return -ENOMEM; 626 return -ENOMEM;
627 } 627 }
628#endif 628#endif
629 } 629 }
630 630
631 feed->state = DMX_STATE_READY; 631 feed->state = DMX_STATE_READY;
632 up(&demux->mutex); 632 mutex_unlock(&demux->mutex);
633 633
634 return 0; 634 return 0;
635} 635}
@@ -640,21 +640,21 @@ static int dmx_ts_feed_start_filtering(struct dmx_ts_feed *ts_feed)
640 struct dvb_demux *demux = feed->demux; 640 struct dvb_demux *demux = feed->demux;
641 int ret; 641 int ret;
642 642
643 if (down_interruptible(&demux->mutex)) 643 if (mutex_lock_interruptible(&demux->mutex))
644 return -ERESTARTSYS; 644 return -ERESTARTSYS;
645 645
646 if (feed->state != DMX_STATE_READY || feed->type != DMX_TYPE_TS) { 646 if (feed->state != DMX_STATE_READY || feed->type != DMX_TYPE_TS) {
647 up(&demux->mutex); 647 mutex_unlock(&demux->mutex);
648 return -EINVAL; 648 return -EINVAL;
649 } 649 }
650 650
651 if (!demux->start_feed) { 651 if (!demux->start_feed) {
652 up(&demux->mutex); 652 mutex_unlock(&demux->mutex);
653 return -ENODEV; 653 return -ENODEV;
654 } 654 }
655 655
656 if ((ret = demux->start_feed(feed)) < 0) { 656 if ((ret = demux->start_feed(feed)) < 0) {
657 up(&demux->mutex); 657 mutex_unlock(&demux->mutex);
658 return ret; 658 return ret;
659 } 659 }
660 660
@@ -662,7 +662,7 @@ static int dmx_ts_feed_start_filtering(struct dmx_ts_feed *ts_feed)
662 ts_feed->is_filtering = 1; 662 ts_feed->is_filtering = 1;
663 feed->state = DMX_STATE_GO; 663 feed->state = DMX_STATE_GO;
664 spin_unlock_irq(&demux->lock); 664 spin_unlock_irq(&demux->lock);
665 up(&demux->mutex); 665 mutex_unlock(&demux->mutex);
666 666
667 return 0; 667 return 0;
668} 668}
@@ -673,16 +673,16 @@ static int dmx_ts_feed_stop_filtering(struct dmx_ts_feed *ts_feed)
673 struct dvb_demux *demux = feed->demux; 673 struct dvb_demux *demux = feed->demux;
674 int ret; 674 int ret;
675 675
676 if (down_interruptible(&demux->mutex)) 676 if (mutex_lock_interruptible(&demux->mutex))
677 return -ERESTARTSYS; 677 return -ERESTARTSYS;
678 678
679 if (feed->state < DMX_STATE_GO) { 679 if (feed->state < DMX_STATE_GO) {
680 up(&demux->mutex); 680 mutex_unlock(&demux->mutex);
681 return -EINVAL; 681 return -EINVAL;
682 } 682 }
683 683
684 if (!demux->stop_feed) { 684 if (!demux->stop_feed) {
685 up(&demux->mutex); 685 mutex_unlock(&demux->mutex);
686 return -ENODEV; 686 return -ENODEV;
687 } 687 }
688 688
@@ -692,7 +692,7 @@ static int dmx_ts_feed_stop_filtering(struct dmx_ts_feed *ts_feed)
692 ts_feed->is_filtering = 0; 692 ts_feed->is_filtering = 0;
693 feed->state = DMX_STATE_ALLOCATED; 693 feed->state = DMX_STATE_ALLOCATED;
694 spin_unlock_irq(&demux->lock); 694 spin_unlock_irq(&demux->lock);
695 up(&demux->mutex); 695 mutex_unlock(&demux->mutex);
696 696
697 return ret; 697 return ret;
698} 698}
@@ -704,11 +704,11 @@ static int dvbdmx_allocate_ts_feed(struct dmx_demux *dmx,
704 struct dvb_demux *demux = (struct dvb_demux *)dmx; 704 struct dvb_demux *demux = (struct dvb_demux *)dmx;
705 struct dvb_demux_feed *feed; 705 struct dvb_demux_feed *feed;
706 706
707 if (down_interruptible(&demux->mutex)) 707 if (mutex_lock_interruptible(&demux->mutex))
708 return -ERESTARTSYS; 708 return -ERESTARTSYS;
709 709
710 if (!(feed = dvb_dmx_feed_alloc(demux))) { 710 if (!(feed = dvb_dmx_feed_alloc(demux))) {
711 up(&demux->mutex); 711 mutex_unlock(&demux->mutex);
712 return -EBUSY; 712 return -EBUSY;
713 } 713 }
714 714
@@ -729,7 +729,7 @@ static int dvbdmx_allocate_ts_feed(struct dmx_demux *dmx,
729 729
730 if (!(feed->filter = dvb_dmx_filter_alloc(demux))) { 730 if (!(feed->filter = dvb_dmx_filter_alloc(demux))) {
731 feed->state = DMX_STATE_FREE; 731 feed->state = DMX_STATE_FREE;
732 up(&demux->mutex); 732 mutex_unlock(&demux->mutex);
733 return -EBUSY; 733 return -EBUSY;
734 } 734 }
735 735
@@ -737,7 +737,7 @@ static int dvbdmx_allocate_ts_feed(struct dmx_demux *dmx,
737 feed->filter->feed = feed; 737 feed->filter->feed = feed;
738 feed->filter->state = DMX_STATE_READY; 738 feed->filter->state = DMX_STATE_READY;
739 739
740 up(&demux->mutex); 740 mutex_unlock(&demux->mutex);
741 741
742 return 0; 742 return 0;
743} 743}
@@ -748,11 +748,11 @@ static int dvbdmx_release_ts_feed(struct dmx_demux *dmx,
748 struct dvb_demux *demux = (struct dvb_demux *)dmx; 748 struct dvb_demux *demux = (struct dvb_demux *)dmx;
749 struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; 749 struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed;
750 750
751 if (down_interruptible(&demux->mutex)) 751 if (mutex_lock_interruptible(&demux->mutex))
752 return -ERESTARTSYS; 752 return -ERESTARTSYS;
753 753
754 if (feed->state == DMX_STATE_FREE) { 754 if (feed->state == DMX_STATE_FREE) {
755 up(&demux->mutex); 755 mutex_unlock(&demux->mutex);
756 return -EINVAL; 756 return -EINVAL;
757 } 757 }
758#ifndef NOBUFS 758#ifndef NOBUFS
@@ -770,7 +770,7 @@ static int dvbdmx_release_ts_feed(struct dmx_demux *dmx,
770 if (feed->ts_type & TS_DECODER && feed->pes_type < DMX_TS_PES_OTHER) 770 if (feed->ts_type & TS_DECODER && feed->pes_type < DMX_TS_PES_OTHER)
771 demux->pesfilter[feed->pes_type] = NULL; 771 demux->pesfilter[feed->pes_type] = NULL;
772 772
773 up(&demux->mutex); 773 mutex_unlock(&demux->mutex);
774 return 0; 774 return 0;
775} 775}
776 776
@@ -785,12 +785,12 @@ static int dmx_section_feed_allocate_filter(struct dmx_section_feed *feed,
785 struct dvb_demux *dvbdemux = dvbdmxfeed->demux; 785 struct dvb_demux *dvbdemux = dvbdmxfeed->demux;
786 struct dvb_demux_filter *dvbdmxfilter; 786 struct dvb_demux_filter *dvbdmxfilter;
787 787
788 if (down_interruptible(&dvbdemux->mutex)) 788 if (mutex_lock_interruptible(&dvbdemux->mutex))
789 return -ERESTARTSYS; 789 return -ERESTARTSYS;
790 790
791 dvbdmxfilter = dvb_dmx_filter_alloc(dvbdemux); 791 dvbdmxfilter = dvb_dmx_filter_alloc(dvbdemux);
792 if (!dvbdmxfilter) { 792 if (!dvbdmxfilter) {
793 up(&dvbdemux->mutex); 793 mutex_unlock(&dvbdemux->mutex);
794 return -EBUSY; 794 return -EBUSY;
795 } 795 }
796 796
@@ -805,7 +805,7 @@ static int dmx_section_feed_allocate_filter(struct dmx_section_feed *feed,
805 dvbdmxfeed->filter = dvbdmxfilter; 805 dvbdmxfeed->filter = dvbdmxfilter;
806 spin_unlock_irq(&dvbdemux->lock); 806 spin_unlock_irq(&dvbdemux->lock);
807 807
808 up(&dvbdemux->mutex); 808 mutex_unlock(&dvbdemux->mutex);
809 return 0; 809 return 0;
810} 810}
811 811
@@ -819,7 +819,7 @@ static int dmx_section_feed_set(struct dmx_section_feed *feed,
819 if (pid > 0x1fff) 819 if (pid > 0x1fff)
820 return -EINVAL; 820 return -EINVAL;
821 821
822 if (down_interruptible(&dvbdmx->mutex)) 822 if (mutex_lock_interruptible(&dvbdmx->mutex))
823 return -ERESTARTSYS; 823 return -ERESTARTSYS;
824 824
825 dvb_demux_feed_add(dvbdmxfeed); 825 dvb_demux_feed_add(dvbdmxfeed);
@@ -833,13 +833,13 @@ static int dmx_section_feed_set(struct dmx_section_feed *feed,
833#else 833#else
834 dvbdmxfeed->buffer = vmalloc(dvbdmxfeed->buffer_size); 834 dvbdmxfeed->buffer = vmalloc(dvbdmxfeed->buffer_size);
835 if (!dvbdmxfeed->buffer) { 835 if (!dvbdmxfeed->buffer) {
836 up(&dvbdmx->mutex); 836 mutex_unlock(&dvbdmx->mutex);
837 return -ENOMEM; 837 return -ENOMEM;
838 } 838 }
839#endif 839#endif
840 840
841 dvbdmxfeed->state = DMX_STATE_READY; 841 dvbdmxfeed->state = DMX_STATE_READY;
842 up(&dvbdmx->mutex); 842 mutex_unlock(&dvbdmx->mutex);
843 return 0; 843 return 0;
844} 844}
845 845
@@ -871,16 +871,16 @@ static int dmx_section_feed_start_filtering(struct dmx_section_feed *feed)
871 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 871 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
872 int ret; 872 int ret;
873 873
874 if (down_interruptible(&dvbdmx->mutex)) 874 if (mutex_lock_interruptible(&dvbdmx->mutex))
875 return -ERESTARTSYS; 875 return -ERESTARTSYS;
876 876
877 if (feed->is_filtering) { 877 if (feed->is_filtering) {
878 up(&dvbdmx->mutex); 878 mutex_unlock(&dvbdmx->mutex);
879 return -EBUSY; 879 return -EBUSY;
880 } 880 }
881 881
882 if (!dvbdmxfeed->filter) { 882 if (!dvbdmxfeed->filter) {
883 up(&dvbdmx->mutex); 883 mutex_unlock(&dvbdmx->mutex);
884 return -EINVAL; 884 return -EINVAL;
885 } 885 }
886 886
@@ -890,14 +890,14 @@ static int dmx_section_feed_start_filtering(struct dmx_section_feed *feed)
890 dvbdmxfeed->feed.sec.seclen = 0; 890 dvbdmxfeed->feed.sec.seclen = 0;
891 891
892 if (!dvbdmx->start_feed) { 892 if (!dvbdmx->start_feed) {
893 up(&dvbdmx->mutex); 893 mutex_unlock(&dvbdmx->mutex);
894 return -ENODEV; 894 return -ENODEV;
895 } 895 }
896 896
897 prepare_secfilters(dvbdmxfeed); 897 prepare_secfilters(dvbdmxfeed);
898 898
899 if ((ret = dvbdmx->start_feed(dvbdmxfeed)) < 0) { 899 if ((ret = dvbdmx->start_feed(dvbdmxfeed)) < 0) {
900 up(&dvbdmx->mutex); 900 mutex_unlock(&dvbdmx->mutex);
901 return ret; 901 return ret;
902 } 902 }
903 903
@@ -906,7 +906,7 @@ static int dmx_section_feed_start_filtering(struct dmx_section_feed *feed)
906 dvbdmxfeed->state = DMX_STATE_GO; 906 dvbdmxfeed->state = DMX_STATE_GO;
907 spin_unlock_irq(&dvbdmx->lock); 907 spin_unlock_irq(&dvbdmx->lock);
908 908
909 up(&dvbdmx->mutex); 909 mutex_unlock(&dvbdmx->mutex);
910 return 0; 910 return 0;
911} 911}
912 912
@@ -916,11 +916,11 @@ static int dmx_section_feed_stop_filtering(struct dmx_section_feed *feed)
916 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 916 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
917 int ret; 917 int ret;
918 918
919 if (down_interruptible(&dvbdmx->mutex)) 919 if (mutex_lock_interruptible(&dvbdmx->mutex))
920 return -ERESTARTSYS; 920 return -ERESTARTSYS;
921 921
922 if (!dvbdmx->stop_feed) { 922 if (!dvbdmx->stop_feed) {
923 up(&dvbdmx->mutex); 923 mutex_unlock(&dvbdmx->mutex);
924 return -ENODEV; 924 return -ENODEV;
925 } 925 }
926 926
@@ -931,7 +931,7 @@ static int dmx_section_feed_stop_filtering(struct dmx_section_feed *feed)
931 feed->is_filtering = 0; 931 feed->is_filtering = 0;
932 spin_unlock_irq(&dvbdmx->lock); 932 spin_unlock_irq(&dvbdmx->lock);
933 933
934 up(&dvbdmx->mutex); 934 mutex_unlock(&dvbdmx->mutex);
935 return ret; 935 return ret;
936} 936}
937 937
@@ -942,11 +942,11 @@ static int dmx_section_feed_release_filter(struct dmx_section_feed *feed,
942 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; 942 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
943 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 943 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
944 944
945 if (down_interruptible(&dvbdmx->mutex)) 945 if (mutex_lock_interruptible(&dvbdmx->mutex))
946 return -ERESTARTSYS; 946 return -ERESTARTSYS;
947 947
948 if (dvbdmxfilter->feed != dvbdmxfeed) { 948 if (dvbdmxfilter->feed != dvbdmxfeed) {
949 up(&dvbdmx->mutex); 949 mutex_unlock(&dvbdmx->mutex);
950 return -EINVAL; 950 return -EINVAL;
951 } 951 }
952 952
@@ -966,7 +966,7 @@ static int dmx_section_feed_release_filter(struct dmx_section_feed *feed,
966 966
967 dvbdmxfilter->state = DMX_STATE_FREE; 967 dvbdmxfilter->state = DMX_STATE_FREE;
968 spin_unlock_irq(&dvbdmx->lock); 968 spin_unlock_irq(&dvbdmx->lock);
969 up(&dvbdmx->mutex); 969 mutex_unlock(&dvbdmx->mutex);
970 return 0; 970 return 0;
971} 971}
972 972
@@ -977,11 +977,11 @@ static int dvbdmx_allocate_section_feed(struct dmx_demux *demux,
977 struct dvb_demux *dvbdmx = (struct dvb_demux *)demux; 977 struct dvb_demux *dvbdmx = (struct dvb_demux *)demux;
978 struct dvb_demux_feed *dvbdmxfeed; 978 struct dvb_demux_feed *dvbdmxfeed;
979 979
980 if (down_interruptible(&dvbdmx->mutex)) 980 if (mutex_lock_interruptible(&dvbdmx->mutex))
981 return -ERESTARTSYS; 981 return -ERESTARTSYS;
982 982
983 if (!(dvbdmxfeed = dvb_dmx_feed_alloc(dvbdmx))) { 983 if (!(dvbdmxfeed = dvb_dmx_feed_alloc(dvbdmx))) {
984 up(&dvbdmx->mutex); 984 mutex_unlock(&dvbdmx->mutex);
985 return -EBUSY; 985 return -EBUSY;
986 } 986 }
987 987
@@ -1006,7 +1006,7 @@ static int dvbdmx_allocate_section_feed(struct dmx_demux *demux,
1006 (*feed)->stop_filtering = dmx_section_feed_stop_filtering; 1006 (*feed)->stop_filtering = dmx_section_feed_stop_filtering;
1007 (*feed)->release_filter = dmx_section_feed_release_filter; 1007 (*feed)->release_filter = dmx_section_feed_release_filter;
1008 1008
1009 up(&dvbdmx->mutex); 1009 mutex_unlock(&dvbdmx->mutex);
1010 return 0; 1010 return 0;
1011} 1011}
1012 1012
@@ -1016,11 +1016,11 @@ static int dvbdmx_release_section_feed(struct dmx_demux *demux,
1016 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; 1016 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
1017 struct dvb_demux *dvbdmx = (struct dvb_demux *)demux; 1017 struct dvb_demux *dvbdmx = (struct dvb_demux *)demux;
1018 1018
1019 if (down_interruptible(&dvbdmx->mutex)) 1019 if (mutex_lock_interruptible(&dvbdmx->mutex))
1020 return -ERESTARTSYS; 1020 return -ERESTARTSYS;
1021 1021
1022 if (dvbdmxfeed->state == DMX_STATE_FREE) { 1022 if (dvbdmxfeed->state == DMX_STATE_FREE) {
1023 up(&dvbdmx->mutex); 1023 mutex_unlock(&dvbdmx->mutex);
1024 return -EINVAL; 1024 return -EINVAL;
1025 } 1025 }
1026#ifndef NOBUFS 1026#ifndef NOBUFS
@@ -1033,7 +1033,7 @@ static int dvbdmx_release_section_feed(struct dmx_demux *demux,
1033 1033
1034 dvbdmxfeed->pid = 0xffff; 1034 dvbdmxfeed->pid = 0xffff;
1035 1035
1036 up(&dvbdmx->mutex); 1036 mutex_unlock(&dvbdmx->mutex);
1037 return 0; 1037 return 0;
1038} 1038}
1039 1039
@@ -1071,10 +1071,10 @@ static int dvbdmx_write(struct dmx_demux *demux, const char *buf, size_t count)
1071 if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE)) 1071 if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE))
1072 return -EINVAL; 1072 return -EINVAL;
1073 1073
1074 if (down_interruptible(&dvbdemux->mutex)) 1074 if (mutex_lock_interruptible(&dvbdemux->mutex))
1075 return -ERESTARTSYS; 1075 return -ERESTARTSYS;
1076 dvb_dmx_swfilter(dvbdemux, buf, count); 1076 dvb_dmx_swfilter(dvbdemux, buf, count);
1077 up(&dvbdemux->mutex); 1077 mutex_unlock(&dvbdemux->mutex);
1078 1078
1079 if (signal_pending(current)) 1079 if (signal_pending(current))
1080 return -EINTR; 1080 return -EINTR;
@@ -1126,11 +1126,11 @@ static int dvbdmx_connect_frontend(struct dmx_demux *demux,
1126 if (demux->frontend) 1126 if (demux->frontend)
1127 return -EINVAL; 1127 return -EINVAL;
1128 1128
1129 if (down_interruptible(&dvbdemux->mutex)) 1129 if (mutex_lock_interruptible(&dvbdemux->mutex))
1130 return -ERESTARTSYS; 1130 return -ERESTARTSYS;
1131 1131
1132 demux->frontend = frontend; 1132 demux->frontend = frontend;
1133 up(&dvbdemux->mutex); 1133 mutex_unlock(&dvbdemux->mutex);
1134 return 0; 1134 return 0;
1135} 1135}
1136 1136
@@ -1138,11 +1138,11 @@ static int dvbdmx_disconnect_frontend(struct dmx_demux *demux)
1138{ 1138{
1139 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; 1139 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1140 1140
1141 if (down_interruptible(&dvbdemux->mutex)) 1141 if (mutex_lock_interruptible(&dvbdemux->mutex))
1142 return -ERESTARTSYS; 1142 return -ERESTARTSYS;
1143 1143
1144 demux->frontend = NULL; 1144 demux->frontend = NULL;
1145 up(&dvbdemux->mutex); 1145 mutex_unlock(&dvbdemux->mutex);
1146 return 0; 1146 return 0;
1147} 1147}
1148 1148
@@ -1215,7 +1215,7 @@ int dvb_dmx_init(struct dvb_demux *dvbdemux)
1215 dmx->disconnect_frontend = dvbdmx_disconnect_frontend; 1215 dmx->disconnect_frontend = dvbdmx_disconnect_frontend;
1216 dmx->get_pes_pids = dvbdmx_get_pes_pids; 1216 dmx->get_pes_pids = dvbdmx_get_pes_pids;
1217 1217
1218 sema_init(&dvbdemux->mutex, 1); 1218 mutex_init(&dvbdemux->mutex);
1219 spin_lock_init(&dvbdemux->lock); 1219 spin_lock_init(&dvbdemux->lock);
1220 1220
1221 return 0; 1221 return 0;
diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
index 0cc888339d52..2c5f915329ca 100644
--- a/drivers/media/dvb/dvb-core/dvb_demux.h
+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
@@ -26,7 +26,7 @@
26#include <linux/time.h> 26#include <linux/time.h>
27#include <linux/timer.h> 27#include <linux/timer.h>
28#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29#include <asm/semaphore.h> 29#include <linux/mutex.h>
30 30
31#include "demux.h" 31#include "demux.h"
32 32
@@ -125,7 +125,7 @@ struct dvb_demux {
125 u8 tsbuf[204]; 125 u8 tsbuf[204];
126 int tsbufp; 126 int tsbufp;
127 127
128 struct semaphore mutex; 128 struct mutex mutex;
129 spinlock_t lock; 129 spinlock_t lock;
130}; 130};
131 131
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 771f32d889e6..2c3ea8f95dcd 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -37,7 +37,6 @@
37#include <linux/suspend.h> 37#include <linux/suspend.h>
38#include <linux/jiffies.h> 38#include <linux/jiffies.h>
39#include <asm/processor.h> 39#include <asm/processor.h>
40#include <asm/semaphore.h>
41 40
42#include "dvb_frontend.h" 41#include "dvb_frontend.h"
43#include "dvbdev.h" 42#include "dvbdev.h"
@@ -50,13 +49,13 @@ static int dvb_powerdown_on_sleep = 1;
50 49
51module_param_named(frontend_debug, dvb_frontend_debug, int, 0644); 50module_param_named(frontend_debug, dvb_frontend_debug, int, 0644);
52MODULE_PARM_DESC(frontend_debug, "Turn on/off frontend core debugging (default:off)."); 51MODULE_PARM_DESC(frontend_debug, "Turn on/off frontend core debugging (default:off).");
53module_param(dvb_shutdown_timeout, int, 0444); 52module_param(dvb_shutdown_timeout, int, 0644);
54MODULE_PARM_DESC(dvb_shutdown_timeout, "wait <shutdown_timeout> seconds after close() before suspending hardware"); 53MODULE_PARM_DESC(dvb_shutdown_timeout, "wait <shutdown_timeout> seconds after close() before suspending hardware");
55module_param(dvb_force_auto_inversion, int, 0444); 54module_param(dvb_force_auto_inversion, int, 0644);
56MODULE_PARM_DESC(dvb_force_auto_inversion, "0: normal (default), 1: INVERSION_AUTO forced always"); 55MODULE_PARM_DESC(dvb_force_auto_inversion, "0: normal (default), 1: INVERSION_AUTO forced always");
57module_param(dvb_override_tune_delay, int, 0444); 56module_param(dvb_override_tune_delay, int, 0644);
58MODULE_PARM_DESC(dvb_override_tune_delay, "0: normal (default), >0 => delay in milliseconds to wait for lock after a tune attempt"); 57MODULE_PARM_DESC(dvb_override_tune_delay, "0: normal (default), >0 => delay in milliseconds to wait for lock after a tune attempt");
59module_param(dvb_powerdown_on_sleep, int, 0444); 58module_param(dvb_powerdown_on_sleep, int, 0644);
60MODULE_PARM_DESC(dvb_powerdown_on_sleep, "0: do not power down, 1: turn LNB volatage off on sleep (default)"); 59MODULE_PARM_DESC(dvb_powerdown_on_sleep, "0: do not power down, 1: turn LNB volatage off on sleep (default)");
61 60
62#define dprintk if (dvb_frontend_debug) printk 61#define dprintk if (dvb_frontend_debug) printk
@@ -88,7 +87,7 @@ MODULE_PARM_DESC(dvb_powerdown_on_sleep, "0: do not power down, 1: turn LNB vola
88 * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again. 87 * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again.
89 */ 88 */
90 89
91static DECLARE_MUTEX(frontend_mutex); 90static DEFINE_MUTEX(frontend_mutex);
92 91
93struct dvb_frontend_private { 92struct dvb_frontend_private {
94 93
@@ -1021,12 +1020,12 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
1021 1020
1022 dprintk ("%s\n", __FUNCTION__); 1021 dprintk ("%s\n", __FUNCTION__);
1023 1022
1024 if (down_interruptible (&frontend_mutex)) 1023 if (mutex_lock_interruptible(&frontend_mutex))
1025 return -ERESTARTSYS; 1024 return -ERESTARTSYS;
1026 1025
1027 fe->frontend_priv = kzalloc(sizeof(struct dvb_frontend_private), GFP_KERNEL); 1026 fe->frontend_priv = kzalloc(sizeof(struct dvb_frontend_private), GFP_KERNEL);
1028 if (fe->frontend_priv == NULL) { 1027 if (fe->frontend_priv == NULL) {
1029 up(&frontend_mutex); 1028 mutex_unlock(&frontend_mutex);
1030 return -ENOMEM; 1029 return -ENOMEM;
1031 } 1030 }
1032 fepriv = fe->frontend_priv; 1031 fepriv = fe->frontend_priv;
@@ -1045,7 +1044,7 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
1045 dvb_register_device (fe->dvb, &fepriv->dvbdev, &dvbdev_template, 1044 dvb_register_device (fe->dvb, &fepriv->dvbdev, &dvbdev_template,
1046 fe, DVB_DEVICE_FRONTEND); 1045 fe, DVB_DEVICE_FRONTEND);
1047 1046
1048 up (&frontend_mutex); 1047 mutex_unlock(&frontend_mutex);
1049 return 0; 1048 return 0;
1050} 1049}
1051EXPORT_SYMBOL(dvb_register_frontend); 1050EXPORT_SYMBOL(dvb_register_frontend);
@@ -1055,7 +1054,7 @@ int dvb_unregister_frontend(struct dvb_frontend* fe)
1055 struct dvb_frontend_private *fepriv = fe->frontend_priv; 1054 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1056 dprintk ("%s\n", __FUNCTION__); 1055 dprintk ("%s\n", __FUNCTION__);
1057 1056
1058 down (&frontend_mutex); 1057 mutex_lock(&frontend_mutex);
1059 dvb_unregister_device (fepriv->dvbdev); 1058 dvb_unregister_device (fepriv->dvbdev);
1060 dvb_frontend_stop (fe); 1059 dvb_frontend_stop (fe);
1061 if (fe->ops->release) 1060 if (fe->ops->release)
@@ -1064,7 +1063,7 @@ int dvb_unregister_frontend(struct dvb_frontend* fe)
1064 printk("dvb_frontend: Demodulator (%s) does not have a release callback!\n", fe->ops->info.name); 1063 printk("dvb_frontend: Demodulator (%s) does not have a release callback!\n", fe->ops->info.name);
1065 /* fe is invalid now */ 1064 /* fe is invalid now */
1066 kfree(fepriv); 1065 kfree(fepriv);
1067 up (&frontend_mutex); 1066 mutex_unlock(&frontend_mutex);
1068 return 0; 1067 return 0;
1069} 1068}
1070EXPORT_SYMBOL(dvb_unregister_frontend); 1069EXPORT_SYMBOL(dvb_unregister_frontend);
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.h b/drivers/media/dvb/dvb-core/dvb_frontend.h
index 70a6d14efda7..d5aee5ad67a0 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.h
@@ -104,6 +104,7 @@ struct dvb_frontend {
104 struct dvb_adapter *dvb; 104 struct dvb_adapter *dvb;
105 void* demodulator_priv; 105 void* demodulator_priv;
106 void* frontend_priv; 106 void* frontend_priv;
107 void* misc_priv;
107}; 108};
108 109
109extern int dvb_register_frontend(struct dvb_adapter* dvb, 110extern int dvb_register_frontend(struct dvb_adapter* dvb,
diff --git a/drivers/media/dvb/dvb-core/dvb_net.c b/drivers/media/dvb/dvb-core/dvb_net.c
index 6711eb6a058c..2f0f35811bf7 100644
--- a/drivers/media/dvb/dvb-core/dvb_net.c
+++ b/drivers/media/dvb/dvb-core/dvb_net.c
@@ -62,6 +62,7 @@
62#include <linux/uio.h> 62#include <linux/uio.h>
63#include <asm/uaccess.h> 63#include <asm/uaccess.h>
64#include <linux/crc32.h> 64#include <linux/crc32.h>
65#include <linux/mutex.h>
65 66
66#include "dvb_demux.h" 67#include "dvb_demux.h"
67#include "dvb_net.h" 68#include "dvb_net.h"
@@ -151,8 +152,7 @@ struct dvb_net_priv {
151 unsigned char ule_bridged; /* Whether the ULE_BRIDGED extension header was found. */ 152 unsigned char ule_bridged; /* Whether the ULE_BRIDGED extension header was found. */
152 int ule_sndu_remain; /* Nr. of bytes still required for current ULE SNDU. */ 153 int ule_sndu_remain; /* Nr. of bytes still required for current ULE SNDU. */
153 unsigned long ts_count; /* Current ts cell counter. */ 154 unsigned long ts_count; /* Current ts cell counter. */
154 155 struct mutex mutex;
155 struct semaphore mutex;
156}; 156};
157 157
158 158
@@ -889,7 +889,7 @@ static int dvb_net_feed_start(struct net_device *dev)
889 unsigned char *mac = (unsigned char *) dev->dev_addr; 889 unsigned char *mac = (unsigned char *) dev->dev_addr;
890 890
891 dprintk("%s: rx_mode %i\n", __FUNCTION__, priv->rx_mode); 891 dprintk("%s: rx_mode %i\n", __FUNCTION__, priv->rx_mode);
892 down(&priv->mutex); 892 mutex_lock(&priv->mutex);
893 if (priv->tsfeed || priv->secfeed || priv->secfilter || priv->multi_secfilter[0]) 893 if (priv->tsfeed || priv->secfeed || priv->secfilter || priv->multi_secfilter[0])
894 printk("%s: BUG %d\n", __FUNCTION__, __LINE__); 894 printk("%s: BUG %d\n", __FUNCTION__, __LINE__);
895 895
@@ -974,7 +974,7 @@ static int dvb_net_feed_start(struct net_device *dev)
974 ret = -EINVAL; 974 ret = -EINVAL;
975 975
976error: 976error:
977 up(&priv->mutex); 977 mutex_unlock(&priv->mutex);
978 return ret; 978 return ret;
979} 979}
980 980
@@ -984,7 +984,7 @@ static int dvb_net_feed_stop(struct net_device *dev)
984 int i, ret = 0; 984 int i, ret = 0;
985 985
986 dprintk("%s\n", __FUNCTION__); 986 dprintk("%s\n", __FUNCTION__);
987 down(&priv->mutex); 987 mutex_lock(&priv->mutex);
988 if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) { 988 if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) {
989 if (priv->secfeed) { 989 if (priv->secfeed) {
990 if (priv->secfeed->is_filtering) { 990 if (priv->secfeed->is_filtering) {
@@ -1026,7 +1026,7 @@ static int dvb_net_feed_stop(struct net_device *dev)
1026 printk("%s: no ts feed to stop\n", dev->name); 1026 printk("%s: no ts feed to stop\n", dev->name);
1027 } else 1027 } else
1028 ret = -EINVAL; 1028 ret = -EINVAL;
1029 up(&priv->mutex); 1029 mutex_unlock(&priv->mutex);
1030 return ret; 1030 return ret;
1031} 1031}
1032 1032
@@ -1208,7 +1208,7 @@ static int dvb_net_add_if(struct dvb_net *dvbnet, u16 pid, u8 feedtype)
1208 1208
1209 INIT_WORK(&priv->set_multicast_list_wq, wq_set_multicast_list, net); 1209 INIT_WORK(&priv->set_multicast_list_wq, wq_set_multicast_list, net);
1210 INIT_WORK(&priv->restart_net_feed_wq, wq_restart_net_feed, net); 1210 INIT_WORK(&priv->restart_net_feed_wq, wq_restart_net_feed, net);
1211 init_MUTEX(&priv->mutex); 1211 mutex_init(&priv->mutex);
1212 1212
1213 net->base_addr = pid; 1213 net->base_addr = pid;
1214 1214
diff --git a/drivers/media/dvb/dvb-core/dvb_ringbuffer.c b/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
index 77ad2410f4d3..c972fe014c58 100644
--- a/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
+++ b/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
@@ -45,6 +45,7 @@ void dvb_ringbuffer_init(struct dvb_ringbuffer *rbuf, void *data, size_t len)
45 rbuf->pread=rbuf->pwrite=0; 45 rbuf->pread=rbuf->pwrite=0;
46 rbuf->data=data; 46 rbuf->data=data;
47 rbuf->size=len; 47 rbuf->size=len;
48 rbuf->error=0;
48 49
49 init_waitqueue_head(&rbuf->queue); 50 init_waitqueue_head(&rbuf->queue);
50 51
@@ -87,6 +88,7 @@ ssize_t dvb_ringbuffer_avail(struct dvb_ringbuffer *rbuf)
87void dvb_ringbuffer_flush(struct dvb_ringbuffer *rbuf) 88void dvb_ringbuffer_flush(struct dvb_ringbuffer *rbuf)
88{ 89{
89 rbuf->pread = rbuf->pwrite; 90 rbuf->pread = rbuf->pwrite;
91 rbuf->error = 0;
90} 92}
91 93
92 94
diff --git a/drivers/media/dvb/dvb-core/dvb_ringbuffer.h b/drivers/media/dvb/dvb-core/dvb_ringbuffer.h
index 6d2560972771..d97714e75736 100644
--- a/drivers/media/dvb/dvb-core/dvb_ringbuffer.h
+++ b/drivers/media/dvb/dvb-core/dvb_ringbuffer.h
@@ -35,6 +35,7 @@ struct dvb_ringbuffer {
35 ssize_t size; 35 ssize_t size;
36 ssize_t pread; 36 ssize_t pread;
37 ssize_t pwrite; 37 ssize_t pwrite;
38 int error;
38 39
39 wait_queue_head_t queue; 40 wait_queue_head_t queue;
40 spinlock_t lock; 41 spinlock_t lock;
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index 162f9795cd89..e14bf43941e3 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -77,7 +77,7 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
77 struct dvb_usb_device *d = i2c_get_adapdata(adap); 77 struct dvb_usb_device *d = i2c_get_adapdata(adap);
78 int i; 78 int i;
79 79
80 if (down_interruptible(&d->i2c_sem) < 0) 80 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
81 return -EAGAIN; 81 return -EAGAIN;
82 82
83 if (num > 2) 83 if (num > 2)
@@ -126,7 +126,7 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
126 } 126 }
127 } 127 }
128 128
129 up(&d->i2c_sem); 129 mutex_unlock(&d->i2c_mutex);
130 return i; 130 return i;
131} 131}
132 132
diff --git a/drivers/media/dvb/dvb-usb/dibusb-common.c b/drivers/media/dvb/dvb-usb/dibusb-common.c
index 269d899da488..2d52b76671d3 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-common.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-common.c
@@ -128,7 +128,7 @@ static int dibusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num
128 struct dvb_usb_device *d = i2c_get_adapdata(adap); 128 struct dvb_usb_device *d = i2c_get_adapdata(adap);
129 int i; 129 int i;
130 130
131 if (down_interruptible(&d->i2c_sem) < 0) 131 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
132 return -EAGAIN; 132 return -EAGAIN;
133 133
134 if (num > 2) 134 if (num > 2)
@@ -146,7 +146,7 @@ static int dibusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num
146 break; 146 break;
147 } 147 }
148 148
149 up(&d->i2c_sem); 149 mutex_unlock(&d->i2c_mutex);
150 return i; 150 return i;
151} 151}
152 152
diff --git a/drivers/media/dvb/dvb-usb/digitv.c b/drivers/media/dvb/dvb-usb/digitv.c
index caa1346e3063..91136c00ce9d 100644
--- a/drivers/media/dvb/dvb-usb/digitv.c
+++ b/drivers/media/dvb/dvb-usb/digitv.c
@@ -48,7 +48,7 @@ static int digitv_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num
48 struct dvb_usb_device *d = i2c_get_adapdata(adap); 48 struct dvb_usb_device *d = i2c_get_adapdata(adap);
49 int i; 49 int i;
50 50
51 if (down_interruptible(&d->i2c_sem) < 0) 51 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
52 return -EAGAIN; 52 return -EAGAIN;
53 53
54 if (num > 2) 54 if (num > 2)
@@ -67,7 +67,7 @@ static int digitv_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num
67 break; 67 break;
68 } 68 }
69 69
70 up(&d->i2c_sem); 70 mutex_unlock(&d->i2c_mutex);
71 return i; 71 return i;
72} 72}
73 73
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-init.c b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
index ce34a55e5c24..a1705ecb9a54 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
@@ -42,8 +42,8 @@ static int dvb_usb_init(struct dvb_usb_device *d)
42{ 42{
43 int ret = 0; 43 int ret = 0;
44 44
45 sema_init(&d->usb_sem, 1); 45 mutex_init(&d->usb_mutex);
46 sema_init(&d->i2c_sem, 1); 46 mutex_init(&d->i2c_mutex);
47 47
48 d->state = DVB_USB_STATE_INIT; 48 d->state = DVB_USB_STATE_INIT;
49 49
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-urb.c b/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
index ee821974dc60..9002f35aa952 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
@@ -21,7 +21,7 @@ int dvb_usb_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf,
21 if (wbuf == NULL || wlen == 0) 21 if (wbuf == NULL || wlen == 0)
22 return -EINVAL; 22 return -EINVAL;
23 23
24 if ((ret = down_interruptible(&d->usb_sem))) 24 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
25 return ret; 25 return ret;
26 26
27 deb_xfer(">>> "); 27 deb_xfer(">>> ");
@@ -53,7 +53,7 @@ int dvb_usb_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf,
53 } 53 }
54 } 54 }
55 55
56 up(&d->usb_sem); 56 mutex_unlock(&d->usb_mutex);
57 return ret; 57 return ret;
58} 58}
59EXPORT_SYMBOL(dvb_usb_generic_rw); 59EXPORT_SYMBOL(dvb_usb_generic_rw);
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
index d4909e5c67e0..fead958a57e3 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -12,6 +12,7 @@
12#include <linux/input.h> 12#include <linux/input.h>
13#include <linux/usb.h> 13#include <linux/usb.h>
14#include <linux/firmware.h> 14#include <linux/firmware.h>
15#include <linux/mutex.h>
15 16
16#include "dvb_frontend.h" 17#include "dvb_frontend.h"
17#include "dvb_demux.h" 18#include "dvb_demux.h"
@@ -227,8 +228,8 @@ struct dvb_usb_properties {
227 * @feedcount: number of reqested feeds (used for streaming-activation) 228 * @feedcount: number of reqested feeds (used for streaming-activation)
228 * @pid_filtering: is hardware pid_filtering used or not. 229 * @pid_filtering: is hardware pid_filtering used or not.
229 * 230 *
230 * @usb_sem: semaphore of USB control messages (reading needs two messages) 231 * @usb_mutex: semaphore of USB control messages (reading needs two messages)
231 * @i2c_sem: semaphore for i2c-transfers 232 * @i2c_mutex: semaphore for i2c-transfers
232 * 233 *
233 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB 234 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
234 * @pll_addr: I2C address of the tuner for programming 235 * @pll_addr: I2C address of the tuner for programming
@@ -283,10 +284,10 @@ struct dvb_usb_device {
283 int pid_filtering; 284 int pid_filtering;
284 285
285 /* locking */ 286 /* locking */
286 struct semaphore usb_sem; 287 struct mutex usb_mutex;
287 288
288 /* i2c */ 289 /* i2c */
289 struct semaphore i2c_sem; 290 struct mutex i2c_mutex;
290 struct i2c_adapter i2c_adap; 291 struct i2c_adapter i2c_adap;
291 292
292 /* tuner programming information */ 293 /* tuner programming information */
diff --git a/drivers/media/dvb/dvb-usb/vp702x.c b/drivers/media/dvb/dvb-usb/vp702x.c
index 4a95eca81c5c..b2f098a2d5f7 100644
--- a/drivers/media/dvb/dvb-usb/vp702x.c
+++ b/drivers/media/dvb/dvb-usb/vp702x.c
@@ -75,7 +75,7 @@ int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int il
75{ 75{
76 int ret; 76 int ret;
77 77
78 if ((ret = down_interruptible(&d->usb_sem))) 78 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
79 return ret; 79 return ret;
80 80
81 if ((ret = vp702x_usb_out_op(d,REQUEST_OUT,0,0,o,olen)) < 0) 81 if ((ret = vp702x_usb_out_op(d,REQUEST_OUT,0,0,o,olen)) < 0)
@@ -84,7 +84,7 @@ int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int il
84 ret = vp702x_usb_in_op(d,REQUEST_IN,0,0,i,ilen); 84 ret = vp702x_usb_in_op(d,REQUEST_IN,0,0,i,ilen);
85 85
86unlock: 86unlock:
87 up(&d->usb_sem); 87 mutex_unlock(&d->usb_mutex);
88 88
89 return ret; 89 return ret;
90} 90}
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
index 3835235b68df..8ea3834a6cf8 100644
--- a/drivers/media/dvb/dvb-usb/vp7045.c
+++ b/drivers/media/dvb/dvb-usb/vp7045.c
@@ -38,7 +38,7 @@ int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in,
38 deb_xfer("out buffer: "); 38 deb_xfer("out buffer: ");
39 debug_dump(outbuf,outlen+1,deb_xfer); 39 debug_dump(outbuf,outlen+1,deb_xfer);
40 40
41 if ((ret = down_interruptible(&d->usb_sem))) 41 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
42 return ret; 42 return ret;
43 43
44 if (usb_control_msg(d->udev, 44 if (usb_control_msg(d->udev,
@@ -68,7 +68,7 @@ int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in,
68 memcpy(in,&inbuf[1],inlen); 68 memcpy(in,&inbuf[1],inlen);
69 69
70unlock: 70unlock:
71 up(&d->usb_sem); 71 mutex_unlock(&d->usb_mutex);
72 72
73 return ret; 73 return ret;
74} 74}
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index c676b1e23ab0..94233168d241 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -116,6 +116,12 @@ config DVB_MT352
116 help 116 help
117 A DVB-T tuner module. Say Y when you want to support this frontend. 117 A DVB-T tuner module. Say Y when you want to support this frontend.
118 118
119config DVB_ZL10353
120 tristate "Zarlink ZL10353 based"
121 depends on DVB_CORE
122 help
123 A DVB-T tuner module. Say Y when you want to support this frontend.
124
119config DVB_DIB3000MB 125config DVB_DIB3000MB
120 tristate "DiBcom 3000M-B" 126 tristate "DiBcom 3000M-B"
121 depends on DVB_CORE 127 depends on DVB_CORE
@@ -155,7 +161,7 @@ comment "ATSC (North American/Korean Terresterial DTV) frontends"
155 depends on DVB_CORE 161 depends on DVB_CORE
156 162
157config DVB_NXT200X 163config DVB_NXT200X
158 tristate "Nextwave NXT2002/NXT2004 based" 164 tristate "NxtWave Communications NXT2002/NXT2004 based"
159 depends on DVB_CORE 165 depends on DVB_CORE
160 select FW_LOADER 166 select FW_LOADER
161 help 167 help
@@ -169,14 +175,14 @@ config DVB_NXT200X
169 or /lib/firmware (depending on configuration of firmware hotplug). 175 or /lib/firmware (depending on configuration of firmware hotplug).
170 176
171config DVB_OR51211 177config DVB_OR51211
172 tristate "or51211 based (pcHDTV HD2000 card)" 178 tristate "Oren OR51211 based"
173 depends on DVB_CORE 179 depends on DVB_CORE
174 select FW_LOADER 180 select FW_LOADER
175 help 181 help
176 An ATSC 8VSB tuner module. Say Y when you want to support this frontend. 182 An ATSC 8VSB tuner module. Say Y when you want to support this frontend.
177 183
178config DVB_OR51132 184config DVB_OR51132
179 tristate "OR51132 based (pcHDTV HD3000 card)" 185 tristate "Oren OR51132 based"
180 depends on DVB_CORE 186 depends on DVB_CORE
181 select FW_LOADER 187 select FW_LOADER
182 help 188 help
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 1af769cd90c0..d09b6071fbaf 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_DVB_TDA1004X) += tda1004x.o
20obj-$(CONFIG_DVB_SP887X) += sp887x.o 20obj-$(CONFIG_DVB_SP887X) += sp887x.o
21obj-$(CONFIG_DVB_NXT6000) += nxt6000.o 21obj-$(CONFIG_DVB_NXT6000) += nxt6000.o
22obj-$(CONFIG_DVB_MT352) += mt352.o 22obj-$(CONFIG_DVB_MT352) += mt352.o
23obj-$(CONFIG_DVB_ZL10353) += zl10353.o
23obj-$(CONFIG_DVB_CX22702) += cx22702.o 24obj-$(CONFIG_DVB_CX22702) += cx22702.o
24obj-$(CONFIG_DVB_TDA10021) += tda10021.o 25obj-$(CONFIG_DVB_TDA10021) += tda10021.o
25obj-$(CONFIG_DVB_STV0297) += stv0297.o 26obj-$(CONFIG_DVB_STV0297) += stv0297.o
diff --git a/drivers/media/dvb/frontends/bcm3510.c b/drivers/media/dvb/frontends/bcm3510.c
index caaee893ca76..1708a1d4893e 100644
--- a/drivers/media/dvb/frontends/bcm3510.c
+++ b/drivers/media/dvb/frontends/bcm3510.c
@@ -39,6 +39,7 @@
39#include <linux/jiffies.h> 39#include <linux/jiffies.h>
40#include <linux/string.h> 40#include <linux/string.h>
41#include <linux/slab.h> 41#include <linux/slab.h>
42#include <linux/mutex.h>
42 43
43#include "dvb_frontend.h" 44#include "dvb_frontend.h"
44#include "bcm3510.h" 45#include "bcm3510.h"
@@ -52,7 +53,7 @@ struct bcm3510_state {
52 struct dvb_frontend frontend; 53 struct dvb_frontend frontend;
53 54
54 /* demodulator private data */ 55 /* demodulator private data */
55 struct semaphore hab_sem; 56 struct mutex hab_mutex;
56 u8 firmware_loaded:1; 57 u8 firmware_loaded:1;
57 58
58 unsigned long next_status_check; 59 unsigned long next_status_check;
@@ -213,7 +214,7 @@ static int bcm3510_do_hab_cmd(struct bcm3510_state *st, u8 cmd, u8 msgid, u8 *ob
213 dbufout(ob,olen+2,deb_hab); 214 dbufout(ob,olen+2,deb_hab);
214 deb_hab("\n"); 215 deb_hab("\n");
215 216
216 if (down_interruptible(&st->hab_sem) < 0) 217 if (mutex_lock_interruptible(&st->hab_mutex) < 0)
217 return -EAGAIN; 218 return -EAGAIN;
218 219
219 if ((ret = bcm3510_hab_send_request(st, ob, olen+2)) < 0 || 220 if ((ret = bcm3510_hab_send_request(st, ob, olen+2)) < 0 ||
@@ -226,7 +227,7 @@ static int bcm3510_do_hab_cmd(struct bcm3510_state *st, u8 cmd, u8 msgid, u8 *ob
226 227
227 memcpy(ibuf,&ib[2],ilen); 228 memcpy(ibuf,&ib[2],ilen);
228error: 229error:
229 up(&st->hab_sem); 230 mutex_unlock(&st->hab_mutex);
230 return ret; 231 return ret;
231} 232}
232 233
@@ -796,7 +797,7 @@ struct dvb_frontend* bcm3510_attach(const struct bcm3510_config *config,
796 state->frontend.ops = &state->ops; 797 state->frontend.ops = &state->ops;
797 state->frontend.demodulator_priv = state; 798 state->frontend.demodulator_priv = state;
798 799
799 sema_init(&state->hab_sem, 1); 800 mutex_init(&state->hab_mutex);
800 801
801 if ((ret = bcm3510_readB(state,0xe0,&v)) < 0) 802 if ((ret = bcm3510_readB(state,0xe0,&v)) < 0)
802 goto error; 803 goto error;
diff --git a/drivers/media/dvb/frontends/bsbe1.h b/drivers/media/dvb/frontends/bsbe1.h
new file mode 100644
index 000000000000..78573b22ada9
--- /dev/null
+++ b/drivers/media/dvb/frontends/bsbe1.h
@@ -0,0 +1,123 @@
1/*
2 * bsbe1.h - ALPS BSBE1 tuner support (moved from av7110.c)
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
20 *
21 *
22 * the project's page is at http://www.linuxtv.org
23 */
24
25#ifndef BSBE1_H
26#define BSBE1_H
27
28static u8 alps_bsbe1_inittab[] = {
29 0x01, 0x15,
30 0x02, 0x30,
31 0x03, 0x00,
32 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
33 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
34 0x06, 0x40, /* DAC not used, set to high impendance mode */
35 0x07, 0x00, /* DAC LSB */
36 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
37 0x09, 0x00, /* FIFO */
38 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
39 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
40 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
41 0x10, 0x3f, // AGC2 0x3d
42 0x11, 0x84,
43 0x12, 0xb9,
44 0x15, 0xc9, // lock detector threshold
45 0x16, 0x00,
46 0x17, 0x00,
47 0x18, 0x00,
48 0x19, 0x00,
49 0x1a, 0x00,
50 0x1f, 0x50,
51 0x20, 0x00,
52 0x21, 0x00,
53 0x22, 0x00,
54 0x23, 0x00,
55 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
56 0x29, 0x1e, // 1/2 threshold
57 0x2a, 0x14, // 2/3 threshold
58 0x2b, 0x0f, // 3/4 threshold
59 0x2c, 0x09, // 5/6 threshold
60 0x2d, 0x05, // 7/8 threshold
61 0x2e, 0x01,
62 0x31, 0x1f, // test all FECs
63 0x32, 0x19, // viterbi and synchro search
64 0x33, 0xfc, // rs control
65 0x34, 0x93, // error control
66 0x0f, 0x92,
67 0xff, 0xff
68};
69
70
71static int alps_bsbe1_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio)
72{
73 u8 aclk = 0;
74 u8 bclk = 0;
75
76 if (srate < 1500000) { aclk = 0xb7; bclk = 0x47; }
77 else if (srate < 3000000) { aclk = 0xb7; bclk = 0x4b; }
78 else if (srate < 7000000) { aclk = 0xb7; bclk = 0x4f; }
79 else if (srate < 14000000) { aclk = 0xb7; bclk = 0x53; }
80 else if (srate < 30000000) { aclk = 0xb6; bclk = 0x53; }
81 else if (srate < 45000000) { aclk = 0xb4; bclk = 0x51; }
82
83 stv0299_writereg(fe, 0x13, aclk);
84 stv0299_writereg(fe, 0x14, bclk);
85 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
86 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
87 stv0299_writereg(fe, 0x21, (ratio ) & 0xf0);
88
89 return 0;
90}
91
92static int alps_bsbe1_pll_set(struct dvb_frontend* fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters* params)
93{
94 int ret;
95 u8 data[4];
96 u32 div;
97 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
98
99 if ((params->frequency < 950000) || (params->frequency > 2150000))
100 return -EINVAL;
101
102 div = (params->frequency + (125 - 1)) / 125; // round correctly
103 data[0] = (div >> 8) & 0x7f;
104 data[1] = div & 0xff;
105 data[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
106 data[3] = (params->frequency > 1530000) ? 0xE0 : 0xE4;
107
108 ret = i2c_transfer(i2c, &msg, 1);
109 return (ret != 1) ? -EIO : 0;
110}
111
112static struct stv0299_config alps_bsbe1_config = {
113 .demod_address = 0x68,
114 .inittab = alps_bsbe1_inittab,
115 .mclk = 88000000UL,
116 .invert = 1,
117 .skip_reinit = 0,
118 .min_delay_ms = 100,
119 .set_symbol_rate = alps_bsbe1_set_symbol_rate,
120 .pll_set = alps_bsbe1_pll_set,
121};
122
123#endif
diff --git a/drivers/media/dvb/frontends/bsru6.h b/drivers/media/dvb/frontends/bsru6.h
new file mode 100644
index 000000000000..2a5366ce79cc
--- /dev/null
+++ b/drivers/media/dvb/frontends/bsru6.h
@@ -0,0 +1,140 @@
1/*
2 * bsru6.h - ALPS BSRU6 tuner support (moved from budget-ci.c)
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
20 *
21 *
22 * the project's page is at http://www.linuxtv.org
23 */
24
25#ifndef BSRU6_H
26#define BSRU6_H
27
28static u8 alps_bsru6_inittab[] = {
29 0x01, 0x15,
30 0x02, 0x00,
31 0x03, 0x00,
32 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
33 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
34 0x06, 0x40, /* DAC not used, set to high impendance mode */
35 0x07, 0x00, /* DAC LSB */
36 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
37 0x09, 0x00, /* FIFO */
38 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
39 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
40 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
41 0x10, 0x3f, // AGC2 0x3d
42 0x11, 0x84,
43 0x12, 0xb9,
44 0x15, 0xc9, // lock detector threshold
45 0x16, 0x00,
46 0x17, 0x00,
47 0x18, 0x00,
48 0x19, 0x00,
49 0x1a, 0x00,
50 0x1f, 0x50,
51 0x20, 0x00,
52 0x21, 0x00,
53 0x22, 0x00,
54 0x23, 0x00,
55 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
56 0x29, 0x1e, // 1/2 threshold
57 0x2a, 0x14, // 2/3 threshold
58 0x2b, 0x0f, // 3/4 threshold
59 0x2c, 0x09, // 5/6 threshold
60 0x2d, 0x05, // 7/8 threshold
61 0x2e, 0x01,
62 0x31, 0x1f, // test all FECs
63 0x32, 0x19, // viterbi and synchro search
64 0x33, 0xfc, // rs control
65 0x34, 0x93, // error control
66 0x0f, 0x52,
67 0xff, 0xff
68};
69
70static int alps_bsru6_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
71{
72 u8 aclk = 0;
73 u8 bclk = 0;
74
75 if (srate < 1500000) {
76 aclk = 0xb7;
77 bclk = 0x47;
78 } else if (srate < 3000000) {
79 aclk = 0xb7;
80 bclk = 0x4b;
81 } else if (srate < 7000000) {
82 aclk = 0xb7;
83 bclk = 0x4f;
84 } else if (srate < 14000000) {
85 aclk = 0xb7;
86 bclk = 0x53;
87 } else if (srate < 30000000) {
88 aclk = 0xb6;
89 bclk = 0x53;
90 } else if (srate < 45000000) {
91 aclk = 0xb4;
92 bclk = 0x51;
93 }
94
95 stv0299_writereg(fe, 0x13, aclk);
96 stv0299_writereg(fe, 0x14, bclk);
97 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
98 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
99 stv0299_writereg(fe, 0x21, ratio & 0xf0);
100
101 return 0;
102}
103
104static int alps_bsru6_pll_set(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters *params)
105{
106 u8 buf[4];
107 u32 div;
108 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
109
110 if ((params->frequency < 950000) || (params->frequency > 2150000))
111 return -EINVAL;
112
113 div = (params->frequency + (125 - 1)) / 125; // round correctly
114 buf[0] = (div >> 8) & 0x7f;
115 buf[1] = div & 0xff;
116 buf[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
117 buf[3] = 0xC4;
118
119 if (params->frequency > 1530000)
120 buf[3] = 0xc0;
121
122 if (i2c_transfer(i2c, &msg, 1) != 1)
123 return -EIO;
124 return 0;
125}
126
127static struct stv0299_config alps_bsru6_config = {
128 .demod_address = 0x68,
129 .inittab = alps_bsru6_inittab,
130 .mclk = 88000000UL,
131 .invert = 1,
132 .skip_reinit = 0,
133 .lock_output = STV0229_LOCKOUTPUT_1,
134 .volt13_op0_op1 = STV0299_VOLT13_OP1,
135 .min_delay_ms = 100,
136 .set_symbol_rate = alps_bsru6_set_symbol_rate,
137 .pll_set = alps_bsru6_pll_set,
138};
139
140#endif
diff --git a/drivers/media/dvb/frontends/cx24110.c b/drivers/media/dvb/frontends/cx24110.c
index d15d32c51dc5..f3edf8b517dd 100644
--- a/drivers/media/dvb/frontends/cx24110.c
+++ b/drivers/media/dvb/frontends/cx24110.c
@@ -371,6 +371,15 @@ static int cx24110_initfe(struct dvb_frontend* fe)
371 return 0; 371 return 0;
372} 372}
373 373
374static int cx24110_sleep(struct dvb_frontend *fe)
375{
376 struct cx24110_state *state = fe->demodulator_priv;
377
378 if (state->config->pll_sleep)
379 return state->config->pll_sleep(fe);
380 return 0;
381}
382
374static int cx24110_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage) 383static int cx24110_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage)
375{ 384{
376 struct cx24110_state *state = fe->demodulator_priv; 385 struct cx24110_state *state = fe->demodulator_priv;
@@ -418,6 +427,9 @@ static int cx24110_send_diseqc_msg(struct dvb_frontend* fe,
418 struct cx24110_state *state = fe->demodulator_priv; 427 struct cx24110_state *state = fe->demodulator_priv;
419 unsigned long timeout; 428 unsigned long timeout;
420 429
430 if (cmd->msg_len < 3 || cmd->msg_len > 6)
431 return -EINVAL; /* not implemented */
432
421 for (i = 0; i < cmd->msg_len; i++) 433 for (i = 0; i < cmd->msg_len; i++)
422 cx24110_writereg(state, 0x79 + i, cmd->msg[i]); 434 cx24110_writereg(state, 0x79 + i, cmd->msg[i]);
423 435
@@ -639,6 +651,7 @@ static struct dvb_frontend_ops cx24110_ops = {
639 .release = cx24110_release, 651 .release = cx24110_release,
640 652
641 .init = cx24110_initfe, 653 .init = cx24110_initfe,
654 .sleep = cx24110_sleep,
642 .set_frontend = cx24110_set_frontend, 655 .set_frontend = cx24110_set_frontend,
643 .get_frontend = cx24110_get_frontend, 656 .get_frontend = cx24110_get_frontend,
644 .read_status = cx24110_read_status, 657 .read_status = cx24110_read_status,
diff --git a/drivers/media/dvb/frontends/cx24110.h b/drivers/media/dvb/frontends/cx24110.h
index b63ecf26421a..609ac642b406 100644
--- a/drivers/media/dvb/frontends/cx24110.h
+++ b/drivers/media/dvb/frontends/cx24110.h
@@ -35,6 +35,7 @@ struct cx24110_config
35 /* PLL maintenance */ 35 /* PLL maintenance */
36 int (*pll_init)(struct dvb_frontend* fe); 36 int (*pll_init)(struct dvb_frontend* fe);
37 int (*pll_set)(struct dvb_frontend* fe, struct dvb_frontend_parameters* params); 37 int (*pll_set)(struct dvb_frontend* fe, struct dvb_frontend_parameters* params);
38 int (*pll_sleep)(struct dvb_frontend* fe);
38}; 39};
39 40
40extern struct dvb_frontend* cx24110_attach(const struct cx24110_config* config, 41extern struct dvb_frontend* cx24110_attach(const struct cx24110_config* config,
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c
index 4dcb6050d4fa..b6e2c387a04c 100644
--- a/drivers/media/dvb/frontends/dvb-pll.c
+++ b/drivers/media/dvb/frontends/dvb-pll.c
@@ -362,6 +362,63 @@ struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261 = {
362}; 362};
363EXPORT_SYMBOL(dvb_pll_philips_sd1878_tda8261); 363EXPORT_SYMBOL(dvb_pll_philips_sd1878_tda8261);
364 364
365/*
366 * Philips TD1316 Tuner.
367 */
368static void td1316_bw(u8 *buf, u32 freq, int bandwidth)
369{
370 u8 band;
371
372 /* determine band */
373 if (freq < 161000000)
374 band = 1;
375 else if (freq < 444000000)
376 band = 2;
377 else
378 band = 4;
379
380 buf[3] |= band;
381
382 /* setup PLL filter */
383 if (bandwidth == BANDWIDTH_8_MHZ)
384 buf[3] |= 1 << 3;
385}
386
387struct dvb_pll_desc dvb_pll_philips_td1316 = {
388 .name = "Philips TD1316",
389 .min = 87000000,
390 .max = 895000000,
391 .setbw = td1316_bw,
392 .count = 9,
393 .entries = {
394 { 93834000, 36166000, 166666, 0xca, 0x60},
395 { 123834000, 36166000, 166666, 0xca, 0xa0},
396 { 163834000, 36166000, 166666, 0xca, 0xc0},
397 { 253834000, 36166000, 166666, 0xca, 0x60},
398 { 383834000, 36166000, 166666, 0xca, 0xa0},
399 { 443834000, 36166000, 166666, 0xca, 0xc0},
400 { 583834000, 36166000, 166666, 0xca, 0x60},
401 { 793834000, 36166000, 166666, 0xca, 0xa0},
402 { 858834000, 36166000, 166666, 0xca, 0xe0},
403 },
404};
405EXPORT_SYMBOL(dvb_pll_philips_td1316);
406
407/* FE6600 used on DViCO Hybrid */
408struct dvb_pll_desc dvb_pll_thomson_fe6600 = {
409 .name = "Thomson FE6600",
410 .min = 44250000,
411 .max = 858000000,
412 .count = 4,
413 .entries = {
414 { 250000000, 36213333, 166667, 0xb4, 0x12 },
415 { 455000000, 36213333, 166667, 0xfe, 0x11 },
416 { 775500000, 36213333, 166667, 0xbc, 0x18 },
417 { 999999999, 36213333, 166667, 0xf4, 0x18 },
418 }
419};
420EXPORT_SYMBOL(dvb_pll_thomson_fe6600);
421
365/* ----------------------------------------------------------- */ 422/* ----------------------------------------------------------- */
366/* code */ 423/* code */
367 424
@@ -391,8 +448,8 @@ int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
391 div = (freq + desc->entries[i].offset) / desc->entries[i].stepsize; 448 div = (freq + desc->entries[i].offset) / desc->entries[i].stepsize;
392 buf[0] = div >> 8; 449 buf[0] = div >> 8;
393 buf[1] = div & 0xff; 450 buf[1] = div & 0xff;
394 buf[2] = desc->entries[i].cb1; 451 buf[2] = desc->entries[i].config;
395 buf[3] = desc->entries[i].cb2; 452 buf[3] = desc->entries[i].cb;
396 453
397 if (desc->setbw) 454 if (desc->setbw)
398 desc->setbw(buf, freq, bandwidth); 455 desc->setbw(buf, freq, bandwidth);
diff --git a/drivers/media/dvb/frontends/dvb-pll.h b/drivers/media/dvb/frontends/dvb-pll.h
index bb8d4b4eb183..2b8461784989 100644
--- a/drivers/media/dvb/frontends/dvb-pll.h
+++ b/drivers/media/dvb/frontends/dvb-pll.h
@@ -15,8 +15,8 @@ struct dvb_pll_desc {
15 u32 limit; 15 u32 limit;
16 u32 offset; 16 u32 offset;
17 u32 stepsize; 17 u32 stepsize;
18 u8 cb1; 18 u8 config;
19 u8 cb2; 19 u8 cb;
20 } entries[12]; 20 } entries[12];
21}; 21};
22 22
@@ -40,6 +40,9 @@ extern struct dvb_pll_desc dvb_pll_tuv1236d;
40extern struct dvb_pll_desc dvb_pll_tdhu2; 40extern struct dvb_pll_desc dvb_pll_tdhu2;
41extern struct dvb_pll_desc dvb_pll_samsung_tbmv; 41extern struct dvb_pll_desc dvb_pll_samsung_tbmv;
42extern struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261; 42extern struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261;
43extern struct dvb_pll_desc dvb_pll_philips_td1316;
44
45extern struct dvb_pll_desc dvb_pll_thomson_fe6600;
43 46
44int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf, 47int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
45 u32 freq, int bandwidth); 48 u32 freq, int bandwidth);
diff --git a/drivers/media/dvb/frontends/lnbp21.h b/drivers/media/dvb/frontends/lnbp21.h
new file mode 100644
index 000000000000..0dcbe61b61b1
--- /dev/null
+++ b/drivers/media/dvb/frontends/lnbp21.h
@@ -0,0 +1,139 @@
1/*
2 * lnbp21.h - driver for lnb supply and control ic lnbp21
3 *
4 * Copyright (C) 2006 Oliver Endriss
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 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
22 *
23 *
24 * the project's page is at http://www.linuxtv.org
25 */
26
27#ifndef _LNBP21_H
28#define _LNBP21_H
29
30/* system register */
31#define LNBP21_OLF 0x01
32#define LNBP21_OTF 0x02
33#define LNBP21_EN 0x04
34#define LNBP21_VSEL 0x08
35#define LNBP21_LLC 0x10
36#define LNBP21_TEN 0x20
37#define LNBP21_ISEL 0x40
38#define LNBP21_PCL 0x80
39
40struct lnbp21 {
41 u8 config;
42 u8 override_or;
43 u8 override_and;
44 struct i2c_adapter *i2c;
45 void (*release_chain)(struct dvb_frontend* fe);
46};
47
48static int lnbp21_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
49{
50 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->misc_priv;
51 struct i2c_msg msg = { .addr = 0x08, .flags = 0,
52 .buf = &lnbp21->config,
53 .len = sizeof(lnbp21->config) };
54
55 lnbp21->config &= ~(LNBP21_VSEL | LNBP21_EN);
56
57 switch(voltage) {
58 case SEC_VOLTAGE_OFF:
59 break;
60 case SEC_VOLTAGE_13:
61 lnbp21->config |= LNBP21_EN;
62 break;
63 case SEC_VOLTAGE_18:
64 lnbp21->config |= (LNBP21_EN | LNBP21_VSEL);
65 break;
66 default:
67 return -EINVAL;
68 };
69
70 lnbp21->config |= lnbp21->override_or;
71 lnbp21->config &= lnbp21->override_and;
72
73 return (i2c_transfer(lnbp21->i2c, &msg, 1) == 1) ? 0 : -EIO;
74}
75
76static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
77{
78 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->misc_priv;
79 struct i2c_msg msg = { .addr = 0x08, .flags = 0,
80 .buf = &lnbp21->config,
81 .len = sizeof(lnbp21->config) };
82
83 if (arg)
84 lnbp21->config |= LNBP21_LLC;
85 else
86 lnbp21->config &= ~LNBP21_LLC;
87
88 lnbp21->config |= lnbp21->override_or;
89 lnbp21->config &= lnbp21->override_and;
90
91 return (i2c_transfer(lnbp21->i2c, &msg, 1) == 1) ? 0 : -EIO;
92}
93
94static void lnbp21_exit(struct dvb_frontend *fe)
95{
96 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->misc_priv;
97
98 /* LNBP power off */
99 lnbp21_set_voltage(fe, SEC_VOLTAGE_OFF);
100
101 /* free data & call next release routine */
102 fe->ops->release = lnbp21->release_chain;
103 kfree(fe->misc_priv);
104 fe->misc_priv = NULL;
105 if (fe->ops->release)
106 fe->ops->release(fe);
107}
108
109static int lnbp21_init(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 override_set, u8 override_clear)
110{
111 struct lnbp21 *lnbp21 = kmalloc(sizeof(struct lnbp21), GFP_KERNEL);
112
113 if (!lnbp21)
114 return -ENOMEM;
115
116 /* default configuration */
117 lnbp21->config = LNBP21_ISEL;
118
119 /* bits which should be forced to '1' */
120 lnbp21->override_or = override_set;
121
122 /* bits which should be forced to '0' */
123 lnbp21->override_and = ~override_clear;
124
125 /* install release callback */
126 lnbp21->release_chain = fe->ops->release;
127 fe->ops->release = lnbp21_exit;
128
129 /* override frontend ops */
130 fe->ops->set_voltage = lnbp21_set_voltage;
131 fe->ops->enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage;
132
133 lnbp21->i2c = i2c;
134 fe->misc_priv = lnbp21;
135
136 return lnbp21_set_voltage(fe, SEC_VOLTAGE_OFF);
137}
138
139#endif
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c
index c63e9a5084eb..8e8df7b4ca0e 100644
--- a/drivers/media/dvb/frontends/tda1004x.c
+++ b/drivers/media/dvb/frontends/tda1004x.c
@@ -229,7 +229,7 @@ static int tda1004x_enable_tuner_i2c(struct tda1004x_state *state)
229 dprintk("%s\n", __FUNCTION__); 229 dprintk("%s\n", __FUNCTION__);
230 230
231 result = tda1004x_write_mask(state, TDA1004X_CONFC4, 2, 2); 231 result = tda1004x_write_mask(state, TDA1004X_CONFC4, 2, 2);
232 msleep(1); 232 msleep(20);
233 return result; 233 return result;
234} 234}
235 235
@@ -502,7 +502,12 @@ static int tda10046_fwupload(struct dvb_frontend* fe)
502 const struct firmware *fw; 502 const struct firmware *fw;
503 503
504 /* reset + wake up chip */ 504 /* reset + wake up chip */
505 tda1004x_write_byteI(state, TDA1004X_CONFC4, 0); 505 if (state->config->xtal_freq == TDA10046_XTAL_4M) {
506 tda1004x_write_byteI(state, TDA1004X_CONFC4, 0);
507 } else {
508 dprintk("%s: 16MHz Xtal, reducing I2C speed\n", __FUNCTION__);
509 tda1004x_write_byteI(state, TDA1004X_CONFC4, 0x80);
510 }
506 tda1004x_write_mask(state, TDA10046H_CONF_TRISTATE1, 1, 0); 511 tda1004x_write_mask(state, TDA10046H_CONF_TRISTATE1, 1, 0);
507 /* let the clocks recover from sleep */ 512 /* let the clocks recover from sleep */
508 msleep(5); 513 msleep(5);
@@ -651,7 +656,7 @@ static int tda10046_init(struct dvb_frontend* fe)
651 // tda setup 656 // tda setup
652 tda1004x_write_mask(state, TDA1004X_CONFC4, 0x20, 0); // disable DSP watchdog timer 657 tda1004x_write_mask(state, TDA1004X_CONFC4, 0x20, 0); // disable DSP watchdog timer
653 tda1004x_write_byteI(state, TDA1004X_AUTO, 0x87); // 100 ppm crystal, select HP stream 658 tda1004x_write_byteI(state, TDA1004X_AUTO, 0x87); // 100 ppm crystal, select HP stream
654 tda1004x_write_byteI(state, TDA1004X_CONFC1, 8); // disable pulse killer 659 tda1004x_write_byteI(state, TDA1004X_CONFC1, 0x88); // enable pulse killer
655 660
656 switch (state->config->agc_config) { 661 switch (state->config->agc_config) {
657 case TDA10046_AGC_DEFAULT: 662 case TDA10046_AGC_DEFAULT:
@@ -672,6 +677,12 @@ static int tda10046_init(struct dvb_frontend* fe)
672 tda1004x_write_byteI(state, TDA10046H_AGC_RENORM, 0x08); // Gain Renormalize 677 tda1004x_write_byteI(state, TDA10046H_AGC_RENORM, 0x08); // Gain Renormalize
673 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x6a); // set AGC polarities 678 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x6a); // set AGC polarities
674 break; 679 break;
680 case TDA10046_AGC_TDA827X_GPL:
681 tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x02); // AGC setup
682 tda1004x_write_byteI(state, TDA10046H_AGC_THR, 0x70); // AGC Threshold
683 tda1004x_write_byteI(state, TDA10046H_AGC_RENORM, 0x08); // Gain Renormalize
684 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x60); // set AGC polarities
685 break;
675 } 686 }
676 tda1004x_write_byteI(state, TDA1004X_CONFADC2, 0x38); 687 tda1004x_write_byteI(state, TDA1004X_CONFADC2, 0x38);
677 tda1004x_write_byteI(state, TDA10046H_CONF_TRISTATE1, 0x61); // Turn both AGC outputs on 688 tda1004x_write_byteI(state, TDA10046H_CONF_TRISTATE1, 0x61); // Turn both AGC outputs on
@@ -683,6 +694,7 @@ static int tda10046_init(struct dvb_frontend* fe)
683 tda1004x_write_byteI(state, TDA10046H_CVBER_CTRL, 0x1a); // 10^6 VBER measurement bits 694 tda1004x_write_byteI(state, TDA10046H_CVBER_CTRL, 0x1a); // 10^6 VBER measurement bits
684 tda1004x_write_byteI(state, TDA1004X_CONF_TS1, 7); // MPEG2 interface config 695 tda1004x_write_byteI(state, TDA1004X_CONF_TS1, 7); // MPEG2 interface config
685 tda1004x_write_byteI(state, TDA1004X_CONF_TS2, 0xc0); // MPEG2 interface config 696 tda1004x_write_byteI(state, TDA1004X_CONF_TS2, 0xc0); // MPEG2 interface config
697 // tda1004x_write_mask(state, 0x50, 0x80, 0x80); // handle out of guard echoes
686 tda1004x_write_mask(state, 0x3a, 0x80, state->config->invert_oclk << 7); 698 tda1004x_write_mask(state, 0x3a, 0x80, state->config->invert_oclk << 7);
687 699
688 state->initialised = 1; 700 state->initialised = 1;
@@ -1027,6 +1039,7 @@ static int tda1004x_read_status(struct dvb_frontend* fe, fe_status_t * fe_status
1027 if (status == -1) 1039 if (status == -1)
1028 return -EIO; 1040 return -EIO;
1029 cber |= (status << 8); 1041 cber |= (status << 8);
1042 // The address 0x20 should be read to cope with a TDA10046 bug
1030 tda1004x_read_byte(state, TDA1004X_CBER_RESET); 1043 tda1004x_read_byte(state, TDA1004X_CBER_RESET);
1031 1044
1032 if (cber != 65535) 1045 if (cber != 65535)
@@ -1047,7 +1060,8 @@ static int tda1004x_read_status(struct dvb_frontend* fe, fe_status_t * fe_status
1047 status = tda1004x_read_byte(state, TDA1004X_VBER_MSB); 1060 status = tda1004x_read_byte(state, TDA1004X_VBER_MSB);
1048 if (status == -1) 1061 if (status == -1)
1049 return -EIO; 1062 return -EIO;
1050 vber |= ((status << 16) & 0x0f); 1063 vber |= (status & 0x0f) << 16;
1064 // The CVBER_LUT should be read to cope with TDA10046 hardware bug
1051 tda1004x_read_byte(state, TDA1004X_CVBER_LUT); 1065 tda1004x_read_byte(state, TDA1004X_CVBER_LUT);
1052 1066
1053 // if RS has passed some valid TS packets, then we must be 1067 // if RS has passed some valid TS packets, then we must be
@@ -1161,6 +1175,7 @@ static int tda1004x_read_ber(struct dvb_frontend* fe, u32* ber)
1161 if (tmp < 0) 1175 if (tmp < 0)
1162 return -EIO; 1176 return -EIO;
1163 *ber |= (tmp << 9); 1177 *ber |= (tmp << 9);
1178 // The address 0x20 should be read to cope with a TDA10046 bug
1164 tda1004x_read_byte(state, TDA1004X_CBER_RESET); 1179 tda1004x_read_byte(state, TDA1004X_CBER_RESET);
1165 1180
1166 dprintk("%s: ber=0x%x\n", __FUNCTION__, *ber); 1181 dprintk("%s: ber=0x%x\n", __FUNCTION__, *ber);
@@ -1187,6 +1202,8 @@ static int tda1004x_sleep(struct dvb_frontend* fe)
1187 tda1004x_disable_tuner_i2c(state); 1202 tda1004x_disable_tuner_i2c(state);
1188 } 1203 }
1189 } 1204 }
1205 /* set outputs to tristate */
1206 tda1004x_write_byteI(state, TDA10046H_CONF_TRISTATE1, 0xff);
1190 tda1004x_write_mask(state, TDA1004X_CONFC4, 1, 1); 1207 tda1004x_write_mask(state, TDA1004X_CONFC4, 1, 1);
1191 break; 1208 break;
1192 } 1209 }
diff --git a/drivers/media/dvb/frontends/tda1004x.h b/drivers/media/dvb/frontends/tda1004x.h
index 8659c52647ad..cc0c4af64067 100644
--- a/drivers/media/dvb/frontends/tda1004x.h
+++ b/drivers/media/dvb/frontends/tda1004x.h
@@ -35,7 +35,8 @@ enum tda10046_agc {
35 TDA10046_AGC_DEFAULT, /* original configuration */ 35 TDA10046_AGC_DEFAULT, /* original configuration */
36 TDA10046_AGC_IFO_AUTO_NEG, /* IF AGC only, automatic, negtive */ 36 TDA10046_AGC_IFO_AUTO_NEG, /* IF AGC only, automatic, negtive */
37 TDA10046_AGC_IFO_AUTO_POS, /* IF AGC only, automatic, positive */ 37 TDA10046_AGC_IFO_AUTO_POS, /* IF AGC only, automatic, positive */
38 TDA10046_AGC_TDA827X, /* IF AGC only, special setup for tda827x */ 38 TDA10046_AGC_TDA827X, /* IF AGC only, special setup for tda827x */
39 TDA10046_AGC_TDA827X_GPL, /* same as above, but GPIOs 0 */
39}; 40};
40 41
41enum tda10046_if { 42enum tda10046_if {
diff --git a/drivers/media/dvb/frontends/zl10353.c b/drivers/media/dvb/frontends/zl10353.c
new file mode 100644
index 000000000000..d7d9f59d76d2
--- /dev/null
+++ b/drivers/media/dvb/frontends/zl10353.c
@@ -0,0 +1,311 @@
1/*
2 * Driver for Zarlink DVB-T ZL10353 demodulator
3 *
4 * Copyright (C) 2006 Christopher Pascoe <c.pascoe@itee.uq.edu.au>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/init.h>
26#include <linux/delay.h>
27#include <linux/string.h>
28#include <linux/slab.h>
29
30#include "dvb_frontend.h"
31#include "zl10353_priv.h"
32#include "zl10353.h"
33
34struct zl10353_state {
35 struct i2c_adapter *i2c;
36 struct dvb_frontend frontend;
37 struct dvb_frontend_ops ops;
38
39 struct zl10353_config config;
40};
41
42static int debug_regs = 0;
43
44static int zl10353_single_write(struct dvb_frontend *fe, u8 reg, u8 val)
45{
46 struct zl10353_state *state = fe->demodulator_priv;
47 u8 buf[2] = { reg, val };
48 struct i2c_msg msg = { .addr = state->config.demod_address, .flags = 0,
49 .buf = buf, .len = 2 };
50 int err = i2c_transfer(state->i2c, &msg, 1);
51 if (err != 1) {
52 printk("zl10353: write to reg %x failed (err = %d)!\n", reg, err);
53 return err;
54 }
55 return 0;
56}
57
58int zl10353_write(struct dvb_frontend *fe, u8 *ibuf, int ilen)
59{
60 int err, i;
61 for (i = 0; i < ilen - 1; i++)
62 if ((err = zl10353_single_write(fe, ibuf[0] + i, ibuf[i + 1])))
63 return err;
64
65 return 0;
66}
67
68static int zl10353_read_register(struct zl10353_state *state, u8 reg)
69{
70 int ret;
71 u8 b0[1] = { reg };
72 u8 b1[1] = { 0 };
73 struct i2c_msg msg[2] = { { .addr = state->config.demod_address,
74 .flags = 0,
75 .buf = b0, .len = 1 },
76 { .addr = state->config.demod_address,
77 .flags = I2C_M_RD,
78 .buf = b1, .len = 1 } };
79
80 ret = i2c_transfer(state->i2c, msg, 2);
81
82 if (ret != 2) {
83 printk("%s: readreg error (reg=%d, ret==%i)\n",
84 __FUNCTION__, reg, ret);
85 return ret;
86 }
87
88 return b1[0];
89}
90
91static void zl10353_dump_regs(struct dvb_frontend *fe)
92{
93 struct zl10353_state *state = fe->demodulator_priv;
94 char buf[52], buf2[4];
95 int ret;
96 u8 reg;
97
98 /* Dump all registers. */
99 for (reg = 0; ; reg++) {
100 if (reg % 16 == 0) {
101 if (reg)
102 printk(KERN_DEBUG "%s\n", buf);
103 sprintf(buf, "%02x: ", reg);
104 }
105 ret = zl10353_read_register(state, reg);
106 if (ret >= 0)
107 sprintf(buf2, "%02x ", (u8)ret);
108 else
109 strcpy(buf2, "-- ");
110 strcat(buf, buf2);
111 if (reg == 0xff)
112 break;
113 }
114 printk(KERN_DEBUG "%s\n", buf);
115}
116
117static int zl10353_sleep(struct dvb_frontend *fe)
118{
119 static u8 zl10353_softdown[] = { 0x50, 0x0C, 0x44 };
120
121 zl10353_write(fe, zl10353_softdown, sizeof(zl10353_softdown));
122 return 0;
123}
124
125static int zl10353_set_parameters(struct dvb_frontend *fe,
126 struct dvb_frontend_parameters *param)
127{
128 struct zl10353_state *state = fe->demodulator_priv;
129 u8 pllbuf[6] = { 0x67 };
130
131 /* These settings set "auto-everything" and start the FSM. */
132 zl10353_single_write(fe, 0x55, 0x80);
133 udelay(200);
134 zl10353_single_write(fe, 0xEA, 0x01);
135 udelay(200);
136 zl10353_single_write(fe, 0xEA, 0x00);
137
138 zl10353_single_write(fe, 0x56, 0x28);
139 zl10353_single_write(fe, 0x89, 0x20);
140 zl10353_single_write(fe, 0x5E, 0x00);
141 zl10353_single_write(fe, 0x65, 0x5A);
142 zl10353_single_write(fe, 0x66, 0xE9);
143 zl10353_single_write(fe, 0x62, 0x0A);
144
145 state->config.pll_set(fe, param, pllbuf + 1);
146 zl10353_write(fe, pllbuf, sizeof(pllbuf));
147
148 zl10353_single_write(fe, 0x70, 0x01);
149 udelay(250);
150 zl10353_single_write(fe, 0xE4, 0x00);
151 zl10353_single_write(fe, 0xE5, 0x2A);
152 zl10353_single_write(fe, 0xE9, 0x02);
153 zl10353_single_write(fe, 0xE7, 0x40);
154 zl10353_single_write(fe, 0xE8, 0x10);
155
156 return 0;
157}
158
159static int zl10353_read_status(struct dvb_frontend *fe, fe_status_t *status)
160{
161 struct zl10353_state *state = fe->demodulator_priv;
162 int s6, s7, s8;
163
164 if ((s6 = zl10353_read_register(state, STATUS_6)) < 0)
165 return -EREMOTEIO;
166 if ((s7 = zl10353_read_register(state, STATUS_7)) < 0)
167 return -EREMOTEIO;
168 if ((s8 = zl10353_read_register(state, STATUS_8)) < 0)
169 return -EREMOTEIO;
170
171 *status = 0;
172 if (s6 & (1 << 2))
173 *status |= FE_HAS_CARRIER;
174 if (s6 & (1 << 1))
175 *status |= FE_HAS_VITERBI;
176 if (s6 & (1 << 5))
177 *status |= FE_HAS_LOCK;
178 if (s7 & (1 << 4))
179 *status |= FE_HAS_SYNC;
180 if (s8 & (1 << 6))
181 *status |= FE_HAS_SIGNAL;
182
183 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
184 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
185 *status &= ~FE_HAS_LOCK;
186
187 return 0;
188}
189
190static int zl10353_read_snr(struct dvb_frontend *fe, u16 *snr)
191{
192 struct zl10353_state *state = fe->demodulator_priv;
193 u8 _snr;
194
195 if (debug_regs)
196 zl10353_dump_regs(fe);
197
198 _snr = zl10353_read_register(state, SNR);
199 *snr = (_snr << 8) | _snr;
200
201 return 0;
202}
203
204static int zl10353_get_tune_settings(struct dvb_frontend *fe,
205 struct dvb_frontend_tune_settings
206 *fe_tune_settings)
207{
208 fe_tune_settings->min_delay_ms = 1000;
209 fe_tune_settings->step_size = 0;
210 fe_tune_settings->max_drift = 0;
211
212 return 0;
213}
214
215static int zl10353_init(struct dvb_frontend *fe)
216{
217 struct zl10353_state *state = fe->demodulator_priv;
218 u8 zl10353_reset_attach[6] = { 0x50, 0x03, 0x64, 0x46, 0x15, 0x0F };
219 int rc = 0;
220
221 if (debug_regs)
222 zl10353_dump_regs(fe);
223
224 /* Do a "hard" reset if not already done */
225 if (zl10353_read_register(state, 0x50) != 0x03) {
226 rc = zl10353_write(fe, zl10353_reset_attach,
227 sizeof(zl10353_reset_attach));
228 if (debug_regs)
229 zl10353_dump_regs(fe);
230 }
231
232 return 0;
233}
234
235static void zl10353_release(struct dvb_frontend *fe)
236{
237 struct zl10353_state *state = fe->demodulator_priv;
238
239 kfree(state);
240}
241
242static struct dvb_frontend_ops zl10353_ops;
243
244struct dvb_frontend *zl10353_attach(const struct zl10353_config *config,
245 struct i2c_adapter *i2c)
246{
247 struct zl10353_state *state = NULL;
248
249 /* allocate memory for the internal state */
250 state = kzalloc(sizeof(struct zl10353_state), GFP_KERNEL);
251 if (state == NULL)
252 goto error;
253
254 /* setup the state */
255 state->i2c = i2c;
256 memcpy(&state->config, config, sizeof(struct zl10353_config));
257 memcpy(&state->ops, &zl10353_ops, sizeof(struct dvb_frontend_ops));
258
259 /* check if the demod is there */
260 if (zl10353_read_register(state, CHIP_ID) != ID_ZL10353)
261 goto error;
262
263 /* create dvb_frontend */
264 state->frontend.ops = &state->ops;
265 state->frontend.demodulator_priv = state;
266
267 return &state->frontend;
268error:
269 kfree(state);
270 return NULL;
271}
272
273static struct dvb_frontend_ops zl10353_ops = {
274
275 .info = {
276 .name = "Zarlink ZL10353 DVB-T",
277 .type = FE_OFDM,
278 .frequency_min = 174000000,
279 .frequency_max = 862000000,
280 .frequency_stepsize = 166667,
281 .frequency_tolerance = 0,
282 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
283 FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
284 FE_CAN_FEC_AUTO |
285 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
286 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
287 FE_CAN_HIERARCHY_AUTO | FE_CAN_RECOVER |
288 FE_CAN_MUTE_TS
289 },
290
291 .release = zl10353_release,
292
293 .init = zl10353_init,
294 .sleep = zl10353_sleep,
295
296 .set_frontend = zl10353_set_parameters,
297 .get_tune_settings = zl10353_get_tune_settings,
298
299 .read_status = zl10353_read_status,
300 .read_snr = zl10353_read_snr,
301};
302
303module_param(debug_regs, int, 0644);
304MODULE_PARM_DESC(debug_regs, "Turn on/off frontend register dumps (default:off).");
305
306MODULE_DESCRIPTION("Zarlink ZL10353 DVB-T demodulator driver");
307MODULE_AUTHOR("Chris Pascoe");
308MODULE_LICENSE("GPL");
309
310EXPORT_SYMBOL(zl10353_attach);
311EXPORT_SYMBOL(zl10353_write);
diff --git a/drivers/media/dvb/frontends/zl10353.h b/drivers/media/dvb/frontends/zl10353.h
new file mode 100644
index 000000000000..5cc4ae718d8c
--- /dev/null
+++ b/drivers/media/dvb/frontends/zl10353.h
@@ -0,0 +1,43 @@
1/*
2 * Driver for Zarlink DVB-T ZL10353 demodulator
3 *
4 * Copyright (C) 2006 Christopher Pascoe <c.pascoe@itee.uq.edu.au>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
20 */
21
22#ifndef ZL10353_H
23#define ZL10353_H
24
25#include <linux/dvb/frontend.h>
26
27struct zl10353_config
28{
29 /* demodulator's I2C address */
30 u8 demod_address;
31
32 /* function which configures the PLL buffer (for secondary I2C
33 * connected tuner) or tunes the PLL (for direct connected tuner) */
34 int (*pll_set)(struct dvb_frontend *fe,
35 struct dvb_frontend_parameters *params, u8 *pllbuf);
36};
37
38extern struct dvb_frontend* zl10353_attach(const struct zl10353_config *config,
39 struct i2c_adapter *i2c);
40
41extern int zl10353_write(struct dvb_frontend *fe, u8 *ibuf, int ilen);
42
43#endif /* ZL10353_H */
diff --git a/drivers/media/dvb/frontends/zl10353_priv.h b/drivers/media/dvb/frontends/zl10353_priv.h
new file mode 100644
index 000000000000..b72224bd7dde
--- /dev/null
+++ b/drivers/media/dvb/frontends/zl10353_priv.h
@@ -0,0 +1,42 @@
1/*
2 * Driver for Zarlink DVB-T ZL10353 demodulator
3 *
4 * Copyright (C) 2006 Christopher Pascoe <c.pascoe@itee.uq.edu.au>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
20 */
21
22#ifndef _ZL10353_PRIV_
23#define _ZL10353_PRIV_
24
25#define ID_ZL10353 0x14
26
27enum zl10353_reg_addr {
28 INTERRUPT_0 = 0x00,
29 INTERRUPT_1 = 0x01,
30 INTERRUPT_2 = 0x02,
31 INTERRUPT_3 = 0x03,
32 INTERRUPT_4 = 0x04,
33 INTERRUPT_5 = 0x05,
34 STATUS_6 = 0x06,
35 STATUS_7 = 0x07,
36 STATUS_8 = 0x08,
37 STATUS_9 = 0x09,
38 SNR = 0x10,
39 CHIP_ID = 0x7F,
40};
41
42#endif /* _ZL10353_PRIV_ */
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 7c6ccb96b157..840efec32cb6 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -54,7 +54,6 @@
54#include <linux/i2c.h> 54#include <linux/i2c.h>
55 55
56#include <asm/system.h> 56#include <asm/system.h>
57#include <asm/semaphore.h>
58 57
59#include <linux/dvb/frontend.h> 58#include <linux/dvb/frontend.h>
60 59
@@ -67,6 +66,10 @@
67#include "av7110_ca.h" 66#include "av7110_ca.h"
68#include "av7110_ipack.h" 67#include "av7110_ipack.h"
69 68
69#include "bsbe1.h"
70#include "lnbp21.h"
71#include "bsru6.h"
72
70#define TS_WIDTH 376 73#define TS_WIDTH 376
71#define TS_HEIGHT 512 74#define TS_HEIGHT 512
72#define TS_BUFLEN (TS_WIDTH*TS_HEIGHT) 75#define TS_BUFLEN (TS_WIDTH*TS_HEIGHT)
@@ -82,6 +85,8 @@ static int hw_sections;
82static int rgb_on; 85static int rgb_on;
83static int volume = 255; 86static int volume = 255;
84static int budgetpatch; 87static int budgetpatch;
88static int wss_cfg_4_3 = 0x4008;
89static int wss_cfg_16_9 = 0x0007;
85 90
86module_param_named(debug, av7110_debug, int, 0644); 91module_param_named(debug, av7110_debug, int, 0644);
87MODULE_PARM_DESC(debug, "debug level (bitmask, default 0)"); 92MODULE_PARM_DESC(debug, "debug level (bitmask, default 0)");
@@ -100,6 +105,10 @@ module_param(volume, int, 0444);
100MODULE_PARM_DESC(volume, "initial volume: default 255 (range 0-255)"); 105MODULE_PARM_DESC(volume, "initial volume: default 255 (range 0-255)");
101module_param(budgetpatch, int, 0444); 106module_param(budgetpatch, int, 0444);
102MODULE_PARM_DESC(budgetpatch, "use budget-patch hardware modification: default 0 (0 no, 1 autodetect, 2 always)"); 107MODULE_PARM_DESC(budgetpatch, "use budget-patch hardware modification: default 0 (0 no, 1 autodetect, 2 always)");
108module_param(wss_cfg_4_3, int, 0444);
109MODULE_PARM_DESC(wss_cfg_4_3, "WSS 4:3 - default 0x4008 - bit 15: disable, 14: burst mode, 13..0: wss data");
110module_param(wss_cfg_16_9, int, 0444);
111MODULE_PARM_DESC(wss_cfg_16_9, "WSS 16:9 - default 0x0007 - bit 15: disable, 14: burst mode, 13..0: wss data");
103 112
104static void restart_feeds(struct av7110 *av7110); 113static void restart_feeds(struct av7110 *av7110);
105 114
@@ -125,6 +134,13 @@ static void init_av7110_av(struct av7110 *av7110)
125 if (ret < 0) 134 if (ret < 0)
126 printk("dvb-ttpci:cannot set internal volume to maximum:%d\n",ret); 135 printk("dvb-ttpci:cannot set internal volume to maximum:%d\n",ret);
127 136
137 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetWSSConfig, 2, 2, wss_cfg_4_3);
138 if (ret < 0)
139 printk("dvb-ttpci: unable to configure 4:3 wss\n");
140 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetWSSConfig, 2, 3, wss_cfg_16_9);
141 if (ret < 0)
142 printk("dvb-ttpci: unable to configure 16:9 wss\n");
143
128 ret = av7710_set_video_mode(av7110, vidmode); 144 ret = av7710_set_video_mode(av7110, vidmode);
129 if (ret < 0) 145 if (ret < 0)
130 printk("dvb-ttpci:cannot set video mode:%d\n",ret); 146 printk("dvb-ttpci:cannot set video mode:%d\n",ret);
@@ -242,10 +258,10 @@ static int arm_thread(void *data)
242 if (!av7110->arm_ready) 258 if (!av7110->arm_ready)
243 continue; 259 continue;
244 260
245 if (down_interruptible(&av7110->dcomlock)) 261 if (mutex_lock_interruptible(&av7110->dcomlock))
246 break; 262 break;
247 newloops = rdebi(av7110, DEBINOSWAP, STATUS_LOOPS, 0, 2); 263 newloops = rdebi(av7110, DEBINOSWAP, STATUS_LOOPS, 0, 2);
248 up(&av7110->dcomlock); 264 mutex_unlock(&av7110->dcomlock);
249 265
250 if (newloops == av7110->arm_loops || av7110->arm_errors > 3) { 266 if (newloops == av7110->arm_loops || av7110->arm_errors > 3) {
251 printk(KERN_ERR "dvb-ttpci: ARM crashed @ card %d\n", 267 printk(KERN_ERR "dvb-ttpci: ARM crashed @ card %d\n",
@@ -253,10 +269,10 @@ static int arm_thread(void *data)
253 269
254 recover_arm(av7110); 270 recover_arm(av7110);
255 271
256 if (down_interruptible(&av7110->dcomlock)) 272 if (mutex_lock_interruptible(&av7110->dcomlock))
257 break; 273 break;
258 newloops = rdebi(av7110, DEBINOSWAP, STATUS_LOOPS, 0, 2) - 1; 274 newloops = rdebi(av7110, DEBINOSWAP, STATUS_LOOPS, 0, 2) - 1;
259 up(&av7110->dcomlock); 275 mutex_unlock(&av7110->dcomlock);
260 } 276 }
261 av7110->arm_loops = newloops; 277 av7110->arm_loops = newloops;
262 av7110->arm_errors = 0; 278 av7110->arm_errors = 0;
@@ -741,7 +757,7 @@ int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
741 int ret = 0; 757 int ret = 0;
742 dprintk(4, "%p\n", av7110); 758 dprintk(4, "%p\n", av7110);
743 759
744 if (down_interruptible(&av7110->pid_mutex)) 760 if (mutex_lock_interruptible(&av7110->pid_mutex))
745 return -ERESTARTSYS; 761 return -ERESTARTSYS;
746 762
747 if (!(vpid & 0x8000)) 763 if (!(vpid & 0x8000))
@@ -760,7 +776,7 @@ int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
760 ret = SetPIDs(av7110, vpid, apid, ttpid, subpid, pcrpid); 776 ret = SetPIDs(av7110, vpid, apid, ttpid, subpid, pcrpid);
761 } 777 }
762 778
763 up(&av7110->pid_mutex); 779 mutex_unlock(&av7110->pid_mutex);
764 return ret; 780 return ret;
765} 781}
766 782
@@ -1088,11 +1104,9 @@ static int dvb_get_stc(struct dmx_demux *demux, unsigned int num,
1088 struct av7110 *av7110; 1104 struct av7110 *av7110;
1089 1105
1090 /* pointer casting paranoia... */ 1106 /* pointer casting paranoia... */
1091 if (!demux) 1107 BUG_ON(!demux);
1092 BUG();
1093 dvbdemux = (struct dvb_demux *) demux->priv; 1108 dvbdemux = (struct dvb_demux *) demux->priv;
1094 if (!dvbdemux) 1109 BUG_ON(!dvbdemux);
1095 BUG();
1096 av7110 = (struct av7110 *) dvbdemux->priv; 1110 av7110 = (struct av7110 *) dvbdemux->priv;
1097 1111
1098 dprintk(4, "%p\n", av7110); 1112 dprintk(4, "%p\n", av7110);
@@ -1570,208 +1584,6 @@ static struct ves1x93_config alps_bsrv2_config = {
1570 .pll_set = alps_bsrv2_pll_set, 1584 .pll_set = alps_bsrv2_pll_set,
1571}; 1585};
1572 1586
1573
1574static u8 alps_bsru6_inittab[] = {
1575 0x01, 0x15,
1576 0x02, 0x30,
1577 0x03, 0x00,
1578 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
1579 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
1580 0x06, 0x40, /* DAC not used, set to high impendance mode */
1581 0x07, 0x00, /* DAC LSB */
1582 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
1583 0x09, 0x00, /* FIFO */
1584 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
1585 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
1586 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
1587 0x10, 0x3f, // AGC2 0x3d
1588 0x11, 0x84,
1589 0x12, 0xb9,
1590 0x15, 0xc9, // lock detector threshold
1591 0x16, 0x00,
1592 0x17, 0x00,
1593 0x18, 0x00,
1594 0x19, 0x00,
1595 0x1a, 0x00,
1596 0x1f, 0x50,
1597 0x20, 0x00,
1598 0x21, 0x00,
1599 0x22, 0x00,
1600 0x23, 0x00,
1601 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
1602 0x29, 0x1e, // 1/2 threshold
1603 0x2a, 0x14, // 2/3 threshold
1604 0x2b, 0x0f, // 3/4 threshold
1605 0x2c, 0x09, // 5/6 threshold
1606 0x2d, 0x05, // 7/8 threshold
1607 0x2e, 0x01,
1608 0x31, 0x1f, // test all FECs
1609 0x32, 0x19, // viterbi and synchro search
1610 0x33, 0xfc, // rs control
1611 0x34, 0x93, // error control
1612 0x0f, 0x52,
1613 0xff, 0xff
1614};
1615
1616static int alps_bsru6_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio)
1617{
1618 u8 aclk = 0;
1619 u8 bclk = 0;
1620
1621 if (srate < 1500000) { aclk = 0xb7; bclk = 0x47; }
1622 else if (srate < 3000000) { aclk = 0xb7; bclk = 0x4b; }
1623 else if (srate < 7000000) { aclk = 0xb7; bclk = 0x4f; }
1624 else if (srate < 14000000) { aclk = 0xb7; bclk = 0x53; }
1625 else if (srate < 30000000) { aclk = 0xb6; bclk = 0x53; }
1626 else if (srate < 45000000) { aclk = 0xb4; bclk = 0x51; }
1627
1628 stv0299_writereg(fe, 0x13, aclk);
1629 stv0299_writereg(fe, 0x14, bclk);
1630 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
1631 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
1632 stv0299_writereg(fe, 0x21, (ratio ) & 0xf0);
1633
1634 return 0;
1635}
1636
1637static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters* params)
1638{
1639 int ret;
1640 u8 data[4];
1641 u32 div;
1642 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
1643
1644 if ((params->frequency < 950000) || (params->frequency > 2150000))
1645 return -EINVAL;
1646
1647 div = (params->frequency + (125 - 1)) / 125; // round correctly
1648 data[0] = (div >> 8) & 0x7f;
1649 data[1] = div & 0xff;
1650 data[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
1651 data[3] = 0xC4;
1652
1653 if (params->frequency > 1530000) data[3] = 0xc0;
1654
1655 ret = i2c_transfer(i2c, &msg, 1);
1656 if (ret != 1)
1657 return -EIO;
1658 return 0;
1659}
1660
1661static struct stv0299_config alps_bsru6_config = {
1662
1663 .demod_address = 0x68,
1664 .inittab = alps_bsru6_inittab,
1665 .mclk = 88000000UL,
1666 .invert = 1,
1667 .skip_reinit = 0,
1668 .lock_output = STV0229_LOCKOUTPUT_1,
1669 .volt13_op0_op1 = STV0299_VOLT13_OP1,
1670 .min_delay_ms = 100,
1671 .set_symbol_rate = alps_bsru6_set_symbol_rate,
1672 .pll_set = alps_bsru6_pll_set,
1673};
1674
1675
1676static u8 alps_bsbe1_inittab[] = {
1677 0x01, 0x15,
1678 0x02, 0x30,
1679 0x03, 0x00,
1680 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
1681 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
1682 0x06, 0x40, /* DAC not used, set to high impendance mode */
1683 0x07, 0x00, /* DAC LSB */
1684 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
1685 0x09, 0x00, /* FIFO */
1686 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
1687 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
1688 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
1689 0x10, 0x3f, // AGC2 0x3d
1690 0x11, 0x84,
1691 0x12, 0xb9,
1692 0x15, 0xc9, // lock detector threshold
1693 0x16, 0x00,
1694 0x17, 0x00,
1695 0x18, 0x00,
1696 0x19, 0x00,
1697 0x1a, 0x00,
1698 0x1f, 0x50,
1699 0x20, 0x00,
1700 0x21, 0x00,
1701 0x22, 0x00,
1702 0x23, 0x00,
1703 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
1704 0x29, 0x1e, // 1/2 threshold
1705 0x2a, 0x14, // 2/3 threshold
1706 0x2b, 0x0f, // 3/4 threshold
1707 0x2c, 0x09, // 5/6 threshold
1708 0x2d, 0x05, // 7/8 threshold
1709 0x2e, 0x01,
1710 0x31, 0x1f, // test all FECs
1711 0x32, 0x19, // viterbi and synchro search
1712 0x33, 0xfc, // rs control
1713 0x34, 0x93, // error control
1714 0x0f, 0x92,
1715 0xff, 0xff
1716};
1717
1718static int alps_bsbe1_pll_set(struct dvb_frontend* fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters* params)
1719{
1720 int ret;
1721 u8 data[4];
1722 u32 div;
1723 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
1724
1725 if ((params->frequency < 950000) || (params->frequency > 2150000))
1726 return -EINVAL;
1727
1728 div = (params->frequency + (125 - 1)) / 125; // round correctly
1729 data[0] = (div >> 8) & 0x7f;
1730 data[1] = div & 0xff;
1731 data[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
1732 data[3] = (params->frequency > 1530000) ? 0xE0 : 0xE4;
1733
1734 ret = i2c_transfer(i2c, &msg, 1);
1735 return (ret != 1) ? -EIO : 0;
1736}
1737
1738static struct stv0299_config alps_bsbe1_config = {
1739 .demod_address = 0x68,
1740 .inittab = alps_bsbe1_inittab,
1741 .mclk = 88000000UL,
1742 .invert = 1,
1743 .skip_reinit = 0,
1744 .min_delay_ms = 100,
1745 .set_symbol_rate = alps_bsru6_set_symbol_rate,
1746 .pll_set = alps_bsbe1_pll_set,
1747};
1748
1749static int lnbp21_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
1750{
1751 struct av7110* av7110 = (struct av7110*) fe->dvb->priv;
1752 int ret;
1753 u8 data[1];
1754 struct i2c_msg msg = { .addr = 0x08, .flags = 0, .buf = data, .len = sizeof(data) };
1755
1756 switch(voltage) {
1757 case SEC_VOLTAGE_OFF:
1758 data[0] = 0x00;
1759 break;
1760 case SEC_VOLTAGE_13:
1761 data[0] = 0x44;
1762 break;
1763 case SEC_VOLTAGE_18:
1764 data[0] = 0x4c;
1765 break;
1766 default:
1767 return -EINVAL;
1768 };
1769
1770 ret = i2c_transfer(&av7110->i2c_adap, &msg, 1);
1771 return (ret != 1) ? -EIO : 0;
1772}
1773
1774
1775static int alps_tdbe2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 1587static int alps_tdbe2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
1776{ 1588{
1777 struct av7110* av7110 = fe->dvb->priv; 1589 struct av7110* av7110 = fe->dvb->priv;
@@ -2096,7 +1908,7 @@ static int av7110_fe_lock_fix(struct av7110* av7110, fe_status_t status)
2096 if (av7110->playing) 1908 if (av7110->playing)
2097 return 0; 1909 return 0;
2098 1910
2099 if (down_interruptible(&av7110->pid_mutex)) 1911 if (mutex_lock_interruptible(&av7110->pid_mutex))
2100 return -ERESTARTSYS; 1912 return -ERESTARTSYS;
2101 1913
2102 if (synced) { 1914 if (synced) {
@@ -2118,7 +1930,7 @@ static int av7110_fe_lock_fix(struct av7110* av7110, fe_status_t status)
2118 if (!ret) 1930 if (!ret)
2119 av7110->fe_synced = synced; 1931 av7110->fe_synced = synced;
2120 1932
2121 up(&av7110->pid_mutex); 1933 mutex_unlock(&av7110->pid_mutex);
2122 return ret; 1934 return ret;
2123} 1935}
2124 1936
@@ -2374,9 +2186,15 @@ static int frontend_init(struct av7110 *av7110)
2374 /* ALPS BSBE1 */ 2186 /* ALPS BSBE1 */
2375 av7110->fe = stv0299_attach(&alps_bsbe1_config, &av7110->i2c_adap); 2187 av7110->fe = stv0299_attach(&alps_bsbe1_config, &av7110->i2c_adap);
2376 if (av7110->fe) { 2188 if (av7110->fe) {
2377 av7110->fe->ops->set_voltage = lnbp21_set_voltage; 2189 if (lnbp21_init(av7110->fe, &av7110->i2c_adap, 0, 0)) {
2378 av7110->fe->ops->dishnetwork_send_legacy_command = NULL; 2190 printk("dvb-ttpci: LNBP21 not found!\n");
2379 av7110->recover = dvb_s_recover; 2191 if (av7110->fe->ops->release)
2192 av7110->fe->ops->release(av7110->fe);
2193 av7110->fe = NULL;
2194 } else {
2195 av7110->fe->ops->dishnetwork_send_legacy_command = NULL;
2196 av7110->recover = dvb_s_recover;
2197 }
2380 } 2198 }
2381 break; 2199 break;
2382 } 2200 }
@@ -2714,16 +2532,16 @@ static int __devinit av7110_attach(struct saa7146_dev* dev,
2714 tasklet_init (&av7110->debi_tasklet, debiirq, (unsigned long) av7110); 2532 tasklet_init (&av7110->debi_tasklet, debiirq, (unsigned long) av7110);
2715 tasklet_init (&av7110->gpio_tasklet, gpioirq, (unsigned long) av7110); 2533 tasklet_init (&av7110->gpio_tasklet, gpioirq, (unsigned long) av7110);
2716 2534
2717 sema_init(&av7110->pid_mutex, 1); 2535 mutex_init(&av7110->pid_mutex);
2718 2536
2719 /* locks for data transfers from/to AV7110 */ 2537 /* locks for data transfers from/to AV7110 */
2720 spin_lock_init(&av7110->debilock); 2538 spin_lock_init(&av7110->debilock);
2721 sema_init(&av7110->dcomlock, 1); 2539 mutex_init(&av7110->dcomlock);
2722 av7110->debitype = -1; 2540 av7110->debitype = -1;
2723 2541
2724 /* default OSD window */ 2542 /* default OSD window */
2725 av7110->osdwin = 1; 2543 av7110->osdwin = 1;
2726 sema_init(&av7110->osd_sema, 1); 2544 mutex_init(&av7110->osd_mutex);
2727 2545
2728 /* ARM "watchdog" */ 2546 /* ARM "watchdog" */
2729 init_waitqueue_head(&av7110->arm_wait); 2547 init_waitqueue_head(&av7110->arm_wait);
diff --git a/drivers/media/dvb/ttpci/av7110.h b/drivers/media/dvb/ttpci/av7110.h
index fafd25fab835..3e2e12124bae 100644
--- a/drivers/media/dvb/ttpci/av7110.h
+++ b/drivers/media/dvb/ttpci/av7110.h
@@ -16,6 +16,7 @@
16#include <linux/dvb/ca.h> 16#include <linux/dvb/ca.h>
17#include <linux/dvb/osd.h> 17#include <linux/dvb/osd.h>
18#include <linux/dvb/net.h> 18#include <linux/dvb/net.h>
19#include <linux/mutex.h>
19 20
20#include "dvbdev.h" 21#include "dvbdev.h"
21#include "demux.h" 22#include "demux.h"
@@ -127,7 +128,7 @@ struct av7110 {
127 /* DEBI and polled command interface */ 128 /* DEBI and polled command interface */
128 129
129 spinlock_t debilock; 130 spinlock_t debilock;
130 struct semaphore dcomlock; 131 struct mutex dcomlock;
131 volatile int debitype; 132 volatile int debitype;
132 volatile int debilen; 133 volatile int debilen;
133 134
@@ -146,7 +147,7 @@ struct av7110 {
146 147
147 int osdwin; /* currently active window */ 148 int osdwin; /* currently active window */
148 u16 osdbpp[8]; 149 u16 osdbpp[8];
149 struct semaphore osd_sema; 150 struct mutex osd_mutex;
150 151
151 /* CA */ 152 /* CA */
152 153
@@ -172,7 +173,7 @@ struct av7110 {
172 struct tasklet_struct vpe_tasklet; 173 struct tasklet_struct vpe_tasklet;
173 174
174 int fe_synced; 175 int fe_synced;
175 struct semaphore pid_mutex; 176 struct mutex pid_mutex;
176 177
177 int video_blank; 178 int video_blank;
178 struct video_status videostate; 179 struct video_status videostate;
diff --git a/drivers/media/dvb/ttpci/av7110_hw.c b/drivers/media/dvb/ttpci/av7110_hw.c
index 0bb6e74ae7f0..75736f2fe838 100644
--- a/drivers/media/dvb/ttpci/av7110_hw.c
+++ b/drivers/media/dvb/ttpci/av7110_hw.c
@@ -327,10 +327,10 @@ int av7110_wait_msgstate(struct av7110 *av7110, u16 flags)
327 start = jiffies; 327 start = jiffies;
328 for (;;) { 328 for (;;) {
329 err = time_after(jiffies, start + ARM_WAIT_FREE); 329 err = time_after(jiffies, start + ARM_WAIT_FREE);
330 if (down_interruptible(&av7110->dcomlock)) 330 if (mutex_lock_interruptible(&av7110->dcomlock))
331 return -ERESTARTSYS; 331 return -ERESTARTSYS;
332 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2); 332 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
333 up(&av7110->dcomlock); 333 mutex_unlock(&av7110->dcomlock);
334 if ((stat & flags) == 0) 334 if ((stat & flags) == 0)
335 break; 335 break;
336 if (err) { 336 if (err) {
@@ -487,11 +487,11 @@ static int av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
487 dprintk(1, "arm not ready.\n"); 487 dprintk(1, "arm not ready.\n");
488 return -1; 488 return -1;
489 } 489 }
490 if (down_interruptible(&av7110->dcomlock)) 490 if (mutex_lock_interruptible(&av7110->dcomlock))
491 return -ERESTARTSYS; 491 return -ERESTARTSYS;
492 492
493 ret = __av7110_send_fw_cmd(av7110, buf, length); 493 ret = __av7110_send_fw_cmd(av7110, buf, length);
494 up(&av7110->dcomlock); 494 mutex_unlock(&av7110->dcomlock);
495 if (ret && ret!=-ERESTARTSYS) 495 if (ret && ret!=-ERESTARTSYS)
496 printk(KERN_ERR "dvb-ttpci: %s(): av7110_send_fw_cmd error %d\n", 496 printk(KERN_ERR "dvb-ttpci: %s(): av7110_send_fw_cmd error %d\n",
497 __FUNCTION__, ret); 497 __FUNCTION__, ret);
@@ -563,11 +563,11 @@ int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
563 return -1; 563 return -1;
564 } 564 }
565 565
566 if (down_interruptible(&av7110->dcomlock)) 566 if (mutex_lock_interruptible(&av7110->dcomlock))
567 return -ERESTARTSYS; 567 return -ERESTARTSYS;
568 568
569 if ((err = __av7110_send_fw_cmd(av7110, request_buf, request_buf_len)) < 0) { 569 if ((err = __av7110_send_fw_cmd(av7110, request_buf, request_buf_len)) < 0) {
570 up(&av7110->dcomlock); 570 mutex_unlock(&av7110->dcomlock);
571 printk(KERN_ERR "dvb-ttpci: av7110_fw_request error %d\n", err); 571 printk(KERN_ERR "dvb-ttpci: av7110_fw_request error %d\n", err);
572 return err; 572 return err;
573 } 573 }
@@ -579,7 +579,7 @@ int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
579 break; 579 break;
580 if (err) { 580 if (err) {
581 printk(KERN_ERR "%s: timeout waiting for COMMAND to complete\n", __FUNCTION__); 581 printk(KERN_ERR "%s: timeout waiting for COMMAND to complete\n", __FUNCTION__);
582 up(&av7110->dcomlock); 582 mutex_unlock(&av7110->dcomlock);
583 return -ETIMEDOUT; 583 return -ETIMEDOUT;
584 } 584 }
585#ifdef _NOHANDSHAKE 585#ifdef _NOHANDSHAKE
@@ -595,7 +595,7 @@ int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
595 break; 595 break;
596 if (err) { 596 if (err) {
597 printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __FUNCTION__); 597 printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __FUNCTION__);
598 up(&av7110->dcomlock); 598 mutex_unlock(&av7110->dcomlock);
599 return -ETIMEDOUT; 599 return -ETIMEDOUT;
600 } 600 }
601 msleep(1); 601 msleep(1);
@@ -606,12 +606,12 @@ int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
606 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2); 606 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
607 if (stat & GPMQOver) { 607 if (stat & GPMQOver) {
608 printk(KERN_ERR "%s: GPMQOver\n", __FUNCTION__); 608 printk(KERN_ERR "%s: GPMQOver\n", __FUNCTION__);
609 up(&av7110->dcomlock); 609 mutex_unlock(&av7110->dcomlock);
610 return -1; 610 return -1;
611 } 611 }
612 else if (stat & OSDQOver) { 612 else if (stat & OSDQOver) {
613 printk(KERN_ERR "%s: OSDQOver\n", __FUNCTION__); 613 printk(KERN_ERR "%s: OSDQOver\n", __FUNCTION__);
614 up(&av7110->dcomlock); 614 mutex_unlock(&av7110->dcomlock);
615 return -1; 615 return -1;
616 } 616 }
617#endif 617#endif
@@ -619,7 +619,7 @@ int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
619 for (i = 0; i < reply_buf_len; i++) 619 for (i = 0; i < reply_buf_len; i++)
620 reply_buf[i] = rdebi(av7110, DEBINOSWAP, COM_BUFF + 2 * i, 0, 2); 620 reply_buf[i] = rdebi(av7110, DEBINOSWAP, COM_BUFF + 2 * i, 0, 2);
621 621
622 up(&av7110->dcomlock); 622 mutex_unlock(&av7110->dcomlock);
623 return 0; 623 return 0;
624} 624}
625 625
@@ -735,7 +735,7 @@ static int FlushText(struct av7110 *av7110)
735 unsigned long start; 735 unsigned long start;
736 int err; 736 int err;
737 737
738 if (down_interruptible(&av7110->dcomlock)) 738 if (mutex_lock_interruptible(&av7110->dcomlock))
739 return -ERESTARTSYS; 739 return -ERESTARTSYS;
740 start = jiffies; 740 start = jiffies;
741 while (1) { 741 while (1) {
@@ -745,12 +745,12 @@ static int FlushText(struct av7110 *av7110)
745 if (err) { 745 if (err) {
746 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for BUFF1_BASE == 0\n", 746 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for BUFF1_BASE == 0\n",
747 __FUNCTION__); 747 __FUNCTION__);
748 up(&av7110->dcomlock); 748 mutex_unlock(&av7110->dcomlock);
749 return -ETIMEDOUT; 749 return -ETIMEDOUT;
750 } 750 }
751 msleep(1); 751 msleep(1);
752 } 752 }
753 up(&av7110->dcomlock); 753 mutex_unlock(&av7110->dcomlock);
754 return 0; 754 return 0;
755} 755}
756 756
@@ -761,7 +761,7 @@ static int WriteText(struct av7110 *av7110, u8 win, u16 x, u16 y, u8* buf)
761 int length = strlen(buf) + 1; 761 int length = strlen(buf) + 1;
762 u16 cbuf[5] = { (COMTYPE_OSD << 8) + DText, 3, win, x, y }; 762 u16 cbuf[5] = { (COMTYPE_OSD << 8) + DText, 3, win, x, y };
763 763
764 if (down_interruptible(&av7110->dcomlock)) 764 if (mutex_lock_interruptible(&av7110->dcomlock))
765 return -ERESTARTSYS; 765 return -ERESTARTSYS;
766 766
767 start = jiffies; 767 start = jiffies;
@@ -772,7 +772,7 @@ static int WriteText(struct av7110 *av7110, u8 win, u16 x, u16 y, u8* buf)
772 if (ret) { 772 if (ret) {
773 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for BUFF1_BASE == 0\n", 773 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for BUFF1_BASE == 0\n",
774 __FUNCTION__); 774 __FUNCTION__);
775 up(&av7110->dcomlock); 775 mutex_unlock(&av7110->dcomlock);
776 return -ETIMEDOUT; 776 return -ETIMEDOUT;
777 } 777 }
778 msleep(1); 778 msleep(1);
@@ -786,7 +786,7 @@ static int WriteText(struct av7110 *av7110, u8 win, u16 x, u16 y, u8* buf)
786 if (ret) { 786 if (ret) {
787 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for HANDSHAKE_REG\n", 787 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for HANDSHAKE_REG\n",
788 __FUNCTION__); 788 __FUNCTION__);
789 up(&av7110->dcomlock); 789 mutex_unlock(&av7110->dcomlock);
790 return -ETIMEDOUT; 790 return -ETIMEDOUT;
791 } 791 }
792 msleep(1); 792 msleep(1);
@@ -798,7 +798,7 @@ static int WriteText(struct av7110 *av7110, u8 win, u16 x, u16 y, u8* buf)
798 if (length & 1) 798 if (length & 1)
799 wdebi(av7110, DEBINOSWAP, BUFF1_BASE + i * 2, 0, 2); 799 wdebi(av7110, DEBINOSWAP, BUFF1_BASE + i * 2, 0, 2);
800 ret = __av7110_send_fw_cmd(av7110, cbuf, 5); 800 ret = __av7110_send_fw_cmd(av7110, cbuf, 5);
801 up(&av7110->dcomlock); 801 mutex_unlock(&av7110->dcomlock);
802 if (ret && ret!=-ERESTARTSYS) 802 if (ret && ret!=-ERESTARTSYS)
803 printk(KERN_ERR "dvb-ttpci: WriteText error %d\n", ret); 803 printk(KERN_ERR "dvb-ttpci: WriteText error %d\n", ret);
804 return ret; 804 return ret;
@@ -1062,7 +1062,7 @@ int av7110_osd_cmd(struct av7110 *av7110, osd_cmd_t *dc)
1062{ 1062{
1063 int ret; 1063 int ret;
1064 1064
1065 if (down_interruptible(&av7110->osd_sema)) 1065 if (mutex_lock_interruptible(&av7110->osd_mutex))
1066 return -ERESTARTSYS; 1066 return -ERESTARTSYS;
1067 1067
1068 switch (dc->cmd) { 1068 switch (dc->cmd) {
@@ -1198,7 +1198,7 @@ int av7110_osd_cmd(struct av7110 *av7110, osd_cmd_t *dc)
1198 break; 1198 break;
1199 } 1199 }
1200 1200
1201 up(&av7110->osd_sema); 1201 mutex_unlock(&av7110->osd_mutex);
1202 if (ret==-ERESTARTSYS) 1202 if (ret==-ERESTARTSYS)
1203 dprintk(1, "av7110_osd_cmd(%d) returns with -ERESTARTSYS\n",dc->cmd); 1203 dprintk(1, "av7110_osd_cmd(%d) returns with -ERESTARTSYS\n",dc->cmd);
1204 else if (ret) 1204 else if (ret)
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index 94cf38c7e8a8..2f23ceab8d44 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -579,14 +579,11 @@ static ssize_t av7110_vbi_write(struct file *file, const char __user *data, size
579 return -EFAULT; 579 return -EFAULT;
580 if ((d.id != 0 && d.id != V4L2_SLICED_WSS_625) || d.field != 0 || d.line != 23) 580 if ((d.id != 0 && d.id != V4L2_SLICED_WSS_625) || d.field != 0 || d.line != 23)
581 return -EINVAL; 581 return -EINVAL;
582 if (d.id) { 582 if (d.id)
583 av7110->wssData = ((d.data[1] << 8) & 0x3f00) | d.data[0]; 583 av7110->wssData = ((d.data[1] << 8) & 0x3f00) | d.data[0];
584 rc = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetWSSConfig, 584 else
585 2, 1, av7110->wssData); 585 av7110->wssData = 0x8000;
586 } else { 586 rc = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetWSSConfig, 2, 1, av7110->wssData);
587 av7110->wssData = 0;
588 rc = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetWSSConfig, 1, 0);
589 }
590 return (rc < 0) ? rc : count; 587 return (rc < 0) ? rc : count;
591} 588}
592 589
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 1465c04e49aa..9dd4745f5312 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -1000,6 +1000,7 @@ static u8 read_pwm(struct budget_av *budget_av)
1000 1000
1001#define SUBID_DVBS_TV_STAR 0x0014 1001#define SUBID_DVBS_TV_STAR 0x0014
1002#define SUBID_DVBS_TV_STAR_CI 0x0016 1002#define SUBID_DVBS_TV_STAR_CI 0x0016
1003#define SUBID_DVBS_EASYWATCH 0x001e
1003#define SUBID_DVBC_KNC1 0x0020 1004#define SUBID_DVBC_KNC1 0x0020
1004#define SUBID_DVBC_KNC1_PLUS 0x0021 1005#define SUBID_DVBC_KNC1_PLUS 0x0021
1005#define SUBID_DVBC_CINERGY1200 0x1156 1006#define SUBID_DVBC_CINERGY1200 0x1156
@@ -1038,6 +1039,7 @@ static void frontend_init(struct budget_av *budget_av)
1038 case SUBID_DVBS_TV_STAR: 1039 case SUBID_DVBS_TV_STAR:
1039 case SUBID_DVBS_TV_STAR_CI: 1040 case SUBID_DVBS_TV_STAR_CI:
1040 case SUBID_DVBS_CYNERGY1200N: 1041 case SUBID_DVBS_CYNERGY1200N:
1042 case SUBID_DVBS_EASYWATCH:
1041 fe = stv0299_attach(&philips_sd1878_config, 1043 fe = stv0299_attach(&philips_sd1878_config,
1042 &budget_av->budget.i2c_adap); 1044 &budget_av->budget.i2c_adap);
1043 break; 1045 break;
@@ -1285,6 +1287,7 @@ MAKE_BUDGET_INFO(knc1s, "KNC1 DVB-S", BUDGET_KNC1S);
1285MAKE_BUDGET_INFO(knc1c, "KNC1 DVB-C", BUDGET_KNC1C); 1287MAKE_BUDGET_INFO(knc1c, "KNC1 DVB-C", BUDGET_KNC1C);
1286MAKE_BUDGET_INFO(knc1t, "KNC1 DVB-T", BUDGET_KNC1T); 1288MAKE_BUDGET_INFO(knc1t, "KNC1 DVB-T", BUDGET_KNC1T);
1287MAKE_BUDGET_INFO(kncxs, "KNC TV STAR DVB-S", BUDGET_TVSTAR); 1289MAKE_BUDGET_INFO(kncxs, "KNC TV STAR DVB-S", BUDGET_TVSTAR);
1290MAKE_BUDGET_INFO(satewpls, "Satelco EasyWatch DVB-S light", BUDGET_TVSTAR);
1288MAKE_BUDGET_INFO(knc1sp, "KNC1 DVB-S Plus", BUDGET_KNC1SP); 1291MAKE_BUDGET_INFO(knc1sp, "KNC1 DVB-S Plus", BUDGET_KNC1SP);
1289MAKE_BUDGET_INFO(knc1cp, "KNC1 DVB-C Plus", BUDGET_KNC1CP); 1292MAKE_BUDGET_INFO(knc1cp, "KNC1 DVB-C Plus", BUDGET_KNC1CP);
1290MAKE_BUDGET_INFO(knc1tp, "KNC1 DVB-T Plus", BUDGET_KNC1TP); 1293MAKE_BUDGET_INFO(knc1tp, "KNC1 DVB-T Plus", BUDGET_KNC1TP);
@@ -1300,6 +1303,7 @@ static struct pci_device_id pci_tbl[] = {
1300 MAKE_EXTENSION_PCI(knc1sp, 0x1131, 0x0011), 1303 MAKE_EXTENSION_PCI(knc1sp, 0x1131, 0x0011),
1301 MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0014), 1304 MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0014),
1302 MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0016), 1305 MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0016),
1306 MAKE_EXTENSION_PCI(satewpls, 0x1894, 0x001e),
1303 MAKE_EXTENSION_PCI(knc1c, 0x1894, 0x0020), 1307 MAKE_EXTENSION_PCI(knc1c, 0x1894, 0x0020),
1304 MAKE_EXTENSION_PCI(knc1cp, 0x1894, 0x0021), 1308 MAKE_EXTENSION_PCI(knc1cp, 0x1894, 0x0021),
1305 MAKE_EXTENSION_PCI(knc1t, 0x1894, 0x0030), 1309 MAKE_EXTENSION_PCI(knc1t, 0x1894, 0x0030),
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index b9b3cd9c0369..5f91036f5b87 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -42,6 +42,9 @@
42#include "stv0299.h" 42#include "stv0299.h"
43#include "stv0297.h" 43#include "stv0297.h"
44#include "tda1004x.h" 44#include "tda1004x.h"
45#include "lnbp21.h"
46#include "bsbe1.h"
47#include "bsru6.h"
45 48
46#define DEBIADDR_IR 0x1234 49#define DEBIADDR_IR 0x1234
47#define DEBIADDR_CICONTROL 0x0000 50#define DEBIADDR_CICONTROL 0x0000
@@ -474,123 +477,6 @@ static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr)
474 tasklet_schedule(&budget_ci->ciintf_irq_tasklet); 477 tasklet_schedule(&budget_ci->ciintf_irq_tasklet);
475} 478}
476 479
477
478static u8 alps_bsru6_inittab[] = {
479 0x01, 0x15,
480 0x02, 0x00,
481 0x03, 0x00,
482 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
483 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
484 0x06, 0x40, /* DAC not used, set to high impendance mode */
485 0x07, 0x00, /* DAC LSB */
486 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
487 0x09, 0x00, /* FIFO */
488 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
489 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
490 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
491 0x10, 0x3f, // AGC2 0x3d
492 0x11, 0x84,
493 0x12, 0xb9,
494 0x15, 0xc9, // lock detector threshold
495 0x16, 0x00,
496 0x17, 0x00,
497 0x18, 0x00,
498 0x19, 0x00,
499 0x1a, 0x00,
500 0x1f, 0x50,
501 0x20, 0x00,
502 0x21, 0x00,
503 0x22, 0x00,
504 0x23, 0x00,
505 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
506 0x29, 0x1e, // 1/2 threshold
507 0x2a, 0x14, // 2/3 threshold
508 0x2b, 0x0f, // 3/4 threshold
509 0x2c, 0x09, // 5/6 threshold
510 0x2d, 0x05, // 7/8 threshold
511 0x2e, 0x01,
512 0x31, 0x1f, // test all FECs
513 0x32, 0x19, // viterbi and synchro search
514 0x33, 0xfc, // rs control
515 0x34, 0x93, // error control
516 0x0f, 0x52,
517 0xff, 0xff
518};
519
520static int alps_bsru6_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
521{
522 u8 aclk = 0;
523 u8 bclk = 0;
524
525 if (srate < 1500000) {
526 aclk = 0xb7;
527 bclk = 0x47;
528 } else if (srate < 3000000) {
529 aclk = 0xb7;
530 bclk = 0x4b;
531 } else if (srate < 7000000) {
532 aclk = 0xb7;
533 bclk = 0x4f;
534 } else if (srate < 14000000) {
535 aclk = 0xb7;
536 bclk = 0x53;
537 } else if (srate < 30000000) {
538 aclk = 0xb6;
539 bclk = 0x53;
540 } else if (srate < 45000000) {
541 aclk = 0xb4;
542 bclk = 0x51;
543 }
544
545 stv0299_writereg(fe, 0x13, aclk);
546 stv0299_writereg(fe, 0x14, bclk);
547 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
548 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
549 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
550
551 return 0;
552}
553
554static int alps_bsru6_pll_set(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters *params)
555{
556 u8 buf[4];
557 u32 div;
558 struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) };
559
560 if ((params->frequency < 950000) || (params->frequency > 2150000))
561 return -EINVAL;
562
563 div = (params->frequency + (125 - 1)) / 125; // round correctly
564 buf[0] = (div >> 8) & 0x7f;
565 buf[1] = div & 0xff;
566 buf[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
567 buf[3] = 0xC4;
568
569 if (params->frequency > 1530000)
570 buf[3] = 0xc0;
571
572 if (i2c_transfer(i2c, &msg, 1) != 1)
573 return -EIO;
574 return 0;
575}
576
577static struct stv0299_config alps_bsru6_config = {
578
579 .demod_address = 0x68,
580 .inittab = alps_bsru6_inittab,
581 .mclk = 88000000UL,
582 .invert = 1,
583 .skip_reinit = 0,
584 .lock_output = STV0229_LOCKOUTPUT_1,
585 .volt13_op0_op1 = STV0299_VOLT13_OP1,
586 .min_delay_ms = 100,
587 .set_symbol_rate = alps_bsru6_set_symbol_rate,
588 .pll_set = alps_bsru6_pll_set,
589};
590
591
592
593
594static u8 philips_su1278_tt_inittab[] = { 480static u8 philips_su1278_tt_inittab[] = {
595 0x01, 0x0f, 481 0x01, 0x0f,
596 0x02, 0x30, 482 0x02, 0x30,
@@ -1069,6 +955,20 @@ static void frontend_init(struct budget_ci *budget_ci)
1069 break; 955 break;
1070 } 956 }
1071 break; 957 break;
958
959 case 0x1017: // TT S-1500 PCI
960 budget_ci->budget.dvb_frontend = stv0299_attach(&alps_bsbe1_config, &budget_ci->budget.i2c_adap);
961 if (budget_ci->budget.dvb_frontend) {
962 budget_ci->budget.dvb_frontend->ops->dishnetwork_send_legacy_command = NULL;
963 if (lnbp21_init(budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0)) {
964 printk("%s: No LNBP21 found!\n", __FUNCTION__);
965 if (budget_ci->budget.dvb_frontend->ops->release)
966 budget_ci->budget.dvb_frontend->ops->release(budget_ci->budget.dvb_frontend);
967 budget_ci->budget.dvb_frontend = NULL;
968 }
969 }
970
971 break;
1072 } 972 }
1073 973
1074 if (budget_ci->budget.dvb_frontend == NULL) { 974 if (budget_ci->budget.dvb_frontend == NULL) {
@@ -1146,6 +1046,7 @@ static int budget_ci_detach(struct saa7146_dev *dev)
1146 1046
1147static struct saa7146_extension budget_extension; 1047static struct saa7146_extension budget_extension;
1148 1048
1049MAKE_BUDGET_INFO(ttbs2, "TT-Budget/S-1500 PCI", BUDGET_TT);
1149MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC); 1050MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC);
1150MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT); 1051MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
1151MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT); 1052MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT);
@@ -1157,6 +1058,7 @@ static struct pci_device_id pci_tbl[] = {
1157 MAKE_EXTENSION_PCI(ttbcci, 0x13c2, 0x1010), 1058 MAKE_EXTENSION_PCI(ttbcci, 0x13c2, 0x1010),
1158 MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011), 1059 MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011),
1159 MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012), 1060 MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012),
1061 MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017),
1160 { 1062 {
1161 .vendor = 0, 1063 .vendor = 0,
1162 } 1064 }
diff --git a/drivers/media/dvb/ttpci/budget-patch.c b/drivers/media/dvb/ttpci/budget-patch.c
index fc416cf5253c..9fc9185a8426 100644
--- a/drivers/media/dvb/ttpci/budget-patch.c
+++ b/drivers/media/dvb/ttpci/budget-patch.c
@@ -37,6 +37,8 @@
37#include "ves1x93.h" 37#include "ves1x93.h"
38#include "tda8083.h" 38#include "tda8083.h"
39 39
40#include "bsru6.h"
41
40#define budget_patch budget 42#define budget_patch budget
41 43
42static struct saa7146_extension budget_extension; 44static struct saa7146_extension budget_extension;
@@ -290,103 +292,6 @@ static struct ves1x93_config alps_bsrv2_config = {
290 .pll_set = alps_bsrv2_pll_set, 292 .pll_set = alps_bsrv2_pll_set,
291}; 293};
292 294
293static u8 alps_bsru6_inittab[] = {
294 0x01, 0x15,
295 0x02, 0x00,
296 0x03, 0x00,
297 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
298 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
299 0x06, 0x40, /* DAC not used, set to high impendance mode */
300 0x07, 0x00, /* DAC LSB */
301 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
302 0x09, 0x00, /* FIFO */
303 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
304 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
305 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
306 0x10, 0x3f, // AGC2 0x3d
307 0x11, 0x84,
308 0x12, 0xb9,
309 0x15, 0xc9, // lock detector threshold
310 0x16, 0x00,
311 0x17, 0x00,
312 0x18, 0x00,
313 0x19, 0x00,
314 0x1a, 0x00,
315 0x1f, 0x50,
316 0x20, 0x00,
317 0x21, 0x00,
318 0x22, 0x00,
319 0x23, 0x00,
320 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
321 0x29, 0x1e, // 1/2 threshold
322 0x2a, 0x14, // 2/3 threshold
323 0x2b, 0x0f, // 3/4 threshold
324 0x2c, 0x09, // 5/6 threshold
325 0x2d, 0x05, // 7/8 threshold
326 0x2e, 0x01,
327 0x31, 0x1f, // test all FECs
328 0x32, 0x19, // viterbi and synchro search
329 0x33, 0xfc, // rs control
330 0x34, 0x93, // error control
331 0x0f, 0x52,
332 0xff, 0xff
333};
334
335static int alps_bsru6_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio)
336{
337 u8 aclk = 0;
338 u8 bclk = 0;
339
340 if (srate < 1500000) { aclk = 0xb7; bclk = 0x47; }
341 else if (srate < 3000000) { aclk = 0xb7; bclk = 0x4b; }
342 else if (srate < 7000000) { aclk = 0xb7; bclk = 0x4f; }
343 else if (srate < 14000000) { aclk = 0xb7; bclk = 0x53; }
344 else if (srate < 30000000) { aclk = 0xb6; bclk = 0x53; }
345 else if (srate < 45000000) { aclk = 0xb4; bclk = 0x51; }
346
347 stv0299_writereg (fe, 0x13, aclk);
348 stv0299_writereg (fe, 0x14, bclk);
349 stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff);
350 stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff);
351 stv0299_writereg (fe, 0x21, (ratio ) & 0xf0);
352
353 return 0;
354}
355
356static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters* params)
357{
358 u8 data[4];
359 u32 div;
360 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
361
362 if ((params->frequency < 950000) || (params->frequency > 2150000)) return -EINVAL;
363
364 div = (params->frequency + (125 - 1)) / 125; // round correctly
365 data[0] = (div >> 8) & 0x7f;
366 data[1] = div & 0xff;
367 data[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
368 data[3] = 0xC4;
369
370 if (params->frequency > 1530000) data[3] = 0xc0;
371
372 if (i2c_transfer(i2c, &msg, 1) != 1) return -EIO;
373 return 0;
374}
375
376static struct stv0299_config alps_bsru6_config = {
377
378 .demod_address = 0x68,
379 .inittab = alps_bsru6_inittab,
380 .mclk = 88000000UL,
381 .invert = 1,
382 .skip_reinit = 0,
383 .lock_output = STV0229_LOCKOUTPUT_1,
384 .volt13_op0_op1 = STV0299_VOLT13_OP1,
385 .min_delay_ms = 100,
386 .set_symbol_rate = alps_bsru6_set_symbol_rate,
387 .pll_set = alps_bsru6_pll_set,
388};
389
390static int grundig_29504_451_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 295static int grundig_29504_451_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
391{ 296{
392 struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv; 297 struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
diff --git a/drivers/media/dvb/ttpci/budget.c b/drivers/media/dvb/ttpci/budget.c
index 238c77b52f89..c23c02d95641 100644
--- a/drivers/media/dvb/ttpci/budget.c
+++ b/drivers/media/dvb/ttpci/budget.c
@@ -41,6 +41,8 @@
41#include "l64781.h" 41#include "l64781.h"
42#include "tda8083.h" 42#include "tda8083.h"
43#include "s5h1420.h" 43#include "s5h1420.h"
44#include "lnbp21.h"
45#include "bsru6.h"
44 46
45static void Set22K (struct budget *budget, int state) 47static void Set22K (struct budget *budget, int state)
46{ 48{
@@ -184,64 +186,6 @@ static int budget_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t m
184 return 0; 186 return 0;
185} 187}
186 188
187static int lnbp21_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
188{
189 struct budget* budget = (struct budget*) fe->dvb->priv;
190 u8 buf;
191 struct i2c_msg msg = { .addr = 0x08, .flags = I2C_M_RD, .buf = &buf, .len = sizeof(buf) };
192
193 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
194
195 switch(voltage) {
196 case SEC_VOLTAGE_13:
197 buf = (buf & 0xf7) | 0x04;
198 break;
199
200 case SEC_VOLTAGE_18:
201 buf = (buf & 0xf7) | 0x0c;
202 break;
203
204 case SEC_VOLTAGE_OFF:
205 buf = buf & 0xf0;
206 break;
207 }
208
209 msg.flags = 0;
210 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
211
212 return 0;
213}
214
215static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend* fe, long arg)
216{
217 struct budget* budget = (struct budget*) fe->dvb->priv;
218 u8 buf;
219 struct i2c_msg msg = { .addr = 0x08, .flags = I2C_M_RD, .buf = &buf, .len = sizeof(buf) };
220
221 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
222
223 if (arg) {
224 buf = buf | 0x10;
225 } else {
226 buf = buf & 0xef;
227 }
228
229 msg.flags = 0;
230 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
231
232 return 0;
233}
234
235static int lnbp21_init(struct budget* budget)
236{
237 u8 buf = 0x00;
238 struct i2c_msg msg = { .addr = 0x08, .flags = 0, .buf = &buf, .len = sizeof(buf) };
239
240 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1)
241 return -EIO;
242 return 0;
243}
244
245static int alps_bsrv2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 189static int alps_bsrv2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
246{ 190{
247 struct budget* budget = (struct budget*) fe->dvb->priv; 191 struct budget* budget = (struct budget*) fe->dvb->priv;
@@ -277,176 +221,6 @@ static struct ves1x93_config alps_bsrv2_config =
277 .pll_set = alps_bsrv2_pll_set, 221 .pll_set = alps_bsrv2_pll_set,
278}; 222};
279 223
280static u8 alps_bsru6_inittab[] = {
281 0x01, 0x15,
282 0x02, 0x00,
283 0x03, 0x00,
284 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
285 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
286 0x06, 0x40, /* DAC not used, set to high impendance mode */
287 0x07, 0x00, /* DAC LSB */
288 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
289 0x09, 0x00, /* FIFO */
290 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
291 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
292 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
293 0x10, 0x3f, // AGC2 0x3d
294 0x11, 0x84,
295 0x12, 0xb9,
296 0x15, 0xc9, // lock detector threshold
297 0x16, 0x00,
298 0x17, 0x00,
299 0x18, 0x00,
300 0x19, 0x00,
301 0x1a, 0x00,
302 0x1f, 0x50,
303 0x20, 0x00,
304 0x21, 0x00,
305 0x22, 0x00,
306 0x23, 0x00,
307 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
308 0x29, 0x1e, // 1/2 threshold
309 0x2a, 0x14, // 2/3 threshold
310 0x2b, 0x0f, // 3/4 threshold
311 0x2c, 0x09, // 5/6 threshold
312 0x2d, 0x05, // 7/8 threshold
313 0x2e, 0x01,
314 0x31, 0x1f, // test all FECs
315 0x32, 0x19, // viterbi and synchro search
316 0x33, 0xfc, // rs control
317 0x34, 0x93, // error control
318 0x0f, 0x52,
319 0xff, 0xff
320};
321
322static int alps_bsru6_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio)
323{
324 u8 aclk = 0;
325 u8 bclk = 0;
326
327 if (srate < 1500000) { aclk = 0xb7; bclk = 0x47; }
328 else if (srate < 3000000) { aclk = 0xb7; bclk = 0x4b; }
329 else if (srate < 7000000) { aclk = 0xb7; bclk = 0x4f; }
330 else if (srate < 14000000) { aclk = 0xb7; bclk = 0x53; }
331 else if (srate < 30000000) { aclk = 0xb6; bclk = 0x53; }
332 else if (srate < 45000000) { aclk = 0xb4; bclk = 0x51; }
333
334 stv0299_writereg (fe, 0x13, aclk);
335 stv0299_writereg (fe, 0x14, bclk);
336 stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff);
337 stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff);
338 stv0299_writereg (fe, 0x21, (ratio ) & 0xf0);
339
340 return 0;
341}
342
343static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters* params)
344{
345 u8 data[4];
346 u32 div;
347 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
348
349 if ((params->frequency < 950000) || (params->frequency > 2150000)) return -EINVAL;
350
351 div = (params->frequency + (125 - 1)) / 125; // round correctly
352 data[0] = (div >> 8) & 0x7f;
353 data[1] = div & 0xff;
354 data[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
355 data[3] = 0xC4;
356
357 if (params->frequency > 1530000) data[3] = 0xc0;
358
359 if (i2c_transfer(i2c, &msg, 1) != 1) return -EIO;
360 return 0;
361}
362
363static struct stv0299_config alps_bsru6_config = {
364
365 .demod_address = 0x68,
366 .inittab = alps_bsru6_inittab,
367 .mclk = 88000000UL,
368 .invert = 1,
369 .skip_reinit = 0,
370 .lock_output = STV0229_LOCKOUTPUT_1,
371 .volt13_op0_op1 = STV0299_VOLT13_OP1,
372 .min_delay_ms = 100,
373 .set_symbol_rate = alps_bsru6_set_symbol_rate,
374 .pll_set = alps_bsru6_pll_set,
375};
376
377static u8 alps_bsbe1_inittab[] = {
378 0x01, 0x15,
379 0x02, 0x30,
380 0x03, 0x00,
381 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
382 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
383 0x06, 0x40, /* DAC not used, set to high impendance mode */
384 0x07, 0x00, /* DAC LSB */
385 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
386 0x09, 0x00, /* FIFO */
387 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
388 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
389 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
390 0x10, 0x3f, // AGC2 0x3d
391 0x11, 0x84,
392 0x12, 0xb9,
393 0x15, 0xc9, // lock detector threshold
394 0x16, 0x00,
395 0x17, 0x00,
396 0x18, 0x00,
397 0x19, 0x00,
398 0x1a, 0x00,
399 0x1f, 0x50,
400 0x20, 0x00,
401 0x21, 0x00,
402 0x22, 0x00,
403 0x23, 0x00,
404 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
405 0x29, 0x1e, // 1/2 threshold
406 0x2a, 0x14, // 2/3 threshold
407 0x2b, 0x0f, // 3/4 threshold
408 0x2c, 0x09, // 5/6 threshold
409 0x2d, 0x05, // 7/8 threshold
410 0x2e, 0x01,
411 0x31, 0x1f, // test all FECs
412 0x32, 0x19, // viterbi and synchro search
413 0x33, 0xfc, // rs control
414 0x34, 0x93, // error control
415 0x0f, 0x92, // 0x80 = inverse AGC
416 0xff, 0xff
417};
418
419static int alps_bsbe1_pll_set(struct dvb_frontend* fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters* params)
420{
421 int ret;
422 u8 data[4];
423 u32 div;
424 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
425
426 if ((params->frequency < 950000) || (params->frequency > 2150000))
427 return -EINVAL;
428
429 div = (params->frequency + (125 - 1)) / 125; // round correctly
430 data[0] = (div >> 8) & 0x7f;
431 data[1] = div & 0xff;
432 data[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
433 data[3] = (params->frequency > 1530000) ? 0xE0 : 0xE4;
434
435 ret = i2c_transfer(i2c, &msg, 1);
436 return (ret != 1) ? -EIO : 0;
437}
438
439static struct stv0299_config alps_bsbe1_config = {
440 .demod_address = 0x68,
441 .inittab = alps_bsbe1_inittab,
442 .mclk = 88000000UL,
443 .invert = 1,
444 .skip_reinit = 0,
445 .min_delay_ms = 100,
446 .set_symbol_rate = alps_bsru6_set_symbol_rate,
447 .pll_set = alps_bsbe1_pll_set,
448};
449
450static int alps_tdbe2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 224static int alps_tdbe2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
451{ 225{
452 struct budget* budget = (struct budget*) fe->dvb->priv; 226 struct budget* budget = (struct budget*) fe->dvb->priv;
@@ -580,20 +354,6 @@ static u8 read_pwm(struct budget* budget)
580static void frontend_init(struct budget *budget) 354static void frontend_init(struct budget *budget)
581{ 355{
582 switch(budget->dev->pci->subsystem_device) { 356 switch(budget->dev->pci->subsystem_device) {
583 case 0x1017:
584 // try the ALPS BSBE1 now
585 budget->dvb_frontend = stv0299_attach(&alps_bsbe1_config, &budget->i2c_adap);
586 if (budget->dvb_frontend) {
587 budget->dvb_frontend->ops->set_voltage = lnbp21_set_voltage;
588 budget->dvb_frontend->ops->enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage;
589 budget->dvb_frontend->ops->dishnetwork_send_legacy_command = NULL;
590 if (lnbp21_init(budget)) {
591 printk("%s: No LNBP21 found!\n", __FUNCTION__);
592 goto error_out;
593 }
594 }
595
596 break;
597 case 0x1003: // Hauppauge/TT Nova budget (stv0299/ALPS BSRU6(tsa5059) OR ves1893/ALPS BSRV2(sp5659)) 357 case 0x1003: // Hauppauge/TT Nova budget (stv0299/ALPS BSRU6(tsa5059) OR ves1893/ALPS BSRV2(sp5659))
598 case 0x1013: 358 case 0x1013:
599 // try the ALPS BSRV2 first of all 359 // try the ALPS BSRV2 first of all
@@ -646,9 +406,7 @@ static void frontend_init(struct budget *budget)
646 case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260)) 406 case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260))
647 budget->dvb_frontend = s5h1420_attach(&s5h1420_config, &budget->i2c_adap); 407 budget->dvb_frontend = s5h1420_attach(&s5h1420_config, &budget->i2c_adap);
648 if (budget->dvb_frontend) { 408 if (budget->dvb_frontend) {
649 budget->dvb_frontend->ops->set_voltage = lnbp21_set_voltage; 409 if (lnbp21_init(budget->dvb_frontend, &budget->i2c_adap, 0, 0)) {
650 budget->dvb_frontend->ops->enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage;
651 if (lnbp21_init(budget)) {
652 printk("%s: No LNBP21 found!\n", __FUNCTION__); 410 printk("%s: No LNBP21 found!\n", __FUNCTION__);
653 goto error_out; 411 goto error_out;
654 } 412 }
@@ -719,7 +477,6 @@ static int budget_detach (struct saa7146_dev* dev)
719 477
720static struct saa7146_extension budget_extension; 478static struct saa7146_extension budget_extension;
721 479
722MAKE_BUDGET_INFO(ttbs2, "TT-Budget/WinTV-NOVA-S PCI (rev AL/alps bsbe1 lnbp21 frontend)", BUDGET_TT);
723MAKE_BUDGET_INFO(ttbs, "TT-Budget/WinTV-NOVA-S PCI", BUDGET_TT); 480MAKE_BUDGET_INFO(ttbs, "TT-Budget/WinTV-NOVA-S PCI", BUDGET_TT);
724MAKE_BUDGET_INFO(ttbc, "TT-Budget/WinTV-NOVA-C PCI", BUDGET_TT); 481MAKE_BUDGET_INFO(ttbc, "TT-Budget/WinTV-NOVA-C PCI", BUDGET_TT);
725MAKE_BUDGET_INFO(ttbt, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT); 482MAKE_BUDGET_INFO(ttbt, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
@@ -732,7 +489,6 @@ static struct pci_device_id pci_tbl[] = {
732 MAKE_EXTENSION_PCI(ttbc, 0x13c2, 0x1004), 489 MAKE_EXTENSION_PCI(ttbc, 0x13c2, 0x1004),
733 MAKE_EXTENSION_PCI(ttbt, 0x13c2, 0x1005), 490 MAKE_EXTENSION_PCI(ttbt, 0x13c2, 0x1005),
734 MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013), 491 MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013),
735 MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017),
736 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1016), 492 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1016),
737 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60), 493 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60),
738 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61), 494 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61),
diff --git a/drivers/media/dvb/ttpci/budget.h b/drivers/media/dvb/ttpci/budget.h
index c7bb63c4d98d..4ac0f4d08025 100644
--- a/drivers/media/dvb/ttpci/budget.h
+++ b/drivers/media/dvb/ttpci/budget.h
@@ -10,6 +10,8 @@
10#include "dvb_net.h" 10#include "dvb_net.h"
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/mutex.h>
14
13#include <media/saa7146.h> 15#include <media/saa7146.h>
14 16
15extern int budget_debug; 17extern int budget_debug;
@@ -51,7 +53,7 @@ struct budget {
51 struct dmx_frontend mem_frontend; 53 struct dmx_frontend mem_frontend;
52 54
53 int fe_synced; 55 int fe_synced;
54 struct semaphore pid_mutex; 56 struct mutex pid_mutex;
55 57
56 int ci_present; 58 int ci_present;
57 int video_port; 59 int video_port;
diff --git a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
index 5a13c4744f61..248fdc7accfb 100644
--- a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
@@ -19,7 +19,7 @@
19#include <linux/time.h> 19#include <linux/time.h>
20#include <linux/errno.h> 20#include <linux/errno.h>
21#include <linux/jiffies.h> 21#include <linux/jiffies.h>
22#include <asm/semaphore.h> 22#include <linux/mutex.h>
23 23
24#include "dvb_frontend.h" 24#include "dvb_frontend.h"
25#include "dmxdev.h" 25#include "dmxdev.h"
@@ -35,7 +35,6 @@
35#include <linux/dvb/dmx.h> 35#include <linux/dvb/dmx.h>
36#include <linux/pci.h> 36#include <linux/pci.h>
37 37
38
39/* 38/*
40 TTUSB_HWSECTIONS: 39 TTUSB_HWSECTIONS:
41 the DSP supports filtering in hardware, however, since the "muxstream" 40 the DSP supports filtering in hardware, however, since the "muxstream"
@@ -83,8 +82,8 @@ struct ttusb {
83 struct dvb_net dvbnet; 82 struct dvb_net dvbnet;
84 83
85 /* and one for USB access. */ 84 /* and one for USB access. */
86 struct semaphore semi2c; 85 struct mutex semi2c;
87 struct semaphore semusb; 86 struct mutex semusb;
88 87
89 struct dvb_adapter adapter; 88 struct dvb_adapter adapter;
90 struct usb_device *dev; 89 struct usb_device *dev;
@@ -150,7 +149,7 @@ static int ttusb_cmd(struct ttusb *ttusb,
150 printk("\n"); 149 printk("\n");
151#endif 150#endif
152 151
153 if (down_interruptible(&ttusb->semusb) < 0) 152 if (mutex_lock_interruptible(&ttusb->semusb) < 0)
154 return -EAGAIN; 153 return -EAGAIN;
155 154
156 err = usb_bulk_msg(ttusb->dev, ttusb->bulk_out_pipe, 155 err = usb_bulk_msg(ttusb->dev, ttusb->bulk_out_pipe,
@@ -158,13 +157,13 @@ static int ttusb_cmd(struct ttusb *ttusb,
158 if (err != 0) { 157 if (err != 0) {
159 dprintk("%s: usb_bulk_msg(send) failed, err == %i!\n", 158 dprintk("%s: usb_bulk_msg(send) failed, err == %i!\n",
160 __FUNCTION__, err); 159 __FUNCTION__, err);
161 up(&ttusb->semusb); 160 mutex_unlock(&ttusb->semusb);
162 return err; 161 return err;
163 } 162 }
164 if (actual_len != len) { 163 if (actual_len != len) {
165 dprintk("%s: only wrote %d of %d bytes\n", __FUNCTION__, 164 dprintk("%s: only wrote %d of %d bytes\n", __FUNCTION__,
166 actual_len, len); 165 actual_len, len);
167 up(&ttusb->semusb); 166 mutex_unlock(&ttusb->semusb);
168 return -1; 167 return -1;
169 } 168 }
170 169
@@ -174,7 +173,7 @@ static int ttusb_cmd(struct ttusb *ttusb,
174 if (err != 0) { 173 if (err != 0) {
175 printk("%s: failed, receive error %d\n", __FUNCTION__, 174 printk("%s: failed, receive error %d\n", __FUNCTION__,
176 err); 175 err);
177 up(&ttusb->semusb); 176 mutex_unlock(&ttusb->semusb);
178 return err; 177 return err;
179 } 178 }
180#if DEBUG >= 3 179#if DEBUG >= 3
@@ -185,14 +184,14 @@ static int ttusb_cmd(struct ttusb *ttusb,
185 printk("\n"); 184 printk("\n");
186#endif 185#endif
187 if (!needresult) 186 if (!needresult)
188 up(&ttusb->semusb); 187 mutex_unlock(&ttusb->semusb);
189 return 0; 188 return 0;
190} 189}
191 190
192static int ttusb_result(struct ttusb *ttusb, u8 * data, int len) 191static int ttusb_result(struct ttusb *ttusb, u8 * data, int len)
193{ 192{
194 memcpy(data, ttusb->last_result, len); 193 memcpy(data, ttusb->last_result, len);
195 up(&ttusb->semusb); 194 mutex_unlock(&ttusb->semusb);
196 return 0; 195 return 0;
197} 196}
198 197
@@ -250,7 +249,7 @@ static int master_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, int num
250 int i = 0; 249 int i = 0;
251 int inc; 250 int inc;
252 251
253 if (down_interruptible(&ttusb->semi2c) < 0) 252 if (mutex_lock_interruptible(&ttusb->semi2c) < 0)
254 return -EAGAIN; 253 return -EAGAIN;
255 254
256 while (i < num) { 255 while (i < num) {
@@ -284,7 +283,7 @@ static int master_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, int num
284 i += inc; 283 i += inc;
285 } 284 }
286 285
287 up(&ttusb->semi2c); 286 mutex_unlock(&ttusb->semi2c);
288 return i; 287 return i;
289} 288}
290 289
@@ -689,8 +688,7 @@ static void ttusb_process_frame(struct ttusb *ttusb, u8 * data, int len)
689 memcpy(ttusb->muxpack + ttusb->muxpack_ptr, 688 memcpy(ttusb->muxpack + ttusb->muxpack_ptr,
690 data, avail); 689 data, avail);
691 ttusb->muxpack_ptr += avail; 690 ttusb->muxpack_ptr += avail;
692 if (ttusb->muxpack_ptr > 264) 691 BUG_ON(ttusb->muxpack_ptr > 264);
693 BUG();
694 data += avail; 692 data += avail;
695 len -= avail; 693 len -= avail;
696 /* determine length */ 694 /* determine length */
@@ -1495,8 +1493,11 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i
1495 ttusb->dev = udev; 1493 ttusb->dev = udev;
1496 ttusb->c = 0; 1494 ttusb->c = 0;
1497 ttusb->mux_state = 0; 1495 ttusb->mux_state = 0;
1498 sema_init(&ttusb->semi2c, 0); 1496 mutex_init(&ttusb->semi2c);
1499 sema_init(&ttusb->semusb, 1); 1497
1498 mutex_lock(&ttusb->semi2c);
1499
1500 mutex_init(&ttusb->semusb);
1500 1501
1501 ttusb_setup_interfaces(ttusb); 1502 ttusb_setup_interfaces(ttusb);
1502 1503
@@ -1504,7 +1505,7 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i
1504 if (ttusb_init_controller(ttusb)) 1505 if (ttusb_init_controller(ttusb))
1505 printk("ttusb_init_controller: error\n"); 1506 printk("ttusb_init_controller: error\n");
1506 1507
1507 up(&ttusb->semi2c); 1508 mutex_unlock(&ttusb->semi2c);
1508 1509
1509 dvb_register_adapter(&ttusb->adapter, "Technotrend/Hauppauge Nova-USB", THIS_MODULE); 1510 dvb_register_adapter(&ttusb->adapter, "Technotrend/Hauppauge Nova-USB", THIS_MODULE);
1510 ttusb->adapter.priv = ttusb; 1511 ttusb->adapter.priv = ttusb;
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index df831171e03c..44dea3211848 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -20,7 +20,8 @@
20 * 20 *
21 */ 21 */
22 22
23#include <asm/semaphore.h> 23#include <linux/mutex.h>
24
24#include <linux/list.h> 25#include <linux/list.h>
25#include <linux/module.h> 26#include <linux/module.h>
26#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
@@ -115,7 +116,7 @@ struct ttusb_dec {
115 unsigned int out_pipe; 116 unsigned int out_pipe;
116 unsigned int irq_pipe; 117 unsigned int irq_pipe;
117 enum ttusb_dec_interface interface; 118 enum ttusb_dec_interface interface;
118 struct semaphore usb_sem; 119 struct mutex usb_mutex;
119 120
120 void *irq_buffer; 121 void *irq_buffer;
121 struct urb *irq_urb; 122 struct urb *irq_urb;
@@ -124,7 +125,7 @@ struct ttusb_dec {
124 dma_addr_t iso_dma_handle; 125 dma_addr_t iso_dma_handle;
125 struct urb *iso_urb[ISO_BUF_COUNT]; 126 struct urb *iso_urb[ISO_BUF_COUNT];
126 int iso_stream_count; 127 int iso_stream_count;
127 struct semaphore iso_sem; 128 struct mutex iso_mutex;
128 129
129 u8 packet[MAX_PVA_LENGTH + 4]; 130 u8 packet[MAX_PVA_LENGTH + 4];
130 enum ttusb_dec_packet_type packet_type; 131 enum ttusb_dec_packet_type packet_type;
@@ -273,9 +274,9 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
273 if (!b) 274 if (!b)
274 return -ENOMEM; 275 return -ENOMEM;
275 276
276 if ((result = down_interruptible(&dec->usb_sem))) { 277 if ((result = mutex_lock_interruptible(&dec->usb_mutex))) {
277 kfree(b); 278 kfree(b);
278 printk("%s: Failed to down usb semaphore.\n", __FUNCTION__); 279 printk("%s: Failed to lock usb mutex.\n", __FUNCTION__);
279 return result; 280 return result;
280 } 281 }
281 282
@@ -300,7 +301,7 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
300 if (result) { 301 if (result) {
301 printk("%s: command bulk message failed: error %d\n", 302 printk("%s: command bulk message failed: error %d\n",
302 __FUNCTION__, result); 303 __FUNCTION__, result);
303 up(&dec->usb_sem); 304 mutex_unlock(&dec->usb_mutex);
304 kfree(b); 305 kfree(b);
305 return result; 306 return result;
306 } 307 }
@@ -311,7 +312,7 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
311 if (result) { 312 if (result) {
312 printk("%s: result bulk message failed: error %d\n", 313 printk("%s: result bulk message failed: error %d\n",
313 __FUNCTION__, result); 314 __FUNCTION__, result);
314 up(&dec->usb_sem); 315 mutex_unlock(&dec->usb_mutex);
315 kfree(b); 316 kfree(b);
316 return result; 317 return result;
317 } else { 318 } else {
@@ -327,7 +328,7 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
327 if (cmd_result && b[3] > 0) 328 if (cmd_result && b[3] > 0)
328 memcpy(cmd_result, &b[4], b[3]); 329 memcpy(cmd_result, &b[4], b[3]);
329 330
330 up(&dec->usb_sem); 331 mutex_unlock(&dec->usb_mutex);
331 332
332 kfree(b); 333 kfree(b);
333 return 0; 334 return 0;
@@ -835,7 +836,7 @@ static void ttusb_dec_stop_iso_xfer(struct ttusb_dec *dec)
835 836
836 dprintk("%s\n", __FUNCTION__); 837 dprintk("%s\n", __FUNCTION__);
837 838
838 if (down_interruptible(&dec->iso_sem)) 839 if (mutex_lock_interruptible(&dec->iso_mutex))
839 return; 840 return;
840 841
841 dec->iso_stream_count--; 842 dec->iso_stream_count--;
@@ -845,7 +846,7 @@ static void ttusb_dec_stop_iso_xfer(struct ttusb_dec *dec)
845 usb_kill_urb(dec->iso_urb[i]); 846 usb_kill_urb(dec->iso_urb[i]);
846 } 847 }
847 848
848 up(&dec->iso_sem); 849 mutex_unlock(&dec->iso_mutex);
849} 850}
850 851
851/* Setting the interface of the DEC tends to take down the USB communications 852/* Setting the interface of the DEC tends to take down the USB communications
@@ -890,7 +891,7 @@ static int ttusb_dec_start_iso_xfer(struct ttusb_dec *dec)
890 891
891 dprintk("%s\n", __FUNCTION__); 892 dprintk("%s\n", __FUNCTION__);
892 893
893 if (down_interruptible(&dec->iso_sem)) 894 if (mutex_lock_interruptible(&dec->iso_mutex))
894 return -EAGAIN; 895 return -EAGAIN;
895 896
896 if (!dec->iso_stream_count) { 897 if (!dec->iso_stream_count) {
@@ -911,7 +912,7 @@ static int ttusb_dec_start_iso_xfer(struct ttusb_dec *dec)
911 i--; 912 i--;
912 } 913 }
913 914
914 up(&dec->iso_sem); 915 mutex_unlock(&dec->iso_mutex);
915 return result; 916 return result;
916 } 917 }
917 } 918 }
@@ -919,7 +920,7 @@ static int ttusb_dec_start_iso_xfer(struct ttusb_dec *dec)
919 920
920 dec->iso_stream_count++; 921 dec->iso_stream_count++;
921 922
922 up(&dec->iso_sem); 923 mutex_unlock(&dec->iso_mutex);
923 924
924 return 0; 925 return 0;
925} 926}
@@ -1229,8 +1230,8 @@ static int ttusb_dec_init_usb(struct ttusb_dec *dec)
1229{ 1230{
1230 dprintk("%s\n", __FUNCTION__); 1231 dprintk("%s\n", __FUNCTION__);
1231 1232
1232 sema_init(&dec->usb_sem, 1); 1233 mutex_init(&dec->usb_mutex);
1233 sema_init(&dec->iso_sem, 1); 1234 mutex_init(&dec->iso_mutex);
1234 1235
1235 dec->command_pipe = usb_sndbulkpipe(dec->udev, COMMAND_PIPE); 1236 dec->command_pipe = usb_sndbulkpipe(dec->udev, COMMAND_PIPE);
1236 dec->result_pipe = usb_rcvbulkpipe(dec->udev, RESULT_PIPE); 1237 dec->result_pipe = usb_rcvbulkpipe(dec->udev, RESULT_PIPE);
diff --git a/drivers/media/radio/miropcm20-rds-core.c b/drivers/media/radio/miropcm20-rds-core.c
index a917a90cb5dc..b602c73e2309 100644
--- a/drivers/media/radio/miropcm20-rds-core.c
+++ b/drivers/media/radio/miropcm20-rds-core.c
@@ -18,14 +18,15 @@
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <asm/semaphore.h> 21#include <linux/mutex.h>
22
22#include <asm/io.h> 23#include <asm/io.h>
23#include "../../../sound/oss/aci.h" 24#include "../../../sound/oss/aci.h"
24#include "miropcm20-rds-core.h" 25#include "miropcm20-rds-core.h"
25 26
26#define DEBUG 0 27#define DEBUG 0
27 28
28static struct semaphore aci_rds_sem; 29static struct mutex aci_rds_mutex;
29 30
30#define RDS_DATASHIFT 2 /* Bit 2 */ 31#define RDS_DATASHIFT 2 /* Bit 2 */
31#define RDS_DATAMASK (1 << RDS_DATASHIFT) 32#define RDS_DATAMASK (1 << RDS_DATASHIFT)
@@ -181,7 +182,7 @@ int aci_rds_cmd(unsigned char cmd, unsigned char databuffer[], int datasize)
181{ 182{
182 int ret; 183 int ret;
183 184
184 if (down_interruptible(&aci_rds_sem)) 185 if (mutex_lock_interruptible(&aci_rds_mutex))
185 return -EINTR; 186 return -EINTR;
186 187
187 rds_write(cmd); 188 rds_write(cmd);
@@ -192,7 +193,7 @@ int aci_rds_cmd(unsigned char cmd, unsigned char databuffer[], int datasize)
192 else 193 else
193 ret = 0; 194 ret = 0;
194 195
195 up(&aci_rds_sem); 196 mutex_unlock(&aci_rds_mutex);
196 197
197 return ret; 198 return ret;
198} 199}
@@ -200,7 +201,7 @@ EXPORT_SYMBOL(aci_rds_cmd);
200 201
201int __init attach_aci_rds(void) 202int __init attach_aci_rds(void)
202{ 203{
203 init_MUTEX(&aci_rds_sem); 204 mutex_init(&aci_rds_mutex);
204 return 0; 205 return 0;
205} 206}
206 207
diff --git a/drivers/media/radio/radio-aimslab.c b/drivers/media/radio/radio-aimslab.c
index 914deab4e044..557fb5c4af38 100644
--- a/drivers/media/radio/radio-aimslab.c
+++ b/drivers/media/radio/radio-aimslab.c
@@ -43,7 +43,7 @@
43 43
44static int io = CONFIG_RADIO_RTRACK_PORT; 44static int io = CONFIG_RADIO_RTRACK_PORT;
45static int radio_nr = -1; 45static int radio_nr = -1;
46static struct semaphore lock; 46static struct mutex lock;
47 47
48struct rt_device 48struct rt_device
49{ 49{
@@ -83,23 +83,23 @@ static void rt_incvol(void)
83static void rt_mute(struct rt_device *dev) 83static void rt_mute(struct rt_device *dev)
84{ 84{
85 dev->muted = 1; 85 dev->muted = 1;
86 down(&lock); 86 mutex_lock(&lock);
87 outb(0xd0, io); /* volume steady, off */ 87 outb(0xd0, io); /* volume steady, off */
88 up(&lock); 88 mutex_unlock(&lock);
89} 89}
90 90
91static int rt_setvol(struct rt_device *dev, int vol) 91static int rt_setvol(struct rt_device *dev, int vol)
92{ 92{
93 int i; 93 int i;
94 94
95 down(&lock); 95 mutex_lock(&lock);
96 96
97 if(vol == dev->curvol) { /* requested volume = current */ 97 if(vol == dev->curvol) { /* requested volume = current */
98 if (dev->muted) { /* user is unmuting the card */ 98 if (dev->muted) { /* user is unmuting the card */
99 dev->muted = 0; 99 dev->muted = 0;
100 outb (0xd8, io); /* enable card */ 100 outb (0xd8, io); /* enable card */
101 } 101 }
102 up(&lock); 102 mutex_unlock(&lock);
103 return 0; 103 return 0;
104 } 104 }
105 105
@@ -108,7 +108,7 @@ static int rt_setvol(struct rt_device *dev, int vol)
108 sleep_delay(2000000); /* make sure it's totally down */ 108 sleep_delay(2000000); /* make sure it's totally down */
109 outb(0xd0, io); /* volume steady, off */ 109 outb(0xd0, io); /* volume steady, off */
110 dev->curvol = 0; /* track the volume state! */ 110 dev->curvol = 0; /* track the volume state! */
111 up(&lock); 111 mutex_unlock(&lock);
112 return 0; 112 return 0;
113 } 113 }
114 114
@@ -121,7 +121,7 @@ static int rt_setvol(struct rt_device *dev, int vol)
121 rt_decvol(); 121 rt_decvol();
122 122
123 dev->curvol = vol; 123 dev->curvol = vol;
124 up(&lock); 124 mutex_unlock(&lock);
125 return 0; 125 return 0;
126} 126}
127 127
@@ -168,7 +168,7 @@ static int rt_setfreq(struct rt_device *dev, unsigned long freq)
168 freq += 171200; /* Add 10.7 MHz IF */ 168 freq += 171200; /* Add 10.7 MHz IF */
169 freq /= 800; /* Convert to 50 kHz units */ 169 freq /= 800; /* Convert to 50 kHz units */
170 170
171 down(&lock); /* Stop other ops interfering */ 171 mutex_lock(&lock); /* Stop other ops interfering */
172 172
173 send_0_byte (io, dev); /* 0: LSB of frequency */ 173 send_0_byte (io, dev); /* 0: LSB of frequency */
174 174
@@ -196,7 +196,7 @@ static int rt_setfreq(struct rt_device *dev, unsigned long freq)
196 else 196 else
197 outb (0xd8, io); /* volume steady + sigstr + on */ 197 outb (0xd8, io); /* volume steady + sigstr + on */
198 198
199 up(&lock); 199 mutex_unlock(&lock);
200 200
201 return 0; 201 return 0;
202} 202}
@@ -337,7 +337,7 @@ static int __init rtrack_init(void)
337 337
338 /* Set up the I/O locking */ 338 /* Set up the I/O locking */
339 339
340 init_MUTEX(&lock); 340 mutex_init(&lock);
341 341
342 /* mute card - prevents noisy bootups */ 342 /* mute card - prevents noisy bootups */
343 343
diff --git a/drivers/media/radio/radio-aztech.c b/drivers/media/radio/radio-aztech.c
index 523be820f9c6..83bdae23417d 100644
--- a/drivers/media/radio/radio-aztech.c
+++ b/drivers/media/radio/radio-aztech.c
@@ -42,7 +42,7 @@
42static int io = CONFIG_RADIO_AZTECH_PORT; 42static int io = CONFIG_RADIO_AZTECH_PORT;
43static int radio_nr = -1; 43static int radio_nr = -1;
44static int radio_wait_time = 1000; 44static int radio_wait_time = 1000;
45static struct semaphore lock; 45static struct mutex lock;
46 46
47struct az_device 47struct az_device
48{ 48{
@@ -87,9 +87,9 @@ static void send_1_byte (struct az_device *dev)
87 87
88static int az_setvol(struct az_device *dev, int vol) 88static int az_setvol(struct az_device *dev, int vol)
89{ 89{
90 down(&lock); 90 mutex_lock(&lock);
91 outb (volconvert(vol), io); 91 outb (volconvert(vol), io);
92 up(&lock); 92 mutex_unlock(&lock);
93 return 0; 93 return 0;
94} 94}
95 95
@@ -122,7 +122,7 @@ static int az_setfreq(struct az_device *dev, unsigned long frequency)
122 frequency += 171200; /* Add 10.7 MHz IF */ 122 frequency += 171200; /* Add 10.7 MHz IF */
123 frequency /= 800; /* Convert to 50 kHz units */ 123 frequency /= 800; /* Convert to 50 kHz units */
124 124
125 down(&lock); 125 mutex_lock(&lock);
126 126
127 send_0_byte (dev); /* 0: LSB of frequency */ 127 send_0_byte (dev); /* 0: LSB of frequency */
128 128
@@ -152,7 +152,7 @@ static int az_setfreq(struct az_device *dev, unsigned long frequency)
152 udelay (radio_wait_time); 152 udelay (radio_wait_time);
153 outb_p(128+64+volconvert(dev->curvol), io); 153 outb_p(128+64+volconvert(dev->curvol), io);
154 154
155 up(&lock); 155 mutex_unlock(&lock);
156 156
157 return 0; 157 return 0;
158} 158}
@@ -283,7 +283,7 @@ static int __init aztech_init(void)
283 return -EBUSY; 283 return -EBUSY;
284 } 284 }
285 285
286 init_MUTEX(&lock); 286 mutex_init(&lock);
287 aztech_radio.priv=&aztech_unit; 287 aztech_radio.priv=&aztech_unit;
288 288
289 if(video_register_device(&aztech_radio, VFL_TYPE_RADIO, radio_nr)==-1) 289 if(video_register_device(&aztech_radio, VFL_TYPE_RADIO, radio_nr)==-1)
diff --git a/drivers/media/radio/radio-maestro.c b/drivers/media/radio/radio-maestro.c
index 36c9f5bf8cdd..39c1d9118636 100644
--- a/drivers/media/radio/radio-maestro.c
+++ b/drivers/media/radio/radio-maestro.c
@@ -23,10 +23,11 @@
23#include <linux/sched.h> 23#include <linux/sched.h>
24#include <asm/io.h> 24#include <asm/io.h>
25#include <asm/uaccess.h> 25#include <asm/uaccess.h>
26#include <asm/semaphore.h> 26#include <linux/mutex.h>
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/videodev.h> 28#include <linux/videodev.h>
29 29
30
30#define DRIVER_VERSION "0.05" 31#define DRIVER_VERSION "0.05"
31 32
32#define GPIO_DATA 0x60 /* port offset from ESS_IO_BASE */ 33#define GPIO_DATA 0x60 /* port offset from ESS_IO_BASE */
@@ -104,7 +105,7 @@ struct radio_device {
104 muted, /* VIDEO_AUDIO_MUTE */ 105 muted, /* VIDEO_AUDIO_MUTE */
105 stereo, /* VIDEO_TUNER_STEREO_ON */ 106 stereo, /* VIDEO_TUNER_STEREO_ON */
106 tuned; /* signal strength (0 or 0xffff) */ 107 tuned; /* signal strength (0 or 0xffff) */
107 struct semaphore lock; 108 struct mutex lock;
108}; 109};
109 110
110static u32 radio_bits_get(struct radio_device *dev) 111static u32 radio_bits_get(struct radio_device *dev)
@@ -258,9 +259,9 @@ static int radio_ioctl(struct inode *inode, struct file *file,
258 struct radio_device *card = video_get_drvdata(dev); 259 struct radio_device *card = video_get_drvdata(dev);
259 int ret; 260 int ret;
260 261
261 down(&card->lock); 262 mutex_lock(&card->lock);
262 ret = video_usercopy(inode, file, cmd, arg, radio_function); 263 ret = video_usercopy(inode, file, cmd, arg, radio_function);
263 up(&card->lock); 264 mutex_unlock(&card->lock);
264 265
265 return ret; 266 return ret;
266} 267}
@@ -311,7 +312,7 @@ static int __devinit maestro_probe(struct pci_dev *pdev,
311 } 312 }
312 313
313 radio_unit->io = pci_resource_start(pdev, 0) + GPIO_DATA; 314 radio_unit->io = pci_resource_start(pdev, 0) + GPIO_DATA;
314 init_MUTEX(&radio_unit->lock); 315 mutex_init(&radio_unit->lock);
315 316
316 maestro_radio_inst = video_device_alloc(); 317 maestro_radio_inst = video_device_alloc();
317 if (maestro_radio_inst == NULL) { 318 if (maestro_radio_inst == NULL) {
diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
index c975ddd86cd5..f0bf47bcb64c 100644
--- a/drivers/media/radio/radio-maxiradio.c
+++ b/drivers/media/radio/radio-maxiradio.c
@@ -37,7 +37,8 @@
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <asm/io.h> 38#include <asm/io.h>
39#include <asm/uaccess.h> 39#include <asm/uaccess.h>
40#include <asm/semaphore.h> 40#include <linux/mutex.h>
41
41#include <linux/pci.h> 42#include <linux/pci.h>
42#include <linux/videodev.h> 43#include <linux/videodev.h>
43 44
@@ -101,7 +102,7 @@ static struct radio_device
101 102
102 unsigned long freq; 103 unsigned long freq;
103 104
104 struct semaphore lock; 105 struct mutex lock;
105} radio_unit = {0, 0, 0, 0, }; 106} radio_unit = {0, 0, 0, 0, };
106 107
107 108
@@ -267,9 +268,9 @@ static int radio_ioctl(struct inode *inode, struct file *file,
267 struct radio_device *card=dev->priv; 268 struct radio_device *card=dev->priv;
268 int ret; 269 int ret;
269 270
270 down(&card->lock); 271 mutex_lock(&card->lock);
271 ret = video_usercopy(inode, file, cmd, arg, radio_function); 272 ret = video_usercopy(inode, file, cmd, arg, radio_function);
272 up(&card->lock); 273 mutex_unlock(&card->lock);
273 return ret; 274 return ret;
274} 275}
275 276
@@ -290,7 +291,7 @@ static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_d
290 goto err_out_free_region; 291 goto err_out_free_region;
291 292
292 radio_unit.io = pci_resource_start(pdev, 0); 293 radio_unit.io = pci_resource_start(pdev, 0);
293 init_MUTEX(&radio_unit.lock); 294 mutex_init(&radio_unit.lock);
294 maxiradio_radio.priv = &radio_unit; 295 maxiradio_radio.priv = &radio_unit;
295 296
296 if(video_register_device(&maxiradio_radio, VFL_TYPE_RADIO, radio_nr)==-1) { 297 if(video_register_device(&maxiradio_radio, VFL_TYPE_RADIO, radio_nr)==-1) {
diff --git a/drivers/media/radio/radio-sf16fmi.c b/drivers/media/radio/radio-sf16fmi.c
index 0229f792a059..53073b424107 100644
--- a/drivers/media/radio/radio-sf16fmi.c
+++ b/drivers/media/radio/radio-sf16fmi.c
@@ -24,7 +24,7 @@
24#include <linux/isapnp.h> 24#include <linux/isapnp.h>
25#include <asm/io.h> /* outb, outb_p */ 25#include <asm/io.h> /* outb, outb_p */
26#include <asm/uaccess.h> /* copy to/from user */ 26#include <asm/uaccess.h> /* copy to/from user */
27#include <asm/semaphore.h> 27#include <linux/mutex.h>
28 28
29struct fmi_device 29struct fmi_device
30{ 30{
@@ -37,7 +37,7 @@ struct fmi_device
37static int io = -1; 37static int io = -1;
38static int radio_nr = -1; 38static int radio_nr = -1;
39static struct pnp_dev *dev = NULL; 39static struct pnp_dev *dev = NULL;
40static struct semaphore lock; 40static struct mutex lock;
41 41
42/* freq is in 1/16 kHz to internal number, hw precision is 50 kHz */ 42/* freq is in 1/16 kHz to internal number, hw precision is 50 kHz */
43/* It is only useful to give freq in intervall of 800 (=0.05Mhz), 43/* It is only useful to give freq in intervall of 800 (=0.05Mhz),
@@ -68,16 +68,16 @@ static void outbits(int bits, unsigned int data, int port)
68 68
69static inline void fmi_mute(int port) 69static inline void fmi_mute(int port)
70{ 70{
71 down(&lock); 71 mutex_lock(&lock);
72 outb(0x00, port); 72 outb(0x00, port);
73 up(&lock); 73 mutex_unlock(&lock);
74} 74}
75 75
76static inline void fmi_unmute(int port) 76static inline void fmi_unmute(int port)
77{ 77{
78 down(&lock); 78 mutex_lock(&lock);
79 outb(0x08, port); 79 outb(0x08, port);
80 up(&lock); 80 mutex_unlock(&lock);
81} 81}
82 82
83static inline int fmi_setfreq(struct fmi_device *dev) 83static inline int fmi_setfreq(struct fmi_device *dev)
@@ -85,12 +85,12 @@ static inline int fmi_setfreq(struct fmi_device *dev)
85 int myport = dev->port; 85 int myport = dev->port;
86 unsigned long freq = dev->curfreq; 86 unsigned long freq = dev->curfreq;
87 87
88 down(&lock); 88 mutex_lock(&lock);
89 89
90 outbits(16, RSF16_ENCODE(freq), myport); 90 outbits(16, RSF16_ENCODE(freq), myport);
91 outbits(8, 0xC0, myport); 91 outbits(8, 0xC0, myport);
92 msleep(143); /* was schedule_timeout(HZ/7) */ 92 msleep(143); /* was schedule_timeout(HZ/7) */
93 up(&lock); 93 mutex_unlock(&lock);
94 if (dev->curvol) fmi_unmute(myport); 94 if (dev->curvol) fmi_unmute(myport);
95 return 0; 95 return 0;
96} 96}
@@ -102,7 +102,7 @@ static inline int fmi_getsigstr(struct fmi_device *dev)
102 int myport = dev->port; 102 int myport = dev->port;
103 103
104 104
105 down(&lock); 105 mutex_lock(&lock);
106 val = dev->curvol ? 0x08 : 0x00; /* unmute/mute */ 106 val = dev->curvol ? 0x08 : 0x00; /* unmute/mute */
107 outb(val, myport); 107 outb(val, myport);
108 outb(val | 0x10, myport); 108 outb(val | 0x10, myport);
@@ -110,7 +110,7 @@ static inline int fmi_getsigstr(struct fmi_device *dev)
110 res = (int)inb(myport+1); 110 res = (int)inb(myport+1);
111 outb(val, myport); 111 outb(val, myport);
112 112
113 up(&lock); 113 mutex_unlock(&lock);
114 return (res & 2) ? 0 : 0xFFFF; 114 return (res & 2) ? 0 : 0xFFFF;
115} 115}
116 116
@@ -296,7 +296,7 @@ static int __init fmi_init(void)
296 fmi_unit.flags = VIDEO_TUNER_LOW; 296 fmi_unit.flags = VIDEO_TUNER_LOW;
297 fmi_radio.priv = &fmi_unit; 297 fmi_radio.priv = &fmi_unit;
298 298
299 init_MUTEX(&lock); 299 mutex_init(&lock);
300 300
301 if (video_register_device(&fmi_radio, VFL_TYPE_RADIO, radio_nr) == -1) { 301 if (video_register_device(&fmi_radio, VFL_TYPE_RADIO, radio_nr) == -1) {
302 release_region(io, 2); 302 release_region(io, 2);
diff --git a/drivers/media/radio/radio-sf16fmr2.c b/drivers/media/radio/radio-sf16fmr2.c
index 099ffb3b9c71..bcebd8cb19ad 100644
--- a/drivers/media/radio/radio-sf16fmr2.c
+++ b/drivers/media/radio/radio-sf16fmr2.c
@@ -19,9 +19,9 @@
19#include <asm/io.h> /* outb, outb_p */ 19#include <asm/io.h> /* outb, outb_p */
20#include <asm/uaccess.h> /* copy to/from user */ 20#include <asm/uaccess.h> /* copy to/from user */
21#include <linux/videodev.h> /* kernel radio structs */ 21#include <linux/videodev.h> /* kernel radio structs */
22#include <asm/semaphore.h> 22#include <linux/mutex.h>
23 23
24static struct semaphore lock; 24static struct mutex lock;
25 25
26#undef DEBUG 26#undef DEBUG
27//#define DEBUG 1 27//#define DEBUG 1
@@ -238,9 +238,9 @@ static int fmr2_do_ioctl(struct inode *inode, struct file *file,
238 if (fmr2->mute) 238 if (fmr2->mute)
239 v->flags |= VIDEO_AUDIO_MUTE; 239 v->flags |= VIDEO_AUDIO_MUTE;
240 v->mode=VIDEO_MODE_AUTO; 240 v->mode=VIDEO_MODE_AUTO;
241 down(&lock); 241 mutex_lock(&lock);
242 v->signal = fmr2_getsigstr(fmr2); 242 v->signal = fmr2_getsigstr(fmr2);
243 up(&lock); 243 mutex_unlock(&lock);
244 return 0; 244 return 0;
245 } 245 }
246 case VIDIOCSTUNER: 246 case VIDIOCSTUNER:
@@ -274,9 +274,9 @@ static int fmr2_do_ioctl(struct inode *inode, struct file *file,
274 /* set card freq (if not muted) */ 274 /* set card freq (if not muted) */
275 if (fmr2->curvol && !fmr2->mute) 275 if (fmr2->curvol && !fmr2->mute)
276 { 276 {
277 down(&lock); 277 mutex_lock(&lock);
278 fmr2_setfreq(fmr2); 278 fmr2_setfreq(fmr2);
279 up(&lock); 279 mutex_unlock(&lock);
280 } 280 }
281 return 0; 281 return 0;
282 } 282 }
@@ -318,14 +318,14 @@ static int fmr2_do_ioctl(struct inode *inode, struct file *file,
318 else 318 else
319 printk(KERN_DEBUG "mute\n"); 319 printk(KERN_DEBUG "mute\n");
320#endif 320#endif
321 down(&lock); 321 mutex_lock(&lock);
322 if (fmr2->curvol && !fmr2->mute) 322 if (fmr2->curvol && !fmr2->mute)
323 { 323 {
324 fmr2_setvolume(fmr2); 324 fmr2_setvolume(fmr2);
325 fmr2_setfreq(fmr2); 325 fmr2_setfreq(fmr2);
326 } 326 }
327 else fmr2_mute(fmr2->port); 327 else fmr2_mute(fmr2->port);
328 up(&lock); 328 mutex_unlock(&lock);
329 return 0; 329 return 0;
330 } 330 }
331 case VIDIOCGUNIT: 331 case VIDIOCGUNIT:
@@ -380,7 +380,7 @@ static int __init fmr2_init(void)
380 fmr2_unit.card_type = 0; 380 fmr2_unit.card_type = 0;
381 fmr2_radio.priv = &fmr2_unit; 381 fmr2_radio.priv = &fmr2_unit;
382 382
383 init_MUTEX(&lock); 383 mutex_init(&lock);
384 384
385 if (request_region(io, 2, "sf16fmr2")) 385 if (request_region(io, 2, "sf16fmr2"))
386 { 386 {
@@ -397,10 +397,10 @@ static int __init fmr2_init(void)
397 printk(KERN_INFO "SF16FMR2 radio card driver at 0x%x.\n", io); 397 printk(KERN_INFO "SF16FMR2 radio card driver at 0x%x.\n", io);
398 debug_print((KERN_DEBUG "Mute %d Low %d\n",VIDEO_AUDIO_MUTE,VIDEO_TUNER_LOW)); 398 debug_print((KERN_DEBUG "Mute %d Low %d\n",VIDEO_AUDIO_MUTE,VIDEO_TUNER_LOW));
399 /* mute card - prevents noisy bootups */ 399 /* mute card - prevents noisy bootups */
400 down(&lock); 400 mutex_lock(&lock);
401 fmr2_mute(io); 401 fmr2_mute(io);
402 fmr2_product_info(&fmr2_unit); 402 fmr2_product_info(&fmr2_unit);
403 up(&lock); 403 mutex_unlock(&lock);
404 debug_print((KERN_DEBUG "card_type %d\n", fmr2_unit.card_type)); 404 debug_print((KERN_DEBUG "card_type %d\n", fmr2_unit.card_type));
405 return 0; 405 return 0;
406} 406}
diff --git a/drivers/media/radio/radio-typhoon.c b/drivers/media/radio/radio-typhoon.c
index 8ac9a8ef9094..e50955836d6b 100644
--- a/drivers/media/radio/radio-typhoon.c
+++ b/drivers/media/radio/radio-typhoon.c
@@ -59,7 +59,7 @@ struct typhoon_device {
59 int muted; 59 int muted;
60 unsigned long curfreq; 60 unsigned long curfreq;
61 unsigned long mutefreq; 61 unsigned long mutefreq;
62 struct semaphore lock; 62 struct mutex lock;
63}; 63};
64 64
65static void typhoon_setvol_generic(struct typhoon_device *dev, int vol); 65static void typhoon_setvol_generic(struct typhoon_device *dev, int vol);
@@ -77,12 +77,12 @@ static int typhoon_get_info(char *buf, char **start, off_t offset, int len);
77 77
78static void typhoon_setvol_generic(struct typhoon_device *dev, int vol) 78static void typhoon_setvol_generic(struct typhoon_device *dev, int vol)
79{ 79{
80 down(&dev->lock); 80 mutex_lock(&dev->lock);
81 vol >>= 14; /* Map 16 bit to 2 bit */ 81 vol >>= 14; /* Map 16 bit to 2 bit */
82 vol &= 3; 82 vol &= 3;
83 outb_p(vol / 2, dev->iobase); /* Set the volume, high bit. */ 83 outb_p(vol / 2, dev->iobase); /* Set the volume, high bit. */
84 outb_p(vol % 2, dev->iobase + 2); /* Set the volume, low bit. */ 84 outb_p(vol % 2, dev->iobase + 2); /* Set the volume, low bit. */
85 up(&dev->lock); 85 mutex_unlock(&dev->lock);
86} 86}
87 87
88static int typhoon_setfreq_generic(struct typhoon_device *dev, 88static int typhoon_setfreq_generic(struct typhoon_device *dev,
@@ -102,7 +102,7 @@ static int typhoon_setfreq_generic(struct typhoon_device *dev,
102 * 102 *
103 */ 103 */
104 104
105 down(&dev->lock); 105 mutex_lock(&dev->lock);
106 x = frequency / 160; 106 x = frequency / 160;
107 outval = (x * x + 2500) / 5000; 107 outval = (x * x + 2500) / 5000;
108 outval = (outval * x + 5000) / 10000; 108 outval = (outval * x + 5000) / 10000;
@@ -112,7 +112,7 @@ static int typhoon_setfreq_generic(struct typhoon_device *dev,
112 outb_p((outval >> 8) & 0x01, dev->iobase + 4); 112 outb_p((outval >> 8) & 0x01, dev->iobase + 4);
113 outb_p(outval >> 9, dev->iobase + 6); 113 outb_p(outval >> 9, dev->iobase + 6);
114 outb_p(outval & 0xff, dev->iobase + 8); 114 outb_p(outval & 0xff, dev->iobase + 8);
115 up(&dev->lock); 115 mutex_unlock(&dev->lock);
116 116
117 return 0; 117 return 0;
118} 118}
@@ -337,7 +337,7 @@ static int __init typhoon_init(void)
337#endif /* MODULE */ 337#endif /* MODULE */
338 338
339 printk(KERN_INFO BANNER); 339 printk(KERN_INFO BANNER);
340 init_MUTEX(&typhoon_unit.lock); 340 mutex_init(&typhoon_unit.lock);
341 io = typhoon_unit.iobase; 341 io = typhoon_unit.iobase;
342 if (!request_region(io, 8, "typhoon")) { 342 if (!request_region(io, 8, "typhoon")) {
343 printk(KERN_ERR "radio-typhoon: port 0x%x already in use\n", 343 printk(KERN_ERR "radio-typhoon: port 0x%x already in use\n",
diff --git a/drivers/media/radio/radio-zoltrix.c b/drivers/media/radio/radio-zoltrix.c
index d590e80c922e..7bf1a4264891 100644
--- a/drivers/media/radio/radio-zoltrix.c
+++ b/drivers/media/radio/radio-zoltrix.c
@@ -48,7 +48,7 @@ struct zol_device {
48 unsigned long curfreq; 48 unsigned long curfreq;
49 int muted; 49 int muted;
50 unsigned int stereo; 50 unsigned int stereo;
51 struct semaphore lock; 51 struct mutex lock;
52}; 52};
53 53
54static int zol_setvol(struct zol_device *dev, int vol) 54static int zol_setvol(struct zol_device *dev, int vol)
@@ -57,30 +57,30 @@ static int zol_setvol(struct zol_device *dev, int vol)
57 if (dev->muted) 57 if (dev->muted)
58 return 0; 58 return 0;
59 59
60 down(&dev->lock); 60 mutex_lock(&dev->lock);
61 if (vol == 0) { 61 if (vol == 0) {
62 outb(0, io); 62 outb(0, io);
63 outb(0, io); 63 outb(0, io);
64 inb(io + 3); /* Zoltrix needs to be read to confirm */ 64 inb(io + 3); /* Zoltrix needs to be read to confirm */
65 up(&dev->lock); 65 mutex_unlock(&dev->lock);
66 return 0; 66 return 0;
67 } 67 }
68 68
69 outb(dev->curvol-1, io); 69 outb(dev->curvol-1, io);
70 msleep(10); 70 msleep(10);
71 inb(io + 2); 71 inb(io + 2);
72 up(&dev->lock); 72 mutex_unlock(&dev->lock);
73 return 0; 73 return 0;
74} 74}
75 75
76static void zol_mute(struct zol_device *dev) 76static void zol_mute(struct zol_device *dev)
77{ 77{
78 dev->muted = 1; 78 dev->muted = 1;
79 down(&dev->lock); 79 mutex_lock(&dev->lock);
80 outb(0, io); 80 outb(0, io);
81 outb(0, io); 81 outb(0, io);
82 inb(io + 3); /* Zoltrix needs to be read to confirm */ 82 inb(io + 3); /* Zoltrix needs to be read to confirm */
83 up(&dev->lock); 83 mutex_unlock(&dev->lock);
84} 84}
85 85
86static void zol_unmute(struct zol_device *dev) 86static void zol_unmute(struct zol_device *dev)
@@ -104,7 +104,7 @@ static int zol_setfreq(struct zol_device *dev, unsigned long freq)
104 bitmask = 0xc480402c10080000ull; 104 bitmask = 0xc480402c10080000ull;
105 i = 45; 105 i = 45;
106 106
107 down(&dev->lock); 107 mutex_lock(&dev->lock);
108 108
109 outb(0, io); 109 outb(0, io);
110 outb(0, io); 110 outb(0, io);
@@ -149,7 +149,7 @@ static int zol_setfreq(struct zol_device *dev, unsigned long freq)
149 udelay(1000); 149 udelay(1000);
150 } 150 }
151 151
152 up(&dev->lock); 152 mutex_unlock(&dev->lock);
153 153
154 if(!dev->muted) 154 if(!dev->muted)
155 { 155 {
@@ -164,7 +164,7 @@ static int zol_getsigstr(struct zol_device *dev)
164{ 164{
165 int a, b; 165 int a, b;
166 166
167 down(&dev->lock); 167 mutex_lock(&dev->lock);
168 outb(0x00, io); /* This stuff I found to do nothing */ 168 outb(0x00, io); /* This stuff I found to do nothing */
169 outb(dev->curvol, io); 169 outb(dev->curvol, io);
170 msleep(20); 170 msleep(20);
@@ -173,7 +173,7 @@ static int zol_getsigstr(struct zol_device *dev)
173 msleep(10); 173 msleep(10);
174 b = inb(io); 174 b = inb(io);
175 175
176 up(&dev->lock); 176 mutex_unlock(&dev->lock);
177 177
178 if (a != b) 178 if (a != b)
179 return (0); 179 return (0);
@@ -188,7 +188,7 @@ static int zol_is_stereo (struct zol_device *dev)
188{ 188{
189 int x1, x2; 189 int x1, x2;
190 190
191 down(&dev->lock); 191 mutex_lock(&dev->lock);
192 192
193 outb(0x00, io); 193 outb(0x00, io);
194 outb(dev->curvol, io); 194 outb(dev->curvol, io);
@@ -198,7 +198,7 @@ static int zol_is_stereo (struct zol_device *dev)
198 msleep(10); 198 msleep(10);
199 x2 = inb(io); 199 x2 = inb(io);
200 200
201 up(&dev->lock); 201 mutex_unlock(&dev->lock);
202 202
203 if ((x1 == x2) && (x1 == 0xcf)) 203 if ((x1 == x2) && (x1 == 0xcf))
204 return 1; 204 return 1;
@@ -350,7 +350,7 @@ static int __init zoltrix_init(void)
350 } 350 }
351 printk(KERN_INFO "Zoltrix Radio Plus card driver.\n"); 351 printk(KERN_INFO "Zoltrix Radio Plus card driver.\n");
352 352
353 init_MUTEX(&zoltrix_unit.lock); 353 mutex_init(&zoltrix_unit.lock);
354 354
355 /* mute card - prevents noisy bootups */ 355 /* mute card - prevents noisy bootups */
356 356
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index d82c8a30ba44..c622a4da5663 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -26,6 +26,7 @@ config VIDEO_BT848
26 select VIDEO_IR 26 select VIDEO_IR
27 select VIDEO_TUNER 27 select VIDEO_TUNER
28 select VIDEO_TVEEPROM 28 select VIDEO_TVEEPROM
29 select VIDEO_MSP3400
29 ---help--- 30 ---help---
30 Support for BT848 based frame grabber/overlay boards. This includes 31 Support for BT848 based frame grabber/overlay boards. This includes
31 the Miro, Hauppauge and STB boards. Please read the material in 32 the Miro, Hauppauge and STB boards. Please read the material in
@@ -142,6 +143,8 @@ config VIDEO_CPIA_USB
142 otherwise say N. This will not work with the Creative Webcam III. 143 otherwise say N. This will not work with the Creative Webcam III.
143 It is also available as a module (cpia_usb). 144 It is also available as a module (cpia_usb).
144 145
146source "drivers/media/video/cpia2/Kconfig"
147
145config VIDEO_SAA5246A 148config VIDEO_SAA5246A
146 tristate "SAA5246A, SAA5281 Teletext processor" 149 tristate "SAA5246A, SAA5281 Teletext processor"
147 depends on VIDEO_DEV && I2C 150 depends on VIDEO_DEV && I2C
@@ -339,18 +342,53 @@ config VIDEO_M32R_AR_M64278
339 Say Y here to use the Renesas M64278E-800 camera module, 342 Say Y here to use the Renesas M64278E-800 camera module,
340 which supports VGA(640x480 pixcels) size of images. 343 which supports VGA(640x480 pixcels) size of images.
341 344
342config VIDEO_AUDIO_DECODER 345config VIDEO_MSP3400
343 tristate "Add support for additional audio chipsets" 346 tristate "Micronas MSP34xx audio decoders"
347 depends on VIDEO_DEV && I2C
348 ---help---
349 Support for the Micronas MSP34xx series of audio decoders.
350
351 To compile this driver as a module, choose M here: the
352 module will be called msp3400
353
354config VIDEO_CS53L32A
355 tristate "Cirrus Logic CS53L32A audio ADC"
344 depends on VIDEO_DEV && I2C && EXPERIMENTAL 356 depends on VIDEO_DEV && I2C && EXPERIMENTAL
345 ---help--- 357 ---help---
346 Say Y here to compile drivers for WM8775 and CS53L32A audio 358 Support for the Cirrus Logic CS53L32A low voltage
347 decoders. 359 stereo A/D converter.
348 360
349config VIDEO_DECODER 361 To compile this driver as a module, choose M here: the
350 tristate "Add support for additional video chipsets" 362 module will be called cs53l32a
363
364config VIDEO_WM8775
365 tristate "Wolfson Microelectronics WM8775 audio ADC"
351 depends on VIDEO_DEV && I2C && EXPERIMENTAL 366 depends on VIDEO_DEV && I2C && EXPERIMENTAL
352 ---help--- 367 ---help---
353 Say Y here to compile drivers for SAA7115, SAA7127 and CX25840 368 Support for the Wolfson Microelectronics WM8775
354 video decoders. 369 high performance stereo A/D Converter.
370
371 To compile this driver as a module, choose M here: the
372 module will be called wm8775
373
374source "drivers/media/video/cx25840/Kconfig"
375
376config VIDEO_SAA711X
377 tristate "Philips SAA7113/4/5 video decoders"
378 depends on VIDEO_DEV && I2C && EXPERIMENTAL
379 ---help---
380 Support for the Philips SAA7113/4/5 video decoders.
381
382 To compile this driver as a module, choose M here: the
383 module will be called saa7115
384
385config VIDEO_SAA7127
386 tristate "Philips SAA7127/9 digital video encoders"
387 depends on VIDEO_DEV && I2C && EXPERIMENTAL
388 ---help---
389 Support for the Philips SAA7127/9 digital video encoders.
390
391 To compile this driver as a module, choose M here: the
392 module will be called saa7127
355 393
356endmenu 394endmenu
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index faf728366c4e..f2bd4c0c4f10 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -15,7 +15,7 @@ msp3400-objs := msp3400-driver.o msp3400-kthreads.o
15 15
16obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o v4l1-compat.o compat_ioctl32.o 16obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o v4l1-compat.o compat_ioctl32.o
17 17
18obj-$(CONFIG_VIDEO_BT848) += bttv.o msp3400.o tvaudio.o \ 18obj-$(CONFIG_VIDEO_BT848) += bttv.o tvaudio.o \
19 tda7432.o tda9875.o ir-kbd-i2c.o 19 tda7432.o tda9875.o ir-kbd-i2c.o
20obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o 20obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o
21 21
@@ -44,10 +44,13 @@ obj-$(CONFIG_VIDEO_MEYE) += meye.o
44obj-$(CONFIG_VIDEO_SAA7134) += ir-kbd-i2c.o saa7134/ 44obj-$(CONFIG_VIDEO_SAA7134) += ir-kbd-i2c.o saa7134/
45obj-$(CONFIG_VIDEO_CX88) += cx88/ 45obj-$(CONFIG_VIDEO_CX88) += cx88/
46obj-$(CONFIG_VIDEO_EM28XX) += em28xx/ 46obj-$(CONFIG_VIDEO_EM28XX) += em28xx/
47obj-$(CONFIG_VIDEO_EM28XX) += saa711x.o tvp5150.o 47obj-$(CONFIG_VIDEO_EM28XX) += tvp5150.o
48obj-$(CONFIG_VIDEO_AUDIO_DECODER) += wm8775.o cs53l32a.o 48obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o
49obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o
50obj-$(CONFIG_VIDEO_WM8775) += wm8775.o
49obj-$(CONFIG_VIDEO_OVCAMCHIP) += ovcamchip/ 51obj-$(CONFIG_VIDEO_OVCAMCHIP) += ovcamchip/
50obj-$(CONFIG_VIDEO_MXB) += saa7111.o tuner.o tda9840.o tea6415c.o tea6420.o mxb.o 52obj-$(CONFIG_VIDEO_CPIA2) += cpia2/
53obj-$(CONFIG_VIDEO_MXB) += saa7111.o tda9840.o tea6415c.o tea6420.o mxb.o
51obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o 54obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o
52obj-$(CONFIG_VIDEO_HEXIUM_GEMINI) += hexium_gemini.o 55obj-$(CONFIG_VIDEO_HEXIUM_GEMINI) += hexium_gemini.o
53obj-$(CONFIG_VIDEO_DPC) += saa7111.o dpc7146.o 56obj-$(CONFIG_VIDEO_DPC) += saa7111.o dpc7146.o
@@ -61,6 +64,8 @@ obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o
61 64
62obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o 65obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
63 66
64obj-$(CONFIG_VIDEO_DECODER) += saa7115.o cx25840/ saa7127.o 67obj-$(CONFIG_VIDEO_CX25840) += cx25840/
68obj-$(CONFIG_VIDEO_SAA711X) += saa7115.o
69obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
65 70
66EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/dvb-core 71EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/dvb-core
diff --git a/drivers/media/video/arv.c b/drivers/media/video/arv.c
index 994b75fe165a..c586f64b6b7f 100644
--- a/drivers/media/video/arv.c
+++ b/drivers/media/video/arv.c
@@ -31,8 +31,8 @@
31#include <linux/mm.h> 31#include <linux/mm.h>
32#include <linux/sched.h> 32#include <linux/sched.h>
33#include <linux/videodev.h> 33#include <linux/videodev.h>
34#include <linux/mutex.h>
34 35
35#include <asm/semaphore.h>
36#include <asm/uaccess.h> 36#include <asm/uaccess.h>
37#include <asm/m32r.h> 37#include <asm/m32r.h>
38#include <asm/io.h> 38#include <asm/io.h>
@@ -117,7 +117,7 @@ struct ar_device {
117 int width, height; 117 int width, height;
118 int frame_bytes, line_bytes; 118 int frame_bytes, line_bytes;
119 wait_queue_head_t wait; 119 wait_queue_head_t wait;
120 struct semaphore lock; 120 struct mutex lock;
121}; 121};
122 122
123static int video_nr = -1; /* video device number (first free) */ 123static int video_nr = -1; /* video device number (first free) */
@@ -288,7 +288,7 @@ static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
288 if (ar->mode == AR_MODE_NORMAL) 288 if (ar->mode == AR_MODE_NORMAL)
289 arvcr1 |= ARVCR1_NORMAL; 289 arvcr1 |= ARVCR1_NORMAL;
290 290
291 down(&ar->lock); 291 mutex_lock(&ar->lock);
292 292
293#if USE_INT 293#if USE_INT
294 local_irq_save(flags); 294 local_irq_save(flags);
@@ -392,7 +392,7 @@ static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
392 } 392 }
393 DEBUG(1, "ret = %d\n", ret); 393 DEBUG(1, "ret = %d\n", ret);
394out_up: 394out_up:
395 up(&ar->lock); 395 mutex_unlock(&ar->lock);
396 return ret; 396 return ret;
397} 397}
398 398
@@ -456,7 +456,7 @@ static int ar_do_ioctl(struct inode *inode, struct file *file,
456 (w->width != AR_WIDTH_QVGA || w->height != AR_HEIGHT_QVGA)) 456 (w->width != AR_WIDTH_QVGA || w->height != AR_HEIGHT_QVGA))
457 return -EINVAL; 457 return -EINVAL;
458 458
459 down(&ar->lock); 459 mutex_lock(&ar->lock);
460 ar->width = w->width; 460 ar->width = w->width;
461 ar->height = w->height; 461 ar->height = w->height;
462 if (ar->width == AR_WIDTH_VGA) { 462 if (ar->width == AR_WIDTH_VGA) {
@@ -473,7 +473,7 @@ static int ar_do_ioctl(struct inode *inode, struct file *file,
473 ar->line_bytes = AR_LINE_BYTES_QVGA; 473 ar->line_bytes = AR_LINE_BYTES_QVGA;
474 ar->mode = AR_MODE_INTERLACE; 474 ar->mode = AR_MODE_INTERLACE;
475 } 475 }
476 up(&ar->lock); 476 mutex_unlock(&ar->lock);
477 return 0; 477 return 0;
478 } 478 }
479 case VIDIOCGFBUF: 479 case VIDIOCGFBUF:
@@ -734,7 +734,7 @@ static int ar_initialize(struct video_device *dev)
734void ar_release(struct video_device *vfd) 734void ar_release(struct video_device *vfd)
735{ 735{
736 struct ar_device *ar = vfd->priv; 736 struct ar_device *ar = vfd->priv;
737 down(&ar->lock); 737 mutex_lock(&ar->lock);
738 video_device_release(vfd); 738 video_device_release(vfd);
739} 739}
740 740
@@ -824,7 +824,7 @@ static int __init ar_init(void)
824 ar->line_bytes = AR_LINE_BYTES_QVGA; 824 ar->line_bytes = AR_LINE_BYTES_QVGA;
825 ar->mode = AR_MODE_INTERLACE; 825 ar->mode = AR_MODE_INTERLACE;
826 } 826 }
827 init_MUTEX(&ar->lock); 827 mutex_init(&ar->lock);
828 init_waitqueue_head(&ar->wait); 828 init_waitqueue_head(&ar->wait);
829 829
830#if USE_INT 830#if USE_INT
diff --git a/drivers/media/video/bttv-cards.c b/drivers/media/video/bttv-cards.c
index 9749d6ed6231..abfa6ad857a0 100644
--- a/drivers/media/video/bttv-cards.c
+++ b/drivers/media/video/bttv-cards.c
@@ -137,6 +137,8 @@ MODULE_PARM_DESC(card,"specify TV/grabber card model, see CARDLIST file for a li
137MODULE_PARM_DESC(pll,"specify installed crystal (0=none, 28=28 MHz, 35=35 MHz)"); 137MODULE_PARM_DESC(pll,"specify installed crystal (0=none, 28=28 MHz, 35=35 MHz)");
138MODULE_PARM_DESC(tuner,"specify installed tuner type"); 138MODULE_PARM_DESC(tuner,"specify installed tuner type");
139MODULE_PARM_DESC(autoload,"automatically load i2c modules like tuner.o, default is 1 (yes)"); 139MODULE_PARM_DESC(autoload,"automatically load i2c modules like tuner.o, default is 1 (yes)");
140MODULE_PARM_DESC(no_overlay,"allow override overlay default (0 disables, 1 enables)"
141 " [some VIA/SIS chipsets are known to have problem with overlay]");
140 142
141/* ----------------------------------------------------------------------- */ 143/* ----------------------------------------------------------------------- */
142/* list of card IDs for bt878+ cards */ 144/* list of card IDs for bt878+ cards */
@@ -275,7 +277,6 @@ static struct CARD {
275 { 0x03116000, BTTV_BOARD_SENSORAY311, "Sensoray 311" }, 277 { 0x03116000, BTTV_BOARD_SENSORAY311, "Sensoray 311" },
276 { 0x00790e11, BTTV_BOARD_WINDVR, "Canopus WinDVR PCI" }, 278 { 0x00790e11, BTTV_BOARD_WINDVR, "Canopus WinDVR PCI" },
277 { 0xa0fca1a0, BTTV_BOARD_ZOLTRIX, "Face to Face Tvmax" }, 279 { 0xa0fca1a0, BTTV_BOARD_ZOLTRIX, "Face to Face Tvmax" },
278 { 0x20007063, BTTV_BOARD_PC_HDTV, "pcHDTV HD-2000 TV"},
279 { 0x82b2aa6a, BTTV_BOARD_SIMUS_GVC1100, "SIMUS GVC1100" }, 280 { 0x82b2aa6a, BTTV_BOARD_SIMUS_GVC1100, "SIMUS GVC1100" },
280 { 0x146caa0c, BTTV_BOARD_PV951, "ituner spectra8" }, 281 { 0x146caa0c, BTTV_BOARD_PV951, "ituner spectra8" },
281 { 0x200a1295, BTTV_BOARD_PXC200, "ImageNation PXC200A" }, 282 { 0x200a1295, BTTV_BOARD_PXC200, "ImageNation PXC200A" },
@@ -297,13 +298,14 @@ static struct CARD {
297 * { 0x13eb0070, BTTV_BOARD_HAUPPAUGE_IMPACTVCB, "Hauppauge ImpactVCB" }, */ 298 * { 0x13eb0070, BTTV_BOARD_HAUPPAUGE_IMPACTVCB, "Hauppauge ImpactVCB" }, */
298 299
299 /* DVB cards (using pci function .1 for mpeg data xfer) */ 300 /* DVB cards (using pci function .1 for mpeg data xfer) */
300 { 0x01010071, BTTV_BOARD_NEBULA_DIGITV, "Nebula Electronics DigiTV" },
301 { 0x07611461, BTTV_BOARD_AVDVBT_761, "AverMedia AverTV DVB-T 761" },
302 { 0x001c11bd, BTTV_BOARD_PINNACLESAT, "Pinnacle PCTV Sat" }, 301 { 0x001c11bd, BTTV_BOARD_PINNACLESAT, "Pinnacle PCTV Sat" },
302 { 0x01010071, BTTV_BOARD_NEBULA_DIGITV, "Nebula Electronics DigiTV" },
303 { 0x20007063, BTTV_BOARD_PC_HDTV, "pcHDTV HD-2000 TV"},
303 { 0x002611bd, BTTV_BOARD_TWINHAN_DST, "Pinnacle PCTV SAT CI" }, 304 { 0x002611bd, BTTV_BOARD_TWINHAN_DST, "Pinnacle PCTV SAT CI" },
304 { 0x00011822, BTTV_BOARD_TWINHAN_DST, "Twinhan VisionPlus DVB" }, 305 { 0x00011822, BTTV_BOARD_TWINHAN_DST, "Twinhan VisionPlus DVB" },
305 { 0xfc00270f, BTTV_BOARD_TWINHAN_DST, "ChainTech digitop DST-1000 DVB-S" }, 306 { 0xfc00270f, BTTV_BOARD_TWINHAN_DST, "ChainTech digitop DST-1000 DVB-S" },
306 { 0x07711461, BTTV_BOARD_AVDVBT_771, "AVermedia AverTV DVB-T 771" }, 307 { 0x07711461, BTTV_BOARD_AVDVBT_771, "AVermedia AverTV DVB-T 771" },
308 { 0x07611461, BTTV_BOARD_AVDVBT_761, "AverMedia AverTV DVB-T 761" },
307 { 0xdb1018ac, BTTV_BOARD_DVICO_DVBT_LITE, "DViCO FusionHDTV DVB-T Lite" }, 309 { 0xdb1018ac, BTTV_BOARD_DVICO_DVBT_LITE, "DViCO FusionHDTV DVB-T Lite" },
308 { 0xd50018ac, BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE, "DViCO FusionHDTV 5 Lite" }, 310 { 0xd50018ac, BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE, "DViCO FusionHDTV 5 Lite" },
309 311
@@ -4944,12 +4946,14 @@ void __devinit bttv_check_chipset(void)
4944 if (vsfx) 4946 if (vsfx)
4945 printk(KERN_INFO "bttv: Host bridge needs VSFX enabled.\n"); 4947 printk(KERN_INFO "bttv: Host bridge needs VSFX enabled.\n");
4946 if (pcipci_fail) { 4948 if (pcipci_fail) {
4947 printk(KERN_WARNING "bttv: BT848 and your chipset may not work together.\n"); 4949 printk(KERN_INFO "bttv: bttv and your chipset may not work "
4950 "together.\n");
4948 if (!no_overlay) { 4951 if (!no_overlay) {
4949 printk(KERN_WARNING "bttv: overlay will be disabled.\n"); 4952 printk(KERN_INFO "bttv: overlay will be disabled.\n");
4950 no_overlay = 1; 4953 no_overlay = 1;
4951 } else { 4954 } else {
4952 printk(KERN_WARNING "bttv: overlay forced. Use this option at your own risk.\n"); 4955 printk(KERN_INFO "bttv: overlay forced. Use this "
4956 "option at your own risk.\n");
4953 } 4957 }
4954 } 4958 }
4955 if (UNSET != latency) 4959 if (UNSET != latency)
diff --git a/drivers/media/video/bttv-driver.c b/drivers/media/video/bttv-driver.c
index 578b20085082..c0415d6e7fee 100644
--- a/drivers/media/video/bttv-driver.c
+++ b/drivers/media/video/bttv-driver.c
@@ -1965,7 +1965,7 @@ static int setup_window(struct bttv_fh *fh, struct bttv *btv,
1965 BUG(); 1965 BUG();
1966 } 1966 }
1967 1967
1968 down(&fh->cap.lock); 1968 mutex_lock(&fh->cap.lock);
1969 kfree(fh->ov.clips); 1969 kfree(fh->ov.clips);
1970 fh->ov.clips = clips; 1970 fh->ov.clips = clips;
1971 fh->ov.nclips = n; 1971 fh->ov.nclips = n;
@@ -1986,7 +1986,7 @@ static int setup_window(struct bttv_fh *fh, struct bttv *btv,
1986 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); 1986 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
1987 retval = bttv_switch_overlay(btv,fh,new); 1987 retval = bttv_switch_overlay(btv,fh,new);
1988 } 1988 }
1989 up(&fh->cap.lock); 1989 mutex_unlock(&fh->cap.lock);
1990 return retval; 1990 return retval;
1991} 1991}
1992 1992
@@ -2166,7 +2166,7 @@ static int bttv_s_fmt(struct bttv_fh *fh, struct bttv *btv,
2166 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 2166 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
2167 2167
2168 /* update our state informations */ 2168 /* update our state informations */
2169 down(&fh->cap.lock); 2169 mutex_lock(&fh->cap.lock);
2170 fh->fmt = fmt; 2170 fh->fmt = fmt;
2171 fh->cap.field = f->fmt.pix.field; 2171 fh->cap.field = f->fmt.pix.field;
2172 fh->cap.last = V4L2_FIELD_NONE; 2172 fh->cap.last = V4L2_FIELD_NONE;
@@ -2175,7 +2175,7 @@ static int bttv_s_fmt(struct bttv_fh *fh, struct bttv *btv,
2175 btv->init.fmt = fmt; 2175 btv->init.fmt = fmt;
2176 btv->init.width = f->fmt.pix.width; 2176 btv->init.width = f->fmt.pix.width;
2177 btv->init.height = f->fmt.pix.height; 2177 btv->init.height = f->fmt.pix.height;
2178 up(&fh->cap.lock); 2178 mutex_unlock(&fh->cap.lock);
2179 2179
2180 return 0; 2180 return 0;
2181 } 2181 }
@@ -2282,7 +2282,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2282 fmt = format_by_palette(pic->palette); 2282 fmt = format_by_palette(pic->palette);
2283 if (NULL == fmt) 2283 if (NULL == fmt)
2284 return -EINVAL; 2284 return -EINVAL;
2285 down(&fh->cap.lock); 2285 mutex_lock(&fh->cap.lock);
2286 if (fmt->depth != pic->depth) { 2286 if (fmt->depth != pic->depth) {
2287 retval = -EINVAL; 2287 retval = -EINVAL;
2288 goto fh_unlock_and_return; 2288 goto fh_unlock_and_return;
@@ -2313,7 +2313,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2313 bt848_contrast(btv,pic->contrast); 2313 bt848_contrast(btv,pic->contrast);
2314 bt848_hue(btv,pic->hue); 2314 bt848_hue(btv,pic->hue);
2315 bt848_sat(btv,pic->colour); 2315 bt848_sat(btv,pic->colour);
2316 up(&fh->cap.lock); 2316 mutex_unlock(&fh->cap.lock);
2317 return 0; 2317 return 0;
2318 } 2318 }
2319 2319
@@ -2379,7 +2379,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2379 return -EPERM; 2379 return -EPERM;
2380 end = (unsigned long)fbuf->base + 2380 end = (unsigned long)fbuf->base +
2381 fbuf->height * fbuf->bytesperline; 2381 fbuf->height * fbuf->bytesperline;
2382 down(&fh->cap.lock); 2382 mutex_lock(&fh->cap.lock);
2383 retval = -EINVAL; 2383 retval = -EINVAL;
2384 2384
2385 switch (fbuf->depth) { 2385 switch (fbuf->depth) {
@@ -2417,7 +2417,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2417 btv->fbuf.fmt.bytesperline = fbuf->bytesperline; 2417 btv->fbuf.fmt.bytesperline = fbuf->bytesperline;
2418 else 2418 else
2419 btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fbuf->depth/8; 2419 btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fbuf->depth/8;
2420 up(&fh->cap.lock); 2420 mutex_unlock(&fh->cap.lock);
2421 return 0; 2421 return 0;
2422 } 2422 }
2423 2423
@@ -2440,7 +2440,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2440 if (!check_alloc_btres(btv,fh,RESOURCE_OVERLAY)) 2440 if (!check_alloc_btres(btv,fh,RESOURCE_OVERLAY))
2441 return -EBUSY; 2441 return -EBUSY;
2442 2442
2443 down(&fh->cap.lock); 2443 mutex_lock(&fh->cap.lock);
2444 if (*on) { 2444 if (*on) {
2445 fh->ov.tvnorm = btv->tvnorm; 2445 fh->ov.tvnorm = btv->tvnorm;
2446 new = videobuf_alloc(sizeof(*new)); 2446 new = videobuf_alloc(sizeof(*new));
@@ -2451,7 +2451,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2451 2451
2452 /* switch over */ 2452 /* switch over */
2453 retval = bttv_switch_overlay(btv,fh,new); 2453 retval = bttv_switch_overlay(btv,fh,new);
2454 up(&fh->cap.lock); 2454 mutex_unlock(&fh->cap.lock);
2455 return retval; 2455 return retval;
2456 } 2456 }
2457 2457
@@ -2460,7 +2460,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2460 struct video_mbuf *mbuf = arg; 2460 struct video_mbuf *mbuf = arg;
2461 unsigned int i; 2461 unsigned int i;
2462 2462
2463 down(&fh->cap.lock); 2463 mutex_lock(&fh->cap.lock);
2464 retval = videobuf_mmap_setup(&fh->cap,gbuffers,gbufsize, 2464 retval = videobuf_mmap_setup(&fh->cap,gbuffers,gbufsize,
2465 V4L2_MEMORY_MMAP); 2465 V4L2_MEMORY_MMAP);
2466 if (retval < 0) 2466 if (retval < 0)
@@ -2470,7 +2470,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2470 mbuf->size = gbuffers * gbufsize; 2470 mbuf->size = gbuffers * gbufsize;
2471 for (i = 0; i < gbuffers; i++) 2471 for (i = 0; i < gbuffers; i++)
2472 mbuf->offsets[i] = i * gbufsize; 2472 mbuf->offsets[i] = i * gbufsize;
2473 up(&fh->cap.lock); 2473 mutex_unlock(&fh->cap.lock);
2474 return 0; 2474 return 0;
2475 } 2475 }
2476 case VIDIOCMCAPTURE: 2476 case VIDIOCMCAPTURE:
@@ -2482,7 +2482,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2482 if (vm->frame >= VIDEO_MAX_FRAME) 2482 if (vm->frame >= VIDEO_MAX_FRAME)
2483 return -EINVAL; 2483 return -EINVAL;
2484 2484
2485 down(&fh->cap.lock); 2485 mutex_lock(&fh->cap.lock);
2486 retval = -EINVAL; 2486 retval = -EINVAL;
2487 buf = (struct bttv_buffer *)fh->cap.bufs[vm->frame]; 2487 buf = (struct bttv_buffer *)fh->cap.bufs[vm->frame];
2488 if (NULL == buf) 2488 if (NULL == buf)
@@ -2504,7 +2504,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2504 spin_lock_irqsave(&btv->s_lock,flags); 2504 spin_lock_irqsave(&btv->s_lock,flags);
2505 buffer_queue(&fh->cap,&buf->vb); 2505 buffer_queue(&fh->cap,&buf->vb);
2506 spin_unlock_irqrestore(&btv->s_lock,flags); 2506 spin_unlock_irqrestore(&btv->s_lock,flags);
2507 up(&fh->cap.lock); 2507 mutex_unlock(&fh->cap.lock);
2508 return 0; 2508 return 0;
2509 } 2509 }
2510 case VIDIOCSYNC: 2510 case VIDIOCSYNC:
@@ -2515,7 +2515,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2515 if (*frame >= VIDEO_MAX_FRAME) 2515 if (*frame >= VIDEO_MAX_FRAME)
2516 return -EINVAL; 2516 return -EINVAL;
2517 2517
2518 down(&fh->cap.lock); 2518 mutex_lock(&fh->cap.lock);
2519 retval = -EINVAL; 2519 retval = -EINVAL;
2520 buf = (struct bttv_buffer *)fh->cap.bufs[*frame]; 2520 buf = (struct bttv_buffer *)fh->cap.bufs[*frame];
2521 if (NULL == buf) 2521 if (NULL == buf)
@@ -2535,7 +2535,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2535 retval = -EINVAL; 2535 retval = -EINVAL;
2536 break; 2536 break;
2537 } 2537 }
2538 up(&fh->cap.lock); 2538 mutex_unlock(&fh->cap.lock);
2539 return retval; 2539 return retval;
2540 } 2540 }
2541 2541
@@ -2719,7 +2719,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2719 if (0 == (fmt->flags & FORMAT_FLAGS_PACKED)) 2719 if (0 == (fmt->flags & FORMAT_FLAGS_PACKED))
2720 return -EINVAL; 2720 return -EINVAL;
2721 2721
2722 down(&fh->cap.lock); 2722 mutex_lock(&fh->cap.lock);
2723 retval = -EINVAL; 2723 retval = -EINVAL;
2724 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) { 2724 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) {
2725 if (fb->fmt.width > bttv_tvnorms[btv->tvnorm].swidth) 2725 if (fb->fmt.width > bttv_tvnorms[btv->tvnorm].swidth)
@@ -2759,7 +2759,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2759 retval = bttv_switch_overlay(btv,fh,new); 2759 retval = bttv_switch_overlay(btv,fh,new);
2760 } 2760 }
2761 } 2761 }
2762 up(&fh->cap.lock); 2762 mutex_unlock(&fh->cap.lock);
2763 return retval; 2763 return retval;
2764 } 2764 }
2765 2765
@@ -2890,7 +2890,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2890 return 0; 2890 return 0;
2891 2891
2892 fh_unlock_and_return: 2892 fh_unlock_and_return:
2893 up(&fh->cap.lock); 2893 mutex_unlock(&fh->cap.lock);
2894 return retval; 2894 return retval;
2895} 2895}
2896 2896
@@ -2957,16 +2957,16 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
2957 buf = list_entry(fh->cap.stream.next,struct bttv_buffer,vb.stream); 2957 buf = list_entry(fh->cap.stream.next,struct bttv_buffer,vb.stream);
2958 } else { 2958 } else {
2959 /* read() capture */ 2959 /* read() capture */
2960 down(&fh->cap.lock); 2960 mutex_lock(&fh->cap.lock);
2961 if (NULL == fh->cap.read_buf) { 2961 if (NULL == fh->cap.read_buf) {
2962 /* need to capture a new frame */ 2962 /* need to capture a new frame */
2963 if (locked_btres(fh->btv,RESOURCE_VIDEO)) { 2963 if (locked_btres(fh->btv,RESOURCE_VIDEO)) {
2964 up(&fh->cap.lock); 2964 mutex_unlock(&fh->cap.lock);
2965 return POLLERR; 2965 return POLLERR;
2966 } 2966 }
2967 fh->cap.read_buf = videobuf_alloc(fh->cap.msize); 2967 fh->cap.read_buf = videobuf_alloc(fh->cap.msize);
2968 if (NULL == fh->cap.read_buf) { 2968 if (NULL == fh->cap.read_buf) {
2969 up(&fh->cap.lock); 2969 mutex_unlock(&fh->cap.lock);
2970 return POLLERR; 2970 return POLLERR;
2971 } 2971 }
2972 fh->cap.read_buf->memory = V4L2_MEMORY_USERPTR; 2972 fh->cap.read_buf->memory = V4L2_MEMORY_USERPTR;
@@ -2974,13 +2974,13 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
2974 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,field)) { 2974 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,field)) {
2975 kfree (fh->cap.read_buf); 2975 kfree (fh->cap.read_buf);
2976 fh->cap.read_buf = NULL; 2976 fh->cap.read_buf = NULL;
2977 up(&fh->cap.lock); 2977 mutex_unlock(&fh->cap.lock);
2978 return POLLERR; 2978 return POLLERR;
2979 } 2979 }
2980 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf); 2980 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf);
2981 fh->cap.read_off = 0; 2981 fh->cap.read_off = 0;
2982 } 2982 }
2983 up(&fh->cap.lock); 2983 mutex_unlock(&fh->cap.lock);
2984 buf = (struct bttv_buffer*)fh->cap.read_buf; 2984 buf = (struct bttv_buffer*)fh->cap.read_buf;
2985 } 2985 }
2986 2986
diff --git a/drivers/media/video/bttv-input.c b/drivers/media/video/bttv-input.c
index 221b36e7f392..69efa0e5174d 100644
--- a/drivers/media/video/bttv-input.c
+++ b/drivers/media/video/bttv-input.c
@@ -28,251 +28,6 @@
28#include "bttv.h" 28#include "bttv.h"
29#include "bttvp.h" 29#include "bttvp.h"
30 30
31/* ---------------------------------------------------------------------- */
32
33static IR_KEYTAB_TYPE ir_codes_avermedia[IR_KEYTAB_SIZE] = {
34 [ 34 ] = KEY_KP0,
35 [ 40 ] = KEY_KP1,
36 [ 24 ] = KEY_KP2,
37 [ 56 ] = KEY_KP3,
38 [ 36 ] = KEY_KP4,
39 [ 20 ] = KEY_KP5,
40 [ 52 ] = KEY_KP6,
41 [ 44 ] = KEY_KP7,
42 [ 28 ] = KEY_KP8,
43 [ 60 ] = KEY_KP9,
44
45 [ 48 ] = KEY_EJECTCD, // Unmarked on my controller
46 [ 0 ] = KEY_POWER,
47 [ 18 ] = BTN_LEFT, // DISPLAY/L
48 [ 50 ] = BTN_RIGHT, // LOOP/R
49 [ 10 ] = KEY_MUTE,
50 [ 38 ] = KEY_RECORD,
51 [ 22 ] = KEY_PAUSE,
52 [ 54 ] = KEY_STOP,
53 [ 30 ] = KEY_VOLUMEDOWN,
54 [ 62 ] = KEY_VOLUMEUP,
55
56 [ 32 ] = KEY_TUNER, // TV/FM
57 [ 16 ] = KEY_CD,
58 [ 8 ] = KEY_VIDEO,
59 [ 4 ] = KEY_AUDIO,
60 [ 12 ] = KEY_ZOOM, // full screen
61 [ 2 ] = KEY_INFO, // preview
62 [ 42 ] = KEY_SEARCH, // autoscan
63 [ 26 ] = KEY_STOP, // freeze
64 [ 58 ] = KEY_RECORD, // capture
65 [ 6 ] = KEY_PLAY, // unmarked
66 [ 46 ] = KEY_RED, // unmarked
67 [ 14 ] = KEY_GREEN, // unmarked
68
69 [ 33 ] = KEY_YELLOW, // unmarked
70 [ 17 ] = KEY_CHANNELDOWN,
71 [ 49 ] = KEY_CHANNELUP,
72 [ 1 ] = KEY_BLUE, // unmarked
73};
74
75/* Matt Jesson <dvb@jesson.eclipse.co.uk */
76static IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE] = {
77 [ 0x28 ] = KEY_KP0, //'0' / 'enter'
78 [ 0x22 ] = KEY_KP1, //'1'
79 [ 0x12 ] = KEY_KP2, //'2' / 'up arrow'
80 [ 0x32 ] = KEY_KP3, //'3'
81 [ 0x24 ] = KEY_KP4, //'4' / 'left arrow'
82 [ 0x14 ] = KEY_KP5, //'5'
83 [ 0x34 ] = KEY_KP6, //'6' / 'right arrow'
84 [ 0x26 ] = KEY_KP7, //'7'
85 [ 0x16 ] = KEY_KP8, //'8' / 'down arrow'
86 [ 0x36 ] = KEY_KP9, //'9'
87
88 [ 0x20 ] = KEY_LIST, // 'source'
89 [ 0x10 ] = KEY_TEXT, // 'teletext'
90 [ 0x00 ] = KEY_POWER, // 'power'
91 [ 0x04 ] = KEY_AUDIO, // 'audio'
92 [ 0x06 ] = KEY_ZOOM, // 'full screen'
93 [ 0x18 ] = KEY_VIDEO, // 'display'
94 [ 0x38 ] = KEY_SEARCH, // 'loop'
95 [ 0x08 ] = KEY_INFO, // 'preview'
96 [ 0x2a ] = KEY_REWIND, // 'backward <<'
97 [ 0x1a ] = KEY_FASTFORWARD, // 'forward >>'
98 [ 0x3a ] = KEY_RECORD, // 'capture'
99 [ 0x0a ] = KEY_MUTE, // 'mute'
100 [ 0x2c ] = KEY_RECORD, // 'record'
101 [ 0x1c ] = KEY_PAUSE, // 'pause'
102 [ 0x3c ] = KEY_STOP, // 'stop'
103 [ 0x0c ] = KEY_PLAY, // 'play'
104 [ 0x2e ] = KEY_RED, // 'red'
105 [ 0x01 ] = KEY_BLUE, // 'blue' / 'cancel'
106 [ 0x0e ] = KEY_YELLOW, // 'yellow' / 'ok'
107 [ 0x21 ] = KEY_GREEN, // 'green'
108 [ 0x11 ] = KEY_CHANNELDOWN, // 'channel -'
109 [ 0x31 ] = KEY_CHANNELUP, // 'channel +'
110 [ 0x1e ] = KEY_VOLUMEDOWN, // 'volume -'
111 [ 0x3e ] = KEY_VOLUMEUP, // 'volume +'
112};
113
114/* Attila Kondoros <attila.kondoros@chello.hu> */
115static IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = {
116
117 [ 1 ] = KEY_KP1,
118 [ 2 ] = KEY_KP2,
119 [ 3 ] = KEY_KP3,
120 [ 4 ] = KEY_KP4,
121 [ 5 ] = KEY_KP5,
122 [ 6 ] = KEY_KP6,
123 [ 7 ] = KEY_KP7,
124 [ 8 ] = KEY_KP8,
125 [ 9 ] = KEY_KP9,
126 [ 0 ] = KEY_KP0,
127 [ 23 ] = KEY_LAST, // +100
128 [ 10 ] = KEY_LIST, // recall
129
130
131 [ 28 ] = KEY_TUNER, // TV/FM
132 [ 21 ] = KEY_SEARCH, // scan
133 [ 18 ] = KEY_POWER, // power
134 [ 31 ] = KEY_VOLUMEDOWN, // vol up
135 [ 27 ] = KEY_VOLUMEUP, // vol down
136 [ 30 ] = KEY_CHANNELDOWN, // chn up
137 [ 26 ] = KEY_CHANNELUP, // chn down
138
139 [ 17 ] = KEY_VIDEO, // video
140 [ 15 ] = KEY_ZOOM, // full screen
141 [ 19 ] = KEY_MUTE, // mute/unmute
142 [ 16 ] = KEY_TEXT, // min
143
144 [ 13 ] = KEY_STOP, // freeze
145 [ 14 ] = KEY_RECORD, // record
146 [ 29 ] = KEY_PLAYPAUSE, // stop
147 [ 25 ] = KEY_PLAY, // play
148
149 [ 22 ] = KEY_GOTO, // osd
150 [ 20 ] = KEY_REFRESH, // default
151 [ 12 ] = KEY_KPPLUS, // fine tune >>>>
152 [ 24 ] = KEY_KPMINUS // fine tune <<<<
153};
154
155/* ---------------------------------------------------------------------- */
156
157static IR_KEYTAB_TYPE ir_codes_conceptronic[IR_KEYTAB_SIZE] = {
158
159 [ 30 ] = KEY_POWER, // power
160 [ 7 ] = KEY_MEDIA, // source
161 [ 28 ] = KEY_SEARCH, // scan
162
163/* FIXME: duplicate keycodes?
164 *
165 * These four keys seem to share the same GPIO as CH+, CH-, <<< and >>>
166 * The GPIO values are
167 * 6397fb for both "Scan <" and "CH -",
168 * 639ffb for "Scan >" and "CH+",
169 * 6384fb for "Tune <" and "<<<",
170 * 638cfb for "Tune >" and ">>>", regardless of the mask.
171 *
172 * [ 23 ] = KEY_BACK, // fm scan <<
173 * [ 31 ] = KEY_FORWARD, // fm scan >>
174 *
175 * [ 4 ] = KEY_LEFT, // fm tuning <
176 * [ 12 ] = KEY_RIGHT, // fm tuning >
177 *
178 * For now, these four keys are disabled. Pressing them will generate
179 * the CH+/CH-/<<</>>> events
180 */
181
182 [ 3 ] = KEY_TUNER, // TV/FM
183
184 [ 0 ] = KEY_RECORD,
185 [ 8 ] = KEY_STOP,
186 [ 17 ] = KEY_PLAY,
187
188 [ 26 ] = KEY_PLAYPAUSE, // freeze
189 [ 25 ] = KEY_ZOOM, // zoom
190 [ 15 ] = KEY_TEXT, // min
191
192 [ 1 ] = KEY_KP1,
193 [ 11 ] = KEY_KP2,
194 [ 27 ] = KEY_KP3,
195 [ 5 ] = KEY_KP4,
196 [ 9 ] = KEY_KP5,
197 [ 21 ] = KEY_KP6,
198 [ 6 ] = KEY_KP7,
199 [ 10 ] = KEY_KP8,
200 [ 18 ] = KEY_KP9,
201 [ 2 ] = KEY_KP0,
202 [ 16 ] = KEY_LAST, // +100
203 [ 19 ] = KEY_LIST, // recall
204
205 [ 31 ] = KEY_CHANNELUP, // chn down
206 [ 23 ] = KEY_CHANNELDOWN, // chn up
207 [ 22 ] = KEY_VOLUMEUP, // vol down
208 [ 20 ] = KEY_VOLUMEDOWN, // vol up
209
210 [ 4 ] = KEY_KPMINUS, // <<<
211 [ 14 ] = KEY_SETUP, // function
212 [ 12 ] = KEY_KPPLUS, // >>>
213
214 [ 13 ] = KEY_GOTO, // mts
215 [ 29 ] = KEY_REFRESH, // reset
216 [ 24 ] = KEY_MUTE // mute/unmute
217};
218
219static IR_KEYTAB_TYPE ir_codes_nebula[IR_KEYTAB_SIZE] = {
220 [0x00] = KEY_KP0,
221 [0x01] = KEY_KP1,
222 [0x02] = KEY_KP2,
223 [0x03] = KEY_KP3,
224 [0x04] = KEY_KP4,
225 [0x05] = KEY_KP5,
226 [0x06] = KEY_KP6,
227 [0x07] = KEY_KP7,
228 [0x08] = KEY_KP8,
229 [0x09] = KEY_KP9,
230 [0x0a] = KEY_TV,
231 [0x0b] = KEY_AUX,
232 [0x0c] = KEY_DVD,
233 [0x0d] = KEY_POWER,
234 [0x0e] = KEY_MHP, /* labelled 'Picture' */
235 [0x0f] = KEY_AUDIO,
236 [0x10] = KEY_INFO,
237 [0x11] = KEY_F13, /* 16:9 */
238 [0x12] = KEY_F14, /* 14:9 */
239 [0x13] = KEY_EPG,
240 [0x14] = KEY_EXIT,
241 [0x15] = KEY_MENU,
242 [0x16] = KEY_UP,
243 [0x17] = KEY_DOWN,
244 [0x18] = KEY_LEFT,
245 [0x19] = KEY_RIGHT,
246 [0x1a] = KEY_ENTER,
247 [0x1b] = KEY_CHANNELUP,
248 [0x1c] = KEY_CHANNELDOWN,
249 [0x1d] = KEY_VOLUMEUP,
250 [0x1e] = KEY_VOLUMEDOWN,
251 [0x1f] = KEY_RED,
252 [0x20] = KEY_GREEN,
253 [0x21] = KEY_YELLOW,
254 [0x22] = KEY_BLUE,
255 [0x23] = KEY_SUBTITLE,
256 [0x24] = KEY_F15, /* AD */
257 [0x25] = KEY_TEXT,
258 [0x26] = KEY_MUTE,
259 [0x27] = KEY_REWIND,
260 [0x28] = KEY_STOP,
261 [0x29] = KEY_PLAY,
262 [0x2a] = KEY_FASTFORWARD,
263 [0x2b] = KEY_F16, /* chapter */
264 [0x2c] = KEY_PAUSE,
265 [0x2d] = KEY_PLAY,
266 [0x2e] = KEY_RECORD,
267 [0x2f] = KEY_F17, /* picture in picture */
268 [0x30] = KEY_KPPLUS, /* zoom in */
269 [0x31] = KEY_KPMINUS, /* zoom out */
270 [0x32] = KEY_F18, /* capture */
271 [0x33] = KEY_F19, /* web */
272 [0x34] = KEY_EMAIL,
273 [0x35] = KEY_PHONE,
274 [0x36] = KEY_PC
275};
276 31
277static int debug; 32static int debug;
278module_param(debug, int, 0644); /* debug level (0,1,2) */ 33module_param(debug, int, 0644); /* debug level (0,1,2) */
@@ -573,7 +328,8 @@ int bttv_input_init(struct bttv *btv)
573 ir->polling = 50; // ms 328 ir->polling = 50; // ms
574 break; 329 break;
575 case BTTV_BOARD_CONCEPTRONIC_CTVFMI2: 330 case BTTV_BOARD_CONCEPTRONIC_CTVFMI2:
576 ir_codes = ir_codes_conceptronic; 331 case BTTV_BOARD_CONTVFMI:
332 ir_codes = ir_codes_pixelview;
577 ir->mask_keycode = 0x001F00; 333 ir->mask_keycode = 0x001F00;
578 ir->mask_keyup = 0x006000; 334 ir->mask_keyup = 0x006000;
579 ir->polling = 50; // ms 335 ir->polling = 50; // ms
diff --git a/drivers/media/video/bttv-risc.c b/drivers/media/video/bttv-risc.c
index b40e9734bf08..344f84e9af04 100644
--- a/drivers/media/video/bttv-risc.c
+++ b/drivers/media/video/bttv-risc.c
@@ -51,8 +51,10 @@ bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
51 int rc; 51 int rc;
52 52
53 /* estimate risc mem: worst case is one write per page border + 53 /* estimate risc mem: worst case is one write per page border +
54 one write per scan line + sync + jump (all 2 dwords) */ 54 one write per scan line + sync + jump (all 2 dwords). padding
55 instructions = (bpl * lines) / PAGE_SIZE + lines; 55 can cause next bpl to start close to a page border. First DMA
56 region may be smaller than PAGE_SIZE */
57 instructions = 1 + ((bpl + padding) * lines) / PAGE_SIZE + lines;
56 instructions += 2; 58 instructions += 2;
57 if ((rc = btcx_riscmem_alloc(btv->c.pci,risc,instructions*8)) < 0) 59 if ((rc = btcx_riscmem_alloc(btv->c.pci,risc,instructions*8)) < 0)
58 return rc; 60 return rc;
@@ -104,7 +106,7 @@ bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
104 106
105 /* save pointer to jmp instruction address */ 107 /* save pointer to jmp instruction address */
106 risc->jmp = rp; 108 risc->jmp = rp;
107 BUG_ON((risc->jmp - risc->cpu + 2) / 4 > risc->size); 109 BUG_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size);
108 return 0; 110 return 0;
109} 111}
110 112
@@ -222,7 +224,7 @@ bttv_risc_planar(struct bttv *btv, struct btcx_riscmem *risc,
222 224
223 /* save pointer to jmp instruction address */ 225 /* save pointer to jmp instruction address */
224 risc->jmp = rp; 226 risc->jmp = rp;
225 BUG_ON((risc->jmp - risc->cpu + 2) / 4 > risc->size); 227 BUG_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size);
226 return 0; 228 return 0;
227} 229}
228 230
@@ -274,6 +276,8 @@ bttv_risc_overlay(struct bttv *btv, struct btcx_riscmem *risc,
274 if (line > maxy) 276 if (line > maxy)
275 btcx_calc_skips(line, ov->w.width, &maxy, 277 btcx_calc_skips(line, ov->w.width, &maxy,
276 skips, &nskips, ov->clips, ov->nclips); 278 skips, &nskips, ov->clips, ov->nclips);
279 else
280 nskips = 0;
277 281
278 /* write out risc code */ 282 /* write out risc code */
279 for (start = 0, skip = 0; start < ov->w.width; start = end) { 283 for (start = 0, skip = 0; start < ov->w.width; start = end) {
@@ -307,7 +311,7 @@ bttv_risc_overlay(struct bttv *btv, struct btcx_riscmem *risc,
307 311
308 /* save pointer to jmp instruction address */ 312 /* save pointer to jmp instruction address */
309 risc->jmp = rp; 313 risc->jmp = rp;
310 BUG_ON((risc->jmp - risc->cpu + 2) / 4 > risc->size); 314 BUG_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size);
311 kfree(skips); 315 kfree(skips);
312 return 0; 316 return 0;
313} 317}
@@ -507,8 +511,7 @@ bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
507void 511void
508bttv_dma_free(struct bttv *btv, struct bttv_buffer *buf) 512bttv_dma_free(struct bttv *btv, struct bttv_buffer *buf)
509{ 513{
510 if (in_interrupt()) 514 BUG_ON(in_interrupt());
511 BUG();
512 videobuf_waiton(&buf->vb,0,0); 515 videobuf_waiton(&buf->vb,0,0);
513 videobuf_dma_pci_unmap(btv->c.pci, &buf->vb.dma); 516 videobuf_dma_pci_unmap(btv->c.pci, &buf->vb.dma);
514 videobuf_dma_free(&buf->vb.dma); 517 videobuf_dma_free(&buf->vb.dma);
diff --git a/drivers/media/video/bw-qcam.c b/drivers/media/video/bw-qcam.c
index 6bad93ef969f..d97b7d8ac33d 100644
--- a/drivers/media/video/bw-qcam.c
+++ b/drivers/media/video/bw-qcam.c
@@ -73,7 +73,7 @@ OTHER DEALINGS IN THE SOFTWARE.
73#include <linux/parport.h> 73#include <linux/parport.h>
74#include <linux/sched.h> 74#include <linux/sched.h>
75#include <linux/videodev.h> 75#include <linux/videodev.h>
76#include <asm/semaphore.h> 76#include <linux/mutex.h>
77#include <asm/uaccess.h> 77#include <asm/uaccess.h>
78 78
79#include "bw-qcam.h" 79#include "bw-qcam.h"
@@ -168,7 +168,7 @@ static struct qcam_device *qcam_init(struct parport *port)
168 168
169 memcpy(&q->vdev, &qcam_template, sizeof(qcam_template)); 169 memcpy(&q->vdev, &qcam_template, sizeof(qcam_template));
170 170
171 init_MUTEX(&q->lock); 171 mutex_init(&q->lock);
172 172
173 q->port_mode = (QC_ANY | QC_NOTSET); 173 q->port_mode = (QC_ANY | QC_NOTSET);
174 q->width = 320; 174 q->width = 320;
@@ -772,9 +772,9 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
772 qcam->whitebal = p->whiteness>>8; 772 qcam->whitebal = p->whiteness>>8;
773 qcam->bpp = p->depth; 773 qcam->bpp = p->depth;
774 774
775 down(&qcam->lock); 775 mutex_lock(&qcam->lock);
776 qc_setscanmode(qcam); 776 qc_setscanmode(qcam);
777 up(&qcam->lock); 777 mutex_unlock(&qcam->lock);
778 qcam->status |= QC_PARAM_CHANGE; 778 qcam->status |= QC_PARAM_CHANGE;
779 779
780 return 0; 780 return 0;
@@ -805,9 +805,9 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
805 qcam->height = 240; 805 qcam->height = 240;
806 qcam->transfer_scale = 1; 806 qcam->transfer_scale = 1;
807 } 807 }
808 down(&qcam->lock); 808 mutex_lock(&qcam->lock);
809 qc_setscanmode(qcam); 809 qc_setscanmode(qcam);
810 up(&qcam->lock); 810 mutex_unlock(&qcam->lock);
811 811
812 /* We must update the camera before we grab. We could 812 /* We must update the camera before we grab. We could
813 just have changed the grab size */ 813 just have changed the grab size */
@@ -854,7 +854,7 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
854 int len; 854 int len;
855 parport_claim_or_block(qcam->pdev); 855 parport_claim_or_block(qcam->pdev);
856 856
857 down(&qcam->lock); 857 mutex_lock(&qcam->lock);
858 858
859 qc_reset(qcam); 859 qc_reset(qcam);
860 860
@@ -864,7 +864,7 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
864 864
865 len=qc_capture(qcam, buf,count); 865 len=qc_capture(qcam, buf,count);
866 866
867 up(&qcam->lock); 867 mutex_unlock(&qcam->lock);
868 868
869 parport_release(qcam->pdev); 869 parport_release(qcam->pdev);
870 return len; 870 return len;
diff --git a/drivers/media/video/bw-qcam.h b/drivers/media/video/bw-qcam.h
index 723e8ad9e56a..6701dafbc0da 100644
--- a/drivers/media/video/bw-qcam.h
+++ b/drivers/media/video/bw-qcam.h
@@ -55,7 +55,7 @@ struct qcam_device {
55 struct video_device vdev; 55 struct video_device vdev;
56 struct pardevice *pdev; 56 struct pardevice *pdev;
57 struct parport *pport; 57 struct parport *pport;
58 struct semaphore lock; 58 struct mutex lock;
59 int width, height; 59 int width, height;
60 int bpp; 60 int bpp;
61 int mode; 61 int mode;
diff --git a/drivers/media/video/c-qcam.c b/drivers/media/video/c-qcam.c
index 9976db4f6da8..8211fd8d7cbf 100644
--- a/drivers/media/video/c-qcam.c
+++ b/drivers/media/video/c-qcam.c
@@ -34,7 +34,8 @@
34#include <linux/parport.h> 34#include <linux/parport.h>
35#include <linux/sched.h> 35#include <linux/sched.h>
36#include <linux/videodev.h> 36#include <linux/videodev.h>
37#include <asm/semaphore.h> 37#include <linux/mutex.h>
38
38#include <asm/uaccess.h> 39#include <asm/uaccess.h>
39 40
40struct qcam_device { 41struct qcam_device {
@@ -47,7 +48,7 @@ struct qcam_device {
47 int contrast, brightness, whitebal; 48 int contrast, brightness, whitebal;
48 int top, left; 49 int top, left;
49 unsigned int bidirectional; 50 unsigned int bidirectional;
50 struct semaphore lock; 51 struct mutex lock;
51}; 52};
52 53
53/* cameras maximum */ 54/* cameras maximum */
@@ -581,11 +582,11 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
581 qcam->contrast = p->contrast>>8; 582 qcam->contrast = p->contrast>>8;
582 qcam->whitebal = p->whiteness>>8; 583 qcam->whitebal = p->whiteness>>8;
583 584
584 down(&qcam->lock); 585 mutex_lock(&qcam->lock);
585 parport_claim_or_block(qcam->pdev); 586 parport_claim_or_block(qcam->pdev);
586 qc_setup(qcam); 587 qc_setup(qcam);
587 parport_release(qcam->pdev); 588 parport_release(qcam->pdev);
588 up(&qcam->lock); 589 mutex_unlock(&qcam->lock);
589 return 0; 590 return 0;
590 } 591 }
591 case VIDIOCSWIN: 592 case VIDIOCSWIN:
@@ -628,11 +629,11 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
628#endif 629#endif
629 /* Ok we figured out what to use from our 630 /* Ok we figured out what to use from our
630 wide choice */ 631 wide choice */
631 down(&qcam->lock); 632 mutex_lock(&qcam->lock);
632 parport_claim_or_block(qcam->pdev); 633 parport_claim_or_block(qcam->pdev);
633 qc_setup(qcam); 634 qc_setup(qcam);
634 parport_release(qcam->pdev); 635 parport_release(qcam->pdev);
635 up(&qcam->lock); 636 mutex_unlock(&qcam->lock);
636 return 0; 637 return 0;
637 } 638 }
638 case VIDIOCGWIN: 639 case VIDIOCGWIN:
@@ -672,12 +673,12 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
672 struct qcam_device *qcam=(struct qcam_device *)v; 673 struct qcam_device *qcam=(struct qcam_device *)v;
673 int len; 674 int len;
674 675
675 down(&qcam->lock); 676 mutex_lock(&qcam->lock);
676 parport_claim_or_block(qcam->pdev); 677 parport_claim_or_block(qcam->pdev);
677 /* Probably should have a semaphore against multiple users */ 678 /* Probably should have a semaphore against multiple users */
678 len = qc_capture(qcam, buf,count); 679 len = qc_capture(qcam, buf,count);
679 parport_release(qcam->pdev); 680 parport_release(qcam->pdev);
680 up(&qcam->lock); 681 mutex_unlock(&qcam->lock);
681 return len; 682 return len;
682} 683}
683 684
@@ -727,7 +728,7 @@ static struct qcam_device *qcam_init(struct parport *port)
727 728
728 memcpy(&q->vdev, &qcam_template, sizeof(qcam_template)); 729 memcpy(&q->vdev, &qcam_template, sizeof(qcam_template));
729 730
730 init_MUTEX(&q->lock); 731 mutex_init(&q->lock);
731 q->width = q->ccd_width = 320; 732 q->width = q->ccd_width = 320;
732 q->height = q->ccd_height = 240; 733 q->height = q->ccd_height = 240;
733 q->mode = QC_MILLIONS | QC_DECIMATION_1; 734 q->mode = QC_MILLIONS | QC_DECIMATION_1;
diff --git a/drivers/media/video/cpia.c b/drivers/media/video/cpia.c
index 85d964b5b33c..d93a561e6b80 100644
--- a/drivers/media/video/cpia.c
+++ b/drivers/media/video/cpia.c
@@ -39,7 +39,7 @@
39#include <linux/pagemap.h> 39#include <linux/pagemap.h>
40#include <linux/delay.h> 40#include <linux/delay.h>
41#include <asm/io.h> 41#include <asm/io.h>
42#include <asm/semaphore.h> 42#include <linux/mutex.h>
43 43
44#ifdef CONFIG_KMOD 44#ifdef CONFIG_KMOD
45#include <linux/kmod.h> 45#include <linux/kmod.h>
@@ -622,7 +622,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
622 622
623 buffer = page; 623 buffer = page;
624 624
625 if (down_interruptible(&cam->param_lock)) 625 if (mutex_lock_interruptible(&cam->param_lock))
626 return -ERESTARTSYS; 626 return -ERESTARTSYS;
627 627
628 /* 628 /*
@@ -1350,7 +1350,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1350 } else 1350 } else
1351 DBG("error: %d\n", retval); 1351 DBG("error: %d\n", retval);
1352 1352
1353 up(&cam->param_lock); 1353 mutex_unlock(&cam->param_lock);
1354 1354
1355out: 1355out:
1356 free_page((unsigned long)page); 1356 free_page((unsigned long)page);
@@ -1664,7 +1664,7 @@ static int do_command(struct cam_data *cam, u16 command, u8 a, u8 b, u8 c, u8 d)
1664 case CPIA_COMMAND_GetColourParams: 1664 case CPIA_COMMAND_GetColourParams:
1665 case CPIA_COMMAND_GetColourBalance: 1665 case CPIA_COMMAND_GetColourBalance:
1666 case CPIA_COMMAND_GetExposure: 1666 case CPIA_COMMAND_GetExposure:
1667 down(&cam->param_lock); 1667 mutex_lock(&cam->param_lock);
1668 datasize=8; 1668 datasize=8;
1669 break; 1669 break;
1670 case CPIA_COMMAND_ReadMCPorts: 1670 case CPIA_COMMAND_ReadMCPorts:
@@ -1691,7 +1691,7 @@ static int do_command(struct cam_data *cam, u16 command, u8 a, u8 b, u8 c, u8 d)
1691 if (command == CPIA_COMMAND_GetColourParams || 1691 if (command == CPIA_COMMAND_GetColourParams ||
1692 command == CPIA_COMMAND_GetColourBalance || 1692 command == CPIA_COMMAND_GetColourBalance ||
1693 command == CPIA_COMMAND_GetExposure) 1693 command == CPIA_COMMAND_GetExposure)
1694 up(&cam->param_lock); 1694 mutex_unlock(&cam->param_lock);
1695 } else { 1695 } else {
1696 switch(command) { 1696 switch(command) {
1697 case CPIA_COMMAND_GetCPIAVersion: 1697 case CPIA_COMMAND_GetCPIAVersion:
@@ -1726,13 +1726,13 @@ static int do_command(struct cam_data *cam, u16 command, u8 a, u8 b, u8 c, u8 d)
1726 cam->params.colourParams.brightness = data[0]; 1726 cam->params.colourParams.brightness = data[0];
1727 cam->params.colourParams.contrast = data[1]; 1727 cam->params.colourParams.contrast = data[1];
1728 cam->params.colourParams.saturation = data[2]; 1728 cam->params.colourParams.saturation = data[2];
1729 up(&cam->param_lock); 1729 mutex_unlock(&cam->param_lock);
1730 break; 1730 break;
1731 case CPIA_COMMAND_GetColourBalance: 1731 case CPIA_COMMAND_GetColourBalance:
1732 cam->params.colourBalance.redGain = data[0]; 1732 cam->params.colourBalance.redGain = data[0];
1733 cam->params.colourBalance.greenGain = data[1]; 1733 cam->params.colourBalance.greenGain = data[1];
1734 cam->params.colourBalance.blueGain = data[2]; 1734 cam->params.colourBalance.blueGain = data[2];
1735 up(&cam->param_lock); 1735 mutex_unlock(&cam->param_lock);
1736 break; 1736 break;
1737 case CPIA_COMMAND_GetExposure: 1737 case CPIA_COMMAND_GetExposure:
1738 cam->params.exposure.gain = data[0]; 1738 cam->params.exposure.gain = data[0];
@@ -1743,7 +1743,7 @@ static int do_command(struct cam_data *cam, u16 command, u8 a, u8 b, u8 c, u8 d)
1743 cam->params.exposure.green1Comp = data[5]; 1743 cam->params.exposure.green1Comp = data[5];
1744 cam->params.exposure.green2Comp = data[6]; 1744 cam->params.exposure.green2Comp = data[6];
1745 cam->params.exposure.blueComp = data[7]; 1745 cam->params.exposure.blueComp = data[7];
1746 up(&cam->param_lock); 1746 mutex_unlock(&cam->param_lock);
1747 break; 1747 break;
1748 1748
1749 case CPIA_COMMAND_ReadMCPorts: 1749 case CPIA_COMMAND_ReadMCPorts:
@@ -2059,7 +2059,7 @@ static int parse_picture(struct cam_data *cam, int size)
2059 int rows, cols, linesize, subsample_422; 2059 int rows, cols, linesize, subsample_422;
2060 2060
2061 /* make sure params don't change while we are decoding */ 2061 /* make sure params don't change while we are decoding */
2062 down(&cam->param_lock); 2062 mutex_lock(&cam->param_lock);
2063 2063
2064 obuf = cam->decompressed_frame.data; 2064 obuf = cam->decompressed_frame.data;
2065 end_obuf = obuf+CPIA_MAX_FRAME_SIZE; 2065 end_obuf = obuf+CPIA_MAX_FRAME_SIZE;
@@ -2069,26 +2069,26 @@ static int parse_picture(struct cam_data *cam, int size)
2069 2069
2070 if ((ibuf[0] != MAGIC_0) || (ibuf[1] != MAGIC_1)) { 2070 if ((ibuf[0] != MAGIC_0) || (ibuf[1] != MAGIC_1)) {
2071 LOG("header not found\n"); 2071 LOG("header not found\n");
2072 up(&cam->param_lock); 2072 mutex_unlock(&cam->param_lock);
2073 return -1; 2073 return -1;
2074 } 2074 }
2075 2075
2076 if ((ibuf[16] != VIDEOSIZE_QCIF) && (ibuf[16] != VIDEOSIZE_CIF)) { 2076 if ((ibuf[16] != VIDEOSIZE_QCIF) && (ibuf[16] != VIDEOSIZE_CIF)) {
2077 LOG("wrong video size\n"); 2077 LOG("wrong video size\n");
2078 up(&cam->param_lock); 2078 mutex_unlock(&cam->param_lock);
2079 return -1; 2079 return -1;
2080 } 2080 }
2081 2081
2082 if (ibuf[17] != SUBSAMPLE_420 && ibuf[17] != SUBSAMPLE_422) { 2082 if (ibuf[17] != SUBSAMPLE_420 && ibuf[17] != SUBSAMPLE_422) {
2083 LOG("illegal subtype %d\n",ibuf[17]); 2083 LOG("illegal subtype %d\n",ibuf[17]);
2084 up(&cam->param_lock); 2084 mutex_unlock(&cam->param_lock);
2085 return -1; 2085 return -1;
2086 } 2086 }
2087 subsample_422 = ibuf[17] == SUBSAMPLE_422; 2087 subsample_422 = ibuf[17] == SUBSAMPLE_422;
2088 2088
2089 if (ibuf[18] != YUVORDER_YUYV && ibuf[18] != YUVORDER_UYVY) { 2089 if (ibuf[18] != YUVORDER_YUYV && ibuf[18] != YUVORDER_UYVY) {
2090 LOG("illegal yuvorder %d\n",ibuf[18]); 2090 LOG("illegal yuvorder %d\n",ibuf[18]);
2091 up(&cam->param_lock); 2091 mutex_unlock(&cam->param_lock);
2092 return -1; 2092 return -1;
2093 } 2093 }
2094 in_uyvy = ibuf[18] == YUVORDER_UYVY; 2094 in_uyvy = ibuf[18] == YUVORDER_UYVY;
@@ -2098,7 +2098,7 @@ static int parse_picture(struct cam_data *cam, int size)
2098 (ibuf[26] != cam->params.roi.rowStart) || 2098 (ibuf[26] != cam->params.roi.rowStart) ||
2099 (ibuf[27] != cam->params.roi.rowEnd)) { 2099 (ibuf[27] != cam->params.roi.rowEnd)) {
2100 LOG("ROI mismatch\n"); 2100 LOG("ROI mismatch\n");
2101 up(&cam->param_lock); 2101 mutex_unlock(&cam->param_lock);
2102 return -1; 2102 return -1;
2103 } 2103 }
2104 cols = 8*(ibuf[25] - ibuf[24]); 2104 cols = 8*(ibuf[25] - ibuf[24]);
@@ -2107,14 +2107,14 @@ static int parse_picture(struct cam_data *cam, int size)
2107 2107
2108 if ((ibuf[28] != NOT_COMPRESSED) && (ibuf[28] != COMPRESSED)) { 2108 if ((ibuf[28] != NOT_COMPRESSED) && (ibuf[28] != COMPRESSED)) {
2109 LOG("illegal compression %d\n",ibuf[28]); 2109 LOG("illegal compression %d\n",ibuf[28]);
2110 up(&cam->param_lock); 2110 mutex_unlock(&cam->param_lock);
2111 return -1; 2111 return -1;
2112 } 2112 }
2113 compressed = (ibuf[28] == COMPRESSED); 2113 compressed = (ibuf[28] == COMPRESSED);
2114 2114
2115 if (ibuf[29] != NO_DECIMATION && ibuf[29] != DECIMATION_ENAB) { 2115 if (ibuf[29] != NO_DECIMATION && ibuf[29] != DECIMATION_ENAB) {
2116 LOG("illegal decimation %d\n",ibuf[29]); 2116 LOG("illegal decimation %d\n",ibuf[29]);
2117 up(&cam->param_lock); 2117 mutex_unlock(&cam->param_lock);
2118 return -1; 2118 return -1;
2119 } 2119 }
2120 decimation = (ibuf[29] == DECIMATION_ENAB); 2120 decimation = (ibuf[29] == DECIMATION_ENAB);
@@ -2130,7 +2130,7 @@ static int parse_picture(struct cam_data *cam, int size)
2130 cam->params.status.vpStatus = ibuf[38]; 2130 cam->params.status.vpStatus = ibuf[38];
2131 cam->params.status.errorCode = ibuf[39]; 2131 cam->params.status.errorCode = ibuf[39];
2132 cam->fps = ibuf[41]; 2132 cam->fps = ibuf[41];
2133 up(&cam->param_lock); 2133 mutex_unlock(&cam->param_lock);
2134 2134
2135 linesize = skipcount(cols, out_fmt); 2135 linesize = skipcount(cols, out_fmt);
2136 ibuf += FRAME_HEADER_SIZE; 2136 ibuf += FRAME_HEADER_SIZE;
@@ -2271,9 +2271,9 @@ static int find_over_exposure(int brightness)
2271/* update various camera modes and settings */ 2271/* update various camera modes and settings */
2272static void dispatch_commands(struct cam_data *cam) 2272static void dispatch_commands(struct cam_data *cam)
2273{ 2273{
2274 down(&cam->param_lock); 2274 mutex_lock(&cam->param_lock);
2275 if (cam->cmd_queue==COMMAND_NONE) { 2275 if (cam->cmd_queue==COMMAND_NONE) {
2276 up(&cam->param_lock); 2276 mutex_unlock(&cam->param_lock);
2277 return; 2277 return;
2278 } 2278 }
2279 DEB_BYTE(cam->cmd_queue); 2279 DEB_BYTE(cam->cmd_queue);
@@ -2415,7 +2415,7 @@ static void dispatch_commands(struct cam_data *cam)
2415 } 2415 }
2416 2416
2417 cam->cmd_queue = COMMAND_NONE; 2417 cam->cmd_queue = COMMAND_NONE;
2418 up(&cam->param_lock); 2418 mutex_unlock(&cam->param_lock);
2419 return; 2419 return;
2420} 2420}
2421 2421
@@ -2562,7 +2562,7 @@ static void monitor_exposure(struct cam_data *cam)
2562 gain = data[2]; 2562 gain = data[2];
2563 coarseL = data[3]; 2563 coarseL = data[3];
2564 2564
2565 down(&cam->param_lock); 2565 mutex_lock(&cam->param_lock);
2566 light_exp = cam->params.colourParams.brightness + 2566 light_exp = cam->params.colourParams.brightness +
2567 TC - 50 + EXP_ACC_LIGHT; 2567 TC - 50 + EXP_ACC_LIGHT;
2568 if(light_exp > 255) 2568 if(light_exp > 255)
@@ -2762,7 +2762,7 @@ static void monitor_exposure(struct cam_data *cam)
2762 LOG("Automatically increasing sensor_fps\n"); 2762 LOG("Automatically increasing sensor_fps\n");
2763 } 2763 }
2764 } 2764 }
2765 up(&cam->param_lock); 2765 mutex_unlock(&cam->param_lock);
2766} 2766}
2767 2767
2768/*-----------------------------------------------------------------*/ 2768/*-----------------------------------------------------------------*/
@@ -2778,10 +2778,10 @@ static void restart_flicker(struct cam_data *cam)
2778 int cam_exposure, old_exp; 2778 int cam_exposure, old_exp;
2779 if(!FIRMWARE_VERSION(1,2)) 2779 if(!FIRMWARE_VERSION(1,2))
2780 return; 2780 return;
2781 down(&cam->param_lock); 2781 mutex_lock(&cam->param_lock);
2782 if(cam->params.flickerControl.flickerMode == 0 || 2782 if(cam->params.flickerControl.flickerMode == 0 ||
2783 cam->raw_image[39] == 0) { 2783 cam->raw_image[39] == 0) {
2784 up(&cam->param_lock); 2784 mutex_unlock(&cam->param_lock);
2785 return; 2785 return;
2786 } 2786 }
2787 cam_exposure = cam->raw_image[39]*2; 2787 cam_exposure = cam->raw_image[39]*2;
@@ -2810,7 +2810,7 @@ static void restart_flicker(struct cam_data *cam)
2810 cam->exposure_status = EXPOSURE_NORMAL; 2810 cam->exposure_status = EXPOSURE_NORMAL;
2811 2811
2812 } 2812 }
2813 up(&cam->param_lock); 2813 mutex_unlock(&cam->param_lock);
2814} 2814}
2815#undef FIRMWARE_VERSION 2815#undef FIRMWARE_VERSION
2816 2816
@@ -3186,7 +3186,7 @@ static int cpia_open(struct inode *inode, struct file *file)
3186 if (!try_module_get(cam->ops->owner)) 3186 if (!try_module_get(cam->ops->owner))
3187 return -ENODEV; 3187 return -ENODEV;
3188 3188
3189 down(&cam->busy_lock); 3189 mutex_lock(&cam->busy_lock);
3190 err = -ENOMEM; 3190 err = -ENOMEM;
3191 if (!cam->raw_image) { 3191 if (!cam->raw_image) {
3192 cam->raw_image = rvmalloc(CPIA_MAX_IMAGE_SIZE); 3192 cam->raw_image = rvmalloc(CPIA_MAX_IMAGE_SIZE);
@@ -3227,7 +3227,7 @@ static int cpia_open(struct inode *inode, struct file *file)
3227 3227
3228 ++cam->open_count; 3228 ++cam->open_count;
3229 file->private_data = dev; 3229 file->private_data = dev;
3230 up(&cam->busy_lock); 3230 mutex_unlock(&cam->busy_lock);
3231 return 0; 3231 return 0;
3232 3232
3233 oops: 3233 oops:
@@ -3239,7 +3239,7 @@ static int cpia_open(struct inode *inode, struct file *file)
3239 rvfree(cam->raw_image, CPIA_MAX_IMAGE_SIZE); 3239 rvfree(cam->raw_image, CPIA_MAX_IMAGE_SIZE);
3240 cam->raw_image = NULL; 3240 cam->raw_image = NULL;
3241 } 3241 }
3242 up(&cam->busy_lock); 3242 mutex_unlock(&cam->busy_lock);
3243 put_cam(cam->ops); 3243 put_cam(cam->ops);
3244 return err; 3244 return err;
3245} 3245}
@@ -3303,24 +3303,24 @@ static ssize_t cpia_read(struct file *file, char __user *buf,
3303 int err; 3303 int err;
3304 3304
3305 /* make this _really_ smp and multithread-safe */ 3305 /* make this _really_ smp and multithread-safe */
3306 if (down_interruptible(&cam->busy_lock)) 3306 if (mutex_lock_interruptible(&cam->busy_lock))
3307 return -EINTR; 3307 return -EINTR;
3308 3308
3309 if (!buf) { 3309 if (!buf) {
3310 DBG("buf NULL\n"); 3310 DBG("buf NULL\n");
3311 up(&cam->busy_lock); 3311 mutex_unlock(&cam->busy_lock);
3312 return -EINVAL; 3312 return -EINVAL;
3313 } 3313 }
3314 3314
3315 if (!count) { 3315 if (!count) {
3316 DBG("count 0\n"); 3316 DBG("count 0\n");
3317 up(&cam->busy_lock); 3317 mutex_unlock(&cam->busy_lock);
3318 return 0; 3318 return 0;
3319 } 3319 }
3320 3320
3321 if (!cam->ops) { 3321 if (!cam->ops) {
3322 DBG("ops NULL\n"); 3322 DBG("ops NULL\n");
3323 up(&cam->busy_lock); 3323 mutex_unlock(&cam->busy_lock);
3324 return -ENODEV; 3324 return -ENODEV;
3325 } 3325 }
3326 3326
@@ -3329,7 +3329,7 @@ static ssize_t cpia_read(struct file *file, char __user *buf,
3329 cam->mmap_kludge=0; 3329 cam->mmap_kludge=0;
3330 if((err = fetch_frame(cam)) != 0) { 3330 if((err = fetch_frame(cam)) != 0) {
3331 DBG("ERROR from fetch_frame: %d\n", err); 3331 DBG("ERROR from fetch_frame: %d\n", err);
3332 up(&cam->busy_lock); 3332 mutex_unlock(&cam->busy_lock);
3333 return err; 3333 return err;
3334 } 3334 }
3335 cam->decompressed_frame.state = FRAME_UNUSED; 3335 cam->decompressed_frame.state = FRAME_UNUSED;
@@ -3338,17 +3338,17 @@ static ssize_t cpia_read(struct file *file, char __user *buf,
3338 if (cam->decompressed_frame.count > count) { 3338 if (cam->decompressed_frame.count > count) {
3339 DBG("count wrong: %d, %lu\n", cam->decompressed_frame.count, 3339 DBG("count wrong: %d, %lu\n", cam->decompressed_frame.count,
3340 (unsigned long) count); 3340 (unsigned long) count);
3341 up(&cam->busy_lock); 3341 mutex_unlock(&cam->busy_lock);
3342 return -EFAULT; 3342 return -EFAULT;
3343 } 3343 }
3344 if (copy_to_user(buf, cam->decompressed_frame.data, 3344 if (copy_to_user(buf, cam->decompressed_frame.data,
3345 cam->decompressed_frame.count)) { 3345 cam->decompressed_frame.count)) {
3346 DBG("copy_to_user failed\n"); 3346 DBG("copy_to_user failed\n");
3347 up(&cam->busy_lock); 3347 mutex_unlock(&cam->busy_lock);
3348 return -EFAULT; 3348 return -EFAULT;
3349 } 3349 }
3350 3350
3351 up(&cam->busy_lock); 3351 mutex_unlock(&cam->busy_lock);
3352 return cam->decompressed_frame.count; 3352 return cam->decompressed_frame.count;
3353} 3353}
3354 3354
@@ -3363,7 +3363,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3363 return -ENODEV; 3363 return -ENODEV;
3364 3364
3365 /* make this _really_ smp-safe */ 3365 /* make this _really_ smp-safe */
3366 if (down_interruptible(&cam->busy_lock)) 3366 if (mutex_lock_interruptible(&cam->busy_lock))
3367 return -EINTR; 3367 return -EINTR;
3368 3368
3369 //DBG("cpia_ioctl: %u\n", ioctlnr); 3369 //DBG("cpia_ioctl: %u\n", ioctlnr);
@@ -3439,7 +3439,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3439 break; 3439 break;
3440 } 3440 }
3441 3441
3442 down(&cam->param_lock); 3442 mutex_lock(&cam->param_lock);
3443 /* brightness, colour, contrast need no check 0-65535 */ 3443 /* brightness, colour, contrast need no check 0-65535 */
3444 cam->vp = *vp; 3444 cam->vp = *vp;
3445 /* update cam->params.colourParams */ 3445 /* update cam->params.colourParams */
@@ -3466,7 +3466,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3466 3466
3467 /* queue command to update camera */ 3467 /* queue command to update camera */
3468 cam->cmd_queue |= COMMAND_SETCOLOURPARAMS; 3468 cam->cmd_queue |= COMMAND_SETCOLOURPARAMS;
3469 up(&cam->param_lock); 3469 mutex_unlock(&cam->param_lock);
3470 DBG("VIDIOCSPICT: %d / %d // %d / %d / %d / %d\n", 3470 DBG("VIDIOCSPICT: %d / %d // %d / %d / %d / %d\n",
3471 vp->depth, vp->palette, vp->brightness, vp->hue, vp->colour, 3471 vp->depth, vp->palette, vp->brightness, vp->hue, vp->colour,
3472 vp->contrast); 3472 vp->contrast);
@@ -3501,13 +3501,13 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3501 /* we set the video window to something smaller or equal to what 3501 /* we set the video window to something smaller or equal to what
3502 * is requested by the user??? 3502 * is requested by the user???
3503 */ 3503 */
3504 down(&cam->param_lock); 3504 mutex_lock(&cam->param_lock);
3505 if (vw->width != cam->vw.width || vw->height != cam->vw.height) { 3505 if (vw->width != cam->vw.width || vw->height != cam->vw.height) {
3506 int video_size = match_videosize(vw->width, vw->height); 3506 int video_size = match_videosize(vw->width, vw->height);
3507 3507
3508 if (video_size < 0) { 3508 if (video_size < 0) {
3509 retval = -EINVAL; 3509 retval = -EINVAL;
3510 up(&cam->param_lock); 3510 mutex_unlock(&cam->param_lock);
3511 break; 3511 break;
3512 } 3512 }
3513 cam->video_size = video_size; 3513 cam->video_size = video_size;
@@ -3520,7 +3520,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3520 cam->cmd_queue |= COMMAND_SETFORMAT; 3520 cam->cmd_queue |= COMMAND_SETFORMAT;
3521 } 3521 }
3522 3522
3523 up(&cam->param_lock); 3523 mutex_unlock(&cam->param_lock);
3524 3524
3525 /* setformat ignored by camera during streaming, 3525 /* setformat ignored by camera during streaming,
3526 * so stop/dispatch/start */ 3526 * so stop/dispatch/start */
@@ -3682,7 +3682,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3682 3682
3683 DBG("%d,%d/%dx%d\n", vc->x,vc->y,vc->width, vc->height); 3683 DBG("%d,%d/%dx%d\n", vc->x,vc->y,vc->width, vc->height);
3684 3684
3685 down(&cam->param_lock); 3685 mutex_lock(&cam->param_lock);
3686 3686
3687 cam->vc.x = vc->x; 3687 cam->vc.x = vc->x;
3688 cam->vc.y = vc->y; 3688 cam->vc.y = vc->y;
@@ -3692,7 +3692,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3692 set_vw_size(cam); 3692 set_vw_size(cam);
3693 cam->cmd_queue |= COMMAND_SETFORMAT; 3693 cam->cmd_queue |= COMMAND_SETFORMAT;
3694 3694
3695 up(&cam->param_lock); 3695 mutex_unlock(&cam->param_lock);
3696 3696
3697 /* setformat ignored by camera during streaming, 3697 /* setformat ignored by camera during streaming,
3698 * so stop/dispatch/start */ 3698 * so stop/dispatch/start */
@@ -3736,7 +3736,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3736 break; 3736 break;
3737 } 3737 }
3738 3738
3739 up(&cam->busy_lock); 3739 mutex_unlock(&cam->busy_lock);
3740 return retval; 3740 return retval;
3741} 3741}
3742 3742
@@ -3769,12 +3769,12 @@ static int cpia_mmap(struct file *file, struct vm_area_struct *vma)
3769 return -ENODEV; 3769 return -ENODEV;
3770 3770
3771 /* make this _really_ smp-safe */ 3771 /* make this _really_ smp-safe */
3772 if (down_interruptible(&cam->busy_lock)) 3772 if (mutex_lock_interruptible(&cam->busy_lock))
3773 return -EINTR; 3773 return -EINTR;
3774 3774
3775 if (!cam->frame_buf) { /* we do lazy allocation */ 3775 if (!cam->frame_buf) { /* we do lazy allocation */
3776 if ((retval = allocate_frame_buf(cam))) { 3776 if ((retval = allocate_frame_buf(cam))) {
3777 up(&cam->busy_lock); 3777 mutex_unlock(&cam->busy_lock);
3778 return retval; 3778 return retval;
3779 } 3779 }
3780 } 3780 }
@@ -3783,7 +3783,7 @@ static int cpia_mmap(struct file *file, struct vm_area_struct *vma)
3783 while (size > 0) { 3783 while (size > 0) {
3784 page = vmalloc_to_pfn((void *)pos); 3784 page = vmalloc_to_pfn((void *)pos);
3785 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) { 3785 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
3786 up(&cam->busy_lock); 3786 mutex_unlock(&cam->busy_lock);
3787 return -EAGAIN; 3787 return -EAGAIN;
3788 } 3788 }
3789 start += PAGE_SIZE; 3789 start += PAGE_SIZE;
@@ -3795,7 +3795,7 @@ static int cpia_mmap(struct file *file, struct vm_area_struct *vma)
3795 } 3795 }
3796 3796
3797 DBG("cpia_mmap: %ld\n", size); 3797 DBG("cpia_mmap: %ld\n", size);
3798 up(&cam->busy_lock); 3798 mutex_unlock(&cam->busy_lock);
3799 3799
3800 return 0; 3800 return 0;
3801} 3801}
@@ -3936,8 +3936,8 @@ static void init_camera_struct(struct cam_data *cam,
3936 memset(cam, 0, sizeof(struct cam_data)); 3936 memset(cam, 0, sizeof(struct cam_data));
3937 3937
3938 cam->ops = ops; 3938 cam->ops = ops;
3939 init_MUTEX(&cam->param_lock); 3939 mutex_init(&cam->param_lock);
3940 init_MUTEX(&cam->busy_lock); 3940 mutex_init(&cam->busy_lock);
3941 3941
3942 reset_camera_struct(cam); 3942 reset_camera_struct(cam);
3943 3943
diff --git a/drivers/media/video/cpia.h b/drivers/media/video/cpia.h
index f629b693ee65..de6678200a57 100644
--- a/drivers/media/video/cpia.h
+++ b/drivers/media/video/cpia.h
@@ -47,6 +47,7 @@
47#include <linux/videodev.h> 47#include <linux/videodev.h>
48#include <linux/list.h> 48#include <linux/list.h>
49#include <linux/smp_lock.h> 49#include <linux/smp_lock.h>
50#include <linux/mutex.h>
50 51
51struct cpia_camera_ops 52struct cpia_camera_ops
52{ 53{
@@ -246,7 +247,7 @@ enum v4l_camstates {
246struct cam_data { 247struct cam_data {
247 struct list_head cam_data_list; 248 struct list_head cam_data_list;
248 249
249 struct semaphore busy_lock; /* guard against SMP multithreading */ 250 struct mutex busy_lock; /* guard against SMP multithreading */
250 struct cpia_camera_ops *ops; /* lowlevel driver operations */ 251 struct cpia_camera_ops *ops; /* lowlevel driver operations */
251 void *lowlevel_data; /* private data for lowlevel driver */ 252 void *lowlevel_data; /* private data for lowlevel driver */
252 u8 *raw_image; /* buffer for raw image data */ 253 u8 *raw_image; /* buffer for raw image data */
@@ -261,7 +262,7 @@ struct cam_data {
261 u8 mainsFreq; /* for flicker control */ 262 u8 mainsFreq; /* for flicker control */
262 263
263 /* proc interface */ 264 /* proc interface */
264 struct semaphore param_lock; /* params lock for this camera */ 265 struct mutex param_lock; /* params lock for this camera */
265 struct cam_params params; /* camera settings */ 266 struct cam_params params; /* camera settings */
266 struct proc_dir_entry *proc_entry; /* /proc/cpia/videoX */ 267 struct proc_dir_entry *proc_entry; /* /proc/cpia/videoX */
267 268
diff --git a/drivers/media/video/cpia2/Kconfig b/drivers/media/video/cpia2/Kconfig
new file mode 100644
index 000000000000..513cc0927389
--- /dev/null
+++ b/drivers/media/video/cpia2/Kconfig
@@ -0,0 +1,9 @@
1config VIDEO_CPIA2
2 tristate "CPiA2 Video For Linux"
3 depends on VIDEO_DEV && USB
4 ---help---
5 This is the video4linux driver for cameras based on Vision's CPiA2
6 (Colour Processor Interface ASIC), such as the Digital Blue QX5
7 Microscope. If you have one of these cameras, say Y here
8
9 This driver is also available as a module (cpia2).
diff --git a/drivers/media/video/cpia2/Makefile b/drivers/media/video/cpia2/Makefile
new file mode 100644
index 000000000000..828cf1b1df86
--- /dev/null
+++ b/drivers/media/video/cpia2/Makefile
@@ -0,0 +1,3 @@
1cpia2-objs := cpia2_v4l.o cpia2_usb.o cpia2_core.o
2
3obj-$(CONFIG_VIDEO_CPIA2) += cpia2.o
diff --git a/drivers/media/video/cpia2/cpia2.h b/drivers/media/video/cpia2/cpia2.h
new file mode 100644
index 000000000000..95d3afa94a3d
--- /dev/null
+++ b/drivers/media/video/cpia2/cpia2.h
@@ -0,0 +1,497 @@
1/****************************************************************************
2 *
3 * Filename: cpia2.h
4 *
5 * Copyright 2001, STMicrolectronics, Inc.
6 *
7 * Contact: steve.miller@st.com
8 *
9 * Description:
10 * This is a USB driver for CPiA2 based video cameras.
11 *
12 * This driver is modelled on the cpia usb driver by
13 * Jochen Scharrlach and Johannes Erdfeldt.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
29 ****************************************************************************/
30
31#ifndef __CPIA2_H__
32#define __CPIA2_H__
33
34#include <linux/version.h>
35#include <linux/videodev.h>
36#include <linux/usb.h>
37#include <linux/poll.h>
38
39#include "cpia2dev.h"
40#include "cpia2_registers.h"
41
42/* define for verbose debug output */
43//#define _CPIA2_DEBUG_
44
45#define CPIA2_MAJ_VER 2
46#define CPIA2_MIN_VER 0
47#define CPIA2_PATCH_VER 0
48
49/***
50 * Image defines
51 ***/
52#ifndef true
53#define true 1
54#define false 0
55#endif
56
57/* Misc constants */
58#define ALLOW_CORRUPT 0 /* Causes collater to discard checksum */
59
60/* USB Transfer mode */
61#define XFER_ISOC 0
62#define XFER_BULK 1
63
64/* USB Alternates */
65#define USBIF_CMDONLY 0
66#define USBIF_BULK 1
67#define USBIF_ISO_1 2 /* 128 bytes/ms */
68#define USBIF_ISO_2 3 /* 384 bytes/ms */
69#define USBIF_ISO_3 4 /* 640 bytes/ms */
70#define USBIF_ISO_4 5 /* 768 bytes/ms */
71#define USBIF_ISO_5 6 /* 896 bytes/ms */
72#define USBIF_ISO_6 7 /* 1023 bytes/ms */
73
74/* Flicker Modes */
75#define NEVER_FLICKER 0
76#define ANTI_FLICKER_ON 1
77#define FLICKER_60 60
78#define FLICKER_50 50
79
80/* Debug flags */
81#define DEBUG_NONE 0
82#define DEBUG_REG 0x00000001
83#define DEBUG_DUMP_PATCH 0x00000002
84#define DEBUG_DUMP_REGS 0x00000004
85
86/***
87 * Video frame sizes
88 ***/
89enum {
90 VIDEOSIZE_VGA = 0, /* 640x480 */
91 VIDEOSIZE_CIF, /* 352x288 */
92 VIDEOSIZE_QVGA, /* 320x240 */
93 VIDEOSIZE_QCIF, /* 176x144 */
94 VIDEOSIZE_288_216,
95 VIDEOSIZE_256_192,
96 VIDEOSIZE_224_168,
97 VIDEOSIZE_192_144,
98};
99
100#define STV_IMAGE_CIF_ROWS 288
101#define STV_IMAGE_CIF_COLS 352
102
103#define STV_IMAGE_QCIF_ROWS 144
104#define STV_IMAGE_QCIF_COLS 176
105
106#define STV_IMAGE_VGA_ROWS 480
107#define STV_IMAGE_VGA_COLS 640
108
109#define STV_IMAGE_QVGA_ROWS 240
110#define STV_IMAGE_QVGA_COLS 320
111
112#define JPEG_MARKER_COM (1<<6) /* Comment segment */
113
114/***
115 * Enums
116 ***/
117/* Sensor types available with cpia2 asics */
118enum sensors {
119 CPIA2_SENSOR_410,
120 CPIA2_SENSOR_500
121};
122
123/* Asic types available in the CPiA2 architecture */
124#define CPIA2_ASIC_672 0x67
125
126/* Device types (stv672, stv676, etc) */
127#define DEVICE_STV_672 0x0001
128#define DEVICE_STV_676 0x0002
129
130enum frame_status {
131 FRAME_EMPTY,
132 FRAME_READING, /* In the process of being grabbed into */
133 FRAME_READY, /* Ready to be read */
134 FRAME_ERROR,
135};
136
137/***
138 * Register access (for USB request byte)
139 ***/
140enum {
141 CAMERAACCESS_SYSTEM = 0,
142 CAMERAACCESS_VC,
143 CAMERAACCESS_VP,
144 CAMERAACCESS_IDATA
145};
146
147#define CAMERAACCESS_TYPE_BLOCK 0x00
148#define CAMERAACCESS_TYPE_RANDOM 0x04
149#define CAMERAACCESS_TYPE_MASK 0x08
150#define CAMERAACCESS_TYPE_REPEAT 0x0C
151
152#define TRANSFER_READ 0
153#define TRANSFER_WRITE 1
154
155#define DEFAULT_ALT USBIF_ISO_6
156#define DEFAULT_BRIGHTNESS 0x46
157#define DEFAULT_CONTRAST 0x93
158#define DEFAULT_SATURATION 0x7f
159#define DEFAULT_TARGET_KB 0x30
160
161/* Power state */
162#define HI_POWER_MODE CPIA2_SYSTEM_CONTROL_HIGH_POWER
163#define LO_POWER_MODE CPIA2_SYSTEM_CONTROL_LOW_POWER
164
165
166/********
167 * Commands
168 *******/
169enum {
170 CPIA2_CMD_NONE = 0,
171 CPIA2_CMD_GET_VERSION,
172 CPIA2_CMD_GET_PNP_ID,
173 CPIA2_CMD_GET_ASIC_TYPE,
174 CPIA2_CMD_GET_SENSOR,
175 CPIA2_CMD_GET_VP_DEVICE,
176 CPIA2_CMD_GET_VP_BRIGHTNESS,
177 CPIA2_CMD_SET_VP_BRIGHTNESS,
178 CPIA2_CMD_GET_CONTRAST,
179 CPIA2_CMD_SET_CONTRAST,
180 CPIA2_CMD_GET_VP_SATURATION,
181 CPIA2_CMD_SET_VP_SATURATION,
182 CPIA2_CMD_GET_VP_GPIO_DIRECTION,
183 CPIA2_CMD_SET_VP_GPIO_DIRECTION,
184 CPIA2_CMD_GET_VP_GPIO_DATA,
185 CPIA2_CMD_SET_VP_GPIO_DATA,
186 CPIA2_CMD_GET_VC_MP_GPIO_DIRECTION,
187 CPIA2_CMD_SET_VC_MP_GPIO_DIRECTION,
188 CPIA2_CMD_GET_VC_MP_GPIO_DATA,
189 CPIA2_CMD_SET_VC_MP_GPIO_DATA,
190 CPIA2_CMD_ENABLE_PACKET_CTRL,
191 CPIA2_CMD_GET_FLICKER_MODES,
192 CPIA2_CMD_SET_FLICKER_MODES,
193 CPIA2_CMD_RESET_FIFO, /* clear fifo and enable stream block */
194 CPIA2_CMD_SET_HI_POWER,
195 CPIA2_CMD_SET_LOW_POWER,
196 CPIA2_CMD_CLEAR_V2W_ERR,
197 CPIA2_CMD_SET_USER_MODE,
198 CPIA2_CMD_GET_USER_MODE,
199 CPIA2_CMD_FRAMERATE_REQ,
200 CPIA2_CMD_SET_COMPRESSION_STATE,
201 CPIA2_CMD_GET_WAKEUP,
202 CPIA2_CMD_SET_WAKEUP,
203 CPIA2_CMD_GET_PW_CONTROL,
204 CPIA2_CMD_SET_PW_CONTROL,
205 CPIA2_CMD_GET_SYSTEM_CTRL,
206 CPIA2_CMD_SET_SYSTEM_CTRL,
207 CPIA2_CMD_GET_VP_SYSTEM_STATE,
208 CPIA2_CMD_GET_VP_SYSTEM_CTRL,
209 CPIA2_CMD_SET_VP_SYSTEM_CTRL,
210 CPIA2_CMD_GET_VP_EXP_MODES,
211 CPIA2_CMD_SET_VP_EXP_MODES,
212 CPIA2_CMD_GET_DEVICE_CONFIG,
213 CPIA2_CMD_SET_DEVICE_CONFIG,
214 CPIA2_CMD_SET_SERIAL_ADDR,
215 CPIA2_CMD_SET_SENSOR_CR1,
216 CPIA2_CMD_GET_VC_CONTROL,
217 CPIA2_CMD_SET_VC_CONTROL,
218 CPIA2_CMD_SET_TARGET_KB,
219 CPIA2_CMD_SET_DEF_JPEG_OPT,
220 CPIA2_CMD_REHASH_VP4,
221 CPIA2_CMD_GET_USER_EFFECTS,
222 CPIA2_CMD_SET_USER_EFFECTS
223};
224
225enum user_cmd {
226 COMMAND_NONE = 0x00000001,
227 COMMAND_SET_FPS = 0x00000002,
228 COMMAND_SET_COLOR_PARAMS = 0x00000004,
229 COMMAND_GET_COLOR_PARAMS = 0x00000008,
230 COMMAND_SET_FORMAT = 0x00000010, /* size, etc */
231 COMMAND_SET_FLICKER = 0x00000020
232};
233
234/***
235 * Some defines specific to the 676 chip
236 ***/
237#define CAMACC_CIF 0x01
238#define CAMACC_VGA 0x02
239#define CAMACC_QCIF 0x04
240#define CAMACC_QVGA 0x08
241
242
243struct cpia2_register {
244 u8 index;
245 u8 value;
246};
247
248struct cpia2_reg_mask {
249 u8 index;
250 u8 and_mask;
251 u8 or_mask;
252 u8 fill;
253};
254
255struct cpia2_command {
256 u32 command;
257 u8 req_mode; /* (Block or random) | registerBank */
258 u8 reg_count;
259 u8 direction;
260 u8 start;
261 union reg_types {
262 struct cpia2_register registers[32];
263 struct cpia2_reg_mask masks[16];
264 u8 block_data[64];
265 u8 *patch_data; /* points to function defined block */
266 } buffer;
267};
268
269struct camera_params {
270 struct {
271 u8 firmware_revision_hi; /* For system register set (bank 0) */
272 u8 firmware_revision_lo;
273 u8 asic_id; /* Video Compressor set (bank 1) */
274 u8 asic_rev;
275 u8 vp_device_hi; /* Video Processor set (bank 2) */
276 u8 vp_device_lo;
277 u8 sensor_flags;
278 u8 sensor_rev;
279 } version;
280
281 struct {
282 u32 device_type; /* enumerated from vendor/product ids.
283 * Currently, either STV_672 or STV_676 */
284 u16 vendor;
285 u16 product;
286 u16 device_revision;
287 } pnp_id;
288
289 struct {
290 u8 brightness; /* CPIA2_VP_EXPOSURE_TARGET */
291 u8 contrast; /* Note: this is CPIA2_VP_YRANGE */
292 u8 saturation; /* CPIA2_VP_SATURATION */
293 } color_params;
294
295 struct {
296 u8 cam_register;
297 u8 flicker_mode_req; /* 1 if flicker on, else never flicker */
298 int mains_frequency;
299 } flicker_control;
300
301 struct {
302 u8 jpeg_options;
303 u8 creep_period;
304 u8 user_squeeze;
305 u8 inhibit_htables;
306 } compression;
307
308 struct {
309 u8 ohsize; /* output image size */
310 u8 ovsize;
311 u8 hcrop; /* cropping start_pos/4 */
312 u8 vcrop;
313 u8 hphase; /* scaling registers */
314 u8 vphase;
315 u8 hispan;
316 u8 vispan;
317 u8 hicrop;
318 u8 vicrop;
319 u8 hifraction;
320 u8 vifraction;
321 } image_size;
322
323 struct {
324 int width; /* actual window width */
325 int height; /* actual window height */
326 } roi;
327
328 struct {
329 u8 video_mode;
330 u8 frame_rate;
331 u8 video_size; /* Not a register, just a convenience for cropped sizes */
332 u8 gpio_direction;
333 u8 gpio_data;
334 u8 system_ctrl;
335 u8 system_state;
336 u8 lowlight_boost; /* Bool: 0 = off, 1 = on */
337 u8 device_config;
338 u8 exposure_modes;
339 u8 user_effects;
340 } vp_params;
341
342 struct {
343 u8 pw_control;
344 u8 wakeup;
345 u8 vc_control;
346 u8 vc_mp_direction;
347 u8 vc_mp_data;
348 u8 target_kb;
349 } vc_params;
350
351 struct {
352 u8 power_mode;
353 u8 system_ctrl;
354 u8 stream_mode; /* This is the current alternate for usb drivers */
355 u8 allow_corrupt;
356 } camera_state;
357};
358
359#define NUM_SBUF 2
360
361struct cpia2_sbuf {
362 char *data;
363 struct urb *urb;
364};
365
366struct framebuf {
367 struct timeval timestamp;
368 unsigned long seq;
369 int num;
370 int length;
371 int max_length;
372 volatile enum frame_status status;
373 u8 *data;
374 struct framebuf *next;
375};
376
377struct cpia2_fh {
378 enum v4l2_priority prio;
379 u8 mmapped;
380};
381
382struct camera_data {
383 /* locks */
384 struct semaphore busy_lock; /* guard against SMP multithreading */
385 struct v4l2_prio_state prio;
386
387 /* camera status */
388 volatile int present; /* Is the camera still present? */
389 int open_count; /* # of process that have camera open */
390 int first_image_seen;
391 u8 mains_freq; /* for flicker control */
392 enum sensors sensor_type;
393 u8 flush;
394 u8 mmapped;
395 int streaming; /* 0 = no, 1 = yes */
396 int xfer_mode; /* XFER_BULK or XFER_ISOC */
397 struct camera_params params; /* camera settings */
398
399 /* v4l */
400 int video_size; /* VIDEO_SIZE_ */
401 struct video_device *vdev; /* v4l videodev */
402 struct video_picture vp; /* v4l camera settings */
403 struct video_window vw; /* v4l capture area */
404 __u32 pixelformat; /* Format fourcc */
405
406 /* USB */
407 struct usb_device *dev;
408 unsigned char iface;
409 unsigned int cur_alt;
410 unsigned int old_alt;
411 struct cpia2_sbuf sbuf[NUM_SBUF]; /* Double buffering */
412
413 wait_queue_head_t wq_stream;
414
415 /* Buffering */
416 u32 frame_size;
417 int num_frames;
418 unsigned long frame_count;
419 u8 *frame_buffer; /* frame buffer data */
420 struct framebuf *buffers;
421 struct framebuf * volatile curbuff;
422 struct framebuf *workbuff;
423
424 /* MJPEG Extension */
425 int APPn; /* Number of APP segment to be written, must be 0..15 */
426 int APP_len; /* Length of data in JPEG APPn segment */
427 char APP_data[60]; /* Data in the JPEG APPn segment. */
428
429 int COM_len; /* Length of data in JPEG COM segment */
430 char COM_data[60]; /* Data in JPEG COM segment */
431};
432
433/* v4l */
434int cpia2_register_camera(struct camera_data *cam);
435void cpia2_unregister_camera(struct camera_data *cam);
436
437/* core */
438int cpia2_reset_camera(struct camera_data *cam);
439int cpia2_set_low_power(struct camera_data *cam);
440void cpia2_dbg_dump_registers(struct camera_data *cam);
441int cpia2_match_video_size(int width, int height);
442void cpia2_set_camera_state(struct camera_data *cam);
443void cpia2_save_camera_state(struct camera_data *cam);
444void cpia2_set_color_params(struct camera_data *cam);
445void cpia2_set_brightness(struct camera_data *cam, unsigned char value);
446void cpia2_set_contrast(struct camera_data *cam, unsigned char value);
447void cpia2_set_saturation(struct camera_data *cam, unsigned char value);
448int cpia2_set_flicker_mode(struct camera_data *cam, int mode);
449void cpia2_set_format(struct camera_data *cam);
450int cpia2_send_command(struct camera_data *cam, struct cpia2_command *cmd);
451int cpia2_do_command(struct camera_data *cam,
452 unsigned int command,
453 unsigned char direction, unsigned char param);
454struct camera_data *cpia2_init_camera_struct(void);
455int cpia2_init_camera(struct camera_data *cam);
456int cpia2_allocate_buffers(struct camera_data *cam);
457void cpia2_free_buffers(struct camera_data *cam);
458long cpia2_read(struct camera_data *cam,
459 char *buf, unsigned long count, int noblock);
460unsigned int cpia2_poll(struct camera_data *cam,
461 struct file *filp, poll_table *wait);
462int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma);
463void cpia2_set_property_flip(struct camera_data *cam, int prop_val);
464void cpia2_set_property_mirror(struct camera_data *cam, int prop_val);
465int cpia2_set_target_kb(struct camera_data *cam, unsigned char value);
466int cpia2_set_gpio(struct camera_data *cam, unsigned char setting);
467int cpia2_set_fps(struct camera_data *cam, int framerate);
468
469/* usb */
470int cpia2_usb_init(void);
471void cpia2_usb_cleanup(void);
472int cpia2_usb_transfer_cmd(struct camera_data *cam, void *registers,
473 u8 request, u8 start, u8 count, u8 direction);
474int cpia2_usb_stream_start(struct camera_data *cam, unsigned int alternate);
475int cpia2_usb_stream_stop(struct camera_data *cam);
476int cpia2_usb_stream_pause(struct camera_data *cam);
477int cpia2_usb_stream_resume(struct camera_data *cam);
478int cpia2_usb_change_streaming_alternate(struct camera_data *cam,
479 unsigned int alt);
480
481
482/* ----------------------- debug functions ---------------------- */
483#ifdef _CPIA2_DEBUG_
484#define ALOG(lev, fmt, args...) printk(lev "%s:%d %s(): " fmt, __FILE__, __LINE__, __func__, ## args)
485#define LOG(fmt, args...) ALOG(KERN_INFO, fmt, ## args)
486#define ERR(fmt, args...) ALOG(KERN_ERR, fmt, ## args)
487#define DBG(fmt, args...) ALOG(KERN_DEBUG, fmt, ## args)
488#else
489#define ALOG(fmt,args...) printk(fmt,##args)
490#define LOG(fmt,args...) ALOG(KERN_INFO "cpia2: "fmt,##args)
491#define ERR(fmt,args...) ALOG(KERN_ERR "cpia2: "fmt,##args)
492#define DBG(fmn,args...) do {} while(0)
493#endif
494/* No function or lineno, for shorter lines */
495#define KINFO(fmt, args...) printk(KERN_INFO fmt,##args)
496
497#endif
diff --git a/drivers/media/video/cpia2/cpia2_core.c b/drivers/media/video/cpia2/cpia2_core.c
new file mode 100644
index 000000000000..5dfb242d5b8c
--- /dev/null
+++ b/drivers/media/video/cpia2/cpia2_core.c
@@ -0,0 +1,2525 @@
1/****************************************************************************
2 *
3 * Filename: cpia2_core.c
4 *
5 * Copyright 2001, STMicrolectronics, Inc.
6 * Contact: steve.miller@st.com
7 *
8 * Description:
9 * This is a USB driver for CPia2 based video cameras.
10 * The infrastructure of this driver is based on the cpia usb driver by
11 * Jochen Scharrlach and Johannes Erdfeldt.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 * Stripped of 2.4 stuff ready for main kernel submit by
28 * Alan Cox <alan@redhat.com>
29 *
30 ****************************************************************************/
31
32#include "cpia2.h"
33
34#include <linux/slab.h>
35#include <linux/vmalloc.h>
36
37//#define _CPIA2_DEBUG_
38
39#include "cpia2patch.h"
40
41#ifdef _CPIA2_DEBUG_
42
43static const char *block_name[] = {
44 "System",
45 "VC",
46 "VP",
47 "IDATA"
48};
49#endif
50
51static unsigned int debugs_on = 0;//DEBUG_REG;
52
53
54/******************************************************************************
55 *
56 * Forward Declarations
57 *
58 *****************************************************************************/
59static int apply_vp_patch(struct camera_data *cam);
60static int set_default_user_mode(struct camera_data *cam);
61static int set_vw_size(struct camera_data *cam, int size);
62static int configure_sensor(struct camera_data *cam,
63 int reqwidth, int reqheight);
64static int config_sensor_410(struct camera_data *cam,
65 int reqwidth, int reqheight);
66static int config_sensor_500(struct camera_data *cam,
67 int reqwidth, int reqheight);
68static int set_all_properties(struct camera_data *cam);
69static void get_color_params(struct camera_data *cam);
70static void wake_system(struct camera_data *cam);
71static void set_lowlight_boost(struct camera_data *cam);
72static void reset_camera_struct(struct camera_data *cam);
73static int cpia2_set_high_power(struct camera_data *cam);
74
75/* Here we want the physical address of the memory.
76 * This is used when initializing the contents of the
77 * area and marking the pages as reserved.
78 */
79static inline unsigned long kvirt_to_pa(unsigned long adr)
80{
81 unsigned long kva, ret;
82
83 kva = (unsigned long) page_address(vmalloc_to_page((void *)adr));
84 kva |= adr & (PAGE_SIZE-1); /* restore the offset */
85 ret = __pa(kva);
86 return ret;
87}
88
89static void *rvmalloc(unsigned long size)
90{
91 void *mem;
92 unsigned long adr;
93
94 /* Round it off to PAGE_SIZE */
95 size = PAGE_ALIGN(size);
96
97 mem = vmalloc_32(size);
98 if (!mem)
99 return NULL;
100
101 memset(mem, 0, size); /* Clear the ram out, no junk to the user */
102 adr = (unsigned long) mem;
103
104 while ((long)size > 0) {
105 SetPageReserved(vmalloc_to_page((void *)adr));
106 adr += PAGE_SIZE;
107 size -= PAGE_SIZE;
108 }
109 return mem;
110}
111
112static void rvfree(void *mem, unsigned long size)
113{
114 unsigned long adr;
115
116 if (!mem)
117 return;
118
119 size = PAGE_ALIGN(size);
120
121 adr = (unsigned long) mem;
122 while ((long)size > 0) {
123 ClearPageReserved(vmalloc_to_page((void *)adr));
124 adr += PAGE_SIZE;
125 size -= PAGE_SIZE;
126 }
127 vfree(mem);
128}
129
130/******************************************************************************
131 *
132 * cpia2_do_command
133 *
134 * Send an arbitrary command to the camera. For commands that read from
135 * the camera, copy the buffers into the proper param structures.
136 *****************************************************************************/
137int cpia2_do_command(struct camera_data *cam,
138 u32 command, u8 direction, u8 param)
139{
140 int retval = 0;
141 struct cpia2_command cmd;
142 unsigned int device = cam->params.pnp_id.device_type;
143
144 cmd.command = command;
145 cmd.reg_count = 2; /* default */
146 cmd.direction = direction;
147
148 /***
149 * Set up the command.
150 ***/
151 switch (command) {
152 case CPIA2_CMD_GET_VERSION:
153 cmd.req_mode =
154 CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_SYSTEM;
155 cmd.start = CPIA2_SYSTEM_DEVICE_HI;
156 break;
157 case CPIA2_CMD_GET_PNP_ID:
158 cmd.req_mode =
159 CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_SYSTEM;
160 cmd.reg_count = 8;
161 cmd.start = CPIA2_SYSTEM_DESCRIP_VID_HI;
162 break;
163 case CPIA2_CMD_GET_ASIC_TYPE:
164 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VC;
165 cmd.start = CPIA2_VC_ASIC_ID;
166 break;
167 case CPIA2_CMD_GET_SENSOR:
168 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
169 cmd.start = CPIA2_VP_SENSOR_FLAGS;
170 break;
171 case CPIA2_CMD_GET_VP_DEVICE:
172 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
173 cmd.start = CPIA2_VP_DEVICEH;
174 break;
175 case CPIA2_CMD_SET_VP_BRIGHTNESS:
176 cmd.buffer.block_data[0] = param; /* Then fall through */
177 case CPIA2_CMD_GET_VP_BRIGHTNESS:
178 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
179 cmd.reg_count = 1;
180 if (device == DEVICE_STV_672)
181 cmd.start = CPIA2_VP4_EXPOSURE_TARGET;
182 else
183 cmd.start = CPIA2_VP5_EXPOSURE_TARGET;
184 break;
185 case CPIA2_CMD_SET_CONTRAST:
186 cmd.buffer.block_data[0] = param; /* Then fall through */
187 case CPIA2_CMD_GET_CONTRAST:
188 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
189 cmd.reg_count = 1;
190 cmd.start = CPIA2_VP_YRANGE;
191 break;
192 case CPIA2_CMD_SET_VP_SATURATION:
193 cmd.buffer.block_data[0] = param; /* Then fall through */
194 case CPIA2_CMD_GET_VP_SATURATION:
195 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
196 cmd.reg_count = 1;
197 if (device == DEVICE_STV_672)
198 cmd.start = CPIA2_VP_SATURATION;
199 else
200 cmd.start = CPIA2_VP5_MCUVSATURATION;
201 break;
202 case CPIA2_CMD_SET_VP_GPIO_DATA:
203 cmd.buffer.block_data[0] = param; /* Then fall through */
204 case CPIA2_CMD_GET_VP_GPIO_DATA:
205 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
206 cmd.reg_count = 1;
207 cmd.start = CPIA2_VP_GPIO_DATA;
208 break;
209 case CPIA2_CMD_SET_VP_GPIO_DIRECTION:
210 cmd.buffer.block_data[0] = param; /* Then fall through */
211 case CPIA2_CMD_GET_VP_GPIO_DIRECTION:
212 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
213 cmd.reg_count = 1;
214 cmd.start = CPIA2_VP_GPIO_DIRECTION;
215 break;
216 case CPIA2_CMD_SET_VC_MP_GPIO_DATA:
217 cmd.buffer.block_data[0] = param; /* Then fall through */
218 case CPIA2_CMD_GET_VC_MP_GPIO_DATA:
219 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VC;
220 cmd.reg_count = 1;
221 cmd.start = CPIA2_VC_MP_DATA;
222 break;
223 case CPIA2_CMD_SET_VC_MP_GPIO_DIRECTION:
224 cmd.buffer.block_data[0] = param; /* Then fall through */
225 case CPIA2_CMD_GET_VC_MP_GPIO_DIRECTION:
226 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VC;
227 cmd.reg_count = 1;
228 cmd.start = CPIA2_VC_MP_DIR;
229 break;
230 case CPIA2_CMD_ENABLE_PACKET_CTRL:
231 cmd.req_mode =
232 CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_SYSTEM;
233 cmd.start = CPIA2_SYSTEM_INT_PACKET_CTRL;
234 cmd.reg_count = 1;
235 cmd.buffer.block_data[0] = param;
236 break;
237 case CPIA2_CMD_SET_FLICKER_MODES:
238 cmd.buffer.block_data[0] = param; /* Then fall through */
239 case CPIA2_CMD_GET_FLICKER_MODES:
240 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
241 cmd.reg_count = 1;
242 cmd.start = CPIA2_VP_FLICKER_MODES;
243 break;
244 case CPIA2_CMD_RESET_FIFO: /* clear fifo and enable stream block */
245 cmd.req_mode = CAMERAACCESS_TYPE_RANDOM | CAMERAACCESS_VC;
246 cmd.reg_count = 2;
247 cmd.start = 0;
248 cmd.buffer.registers[0].index = CPIA2_VC_ST_CTRL;
249 cmd.buffer.registers[0].value = CPIA2_VC_ST_CTRL_SRC_VC |
250 CPIA2_VC_ST_CTRL_DST_USB | CPIA2_VC_ST_CTRL_EOF_DETECT;
251 cmd.buffer.registers[1].index = CPIA2_VC_ST_CTRL;
252 cmd.buffer.registers[1].value = CPIA2_VC_ST_CTRL_SRC_VC |
253 CPIA2_VC_ST_CTRL_DST_USB |
254 CPIA2_VC_ST_CTRL_EOF_DETECT |
255 CPIA2_VC_ST_CTRL_FIFO_ENABLE;
256 break;
257 case CPIA2_CMD_SET_HI_POWER:
258 cmd.req_mode =
259 CAMERAACCESS_TYPE_RANDOM | CAMERAACCESS_SYSTEM;
260 cmd.reg_count = 2;
261 cmd.buffer.registers[0].index =
262 CPIA2_SYSTEM_SYSTEM_CONTROL;
263 cmd.buffer.registers[1].index =
264 CPIA2_SYSTEM_SYSTEM_CONTROL;
265 cmd.buffer.registers[0].value = CPIA2_SYSTEM_CONTROL_CLEAR_ERR;
266 cmd.buffer.registers[1].value =
267 CPIA2_SYSTEM_CONTROL_HIGH_POWER;
268 break;
269 case CPIA2_CMD_SET_LOW_POWER:
270 cmd.req_mode =
271 CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_SYSTEM;
272 cmd.reg_count = 1;
273 cmd.start = CPIA2_SYSTEM_SYSTEM_CONTROL;
274 cmd.buffer.block_data[0] = 0;
275 break;
276 case CPIA2_CMD_CLEAR_V2W_ERR:
277 cmd.req_mode =
278 CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_SYSTEM;
279 cmd.reg_count = 1;
280 cmd.start = CPIA2_SYSTEM_SYSTEM_CONTROL;
281 cmd.buffer.block_data[0] = CPIA2_SYSTEM_CONTROL_CLEAR_ERR;
282 break;
283 case CPIA2_CMD_SET_USER_MODE: /* Then fall through */
284 cmd.buffer.block_data[0] = param;
285 case CPIA2_CMD_GET_USER_MODE:
286 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
287 cmd.reg_count = 1;
288 if (device == DEVICE_STV_672)
289 cmd.start = CPIA2_VP4_USER_MODE;
290 else
291 cmd.start = CPIA2_VP5_USER_MODE;
292 break;
293 case CPIA2_CMD_FRAMERATE_REQ:
294 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
295 cmd.reg_count = 1;
296 if (device == DEVICE_STV_672)
297 cmd.start = CPIA2_VP4_FRAMERATE_REQUEST;
298 else
299 cmd.start = CPIA2_VP5_FRAMERATE_REQUEST;
300 cmd.buffer.block_data[0] = param;
301 break;
302 case CPIA2_CMD_SET_WAKEUP:
303 cmd.buffer.block_data[0] = param; /* Then fall through */
304 case CPIA2_CMD_GET_WAKEUP:
305 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VC;
306 cmd.reg_count = 1;
307 cmd.start = CPIA2_VC_WAKEUP;
308 break;
309 case CPIA2_CMD_SET_PW_CONTROL:
310 cmd.buffer.block_data[0] = param; /* Then fall through */
311 case CPIA2_CMD_GET_PW_CONTROL:
312 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VC;
313 cmd.reg_count = 1;
314 cmd.start = CPIA2_VC_PW_CTRL;
315 break;
316 case CPIA2_CMD_GET_VP_SYSTEM_STATE:
317 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
318 cmd.reg_count = 1;
319 cmd.start = CPIA2_VP_SYSTEMSTATE;
320 break;
321 case CPIA2_CMD_SET_SYSTEM_CTRL:
322 cmd.buffer.block_data[0] = param; /* Then fall through */
323 case CPIA2_CMD_GET_SYSTEM_CTRL:
324 cmd.req_mode =
325 CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_SYSTEM;
326 cmd.reg_count = 1;
327 cmd.start = CPIA2_SYSTEM_SYSTEM_CONTROL;
328 break;
329 case CPIA2_CMD_SET_VP_SYSTEM_CTRL:
330 cmd.buffer.block_data[0] = param; /* Then fall through */
331 case CPIA2_CMD_GET_VP_SYSTEM_CTRL:
332 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
333 cmd.reg_count = 1;
334 cmd.start = CPIA2_VP_SYSTEMCTRL;
335 break;
336 case CPIA2_CMD_SET_VP_EXP_MODES:
337 cmd.buffer.block_data[0] = param; /* Then fall through */
338 case CPIA2_CMD_GET_VP_EXP_MODES:
339 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
340 cmd.reg_count = 1;
341 cmd.start = CPIA2_VP_EXPOSURE_MODES;
342 break;
343 case CPIA2_CMD_SET_DEVICE_CONFIG:
344 cmd.buffer.block_data[0] = param; /* Then fall through */
345 case CPIA2_CMD_GET_DEVICE_CONFIG:
346 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
347 cmd.reg_count = 1;
348 cmd.start = CPIA2_VP_DEVICE_CONFIG;
349 break;
350 case CPIA2_CMD_SET_SERIAL_ADDR:
351 cmd.buffer.block_data[0] = param;
352 cmd.req_mode =
353 CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_SYSTEM;
354 cmd.reg_count = 1;
355 cmd.start = CPIA2_SYSTEM_VP_SERIAL_ADDR;
356 break;
357 case CPIA2_CMD_SET_SENSOR_CR1:
358 cmd.buffer.block_data[0] = param;
359 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
360 cmd.reg_count = 1;
361 cmd.start = CPIA2_SENSOR_CR1;
362 break;
363 case CPIA2_CMD_SET_VC_CONTROL:
364 cmd.buffer.block_data[0] = param; /* Then fall through */
365 case CPIA2_CMD_GET_VC_CONTROL:
366 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VC;
367 cmd.reg_count = 1;
368 cmd.start = CPIA2_VC_VC_CTRL;
369 break;
370 case CPIA2_CMD_SET_TARGET_KB:
371 cmd.req_mode = CAMERAACCESS_TYPE_RANDOM | CAMERAACCESS_VC;
372 cmd.reg_count = 1;
373 cmd.buffer.registers[0].index = CPIA2_VC_VC_TARGET_KB;
374 cmd.buffer.registers[0].value = param;
375 break;
376 case CPIA2_CMD_SET_DEF_JPEG_OPT:
377 cmd.req_mode = CAMERAACCESS_TYPE_RANDOM | CAMERAACCESS_VC;
378 cmd.reg_count = 4;
379 cmd.buffer.registers[0].index = CPIA2_VC_VC_JPEG_OPT;
380 cmd.buffer.registers[0].value =
381 CPIA2_VC_VC_JPEG_OPT_DOUBLE_SQUEEZE;
382 cmd.buffer.registers[1].index = CPIA2_VC_VC_USER_SQUEEZE;
383 cmd.buffer.registers[1].value = 20;
384 cmd.buffer.registers[2].index = CPIA2_VC_VC_CREEP_PERIOD;
385 cmd.buffer.registers[2].value = 2;
386 cmd.buffer.registers[3].index = CPIA2_VC_VC_JPEG_OPT;
387 cmd.buffer.registers[3].value = CPIA2_VC_VC_JPEG_OPT_DEFAULT;
388 break;
389 case CPIA2_CMD_REHASH_VP4:
390 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
391 cmd.reg_count = 1;
392 cmd.start = CPIA2_VP_REHASH_VALUES;
393 cmd.buffer.block_data[0] = param;
394 break;
395 case CPIA2_CMD_SET_USER_EFFECTS: /* Note: Be careful with this as
396 this register can also affect
397 flicker modes */
398 cmd.buffer.block_data[0] = param; /* Then fall through */
399 case CPIA2_CMD_GET_USER_EFFECTS:
400 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
401 cmd.reg_count = 1;
402 if (device == DEVICE_STV_672)
403 cmd.start = CPIA2_VP4_USER_EFFECTS;
404 else
405 cmd.start = CPIA2_VP5_USER_EFFECTS;
406 break;
407 default:
408 LOG("DoCommand received invalid command\n");
409 return -EINVAL;
410 }
411
412 retval = cpia2_send_command(cam, &cmd);
413 if (retval) {
414 return retval;
415 }
416
417 /***
418 * Now copy any results from a read into the appropriate param struct.
419 ***/
420 switch (command) {
421 case CPIA2_CMD_GET_VERSION:
422 cam->params.version.firmware_revision_hi =
423 cmd.buffer.block_data[0];
424 cam->params.version.firmware_revision_lo =
425 cmd.buffer.block_data[1];
426 break;
427 case CPIA2_CMD_GET_PNP_ID:
428 cam->params.pnp_id.vendor = (cmd.buffer.block_data[0] << 8) |
429 cmd.buffer.block_data[1];
430 cam->params.pnp_id.product = (cmd.buffer.block_data[2] << 8) |
431 cmd.buffer.block_data[3];
432 cam->params.pnp_id.device_revision =
433 (cmd.buffer.block_data[4] << 8) |
434 cmd.buffer.block_data[5];
435 if (cam->params.pnp_id.vendor == 0x553) {
436 if (cam->params.pnp_id.product == 0x100) {
437 cam->params.pnp_id.device_type = DEVICE_STV_672;
438 } else if (cam->params.pnp_id.product == 0x140 ||
439 cam->params.pnp_id.product == 0x151) {
440 cam->params.pnp_id.device_type = DEVICE_STV_676;
441 }
442 }
443 break;
444 case CPIA2_CMD_GET_ASIC_TYPE:
445 cam->params.version.asic_id = cmd.buffer.block_data[0];
446 cam->params.version.asic_rev = cmd.buffer.block_data[1];
447 break;
448 case CPIA2_CMD_GET_SENSOR:
449 cam->params.version.sensor_flags = cmd.buffer.block_data[0];
450 cam->params.version.sensor_rev = cmd.buffer.block_data[1];
451 break;
452 case CPIA2_CMD_GET_VP_DEVICE:
453 cam->params.version.vp_device_hi = cmd.buffer.block_data[0];
454 cam->params.version.vp_device_lo = cmd.buffer.block_data[1];
455 break;
456 case CPIA2_CMD_GET_VP_BRIGHTNESS:
457 cam->params.color_params.brightness = cmd.buffer.block_data[0];
458 break;
459 case CPIA2_CMD_GET_CONTRAST:
460 cam->params.color_params.contrast = cmd.buffer.block_data[0];
461 break;
462 case CPIA2_CMD_GET_VP_SATURATION:
463 cam->params.color_params.saturation = cmd.buffer.block_data[0];
464 break;
465 case CPIA2_CMD_GET_VP_GPIO_DATA:
466 cam->params.vp_params.gpio_data = cmd.buffer.block_data[0];
467 break;
468 case CPIA2_CMD_GET_VP_GPIO_DIRECTION:
469 cam->params.vp_params.gpio_direction = cmd.buffer.block_data[0];
470 break;
471 case CPIA2_CMD_GET_VC_MP_GPIO_DIRECTION:
472 cam->params.vc_params.vc_mp_direction =cmd.buffer.block_data[0];
473 break;
474 case CPIA2_CMD_GET_VC_MP_GPIO_DATA:
475 cam->params.vc_params.vc_mp_data = cmd.buffer.block_data[0];
476 break;
477 case CPIA2_CMD_GET_FLICKER_MODES:
478 cam->params.flicker_control.cam_register =
479 cmd.buffer.block_data[0];
480 break;
481 case CPIA2_CMD_GET_WAKEUP:
482 cam->params.vc_params.wakeup = cmd.buffer.block_data[0];
483 break;
484 case CPIA2_CMD_GET_PW_CONTROL:
485 cam->params.vc_params.pw_control = cmd.buffer.block_data[0];
486 break;
487 case CPIA2_CMD_GET_SYSTEM_CTRL:
488 cam->params.camera_state.system_ctrl = cmd.buffer.block_data[0];
489 break;
490 case CPIA2_CMD_GET_VP_SYSTEM_STATE:
491 cam->params.vp_params.system_state = cmd.buffer.block_data[0];
492 break;
493 case CPIA2_CMD_GET_VP_SYSTEM_CTRL:
494 cam->params.vp_params.system_ctrl = cmd.buffer.block_data[0];
495 break;
496 case CPIA2_CMD_GET_VP_EXP_MODES:
497 cam->params.vp_params.exposure_modes = cmd.buffer.block_data[0];
498 break;
499 case CPIA2_CMD_GET_DEVICE_CONFIG:
500 cam->params.vp_params.device_config = cmd.buffer.block_data[0];
501 break;
502 case CPIA2_CMD_GET_VC_CONTROL:
503 cam->params.vc_params.vc_control = cmd.buffer.block_data[0];
504 break;
505 case CPIA2_CMD_GET_USER_MODE:
506 cam->params.vp_params.video_mode = cmd.buffer.block_data[0];
507 break;
508 case CPIA2_CMD_GET_USER_EFFECTS:
509 cam->params.vp_params.user_effects = cmd.buffer.block_data[0];
510 break;
511 default:
512 break;
513 }
514 return retval;
515}
516
517/******************************************************************************
518 *
519 * cpia2_send_command
520 *
521 *****************************************************************************/
522int cpia2_send_command(struct camera_data *cam, struct cpia2_command *cmd)
523{
524 u8 count;
525 u8 start;
526 u8 block_index;
527 u8 *buffer;
528 int retval;
529 const char* dir;
530
531 if (cmd->direction == TRANSFER_WRITE) {
532 dir = "Write";
533 } else {
534 dir = "Read";
535 }
536
537 block_index = cmd->req_mode & 0x03;
538
539 switch (cmd->req_mode & 0x0c) {
540 case CAMERAACCESS_TYPE_RANDOM:
541 count = cmd->reg_count * sizeof(struct cpia2_register);
542 start = 0;
543 buffer = (u8 *) & cmd->buffer;
544 if (debugs_on & DEBUG_REG)
545 DBG("%s Random: Register block %s\n", dir,
546 block_name[block_index]);
547 break;
548 case CAMERAACCESS_TYPE_BLOCK:
549 count = cmd->reg_count;
550 start = cmd->start;
551 buffer = cmd->buffer.block_data;
552 if (debugs_on & DEBUG_REG)
553 DBG("%s Block: Register block %s\n", dir,
554 block_name[block_index]);
555 break;
556 case CAMERAACCESS_TYPE_MASK:
557 count = cmd->reg_count * sizeof(struct cpia2_reg_mask);
558 start = 0;
559 buffer = (u8 *) & cmd->buffer;
560 if (debugs_on & DEBUG_REG)
561 DBG("%s Mask: Register block %s\n", dir,
562 block_name[block_index]);
563 break;
564 case CAMERAACCESS_TYPE_REPEAT: /* For patch blocks only */
565 count = cmd->reg_count;
566 start = cmd->start;
567 buffer = cmd->buffer.block_data;
568 if (debugs_on & DEBUG_REG)
569 DBG("%s Repeat: Register block %s\n", dir,
570 block_name[block_index]);
571 break;
572 default:
573 LOG("%s: invalid request mode\n",__FUNCTION__);
574 return -EINVAL;
575 }
576
577 retval = cpia2_usb_transfer_cmd(cam,
578 buffer,
579 cmd->req_mode,
580 start, count, cmd->direction);
581#ifdef _CPIA2_DEBUG_
582 if (debugs_on & DEBUG_REG) {
583 int i;
584 for (i = 0; i < cmd->reg_count; i++) {
585 if((cmd->req_mode & 0x0c) == CAMERAACCESS_TYPE_BLOCK)
586 KINFO("%s Block: [0x%02X] = 0x%02X\n",
587 dir, start + i, buffer[i]);
588 if((cmd->req_mode & 0x0c) == CAMERAACCESS_TYPE_RANDOM)
589 KINFO("%s Random: [0x%02X] = 0x%02X\n",
590 dir, cmd->buffer.registers[i].index,
591 cmd->buffer.registers[i].value);
592 }
593 }
594#endif
595
596 return retval;
597};
598
599/*************
600 * Functions to implement camera functionality
601 *************/
602/******************************************************************************
603 *
604 * cpia2_get_version_info
605 *
606 *****************************************************************************/
607static void cpia2_get_version_info(struct camera_data *cam)
608{
609 cpia2_do_command(cam, CPIA2_CMD_GET_VERSION, TRANSFER_READ, 0);
610 cpia2_do_command(cam, CPIA2_CMD_GET_PNP_ID, TRANSFER_READ, 0);
611 cpia2_do_command(cam, CPIA2_CMD_GET_ASIC_TYPE, TRANSFER_READ, 0);
612 cpia2_do_command(cam, CPIA2_CMD_GET_SENSOR, TRANSFER_READ, 0);
613 cpia2_do_command(cam, CPIA2_CMD_GET_VP_DEVICE, TRANSFER_READ, 0);
614}
615
616/******************************************************************************
617 *
618 * cpia2_reset_camera
619 *
620 * Called at least during the open process, sets up initial params.
621 *****************************************************************************/
622int cpia2_reset_camera(struct camera_data *cam)
623{
624 u8 tmp_reg;
625 int retval = 0;
626 int i;
627 struct cpia2_command cmd;
628
629 /***
630 * VC setup
631 ***/
632 retval = configure_sensor(cam,
633 cam->params.roi.width,
634 cam->params.roi.height);
635 if (retval < 0) {
636 ERR("Couldn't configure sensor, error=%d\n", retval);
637 return retval;
638 }
639
640 /* Clear FIFO and route/enable stream block */
641 cmd.req_mode = CAMERAACCESS_TYPE_RANDOM | CAMERAACCESS_VC;
642 cmd.direction = TRANSFER_WRITE;
643 cmd.reg_count = 2;
644 cmd.buffer.registers[0].index = CPIA2_VC_ST_CTRL;
645 cmd.buffer.registers[0].value = CPIA2_VC_ST_CTRL_SRC_VC |
646 CPIA2_VC_ST_CTRL_DST_USB | CPIA2_VC_ST_CTRL_EOF_DETECT;
647 cmd.buffer.registers[1].index = CPIA2_VC_ST_CTRL;
648 cmd.buffer.registers[1].value = CPIA2_VC_ST_CTRL_SRC_VC |
649 CPIA2_VC_ST_CTRL_DST_USB |
650 CPIA2_VC_ST_CTRL_EOF_DETECT | CPIA2_VC_ST_CTRL_FIFO_ENABLE;
651
652 cpia2_send_command(cam, &cmd);
653
654 cpia2_set_high_power(cam);
655
656 if (cam->params.pnp_id.device_type == DEVICE_STV_672) {
657 /* Enable button notification */
658 cmd.req_mode = CAMERAACCESS_TYPE_RANDOM | CAMERAACCESS_SYSTEM;
659 cmd.buffer.registers[0].index = CPIA2_SYSTEM_INT_PACKET_CTRL;
660 cmd.buffer.registers[0].value =
661 CPIA2_SYSTEM_INT_PACKET_CTRL_ENABLE_SW_XX;
662 cmd.reg_count = 1;
663 cpia2_send_command(cam, &cmd);
664 }
665
666 current->state = TASK_INTERRUPTIBLE;
667 schedule_timeout(100 * HZ / 1000); /* wait for 100 msecs */
668
669 if (cam->params.pnp_id.device_type == DEVICE_STV_672)
670 retval = apply_vp_patch(cam);
671
672 /* wait for vp to go to sleep */
673 current->state = TASK_INTERRUPTIBLE;
674 schedule_timeout(100 * HZ / 1000); /* wait for 100 msecs */
675
676 /***
677 * If this is a 676, apply VP5 fixes before we start streaming
678 ***/
679 if (cam->params.pnp_id.device_type == DEVICE_STV_676) {
680 cmd.req_mode = CAMERAACCESS_TYPE_RANDOM | CAMERAACCESS_VP;
681
682 /* The following writes improve the picture */
683 cmd.buffer.registers[0].index = CPIA2_VP5_MYBLACK_LEVEL;
684 cmd.buffer.registers[0].value = 0; /* reduce from the default
685 * rec 601 pedestal of 16 */
686 cmd.buffer.registers[1].index = CPIA2_VP5_MCYRANGE;
687 cmd.buffer.registers[1].value = 0x92; /* increase from 100% to
688 * (256/256 - 31) to fill
689 * available range */
690 cmd.buffer.registers[2].index = CPIA2_VP5_MYCEILING;
691 cmd.buffer.registers[2].value = 0xFF; /* Increase from the
692 * default rec 601 ceiling
693 * of 240 */
694 cmd.buffer.registers[3].index = CPIA2_VP5_MCUVSATURATION;
695 cmd.buffer.registers[3].value = 0xFF; /* Increase from the rec
696 * 601 100% level (128)
697 * to 145-192 */
698 cmd.buffer.registers[4].index = CPIA2_VP5_ANTIFLKRSETUP;
699 cmd.buffer.registers[4].value = 0x80; /* Inhibit the
700 * anti-flicker */
701
702 /* The following 4 writes are a fix to allow QVGA to work at 30 fps */
703 cmd.buffer.registers[5].index = CPIA2_VP_RAM_ADDR_H;
704 cmd.buffer.registers[5].value = 0x01;
705 cmd.buffer.registers[6].index = CPIA2_VP_RAM_ADDR_L;
706 cmd.buffer.registers[6].value = 0xE3;
707 cmd.buffer.registers[7].index = CPIA2_VP_RAM_DATA;
708 cmd.buffer.registers[7].value = 0x02;
709 cmd.buffer.registers[8].index = CPIA2_VP_RAM_DATA;
710 cmd.buffer.registers[8].value = 0xFC;
711
712 cmd.direction = TRANSFER_WRITE;
713 cmd.reg_count = 9;
714
715 cpia2_send_command(cam, &cmd);
716 }
717
718 /* Activate all settings and start the data stream */
719 /* Set user mode */
720 set_default_user_mode(cam);
721
722 /* Give VP time to wake up */
723 current->state = TASK_INTERRUPTIBLE;
724 schedule_timeout(100 * HZ / 1000); /* wait for 100 msecs */
725
726 set_all_properties(cam);
727
728 cpia2_do_command(cam, CPIA2_CMD_GET_USER_MODE, TRANSFER_READ, 0);
729 DBG("After SetAllProperties(cam), user mode is 0x%0X\n",
730 cam->params.vp_params.video_mode);
731
732 /***
733 * Set audio regulator off. This and the code to set the compresison
734 * state are too complex to form a CPIA2_CMD_, and seem to be somewhat
735 * intertwined. This stuff came straight from the windows driver.
736 ***/
737 /* Turn AutoExposure off in VP and enable the serial bridge to the sensor */
738 cpia2_do_command(cam, CPIA2_CMD_GET_VP_SYSTEM_CTRL, TRANSFER_READ, 0);
739 tmp_reg = cam->params.vp_params.system_ctrl;
740 cmd.buffer.registers[0].value = tmp_reg &
741 (tmp_reg & (CPIA2_VP_SYSTEMCTRL_HK_CONTROL ^ 0xFF));
742
743 cpia2_do_command(cam, CPIA2_CMD_GET_DEVICE_CONFIG, TRANSFER_READ, 0);
744 cmd.buffer.registers[1].value = cam->params.vp_params.device_config |
745 CPIA2_VP_DEVICE_CONFIG_SERIAL_BRIDGE;
746 cmd.buffer.registers[0].index = CPIA2_VP_SYSTEMCTRL;
747 cmd.buffer.registers[1].index = CPIA2_VP_DEVICE_CONFIG;
748 cmd.req_mode = CAMERAACCESS_TYPE_RANDOM | CAMERAACCESS_VP;
749 cmd.reg_count = 2;
750 cmd.direction = TRANSFER_WRITE;
751 cmd.start = 0;
752 cpia2_send_command(cam, &cmd);
753
754 /* Set the correct I2C address in the CPiA-2 system register */
755 cpia2_do_command(cam,
756 CPIA2_CMD_SET_SERIAL_ADDR,
757 TRANSFER_WRITE,
758 CPIA2_SYSTEM_VP_SERIAL_ADDR_SENSOR);
759
760 /* Now have sensor access - set bit to turn the audio regulator off */
761 cpia2_do_command(cam,
762 CPIA2_CMD_SET_SENSOR_CR1,
763 TRANSFER_WRITE, CPIA2_SENSOR_CR1_DOWN_AUDIO_REGULATOR);
764
765 /* Set the correct I2C address in the CPiA-2 system register */
766 if (cam->params.pnp_id.device_type == DEVICE_STV_672)
767 cpia2_do_command(cam,
768 CPIA2_CMD_SET_SERIAL_ADDR,
769 TRANSFER_WRITE,
770 CPIA2_SYSTEM_VP_SERIAL_ADDR_VP); // 0x88
771 else
772 cpia2_do_command(cam,
773 CPIA2_CMD_SET_SERIAL_ADDR,
774 TRANSFER_WRITE,
775 CPIA2_SYSTEM_VP_SERIAL_ADDR_676_VP); // 0x8a
776
777 /* increase signal drive strength */
778 if (cam->params.pnp_id.device_type == DEVICE_STV_676)
779 cpia2_do_command(cam,
780 CPIA2_CMD_SET_VP_EXP_MODES,
781 TRANSFER_WRITE,
782 CPIA2_VP_EXPOSURE_MODES_COMPILE_EXP);
783
784 /* Start autoexposure */
785 cpia2_do_command(cam, CPIA2_CMD_GET_DEVICE_CONFIG, TRANSFER_READ, 0);
786 cmd.buffer.registers[0].value = cam->params.vp_params.device_config &
787 (CPIA2_VP_DEVICE_CONFIG_SERIAL_BRIDGE ^ 0xFF);
788
789 cpia2_do_command(cam, CPIA2_CMD_GET_VP_SYSTEM_CTRL, TRANSFER_READ, 0);
790 cmd.buffer.registers[1].value =
791 cam->params.vp_params.system_ctrl | CPIA2_VP_SYSTEMCTRL_HK_CONTROL;
792
793 cmd.buffer.registers[0].index = CPIA2_VP_DEVICE_CONFIG;
794 cmd.buffer.registers[1].index = CPIA2_VP_SYSTEMCTRL;
795 cmd.req_mode = CAMERAACCESS_TYPE_RANDOM | CAMERAACCESS_VP;
796 cmd.reg_count = 2;
797 cmd.direction = TRANSFER_WRITE;
798
799 cpia2_send_command(cam, &cmd);
800
801 /* Set compression state */
802 cpia2_do_command(cam, CPIA2_CMD_GET_VC_CONTROL, TRANSFER_READ, 0);
803 if (cam->params.compression.inhibit_htables) {
804 tmp_reg = cam->params.vc_params.vc_control |
805 CPIA2_VC_VC_CTRL_INHIBIT_H_TABLES;
806 } else {
807 tmp_reg = cam->params.vc_params.vc_control &
808 ~CPIA2_VC_VC_CTRL_INHIBIT_H_TABLES;
809 }
810 cpia2_do_command(cam, CPIA2_CMD_SET_VC_CONTROL, TRANSFER_WRITE,tmp_reg);
811
812 /* Set target size (kb) on vc */
813 cpia2_do_command(cam, CPIA2_CMD_SET_TARGET_KB,
814 TRANSFER_WRITE, cam->params.vc_params.target_kb);
815
816 /* Wiggle VC Reset */
817 /***
818 * First read and wait a bit.
819 ***/
820 for (i = 0; i < 50; i++) {
821 cpia2_do_command(cam, CPIA2_CMD_GET_PW_CONTROL,
822 TRANSFER_READ, 0);
823 }
824
825 tmp_reg = cam->params.vc_params.pw_control;
826 tmp_reg &= ~CPIA2_VC_PW_CTRL_VC_RESET_N;
827
828 cpia2_do_command(cam, CPIA2_CMD_SET_PW_CONTROL, TRANSFER_WRITE,tmp_reg);
829
830 tmp_reg |= CPIA2_VC_PW_CTRL_VC_RESET_N;
831 cpia2_do_command(cam, CPIA2_CMD_SET_PW_CONTROL, TRANSFER_WRITE,tmp_reg);
832
833 cpia2_do_command(cam, CPIA2_CMD_SET_DEF_JPEG_OPT, TRANSFER_WRITE, 0);
834
835 cpia2_do_command(cam, CPIA2_CMD_GET_USER_MODE, TRANSFER_READ, 0);
836 DBG("After VC RESET, user mode is 0x%0X\n",
837 cam->params.vp_params.video_mode);
838
839 return retval;
840}
841
842/******************************************************************************
843 *
844 * cpia2_set_high_power
845 *
846 *****************************************************************************/
847static int cpia2_set_high_power(struct camera_data *cam)
848{
849 int i;
850 for (i = 0; i <= 50; i++) {
851 /* Read system status */
852 cpia2_do_command(cam,CPIA2_CMD_GET_SYSTEM_CTRL,TRANSFER_READ,0);
853
854 /* If there is an error, clear it */
855 if(cam->params.camera_state.system_ctrl &
856 CPIA2_SYSTEM_CONTROL_V2W_ERR)
857 cpia2_do_command(cam, CPIA2_CMD_CLEAR_V2W_ERR,
858 TRANSFER_WRITE, 0);
859
860 /* Try to set high power mode */
861 cpia2_do_command(cam, CPIA2_CMD_SET_SYSTEM_CTRL,
862 TRANSFER_WRITE, 1);
863
864 /* Try to read something in VP to check if everything is awake */
865 cpia2_do_command(cam, CPIA2_CMD_GET_VP_SYSTEM_STATE,
866 TRANSFER_READ, 0);
867 if (cam->params.vp_params.system_state &
868 CPIA2_VP_SYSTEMSTATE_HK_ALIVE) {
869 break;
870 } else if (i == 50) {
871 cam->params.camera_state.power_mode = LO_POWER_MODE;
872 ERR("Camera did not wake up\n");
873 return -EIO;
874 }
875 }
876
877 DBG("System now in high power state\n");
878 cam->params.camera_state.power_mode = HI_POWER_MODE;
879 return 0;
880}
881
882/******************************************************************************
883 *
884 * cpia2_set_low_power
885 *
886 *****************************************************************************/
887int cpia2_set_low_power(struct camera_data *cam)
888{
889 cam->params.camera_state.power_mode = LO_POWER_MODE;
890 cpia2_do_command(cam, CPIA2_CMD_SET_SYSTEM_CTRL, TRANSFER_WRITE, 0);
891 return 0;
892}
893
894/******************************************************************************
895 *
896 * apply_vp_patch
897 *
898 *****************************************************************************/
899static int apply_vp_patch(struct camera_data *cam)
900{
901 int i, j;
902 struct cpia2_command cmd;
903
904 cmd.req_mode = CAMERAACCESS_TYPE_REPEAT | CAMERAACCESS_VP;
905 cmd.direction = TRANSFER_WRITE;
906
907 for (i = 0; i < PATCH_DATA_SIZE; i++) {
908 for (j = 0; j < patch_data[i].count; j++) {
909 cmd.buffer.block_data[j] = patch_data[i].data[j];
910 }
911
912 cmd.start = patch_data[i].reg;
913 cmd.reg_count = patch_data[i].count;
914 cpia2_send_command(cam, &cmd);
915 }
916
917 return 0;
918}
919
920/******************************************************************************
921 *
922 * set_default_user_mode
923 *
924 *****************************************************************************/
925static int set_default_user_mode(struct camera_data *cam)
926{
927 unsigned char user_mode;
928 unsigned char frame_rate;
929 int width = cam->params.roi.width;
930 int height = cam->params.roi.height;
931
932 switch (cam->params.version.sensor_flags) {
933 case CPIA2_VP_SENSOR_FLAGS_404:
934 case CPIA2_VP_SENSOR_FLAGS_407:
935 case CPIA2_VP_SENSOR_FLAGS_409:
936 case CPIA2_VP_SENSOR_FLAGS_410:
937 if ((width > STV_IMAGE_QCIF_COLS)
938 || (height > STV_IMAGE_QCIF_ROWS)) {
939 user_mode = CPIA2_VP_USER_MODE_CIF;
940 } else {
941 user_mode = CPIA2_VP_USER_MODE_QCIFDS;
942 }
943 frame_rate = CPIA2_VP_FRAMERATE_30;
944 break;
945 case CPIA2_VP_SENSOR_FLAGS_500:
946 if ((width > STV_IMAGE_CIF_COLS)
947 || (height > STV_IMAGE_CIF_ROWS)) {
948 user_mode = CPIA2_VP_USER_MODE_VGA;
949 } else {
950 user_mode = CPIA2_VP_USER_MODE_QVGADS;
951 }
952 if (cam->params.pnp_id.device_type == DEVICE_STV_672)
953 frame_rate = CPIA2_VP_FRAMERATE_15;
954 else
955 frame_rate = CPIA2_VP_FRAMERATE_30;
956 break;
957 default:
958 LOG("%s: Invalid sensor flag value 0x%0X\n",__FUNCTION__,
959 cam->params.version.sensor_flags);
960 return -EINVAL;
961 }
962
963 DBG("Sensor flag = 0x%0x, user mode = 0x%0x, frame rate = 0x%X\n",
964 cam->params.version.sensor_flags, user_mode, frame_rate);
965 cpia2_do_command(cam, CPIA2_CMD_SET_USER_MODE, TRANSFER_WRITE,
966 user_mode);
967 if(cam->params.vp_params.frame_rate > 0 &&
968 frame_rate > cam->params.vp_params.frame_rate)
969 frame_rate = cam->params.vp_params.frame_rate;
970
971 cpia2_set_fps(cam, frame_rate);
972
973// if (cam->params.pnp_id.device_type == DEVICE_STV_676)
974// cpia2_do_command(cam,
975// CPIA2_CMD_SET_VP_SYSTEM_CTRL,
976// TRANSFER_WRITE,
977// CPIA2_VP_SYSTEMCTRL_HK_CONTROL |
978// CPIA2_VP_SYSTEMCTRL_POWER_CONTROL);
979
980 return 0;
981}
982
983/******************************************************************************
984 *
985 * cpia2_match_video_size
986 *
987 * return the best match, where 'best' is as always
988 * the largest that is not bigger than what is requested.
989 *****************************************************************************/
990int cpia2_match_video_size(int width, int height)
991{
992 if (width >= STV_IMAGE_VGA_COLS && height >= STV_IMAGE_VGA_ROWS)
993 return VIDEOSIZE_VGA;
994
995 if (width >= STV_IMAGE_CIF_COLS && height >= STV_IMAGE_CIF_ROWS)
996 return VIDEOSIZE_CIF;
997
998 if (width >= STV_IMAGE_QVGA_COLS && height >= STV_IMAGE_QVGA_ROWS)
999 return VIDEOSIZE_QVGA;
1000
1001 if (width >= 288 && height >= 216)
1002 return VIDEOSIZE_288_216;
1003
1004 if (width >= 256 && height >= 192)
1005 return VIDEOSIZE_256_192;
1006
1007 if (width >= 224 && height >= 168)
1008 return VIDEOSIZE_224_168;
1009
1010 if (width >= 192 && height >= 144)
1011 return VIDEOSIZE_192_144;
1012
1013 if (width >= STV_IMAGE_QCIF_COLS && height >= STV_IMAGE_QCIF_ROWS)
1014 return VIDEOSIZE_QCIF;
1015
1016 return -1;
1017}
1018
1019/******************************************************************************
1020 *
1021 * SetVideoSize
1022 *
1023 *****************************************************************************/
1024static int set_vw_size(struct camera_data *cam, int size)
1025{
1026 int retval = 0;
1027
1028 cam->params.vp_params.video_size = size;
1029
1030 switch (size) {
1031 case VIDEOSIZE_VGA:
1032 DBG("Setting size to VGA\n");
1033 cam->params.roi.width = STV_IMAGE_VGA_COLS;
1034 cam->params.roi.height = STV_IMAGE_VGA_ROWS;
1035 cam->vw.width = STV_IMAGE_VGA_COLS;
1036 cam->vw.height = STV_IMAGE_VGA_ROWS;
1037 break;
1038 case VIDEOSIZE_CIF:
1039 DBG("Setting size to CIF\n");
1040 cam->params.roi.width = STV_IMAGE_CIF_COLS;
1041 cam->params.roi.height = STV_IMAGE_CIF_ROWS;
1042 cam->vw.width = STV_IMAGE_CIF_COLS;
1043 cam->vw.height = STV_IMAGE_CIF_ROWS;
1044 break;
1045 case VIDEOSIZE_QVGA:
1046 DBG("Setting size to QVGA\n");
1047 cam->params.roi.width = STV_IMAGE_QVGA_COLS;
1048 cam->params.roi.height = STV_IMAGE_QVGA_ROWS;
1049 cam->vw.width = STV_IMAGE_QVGA_COLS;
1050 cam->vw.height = STV_IMAGE_QVGA_ROWS;
1051 break;
1052 case VIDEOSIZE_288_216:
1053 cam->params.roi.width = 288;
1054 cam->params.roi.height = 216;
1055 cam->vw.width = 288;
1056 cam->vw.height = 216;
1057 break;
1058 case VIDEOSIZE_256_192:
1059 cam->vw.width = 256;
1060 cam->vw.height = 192;
1061 cam->params.roi.width = 256;
1062 cam->params.roi.height = 192;
1063 break;
1064 case VIDEOSIZE_224_168:
1065 cam->vw.width = 224;
1066 cam->vw.height = 168;
1067 cam->params.roi.width = 224;
1068 cam->params.roi.height = 168;
1069 break;
1070 case VIDEOSIZE_192_144:
1071 cam->vw.width = 192;
1072 cam->vw.height = 144;
1073 cam->params.roi.width = 192;
1074 cam->params.roi.height = 144;
1075 break;
1076 case VIDEOSIZE_QCIF:
1077 DBG("Setting size to QCIF\n");
1078 cam->params.roi.width = STV_IMAGE_QCIF_COLS;
1079 cam->params.roi.height = STV_IMAGE_QCIF_ROWS;
1080 cam->vw.width = STV_IMAGE_QCIF_COLS;
1081 cam->vw.height = STV_IMAGE_QCIF_ROWS;
1082 break;
1083 default:
1084 retval = -EINVAL;
1085 }
1086 return retval;
1087}
1088
1089/******************************************************************************
1090 *
1091 * configure_sensor
1092 *
1093 *****************************************************************************/
1094static int configure_sensor(struct camera_data *cam,
1095 int req_width, int req_height)
1096{
1097 int retval;
1098
1099 switch (cam->params.version.sensor_flags) {
1100 case CPIA2_VP_SENSOR_FLAGS_404:
1101 case CPIA2_VP_SENSOR_FLAGS_407:
1102 case CPIA2_VP_SENSOR_FLAGS_409:
1103 case CPIA2_VP_SENSOR_FLAGS_410:
1104 retval = config_sensor_410(cam, req_width, req_height);
1105 break;
1106 case CPIA2_VP_SENSOR_FLAGS_500:
1107 retval = config_sensor_500(cam, req_width, req_height);
1108 break;
1109 default:
1110 return -EINVAL;
1111 }
1112
1113 return retval;
1114}
1115
1116/******************************************************************************
1117 *
1118 * config_sensor_410
1119 *
1120 *****************************************************************************/
1121static int config_sensor_410(struct camera_data *cam,
1122 int req_width, int req_height)
1123{
1124 struct cpia2_command cmd;
1125 int i = 0;
1126 int image_size;
1127 int image_type;
1128 int width = req_width;
1129 int height = req_height;
1130
1131 /***
1132 * Make sure size doesn't exceed CIF.
1133 ***/
1134 if (width > STV_IMAGE_CIF_COLS)
1135 width = STV_IMAGE_CIF_COLS;
1136 if (height > STV_IMAGE_CIF_ROWS)
1137 height = STV_IMAGE_CIF_ROWS;
1138
1139 image_size = cpia2_match_video_size(width, height);
1140
1141 DBG("Config 410: width = %d, height = %d\n", width, height);
1142 DBG("Image size returned is %d\n", image_size);
1143 if (image_size >= 0) {
1144 set_vw_size(cam, image_size);
1145 width = cam->params.roi.width;
1146 height = cam->params.roi.height;
1147
1148 DBG("After set_vw_size(), width = %d, height = %d\n",
1149 width, height);
1150 if (width <= 176 && height <= 144) {
1151 DBG("image type = VIDEOSIZE_QCIF\n");
1152 image_type = VIDEOSIZE_QCIF;
1153 }
1154 else if (width <= 320 && height <= 240) {
1155 DBG("image type = VIDEOSIZE_QVGA\n");
1156 image_type = VIDEOSIZE_QVGA;
1157 }
1158 else {
1159 DBG("image type = VIDEOSIZE_CIF\n");
1160 image_type = VIDEOSIZE_CIF;
1161 }
1162 } else {
1163 ERR("ConfigSensor410 failed\n");
1164 return -EINVAL;
1165 }
1166
1167 cmd.req_mode = CAMERAACCESS_TYPE_RANDOM | CAMERAACCESS_VC;
1168 cmd.direction = TRANSFER_WRITE;
1169
1170 /* VC Format */
1171 cmd.buffer.registers[i].index = CPIA2_VC_VC_FORMAT;
1172 if (image_type == VIDEOSIZE_CIF) {
1173 cmd.buffer.registers[i++].value =
1174 (u8) (CPIA2_VC_VC_FORMAT_UFIRST |
1175 CPIA2_VC_VC_FORMAT_SHORTLINE);
1176 } else {
1177 cmd.buffer.registers[i++].value =
1178 (u8) CPIA2_VC_VC_FORMAT_UFIRST;
1179 }
1180
1181 /* VC Clocks */
1182 cmd.buffer.registers[i].index = CPIA2_VC_VC_CLOCKS;
1183 if (image_type == VIDEOSIZE_QCIF) {
1184 if (cam->params.pnp_id.device_type == DEVICE_STV_672) {
1185 cmd.buffer.registers[i++].value=
1186 (u8)(CPIA2_VC_VC_672_CLOCKS_CIF_DIV_BY_3 |
1187 CPIA2_VC_VC_672_CLOCKS_SCALING |
1188 CPIA2_VC_VC_CLOCKS_LOGDIV2);
1189 DBG("VC_Clocks (0xc4) should be B\n");
1190 }
1191 else {
1192 cmd.buffer.registers[i++].value=
1193 (u8)(CPIA2_VC_VC_676_CLOCKS_CIF_DIV_BY_3 |
1194 CPIA2_VC_VC_CLOCKS_LOGDIV2);
1195 }
1196 } else {
1197 if (cam->params.pnp_id.device_type == DEVICE_STV_672) {
1198 cmd.buffer.registers[i++].value =
1199 (u8) (CPIA2_VC_VC_672_CLOCKS_CIF_DIV_BY_3 |
1200 CPIA2_VC_VC_CLOCKS_LOGDIV0);
1201 }
1202 else {
1203 cmd.buffer.registers[i++].value =
1204 (u8) (CPIA2_VC_VC_676_CLOCKS_CIF_DIV_BY_3 |
1205 CPIA2_VC_VC_676_CLOCKS_SCALING |
1206 CPIA2_VC_VC_CLOCKS_LOGDIV0);
1207 }
1208 }
1209 DBG("VC_Clocks (0xc4) = 0x%0X\n", cmd.buffer.registers[i-1].value);
1210
1211 /* Input reqWidth from VC */
1212 cmd.buffer.registers[i].index = CPIA2_VC_VC_IHSIZE_LO;
1213 if (image_type == VIDEOSIZE_QCIF)
1214 cmd.buffer.registers[i++].value =
1215 (u8) (STV_IMAGE_QCIF_COLS / 4);
1216 else
1217 cmd.buffer.registers[i++].value =
1218 (u8) (STV_IMAGE_CIF_COLS / 4);
1219
1220 /* Timings */
1221 cmd.buffer.registers[i].index = CPIA2_VC_VC_XLIM_HI;
1222 if (image_type == VIDEOSIZE_QCIF)
1223 cmd.buffer.registers[i++].value = (u8) 0;
1224 else
1225 cmd.buffer.registers[i++].value = (u8) 1;
1226
1227 cmd.buffer.registers[i].index = CPIA2_VC_VC_XLIM_LO;
1228 if (image_type == VIDEOSIZE_QCIF)
1229 cmd.buffer.registers[i++].value = (u8) 208;
1230 else
1231 cmd.buffer.registers[i++].value = (u8) 160;
1232
1233 cmd.buffer.registers[i].index = CPIA2_VC_VC_YLIM_HI;
1234 if (image_type == VIDEOSIZE_QCIF)
1235 cmd.buffer.registers[i++].value = (u8) 0;
1236 else
1237 cmd.buffer.registers[i++].value = (u8) 1;
1238
1239 cmd.buffer.registers[i].index = CPIA2_VC_VC_YLIM_LO;
1240 if (image_type == VIDEOSIZE_QCIF)
1241 cmd.buffer.registers[i++].value = (u8) 160;
1242 else
1243 cmd.buffer.registers[i++].value = (u8) 64;
1244
1245 /* Output Image Size */
1246 cmd.buffer.registers[i].index = CPIA2_VC_VC_OHSIZE;
1247 cmd.buffer.registers[i++].value = cam->params.roi.width / 4;
1248
1249 cmd.buffer.registers[i].index = CPIA2_VC_VC_OVSIZE;
1250 cmd.buffer.registers[i++].value = cam->params.roi.height / 4;
1251
1252 /* Cropping */
1253 cmd.buffer.registers[i].index = CPIA2_VC_VC_HCROP;
1254 if (image_type == VIDEOSIZE_QCIF)
1255 cmd.buffer.registers[i++].value =
1256 (u8) (((STV_IMAGE_QCIF_COLS / 4) - (width / 4)) / 2);
1257 else
1258 cmd.buffer.registers[i++].value =
1259 (u8) (((STV_IMAGE_CIF_COLS / 4) - (width / 4)) / 2);
1260
1261 cmd.buffer.registers[i].index = CPIA2_VC_VC_VCROP;
1262 if (image_type == VIDEOSIZE_QCIF)
1263 cmd.buffer.registers[i++].value =
1264 (u8) (((STV_IMAGE_QCIF_ROWS / 4) - (height / 4)) / 2);
1265 else
1266 cmd.buffer.registers[i++].value =
1267 (u8) (((STV_IMAGE_CIF_ROWS / 4) - (height / 4)) / 2);
1268
1269 /* Scaling registers (defaults) */
1270 cmd.buffer.registers[i].index = CPIA2_VC_VC_HPHASE;
1271 cmd.buffer.registers[i++].value = (u8) 0;
1272
1273 cmd.buffer.registers[i].index = CPIA2_VC_VC_VPHASE;
1274 cmd.buffer.registers[i++].value = (u8) 0;
1275
1276 cmd.buffer.registers[i].index = CPIA2_VC_VC_HISPAN;
1277 cmd.buffer.registers[i++].value = (u8) 31;
1278
1279 cmd.buffer.registers[i].index = CPIA2_VC_VC_VISPAN;
1280 cmd.buffer.registers[i++].value = (u8) 31;
1281
1282 cmd.buffer.registers[i].index = CPIA2_VC_VC_HICROP;
1283 cmd.buffer.registers[i++].value = (u8) 0;
1284
1285 cmd.buffer.registers[i].index = CPIA2_VC_VC_VICROP;
1286 cmd.buffer.registers[i++].value = (u8) 0;
1287
1288 cmd.buffer.registers[i].index = CPIA2_VC_VC_HFRACT;
1289 cmd.buffer.registers[i++].value = (u8) 0x81; /* = 8/1 = 8 (HIBYTE/LOBYTE) */
1290
1291 cmd.buffer.registers[i].index = CPIA2_VC_VC_VFRACT;
1292 cmd.buffer.registers[i++].value = (u8) 0x81; /* = 8/1 = 8 (HIBYTE/LOBYTE) */
1293
1294 cmd.reg_count = i;
1295
1296 cpia2_send_command(cam, &cmd);
1297
1298 return i;
1299}
1300
1301
1302/******************************************************************************
1303 *
1304 * config_sensor_500(cam)
1305 *
1306 *****************************************************************************/
1307static int config_sensor_500(struct camera_data *cam,
1308 int req_width, int req_height)
1309{
1310 struct cpia2_command cmd;
1311 int i = 0;
1312 int image_size = VIDEOSIZE_CIF;
1313 int image_type = VIDEOSIZE_VGA;
1314 int width = req_width;
1315 int height = req_height;
1316 unsigned int device = cam->params.pnp_id.device_type;
1317
1318 image_size = cpia2_match_video_size(width, height);
1319
1320 if (width > STV_IMAGE_CIF_COLS || height > STV_IMAGE_CIF_ROWS)
1321 image_type = VIDEOSIZE_VGA;
1322 else if (width > STV_IMAGE_QVGA_COLS || height > STV_IMAGE_QVGA_ROWS)
1323 image_type = VIDEOSIZE_CIF;
1324 else if (width > STV_IMAGE_QCIF_COLS || height > STV_IMAGE_QCIF_ROWS)
1325 image_type = VIDEOSIZE_QVGA;
1326 else
1327 image_type = VIDEOSIZE_QCIF;
1328
1329 if (image_size >= 0) {
1330 set_vw_size(cam, image_size);
1331 width = cam->params.roi.width;
1332 height = cam->params.roi.height;
1333 } else {
1334 ERR("ConfigSensor500 failed\n");
1335 return -EINVAL;
1336 }
1337
1338 DBG("image_size = %d, width = %d, height = %d, type = %d\n",
1339 image_size, width, height, image_type);
1340
1341 cmd.req_mode = CAMERAACCESS_TYPE_RANDOM | CAMERAACCESS_VC;
1342 cmd.direction = TRANSFER_WRITE;
1343 i = 0;
1344
1345 /* VC Format */
1346 cmd.buffer.registers[i].index = CPIA2_VC_VC_FORMAT;
1347 cmd.buffer.registers[i].value = (u8) CPIA2_VC_VC_FORMAT_UFIRST;
1348 if (image_type == VIDEOSIZE_QCIF)
1349 cmd.buffer.registers[i].value |= (u8) CPIA2_VC_VC_FORMAT_DECIMATING;
1350 i++;
1351
1352 /* VC Clocks */
1353 cmd.buffer.registers[i].index = CPIA2_VC_VC_CLOCKS;
1354 if (device == DEVICE_STV_672) {
1355 if (image_type == VIDEOSIZE_VGA)
1356 cmd.buffer.registers[i].value =
1357 (u8)CPIA2_VC_VC_CLOCKS_LOGDIV1;
1358 else
1359 cmd.buffer.registers[i].value =
1360 (u8)(CPIA2_VC_VC_672_CLOCKS_SCALING |
1361 CPIA2_VC_VC_CLOCKS_LOGDIV3);
1362 } else {
1363 if (image_type == VIDEOSIZE_VGA)
1364 cmd.buffer.registers[i].value =
1365 (u8)CPIA2_VC_VC_CLOCKS_LOGDIV0;
1366 else
1367 cmd.buffer.registers[i].value =
1368 (u8)(CPIA2_VC_VC_676_CLOCKS_SCALING |
1369 CPIA2_VC_VC_CLOCKS_LOGDIV2);
1370 }
1371 i++;
1372
1373 DBG("VC_CLOCKS = 0x%X\n", cmd.buffer.registers[i-1].value);
1374
1375 /* Input width from VP */
1376 cmd.buffer.registers[i].index = CPIA2_VC_VC_IHSIZE_LO;
1377 if (image_type == VIDEOSIZE_VGA)
1378 cmd.buffer.registers[i].value =
1379 (u8) (STV_IMAGE_VGA_COLS / 4);
1380 else
1381 cmd.buffer.registers[i].value =
1382 (u8) (STV_IMAGE_QVGA_COLS / 4);
1383 i++;
1384 DBG("Input width = %d\n", cmd.buffer.registers[i-1].value);
1385
1386 /* Timings */
1387 cmd.buffer.registers[i].index = CPIA2_VC_VC_XLIM_HI;
1388 if (image_type == VIDEOSIZE_VGA)
1389 cmd.buffer.registers[i++].value = (u8) 2;
1390 else
1391 cmd.buffer.registers[i++].value = (u8) 1;
1392
1393 cmd.buffer.registers[i].index = CPIA2_VC_VC_XLIM_LO;
1394 if (image_type == VIDEOSIZE_VGA)
1395 cmd.buffer.registers[i++].value = (u8) 250;
1396 else if (image_type == VIDEOSIZE_QVGA)
1397 cmd.buffer.registers[i++].value = (u8) 125;
1398 else
1399 cmd.buffer.registers[i++].value = (u8) 160;
1400
1401 cmd.buffer.registers[i].index = CPIA2_VC_VC_YLIM_HI;
1402 if (image_type == VIDEOSIZE_VGA)
1403 cmd.buffer.registers[i++].value = (u8) 2;
1404 else
1405 cmd.buffer.registers[i++].value = (u8) 1;
1406
1407 cmd.buffer.registers[i].index = CPIA2_VC_VC_YLIM_LO;
1408 if (image_type == VIDEOSIZE_VGA)
1409 cmd.buffer.registers[i++].value = (u8) 12;
1410 else if (image_type == VIDEOSIZE_QVGA)
1411 cmd.buffer.registers[i++].value = (u8) 64;
1412 else
1413 cmd.buffer.registers[i++].value = (u8) 6;
1414
1415 /* Output Image Size */
1416 cmd.buffer.registers[i].index = CPIA2_VC_VC_OHSIZE;
1417 if (image_type == VIDEOSIZE_QCIF)
1418 cmd.buffer.registers[i++].value = STV_IMAGE_CIF_COLS / 4;
1419 else
1420 cmd.buffer.registers[i++].value = width / 4;
1421
1422 cmd.buffer.registers[i].index = CPIA2_VC_VC_OVSIZE;
1423 if (image_type == VIDEOSIZE_QCIF)
1424 cmd.buffer.registers[i++].value = STV_IMAGE_CIF_ROWS / 4;
1425 else
1426 cmd.buffer.registers[i++].value = height / 4;
1427
1428 /* Cropping */
1429 cmd.buffer.registers[i].index = CPIA2_VC_VC_HCROP;
1430 if (image_type == VIDEOSIZE_VGA)
1431 cmd.buffer.registers[i++].value =
1432 (u8) (((STV_IMAGE_VGA_COLS / 4) - (width / 4)) / 2);
1433 else if (image_type == VIDEOSIZE_QVGA)
1434 cmd.buffer.registers[i++].value =
1435 (u8) (((STV_IMAGE_QVGA_COLS / 4) - (width / 4)) / 2);
1436 else if (image_type == VIDEOSIZE_CIF)
1437 cmd.buffer.registers[i++].value =
1438 (u8) (((STV_IMAGE_CIF_COLS / 4) - (width / 4)) / 2);
1439 else /*if (image_type == VIDEOSIZE_QCIF)*/
1440 cmd.buffer.registers[i++].value =
1441 (u8) (((STV_IMAGE_QCIF_COLS / 4) - (width / 4)) / 2);
1442
1443 cmd.buffer.registers[i].index = CPIA2_VC_VC_VCROP;
1444 if (image_type == VIDEOSIZE_VGA)
1445 cmd.buffer.registers[i++].value =
1446 (u8) (((STV_IMAGE_VGA_ROWS / 4) - (height / 4)) / 2);
1447 else if (image_type == VIDEOSIZE_QVGA)
1448 cmd.buffer.registers[i++].value =
1449 (u8) (((STV_IMAGE_QVGA_ROWS / 4) - (height / 4)) / 2);
1450 else if (image_type == VIDEOSIZE_CIF)
1451 cmd.buffer.registers[i++].value =
1452 (u8) (((STV_IMAGE_CIF_ROWS / 4) - (height / 4)) / 2);
1453 else /*if (image_type == VIDEOSIZE_QCIF)*/
1454 cmd.buffer.registers[i++].value =
1455 (u8) (((STV_IMAGE_QCIF_ROWS / 4) - (height / 4)) / 2);
1456
1457 /* Scaling registers (defaults) */
1458 cmd.buffer.registers[i].index = CPIA2_VC_VC_HPHASE;
1459 if (image_type == VIDEOSIZE_CIF || image_type == VIDEOSIZE_QCIF)
1460 cmd.buffer.registers[i++].value = (u8) 36;
1461 else
1462 cmd.buffer.registers[i++].value = (u8) 0;
1463
1464 cmd.buffer.registers[i].index = CPIA2_VC_VC_VPHASE;
1465 if (image_type == VIDEOSIZE_CIF || image_type == VIDEOSIZE_QCIF)
1466 cmd.buffer.registers[i++].value = (u8) 32;
1467 else
1468 cmd.buffer.registers[i++].value = (u8) 0;
1469
1470 cmd.buffer.registers[i].index = CPIA2_VC_VC_HISPAN;
1471 if (image_type == VIDEOSIZE_CIF || image_type == VIDEOSIZE_QCIF)
1472 cmd.buffer.registers[i++].value = (u8) 26;
1473 else
1474 cmd.buffer.registers[i++].value = (u8) 31;
1475
1476 cmd.buffer.registers[i].index = CPIA2_VC_VC_VISPAN;
1477 if (image_type == VIDEOSIZE_CIF || image_type == VIDEOSIZE_QCIF)
1478 cmd.buffer.registers[i++].value = (u8) 21;
1479 else
1480 cmd.buffer.registers[i++].value = (u8) 31;
1481
1482 cmd.buffer.registers[i].index = CPIA2_VC_VC_HICROP;
1483 cmd.buffer.registers[i++].value = (u8) 0;
1484
1485 cmd.buffer.registers[i].index = CPIA2_VC_VC_VICROP;
1486 cmd.buffer.registers[i++].value = (u8) 0;
1487
1488 cmd.buffer.registers[i].index = CPIA2_VC_VC_HFRACT;
1489 if (image_type == VIDEOSIZE_CIF || image_type == VIDEOSIZE_QCIF)
1490 cmd.buffer.registers[i++].value = (u8) 0x2B; /* 2/11 */
1491 else
1492 cmd.buffer.registers[i++].value = (u8) 0x81; /* 8/1 */
1493
1494 cmd.buffer.registers[i].index = CPIA2_VC_VC_VFRACT;
1495 if (image_type == VIDEOSIZE_CIF || image_type == VIDEOSIZE_QCIF)
1496 cmd.buffer.registers[i++].value = (u8) 0x13; /* 1/3 */
1497 else
1498 cmd.buffer.registers[i++].value = (u8) 0x81; /* 8/1 */
1499
1500 cmd.reg_count = i;
1501
1502 cpia2_send_command(cam, &cmd);
1503
1504 return i;
1505}
1506
1507
1508/******************************************************************************
1509 *
1510 * setallproperties
1511 *
1512 * This sets all user changeable properties to the values in cam->params.
1513 *****************************************************************************/
1514int set_all_properties(struct camera_data *cam)
1515{
1516 /**
1517 * Don't set target_kb here, it will be set later.
1518 * framerate and user_mode were already set (set_default_user_mode).
1519 **/
1520
1521 cpia2_set_color_params(cam);
1522
1523 cpia2_usb_change_streaming_alternate(cam,
1524 cam->params.camera_state.stream_mode);
1525
1526 cpia2_do_command(cam, CPIA2_CMD_SET_USER_EFFECTS, TRANSFER_WRITE,
1527 cam->params.vp_params.user_effects);
1528
1529 cpia2_set_flicker_mode(cam,
1530 cam->params.flicker_control.flicker_mode_req);
1531
1532 cpia2_do_command(cam,
1533 CPIA2_CMD_SET_VC_MP_GPIO_DIRECTION,
1534 TRANSFER_WRITE, cam->params.vp_params.gpio_direction);
1535 cpia2_do_command(cam, CPIA2_CMD_SET_VC_MP_GPIO_DATA, TRANSFER_WRITE,
1536 cam->params.vp_params.gpio_data);
1537
1538 wake_system(cam);
1539
1540 set_lowlight_boost(cam);
1541
1542 return 0;
1543}
1544
1545/******************************************************************************
1546 *
1547 * cpia2_save_camera_state
1548 *
1549 *****************************************************************************/
1550void cpia2_save_camera_state(struct camera_data *cam)
1551{
1552 get_color_params(cam);
1553 cpia2_do_command(cam, CPIA2_CMD_GET_USER_EFFECTS, TRANSFER_READ, 0);
1554 cpia2_do_command(cam, CPIA2_CMD_GET_VC_MP_GPIO_DIRECTION, TRANSFER_READ,
1555 0);
1556 cpia2_do_command(cam, CPIA2_CMD_GET_VC_MP_GPIO_DATA, TRANSFER_READ, 0);
1557 /* Don't get framerate or target_kb. Trust the values we already have */
1558}
1559
1560/******************************************************************************
1561 *
1562 * get_color_params
1563 *
1564 *****************************************************************************/
1565void get_color_params(struct camera_data *cam)
1566{
1567 cpia2_do_command(cam, CPIA2_CMD_GET_VP_BRIGHTNESS, TRANSFER_READ, 0);
1568 cpia2_do_command(cam, CPIA2_CMD_GET_VP_SATURATION, TRANSFER_READ, 0);
1569 cpia2_do_command(cam, CPIA2_CMD_GET_CONTRAST, TRANSFER_READ, 0);
1570}
1571
1572/******************************************************************************
1573 *
1574 * cpia2_set_color_params
1575 *
1576 *****************************************************************************/
1577void cpia2_set_color_params(struct camera_data *cam)
1578{
1579 DBG("Setting color params\n");
1580 cpia2_set_brightness(cam, cam->params.color_params.brightness);
1581 cpia2_set_contrast(cam, cam->params.color_params.contrast);
1582 cpia2_set_saturation(cam, cam->params.color_params.saturation);
1583}
1584
1585/******************************************************************************
1586 *
1587 * cpia2_set_flicker_mode
1588 *
1589 *****************************************************************************/
1590int cpia2_set_flicker_mode(struct camera_data *cam, int mode)
1591{
1592 unsigned char cam_reg;
1593 int err = 0;
1594
1595 if(cam->params.pnp_id.device_type != DEVICE_STV_672)
1596 return -EINVAL;
1597
1598 /* Set the appropriate bits in FLICKER_MODES, preserving the rest */
1599 if((err = cpia2_do_command(cam, CPIA2_CMD_GET_FLICKER_MODES,
1600 TRANSFER_READ, 0)))
1601 return err;
1602 cam_reg = cam->params.flicker_control.cam_register;
1603
1604 switch(mode) {
1605 case NEVER_FLICKER:
1606 cam_reg |= CPIA2_VP_FLICKER_MODES_NEVER_FLICKER;
1607 cam_reg &= ~CPIA2_VP_FLICKER_MODES_50HZ;
1608 break;
1609 case FLICKER_60:
1610 cam_reg &= ~CPIA2_VP_FLICKER_MODES_NEVER_FLICKER;
1611 cam_reg &= ~CPIA2_VP_FLICKER_MODES_50HZ;
1612 break;
1613 case FLICKER_50:
1614 cam_reg &= ~CPIA2_VP_FLICKER_MODES_NEVER_FLICKER;
1615 cam_reg |= CPIA2_VP_FLICKER_MODES_50HZ;
1616 break;
1617 default:
1618 return -EINVAL;
1619 }
1620
1621 if((err = cpia2_do_command(cam, CPIA2_CMD_SET_FLICKER_MODES,
1622 TRANSFER_WRITE, cam_reg)))
1623 return err;
1624
1625 /* Set the appropriate bits in EXP_MODES, preserving the rest */
1626 if((err = cpia2_do_command(cam, CPIA2_CMD_GET_VP_EXP_MODES,
1627 TRANSFER_READ, 0)))
1628 return err;
1629 cam_reg = cam->params.vp_params.exposure_modes;
1630
1631 if (mode == NEVER_FLICKER) {
1632 cam_reg |= CPIA2_VP_EXPOSURE_MODES_INHIBIT_FLICKER;
1633 } else {
1634 cam_reg &= ~CPIA2_VP_EXPOSURE_MODES_INHIBIT_FLICKER;
1635 }
1636
1637 if((err = cpia2_do_command(cam, CPIA2_CMD_SET_VP_EXP_MODES,
1638 TRANSFER_WRITE, cam_reg)))
1639 return err;
1640
1641 if((err = cpia2_do_command(cam, CPIA2_CMD_REHASH_VP4,
1642 TRANSFER_WRITE, 1)))
1643 return err;
1644
1645 switch(mode) {
1646 case NEVER_FLICKER:
1647 cam->params.flicker_control.flicker_mode_req = mode;
1648 break;
1649 case FLICKER_60:
1650 cam->params.flicker_control.flicker_mode_req = mode;
1651 cam->params.flicker_control.mains_frequency = 60;
1652 break;
1653 case FLICKER_50:
1654 cam->params.flicker_control.flicker_mode_req = mode;
1655 cam->params.flicker_control.mains_frequency = 50;
1656 break;
1657 default:
1658 err = -EINVAL;
1659 }
1660
1661 return err;
1662}
1663
1664/******************************************************************************
1665 *
1666 * cpia2_set_property_flip
1667 *
1668 *****************************************************************************/
1669void cpia2_set_property_flip(struct camera_data *cam, int prop_val)
1670{
1671 unsigned char cam_reg;
1672
1673 cpia2_do_command(cam, CPIA2_CMD_GET_USER_EFFECTS, TRANSFER_READ, 0);
1674 cam_reg = cam->params.vp_params.user_effects;
1675
1676 if (prop_val)
1677 {
1678 cam_reg |= CPIA2_VP_USER_EFFECTS_FLIP;
1679 }
1680 else
1681 {
1682 cam_reg &= ~CPIA2_VP_USER_EFFECTS_FLIP;
1683 }
1684 cpia2_do_command(cam, CPIA2_CMD_SET_USER_EFFECTS, TRANSFER_WRITE,
1685 cam_reg);
1686}
1687
1688/******************************************************************************
1689 *
1690 * cpia2_set_property_mirror
1691 *
1692 *****************************************************************************/
1693void cpia2_set_property_mirror(struct camera_data *cam, int prop_val)
1694{
1695 unsigned char cam_reg;
1696
1697 cpia2_do_command(cam, CPIA2_CMD_GET_USER_EFFECTS, TRANSFER_READ, 0);
1698 cam_reg = cam->params.vp_params.user_effects;
1699
1700 if (prop_val)
1701 {
1702 cam_reg |= CPIA2_VP_USER_EFFECTS_MIRROR;
1703 }
1704 else
1705 {
1706 cam_reg &= ~CPIA2_VP_USER_EFFECTS_MIRROR;
1707 }
1708 cpia2_do_command(cam, CPIA2_CMD_SET_USER_EFFECTS, TRANSFER_WRITE,
1709 cam_reg);
1710}
1711
1712/******************************************************************************
1713 *
1714 * set_target_kb
1715 *
1716 * The new Target KB is set in cam->params.vc_params.target_kb and
1717 * activates on reset.
1718 *****************************************************************************/
1719
1720int cpia2_set_target_kb(struct camera_data *cam, unsigned char value)
1721{
1722 DBG("Requested target_kb = %d\n", value);
1723 if (value != cam->params.vc_params.target_kb) {
1724
1725 cpia2_usb_stream_pause(cam);
1726
1727 /* reset camera for new target_kb */
1728 cam->params.vc_params.target_kb = value;
1729 cpia2_reset_camera(cam);
1730
1731 cpia2_usb_stream_resume(cam);
1732 }
1733
1734 return 0;
1735}
1736
1737/******************************************************************************
1738 *
1739 * cpia2_set_gpio
1740 *
1741 *****************************************************************************/
1742int cpia2_set_gpio(struct camera_data *cam, unsigned char setting)
1743{
1744 int ret;
1745
1746 /* Set the microport direction (register 0x90, should be defined
1747 * already) to 1 (user output), and set the microport data (0x91) to
1748 * the value in the ioctl argument.
1749 */
1750
1751 ret = cpia2_do_command(cam,
1752 CPIA2_CMD_SET_VC_MP_GPIO_DIRECTION,
1753 CPIA2_VC_MP_DIR_OUTPUT,
1754 255);
1755 if (ret < 0)
1756 return ret;
1757 cam->params.vp_params.gpio_direction = 255;
1758
1759 ret = cpia2_do_command(cam,
1760 CPIA2_CMD_SET_VC_MP_GPIO_DATA,
1761 CPIA2_VC_MP_DIR_OUTPUT,
1762 setting);
1763 if (ret < 0)
1764 return ret;
1765 cam->params.vp_params.gpio_data = setting;
1766
1767 return 0;
1768}
1769
1770/******************************************************************************
1771 *
1772 * cpia2_set_fps
1773 *
1774 *****************************************************************************/
1775int cpia2_set_fps(struct camera_data *cam, int framerate)
1776{
1777 int retval;
1778
1779 switch(framerate) {
1780 case CPIA2_VP_FRAMERATE_30:
1781 case CPIA2_VP_FRAMERATE_25:
1782 if(cam->params.pnp_id.device_type == DEVICE_STV_672 &&
1783 cam->params.version.sensor_flags ==
1784 CPIA2_VP_SENSOR_FLAGS_500) {
1785 return -EINVAL;
1786 }
1787 /* Fall through */
1788 case CPIA2_VP_FRAMERATE_15:
1789 case CPIA2_VP_FRAMERATE_12_5:
1790 case CPIA2_VP_FRAMERATE_7_5:
1791 case CPIA2_VP_FRAMERATE_6_25:
1792 break;
1793 default:
1794 return -EINVAL;
1795 }
1796
1797 if (cam->params.pnp_id.device_type == DEVICE_STV_672 &&
1798 framerate == CPIA2_VP_FRAMERATE_15)
1799 framerate = 0; /* Work around bug in VP4 */
1800
1801 retval = cpia2_do_command(cam,
1802 CPIA2_CMD_FRAMERATE_REQ,
1803 TRANSFER_WRITE,
1804 framerate);
1805
1806 if(retval == 0)
1807 cam->params.vp_params.frame_rate = framerate;
1808
1809 return retval;
1810}
1811
1812/******************************************************************************
1813 *
1814 * cpia2_set_brightness
1815 *
1816 *****************************************************************************/
1817void cpia2_set_brightness(struct camera_data *cam, unsigned char value)
1818{
1819 /***
1820 * Don't let the register be set to zero - bug in VP4 - flash of full
1821 * brightness
1822 ***/
1823 if (cam->params.pnp_id.device_type == DEVICE_STV_672 && value == 0)
1824 value++;
1825 DBG("Setting brightness to %d (0x%0x)\n", value, value);
1826 cpia2_do_command(cam,CPIA2_CMD_SET_VP_BRIGHTNESS, TRANSFER_WRITE,value);
1827}
1828
1829/******************************************************************************
1830 *
1831 * cpia2_set_contrast
1832 *
1833 *****************************************************************************/
1834void cpia2_set_contrast(struct camera_data *cam, unsigned char value)
1835{
1836 DBG("Setting contrast to %d (0x%0x)\n", value, value);
1837 cam->params.color_params.contrast = value;
1838 cpia2_do_command(cam, CPIA2_CMD_SET_CONTRAST, TRANSFER_WRITE, value);
1839}
1840
1841/******************************************************************************
1842 *
1843 * cpia2_set_saturation
1844 *
1845 *****************************************************************************/
1846void cpia2_set_saturation(struct camera_data *cam, unsigned char value)
1847{
1848 DBG("Setting saturation to %d (0x%0x)\n", value, value);
1849 cam->params.color_params.saturation = value;
1850 cpia2_do_command(cam,CPIA2_CMD_SET_VP_SATURATION, TRANSFER_WRITE,value);
1851}
1852
1853/******************************************************************************
1854 *
1855 * wake_system
1856 *
1857 *****************************************************************************/
1858void wake_system(struct camera_data *cam)
1859{
1860 cpia2_do_command(cam, CPIA2_CMD_SET_WAKEUP, TRANSFER_WRITE, 0);
1861}
1862
1863/******************************************************************************
1864 *
1865 * set_lowlight_boost
1866 *
1867 * Valid for STV500 sensor only
1868 *****************************************************************************/
1869void set_lowlight_boost(struct camera_data *cam)
1870{
1871 struct cpia2_command cmd;
1872
1873 if (cam->params.pnp_id.device_type != DEVICE_STV_672 ||
1874 cam->params.version.sensor_flags != CPIA2_VP_SENSOR_FLAGS_500)
1875 return;
1876
1877 cmd.direction = TRANSFER_WRITE;
1878 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
1879 cmd.reg_count = 3;
1880 cmd.start = CPIA2_VP_RAM_ADDR_H;
1881
1882 cmd.buffer.block_data[0] = 0; /* High byte of address to write to */
1883 cmd.buffer.block_data[1] = 0x59; /* Low byte of address to write to */
1884 cmd.buffer.block_data[2] = 0; /* High byte of data to write */
1885
1886 cpia2_send_command(cam, &cmd);
1887
1888 if (cam->params.vp_params.lowlight_boost) {
1889 cmd.buffer.block_data[0] = 0x02; /* Low byte data to write */
1890 } else {
1891 cmd.buffer.block_data[0] = 0x06;
1892 }
1893 cmd.start = CPIA2_VP_RAM_DATA;
1894 cmd.reg_count = 1;
1895 cpia2_send_command(cam, &cmd);
1896
1897 /* Rehash the VP4 values */
1898 cpia2_do_command(cam, CPIA2_CMD_REHASH_VP4, TRANSFER_WRITE, 1);
1899}
1900
1901/******************************************************************************
1902 *
1903 * cpia2_set_format
1904 *
1905 * Assumes that new size is already set in param struct.
1906 *****************************************************************************/
1907void cpia2_set_format(struct camera_data *cam)
1908{
1909 cam->flush = true;
1910
1911 cpia2_usb_stream_pause(cam);
1912
1913 /* reset camera to new size */
1914 cpia2_set_low_power(cam);
1915 cpia2_reset_camera(cam);
1916 cam->flush = false;
1917
1918 cpia2_dbg_dump_registers(cam);
1919
1920 cpia2_usb_stream_resume(cam);
1921}
1922
1923/******************************************************************************
1924 *
1925 * cpia2_dbg_dump_registers
1926 *
1927 *****************************************************************************/
1928void cpia2_dbg_dump_registers(struct camera_data *cam)
1929{
1930#ifdef _CPIA2_DEBUG_
1931 struct cpia2_command cmd;
1932
1933 if (!(debugs_on & DEBUG_DUMP_REGS))
1934 return;
1935
1936 cmd.direction = TRANSFER_READ;
1937
1938 /* Start with bank 0 (SYSTEM) */
1939 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_SYSTEM;
1940 cmd.reg_count = 3;
1941 cmd.start = 0;
1942 cpia2_send_command(cam, &cmd);
1943 printk(KERN_DEBUG "System Device Hi = 0x%X\n",
1944 cmd.buffer.block_data[0]);
1945 printk(KERN_DEBUG "System Device Lo = 0x%X\n",
1946 cmd.buffer.block_data[1]);
1947 printk(KERN_DEBUG "System_system control = 0x%X\n",
1948 cmd.buffer.block_data[2]);
1949
1950 /* Bank 1 (VC) */
1951 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VC;
1952 cmd.reg_count = 4;
1953 cmd.start = 0x80;
1954 cpia2_send_command(cam, &cmd);
1955 printk(KERN_DEBUG "ASIC_ID = 0x%X\n",
1956 cmd.buffer.block_data[0]);
1957 printk(KERN_DEBUG "ASIC_REV = 0x%X\n",
1958 cmd.buffer.block_data[1]);
1959 printk(KERN_DEBUG "PW_CONTRL = 0x%X\n",
1960 cmd.buffer.block_data[2]);
1961 printk(KERN_DEBUG "WAKEUP = 0x%X\n",
1962 cmd.buffer.block_data[3]);
1963
1964 cmd.start = 0xA0; /* ST_CTRL */
1965 cmd.reg_count = 1;
1966 cpia2_send_command(cam, &cmd);
1967 printk(KERN_DEBUG "Stream ctrl = 0x%X\n",
1968 cmd.buffer.block_data[0]);
1969
1970 cmd.start = 0xA4; /* Stream status */
1971 cpia2_send_command(cam, &cmd);
1972 printk(KERN_DEBUG "Stream status = 0x%X\n",
1973 cmd.buffer.block_data[0]);
1974
1975 cmd.start = 0xA8; /* USB status */
1976 cmd.reg_count = 3;
1977 cpia2_send_command(cam, &cmd);
1978 printk(KERN_DEBUG "USB_CTRL = 0x%X\n",
1979 cmd.buffer.block_data[0]);
1980 printk(KERN_DEBUG "USB_STRM = 0x%X\n",
1981 cmd.buffer.block_data[1]);
1982 printk(KERN_DEBUG "USB_STATUS = 0x%X\n",
1983 cmd.buffer.block_data[2]);
1984
1985 cmd.start = 0xAF; /* USB settings */
1986 cmd.reg_count = 1;
1987 cpia2_send_command(cam, &cmd);
1988 printk(KERN_DEBUG "USB settings = 0x%X\n",
1989 cmd.buffer.block_data[0]);
1990
1991 cmd.start = 0xC0; /* VC stuff */
1992 cmd.reg_count = 26;
1993 cpia2_send_command(cam, &cmd);
1994 printk(KERN_DEBUG "VC Control = 0x%0X\n",
1995 cmd.buffer.block_data[0]);
1996 printk(KERN_DEBUG "VC Format = 0x%0X\n",
1997 cmd.buffer.block_data[3]);
1998 printk(KERN_DEBUG "VC Clocks = 0x%0X\n",
1999 cmd.buffer.block_data[4]);
2000 printk(KERN_DEBUG "VC IHSize = 0x%0X\n",
2001 cmd.buffer.block_data[5]);
2002 printk(KERN_DEBUG "VC Xlim Hi = 0x%0X\n",
2003 cmd.buffer.block_data[6]);
2004 printk(KERN_DEBUG "VC XLim Lo = 0x%0X\n",
2005 cmd.buffer.block_data[7]);
2006 printk(KERN_DEBUG "VC YLim Hi = 0x%0X\n",
2007 cmd.buffer.block_data[8]);
2008 printk(KERN_DEBUG "VC YLim Lo = 0x%0X\n",
2009 cmd.buffer.block_data[9]);
2010 printk(KERN_DEBUG "VC OHSize = 0x%0X\n",
2011 cmd.buffer.block_data[10]);
2012 printk(KERN_DEBUG "VC OVSize = 0x%0X\n",
2013 cmd.buffer.block_data[11]);
2014 printk(KERN_DEBUG "VC HCrop = 0x%0X\n",
2015 cmd.buffer.block_data[12]);
2016 printk(KERN_DEBUG "VC VCrop = 0x%0X\n",
2017 cmd.buffer.block_data[13]);
2018 printk(KERN_DEBUG "VC HPhase = 0x%0X\n",
2019 cmd.buffer.block_data[14]);
2020 printk(KERN_DEBUG "VC VPhase = 0x%0X\n",
2021 cmd.buffer.block_data[15]);
2022 printk(KERN_DEBUG "VC HIspan = 0x%0X\n",
2023 cmd.buffer.block_data[16]);
2024 printk(KERN_DEBUG "VC VIspan = 0x%0X\n",
2025 cmd.buffer.block_data[17]);
2026 printk(KERN_DEBUG "VC HiCrop = 0x%0X\n",
2027 cmd.buffer.block_data[18]);
2028 printk(KERN_DEBUG "VC ViCrop = 0x%0X\n",
2029 cmd.buffer.block_data[19]);
2030 printk(KERN_DEBUG "VC HiFract = 0x%0X\n",
2031 cmd.buffer.block_data[20]);
2032 printk(KERN_DEBUG "VC ViFract = 0x%0X\n",
2033 cmd.buffer.block_data[21]);
2034 printk(KERN_DEBUG "VC JPeg Opt = 0x%0X\n",
2035 cmd.buffer.block_data[22]);
2036 printk(KERN_DEBUG "VC Creep Per = 0x%0X\n",
2037 cmd.buffer.block_data[23]);
2038 printk(KERN_DEBUG "VC User Sq. = 0x%0X\n",
2039 cmd.buffer.block_data[24]);
2040 printk(KERN_DEBUG "VC Target KB = 0x%0X\n",
2041 cmd.buffer.block_data[25]);
2042
2043 /*** VP ***/
2044 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VP;
2045 cmd.reg_count = 14;
2046 cmd.start = 0;
2047 cpia2_send_command(cam, &cmd);
2048
2049 printk(KERN_DEBUG "VP Dev Hi = 0x%0X\n",
2050 cmd.buffer.block_data[0]);
2051 printk(KERN_DEBUG "VP Dev Lo = 0x%0X\n",
2052 cmd.buffer.block_data[1]);
2053 printk(KERN_DEBUG "VP Sys State = 0x%0X\n",
2054 cmd.buffer.block_data[2]);
2055 printk(KERN_DEBUG "VP Sys Ctrl = 0x%0X\n",
2056 cmd.buffer.block_data[3]);
2057 printk(KERN_DEBUG "VP Sensor flg = 0x%0X\n",
2058 cmd.buffer.block_data[5]);
2059 printk(KERN_DEBUG "VP Sensor Rev = 0x%0X\n",
2060 cmd.buffer.block_data[6]);
2061 printk(KERN_DEBUG "VP Dev Config = 0x%0X\n",
2062 cmd.buffer.block_data[7]);
2063 printk(KERN_DEBUG "VP GPIO_DIR = 0x%0X\n",
2064 cmd.buffer.block_data[8]);
2065 printk(KERN_DEBUG "VP GPIO_DATA = 0x%0X\n",
2066 cmd.buffer.block_data[9]);
2067 printk(KERN_DEBUG "VP Ram ADDR H = 0x%0X\n",
2068 cmd.buffer.block_data[10]);
2069 printk(KERN_DEBUG "VP Ram ADDR L = 0x%0X\n",
2070 cmd.buffer.block_data[11]);
2071 printk(KERN_DEBUG "VP RAM Data = 0x%0X\n",
2072 cmd.buffer.block_data[12]);
2073 printk(KERN_DEBUG "Do Call = 0x%0X\n",
2074 cmd.buffer.block_data[13]);
2075
2076 if (cam->params.pnp_id.device_type == DEVICE_STV_672) {
2077 cmd.reg_count = 9;
2078 cmd.start = 0x0E;
2079 cpia2_send_command(cam, &cmd);
2080 printk(KERN_DEBUG "VP Clock Ctrl = 0x%0X\n",
2081 cmd.buffer.block_data[0]);
2082 printk(KERN_DEBUG "VP Patch Rev = 0x%0X\n",
2083 cmd.buffer.block_data[1]);
2084 printk(KERN_DEBUG "VP Vid Mode = 0x%0X\n",
2085 cmd.buffer.block_data[2]);
2086 printk(KERN_DEBUG "VP Framerate = 0x%0X\n",
2087 cmd.buffer.block_data[3]);
2088 printk(KERN_DEBUG "VP UserEffect = 0x%0X\n",
2089 cmd.buffer.block_data[4]);
2090 printk(KERN_DEBUG "VP White Bal = 0x%0X\n",
2091 cmd.buffer.block_data[5]);
2092 printk(KERN_DEBUG "VP WB thresh = 0x%0X\n",
2093 cmd.buffer.block_data[6]);
2094 printk(KERN_DEBUG "VP Exp Modes = 0x%0X\n",
2095 cmd.buffer.block_data[7]);
2096 printk(KERN_DEBUG "VP Exp Target = 0x%0X\n",
2097 cmd.buffer.block_data[8]);
2098
2099 cmd.reg_count = 1;
2100 cmd.start = 0x1B;
2101 cpia2_send_command(cam, &cmd);
2102 printk(KERN_DEBUG "VP FlickerMds = 0x%0X\n",
2103 cmd.buffer.block_data[0]);
2104 } else {
2105 cmd.reg_count = 8 ;
2106 cmd.start = 0x0E;
2107 cpia2_send_command(cam, &cmd);
2108 printk(KERN_DEBUG "VP Clock Ctrl = 0x%0X\n",
2109 cmd.buffer.block_data[0]);
2110 printk(KERN_DEBUG "VP Patch Rev = 0x%0X\n",
2111 cmd.buffer.block_data[1]);
2112 printk(KERN_DEBUG "VP Vid Mode = 0x%0X\n",
2113 cmd.buffer.block_data[5]);
2114 printk(KERN_DEBUG "VP Framerate = 0x%0X\n",
2115 cmd.buffer.block_data[6]);
2116 printk(KERN_DEBUG "VP UserEffect = 0x%0X\n",
2117 cmd.buffer.block_data[7]);
2118
2119 cmd.reg_count = 1;
2120 cmd.start = CPIA2_VP5_EXPOSURE_TARGET;
2121 cpia2_send_command(cam, &cmd);
2122 printk(KERN_DEBUG "VP5 Exp Target= 0x%0X\n",
2123 cmd.buffer.block_data[0]);
2124
2125 cmd.reg_count = 4;
2126 cmd.start = 0x3A;
2127 cpia2_send_command(cam, &cmd);
2128 printk(KERN_DEBUG "VP5 MY Black = 0x%0X\n",
2129 cmd.buffer.block_data[0]);
2130 printk(KERN_DEBUG "VP5 MCY Range = 0x%0X\n",
2131 cmd.buffer.block_data[1]);
2132 printk(KERN_DEBUG "VP5 MYCEILING = 0x%0X\n",
2133 cmd.buffer.block_data[2]);
2134 printk(KERN_DEBUG "VP5 MCUV Sat = 0x%0X\n",
2135 cmd.buffer.block_data[3]);
2136 }
2137#endif
2138}
2139
2140/******************************************************************************
2141 *
2142 * reset_camera_struct
2143 *
2144 * Sets all values to the defaults
2145 *****************************************************************************/
2146void reset_camera_struct(struct camera_data *cam)
2147{
2148 /***
2149 * The following parameter values are the defaults from the register map.
2150 ***/
2151 cam->params.color_params.brightness = DEFAULT_BRIGHTNESS;
2152 cam->params.color_params.contrast = DEFAULT_CONTRAST;
2153 cam->params.color_params.saturation = DEFAULT_SATURATION;
2154 cam->params.vp_params.lowlight_boost = 0;
2155
2156 /* FlickerModes */
2157 cam->params.flicker_control.flicker_mode_req = NEVER_FLICKER;
2158 cam->params.flicker_control.mains_frequency = 60;
2159
2160 /* jpeg params */
2161 cam->params.compression.jpeg_options = CPIA2_VC_VC_JPEG_OPT_DEFAULT;
2162 cam->params.compression.creep_period = 2;
2163 cam->params.compression.user_squeeze = 20;
2164 cam->params.compression.inhibit_htables = false;
2165
2166 /* gpio params */
2167 cam->params.vp_params.gpio_direction = 0; /* write, the default safe mode */
2168 cam->params.vp_params.gpio_data = 0;
2169
2170 /* Target kb params */
2171 cam->params.vc_params.target_kb = DEFAULT_TARGET_KB;
2172
2173 /***
2174 * Set Sensor FPS as fast as possible.
2175 ***/
2176 if(cam->params.pnp_id.device_type == DEVICE_STV_672) {
2177 if(cam->params.version.sensor_flags == CPIA2_VP_SENSOR_FLAGS_500)
2178 cam->params.vp_params.frame_rate = CPIA2_VP_FRAMERATE_15;
2179 else
2180 cam->params.vp_params.frame_rate = CPIA2_VP_FRAMERATE_30;
2181 } else {
2182 cam->params.vp_params.frame_rate = CPIA2_VP_FRAMERATE_30;
2183 }
2184
2185 /***
2186 * Set default video mode as large as possible :
2187 * for vga sensor set to vga, for cif sensor set to CIF.
2188 ***/
2189 if (cam->params.version.sensor_flags == CPIA2_VP_SENSOR_FLAGS_500) {
2190 cam->sensor_type = CPIA2_SENSOR_500;
2191 cam->video_size = VIDEOSIZE_VGA;
2192 cam->params.roi.width = STV_IMAGE_VGA_COLS;
2193 cam->params.roi.height = STV_IMAGE_VGA_ROWS;
2194 } else {
2195 cam->sensor_type = CPIA2_SENSOR_410;
2196 cam->video_size = VIDEOSIZE_CIF;
2197 cam->params.roi.width = STV_IMAGE_CIF_COLS;
2198 cam->params.roi.height = STV_IMAGE_CIF_ROWS;
2199 }
2200
2201 /***
2202 * Fill in the v4l structures. video_cap is filled in inside the VIDIOCCAP
2203 * Ioctl. Here, just do the window and picture stucts.
2204 ***/
2205 cam->vp.palette = (u16) VIDEO_PALETTE_RGB24; /* Is this right? */
2206 cam->vp.brightness = (u16) cam->params.color_params.brightness * 256;
2207 cam->vp.colour = (u16) cam->params.color_params.saturation * 256;
2208 cam->vp.contrast = (u16) cam->params.color_params.contrast * 256;
2209
2210 cam->vw.x = 0;
2211 cam->vw.y = 0;
2212 cam->vw.width = cam->params.roi.width;
2213 cam->vw.height = cam->params.roi.height;
2214 cam->vw.flags = 0;
2215 cam->vw.clipcount = 0;
2216
2217 return;
2218}
2219
2220/******************************************************************************
2221 *
2222 * cpia2_init_camera_struct
2223 *
2224 * Initializes camera struct, does not call reset to fill in defaults.
2225 *****************************************************************************/
2226struct camera_data *cpia2_init_camera_struct(void)
2227{
2228 struct camera_data *cam;
2229
2230 cam = kmalloc(sizeof(*cam), GFP_KERNEL);
2231
2232 if (!cam) {
2233 ERR("couldn't kmalloc cpia2 struct\n");
2234 return NULL;
2235 }
2236
2237 /* Default everything to 0 */
2238 memset(cam, 0, sizeof(struct camera_data));
2239
2240 cam->present = 1;
2241 init_MUTEX(&cam->busy_lock);
2242 init_waitqueue_head(&cam->wq_stream);
2243
2244 return cam;
2245}
2246
2247/******************************************************************************
2248 *
2249 * cpia2_init_camera
2250 *
2251 * Initializes camera.
2252 *****************************************************************************/
2253int cpia2_init_camera(struct camera_data *cam)
2254{
2255 DBG("Start\n");
2256
2257 cam->mmapped = false;
2258
2259 /* Get sensor and asic types before reset. */
2260 cpia2_set_high_power(cam);
2261 cpia2_get_version_info(cam);
2262 if (cam->params.version.asic_id != CPIA2_ASIC_672) {
2263 ERR("Device IO error (asicID has incorrect value of 0x%X\n",
2264 cam->params.version.asic_id);
2265 return -ENODEV;
2266 }
2267
2268 /* Set GPIO direction and data to a safe state. */
2269 cpia2_do_command(cam, CPIA2_CMD_SET_VC_MP_GPIO_DIRECTION,
2270 TRANSFER_WRITE, 0);
2271 cpia2_do_command(cam, CPIA2_CMD_SET_VC_MP_GPIO_DATA,
2272 TRANSFER_WRITE, 0);
2273
2274 /* resetting struct requires version info for sensor and asic types */
2275 reset_camera_struct(cam);
2276
2277 cpia2_set_low_power(cam);
2278
2279 DBG("End\n");
2280
2281 return 0;
2282}
2283
2284/******************************************************************************
2285 *
2286 * cpia2_allocate_buffers
2287 *
2288 *****************************************************************************/
2289int cpia2_allocate_buffers(struct camera_data *cam)
2290{
2291 int i;
2292
2293 if(!cam->buffers) {
2294 u32 size = cam->num_frames*sizeof(struct framebuf);
2295 cam->buffers = kmalloc(size, GFP_KERNEL);
2296 if(!cam->buffers) {
2297 ERR("couldn't kmalloc frame buffer structures\n");
2298 return -ENOMEM;
2299 }
2300 }
2301
2302 if(!cam->frame_buffer) {
2303 cam->frame_buffer = rvmalloc(cam->frame_size*cam->num_frames);
2304 if (!cam->frame_buffer) {
2305 ERR("couldn't vmalloc frame buffer data area\n");
2306 kfree(cam->buffers);
2307 cam->buffers = NULL;
2308 return -ENOMEM;
2309 }
2310 }
2311
2312 for(i=0; i<cam->num_frames-1; ++i) {
2313 cam->buffers[i].next = &cam->buffers[i+1];
2314 cam->buffers[i].data = cam->frame_buffer +i*cam->frame_size;
2315 cam->buffers[i].status = FRAME_EMPTY;
2316 cam->buffers[i].length = 0;
2317 cam->buffers[i].max_length = 0;
2318 cam->buffers[i].num = i;
2319 }
2320 cam->buffers[i].next = cam->buffers;
2321 cam->buffers[i].data = cam->frame_buffer +i*cam->frame_size;
2322 cam->buffers[i].status = FRAME_EMPTY;
2323 cam->buffers[i].length = 0;
2324 cam->buffers[i].max_length = 0;
2325 cam->buffers[i].num = i;
2326 cam->curbuff = cam->buffers;
2327 cam->workbuff = cam->curbuff->next;
2328 DBG("buffers=%p, curbuff=%p, workbuff=%p\n", cam->buffers, cam->curbuff,
2329 cam->workbuff);
2330 return 0;
2331}
2332
2333/******************************************************************************
2334 *
2335 * cpia2_free_buffers
2336 *
2337 *****************************************************************************/
2338void cpia2_free_buffers(struct camera_data *cam)
2339{
2340 if(cam->buffers) {
2341 kfree(cam->buffers);
2342 cam->buffers = NULL;
2343 }
2344 if(cam->frame_buffer) {
2345 rvfree(cam->frame_buffer, cam->frame_size*cam->num_frames);
2346 cam->frame_buffer = NULL;
2347 }
2348}
2349
2350/******************************************************************************
2351 *
2352 * cpia2_read
2353 *
2354 *****************************************************************************/
2355long cpia2_read(struct camera_data *cam,
2356 char __user *buf, unsigned long count, int noblock)
2357{
2358 struct framebuf *frame;
2359 if (!count) {
2360 return 0;
2361 }
2362
2363 if (!buf) {
2364 ERR("%s: buffer NULL\n",__FUNCTION__);
2365 return -EINVAL;
2366 }
2367
2368 if (!cam) {
2369 ERR("%s: Internal error, camera_data NULL!\n",__FUNCTION__);
2370 return -EINVAL;
2371 }
2372
2373 /* make this _really_ smp and multithread-safe */
2374 if (down_interruptible(&cam->busy_lock))
2375 return -ERESTARTSYS;
2376
2377 if (!cam->present) {
2378 LOG("%s: camera removed\n",__FUNCTION__);
2379 up(&cam->busy_lock);
2380 return 0; /* EOF */
2381 }
2382
2383 if(!cam->streaming) {
2384 /* Start streaming */
2385 cpia2_usb_stream_start(cam,
2386 cam->params.camera_state.stream_mode);
2387 }
2388
2389 /* Copy cam->curbuff in case it changes while we're processing */
2390 frame = cam->curbuff;
2391 if (noblock && frame->status != FRAME_READY) {
2392 up(&cam->busy_lock);
2393 return -EAGAIN;
2394 }
2395
2396 if(frame->status != FRAME_READY) {
2397 up(&cam->busy_lock);
2398 wait_event_interruptible(cam->wq_stream,
2399 !cam->present ||
2400 (frame = cam->curbuff)->status == FRAME_READY);
2401 if (signal_pending(current))
2402 return -ERESTARTSYS;
2403 /* make this _really_ smp and multithread-safe */
2404 if (down_interruptible(&cam->busy_lock)) {
2405 return -ERESTARTSYS;
2406 }
2407 if(!cam->present) {
2408 up(&cam->busy_lock);
2409 return 0;
2410 }
2411 }
2412
2413 /* copy data to user space */
2414 if (frame->length > count) {
2415 up(&cam->busy_lock);
2416 return -EFAULT;
2417 }
2418 if (copy_to_user(buf, frame->data, frame->length)) {
2419 up(&cam->busy_lock);
2420 return -EFAULT;
2421 }
2422
2423 count = frame->length;
2424
2425 frame->status = FRAME_EMPTY;
2426
2427 up(&cam->busy_lock);
2428 return count;
2429}
2430
2431/******************************************************************************
2432 *
2433 * cpia2_poll
2434 *
2435 *****************************************************************************/
2436unsigned int cpia2_poll(struct camera_data *cam, struct file *filp,
2437 poll_table *wait)
2438{
2439 unsigned int status=0;
2440
2441 if(!cam) {
2442 ERR("%s: Internal error, camera_data not found!\n",__FUNCTION__);
2443 return POLLERR;
2444 }
2445
2446 down(&cam->busy_lock);
2447
2448 if(!cam->present) {
2449 up(&cam->busy_lock);
2450 return POLLHUP;
2451 }
2452
2453 if(!cam->streaming) {
2454 /* Start streaming */
2455 cpia2_usb_stream_start(cam,
2456 cam->params.camera_state.stream_mode);
2457 }
2458
2459 up(&cam->busy_lock);
2460 poll_wait(filp, &cam->wq_stream, wait);
2461 down(&cam->busy_lock);
2462
2463 if(!cam->present)
2464 status = POLLHUP;
2465 else if(cam->curbuff->status == FRAME_READY)
2466 status = POLLIN | POLLRDNORM;
2467
2468 up(&cam->busy_lock);
2469 return status;
2470}
2471
2472/******************************************************************************
2473 *
2474 * cpia2_remap_buffer
2475 *
2476 *****************************************************************************/
2477int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma)
2478{
2479 const char *adr = (const char *)vma->vm_start;
2480 unsigned long size = vma->vm_end-vma->vm_start;
2481 unsigned long start_offset = vma->vm_pgoff << PAGE_SHIFT;
2482 unsigned long start = (unsigned long) adr;
2483 unsigned long page, pos;
2484
2485 if (!cam)
2486 return -ENODEV;
2487
2488 DBG("mmap offset:%ld size:%ld\n", start_offset, size);
2489
2490 /* make this _really_ smp-safe */
2491 if (down_interruptible(&cam->busy_lock))
2492 return -ERESTARTSYS;
2493
2494 if (!cam->present) {
2495 up(&cam->busy_lock);
2496 return -ENODEV;
2497 }
2498
2499 if (size > cam->frame_size*cam->num_frames ||
2500 (start_offset % cam->frame_size) != 0 ||
2501 (start_offset+size > cam->frame_size*cam->num_frames)) {
2502 up(&cam->busy_lock);
2503 return -EINVAL;
2504 }
2505
2506 pos = ((unsigned long) (cam->frame_buffer)) + start_offset;
2507 while (size > 0) {
2508 page = kvirt_to_pa(pos);
2509 if (remap_pfn_range(vma, start, page >> PAGE_SHIFT, PAGE_SIZE, PAGE_SHARED)) {
2510 up(&cam->busy_lock);
2511 return -EAGAIN;
2512 }
2513 start += PAGE_SIZE;
2514 pos += PAGE_SIZE;
2515 if (size > PAGE_SIZE)
2516 size -= PAGE_SIZE;
2517 else
2518 size = 0;
2519 }
2520
2521 cam->mmapped = true;
2522 up(&cam->busy_lock);
2523 return 0;
2524}
2525
diff --git a/drivers/media/video/cpia2/cpia2_registers.h b/drivers/media/video/cpia2/cpia2_registers.h
new file mode 100644
index 000000000000..3bbec514a967
--- /dev/null
+++ b/drivers/media/video/cpia2/cpia2_registers.h
@@ -0,0 +1,476 @@
1/****************************************************************************
2 *
3 * Filename: cpia2registers.h
4 *
5 * Copyright 2001, STMicrolectronics, Inc.
6 *
7 * Description:
8 * Definitions for the CPia2 register set
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 ****************************************************************************/
25
26#ifndef CPIA2_REGISTER_HEADER
27#define CPIA2_REGISTER_HEADER
28
29/***
30 * System register set (Bank 0)
31 ***/
32#define CPIA2_SYSTEM_DEVICE_HI 0x00
33#define CPIA2_SYSTEM_DEVICE_LO 0x01
34
35#define CPIA2_SYSTEM_SYSTEM_CONTROL 0x02
36#define CPIA2_SYSTEM_CONTROL_LOW_POWER 0x00
37#define CPIA2_SYSTEM_CONTROL_HIGH_POWER 0x01
38#define CPIA2_SYSTEM_CONTROL_SUSPEND 0x02
39#define CPIA2_SYSTEM_CONTROL_V2W_ERR 0x10
40#define CPIA2_SYSTEM_CONTROL_RB_ERR 0x10
41#define CPIA2_SYSTEM_CONTROL_CLEAR_ERR 0x80
42
43#define CPIA2_SYSTEM_INT_PACKET_CTRL 0x04
44#define CPIA2_SYSTEM_INT_PACKET_CTRL_ENABLE_SW_XX 0x01
45#define CPIA2_SYSTEM_INT_PACKET_CTRL_ENABLE_EOF 0x02
46#define CPIA2_SYSTEM_INT_PACKET_CTRL_ENABLE_INT1 0x04
47
48#define CPIA2_SYSTEM_CACHE_CTRL 0x05
49#define CPIA2_SYSTEM_CACHE_CTRL_CACHE_RESET 0x01
50#define CPIA2_SYSTEM_CACHE_CTRL_CACHE_FLUSH 0x02
51
52#define CPIA2_SYSTEM_SERIAL_CTRL 0x06
53#define CPIA2_SYSTEM_SERIAL_CTRL_NULL_CMD 0x00
54#define CPIA2_SYSTEM_SERIAL_CTRL_START_CMD 0x01
55#define CPIA2_SYSTEM_SERIAL_CTRL_STOP_CMD 0x02
56#define CPIA2_SYSTEM_SERIAL_CTRL_WRITE_CMD 0x03
57#define CPIA2_SYSTEM_SERIAL_CTRL_READ_ACK_CMD 0x04
58#define CPIA2_SYSTEM_SERIAL_CTRL_READ_NACK_CMD 0x05
59
60#define CPIA2_SYSTEM_SERIAL_DATA 0x07
61
62#define CPIA2_SYSTEM_VP_SERIAL_ADDR 0x08
63
64/***
65 * I2C addresses for various devices in CPiA2
66 ***/
67#define CPIA2_SYSTEM_VP_SERIAL_ADDR_SENSOR 0x20
68#define CPIA2_SYSTEM_VP_SERIAL_ADDR_VP 0x88
69#define CPIA2_SYSTEM_VP_SERIAL_ADDR_676_VP 0x8A
70
71#define CPIA2_SYSTEM_SPARE_REG1 0x09
72#define CPIA2_SYSTEM_SPARE_REG2 0x0A
73#define CPIA2_SYSTEM_SPARE_REG3 0x0B
74
75#define CPIA2_SYSTEM_MC_PORT_0 0x0C
76#define CPIA2_SYSTEM_MC_PORT_1 0x0D
77#define CPIA2_SYSTEM_MC_PORT_2 0x0E
78#define CPIA2_SYSTEM_MC_PORT_3 0x0F
79
80#define CPIA2_SYSTEM_STATUS_PKT 0x20
81#define CPIA2_SYSTEM_STATUS_PKT_END 0x27
82
83#define CPIA2_SYSTEM_DESCRIP_VID_HI 0x30
84#define CPIA2_SYSTEM_DESCRIP_VID_LO 0x31
85#define CPIA2_SYSTEM_DESCRIP_PID_HI 0x32
86#define CPIA2_SYSTEM_DESCRIP_PID_LO 0x33
87
88#define CPIA2_SYSTEM_FW_VERSION_HI 0x34
89#define CPIA2_SYSTEM_FW_VERSION_LO 0x35
90
91#define CPIA2_SYSTEM_CACHE_START_INDEX 0x80
92#define CPIA2_SYSTEM_CACHE_MAX_WRITES 0x10
93
94/***
95 * VC register set (Bank 1)
96 ***/
97#define CPIA2_VC_ASIC_ID 0x80
98
99#define CPIA2_VC_ASIC_REV 0x81
100
101#define CPIA2_VC_PW_CTRL 0x82
102#define CPIA2_VC_PW_CTRL_COLDSTART 0x01
103#define CPIA2_VC_PW_CTRL_CP_CLK_EN 0x02
104#define CPIA2_VC_PW_CTRL_VP_RESET_N 0x04
105#define CPIA2_VC_PW_CTRL_VC_CLK_EN 0x08
106#define CPIA2_VC_PW_CTRL_VC_RESET_N 0x10
107#define CPIA2_VC_PW_CTRL_GOTO_SUSPEND 0x20
108#define CPIA2_VC_PW_CTRL_UDC_SUSPEND 0x40
109#define CPIA2_VC_PW_CTRL_PWR_DOWN 0x80
110
111#define CPIA2_VC_WAKEUP 0x83
112#define CPIA2_VC_WAKEUP_SW_ENABLE 0x01
113#define CPIA2_VC_WAKEUP_XX_ENABLE 0x02
114#define CPIA2_VC_WAKEUP_SW_ATWAKEUP 0x04
115#define CPIA2_VC_WAKEUP_XX_ATWAKEUP 0x08
116
117#define CPIA2_VC_CLOCK_CTRL 0x84
118#define CPIA2_VC_CLOCK_CTRL_TESTUP72 0x01
119
120#define CPIA2_VC_INT_ENABLE 0x88
121#define CPIA2_VC_INT_ENABLE_XX_IE 0x01
122#define CPIA2_VC_INT_ENABLE_SW_IE 0x02
123#define CPIA2_VC_INT_ENABLE_VC_IE 0x04
124#define CPIA2_VC_INT_ENABLE_USBDATA_IE 0x08
125#define CPIA2_VC_INT_ENABLE_USBSETUP_IE 0x10
126#define CPIA2_VC_INT_ENABLE_USBCFG_IE 0x20
127
128#define CPIA2_VC_INT_FLAG 0x89
129#define CPIA2_VC_INT_ENABLE_XX_FLAG 0x01
130#define CPIA2_VC_INT_ENABLE_SW_FLAG 0x02
131#define CPIA2_VC_INT_ENABLE_VC_FLAG 0x04
132#define CPIA2_VC_INT_ENABLE_USBDATA_FLAG 0x08
133#define CPIA2_VC_INT_ENABLE_USBSETUP_FLAG 0x10
134#define CPIA2_VC_INT_ENABLE_USBCFG_FLAG 0x20
135#define CPIA2_VC_INT_ENABLE_SET_RESET_BIT 0x80
136
137#define CPIA2_VC_INT_STATE 0x8A
138#define CPIA2_VC_INT_STATE_XX_STATE 0x01
139#define CPIA2_VC_INT_STATE_SW_STATE 0x02
140
141#define CPIA2_VC_MP_DIR 0x90
142#define CPIA2_VC_MP_DIR_INPUT 0x00
143#define CPIA2_VC_MP_DIR_OUTPUT 0x01
144
145#define CPIA2_VC_MP_DATA 0x91
146
147#define CPIA2_VC_DP_CTRL 0x98
148#define CPIA2_VC_DP_CTRL_MODE_0 0x00
149#define CPIA2_VC_DP_CTRL_MODE_A 0x01
150#define CPIA2_VC_DP_CTRL_MODE_B 0x02
151#define CPIA2_VC_DP_CTRL_MODE_C 0x03
152#define CPIA2_VC_DP_CTRL_FAKE_FST 0x04
153
154#define CPIA2_VC_AD_CTRL 0x99
155#define CPIA2_VC_AD_CTRL_SRC_0 0x00
156#define CPIA2_VC_AD_CTRL_SRC_DIGI_A 0x01
157#define CPIA2_VC_AD_CTRL_SRC_REG 0x02
158#define CPIA2_VC_AD_CTRL_DST_USB 0x00
159#define CPIA2_VC_AD_CTRL_DST_REG 0x04
160
161#define CPIA2_VC_AD_TEST_IN 0x9B
162
163#define CPIA2_VC_AD_TEST_OUT 0x9C
164
165#define CPIA2_VC_AD_STATUS 0x9D
166#define CPIA2_VC_AD_STATUS_EMPTY 0x01
167#define CPIA2_VC_AD_STATUS_FULL 0x02
168
169#define CPIA2_VC_DP_DATA 0x9E
170
171#define CPIA2_VC_ST_CTRL 0xA0
172#define CPIA2_VC_ST_CTRL_SRC_VC 0x00
173#define CPIA2_VC_ST_CTRL_SRC_DP 0x01
174#define CPIA2_VC_ST_CTRL_SRC_REG 0x02
175
176#define CPIA2_VC_ST_CTRL_RAW_SELECT 0x04
177
178#define CPIA2_VC_ST_CTRL_DST_USB 0x00
179#define CPIA2_VC_ST_CTRL_DST_DP 0x08
180#define CPIA2_VC_ST_CTRL_DST_REG 0x10
181
182#define CPIA2_VC_ST_CTRL_FIFO_ENABLE 0x20
183#define CPIA2_VC_ST_CTRL_EOF_DETECT 0x40
184
185#define CPIA2_VC_ST_TEST 0xA1
186#define CPIA2_VC_ST_TEST_MODE_MANUAL 0x00
187#define CPIA2_VC_ST_TEST_MODE_INCREMENT 0x02
188
189#define CPIA2_VC_ST_TEST_AUTO_FILL 0x08
190
191#define CPIA2_VC_ST_TEST_REPEAT_FIFO 0x10
192
193#define CPIA2_VC_ST_TEST_IN 0xA2
194
195#define CPIA2_VC_ST_TEST_OUT 0xA3
196
197#define CPIA2_VC_ST_STATUS 0xA4
198#define CPIA2_VC_ST_STATUS_EMPTY 0x01
199#define CPIA2_VC_ST_STATUS_FULL 0x02
200
201#define CPIA2_VC_ST_FRAME_DETECT_1 0xA5
202
203#define CPIA2_VC_ST_FRAME_DETECT_2 0xA6
204
205#define CPIA2_VC_USB_CTRL 0xA8
206#define CPIA2_VC_USB_CTRL_CMD_STALLED 0x01
207#define CPIA2_VC_USB_CTRL_CMD_READY 0x02
208#define CPIA2_VC_USB_CTRL_CMD_STATUS 0x04
209#define CPIA2_VC_USB_CTRL_CMD_STATUS_DIR 0x08
210#define CPIA2_VC_USB_CTRL_CMD_NO_CLASH 0x10
211#define CPIA2_VC_USB_CTRL_CMD_MICRO_ACCESS 0x80
212
213#define CPIA2_VC_USB_STRM 0xA9
214#define CPIA2_VC_USB_STRM_ISO_ENABLE 0x01
215#define CPIA2_VC_USB_STRM_BLK_ENABLE 0x02
216#define CPIA2_VC_USB_STRM_INT_ENABLE 0x04
217#define CPIA2_VC_USB_STRM_AUD_ENABLE 0x08
218
219#define CPIA2_VC_USB_STATUS 0xAA
220#define CPIA2_VC_USB_STATUS_CMD_IN_PROGRESS 0x01
221#define CPIA2_VC_USB_STATUS_CMD_STATUS_STALL 0x02
222#define CPIA2_VC_USB_STATUS_CMD_HANDSHAKE 0x04
223#define CPIA2_VC_USB_STATUS_CMD_OVERRIDE 0x08
224#define CPIA2_VC_USB_STATUS_CMD_FIFO_BUSY 0x10
225#define CPIA2_VC_USB_STATUS_BULK_REPEAT_TXN 0x20
226#define CPIA2_VC_USB_STATUS_CONFIG_DONE 0x40
227#define CPIA2_VC_USB_STATUS_USB_SUSPEND 0x80
228
229#define CPIA2_VC_USB_CMDW 0xAB
230
231#define CPIA2_VC_USB_DATARW 0xAC
232
233#define CPIA2_VC_USB_INFO 0xAD
234
235#define CPIA2_VC_USB_CONFIG 0xAE
236
237#define CPIA2_VC_USB_SETTINGS 0xAF
238#define CPIA2_VC_USB_SETTINGS_CONFIG_MASK 0x03
239#define CPIA2_VC_USB_SETTINGS_INTERFACE_MASK 0x0C
240#define CPIA2_VC_USB_SETTINGS_ALTERNATE_MASK 0x70
241
242#define CPIA2_VC_USB_ISOLIM 0xB0
243
244#define CPIA2_VC_USB_ISOFAILS 0xB1
245
246#define CPIA2_VC_USB_ISOMAXPKTHI 0xB2
247
248#define CPIA2_VC_USB_ISOMAXPKTLO 0xB3
249
250#define CPIA2_VC_V2W_CTRL 0xB8
251#define CPIA2_VC_V2W_SELECT 0x01
252
253#define CPIA2_VC_V2W_SCL 0xB9
254
255#define CPIA2_VC_V2W_SDA 0xBA
256
257#define CPIA2_VC_VC_CTRL 0xC0
258#define CPIA2_VC_VC_CTRL_RUN 0x01
259#define CPIA2_VC_VC_CTRL_SINGLESHOT 0x02
260#define CPIA2_VC_VC_CTRL_IDLING 0x04
261#define CPIA2_VC_VC_CTRL_INHIBIT_H_TABLES 0x10
262#define CPIA2_VC_VC_CTRL_INHIBIT_Q_TABLES 0x20
263#define CPIA2_VC_VC_CTRL_INHIBIT_PRIVATE 0x40
264
265#define CPIA2_VC_VC_RESTART_IVAL_HI 0xC1
266
267#define CPIA2_VC_VC_RESTART_IVAL_LO 0xC2
268
269#define CPIA2_VC_VC_FORMAT 0xC3
270#define CPIA2_VC_VC_FORMAT_UFIRST 0x01
271#define CPIA2_VC_VC_FORMAT_MONO 0x02
272#define CPIA2_VC_VC_FORMAT_DECIMATING 0x04
273#define CPIA2_VC_VC_FORMAT_SHORTLINE 0x08
274#define CPIA2_VC_VC_FORMAT_SELFTEST 0x10
275
276#define CPIA2_VC_VC_CLOCKS 0xC4
277#define CPIA2_VC_VC_CLOCKS_CLKDIV_MASK 0x03
278#define CPIA2_VC_VC_672_CLOCKS_CIF_DIV_BY_3 0x04
279#define CPIA2_VC_VC_672_CLOCKS_SCALING 0x08
280#define CPIA2_VC_VC_CLOCKS_LOGDIV0 0x00
281#define CPIA2_VC_VC_CLOCKS_LOGDIV1 0x01
282#define CPIA2_VC_VC_CLOCKS_LOGDIV2 0x02
283#define CPIA2_VC_VC_CLOCKS_LOGDIV3 0x03
284#define CPIA2_VC_VC_676_CLOCKS_CIF_DIV_BY_3 0x08
285#define CPIA2_VC_VC_676_CLOCKS_SCALING 0x10
286
287#define CPIA2_VC_VC_IHSIZE_LO 0xC5
288
289#define CPIA2_VC_VC_XLIM_HI 0xC6
290
291#define CPIA2_VC_VC_XLIM_LO 0xC7
292
293#define CPIA2_VC_VC_YLIM_HI 0xC8
294
295#define CPIA2_VC_VC_YLIM_LO 0xC9
296
297#define CPIA2_VC_VC_OHSIZE 0xCA
298
299#define CPIA2_VC_VC_OVSIZE 0xCB
300
301#define CPIA2_VC_VC_HCROP 0xCC
302
303#define CPIA2_VC_VC_VCROP 0xCD
304
305#define CPIA2_VC_VC_HPHASE 0xCE
306
307#define CPIA2_VC_VC_VPHASE 0xCF
308
309#define CPIA2_VC_VC_HISPAN 0xD0
310
311#define CPIA2_VC_VC_VISPAN 0xD1
312
313#define CPIA2_VC_VC_HICROP 0xD2
314
315#define CPIA2_VC_VC_VICROP 0xD3
316
317#define CPIA2_VC_VC_HFRACT 0xD4
318#define CPIA2_VC_VC_HFRACT_DEN_MASK 0x0F
319#define CPIA2_VC_VC_HFRACT_NUM_MASK 0xF0
320
321#define CPIA2_VC_VC_VFRACT 0xD5
322#define CPIA2_VC_VC_VFRACT_DEN_MASK 0x0F
323#define CPIA2_VC_VC_VFRACT_NUM_MASK 0xF0
324
325#define CPIA2_VC_VC_JPEG_OPT 0xD6
326#define CPIA2_VC_VC_JPEG_OPT_DOUBLE_SQUEEZE 0x01
327#define CPIA2_VC_VC_JPEG_OPT_NO_DC_AUTO_SQUEEZE 0x02
328#define CPIA2_VC_VC_JPEG_OPT_AUTO_SQUEEZE 0x04
329#define CPIA2_VC_VC_JPEG_OPT_DEFAULT (CPIA2_VC_VC_JPEG_OPT_DOUBLE_SQUEEZE|\
330 CPIA2_VC_VC_JPEG_OPT_AUTO_SQUEEZE)
331
332
333#define CPIA2_VC_VC_CREEP_PERIOD 0xD7
334#define CPIA2_VC_VC_USER_SQUEEZE 0xD8
335#define CPIA2_VC_VC_TARGET_KB 0xD9
336
337#define CPIA2_VC_VC_AUTO_SQUEEZE 0xE6
338
339
340/***
341 * VP register set (Bank 2)
342 ***/
343#define CPIA2_VP_DEVICEH 0
344#define CPIA2_VP_DEVICEL 1
345
346#define CPIA2_VP_SYSTEMSTATE 0x02
347#define CPIA2_VP_SYSTEMSTATE_HK_ALIVE 0x01
348
349#define CPIA2_VP_SYSTEMCTRL 0x03
350#define CPIA2_VP_SYSTEMCTRL_REQ_CLEAR_ERROR 0x80
351#define CPIA2_VP_SYSTEMCTRL_POWER_DOWN_PLL 0x20
352#define CPIA2_VP_SYSTEMCTRL_REQ_SUSPEND_STATE 0x10
353#define CPIA2_VP_SYSTEMCTRL_REQ_SERIAL_WAKEUP 0x08
354#define CPIA2_VP_SYSTEMCTRL_REQ_AUTOLOAD 0x04
355#define CPIA2_VP_SYSTEMCTRL_HK_CONTROL 0x02
356#define CPIA2_VP_SYSTEMCTRL_POWER_CONTROL 0x01
357
358#define CPIA2_VP_SENSOR_FLAGS 0x05
359#define CPIA2_VP_SENSOR_FLAGS_404 0x01
360#define CPIA2_VP_SENSOR_FLAGS_407 0x02
361#define CPIA2_VP_SENSOR_FLAGS_409 0x04
362#define CPIA2_VP_SENSOR_FLAGS_410 0x08
363#define CPIA2_VP_SENSOR_FLAGS_500 0x10
364
365#define CPIA2_VP_SENSOR_REV 0x06
366
367#define CPIA2_VP_DEVICE_CONFIG 0x07
368#define CPIA2_VP_DEVICE_CONFIG_SERIAL_BRIDGE 0x01
369
370#define CPIA2_VP_GPIO_DIRECTION 0x08
371#define CPIA2_VP_GPIO_READ 0xFF
372#define CPIA2_VP_GPIO_WRITE 0x00
373
374#define CPIA2_VP_GPIO_DATA 0x09
375
376#define CPIA2_VP_RAM_ADDR_H 0x0A
377#define CPIA2_VP_RAM_ADDR_L 0x0B
378#define CPIA2_VP_RAM_DATA 0x0C
379
380#define CPIA2_VP_PATCH_REV 0x0F
381
382#define CPIA2_VP4_USER_MODE 0x10
383#define CPIA2_VP5_USER_MODE 0x13
384#define CPIA2_VP_USER_MODE_CIF 0x01
385#define CPIA2_VP_USER_MODE_QCIFDS 0x02
386#define CPIA2_VP_USER_MODE_QCIFPTC 0x04
387#define CPIA2_VP_USER_MODE_QVGADS 0x08
388#define CPIA2_VP_USER_MODE_QVGAPTC 0x10
389#define CPIA2_VP_USER_MODE_VGA 0x20
390
391#define CPIA2_VP4_FRAMERATE_REQUEST 0x11
392#define CPIA2_VP5_FRAMERATE_REQUEST 0x14
393#define CPIA2_VP_FRAMERATE_60 0x80
394#define CPIA2_VP_FRAMERATE_50 0x40
395#define CPIA2_VP_FRAMERATE_30 0x20
396#define CPIA2_VP_FRAMERATE_25 0x10
397#define CPIA2_VP_FRAMERATE_15 0x08
398#define CPIA2_VP_FRAMERATE_12_5 0x04
399#define CPIA2_VP_FRAMERATE_7_5 0x02
400#define CPIA2_VP_FRAMERATE_6_25 0x01
401
402#define CPIA2_VP4_USER_EFFECTS 0x12
403#define CPIA2_VP5_USER_EFFECTS 0x15
404#define CPIA2_VP_USER_EFFECTS_COLBARS 0x01
405#define CPIA2_VP_USER_EFFECTS_COLBARS_GRAD 0x02
406#define CPIA2_VP_USER_EFFECTS_MIRROR 0x04
407#define CPIA2_VP_USER_EFFECTS_FLIP 0x40 // VP5 only
408
409/* NOTE: CPIA2_VP_EXPOSURE_MODES shares the same register as VP5 User
410 * Effects */
411#define CPIA2_VP_EXPOSURE_MODES 0x15
412#define CPIA2_VP_EXPOSURE_MODES_INHIBIT_FLICKER 0x20
413#define CPIA2_VP_EXPOSURE_MODES_COMPILE_EXP 0x10
414
415#define CPIA2_VP4_EXPOSURE_TARGET 0x16 // VP4
416#define CPIA2_VP5_EXPOSURE_TARGET 0x20 // VP5
417
418#define CPIA2_VP_FLICKER_MODES 0x1B
419#define CPIA2_VP_FLICKER_MODES_50HZ 0x80
420#define CPIA2_VP_FLICKER_MODES_CUSTOM_FLT_FFREQ 0x40
421#define CPIA2_VP_FLICKER_MODES_NEVER_FLICKER 0x20
422#define CPIA2_VP_FLICKER_MODES_INHIBIT_RUB 0x10
423#define CPIA2_VP_FLICKER_MODES_ADJUST_LINE_FREQ 0x08
424#define CPIA2_VP_FLICKER_MODES_CUSTOM_INT_FFREQ 0x04
425
426#define CPIA2_VP_UMISC 0x1D
427#define CPIA2_VP_UMISC_FORCE_MONO 0x80
428#define CPIA2_VP_UMISC_FORCE_ID_MASK 0x40
429#define CPIA2_VP_UMISC_INHIBIT_AUTO_FGS 0x20
430#define CPIA2_VP_UMISC_INHIBIT_AUTO_DIMS 0x08
431#define CPIA2_VP_UMISC_OPT_FOR_SENSOR_DS 0x04
432#define CPIA2_VP_UMISC_INHIBIT_AUTO_MODE_INT 0x02
433
434#define CPIA2_VP5_ANTIFLKRSETUP 0x22 //34
435
436#define CPIA2_VP_INTERPOLATION 0x24
437#define CPIA2_VP_INTERPOLATION_EVEN_FIRST 0x40
438#define CPIA2_VP_INTERPOLATION_HJOG 0x20
439#define CPIA2_VP_INTERPOLATION_VJOG 0x10
440
441#define CPIA2_VP_GAMMA 0x25
442#define CPIA2_VP_DEFAULT_GAMMA 0x10
443
444#define CPIA2_VP_YRANGE 0x26
445
446#define CPIA2_VP_SATURATION 0x27
447
448#define CPIA2_VP5_MYBLACK_LEVEL 0x3A //58
449#define CPIA2_VP5_MCYRANGE 0x3B //59
450#define CPIA2_VP5_MYCEILING 0x3C //60
451#define CPIA2_VP5_MCUVSATURATION 0x3D //61
452
453
454#define CPIA2_VP_REHASH_VALUES 0x60
455
456
457/***
458 * Common sensor registers
459 ***/
460#define CPIA2_SENSOR_DEVICE_H 0x00
461#define CPIA2_SENSOR_DEVICE_L 0x01
462
463#define CPIA2_SENSOR_DATA_FORMAT 0x16
464#define CPIA2_SENSOR_DATA_FORMAT_HMIRROR 0x08
465#define CPIA2_SENSOR_DATA_FORMAT_VMIRROR 0x10
466
467#define CPIA2_SENSOR_CR1 0x76
468#define CPIA2_SENSOR_CR1_STAND_BY 0x01
469#define CPIA2_SENSOR_CR1_DOWN_RAMP_GEN 0x02
470#define CPIA2_SENSOR_CR1_DOWN_COLUMN_ADC 0x04
471#define CPIA2_SENSOR_CR1_DOWN_CAB_REGULATOR 0x08
472#define CPIA2_SENSOR_CR1_DOWN_AUDIO_REGULATOR 0x10
473#define CPIA2_SENSOR_CR1_DOWN_VRT_AMP 0x20
474#define CPIA2_SENSOR_CR1_DOWN_BAND_GAP 0x40
475
476#endif
diff --git a/drivers/media/video/cpia2/cpia2_usb.c b/drivers/media/video/cpia2/cpia2_usb.c
new file mode 100644
index 000000000000..f4da02941493
--- /dev/null
+++ b/drivers/media/video/cpia2/cpia2_usb.c
@@ -0,0 +1,907 @@
1/****************************************************************************
2 *
3 * Filename: cpia2_usb.c
4 *
5 * Copyright 2001, STMicrolectronics, Inc.
6 * Contact: steve.miller@st.com
7 *
8 * Description:
9 * This is a USB driver for CPia2 based video cameras.
10 * The infrastructure of this driver is based on the cpia usb driver by
11 * Jochen Scharrlach and Johannes Erdfeldt.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 * Stripped of 2.4 stuff ready for main kernel submit by
28 * Alan Cox <alan@redhat.com>
29 ****************************************************************************/
30
31#include <linux/kernel.h>
32#include <linux/slab.h>
33#include <linux/usb.h>
34
35#include "cpia2.h"
36
37static int frame_sizes[] = {
38 0, // USBIF_CMDONLY
39 0, // USBIF_BULK
40 128, // USBIF_ISO_1
41 384, // USBIF_ISO_2
42 640, // USBIF_ISO_3
43 768, // USBIF_ISO_4
44 896, // USBIF_ISO_5
45 1023, // USBIF_ISO_6
46};
47
48#define FRAMES_PER_DESC 10
49#define FRAME_SIZE_PER_DESC frame_sizes[cam->cur_alt]
50
51static void process_frame(struct camera_data *cam);
52static void cpia2_usb_complete(struct urb *urb, struct pt_regs *);
53static int cpia2_usb_probe(struct usb_interface *intf,
54 const struct usb_device_id *id);
55static void cpia2_usb_disconnect(struct usb_interface *intf);
56
57static void free_sbufs(struct camera_data *cam);
58static void add_APPn(struct camera_data *cam);
59static void add_COM(struct camera_data *cam);
60static int submit_urbs(struct camera_data *cam);
61static int set_alternate(struct camera_data *cam, unsigned int alt);
62static int configure_transfer_mode(struct camera_data *cam, unsigned int alt);
63
64static struct usb_device_id cpia2_id_table[] = {
65 {USB_DEVICE(0x0553, 0x0100)},
66 {USB_DEVICE(0x0553, 0x0140)},
67 {USB_DEVICE(0x0553, 0x0151)}, /* STV0676 */
68 {} /* Terminating entry */
69};
70MODULE_DEVICE_TABLE(usb, cpia2_id_table);
71
72static struct usb_driver cpia2_driver = {
73 .name = "cpia2",
74 .probe = cpia2_usb_probe,
75 .disconnect = cpia2_usb_disconnect,
76 .id_table = cpia2_id_table
77};
78
79
80/******************************************************************************
81 *
82 * process_frame
83 *
84 *****************************************************************************/
85static void process_frame(struct camera_data *cam)
86{
87 static int frame_count = 0;
88
89 unsigned char *inbuff = cam->workbuff->data;
90
91 DBG("Processing frame #%d, current:%d\n",
92 cam->workbuff->num, cam->curbuff->num);
93
94 if(cam->workbuff->length > cam->workbuff->max_length)
95 cam->workbuff->max_length = cam->workbuff->length;
96
97 if ((inbuff[0] == 0xFF) && (inbuff[1] == 0xD8)) {
98 frame_count++;
99 } else {
100 cam->workbuff->status = FRAME_ERROR;
101 DBG("Start of frame not found\n");
102 return;
103 }
104
105 /***
106 * Now the output buffer should have a JPEG image in it.
107 ***/
108 if(!cam->first_image_seen) {
109 /* Always skip the first image after streaming
110 * starts. It is almost certainly corrupt. */
111 cam->first_image_seen = 1;
112 cam->workbuff->status = FRAME_EMPTY;
113 return;
114 }
115 if (cam->workbuff->length > 3) {
116 if(cam->mmapped &&
117 cam->workbuff->length < cam->workbuff->max_length) {
118 /* No junk in the buffers */
119 memset(cam->workbuff->data+cam->workbuff->length,
120 0, cam->workbuff->max_length-
121 cam->workbuff->length);
122 }
123 cam->workbuff->max_length = cam->workbuff->length;
124 cam->workbuff->status = FRAME_READY;
125
126 if(!cam->mmapped && cam->num_frames > 2) {
127 /* During normal reading, the most recent
128 * frame will be read. If the current frame
129 * hasn't started reading yet, it will never
130 * be read, so mark it empty. If the buffer is
131 * mmapped, or we have few buffers, we need to
132 * wait for the user to free the buffer.
133 *
134 * NOTE: This is not entirely foolproof with 3
135 * buffers, but it would take an EXTREMELY
136 * overloaded system to cause problems (possible
137 * image data corruption). Basically, it would
138 * need to take more time to execute cpia2_read
139 * than it would for the camera to send
140 * cam->num_frames-2 frames before problems
141 * could occur.
142 */
143 cam->curbuff->status = FRAME_EMPTY;
144 }
145 cam->curbuff = cam->workbuff;
146 cam->workbuff = cam->workbuff->next;
147 DBG("Changed buffers, work:%d, current:%d\n",
148 cam->workbuff->num, cam->curbuff->num);
149 return;
150 } else {
151 DBG("Not enough data for an image.\n");
152 }
153
154 cam->workbuff->status = FRAME_ERROR;
155 return;
156}
157
158/******************************************************************************
159 *
160 * add_APPn
161 *
162 * Adds a user specified APPn record
163 *****************************************************************************/
164static void add_APPn(struct camera_data *cam)
165{
166 if(cam->APP_len > 0) {
167 cam->workbuff->data[cam->workbuff->length++] = 0xFF;
168 cam->workbuff->data[cam->workbuff->length++] = 0xE0+cam->APPn;
169 cam->workbuff->data[cam->workbuff->length++] = 0;
170 cam->workbuff->data[cam->workbuff->length++] = cam->APP_len+2;
171 memcpy(cam->workbuff->data+cam->workbuff->length,
172 cam->APP_data, cam->APP_len);
173 cam->workbuff->length += cam->APP_len;
174 }
175}
176
177/******************************************************************************
178 *
179 * add_COM
180 *
181 * Adds a user specified COM record
182 *****************************************************************************/
183static void add_COM(struct camera_data *cam)
184{
185 if(cam->COM_len > 0) {
186 cam->workbuff->data[cam->workbuff->length++] = 0xFF;
187 cam->workbuff->data[cam->workbuff->length++] = 0xFE;
188 cam->workbuff->data[cam->workbuff->length++] = 0;
189 cam->workbuff->data[cam->workbuff->length++] = cam->COM_len+2;
190 memcpy(cam->workbuff->data+cam->workbuff->length,
191 cam->COM_data, cam->COM_len);
192 cam->workbuff->length += cam->COM_len;
193 }
194}
195
196/******************************************************************************
197 *
198 * cpia2_usb_complete
199 *
200 * callback when incoming packet is received
201 *****************************************************************************/
202static void cpia2_usb_complete(struct urb *urb, struct pt_regs *regs)
203{
204 int i;
205 unsigned char *cdata;
206 static int frame_ready = false;
207 struct camera_data *cam = (struct camera_data *) urb->context;
208
209 if (urb->status!=0) {
210 if (!(urb->status == -ENOENT ||
211 urb->status == -ECONNRESET ||
212 urb->status == -ESHUTDOWN))
213 {
214 DBG("urb->status = %d!\n", urb->status);
215 }
216 DBG("Stopping streaming\n");
217 return;
218 }
219
220 if (!cam->streaming || !cam->present || cam->open_count == 0) {
221 LOG("Will now stop the streaming: streaming = %d, "
222 "present=%d, open_count=%d\n",
223 cam->streaming, cam->present, cam->open_count);
224 return;
225 }
226
227 /***
228 * Packet collater
229 ***/
230 //DBG("Collating %d packets\n", urb->number_of_packets);
231 for (i = 0; i < urb->number_of_packets; i++) {
232 u16 checksum, iso_checksum;
233 int j;
234 int n = urb->iso_frame_desc[i].actual_length;
235 int st = urb->iso_frame_desc[i].status;
236
237 if(cam->workbuff->status == FRAME_READY) {
238 struct framebuf *ptr;
239 /* Try to find an available buffer */
240 DBG("workbuff full, searching\n");
241 for (ptr = cam->workbuff->next;
242 ptr != cam->workbuff;
243 ptr = ptr->next)
244 {
245 if (ptr->status == FRAME_EMPTY) {
246 ptr->status = FRAME_READING;
247 ptr->length = 0;
248 break;
249 }
250 }
251 if (ptr == cam->workbuff)
252 break; /* No READING or EMPTY buffers left */
253
254 cam->workbuff = ptr;
255 }
256
257 if (cam->workbuff->status == FRAME_EMPTY ||
258 cam->workbuff->status == FRAME_ERROR) {
259 cam->workbuff->status = FRAME_READING;
260 cam->workbuff->length = 0;
261 }
262
263 //DBG(" Packet %d length = %d, status = %d\n", i, n, st);
264 cdata = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
265
266 if (st) {
267 LOG("cpia2 data error: [%d] len=%d, status = %d\n",
268 i, n, st);
269 if(!ALLOW_CORRUPT)
270 cam->workbuff->status = FRAME_ERROR;
271 continue;
272 }
273
274 if(n<=2)
275 continue;
276
277 checksum = 0;
278 for(j=0; j<n-2; ++j)
279 checksum += cdata[j];
280 iso_checksum = cdata[j] + cdata[j+1]*256;
281 if(checksum != iso_checksum) {
282 LOG("checksum mismatch: [%d] len=%d, calculated = %x, checksum = %x\n",
283 i, n, (int)checksum, (int)iso_checksum);
284 if(!ALLOW_CORRUPT) {
285 cam->workbuff->status = FRAME_ERROR;
286 continue;
287 }
288 }
289 n -= 2;
290
291 if(cam->workbuff->status != FRAME_READING) {
292 if((0xFF == cdata[0] && 0xD8 == cdata[1]) ||
293 (0xD8 == cdata[0] && 0xFF == cdata[1] &&
294 0 != cdata[2])) {
295 /* frame is skipped, but increment total
296 * frame count anyway */
297 cam->frame_count++;
298 }
299 DBG("workbuff not reading, status=%d\n",
300 cam->workbuff->status);
301 continue;
302 }
303
304 if (cam->frame_size < cam->workbuff->length + n) {
305 ERR("buffer overflow! length: %d, n: %d\n",
306 cam->workbuff->length, n);
307 cam->workbuff->status = FRAME_ERROR;
308 if(cam->workbuff->length > cam->workbuff->max_length)
309 cam->workbuff->max_length =
310 cam->workbuff->length;
311 continue;
312 }
313
314 if (cam->workbuff->length == 0) {
315 int data_offset;
316 if ((0xD8 == cdata[0]) && (0xFF == cdata[1])) {
317 data_offset = 1;
318 } else if((0xFF == cdata[0]) && (0xD8 == cdata[1])
319 && (0xFF == cdata[2])) {
320 data_offset = 2;
321 } else {
322 DBG("Ignoring packet, not beginning!\n");
323 continue;
324 }
325 DBG("Start of frame pattern found\n");
326 do_gettimeofday(&cam->workbuff->timestamp);
327 cam->workbuff->seq = cam->frame_count++;
328 cam->workbuff->data[0] = 0xFF;
329 cam->workbuff->data[1] = 0xD8;
330 cam->workbuff->length = 2;
331 add_APPn(cam);
332 add_COM(cam);
333 memcpy(cam->workbuff->data+cam->workbuff->length,
334 cdata+data_offset, n-data_offset);
335 cam->workbuff->length += n-data_offset;
336 } else if (cam->workbuff->length > 0) {
337 memcpy(cam->workbuff->data + cam->workbuff->length,
338 cdata, n);
339 cam->workbuff->length += n;
340 }
341
342 if ((cam->workbuff->length >= 3) &&
343 (cam->workbuff->data[cam->workbuff->length - 3] == 0xFF) &&
344 (cam->workbuff->data[cam->workbuff->length - 2] == 0xD9) &&
345 (cam->workbuff->data[cam->workbuff->length - 1] == 0xFF)) {
346 frame_ready = true;
347 cam->workbuff->data[cam->workbuff->length - 1] = 0;
348 cam->workbuff->length -= 1;
349 } else if ((cam->workbuff->length >= 2) &&
350 (cam->workbuff->data[cam->workbuff->length - 2] == 0xFF) &&
351 (cam->workbuff->data[cam->workbuff->length - 1] == 0xD9)) {
352 frame_ready = true;
353 }
354
355 if (frame_ready) {
356 DBG("Workbuff image size = %d\n",cam->workbuff->length);
357 process_frame(cam);
358
359 frame_ready = false;
360
361 if (waitqueue_active(&cam->wq_stream))
362 wake_up_interruptible(&cam->wq_stream);
363 }
364 }
365
366 if(cam->streaming) {
367 /* resubmit */
368 urb->dev = cam->dev;
369 if ((i = usb_submit_urb(urb, GFP_ATOMIC)) != 0)
370 ERR("%s: usb_submit_urb ret %d!\n", __func__, i);
371 }
372}
373
374/******************************************************************************
375 *
376 * configure_transfer_mode
377 *
378 *****************************************************************************/
379static int configure_transfer_mode(struct camera_data *cam, unsigned int alt)
380{
381 static unsigned char iso_regs[8][4] = {
382 {0x00, 0x00, 0x00, 0x00},
383 {0x00, 0x00, 0x00, 0x00},
384 {0xB9, 0x00, 0x00, 0x7E},
385 {0xB9, 0x00, 0x01, 0x7E},
386 {0xB9, 0x00, 0x02, 0x7E},
387 {0xB9, 0x00, 0x02, 0xFE},
388 {0xB9, 0x00, 0x03, 0x7E},
389 {0xB9, 0x00, 0x03, 0xFD}
390 };
391 struct cpia2_command cmd;
392 unsigned char reg;
393
394 if(!cam->present)
395 return -ENODEV;
396
397 /***
398 * Write the isoc registers according to the alternate selected
399 ***/
400 cmd.direction = TRANSFER_WRITE;
401 cmd.buffer.block_data[0] = iso_regs[alt][0];
402 cmd.buffer.block_data[1] = iso_regs[alt][1];
403 cmd.buffer.block_data[2] = iso_regs[alt][2];
404 cmd.buffer.block_data[3] = iso_regs[alt][3];
405 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VC;
406 cmd.start = CPIA2_VC_USB_ISOLIM;
407 cmd.reg_count = 4;
408 cpia2_send_command(cam, &cmd);
409
410 /***
411 * Enable relevant streams before starting polling.
412 * First read USB Stream Config Register.
413 ***/
414 cmd.direction = TRANSFER_READ;
415 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VC;
416 cmd.start = CPIA2_VC_USB_STRM;
417 cmd.reg_count = 1;
418 cpia2_send_command(cam, &cmd);
419 reg = cmd.buffer.block_data[0];
420
421 /* Clear iso, bulk, and int */
422 reg &= ~(CPIA2_VC_USB_STRM_BLK_ENABLE |
423 CPIA2_VC_USB_STRM_ISO_ENABLE |
424 CPIA2_VC_USB_STRM_INT_ENABLE);
425
426 if (alt == USBIF_BULK) {
427 DBG("Enabling bulk xfer\n");
428 reg |= CPIA2_VC_USB_STRM_BLK_ENABLE; /* Enable Bulk */
429 cam->xfer_mode = XFER_BULK;
430 } else if (alt >= USBIF_ISO_1) {
431 DBG("Enabling ISOC xfer\n");
432 reg |= CPIA2_VC_USB_STRM_ISO_ENABLE;
433 cam->xfer_mode = XFER_ISOC;
434 }
435
436 cmd.buffer.block_data[0] = reg;
437 cmd.direction = TRANSFER_WRITE;
438 cmd.start = CPIA2_VC_USB_STRM;
439 cmd.reg_count = 1;
440 cmd.req_mode = CAMERAACCESS_TYPE_BLOCK | CAMERAACCESS_VC;
441 cpia2_send_command(cam, &cmd);
442
443 return 0;
444}
445
446/******************************************************************************
447 *
448 * cpia2_usb_change_streaming_alternate
449 *
450 *****************************************************************************/
451int cpia2_usb_change_streaming_alternate(struct camera_data *cam,
452 unsigned int alt)
453{
454 int ret = 0;
455
456 if(alt < USBIF_ISO_1 || alt > USBIF_ISO_6)
457 return -EINVAL;
458
459 if(alt == cam->params.camera_state.stream_mode)
460 return 0;
461
462 cpia2_usb_stream_pause(cam);
463
464 configure_transfer_mode(cam, alt);
465
466 cam->params.camera_state.stream_mode = alt;
467
468 /* Reset the camera to prevent image quality degradation */
469 cpia2_reset_camera(cam);
470
471 cpia2_usb_stream_resume(cam);
472
473 return ret;
474}
475
476/******************************************************************************
477 *
478 * set_alternate
479 *
480 *****************************************************************************/
481int set_alternate(struct camera_data *cam, unsigned int alt)
482{
483 int ret = 0;
484
485 if(alt == cam->cur_alt)
486 return 0;
487
488 if (cam->cur_alt != USBIF_CMDONLY) {
489 DBG("Changing from alt %d to %d\n", cam->cur_alt, USBIF_CMDONLY);
490 ret = usb_set_interface(cam->dev, cam->iface, USBIF_CMDONLY);
491 if (ret != 0)
492 return ret;
493 }
494 if (alt != USBIF_CMDONLY) {
495 DBG("Changing from alt %d to %d\n", USBIF_CMDONLY, alt);
496 ret = usb_set_interface(cam->dev, cam->iface, alt);
497 if (ret != 0)
498 return ret;
499 }
500
501 cam->old_alt = cam->cur_alt;
502 cam->cur_alt = alt;
503
504 return ret;
505}
506
507/******************************************************************************
508 *
509 * free_sbufs
510 *
511 * Free all cam->sbuf[]. All non-NULL .data and .urb members that are non-NULL
512 * are assumed to be allocated. Non-NULL .urb members are also assumed to be
513 * submitted (and must therefore be killed before they are freed).
514 *****************************************************************************/
515static void free_sbufs(struct camera_data *cam)
516{
517 int i;
518
519 for (i = 0; i < NUM_SBUF; i++) {
520 if(cam->sbuf[i].urb) {
521 usb_kill_urb(cam->sbuf[i].urb);
522 usb_free_urb(cam->sbuf[i].urb);
523 cam->sbuf[i].urb = NULL;
524 }
525 if(cam->sbuf[i].data) {
526 kfree(cam->sbuf[i].data);
527 cam->sbuf[i].data = NULL;
528 }
529 }
530}
531
532/*******
533* Convenience functions
534*******/
535/****************************************************************************
536 *
537 * write_packet
538 *
539 ***************************************************************************/
540static int write_packet(struct usb_device *udev,
541 u8 request, u8 * registers, u16 start, size_t size)
542{
543 if (!registers || size <= 0)
544 return -EINVAL;
545
546 return usb_control_msg(udev,
547 usb_sndctrlpipe(udev, 0),
548 request,
549 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
550 start, /* value */
551 0, /* index */
552 registers, /* buffer */
553 size,
554 HZ);
555}
556
557/****************************************************************************
558 *
559 * read_packet
560 *
561 ***************************************************************************/
562static int read_packet(struct usb_device *udev,
563 u8 request, u8 * registers, u16 start, size_t size)
564{
565 if (!registers || size <= 0)
566 return -EINVAL;
567
568 return usb_control_msg(udev,
569 usb_rcvctrlpipe(udev, 0),
570 request,
571 USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_DEVICE,
572 start, /* value */
573 0, /* index */
574 registers, /* buffer */
575 size,
576 HZ);
577}
578
579/******************************************************************************
580 *
581 * cpia2_usb_transfer_cmd
582 *
583 *****************************************************************************/
584int cpia2_usb_transfer_cmd(struct camera_data *cam,
585 void *registers,
586 u8 request, u8 start, u8 count, u8 direction)
587{
588 int err = 0;
589 struct usb_device *udev = cam->dev;
590
591 if (!udev) {
592 ERR("%s: Internal driver error: udev is NULL\n", __func__);
593 return -EINVAL;
594 }
595
596 if (!registers) {
597 ERR("%s: Internal driver error: register array is NULL\n", __func__);
598 return -EINVAL;
599 }
600
601 if (direction == TRANSFER_READ) {
602 err = read_packet(udev, request, (u8 *)registers, start, count);
603 if (err > 0)
604 err = 0;
605 } else if (direction == TRANSFER_WRITE) {
606 err =write_packet(udev, request, (u8 *)registers, start, count);
607 if (err < 0) {
608 LOG("Control message failed, err val = %d\n", err);
609 LOG("Message: request = 0x%0X, start = 0x%0X\n",
610 request, start);
611 LOG("Message: count = %d, register[0] = 0x%0X\n",
612 count, ((unsigned char *) registers)[0]);
613 } else
614 err=0;
615 } else {
616 LOG("Unexpected first byte of direction: %d\n",
617 direction);
618 return -EINVAL;
619 }
620
621 if(err != 0)
622 LOG("Unexpected error: %d\n", err);
623 return err;
624}
625
626
627/******************************************************************************
628 *
629 * submit_urbs
630 *
631 *****************************************************************************/
632static int submit_urbs(struct camera_data *cam)
633{
634 struct urb *urb;
635 int fx, err, i;
636
637 for(i=0; i<NUM_SBUF; ++i) {
638 if (cam->sbuf[i].data)
639 continue;
640 cam->sbuf[i].data =
641 kmalloc(FRAMES_PER_DESC * FRAME_SIZE_PER_DESC, GFP_KERNEL);
642 if (!cam->sbuf[i].data) {
643 return -ENOMEM;
644 }
645 }
646
647 /* We double buffer the Isoc lists, and also know the polling
648 * interval is every frame (1 == (1 << (bInterval -1))).
649 */
650 for(i=0; i<NUM_SBUF; ++i) {
651 if(cam->sbuf[i].urb) {
652 continue;
653 }
654 urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
655 if (!urb) {
656 return -ENOMEM;
657 }
658
659 cam->sbuf[i].urb = urb;
660 urb->dev = cam->dev;
661 urb->context = cam;
662 urb->pipe = usb_rcvisocpipe(cam->dev, 1 /*ISOC endpoint*/);
663 urb->transfer_flags = URB_ISO_ASAP;
664 urb->transfer_buffer = cam->sbuf[i].data;
665 urb->complete = cpia2_usb_complete;
666 urb->number_of_packets = FRAMES_PER_DESC;
667 urb->interval = 1;
668 urb->transfer_buffer_length =
669 FRAME_SIZE_PER_DESC * FRAMES_PER_DESC;
670
671 for (fx = 0; fx < FRAMES_PER_DESC; fx++) {
672 urb->iso_frame_desc[fx].offset =
673 FRAME_SIZE_PER_DESC * fx;
674 urb->iso_frame_desc[fx].length = FRAME_SIZE_PER_DESC;
675 }
676 }
677
678
679 /* Queue the ISO urbs, and resubmit in the completion handler */
680 for(i=0; i<NUM_SBUF; ++i) {
681 err = usb_submit_urb(cam->sbuf[i].urb, GFP_KERNEL);
682 if (err) {
683 ERR("usb_submit_urb[%d]() = %d\n", i, err);
684 return err;
685 }
686 }
687
688 return 0;
689}
690
691/******************************************************************************
692 *
693 * cpia2_usb_stream_start
694 *
695 *****************************************************************************/
696int cpia2_usb_stream_start(struct camera_data *cam, unsigned int alternate)
697{
698 int ret;
699 int old_alt;
700
701 if(cam->streaming)
702 return 0;
703
704 if (cam->flush) {
705 int i;
706 DBG("Flushing buffers\n");
707 for(i=0; i<cam->num_frames; ++i) {
708 cam->buffers[i].status = FRAME_EMPTY;
709 cam->buffers[i].length = 0;
710 }
711 cam->curbuff = &cam->buffers[0];
712 cam->workbuff = cam->curbuff->next;
713 cam->flush = false;
714 }
715
716 old_alt = cam->params.camera_state.stream_mode;
717 cam->params.camera_state.stream_mode = 0;
718 ret = cpia2_usb_change_streaming_alternate(cam, alternate);
719 if (ret < 0) {
720 int ret2;
721 ERR("cpia2_usb_change_streaming_alternate() = %d!\n", ret);
722 cam->params.camera_state.stream_mode = old_alt;
723 ret2 = set_alternate(cam, USBIF_CMDONLY);
724 if (ret2 < 0) {
725 ERR("cpia2_usb_change_streaming_alternate(%d) =%d has already "
726 "failed. Then tried to call "
727 "set_alternate(USBIF_CMDONLY) = %d.\n",
728 alternate, ret, ret2);
729 }
730 } else {
731 cam->frame_count = 0;
732 cam->streaming = 1;
733 ret = cpia2_usb_stream_resume(cam);
734 }
735 return ret;
736}
737
738/******************************************************************************
739 *
740 * cpia2_usb_stream_pause
741 *
742 *****************************************************************************/
743int cpia2_usb_stream_pause(struct camera_data *cam)
744{
745 int ret = 0;
746 if(cam->streaming) {
747 ret = set_alternate(cam, USBIF_CMDONLY);
748 free_sbufs(cam);
749 }
750 return ret;
751}
752
753/******************************************************************************
754 *
755 * cpia2_usb_stream_resume
756 *
757 *****************************************************************************/
758int cpia2_usb_stream_resume(struct camera_data *cam)
759{
760 int ret = 0;
761 if(cam->streaming) {
762 cam->first_image_seen = 0;
763 ret = set_alternate(cam, cam->params.camera_state.stream_mode);
764 if(ret == 0) {
765 ret = submit_urbs(cam);
766 }
767 }
768 return ret;
769}
770
771/******************************************************************************
772 *
773 * cpia2_usb_stream_stop
774 *
775 *****************************************************************************/
776int cpia2_usb_stream_stop(struct camera_data *cam)
777{
778 int ret;
779 ret = cpia2_usb_stream_pause(cam);
780 cam->streaming = 0;
781 configure_transfer_mode(cam, 0);
782 return ret;
783}
784
785/******************************************************************************
786 *
787 * cpia2_usb_probe
788 *
789 * Probe and initialize.
790 *****************************************************************************/
791static int cpia2_usb_probe(struct usb_interface *intf,
792 const struct usb_device_id *id)
793{
794 struct usb_device *udev = interface_to_usbdev(intf);
795 struct usb_interface_descriptor *interface;
796 struct camera_data *cam;
797 int ret;
798
799 /* A multi-config CPiA2 camera? */
800 if (udev->descriptor.bNumConfigurations != 1)
801 return -ENODEV;
802 interface = &intf->cur_altsetting->desc;
803
804 /* If we get to this point, we found a CPiA2 camera */
805 LOG("CPiA2 USB camera found\n");
806
807 if((cam = cpia2_init_camera_struct()) == NULL)
808 return -ENOMEM;
809
810 cam->dev = udev;
811 cam->iface = interface->bInterfaceNumber;
812
813 ret = set_alternate(cam, USBIF_CMDONLY);
814 if (ret < 0) {
815 ERR("%s: usb_set_interface error (ret = %d)\n", __func__, ret);
816 kfree(cam);
817 return ret;
818 }
819
820 if ((ret = cpia2_register_camera(cam)) < 0) {
821 ERR("%s: Failed to register cpia2 camera (ret = %d)\n", __func__, ret);
822 kfree(cam);
823 return ret;
824 }
825
826
827 if((ret = cpia2_init_camera(cam)) < 0) {
828 ERR("%s: failed to initialize cpia2 camera (ret = %d)\n", __func__, ret);
829 cpia2_unregister_camera(cam);
830 kfree(cam);
831 return ret;
832 }
833 LOG(" CPiA Version: %d.%02d (%d.%d)\n",
834 cam->params.version.firmware_revision_hi,
835 cam->params.version.firmware_revision_lo,
836 cam->params.version.asic_id,
837 cam->params.version.asic_rev);
838 LOG(" CPiA PnP-ID: %04x:%04x:%04x\n",
839 cam->params.pnp_id.vendor,
840 cam->params.pnp_id.product,
841 cam->params.pnp_id.device_revision);
842 LOG(" SensorID: %d.(version %d)\n",
843 cam->params.version.sensor_flags,
844 cam->params.version.sensor_rev);
845
846 usb_set_intfdata(intf, cam);
847
848 return 0;
849}
850
851/******************************************************************************
852 *
853 * cpia2_disconnect
854 *
855 *****************************************************************************/
856static void cpia2_usb_disconnect(struct usb_interface *intf)
857{
858 struct camera_data *cam = usb_get_intfdata(intf);
859 usb_set_intfdata(intf, NULL);
860 cam->present = 0;
861
862 DBG("Stopping stream\n");
863 cpia2_usb_stream_stop(cam);
864
865 DBG("Unregistering camera\n");
866 cpia2_unregister_camera(cam);
867
868 if(cam->buffers) {
869 DBG("Wakeup waiting processes\n");
870 cam->curbuff->status = FRAME_READY;
871 cam->curbuff->length = 0;
872 if (waitqueue_active(&cam->wq_stream))
873 wake_up_interruptible(&cam->wq_stream);
874 }
875
876 DBG("Releasing interface\n");
877 usb_driver_release_interface(&cpia2_driver, intf);
878
879 if (cam->open_count == 0) {
880 DBG("Freeing camera structure\n");
881 kfree(cam);
882 }
883
884 LOG("CPiA2 camera disconnected.\n");
885}
886
887
888/******************************************************************************
889 *
890 * usb_cpia2_init
891 *
892 *****************************************************************************/
893int cpia2_usb_init(void)
894{
895 return usb_register(&cpia2_driver);
896}
897
898/******************************************************************************
899 *
900 * usb_cpia_cleanup
901 *
902 *****************************************************************************/
903void cpia2_usb_cleanup(void)
904{
905 schedule_timeout(2 * HZ);
906 usb_deregister(&cpia2_driver);
907}
diff --git a/drivers/media/video/cpia2/cpia2_v4l.c b/drivers/media/video/cpia2/cpia2_v4l.c
new file mode 100644
index 000000000000..08f8be345fa8
--- /dev/null
+++ b/drivers/media/video/cpia2/cpia2_v4l.c
@@ -0,0 +1,2079 @@
1/****************************************************************************
2 *
3 * Filename: cpia2_v4l.c
4 *
5 * Copyright 2001, STMicrolectronics, Inc.
6 * Contact: steve.miller@st.com
7 * Copyright 2001,2005, Scott J. Bertin <scottbertin@yahoo.com>
8 *
9 * Description:
10 * This is a USB driver for CPia2 based video cameras.
11 * The infrastructure of this driver is based on the cpia usb driver by
12 * Jochen Scharrlach and Johannes Erdfeldt.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 * Stripped of 2.4 stuff ready for main kernel submit by
29 * Alan Cox <alan@redhat.com>
30 ****************************************************************************/
31
32#include <linux/version.h>
33
34#include <linux/config.h>
35
36#include <linux/module.h>
37#include <linux/time.h>
38#include <linux/sched.h>
39#include <linux/slab.h>
40#include <linux/init.h>
41#include <linux/moduleparam.h>
42
43#include "cpia2.h"
44#include "cpia2dev.h"
45
46
47//#define _CPIA2_DEBUG_
48
49#define MAKE_STRING_1(x) #x
50#define MAKE_STRING(x) MAKE_STRING_1(x)
51
52static int video_nr = -1;
53module_param(video_nr, int, 0);
54MODULE_PARM_DESC(video_nr,"video device to register (0=/dev/video0, etc)");
55
56static int buffer_size = 68*1024;
57module_param(buffer_size, int, 0);
58MODULE_PARM_DESC(buffer_size, "Size for each frame buffer in bytes (default 68k)");
59
60static int num_buffers = 3;
61module_param(num_buffers, int, 0);
62MODULE_PARM_DESC(num_buffers, "Number of frame buffers (1-"
63 MAKE_STRING(VIDEO_MAX_FRAME) ", default 3)");
64
65static int alternate = DEFAULT_ALT;
66module_param(alternate, int, 0);
67MODULE_PARM_DESC(alternate, "USB Alternate (" MAKE_STRING(USBIF_ISO_1) "-"
68 MAKE_STRING(USBIF_ISO_6) ", default "
69 MAKE_STRING(DEFAULT_ALT) ")");
70
71static int flicker_freq = 60;
72module_param(flicker_freq, int, 0);
73MODULE_PARM_DESC(flicker_freq, "Flicker frequency (" MAKE_STRING(50) "or"
74 MAKE_STRING(60) ", default "
75 MAKE_STRING(60) ")");
76
77static int flicker_mode = NEVER_FLICKER;
78module_param(flicker_mode, int, 0);
79MODULE_PARM_DESC(flicker_mode,
80 "Flicker supression (" MAKE_STRING(NEVER_FLICKER) "or"
81 MAKE_STRING(ANTI_FLICKER_ON) ", default "
82 MAKE_STRING(NEVER_FLICKER) ")");
83
84MODULE_AUTHOR("Steve Miller (STMicroelectronics) <steve.miller@st.com>");
85MODULE_DESCRIPTION("V4L-driver for STMicroelectronics CPiA2 based cameras");
86MODULE_SUPPORTED_DEVICE("video");
87MODULE_LICENSE("GPL");
88
89#define ABOUT "V4L-Driver for Vision CPiA2 based cameras"
90
91#ifndef VID_HARDWARE_CPIA2
92#error "VID_HARDWARE_CPIA2 should have been defined in linux/videodev.h"
93#endif
94
95struct control_menu_info {
96 int value;
97 char name[32];
98};
99
100static struct control_menu_info framerate_controls[] =
101{
102 { CPIA2_VP_FRAMERATE_6_25, "6.25 fps" },
103 { CPIA2_VP_FRAMERATE_7_5, "7.5 fps" },
104 { CPIA2_VP_FRAMERATE_12_5, "12.5 fps" },
105 { CPIA2_VP_FRAMERATE_15, "15 fps" },
106 { CPIA2_VP_FRAMERATE_25, "25 fps" },
107 { CPIA2_VP_FRAMERATE_30, "30 fps" },
108};
109#define NUM_FRAMERATE_CONTROLS (sizeof(framerate_controls)/sizeof(framerate_controls[0]))
110
111static struct control_menu_info flicker_controls[] =
112{
113 { NEVER_FLICKER, "Off" },
114 { FLICKER_50, "50 Hz" },
115 { FLICKER_60, "60 Hz" },
116};
117#define NUM_FLICKER_CONTROLS (sizeof(flicker_controls)/sizeof(flicker_controls[0]))
118
119static struct control_menu_info lights_controls[] =
120{
121 { 0, "Off" },
122 { 64, "Top" },
123 { 128, "Bottom" },
124 { 192, "Both" },
125};
126#define NUM_LIGHTS_CONTROLS (sizeof(lights_controls)/sizeof(lights_controls[0]))
127#define GPIO_LIGHTS_MASK 192
128
129static struct v4l2_queryctrl controls[] = {
130 {
131 .id = V4L2_CID_BRIGHTNESS,
132 .type = V4L2_CTRL_TYPE_INTEGER,
133 .name = "Brightness",
134 .minimum = 0,
135 .maximum = 255,
136 .step = 1,
137 .default_value = DEFAULT_BRIGHTNESS,
138 },
139 {
140 .id = V4L2_CID_CONTRAST,
141 .type = V4L2_CTRL_TYPE_INTEGER,
142 .name = "Contrast",
143 .minimum = 0,
144 .maximum = 255,
145 .step = 1,
146 .default_value = DEFAULT_CONTRAST,
147 },
148 {
149 .id = V4L2_CID_SATURATION,
150 .type = V4L2_CTRL_TYPE_INTEGER,
151 .name = "Saturation",
152 .minimum = 0,
153 .maximum = 255,
154 .step = 1,
155 .default_value = DEFAULT_SATURATION,
156 },
157 {
158 .id = V4L2_CID_HFLIP,
159 .type = V4L2_CTRL_TYPE_BOOLEAN,
160 .name = "Mirror Horizontally",
161 .minimum = 0,
162 .maximum = 1,
163 .step = 1,
164 .default_value = 0,
165 },
166 {
167 .id = V4L2_CID_VFLIP,
168 .type = V4L2_CTRL_TYPE_BOOLEAN,
169 .name = "Flip Vertically",
170 .minimum = 0,
171 .maximum = 1,
172 .step = 1,
173 .default_value = 0,
174 },
175 {
176 .id = CPIA2_CID_TARGET_KB,
177 .type = V4L2_CTRL_TYPE_INTEGER,
178 .name = "Target KB",
179 .minimum = 0,
180 .maximum = 255,
181 .step = 1,
182 .default_value = DEFAULT_TARGET_KB,
183 },
184 {
185 .id = CPIA2_CID_GPIO,
186 .type = V4L2_CTRL_TYPE_INTEGER,
187 .name = "GPIO",
188 .minimum = 0,
189 .maximum = 255,
190 .step = 1,
191 .default_value = 0,
192 },
193 {
194 .id = CPIA2_CID_FLICKER_MODE,
195 .type = V4L2_CTRL_TYPE_MENU,
196 .name = "Flicker Reduction",
197 .minimum = 0,
198 .maximum = NUM_FLICKER_CONTROLS-1,
199 .step = 1,
200 .default_value = 0,
201 },
202 {
203 .id = CPIA2_CID_FRAMERATE,
204 .type = V4L2_CTRL_TYPE_MENU,
205 .name = "Framerate",
206 .minimum = 0,
207 .maximum = NUM_FRAMERATE_CONTROLS-1,
208 .step = 1,
209 .default_value = NUM_FRAMERATE_CONTROLS-1,
210 },
211 {
212 .id = CPIA2_CID_USB_ALT,
213 .type = V4L2_CTRL_TYPE_INTEGER,
214 .name = "USB Alternate",
215 .minimum = USBIF_ISO_1,
216 .maximum = USBIF_ISO_6,
217 .step = 1,
218 .default_value = DEFAULT_ALT,
219 },
220 {
221 .id = CPIA2_CID_LIGHTS,
222 .type = V4L2_CTRL_TYPE_MENU,
223 .name = "Lights",
224 .minimum = 0,
225 .maximum = NUM_LIGHTS_CONTROLS-1,
226 .step = 1,
227 .default_value = 0,
228 },
229 {
230 .id = CPIA2_CID_RESET_CAMERA,
231 .type = V4L2_CTRL_TYPE_BUTTON,
232 .name = "Reset Camera",
233 .minimum = 0,
234 .maximum = 0,
235 .step = 0,
236 .default_value = 0,
237 },
238};
239#define NUM_CONTROLS (sizeof(controls)/sizeof(controls[0]))
240
241
242/******************************************************************************
243 *
244 * cpia2_open
245 *
246 *****************************************************************************/
247static int cpia2_open(struct inode *inode, struct file *file)
248{
249 struct video_device *dev = video_devdata(file);
250 struct camera_data *cam = video_get_drvdata(dev);
251 int retval = 0;
252
253 if (!cam) {
254 ERR("Internal error, camera_data not found!\n");
255 return -ENODEV;
256 }
257
258 if(down_interruptible(&cam->busy_lock))
259 return -ERESTARTSYS;
260
261 if(!cam->present) {
262 retval = -ENODEV;
263 goto err_return;
264 }
265
266 if (cam->open_count > 0) {
267 goto skip_init;
268 }
269
270 if (cpia2_allocate_buffers(cam)) {
271 retval = -ENOMEM;
272 goto err_return;
273 }
274
275 /* reset the camera */
276 if (cpia2_reset_camera(cam) < 0) {
277 retval = -EIO;
278 goto err_return;
279 }
280
281 cam->APP_len = 0;
282 cam->COM_len = 0;
283
284skip_init:
285 {
286 struct cpia2_fh *fh = kmalloc(sizeof(*fh),GFP_KERNEL);
287 if(!fh) {
288 retval = -ENOMEM;
289 goto err_return;
290 }
291 file->private_data = fh;
292 fh->prio = V4L2_PRIORITY_UNSET;
293 v4l2_prio_open(&cam->prio, &fh->prio);
294 fh->mmapped = 0;
295 }
296
297 ++cam->open_count;
298
299 cpia2_dbg_dump_registers(cam);
300
301err_return:
302 up(&cam->busy_lock);
303 return retval;
304}
305
306/******************************************************************************
307 *
308 * cpia2_close
309 *
310 *****************************************************************************/
311static int cpia2_close(struct inode *inode, struct file *file)
312{
313 struct video_device *dev = video_devdata(file);
314 struct camera_data *cam = video_get_drvdata(dev);
315 struct cpia2_fh *fh = file->private_data;
316
317 down(&cam->busy_lock);
318
319 if (cam->present &&
320 (cam->open_count == 1
321 || fh->prio == V4L2_PRIORITY_RECORD
322 )) {
323 cpia2_usb_stream_stop(cam);
324
325 if(cam->open_count == 1) {
326 /* save camera state for later open */
327 cpia2_save_camera_state(cam);
328
329 cpia2_set_low_power(cam);
330 cpia2_free_buffers(cam);
331 }
332 }
333
334 {
335 if(fh->mmapped)
336 cam->mmapped = 0;
337 v4l2_prio_close(&cam->prio,&fh->prio);
338 file->private_data = NULL;
339 kfree(fh);
340 }
341
342 if (--cam->open_count == 0) {
343 cpia2_free_buffers(cam);
344 if (!cam->present) {
345 video_unregister_device(dev);
346 kfree(cam);
347 }
348 }
349
350 up(&cam->busy_lock);
351
352 return 0;
353}
354
355/******************************************************************************
356 *
357 * cpia2_v4l_read
358 *
359 *****************************************************************************/
360static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count,
361 loff_t *off)
362{
363 struct video_device *dev = video_devdata(file);
364 struct camera_data *cam = video_get_drvdata(dev);
365 int noblock = file->f_flags&O_NONBLOCK;
366
367 struct cpia2_fh *fh = file->private_data;
368
369 if(!cam)
370 return -EINVAL;
371
372 /* Priority check */
373 if(fh->prio != V4L2_PRIORITY_RECORD) {
374 return -EBUSY;
375 }
376
377 return cpia2_read(cam, buf, count, noblock);
378}
379
380
381/******************************************************************************
382 *
383 * cpia2_v4l_poll
384 *
385 *****************************************************************************/
386static unsigned int cpia2_v4l_poll(struct file *filp, struct poll_table_struct *wait)
387{
388 struct video_device *dev = video_devdata(filp);
389 struct camera_data *cam = video_get_drvdata(dev);
390
391 struct cpia2_fh *fh = filp->private_data;
392
393 if(!cam)
394 return POLLERR;
395
396 /* Priority check */
397 if(fh->prio != V4L2_PRIORITY_RECORD) {
398 return POLLERR;
399 }
400
401 return cpia2_poll(cam, filp, wait);
402}
403
404
405/******************************************************************************
406 *
407 * ioctl_cap_query
408 *
409 *****************************************************************************/
410static int ioctl_cap_query(void *arg, struct camera_data *cam)
411{
412 struct video_capability *vc;
413 int retval = 0;
414 vc = arg;
415
416 if (cam->params.pnp_id.product == 0x151)
417 strcpy(vc->name, "QX5 Microscope");
418 else
419 strcpy(vc->name, "CPiA2 Camera");
420
421 vc->type = VID_TYPE_CAPTURE | VID_TYPE_MJPEG_ENCODER;
422 vc->channels = 1;
423 vc->audios = 0;
424 vc->minwidth = 176; /* VIDEOSIZE_QCIF */
425 vc->minheight = 144;
426 switch (cam->params.version.sensor_flags) {
427 case CPIA2_VP_SENSOR_FLAGS_500:
428 vc->maxwidth = STV_IMAGE_VGA_COLS;
429 vc->maxheight = STV_IMAGE_VGA_ROWS;
430 break;
431 case CPIA2_VP_SENSOR_FLAGS_410:
432 vc->maxwidth = STV_IMAGE_CIF_COLS;
433 vc->maxheight = STV_IMAGE_CIF_ROWS;
434 break;
435 default:
436 return -EINVAL;
437 }
438
439 return retval;
440}
441
442/******************************************************************************
443 *
444 * ioctl_get_channel
445 *
446 *****************************************************************************/
447static int ioctl_get_channel(void *arg)
448{
449 int retval = 0;
450 struct video_channel *v;
451 v = arg;
452
453 if (v->channel != 0)
454 return -EINVAL;
455
456 v->channel = 0;
457 strcpy(v->name, "Camera");
458 v->tuners = 0;
459 v->flags = 0;
460 v->type = VIDEO_TYPE_CAMERA;
461 v->norm = 0;
462
463 return retval;
464}
465
466/******************************************************************************
467 *
468 * ioctl_set_channel
469 *
470 *****************************************************************************/
471static int ioctl_set_channel(void *arg)
472{
473 struct video_channel *v;
474 int retval = 0;
475 v = arg;
476
477 if (retval == 0 && v->channel != 0)
478 retval = -EINVAL;
479
480 return retval;
481}
482
483/******************************************************************************
484 *
485 * ioctl_set_image_prop
486 *
487 *****************************************************************************/
488static int ioctl_set_image_prop(void *arg, struct camera_data *cam)
489{
490 struct video_picture *vp;
491 int retval = 0;
492 vp = arg;
493
494 /* brightness, color, contrast need no check 0-65535 */
495 memcpy(&cam->vp, vp, sizeof(*vp));
496
497 /* update cam->params.colorParams */
498 cam->params.color_params.brightness = vp->brightness / 256;
499 cam->params.color_params.saturation = vp->colour / 256;
500 cam->params.color_params.contrast = vp->contrast / 256;
501
502 DBG("Requested params: bright 0x%X, sat 0x%X, contrast 0x%X\n",
503 cam->params.color_params.brightness,
504 cam->params.color_params.saturation,
505 cam->params.color_params.contrast);
506
507 cpia2_set_color_params(cam);
508
509 return retval;
510}
511
512static int sync(struct camera_data *cam, int frame_nr)
513{
514 struct framebuf *frame = &cam->buffers[frame_nr];
515
516 while (1) {
517 if (frame->status == FRAME_READY)
518 return 0;
519
520 if (!cam->streaming) {
521 frame->status = FRAME_READY;
522 frame->length = 0;
523 return 0;
524 }
525
526 up(&cam->busy_lock);
527 wait_event_interruptible(cam->wq_stream,
528 !cam->streaming ||
529 frame->status == FRAME_READY);
530 down(&cam->busy_lock);
531 if (signal_pending(current))
532 return -ERESTARTSYS;
533 if(!cam->present)
534 return -ENOTTY;
535 }
536}
537
538/******************************************************************************
539 *
540 * ioctl_set_window_size
541 *
542 *****************************************************************************/
543static int ioctl_set_window_size(void *arg, struct camera_data *cam,
544 struct cpia2_fh *fh)
545{
546 /* copy_from_user, check validity, copy to internal structure */
547 struct video_window *vw;
548 int frame, err;
549 vw = arg;
550
551 if (vw->clipcount != 0) /* clipping not supported */
552 return -EINVAL;
553
554 if (vw->clips != NULL) /* clipping not supported */
555 return -EINVAL;
556
557 /* Ensure that only this process can change the format. */
558 err = v4l2_prio_change(&cam->prio, &fh->prio, V4L2_PRIORITY_RECORD);
559 if(err != 0)
560 return err;
561
562 cam->pixelformat = V4L2_PIX_FMT_JPEG;
563
564 /* Be sure to supply the Huffman tables, this isn't MJPEG */
565 cam->params.compression.inhibit_htables = 0;
566
567 /* we set the video window to something smaller or equal to what
568 * is requested by the user???
569 */
570 DBG("Requested width = %d, height = %d\n", vw->width, vw->height);
571 if (vw->width != cam->vw.width || vw->height != cam->vw.height) {
572 cam->vw.width = vw->width;
573 cam->vw.height = vw->height;
574 cam->params.roi.width = vw->width;
575 cam->params.roi.height = vw->height;
576 cpia2_set_format(cam);
577 }
578
579 for (frame = 0; frame < cam->num_frames; ++frame) {
580 if (cam->buffers[frame].status == FRAME_READING)
581 if ((err = sync(cam, frame)) < 0)
582 return err;
583
584 cam->buffers[frame].status = FRAME_EMPTY;
585 }
586
587 return 0;
588}
589
590/******************************************************************************
591 *
592 * ioctl_get_mbuf
593 *
594 *****************************************************************************/
595static int ioctl_get_mbuf(void *arg, struct camera_data *cam)
596{
597 struct video_mbuf *vm;
598 int i;
599 vm = arg;
600
601 memset(vm, 0, sizeof(*vm));
602 vm->size = cam->frame_size*cam->num_frames;
603 vm->frames = cam->num_frames;
604 for (i = 0; i < cam->num_frames; i++)
605 vm->offsets[i] = cam->frame_size * i;
606
607 return 0;
608}
609
610/******************************************************************************
611 *
612 * ioctl_mcapture
613 *
614 *****************************************************************************/
615static int ioctl_mcapture(void *arg, struct camera_data *cam,
616 struct cpia2_fh *fh)
617{
618 struct video_mmap *vm;
619 int video_size, err;
620 vm = arg;
621
622 if (vm->frame < 0 || vm->frame >= cam->num_frames)
623 return -EINVAL;
624
625 /* set video size */
626 video_size = cpia2_match_video_size(vm->width, vm->height);
627 if (cam->video_size < 0) {
628 return -EINVAL;
629 }
630
631 /* Ensure that only this process can change the format. */
632 err = v4l2_prio_change(&cam->prio, &fh->prio, V4L2_PRIORITY_RECORD);
633 if(err != 0)
634 return err;
635
636 if (video_size != cam->video_size) {
637 cam->video_size = video_size;
638 cam->params.roi.width = vm->width;
639 cam->params.roi.height = vm->height;
640 cpia2_set_format(cam);
641 }
642
643 if (cam->buffers[vm->frame].status == FRAME_READING)
644 if ((err=sync(cam, vm->frame)) < 0)
645 return err;
646
647 cam->buffers[vm->frame].status = FRAME_EMPTY;
648
649 return cpia2_usb_stream_start(cam,cam->params.camera_state.stream_mode);
650}
651
652/******************************************************************************
653 *
654 * ioctl_sync
655 *
656 *****************************************************************************/
657static int ioctl_sync(void *arg, struct camera_data *cam)
658{
659 int frame;
660
661 frame = *(int*)arg;
662
663 if (frame < 0 || frame >= cam->num_frames)
664 return -EINVAL;
665
666 return sync(cam, frame);
667}
668
669
670/******************************************************************************
671 *
672 * ioctl_set_gpio
673 *
674 *****************************************************************************/
675
676static int ioctl_set_gpio(void *arg, struct camera_data *cam)
677{
678 __u32 gpio_val;
679
680 gpio_val = *(__u32*) arg;
681
682 if (gpio_val &~ 0xFFU)
683 return -EINVAL;
684
685 return cpia2_set_gpio(cam, (unsigned char)gpio_val);
686}
687
688/******************************************************************************
689 *
690 * ioctl_querycap
691 *
692 * V4L2 device capabilities
693 *
694 *****************************************************************************/
695
696static int ioctl_querycap(void *arg, struct camera_data *cam)
697{
698 struct v4l2_capability *vc = arg;
699
700 memset(vc, 0, sizeof(*vc));
701 strcpy(vc->driver, "cpia2");
702
703 if (cam->params.pnp_id.product == 0x151)
704 strcpy(vc->card, "QX5 Microscope");
705 else
706 strcpy(vc->card, "CPiA2 Camera");
707 switch (cam->params.pnp_id.device_type) {
708 case DEVICE_STV_672:
709 strcat(vc->card, " (672/");
710 break;
711 case DEVICE_STV_676:
712 strcat(vc->card, " (676/");
713 break;
714 default:
715 strcat(vc->card, " (???/");
716 break;
717 }
718 switch (cam->params.version.sensor_flags) {
719 case CPIA2_VP_SENSOR_FLAGS_404:
720 strcat(vc->card, "404)");
721 break;
722 case CPIA2_VP_SENSOR_FLAGS_407:
723 strcat(vc->card, "407)");
724 break;
725 case CPIA2_VP_SENSOR_FLAGS_409:
726 strcat(vc->card, "409)");
727 break;
728 case CPIA2_VP_SENSOR_FLAGS_410:
729 strcat(vc->card, "410)");
730 break;
731 case CPIA2_VP_SENSOR_FLAGS_500:
732 strcat(vc->card, "500)");
733 break;
734 default:
735 strcat(vc->card, "???)");
736 break;
737 }
738
739 if (usb_make_path(cam->dev, vc->bus_info, sizeof(vc->bus_info)) <0)
740 memset(vc->bus_info,0, sizeof(vc->bus_info));
741
742 vc->version = KERNEL_VERSION(CPIA2_MAJ_VER, CPIA2_MIN_VER,
743 CPIA2_PATCH_VER);
744
745 vc->capabilities = V4L2_CAP_VIDEO_CAPTURE |
746 V4L2_CAP_READWRITE |
747 V4L2_CAP_STREAMING;
748
749 return 0;
750}
751
752/******************************************************************************
753 *
754 * ioctl_input
755 *
756 * V4L2 input get/set/enumerate
757 *
758 *****************************************************************************/
759
760static int ioctl_input(unsigned int ioclt_nr,void *arg,struct camera_data *cam)
761{
762 struct v4l2_input *i = arg;
763
764 if(ioclt_nr != VIDIOC_G_INPUT) {
765 if (i->index != 0)
766 return -EINVAL;
767 }
768
769 memset(i, 0, sizeof(*i));
770 strcpy(i->name, "Camera");
771 i->type = V4L2_INPUT_TYPE_CAMERA;
772
773 return 0;
774}
775
776/******************************************************************************
777 *
778 * ioctl_enum_fmt
779 *
780 * V4L2 format enumerate
781 *
782 *****************************************************************************/
783
784static int ioctl_enum_fmt(void *arg,struct camera_data *cam)
785{
786 struct v4l2_fmtdesc *f = arg;
787 int index = f->index;
788
789 if (index < 0 || index > 1)
790 return -EINVAL;
791
792 memset(f, 0, sizeof(*f));
793 f->index = index;
794 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
795 f->flags = V4L2_FMT_FLAG_COMPRESSED;
796 switch(index) {
797 case 0:
798 strcpy(f->description, "MJPEG");
799 f->pixelformat = V4L2_PIX_FMT_MJPEG;
800 break;
801 case 1:
802 strcpy(f->description, "JPEG");
803 f->pixelformat = V4L2_PIX_FMT_JPEG;
804 break;
805 default:
806 return -EINVAL;
807 }
808
809 return 0;
810}
811
812/******************************************************************************
813 *
814 * ioctl_try_fmt
815 *
816 * V4L2 format try
817 *
818 *****************************************************************************/
819
820static int ioctl_try_fmt(void *arg,struct camera_data *cam)
821{
822 struct v4l2_format *f = arg;
823
824 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
825 return -EINVAL;
826
827 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG &&
828 f->fmt.pix.pixelformat != V4L2_PIX_FMT_JPEG)
829 return -EINVAL;
830
831 f->fmt.pix.field = V4L2_FIELD_NONE;
832 f->fmt.pix.bytesperline = 0;
833 f->fmt.pix.sizeimage = cam->frame_size;
834 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
835 f->fmt.pix.priv = 0;
836
837 switch (cpia2_match_video_size(f->fmt.pix.width, f->fmt.pix.height)) {
838 case VIDEOSIZE_VGA:
839 f->fmt.pix.width = 640;
840 f->fmt.pix.height = 480;
841 break;
842 case VIDEOSIZE_CIF:
843 f->fmt.pix.width = 352;
844 f->fmt.pix.height = 288;
845 break;
846 case VIDEOSIZE_QVGA:
847 f->fmt.pix.width = 320;
848 f->fmt.pix.height = 240;
849 break;
850 case VIDEOSIZE_288_216:
851 f->fmt.pix.width = 288;
852 f->fmt.pix.height = 216;
853 break;
854 case VIDEOSIZE_256_192:
855 f->fmt.pix.width = 256;
856 f->fmt.pix.height = 192;
857 break;
858 case VIDEOSIZE_224_168:
859 f->fmt.pix.width = 224;
860 f->fmt.pix.height = 168;
861 break;
862 case VIDEOSIZE_192_144:
863 f->fmt.pix.width = 192;
864 f->fmt.pix.height = 144;
865 break;
866 case VIDEOSIZE_QCIF:
867 default:
868 f->fmt.pix.width = 176;
869 f->fmt.pix.height = 144;
870 break;
871 }
872
873 return 0;
874}
875
876/******************************************************************************
877 *
878 * ioctl_set_fmt
879 *
880 * V4L2 format set
881 *
882 *****************************************************************************/
883
884static int ioctl_set_fmt(void *arg,struct camera_data *cam, struct cpia2_fh *fh)
885{
886 struct v4l2_format *f = arg;
887 int err, frame;
888
889 err = ioctl_try_fmt(arg, cam);
890 if(err != 0)
891 return err;
892
893 /* Ensure that only this process can change the format. */
894 err = v4l2_prio_change(&cam->prio, &fh->prio, V4L2_PRIORITY_RECORD);
895 if(err != 0) {
896 return err;
897 }
898
899 cam->pixelformat = f->fmt.pix.pixelformat;
900
901 /* NOTE: This should be set to 1 for MJPEG, but some apps don't handle
902 * the missing Huffman table properly. */
903 cam->params.compression.inhibit_htables = 0;
904 /*f->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG;*/
905
906 /* we set the video window to something smaller or equal to what
907 * is requested by the user???
908 */
909 DBG("Requested width = %d, height = %d\n",
910 f->fmt.pix.width, f->fmt.pix.height);
911 if (f->fmt.pix.width != cam->vw.width ||
912 f->fmt.pix.height != cam->vw.height) {
913 cam->vw.width = f->fmt.pix.width;
914 cam->vw.height = f->fmt.pix.height;
915 cam->params.roi.width = f->fmt.pix.width;
916 cam->params.roi.height = f->fmt.pix.height;
917 cpia2_set_format(cam);
918 }
919
920 for (frame = 0; frame < cam->num_frames; ++frame) {
921 if (cam->buffers[frame].status == FRAME_READING)
922 if ((err = sync(cam, frame)) < 0)
923 return err;
924
925 cam->buffers[frame].status = FRAME_EMPTY;
926 }
927
928 return 0;
929}
930
931/******************************************************************************
932 *
933 * ioctl_get_fmt
934 *
935 * V4L2 format get
936 *
937 *****************************************************************************/
938
939static int ioctl_get_fmt(void *arg,struct camera_data *cam)
940{
941 struct v4l2_format *f = arg;
942
943 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
944 return -EINVAL;
945
946 f->fmt.pix.width = cam->vw.width;
947 f->fmt.pix.height = cam->vw.height;
948 f->fmt.pix.pixelformat = cam->pixelformat;
949 f->fmt.pix.field = V4L2_FIELD_NONE;
950 f->fmt.pix.bytesperline = 0;
951 f->fmt.pix.sizeimage = cam->frame_size;
952 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
953 f->fmt.pix.priv = 0;
954
955 return 0;
956}
957
958/******************************************************************************
959 *
960 * ioctl_cropcap
961 *
962 * V4L2 query cropping capabilities
963 * NOTE: cropping is currently disabled
964 *
965 *****************************************************************************/
966
967static int ioctl_cropcap(void *arg,struct camera_data *cam)
968{
969 struct v4l2_cropcap *c = arg;
970
971 if (c->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
972 return -EINVAL;
973
974 c->bounds.left = 0;
975 c->bounds.top = 0;
976 c->bounds.width = cam->vw.width;
977 c->bounds.height = cam->vw.height;
978 c->defrect.left = 0;
979 c->defrect.top = 0;
980 c->defrect.width = cam->vw.width;
981 c->defrect.height = cam->vw.height;
982 c->pixelaspect.numerator = 1;
983 c->pixelaspect.denominator = 1;
984
985 return 0;
986}
987
988/******************************************************************************
989 *
990 * ioctl_queryctrl
991 *
992 * V4L2 query possible control variables
993 *
994 *****************************************************************************/
995
996static int ioctl_queryctrl(void *arg,struct camera_data *cam)
997{
998 struct v4l2_queryctrl *c = arg;
999 int i;
1000
1001 for(i=0; i<NUM_CONTROLS; ++i) {
1002 if(c->id == controls[i].id) {
1003 memcpy(c, controls+i, sizeof(*c));
1004 break;
1005 }
1006 }
1007
1008 if(i == NUM_CONTROLS)
1009 return -EINVAL;
1010
1011 /* Some devices have additional limitations */
1012 switch(c->id) {
1013 case V4L2_CID_BRIGHTNESS:
1014 /***
1015 * Don't let the register be set to zero - bug in VP4
1016 * flash of full brightness
1017 ***/
1018 if (cam->params.pnp_id.device_type == DEVICE_STV_672)
1019 c->minimum = 1;
1020 break;
1021 case V4L2_CID_VFLIP:
1022 // VP5 Only
1023 if(cam->params.pnp_id.device_type == DEVICE_STV_672)
1024 c->flags |= V4L2_CTRL_FLAG_DISABLED;
1025 break;
1026 case CPIA2_CID_FRAMERATE:
1027 if(cam->params.pnp_id.device_type == DEVICE_STV_672 &&
1028 cam->params.version.sensor_flags==CPIA2_VP_SENSOR_FLAGS_500){
1029 // Maximum 15fps
1030 int i;
1031 for(i=0; i<c->maximum; ++i) {
1032 if(framerate_controls[i].value ==
1033 CPIA2_VP_FRAMERATE_15) {
1034 c->maximum = i;
1035 c->default_value = i;
1036 }
1037 }
1038 }
1039 break;
1040 case CPIA2_CID_FLICKER_MODE:
1041 // Flicker control only valid for 672.
1042 if(cam->params.pnp_id.device_type != DEVICE_STV_672)
1043 c->flags |= V4L2_CTRL_FLAG_DISABLED;
1044 break;
1045 case CPIA2_CID_LIGHTS:
1046 // Light control only valid for the QX5 Microscope.
1047 if(cam->params.pnp_id.product != 0x151)
1048 c->flags |= V4L2_CTRL_FLAG_DISABLED;
1049 break;
1050 default:
1051 break;
1052 }
1053
1054 return 0;
1055}
1056
1057/******************************************************************************
1058 *
1059 * ioctl_querymenu
1060 *
1061 * V4L2 query possible control variables
1062 *
1063 *****************************************************************************/
1064
1065static int ioctl_querymenu(void *arg,struct camera_data *cam)
1066{
1067 struct v4l2_querymenu *m = arg;
1068
1069 memset(m->name, 0, sizeof(m->name));
1070 m->reserved = 0;
1071
1072 switch(m->id) {
1073 case CPIA2_CID_FLICKER_MODE:
1074 if(m->index < 0 || m->index >= NUM_FLICKER_CONTROLS)
1075 return -EINVAL;
1076
1077 strcpy(m->name, flicker_controls[m->index].name);
1078 break;
1079 case CPIA2_CID_FRAMERATE:
1080 {
1081 int maximum = NUM_FRAMERATE_CONTROLS - 1;
1082 if(cam->params.pnp_id.device_type == DEVICE_STV_672 &&
1083 cam->params.version.sensor_flags==CPIA2_VP_SENSOR_FLAGS_500){
1084 // Maximum 15fps
1085 int i;
1086 for(i=0; i<maximum; ++i) {
1087 if(framerate_controls[i].value ==
1088 CPIA2_VP_FRAMERATE_15)
1089 maximum = i;
1090 }
1091 }
1092 if(m->index < 0 || m->index > maximum)
1093 return -EINVAL;
1094
1095 strcpy(m->name, framerate_controls[m->index].name);
1096 break;
1097 }
1098 case CPIA2_CID_LIGHTS:
1099 if(m->index < 0 || m->index >= NUM_LIGHTS_CONTROLS)
1100 return -EINVAL;
1101
1102 strcpy(m->name, lights_controls[m->index].name);
1103 break;
1104 default:
1105 return -EINVAL;
1106 }
1107
1108 return 0;
1109}
1110
1111/******************************************************************************
1112 *
1113 * ioctl_g_ctrl
1114 *
1115 * V4L2 get the value of a control variable
1116 *
1117 *****************************************************************************/
1118
1119static int ioctl_g_ctrl(void *arg,struct camera_data *cam)
1120{
1121 struct v4l2_control *c = arg;
1122
1123 switch(c->id) {
1124 case V4L2_CID_BRIGHTNESS:
1125 cpia2_do_command(cam, CPIA2_CMD_GET_VP_BRIGHTNESS,
1126 TRANSFER_READ, 0);
1127 c->value = cam->params.color_params.brightness;
1128 break;
1129 case V4L2_CID_CONTRAST:
1130 cpia2_do_command(cam, CPIA2_CMD_GET_CONTRAST,
1131 TRANSFER_READ, 0);
1132 c->value = cam->params.color_params.contrast;
1133 break;
1134 case V4L2_CID_SATURATION:
1135 cpia2_do_command(cam, CPIA2_CMD_GET_VP_SATURATION,
1136 TRANSFER_READ, 0);
1137 c->value = cam->params.color_params.saturation;
1138 break;
1139 case V4L2_CID_HFLIP:
1140 cpia2_do_command(cam, CPIA2_CMD_GET_USER_EFFECTS,
1141 TRANSFER_READ, 0);
1142 c->value = (cam->params.vp_params.user_effects &
1143 CPIA2_VP_USER_EFFECTS_MIRROR) != 0;
1144 break;
1145 case V4L2_CID_VFLIP:
1146 cpia2_do_command(cam, CPIA2_CMD_GET_USER_EFFECTS,
1147 TRANSFER_READ, 0);
1148 c->value = (cam->params.vp_params.user_effects &
1149 CPIA2_VP_USER_EFFECTS_FLIP) != 0;
1150 break;
1151 case CPIA2_CID_TARGET_KB:
1152 c->value = cam->params.vc_params.target_kb;
1153 break;
1154 case CPIA2_CID_GPIO:
1155 cpia2_do_command(cam, CPIA2_CMD_GET_VP_GPIO_DATA,
1156 TRANSFER_READ, 0);
1157 c->value = cam->params.vp_params.gpio_data;
1158 break;
1159 case CPIA2_CID_FLICKER_MODE:
1160 {
1161 int i, mode;
1162 cpia2_do_command(cam, CPIA2_CMD_GET_FLICKER_MODES,
1163 TRANSFER_READ, 0);
1164 if(cam->params.flicker_control.cam_register &
1165 CPIA2_VP_FLICKER_MODES_NEVER_FLICKER) {
1166 mode = NEVER_FLICKER;
1167 } else {
1168 if(cam->params.flicker_control.cam_register &
1169 CPIA2_VP_FLICKER_MODES_50HZ) {
1170 mode = FLICKER_50;
1171 } else {
1172 mode = FLICKER_60;
1173 }
1174 }
1175 for(i=0; i<NUM_FLICKER_CONTROLS; i++) {
1176 if(flicker_controls[i].value == mode) {
1177 c->value = i;
1178 break;
1179 }
1180 }
1181 if(i == NUM_FLICKER_CONTROLS)
1182 return -EINVAL;
1183 break;
1184 }
1185 case CPIA2_CID_FRAMERATE:
1186 {
1187 int maximum = NUM_FRAMERATE_CONTROLS - 1;
1188 int i;
1189 for(i=0; i<= maximum; i++) {
1190 if(cam->params.vp_params.frame_rate ==
1191 framerate_controls[i].value)
1192 break;
1193 }
1194 if(i > maximum)
1195 return -EINVAL;
1196 c->value = i;
1197 break;
1198 }
1199 case CPIA2_CID_USB_ALT:
1200 c->value = cam->params.camera_state.stream_mode;
1201 break;
1202 case CPIA2_CID_LIGHTS:
1203 {
1204 int i;
1205 cpia2_do_command(cam, CPIA2_CMD_GET_VP_GPIO_DATA,
1206 TRANSFER_READ, 0);
1207 for(i=0; i<NUM_LIGHTS_CONTROLS; i++) {
1208 if((cam->params.vp_params.gpio_data&GPIO_LIGHTS_MASK) ==
1209 lights_controls[i].value) {
1210 break;
1211 }
1212 }
1213 if(i == NUM_LIGHTS_CONTROLS)
1214 return -EINVAL;
1215 c->value = i;
1216 break;
1217 }
1218 case CPIA2_CID_RESET_CAMERA:
1219 return -EINVAL;
1220 default:
1221 return -EINVAL;
1222 }
1223
1224 DBG("Get control id:%d, value:%d\n", c->id, c->value);
1225
1226 return 0;
1227}
1228
1229/******************************************************************************
1230 *
1231 * ioctl_s_ctrl
1232 *
1233 * V4L2 set the value of a control variable
1234 *
1235 *****************************************************************************/
1236
1237static int ioctl_s_ctrl(void *arg,struct camera_data *cam)
1238{
1239 struct v4l2_control *c = arg;
1240 int i;
1241 int retval = 0;
1242
1243 DBG("Set control id:%d, value:%d\n", c->id, c->value);
1244
1245 /* Check that the value is in range */
1246 for(i=0; i<NUM_CONTROLS; i++) {
1247 if(c->id == controls[i].id) {
1248 if(c->value < controls[i].minimum ||
1249 c->value > controls[i].maximum) {
1250 return -EINVAL;
1251 }
1252 break;
1253 }
1254 }
1255 if(i == NUM_CONTROLS)
1256 return -EINVAL;
1257
1258 switch(c->id) {
1259 case V4L2_CID_BRIGHTNESS:
1260 cpia2_set_brightness(cam, c->value);
1261 break;
1262 case V4L2_CID_CONTRAST:
1263 cpia2_set_contrast(cam, c->value);
1264 break;
1265 case V4L2_CID_SATURATION:
1266 cpia2_set_saturation(cam, c->value);
1267 break;
1268 case V4L2_CID_HFLIP:
1269 cpia2_set_property_mirror(cam, c->value);
1270 break;
1271 case V4L2_CID_VFLIP:
1272 cpia2_set_property_flip(cam, c->value);
1273 break;
1274 case CPIA2_CID_TARGET_KB:
1275 retval = cpia2_set_target_kb(cam, c->value);
1276 break;
1277 case CPIA2_CID_GPIO:
1278 retval = cpia2_set_gpio(cam, c->value);
1279 break;
1280 case CPIA2_CID_FLICKER_MODE:
1281 retval = cpia2_set_flicker_mode(cam,
1282 flicker_controls[c->value].value);
1283 break;
1284 case CPIA2_CID_FRAMERATE:
1285 retval = cpia2_set_fps(cam, framerate_controls[c->value].value);
1286 break;
1287 case CPIA2_CID_USB_ALT:
1288 retval = cpia2_usb_change_streaming_alternate(cam, c->value);
1289 break;
1290 case CPIA2_CID_LIGHTS:
1291 retval = cpia2_set_gpio(cam, lights_controls[c->value].value);
1292 break;
1293 case CPIA2_CID_RESET_CAMERA:
1294 cpia2_usb_stream_pause(cam);
1295 cpia2_reset_camera(cam);
1296 cpia2_usb_stream_resume(cam);
1297 break;
1298 default:
1299 retval = -EINVAL;
1300 }
1301
1302 return retval;
1303}
1304
1305/******************************************************************************
1306 *
1307 * ioctl_g_jpegcomp
1308 *
1309 * V4L2 get the JPEG compression parameters
1310 *
1311 *****************************************************************************/
1312
1313static int ioctl_g_jpegcomp(void *arg,struct camera_data *cam)
1314{
1315 struct v4l2_jpegcompression *parms = arg;
1316
1317 memset(parms, 0, sizeof(*parms));
1318
1319 parms->quality = 80; // TODO: Can this be made meaningful?
1320
1321 parms->jpeg_markers = V4L2_JPEG_MARKER_DQT | V4L2_JPEG_MARKER_DRI;
1322 if(!cam->params.compression.inhibit_htables) {
1323 parms->jpeg_markers |= V4L2_JPEG_MARKER_DHT;
1324 }
1325
1326 parms->APPn = cam->APPn;
1327 parms->APP_len = cam->APP_len;
1328 if(cam->APP_len > 0) {
1329 memcpy(parms->APP_data, cam->APP_data, cam->APP_len);
1330 parms->jpeg_markers |= V4L2_JPEG_MARKER_APP;
1331 }
1332
1333 parms->COM_len = cam->COM_len;
1334 if(cam->COM_len > 0) {
1335 memcpy(parms->COM_data, cam->COM_data, cam->COM_len);
1336 parms->jpeg_markers |= JPEG_MARKER_COM;
1337 }
1338
1339 DBG("G_JPEGCOMP APP_len:%d COM_len:%d\n",
1340 parms->APP_len, parms->COM_len);
1341
1342 return 0;
1343}
1344
1345/******************************************************************************
1346 *
1347 * ioctl_s_jpegcomp
1348 *
1349 * V4L2 set the JPEG compression parameters
1350 * NOTE: quality and some jpeg_markers are ignored.
1351 *
1352 *****************************************************************************/
1353
1354static int ioctl_s_jpegcomp(void *arg,struct camera_data *cam)
1355{
1356 struct v4l2_jpegcompression *parms = arg;
1357
1358 DBG("S_JPEGCOMP APP_len:%d COM_len:%d\n",
1359 parms->APP_len, parms->COM_len);
1360
1361 cam->params.compression.inhibit_htables =
1362 !(parms->jpeg_markers & V4L2_JPEG_MARKER_DHT);
1363
1364 if(parms->APP_len != 0) {
1365 if(parms->APP_len > 0 &&
1366 parms->APP_len <= sizeof(cam->APP_data) &&
1367 parms->APPn >= 0 && parms->APPn <= 15) {
1368 cam->APPn = parms->APPn;
1369 cam->APP_len = parms->APP_len;
1370 memcpy(cam->APP_data, parms->APP_data, parms->APP_len);
1371 } else {
1372 LOG("Bad APPn Params n=%d len=%d\n",
1373 parms->APPn, parms->APP_len);
1374 return -EINVAL;
1375 }
1376 } else {
1377 cam->APP_len = 0;
1378 }
1379
1380 if(parms->COM_len != 0) {
1381 if(parms->COM_len > 0 &&
1382 parms->COM_len <= sizeof(cam->COM_data)) {
1383 cam->COM_len = parms->COM_len;
1384 memcpy(cam->COM_data, parms->COM_data, parms->COM_len);
1385 } else {
1386 LOG("Bad COM_len=%d\n", parms->COM_len);
1387 return -EINVAL;
1388 }
1389 }
1390
1391 return 0;
1392}
1393
1394/******************************************************************************
1395 *
1396 * ioctl_reqbufs
1397 *
1398 * V4L2 Initiate memory mapping.
1399 * NOTE: The user's request is ignored. For now the buffers are fixed.
1400 *
1401 *****************************************************************************/
1402
1403static int ioctl_reqbufs(void *arg,struct camera_data *cam)
1404{
1405 struct v4l2_requestbuffers *req = arg;
1406
1407 if(req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1408 req->memory != V4L2_MEMORY_MMAP)
1409 return -EINVAL;
1410
1411 DBG("REQBUFS requested:%d returning:%d\n", req->count, cam->num_frames);
1412 req->count = cam->num_frames;
1413 memset(&req->reserved, 0, sizeof(req->reserved));
1414
1415 return 0;
1416}
1417
1418/******************************************************************************
1419 *
1420 * ioctl_querybuf
1421 *
1422 * V4L2 Query memory buffer status.
1423 *
1424 *****************************************************************************/
1425
1426static int ioctl_querybuf(void *arg,struct camera_data *cam)
1427{
1428 struct v4l2_buffer *buf = arg;
1429
1430 if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1431 buf->index > cam->num_frames)
1432 return -EINVAL;
1433
1434 buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
1435 buf->length = cam->frame_size;
1436
1437 buf->memory = V4L2_MEMORY_MMAP;
1438
1439 if(cam->mmapped)
1440 buf->flags = V4L2_BUF_FLAG_MAPPED;
1441 else
1442 buf->flags = 0;
1443
1444 switch (cam->buffers[buf->index].status) {
1445 case FRAME_EMPTY:
1446 case FRAME_ERROR:
1447 case FRAME_READING:
1448 buf->bytesused = 0;
1449 buf->flags = V4L2_BUF_FLAG_QUEUED;
1450 break;
1451 case FRAME_READY:
1452 buf->bytesused = cam->buffers[buf->index].length;
1453 buf->timestamp = cam->buffers[buf->index].timestamp;
1454 buf->sequence = cam->buffers[buf->index].seq;
1455 buf->flags = V4L2_BUF_FLAG_DONE;
1456 break;
1457 }
1458
1459 DBG("QUERYBUF index:%d offset:%d flags:%d seq:%d bytesused:%d\n",
1460 buf->index, buf->m.offset, buf->flags, buf->sequence,
1461 buf->bytesused);
1462
1463 return 0;
1464}
1465
1466/******************************************************************************
1467 *
1468 * ioctl_qbuf
1469 *
1470 * V4L2 User is freeing buffer
1471 *
1472 *****************************************************************************/
1473
1474static int ioctl_qbuf(void *arg,struct camera_data *cam)
1475{
1476 struct v4l2_buffer *buf = arg;
1477
1478 if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1479 buf->memory != V4L2_MEMORY_MMAP ||
1480 buf->index > cam->num_frames)
1481 return -EINVAL;
1482
1483 DBG("QBUF #%d\n", buf->index);
1484
1485 if(cam->buffers[buf->index].status == FRAME_READY)
1486 cam->buffers[buf->index].status = FRAME_EMPTY;
1487
1488 return 0;
1489}
1490
1491/******************************************************************************
1492 *
1493 * find_earliest_filled_buffer
1494 *
1495 * Helper for ioctl_dqbuf. Find the next ready buffer.
1496 *
1497 *****************************************************************************/
1498
1499static int find_earliest_filled_buffer(struct camera_data *cam)
1500{
1501 int i;
1502 int found = -1;
1503 for (i=0; i<cam->num_frames; i++) {
1504 if(cam->buffers[i].status == FRAME_READY) {
1505 if(found < 0) {
1506 found = i;
1507 } else {
1508 /* find which buffer is earlier */
1509 struct timeval *tv1, *tv2;
1510 tv1 = &cam->buffers[i].timestamp;
1511 tv2 = &cam->buffers[found].timestamp;
1512 if(tv1->tv_sec < tv2->tv_sec ||
1513 (tv1->tv_sec == tv2->tv_sec &&
1514 tv1->tv_usec < tv2->tv_usec))
1515 found = i;
1516 }
1517 }
1518 }
1519 return found;
1520}
1521
1522/******************************************************************************
1523 *
1524 * ioctl_dqbuf
1525 *
1526 * V4L2 User is asking for a filled buffer.
1527 *
1528 *****************************************************************************/
1529
1530static int ioctl_dqbuf(void *arg,struct camera_data *cam, struct file *file)
1531{
1532 struct v4l2_buffer *buf = arg;
1533 int frame;
1534
1535 if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1536 buf->memory != V4L2_MEMORY_MMAP)
1537 return -EINVAL;
1538
1539 frame = find_earliest_filled_buffer(cam);
1540
1541 if(frame < 0 && file->f_flags&O_NONBLOCK)
1542 return -EAGAIN;
1543
1544 if(frame < 0) {
1545 /* Wait for a frame to become available */
1546 struct framebuf *cb=cam->curbuff;
1547 up(&cam->busy_lock);
1548 wait_event_interruptible(cam->wq_stream,
1549 !cam->present ||
1550 (cb=cam->curbuff)->status == FRAME_READY);
1551 down(&cam->busy_lock);
1552 if (signal_pending(current))
1553 return -ERESTARTSYS;
1554 if(!cam->present)
1555 return -ENOTTY;
1556 frame = cb->num;
1557 }
1558
1559
1560 buf->index = frame;
1561 buf->bytesused = cam->buffers[buf->index].length;
1562 buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE;
1563 buf->field = V4L2_FIELD_NONE;
1564 buf->timestamp = cam->buffers[buf->index].timestamp;
1565 buf->sequence = cam->buffers[buf->index].seq;
1566 buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
1567 buf->length = cam->frame_size;
1568 buf->input = 0;
1569 buf->reserved = 0;
1570 memset(&buf->timecode, 0, sizeof(buf->timecode));
1571
1572 DBG("DQBUF #%d status:%d seq:%d length:%d\n", buf->index,
1573 cam->buffers[buf->index].status, buf->sequence, buf->bytesused);
1574
1575 return 0;
1576}
1577
1578/******************************************************************************
1579 *
1580 * cpia2_ioctl
1581 *
1582 *****************************************************************************/
1583static int cpia2_do_ioctl(struct inode *inode, struct file *file,
1584 unsigned int ioctl_nr, void *arg)
1585{
1586 struct video_device *dev = video_devdata(file);
1587 struct camera_data *cam = video_get_drvdata(dev);
1588 int retval = 0;
1589
1590 if (!cam)
1591 return -ENOTTY;
1592
1593 /* make this _really_ smp-safe */
1594 if (down_interruptible(&cam->busy_lock))
1595 return -ERESTARTSYS;
1596
1597 if (!cam->present) {
1598 up(&cam->busy_lock);
1599 return -ENODEV;
1600 }
1601
1602 /* Priority check */
1603 switch (ioctl_nr) {
1604 case VIDIOCSWIN:
1605 case VIDIOCMCAPTURE:
1606 case VIDIOC_S_FMT:
1607 {
1608 struct cpia2_fh *fh = file->private_data;
1609 retval = v4l2_prio_check(&cam->prio, &fh->prio);
1610 if(retval) {
1611 up(&cam->busy_lock);
1612 return retval;
1613 }
1614 break;
1615 }
1616 case VIDIOCGMBUF:
1617 case VIDIOCSYNC:
1618 {
1619 struct cpia2_fh *fh = file->private_data;
1620 if(fh->prio != V4L2_PRIORITY_RECORD) {
1621 up(&cam->busy_lock);
1622 return -EBUSY;
1623 }
1624 break;
1625 }
1626 default:
1627 break;
1628 }
1629
1630 switch (ioctl_nr) {
1631 case VIDIOCGCAP: /* query capabilities */
1632 retval = ioctl_cap_query(arg, cam);
1633 break;
1634
1635 case VIDIOCGCHAN: /* get video source - we are a camera, nothing else */
1636 retval = ioctl_get_channel(arg);
1637 break;
1638 case VIDIOCSCHAN: /* set video source - we are a camera, nothing else */
1639 retval = ioctl_set_channel(arg);
1640 break;
1641 case VIDIOCGPICT: /* image properties */
1642 memcpy(arg, &cam->vp, sizeof(struct video_picture));
1643 break;
1644 case VIDIOCSPICT:
1645 retval = ioctl_set_image_prop(arg, cam);
1646 break;
1647 case VIDIOCGWIN: /* get/set capture window */
1648 memcpy(arg, &cam->vw, sizeof(struct video_window));
1649 break;
1650 case VIDIOCSWIN:
1651 retval = ioctl_set_window_size(arg, cam, file->private_data);
1652 break;
1653 case VIDIOCGMBUF: /* mmap interface */
1654 retval = ioctl_get_mbuf(arg, cam);
1655 break;
1656 case VIDIOCMCAPTURE:
1657 retval = ioctl_mcapture(arg, cam, file->private_data);
1658 break;
1659 case VIDIOCSYNC:
1660 retval = ioctl_sync(arg, cam);
1661 break;
1662 /* pointless to implement overlay with this camera */
1663 case VIDIOCCAPTURE:
1664 case VIDIOCGFBUF:
1665 case VIDIOCSFBUF:
1666 case VIDIOCKEY:
1667 retval = -EINVAL;
1668 break;
1669
1670 /* tuner interface - we have none */
1671 case VIDIOCGTUNER:
1672 case VIDIOCSTUNER:
1673 case VIDIOCGFREQ:
1674 case VIDIOCSFREQ:
1675 retval = -EINVAL;
1676 break;
1677
1678 /* audio interface - we have none */
1679 case VIDIOCGAUDIO:
1680 case VIDIOCSAUDIO:
1681 retval = -EINVAL;
1682 break;
1683
1684 /* CPIA2 extension to Video4Linux API */
1685 case CPIA2_IOC_SET_GPIO:
1686 retval = ioctl_set_gpio(arg, cam);
1687 break;
1688 case VIDIOC_QUERYCAP:
1689 retval = ioctl_querycap(arg,cam);
1690 break;
1691
1692 case VIDIOC_ENUMINPUT:
1693 case VIDIOC_G_INPUT:
1694 case VIDIOC_S_INPUT:
1695 retval = ioctl_input(ioctl_nr, arg,cam);
1696 break;
1697
1698 case VIDIOC_ENUM_FMT:
1699 retval = ioctl_enum_fmt(arg,cam);
1700 break;
1701 case VIDIOC_TRY_FMT:
1702 retval = ioctl_try_fmt(arg,cam);
1703 break;
1704 case VIDIOC_G_FMT:
1705 retval = ioctl_get_fmt(arg,cam);
1706 break;
1707 case VIDIOC_S_FMT:
1708 retval = ioctl_set_fmt(arg,cam,file->private_data);
1709 break;
1710
1711 case VIDIOC_CROPCAP:
1712 retval = ioctl_cropcap(arg,cam);
1713 break;
1714 case VIDIOC_G_CROP:
1715 case VIDIOC_S_CROP:
1716 // TODO: I think cropping can be implemented - SJB
1717 retval = -EINVAL;
1718 break;
1719
1720 case VIDIOC_QUERYCTRL:
1721 retval = ioctl_queryctrl(arg,cam);
1722 break;
1723 case VIDIOC_QUERYMENU:
1724 retval = ioctl_querymenu(arg,cam);
1725 break;
1726 case VIDIOC_G_CTRL:
1727 retval = ioctl_g_ctrl(arg,cam);
1728 break;
1729 case VIDIOC_S_CTRL:
1730 retval = ioctl_s_ctrl(arg,cam);
1731 break;
1732
1733 case VIDIOC_G_JPEGCOMP:
1734 retval = ioctl_g_jpegcomp(arg,cam);
1735 break;
1736 case VIDIOC_S_JPEGCOMP:
1737 retval = ioctl_s_jpegcomp(arg,cam);
1738 break;
1739
1740 case VIDIOC_G_PRIORITY:
1741 {
1742 struct cpia2_fh *fh = file->private_data;
1743 *(enum v4l2_priority*)arg = fh->prio;
1744 break;
1745 }
1746 case VIDIOC_S_PRIORITY:
1747 {
1748 struct cpia2_fh *fh = file->private_data;
1749 enum v4l2_priority prio;
1750 prio = *(enum v4l2_priority*)arg;
1751 if(cam->streaming &&
1752 prio != fh->prio &&
1753 fh->prio == V4L2_PRIORITY_RECORD) {
1754 /* Can't drop record priority while streaming */
1755 retval = -EBUSY;
1756 } else if(prio == V4L2_PRIORITY_RECORD &&
1757 prio != fh->prio &&
1758 v4l2_prio_max(&cam->prio) == V4L2_PRIORITY_RECORD) {
1759 /* Only one program can record at a time */
1760 retval = -EBUSY;
1761 } else {
1762 retval = v4l2_prio_change(&cam->prio, &fh->prio, prio);
1763 }
1764 break;
1765 }
1766
1767 case VIDIOC_REQBUFS:
1768 retval = ioctl_reqbufs(arg,cam);
1769 break;
1770 case VIDIOC_QUERYBUF:
1771 retval = ioctl_querybuf(arg,cam);
1772 break;
1773 case VIDIOC_QBUF:
1774 retval = ioctl_qbuf(arg,cam);
1775 break;
1776 case VIDIOC_DQBUF:
1777 retval = ioctl_dqbuf(arg,cam,file);
1778 break;
1779 case VIDIOC_STREAMON:
1780 {
1781 int type;
1782 DBG("VIDIOC_STREAMON, streaming=%d\n", cam->streaming);
1783 type = *(int*)arg;
1784 if(!cam->mmapped || type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1785 retval = -EINVAL;
1786
1787 if(!cam->streaming) {
1788 retval = cpia2_usb_stream_start(cam,
1789 cam->params.camera_state.stream_mode);
1790 } else {
1791 retval = -EINVAL;
1792 }
1793
1794 break;
1795 }
1796 case VIDIOC_STREAMOFF:
1797 {
1798 int type;
1799 DBG("VIDIOC_STREAMOFF, streaming=%d\n", cam->streaming);
1800 type = *(int*)arg;
1801 if(!cam->mmapped || type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1802 retval = -EINVAL;
1803
1804 if(cam->streaming) {
1805 retval = cpia2_usb_stream_stop(cam);
1806 } else {
1807 retval = -EINVAL;
1808 }
1809
1810 break;
1811 }
1812
1813 case VIDIOC_ENUMOUTPUT:
1814 case VIDIOC_G_OUTPUT:
1815 case VIDIOC_S_OUTPUT:
1816 case VIDIOC_G_MODULATOR:
1817 case VIDIOC_S_MODULATOR:
1818
1819 case VIDIOC_ENUMAUDIO:
1820 case VIDIOC_G_AUDIO:
1821 case VIDIOC_S_AUDIO:
1822
1823 case VIDIOC_ENUMAUDOUT:
1824 case VIDIOC_G_AUDOUT:
1825 case VIDIOC_S_AUDOUT:
1826
1827 case VIDIOC_ENUMSTD:
1828 case VIDIOC_QUERYSTD:
1829 case VIDIOC_G_STD:
1830 case VIDIOC_S_STD:
1831
1832 case VIDIOC_G_TUNER:
1833 case VIDIOC_S_TUNER:
1834 case VIDIOC_G_FREQUENCY:
1835 case VIDIOC_S_FREQUENCY:
1836
1837 case VIDIOC_OVERLAY:
1838 case VIDIOC_G_FBUF:
1839 case VIDIOC_S_FBUF:
1840
1841 case VIDIOC_G_PARM:
1842 case VIDIOC_S_PARM:
1843 retval = -EINVAL;
1844 break;
1845 default:
1846 retval = -ENOIOCTLCMD;
1847 break;
1848 }
1849
1850 up(&cam->busy_lock);
1851 return retval;
1852}
1853
1854static int cpia2_ioctl(struct inode *inode, struct file *file,
1855 unsigned int ioctl_nr, unsigned long iarg)
1856{
1857 return video_usercopy(inode, file, ioctl_nr, iarg, cpia2_do_ioctl);
1858}
1859
1860/******************************************************************************
1861 *
1862 * cpia2_mmap
1863 *
1864 *****************************************************************************/
1865static int cpia2_mmap(struct file *file, struct vm_area_struct *area)
1866{
1867 int retval;
1868 struct video_device *dev = video_devdata(file);
1869 struct camera_data *cam = video_get_drvdata(dev);
1870
1871 /* Priority check */
1872 struct cpia2_fh *fh = file->private_data;
1873 if(fh->prio != V4L2_PRIORITY_RECORD) {
1874 return -EBUSY;
1875 }
1876
1877 retval = cpia2_remap_buffer(cam, area);
1878
1879 if(!retval)
1880 fh->mmapped = 1;
1881 return retval;
1882}
1883
1884/******************************************************************************
1885 *
1886 * reset_camera_struct_v4l
1887 *
1888 * Sets all values to the defaults
1889 *****************************************************************************/
1890static void reset_camera_struct_v4l(struct camera_data *cam)
1891{
1892 /***
1893 * Fill in the v4l structures. video_cap is filled in inside the VIDIOCCAP
1894 * Ioctl. Here, just do the window and picture stucts.
1895 ***/
1896 cam->vp.palette = (u16) VIDEO_PALETTE_RGB24; /* Is this right? */
1897 cam->vp.brightness = (u16) cam->params.color_params.brightness * 256;
1898 cam->vp.colour = (u16) cam->params.color_params.saturation * 256;
1899 cam->vp.contrast = (u16) cam->params.color_params.contrast * 256;
1900
1901 cam->vw.x = 0;
1902 cam->vw.y = 0;
1903 cam->vw.width = cam->params.roi.width;
1904 cam->vw.height = cam->params.roi.height;
1905 cam->vw.flags = 0;
1906 cam->vw.clipcount = 0;
1907
1908 cam->frame_size = buffer_size;
1909 cam->num_frames = num_buffers;
1910
1911 /* FlickerModes */
1912 cam->params.flicker_control.flicker_mode_req = flicker_mode;
1913 cam->params.flicker_control.mains_frequency = flicker_freq;
1914
1915 /* streamMode */
1916 cam->params.camera_state.stream_mode = alternate;
1917
1918 cam->pixelformat = V4L2_PIX_FMT_JPEG;
1919 v4l2_prio_init(&cam->prio);
1920 return;
1921}
1922
1923/***
1924 * The v4l video device structure initialized for this device
1925 ***/
1926static struct file_operations fops_template = {
1927 .owner= THIS_MODULE,
1928 .open= cpia2_open,
1929 .release= cpia2_close,
1930 .read= cpia2_v4l_read,
1931 .poll= cpia2_v4l_poll,
1932 .ioctl= cpia2_ioctl,
1933 .llseek= no_llseek,
1934 .mmap= cpia2_mmap,
1935};
1936
1937static struct video_device cpia2_template = {
1938 /* I could not find any place for the old .initialize initializer?? */
1939 .owner= THIS_MODULE,
1940 .name= "CPiA2 Camera",
1941 .type= VID_TYPE_CAPTURE,
1942 .type2 = V4L2_CAP_VIDEO_CAPTURE |
1943 V4L2_CAP_STREAMING,
1944 .hardware= VID_HARDWARE_CPIA2,
1945 .minor= -1,
1946 .fops= &fops_template,
1947 .release= video_device_release,
1948};
1949
1950/******************************************************************************
1951 *
1952 * cpia2_register_camera
1953 *
1954 *****************************************************************************/
1955int cpia2_register_camera(struct camera_data *cam)
1956{
1957 cam->vdev = video_device_alloc();
1958 if(!cam->vdev)
1959 return -ENOMEM;
1960
1961 memcpy(cam->vdev, &cpia2_template, sizeof(cpia2_template));
1962 video_set_drvdata(cam->vdev, cam);
1963
1964 reset_camera_struct_v4l(cam);
1965
1966 /* register v4l device */
1967 if (video_register_device
1968 (cam->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
1969 ERR("video_register_device failed\n");
1970 video_device_release(cam->vdev);
1971 return -ENODEV;
1972 }
1973
1974 return 0;
1975}
1976
1977/******************************************************************************
1978 *
1979 * cpia2_unregister_camera
1980 *
1981 *****************************************************************************/
1982void cpia2_unregister_camera(struct camera_data *cam)
1983{
1984 if (!cam->open_count) {
1985 video_unregister_device(cam->vdev);
1986 } else {
1987 LOG("/dev/video%d removed while open, "
1988 "deferring video_unregister_device\n",
1989 cam->vdev->minor);
1990 }
1991}
1992
1993/******************************************************************************
1994 *
1995 * check_parameters
1996 *
1997 * Make sure that all user-supplied parameters are sensible
1998 *****************************************************************************/
1999static void __init check_parameters(void)
2000{
2001 if(buffer_size < PAGE_SIZE) {
2002 buffer_size = PAGE_SIZE;
2003 LOG("buffer_size too small, setting to %d\n", buffer_size);
2004 } else if(buffer_size > 1024*1024) {
2005 /* arbitrary upper limiit */
2006 buffer_size = 1024*1024;
2007 LOG("buffer_size ridiculously large, setting to %d\n",
2008 buffer_size);
2009 } else {
2010 buffer_size += PAGE_SIZE-1;
2011 buffer_size &= ~(PAGE_SIZE-1);
2012 }
2013
2014 if(num_buffers < 1) {
2015 num_buffers = 1;
2016 LOG("num_buffers too small, setting to %d\n", num_buffers);
2017 } else if(num_buffers > VIDEO_MAX_FRAME) {
2018 num_buffers = VIDEO_MAX_FRAME;
2019 LOG("num_buffers too large, setting to %d\n", num_buffers);
2020 }
2021
2022 if(alternate < USBIF_ISO_1 || alternate > USBIF_ISO_6) {
2023 alternate = DEFAULT_ALT;
2024 LOG("alternate specified is invalid, using %d\n", alternate);
2025 }
2026
2027 if (flicker_mode != NEVER_FLICKER && flicker_mode != ANTI_FLICKER_ON) {
2028 flicker_mode = NEVER_FLICKER;
2029 LOG("Flicker mode specified is invalid, using %d\n",
2030 flicker_mode);
2031 }
2032
2033 if (flicker_freq != FLICKER_50 && flicker_freq != FLICKER_60) {
2034 flicker_freq = FLICKER_60;
2035 LOG("Flicker mode specified is invalid, using %d\n",
2036 flicker_freq);
2037 }
2038
2039 if(video_nr < -1 || video_nr > 64) {
2040 video_nr = -1;
2041 LOG("invalid video_nr specified, must be -1 to 64\n");
2042 }
2043
2044 DBG("Using %d buffers, each %d bytes, alternate=%d\n",
2045 num_buffers, buffer_size, alternate);
2046}
2047
2048/************ Module Stuff ***************/
2049
2050
2051/******************************************************************************
2052 *
2053 * cpia2_init/module_init
2054 *
2055 *****************************************************************************/
2056static int __init cpia2_init(void)
2057{
2058 LOG("%s v%d.%d.%d\n",
2059 ABOUT, CPIA2_MAJ_VER, CPIA2_MIN_VER, CPIA2_PATCH_VER);
2060 check_parameters();
2061 cpia2_usb_init();
2062 return 0;
2063}
2064
2065
2066/******************************************************************************
2067 *
2068 * cpia2_exit/module_exit
2069 *
2070 *****************************************************************************/
2071static void __exit cpia2_exit(void)
2072{
2073 cpia2_usb_cleanup();
2074 schedule_timeout(2 * HZ);
2075}
2076
2077module_init(cpia2_init);
2078module_exit(cpia2_exit);
2079
diff --git a/drivers/media/video/cpia2/cpia2dev.h b/drivers/media/video/cpia2/cpia2dev.h
new file mode 100644
index 000000000000..d58097ce0d5e
--- /dev/null
+++ b/drivers/media/video/cpia2/cpia2dev.h
@@ -0,0 +1,50 @@
1/****************************************************************************
2 *
3 * Filename: cpia2dev.h
4 *
5 * Copyright 2001, STMicrolectronics, Inc.
6 *
7 * Contact: steve.miller@st.com
8 *
9 * Description:
10 * This file provides definitions for applications wanting to use the
11 * cpia2 driver beyond the generic v4l capabilities.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 ****************************************************************************/
28
29#ifndef CPIA2_DEV_HEADER
30#define CPIA2_DEV_HEADER
31
32#include <linux/videodev.h>
33
34/***
35 * The following defines are ioctl numbers based on video4linux private ioctls,
36 * which can range from 192 (BASE_VIDIOCPRIVATE) to 255. All of these take int
37 * args
38 */
39#define CPIA2_IOC_SET_GPIO _IOW('v', BASE_VIDIOCPRIVATE + 17, __u32)
40
41/* V4L2 driver specific controls */
42#define CPIA2_CID_TARGET_KB (V4L2_CID_PRIVATE_BASE+0)
43#define CPIA2_CID_GPIO (V4L2_CID_PRIVATE_BASE+1)
44#define CPIA2_CID_FLICKER_MODE (V4L2_CID_PRIVATE_BASE+2)
45#define CPIA2_CID_FRAMERATE (V4L2_CID_PRIVATE_BASE+3)
46#define CPIA2_CID_USB_ALT (V4L2_CID_PRIVATE_BASE+4)
47#define CPIA2_CID_LIGHTS (V4L2_CID_PRIVATE_BASE+5)
48#define CPIA2_CID_RESET_CAMERA (V4L2_CID_PRIVATE_BASE+6)
49
50#endif
diff --git a/drivers/media/video/cpia2/cpia2patch.h b/drivers/media/video/cpia2/cpia2patch.h
new file mode 100644
index 000000000000..7f085fbe76fb
--- /dev/null
+++ b/drivers/media/video/cpia2/cpia2patch.h
@@ -0,0 +1,233 @@
1/****************************************************************************
2 *
3 * Filename: cpia2patch.h
4 *
5 * Copyright 2001, STMicrolectronics, Inc.
6 *
7 * Contact: steve.miller@st.com
8 *
9 * Description:
10 * This file contains patch data for the CPiA2 (stv0672) VP4.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 ****************************************************************************/
27
28#ifndef CPIA2_PATCH_HEADER
29#define CPIA2_PATCH_HEADER
30
31typedef struct {
32 unsigned char reg;
33 unsigned char count;
34 const unsigned char *data;
35} cpia2_patch;
36
37static const unsigned char start_address_hi[1] = {
38 0x01
39};
40
41static const unsigned char start_address_lo[1] = {
42 0xBC
43};
44
45static const unsigned char patch_block0[64] = {
46 0xE3, 0x02, 0xE3, 0x03, 0xE3, 0x04, 0xE3, 0x05,
47 0xE3, 0x06, 0xE3, 0x07, 0x93, 0x44, 0x56, 0xD4,
48 0x93, 0x4E, 0x56, 0x51, 0x93, 0x4E, 0x51, 0xD6,
49 0x93, 0x4E, 0x4F, 0x54, 0x93, 0x4E, 0x92, 0x4F,
50 0x92, 0xA4, 0x93, 0x05, 0x92, 0xF4, 0x93, 0x1B,
51 0x92, 0x92, 0x91, 0xE6, 0x92, 0x36, 0x92, 0x74,
52 0x92, 0x4A, 0x92, 0x8C, 0x92, 0x8E, 0xC8, 0xD0,
53 0x0B, 0x42, 0x02, 0xA0, 0xCA, 0x92, 0x09, 0x02
54};
55
56static const unsigned char patch_block1[64] = {
57 0xC9, 0x10, 0x0A, 0x0A, 0x0A, 0x81, 0xE3, 0xB8,
58 0xE3, 0xB0, 0xE3, 0xA8, 0xE3, 0xA0, 0xE3, 0x98,
59 0xE3, 0x90, 0xE1, 0x00, 0xCF, 0xD7, 0x0A, 0x12,
60 0xCC, 0x95, 0x08, 0xB2, 0x0A, 0x18, 0xE1, 0x00,
61 0x01, 0xEE, 0x0C, 0x08, 0x4A, 0x12, 0xC8, 0x18,
62 0xF0, 0x9A, 0xC0, 0x22, 0xF3, 0x1C, 0x4A, 0x13,
63 0xF3, 0x14, 0xC8, 0xA0, 0xF2, 0x14, 0xF2, 0x1C,
64 0xEB, 0x13, 0xD3, 0xA2, 0x63, 0x16, 0x48, 0x9E
65};
66
67static const unsigned char patch_block2[64] = {
68 0xF0, 0x18, 0xA4, 0x03, 0xF3, 0x93, 0xC0, 0x58,
69 0xF7, 0x13, 0x51, 0x9C, 0xE9, 0x20, 0xCF, 0xEF,
70 0x63, 0xF9, 0x92, 0x2E, 0xD3, 0x5F, 0x63, 0xFA,
71 0x92, 0x2E, 0xD3, 0x67, 0x63, 0xFB, 0x92, 0x2E,
72 0xD3, 0x6F, 0xE9, 0x1A, 0x63, 0x16, 0x48, 0xA7,
73 0xF0, 0x20, 0xA4, 0x06, 0xF3, 0x94, 0xC0, 0x27,
74 0xF7, 0x14, 0xF5, 0x13, 0x51, 0x9D, 0xF6, 0x13,
75 0x63, 0x18, 0xC4, 0x20, 0xCB, 0xEF, 0x63, 0xFC
76};
77
78static const unsigned char patch_block3[64] = {
79 0x92, 0x2E, 0xD3, 0x77, 0x63, 0xFD, 0x92, 0x2E,
80 0xD3, 0x7F, 0x63, 0xFE, 0x92, 0x2E, 0xD3, 0x87,
81 0x63, 0xFF, 0x92, 0x2E, 0xD3, 0x8F, 0x64, 0x38,
82 0x92, 0x2E, 0xD3, 0x97, 0x64, 0x39, 0x92, 0x2E,
83 0xD3, 0x9F, 0xE1, 0x00, 0xF5, 0x3A, 0xF4, 0x3B,
84 0xF7, 0xBF, 0xF2, 0xBC, 0xF2, 0x3D, 0xE1, 0x00,
85 0x80, 0x87, 0x90, 0x80, 0x51, 0xD5, 0x02, 0x22,
86 0x02, 0x32, 0x4B, 0xD3, 0xF7, 0x11, 0x0B, 0xDA
87};
88
89static const unsigned char patch_block4[64] = {
90 0xE1, 0x00, 0x0E, 0x02, 0x02, 0x40, 0x0D, 0xB5,
91 0xE3, 0x02, 0x48, 0x55, 0xE5, 0x12, 0xA4, 0x01,
92 0xE8, 0x1B, 0xE3, 0x90, 0xF0, 0x18, 0xA4, 0x01,
93 0xE8, 0xBF, 0x8D, 0xB8, 0x4B, 0xD1, 0x4B, 0xD8,
94 0x0B, 0xCB, 0x0B, 0xC2, 0xE1, 0x00, 0xE3, 0x02,
95 0xE3, 0x03, 0x52, 0xD3, 0x60, 0x59, 0xE6, 0x93,
96 0x0D, 0x22, 0x52, 0xD4, 0xE6, 0x93, 0x0D, 0x2A,
97 0xE3, 0x98, 0xE3, 0x90, 0xE1, 0x00, 0x02, 0x5D
98};
99
100static const unsigned char patch_block5[64] = {
101 0x02, 0x63, 0xE3, 0x02, 0xC8, 0x12, 0x02, 0xCA,
102 0xC8, 0x52, 0x02, 0xC2, 0x82, 0x68, 0xE3, 0x02,
103 0xC8, 0x14, 0x02, 0xCA, 0xC8, 0x90, 0x02, 0xC2,
104 0x0A, 0xD0, 0xC9, 0x93, 0x0A, 0xDA, 0xCC, 0xD2,
105 0x0A, 0xE2, 0x63, 0x12, 0x02, 0xDA, 0x0A, 0x98,
106 0x0A, 0xA0, 0x0A, 0xA8, 0xE3, 0x90, 0xE1, 0x00,
107 0xE3, 0x02, 0x0A, 0xD0, 0xC9, 0x93, 0x0A, 0xDA,
108 0xCC, 0xD2, 0x0A, 0xE2, 0x63, 0x12, 0x02, 0xDA
109};
110
111static const unsigned char patch_block6[64] = {
112 0x0A, 0x98, 0x0A, 0xA0, 0x0A, 0xA8, 0x49, 0x91,
113 0xE5, 0x6A, 0xA4, 0x04, 0xC8, 0x12, 0x02, 0xCA,
114 0xC8, 0x52, 0x82, 0x89, 0xC8, 0x14, 0x02, 0xCA,
115 0xC8, 0x90, 0x02, 0xC2, 0xE3, 0x90, 0xE1, 0x00,
116 0x08, 0x60, 0xE1, 0x00, 0x48, 0x53, 0xE8, 0x97,
117 0x08, 0x5A, 0xE1, 0x00, 0xE3, 0x02, 0xE3, 0x03,
118 0x54, 0xD3, 0x60, 0x59, 0xE6, 0x93, 0x0D, 0x52,
119 0xE3, 0x98, 0xE3, 0x90, 0xE1, 0x00, 0x02, 0x9C
120};
121
122static const unsigned char patch_block7[64] = {
123 0xE3, 0x02, 0x55, 0x13, 0x93, 0x17, 0x55, 0x13,
124 0x93, 0x17, 0xE3, 0x90, 0xE1, 0x00, 0x75, 0x30,
125 0xE3, 0x02, 0xE3, 0x03, 0x55, 0x55, 0x60, 0x59,
126 0xE6, 0x93, 0x0D, 0xB2, 0xE3, 0x98, 0xE3, 0x90,
127 0xE1, 0x00, 0x02, 0xAE, 0xE7, 0x92, 0xE9, 0x18,
128 0xEA, 0x9A, 0xE8, 0x98, 0xE8, 0x10, 0xE8, 0x11,
129 0xE8, 0x51, 0xD2, 0xDA, 0xD2, 0xF3, 0xE8, 0x13,
130 0xD2, 0xFA, 0xE8, 0x50, 0xD2, 0xEA, 0xE8, 0xD0
131};
132
133static const unsigned char patch_block8[64] = {
134 0xE8, 0xD1, 0xD3, 0x0A, 0x03, 0x09, 0x48, 0x23,
135 0xE5, 0x2C, 0xA0, 0x03, 0x48, 0x24, 0xEA, 0x1C,
136 0x03, 0x08, 0xD2, 0xE3, 0xD3, 0x03, 0xD3, 0x13,
137 0xE1, 0x00, 0x02, 0xCB, 0x05, 0x93, 0x57, 0x93,
138 0xF0, 0x9A, 0xAC, 0x0B, 0xE3, 0x07, 0x92, 0xEA,
139 0xE2, 0x9F, 0xE5, 0x06, 0xE3, 0xB0, 0xA0, 0x02,
140 0xEB, 0x1E, 0x82, 0xD7, 0xEA, 0x1E, 0xE2, 0x3B,
141 0x85, 0x9B, 0xE9, 0x1E, 0xC8, 0x90, 0x85, 0x94
142};
143
144static const unsigned char patch_block9[64] = {
145 0x02, 0xDE, 0x05, 0x80, 0x57, 0x93, 0xF0, 0xBA,
146 0xAC, 0x06, 0x92, 0xEA, 0xE2, 0xBF, 0xE5, 0x06,
147 0xA0, 0x01, 0xEB, 0xBF, 0x85, 0x88, 0xE9, 0x3E,
148 0xC8, 0x90, 0x85, 0x81, 0xE9, 0x3E, 0xF0, 0xBA,
149 0xF3, 0x39, 0xF0, 0x3A, 0x60, 0x17, 0xF0, 0x3A,
150 0xC0, 0x90, 0xF0, 0xBA, 0xE1, 0x00, 0x00, 0x3F,
151 0xE3, 0x02, 0xE3, 0x03, 0x58, 0x10, 0x60, 0x59,
152 0xE6, 0x93, 0x0D, 0xA2, 0x58, 0x12, 0xE6, 0x93
153};
154
155static const unsigned char patch_block10[64] = {
156 0x0D, 0xAA, 0xE3, 0x98, 0xE3, 0x90, 0xE1, 0x00,
157 0x03, 0x01, 0xE1, 0x00, 0x03, 0x03, 0x9B, 0x7D,
158 0x8B, 0x8B, 0xE3, 0x02, 0xE3, 0x03, 0x58, 0x56,
159 0x60, 0x59, 0xE6, 0x93, 0x0D, 0xBA, 0xE3, 0x98,
160 0xE3, 0x90, 0xE1, 0x00, 0x03, 0x0F, 0x93, 0x11,
161 0xE1, 0x00, 0xE3, 0x02, 0x4A, 0x11, 0x0B, 0x42,
162 0x91, 0xAF, 0xE3, 0x90, 0xE1, 0x00, 0xF2, 0x91,
163 0xF0, 0x91, 0xA3, 0xFE, 0xE1, 0x00, 0x60, 0x92
164};
165
166static const unsigned char patch_block11[64] = {
167 0xC0, 0x5F, 0xF0, 0x13, 0xF0, 0x13, 0x59, 0x5B,
168 0xE2, 0x13, 0xF0, 0x11, 0x5A, 0x19, 0xE2, 0x13,
169 0xE1, 0x00, 0x00, 0x00, 0x03, 0x27, 0x68, 0x61,
170 0x76, 0x61, 0x6E, 0x61, 0x00, 0x06, 0x03, 0x2C,
171 0xE3, 0x02, 0xE3, 0x03, 0xE9, 0x38, 0x59, 0x15,
172 0x59, 0x5A, 0xF2, 0x9A, 0xBC, 0x0B, 0xA4, 0x0A,
173 0x59, 0x1E, 0xF3, 0x11, 0xF0, 0x1A, 0xE2, 0xBB,
174 0x59, 0x15, 0xF0, 0x11, 0x19, 0x2A, 0xE5, 0x02
175};
176
177static const unsigned char patch_block12[54] = {
178 0xA4, 0x01, 0xEB, 0xBF, 0xE3, 0x98, 0xE3, 0x90,
179 0xE1, 0x00, 0x03, 0x42, 0x19, 0x28, 0xE1, 0x00,
180 0xE9, 0x30, 0x60, 0x79, 0xE1, 0x00, 0xE3, 0x03,
181 0xE3, 0x07, 0x60, 0x79, 0x93, 0x4E, 0xE3, 0xB8,
182 0xE3, 0x98, 0xE1, 0x00, 0xE9, 0x1A, 0xF0, 0x1F,
183 0xE2, 0x33, 0xF0, 0x91, 0xE2, 0x92, 0xE0, 0x32,
184 0xF0, 0x31, 0xE1, 0x00, 0x00, 0x00
185};
186
187static const unsigned char do_call[1] = {
188 0x01
189};
190
191
192#define PATCH_DATA_SIZE 18
193
194static const cpia2_patch patch_data[PATCH_DATA_SIZE] = {
195 {0x0A, sizeof(start_address_hi), start_address_hi}
196 , // 0
197 {0x0B, sizeof(start_address_lo), start_address_lo}
198 , // 1
199 {0x0C, sizeof(patch_block0), patch_block0}
200 , // 2
201 {0x0C, sizeof(patch_block1), patch_block1}
202 , // 3
203 {0x0C, sizeof(patch_block2), patch_block2}
204 , // 4
205 {0x0C, sizeof(patch_block3), patch_block3}
206 , // 5
207 {0x0C, sizeof(patch_block4), patch_block4}
208 , // 6
209 {0x0C, sizeof(patch_block5), patch_block5}
210 , // 7
211 {0x0C, sizeof(patch_block6), patch_block6}
212 , // 8
213 {0x0C, sizeof(patch_block7), patch_block7}
214 , // 9
215 {0x0C, sizeof(patch_block8), patch_block8}
216 , // 10
217 {0x0C, sizeof(patch_block9), patch_block9}
218 , //11
219 {0x0C, sizeof(patch_block10), patch_block10}
220 , // 12
221 {0x0C, sizeof(patch_block11), patch_block11}
222 , // 13
223 {0x0C, sizeof(patch_block12), patch_block12}
224 , // 14
225 {0x0A, sizeof(start_address_hi), start_address_hi}
226 , // 15
227 {0x0B, sizeof(start_address_lo), start_address_lo}
228 , // 16
229 {0x0D, sizeof(do_call), do_call} //17
230};
231
232
233#endif
diff --git a/drivers/media/video/cx25840/Kconfig b/drivers/media/video/cx25840/Kconfig
new file mode 100644
index 000000000000..854264e42ec0
--- /dev/null
+++ b/drivers/media/video/cx25840/Kconfig
@@ -0,0 +1,9 @@
1config VIDEO_CX25840
2 tristate "Conexant CX2584x audio/video decoders"
3 depends on VIDEO_DEV && I2C && EXPERIMENTAL
4 select FW_LOADER
5 ---help---
6 Support for the Conexant CX2584x audio/video decoders.
7
8 To compile this driver as a module, choose M here: the
9 module will be called cx25840
diff --git a/drivers/media/video/cx25840/Makefile b/drivers/media/video/cx25840/Makefile
index 543ebacdc9d7..32a896c23d1e 100644
--- a/drivers/media/video/cx25840/Makefile
+++ b/drivers/media/video/cx25840/Makefile
@@ -1,6 +1,6 @@
1cx25840-objs := cx25840-core.o cx25840-audio.o cx25840-firmware.o \ 1cx25840-objs := cx25840-core.o cx25840-audio.o cx25840-firmware.o \
2 cx25840-vbi.o 2 cx25840-vbi.o
3 3
4obj-$(CONFIG_VIDEO_DECODER) += cx25840.o 4obj-$(CONFIG_VIDEO_CX25840) += cx25840.o
5 5
6EXTRA_CFLAGS += -I$(src)/.. 6EXTRA_CFLAGS += -I$(src)/..
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index 5588b9a5c430..8a257978056f 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -743,6 +743,7 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
743 743
744 memset(input, 0, sizeof(*input)); 744 memset(input, 0, sizeof(*input));
745 input->index = state->aud_input; 745 input->index = state->aud_input;
746 input->capability = V4L2_AUDCAP_STEREO;
746 break; 747 break;
747 } 748 }
748 749
@@ -753,7 +754,6 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
753 case VIDIOC_G_TUNER: 754 case VIDIOC_G_TUNER:
754 { 755 {
755 u8 mode = cx25840_read(client, 0x804); 756 u8 mode = cx25840_read(client, 0x804);
756 u8 pref = cx25840_read(client, 0x809) & 0xf;
757 u8 vpres = cx25840_read(client, 0x80a) & 0x10; 757 u8 vpres = cx25840_read(client, 0x80a) & 0x10;
758 int val = 0; 758 int val = 0;
759 759
@@ -773,44 +773,49 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
773 val |= V4L2_TUNER_SUB_MONO; 773 val |= V4L2_TUNER_SUB_MONO;
774 774
775 if (mode == 2 || mode == 4) 775 if (mode == 2 || mode == 4)
776 val |= V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 776 val = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
777 777
778 if (mode & 0x10) 778 if (mode & 0x10)
779 val |= V4L2_TUNER_SUB_SAP; 779 val |= V4L2_TUNER_SUB_SAP;
780 780
781 vt->rxsubchans = val; 781 vt->rxsubchans = val;
782 782 vt->audmode = state->audmode;
783 switch (pref) {
784 case 0:
785 vt->audmode = V4L2_TUNER_MODE_MONO;
786 break;
787 case 1:
788 case 2:
789 vt->audmode = V4L2_TUNER_MODE_LANG2;
790 break;
791 case 4:
792 default:
793 vt->audmode = V4L2_TUNER_MODE_STEREO;
794 }
795 break; 783 break;
796 } 784 }
797 785
798 case VIDIOC_S_TUNER: 786 case VIDIOC_S_TUNER:
787 if (state->radio)
788 break;
789
799 switch (vt->audmode) { 790 switch (vt->audmode) {
800 case V4L2_TUNER_MODE_MONO: 791 case V4L2_TUNER_MODE_MONO:
801 case V4L2_TUNER_MODE_LANG1: 792 /* mono -> mono
802 /* Force PREF_MODE to MONO */ 793 stereo -> mono
794 bilingual -> lang1 */
803 cx25840_and_or(client, 0x809, ~0xf, 0x00); 795 cx25840_and_or(client, 0x809, ~0xf, 0x00);
804 break; 796 break;
805 case V4L2_TUNER_MODE_STEREO: 797 case V4L2_TUNER_MODE_LANG1:
806 /* Force PREF_MODE to STEREO */ 798 /* mono -> mono
799 stereo -> stereo
800 bilingual -> lang1 */
807 cx25840_and_or(client, 0x809, ~0xf, 0x04); 801 cx25840_and_or(client, 0x809, ~0xf, 0x04);
808 break; 802 break;
803 case V4L2_TUNER_MODE_STEREO:
804 /* mono -> mono
805 stereo -> stereo
806 bilingual -> lang1/lang2 */
807 cx25840_and_or(client, 0x809, ~0xf, 0x07);
808 break;
809 case V4L2_TUNER_MODE_LANG2: 809 case V4L2_TUNER_MODE_LANG2:
810 /* Force PREF_MODE to LANG2 */ 810 /* mono -> mono
811 stereo ->stereo
812 bilingual -> lang2 */
811 cx25840_and_or(client, 0x809, ~0xf, 0x01); 813 cx25840_and_or(client, 0x809, ~0xf, 0x01);
812 break; 814 break;
815 default:
816 return -EINVAL;
813 } 817 }
818 state->audmode = vt->audmode;
814 break; 819 break;
815 820
816 case VIDIOC_G_FMT: 821 case VIDIOC_G_FMT:
@@ -891,6 +896,7 @@ static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
891 state->aud_input = CX25840_AUDIO8; 896 state->aud_input = CX25840_AUDIO8;
892 state->audclk_freq = 48000; 897 state->audclk_freq = 48000;
893 state->pvr150_workaround = 0; 898 state->pvr150_workaround = 0;
899 state->audmode = V4L2_TUNER_MODE_LANG1;
894 900
895 cx25840_initialize(client, 1); 901 cx25840_initialize(client, 1);
896 902
diff --git a/drivers/media/video/cx25840/cx25840-vbi.c b/drivers/media/video/cx25840/cx25840-vbi.c
index 04d879da7d63..e96fd1f1d6dc 100644
--- a/drivers/media/video/cx25840/cx25840-vbi.c
+++ b/drivers/media/video/cx25840/cx25840-vbi.c
@@ -151,7 +151,7 @@ int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg)
151 case VIDIOC_G_FMT: 151 case VIDIOC_G_FMT:
152 { 152 {
153 static u16 lcr2vbi[] = { 153 static u16 lcr2vbi[] = {
154 0, V4L2_SLICED_TELETEXT_B, 0, /* 1 */ 154 0, V4L2_SLICED_TELETEXT_PAL_B, 0, /* 1 */
155 0, V4L2_SLICED_WSS_625, 0, /* 4 */ 155 0, V4L2_SLICED_WSS_625, 0, /* 4 */
156 V4L2_SLICED_CAPTION_525, /* 6 */ 156 V4L2_SLICED_CAPTION_525, /* 6 */
157 0, 0, V4L2_SLICED_VPS, 0, 0, /* 9 */ 157 0, 0, V4L2_SLICED_VPS, 0, 0, /* 9 */
@@ -231,7 +231,7 @@ int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg)
231 for (i = 7; i <= 23; i++) { 231 for (i = 7; i <= 23; i++) {
232 for (x = 0; x <= 1; x++) { 232 for (x = 0; x <= 1; x++) {
233 switch (svbi->service_lines[1-x][i]) { 233 switch (svbi->service_lines[1-x][i]) {
234 case V4L2_SLICED_TELETEXT_B: 234 case V4L2_SLICED_TELETEXT_PAL_B:
235 lcr[i] |= 1 << (4 * x); 235 lcr[i] |= 1 << (4 * x);
236 break; 236 break;
237 case V4L2_SLICED_WSS_625: 237 case V4L2_SLICED_WSS_625:
@@ -282,7 +282,7 @@ int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg)
282 282
283 switch (id2) { 283 switch (id2) {
284 case 1: 284 case 1:
285 id2 = V4L2_SLICED_TELETEXT_B; 285 id2 = V4L2_SLICED_TELETEXT_PAL_B;
286 break; 286 break;
287 case 4: 287 case 4:
288 id2 = V4L2_SLICED_WSS_625; 288 id2 = V4L2_SLICED_WSS_625;
diff --git a/drivers/media/video/cx25840/cx25840.h b/drivers/media/video/cx25840/cx25840.h
index fd22f30dcc1b..dd70664d1dd9 100644
--- a/drivers/media/video/cx25840/cx25840.h
+++ b/drivers/media/video/cx25840/cx25840.h
@@ -78,6 +78,7 @@ struct cx25840_state {
78 enum cx25840_video_input vid_input; 78 enum cx25840_video_input vid_input;
79 enum cx25840_audio_input aud_input; 79 enum cx25840_audio_input aud_input;
80 u32 audclk_freq; 80 u32 audclk_freq;
81 int audmode;
81}; 82};
82 83
83/* ----------------------------------------------------------------------- */ 84/* ----------------------------------------------------------------------- */
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index 87d79df05336..e140996e6ee4 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -50,6 +50,7 @@ config VIDEO_CX88_DVB_ALL_FRONTENDS
50 depends on VIDEO_CX88_DVB 50 depends on VIDEO_CX88_DVB
51 select DVB_MT352 51 select DVB_MT352
52 select VIDEO_CX88_VP3054 52 select VIDEO_CX88_VP3054
53 select DVB_ZL10353
53 select DVB_OR51132 54 select DVB_OR51132
54 select DVB_CX22702 55 select DVB_CX22702
55 select DVB_LGDT330X 56 select DVB_LGDT330X
@@ -81,6 +82,16 @@ config VIDEO_CX88_VP3054
81 which also require support for the VP-3054 82 which also require support for the VP-3054
82 Secondary I2C bus, such at DNTV Live! DVB-T Pro. 83 Secondary I2C bus, such at DNTV Live! DVB-T Pro.
83 84
85config VIDEO_CX88_DVB_ZL10353
86 bool "Zarlink ZL10353 DVB-T Support"
87 default y
88 depends on VIDEO_CX88_DVB && !VIDEO_CX88_DVB_ALL_FRONTENDS
89 select DVB_ZL10353
90 ---help---
91 This adds DVB-T support for cards based on the
92 Connexant 2388x chip and the ZL10353 demodulator,
93 successor to the Zarlink MT352.
94
84config VIDEO_CX88_DVB_OR51132 95config VIDEO_CX88_DVB_OR51132
85 bool "OR51132 ATSC Support" 96 bool "OR51132 ATSC Support"
86 default y 97 default y
diff --git a/drivers/media/video/cx88/Makefile b/drivers/media/video/cx88/Makefile
index 2b902784facc..6482b9aa6a1f 100644
--- a/drivers/media/video/cx88/Makefile
+++ b/drivers/media/video/cx88/Makefile
@@ -17,6 +17,7 @@ extra-cflags-$(CONFIG_DVB_CX22702) += -DHAVE_CX22702=1
17extra-cflags-$(CONFIG_DVB_OR51132) += -DHAVE_OR51132=1 17extra-cflags-$(CONFIG_DVB_OR51132) += -DHAVE_OR51132=1
18extra-cflags-$(CONFIG_DVB_LGDT330X) += -DHAVE_LGDT330X=1 18extra-cflags-$(CONFIG_DVB_LGDT330X) += -DHAVE_LGDT330X=1
19extra-cflags-$(CONFIG_DVB_MT352) += -DHAVE_MT352=1 19extra-cflags-$(CONFIG_DVB_MT352) += -DHAVE_MT352=1
20extra-cflags-$(CONFIG_DVB_ZL10353) += -DHAVE_ZL10353=1
20extra-cflags-$(CONFIG_DVB_NXT200X) += -DHAVE_NXT200X=1 21extra-cflags-$(CONFIG_DVB_NXT200X) += -DHAVE_NXT200X=1
21extra-cflags-$(CONFIG_DVB_CX24123) += -DHAVE_CX24123=1 22extra-cflags-$(CONFIG_DVB_CX24123) += -DHAVE_CX24123=1
22extra-cflags-$(CONFIG_VIDEO_CX88_VP3054)+= -DHAVE_VP3054_I2C=1 23extra-cflags-$(CONFIG_VIDEO_CX88_VP3054)+= -DHAVE_VP3054_I2C=1
diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
index c841914c0244..3170b8f72c68 100644
--- a/drivers/media/video/cx88/cx88-alsa.c
+++ b/drivers/media/video/cx88/cx88-alsa.c
@@ -676,6 +676,11 @@ static int __devinit snd_cx88_create(struct snd_card *card,
676 chip = (snd_cx88_card_t *) card->private_data; 676 chip = (snd_cx88_card_t *) card->private_data;
677 677
678 core = cx88_core_get(pci); 678 core = cx88_core_get(pci);
679 if (NULL == core) {
680 err = -EINVAL;
681 kfree (chip);
682 return err;
683 }
679 684
680 if (!pci_dma_supported(pci,0xffffffff)) { 685 if (!pci_dma_supported(pci,0xffffffff)) {
681 dprintk(0, "%s/1: Oops: no 32bit PCI DMA ???\n",core->name); 686 dprintk(0, "%s/1: Oops: no 32bit PCI DMA ???\n",core->name);
@@ -692,11 +697,6 @@ static int __devinit snd_cx88_create(struct snd_card *card,
692 spin_lock_init(&chip->reg_lock); 697 spin_lock_init(&chip->reg_lock);
693 698
694 cx88_reset(core); 699 cx88_reset(core);
695 if (NULL == core) {
696 err = -EINVAL;
697 kfree (chip);
698 return err;
699 }
700 chip->core = core; 700 chip->core = core;
701 701
702 /* get irq */ 702 /* get irq */
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index 1bc999247fdc..c7042cf41231 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -184,17 +184,18 @@ struct cx88_board cx88_boards[] = {
184 .input = {{ 184 .input = {{
185 .type = CX88_VMUX_TELEVISION, 185 .type = CX88_VMUX_TELEVISION,
186 .vmux = 0, 186 .vmux = 0,
187 .gpio1 = 0x309f, 187 .gpio1 = 0xe09f,
188 },{ 188 },{
189 .type = CX88_VMUX_COMPOSITE1, 189 .type = CX88_VMUX_COMPOSITE1,
190 .vmux = 1, 190 .vmux = 1,
191 .gpio1 = 0x305f, 191 .gpio1 = 0xe05f,
192 },{ 192 },{
193 .type = CX88_VMUX_SVIDEO, 193 .type = CX88_VMUX_SVIDEO,
194 .vmux = 2, 194 .vmux = 2,
195 .gpio1 = 0x305f, 195 .gpio1 = 0xe05f,
196 }}, 196 }},
197 .radio = { 197 .radio = {
198 .gpio1 = 0xe0df,
198 .type = CX88_RADIO, 199 .type = CX88_RADIO,
199 }, 200 },
200 }, 201 },
@@ -322,19 +323,19 @@ struct cx88_board cx88_boards[] = {
322 .input = {{ 323 .input = {{
323 .type = CX88_VMUX_TELEVISION, 324 .type = CX88_VMUX_TELEVISION,
324 .vmux = 0, 325 .vmux = 0,
325 .gpio0 = 0xff00, 326 .gpio0 = 0xbff0,
326 },{ 327 },{
327 .type = CX88_VMUX_COMPOSITE1, 328 .type = CX88_VMUX_COMPOSITE1,
328 .vmux = 1, 329 .vmux = 1,
329 .gpio0 = 0xff03, 330 .gpio0 = 0xbff3,
330 },{ 331 },{
331 .type = CX88_VMUX_SVIDEO, 332 .type = CX88_VMUX_SVIDEO,
332 .vmux = 2, 333 .vmux = 2,
333 .gpio0 = 0xff03, 334 .gpio0 = 0xbff3,
334 }}, 335 }},
335 .radio = { 336 .radio = {
336 .type = CX88_RADIO, 337 .type = CX88_RADIO,
337 .gpio0 = 0xff00, 338 .gpio0 = 0xbff0,
338 }, 339 },
339 }, 340 },
340 [CX88_BOARD_ASUS_PVR_416] = { 341 [CX88_BOARD_ASUS_PVR_416] = {
@@ -1048,6 +1049,50 @@ struct cx88_board cx88_boards[] = {
1048 }}, 1049 }},
1049 .dvb = 1, 1050 .dvb = 1,
1050 }, 1051 },
1052 [CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT] = {
1053 /* FIXME: Standard video using the cx88 broadcast decoder is
1054 * working, but blackbird isn't working yet, audio is only
1055 * working correctly for television mode. S-Video and Composite
1056 * are working for video-only, so I have them disabled for now.
1057 */
1058 .name = "KWorld HardwareMpegTV XPert",
1059 .tuner_type = TUNER_PHILIPS_TDA8290,
1060 .radio_type = UNSET,
1061 .tuner_addr = ADDR_UNSET,
1062 .radio_addr = ADDR_UNSET,
1063 .input = {{
1064 .type = CX88_VMUX_TELEVISION,
1065 .vmux = 0,
1066 .gpio0 = 0x3de2,
1067 .gpio2 = 0x00ff,
1068 }},
1069 .radio = {
1070 .type = CX88_RADIO,
1071 .gpio0 = 0x3de6,
1072 .gpio2 = 0x00ff,
1073 },
1074 },
1075 [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID] = {
1076 .name = "DViCO FusionHDTV DVB-T Hybrid",
1077 .tuner_type = TUNER_THOMSON_FE6600,
1078 .radio_type = UNSET,
1079 .tuner_addr = ADDR_UNSET,
1080 .radio_addr = ADDR_UNSET,
1081 .input = {{
1082 .type = CX88_VMUX_TELEVISION,
1083 .vmux = 0,
1084 .gpio0 = 0x0000a75f,
1085 },{
1086 .type = CX88_VMUX_COMPOSITE1,
1087 .vmux = 1,
1088 .gpio0 = 0x0000a75b,
1089 },{
1090 .type = CX88_VMUX_SVIDEO,
1091 .vmux = 2,
1092 .gpio0 = 0x0000a75b,
1093 }},
1094 .dvb = 1,
1095 },
1051 1096
1052}; 1097};
1053const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards); 1098const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards);
@@ -1254,6 +1299,18 @@ struct cx88_subid cx88_subids[] = {
1254 .subdevice = 0xdb11, 1299 .subdevice = 0xdb11,
1255 .card = CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS, 1300 .card = CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS,
1256 /* Re-branded DViCO: UltraView DVB-T Plus */ 1301 /* Re-branded DViCO: UltraView DVB-T Plus */
1302 },{
1303 .subvendor = 0x17de,
1304 .subdevice = 0x0840,
1305 .card = CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT,
1306 },{
1307 .subvendor = 0x18ac,
1308 .subdevice = 0xdb40,
1309 .card = CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID,
1310 },{
1311 .subvendor = 0x18ac,
1312 .subdevice = 0xdb44,
1313 .card = CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID,
1257 }, 1314 },
1258}; 1315};
1259const unsigned int cx88_idcount = ARRAY_SIZE(cx88_subids); 1316const unsigned int cx88_idcount = ARRAY_SIZE(cx88_subids);
@@ -1373,6 +1430,40 @@ static void gdi_eeprom(struct cx88_core *core, u8 *eeprom_data)
1373} 1430}
1374 1431
1375/* ----------------------------------------------------------------------- */ 1432/* ----------------------------------------------------------------------- */
1433/* some DViCO specific stuff */
1434
1435static void dvico_fusionhdtv_hybrid_init(struct cx88_core *core)
1436{
1437 struct i2c_msg msg = { .addr = 0x45, .flags = 0 };
1438 int i, err;
1439 static u8 init_bufs[13][5] = {
1440 { 0x10, 0x00, 0x20, 0x01, 0x03 },
1441 { 0x10, 0x10, 0x01, 0x00, 0x21 },
1442 { 0x10, 0x10, 0x10, 0x00, 0xCA },
1443 { 0x10, 0x10, 0x12, 0x00, 0x08 },
1444 { 0x10, 0x10, 0x13, 0x00, 0x0A },
1445 { 0x10, 0x10, 0x16, 0x01, 0xC0 },
1446 { 0x10, 0x10, 0x22, 0x01, 0x3D },
1447 { 0x10, 0x10, 0x73, 0x01, 0x2E },
1448 { 0x10, 0x10, 0x72, 0x00, 0xC5 },
1449 { 0x10, 0x10, 0x71, 0x01, 0x97 },
1450 { 0x10, 0x10, 0x70, 0x00, 0x0F },
1451 { 0x10, 0x10, 0xB0, 0x00, 0x01 },
1452 { 0x03, 0x0C },
1453 };
1454
1455 for (i = 0; i < 13; i++) {
1456 msg.buf = init_bufs[i];
1457 msg.len = (i != 12 ? 5 : 2);
1458 err = i2c_transfer(&core->i2c_adap, &msg, 1);
1459 if (err != 1) {
1460 printk("dvico_fusionhdtv_hybrid_init buf %d failed (err = %d)!\n", i, err);
1461 return;
1462 }
1463 }
1464}
1465
1466/* ----------------------------------------------------------------------- */
1376 1467
1377void cx88_card_list(struct cx88_core *core, struct pci_dev *pci) 1468void cx88_card_list(struct cx88_core *core, struct pci_dev *pci)
1378{ 1469{
@@ -1438,11 +1529,15 @@ void cx88_card_setup(struct cx88_core *core)
1438 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1: 1529 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
1439 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS: 1530 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
1440 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL: 1531 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
1532 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID:
1441 /* GPIO0:0 is hooked to mt352 reset pin */ 1533 /* GPIO0:0 is hooked to mt352 reset pin */
1442 cx_set(MO_GP0_IO, 0x00000101); 1534 cx_set(MO_GP0_IO, 0x00000101);
1443 cx_clear(MO_GP0_IO, 0x00000001); 1535 cx_clear(MO_GP0_IO, 0x00000001);
1444 msleep(1); 1536 msleep(1);
1445 cx_set(MO_GP0_IO, 0x00000101); 1537 cx_set(MO_GP0_IO, 0x00000101);
1538 if (0 == core->i2c_rc &&
1539 core->board == CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID)
1540 dvico_fusionhdtv_hybrid_init(core);
1446 break; 1541 break;
1447 case CX88_BOARD_KWORLD_DVB_T: 1542 case CX88_BOARD_KWORLD_DVB_T:
1448 case CX88_BOARD_DNTV_LIVE_DVB_T: 1543 case CX88_BOARD_DNTV_LIVE_DVB_T:
@@ -1460,7 +1555,7 @@ void cx88_card_setup(struct cx88_core *core)
1460 if (0 == core->i2c_rc) { 1555 if (0 == core->i2c_rc) {
1461 /* enable tuner */ 1556 /* enable tuner */
1462 int i; 1557 int i;
1463 u8 buffer [] = { 0x10,0x12,0x13,0x04,0x16,0x00,0x14,0x04,0x017,0x00 }; 1558 static const u8 buffer [] = { 0x10,0x12,0x13,0x04,0x16,0x00,0x14,0x04,0x017,0x00 };
1464 core->i2c_client.addr = 0x0a; 1559 core->i2c_client.addr = 0x0a;
1465 1560
1466 for (i = 0; i < 5; i++) 1561 for (i = 0; i < 5; i++)
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 3720f24a25cf..c2cdbafdb77b 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -163,7 +163,7 @@ int cx88_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
163 163
164 /* save pointer to jmp instruction address */ 164 /* save pointer to jmp instruction address */
165 risc->jmp = rp; 165 risc->jmp = rp;
166 BUG_ON((risc->jmp - risc->cpu + 2) / 4 > risc->size); 166 BUG_ON((risc->jmp - risc->cpu + 2) * sizeof (*risc->cpu) > risc->size);
167 return 0; 167 return 0;
168} 168}
169 169
@@ -188,7 +188,7 @@ int cx88_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc,
188 188
189 /* save pointer to jmp instruction address */ 189 /* save pointer to jmp instruction address */
190 risc->jmp = rp; 190 risc->jmp = rp;
191 BUG_ON((risc->jmp - risc->cpu + 2) / 4 > risc->size); 191 BUG_ON((risc->jmp - risc->cpu + 2) * sizeof (*risc->cpu) > risc->size);
192 return 0; 192 return 0;
193} 193}
194 194
@@ -215,8 +215,7 @@ int cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
215void 215void
216cx88_free_buffer(struct pci_dev *pci, struct cx88_buffer *buf) 216cx88_free_buffer(struct pci_dev *pci, struct cx88_buffer *buf)
217{ 217{
218 if (in_interrupt()) 218 BUG_ON(in_interrupt());
219 BUG();
220 videobuf_waiton(&buf->vb,0,0); 219 videobuf_waiton(&buf->vb,0,0);
221 videobuf_dma_pci_unmap(pci, &buf->vb.dma); 220 videobuf_dma_pci_unmap(pci, &buf->vb.dma);
222 videobuf_dma_free(&buf->vb.dma); 221 videobuf_dma_free(&buf->vb.dma);
@@ -1061,7 +1060,7 @@ struct cx88_core* cx88_core_get(struct pci_dev *pci)
1061 core->pci_bus = pci->bus->number; 1060 core->pci_bus = pci->bus->number;
1062 core->pci_slot = PCI_SLOT(pci->devfn); 1061 core->pci_slot = PCI_SLOT(pci->devfn);
1063 core->pci_irqmask = 0x00fc00; 1062 core->pci_irqmask = 0x00fc00;
1064 init_MUTEX(&core->lock); 1063 mutex_init(&core->lock);
1065 1064
1066 core->nr = cx88_devcount++; 1065 core->nr = cx88_devcount++;
1067 sprintf(core->name,"cx88[%d]",core->nr); 1066 sprintf(core->name,"cx88[%d]",core->nr);
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index e48aa3f6e500..a9fc2695b157 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -40,6 +40,9 @@
40# include "cx88-vp3054-i2c.h" 40# include "cx88-vp3054-i2c.h"
41# endif 41# endif
42#endif 42#endif
43#ifdef HAVE_ZL10353
44# include "zl10353.h"
45#endif
43#ifdef HAVE_CX22702 46#ifdef HAVE_CX22702
44# include "cx22702.h" 47# include "cx22702.h"
45#endif 48#endif
@@ -111,6 +114,21 @@ static struct videobuf_queue_ops dvb_qops = {
111 114
112/* ------------------------------------------------------------------ */ 115/* ------------------------------------------------------------------ */
113 116
117#if defined(HAVE_MT352) || defined(HAVE_ZL10353)
118static int zarlink_pll_set(struct dvb_frontend *fe,
119 struct dvb_frontend_parameters *params,
120 u8 *pllbuf)
121{
122 struct cx8802_dev *dev = fe->dvb->priv;
123
124 pllbuf[0] = dev->core->pll_addr << 1;
125 dvb_pll_configure(dev->core->pll_desc, pllbuf + 1,
126 params->frequency,
127 params->u.ofdm.bandwidth);
128 return 0;
129}
130#endif
131
114#ifdef HAVE_MT352 132#ifdef HAVE_MT352
115static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe) 133static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
116{ 134{
@@ -176,35 +194,22 @@ static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
176 return 0; 194 return 0;
177} 195}
178 196
179static int mt352_pll_set(struct dvb_frontend* fe,
180 struct dvb_frontend_parameters* params,
181 u8* pllbuf)
182{
183 struct cx8802_dev *dev= fe->dvb->priv;
184
185 pllbuf[0] = dev->core->pll_addr << 1;
186 dvb_pll_configure(dev->core->pll_desc, pllbuf+1,
187 params->frequency,
188 params->u.ofdm.bandwidth);
189 return 0;
190}
191
192static struct mt352_config dvico_fusionhdtv = { 197static struct mt352_config dvico_fusionhdtv = {
193 .demod_address = 0x0F, 198 .demod_address = 0x0F,
194 .demod_init = dvico_fusionhdtv_demod_init, 199 .demod_init = dvico_fusionhdtv_demod_init,
195 .pll_set = mt352_pll_set, 200 .pll_set = zarlink_pll_set,
196}; 201};
197 202
198static struct mt352_config dntv_live_dvbt_config = { 203static struct mt352_config dntv_live_dvbt_config = {
199 .demod_address = 0x0f, 204 .demod_address = 0x0f,
200 .demod_init = dntv_live_dvbt_demod_init, 205 .demod_init = dntv_live_dvbt_demod_init,
201 .pll_set = mt352_pll_set, 206 .pll_set = zarlink_pll_set,
202}; 207};
203 208
204static struct mt352_config dvico_fusionhdtv_dual = { 209static struct mt352_config dvico_fusionhdtv_dual = {
205 .demod_address = 0x0F, 210 .demod_address = 0x0F,
206 .demod_init = dvico_dual_demod_init, 211 .demod_init = dvico_dual_demod_init,
207 .pll_set = mt352_pll_set, 212 .pll_set = zarlink_pll_set,
208}; 213};
209 214
210#ifdef HAVE_VP3054_I2C 215#ifdef HAVE_VP3054_I2C
@@ -294,6 +299,46 @@ static struct mt352_config dntv_live_dvbt_pro_config = {
294#endif 299#endif
295#endif 300#endif
296 301
302#ifdef HAVE_ZL10353
303static int dvico_hybrid_tune_pll(struct dvb_frontend *fe,
304 struct dvb_frontend_parameters *params,
305 u8 *pllbuf)
306{
307 struct cx8802_dev *dev= fe->dvb->priv;
308 struct i2c_msg msg =
309 { .addr = dev->core->pll_addr, .flags = 0,
310 .buf = pllbuf + 1, .len = 4 };
311 int err;
312
313 pllbuf[0] = dev->core->pll_addr << 1;
314 dvb_pll_configure(dev->core->pll_desc, pllbuf + 1,
315 params->frequency,
316 params->u.ofdm.bandwidth);
317
318 if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
319 printk(KERN_WARNING "cx88-dvb: %s error "
320 "(addr %02x <- %02x, err = %i)\n",
321 __FUNCTION__, pllbuf[0], pllbuf[1], err);
322 if (err < 0)
323 return err;
324 else
325 return -EREMOTEIO;
326 }
327
328 return 0;
329}
330
331static struct zl10353_config dvico_fusionhdtv_hybrid = {
332 .demod_address = 0x0F,
333 .pll_set = dvico_hybrid_tune_pll,
334};
335
336static struct zl10353_config dvico_fusionhdtv_plus_v1_1 = {
337 .demod_address = 0x0F,
338 .pll_set = zarlink_pll_set,
339};
340#endif
341
297#ifdef HAVE_CX22702 342#ifdef HAVE_CX22702
298static struct cx22702_config connexant_refboard_config = { 343static struct cx22702_config connexant_refboard_config = {
299 .demod_address = 0x43, 344 .demod_address = 0x43,
@@ -500,16 +545,27 @@ static int dvb_register(struct cx8802_dev *dev)
500 &dev->core->i2c_adap); 545 &dev->core->i2c_adap);
501 break; 546 break;
502#endif 547#endif
548#if defined(HAVE_MT352) || defined(HAVE_ZL10353)
549 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
550 dev->core->pll_addr = 0x60;
551 dev->core->pll_desc = &dvb_pll_thomson_dtt7579;
503#ifdef HAVE_MT352 552#ifdef HAVE_MT352
504 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
505 dev->core->pll_addr = 0x61;
506 dev->core->pll_desc = &dvb_pll_lg_z201;
507 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv, 553 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
508 &dev->core->i2c_adap); 554 &dev->core->i2c_adap);
555 if (dev->dvb.frontend != NULL)
556 break;
557#endif
558#ifdef HAVE_ZL10353
559 /* ZL10353 replaces MT352 on later cards */
560 dev->dvb.frontend = zl10353_attach(&dvico_fusionhdtv_plus_v1_1,
561 &dev->core->i2c_adap);
562#endif
509 break; 563 break;
510 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS: 564#endif /* HAVE_MT352 || HAVE_ZL10353 */
511 dev->core->pll_addr = 0x60; 565#ifdef HAVE_MT352
512 dev->core->pll_desc = &dvb_pll_thomson_dtt7579; 566 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
567 dev->core->pll_addr = 0x61;
568 dev->core->pll_desc = &dvb_pll_lg_z201;
513 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv, 569 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
514 &dev->core->i2c_adap); 570 &dev->core->i2c_adap);
515 break; 571 break;
@@ -540,6 +596,14 @@ static int dvb_register(struct cx8802_dev *dev)
540 &dev->core->i2c_adap); 596 &dev->core->i2c_adap);
541 break; 597 break;
542#endif 598#endif
599#ifdef HAVE_ZL10353
600 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID:
601 dev->core->pll_addr = 0x61;
602 dev->core->pll_desc = &dvb_pll_thomson_fe6600;
603 dev->dvb.frontend = zl10353_attach(&dvico_fusionhdtv_hybrid,
604 &dev->core->i2c_adap);
605 break;
606#endif
543#ifdef HAVE_OR51132 607#ifdef HAVE_OR51132
544 case CX88_BOARD_PCHDTV_HD3000: 608 case CX88_BOARD_PCHDTV_HD3000:
545 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000, 609 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000,
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index 165d948624a3..78a63b7dd380 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -34,337 +34,6 @@
34 34
35/* ---------------------------------------------------------------------- */ 35/* ---------------------------------------------------------------------- */
36 36
37/* DigitalNow DNTV Live DVB-T Remote */
38static IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t[IR_KEYTAB_SIZE] = {
39 [0x00] = KEY_ESC, /* 'go up a level?' */
40 /* Keys 0 to 9 */
41 [0x0a] = KEY_KP0,
42 [0x01] = KEY_KP1,
43 [0x02] = KEY_KP2,
44 [0x03] = KEY_KP3,
45 [0x04] = KEY_KP4,
46 [0x05] = KEY_KP5,
47 [0x06] = KEY_KP6,
48 [0x07] = KEY_KP7,
49 [0x08] = KEY_KP8,
50 [0x09] = KEY_KP9,
51
52 [0x0b] = KEY_TUNER, /* tv/fm */
53 [0x0c] = KEY_SEARCH, /* scan */
54 [0x0d] = KEY_STOP,
55 [0x0e] = KEY_PAUSE,
56 [0x0f] = KEY_LIST, /* source */
57
58 [0x10] = KEY_MUTE,
59 [0x11] = KEY_REWIND, /* backward << */
60 [0x12] = KEY_POWER,
61 [0x13] = KEY_S, /* snap */
62 [0x14] = KEY_AUDIO, /* stereo */
63 [0x15] = KEY_CLEAR, /* reset */
64 [0x16] = KEY_PLAY,
65 [0x17] = KEY_ENTER,
66 [0x18] = KEY_ZOOM, /* full screen */
67 [0x19] = KEY_FASTFORWARD, /* forward >> */
68 [0x1a] = KEY_CHANNELUP,
69 [0x1b] = KEY_VOLUMEUP,
70 [0x1c] = KEY_INFO, /* preview */
71 [0x1d] = KEY_RECORD, /* record */
72 [0x1e] = KEY_CHANNELDOWN,
73 [0x1f] = KEY_VOLUMEDOWN,
74};
75
76/* ---------------------------------------------------------------------- */
77
78/* IO-DATA BCTV7E Remote */
79static IR_KEYTAB_TYPE ir_codes_iodata_bctv7e[IR_KEYTAB_SIZE] = {
80 [0x40] = KEY_TV,
81 [0x20] = KEY_RADIO, /* FM */
82 [0x60] = KEY_EPG,
83 [0x00] = KEY_POWER,
84
85 /* Keys 0 to 9 */
86 [0x44] = KEY_KP0, /* 10 */
87 [0x50] = KEY_KP1,
88 [0x30] = KEY_KP2,
89 [0x70] = KEY_KP3,
90 [0x48] = KEY_KP4,
91 [0x28] = KEY_KP5,
92 [0x68] = KEY_KP6,
93 [0x58] = KEY_KP7,
94 [0x38] = KEY_KP8,
95 [0x78] = KEY_KP9,
96
97 [0x10] = KEY_L, /* Live */
98 [0x08] = KEY_T, /* Time Shift */
99
100 [0x18] = KEY_PLAYPAUSE, /* Play */
101
102 [0x24] = KEY_ENTER, /* 11 */
103 [0x64] = KEY_ESC, /* 12 */
104 [0x04] = KEY_M, /* Multi */
105
106 [0x54] = KEY_VIDEO,
107 [0x34] = KEY_CHANNELUP,
108 [0x74] = KEY_VOLUMEUP,
109 [0x14] = KEY_MUTE,
110
111 [0x4c] = KEY_S, /* SVIDEO */
112 [0x2c] = KEY_CHANNELDOWN,
113 [0x6c] = KEY_VOLUMEDOWN,
114 [0x0c] = KEY_ZOOM,
115
116 [0x5c] = KEY_PAUSE,
117 [0x3c] = KEY_C, /* || (red) */
118 [0x7c] = KEY_RECORD, /* recording */
119 [0x1c] = KEY_STOP,
120
121 [0x41] = KEY_REWIND, /* backward << */
122 [0x21] = KEY_PLAY,
123 [0x61] = KEY_FASTFORWARD, /* forward >> */
124 [0x01] = KEY_NEXT, /* skip >| */
125};
126
127/* ---------------------------------------------------------------------- */
128
129/* ADS Tech Instant TV DVB-T PCI Remote */
130static IR_KEYTAB_TYPE ir_codes_adstech_dvb_t_pci[IR_KEYTAB_SIZE] = {
131 /* Keys 0 to 9 */
132 [0x4d] = KEY_0,
133 [0x57] = KEY_1,
134 [0x4f] = KEY_2,
135 [0x53] = KEY_3,
136 [0x56] = KEY_4,
137 [0x4e] = KEY_5,
138 [0x5e] = KEY_6,
139 [0x54] = KEY_7,
140 [0x4c] = KEY_8,
141 [0x5c] = KEY_9,
142
143 [0x5b] = KEY_POWER,
144 [0x5f] = KEY_MUTE,
145 [0x55] = KEY_GOTO,
146 [0x5d] = KEY_SEARCH,
147 [0x17] = KEY_EPG, /* Guide */
148 [0x1f] = KEY_MENU,
149 [0x0f] = KEY_UP,
150 [0x46] = KEY_DOWN,
151 [0x16] = KEY_LEFT,
152 [0x1e] = KEY_RIGHT,
153 [0x0e] = KEY_SELECT, /* Enter */
154 [0x5a] = KEY_INFO,
155 [0x52] = KEY_EXIT,
156 [0x59] = KEY_PREVIOUS,
157 [0x51] = KEY_NEXT,
158 [0x58] = KEY_REWIND,
159 [0x50] = KEY_FORWARD,
160 [0x44] = KEY_PLAYPAUSE,
161 [0x07] = KEY_STOP,
162 [0x1b] = KEY_RECORD,
163 [0x13] = KEY_TUNER, /* Live */
164 [0x0a] = KEY_A,
165 [0x12] = KEY_B,
166 [0x03] = KEY_PROG1, /* 1 */
167 [0x01] = KEY_PROG2, /* 2 */
168 [0x00] = KEY_PROG3, /* 3 */
169 [0x06] = KEY_DVD,
170 [0x48] = KEY_AUX, /* Photo */
171 [0x40] = KEY_VIDEO,
172 [0x19] = KEY_AUDIO, /* Music */
173 [0x0b] = KEY_CHANNELUP,
174 [0x08] = KEY_CHANNELDOWN,
175 [0x15] = KEY_VOLUMEUP,
176 [0x1c] = KEY_VOLUMEDOWN,
177};
178
179/* ---------------------------------------------------------------------- */
180
181/* MSI TV@nywhere remote */
182static IR_KEYTAB_TYPE ir_codes_msi_tvanywhere[IR_KEYTAB_SIZE] = {
183 /* Keys 0 to 9 */
184 [0x00] = KEY_0,
185 [0x01] = KEY_1,
186 [0x02] = KEY_2,
187 [0x03] = KEY_3,
188 [0x04] = KEY_4,
189 [0x05] = KEY_5,
190 [0x06] = KEY_6,
191 [0x07] = KEY_7,
192 [0x08] = KEY_8,
193 [0x09] = KEY_9,
194
195 [0x0c] = KEY_MUTE,
196 [0x0f] = KEY_SCREEN, /* Full Screen */
197 [0x10] = KEY_F, /* Funtion */
198 [0x11] = KEY_T, /* Time shift */
199 [0x12] = KEY_POWER,
200 [0x13] = KEY_MEDIA, /* MTS */
201 [0x14] = KEY_SLOW,
202 [0x16] = KEY_REWIND, /* backward << */
203 [0x17] = KEY_ENTER, /* Return */
204 [0x18] = KEY_FASTFORWARD, /* forward >> */
205 [0x1a] = KEY_CHANNELUP,
206 [0x1b] = KEY_VOLUMEUP,
207 [0x1e] = KEY_CHANNELDOWN,
208 [0x1f] = KEY_VOLUMEDOWN,
209};
210
211/* ---------------------------------------------------------------------- */
212
213/* Cinergy 1400 DVB-T */
214static IR_KEYTAB_TYPE ir_codes_cinergy_1400[IR_KEYTAB_SIZE] = {
215 [0x01] = KEY_POWER,
216 [0x02] = KEY_1,
217 [0x03] = KEY_2,
218 [0x04] = KEY_3,
219 [0x05] = KEY_4,
220 [0x06] = KEY_5,
221 [0x07] = KEY_6,
222 [0x08] = KEY_7,
223 [0x09] = KEY_8,
224 [0x0a] = KEY_9,
225 [0x0c] = KEY_0,
226
227 [0x0b] = KEY_VIDEO,
228 [0x0d] = KEY_REFRESH,
229 [0x0e] = KEY_SELECT,
230 [0x0f] = KEY_EPG,
231 [0x10] = KEY_UP,
232 [0x11] = KEY_LEFT,
233 [0x12] = KEY_OK,
234 [0x13] = KEY_RIGHT,
235 [0x14] = KEY_DOWN,
236 [0x15] = KEY_TEXT,
237 [0x16] = KEY_INFO,
238
239 [0x17] = KEY_RED,
240 [0x18] = KEY_GREEN,
241 [0x19] = KEY_YELLOW,
242 [0x1a] = KEY_BLUE,
243
244 [0x1b] = KEY_CHANNELUP,
245 [0x1c] = KEY_VOLUMEUP,
246 [0x1d] = KEY_MUTE,
247 [0x1e] = KEY_VOLUMEDOWN,
248 [0x1f] = KEY_CHANNELDOWN,
249
250 [0x40] = KEY_PAUSE,
251 [0x4c] = KEY_PLAY,
252 [0x58] = KEY_RECORD,
253 [0x54] = KEY_PREVIOUS,
254 [0x48] = KEY_STOP,
255 [0x5c] = KEY_NEXT,
256};
257
258/* ---------------------------------------------------------------------- */
259
260/* AVERTV STUDIO 303 Remote */
261static IR_KEYTAB_TYPE ir_codes_avertv_303[IR_KEYTAB_SIZE] = {
262 [ 0x2a ] = KEY_KP1,
263 [ 0x32 ] = KEY_KP2,
264 [ 0x3a ] = KEY_KP3,
265 [ 0x4a ] = KEY_KP4,
266 [ 0x52 ] = KEY_KP5,
267 [ 0x5a ] = KEY_KP6,
268 [ 0x6a ] = KEY_KP7,
269 [ 0x72 ] = KEY_KP8,
270 [ 0x7a ] = KEY_KP9,
271 [ 0x0e ] = KEY_KP0,
272
273 [ 0x02 ] = KEY_POWER,
274 [ 0x22 ] = KEY_VIDEO,
275 [ 0x42 ] = KEY_AUDIO,
276 [ 0x62 ] = KEY_ZOOM,
277 [ 0x0a ] = KEY_TV,
278 [ 0x12 ] = KEY_CD,
279 [ 0x1a ] = KEY_TEXT,
280
281 [ 0x16 ] = KEY_SUBTITLE,
282 [ 0x1e ] = KEY_REWIND,
283 [ 0x06 ] = KEY_PRINT,
284
285 [ 0x2e ] = KEY_SEARCH,
286 [ 0x36 ] = KEY_SLEEP,
287 [ 0x3e ] = KEY_SHUFFLE,
288 [ 0x26 ] = KEY_MUTE,
289
290 [ 0x4e ] = KEY_RECORD,
291 [ 0x56 ] = KEY_PAUSE,
292 [ 0x5e ] = KEY_STOP,
293 [ 0x46 ] = KEY_PLAY,
294
295 [ 0x6e ] = KEY_RED,
296 [ 0x0b ] = KEY_GREEN,
297 [ 0x66 ] = KEY_YELLOW,
298 [ 0x03 ] = KEY_BLUE,
299
300 [ 0x76 ] = KEY_LEFT,
301 [ 0x7e ] = KEY_RIGHT,
302 [ 0x13 ] = KEY_DOWN,
303 [ 0x1b ] = KEY_UP,
304};
305
306/* ---------------------------------------------------------------------- */
307
308/* DigitalNow DNTV Live! DVB-T Pro Remote */
309static IR_KEYTAB_TYPE ir_codes_dntv_live_dvbt_pro[IR_KEYTAB_SIZE] = {
310 [ 0x16 ] = KEY_POWER,
311 [ 0x5b ] = KEY_HOME,
312
313 [ 0x55 ] = KEY_TV, /* live tv */
314 [ 0x58 ] = KEY_TUNER, /* digital Radio */
315 [ 0x5a ] = KEY_RADIO, /* FM radio */
316 [ 0x59 ] = KEY_DVD, /* dvd menu */
317 [ 0x03 ] = KEY_1,
318 [ 0x01 ] = KEY_2,
319 [ 0x06 ] = KEY_3,
320 [ 0x09 ] = KEY_4,
321 [ 0x1d ] = KEY_5,
322 [ 0x1f ] = KEY_6,
323 [ 0x0d ] = KEY_7,
324 [ 0x19 ] = KEY_8,
325 [ 0x1b ] = KEY_9,
326 [ 0x0c ] = KEY_CANCEL,
327 [ 0x15 ] = KEY_0,
328 [ 0x4a ] = KEY_CLEAR,
329 [ 0x13 ] = KEY_BACK,
330 [ 0x00 ] = KEY_TAB,
331 [ 0x4b ] = KEY_UP,
332 [ 0x4e ] = KEY_LEFT,
333 [ 0x4f ] = KEY_OK,
334 [ 0x52 ] = KEY_RIGHT,
335 [ 0x51 ] = KEY_DOWN,
336 [ 0x1e ] = KEY_VOLUMEUP,
337 [ 0x0a ] = KEY_VOLUMEDOWN,
338 [ 0x02 ] = KEY_CHANNELDOWN,
339 [ 0x05 ] = KEY_CHANNELUP,
340 [ 0x11 ] = KEY_RECORD,
341 [ 0x14 ] = KEY_PLAY,
342 [ 0x4c ] = KEY_PAUSE,
343 [ 0x1a ] = KEY_STOP,
344 [ 0x40 ] = KEY_REWIND,
345 [ 0x12 ] = KEY_FASTFORWARD,
346 [ 0x41 ] = KEY_PREVIOUSSONG, /* replay |< */
347 [ 0x42 ] = KEY_NEXTSONG, /* skip >| */
348 [ 0x54 ] = KEY_CAMERA, /* capture */
349 [ 0x50 ] = KEY_LANGUAGE, /* sap */
350 [ 0x47 ] = KEY_TV2, /* pip */
351 [ 0x4d ] = KEY_SCREEN,
352 [ 0x43 ] = KEY_SUBTITLE,
353 [ 0x10 ] = KEY_MUTE,
354 [ 0x49 ] = KEY_AUDIO, /* l/r */
355 [ 0x07 ] = KEY_SLEEP,
356 [ 0x08 ] = KEY_VIDEO, /* a/v */
357 [ 0x0e ] = KEY_PREVIOUS, /* recall */
358 [ 0x45 ] = KEY_ZOOM, /* zoom + */
359 [ 0x46 ] = KEY_ANGLE, /* zoom - */
360 [ 0x56 ] = KEY_RED,
361 [ 0x57 ] = KEY_GREEN,
362 [ 0x5c ] = KEY_YELLOW,
363 [ 0x5d ] = KEY_BLUE,
364};
365
366/* ---------------------------------------------------------------------- */
367
368struct cx88_IR { 37struct cx88_IR {
369 struct cx88_core *core; 38 struct cx88_core *core;
370 struct input_dev *input; 39 struct input_dev *input;
@@ -517,6 +186,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
517 ir->mask_keydown = 0x02; 186 ir->mask_keydown = 0x02;
518 ir->polling = 5; /* ms */ 187 ir->polling = 5; /* ms */
519 break; 188 break;
189 case CX88_BOARD_PROLINK_PLAYTVPVR:
520 case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO: 190 case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
521 ir_codes = ir_codes_pixelview; 191 ir_codes = ir_codes_pixelview;
522 ir->gpio_addr = MO_GP1_IO; 192 ir->gpio_addr = MO_GP1_IO;
@@ -524,6 +194,13 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
524 ir->mask_keyup = 0x80; 194 ir->mask_keyup = 0x80;
525 ir->polling = 1; /* ms */ 195 ir->polling = 1; /* ms */
526 break; 196 break;
197 case CX88_BOARD_KWORLD_LTV883:
198 ir_codes = ir_codes_pixelview;
199 ir->gpio_addr = MO_GP1_IO;
200 ir->mask_keycode = 0x1f;
201 ir->mask_keyup = 0x60;
202 ir->polling = 1; /* ms */
203 break;
527 case CX88_BOARD_ADSTECH_DVB_T_PCI: 204 case CX88_BOARD_ADSTECH_DVB_T_PCI:
528 ir_codes = ir_codes_adstech_dvb_t_pci; 205 ir_codes = ir_codes_adstech_dvb_t_pci;
529 ir->gpio_addr = MO_GP1_IO; 206 ir->gpio_addr = MO_GP1_IO;
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 073494ceab0f..6c97aa740d27 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -227,7 +227,7 @@ static struct cx88_ctrl cx8800_ctls[] = {
227 .minimum = 0x00, 227 .minimum = 0x00,
228 .maximum = 0xff, 228 .maximum = 0xff,
229 .step = 1, 229 .step = 1,
230 .default_value = 0, 230 .default_value = 0x7f,
231 .type = V4L2_CTRL_TYPE_INTEGER, 231 .type = V4L2_CTRL_TYPE_INTEGER,
232 }, 232 },
233 .off = 128, 233 .off = 128,
@@ -255,7 +255,7 @@ static struct cx88_ctrl cx8800_ctls[] = {
255 .minimum = 0, 255 .minimum = 0,
256 .maximum = 0xff, 256 .maximum = 0xff,
257 .step = 1, 257 .step = 1,
258 .default_value = 0, 258 .default_value = 0x7f,
259 .type = V4L2_CTRL_TYPE_INTEGER, 259 .type = V4L2_CTRL_TYPE_INTEGER,
260 }, 260 },
261 .off = 128, 261 .off = 128,
@@ -300,7 +300,7 @@ static struct cx88_ctrl cx8800_ctls[] = {
300 .minimum = 0, 300 .minimum = 0,
301 .maximum = 0x3f, 301 .maximum = 0x3f,
302 .step = 1, 302 .step = 1,
303 .default_value = 0x1f, 303 .default_value = 0x3f,
304 .type = V4L2_CTRL_TYPE_INTEGER, 304 .type = V4L2_CTRL_TYPE_INTEGER,
305 }, 305 },
306 .reg = AUD_VOL_CTL, 306 .reg = AUD_VOL_CTL,
@@ -336,17 +336,17 @@ static int res_get(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bi
336 return 1; 336 return 1;
337 337
338 /* is it free? */ 338 /* is it free? */
339 down(&core->lock); 339 mutex_lock(&core->lock);
340 if (dev->resources & bit) { 340 if (dev->resources & bit) {
341 /* no, someone else uses it */ 341 /* no, someone else uses it */
342 up(&core->lock); 342 mutex_unlock(&core->lock);
343 return 0; 343 return 0;
344 } 344 }
345 /* it's free, grab it */ 345 /* it's free, grab it */
346 fh->resources |= bit; 346 fh->resources |= bit;
347 dev->resources |= bit; 347 dev->resources |= bit;
348 dprintk(1,"res: get %d\n",bit); 348 dprintk(1,"res: get %d\n",bit);
349 up(&core->lock); 349 mutex_unlock(&core->lock);
350 return 1; 350 return 1;
351} 351}
352 352
@@ -366,14 +366,13 @@ static
366void res_free(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bits) 366void res_free(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bits)
367{ 367{
368 struct cx88_core *core = dev->core; 368 struct cx88_core *core = dev->core;
369 if ((fh->resources & bits) != bits) 369 BUG_ON((fh->resources & bits) != bits);
370 BUG();
371 370
372 down(&core->lock); 371 mutex_lock(&core->lock);
373 fh->resources &= ~bits; 372 fh->resources &= ~bits;
374 dev->resources &= ~bits; 373 dev->resources &= ~bits;
375 dprintk(1,"res: put %d\n",bits); 374 dprintk(1,"res: put %d\n",bits);
376 up(&core->lock); 375 mutex_unlock(&core->lock);
377} 376}
378 377
379/* ------------------------------------------------------------------ */ 378/* ------------------------------------------------------------------ */
@@ -909,7 +908,8 @@ static int get_control(struct cx88_core *core, struct v4l2_control *ctl)
909 value = c->sreg ? cx_sread(c->sreg) : cx_read(c->reg); 908 value = c->sreg ? cx_sread(c->sreg) : cx_read(c->reg);
910 switch (ctl->id) { 909 switch (ctl->id) {
911 case V4L2_CID_AUDIO_BALANCE: 910 case V4L2_CID_AUDIO_BALANCE:
912 ctl->value = (value & 0x40) ? (value & 0x3f) : (0x40 - (value & 0x3f)); 911 ctl->value = ((value & 0x7f) < 0x40) ? ((value & 0x7f) + 0x40)
912 : (0x7f - (value & 0x7f));
913 break; 913 break;
914 case V4L2_CID_AUDIO_VOLUME: 914 case V4L2_CID_AUDIO_VOLUME:
915 ctl->value = 0x3f - (value & 0x3f); 915 ctl->value = 0x3f - (value & 0x3f);
@@ -918,9 +918,9 @@ static int get_control(struct cx88_core *core, struct v4l2_control *ctl)
918 ctl->value = ((value + (c->off << c->shift)) & c->mask) >> c->shift; 918 ctl->value = ((value + (c->off << c->shift)) & c->mask) >> c->shift;
919 break; 919 break;
920 } 920 }
921 printk("get_control id=0x%X reg=0x%02x val=0x%02x (mask 0x%02x)%s\n", 921 dprintk(1,"get_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
922 ctl->id, c->reg, ctl->value, 922 ctl->id, c->v.name, ctl->value, c->reg,
923 c->mask, c->sreg ? " [shadowed]" : ""); 923 value,c->mask, c->sreg ? " [shadowed]" : "");
924 return 0; 924 return 0;
925} 925}
926 926
@@ -946,7 +946,7 @@ static int set_control(struct cx88_core *core, struct v4l2_control *ctl)
946 mask=c->mask; 946 mask=c->mask;
947 switch (ctl->id) { 947 switch (ctl->id) {
948 case V4L2_CID_AUDIO_BALANCE: 948 case V4L2_CID_AUDIO_BALANCE:
949 value = (ctl->value < 0x40) ? (0x40 - ctl->value) : ctl->value; 949 value = (ctl->value < 0x40) ? (0x7f - ctl->value) : (ctl->value - 0x40);
950 break; 950 break;
951 case V4L2_CID_AUDIO_VOLUME: 951 case V4L2_CID_AUDIO_VOLUME:
952 value = 0x3f - (ctl->value & 0x3f); 952 value = 0x3f - (ctl->value & 0x3f);
@@ -969,9 +969,9 @@ static int set_control(struct cx88_core *core, struct v4l2_control *ctl)
969 value = ((ctl->value - c->off) << c->shift) & c->mask; 969 value = ((ctl->value - c->off) << c->shift) & c->mask;
970 break; 970 break;
971 } 971 }
972 printk("set_control id=0x%X reg=0x%02x val=0x%02x (mask 0x%02x)%s\n", 972 dprintk(1,"set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
973 ctl->id, c->reg, value, 973 ctl->id, c->v.name, ctl->value, c->reg, value,
974 mask, c->sreg ? " [shadowed]" : ""); 974 mask, c->sreg ? " [shadowed]" : "");
975 if (c->sreg) { 975 if (c->sreg) {
976 cx_sandor(c->sreg, c->reg, mask, value); 976 cx_sandor(c->sreg, c->reg, mask, value);
977 } else { 977 } else {
@@ -987,8 +987,7 @@ static void init_controls(struct cx88_core *core)
987 987
988 for (i = 0; i < CX8800_CTLS; i++) { 988 for (i = 0; i < CX8800_CTLS; i++) {
989 ctrl.id=cx8800_ctls[i].v.id; 989 ctrl.id=cx8800_ctls[i].v.id;
990 ctrl.value=cx8800_ctls[i].v.default_value 990 ctrl.value=cx8800_ctls[i].v.default_value;
991 +cx8800_ctls[i].off;
992 set_control(core, &ctrl); 991 set_control(core, &ctrl);
993 } 992 }
994} 993}
@@ -1252,7 +1251,7 @@ int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
1252{ 1251{
1253 int err; 1252 int err;
1254 1253
1255 dprintk( 1, "CORE IOCTL: 0x%x\n", cmd ); 1254 dprintk(2, "CORE IOCTL: 0x%x\n", cmd );
1256 if (video_debug > 1) 1255 if (video_debug > 1)
1257 v4l_print_ioctl(core->name,cmd); 1256 v4l_print_ioctl(core->name,cmd);
1258 1257
@@ -1291,9 +1290,9 @@ int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
1291 if (i == ARRAY_SIZE(tvnorms)) 1290 if (i == ARRAY_SIZE(tvnorms))
1292 return -EINVAL; 1291 return -EINVAL;
1293 1292
1294 down(&core->lock); 1293 mutex_lock(&core->lock);
1295 cx88_set_tvnorm(core,&tvnorms[i]); 1294 cx88_set_tvnorm(core,&tvnorms[i]);
1296 up(&core->lock); 1295 mutex_unlock(&core->lock);
1297 return 0; 1296 return 0;
1298 } 1297 }
1299 1298
@@ -1343,10 +1342,10 @@ int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
1343 1342
1344 if (*i >= 4) 1343 if (*i >= 4)
1345 return -EINVAL; 1344 return -EINVAL;
1346 down(&core->lock); 1345 mutex_lock(&core->lock);
1347 cx88_newstation(core); 1346 cx88_newstation(core);
1348 video_mux(core,*i); 1347 video_mux(core,*i);
1349 up(&core->lock); 1348 mutex_unlock(&core->lock);
1350 return 0; 1349 return 0;
1351 } 1350 }
1352 1351
@@ -1438,7 +1437,7 @@ int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
1438 return -EINVAL; 1437 return -EINVAL;
1439 if (1 == radio && f->type != V4L2_TUNER_RADIO) 1438 if (1 == radio && f->type != V4L2_TUNER_RADIO)
1440 return -EINVAL; 1439 return -EINVAL;
1441 down(&core->lock); 1440 mutex_lock(&core->lock);
1442 core->freq = f->frequency; 1441 core->freq = f->frequency;
1443 cx88_newstation(core); 1442 cx88_newstation(core);
1444 cx88_call_i2c_clients(core,VIDIOC_S_FREQUENCY,f); 1443 cx88_call_i2c_clients(core,VIDIOC_S_FREQUENCY,f);
@@ -1447,7 +1446,7 @@ int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
1447 msleep (10); 1446 msleep (10);
1448 cx88_set_tvaudio(core); 1447 cx88_set_tvaudio(core);
1449 1448
1450 up(&core->lock); 1449 mutex_unlock(&core->lock);
1451 return 0; 1450 return 0;
1452 } 1451 }
1453 1452
@@ -1921,11 +1920,11 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1921 pci_set_drvdata(pci_dev,dev); 1920 pci_set_drvdata(pci_dev,dev);
1922 1921
1923 /* initial device configuration */ 1922 /* initial device configuration */
1924 down(&core->lock); 1923 mutex_lock(&core->lock);
1925 cx88_set_tvnorm(core,tvnorms); 1924 cx88_set_tvnorm(core,tvnorms);
1926 init_controls(core); 1925 init_controls(core);
1927 video_mux(core,0); 1926 video_mux(core,0);
1928 up(&core->lock); 1927 mutex_unlock(&core->lock);
1929 1928
1930 /* start tvaudio thread */ 1929 /* start tvaudio thread */
1931 if (core->tuner_type != TUNER_ABSENT) 1930 if (core->tuner_type != TUNER_ABSENT)
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index e9fd55b57fa6..cfa8668784b4 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -35,6 +35,7 @@
35#include "cx88-reg.h" 35#include "cx88-reg.h"
36 36
37#include <linux/version.h> 37#include <linux/version.h>
38#include <linux/mutex.h>
38#define CX88_VERSION_CODE KERNEL_VERSION(0,0,5) 39#define CX88_VERSION_CODE KERNEL_VERSION(0,0,5)
39 40
40#ifndef TRUE 41#ifndef TRUE
@@ -62,7 +63,7 @@
62/* need "shadow" registers for some write-only ones ... */ 63/* need "shadow" registers for some write-only ones ... */
63#define SHADOW_AUD_VOL_CTL 1 64#define SHADOW_AUD_VOL_CTL 1
64#define SHADOW_AUD_BAL_CTL 2 65#define SHADOW_AUD_BAL_CTL 2
65#define SHADOW_MAX 2 66#define SHADOW_MAX 3
66 67
67/* FM Radio deemphasis type */ 68/* FM Radio deemphasis type */
68enum cx88_deemph_type { 69enum cx88_deemph_type {
@@ -187,6 +188,8 @@ extern struct sram_channel cx88_sram_channels[];
187#define CX88_BOARD_DNTV_LIVE_DVB_T_PRO 42 188#define CX88_BOARD_DNTV_LIVE_DVB_T_PRO 42
188#define CX88_BOARD_KWORLD_DVB_T_CX22702 43 189#define CX88_BOARD_KWORLD_DVB_T_CX22702 43
189#define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL 44 190#define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL 44
191#define CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT 45
192#define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID 46
190 193
191enum cx88_itype { 194enum cx88_itype {
192 CX88_VMUX_COMPOSITE1 = 1, 195 CX88_VMUX_COMPOSITE1 = 1,
@@ -308,8 +311,7 @@ struct cx88_core {
308 /* IR remote control state */ 311 /* IR remote control state */
309 struct cx88_IR *ir; 312 struct cx88_IR *ir;
310 313
311 struct semaphore lock; 314 struct mutex lock;
312
313 /* various v4l controls */ 315 /* various v4l controls */
314 u32 freq; 316 u32 freq;
315 317
diff --git a/drivers/media/video/dpc7146.c b/drivers/media/video/dpc7146.c
index 2831bdd12057..0fcc935828f8 100644
--- a/drivers/media/video/dpc7146.c
+++ b/drivers/media/video/dpc7146.c
@@ -1,6 +1,6 @@
1/* 1/*
2 dpc7146.c - v4l2 driver for the dpc7146 demonstration board 2 dpc7146.c - v4l2 driver for the dpc7146 demonstration board
3 3
4 Copyright (C) 2000-2003 Michael Hunold <michael@mihu.de> 4 Copyright (C) 2000-2003 Michael Hunold <michael@mihu.de>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
@@ -52,7 +52,7 @@
52#define SAA711X_DECODED_BYTES_OF_TS_2 0x1C 52#define SAA711X_DECODED_BYTES_OF_TS_2 0x1C
53#define SAA711X_STATUS_BYTE 0x1F 53#define SAA711X_STATUS_BYTE 0x1F
54 54
55#define DPC_BOARD_CAN_DO_VBI(dev) (dev->revision != 0) 55#define DPC_BOARD_CAN_DO_VBI(dev) (dev->revision != 0)
56 56
57static int debug = 0; 57static int debug = 0;
58module_param(debug, int, 0); 58module_param(debug, int, 0);
@@ -81,16 +81,16 @@ struct dpc
81 struct video_device *video_dev; 81 struct video_device *video_dev;
82 struct video_device *vbi_dev; 82 struct video_device *vbi_dev;
83 83
84 struct i2c_adapter i2c_adapter; 84 struct i2c_adapter i2c_adapter;
85 struct i2c_client *saa7111a; 85 struct i2c_client *saa7111a;
86 86
87 int cur_input; /* current input */ 87 int cur_input; /* current input */
88}; 88};
89 89
90/* fixme: add vbi stuff here */ 90/* fixme: add vbi stuff here */
91static int dpc_probe(struct saa7146_dev* dev) 91static int dpc_probe(struct saa7146_dev* dev)
92{ 92{
93 struct dpc* dpc = NULL; 93 struct dpc* dpc = NULL;
94 struct i2c_client *client; 94 struct i2c_client *client;
95 struct list_head *item; 95 struct list_head *item;
96 96
@@ -118,20 +118,20 @@ static int dpc_probe(struct saa7146_dev* dev)
118 /* loop through all i2c-devices on the bus and look who is there */ 118 /* loop through all i2c-devices on the bus and look who is there */
119 list_for_each(item,&dpc->i2c_adapter.clients) { 119 list_for_each(item,&dpc->i2c_adapter.clients) {
120 client = list_entry(item, struct i2c_client, list); 120 client = list_entry(item, struct i2c_client, list);
121 if( I2C_SAA7111A == client->addr ) 121 if( I2C_SAA7111A == client->addr )
122 dpc->saa7111a = client; 122 dpc->saa7111a = client;
123 } 123 }
124 124
125 /* check if all devices are present */ 125 /* check if all devices are present */
126 if( 0 == dpc->saa7111a ) { 126 if( 0 == dpc->saa7111a ) {
127 DEB_D(("dpc_v4l2.o: dpc_attach failed for this device.\n")); 127 DEB_D(("dpc_v4l2.o: dpc_attach failed for this device.\n"));
128 i2c_del_adapter(&dpc->i2c_adapter); 128 i2c_del_adapter(&dpc->i2c_adapter);
129 kfree(dpc); 129 kfree(dpc);
130 return -ENODEV; 130 return -ENODEV;
131 } 131 }
132 132
133 /* all devices are present, probe was successful */ 133 /* all devices are present, probe was successful */
134 DEB_D(("dpc_v4l2.o: dpc_probe succeeded for this device.\n")); 134 DEB_D(("dpc_v4l2.o: dpc_probe succeeded for this device.\n"));
135 135
136 /* we store the pointer in our private data field */ 136 /* we store the pointer in our private data field */
137 dev->ext_priv = dpc; 137 dev->ext_priv = dpc;
@@ -182,7 +182,7 @@ static struct saa7146_ext_vv vv_data;
182static int dpc_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data *info) 182static int dpc_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
183{ 183{
184 struct dpc* dpc = (struct dpc*)dev->ext_priv; 184 struct dpc* dpc = (struct dpc*)dev->ext_priv;
185 185
186 DEB_D(("dpc_v4l2.o: dpc_attach called.\n")); 186 DEB_D(("dpc_v4l2.o: dpc_attach called.\n"));
187 187
188 /* checking for i2c-devices can be omitted here, because we 188 /* checking for i2c-devices can be omitted here, because we
@@ -193,7 +193,7 @@ static int dpc_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data
193 ERR(("cannot register capture v4l2 device. skipping.\n")); 193 ERR(("cannot register capture v4l2 device. skipping.\n"));
194 return -1; 194 return -1;
195 } 195 }
196 196
197 /* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/ 197 /* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/
198 if( 0 != DPC_BOARD_CAN_DO_VBI(dev)) { 198 if( 0 != DPC_BOARD_CAN_DO_VBI(dev)) {
199 if( 0 != saa7146_register_device(&dpc->vbi_dev, dev, "dpc", VFL_TYPE_VBI)) { 199 if( 0 != saa7146_register_device(&dpc->vbi_dev, dev, "dpc", VFL_TYPE_VBI)) {
@@ -205,18 +205,18 @@ static int dpc_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data
205 205
206 printk("dpc: found 'dpc7146 demonstration board'-%d.\n",dpc_num); 206 printk("dpc: found 'dpc7146 demonstration board'-%d.\n",dpc_num);
207 dpc_num++; 207 dpc_num++;
208 208
209 /* the rest */ 209 /* the rest */
210 dpc->cur_input = 0; 210 dpc->cur_input = 0;
211 dpc_init_done(dev); 211 dpc_init_done(dev);
212 212
213 return 0; 213 return 0;
214} 214}
215 215
216static int dpc_detach(struct saa7146_dev* dev) 216static int dpc_detach(struct saa7146_dev* dev)
217{ 217{
218 struct dpc* dpc = (struct dpc*)dev->ext_priv; 218 struct dpc* dpc = (struct dpc*)dev->ext_priv;
219 219
220 DEB_EE(("dev:%p\n",dev)); 220 DEB_EE(("dev:%p\n",dev));
221 221
222 i2c_release_client(dpc->saa7111a); 222 i2c_release_client(dpc->saa7111a);
@@ -238,25 +238,25 @@ static int dpc_detach(struct saa7146_dev* dev)
238int dpc_vbi_bypass(struct saa7146_dev* dev) 238int dpc_vbi_bypass(struct saa7146_dev* dev)
239{ 239{
240 struct dpc* dpc = (struct dpc*)dev->ext_priv; 240 struct dpc* dpc = (struct dpc*)dev->ext_priv;
241 241
242 int i = 1; 242 int i = 1;
243 243
244 /* switch bypass in saa7111a */ 244 /* switch bypass in saa7111a */
245 if ( 0 != dpc->saa7111a->driver->command(dpc->saa7111a,SAA711X_VBI_BYPASS, &i)) { 245 if ( 0 != dpc->saa7111a->driver->command(dpc->saa7111a,SAA711X_VBI_BYPASS, &i)) {
246 printk("dpc_v4l2.o: VBI_BYPASS: could not address saa7111a.\n"); 246 printk("dpc_v4l2.o: VBI_BYPASS: could not address saa7111a.\n");
247 return -1; 247 return -1;
248 } 248 }
249 249
250 return 0; 250 return 0;
251} 251}
252#endif 252#endif
253 253
254static int dpc_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg) 254static int dpc_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
255{ 255{
256 struct saa7146_dev *dev = fh->dev; 256 struct saa7146_dev *dev = fh->dev;
257 struct dpc* dpc = (struct dpc*)dev->ext_priv; 257 struct dpc* dpc = (struct dpc*)dev->ext_priv;
258/* 258/*
259 struct saa7146_vv *vv = dev->vv_data; 259 struct saa7146_vv *vv = dev->vv_data;
260*/ 260*/
261 switch(cmd) 261 switch(cmd)
262 { 262 {
@@ -264,11 +264,11 @@ static int dpc_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
264 { 264 {
265 struct v4l2_input *i = arg; 265 struct v4l2_input *i = arg;
266 DEB_EE(("VIDIOC_ENUMINPUT %d.\n",i->index)); 266 DEB_EE(("VIDIOC_ENUMINPUT %d.\n",i->index));
267 267
268 if( i->index < 0 || i->index >= DPC_INPUTS) { 268 if( i->index < 0 || i->index >= DPC_INPUTS) {
269 return -EINVAL; 269 return -EINVAL;
270 } 270 }
271 271
272 memcpy(i, &dpc_inputs[i->index], sizeof(struct v4l2_input)); 272 memcpy(i, &dpc_inputs[i->index], sizeof(struct v4l2_input));
273 273
274 DEB_D(("dpc_v4l2.o: v4l2_ioctl: VIDIOC_ENUMINPUT %d.\n",i->index)); 274 DEB_D(("dpc_v4l2.o: v4l2_ioctl: VIDIOC_ENUMINPUT %d.\n",i->index));
@@ -289,13 +289,13 @@ static int dpc_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
289 if (input < 0 || input >= DPC_INPUTS) { 289 if (input < 0 || input >= DPC_INPUTS) {
290 return -EINVAL; 290 return -EINVAL;
291 } 291 }
292 292
293 dpc->cur_input = input; 293 dpc->cur_input = input;
294 294
295 /* fixme: switch input here, switch audio, too! */ 295 /* fixme: switch input here, switch audio, too! */
296// saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source, input_port_selection[input].hps_sync); 296// saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source, input_port_selection[input].hps_sync);
297 printk("dpc_v4l2.o: VIDIOC_S_INPUT: fixme switch input.\n"); 297 printk("dpc_v4l2.o: VIDIOC_S_INPUT: fixme switch input.\n");
298 298
299 return 0; 299 return 0;
300 } 300 }
301 default: 301 default:
@@ -334,8 +334,8 @@ static struct saa7146_standard standard[] = {
334static struct saa7146_extension extension; 334static struct saa7146_extension extension;
335 335
336static struct saa7146_pci_extension_data dpc = { 336static struct saa7146_pci_extension_data dpc = {
337 .ext_priv = "Multimedia eXtension Board", 337 .ext_priv = "Multimedia eXtension Board",
338 .ext = &extension, 338 .ext = &extension,
339}; 339};
340 340
341static struct pci_device_id pci_tbl[] = { 341static struct pci_device_id pci_tbl[] = {
@@ -357,7 +357,7 @@ static struct saa7146_ext_vv vv_data = {
357 .capabilities = V4L2_CAP_VBI_CAPTURE, 357 .capabilities = V4L2_CAP_VBI_CAPTURE,
358 .stds = &standard[0], 358 .stds = &standard[0],
359 .num_stds = sizeof(standard)/sizeof(struct saa7146_standard), 359 .num_stds = sizeof(standard)/sizeof(struct saa7146_standard),
360 .std_callback = &std_callback, 360 .std_callback = &std_callback,
361 .ioctls = &ioctls[0], 361 .ioctls = &ioctls[0],
362 .ioctl = dpc_ioctl, 362 .ioctl = dpc_ioctl,
363}; 363};
@@ -365,7 +365,7 @@ static struct saa7146_ext_vv vv_data = {
365static struct saa7146_extension extension = { 365static struct saa7146_extension extension = {
366 .name = "dpc7146 demonstration board", 366 .name = "dpc7146 demonstration board",
367 .flags = SAA7146_USE_I2C_IRQ, 367 .flags = SAA7146_USE_I2C_IRQ,
368 368
369 .pci_tbl = &pci_tbl[0], 369 .pci_tbl = &pci_tbl[0],
370 .module = THIS_MODULE, 370 .module = THIS_MODULE,
371 371
@@ -375,7 +375,7 @@ static struct saa7146_extension extension = {
375 375
376 .irq_mask = 0, 376 .irq_mask = 0,
377 .irq_func = NULL, 377 .irq_func = NULL,
378}; 378};
379 379
380static int __init dpc_init_module(void) 380static int __init dpc_init_module(void)
381{ 381{
@@ -383,7 +383,7 @@ static int __init dpc_init_module(void)
383 DEB_S(("failed to register extension.\n")); 383 DEB_S(("failed to register extension.\n"));
384 return -ENODEV; 384 return -ENODEV;
385 } 385 }
386 386
387 return 0; 387 return 0;
388} 388}
389 389
diff --git a/drivers/media/video/em28xx/Kconfig b/drivers/media/video/em28xx/Kconfig
index 885fd0170086..5a793ae7cc23 100644
--- a/drivers/media/video/em28xx/Kconfig
+++ b/drivers/media/video/em28xx/Kconfig
@@ -5,6 +5,7 @@ config VIDEO_EM28XX
5 select VIDEO_TUNER 5 select VIDEO_TUNER
6 select VIDEO_TVEEPROM 6 select VIDEO_TVEEPROM
7 select VIDEO_IR 7 select VIDEO_IR
8 select VIDEO_SAA711X
8 ---help--- 9 ---help---
9 This is a video4linux driver for Empia 28xx based TV cards. 10 This is a video4linux driver for Empia 28xx based TV cards.
10 11
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index 58f7b4194a0d..4e22fc4889e1 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -72,6 +72,24 @@ struct em28xx_board em28xx_boards[] = {
72 .amux = 1, 72 .amux = 1,
73 }}, 73 }},
74 }, 74 },
75 [EM2820_BOARD_KWORLD_PVRTV2800RF] = {
76 .name = "Kworld PVR TV 2800 RF",
77 .is_em2800 = 0,
78 .vchannels = 2,
79 .norm = VIDEO_MODE_PAL,
80 .tda9887_conf = TDA9887_PRESENT,
81 .has_tuner = 1,
82 .decoder = EM28XX_SAA7113,
83 .input = {{
84 .type = EM28XX_VMUX_COMPOSITE1,
85 .vmux = 0,
86 .amux = 1,
87 },{
88 .type = EM28XX_VMUX_SVIDEO,
89 .vmux = 9,
90 .amux = 1,
91 }},
92 },
75 [EM2820_BOARD_TERRATEC_CINERGY_250] = { 93 [EM2820_BOARD_TERRATEC_CINERGY_250] = {
76 .name = "Terratec Cinergy 250 USB", 94 .name = "Terratec Cinergy 250 USB",
77 .vchannels = 3, 95 .vchannels = 3,
@@ -83,7 +101,7 @@ struct em28xx_board em28xx_boards[] = {
83 .input = {{ 101 .input = {{
84 .type = EM28XX_VMUX_TELEVISION, 102 .type = EM28XX_VMUX_TELEVISION,
85 .vmux = 2, 103 .vmux = 2,
86 .amux = 0, 104 .amux = 1,
87 },{ 105 },{
88 .type = EM28XX_VMUX_COMPOSITE1, 106 .type = EM28XX_VMUX_COMPOSITE1,
89 .vmux = 0, 107 .vmux = 0,
@@ -257,27 +275,51 @@ struct usb_device_id em28xx_id_table [] = {
257 { }, 275 { },
258}; 276};
259 277
278void em28xx_pre_card_setup(struct em28xx *dev)
279{
280 /* request some modules */
281 switch(dev->model){
282 case EM2880_BOARD_TERRATEC_PRODIGY_XS:
283 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
284 case EM2880_BOARD_TERRATEC_HYBRID_XS:
285 {
286 em28xx_write_regs_req(dev, 0x00, 0x08, "\x7d", 1); // reset through GPIO?
287 break;
288 }
289 }
290}
291
260void em28xx_card_setup(struct em28xx *dev) 292void em28xx_card_setup(struct em28xx *dev)
261{ 293{
262 /* request some modules */ 294 /* request some modules */
263 if (dev->model == EM2820_BOARD_HAUPPAUGE_WINTV_USB_2) { 295 switch(dev->model){
264 struct tveeprom tv; 296 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
297 {
298 struct tveeprom tv;
265#ifdef CONFIG_MODULES 299#ifdef CONFIG_MODULES
266 request_module("tveeprom"); 300 request_module("tveeprom");
267 request_module("ir-kbd-i2c"); 301 request_module("ir-kbd-i2c");
268 request_module("msp3400"); 302 request_module("msp3400");
269#endif 303#endif
270 /* Call first TVeeprom */ 304 /* Call first TVeeprom */
305
306 dev->i2c_client.addr = 0xa0 >> 1;
307 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata);
271 308
272 dev->i2c_client.addr = 0xa0 >> 1; 309 dev->tuner_type= tv.tuner_type;
273 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata); 310 if (tv.audio_processor == AUDIO_CHIP_MSP34XX) {
311 dev->i2s_speed=2048000;
312 dev->has_msp34xx=1;
313 } else
314 dev->has_msp34xx=0;
315 break;
316 }
317 case EM2820_BOARD_KWORLD_PVRTV2800RF:
318 {
319 em28xx_write_regs_req(dev,0x00,0x08, "\xf9", 1); // GPIO enables sound on KWORLD PVR TV 2800RF
320 break;
321 }
274 322
275 dev->tuner_type= tv.tuner_type;
276 if (tv.audio_processor == AUDIO_CHIP_MSP34XX) {
277 dev->i2s_speed=2048000;
278 dev->has_msp34xx=1;
279 } else
280 dev->has_msp34xx=0;
281 } 323 }
282} 324}
283 325
diff --git a/drivers/media/video/em28xx/em28xx-i2c.c b/drivers/media/video/em28xx/em28xx-i2c.c
index 6ca8631bc36d..5b6cece37aee 100644
--- a/drivers/media/video/em28xx/em28xx-i2c.c
+++ b/drivers/media/video/em28xx/em28xx-i2c.c
@@ -420,7 +420,6 @@ static int em28xx_set_tuner(int check_eeprom, struct i2c_client *client)
420 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; 420 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
421 tun_setup.type = dev->tuner_type; 421 tun_setup.type = dev->tuner_type;
422 tun_setup.addr = dev->tuner_addr; 422 tun_setup.addr = dev->tuner_addr;
423
424 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup); 423 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
425 } 424 }
426 425
diff --git a/drivers/media/video/em28xx/em28xx-input.c b/drivers/media/video/em28xx/em28xx-input.c
index 30dfa5370c73..31e89e4f18be 100644
--- a/drivers/media/video/em28xx/em28xx-input.c
+++ b/drivers/media/video/em28xx/em28xx-input.c
@@ -43,91 +43,6 @@ MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
43#define dprintk(fmt, arg...) if (ir_debug) \ 43#define dprintk(fmt, arg...) if (ir_debug) \
44 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg) 44 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
45 45
46/* ---------------------------------------------------------------------- */
47
48static IR_KEYTAB_TYPE ir_codes_em_terratec[IR_KEYTAB_SIZE] = {
49 [ 0x01 ] = KEY_CHANNEL,
50 [ 0x02 ] = KEY_SELECT,
51 [ 0x03 ] = KEY_MUTE,
52 [ 0x04 ] = KEY_POWER,
53 [ 0x05 ] = KEY_KP1,
54 [ 0x06 ] = KEY_KP2,
55 [ 0x07 ] = KEY_KP3,
56 [ 0x08 ] = KEY_CHANNELUP,
57 [ 0x09 ] = KEY_KP4,
58 [ 0x0a ] = KEY_KP5,
59 [ 0x0b ] = KEY_KP6,
60 [ 0x0c ] = KEY_CHANNELDOWN,
61 [ 0x0d ] = KEY_KP7,
62 [ 0x0e ] = KEY_KP8,
63 [ 0x0f ] = KEY_KP9,
64 [ 0x10 ] = KEY_VOLUMEUP,
65 [ 0x11 ] = KEY_KP0,
66 [ 0x12 ] = KEY_MENU,
67 [ 0x13 ] = KEY_PRINT,
68 [ 0x14 ] = KEY_VOLUMEDOWN,
69 [ 0x16 ] = KEY_PAUSE,
70 [ 0x18 ] = KEY_RECORD,
71 [ 0x19 ] = KEY_REWIND,
72 [ 0x1a ] = KEY_PLAY,
73 [ 0x1b ] = KEY_FORWARD,
74 [ 0x1c ] = KEY_BACKSPACE,
75 [ 0x1e ] = KEY_STOP,
76 [ 0x40 ] = KEY_ZOOM,
77};
78
79static IR_KEYTAB_TYPE ir_codes_em_pinnacle_usb[IR_KEYTAB_SIZE] = {
80 [ 0x3a ] = KEY_KP0,
81 [ 0x31 ] = KEY_KP1,
82 [ 0x32 ] = KEY_KP2,
83 [ 0x33 ] = KEY_KP3,
84 [ 0x34 ] = KEY_KP4,
85 [ 0x35 ] = KEY_KP5,
86 [ 0x36 ] = KEY_KP6,
87 [ 0x37 ] = KEY_KP7,
88 [ 0x38 ] = KEY_KP8,
89 [ 0x39 ] = KEY_KP9,
90
91 [ 0x2f ] = KEY_POWER,
92
93 [ 0x2e ] = KEY_P,
94 [ 0x1f ] = KEY_L,
95 [ 0x2b ] = KEY_I,
96
97 [ 0x2d ] = KEY_ZOOM,
98 [ 0x1e ] = KEY_ZOOM,
99 [ 0x1b ] = KEY_VOLUMEUP,
100 [ 0x0f ] = KEY_VOLUMEDOWN,
101 [ 0x17 ] = KEY_CHANNELUP,
102 [ 0x1c ] = KEY_CHANNELDOWN,
103 [ 0x25 ] = KEY_INFO,
104
105 [ 0x3c ] = KEY_MUTE,
106
107 [ 0x3d ] = KEY_LEFT,
108 [ 0x3b ] = KEY_RIGHT,
109
110 [ 0x3f ] = KEY_UP,
111 [ 0x3e ] = KEY_DOWN,
112 [ 0x1a ] = KEY_PAUSE,
113
114 [ 0x1d ] = KEY_MENU,
115 [ 0x19 ] = KEY_PLAY,
116 [ 0x16 ] = KEY_REWIND,
117 [ 0x13 ] = KEY_FORWARD,
118 [ 0x15 ] = KEY_PAUSE,
119 [ 0x0e ] = KEY_REWIND,
120 [ 0x0d ] = KEY_PLAY,
121 [ 0x0b ] = KEY_STOP,
122 [ 0x07 ] = KEY_FORWARD,
123 [ 0x27 ] = KEY_RECORD,
124 [ 0x26 ] = KEY_TUNER,
125 [ 0x29 ] = KEY_TEXT,
126 [ 0x2a ] = KEY_MEDIA,
127 [ 0x18 ] = KEY_EPG,
128 [ 0x27 ] = KEY_RECORD,
129};
130
131/* ----------------------------------------------------------------------- */ 46/* ----------------------------------------------------------------------- */
132 47
133static int get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) 48static int get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 5b267808a9d4..780342f7b239 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -28,6 +28,7 @@
28#include <linux/list.h> 28#include <linux/list.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/bitmap.h>
31#include <linux/usb.h> 32#include <linux/usb.h>
32#include <linux/i2c.h> 33#include <linux/i2c.h>
33#include <linux/version.h> 34#include <linux/version.h>
@@ -59,8 +60,14 @@ MODULE_LICENSE("GPL");
59static LIST_HEAD(em28xx_devlist); 60static LIST_HEAD(em28xx_devlist);
60 61
61static unsigned int card[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; 62static unsigned int card[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
63static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
64static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
62module_param_array(card, int, NULL, 0444); 65module_param_array(card, int, NULL, 0444);
66module_param_array(video_nr, int, NULL, 0444);
67module_param_array(vbi_nr, int, NULL, 0444);
63MODULE_PARM_DESC(card,"card type"); 68MODULE_PARM_DESC(card,"card type");
69MODULE_PARM_DESC(video_nr,"video device numbers");
70MODULE_PARM_DESC(vbi_nr,"vbi device numbers");
64 71
65static int tuner = -1; 72static int tuner = -1;
66module_param(tuner, int, 0444); 73module_param(tuner, int, 0444);
@@ -70,6 +77,9 @@ static unsigned int video_debug = 0;
70module_param(video_debug,int,0644); 77module_param(video_debug,int,0644);
71MODULE_PARM_DESC(video_debug,"enable debug messages [video]"); 78MODULE_PARM_DESC(video_debug,"enable debug messages [video]");
72 79
80/* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS */
81static unsigned long em28xx_devused;
82
73/* supported tv norms */ 83/* supported tv norms */
74static struct em28xx_tvnorm tvnorms[] = { 84static struct em28xx_tvnorm tvnorms[] = {
75 { 85 {
@@ -91,23 +101,6 @@ static struct em28xx_tvnorm tvnorms[] = {
91 } 101 }
92}; 102};
93 103
94static const unsigned char saa7114_i2c_init[] = {
95 0x00,0x00,0x01,0x08,0x02,0xc4,0x03,0x30,0x04,0x90,0x05,0x90,0x06,0xeb,0x07,0xe0,
96 0x08,0x88,0x09,0x40,0x0a,0x80,0x0b,0x44,0x0c,0x40,0x0d,0x00,0x0e,0x81,0x0f,0x2a,
97 0x10,0x06,0x11,0x00,0x12,0xc8,0x13,0x80,0x14,0x00,0x15,0x11,0x16,0x01,0x17,0x42,
98 0x18,0x40,0x19,0x80,0x40,0x00,0x41,0xff,0x42,0xff,0x43,0xff,0x44,0xff,0x45,0xff,
99 0x46,0xff,0x47,0xff,0x48,0xff,0x49,0xff,0x4a,0xff,0x4b,0xff,0x4c,0xff,0x4d,0xff,
100 0x4e,0xff,0x4f,0xff,0x50,0xff,0x51,0xff,0x52,0xff,0x53,0xff,0x54,0x5f,0x55,0xff,
101 0x56,0xff,0x57,0xff,0x58,0x00,0x59,0x47,0x5a,0x03,0x5b,0x03,0x5d,0x3e,0x5e,0x00,
102 0x80,0x1c,0x83,0x01,0x84,0xa5,0x85,0x10,0x86,0x45,0x87,0x41,0x88,0xf0,0x88,0x00,
103 0x88,0xf0,0x90,0x00,0x91,0x08,0x92,0x00,0x93,0x80,0x94,0x08,0x95,0x00,0x96,0xc0,
104 0x97,0x02,0x98,0x13,0x99,0x00,0x9a,0x38,0x9b,0x01,0x9c,0x80,0x9d,0x02,0x9e,0x06,
105 0x9f,0x01,0xa0,0x01,0xa1,0x00,0xa2,0x00,0xa4,0x80,0xa5,0x36,0xa6,0x36,0xa8,0x67,
106 0xa9,0x04,0xaa,0x00,0xac,0x33,0xad,0x02,0xae,0x00,0xb0,0xcd,0xb1,0x04,0xb2,0xcd,
107 0xb3,0x04,0xb4,0x01,0xb8,0x00,0xb9,0x00,0xba,0x00,0xbb,0x00,0xbc,0x00,0xbd,0x00,
108 0xbe,0x00,0xbf,0x00
109};
110
111#define TVNORMS ARRAY_SIZE(tvnorms) 104#define TVNORMS ARRAY_SIZE(tvnorms)
112 105
113/* supported controls */ 106/* supported controls */
@@ -134,65 +127,6 @@ static struct v4l2_queryctrl em28xx_qctrl[] = {
134 } 127 }
135}; 128};
136 129
137/* FIXME: These are specific to saa711x - should be moved to its code */
138static struct v4l2_queryctrl saa711x_qctrl[] = {
139 {
140 .id = V4L2_CID_BRIGHTNESS,
141 .type = V4L2_CTRL_TYPE_INTEGER,
142 .name = "Brightness",
143 .minimum = -128,
144 .maximum = 127,
145 .step = 1,
146 .default_value = 0,
147 .flags = 0,
148 },{
149 .id = V4L2_CID_CONTRAST,
150 .type = V4L2_CTRL_TYPE_INTEGER,
151 .name = "Contrast",
152 .minimum = 0x0,
153 .maximum = 0x1f,
154 .step = 0x1,
155 .default_value = 0x10,
156 .flags = 0,
157 },{
158 .id = V4L2_CID_SATURATION,
159 .type = V4L2_CTRL_TYPE_INTEGER,
160 .name = "Saturation",
161 .minimum = 0x0,
162 .maximum = 0x1f,
163 .step = 0x1,
164 .default_value = 0x10,
165 .flags = 0,
166 },{
167 .id = V4L2_CID_RED_BALANCE,
168 .type = V4L2_CTRL_TYPE_INTEGER,
169 .name = "Red chroma balance",
170 .minimum = -128,
171 .maximum = 127,
172 .step = 1,
173 .default_value = 0,
174 .flags = 0,
175 },{
176 .id = V4L2_CID_BLUE_BALANCE,
177 .type = V4L2_CTRL_TYPE_INTEGER,
178 .name = "Blue chroma balance",
179 .minimum = -128,
180 .maximum = 127,
181 .step = 1,
182 .default_value = 0,
183 .flags = 0,
184 },{
185 .id = V4L2_CID_GAMMA,
186 .type = V4L2_CTRL_TYPE_INTEGER,
187 .name = "Gamma",
188 .minimum = 0x0,
189 .maximum = 0x3f,
190 .step = 0x1,
191 .default_value = 0x20,
192 .flags = 0,
193 }
194};
195
196static struct usb_driver em28xx_usb_driver; 130static struct usb_driver em28xx_usb_driver;
197 131
198static DEFINE_MUTEX(em28xx_sysfs_lock); 132static DEFINE_MUTEX(em28xx_sysfs_lock);
@@ -211,6 +145,11 @@ static int em28xx_config(struct em28xx *dev)
211 em28xx_write_regs_req(dev, 0x00, 0x06, "\x40", 1); 145 em28xx_write_regs_req(dev, 0x00, 0x06, "\x40", 1);
212 146
213 /* enable vbi capturing */ 147 /* enable vbi capturing */
148
149/* em28xx_write_regs_req(dev,0x00,0x0e,"\xC0",1); audio register */
150/* em28xx_write_regs_req(dev,0x00,0x0f,"\x80",1); clk register */
151 em28xx_write_regs_req(dev,0x00,0x11,"\x51",1);
152
214 em28xx_audio_usb_mute(dev, 1); 153 em28xx_audio_usb_mute(dev, 1);
215 dev->mute = 1; /* maybe not the right place... */ 154 dev->mute = 1; /* maybe not the right place... */
216 dev->volume = 0x1f; 155 dev->volume = 0x1f;
@@ -230,22 +169,9 @@ static int em28xx_config(struct em28xx *dev)
230static void em28xx_config_i2c(struct em28xx *dev) 169static void em28xx_config_i2c(struct em28xx *dev)
231{ 170{
232 struct v4l2_frequency f; 171 struct v4l2_frequency f;
233 struct video_decoder_init em28xx_vdi = {.data = NULL }; 172 em28xx_i2c_call_clients(dev, VIDIOC_INT_RESET, NULL);
234 173 em28xx_i2c_call_clients(dev, VIDIOC_S_INPUT, &dev->ctl_input);
235 174 em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL);
236 /* configure decoder */
237 if(dev->model == EM2820_BOARD_MSI_VOX_USB_2){
238 em28xx_vdi.data=saa7114_i2c_init;
239 em28xx_vdi.len=sizeof(saa7114_i2c_init);
240 }
241
242
243 em28xx_i2c_call_clients(dev, DECODER_INIT, &em28xx_vdi);
244 em28xx_i2c_call_clients(dev, DECODER_SET_INPUT, &dev->ctl_input);
245/* em28xx_i2c_call_clients(dev,DECODER_SET_PICTURE, &dev->vpic); */
246/* em28xx_i2c_call_clients(dev,DECODER_SET_NORM,&dev->tvnorm->id); */
247/* em28xx_i2c_call_clients(dev,DECODER_ENABLE_OUTPUT,&output); */
248/* em28xx_i2c_call_clients(dev,DECODER_DUMP, NULL); */
249 175
250 /* configure tuner */ 176 /* configure tuner */
251 f.tuner = 0; 177 f.tuner = 0;
@@ -285,8 +211,7 @@ static void video_mux(struct em28xx *dev, int index)
285 dev->ctl_input = index; 211 dev->ctl_input = index;
286 dev->ctl_ainput = INPUT(index)->amux; 212 dev->ctl_ainput = INPUT(index)->amux;
287 213
288 em28xx_i2c_call_clients(dev, DECODER_SET_INPUT, &input); 214 em28xx_i2c_call_clients(dev, VIDIOC_S_INPUT, &input);
289
290 215
291 em28xx_videodbg("Setting input index=%d, vmux=%d, amux=%d\n",index,input,dev->ctl_ainput); 216 em28xx_videodbg("Setting input index=%d, vmux=%d, amux=%d\n",index,input,dev->ctl_ainput);
292 217
@@ -298,11 +223,11 @@ static void video_mux(struct em28xx *dev, int index)
298 em28xx_audio_source(dev, ainput); 223 em28xx_audio_source(dev, ainput);
299 } else { 224 } else {
300 switch (dev->ctl_ainput) { 225 switch (dev->ctl_ainput) {
301 case 0: 226 case 0:
302 ainput = EM28XX_AUDIO_SRC_TUNER; 227 ainput = EM28XX_AUDIO_SRC_TUNER;
303 break; 228 break;
304 default: 229 default:
305 ainput = EM28XX_AUDIO_SRC_LINE; 230 ainput = EM28XX_AUDIO_SRC_LINE;
306 } 231 }
307 em28xx_audio_source(dev, ainput); 232 em28xx_audio_source(dev, ainput);
308 } 233 }
@@ -323,13 +248,20 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
323 h = list_entry(list, struct em28xx, devlist); 248 h = list_entry(list, struct em28xx, devlist);
324 if (h->vdev->minor == minor) { 249 if (h->vdev->minor == minor) {
325 dev = h; 250 dev = h;
251 dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
252 }
253 if (h->vbi_dev->minor == minor) {
254 dev = h;
255 dev->type = V4L2_BUF_TYPE_VBI_CAPTURE;
326 } 256 }
327 } 257 }
258 if (NULL == dev)
259 return -ENODEV;
328 260
329 filp->private_data=dev; 261 filp->private_data=dev;
330 262
331 263 em28xx_videodbg("open minor=%d type=%s users=%d\n",
332 em28xx_videodbg("users=%d\n", dev->users); 264 minor,v4l2_type_names[dev->type],dev->users);
333 265
334 if (!down_read_trylock(&em28xx_disconnect)) 266 if (!down_read_trylock(&em28xx_disconnect))
335 return -ERESTARTSYS; 267 return -ERESTARTSYS;
@@ -340,40 +272,36 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
340 return -EBUSY; 272 return -EBUSY;
341 } 273 }
342 274
343/* if(dev->vbi_dev->minor == minor){ 275 mutex_init(&dev->fileop_lock); /* to 1 == available */
344 dev->type=V4L2_BUF_TYPE_VBI_CAPTURE;
345 }*/
346 if (dev->vdev->minor == minor) {
347 dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
348 }
349
350 init_MUTEX(&dev->fileop_lock); /* to 1 == available */
351 spin_lock_init(&dev->queue_lock); 276 spin_lock_init(&dev->queue_lock);
352 init_waitqueue_head(&dev->wait_frame); 277 init_waitqueue_head(&dev->wait_frame);
353 init_waitqueue_head(&dev->wait_stream); 278 init_waitqueue_head(&dev->wait_stream);
354 279
355 down(&dev->lock); 280 mutex_lock(&dev->lock);
356 281
357 em28xx_set_alternate(dev); 282 if (dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
283 em28xx_set_alternate(dev);
358 284
359 dev->width = norm_maxw(dev); 285 dev->width = norm_maxw(dev);
360 dev->height = norm_maxh(dev); 286 dev->height = norm_maxh(dev);
361 dev->frame_size = dev->width * dev->height * 2; 287 dev->frame_size = dev->width * dev->height * 2;
362 dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */ 288 dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */
363 dev->bytesperline = dev->width * 2; 289 dev->bytesperline = dev->width * 2;
364 dev->hscale = 0; 290 dev->hscale = 0;
365 dev->vscale = 0; 291 dev->vscale = 0;
366 292
367 em28xx_capture_start(dev, 1); 293 em28xx_capture_start(dev, 1);
368 em28xx_resolution_set(dev); 294 em28xx_resolution_set(dev);
369 295
370 /* device needs to be initialized before isoc transfer */ 296 /* device needs to be initialized before isoc transfer */
371 video_mux(dev, 0); 297 video_mux(dev, 0);
372 298
373 /* start the transfer */ 299 /* start the transfer */
374 errCode = em28xx_init_isoc(dev); 300 errCode = em28xx_init_isoc(dev);
375 if (errCode) 301 if (errCode)
376 goto err; 302 goto err;
303
304 }
377 305
378 dev->users++; 306 dev->users++;
379 filp->private_data = dev; 307 filp->private_data = dev;
@@ -386,10 +314,8 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
386 314
387 dev->state |= DEV_INITIALIZED; 315 dev->state |= DEV_INITIALIZED;
388 316
389 video_mux(dev, 0); 317err:
390 318 mutex_unlock(&dev->lock);
391 err:
392 up(&dev->lock);
393 up_read(&em28xx_disconnect); 319 up_read(&em28xx_disconnect);
394 return errCode; 320 return errCode;
395} 321}
@@ -403,14 +329,21 @@ static void em28xx_release_resources(struct em28xx *dev)
403{ 329{
404 mutex_lock(&em28xx_sysfs_lock); 330 mutex_lock(&em28xx_sysfs_lock);
405 331
406 em28xx_info("V4L2 device /dev/video%d deregistered\n", 332 /*FIXME: I2C IR should be disconnected */
407 dev->vdev->minor); 333
334 em28xx_info("V4L2 devices /dev/video%d and /dev/vbi%d deregistered\n",
335 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN,
336 dev->vbi_dev->minor-MINOR_VFL_TYPE_VBI_MIN);
408 list_del(&dev->devlist); 337 list_del(&dev->devlist);
409 video_unregister_device(dev->vdev); 338 video_unregister_device(dev->vdev);
410/* video_unregister_device(dev->vbi_dev); */ 339 video_unregister_device(dev->vbi_dev);
411 em28xx_i2c_unregister(dev); 340 em28xx_i2c_unregister(dev);
412 usb_put_dev(dev->udev); 341 usb_put_dev(dev->udev);
413 mutex_unlock(&em28xx_sysfs_lock); 342 mutex_unlock(&em28xx_sysfs_lock);
343
344
345 /* Mark device as unused */
346 em28xx_devused&=~(1<<dev->devno);
414} 347}
415 348
416/* 349/*
@@ -424,7 +357,7 @@ static int em28xx_v4l2_close(struct inode *inode, struct file *filp)
424 357
425 em28xx_videodbg("users=%d\n", dev->users); 358 em28xx_videodbg("users=%d\n", dev->users);
426 359
427 down(&dev->lock); 360 mutex_lock(&dev->lock);
428 361
429 em28xx_uninit_isoc(dev); 362 em28xx_uninit_isoc(dev);
430 363
@@ -433,7 +366,7 @@ static int em28xx_v4l2_close(struct inode *inode, struct file *filp)
433 /* the device is already disconnect, free the remaining resources */ 366 /* the device is already disconnect, free the remaining resources */
434 if (dev->state & DEV_DISCONNECTED) { 367 if (dev->state & DEV_DISCONNECTED) {
435 em28xx_release_resources(dev); 368 em28xx_release_resources(dev);
436 up(&dev->lock); 369 mutex_unlock(&dev->lock);
437 kfree(dev); 370 kfree(dev);
438 return 0; 371 return 0;
439 } 372 }
@@ -449,7 +382,7 @@ static int em28xx_v4l2_close(struct inode *inode, struct file *filp)
449 382
450 dev->users--; 383 dev->users--;
451 wake_up_interruptible_nr(&dev->open, 1); 384 wake_up_interruptible_nr(&dev->open, 1);
452 up(&dev->lock); 385 mutex_unlock(&dev->lock);
453 return 0; 386 return 0;
454} 387}
455 388
@@ -466,32 +399,54 @@ em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count,
466 int ret = 0; 399 int ret = 0;
467 struct em28xx *dev = filp->private_data; 400 struct em28xx *dev = filp->private_data;
468 401
469 if (down_interruptible(&dev->fileop_lock)) 402 if (dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
403 em28xx_videodbg("V4l2_Buf_type_videocapture is set\n");
404 }
405 if (dev->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
406 em28xx_videodbg("V4L2_BUF_TYPE_VBI_CAPTURE is set\n");
407 em28xx_videodbg("not supported yet! ...\n");
408 if (copy_to_user(buf, "", 1)) {
409 mutex_unlock(&dev->fileop_lock);
410 return -EFAULT;
411 }
412 return (1);
413 }
414 if (dev->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
415 em28xx_videodbg("V4L2_BUF_TYPE_SLICED_VBI_CAPTURE is set\n");
416 em28xx_videodbg("not supported yet! ...\n");
417 if (copy_to_user(buf, "", 1)) {
418 mutex_unlock(&dev->fileop_lock);
419 return -EFAULT;
420 }
421 return (1);
422 }
423
424 if (mutex_lock_interruptible(&dev->fileop_lock))
470 return -ERESTARTSYS; 425 return -ERESTARTSYS;
471 426
472 if (dev->state & DEV_DISCONNECTED) { 427 if (dev->state & DEV_DISCONNECTED) {
473 em28xx_videodbg("device not present\n"); 428 em28xx_videodbg("device not present\n");
474 up(&dev->fileop_lock); 429 mutex_unlock(&dev->fileop_lock);
475 return -ENODEV; 430 return -ENODEV;
476 } 431 }
477 432
478 if (dev->state & DEV_MISCONFIGURED) { 433 if (dev->state & DEV_MISCONFIGURED) {
479 em28xx_videodbg("device misconfigured; close and open it again\n"); 434 em28xx_videodbg("device misconfigured; close and open it again\n");
480 up(&dev->fileop_lock); 435 mutex_unlock(&dev->fileop_lock);
481 return -EIO; 436 return -EIO;
482 } 437 }
483 438
484 if (dev->io == IO_MMAP) { 439 if (dev->io == IO_MMAP) {
485 em28xx_videodbg ("IO method is set to mmap; close and open" 440 em28xx_videodbg ("IO method is set to mmap; close and open"
486 " the device again to choose the read method\n"); 441 " the device again to choose the read method\n");
487 up(&dev->fileop_lock); 442 mutex_unlock(&dev->fileop_lock);
488 return -EINVAL; 443 return -EINVAL;
489 } 444 }
490 445
491 if (dev->io == IO_NONE) { 446 if (dev->io == IO_NONE) {
492 if (!em28xx_request_buffers(dev, EM28XX_NUM_READ_FRAMES)) { 447 if (!em28xx_request_buffers(dev, EM28XX_NUM_READ_FRAMES)) {
493 em28xx_errdev("read failed, not enough memory\n"); 448 em28xx_errdev("read failed, not enough memory\n");
494 up(&dev->fileop_lock); 449 mutex_unlock(&dev->fileop_lock);
495 return -ENOMEM; 450 return -ENOMEM;
496 } 451 }
497 dev->io = IO_READ; 452 dev->io = IO_READ;
@@ -500,13 +455,13 @@ em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count,
500 } 455 }
501 456
502 if (!count) { 457 if (!count) {
503 up(&dev->fileop_lock); 458 mutex_unlock(&dev->fileop_lock);
504 return 0; 459 return 0;
505 } 460 }
506 461
507 if (list_empty(&dev->outqueue)) { 462 if (list_empty(&dev->outqueue)) {
508 if (filp->f_flags & O_NONBLOCK) { 463 if (filp->f_flags & O_NONBLOCK) {
509 up(&dev->fileop_lock); 464 mutex_unlock(&dev->fileop_lock);
510 return -EAGAIN; 465 return -EAGAIN;
511 } 466 }
512 ret = wait_event_interruptible 467 ret = wait_event_interruptible
@@ -514,11 +469,11 @@ em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count,
514 (!list_empty(&dev->outqueue)) || 469 (!list_empty(&dev->outqueue)) ||
515 (dev->state & DEV_DISCONNECTED)); 470 (dev->state & DEV_DISCONNECTED));
516 if (ret) { 471 if (ret) {
517 up(&dev->fileop_lock); 472 mutex_unlock(&dev->fileop_lock);
518 return ret; 473 return ret;
519 } 474 }
520 if (dev->state & DEV_DISCONNECTED) { 475 if (dev->state & DEV_DISCONNECTED) {
521 up(&dev->fileop_lock); 476 mutex_unlock(&dev->fileop_lock);
522 return -ENODEV; 477 return -ENODEV;
523 } 478 }
524 } 479 }
@@ -537,12 +492,12 @@ em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count,
537 count = f->buf.length; 492 count = f->buf.length;
538 493
539 if (copy_to_user(buf, f->bufmem, count)) { 494 if (copy_to_user(buf, f->bufmem, count)) {
540 up(&dev->fileop_lock); 495 mutex_unlock(&dev->fileop_lock);
541 return -EFAULT; 496 return -EFAULT;
542 } 497 }
543 *f_pos += count; 498 *f_pos += count;
544 499
545 up(&dev->fileop_lock); 500 mutex_unlock(&dev->fileop_lock);
546 501
547 return count; 502 return count;
548} 503}
@@ -556,7 +511,7 @@ static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table * wait)
556 unsigned int mask = 0; 511 unsigned int mask = 0;
557 struct em28xx *dev = filp->private_data; 512 struct em28xx *dev = filp->private_data;
558 513
559 if (down_interruptible(&dev->fileop_lock)) 514 if (mutex_lock_interruptible(&dev->fileop_lock))
560 return POLLERR; 515 return POLLERR;
561 516
562 if (dev->state & DEV_DISCONNECTED) { 517 if (dev->state & DEV_DISCONNECTED) {
@@ -582,13 +537,13 @@ static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table * wait)
582 if (!list_empty(&dev->outqueue)) 537 if (!list_empty(&dev->outqueue))
583 mask |= POLLIN | POLLRDNORM; 538 mask |= POLLIN | POLLRDNORM;
584 539
585 up(&dev->fileop_lock); 540 mutex_unlock(&dev->fileop_lock);
586 541
587 return mask; 542 return mask;
588 } 543 }
589 } 544 }
590 545
591 up(&dev->fileop_lock); 546 mutex_unlock(&dev->fileop_lock);
592 return POLLERR; 547 return POLLERR;
593} 548}
594 549
@@ -628,25 +583,25 @@ static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
628 583
629 struct em28xx *dev = filp->private_data; 584 struct em28xx *dev = filp->private_data;
630 585
631 if (down_interruptible(&dev->fileop_lock)) 586 if (mutex_lock_interruptible(&dev->fileop_lock))
632 return -ERESTARTSYS; 587 return -ERESTARTSYS;
633 588
634 if (dev->state & DEV_DISCONNECTED) { 589 if (dev->state & DEV_DISCONNECTED) {
635 em28xx_videodbg("mmap: device not present\n"); 590 em28xx_videodbg("mmap: device not present\n");
636 up(&dev->fileop_lock); 591 mutex_unlock(&dev->fileop_lock);
637 return -ENODEV; 592 return -ENODEV;
638 } 593 }
639 594
640 if (dev->state & DEV_MISCONFIGURED) { 595 if (dev->state & DEV_MISCONFIGURED) {
641 em28xx_videodbg ("mmap: Device is misconfigured; close and " 596 em28xx_videodbg ("mmap: Device is misconfigured; close and "
642 "open it again\n"); 597 "open it again\n");
643 up(&dev->fileop_lock); 598 mutex_unlock(&dev->fileop_lock);
644 return -EIO; 599 return -EIO;
645 } 600 }
646 601
647 if (dev->io != IO_MMAP || !(vma->vm_flags & VM_WRITE) || 602 if (dev->io != IO_MMAP || !(vma->vm_flags & VM_WRITE) ||
648 size != PAGE_ALIGN(dev->frame[0].buf.length)) { 603 size != PAGE_ALIGN(dev->frame[0].buf.length)) {
649 up(&dev->fileop_lock); 604 mutex_unlock(&dev->fileop_lock);
650 return -EINVAL; 605 return -EINVAL;
651 } 606 }
652 607
@@ -656,7 +611,7 @@ static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
656 } 611 }
657 if (i == dev->num_frames) { 612 if (i == dev->num_frames) {
658 em28xx_videodbg("mmap: user supplied mapping address is out of range\n"); 613 em28xx_videodbg("mmap: user supplied mapping address is out of range\n");
659 up(&dev->fileop_lock); 614 mutex_unlock(&dev->fileop_lock);
660 return -EINVAL; 615 return -EINVAL;
661 } 616 }
662 617
@@ -668,7 +623,7 @@ static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
668 while (size > 0) { /* size is page-aligned */ 623 while (size > 0) { /* size is page-aligned */
669 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) { 624 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
670 em28xx_videodbg("mmap: vm_insert_page failed\n"); 625 em28xx_videodbg("mmap: vm_insert_page failed\n");
671 up(&dev->fileop_lock); 626 mutex_unlock(&dev->fileop_lock);
672 return -EAGAIN; 627 return -EAGAIN;
673 } 628 }
674 start += PAGE_SIZE; 629 start += PAGE_SIZE;
@@ -680,7 +635,7 @@ static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
680 vma->vm_private_data = &dev->frame[i]; 635 vma->vm_private_data = &dev->frame[i];
681 636
682 em28xx_vm_open(vma); 637 em28xx_vm_open(vma);
683 up(&dev->fileop_lock); 638 mutex_unlock(&dev->fileop_lock);
684 return 0; 639 return 0;
685} 640}
686 641
@@ -702,43 +657,6 @@ static int em28xx_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl)
702 } 657 }
703} 658}
704 659
705/*FIXME: should be moved to saa711x */
706static int saa711x_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl)
707{
708 s32 tmp;
709 switch (ctrl->id) {
710 case V4L2_CID_BRIGHTNESS:
711 if ((tmp = em28xx_brightness_get(dev)) < 0)
712 return -EIO;
713 ctrl->value = (s32) ((s8) tmp); /* FIXME: clenaer way to extend sign? */
714 return 0;
715 case V4L2_CID_CONTRAST:
716 if ((ctrl->value = em28xx_contrast_get(dev)) < 0)
717 return -EIO;
718 return 0;
719 case V4L2_CID_SATURATION:
720 if ((ctrl->value = em28xx_saturation_get(dev)) < 0)
721 return -EIO;
722 return 0;
723 case V4L2_CID_RED_BALANCE:
724 if ((tmp = em28xx_v_balance_get(dev)) < 0)
725 return -EIO;
726 ctrl->value = (s32) ((s8) tmp); /* FIXME: clenaer way to extend sign? */
727 return 0;
728 case V4L2_CID_BLUE_BALANCE:
729 if ((tmp = em28xx_u_balance_get(dev)) < 0)
730 return -EIO;
731 ctrl->value = (s32) ((s8) tmp); /* FIXME: clenaer way to extend sign? */
732 return 0;
733 case V4L2_CID_GAMMA:
734 if ((ctrl->value = em28xx_gamma_get(dev)) < 0)
735 return -EIO;
736 return 0;
737 default:
738 return -EINVAL;
739 }
740}
741
742/* 660/*
743 * em28xx_set_ctrl() 661 * em28xx_set_ctrl()
744 * mute or set new saturation, brightness or contrast 662 * mute or set new saturation, brightness or contrast
@@ -761,27 +679,6 @@ static int em28xx_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl)
761 } 679 }
762} 680}
763 681
764/*FIXME: should be moved to saa711x */
765static int saa711x_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl)
766{
767 switch (ctrl->id) {
768 case V4L2_CID_BRIGHTNESS:
769 return em28xx_brightness_set(dev, ctrl->value);
770 case V4L2_CID_CONTRAST:
771 return em28xx_contrast_set(dev, ctrl->value);
772 case V4L2_CID_SATURATION:
773 return em28xx_saturation_set(dev, ctrl->value);
774 case V4L2_CID_RED_BALANCE:
775 return em28xx_v_balance_set(dev, ctrl->value);
776 case V4L2_CID_BLUE_BALANCE:
777 return em28xx_u_balance_set(dev, ctrl->value);
778 case V4L2_CID_GAMMA:
779 return em28xx_gamma_set(dev, ctrl->value);
780 default:
781 return -EINVAL;
782 }
783}
784
785/* 682/*
786 * em28xx_stream_interrupt() 683 * em28xx_stream_interrupt()
787 * stops streaming 684 * stops streaming
@@ -802,7 +699,8 @@ static int em28xx_stream_interrupt(struct em28xx *dev)
802 else if (ret) { 699 else if (ret) {
803 dev->state |= DEV_MISCONFIGURED; 700 dev->state |= DEV_MISCONFIGURED;
804 em28xx_videodbg("device is misconfigured; close and " 701 em28xx_videodbg("device is misconfigured; close and "
805 "open /dev/video%d again\n", dev->vdev->minor); 702 "open /dev/video%d again\n",
703 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN);
806 return ret; 704 return ret;
807 } 705 }
808 706
@@ -853,6 +751,181 @@ static int em28xx_set_norm(struct em28xx *dev, int width, int height)
853 return 0; 751 return 0;
854} 752}
855 753
754static int em28xx_get_fmt(struct em28xx *dev, struct v4l2_format *format)
755{
756 em28xx_videodbg("VIDIOC_G_FMT: type=%s\n",
757 (format->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE) ?
758 "V4L2_BUF_TYPE_VIDEO_CAPTURE" :
759 (format->type ==V4L2_BUF_TYPE_VBI_CAPTURE) ?
760 "V4L2_BUF_TYPE_VBI_CAPTURE" :
761 (format->type ==V4L2_CAP_SLICED_VBI_CAPTURE) ?
762 "V4L2_BUF_TYPE_SLICED_VBI_CAPTURE " :
763 "not supported");
764
765 switch (format->type) {
766 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
767 {
768 format->fmt.pix.width = dev->width;
769 format->fmt.pix.height = dev->height;
770 format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
771 format->fmt.pix.bytesperline = dev->bytesperline;
772 format->fmt.pix.sizeimage = dev->frame_size;
773 format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
774 format->fmt.pix.field = dev->interlaced ? V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP; /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */
775
776 em28xx_videodbg("VIDIOC_G_FMT: %dx%d\n", dev->width,
777 dev->height);
778 break;
779 }
780
781 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
782 {
783 format->fmt.sliced.service_set=0;
784
785 em28xx_i2c_call_clients(dev,VIDIOC_G_FMT,format);
786
787 if (format->fmt.sliced.service_set==0)
788 return -EINVAL;
789
790 break;
791 }
792
793 default:
794 return -EINVAL;
795 }
796 return (0);
797}
798
799static int em28xx_set_fmt(struct em28xx *dev, unsigned int cmd, struct v4l2_format *format)
800{
801 u32 i;
802 int ret = 0;
803 int width = format->fmt.pix.width;
804 int height = format->fmt.pix.height;
805 unsigned int hscale, vscale;
806 unsigned int maxh, maxw;
807
808 maxw = norm_maxw(dev);
809 maxh = norm_maxh(dev);
810
811 em28xx_videodbg("%s: type=%s\n",
812 cmd == VIDIOC_TRY_FMT ?
813 "VIDIOC_TRY_FMT" : "VIDIOC_S_FMT",
814 format->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ?
815 "V4L2_BUF_TYPE_VIDEO_CAPTURE" :
816 format->type == V4L2_BUF_TYPE_VBI_CAPTURE ?
817 "V4L2_BUF_TYPE_VBI_CAPTURE " :
818 "not supported");
819
820 if (format->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
821 em28xx_i2c_call_clients(dev,VIDIOC_G_FMT,format);
822
823 if (format->fmt.sliced.service_set==0)
824 return -EINVAL;
825
826 return 0;
827 }
828
829
830 if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
831 return -EINVAL;
832
833 em28xx_videodbg("%s: requested %dx%d\n",
834 cmd == VIDIOC_TRY_FMT ?
835 "VIDIOC_TRY_FMT" : "VIDIOC_S_FMT",
836 format->fmt.pix.width, format->fmt.pix.height);
837
838 /* FIXME: Move some code away from here */
839 /* width must even because of the YUYV format */
840 /* height must be even because of interlacing */
841 height &= 0xfffe;
842 width &= 0xfffe;
843
844 if (height < 32)
845 height = 32;
846 if (height > maxh)
847 height = maxh;
848 if (width < 48)
849 width = 48;
850 if (width > maxw)
851 width = maxw;
852
853 if(dev->is_em2800){
854 /* the em2800 can only scale down to 50% */
855 if(height % (maxh / 2))
856 height=maxh;
857 if(width % (maxw / 2))
858 width=maxw;
859 /* according to empiatech support */
860 /* the MaxPacketSize is to small to support */
861 /* framesizes larger than 640x480 @ 30 fps */
862 /* or 640x576 @ 25 fps. As this would cut */
863 /* of a part of the image we prefer */
864 /* 360x576 or 360x480 for now */
865 if(width == maxw && height == maxh)
866 width /= 2;
867 }
868
869 if ((hscale = (((unsigned long)maxw) << 12) / width - 4096L) >= 0x4000)
870 hscale = 0x3fff;
871
872 width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
873
874 if ((vscale = (((unsigned long)maxh) << 12) / height - 4096L) >= 0x4000)
875 vscale = 0x3fff;
876
877 height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
878
879 format->fmt.pix.width = width;
880 format->fmt.pix.height = height;
881 format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
882 format->fmt.pix.bytesperline = width * 2;
883 format->fmt.pix.sizeimage = width * 2 * height;
884 format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
885 format->fmt.pix.field = V4L2_FIELD_INTERLACED;
886
887 em28xx_videodbg("%s: returned %dx%d (%d, %d)\n",
888 cmd == VIDIOC_TRY_FMT ?
889 "VIDIOC_TRY_FMT" :"VIDIOC_S_FMT",
890 format->fmt.pix.width, format->fmt.pix.height, hscale, vscale);
891
892 if (cmd == VIDIOC_TRY_FMT)
893 return 0;
894
895 for (i = 0; i < dev->num_frames; i++)
896 if (dev->frame[i].vma_use_count) {
897 em28xx_videodbg("VIDIOC_S_FMT failed. "
898 "Unmap the buffers first.\n");
899 return -EINVAL;
900 }
901
902 /* stop io in case it is already in progress */
903 if (dev->stream == STREAM_ON) {
904 em28xx_videodbg("VIDIOC_SET_FMT: interupting stream\n");
905 if ((ret = em28xx_stream_interrupt(dev)))
906 return ret;
907 }
908
909 em28xx_release_buffers(dev);
910 dev->io = IO_NONE;
911
912 /* set new image size */
913 dev->width = width;
914 dev->height = height;
915 dev->frame_size = dev->width * dev->height * 2;
916 dev->field_size = dev->frame_size >> 1;
917 dev->bytesperline = dev->width * 2;
918 dev->hscale = hscale;
919 dev->vscale = vscale;
920 em28xx_uninit_isoc(dev);
921 em28xx_set_alternate(dev);
922 em28xx_capture_start(dev, 1);
923 em28xx_resolution_set(dev);
924 em28xx_init_isoc(dev);
925
926 return 0;
927}
928
856/* 929/*
857 * em28xx_v4l2_do_ioctl() 930 * em28xx_v4l2_do_ioctl()
858 * This function is _not_ called directly, but from 931 * This function is _not_ called directly, but from
@@ -868,392 +941,325 @@ static int em28xx_do_ioctl(struct inode *inode, struct file *filp,
868 switch (cmd) { 941 switch (cmd) {
869 /* ---------- tv norms ---------- */ 942 /* ---------- tv norms ---------- */
870 case VIDIOC_ENUMSTD: 943 case VIDIOC_ENUMSTD:
871 { 944 {
872 struct v4l2_standard *e = arg; 945 struct v4l2_standard *e = arg;
873 unsigned int i; 946 unsigned int i;
874 947
875 i = e->index; 948 i = e->index;
876 if (i >= TVNORMS) 949 if (i >= TVNORMS)
877 return -EINVAL; 950 return -EINVAL;
878 ret = v4l2_video_std_construct(e, tvnorms[e->index].id, 951 ret = v4l2_video_std_construct(e, tvnorms[e->index].id,
879 tvnorms[e->index].name); 952 tvnorms[e->index].name);
880 e->index = i; 953 e->index = i;
881 if (ret < 0) 954 if (ret < 0)
882 return ret; 955 return ret;
883 return 0; 956 return 0;
884 } 957 }
885 case VIDIOC_G_STD: 958 case VIDIOC_G_STD:
886 { 959 {
887 v4l2_std_id *id = arg; 960 v4l2_std_id *id = arg;
888 961
889 *id = dev->tvnorm->id; 962 *id = dev->tvnorm->id;
890 return 0; 963 return 0;
891 } 964 }
892 case VIDIOC_S_STD: 965 case VIDIOC_S_STD:
893 { 966 {
894 v4l2_std_id *id = arg; 967 v4l2_std_id *id = arg;
895 unsigned int i; 968 unsigned int i;
896 969
970 for (i = 0; i < TVNORMS; i++)
971 if (*id == tvnorms[i].id)
972 break;
973 if (i == TVNORMS)
897 for (i = 0; i < TVNORMS; i++) 974 for (i = 0; i < TVNORMS; i++)
898 if (*id == tvnorms[i].id) 975 if (*id & tvnorms[i].id)
899 break; 976 break;
900 if (i == TVNORMS) 977 if (i == TVNORMS)
901 for (i = 0; i < TVNORMS; i++) 978 return -EINVAL;
902 if (*id & tvnorms[i].id)
903 break;
904 if (i == TVNORMS)
905 return -EINVAL;
906
907 down(&dev->lock);
908 dev->tvnorm = &tvnorms[i];
909 979
910 em28xx_set_norm(dev, dev->width, dev->height); 980 mutex_lock(&dev->lock);
981 dev->tvnorm = &tvnorms[i];
911 982
912/* 983 em28xx_set_norm(dev, dev->width, dev->height);
913 dev->width=norm_maxw(dev);
914 dev->height=norm_maxh(dev);
915 dev->frame_size=dev->width*dev->height*2;
916 dev->field_size=dev->frame_size>>1;
917 dev->bytesperline=dev->width*2;
918 dev->hscale=0;
919 dev->vscale=0;
920 984
921 em28xx_resolution_set(dev); 985 em28xx_i2c_call_clients(dev, VIDIOC_S_STD,
922*/ 986 &dev->tvnorm->id);
923/*
924 em28xx_uninit_isoc(dev);
925 em28xx_set_alternate(dev);
926 em28xx_capture_start(dev, 1);
927 em28xx_resolution_set(dev);
928 em28xx_init_isoc(dev);
929*/
930 em28xx_i2c_call_clients(dev, DECODER_SET_NORM,
931 &tvnorms[i].mode);
932 em28xx_i2c_call_clients(dev, VIDIOC_S_STD,
933 &dev->tvnorm->id);
934 987
935 up(&dev->lock); 988 mutex_unlock(&dev->lock);
936 989
937 return 0; 990 return 0;
938 } 991 }
939 992
940 /* ------ input switching ---------- */ 993 /* ------ input switching ---------- */
941 case VIDIOC_ENUMINPUT: 994 case VIDIOC_ENUMINPUT:
942 { 995 {
943 struct v4l2_input *i = arg; 996 struct v4l2_input *i = arg;
944 unsigned int n; 997 unsigned int n;
945 static const char *iname[] = { 998 static const char *iname[] = {
946 [EM28XX_VMUX_COMPOSITE1] = "Composite1", 999 [EM28XX_VMUX_COMPOSITE1] = "Composite1",
947 [EM28XX_VMUX_COMPOSITE2] = "Composite2", 1000 [EM28XX_VMUX_COMPOSITE2] = "Composite2",
948 [EM28XX_VMUX_COMPOSITE3] = "Composite3", 1001 [EM28XX_VMUX_COMPOSITE3] = "Composite3",
949 [EM28XX_VMUX_COMPOSITE4] = "Composite4", 1002 [EM28XX_VMUX_COMPOSITE4] = "Composite4",
950 [EM28XX_VMUX_SVIDEO] = "S-Video", 1003 [EM28XX_VMUX_SVIDEO] = "S-Video",
951 [EM28XX_VMUX_TELEVISION] = "Television", 1004 [EM28XX_VMUX_TELEVISION] = "Television",
952 [EM28XX_VMUX_CABLE] = "Cable TV", 1005 [EM28XX_VMUX_CABLE] = "Cable TV",
953 [EM28XX_VMUX_DVB] = "DVB", 1006 [EM28XX_VMUX_DVB] = "DVB",
954 [EM28XX_VMUX_DEBUG] = "for debug only", 1007 [EM28XX_VMUX_DEBUG] = "for debug only",
955 }; 1008 };
956 1009
957 n = i->index; 1010 n = i->index;
958 if (n >= MAX_EM28XX_INPUT) 1011 if (n >= MAX_EM28XX_INPUT)
959 return -EINVAL; 1012 return -EINVAL;
960 if (0 == INPUT(n)->type) 1013 if (0 == INPUT(n)->type)
961 return -EINVAL; 1014 return -EINVAL;
962 memset(i, 0, sizeof(*i)); 1015 memset(i, 0, sizeof(*i));
963 i->index = n; 1016 i->index = n;
964 i->type = V4L2_INPUT_TYPE_CAMERA; 1017 i->type = V4L2_INPUT_TYPE_CAMERA;
965 strcpy(i->name, iname[INPUT(n)->type]); 1018 strcpy(i->name, iname[INPUT(n)->type]);
966 if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) || 1019 if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) ||
967 (EM28XX_VMUX_CABLE == INPUT(n)->type)) 1020 (EM28XX_VMUX_CABLE == INPUT(n)->type))
968 i->type = V4L2_INPUT_TYPE_TUNER; 1021 i->type = V4L2_INPUT_TYPE_TUNER;
969 for (n = 0; n < ARRAY_SIZE(tvnorms); n++) 1022 for (n = 0; n < ARRAY_SIZE(tvnorms); n++)
970 i->std |= tvnorms[n].id; 1023 i->std |= tvnorms[n].id;
971 return 0; 1024 return 0;
972 } 1025 }
973
974 case VIDIOC_G_INPUT: 1026 case VIDIOC_G_INPUT:
975 { 1027 {
976 int *i = arg; 1028 int *i = arg;
977 *i = dev->ctl_input; 1029 *i = dev->ctl_input;
978
979 return 0;
980 }
981 1030
1031 return 0;
1032 }
982 case VIDIOC_S_INPUT: 1033 case VIDIOC_S_INPUT:
983 { 1034 {
984 int *index = arg; 1035 int *index = arg;
985
986 if (*index >= MAX_EM28XX_INPUT)
987 return -EINVAL;
988 if (0 == INPUT(*index)->type)
989 return -EINVAL;
990 1036
991 down(&dev->lock); 1037 if (*index >= MAX_EM28XX_INPUT)
992 video_mux(dev, *index); 1038 return -EINVAL;
993 up(&dev->lock); 1039 if (0 == INPUT(*index)->type)
1040 return -EINVAL;
994 1041
995 return 0; 1042 mutex_lock(&dev->lock);
996 } 1043 video_mux(dev, *index);
1044 mutex_unlock(&dev->lock);
997 1045
1046 return 0;
1047 }
998 case VIDIOC_G_AUDIO: 1048 case VIDIOC_G_AUDIO:
999 { 1049 {
1000 struct v4l2_audio *a = arg; 1050 struct v4l2_audio *a = arg;
1001 unsigned int index = a->index; 1051 unsigned int index = a->index;
1002 1052
1003 if (a->index > 1) 1053 if (a->index > 1)
1004 return -EINVAL; 1054 return -EINVAL;
1005 memset(a, 0, sizeof(*a)); 1055 memset(a, 0, sizeof(*a));
1006 index = dev->ctl_ainput; 1056 index = dev->ctl_ainput;
1007 1057
1008 if (index == 0) { 1058 if (index == 0) {
1009 strcpy(a->name, "Television"); 1059 strcpy(a->name, "Television");
1010 } else { 1060 } else {
1011 strcpy(a->name, "Line In"); 1061 strcpy(a->name, "Line In");
1012 }
1013 a->capability = V4L2_AUDCAP_STEREO;
1014 a->index = index;
1015 return 0;
1016 } 1062 }
1017 1063 a->capability = V4L2_AUDCAP_STEREO;
1064 a->index = index;
1065 return 0;
1066 }
1018 case VIDIOC_S_AUDIO: 1067 case VIDIOC_S_AUDIO:
1019 { 1068 {
1020 struct v4l2_audio *a = arg; 1069 struct v4l2_audio *a = arg;
1021 if (a->index != dev->ctl_ainput)
1022 return -EINVAL;
1023 1070
1024 return 0; 1071 if (a->index != dev->ctl_ainput)
1025 } 1072 return -EINVAL;
1026 1073
1027 /* --- controls ---------------------------------------------- */ 1074 return 0;
1075 }
1076
1077 /* --- controls ---------------------------------------------- */
1028 case VIDIOC_QUERYCTRL: 1078 case VIDIOC_QUERYCTRL:
1029 { 1079 {
1030 struct v4l2_queryctrl *qc = arg; 1080 struct v4l2_queryctrl *qc = arg;
1031 int i, id=qc->id; 1081 int i, id=qc->id;
1032
1033 memset(qc,0,sizeof(*qc));
1034 qc->id=id;
1035
1036 if (!dev->has_msp34xx) {
1037 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
1038 if (qc->id && qc->id == em28xx_qctrl[i].id) {
1039 memcpy(qc, &(em28xx_qctrl[i]),
1040 sizeof(*qc));
1041 return 0;
1042 }
1043 }
1044 }
1045 if (dev->decoder == EM28XX_TVP5150) {
1046 em28xx_i2c_call_clients(dev,cmd,qc);
1047 if (qc->type)
1048 return 0;
1049 else
1050 return -EINVAL;
1051 }
1052 for (i = 0; i < ARRAY_SIZE(saa711x_qctrl); i++) {
1053 if (qc->id && qc->id == saa711x_qctrl[i].id) {
1054 memcpy(qc, &(saa711x_qctrl[i]),
1055 sizeof(*qc));
1056 return 0;
1057 }
1058 }
1059 1082
1060 return -EINVAL; 1083 memset(qc,0,sizeof(*qc));
1061 } 1084 qc->id=id;
1062 1085
1063 case VIDIOC_G_CTRL: 1086 if (!dev->has_msp34xx) {
1064 { 1087 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
1065 struct v4l2_control *ctrl = arg; 1088 if (qc->id && qc->id == em28xx_qctrl[i].id) {
1066 int retval=-EINVAL; 1089 memcpy(qc, &(em28xx_qctrl[i]),
1067 1090 sizeof(*qc));
1068 if (!dev->has_msp34xx)
1069 retval=em28xx_get_ctrl(dev, ctrl);
1070 if (retval==-EINVAL) {
1071 if (dev->decoder == EM28XX_TVP5150) {
1072 em28xx_i2c_call_clients(dev,cmd,arg);
1073 return 0; 1091 return 0;
1074 } 1092 }
1075 1093 }
1076 return saa711x_get_ctrl(dev, ctrl);
1077 } else return retval;
1078 } 1094 }
1095 em28xx_i2c_call_clients(dev,cmd,qc);
1096 if (qc->type)
1097 return 0;
1098 else
1099 return -EINVAL;
1100 }
1101 case VIDIOC_G_CTRL:
1102 {
1103 struct v4l2_control *ctrl = arg;
1104 int retval=-EINVAL;
1079 1105
1106 if (!dev->has_msp34xx)
1107 retval=em28xx_get_ctrl(dev, ctrl);
1108 if (retval==-EINVAL) {
1109 em28xx_i2c_call_clients(dev,cmd,arg);
1110 return 0;
1111 } else return retval;
1112 }
1080 case VIDIOC_S_CTRL: 1113 case VIDIOC_S_CTRL:
1081 { 1114 {
1082 struct v4l2_control *ctrl = arg; 1115 struct v4l2_control *ctrl = arg;
1083 u8 i; 1116 u8 i;
1084 1117
1085 if (!dev->has_msp34xx){ 1118 if (!dev->has_msp34xx){
1086 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { 1119 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
1087 if (ctrl->id == em28xx_qctrl[i].id) { 1120 if (ctrl->id == em28xx_qctrl[i].id) {
1088 if (ctrl->value < 1121 if (ctrl->value <
1089 em28xx_qctrl[i].minimum 1122 em28xx_qctrl[i].minimum
1090 || ctrl->value > 1123 || ctrl->value >
1091 em28xx_qctrl[i].maximum) 1124 em28xx_qctrl[i].maximum)
1092 return -ERANGE; 1125 return -ERANGE;
1093 return em28xx_set_ctrl(dev, ctrl); 1126 return em28xx_set_ctrl(dev, ctrl);
1094 }
1095 }
1096 }
1097
1098 if (dev->decoder == EM28XX_TVP5150) {
1099 em28xx_i2c_call_clients(dev,cmd,arg);
1100 return 0;
1101 } else if (!dev->has_msp34xx) {
1102 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
1103 if (ctrl->id == em28xx_qctrl[i].id) {
1104 if (ctrl->value <
1105 em28xx_qctrl[i].minimum
1106 || ctrl->value >
1107 em28xx_qctrl[i].maximum)
1108 return -ERANGE;
1109 return em28xx_set_ctrl(dev, ctrl);
1110 }
1111 }
1112 for (i = 0; i < ARRAY_SIZE(saa711x_qctrl); i++) {
1113 if (ctrl->id == saa711x_qctrl[i].id) {
1114 if (ctrl->value <
1115 saa711x_qctrl[i].minimum
1116 || ctrl->value >
1117 saa711x_qctrl[i].maximum)
1118 return -ERANGE;
1119 return saa711x_set_ctrl(dev, ctrl);
1120 }
1121 } 1127 }
1122 } 1128 }
1123
1124 return -EINVAL;
1125 } 1129 }
1126 1130
1127 /* --- tuner ioctls ------------------------------------------ */ 1131 em28xx_i2c_call_clients(dev,cmd,arg);
1132 return 0;
1133 }
1134 /* --- tuner ioctls ------------------------------------------ */
1128 case VIDIOC_G_TUNER: 1135 case VIDIOC_G_TUNER:
1129 { 1136 {
1130 struct v4l2_tuner *t = arg; 1137 struct v4l2_tuner *t = arg;
1131 int status = 0; 1138 int status = 0;
1132 1139
1133 if (0 != t->index) 1140 if (0 != t->index)
1134 return -EINVAL; 1141 return -EINVAL;
1135 1142
1136 memset(t, 0, sizeof(*t)); 1143 memset(t, 0, sizeof(*t));
1137 strcpy(t->name, "Tuner"); 1144 strcpy(t->name, "Tuner");
1138 t->type = V4L2_TUNER_ANALOG_TV; 1145 t->type = V4L2_TUNER_ANALOG_TV;
1139 t->capability = V4L2_TUNER_CAP_NORM; 1146 t->capability = V4L2_TUNER_CAP_NORM;
1140 t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */ 1147 t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */
1141/* t->signal = 0xffff;*/ 1148/* t->signal = 0xffff;*/
1142/* em28xx_i2c_call_clients(dev,VIDIOC_G_TUNER,t);*/ 1149/* em28xx_i2c_call_clients(dev,VIDIOC_G_TUNER,t);*/
1143 /* No way to get signal strength? */ 1150 /* No way to get signal strength? */
1144 down(&dev->lock); 1151 mutex_lock(&dev->lock);
1145 em28xx_i2c_call_clients(dev, DECODER_GET_STATUS, 1152 em28xx_i2c_call_clients(dev, DECODER_GET_STATUS,
1146 &status); 1153 &status);
1147 up(&dev->lock); 1154 mutex_unlock(&dev->lock);
1148 t->signal = 1155 t->signal =
1149 (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0; 1156 (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0;
1150 1157
1151 em28xx_videodbg("VIDIO_G_TUNER: signal=%x, afc=%x\n", t->signal, 1158 em28xx_videodbg("VIDIO_G_TUNER: signal=%x, afc=%x\n", t->signal,
1152 t->afc); 1159 t->afc);
1153 return 0; 1160 return 0;
1154 } 1161 }
1155 case VIDIOC_S_TUNER: 1162 case VIDIOC_S_TUNER:
1156 { 1163 {
1157 struct v4l2_tuner *t = arg; 1164 struct v4l2_tuner *t = arg;
1158 int status = 0; 1165 int status = 0;
1159 1166
1160 if (0 != t->index) 1167 if (0 != t->index)
1161 return -EINVAL; 1168 return -EINVAL;
1162 memset(t, 0, sizeof(*t)); 1169 memset(t, 0, sizeof(*t));
1163 strcpy(t->name, "Tuner"); 1170 strcpy(t->name, "Tuner");
1164 t->type = V4L2_TUNER_ANALOG_TV; 1171 t->type = V4L2_TUNER_ANALOG_TV;
1165 t->capability = V4L2_TUNER_CAP_NORM; 1172 t->capability = V4L2_TUNER_CAP_NORM;
1166 t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */ 1173 t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */
1167/* t->signal = 0xffff; */ 1174/* t->signal = 0xffff; */
1168 /* No way to get signal strength? */ 1175 /* No way to get signal strength? */
1169 down(&dev->lock); 1176 mutex_lock(&dev->lock);
1170 em28xx_i2c_call_clients(dev, DECODER_GET_STATUS, 1177 em28xx_i2c_call_clients(dev, DECODER_GET_STATUS,
1171 &status); 1178 &status);
1172 up(&dev->lock); 1179 mutex_unlock(&dev->lock);
1173 t->signal = 1180 t->signal =
1174 (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0; 1181 (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0;
1175 1182
1176 em28xx_videodbg("VIDIO_S_TUNER: signal=%x, afc=%x\n", 1183 em28xx_videodbg("VIDIO_S_TUNER: signal=%x, afc=%x\n",
1177 t->signal, t->afc); 1184 t->signal, t->afc);
1178 return 0; 1185 return 0;
1179 } 1186 }
1180 case VIDIOC_G_FREQUENCY: 1187 case VIDIOC_G_FREQUENCY:
1181 { 1188 {
1182 struct v4l2_frequency *f = arg; 1189 struct v4l2_frequency *f = arg;
1183 1190
1184 memset(f, 0, sizeof(*f)); 1191 memset(f, 0, sizeof(*f));
1185 f->type = V4L2_TUNER_ANALOG_TV; 1192 f->type = V4L2_TUNER_ANALOG_TV;
1186 f->frequency = dev->ctl_freq; 1193 f->frequency = dev->ctl_freq;
1187 1194
1188 return 0; 1195 return 0;
1189 } 1196 }
1190 case VIDIOC_S_FREQUENCY: 1197 case VIDIOC_S_FREQUENCY:
1191 { 1198 {
1192 struct v4l2_frequency *f = arg; 1199 struct v4l2_frequency *f = arg;
1193
1194 if (0 != f->tuner)
1195 return -EINVAL;
1196 1200
1197 if (V4L2_TUNER_ANALOG_TV != f->type) 1201 if (0 != f->tuner)
1198 return -EINVAL; 1202 return -EINVAL;
1199 1203
1200 down(&dev->lock); 1204 if (V4L2_TUNER_ANALOG_TV != f->type)
1201 dev->ctl_freq = f->frequency; 1205 return -EINVAL;
1202 em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f);
1203 up(&dev->lock);
1204 return 0;
1205 }
1206 1206
1207 mutex_lock(&dev->lock);
1208 dev->ctl_freq = f->frequency;
1209 em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f);
1210 mutex_unlock(&dev->lock);
1211 return 0;
1212 }
1207 case VIDIOC_CROPCAP: 1213 case VIDIOC_CROPCAP:
1208 { 1214 {
1209 struct v4l2_cropcap *cc = arg; 1215 struct v4l2_cropcap *cc = arg;
1210 1216
1211 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1217 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1212 return -EINVAL; 1218 return -EINVAL;
1213 cc->bounds.left = 0; 1219 cc->bounds.left = 0;
1214 cc->bounds.top = 0; 1220 cc->bounds.top = 0;
1215 cc->bounds.width = dev->width; 1221 cc->bounds.width = dev->width;
1216 cc->bounds.height = dev->height; 1222 cc->bounds.height = dev->height;
1217 cc->defrect = cc->bounds; 1223 cc->defrect = cc->bounds;
1218 cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */ 1224 cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
1219 cc->pixelaspect.denominator = 59; 1225 cc->pixelaspect.denominator = 59;
1220 return 0; 1226 return 0;
1221 } 1227 }
1222 case VIDIOC_STREAMON: 1228 case VIDIOC_STREAMON:
1223 { 1229 {
1224 int *type = arg; 1230 int *type = arg;
1225 1231
1226 if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE 1232 if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE
1227 || dev->io != IO_MMAP) 1233 || dev->io != IO_MMAP)
1228 return -EINVAL; 1234 return -EINVAL;
1229 1235
1230 if (list_empty(&dev->inqueue)) 1236 if (list_empty(&dev->inqueue))
1231 return -EINVAL; 1237 return -EINVAL;
1232 1238
1233 dev->stream = STREAM_ON; /* FIXME: Start video capture here? */ 1239 dev->stream = STREAM_ON; /* FIXME: Start video capture here? */
1234 1240
1235 em28xx_videodbg("VIDIOC_STREAMON: starting stream\n"); 1241 em28xx_videodbg("VIDIOC_STREAMON: starting stream\n");
1236 1242
1237 return 0; 1243 return 0;
1238 } 1244 }
1239 case VIDIOC_STREAMOFF: 1245 case VIDIOC_STREAMOFF:
1240 { 1246 {
1241 int *type = arg; 1247 int *type = arg;
1242 int ret; 1248 int ret;
1243
1244 if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE
1245 || dev->io != IO_MMAP)
1246 return -EINVAL;
1247 1249
1248 if (dev->stream == STREAM_ON) { 1250 if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE
1249 em28xx_videodbg ("VIDIOC_STREAMOFF: interrupting stream\n"); 1251 || dev->io != IO_MMAP)
1250 if ((ret = em28xx_stream_interrupt(dev))) 1252 return -EINVAL;
1251 return ret;
1252 }
1253 em28xx_empty_framequeues(dev);
1254 1253
1255 return 0; 1254 if (dev->stream == STREAM_ON) {
1255 em28xx_videodbg ("VIDIOC_STREAMOFF: interrupting stream\n");
1256 if ((ret = em28xx_stream_interrupt(dev)))
1257 return ret;
1256 } 1258 }
1259 em28xx_empty_framequeues(dev);
1260
1261 return 0;
1262 }
1257 default: 1263 default:
1258 return v4l_compat_translate_ioctl(inode, filp, cmd, arg, 1264 return v4l_compat_translate_ioctl(inode, filp, cmd, arg,
1259 driver_ioctl); 1265 driver_ioctl);
@@ -1283,327 +1289,170 @@ static int em28xx_video_do_ioctl(struct inode *inode, struct file *filp,
1283 /* --- capabilities ------------------------------------------ */ 1289 /* --- capabilities ------------------------------------------ */
1284 case VIDIOC_QUERYCAP: 1290 case VIDIOC_QUERYCAP:
1285 { 1291 {
1286 struct v4l2_capability *cap = arg; 1292 struct v4l2_capability *cap = arg;
1287 1293
1288 memset(cap, 0, sizeof(*cap)); 1294 memset(cap, 0, sizeof(*cap));
1289 strlcpy(cap->driver, "em28xx", sizeof(cap->driver)); 1295 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
1290 strlcpy(cap->card, em28xx_boards[dev->model].name, 1296 strlcpy(cap->card, em28xx_boards[dev->model].name,
1291 sizeof(cap->card)); 1297 sizeof(cap->card));
1292 strlcpy(cap->bus_info, dev->udev->dev.bus_id, 1298 strlcpy(cap->bus_info, dev->udev->dev.bus_id,
1293 sizeof(cap->bus_info)); 1299 sizeof(cap->bus_info));
1294 cap->version = EM28XX_VERSION_CODE; 1300 cap->version = EM28XX_VERSION_CODE;
1295 cap->capabilities = 1301 cap->capabilities =
1296 V4L2_CAP_VIDEO_CAPTURE | 1302 V4L2_CAP_SLICED_VBI_CAPTURE |
1297 V4L2_CAP_AUDIO | 1303 V4L2_CAP_VIDEO_CAPTURE |
1298 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; 1304 V4L2_CAP_AUDIO |
1299 if (dev->has_tuner) 1305 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1300 cap->capabilities |= V4L2_CAP_TUNER; 1306 if (dev->has_tuner)
1301 return 0; 1307 cap->capabilities |= V4L2_CAP_TUNER;
1302 } 1308 return 0;
1303 1309 }
1304 /* --- capture ioctls ---------------------------------------- */ 1310 /* --- capture ioctls ---------------------------------------- */
1305 case VIDIOC_ENUM_FMT: 1311 case VIDIOC_ENUM_FMT:
1306 { 1312 {
1307 struct v4l2_fmtdesc *fmtd = arg; 1313 struct v4l2_fmtdesc *fmtd = arg;
1308
1309 if (fmtd->index != 0)
1310 return -EINVAL;
1311 memset(fmtd, 0, sizeof(*fmtd));
1312 fmtd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1313 strcpy(fmtd->description, "Packed YUY2");
1314 fmtd->pixelformat = V4L2_PIX_FMT_YUYV;
1315 memset(fmtd->reserved, 0, sizeof(fmtd->reserved));
1316 return 0;
1317 }
1318 1314
1315 if (fmtd->index != 0)
1316 return -EINVAL;
1317 memset(fmtd, 0, sizeof(*fmtd));
1318 fmtd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1319 strcpy(fmtd->description, "Packed YUY2");
1320 fmtd->pixelformat = V4L2_PIX_FMT_YUYV;
1321 memset(fmtd->reserved, 0, sizeof(fmtd->reserved));
1322 return 0;
1323 }
1319 case VIDIOC_G_FMT: 1324 case VIDIOC_G_FMT:
1320 { 1325 return em28xx_get_fmt(dev, (struct v4l2_format *) arg);
1321 struct v4l2_format *format = arg;
1322
1323 em28xx_videodbg("VIDIOC_G_FMT: type=%s\n",
1324 format->type ==
1325 V4L2_BUF_TYPE_VIDEO_CAPTURE ?
1326 "V4L2_BUF_TYPE_VIDEO_CAPTURE" : format->type ==
1327 V4L2_BUF_TYPE_VBI_CAPTURE ?
1328 "V4L2_BUF_TYPE_VBI_CAPTURE " :
1329 "not supported");
1330
1331 if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1332 return -EINVAL;
1333
1334 format->fmt.pix.width = dev->width;
1335 format->fmt.pix.height = dev->height;
1336 format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
1337 format->fmt.pix.bytesperline = dev->bytesperline;
1338 format->fmt.pix.sizeimage = dev->frame_size;
1339 format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1340 format->fmt.pix.field = dev->interlaced ? V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP; /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */
1341
1342 em28xx_videodbg("VIDIOC_G_FMT: %dx%d\n", dev->width,
1343 dev->height);
1344 return 0;
1345 }
1346 1326
1347 case VIDIOC_TRY_FMT: 1327 case VIDIOC_TRY_FMT:
1348 case VIDIOC_S_FMT: 1328 case VIDIOC_S_FMT:
1349 { 1329 return em28xx_set_fmt(dev, cmd, (struct v4l2_format *)arg);
1350 struct v4l2_format *format = arg;
1351 u32 i;
1352 int ret = 0;
1353 int width = format->fmt.pix.width;
1354 int height = format->fmt.pix.height;
1355 unsigned int hscale, vscale;
1356 unsigned int maxh, maxw;
1357
1358 maxw = norm_maxw(dev);
1359 maxh = norm_maxh(dev);
1360
1361/* int both_fields; */
1362
1363 em28xx_videodbg("%s: type=%s\n",
1364 cmd ==
1365 VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" :
1366 "VIDIOC_S_FMT",
1367 format->type ==
1368 V4L2_BUF_TYPE_VIDEO_CAPTURE ?
1369 "V4L2_BUF_TYPE_VIDEO_CAPTURE" : format->type ==
1370 V4L2_BUF_TYPE_VBI_CAPTURE ?
1371 "V4L2_BUF_TYPE_VBI_CAPTURE " :
1372 "not supported");
1373
1374 if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1375 return -EINVAL;
1376
1377 em28xx_videodbg("%s: requested %dx%d\n",
1378 cmd ==
1379 VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" :
1380 "VIDIOC_S_FMT", format->fmt.pix.width,
1381 format->fmt.pix.height);
1382
1383 /* FIXME: Move some code away from here */
1384 /* width must even because of the YUYV format */
1385 /* height must be even because of interlacing */
1386 height &= 0xfffe;
1387 width &= 0xfffe;
1388
1389 if (height < 32)
1390 height = 32;
1391 if (height > maxh)
1392 height = maxh;
1393 if (width < 48)
1394 width = 48;
1395 if (width > maxw)
1396 width = maxw;
1397
1398 if(dev->is_em2800){
1399 /* the em2800 can only scale down to 50% */
1400 if(height % (maxh / 2))
1401 height=maxh;
1402 if(width % (maxw / 2))
1403 width=maxw;
1404 /* according to empiatech support */
1405 /* the MaxPacketSize is to small to support */
1406 /* framesizes larger than 640x480 @ 30 fps */
1407 /* or 640x576 @ 25 fps. As this would cut */
1408 /* of a part of the image we prefer */
1409 /* 360x576 or 360x480 for now */
1410 if(width == maxw && height == maxh)
1411 width /= 2;
1412 }
1413
1414 if ((hscale =
1415 (((unsigned long)maxw) << 12) / width - 4096L) >=
1416 0x4000)
1417 hscale = 0x3fff;
1418 width =
1419 (((unsigned long)maxw) << 12) / (hscale + 4096L);
1420
1421 if ((vscale =
1422 (((unsigned long)maxh) << 12) / height - 4096L) >=
1423 0x4000)
1424 vscale = 0x3fff;
1425 height =
1426 (((unsigned long)maxh) << 12) / (vscale + 4096L);
1427
1428 format->fmt.pix.width = width;
1429 format->fmt.pix.height = height;
1430 format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
1431 format->fmt.pix.bytesperline = width * 2;
1432 format->fmt.pix.sizeimage = width * 2 * height;
1433 format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1434 format->fmt.pix.field = V4L2_FIELD_INTERLACED;
1435
1436 em28xx_videodbg("%s: returned %dx%d (%d, %d)\n",
1437 cmd ==
1438 VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" :
1439 "VIDIOC_S_FMT", format->fmt.pix.width,
1440 format->fmt.pix.height, hscale, vscale);
1441
1442 if (cmd == VIDIOC_TRY_FMT)
1443 return 0;
1444
1445 for (i = 0; i < dev->num_frames; i++)
1446 if (dev->frame[i].vma_use_count) {
1447 em28xx_videodbg("VIDIOC_S_FMT failed. "
1448 "Unmap the buffers first.\n");
1449 return -EINVAL;
1450 }
1451 1330
1452 /* stop io in case it is already in progress */ 1331 case VIDIOC_REQBUFS:
1453 if (dev->stream == STREAM_ON) { 1332 {
1454 em28xx_videodbg("VIDIOC_SET_FMT: interupting stream\n"); 1333 struct v4l2_requestbuffers *rb = arg;
1455 if ((ret = em28xx_stream_interrupt(dev))) 1334 u32 i;
1456 return ret; 1335 int ret;
1457 }
1458 1336
1459 em28xx_release_buffers(dev); 1337 if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1460 dev->io = IO_NONE; 1338 rb->memory != V4L2_MEMORY_MMAP)
1461 1339 return -EINVAL;
1462 /* set new image size */
1463 dev->width = width;
1464 dev->height = height;
1465 dev->frame_size = dev->width * dev->height * 2;
1466 dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */
1467 dev->bytesperline = dev->width * 2;
1468 dev->hscale = hscale;
1469 dev->vscale = vscale;
1470/* dev->both_fileds = both_fileds; */
1471 em28xx_uninit_isoc(dev);
1472 em28xx_set_alternate(dev);
1473 em28xx_capture_start(dev, 1);
1474 em28xx_resolution_set(dev);
1475 em28xx_init_isoc(dev);
1476 1340
1477 return 0; 1341 if (dev->io == IO_READ) {
1342 em28xx_videodbg ("method is set to read;"
1343 " close and open the device again to"
1344 " choose the mmap I/O method\n");
1345 return -EINVAL;
1478 } 1346 }
1479 1347
1480 /* --- streaming capture ------------------------------------- */ 1348 for (i = 0; i < dev->num_frames; i++)
1481 case VIDIOC_REQBUFS: 1349 if (dev->frame[i].vma_use_count) {
1482 { 1350 em28xx_videodbg ("VIDIOC_REQBUFS failed; previous buffers are still mapped\n");
1483 struct v4l2_requestbuffers *rb = arg;
1484 u32 i;
1485 int ret;
1486
1487 if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1488 rb->memory != V4L2_MEMORY_MMAP)
1489 return -EINVAL;
1490
1491 if (dev->io == IO_READ) {
1492 em28xx_videodbg ("method is set to read;"
1493 " close and open the device again to"
1494 " choose the mmap I/O method\n");
1495 return -EINVAL; 1351 return -EINVAL;
1496 } 1352 }
1497 1353
1498 for (i = 0; i < dev->num_frames; i++) 1354 if (dev->stream == STREAM_ON) {
1499 if (dev->frame[i].vma_use_count) { 1355 em28xx_videodbg("VIDIOC_REQBUFS: interrupting stream\n");
1500 em28xx_videodbg ("VIDIOC_REQBUFS failed; previous buffers are still mapped\n"); 1356 if ((ret = em28xx_stream_interrupt(dev)))
1501 return -EINVAL; 1357 return ret;
1502 } 1358 }
1503
1504 if (dev->stream == STREAM_ON) {
1505 em28xx_videodbg("VIDIOC_REQBUFS: interrupting stream\n");
1506 if ((ret = em28xx_stream_interrupt(dev)))
1507 return ret;
1508 }
1509
1510 em28xx_empty_framequeues(dev);
1511 1359
1512 em28xx_release_buffers(dev); 1360 em28xx_empty_framequeues(dev);
1513 if (rb->count)
1514 rb->count =
1515 em28xx_request_buffers(dev, rb->count);
1516 1361
1517 dev->frame_current = NULL; 1362 em28xx_release_buffers(dev);
1363 if (rb->count)
1364 rb->count =
1365 em28xx_request_buffers(dev, rb->count);
1518 1366
1519 em28xx_videodbg ("VIDIOC_REQBUFS: setting io method to mmap: num bufs %i\n", 1367 dev->frame_current = NULL;
1520 rb->count);
1521 dev->io = rb->count ? IO_MMAP : IO_NONE;
1522 return 0;
1523 }
1524 1368
1369 em28xx_videodbg ("VIDIOC_REQBUFS: setting io method to mmap: num bufs %i\n",
1370 rb->count);
1371 dev->io = rb->count ? IO_MMAP : IO_NONE;
1372 return 0;
1373 }
1525 case VIDIOC_QUERYBUF: 1374 case VIDIOC_QUERYBUF:
1526 { 1375 {
1527 struct v4l2_buffer *b = arg; 1376 struct v4l2_buffer *b = arg;
1528 1377
1529 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || 1378 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1530 b->index >= dev->num_frames || dev->io != IO_MMAP) 1379 b->index >= dev->num_frames || dev->io != IO_MMAP)
1531 return -EINVAL; 1380 return -EINVAL;
1532 1381
1533 memcpy(b, &dev->frame[b->index].buf, sizeof(*b)); 1382 memcpy(b, &dev->frame[b->index].buf, sizeof(*b));
1534 1383
1535 if (dev->frame[b->index].vma_use_count) { 1384 if (dev->frame[b->index].vma_use_count) {
1536 b->flags |= V4L2_BUF_FLAG_MAPPED; 1385 b->flags |= V4L2_BUF_FLAG_MAPPED;
1537 }
1538 if (dev->frame[b->index].state == F_DONE)
1539 b->flags |= V4L2_BUF_FLAG_DONE;
1540 else if (dev->frame[b->index].state != F_UNUSED)
1541 b->flags |= V4L2_BUF_FLAG_QUEUED;
1542 return 0;
1543 } 1386 }
1387 if (dev->frame[b->index].state == F_DONE)
1388 b->flags |= V4L2_BUF_FLAG_DONE;
1389 else if (dev->frame[b->index].state != F_UNUSED)
1390 b->flags |= V4L2_BUF_FLAG_QUEUED;
1391 return 0;
1392 }
1544 case VIDIOC_QBUF: 1393 case VIDIOC_QBUF:
1545 { 1394 {
1546 struct v4l2_buffer *b = arg; 1395 struct v4l2_buffer *b = arg;
1547 unsigned long lock_flags; 1396 unsigned long lock_flags;
1548 1397
1549 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || 1398 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1550 b->index >= dev->num_frames || dev->io != IO_MMAP) { 1399 b->index >= dev->num_frames || dev->io != IO_MMAP) {
1551 return -EINVAL; 1400 return -EINVAL;
1552 } 1401 }
1553 1402
1554 if (dev->frame[b->index].state != F_UNUSED) { 1403 if (dev->frame[b->index].state != F_UNUSED) {
1555 return -EAGAIN; 1404 return -EAGAIN;
1556 } 1405 }
1557 dev->frame[b->index].state = F_QUEUED; 1406 dev->frame[b->index].state = F_QUEUED;
1558 1407
1559 /* add frame to fifo */ 1408 /* add frame to fifo */
1560 spin_lock_irqsave(&dev->queue_lock, lock_flags); 1409 spin_lock_irqsave(&dev->queue_lock, lock_flags);
1561 list_add_tail(&dev->frame[b->index].frame, 1410 list_add_tail(&dev->frame[b->index].frame,
1562 &dev->inqueue); 1411 &dev->inqueue);
1563 spin_unlock_irqrestore(&dev->queue_lock, lock_flags); 1412 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
1564 1413
1565 return 0; 1414 return 0;
1566 } 1415 }
1567 case VIDIOC_DQBUF: 1416 case VIDIOC_DQBUF:
1568 { 1417 {
1569 struct v4l2_buffer *b = arg; 1418 struct v4l2_buffer *b = arg;
1570 struct em28xx_frame_t *f; 1419 struct em28xx_frame_t *f;
1571 unsigned long lock_flags; 1420 unsigned long lock_flags;
1572 int ret = 0; 1421 int ret = 0;
1573 1422
1574 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE 1423 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE
1575 || dev->io != IO_MMAP) 1424 || dev->io != IO_MMAP)
1576 return -EINVAL; 1425 return -EINVAL;
1577 1426
1578 if (list_empty(&dev->outqueue)) { 1427 if (list_empty(&dev->outqueue)) {
1579 if (dev->stream == STREAM_OFF) 1428 if (dev->stream == STREAM_OFF)
1580 return -EINVAL; 1429 return -EINVAL;
1581 if (filp->f_flags & O_NONBLOCK) 1430 if (filp->f_flags & O_NONBLOCK)
1582 return -EAGAIN; 1431 return -EAGAIN;
1583 ret = wait_event_interruptible 1432 ret = wait_event_interruptible
1584 (dev->wait_frame, 1433 (dev->wait_frame,
1585 (!list_empty(&dev->outqueue)) || 1434 (!list_empty(&dev->outqueue)) ||
1586 (dev->state & DEV_DISCONNECTED)); 1435 (dev->state & DEV_DISCONNECTED));
1587 if (ret) 1436 if (ret)
1588 return ret; 1437 return ret;
1589 if (dev->state & DEV_DISCONNECTED) 1438 if (dev->state & DEV_DISCONNECTED)
1590 return -ENODEV; 1439 return -ENODEV;
1591 } 1440 }
1592 1441
1593 spin_lock_irqsave(&dev->queue_lock, lock_flags); 1442 spin_lock_irqsave(&dev->queue_lock, lock_flags);
1594 f = list_entry(dev->outqueue.next, 1443 f = list_entry(dev->outqueue.next,
1595 struct em28xx_frame_t, frame); 1444 struct em28xx_frame_t, frame);
1596 list_del(dev->outqueue.next); 1445 list_del(dev->outqueue.next);
1597 spin_unlock_irqrestore(&dev->queue_lock, lock_flags); 1446 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
1598 1447
1599 f->state = F_UNUSED; 1448 f->state = F_UNUSED;
1600 memcpy(b, &f->buf, sizeof(*b)); 1449 memcpy(b, &f->buf, sizeof(*b));
1601 1450
1602 if (f->vma_use_count) 1451 if (f->vma_use_count)
1603 b->flags |= V4L2_BUF_FLAG_MAPPED; 1452 b->flags |= V4L2_BUF_FLAG_MAPPED;
1604 1453
1605 return 0; 1454 return 0;
1606 } 1455 }
1607 default: 1456 default:
1608 return em28xx_do_ioctl(inode, filp, dev, cmd, arg, 1457 return em28xx_do_ioctl(inode, filp, dev, cmd, arg,
1609 em28xx_video_do_ioctl); 1458 em28xx_video_do_ioctl);
@@ -1621,25 +1470,25 @@ static int em28xx_v4l2_ioctl(struct inode *inode, struct file *filp,
1621 int ret = 0; 1470 int ret = 0;
1622 struct em28xx *dev = filp->private_data; 1471 struct em28xx *dev = filp->private_data;
1623 1472
1624 if (down_interruptible(&dev->fileop_lock)) 1473 if (mutex_lock_interruptible(&dev->fileop_lock))
1625 return -ERESTARTSYS; 1474 return -ERESTARTSYS;
1626 1475
1627 if (dev->state & DEV_DISCONNECTED) { 1476 if (dev->state & DEV_DISCONNECTED) {
1628 em28xx_errdev("v4l2 ioctl: device not present\n"); 1477 em28xx_errdev("v4l2 ioctl: device not present\n");
1629 up(&dev->fileop_lock); 1478 mutex_unlock(&dev->fileop_lock);
1630 return -ENODEV; 1479 return -ENODEV;
1631 } 1480 }
1632 1481
1633 if (dev->state & DEV_MISCONFIGURED) { 1482 if (dev->state & DEV_MISCONFIGURED) {
1634 em28xx_errdev 1483 em28xx_errdev
1635 ("v4l2 ioctl: device is misconfigured; close and open it again\n"); 1484 ("v4l2 ioctl: device is misconfigured; close and open it again\n");
1636 up(&dev->fileop_lock); 1485 mutex_unlock(&dev->fileop_lock);
1637 return -EIO; 1486 return -EIO;
1638 } 1487 }
1639 1488
1640 ret = video_usercopy(inode, filp, cmd, arg, em28xx_video_do_ioctl); 1489 ret = video_usercopy(inode, filp, cmd, arg, em28xx_video_do_ioctl);
1641 1490
1642 up(&dev->fileop_lock); 1491 mutex_unlock(&dev->fileop_lock);
1643 1492
1644 return ret; 1493 return ret;
1645} 1494}
@@ -1673,7 +1522,7 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1673 1522
1674 dev->udev = udev; 1523 dev->udev = udev;
1675 dev->model = model; 1524 dev->model = model;
1676 init_MUTEX(&dev->lock); 1525 mutex_init(&dev->lock);
1677 init_waitqueue_head(&dev->open); 1526 init_waitqueue_head(&dev->open);
1678 1527
1679 dev->em28xx_write_regs = em28xx_write_regs; 1528 dev->em28xx_write_regs = em28xx_write_regs;
@@ -1729,10 +1578,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1729 dev->vpic.depth = 16; 1578 dev->vpic.depth = 16;
1730 dev->vpic.palette = VIDEO_PALETTE_YUV422; 1579 dev->vpic.palette = VIDEO_PALETTE_YUV422;
1731 1580
1581 em28xx_pre_card_setup(dev);
1732#ifdef CONFIG_MODULES 1582#ifdef CONFIG_MODULES
1733 /* request some modules */ 1583 /* request some modules */
1734 if (dev->decoder == EM28XX_SAA7113 || dev->decoder == EM28XX_SAA7114) 1584 if (dev->decoder == EM28XX_SAA7113 || dev->decoder == EM28XX_SAA7114)
1735 request_module("saa711x"); 1585 request_module("saa7115");
1736 if (dev->decoder == EM28XX_TVP5150) 1586 if (dev->decoder == EM28XX_TVP5150)
1737 request_module("tvp5150"); 1587 request_module("tvp5150");
1738 if (dev->has_tuner) 1588 if (dev->has_tuner)
@@ -1744,10 +1594,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1744 if (errCode) { 1594 if (errCode) {
1745 em28xx_errdev("error configuring device\n"); 1595 em28xx_errdev("error configuring device\n");
1746 kfree(dev); 1596 kfree(dev);
1597 em28xx_devused&=~(1<<dev->devno);
1747 return -ENOMEM; 1598 return -ENOMEM;
1748 } 1599 }
1749 1600
1750 down(&dev->lock); 1601 mutex_lock(&dev->lock);
1751 /* register i2c bus */ 1602 /* register i2c bus */
1752 em28xx_i2c_register(dev); 1603 em28xx_i2c_register(dev);
1753 1604
@@ -1757,7 +1608,7 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1757 /* configure the device */ 1608 /* configure the device */
1758 em28xx_config_i2c(dev); 1609 em28xx_config_i2c(dev);
1759 1610
1760 up(&dev->lock); 1611 mutex_unlock(&dev->lock);
1761 1612
1762 errCode = em28xx_config(dev); 1613 errCode = em28xx_config(dev);
1763 1614
@@ -1770,9 +1621,30 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1770 if (NULL == dev->vdev) { 1621 if (NULL == dev->vdev) {
1771 em28xx_errdev("cannot allocate video_device.\n"); 1622 em28xx_errdev("cannot allocate video_device.\n");
1772 kfree(dev); 1623 kfree(dev);
1624 em28xx_devused&=~(1<<dev->devno);
1773 return -ENOMEM; 1625 return -ENOMEM;
1774 } 1626 }
1775 1627
1628 dev->vbi_dev = video_device_alloc();
1629 if (NULL == dev->vbi_dev) {
1630 em28xx_errdev("cannot allocate video_device.\n");
1631 kfree(dev->vdev);
1632 kfree(dev);
1633 em28xx_devused&=~(1<<dev->devno);
1634 return -ENOMEM;
1635 }
1636
1637 /* Fills VBI device info */
1638 dev->vbi_dev->type = VFL_TYPE_VBI;
1639 dev->vbi_dev->hardware = 0;
1640 dev->vbi_dev->fops = &em28xx_v4l_fops;
1641 dev->vbi_dev->minor = -1;
1642 dev->vbi_dev->dev = &dev->udev->dev;
1643 dev->vbi_dev->release = video_device_release;
1644 snprintf(dev->vbi_dev->name, sizeof(dev->vbi_dev->name), "%s#%d %s",
1645 "em28xx",dev->devno,"vbi");
1646
1647 /* Fills CAPTURE device info */
1776 dev->vdev->type = VID_TYPE_CAPTURE; 1648 dev->vdev->type = VID_TYPE_CAPTURE;
1777 if (dev->has_tuner) 1649 if (dev->has_tuner)
1778 dev->vdev->type |= VID_TYPE_TUNER; 1650 dev->vdev->type |= VID_TYPE_TUNER;
@@ -1781,21 +1653,39 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1781 dev->vdev->minor = -1; 1653 dev->vdev->minor = -1;
1782 dev->vdev->dev = &dev->udev->dev; 1654 dev->vdev->dev = &dev->udev->dev;
1783 dev->vdev->release = video_device_release; 1655 dev->vdev->release = video_device_release;
1784 snprintf(dev->vdev->name, sizeof(dev->vdev->name), "%s", 1656 snprintf(dev->vdev->name, sizeof(dev->vbi_dev->name), "%s#%d %s",
1785 "em28xx video"); 1657 "em28xx",dev->devno,"video");
1658
1786 list_add_tail(&dev->devlist,&em28xx_devlist); 1659 list_add_tail(&dev->devlist,&em28xx_devlist);
1787 1660
1788 /* register v4l2 device */ 1661 /* register v4l2 device */
1789 down(&dev->lock); 1662 mutex_lock(&dev->lock);
1790 if ((retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1))) { 1663 if ((retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
1664 video_nr[dev->devno]))) {
1791 em28xx_errdev("unable to register video device (error=%i).\n", 1665 em28xx_errdev("unable to register video device (error=%i).\n",
1792 retval); 1666 retval);
1793 up(&dev->lock); 1667 mutex_unlock(&dev->lock);
1794 list_del(&dev->devlist); 1668 list_del(&dev->devlist);
1795 video_device_release(dev->vdev); 1669 video_device_release(dev->vdev);
1796 kfree(dev); 1670 kfree(dev);
1671 em28xx_devused&=~(1<<dev->devno);
1797 return -ENODEV; 1672 return -ENODEV;
1798 } 1673 }
1674
1675 if (video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
1676 vbi_nr[dev->devno]) < 0) {
1677 printk("unable to register vbi device\n");
1678 mutex_unlock(&dev->lock);
1679 list_del(&dev->devlist);
1680 video_device_release(dev->vbi_dev);
1681 video_device_release(dev->vdev);
1682 kfree(dev);
1683 em28xx_devused&=~(1<<dev->devno);
1684 return -ENODEV;
1685 } else {
1686 printk("registered VBI\n");
1687 }
1688
1799 if (dev->has_msp34xx) { 1689 if (dev->has_msp34xx) {
1800 /* Send a reset to other chips via gpio */ 1690 /* Send a reset to other chips via gpio */
1801 em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1); 1691 em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1);
@@ -1806,10 +1696,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1806 } 1696 }
1807 video_mux(dev, 0); 1697 video_mux(dev, 0);
1808 1698
1809 up(&dev->lock); 1699 mutex_unlock(&dev->lock);
1810 1700
1811 em28xx_info("V4L2 device registered as /dev/video%d\n", 1701 em28xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n",
1812 dev->vdev->minor); 1702 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN,
1703 dev->vbi_dev->minor-MINOR_VFL_TYPE_VBI_MIN);
1813 1704
1814 return 0; 1705 return 0;
1815} 1706}
@@ -1831,6 +1722,9 @@ static int em28xx_usb_probe(struct usb_interface *interface,
1831 udev = usb_get_dev(interface_to_usbdev(interface)); 1722 udev = usb_get_dev(interface_to_usbdev(interface));
1832 ifnum = interface->altsetting[0].desc.bInterfaceNumber; 1723 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
1833 1724
1725 /* Check to see next free device and mark as used */
1726 nr=find_first_zero_bit(&em28xx_devused,EM28XX_MAXBOARDS);
1727 em28xx_devused|=1<<nr;
1834 1728
1835 /* Don't register audio interfaces */ 1729 /* Don't register audio interfaces */
1836 if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) { 1730 if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) {
@@ -1838,6 +1732,8 @@ static int em28xx_usb_probe(struct usb_interface *interface,
1838 udev->descriptor.idVendor,udev->descriptor.idProduct, 1732 udev->descriptor.idVendor,udev->descriptor.idProduct,
1839 ifnum, 1733 ifnum,
1840 interface->altsetting[0].desc.bInterfaceClass); 1734 interface->altsetting[0].desc.bInterfaceClass);
1735
1736 em28xx_devused&=~(1<<nr);
1841 return -ENODEV; 1737 return -ENODEV;
1842 } 1738 }
1843 1739
@@ -1852,18 +1748,20 @@ static int em28xx_usb_probe(struct usb_interface *interface,
1852 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != 1748 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
1853 USB_ENDPOINT_XFER_ISOC) { 1749 USB_ENDPOINT_XFER_ISOC) {
1854 em28xx_err(DRIVER_NAME " probing error: endpoint is non-ISO endpoint!\n"); 1750 em28xx_err(DRIVER_NAME " probing error: endpoint is non-ISO endpoint!\n");
1751 em28xx_devused&=~(1<<nr);
1855 return -ENODEV; 1752 return -ENODEV;
1856 } 1753 }
1857 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) { 1754 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) {
1858 em28xx_err(DRIVER_NAME " probing error: endpoint is ISO OUT endpoint!\n"); 1755 em28xx_err(DRIVER_NAME " probing error: endpoint is ISO OUT endpoint!\n");
1756 em28xx_devused&=~(1<<nr);
1859 return -ENODEV; 1757 return -ENODEV;
1860 } 1758 }
1861 1759
1862 model=id->driver_info; 1760 model=id->driver_info;
1863 nr=interface->minor;
1864 1761
1865 if (nr>EM28XX_MAXBOARDS) { 1762 if (nr >= EM28XX_MAXBOARDS) {
1866 printk (DRIVER_NAME ": Supports only %i em28xx boards.\n",EM28XX_MAXBOARDS); 1763 printk (DRIVER_NAME ": Supports only %i em28xx boards.\n",EM28XX_MAXBOARDS);
1764 em28xx_devused&=~(1<<nr);
1867 return -ENOMEM; 1765 return -ENOMEM;
1868 } 1766 }
1869 1767
@@ -1871,19 +1769,24 @@ static int em28xx_usb_probe(struct usb_interface *interface,
1871 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1769 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1872 if (dev == NULL) { 1770 if (dev == NULL) {
1873 em28xx_err(DRIVER_NAME ": out of memory!\n"); 1771 em28xx_err(DRIVER_NAME ": out of memory!\n");
1772 em28xx_devused&=~(1<<nr);
1874 return -ENOMEM; 1773 return -ENOMEM;
1875 } 1774 }
1876 1775
1776 snprintf(dev->name, 29, "em28xx #%d", nr);
1777 dev->devno=nr;
1778
1877 /* compute alternate max packet sizes */ 1779 /* compute alternate max packet sizes */
1878 uif = udev->actconfig->interface[0]; 1780 uif = udev->actconfig->interface[0];
1879 1781
1880 dev->num_alt=uif->num_altsetting; 1782 dev->num_alt=uif->num_altsetting;
1881 printk(DRIVER_NAME ": Alternate settings: %i\n",dev->num_alt); 1783 em28xx_info("Alternate settings: %i\n",dev->num_alt);
1882// dev->alt_max_pkt_size = kmalloc(sizeof(*dev->alt_max_pkt_size)* 1784// dev->alt_max_pkt_size = kmalloc(sizeof(*dev->alt_max_pkt_size)*
1883 dev->alt_max_pkt_size = kmalloc(32* 1785 dev->alt_max_pkt_size = kmalloc(32*
1884 dev->num_alt,GFP_KERNEL); 1786 dev->num_alt,GFP_KERNEL);
1885 if (dev->alt_max_pkt_size == NULL) { 1787 if (dev->alt_max_pkt_size == NULL) {
1886 em28xx_err(DRIVER_NAME ": out of memory!\n"); 1788 em28xx_errdev("out of memory!\n");
1789 em28xx_devused&=~(1<<nr);
1887 return -ENOMEM; 1790 return -ENOMEM;
1888 } 1791 }
1889 1792
@@ -1892,27 +1795,26 @@ static int em28xx_usb_probe(struct usb_interface *interface,
1892 wMaxPacketSize); 1795 wMaxPacketSize);
1893 dev->alt_max_pkt_size[i] = 1796 dev->alt_max_pkt_size[i] =
1894 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); 1797 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1895 printk(DRIVER_NAME ": Alternate setting %i, max size= %i\n",i, 1798 em28xx_info("Alternate setting %i, max size= %i\n",i,
1896 dev->alt_max_pkt_size[i]); 1799 dev->alt_max_pkt_size[i]);
1897 } 1800 }
1898 1801
1899 snprintf(dev->name, 29, "em28xx #%d", nr);
1900
1901 if ((card[nr]>=0)&&(card[nr]<em28xx_bcount)) 1802 if ((card[nr]>=0)&&(card[nr]<em28xx_bcount))
1902 model=card[nr]; 1803 model=card[nr];
1903 1804
1904 if ((model==EM2800_BOARD_UNKNOWN)||(model==EM2820_BOARD_UNKNOWN)) { 1805 if ((model==EM2800_BOARD_UNKNOWN)||(model==EM2820_BOARD_UNKNOWN)) {
1905 printk( "%s: Your board has no eeprom inside it and thus can't\n" 1806 em28xx_errdev( "Your board has no eeprom inside it and thus can't\n"
1906 "%s: be autodetected. Please pass card=<n> insmod option to\n" 1807 "%s: be autodetected. Please pass card=<n> insmod option to\n"
1907 "%s: workaround that. Redirect complaints to the vendor of\n" 1808 "%s: workaround that. Redirect complaints to the vendor of\n"
1908 "%s: the TV card. Best regards,\n" 1809 "%s: the TV card. Generic type will be used."
1810 "%s: Best regards,\n"
1909 "%s: -- tux\n", 1811 "%s: -- tux\n",
1910 dev->name,dev->name,dev->name,dev->name,dev->name); 1812 dev->name,dev->name,dev->name,dev->name,dev->name);
1911 printk("%s: Here is a list of valid choices for the card=<n> insmod option:\n", 1813 em28xx_errdev("%s: Here is a list of valid choices for the card=<n> insmod option:\n",
1912 dev->name); 1814 dev->name);
1913 for (i = 0; i < em28xx_bcount; i++) { 1815 for (i = 0; i < em28xx_bcount; i++) {
1914 printk("%s: card=%d -> %s\n", 1816 em28xx_errdev(" card=%d -> %s\n", i,
1915 dev->name, i, em28xx_boards[i].name); 1817 em28xx_boards[i].name);
1916 } 1818 }
1917 } 1819 }
1918 1820
@@ -1938,15 +1840,12 @@ static void em28xx_usb_disconnect(struct usb_interface *interface)
1938 struct em28xx *dev = usb_get_intfdata(interface); 1840 struct em28xx *dev = usb_get_intfdata(interface);
1939 usb_set_intfdata(interface, NULL); 1841 usb_set_intfdata(interface, NULL);
1940 1842
1941/*FIXME: IR should be disconnected */
1942
1943 if (!dev) 1843 if (!dev)
1944 return; 1844 return;
1945 1845
1946
1947 down_write(&em28xx_disconnect); 1846 down_write(&em28xx_disconnect);
1948 1847
1949 down(&dev->lock); 1848 mutex_lock(&dev->lock);
1950 1849
1951 em28xx_info("disconnecting %s\n", dev->vdev->name); 1850 em28xx_info("disconnecting %s\n", dev->vdev->name);
1952 1851
@@ -1955,7 +1854,9 @@ static void em28xx_usb_disconnect(struct usb_interface *interface)
1955 if (dev->users) { 1854 if (dev->users) {
1956 em28xx_warn 1855 em28xx_warn
1957 ("device /dev/video%d is open! Deregistration and memory " 1856 ("device /dev/video%d is open! Deregistration and memory "
1958 "deallocation are deferred on close.\n", dev->vdev->minor); 1857 "deallocation are deferred on close.\n",
1858 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN);
1859
1959 dev->state |= DEV_MISCONFIGURED; 1860 dev->state |= DEV_MISCONFIGURED;
1960 em28xx_uninit_isoc(dev); 1861 em28xx_uninit_isoc(dev);
1961 dev->state |= DEV_DISCONNECTED; 1862 dev->state |= DEV_DISCONNECTED;
@@ -1966,7 +1867,7 @@ static void em28xx_usb_disconnect(struct usb_interface *interface)
1966 em28xx_release_resources(dev); 1867 em28xx_release_resources(dev);
1967 } 1868 }
1968 1869
1969 up(&dev->lock); 1870 mutex_unlock(&dev->lock);
1970 1871
1971 if (!dev->users) { 1872 if (!dev->users) {
1972 kfree(dev->alt_max_pkt_size); 1873 kfree(dev->alt_max_pkt_size);
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index 33de9d846af5..e1ddc2f27a21 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -27,6 +27,7 @@
27 27
28#include <linux/videodev.h> 28#include <linux/videodev.h>
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/mutex.h>
30#include <media/ir-kbd-i2c.h> 31#include <media/ir-kbd-i2c.h>
31 32
32/* Boards supported by driver */ 33/* Boards supported by driver */
@@ -41,6 +42,10 @@
41#define EM2800_BOARD_LEADTEK_WINFAST_USBII 7 42#define EM2800_BOARD_LEADTEK_WINFAST_USBII 7
42#define EM2800_BOARD_KWORLD_USB2800 8 43#define EM2800_BOARD_KWORLD_USB2800 8
43#define EM2820_BOARD_PINNACLE_DVC_90 9 44#define EM2820_BOARD_PINNACLE_DVC_90 9
45#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10
46#define EM2880_BOARD_TERRATEC_HYBRID_XS 11
47#define EM2820_BOARD_KWORLD_PVRTV2800RF 12
48#define EM2880_BOARD_TERRATEC_PRODIGY_XS 13
44 49
45#define UNSET -1 50#define UNSET -1
46 51
@@ -209,6 +214,7 @@ struct em28xx {
209 /* generic device properties */ 214 /* generic device properties */
210 char name[30]; /* name (including minor) of the device */ 215 char name[30]; /* name (including minor) of the device */
211 int model; /* index in the device_data struct */ 216 int model; /* index in the device_data struct */
217 int devno; /* marks the number of this device */
212 unsigned int is_em2800; 218 unsigned int is_em2800;
213 int video_inputs; /* number of video inputs */ 219 int video_inputs; /* number of video inputs */
214 struct list_head devlist; 220 struct list_head devlist;
@@ -256,7 +262,7 @@ struct em28xx {
256 enum em28xx_stream_state stream; 262 enum em28xx_stream_state stream;
257 enum em28xx_io_method io; 263 enum em28xx_io_method io;
258 /* locks */ 264 /* locks */
259 struct semaphore lock, fileop_lock; 265 struct mutex lock, fileop_lock;
260 spinlock_t queue_lock; 266 spinlock_t queue_lock;
261 struct list_head inqueue, outqueue; 267 struct list_head inqueue, outqueue;
262 wait_queue_head_t open, wait_frame, wait_stream; 268 wait_queue_head_t open, wait_frame, wait_stream;
@@ -326,6 +332,7 @@ int em28xx_set_alternate(struct em28xx *dev);
326 332
327/* Provided by em28xx-cards.c */ 333/* Provided by em28xx-cards.c */
328extern int em2800_variant_detect(struct usb_device* udev,int model); 334extern int em2800_variant_detect(struct usb_device* udev,int model);
335extern void em28xx_pre_card_setup(struct em28xx *dev);
329extern void em28xx_card_setup(struct em28xx *dev); 336extern void em28xx_card_setup(struct em28xx *dev);
330extern struct em28xx_board em28xx_boards[]; 337extern struct em28xx_board em28xx_boards[];
331extern struct usb_device_id em28xx_id_table[]; 338extern struct usb_device_id em28xx_id_table[];
diff --git a/drivers/media/video/hexium_gemini.c b/drivers/media/video/hexium_gemini.c
index e7bbeb11553d..c7fed3405655 100644
--- a/drivers/media/video/hexium_gemini.c
+++ b/drivers/media/video/hexium_gemini.c
@@ -1,9 +1,9 @@
1/* 1/*
2 hexium_gemini.c - v4l2 driver for Hexium Gemini frame grabber cards 2 hexium_gemini.c - v4l2 driver for Hexium Gemini frame grabber cards
3 3
4 Visit http://www.mihu.de/linux/saa7146/ and follow the link 4 Visit http://www.mihu.de/linux/saa7146/ and follow the link
5 to "hexium" for further details about this card. 5 to "hexium" for further details about this card.
6 6
7 Copyright (C) 2003 Michael Hunold <michael@mihu.de> 7 Copyright (C) 2003 Michael Hunold <michael@mihu.de>
8 8
9 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
@@ -81,7 +81,7 @@ struct hexium
81 81
82 struct video_device *video_dev; 82 struct video_device *video_dev;
83 struct i2c_adapter i2c_adapter; 83 struct i2c_adapter i2c_adapter;
84 84
85 int cur_input; /* current input */ 85 int cur_input; /* current input */
86 v4l2_std_id cur_std; /* current standard */ 86 v4l2_std_id cur_std; /* current standard */
87 int cur_bw; /* current black/white status */ 87 int cur_bw; /* current black/white status */
@@ -174,7 +174,7 @@ static struct saa7146_standard hexium_standards[] = {
174 .h_offset = 1, .h_pixels = 720, 174 .h_offset = 1, .h_pixels = 720,
175 .v_max_out = 576, .h_max_out = 768, 175 .v_max_out = 576, .h_max_out = 768,
176 } 176 }
177}; 177};
178 178
179/* bring hardware to a sane state. this has to be done, just in case someone 179/* bring hardware to a sane state. this has to be done, just in case someone
180 wants to capture from this device before it has been properly initialized. 180 wants to capture from this device before it has been properly initialized.
@@ -311,7 +311,7 @@ static int hexium_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
311 struct saa7146_dev *dev = fh->dev; 311 struct saa7146_dev *dev = fh->dev;
312 struct hexium *hexium = (struct hexium *) dev->ext_priv; 312 struct hexium *hexium = (struct hexium *) dev->ext_priv;
313/* 313/*
314 struct saa7146_vv *vv = dev->vv_data; 314 struct saa7146_vv *vv = dev->vv_data;
315*/ 315*/
316 switch (cmd) { 316 switch (cmd) {
317 case VIDIOC_ENUMINPUT: 317 case VIDIOC_ENUMINPUT:
diff --git a/drivers/media/video/hexium_orion.c b/drivers/media/video/hexium_orion.c
index aad4a18aafd6..137c4736da04 100644
--- a/drivers/media/video/hexium_orion.c
+++ b/drivers/media/video/hexium_orion.c
@@ -3,7 +3,7 @@
3 3
4 Visit http://www.mihu.de/linux/saa7146/ and follow the link 4 Visit http://www.mihu.de/linux/saa7146/ and follow the link
5 to "hexium" for further details about this card. 5 to "hexium" for further details about this card.
6 6
7 Copyright (C) 2003 Michael Hunold <michael@mihu.de> 7 Copyright (C) 2003 Michael Hunold <michael@mihu.de>
8 8
9 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
@@ -69,7 +69,7 @@ struct hexium
69{ 69{
70 int type; 70 int type;
71 struct video_device *video_dev; 71 struct video_device *video_dev;
72 struct i2c_adapter i2c_adapter; 72 struct i2c_adapter i2c_adapter;
73 73
74 int cur_input; /* current input */ 74 int cur_input; /* current input */
75}; 75};
@@ -86,7 +86,7 @@ static u8 hexium_saa7110[53]={
86}; 86};
87 87
88static struct { 88static struct {
89 struct hexium_data data[8]; 89 struct hexium_data data[8];
90} hexium_input_select[] = { 90} hexium_input_select[] = {
91{ 91{
92 { /* cvbs 1 */ 92 { /* cvbs 1 */
@@ -153,7 +153,7 @@ static struct {
153 { 0x30, 0x60 }, 153 { 0x30, 0x60 },
154 { 0x31, 0xB5 }, // ?? 154 { 0x31, 0xB5 }, // ??
155 { 0x21, 0x03 }, 155 { 0x21, 0x03 },
156 } 156 }
157}, { 157}, {
158 { /* y/c 1 */ 158 { /* y/c 1 */
159 { 0x06, 0x80 }, 159 { 0x06, 0x80 },
@@ -187,7 +187,7 @@ static struct {
187 { 0x31, 0x75 }, 187 { 0x31, 0x75 },
188 { 0x21, 0x21 }, 188 { 0x21, 0x21 },
189 } 189 }
190} 190}
191}; 191};
192 192
193static struct saa7146_standard hexium_standards[] = { 193static struct saa7146_standard hexium_standards[] = {
@@ -207,7 +207,7 @@ static struct saa7146_standard hexium_standards[] = {
207 .h_offset = 1, .h_pixels = 720, 207 .h_offset = 1, .h_pixels = 720,
208 .v_max_out = 576, .h_max_out = 768, 208 .v_max_out = 576, .h_max_out = 768,
209 } 209 }
210}; 210};
211 211
212/* this is only called for old HV-PCI6/Orion cards 212/* this is only called for old HV-PCI6/Orion cards
213 without eeprom */ 213 without eeprom */
@@ -272,7 +272,7 @@ static int hexium_probe(struct saa7146_dev *dev)
272 return 0; 272 return 0;
273 } 273 }
274 274
275 /* check if this is an old hexium Orion card by looking at 275 /* check if this is an old hexium Orion card by looking at
276 a saa7110 at address 0x4e */ 276 a saa7110 at address 0x4e */
277 if (0 == (err = i2c_smbus_xfer(&hexium->i2c_adapter, 0x4e, 0, I2C_SMBUS_READ, 0x00, I2C_SMBUS_BYTE_DATA, &data))) { 277 if (0 == (err = i2c_smbus_xfer(&hexium->i2c_adapter, 0x4e, 0, I2C_SMBUS_READ, 0x00, I2C_SMBUS_BYTE_DATA, &data))) {
278 printk("hexium_orion: device is a Hexium HV-PCI6/Orion (old).\n"); 278 printk("hexium_orion: device is a Hexium HV-PCI6/Orion (old).\n");
@@ -314,7 +314,7 @@ static int hexium_set_input(struct hexium *hexium, int input)
314{ 314{
315 union i2c_smbus_data data; 315 union i2c_smbus_data data;
316 int i = 0; 316 int i = 0;
317 317
318 DEB_D((".\n")); 318 DEB_D((".\n"));
319 319
320 for (i = 0; i < 8; i++) { 320 for (i = 0; i < 8; i++) {
@@ -375,7 +375,7 @@ static int hexium_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
375 struct saa7146_dev *dev = fh->dev; 375 struct saa7146_dev *dev = fh->dev;
376 struct hexium *hexium = (struct hexium *) dev->ext_priv; 376 struct hexium *hexium = (struct hexium *) dev->ext_priv;
377/* 377/*
378 struct saa7146_vv *vv = dev->vv_data; 378 struct saa7146_vv *vv = dev->vv_data;
379*/ 379*/
380 switch (cmd) { 380 switch (cmd) {
381 case VIDIOC_ENUMINPUT: 381 case VIDIOC_ENUMINPUT:
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 58b0e6982822..95bacf435414 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -44,51 +44,17 @@
44#include <media/ir-common.h> 44#include <media/ir-common.h>
45#include <media/ir-kbd-i2c.h> 45#include <media/ir-kbd-i2c.h>
46 46
47/* Mark Phalan <phalanm@o2.ie> */
48static IR_KEYTAB_TYPE ir_codes_pv951[IR_KEYTAB_SIZE] = {
49 [ 0 ] = KEY_KP0,
50 [ 1 ] = KEY_KP1,
51 [ 2 ] = KEY_KP2,
52 [ 3 ] = KEY_KP3,
53 [ 4 ] = KEY_KP4,
54 [ 5 ] = KEY_KP5,
55 [ 6 ] = KEY_KP6,
56 [ 7 ] = KEY_KP7,
57 [ 8 ] = KEY_KP8,
58 [ 9 ] = KEY_KP9,
59
60 [ 18 ] = KEY_POWER,
61 [ 16 ] = KEY_MUTE,
62 [ 31 ] = KEY_VOLUMEDOWN,
63 [ 27 ] = KEY_VOLUMEUP,
64 [ 26 ] = KEY_CHANNELUP,
65 [ 30 ] = KEY_CHANNELDOWN,
66 [ 14 ] = KEY_PAGEUP,
67 [ 29 ] = KEY_PAGEDOWN,
68 [ 19 ] = KEY_SOUND,
69
70 [ 24 ] = KEY_KPPLUSMINUS, /* CH +/- */
71 [ 22 ] = KEY_SUBTITLE, /* CC */
72 [ 13 ] = KEY_TEXT, /* TTX */
73 [ 11 ] = KEY_TV, /* AIR/CBL */
74 [ 17 ] = KEY_PC, /* PC/TV */
75 [ 23 ] = KEY_OK, /* CH RTN */
76 [ 25 ] = KEY_MODE, /* FUNC */
77 [ 12 ] = KEY_SEARCH, /* AUTOSCAN */
78
79 /* Not sure what to do with these ones! */
80 [ 15 ] = KEY_SELECT, /* SOURCE */
81 [ 10 ] = KEY_KPPLUS, /* +100 */
82 [ 20 ] = KEY_KPEQUAL, /* SYNC */
83 [ 28 ] = KEY_MEDIA, /* PC/TV */
84};
85
86/* ----------------------------------------------------------------------- */ 47/* ----------------------------------------------------------------------- */
87/* insmod parameters */ 48/* insmod parameters */
88 49
89static int debug; 50static int debug;
90module_param(debug, int, 0644); /* debug level (0,1,2) */ 51module_param(debug, int, 0644); /* debug level (0,1,2) */
91 52
53static int hauppauge = 0;
54module_param(hauppauge, int, 0644); /* Choose Hauppauge remote */
55MODULE_PARM_DESC(hauppauge, "Specify Hauppauge remote: 0=black, 1=grey (defaults to 0)");
56
57
92#define DEVNAME "ir-kbd-i2c" 58#define DEVNAME "ir-kbd-i2c"
93#define dprintk(level, fmt, arg...) if (debug >= level) \ 59#define dprintk(level, fmt, arg...) if (debug >= level) \
94 printk(KERN_DEBUG DEVNAME ": " fmt , ## arg) 60 printk(KERN_DEBUG DEVNAME ": " fmt , ## arg)
@@ -336,7 +302,11 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
336 name = "Hauppauge"; 302 name = "Hauppauge";
337 ir->get_key = get_key_haup; 303 ir->get_key = get_key_haup;
338 ir_type = IR_TYPE_RC5; 304 ir_type = IR_TYPE_RC5;
339 ir_codes = ir_codes_rc5_tv; 305 if (hauppauge == 1) {
306 ir_codes = ir_codes_hauppauge_new;
307 } else {
308 ir_codes = ir_codes_rc5_tv;
309 }
340 break; 310 break;
341 case 0x30: 311 case 0x30:
342 name = "KNC One"; 312 name = "KNC One";
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index 2869464aee0d..850bee97090c 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -925,7 +925,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
925 return -EINVAL; 925 return -EINVAL;
926 if (p->palette != VIDEO_PALETTE_YUV422) 926 if (p->palette != VIDEO_PALETTE_YUV422)
927 return -EINVAL; 927 return -EINVAL;
928 down(&meye.lock); 928 mutex_lock(&meye.lock);
929 sonypi_camera_command(SONYPI_COMMAND_SETCAMERABRIGHTNESS, 929 sonypi_camera_command(SONYPI_COMMAND_SETCAMERABRIGHTNESS,
930 p->brightness >> 10); 930 p->brightness >> 10);
931 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAHUE, 931 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAHUE,
@@ -935,7 +935,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
935 sonypi_camera_command(SONYPI_COMMAND_SETCAMERACONTRAST, 935 sonypi_camera_command(SONYPI_COMMAND_SETCAMERACONTRAST,
936 p->contrast >> 10); 936 p->contrast >> 10);
937 meye.picture = *p; 937 meye.picture = *p;
938 up(&meye.lock); 938 mutex_unlock(&meye.lock);
939 break; 939 break;
940 } 940 }
941 941
@@ -946,21 +946,21 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
946 if (*i < 0 || *i >= gbuffers) 946 if (*i < 0 || *i >= gbuffers)
947 return -EINVAL; 947 return -EINVAL;
948 948
949 down(&meye.lock); 949 mutex_lock(&meye.lock);
950 950
951 switch (meye.grab_buffer[*i].state) { 951 switch (meye.grab_buffer[*i].state) {
952 952
953 case MEYE_BUF_UNUSED: 953 case MEYE_BUF_UNUSED:
954 up(&meye.lock); 954 mutex_unlock(&meye.lock);
955 return -EINVAL; 955 return -EINVAL;
956 case MEYE_BUF_USING: 956 case MEYE_BUF_USING:
957 if (file->f_flags & O_NONBLOCK) { 957 if (file->f_flags & O_NONBLOCK) {
958 up(&meye.lock); 958 mutex_unlock(&meye.lock);
959 return -EAGAIN; 959 return -EAGAIN;
960 } 960 }
961 if (wait_event_interruptible(meye.proc_list, 961 if (wait_event_interruptible(meye.proc_list,
962 (meye.grab_buffer[*i].state != MEYE_BUF_USING))) { 962 (meye.grab_buffer[*i].state != MEYE_BUF_USING))) {
963 up(&meye.lock); 963 mutex_unlock(&meye.lock);
964 return -EINTR; 964 return -EINTR;
965 } 965 }
966 /* fall through */ 966 /* fall through */
@@ -968,7 +968,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
968 meye.grab_buffer[*i].state = MEYE_BUF_UNUSED; 968 meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
969 kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int)); 969 kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int));
970 } 970 }
971 up(&meye.lock); 971 mutex_unlock(&meye.lock);
972 break; 972 break;
973 } 973 }
974 974
@@ -987,7 +987,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
987 if (meye.grab_buffer[vm->frame].state != MEYE_BUF_UNUSED) 987 if (meye.grab_buffer[vm->frame].state != MEYE_BUF_UNUSED)
988 return -EBUSY; 988 return -EBUSY;
989 989
990 down(&meye.lock); 990 mutex_lock(&meye.lock);
991 if (vm->width == 640 && vm->height == 480) { 991 if (vm->width == 640 && vm->height == 480) {
992 if (meye.params.subsample) { 992 if (meye.params.subsample) {
993 meye.params.subsample = 0; 993 meye.params.subsample = 0;
@@ -999,7 +999,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
999 restart = 1; 999 restart = 1;
1000 } 1000 }
1001 } else { 1001 } else {
1002 up(&meye.lock); 1002 mutex_unlock(&meye.lock);
1003 return -EINVAL; 1003 return -EINVAL;
1004 } 1004 }
1005 1005
@@ -1007,7 +1007,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1007 mchip_continuous_start(); 1007 mchip_continuous_start();
1008 meye.grab_buffer[vm->frame].state = MEYE_BUF_USING; 1008 meye.grab_buffer[vm->frame].state = MEYE_BUF_USING;
1009 kfifo_put(meye.grabq, (unsigned char *)&vm->frame, sizeof(int)); 1009 kfifo_put(meye.grabq, (unsigned char *)&vm->frame, sizeof(int));
1010 up(&meye.lock); 1010 mutex_unlock(&meye.lock);
1011 break; 1011 break;
1012 } 1012 }
1013 1013
@@ -1039,7 +1039,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1039 return -EINVAL; 1039 return -EINVAL;
1040 if (jp->framerate > 31) 1040 if (jp->framerate > 31)
1041 return -EINVAL; 1041 return -EINVAL;
1042 down(&meye.lock); 1042 mutex_lock(&meye.lock);
1043 if (meye.params.subsample != jp->subsample || 1043 if (meye.params.subsample != jp->subsample ||
1044 meye.params.quality != jp->quality) 1044 meye.params.quality != jp->quality)
1045 mchip_hic_stop(); /* need restart */ 1045 mchip_hic_stop(); /* need restart */
@@ -1050,7 +1050,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1050 meye.params.agc); 1050 meye.params.agc);
1051 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAPICTURE, 1051 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAPICTURE,
1052 meye.params.picture); 1052 meye.params.picture);
1053 up(&meye.lock); 1053 mutex_unlock(&meye.lock);
1054 break; 1054 break;
1055 } 1055 }
1056 1056
@@ -1068,12 +1068,12 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1068 } 1068 }
1069 if (meye.grab_buffer[*nb].state != MEYE_BUF_UNUSED) 1069 if (meye.grab_buffer[*nb].state != MEYE_BUF_UNUSED)
1070 return -EBUSY; 1070 return -EBUSY;
1071 down(&meye.lock); 1071 mutex_lock(&meye.lock);
1072 if (meye.mchip_mode != MCHIP_HIC_MODE_CONT_COMP) 1072 if (meye.mchip_mode != MCHIP_HIC_MODE_CONT_COMP)
1073 mchip_cont_compression_start(); 1073 mchip_cont_compression_start();
1074 meye.grab_buffer[*nb].state = MEYE_BUF_USING; 1074 meye.grab_buffer[*nb].state = MEYE_BUF_USING;
1075 kfifo_put(meye.grabq, (unsigned char *)nb, sizeof(int)); 1075 kfifo_put(meye.grabq, (unsigned char *)nb, sizeof(int));
1076 up(&meye.lock); 1076 mutex_unlock(&meye.lock);
1077 break; 1077 break;
1078 } 1078 }
1079 1079
@@ -1084,20 +1084,20 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1084 if (*i < 0 || *i >= gbuffers) 1084 if (*i < 0 || *i >= gbuffers)
1085 return -EINVAL; 1085 return -EINVAL;
1086 1086
1087 down(&meye.lock); 1087 mutex_lock(&meye.lock);
1088 switch (meye.grab_buffer[*i].state) { 1088 switch (meye.grab_buffer[*i].state) {
1089 1089
1090 case MEYE_BUF_UNUSED: 1090 case MEYE_BUF_UNUSED:
1091 up(&meye.lock); 1091 mutex_unlock(&meye.lock);
1092 return -EINVAL; 1092 return -EINVAL;
1093 case MEYE_BUF_USING: 1093 case MEYE_BUF_USING:
1094 if (file->f_flags & O_NONBLOCK) { 1094 if (file->f_flags & O_NONBLOCK) {
1095 up(&meye.lock); 1095 mutex_unlock(&meye.lock);
1096 return -EAGAIN; 1096 return -EAGAIN;
1097 } 1097 }
1098 if (wait_event_interruptible(meye.proc_list, 1098 if (wait_event_interruptible(meye.proc_list,
1099 (meye.grab_buffer[*i].state != MEYE_BUF_USING))) { 1099 (meye.grab_buffer[*i].state != MEYE_BUF_USING))) {
1100 up(&meye.lock); 1100 mutex_unlock(&meye.lock);
1101 return -EINTR; 1101 return -EINTR;
1102 } 1102 }
1103 /* fall through */ 1103 /* fall through */
@@ -1106,7 +1106,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1106 kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int)); 1106 kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int));
1107 } 1107 }
1108 *i = meye.grab_buffer[*i].size; 1108 *i = meye.grab_buffer[*i].size;
1109 up(&meye.lock); 1109 mutex_unlock(&meye.lock);
1110 break; 1110 break;
1111 } 1111 }
1112 1112
@@ -1116,14 +1116,14 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1116 return -EINVAL; 1116 return -EINVAL;
1117 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED) 1117 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED)
1118 return -EBUSY; 1118 return -EBUSY;
1119 down(&meye.lock); 1119 mutex_lock(&meye.lock);
1120 meye.grab_buffer[0].state = MEYE_BUF_USING; 1120 meye.grab_buffer[0].state = MEYE_BUF_USING;
1121 mchip_take_picture(); 1121 mchip_take_picture();
1122 mchip_get_picture( 1122 mchip_get_picture(
1123 meye.grab_fbuffer, 1123 meye.grab_fbuffer,
1124 mchip_hsize() * mchip_vsize() * 2); 1124 mchip_hsize() * mchip_vsize() * 2);
1125 meye.grab_buffer[0].state = MEYE_BUF_DONE; 1125 meye.grab_buffer[0].state = MEYE_BUF_DONE;
1126 up(&meye.lock); 1126 mutex_unlock(&meye.lock);
1127 break; 1127 break;
1128 } 1128 }
1129 1129
@@ -1134,7 +1134,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1134 return -EINVAL; 1134 return -EINVAL;
1135 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED) 1135 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED)
1136 return -EBUSY; 1136 return -EBUSY;
1137 down(&meye.lock); 1137 mutex_lock(&meye.lock);
1138 meye.grab_buffer[0].state = MEYE_BUF_USING; 1138 meye.grab_buffer[0].state = MEYE_BUF_USING;
1139 *len = -1; 1139 *len = -1;
1140 while (*len == -1) { 1140 while (*len == -1) {
@@ -1142,7 +1142,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1142 *len = mchip_compress_frame(meye.grab_fbuffer, gbufsize); 1142 *len = mchip_compress_frame(meye.grab_fbuffer, gbufsize);
1143 } 1143 }
1144 meye.grab_buffer[0].state = MEYE_BUF_DONE; 1144 meye.grab_buffer[0].state = MEYE_BUF_DONE;
1145 up(&meye.lock); 1145 mutex_unlock(&meye.lock);
1146 break; 1146 break;
1147 } 1147 }
1148 1148
@@ -1285,7 +1285,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1285 case VIDIOC_S_CTRL: { 1285 case VIDIOC_S_CTRL: {
1286 struct v4l2_control *c = arg; 1286 struct v4l2_control *c = arg;
1287 1287
1288 down(&meye.lock); 1288 mutex_lock(&meye.lock);
1289 switch (c->id) { 1289 switch (c->id) {
1290 case V4L2_CID_BRIGHTNESS: 1290 case V4L2_CID_BRIGHTNESS:
1291 sonypi_camera_command( 1291 sonypi_camera_command(
@@ -1329,17 +1329,17 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1329 meye.params.framerate = c->value; 1329 meye.params.framerate = c->value;
1330 break; 1330 break;
1331 default: 1331 default:
1332 up(&meye.lock); 1332 mutex_unlock(&meye.lock);
1333 return -EINVAL; 1333 return -EINVAL;
1334 } 1334 }
1335 up(&meye.lock); 1335 mutex_unlock(&meye.lock);
1336 break; 1336 break;
1337 } 1337 }
1338 1338
1339 case VIDIOC_G_CTRL: { 1339 case VIDIOC_G_CTRL: {
1340 struct v4l2_control *c = arg; 1340 struct v4l2_control *c = arg;
1341 1341
1342 down(&meye.lock); 1342 mutex_lock(&meye.lock);
1343 switch (c->id) { 1343 switch (c->id) {
1344 case V4L2_CID_BRIGHTNESS: 1344 case V4L2_CID_BRIGHTNESS:
1345 c->value = meye.picture.brightness >> 10; 1345 c->value = meye.picture.brightness >> 10;
@@ -1369,10 +1369,10 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1369 c->value = meye.params.framerate; 1369 c->value = meye.params.framerate;
1370 break; 1370 break;
1371 default: 1371 default:
1372 up(&meye.lock); 1372 mutex_unlock(&meye.lock);
1373 return -EINVAL; 1373 return -EINVAL;
1374 } 1374 }
1375 up(&meye.lock); 1375 mutex_unlock(&meye.lock);
1376 break; 1376 break;
1377 } 1377 }
1378 1378
@@ -1469,7 +1469,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1469 f->fmt.pix.field != V4L2_FIELD_NONE) 1469 f->fmt.pix.field != V4L2_FIELD_NONE)
1470 return -EINVAL; 1470 return -EINVAL;
1471 f->fmt.pix.field = V4L2_FIELD_NONE; 1471 f->fmt.pix.field = V4L2_FIELD_NONE;
1472 down(&meye.lock); 1472 mutex_lock(&meye.lock);
1473 if (f->fmt.pix.width <= 320) { 1473 if (f->fmt.pix.width <= 320) {
1474 f->fmt.pix.width = 320; 1474 f->fmt.pix.width = 320;
1475 f->fmt.pix.height = 240; 1475 f->fmt.pix.height = 240;
@@ -1487,7 +1487,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1487 meye.mchip_mode = MCHIP_HIC_MODE_CONT_COMP; 1487 meye.mchip_mode = MCHIP_HIC_MODE_CONT_COMP;
1488 break; 1488 break;
1489 } 1489 }
1490 up(&meye.lock); 1490 mutex_unlock(&meye.lock);
1491 f->fmt.pix.bytesperline = f->fmt.pix.width * 2; 1491 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1492 f->fmt.pix.sizeimage = f->fmt.pix.height * 1492 f->fmt.pix.sizeimage = f->fmt.pix.height *
1493 f->fmt.pix.bytesperline; 1493 f->fmt.pix.bytesperline;
@@ -1509,11 +1509,11 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1509 /* already allocated, no modifications */ 1509 /* already allocated, no modifications */
1510 break; 1510 break;
1511 } 1511 }
1512 down(&meye.lock); 1512 mutex_lock(&meye.lock);
1513 if (meye.grab_fbuffer) { 1513 if (meye.grab_fbuffer) {
1514 for (i = 0; i < gbuffers; i++) 1514 for (i = 0; i < gbuffers; i++)
1515 if (meye.vma_use_count[i]) { 1515 if (meye.vma_use_count[i]) {
1516 up(&meye.lock); 1516 mutex_unlock(&meye.lock);
1517 return -EINVAL; 1517 return -EINVAL;
1518 } 1518 }
1519 rvfree(meye.grab_fbuffer, gbuffers * gbufsize); 1519 rvfree(meye.grab_fbuffer, gbuffers * gbufsize);
@@ -1525,12 +1525,12 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1525 if (!meye.grab_fbuffer) { 1525 if (!meye.grab_fbuffer) {
1526 printk(KERN_ERR "meye: v4l framebuffer allocation" 1526 printk(KERN_ERR "meye: v4l framebuffer allocation"
1527 " failed\n"); 1527 " failed\n");
1528 up(&meye.lock); 1528 mutex_unlock(&meye.lock);
1529 return -ENOMEM; 1529 return -ENOMEM;
1530 } 1530 }
1531 for (i = 0; i < gbuffers; i++) 1531 for (i = 0; i < gbuffers; i++)
1532 meye.vma_use_count[i] = 0; 1532 meye.vma_use_count[i] = 0;
1533 up(&meye.lock); 1533 mutex_unlock(&meye.lock);
1534 break; 1534 break;
1535 } 1535 }
1536 1536
@@ -1569,12 +1569,12 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1569 return -EINVAL; 1569 return -EINVAL;
1570 if (meye.grab_buffer[buf->index].state != MEYE_BUF_UNUSED) 1570 if (meye.grab_buffer[buf->index].state != MEYE_BUF_UNUSED)
1571 return -EINVAL; 1571 return -EINVAL;
1572 down(&meye.lock); 1572 mutex_lock(&meye.lock);
1573 buf->flags |= V4L2_BUF_FLAG_QUEUED; 1573 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1574 buf->flags &= ~V4L2_BUF_FLAG_DONE; 1574 buf->flags &= ~V4L2_BUF_FLAG_DONE;
1575 meye.grab_buffer[buf->index].state = MEYE_BUF_USING; 1575 meye.grab_buffer[buf->index].state = MEYE_BUF_USING;
1576 kfifo_put(meye.grabq, (unsigned char *)&buf->index, sizeof(int)); 1576 kfifo_put(meye.grabq, (unsigned char *)&buf->index, sizeof(int));
1577 up(&meye.lock); 1577 mutex_unlock(&meye.lock);
1578 break; 1578 break;
1579 } 1579 }
1580 1580
@@ -1587,23 +1587,23 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1587 if (buf->memory != V4L2_MEMORY_MMAP) 1587 if (buf->memory != V4L2_MEMORY_MMAP)
1588 return -EINVAL; 1588 return -EINVAL;
1589 1589
1590 down(&meye.lock); 1590 mutex_lock(&meye.lock);
1591 if (kfifo_len(meye.doneq) == 0 && file->f_flags & O_NONBLOCK) { 1591 if (kfifo_len(meye.doneq) == 0 && file->f_flags & O_NONBLOCK) {
1592 up(&meye.lock); 1592 mutex_unlock(&meye.lock);
1593 return -EAGAIN; 1593 return -EAGAIN;
1594 } 1594 }
1595 if (wait_event_interruptible(meye.proc_list, 1595 if (wait_event_interruptible(meye.proc_list,
1596 kfifo_len(meye.doneq) != 0) < 0) { 1596 kfifo_len(meye.doneq) != 0) < 0) {
1597 up(&meye.lock); 1597 mutex_unlock(&meye.lock);
1598 return -EINTR; 1598 return -EINTR;
1599 } 1599 }
1600 if (!kfifo_get(meye.doneq, (unsigned char *)&reqnr, 1600 if (!kfifo_get(meye.doneq, (unsigned char *)&reqnr,
1601 sizeof(int))) { 1601 sizeof(int))) {
1602 up(&meye.lock); 1602 mutex_unlock(&meye.lock);
1603 return -EBUSY; 1603 return -EBUSY;
1604 } 1604 }
1605 if (meye.grab_buffer[reqnr].state != MEYE_BUF_DONE) { 1605 if (meye.grab_buffer[reqnr].state != MEYE_BUF_DONE) {
1606 up(&meye.lock); 1606 mutex_unlock(&meye.lock);
1607 return -EINVAL; 1607 return -EINVAL;
1608 } 1608 }
1609 buf->index = reqnr; 1609 buf->index = reqnr;
@@ -1616,12 +1616,12 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1616 buf->m.offset = reqnr * gbufsize; 1616 buf->m.offset = reqnr * gbufsize;
1617 buf->length = gbufsize; 1617 buf->length = gbufsize;
1618 meye.grab_buffer[reqnr].state = MEYE_BUF_UNUSED; 1618 meye.grab_buffer[reqnr].state = MEYE_BUF_UNUSED;
1619 up(&meye.lock); 1619 mutex_unlock(&meye.lock);
1620 break; 1620 break;
1621 } 1621 }
1622 1622
1623 case VIDIOC_STREAMON: { 1623 case VIDIOC_STREAMON: {
1624 down(&meye.lock); 1624 mutex_lock(&meye.lock);
1625 switch (meye.mchip_mode) { 1625 switch (meye.mchip_mode) {
1626 case MCHIP_HIC_MODE_CONT_OUT: 1626 case MCHIP_HIC_MODE_CONT_OUT:
1627 mchip_continuous_start(); 1627 mchip_continuous_start();
@@ -1630,23 +1630,23 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1630 mchip_cont_compression_start(); 1630 mchip_cont_compression_start();
1631 break; 1631 break;
1632 default: 1632 default:
1633 up(&meye.lock); 1633 mutex_unlock(&meye.lock);
1634 return -EINVAL; 1634 return -EINVAL;
1635 } 1635 }
1636 up(&meye.lock); 1636 mutex_unlock(&meye.lock);
1637 break; 1637 break;
1638 } 1638 }
1639 1639
1640 case VIDIOC_STREAMOFF: { 1640 case VIDIOC_STREAMOFF: {
1641 int i; 1641 int i;
1642 1642
1643 down(&meye.lock); 1643 mutex_lock(&meye.lock);
1644 mchip_hic_stop(); 1644 mchip_hic_stop();
1645 kfifo_reset(meye.grabq); 1645 kfifo_reset(meye.grabq);
1646 kfifo_reset(meye.doneq); 1646 kfifo_reset(meye.doneq);
1647 for (i = 0; i < MEYE_MAX_BUFNBRS; i++) 1647 for (i = 0; i < MEYE_MAX_BUFNBRS; i++)
1648 meye.grab_buffer[i].state = MEYE_BUF_UNUSED; 1648 meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
1649 up(&meye.lock); 1649 mutex_unlock(&meye.lock);
1650 break; 1650 break;
1651 } 1651 }
1652 1652
@@ -1672,11 +1672,11 @@ static unsigned int meye_poll(struct file *file, poll_table *wait)
1672{ 1672{
1673 unsigned int res = 0; 1673 unsigned int res = 0;
1674 1674
1675 down(&meye.lock); 1675 mutex_lock(&meye.lock);
1676 poll_wait(file, &meye.proc_list, wait); 1676 poll_wait(file, &meye.proc_list, wait);
1677 if (kfifo_len(meye.doneq)) 1677 if (kfifo_len(meye.doneq))
1678 res = POLLIN | POLLRDNORM; 1678 res = POLLIN | POLLRDNORM;
1679 up(&meye.lock); 1679 mutex_unlock(&meye.lock);
1680 return res; 1680 return res;
1681} 1681}
1682 1682
@@ -1704,9 +1704,9 @@ static int meye_mmap(struct file *file, struct vm_area_struct *vma)
1704 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; 1704 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
1705 unsigned long page, pos; 1705 unsigned long page, pos;
1706 1706
1707 down(&meye.lock); 1707 mutex_lock(&meye.lock);
1708 if (size > gbuffers * gbufsize) { 1708 if (size > gbuffers * gbufsize) {
1709 up(&meye.lock); 1709 mutex_unlock(&meye.lock);
1710 return -EINVAL; 1710 return -EINVAL;
1711 } 1711 }
1712 if (!meye.grab_fbuffer) { 1712 if (!meye.grab_fbuffer) {
@@ -1716,7 +1716,7 @@ static int meye_mmap(struct file *file, struct vm_area_struct *vma)
1716 meye.grab_fbuffer = rvmalloc(gbuffers*gbufsize); 1716 meye.grab_fbuffer = rvmalloc(gbuffers*gbufsize);
1717 if (!meye.grab_fbuffer) { 1717 if (!meye.grab_fbuffer) {
1718 printk(KERN_ERR "meye: v4l framebuffer allocation failed\n"); 1718 printk(KERN_ERR "meye: v4l framebuffer allocation failed\n");
1719 up(&meye.lock); 1719 mutex_unlock(&meye.lock);
1720 return -ENOMEM; 1720 return -ENOMEM;
1721 } 1721 }
1722 for (i = 0; i < gbuffers; i++) 1722 for (i = 0; i < gbuffers; i++)
@@ -1727,7 +1727,7 @@ static int meye_mmap(struct file *file, struct vm_area_struct *vma)
1727 while (size > 0) { 1727 while (size > 0) {
1728 page = vmalloc_to_pfn((void *)pos); 1728 page = vmalloc_to_pfn((void *)pos);
1729 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) { 1729 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
1730 up(&meye.lock); 1730 mutex_unlock(&meye.lock);
1731 return -EAGAIN; 1731 return -EAGAIN;
1732 } 1732 }
1733 start += PAGE_SIZE; 1733 start += PAGE_SIZE;
@@ -1744,7 +1744,7 @@ static int meye_mmap(struct file *file, struct vm_area_struct *vma)
1744 vma->vm_private_data = (void *) (offset / gbufsize); 1744 vma->vm_private_data = (void *) (offset / gbufsize);
1745 meye_vm_open(vma); 1745 meye_vm_open(vma);
1746 1746
1747 up(&meye.lock); 1747 mutex_unlock(&meye.lock);
1748 return 0; 1748 return 0;
1749} 1749}
1750 1750
@@ -1913,7 +1913,7 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
1913 goto outvideoreg; 1913 goto outvideoreg;
1914 } 1914 }
1915 1915
1916 init_MUTEX(&meye.lock); 1916 mutex_init(&meye.lock);
1917 init_waitqueue_head(&meye.proc_list); 1917 init_waitqueue_head(&meye.proc_list);
1918 meye.picture.depth = 16; 1918 meye.picture.depth = 16;
1919 meye.picture.palette = VIDEO_PALETTE_YUV422; 1919 meye.picture.palette = VIDEO_PALETTE_YUV422;
diff --git a/drivers/media/video/meye.h b/drivers/media/video/meye.h
index e8cd897b0d20..0d09a0e3803c 100644
--- a/drivers/media/video/meye.h
+++ b/drivers/media/video/meye.h
@@ -260,6 +260,8 @@
260 260
261/* private API definitions */ 261/* private API definitions */
262#include <linux/meye.h> 262#include <linux/meye.h>
263#include <linux/mutex.h>
264
263 265
264/* Enable jpg software correction */ 266/* Enable jpg software correction */
265#define MEYE_JPEG_CORRECTION 1 267#define MEYE_JPEG_CORRECTION 1
@@ -301,7 +303,7 @@ struct meye {
301 /* list of buffers */ 303 /* list of buffers */
302 struct meye_grab_buffer grab_buffer[MEYE_MAX_BUFNBRS]; 304 struct meye_grab_buffer grab_buffer[MEYE_MAX_BUFNBRS];
303 int vma_use_count[MEYE_MAX_BUFNBRS]; /* mmap count */ 305 int vma_use_count[MEYE_MAX_BUFNBRS]; /* mmap count */
304 struct semaphore lock; /* semaphore for open/mmap... */ 306 struct mutex lock; /* mutex for open/mmap... */
305 struct kfifo *grabq; /* queue for buffers to be grabbed */ 307 struct kfifo *grabq; /* queue for buffers to be grabbed */
306 spinlock_t grabq_lock; /* lock protecting the queue */ 308 spinlock_t grabq_lock; /* lock protecting the queue */
307 struct kfifo *doneq; /* queue for grabbed buffers */ 309 struct kfifo *doneq; /* queue for grabbed buffers */
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index 69ed369c2f48..11ea9765769c 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -411,9 +411,9 @@ static int msp_mode_v4l2_to_v4l1(int rxsubchans)
411 if (rxsubchans & V4L2_TUNER_SUB_STEREO) 411 if (rxsubchans & V4L2_TUNER_SUB_STEREO)
412 mode |= VIDEO_SOUND_STEREO; 412 mode |= VIDEO_SOUND_STEREO;
413 if (rxsubchans & V4L2_TUNER_SUB_LANG2) 413 if (rxsubchans & V4L2_TUNER_SUB_LANG2)
414 mode |= VIDEO_SOUND_LANG2; 414 mode |= VIDEO_SOUND_LANG2 | VIDEO_SOUND_STEREO;
415 if (rxsubchans & V4L2_TUNER_SUB_LANG1) 415 if (rxsubchans & V4L2_TUNER_SUB_LANG1)
416 mode |= VIDEO_SOUND_LANG1; 416 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_STEREO;
417 if (mode == 0) 417 if (mode == 0)
418 mode |= VIDEO_SOUND_MONO; 418 mode |= VIDEO_SOUND_MONO;
419 return mode; 419 return mode;
@@ -430,21 +430,6 @@ static int msp_mode_v4l1_to_v4l2(int mode)
430 return V4L2_TUNER_MODE_MONO; 430 return V4L2_TUNER_MODE_MONO;
431} 431}
432 432
433static void msp_any_detect_stereo(struct i2c_client *client)
434{
435 struct msp_state *state = i2c_get_clientdata(client);
436
437 switch (state->opmode) {
438 case OPMODE_MANUAL:
439 case OPMODE_AUTODETECT:
440 autodetect_stereo(client);
441 break;
442 case OPMODE_AUTOSELECT:
443 msp34xxg_detect_stereo(client);
444 break;
445 }
446}
447
448static struct v4l2_queryctrl msp_qctrl_std[] = { 433static struct v4l2_queryctrl msp_qctrl_std[] = {
449 { 434 {
450 .id = V4L2_CID_AUDIO_VOLUME, 435 .id = V4L2_CID_AUDIO_VOLUME,
@@ -506,22 +491,6 @@ static struct v4l2_queryctrl msp_qctrl_sound_processing[] = {
506}; 491};
507 492
508 493
509static void msp_any_set_audmode(struct i2c_client *client, int audmode)
510{
511 struct msp_state *state = i2c_get_clientdata(client);
512
513 switch (state->opmode) {
514 case OPMODE_MANUAL:
515 case OPMODE_AUTODETECT:
516 state->watch_stereo = 0;
517 msp3400c_setstereo(client, audmode);
518 break;
519 case OPMODE_AUTOSELECT:
520 msp34xxg_set_audmode(client, audmode);
521 break;
522 }
523}
524
525static int msp_get_ctrl(struct i2c_client *client, struct v4l2_control *ctrl) 494static int msp_get_ctrl(struct i2c_client *client, struct v4l2_control *ctrl)
526{ 495{
527 struct msp_state *state = i2c_get_clientdata(client); 496 struct msp_state *state = i2c_get_clientdata(client);
@@ -653,11 +622,10 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
653 } 622 }
654 if (scart) { 623 if (scart) {
655 state->rxsubchans = V4L2_TUNER_SUB_STEREO; 624 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
656 state->audmode = V4L2_TUNER_MODE_STEREO;
657 msp_set_scart(client, scart, 0); 625 msp_set_scart(client, scart, 0);
658 msp_write_dsp(client, 0x000d, 0x1900); 626 msp_write_dsp(client, 0x000d, 0x1900);
659 if (state->opmode != OPMODE_AUTOSELECT) 627 if (state->opmode != OPMODE_AUTOSELECT)
660 msp3400c_setstereo(client, state->audmode); 628 msp_set_audmode(client);
661 } 629 }
662 msp_wake_thread(client); 630 msp_wake_thread(client);
663 break; 631 break;
@@ -671,8 +639,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
671 switch (state->opmode) { 639 switch (state->opmode) {
672 case OPMODE_MANUAL: 640 case OPMODE_MANUAL:
673 /* set msp3400 to FM radio mode */ 641 /* set msp3400 to FM radio mode */
674 msp3400c_setmode(client, MSP_MODE_FM_RADIO); 642 msp3400c_set_mode(client, MSP_MODE_FM_RADIO);
675 msp3400c_setcarrier(client, MSP_CARRIER(10.7), 643 msp3400c_set_carrier(client, MSP_CARRIER(10.7),
676 MSP_CARRIER(10.7)); 644 MSP_CARRIER(10.7));
677 msp_set_audio(client); 645 msp_set_audio(client);
678 break; 646 break;
@@ -706,7 +674,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
706 if (state->radio) 674 if (state->radio)
707 break; 675 break;
708 if (state->opmode == OPMODE_AUTOSELECT) 676 if (state->opmode == OPMODE_AUTOSELECT)
709 msp_any_detect_stereo(client); 677 msp_detect_stereo(client);
710 va->mode = msp_mode_v4l2_to_v4l1(state->rxsubchans); 678 va->mode = msp_mode_v4l2_to_v4l1(state->rxsubchans);
711 break; 679 break;
712 } 680 }
@@ -722,8 +690,9 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
722 state->treble = va->treble; 690 state->treble = va->treble;
723 msp_set_audio(client); 691 msp_set_audio(client);
724 692
725 if (va->mode != 0 && state->radio == 0) 693 if (va->mode != 0 && state->radio == 0) {
726 msp_any_set_audmode(client, msp_mode_v4l1_to_v4l2(va->mode)); 694 state->audmode = msp_mode_v4l1_to_v4l2(va->mode);
695 }
727 break; 696 break;
728 } 697 }
729 698
@@ -831,11 +800,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
831 return -EINVAL; 800 return -EINVAL;
832 } 801 }
833 802
834 msp_any_detect_stereo(client); 803 a->capability = V4L2_AUDCAP_STEREO;
835 if (state->audmode == V4L2_TUNER_MODE_STEREO) { 804 a->mode = 0; /* TODO: add support for AVL */
836 a->capability = V4L2_AUDCAP_STEREO;
837 }
838
839 break; 805 break;
840 } 806 }
841 807
@@ -865,16 +831,10 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
865 } 831 }
866 if (scart) { 832 if (scart) {
867 state->rxsubchans = V4L2_TUNER_SUB_STEREO; 833 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
868 state->audmode = V4L2_TUNER_MODE_STEREO;
869 msp_set_scart(client, scart, 0); 834 msp_set_scart(client, scart, 0);
870 msp_write_dsp(client, 0x000d, 0x1900); 835 msp_write_dsp(client, 0x000d, 0x1900);
871 } 836 }
872 if (sarg->capability == V4L2_AUDCAP_STEREO) { 837 msp_set_audmode(client);
873 state->audmode = V4L2_TUNER_MODE_STEREO;
874 } else {
875 state->audmode &= ~V4L2_TUNER_MODE_STEREO;
876 }
877 msp_any_set_audmode(client, state->audmode);
878 msp_wake_thread(client); 838 msp_wake_thread(client);
879 break; 839 break;
880 } 840 }
@@ -886,7 +846,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
886 if (state->radio) 846 if (state->radio)
887 break; 847 break;
888 if (state->opmode == OPMODE_AUTOSELECT) 848 if (state->opmode == OPMODE_AUTOSELECT)
889 msp_any_detect_stereo(client); 849 msp_detect_stereo(client);
890 vt->audmode = state->audmode; 850 vt->audmode = state->audmode;
891 vt->rxsubchans = state->rxsubchans; 851 vt->rxsubchans = state->rxsubchans;
892 vt->capability = V4L2_TUNER_CAP_STEREO | 852 vt->capability = V4L2_TUNER_CAP_STEREO |
@@ -898,11 +858,11 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
898 { 858 {
899 struct v4l2_tuner *vt = (struct v4l2_tuner *)arg; 859 struct v4l2_tuner *vt = (struct v4l2_tuner *)arg;
900 860
901 if (state->radio) 861 if (state->radio) /* TODO: add mono/stereo support for radio */
902 break; 862 break;
863 state->audmode = vt->audmode;
903 /* only set audmode */ 864 /* only set audmode */
904 if (vt->audmode != -1 && vt->audmode != 0) 865 msp_set_audmode(client);
905 msp_any_set_audmode(client, vt->audmode);
906 break; 866 break;
907 } 867 }
908 868
@@ -927,7 +887,6 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
927 return -EINVAL; 887 return -EINVAL;
928 } 888 }
929 break; 889 break;
930
931 } 890 }
932 891
933 case VIDIOC_S_AUDOUT: 892 case VIDIOC_S_AUDOUT:
@@ -993,7 +952,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
993 const char *p; 952 const char *p;
994 953
995 if (state->opmode == OPMODE_AUTOSELECT) 954 if (state->opmode == OPMODE_AUTOSELECT)
996 msp_any_detect_stereo(client); 955 msp_detect_stereo(client);
997 v4l_info(client, "%s rev1 = 0x%04x rev2 = 0x%04x\n", 956 v4l_info(client, "%s rev1 = 0x%04x rev2 = 0x%04x\n",
998 client->name, state->rev1, state->rev2); 957 client->name, state->rev1, state->rev2);
999 v4l_info(client, "Audio: volume %d%s\n", 958 v4l_info(client, "Audio: volume %d%s\n",
@@ -1094,6 +1053,7 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
1094 1053
1095 memset(state, 0, sizeof(*state)); 1054 memset(state, 0, sizeof(*state));
1096 state->v4l2_std = V4L2_STD_NTSC; 1055 state->v4l2_std = V4L2_STD_NTSC;
1056 state->audmode = V4L2_TUNER_MODE_LANG1;
1097 state->volume = 58880; /* 0db gain */ 1057 state->volume = 58880; /* 0db gain */
1098 state->balance = 32768; /* 0db gain */ 1058 state->balance = 32768; /* 0db gain */
1099 state->bass = 32768; 1059 state->bass = 32768;
diff --git a/drivers/media/video/msp3400-kthreads.c b/drivers/media/video/msp3400-kthreads.c
index 2072c3efebb3..852ab6a115fa 100644
--- a/drivers/media/video/msp3400-kthreads.c
+++ b/drivers/media/video/msp3400-kthreads.c
@@ -109,7 +109,7 @@ static struct msp3400c_init_data_dem {
109 {-2, -8, -10, 10, 50, 86}, 109 {-2, -8, -10, 10, 50, 86},
110 {-4, -12, -9, 23, 79, 126}, 110 {-4, -12, -9, 23, 79, 126},
111 MSP_CARRIER(6.5), MSP_CARRIER(6.5), 111 MSP_CARRIER(6.5), MSP_CARRIER(6.5),
112 0x00c6, 0x0140, 0x0120, 0x7c03 112 0x00c6, 0x0140, 0x0120, 0x7c00
113 }, 113 },
114}; 114};
115 115
@@ -154,54 +154,60 @@ const char *msp_standard_std_name(int std)
154 return "unknown"; 154 return "unknown";
155} 155}
156 156
157void msp3400c_setcarrier(struct i2c_client *client, int cdo1, int cdo2) 157static void msp_set_source(struct i2c_client *client, u16 src)
158{
159 struct msp_state *state = i2c_get_clientdata(client);
160
161 if (msp_dolby) {
162 msp_write_dsp(client, 0x0008, 0x0520); /* I2S1 */
163 msp_write_dsp(client, 0x0009, 0x0620); /* I2S2 */
164 } else {
165 msp_write_dsp(client, 0x0008, src);
166 msp_write_dsp(client, 0x0009, src);
167 }
168 msp_write_dsp(client, 0x000a, src);
169 msp_write_dsp(client, 0x000b, src);
170 msp_write_dsp(client, 0x000c, src);
171 if (state->has_scart23_in_scart2_out)
172 msp_write_dsp(client, 0x0041, src);
173}
174
175void msp3400c_set_carrier(struct i2c_client *client, int cdo1, int cdo2)
158{ 176{
159 msp_write_dem(client, 0x0093, cdo1 & 0xfff); 177 msp_write_dem(client, 0x0093, cdo1 & 0xfff);
160 msp_write_dem(client, 0x009b, cdo1 >> 12); 178 msp_write_dem(client, 0x009b, cdo1 >> 12);
161 msp_write_dem(client, 0x00a3, cdo2 & 0xfff); 179 msp_write_dem(client, 0x00a3, cdo2 & 0xfff);
162 msp_write_dem(client, 0x00ab, cdo2 >> 12); 180 msp_write_dem(client, 0x00ab, cdo2 >> 12);
163 msp_write_dem(client, 0x0056, 0); /*LOAD_REG_1/2*/ 181 msp_write_dem(client, 0x0056, 0); /* LOAD_REG_1/2 */
164} 182}
165 183
166void msp3400c_setmode(struct i2c_client *client, int type) 184void msp3400c_set_mode(struct i2c_client *client, int mode)
167{ 185{
168 struct msp_state *state = i2c_get_clientdata(client); 186 struct msp_state *state = i2c_get_clientdata(client);
187 struct msp3400c_init_data_dem *data = &msp3400c_init_data[mode];
169 int i; 188 int i;
170 189
171 v4l_dbg(1, msp_debug, client, "setmode: %d\n", type); 190 v4l_dbg(1, msp_debug, client, "set_mode: %d\n", mode);
172 state->mode = type; 191 state->mode = mode;
173 state->audmode = V4L2_TUNER_MODE_MONO;
174 state->rxsubchans = V4L2_TUNER_SUB_MONO; 192 state->rxsubchans = V4L2_TUNER_SUB_MONO;
175 193
176 msp_write_dem(client, 0x00bb, msp3400c_init_data[type].ad_cv); 194 msp_write_dem(client, 0x00bb, data->ad_cv);
177 195
178 for (i = 5; i >= 0; i--) /* fir 1 */ 196 for (i = 5; i >= 0; i--) /* fir 1 */
179 msp_write_dem(client, 0x0001, msp3400c_init_data[type].fir1[i]); 197 msp_write_dem(client, 0x0001, data->fir1[i]);
180 198
181 msp_write_dem(client, 0x0005, 0x0004); /* fir 2 */ 199 msp_write_dem(client, 0x0005, 0x0004); /* fir 2 */
182 msp_write_dem(client, 0x0005, 0x0040); 200 msp_write_dem(client, 0x0005, 0x0040);
183 msp_write_dem(client, 0x0005, 0x0000); 201 msp_write_dem(client, 0x0005, 0x0000);
184 for (i = 5; i >= 0; i--) 202 for (i = 5; i >= 0; i--)
185 msp_write_dem(client, 0x0005, msp3400c_init_data[type].fir2[i]); 203 msp_write_dem(client, 0x0005, data->fir2[i]);
186 204
187 msp_write_dem(client, 0x0083, msp3400c_init_data[type].mode_reg); 205 msp_write_dem(client, 0x0083, data->mode_reg);
188 206
189 msp3400c_setcarrier(client, msp3400c_init_data[type].cdo1, 207 msp3400c_set_carrier(client, data->cdo1, data->cdo2);
190 msp3400c_init_data[type].cdo2);
191 208
192 msp_write_dem(client, 0x0056, 0); /*LOAD_REG_1/2*/ 209 msp_set_source(client, data->dsp_src);
193 210 msp_write_dsp(client, 0x000e, data->dsp_matrix);
194 if (msp_dolby) {
195 msp_write_dsp(client, 0x0008, 0x0520); /* I2S1 */
196 msp_write_dsp(client, 0x0009, 0x0620); /* I2S2 */
197 msp_write_dsp(client, 0x000b, msp3400c_init_data[type].dsp_src);
198 } else {
199 msp_write_dsp(client, 0x0008, msp3400c_init_data[type].dsp_src);
200 msp_write_dsp(client, 0x0009, msp3400c_init_data[type].dsp_src);
201 msp_write_dsp(client, 0x000b, msp3400c_init_data[type].dsp_src);
202 }
203 msp_write_dsp(client, 0x000a, msp3400c_init_data[type].dsp_src);
204 msp_write_dsp(client, 0x000e, msp3400c_init_data[type].dsp_matrix);
205 211
206 if (state->has_nicam) { 212 if (state->has_nicam) {
207 /* nicam prescale */ 213 /* nicam prescale */
@@ -209,29 +215,31 @@ void msp3400c_setmode(struct i2c_client *client, int type)
209 } 215 }
210} 216}
211 217
212/* turn on/off nicam + stereo */ 218/* Set audio mode. Note that the pre-'G' models do not support BTSC+SAP,
213void msp3400c_setstereo(struct i2c_client *client, int mode) 219 nor do they support stereo BTSC. */
220static void msp3400c_set_audmode(struct i2c_client *client)
214{ 221{
215 static char *strmode[] = { "mono", "stereo", "lang2", "lang1" }; 222 static char *strmode[] = { "mono", "stereo", "lang2", "lang1" };
216 struct msp_state *state = i2c_get_clientdata(client); 223 struct msp_state *state = i2c_get_clientdata(client);
217 int nicam = 0; /* channel source: FM/AM or nicam */ 224 char *modestr = (state->audmode >= 0 && state->audmode < 4) ?
218 int src = 0; 225 strmode[state->audmode] : "unknown";
226 int src = 0; /* channel source: FM/AM, nicam or SCART */
219 227
220 if (state->opmode == OPMODE_AUTOSELECT) { 228 if (state->opmode == OPMODE_AUTOSELECT) {
221 /* this method would break everything, let's make sure 229 /* this method would break everything, let's make sure
222 * it's never called 230 * it's never called
223 */ 231 */
224 v4l_dbg(1, msp_debug, client, "setstereo called with mode=%d instead of set_source (ignored)\n", 232 v4l_dbg(1, msp_debug, client,
225 mode); 233 "set_audmode called with mode=%d instead of set_source (ignored)\n",
234 state->audmode);
226 return; 235 return;
227 } 236 }
228 237
229 /* switch demodulator */ 238 /* switch demodulator */
230 switch (state->mode) { 239 switch (state->mode) {
231 case MSP_MODE_FM_TERRA: 240 case MSP_MODE_FM_TERRA:
232 v4l_dbg(1, msp_debug, client, "FM setstereo: %s\n", strmode[mode]); 241 v4l_dbg(1, msp_debug, client, "FM set_audmode: %s\n", modestr);
233 msp3400c_setcarrier(client, state->second, state->main); 242 switch (state->audmode) {
234 switch (mode) {
235 case V4L2_TUNER_MODE_STEREO: 243 case V4L2_TUNER_MODE_STEREO:
236 msp_write_dsp(client, 0x000e, 0x3001); 244 msp_write_dsp(client, 0x000e, 0x3001);
237 break; 245 break;
@@ -243,50 +251,49 @@ void msp3400c_setstereo(struct i2c_client *client, int mode)
243 } 251 }
244 break; 252 break;
245 case MSP_MODE_FM_SAT: 253 case MSP_MODE_FM_SAT:
246 v4l_dbg(1, msp_debug, client, "SAT setstereo: %s\n", strmode[mode]); 254 v4l_dbg(1, msp_debug, client, "SAT set_audmode: %s\n", modestr);
247 switch (mode) { 255 switch (state->audmode) {
248 case V4L2_TUNER_MODE_MONO: 256 case V4L2_TUNER_MODE_MONO:
249 msp3400c_setcarrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5)); 257 msp3400c_set_carrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5));
250 break; 258 break;
251 case V4L2_TUNER_MODE_STEREO: 259 case V4L2_TUNER_MODE_STEREO:
252 msp3400c_setcarrier(client, MSP_CARRIER(7.2), MSP_CARRIER(7.02)); 260 msp3400c_set_carrier(client, MSP_CARRIER(7.2), MSP_CARRIER(7.02));
253 break; 261 break;
254 case V4L2_TUNER_MODE_LANG1: 262 case V4L2_TUNER_MODE_LANG1:
255 msp3400c_setcarrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02)); 263 msp3400c_set_carrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
256 break; 264 break;
257 case V4L2_TUNER_MODE_LANG2: 265 case V4L2_TUNER_MODE_LANG2:
258 msp3400c_setcarrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02)); 266 msp3400c_set_carrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
259 break; 267 break;
260 } 268 }
261 break; 269 break;
262 case MSP_MODE_FM_NICAM1: 270 case MSP_MODE_FM_NICAM1:
263 case MSP_MODE_FM_NICAM2: 271 case MSP_MODE_FM_NICAM2:
264 case MSP_MODE_AM_NICAM: 272 case MSP_MODE_AM_NICAM:
265 v4l_dbg(1, msp_debug, client, "NICAM setstereo: %s\n",strmode[mode]); 273 v4l_dbg(1, msp_debug, client, "NICAM set_audmode: %s\n",modestr);
266 msp3400c_setcarrier(client,state->second,state->main); 274 msp3400c_set_carrier(client, state->second, state->main);
267 if (state->nicam_on) 275 if (state->nicam_on)
268 nicam=0x0100; 276 src = 0x0100; /* NICAM */
269 break; 277 break;
270 case MSP_MODE_BTSC: 278 case MSP_MODE_BTSC:
271 v4l_dbg(1, msp_debug, client, "BTSC setstereo: %s\n",strmode[mode]); 279 v4l_dbg(1, msp_debug, client, "BTSC set_audmode: %s\n",modestr);
272 nicam=0x0300;
273 break; 280 break;
274 case MSP_MODE_EXTERN: 281 case MSP_MODE_EXTERN:
275 v4l_dbg(1, msp_debug, client, "extern setstereo: %s\n",strmode[mode]); 282 v4l_dbg(1, msp_debug, client, "extern set_audmode: %s\n",modestr);
276 nicam = 0x0200; 283 src = 0x0200; /* SCART */
277 break; 284 break;
278 case MSP_MODE_FM_RADIO: 285 case MSP_MODE_FM_RADIO:
279 v4l_dbg(1, msp_debug, client, "FM-Radio setstereo: %s\n",strmode[mode]); 286 v4l_dbg(1, msp_debug, client, "FM-Radio set_audmode: %s\n",modestr);
280 break; 287 break;
281 default: 288 default:
282 v4l_dbg(1, msp_debug, client, "mono setstereo\n"); 289 v4l_dbg(1, msp_debug, client, "mono set_audmode\n");
283 return; 290 return;
284 } 291 }
285 292
286 /* switch audio */ 293 /* switch audio */
287 switch (mode) { 294 switch (state->audmode) {
288 case V4L2_TUNER_MODE_STEREO: 295 case V4L2_TUNER_MODE_STEREO:
289 src = 0x0020 | nicam; 296 src |= 0x0020;
290 break; 297 break;
291 case V4L2_TUNER_MODE_MONO: 298 case V4L2_TUNER_MODE_MONO:
292 if (state->mode == MSP_MODE_AM_NICAM) { 299 if (state->mode == MSP_MODE_AM_NICAM) {
@@ -297,29 +304,22 @@ void msp3400c_setstereo(struct i2c_client *client, int mode)
297 src = 0x0200; 304 src = 0x0200;
298 break; 305 break;
299 } 306 }
307 if (state->rxsubchans & V4L2_TUNER_SUB_STEREO)
308 src = 0x0030;
309 break;
300 case V4L2_TUNER_MODE_LANG1: 310 case V4L2_TUNER_MODE_LANG1:
301 src = 0x0000 | nicam; 311 /* switch to stereo for stereo transmission, otherwise
312 keep first language */
313 if (state->rxsubchans & V4L2_TUNER_SUB_STEREO)
314 src |= 0x0020;
302 break; 315 break;
303 case V4L2_TUNER_MODE_LANG2: 316 case V4L2_TUNER_MODE_LANG2:
304 src = 0x0010 | nicam; 317 src |= 0x0010;
305 break; 318 break;
306 } 319 }
307 v4l_dbg(1, msp_debug, client, "setstereo final source/matrix = 0x%x\n", src); 320 v4l_dbg(1, msp_debug, client, "set_audmode final source/matrix = 0x%x\n", src);
308 321
309 if (msp_dolby) { 322 msp_set_source(client, src);
310 msp_write_dsp(client, 0x0008, 0x0520);
311 msp_write_dsp(client, 0x0009, 0x0620);
312 msp_write_dsp(client, 0x000a, src);
313 msp_write_dsp(client, 0x000b, src);
314 } else {
315 msp_write_dsp(client, 0x0008, src);
316 msp_write_dsp(client, 0x0009, src);
317 msp_write_dsp(client, 0x000a, src);
318 msp_write_dsp(client, 0x000b, src);
319 msp_write_dsp(client, 0x000c, src);
320 if (state->has_scart23_in_scart2_out)
321 msp_write_dsp(client, 0x0041, src);
322 }
323} 323}
324 324
325static void msp3400c_print_mode(struct i2c_client *client) 325static void msp3400c_print_mode(struct i2c_client *client)
@@ -347,12 +347,12 @@ static void msp3400c_print_mode(struct i2c_client *client)
347 347
348/* ----------------------------------------------------------------------- */ 348/* ----------------------------------------------------------------------- */
349 349
350int autodetect_stereo(struct i2c_client *client) 350static int msp3400c_detect_stereo(struct i2c_client *client)
351{ 351{
352 struct msp_state *state = i2c_get_clientdata(client); 352 struct msp_state *state = i2c_get_clientdata(client);
353 int val; 353 int val;
354 int rxsubchans = state->rxsubchans; 354 int rxsubchans = state->rxsubchans;
355 int newnicam = state->nicam_on; 355 int newnicam = state->nicam_on;
356 int update = 0; 356 int update = 0;
357 357
358 switch (state->mode) { 358 switch (state->mode) {
@@ -362,7 +362,7 @@ int autodetect_stereo(struct i2c_client *client)
362 val -= 65536; 362 val -= 65536;
363 v4l_dbg(2, msp_debug, client, "stereo detect register: %d\n", val); 363 v4l_dbg(2, msp_debug, client, "stereo detect register: %d\n", val);
364 if (val > 4096) { 364 if (val > 4096) {
365 rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO; 365 rxsubchans = V4L2_TUNER_SUB_STEREO;
366 } else if (val < -4096) { 366 } else if (val < -4096) {
367 rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 367 rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
368 } else { 368 } else {
@@ -386,14 +386,11 @@ int autodetect_stereo(struct i2c_client *client)
386 break; 386 break;
387 case 1: 387 case 1:
388 case 9: 388 case 9:
389 rxsubchans = V4L2_TUNER_SUB_MONO 389 rxsubchans = V4L2_TUNER_SUB_MONO;
390 | V4L2_TUNER_SUB_LANG1;
391 break; 390 break;
392 case 2: 391 case 2:
393 case 10: 392 case 10:
394 rxsubchans = V4L2_TUNER_SUB_MONO 393 rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
395 | V4L2_TUNER_SUB_LANG1
396 | V4L2_TUNER_SUB_LANG2;
397 break; 394 break;
398 default: 395 default:
399 rxsubchans = V4L2_TUNER_SUB_MONO; 396 rxsubchans = V4L2_TUNER_SUB_MONO;
@@ -405,30 +402,17 @@ int autodetect_stereo(struct i2c_client *client)
405 rxsubchans = V4L2_TUNER_SUB_MONO; 402 rxsubchans = V4L2_TUNER_SUB_MONO;
406 } 403 }
407 break; 404 break;
408 case MSP_MODE_BTSC:
409 val = msp_read_dem(client, 0x200);
410 v4l_dbg(2, msp_debug, client, "status=0x%x (pri=%s, sec=%s, %s%s%s)\n",
411 val,
412 (val & 0x0002) ? "no" : "yes",
413 (val & 0x0004) ? "no" : "yes",
414 (val & 0x0040) ? "stereo" : "mono",
415 (val & 0x0080) ? ", nicam 2nd mono" : "",
416 (val & 0x0100) ? ", bilingual/SAP" : "");
417 rxsubchans = V4L2_TUNER_SUB_MONO;
418 if (val & 0x0040) rxsubchans |= V4L2_TUNER_SUB_STEREO;
419 if (val & 0x0100) rxsubchans |= V4L2_TUNER_SUB_LANG1;
420 break;
421 } 405 }
422 if (rxsubchans != state->rxsubchans) { 406 if (rxsubchans != state->rxsubchans) {
423 update = 1; 407 update = 1;
424 v4l_dbg(1, msp_debug, client, "watch: rxsubchans %d => %d\n", 408 v4l_dbg(1, msp_debug, client, "watch: rxsubchans %02x => %02x\n",
425 state->rxsubchans,rxsubchans); 409 state->rxsubchans, rxsubchans);
426 state->rxsubchans = rxsubchans; 410 state->rxsubchans = rxsubchans;
427 } 411 }
428 if (newnicam != state->nicam_on) { 412 if (newnicam != state->nicam_on) {
429 update = 1; 413 update = 1;
430 v4l_dbg(1, msp_debug, client, "watch: nicam %d => %d\n", 414 v4l_dbg(1, msp_debug, client, "watch: nicam %d => %d\n",
431 state->nicam_on,newnicam); 415 state->nicam_on, newnicam);
432 state->nicam_on = newnicam; 416 state->nicam_on = newnicam;
433 } 417 }
434 return update; 418 return update;
@@ -443,13 +427,8 @@ static void watch_stereo(struct i2c_client *client)
443{ 427{
444 struct msp_state *state = i2c_get_clientdata(client); 428 struct msp_state *state = i2c_get_clientdata(client);
445 429
446 if (autodetect_stereo(client)) { 430 if (msp3400c_detect_stereo(client)) {
447 if (state->rxsubchans & V4L2_TUNER_SUB_STEREO) 431 msp3400c_set_audmode(client);
448 msp3400c_setstereo(client, V4L2_TUNER_MODE_STEREO);
449 else if (state->rxsubchans & V4L2_TUNER_SUB_LANG1)
450 msp3400c_setstereo(client, V4L2_TUNER_MODE_LANG1);
451 else
452 msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
453 } 432 }
454 433
455 if (msp_once) 434 if (msp_once)
@@ -461,7 +440,7 @@ int msp3400c_thread(void *data)
461 struct i2c_client *client = data; 440 struct i2c_client *client = data;
462 struct msp_state *state = i2c_get_clientdata(client); 441 struct msp_state *state = i2c_get_clientdata(client);
463 struct msp3400c_carrier_detect *cd; 442 struct msp3400c_carrier_detect *cd;
464 int count, max1,max2,val1,val2, val,this; 443 int count, max1, max2, val1, val2, val, this;
465 444
466 445
467 v4l_dbg(1, msp_debug, client, "msp3400 daemon started\n"); 446 v4l_dbg(1, msp_debug, client, "msp3400 daemon started\n");
@@ -471,7 +450,7 @@ int msp3400c_thread(void *data)
471 v4l_dbg(2, msp_debug, client, "msp3400 thread: wakeup\n"); 450 v4l_dbg(2, msp_debug, client, "msp3400 thread: wakeup\n");
472 451
473 restart: 452 restart:
474 v4l_dbg(1, msp_debug, client, "thread: restart scan\n"); 453 v4l_dbg(2, msp_debug, client, "thread: restart scan\n");
475 state->restart = 0; 454 state->restart = 0;
476 if (kthread_should_stop()) 455 if (kthread_should_stop())
477 break; 456 break;
@@ -485,13 +464,14 @@ int msp3400c_thread(void *data)
485 464
486 /* mute */ 465 /* mute */
487 msp_set_mute(client); 466 msp_set_mute(client);
488 msp3400c_setmode(client, MSP_MODE_AM_DETECT /* +1 */ ); 467 msp3400c_set_mode(client, MSP_MODE_AM_DETECT /* +1 */ );
489 val1 = val2 = 0; 468 val1 = val2 = 0;
490 max1 = max2 = -1; 469 max1 = max2 = -1;
491 state->watch_stereo = 0; 470 state->watch_stereo = 0;
471 state->nicam_on = 0;
492 472
493 /* some time for the tuner to sync */ 473 /* some time for the tuner to sync */
494 if (msp_sleep(state,200)) 474 if (msp_sleep(state, 200))
495 goto restart; 475 goto restart;
496 476
497 /* carrier detect pass #1 -- main carrier */ 477 /* carrier detect pass #1 -- main carrier */
@@ -506,7 +486,7 @@ int msp3400c_thread(void *data)
506 } 486 }
507 487
508 for (this = 0; this < count; this++) { 488 for (this = 0; this < count; this++) {
509 msp3400c_setcarrier(client, cd[this].cdo,cd[this].cdo); 489 msp3400c_set_carrier(client, cd[this].cdo, cd[this].cdo);
510 if (msp_sleep(state,100)) 490 if (msp_sleep(state,100))
511 goto restart; 491 goto restart;
512 val = msp_read_dsp(client, 0x1b); 492 val = msp_read_dsp(client, 0x1b);
@@ -542,7 +522,7 @@ int msp3400c_thread(void *data)
542 max2 = 0; 522 max2 = 0;
543 } 523 }
544 for (this = 0; this < count; this++) { 524 for (this = 0; this < count; this++) {
545 msp3400c_setcarrier(client, cd[this].cdo,cd[this].cdo); 525 msp3400c_set_carrier(client, cd[this].cdo, cd[this].cdo);
546 if (msp_sleep(state,100)) 526 if (msp_sleep(state,100))
547 goto restart; 527 goto restart;
548 val = msp_read_dsp(client, 0x1b); 528 val = msp_read_dsp(client, 0x1b);
@@ -554,22 +534,20 @@ int msp3400c_thread(void *data)
554 } 534 }
555 535
556 /* program the msp3400 according to the results */ 536 /* program the msp3400 according to the results */
557 state->main = msp3400c_carrier_detect_main[max1].cdo; 537 state->main = msp3400c_carrier_detect_main[max1].cdo;
558 switch (max1) { 538 switch (max1) {
559 case 1: /* 5.5 */ 539 case 1: /* 5.5 */
560 if (max2 == 0) { 540 if (max2 == 0) {
561 /* B/G FM-stereo */ 541 /* B/G FM-stereo */
562 state->second = msp3400c_carrier_detect_55[max2].cdo; 542 state->second = msp3400c_carrier_detect_55[max2].cdo;
563 msp3400c_setmode(client, MSP_MODE_FM_TERRA); 543 msp3400c_set_mode(client, MSP_MODE_FM_TERRA);
564 state->nicam_on = 0;
565 msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
566 state->watch_stereo = 1; 544 state->watch_stereo = 1;
567 } else if (max2 == 1 && state->has_nicam) { 545 } else if (max2 == 1 && state->has_nicam) {
568 /* B/G NICAM */ 546 /* B/G NICAM */
569 state->second = msp3400c_carrier_detect_55[max2].cdo; 547 state->second = msp3400c_carrier_detect_55[max2].cdo;
570 msp3400c_setmode(client, MSP_MODE_FM_NICAM1); 548 msp3400c_set_mode(client, MSP_MODE_FM_NICAM1);
549 msp3400c_set_carrier(client, state->second, state->main);
571 state->nicam_on = 1; 550 state->nicam_on = 1;
572 msp3400c_setcarrier(client, state->second, state->main);
573 state->watch_stereo = 1; 551 state->watch_stereo = 1;
574 } else { 552 } else {
575 goto no_second; 553 goto no_second;
@@ -578,35 +556,31 @@ int msp3400c_thread(void *data)
578 case 2: /* 6.0 */ 556 case 2: /* 6.0 */
579 /* PAL I NICAM */ 557 /* PAL I NICAM */
580 state->second = MSP_CARRIER(6.552); 558 state->second = MSP_CARRIER(6.552);
581 msp3400c_setmode(client, MSP_MODE_FM_NICAM2); 559 msp3400c_set_mode(client, MSP_MODE_FM_NICAM2);
560 msp3400c_set_carrier(client, state->second, state->main);
582 state->nicam_on = 1; 561 state->nicam_on = 1;
583 msp3400c_setcarrier(client, state->second, state->main);
584 state->watch_stereo = 1; 562 state->watch_stereo = 1;
585 break; 563 break;
586 case 3: /* 6.5 */ 564 case 3: /* 6.5 */
587 if (max2 == 1 || max2 == 2) { 565 if (max2 == 1 || max2 == 2) {
588 /* D/K FM-stereo */ 566 /* D/K FM-stereo */
589 state->second = msp3400c_carrier_detect_65[max2].cdo; 567 state->second = msp3400c_carrier_detect_65[max2].cdo;
590 msp3400c_setmode(client, MSP_MODE_FM_TERRA); 568 msp3400c_set_mode(client, MSP_MODE_FM_TERRA);
591 state->nicam_on = 0;
592 msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
593 state->watch_stereo = 1; 569 state->watch_stereo = 1;
594 } else if (max2 == 0 && (state->v4l2_std & V4L2_STD_SECAM)) { 570 } else if (max2 == 0 && (state->v4l2_std & V4L2_STD_SECAM)) {
595 /* L NICAM or AM-mono */ 571 /* L NICAM or AM-mono */
596 state->second = msp3400c_carrier_detect_65[max2].cdo; 572 state->second = msp3400c_carrier_detect_65[max2].cdo;
597 msp3400c_setmode(client, MSP_MODE_AM_NICAM); 573 msp3400c_set_mode(client, MSP_MODE_AM_NICAM);
598 state->nicam_on = 0; 574 msp3400c_set_carrier(client, state->second, state->main);
599 msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
600 msp3400c_setcarrier(client, state->second, state->main);
601 /* volume prescale for SCART (AM mono input) */ 575 /* volume prescale for SCART (AM mono input) */
602 msp_write_dsp(client, 0x000d, 0x1900); 576 msp_write_dsp(client, 0x000d, 0x1900);
603 state->watch_stereo = 1; 577 state->watch_stereo = 1;
604 } else if (max2 == 0 && state->has_nicam) { 578 } else if (max2 == 0 && state->has_nicam) {
605 /* D/K NICAM */ 579 /* D/K NICAM */
606 state->second = msp3400c_carrier_detect_65[max2].cdo; 580 state->second = msp3400c_carrier_detect_65[max2].cdo;
607 msp3400c_setmode(client, MSP_MODE_FM_NICAM1); 581 msp3400c_set_mode(client, MSP_MODE_FM_NICAM1);
582 msp3400c_set_carrier(client, state->second, state->main);
608 state->nicam_on = 1; 583 state->nicam_on = 1;
609 msp3400c_setcarrier(client, state->second, state->main);
610 state->watch_stereo = 1; 584 state->watch_stereo = 1;
611 } else { 585 } else {
612 goto no_second; 586 goto no_second;
@@ -616,23 +590,25 @@ int msp3400c_thread(void *data)
616 default: 590 default:
617 no_second: 591 no_second:
618 state->second = msp3400c_carrier_detect_main[max1].cdo; 592 state->second = msp3400c_carrier_detect_main[max1].cdo;
619 msp3400c_setmode(client, MSP_MODE_FM_TERRA); 593 msp3400c_set_mode(client, MSP_MODE_FM_TERRA);
620 state->nicam_on = 0; 594 msp3400c_set_carrier(client, state->second, state->main);
621 msp3400c_setcarrier(client, state->second, state->main);
622 state->rxsubchans = V4L2_TUNER_SUB_MONO; 595 state->rxsubchans = V4L2_TUNER_SUB_MONO;
623 msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
624 break; 596 break;
625 } 597 }
626 598
627 /* unmute */ 599 /* unmute */
628 msp_set_audio(client); 600 msp_set_audio(client);
601 msp3400c_set_audmode(client);
629 602
630 if (msp_debug) 603 if (msp_debug)
631 msp3400c_print_mode(client); 604 msp3400c_print_mode(client);
632 605
633 /* monitor tv audio mode */ 606 /* monitor tv audio mode, the first time don't wait
607 so long to get a quick stereo/bilingual result */
608 if (msp_sleep(state, 1000))
609 goto restart;
634 while (state->watch_stereo) { 610 while (state->watch_stereo) {
635 if (msp_sleep(state,5000)) 611 if (msp_sleep(state, 5000))
636 goto restart; 612 goto restart;
637 watch_stereo(client); 613 watch_stereo(client);
638 } 614 }
@@ -656,7 +632,7 @@ int msp3410d_thread(void *data)
656 v4l_dbg(2, msp_debug, client, "msp3410 thread: wakeup\n"); 632 v4l_dbg(2, msp_debug, client, "msp3410 thread: wakeup\n");
657 633
658 restart: 634 restart:
659 v4l_dbg(1, msp_debug, client, "thread: restart scan\n"); 635 v4l_dbg(2, msp_debug, client, "thread: restart scan\n");
660 state->restart = 0; 636 state->restart = 0;
661 if (kthread_should_stop()) 637 if (kthread_should_stop())
662 break; 638 break;
@@ -681,9 +657,10 @@ int msp3410d_thread(void *data)
681 else 657 else
682 std = (state->v4l2_std & V4L2_STD_NTSC) ? 0x20 : 1; 658 std = (state->v4l2_std & V4L2_STD_NTSC) ? 0x20 : 1;
683 state->watch_stereo = 0; 659 state->watch_stereo = 0;
660 state->nicam_on = 0;
684 661
685 if (msp_debug) 662 if (msp_debug)
686 v4l_dbg(1, msp_debug, client, "setting standard: %s (0x%04x)\n", 663 v4l_dbg(2, msp_debug, client, "setting standard: %s (0x%04x)\n",
687 msp_standard_std_name(std), std); 664 msp_standard_std_name(std), std);
688 665
689 if (std != 1) { 666 if (std != 1) {
@@ -700,7 +677,7 @@ int msp3410d_thread(void *data)
700 val = msp_read_dem(client, 0x7e); 677 val = msp_read_dem(client, 0x7e);
701 if (val < 0x07ff) 678 if (val < 0x07ff)
702 break; 679 break;
703 v4l_dbg(1, msp_debug, client, "detection still in progress\n"); 680 v4l_dbg(2, msp_debug, client, "detection still in progress\n");
704 } 681 }
705 } 682 }
706 for (i = 0; msp_stdlist[i].name != NULL; i++) 683 for (i = 0; msp_stdlist[i].name != NULL; i++)
@@ -739,48 +716,34 @@ int msp3410d_thread(void *data)
739 state->rxsubchans = V4L2_TUNER_SUB_STEREO; 716 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
740 state->nicam_on = 1; 717 state->nicam_on = 1;
741 state->watch_stereo = 1; 718 state->watch_stereo = 1;
742 msp3400c_setstereo(client,V4L2_TUNER_MODE_STEREO);
743 break; 719 break;
744 case 0x0009: 720 case 0x0009:
745 state->mode = MSP_MODE_AM_NICAM; 721 state->mode = MSP_MODE_AM_NICAM;
746 state->rxsubchans = V4L2_TUNER_SUB_MONO; 722 state->rxsubchans = V4L2_TUNER_SUB_MONO;
747 state->nicam_on = 1; 723 state->nicam_on = 1;
748 msp3400c_setstereo(client,V4L2_TUNER_MODE_MONO);
749 state->watch_stereo = 1; 724 state->watch_stereo = 1;
750 break; 725 break;
751 case 0x0020: /* BTSC */ 726 case 0x0020: /* BTSC */
752 /* just turn on stereo */ 727 /* The pre-'G' models only have BTSC-mono */
753 state->mode = MSP_MODE_BTSC; 728 state->mode = MSP_MODE_BTSC;
754 state->rxsubchans = V4L2_TUNER_SUB_STEREO; 729 state->rxsubchans = V4L2_TUNER_SUB_MONO;
755 state->nicam_on = 0;
756 state->watch_stereo = 1;
757 msp3400c_setstereo(client,V4L2_TUNER_MODE_STEREO);
758 break; 730 break;
759 case 0x0040: /* FM radio */ 731 case 0x0040: /* FM radio */
760 state->mode = MSP_MODE_FM_RADIO; 732 state->mode = MSP_MODE_FM_RADIO;
761 state->rxsubchans = V4L2_TUNER_SUB_STEREO; 733 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
762 state->audmode = V4L2_TUNER_MODE_STEREO;
763 state->nicam_on = 0;
764 state->watch_stereo = 0;
765 /* not needed in theory if we have radio, but 734 /* not needed in theory if we have radio, but
766 short programming enables carrier mute */ 735 short programming enables carrier mute */
767 msp3400c_setmode(client, MSP_MODE_FM_RADIO); 736 msp3400c_set_mode(client, MSP_MODE_FM_RADIO);
768 msp3400c_setcarrier(client, MSP_CARRIER(10.7), 737 msp3400c_set_carrier(client, MSP_CARRIER(10.7),
769 MSP_CARRIER(10.7)); 738 MSP_CARRIER(10.7));
770 /* scart routing */ 739 /* scart routing (this doesn't belong here I think) */
771 msp_set_scart(client,SCART_IN2,0); 740 msp_set_scart(client,SCART_IN2,0);
772 /* msp34xx does radio decoding */
773 msp_write_dsp(client, 0x08, 0x0020);
774 msp_write_dsp(client, 0x09, 0x0020);
775 msp_write_dsp(client, 0x0b, 0x0020);
776 break; 741 break;
777 case 0x0003: 742 case 0x0003:
778 case 0x0004: 743 case 0x0004:
779 case 0x0005: 744 case 0x0005:
780 state->mode = MSP_MODE_FM_TERRA; 745 state->mode = MSP_MODE_FM_TERRA;
781 state->rxsubchans = V4L2_TUNER_SUB_MONO; 746 state->rxsubchans = V4L2_TUNER_SUB_MONO;
782 state->audmode = V4L2_TUNER_MODE_MONO;
783 state->nicam_on = 0;
784 state->watch_stereo = 1; 747 state->watch_stereo = 1;
785 break; 748 break;
786 } 749 }
@@ -791,11 +754,16 @@ int msp3410d_thread(void *data)
791 if (state->has_i2s_conf) 754 if (state->has_i2s_conf)
792 msp_write_dem(client, 0x40, state->i2s_mode); 755 msp_write_dem(client, 0x40, state->i2s_mode);
793 756
794 /* monitor tv audio mode */ 757 msp3400c_set_audmode(client);
758
759 /* monitor tv audio mode, the first time don't wait
760 so long to get a quick stereo/bilingual result */
761 if (msp_sleep(state, 1000))
762 goto restart;
795 while (state->watch_stereo) { 763 while (state->watch_stereo) {
796 if (msp_sleep(state,5000))
797 goto restart;
798 watch_stereo(client); 764 watch_stereo(client);
765 if (msp_sleep(state, 5000))
766 goto restart;
799 } 767 }
800 } 768 }
801 v4l_dbg(1, msp_debug, client, "thread: exit\n"); 769 v4l_dbg(1, msp_debug, client, "thread: exit\n");
@@ -813,7 +781,7 @@ int msp3410d_thread(void *data)
813 * the value for source is the same as bit 15:8 of DSP registers 0x08, 781 * the value for source is the same as bit 15:8 of DSP registers 0x08,
814 * 0x0a and 0x0c: 0=mono, 1=stereo or A|B, 2=SCART, 3=stereo or A, 4=stereo or B 782 * 0x0a and 0x0c: 0=mono, 1=stereo or A|B, 2=SCART, 3=stereo or A, 4=stereo or B
815 * 783 *
816 * this function replaces msp3400c_setstereo 784 * this function replaces msp3400c_set_audmode
817 */ 785 */
818static void msp34xxg_set_source(struct i2c_client *client, int source) 786static void msp34xxg_set_source(struct i2c_client *client, int source)
819{ 787{
@@ -826,12 +794,7 @@ static void msp34xxg_set_source(struct i2c_client *client, int source)
826 int value = (source & 0x07) << 8 | (source == 0 ? 0x30 : 0x20); 794 int value = (source & 0x07) << 8 | (source == 0 ? 0x30 : 0x20);
827 795
828 v4l_dbg(1, msp_debug, client, "set source to %d (0x%x)\n", source, value); 796 v4l_dbg(1, msp_debug, client, "set source to %d (0x%x)\n", source, value);
829 /* Loudspeaker Output */ 797 msp_set_source(client, value);
830 msp_write_dsp(client, 0x08, value);
831 /* SCART1 DA Output */
832 msp_write_dsp(client, 0x0a, value);
833 /* Quasi-peak detector */
834 msp_write_dsp(client, 0x0c, value);
835 /* 798 /*
836 * set identification threshold. Personally, I 799 * set identification threshold. Personally, I
837 * I set it to a higher value that the default 800 * I set it to a higher value that the default
@@ -948,13 +911,14 @@ int msp34xxg_thread(void *data)
948 if (msp_write_dsp(client, 0x13, state->acb)) 911 if (msp_write_dsp(client, 0x13, state->acb))
949 return -1; 912 return -1;
950 913
951 msp_write_dem(client, 0x40, state->i2s_mode); 914 if (state->has_i2s_conf)
915 msp_write_dem(client, 0x40, state->i2s_mode);
952 } 916 }
953 v4l_dbg(1, msp_debug, client, "thread: exit\n"); 917 v4l_dbg(1, msp_debug, client, "thread: exit\n");
954 return 0; 918 return 0;
955} 919}
956 920
957void msp34xxg_detect_stereo(struct i2c_client *client) 921static void msp34xxg_detect_stereo(struct i2c_client *client)
958{ 922{
959 struct msp_state *state = i2c_get_clientdata(client); 923 struct msp_state *state = i2c_get_clientdata(client);
960 924
@@ -964,11 +928,11 @@ void msp34xxg_detect_stereo(struct i2c_client *client)
964 928
965 state->rxsubchans = 0; 929 state->rxsubchans = 0;
966 if (is_stereo) 930 if (is_stereo)
967 state->rxsubchans |= V4L2_TUNER_SUB_STEREO; 931 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
968 else 932 else
969 state->rxsubchans |= V4L2_TUNER_SUB_MONO; 933 state->rxsubchans = V4L2_TUNER_SUB_MONO;
970 if (is_bilingual) { 934 if (is_bilingual) {
971 state->rxsubchans |= V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 935 state->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
972 /* I'm supposed to check whether it's SAP or not 936 /* I'm supposed to check whether it's SAP or not
973 * and set only LANG2/SAP in this case. Yet, the MSP 937 * and set only LANG2/SAP in this case. Yet, the MSP
974 * does a lot of work to hide this and handle everything 938 * does a lot of work to hide this and handle everything
@@ -980,12 +944,12 @@ void msp34xxg_detect_stereo(struct i2c_client *client)
980 status, is_stereo, is_bilingual, state->rxsubchans); 944 status, is_stereo, is_bilingual, state->rxsubchans);
981} 945}
982 946
983void msp34xxg_set_audmode(struct i2c_client *client, int audmode) 947static void msp34xxg_set_audmode(struct i2c_client *client)
984{ 948{
985 struct msp_state *state = i2c_get_clientdata(client); 949 struct msp_state *state = i2c_get_clientdata(client);
986 int source; 950 int source;
987 951
988 switch (audmode) { 952 switch (state->audmode) {
989 case V4L2_TUNER_MODE_MONO: 953 case V4L2_TUNER_MODE_MONO:
990 source = 0; /* mono only */ 954 source = 0; /* mono only */
991 break; 955 break;
@@ -1000,11 +964,40 @@ void msp34xxg_set_audmode(struct i2c_client *client, int audmode)
1000 source = 4; /* stereo or B */ 964 source = 4; /* stereo or B */
1001 break; 965 break;
1002 default: 966 default:
1003 audmode = 0;
1004 source = 1; 967 source = 1;
1005 break; 968 break;
1006 } 969 }
1007 state->audmode = audmode;
1008 msp34xxg_set_source(client, source); 970 msp34xxg_set_source(client, source);
1009} 971}
1010 972
973void msp_set_audmode(struct i2c_client *client)
974{
975 struct msp_state *state = i2c_get_clientdata(client);
976
977 switch (state->opmode) {
978 case OPMODE_MANUAL:
979 case OPMODE_AUTODETECT:
980 state->watch_stereo = 0;
981 msp3400c_set_audmode(client);
982 break;
983 case OPMODE_AUTOSELECT:
984 msp34xxg_set_audmode(client);
985 break;
986 }
987}
988
989void msp_detect_stereo(struct i2c_client *client)
990{
991 struct msp_state *state = i2c_get_clientdata(client);
992
993 switch (state->opmode) {
994 case OPMODE_MANUAL:
995 case OPMODE_AUTODETECT:
996 msp3400c_detect_stereo(client);
997 break;
998 case OPMODE_AUTOSELECT:
999 msp34xxg_detect_stereo(client);
1000 break;
1001 }
1002}
1003
diff --git a/drivers/media/video/msp3400.h b/drivers/media/video/msp3400.h
index a9ac57d0700b..6fb5c8c994e7 100644
--- a/drivers/media/video/msp3400.h
+++ b/drivers/media/video/msp3400.h
@@ -104,14 +104,12 @@ int msp_sleep(struct msp_state *state, int timeout);
104 104
105/* msp3400-kthreads.c */ 105/* msp3400-kthreads.c */
106const char *msp_standard_std_name(int std); 106const char *msp_standard_std_name(int std);
107void msp3400c_setcarrier(struct i2c_client *client, int cdo1, int cdo2); 107void msp_set_audmode(struct i2c_client *client);
108void msp3400c_setmode(struct i2c_client *client, int type); 108void msp_detect_stereo(struct i2c_client *client);
109void msp3400c_setstereo(struct i2c_client *client, int mode);
110int autodetect_stereo(struct i2c_client *client);
111int msp3400c_thread(void *data); 109int msp3400c_thread(void *data);
112int msp3410d_thread(void *data); 110int msp3410d_thread(void *data);
113int msp34xxg_thread(void *data); 111int msp34xxg_thread(void *data);
114void msp34xxg_detect_stereo(struct i2c_client *client); 112void msp3400c_set_mode(struct i2c_client *client, int mode);
115void msp34xxg_set_audmode(struct i2c_client *client, int audmode); 113void msp3400c_set_carrier(struct i2c_client *client, int cdo1, int cdo2);
116 114
117#endif /* MSP3400_H */ 115#endif /* MSP3400_H */
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index 41715cacf926..eb3b31867494 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -1,11 +1,11 @@
1/* 1/*
2 mxb - v4l2 driver for the Multimedia eXtension Board 2 mxb - v4l2 driver for the Multimedia eXtension Board
3 3
4 Copyright (C) 1998-2006 Michael Hunold <michael@mihu.de> 4 Copyright (C) 1998-2006 Michael Hunold <michael@mihu.de>
5 5
6 Visit http://www.mihu.de/linux/saa7146/mxb/ 6 Visit http://www.mihu.de/linux/saa7146/mxb/
7 for further details about this card. 7 for further details about this card.
8 8
9 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or 11 the Free Software Foundation; either version 2 of the License, or
@@ -35,12 +35,12 @@
35 35
36#define I2C_SAA7111 0x24 36#define I2C_SAA7111 0x24
37 37
38#define MXB_BOARD_CAN_DO_VBI(dev) (dev->revision != 0) 38#define MXB_BOARD_CAN_DO_VBI(dev) (dev->revision != 0)
39 39
40/* global variable */ 40/* global variable */
41static int mxb_num = 0; 41static int mxb_num = 0;
42 42
43/* initial frequence the tuner will be tuned to. 43/* initial frequence the tuner will be tuned to.
44 in verden (lower saxony, germany) 4148 is a 44 in verden (lower saxony, germany) 4148 is a
45 channel called "phoenix" */ 45 channel called "phoenix" */
46static int freq = 4148; 46static int freq = 4148;
@@ -55,7 +55,7 @@ MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
55enum { TUNER, AUX1, AUX3, AUX3_YC }; 55enum { TUNER, AUX1, AUX3, AUX3_YC };
56 56
57static struct v4l2_input mxb_inputs[MXB_INPUTS] = { 57static struct v4l2_input mxb_inputs[MXB_INPUTS] = {
58 { TUNER, "Tuner", V4L2_INPUT_TYPE_TUNER, 1, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 58 { TUNER, "Tuner", V4L2_INPUT_TYPE_TUNER, 1, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
59 { AUX1, "AUX1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 59 { AUX1, "AUX1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
60 { AUX3, "AUX3 Composite", V4L2_INPUT_TYPE_CAMERA, 4, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 60 { AUX3, "AUX3 Composite", V4L2_INPUT_TYPE_CAMERA, 4, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
61 { AUX3_YC, "AUX3 S-Video", V4L2_INPUT_TYPE_CAMERA, 4, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 61 { AUX3_YC, "AUX3 S-Video", V4L2_INPUT_TYPE_CAMERA, 4, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
@@ -66,7 +66,7 @@ static struct v4l2_input mxb_inputs[MXB_INPUTS] = {
66static struct { 66static struct {
67 int hps_source; 67 int hps_source;
68 int hps_sync; 68 int hps_sync;
69} input_port_selection[MXB_INPUTS] = { 69} input_port_selection[MXB_INPUTS] = {
70 { SAA7146_HPS_SOURCE_PORT_A, SAA7146_HPS_SYNC_PORT_A }, 70 { SAA7146_HPS_SOURCE_PORT_A, SAA7146_HPS_SYNC_PORT_A },
71 { SAA7146_HPS_SOURCE_PORT_A, SAA7146_HPS_SYNC_PORT_A }, 71 { SAA7146_HPS_SOURCE_PORT_A, SAA7146_HPS_SYNC_PORT_A },
72 { SAA7146_HPS_SOURCE_PORT_A, SAA7146_HPS_SYNC_PORT_A }, 72 { SAA7146_HPS_SOURCE_PORT_A, SAA7146_HPS_SYNC_PORT_A },
@@ -81,7 +81,7 @@ static int video_audio_connect[MXB_INPUTS] =
81/* these are the necessary input-output-pins for bringing one audio source 81/* these are the necessary input-output-pins for bringing one audio source
82(see above) to the CD-output */ 82(see above) to the CD-output */
83static struct tea6420_multiplex TEA6420_cd[MXB_AUDIOS+1][2] = 83static struct tea6420_multiplex TEA6420_cd[MXB_AUDIOS+1][2] =
84 { 84 {
85 {{1,1,0},{1,1,0}}, /* Tuner */ 85 {{1,1,0},{1,1,0}}, /* Tuner */
86 {{5,1,0},{6,1,0}}, /* AUX 1 */ 86 {{5,1,0},{6,1,0}}, /* AUX 1 */
87 {{4,1,0},{6,1,0}}, /* AUX 2 */ 87 {{4,1,0},{6,1,0}}, /* AUX 2 */
@@ -122,8 +122,8 @@ static struct saa7146_extension_ioctls ioctls[] = {
122 { VIDIOC_S_FREQUENCY, SAA7146_EXCLUSIVE }, 122 { VIDIOC_S_FREQUENCY, SAA7146_EXCLUSIVE },
123 { VIDIOC_G_AUDIO, SAA7146_EXCLUSIVE }, 123 { VIDIOC_G_AUDIO, SAA7146_EXCLUSIVE },
124 { VIDIOC_S_AUDIO, SAA7146_EXCLUSIVE }, 124 { VIDIOC_S_AUDIO, SAA7146_EXCLUSIVE },
125 { MXB_S_AUDIO_CD, SAA7146_EXCLUSIVE }, /* custom control */ 125 { MXB_S_AUDIO_CD, SAA7146_EXCLUSIVE }, /* custom control */
126 { MXB_S_AUDIO_LINE, SAA7146_EXCLUSIVE }, /* custom control */ 126 { MXB_S_AUDIO_LINE, SAA7146_EXCLUSIVE }, /* custom control */
127 { 0, 0 } 127 { 0, 0 }
128}; 128};
129 129
@@ -132,7 +132,7 @@ struct mxb
132 struct video_device *video_dev; 132 struct video_device *video_dev;
133 struct video_device *vbi_dev; 133 struct video_device *vbi_dev;
134 134
135 struct i2c_adapter i2c_adapter; 135 struct i2c_adapter i2c_adapter;
136 136
137 struct i2c_client* saa7111a; 137 struct i2c_client* saa7111a;
138 struct i2c_client* tda9840; 138 struct i2c_client* tda9840;
@@ -200,15 +200,15 @@ static int mxb_probe(struct saa7146_dev* dev)
200 client = list_entry(item, struct i2c_client, list); 200 client = list_entry(item, struct i2c_client, list);
201 if( I2C_TEA6420_1 == client->addr ) 201 if( I2C_TEA6420_1 == client->addr )
202 mxb->tea6420_1 = client; 202 mxb->tea6420_1 = client;
203 if( I2C_TEA6420_2 == client->addr ) 203 if( I2C_TEA6420_2 == client->addr )
204 mxb->tea6420_2 = client; 204 mxb->tea6420_2 = client;
205 if( I2C_TEA6415C_2 == client->addr ) 205 if( I2C_TEA6415C_2 == client->addr )
206 mxb->tea6415c = client; 206 mxb->tea6415c = client;
207 if( I2C_TDA9840 == client->addr ) 207 if( I2C_TDA9840 == client->addr )
208 mxb->tda9840 = client; 208 mxb->tda9840 = client;
209 if( I2C_SAA7111 == client->addr ) 209 if( I2C_SAA7111 == client->addr )
210 mxb->saa7111a = client; 210 mxb->saa7111a = client;
211 if( 0x60 == client->addr ) 211 if( 0x60 == client->addr )
212 mxb->tuner = client; 212 mxb->tuner = client;
213 } 213 }
214 214
@@ -222,7 +222,7 @@ static int mxb_probe(struct saa7146_dev* dev)
222 return -ENODEV; 222 return -ENODEV;
223 } 223 }
224 224
225 /* all devices are present, probe was successful */ 225 /* all devices are present, probe was successful */
226 226
227 /* we store the pointer in our private data field */ 227 /* we store the pointer in our private data field */
228 dev->ext_priv = mxb; 228 dev->ext_priv = mxb;
@@ -230,7 +230,7 @@ static int mxb_probe(struct saa7146_dev* dev)
230 return 0; 230 return 0;
231} 231}
232 232
233/* some init data for the saa7740, the so-called 'sound arena module'. 233/* some init data for the saa7740, the so-called 'sound arena module'.
234 there are no specs available, so we simply use some init values */ 234 there are no specs available, so we simply use some init values */
235static struct { 235static struct {
236 int length; 236 int length;
@@ -330,7 +330,7 @@ static int mxb_init_done(struct saa7146_dev* dev)
330 v4l2_std_id std = V4L2_STD_PAL_BG; 330 v4l2_std_id std = V4L2_STD_PAL_BG;
331 331
332 int i = 0, err = 0; 332 int i = 0, err = 0;
333 struct tea6415c_multiplex vm; 333 struct tea6415c_multiplex vm;
334 334
335 /* select video mode in saa7111a */ 335 /* select video mode in saa7111a */
336 i = VIDEO_MODE_PAL; 336 i = VIDEO_MODE_PAL;
@@ -380,16 +380,16 @@ static int mxb_init_done(struct saa7146_dev* dev)
380 vm.in = 3; 380 vm.in = 3;
381 vm.out = 13; 381 vm.out = 13;
382 mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm); 382 mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm);
383 383
384 /* the rest for mxb */ 384 /* the rest for mxb */
385 mxb->cur_input = 0; 385 mxb->cur_input = 0;
386 mxb->cur_mute = 1; 386 mxb->cur_mute = 1;
387 387
388 mxb->cur_mode = V4L2_TUNER_MODE_STEREO; 388 mxb->cur_mode = V4L2_TUNER_MODE_STEREO;
389 mxb->tda9840->driver->command(mxb->tda9840, TDA9840_SWITCH, &mxb->cur_mode); 389 mxb->tda9840->driver->command(mxb->tda9840, TDA9840_SWITCH, &mxb->cur_mode);
390 390
391 /* check if the saa7740 (aka 'sound arena module') is present 391 /* check if the saa7740 (aka 'sound arena module') is present
392 on the mxb. if so, we must initialize it. due to lack of 392 on the mxb. if so, we must initialize it. due to lack of
393 informations about the saa7740, the values were reverse 393 informations about the saa7740, the values were reverse
394 engineered. */ 394 engineered. */
395 msg.addr = 0x1b; 395 msg.addr = 0x1b;
@@ -409,7 +409,7 @@ static int mxb_init_done(struct saa7146_dev* dev)
409 break; 409 break;
410 } 410 }
411 411
412 msg.len = mxb_saa7740_init[i].length; 412 msg.len = mxb_saa7740_init[i].length;
413 msg.buf = &mxb_saa7740_init[i].data[0]; 413 msg.buf = &mxb_saa7740_init[i].data[0];
414 if( 1 != (err = i2c_transfer(&mxb->i2c_adapter, &msg, 1))) { 414 if( 1 != (err = i2c_transfer(&mxb->i2c_adapter, &msg, 1))) {
415 DEB_D(("failed to initialize 'sound arena module'.\n")); 415 DEB_D(("failed to initialize 'sound arena module'.\n"));
@@ -418,12 +418,12 @@ static int mxb_init_done(struct saa7146_dev* dev)
418 } 418 }
419 INFO(("'sound arena module' detected.\n")); 419 INFO(("'sound arena module' detected.\n"));
420 } 420 }
421err: 421err:
422 /* the rest for saa7146: you should definitely set some basic values 422 /* the rest for saa7146: you should definitely set some basic values
423 for the input-port handling of the saa7146. */ 423 for the input-port handling of the saa7146. */
424 424
425 /* ext->saa has been filled by the core driver */ 425 /* ext->saa has been filled by the core driver */
426 426
427 /* some stuff is done via variables */ 427 /* some stuff is done via variables */
428 saa7146_set_hps_source_and_sync(dev, input_port_selection[mxb->cur_input].hps_source, input_port_selection[mxb->cur_input].hps_sync); 428 saa7146_set_hps_source_and_sync(dev, input_port_selection[mxb->cur_input].hps_source, input_port_selection[mxb->cur_input].hps_sync);
429 429
@@ -431,7 +431,7 @@ err:
431 431
432 /* this is ugly, but because of the fact that this is completely 432 /* this is ugly, but because of the fact that this is completely
433 hardware dependend, it should be done directly... */ 433 hardware dependend, it should be done directly... */
434 saa7146_write(dev, DD1_STREAM_B, 0x00000000); 434 saa7146_write(dev, DD1_STREAM_B, 0x00000000);
435 saa7146_write(dev, DD1_INIT, 0x02000200); 435 saa7146_write(dev, DD1_INIT, 0x02000200);
436 saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26)); 436 saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
437 437
@@ -453,7 +453,7 @@ static struct saa7146_ext_vv vv_data;
453static int mxb_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data *info) 453static int mxb_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
454{ 454{
455 struct mxb* mxb = (struct mxb*)dev->ext_priv; 455 struct mxb* mxb = (struct mxb*)dev->ext_priv;
456 456
457 DEB_EE(("dev:%p\n",dev)); 457 DEB_EE(("dev:%p\n",dev));
458 458
459 /* checking for i2c-devices can be omitted here, because we 459 /* checking for i2c-devices can be omitted here, because we
@@ -464,7 +464,7 @@ static int mxb_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data
464 ERR(("cannot register capture v4l2 device. skipping.\n")); 464 ERR(("cannot register capture v4l2 device. skipping.\n"));
465 return -1; 465 return -1;
466 } 466 }
467 467
468 /* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/ 468 /* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/
469 if( 0 != MXB_BOARD_CAN_DO_VBI(dev)) { 469 if( 0 != MXB_BOARD_CAN_DO_VBI(dev)) {
470 if( 0 != saa7146_register_device(&mxb->vbi_dev, dev, "mxb", VFL_TYPE_VBI)) { 470 if( 0 != saa7146_register_device(&mxb->vbi_dev, dev, "mxb", VFL_TYPE_VBI)) {
@@ -513,17 +513,17 @@ static int mxb_detach(struct saa7146_dev* dev)
513 return 0; 513 return 0;
514} 514}
515 515
516static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg) 516static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
517{ 517{
518 struct saa7146_dev *dev = fh->dev; 518 struct saa7146_dev *dev = fh->dev;
519 struct mxb* mxb = (struct mxb*)dev->ext_priv; 519 struct mxb* mxb = (struct mxb*)dev->ext_priv;
520 struct saa7146_vv *vv = dev->vv_data; 520 struct saa7146_vv *vv = dev->vv_data;
521 521
522 switch(cmd) { 522 switch(cmd) {
523 case VIDIOC_ENUMINPUT: 523 case VIDIOC_ENUMINPUT:
524 { 524 {
525 struct v4l2_input *i = arg; 525 struct v4l2_input *i = arg;
526 526
527 DEB_EE(("VIDIOC_ENUMINPUT %d.\n",i->index)); 527 DEB_EE(("VIDIOC_ENUMINPUT %d.\n",i->index));
528 if( i->index < 0 || i->index >= MXB_INPUTS) { 528 if( i->index < 0 || i->index >= MXB_INPUTS) {
529 return -EINVAL; 529 return -EINVAL;
@@ -559,11 +559,11 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
559 break; 559 break;
560 } 560 }
561 } 561 }
562 562
563 if( i < 0 ) { 563 if( i < 0 ) {
564 return -EAGAIN; 564 return -EAGAIN;
565 } 565 }
566 566
567 switch (vc->id ) { 567 switch (vc->id ) {
568 case V4L2_CID_AUDIO_MUTE: { 568 case V4L2_CID_AUDIO_MUTE: {
569 vc->value = mxb->cur_mute; 569 vc->value = mxb->cur_mute;
@@ -571,7 +571,7 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
571 return 0; 571 return 0;
572 } 572 }
573 } 573 }
574 574
575 DEB_EE(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n",vc->value)); 575 DEB_EE(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n",vc->value));
576 return 0; 576 return 0;
577 } 577 }
@@ -580,17 +580,17 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
580 { 580 {
581 struct v4l2_control *vc = arg; 581 struct v4l2_control *vc = arg;
582 int i = 0; 582 int i = 0;
583 583
584 for (i = MAXCONTROLS - 1; i >= 0; i--) { 584 for (i = MAXCONTROLS - 1; i >= 0; i--) {
585 if (mxb_controls[i].id == vc->id) { 585 if (mxb_controls[i].id == vc->id) {
586 break; 586 break;
587 } 587 }
588 } 588 }
589 589
590 if( i < 0 ) { 590 if( i < 0 ) {
591 return -EAGAIN; 591 return -EAGAIN;
592 } 592 }
593 593
594 switch (vc->id ) { 594 switch (vc->id ) {
595 case V4L2_CID_AUDIO_MUTE: { 595 case V4L2_CID_AUDIO_MUTE: {
596 mxb->cur_mute = vc->value; 596 mxb->cur_mute = vc->value;
@@ -614,12 +614,12 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
614 *input = mxb->cur_input; 614 *input = mxb->cur_input;
615 615
616 DEB_EE(("VIDIOC_G_INPUT %d.\n",*input)); 616 DEB_EE(("VIDIOC_G_INPUT %d.\n",*input));
617 return 0; 617 return 0;
618 } 618 }
619 case VIDIOC_S_INPUT: 619 case VIDIOC_S_INPUT:
620 { 620 {
621 int input = *(int *)arg; 621 int input = *(int *)arg;
622 struct tea6415c_multiplex vm; 622 struct tea6415c_multiplex vm;
623 int i = 0; 623 int i = 0;
624 624
625 DEB_EE(("VIDIOC_S_INPUT %d.\n",input)); 625 DEB_EE(("VIDIOC_S_INPUT %d.\n",input));
@@ -627,34 +627,34 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
627 if (input < 0 || input >= MXB_INPUTS) { 627 if (input < 0 || input >= MXB_INPUTS) {
628 return -EINVAL; 628 return -EINVAL;
629 } 629 }
630 630
631 /* fixme: locke das setzen des inputs mit hilfe des mutexes 631 /* fixme: locke das setzen des inputs mit hilfe des mutexes
632 down(&dev->lock); 632 mutex_lock(&dev->lock);
633 video_mux(dev,*i); 633 video_mux(dev,*i);
634 up(&dev->lock); 634 mutex_unlock(&dev->lock);
635 */ 635 */
636 636
637 /* fixme: check if streaming capture 637 /* fixme: check if streaming capture
638 if ( 0 != dev->streaming ) { 638 if ( 0 != dev->streaming ) {
639 DEB_D(("VIDIOC_S_INPUT illegal while streaming.\n")); 639 DEB_D(("VIDIOC_S_INPUT illegal while streaming.\n"));
640 return -EPERM; 640 return -EPERM;
641 } 641 }
642 */ 642 */
643 643
644 mxb->cur_input = input; 644 mxb->cur_input = input;
645 645
646 saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source, input_port_selection[input].hps_sync); 646 saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source, input_port_selection[input].hps_sync);
647 647
648 /* prepare switching of tea6415c and saa7111a; 648 /* prepare switching of tea6415c and saa7111a;
649 have a look at the 'background'-file for further informations */ 649 have a look at the 'background'-file for further informations */
650 switch( input ) { 650 switch( input ) {
651 651
652 case TUNER: 652 case TUNER:
653 { 653 {
654 i = 0; 654 i = 0;
655 vm.in = 3; 655 vm.in = 3;
656 vm.out = 17; 656 vm.out = 17;
657 657
658 if ( 0 != mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm)) { 658 if ( 0 != mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm)) {
659 printk("VIDIOC_S_INPUT: could not address tea6415c #1\n"); 659 printk("VIDIOC_S_INPUT: could not address tea6415c #1\n");
660 return -EFAULT; 660 return -EFAULT;
@@ -662,7 +662,7 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
662 /* connect tuner-output always to multicable */ 662 /* connect tuner-output always to multicable */
663 vm.in = 3; 663 vm.in = 3;
664 vm.out = 13; 664 vm.out = 13;
665 break; 665 break;
666 } 666 }
667 case AUX3_YC: 667 case AUX3_YC:
668 { 668 {
@@ -703,11 +703,11 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
703 break; 703 break;
704 } 704 }
705 } 705 }
706 706
707 /* switch video in saa7111a */ 707 /* switch video in saa7111a */
708 if ( 0 != mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_INPUT, &i)) { 708 if ( 0 != mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_INPUT, &i)) {
709 printk("VIDIOC_S_INPUT: could not address saa7111a #1.\n"); 709 printk("VIDIOC_S_INPUT: could not address saa7111a #1.\n");
710 } 710 }
711 711
712 /* switch the audio-source only if necessary */ 712 /* switch the audio-source only if necessary */
713 if( 0 == mxb->cur_mute ) { 713 if( 0 == mxb->cur_mute ) {
@@ -738,11 +738,11 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
738 t->rangehigh = 13684; /* 855.25 MHz / 62.5 kHz = 13684 */ 738 t->rangehigh = 13684; /* 855.25 MHz / 62.5 kHz = 13684 */
739 /* FIXME: add the real signal strength here */ 739 /* FIXME: add the real signal strength here */
740 t->signal = 0xffff; 740 t->signal = 0xffff;
741 t->afc = 0; 741 t->afc = 0;
742 742
743 mxb->tda9840->driver->command(mxb->tda9840,TDA9840_DETECT, &byte); 743 mxb->tda9840->driver->command(mxb->tda9840,TDA9840_DETECT, &byte);
744 t->audmode = mxb->cur_mode; 744 t->audmode = mxb->cur_mode;
745 745
746 if( byte < 0 ) { 746 if( byte < 0 ) {
747 t->rxsubchans = V4L2_TUNER_SUB_MONO; 747 t->rxsubchans = V4L2_TUNER_SUB_MONO;
748 } else { 748 } else {
@@ -777,12 +777,12 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
777 struct v4l2_tuner *t = arg; 777 struct v4l2_tuner *t = arg;
778 int result = 0; 778 int result = 0;
779 int byte = 0; 779 int byte = 0;
780 780
781 if( 0 != t->index ) { 781 if( 0 != t->index ) {
782 DEB_D(("VIDIOC_S_TUNER: channel %d does not have a tuner attached.\n",t->index)); 782 DEB_D(("VIDIOC_S_TUNER: channel %d does not have a tuner attached.\n",t->index));
783 return -EINVAL; 783 return -EINVAL;
784 } 784 }
785 785
786 switch(t->audmode) { 786 switch(t->audmode) {
787 case V4L2_TUNER_MODE_STEREO: { 787 case V4L2_TUNER_MODE_STEREO: {
788 mxb->cur_mode = V4L2_TUNER_MODE_STEREO; 788 mxb->cur_mode = V4L2_TUNER_MODE_STEREO;
@@ -813,7 +813,7 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
813 if( 0 != (result = mxb->tda9840->driver->command(mxb->tda9840, TDA9840_SWITCH, &byte))) { 813 if( 0 != (result = mxb->tda9840->driver->command(mxb->tda9840, TDA9840_SWITCH, &byte))) {
814 printk("VIDIOC_S_TUNER error. result:%d, byte:%d\n",result,byte); 814 printk("VIDIOC_S_TUNER error. result:%d, byte:%d\n",result,byte);
815 } 815 }
816 816
817 return 0; 817 return 0;
818 } 818 }
819 case VIDIOC_G_FREQUENCY: 819 case VIDIOC_G_FREQUENCY:
@@ -839,7 +839,7 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
839 839
840 if (V4L2_TUNER_ANALOG_TV != f->type) 840 if (V4L2_TUNER_ANALOG_TV != f->type)
841 return -EINVAL; 841 return -EINVAL;
842 842
843 if(0 != mxb->cur_input) { 843 if(0 != mxb->cur_input) {
844 DEB_D(("VIDIOC_S_FREQ: channel %d does not have a tuner!\n",mxb->cur_input)); 844 DEB_D(("VIDIOC_S_FREQ: channel %d does not have a tuner!\n",mxb->cur_input));
845 return -EINVAL; 845 return -EINVAL;
@@ -848,7 +848,7 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
848 mxb->cur_freq = *f; 848 mxb->cur_freq = *f;
849 DEB_EE(("VIDIOC_S_FREQUENCY: freq:0x%08x.\n", mxb->cur_freq.frequency)); 849 DEB_EE(("VIDIOC_S_FREQUENCY: freq:0x%08x.\n", mxb->cur_freq.frequency));
850 850
851 /* tune in desired frequency */ 851 /* tune in desired frequency */
852 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_FREQUENCY, &mxb->cur_freq); 852 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_FREQUENCY, &mxb->cur_freq);
853 853
854 /* hack: changing the frequency should invalidate the vbi-counter (=> alevt) */ 854 /* hack: changing the frequency should invalidate the vbi-counter (=> alevt) */
@@ -861,12 +861,12 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
861 case MXB_S_AUDIO_CD: 861 case MXB_S_AUDIO_CD:
862 { 862 {
863 int i = *(int*)arg; 863 int i = *(int*)arg;
864 864
865 if( i < 0 || i >= MXB_AUDIOS ) { 865 if( i < 0 || i >= MXB_AUDIOS ) {
866 DEB_D(("illegal argument to MXB_S_AUDIO_CD: i:%d.\n",i)); 866 DEB_D(("illegal argument to MXB_S_AUDIO_CD: i:%d.\n",i));
867 return -EINVAL; 867 return -EINVAL;
868 } 868 }
869 869
870 DEB_EE(("MXB_S_AUDIO_CD: i:%d.\n",i)); 870 DEB_EE(("MXB_S_AUDIO_CD: i:%d.\n",i));
871 871
872 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_cd[i][0]); 872 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_cd[i][0]);
@@ -877,12 +877,12 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
877 case MXB_S_AUDIO_LINE: 877 case MXB_S_AUDIO_LINE:
878 { 878 {
879 int i = *(int*)arg; 879 int i = *(int*)arg;
880 880
881 if( i < 0 || i >= MXB_AUDIOS ) { 881 if( i < 0 || i >= MXB_AUDIOS ) {
882 DEB_D(("illegal argument to MXB_S_AUDIO_LINE: i:%d.\n",i)); 882 DEB_D(("illegal argument to MXB_S_AUDIO_LINE: i:%d.\n",i));
883 return -EINVAL; 883 return -EINVAL;
884 } 884 }
885 885
886 DEB_EE(("MXB_S_AUDIO_LINE: i:%d.\n",i)); 886 DEB_EE(("MXB_S_AUDIO_LINE: i:%d.\n",i));
887 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[i][0]); 887 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[i][0]);
888 mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[i][1]); 888 mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[i][1]);
@@ -894,13 +894,13 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
894 struct v4l2_audio *a = arg; 894 struct v4l2_audio *a = arg;
895 895
896 if( a->index < 0 || a->index > MXB_INPUTS ) { 896 if( a->index < 0 || a->index > MXB_INPUTS ) {
897 DEB_D(("VIDIOC_G_AUDIO %d out of range.\n",a->index)); 897 DEB_D(("VIDIOC_G_AUDIO %d out of range.\n",a->index));
898 return -EINVAL; 898 return -EINVAL;
899 } 899 }
900 900
901 DEB_EE(("VIDIOC_G_AUDIO %d.\n",a->index)); 901 DEB_EE(("VIDIOC_G_AUDIO %d.\n",a->index));
902 memcpy(a, &mxb_audios[video_audio_connect[mxb->cur_input]], sizeof(struct v4l2_audio)); 902 memcpy(a, &mxb_audios[video_audio_connect[mxb->cur_input]], sizeof(struct v4l2_audio));
903 903
904 return 0; 904 return 0;
905 } 905 }
906 case VIDIOC_S_AUDIO: 906 case VIDIOC_S_AUDIO:
@@ -908,7 +908,7 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
908 struct v4l2_audio *a = arg; 908 struct v4l2_audio *a = arg;
909 DEB_D(("VIDIOC_S_AUDIO %d.\n",a->index)); 909 DEB_D(("VIDIOC_S_AUDIO %d.\n",a->index));
910 return 0; 910 return 0;
911 } 911 }
912 default: 912 default:
913/* 913/*
914 DEB2(printk("does not handle this ioctl.\n")); 914 DEB2(printk("does not handle this ioctl.\n"));
@@ -928,7 +928,7 @@ static int std_callback(struct saa7146_dev* dev, struct saa7146_standard *std)
928 v4l2_std_id std = V4L2_STD_PAL_I; 928 v4l2_std_id std = V4L2_STD_PAL_I;
929 DEB_D(("VIDIOC_S_STD: setting mxb for PAL_I.\n")); 929 DEB_D(("VIDIOC_S_STD: setting mxb for PAL_I.\n"));
930 /* set the 7146 gpio register -- I don't know what this does exactly */ 930 /* set the 7146 gpio register -- I don't know what this does exactly */
931 saa7146_write(dev, GPIO_CTRL, 0x00404050); 931 saa7146_write(dev, GPIO_CTRL, 0x00404050);
932 /* unset the 7111 gpio register -- I don't know what this does exactly */ 932 /* unset the 7111 gpio register -- I don't know what this does exactly */
933 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_GPIO, &zero); 933 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_GPIO, &zero);
934 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std); 934 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);
@@ -936,7 +936,7 @@ static int std_callback(struct saa7146_dev* dev, struct saa7146_standard *std)
936 v4l2_std_id std = V4L2_STD_PAL_BG; 936 v4l2_std_id std = V4L2_STD_PAL_BG;
937 DEB_D(("VIDIOC_S_STD: setting mxb for PAL/NTSC/SECAM.\n")); 937 DEB_D(("VIDIOC_S_STD: setting mxb for PAL/NTSC/SECAM.\n"));
938 /* set the 7146 gpio register -- I don't know what this does exactly */ 938 /* set the 7146 gpio register -- I don't know what this does exactly */
939 saa7146_write(dev, GPIO_CTRL, 0x00404050); 939 saa7146_write(dev, GPIO_CTRL, 0x00404050);
940 /* set the 7111 gpio register -- I don't know what this does exactly */ 940 /* set the 7111 gpio register -- I don't know what this does exactly */
941 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_GPIO, &one); 941 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_GPIO, &one);
942 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std); 942 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);
@@ -969,8 +969,8 @@ static struct saa7146_standard standard[] = {
969}; 969};
970 970
971static struct saa7146_pci_extension_data mxb = { 971static struct saa7146_pci_extension_data mxb = {
972 .ext_priv = "Multimedia eXtension Board", 972 .ext_priv = "Multimedia eXtension Board",
973 .ext = &extension, 973 .ext = &extension,
974}; 974};
975 975
976static struct pci_device_id pci_tbl[] = { 976static struct pci_device_id pci_tbl[] = {
@@ -992,7 +992,7 @@ static struct saa7146_ext_vv vv_data = {
992 .capabilities = V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE, 992 .capabilities = V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE,
993 .stds = &standard[0], 993 .stds = &standard[0],
994 .num_stds = sizeof(standard)/sizeof(struct saa7146_standard), 994 .num_stds = sizeof(standard)/sizeof(struct saa7146_standard),
995 .std_callback = &std_callback, 995 .std_callback = &std_callback,
996 .ioctls = &ioctls[0], 996 .ioctls = &ioctls[0],
997 .ioctl = mxb_ioctl, 997 .ioctl = mxb_ioctl,
998}; 998};
@@ -1000,7 +1000,7 @@ static struct saa7146_ext_vv vv_data = {
1000static struct saa7146_extension extension = { 1000static struct saa7146_extension extension = {
1001 .name = MXB_IDENTIFIER, 1001 .name = MXB_IDENTIFIER,
1002 .flags = SAA7146_USE_I2C_IRQ, 1002 .flags = SAA7146_USE_I2C_IRQ,
1003 1003
1004 .pci_tbl = &pci_tbl[0], 1004 .pci_tbl = &pci_tbl[0],
1005 .module = THIS_MODULE, 1005 .module = THIS_MODULE,
1006 1006
@@ -1010,7 +1010,7 @@ static struct saa7146_extension extension = {
1010 1010
1011 .irq_mask = 0, 1011 .irq_mask = 0,
1012 .irq_func = NULL, 1012 .irq_func = NULL,
1013}; 1013};
1014 1014
1015static int __init mxb_init_module(void) 1015static int __init mxb_init_module(void)
1016{ 1016{
@@ -1018,7 +1018,7 @@ static int __init mxb_init_module(void)
1018 DEB_S(("failed to register extension.\n")); 1018 DEB_S(("failed to register extension.\n"));
1019 return -ENODEV; 1019 return -ENODEV;
1020 } 1020 }
1021 1021
1022 return 0; 1022 return 0;
1023} 1023}
1024 1024
diff --git a/drivers/media/video/mxb.h b/drivers/media/video/mxb.h
index 2332ed5f7c6b..400a57ba62ec 100644
--- a/drivers/media/video/mxb.h
+++ b/drivers/media/video/mxb.h
@@ -38,5 +38,5 @@ static struct v4l2_audio mxb_audios[MXB_AUDIOS] = {
38 .name = "CD-ROM (X10)", 38 .name = "CD-ROM (X10)",
39 .capability = V4L2_AUDCAP_STEREO, 39 .capability = V4L2_AUDCAP_STEREO,
40 } 40 }
41}; 41};
42#endif 42#endif
diff --git a/drivers/media/video/planb.c b/drivers/media/video/planb.c
index f3fc361bec97..15fd85acabda 100644
--- a/drivers/media/video/planb.c
+++ b/drivers/media/video/planb.c
@@ -48,7 +48,7 @@
48#include <asm/pgtable.h> 48#include <asm/pgtable.h>
49#include <asm/page.h> 49#include <asm/page.h>
50#include <asm/irq.h> 50#include <asm/irq.h>
51#include <asm/semaphore.h> 51#include <linux/mutex.h>
52 52
53#include "planb.h" 53#include "planb.h"
54#include "saa7196.h" 54#include "saa7196.h"
@@ -329,12 +329,12 @@ static volatile struct dbdma_cmd *cmd_geo_setup(
329 329
330static inline void planb_lock(struct planb *pb) 330static inline void planb_lock(struct planb *pb)
331{ 331{
332 down(&pb->lock); 332 mutex_lock(&pb->lock);
333} 333}
334 334
335static inline void planb_unlock(struct planb *pb) 335static inline void planb_unlock(struct planb *pb)
336{ 336{
337 up(&pb->lock); 337 mutex_unlock(&pb->lock);
338} 338}
339 339
340/***************/ 340/***************/
@@ -2067,7 +2067,7 @@ static int init_planb(struct planb *pb)
2067#endif 2067#endif
2068 pb->tab_size = PLANB_MAXLINES + 40; 2068 pb->tab_size = PLANB_MAXLINES + 40;
2069 pb->suspend = 0; 2069 pb->suspend = 0;
2070 init_MUTEX(&pb->lock); 2070 mutex_init(&pb->lock);
2071 pb->ch1_cmd = 0; 2071 pb->ch1_cmd = 0;
2072 pb->ch2_cmd = 0; 2072 pb->ch2_cmd = 0;
2073 pb->mask = 0; 2073 pb->mask = 0;
diff --git a/drivers/media/video/planb.h b/drivers/media/video/planb.h
index 8a0faad16118..79b6b561426e 100644
--- a/drivers/media/video/planb.h
+++ b/drivers/media/video/planb.h
@@ -174,7 +174,7 @@ struct planb {
174 int user; 174 int user;
175 unsigned int tab_size; 175 unsigned int tab_size;
176 int maxlines; 176 int maxlines;
177 struct semaphore lock; 177 struct mutex lock;
178 unsigned int irq; /* interrupt number */ 178 unsigned int irq; /* interrupt number */
179 volatile unsigned int intr_mask; 179 volatile unsigned int intr_mask;
180 180
diff --git a/drivers/media/video/pms.c b/drivers/media/video/pms.c
index 9e6448639480..05ca55939e77 100644
--- a/drivers/media/video/pms.c
+++ b/drivers/media/video/pms.c
@@ -30,6 +30,8 @@
30#include <asm/io.h> 30#include <asm/io.h>
31#include <linux/sched.h> 31#include <linux/sched.h>
32#include <linux/videodev.h> 32#include <linux/videodev.h>
33#include <linux/mutex.h>
34
33#include <asm/uaccess.h> 35#include <asm/uaccess.h>
34 36
35 37
@@ -44,7 +46,7 @@ struct pms_device
44 struct video_picture picture; 46 struct video_picture picture;
45 int height; 47 int height;
46 int width; 48 int width;
47 struct semaphore lock; 49 struct mutex lock;
48}; 50};
49 51
50struct i2c_info 52struct i2c_info
@@ -724,10 +726,10 @@ static int pms_do_ioctl(struct inode *inode, struct file *file,
724 struct video_channel *v = arg; 726 struct video_channel *v = arg;
725 if(v->channel<0 || v->channel>3) 727 if(v->channel<0 || v->channel>3)
726 return -EINVAL; 728 return -EINVAL;
727 down(&pd->lock); 729 mutex_lock(&pd->lock);
728 pms_videosource(v->channel&1); 730 pms_videosource(v->channel&1);
729 pms_vcrinput(v->channel>>1); 731 pms_vcrinput(v->channel>>1);
730 up(&pd->lock); 732 mutex_unlock(&pd->lock);
731 return 0; 733 return 0;
732 } 734 }
733 case VIDIOCGTUNER: 735 case VIDIOCGTUNER:
@@ -761,7 +763,7 @@ static int pms_do_ioctl(struct inode *inode, struct file *file,
761 struct video_tuner *v = arg; 763 struct video_tuner *v = arg;
762 if(v->tuner) 764 if(v->tuner)
763 return -EINVAL; 765 return -EINVAL;
764 down(&pd->lock); 766 mutex_lock(&pd->lock);
765 switch(v->mode) 767 switch(v->mode)
766 { 768 {
767 case VIDEO_MODE_AUTO: 769 case VIDEO_MODE_AUTO:
@@ -785,10 +787,10 @@ static int pms_do_ioctl(struct inode *inode, struct file *file,
785 pms_format(2); 787 pms_format(2);
786 break; 788 break;
787 default: 789 default:
788 up(&pd->lock); 790 mutex_unlock(&pd->lock);
789 return -EINVAL; 791 return -EINVAL;
790 } 792 }
791 up(&pd->lock); 793 mutex_unlock(&pd->lock);
792 return 0; 794 return 0;
793 } 795 }
794 case VIDIOCGPICT: 796 case VIDIOCGPICT:
@@ -809,12 +811,12 @@ static int pms_do_ioctl(struct inode *inode, struct file *file,
809 * Now load the card. 811 * Now load the card.
810 */ 812 */
811 813
812 down(&pd->lock); 814 mutex_lock(&pd->lock);
813 pms_brightness(p->brightness>>8); 815 pms_brightness(p->brightness>>8);
814 pms_hue(p->hue>>8); 816 pms_hue(p->hue>>8);
815 pms_colour(p->colour>>8); 817 pms_colour(p->colour>>8);
816 pms_contrast(p->contrast>>8); 818 pms_contrast(p->contrast>>8);
817 up(&pd->lock); 819 mutex_unlock(&pd->lock);
818 return 0; 820 return 0;
819 } 821 }
820 case VIDIOCSWIN: 822 case VIDIOCSWIN:
@@ -830,9 +832,9 @@ static int pms_do_ioctl(struct inode *inode, struct file *file,
830 return -EINVAL; 832 return -EINVAL;
831 pd->width=vw->width; 833 pd->width=vw->width;
832 pd->height=vw->height; 834 pd->height=vw->height;
833 down(&pd->lock); 835 mutex_lock(&pd->lock);
834 pms_resolution(pd->width, pd->height); 836 pms_resolution(pd->width, pd->height);
835 up(&pd->lock); /* Ok we figured out what to use from our wide choice */ 837 mutex_unlock(&pd->lock); /* Ok we figured out what to use from our wide choice */
836 return 0; 838 return 0;
837 } 839 }
838 case VIDIOCGWIN: 840 case VIDIOCGWIN:
@@ -872,9 +874,9 @@ static ssize_t pms_read(struct file *file, char __user *buf,
872 struct pms_device *pd=(struct pms_device *)v; 874 struct pms_device *pd=(struct pms_device *)v;
873 int len; 875 int len;
874 876
875 down(&pd->lock); 877 mutex_lock(&pd->lock);
876 len=pms_capture(pd, buf, (pd->picture.depth==16)?0:1,count); 878 len=pms_capture(pd, buf, (pd->picture.depth==16)?0:1,count);
877 up(&pd->lock); 879 mutex_unlock(&pd->lock);
878 return len; 880 return len;
879} 881}
880 882
@@ -1029,7 +1031,7 @@ static int __init init_pms_cards(void)
1029 return -ENODEV; 1031 return -ENODEV;
1030 } 1032 }
1031 memcpy(&pms_device, &pms_template, sizeof(pms_template)); 1033 memcpy(&pms_device, &pms_template, sizeof(pms_template));
1032 init_MUTEX(&pms_device.lock); 1034 mutex_init(&pms_device.lock);
1033 pms_device.height=240; 1035 pms_device.height=240;
1034 pms_device.width=320; 1036 pms_device.width=320;
1035 pms_swsense(75); 1037 pms_swsense(75);
diff --git a/drivers/media/video/saa5246a.c b/drivers/media/video/saa5246a.c
index 2ce010201308..dd830e0e5e96 100644
--- a/drivers/media/video/saa5246a.c
+++ b/drivers/media/video/saa5246a.c
@@ -46,6 +46,8 @@
46#include <linux/i2c.h> 46#include <linux/i2c.h>
47#include <linux/videotext.h> 47#include <linux/videotext.h>
48#include <linux/videodev.h> 48#include <linux/videodev.h>
49#include <linux/mutex.h>
50
49#include "saa5246a.h" 51#include "saa5246a.h"
50 52
51MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>"); 53MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>");
@@ -57,7 +59,7 @@ struct saa5246a_device
57 u8 pgbuf[NUM_DAUS][VTX_VIRTUALSIZE]; 59 u8 pgbuf[NUM_DAUS][VTX_VIRTUALSIZE];
58 int is_searching[NUM_DAUS]; 60 int is_searching[NUM_DAUS];
59 struct i2c_client *client; 61 struct i2c_client *client;
60 struct semaphore lock; 62 struct mutex lock;
61}; 63};
62 64
63static struct video_device saa_template; /* Declared near bottom */ 65static struct video_device saa_template; /* Declared near bottom */
@@ -90,7 +92,7 @@ static int saa5246a_attach(struct i2c_adapter *adap, int addr, int kind)
90 return -ENOMEM; 92 return -ENOMEM;
91 } 93 }
92 strlcpy(client->name, IF_NAME, I2C_NAME_SIZE); 94 strlcpy(client->name, IF_NAME, I2C_NAME_SIZE);
93 init_MUTEX(&t->lock); 95 mutex_init(&t->lock);
94 96
95 /* 97 /*
96 * Now create a video4linux device 98 * Now create a video4linux device
@@ -719,9 +721,9 @@ static int saa5246a_ioctl(struct inode *inode, struct file *file,
719 int err; 721 int err;
720 722
721 cmd = vtx_fix_command(cmd); 723 cmd = vtx_fix_command(cmd);
722 down(&t->lock); 724 mutex_lock(&t->lock);
723 err = video_usercopy(inode, file, cmd, arg, do_saa5246a_ioctl); 725 err = video_usercopy(inode, file, cmd, arg, do_saa5246a_ioctl);
724 up(&t->lock); 726 mutex_unlock(&t->lock);
725 return err; 727 return err;
726} 728}
727 729
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index 5694eb58c3a1..a9f3cf0b1e3c 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -56,6 +56,8 @@
56#include <linux/i2c.h> 56#include <linux/i2c.h>
57#include <linux/videotext.h> 57#include <linux/videotext.h>
58#include <linux/videodev.h> 58#include <linux/videodev.h>
59#include <linux/mutex.h>
60
59 61
60#include <asm/io.h> 62#include <asm/io.h>
61#include <asm/uaccess.h> 63#include <asm/uaccess.h>
@@ -105,7 +107,7 @@ struct saa5249_device
105 int disp_mode; 107 int disp_mode;
106 int virtual_mode; 108 int virtual_mode;
107 struct i2c_client *client; 109 struct i2c_client *client;
108 struct semaphore lock; 110 struct mutex lock;
109}; 111};
110 112
111 113
@@ -158,7 +160,7 @@ static int saa5249_attach(struct i2c_adapter *adap, int addr, int kind)
158 return -ENOMEM; 160 return -ENOMEM;
159 } 161 }
160 strlcpy(client->name, IF_NAME, I2C_NAME_SIZE); 162 strlcpy(client->name, IF_NAME, I2C_NAME_SIZE);
161 init_MUTEX(&t->lock); 163 mutex_init(&t->lock);
162 164
163 /* 165 /*
164 * Now create a video4linux device 166 * Now create a video4linux device
@@ -619,9 +621,9 @@ static int saa5249_ioctl(struct inode *inode, struct file *file,
619 int err; 621 int err;
620 622
621 cmd = vtx_fix_command(cmd); 623 cmd = vtx_fix_command(cmd);
622 down(&t->lock); 624 mutex_lock(&t->lock);
623 err = video_usercopy(inode,file,cmd,arg,do_saa5249_ioctl); 625 err = video_usercopy(inode,file,cmd,arg,do_saa5249_ioctl);
624 up(&t->lock); 626 mutex_unlock(&t->lock);
625 return err; 627 return err;
626} 628}
627 629
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index ffd87ce55556..b184fd00b4e7 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -1,4 +1,4 @@
1/* saa7115 - Philips SAA7114/SAA7115 video decoder driver 1/* saa7115 - Philips SAA7113/SAA7114/SAA7115 video decoder driver
2 * 2 *
3 * Based on saa7114 driver by Maxim Yevtyushkin, which is based on 3 * Based on saa7114 driver by Maxim Yevtyushkin, which is based on
4 * the saa7111 driver by Dave Perks. 4 * the saa7111 driver by Dave Perks.
@@ -16,6 +16,7 @@
16 * (2/17/2003) 16 * (2/17/2003)
17 * 17 *
18 * VBI support (2004) and cleanups (2005) by Hans Verkuil <hverkuil@xs4all.nl> 18 * VBI support (2004) and cleanups (2005) by Hans Verkuil <hverkuil@xs4all.nl>
19 * SAA7113 support by Mauro Carvalho Chehab <mchehab@infradead.org>
19 * 20 *
20 * This program is free software; you can redistribute it and/or 21 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License 22 * modify it under the terms of the GNU General Public License
@@ -42,8 +43,9 @@
42#include <media/audiochip.h> 43#include <media/audiochip.h>
43#include <asm/div64.h> 44#include <asm/div64.h>
44 45
45MODULE_DESCRIPTION("Philips SAA7114/SAA7115 video decoder driver"); 46MODULE_DESCRIPTION("Philips SAA7113/SAA7114/SAA7115 video decoder driver");
46MODULE_AUTHOR("Maxim Yevtyushkin, Kevin Thayer, Chris Kennedy, Hans Verkuil"); 47MODULE_AUTHOR( "Maxim Yevtyushkin, Kevin Thayer, Chris Kennedy, "
48 "Hans Verkuil, Mauro Carvalho Chehab");
47MODULE_LICENSE("GPL"); 49MODULE_LICENSE("GPL");
48 50
49static int debug = 0; 51static int debug = 0;
@@ -51,7 +53,10 @@ module_param(debug, bool, 0644);
51 53
52MODULE_PARM_DESC(debug, "Debug level (0-1)"); 54MODULE_PARM_DESC(debug, "Debug level (0-1)");
53 55
54static unsigned short normal_i2c[] = { 0x42 >> 1, 0x40 >> 1, I2C_CLIENT_END }; 56static unsigned short normal_i2c[] = {
57 0x4a >>1, 0x48 >>1, /* SAA7113 */
58 0x42 >> 1, 0x40 >> 1, /* SAA7114 and SAA7115 */
59 I2C_CLIENT_END };
55 60
56 61
57I2C_CLIENT_INSMOD; 62I2C_CLIENT_INSMOD;
@@ -101,10 +106,12 @@ static inline int saa7115_read(struct i2c_client *client, u8 reg)
101 Hauppauge driver sets. */ 106 Hauppauge driver sets. */
102 107
103static const unsigned char saa7115_init_auto_input[] = { 108static const unsigned char saa7115_init_auto_input[] = {
109 /* Front-End Part */
104 0x01, 0x48, /* white peak control disabled */ 110 0x01, 0x48, /* white peak control disabled */
105 0x03, 0x20, /* was 0x30. 0x20: long vertical blanking */ 111 0x03, 0x20, /* was 0x30. 0x20: long vertical blanking */
106 0x04, 0x90, /* analog gain set to 0 */ 112 0x04, 0x90, /* analog gain set to 0 */
107 0x05, 0x90, /* analog gain set to 0 */ 113 0x05, 0x90, /* analog gain set to 0 */
114 /* Decoder Part */
108 0x06, 0xeb, /* horiz sync begin = -21 */ 115 0x06, 0xeb, /* horiz sync begin = -21 */
109 0x07, 0xe0, /* horiz sync stop = -17 */ 116 0x07, 0xe0, /* horiz sync stop = -17 */
110 0x0a, 0x80, /* was 0x88. decoder brightness, 0x80 is itu standard */ 117 0x0a, 0x80, /* was 0x88. decoder brightness, 0x80 is itu standard */
@@ -123,6 +130,8 @@ static const unsigned char saa7115_init_auto_input[] = {
123 0x1b, 0x42, /* misc chroma control 0x42 = recommended */ 130 0x1b, 0x42, /* misc chroma control 0x42 = recommended */
124 0x1c, 0xa9, /* combfilter control 0xA9 = recommended */ 131 0x1c, 0xa9, /* combfilter control 0xA9 = recommended */
125 0x1d, 0x01, /* combfilter control 0x01 = recommended */ 132 0x1d, 0x01, /* combfilter control 0x01 = recommended */
133
134 /* Power Device Control */
126 0x88, 0xd0, /* reset device */ 135 0x88, 0xd0, /* reset device */
127 0x88, 0xf0, /* set device programmed, all in operational mode */ 136 0x88, 0xf0, /* set device programmed, all in operational mode */
128 0x00, 0x00 137 0x00, 0x00
@@ -338,6 +347,33 @@ static const unsigned char saa7115_cfg_vbi_off[] = {
338 0x00, 0x00 347 0x00, 0x00
339}; 348};
340 349
350static const unsigned char saa7113_init_auto_input[] = {
351 0x01, 0x08, /* PH7113_INCREMENT_DELAY - (1) (1) (1) (1) IDEL3 IDEL2 IDELL1 IDEL0 */
352 0x02, 0xc2, /* PH7113_ANALOG_INPUT_CONTR_1 - FUSE1 FUSE0 GUDL1 GUDL0 MODE3 MODE2 MODE1 MODE0 */
353 0x03, 0x30, /* PH7113_ANALOG_INPUT_CONTR_2 - (1) HLNRS VBSL WPOFF HOLDG GAFIX GAI28 GAI18 */
354 0x04, 0x00, /* PH7113_ANALOG_INPUT_CONTR_3 - GAI17 GAI16 GAI15 GAI14 GAI13 GAI12 GAI11 GAI10 */
355 0x05, 0x00, /* PH7113_ANALOG_INPUT_CONTR_4 - GAI27 GAI26 GAI25 GAI24 GAI23 GAI22 GAI21 GAI20 */
356 0x06, 0x89, /* PH7113_HORIZONTAL_SYNC_START - HSB7 HSB6 HSB5 HSB4 HSB3 HSB2 HSB1 HSB0 */
357 0x07, 0x0d, /* PH7113_HORIZONTAL_SYNC_STOP - HSS7 HSS6 HSS5 HSS4 HSS3 HSS2 HSS1 HSS0 */
358 0x08, 0x88, /* PH7113_SYNC_CONTROL - AUFD FSEL FOET HTC1 HTC0 HPLL VNOI1 VNOI0 */
359 0x09, 0x01, /* PH7113_LUMINANCE_CONTROL - BYPS PREF BPSS1 BPSS0 VBLB UPTCV APER1 APER0 */
360 0x0a, 0x80, /* PH7113_LUMINANCE_BRIGHTNESS - BRIG7 BRIG6 BRIG5 BRIG4 BRIG3 BRIG2 BRIG1 BRIG0 */
361 0x0b, 0x47, /* PH7113_LUMINANCE_CONTRAST - CONT7 CONT6 CONT5 CONT4 CONT3 CONT2 CONT1 CONT0 */
362 0x0c, 0x40, /* PH7113_CHROMA_SATURATION - SATN7 SATN6 SATN5 SATN4 SATN3 SATN2 SATN1 SATN0 */
363 0x0d, 0x00, /* PH7113_CHROMA_HUE_CONTROL - HUEC7 HUEC6 HUEC5 HUEC4 HUEC3 HUEC2 HUEC1 HUEC0 */
364 0x0e, 0x01, /* PH7113_CHROMA_CONTROL - CDTO CSTD2 CSTD1 CSTD0 DCCF FCTC CHBW1 CHBW0 */
365 0x0f, 0x2a, /* PH7113_CHROMA_GAIN_CONTROL - ACGC CGAIN6 CGAIN5 CGAIN4 CGAIN3 CGAIN2 CGAIN1 CGAIN0 */
366 0x10, 0x08, /* PH7113_FORMAT_DELAY_CONTROL - OFTS1 OFTS0 HDEL1 HDEL0 VRLN YDEL2 YDEL1 YDEL0 */
367 0x11, 0x0c, /* PH7113_OUTPUT_CONTROL_1 - GPSW1 CM99 GPSW0 HLSEL OEYC OERT VIPB COLO */
368 0x12, 0x07, /* PH7113_OUTPUT_CONTROL_2 - RTSE13 RTSE12 RTSE11 RTSE10 RTSE03 RTSE02 RTSE01 RTSE00 */
369 0x13, 0x00, /* PH7113_OUTPUT_CONTROL_3 - ADLSB (1) (1) OLDSB FIDP (1) AOSL1 AOSL0 */
370 0x14, 0x00, /* RESERVED 14 - (1) (1) (1) (1) (1) (1) (1) (1) */
371 0x15, 0x00, /* PH7113_V_GATE1_START - VSTA7 VSTA6 VSTA5 VSTA4 VSTA3 VSTA2 VSTA1 VSTA0 */
372 0x16, 0x00, /* PH7113_V_GATE1_STOP - VSTO7 VSTO6 VSTO5 VSTO4 VSTO3 VSTO2 VSTO1 VSTO0 */
373 0x17, 0x00, /* PH7113_V_GATE1_MSB - (1) (1) (1) (1) (1) (1) VSTO8 VSTA8 */
374 0x00, 0x00
375};
376
341static const unsigned char saa7115_init_misc[] = { 377static const unsigned char saa7115_init_misc[] = {
342 0x38, 0x03, /* audio stuff */ 378 0x38, 0x03, /* audio stuff */
343 0x39, 0x10, 379 0x39, 0x10,
@@ -677,10 +713,35 @@ static void saa7115_set_v4lstd(struct i2c_client *client, v4l2_std_id std)
677 saa7115_writeregs(client, saa7115_cfg_50hz_video); 713 saa7115_writeregs(client, saa7115_cfg_50hz_video);
678 } 714 }
679 715
716 /* Register 0E - Bits D6-D4 on NO-AUTO mode
717 (SAA7113 doesn't have auto mode)
718 50 Hz / 625 lines 60 Hz / 525 lines
719 000 PAL BGDHI (4.43Mhz) NTSC M (3.58MHz)
720 001 NTSC 4.43 (50 Hz) PAL 4.43 (60 Hz)
721 010 Combination-PAL N (3.58MHz) NTSC 4.43 (60 Hz)
722 011 NTSC N (3.58MHz) PAL M (3.58MHz)
723 100 reserved NTSC-Japan (3.58MHz)
724 */
725 if (state->ident == V4L2_IDENT_SAA7113) {
726 u8 reg = saa7115_read(client, 0x0e) & 0x8f;
727
728 if (std == V4L2_STD_PAL_M) {
729 reg|=0x30;
730 } else if (std == V4L2_STD_PAL_N) {
731 reg|=0x20;
732 } else if (std == V4L2_STD_PAL_60) {
733 reg|=0x10;
734 } else if (std == V4L2_STD_NTSC_M_JP) {
735 reg|=0x40;
736 }
737 saa7115_write(client, 0x0e, reg);
738 }
739
740
680 state->std = std; 741 state->std = std;
681 742
682 /* restart task B if needed */ 743 /* restart task B if needed */
683 if (taskb && state->ident == V4L2_IDENT_SAA7114) { 744 if (taskb && state->ident != V4L2_IDENT_SAA7115) {
684 saa7115_writeregs(client, saa7115_cfg_vbi_on); 745 saa7115_writeregs(client, saa7115_cfg_vbi_on);
685 } 746 }
686 747
@@ -703,7 +764,7 @@ static void saa7115_log_status(struct i2c_client *client)
703 int vcr; 764 int vcr;
704 765
705 v4l_info(client, "Audio frequency: %d Hz\n", state->audclk_freq); 766 v4l_info(client, "Audio frequency: %d Hz\n", state->audclk_freq);
706 if (client->name[6] == '4') { 767 if (state->ident != V4L2_IDENT_SAA7115) {
707 /* status for the saa7114 */ 768 /* status for the saa7114 */
708 reg1f = saa7115_read(client, 0x1f); 769 reg1f = saa7115_read(client, 0x1f);
709 signalOk = (reg1f & 0xc1) == 0x81; 770 signalOk = (reg1f & 0xc1) == 0x81;
@@ -751,8 +812,8 @@ static void saa7115_set_lcr(struct i2c_client *client, struct v4l2_sliced_vbi_fo
751 u8 lcr[24]; 812 u8 lcr[24];
752 int i, x; 813 int i, x;
753 814
754 /* saa7114 doesn't yet support VBI */ 815 /* saa7113/71144 doesn't yet support VBI */
755 if (state->ident == V4L2_IDENT_SAA7114) 816 if (state->ident != V4L2_IDENT_SAA7115)
756 return; 817 return;
757 818
758 for (i = 0; i <= 23; i++) 819 for (i = 0; i <= 23; i++)
@@ -791,7 +852,7 @@ static void saa7115_set_lcr(struct i2c_client *client, struct v4l2_sliced_vbi_fo
791 case 0: 852 case 0:
792 lcr[i] |= 0xf << (4 * x); 853 lcr[i] |= 0xf << (4 * x);
793 break; 854 break;
794 case V4L2_SLICED_TELETEXT_B: 855 case V4L2_SLICED_TELETEXT_PAL_B:
795 lcr[i] |= 1 << (4 * x); 856 lcr[i] |= 1 << (4 * x);
796 break; 857 break;
797 case V4L2_SLICED_CAPTION_525: 858 case V4L2_SLICED_CAPTION_525:
@@ -820,7 +881,7 @@ static void saa7115_set_lcr(struct i2c_client *client, struct v4l2_sliced_vbi_fo
820static int saa7115_get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt) 881static int saa7115_get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
821{ 882{
822 static u16 lcr2vbi[] = { 883 static u16 lcr2vbi[] = {
823 0, V4L2_SLICED_TELETEXT_B, 0, /* 1 */ 884 0, V4L2_SLICED_TELETEXT_PAL_B, 0, /* 1 */
824 0, V4L2_SLICED_CAPTION_525, /* 4 */ 885 0, V4L2_SLICED_CAPTION_525, /* 4 */
825 V4L2_SLICED_WSS_625, 0, /* 5 */ 886 V4L2_SLICED_WSS_625, 0, /* 5 */
826 V4L2_SLICED_VPS, 0, 0, 0, 0, /* 7 */ 887 V4L2_SLICED_VPS, 0, 0, 0, 0, /* 7 */
@@ -985,7 +1046,7 @@ static void saa7115_decode_vbi_line(struct i2c_client *client,
985 /* decode payloads */ 1046 /* decode payloads */
986 switch (id2) { 1047 switch (id2) {
987 case 1: 1048 case 1:
988 vbi->type = V4L2_SLICED_TELETEXT_B; 1049 vbi->type = V4L2_SLICED_TELETEXT_PAL_B;
989 break; 1050 break;
990 case 4: 1051 case 4:
991 if (!saa7115_odd_parity(p[0]) || !saa7115_odd_parity(p[1])) 1052 if (!saa7115_odd_parity(p[0]) || !saa7115_odd_parity(p[1]))
@@ -1261,14 +1322,12 @@ static int saa7115_attach(struct i2c_adapter *adapter, int address, int kind)
1261 1322
1262 saa7115_write(client, 0, 5); 1323 saa7115_write(client, 0, 5);
1263 chip_id = saa7115_read(client, 0) & 0x0f; 1324 chip_id = saa7115_read(client, 0) & 0x0f;
1264 if (chip_id != 4 && chip_id != 5) { 1325 if (chip_id <3 && chip_id > 5) {
1265 v4l_dbg(1, debug, client, "saa7115 not found\n"); 1326 v4l_dbg(1, debug, client, "saa7115 not found\n");
1266 kfree(client); 1327 kfree(client);
1267 return 0; 1328 return 0;
1268 } 1329 }
1269 if (chip_id == 4) { 1330 snprintf(client->name, sizeof(client->name) - 1, "saa711%d",chip_id);
1270 snprintf(client->name, sizeof(client->name) - 1, "saa7114");
1271 }
1272 v4l_info(client, "saa711%d found @ 0x%x (%s)\n", chip_id, address << 1, adapter->name); 1331 v4l_info(client, "saa711%d found @ 0x%x (%s)\n", chip_id, address << 1, adapter->name);
1273 1332
1274 state = kzalloc(sizeof(struct saa7115_state), GFP_KERNEL); 1333 state = kzalloc(sizeof(struct saa7115_state), GFP_KERNEL);
@@ -1285,13 +1344,27 @@ static int saa7115_attach(struct i2c_adapter *adapter, int address, int kind)
1285 state->contrast = 64; 1344 state->contrast = 64;
1286 state->hue = 0; 1345 state->hue = 0;
1287 state->sat = 64; 1346 state->sat = 64;
1288 state->ident = (chip_id == 4) ? V4L2_IDENT_SAA7114 : V4L2_IDENT_SAA7115; 1347 switch (chip_id) {
1348 case 3:
1349 state->ident = V4L2_IDENT_SAA7113;
1350 break;
1351 case 4:
1352 state->ident = V4L2_IDENT_SAA7114;
1353 break;
1354 default:
1355 state->ident = V4L2_IDENT_SAA7115;
1356 break;
1357 }
1358
1289 state->audclk_freq = 48000; 1359 state->audclk_freq = 48000;
1290 1360
1291 v4l_dbg(1, debug, client, "writing init values\n"); 1361 v4l_dbg(1, debug, client, "writing init values\n");
1292 1362
1293 /* init to 60hz/48khz */ 1363 /* init to 60hz/48khz */
1294 saa7115_writeregs(client, saa7115_init_auto_input); 1364 if (state->ident==V4L2_IDENT_SAA7113)
1365 saa7115_writeregs(client, saa7113_init_auto_input);
1366 else
1367 saa7115_writeregs(client, saa7115_init_auto_input);
1295 saa7115_writeregs(client, saa7115_init_misc); 1368 saa7115_writeregs(client, saa7115_init_misc);
1296 saa7115_writeregs(client, saa7115_cfg_60hz_fullres_x); 1369 saa7115_writeregs(client, saa7115_cfg_60hz_fullres_x);
1297 saa7115_writeregs(client, saa7115_cfg_60hz_fullres_y); 1370 saa7115_writeregs(client, saa7115_cfg_60hz_fullres_y);
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index e02e6ee31b78..aca84d2f9825 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -308,8 +308,7 @@ static int dsp_buffer_init(struct saa7134_dev *dev)
308 308
309static int dsp_buffer_free(struct saa7134_dev *dev) 309static int dsp_buffer_free(struct saa7134_dev *dev)
310{ 310{
311 if (!dev->dmasound.blksize) 311 BUG_ON(!dev->dmasound.blksize);
312 BUG();
313 312
314 videobuf_dma_free(&dev->dmasound.dma); 313 videobuf_dma_free(&dev->dmasound.dma);
315 314
@@ -612,12 +611,12 @@ static int snd_card_saa7134_capture_open(struct snd_pcm_substream * substream)
612 struct saa7134_dev *dev = saa7134->dev; 611 struct saa7134_dev *dev = saa7134->dev;
613 int err; 612 int err;
614 613
615 down(&dev->dmasound.lock); 614 mutex_lock(&dev->dmasound.lock);
616 615
617 dev->dmasound.read_count = 0; 616 dev->dmasound.read_count = 0;
618 dev->dmasound.read_offset = 0; 617 dev->dmasound.read_offset = 0;
619 618
620 up(&dev->dmasound.lock); 619 mutex_unlock(&dev->dmasound.lock);
621 620
622 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); 621 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
623 if (pcm == NULL) 622 if (pcm == NULL)
@@ -941,7 +940,7 @@ static int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
941 940
942 chip->irq = dev->pci->irq; 941 chip->irq = dev->pci->irq;
943 942
944 init_MUTEX(&dev->dmasound.lock); 943 mutex_init(&dev->dmasound.lock);
945 944
946 if ((err = snd_card_saa7134_new_mixer(chip)) < 0) 945 if ((err = snd_card_saa7134_new_mixer(chip)) < 0)
947 goto __nodev; 946 goto __nodev;
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 6bc63a4086c1..fdd7f48f3b76 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -536,7 +536,7 @@ struct saa7134_board saa7134_boards[] = {
536 .radio = { 536 .radio = {
537 .name = name_radio, 537 .name = name_radio,
538 .amux = LINE2, 538 .amux = LINE2,
539 }, 539 },
540 }, 540 },
541 [SAA7134_BOARD_MD7134] = { 541 [SAA7134_BOARD_MD7134] = {
542 .name = "Medion 7134", 542 .name = "Medion 7134",
@@ -640,6 +640,32 @@ struct saa7134_board saa7134_boards[] = {
640 .tv = 1, 640 .tv = 1,
641 }}, 641 }},
642 }, 642 },
643 [SAA7134_BOARD_ELSA_700TV] = {
644 .name = "ELSA EX-VISION 700TV",
645 .audio_clock = 0x00187de7,
646 .tuner_type = TUNER_HITACHI_NTSC,
647 .radio_type = UNSET,
648 .tuner_addr = ADDR_UNSET,
649 .radio_addr = ADDR_UNSET,
650 .inputs = {{
651 .name = name_tv,
652 .vmux = 4,
653 .amux = LINE2,
654 .tv = 1,
655 },{
656 .name = name_comp1,
657 .vmux = 6,
658 .amux = LINE1,
659 },{
660 .name = name_svideo,
661 .vmux = 7,
662 .amux = LINE1,
663 }},
664 .mute = {
665 .name = name_mute,
666 .amux = TV,
667 },
668 },
643 [SAA7134_BOARD_ASUSTeK_TVFM7134] = { 669 [SAA7134_BOARD_ASUSTeK_TVFM7134] = {
644 .name = "ASUS TV-FM 7134", 670 .name = "ASUS TV-FM 7134",
645 .audio_clock = 0x00187de7, 671 .audio_clock = 0x00187de7,
@@ -2002,7 +2028,7 @@ struct saa7134_board saa7134_boards[] = {
2002 [SAA7134_BOARD_FLYTV_DIGIMATRIX] = { 2028 [SAA7134_BOARD_FLYTV_DIGIMATRIX] = {
2003 .name = "FlyTV mini Asus Digimatrix", 2029 .name = "FlyTV mini Asus Digimatrix",
2004 .audio_clock = 0x00200000, 2030 .audio_clock = 0x00200000,
2005 .tuner_type = TUNER_LG_NTSC_TALN_MINI, 2031 .tuner_type = TUNER_LG_TALN,
2006 .radio_type = UNSET, 2032 .radio_type = UNSET,
2007 .tuner_addr = ADDR_UNSET, 2033 .tuner_addr = ADDR_UNSET,
2008 .radio_addr = ADDR_UNSET, 2034 .radio_addr = ADDR_UNSET,
@@ -2598,6 +2624,7 @@ struct saa7134_board saa7134_boards[] = {
2598 .tuner_addr = ADDR_UNSET, 2624 .tuner_addr = ADDR_UNSET,
2599 .radio_addr = ADDR_UNSET, 2625 .radio_addr = ADDR_UNSET,
2600 .gpiomask = 0x00200000, 2626 .gpiomask = 0x00200000,
2627 .mpeg = SAA7134_MPEG_DVB,
2601 .inputs = {{ 2628 .inputs = {{
2602 .name = name_tv, /* Analog broadcast/cable TV */ 2629 .name = name_tv, /* Analog broadcast/cable TV */
2603 .vmux = 1, 2630 .vmux = 1,
@@ -2623,6 +2650,164 @@ struct saa7134_board saa7134_boards[] = {
2623 .gpio = 0x000000, /* GPIO21=Low for FM radio antenna */ 2650 .gpio = 0x000000, /* GPIO21=Low for FM radio antenna */
2624 }, 2651 },
2625 }, 2652 },
2653 [SAA7134_BOARD_AVERMEDIA_777] = {
2654 .name = "AverTV DVB-T 777",
2655 .audio_clock = 0x00187de7,
2656 .tuner_type = TUNER_ABSENT,
2657 .radio_type = UNSET,
2658 .tuner_addr = ADDR_UNSET,
2659 .radio_addr = ADDR_UNSET,
2660 .mpeg = SAA7134_MPEG_DVB,
2661 .inputs = {{
2662 .name = name_comp1,
2663 .vmux = 0,
2664 .amux = LINE1,
2665 },{
2666 .name = name_svideo,
2667 .vmux = 8,
2668 .amux = LINE1,
2669 }},
2670 },
2671 [SAA7134_BOARD_FLYDVBT_LR301] = {
2672 /* LifeView FlyDVB-T */
2673 /* Giampiero Giancipoli <gianci@libero.it> */
2674 .name = "LifeView FlyDVB-T",
2675 .audio_clock = 0x00200000,
2676 .tuner_type = TUNER_ABSENT,
2677 .radio_type = UNSET,
2678 .tuner_addr = ADDR_UNSET,
2679 .radio_addr = ADDR_UNSET,
2680 .mpeg = SAA7134_MPEG_DVB,
2681 .inputs = {{
2682 .name = name_comp1, /* Composite input */
2683 .vmux = 3,
2684 .amux = LINE2,
2685 },{
2686 .name = name_svideo, /* S-Video signal on S-Video input */
2687 .vmux = 8,
2688 .amux = LINE2,
2689 }},
2690 },
2691 [SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331] = {
2692 .name = "ADS Instant TV Duo Cardbus PTV331",
2693 .audio_clock = 0x00200000,
2694 .tuner_type = TUNER_PHILIPS_TDA8290,
2695 .radio_type = UNSET,
2696 .tuner_addr = ADDR_UNSET,
2697 .radio_addr = ADDR_UNSET,
2698 .mpeg = SAA7134_MPEG_DVB,
2699 .gpiomask = 0x00600000, /* Bit 21 0=Radio, Bit 22 0=TV */
2700 .inputs = {{
2701 .name = name_tv,
2702 .vmux = 1,
2703 .amux = TV,
2704 .tv = 1,
2705 .gpio = 0x00200000,
2706 }},
2707 },
2708 [SAA7134_BOARD_TEVION_DVBT_220RF] = {
2709 .name = "Tevion/KWorld DVB-T 220RF",
2710 .audio_clock = 0x00187de7,
2711 .tuner_type = TUNER_PHILIPS_TDA8290,
2712 .radio_type = UNSET,
2713 .tuner_addr = ADDR_UNSET,
2714 .radio_addr = ADDR_UNSET,
2715 .mpeg = SAA7134_MPEG_DVB,
2716 .inputs = {{
2717 .name = name_tv,
2718 .vmux = 1,
2719 .amux = TV,
2720 .tv = 1,
2721 },{
2722 .name = name_comp1,
2723 .vmux = 3,
2724 .amux = LINE1,
2725 },{
2726 .name = name_svideo,
2727 .vmux = 0,
2728 .amux = LINE1,
2729 }},
2730 .radio = {
2731 .name = name_radio,
2732 .amux = LINE1,
2733 },
2734 },
2735 [SAA7134_BOARD_KWORLD_ATSC110] = {
2736 .name = "Kworld ATSC110",
2737 .audio_clock = 0x00187de7,
2738 .tuner_type = TUNER_PHILIPS_TUV1236D,
2739 .radio_type = UNSET,
2740 .tuner_addr = ADDR_UNSET,
2741 .radio_addr = ADDR_UNSET,
2742 .tda9887_conf = TDA9887_PRESENT,
2743 .mpeg = SAA7134_MPEG_DVB,
2744 .inputs = {{
2745 .name = name_tv,
2746 .vmux = 1,
2747 .amux = TV,
2748 .tv = 1,
2749 },{
2750 .name = name_comp1,
2751 .vmux = 3,
2752 .amux = LINE2,
2753 },{
2754 .name = name_svideo,
2755 .vmux = 8,
2756 .amux = LINE2,
2757 }},
2758 },
2759 [SAA7134_BOARD_AVERMEDIA_A169_B] = {
2760 /* AVerMedia A169 */
2761 /* Rickard Osser <ricky@osser.se> */
2762 /* This card has two saa7134 chips on it,
2763 but only one of them is currently working. */
2764 .name = "AVerMedia A169 B",
2765 .audio_clock = 0x02187de7,
2766 .tuner_type = TUNER_LG_TALN,
2767 .radio_type = UNSET,
2768 .tuner_addr = ADDR_UNSET,
2769 .radio_addr = ADDR_UNSET,
2770 .tda9887_conf = TDA9887_PRESENT,
2771 .gpiomask = 0x0a60000,
2772 },
2773 [SAA7134_BOARD_AVERMEDIA_A169_B1] = {
2774 /* AVerMedia A169 */
2775 /* Rickard Osser <ricky@osser.se> */
2776 .name = "AVerMedia A169 B1",
2777 .audio_clock = 0x02187de7,
2778 .tuner_type = TUNER_LG_TALN,
2779 .radio_type = UNSET,
2780 .tuner_addr = ADDR_UNSET,
2781 .radio_addr = ADDR_UNSET,
2782 .tda9887_conf = TDA9887_PRESENT,
2783 .gpiomask = 0xca60000,
2784 .inputs = {{
2785 .name = name_tv,
2786 .vmux = 4,
2787 .amux = TV,
2788 .tv = 1,
2789 .gpio = 0x04a61000,
2790 },{
2791 .name = name_comp2, /* Composite SVIDEO (B/W if signal is carried with SVIDEO) */
2792 .vmux = 1,
2793 .amux = LINE2,
2794 },{
2795 .name = name_svideo,
2796 .vmux = 9, /* 9 is correct as S-VIDEO1 according to a169.inf! */
2797 .amux = LINE1,
2798 }},
2799 },
2800 [SAA7134_BOARD_MD7134_BRIDGE_2] = {
2801 /* This card has two saa7134 chips on it,
2802 but only one of them is currently working.
2803 The programming for the primary decoder is
2804 in SAA7134_BOARD_MD7134 */
2805 .name = "Medion 7134 Bridge #2",
2806 .audio_clock = 0x00187de7,
2807 .radio_type = UNSET,
2808 .tuner_addr = ADDR_UNSET,
2809 .radio_addr = ADDR_UNSET,
2810 },
2626}; 2811};
2627 2812
2628const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 2813const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -2753,6 +2938,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
2753 .driver_data = SAA7134_BOARD_ELSA_500TV, 2938 .driver_data = SAA7134_BOARD_ELSA_500TV,
2754 },{ 2939 },{
2755 .vendor = PCI_VENDOR_ID_PHILIPS, 2940 .vendor = PCI_VENDOR_ID_PHILIPS,
2941 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
2942 .subvendor = 0x1048,
2943 .subdevice = 0x226c,
2944 .driver_data = SAA7134_BOARD_ELSA_700TV,
2945 },{
2946 .vendor = PCI_VENDOR_ID_PHILIPS,
2756 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2947 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
2757 .subvendor = PCI_VENDOR_ID_ASUSTEK, 2948 .subvendor = PCI_VENDOR_ID_ASUSTEK,
2758 .subdevice = 0x4842, 2949 .subdevice = 0x4842,
@@ -3094,6 +3285,54 @@ struct pci_device_id saa7134_pci_tbl[] = {
3094 .subdevice = 0x0319, 3285 .subdevice = 0x0319,
3095 .driver_data = SAA7134_BOARD_FLYDVB_TRIO, 3286 .driver_data = SAA7134_BOARD_FLYDVB_TRIO,
3096 },{ 3287 },{
3288 .vendor = PCI_VENDOR_ID_PHILIPS,
3289 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, /* SAA 7131E */
3290 .subvendor = 0x1461,
3291 .subdevice = 0x2c05,
3292 .driver_data = SAA7134_BOARD_AVERMEDIA_777,
3293 },{
3294 .vendor = PCI_VENDOR_ID_PHILIPS,
3295 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
3296 .subvendor = 0x5168,
3297 .subdevice = 0x0301,
3298 .driver_data = SAA7134_BOARD_FLYDVBT_LR301,
3299 },{
3300 .vendor = PCI_VENDOR_ID_PHILIPS,
3301 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3302 .subvendor = 0x0331,
3303 .subdevice = 0x1421,
3304 .driver_data = SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331,
3305 },{
3306 .vendor = PCI_VENDOR_ID_PHILIPS,
3307 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3308 .subvendor = 0x17de,
3309 .subdevice = 0x7201,
3310 .driver_data = SAA7134_BOARD_TEVION_DVBT_220RF,
3311 },{
3312 .vendor = PCI_VENDOR_ID_PHILIPS,
3313 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, /* SAA7135HL */
3314 .subvendor = 0x17de,
3315 .subdevice = 0x7350,
3316 .driver_data = SAA7134_BOARD_KWORLD_ATSC110,
3317 },{
3318 .vendor = PCI_VENDOR_ID_PHILIPS,
3319 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
3320 .subvendor = 0x1461,
3321 .subdevice = 0x7360,
3322 .driver_data = SAA7134_BOARD_AVERMEDIA_A169_B,
3323 },{
3324 .vendor = PCI_VENDOR_ID_PHILIPS,
3325 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
3326 .subvendor = 0x1461,
3327 .subdevice = 0x6360,
3328 .driver_data = SAA7134_BOARD_AVERMEDIA_A169_B1,
3329 },{
3330 .vendor = PCI_VENDOR_ID_PHILIPS,
3331 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
3332 .subvendor = 0x16be,
3333 .subdevice = 0x0005,
3334 .driver_data = SAA7134_BOARD_MD7134_BRIDGE_2,
3335 },{
3097 /* --- boards without eeprom + subsystem ID --- */ 3336 /* --- boards without eeprom + subsystem ID --- */
3098 .vendor = PCI_VENDOR_ID_PHILIPS, 3337 .vendor = PCI_VENDOR_ID_PHILIPS,
3099 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 3338 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -3193,13 +3432,15 @@ int saa7134_board_init1(struct saa7134_dev *dev)
3193 case SAA7134_BOARD_GOTVIEW_7135: 3432 case SAA7134_BOARD_GOTVIEW_7135:
3194 case SAA7134_BOARD_KWORLD_TERMINATOR: 3433 case SAA7134_BOARD_KWORLD_TERMINATOR:
3195 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS: 3434 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
3435 case SAA7134_BOARD_FLYDVBT_LR301:
3436 case SAA7134_BOARD_FLYDVBTDUO:
3196 dev->has_remote = SAA7134_REMOTE_GPIO; 3437 dev->has_remote = SAA7134_REMOTE_GPIO;
3197 break; 3438 break;
3198 case SAA7134_BOARD_MD5044: 3439 case SAA7134_BOARD_MD5044:
3199 printk("%s: seems there are two different versions of the MD5044\n" 3440 printk("%s: seems there are two different versions of the MD5044\n"
3200 "%s: (with the same ID) out there. If sound doesn't work for\n" 3441 "%s: (with the same ID) out there. If sound doesn't work for\n"
3201 "%s: you try the audio_clock_override=0x200000 insmod option.\n", 3442 "%s: you try the audio_clock_override=0x200000 insmod option.\n",
3202 dev->name,dev->name,dev->name); 3443 dev->name,dev->name,dev->name);
3203 break; 3444 break;
3204 case SAA7134_BOARD_CINERGY400_CARDBUS: 3445 case SAA7134_BOARD_CINERGY400_CARDBUS:
3205 /* power-up tuner chip */ 3446 /* power-up tuner chip */
@@ -3220,6 +3461,10 @@ int saa7134_board_init1(struct saa7134_dev *dev)
3220 saa_writeb(SAA7134_GPIO_GPMODE3, 0x08); 3461 saa_writeb(SAA7134_GPIO_GPMODE3, 0x08);
3221 saa_writeb(SAA7134_GPIO_GPSTATUS3, 0x06); 3462 saa_writeb(SAA7134_GPIO_GPSTATUS3, 0x06);
3222 break; 3463 break;
3464 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
3465 saa_writeb(SAA7134_GPIO_GPMODE3, 0x08);
3466 saa_writeb(SAA7134_GPIO_GPSTATUS3, 0x00);
3467 break;
3223 case SAA7134_BOARD_AVERMEDIA_CARDBUS: 3468 case SAA7134_BOARD_AVERMEDIA_CARDBUS:
3224 /* power-up tuner chip */ 3469 /* power-up tuner chip */
3225 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0xffffffff, 0xffffffff); 3470 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0xffffffff, 0xffffffff);
@@ -3242,6 +3487,13 @@ int saa7134_board_init1(struct saa7134_dev *dev)
3242 case SAA7134_BOARD_UPMOST_PURPLE_TV: 3487 case SAA7134_BOARD_UPMOST_PURPLE_TV:
3243 dev->has_remote = SAA7134_REMOTE_I2C; 3488 dev->has_remote = SAA7134_REMOTE_I2C;
3244 break; 3489 break;
3490 case SAA7134_BOARD_AVERMEDIA_A169_B:
3491 case SAA7134_BOARD_MD7134_BRIDGE_2:
3492 printk("%s: %s: dual saa713x broadcast decoders\n"
3493 "%s: Sorry, none of the inputs to this chip are supported yet.\n"
3494 "%s: Dual decoder functionality is disabled for now, use the other chip.\n",
3495 dev->name,card(dev).name,dev->name,dev->name);
3496 break;
3245 } 3497 }
3246 return 0; 3498 return 0;
3247} 3499}
@@ -3362,14 +3614,44 @@ int saa7134_board_init2(struct saa7134_dev *dev)
3362 } 3614 }
3363 break; 3615 break;
3364 case SAA7134_BOARD_PHILIPS_TIGER: 3616 case SAA7134_BOARD_PHILIPS_TIGER:
3617 case SAA7134_BOARD_TEVION_DVBT_220RF:
3365 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 3618 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
3366 /* this is a hybrid board, initialize to analog mode */ 3619 /* this is a hybrid board, initialize to analog mode
3620 * and configure firmware eeprom address
3621 */
3367 { 3622 {
3368 u8 data[] = { 0x3c, 0x33, 0x68}; 3623 u8 data[] = { 0x3c, 0x33, 0x68};
3369 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)}; 3624 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
3370 i2c_transfer(&dev->i2c_adap, &msg, 1); 3625 i2c_transfer(&dev->i2c_adap, &msg, 1);
3371 } 3626 }
3372 break; 3627 break;
3628 case SAA7134_BOARD_FLYDVB_TRIO:
3629 {
3630 u8 data[] = { 0x3c, 0x33, 0x62};
3631 struct i2c_msg msg = {.addr=0x09, .flags=0, .buf=data, .len = sizeof(data)};
3632 i2c_transfer(&dev->i2c_adap, &msg, 1);
3633 }
3634 break;
3635 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
3636 /* make the tda10046 find its eeprom */
3637 {
3638 u8 data[] = { 0x3c, 0x33, 0x62};
3639 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
3640 i2c_transfer(&dev->i2c_adap, &msg, 1);
3641 }
3642 break;
3643 case SAA7134_BOARD_KWORLD_ATSC110:
3644 {
3645 /* enable tuner */
3646 int i;
3647 static const u8 buffer [] = { 0x10,0x12,0x13,0x04,0x16,0x00,0x14,0x04,0x017,0x00 };
3648 dev->i2c_client.addr = 0x0a;
3649 for (i = 0; i < 5; i++)
3650 if (2 != i2c_master_send(&dev->i2c_client,&buffer[i*2],2))
3651 printk(KERN_WARNING "%s: Unable to enable tuner(%i).\n",
3652 dev->name, i);
3653 }
3654 break;
3373 } 3655 }
3374 return 0; 3656 return 0;
3375} 3657}
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 028904bd94a2..58e568d7d2ee 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -66,6 +66,11 @@ static unsigned int latency = UNSET;
66module_param(latency, int, 0444); 66module_param(latency, int, 0444);
67MODULE_PARM_DESC(latency,"pci latency timer"); 67MODULE_PARM_DESC(latency,"pci latency timer");
68 68
69int saa7134_no_overlay=-1;
70module_param_named(no_overlay, saa7134_no_overlay, int, 0444);
71MODULE_PARM_DESC(no_overlay,"allow override overlay default (0 disables, 1 enables)"
72 " [some VIA/SIS chipsets are known to have problem with overlay]");
73
69static unsigned int video_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; 74static unsigned int video_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
70static unsigned int vbi_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; 75static unsigned int vbi_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
71static unsigned int radio_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; 76static unsigned int radio_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
@@ -251,8 +256,7 @@ void saa7134_pgtable_free(struct pci_dev *pci, struct saa7134_pgtable *pt)
251 256
252void saa7134_dma_free(struct saa7134_dev *dev,struct saa7134_buf *buf) 257void saa7134_dma_free(struct saa7134_dev *dev,struct saa7134_buf *buf)
253{ 258{
254 if (in_interrupt()) 259 BUG_ON(in_interrupt());
255 BUG();
256 260
257 videobuf_waiton(&buf->vb,0,0); 261 videobuf_waiton(&buf->vb,0,0);
258 videobuf_dma_pci_unmap(dev->pci, &buf->vb.dma); 262 videobuf_dma_pci_unmap(dev->pci, &buf->vb.dma);
@@ -613,7 +617,7 @@ static int saa7134_hwinit1(struct saa7134_dev *dev)
613 617
614 saa_writel(SAA7134_IRQ1, 0); 618 saa_writel(SAA7134_IRQ1, 0);
615 saa_writel(SAA7134_IRQ2, 0); 619 saa_writel(SAA7134_IRQ2, 0);
616 init_MUTEX(&dev->lock); 620 mutex_init(&dev->lock);
617 spin_lock_init(&dev->slock); 621 spin_lock_init(&dev->slock);
618 622
619 saa7134_track_gpio(dev,"pre-init"); 623 saa7134_track_gpio(dev,"pre-init");
@@ -835,6 +839,22 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
835 latency = 0x0A; 839 latency = 0x0A;
836 } 840 }
837#endif 841#endif
842 if (pci_pci_problems & PCIPCI_FAIL) {
843 printk(KERN_INFO "%s: quirk: this driver and your "
844 "chipset may not work together"
845 " in overlay mode.\n",dev->name);
846 if (!saa7134_no_overlay) {
847 printk(KERN_INFO "%s: quirk: overlay "
848 "mode will be disabled.\n",
849 dev->name);
850 saa7134_no_overlay = 1;
851 } else {
852 printk(KERN_INFO "%s: quirk: overlay "
853 "mode will be forced. Use this"
854 " option at your own risk.\n",
855 dev->name);
856 }
857 }
838 } 858 }
839 if (UNSET != latency) { 859 if (UNSET != latency) {
840 printk(KERN_INFO "%s: setting pci latency timer to %d\n", 860 printk(KERN_INFO "%s: setting pci latency timer to %d\n",
@@ -937,6 +957,11 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
937 v4l2_prio_init(&dev->prio); 957 v4l2_prio_init(&dev->prio);
938 958
939 /* register v4l devices */ 959 /* register v4l devices */
960 if (saa7134_no_overlay <= 0) {
961 saa7134_video_template.type |= VID_TYPE_OVERLAY;
962 } else {
963 printk("bttv: Overlay support disabled.\n");
964 }
940 dev->video_dev = vdev_init(dev,&saa7134_video_template,"video"); 965 dev->video_dev = vdev_init(dev,&saa7134_video_template,"video");
941 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER, 966 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER,
942 video_nr[dev->nr]); 967 video_nr[dev->nr]);
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index 9db8e13f21c3..86cfdb8514cb 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -32,6 +32,7 @@
32#include "saa7134-reg.h" 32#include "saa7134-reg.h"
33#include "saa7134.h" 33#include "saa7134.h"
34#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
35#include "dvb-pll.h"
35 36
36#ifdef HAVE_MT352 37#ifdef HAVE_MT352
37# include "mt352.h" 38# include "mt352.h"
@@ -42,7 +43,6 @@
42#endif 43#endif
43#ifdef HAVE_NXT200X 44#ifdef HAVE_NXT200X
44# include "nxt200x.h" 45# include "nxt200x.h"
45# include "dvb-pll.h"
46#endif 46#endif
47 47
48MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 48MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
@@ -114,6 +114,24 @@ static int mt352_pinnacle_init(struct dvb_frontend* fe)
114 return 0; 114 return 0;
115} 115}
116 116
117static int mt352_aver777_init(struct dvb_frontend* fe)
118{
119 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
120 static u8 reset [] = { RESET, 0x80 };
121 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
122 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
123 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
124
125 mt352_write(fe, clock_config, sizeof(clock_config));
126 udelay(200);
127 mt352_write(fe, reset, sizeof(reset));
128 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
129 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
130 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
131
132 return 0;
133}
134
117static int mt352_pinnacle_pll_set(struct dvb_frontend* fe, 135static int mt352_pinnacle_pll_set(struct dvb_frontend* fe,
118 struct dvb_frontend_parameters* params, 136 struct dvb_frontend_parameters* params,
119 u8* pllbuf) 137 u8* pllbuf)
@@ -146,6 +164,15 @@ static int mt352_pinnacle_pll_set(struct dvb_frontend* fe,
146 return 0; 164 return 0;
147} 165}
148 166
167static int mt352_aver777_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8* pllbuf)
168{
169 pllbuf[0] = 0xc2;
170 dvb_pll_configure(&dvb_pll_philips_td1316, pllbuf+1,
171 params->frequency,
172 params->u.ofdm.bandwidth);
173 return 0;
174}
175
149static struct mt352_config pinnacle_300i = { 176static struct mt352_config pinnacle_300i = {
150 .demod_address = 0x3c >> 1, 177 .demod_address = 0x3c >> 1,
151 .adc_clock = 20333, 178 .adc_clock = 20333,
@@ -154,6 +181,12 @@ static struct mt352_config pinnacle_300i = {
154 .demod_init = mt352_pinnacle_init, 181 .demod_init = mt352_pinnacle_init,
155 .pll_set = mt352_pinnacle_pll_set, 182 .pll_set = mt352_pinnacle_pll_set,
156}; 183};
184
185static struct mt352_config avermedia_777 = {
186 .demod_address = 0xf,
187 .demod_init = mt352_aver777_init,
188 .pll_set = mt352_aver777_pll_set,
189};
157#endif 190#endif
158 191
159/* ------------------------------------------------------------------ */ 192/* ------------------------------------------------------------------ */
@@ -781,7 +814,7 @@ static int philips_tiger_pll_set(struct dvb_frontend *fe, struct dvb_frontend_pa
781 tda8290_msg.buf = tda8290_open; 814 tda8290_msg.buf = tda8290_open;
782 i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1); 815 i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
783 return ret; 816 return ret;
784}; 817}
785 818
786static int philips_tiger_dvb_mode(struct dvb_frontend *fe) 819static int philips_tiger_dvb_mode(struct dvb_frontend *fe)
787{ 820{
@@ -817,6 +850,110 @@ static struct tda1004x_config philips_tiger_config = {
817 .request_firmware = NULL, 850 .request_firmware = NULL,
818}; 851};
819 852
853/* ------------------------------------------------------------------ */
854
855static int lifeview_trio_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
856{
857 int ret;
858
859 ret = philips_tda827xa_pll_set(0x60, fe, params);
860 return ret;
861}
862
863static int lifeview_trio_dvb_mode(struct dvb_frontend *fe)
864{
865 return 0;
866}
867
868static void lifeview_trio_analog_mode(struct dvb_frontend *fe)
869{
870 philips_tda827xa_pll_sleep(0x60, fe);
871}
872
873static struct tda1004x_config lifeview_trio_config = {
874 .demod_address = 0x09,
875 .invert = 1,
876 .invert_oclk = 0,
877 .xtal_freq = TDA10046_XTAL_16M,
878 .agc_config = TDA10046_AGC_TDA827X_GPL,
879 .if_freq = TDA10046_FREQ_045,
880 .pll_init = lifeview_trio_dvb_mode,
881 .pll_set = lifeview_trio_pll_set,
882 .pll_sleep = lifeview_trio_analog_mode,
883 .request_firmware = NULL,
884};
885
886/* ------------------------------------------------------------------ */
887
888static int ads_duo_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
889{
890 int ret;
891
892 ret = philips_tda827xa_pll_set(0x61, fe, params);
893 return ret;
894}
895
896static int ads_duo_dvb_mode(struct dvb_frontend *fe)
897{
898 struct saa7134_dev *dev = fe->dvb->priv;
899 /* route TDA8275a AGC input to the channel decoder */
900 saa_writeb(SAA7134_GPIO_GPSTATUS2, 0x60);
901 return 0;
902}
903
904static void ads_duo_analog_mode(struct dvb_frontend *fe)
905{
906 struct saa7134_dev *dev = fe->dvb->priv;
907 /* route TDA8275a AGC input to the analog IF chip*/
908 saa_writeb(SAA7134_GPIO_GPSTATUS2, 0x20);
909 philips_tda827xa_pll_sleep( 0x61, fe);
910}
911
912static struct tda1004x_config ads_tech_duo_config = {
913 .demod_address = 0x08,
914 .invert = 1,
915 .invert_oclk = 0,
916 .xtal_freq = TDA10046_XTAL_16M,
917 .agc_config = TDA10046_AGC_TDA827X_GPL,
918 .if_freq = TDA10046_FREQ_045,
919 .pll_init = ads_duo_dvb_mode,
920 .pll_set = ads_duo_pll_set,
921 .pll_sleep = ads_duo_analog_mode,
922 .request_firmware = NULL,
923};
924
925/* ------------------------------------------------------------------ */
926
927static int tevion_dvb220rf_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
928{
929 int ret;
930 ret = philips_tda827xa_pll_set(0x60, fe, params);
931 return ret;
932}
933
934static int tevion_dvb220rf_pll_init(struct dvb_frontend *fe)
935{
936 return 0;
937}
938
939static void tevion_dvb220rf_pll_sleep(struct dvb_frontend *fe)
940{
941 philips_tda827xa_pll_sleep( 0x61, fe);
942}
943
944static struct tda1004x_config tevion_dvbt220rf_config = {
945 .demod_address = 0x08,
946 .invert = 1,
947 .invert_oclk = 0,
948 .xtal_freq = TDA10046_XTAL_16M,
949 .agc_config = TDA10046_AGC_TDA827X,
950 .if_freq = TDA10046_FREQ_045,
951 .pll_init = tevion_dvb220rf_pll_init,
952 .pll_set = tevion_dvb220rf_pll_set,
953 .pll_sleep = tevion_dvb220rf_pll_sleep,
954 .request_firmware = NULL,
955};
956
820#endif 957#endif
821 958
822/* ------------------------------------------------------------------ */ 959/* ------------------------------------------------------------------ */
@@ -827,6 +964,22 @@ static struct nxt200x_config avertvhda180 = {
827 .pll_address = 0x61, 964 .pll_address = 0x61,
828 .pll_desc = &dvb_pll_tdhu2, 965 .pll_desc = &dvb_pll_tdhu2,
829}; 966};
967
968static int nxt200x_set_pll_input(u8 *buf, int input)
969{
970 if (input)
971 buf[3] |= 0x08;
972 else
973 buf[3] &= ~0x08;
974 return 0;
975}
976
977static struct nxt200x_config kworldatsc110 = {
978 .demod_address = 0x0a,
979 .pll_address = 0x61,
980 .pll_desc = &dvb_pll_tuv1236d,
981 .set_pll_input = nxt200x_set_pll_input,
982};
830#endif 983#endif
831 984
832/* ------------------------------------------------------------------ */ 985/* ------------------------------------------------------------------ */
@@ -851,6 +1004,12 @@ static int dvb_init(struct saa7134_dev *dev)
851 dev->dvb.frontend = mt352_attach(&pinnacle_300i, 1004 dev->dvb.frontend = mt352_attach(&pinnacle_300i,
852 &dev->i2c_adap); 1005 &dev->i2c_adap);
853 break; 1006 break;
1007
1008 case SAA7134_BOARD_AVERMEDIA_777:
1009 printk("%s: avertv 777 dvb setup\n",dev->name);
1010 dev->dvb.frontend = mt352_attach(&avermedia_777,
1011 &dev->i2c_adap);
1012 break;
854#endif 1013#endif
855#ifdef HAVE_TDA1004X 1014#ifdef HAVE_TDA1004X
856 case SAA7134_BOARD_MD7134: 1015 case SAA7134_BOARD_MD7134:
@@ -889,11 +1048,30 @@ static int dvb_init(struct saa7134_dev *dev)
889 dev->dvb.frontend = tda10046_attach(&philips_tiger_config, 1048 dev->dvb.frontend = tda10046_attach(&philips_tiger_config,
890 &dev->i2c_adap); 1049 &dev->i2c_adap);
891 break; 1050 break;
1051 case SAA7134_BOARD_FLYDVBT_LR301:
1052 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
1053 &dev->i2c_adap);
1054 break;
1055 case SAA7134_BOARD_FLYDVB_TRIO:
1056 dev->dvb.frontend = tda10046_attach(&lifeview_trio_config,
1057 &dev->i2c_adap);
1058 break;
1059 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1060 dev->dvb.frontend = tda10046_attach(&ads_tech_duo_config,
1061 &dev->i2c_adap);
1062 break;
1063 case SAA7134_BOARD_TEVION_DVBT_220RF:
1064 dev->dvb.frontend = tda10046_attach(&tevion_dvbt220rf_config,
1065 &dev->i2c_adap);
1066 break;
892#endif 1067#endif
893#ifdef HAVE_NXT200X 1068#ifdef HAVE_NXT200X
894 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180: 1069 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
895 dev->dvb.frontend = nxt200x_attach(&avertvhda180, &dev->i2c_adap); 1070 dev->dvb.frontend = nxt200x_attach(&avertvhda180, &dev->i2c_adap);
896 break; 1071 break;
1072 case SAA7134_BOARD_KWORLD_ATSC110:
1073 dev->dvb.frontend = nxt200x_attach(&kworldatsc110, &dev->i2c_adap);
1074 break;
897#endif 1075#endif
898 default: 1076 default:
899 printk("%s: Huh? unknown DVB card?\n",dev->name); 1077 printk("%s: Huh? unknown DVB card?\n",dev->name);
diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c
index bd4c389d4c37..1d972edb3be6 100644
--- a/drivers/media/video/saa7134/saa7134-empress.c
+++ b/drivers/media/video/saa7134/saa7134-empress.c
@@ -89,7 +89,7 @@ static int ts_open(struct inode *inode, struct file *file)
89 89
90 dprintk("open minor=%d\n",minor); 90 dprintk("open minor=%d\n",minor);
91 err = -EBUSY; 91 err = -EBUSY;
92 if (down_trylock(&dev->empress_tsq.lock)) 92 if (!mutex_trylock(&dev->empress_tsq.lock))
93 goto done; 93 goto done;
94 if (dev->empress_users) 94 if (dev->empress_users)
95 goto done_up; 95 goto done_up;
@@ -99,7 +99,7 @@ static int ts_open(struct inode *inode, struct file *file)
99 err = 0; 99 err = 0;
100 100
101done_up: 101done_up:
102 up(&dev->empress_tsq.lock); 102 mutex_unlock(&dev->empress_tsq.lock);
103done: 103done:
104 return err; 104 return err;
105} 105}
@@ -110,7 +110,7 @@ static int ts_release(struct inode *inode, struct file *file)
110 110
111 if (dev->empress_tsq.streaming) 111 if (dev->empress_tsq.streaming)
112 videobuf_streamoff(&dev->empress_tsq); 112 videobuf_streamoff(&dev->empress_tsq);
113 down(&dev->empress_tsq.lock); 113 mutex_lock(&dev->empress_tsq.lock);
114 if (dev->empress_tsq.reading) 114 if (dev->empress_tsq.reading)
115 videobuf_read_stop(&dev->empress_tsq); 115 videobuf_read_stop(&dev->empress_tsq);
116 videobuf_mmap_free(&dev->empress_tsq); 116 videobuf_mmap_free(&dev->empress_tsq);
@@ -119,7 +119,7 @@ static int ts_release(struct inode *inode, struct file *file)
119 /* stop the encoder */ 119 /* stop the encoder */
120 ts_reset_encoder(dev); 120 ts_reset_encoder(dev);
121 121
122 up(&dev->empress_tsq.lock); 122 mutex_unlock(&dev->empress_tsq.lock);
123 return 0; 123 return 0;
124} 124}
125 125
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index 82d28cbf289f..1426e4c8602f 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -42,485 +42,6 @@ MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
42#define i2cdprintk(fmt, arg...) if (ir_debug) \ 42#define i2cdprintk(fmt, arg...) if (ir_debug) \
43 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg) 43 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
44 44
45/* ---------------------------------------------------------------------- */
46
47static IR_KEYTAB_TYPE flyvideo_codes[IR_KEYTAB_SIZE] = {
48 [ 15 ] = KEY_KP0,
49 [ 3 ] = KEY_KP1,
50 [ 4 ] = KEY_KP2,
51 [ 5 ] = KEY_KP3,
52 [ 7 ] = KEY_KP4,
53 [ 8 ] = KEY_KP5,
54 [ 9 ] = KEY_KP6,
55 [ 11 ] = KEY_KP7,
56 [ 12 ] = KEY_KP8,
57 [ 13 ] = KEY_KP9,
58
59 [ 14 ] = KEY_MODE, // Air/Cable
60 [ 17 ] = KEY_VIDEO, // Video
61 [ 21 ] = KEY_AUDIO, // Audio
62 [ 0 ] = KEY_POWER, // Power
63 [ 24 ] = KEY_TUNER, // AV Source
64 [ 2 ] = KEY_ZOOM, // Fullscreen
65 [ 26 ] = KEY_LANGUAGE, // Stereo
66 [ 27 ] = KEY_MUTE, // Mute
67 [ 20 ] = KEY_VOLUMEUP, // Volume +
68 [ 23 ] = KEY_VOLUMEDOWN, // Volume -
69 [ 18 ] = KEY_CHANNELUP, // Channel +
70 [ 19 ] = KEY_CHANNELDOWN, // Channel -
71 [ 6 ] = KEY_AGAIN, // Recall
72 [ 16 ] = KEY_ENTER, // Enter
73};
74
75
76static IR_KEYTAB_TYPE cinergy_codes[IR_KEYTAB_SIZE] = {
77 [ 0 ] = KEY_KP0,
78 [ 1 ] = KEY_KP1,
79 [ 2 ] = KEY_KP2,
80 [ 3 ] = KEY_KP3,
81 [ 4 ] = KEY_KP4,
82 [ 5 ] = KEY_KP5,
83 [ 6 ] = KEY_KP6,
84 [ 7 ] = KEY_KP7,
85 [ 8 ] = KEY_KP8,
86 [ 9 ] = KEY_KP9,
87
88 [ 0x0a ] = KEY_POWER,
89 [ 0x0b ] = KEY_PROG1, // app
90 [ 0x0c ] = KEY_ZOOM, // zoom/fullscreen
91 [ 0x0d ] = KEY_CHANNELUP, // channel
92 [ 0x0e ] = KEY_CHANNELDOWN, // channel-
93 [ 0x0f ] = KEY_VOLUMEUP,
94 [ 0x10 ] = KEY_VOLUMEDOWN,
95 [ 0x11 ] = KEY_TUNER, // AV
96 [ 0x12 ] = KEY_NUMLOCK, // -/--
97 [ 0x13 ] = KEY_AUDIO, // audio
98 [ 0x14 ] = KEY_MUTE,
99 [ 0x15 ] = KEY_UP,
100 [ 0x16 ] = KEY_DOWN,
101 [ 0x17 ] = KEY_LEFT,
102 [ 0x18 ] = KEY_RIGHT,
103 [ 0x19 ] = BTN_LEFT,
104 [ 0x1a ] = BTN_RIGHT,
105 [ 0x1b ] = KEY_WWW, // text
106 [ 0x1c ] = KEY_REWIND,
107 [ 0x1d ] = KEY_FORWARD,
108 [ 0x1e ] = KEY_RECORD,
109 [ 0x1f ] = KEY_PLAY,
110 [ 0x20 ] = KEY_PREVIOUSSONG,
111 [ 0x21 ] = KEY_NEXTSONG,
112 [ 0x22 ] = KEY_PAUSE,
113 [ 0x23 ] = KEY_STOP,
114};
115
116/* Alfons Geser <a.geser@cox.net>
117 * updates from Job D. R. Borges <jobdrb@ig.com.br> */
118static IR_KEYTAB_TYPE eztv_codes[IR_KEYTAB_SIZE] = {
119 [ 18 ] = KEY_POWER,
120 [ 1 ] = KEY_TV, // DVR
121 [ 21 ] = KEY_DVD, // DVD
122 [ 23 ] = KEY_AUDIO, // music
123 // DVR mode / DVD mode / music mode
124
125 [ 27 ] = KEY_MUTE, // mute
126 [ 2 ] = KEY_LANGUAGE, // MTS/SAP / audio / autoseek
127 [ 30 ] = KEY_SUBTITLE, // closed captioning / subtitle / seek
128 [ 22 ] = KEY_ZOOM, // full screen
129 [ 28 ] = KEY_VIDEO, // video source / eject / delall
130 [ 29 ] = KEY_RESTART, // playback / angle / del
131 [ 47 ] = KEY_SEARCH, // scan / menu / playlist
132 [ 48 ] = KEY_CHANNEL, // CH surfing / bookmark / memo
133
134 [ 49 ] = KEY_HELP, // help
135 [ 50 ] = KEY_MODE, // num/memo
136 [ 51 ] = KEY_ESC, // cancel
137
138 [ 12 ] = KEY_UP, // up
139 [ 16 ] = KEY_DOWN, // down
140 [ 8 ] = KEY_LEFT, // left
141 [ 4 ] = KEY_RIGHT, // right
142 [ 3 ] = KEY_SELECT, // select
143
144 [ 31 ] = KEY_REWIND, // rewind
145 [ 32 ] = KEY_PLAYPAUSE, // play/pause
146 [ 41 ] = KEY_FORWARD, // forward
147 [ 20 ] = KEY_AGAIN, // repeat
148 [ 43 ] = KEY_RECORD, // recording
149 [ 44 ] = KEY_STOP, // stop
150 [ 45 ] = KEY_PLAY, // play
151 [ 46 ] = KEY_SHUFFLE, // snapshot / shuffle
152
153 [ 0 ] = KEY_KP0,
154 [ 5 ] = KEY_KP1,
155 [ 6 ] = KEY_KP2,
156 [ 7 ] = KEY_KP3,
157 [ 9 ] = KEY_KP4,
158 [ 10 ] = KEY_KP5,
159 [ 11 ] = KEY_KP6,
160 [ 13 ] = KEY_KP7,
161 [ 14 ] = KEY_KP8,
162 [ 15 ] = KEY_KP9,
163
164 [ 42 ] = KEY_VOLUMEUP,
165 [ 17 ] = KEY_VOLUMEDOWN,
166 [ 24 ] = KEY_CHANNELUP, // CH.tracking up
167 [ 25 ] = KEY_CHANNELDOWN, // CH.tracking down
168
169 [ 19 ] = KEY_KPENTER, // enter
170 [ 33 ] = KEY_KPDOT, // . (decimal dot)
171};
172
173static IR_KEYTAB_TYPE avacssmart_codes[IR_KEYTAB_SIZE] = {
174 [ 30 ] = KEY_POWER, // power
175 [ 28 ] = KEY_SEARCH, // scan
176 [ 7 ] = KEY_SELECT, // source
177
178 [ 22 ] = KEY_VOLUMEUP,
179 [ 20 ] = KEY_VOLUMEDOWN,
180 [ 31 ] = KEY_CHANNELUP,
181 [ 23 ] = KEY_CHANNELDOWN,
182 [ 24 ] = KEY_MUTE,
183
184 [ 2 ] = KEY_KP0,
185 [ 1 ] = KEY_KP1,
186 [ 11 ] = KEY_KP2,
187 [ 27 ] = KEY_KP3,
188 [ 5 ] = KEY_KP4,
189 [ 9 ] = KEY_KP5,
190 [ 21 ] = KEY_KP6,
191 [ 6 ] = KEY_KP7,
192 [ 10 ] = KEY_KP8,
193 [ 18 ] = KEY_KP9,
194 [ 16 ] = KEY_KPDOT,
195
196 [ 3 ] = KEY_TUNER, // tv/fm
197 [ 4 ] = KEY_REWIND, // fm tuning left or function left
198 [ 12 ] = KEY_FORWARD, // fm tuning right or function right
199
200 [ 0 ] = KEY_RECORD,
201 [ 8 ] = KEY_STOP,
202 [ 17 ] = KEY_PLAY,
203
204 [ 25 ] = KEY_ZOOM,
205 [ 14 ] = KEY_MENU, // function
206 [ 19 ] = KEY_AGAIN, // recall
207 [ 29 ] = KEY_RESTART, // reset
208 [ 26 ] = KEY_SHUFFLE, // snapshot/shuffle
209
210// FIXME
211 [ 13 ] = KEY_F21, // mts
212 [ 15 ] = KEY_F22, // min
213};
214
215/* Alex Hermann <gaaf@gmx.net> */
216static IR_KEYTAB_TYPE md2819_codes[IR_KEYTAB_SIZE] = {
217 [ 40 ] = KEY_KP1,
218 [ 24 ] = KEY_KP2,
219 [ 56 ] = KEY_KP3,
220 [ 36 ] = KEY_KP4,
221 [ 20 ] = KEY_KP5,
222 [ 52 ] = KEY_KP6,
223 [ 44 ] = KEY_KP7,
224 [ 28 ] = KEY_KP8,
225 [ 60 ] = KEY_KP9,
226 [ 34 ] = KEY_KP0,
227
228 [ 32 ] = KEY_TV, // TV/FM
229 [ 16 ] = KEY_CD, // CD
230 [ 48 ] = KEY_TEXT, // TELETEXT
231 [ 0 ] = KEY_POWER, // POWER
232
233 [ 8 ] = KEY_VIDEO, // VIDEO
234 [ 4 ] = KEY_AUDIO, // AUDIO
235 [ 12 ] = KEY_ZOOM, // FULL SCREEN
236
237 [ 18 ] = KEY_SUBTITLE, // DISPLAY - ???
238 [ 50 ] = KEY_REWIND, // LOOP - ???
239 [ 2 ] = KEY_PRINT, // PREVIEW - ???
240
241 [ 42 ] = KEY_SEARCH, // AUTOSCAN
242 [ 26 ] = KEY_SLEEP, // FREEZE - ???
243 [ 58 ] = KEY_SHUFFLE, // SNAPSHOT - ???
244 [ 10 ] = KEY_MUTE, // MUTE
245
246 [ 38 ] = KEY_RECORD, // RECORD
247 [ 22 ] = KEY_PAUSE, // PAUSE
248 [ 54 ] = KEY_STOP, // STOP
249 [ 6 ] = KEY_PLAY, // PLAY
250
251 [ 46 ] = KEY_RED, // <RED>
252 [ 33 ] = KEY_GREEN, // <GREEN>
253 [ 14 ] = KEY_YELLOW, // <YELLOW>
254 [ 1 ] = KEY_BLUE, // <BLUE>
255
256 [ 30 ] = KEY_VOLUMEDOWN, // VOLUME-
257 [ 62 ] = KEY_VOLUMEUP, // VOLUME+
258 [ 17 ] = KEY_CHANNELDOWN, // CHANNEL/PAGE-
259 [ 49 ] = KEY_CHANNELUP // CHANNEL/PAGE+
260};
261
262static IR_KEYTAB_TYPE videomate_tv_pvr_codes[IR_KEYTAB_SIZE] = {
263 [ 20 ] = KEY_MUTE,
264 [ 36 ] = KEY_ZOOM,
265
266 [ 1 ] = KEY_DVD,
267 [ 35 ] = KEY_RADIO,
268 [ 0 ] = KEY_TV,
269
270 [ 10 ] = KEY_REWIND,
271 [ 8 ] = KEY_PLAYPAUSE,
272 [ 15 ] = KEY_FORWARD,
273
274 [ 2 ] = KEY_PREVIOUS,
275 [ 7 ] = KEY_STOP,
276 [ 6 ] = KEY_NEXT,
277
278 [ 12 ] = KEY_UP,
279 [ 14 ] = KEY_DOWN,
280 [ 11 ] = KEY_LEFT,
281 [ 13 ] = KEY_RIGHT,
282 [ 17 ] = KEY_OK,
283
284 [ 3 ] = KEY_MENU,
285 [ 9 ] = KEY_SETUP,
286 [ 5 ] = KEY_VIDEO,
287 [ 34 ] = KEY_CHANNEL,
288
289 [ 18 ] = KEY_VOLUMEUP,
290 [ 21 ] = KEY_VOLUMEDOWN,
291 [ 16 ] = KEY_CHANNELUP,
292 [ 19 ] = KEY_CHANNELDOWN,
293
294 [ 4 ] = KEY_RECORD,
295
296 [ 22 ] = KEY_KP1,
297 [ 23 ] = KEY_KP2,
298 [ 24 ] = KEY_KP3,
299 [ 25 ] = KEY_KP4,
300 [ 26 ] = KEY_KP5,
301 [ 27 ] = KEY_KP6,
302 [ 28 ] = KEY_KP7,
303 [ 29 ] = KEY_KP8,
304 [ 30 ] = KEY_KP9,
305 [ 31 ] = KEY_KP0,
306
307 [ 32 ] = KEY_LANGUAGE,
308 [ 33 ] = KEY_SLEEP,
309};
310
311/* Michael Tokarev <mjt@tls.msk.ru>
312 http://www.corpit.ru/mjt/beholdTV/remote_control.jpg
313 keytable is used by MANLI MTV00[12] and BeholdTV 40[13] at
314 least, and probably other cards too.
315 The "ascii-art picture" below (in comments, first row
316 is the keycode in hex, and subsequent row(s) shows
317 the button labels (several variants when appropriate)
318 helps to descide which keycodes to assign to the buttons.
319 */
320static IR_KEYTAB_TYPE manli_codes[IR_KEYTAB_SIZE] = {
321
322 /* 0x1c 0x12 *
323 * FUNCTION POWER *
324 * FM (|) *
325 * */
326 [ 0x1c ] = KEY_RADIO, /*XXX*/
327 [ 0x12 ] = KEY_POWER,
328
329 /* 0x01 0x02 0x03 *
330 * 1 2 3 *
331 * *
332 * 0x04 0x05 0x06 *
333 * 4 5 6 *
334 * *
335 * 0x07 0x08 0x09 *
336 * 7 8 9 *
337 * */
338 [ 0x01 ] = KEY_KP1,
339 [ 0x02 ] = KEY_KP2,
340 [ 0x03 ] = KEY_KP3,
341 [ 0x04 ] = KEY_KP4,
342 [ 0x05 ] = KEY_KP5,
343 [ 0x06 ] = KEY_KP6,
344 [ 0x07 ] = KEY_KP7,
345 [ 0x08 ] = KEY_KP8,
346 [ 0x09 ] = KEY_KP9,
347
348 /* 0x0a 0x00 0x17 *
349 * RECALL 0 +100 *
350 * PLUS *
351 * */
352 [ 0x0a ] = KEY_AGAIN, /*XXX KEY_REWIND? */
353 [ 0x00 ] = KEY_KP0,
354 [ 0x17 ] = KEY_DIGITS, /*XXX*/
355
356 /* 0x14 0x10 *
357 * MENU INFO *
358 * OSD */
359 [ 0x14 ] = KEY_MENU,
360 [ 0x10 ] = KEY_INFO,
361
362 /* 0x0b *
363 * Up *
364 * *
365 * 0x18 0x16 0x0c *
366 * Left Ok Right *
367 * *
368 * 0x015 *
369 * Down *
370 * */
371 [ 0x0b ] = KEY_UP, /*XXX KEY_SCROLLUP? */
372 [ 0x18 ] = KEY_LEFT, /*XXX KEY_BACK? */
373 [ 0x16 ] = KEY_OK, /*XXX KEY_SELECT? KEY_ENTER? */
374 [ 0x0c ] = KEY_RIGHT, /*XXX KEY_FORWARD? */
375 [ 0x15 ] = KEY_DOWN, /*XXX KEY_SCROLLDOWN? */
376
377 /* 0x11 0x0d *
378 * TV/AV MODE *
379 * SOURCE STEREO *
380 * */
381 [ 0x11 ] = KEY_TV, /*XXX*/
382 [ 0x0d ] = KEY_MODE, /*XXX there's no KEY_STEREO */
383
384 /* 0x0f 0x1b 0x1a *
385 * AUDIO Vol+ Chan+ *
386 * TIMESHIFT??? *
387 * *
388 * 0x0e 0x1f 0x1e *
389 * SLEEP Vol- Chan- *
390 * */
391 [ 0x0f ] = KEY_AUDIO,
392 [ 0x1b ] = KEY_VOLUMEUP,
393 [ 0x1a ] = KEY_CHANNELUP,
394 [ 0x0e ] = KEY_SLEEP, /*XXX maybe KEY_PAUSE */
395 [ 0x1f ] = KEY_VOLUMEDOWN,
396 [ 0x1e ] = KEY_CHANNELDOWN,
397
398 /* 0x13 0x19 *
399 * MUTE SNAPSHOT*
400 * */
401 [ 0x13 ] = KEY_MUTE,
402 [ 0x19 ] = KEY_RECORD, /*XXX*/
403
404 // 0x1d unused ?
405};
406
407
408/* Mike Baikov <mike@baikov.com> */
409static IR_KEYTAB_TYPE gotview7135_codes[IR_KEYTAB_SIZE] = {
410
411 [ 33 ] = KEY_POWER,
412 [ 105] = KEY_TV,
413 [ 51 ] = KEY_KP0,
414 [ 81 ] = KEY_KP1,
415 [ 49 ] = KEY_KP2,
416 [ 113] = KEY_KP3,
417 [ 59 ] = KEY_KP4,
418 [ 88 ] = KEY_KP5,
419 [ 65 ] = KEY_KP6,
420 [ 72 ] = KEY_KP7,
421 [ 48 ] = KEY_KP8,
422 [ 83 ] = KEY_KP9,
423 [ 115] = KEY_AGAIN, /* LOOP */
424 [ 10 ] = KEY_AUDIO,
425 [ 97 ] = KEY_PRINT, /* PREVIEW */
426 [ 122] = KEY_VIDEO,
427 [ 32 ] = KEY_CHANNELUP,
428 [ 64 ] = KEY_CHANNELDOWN,
429 [ 24 ] = KEY_VOLUMEDOWN,
430 [ 80 ] = KEY_VOLUMEUP,
431 [ 16 ] = KEY_MUTE,
432 [ 74 ] = KEY_SEARCH,
433 [ 123] = KEY_SHUFFLE, /* SNAPSHOT */
434 [ 34 ] = KEY_RECORD,
435 [ 98 ] = KEY_STOP,
436 [ 120] = KEY_PLAY,
437 [ 57 ] = KEY_REWIND,
438 [ 89 ] = KEY_PAUSE,
439 [ 25 ] = KEY_FORWARD,
440 [ 9 ] = KEY_ZOOM,
441
442 [ 82 ] = KEY_F21, /* LIVE TIMESHIFT */
443 [ 26 ] = KEY_F22, /* MIN TIMESHIFT */
444 [ 58 ] = KEY_F23, /* TIMESHIFT */
445 [ 112] = KEY_F24, /* NORMAL TIMESHIFT */
446};
447
448static IR_KEYTAB_TYPE ir_codes_purpletv[IR_KEYTAB_SIZE] = {
449 [ 0x3 ] = KEY_POWER,
450 [ 0x6f ] = KEY_MUTE,
451 [ 0x10 ] = KEY_BACKSPACE, /* Recall */
452
453 [ 0x11 ] = KEY_KP0,
454 [ 0x4 ] = KEY_KP1,
455 [ 0x5 ] = KEY_KP2,
456 [ 0x6 ] = KEY_KP3,
457 [ 0x8 ] = KEY_KP4,
458 [ 0x9 ] = KEY_KP5,
459 [ 0xa ] = KEY_KP6,
460 [ 0xc ] = KEY_KP7,
461 [ 0xd ] = KEY_KP8,
462 [ 0xe ] = KEY_KP9,
463 [ 0x12 ] = KEY_KPDOT, /* 100+ */
464
465 [ 0x7 ] = KEY_VOLUMEUP,
466 [ 0xb ] = KEY_VOLUMEDOWN,
467 [ 0x1a ] = KEY_KPPLUS,
468 [ 0x18 ] = KEY_KPMINUS,
469 [ 0x15 ] = KEY_UP,
470 [ 0x1d ] = KEY_DOWN,
471 [ 0xf ] = KEY_CHANNELUP,
472 [ 0x13 ] = KEY_CHANNELDOWN,
473 [ 0x48 ] = KEY_ZOOM,
474
475 [ 0x1b ] = KEY_VIDEO, /* Video source */
476 [ 0x49 ] = KEY_LANGUAGE, /* MTS Select */
477 [ 0x19 ] = KEY_SEARCH, /* Auto Scan */
478
479 [ 0x4b ] = KEY_RECORD,
480 [ 0x46 ] = KEY_PLAY,
481 [ 0x45 ] = KEY_PAUSE, /* Pause */
482 [ 0x44 ] = KEY_STOP,
483 [ 0x40 ] = KEY_FORWARD, /* Forward ? */
484 [ 0x42 ] = KEY_REWIND, /* Backward ? */
485
486};
487
488/* Mapping for the 28 key remote control as seen at
489 http://www.sednacomputer.com/photo/cardbus-tv.jpg
490 Pavel Mihaylov <bin@bash.info> */
491static IR_KEYTAB_TYPE pctv_sedna_codes[IR_KEYTAB_SIZE] = {
492 [ 0 ] = KEY_KP0,
493 [ 1 ] = KEY_KP1,
494 [ 2 ] = KEY_KP2,
495 [ 3 ] = KEY_KP3,
496 [ 4 ] = KEY_KP4,
497 [ 5 ] = KEY_KP5,
498 [ 6 ] = KEY_KP6,
499 [ 7 ] = KEY_KP7,
500 [ 8 ] = KEY_KP8,
501 [ 9 ] = KEY_KP9,
502
503 [ 0x0a ] = KEY_AGAIN, /* Recall */
504 [ 0x0b ] = KEY_CHANNELUP,
505 [ 0x0c ] = KEY_VOLUMEUP,
506 [ 0x0d ] = KEY_MODE, /* Stereo */
507 [ 0x0e ] = KEY_STOP,
508 [ 0x0f ] = KEY_PREVIOUSSONG,
509 [ 0x10 ] = KEY_ZOOM,
510 [ 0x11 ] = KEY_TUNER, /* Source */
511 [ 0x12 ] = KEY_POWER,
512 [ 0x13 ] = KEY_MUTE,
513 [ 0x15 ] = KEY_CHANNELDOWN,
514 [ 0x18 ] = KEY_VOLUMEDOWN,
515 [ 0x19 ] = KEY_SHUFFLE, /* Snapshot */
516 [ 0x1a ] = KEY_NEXTSONG,
517 [ 0x1b ] = KEY_TEXT, /* Time Shift */
518 [ 0x1c ] = KEY_RADIO, /* FM Radio */
519 [ 0x1d ] = KEY_RECORD,
520 [ 0x1e ] = KEY_PAUSE,
521};
522
523
524/* -------------------- GPIO generic keycode builder -------------------- */ 45/* -------------------- GPIO generic keycode builder -------------------- */
525 46
526static int build_key(struct saa7134_dev *dev) 47static int build_key(struct saa7134_dev *dev)
@@ -628,27 +149,27 @@ int saa7134_input_init1(struct saa7134_dev *dev)
628 case SAA7134_BOARD_FLYVIDEO3000: 149 case SAA7134_BOARD_FLYVIDEO3000:
629 case SAA7134_BOARD_FLYTVPLATINUM_FM: 150 case SAA7134_BOARD_FLYTVPLATINUM_FM:
630 case SAA7134_BOARD_FLYTVPLATINUM_MINI2: 151 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
631 ir_codes = flyvideo_codes; 152 ir_codes = ir_codes_flyvideo;
632 mask_keycode = 0xEC00000; 153 mask_keycode = 0xEC00000;
633 mask_keydown = 0x0040000; 154 mask_keydown = 0x0040000;
634 break; 155 break;
635 case SAA7134_BOARD_CINERGY400: 156 case SAA7134_BOARD_CINERGY400:
636 case SAA7134_BOARD_CINERGY600: 157 case SAA7134_BOARD_CINERGY600:
637 case SAA7134_BOARD_CINERGY600_MK3: 158 case SAA7134_BOARD_CINERGY600_MK3:
638 ir_codes = cinergy_codes; 159 ir_codes = ir_codes_cinergy;
639 mask_keycode = 0x00003f; 160 mask_keycode = 0x00003f;
640 mask_keyup = 0x040000; 161 mask_keyup = 0x040000;
641 break; 162 break;
642 case SAA7134_BOARD_ECS_TVP3XP: 163 case SAA7134_BOARD_ECS_TVP3XP:
643 case SAA7134_BOARD_ECS_TVP3XP_4CB5: 164 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
644 ir_codes = eztv_codes; 165 ir_codes = ir_codes_eztv;
645 mask_keycode = 0x00017c; 166 mask_keycode = 0x00017c;
646 mask_keyup = 0x000002; 167 mask_keyup = 0x000002;
647 polling = 50; // ms 168 polling = 50; // ms
648 break; 169 break;
649 case SAA7134_BOARD_KWORLD_XPERT: 170 case SAA7134_BOARD_KWORLD_XPERT:
650 case SAA7134_BOARD_AVACSSMARTTV: 171 case SAA7134_BOARD_AVACSSMARTTV:
651 ir_codes = avacssmart_codes; 172 ir_codes = ir_codes_pixelview;
652 mask_keycode = 0x00001F; 173 mask_keycode = 0x00001F;
653 mask_keyup = 0x000020; 174 mask_keyup = 0x000020;
654 polling = 50; // ms 175 polling = 50; // ms
@@ -660,7 +181,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
660 case SAA7134_BOARD_AVERMEDIA_STUDIO_305: 181 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
661 case SAA7134_BOARD_AVERMEDIA_STUDIO_307: 182 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
662 case SAA7134_BOARD_AVERMEDIA_GO_007_FM: 183 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
663 ir_codes = md2819_codes; 184 ir_codes = ir_codes_avermedia;
664 mask_keycode = 0x0007C8; 185 mask_keycode = 0x0007C8;
665 mask_keydown = 0x000010; 186 mask_keydown = 0x000010;
666 polling = 50; // ms 187 polling = 50; // ms
@@ -669,7 +190,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
669 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4); 190 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
670 break; 191 break;
671 case SAA7134_BOARD_KWORLD_TERMINATOR: 192 case SAA7134_BOARD_KWORLD_TERMINATOR:
672 ir_codes = avacssmart_codes; 193 ir_codes = ir_codes_pixelview;
673 mask_keycode = 0x00001f; 194 mask_keycode = 0x00001f;
674 mask_keyup = 0x000060; 195 mask_keyup = 0x000060;
675 polling = 50; // ms 196 polling = 50; // ms
@@ -677,19 +198,19 @@ int saa7134_input_init1(struct saa7134_dev *dev)
677 case SAA7134_BOARD_MANLI_MTV001: 198 case SAA7134_BOARD_MANLI_MTV001:
678 case SAA7134_BOARD_MANLI_MTV002: 199 case SAA7134_BOARD_MANLI_MTV002:
679 case SAA7134_BOARD_BEHOLD_409FM: 200 case SAA7134_BOARD_BEHOLD_409FM:
680 ir_codes = manli_codes; 201 ir_codes = ir_codes_manli;
681 mask_keycode = 0x001f00; 202 mask_keycode = 0x001f00;
682 mask_keyup = 0x004000; 203 mask_keyup = 0x004000;
683 polling = 50; // ms 204 polling = 50; // ms
684 break; 205 break;
685 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS: 206 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
686 ir_codes = pctv_sedna_codes; 207 ir_codes = ir_codes_pctv_sedna;
687 mask_keycode = 0x001f00; 208 mask_keycode = 0x001f00;
688 mask_keyup = 0x004000; 209 mask_keyup = 0x004000;
689 polling = 50; // ms 210 polling = 50; // ms
690 break; 211 break;
691 case SAA7134_BOARD_GOTVIEW_7135: 212 case SAA7134_BOARD_GOTVIEW_7135:
692 ir_codes = gotview7135_codes; 213 ir_codes = ir_codes_gotview7135;
693 mask_keycode = 0x0003EC; 214 mask_keycode = 0x0003EC;
694 mask_keyup = 0x008000; 215 mask_keyup = 0x008000;
695 mask_keydown = 0x000010; 216 mask_keydown = 0x000010;
@@ -698,17 +219,23 @@ int saa7134_input_init1(struct saa7134_dev *dev)
698 case SAA7134_BOARD_VIDEOMATE_TV_PVR: 219 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
699 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS: 220 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
700 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII: 221 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
701 ir_codes = videomate_tv_pvr_codes; 222 ir_codes = ir_codes_videomate_tv_pvr;
702 mask_keycode = 0x00003F; 223 mask_keycode = 0x00003F;
703 mask_keyup = 0x400000; 224 mask_keyup = 0x400000;
704 polling = 50; // ms 225 polling = 50; // ms
705 break; 226 break;
706 case SAA7134_BOARD_VIDEOMATE_DVBT_300: 227 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
707 case SAA7134_BOARD_VIDEOMATE_DVBT_200: 228 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
708 ir_codes = videomate_tv_pvr_codes; 229 ir_codes = ir_codes_videomate_tv_pvr;
709 mask_keycode = 0x003F00; 230 mask_keycode = 0x003F00;
710 mask_keyup = 0x040000; 231 mask_keyup = 0x040000;
711 break; 232 break;
233 case SAA7134_BOARD_FLYDVBT_LR301:
234 case SAA7134_BOARD_FLYDVBTDUO:
235 ir_codes = ir_codes_flydvb;
236 mask_keycode = 0x0001F00;
237 mask_keydown = 0x0040000;
238 break;
712 } 239 }
713 if (NULL == ir_codes) { 240 if (NULL == ir_codes) {
714 printk("%s: Oops: IR config error [card=%d]\n", 241 printk("%s: Oops: IR config error [card=%d]\n",
diff --git a/drivers/media/video/saa7134/saa7134-oss.c b/drivers/media/video/saa7134/saa7134-oss.c
index 7448e386a804..d79d05f88705 100644
--- a/drivers/media/video/saa7134/saa7134-oss.c
+++ b/drivers/media/video/saa7134/saa7134-oss.c
@@ -84,8 +84,7 @@ static int dsp_buffer_init(struct saa7134_dev *dev)
84{ 84{
85 int err; 85 int err;
86 86
87 if (!dev->dmasound.bufsize) 87 BUG_ON(!dev->dmasound.bufsize);
88 BUG();
89 videobuf_dma_init(&dev->dmasound.dma); 88 videobuf_dma_init(&dev->dmasound.dma);
90 err = videobuf_dma_init_kernel(&dev->dmasound.dma, PCI_DMA_FROMDEVICE, 89 err = videobuf_dma_init_kernel(&dev->dmasound.dma, PCI_DMA_FROMDEVICE,
91 (dev->dmasound.bufsize + PAGE_SIZE) >> PAGE_SHIFT); 90 (dev->dmasound.bufsize + PAGE_SIZE) >> PAGE_SHIFT);
@@ -96,8 +95,7 @@ static int dsp_buffer_init(struct saa7134_dev *dev)
96 95
97static int dsp_buffer_free(struct saa7134_dev *dev) 96static int dsp_buffer_free(struct saa7134_dev *dev)
98{ 97{
99 if (!dev->dmasound.blksize) 98 BUG_ON(!dev->dmasound.blksize);
100 BUG();
101 videobuf_dma_free(&dev->dmasound.dma); 99 videobuf_dma_free(&dev->dmasound.dma);
102 dev->dmasound.blocks = 0; 100 dev->dmasound.blocks = 0;
103 dev->dmasound.blksize = 0; 101 dev->dmasound.blksize = 0;
@@ -254,7 +252,7 @@ static int dsp_open(struct inode *inode, struct file *file)
254 if (NULL == dev) 252 if (NULL == dev)
255 return -ENODEV; 253 return -ENODEV;
256 254
257 down(&dev->dmasound.lock); 255 mutex_lock(&dev->dmasound.lock);
258 err = -EBUSY; 256 err = -EBUSY;
259 if (dev->dmasound.users_dsp) 257 if (dev->dmasound.users_dsp)
260 goto fail1; 258 goto fail1;
@@ -270,13 +268,13 @@ static int dsp_open(struct inode *inode, struct file *file)
270 if (0 != err) 268 if (0 != err)
271 goto fail2; 269 goto fail2;
272 270
273 up(&dev->dmasound.lock); 271 mutex_unlock(&dev->dmasound.lock);
274 return 0; 272 return 0;
275 273
276 fail2: 274 fail2:
277 dev->dmasound.users_dsp--; 275 dev->dmasound.users_dsp--;
278 fail1: 276 fail1:
279 up(&dev->dmasound.lock); 277 mutex_unlock(&dev->dmasound.lock);
280 return err; 278 return err;
281} 279}
282 280
@@ -284,13 +282,13 @@ static int dsp_release(struct inode *inode, struct file *file)
284{ 282{
285 struct saa7134_dev *dev = file->private_data; 283 struct saa7134_dev *dev = file->private_data;
286 284
287 down(&dev->dmasound.lock); 285 mutex_lock(&dev->dmasound.lock);
288 if (dev->dmasound.recording_on) 286 if (dev->dmasound.recording_on)
289 dsp_rec_stop(dev); 287 dsp_rec_stop(dev);
290 dsp_buffer_free(dev); 288 dsp_buffer_free(dev);
291 dev->dmasound.users_dsp--; 289 dev->dmasound.users_dsp--;
292 file->private_data = NULL; 290 file->private_data = NULL;
293 up(&dev->dmasound.lock); 291 mutex_unlock(&dev->dmasound.lock);
294 return 0; 292 return 0;
295} 293}
296 294
@@ -304,7 +302,7 @@ static ssize_t dsp_read(struct file *file, char __user *buffer,
304 int err,ret = 0; 302 int err,ret = 0;
305 303
306 add_wait_queue(&dev->dmasound.wq, &wait); 304 add_wait_queue(&dev->dmasound.wq, &wait);
307 down(&dev->dmasound.lock); 305 mutex_lock(&dev->dmasound.lock);
308 while (count > 0) { 306 while (count > 0) {
309 /* wait for data if needed */ 307 /* wait for data if needed */
310 if (0 == dev->dmasound.read_count) { 308 if (0 == dev->dmasound.read_count) {
@@ -328,12 +326,12 @@ static ssize_t dsp_read(struct file *file, char __user *buffer,
328 ret = -EAGAIN; 326 ret = -EAGAIN;
329 break; 327 break;
330 } 328 }
331 up(&dev->dmasound.lock); 329 mutex_unlock(&dev->dmasound.lock);
332 set_current_state(TASK_INTERRUPTIBLE); 330 set_current_state(TASK_INTERRUPTIBLE);
333 if (0 == dev->dmasound.read_count) 331 if (0 == dev->dmasound.read_count)
334 schedule(); 332 schedule();
335 set_current_state(TASK_RUNNING); 333 set_current_state(TASK_RUNNING);
336 down(&dev->dmasound.lock); 334 mutex_lock(&dev->dmasound.lock);
337 if (signal_pending(current)) { 335 if (signal_pending(current)) {
338 if (0 == ret) 336 if (0 == ret)
339 ret = -EINTR; 337 ret = -EINTR;
@@ -362,7 +360,7 @@ static ssize_t dsp_read(struct file *file, char __user *buffer,
362 if (dev->dmasound.read_offset == dev->dmasound.bufsize) 360 if (dev->dmasound.read_offset == dev->dmasound.bufsize)
363 dev->dmasound.read_offset = 0; 361 dev->dmasound.read_offset = 0;
364 } 362 }
365 up(&dev->dmasound.lock); 363 mutex_unlock(&dev->dmasound.lock);
366 remove_wait_queue(&dev->dmasound.wq, &wait); 364 remove_wait_queue(&dev->dmasound.wq, &wait);
367 return ret; 365 return ret;
368} 366}
@@ -435,13 +433,13 @@ static int dsp_ioctl(struct inode *inode, struct file *file,
435 case SNDCTL_DSP_STEREO: 433 case SNDCTL_DSP_STEREO:
436 if (get_user(val, p)) 434 if (get_user(val, p))
437 return -EFAULT; 435 return -EFAULT;
438 down(&dev->dmasound.lock); 436 mutex_lock(&dev->dmasound.lock);
439 dev->dmasound.channels = val ? 2 : 1; 437 dev->dmasound.channels = val ? 2 : 1;
440 if (dev->dmasound.recording_on) { 438 if (dev->dmasound.recording_on) {
441 dsp_rec_stop(dev); 439 dsp_rec_stop(dev);
442 dsp_rec_start(dev); 440 dsp_rec_start(dev);
443 } 441 }
444 up(&dev->dmasound.lock); 442 mutex_unlock(&dev->dmasound.lock);
445 return put_user(dev->dmasound.channels-1, p); 443 return put_user(dev->dmasound.channels-1, p);
446 444
447 case SNDCTL_DSP_CHANNELS: 445 case SNDCTL_DSP_CHANNELS:
@@ -449,13 +447,13 @@ static int dsp_ioctl(struct inode *inode, struct file *file,
449 return -EFAULT; 447 return -EFAULT;
450 if (val != 1 && val != 2) 448 if (val != 1 && val != 2)
451 return -EINVAL; 449 return -EINVAL;
452 down(&dev->dmasound.lock); 450 mutex_lock(&dev->dmasound.lock);
453 dev->dmasound.channels = val; 451 dev->dmasound.channels = val;
454 if (dev->dmasound.recording_on) { 452 if (dev->dmasound.recording_on) {
455 dsp_rec_stop(dev); 453 dsp_rec_stop(dev);
456 dsp_rec_start(dev); 454 dsp_rec_start(dev);
457 } 455 }
458 up(&dev->dmasound.lock); 456 mutex_unlock(&dev->dmasound.lock);
459 /* fall through */ 457 /* fall through */
460 case SOUND_PCM_READ_CHANNELS: 458 case SOUND_PCM_READ_CHANNELS:
461 return put_user(dev->dmasound.channels, p); 459 return put_user(dev->dmasound.channels, p);
@@ -478,13 +476,13 @@ static int dsp_ioctl(struct inode *inode, struct file *file,
478 case AFMT_U16_BE: 476 case AFMT_U16_BE:
479 case AFMT_S16_LE: 477 case AFMT_S16_LE:
480 case AFMT_S16_BE: 478 case AFMT_S16_BE:
481 down(&dev->dmasound.lock); 479 mutex_lock(&dev->dmasound.lock);
482 dev->dmasound.afmt = val; 480 dev->dmasound.afmt = val;
483 if (dev->dmasound.recording_on) { 481 if (dev->dmasound.recording_on) {
484 dsp_rec_stop(dev); 482 dsp_rec_stop(dev);
485 dsp_rec_start(dev); 483 dsp_rec_start(dev);
486 } 484 }
487 up(&dev->dmasound.lock); 485 mutex_unlock(&dev->dmasound.lock);
488 return put_user(dev->dmasound.afmt, p); 486 return put_user(dev->dmasound.afmt, p);
489 default: 487 default:
490 return -EINVAL; 488 return -EINVAL;
@@ -509,10 +507,10 @@ static int dsp_ioctl(struct inode *inode, struct file *file,
509 return 0; 507 return 0;
510 508
511 case SNDCTL_DSP_RESET: 509 case SNDCTL_DSP_RESET:
512 down(&dev->dmasound.lock); 510 mutex_lock(&dev->dmasound.lock);
513 if (dev->dmasound.recording_on) 511 if (dev->dmasound.recording_on)
514 dsp_rec_stop(dev); 512 dsp_rec_stop(dev);
515 up(&dev->dmasound.lock); 513 mutex_unlock(&dev->dmasound.lock);
516 return 0; 514 return 0;
517 case SNDCTL_DSP_GETBLKSIZE: 515 case SNDCTL_DSP_GETBLKSIZE:
518 return put_user(dev->dmasound.blksize, p); 516 return put_user(dev->dmasound.blksize, p);
@@ -556,10 +554,10 @@ static unsigned int dsp_poll(struct file *file, struct poll_table_struct *wait)
556 poll_wait(file, &dev->dmasound.wq, wait); 554 poll_wait(file, &dev->dmasound.wq, wait);
557 555
558 if (0 == dev->dmasound.read_count) { 556 if (0 == dev->dmasound.read_count) {
559 down(&dev->dmasound.lock); 557 mutex_lock(&dev->dmasound.lock);
560 if (!dev->dmasound.recording_on) 558 if (!dev->dmasound.recording_on)
561 dsp_rec_start(dev); 559 dsp_rec_start(dev);
562 up(&dev->dmasound.lock); 560 mutex_unlock(&dev->dmasound.lock);
563 } else 561 } else
564 mask |= (POLLIN | POLLRDNORM); 562 mask |= (POLLIN | POLLRDNORM);
565 return mask; 563 return mask;
@@ -852,7 +850,7 @@ int saa7134_oss_init1(struct saa7134_dev *dev)
852 return -1; 850 return -1;
853 851
854 /* general */ 852 /* general */
855 init_MUTEX(&dev->dmasound.lock); 853 mutex_init(&dev->dmasound.lock);
856 init_waitqueue_head(&dev->dmasound.wq); 854 init_waitqueue_head(&dev->dmasound.wq);
857 855
858 switch (dev->pci->device) { 856 switch (dev->pci->device) {
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index afa4dcb3f96d..3043233a8b6e 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -140,6 +140,12 @@ static struct saa7134_tvaudio tvaudio[] = {
140 .carr2 = 5850, 140 .carr2 = 5850,
141 .mode = TVAUDIO_NICAM_AM, 141 .mode = TVAUDIO_NICAM_AM,
142 },{ 142 },{
143 .name = "SECAM-L MONO",
144 .std = V4L2_STD_SECAM,
145 .carr1 = 6500,
146 .carr2 = -1,
147 .mode = TVAUDIO_AM_MONO,
148 },{
143 .name = "SECAM-D/K", 149 .name = "SECAM-D/K",
144 .std = V4L2_STD_SECAM, 150 .std = V4L2_STD_SECAM,
145 .carr1 = 6500, 151 .carr1 = 6500,
@@ -334,6 +340,12 @@ static void tvaudio_setmode(struct saa7134_dev *dev,
334 saa_writeb(SAA7134_STEREO_DAC_OUTPUT_SELECT, 0xa1); 340 saa_writeb(SAA7134_STEREO_DAC_OUTPUT_SELECT, 0xa1);
335 saa_writeb(SAA7134_NICAM_CONFIG, 0x00); 341 saa_writeb(SAA7134_NICAM_CONFIG, 0x00);
336 break; 342 break;
343 case TVAUDIO_AM_MONO:
344 saa_writeb(SAA7134_DEMODULATOR, 0x12);
345 saa_writeb(SAA7134_DCXO_IDENT_CTRL, 0x00);
346 saa_writeb(SAA7134_FM_DEEMPHASIS, 0x44);
347 saa_writeb(SAA7134_STEREO_DAC_OUTPUT_SELECT, 0xa0);
348 break;
337 case TVAUDIO_FM_SAT_STEREO: 349 case TVAUDIO_FM_SAT_STEREO:
338 /* not implemented (yet) */ 350 /* not implemented (yet) */
339 break; 351 break;
@@ -414,6 +426,7 @@ static int tvaudio_getstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *au
414 426
415 switch (audio->mode) { 427 switch (audio->mode) {
416 case TVAUDIO_FM_MONO: 428 case TVAUDIO_FM_MONO:
429 case TVAUDIO_AM_MONO:
417 return V4L2_TUNER_SUB_MONO; 430 return V4L2_TUNER_SUB_MONO;
418 case TVAUDIO_FM_K_STEREO: 431 case TVAUDIO_FM_K_STEREO:
419 case TVAUDIO_FM_BG_STEREO: 432 case TVAUDIO_FM_BG_STEREO:
@@ -480,6 +493,7 @@ static int tvaudio_setstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *au
480 493
481 switch (audio->mode) { 494 switch (audio->mode) {
482 case TVAUDIO_FM_MONO: 495 case TVAUDIO_FM_MONO:
496 case TVAUDIO_AM_MONO:
483 /* nothing to do ... */ 497 /* nothing to do ... */
484 break; 498 break;
485 case TVAUDIO_FM_K_STEREO: 499 case TVAUDIO_FM_K_STEREO:
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index e97426bc85df..57a11e71d996 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -460,17 +460,17 @@ static int res_get(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int
460 return 1; 460 return 1;
461 461
462 /* is it free? */ 462 /* is it free? */
463 down(&dev->lock); 463 mutex_lock(&dev->lock);
464 if (dev->resources & bit) { 464 if (dev->resources & bit) {
465 /* no, someone else uses it */ 465 /* no, someone else uses it */
466 up(&dev->lock); 466 mutex_unlock(&dev->lock);
467 return 0; 467 return 0;
468 } 468 }
469 /* it's free, grab it */ 469 /* it's free, grab it */
470 fh->resources |= bit; 470 fh->resources |= bit;
471 dev->resources |= bit; 471 dev->resources |= bit;
472 dprintk("res: get %d\n",bit); 472 dprintk("res: get %d\n",bit);
473 up(&dev->lock); 473 mutex_unlock(&dev->lock);
474 return 1; 474 return 1;
475} 475}
476 476
@@ -489,14 +489,13 @@ int res_locked(struct saa7134_dev *dev, unsigned int bit)
489static 489static
490void res_free(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bits) 490void res_free(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bits)
491{ 491{
492 if ((fh->resources & bits) != bits) 492 BUG_ON((fh->resources & bits) != bits);
493 BUG();
494 493
495 down(&dev->lock); 494 mutex_lock(&dev->lock);
496 fh->resources &= ~bits; 495 fh->resources &= ~bits;
497 dev->resources &= ~bits; 496 dev->resources &= ~bits;
498 dprintk("res: put %d\n",bits); 497 dprintk("res: put %d\n",bits);
499 up(&dev->lock); 498 mutex_unlock(&dev->lock);
500} 499}
501 500
502/* ------------------------------------------------------------------ */ 501/* ------------------------------------------------------------------ */
@@ -1340,21 +1339,21 @@ video_poll(struct file *file, struct poll_table_struct *wait)
1340 if (!list_empty(&fh->cap.stream)) 1339 if (!list_empty(&fh->cap.stream))
1341 buf = list_entry(fh->cap.stream.next, struct videobuf_buffer, stream); 1340 buf = list_entry(fh->cap.stream.next, struct videobuf_buffer, stream);
1342 } else { 1341 } else {
1343 down(&fh->cap.lock); 1342 mutex_lock(&fh->cap.lock);
1344 if (UNSET == fh->cap.read_off) { 1343 if (UNSET == fh->cap.read_off) {
1345 /* need to capture a new frame */ 1344 /* need to capture a new frame */
1346 if (res_locked(fh->dev,RESOURCE_VIDEO)) { 1345 if (res_locked(fh->dev,RESOURCE_VIDEO)) {
1347 up(&fh->cap.lock); 1346 mutex_unlock(&fh->cap.lock);
1348 return POLLERR; 1347 return POLLERR;
1349 } 1348 }
1350 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,fh->cap.field)) { 1349 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,fh->cap.field)) {
1351 up(&fh->cap.lock); 1350 mutex_unlock(&fh->cap.lock);
1352 return POLLERR; 1351 return POLLERR;
1353 } 1352 }
1354 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf); 1353 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf);
1355 fh->cap.read_off = 0; 1354 fh->cap.read_off = 0;
1356 } 1355 }
1357 up(&fh->cap.lock); 1356 mutex_unlock(&fh->cap.lock);
1358 buf = fh->cap.read_buf; 1357 buf = fh->cap.read_buf;
1359 } 1358 }
1360 1359
@@ -1463,6 +1462,10 @@ static int saa7134_g_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh,
1463 f->fmt.pix.height * f->fmt.pix.bytesperline; 1462 f->fmt.pix.height * f->fmt.pix.bytesperline;
1464 return 0; 1463 return 0;
1465 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 1464 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1465 if (saa7134_no_overlay > 0) {
1466 printk ("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1467 return -EINVAL;
1468 }
1466 f->fmt.win = fh->win; 1469 f->fmt.win = fh->win;
1467 return 0; 1470 return 0;
1468 case V4L2_BUF_TYPE_VBI_CAPTURE: 1471 case V4L2_BUF_TYPE_VBI_CAPTURE:
@@ -1527,6 +1530,10 @@ static int saa7134_try_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh,
1527 return 0; 1530 return 0;
1528 } 1531 }
1529 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 1532 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1533 if (saa7134_no_overlay > 0) {
1534 printk ("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1535 return -EINVAL;
1536 }
1530 err = verify_preview(dev,&f->fmt.win); 1537 err = verify_preview(dev,&f->fmt.win);
1531 if (0 != err) 1538 if (0 != err)
1532 return err; 1539 return err;
@@ -1557,18 +1564,22 @@ static int saa7134_s_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh,
1557 fh->cap.field = f->fmt.pix.field; 1564 fh->cap.field = f->fmt.pix.field;
1558 return 0; 1565 return 0;
1559 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 1566 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1567 if (saa7134_no_overlay > 0) {
1568 printk ("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1569 return -EINVAL;
1570 }
1560 err = verify_preview(dev,&f->fmt.win); 1571 err = verify_preview(dev,&f->fmt.win);
1561 if (0 != err) 1572 if (0 != err)
1562 return err; 1573 return err;
1563 1574
1564 down(&dev->lock); 1575 mutex_lock(&dev->lock);
1565 fh->win = f->fmt.win; 1576 fh->win = f->fmt.win;
1566 fh->nclips = f->fmt.win.clipcount; 1577 fh->nclips = f->fmt.win.clipcount;
1567 if (fh->nclips > 8) 1578 if (fh->nclips > 8)
1568 fh->nclips = 8; 1579 fh->nclips = 8;
1569 if (copy_from_user(fh->clips,f->fmt.win.clips, 1580 if (copy_from_user(fh->clips,f->fmt.win.clips,
1570 sizeof(struct v4l2_clip)*fh->nclips)) { 1581 sizeof(struct v4l2_clip)*fh->nclips)) {
1571 up(&dev->lock); 1582 mutex_unlock(&dev->lock);
1572 return -EFAULT; 1583 return -EFAULT;
1573 } 1584 }
1574 1585
@@ -1578,7 +1589,7 @@ static int saa7134_s_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh,
1578 start_preview(dev,fh); 1589 start_preview(dev,fh);
1579 spin_unlock_irqrestore(&dev->slock,flags); 1590 spin_unlock_irqrestore(&dev->slock,flags);
1580 } 1591 }
1581 up(&dev->lock); 1592 mutex_unlock(&dev->lock);
1582 return 0; 1593 return 0;
1583 case V4L2_BUF_TYPE_VBI_CAPTURE: 1594 case V4L2_BUF_TYPE_VBI_CAPTURE:
1584 saa7134_vbi_fmt(dev,f); 1595 saa7134_vbi_fmt(dev,f);
@@ -1612,9 +1623,9 @@ int saa7134_common_ioctl(struct saa7134_dev *dev,
1612 return get_control(dev,arg); 1623 return get_control(dev,arg);
1613 case VIDIOC_S_CTRL: 1624 case VIDIOC_S_CTRL:
1614 { 1625 {
1615 down(&dev->lock); 1626 mutex_lock(&dev->lock);
1616 err = set_control(dev,NULL,arg); 1627 err = set_control(dev,NULL,arg);
1617 up(&dev->lock); 1628 mutex_unlock(&dev->lock);
1618 return err; 1629 return err;
1619 } 1630 }
1620 /* --- input switching --------------------------------------- */ 1631 /* --- input switching --------------------------------------- */
@@ -1664,9 +1675,9 @@ int saa7134_common_ioctl(struct saa7134_dev *dev,
1664 return -EINVAL; 1675 return -EINVAL;
1665 if (NULL == card_in(dev,*i).name) 1676 if (NULL == card_in(dev,*i).name)
1666 return -EINVAL; 1677 return -EINVAL;
1667 down(&dev->lock); 1678 mutex_lock(&dev->lock);
1668 video_mux(dev,*i); 1679 video_mux(dev,*i);
1669 up(&dev->lock); 1680 mutex_unlock(&dev->lock);
1670 return 0; 1681 return 0;
1671 } 1682 }
1672 1683
@@ -1716,11 +1727,13 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1716 cap->version = SAA7134_VERSION_CODE; 1727 cap->version = SAA7134_VERSION_CODE;
1717 cap->capabilities = 1728 cap->capabilities =
1718 V4L2_CAP_VIDEO_CAPTURE | 1729 V4L2_CAP_VIDEO_CAPTURE |
1719 V4L2_CAP_VIDEO_OVERLAY |
1720 V4L2_CAP_VBI_CAPTURE | 1730 V4L2_CAP_VBI_CAPTURE |
1721 V4L2_CAP_READWRITE | 1731 V4L2_CAP_READWRITE |
1722 V4L2_CAP_STREAMING | 1732 V4L2_CAP_STREAMING |
1723 V4L2_CAP_TUNER; 1733 V4L2_CAP_TUNER;
1734 if (saa7134_no_overlay <= 0) {
1735 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY;
1736 }
1724 1737
1725 if ((tuner_type == TUNER_ABSENT) || (tuner_type == UNSET)) 1738 if ((tuner_type == TUNER_ABSENT) || (tuner_type == UNSET))
1726 cap->capabilities &= ~V4L2_CAP_TUNER; 1739 cap->capabilities &= ~V4L2_CAP_TUNER;
@@ -1766,7 +1779,7 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1766 if (i == TVNORMS) 1779 if (i == TVNORMS)
1767 return -EINVAL; 1780 return -EINVAL;
1768 1781
1769 down(&dev->lock); 1782 mutex_lock(&dev->lock);
1770 if (res_check(fh, RESOURCE_OVERLAY)) { 1783 if (res_check(fh, RESOURCE_OVERLAY)) {
1771 spin_lock_irqsave(&dev->slock,flags); 1784 spin_lock_irqsave(&dev->slock,flags);
1772 stop_preview(dev,fh); 1785 stop_preview(dev,fh);
@@ -1776,7 +1789,7 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1776 } else 1789 } else
1777 set_tvnorm(dev,&tvnorms[i]); 1790 set_tvnorm(dev,&tvnorms[i]);
1778 saa7134_tvaudio_do_scan(dev); 1791 saa7134_tvaudio_do_scan(dev);
1779 up(&dev->lock); 1792 mutex_unlock(&dev->lock);
1780 return 0; 1793 return 0;
1781 } 1794 }
1782 1795
@@ -1909,13 +1922,13 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1909 return -EINVAL; 1922 return -EINVAL;
1910 if (1 == fh->radio && V4L2_TUNER_RADIO != f->type) 1923 if (1 == fh->radio && V4L2_TUNER_RADIO != f->type)
1911 return -EINVAL; 1924 return -EINVAL;
1912 down(&dev->lock); 1925 mutex_lock(&dev->lock);
1913 dev->ctl_freq = f->frequency; 1926 dev->ctl_freq = f->frequency;
1914 1927
1915 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,f); 1928 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,f);
1916 1929
1917 saa7134_tvaudio_do_scan(dev); 1930 saa7134_tvaudio_do_scan(dev);
1918 up(&dev->lock); 1931 mutex_unlock(&dev->lock);
1919 return 0; 1932 return 0;
1920 } 1933 }
1921 1934
@@ -1971,6 +1984,10 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1971 switch (type) { 1984 switch (type) {
1972 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1985 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1973 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 1986 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1987 if (saa7134_no_overlay > 0) {
1988 printk ("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1989 return -EINVAL;
1990 }
1974 if (index >= FORMATS) 1991 if (index >= FORMATS)
1975 return -EINVAL; 1992 return -EINVAL;
1976 if (f->type == V4L2_BUF_TYPE_VIDEO_OVERLAY && 1993 if (f->type == V4L2_BUF_TYPE_VIDEO_OVERLAY &&
@@ -2031,6 +2048,11 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
2031 int *on = arg; 2048 int *on = arg;
2032 2049
2033 if (*on) { 2050 if (*on) {
2051 if (saa7134_no_overlay > 0) {
2052 printk ("no_overlay\n");
2053 return -EINVAL;
2054 }
2055
2034 if (!res_get(dev,fh,RESOURCE_OVERLAY)) 2056 if (!res_get(dev,fh,RESOURCE_OVERLAY))
2035 return -EBUSY; 2057 return -EBUSY;
2036 spin_lock_irqsave(&dev->slock,flags); 2058 spin_lock_irqsave(&dev->slock,flags);
@@ -2282,7 +2304,7 @@ static struct file_operations radio_fops =
2282struct video_device saa7134_video_template = 2304struct video_device saa7134_video_template =
2283{ 2305{
2284 .name = "saa7134-video", 2306 .name = "saa7134-video",
2285 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_OVERLAY| 2307 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|
2286 VID_TYPE_CLIPPING|VID_TYPE_SCALES, 2308 VID_TYPE_CLIPPING|VID_TYPE_SCALES,
2287 .hardware = 0, 2309 .hardware = 0,
2288 .fops = &video_fops, 2310 .fops = &video_fops,
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 6873d9a85ef1..ce1c2e0b065e 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -29,6 +29,7 @@
29#include <linux/input.h> 29#include <linux/input.h>
30#include <linux/notifier.h> 30#include <linux/notifier.h>
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/mutex.h>
32 33
33#include <asm/io.h> 34#include <asm/io.h>
34 35
@@ -60,6 +61,7 @@ enum saa7134_tvaudio_mode {
60 TVAUDIO_FM_K_STEREO = 4, 61 TVAUDIO_FM_K_STEREO = 4,
61 TVAUDIO_NICAM_AM = 5, 62 TVAUDIO_NICAM_AM = 5,
62 TVAUDIO_NICAM_FM = 6, 63 TVAUDIO_NICAM_FM = 6,
64 TVAUDIO_AM_MONO = 7
63}; 65};
64 66
65enum saa7134_audio_in { 67enum saa7134_audio_in {
@@ -210,6 +212,15 @@ struct saa7134_format {
210#define SAA7134_BOARD_MSI_TVATANYWHERE_PLUS 82 212#define SAA7134_BOARD_MSI_TVATANYWHERE_PLUS 82
211#define SAA7134_BOARD_CINERGY250PCI 83 213#define SAA7134_BOARD_CINERGY250PCI 83
212#define SAA7134_BOARD_FLYDVB_TRIO 84 214#define SAA7134_BOARD_FLYDVB_TRIO 84
215#define SAA7134_BOARD_AVERMEDIA_777 85
216#define SAA7134_BOARD_FLYDVBT_LR301 86
217#define SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331 87
218#define SAA7134_BOARD_TEVION_DVBT_220RF 88
219#define SAA7134_BOARD_ELSA_700TV 89
220#define SAA7134_BOARD_KWORLD_ATSC110 90
221#define SAA7134_BOARD_AVERMEDIA_A169_B 91
222#define SAA7134_BOARD_AVERMEDIA_A169_B1 92
223#define SAA7134_BOARD_MD7134_BRIDGE_2 93
213 224
214#define SAA7134_MAXBOARDS 8 225#define SAA7134_MAXBOARDS 8
215#define SAA7134_INPUT_MAX 8 226#define SAA7134_INPUT_MAX 8
@@ -359,7 +370,7 @@ struct saa7134_fh {
359 370
360/* dmasound dsp status */ 371/* dmasound dsp status */
361struct saa7134_dmasound { 372struct saa7134_dmasound {
362 struct semaphore lock; 373 struct mutex lock;
363 int minor_mixer; 374 int minor_mixer;
364 int minor_dsp; 375 int minor_dsp;
365 unsigned int users_dsp; 376 unsigned int users_dsp;
@@ -423,7 +434,7 @@ struct saa7134_mpeg_ops {
423/* global device status */ 434/* global device status */
424struct saa7134_dev { 435struct saa7134_dev {
425 struct list_head devlist; 436 struct list_head devlist;
426 struct semaphore lock; 437 struct mutex lock;
427 spinlock_t slock; 438 spinlock_t slock;
428#ifdef VIDIOC_G_PRIORITY 439#ifdef VIDIOC_G_PRIORITY
429 struct v4l2_prio_state prio; 440 struct v4l2_prio_state prio;
@@ -546,6 +557,7 @@ struct saa7134_dev {
546/* saa7134-core.c */ 557/* saa7134-core.c */
547 558
548extern struct list_head saa7134_devlist; 559extern struct list_head saa7134_devlist;
560extern int saa7134_no_overlay;
549 561
550void saa7134_track_gpio(struct saa7134_dev *dev, char *msg); 562void saa7134_track_gpio(struct saa7134_dev *dev, char *msg);
551 563
diff --git a/drivers/media/video/tda8290.c b/drivers/media/video/tda8290.c
index a796a4e1917c..027c8a074dfe 100644
--- a/drivers/media/video/tda8290.c
+++ b/drivers/media/video/tda8290.c
@@ -281,7 +281,7 @@ static void tda827xa_agcf(struct i2c_client *c)
281static void tda8290_i2c_bridge(struct i2c_client *c, int close) 281static void tda8290_i2c_bridge(struct i2c_client *c, int close)
282{ 282{
283 unsigned char enable[2] = { 0x21, 0xC0 }; 283 unsigned char enable[2] = { 0x21, 0xC0 };
284 unsigned char disable[2] = { 0x21, 0x80 }; 284 unsigned char disable[2] = { 0x21, 0x00 };
285 unsigned char *msg; 285 unsigned char *msg;
286 if(close) { 286 if(close) {
287 msg = enable; 287 msg = enable;
@@ -302,6 +302,7 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
302 unsigned char soft_reset[] = { 0x00, 0x00 }; 302 unsigned char soft_reset[] = { 0x00, 0x00 };
303 unsigned char easy_mode[] = { 0x01, t->tda8290_easy_mode }; 303 unsigned char easy_mode[] = { 0x01, t->tda8290_easy_mode };
304 unsigned char expert_mode[] = { 0x01, 0x80 }; 304 unsigned char expert_mode[] = { 0x01, 0x80 };
305 unsigned char agc_out_on[] = { 0x02, 0x00 };
305 unsigned char gainset_off[] = { 0x28, 0x14 }; 306 unsigned char gainset_off[] = { 0x28, 0x14 };
306 unsigned char if_agc_spd[] = { 0x0f, 0x88 }; 307 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
307 unsigned char adc_head_6[] = { 0x05, 0x04 }; 308 unsigned char adc_head_6[] = { 0x05, 0x04 };
@@ -320,6 +321,7 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
320 pll_stat; 321 pll_stat;
321 322
322 i2c_master_send(c, easy_mode, 2); 323 i2c_master_send(c, easy_mode, 2);
324 i2c_master_send(c, agc_out_on, 2);
323 i2c_master_send(c, soft_reset, 2); 325 i2c_master_send(c, soft_reset, 2);
324 msleep(1); 326 msleep(1);
325 327
@@ -470,6 +472,7 @@ static void standby(struct i2c_client *c)
470 struct tuner *t = i2c_get_clientdata(c); 472 struct tuner *t = i2c_get_clientdata(c);
471 unsigned char cb1[] = { 0x30, 0xD0 }; 473 unsigned char cb1[] = { 0x30, 0xD0 };
472 unsigned char tda8290_standby[] = { 0x00, 0x02 }; 474 unsigned char tda8290_standby[] = { 0x00, 0x02 };
475 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
473 struct i2c_msg msg = {.addr = t->tda827x_addr, .flags=0, .buf=cb1, .len = 2}; 476 struct i2c_msg msg = {.addr = t->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
474 477
475 tda8290_i2c_bridge(c, 1); 478 tda8290_i2c_bridge(c, 1);
@@ -477,6 +480,7 @@ static void standby(struct i2c_client *c)
477 cb1[1] = 0x90; 480 cb1[1] = 0x90;
478 i2c_transfer(c->adapter, &msg, 1); 481 i2c_transfer(c->adapter, &msg, 1);
479 tda8290_i2c_bridge(c, 0); 482 tda8290_i2c_bridge(c, 0);
483 i2c_master_send(c, tda8290_agc_tri, 2);
480 i2c_master_send(c, tda8290_standby, 2); 484 i2c_master_send(c, tda8290_standby, 2);
481} 485}
482 486
@@ -565,7 +569,7 @@ int tda8290_init(struct i2c_client *c)
565 strlcpy(c->name, "tda8290+75a", sizeof(c->name)); 569 strlcpy(c->name, "tda8290+75a", sizeof(c->name));
566 t->tda827x_ver = 2; 570 t->tda827x_ver = 2;
567 } 571 }
568 tuner_info("tuner: type set to %s\n", c->name); 572 tuner_info("type set to %s\n", c->name);
569 573
570 t->set_tv_freq = set_tv_freq; 574 t->set_tv_freq = set_tv_freq;
571 t->set_radio_freq = set_radio_freq; 575 t->set_radio_freq = set_radio_freq;
diff --git a/drivers/media/video/tda9840.c b/drivers/media/video/tda9840.c
index ed4c04119ccc..0243700f58ae 100644
--- a/drivers/media/video/tda9840.c
+++ b/drivers/media/video/tda9840.c
@@ -24,6 +24,7 @@
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */ 25 */
26 26
27
27#include <linux/module.h> 28#include <linux/module.h>
28#include <linux/ioctl.h> 29#include <linux/ioctl.h>
29#include <linux/i2c.h> 30#include <linux/i2c.h>
@@ -222,7 +223,7 @@ static int detach(struct i2c_client *client)
222 223
223static struct i2c_driver driver = { 224static struct i2c_driver driver = {
224 .driver = { 225 .driver = {
225 .name = "tda9840", 226 .name = "tda9840",
226 }, 227 },
227 .id = I2C_DRIVERID_TDA9840, 228 .id = I2C_DRIVERID_TDA9840,
228 .attach_adapter = attach, 229 .attach_adapter = attach,
diff --git a/drivers/media/video/tea6415c.c b/drivers/media/video/tea6415c.c
index bb35844e3842..774ed0dbc56d 100644
--- a/drivers/media/video/tea6415c.c
+++ b/drivers/media/video/tea6415c.c
@@ -26,6 +26,7 @@
26 Foundation, Inc., 675 Mvss Ave, Cambridge, MA 02139, USA. 26 Foundation, Inc., 675 Mvss Ave, Cambridge, MA 02139, USA.
27 */ 27 */
28 28
29
29#include <linux/module.h> 30#include <linux/module.h>
30#include <linux/ioctl.h> 31#include <linux/ioctl.h>
31#include <linux/i2c.h> 32#include <linux/i2c.h>
@@ -107,7 +108,7 @@ static int switch_matrix(struct i2c_client *client, int i, int o)
107{ 108{
108 u8 byte = 0; 109 u8 byte = 0;
109 int ret; 110 int ret;
110 111
111 dprintk("adr:0x%02x, i:%d, o:%d\n", client->addr, i, o); 112 dprintk("adr:0x%02x, i:%d, o:%d\n", client->addr, i, o);
112 113
113 /* check if the pins are valid */ 114 /* check if the pins are valid */
@@ -191,7 +192,7 @@ static int command(struct i2c_client *client, unsigned int cmd, void *arg)
191 192
192static struct i2c_driver driver = { 193static struct i2c_driver driver = {
193 .driver = { 194 .driver = {
194 .name = "tea6415c", 195 .name = "tea6415c",
195 }, 196 },
196 .id = I2C_DRIVERID_TEA6415C, 197 .id = I2C_DRIVERID_TEA6415C,
197 .attach_adapter = attach, 198 .attach_adapter = attach,
diff --git a/drivers/media/video/tea6420.c b/drivers/media/video/tea6420.c
index 4dcba5a4fff0..ad7d2872cfbf 100644
--- a/drivers/media/video/tea6420.c
+++ b/drivers/media/video/tea6420.c
@@ -26,6 +26,7 @@
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */ 27 */
28 28
29
29#include <linux/module.h> 30#include <linux/module.h>
30#include <linux/ioctl.h> 31#include <linux/ioctl.h>
31#include <linux/i2c.h> 32#include <linux/i2c.h>
@@ -83,7 +84,7 @@ static int tea6420_switch(struct i2c_client *client, int i, int o, int g)
83 dprintk("i2c_smbus_write_byte() failed, ret:%d\n", ret); 84 dprintk("i2c_smbus_write_byte() failed, ret:%d\n", ret);
84 return -EIO; 85 return -EIO;
85 } 86 }
86 87
87 return 0; 88 return 0;
88} 89}
89 90
@@ -167,7 +168,7 @@ static int command(struct i2c_client *client, unsigned int cmd, void *arg)
167 168
168static struct i2c_driver driver = { 169static struct i2c_driver driver = {
169 .driver = { 170 .driver = {
170 .name = "tea6420", 171 .name = "tea6420",
171 }, 172 },
172 .id = I2C_DRIVERID_TEA6420, 173 .id = I2C_DRIVERID_TEA6420,
173 .attach_adapter = attach, 174 .attach_adapter = attach,
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index b6101bf446d4..32e1849441fb 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -173,7 +173,6 @@ static void set_type(struct i2c_client *c, unsigned int type,
173 } 173 }
174 174
175 t->type = type; 175 t->type = type;
176
177 switch (t->type) { 176 switch (t->type) {
178 case TUNER_MT2032: 177 case TUNER_MT2032:
179 microtune_init(c); 178 microtune_init(c);
@@ -404,15 +403,16 @@ static void tuner_status(struct i2c_client *client)
404 tuner_info("Tuner mode: %s\n", p); 403 tuner_info("Tuner mode: %s\n", p);
405 tuner_info("Frequency: %lu.%02lu MHz\n", freq, freq_fraction); 404 tuner_info("Frequency: %lu.%02lu MHz\n", freq, freq_fraction);
406 tuner_info("Standard: 0x%08llx\n", t->std); 405 tuner_info("Standard: 0x%08llx\n", t->std);
407 if (t->mode == V4L2_TUNER_RADIO) { 406 if (t->mode != V4L2_TUNER_RADIO)
408 if (t->has_signal) { 407 return;
409 tuner_info("Signal strength: %d\n", t->has_signal(client)); 408 if (t->has_signal) {
410 } 409 tuner_info("Signal strength: %d\n", t->has_signal(client));
411 if (t->is_stereo) { 410 }
412 tuner_info("Stereo: %s\n", t->is_stereo(client) ? "yes" : "no"); 411 if (t->is_stereo) {
413 } 412 tuner_info("Stereo: %s\n", t->is_stereo(client) ? "yes" : "no");
414 } 413 }
415} 414}
415
416/* ---------------------------------------------------------------------- */ 416/* ---------------------------------------------------------------------- */
417 417
418/* static var Used only in tuner_attach and tuner_probe */ 418/* static var Used only in tuner_attach and tuner_probe */
@@ -744,33 +744,29 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
744 return 0; 744 return 0;
745 switch_v4l2(); 745 switch_v4l2();
746 746
747 if (V4L2_TUNER_RADIO == t->mode) { 747 tuner->type = t->mode;
748 748 if (t->mode != V4L2_TUNER_RADIO) {
749 if (t->has_signal)
750 tuner->signal = t->has_signal(client);
751
752 if (t->is_stereo) {
753 if (t->is_stereo(client)) {
754 tuner->rxsubchans =
755 V4L2_TUNER_SUB_STEREO |
756 V4L2_TUNER_SUB_MONO;
757 } else {
758 tuner->rxsubchans =
759 V4L2_TUNER_SUB_MONO;
760 }
761 }
762
763 tuner->capability |=
764 V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
765
766 tuner->audmode = t->audmode;
767
768 tuner->rangelow = radio_range[0] * 16000;
769 tuner->rangehigh = radio_range[1] * 16000;
770 } else {
771 tuner->rangelow = tv_range[0] * 16; 749 tuner->rangelow = tv_range[0] * 16;
772 tuner->rangehigh = tv_range[1] * 16; 750 tuner->rangehigh = tv_range[1] * 16;
751 break;
773 } 752 }
753
754 /* radio mode */
755 if (t->has_signal)
756 tuner->signal = t->has_signal(client);
757
758 tuner->rxsubchans =
759 V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
760 if (t->is_stereo) {
761 tuner->rxsubchans = t->is_stereo(client) ?
762 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
763 }
764
765 tuner->capability |=
766 V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
767 tuner->audmode = t->audmode;
768 tuner->rangelow = radio_range[0] * 16000;
769 tuner->rangehigh = radio_range[1] * 16000;
774 break; 770 break;
775 } 771 }
776 case VIDIOC_S_TUNER: 772 case VIDIOC_S_TUNER:
@@ -782,10 +778,11 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
782 778
783 switch_v4l2(); 779 switch_v4l2();
784 780
785 if (V4L2_TUNER_RADIO == t->mode) { 781 /* do nothing unless we're a radio tuner */
786 t->audmode = tuner->audmode; 782 if (t->mode != V4L2_TUNER_RADIO)
787 set_radio_freq(client, t->radio_freq); 783 break;
788 } 784 t->audmode = tuner->audmode;
785 set_radio_freq(client, t->radio_freq);
789 break; 786 break;
790 } 787 }
791 case VIDIOC_LOG_STATUS: 788 case VIDIOC_LOG_STATUS:
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index 37977ff49780..5d7abed71674 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -79,17 +79,6 @@ MODULE_PARM_DESC(offset,"Allows to specify an offset for tuner");
79#define TUNER_PLL_LOCKED 0x40 79#define TUNER_PLL_LOCKED 0x40
80#define TUNER_STEREO_MK3 0x04 80#define TUNER_STEREO_MK3 0x04
81 81
82#define TUNER_PARAM_ANALOG 0 /* to be removed */
83/* FIXME:
84 * Right now, all tuners are using the first tuner_params[] array element
85 * for analog mode. In the future, we will be merging similar tuner
86 * definitions together, such that each tuner definition will have a
87 * tuner_params struct for each available video standard. At that point,
88 * TUNER_PARAM_ANALOG will be removed, and the tuner_params[] array
89 * element will be chosen based on the video standard in use.
90 *
91 */
92
93/* ---------------------------------------------------------------------- */ 82/* ---------------------------------------------------------------------- */
94 83
95static int tuner_getstatus(struct i2c_client *c) 84static int tuner_getstatus(struct i2c_client *c)
@@ -133,14 +122,53 @@ static int tuner_stereo(struct i2c_client *c)
133static void default_set_tv_freq(struct i2c_client *c, unsigned int freq) 122static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
134{ 123{
135 struct tuner *t = i2c_get_clientdata(c); 124 struct tuner *t = i2c_get_clientdata(c);
136 u8 config, tuneraddr; 125 u8 config, cb, tuneraddr;
137 u16 div; 126 u16 div;
138 struct tunertype *tun; 127 struct tunertype *tun;
139 u8 buffer[4]; 128 u8 buffer[4];
140 int rc, IFPCoff, i, j; 129 int rc, IFPCoff, i, j;
130 enum param_type desired_type;
141 131
142 tun = &tuners[t->type]; 132 tun = &tuners[t->type];
143 j = TUNER_PARAM_ANALOG; 133
134 /* IFPCoff = Video Intermediate Frequency - Vif:
135 940 =16*58.75 NTSC/J (Japan)
136 732 =16*45.75 M/N STD
137 704 =16*44 ATSC (at DVB code)
138 632 =16*39.50 I U.K.
139 622.4=16*38.90 B/G D/K I, L STD
140 592 =16*37.00 D China
141 590 =16.36.875 B Australia
142 543.2=16*33.95 L' STD
143 171.2=16*10.70 FM Radio (at set_radio_freq)
144 */
145
146 if (t->std == V4L2_STD_NTSC_M_JP) {
147 IFPCoff = 940;
148 desired_type = TUNER_PARAM_TYPE_NTSC;
149 } else if ((t->std & V4L2_STD_MN) &&
150 !(t->std & ~V4L2_STD_MN)) {
151 IFPCoff = 732;
152 desired_type = TUNER_PARAM_TYPE_NTSC;
153 } else if (t->std == V4L2_STD_SECAM_LC) {
154 IFPCoff = 543;
155 desired_type = TUNER_PARAM_TYPE_SECAM;
156 } else {
157 IFPCoff = 623;
158 desired_type = TUNER_PARAM_TYPE_PAL;
159 }
160
161 for (j = 0; j < tun->count-1; j++) {
162 if (desired_type != tun->params[j].type)
163 continue;
164 break;
165 }
166 /* use default tuner_params if desired_type not available */
167 if (desired_type != tun->params[j].type) {
168 tuner_dbg("IFPCoff = %d: tuner_params undefined for tuner %d\n",
169 IFPCoff,t->type);
170 j = 0;
171 }
144 172
145 for (i = 0; i < tun->params[j].count; i++) { 173 for (i = 0; i < tun->params[j].count; i++) {
146 if (freq > tun->params[j].ranges[i].limit) 174 if (freq > tun->params[j].ranges[i].limit)
@@ -152,11 +180,20 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
152 freq, tun->params[j].ranges[i - 1].limit); 180 freq, tun->params[j].ranges[i - 1].limit);
153 freq = tun->params[j].ranges[--i].limit; 181 freq = tun->params[j].ranges[--i].limit;
154 } 182 }
155 config = tun->params[j].ranges[i].cb; 183 config = tun->params[j].ranges[i].config;
156 /* i == 0 -> VHF_LO */ 184 cb = tun->params[j].ranges[i].cb;
157 /* i == 1 -> VHF_HI */ 185 /* i == 0 -> VHF_LO
158 /* i == 2 -> UHF */ 186 * i == 1 -> VHF_HI
159 tuner_dbg("tv: range %d\n",i); 187 * i == 2 -> UHF */
188 tuner_dbg("tv: param %d, range %d\n",j,i);
189
190 div=freq + IFPCoff + offset;
191
192 tuner_dbg("Freq= %d.%02d MHz, V_IF=%d.%02d MHz, Offset=%d.%02d MHz, div=%0d\n",
193 freq / 16, freq % 16 * 100 / 16,
194 IFPCoff / 16, IFPCoff % 16 * 100 / 16,
195 offset / 16, offset % 16 * 100 / 16,
196 div);
160 197
161 /* tv norm specific stuff for multi-norm tuners */ 198 /* tv norm specific stuff for multi-norm tuners */
162 switch (t->type) { 199 switch (t->type) {
@@ -164,40 +201,40 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
164 /* 0x01 -> ??? no change ??? */ 201 /* 0x01 -> ??? no change ??? */
165 /* 0x02 -> PAL BDGHI / SECAM L */ 202 /* 0x02 -> PAL BDGHI / SECAM L */
166 /* 0x04 -> ??? PAL others / SECAM others ??? */ 203 /* 0x04 -> ??? PAL others / SECAM others ??? */
167 config &= ~0x02; 204 cb &= ~0x02;
168 if (t->std & V4L2_STD_SECAM) 205 if (t->std & V4L2_STD_SECAM)
169 config |= 0x02; 206 cb |= 0x02;
170 break; 207 break;
171 208
172 case TUNER_TEMIC_4046FM5: 209 case TUNER_TEMIC_4046FM5:
173 config &= ~0x0f; 210 cb &= ~0x0f;
174 211
175 if (t->std & V4L2_STD_PAL_BG) { 212 if (t->std & V4L2_STD_PAL_BG) {
176 config |= TEMIC_SET_PAL_BG; 213 cb |= TEMIC_SET_PAL_BG;
177 214
178 } else if (t->std & V4L2_STD_PAL_I) { 215 } else if (t->std & V4L2_STD_PAL_I) {
179 config |= TEMIC_SET_PAL_I; 216 cb |= TEMIC_SET_PAL_I;
180 217
181 } else if (t->std & V4L2_STD_PAL_DK) { 218 } else if (t->std & V4L2_STD_PAL_DK) {
182 config |= TEMIC_SET_PAL_DK; 219 cb |= TEMIC_SET_PAL_DK;
183 220
184 } else if (t->std & V4L2_STD_SECAM_L) { 221 } else if (t->std & V4L2_STD_SECAM_L) {
185 config |= TEMIC_SET_PAL_L; 222 cb |= TEMIC_SET_PAL_L;
186 223
187 } 224 }
188 break; 225 break;
189 226
190 case TUNER_PHILIPS_FQ1216ME: 227 case TUNER_PHILIPS_FQ1216ME:
191 config &= ~0x0f; 228 cb &= ~0x0f;
192 229
193 if (t->std & (V4L2_STD_PAL_BG|V4L2_STD_PAL_DK)) { 230 if (t->std & (V4L2_STD_PAL_BG|V4L2_STD_PAL_DK)) {
194 config |= PHILIPS_SET_PAL_BGDK; 231 cb |= PHILIPS_SET_PAL_BGDK;
195 232
196 } else if (t->std & V4L2_STD_PAL_I) { 233 } else if (t->std & V4L2_STD_PAL_I) {
197 config |= PHILIPS_SET_PAL_I; 234 cb |= PHILIPS_SET_PAL_I;
198 235
199 } else if (t->std & V4L2_STD_SECAM_L) { 236 } else if (t->std & V4L2_STD_SECAM_L) {
200 config |= PHILIPS_SET_PAL_L; 237 cb |= PHILIPS_SET_PAL_L;
201 238
202 } 239 }
203 break; 240 break;
@@ -207,15 +244,15 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
207 /* 0x01 -> ATSC antenna input 2 */ 244 /* 0x01 -> ATSC antenna input 2 */
208 /* 0x02 -> NTSC antenna input 1 */ 245 /* 0x02 -> NTSC antenna input 1 */
209 /* 0x03 -> NTSC antenna input 2 */ 246 /* 0x03 -> NTSC antenna input 2 */
210 config &= ~0x03; 247 cb &= ~0x03;
211 if (!(t->std & V4L2_STD_ATSC)) 248 if (!(t->std & V4L2_STD_ATSC))
212 config |= 2; 249 cb |= 2;
213 /* FIXME: input */ 250 /* FIXME: input */
214 break; 251 break;
215 252
216 case TUNER_MICROTUNE_4042FI5: 253 case TUNER_MICROTUNE_4042FI5:
217 /* Set the charge pump for fast tuning */ 254 /* Set the charge pump for fast tuning */
218 tun->params[j].config |= TUNER_CHARGE_PUMP; 255 config |= TUNER_CHARGE_PUMP;
219 break; 256 break;
220 257
221 case TUNER_PHILIPS_TUV1236D: 258 case TUNER_PHILIPS_TUV1236D:
@@ -227,9 +264,9 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
227 buffer[1] = 0x00; 264 buffer[1] = 0x00;
228 buffer[2] = 0x17; 265 buffer[2] = 0x17;
229 buffer[3] = 0x00; 266 buffer[3] = 0x00;
230 config &= ~0x40; 267 cb &= ~0x40;
231 if (t->std & V4L2_STD_ATSC) { 268 if (t->std & V4L2_STD_ATSC) {
232 config |= 0x40; 269 cb |= 0x40;
233 buffer[1] = 0x04; 270 buffer[1] = 0x04;
234 } 271 }
235 /* set to the correct mode (analog or digital) */ 272 /* set to the correct mode (analog or digital) */
@@ -244,47 +281,16 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
244 break; 281 break;
245 } 282 }
246 283
247 /* IFPCoff = Video Intermediate Frequency - Vif:
248 940 =16*58.75 NTSC/J (Japan)
249 732 =16*45.75 M/N STD
250 704 =16*44 ATSC (at DVB code)
251 632 =16*39.50 I U.K.
252 622.4=16*38.90 B/G D/K I, L STD
253 592 =16*37.00 D China
254 590 =16.36.875 B Australia
255 543.2=16*33.95 L' STD
256 171.2=16*10.70 FM Radio (at set_radio_freq)
257 */
258
259 if (t->std == V4L2_STD_NTSC_M_JP) {
260 IFPCoff = 940;
261 } else if ((t->std & V4L2_STD_MN) &&
262 !(t->std & ~V4L2_STD_MN)) {
263 IFPCoff = 732;
264 } else if (t->std == V4L2_STD_SECAM_LC) {
265 IFPCoff = 543;
266 } else {
267 IFPCoff = 623;
268 }
269
270 div=freq + IFPCoff + offset;
271
272 tuner_dbg("Freq= %d.%02d MHz, V_IF=%d.%02d MHz, Offset=%d.%02d MHz, div=%0d\n",
273 freq / 16, freq % 16 * 100 / 16,
274 IFPCoff / 16, IFPCoff % 16 * 100 / 16,
275 offset / 16, offset % 16 * 100 / 16,
276 div);
277
278 if (tuners[t->type].params->cb_first_if_lower_freq && div < t->last_div) { 284 if (tuners[t->type].params->cb_first_if_lower_freq && div < t->last_div) {
279 buffer[0] = tun->params[j].config; 285 buffer[0] = config;
280 buffer[1] = config; 286 buffer[1] = cb;
281 buffer[2] = (div>>8) & 0x7f; 287 buffer[2] = (div>>8) & 0x7f;
282 buffer[3] = div & 0xff; 288 buffer[3] = div & 0xff;
283 } else { 289 } else {
284 buffer[0] = (div>>8) & 0x7f; 290 buffer[0] = (div>>8) & 0x7f;
285 buffer[1] = div & 0xff; 291 buffer[1] = div & 0xff;
286 buffer[2] = tun->params[j].config; 292 buffer[2] = config;
287 buffer[3] = config; 293 buffer[3] = cb;
288 } 294 }
289 t->last_div = div; 295 t->last_div = div;
290 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", 296 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
@@ -312,11 +318,11 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
312 } 318 }
313 319
314 /* Set the charge pump for optimized phase noise figure */ 320 /* Set the charge pump for optimized phase noise figure */
315 tun->params[j].config &= ~TUNER_CHARGE_PUMP; 321 config &= ~TUNER_CHARGE_PUMP;
316 buffer[0] = (div>>8) & 0x7f; 322 buffer[0] = (div>>8) & 0x7f;
317 buffer[1] = div & 0xff; 323 buffer[1] = div & 0xff;
318 buffer[2] = tun->params[j].config; 324 buffer[2] = config;
319 buffer[3] = config; 325 buffer[3] = cb;
320 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", 326 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
321 buffer[0],buffer[1],buffer[2],buffer[3]); 327 buffer[0],buffer[1],buffer[2],buffer[3]);
322 328
@@ -332,12 +338,21 @@ static void default_set_radio_freq(struct i2c_client *c, unsigned int freq)
332 u8 buffer[4]; 338 u8 buffer[4];
333 u16 div; 339 u16 div;
334 int rc, j; 340 int rc, j;
341 enum param_type desired_type = TUNER_PARAM_TYPE_RADIO;
335 342
336 tun = &tuners[t->type]; 343 tun = &tuners[t->type];
337 j = TUNER_PARAM_ANALOG; 344
345 for (j = 0; j < tun->count-1; j++) {
346 if (desired_type != tun->params[j].type)
347 continue;
348 break;
349 }
350 /* use default tuner_params if desired_type not available */
351 if (desired_type != tun->params[j].type)
352 j = 0;
338 353
339 div = (20 * freq / 16000) + (int)(20*10.7); /* IF 10.7 MHz */ 354 div = (20 * freq / 16000) + (int)(20*10.7); /* IF 10.7 MHz */
340 buffer[2] = (tun->params[j].config & ~TUNER_RATIO_MASK) | TUNER_RATIO_SELECT_50; /* 50 kHz step */ 355 buffer[2] = (tun->params[j].ranges[0].config & ~TUNER_RATIO_MASK) | TUNER_RATIO_SELECT_50; /* 50 kHz step */
341 356
342 switch (t->type) { 357 switch (t->type) {
343 case TUNER_TENA_9533_DI: 358 case TUNER_TENA_9533_DI:
@@ -349,6 +364,9 @@ static void default_set_radio_freq(struct i2c_client *c, unsigned int freq)
349 case TUNER_PHILIPS_FMD1216ME_MK3: 364 case TUNER_PHILIPS_FMD1216ME_MK3:
350 buffer[3] = 0x19; 365 buffer[3] = 0x19;
351 break; 366 break;
367 case TUNER_TNF_5335MF:
368 buffer[3] = 0x11;
369 break;
352 case TUNER_PHILIPS_FM1256_IH3: 370 case TUNER_PHILIPS_FM1256_IH3:
353 div = (20 * freq) / 16000 + (int)(33.3 * 20); /* IF 33.3 MHz */ 371 div = (20 * freq) / 16000 + (int)(33.3 * 20); /* IF 33.3 MHz */
354 buffer[3] = 0x19; 372 buffer[3] = 0x19;
diff --git a/drivers/media/video/tuner-types.c b/drivers/media/video/tuner-types.c
index 6fe781798d89..72e0f01db563 100644
--- a/drivers/media/video/tuner-types.c
+++ b/drivers/media/video/tuner-types.c
@@ -23,22 +23,25 @@
23 * Each tuner_params array may contain one or more elements, one 23 * Each tuner_params array may contain one or more elements, one
24 * for each video standard. 24 * for each video standard.
25 * 25 *
26 * FIXME: Some tuner_range definitions are duplicated, and 26 * FIXME: tuner_params struct contains an element, tda988x. We must
27 * should be eliminated. 27 * set this for all tuners that contain a tda988x chip, and then we
28 * can remove this setting from the various card structs.
28 * 29 *
29 * FIXME: tunertype struct contains an element, has_tda988x. 30 * FIXME: Right now, all tuners are using the first tuner_params[]
30 * We must set this for all tunertypes that contain a tda988x 31 * array element for analog mode. In the future, we will be merging
31 * chip, and then we can remove this setting from the various 32 * similar tuner definitions together, such that each tuner definition
32 * card structs. 33 * will have a tuner_params struct for each available video standard.
34 * At that point, the tuner_params[] array element will be chosen
35 * based on the video standard in use.
33 */ 36 */
34 37
35/* 0-9 */ 38/* 0-9 */
36/* ------------ TUNER_TEMIC_PAL - TEMIC PAL ------------ */ 39/* ------------ TUNER_TEMIC_PAL - TEMIC PAL ------------ */
37 40
38static struct tuner_range tuner_temic_pal_ranges[] = { 41static struct tuner_range tuner_temic_pal_ranges[] = {
39 { 16 * 140.25 /*MHz*/, 0x02, }, 42 { 16 * 140.25 /*MHz*/, 0x8e, 0x02, },
40 { 16 * 463.25 /*MHz*/, 0x04, }, 43 { 16 * 463.25 /*MHz*/, 0x8e, 0x04, },
41 { 16 * 999.99 , 0x01, }, 44 { 16 * 999.99 , 0x8e, 0x01, },
42}; 45};
43 46
44static struct tuner_params tuner_temic_pal_params[] = { 47static struct tuner_params tuner_temic_pal_params[] = {
@@ -46,16 +49,15 @@ static struct tuner_params tuner_temic_pal_params[] = {
46 .type = TUNER_PARAM_TYPE_PAL, 49 .type = TUNER_PARAM_TYPE_PAL,
47 .ranges = tuner_temic_pal_ranges, 50 .ranges = tuner_temic_pal_ranges,
48 .count = ARRAY_SIZE(tuner_temic_pal_ranges), 51 .count = ARRAY_SIZE(tuner_temic_pal_ranges),
49 .config = 0x8e,
50 }, 52 },
51}; 53};
52 54
53/* ------------ TUNER_PHILIPS_PAL_I - Philips PAL_I ------------ */ 55/* ------------ TUNER_PHILIPS_PAL_I - Philips PAL_I ------------ */
54 56
55static struct tuner_range tuner_philips_pal_i_ranges[] = { 57static struct tuner_range tuner_philips_pal_i_ranges[] = {
56 { 16 * 140.25 /*MHz*/, 0xa0, }, 58 { 16 * 140.25 /*MHz*/, 0x8e, 0xa0, },
57 { 16 * 463.25 /*MHz*/, 0x90, }, 59 { 16 * 463.25 /*MHz*/, 0x8e, 0x90, },
58 { 16 * 999.99 , 0x30, }, 60 { 16 * 999.99 , 0x8e, 0x30, },
59}; 61};
60 62
61static struct tuner_params tuner_philips_pal_i_params[] = { 63static struct tuner_params tuner_philips_pal_i_params[] = {
@@ -63,16 +65,15 @@ static struct tuner_params tuner_philips_pal_i_params[] = {
63 .type = TUNER_PARAM_TYPE_PAL, 65 .type = TUNER_PARAM_TYPE_PAL,
64 .ranges = tuner_philips_pal_i_ranges, 66 .ranges = tuner_philips_pal_i_ranges,
65 .count = ARRAY_SIZE(tuner_philips_pal_i_ranges), 67 .count = ARRAY_SIZE(tuner_philips_pal_i_ranges),
66 .config = 0x8e,
67 }, 68 },
68}; 69};
69 70
70/* ------------ TUNER_PHILIPS_NTSC - Philips NTSC ------------ */ 71/* ------------ TUNER_PHILIPS_NTSC - Philips NTSC ------------ */
71 72
72static struct tuner_range tuner_philips_ntsc_ranges[] = { 73static struct tuner_range tuner_philips_ntsc_ranges[] = {
73 { 16 * 157.25 /*MHz*/, 0xa0, }, 74 { 16 * 157.25 /*MHz*/, 0x8e, 0xa0, },
74 { 16 * 451.25 /*MHz*/, 0x90, }, 75 { 16 * 451.25 /*MHz*/, 0x8e, 0x90, },
75 { 16 * 999.99 , 0x30, }, 76 { 16 * 999.99 , 0x8e, 0x30, },
76}; 77};
77 78
78static struct tuner_params tuner_philips_ntsc_params[] = { 79static struct tuner_params tuner_philips_ntsc_params[] = {
@@ -80,7 +81,6 @@ static struct tuner_params tuner_philips_ntsc_params[] = {
80 .type = TUNER_PARAM_TYPE_NTSC, 81 .type = TUNER_PARAM_TYPE_NTSC,
81 .ranges = tuner_philips_ntsc_ranges, 82 .ranges = tuner_philips_ntsc_ranges,
82 .count = ARRAY_SIZE(tuner_philips_ntsc_ranges), 83 .count = ARRAY_SIZE(tuner_philips_ntsc_ranges),
83 .config = 0x8e,
84 .cb_first_if_lower_freq = 1, 84 .cb_first_if_lower_freq = 1,
85 }, 85 },
86}; 86};
@@ -88,9 +88,9 @@ static struct tuner_params tuner_philips_ntsc_params[] = {
88/* ------------ TUNER_PHILIPS_SECAM - Philips SECAM ------------ */ 88/* ------------ TUNER_PHILIPS_SECAM - Philips SECAM ------------ */
89 89
90static struct tuner_range tuner_philips_secam_ranges[] = { 90static struct tuner_range tuner_philips_secam_ranges[] = {
91 { 16 * 168.25 /*MHz*/, 0xa7, }, 91 { 16 * 168.25 /*MHz*/, 0x8e, 0xa7, },
92 { 16 * 447.25 /*MHz*/, 0x97, }, 92 { 16 * 447.25 /*MHz*/, 0x8e, 0x97, },
93 { 16 * 999.99 , 0x37, }, 93 { 16 * 999.99 , 0x8e, 0x37, },
94}; 94};
95 95
96static struct tuner_params tuner_philips_secam_params[] = { 96static struct tuner_params tuner_philips_secam_params[] = {
@@ -98,7 +98,6 @@ static struct tuner_params tuner_philips_secam_params[] = {
98 .type = TUNER_PARAM_TYPE_SECAM, 98 .type = TUNER_PARAM_TYPE_SECAM,
99 .ranges = tuner_philips_secam_ranges, 99 .ranges = tuner_philips_secam_ranges,
100 .count = ARRAY_SIZE(tuner_philips_secam_ranges), 100 .count = ARRAY_SIZE(tuner_philips_secam_ranges),
101 .config = 0x8e,
102 .cb_first_if_lower_freq = 1, 101 .cb_first_if_lower_freq = 1,
103 }, 102 },
104}; 103};
@@ -106,9 +105,9 @@ static struct tuner_params tuner_philips_secam_params[] = {
106/* ------------ TUNER_PHILIPS_PAL - Philips PAL ------------ */ 105/* ------------ TUNER_PHILIPS_PAL - Philips PAL ------------ */
107 106
108static struct tuner_range tuner_philips_pal_ranges[] = { 107static struct tuner_range tuner_philips_pal_ranges[] = {
109 { 16 * 168.25 /*MHz*/, 0xa0, }, 108 { 16 * 168.25 /*MHz*/, 0x8e, 0xa0, },
110 { 16 * 447.25 /*MHz*/, 0x90, }, 109 { 16 * 447.25 /*MHz*/, 0x8e, 0x90, },
111 { 16 * 999.99 , 0x30, }, 110 { 16 * 999.99 , 0x8e, 0x30, },
112}; 111};
113 112
114static struct tuner_params tuner_philips_pal_params[] = { 113static struct tuner_params tuner_philips_pal_params[] = {
@@ -116,7 +115,6 @@ static struct tuner_params tuner_philips_pal_params[] = {
116 .type = TUNER_PARAM_TYPE_PAL, 115 .type = TUNER_PARAM_TYPE_PAL,
117 .ranges = tuner_philips_pal_ranges, 116 .ranges = tuner_philips_pal_ranges,
118 .count = ARRAY_SIZE(tuner_philips_pal_ranges), 117 .count = ARRAY_SIZE(tuner_philips_pal_ranges),
119 .config = 0x8e,
120 .cb_first_if_lower_freq = 1, 118 .cb_first_if_lower_freq = 1,
121 }, 119 },
122}; 120};
@@ -124,9 +122,9 @@ static struct tuner_params tuner_philips_pal_params[] = {
124/* ------------ TUNER_TEMIC_NTSC - TEMIC NTSC ------------ */ 122/* ------------ TUNER_TEMIC_NTSC - TEMIC NTSC ------------ */
125 123
126static struct tuner_range tuner_temic_ntsc_ranges[] = { 124static struct tuner_range tuner_temic_ntsc_ranges[] = {
127 { 16 * 157.25 /*MHz*/, 0x02, }, 125 { 16 * 157.25 /*MHz*/, 0x8e, 0x02, },
128 { 16 * 463.25 /*MHz*/, 0x04, }, 126 { 16 * 463.25 /*MHz*/, 0x8e, 0x04, },
129 { 16 * 999.99 , 0x01, }, 127 { 16 * 999.99 , 0x8e, 0x01, },
130}; 128};
131 129
132static struct tuner_params tuner_temic_ntsc_params[] = { 130static struct tuner_params tuner_temic_ntsc_params[] = {
@@ -134,16 +132,15 @@ static struct tuner_params tuner_temic_ntsc_params[] = {
134 .type = TUNER_PARAM_TYPE_NTSC, 132 .type = TUNER_PARAM_TYPE_NTSC,
135 .ranges = tuner_temic_ntsc_ranges, 133 .ranges = tuner_temic_ntsc_ranges,
136 .count = ARRAY_SIZE(tuner_temic_ntsc_ranges), 134 .count = ARRAY_SIZE(tuner_temic_ntsc_ranges),
137 .config = 0x8e,
138 }, 135 },
139}; 136};
140 137
141/* ------------ TUNER_TEMIC_PAL_I - TEMIC PAL_I ------------ */ 138/* ------------ TUNER_TEMIC_PAL_I - TEMIC PAL_I ------------ */
142 139
143static struct tuner_range tuner_temic_pal_i_ranges[] = { 140static struct tuner_range tuner_temic_pal_i_ranges[] = {
144 { 16 * 170.00 /*MHz*/, 0x02, }, 141 { 16 * 170.00 /*MHz*/, 0x8e, 0x02, },
145 { 16 * 450.00 /*MHz*/, 0x04, }, 142 { 16 * 450.00 /*MHz*/, 0x8e, 0x04, },
146 { 16 * 999.99 , 0x01, }, 143 { 16 * 999.99 , 0x8e, 0x01, },
147}; 144};
148 145
149static struct tuner_params tuner_temic_pal_i_params[] = { 146static struct tuner_params tuner_temic_pal_i_params[] = {
@@ -151,16 +148,15 @@ static struct tuner_params tuner_temic_pal_i_params[] = {
151 .type = TUNER_PARAM_TYPE_PAL, 148 .type = TUNER_PARAM_TYPE_PAL,
152 .ranges = tuner_temic_pal_i_ranges, 149 .ranges = tuner_temic_pal_i_ranges,
153 .count = ARRAY_SIZE(tuner_temic_pal_i_ranges), 150 .count = ARRAY_SIZE(tuner_temic_pal_i_ranges),
154 .config = 0x8e,
155 }, 151 },
156}; 152};
157 153
158/* ------------ TUNER_TEMIC_4036FY5_NTSC - TEMIC NTSC ------------ */ 154/* ------------ TUNER_TEMIC_4036FY5_NTSC - TEMIC NTSC ------------ */
159 155
160static struct tuner_range tuner_temic_4036fy5_ntsc_ranges[] = { 156static struct tuner_range tuner_temic_4036fy5_ntsc_ranges[] = {
161 { 16 * 157.25 /*MHz*/, 0xa0, }, 157 { 16 * 157.25 /*MHz*/, 0x8e, 0xa0, },
162 { 16 * 463.25 /*MHz*/, 0x90, }, 158 { 16 * 463.25 /*MHz*/, 0x8e, 0x90, },
163 { 16 * 999.99 , 0x30, }, 159 { 16 * 999.99 , 0x8e, 0x30, },
164}; 160};
165 161
166static struct tuner_params tuner_temic_4036fy5_ntsc_params[] = { 162static struct tuner_params tuner_temic_4036fy5_ntsc_params[] = {
@@ -168,16 +164,15 @@ static struct tuner_params tuner_temic_4036fy5_ntsc_params[] = {
168 .type = TUNER_PARAM_TYPE_NTSC, 164 .type = TUNER_PARAM_TYPE_NTSC,
169 .ranges = tuner_temic_4036fy5_ntsc_ranges, 165 .ranges = tuner_temic_4036fy5_ntsc_ranges,
170 .count = ARRAY_SIZE(tuner_temic_4036fy5_ntsc_ranges), 166 .count = ARRAY_SIZE(tuner_temic_4036fy5_ntsc_ranges),
171 .config = 0x8e,
172 }, 167 },
173}; 168};
174 169
175/* ------------ TUNER_ALPS_TSBH1_NTSC - TEMIC NTSC ------------ */ 170/* ------------ TUNER_ALPS_TSBH1_NTSC - TEMIC NTSC ------------ */
176 171
177static struct tuner_range tuner_alps_tsb_1_ranges[] = { 172static struct tuner_range tuner_alps_tsb_1_ranges[] = {
178 { 16 * 137.25 /*MHz*/, 0x01, }, 173 { 16 * 137.25 /*MHz*/, 0x8e, 0x01, },
179 { 16 * 385.25 /*MHz*/, 0x02, }, 174 { 16 * 385.25 /*MHz*/, 0x8e, 0x02, },
180 { 16 * 999.99 , 0x08, }, 175 { 16 * 999.99 , 0x8e, 0x08, },
181}; 176};
182 177
183static struct tuner_params tuner_alps_tsbh1_ntsc_params[] = { 178static struct tuner_params tuner_alps_tsbh1_ntsc_params[] = {
@@ -185,7 +180,6 @@ static struct tuner_params tuner_alps_tsbh1_ntsc_params[] = {
185 .type = TUNER_PARAM_TYPE_NTSC, 180 .type = TUNER_PARAM_TYPE_NTSC,
186 .ranges = tuner_alps_tsb_1_ranges, 181 .ranges = tuner_alps_tsb_1_ranges,
187 .count = ARRAY_SIZE(tuner_alps_tsb_1_ranges), 182 .count = ARRAY_SIZE(tuner_alps_tsb_1_ranges),
188 .config = 0x8e,
189 }, 183 },
190}; 184};
191 185
@@ -197,16 +191,15 @@ static struct tuner_params tuner_alps_tsb_1_params[] = {
197 .type = TUNER_PARAM_TYPE_PAL, 191 .type = TUNER_PARAM_TYPE_PAL,
198 .ranges = tuner_alps_tsb_1_ranges, 192 .ranges = tuner_alps_tsb_1_ranges,
199 .count = ARRAY_SIZE(tuner_alps_tsb_1_ranges), 193 .count = ARRAY_SIZE(tuner_alps_tsb_1_ranges),
200 .config = 0x8e,
201 }, 194 },
202}; 195};
203 196
204/* ------------ TUNER_ALPS_TSBB5_PAL_I - Alps PAL_I ------------ */ 197/* ------------ TUNER_ALPS_TSBB5_PAL_I - Alps PAL_I ------------ */
205 198
206static struct tuner_range tuner_alps_tsb_5_pal_ranges[] = { 199static struct tuner_range tuner_alps_tsb_5_pal_ranges[] = {
207 { 16 * 133.25 /*MHz*/, 0x01, }, 200 { 16 * 133.25 /*MHz*/, 0x8e, 0x01, },
208 { 16 * 351.25 /*MHz*/, 0x02, }, 201 { 16 * 351.25 /*MHz*/, 0x8e, 0x02, },
209 { 16 * 999.99 , 0x08, }, 202 { 16 * 999.99 , 0x8e, 0x08, },
210}; 203};
211 204
212static struct tuner_params tuner_alps_tsbb5_params[] = { 205static struct tuner_params tuner_alps_tsbb5_params[] = {
@@ -214,7 +207,6 @@ static struct tuner_params tuner_alps_tsbb5_params[] = {
214 .type = TUNER_PARAM_TYPE_PAL, 207 .type = TUNER_PARAM_TYPE_PAL,
215 .ranges = tuner_alps_tsb_5_pal_ranges, 208 .ranges = tuner_alps_tsb_5_pal_ranges,
216 .count = ARRAY_SIZE(tuner_alps_tsb_5_pal_ranges), 209 .count = ARRAY_SIZE(tuner_alps_tsb_5_pal_ranges),
217 .config = 0x8e,
218 }, 210 },
219}; 211};
220 212
@@ -225,7 +217,6 @@ static struct tuner_params tuner_alps_tsbe5_params[] = {
225 .type = TUNER_PARAM_TYPE_PAL, 217 .type = TUNER_PARAM_TYPE_PAL,
226 .ranges = tuner_alps_tsb_5_pal_ranges, 218 .ranges = tuner_alps_tsb_5_pal_ranges,
227 .count = ARRAY_SIZE(tuner_alps_tsb_5_pal_ranges), 219 .count = ARRAY_SIZE(tuner_alps_tsb_5_pal_ranges),
228 .config = 0x8e,
229 }, 220 },
230}; 221};
231 222
@@ -236,33 +227,31 @@ static struct tuner_params tuner_alps_tsbc5_params[] = {
236 .type = TUNER_PARAM_TYPE_PAL, 227 .type = TUNER_PARAM_TYPE_PAL,
237 .ranges = tuner_alps_tsb_5_pal_ranges, 228 .ranges = tuner_alps_tsb_5_pal_ranges,
238 .count = ARRAY_SIZE(tuner_alps_tsb_5_pal_ranges), 229 .count = ARRAY_SIZE(tuner_alps_tsb_5_pal_ranges),
239 .config = 0x8e,
240 }, 230 },
241}; 231};
242 232
243/* ------------ TUNER_TEMIC_4006FH5_PAL - TEMIC PAL ------------ */ 233/* ------------ TUNER_TEMIC_4006FH5_PAL - TEMIC PAL ------------ */
244 234
245static struct tuner_range tuner_temic_4006fh5_pal_ranges[] = { 235static struct tuner_range tuner_lg_pal_ranges[] = {
246 { 16 * 170.00 /*MHz*/, 0xa0, }, 236 { 16 * 170.00 /*MHz*/, 0x8e, 0xa0, },
247 { 16 * 450.00 /*MHz*/, 0x90, }, 237 { 16 * 450.00 /*MHz*/, 0x8e, 0x90, },
248 { 16 * 999.99 , 0x30, }, 238 { 16 * 999.99 , 0x8e, 0x30, },
249}; 239};
250 240
251static struct tuner_params tuner_temic_4006fh5_params[] = { 241static struct tuner_params tuner_temic_4006fh5_params[] = {
252 { 242 {
253 .type = TUNER_PARAM_TYPE_PAL, 243 .type = TUNER_PARAM_TYPE_PAL,
254 .ranges = tuner_temic_4006fh5_pal_ranges, 244 .ranges = tuner_lg_pal_ranges,
255 .count = ARRAY_SIZE(tuner_temic_4006fh5_pal_ranges), 245 .count = ARRAY_SIZE(tuner_lg_pal_ranges),
256 .config = 0x8e,
257 }, 246 },
258}; 247};
259 248
260/* ------------ TUNER_ALPS_TSHC6_NTSC - Alps NTSC ------------ */ 249/* ------------ TUNER_ALPS_TSHC6_NTSC - Alps NTSC ------------ */
261 250
262static struct tuner_range tuner_alps_tshc6_ntsc_ranges[] = { 251static struct tuner_range tuner_alps_tshc6_ntsc_ranges[] = {
263 { 16 * 137.25 /*MHz*/, 0x14, }, 252 { 16 * 137.25 /*MHz*/, 0x8e, 0x14, },
264 { 16 * 385.25 /*MHz*/, 0x12, }, 253 { 16 * 385.25 /*MHz*/, 0x8e, 0x12, },
265 { 16 * 999.99 , 0x11, }, 254 { 16 * 999.99 , 0x8e, 0x11, },
266}; 255};
267 256
268static struct tuner_params tuner_alps_tshc6_params[] = { 257static struct tuner_params tuner_alps_tshc6_params[] = {
@@ -270,16 +259,15 @@ static struct tuner_params tuner_alps_tshc6_params[] = {
270 .type = TUNER_PARAM_TYPE_NTSC, 259 .type = TUNER_PARAM_TYPE_NTSC,
271 .ranges = tuner_alps_tshc6_ntsc_ranges, 260 .ranges = tuner_alps_tshc6_ntsc_ranges,
272 .count = ARRAY_SIZE(tuner_alps_tshc6_ntsc_ranges), 261 .count = ARRAY_SIZE(tuner_alps_tshc6_ntsc_ranges),
273 .config = 0x8e,
274 }, 262 },
275}; 263};
276 264
277/* ------------ TUNER_TEMIC_PAL_DK - TEMIC PAL ------------ */ 265/* ------------ TUNER_TEMIC_PAL_DK - TEMIC PAL ------------ */
278 266
279static struct tuner_range tuner_temic_pal_dk_ranges[] = { 267static struct tuner_range tuner_temic_pal_dk_ranges[] = {
280 { 16 * 168.25 /*MHz*/, 0xa0, }, 268 { 16 * 168.25 /*MHz*/, 0x8e, 0xa0, },
281 { 16 * 456.25 /*MHz*/, 0x90, }, 269 { 16 * 456.25 /*MHz*/, 0x8e, 0x90, },
282 { 16 * 999.99 , 0x30, }, 270 { 16 * 999.99 , 0x8e, 0x30, },
283}; 271};
284 272
285static struct tuner_params tuner_temic_pal_dk_params[] = { 273static struct tuner_params tuner_temic_pal_dk_params[] = {
@@ -287,16 +275,15 @@ static struct tuner_params tuner_temic_pal_dk_params[] = {
287 .type = TUNER_PARAM_TYPE_PAL, 275 .type = TUNER_PARAM_TYPE_PAL,
288 .ranges = tuner_temic_pal_dk_ranges, 276 .ranges = tuner_temic_pal_dk_ranges,
289 .count = ARRAY_SIZE(tuner_temic_pal_dk_ranges), 277 .count = ARRAY_SIZE(tuner_temic_pal_dk_ranges),
290 .config = 0x8e,
291 }, 278 },
292}; 279};
293 280
294/* ------------ TUNER_PHILIPS_NTSC_M - Philips NTSC ------------ */ 281/* ------------ TUNER_PHILIPS_NTSC_M - Philips NTSC ------------ */
295 282
296static struct tuner_range tuner_philips_ntsc_m_ranges[] = { 283static struct tuner_range tuner_philips_ntsc_m_ranges[] = {
297 { 16 * 160.00 /*MHz*/, 0xa0, }, 284 { 16 * 160.00 /*MHz*/, 0x8e, 0xa0, },
298 { 16 * 454.00 /*MHz*/, 0x90, }, 285 { 16 * 454.00 /*MHz*/, 0x8e, 0x90, },
299 { 16 * 999.99 , 0x30, }, 286 { 16 * 999.99 , 0x8e, 0x30, },
300}; 287};
301 288
302static struct tuner_params tuner_philips_ntsc_m_params[] = { 289static struct tuner_params tuner_philips_ntsc_m_params[] = {
@@ -304,16 +291,15 @@ static struct tuner_params tuner_philips_ntsc_m_params[] = {
304 .type = TUNER_PARAM_TYPE_NTSC, 291 .type = TUNER_PARAM_TYPE_NTSC,
305 .ranges = tuner_philips_ntsc_m_ranges, 292 .ranges = tuner_philips_ntsc_m_ranges,
306 .count = ARRAY_SIZE(tuner_philips_ntsc_m_ranges), 293 .count = ARRAY_SIZE(tuner_philips_ntsc_m_ranges),
307 .config = 0x8e,
308 }, 294 },
309}; 295};
310 296
311/* ------------ TUNER_TEMIC_4066FY5_PAL_I - TEMIC PAL_I ------------ */ 297/* ------------ TUNER_TEMIC_4066FY5_PAL_I - TEMIC PAL_I ------------ */
312 298
313static struct tuner_range tuner_temic_40x6f_5_pal_ranges[] = { 299static struct tuner_range tuner_temic_40x6f_5_pal_ranges[] = {
314 { 16 * 169.00 /*MHz*/, 0xa0, }, 300 { 16 * 169.00 /*MHz*/, 0x8e, 0xa0, },
315 { 16 * 454.00 /*MHz*/, 0x90, }, 301 { 16 * 454.00 /*MHz*/, 0x8e, 0x90, },
316 { 16 * 999.99 , 0x30, }, 302 { 16 * 999.99 , 0x8e, 0x30, },
317}; 303};
318 304
319static struct tuner_params tuner_temic_4066fy5_pal_i_params[] = { 305static struct tuner_params tuner_temic_4066fy5_pal_i_params[] = {
@@ -321,7 +307,6 @@ static struct tuner_params tuner_temic_4066fy5_pal_i_params[] = {
321 .type = TUNER_PARAM_TYPE_PAL, 307 .type = TUNER_PARAM_TYPE_PAL,
322 .ranges = tuner_temic_40x6f_5_pal_ranges, 308 .ranges = tuner_temic_40x6f_5_pal_ranges,
323 .count = ARRAY_SIZE(tuner_temic_40x6f_5_pal_ranges), 309 .count = ARRAY_SIZE(tuner_temic_40x6f_5_pal_ranges),
324 .config = 0x8e,
325 }, 310 },
326}; 311};
327 312
@@ -332,7 +317,6 @@ static struct tuner_params tuner_temic_4006fn5_multi_params[] = {
332 .type = TUNER_PARAM_TYPE_PAL, 317 .type = TUNER_PARAM_TYPE_PAL,
333 .ranges = tuner_temic_40x6f_5_pal_ranges, 318 .ranges = tuner_temic_40x6f_5_pal_ranges,
334 .count = ARRAY_SIZE(tuner_temic_40x6f_5_pal_ranges), 319 .count = ARRAY_SIZE(tuner_temic_40x6f_5_pal_ranges),
335 .config = 0x8e,
336 }, 320 },
337}; 321};
338 322
@@ -340,9 +324,9 @@ static struct tuner_params tuner_temic_4006fn5_multi_params[] = {
340/* ------------ TUNER_TEMIC_4009FR5_PAL - TEMIC PAL ------------ */ 324/* ------------ TUNER_TEMIC_4009FR5_PAL - TEMIC PAL ------------ */
341 325
342static struct tuner_range tuner_temic_4009f_5_pal_ranges[] = { 326static struct tuner_range tuner_temic_4009f_5_pal_ranges[] = {
343 { 16 * 141.00 /*MHz*/, 0xa0, }, 327 { 16 * 141.00 /*MHz*/, 0x8e, 0xa0, },
344 { 16 * 464.00 /*MHz*/, 0x90, }, 328 { 16 * 464.00 /*MHz*/, 0x8e, 0x90, },
345 { 16 * 999.99 , 0x30, }, 329 { 16 * 999.99 , 0x8e, 0x30, },
346}; 330};
347 331
348static struct tuner_params tuner_temic_4009f_5_params[] = { 332static struct tuner_params tuner_temic_4009f_5_params[] = {
@@ -350,58 +334,42 @@ static struct tuner_params tuner_temic_4009f_5_params[] = {
350 .type = TUNER_PARAM_TYPE_PAL, 334 .type = TUNER_PARAM_TYPE_PAL,
351 .ranges = tuner_temic_4009f_5_pal_ranges, 335 .ranges = tuner_temic_4009f_5_pal_ranges,
352 .count = ARRAY_SIZE(tuner_temic_4009f_5_pal_ranges), 336 .count = ARRAY_SIZE(tuner_temic_4009f_5_pal_ranges),
353 .config = 0x8e,
354 }, 337 },
355}; 338};
356 339
357/* ------------ TUNER_TEMIC_4039FR5_NTSC - TEMIC NTSC ------------ */ 340/* ------------ TUNER_TEMIC_4039FR5_NTSC - TEMIC NTSC ------------ */
358 341
359static struct tuner_range tuner_temic_4039fr5_ntsc_ranges[] = { 342static struct tuner_range tuner_temic_4x3x_f_5_ntsc_ranges[] = {
360 { 16 * 158.00 /*MHz*/, 0xa0, }, 343 { 16 * 158.00 /*MHz*/, 0x8e, 0xa0, },
361 { 16 * 453.00 /*MHz*/, 0x90, }, 344 { 16 * 453.00 /*MHz*/, 0x8e, 0x90, },
362 { 16 * 999.99 , 0x30, }, 345 { 16 * 999.99 , 0x8e, 0x30, },
363}; 346};
364 347
365static struct tuner_params tuner_temic_4039fr5_params[] = { 348static struct tuner_params tuner_temic_4039fr5_params[] = {
366 { 349 {
367 .type = TUNER_PARAM_TYPE_NTSC, 350 .type = TUNER_PARAM_TYPE_NTSC,
368 .ranges = tuner_temic_4039fr5_ntsc_ranges, 351 .ranges = tuner_temic_4x3x_f_5_ntsc_ranges,
369 .count = ARRAY_SIZE(tuner_temic_4039fr5_ntsc_ranges), 352 .count = ARRAY_SIZE(tuner_temic_4x3x_f_5_ntsc_ranges),
370 .config = 0x8e,
371 }, 353 },
372}; 354};
373 355
374/* ------------ TUNER_TEMIC_4046FM5 - TEMIC PAL ------------ */ 356/* ------------ TUNER_TEMIC_4046FM5 - TEMIC PAL ------------ */
375 357
376static struct tuner_range tuner_temic_4046fm5_pal_ranges[] = {
377 { 16 * 169.00 /*MHz*/, 0xa0, },
378 { 16 * 454.00 /*MHz*/, 0x90, },
379 { 16 * 999.99 , 0x30, },
380};
381
382static struct tuner_params tuner_temic_4046fm5_params[] = { 358static struct tuner_params tuner_temic_4046fm5_params[] = {
383 { 359 {
384 .type = TUNER_PARAM_TYPE_PAL, 360 .type = TUNER_PARAM_TYPE_PAL,
385 .ranges = tuner_temic_4046fm5_pal_ranges, 361 .ranges = tuner_temic_40x6f_5_pal_ranges,
386 .count = ARRAY_SIZE(tuner_temic_4046fm5_pal_ranges), 362 .count = ARRAY_SIZE(tuner_temic_40x6f_5_pal_ranges),
387 .config = 0x8e,
388 }, 363 },
389}; 364};
390 365
391/* ------------ TUNER_PHILIPS_PAL_DK - Philips PAL ------------ */ 366/* ------------ TUNER_PHILIPS_PAL_DK - Philips PAL ------------ */
392 367
393static struct tuner_range tuner_lg_pal_ranges[] = {
394 { 16 * 170.00 /*MHz*/, 0xa0, },
395 { 16 * 450.00 /*MHz*/, 0x90, },
396 { 16 * 999.99 , 0x30, },
397};
398
399static struct tuner_params tuner_philips_pal_dk_params[] = { 368static struct tuner_params tuner_philips_pal_dk_params[] = {
400 { 369 {
401 .type = TUNER_PARAM_TYPE_PAL, 370 .type = TUNER_PARAM_TYPE_PAL,
402 .ranges = tuner_lg_pal_ranges, 371 .ranges = tuner_lg_pal_ranges,
403 .count = ARRAY_SIZE(tuner_lg_pal_ranges), 372 .count = ARRAY_SIZE(tuner_lg_pal_ranges),
404 .config = 0x8e,
405 }, 373 },
406}; 374};
407 375
@@ -412,7 +380,6 @@ static struct tuner_params tuner_philips_fq1216me_params[] = {
412 .type = TUNER_PARAM_TYPE_PAL, 380 .type = TUNER_PARAM_TYPE_PAL,
413 .ranges = tuner_lg_pal_ranges, 381 .ranges = tuner_lg_pal_ranges,
414 .count = ARRAY_SIZE(tuner_lg_pal_ranges), 382 .count = ARRAY_SIZE(tuner_lg_pal_ranges),
415 .config = 0x8e,
416 }, 383 },
417}; 384};
418 385
@@ -423,7 +390,6 @@ static struct tuner_params tuner_lg_pal_i_fm_params[] = {
423 .type = TUNER_PARAM_TYPE_PAL, 390 .type = TUNER_PARAM_TYPE_PAL,
424 .ranges = tuner_lg_pal_ranges, 391 .ranges = tuner_lg_pal_ranges,
425 .count = ARRAY_SIZE(tuner_lg_pal_ranges), 392 .count = ARRAY_SIZE(tuner_lg_pal_ranges),
426 .config = 0x8e,
427 }, 393 },
428}; 394};
429 395
@@ -434,16 +400,15 @@ static struct tuner_params tuner_lg_pal_i_params[] = {
434 .type = TUNER_PARAM_TYPE_PAL, 400 .type = TUNER_PARAM_TYPE_PAL,
435 .ranges = tuner_lg_pal_ranges, 401 .ranges = tuner_lg_pal_ranges,
436 .count = ARRAY_SIZE(tuner_lg_pal_ranges), 402 .count = ARRAY_SIZE(tuner_lg_pal_ranges),
437 .config = 0x8e,
438 }, 403 },
439}; 404};
440 405
441/* ------------ TUNER_LG_NTSC_FM - LGINNOTEK NTSC ------------ */ 406/* ------------ TUNER_LG_NTSC_FM - LGINNOTEK NTSC ------------ */
442 407
443static struct tuner_range tuner_lg_ntsc_fm_ranges[] = { 408static struct tuner_range tuner_lg_ntsc_fm_ranges[] = {
444 { 16 * 210.00 /*MHz*/, 0xa0, }, 409 { 16 * 210.00 /*MHz*/, 0x8e, 0xa0, },
445 { 16 * 497.00 /*MHz*/, 0x90, }, 410 { 16 * 497.00 /*MHz*/, 0x8e, 0x90, },
446 { 16 * 999.99 , 0x30, }, 411 { 16 * 999.99 , 0x8e, 0x30, },
447}; 412};
448 413
449static struct tuner_params tuner_lg_ntsc_fm_params[] = { 414static struct tuner_params tuner_lg_ntsc_fm_params[] = {
@@ -451,7 +416,6 @@ static struct tuner_params tuner_lg_ntsc_fm_params[] = {
451 .type = TUNER_PARAM_TYPE_NTSC, 416 .type = TUNER_PARAM_TYPE_NTSC,
452 .ranges = tuner_lg_ntsc_fm_ranges, 417 .ranges = tuner_lg_ntsc_fm_ranges,
453 .count = ARRAY_SIZE(tuner_lg_ntsc_fm_ranges), 418 .count = ARRAY_SIZE(tuner_lg_ntsc_fm_ranges),
454 .config = 0x8e,
455 }, 419 },
456}; 420};
457 421
@@ -462,7 +426,6 @@ static struct tuner_params tuner_lg_pal_fm_params[] = {
462 .type = TUNER_PARAM_TYPE_PAL, 426 .type = TUNER_PARAM_TYPE_PAL,
463 .ranges = tuner_lg_pal_ranges, 427 .ranges = tuner_lg_pal_ranges,
464 .count = ARRAY_SIZE(tuner_lg_pal_ranges), 428 .count = ARRAY_SIZE(tuner_lg_pal_ranges),
465 .config = 0x8e,
466 }, 429 },
467}; 430};
468 431
@@ -473,7 +436,6 @@ static struct tuner_params tuner_lg_pal_params[] = {
473 .type = TUNER_PARAM_TYPE_PAL, 436 .type = TUNER_PARAM_TYPE_PAL,
474 .ranges = tuner_lg_pal_ranges, 437 .ranges = tuner_lg_pal_ranges,
475 .count = ARRAY_SIZE(tuner_lg_pal_ranges), 438 .count = ARRAY_SIZE(tuner_lg_pal_ranges),
476 .config = 0x8e,
477 }, 439 },
478}; 440};
479 441
@@ -485,16 +447,15 @@ static struct tuner_params tuner_temic_4009_fn5_multi_pal_fm_params[] = {
485 .type = TUNER_PARAM_TYPE_PAL, 447 .type = TUNER_PARAM_TYPE_PAL,
486 .ranges = tuner_temic_4009f_5_pal_ranges, 448 .ranges = tuner_temic_4009f_5_pal_ranges,
487 .count = ARRAY_SIZE(tuner_temic_4009f_5_pal_ranges), 449 .count = ARRAY_SIZE(tuner_temic_4009f_5_pal_ranges),
488 .config = 0x8e,
489 }, 450 },
490}; 451};
491 452
492/* ------------ TUNER_SHARP_2U5JF5540_NTSC - SHARP NTSC ------------ */ 453/* ------------ TUNER_SHARP_2U5JF5540_NTSC - SHARP NTSC ------------ */
493 454
494static struct tuner_range tuner_sharp_2u5jf5540_ntsc_ranges[] = { 455static struct tuner_range tuner_sharp_2u5jf5540_ntsc_ranges[] = {
495 { 16 * 137.25 /*MHz*/, 0x01, }, 456 { 16 * 137.25 /*MHz*/, 0x8e, 0x01, },
496 { 16 * 317.25 /*MHz*/, 0x02, }, 457 { 16 * 317.25 /*MHz*/, 0x8e, 0x02, },
497 { 16 * 999.99 , 0x08, }, 458 { 16 * 999.99 , 0x8e, 0x08, },
498}; 459};
499 460
500static struct tuner_params tuner_sharp_2u5jf5540_params[] = { 461static struct tuner_params tuner_sharp_2u5jf5540_params[] = {
@@ -502,16 +463,15 @@ static struct tuner_params tuner_sharp_2u5jf5540_params[] = {
502 .type = TUNER_PARAM_TYPE_NTSC, 463 .type = TUNER_PARAM_TYPE_NTSC,
503 .ranges = tuner_sharp_2u5jf5540_ntsc_ranges, 464 .ranges = tuner_sharp_2u5jf5540_ntsc_ranges,
504 .count = ARRAY_SIZE(tuner_sharp_2u5jf5540_ntsc_ranges), 465 .count = ARRAY_SIZE(tuner_sharp_2u5jf5540_ntsc_ranges),
505 .config = 0x8e,
506 }, 466 },
507}; 467};
508 468
509/* ------------ TUNER_Samsung_PAL_TCPM9091PD27 - Samsung PAL ------------ */ 469/* ------------ TUNER_Samsung_PAL_TCPM9091PD27 - Samsung PAL ------------ */
510 470
511static struct tuner_range tuner_samsung_pal_tcpm9091pd27_ranges[] = { 471static struct tuner_range tuner_samsung_pal_tcpm9091pd27_ranges[] = {
512 { 16 * 169 /*MHz*/, 0xa0, }, 472 { 16 * 169 /*MHz*/, 0x8e, 0xa0, },
513 { 16 * 464 /*MHz*/, 0x90, }, 473 { 16 * 464 /*MHz*/, 0x8e, 0x90, },
514 { 16 * 999.99 , 0x30, }, 474 { 16 * 999.99 , 0x8e, 0x30, },
515}; 475};
516 476
517static struct tuner_params tuner_samsung_pal_tcpm9091pd27_params[] = { 477static struct tuner_params tuner_samsung_pal_tcpm9091pd27_params[] = {
@@ -519,7 +479,6 @@ static struct tuner_params tuner_samsung_pal_tcpm9091pd27_params[] = {
519 .type = TUNER_PARAM_TYPE_PAL, 479 .type = TUNER_PARAM_TYPE_PAL,
520 .ranges = tuner_samsung_pal_tcpm9091pd27_ranges, 480 .ranges = tuner_samsung_pal_tcpm9091pd27_ranges,
521 .count = ARRAY_SIZE(tuner_samsung_pal_tcpm9091pd27_ranges), 481 .count = ARRAY_SIZE(tuner_samsung_pal_tcpm9091pd27_ranges),
522 .config = 0x8e,
523 }, 482 },
524}; 483};
525 484
@@ -530,50 +489,35 @@ static struct tuner_params tuner_temic_4106fh5_params[] = {
530 .type = TUNER_PARAM_TYPE_PAL, 489 .type = TUNER_PARAM_TYPE_PAL,
531 .ranges = tuner_temic_4009f_5_pal_ranges, 490 .ranges = tuner_temic_4009f_5_pal_ranges,
532 .count = ARRAY_SIZE(tuner_temic_4009f_5_pal_ranges), 491 .count = ARRAY_SIZE(tuner_temic_4009f_5_pal_ranges),
533 .config = 0x8e,
534 }, 492 },
535}; 493};
536 494
537/* ------------ TUNER_TEMIC_4012FY5 - TEMIC PAL ------------ */ 495/* ------------ TUNER_TEMIC_4012FY5 - TEMIC PAL ------------ */
538 496
539static struct tuner_range tuner_temic_4012fy5_pal_ranges[] = {
540 { 16 * 140.25 /*MHz*/, 0x02, },
541 { 16 * 463.25 /*MHz*/, 0x04, },
542 { 16 * 999.99 , 0x01, },
543};
544
545static struct tuner_params tuner_temic_4012fy5_params[] = { 497static struct tuner_params tuner_temic_4012fy5_params[] = {
546 { 498 {
547 .type = TUNER_PARAM_TYPE_PAL, 499 .type = TUNER_PARAM_TYPE_PAL,
548 .ranges = tuner_temic_4012fy5_pal_ranges, 500 .ranges = tuner_temic_pal_ranges,
549 .count = ARRAY_SIZE(tuner_temic_4012fy5_pal_ranges), 501 .count = ARRAY_SIZE(tuner_temic_pal_ranges),
550 .config = 0x8e,
551 }, 502 },
552}; 503};
553 504
554/* ------------ TUNER_TEMIC_4136FY5 - TEMIC NTSC ------------ */ 505/* ------------ TUNER_TEMIC_4136FY5 - TEMIC NTSC ------------ */
555 506
556static struct tuner_range tuner_temic_4136_fy5_ntsc_ranges[] = {
557 { 16 * 158.00 /*MHz*/, 0xa0, },
558 { 16 * 453.00 /*MHz*/, 0x90, },
559 { 16 * 999.99 , 0x30, },
560};
561
562static struct tuner_params tuner_temic_4136_fy5_params[] = { 507static struct tuner_params tuner_temic_4136_fy5_params[] = {
563 { 508 {
564 .type = TUNER_PARAM_TYPE_NTSC, 509 .type = TUNER_PARAM_TYPE_NTSC,
565 .ranges = tuner_temic_4136_fy5_ntsc_ranges, 510 .ranges = tuner_temic_4x3x_f_5_ntsc_ranges,
566 .count = ARRAY_SIZE(tuner_temic_4136_fy5_ntsc_ranges), 511 .count = ARRAY_SIZE(tuner_temic_4x3x_f_5_ntsc_ranges),
567 .config = 0x8e,
568 }, 512 },
569}; 513};
570 514
571/* ------------ TUNER_LG_PAL_NEW_TAPC - LGINNOTEK PAL ------------ */ 515/* ------------ TUNER_LG_PAL_NEW_TAPC - LGINNOTEK PAL ------------ */
572 516
573static struct tuner_range tuner_lg_new_tapc_ranges[] = { 517static struct tuner_range tuner_lg_new_tapc_ranges[] = {
574 { 16 * 170.00 /*MHz*/, 0x01, }, 518 { 16 * 170.00 /*MHz*/, 0x8e, 0x01, },
575 { 16 * 450.00 /*MHz*/, 0x02, }, 519 { 16 * 450.00 /*MHz*/, 0x8e, 0x02, },
576 { 16 * 999.99 , 0x08, }, 520 { 16 * 999.99 , 0x8e, 0x08, },
577}; 521};
578 522
579static struct tuner_params tuner_lg_pal_new_tapc_params[] = { 523static struct tuner_params tuner_lg_pal_new_tapc_params[] = {
@@ -581,16 +525,15 @@ static struct tuner_params tuner_lg_pal_new_tapc_params[] = {
581 .type = TUNER_PARAM_TYPE_PAL, 525 .type = TUNER_PARAM_TYPE_PAL,
582 .ranges = tuner_lg_new_tapc_ranges, 526 .ranges = tuner_lg_new_tapc_ranges,
583 .count = ARRAY_SIZE(tuner_lg_new_tapc_ranges), 527 .count = ARRAY_SIZE(tuner_lg_new_tapc_ranges),
584 .config = 0x8e,
585 }, 528 },
586}; 529};
587 530
588/* ------------ TUNER_PHILIPS_FM1216ME_MK3 - Philips PAL ------------ */ 531/* ------------ TUNER_PHILIPS_FM1216ME_MK3 - Philips PAL ------------ */
589 532
590static struct tuner_range tuner_fm1216me_mk3_pal_ranges[] = { 533static struct tuner_range tuner_fm1216me_mk3_pal_ranges[] = {
591 { 16 * 158.00 /*MHz*/, 0x01, }, 534 { 16 * 158.00 /*MHz*/, 0x8e, 0x01, },
592 { 16 * 442.00 /*MHz*/, 0x02, }, 535 { 16 * 442.00 /*MHz*/, 0x8e, 0x02, },
593 { 16 * 999.99 , 0x04, }, 536 { 16 * 999.99 , 0x8e, 0x04, },
594}; 537};
595 538
596static struct tuner_params tuner_fm1216me_mk3_params[] = { 539static struct tuner_params tuner_fm1216me_mk3_params[] = {
@@ -598,7 +541,6 @@ static struct tuner_params tuner_fm1216me_mk3_params[] = {
598 .type = TUNER_PARAM_TYPE_PAL, 541 .type = TUNER_PARAM_TYPE_PAL,
599 .ranges = tuner_fm1216me_mk3_pal_ranges, 542 .ranges = tuner_fm1216me_mk3_pal_ranges,
600 .count = ARRAY_SIZE(tuner_fm1216me_mk3_pal_ranges), 543 .count = ARRAY_SIZE(tuner_fm1216me_mk3_pal_ranges),
601 .config = 0x8e,
602 .cb_first_if_lower_freq = 1, 544 .cb_first_if_lower_freq = 1,
603 }, 545 },
604}; 546};
@@ -610,7 +552,6 @@ static struct tuner_params tuner_lg_ntsc_new_tapc_params[] = {
610 .type = TUNER_PARAM_TYPE_NTSC, 552 .type = TUNER_PARAM_TYPE_NTSC,
611 .ranges = tuner_lg_new_tapc_ranges, 553 .ranges = tuner_lg_new_tapc_ranges,
612 .count = ARRAY_SIZE(tuner_lg_new_tapc_ranges), 554 .count = ARRAY_SIZE(tuner_lg_new_tapc_ranges),
613 .config = 0x8e,
614 }, 555 },
615}; 556};
616 557
@@ -622,16 +563,15 @@ static struct tuner_params tuner_hitachi_ntsc_params[] = {
622 .type = TUNER_PARAM_TYPE_NTSC, 563 .type = TUNER_PARAM_TYPE_NTSC,
623 .ranges = tuner_lg_new_tapc_ranges, 564 .ranges = tuner_lg_new_tapc_ranges,
624 .count = ARRAY_SIZE(tuner_lg_new_tapc_ranges), 565 .count = ARRAY_SIZE(tuner_lg_new_tapc_ranges),
625 .config = 0x8e,
626 }, 566 },
627}; 567};
628 568
629/* ------------ TUNER_PHILIPS_PAL_MK - Philips PAL ------------ */ 569/* ------------ TUNER_PHILIPS_PAL_MK - Philips PAL ------------ */
630 570
631static struct tuner_range tuner_philips_pal_mk_pal_ranges[] = { 571static struct tuner_range tuner_philips_pal_mk_pal_ranges[] = {
632 { 16 * 140.25 /*MHz*/, 0x01, }, 572 { 16 * 140.25 /*MHz*/, 0x8e, 0x01, },
633 { 16 * 463.25 /*MHz*/, 0xc2, }, 573 { 16 * 463.25 /*MHz*/, 0x8e, 0xc2, },
634 { 16 * 999.99 , 0xcf, }, 574 { 16 * 999.99 , 0x8e, 0xcf, },
635}; 575};
636 576
637static struct tuner_params tuner_philips_pal_mk_params[] = { 577static struct tuner_params tuner_philips_pal_mk_params[] = {
@@ -639,16 +579,15 @@ static struct tuner_params tuner_philips_pal_mk_params[] = {
639 .type = TUNER_PARAM_TYPE_PAL, 579 .type = TUNER_PARAM_TYPE_PAL,
640 .ranges = tuner_philips_pal_mk_pal_ranges, 580 .ranges = tuner_philips_pal_mk_pal_ranges,
641 .count = ARRAY_SIZE(tuner_philips_pal_mk_pal_ranges), 581 .count = ARRAY_SIZE(tuner_philips_pal_mk_pal_ranges),
642 .config = 0x8e,
643 }, 582 },
644}; 583};
645 584
646/* ------------ TUNER_PHILIPS_ATSC - Philips ATSC ------------ */ 585/* ------------ TUNER_PHILIPS_ATSC - Philips ATSC ------------ */
647 586
648static struct tuner_range tuner_philips_atsc_ranges[] = { 587static struct tuner_range tuner_philips_atsc_ranges[] = {
649 { 16 * 157.25 /*MHz*/, 0xa0, }, 588 { 16 * 157.25 /*MHz*/, 0x8e, 0xa0, },
650 { 16 * 454.00 /*MHz*/, 0x90, }, 589 { 16 * 454.00 /*MHz*/, 0x8e, 0x90, },
651 { 16 * 999.99 , 0x30, }, 590 { 16 * 999.99 , 0x8e, 0x30, },
652}; 591};
653 592
654static struct tuner_params tuner_philips_atsc_params[] = { 593static struct tuner_params tuner_philips_atsc_params[] = {
@@ -656,16 +595,15 @@ static struct tuner_params tuner_philips_atsc_params[] = {
656 .type = TUNER_PARAM_TYPE_NTSC, 595 .type = TUNER_PARAM_TYPE_NTSC,
657 .ranges = tuner_philips_atsc_ranges, 596 .ranges = tuner_philips_atsc_ranges,
658 .count = ARRAY_SIZE(tuner_philips_atsc_ranges), 597 .count = ARRAY_SIZE(tuner_philips_atsc_ranges),
659 .config = 0x8e,
660 }, 598 },
661}; 599};
662 600
663/* ------------ TUNER_PHILIPS_FM1236_MK3 - Philips NTSC ------------ */ 601/* ------------ TUNER_PHILIPS_FM1236_MK3 - Philips NTSC ------------ */
664 602
665static struct tuner_range tuner_fm1236_mk3_ntsc_ranges[] = { 603static struct tuner_range tuner_fm1236_mk3_ntsc_ranges[] = {
666 { 16 * 160.00 /*MHz*/, 0x01, }, 604 { 16 * 160.00 /*MHz*/, 0x8e, 0x01, },
667 { 16 * 442.00 /*MHz*/, 0x02, }, 605 { 16 * 442.00 /*MHz*/, 0x8e, 0x02, },
668 { 16 * 999.99 , 0x04, }, 606 { 16 * 999.99 , 0x8e, 0x04, },
669}; 607};
670 608
671static struct tuner_params tuner_fm1236_mk3_params[] = { 609static struct tuner_params tuner_fm1236_mk3_params[] = {
@@ -673,25 +611,17 @@ static struct tuner_params tuner_fm1236_mk3_params[] = {
673 .type = TUNER_PARAM_TYPE_NTSC, 611 .type = TUNER_PARAM_TYPE_NTSC,
674 .ranges = tuner_fm1236_mk3_ntsc_ranges, 612 .ranges = tuner_fm1236_mk3_ntsc_ranges,
675 .count = ARRAY_SIZE(tuner_fm1236_mk3_ntsc_ranges), 613 .count = ARRAY_SIZE(tuner_fm1236_mk3_ntsc_ranges),
676 .config = 0x8e,
677 .cb_first_if_lower_freq = 1, 614 .cb_first_if_lower_freq = 1,
678 }, 615 },
679}; 616};
680 617
681/* ------------ TUNER_PHILIPS_4IN1 - Philips NTSC ------------ */ 618/* ------------ TUNER_PHILIPS_4IN1 - Philips NTSC ------------ */
682 619
683static struct tuner_range tuner_philips_4in1_ntsc_ranges[] = {
684 { 16 * 160.00 /*MHz*/, 0x01, },
685 { 16 * 442.00 /*MHz*/, 0x02, },
686 { 16 * 999.99 , 0x04, },
687};
688
689static struct tuner_params tuner_philips_4in1_params[] = { 620static struct tuner_params tuner_philips_4in1_params[] = {
690 { 621 {
691 .type = TUNER_PARAM_TYPE_NTSC, 622 .type = TUNER_PARAM_TYPE_NTSC,
692 .ranges = tuner_philips_4in1_ntsc_ranges, 623 .ranges = tuner_fm1236_mk3_ntsc_ranges,
693 .count = ARRAY_SIZE(tuner_philips_4in1_ntsc_ranges), 624 .count = ARRAY_SIZE(tuner_fm1236_mk3_ntsc_ranges),
694 .config = 0x8e,
695 }, 625 },
696}; 626};
697 627
@@ -702,16 +632,15 @@ static struct tuner_params tuner_microtune_4049_fm5_params[] = {
702 .type = TUNER_PARAM_TYPE_PAL, 632 .type = TUNER_PARAM_TYPE_PAL,
703 .ranges = tuner_temic_4009f_5_pal_ranges, 633 .ranges = tuner_temic_4009f_5_pal_ranges,
704 .count = ARRAY_SIZE(tuner_temic_4009f_5_pal_ranges), 634 .count = ARRAY_SIZE(tuner_temic_4009f_5_pal_ranges),
705 .config = 0x8e,
706 }, 635 },
707}; 636};
708 637
709/* ------------ TUNER_PANASONIC_VP27 - Panasonic NTSC ------------ */ 638/* ------------ TUNER_PANASONIC_VP27 - Panasonic NTSC ------------ */
710 639
711static struct tuner_range tuner_panasonic_vp27_ntsc_ranges[] = { 640static struct tuner_range tuner_panasonic_vp27_ntsc_ranges[] = {
712 { 16 * 160.00 /*MHz*/, 0x01, }, 641 { 16 * 160.00 /*MHz*/, 0xce, 0x01, },
713 { 16 * 454.00 /*MHz*/, 0x02, }, 642 { 16 * 454.00 /*MHz*/, 0xce, 0x02, },
714 { 16 * 999.99 , 0x08, }, 643 { 16 * 999.99 , 0xce, 0x08, },
715}; 644};
716 645
717static struct tuner_params tuner_panasonic_vp27_params[] = { 646static struct tuner_params tuner_panasonic_vp27_params[] = {
@@ -719,33 +648,25 @@ static struct tuner_params tuner_panasonic_vp27_params[] = {
719 .type = TUNER_PARAM_TYPE_NTSC, 648 .type = TUNER_PARAM_TYPE_NTSC,
720 .ranges = tuner_panasonic_vp27_ntsc_ranges, 649 .ranges = tuner_panasonic_vp27_ntsc_ranges,
721 .count = ARRAY_SIZE(tuner_panasonic_vp27_ntsc_ranges), 650 .count = ARRAY_SIZE(tuner_panasonic_vp27_ntsc_ranges),
722 .config = 0xce,
723 }, 651 },
724}; 652};
725 653
726/* ------------ TUNER_LG_NTSC_TAPE - LGINNOTEK NTSC ------------ */ 654/* ------------ TUNER_LG_NTSC_TAPE - LGINNOTEK NTSC ------------ */
727 655
728static struct tuner_range tuner_lg_ntsc_tape_ranges[] = {
729 { 16 * 160.00 /*MHz*/, 0x01, },
730 { 16 * 442.00 /*MHz*/, 0x02, },
731 { 16 * 999.99 , 0x04, },
732};
733
734static struct tuner_params tuner_lg_ntsc_tape_params[] = { 656static struct tuner_params tuner_lg_ntsc_tape_params[] = {
735 { 657 {
736 .type = TUNER_PARAM_TYPE_NTSC, 658 .type = TUNER_PARAM_TYPE_NTSC,
737 .ranges = tuner_lg_ntsc_tape_ranges, 659 .ranges = tuner_fm1236_mk3_ntsc_ranges,
738 .count = ARRAY_SIZE(tuner_lg_ntsc_tape_ranges), 660 .count = ARRAY_SIZE(tuner_fm1236_mk3_ntsc_ranges),
739 .config = 0x8e,
740 }, 661 },
741}; 662};
742 663
743/* ------------ TUNER_TNF_8831BGFF - Philips PAL ------------ */ 664/* ------------ TUNER_TNF_8831BGFF - Philips PAL ------------ */
744 665
745static struct tuner_range tuner_tnf_8831bgff_pal_ranges[] = { 666static struct tuner_range tuner_tnf_8831bgff_pal_ranges[] = {
746 { 16 * 161.25 /*MHz*/, 0xa0, }, 667 { 16 * 161.25 /*MHz*/, 0x8e, 0xa0, },
747 { 16 * 463.25 /*MHz*/, 0x90, }, 668 { 16 * 463.25 /*MHz*/, 0x8e, 0x90, },
748 { 16 * 999.99 , 0x30, }, 669 { 16 * 999.99 , 0x8e, 0x30, },
749}; 670};
750 671
751static struct tuner_params tuner_tnf_8831bgff_params[] = { 672static struct tuner_params tuner_tnf_8831bgff_params[] = {
@@ -753,16 +674,15 @@ static struct tuner_params tuner_tnf_8831bgff_params[] = {
753 .type = TUNER_PARAM_TYPE_PAL, 674 .type = TUNER_PARAM_TYPE_PAL,
754 .ranges = tuner_tnf_8831bgff_pal_ranges, 675 .ranges = tuner_tnf_8831bgff_pal_ranges,
755 .count = ARRAY_SIZE(tuner_tnf_8831bgff_pal_ranges), 676 .count = ARRAY_SIZE(tuner_tnf_8831bgff_pal_ranges),
756 .config = 0x8e,
757 }, 677 },
758}; 678};
759 679
760/* ------------ TUNER_MICROTUNE_4042FI5 - Microtune NTSC ------------ */ 680/* ------------ TUNER_MICROTUNE_4042FI5 - Microtune NTSC ------------ */
761 681
762static struct tuner_range tuner_microtune_4042fi5_ntsc_ranges[] = { 682static struct tuner_range tuner_microtune_4042fi5_ntsc_ranges[] = {
763 { 16 * 162.00 /*MHz*/, 0xa2, }, 683 { 16 * 162.00 /*MHz*/, 0x8e, 0xa2, },
764 { 16 * 457.00 /*MHz*/, 0x94, }, 684 { 16 * 457.00 /*MHz*/, 0x8e, 0x94, },
765 { 16 * 999.99 , 0x31, }, 685 { 16 * 999.99 , 0x8e, 0x31, },
766}; 686};
767 687
768static struct tuner_params tuner_microtune_4042fi5_params[] = { 688static struct tuner_params tuner_microtune_4042fi5_params[] = {
@@ -770,7 +690,6 @@ static struct tuner_params tuner_microtune_4042fi5_params[] = {
770 .type = TUNER_PARAM_TYPE_NTSC, 690 .type = TUNER_PARAM_TYPE_NTSC,
771 .ranges = tuner_microtune_4042fi5_ntsc_ranges, 691 .ranges = tuner_microtune_4042fi5_ntsc_ranges,
772 .count = ARRAY_SIZE(tuner_microtune_4042fi5_ntsc_ranges), 692 .count = ARRAY_SIZE(tuner_microtune_4042fi5_ntsc_ranges),
773 .config = 0x8e,
774 }, 693 },
775}; 694};
776 695
@@ -778,9 +697,9 @@ static struct tuner_params tuner_microtune_4042fi5_params[] = {
778/* ------------ TUNER_TCL_2002N - TCL NTSC ------------ */ 697/* ------------ TUNER_TCL_2002N - TCL NTSC ------------ */
779 698
780static struct tuner_range tuner_tcl_2002n_ntsc_ranges[] = { 699static struct tuner_range tuner_tcl_2002n_ntsc_ranges[] = {
781 { 16 * 172.00 /*MHz*/, 0x01, }, 700 { 16 * 172.00 /*MHz*/, 0x8e, 0x01, },
782 { 16 * 448.00 /*MHz*/, 0x02, }, 701 { 16 * 448.00 /*MHz*/, 0x8e, 0x02, },
783 { 16 * 999.99 , 0x08, }, 702 { 16 * 999.99 , 0x8e, 0x08, },
784}; 703};
785 704
786static struct tuner_params tuner_tcl_2002n_params[] = { 705static struct tuner_params tuner_tcl_2002n_params[] = {
@@ -788,34 +707,26 @@ static struct tuner_params tuner_tcl_2002n_params[] = {
788 .type = TUNER_PARAM_TYPE_NTSC, 707 .type = TUNER_PARAM_TYPE_NTSC,
789 .ranges = tuner_tcl_2002n_ntsc_ranges, 708 .ranges = tuner_tcl_2002n_ntsc_ranges,
790 .count = ARRAY_SIZE(tuner_tcl_2002n_ntsc_ranges), 709 .count = ARRAY_SIZE(tuner_tcl_2002n_ntsc_ranges),
791 .config = 0x8e,
792 .cb_first_if_lower_freq = 1, 710 .cb_first_if_lower_freq = 1,
793 }, 711 },
794}; 712};
795 713
796/* ------------ TUNER_PHILIPS_FM1256_IH3 - Philips PAL ------------ */ 714/* ------------ TUNER_PHILIPS_FM1256_IH3 - Philips PAL ------------ */
797 715
798static struct tuner_range tuner_philips_fm1256_ih3_pal_ranges[] = {
799 { 16 * 160.00 /*MHz*/, 0x01, },
800 { 16 * 442.00 /*MHz*/, 0x02, },
801 { 16 * 999.99 , 0x04, },
802};
803
804static struct tuner_params tuner_philips_fm1256_ih3_params[] = { 716static struct tuner_params tuner_philips_fm1256_ih3_params[] = {
805 { 717 {
806 .type = TUNER_PARAM_TYPE_PAL, 718 .type = TUNER_PARAM_TYPE_PAL,
807 .ranges = tuner_philips_fm1256_ih3_pal_ranges, 719 .ranges = tuner_fm1236_mk3_ntsc_ranges,
808 .count = ARRAY_SIZE(tuner_philips_fm1256_ih3_pal_ranges), 720 .count = ARRAY_SIZE(tuner_fm1236_mk3_ntsc_ranges),
809 .config = 0x8e,
810 }, 721 },
811}; 722};
812 723
813/* ------------ TUNER_THOMSON_DTT7610 - THOMSON ATSC ------------ */ 724/* ------------ TUNER_THOMSON_DTT7610 - THOMSON ATSC ------------ */
814 725
815static struct tuner_range tuner_thomson_dtt7610_ntsc_ranges[] = { 726static struct tuner_range tuner_thomson_dtt7610_ntsc_ranges[] = {
816 { 16 * 157.25 /*MHz*/, 0x39, }, 727 { 16 * 157.25 /*MHz*/, 0x8e, 0x39, },
817 { 16 * 454.00 /*MHz*/, 0x3a, }, 728 { 16 * 454.00 /*MHz*/, 0x8e, 0x3a, },
818 { 16 * 999.99 , 0x3c, }, 729 { 16 * 999.99 , 0x8e, 0x3c, },
819}; 730};
820 731
821static struct tuner_params tuner_thomson_dtt7610_params[] = { 732static struct tuner_params tuner_thomson_dtt7610_params[] = {
@@ -823,16 +734,15 @@ static struct tuner_params tuner_thomson_dtt7610_params[] = {
823 .type = TUNER_PARAM_TYPE_NTSC, 734 .type = TUNER_PARAM_TYPE_NTSC,
824 .ranges = tuner_thomson_dtt7610_ntsc_ranges, 735 .ranges = tuner_thomson_dtt7610_ntsc_ranges,
825 .count = ARRAY_SIZE(tuner_thomson_dtt7610_ntsc_ranges), 736 .count = ARRAY_SIZE(tuner_thomson_dtt7610_ntsc_ranges),
826 .config = 0x8e,
827 }, 737 },
828}; 738};
829 739
830/* ------------ TUNER_PHILIPS_FQ1286 - Philips NTSC ------------ */ 740/* ------------ TUNER_PHILIPS_FQ1286 - Philips NTSC ------------ */
831 741
832static struct tuner_range tuner_philips_fq1286_ntsc_ranges[] = { 742static struct tuner_range tuner_philips_fq1286_ntsc_ranges[] = {
833 { 16 * 160.00 /*MHz*/, 0x41, }, 743 { 16 * 160.00 /*MHz*/, 0x8e, 0x41, },
834 { 16 * 454.00 /*MHz*/, 0x42, }, 744 { 16 * 454.00 /*MHz*/, 0x8e, 0x42, },
835 { 16 * 999.99 , 0x04, }, 745 { 16 * 999.99 , 0x8e, 0x04, },
836}; 746};
837 747
838static struct tuner_params tuner_philips_fq1286_params[] = { 748static struct tuner_params tuner_philips_fq1286_params[] = {
@@ -840,16 +750,15 @@ static struct tuner_params tuner_philips_fq1286_params[] = {
840 .type = TUNER_PARAM_TYPE_NTSC, 750 .type = TUNER_PARAM_TYPE_NTSC,
841 .ranges = tuner_philips_fq1286_ntsc_ranges, 751 .ranges = tuner_philips_fq1286_ntsc_ranges,
842 .count = ARRAY_SIZE(tuner_philips_fq1286_ntsc_ranges), 752 .count = ARRAY_SIZE(tuner_philips_fq1286_ntsc_ranges),
843 .config = 0x8e,
844 }, 753 },
845}; 754};
846 755
847/* ------------ TUNER_TCL_2002MB - TCL PAL ------------ */ 756/* ------------ TUNER_TCL_2002MB - TCL PAL ------------ */
848 757
849static struct tuner_range tuner_tcl_2002mb_pal_ranges[] = { 758static struct tuner_range tuner_tcl_2002mb_pal_ranges[] = {
850 { 16 * 170.00 /*MHz*/, 0x01, }, 759 { 16 * 170.00 /*MHz*/, 0xce, 0x01, },
851 { 16 * 450.00 /*MHz*/, 0x02, }, 760 { 16 * 450.00 /*MHz*/, 0xce, 0x02, },
852 { 16 * 999.99 , 0x08, }, 761 { 16 * 999.99 , 0xce, 0x08, },
853}; 762};
854 763
855static struct tuner_params tuner_tcl_2002mb_params[] = { 764static struct tuner_params tuner_tcl_2002mb_params[] = {
@@ -857,24 +766,22 @@ static struct tuner_params tuner_tcl_2002mb_params[] = {
857 .type = TUNER_PARAM_TYPE_PAL, 766 .type = TUNER_PARAM_TYPE_PAL,
858 .ranges = tuner_tcl_2002mb_pal_ranges, 767 .ranges = tuner_tcl_2002mb_pal_ranges,
859 .count = ARRAY_SIZE(tuner_tcl_2002mb_pal_ranges), 768 .count = ARRAY_SIZE(tuner_tcl_2002mb_pal_ranges),
860 .config = 0xce,
861 }, 769 },
862}; 770};
863 771
864/* ------------ TUNER_PHILIPS_FQ1216AME_MK4 - Philips PAL ------------ */ 772/* ------------ TUNER_PHILIPS_FQ1216AME_MK4 - Philips PAL ------------ */
865 773
866static struct tuner_range tuner_philips_fq12_6a___mk4_ranges[] = { 774static struct tuner_range tuner_philips_fq12_6a___mk4_pal_ranges[] = {
867 { 16 * 160.00 /*MHz*/, 0x01, }, 775 { 16 * 160.00 /*MHz*/, 0xce, 0x01, },
868 { 16 * 442.00 /*MHz*/, 0x02, }, 776 { 16 * 442.00 /*MHz*/, 0xce, 0x02, },
869 { 16 * 999.99 , 0x04, }, 777 { 16 * 999.99 , 0xce, 0x04, },
870}; 778};
871 779
872static struct tuner_params tuner_philips_fq1216ame_mk4_params[] = { 780static struct tuner_params tuner_philips_fq1216ame_mk4_params[] = {
873 { 781 {
874 .type = TUNER_PARAM_TYPE_PAL, 782 .type = TUNER_PARAM_TYPE_PAL,
875 .ranges = tuner_philips_fq12_6a___mk4_ranges, 783 .ranges = tuner_philips_fq12_6a___mk4_pal_ranges,
876 .count = ARRAY_SIZE(tuner_philips_fq12_6a___mk4_ranges), 784 .count = ARRAY_SIZE(tuner_philips_fq12_6a___mk4_pal_ranges),
877 .config = 0xce,
878 }, 785 },
879}; 786};
880 787
@@ -883,35 +790,27 @@ static struct tuner_params tuner_philips_fq1216ame_mk4_params[] = {
883static struct tuner_params tuner_philips_fq1236a_mk4_params[] = { 790static struct tuner_params tuner_philips_fq1236a_mk4_params[] = {
884 { 791 {
885 .type = TUNER_PARAM_TYPE_NTSC, 792 .type = TUNER_PARAM_TYPE_NTSC,
886 .ranges = tuner_philips_fq12_6a___mk4_ranges, 793 .ranges = tuner_fm1236_mk3_ntsc_ranges,
887 .count = ARRAY_SIZE(tuner_philips_fq12_6a___mk4_ranges), 794 .count = ARRAY_SIZE(tuner_fm1236_mk3_ntsc_ranges),
888 .config = 0x8e,
889 }, 795 },
890}; 796};
891 797
892/* ------------ TUNER_YMEC_TVF_8531MF - Philips NTSC ------------ */ 798/* ------------ TUNER_YMEC_TVF_8531MF - Philips NTSC ------------ */
893 799
894static struct tuner_range tuner_ymec_tvf_8531mf_ntsc_ranges[] = {
895 { 16 * 160.00 /*MHz*/, 0xa0, },
896 { 16 * 454.00 /*MHz*/, 0x90, },
897 { 16 * 999.99 , 0x30, },
898};
899
900static struct tuner_params tuner_ymec_tvf_8531mf_params[] = { 800static struct tuner_params tuner_ymec_tvf_8531mf_params[] = {
901 { 801 {
902 .type = TUNER_PARAM_TYPE_NTSC, 802 .type = TUNER_PARAM_TYPE_NTSC,
903 .ranges = tuner_ymec_tvf_8531mf_ntsc_ranges, 803 .ranges = tuner_philips_ntsc_m_ranges,
904 .count = ARRAY_SIZE(tuner_ymec_tvf_8531mf_ntsc_ranges), 804 .count = ARRAY_SIZE(tuner_philips_ntsc_m_ranges),
905 .config = 0x8e,
906 }, 805 },
907}; 806};
908 807
909/* ------------ TUNER_YMEC_TVF_5533MF - Philips NTSC ------------ */ 808/* ------------ TUNER_YMEC_TVF_5533MF - Philips NTSC ------------ */
910 809
911static struct tuner_range tuner_ymec_tvf_5533mf_ntsc_ranges[] = { 810static struct tuner_range tuner_ymec_tvf_5533mf_ntsc_ranges[] = {
912 { 16 * 160.00 /*MHz*/, 0x01, }, 811 { 16 * 160.00 /*MHz*/, 0x8e, 0x01, },
913 { 16 * 454.00 /*MHz*/, 0x02, }, 812 { 16 * 454.00 /*MHz*/, 0x8e, 0x02, },
914 { 16 * 999.99 , 0x04, }, 813 { 16 * 999.99 , 0x8e, 0x04, },
915}; 814};
916 815
917static struct tuner_params tuner_ymec_tvf_5533mf_params[] = { 816static struct tuner_params tuner_ymec_tvf_5533mf_params[] = {
@@ -919,7 +818,6 @@ static struct tuner_params tuner_ymec_tvf_5533mf_params[] = {
919 .type = TUNER_PARAM_TYPE_NTSC, 818 .type = TUNER_PARAM_TYPE_NTSC,
920 .ranges = tuner_ymec_tvf_5533mf_ntsc_ranges, 819 .ranges = tuner_ymec_tvf_5533mf_ntsc_ranges,
921 .count = ARRAY_SIZE(tuner_ymec_tvf_5533mf_ntsc_ranges), 820 .count = ARRAY_SIZE(tuner_ymec_tvf_5533mf_ntsc_ranges),
922 .config = 0x8e,
923 }, 821 },
924}; 822};
925 823
@@ -928,9 +826,9 @@ static struct tuner_params tuner_ymec_tvf_5533mf_params[] = {
928/* DTT 7611 7611A 7612 7613 7613A 7614 7615 7615A */ 826/* DTT 7611 7611A 7612 7613 7613A 7614 7615 7615A */
929 827
930static struct tuner_range tuner_thomson_dtt761x_ntsc_ranges[] = { 828static struct tuner_range tuner_thomson_dtt761x_ntsc_ranges[] = {
931 { 16 * 145.25 /*MHz*/, 0x39, }, 829 { 16 * 145.25 /*MHz*/, 0x8e, 0x39, },
932 { 16 * 415.25 /*MHz*/, 0x3a, }, 830 { 16 * 415.25 /*MHz*/, 0x8e, 0x3a, },
933 { 16 * 999.99 , 0x3c, }, 831 { 16 * 999.99 , 0x8e, 0x3c, },
934}; 832};
935 833
936 834
@@ -939,42 +837,39 @@ static struct tuner_params tuner_thomson_dtt761x_params[] = {
939 .type = TUNER_PARAM_TYPE_NTSC, 837 .type = TUNER_PARAM_TYPE_NTSC,
940 .ranges = tuner_thomson_dtt761x_ntsc_ranges, 838 .ranges = tuner_thomson_dtt761x_ntsc_ranges,
941 .count = ARRAY_SIZE(tuner_thomson_dtt761x_ntsc_ranges), 839 .count = ARRAY_SIZE(tuner_thomson_dtt761x_ntsc_ranges),
942 .config = 0x8e,
943 }, 840 },
944}; 841};
945 842
946/* ------------ TUNER_TENA_9533_DI - Philips PAL ------------ */ 843/* ------------ TUNER_TENA_9533_DI - Philips PAL ------------ */
947 844
948static struct tuner_range tuner_tuner_tena_9533_di_pal_ranges[] = { 845static struct tuner_range tuner_tena_9533_di_pal_ranges[] = {
949 { 16 * 160.25 /*MHz*/, 0x01, }, 846 { 16 * 160.25 /*MHz*/, 0x8e, 0x01, },
950 { 16 * 464.25 /*MHz*/, 0x02, }, 847 { 16 * 464.25 /*MHz*/, 0x8e, 0x02, },
951 { 16 * 999.99 , 0x04, }, 848 { 16 * 999.99 , 0x8e, 0x04, },
952}; 849};
953 850
954static struct tuner_params tuner_tena_9533_di_params[] = { 851static struct tuner_params tuner_tena_9533_di_params[] = {
955 { 852 {
956 .type = TUNER_PARAM_TYPE_PAL, 853 .type = TUNER_PARAM_TYPE_PAL,
957 .ranges = tuner_tuner_tena_9533_di_pal_ranges, 854 .ranges = tuner_tena_9533_di_pal_ranges,
958 .count = ARRAY_SIZE(tuner_tuner_tena_9533_di_pal_ranges), 855 .count = ARRAY_SIZE(tuner_tena_9533_di_pal_ranges),
959 .config = 0x8e,
960 }, 856 },
961}; 857};
962 858
963/* ------------ TUNER_PHILIPS_FMD1216ME_MK3 - Philips PAL ------------ */ 859/* ------------ TUNER_PHILIPS_FMD1216ME_MK3 - Philips PAL ------------ */
964 860
965static struct tuner_range tuner_philips_fmd1216me_mk3_pal_ranges[] = { 861static struct tuner_range tuner_philips_fmd1216me_mk3_pal_ranges[] = {
966 { 16 * 160.00 /*MHz*/, 0x51, }, 862 { 16 * 160.00 /*MHz*/, 0x86, 0x51, },
967 { 16 * 442.00 /*MHz*/, 0x52, }, 863 { 16 * 442.00 /*MHz*/, 0x86, 0x52, },
968 { 16 * 999.99 , 0x54, }, 864 { 16 * 999.99 , 0x86, 0x54, },
969}; 865};
970 866
971 867
972static struct tuner_params tuner_tuner_philips_fmd1216me_mk3_params[] = { 868static struct tuner_params tuner_philips_fmd1216me_mk3_params[] = {
973 { 869 {
974 .type = TUNER_PARAM_TYPE_PAL, 870 .type = TUNER_PARAM_TYPE_PAL,
975 .ranges = tuner_philips_fmd1216me_mk3_pal_ranges, 871 .ranges = tuner_philips_fmd1216me_mk3_pal_ranges,
976 .count = ARRAY_SIZE(tuner_philips_fmd1216me_mk3_pal_ranges), 872 .count = ARRAY_SIZE(tuner_philips_fmd1216me_mk3_pal_ranges),
977 .config = 0x86,
978 }, 873 },
979}; 874};
980 875
@@ -982,9 +877,9 @@ static struct tuner_params tuner_tuner_philips_fmd1216me_mk3_params[] = {
982/* ------------ TUNER_LG_TDVS_H062F - INFINEON ATSC ------------ */ 877/* ------------ TUNER_LG_TDVS_H062F - INFINEON ATSC ------------ */
983 878
984static struct tuner_range tuner_tua6034_ntsc_ranges[] = { 879static struct tuner_range tuner_tua6034_ntsc_ranges[] = {
985 { 16 * 160.00 /*MHz*/, 0x01 }, 880 { 16 * 160.00 /*MHz*/, 0x8e, 0x01 },
986 { 16 * 455.00 /*MHz*/, 0x02 }, 881 { 16 * 455.00 /*MHz*/, 0x8e, 0x02 },
987 { 16 * 999.99 , 0x04 }, 882 { 16 * 999.99 , 0x8e, 0x04 },
988}; 883};
989 884
990 885
@@ -993,50 +888,51 @@ static struct tuner_params tuner_tua6034_params[] = {
993 .type = TUNER_PARAM_TYPE_NTSC, 888 .type = TUNER_PARAM_TYPE_NTSC,
994 .ranges = tuner_tua6034_ntsc_ranges, 889 .ranges = tuner_tua6034_ntsc_ranges,
995 .count = ARRAY_SIZE(tuner_tua6034_ntsc_ranges), 890 .count = ARRAY_SIZE(tuner_tua6034_ntsc_ranges),
996 .config = 0x8e,
997 }, 891 },
998}; 892};
999 893
1000/* ------------ TUNER_YMEC_TVF66T5_B_DFF - Philips PAL ------------ */ 894/* ------------ TUNER_YMEC_TVF66T5_B_DFF - Philips PAL ------------ */
1001 895
1002static struct tuner_range tuner_ymec_tvf66t5_b_dff_pal_ranges[] = {
1003 { 16 * 160.25 /*MHz*/, 0x01, },
1004 { 16 * 464.25 /*MHz*/, 0x02, },
1005 { 16 * 999.99 , 0x08, },
1006};
1007
1008static struct tuner_params tuner_ymec_tvf66t5_b_dff_params[] = { 896static struct tuner_params tuner_ymec_tvf66t5_b_dff_params[] = {
1009 { 897 {
1010 .type = TUNER_PARAM_TYPE_PAL, 898 .type = TUNER_PARAM_TYPE_PAL,
1011 .ranges = tuner_ymec_tvf66t5_b_dff_pal_ranges, 899 .ranges = tuner_tena_9533_di_pal_ranges,
1012 .count = ARRAY_SIZE(tuner_ymec_tvf66t5_b_dff_pal_ranges), 900 .count = ARRAY_SIZE(tuner_tena_9533_di_pal_ranges),
1013 .config = 0x8e,
1014 }, 901 },
1015}; 902};
1016 903
1017/* ------------ TUNER_LG_NTSC_TALN_MINI - LGINNOTEK NTSC ------------ */ 904/* ------------ TUNER_LG_NTSC_TALN_MINI - LGINNOTEK NTSC ------------ */
1018 905
1019static struct tuner_range tuner_lg_taln_mini_ntsc_ranges[] = { 906static struct tuner_range tuner_lg_taln_ntsc_ranges[] = {
1020 { 16 * 137.25 /*MHz*/, 0x01, }, 907 { 16 * 137.25 /*MHz*/, 0x8e, 0x01, },
1021 { 16 * 373.25 /*MHz*/, 0x02, }, 908 { 16 * 373.25 /*MHz*/, 0x8e, 0x02, },
1022 { 16 * 999.99 , 0x08, }, 909 { 16 * 999.99 , 0x8e, 0x08, },
910};
911
912static struct tuner_range tuner_lg_taln_pal_secam_ranges[] = {
913 { 16 * 150.00 /*MHz*/, 0x8e, 0x01, },
914 { 16 * 425.00 /*MHz*/, 0x8e, 0x02, },
915 { 16 * 999.99 , 0x8e, 0x08, },
1023}; 916};
1024 917
1025static struct tuner_params tuner_lg_taln_mini_params[] = { 918static struct tuner_params tuner_lg_taln_params[] = {
1026 { 919 {
1027 .type = TUNER_PARAM_TYPE_NTSC, 920 .type = TUNER_PARAM_TYPE_NTSC,
1028 .ranges = tuner_lg_taln_mini_ntsc_ranges, 921 .ranges = tuner_lg_taln_ntsc_ranges,
1029 .count = ARRAY_SIZE(tuner_lg_taln_mini_ntsc_ranges), 922 .count = ARRAY_SIZE(tuner_lg_taln_ntsc_ranges),
1030 .config = 0x8e, 923 },{
924 .type = TUNER_PARAM_TYPE_PAL,
925 .ranges = tuner_lg_taln_pal_secam_ranges,
926 .count = ARRAY_SIZE(tuner_lg_taln_pal_secam_ranges),
1031 }, 927 },
1032}; 928};
1033 929
1034/* ------------ TUNER_PHILIPS_TD1316 - Philips PAL ------------ */ 930/* ------------ TUNER_PHILIPS_TD1316 - Philips PAL ------------ */
1035 931
1036static struct tuner_range tuner_philips_td1316_pal_ranges[] = { 932static struct tuner_range tuner_philips_td1316_pal_ranges[] = {
1037 { 16 * 160.00 /*MHz*/, 0xa1, }, 933 { 16 * 160.00 /*MHz*/, 0xc8, 0xa1, },
1038 { 16 * 442.00 /*MHz*/, 0xa2, }, 934 { 16 * 442.00 /*MHz*/, 0xc8, 0xa2, },
1039 { 16 * 999.99 , 0xa4, }, 935 { 16 * 999.99 , 0xc8, 0xa4, },
1040}; 936};
1041 937
1042static struct tuner_params tuner_philips_td1316_params[] = { 938static struct tuner_params tuner_philips_td1316_params[] = {
@@ -1044,34 +940,42 @@ static struct tuner_params tuner_philips_td1316_params[] = {
1044 .type = TUNER_PARAM_TYPE_PAL, 940 .type = TUNER_PARAM_TYPE_PAL,
1045 .ranges = tuner_philips_td1316_pal_ranges, 941 .ranges = tuner_philips_td1316_pal_ranges,
1046 .count = ARRAY_SIZE(tuner_philips_td1316_pal_ranges), 942 .count = ARRAY_SIZE(tuner_philips_td1316_pal_ranges),
1047 .config = 0xc8,
1048 }, 943 },
1049}; 944};
1050 945
1051/* ------------ TUNER_PHILIPS_TUV1236D - Philips ATSC ------------ */ 946/* ------------ TUNER_PHILIPS_TUV1236D - Philips ATSC ------------ */
1052 947
1053static struct tuner_range tuner_tuv1236d_ntsc_ranges[] = { 948static struct tuner_range tuner_tuv1236d_ntsc_ranges[] = {
1054 { 16 * 157.25 /*MHz*/, 0x01, }, 949 { 16 * 157.25 /*MHz*/, 0xce, 0x01, },
1055 { 16 * 454.00 /*MHz*/, 0x02, }, 950 { 16 * 454.00 /*MHz*/, 0xce, 0x02, },
1056 { 16 * 999.99 , 0x04, }, 951 { 16 * 999.99 , 0xce, 0x04, },
1057}; 952};
1058 953
1059 954
1060static struct tuner_params tuner_tuner_tuv1236d_params[] = { 955static struct tuner_params tuner_tuv1236d_params[] = {
1061 { 956 {
1062 .type = TUNER_PARAM_TYPE_NTSC, 957 .type = TUNER_PARAM_TYPE_NTSC,
1063 .ranges = tuner_tuv1236d_ntsc_ranges, 958 .ranges = tuner_tuv1236d_ntsc_ranges,
1064 .count = ARRAY_SIZE(tuner_tuv1236d_ntsc_ranges), 959 .count = ARRAY_SIZE(tuner_tuv1236d_ntsc_ranges),
1065 .config = 0xce,
1066 }, 960 },
1067}; 961};
1068 962
1069/* ------------ TUNER_TNF_5335MF - Philips NTSC ------------ */ 963/* ------------ TUNER_TNF_xxx5 - Texas Instruments--------- */
964/* This is known to work with Tenna TVF58t5-MFF and TVF5835 MFF
965 * but it is expected to work also with other Tenna/Ymec
966 * models based on TI SN 761677 chip on both PAL and NTSC
967 */
968
969static struct tuner_range tuner_tnf_5335_d_if_pal_ranges[] = {
970 { 16 * 168.25 /*MHz*/, 0x8e, 0x01, },
971 { 16 * 471.25 /*MHz*/, 0x8e, 0x02, },
972 { 16 * 999.99 , 0x8e, 0x08, },
973};
1070 974
1071static struct tuner_range tuner_tnf_5335mf_ntsc_ranges[] = { 975static struct tuner_range tuner_tnf_5335mf_ntsc_ranges[] = {
1072 { 16 * 157.25 /*MHz*/, 0x01, }, 976 { 16 * 169.25 /*MHz*/, 0x8e, 0x01, },
1073 { 16 * 454.00 /*MHz*/, 0x02, }, 977 { 16 * 469.25 /*MHz*/, 0x8e, 0x02, },
1074 { 16 * 999.99 , 0x04, }, 978 { 16 * 999.99 , 0x8e, 0x08, },
1075}; 979};
1076 980
1077static struct tuner_params tuner_tnf_5335mf_params[] = { 981static struct tuner_params tuner_tnf_5335mf_params[] = {
@@ -1079,7 +983,11 @@ static struct tuner_params tuner_tnf_5335mf_params[] = {
1079 .type = TUNER_PARAM_TYPE_NTSC, 983 .type = TUNER_PARAM_TYPE_NTSC,
1080 .ranges = tuner_tnf_5335mf_ntsc_ranges, 984 .ranges = tuner_tnf_5335mf_ntsc_ranges,
1081 .count = ARRAY_SIZE(tuner_tnf_5335mf_ntsc_ranges), 985 .count = ARRAY_SIZE(tuner_tnf_5335mf_ntsc_ranges),
1082 .config = 0x8e, 986 },
987 {
988 .type = TUNER_PARAM_TYPE_PAL,
989 .ranges = tuner_tnf_5335_d_if_pal_ranges,
990 .count = ARRAY_SIZE(tuner_tnf_5335_d_if_pal_ranges),
1083 }, 991 },
1084}; 992};
1085 993
@@ -1087,9 +995,9 @@ static struct tuner_params tuner_tnf_5335mf_params[] = {
1087/* ------------ TUNER_SAMSUNG_TCPN_2121P30A - Samsung NTSC ------------ */ 995/* ------------ TUNER_SAMSUNG_TCPN_2121P30A - Samsung NTSC ------------ */
1088 996
1089static struct tuner_range tuner_samsung_tcpn_2121p30a_ntsc_ranges[] = { 997static struct tuner_range tuner_samsung_tcpn_2121p30a_ntsc_ranges[] = {
1090 { 16 * 175.75 /*MHz*/, 0x01, }, 998 { 16 * 130.00 /*MHz*/, 0xce, 0x01, },
1091 { 16 * 410.25 /*MHz*/, 0x02, }, 999 { 16 * 364.50 /*MHz*/, 0xce, 0x02, },
1092 { 16 * 999.99 , 0x08, }, 1000 { 16 * 999.99 , 0xce, 0x08, },
1093}; 1001};
1094 1002
1095static struct tuner_params tuner_samsung_tcpn_2121p30a_params[] = { 1003static struct tuner_params tuner_samsung_tcpn_2121p30a_params[] = {
@@ -1097,7 +1005,22 @@ static struct tuner_params tuner_samsung_tcpn_2121p30a_params[] = {
1097 .type = TUNER_PARAM_TYPE_NTSC, 1005 .type = TUNER_PARAM_TYPE_NTSC,
1098 .ranges = tuner_samsung_tcpn_2121p30a_ntsc_ranges, 1006 .ranges = tuner_samsung_tcpn_2121p30a_ntsc_ranges,
1099 .count = ARRAY_SIZE(tuner_samsung_tcpn_2121p30a_ntsc_ranges), 1007 .count = ARRAY_SIZE(tuner_samsung_tcpn_2121p30a_ntsc_ranges),
1100 .config = 0xce, 1008 },
1009};
1010
1011/* ------------ TUNER_THOMSON_FE6600 - DViCO Hybrid PAL ------------ */
1012
1013static struct tuner_range tuner_thomson_fe6600_ranges[] = {
1014 { 16 * 160.00 /*MHz*/, 0xfe, 0x11, },
1015 { 16 * 442.00 /*MHz*/, 0xf6, 0x12, },
1016 { 16 * 999.99 , 0xf6, 0x18, },
1017};
1018
1019static struct tuner_params tuner_thomson_fe6600_params[] = {
1020 {
1021 .type = TUNER_PARAM_TYPE_PAL,
1022 .ranges = tuner_thomson_fe6600_ranges,
1023 .count = ARRAY_SIZE(tuner_thomson_fe6600_ranges),
1101 }, 1024 },
1102}; 1025};
1103 1026
@@ -1108,18 +1031,22 @@ struct tunertype tuners[] = {
1108 [TUNER_TEMIC_PAL] = { /* TEMIC PAL */ 1031 [TUNER_TEMIC_PAL] = { /* TEMIC PAL */
1109 .name = "Temic PAL (4002 FH5)", 1032 .name = "Temic PAL (4002 FH5)",
1110 .params = tuner_temic_pal_params, 1033 .params = tuner_temic_pal_params,
1034 .count = ARRAY_SIZE(tuner_temic_pal_params),
1111 }, 1035 },
1112 [TUNER_PHILIPS_PAL_I] = { /* Philips PAL_I */ 1036 [TUNER_PHILIPS_PAL_I] = { /* Philips PAL_I */
1113 .name = "Philips PAL_I (FI1246 and compatibles)", 1037 .name = "Philips PAL_I (FI1246 and compatibles)",
1114 .params = tuner_philips_pal_i_params, 1038 .params = tuner_philips_pal_i_params,
1039 .count = ARRAY_SIZE(tuner_philips_pal_i_params),
1115 }, 1040 },
1116 [TUNER_PHILIPS_NTSC] = { /* Philips NTSC */ 1041 [TUNER_PHILIPS_NTSC] = { /* Philips NTSC */
1117 .name = "Philips NTSC (FI1236,FM1236 and compatibles)", 1042 .name = "Philips NTSC (FI1236,FM1236 and compatibles)",
1118 .params = tuner_philips_ntsc_params, 1043 .params = tuner_philips_ntsc_params,
1044 .count = ARRAY_SIZE(tuner_philips_ntsc_params),
1119 }, 1045 },
1120 [TUNER_PHILIPS_SECAM] = { /* Philips SECAM */ 1046 [TUNER_PHILIPS_SECAM] = { /* Philips SECAM */
1121 .name = "Philips (SECAM+PAL_BG) (FI1216MF, FM1216MF, FR1216MF)", 1047 .name = "Philips (SECAM+PAL_BG) (FI1216MF, FM1216MF, FR1216MF)",
1122 .params = tuner_philips_secam_params, 1048 .params = tuner_philips_secam_params,
1049 .count = ARRAY_SIZE(tuner_philips_secam_params),
1123 }, 1050 },
1124 [TUNER_ABSENT] = { /* Tuner Absent */ 1051 [TUNER_ABSENT] = { /* Tuner Absent */
1125 .name = "NoTuner", 1052 .name = "NoTuner",
@@ -1127,120 +1054,148 @@ struct tunertype tuners[] = {
1127 [TUNER_PHILIPS_PAL] = { /* Philips PAL */ 1054 [TUNER_PHILIPS_PAL] = { /* Philips PAL */
1128 .name = "Philips PAL_BG (FI1216 and compatibles)", 1055 .name = "Philips PAL_BG (FI1216 and compatibles)",
1129 .params = tuner_philips_pal_params, 1056 .params = tuner_philips_pal_params,
1057 .count = ARRAY_SIZE(tuner_philips_pal_params),
1130 }, 1058 },
1131 [TUNER_TEMIC_NTSC] = { /* TEMIC NTSC */ 1059 [TUNER_TEMIC_NTSC] = { /* TEMIC NTSC */
1132 .name = "Temic NTSC (4032 FY5)", 1060 .name = "Temic NTSC (4032 FY5)",
1133 .params = tuner_temic_ntsc_params, 1061 .params = tuner_temic_ntsc_params,
1062 .count = ARRAY_SIZE(tuner_temic_ntsc_params),
1134 }, 1063 },
1135 [TUNER_TEMIC_PAL_I] = { /* TEMIC PAL_I */ 1064 [TUNER_TEMIC_PAL_I] = { /* TEMIC PAL_I */
1136 .name = "Temic PAL_I (4062 FY5)", 1065 .name = "Temic PAL_I (4062 FY5)",
1137 .params = tuner_temic_pal_i_params, 1066 .params = tuner_temic_pal_i_params,
1067 .count = ARRAY_SIZE(tuner_temic_pal_i_params),
1138 }, 1068 },
1139 [TUNER_TEMIC_4036FY5_NTSC] = { /* TEMIC NTSC */ 1069 [TUNER_TEMIC_4036FY5_NTSC] = { /* TEMIC NTSC */
1140 .name = "Temic NTSC (4036 FY5)", 1070 .name = "Temic NTSC (4036 FY5)",
1141 .params = tuner_temic_4036fy5_ntsc_params, 1071 .params = tuner_temic_4036fy5_ntsc_params,
1072 .count = ARRAY_SIZE(tuner_temic_4036fy5_ntsc_params),
1142 }, 1073 },
1143 [TUNER_ALPS_TSBH1_NTSC] = { /* TEMIC NTSC */ 1074 [TUNER_ALPS_TSBH1_NTSC] = { /* TEMIC NTSC */
1144 .name = "Alps HSBH1", 1075 .name = "Alps HSBH1",
1145 .params = tuner_alps_tsbh1_ntsc_params, 1076 .params = tuner_alps_tsbh1_ntsc_params,
1077 .count = ARRAY_SIZE(tuner_alps_tsbh1_ntsc_params),
1146 }, 1078 },
1147 1079
1148 /* 10-19 */ 1080 /* 10-19 */
1149 [TUNER_ALPS_TSBE1_PAL] = { /* TEMIC PAL */ 1081 [TUNER_ALPS_TSBE1_PAL] = { /* TEMIC PAL */
1150 .name = "Alps TSBE1", 1082 .name = "Alps TSBE1",
1151 .params = tuner_alps_tsb_1_params, 1083 .params = tuner_alps_tsb_1_params,
1084 .count = ARRAY_SIZE(tuner_alps_tsb_1_params),
1152 }, 1085 },
1153 [TUNER_ALPS_TSBB5_PAL_I] = { /* Alps PAL_I */ 1086 [TUNER_ALPS_TSBB5_PAL_I] = { /* Alps PAL_I */
1154 .name = "Alps TSBB5", 1087 .name = "Alps TSBB5",
1155 .params = tuner_alps_tsbb5_params, 1088 .params = tuner_alps_tsbb5_params,
1089 .count = ARRAY_SIZE(tuner_alps_tsbb5_params),
1156 }, 1090 },
1157 [TUNER_ALPS_TSBE5_PAL] = { /* Alps PAL */ 1091 [TUNER_ALPS_TSBE5_PAL] = { /* Alps PAL */
1158 .name = "Alps TSBE5", 1092 .name = "Alps TSBE5",
1159 .params = tuner_alps_tsbe5_params, 1093 .params = tuner_alps_tsbe5_params,
1094 .count = ARRAY_SIZE(tuner_alps_tsbe5_params),
1160 }, 1095 },
1161 [TUNER_ALPS_TSBC5_PAL] = { /* Alps PAL */ 1096 [TUNER_ALPS_TSBC5_PAL] = { /* Alps PAL */
1162 .name = "Alps TSBC5", 1097 .name = "Alps TSBC5",
1163 .params = tuner_alps_tsbc5_params, 1098 .params = tuner_alps_tsbc5_params,
1099 .count = ARRAY_SIZE(tuner_alps_tsbc5_params),
1164 }, 1100 },
1165 [TUNER_TEMIC_4006FH5_PAL] = { /* TEMIC PAL */ 1101 [TUNER_TEMIC_4006FH5_PAL] = { /* TEMIC PAL */
1166 .name = "Temic PAL_BG (4006FH5)", 1102 .name = "Temic PAL_BG (4006FH5)",
1167 .params = tuner_temic_4006fh5_params, 1103 .params = tuner_temic_4006fh5_params,
1104 .count = ARRAY_SIZE(tuner_temic_4006fh5_params),
1168 }, 1105 },
1169 [TUNER_ALPS_TSHC6_NTSC] = { /* Alps NTSC */ 1106 [TUNER_ALPS_TSHC6_NTSC] = { /* Alps NTSC */
1170 .name = "Alps TSCH6", 1107 .name = "Alps TSCH6",
1171 .params = tuner_alps_tshc6_params, 1108 .params = tuner_alps_tshc6_params,
1109 .count = ARRAY_SIZE(tuner_alps_tshc6_params),
1172 }, 1110 },
1173 [TUNER_TEMIC_PAL_DK] = { /* TEMIC PAL */ 1111 [TUNER_TEMIC_PAL_DK] = { /* TEMIC PAL */
1174 .name = "Temic PAL_DK (4016 FY5)", 1112 .name = "Temic PAL_DK (4016 FY5)",
1175 .params = tuner_temic_pal_dk_params, 1113 .params = tuner_temic_pal_dk_params,
1114 .count = ARRAY_SIZE(tuner_temic_pal_dk_params),
1176 }, 1115 },
1177 [TUNER_PHILIPS_NTSC_M] = { /* Philips NTSC */ 1116 [TUNER_PHILIPS_NTSC_M] = { /* Philips NTSC */
1178 .name = "Philips NTSC_M (MK2)", 1117 .name = "Philips NTSC_M (MK2)",
1179 .params = tuner_philips_ntsc_m_params, 1118 .params = tuner_philips_ntsc_m_params,
1119 .count = ARRAY_SIZE(tuner_philips_ntsc_m_params),
1180 }, 1120 },
1181 [TUNER_TEMIC_4066FY5_PAL_I] = { /* TEMIC PAL_I */ 1121 [TUNER_TEMIC_4066FY5_PAL_I] = { /* TEMIC PAL_I */
1182 .name = "Temic PAL_I (4066 FY5)", 1122 .name = "Temic PAL_I (4066 FY5)",
1183 .params = tuner_temic_4066fy5_pal_i_params, 1123 .params = tuner_temic_4066fy5_pal_i_params,
1124 .count = ARRAY_SIZE(tuner_temic_4066fy5_pal_i_params),
1184 }, 1125 },
1185 [TUNER_TEMIC_4006FN5_MULTI_PAL] = { /* TEMIC PAL */ 1126 [TUNER_TEMIC_4006FN5_MULTI_PAL] = { /* TEMIC PAL */
1186 .name = "Temic PAL* auto (4006 FN5)", 1127 .name = "Temic PAL* auto (4006 FN5)",
1187 .params = tuner_temic_4006fn5_multi_params, 1128 .params = tuner_temic_4006fn5_multi_params,
1129 .count = ARRAY_SIZE(tuner_temic_4006fn5_multi_params),
1188 }, 1130 },
1189 1131
1190 /* 20-29 */ 1132 /* 20-29 */
1191 [TUNER_TEMIC_4009FR5_PAL] = { /* TEMIC PAL */ 1133 [TUNER_TEMIC_4009FR5_PAL] = { /* TEMIC PAL */
1192 .name = "Temic PAL_BG (4009 FR5) or PAL_I (4069 FR5)", 1134 .name = "Temic PAL_BG (4009 FR5) or PAL_I (4069 FR5)",
1193 .params = tuner_temic_4009f_5_params, 1135 .params = tuner_temic_4009f_5_params,
1136 .count = ARRAY_SIZE(tuner_temic_4009f_5_params),
1194 }, 1137 },
1195 [TUNER_TEMIC_4039FR5_NTSC] = { /* TEMIC NTSC */ 1138 [TUNER_TEMIC_4039FR5_NTSC] = { /* TEMIC NTSC */
1196 .name = "Temic NTSC (4039 FR5)", 1139 .name = "Temic NTSC (4039 FR5)",
1197 .params = tuner_temic_4039fr5_params, 1140 .params = tuner_temic_4039fr5_params,
1141 .count = ARRAY_SIZE(tuner_temic_4039fr5_params),
1198 }, 1142 },
1199 [TUNER_TEMIC_4046FM5] = { /* TEMIC PAL */ 1143 [TUNER_TEMIC_4046FM5] = { /* TEMIC PAL */
1200 .name = "Temic PAL/SECAM multi (4046 FM5)", 1144 .name = "Temic PAL/SECAM multi (4046 FM5)",
1201 .params = tuner_temic_4046fm5_params, 1145 .params = tuner_temic_4046fm5_params,
1146 .count = ARRAY_SIZE(tuner_temic_4046fm5_params),
1202 }, 1147 },
1203 [TUNER_PHILIPS_PAL_DK] = { /* Philips PAL */ 1148 [TUNER_PHILIPS_PAL_DK] = { /* Philips PAL */
1204 .name = "Philips PAL_DK (FI1256 and compatibles)", 1149 .name = "Philips PAL_DK (FI1256 and compatibles)",
1205 .params = tuner_philips_pal_dk_params, 1150 .params = tuner_philips_pal_dk_params,
1151 .count = ARRAY_SIZE(tuner_philips_pal_dk_params),
1206 }, 1152 },
1207 [TUNER_PHILIPS_FQ1216ME] = { /* Philips PAL */ 1153 [TUNER_PHILIPS_FQ1216ME] = { /* Philips PAL */
1208 .name = "Philips PAL/SECAM multi (FQ1216ME)", 1154 .name = "Philips PAL/SECAM multi (FQ1216ME)",
1209 .params = tuner_philips_fq1216me_params, 1155 .params = tuner_philips_fq1216me_params,
1156 .count = ARRAY_SIZE(tuner_philips_fq1216me_params),
1210 }, 1157 },
1211 [TUNER_LG_PAL_I_FM] = { /* LGINNOTEK PAL_I */ 1158 [TUNER_LG_PAL_I_FM] = { /* LGINNOTEK PAL_I */
1212 .name = "LG PAL_I+FM (TAPC-I001D)", 1159 .name = "LG PAL_I+FM (TAPC-I001D)",
1213 .params = tuner_lg_pal_i_fm_params, 1160 .params = tuner_lg_pal_i_fm_params,
1161 .count = ARRAY_SIZE(tuner_lg_pal_i_fm_params),
1214 }, 1162 },
1215 [TUNER_LG_PAL_I] = { /* LGINNOTEK PAL_I */ 1163 [TUNER_LG_PAL_I] = { /* LGINNOTEK PAL_I */
1216 .name = "LG PAL_I (TAPC-I701D)", 1164 .name = "LG PAL_I (TAPC-I701D)",
1217 .params = tuner_lg_pal_i_params, 1165 .params = tuner_lg_pal_i_params,
1166 .count = ARRAY_SIZE(tuner_lg_pal_i_params),
1218 }, 1167 },
1219 [TUNER_LG_NTSC_FM] = { /* LGINNOTEK NTSC */ 1168 [TUNER_LG_NTSC_FM] = { /* LGINNOTEK NTSC */
1220 .name = "LG NTSC+FM (TPI8NSR01F)", 1169 .name = "LG NTSC+FM (TPI8NSR01F)",
1221 .params = tuner_lg_ntsc_fm_params, 1170 .params = tuner_lg_ntsc_fm_params,
1171 .count = ARRAY_SIZE(tuner_lg_ntsc_fm_params),
1222 }, 1172 },
1223 [TUNER_LG_PAL_FM] = { /* LGINNOTEK PAL */ 1173 [TUNER_LG_PAL_FM] = { /* LGINNOTEK PAL */
1224 .name = "LG PAL_BG+FM (TPI8PSB01D)", 1174 .name = "LG PAL_BG+FM (TPI8PSB01D)",
1225 .params = tuner_lg_pal_fm_params, 1175 .params = tuner_lg_pal_fm_params,
1176 .count = ARRAY_SIZE(tuner_lg_pal_fm_params),
1226 }, 1177 },
1227 [TUNER_LG_PAL] = { /* LGINNOTEK PAL */ 1178 [TUNER_LG_PAL] = { /* LGINNOTEK PAL */
1228 .name = "LG PAL_BG (TPI8PSB11D)", 1179 .name = "LG PAL_BG (TPI8PSB11D)",
1229 .params = tuner_lg_pal_params, 1180 .params = tuner_lg_pal_params,
1181 .count = ARRAY_SIZE(tuner_lg_pal_params),
1230 }, 1182 },
1231 1183
1232 /* 30-39 */ 1184 /* 30-39 */
1233 [TUNER_TEMIC_4009FN5_MULTI_PAL_FM] = { /* TEMIC PAL */ 1185 [TUNER_TEMIC_4009FN5_MULTI_PAL_FM] = { /* TEMIC PAL */
1234 .name = "Temic PAL* auto + FM (4009 FN5)", 1186 .name = "Temic PAL* auto + FM (4009 FN5)",
1235 .params = tuner_temic_4009_fn5_multi_pal_fm_params, 1187 .params = tuner_temic_4009_fn5_multi_pal_fm_params,
1188 .count = ARRAY_SIZE(tuner_temic_4009_fn5_multi_pal_fm_params),
1236 }, 1189 },
1237 [TUNER_SHARP_2U5JF5540_NTSC] = { /* SHARP NTSC */ 1190 [TUNER_SHARP_2U5JF5540_NTSC] = { /* SHARP NTSC */
1238 .name = "SHARP NTSC_JP (2U5JF5540)", 1191 .name = "SHARP NTSC_JP (2U5JF5540)",
1239 .params = tuner_sharp_2u5jf5540_params, 1192 .params = tuner_sharp_2u5jf5540_params,
1193 .count = ARRAY_SIZE(tuner_sharp_2u5jf5540_params),
1240 }, 1194 },
1241 [TUNER_Samsung_PAL_TCPM9091PD27] = { /* Samsung PAL */ 1195 [TUNER_Samsung_PAL_TCPM9091PD27] = { /* Samsung PAL */
1242 .name = "Samsung PAL TCPM9091PD27", 1196 .name = "Samsung PAL TCPM9091PD27",
1243 .params = tuner_samsung_pal_tcpm9091pd27_params, 1197 .params = tuner_samsung_pal_tcpm9091pd27_params,
1198 .count = ARRAY_SIZE(tuner_samsung_pal_tcpm9091pd27_params),
1244 }, 1199 },
1245 [TUNER_MT2032] = { /* Microtune PAL|NTSC */ 1200 [TUNER_MT2032] = { /* Microtune PAL|NTSC */
1246 .name = "MT20xx universal", 1201 .name = "MT20xx universal",
@@ -1248,86 +1203,106 @@ struct tunertype tuners[] = {
1248 [TUNER_TEMIC_4106FH5] = { /* TEMIC PAL */ 1203 [TUNER_TEMIC_4106FH5] = { /* TEMIC PAL */
1249 .name = "Temic PAL_BG (4106 FH5)", 1204 .name = "Temic PAL_BG (4106 FH5)",
1250 .params = tuner_temic_4106fh5_params, 1205 .params = tuner_temic_4106fh5_params,
1206 .count = ARRAY_SIZE(tuner_temic_4106fh5_params),
1251 }, 1207 },
1252 [TUNER_TEMIC_4012FY5] = { /* TEMIC PAL */ 1208 [TUNER_TEMIC_4012FY5] = { /* TEMIC PAL */
1253 .name = "Temic PAL_DK/SECAM_L (4012 FY5)", 1209 .name = "Temic PAL_DK/SECAM_L (4012 FY5)",
1254 .params = tuner_temic_4012fy5_params, 1210 .params = tuner_temic_4012fy5_params,
1211 .count = ARRAY_SIZE(tuner_temic_4012fy5_params),
1255 }, 1212 },
1256 [TUNER_TEMIC_4136FY5] = { /* TEMIC NTSC */ 1213 [TUNER_TEMIC_4136FY5] = { /* TEMIC NTSC */
1257 .name = "Temic NTSC (4136 FY5)", 1214 .name = "Temic NTSC (4136 FY5)",
1258 .params = tuner_temic_4136_fy5_params, 1215 .params = tuner_temic_4136_fy5_params,
1216 .count = ARRAY_SIZE(tuner_temic_4136_fy5_params),
1259 }, 1217 },
1260 [TUNER_LG_PAL_NEW_TAPC] = { /* LGINNOTEK PAL */ 1218 [TUNER_LG_PAL_NEW_TAPC] = { /* LGINNOTEK PAL */
1261 .name = "LG PAL (newer TAPC series)", 1219 .name = "LG PAL (newer TAPC series)",
1262 .params = tuner_lg_pal_new_tapc_params, 1220 .params = tuner_lg_pal_new_tapc_params,
1221 .count = ARRAY_SIZE(tuner_lg_pal_new_tapc_params),
1263 }, 1222 },
1264 [TUNER_PHILIPS_FM1216ME_MK3] = { /* Philips PAL */ 1223 [TUNER_PHILIPS_FM1216ME_MK3] = { /* Philips PAL */
1265 .name = "Philips PAL/SECAM multi (FM1216ME MK3)", 1224 .name = "Philips PAL/SECAM multi (FM1216ME MK3)",
1266 .params = tuner_fm1216me_mk3_params, 1225 .params = tuner_fm1216me_mk3_params,
1226 .count = ARRAY_SIZE(tuner_fm1216me_mk3_params),
1267 }, 1227 },
1268 [TUNER_LG_NTSC_NEW_TAPC] = { /* LGINNOTEK NTSC */ 1228 [TUNER_LG_NTSC_NEW_TAPC] = { /* LGINNOTEK NTSC */
1269 .name = "LG NTSC (newer TAPC series)", 1229 .name = "LG NTSC (newer TAPC series)",
1270 .params = tuner_lg_ntsc_new_tapc_params, 1230 .params = tuner_lg_ntsc_new_tapc_params,
1231 .count = ARRAY_SIZE(tuner_lg_ntsc_new_tapc_params),
1271 }, 1232 },
1272 1233
1273 /* 40-49 */ 1234 /* 40-49 */
1274 [TUNER_HITACHI_NTSC] = { /* HITACHI NTSC */ 1235 [TUNER_HITACHI_NTSC] = { /* HITACHI NTSC */
1275 .name = "HITACHI V7-J180AT", 1236 .name = "HITACHI V7-J180AT",
1276 .params = tuner_hitachi_ntsc_params, 1237 .params = tuner_hitachi_ntsc_params,
1238 .count = ARRAY_SIZE(tuner_hitachi_ntsc_params),
1277 }, 1239 },
1278 [TUNER_PHILIPS_PAL_MK] = { /* Philips PAL */ 1240 [TUNER_PHILIPS_PAL_MK] = { /* Philips PAL */
1279 .name = "Philips PAL_MK (FI1216 MK)", 1241 .name = "Philips PAL_MK (FI1216 MK)",
1280 .params = tuner_philips_pal_mk_params, 1242 .params = tuner_philips_pal_mk_params,
1243 .count = ARRAY_SIZE(tuner_philips_pal_mk_params),
1281 }, 1244 },
1282 [TUNER_PHILIPS_ATSC] = { /* Philips ATSC */ 1245 [TUNER_PHILIPS_ATSC] = { /* Philips ATSC */
1283 .name = "Philips 1236D ATSC/NTSC dual in", 1246 .name = "Philips 1236D ATSC/NTSC dual in",
1284 .params = tuner_philips_atsc_params, 1247 .params = tuner_philips_atsc_params,
1248 .count = ARRAY_SIZE(tuner_philips_atsc_params),
1285 }, 1249 },
1286 [TUNER_PHILIPS_FM1236_MK3] = { /* Philips NTSC */ 1250 [TUNER_PHILIPS_FM1236_MK3] = { /* Philips NTSC */
1287 .name = "Philips NTSC MK3 (FM1236MK3 or FM1236/F)", 1251 .name = "Philips NTSC MK3 (FM1236MK3 or FM1236/F)",
1288 .params = tuner_fm1236_mk3_params, 1252 .params = tuner_fm1236_mk3_params,
1253 .count = ARRAY_SIZE(tuner_fm1236_mk3_params),
1289 }, 1254 },
1290 [TUNER_PHILIPS_4IN1] = { /* Philips NTSC */ 1255 [TUNER_PHILIPS_4IN1] = { /* Philips NTSC */
1291 .name = "Philips 4 in 1 (ATI TV Wonder Pro/Conexant)", 1256 .name = "Philips 4 in 1 (ATI TV Wonder Pro/Conexant)",
1292 .params = tuner_philips_4in1_params, 1257 .params = tuner_philips_4in1_params,
1258 .count = ARRAY_SIZE(tuner_philips_4in1_params),
1293 }, 1259 },
1294 [TUNER_MICROTUNE_4049FM5] = { /* Microtune PAL */ 1260 [TUNER_MICROTUNE_4049FM5] = { /* Microtune PAL */
1295 .name = "Microtune 4049 FM5", 1261 .name = "Microtune 4049 FM5",
1296 .params = tuner_microtune_4049_fm5_params, 1262 .params = tuner_microtune_4049_fm5_params,
1263 .count = ARRAY_SIZE(tuner_microtune_4049_fm5_params),
1297 }, 1264 },
1298 [TUNER_PANASONIC_VP27] = { /* Panasonic NTSC */ 1265 [TUNER_PANASONIC_VP27] = { /* Panasonic NTSC */
1299 .name = "Panasonic VP27s/ENGE4324D", 1266 .name = "Panasonic VP27s/ENGE4324D",
1300 .params = tuner_panasonic_vp27_params, 1267 .params = tuner_panasonic_vp27_params,
1268 .count = ARRAY_SIZE(tuner_panasonic_vp27_params),
1301 }, 1269 },
1302 [TUNER_LG_NTSC_TAPE] = { /* LGINNOTEK NTSC */ 1270 [TUNER_LG_NTSC_TAPE] = { /* LGINNOTEK NTSC */
1303 .name = "LG NTSC (TAPE series)", 1271 .name = "LG NTSC (TAPE series)",
1304 .params = tuner_lg_ntsc_tape_params, 1272 .params = tuner_lg_ntsc_tape_params,
1273 .count = ARRAY_SIZE(tuner_lg_ntsc_tape_params),
1305 }, 1274 },
1306 [TUNER_TNF_8831BGFF] = { /* Philips PAL */ 1275 [TUNER_TNF_8831BGFF] = { /* Philips PAL */
1307 .name = "Tenna TNF 8831 BGFF)", 1276 .name = "Tenna TNF 8831 BGFF)",
1308 .params = tuner_tnf_8831bgff_params, 1277 .params = tuner_tnf_8831bgff_params,
1278 .count = ARRAY_SIZE(tuner_tnf_8831bgff_params),
1309 }, 1279 },
1310 [TUNER_MICROTUNE_4042FI5] = { /* Microtune NTSC */ 1280 [TUNER_MICROTUNE_4042FI5] = { /* Microtune NTSC */
1311 .name = "Microtune 4042 FI5 ATSC/NTSC dual in", 1281 .name = "Microtune 4042 FI5 ATSC/NTSC dual in",
1312 .params = tuner_microtune_4042fi5_params, 1282 .params = tuner_microtune_4042fi5_params,
1283 .count = ARRAY_SIZE(tuner_microtune_4042fi5_params),
1313 }, 1284 },
1314 1285
1315 /* 50-59 */ 1286 /* 50-59 */
1316 [TUNER_TCL_2002N] = { /* TCL NTSC */ 1287 [TUNER_TCL_2002N] = { /* TCL NTSC */
1317 .name = "TCL 2002N", 1288 .name = "TCL 2002N",
1318 .params = tuner_tcl_2002n_params, 1289 .params = tuner_tcl_2002n_params,
1290 .count = ARRAY_SIZE(tuner_tcl_2002n_params),
1319 }, 1291 },
1320 [TUNER_PHILIPS_FM1256_IH3] = { /* Philips PAL */ 1292 [TUNER_PHILIPS_FM1256_IH3] = { /* Philips PAL */
1321 .name = "Philips PAL/SECAM_D (FM 1256 I-H3)", 1293 .name = "Philips PAL/SECAM_D (FM 1256 I-H3)",
1322 .params = tuner_philips_fm1256_ih3_params, 1294 .params = tuner_philips_fm1256_ih3_params,
1295 .count = ARRAY_SIZE(tuner_philips_fm1256_ih3_params),
1323 }, 1296 },
1324 [TUNER_THOMSON_DTT7610] = { /* THOMSON ATSC */ 1297 [TUNER_THOMSON_DTT7610] = { /* THOMSON ATSC */
1325 .name = "Thomson DTT 7610 (ATSC/NTSC)", 1298 .name = "Thomson DTT 7610 (ATSC/NTSC)",
1326 .params = tuner_thomson_dtt7610_params, 1299 .params = tuner_thomson_dtt7610_params,
1300 .count = ARRAY_SIZE(tuner_thomson_dtt7610_params),
1327 }, 1301 },
1328 [TUNER_PHILIPS_FQ1286] = { /* Philips NTSC */ 1302 [TUNER_PHILIPS_FQ1286] = { /* Philips NTSC */
1329 .name = "Philips FQ1286", 1303 .name = "Philips FQ1286",
1330 .params = tuner_philips_fq1286_params, 1304 .params = tuner_philips_fq1286_params,
1305 .count = ARRAY_SIZE(tuner_philips_fq1286_params),
1331 }, 1306 },
1332 [TUNER_PHILIPS_TDA8290] = { /* Philips PAL|NTSC */ 1307 [TUNER_PHILIPS_TDA8290] = { /* Philips PAL|NTSC */
1333 .name = "tda8290+75", 1308 .name = "tda8290+75",
@@ -1335,22 +1310,27 @@ struct tunertype tuners[] = {
1335 [TUNER_TCL_2002MB] = { /* TCL PAL */ 1310 [TUNER_TCL_2002MB] = { /* TCL PAL */
1336 .name = "TCL 2002MB", 1311 .name = "TCL 2002MB",
1337 .params = tuner_tcl_2002mb_params, 1312 .params = tuner_tcl_2002mb_params,
1313 .count = ARRAY_SIZE(tuner_tcl_2002mb_params),
1338 }, 1314 },
1339 [TUNER_PHILIPS_FQ1216AME_MK4] = { /* Philips PAL */ 1315 [TUNER_PHILIPS_FQ1216AME_MK4] = { /* Philips PAL */
1340 .name = "Philips PAL/SECAM multi (FQ1216AME MK4)", 1316 .name = "Philips PAL/SECAM multi (FQ1216AME MK4)",
1341 .params = tuner_philips_fq1216ame_mk4_params, 1317 .params = tuner_philips_fq1216ame_mk4_params,
1318 .count = ARRAY_SIZE(tuner_philips_fq1216ame_mk4_params),
1342 }, 1319 },
1343 [TUNER_PHILIPS_FQ1236A_MK4] = { /* Philips NTSC */ 1320 [TUNER_PHILIPS_FQ1236A_MK4] = { /* Philips NTSC */
1344 .name = "Philips FQ1236A MK4", 1321 .name = "Philips FQ1236A MK4",
1345 .params = tuner_philips_fq1236a_mk4_params, 1322 .params = tuner_philips_fq1236a_mk4_params,
1323 .count = ARRAY_SIZE(tuner_philips_fq1236a_mk4_params),
1346 }, 1324 },
1347 [TUNER_YMEC_TVF_8531MF] = { /* Philips NTSC */ 1325 [TUNER_YMEC_TVF_8531MF] = { /* Philips NTSC */
1348 .name = "Ymec TVision TVF-8531MF/8831MF/8731MF", 1326 .name = "Ymec TVision TVF-8531MF/8831MF/8731MF",
1349 .params = tuner_ymec_tvf_8531mf_params, 1327 .params = tuner_ymec_tvf_8531mf_params,
1328 .count = ARRAY_SIZE(tuner_ymec_tvf_8531mf_params),
1350 }, 1329 },
1351 [TUNER_YMEC_TVF_5533MF] = { /* Philips NTSC */ 1330 [TUNER_YMEC_TVF_5533MF] = { /* Philips NTSC */
1352 .name = "Ymec TVision TVF-5533MF", 1331 .name = "Ymec TVision TVF-5533MF",
1353 .params = tuner_ymec_tvf_5533mf_params, 1332 .params = tuner_ymec_tvf_5533mf_params,
1333 .count = ARRAY_SIZE(tuner_ymec_tvf_5533mf_params),
1354 }, 1334 },
1355 1335
1356 /* 60-69 */ 1336 /* 60-69 */
@@ -1358,10 +1338,12 @@ struct tunertype tuners[] = {
1358 /* DTT 7611 7611A 7612 7613 7613A 7614 7615 7615A */ 1338 /* DTT 7611 7611A 7612 7613 7613A 7614 7615 7615A */
1359 .name = "Thomson DTT 761X (ATSC/NTSC)", 1339 .name = "Thomson DTT 761X (ATSC/NTSC)",
1360 .params = tuner_thomson_dtt761x_params, 1340 .params = tuner_thomson_dtt761x_params,
1341 .count = ARRAY_SIZE(tuner_thomson_dtt761x_params),
1361 }, 1342 },
1362 [TUNER_TENA_9533_DI] = { /* Philips PAL */ 1343 [TUNER_TENA_9533_DI] = { /* Philips PAL */
1363 .name = "Tena TNF9533-D/IF/TNF9533-B/DF", 1344 .name = "Tena TNF9533-D/IF/TNF9533-B/DF",
1364 .params = tuner_tena_9533_di_params, 1345 .params = tuner_tena_9533_di_params,
1346 .count = ARRAY_SIZE(tuner_tena_9533_di_params),
1365 }, 1347 },
1366 [TUNER_TEA5767] = { /* Philips RADIO */ 1348 [TUNER_TEA5767] = { /* Philips RADIO */
1367 .name = "Philips TEA5767HN FM Radio", 1349 .name = "Philips TEA5767HN FM Radio",
@@ -1369,37 +1351,54 @@ struct tunertype tuners[] = {
1369 }, 1351 },
1370 [TUNER_PHILIPS_FMD1216ME_MK3] = { /* Philips PAL */ 1352 [TUNER_PHILIPS_FMD1216ME_MK3] = { /* Philips PAL */
1371 .name = "Philips FMD1216ME MK3 Hybrid Tuner", 1353 .name = "Philips FMD1216ME MK3 Hybrid Tuner",
1372 .params = tuner_tuner_philips_fmd1216me_mk3_params, 1354 .params = tuner_philips_fmd1216me_mk3_params,
1355 .count = ARRAY_SIZE(tuner_philips_fmd1216me_mk3_params),
1373 }, 1356 },
1374 [TUNER_LG_TDVS_H062F] = { /* LGINNOTEK ATSC */ 1357 [TUNER_LG_TDVS_H062F] = { /* LGINNOTEK ATSC */
1375 .name = "LG TDVS-H062F/TUA6034", 1358 .name = "LG TDVS-H062F/TUA6034",
1376 .params = tuner_tua6034_params, 1359 .params = tuner_tua6034_params,
1360 .count = ARRAY_SIZE(tuner_tua6034_params),
1377 }, 1361 },
1378 [TUNER_YMEC_TVF66T5_B_DFF] = { /* Philips PAL */ 1362 [TUNER_YMEC_TVF66T5_B_DFF] = { /* Philips PAL */
1379 .name = "Ymec TVF66T5-B/DFF", 1363 .name = "Ymec TVF66T5-B/DFF",
1380 .params = tuner_ymec_tvf66t5_b_dff_params, 1364 .params = tuner_ymec_tvf66t5_b_dff_params,
1365 .count = ARRAY_SIZE(tuner_ymec_tvf66t5_b_dff_params),
1381 }, 1366 },
1382 [TUNER_LG_NTSC_TALN_MINI] = { /* LGINNOTEK NTSC */ 1367 [TUNER_LG_TALN] = { /* LGINNOTEK NTSC / PAL / SECAM */
1383 .name = "LG NTSC (TALN mini series)", 1368 .name = "LG TALN series",
1384 .params = tuner_lg_taln_mini_params, 1369 .params = tuner_lg_taln_params,
1370 .count = ARRAY_SIZE(tuner_lg_taln_params),
1385 }, 1371 },
1386 [TUNER_PHILIPS_TD1316] = { /* Philips PAL */ 1372 [TUNER_PHILIPS_TD1316] = { /* Philips PAL */
1387 .name = "Philips TD1316 Hybrid Tuner", 1373 .name = "Philips TD1316 Hybrid Tuner",
1388 .params = tuner_philips_td1316_params, 1374 .params = tuner_philips_td1316_params,
1375 .count = ARRAY_SIZE(tuner_philips_td1316_params),
1389 }, 1376 },
1390 [TUNER_PHILIPS_TUV1236D] = { /* Philips ATSC */ 1377 [TUNER_PHILIPS_TUV1236D] = { /* Philips ATSC */
1391 .name = "Philips TUV1236D ATSC/NTSC dual in", 1378 .name = "Philips TUV1236D ATSC/NTSC dual in",
1392 .params = tuner_tuner_tuv1236d_params, 1379 .params = tuner_tuv1236d_params,
1380 .count = ARRAY_SIZE(tuner_tuv1236d_params),
1393 }, 1381 },
1394 [TUNER_TNF_5335MF] = { /* Philips NTSC */ 1382 [TUNER_TNF_5335MF] = { /* Tenna PAL/NTSC */
1395 .name = "Tena TNF 5335 MF", 1383 .name = "Tena TNF 5335 and similar models",
1396 .params = tuner_tnf_5335mf_params, 1384 .params = tuner_tnf_5335mf_params,
1385 .count = ARRAY_SIZE(tuner_tnf_5335mf_params),
1397 }, 1386 },
1398 1387
1399 /* 70-79 */ 1388 /* 70-79 */
1400 [TUNER_SAMSUNG_TCPN_2121P30A] = { /* Samsung NTSC */ 1389 [TUNER_SAMSUNG_TCPN_2121P30A] = { /* Samsung NTSC */
1401 .name = "Samsung TCPN 2121P30A", 1390 .name = "Samsung TCPN 2121P30A",
1402 .params = tuner_samsung_tcpn_2121p30a_params, 1391 .params = tuner_samsung_tcpn_2121p30a_params,
1392 .count = ARRAY_SIZE(tuner_samsung_tcpn_2121p30a_params),
1393 },
1394 [TUNER_XCEIVE_XC3028] = { /* Xceive 3028 */
1395 .name = "Xceive xc3028",
1396 /* see xc3028.c for details */
1397 },
1398 [TUNER_THOMSON_FE6600] = { /* Thomson PAL / DVB-T */
1399 .name = "Thomson FE6600",
1400 .params = tuner_thomson_fe6600_params,
1401 .count = ARRAY_SIZE(tuner_thomson_fe6600_params),
1403 }, 1402 },
1404}; 1403};
1405 1404
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index c8e5ad0e8185..4efb01bb44ac 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -130,6 +130,7 @@ struct CHIPSTATE {
130 struct timer_list wt; 130 struct timer_list wt;
131 int done; 131 int done;
132 int watch_stereo; 132 int watch_stereo;
133 int audmode;
133}; 134};
134 135
135/* ---------------------------------------------------------------------- */ 136/* ---------------------------------------------------------------------- */
@@ -1514,6 +1515,7 @@ static int chip_attach(struct i2c_adapter *adap, int addr, int kind)
1514 chip->type = desc-chiplist; 1515 chip->type = desc-chiplist;
1515 chip->shadow.count = desc->registers+1; 1516 chip->shadow.count = desc->registers+1;
1516 chip->prevmode = -1; 1517 chip->prevmode = -1;
1518 chip->audmode = V4L2_TUNER_MODE_LANG1;
1517 /* register */ 1519 /* register */
1518 i2c_attach_client(&chip->c); 1520 i2c_attach_client(&chip->c);
1519 1521
@@ -1671,6 +1673,8 @@ static int chip_command(struct i2c_client *client,
1671 struct v4l2_tuner *vt = arg; 1673 struct v4l2_tuner *vt = arg;
1672 int mode = 0; 1674 int mode = 0;
1673 1675
1676 if (chip->radio)
1677 break;
1674 switch (vt->audmode) { 1678 switch (vt->audmode) {
1675 case V4L2_TUNER_MODE_MONO: 1679 case V4L2_TUNER_MODE_MONO:
1676 mode = VIDEO_SOUND_MONO; 1680 mode = VIDEO_SOUND_MONO;
@@ -1685,8 +1689,9 @@ static int chip_command(struct i2c_client *client,
1685 mode = VIDEO_SOUND_LANG2; 1689 mode = VIDEO_SOUND_LANG2;
1686 break; 1690 break;
1687 default: 1691 default:
1688 break; 1692 return -EINVAL;
1689 } 1693 }
1694 chip->audmode = vt->audmode;
1690 1695
1691 if (desc->setmode && mode) { 1696 if (desc->setmode && mode) {
1692 chip->watch_stereo = 0; 1697 chip->watch_stereo = 0;
@@ -1704,7 +1709,7 @@ static int chip_command(struct i2c_client *client,
1704 1709
1705 if (chip->radio) 1710 if (chip->radio)
1706 break; 1711 break;
1707 vt->audmode = 0; 1712 vt->audmode = chip->audmode;
1708 vt->rxsubchans = 0; 1713 vt->rxsubchans = 0;
1709 vt->capability = V4L2_TUNER_CAP_STEREO | 1714 vt->capability = V4L2_TUNER_CAP_STEREO |
1710 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2; 1715 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
@@ -1716,19 +1721,12 @@ static int chip_command(struct i2c_client *client,
1716 vt->rxsubchans |= V4L2_TUNER_SUB_MONO; 1721 vt->rxsubchans |= V4L2_TUNER_SUB_MONO;
1717 if (mode & VIDEO_SOUND_STEREO) 1722 if (mode & VIDEO_SOUND_STEREO)
1718 vt->rxsubchans |= V4L2_TUNER_SUB_STEREO; 1723 vt->rxsubchans |= V4L2_TUNER_SUB_STEREO;
1724 /* Note: for SAP it should be mono/lang2 or stereo/lang2.
1725 When this module is converted fully to v4l2, then this
1726 should change for those chips that can detect SAP. */
1719 if (mode & VIDEO_SOUND_LANG1) 1727 if (mode & VIDEO_SOUND_LANG1)
1720 vt->rxsubchans |= V4L2_TUNER_SUB_LANG1 | 1728 vt->rxsubchans = V4L2_TUNER_SUB_LANG1 |
1721 V4L2_TUNER_SUB_LANG2; 1729 V4L2_TUNER_SUB_LANG2;
1722
1723 mode = chip->mode;
1724 if (mode & VIDEO_SOUND_MONO)
1725 vt->audmode = V4L2_TUNER_MODE_MONO;
1726 if (mode & VIDEO_SOUND_STEREO)
1727 vt->audmode = V4L2_TUNER_MODE_STEREO;
1728 if (mode & VIDEO_SOUND_LANG1)
1729 vt->audmode = V4L2_TUNER_MODE_LANG1;
1730 if (mode & VIDEO_SOUND_LANG2)
1731 vt->audmode = V4L2_TUNER_MODE_LANG2;
1732 break; 1730 break;
1733 } 1731 }
1734 1732
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index 1864423b3046..69d0fe159f4d 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * tvp5150 - Texas Instruments TVP5150A(M) video decoder driver 2 * tvp5150 - Texas Instruments TVP5150A/AM1 video decoder driver
3 * 3 *
4 * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br) 4 * Copyright (c) 2005,2006 Mauro Carvalho Chehab (mchehab@infradead.org)
5 * This code is placed under the terms of the GNU General Public License 5 * This code is placed under the terms of the GNU General Public License v2
6 */ 6 */
7 7
8#include <linux/i2c.h> 8#include <linux/i2c.h>
@@ -13,10 +13,11 @@
13 13
14#include "tvp5150_reg.h" 14#include "tvp5150_reg.h"
15 15
16MODULE_DESCRIPTION("Texas Instruments TVP5150A video decoder driver"); /* standard i2c insmod options */ 16MODULE_DESCRIPTION("Texas Instruments TVP5150A video decoder driver");
17MODULE_AUTHOR("Mauro Carvalho Chehab"); 17MODULE_AUTHOR("Mauro Carvalho Chehab");
18MODULE_LICENSE("GPL"); 18MODULE_LICENSE("GPL");
19 19
20/* standard i2c insmod options */
20static unsigned short normal_i2c[] = { 21static unsigned short normal_i2c[] = {
21 0xb8 >> 1, 22 0xb8 >> 1,
22 0xba >> 1, 23 0xba >> 1,
@@ -29,6 +30,9 @@ static int debug = 0;
29module_param(debug, int, 0); 30module_param(debug, int, 0);
30MODULE_PARM_DESC(debug, "Debug level (0-1)"); 31MODULE_PARM_DESC(debug, "Debug level (0-1)");
31 32
33#define tvp5150_err(fmt, arg...) do { \
34 printk(KERN_ERR "%s %d-%04x: " fmt, c->driver->driver.name, \
35 i2c_adapter_id(c->adapter), c->addr , ## arg); } while (0)
32#define tvp5150_info(fmt, arg...) do { \ 36#define tvp5150_info(fmt, arg...) do { \
33 printk(KERN_INFO "%s %d-%04x: " fmt, c->driver->driver.name, \ 37 printk(KERN_INFO "%s %d-%04x: " fmt, c->driver->driver.name, \
34 i2c_adapter_id(c->adapter), c->addr , ## arg); } while (0) 38 i2c_adapter_id(c->adapter), c->addr , ## arg); } while (0)
@@ -84,7 +88,7 @@ static struct v4l2_queryctrl tvp5150_qctrl[] = {
84struct tvp5150 { 88struct tvp5150 {
85 struct i2c_client *client; 89 struct i2c_client *client;
86 90
87 int norm; 91 v4l2_std_id norm; /* Current set standard */
88 int input; 92 int input;
89 int enable; 93 int enable;
90 int bright; 94 int bright;
@@ -125,310 +129,155 @@ static inline void tvp5150_write(struct i2c_client *c, unsigned char addr,
125 tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 2)\n", rc); 129 tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 2)\n", rc);
126} 130}
127 131
132static void dump_reg_range(struct i2c_client *c, char *s, u8 init, const u8 end,int max_line)
133{
134 int i=0;
135
136 while (init!=(u8)(end+1)) {
137 if ((i%max_line) == 0) {
138 if (i>0)
139 printk("\n");
140 printk("tvp5150: %s reg 0x%02x = ",s,init);
141 }
142 printk("%02x ",tvp5150_read(c, init));
143
144 init++;
145 i++;
146 }
147 printk("\n");
148}
149
128static void dump_reg(struct i2c_client *c) 150static void dump_reg(struct i2c_client *c)
129{ 151{
130 printk("tvp5150: Video input source selection #1 = 0x%02x\n", 152 printk("tvp5150: Video input source selection #1 = 0x%02x\n",
131 tvp5150_read(c, TVP5150_VD_IN_SRC_SEL_1)); 153 tvp5150_read(c, TVP5150_VD_IN_SRC_SEL_1));
132 printk("tvp5150: Analog channel controls = 0x%02x\n", 154 printk("tvp5150: Analog channel controls = 0x%02x\n",
133 tvp5150_read(c, TVP5150_ANAL_CHL_CTL)); 155 tvp5150_read(c, TVP5150_ANAL_CHL_CTL));
134 printk("tvp5150: Operation mode controls = 0x%02x\n", 156 printk("tvp5150: Operation mode controls = 0x%02x\n",
135 tvp5150_read(c, TVP5150_OP_MODE_CTL)); 157 tvp5150_read(c, TVP5150_OP_MODE_CTL));
136 printk("tvp5150: Miscellaneous controls = 0x%02x\n", 158 printk("tvp5150: Miscellaneous controls = 0x%02x\n",
137 tvp5150_read(c, TVP5150_MISC_CTL)); 159 tvp5150_read(c, TVP5150_MISC_CTL));
138 printk("tvp5150: Autoswitch mask: TVP5150A / TVP5150AM = 0x%02x\n", 160 printk("tvp5150: Autoswitch mask= 0x%02x\n",
139 tvp5150_read(c, TVP5150_AUTOSW_MSK)); 161 tvp5150_read(c, TVP5150_AUTOSW_MSK));
140 printk("tvp5150: Color killer threshold control = 0x%02x\n", 162 printk("tvp5150: Color killer threshold control = 0x%02x\n",
141 tvp5150_read(c, TVP5150_COLOR_KIL_THSH_CTL)); 163 tvp5150_read(c, TVP5150_COLOR_KIL_THSH_CTL));
142 printk("tvp5150: Luminance processing control #1 = 0x%02x\n", 164 printk("tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n",
143 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_1)); 165 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_1),
144 printk("tvp5150: Luminance processing control #2 = 0x%02x\n", 166 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_2),
145 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_2)); 167 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_3));
146 printk("tvp5150: Brightness control = 0x%02x\n", 168 printk("tvp5150: Brightness control = 0x%02x\n",
147 tvp5150_read(c, TVP5150_BRIGHT_CTL)); 169 tvp5150_read(c, TVP5150_BRIGHT_CTL));
148 printk("tvp5150: Color saturation control = 0x%02x\n", 170 printk("tvp5150: Color saturation control = 0x%02x\n",
149 tvp5150_read(c, TVP5150_SATURATION_CTL)); 171 tvp5150_read(c, TVP5150_SATURATION_CTL));
150 printk("tvp5150: Hue control = 0x%02x\n", 172 printk("tvp5150: Hue control = 0x%02x\n",
151 tvp5150_read(c, TVP5150_HUE_CTL)); 173 tvp5150_read(c, TVP5150_HUE_CTL));
152 printk("tvp5150: Contrast control = 0x%02x\n", 174 printk("tvp5150: Contrast control = 0x%02x\n",
153 tvp5150_read(c, TVP5150_CONTRAST_CTL)); 175 tvp5150_read(c, TVP5150_CONTRAST_CTL));
154 printk("tvp5150: Outputs and data rates select = 0x%02x\n", 176 printk("tvp5150: Outputs and data rates select = 0x%02x\n",
155 tvp5150_read(c, TVP5150_DATA_RATE_SEL)); 177 tvp5150_read(c, TVP5150_DATA_RATE_SEL));
156 printk("tvp5150: Luminance processing control #3 = 0x%02x\n",
157 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_3));
158 printk("tvp5150: Configuration shared pins = 0x%02x\n", 178 printk("tvp5150: Configuration shared pins = 0x%02x\n",
159 tvp5150_read(c, TVP5150_CONF_SHARED_PIN)); 179 tvp5150_read(c, TVP5150_CONF_SHARED_PIN));
160 printk("tvp5150: Active video cropping start MSB = 0x%02x\n", 180 printk("tvp5150: Active video cropping start = 0x%02x%02x\n",
161 tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_MSB)); 181 tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_MSB),
162 printk("tvp5150: Active video cropping start LSB = 0x%02x\n", 182 tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_LSB));
163 tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_LSB)); 183 printk("tvp5150: Active video cropping stop = 0x%02x%02x\n",
164 printk("tvp5150: Active video cropping stop MSB = 0x%02x\n", 184 tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_MSB),
165 tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_MSB)); 185 tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_LSB));
166 printk("tvp5150: Active video cropping stop LSB = 0x%02x\n",
167 tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_LSB));
168 printk("tvp5150: Genlock/RTC = 0x%02x\n", 186 printk("tvp5150: Genlock/RTC = 0x%02x\n",
169 tvp5150_read(c, TVP5150_GENLOCK)); 187 tvp5150_read(c, TVP5150_GENLOCK));
170 printk("tvp5150: Horizontal sync start = 0x%02x\n", 188 printk("tvp5150: Horizontal sync start = 0x%02x\n",
171 tvp5150_read(c, TVP5150_HORIZ_SYNC_START)); 189 tvp5150_read(c, TVP5150_HORIZ_SYNC_START));
172 printk("tvp5150: Vertical blanking start = 0x%02x\n", 190 printk("tvp5150: Vertical blanking start = 0x%02x\n",
173 tvp5150_read(c, TVP5150_VERT_BLANKING_START)); 191 tvp5150_read(c, TVP5150_VERT_BLANKING_START));
174 printk("tvp5150: Vertical blanking stop = 0x%02x\n", 192 printk("tvp5150: Vertical blanking stop = 0x%02x\n",
175 tvp5150_read(c, TVP5150_VERT_BLANKING_STOP)); 193 tvp5150_read(c, TVP5150_VERT_BLANKING_STOP));
176 printk("tvp5150: Chrominance processing control #1 = 0x%02x\n", 194 printk("tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n",
177 tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_1)); 195 tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_1),
178 printk("tvp5150: Chrominance processing control #2 = 0x%02x\n", 196 tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_2));
179 tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_2));
180 printk("tvp5150: Interrupt reset register B = 0x%02x\n", 197 printk("tvp5150: Interrupt reset register B = 0x%02x\n",
181 tvp5150_read(c, TVP5150_INT_RESET_REG_B)); 198 tvp5150_read(c, TVP5150_INT_RESET_REG_B));
182 printk("tvp5150: Interrupt enable register B = 0x%02x\n", 199 printk("tvp5150: Interrupt enable register B = 0x%02x\n",
183 tvp5150_read(c, TVP5150_INT_ENABLE_REG_B)); 200 tvp5150_read(c, TVP5150_INT_ENABLE_REG_B));
184 printk("tvp5150: Interrupt configuration register B = 0x%02x\n", 201 printk("tvp5150: Interrupt configuration register B = 0x%02x\n",
185 tvp5150_read(c, TVP5150_INTT_CONFIG_REG_B)); 202 tvp5150_read(c, TVP5150_INTT_CONFIG_REG_B));
186 printk("tvp5150: Video standard = 0x%02x\n", 203 printk("tvp5150: Video standard = 0x%02x\n",
187 tvp5150_read(c, TVP5150_VIDEO_STD)); 204 tvp5150_read(c, TVP5150_VIDEO_STD));
188 printk("tvp5150: Cb gain factor = 0x%02x\n", 205 printk("tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n",
189 tvp5150_read(c, TVP5150_CB_GAIN_FACT)); 206 tvp5150_read(c, TVP5150_CB_GAIN_FACT),
190 printk("tvp5150: Cr gain factor = 0x%02x\n", 207 tvp5150_read(c, TVP5150_CR_GAIN_FACTOR));
191 tvp5150_read(c, TVP5150_CR_GAIN_FACTOR));
192 printk("tvp5150: Macrovision on counter = 0x%02x\n", 208 printk("tvp5150: Macrovision on counter = 0x%02x\n",
193 tvp5150_read(c, TVP5150_MACROVISION_ON_CTR)); 209 tvp5150_read(c, TVP5150_MACROVISION_ON_CTR));
194 printk("tvp5150: Macrovision off counter = 0x%02x\n", 210 printk("tvp5150: Macrovision off counter = 0x%02x\n",
195 tvp5150_read(c, TVP5150_MACROVISION_OFF_CTR)); 211 tvp5150_read(c, TVP5150_MACROVISION_OFF_CTR));
196 printk("tvp5150: revision select (TVP5150AM1 only) = 0x%02x\n", 212 printk("tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n",
197 tvp5150_read(c, TVP5150_REV_SELECT)); 213 (tvp5150_read(c, TVP5150_REV_SELECT)&1)?3:4);
198 printk("tvp5150: MSB of device ID = 0x%02x\n", 214 printk("tvp5150: Device ID = %02x%02x\n",
199 tvp5150_read(c, TVP5150_MSB_DEV_ID)); 215 tvp5150_read(c, TVP5150_MSB_DEV_ID),
200 printk("tvp5150: LSB of device ID = 0x%02x\n", 216 tvp5150_read(c, TVP5150_LSB_DEV_ID));
201 tvp5150_read(c, TVP5150_LSB_DEV_ID)); 217 printk("tvp5150: ROM version = (hex) %02x.%02x\n",
202 printk("tvp5150: ROM major version = 0x%02x\n", 218 tvp5150_read(c, TVP5150_ROM_MAJOR_VER),
203 tvp5150_read(c, TVP5150_ROM_MAJOR_VER)); 219 tvp5150_read(c, TVP5150_ROM_MINOR_VER));
204 printk("tvp5150: ROM minor version = 0x%02x\n", 220 printk("tvp5150: Vertical line count = 0x%02x%02x\n",
205 tvp5150_read(c, TVP5150_ROM_MINOR_VER)); 221 tvp5150_read(c, TVP5150_VERT_LN_COUNT_MSB),
206 printk("tvp5150: Vertical line count MSB = 0x%02x\n", 222 tvp5150_read(c, TVP5150_VERT_LN_COUNT_LSB));
207 tvp5150_read(c, TVP5150_VERT_LN_COUNT_MSB));
208 printk("tvp5150: Vertical line count LSB = 0x%02x\n",
209 tvp5150_read(c, TVP5150_VERT_LN_COUNT_LSB));
210 printk("tvp5150: Interrupt status register B = 0x%02x\n", 223 printk("tvp5150: Interrupt status register B = 0x%02x\n",
211 tvp5150_read(c, TVP5150_INT_STATUS_REG_B)); 224 tvp5150_read(c, TVP5150_INT_STATUS_REG_B));
212 printk("tvp5150: Interrupt active register B = 0x%02x\n", 225 printk("tvp5150: Interrupt active register B = 0x%02x\n",
213 tvp5150_read(c, TVP5150_INT_ACTIVE_REG_B)); 226 tvp5150_read(c, TVP5150_INT_ACTIVE_REG_B));
214 printk("tvp5150: Status register #1 = 0x%02x\n", 227 printk("tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n",
215 tvp5150_read(c, TVP5150_STATUS_REG_1)); 228 tvp5150_read(c, TVP5150_STATUS_REG_1),
216 printk("tvp5150: Status register #2 = 0x%02x\n", 229 tvp5150_read(c, TVP5150_STATUS_REG_2),
217 tvp5150_read(c, TVP5150_STATUS_REG_2)); 230 tvp5150_read(c, TVP5150_STATUS_REG_3),
218 printk("tvp5150: Status register #3 = 0x%02x\n", 231 tvp5150_read(c, TVP5150_STATUS_REG_4),
219 tvp5150_read(c, TVP5150_STATUS_REG_3)); 232 tvp5150_read(c, TVP5150_STATUS_REG_5));
220 printk("tvp5150: Status register #4 = 0x%02x\n", 233
221 tvp5150_read(c, TVP5150_STATUS_REG_4)); 234 dump_reg_range(c,"Teletext filter 1", TVP5150_TELETEXT_FIL1_INI,
222 printk("tvp5150: Status register #5 = 0x%02x\n", 235 TVP5150_TELETEXT_FIL1_END,8);
223 tvp5150_read(c, TVP5150_STATUS_REG_5)); 236 dump_reg_range(c,"Teletext filter 2", TVP5150_TELETEXT_FIL2_INI,
224 printk("tvp5150: Closed caption data registers = 0x%02x\n", 237 TVP5150_TELETEXT_FIL2_END,8);
225 tvp5150_read(c, TVP5150_CC_DATA_REG1)); 238
226 printk("tvp5150: Closed caption data registers = 0x%02x\n",
227 tvp5150_read(c, TVP5150_CC_DATA_REG2));
228 printk("tvp5150: Closed caption data registers = 0x%02x\n",
229 tvp5150_read(c, TVP5150_CC_DATA_REG3));
230 printk("tvp5150: Closed caption data registers = 0x%02x\n",
231 tvp5150_read(c, TVP5150_CC_DATA_REG4));
232 printk("tvp5150: WSS data registers = 0x%02x\n",
233 tvp5150_read(c, TVP5150_WSS_DATA_REG1));
234 printk("tvp5150: WSS data registers = 0x%02x\n",
235 tvp5150_read(c, TVP5150_WSS_DATA_REG2));
236 printk("tvp5150: WSS data registers = 0x%02x\n",
237 tvp5150_read(c, TVP5150_WSS_DATA_REG3));
238 printk("tvp5150: WSS data registers = 0x%02x\n",
239 tvp5150_read(c, TVP5150_WSS_DATA_REG4));
240 printk("tvp5150: WSS data registers = 0x%02x\n",
241 tvp5150_read(c, TVP5150_WSS_DATA_REG5));
242 printk("tvp5150: WSS data registers = 0x%02x\n",
243 tvp5150_read(c, TVP5150_WSS_DATA_REG6));
244 printk("tvp5150: VPS data registers = 0x%02x\n",
245 tvp5150_read(c, TVP5150_VPS_DATA_REG1));
246 printk("tvp5150: VPS data registers = 0x%02x\n",
247 tvp5150_read(c, TVP5150_VPS_DATA_REG2));
248 printk("tvp5150: VPS data registers = 0x%02x\n",
249 tvp5150_read(c, TVP5150_VPS_DATA_REG3));
250 printk("tvp5150: VPS data registers = 0x%02x\n",
251 tvp5150_read(c, TVP5150_VPS_DATA_REG4));
252 printk("tvp5150: VPS data registers = 0x%02x\n",
253 tvp5150_read(c, TVP5150_VPS_DATA_REG5));
254 printk("tvp5150: VPS data registers = 0x%02x\n",
255 tvp5150_read(c, TVP5150_VPS_DATA_REG6));
256 printk("tvp5150: VPS data registers = 0x%02x\n",
257 tvp5150_read(c, TVP5150_VPS_DATA_REG7));
258 printk("tvp5150: VPS data registers = 0x%02x\n",
259 tvp5150_read(c, TVP5150_VPS_DATA_REG8));
260 printk("tvp5150: VPS data registers = 0x%02x\n",
261 tvp5150_read(c, TVP5150_VPS_DATA_REG9));
262 printk("tvp5150: VPS data registers = 0x%02x\n",
263 tvp5150_read(c, TVP5150_VPS_DATA_REG10));
264 printk("tvp5150: VPS data registers = 0x%02x\n",
265 tvp5150_read(c, TVP5150_VPS_DATA_REG11));
266 printk("tvp5150: VPS data registers = 0x%02x\n",
267 tvp5150_read(c, TVP5150_VPS_DATA_REG12));
268 printk("tvp5150: VPS data registers = 0x%02x\n",
269 tvp5150_read(c, TVP5150_VPS_DATA_REG13));
270 printk("tvp5150: VITC data registers = 0x%02x\n",
271 tvp5150_read(c, TVP5150_VITC_DATA_REG1));
272 printk("tvp5150: VITC data registers = 0x%02x\n",
273 tvp5150_read(c, TVP5150_VITC_DATA_REG2));
274 printk("tvp5150: VITC data registers = 0x%02x\n",
275 tvp5150_read(c, TVP5150_VITC_DATA_REG3));
276 printk("tvp5150: VITC data registers = 0x%02x\n",
277 tvp5150_read(c, TVP5150_VITC_DATA_REG4));
278 printk("tvp5150: VITC data registers = 0x%02x\n",
279 tvp5150_read(c, TVP5150_VITC_DATA_REG5));
280 printk("tvp5150: VITC data registers = 0x%02x\n",
281 tvp5150_read(c, TVP5150_VITC_DATA_REG6));
282 printk("tvp5150: VITC data registers = 0x%02x\n",
283 tvp5150_read(c, TVP5150_VITC_DATA_REG7));
284 printk("tvp5150: VITC data registers = 0x%02x\n",
285 tvp5150_read(c, TVP5150_VITC_DATA_REG8));
286 printk("tvp5150: VITC data registers = 0x%02x\n",
287 tvp5150_read(c, TVP5150_VITC_DATA_REG9));
288 printk("tvp5150: VBI FIFO read data = 0x%02x\n",
289 tvp5150_read(c, TVP5150_VBI_FIFO_READ_DATA));
290 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
291 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_1));
292 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
293 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_2));
294 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
295 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_3));
296 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
297 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_4));
298 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
299 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_5));
300 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
301 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_1));
302 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
303 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_2));
304 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
305 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_3));
306 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
307 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_4));
308 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
309 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_5));
310 printk("tvp5150: Teletext filter enable = 0x%02x\n", 239 printk("tvp5150: Teletext filter enable = 0x%02x\n",
311 tvp5150_read(c, TVP5150_TELETEXT_FIL_ENA)); 240 tvp5150_read(c, TVP5150_TELETEXT_FIL_ENA));
312 printk("tvp5150: Interrupt status register A = 0x%02x\n", 241 printk("tvp5150: Interrupt status register A = 0x%02x\n",
313 tvp5150_read(c, TVP5150_INT_STATUS_REG_A)); 242 tvp5150_read(c, TVP5150_INT_STATUS_REG_A));
314 printk("tvp5150: Interrupt enable register A = 0x%02x\n", 243 printk("tvp5150: Interrupt enable register A = 0x%02x\n",
315 tvp5150_read(c, TVP5150_INT_ENABLE_REG_A)); 244 tvp5150_read(c, TVP5150_INT_ENABLE_REG_A));
316 printk("tvp5150: Interrupt configuration = 0x%02x\n", 245 printk("tvp5150: Interrupt configuration = 0x%02x\n",
317 tvp5150_read(c, TVP5150_INT_CONF)); 246 tvp5150_read(c, TVP5150_INT_CONF));
318 printk("tvp5150: VDP configuration RAM data = 0x%02x\n",
319 tvp5150_read(c, TVP5150_VDP_CONF_RAM_DATA));
320 printk("tvp5150: Configuration RAM address low byte = 0x%02x\n",
321 tvp5150_read(c, TVP5150_CONF_RAM_ADDR_LOW));
322 printk("tvp5150: Configuration RAM address high byte = 0x%02x\n",
323 tvp5150_read(c, TVP5150_CONF_RAM_ADDR_HIGH));
324 printk("tvp5150: VDP status register = 0x%02x\n", 247 printk("tvp5150: VDP status register = 0x%02x\n",
325 tvp5150_read(c, TVP5150_VDP_STATUS_REG)); 248 tvp5150_read(c, TVP5150_VDP_STATUS_REG));
326 printk("tvp5150: FIFO word count = 0x%02x\n", 249 printk("tvp5150: FIFO word count = 0x%02x\n",
327 tvp5150_read(c, TVP5150_FIFO_WORD_COUNT)); 250 tvp5150_read(c, TVP5150_FIFO_WORD_COUNT));
328 printk("tvp5150: FIFO interrupt threshold = 0x%02x\n", 251 printk("tvp5150: FIFO interrupt threshold = 0x%02x\n",
329 tvp5150_read(c, TVP5150_FIFO_INT_THRESHOLD)); 252 tvp5150_read(c, TVP5150_FIFO_INT_THRESHOLD));
330 printk("tvp5150: FIFO reset = 0x%02x\n", 253 printk("tvp5150: FIFO reset = 0x%02x\n",
331 tvp5150_read(c, TVP5150_FIFO_RESET)); 254 tvp5150_read(c, TVP5150_FIFO_RESET));
332 printk("tvp5150: Line number interrupt = 0x%02x\n", 255 printk("tvp5150: Line number interrupt = 0x%02x\n",
333 tvp5150_read(c, TVP5150_LINE_NUMBER_INT)); 256 tvp5150_read(c, TVP5150_LINE_NUMBER_INT));
334 printk("tvp5150: Pixel alignment register low byte = 0x%02x\n", 257 printk("tvp5150: Pixel alignment register = 0x%02x%02x\n",
335 tvp5150_read(c, TVP5150_PIX_ALIGN_REG_LOW)); 258 tvp5150_read(c, TVP5150_PIX_ALIGN_REG_HIGH),
336 printk("tvp5150: Pixel alignment register high byte = 0x%02x\n", 259 tvp5150_read(c, TVP5150_PIX_ALIGN_REG_LOW));
337 tvp5150_read(c, TVP5150_PIX_ALIGN_REG_HIGH));
338 printk("tvp5150: FIFO output control = 0x%02x\n", 260 printk("tvp5150: FIFO output control = 0x%02x\n",
339 tvp5150_read(c, TVP5150_FIFO_OUT_CTRL)); 261 tvp5150_read(c, TVP5150_FIFO_OUT_CTRL));
340 printk("tvp5150: Full field enable 1 = 0x%02x\n", 262 printk("tvp5150: Full field enable = 0x%02x\n",
341 tvp5150_read(c, TVP5150_FULL_FIELD_ENA_1)); 263 tvp5150_read(c, TVP5150_FULL_FIELD_ENA));
342 printk("tvp5150: Full field enable 2 = 0x%02x\n",
343 tvp5150_read(c, TVP5150_FULL_FIELD_ENA_2));
344 printk("tvp5150: Line mode registers = 0x%02x\n",
345 tvp5150_read(c, TVP5150_LINE_MODE_REG_1));
346 printk("tvp5150: Line mode registers = 0x%02x\n",
347 tvp5150_read(c, TVP5150_LINE_MODE_REG_2));
348 printk("tvp5150: Line mode registers = 0x%02x\n",
349 tvp5150_read(c, TVP5150_LINE_MODE_REG_3));
350 printk("tvp5150: Line mode registers = 0x%02x\n",
351 tvp5150_read(c, TVP5150_LINE_MODE_REG_4));
352 printk("tvp5150: Line mode registers = 0x%02x\n",
353 tvp5150_read(c, TVP5150_LINE_MODE_REG_5));
354 printk("tvp5150: Line mode registers = 0x%02x\n",
355 tvp5150_read(c, TVP5150_LINE_MODE_REG_6));
356 printk("tvp5150: Line mode registers = 0x%02x\n",
357 tvp5150_read(c, TVP5150_LINE_MODE_REG_7));
358 printk("tvp5150: Line mode registers = 0x%02x\n",
359 tvp5150_read(c, TVP5150_LINE_MODE_REG_8));
360 printk("tvp5150: Line mode registers = 0x%02x\n",
361 tvp5150_read(c, TVP5150_LINE_MODE_REG_9));
362 printk("tvp5150: Line mode registers = 0x%02x\n",
363 tvp5150_read(c, TVP5150_LINE_MODE_REG_10));
364 printk("tvp5150: Line mode registers = 0x%02x\n",
365 tvp5150_read(c, TVP5150_LINE_MODE_REG_11));
366 printk("tvp5150: Line mode registers = 0x%02x\n",
367 tvp5150_read(c, TVP5150_LINE_MODE_REG_12));
368 printk("tvp5150: Line mode registers = 0x%02x\n",
369 tvp5150_read(c, TVP5150_LINE_MODE_REG_13));
370 printk("tvp5150: Line mode registers = 0x%02x\n",
371 tvp5150_read(c, TVP5150_LINE_MODE_REG_14));
372 printk("tvp5150: Line mode registers = 0x%02x\n",
373 tvp5150_read(c, TVP5150_LINE_MODE_REG_15));
374 printk("tvp5150: Line mode registers = 0x%02x\n",
375 tvp5150_read(c, TVP5150_LINE_MODE_REG_16));
376 printk("tvp5150: Line mode registers = 0x%02x\n",
377 tvp5150_read(c, TVP5150_LINE_MODE_REG_17));
378 printk("tvp5150: Line mode registers = 0x%02x\n",
379 tvp5150_read(c, TVP5150_LINE_MODE_REG_18));
380 printk("tvp5150: Line mode registers = 0x%02x\n",
381 tvp5150_read(c, TVP5150_LINE_MODE_REG_19));
382 printk("tvp5150: Line mode registers = 0x%02x\n",
383 tvp5150_read(c, TVP5150_LINE_MODE_REG_20));
384 printk("tvp5150: Line mode registers = 0x%02x\n",
385 tvp5150_read(c, TVP5150_LINE_MODE_REG_21));
386 printk("tvp5150: Line mode registers = 0x%02x\n",
387 tvp5150_read(c, TVP5150_LINE_MODE_REG_22));
388 printk("tvp5150: Line mode registers = 0x%02x\n",
389 tvp5150_read(c, TVP5150_LINE_MODE_REG_23));
390 printk("tvp5150: Line mode registers = 0x%02x\n",
391 tvp5150_read(c, TVP5150_LINE_MODE_REG_24));
392 printk("tvp5150: Line mode registers = 0x%02x\n",
393 tvp5150_read(c, TVP5150_LINE_MODE_REG_25));
394 printk("tvp5150: Line mode registers = 0x%02x\n",
395 tvp5150_read(c, TVP5150_LINE_MODE_REG_27));
396 printk("tvp5150: Line mode registers = 0x%02x\n",
397 tvp5150_read(c, TVP5150_LINE_MODE_REG_28));
398 printk("tvp5150: Line mode registers = 0x%02x\n",
399 tvp5150_read(c, TVP5150_LINE_MODE_REG_29));
400 printk("tvp5150: Line mode registers = 0x%02x\n",
401 tvp5150_read(c, TVP5150_LINE_MODE_REG_30));
402 printk("tvp5150: Line mode registers = 0x%02x\n",
403 tvp5150_read(c, TVP5150_LINE_MODE_REG_31));
404 printk("tvp5150: Line mode registers = 0x%02x\n",
405 tvp5150_read(c, TVP5150_LINE_MODE_REG_32));
406 printk("tvp5150: Line mode registers = 0x%02x\n",
407 tvp5150_read(c, TVP5150_LINE_MODE_REG_33));
408 printk("tvp5150: Line mode registers = 0x%02x\n",
409 tvp5150_read(c, TVP5150_LINE_MODE_REG_34));
410 printk("tvp5150: Line mode registers = 0x%02x\n",
411 tvp5150_read(c, TVP5150_LINE_MODE_REG_35));
412 printk("tvp5150: Line mode registers = 0x%02x\n",
413 tvp5150_read(c, TVP5150_LINE_MODE_REG_36));
414 printk("tvp5150: Line mode registers = 0x%02x\n",
415 tvp5150_read(c, TVP5150_LINE_MODE_REG_37));
416 printk("tvp5150: Line mode registers = 0x%02x\n",
417 tvp5150_read(c, TVP5150_LINE_MODE_REG_38));
418 printk("tvp5150: Line mode registers = 0x%02x\n",
419 tvp5150_read(c, TVP5150_LINE_MODE_REG_39));
420 printk("tvp5150: Line mode registers = 0x%02x\n",
421 tvp5150_read(c, TVP5150_LINE_MODE_REG_40));
422 printk("tvp5150: Line mode registers = 0x%02x\n",
423 tvp5150_read(c, TVP5150_LINE_MODE_REG_41));
424 printk("tvp5150: Line mode registers = 0x%02x\n",
425 tvp5150_read(c, TVP5150_LINE_MODE_REG_42));
426 printk("tvp5150: Line mode registers = 0x%02x\n",
427 tvp5150_read(c, TVP5150_LINE_MODE_REG_43));
428 printk("tvp5150: Line mode registers = 0x%02x\n",
429 tvp5150_read(c, TVP5150_LINE_MODE_REG_44));
430 printk("tvp5150: Full field mode register = 0x%02x\n", 264 printk("tvp5150: Full field mode register = 0x%02x\n",
431 tvp5150_read(c, TVP5150_FULL_FIELD_MODE_REG)); 265 tvp5150_read(c, TVP5150_FULL_FIELD_MODE_REG));
266
267 dump_reg_range(c,"CC data", TVP5150_CC_DATA_INI,
268 TVP5150_CC_DATA_END,8);
269
270 dump_reg_range(c,"WSS data", TVP5150_WSS_DATA_INI,
271 TVP5150_WSS_DATA_END,8);
272
273 dump_reg_range(c,"VPS data", TVP5150_VPS_DATA_INI,
274 TVP5150_VPS_DATA_END,8);
275
276 dump_reg_range(c,"VITC data", TVP5150_VITC_DATA_INI,
277 TVP5150_VITC_DATA_END,10);
278
279 dump_reg_range(c,"Line mode", TVP5150_LINE_MODE_INI,
280 TVP5150_LINE_MODE_END,8);
432} 281}
433 282
434/**************************************************************************** 283/****************************************************************************
@@ -593,10 +442,10 @@ static const struct i2c_reg_value tvp5150_init_default[] = {
593 TVP5150_FIFO_OUT_CTRL,0x01 442 TVP5150_FIFO_OUT_CTRL,0x01
594 }, 443 },
595 { /* 0xcf */ 444 { /* 0xcf */
596 TVP5150_FULL_FIELD_ENA_1,0x00 445 TVP5150_FULL_FIELD_ENA,0x00
597 }, 446 },
598 { /* 0xd0 */ 447 { /* 0xd0 */
599 TVP5150_FULL_FIELD_ENA_2,0x00 448 TVP5150_LINE_MODE_INI,0x00
600 }, 449 },
601 { /* 0xfc */ 450 { /* 0xfc */
602 TVP5150_FULL_FIELD_MODE_REG,0x7f 451 TVP5150_FULL_FIELD_MODE_REG,0x7f
@@ -629,54 +478,101 @@ static const struct i2c_reg_value tvp5150_init_enable[] = {
629 } 478 }
630}; 479};
631 480
481struct tvp5150_vbi_type {
482 unsigned int vbi_type;
483 unsigned int ini_line;
484 unsigned int end_line;
485 unsigned int by_field :1;
486};
487
632struct i2c_vbi_ram_value { 488struct i2c_vbi_ram_value {
633 u16 reg; 489 u16 reg;
634 unsigned char values[26]; 490 struct tvp5150_vbi_type type;
491 unsigned char values[16];
635}; 492};
636 493
494/* This struct have the values for each supported VBI Standard
495 * by
496 tvp5150_vbi_types should follow the same order as vbi_ram_default
497 * value 0 means rom position 0x10, value 1 means rom position 0x30
498 * and so on. There are 16 possible locations from 0 to 15.
499 */
500
637static struct i2c_vbi_ram_value vbi_ram_default[] = 501static struct i2c_vbi_ram_value vbi_ram_default[] =
638{ 502{
639 {0x010, /* WST SECAM 6 */ 503 {0x010, /* Teletext, SECAM, WST System A */
640 { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x26, 0xe6, 0xb4, 0x0e, 0x0, 0x0, 0x0, 0x10, 0x0 } 504 {V4L2_SLICED_TELETEXT_SECAM,6,23,1},
505 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
506 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
641 }, 507 },
642 {0x030, /* WST PAL B 6 */ 508 {0x030, /* Teletext, PAL, WST System B */
643 { 0xaa, 0xaa, 0xff, 0xff , 0x27, 0x2e, 0x20, 0x2b, 0xa6, 0x72, 0x10, 0x0, 0x0, 0x0, 0x10, 0x0 } 509 {V4L2_SLICED_TELETEXT_PAL_B,6,22,1},
510 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
511 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
644 }, 512 },
645 {0x050, /* WST PAL C 6 */ 513 {0x050, /* Teletext, PAL, WST System C */
646 { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x22, 0xa6, 0x98, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 } 514 {V4L2_SLICED_TELETEXT_PAL_C,6,22,1},
515 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
516 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
647 }, 517 },
648 {0x070, /* WST NTSC 6 */ 518 {0x070, /* Teletext, NTSC, WST System B */
649 { 0xaa, 0xaa, 0xff, 0xff , 0x27, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 } 519 {V4L2_SLICED_TELETEXT_NTSC_B,10,21,1},
520 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23,
521 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
650 }, 522 },
651 {0x090, /* NABTS, NTSC 6 */ 523 {0x090, /* Tetetext, NTSC NABTS System C */
652 { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x22, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x15, 0x0 } 524 {V4L2_SLICED_TELETEXT_NTSC_C,10,21,1},
525 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
526 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 }
653 }, 527 },
654 {0x0b0, /* NABTS, NTSC-J 6 */ 528 {0x0b0, /* Teletext, NTSC-J, NABTS System D */
655 { 0xaa, 0xaa, 0xff, 0xff , 0xa7, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 } 529 {V4L2_SLICED_TELETEXT_NTSC_D,10,21,1},
530 { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23,
531 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
656 }, 532 },
657 {0x0d0, /* CC, PAL/SECAM 6 */ 533 {0x0d0, /* Closed Caption, PAL/SECAM */
658 { 0xaa, 0x2a, 0xff, 0x3f , 0x04, 0x51, 0x6e, 0x02, 0xa6, 0x7b, 0x09, 0x0, 0x0, 0x0, 0x27, 0x0 } 534 {V4L2_SLICED_CAPTION_625,22,22,1},
535 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
536 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
659 }, 537 },
660 {0x0f0, /* CC, NTSC 6 */ 538 {0x0f0, /* Closed Caption, NTSC */
661 { 0xaa, 0x2a, 0xff, 0x3f , 0x04, 0x51, 0x6e, 0x02, 0x69, 0x8c, 0x09, 0x0, 0x0, 0x0, 0x27, 0x0 } 539 {V4L2_SLICED_CAPTION_525,21,21,1},
540 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
541 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
662 }, 542 },
663 {0x110, /* WSS, PAL/SECAM 6 */ 543 {0x110, /* Wide Screen Signal, PAL/SECAM */
664 { 0x5b, 0x55, 0xc5, 0xff , 0x0, 0x71, 0x6e, 0x42, 0xa6, 0xcd, 0x0f, 0x0, 0x0, 0x0, 0x3a, 0x0 } 544 {V4L2_SLICED_WSS_625,23,23,1},
545 { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
546 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
665 }, 547 },
666 {0x130, /* WSS, NTSC C */ 548 {0x130, /* Wide Screen Signal, NTSC C */
667 { 0x38, 0x00, 0x3f, 0x00 , 0x0, 0x71, 0x6e, 0x43, 0x69, 0x7c, 0x08, 0x0, 0x0, 0x0, 0x39, 0x0 } 549 {V4L2_SLICED_WSS_525,20,20,1},
550 { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
551 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 }
668 }, 552 },
669 {0x150, /* VITC, PAL/SECAM 6 */ 553 {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */
670 { 0x0, 0x0, 0x0, 0x0 , 0x0, 0x8f, 0x6d, 0x49, 0xa6, 0x85, 0x08, 0x0, 0x0, 0x0, 0x4c, 0x0 } 554 {V4l2_SLICED_VITC_625,6,22,0},
555 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
556 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
671 }, 557 },
672 {0x170, /* VITC, NTSC 6 */ 558 {0x170, /* Vertical Interval Timecode (VITC), NTSC */
673 { 0x0, 0x0, 0x0, 0x0 , 0x0, 0x8f, 0x6d, 0x49, 0x69, 0x94, 0x08, 0x0, 0x0, 0x0, 0x4c, 0x0 } 559 {V4l2_SLICED_VITC_525,10,20,0},
560 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
561 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
674 }, 562 },
563 {0x190, /* Video Program System (VPS), PAL */
564 {V4L2_SLICED_VPS,16,16,0},
565 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
566 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
567 },
568 /* 0x1d0 User programmable */
569
570 /* End of struct */
675 { (u16)-1 } 571 { (u16)-1 }
676}; 572};
677 573
678static int tvp5150_write_inittab(struct i2c_client *c, 574static int tvp5150_write_inittab(struct i2c_client *c,
679 const struct i2c_reg_value *regs) 575 const struct i2c_reg_value *regs)
680{ 576{
681 while (regs->reg != 0xff) { 577 while (regs->reg != 0xff) {
682 tvp5150_write(c, regs->reg, regs->value); 578 tvp5150_write(c, regs->reg, regs->value);
@@ -686,15 +582,15 @@ static int tvp5150_write_inittab(struct i2c_client *c,
686} 582}
687 583
688static int tvp5150_vdp_init(struct i2c_client *c, 584static int tvp5150_vdp_init(struct i2c_client *c,
689 const struct i2c_vbi_ram_value *regs) 585 const struct i2c_vbi_ram_value *regs)
690{ 586{
691 unsigned int i; 587 unsigned int i;
692 588
693 /* Disable Full Field */ 589 /* Disable Full Field */
694 tvp5150_write(c, TVP5150_FULL_FIELD_ENA_1, 0); 590 tvp5150_write(c, TVP5150_FULL_FIELD_ENA, 0);
695 591
696 /* Before programming, Line mode should be at 0xff */ 592 /* Before programming, Line mode should be at 0xff */
697 for (i=TVP5150_FULL_FIELD_ENA_2; i<=TVP5150_LINE_MODE_REG_44; i++) 593 for (i=TVP5150_LINE_MODE_INI; i<=TVP5150_LINE_MODE_END; i++)
698 tvp5150_write(c, i, 0xff); 594 tvp5150_write(c, i, 0xff);
699 595
700 /* Load Ram Table */ 596 /* Load Ram Table */
@@ -710,6 +606,117 @@ static int tvp5150_vdp_init(struct i2c_client *c,
710 return 0; 606 return 0;
711} 607}
712 608
609/* Fills VBI capabilities based on i2c_vbi_ram_value struct */
610static void tvp5150_vbi_get_cap(const struct i2c_vbi_ram_value *regs,
611 struct v4l2_sliced_vbi_cap *cap)
612{
613 int line;
614
615 memset(cap, 0, sizeof *cap);
616
617 while (regs->reg != (u16)-1 ) {
618 for (line=regs->type.ini_line;line<=regs->type.end_line;line++) {
619 cap->service_lines[0][line] |= regs->type.vbi_type;
620 }
621 cap->service_set |= regs->type.vbi_type;
622
623 regs++;
624 }
625}
626
627/* Set vbi processing
628 * type - one of tvp5150_vbi_types
629 * line - line to gather data
630 * fields: bit 0 field1, bit 1, field2
631 * flags (default=0xf0) is a bitmask, were set means:
632 * bit 7: enable filtering null bytes on CC
633 * bit 6: send data also to FIFO
634 * bit 5: don't allow data with errors on FIFO
635 * bit 4: enable ECC when possible
636 * pix_align = pix alignment:
637 * LSB = field1
638 * MSB = field2
639 */
640static int tvp5150_set_vbi(struct i2c_client *c,
641 const struct i2c_vbi_ram_value *regs,
642 unsigned int type,u8 flags, int line,
643 const int fields)
644{
645 struct tvp5150 *decoder = i2c_get_clientdata(c);
646 v4l2_std_id std=decoder->norm;
647 u8 reg;
648 int pos=0;
649
650 if (std == V4L2_STD_ALL) {
651 tvp5150_err("VBI can't be configured without knowing number of lines\n");
652 return 0;
653 } else if (std && V4L2_STD_625_50) {
654 /* Don't follow NTSC Line number convension */
655 line += 3;
656 }
657
658 if (line<6||line>27)
659 return 0;
660
661 while (regs->reg != (u16)-1 ) {
662 if ((type & regs->type.vbi_type) &&
663 (line>=regs->type.ini_line) &&
664 (line<=regs->type.end_line)) {
665 type=regs->type.vbi_type;
666 break;
667 }
668
669 regs++;
670 pos++;
671 }
672 if (regs->reg == (u16)-1)
673 return 0;
674
675 type=pos | (flags & 0xf0);
676 reg=((line-6)<<1)+TVP5150_LINE_MODE_INI;
677
678 if (fields&1) {
679 tvp5150_write(c, reg, type);
680 }
681
682 if (fields&2) {
683 tvp5150_write(c, reg+1, type);
684 }
685
686 return type;
687}
688
689static int tvp5150_get_vbi(struct i2c_client *c,
690 const struct i2c_vbi_ram_value *regs, int line)
691{
692 struct tvp5150 *decoder = i2c_get_clientdata(c);
693 v4l2_std_id std=decoder->norm;
694 u8 reg;
695 int pos, type=0;
696
697 if (std == V4L2_STD_ALL) {
698 tvp5150_err("VBI can't be configured without knowing number of lines\n");
699 return 0;
700 } else if (std && V4L2_STD_625_50) {
701 /* Don't follow NTSC Line number convension */
702 line += 3;
703 }
704
705 if (line<6||line>27)
706 return 0;
707
708 reg=((line-6)<<1)+TVP5150_LINE_MODE_INI;
709
710 pos=tvp5150_read(c, reg)&0x0f;
711 if (pos<0x0f)
712 type=regs[pos].type.vbi_type;
713
714 pos=tvp5150_read(c, reg+1)&0x0f;
715 if (pos<0x0f)
716 type|=regs[pos].type.vbi_type;
717
718 return type;
719}
713static int tvp5150_set_std(struct i2c_client *c, v4l2_std_id std) 720static int tvp5150_set_std(struct i2c_client *c, v4l2_std_id std)
714{ 721{
715 struct tvp5150 *decoder = i2c_get_clientdata(c); 722 struct tvp5150 *decoder = i2c_get_clientdata(c);
@@ -854,6 +861,69 @@ static int tvp5150_command(struct i2c_client *c,
854 *(v4l2_std_id *)arg = decoder->norm; 861 *(v4l2_std_id *)arg = decoder->norm;
855 break; 862 break;
856 863
864 case VIDIOC_G_SLICED_VBI_CAP:
865 {
866 struct v4l2_sliced_vbi_cap *cap = arg;
867 tvp5150_dbg(1, "VIDIOC_G_SLICED_VBI_CAP\n");
868
869 tvp5150_vbi_get_cap(vbi_ram_default, cap);
870 break;
871 }
872 case VIDIOC_S_FMT:
873 {
874 struct v4l2_format *fmt;
875 struct v4l2_sliced_vbi_format *svbi;
876 int i;
877
878 fmt = arg;
879 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
880 return -EINVAL;
881 svbi = &fmt->fmt.sliced;
882 if (svbi->service_set != 0) {
883 for (i = 0; i <= 23; i++) {
884 svbi->service_lines[1][i] = 0;
885
886 svbi->service_lines[0][i]=tvp5150_set_vbi(c,
887 vbi_ram_default,
888 svbi->service_lines[0][i],0xf0,i,3);
889 }
890 /* Enables FIFO */
891 tvp5150_write(c, TVP5150_FIFO_OUT_CTRL,1);
892 } else {
893 /* Disables FIFO*/
894 tvp5150_write(c, TVP5150_FIFO_OUT_CTRL,0);
895
896 /* Disable Full Field */
897 tvp5150_write(c, TVP5150_FULL_FIELD_ENA, 0);
898
899 /* Disable Line modes */
900 for (i=TVP5150_LINE_MODE_INI; i<=TVP5150_LINE_MODE_END; i++)
901 tvp5150_write(c, i, 0xff);
902 }
903 break;
904 }
905 case VIDIOC_G_FMT:
906 {
907 struct v4l2_format *fmt;
908 struct v4l2_sliced_vbi_format *svbi;
909
910 int i, mask=0;
911
912 fmt = arg;
913 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
914 return -EINVAL;
915 svbi = &fmt->fmt.sliced;
916 memset(svbi, 0, sizeof(*svbi));
917
918 for (i = 0; i <= 23; i++) {
919 svbi->service_lines[0][i]=tvp5150_get_vbi(c,
920 vbi_ram_default,i);
921 mask|=svbi->service_lines[0][i];
922 }
923 svbi->service_set=mask;
924 break;
925 }
926
857#ifdef CONFIG_VIDEO_ADV_DEBUG 927#ifdef CONFIG_VIDEO_ADV_DEBUG
858 case VIDIOC_INT_G_REGISTER: 928 case VIDIOC_INT_G_REGISTER:
859 { 929 {
@@ -878,6 +948,7 @@ static int tvp5150_command(struct i2c_client *c,
878 } 948 }
879#endif 949#endif
880 950
951 case VIDIOC_LOG_STATUS:
881 case DECODER_DUMP: 952 case DECODER_DUMP:
882 dump_reg(c); 953 dump_reg(c);
883 break; 954 break;
@@ -1097,7 +1168,7 @@ static int tvp5150_detect_client(struct i2c_adapter *adapter,
1097 1168
1098 rv = i2c_attach_client(c); 1169 rv = i2c_attach_client(c);
1099 1170
1100 core->norm = V4L2_STD_ALL; 1171 core->norm = V4L2_STD_ALL; /* Default is autodetect */
1101 core->input = 2; 1172 core->input = 2;
1102 core->enable = 1; 1173 core->enable = 1;
1103 core->bright = 32768; 1174 core->bright = 32768;
diff --git a/drivers/media/video/tvp5150_reg.h b/drivers/media/video/tvp5150_reg.h
index cd45c1ded786..4240043c0b2a 100644
--- a/drivers/media/video/tvp5150_reg.h
+++ b/drivers/media/video/tvp5150_reg.h
@@ -1,3 +1,10 @@
1/*
2 * tvp5150 - Texas Instruments TVP5150A/AM1 video decoder registers
3 *
4 * Copyright (c) 2005,2006 Mauro Carvalho Chehab (mchehab@infradead.org)
5 * This code is placed under the terms of the GNU General Public License v2
6 */
7
1#define TVP5150_VD_IN_SRC_SEL_1 0x00 /* Video input source selection #1 */ 8#define TVP5150_VD_IN_SRC_SEL_1 0x00 /* Video input source selection #1 */
2#define TVP5150_ANAL_CHL_CTL 0x01 /* Analog channel controls */ 9#define TVP5150_ANAL_CHL_CTL 0x01 /* Analog channel controls */
3#define TVP5150_OP_MODE_CTL 0x02 /* Operation mode controls */ 10#define TVP5150_OP_MODE_CTL 0x02 /* Operation mode controls */
@@ -64,49 +71,32 @@
64#define TVP5150_STATUS_REG_4 0x8b /* Status register #4 */ 71#define TVP5150_STATUS_REG_4 0x8b /* Status register #4 */
65#define TVP5150_STATUS_REG_5 0x8c /* Status register #5 */ 72#define TVP5150_STATUS_REG_5 0x8c /* Status register #5 */
66/* Reserved 8Dh-8Fh */ 73/* Reserved 8Dh-8Fh */
67#define TVP5150_CC_DATA_REG1 0x90 /* Closed caption data registers */ 74 /* Closed caption data registers */
68#define TVP5150_CC_DATA_REG2 0x91 /* Closed caption data registers */ 75#define TVP5150_CC_DATA_INI 0x90
69#define TVP5150_CC_DATA_REG3 0x92 /* Closed caption data registers */ 76#define TVP5150_CC_DATA_END 0x93
70#define TVP5150_CC_DATA_REG4 0x93 /* Closed caption data registers */ 77
71#define TVP5150_WSS_DATA_REG1 0X94 /* WSS data registers */ 78 /* WSS data registers */
72#define TVP5150_WSS_DATA_REG2 0X95 /* WSS data registers */ 79#define TVP5150_WSS_DATA_INI 0x94
73#define TVP5150_WSS_DATA_REG3 0X96 /* WSS data registers */ 80#define TVP5150_WSS_DATA_END 0x99
74#define TVP5150_WSS_DATA_REG4 0X97 /* WSS data registers */ 81
75#define TVP5150_WSS_DATA_REG5 0X98 /* WSS data registers */ 82/* VPS data registers */
76#define TVP5150_WSS_DATA_REG6 0X99 /* WSS data registers */ 83#define TVP5150_VPS_DATA_INI 0x9a
77#define TVP5150_VPS_DATA_REG1 0x9a /* VPS data registers */ 84#define TVP5150_VPS_DATA_END 0xa6
78#define TVP5150_VPS_DATA_REG2 0x9b /* VPS data registers */ 85
79#define TVP5150_VPS_DATA_REG3 0x9c /* VPS data registers */ 86/* VITC data registers */
80#define TVP5150_VPS_DATA_REG4 0x9d /* VPS data registers */ 87#define TVP5150_VITC_DATA_INI 0xa7
81#define TVP5150_VPS_DATA_REG5 0x9e /* VPS data registers */ 88#define TVP5150_VITC_DATA_END 0xaf
82#define TVP5150_VPS_DATA_REG6 0x9f /* VPS data registers */ 89
83#define TVP5150_VPS_DATA_REG7 0xa0 /* VPS data registers */
84#define TVP5150_VPS_DATA_REG8 0xa1 /* VPS data registers */
85#define TVP5150_VPS_DATA_REG9 0xa2 /* VPS data registers */
86#define TVP5150_VPS_DATA_REG10 0xa3 /* VPS data registers */
87#define TVP5150_VPS_DATA_REG11 0xa4 /* VPS data registers */
88#define TVP5150_VPS_DATA_REG12 0xa5 /* VPS data registers */
89#define TVP5150_VPS_DATA_REG13 0xa6 /* VPS data registers */
90#define TVP5150_VITC_DATA_REG1 0xa7 /* VITC data registers */
91#define TVP5150_VITC_DATA_REG2 0xa8 /* VITC data registers */
92#define TVP5150_VITC_DATA_REG3 0xa9 /* VITC data registers */
93#define TVP5150_VITC_DATA_REG4 0xaa /* VITC data registers */
94#define TVP5150_VITC_DATA_REG5 0xab /* VITC data registers */
95#define TVP5150_VITC_DATA_REG6 0xac /* VITC data registers */
96#define TVP5150_VITC_DATA_REG7 0xad /* VITC data registers */
97#define TVP5150_VITC_DATA_REG8 0xae /* VITC data registers */
98#define TVP5150_VITC_DATA_REG9 0xaf /* VITC data registers */
99#define TVP5150_VBI_FIFO_READ_DATA 0xb0 /* VBI FIFO read data */ 90#define TVP5150_VBI_FIFO_READ_DATA 0xb0 /* VBI FIFO read data */
100#define TVP5150_TELETEXT_FIL_1_1 0xb1 /* Teletext filter 1 */ 91
101#define TVP5150_TELETEXT_FIL_1_2 0xb2 /* Teletext filter 1 */ 92/* Teletext filter 1 */
102#define TVP5150_TELETEXT_FIL_1_3 0xb3 /* Teletext filter 1 */ 93#define TVP5150_TELETEXT_FIL1_INI 0xb1
103#define TVP5150_TELETEXT_FIL_1_4 0xb4 /* Teletext filter 1 */ 94#define TVP5150_TELETEXT_FIL1_END 0xb5
104#define TVP5150_TELETEXT_FIL_1_5 0xb5 /* Teletext filter 1 */ 95
105#define TVP5150_TELETEXT_FIL_2_1 0xb6 /* Teletext filter 2 */ 96/* Teletext filter 2 */
106#define TVP5150_TELETEXT_FIL_2_2 0xb7 /* Teletext filter 2 */ 97#define TVP5150_TELETEXT_FIL2_INI 0xb6
107#define TVP5150_TELETEXT_FIL_2_3 0xb8 /* Teletext filter 2 */ 98#define TVP5150_TELETEXT_FIL2_END 0xba
108#define TVP5150_TELETEXT_FIL_2_4 0xb9 /* Teletext filter 2 */ 99
109#define TVP5150_TELETEXT_FIL_2_5 0xba /* Teletext filter 2 */
110#define TVP5150_TELETEXT_FIL_ENA 0xbb /* Teletext filter enable */ 100#define TVP5150_TELETEXT_FIL_ENA 0xbb /* Teletext filter enable */
111/* Reserved BCh-BFh */ 101/* Reserved BCh-BFh */
112#define TVP5150_INT_STATUS_REG_A 0xc0 /* Interrupt status register A */ 102#define TVP5150_INT_STATUS_REG_A 0xc0 /* Interrupt status register A */
@@ -124,50 +114,11 @@
124#define TVP5150_PIX_ALIGN_REG_HIGH 0xcc /* Pixel alignment register high byte */ 114#define TVP5150_PIX_ALIGN_REG_HIGH 0xcc /* Pixel alignment register high byte */
125#define TVP5150_FIFO_OUT_CTRL 0xcd /* FIFO output control */ 115#define TVP5150_FIFO_OUT_CTRL 0xcd /* FIFO output control */
126/* Reserved CEh */ 116/* Reserved CEh */
127#define TVP5150_FULL_FIELD_ENA_1 0xcf /* Full field enable 1 */ 117#define TVP5150_FULL_FIELD_ENA 0xcf /* Full field enable 1 */
128#define TVP5150_FULL_FIELD_ENA_2 0xd0 /* Full field enable 2 */ 118
129#define TVP5150_LINE_MODE_REG_1 0xd1 /* Line mode registers */ 119/* Line mode registers */
130#define TVP5150_LINE_MODE_REG_2 0xd2 /* Line mode registers */ 120#define TVP5150_LINE_MODE_INI 0xd0
131#define TVP5150_LINE_MODE_REG_3 0xd3 /* Line mode registers */ 121#define TVP5150_LINE_MODE_END 0xfb
132#define TVP5150_LINE_MODE_REG_4 0xd4 /* Line mode registers */ 122
133#define TVP5150_LINE_MODE_REG_5 0xd5 /* Line mode registers */
134#define TVP5150_LINE_MODE_REG_6 0xd6 /* Line mode registers */
135#define TVP5150_LINE_MODE_REG_7 0xd7 /* Line mode registers */
136#define TVP5150_LINE_MODE_REG_8 0xd8 /* Line mode registers */
137#define TVP5150_LINE_MODE_REG_9 0xd9 /* Line mode registers */
138#define TVP5150_LINE_MODE_REG_10 0xda /* Line mode registers */
139#define TVP5150_LINE_MODE_REG_11 0xdb /* Line mode registers */
140#define TVP5150_LINE_MODE_REG_12 0xdc /* Line mode registers */
141#define TVP5150_LINE_MODE_REG_13 0xdd /* Line mode registers */
142#define TVP5150_LINE_MODE_REG_14 0xde /* Line mode registers */
143#define TVP5150_LINE_MODE_REG_15 0xdf /* Line mode registers */
144#define TVP5150_LINE_MODE_REG_16 0xe0 /* Line mode registers */
145#define TVP5150_LINE_MODE_REG_17 0xe1 /* Line mode registers */
146#define TVP5150_LINE_MODE_REG_18 0xe2 /* Line mode registers */
147#define TVP5150_LINE_MODE_REG_19 0xe3 /* Line mode registers */
148#define TVP5150_LINE_MODE_REG_20 0xe4 /* Line mode registers */
149#define TVP5150_LINE_MODE_REG_21 0xe5 /* Line mode registers */
150#define TVP5150_LINE_MODE_REG_22 0xe6 /* Line mode registers */
151#define TVP5150_LINE_MODE_REG_23 0xe7 /* Line mode registers */
152#define TVP5150_LINE_MODE_REG_24 0xe8 /* Line mode registers */
153#define TVP5150_LINE_MODE_REG_25 0xe9 /* Line mode registers */
154#define TVP5150_LINE_MODE_REG_27 0xea /* Line mode registers */
155#define TVP5150_LINE_MODE_REG_28 0xeb /* Line mode registers */
156#define TVP5150_LINE_MODE_REG_29 0xec /* Line mode registers */
157#define TVP5150_LINE_MODE_REG_30 0xed /* Line mode registers */
158#define TVP5150_LINE_MODE_REG_31 0xee /* Line mode registers */
159#define TVP5150_LINE_MODE_REG_32 0xef /* Line mode registers */
160#define TVP5150_LINE_MODE_REG_33 0xf0 /* Line mode registers */
161#define TVP5150_LINE_MODE_REG_34 0xf1 /* Line mode registers */
162#define TVP5150_LINE_MODE_REG_35 0xf2 /* Line mode registers */
163#define TVP5150_LINE_MODE_REG_36 0xf3 /* Line mode registers */
164#define TVP5150_LINE_MODE_REG_37 0xf4 /* Line mode registers */
165#define TVP5150_LINE_MODE_REG_38 0xf5 /* Line mode registers */
166#define TVP5150_LINE_MODE_REG_39 0xf6 /* Line mode registers */
167#define TVP5150_LINE_MODE_REG_40 0xf7 /* Line mode registers */
168#define TVP5150_LINE_MODE_REG_41 0xf8 /* Line mode registers */
169#define TVP5150_LINE_MODE_REG_42 0xf9 /* Line mode registers */
170#define TVP5150_LINE_MODE_REG_43 0xfa /* Line mode registers */
171#define TVP5150_LINE_MODE_REG_44 0xfb /* Line mode registers */
172#define TVP5150_FULL_FIELD_MODE_REG 0xfc /* Full field mode register */ 123#define TVP5150_FULL_FIELD_MODE_REG 0xfc /* Full field mode register */
173/* Reserved FDh-FFh */ 124/* Reserved FDh-FFh */
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index cd2c4475525e..95a6e47c99f1 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -97,7 +97,7 @@ int v4l2_video_std_construct(struct v4l2_standard *vs,
97 memset(vs, 0, sizeof(struct v4l2_standard)); 97 memset(vs, 0, sizeof(struct v4l2_standard));
98 vs->index = index; 98 vs->index = index;
99 vs->id = id; 99 vs->id = id;
100 if (id & (V4L2_STD_NTSC | V4L2_STD_PAL_M)) { 100 if (id & V4L2_STD_525_60) {
101 vs->frameperiod.numerator = 1001; 101 vs->frameperiod.numerator = 1001;
102 vs->frameperiod.denominator = 30000; 102 vs->frameperiod.denominator = 30000;
103 vs->framelines = 525; 103 vs->framelines = 525;
@@ -110,7 +110,6 @@ int v4l2_video_std_construct(struct v4l2_standard *vs,
110 return 0; 110 return 0;
111} 111}
112 112
113
114/* ----------------------------------------------------------------- */ 113/* ----------------------------------------------------------------- */
115/* priority handling */ 114/* priority handling */
116 115
@@ -171,7 +170,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local)
171 170
172 171
173/* ----------------------------------------------------------------- */ 172/* ----------------------------------------------------------------- */
174/* some arrays for pretty-printing debug messages */ 173/* some arrays for pretty-printing debug messages of enum types */
175 174
176char *v4l2_field_names[] = { 175char *v4l2_field_names[] = {
177 [V4L2_FIELD_ANY] = "any", 176 [V4L2_FIELD_ANY] = "any",
@@ -192,6 +191,14 @@ char *v4l2_type_names[] = {
192 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out", 191 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
193}; 192};
194 193
194static char *v4l2_memory_names[] = {
195 [V4L2_MEMORY_MMAP] = "mmap",
196 [V4L2_MEMORY_USERPTR] = "userptr",
197 [V4L2_MEMORY_OVERLAY] = "overlay",
198};
199
200#define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown"
201
195/* ------------------------------------------------------------------ */ 202/* ------------------------------------------------------------------ */
196/* debug help functions */ 203/* debug help functions */
197 204
@@ -324,6 +331,15 @@ static const char *v4l2_int_ioctls[] = {
324}; 331};
325#define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls) 332#define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
326 333
334static void v4l_print_pix_fmt (char *s, struct v4l2_pix_format *fmt)
335{
336 printk ("%s: width=%d, height=%d, format=%d, field=%s, "
337 "bytesperline=%d sizeimage=%d, colorspace=%d\n", s,
338 fmt->width,fmt->height,fmt->pixelformat,
339 prt_names(fmt->field,v4l2_field_names),
340 fmt->bytesperline,fmt->sizeimage,fmt->colorspace);
341};
342
327/* Common ioctl debug function. This function can be used by 343/* Common ioctl debug function. This function can be used by
328 external ioctl messages as well as internal V4L ioctl */ 344 external ioctl messages as well as internal V4L ioctl */
329void v4l_printk_ioctl(unsigned int cmd) 345void v4l_printk_ioctl(unsigned int cmd)
@@ -362,6 +378,541 @@ void v4l_printk_ioctl(unsigned int cmd)
362 } 378 }
363} 379}
364 380
381/* Common ioctl debug function. This function can be used by
382 external ioctl messages as well as internal V4L ioctl and its
383 arguments */
384void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
385{
386 printk(s);
387 printk(": ");
388 v4l_printk_ioctl(cmd);
389 switch (cmd) {
390 case VIDIOC_INT_G_CHIP_IDENT:
391 {
392 enum v4l2_chip_ident *p=arg;
393 printk ("%s: chip ident=%d\n", s, *p);
394 break;
395 }
396 case VIDIOC_G_PRIORITY:
397 case VIDIOC_S_PRIORITY:
398 {
399 enum v4l2_priority *p=arg;
400 printk ("%s: priority=%d\n", s, *p);
401 break;
402 }
403 case VIDIOC_INT_S_TUNER_MODE:
404 {
405 enum v4l2_tuner_type *p=arg;
406 printk ("%s: tuner type=%d\n", s, *p);
407 break;
408 }
409 case DECODER_SET_VBI_BYPASS:
410 case DECODER_ENABLE_OUTPUT:
411 case DECODER_GET_STATUS:
412 case DECODER_SET_OUTPUT:
413 case DECODER_SET_INPUT:
414 case DECODER_SET_GPIO:
415 case DECODER_SET_NORM:
416 case VIDIOCCAPTURE:
417 case VIDIOCSYNC:
418 case VIDIOCSWRITEMODE:
419 case TUNER_SET_TYPE_ADDR:
420 case TUNER_SET_STANDBY:
421 case TDA9887_SET_CONFIG:
422 case AUDC_SET_INPUT:
423 case VIDIOC_OVERLAY_OLD:
424 case VIDIOC_STREAMOFF:
425 case VIDIOC_G_OUTPUT:
426 case VIDIOC_S_OUTPUT:
427 case VIDIOC_STREAMON:
428 case VIDIOC_G_INPUT:
429 case VIDIOC_OVERLAY:
430 case VIDIOC_S_INPUT:
431 {
432 int *p=arg;
433 printk ("%s: value=%d\n", s, *p);
434 break;
435 }
436 case MSP_SET_MATRIX:
437 {
438 struct msp_matrix *p=arg;
439 printk ("%s: input=%d, output=%d\n", s, p->input, p->output);
440 break;
441 }
442 case VIDIOC_G_AUDIO:
443 case VIDIOC_S_AUDIO:
444 case VIDIOC_ENUMAUDIO:
445 case VIDIOC_G_AUDIO_OLD:
446 {
447 struct v4l2_audio *p=arg;
448
449 printk ("%s: index=%d, name=%s, capability=%d, mode=%d\n",
450 s,p->index, p->name,p->capability, p->mode);
451 break;
452 }
453 case VIDIOC_G_AUDOUT:
454 case VIDIOC_S_AUDOUT:
455 case VIDIOC_ENUMAUDOUT:
456 case VIDIOC_G_AUDOUT_OLD:
457 {
458 struct v4l2_audioout *p=arg;
459 printk ("%s: index=%d, name=%s, capability=%d, mode=%d\n", s,
460 p->index, p->name, p->capability,p->mode);
461 break;
462 }
463 case VIDIOC_QBUF:
464 case VIDIOC_DQBUF:
465 case VIDIOC_QUERYBUF:
466 {
467 struct v4l2_buffer *p=arg;
468 struct v4l2_timecode *tc=&p->timecode;
469 printk ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, "
470 "bytesused=%d, flags=0x%08d, "
471 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx\n",
472 s,
473 (p->timestamp.tv_sec/3600),
474 (int)(p->timestamp.tv_sec/60)%60,
475 (int)(p->timestamp.tv_sec%60),
476 p->timestamp.tv_usec,
477 p->index,
478 prt_names(p->type,v4l2_type_names),
479 p->bytesused,p->flags,
480 p->field,p->sequence,
481 prt_names(p->memory,v4l2_memory_names),
482 p->m.userptr);
483 printk ("%s: timecode= %02d:%02d:%02d type=%d, "
484 "flags=0x%08d, frames=%d, userbits=0x%08x",
485 s,tc->hours,tc->minutes,tc->seconds,
486 tc->type, tc->flags, tc->frames, (__u32) tc->userbits);
487 break;
488 }
489 case VIDIOC_QUERYCAP:
490 {
491 struct v4l2_capability *p=arg;
492 printk ("%s: driver=%s, card=%s, bus=%s, version=%d, "
493 "capabilities=%d\n", s,
494 p->driver,p->card,p->bus_info,
495 p->version,
496 p->capabilities);
497 break;
498 }
499 case VIDIOC_G_CTRL:
500 case VIDIOC_S_CTRL:
501 case VIDIOC_S_CTRL_OLD:
502 {
503 struct v4l2_control *p=arg;
504 printk ("%s: id=%d, value=%d\n", s, p->id, p->value);
505 break;
506 }
507 case VIDIOC_G_CROP:
508 case VIDIOC_S_CROP:
509 {
510 struct v4l2_crop *p=arg;
511 /*FIXME: Should also show rect structs */
512 printk ("%s: type=%d\n", s, p->type);
513 break;
514 }
515 case VIDIOC_CROPCAP:
516 case VIDIOC_CROPCAP_OLD:
517 {
518 struct v4l2_cropcap *p=arg;
519 /*FIXME: Should also show rect structs */
520 printk ("%s: type=%d\n", s, p->type);
521 break;
522 }
523 case VIDIOC_INT_DECODE_VBI_LINE:
524 {
525 struct v4l2_decode_vbi_line *p=arg;
526 printk ("%s: is_second_field=%d, ptr=0x%08lx, line=%d, "
527 "type=%d\n", s,
528 p->is_second_field,(unsigned long)p->p,p->line,p->type);
529 break;
530 }
531 case VIDIOC_ENUM_FMT:
532 {
533 struct v4l2_fmtdesc *p=arg;
534 printk ("%s: index=%d, type=%d, flags=%d, description=%s,"
535 " pixelformat=%d\n", s,
536 p->index, p->type, p->flags,p->description,
537 p->pixelformat);
538
539 break;
540 }
541 case VIDIOC_G_FMT:
542 case VIDIOC_S_FMT:
543 case VIDIOC_TRY_FMT:
544 {
545 struct v4l2_format *p=arg;
546 printk ("%s: type=%s\n", s,
547 prt_names(p->type,v4l2_type_names));
548 switch (p->type) {
549 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
550 v4l_print_pix_fmt (s, &p->fmt.pix);
551 break;
552 default:
553 break;
554 }
555 }
556 case VIDIOC_G_FBUF:
557 case VIDIOC_S_FBUF:
558 {
559 struct v4l2_framebuffer *p=arg;
560 printk ("%s: capability=%d, flags=%d, base=0x%08lx\n", s,
561 p->capability,p->flags, (unsigned long)p->base);
562 v4l_print_pix_fmt (s, &p->fmt);
563 break;
564 }
565 case VIDIOC_G_FREQUENCY:
566 case VIDIOC_S_FREQUENCY:
567 {
568 struct v4l2_frequency *p=arg;
569 printk ("%s: tuner=%d, type=%d, frequency=%d\n", s,
570 p->tuner,p->type,p->frequency);
571 break;
572 }
573 case VIDIOC_ENUMINPUT:
574 {
575 struct v4l2_input *p=arg;
576 printk ("%s: index=%d, name=%s, type=%d, audioset=%d, "
577 "tuner=%d, std=%lld, status=%d\n", s,
578 p->index,p->name,p->type,p->audioset,
579 p->tuner,p->std,
580 p->status);
581 break;
582 }
583 case VIDIOC_G_JPEGCOMP:
584 case VIDIOC_S_JPEGCOMP:
585 {
586 struct v4l2_jpegcompression *p=arg;
587 printk ("%s: quality=%d, APPn=%d, APP_len=%d, COM_len=%d,"
588 " jpeg_markers=%d\n", s,
589 p->quality,p->APPn,p->APP_len,
590 p->COM_len,p->jpeg_markers);
591 break;
592 }
593 case VIDIOC_G_MODULATOR:
594 case VIDIOC_S_MODULATOR:
595 {
596 struct v4l2_modulator *p=arg;
597 printk ("%s: index=%d, name=%s, capability=%d, rangelow=%d,"
598 " rangehigh=%d, txsubchans=%d\n", s,
599 p->index, p->name,p->capability,p->rangelow,
600 p->rangehigh,p->txsubchans);
601 break;
602 }
603 case VIDIOC_G_MPEGCOMP:
604 case VIDIOC_S_MPEGCOMP:
605 {
606 struct v4l2_mpeg_compression *p=arg;
607 /*FIXME: Several fields not shown */
608 printk ("%s: ts_pid_pmt=%d, ts_pid_audio=%d, ts_pid_video=%d, "
609 "ts_pid_pcr=%d, ps_size=%d, au_sample_rate=%d, "
610 "au_pesid=%c, vi_frame_rate=%d, vi_frames_per_gop=%d, "
611 "vi_bframes_count=%d, vi_pesid=%c\n", s,
612 p->ts_pid_pmt,p->ts_pid_audio, p->ts_pid_video,
613 p->ts_pid_pcr, p->ps_size, p->au_sample_rate,
614 p->au_pesid, p->vi_frame_rate,
615 p->vi_frames_per_gop, p->vi_bframes_count,
616 p->vi_pesid);
617 break;
618 }
619 case VIDIOC_ENUMOUTPUT:
620 {
621 struct v4l2_output *p=arg;
622 printk ("%s: index=%d, name=%s,type=%d, audioset=%d, "
623 "modulator=%d, std=%lld\n",
624 s,p->index,p->name,p->type,p->audioset,
625 p->modulator,p->std);
626 break;
627 }
628 case VIDIOC_QUERYCTRL:
629 {
630 struct v4l2_queryctrl *p=arg;
631 printk ("%s: id=%d, type=%d, name=%s, min/max=%d/%d,"
632 " step=%d, default=%d, flags=0x%08x\n", s,
633 p->id,p->type,p->name,p->minimum,p->maximum,
634 p->step,p->default_value,p->flags);
635 break;
636 }
637 case VIDIOC_QUERYMENU:
638 {
639 struct v4l2_querymenu *p=arg;
640 printk ("%s: id=%d, index=%d, name=%s\n", s,
641 p->id,p->index,p->name);
642 break;
643 }
644 case VIDIOC_INT_G_REGISTER:
645 case VIDIOC_INT_S_REGISTER:
646 {
647 struct v4l2_register *p=arg;
648 printk ("%s: i2c_id=%d, reg=%lu, val=%d\n", s,
649 p->i2c_id,p->reg,p->val);
650
651 break;
652 }
653 case VIDIOC_REQBUFS:
654 {
655 struct v4l2_requestbuffers *p=arg;
656 printk ("%s: count=%d, type=%s, memory=%s\n", s,
657 p->count,
658 prt_names(p->type,v4l2_type_names),
659 prt_names(p->memory,v4l2_memory_names));
660 break;
661 }
662 case VIDIOC_INT_S_AUDIO_ROUTING:
663 case VIDIOC_INT_S_VIDEO_ROUTING:
664 case VIDIOC_INT_G_AUDIO_ROUTING:
665 case VIDIOC_INT_G_VIDEO_ROUTING:
666 {
667 struct v4l2_routing *p=arg;
668 printk ("%s: input=%d, output=%d\n", s, p->input, p->output);
669 break;
670 }
671 case VIDIOC_G_SLICED_VBI_CAP:
672 {
673 struct v4l2_sliced_vbi_cap *p=arg;
674 printk ("%s: service_set=%d\n", s,
675 p->service_set);
676 break;
677 }
678 case VIDIOC_INT_S_VBI_DATA:
679 case VIDIOC_INT_G_VBI_DATA:
680 {
681 struct v4l2_sliced_vbi_data *p=arg;
682 printk ("%s: id=%d, field=%d, line=%d\n", s,
683 p->id, p->field, p->line);
684 break;
685 }
686 case VIDIOC_ENUMSTD:
687 {
688 struct v4l2_standard *p=arg;
689 printk ("%s: index=%d, id=%lld, name=%s, fps=%d/%d, framelines=%d\n", s,
690 p->index, p->id, p->name,
691 p->frameperiod.numerator,
692 p->frameperiod.denominator,
693 p->framelines);
694
695 break;
696 }
697 case VIDIOC_G_PARM:
698 case VIDIOC_S_PARM:
699 case VIDIOC_S_PARM_OLD:
700 {
701 struct v4l2_streamparm *p=arg;
702 printk ("%s: type=%d\n", s, p->type);
703
704 break;
705 }
706 case VIDIOC_G_TUNER:
707 case VIDIOC_S_TUNER:
708 {
709 struct v4l2_tuner *p=arg;
710 printk ("%s: index=%d, name=%s, type=%d, capability=%d, "
711 "rangelow=%d, rangehigh=%d, signal=%d, afc=%d, "
712 "rxsubchans=%d, audmode=%d\n", s,
713 p->index, p->name, p->type,
714 p->capability, p->rangelow,p->rangehigh,
715 p->rxsubchans, p->audmode, p->signal,
716 p->afc);
717 break;
718 }
719 case VIDIOCGVBIFMT:
720 case VIDIOCSVBIFMT:
721 {
722 struct vbi_format *p=arg;
723 printk ("%s: sampling_rate=%d, samples_per_line=%d, "
724 "sample_format=%d, start=%d/%d, count=%d/%d, flags=%d\n", s,
725 p->sampling_rate,p->samples_per_line,
726 p->sample_format,p->start[0],p->start[1],
727 p->count[0],p->count[1],p->flags);
728 break;
729 }
730 case VIDIOCGAUDIO:
731 case VIDIOCSAUDIO:
732 {
733 struct video_audio *p=arg;
734 printk ("%s: audio=%d, volume=%d, bass=%d, treble=%d, "
735 "flags=%d, name=%s, mode=%d, balance=%d, step=%d\n",
736 s,p->audio,p->volume,p->bass, p->treble,
737 p->flags,p->name,p->mode,p->balance,p->step);
738 break;
739 }
740 case VIDIOCGFBUF:
741 case VIDIOCSFBUF:
742 {
743 struct video_buffer *p=arg;
744 printk ("%s: base=%08lx, height=%d, width=%d, depth=%d, "
745 "bytesperline=%d\n", s,
746 (unsigned long) p->base, p->height, p->width,
747 p->depth,p->bytesperline);
748 break;
749 }
750 case VIDIOCGCAP:
751 {
752 struct video_capability *p=arg;
753 printk ("%s: name=%s, type=%d, channels=%d, audios=%d, "
754 "maxwidth=%d, maxheight=%d, minwidth=%d, minheight=%d\n",
755 s,p->name,p->type,p->channels,p->audios,
756 p->maxwidth,p->maxheight,p->minwidth,
757 p->minheight);
758
759 break;
760 }
761 case VIDIOCGCAPTURE:
762 case VIDIOCSCAPTURE:
763 {
764 struct video_capture *p=arg;
765 printk ("%s: x=%d, y=%d, width=%d, height=%d, decimation=%d,"
766 " flags=%d\n", s,
767 p->x, p->y,p->width, p->height,
768 p->decimation,p->flags);
769 break;
770 }
771 case VIDIOCGCHAN:
772 case VIDIOCSCHAN:
773 {
774 struct video_channel *p=arg;
775 printk ("%s: channel=%d, name=%s, tuners=%d, flags=%d, "
776 "type=%d, norm=%d\n", s,
777 p->channel,p->name,p->tuners,
778 p->flags,p->type,p->norm);
779
780 break;
781 }
782 case VIDIOCSMICROCODE:
783 {
784 struct video_code *p=arg;
785 printk ("%s: loadwhat=%s, datasize=%d\n", s,
786 p->loadwhat,p->datasize);
787 break;
788 }
789 case DECODER_GET_CAPABILITIES:
790 {
791 struct video_decoder_capability *p=arg;
792 printk ("%s: flags=%d, inputs=%d, outputs=%d\n", s,
793 p->flags,p->inputs,p->outputs);
794 break;
795 }
796 case DECODER_INIT:
797 {
798 struct video_decoder_init *p=arg;
799 printk ("%s: len=%c\n", s, p->len);
800 break;
801 }
802 case VIDIOCGPLAYINFO:
803 {
804 struct video_info *p=arg;
805 printk ("%s: frame_count=%d, h_size=%d, v_size=%d, "
806 "smpte_timecode=%d, picture_type=%d, "
807 "temporal_reference=%d, user_data=%s\n", s,
808 p->frame_count, p->h_size,
809 p->v_size, p->smpte_timecode,
810 p->picture_type, p->temporal_reference,
811 p->user_data);
812 break;
813 }
814 case VIDIOCKEY:
815 {
816 struct video_key *p=arg;
817 printk ("%s: key=%s, flags=%d\n", s,
818 p->key, p->flags);
819 break;
820 }
821 case VIDIOCGMBUF:
822 {
823 struct video_mbuf *p=arg;
824 printk ("%s: size=%d, frames=%d, offsets=0x%08lx\n", s,
825 p->size,
826 p->frames,
827 (unsigned long)p->offsets);
828 break;
829 }
830 case VIDIOCMCAPTURE:
831 {
832 struct video_mmap *p=arg;
833 printk ("%s: frame=%d, height=%d, width=%d, format=%d\n", s,
834 p->frame,
835 p->height, p->width,
836 p->format);
837 break;
838 }
839 case VIDIOCGPICT:
840 case VIDIOCSPICT:
841 case DECODER_SET_PICTURE:
842 {
843 struct video_picture *p=arg;
844
845 printk ("%s: brightness=%d, hue=%d, colour=%d, contrast=%d,"
846 " whiteness=%d, depth=%d, palette=%d\n", s,
847 p->brightness, p->hue, p->colour,
848 p->contrast, p->whiteness, p->depth,
849 p->palette);
850 break;
851 }
852 case VIDIOCSPLAYMODE:
853 {
854 struct video_play_mode *p=arg;
855 printk ("%s: mode=%d, p1=%d, p2=%d\n", s,
856 p->mode,p->p1,p->p2);
857 break;
858 }
859 case VIDIOCGTUNER:
860 case VIDIOCSTUNER:
861 {
862 struct video_tuner *p=arg;
863 printk ("%s: tuner=%d, name=%s, rangelow=%ld, rangehigh=%ld, "
864 "flags=%d, mode=%d, signal=%d\n", s,
865 p->tuner, p->name,p->rangelow, p->rangehigh,
866 p->flags,p->mode, p->signal);
867 break;
868 }
869 case VIDIOCGUNIT:
870 {
871 struct video_unit *p=arg;
872 printk ("%s: video=%d, vbi=%d, radio=%d, audio=%d, "
873 "teletext=%d\n", s,
874 p->video,p->vbi,p->radio,p->audio,p->teletext);
875 break;
876 }
877 case VIDIOCGWIN:
878 case VIDIOCSWIN:
879 {
880 struct video_window *p=arg;
881 printk ("%s: x=%d, y=%d, width=%d, height=%d, chromakey=%d,"
882 " flags=%d, clipcount=%d\n", s,
883 p->x, p->y,p->width, p->height,
884 p->chromakey,p->flags,
885 p->clipcount);
886 break;
887 }
888 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
889 case VIDIOC_INT_I2S_CLOCK_FREQ:
890 case VIDIOC_INT_S_STANDBY:
891 {
892 u32 *p=arg;
893
894 printk ("%s: value=%d\n", s, *p);
895 break;
896 }
897 case VIDIOCGFREQ:
898 case VIDIOCSFREQ:
899 {
900 unsigned long *p=arg;
901 printk ("%s: value=%lu\n", s, *p);
902 break;
903 }
904 case VIDIOC_G_STD:
905 case VIDIOC_S_STD:
906 case VIDIOC_QUERYSTD:
907 {
908 v4l2_std_id *p=arg;
909
910 printk ("%s: value=%llu\n", s, *p);
911 break;
912 }
913 }
914}
915
365/* ----------------------------------------------------------------- */ 916/* ----------------------------------------------------------------- */
366 917
367EXPORT_SYMBOL(v4l2_video_std_construct); 918EXPORT_SYMBOL(v4l2_video_std_construct);
@@ -376,6 +927,7 @@ EXPORT_SYMBOL(v4l2_prio_check);
376EXPORT_SYMBOL(v4l2_field_names); 927EXPORT_SYMBOL(v4l2_field_names);
377EXPORT_SYMBOL(v4l2_type_names); 928EXPORT_SYMBOL(v4l2_type_names);
378EXPORT_SYMBOL(v4l_printk_ioctl); 929EXPORT_SYMBOL(v4l_printk_ioctl);
930EXPORT_SYMBOL(v4l_printk_ioctl_arg);
379 931
380/* 932/*
381 * Local variables: 933 * Local variables:
diff --git a/drivers/media/video/video-buf-dvb.c b/drivers/media/video/video-buf-dvb.c
index 0a4004a4393c..caf3e7e2f219 100644
--- a/drivers/media/video/video-buf-dvb.c
+++ b/drivers/media/video/video-buf-dvb.c
@@ -96,7 +96,7 @@ static int videobuf_dvb_start_feed(struct dvb_demux_feed *feed)
96 if (!demux->dmx.frontend) 96 if (!demux->dmx.frontend)
97 return -EINVAL; 97 return -EINVAL;
98 98
99 down(&dvb->lock); 99 mutex_lock(&dvb->lock);
100 dvb->nfeeds++; 100 dvb->nfeeds++;
101 rc = dvb->nfeeds; 101 rc = dvb->nfeeds;
102 102
@@ -110,7 +110,7 @@ static int videobuf_dvb_start_feed(struct dvb_demux_feed *feed)
110 } 110 }
111 111
112out: 112out:
113 up(&dvb->lock); 113 mutex_unlock(&dvb->lock);
114 return rc; 114 return rc;
115} 115}
116 116
@@ -120,14 +120,14 @@ static int videobuf_dvb_stop_feed(struct dvb_demux_feed *feed)
120 struct videobuf_dvb *dvb = demux->priv; 120 struct videobuf_dvb *dvb = demux->priv;
121 int err = 0; 121 int err = 0;
122 122
123 down(&dvb->lock); 123 mutex_lock(&dvb->lock);
124 dvb->nfeeds--; 124 dvb->nfeeds--;
125 if (0 == dvb->nfeeds && NULL != dvb->thread) { 125 if (0 == dvb->nfeeds && NULL != dvb->thread) {
126 // FIXME: cx8802_cancel_buffers(dev); 126 // FIXME: cx8802_cancel_buffers(dev);
127 err = kthread_stop(dvb->thread); 127 err = kthread_stop(dvb->thread);
128 dvb->thread = NULL; 128 dvb->thread = NULL;
129 } 129 }
130 up(&dvb->lock); 130 mutex_unlock(&dvb->lock);
131 return err; 131 return err;
132} 132}
133 133
@@ -139,7 +139,7 @@ int videobuf_dvb_register(struct videobuf_dvb *dvb,
139{ 139{
140 int result; 140 int result;
141 141
142 init_MUTEX(&dvb->lock); 142 mutex_init(&dvb->lock);
143 143
144 /* register adapter */ 144 /* register adapter */
145 result = dvb_register_adapter(&dvb->adapter, dvb->name, module); 145 result = dvb_register_adapter(&dvb->adapter, dvb->name, module);
diff --git a/drivers/media/video/video-buf.c b/drivers/media/video/video-buf.c
index 9ef477523d27..87e937581d5a 100644
--- a/drivers/media/video/video-buf.c
+++ b/drivers/media/video/video-buf.c
@@ -59,8 +59,7 @@ videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
59 pg = vmalloc_to_page(virt); 59 pg = vmalloc_to_page(virt);
60 if (NULL == pg) 60 if (NULL == pg)
61 goto err; 61 goto err;
62 if (PageHighMem(pg)) 62 BUG_ON(PageHighMem(pg));
63 BUG();
64 sglist[i].page = pg; 63 sglist[i].page = pg;
65 sglist[i].length = PAGE_SIZE; 64 sglist[i].length = PAGE_SIZE;
66 } 65 }
@@ -385,7 +384,7 @@ void videobuf_queue_init(struct videobuf_queue* q,
385 q->ops = ops; 384 q->ops = ops;
386 q->priv_data = priv; 385 q->priv_data = priv;
387 386
388 init_MUTEX(&q->lock); 387 mutex_init(&q->lock);
389 INIT_LIST_HEAD(&q->stream); 388 INIT_LIST_HEAD(&q->stream);
390} 389}
391 390
@@ -428,7 +427,7 @@ videobuf_queue_is_busy(struct videobuf_queue *q)
428void 427void
429videobuf_queue_cancel(struct videobuf_queue *q) 428videobuf_queue_cancel(struct videobuf_queue *q)
430{ 429{
431 unsigned long flags; 430 unsigned long flags=0;
432 int i; 431 int i;
433 432
434 /* remove queued buffers from list */ 433 /* remove queued buffers from list */
@@ -549,7 +548,7 @@ videobuf_reqbufs(struct videobuf_queue *q,
549 if (!list_empty(&q->stream)) 548 if (!list_empty(&q->stream))
550 return -EBUSY; 549 return -EBUSY;
551 550
552 down(&q->lock); 551 mutex_lock(&q->lock);
553 count = req->count; 552 count = req->count;
554 if (count > VIDEO_MAX_FRAME) 553 if (count > VIDEO_MAX_FRAME)
555 count = VIDEO_MAX_FRAME; 554 count = VIDEO_MAX_FRAME;
@@ -566,7 +565,7 @@ videobuf_reqbufs(struct videobuf_queue *q,
566 req->count = count; 565 req->count = count;
567 566
568 done: 567 done:
569 up(&q->lock); 568 mutex_unlock(&q->lock);
570 return retval; 569 return retval;
571} 570}
572 571
@@ -589,10 +588,10 @@ videobuf_qbuf(struct videobuf_queue *q,
589{ 588{
590 struct videobuf_buffer *buf; 589 struct videobuf_buffer *buf;
591 enum v4l2_field field; 590 enum v4l2_field field;
592 unsigned long flags; 591 unsigned long flags=0;
593 int retval; 592 int retval;
594 593
595 down(&q->lock); 594 mutex_lock(&q->lock);
596 retval = -EBUSY; 595 retval = -EBUSY;
597 if (q->reading) 596 if (q->reading)
598 goto done; 597 goto done;
@@ -652,7 +651,7 @@ videobuf_qbuf(struct videobuf_queue *q,
652 retval = 0; 651 retval = 0;
653 652
654 done: 653 done:
655 up(&q->lock); 654 mutex_unlock(&q->lock);
656 return retval; 655 return retval;
657} 656}
658 657
@@ -663,7 +662,7 @@ videobuf_dqbuf(struct videobuf_queue *q,
663 struct videobuf_buffer *buf; 662 struct videobuf_buffer *buf;
664 int retval; 663 int retval;
665 664
666 down(&q->lock); 665 mutex_lock(&q->lock);
667 retval = -EBUSY; 666 retval = -EBUSY;
668 if (q->reading) 667 if (q->reading)
669 goto done; 668 goto done;
@@ -693,7 +692,7 @@ videobuf_dqbuf(struct videobuf_queue *q,
693 videobuf_status(b,buf,q->type); 692 videobuf_status(b,buf,q->type);
694 693
695 done: 694 done:
696 up(&q->lock); 695 mutex_unlock(&q->lock);
697 return retval; 696 return retval;
698} 697}
699 698
@@ -701,10 +700,10 @@ int videobuf_streamon(struct videobuf_queue *q)
701{ 700{
702 struct videobuf_buffer *buf; 701 struct videobuf_buffer *buf;
703 struct list_head *list; 702 struct list_head *list;
704 unsigned long flags; 703 unsigned long flags=0;
705 int retval; 704 int retval;
706 705
707 down(&q->lock); 706 mutex_lock(&q->lock);
708 retval = -EBUSY; 707 retval = -EBUSY;
709 if (q->reading) 708 if (q->reading)
710 goto done; 709 goto done;
@@ -721,7 +720,7 @@ int videobuf_streamon(struct videobuf_queue *q)
721 spin_unlock_irqrestore(q->irqlock,flags); 720 spin_unlock_irqrestore(q->irqlock,flags);
722 721
723 done: 722 done:
724 up(&q->lock); 723 mutex_unlock(&q->lock);
725 return retval; 724 return retval;
726} 725}
727 726
@@ -729,7 +728,7 @@ int videobuf_streamoff(struct videobuf_queue *q)
729{ 728{
730 int retval = -EINVAL; 729 int retval = -EINVAL;
731 730
732 down(&q->lock); 731 mutex_lock(&q->lock);
733 if (!q->streaming) 732 if (!q->streaming)
734 goto done; 733 goto done;
735 videobuf_queue_cancel(q); 734 videobuf_queue_cancel(q);
@@ -737,7 +736,7 @@ int videobuf_streamoff(struct videobuf_queue *q)
737 retval = 0; 736 retval = 0;
738 737
739 done: 738 done:
740 up(&q->lock); 739 mutex_unlock(&q->lock);
741 return retval; 740 return retval;
742} 741}
743 742
@@ -746,7 +745,7 @@ videobuf_read_zerocopy(struct videobuf_queue *q, char __user *data,
746 size_t count, loff_t *ppos) 745 size_t count, loff_t *ppos)
747{ 746{
748 enum v4l2_field field; 747 enum v4l2_field field;
749 unsigned long flags; 748 unsigned long flags=0;
750 int retval; 749 int retval;
751 750
752 /* setup stuff */ 751 /* setup stuff */
@@ -788,11 +787,11 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
788 int nonblocking) 787 int nonblocking)
789{ 788{
790 enum v4l2_field field; 789 enum v4l2_field field;
791 unsigned long flags; 790 unsigned long flags=0;
792 unsigned size, nbufs, bytes; 791 unsigned size, nbufs, bytes;
793 int retval; 792 int retval;
794 793
795 down(&q->lock); 794 mutex_lock(&q->lock);
796 795
797 nbufs = 1; size = 0; 796 nbufs = 1; size = 0;
798 q->ops->buf_setup(q,&nbufs,&size); 797 q->ops->buf_setup(q,&nbufs,&size);
@@ -860,14 +859,14 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
860 } 859 }
861 860
862 done: 861 done:
863 up(&q->lock); 862 mutex_unlock(&q->lock);
864 return retval; 863 return retval;
865} 864}
866 865
867int videobuf_read_start(struct videobuf_queue *q) 866int videobuf_read_start(struct videobuf_queue *q)
868{ 867{
869 enum v4l2_field field; 868 enum v4l2_field field;
870 unsigned long flags; 869 unsigned long flags=0;
871 int count = 0, size = 0; 870 int count = 0, size = 0;
872 int err, i; 871 int err, i;
873 872
@@ -919,10 +918,10 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
919{ 918{
920 unsigned int *fc, bytes; 919 unsigned int *fc, bytes;
921 int err, retval; 920 int err, retval;
922 unsigned long flags; 921 unsigned long flags=0;
923 922
924 dprintk(2,"%s\n",__FUNCTION__); 923 dprintk(2,"%s\n",__FUNCTION__);
925 down(&q->lock); 924 mutex_lock(&q->lock);
926 retval = -EBUSY; 925 retval = -EBUSY;
927 if (q->streaming) 926 if (q->streaming)
928 goto done; 927 goto done;
@@ -996,7 +995,7 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
996 } 995 }
997 996
998 done: 997 done:
999 up(&q->lock); 998 mutex_unlock(&q->lock);
1000 return retval; 999 return retval;
1001} 1000}
1002 1001
@@ -1007,7 +1006,7 @@ unsigned int videobuf_poll_stream(struct file *file,
1007 struct videobuf_buffer *buf = NULL; 1006 struct videobuf_buffer *buf = NULL;
1008 unsigned int rc = 0; 1007 unsigned int rc = 0;
1009 1008
1010 down(&q->lock); 1009 mutex_lock(&q->lock);
1011 if (q->streaming) { 1010 if (q->streaming) {
1012 if (!list_empty(&q->stream)) 1011 if (!list_empty(&q->stream))
1013 buf = list_entry(q->stream.next, 1012 buf = list_entry(q->stream.next,
@@ -1035,7 +1034,7 @@ unsigned int videobuf_poll_stream(struct file *file,
1035 buf->state == STATE_ERROR) 1034 buf->state == STATE_ERROR)
1036 rc = POLLIN|POLLRDNORM; 1035 rc = POLLIN|POLLRDNORM;
1037 } 1036 }
1038 up(&q->lock); 1037 mutex_unlock(&q->lock);
1039 return rc; 1038 return rc;
1040} 1039}
1041 1040
@@ -1064,7 +1063,7 @@ videobuf_vm_close(struct vm_area_struct *vma)
1064 map->count--; 1063 map->count--;
1065 if (0 == map->count) { 1064 if (0 == map->count) {
1066 dprintk(1,"munmap %p q=%p\n",map,q); 1065 dprintk(1,"munmap %p q=%p\n",map,q);
1067 down(&q->lock); 1066 mutex_lock(&q->lock);
1068 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 1067 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
1069 if (NULL == q->bufs[i]) 1068 if (NULL == q->bufs[i])
1070 continue; 1069 continue;
@@ -1076,7 +1075,7 @@ videobuf_vm_close(struct vm_area_struct *vma)
1076 q->bufs[i]->baddr = 0; 1075 q->bufs[i]->baddr = 0;
1077 q->ops->buf_release(q,q->bufs[i]); 1076 q->ops->buf_release(q,q->bufs[i]);
1078 } 1077 }
1079 up(&q->lock); 1078 mutex_unlock(&q->lock);
1080 kfree(map); 1079 kfree(map);
1081 } 1080 }
1082 return; 1081 return;
@@ -1170,7 +1169,7 @@ int videobuf_mmap_mapper(struct videobuf_queue *q,
1170 unsigned int first,last,size,i; 1169 unsigned int first,last,size,i;
1171 int retval; 1170 int retval;
1172 1171
1173 down(&q->lock); 1172 mutex_lock(&q->lock);
1174 retval = -EINVAL; 1173 retval = -EINVAL;
1175 if (!(vma->vm_flags & VM_WRITE)) { 1174 if (!(vma->vm_flags & VM_WRITE)) {
1176 dprintk(1,"mmap app bug: PROT_WRITE please\n"); 1175 dprintk(1,"mmap app bug: PROT_WRITE please\n");
@@ -1238,7 +1237,7 @@ int videobuf_mmap_mapper(struct videobuf_queue *q,
1238 retval = 0; 1237 retval = 0;
1239 1238
1240 done: 1239 done:
1241 up(&q->lock); 1240 mutex_unlock(&q->lock);
1242 return retval; 1241 return retval;
1243} 1242}
1244 1243
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index 078880e4c8c0..75e3d41382f2 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -224,13 +224,13 @@ int video_exclusive_open(struct inode *inode, struct file *file)
224 struct video_device *vfl = video_devdata(file); 224 struct video_device *vfl = video_devdata(file);
225 int retval = 0; 225 int retval = 0;
226 226
227 down(&vfl->lock); 227 mutex_lock(&vfl->lock);
228 if (vfl->users) { 228 if (vfl->users) {
229 retval = -EBUSY; 229 retval = -EBUSY;
230 } else { 230 } else {
231 vfl->users++; 231 vfl->users++;
232 } 232 }
233 up(&vfl->lock); 233 mutex_unlock(&vfl->lock);
234 return retval; 234 return retval;
235} 235}
236 236
@@ -279,23 +279,23 @@ int video_register_device(struct video_device *vfd, int type, int nr)
279 switch(type) 279 switch(type)
280 { 280 {
281 case VFL_TYPE_GRABBER: 281 case VFL_TYPE_GRABBER:
282 base=0; 282 base=MINOR_VFL_TYPE_GRABBER_MIN;
283 end=64; 283 end=MINOR_VFL_TYPE_GRABBER_MAX+1;
284 name_base = "video"; 284 name_base = "video";
285 break; 285 break;
286 case VFL_TYPE_VTX: 286 case VFL_TYPE_VTX:
287 base=192; 287 base=MINOR_VFL_TYPE_VTX_MIN;
288 end=224; 288 end=MINOR_VFL_TYPE_VTX_MAX+1;
289 name_base = "vtx"; 289 name_base = "vtx";
290 break; 290 break;
291 case VFL_TYPE_VBI: 291 case VFL_TYPE_VBI:
292 base=224; 292 base=MINOR_VFL_TYPE_VBI_MIN;
293 end=256; 293 end=MINOR_VFL_TYPE_VBI_MAX+1;
294 name_base = "vbi"; 294 name_base = "vbi";
295 break; 295 break;
296 case VFL_TYPE_RADIO: 296 case VFL_TYPE_RADIO:
297 base=64; 297 base=MINOR_VFL_TYPE_RADIO_MIN;
298 end=128; 298 end=MINOR_VFL_TYPE_RADIO_MAX+1;
299 name_base = "radio"; 299 name_base = "radio";
300 break; 300 break;
301 default: 301 default:
@@ -328,7 +328,7 @@ int video_register_device(struct video_device *vfd, int type, int nr)
328 sprintf(vfd->devfs_name, "v4l/%s%d", name_base, i - base); 328 sprintf(vfd->devfs_name, "v4l/%s%d", name_base, i - base);
329 devfs_mk_cdev(MKDEV(VIDEO_MAJOR, vfd->minor), 329 devfs_mk_cdev(MKDEV(VIDEO_MAJOR, vfd->minor),
330 S_IFCHR | S_IRUSR | S_IWUSR, vfd->devfs_name); 330 S_IFCHR | S_IRUSR | S_IWUSR, vfd->devfs_name);
331 init_MUTEX(&vfd->lock); 331 mutex_init(&vfd->lock);
332 332
333 /* sysfs class */ 333 /* sysfs class */
334 memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev)); 334 memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index c8fd8238904d..0229819d0aac 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -42,6 +42,7 @@
42#include <linux/videodev.h> 42#include <linux/videodev.h>
43#include <linux/videodev2.h> 43#include <linux/videodev2.h>
44#include <linux/video_decoder.h> 44#include <linux/video_decoder.h>
45#include <linux/mutex.h>
45 46
46#include <asm/paccess.h> 47#include <asm/paccess.h>
47#include <asm/io.h> 48#include <asm/io.h>
@@ -245,7 +246,7 @@ struct vino_framebuffer_queue {
245 struct vino_framebuffer *buffer[VINO_FRAMEBUFFER_COUNT_MAX]; 246 struct vino_framebuffer *buffer[VINO_FRAMEBUFFER_COUNT_MAX];
246 247
247 spinlock_t queue_lock; 248 spinlock_t queue_lock;
248 struct semaphore queue_sem; 249 struct mutex queue_mutex;
249 wait_queue_head_t frame_wait_queue; 250 wait_queue_head_t frame_wait_queue;
250}; 251};
251 252
@@ -283,7 +284,7 @@ struct vino_channel_settings {
283 /* the driver is currently processing the queue */ 284 /* the driver is currently processing the queue */
284 int capturing; 285 int capturing;
285 286
286 struct semaphore sem; 287 struct mutex mutex;
287 spinlock_t capture_lock; 288 spinlock_t capture_lock;
288 289
289 unsigned int users; 290 unsigned int users;
@@ -1131,11 +1132,11 @@ static void vino_queue_free(struct vino_framebuffer_queue *q)
1131 if (q->type != VINO_MEMORY_MMAP) 1132 if (q->type != VINO_MEMORY_MMAP)
1132 return; 1133 return;
1133 1134
1134 down(&q->queue_sem); 1135 mutex_lock(&q->queue_mutex);
1135 1136
1136 vino_queue_free_with_count(q, q->length); 1137 vino_queue_free_with_count(q, q->length);
1137 1138
1138 up(&q->queue_sem); 1139 mutex_unlock(&q->queue_mutex);
1139} 1140}
1140 1141
1141static int vino_queue_init(struct vino_framebuffer_queue *q, 1142static int vino_queue_init(struct vino_framebuffer_queue *q,
@@ -1159,7 +1160,7 @@ static int vino_queue_init(struct vino_framebuffer_queue *q,
1159 if (*length < 1) 1160 if (*length < 1)
1160 return -EINVAL; 1161 return -EINVAL;
1161 1162
1162 down(&q->queue_sem); 1163 mutex_lock(&q->queue_mutex);
1163 1164
1164 if (*length > VINO_FRAMEBUFFER_COUNT_MAX) 1165 if (*length > VINO_FRAMEBUFFER_COUNT_MAX)
1165 *length = VINO_FRAMEBUFFER_COUNT_MAX; 1166 *length = VINO_FRAMEBUFFER_COUNT_MAX;
@@ -1211,7 +1212,7 @@ static int vino_queue_init(struct vino_framebuffer_queue *q,
1211 q->magic = VINO_QUEUE_MAGIC; 1212 q->magic = VINO_QUEUE_MAGIC;
1212 } 1213 }
1213 1214
1214 up(&q->queue_sem); 1215 mutex_unlock(&q->queue_mutex);
1215 1216
1216 return ret; 1217 return ret;
1217} 1218}
@@ -4045,7 +4046,7 @@ static int vino_open(struct inode *inode, struct file *file)
4045 dprintk("open(): channel = %c\n", 4046 dprintk("open(): channel = %c\n",
4046 (vcs->channel == VINO_CHANNEL_A) ? 'A' : 'B'); 4047 (vcs->channel == VINO_CHANNEL_A) ? 'A' : 'B');
4047 4048
4048 down(&vcs->sem); 4049 mutex_lock(&vcs->mutex);
4049 4050
4050 if (vcs->users) { 4051 if (vcs->users) {
4051 dprintk("open(): driver busy\n"); 4052 dprintk("open(): driver busy\n");
@@ -4062,7 +4063,7 @@ static int vino_open(struct inode *inode, struct file *file)
4062 vcs->users++; 4063 vcs->users++;
4063 4064
4064 out: 4065 out:
4065 up(&vcs->sem); 4066 mutex_unlock(&vcs->mutex);
4066 4067
4067 dprintk("open(): %s!\n", ret ? "failed" : "complete"); 4068 dprintk("open(): %s!\n", ret ? "failed" : "complete");
4068 4069
@@ -4075,7 +4076,7 @@ static int vino_close(struct inode *inode, struct file *file)
4075 struct vino_channel_settings *vcs = video_get_drvdata(dev); 4076 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4076 dprintk("close():\n"); 4077 dprintk("close():\n");
4077 4078
4078 down(&vcs->sem); 4079 mutex_lock(&vcs->mutex);
4079 4080
4080 vcs->users--; 4081 vcs->users--;
4081 4082
@@ -4087,7 +4088,7 @@ static int vino_close(struct inode *inode, struct file *file)
4087 vino_queue_free(&vcs->fb_queue); 4088 vino_queue_free(&vcs->fb_queue);
4088 } 4089 }
4089 4090
4090 up(&vcs->sem); 4091 mutex_unlock(&vcs->mutex);
4091 4092
4092 return 0; 4093 return 0;
4093} 4094}
@@ -4130,7 +4131,7 @@ static int vino_mmap(struct file *file, struct vm_area_struct *vma)
4130 4131
4131 // TODO: reject mmap if already mapped 4132 // TODO: reject mmap if already mapped
4132 4133
4133 if (down_interruptible(&vcs->sem)) 4134 if (mutex_lock_interruptible(&vcs->mutex))
4134 return -EINTR; 4135 return -EINTR;
4135 4136
4136 if (vcs->reading) { 4137 if (vcs->reading) {
@@ -4214,7 +4215,7 @@ found:
4214 vma->vm_ops = &vino_vm_ops; 4215 vma->vm_ops = &vino_vm_ops;
4215 4216
4216out: 4217out:
4217 up(&vcs->sem); 4218 mutex_unlock(&vcs->mutex);
4218 4219
4219 return ret; 4220 return ret;
4220} 4221}
@@ -4374,12 +4375,12 @@ static int vino_ioctl(struct inode *inode, struct file *file,
4374 struct vino_channel_settings *vcs = video_get_drvdata(dev); 4375 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4375 int ret; 4376 int ret;
4376 4377
4377 if (down_interruptible(&vcs->sem)) 4378 if (mutex_lock_interruptible(&vcs->mutex))
4378 return -EINTR; 4379 return -EINTR;
4379 4380
4380 ret = video_usercopy(inode, file, cmd, arg, vino_do_ioctl); 4381 ret = video_usercopy(inode, file, cmd, arg, vino_do_ioctl);
4381 4382
4382 up(&vcs->sem); 4383 mutex_unlock(&vcs->mutex);
4383 4384
4384 return ret; 4385 return ret;
4385} 4386}
@@ -4564,10 +4565,10 @@ static int vino_init_channel_settings(struct vino_channel_settings *vcs,
4564 4565
4565 vcs->capturing = 0; 4566 vcs->capturing = 0;
4566 4567
4567 init_MUTEX(&vcs->sem); 4568 mutex_init(&vcs->mutex);
4568 spin_lock_init(&vcs->capture_lock); 4569 spin_lock_init(&vcs->capture_lock);
4569 4570
4570 init_MUTEX(&vcs->fb_queue.queue_sem); 4571 mutex_init(&vcs->fb_queue.queue_mutex);
4571 spin_lock_init(&vcs->fb_queue.queue_lock); 4572 spin_lock_init(&vcs->fb_queue.queue_lock);
4572 init_waitqueue_head(&vcs->fb_queue.frame_wait_queue); 4573 init_waitqueue_head(&vcs->fb_queue.frame_wait_queue);
4573 4574
diff --git a/drivers/mmc/pxamci.c b/drivers/mmc/pxamci.c
index 285d7d068097..c32fad1ce51c 100644
--- a/drivers/mmc/pxamci.c
+++ b/drivers/mmc/pxamci.c
@@ -438,7 +438,7 @@ static int pxamci_probe(struct platform_device *pdev)
438 438
439 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 439 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
440 irq = platform_get_irq(pdev, 0); 440 irq = platform_get_irq(pdev, 0);
441 if (!r || irq == NO_IRQ) 441 if (!r || irq < 0)
442 return -ENXIO; 442 return -ENXIO;
443 443
444 r = request_mem_region(r->start, SZ_4K, DRIVER_NAME); 444 r = request_mem_region(r->start, SZ_4K, DRIVER_NAME);
diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index e58d4c50c2e1..f5ee064ab6b2 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -1605,7 +1605,7 @@ static void rtl8139_thread (void *_data)
1605 if (tp->watchdog_fired) { 1605 if (tp->watchdog_fired) {
1606 tp->watchdog_fired = 0; 1606 tp->watchdog_fired = 0;
1607 rtl8139_tx_timeout_task(_data); 1607 rtl8139_tx_timeout_task(_data);
1608 } else if (rtnl_shlock_nowait() == 0) { 1608 } else if (rtnl_trylock()) {
1609 rtl8139_thread_iter (dev, tp, tp->mmio_addr); 1609 rtl8139_thread_iter (dev, tp, tp->mmio_addr);
1610 rtnl_unlock (); 1610 rtnl_unlock ();
1611 } else { 1611 } else {
diff --git a/drivers/net/arm/am79c961a.c b/drivers/net/arm/am79c961a.c
index 53e3afc1b7b7..09d5c3f26985 100644
--- a/drivers/net/arm/am79c961a.c
+++ b/drivers/net/arm/am79c961a.c
@@ -696,7 +696,9 @@ static int __init am79c961_probe(struct platform_device *pdev)
696 dev->base_addr = res->start; 696 dev->base_addr = res->start;
697 dev->irq = platform_get_irq(pdev, 0); 697 dev->irq = platform_get_irq(pdev, 0);
698 698
699 ret = -ENODEV; 699 ret = -ENODEV;
700 if (dev->irq < 0)
701 goto nodev;
700 if (!request_region(dev->base_addr, 0x18, dev->name)) 702 if (!request_region(dev->base_addr, 0x18, dev->name))
701 goto nodev; 703 goto nodev;
702 704
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index b787b6582e50..7d213707008a 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -14,8 +14,8 @@
14 14
15#define DRV_MODULE_NAME "bnx2" 15#define DRV_MODULE_NAME "bnx2"
16#define PFX DRV_MODULE_NAME ": " 16#define PFX DRV_MODULE_NAME ": "
17#define DRV_MODULE_VERSION "1.4.31" 17#define DRV_MODULE_VERSION "1.4.38"
18#define DRV_MODULE_RELDATE "January 19, 2006" 18#define DRV_MODULE_RELDATE "February 10, 2006"
19 19
20#define RUN_AT(x) (jiffies + (x)) 20#define RUN_AT(x) (jiffies + (x))
21 21
@@ -360,6 +360,8 @@ bnx2_netif_start(struct bnx2 *bp)
360static void 360static void
361bnx2_free_mem(struct bnx2 *bp) 361bnx2_free_mem(struct bnx2 *bp)
362{ 362{
363 int i;
364
363 if (bp->stats_blk) { 365 if (bp->stats_blk) {
364 pci_free_consistent(bp->pdev, sizeof(struct statistics_block), 366 pci_free_consistent(bp->pdev, sizeof(struct statistics_block),
365 bp->stats_blk, bp->stats_blk_mapping); 367 bp->stats_blk, bp->stats_blk_mapping);
@@ -378,19 +380,23 @@ bnx2_free_mem(struct bnx2 *bp)
378 } 380 }
379 kfree(bp->tx_buf_ring); 381 kfree(bp->tx_buf_ring);
380 bp->tx_buf_ring = NULL; 382 bp->tx_buf_ring = NULL;
381 if (bp->rx_desc_ring) { 383 for (i = 0; i < bp->rx_max_ring; i++) {
382 pci_free_consistent(bp->pdev, 384 if (bp->rx_desc_ring[i])
383 sizeof(struct rx_bd) * RX_DESC_CNT, 385 pci_free_consistent(bp->pdev,
384 bp->rx_desc_ring, bp->rx_desc_mapping); 386 sizeof(struct rx_bd) * RX_DESC_CNT,
385 bp->rx_desc_ring = NULL; 387 bp->rx_desc_ring[i],
386 } 388 bp->rx_desc_mapping[i]);
387 kfree(bp->rx_buf_ring); 389 bp->rx_desc_ring[i] = NULL;
390 }
391 vfree(bp->rx_buf_ring);
388 bp->rx_buf_ring = NULL; 392 bp->rx_buf_ring = NULL;
389} 393}
390 394
391static int 395static int
392bnx2_alloc_mem(struct bnx2 *bp) 396bnx2_alloc_mem(struct bnx2 *bp)
393{ 397{
398 int i;
399
394 bp->tx_buf_ring = kmalloc(sizeof(struct sw_bd) * TX_DESC_CNT, 400 bp->tx_buf_ring = kmalloc(sizeof(struct sw_bd) * TX_DESC_CNT,
395 GFP_KERNEL); 401 GFP_KERNEL);
396 if (bp->tx_buf_ring == NULL) 402 if (bp->tx_buf_ring == NULL)
@@ -404,18 +410,23 @@ bnx2_alloc_mem(struct bnx2 *bp)
404 if (bp->tx_desc_ring == NULL) 410 if (bp->tx_desc_ring == NULL)
405 goto alloc_mem_err; 411 goto alloc_mem_err;
406 412
407 bp->rx_buf_ring = kmalloc(sizeof(struct sw_bd) * RX_DESC_CNT, 413 bp->rx_buf_ring = vmalloc(sizeof(struct sw_bd) * RX_DESC_CNT *
408 GFP_KERNEL); 414 bp->rx_max_ring);
409 if (bp->rx_buf_ring == NULL) 415 if (bp->rx_buf_ring == NULL)
410 goto alloc_mem_err; 416 goto alloc_mem_err;
411 417
412 memset(bp->rx_buf_ring, 0, sizeof(struct sw_bd) * RX_DESC_CNT); 418 memset(bp->rx_buf_ring, 0, sizeof(struct sw_bd) * RX_DESC_CNT *
413 bp->rx_desc_ring = pci_alloc_consistent(bp->pdev, 419 bp->rx_max_ring);
414 sizeof(struct rx_bd) * 420
415 RX_DESC_CNT, 421 for (i = 0; i < bp->rx_max_ring; i++) {
416 &bp->rx_desc_mapping); 422 bp->rx_desc_ring[i] =
417 if (bp->rx_desc_ring == NULL) 423 pci_alloc_consistent(bp->pdev,
418 goto alloc_mem_err; 424 sizeof(struct rx_bd) * RX_DESC_CNT,
425 &bp->rx_desc_mapping[i]);
426 if (bp->rx_desc_ring[i] == NULL)
427 goto alloc_mem_err;
428
429 }
419 430
420 bp->status_blk = pci_alloc_consistent(bp->pdev, 431 bp->status_blk = pci_alloc_consistent(bp->pdev,
421 sizeof(struct status_block), 432 sizeof(struct status_block),
@@ -1520,7 +1531,7 @@ bnx2_alloc_rx_skb(struct bnx2 *bp, u16 index)
1520 struct sk_buff *skb; 1531 struct sk_buff *skb;
1521 struct sw_bd *rx_buf = &bp->rx_buf_ring[index]; 1532 struct sw_bd *rx_buf = &bp->rx_buf_ring[index];
1522 dma_addr_t mapping; 1533 dma_addr_t mapping;
1523 struct rx_bd *rxbd = &bp->rx_desc_ring[index]; 1534 struct rx_bd *rxbd = &bp->rx_desc_ring[RX_RING(index)][RX_IDX(index)];
1524 unsigned long align; 1535 unsigned long align;
1525 1536
1526 skb = dev_alloc_skb(bp->rx_buf_size); 1537 skb = dev_alloc_skb(bp->rx_buf_size);
@@ -1656,23 +1667,30 @@ static inline void
1656bnx2_reuse_rx_skb(struct bnx2 *bp, struct sk_buff *skb, 1667bnx2_reuse_rx_skb(struct bnx2 *bp, struct sk_buff *skb,
1657 u16 cons, u16 prod) 1668 u16 cons, u16 prod)
1658{ 1669{
1659 struct sw_bd *cons_rx_buf = &bp->rx_buf_ring[cons]; 1670 struct sw_bd *cons_rx_buf, *prod_rx_buf;
1660 struct sw_bd *prod_rx_buf = &bp->rx_buf_ring[prod]; 1671 struct rx_bd *cons_bd, *prod_bd;
1661 struct rx_bd *cons_bd = &bp->rx_desc_ring[cons]; 1672
1662 struct rx_bd *prod_bd = &bp->rx_desc_ring[prod]; 1673 cons_rx_buf = &bp->rx_buf_ring[cons];
1674 prod_rx_buf = &bp->rx_buf_ring[prod];
1663 1675
1664 pci_dma_sync_single_for_device(bp->pdev, 1676 pci_dma_sync_single_for_device(bp->pdev,
1665 pci_unmap_addr(cons_rx_buf, mapping), 1677 pci_unmap_addr(cons_rx_buf, mapping),
1666 bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE); 1678 bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
1667 1679
1668 prod_rx_buf->skb = cons_rx_buf->skb; 1680 bp->rx_prod_bseq += bp->rx_buf_use_size;
1669 pci_unmap_addr_set(prod_rx_buf, mapping,
1670 pci_unmap_addr(cons_rx_buf, mapping));
1671 1681
1672 memcpy(prod_bd, cons_bd, 8); 1682 prod_rx_buf->skb = skb;
1673 1683
1674 bp->rx_prod_bseq += bp->rx_buf_use_size; 1684 if (cons == prod)
1685 return;
1675 1686
1687 pci_unmap_addr_set(prod_rx_buf, mapping,
1688 pci_unmap_addr(cons_rx_buf, mapping));
1689
1690 cons_bd = &bp->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)];
1691 prod_bd = &bp->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
1692 prod_bd->rx_bd_haddr_hi = cons_bd->rx_bd_haddr_hi;
1693 prod_bd->rx_bd_haddr_lo = cons_bd->rx_bd_haddr_lo;
1676} 1694}
1677 1695
1678static int 1696static int
@@ -1699,14 +1717,19 @@ bnx2_rx_int(struct bnx2 *bp, int budget)
1699 u32 status; 1717 u32 status;
1700 struct sw_bd *rx_buf; 1718 struct sw_bd *rx_buf;
1701 struct sk_buff *skb; 1719 struct sk_buff *skb;
1720 dma_addr_t dma_addr;
1702 1721
1703 sw_ring_cons = RX_RING_IDX(sw_cons); 1722 sw_ring_cons = RX_RING_IDX(sw_cons);
1704 sw_ring_prod = RX_RING_IDX(sw_prod); 1723 sw_ring_prod = RX_RING_IDX(sw_prod);
1705 1724
1706 rx_buf = &bp->rx_buf_ring[sw_ring_cons]; 1725 rx_buf = &bp->rx_buf_ring[sw_ring_cons];
1707 skb = rx_buf->skb; 1726 skb = rx_buf->skb;
1708 pci_dma_sync_single_for_cpu(bp->pdev, 1727
1709 pci_unmap_addr(rx_buf, mapping), 1728 rx_buf->skb = NULL;
1729
1730 dma_addr = pci_unmap_addr(rx_buf, mapping);
1731
1732 pci_dma_sync_single_for_cpu(bp->pdev, dma_addr,
1710 bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE); 1733 bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
1711 1734
1712 rx_hdr = (struct l2_fhdr *) skb->data; 1735 rx_hdr = (struct l2_fhdr *) skb->data;
@@ -1747,8 +1770,7 @@ bnx2_rx_int(struct bnx2 *bp, int budget)
1747 skb = new_skb; 1770 skb = new_skb;
1748 } 1771 }
1749 else if (bnx2_alloc_rx_skb(bp, sw_ring_prod) == 0) { 1772 else if (bnx2_alloc_rx_skb(bp, sw_ring_prod) == 0) {
1750 pci_unmap_single(bp->pdev, 1773 pci_unmap_single(bp->pdev, dma_addr,
1751 pci_unmap_addr(rx_buf, mapping),
1752 bp->rx_buf_use_size, PCI_DMA_FROMDEVICE); 1774 bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
1753 1775
1754 skb_reserve(skb, bp->rx_offset); 1776 skb_reserve(skb, bp->rx_offset);
@@ -1794,8 +1816,6 @@ reuse_rx:
1794 rx_pkt++; 1816 rx_pkt++;
1795 1817
1796next_rx: 1818next_rx:
1797 rx_buf->skb = NULL;
1798
1799 sw_cons = NEXT_RX_BD(sw_cons); 1819 sw_cons = NEXT_RX_BD(sw_cons);
1800 sw_prod = NEXT_RX_BD(sw_prod); 1820 sw_prod = NEXT_RX_BD(sw_prod);
1801 1821
@@ -3340,27 +3360,35 @@ bnx2_init_rx_ring(struct bnx2 *bp)
3340 bp->hw_rx_cons = 0; 3360 bp->hw_rx_cons = 0;
3341 bp->rx_prod_bseq = 0; 3361 bp->rx_prod_bseq = 0;
3342 3362
3343 rxbd = &bp->rx_desc_ring[0]; 3363 for (i = 0; i < bp->rx_max_ring; i++) {
3344 for (i = 0; i < MAX_RX_DESC_CNT; i++, rxbd++) { 3364 int j;
3345 rxbd->rx_bd_len = bp->rx_buf_use_size;
3346 rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
3347 }
3348 3365
3349 rxbd->rx_bd_haddr_hi = (u64) bp->rx_desc_mapping >> 32; 3366 rxbd = &bp->rx_desc_ring[i][0];
3350 rxbd->rx_bd_haddr_lo = (u64) bp->rx_desc_mapping & 0xffffffff; 3367 for (j = 0; j < MAX_RX_DESC_CNT; j++, rxbd++) {
3368 rxbd->rx_bd_len = bp->rx_buf_use_size;
3369 rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
3370 }
3371 if (i == (bp->rx_max_ring - 1))
3372 j = 0;
3373 else
3374 j = i + 1;
3375 rxbd->rx_bd_haddr_hi = (u64) bp->rx_desc_mapping[j] >> 32;
3376 rxbd->rx_bd_haddr_lo = (u64) bp->rx_desc_mapping[j] &
3377 0xffffffff;
3378 }
3351 3379
3352 val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE; 3380 val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
3353 val |= BNX2_L2CTX_CTX_TYPE_SIZE_L2; 3381 val |= BNX2_L2CTX_CTX_TYPE_SIZE_L2;
3354 val |= 0x02 << 8; 3382 val |= 0x02 << 8;
3355 CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_CTX_TYPE, val); 3383 CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_CTX_TYPE, val);
3356 3384
3357 val = (u64) bp->rx_desc_mapping >> 32; 3385 val = (u64) bp->rx_desc_mapping[0] >> 32;
3358 CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_HI, val); 3386 CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_HI, val);
3359 3387
3360 val = (u64) bp->rx_desc_mapping & 0xffffffff; 3388 val = (u64) bp->rx_desc_mapping[0] & 0xffffffff;
3361 CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_LO, val); 3389 CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_LO, val);
3362 3390
3363 for ( ;ring_prod < bp->rx_ring_size; ) { 3391 for (i = 0; i < bp->rx_ring_size; i++) {
3364 if (bnx2_alloc_rx_skb(bp, ring_prod) < 0) { 3392 if (bnx2_alloc_rx_skb(bp, ring_prod) < 0) {
3365 break; 3393 break;
3366 } 3394 }
@@ -3375,6 +3403,29 @@ bnx2_init_rx_ring(struct bnx2 *bp)
3375} 3403}
3376 3404
3377static void 3405static void
3406bnx2_set_rx_ring_size(struct bnx2 *bp, u32 size)
3407{
3408 u32 num_rings, max;
3409
3410 bp->rx_ring_size = size;
3411 num_rings = 1;
3412 while (size > MAX_RX_DESC_CNT) {
3413 size -= MAX_RX_DESC_CNT;
3414 num_rings++;
3415 }
3416 /* round to next power of 2 */
3417 max = MAX_RX_RINGS;
3418 while ((max & num_rings) == 0)
3419 max >>= 1;
3420
3421 if (num_rings != max)
3422 max <<= 1;
3423
3424 bp->rx_max_ring = max;
3425 bp->rx_max_ring_idx = (bp->rx_max_ring * RX_DESC_CNT) - 1;
3426}
3427
3428static void
3378bnx2_free_tx_skbs(struct bnx2 *bp) 3429bnx2_free_tx_skbs(struct bnx2 *bp)
3379{ 3430{
3380 int i; 3431 int i;
@@ -3419,7 +3470,7 @@ bnx2_free_rx_skbs(struct bnx2 *bp)
3419 if (bp->rx_buf_ring == NULL) 3470 if (bp->rx_buf_ring == NULL)
3420 return; 3471 return;
3421 3472
3422 for (i = 0; i < RX_DESC_CNT; i++) { 3473 for (i = 0; i < bp->rx_max_ring_idx; i++) {
3423 struct sw_bd *rx_buf = &bp->rx_buf_ring[i]; 3474 struct sw_bd *rx_buf = &bp->rx_buf_ring[i];
3424 struct sk_buff *skb = rx_buf->skb; 3475 struct sk_buff *skb = rx_buf->skb;
3425 3476
@@ -3506,74 +3557,9 @@ bnx2_test_registers(struct bnx2 *bp)
3506 { 0x0c00, 0, 0x00000000, 0x00000001 }, 3557 { 0x0c00, 0, 0x00000000, 0x00000001 },
3507 { 0x0c04, 0, 0x00000000, 0x03ff0001 }, 3558 { 0x0c04, 0, 0x00000000, 0x03ff0001 },
3508 { 0x0c08, 0, 0x0f0ff073, 0x00000000 }, 3559 { 0x0c08, 0, 0x0f0ff073, 0x00000000 },
3509 { 0x0c0c, 0, 0x00ffffff, 0x00000000 },
3510 { 0x0c30, 0, 0x00000000, 0xffffffff },
3511 { 0x0c34, 0, 0x00000000, 0xffffffff },
3512 { 0x0c38, 0, 0x00000000, 0xffffffff },
3513 { 0x0c3c, 0, 0x00000000, 0xffffffff },
3514 { 0x0c40, 0, 0x00000000, 0xffffffff },
3515 { 0x0c44, 0, 0x00000000, 0xffffffff },
3516 { 0x0c48, 0, 0x00000000, 0x0007ffff },
3517 { 0x0c4c, 0, 0x00000000, 0xffffffff },
3518 { 0x0c50, 0, 0x00000000, 0xffffffff },
3519 { 0x0c54, 0, 0x00000000, 0xffffffff },
3520 { 0x0c58, 0, 0x00000000, 0xffffffff },
3521 { 0x0c5c, 0, 0x00000000, 0xffffffff },
3522 { 0x0c60, 0, 0x00000000, 0xffffffff },
3523 { 0x0c64, 0, 0x00000000, 0xffffffff },
3524 { 0x0c68, 0, 0x00000000, 0xffffffff },
3525 { 0x0c6c, 0, 0x00000000, 0xffffffff },
3526 { 0x0c70, 0, 0x00000000, 0xffffffff },
3527 { 0x0c74, 0, 0x00000000, 0xffffffff },
3528 { 0x0c78, 0, 0x00000000, 0xffffffff },
3529 { 0x0c7c, 0, 0x00000000, 0xffffffff },
3530 { 0x0c80, 0, 0x00000000, 0xffffffff },
3531 { 0x0c84, 0, 0x00000000, 0xffffffff },
3532 { 0x0c88, 0, 0x00000000, 0xffffffff },
3533 { 0x0c8c, 0, 0x00000000, 0xffffffff },
3534 { 0x0c90, 0, 0x00000000, 0xffffffff },
3535 { 0x0c94, 0, 0x00000000, 0xffffffff },
3536 { 0x0c98, 0, 0x00000000, 0xffffffff },
3537 { 0x0c9c, 0, 0x00000000, 0xffffffff },
3538 { 0x0ca0, 0, 0x00000000, 0xffffffff },
3539 { 0x0ca4, 0, 0x00000000, 0xffffffff },
3540 { 0x0ca8, 0, 0x00000000, 0x0007ffff },
3541 { 0x0cac, 0, 0x00000000, 0xffffffff },
3542 { 0x0cb0, 0, 0x00000000, 0xffffffff },
3543 { 0x0cb4, 0, 0x00000000, 0xffffffff },
3544 { 0x0cb8, 0, 0x00000000, 0xffffffff },
3545 { 0x0cbc, 0, 0x00000000, 0xffffffff },
3546 { 0x0cc0, 0, 0x00000000, 0xffffffff },
3547 { 0x0cc4, 0, 0x00000000, 0xffffffff },
3548 { 0x0cc8, 0, 0x00000000, 0xffffffff },
3549 { 0x0ccc, 0, 0x00000000, 0xffffffff },
3550 { 0x0cd0, 0, 0x00000000, 0xffffffff },
3551 { 0x0cd4, 0, 0x00000000, 0xffffffff },
3552 { 0x0cd8, 0, 0x00000000, 0xffffffff },
3553 { 0x0cdc, 0, 0x00000000, 0xffffffff },
3554 { 0x0ce0, 0, 0x00000000, 0xffffffff },
3555 { 0x0ce4, 0, 0x00000000, 0xffffffff },
3556 { 0x0ce8, 0, 0x00000000, 0xffffffff },
3557 { 0x0cec, 0, 0x00000000, 0xffffffff },
3558 { 0x0cf0, 0, 0x00000000, 0xffffffff },
3559 { 0x0cf4, 0, 0x00000000, 0xffffffff },
3560 { 0x0cf8, 0, 0x00000000, 0xffffffff },
3561 { 0x0cfc, 0, 0x00000000, 0xffffffff },
3562 { 0x0d00, 0, 0x00000000, 0xffffffff },
3563 { 0x0d04, 0, 0x00000000, 0xffffffff },
3564 3560
3565 { 0x1000, 0, 0x00000000, 0x00000001 }, 3561 { 0x1000, 0, 0x00000000, 0x00000001 },
3566 { 0x1004, 0, 0x00000000, 0x000f0001 }, 3562 { 0x1004, 0, 0x00000000, 0x000f0001 },
3567 { 0x1044, 0, 0x00000000, 0xffc003ff },
3568 { 0x1080, 0, 0x00000000, 0x0001ffff },
3569 { 0x1084, 0, 0x00000000, 0xffffffff },
3570 { 0x1088, 0, 0x00000000, 0xffffffff },
3571 { 0x108c, 0, 0x00000000, 0xffffffff },
3572 { 0x1090, 0, 0x00000000, 0xffffffff },
3573 { 0x1094, 0, 0x00000000, 0xffffffff },
3574 { 0x1098, 0, 0x00000000, 0xffffffff },
3575 { 0x109c, 0, 0x00000000, 0xffffffff },
3576 { 0x10a0, 0, 0x00000000, 0xffffffff },
3577 3563
3578 { 0x1408, 0, 0x01c00800, 0x00000000 }, 3564 { 0x1408, 0, 0x01c00800, 0x00000000 },
3579 { 0x149c, 0, 0x8000ffff, 0x00000000 }, 3565 { 0x149c, 0, 0x8000ffff, 0x00000000 },
@@ -3585,111 +3571,9 @@ bnx2_test_registers(struct bnx2 *bp)
3585 { 0x14c4, 0, 0x00003fff, 0x00000000 }, 3571 { 0x14c4, 0, 0x00003fff, 0x00000000 },
3586 { 0x14cc, 0, 0x00000000, 0x00000001 }, 3572 { 0x14cc, 0, 0x00000000, 0x00000001 },
3587 { 0x14d0, 0, 0xffffffff, 0x00000000 }, 3573 { 0x14d0, 0, 0xffffffff, 0x00000000 },
3588 { 0x1500, 0, 0x00000000, 0xffffffff },
3589 { 0x1504, 0, 0x00000000, 0xffffffff },
3590 { 0x1508, 0, 0x00000000, 0xffffffff },
3591 { 0x150c, 0, 0x00000000, 0xffffffff },
3592 { 0x1510, 0, 0x00000000, 0xffffffff },
3593 { 0x1514, 0, 0x00000000, 0xffffffff },
3594 { 0x1518, 0, 0x00000000, 0xffffffff },
3595 { 0x151c, 0, 0x00000000, 0xffffffff },
3596 { 0x1520, 0, 0x00000000, 0xffffffff },
3597 { 0x1524, 0, 0x00000000, 0xffffffff },
3598 { 0x1528, 0, 0x00000000, 0xffffffff },
3599 { 0x152c, 0, 0x00000000, 0xffffffff },
3600 { 0x1530, 0, 0x00000000, 0xffffffff },
3601 { 0x1534, 0, 0x00000000, 0xffffffff },
3602 { 0x1538, 0, 0x00000000, 0xffffffff },
3603 { 0x153c, 0, 0x00000000, 0xffffffff },
3604 { 0x1540, 0, 0x00000000, 0xffffffff },
3605 { 0x1544, 0, 0x00000000, 0xffffffff },
3606 { 0x1548, 0, 0x00000000, 0xffffffff },
3607 { 0x154c, 0, 0x00000000, 0xffffffff },
3608 { 0x1550, 0, 0x00000000, 0xffffffff },
3609 { 0x1554, 0, 0x00000000, 0xffffffff },
3610 { 0x1558, 0, 0x00000000, 0xffffffff },
3611 { 0x1600, 0, 0x00000000, 0xffffffff },
3612 { 0x1604, 0, 0x00000000, 0xffffffff },
3613 { 0x1608, 0, 0x00000000, 0xffffffff },
3614 { 0x160c, 0, 0x00000000, 0xffffffff },
3615 { 0x1610, 0, 0x00000000, 0xffffffff },
3616 { 0x1614, 0, 0x00000000, 0xffffffff },
3617 { 0x1618, 0, 0x00000000, 0xffffffff },
3618 { 0x161c, 0, 0x00000000, 0xffffffff },
3619 { 0x1620, 0, 0x00000000, 0xffffffff },
3620 { 0x1624, 0, 0x00000000, 0xffffffff },
3621 { 0x1628, 0, 0x00000000, 0xffffffff },
3622 { 0x162c, 0, 0x00000000, 0xffffffff },
3623 { 0x1630, 0, 0x00000000, 0xffffffff },
3624 { 0x1634, 0, 0x00000000, 0xffffffff },
3625 { 0x1638, 0, 0x00000000, 0xffffffff },
3626 { 0x163c, 0, 0x00000000, 0xffffffff },
3627 { 0x1640, 0, 0x00000000, 0xffffffff },
3628 { 0x1644, 0, 0x00000000, 0xffffffff },
3629 { 0x1648, 0, 0x00000000, 0xffffffff },
3630 { 0x164c, 0, 0x00000000, 0xffffffff },
3631 { 0x1650, 0, 0x00000000, 0xffffffff },
3632 { 0x1654, 0, 0x00000000, 0xffffffff },
3633 3574
3634 { 0x1800, 0, 0x00000000, 0x00000001 }, 3575 { 0x1800, 0, 0x00000000, 0x00000001 },
3635 { 0x1804, 0, 0x00000000, 0x00000003 }, 3576 { 0x1804, 0, 0x00000000, 0x00000003 },
3636 { 0x1840, 0, 0x00000000, 0xffffffff },
3637 { 0x1844, 0, 0x00000000, 0xffffffff },
3638 { 0x1848, 0, 0x00000000, 0xffffffff },
3639 { 0x184c, 0, 0x00000000, 0xffffffff },
3640 { 0x1850, 0, 0x00000000, 0xffffffff },
3641 { 0x1900, 0, 0x7ffbffff, 0x00000000 },
3642 { 0x1904, 0, 0xffffffff, 0x00000000 },
3643 { 0x190c, 0, 0xffffffff, 0x00000000 },
3644 { 0x1914, 0, 0xffffffff, 0x00000000 },
3645 { 0x191c, 0, 0xffffffff, 0x00000000 },
3646 { 0x1924, 0, 0xffffffff, 0x00000000 },
3647 { 0x192c, 0, 0xffffffff, 0x00000000 },
3648 { 0x1934, 0, 0xffffffff, 0x00000000 },
3649 { 0x193c, 0, 0xffffffff, 0x00000000 },
3650 { 0x1944, 0, 0xffffffff, 0x00000000 },
3651 { 0x194c, 0, 0xffffffff, 0x00000000 },
3652 { 0x1954, 0, 0xffffffff, 0x00000000 },
3653 { 0x195c, 0, 0xffffffff, 0x00000000 },
3654 { 0x1964, 0, 0xffffffff, 0x00000000 },
3655 { 0x196c, 0, 0xffffffff, 0x00000000 },
3656 { 0x1974, 0, 0xffffffff, 0x00000000 },
3657 { 0x197c, 0, 0xffffffff, 0x00000000 },
3658 { 0x1980, 0, 0x0700ffff, 0x00000000 },
3659
3660 { 0x1c00, 0, 0x00000000, 0x00000001 },
3661 { 0x1c04, 0, 0x00000000, 0x00000003 },
3662 { 0x1c08, 0, 0x0000000f, 0x00000000 },
3663 { 0x1c40, 0, 0x00000000, 0xffffffff },
3664 { 0x1c44, 0, 0x00000000, 0xffffffff },
3665 { 0x1c48, 0, 0x00000000, 0xffffffff },
3666 { 0x1c4c, 0, 0x00000000, 0xffffffff },
3667 { 0x1c50, 0, 0x00000000, 0xffffffff },
3668 { 0x1d00, 0, 0x7ffbffff, 0x00000000 },
3669 { 0x1d04, 0, 0xffffffff, 0x00000000 },
3670 { 0x1d0c, 0, 0xffffffff, 0x00000000 },
3671 { 0x1d14, 0, 0xffffffff, 0x00000000 },
3672 { 0x1d1c, 0, 0xffffffff, 0x00000000 },
3673 { 0x1d24, 0, 0xffffffff, 0x00000000 },
3674 { 0x1d2c, 0, 0xffffffff, 0x00000000 },
3675 { 0x1d34, 0, 0xffffffff, 0x00000000 },
3676 { 0x1d3c, 0, 0xffffffff, 0x00000000 },
3677 { 0x1d44, 0, 0xffffffff, 0x00000000 },
3678 { 0x1d4c, 0, 0xffffffff, 0x00000000 },
3679 { 0x1d54, 0, 0xffffffff, 0x00000000 },
3680 { 0x1d5c, 0, 0xffffffff, 0x00000000 },
3681 { 0x1d64, 0, 0xffffffff, 0x00000000 },
3682 { 0x1d6c, 0, 0xffffffff, 0x00000000 },
3683 { 0x1d74, 0, 0xffffffff, 0x00000000 },
3684 { 0x1d7c, 0, 0xffffffff, 0x00000000 },
3685 { 0x1d80, 0, 0x0700ffff, 0x00000000 },
3686
3687 { 0x2004, 0, 0x00000000, 0x0337000f },
3688 { 0x2008, 0, 0xffffffff, 0x00000000 },
3689 { 0x200c, 0, 0xffffffff, 0x00000000 },
3690 { 0x2010, 0, 0xffffffff, 0x00000000 },
3691 { 0x2014, 0, 0x801fff80, 0x00000000 },
3692 { 0x2018, 0, 0x000003ff, 0x00000000 },
3693 3577
3694 { 0x2800, 0, 0x00000000, 0x00000001 }, 3578 { 0x2800, 0, 0x00000000, 0x00000001 },
3695 { 0x2804, 0, 0x00000000, 0x00003f01 }, 3579 { 0x2804, 0, 0x00000000, 0x00003f01 },
@@ -3707,16 +3591,6 @@ bnx2_test_registers(struct bnx2 *bp)
3707 { 0x2c00, 0, 0x00000000, 0x00000011 }, 3591 { 0x2c00, 0, 0x00000000, 0x00000011 },
3708 { 0x2c04, 0, 0x00000000, 0x00030007 }, 3592 { 0x2c04, 0, 0x00000000, 0x00030007 },
3709 3593
3710 { 0x3000, 0, 0x00000000, 0x00000001 },
3711 { 0x3004, 0, 0x00000000, 0x007007ff },
3712 { 0x3008, 0, 0x00000003, 0x00000000 },
3713 { 0x300c, 0, 0xffffffff, 0x00000000 },
3714 { 0x3010, 0, 0xffffffff, 0x00000000 },
3715 { 0x3014, 0, 0xffffffff, 0x00000000 },
3716 { 0x3034, 0, 0xffffffff, 0x00000000 },
3717 { 0x3038, 0, 0xffffffff, 0x00000000 },
3718 { 0x3050, 0, 0x00000001, 0x00000000 },
3719
3720 { 0x3c00, 0, 0x00000000, 0x00000001 }, 3594 { 0x3c00, 0, 0x00000000, 0x00000001 },
3721 { 0x3c04, 0, 0x00000000, 0x00070000 }, 3595 { 0x3c04, 0, 0x00000000, 0x00070000 },
3722 { 0x3c08, 0, 0x00007f71, 0x07f00000 }, 3596 { 0x3c08, 0, 0x00007f71, 0x07f00000 },
@@ -3726,88 +3600,11 @@ bnx2_test_registers(struct bnx2 *bp)
3726 { 0x3c18, 0, 0x00000000, 0xffffffff }, 3600 { 0x3c18, 0, 0x00000000, 0xffffffff },
3727 { 0x3c1c, 0, 0xfffff000, 0x00000000 }, 3601 { 0x3c1c, 0, 0xfffff000, 0x00000000 },
3728 { 0x3c20, 0, 0xffffff00, 0x00000000 }, 3602 { 0x3c20, 0, 0xffffff00, 0x00000000 },
3729 { 0x3c24, 0, 0xffffffff, 0x00000000 },
3730 { 0x3c28, 0, 0xffffffff, 0x00000000 },
3731 { 0x3c2c, 0, 0xffffffff, 0x00000000 },
3732 { 0x3c30, 0, 0xffffffff, 0x00000000 },
3733 { 0x3c34, 0, 0xffffffff, 0x00000000 },
3734 { 0x3c38, 0, 0xffffffff, 0x00000000 },
3735 { 0x3c3c, 0, 0xffffffff, 0x00000000 },
3736 { 0x3c40, 0, 0xffffffff, 0x00000000 },
3737 { 0x3c44, 0, 0xffffffff, 0x00000000 },
3738 { 0x3c48, 0, 0xffffffff, 0x00000000 },
3739 { 0x3c4c, 0, 0xffffffff, 0x00000000 },
3740 { 0x3c50, 0, 0xffffffff, 0x00000000 },
3741 { 0x3c54, 0, 0xffffffff, 0x00000000 },
3742 { 0x3c58, 0, 0xffffffff, 0x00000000 },
3743 { 0x3c5c, 0, 0xffffffff, 0x00000000 },
3744 { 0x3c60, 0, 0xffffffff, 0x00000000 },
3745 { 0x3c64, 0, 0xffffffff, 0x00000000 },
3746 { 0x3c68, 0, 0xffffffff, 0x00000000 },
3747 { 0x3c6c, 0, 0xffffffff, 0x00000000 },
3748 { 0x3c70, 0, 0xffffffff, 0x00000000 },
3749 { 0x3c74, 0, 0x0000003f, 0x00000000 },
3750 { 0x3c78, 0, 0x00000000, 0x00000000 },
3751 { 0x3c7c, 0, 0x00000000, 0x00000000 },
3752 { 0x3c80, 0, 0x3fffffff, 0x00000000 },
3753 { 0x3c84, 0, 0x0000003f, 0x00000000 },
3754 { 0x3c88, 0, 0x00000000, 0xffffffff },
3755 { 0x3c8c, 0, 0x00000000, 0xffffffff },
3756
3757 { 0x4000, 0, 0x00000000, 0x00000001 },
3758 { 0x4004, 0, 0x00000000, 0x00030000 },
3759 { 0x4008, 0, 0x00000ff0, 0x00000000 },
3760 { 0x400c, 0, 0xffffffff, 0x00000000 },
3761 { 0x4088, 0, 0x00000000, 0x00070303 },
3762
3763 { 0x4400, 0, 0x00000000, 0x00000001 },
3764 { 0x4404, 0, 0x00000000, 0x00003f01 },
3765 { 0x4408, 0, 0x7fff00ff, 0x00000000 },
3766 { 0x440c, 0, 0xffffffff, 0x00000000 },
3767 { 0x4410, 0, 0xffff, 0x0000 },
3768 { 0x4414, 0, 0xffff, 0x0000 },
3769 { 0x4418, 0, 0xffff, 0x0000 },
3770 { 0x441c, 0, 0xffff, 0x0000 },
3771 { 0x4428, 0, 0xffffffff, 0x00000000 },
3772 { 0x442c, 0, 0xffffffff, 0x00000000 },
3773 { 0x4430, 0, 0xffffffff, 0x00000000 },
3774 { 0x4434, 0, 0xffffffff, 0x00000000 },
3775 { 0x4438, 0, 0xffffffff, 0x00000000 },
3776 { 0x443c, 0, 0xffffffff, 0x00000000 },
3777 { 0x4440, 0, 0xffffffff, 0x00000000 },
3778 { 0x4444, 0, 0xffffffff, 0x00000000 },
3779
3780 { 0x4c00, 0, 0x00000000, 0x00000001 },
3781 { 0x4c04, 0, 0x00000000, 0x0000003f },
3782 { 0x4c08, 0, 0xffffffff, 0x00000000 },
3783 { 0x4c0c, 0, 0x0007fc00, 0x00000000 },
3784 { 0x4c10, 0, 0x80003fe0, 0x00000000 },
3785 { 0x4c14, 0, 0xffffffff, 0x00000000 },
3786 { 0x4c44, 0, 0x00000000, 0x9fff9fff },
3787 { 0x4c48, 0, 0x00000000, 0xb3009fff },
3788 { 0x4c4c, 0, 0x00000000, 0x77f33b30 },
3789 { 0x4c50, 0, 0x00000000, 0xffffffff },
3790 3603
3791 { 0x5004, 0, 0x00000000, 0x0000007f }, 3604 { 0x5004, 0, 0x00000000, 0x0000007f },
3792 { 0x5008, 0, 0x0f0007ff, 0x00000000 }, 3605 { 0x5008, 0, 0x0f0007ff, 0x00000000 },
3793 { 0x500c, 0, 0xf800f800, 0x07ff07ff }, 3606 { 0x500c, 0, 0xf800f800, 0x07ff07ff },
3794 3607
3795 { 0x5400, 0, 0x00000008, 0x00000001 },
3796 { 0x5404, 0, 0x00000000, 0x0000003f },
3797 { 0x5408, 0, 0x0000001f, 0x00000000 },
3798 { 0x540c, 0, 0xffffffff, 0x00000000 },
3799 { 0x5410, 0, 0xffffffff, 0x00000000 },
3800 { 0x5414, 0, 0x0000ffff, 0x00000000 },
3801 { 0x5418, 0, 0x0000ffff, 0x00000000 },
3802 { 0x541c, 0, 0x0000ffff, 0x00000000 },
3803 { 0x5420, 0, 0x0000ffff, 0x00000000 },
3804 { 0x5428, 0, 0x000000ff, 0x00000000 },
3805 { 0x542c, 0, 0xff00ffff, 0x00000000 },
3806 { 0x5430, 0, 0x001fff80, 0x00000000 },
3807 { 0x5438, 0, 0xffffffff, 0x00000000 },
3808 { 0x543c, 0, 0xffffffff, 0x00000000 },
3809 { 0x5440, 0, 0xf800f800, 0x07ff07ff },
3810
3811 { 0x5c00, 0, 0x00000000, 0x00000001 }, 3608 { 0x5c00, 0, 0x00000000, 0x00000001 },
3812 { 0x5c04, 0, 0x00000000, 0x0003000f }, 3609 { 0x5c04, 0, 0x00000000, 0x0003000f },
3813 { 0x5c08, 0, 0x00000003, 0x00000000 }, 3610 { 0x5c08, 0, 0x00000003, 0x00000000 },
@@ -4794,6 +4591,64 @@ bnx2_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
4794 info->fw_version[5] = 0; 4591 info->fw_version[5] = 0;
4795} 4592}
4796 4593
4594#define BNX2_REGDUMP_LEN (32 * 1024)
4595
4596static int
4597bnx2_get_regs_len(struct net_device *dev)
4598{
4599 return BNX2_REGDUMP_LEN;
4600}
4601
4602static void
4603bnx2_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
4604{
4605 u32 *p = _p, i, offset;
4606 u8 *orig_p = _p;
4607 struct bnx2 *bp = netdev_priv(dev);
4608 u32 reg_boundaries[] = { 0x0000, 0x0098, 0x0400, 0x045c,
4609 0x0800, 0x0880, 0x0c00, 0x0c10,
4610 0x0c30, 0x0d08, 0x1000, 0x101c,
4611 0x1040, 0x1048, 0x1080, 0x10a4,
4612 0x1400, 0x1490, 0x1498, 0x14f0,
4613 0x1500, 0x155c, 0x1580, 0x15dc,
4614 0x1600, 0x1658, 0x1680, 0x16d8,
4615 0x1800, 0x1820, 0x1840, 0x1854,
4616 0x1880, 0x1894, 0x1900, 0x1984,
4617 0x1c00, 0x1c0c, 0x1c40, 0x1c54,
4618 0x1c80, 0x1c94, 0x1d00, 0x1d84,
4619 0x2000, 0x2030, 0x23c0, 0x2400,
4620 0x2800, 0x2820, 0x2830, 0x2850,
4621 0x2b40, 0x2c10, 0x2fc0, 0x3058,
4622 0x3c00, 0x3c94, 0x4000, 0x4010,
4623 0x4080, 0x4090, 0x43c0, 0x4458,
4624 0x4c00, 0x4c18, 0x4c40, 0x4c54,
4625 0x4fc0, 0x5010, 0x53c0, 0x5444,
4626 0x5c00, 0x5c18, 0x5c80, 0x5c90,
4627 0x5fc0, 0x6000, 0x6400, 0x6428,
4628 0x6800, 0x6848, 0x684c, 0x6860,
4629 0x6888, 0x6910, 0x8000 };
4630
4631 regs->version = 0;
4632
4633 memset(p, 0, BNX2_REGDUMP_LEN);
4634
4635 if (!netif_running(bp->dev))
4636 return;
4637
4638 i = 0;
4639 offset = reg_boundaries[0];
4640 p += offset;
4641 while (offset < BNX2_REGDUMP_LEN) {
4642 *p++ = REG_RD(bp, offset);
4643 offset += 4;
4644 if (offset == reg_boundaries[i + 1]) {
4645 offset = reg_boundaries[i + 2];
4646 p = (u32 *) (orig_p + offset);
4647 i += 2;
4648 }
4649 }
4650}
4651
4797static void 4652static void
4798bnx2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 4653bnx2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
4799{ 4654{
@@ -4979,7 +4834,7 @@ bnx2_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
4979{ 4834{
4980 struct bnx2 *bp = netdev_priv(dev); 4835 struct bnx2 *bp = netdev_priv(dev);
4981 4836
4982 ering->rx_max_pending = MAX_RX_DESC_CNT; 4837 ering->rx_max_pending = MAX_TOTAL_RX_DESC_CNT;
4983 ering->rx_mini_max_pending = 0; 4838 ering->rx_mini_max_pending = 0;
4984 ering->rx_jumbo_max_pending = 0; 4839 ering->rx_jumbo_max_pending = 0;
4985 4840
@@ -4996,17 +4851,28 @@ bnx2_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
4996{ 4851{
4997 struct bnx2 *bp = netdev_priv(dev); 4852 struct bnx2 *bp = netdev_priv(dev);
4998 4853
4999 if ((ering->rx_pending > MAX_RX_DESC_CNT) || 4854 if ((ering->rx_pending > MAX_TOTAL_RX_DESC_CNT) ||
5000 (ering->tx_pending > MAX_TX_DESC_CNT) || 4855 (ering->tx_pending > MAX_TX_DESC_CNT) ||
5001 (ering->tx_pending <= MAX_SKB_FRAGS)) { 4856 (ering->tx_pending <= MAX_SKB_FRAGS)) {
5002 4857
5003 return -EINVAL; 4858 return -EINVAL;
5004 } 4859 }
5005 bp->rx_ring_size = ering->rx_pending; 4860 if (netif_running(bp->dev)) {
4861 bnx2_netif_stop(bp);
4862 bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
4863 bnx2_free_skbs(bp);
4864 bnx2_free_mem(bp);
4865 }
4866
4867 bnx2_set_rx_ring_size(bp, ering->rx_pending);
5006 bp->tx_ring_size = ering->tx_pending; 4868 bp->tx_ring_size = ering->tx_pending;
5007 4869
5008 if (netif_running(bp->dev)) { 4870 if (netif_running(bp->dev)) {
5009 bnx2_netif_stop(bp); 4871 int rc;
4872
4873 rc = bnx2_alloc_mem(bp);
4874 if (rc)
4875 return rc;
5010 bnx2_init_nic(bp); 4876 bnx2_init_nic(bp);
5011 bnx2_netif_start(bp); 4877 bnx2_netif_start(bp);
5012 } 4878 }
@@ -5360,6 +5226,8 @@ static struct ethtool_ops bnx2_ethtool_ops = {
5360 .get_settings = bnx2_get_settings, 5226 .get_settings = bnx2_get_settings,
5361 .set_settings = bnx2_set_settings, 5227 .set_settings = bnx2_set_settings,
5362 .get_drvinfo = bnx2_get_drvinfo, 5228 .get_drvinfo = bnx2_get_drvinfo,
5229 .get_regs_len = bnx2_get_regs_len,
5230 .get_regs = bnx2_get_regs,
5363 .get_wol = bnx2_get_wol, 5231 .get_wol = bnx2_get_wol,
5364 .set_wol = bnx2_set_wol, 5232 .set_wol = bnx2_set_wol,
5365 .nway_reset = bnx2_nway_reset, 5233 .nway_reset = bnx2_nway_reset,
@@ -5678,7 +5546,7 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5678 bp->mac_addr[5] = (u8) reg; 5546 bp->mac_addr[5] = (u8) reg;
5679 5547
5680 bp->tx_ring_size = MAX_TX_DESC_CNT; 5548 bp->tx_ring_size = MAX_TX_DESC_CNT;
5681 bp->rx_ring_size = 100; 5549 bnx2_set_rx_ring_size(bp, 100);
5682 5550
5683 bp->rx_csum = 1; 5551 bp->rx_csum = 1;
5684 5552
@@ -5897,6 +5765,7 @@ bnx2_suspend(struct pci_dev *pdev, pm_message_t state)
5897 if (!netif_running(dev)) 5765 if (!netif_running(dev))
5898 return 0; 5766 return 0;
5899 5767
5768 flush_scheduled_work();
5900 bnx2_netif_stop(bp); 5769 bnx2_netif_stop(bp);
5901 netif_device_detach(dev); 5770 netif_device_detach(dev);
5902 del_timer_sync(&bp->timer); 5771 del_timer_sync(&bp->timer);
diff --git a/drivers/net/bnx2.h b/drivers/net/bnx2.h
index 9f691cbd666b..fd4b7f2eb477 100644
--- a/drivers/net/bnx2.h
+++ b/drivers/net/bnx2.h
@@ -23,6 +23,7 @@
23#include <linux/errno.h> 23#include <linux/errno.h>
24#include <linux/ioport.h> 24#include <linux/ioport.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/vmalloc.h>
26#include <linux/interrupt.h> 27#include <linux/interrupt.h>
27#include <linux/pci.h> 28#include <linux/pci.h>
28#include <linux/init.h> 29#include <linux/init.h>
@@ -3792,8 +3793,10 @@ struct l2_fhdr {
3792#define TX_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct tx_bd)) 3793#define TX_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct tx_bd))
3793#define MAX_TX_DESC_CNT (TX_DESC_CNT - 1) 3794#define MAX_TX_DESC_CNT (TX_DESC_CNT - 1)
3794 3795
3796#define MAX_RX_RINGS 4
3795#define RX_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct rx_bd)) 3797#define RX_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct rx_bd))
3796#define MAX_RX_DESC_CNT (RX_DESC_CNT - 1) 3798#define MAX_RX_DESC_CNT (RX_DESC_CNT - 1)
3799#define MAX_TOTAL_RX_DESC_CNT (MAX_RX_DESC_CNT * MAX_RX_RINGS)
3797 3800
3798#define NEXT_TX_BD(x) (((x) & (MAX_TX_DESC_CNT - 1)) == \ 3801#define NEXT_TX_BD(x) (((x) & (MAX_TX_DESC_CNT - 1)) == \
3799 (MAX_TX_DESC_CNT - 1)) ? \ 3802 (MAX_TX_DESC_CNT - 1)) ? \
@@ -3805,8 +3808,10 @@ struct l2_fhdr {
3805 (MAX_RX_DESC_CNT - 1)) ? \ 3808 (MAX_RX_DESC_CNT - 1)) ? \
3806 (x) + 2 : (x) + 1 3809 (x) + 2 : (x) + 1
3807 3810
3808#define RX_RING_IDX(x) ((x) & MAX_RX_DESC_CNT) 3811#define RX_RING_IDX(x) ((x) & bp->rx_max_ring_idx)
3809 3812
3813#define RX_RING(x) (((x) & ~MAX_RX_DESC_CNT) >> 8)
3814#define RX_IDX(x) ((x) & MAX_RX_DESC_CNT)
3810 3815
3811/* Context size. */ 3816/* Context size. */
3812#define CTX_SHIFT 7 3817#define CTX_SHIFT 7
@@ -3903,6 +3908,15 @@ struct bnx2 {
3903 struct status_block *status_blk; 3908 struct status_block *status_blk;
3904 u32 last_status_idx; 3909 u32 last_status_idx;
3905 3910
3911 u32 flags;
3912#define PCIX_FLAG 1
3913#define PCI_32BIT_FLAG 2
3914#define ONE_TDMA_FLAG 4 /* no longer used */
3915#define NO_WOL_FLAG 8
3916#define USING_DAC_FLAG 0x10
3917#define USING_MSI_FLAG 0x20
3918#define ASF_ENABLE_FLAG 0x40
3919
3906 struct tx_bd *tx_desc_ring; 3920 struct tx_bd *tx_desc_ring;
3907 struct sw_bd *tx_buf_ring; 3921 struct sw_bd *tx_buf_ring;
3908 u32 tx_prod_bseq; 3922 u32 tx_prod_bseq;
@@ -3920,19 +3934,22 @@ struct bnx2 {
3920 u32 rx_offset; 3934 u32 rx_offset;
3921 u32 rx_buf_use_size; /* useable size */ 3935 u32 rx_buf_use_size; /* useable size */
3922 u32 rx_buf_size; /* with alignment */ 3936 u32 rx_buf_size; /* with alignment */
3923 struct rx_bd *rx_desc_ring; 3937 u32 rx_max_ring_idx;
3924 struct sw_bd *rx_buf_ring; 3938
3925 u32 rx_prod_bseq; 3939 u32 rx_prod_bseq;
3926 u16 rx_prod; 3940 u16 rx_prod;
3927 u16 rx_cons; 3941 u16 rx_cons;
3928 3942
3929 u32 rx_csum; 3943 u32 rx_csum;
3930 3944
3945 struct sw_bd *rx_buf_ring;
3946 struct rx_bd *rx_desc_ring[MAX_RX_RINGS];
3947
3931 /* Only used to synchronize netif_stop_queue/wake_queue when tx */ 3948 /* Only used to synchronize netif_stop_queue/wake_queue when tx */
3932 /* ring is full */ 3949 /* ring is full */
3933 spinlock_t tx_lock; 3950 spinlock_t tx_lock;
3934 3951
3935 /* End of fileds used in the performance code paths. */ 3952 /* End of fields used in the performance code paths. */
3936 3953
3937 char *name; 3954 char *name;
3938 3955
@@ -3945,15 +3962,6 @@ struct bnx2 {
3945 /* Used to synchronize phy accesses. */ 3962 /* Used to synchronize phy accesses. */
3946 spinlock_t phy_lock; 3963 spinlock_t phy_lock;
3947 3964
3948 u32 flags;
3949#define PCIX_FLAG 1
3950#define PCI_32BIT_FLAG 2
3951#define ONE_TDMA_FLAG 4 /* no longer used */
3952#define NO_WOL_FLAG 8
3953#define USING_DAC_FLAG 0x10
3954#define USING_MSI_FLAG 0x20
3955#define ASF_ENABLE_FLAG 0x40
3956
3957 u32 phy_flags; 3965 u32 phy_flags;
3958#define PHY_SERDES_FLAG 1 3966#define PHY_SERDES_FLAG 1
3959#define PHY_CRC_FIX_FLAG 2 3967#define PHY_CRC_FIX_FLAG 2
@@ -4004,8 +4012,9 @@ struct bnx2 {
4004 dma_addr_t tx_desc_mapping; 4012 dma_addr_t tx_desc_mapping;
4005 4013
4006 4014
4015 int rx_max_ring;
4007 int rx_ring_size; 4016 int rx_ring_size;
4008 dma_addr_t rx_desc_mapping; 4017 dma_addr_t rx_desc_mapping[MAX_RX_RINGS];
4009 4018
4010 u16 tx_quick_cons_trip; 4019 u16 tx_quick_cons_trip;
4011 u16 tx_quick_cons_trip_int; 4020 u16 tx_quick_cons_trip_int;
diff --git a/drivers/net/cassini.c b/drivers/net/cassini.c
index 6e295fce5c6f..8f1573e658a5 100644
--- a/drivers/net/cassini.c
+++ b/drivers/net/cassini.c
@@ -91,6 +91,7 @@
91#include <linux/mii.h> 91#include <linux/mii.h>
92#include <linux/ip.h> 92#include <linux/ip.h>
93#include <linux/tcp.h> 93#include <linux/tcp.h>
94#include <linux/mutex.h>
94 95
95#include <net/checksum.h> 96#include <net/checksum.h>
96 97
@@ -3892,7 +3893,7 @@ static void cas_reset(struct cas *cp, int blkflag)
3892 spin_unlock(&cp->stat_lock[N_TX_RINGS]); 3893 spin_unlock(&cp->stat_lock[N_TX_RINGS]);
3893} 3894}
3894 3895
3895/* Shut down the chip, must be called with pm_sem held. */ 3896/* Shut down the chip, must be called with pm_mutex held. */
3896static void cas_shutdown(struct cas *cp) 3897static void cas_shutdown(struct cas *cp)
3897{ 3898{
3898 unsigned long flags; 3899 unsigned long flags;
@@ -4311,11 +4312,11 @@ static int cas_open(struct net_device *dev)
4311 int hw_was_up, err; 4312 int hw_was_up, err;
4312 unsigned long flags; 4313 unsigned long flags;
4313 4314
4314 down(&cp->pm_sem); 4315 mutex_lock(&cp->pm_mutex);
4315 4316
4316 hw_was_up = cp->hw_running; 4317 hw_was_up = cp->hw_running;
4317 4318
4318 /* The power-management semaphore protects the hw_running 4319 /* The power-management mutex protects the hw_running
4319 * etc. state so it is safe to do this bit without cp->lock 4320 * etc. state so it is safe to do this bit without cp->lock
4320 */ 4321 */
4321 if (!cp->hw_running) { 4322 if (!cp->hw_running) {
@@ -4364,7 +4365,7 @@ static int cas_open(struct net_device *dev)
4364 cas_unlock_all_restore(cp, flags); 4365 cas_unlock_all_restore(cp, flags);
4365 4366
4366 netif_start_queue(dev); 4367 netif_start_queue(dev);
4367 up(&cp->pm_sem); 4368 mutex_unlock(&cp->pm_mutex);
4368 return 0; 4369 return 0;
4369 4370
4370err_spare: 4371err_spare:
@@ -4372,7 +4373,7 @@ err_spare:
4372 cas_free_rxds(cp); 4373 cas_free_rxds(cp);
4373err_tx_tiny: 4374err_tx_tiny:
4374 cas_tx_tiny_free(cp); 4375 cas_tx_tiny_free(cp);
4375 up(&cp->pm_sem); 4376 mutex_unlock(&cp->pm_mutex);
4376 return err; 4377 return err;
4377} 4378}
4378 4379
@@ -4382,7 +4383,7 @@ static int cas_close(struct net_device *dev)
4382 struct cas *cp = netdev_priv(dev); 4383 struct cas *cp = netdev_priv(dev);
4383 4384
4384 /* Make sure we don't get distracted by suspend/resume */ 4385 /* Make sure we don't get distracted by suspend/resume */
4385 down(&cp->pm_sem); 4386 mutex_lock(&cp->pm_mutex);
4386 4387
4387 netif_stop_queue(dev); 4388 netif_stop_queue(dev);
4388 4389
@@ -4399,7 +4400,7 @@ static int cas_close(struct net_device *dev)
4399 cas_spare_free(cp); 4400 cas_spare_free(cp);
4400 cas_free_rxds(cp); 4401 cas_free_rxds(cp);
4401 cas_tx_tiny_free(cp); 4402 cas_tx_tiny_free(cp);
4402 up(&cp->pm_sem); 4403 mutex_unlock(&cp->pm_mutex);
4403 return 0; 4404 return 0;
4404} 4405}
4405 4406
@@ -4834,10 +4835,10 @@ static int cas_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
4834 unsigned long flags; 4835 unsigned long flags;
4835 int rc = -EOPNOTSUPP; 4836 int rc = -EOPNOTSUPP;
4836 4837
4837 /* Hold the PM semaphore while doing ioctl's or we may collide 4838 /* Hold the PM mutex while doing ioctl's or we may collide
4838 * with open/close and power management and oops. 4839 * with open/close and power management and oops.
4839 */ 4840 */
4840 down(&cp->pm_sem); 4841 mutex_lock(&cp->pm_mutex);
4841 switch (cmd) { 4842 switch (cmd) {
4842 case SIOCGMIIPHY: /* Get address of MII PHY in use. */ 4843 case SIOCGMIIPHY: /* Get address of MII PHY in use. */
4843 data->phy_id = cp->phy_addr; 4844 data->phy_id = cp->phy_addr;
@@ -4867,7 +4868,7 @@ static int cas_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
4867 break; 4868 break;
4868 }; 4869 };
4869 4870
4870 up(&cp->pm_sem); 4871 mutex_unlock(&cp->pm_mutex);
4871 return rc; 4872 return rc;
4872} 4873}
4873 4874
@@ -4994,7 +4995,7 @@ static int __devinit cas_init_one(struct pci_dev *pdev,
4994 spin_lock_init(&cp->tx_lock[i]); 4995 spin_lock_init(&cp->tx_lock[i]);
4995 } 4996 }
4996 spin_lock_init(&cp->stat_lock[N_TX_RINGS]); 4997 spin_lock_init(&cp->stat_lock[N_TX_RINGS]);
4997 init_MUTEX(&cp->pm_sem); 4998 mutex_init(&cp->pm_mutex);
4998 4999
4999 init_timer(&cp->link_timer); 5000 init_timer(&cp->link_timer);
5000 cp->link_timer.function = cas_link_timer; 5001 cp->link_timer.function = cas_link_timer;
@@ -5116,10 +5117,10 @@ err_out_free_consistent:
5116 cp->init_block, cp->block_dvma); 5117 cp->init_block, cp->block_dvma);
5117 5118
5118err_out_iounmap: 5119err_out_iounmap:
5119 down(&cp->pm_sem); 5120 mutex_lock(&cp->pm_mutex);
5120 if (cp->hw_running) 5121 if (cp->hw_running)
5121 cas_shutdown(cp); 5122 cas_shutdown(cp);
5122 up(&cp->pm_sem); 5123 mutex_unlock(&cp->pm_mutex);
5123 5124
5124 iounmap(cp->regs); 5125 iounmap(cp->regs);
5125 5126
@@ -5152,11 +5153,11 @@ static void __devexit cas_remove_one(struct pci_dev *pdev)
5152 cp = netdev_priv(dev); 5153 cp = netdev_priv(dev);
5153 unregister_netdev(dev); 5154 unregister_netdev(dev);
5154 5155
5155 down(&cp->pm_sem); 5156 mutex_lock(&cp->pm_mutex);
5156 flush_scheduled_work(); 5157 flush_scheduled_work();
5157 if (cp->hw_running) 5158 if (cp->hw_running)
5158 cas_shutdown(cp); 5159 cas_shutdown(cp);
5159 up(&cp->pm_sem); 5160 mutex_unlock(&cp->pm_mutex);
5160 5161
5161#if 1 5162#if 1
5162 if (cp->orig_cacheline_size) { 5163 if (cp->orig_cacheline_size) {
@@ -5183,10 +5184,7 @@ static int cas_suspend(struct pci_dev *pdev, pm_message_t state)
5183 struct cas *cp = netdev_priv(dev); 5184 struct cas *cp = netdev_priv(dev);
5184 unsigned long flags; 5185 unsigned long flags;
5185 5186
5186 /* We hold the PM semaphore during entire driver 5187 mutex_lock(&cp->pm_mutex);
5187 * sleep time
5188 */
5189 down(&cp->pm_sem);
5190 5188
5191 /* If the driver is opened, we stop the DMA */ 5189 /* If the driver is opened, we stop the DMA */
5192 if (cp->opened) { 5190 if (cp->opened) {
@@ -5206,6 +5204,7 @@ static int cas_suspend(struct pci_dev *pdev, pm_message_t state)
5206 5204
5207 if (cp->hw_running) 5205 if (cp->hw_running)
5208 cas_shutdown(cp); 5206 cas_shutdown(cp);
5207 mutex_unlock(&cp->pm_mutex);
5209 5208
5210 return 0; 5209 return 0;
5211} 5210}
@@ -5217,6 +5216,7 @@ static int cas_resume(struct pci_dev *pdev)
5217 5216
5218 printk(KERN_INFO "%s: resuming\n", dev->name); 5217 printk(KERN_INFO "%s: resuming\n", dev->name);
5219 5218
5219 mutex_lock(&cp->pm_mutex);
5220 cas_hard_reset(cp); 5220 cas_hard_reset(cp);
5221 if (cp->opened) { 5221 if (cp->opened) {
5222 unsigned long flags; 5222 unsigned long flags;
@@ -5229,7 +5229,7 @@ static int cas_resume(struct pci_dev *pdev)
5229 5229
5230 netif_device_attach(dev); 5230 netif_device_attach(dev);
5231 } 5231 }
5232 up(&cp->pm_sem); 5232 mutex_unlock(&cp->pm_mutex);
5233 return 0; 5233 return 0;
5234} 5234}
5235#endif /* CONFIG_PM */ 5235#endif /* CONFIG_PM */
diff --git a/drivers/net/cassini.h b/drivers/net/cassini.h
index 88063ef16cf6..ab55c7ee1012 100644
--- a/drivers/net/cassini.h
+++ b/drivers/net/cassini.h
@@ -4284,7 +4284,7 @@ struct cas {
4284 * (ie. not power managed) */ 4284 * (ie. not power managed) */
4285 int hw_running; 4285 int hw_running;
4286 int opened; 4286 int opened;
4287 struct semaphore pm_sem; /* open/close/suspend/resume */ 4287 struct mutex pm_mutex; /* open/close/suspend/resume */
4288 4288
4289 struct cas_init_block *init_block; 4289 struct cas_init_block *init_block;
4290 struct cas_tx_desc *init_txds[MAX_TX_RINGS]; 4290 struct cas_tx_desc *init_txds[MAX_TX_RINGS];
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index f39de16e6b97..49cd096a3c3d 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -920,7 +920,7 @@ e1000_remove(struct pci_dev *pdev)
920 unregister_netdev(netdev); 920 unregister_netdev(netdev);
921#ifdef CONFIG_E1000_NAPI 921#ifdef CONFIG_E1000_NAPI
922 for (i = 0; i < adapter->num_rx_queues; i++) 922 for (i = 0; i < adapter->num_rx_queues; i++)
923 __dev_put(&adapter->polling_netdev[i]); 923 dev_put(&adapter->polling_netdev[i]);
924#endif 924#endif
925 925
926 if (!e1000_check_phy_reset_block(&adapter->hw)) 926 if (!e1000_check_phy_reset_block(&adapter->hw))
diff --git a/drivers/net/fs_enet/mac-fcc.c b/drivers/net/fs_enet/mac-fcc.c
index e67b1d06611c..95e2bb8dd7b4 100644
--- a/drivers/net/fs_enet/mac-fcc.c
+++ b/drivers/net/fs_enet/mac-fcc.c
@@ -118,6 +118,8 @@ static int do_pd_setup(struct fs_enet_private *fep)
118 118
119 /* Fill out IRQ field */ 119 /* Fill out IRQ field */
120 fep->interrupt = platform_get_irq(pdev, 0); 120 fep->interrupt = platform_get_irq(pdev, 0);
121 if (fep->interrupt < 0)
122 return -EINVAL;
121 123
122 /* Attach the memory for the FCC Parameter RAM */ 124 /* Attach the memory for the FCC Parameter RAM */
123 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_pram"); 125 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_pram");
diff --git a/drivers/net/fs_enet/mac-fec.c b/drivers/net/fs_enet/mac-fec.c
index 2e8f44469699..3dad69dfdb2c 100644
--- a/drivers/net/fs_enet/mac-fec.c
+++ b/drivers/net/fs_enet/mac-fec.c
@@ -144,6 +144,8 @@ static int do_pd_setup(struct fs_enet_private *fep)
144 144
145 /* Fill out IRQ field */ 145 /* Fill out IRQ field */
146 fep->interrupt = platform_get_irq_byname(pdev,"interrupt"); 146 fep->interrupt = platform_get_irq_byname(pdev,"interrupt");
147 if (fep->interrupt < 0)
148 return -EINVAL;
147 149
148 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); 150 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
149 fep->fec.fecp =(void*)r->start; 151 fep->fec.fecp =(void*)r->start;
diff --git a/drivers/net/fs_enet/mac-scc.c b/drivers/net/fs_enet/mac-scc.c
index a3897fda71fa..a772b286f96d 100644
--- a/drivers/net/fs_enet/mac-scc.c
+++ b/drivers/net/fs_enet/mac-scc.c
@@ -118,6 +118,8 @@ static int do_pd_setup(struct fs_enet_private *fep)
118 118
119 /* Fill out IRQ field */ 119 /* Fill out IRQ field */
120 fep->interrupt = platform_get_irq_byname(pdev, "interrupt"); 120 fep->interrupt = platform_get_irq_byname(pdev, "interrupt");
121 if (fep->interrupt < 0)
122 return -EINVAL;
121 123
122 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); 124 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
123 fep->scc.sccp = (void *)r->start; 125 fep->scc.sccp = (void *)r->start;
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 0e8e3fcde9ff..771e25d8c417 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -193,8 +193,12 @@ static int gfar_probe(struct platform_device *pdev)
193 priv->interruptTransmit = platform_get_irq_byname(pdev, "tx"); 193 priv->interruptTransmit = platform_get_irq_byname(pdev, "tx");
194 priv->interruptReceive = platform_get_irq_byname(pdev, "rx"); 194 priv->interruptReceive = platform_get_irq_byname(pdev, "rx");
195 priv->interruptError = platform_get_irq_byname(pdev, "error"); 195 priv->interruptError = platform_get_irq_byname(pdev, "error");
196 if (priv->interruptTransmit < 0 || priv->interruptReceive < 0 || priv->interruptError < 0)
197 goto regs_fail;
196 } else { 198 } else {
197 priv->interruptTransmit = platform_get_irq(pdev, 0); 199 priv->interruptTransmit = platform_get_irq(pdev, 0);
200 if (priv->interruptTransmit < 0)
201 goto regs_fail;
198 } 202 }
199 203
200 /* get a pointer to the register memory */ 204 /* get a pointer to the register memory */
diff --git a/drivers/net/irda/Kconfig b/drivers/net/irda/Kconfig
index c81fe1c382d5..5e6d00752990 100644
--- a/drivers/net/irda/Kconfig
+++ b/drivers/net/irda/Kconfig
@@ -64,6 +64,14 @@ config TEKRAM_DONGLE
64 dongles you will have to start irattach like this: 64 dongles you will have to start irattach like this:
65 "irattach -d tekram". 65 "irattach -d tekram".
66 66
67config TOIM3232_DONGLE
68 tristate "TOIM3232 IrDa dongle"
69 depends on DONGLE && IRDA
70 help
71 Say Y here if you want to build support for the Vishay/Temic
72 TOIM3232 and TOIM4232 based dongles.
73 To compile it as a module, choose M here.
74
67config LITELINK_DONGLE 75config LITELINK_DONGLE
68 tristate "Parallax LiteLink dongle" 76 tristate "Parallax LiteLink dongle"
69 depends on DONGLE && IRDA 77 depends on DONGLE && IRDA
diff --git a/drivers/net/irda/Makefile b/drivers/net/irda/Makefile
index 72cbfdc9cfcc..27ab75f20799 100644
--- a/drivers/net/irda/Makefile
+++ b/drivers/net/irda/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_OLD_BELKIN_DONGLE) += old_belkin-sir.o
43obj-$(CONFIG_MCP2120_DONGLE) += mcp2120-sir.o 43obj-$(CONFIG_MCP2120_DONGLE) += mcp2120-sir.o
44obj-$(CONFIG_ACT200L_DONGLE) += act200l-sir.o 44obj-$(CONFIG_ACT200L_DONGLE) += act200l-sir.o
45obj-$(CONFIG_MA600_DONGLE) += ma600-sir.o 45obj-$(CONFIG_MA600_DONGLE) += ma600-sir.o
46obj-$(CONFIG_TOIM3232_DONGLE) += toim3232-sir.o
46 47
47# The SIR helper module 48# The SIR helper module
48sir-dev-objs := sir_dev.o sir_dongle.o sir_kthread.o 49sir-dev-objs := sir_dev.o sir_dongle.o sir_kthread.o
diff --git a/drivers/net/irda/donauboe.c b/drivers/net/irda/donauboe.c
index 3137592d60c0..910c0cab35b0 100644
--- a/drivers/net/irda/donauboe.c
+++ b/drivers/net/irda/donauboe.c
@@ -1778,7 +1778,7 @@ static struct pci_driver donauboe_pci_driver = {
1778static int __init 1778static int __init
1779donauboe_init (void) 1779donauboe_init (void)
1780{ 1780{
1781 return pci_module_init(&donauboe_pci_driver); 1781 return pci_register_driver(&donauboe_pci_driver);
1782} 1782}
1783 1783
1784static void __exit 1784static void __exit
diff --git a/drivers/net/irda/ep7211_ir.c b/drivers/net/irda/ep7211_ir.c
index 31896262d21c..4cba38f7e4a8 100644
--- a/drivers/net/irda/ep7211_ir.c
+++ b/drivers/net/irda/ep7211_ir.c
@@ -8,6 +8,7 @@
8#include <linux/delay.h> 8#include <linux/delay.h>
9#include <linux/tty.h> 9#include <linux/tty.h>
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/spinlock.h>
11 12
12#include <net/irda/irda.h> 13#include <net/irda/irda.h>
13#include <net/irda/irda_device.h> 14#include <net/irda/irda_device.h>
@@ -23,6 +24,8 @@ static void ep7211_ir_close(dongle_t *self);
23static int ep7211_ir_change_speed(struct irda_task *task); 24static int ep7211_ir_change_speed(struct irda_task *task);
24static int ep7211_ir_reset(struct irda_task *task); 25static int ep7211_ir_reset(struct irda_task *task);
25 26
27static DEFINE_SPINLOCK(ep7211_lock);
28
26static struct dongle_reg dongle = { 29static struct dongle_reg dongle = {
27 .type = IRDA_EP7211_IR, 30 .type = IRDA_EP7211_IR,
28 .open = ep7211_ir_open, 31 .open = ep7211_ir_open,
@@ -36,7 +39,7 @@ static void ep7211_ir_open(dongle_t *self, struct qos_info *qos)
36{ 39{
37 unsigned int syscon1, flags; 40 unsigned int syscon1, flags;
38 41
39 save_flags(flags); cli(); 42 spin_lock_irqsave(&ep7211_lock, flags);
40 43
41 /* Turn on the SIR encoder. */ 44 /* Turn on the SIR encoder. */
42 syscon1 = clps_readl(SYSCON1); 45 syscon1 = clps_readl(SYSCON1);
@@ -46,14 +49,14 @@ static void ep7211_ir_open(dongle_t *self, struct qos_info *qos)
46 /* XXX: We should disable modem status interrupts on the first 49 /* XXX: We should disable modem status interrupts on the first
47 UART (interrupt #14). */ 50 UART (interrupt #14). */
48 51
49 restore_flags(flags); 52 spin_unlock_irqrestore(&ep7211_lock, flags);
50} 53}
51 54
52static void ep7211_ir_close(dongle_t *self) 55static void ep7211_ir_close(dongle_t *self)
53{ 56{
54 unsigned int syscon1, flags; 57 unsigned int syscon1, flags;
55 58
56 save_flags(flags); cli(); 59 spin_lock_irqsave(&ep7211_lock, flags);
57 60
58 /* Turn off the SIR encoder. */ 61 /* Turn off the SIR encoder. */
59 syscon1 = clps_readl(SYSCON1); 62 syscon1 = clps_readl(SYSCON1);
@@ -63,7 +66,7 @@ static void ep7211_ir_close(dongle_t *self)
63 /* XXX: If we've disabled the modem status interrupts, we should 66 /* XXX: If we've disabled the modem status interrupts, we should
64 reset them back to their original state. */ 67 reset them back to their original state. */
65 68
66 restore_flags(flags); 69 spin_unlock_irqrestore(&ep7211_lock, flags);
67} 70}
68 71
69/* 72/*
diff --git a/drivers/net/irda/irda-usb.c b/drivers/net/irda/irda-usb.c
index 8936058a3cce..6e2ec56cde0b 100644
--- a/drivers/net/irda/irda-usb.c
+++ b/drivers/net/irda/irda-usb.c
@@ -740,7 +740,7 @@ static void irda_usb_receive(struct urb *urb, struct pt_regs *regs)
740 struct sk_buff *newskb; 740 struct sk_buff *newskb;
741 struct sk_buff *dataskb; 741 struct sk_buff *dataskb;
742 struct urb *next_urb; 742 struct urb *next_urb;
743 int docopy; 743 unsigned int len, docopy;
744 744
745 IRDA_DEBUG(2, "%s(), len=%d\n", __FUNCTION__, urb->actual_length); 745 IRDA_DEBUG(2, "%s(), len=%d\n", __FUNCTION__, urb->actual_length);
746 746
@@ -851,10 +851,11 @@ static void irda_usb_receive(struct urb *urb, struct pt_regs *regs)
851 dataskb->dev = self->netdev; 851 dataskb->dev = self->netdev;
852 dataskb->mac.raw = dataskb->data; 852 dataskb->mac.raw = dataskb->data;
853 dataskb->protocol = htons(ETH_P_IRDA); 853 dataskb->protocol = htons(ETH_P_IRDA);
854 len = dataskb->len;
854 netif_rx(dataskb); 855 netif_rx(dataskb);
855 856
856 /* Keep stats up to date */ 857 /* Keep stats up to date */
857 self->stats.rx_bytes += dataskb->len; 858 self->stats.rx_bytes += len;
858 self->stats.rx_packets++; 859 self->stats.rx_packets++;
859 self->netdev->last_rx = jiffies; 860 self->netdev->last_rx = jiffies;
860 861
diff --git a/drivers/net/irda/irtty-sir.c b/drivers/net/irda/irtty-sir.c
index 101750bf210f..6a98b7ae4975 100644
--- a/drivers/net/irda/irtty-sir.c
+++ b/drivers/net/irda/irtty-sir.c
@@ -33,6 +33,7 @@
33#include <asm/uaccess.h> 33#include <asm/uaccess.h>
34#include <linux/smp_lock.h> 34#include <linux/smp_lock.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/mutex.h>
36 37
37#include <net/irda/irda.h> 38#include <net/irda/irda.h>
38#include <net/irda/irda_device.h> 39#include <net/irda/irda_device.h>
@@ -338,7 +339,7 @@ static inline void irtty_stop_receiver(struct tty_struct *tty, int stop)
338/*****************************************************************/ 339/*****************************************************************/
339 340
340/* serialize ldisc open/close with sir_dev */ 341/* serialize ldisc open/close with sir_dev */
341static DECLARE_MUTEX(irtty_sem); 342static DEFINE_MUTEX(irtty_mutex);
342 343
343/* notifier from sir_dev when irda% device gets opened (ifup) */ 344/* notifier from sir_dev when irda% device gets opened (ifup) */
344 345
@@ -348,11 +349,11 @@ static int irtty_start_dev(struct sir_dev *dev)
348 struct tty_struct *tty; 349 struct tty_struct *tty;
349 350
350 /* serialize with ldisc open/close */ 351 /* serialize with ldisc open/close */
351 down(&irtty_sem); 352 mutex_lock(&irtty_mutex);
352 353
353 priv = dev->priv; 354 priv = dev->priv;
354 if (unlikely(!priv || priv->magic!=IRTTY_MAGIC)) { 355 if (unlikely(!priv || priv->magic!=IRTTY_MAGIC)) {
355 up(&irtty_sem); 356 mutex_unlock(&irtty_mutex);
356 return -ESTALE; 357 return -ESTALE;
357 } 358 }
358 359
@@ -363,7 +364,7 @@ static int irtty_start_dev(struct sir_dev *dev)
363 /* Make sure we can receive more data */ 364 /* Make sure we can receive more data */
364 irtty_stop_receiver(tty, FALSE); 365 irtty_stop_receiver(tty, FALSE);
365 366
366 up(&irtty_sem); 367 mutex_unlock(&irtty_mutex);
367 return 0; 368 return 0;
368} 369}
369 370
@@ -375,11 +376,11 @@ static int irtty_stop_dev(struct sir_dev *dev)
375 struct tty_struct *tty; 376 struct tty_struct *tty;
376 377
377 /* serialize with ldisc open/close */ 378 /* serialize with ldisc open/close */
378 down(&irtty_sem); 379 mutex_lock(&irtty_mutex);
379 380
380 priv = dev->priv; 381 priv = dev->priv;
381 if (unlikely(!priv || priv->magic!=IRTTY_MAGIC)) { 382 if (unlikely(!priv || priv->magic!=IRTTY_MAGIC)) {
382 up(&irtty_sem); 383 mutex_unlock(&irtty_mutex);
383 return -ESTALE; 384 return -ESTALE;
384 } 385 }
385 386
@@ -390,7 +391,7 @@ static int irtty_stop_dev(struct sir_dev *dev)
390 if (tty->driver->stop) 391 if (tty->driver->stop)
391 tty->driver->stop(tty); 392 tty->driver->stop(tty);
392 393
393 up(&irtty_sem); 394 mutex_unlock(&irtty_mutex);
394 395
395 return 0; 396 return 0;
396} 397}
@@ -514,13 +515,13 @@ static int irtty_open(struct tty_struct *tty)
514 priv->dev = dev; 515 priv->dev = dev;
515 516
516 /* serialize with start_dev - in case we were racing with ifup */ 517 /* serialize with start_dev - in case we were racing with ifup */
517 down(&irtty_sem); 518 mutex_lock(&irtty_mutex);
518 519
519 dev->priv = priv; 520 dev->priv = priv;
520 tty->disc_data = priv; 521 tty->disc_data = priv;
521 tty->receive_room = 65536; 522 tty->receive_room = 65536;
522 523
523 up(&irtty_sem); 524 mutex_unlock(&irtty_mutex);
524 525
525 IRDA_DEBUG(0, "%s - %s: irda line discipline opened\n", __FUNCTION__, tty->name); 526 IRDA_DEBUG(0, "%s - %s: irda line discipline opened\n", __FUNCTION__, tty->name);
526 527
diff --git a/drivers/net/irda/nsc-ircc.c b/drivers/net/irda/nsc-ircc.c
index ee717d0e939e..83141a3ff546 100644
--- a/drivers/net/irda/nsc-ircc.c
+++ b/drivers/net/irda/nsc-ircc.c
@@ -12,6 +12,7 @@
12 * Copyright (c) 1998-2000 Dag Brattli <dagb@cs.uit.no> 12 * Copyright (c) 1998-2000 Dag Brattli <dagb@cs.uit.no>
13 * Copyright (c) 1998 Lichen Wang, <lwang@actisys.com> 13 * Copyright (c) 1998 Lichen Wang, <lwang@actisys.com>
14 * Copyright (c) 1998 Actisys Corp., www.actisys.com 14 * Copyright (c) 1998 Actisys Corp., www.actisys.com
15 * Copyright (c) 2000-2004 Jean Tourrilhes <jt@hpl.hp.com>
15 * All Rights Reserved 16 * All Rights Reserved
16 * 17 *
17 * This program is free software; you can redistribute it and/or 18 * This program is free software; you can redistribute it and/or
@@ -53,14 +54,13 @@
53#include <linux/init.h> 54#include <linux/init.h>
54#include <linux/rtnetlink.h> 55#include <linux/rtnetlink.h>
55#include <linux/dma-mapping.h> 56#include <linux/dma-mapping.h>
57#include <linux/pnp.h>
58#include <linux/platform_device.h>
56 59
57#include <asm/io.h> 60#include <asm/io.h>
58#include <asm/dma.h> 61#include <asm/dma.h>
59#include <asm/byteorder.h> 62#include <asm/byteorder.h>
60 63
61#include <linux/pm.h>
62#include <linux/pm_legacy.h>
63
64#include <net/irda/wrapper.h> 64#include <net/irda/wrapper.h>
65#include <net/irda/irda.h> 65#include <net/irda/irda.h>
66#include <net/irda/irda_device.h> 66#include <net/irda/irda_device.h>
@@ -72,14 +72,27 @@
72 72
73static char *driver_name = "nsc-ircc"; 73static char *driver_name = "nsc-ircc";
74 74
75/* Power Management */
76#define NSC_IRCC_DRIVER_NAME "nsc-ircc"
77static int nsc_ircc_suspend(struct platform_device *dev, pm_message_t state);
78static int nsc_ircc_resume(struct platform_device *dev);
79
80static struct platform_driver nsc_ircc_driver = {
81 .suspend = nsc_ircc_suspend,
82 .resume = nsc_ircc_resume,
83 .driver = {
84 .name = NSC_IRCC_DRIVER_NAME,
85 },
86};
87
75/* Module parameters */ 88/* Module parameters */
76static int qos_mtt_bits = 0x07; /* 1 ms or more */ 89static int qos_mtt_bits = 0x07; /* 1 ms or more */
77static int dongle_id; 90static int dongle_id;
78 91
79/* Use BIOS settions by default, but user may supply module parameters */ 92/* Use BIOS settions by default, but user may supply module parameters */
80static unsigned int io[] = { ~0, ~0, ~0, ~0 }; 93static unsigned int io[] = { ~0, ~0, ~0, ~0, ~0 };
81static unsigned int irq[] = { 0, 0, 0, 0, 0 }; 94static unsigned int irq[] = { 0, 0, 0, 0, 0 };
82static unsigned int dma[] = { 0, 0, 0, 0, 0 }; 95static unsigned int dma[] = { 0, 0, 0, 0, 0 };
83 96
84static int nsc_ircc_probe_108(nsc_chip_t *chip, chipio_t *info); 97static int nsc_ircc_probe_108(nsc_chip_t *chip, chipio_t *info);
85static int nsc_ircc_probe_338(nsc_chip_t *chip, chipio_t *info); 98static int nsc_ircc_probe_338(nsc_chip_t *chip, chipio_t *info);
@@ -87,6 +100,7 @@ static int nsc_ircc_probe_39x(nsc_chip_t *chip, chipio_t *info);
87static int nsc_ircc_init_108(nsc_chip_t *chip, chipio_t *info); 100static int nsc_ircc_init_108(nsc_chip_t *chip, chipio_t *info);
88static int nsc_ircc_init_338(nsc_chip_t *chip, chipio_t *info); 101static int nsc_ircc_init_338(nsc_chip_t *chip, chipio_t *info);
89static int nsc_ircc_init_39x(nsc_chip_t *chip, chipio_t *info); 102static int nsc_ircc_init_39x(nsc_chip_t *chip, chipio_t *info);
103static int nsc_ircc_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *id);
90 104
91/* These are the known NSC chips */ 105/* These are the known NSC chips */
92static nsc_chip_t chips[] = { 106static nsc_chip_t chips[] = {
@@ -101,11 +115,12 @@ static nsc_chip_t chips[] = {
101 /* Contributed by Jan Frey - IBM A30/A31 */ 115 /* Contributed by Jan Frey - IBM A30/A31 */
102 { "PC8739x", { 0x2e, 0x4e, 0x0 }, 0x20, 0xea, 0xff, 116 { "PC8739x", { 0x2e, 0x4e, 0x0 }, 0x20, 0xea, 0xff,
103 nsc_ircc_probe_39x, nsc_ircc_init_39x }, 117 nsc_ircc_probe_39x, nsc_ircc_init_39x },
118 { "IBM", { 0x2e, 0x4e, 0x0 }, 0x20, 0xf4, 0xff,
119 nsc_ircc_probe_39x, nsc_ircc_init_39x },
104 { NULL } 120 { NULL }
105}; 121};
106 122
107/* Max 4 instances for now */ 123static struct nsc_ircc_cb *dev_self[] = { NULL, NULL, NULL, NULL, NULL };
108static struct nsc_ircc_cb *dev_self[] = { NULL, NULL, NULL, NULL };
109 124
110static char *dongle_types[] = { 125static char *dongle_types[] = {
111 "Differential serial interface", 126 "Differential serial interface",
@@ -126,8 +141,24 @@ static char *dongle_types[] = {
126 "No dongle connected", 141 "No dongle connected",
127}; 142};
128 143
144/* PNP probing */
145static chipio_t pnp_info;
146static const struct pnp_device_id nsc_ircc_pnp_table[] = {
147 { .id = "NSC6001", .driver_data = 0 },
148 { .id = "IBM0071", .driver_data = 0 },
149 { }
150};
151
152MODULE_DEVICE_TABLE(pnp, nsc_ircc_pnp_table);
153
154static struct pnp_driver nsc_ircc_pnp_driver = {
155 .name = "nsc-ircc",
156 .id_table = nsc_ircc_pnp_table,
157 .probe = nsc_ircc_pnp_probe,
158};
159
129/* Some prototypes */ 160/* Some prototypes */
130static int nsc_ircc_open(int i, chipio_t *info); 161static int nsc_ircc_open(chipio_t *info);
131static int nsc_ircc_close(struct nsc_ircc_cb *self); 162static int nsc_ircc_close(struct nsc_ircc_cb *self);
132static int nsc_ircc_setup(chipio_t *info); 163static int nsc_ircc_setup(chipio_t *info);
133static void nsc_ircc_pio_receive(struct nsc_ircc_cb *self); 164static void nsc_ircc_pio_receive(struct nsc_ircc_cb *self);
@@ -146,7 +177,10 @@ static int nsc_ircc_net_open(struct net_device *dev);
146static int nsc_ircc_net_close(struct net_device *dev); 177static int nsc_ircc_net_close(struct net_device *dev);
147static int nsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 178static int nsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
148static struct net_device_stats *nsc_ircc_net_get_stats(struct net_device *dev); 179static struct net_device_stats *nsc_ircc_net_get_stats(struct net_device *dev);
149static int nsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data); 180
181/* Globals */
182static int pnp_registered;
183static int pnp_succeeded;
150 184
151/* 185/*
152 * Function nsc_ircc_init () 186 * Function nsc_ircc_init ()
@@ -158,28 +192,36 @@ static int __init nsc_ircc_init(void)
158{ 192{
159 chipio_t info; 193 chipio_t info;
160 nsc_chip_t *chip; 194 nsc_chip_t *chip;
161 int ret = -ENODEV; 195 int ret;
162 int cfg_base; 196 int cfg_base;
163 int cfg, id; 197 int cfg, id;
164 int reg; 198 int reg;
165 int i = 0; 199 int i = 0;
166 200
201 ret = platform_driver_register(&nsc_ircc_driver);
202 if (ret) {
203 IRDA_ERROR("%s, Can't register driver!\n", driver_name);
204 return ret;
205 }
206
207 /* Register with PnP subsystem to detect disable ports */
208 ret = pnp_register_driver(&nsc_ircc_pnp_driver);
209
210 if (ret >= 0)
211 pnp_registered = 1;
212
213 ret = -ENODEV;
214
167 /* Probe for all the NSC chipsets we know about */ 215 /* Probe for all the NSC chipsets we know about */
168 for (chip=chips; chip->name ; chip++) { 216 for (chip = chips; chip->name ; chip++) {
169 IRDA_DEBUG(2, "%s(), Probing for %s ...\n", __FUNCTION__, 217 IRDA_DEBUG(2, "%s(), Probing for %s ...\n", __FUNCTION__,
170 chip->name); 218 chip->name);
171 219
172 /* Try all config registers for this chip */ 220 /* Try all config registers for this chip */
173 for (cfg=0; cfg<3; cfg++) { 221 for (cfg = 0; cfg < ARRAY_SIZE(chip->cfg); cfg++) {
174 cfg_base = chip->cfg[cfg]; 222 cfg_base = chip->cfg[cfg];
175 if (!cfg_base) 223 if (!cfg_base)
176 continue; 224 continue;
177
178 memset(&info, 0, sizeof(chipio_t));
179 info.cfg_base = cfg_base;
180 info.fir_base = io[i];
181 info.dma = dma[i];
182 info.irq = irq[i];
183 225
184 /* Read index register */ 226 /* Read index register */
185 reg = inb(cfg_base); 227 reg = inb(cfg_base);
@@ -194,24 +236,65 @@ static int __init nsc_ircc_init(void)
194 if ((id & chip->cid_mask) == chip->cid_value) { 236 if ((id & chip->cid_mask) == chip->cid_value) {
195 IRDA_DEBUG(2, "%s() Found %s chip, revision=%d\n", 237 IRDA_DEBUG(2, "%s() Found %s chip, revision=%d\n",
196 __FUNCTION__, chip->name, id & ~chip->cid_mask); 238 __FUNCTION__, chip->name, id & ~chip->cid_mask);
197 /*
198 * If the user supplies the base address, then
199 * we init the chip, if not we probe the values
200 * set by the BIOS
201 */
202 if (io[i] < 0x2000) {
203 chip->init(chip, &info);
204 } else
205 chip->probe(chip, &info);
206 239
207 if (nsc_ircc_open(i, &info) == 0) 240 /*
208 ret = 0; 241 * If we found a correct PnP setting,
242 * we first try it.
243 */
244 if (pnp_succeeded) {
245 memset(&info, 0, sizeof(chipio_t));
246 info.cfg_base = cfg_base;
247 info.fir_base = pnp_info.fir_base;
248 info.dma = pnp_info.dma;
249 info.irq = pnp_info.irq;
250
251 if (info.fir_base < 0x2000) {
252 IRDA_MESSAGE("%s, chip->init\n", driver_name);
253 chip->init(chip, &info);
254 } else
255 chip->probe(chip, &info);
256
257 if (nsc_ircc_open(&info) >= 0)
258 ret = 0;
259 }
260
261 /*
262 * Opening based on PnP values failed.
263 * Let's fallback to user values, or probe
264 * the chip.
265 */
266 if (ret) {
267 IRDA_DEBUG(2, "%s, PnP init failed\n", driver_name);
268 memset(&info, 0, sizeof(chipio_t));
269 info.cfg_base = cfg_base;
270 info.fir_base = io[i];
271 info.dma = dma[i];
272 info.irq = irq[i];
273
274 /*
275 * If the user supplies the base address, then
276 * we init the chip, if not we probe the values
277 * set by the BIOS
278 */
279 if (io[i] < 0x2000) {
280 chip->init(chip, &info);
281 } else
282 chip->probe(chip, &info);
283
284 if (nsc_ircc_open(&info) >= 0)
285 ret = 0;
286 }
209 i++; 287 i++;
210 } else { 288 } else {
211 IRDA_DEBUG(2, "%s(), Wrong chip id=0x%02x\n", __FUNCTION__, id); 289 IRDA_DEBUG(2, "%s(), Wrong chip id=0x%02x\n", __FUNCTION__, id);
212 } 290 }
213 } 291 }
214 292 }
293
294 if (ret) {
295 platform_driver_unregister(&nsc_ircc_driver);
296 pnp_unregister_driver(&nsc_ircc_pnp_driver);
297 pnp_registered = 0;
215 } 298 }
216 299
217 return ret; 300 return ret;
@@ -227,12 +310,17 @@ static void __exit nsc_ircc_cleanup(void)
227{ 310{
228 int i; 311 int i;
229 312
230 pm_unregister_all(nsc_ircc_pmproc); 313 for (i = 0; i < ARRAY_SIZE(dev_self); i++) {
231
232 for (i=0; i < 4; i++) {
233 if (dev_self[i]) 314 if (dev_self[i])
234 nsc_ircc_close(dev_self[i]); 315 nsc_ircc_close(dev_self[i]);
235 } 316 }
317
318 platform_driver_unregister(&nsc_ircc_driver);
319
320 if (pnp_registered)
321 pnp_unregister_driver(&nsc_ircc_pnp_driver);
322
323 pnp_registered = 0;
236} 324}
237 325
238/* 326/*
@@ -241,16 +329,26 @@ static void __exit nsc_ircc_cleanup(void)
241 * Open driver instance 329 * Open driver instance
242 * 330 *
243 */ 331 */
244static int __init nsc_ircc_open(int i, chipio_t *info) 332static int __init nsc_ircc_open(chipio_t *info)
245{ 333{
246 struct net_device *dev; 334 struct net_device *dev;
247 struct nsc_ircc_cb *self; 335 struct nsc_ircc_cb *self;
248 struct pm_dev *pmdev;
249 void *ret; 336 void *ret;
250 int err; 337 int err, chip_index;
251 338
252 IRDA_DEBUG(2, "%s()\n", __FUNCTION__); 339 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
253 340
341
342 for (chip_index = 0; chip_index < ARRAY_SIZE(dev_self); chip_index++) {
343 if (!dev_self[chip_index])
344 break;
345 }
346
347 if (chip_index == ARRAY_SIZE(dev_self)) {
348 IRDA_ERROR("%s(), maximum number of supported chips reached!\n", __FUNCTION__);
349 return -ENOMEM;
350 }
351
254 IRDA_MESSAGE("%s, Found chip at base=0x%03x\n", driver_name, 352 IRDA_MESSAGE("%s, Found chip at base=0x%03x\n", driver_name,
255 info->cfg_base); 353 info->cfg_base);
256 354
@@ -271,8 +369,8 @@ static int __init nsc_ircc_open(int i, chipio_t *info)
271 spin_lock_init(&self->lock); 369 spin_lock_init(&self->lock);
272 370
273 /* Need to store self somewhere */ 371 /* Need to store self somewhere */
274 dev_self[i] = self; 372 dev_self[chip_index] = self;
275 self->index = i; 373 self->index = chip_index;
276 374
277 /* Initialize IO */ 375 /* Initialize IO */
278 self->io.cfg_base = info->cfg_base; 376 self->io.cfg_base = info->cfg_base;
@@ -351,7 +449,7 @@ static int __init nsc_ircc_open(int i, chipio_t *info)
351 449
352 /* Check if user has supplied a valid dongle id or not */ 450 /* Check if user has supplied a valid dongle id or not */
353 if ((dongle_id <= 0) || 451 if ((dongle_id <= 0) ||
354 (dongle_id >= (sizeof(dongle_types) / sizeof(dongle_types[0]))) ) { 452 (dongle_id >= ARRAY_SIZE(dongle_types))) {
355 dongle_id = nsc_ircc_read_dongle_id(self->io.fir_base); 453 dongle_id = nsc_ircc_read_dongle_id(self->io.fir_base);
356 454
357 IRDA_MESSAGE("%s, Found dongle: %s\n", driver_name, 455 IRDA_MESSAGE("%s, Found dongle: %s\n", driver_name,
@@ -364,11 +462,18 @@ static int __init nsc_ircc_open(int i, chipio_t *info)
364 self->io.dongle_id = dongle_id; 462 self->io.dongle_id = dongle_id;
365 nsc_ircc_init_dongle_interface(self->io.fir_base, dongle_id); 463 nsc_ircc_init_dongle_interface(self->io.fir_base, dongle_id);
366 464
367 pmdev = pm_register(PM_SYS_DEV, PM_SYS_IRDA, nsc_ircc_pmproc); 465 self->pldev = platform_device_register_simple(NSC_IRCC_DRIVER_NAME,
368 if (pmdev) 466 self->index, NULL, 0);
369 pmdev->data = self; 467 if (IS_ERR(self->pldev)) {
468 err = PTR_ERR(self->pldev);
469 goto out5;
470 }
471 platform_set_drvdata(self->pldev, self);
370 472
371 return 0; 473 return chip_index;
474
475 out5:
476 unregister_netdev(dev);
372 out4: 477 out4:
373 dma_free_coherent(NULL, self->tx_buff.truesize, 478 dma_free_coherent(NULL, self->tx_buff.truesize,
374 self->tx_buff.head, self->tx_buff_dma); 479 self->tx_buff.head, self->tx_buff_dma);
@@ -379,7 +484,7 @@ static int __init nsc_ircc_open(int i, chipio_t *info)
379 release_region(self->io.fir_base, self->io.fir_ext); 484 release_region(self->io.fir_base, self->io.fir_ext);
380 out1: 485 out1:
381 free_netdev(dev); 486 free_netdev(dev);
382 dev_self[i] = NULL; 487 dev_self[chip_index] = NULL;
383 return err; 488 return err;
384} 489}
385 490
@@ -399,6 +504,8 @@ static int __exit nsc_ircc_close(struct nsc_ircc_cb *self)
399 504
400 iobase = self->io.fir_base; 505 iobase = self->io.fir_base;
401 506
507 platform_device_unregister(self->pldev);
508
402 /* Remove netdevice */ 509 /* Remove netdevice */
403 unregister_netdev(self->netdev); 510 unregister_netdev(self->netdev);
404 511
@@ -806,6 +913,43 @@ static int nsc_ircc_probe_39x(nsc_chip_t *chip, chipio_t *info)
806 return 0; 913 return 0;
807} 914}
808 915
916/* PNP probing */
917static int nsc_ircc_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *id)
918{
919 memset(&pnp_info, 0, sizeof(chipio_t));
920 pnp_info.irq = -1;
921 pnp_info.dma = -1;
922 pnp_succeeded = 1;
923
924 /* There don't seem to be any way to get the cfg_base.
925 * On my box, cfg_base is in the PnP descriptor of the
926 * motherboard. Oh well... Jean II */
927
928 if (pnp_port_valid(dev, 0) &&
929 !(pnp_port_flags(dev, 0) & IORESOURCE_DISABLED))
930 pnp_info.fir_base = pnp_port_start(dev, 0);
931
932 if (pnp_irq_valid(dev, 0) &&
933 !(pnp_irq_flags(dev, 0) & IORESOURCE_DISABLED))
934 pnp_info.irq = pnp_irq(dev, 0);
935
936 if (pnp_dma_valid(dev, 0) &&
937 !(pnp_dma_flags(dev, 0) & IORESOURCE_DISABLED))
938 pnp_info.dma = pnp_dma(dev, 0);
939
940 IRDA_DEBUG(0, "%s() : From PnP, found firbase 0x%03X ; irq %d ; dma %d.\n",
941 __FUNCTION__, pnp_info.fir_base, pnp_info.irq, pnp_info.dma);
942
943 if((pnp_info.fir_base == 0) ||
944 (pnp_info.irq == -1) || (pnp_info.dma == -1)) {
945 /* Returning an error will disable the device. Yuck ! */
946 //return -EINVAL;
947 pnp_succeeded = 0;
948 }
949
950 return 0;
951}
952
809/* 953/*
810 * Function nsc_ircc_setup (info) 954 * Function nsc_ircc_setup (info)
811 * 955 *
@@ -2161,45 +2305,83 @@ static struct net_device_stats *nsc_ircc_net_get_stats(struct net_device *dev)
2161 return &self->stats; 2305 return &self->stats;
2162} 2306}
2163 2307
2164static void nsc_ircc_suspend(struct nsc_ircc_cb *self) 2308static int nsc_ircc_suspend(struct platform_device *dev, pm_message_t state)
2165{ 2309{
2166 IRDA_MESSAGE("%s, Suspending\n", driver_name); 2310 struct nsc_ircc_cb *self = platform_get_drvdata(dev);
2311 int bank;
2312 unsigned long flags;
2313 int iobase = self->io.fir_base;
2167 2314
2168 if (self->io.suspended) 2315 if (self->io.suspended)
2169 return; 2316 return 0;
2170 2317
2171 nsc_ircc_net_close(self->netdev); 2318 IRDA_DEBUG(1, "%s, Suspending\n", driver_name);
2172 2319
2320 rtnl_lock();
2321 if (netif_running(self->netdev)) {
2322 netif_device_detach(self->netdev);
2323 spin_lock_irqsave(&self->lock, flags);
2324 /* Save current bank */
2325 bank = inb(iobase+BSR);
2326
2327 /* Disable interrupts */
2328 switch_bank(iobase, BANK0);
2329 outb(0, iobase+IER);
2330
2331 /* Restore bank register */
2332 outb(bank, iobase+BSR);
2333
2334 spin_unlock_irqrestore(&self->lock, flags);
2335 free_irq(self->io.irq, self->netdev);
2336 disable_dma(self->io.dma);
2337 }
2173 self->io.suspended = 1; 2338 self->io.suspended = 1;
2339 rtnl_unlock();
2340
2341 return 0;
2174} 2342}
2175 2343
2176static void nsc_ircc_wakeup(struct nsc_ircc_cb *self) 2344static int nsc_ircc_resume(struct platform_device *dev)
2177{ 2345{
2346 struct nsc_ircc_cb *self = platform_get_drvdata(dev);
2347 unsigned long flags;
2348
2178 if (!self->io.suspended) 2349 if (!self->io.suspended)
2179 return; 2350 return 0;
2180 2351
2352 IRDA_DEBUG(1, "%s, Waking up\n", driver_name);
2353
2354 rtnl_lock();
2181 nsc_ircc_setup(&self->io); 2355 nsc_ircc_setup(&self->io);
2182 nsc_ircc_net_open(self->netdev); 2356 nsc_ircc_init_dongle_interface(self->io.fir_base, self->io.dongle_id);
2183
2184 IRDA_MESSAGE("%s, Waking up\n", driver_name);
2185 2357
2358 if (netif_running(self->netdev)) {
2359 if (request_irq(self->io.irq, nsc_ircc_interrupt, 0,
2360 self->netdev->name, self->netdev)) {
2361 IRDA_WARNING("%s, unable to allocate irq=%d\n",
2362 driver_name, self->io.irq);
2363
2364 /*
2365 * Don't fail resume process, just kill this
2366 * network interface
2367 */
2368 unregister_netdevice(self->netdev);
2369 } else {
2370 spin_lock_irqsave(&self->lock, flags);
2371 nsc_ircc_change_speed(self, self->io.speed);
2372 spin_unlock_irqrestore(&self->lock, flags);
2373 netif_device_attach(self->netdev);
2374 }
2375
2376 } else {
2377 spin_lock_irqsave(&self->lock, flags);
2378 nsc_ircc_change_speed(self, 9600);
2379 spin_unlock_irqrestore(&self->lock, flags);
2380 }
2186 self->io.suspended = 0; 2381 self->io.suspended = 0;
2187} 2382 rtnl_unlock();
2188 2383
2189static int nsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data) 2384 return 0;
2190{
2191 struct nsc_ircc_cb *self = (struct nsc_ircc_cb*) dev->data;
2192 if (self) {
2193 switch (rqst) {
2194 case PM_SUSPEND:
2195 nsc_ircc_suspend(self);
2196 break;
2197 case PM_RESUME:
2198 nsc_ircc_wakeup(self);
2199 break;
2200 }
2201 }
2202 return 0;
2203} 2385}
2204 2386
2205MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>"); 2387MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
diff --git a/drivers/net/irda/nsc-ircc.h b/drivers/net/irda/nsc-ircc.h
index 6edf7e514624..dacf671abcd6 100644
--- a/drivers/net/irda/nsc-ircc.h
+++ b/drivers/net/irda/nsc-ircc.h
@@ -269,7 +269,7 @@ struct nsc_ircc_cb {
269 __u32 new_speed; 269 __u32 new_speed;
270 int index; /* Instance index */ 270 int index; /* Instance index */
271 271
272 struct pm_dev *dev; 272 struct platform_device *pldev;
273}; 273};
274 274
275static inline void switch_bank(int iobase, int bank) 275static inline void switch_bank(int iobase, int bank)
diff --git a/drivers/net/irda/sir_dongle.c b/drivers/net/irda/sir_dongle.c
index 8d225921ae7b..d7e32d9554fc 100644
--- a/drivers/net/irda/sir_dongle.c
+++ b/drivers/net/irda/sir_dongle.c
@@ -16,6 +16,7 @@
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/smp_lock.h> 17#include <linux/smp_lock.h>
18#include <linux/kmod.h> 18#include <linux/kmod.h>
19#include <linux/mutex.h>
19 20
20#include <net/irda/irda.h> 21#include <net/irda/irda.h>
21 22
@@ -28,7 +29,7 @@
28 */ 29 */
29 30
30static LIST_HEAD(dongle_list); /* list of registered dongle drivers */ 31static LIST_HEAD(dongle_list); /* list of registered dongle drivers */
31static DECLARE_MUTEX(dongle_list_lock); /* protects the list */ 32static DEFINE_MUTEX(dongle_list_lock); /* protects the list */
32 33
33int irda_register_dongle(struct dongle_driver *new) 34int irda_register_dongle(struct dongle_driver *new)
34{ 35{
@@ -38,25 +39,25 @@ int irda_register_dongle(struct dongle_driver *new)
38 IRDA_DEBUG(0, "%s : registering dongle \"%s\" (%d).\n", 39 IRDA_DEBUG(0, "%s : registering dongle \"%s\" (%d).\n",
39 __FUNCTION__, new->driver_name, new->type); 40 __FUNCTION__, new->driver_name, new->type);
40 41
41 down(&dongle_list_lock); 42 mutex_lock(&dongle_list_lock);
42 list_for_each(entry, &dongle_list) { 43 list_for_each(entry, &dongle_list) {
43 drv = list_entry(entry, struct dongle_driver, dongle_list); 44 drv = list_entry(entry, struct dongle_driver, dongle_list);
44 if (new->type == drv->type) { 45 if (new->type == drv->type) {
45 up(&dongle_list_lock); 46 mutex_unlock(&dongle_list_lock);
46 return -EEXIST; 47 return -EEXIST;
47 } 48 }
48 } 49 }
49 list_add(&new->dongle_list, &dongle_list); 50 list_add(&new->dongle_list, &dongle_list);
50 up(&dongle_list_lock); 51 mutex_unlock(&dongle_list_lock);
51 return 0; 52 return 0;
52} 53}
53EXPORT_SYMBOL(irda_register_dongle); 54EXPORT_SYMBOL(irda_register_dongle);
54 55
55int irda_unregister_dongle(struct dongle_driver *drv) 56int irda_unregister_dongle(struct dongle_driver *drv)
56{ 57{
57 down(&dongle_list_lock); 58 mutex_lock(&dongle_list_lock);
58 list_del(&drv->dongle_list); 59 list_del(&drv->dongle_list);
59 up(&dongle_list_lock); 60 mutex_unlock(&dongle_list_lock);
60 return 0; 61 return 0;
61} 62}
62EXPORT_SYMBOL(irda_unregister_dongle); 63EXPORT_SYMBOL(irda_unregister_dongle);
@@ -75,7 +76,7 @@ int sirdev_get_dongle(struct sir_dev *dev, IRDA_DONGLE type)
75 return -EBUSY; 76 return -EBUSY;
76 77
77 /* serialize access to the list of registered dongles */ 78 /* serialize access to the list of registered dongles */
78 down(&dongle_list_lock); 79 mutex_lock(&dongle_list_lock);
79 80
80 list_for_each(entry, &dongle_list) { 81 list_for_each(entry, &dongle_list) {
81 drv = list_entry(entry, struct dongle_driver, dongle_list); 82 drv = list_entry(entry, struct dongle_driver, dongle_list);
@@ -109,14 +110,14 @@ int sirdev_get_dongle(struct sir_dev *dev, IRDA_DONGLE type)
109 if (!drv->open || (err=drv->open(dev))!=0) 110 if (!drv->open || (err=drv->open(dev))!=0)
110 goto out_reject; /* failed to open driver */ 111 goto out_reject; /* failed to open driver */
111 112
112 up(&dongle_list_lock); 113 mutex_unlock(&dongle_list_lock);
113 return 0; 114 return 0;
114 115
115out_reject: 116out_reject:
116 dev->dongle_drv = NULL; 117 dev->dongle_drv = NULL;
117 module_put(drv->owner); 118 module_put(drv->owner);
118out_unlock: 119out_unlock:
119 up(&dongle_list_lock); 120 mutex_unlock(&dongle_list_lock);
120 return err; 121 return err;
121} 122}
122 123
diff --git a/drivers/net/irda/toim3232-sir.c b/drivers/net/irda/toim3232-sir.c
new file mode 100644
index 000000000000..aa1a9b0ed83e
--- /dev/null
+++ b/drivers/net/irda/toim3232-sir.c
@@ -0,0 +1,375 @@
1/*********************************************************************
2 *
3 * Filename: toim3232-sir.c
4 * Version: 1.0
5 * Description: Implementation of dongles based on the Vishay/Temic
6 * TOIM3232 SIR Endec chipset. Currently only the
7 * IRWave IR320ST-2 is tested, although it should work
8 * with any TOIM3232 or TOIM4232 chipset based RS232
9 * dongle with minimal modification.
10 * Based heavily on the Tekram driver (tekram.c),
11 * with thanks to Dag Brattli and Martin Diehl.
12 * Status: Experimental.
13 * Author: David Basden <davidb-irda@rcpt.to>
14 * Created at: Thu Feb 09 23:47:32 2006
15 *
16 * Copyright (c) 2006 David Basden.
17 * Copyright (c) 1998-1999 Dag Brattli,
18 * Copyright (c) 2002 Martin Diehl,
19 * All Rights Reserved.
20 *
21 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU General Public License as
23 * published by the Free Software Foundation; either version 2 of
24 * the License, or (at your option) any later version.
25 *
26 * Neither Dag Brattli nor University of Tromsø admit liability nor
27 * provide warranty for any of this software. This material is
28 * provided "AS-IS" and at no charge.
29 *
30 ********************************************************************/
31
32/*
33 * This driver has currently only been tested on the IRWave IR320ST-2
34 *
35 * PROTOCOL:
36 *
37 * The protocol for talking to the TOIM3232 is quite easy, and is
38 * designed to interface with RS232 with only level convertors. The
39 * BR/~D line on the chip is brought high to signal 'command mode',
40 * where a command byte is sent to select the baudrate of the RS232
41 * interface and the pulse length of the IRDA output. When BR/~D
42 * is brought low, the dongle then changes to the selected baudrate,
43 * and the RS232 interface is used for data until BR/~D is brought
44 * high again. The initial speed for the TOIMx323 after RESET is
45 * 9600 baud. The baudrate for command-mode is the last selected
46 * baud-rate, or 9600 after a RESET.
47 *
48 * The dongle I have (below) adds some extra hardware on the front end,
49 * but this is mostly directed towards pariasitic power from the RS232
50 * line rather than changing very much about how to communicate with
51 * the TOIM3232.
52 *
53 * The protocol to talk to the TOIM4232 chipset seems to be almost
54 * identical to the TOIM3232 (and the 4232 datasheet is more detailed)
55 * so this code will probably work on that as well, although I haven't
56 * tested it on that hardware.
57 *
58 * Target dongle variations that might be common:
59 *
60 * DTR and RTS function:
61 * The data sheet for the 4232 has a sample implementation that hooks the
62 * DTR and RTS lines to the RESET and BaudRate/~Data lines of the
63 * chip (through line-converters). Given both DTR and RTS would have to
64 * be held low in normal operation, and the TOIMx232 requires +5V to
65 * signal ground, most dongle designers would almost certainly choose
66 * an implementation that kept at least one of DTR or RTS high in
67 * normal operation to provide power to the dongle, but will likely
68 * vary between designs.
69 *
70 * User specified command bits:
71 * There are two user-controllable output lines from the TOIMx232 that
72 * can be set low or high by setting the appropriate bits in the
73 * high-nibble of the command byte (when setting speed and pulse length).
74 * These might be used to switch on and off added hardware or extra
75 * dongle features.
76 *
77 *
78 * Target hardware: IRWave IR320ST-2
79 *
80 * The IRWave IR320ST-2 is a simple dongle based on the Vishay/Temic
81 * TOIM3232 SIR Endec and the Vishay/Temic TFDS4500 SIR IRDA transciever.
82 * It uses a hex inverter and some discrete components to buffer and
83 * line convert the RS232 down to 5V.
84 *
85 * The dongle is powered through a voltage regulator, fed by a large
86 * capacitor. To switch the dongle on, DTR is brought high to charge
87 * the capacitor and drive the voltage regulator. DTR isn't associated
88 * with any control lines on the TOIM3232. Parisitic power is also taken
89 * from the RTS, TD and RD lines when brought high, but through resistors.
90 * When DTR is low, the circuit might lose power even with RTS high.
91 *
92 * RTS is inverted and attached to the BR/~D input pin. When RTS
93 * is high, BR/~D is low, and the TOIM3232 is in the normal 'data' mode.
94 * RTS is brought low, BR/~D is high, and the TOIM3232 is in 'command
95 * mode'.
96 *
97 * For some unknown reason, the RESET line isn't actually connected
98 * to anything. This means to reset the dongle to get it to a known
99 * state (9600 baud) you must drop DTR and RTS low, wait for the power
100 * capacitor to discharge, and then bring DTR (and RTS for data mode)
101 * high again, and wait for the capacitor to charge, the power supply
102 * to stabilise, and the oscillator clock to stabilise.
103 *
104 * Fortunately, if the current baudrate is known, the chipset can
105 * easily change speed by entering command mode without having to
106 * reset the dongle first.
107 *
108 * Major Components:
109 *
110 * - Vishay/Temic TOIM3232 SIR Endec to change RS232 pulse timings
111 * to IRDA pulse timings
112 * - 3.6864MHz crystal to drive TOIM3232 clock oscillator
113 * - DM74lS04M Inverting Hex line buffer for RS232 input buffering
114 * and level conversion
115 * - PJ2951AC 150mA voltage regulator
116 * - Vishay/Temic TFDS4500 SIR IRDA front-end transceiver
117 *
118 */
119
120#include <linux/module.h>
121#include <linux/delay.h>
122#include <linux/init.h>
123
124#include <net/irda/irda.h>
125
126#include "sir-dev.h"
127
128static int toim3232delay = 150; /* default is 150 ms */
129module_param(toim3232delay, int, 0);
130MODULE_PARM_DESC(toim3232delay, "toim3232 dongle write complete delay");
131
132#if 0
133static int toim3232flipdtr = 0; /* default is DTR high to reset */
134module_param(toim3232flipdtr, int, 0);
135MODULE_PARM_DESC(toim3232flipdtr, "toim3232 dongle invert DTR (Reset)");
136
137static int toim3232fliprts = 0; /* default is RTS high for baud change */
138module_param(toim3232fliptrs, int, 0);
139MODULE_PARM_DESC(toim3232fliprts, "toim3232 dongle invert RTS (BR/D)");
140#endif
141
142static int toim3232_open(struct sir_dev *);
143static int toim3232_close(struct sir_dev *);
144static int toim3232_change_speed(struct sir_dev *, unsigned);
145static int toim3232_reset(struct sir_dev *);
146
147#define TOIM3232_115200 0x00
148#define TOIM3232_57600 0x01
149#define TOIM3232_38400 0x02
150#define TOIM3232_19200 0x03
151#define TOIM3232_9600 0x06
152#define TOIM3232_2400 0x0A
153
154#define TOIM3232_PW 0x10 /* Pulse select bit */
155
156static struct dongle_driver toim3232 = {
157 .owner = THIS_MODULE,
158 .driver_name = "Vishay TOIM3232",
159 .type = IRDA_TOIM3232_DONGLE,
160 .open = toim3232_open,
161 .close = toim3232_close,
162 .reset = toim3232_reset,
163 .set_speed = toim3232_change_speed,
164};
165
166static int __init toim3232_sir_init(void)
167{
168 if (toim3232delay < 1 || toim3232delay > 500)
169 toim3232delay = 200;
170 IRDA_DEBUG(1, "%s - using %d ms delay\n",
171 toim3232.driver_name, toim3232delay);
172 return irda_register_dongle(&toim3232);
173}
174
175static void __exit toim3232_sir_cleanup(void)
176{
177 irda_unregister_dongle(&toim3232);
178}
179
180static int toim3232_open(struct sir_dev *dev)
181{
182 struct qos_info *qos = &dev->qos;
183
184 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
185
186 /* Pull the lines high to start with.
187 *
188 * For the IR320ST-2, we need to charge the main supply capacitor to
189 * switch the device on. We keep DTR high throughout to do this.
190 * When RTS, TD and RD are high, they will also trickle-charge the
191 * cap. RTS is high for data transmission, and low for baud rate select.
192 * -- DGB
193 */
194 sirdev_set_dtr_rts(dev, TRUE, TRUE);
195
196 /* The TOI3232 supports many speeds between 1200bps and 115000bps.
197 * We really only care about those supported by the IRDA spec, but
198 * 38400 seems to be implemented in many places */
199 qos->baud_rate.bits &= IR_2400|IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
200
201 /* From the tekram driver. Not sure what a reasonable value is -- DGB */
202 qos->min_turn_time.bits = 0x01; /* Needs at least 10 ms */
203 irda_qos_bits_to_value(qos);
204
205 /* irda thread waits 50 msec for power settling */
206
207 return 0;
208}
209
210static int toim3232_close(struct sir_dev *dev)
211{
212 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
213
214 /* Power off dongle */
215 sirdev_set_dtr_rts(dev, FALSE, FALSE);
216
217 return 0;
218}
219
220/*
221 * Function toim3232change_speed (dev, state, speed)
222 *
223 * Set the speed for the TOIM3232 based dongle. Warning, this
224 * function must be called with a process context!
225 *
226 * Algorithm
227 * 1. keep DTR high but clear RTS to bring into baud programming mode
228 * 2. wait at least 7us to enter programming mode
229 * 3. send control word to set baud rate and timing
230 * 4. wait at least 1us
231 * 5. bring RTS high to enter DATA mode (RS232 is passed through to transceiver)
232 * 6. should take effect immediately (although probably worth waiting)
233 */
234
235#define TOIM3232_STATE_WAIT_SPEED (SIRDEV_STATE_DONGLE_SPEED + 1)
236
237static int toim3232_change_speed(struct sir_dev *dev, unsigned speed)
238{
239 unsigned state = dev->fsm.substate;
240 unsigned delay = 0;
241 u8 byte;
242 static int ret = 0;
243
244 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
245
246 switch(state) {
247 case SIRDEV_STATE_DONGLE_SPEED:
248
249 /* Figure out what we are going to send as a control byte */
250 switch (speed) {
251 case 2400:
252 byte = TOIM3232_PW|TOIM3232_2400;
253 break;
254 default:
255 speed = 9600;
256 ret = -EINVAL;
257 /* fall thru */
258 case 9600:
259 byte = TOIM3232_PW|TOIM3232_9600;
260 break;
261 case 19200:
262 byte = TOIM3232_PW|TOIM3232_19200;
263 break;
264 case 38400:
265 byte = TOIM3232_PW|TOIM3232_38400;
266 break;
267 case 57600:
268 byte = TOIM3232_PW|TOIM3232_57600;
269 break;
270 case 115200:
271 byte = TOIM3232_115200;
272 break;
273 }
274
275 /* Set DTR, Clear RTS: Go into baud programming mode */
276 sirdev_set_dtr_rts(dev, TRUE, FALSE);
277
278 /* Wait at least 7us */
279 udelay(14);
280
281 /* Write control byte */
282 sirdev_raw_write(dev, &byte, 1);
283
284 dev->speed = speed;
285
286 state = TOIM3232_STATE_WAIT_SPEED;
287 delay = toim3232delay;
288 break;
289
290 case TOIM3232_STATE_WAIT_SPEED:
291 /* Have transmitted control byte * Wait for 'at least 1us' */
292 udelay(14);
293
294 /* Set DTR, Set RTS: Go into normal data mode */
295 sirdev_set_dtr_rts(dev, TRUE, TRUE);
296
297 /* Wait (TODO: check this is needed) */
298 udelay(50);
299 break;
300
301 default:
302 printk(KERN_ERR "%s - undefined state %d\n", __FUNCTION__, state);
303 ret = -EINVAL;
304 break;
305 }
306
307 dev->fsm.substate = state;
308 return (delay > 0) ? delay : ret;
309}
310
311/*
312 * Function toim3232reset (driver)
313 *
314 * This function resets the toim3232 dongle. Warning, this function
315 * must be called with a process context!!
316 *
317 * What we should do is:
318 * 0. Pull RESET high
319 * 1. Wait for at least 7us
320 * 2. Pull RESET low
321 * 3. Wait for at least 7us
322 * 4. Pull BR/~D high
323 * 5. Wait for at least 7us
324 * 6. Send control byte to set baud rate
325 * 7. Wait at least 1us after stop bit
326 * 8. Pull BR/~D low
327 * 9. Should then be in data mode
328 *
329 * Because the IR320ST-2 doesn't have the RESET line connected for some reason,
330 * we'll have to do something else.
331 *
332 * The default speed after a RESET is 9600, so lets try just bringing it up in
333 * data mode after switching it off, waiting for the supply capacitor to
334 * discharge, and then switch it back on. This isn't actually pulling RESET
335 * high, but it seems to have the same effect.
336 *
337 * This behaviour will probably work on dongles that have the RESET line connected,
338 * but if not, add a flag for the IR320ST-2, and implment the above-listed proper
339 * behaviour.
340 *
341 * RTS is inverted and then fed to BR/~D, so to put it in programming mode, we
342 * need to have pull RTS low
343 */
344
345static int toim3232_reset(struct sir_dev *dev)
346{
347 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
348
349 /* Switch off both DTR and RTS to switch off dongle */
350 sirdev_set_dtr_rts(dev, FALSE, FALSE);
351
352 /* Should sleep a while. This might be evil doing it this way.*/
353 set_current_state(TASK_UNINTERRUPTIBLE);
354 schedule_timeout(msecs_to_jiffies(50));
355
356 /* Set DTR, Set RTS (data mode) */
357 sirdev_set_dtr_rts(dev, TRUE, TRUE);
358
359 /* Wait at least 10 ms for power to stabilize again */
360 set_current_state(TASK_UNINTERRUPTIBLE);
361 schedule_timeout(msecs_to_jiffies(10));
362
363 /* Speed should now be 9600 */
364 dev->speed = 9600;
365
366 return 0;
367}
368
369MODULE_AUTHOR("David Basden <davidb-linux@rcpt.to>");
370MODULE_DESCRIPTION("Vishay/Temic TOIM3232 based dongle driver");
371MODULE_LICENSE("GPL");
372MODULE_ALIAS("irda-dongle-12"); /* IRDA_TOIM3232_DONGLE */
373
374module_init(toim3232_sir_init);
375module_exit(toim3232_sir_cleanup);
diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
index a9f49f058cfb..97a49e0be76b 100644
--- a/drivers/net/irda/vlsi_ir.c
+++ b/drivers/net/irda/vlsi_ir.c
@@ -1887,7 +1887,7 @@ static int __init vlsi_mod_init(void)
1887 vlsi_proc_root->owner = THIS_MODULE; 1887 vlsi_proc_root->owner = THIS_MODULE;
1888 } 1888 }
1889 1889
1890 ret = pci_module_init(&vlsi_irda_driver); 1890 ret = pci_register_driver(&vlsi_irda_driver);
1891 1891
1892 if (ret && vlsi_proc_root) 1892 if (ret && vlsi_proc_root)
1893 remove_proc_entry(PROC_DIR, NULL); 1893 remove_proc_entry(PROC_DIR, NULL);
diff --git a/drivers/net/mv643xx_eth.h b/drivers/net/mv643xx_eth.h
index 7754d1974b9e..4262c1da6d4a 100644
--- a/drivers/net/mv643xx_eth.h
+++ b/drivers/net/mv643xx_eth.h
@@ -42,13 +42,23 @@
42#define MAX_DESCS_PER_SKB 1 42#define MAX_DESCS_PER_SKB 1
43#endif 43#endif
44 44
45/*
46 * The MV643XX HW requires 8-byte alignment. However, when I/O
47 * is non-cache-coherent, we need to ensure that the I/O buffers
48 * we use don't share cache lines with other data.
49 */
50#if defined(CONFIG_DMA_NONCOHERENT) || defined(CONFIG_NOT_COHERENT_CACHE)
51#define ETH_DMA_ALIGN L1_CACHE_BYTES
52#else
53#define ETH_DMA_ALIGN 8
54#endif
55
45#define ETH_VLAN_HLEN 4 56#define ETH_VLAN_HLEN 4
46#define ETH_FCS_LEN 4 57#define ETH_FCS_LEN 4
47#define ETH_DMA_ALIGN 8 /* hw requires 8-byte alignment */ 58#define ETH_HW_IP_ALIGN 2 /* hw aligns IP header */
48#define ETH_HW_IP_ALIGN 2 /* hw aligns IP header */
49#define ETH_WRAPPER_LEN (ETH_HW_IP_ALIGN + ETH_HLEN + \ 59#define ETH_WRAPPER_LEN (ETH_HW_IP_ALIGN + ETH_HLEN + \
50 ETH_VLAN_HLEN + ETH_FCS_LEN) 60 ETH_VLAN_HLEN + ETH_FCS_LEN)
51#define ETH_RX_SKB_SIZE ((dev->mtu + ETH_WRAPPER_LEN + 7) & ~0x7) 61#define ETH_RX_SKB_SIZE (dev->mtu + ETH_WRAPPER_LEN + ETH_DMA_ALIGN)
52 62
53#define ETH_RX_QUEUES_ENABLED (1 << 0) /* use only Q0 for receive */ 63#define ETH_RX_QUEUES_ENABLED (1 << 0) /* use only Q0 for receive */
54#define ETH_TX_QUEUES_ENABLED (1 << 0) /* use only Q0 for transmit */ 64#define ETH_TX_QUEUES_ENABLED (1 << 0) /* use only Q0 for transmit */
diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
index 7e900572eaf8..9595f74da93f 100644
--- a/drivers/net/pcnet32.c
+++ b/drivers/net/pcnet32.c
@@ -22,12 +22,12 @@
22 *************************************************************************/ 22 *************************************************************************/
23 23
24#define DRV_NAME "pcnet32" 24#define DRV_NAME "pcnet32"
25#define DRV_VERSION "1.31c" 25#define DRV_VERSION "1.32"
26#define DRV_RELDATE "01.Nov.2005" 26#define DRV_RELDATE "18.Mar.2006"
27#define PFX DRV_NAME ": " 27#define PFX DRV_NAME ": "
28 28
29static const char * const version = 29static const char *const version =
30DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " tsbogend@alpha.franken.de\n"; 30 DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " tsbogend@alpha.franken.de\n";
31 31
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/kernel.h> 33#include <linux/kernel.h>
@@ -58,18 +58,23 @@ DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " tsbogend@alpha.franken.de\n";
58 * PCI device identifiers for "new style" Linux PCI Device Drivers 58 * PCI device identifiers for "new style" Linux PCI Device Drivers
59 */ 59 */
60static struct pci_device_id pcnet32_pci_tbl[] = { 60static struct pci_device_id pcnet32_pci_tbl[] = {
61 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE_HOME, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 61 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE_HOME,
62 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 62 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
63 /* 63 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE,
64 * Adapters that were sold with IBM's RS/6000 or pSeries hardware have 64 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
65 * the incorrect vendor id. 65
66 */ 66 /*
67 { PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_AMD_LANCE, PCI_ANY_ID, PCI_ANY_ID, 67 * Adapters that were sold with IBM's RS/6000 or pSeries hardware have
68 PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, 0 }, 68 * the incorrect vendor id.
69 { 0, } 69 */
70 { PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_AMD_LANCE,
71 PCI_ANY_ID, PCI_ANY_ID,
72 PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, 0},
73
74 { } /* terminate list */
70}; 75};
71 76
72MODULE_DEVICE_TABLE (pci, pcnet32_pci_tbl); 77MODULE_DEVICE_TABLE(pci, pcnet32_pci_tbl);
73 78
74static int cards_found; 79static int cards_found;
75 80
@@ -77,13 +82,11 @@ static int cards_found;
77 * VLB I/O addresses 82 * VLB I/O addresses
78 */ 83 */
79static unsigned int pcnet32_portlist[] __initdata = 84static unsigned int pcnet32_portlist[] __initdata =
80 { 0x300, 0x320, 0x340, 0x360, 0 }; 85 { 0x300, 0x320, 0x340, 0x360, 0 };
81
82
83 86
84static int pcnet32_debug = 0; 87static int pcnet32_debug = 0;
85static int tx_start = 1; /* Mapping -- 0:20, 1:64, 2:128, 3:~220 (depends on chip vers) */ 88static int tx_start = 1; /* Mapping -- 0:20, 1:64, 2:128, 3:~220 (depends on chip vers) */
86static int pcnet32vlb; /* check for VLB cards ? */ 89static int pcnet32vlb; /* check for VLB cards ? */
87 90
88static struct net_device *pcnet32_dev; 91static struct net_device *pcnet32_dev;
89 92
@@ -110,32 +113,34 @@ static int rx_copybreak = 200;
110 * to internal options 113 * to internal options
111 */ 114 */
112static const unsigned char options_mapping[] = { 115static const unsigned char options_mapping[] = {
113 PCNET32_PORT_ASEL, /* 0 Auto-select */ 116 PCNET32_PORT_ASEL, /* 0 Auto-select */
114 PCNET32_PORT_AUI, /* 1 BNC/AUI */ 117 PCNET32_PORT_AUI, /* 1 BNC/AUI */
115 PCNET32_PORT_AUI, /* 2 AUI/BNC */ 118 PCNET32_PORT_AUI, /* 2 AUI/BNC */
116 PCNET32_PORT_ASEL, /* 3 not supported */ 119 PCNET32_PORT_ASEL, /* 3 not supported */
117 PCNET32_PORT_10BT | PCNET32_PORT_FD, /* 4 10baseT-FD */ 120 PCNET32_PORT_10BT | PCNET32_PORT_FD, /* 4 10baseT-FD */
118 PCNET32_PORT_ASEL, /* 5 not supported */ 121 PCNET32_PORT_ASEL, /* 5 not supported */
119 PCNET32_PORT_ASEL, /* 6 not supported */ 122 PCNET32_PORT_ASEL, /* 6 not supported */
120 PCNET32_PORT_ASEL, /* 7 not supported */ 123 PCNET32_PORT_ASEL, /* 7 not supported */
121 PCNET32_PORT_ASEL, /* 8 not supported */ 124 PCNET32_PORT_ASEL, /* 8 not supported */
122 PCNET32_PORT_MII, /* 9 MII 10baseT */ 125 PCNET32_PORT_MII, /* 9 MII 10baseT */
123 PCNET32_PORT_MII | PCNET32_PORT_FD, /* 10 MII 10baseT-FD */ 126 PCNET32_PORT_MII | PCNET32_PORT_FD, /* 10 MII 10baseT-FD */
124 PCNET32_PORT_MII, /* 11 MII (autosel) */ 127 PCNET32_PORT_MII, /* 11 MII (autosel) */
125 PCNET32_PORT_10BT, /* 12 10BaseT */ 128 PCNET32_PORT_10BT, /* 12 10BaseT */
126 PCNET32_PORT_MII | PCNET32_PORT_100, /* 13 MII 100BaseTx */ 129 PCNET32_PORT_MII | PCNET32_PORT_100, /* 13 MII 100BaseTx */
127 PCNET32_PORT_MII | PCNET32_PORT_100 | PCNET32_PORT_FD, /* 14 MII 100BaseTx-FD */ 130 /* 14 MII 100BaseTx-FD */
128 PCNET32_PORT_ASEL /* 15 not supported */ 131 PCNET32_PORT_MII | PCNET32_PORT_100 | PCNET32_PORT_FD,
132 PCNET32_PORT_ASEL /* 15 not supported */
129}; 133};
130 134
131static const char pcnet32_gstrings_test[][ETH_GSTRING_LEN] = { 135static const char pcnet32_gstrings_test[][ETH_GSTRING_LEN] = {
132 "Loopback test (offline)" 136 "Loopback test (offline)"
133}; 137};
138
134#define PCNET32_TEST_LEN (sizeof(pcnet32_gstrings_test) / ETH_GSTRING_LEN) 139#define PCNET32_TEST_LEN (sizeof(pcnet32_gstrings_test) / ETH_GSTRING_LEN)
135 140
136#define PCNET32_NUM_REGS 168 141#define PCNET32_NUM_REGS 136
137 142
138#define MAX_UNITS 8 /* More are supported, limit only on options */ 143#define MAX_UNITS 8 /* More are supported, limit only on options */
139static int options[MAX_UNITS]; 144static int options[MAX_UNITS];
140static int full_duplex[MAX_UNITS]; 145static int full_duplex[MAX_UNITS];
141static int homepna[MAX_UNITS]; 146static int homepna[MAX_UNITS];
@@ -151,124 +156,6 @@ static int homepna[MAX_UNITS];
151 */ 156 */
152 157
153/* 158/*
154 * History:
155 * v0.01: Initial version
156 * only tested on Alpha Noname Board
157 * v0.02: changed IRQ handling for new interrupt scheme (dev_id)
158 * tested on a ASUS SP3G
159 * v0.10: fixed an odd problem with the 79C974 in a Compaq Deskpro XL
160 * looks like the 974 doesn't like stopping and restarting in a
161 * short period of time; now we do a reinit of the lance; the
162 * bug was triggered by doing ifconfig eth0 <ip> broadcast <addr>
163 * and hangs the machine (thanks to Klaus Liedl for debugging)
164 * v0.12: by suggestion from Donald Becker: Renamed driver to pcnet32,
165 * made it standalone (no need for lance.c)
166 * v0.13: added additional PCI detecting for special PCI devices (Compaq)
167 * v0.14: stripped down additional PCI probe (thanks to David C Niemi
168 * and sveneric@xs4all.nl for testing this on their Compaq boxes)
169 * v0.15: added 79C965 (VLB) probe
170 * added interrupt sharing for PCI chips
171 * v0.16: fixed set_multicast_list on Alpha machines
172 * v0.17: removed hack from dev.c; now pcnet32 uses ethif_probe in Space.c
173 * v0.19: changed setting of autoselect bit
174 * v0.20: removed additional Compaq PCI probe; there is now a working one
175 * in arch/i386/bios32.c
176 * v0.21: added endian conversion for ppc, from work by cort@cs.nmt.edu
177 * v0.22: added printing of status to ring dump
178 * v0.23: changed enet_statistics to net_devive_stats
179 * v0.90: added multicast filter
180 * added module support
181 * changed irq probe to new style
182 * added PCnetFast chip id
183 * added fix for receive stalls with Intel saturn chipsets
184 * added in-place rx skbs like in the tulip driver
185 * minor cleanups
186 * v0.91: added PCnetFast+ chip id
187 * back port to 2.0.x
188 * v1.00: added some stuff from Donald Becker's 2.0.34 version
189 * added support for byte counters in net_dev_stats
190 * v1.01: do ring dumps, only when debugging the driver
191 * increased the transmit timeout
192 * v1.02: fixed memory leak in pcnet32_init_ring()
193 * v1.10: workaround for stopped transmitter
194 * added port selection for modules
195 * detect special T1/E1 WAN card and setup port selection
196 * v1.11: fixed wrong checking of Tx errors
197 * v1.20: added check of return value kmalloc (cpeterso@cs.washington.edu)
198 * added save original kmalloc addr for freeing (mcr@solidum.com)
199 * added support for PCnetHome chip (joe@MIT.EDU)
200 * rewritten PCI card detection
201 * added dwio mode to get driver working on some PPC machines
202 * v1.21: added mii selection and mii ioctl
203 * v1.22: changed pci scanning code to make PPC people happy
204 * fixed switching to 32bit mode in pcnet32_open() (thanks
205 * to Michael Richard <mcr@solidum.com> for noticing this one)
206 * added sub vendor/device id matching (thanks again to
207 * Michael Richard <mcr@solidum.com>)
208 * added chip id for 79c973/975 (thanks to Zach Brown <zab@zabbo.net>)
209 * v1.23 fixed small bug, when manual selecting MII speed/duplex
210 * v1.24 Applied Thomas' patch to use TxStartPoint and thus decrease TxFIFO
211 * underflows. Added tx_start_pt module parameter. Increased
212 * TX_RING_SIZE from 16 to 32. Added #ifdef'd code to use DXSUFLO
213 * for FAST[+] chipsets. <kaf@fc.hp.com>
214 * v1.24ac Added SMP spinlocking - Alan Cox <alan@redhat.com>
215 * v1.25kf Added No Interrupt on successful Tx for some Tx's <kaf@fc.hp.com>
216 * v1.26 Converted to pci_alloc_consistent, Jamey Hicks / George France
217 * <jamey@crl.dec.com>
218 * - Fixed a few bugs, related to running the controller in 32bit mode.
219 * 23 Oct, 2000. Carsten Langgaard, carstenl@mips.com
220 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
221 * v1.26p Fix oops on rmmod+insmod; plug i/o resource leak - Paul Gortmaker
222 * v1.27 improved CSR/PROM address detection, lots of cleanups,
223 * new pcnet32vlb module option, HP-PARISC support,
224 * added module parameter descriptions,
225 * initial ethtool support - Helge Deller <deller@gmx.de>
226 * v1.27a Sun Feb 10 2002 Go Taniguchi <go@turbolinux.co.jp>
227 * use alloc_etherdev and register_netdev
228 * fix pci probe not increment cards_found
229 * FD auto negotiate error workaround for xSeries250
230 * clean up and using new mii module
231 * v1.27b Sep 30 2002 Kent Yoder <yoder1@us.ibm.com>
232 * Added timer for cable connection state changes.
233 * v1.28 20 Feb 2004 Don Fry <brazilnut@us.ibm.com>
234 * Jon Mason <jonmason@us.ibm.com>, Chinmay Albal <albal@in.ibm.com>
235 * Now uses ethtool_ops, netif_msg_* and generic_mii_ioctl.
236 * Fixes bogus 'Bus master arbitration failure', pci_[un]map_single
237 * length errors, and transmit hangs. Cleans up after errors in open.
238 * Jim Lewis <jklewis@us.ibm.com> added ethernet loopback test.
239 * Thomas Munck Steenholdt <tmus@tmus.dk> non-mii ioctl corrections.
240 * v1.29 6 Apr 2004 Jim Lewis <jklewis@us.ibm.com> added physical
241 * identification code (blink led's) and register dump.
242 * Don Fry added timer for 971/972 so skbufs don't remain on tx ring
243 * forever.
244 * v1.30 18 May 2004 Don Fry removed timer and Last Transmit Interrupt
245 * (ltint) as they added complexity and didn't give good throughput.
246 * v1.30a 22 May 2004 Don Fry limit frames received during interrupt.
247 * v1.30b 24 May 2004 Don Fry fix bogus tx carrier errors with 79c973,
248 * assisted by Bruce Penrod <bmpenrod@endruntechnologies.com>.
249 * v1.30c 25 May 2004 Don Fry added netif_wake_queue after pcnet32_restart.
250 * v1.30d 01 Jun 2004 Don Fry discard oversize rx packets.
251 * v1.30e 11 Jun 2004 Don Fry recover after fifo error and rx hang.
252 * v1.30f 16 Jun 2004 Don Fry cleanup IRQ to allow 0 and 1 for PCI,
253 * expanding on suggestions from Ralf Baechle <ralf@linux-mips.org>,
254 * and Brian Murphy <brian@murphy.dk>.
255 * v1.30g 22 Jun 2004 Patrick Simmons <psimmons@flash.net> added option
256 * homepna for selecting HomePNA mode for PCNet/Home 79C978.
257 * v1.30h 24 Jun 2004 Don Fry correctly select auto, speed, duplex in bcr32.
258 * v1.30i 28 Jun 2004 Don Fry change to use module_param.
259 * v1.30j 29 Apr 2005 Don Fry fix skb/map leak with loopback test.
260 * v1.31 02 Sep 2005 Hubert WS Lin <wslin@tw.ibm.c0m> added set_ringparam().
261 * v1.31a 12 Sep 2005 Hubert WS Lin <wslin@tw.ibm.c0m> set min ring size to 4
262 * to allow loopback test to work unchanged.
263 * v1.31b 06 Oct 2005 Don Fry changed alloc_ring to show name of device
264 * if allocation fails
265 * v1.31c 01 Nov 2005 Don Fry Allied Telesyn 2700/2701 FX are 100Mbit only.
266 * Force 100Mbit FD if Auto (ASEL) is selected.
267 * See Bugzilla 2669 and 4551.
268 */
269
270
271/*
272 * Set the number of Tx and Rx buffers, using Log_2(# buffers). 159 * Set the number of Tx and Rx buffers, using Log_2(# buffers).
273 * Reasonable default values are 4 Tx buffers, and 16 Rx buffers. 160 * Reasonable default values are 4 Tx buffers, and 16 Rx buffers.
274 * That translates to 2 (4 == 2^^2) and 4 (16 == 2^^4). 161 * That translates to 2 (4 == 2^^2) and 4 (16 == 2^^4).
@@ -303,42 +190,42 @@ static int homepna[MAX_UNITS];
303 190
304/* The PCNET32 Rx and Tx ring descriptors. */ 191/* The PCNET32 Rx and Tx ring descriptors. */
305struct pcnet32_rx_head { 192struct pcnet32_rx_head {
306 u32 base; 193 u32 base;
307 s16 buf_length; 194 s16 buf_length;
308 s16 status; 195 s16 status;
309 u32 msg_length; 196 u32 msg_length;
310 u32 reserved; 197 u32 reserved;
311}; 198};
312 199
313struct pcnet32_tx_head { 200struct pcnet32_tx_head {
314 u32 base; 201 u32 base;
315 s16 length; 202 s16 length;
316 s16 status; 203 s16 status;
317 u32 misc; 204 u32 misc;
318 u32 reserved; 205 u32 reserved;
319}; 206};
320 207
321/* The PCNET32 32-Bit initialization block, described in databook. */ 208/* The PCNET32 32-Bit initialization block, described in databook. */
322struct pcnet32_init_block { 209struct pcnet32_init_block {
323 u16 mode; 210 u16 mode;
324 u16 tlen_rlen; 211 u16 tlen_rlen;
325 u8 phys_addr[6]; 212 u8 phys_addr[6];
326 u16 reserved; 213 u16 reserved;
327 u32 filter[2]; 214 u32 filter[2];
328 /* Receive and transmit ring base, along with extra bits. */ 215 /* Receive and transmit ring base, along with extra bits. */
329 u32 rx_ring; 216 u32 rx_ring;
330 u32 tx_ring; 217 u32 tx_ring;
331}; 218};
332 219
333/* PCnet32 access functions */ 220/* PCnet32 access functions */
334struct pcnet32_access { 221struct pcnet32_access {
335 u16 (*read_csr)(unsigned long, int); 222 u16 (*read_csr) (unsigned long, int);
336 void (*write_csr)(unsigned long, int, u16); 223 void (*write_csr) (unsigned long, int, u16);
337 u16 (*read_bcr)(unsigned long, int); 224 u16 (*read_bcr) (unsigned long, int);
338 void (*write_bcr)(unsigned long, int, u16); 225 void (*write_bcr) (unsigned long, int, u16);
339 u16 (*read_rap)(unsigned long); 226 u16 (*read_rap) (unsigned long);
340 void (*write_rap)(unsigned long, u16); 227 void (*write_rap) (unsigned long, u16);
341 void (*reset)(unsigned long); 228 void (*reset) (unsigned long);
342}; 229};
343 230
344/* 231/*
@@ -346,760 +233,794 @@ struct pcnet32_access {
346 * so the structure should be allocated using pci_alloc_consistent(). 233 * so the structure should be allocated using pci_alloc_consistent().
347 */ 234 */
348struct pcnet32_private { 235struct pcnet32_private {
349 struct pcnet32_init_block init_block; 236 struct pcnet32_init_block init_block;
350 /* The Tx and Rx ring entries must be aligned on 16-byte boundaries in 32bit mode. */ 237 /* The Tx and Rx ring entries must be aligned on 16-byte boundaries in 32bit mode. */
351 struct pcnet32_rx_head *rx_ring; 238 struct pcnet32_rx_head *rx_ring;
352 struct pcnet32_tx_head *tx_ring; 239 struct pcnet32_tx_head *tx_ring;
353 dma_addr_t dma_addr; /* DMA address of beginning of this 240 dma_addr_t dma_addr;/* DMA address of beginning of this
354 object, returned by 241 object, returned by pci_alloc_consistent */
355 pci_alloc_consistent */ 242 struct pci_dev *pci_dev;
356 struct pci_dev *pci_dev; /* Pointer to the associated pci device 243 const char *name;
357 structure */ 244 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
358 const char *name; 245 struct sk_buff **tx_skbuff;
359 /* The saved address of a sent-in-place packet/buffer, for skfree(). */ 246 struct sk_buff **rx_skbuff;
360 struct sk_buff **tx_skbuff; 247 dma_addr_t *tx_dma_addr;
361 struct sk_buff **rx_skbuff; 248 dma_addr_t *rx_dma_addr;
362 dma_addr_t *tx_dma_addr; 249 struct pcnet32_access a;
363 dma_addr_t *rx_dma_addr; 250 spinlock_t lock; /* Guard lock */
364 struct pcnet32_access a; 251 unsigned int cur_rx, cur_tx; /* The next free ring entry */
365 spinlock_t lock; /* Guard lock */ 252 unsigned int rx_ring_size; /* current rx ring size */
366 unsigned int cur_rx, cur_tx; /* The next free ring entry */ 253 unsigned int tx_ring_size; /* current tx ring size */
367 unsigned int rx_ring_size; /* current rx ring size */ 254 unsigned int rx_mod_mask; /* rx ring modular mask */
368 unsigned int tx_ring_size; /* current tx ring size */ 255 unsigned int tx_mod_mask; /* tx ring modular mask */
369 unsigned int rx_mod_mask; /* rx ring modular mask */ 256 unsigned short rx_len_bits;
370 unsigned int tx_mod_mask; /* tx ring modular mask */ 257 unsigned short tx_len_bits;
371 unsigned short rx_len_bits; 258 dma_addr_t rx_ring_dma_addr;
372 unsigned short tx_len_bits; 259 dma_addr_t tx_ring_dma_addr;
373 dma_addr_t rx_ring_dma_addr; 260 unsigned int dirty_rx, /* ring entries to be freed. */
374 dma_addr_t tx_ring_dma_addr; 261 dirty_tx;
375 unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */ 262
376 struct net_device_stats stats; 263 struct net_device_stats stats;
377 char tx_full; 264 char tx_full;
378 int options; 265 char phycount; /* number of phys found */
379 unsigned int shared_irq:1, /* shared irq possible */ 266 int options;
380 dxsuflo:1, /* disable transmit stop on uflo */ 267 unsigned int shared_irq:1, /* shared irq possible */
381 mii:1; /* mii port available */ 268 dxsuflo:1, /* disable transmit stop on uflo */
382 struct net_device *next; 269 mii:1; /* mii port available */
383 struct mii_if_info mii_if; 270 struct net_device *next;
384 struct timer_list watchdog_timer; 271 struct mii_if_info mii_if;
385 struct timer_list blink_timer; 272 struct timer_list watchdog_timer;
386 u32 msg_enable; /* debug message level */ 273 struct timer_list blink_timer;
274 u32 msg_enable; /* debug message level */
275
276 /* each bit indicates an available PHY */
277 u32 phymask;
387}; 278};
388 279
389static void pcnet32_probe_vlbus(void); 280static void pcnet32_probe_vlbus(void);
390static int pcnet32_probe_pci(struct pci_dev *, const struct pci_device_id *); 281static int pcnet32_probe_pci(struct pci_dev *, const struct pci_device_id *);
391static int pcnet32_probe1(unsigned long, int, struct pci_dev *); 282static int pcnet32_probe1(unsigned long, int, struct pci_dev *);
392static int pcnet32_open(struct net_device *); 283static int pcnet32_open(struct net_device *);
393static int pcnet32_init_ring(struct net_device *); 284static int pcnet32_init_ring(struct net_device *);
394static int pcnet32_start_xmit(struct sk_buff *, struct net_device *); 285static int pcnet32_start_xmit(struct sk_buff *, struct net_device *);
395static int pcnet32_rx(struct net_device *); 286static int pcnet32_rx(struct net_device *);
396static void pcnet32_tx_timeout (struct net_device *dev); 287static void pcnet32_tx_timeout(struct net_device *dev);
397static irqreturn_t pcnet32_interrupt(int, void *, struct pt_regs *); 288static irqreturn_t pcnet32_interrupt(int, void *, struct pt_regs *);
398static int pcnet32_close(struct net_device *); 289static int pcnet32_close(struct net_device *);
399static struct net_device_stats *pcnet32_get_stats(struct net_device *); 290static struct net_device_stats *pcnet32_get_stats(struct net_device *);
400static void pcnet32_load_multicast(struct net_device *dev); 291static void pcnet32_load_multicast(struct net_device *dev);
401static void pcnet32_set_multicast_list(struct net_device *); 292static void pcnet32_set_multicast_list(struct net_device *);
402static int pcnet32_ioctl(struct net_device *, struct ifreq *, int); 293static int pcnet32_ioctl(struct net_device *, struct ifreq *, int);
403static void pcnet32_watchdog(struct net_device *); 294static void pcnet32_watchdog(struct net_device *);
404static int mdio_read(struct net_device *dev, int phy_id, int reg_num); 295static int mdio_read(struct net_device *dev, int phy_id, int reg_num);
405static void mdio_write(struct net_device *dev, int phy_id, int reg_num, int val); 296static void mdio_write(struct net_device *dev, int phy_id, int reg_num,
297 int val);
406static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits); 298static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits);
407static void pcnet32_ethtool_test(struct net_device *dev, 299static void pcnet32_ethtool_test(struct net_device *dev,
408 struct ethtool_test *eth_test, u64 *data); 300 struct ethtool_test *eth_test, u64 * data);
409static int pcnet32_loopback_test(struct net_device *dev, uint64_t *data1); 301static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1);
410static int pcnet32_phys_id(struct net_device *dev, u32 data); 302static int pcnet32_phys_id(struct net_device *dev, u32 data);
411static void pcnet32_led_blink_callback(struct net_device *dev); 303static void pcnet32_led_blink_callback(struct net_device *dev);
412static int pcnet32_get_regs_len(struct net_device *dev); 304static int pcnet32_get_regs_len(struct net_device *dev);
413static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs, 305static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
414 void *ptr); 306 void *ptr);
415static void pcnet32_purge_tx_ring(struct net_device *dev); 307static void pcnet32_purge_tx_ring(struct net_device *dev);
416static int pcnet32_alloc_ring(struct net_device *dev, char *name); 308static int pcnet32_alloc_ring(struct net_device *dev, char *name);
417static void pcnet32_free_ring(struct net_device *dev); 309static void pcnet32_free_ring(struct net_device *dev);
418 310static void pcnet32_check_media(struct net_device *dev, int verbose);
419 311
420enum pci_flags_bit { 312enum pci_flags_bit {
421 PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4, 313 PCI_USES_IO = 1, PCI_USES_MEM = 2, PCI_USES_MASTER = 4,
422 PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3, 314 PCI_ADDR0 = 0x10 << 0, PCI_ADDR1 = 0x10 << 1, PCI_ADDR2 =
315 0x10 << 2, PCI_ADDR3 = 0x10 << 3,
423}; 316};
424 317
425 318static u16 pcnet32_wio_read_csr(unsigned long addr, int index)
426static u16 pcnet32_wio_read_csr (unsigned long addr, int index)
427{ 319{
428 outw (index, addr+PCNET32_WIO_RAP); 320 outw(index, addr + PCNET32_WIO_RAP);
429 return inw (addr+PCNET32_WIO_RDP); 321 return inw(addr + PCNET32_WIO_RDP);
430} 322}
431 323
432static void pcnet32_wio_write_csr (unsigned long addr, int index, u16 val) 324static void pcnet32_wio_write_csr(unsigned long addr, int index, u16 val)
433{ 325{
434 outw (index, addr+PCNET32_WIO_RAP); 326 outw(index, addr + PCNET32_WIO_RAP);
435 outw (val, addr+PCNET32_WIO_RDP); 327 outw(val, addr + PCNET32_WIO_RDP);
436} 328}
437 329
438static u16 pcnet32_wio_read_bcr (unsigned long addr, int index) 330static u16 pcnet32_wio_read_bcr(unsigned long addr, int index)
439{ 331{
440 outw (index, addr+PCNET32_WIO_RAP); 332 outw(index, addr + PCNET32_WIO_RAP);
441 return inw (addr+PCNET32_WIO_BDP); 333 return inw(addr + PCNET32_WIO_BDP);
442} 334}
443 335
444static void pcnet32_wio_write_bcr (unsigned long addr, int index, u16 val) 336static void pcnet32_wio_write_bcr(unsigned long addr, int index, u16 val)
445{ 337{
446 outw (index, addr+PCNET32_WIO_RAP); 338 outw(index, addr + PCNET32_WIO_RAP);
447 outw (val, addr+PCNET32_WIO_BDP); 339 outw(val, addr + PCNET32_WIO_BDP);
448} 340}
449 341
450static u16 pcnet32_wio_read_rap (unsigned long addr) 342static u16 pcnet32_wio_read_rap(unsigned long addr)
451{ 343{
452 return inw (addr+PCNET32_WIO_RAP); 344 return inw(addr + PCNET32_WIO_RAP);
453} 345}
454 346
455static void pcnet32_wio_write_rap (unsigned long addr, u16 val) 347static void pcnet32_wio_write_rap(unsigned long addr, u16 val)
456{ 348{
457 outw (val, addr+PCNET32_WIO_RAP); 349 outw(val, addr + PCNET32_WIO_RAP);
458} 350}
459 351
460static void pcnet32_wio_reset (unsigned long addr) 352static void pcnet32_wio_reset(unsigned long addr)
461{ 353{
462 inw (addr+PCNET32_WIO_RESET); 354 inw(addr + PCNET32_WIO_RESET);
463} 355}
464 356
465static int pcnet32_wio_check (unsigned long addr) 357static int pcnet32_wio_check(unsigned long addr)
466{ 358{
467 outw (88, addr+PCNET32_WIO_RAP); 359 outw(88, addr + PCNET32_WIO_RAP);
468 return (inw (addr+PCNET32_WIO_RAP) == 88); 360 return (inw(addr + PCNET32_WIO_RAP) == 88);
469} 361}
470 362
471static struct pcnet32_access pcnet32_wio = { 363static struct pcnet32_access pcnet32_wio = {
472 .read_csr = pcnet32_wio_read_csr, 364 .read_csr = pcnet32_wio_read_csr,
473 .write_csr = pcnet32_wio_write_csr, 365 .write_csr = pcnet32_wio_write_csr,
474 .read_bcr = pcnet32_wio_read_bcr, 366 .read_bcr = pcnet32_wio_read_bcr,
475 .write_bcr = pcnet32_wio_write_bcr, 367 .write_bcr = pcnet32_wio_write_bcr,
476 .read_rap = pcnet32_wio_read_rap, 368 .read_rap = pcnet32_wio_read_rap,
477 .write_rap = pcnet32_wio_write_rap, 369 .write_rap = pcnet32_wio_write_rap,
478 .reset = pcnet32_wio_reset 370 .reset = pcnet32_wio_reset
479}; 371};
480 372
481static u16 pcnet32_dwio_read_csr (unsigned long addr, int index) 373static u16 pcnet32_dwio_read_csr(unsigned long addr, int index)
482{ 374{
483 outl (index, addr+PCNET32_DWIO_RAP); 375 outl(index, addr + PCNET32_DWIO_RAP);
484 return (inl (addr+PCNET32_DWIO_RDP) & 0xffff); 376 return (inl(addr + PCNET32_DWIO_RDP) & 0xffff);
485} 377}
486 378
487static void pcnet32_dwio_write_csr (unsigned long addr, int index, u16 val) 379static void pcnet32_dwio_write_csr(unsigned long addr, int index, u16 val)
488{ 380{
489 outl (index, addr+PCNET32_DWIO_RAP); 381 outl(index, addr + PCNET32_DWIO_RAP);
490 outl (val, addr+PCNET32_DWIO_RDP); 382 outl(val, addr + PCNET32_DWIO_RDP);
491} 383}
492 384
493static u16 pcnet32_dwio_read_bcr (unsigned long addr, int index) 385static u16 pcnet32_dwio_read_bcr(unsigned long addr, int index)
494{ 386{
495 outl (index, addr+PCNET32_DWIO_RAP); 387 outl(index, addr + PCNET32_DWIO_RAP);
496 return (inl (addr+PCNET32_DWIO_BDP) & 0xffff); 388 return (inl(addr + PCNET32_DWIO_BDP) & 0xffff);
497} 389}
498 390
499static void pcnet32_dwio_write_bcr (unsigned long addr, int index, u16 val) 391static void pcnet32_dwio_write_bcr(unsigned long addr, int index, u16 val)
500{ 392{
501 outl (index, addr+PCNET32_DWIO_RAP); 393 outl(index, addr + PCNET32_DWIO_RAP);
502 outl (val, addr+PCNET32_DWIO_BDP); 394 outl(val, addr + PCNET32_DWIO_BDP);
503} 395}
504 396
505static u16 pcnet32_dwio_read_rap (unsigned long addr) 397static u16 pcnet32_dwio_read_rap(unsigned long addr)
506{ 398{
507 return (inl (addr+PCNET32_DWIO_RAP) & 0xffff); 399 return (inl(addr + PCNET32_DWIO_RAP) & 0xffff);
508} 400}
509 401
510static void pcnet32_dwio_write_rap (unsigned long addr, u16 val) 402static void pcnet32_dwio_write_rap(unsigned long addr, u16 val)
511{ 403{
512 outl (val, addr+PCNET32_DWIO_RAP); 404 outl(val, addr + PCNET32_DWIO_RAP);
513} 405}
514 406
515static void pcnet32_dwio_reset (unsigned long addr) 407static void pcnet32_dwio_reset(unsigned long addr)
516{ 408{
517 inl (addr+PCNET32_DWIO_RESET); 409 inl(addr + PCNET32_DWIO_RESET);
518} 410}
519 411
520static int pcnet32_dwio_check (unsigned long addr) 412static int pcnet32_dwio_check(unsigned long addr)
521{ 413{
522 outl (88, addr+PCNET32_DWIO_RAP); 414 outl(88, addr + PCNET32_DWIO_RAP);
523 return ((inl (addr+PCNET32_DWIO_RAP) & 0xffff) == 88); 415 return ((inl(addr + PCNET32_DWIO_RAP) & 0xffff) == 88);
524} 416}
525 417
526static struct pcnet32_access pcnet32_dwio = { 418static struct pcnet32_access pcnet32_dwio = {
527 .read_csr = pcnet32_dwio_read_csr, 419 .read_csr = pcnet32_dwio_read_csr,
528 .write_csr = pcnet32_dwio_write_csr, 420 .write_csr = pcnet32_dwio_write_csr,
529 .read_bcr = pcnet32_dwio_read_bcr, 421 .read_bcr = pcnet32_dwio_read_bcr,
530 .write_bcr = pcnet32_dwio_write_bcr, 422 .write_bcr = pcnet32_dwio_write_bcr,
531 .read_rap = pcnet32_dwio_read_rap, 423 .read_rap = pcnet32_dwio_read_rap,
532 .write_rap = pcnet32_dwio_write_rap, 424 .write_rap = pcnet32_dwio_write_rap,
533 .reset = pcnet32_dwio_reset 425 .reset = pcnet32_dwio_reset
534}; 426};
535 427
536#ifdef CONFIG_NET_POLL_CONTROLLER 428#ifdef CONFIG_NET_POLL_CONTROLLER
537static void pcnet32_poll_controller(struct net_device *dev) 429static void pcnet32_poll_controller(struct net_device *dev)
538{ 430{
539 disable_irq(dev->irq); 431 disable_irq(dev->irq);
540 pcnet32_interrupt(0, dev, NULL); 432 pcnet32_interrupt(0, dev, NULL);
541 enable_irq(dev->irq); 433 enable_irq(dev->irq);
542} 434}
543#endif 435#endif
544 436
545
546static int pcnet32_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 437static int pcnet32_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
547{ 438{
548 struct pcnet32_private *lp = dev->priv; 439 struct pcnet32_private *lp = dev->priv;
549 unsigned long flags; 440 unsigned long flags;
550 int r = -EOPNOTSUPP; 441 int r = -EOPNOTSUPP;
551 442
552 if (lp->mii) { 443 if (lp->mii) {
553 spin_lock_irqsave(&lp->lock, flags); 444 spin_lock_irqsave(&lp->lock, flags);
554 mii_ethtool_gset(&lp->mii_if, cmd); 445 mii_ethtool_gset(&lp->mii_if, cmd);
555 spin_unlock_irqrestore(&lp->lock, flags); 446 spin_unlock_irqrestore(&lp->lock, flags);
556 r = 0; 447 r = 0;
557 } 448 }
558 return r; 449 return r;
559} 450}
560 451
561static int pcnet32_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 452static int pcnet32_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
562{ 453{
563 struct pcnet32_private *lp = dev->priv; 454 struct pcnet32_private *lp = dev->priv;
564 unsigned long flags; 455 unsigned long flags;
565 int r = -EOPNOTSUPP; 456 int r = -EOPNOTSUPP;
566 457
567 if (lp->mii) { 458 if (lp->mii) {
568 spin_lock_irqsave(&lp->lock, flags); 459 spin_lock_irqsave(&lp->lock, flags);
569 r = mii_ethtool_sset(&lp->mii_if, cmd); 460 r = mii_ethtool_sset(&lp->mii_if, cmd);
570 spin_unlock_irqrestore(&lp->lock, flags); 461 spin_unlock_irqrestore(&lp->lock, flags);
571 } 462 }
572 return r; 463 return r;
573} 464}
574 465
575static void pcnet32_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) 466static void pcnet32_get_drvinfo(struct net_device *dev,
467 struct ethtool_drvinfo *info)
576{ 468{
577 struct pcnet32_private *lp = dev->priv; 469 struct pcnet32_private *lp = dev->priv;
578 470
579 strcpy (info->driver, DRV_NAME); 471 strcpy(info->driver, DRV_NAME);
580 strcpy (info->version, DRV_VERSION); 472 strcpy(info->version, DRV_VERSION);
581 if (lp->pci_dev) 473 if (lp->pci_dev)
582 strcpy (info->bus_info, pci_name(lp->pci_dev)); 474 strcpy(info->bus_info, pci_name(lp->pci_dev));
583 else 475 else
584 sprintf(info->bus_info, "VLB 0x%lx", dev->base_addr); 476 sprintf(info->bus_info, "VLB 0x%lx", dev->base_addr);
585} 477}
586 478
587static u32 pcnet32_get_link(struct net_device *dev) 479static u32 pcnet32_get_link(struct net_device *dev)
588{ 480{
589 struct pcnet32_private *lp = dev->priv; 481 struct pcnet32_private *lp = dev->priv;
590 unsigned long flags; 482 unsigned long flags;
591 int r; 483 int r;
592
593 spin_lock_irqsave(&lp->lock, flags);
594 if (lp->mii) {
595 r = mii_link_ok(&lp->mii_if);
596 } else {
597 ulong ioaddr = dev->base_addr; /* card base I/O address */
598 r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
599 }
600 spin_unlock_irqrestore(&lp->lock, flags);
601 484
602 return r; 485 spin_lock_irqsave(&lp->lock, flags);
486 if (lp->mii) {
487 r = mii_link_ok(&lp->mii_if);
488 } else {
489 ulong ioaddr = dev->base_addr; /* card base I/O address */
490 r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
491 }
492 spin_unlock_irqrestore(&lp->lock, flags);
493
494 return r;
603} 495}
604 496
605static u32 pcnet32_get_msglevel(struct net_device *dev) 497static u32 pcnet32_get_msglevel(struct net_device *dev)
606{ 498{
607 struct pcnet32_private *lp = dev->priv; 499 struct pcnet32_private *lp = dev->priv;
608 return lp->msg_enable; 500 return lp->msg_enable;
609} 501}
610 502
611static void pcnet32_set_msglevel(struct net_device *dev, u32 value) 503static void pcnet32_set_msglevel(struct net_device *dev, u32 value)
612{ 504{
613 struct pcnet32_private *lp = dev->priv; 505 struct pcnet32_private *lp = dev->priv;
614 lp->msg_enable = value; 506 lp->msg_enable = value;
615} 507}
616 508
617static int pcnet32_nway_reset(struct net_device *dev) 509static int pcnet32_nway_reset(struct net_device *dev)
618{ 510{
619 struct pcnet32_private *lp = dev->priv; 511 struct pcnet32_private *lp = dev->priv;
620 unsigned long flags; 512 unsigned long flags;
621 int r = -EOPNOTSUPP; 513 int r = -EOPNOTSUPP;
622 514
623 if (lp->mii) { 515 if (lp->mii) {
624 spin_lock_irqsave(&lp->lock, flags); 516 spin_lock_irqsave(&lp->lock, flags);
625 r = mii_nway_restart(&lp->mii_if); 517 r = mii_nway_restart(&lp->mii_if);
626 spin_unlock_irqrestore(&lp->lock, flags); 518 spin_unlock_irqrestore(&lp->lock, flags);
627 } 519 }
628 return r; 520 return r;
629} 521}
630 522
631static void pcnet32_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) 523static void pcnet32_get_ringparam(struct net_device *dev,
524 struct ethtool_ringparam *ering)
632{ 525{
633 struct pcnet32_private *lp = dev->priv; 526 struct pcnet32_private *lp = dev->priv;
634 527
635 ering->tx_max_pending = TX_MAX_RING_SIZE - 1; 528 ering->tx_max_pending = TX_MAX_RING_SIZE - 1;
636 ering->tx_pending = lp->tx_ring_size - 1; 529 ering->tx_pending = lp->tx_ring_size - 1;
637 ering->rx_max_pending = RX_MAX_RING_SIZE - 1; 530 ering->rx_max_pending = RX_MAX_RING_SIZE - 1;
638 ering->rx_pending = lp->rx_ring_size - 1; 531 ering->rx_pending = lp->rx_ring_size - 1;
639} 532}
640 533
641static int pcnet32_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) 534static int pcnet32_set_ringparam(struct net_device *dev,
535 struct ethtool_ringparam *ering)
642{ 536{
643 struct pcnet32_private *lp = dev->priv; 537 struct pcnet32_private *lp = dev->priv;
644 unsigned long flags; 538 unsigned long flags;
645 int i; 539 int i;
646 540
647 if (ering->rx_mini_pending || ering->rx_jumbo_pending) 541 if (ering->rx_mini_pending || ering->rx_jumbo_pending)
648 return -EINVAL; 542 return -EINVAL;
649 543
650 if (netif_running(dev)) 544 if (netif_running(dev))
651 pcnet32_close(dev); 545 pcnet32_close(dev);
652 546
653 spin_lock_irqsave(&lp->lock, flags); 547 spin_lock_irqsave(&lp->lock, flags);
654 pcnet32_free_ring(dev);
655 lp->tx_ring_size = min(ering->tx_pending, (unsigned int) TX_MAX_RING_SIZE);
656 lp->rx_ring_size = min(ering->rx_pending, (unsigned int) RX_MAX_RING_SIZE);
657
658 /* set the minimum ring size to 4, to allow the loopback test to work
659 * unchanged.
660 */
661 for (i = 2; i <= PCNET32_LOG_MAX_TX_BUFFERS; i++) {
662 if (lp->tx_ring_size <= (1 << i))
663 break;
664 }
665 lp->tx_ring_size = (1 << i);
666 lp->tx_mod_mask = lp->tx_ring_size - 1;
667 lp->tx_len_bits = (i << 12);
668
669 for (i = 2; i <= PCNET32_LOG_MAX_RX_BUFFERS; i++) {
670 if (lp->rx_ring_size <= (1 << i))
671 break;
672 }
673 lp->rx_ring_size = (1 << i);
674 lp->rx_mod_mask = lp->rx_ring_size - 1;
675 lp->rx_len_bits = (i << 4);
676
677 if (pcnet32_alloc_ring(dev, dev->name)) {
678 pcnet32_free_ring(dev); 548 pcnet32_free_ring(dev);
679 spin_unlock_irqrestore(&lp->lock, flags); 549 lp->tx_ring_size =
680 return -ENOMEM; 550 min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
681 } 551 lp->rx_ring_size =
552 min(ering->rx_pending, (unsigned int)RX_MAX_RING_SIZE);
553
554 /* set the minimum ring size to 4, to allow the loopback test to work
555 * unchanged.
556 */
557 for (i = 2; i <= PCNET32_LOG_MAX_TX_BUFFERS; i++) {
558 if (lp->tx_ring_size <= (1 << i))
559 break;
560 }
561 lp->tx_ring_size = (1 << i);
562 lp->tx_mod_mask = lp->tx_ring_size - 1;
563 lp->tx_len_bits = (i << 12);
682 564
683 spin_unlock_irqrestore(&lp->lock, flags); 565 for (i = 2; i <= PCNET32_LOG_MAX_RX_BUFFERS; i++) {
566 if (lp->rx_ring_size <= (1 << i))
567 break;
568 }
569 lp->rx_ring_size = (1 << i);
570 lp->rx_mod_mask = lp->rx_ring_size - 1;
571 lp->rx_len_bits = (i << 4);
572
573 if (pcnet32_alloc_ring(dev, dev->name)) {
574 pcnet32_free_ring(dev);
575 spin_unlock_irqrestore(&lp->lock, flags);
576 return -ENOMEM;
577 }
684 578
685 if (pcnet32_debug & NETIF_MSG_DRV) 579 spin_unlock_irqrestore(&lp->lock, flags);
686 printk(KERN_INFO PFX "%s: Ring Param Settings: RX: %d, TX: %d\n",
687 dev->name, lp->rx_ring_size, lp->tx_ring_size);
688 580
689 if (netif_running(dev)) 581 if (pcnet32_debug & NETIF_MSG_DRV)
690 pcnet32_open(dev); 582 printk(KERN_INFO PFX
583 "%s: Ring Param Settings: RX: %d, TX: %d\n", dev->name,
584 lp->rx_ring_size, lp->tx_ring_size);
691 585
692 return 0; 586 if (netif_running(dev))
587 pcnet32_open(dev);
588
589 return 0;
693} 590}
694 591
695static void pcnet32_get_strings(struct net_device *dev, u32 stringset, u8 *data) 592static void pcnet32_get_strings(struct net_device *dev, u32 stringset,
593 u8 * data)
696{ 594{
697 memcpy(data, pcnet32_gstrings_test, sizeof(pcnet32_gstrings_test)); 595 memcpy(data, pcnet32_gstrings_test, sizeof(pcnet32_gstrings_test));
698} 596}
699 597
700static int pcnet32_self_test_count(struct net_device *dev) 598static int pcnet32_self_test_count(struct net_device *dev)
701{ 599{
702 return PCNET32_TEST_LEN; 600 return PCNET32_TEST_LEN;
703} 601}
704 602
705static void pcnet32_ethtool_test(struct net_device *dev, 603static void pcnet32_ethtool_test(struct net_device *dev,
706 struct ethtool_test *test, u64 *data) 604 struct ethtool_test *test, u64 * data)
707{ 605{
708 struct pcnet32_private *lp = dev->priv; 606 struct pcnet32_private *lp = dev->priv;
709 int rc; 607 int rc;
710 608
711 if (test->flags == ETH_TEST_FL_OFFLINE) { 609 if (test->flags == ETH_TEST_FL_OFFLINE) {
712 rc = pcnet32_loopback_test(dev, data); 610 rc = pcnet32_loopback_test(dev, data);
713 if (rc) { 611 if (rc) {
714 if (netif_msg_hw(lp)) 612 if (netif_msg_hw(lp))
715 printk(KERN_DEBUG "%s: Loopback test failed.\n", dev->name); 613 printk(KERN_DEBUG "%s: Loopback test failed.\n",
716 test->flags |= ETH_TEST_FL_FAILED; 614 dev->name);
615 test->flags |= ETH_TEST_FL_FAILED;
616 } else if (netif_msg_hw(lp))
617 printk(KERN_DEBUG "%s: Loopback test passed.\n",
618 dev->name);
717 } else if (netif_msg_hw(lp)) 619 } else if (netif_msg_hw(lp))
718 printk(KERN_DEBUG "%s: Loopback test passed.\n", dev->name); 620 printk(KERN_DEBUG
719 } else if (netif_msg_hw(lp)) 621 "%s: No tests to run (specify 'Offline' on ethtool).",
720 printk(KERN_DEBUG "%s: No tests to run (specify 'Offline' on ethtool).", dev->name); 622 dev->name);
721} /* end pcnet32_ethtool_test */ 623} /* end pcnet32_ethtool_test */
722 624
723static int pcnet32_loopback_test(struct net_device *dev, uint64_t *data1) 625static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
724{ 626{
725 struct pcnet32_private *lp = dev->priv; 627 struct pcnet32_private *lp = dev->priv;
726 struct pcnet32_access *a = &lp->a; /* access to registers */ 628 struct pcnet32_access *a = &lp->a; /* access to registers */
727 ulong ioaddr = dev->base_addr; /* card base I/O address */ 629 ulong ioaddr = dev->base_addr; /* card base I/O address */
728 struct sk_buff *skb; /* sk buff */ 630 struct sk_buff *skb; /* sk buff */
729 int x, i; /* counters */ 631 int x, i; /* counters */
730 int numbuffs = 4; /* number of TX/RX buffers and descs */ 632 int numbuffs = 4; /* number of TX/RX buffers and descs */
731 u16 status = 0x8300; /* TX ring status */ 633 u16 status = 0x8300; /* TX ring status */
732 u16 teststatus; /* test of ring status */ 634 u16 teststatus; /* test of ring status */
733 int rc; /* return code */ 635 int rc; /* return code */
734 int size; /* size of packets */ 636 int size; /* size of packets */
735 unsigned char *packet; /* source packet data */ 637 unsigned char *packet; /* source packet data */
736 static const int data_len = 60; /* length of source packets */ 638 static const int data_len = 60; /* length of source packets */
737 unsigned long flags; 639 unsigned long flags;
738 unsigned long ticks; 640 unsigned long ticks;
739 641
740 *data1 = 1; /* status of test, default to fail */ 642 *data1 = 1; /* status of test, default to fail */
741 rc = 1; /* default to fail */ 643 rc = 1; /* default to fail */
742 644
743 if (netif_running(dev)) 645 if (netif_running(dev))
744 pcnet32_close(dev); 646 pcnet32_close(dev);
745 647
746 spin_lock_irqsave(&lp->lock, flags); 648 spin_lock_irqsave(&lp->lock, flags);
747 649
748 /* Reset the PCNET32 */ 650 /* Reset the PCNET32 */
749 lp->a.reset (ioaddr); 651 lp->a.reset(ioaddr);
750 652
751 /* switch pcnet32 to 32bit mode */ 653 /* switch pcnet32 to 32bit mode */
752 lp->a.write_bcr (ioaddr, 20, 2); 654 lp->a.write_bcr(ioaddr, 20, 2);
753 655
754 lp->init_block.mode = le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7); 656 lp->init_block.mode =
755 lp->init_block.filter[0] = 0; 657 le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);
756 lp->init_block.filter[1] = 0; 658 lp->init_block.filter[0] = 0;
757 659 lp->init_block.filter[1] = 0;
758 /* purge & init rings but don't actually restart */ 660
759 pcnet32_restart(dev, 0x0000); 661 /* purge & init rings but don't actually restart */
760 662 pcnet32_restart(dev, 0x0000);
761 lp->a.write_csr(ioaddr, 0, 0x0004); /* Set STOP bit */ 663
762 664 lp->a.write_csr(ioaddr, 0, 0x0004); /* Set STOP bit */
763 /* Initialize Transmit buffers. */ 665
764 size = data_len + 15; 666 /* Initialize Transmit buffers. */
765 for (x=0; x<numbuffs; x++) { 667 size = data_len + 15;
766 if (!(skb = dev_alloc_skb(size))) { 668 for (x = 0; x < numbuffs; x++) {
767 if (netif_msg_hw(lp)) 669 if (!(skb = dev_alloc_skb(size))) {
768 printk(KERN_DEBUG "%s: Cannot allocate skb at line: %d!\n", 670 if (netif_msg_hw(lp))
769 dev->name, __LINE__); 671 printk(KERN_DEBUG
770 goto clean_up; 672 "%s: Cannot allocate skb at line: %d!\n",
771 } else { 673 dev->name, __LINE__);
772 packet = skb->data; 674 goto clean_up;
773 skb_put(skb, size); /* create space for data */ 675 } else {
774 lp->tx_skbuff[x] = skb; 676 packet = skb->data;
775 lp->tx_ring[x].length = le16_to_cpu(-skb->len); 677 skb_put(skb, size); /* create space for data */
776 lp->tx_ring[x].misc = 0; 678 lp->tx_skbuff[x] = skb;
777 679 lp->tx_ring[x].length = le16_to_cpu(-skb->len);
778 /* put DA and SA into the skb */ 680 lp->tx_ring[x].misc = 0;
779 for (i=0; i<6; i++) 681
780 *packet++ = dev->dev_addr[i]; 682 /* put DA and SA into the skb */
781 for (i=0; i<6; i++) 683 for (i = 0; i < 6; i++)
782 *packet++ = dev->dev_addr[i]; 684 *packet++ = dev->dev_addr[i];
783 /* type */ 685 for (i = 0; i < 6; i++)
784 *packet++ = 0x08; 686 *packet++ = dev->dev_addr[i];
785 *packet++ = 0x06; 687 /* type */
786 /* packet number */ 688 *packet++ = 0x08;
787 *packet++ = x; 689 *packet++ = 0x06;
788 /* fill packet with data */ 690 /* packet number */
789 for (i=0; i<data_len; i++) 691 *packet++ = x;
790 *packet++ = i; 692 /* fill packet with data */
791 693 for (i = 0; i < data_len; i++)
792 lp->tx_dma_addr[x] = pci_map_single(lp->pci_dev, skb->data, 694 *packet++ = i;
793 skb->len, PCI_DMA_TODEVICE); 695
794 lp->tx_ring[x].base = (u32)le32_to_cpu(lp->tx_dma_addr[x]); 696 lp->tx_dma_addr[x] =
795 wmb(); /* Make sure owner changes after all others are visible */ 697 pci_map_single(lp->pci_dev, skb->data, skb->len,
796 lp->tx_ring[x].status = le16_to_cpu(status); 698 PCI_DMA_TODEVICE);
797 } 699 lp->tx_ring[x].base =
798 } 700 (u32) le32_to_cpu(lp->tx_dma_addr[x]);
799 701 wmb(); /* Make sure owner changes after all others are visible */
800 x = a->read_bcr(ioaddr, 32); /* set internal loopback in BSR32 */ 702 lp->tx_ring[x].status = le16_to_cpu(status);
801 x = x | 0x0002; 703 }
802 a->write_bcr(ioaddr, 32, x); 704 }
803 705
804 lp->a.write_csr (ioaddr, 15, 0x0044); /* set int loopback in CSR15 */ 706 x = a->read_bcr(ioaddr, 32); /* set internal loopback in BSR32 */
805 707 x = x | 0x0002;
806 teststatus = le16_to_cpu(0x8000); 708 a->write_bcr(ioaddr, 32, x);
807 lp->a.write_csr(ioaddr, 0, 0x0002); /* Set STRT bit */ 709
808 710 lp->a.write_csr(ioaddr, 15, 0x0044); /* set int loopback in CSR15 */
809 /* Check status of descriptors */ 711
810 for (x=0; x<numbuffs; x++) { 712 teststatus = le16_to_cpu(0x8000);
811 ticks = 0; 713 lp->a.write_csr(ioaddr, 0, 0x0002); /* Set STRT bit */
812 rmb(); 714
813 while ((lp->rx_ring[x].status & teststatus) && (ticks < 200)) { 715 /* Check status of descriptors */
814 spin_unlock_irqrestore(&lp->lock, flags); 716 for (x = 0; x < numbuffs; x++) {
815 mdelay(1); 717 ticks = 0;
816 spin_lock_irqsave(&lp->lock, flags); 718 rmb();
817 rmb(); 719 while ((lp->rx_ring[x].status & teststatus) && (ticks < 200)) {
818 ticks++; 720 spin_unlock_irqrestore(&lp->lock, flags);
819 } 721 mdelay(1);
820 if (ticks == 200) { 722 spin_lock_irqsave(&lp->lock, flags);
821 if (netif_msg_hw(lp)) 723 rmb();
822 printk("%s: Desc %d failed to reset!\n",dev->name,x); 724 ticks++;
823 break; 725 }
824 } 726 if (ticks == 200) {
825 } 727 if (netif_msg_hw(lp))
826 728 printk("%s: Desc %d failed to reset!\n",
827 lp->a.write_csr(ioaddr, 0, 0x0004); /* Set STOP bit */ 729 dev->name, x);
828 wmb(); 730 break;
829 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) { 731 }
830 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name); 732 }
831 733
832 for (x=0; x<numbuffs; x++) { 734 lp->a.write_csr(ioaddr, 0, 0x0004); /* Set STOP bit */
833 printk(KERN_DEBUG "%s: Packet %d:\n", dev->name, x); 735 wmb();
834 skb = lp->rx_skbuff[x]; 736 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
835 for (i=0; i<size; i++) { 737 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name);
836 printk("%02x ", *(skb->data+i)); 738
837 } 739 for (x = 0; x < numbuffs; x++) {
838 printk("\n"); 740 printk(KERN_DEBUG "%s: Packet %d:\n", dev->name, x);
839 } 741 skb = lp->rx_skbuff[x];
840 } 742 for (i = 0; i < size; i++) {
841 743 printk("%02x ", *(skb->data + i));
842 x = 0; 744 }
843 rc = 0; 745 printk("\n");
844 while (x<numbuffs && !rc) { 746 }
845 skb = lp->rx_skbuff[x]; 747 }
846 packet = lp->tx_skbuff[x]->data; 748
847 for (i=0; i<size; i++) { 749 x = 0;
848 if (*(skb->data+i) != packet[i]) { 750 rc = 0;
849 if (netif_msg_hw(lp)) 751 while (x < numbuffs && !rc) {
850 printk(KERN_DEBUG "%s: Error in compare! %2x - %02x %02x\n", 752 skb = lp->rx_skbuff[x];
851 dev->name, i, *(skb->data+i), packet[i]); 753 packet = lp->tx_skbuff[x]->data;
852 rc = 1; 754 for (i = 0; i < size; i++) {
853 break; 755 if (*(skb->data + i) != packet[i]) {
854 } 756 if (netif_msg_hw(lp))
757 printk(KERN_DEBUG
758 "%s: Error in compare! %2x - %02x %02x\n",
759 dev->name, i, *(skb->data + i),
760 packet[i]);
761 rc = 1;
762 break;
763 }
764 }
765 x++;
766 }
767 if (!rc) {
768 *data1 = 0;
855 } 769 }
856 x++;
857 }
858 if (!rc) {
859 *data1 = 0;
860 }
861 770
862clean_up: 771 clean_up:
863 pcnet32_purge_tx_ring(dev); 772 pcnet32_purge_tx_ring(dev);
864 x = a->read_csr(ioaddr, 15) & 0xFFFF; 773 x = a->read_csr(ioaddr, 15) & 0xFFFF;
865 a->write_csr(ioaddr, 15, (x & ~0x0044)); /* reset bits 6 and 2 */ 774 a->write_csr(ioaddr, 15, (x & ~0x0044)); /* reset bits 6 and 2 */
866 775
867 x = a->read_bcr(ioaddr, 32); /* reset internal loopback */ 776 x = a->read_bcr(ioaddr, 32); /* reset internal loopback */
868 x = x & ~0x0002; 777 x = x & ~0x0002;
869 a->write_bcr(ioaddr, 32, x); 778 a->write_bcr(ioaddr, 32, x);
870 779
871 spin_unlock_irqrestore(&lp->lock, flags); 780 spin_unlock_irqrestore(&lp->lock, flags);
872 781
873 if (netif_running(dev)) { 782 if (netif_running(dev)) {
874 pcnet32_open(dev); 783 pcnet32_open(dev);
875 } else { 784 } else {
876 lp->a.write_bcr (ioaddr, 20, 4); /* return to 16bit mode */ 785 lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
877 } 786 }
878 787
879 return(rc); 788 return (rc);
880} /* end pcnet32_loopback_test */ 789} /* end pcnet32_loopback_test */
881 790
882static void pcnet32_led_blink_callback(struct net_device *dev) 791static void pcnet32_led_blink_callback(struct net_device *dev)
883{ 792{
884 struct pcnet32_private *lp = dev->priv; 793 struct pcnet32_private *lp = dev->priv;
885 struct pcnet32_access *a = &lp->a; 794 struct pcnet32_access *a = &lp->a;
886 ulong ioaddr = dev->base_addr; 795 ulong ioaddr = dev->base_addr;
887 unsigned long flags; 796 unsigned long flags;
888 int i; 797 int i;
889 798
890 spin_lock_irqsave(&lp->lock, flags); 799 spin_lock_irqsave(&lp->lock, flags);
891 for (i=4; i<8; i++) { 800 for (i = 4; i < 8; i++) {
892 a->write_bcr(ioaddr, i, a->read_bcr(ioaddr, i) ^ 0x4000); 801 a->write_bcr(ioaddr, i, a->read_bcr(ioaddr, i) ^ 0x4000);
893 } 802 }
894 spin_unlock_irqrestore(&lp->lock, flags); 803 spin_unlock_irqrestore(&lp->lock, flags);
895 804
896 mod_timer(&lp->blink_timer, PCNET32_BLINK_TIMEOUT); 805 mod_timer(&lp->blink_timer, PCNET32_BLINK_TIMEOUT);
897} 806}
898 807
899static int pcnet32_phys_id(struct net_device *dev, u32 data) 808static int pcnet32_phys_id(struct net_device *dev, u32 data)
900{ 809{
901 struct pcnet32_private *lp = dev->priv; 810 struct pcnet32_private *lp = dev->priv;
902 struct pcnet32_access *a = &lp->a; 811 struct pcnet32_access *a = &lp->a;
903 ulong ioaddr = dev->base_addr; 812 ulong ioaddr = dev->base_addr;
904 unsigned long flags; 813 unsigned long flags;
905 int i, regs[4]; 814 int i, regs[4];
906 815
907 if (!lp->blink_timer.function) { 816 if (!lp->blink_timer.function) {
908 init_timer(&lp->blink_timer); 817 init_timer(&lp->blink_timer);
909 lp->blink_timer.function = (void *) pcnet32_led_blink_callback; 818 lp->blink_timer.function = (void *)pcnet32_led_blink_callback;
910 lp->blink_timer.data = (unsigned long) dev; 819 lp->blink_timer.data = (unsigned long)dev;
911 } 820 }
912 821
913 /* Save the current value of the bcrs */ 822 /* Save the current value of the bcrs */
914 spin_lock_irqsave(&lp->lock, flags); 823 spin_lock_irqsave(&lp->lock, flags);
915 for (i=4; i<8; i++) { 824 for (i = 4; i < 8; i++) {
916 regs[i-4] = a->read_bcr(ioaddr, i); 825 regs[i - 4] = a->read_bcr(ioaddr, i);
917 } 826 }
918 spin_unlock_irqrestore(&lp->lock, flags); 827 spin_unlock_irqrestore(&lp->lock, flags);
919 828
920 mod_timer(&lp->blink_timer, jiffies); 829 mod_timer(&lp->blink_timer, jiffies);
921 set_current_state(TASK_INTERRUPTIBLE); 830 set_current_state(TASK_INTERRUPTIBLE);
922 831
923 if ((!data) || (data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ))) 832 if ((!data) || (data > (u32) (MAX_SCHEDULE_TIMEOUT / HZ)))
924 data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ); 833 data = (u32) (MAX_SCHEDULE_TIMEOUT / HZ);
925 834
926 msleep_interruptible(data * 1000); 835 msleep_interruptible(data * 1000);
927 del_timer_sync(&lp->blink_timer); 836 del_timer_sync(&lp->blink_timer);
928 837
929 /* Restore the original value of the bcrs */ 838 /* Restore the original value of the bcrs */
930 spin_lock_irqsave(&lp->lock, flags); 839 spin_lock_irqsave(&lp->lock, flags);
931 for (i=4; i<8; i++) { 840 for (i = 4; i < 8; i++) {
932 a->write_bcr(ioaddr, i, regs[i-4]); 841 a->write_bcr(ioaddr, i, regs[i - 4]);
933 } 842 }
934 spin_unlock_irqrestore(&lp->lock, flags); 843 spin_unlock_irqrestore(&lp->lock, flags);
935 844
936 return 0; 845 return 0;
937} 846}
938 847
848#define PCNET32_REGS_PER_PHY 32
849#define PCNET32_MAX_PHYS 32
939static int pcnet32_get_regs_len(struct net_device *dev) 850static int pcnet32_get_regs_len(struct net_device *dev)
940{ 851{
941 return(PCNET32_NUM_REGS * sizeof(u16)); 852 struct pcnet32_private *lp = dev->priv;
853 int j = lp->phycount * PCNET32_REGS_PER_PHY;
854
855 return ((PCNET32_NUM_REGS + j) * sizeof(u16));
942} 856}
943 857
944static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs, 858static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
945 void *ptr) 859 void *ptr)
946{ 860{
947 int i, csr0; 861 int i, csr0;
948 u16 *buff = ptr; 862 u16 *buff = ptr;
949 struct pcnet32_private *lp = dev->priv; 863 struct pcnet32_private *lp = dev->priv;
950 struct pcnet32_access *a = &lp->a; 864 struct pcnet32_access *a = &lp->a;
951 ulong ioaddr = dev->base_addr; 865 ulong ioaddr = dev->base_addr;
952 int ticks; 866 int ticks;
953 unsigned long flags; 867 unsigned long flags;
954
955 spin_lock_irqsave(&lp->lock, flags);
956
957 csr0 = a->read_csr(ioaddr, 0);
958 if (!(csr0 & 0x0004)) { /* If not stopped */
959 /* set SUSPEND (SPND) - CSR5 bit 0 */
960 a->write_csr(ioaddr, 5, 0x0001);
961
962 /* poll waiting for bit to be set */
963 ticks = 0;
964 while (!(a->read_csr(ioaddr, 5) & 0x0001)) {
965 spin_unlock_irqrestore(&lp->lock, flags);
966 mdelay(1);
967 spin_lock_irqsave(&lp->lock, flags);
968 ticks++;
969 if (ticks > 200) {
970 if (netif_msg_hw(lp))
971 printk(KERN_DEBUG "%s: Error getting into suspend!\n",
972 dev->name);
973 break;
974 }
975 }
976 }
977 868
978 /* read address PROM */ 869 spin_lock_irqsave(&lp->lock, flags);
979 for (i=0; i<16; i += 2)
980 *buff++ = inw(ioaddr + i);
981 870
982 /* read control and status registers */ 871 csr0 = a->read_csr(ioaddr, 0);
983 for (i=0; i<90; i++) { 872 if (!(csr0 & 0x0004)) { /* If not stopped */
984 *buff++ = a->read_csr(ioaddr, i); 873 /* set SUSPEND (SPND) - CSR5 bit 0 */
985 } 874 a->write_csr(ioaddr, 5, 0x0001);
875
876 /* poll waiting for bit to be set */
877 ticks = 0;
878 while (!(a->read_csr(ioaddr, 5) & 0x0001)) {
879 spin_unlock_irqrestore(&lp->lock, flags);
880 mdelay(1);
881 spin_lock_irqsave(&lp->lock, flags);
882 ticks++;
883 if (ticks > 200) {
884 if (netif_msg_hw(lp))
885 printk(KERN_DEBUG
886 "%s: Error getting into suspend!\n",
887 dev->name);
888 break;
889 }
890 }
891 }
986 892
987 *buff++ = a->read_csr(ioaddr, 112); 893 /* read address PROM */
988 *buff++ = a->read_csr(ioaddr, 114); 894 for (i = 0; i < 16; i += 2)
895 *buff++ = inw(ioaddr + i);
989 896
990 /* read bus configuration registers */ 897 /* read control and status registers */
991 for (i=0; i<30; i++) { 898 for (i = 0; i < 90; i++) {
992 *buff++ = a->read_bcr(ioaddr, i); 899 *buff++ = a->read_csr(ioaddr, i);
993 } 900 }
994 *buff++ = 0; /* skip bcr30 so as not to hang 79C976 */ 901
995 for (i=31; i<36; i++) { 902 *buff++ = a->read_csr(ioaddr, 112);
996 *buff++ = a->read_bcr(ioaddr, i); 903 *buff++ = a->read_csr(ioaddr, 114);
997 }
998 904
999 /* read mii phy registers */ 905 /* read bus configuration registers */
1000 if (lp->mii) { 906 for (i = 0; i < 30; i++) {
1001 for (i=0; i<32; i++) { 907 *buff++ = a->read_bcr(ioaddr, i);
1002 lp->a.write_bcr(ioaddr, 33, ((lp->mii_if.phy_id) << 5) | i); 908 }
1003 *buff++ = lp->a.read_bcr(ioaddr, 34); 909 *buff++ = 0; /* skip bcr30 so as not to hang 79C976 */
910 for (i = 31; i < 36; i++) {
911 *buff++ = a->read_bcr(ioaddr, i);
1004 } 912 }
1005 }
1006 913
1007 if (!(csr0 & 0x0004)) { /* If not stopped */ 914 /* read mii phy registers */
1008 /* clear SUSPEND (SPND) - CSR5 bit 0 */ 915 if (lp->mii) {
1009 a->write_csr(ioaddr, 5, 0x0000); 916 int j;
1010 } 917 for (j = 0; j < PCNET32_MAX_PHYS; j++) {
918 if (lp->phymask & (1 << j)) {
919 for (i = 0; i < PCNET32_REGS_PER_PHY; i++) {
920 lp->a.write_bcr(ioaddr, 33,
921 (j << 5) | i);
922 *buff++ = lp->a.read_bcr(ioaddr, 34);
923 }
924 }
925 }
926 }
1011 927
1012 i = buff - (u16 *)ptr; 928 if (!(csr0 & 0x0004)) { /* If not stopped */
1013 for (; i < PCNET32_NUM_REGS; i++) 929 /* clear SUSPEND (SPND) - CSR5 bit 0 */
1014 *buff++ = 0; 930 a->write_csr(ioaddr, 5, 0x0000);
931 }
1015 932
1016 spin_unlock_irqrestore(&lp->lock, flags); 933 spin_unlock_irqrestore(&lp->lock, flags);
1017} 934}
1018 935
1019static struct ethtool_ops pcnet32_ethtool_ops = { 936static struct ethtool_ops pcnet32_ethtool_ops = {
1020 .get_settings = pcnet32_get_settings, 937 .get_settings = pcnet32_get_settings,
1021 .set_settings = pcnet32_set_settings, 938 .set_settings = pcnet32_set_settings,
1022 .get_drvinfo = pcnet32_get_drvinfo, 939 .get_drvinfo = pcnet32_get_drvinfo,
1023 .get_msglevel = pcnet32_get_msglevel, 940 .get_msglevel = pcnet32_get_msglevel,
1024 .set_msglevel = pcnet32_set_msglevel, 941 .set_msglevel = pcnet32_set_msglevel,
1025 .nway_reset = pcnet32_nway_reset, 942 .nway_reset = pcnet32_nway_reset,
1026 .get_link = pcnet32_get_link, 943 .get_link = pcnet32_get_link,
1027 .get_ringparam = pcnet32_get_ringparam, 944 .get_ringparam = pcnet32_get_ringparam,
1028 .set_ringparam = pcnet32_set_ringparam, 945 .set_ringparam = pcnet32_set_ringparam,
1029 .get_tx_csum = ethtool_op_get_tx_csum, 946 .get_tx_csum = ethtool_op_get_tx_csum,
1030 .get_sg = ethtool_op_get_sg, 947 .get_sg = ethtool_op_get_sg,
1031 .get_tso = ethtool_op_get_tso, 948 .get_tso = ethtool_op_get_tso,
1032 .get_strings = pcnet32_get_strings, 949 .get_strings = pcnet32_get_strings,
1033 .self_test_count = pcnet32_self_test_count, 950 .self_test_count = pcnet32_self_test_count,
1034 .self_test = pcnet32_ethtool_test, 951 .self_test = pcnet32_ethtool_test,
1035 .phys_id = pcnet32_phys_id, 952 .phys_id = pcnet32_phys_id,
1036 .get_regs_len = pcnet32_get_regs_len, 953 .get_regs_len = pcnet32_get_regs_len,
1037 .get_regs = pcnet32_get_regs, 954 .get_regs = pcnet32_get_regs,
1038 .get_perm_addr = ethtool_op_get_perm_addr, 955 .get_perm_addr = ethtool_op_get_perm_addr,
1039}; 956};
1040 957
1041/* only probes for non-PCI devices, the rest are handled by 958/* only probes for non-PCI devices, the rest are handled by
1042 * pci_register_driver via pcnet32_probe_pci */ 959 * pci_register_driver via pcnet32_probe_pci */
1043 960
1044static void __devinit 961static void __devinit pcnet32_probe_vlbus(void)
1045pcnet32_probe_vlbus(void)
1046{ 962{
1047 unsigned int *port, ioaddr; 963 unsigned int *port, ioaddr;
1048 964
1049 /* search for PCnet32 VLB cards at known addresses */ 965 /* search for PCnet32 VLB cards at known addresses */
1050 for (port = pcnet32_portlist; (ioaddr = *port); port++) { 966 for (port = pcnet32_portlist; (ioaddr = *port); port++) {
1051 if (request_region(ioaddr, PCNET32_TOTAL_SIZE, "pcnet32_probe_vlbus")) { 967 if (request_region
1052 /* check if there is really a pcnet chip on that ioaddr */ 968 (ioaddr, PCNET32_TOTAL_SIZE, "pcnet32_probe_vlbus")) {
1053 if ((inb(ioaddr + 14) == 0x57) && (inb(ioaddr + 15) == 0x57)) { 969 /* check if there is really a pcnet chip on that ioaddr */
1054 pcnet32_probe1(ioaddr, 0, NULL); 970 if ((inb(ioaddr + 14) == 0x57)
1055 } else { 971 && (inb(ioaddr + 15) == 0x57)) {
1056 release_region(ioaddr, PCNET32_TOTAL_SIZE); 972 pcnet32_probe1(ioaddr, 0, NULL);
1057 } 973 } else {
1058 } 974 release_region(ioaddr, PCNET32_TOTAL_SIZE);
1059 } 975 }
976 }
977 }
1060} 978}
1061 979
1062
1063static int __devinit 980static int __devinit
1064pcnet32_probe_pci(struct pci_dev *pdev, const struct pci_device_id *ent) 981pcnet32_probe_pci(struct pci_dev *pdev, const struct pci_device_id *ent)
1065{ 982{
1066 unsigned long ioaddr; 983 unsigned long ioaddr;
1067 int err; 984 int err;
1068 985
1069 err = pci_enable_device(pdev); 986 err = pci_enable_device(pdev);
1070 if (err < 0) { 987 if (err < 0) {
1071 if (pcnet32_debug & NETIF_MSG_PROBE) 988 if (pcnet32_debug & NETIF_MSG_PROBE)
1072 printk(KERN_ERR PFX "failed to enable device -- err=%d\n", err); 989 printk(KERN_ERR PFX
1073 return err; 990 "failed to enable device -- err=%d\n", err);
1074 } 991 return err;
1075 pci_set_master(pdev); 992 }
993 pci_set_master(pdev);
994
995 ioaddr = pci_resource_start(pdev, 0);
996 if (!ioaddr) {
997 if (pcnet32_debug & NETIF_MSG_PROBE)
998 printk(KERN_ERR PFX
999 "card has no PCI IO resources, aborting\n");
1000 return -ENODEV;
1001 }
1076 1002
1077 ioaddr = pci_resource_start (pdev, 0); 1003 if (!pci_dma_supported(pdev, PCNET32_DMA_MASK)) {
1078 if (!ioaddr) { 1004 if (pcnet32_debug & NETIF_MSG_PROBE)
1079 if (pcnet32_debug & NETIF_MSG_PROBE) 1005 printk(KERN_ERR PFX
1080 printk (KERN_ERR PFX "card has no PCI IO resources, aborting\n"); 1006 "architecture does not support 32bit PCI busmaster DMA\n");
1081 return -ENODEV; 1007 return -ENODEV;
1082 } 1008 }
1009 if (request_region(ioaddr, PCNET32_TOTAL_SIZE, "pcnet32_probe_pci") ==
1010 NULL) {
1011 if (pcnet32_debug & NETIF_MSG_PROBE)
1012 printk(KERN_ERR PFX
1013 "io address range already allocated\n");
1014 return -EBUSY;
1015 }
1083 1016
1084 if (!pci_dma_supported(pdev, PCNET32_DMA_MASK)) { 1017 err = pcnet32_probe1(ioaddr, 1, pdev);
1085 if (pcnet32_debug & NETIF_MSG_PROBE) 1018 if (err < 0) {
1086 printk(KERN_ERR PFX "architecture does not support 32bit PCI busmaster DMA\n"); 1019 pci_disable_device(pdev);
1087 return -ENODEV; 1020 }
1088 } 1021 return err;
1089 if (request_region(ioaddr, PCNET32_TOTAL_SIZE, "pcnet32_probe_pci") == NULL) {
1090 if (pcnet32_debug & NETIF_MSG_PROBE)
1091 printk(KERN_ERR PFX "io address range already allocated\n");
1092 return -EBUSY;
1093 }
1094
1095 err = pcnet32_probe1(ioaddr, 1, pdev);
1096 if (err < 0) {
1097 pci_disable_device(pdev);
1098 }
1099 return err;
1100} 1022}
1101 1023
1102
1103/* pcnet32_probe1 1024/* pcnet32_probe1
1104 * Called from both pcnet32_probe_vlbus and pcnet_probe_pci. 1025 * Called from both pcnet32_probe_vlbus and pcnet_probe_pci.
1105 * pdev will be NULL when called from pcnet32_probe_vlbus. 1026 * pdev will be NULL when called from pcnet32_probe_vlbus.
@@ -1107,630 +1028,764 @@ pcnet32_probe_pci(struct pci_dev *pdev, const struct pci_device_id *ent)
1107static int __devinit 1028static int __devinit
1108pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev) 1029pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
1109{ 1030{
1110 struct pcnet32_private *lp; 1031 struct pcnet32_private *lp;
1111 dma_addr_t lp_dma_addr; 1032 dma_addr_t lp_dma_addr;
1112 int i, media; 1033 int i, media;
1113 int fdx, mii, fset, dxsuflo; 1034 int fdx, mii, fset, dxsuflo;
1114 int chip_version; 1035 int chip_version;
1115 char *chipname; 1036 char *chipname;
1116 struct net_device *dev; 1037 struct net_device *dev;
1117 struct pcnet32_access *a = NULL; 1038 struct pcnet32_access *a = NULL;
1118 u8 promaddr[6]; 1039 u8 promaddr[6];
1119 int ret = -ENODEV; 1040 int ret = -ENODEV;
1120 1041
1121 /* reset the chip */ 1042 /* reset the chip */
1122 pcnet32_wio_reset(ioaddr); 1043 pcnet32_wio_reset(ioaddr);
1123 1044
1124 /* NOTE: 16-bit check is first, otherwise some older PCnet chips fail */ 1045 /* NOTE: 16-bit check is first, otherwise some older PCnet chips fail */
1125 if (pcnet32_wio_read_csr(ioaddr, 0) == 4 && pcnet32_wio_check(ioaddr)) { 1046 if (pcnet32_wio_read_csr(ioaddr, 0) == 4 && pcnet32_wio_check(ioaddr)) {
1126 a = &pcnet32_wio; 1047 a = &pcnet32_wio;
1127 } else { 1048 } else {
1128 pcnet32_dwio_reset(ioaddr); 1049 pcnet32_dwio_reset(ioaddr);
1129 if (pcnet32_dwio_read_csr(ioaddr, 0) == 4 && pcnet32_dwio_check(ioaddr)) { 1050 if (pcnet32_dwio_read_csr(ioaddr, 0) == 4
1130 a = &pcnet32_dwio; 1051 && pcnet32_dwio_check(ioaddr)) {
1131 } else 1052 a = &pcnet32_dwio;
1132 goto err_release_region; 1053 } else
1133 } 1054 goto err_release_region;
1134 1055 }
1135 chip_version = a->read_csr(ioaddr, 88) | (a->read_csr(ioaddr,89) << 16); 1056
1136 if ((pcnet32_debug & NETIF_MSG_PROBE) && (pcnet32_debug & NETIF_MSG_HW)) 1057 chip_version =
1137 printk(KERN_INFO " PCnet chip version is %#x.\n", chip_version); 1058 a->read_csr(ioaddr, 88) | (a->read_csr(ioaddr, 89) << 16);
1138 if ((chip_version & 0xfff) != 0x003) { 1059 if ((pcnet32_debug & NETIF_MSG_PROBE) && (pcnet32_debug & NETIF_MSG_HW))
1139 if (pcnet32_debug & NETIF_MSG_PROBE) 1060 printk(KERN_INFO " PCnet chip version is %#x.\n",
1140 printk(KERN_INFO PFX "Unsupported chip version.\n"); 1061 chip_version);
1141 goto err_release_region; 1062 if ((chip_version & 0xfff) != 0x003) {
1142 } 1063 if (pcnet32_debug & NETIF_MSG_PROBE)
1143 1064 printk(KERN_INFO PFX "Unsupported chip version.\n");
1144 /* initialize variables */ 1065 goto err_release_region;
1145 fdx = mii = fset = dxsuflo = 0; 1066 }
1146 chip_version = (chip_version >> 12) & 0xffff; 1067
1147 1068 /* initialize variables */
1148 switch (chip_version) { 1069 fdx = mii = fset = dxsuflo = 0;
1149 case 0x2420: 1070 chip_version = (chip_version >> 12) & 0xffff;
1150 chipname = "PCnet/PCI 79C970"; /* PCI */ 1071
1151 break; 1072 switch (chip_version) {
1152 case 0x2430: 1073 case 0x2420:
1153 if (shared) 1074 chipname = "PCnet/PCI 79C970"; /* PCI */
1154 chipname = "PCnet/PCI 79C970"; /* 970 gives the wrong chip id back */ 1075 break;
1155 else 1076 case 0x2430:
1156 chipname = "PCnet/32 79C965"; /* 486/VL bus */ 1077 if (shared)
1157 break; 1078 chipname = "PCnet/PCI 79C970"; /* 970 gives the wrong chip id back */
1158 case 0x2621: 1079 else
1159 chipname = "PCnet/PCI II 79C970A"; /* PCI */ 1080 chipname = "PCnet/32 79C965"; /* 486/VL bus */
1160 fdx = 1; 1081 break;
1161 break; 1082 case 0x2621:
1162 case 0x2623: 1083 chipname = "PCnet/PCI II 79C970A"; /* PCI */
1163 chipname = "PCnet/FAST 79C971"; /* PCI */ 1084 fdx = 1;
1164 fdx = 1; mii = 1; fset = 1; 1085 break;
1165 break; 1086 case 0x2623:
1166 case 0x2624: 1087 chipname = "PCnet/FAST 79C971"; /* PCI */
1167 chipname = "PCnet/FAST+ 79C972"; /* PCI */ 1088 fdx = 1;
1168 fdx = 1; mii = 1; fset = 1; 1089 mii = 1;
1169 break; 1090 fset = 1;
1170 case 0x2625: 1091 break;
1171 chipname = "PCnet/FAST III 79C973"; /* PCI */ 1092 case 0x2624:
1172 fdx = 1; mii = 1; 1093 chipname = "PCnet/FAST+ 79C972"; /* PCI */
1173 break; 1094 fdx = 1;
1174 case 0x2626: 1095 mii = 1;
1175 chipname = "PCnet/Home 79C978"; /* PCI */ 1096 fset = 1;
1176 fdx = 1; 1097 break;
1098 case 0x2625:
1099 chipname = "PCnet/FAST III 79C973"; /* PCI */
1100 fdx = 1;
1101 mii = 1;
1102 break;
1103 case 0x2626:
1104 chipname = "PCnet/Home 79C978"; /* PCI */
1105 fdx = 1;
1106 /*
1107 * This is based on specs published at www.amd.com. This section
1108 * assumes that a card with a 79C978 wants to go into standard
1109 * ethernet mode. The 79C978 can also go into 1Mb HomePNA mode,
1110 * and the module option homepna=1 can select this instead.
1111 */
1112 media = a->read_bcr(ioaddr, 49);
1113 media &= ~3; /* default to 10Mb ethernet */
1114 if (cards_found < MAX_UNITS && homepna[cards_found])
1115 media |= 1; /* switch to home wiring mode */
1116 if (pcnet32_debug & NETIF_MSG_PROBE)
1117 printk(KERN_DEBUG PFX "media set to %sMbit mode.\n",
1118 (media & 1) ? "1" : "10");
1119 a->write_bcr(ioaddr, 49, media);
1120 break;
1121 case 0x2627:
1122 chipname = "PCnet/FAST III 79C975"; /* PCI */
1123 fdx = 1;
1124 mii = 1;
1125 break;
1126 case 0x2628:
1127 chipname = "PCnet/PRO 79C976";
1128 fdx = 1;
1129 mii = 1;
1130 break;
1131 default:
1132 if (pcnet32_debug & NETIF_MSG_PROBE)
1133 printk(KERN_INFO PFX
1134 "PCnet version %#x, no PCnet32 chip.\n",
1135 chip_version);
1136 goto err_release_region;
1137 }
1138
1177 /* 1139 /*
1178 * This is based on specs published at www.amd.com. This section 1140 * On selected chips turn on the BCR18:NOUFLO bit. This stops transmit
1179 * assumes that a card with a 79C978 wants to go into standard 1141 * starting until the packet is loaded. Strike one for reliability, lose
1180 * ethernet mode. The 79C978 can also go into 1Mb HomePNA mode, 1142 * one for latency - although on PCI this isnt a big loss. Older chips
1181 * and the module option homepna=1 can select this instead. 1143 * have FIFO's smaller than a packet, so you can't do this.
1144 * Turn on BCR18:BurstRdEn and BCR18:BurstWrEn.
1182 */ 1145 */
1183 media = a->read_bcr(ioaddr, 49); 1146
1184 media &= ~3; /* default to 10Mb ethernet */ 1147 if (fset) {
1185 if (cards_found < MAX_UNITS && homepna[cards_found]) 1148 a->write_bcr(ioaddr, 18, (a->read_bcr(ioaddr, 18) | 0x0860));
1186 media |= 1; /* switch to home wiring mode */ 1149 a->write_csr(ioaddr, 80,
1187 if (pcnet32_debug & NETIF_MSG_PROBE) 1150 (a->read_csr(ioaddr, 80) & 0x0C00) | 0x0c00);
1188 printk(KERN_DEBUG PFX "media set to %sMbit mode.\n", 1151 dxsuflo = 1;
1189 (media & 1) ? "1" : "10"); 1152 }
1190 a->write_bcr(ioaddr, 49, media); 1153
1191 break; 1154 dev = alloc_etherdev(0);
1192 case 0x2627: 1155 if (!dev) {
1193 chipname = "PCnet/FAST III 79C975"; /* PCI */ 1156 if (pcnet32_debug & NETIF_MSG_PROBE)
1194 fdx = 1; mii = 1; 1157 printk(KERN_ERR PFX "Memory allocation failed.\n");
1195 break; 1158 ret = -ENOMEM;
1196 case 0x2628: 1159 goto err_release_region;
1197 chipname = "PCnet/PRO 79C976"; 1160 }
1198 fdx = 1; mii = 1; 1161 SET_NETDEV_DEV(dev, &pdev->dev);
1199 break; 1162
1200 default:
1201 if (pcnet32_debug & NETIF_MSG_PROBE)
1202 printk(KERN_INFO PFX "PCnet version %#x, no PCnet32 chip.\n",
1203 chip_version);
1204 goto err_release_region;
1205 }
1206
1207 /*
1208 * On selected chips turn on the BCR18:NOUFLO bit. This stops transmit
1209 * starting until the packet is loaded. Strike one for reliability, lose
1210 * one for latency - although on PCI this isnt a big loss. Older chips
1211 * have FIFO's smaller than a packet, so you can't do this.
1212 * Turn on BCR18:BurstRdEn and BCR18:BurstWrEn.
1213 */
1214
1215 if (fset) {
1216 a->write_bcr(ioaddr, 18, (a->read_bcr(ioaddr, 18) | 0x0860));
1217 a->write_csr(ioaddr, 80, (a->read_csr(ioaddr, 80) & 0x0C00) | 0x0c00);
1218 dxsuflo = 1;
1219 }
1220
1221 dev = alloc_etherdev(0);
1222 if (!dev) {
1223 if (pcnet32_debug & NETIF_MSG_PROBE) 1163 if (pcnet32_debug & NETIF_MSG_PROBE)
1224 printk(KERN_ERR PFX "Memory allocation failed.\n"); 1164 printk(KERN_INFO PFX "%s at %#3lx,", chipname, ioaddr);
1225 ret = -ENOMEM; 1165
1226 goto err_release_region; 1166 /* In most chips, after a chip reset, the ethernet address is read from the
1227 } 1167 * station address PROM at the base address and programmed into the
1228 SET_NETDEV_DEV(dev, &pdev->dev); 1168 * "Physical Address Registers" CSR12-14.
1229 1169 * As a precautionary measure, we read the PROM values and complain if
1230 if (pcnet32_debug & NETIF_MSG_PROBE) 1170 * they disagree with the CSRs. Either way, we use the CSR values, and
1231 printk(KERN_INFO PFX "%s at %#3lx,", chipname, ioaddr); 1171 * double check that they are valid.
1232 1172 */
1233 /* In most chips, after a chip reset, the ethernet address is read from the 1173 for (i = 0; i < 3; i++) {
1234 * station address PROM at the base address and programmed into the 1174 unsigned int val;
1235 * "Physical Address Registers" CSR12-14. 1175 val = a->read_csr(ioaddr, i + 12) & 0x0ffff;
1236 * As a precautionary measure, we read the PROM values and complain if 1176 /* There may be endianness issues here. */
1237 * they disagree with the CSRs. Either way, we use the CSR values, and 1177 dev->dev_addr[2 * i] = val & 0x0ff;
1238 * double check that they are valid. 1178 dev->dev_addr[2 * i + 1] = (val >> 8) & 0x0ff;
1239 */ 1179 }
1240 for (i = 0; i < 3; i++) { 1180
1241 unsigned int val; 1181 /* read PROM address and compare with CSR address */
1242 val = a->read_csr(ioaddr, i+12) & 0x0ffff;
1243 /* There may be endianness issues here. */
1244 dev->dev_addr[2*i] = val & 0x0ff;
1245 dev->dev_addr[2*i+1] = (val >> 8) & 0x0ff;
1246 }
1247
1248 /* read PROM address and compare with CSR address */
1249 for (i = 0; i < 6; i++)
1250 promaddr[i] = inb(ioaddr + i);
1251
1252 if (memcmp(promaddr, dev->dev_addr, 6)
1253 || !is_valid_ether_addr(dev->dev_addr)) {
1254 if (is_valid_ether_addr(promaddr)) {
1255 if (pcnet32_debug & NETIF_MSG_PROBE) {
1256 printk(" warning: CSR address invalid,\n");
1257 printk(KERN_INFO " using instead PROM address of");
1258 }
1259 memcpy(dev->dev_addr, promaddr, 6);
1260 }
1261 }
1262 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
1263
1264 /* if the ethernet address is not valid, force to 00:00:00:00:00:00 */
1265 if (!is_valid_ether_addr(dev->perm_addr))
1266 memset(dev->dev_addr, 0, sizeof(dev->dev_addr));
1267
1268 if (pcnet32_debug & NETIF_MSG_PROBE) {
1269 for (i = 0; i < 6; i++) 1182 for (i = 0; i < 6; i++)
1270 printk(" %2.2x", dev->dev_addr[i]); 1183 promaddr[i] = inb(ioaddr + i);
1271 1184
1272 /* Version 0x2623 and 0x2624 */ 1185 if (memcmp(promaddr, dev->dev_addr, 6)
1273 if (((chip_version + 1) & 0xfffe) == 0x2624) { 1186 || !is_valid_ether_addr(dev->dev_addr)) {
1274 i = a->read_csr(ioaddr, 80) & 0x0C00; /* Check tx_start_pt */ 1187 if (is_valid_ether_addr(promaddr)) {
1275 printk("\n" KERN_INFO " tx_start_pt(0x%04x):",i); 1188 if (pcnet32_debug & NETIF_MSG_PROBE) {
1276 switch(i>>10) { 1189 printk(" warning: CSR address invalid,\n");
1277 case 0: printk(" 20 bytes,"); break; 1190 printk(KERN_INFO
1278 case 1: printk(" 64 bytes,"); break; 1191 " using instead PROM address of");
1279 case 2: printk(" 128 bytes,"); break; 1192 }
1280 case 3: printk("~220 bytes,"); break; 1193 memcpy(dev->dev_addr, promaddr, 6);
1281 } 1194 }
1282 i = a->read_bcr(ioaddr, 18); /* Check Burst/Bus control */ 1195 }
1283 printk(" BCR18(%x):",i&0xffff); 1196 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
1284 if (i & (1<<5)) printk("BurstWrEn "); 1197
1285 if (i & (1<<6)) printk("BurstRdEn "); 1198 /* if the ethernet address is not valid, force to 00:00:00:00:00:00 */
1286 if (i & (1<<7)) printk("DWordIO "); 1199 if (!is_valid_ether_addr(dev->perm_addr))
1287 if (i & (1<<11)) printk("NoUFlow "); 1200 memset(dev->dev_addr, 0, sizeof(dev->dev_addr));
1288 i = a->read_bcr(ioaddr, 25); 1201
1289 printk("\n" KERN_INFO " SRAMSIZE=0x%04x,",i<<8); 1202 if (pcnet32_debug & NETIF_MSG_PROBE) {
1290 i = a->read_bcr(ioaddr, 26); 1203 for (i = 0; i < 6; i++)
1291 printk(" SRAM_BND=0x%04x,",i<<8); 1204 printk(" %2.2x", dev->dev_addr[i]);
1292 i = a->read_bcr(ioaddr, 27); 1205
1293 if (i & (1<<14)) printk("LowLatRx"); 1206 /* Version 0x2623 and 0x2624 */
1294 } 1207 if (((chip_version + 1) & 0xfffe) == 0x2624) {
1295 } 1208 i = a->read_csr(ioaddr, 80) & 0x0C00; /* Check tx_start_pt */
1296 1209 printk("\n" KERN_INFO " tx_start_pt(0x%04x):", i);
1297 dev->base_addr = ioaddr; 1210 switch (i >> 10) {
1298 /* pci_alloc_consistent returns page-aligned memory, so we do not have to check the alignment */ 1211 case 0:
1299 if ((lp = pci_alloc_consistent(pdev, sizeof(*lp), &lp_dma_addr)) == NULL) { 1212 printk(" 20 bytes,");
1300 if (pcnet32_debug & NETIF_MSG_PROBE) 1213 break;
1301 printk(KERN_ERR PFX "Consistent memory allocation failed.\n"); 1214 case 1:
1302 ret = -ENOMEM; 1215 printk(" 64 bytes,");
1303 goto err_free_netdev; 1216 break;
1304 } 1217 case 2:
1305 1218 printk(" 128 bytes,");
1306 memset(lp, 0, sizeof(*lp)); 1219 break;
1307 lp->dma_addr = lp_dma_addr; 1220 case 3:
1308 lp->pci_dev = pdev; 1221 printk("~220 bytes,");
1309 1222 break;
1310 spin_lock_init(&lp->lock); 1223 }
1311 1224 i = a->read_bcr(ioaddr, 18); /* Check Burst/Bus control */
1312 SET_MODULE_OWNER(dev); 1225 printk(" BCR18(%x):", i & 0xffff);
1313 SET_NETDEV_DEV(dev, &pdev->dev); 1226 if (i & (1 << 5))
1314 dev->priv = lp; 1227 printk("BurstWrEn ");
1315 lp->name = chipname; 1228 if (i & (1 << 6))
1316 lp->shared_irq = shared; 1229 printk("BurstRdEn ");
1317 lp->tx_ring_size = TX_RING_SIZE; /* default tx ring size */ 1230 if (i & (1 << 7))
1318 lp->rx_ring_size = RX_RING_SIZE; /* default rx ring size */ 1231 printk("DWordIO ");
1319 lp->tx_mod_mask = lp->tx_ring_size - 1; 1232 if (i & (1 << 11))
1320 lp->rx_mod_mask = lp->rx_ring_size - 1; 1233 printk("NoUFlow ");
1321 lp->tx_len_bits = (PCNET32_LOG_TX_BUFFERS << 12); 1234 i = a->read_bcr(ioaddr, 25);
1322 lp->rx_len_bits = (PCNET32_LOG_RX_BUFFERS << 4); 1235 printk("\n" KERN_INFO " SRAMSIZE=0x%04x,", i << 8);
1323 lp->mii_if.full_duplex = fdx; 1236 i = a->read_bcr(ioaddr, 26);
1324 lp->mii_if.phy_id_mask = 0x1f; 1237 printk(" SRAM_BND=0x%04x,", i << 8);
1325 lp->mii_if.reg_num_mask = 0x1f; 1238 i = a->read_bcr(ioaddr, 27);
1326 lp->dxsuflo = dxsuflo; 1239 if (i & (1 << 14))
1327 lp->mii = mii; 1240 printk("LowLatRx");
1328 lp->msg_enable = pcnet32_debug; 1241 }
1329 if ((cards_found >= MAX_UNITS) || (options[cards_found] > sizeof(options_mapping))) 1242 }
1330 lp->options = PCNET32_PORT_ASEL; 1243
1331 else 1244 dev->base_addr = ioaddr;
1332 lp->options = options_mapping[options[cards_found]]; 1245 /* pci_alloc_consistent returns page-aligned memory, so we do not have to check the alignment */
1333 lp->mii_if.dev = dev; 1246 if ((lp =
1334 lp->mii_if.mdio_read = mdio_read; 1247 pci_alloc_consistent(pdev, sizeof(*lp), &lp_dma_addr)) == NULL) {
1335 lp->mii_if.mdio_write = mdio_write; 1248 if (pcnet32_debug & NETIF_MSG_PROBE)
1336 1249 printk(KERN_ERR PFX
1337 if (fdx && !(lp->options & PCNET32_PORT_ASEL) && 1250 "Consistent memory allocation failed.\n");
1338 ((cards_found>=MAX_UNITS) || full_duplex[cards_found])) 1251 ret = -ENOMEM;
1339 lp->options |= PCNET32_PORT_FD; 1252 goto err_free_netdev;
1340 1253 }
1341 if (!a) { 1254
1342 if (pcnet32_debug & NETIF_MSG_PROBE) 1255 memset(lp, 0, sizeof(*lp));
1343 printk(KERN_ERR PFX "No access methods\n"); 1256 lp->dma_addr = lp_dma_addr;
1344 ret = -ENODEV; 1257 lp->pci_dev = pdev;
1345 goto err_free_consistent; 1258
1346 } 1259 spin_lock_init(&lp->lock);
1347 lp->a = *a; 1260
1348 1261 SET_MODULE_OWNER(dev);
1349 /* prior to register_netdev, dev->name is not yet correct */ 1262 SET_NETDEV_DEV(dev, &pdev->dev);
1350 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) { 1263 dev->priv = lp;
1351 ret = -ENOMEM; 1264 lp->name = chipname;
1352 goto err_free_ring; 1265 lp->shared_irq = shared;
1353 } 1266 lp->tx_ring_size = TX_RING_SIZE; /* default tx ring size */
1354 /* detect special T1/E1 WAN card by checking for MAC address */ 1267 lp->rx_ring_size = RX_RING_SIZE; /* default rx ring size */
1355 if (dev->dev_addr[0] == 0x00 && dev->dev_addr[1] == 0xe0 1268 lp->tx_mod_mask = lp->tx_ring_size - 1;
1269 lp->rx_mod_mask = lp->rx_ring_size - 1;
1270 lp->tx_len_bits = (PCNET32_LOG_TX_BUFFERS << 12);
1271 lp->rx_len_bits = (PCNET32_LOG_RX_BUFFERS << 4);
1272 lp->mii_if.full_duplex = fdx;
1273 lp->mii_if.phy_id_mask = 0x1f;
1274 lp->mii_if.reg_num_mask = 0x1f;
1275 lp->dxsuflo = dxsuflo;
1276 lp->mii = mii;
1277 lp->msg_enable = pcnet32_debug;
1278 if ((cards_found >= MAX_UNITS)
1279 || (options[cards_found] > sizeof(options_mapping)))
1280 lp->options = PCNET32_PORT_ASEL;
1281 else
1282 lp->options = options_mapping[options[cards_found]];
1283 lp->mii_if.dev = dev;
1284 lp->mii_if.mdio_read = mdio_read;
1285 lp->mii_if.mdio_write = mdio_write;
1286
1287 if (fdx && !(lp->options & PCNET32_PORT_ASEL) &&
1288 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
1289 lp->options |= PCNET32_PORT_FD;
1290
1291 if (!a) {
1292 if (pcnet32_debug & NETIF_MSG_PROBE)
1293 printk(KERN_ERR PFX "No access methods\n");
1294 ret = -ENODEV;
1295 goto err_free_consistent;
1296 }
1297 lp->a = *a;
1298
1299 /* prior to register_netdev, dev->name is not yet correct */
1300 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
1301 ret = -ENOMEM;
1302 goto err_free_ring;
1303 }
1304 /* detect special T1/E1 WAN card by checking for MAC address */
1305 if (dev->dev_addr[0] == 0x00 && dev->dev_addr[1] == 0xe0
1356 && dev->dev_addr[2] == 0x75) 1306 && dev->dev_addr[2] == 0x75)
1357 lp->options = PCNET32_PORT_FD | PCNET32_PORT_GPSI; 1307 lp->options = PCNET32_PORT_FD | PCNET32_PORT_GPSI;
1358
1359 lp->init_block.mode = le16_to_cpu(0x0003); /* Disable Rx and Tx. */
1360 lp->init_block.tlen_rlen = le16_to_cpu(lp->tx_len_bits | lp->rx_len_bits);
1361 for (i = 0; i < 6; i++)
1362 lp->init_block.phys_addr[i] = dev->dev_addr[i];
1363 lp->init_block.filter[0] = 0x00000000;
1364 lp->init_block.filter[1] = 0x00000000;
1365 lp->init_block.rx_ring = (u32)le32_to_cpu(lp->rx_ring_dma_addr);
1366 lp->init_block.tx_ring = (u32)le32_to_cpu(lp->tx_ring_dma_addr);
1367
1368 /* switch pcnet32 to 32bit mode */
1369 a->write_bcr(ioaddr, 20, 2);
1370
1371 a->write_csr(ioaddr, 1, (lp->dma_addr + offsetof(struct pcnet32_private,
1372 init_block)) & 0xffff);
1373 a->write_csr(ioaddr, 2, (lp->dma_addr + offsetof(struct pcnet32_private,
1374 init_block)) >> 16);
1375
1376 if (pdev) { /* use the IRQ provided by PCI */
1377 dev->irq = pdev->irq;
1378 if (pcnet32_debug & NETIF_MSG_PROBE)
1379 printk(" assigned IRQ %d.\n", dev->irq);
1380 } else {
1381 unsigned long irq_mask = probe_irq_on();
1382 1308
1383 /* 1309 lp->init_block.mode = le16_to_cpu(0x0003); /* Disable Rx and Tx. */
1384 * To auto-IRQ we enable the initialization-done and DMA error 1310 lp->init_block.tlen_rlen =
1385 * interrupts. For ISA boards we get a DMA error, but VLB and PCI 1311 le16_to_cpu(lp->tx_len_bits | lp->rx_len_bits);
1386 * boards will work. 1312 for (i = 0; i < 6; i++)
1387 */ 1313 lp->init_block.phys_addr[i] = dev->dev_addr[i];
1388 /* Trigger an initialization just for the interrupt. */ 1314 lp->init_block.filter[0] = 0x00000000;
1389 a->write_csr (ioaddr, 0, 0x41); 1315 lp->init_block.filter[1] = 0x00000000;
1390 mdelay (1); 1316 lp->init_block.rx_ring = (u32) le32_to_cpu(lp->rx_ring_dma_addr);
1317 lp->init_block.tx_ring = (u32) le32_to_cpu(lp->tx_ring_dma_addr);
1318
1319 /* switch pcnet32 to 32bit mode */
1320 a->write_bcr(ioaddr, 20, 2);
1321
1322 a->write_csr(ioaddr, 1, (lp->dma_addr + offsetof(struct pcnet32_private,
1323 init_block)) & 0xffff);
1324 a->write_csr(ioaddr, 2, (lp->dma_addr + offsetof(struct pcnet32_private,
1325 init_block)) >> 16);
1326
1327 if (pdev) { /* use the IRQ provided by PCI */
1328 dev->irq = pdev->irq;
1329 if (pcnet32_debug & NETIF_MSG_PROBE)
1330 printk(" assigned IRQ %d.\n", dev->irq);
1331 } else {
1332 unsigned long irq_mask = probe_irq_on();
1333
1334 /*
1335 * To auto-IRQ we enable the initialization-done and DMA error
1336 * interrupts. For ISA boards we get a DMA error, but VLB and PCI
1337 * boards will work.
1338 */
1339 /* Trigger an initialization just for the interrupt. */
1340 a->write_csr(ioaddr, 0, 0x41);
1341 mdelay(1);
1342
1343 dev->irq = probe_irq_off(irq_mask);
1344 if (!dev->irq) {
1345 if (pcnet32_debug & NETIF_MSG_PROBE)
1346 printk(", failed to detect IRQ line.\n");
1347 ret = -ENODEV;
1348 goto err_free_ring;
1349 }
1350 if (pcnet32_debug & NETIF_MSG_PROBE)
1351 printk(", probed IRQ %d.\n", dev->irq);
1352 }
1391 1353
1392 dev->irq = probe_irq_off (irq_mask); 1354 /* Set the mii phy_id so that we can query the link state */
1393 if (!dev->irq) { 1355 if (lp->mii) {
1394 if (pcnet32_debug & NETIF_MSG_PROBE) 1356 /* lp->phycount and lp->phymask are set to 0 by memset above */
1395 printk(", failed to detect IRQ line.\n"); 1357
1396 ret = -ENODEV; 1358 lp->mii_if.phy_id = ((lp->a.read_bcr(ioaddr, 33)) >> 5) & 0x1f;
1397 goto err_free_ring; 1359 /* scan for PHYs */
1360 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
1361 unsigned short id1, id2;
1362
1363 id1 = mdio_read(dev, i, MII_PHYSID1);
1364 if (id1 == 0xffff)
1365 continue;
1366 id2 = mdio_read(dev, i, MII_PHYSID2);
1367 if (id2 == 0xffff)
1368 continue;
1369 if (i == 31 && ((chip_version + 1) & 0xfffe) == 0x2624)
1370 continue; /* 79C971 & 79C972 have phantom phy at id 31 */
1371 lp->phycount++;
1372 lp->phymask |= (1 << i);
1373 lp->mii_if.phy_id = i;
1374 if (pcnet32_debug & NETIF_MSG_PROBE)
1375 printk(KERN_INFO PFX
1376 "Found PHY %04x:%04x at address %d.\n",
1377 id1, id2, i);
1378 }
1379 lp->a.write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
1380 if (lp->phycount > 1) {
1381 lp->options |= PCNET32_PORT_MII;
1382 }
1398 } 1383 }
1399 if (pcnet32_debug & NETIF_MSG_PROBE) 1384
1400 printk(", probed IRQ %d.\n", dev->irq); 1385 init_timer(&lp->watchdog_timer);
1401 } 1386 lp->watchdog_timer.data = (unsigned long)dev;
1402 1387 lp->watchdog_timer.function = (void *)&pcnet32_watchdog;
1403 /* Set the mii phy_id so that we can query the link state */ 1388
1404 if (lp->mii) 1389 /* The PCNET32-specific entries in the device structure. */
1405 lp->mii_if.phy_id = ((lp->a.read_bcr (ioaddr, 33)) >> 5) & 0x1f; 1390 dev->open = &pcnet32_open;
1406 1391 dev->hard_start_xmit = &pcnet32_start_xmit;
1407 init_timer (&lp->watchdog_timer); 1392 dev->stop = &pcnet32_close;
1408 lp->watchdog_timer.data = (unsigned long) dev; 1393 dev->get_stats = &pcnet32_get_stats;
1409 lp->watchdog_timer.function = (void *) &pcnet32_watchdog; 1394 dev->set_multicast_list = &pcnet32_set_multicast_list;
1410 1395 dev->do_ioctl = &pcnet32_ioctl;
1411 /* The PCNET32-specific entries in the device structure. */ 1396 dev->ethtool_ops = &pcnet32_ethtool_ops;
1412 dev->open = &pcnet32_open; 1397 dev->tx_timeout = pcnet32_tx_timeout;
1413 dev->hard_start_xmit = &pcnet32_start_xmit; 1398 dev->watchdog_timeo = (5 * HZ);
1414 dev->stop = &pcnet32_close;
1415 dev->get_stats = &pcnet32_get_stats;
1416 dev->set_multicast_list = &pcnet32_set_multicast_list;
1417 dev->do_ioctl = &pcnet32_ioctl;
1418 dev->ethtool_ops = &pcnet32_ethtool_ops;
1419 dev->tx_timeout = pcnet32_tx_timeout;
1420 dev->watchdog_timeo = (5*HZ);
1421 1399
1422#ifdef CONFIG_NET_POLL_CONTROLLER 1400#ifdef CONFIG_NET_POLL_CONTROLLER
1423 dev->poll_controller = pcnet32_poll_controller; 1401 dev->poll_controller = pcnet32_poll_controller;
1424#endif 1402#endif
1425 1403
1426 /* Fill in the generic fields of the device structure. */ 1404 /* Fill in the generic fields of the device structure. */
1427 if (register_netdev(dev)) 1405 if (register_netdev(dev))
1428 goto err_free_ring; 1406 goto err_free_ring;
1429 1407
1430 if (pdev) { 1408 if (pdev) {
1431 pci_set_drvdata(pdev, dev); 1409 pci_set_drvdata(pdev, dev);
1432 } else { 1410 } else {
1433 lp->next = pcnet32_dev; 1411 lp->next = pcnet32_dev;
1434 pcnet32_dev = dev; 1412 pcnet32_dev = dev;
1435 } 1413 }
1436
1437 if (pcnet32_debug & NETIF_MSG_PROBE)
1438 printk(KERN_INFO "%s: registered as %s\n", dev->name, lp->name);
1439 cards_found++;
1440
1441 /* enable LED writes */
1442 a->write_bcr(ioaddr, 2, a->read_bcr(ioaddr, 2) | 0x1000);
1443
1444 return 0;
1445
1446err_free_ring:
1447 pcnet32_free_ring(dev);
1448err_free_consistent:
1449 pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr);
1450err_free_netdev:
1451 free_netdev(dev);
1452err_release_region:
1453 release_region(ioaddr, PCNET32_TOTAL_SIZE);
1454 return ret;
1455}
1456 1414
1415 if (pcnet32_debug & NETIF_MSG_PROBE)
1416 printk(KERN_INFO "%s: registered as %s\n", dev->name, lp->name);
1417 cards_found++;
1418
1419 /* enable LED writes */
1420 a->write_bcr(ioaddr, 2, a->read_bcr(ioaddr, 2) | 0x1000);
1421
1422 return 0;
1423
1424 err_free_ring:
1425 pcnet32_free_ring(dev);
1426 err_free_consistent:
1427 pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr);
1428 err_free_netdev:
1429 free_netdev(dev);
1430 err_release_region:
1431 release_region(ioaddr, PCNET32_TOTAL_SIZE);
1432 return ret;
1433}
1457 1434
1458/* if any allocation fails, caller must also call pcnet32_free_ring */ 1435/* if any allocation fails, caller must also call pcnet32_free_ring */
1459static int pcnet32_alloc_ring(struct net_device *dev, char *name) 1436static int pcnet32_alloc_ring(struct net_device *dev, char *name)
1460{ 1437{
1461 struct pcnet32_private *lp = dev->priv; 1438 struct pcnet32_private *lp = dev->priv;
1462 1439
1463 lp->tx_ring = pci_alloc_consistent(lp->pci_dev, 1440 lp->tx_ring = pci_alloc_consistent(lp->pci_dev,
1464 sizeof(struct pcnet32_tx_head) * lp->tx_ring_size, 1441 sizeof(struct pcnet32_tx_head) *
1465 &lp->tx_ring_dma_addr); 1442 lp->tx_ring_size,
1466 if (lp->tx_ring == NULL) { 1443 &lp->tx_ring_dma_addr);
1467 if (pcnet32_debug & NETIF_MSG_DRV) 1444 if (lp->tx_ring == NULL) {
1468 printk("\n" KERN_ERR PFX "%s: Consistent memory allocation failed.\n", 1445 if (pcnet32_debug & NETIF_MSG_DRV)
1469 name); 1446 printk("\n" KERN_ERR PFX
1470 return -ENOMEM; 1447 "%s: Consistent memory allocation failed.\n",
1471 } 1448 name);
1472 1449 return -ENOMEM;
1473 lp->rx_ring = pci_alloc_consistent(lp->pci_dev, 1450 }
1474 sizeof(struct pcnet32_rx_head) * lp->rx_ring_size,
1475 &lp->rx_ring_dma_addr);
1476 if (lp->rx_ring == NULL) {
1477 if (pcnet32_debug & NETIF_MSG_DRV)
1478 printk("\n" KERN_ERR PFX "%s: Consistent memory allocation failed.\n",
1479 name);
1480 return -ENOMEM;
1481 }
1482
1483 lp->tx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->tx_ring_size,
1484 GFP_ATOMIC);
1485 if (!lp->tx_dma_addr) {
1486 if (pcnet32_debug & NETIF_MSG_DRV)
1487 printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name);
1488 return -ENOMEM;
1489 }
1490 memset(lp->tx_dma_addr, 0, sizeof(dma_addr_t) * lp->tx_ring_size);
1491
1492 lp->rx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->rx_ring_size,
1493 GFP_ATOMIC);
1494 if (!lp->rx_dma_addr) {
1495 if (pcnet32_debug & NETIF_MSG_DRV)
1496 printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name);
1497 return -ENOMEM;
1498 }
1499 memset(lp->rx_dma_addr, 0, sizeof(dma_addr_t) * lp->rx_ring_size);
1500
1501 lp->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->tx_ring_size,
1502 GFP_ATOMIC);
1503 if (!lp->tx_skbuff) {
1504 if (pcnet32_debug & NETIF_MSG_DRV)
1505 printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name);
1506 return -ENOMEM;
1507 }
1508 memset(lp->tx_skbuff, 0, sizeof(struct sk_buff *) * lp->tx_ring_size);
1509
1510 lp->rx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->rx_ring_size,
1511 GFP_ATOMIC);
1512 if (!lp->rx_skbuff) {
1513 if (pcnet32_debug & NETIF_MSG_DRV)
1514 printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name);
1515 return -ENOMEM;
1516 }
1517 memset(lp->rx_skbuff, 0, sizeof(struct sk_buff *) * lp->rx_ring_size);
1518 1451
1519 return 0; 1452 lp->rx_ring = pci_alloc_consistent(lp->pci_dev,
1520} 1453 sizeof(struct pcnet32_rx_head) *
1454 lp->rx_ring_size,
1455 &lp->rx_ring_dma_addr);
1456 if (lp->rx_ring == NULL) {
1457 if (pcnet32_debug & NETIF_MSG_DRV)
1458 printk("\n" KERN_ERR PFX
1459 "%s: Consistent memory allocation failed.\n",
1460 name);
1461 return -ENOMEM;
1462 }
1521 1463
1464 lp->tx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->tx_ring_size,
1465 GFP_ATOMIC);
1466 if (!lp->tx_dma_addr) {
1467 if (pcnet32_debug & NETIF_MSG_DRV)
1468 printk("\n" KERN_ERR PFX
1469 "%s: Memory allocation failed.\n", name);
1470 return -ENOMEM;
1471 }
1472 memset(lp->tx_dma_addr, 0, sizeof(dma_addr_t) * lp->tx_ring_size);
1473
1474 lp->rx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->rx_ring_size,
1475 GFP_ATOMIC);
1476 if (!lp->rx_dma_addr) {
1477 if (pcnet32_debug & NETIF_MSG_DRV)
1478 printk("\n" KERN_ERR PFX
1479 "%s: Memory allocation failed.\n", name);
1480 return -ENOMEM;
1481 }
1482 memset(lp->rx_dma_addr, 0, sizeof(dma_addr_t) * lp->rx_ring_size);
1483
1484 lp->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->tx_ring_size,
1485 GFP_ATOMIC);
1486 if (!lp->tx_skbuff) {
1487 if (pcnet32_debug & NETIF_MSG_DRV)
1488 printk("\n" KERN_ERR PFX
1489 "%s: Memory allocation failed.\n", name);
1490 return -ENOMEM;
1491 }
1492 memset(lp->tx_skbuff, 0, sizeof(struct sk_buff *) * lp->tx_ring_size);
1493
1494 lp->rx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->rx_ring_size,
1495 GFP_ATOMIC);
1496 if (!lp->rx_skbuff) {
1497 if (pcnet32_debug & NETIF_MSG_DRV)
1498 printk("\n" KERN_ERR PFX
1499 "%s: Memory allocation failed.\n", name);
1500 return -ENOMEM;
1501 }
1502 memset(lp->rx_skbuff, 0, sizeof(struct sk_buff *) * lp->rx_ring_size);
1503
1504 return 0;
1505}
1522 1506
1523static void pcnet32_free_ring(struct net_device *dev) 1507static void pcnet32_free_ring(struct net_device *dev)
1524{ 1508{
1525 struct pcnet32_private *lp = dev->priv; 1509 struct pcnet32_private *lp = dev->priv;
1526 1510
1527 kfree(lp->tx_skbuff); 1511 kfree(lp->tx_skbuff);
1528 lp->tx_skbuff = NULL; 1512 lp->tx_skbuff = NULL;
1529 1513
1530 kfree(lp->rx_skbuff); 1514 kfree(lp->rx_skbuff);
1531 lp->rx_skbuff = NULL; 1515 lp->rx_skbuff = NULL;
1532 1516
1533 kfree(lp->tx_dma_addr); 1517 kfree(lp->tx_dma_addr);
1534 lp->tx_dma_addr = NULL; 1518 lp->tx_dma_addr = NULL;
1535 1519
1536 kfree(lp->rx_dma_addr); 1520 kfree(lp->rx_dma_addr);
1537 lp->rx_dma_addr = NULL; 1521 lp->rx_dma_addr = NULL;
1538 1522
1539 if (lp->tx_ring) { 1523 if (lp->tx_ring) {
1540 pci_free_consistent(lp->pci_dev, sizeof(struct pcnet32_tx_head) * lp->tx_ring_size, 1524 pci_free_consistent(lp->pci_dev,
1541 lp->tx_ring, lp->tx_ring_dma_addr); 1525 sizeof(struct pcnet32_tx_head) *
1542 lp->tx_ring = NULL; 1526 lp->tx_ring_size, lp->tx_ring,
1543 } 1527 lp->tx_ring_dma_addr);
1528 lp->tx_ring = NULL;
1529 }
1544 1530
1545 if (lp->rx_ring) { 1531 if (lp->rx_ring) {
1546 pci_free_consistent(lp->pci_dev, sizeof(struct pcnet32_rx_head) * lp->rx_ring_size, 1532 pci_free_consistent(lp->pci_dev,
1547 lp->rx_ring, lp->rx_ring_dma_addr); 1533 sizeof(struct pcnet32_rx_head) *
1548 lp->rx_ring = NULL; 1534 lp->rx_ring_size, lp->rx_ring,
1549 } 1535 lp->rx_ring_dma_addr);
1536 lp->rx_ring = NULL;
1537 }
1550} 1538}
1551 1539
1552 1540static int pcnet32_open(struct net_device *dev)
1553static int
1554pcnet32_open(struct net_device *dev)
1555{ 1541{
1556 struct pcnet32_private *lp = dev->priv; 1542 struct pcnet32_private *lp = dev->priv;
1557 unsigned long ioaddr = dev->base_addr; 1543 unsigned long ioaddr = dev->base_addr;
1558 u16 val; 1544 u16 val;
1559 int i; 1545 int i;
1560 int rc; 1546 int rc;
1561 unsigned long flags; 1547 unsigned long flags;
1562 1548
1563 if (request_irq(dev->irq, &pcnet32_interrupt, 1549 if (request_irq(dev->irq, &pcnet32_interrupt,
1564 lp->shared_irq ? SA_SHIRQ : 0, dev->name, (void *)dev)) { 1550 lp->shared_irq ? SA_SHIRQ : 0, dev->name,
1565 return -EAGAIN; 1551 (void *)dev)) {
1566 } 1552 return -EAGAIN;
1567 1553 }
1568 spin_lock_irqsave(&lp->lock, flags); 1554
1569 /* Check for a valid station address */ 1555 spin_lock_irqsave(&lp->lock, flags);
1570 if (!is_valid_ether_addr(dev->dev_addr)) { 1556 /* Check for a valid station address */
1571 rc = -EINVAL; 1557 if (!is_valid_ether_addr(dev->dev_addr)) {
1572 goto err_free_irq; 1558 rc = -EINVAL;
1573 } 1559 goto err_free_irq;
1574 1560 }
1575 /* Reset the PCNET32 */ 1561
1576 lp->a.reset (ioaddr); 1562 /* Reset the PCNET32 */
1577 1563 lp->a.reset(ioaddr);
1578 /* switch pcnet32 to 32bit mode */ 1564
1579 lp->a.write_bcr (ioaddr, 20, 2); 1565 /* switch pcnet32 to 32bit mode */
1580 1566 lp->a.write_bcr(ioaddr, 20, 2);
1581 if (netif_msg_ifup(lp)) 1567
1582 printk(KERN_DEBUG "%s: pcnet32_open() irq %d tx/rx rings %#x/%#x init %#x.\n", 1568 if (netif_msg_ifup(lp))
1583 dev->name, dev->irq, 1569 printk(KERN_DEBUG
1584 (u32) (lp->tx_ring_dma_addr), 1570 "%s: pcnet32_open() irq %d tx/rx rings %#x/%#x init %#x.\n",
1585 (u32) (lp->rx_ring_dma_addr), 1571 dev->name, dev->irq, (u32) (lp->tx_ring_dma_addr),
1586 (u32) (lp->dma_addr + offsetof(struct pcnet32_private, init_block))); 1572 (u32) (lp->rx_ring_dma_addr),
1587 1573 (u32) (lp->dma_addr +
1588 /* set/reset autoselect bit */ 1574 offsetof(struct pcnet32_private, init_block)));
1589 val = lp->a.read_bcr (ioaddr, 2) & ~2; 1575
1590 if (lp->options & PCNET32_PORT_ASEL) 1576 /* set/reset autoselect bit */
1591 val |= 2; 1577 val = lp->a.read_bcr(ioaddr, 2) & ~2;
1592 lp->a.write_bcr (ioaddr, 2, val); 1578 if (lp->options & PCNET32_PORT_ASEL)
1593
1594 /* handle full duplex setting */
1595 if (lp->mii_if.full_duplex) {
1596 val = lp->a.read_bcr (ioaddr, 9) & ~3;
1597 if (lp->options & PCNET32_PORT_FD) {
1598 val |= 1;
1599 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
1600 val |= 2; 1579 val |= 2;
1601 } else if (lp->options & PCNET32_PORT_ASEL) { 1580 lp->a.write_bcr(ioaddr, 2, val);
1602 /* workaround of xSeries250, turn on for 79C975 only */ 1581
1603 i = ((lp->a.read_csr(ioaddr, 88) | 1582 /* handle full duplex setting */
1604 (lp->a.read_csr(ioaddr,89) << 16)) >> 12) & 0xffff; 1583 if (lp->mii_if.full_duplex) {
1605 if (i == 0x2627) 1584 val = lp->a.read_bcr(ioaddr, 9) & ~3;
1606 val |= 3; 1585 if (lp->options & PCNET32_PORT_FD) {
1607 } 1586 val |= 1;
1608 lp->a.write_bcr (ioaddr, 9, val); 1587 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
1609 } 1588 val |= 2;
1610 1589 } else if (lp->options & PCNET32_PORT_ASEL) {
1611 /* set/reset GPSI bit in test register */ 1590 /* workaround of xSeries250, turn on for 79C975 only */
1612 val = lp->a.read_csr (ioaddr, 124) & ~0x10; 1591 i = ((lp->a.read_csr(ioaddr, 88) |
1613 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI) 1592 (lp->a.
1614 val |= 0x10; 1593 read_csr(ioaddr, 89) << 16)) >> 12) & 0xffff;
1615 lp->a.write_csr (ioaddr, 124, val); 1594 if (i == 0x2627)
1616 1595 val |= 3;
1617 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */ 1596 }
1618 if (lp->pci_dev->subsystem_vendor == PCI_VENDOR_ID_AT && 1597 lp->a.write_bcr(ioaddr, 9, val);
1598 }
1599
1600 /* set/reset GPSI bit in test register */
1601 val = lp->a.read_csr(ioaddr, 124) & ~0x10;
1602 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
1603 val |= 0x10;
1604 lp->a.write_csr(ioaddr, 124, val);
1605
1606 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
1607 if (lp->pci_dev->subsystem_vendor == PCI_VENDOR_ID_AT &&
1619 (lp->pci_dev->subsystem_device == PCI_SUBDEVICE_ID_AT_2700FX || 1608 (lp->pci_dev->subsystem_device == PCI_SUBDEVICE_ID_AT_2700FX ||
1620 lp->pci_dev->subsystem_device == PCI_SUBDEVICE_ID_AT_2701FX)) { 1609 lp->pci_dev->subsystem_device == PCI_SUBDEVICE_ID_AT_2701FX)) {
1621 if (lp->options & PCNET32_PORT_ASEL) { 1610 if (lp->options & PCNET32_PORT_ASEL) {
1622 lp->options = PCNET32_PORT_FD | PCNET32_PORT_100; 1611 lp->options = PCNET32_PORT_FD | PCNET32_PORT_100;
1623 if (netif_msg_link(lp)) 1612 if (netif_msg_link(lp))
1624 printk(KERN_DEBUG "%s: Setting 100Mb-Full Duplex.\n", 1613 printk(KERN_DEBUG
1625 dev->name); 1614 "%s: Setting 100Mb-Full Duplex.\n",
1626 } 1615 dev->name);
1627 } 1616 }
1628 { 1617 }
1629 /* 1618 if (lp->phycount < 2) {
1630 * 24 Jun 2004 according AMD, in order to change the PHY, 1619 /*
1631 * DANAS (or DISPM for 79C976) must be set; then select the speed, 1620 * 24 Jun 2004 according AMD, in order to change the PHY,
1632 * duplex, and/or enable auto negotiation, and clear DANAS 1621 * DANAS (or DISPM for 79C976) must be set; then select the speed,
1633 */ 1622 * duplex, and/or enable auto negotiation, and clear DANAS
1634 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) { 1623 */
1635 lp->a.write_bcr(ioaddr, 32, 1624 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
1636 lp->a.read_bcr(ioaddr, 32) | 0x0080); 1625 lp->a.write_bcr(ioaddr, 32,
1637 /* disable Auto Negotiation, set 10Mpbs, HD */ 1626 lp->a.read_bcr(ioaddr, 32) | 0x0080);
1638 val = lp->a.read_bcr(ioaddr, 32) & ~0xb8; 1627 /* disable Auto Negotiation, set 10Mpbs, HD */
1639 if (lp->options & PCNET32_PORT_FD) 1628 val = lp->a.read_bcr(ioaddr, 32) & ~0xb8;
1640 val |= 0x10; 1629 if (lp->options & PCNET32_PORT_FD)
1641 if (lp->options & PCNET32_PORT_100) 1630 val |= 0x10;
1642 val |= 0x08; 1631 if (lp->options & PCNET32_PORT_100)
1643 lp->a.write_bcr (ioaddr, 32, val); 1632 val |= 0x08;
1633 lp->a.write_bcr(ioaddr, 32, val);
1634 } else {
1635 if (lp->options & PCNET32_PORT_ASEL) {
1636 lp->a.write_bcr(ioaddr, 32,
1637 lp->a.read_bcr(ioaddr,
1638 32) | 0x0080);
1639 /* enable auto negotiate, setup, disable fd */
1640 val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
1641 val |= 0x20;
1642 lp->a.write_bcr(ioaddr, 32, val);
1643 }
1644 }
1644 } else { 1645 } else {
1645 if (lp->options & PCNET32_PORT_ASEL) { 1646 int first_phy = -1;
1646 lp->a.write_bcr(ioaddr, 32, 1647 u16 bmcr;
1647 lp->a.read_bcr(ioaddr, 32) | 0x0080); 1648 u32 bcr9;
1648 /* enable auto negotiate, setup, disable fd */ 1649 struct ethtool_cmd ecmd;
1649 val = lp->a.read_bcr(ioaddr, 32) & ~0x98; 1650
1650 val |= 0x20; 1651 /*
1651 lp->a.write_bcr(ioaddr, 32, val); 1652 * There is really no good other way to handle multiple PHYs
1652 } 1653 * other than turning off all automatics
1654 */
1655 val = lp->a.read_bcr(ioaddr, 2);
1656 lp->a.write_bcr(ioaddr, 2, val & ~2);
1657 val = lp->a.read_bcr(ioaddr, 32);
1658 lp->a.write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
1659
1660 if (!(lp->options & PCNET32_PORT_ASEL)) {
1661 /* setup ecmd */
1662 ecmd.port = PORT_MII;
1663 ecmd.transceiver = XCVR_INTERNAL;
1664 ecmd.autoneg = AUTONEG_DISABLE;
1665 ecmd.speed =
1666 lp->
1667 options & PCNET32_PORT_100 ? SPEED_100 : SPEED_10;
1668 bcr9 = lp->a.read_bcr(ioaddr, 9);
1669
1670 if (lp->options & PCNET32_PORT_FD) {
1671 ecmd.duplex = DUPLEX_FULL;
1672 bcr9 |= (1 << 0);
1673 } else {
1674 ecmd.duplex = DUPLEX_HALF;
1675 bcr9 |= ~(1 << 0);
1676 }
1677 lp->a.write_bcr(ioaddr, 9, bcr9);
1678 }
1679
1680 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
1681 if (lp->phymask & (1 << i)) {
1682 /* isolate all but the first PHY */
1683 bmcr = mdio_read(dev, i, MII_BMCR);
1684 if (first_phy == -1) {
1685 first_phy = i;
1686 mdio_write(dev, i, MII_BMCR,
1687 bmcr & ~BMCR_ISOLATE);
1688 } else {
1689 mdio_write(dev, i, MII_BMCR,
1690 bmcr | BMCR_ISOLATE);
1691 }
1692 /* use mii_ethtool_sset to setup PHY */
1693 lp->mii_if.phy_id = i;
1694 ecmd.phy_address = i;
1695 if (lp->options & PCNET32_PORT_ASEL) {
1696 mii_ethtool_gset(&lp->mii_if, &ecmd);
1697 ecmd.autoneg = AUTONEG_ENABLE;
1698 }
1699 mii_ethtool_sset(&lp->mii_if, &ecmd);
1700 }
1701 }
1702 lp->mii_if.phy_id = first_phy;
1703 if (netif_msg_link(lp))
1704 printk(KERN_INFO "%s: Using PHY number %d.\n",
1705 dev->name, first_phy);
1653 } 1706 }
1654 }
1655 1707
1656#ifdef DO_DXSUFLO 1708#ifdef DO_DXSUFLO
1657 if (lp->dxsuflo) { /* Disable transmit stop on underflow */ 1709 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
1658 val = lp->a.read_csr (ioaddr, 3); 1710 val = lp->a.read_csr(ioaddr, 3);
1659 val |= 0x40; 1711 val |= 0x40;
1660 lp->a.write_csr (ioaddr, 3, val); 1712 lp->a.write_csr(ioaddr, 3, val);
1661 } 1713 }
1662#endif 1714#endif
1663 1715
1664 lp->init_block.mode = le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7); 1716 lp->init_block.mode =
1665 pcnet32_load_multicast(dev); 1717 le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);
1666 1718 pcnet32_load_multicast(dev);
1667 if (pcnet32_init_ring(dev)) { 1719
1668 rc = -ENOMEM; 1720 if (pcnet32_init_ring(dev)) {
1669 goto err_free_ring; 1721 rc = -ENOMEM;
1670 } 1722 goto err_free_ring;
1671 1723 }
1672 /* Re-initialize the PCNET32, and start it when done. */ 1724
1673 lp->a.write_csr (ioaddr, 1, (lp->dma_addr + 1725 /* Re-initialize the PCNET32, and start it when done. */
1674 offsetof(struct pcnet32_private, init_block)) & 0xffff); 1726 lp->a.write_csr(ioaddr, 1, (lp->dma_addr +
1675 lp->a.write_csr (ioaddr, 2, (lp->dma_addr + 1727 offsetof(struct pcnet32_private,
1676 offsetof(struct pcnet32_private, init_block)) >> 16); 1728 init_block)) & 0xffff);
1677 1729 lp->a.write_csr(ioaddr, 2,
1678 lp->a.write_csr (ioaddr, 4, 0x0915); 1730 (lp->dma_addr +
1679 lp->a.write_csr (ioaddr, 0, 0x0001); 1731 offsetof(struct pcnet32_private, init_block)) >> 16);
1680 1732
1681 netif_start_queue(dev); 1733 lp->a.write_csr(ioaddr, 4, 0x0915);
1682 1734 lp->a.write_csr(ioaddr, 0, 0x0001);
1683 /* If we have mii, print the link status and start the watchdog */ 1735
1684 if (lp->mii) { 1736 netif_start_queue(dev);
1685 mii_check_media (&lp->mii_if, netif_msg_link(lp), 1); 1737
1686 mod_timer (&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT); 1738 /* Print the link status and start the watchdog */
1687 } 1739 pcnet32_check_media(dev, 1);
1688 1740 mod_timer(&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT);
1689 i = 0; 1741
1690 while (i++ < 100) 1742 i = 0;
1691 if (lp->a.read_csr (ioaddr, 0) & 0x0100) 1743 while (i++ < 100)
1692 break; 1744 if (lp->a.read_csr(ioaddr, 0) & 0x0100)
1693 /* 1745 break;
1694 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton 1746 /*
1695 * reports that doing so triggers a bug in the '974. 1747 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
1696 */ 1748 * reports that doing so triggers a bug in the '974.
1697 lp->a.write_csr (ioaddr, 0, 0x0042); 1749 */
1698 1750 lp->a.write_csr(ioaddr, 0, 0x0042);
1699 if (netif_msg_ifup(lp)) 1751
1700 printk(KERN_DEBUG "%s: pcnet32 open after %d ticks, init block %#x csr0 %4.4x.\n", 1752 if (netif_msg_ifup(lp))
1701 dev->name, i, (u32) (lp->dma_addr + 1753 printk(KERN_DEBUG
1702 offsetof(struct pcnet32_private, init_block)), 1754 "%s: pcnet32 open after %d ticks, init block %#x csr0 %4.4x.\n",
1703 lp->a.read_csr(ioaddr, 0)); 1755 dev->name, i,
1704 1756 (u32) (lp->dma_addr +
1705 spin_unlock_irqrestore(&lp->lock, flags); 1757 offsetof(struct pcnet32_private, init_block)),
1706 1758 lp->a.read_csr(ioaddr, 0));
1707 return 0; /* Always succeed */ 1759
1708 1760 spin_unlock_irqrestore(&lp->lock, flags);
1709err_free_ring: 1761
1710 /* free any allocated skbuffs */ 1762 return 0; /* Always succeed */
1711 for (i = 0; i < lp->rx_ring_size; i++) { 1763
1712 lp->rx_ring[i].status = 0; 1764 err_free_ring:
1713 if (lp->rx_skbuff[i]) { 1765 /* free any allocated skbuffs */
1714 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i], PKT_BUF_SZ-2, 1766 for (i = 0; i < lp->rx_ring_size; i++) {
1715 PCI_DMA_FROMDEVICE); 1767 lp->rx_ring[i].status = 0;
1716 dev_kfree_skb(lp->rx_skbuff[i]); 1768 if (lp->rx_skbuff[i]) {
1717 } 1769 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i],
1718 lp->rx_skbuff[i] = NULL; 1770 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
1719 lp->rx_dma_addr[i] = 0; 1771 dev_kfree_skb(lp->rx_skbuff[i]);
1720 } 1772 }
1721 1773 lp->rx_skbuff[i] = NULL;
1722 pcnet32_free_ring(dev); 1774 lp->rx_dma_addr[i] = 0;
1723 1775 }
1724 /* 1776
1725 * Switch back to 16bit mode to avoid problems with dumb 1777 pcnet32_free_ring(dev);
1726 * DOS packet driver after a warm reboot 1778
1727 */ 1779 /*
1728 lp->a.write_bcr (ioaddr, 20, 4); 1780 * Switch back to 16bit mode to avoid problems with dumb
1729 1781 * DOS packet driver after a warm reboot
1730err_free_irq: 1782 */
1731 spin_unlock_irqrestore(&lp->lock, flags); 1783 lp->a.write_bcr(ioaddr, 20, 4);
1732 free_irq(dev->irq, dev); 1784
1733 return rc; 1785 err_free_irq:
1786 spin_unlock_irqrestore(&lp->lock, flags);
1787 free_irq(dev->irq, dev);
1788 return rc;
1734} 1789}
1735 1790
1736/* 1791/*
@@ -1746,727 +1801,893 @@ err_free_irq:
1746 * restarting the chip, but I'm too lazy to do so right now. dplatt@3do.com 1801 * restarting the chip, but I'm too lazy to do so right now. dplatt@3do.com
1747 */ 1802 */
1748 1803
1749static void 1804static void pcnet32_purge_tx_ring(struct net_device *dev)
1750pcnet32_purge_tx_ring(struct net_device *dev)
1751{ 1805{
1752 struct pcnet32_private *lp = dev->priv; 1806 struct pcnet32_private *lp = dev->priv;
1753 int i; 1807 int i;
1754
1755 for (i = 0; i < lp->tx_ring_size; i++) {
1756 lp->tx_ring[i].status = 0; /* CPU owns buffer */
1757 wmb(); /* Make sure adapter sees owner change */
1758 if (lp->tx_skbuff[i]) {
1759 pci_unmap_single(lp->pci_dev, lp->tx_dma_addr[i],
1760 lp->tx_skbuff[i]->len, PCI_DMA_TODEVICE);
1761 dev_kfree_skb_any(lp->tx_skbuff[i]);
1762 }
1763 lp->tx_skbuff[i] = NULL;
1764 lp->tx_dma_addr[i] = 0;
1765 }
1766}
1767 1808
1809 for (i = 0; i < lp->tx_ring_size; i++) {
1810 lp->tx_ring[i].status = 0; /* CPU owns buffer */
1811 wmb(); /* Make sure adapter sees owner change */
1812 if (lp->tx_skbuff[i]) {
1813 pci_unmap_single(lp->pci_dev, lp->tx_dma_addr[i],
1814 lp->tx_skbuff[i]->len,
1815 PCI_DMA_TODEVICE);
1816 dev_kfree_skb_any(lp->tx_skbuff[i]);
1817 }
1818 lp->tx_skbuff[i] = NULL;
1819 lp->tx_dma_addr[i] = 0;
1820 }
1821}
1768 1822
1769/* Initialize the PCNET32 Rx and Tx rings. */ 1823/* Initialize the PCNET32 Rx and Tx rings. */
1770static int 1824static int pcnet32_init_ring(struct net_device *dev)
1771pcnet32_init_ring(struct net_device *dev)
1772{ 1825{
1773 struct pcnet32_private *lp = dev->priv; 1826 struct pcnet32_private *lp = dev->priv;
1774 int i; 1827 int i;
1775 1828
1776 lp->tx_full = 0; 1829 lp->tx_full = 0;
1777 lp->cur_rx = lp->cur_tx = 0; 1830 lp->cur_rx = lp->cur_tx = 0;
1778 lp->dirty_rx = lp->dirty_tx = 0; 1831 lp->dirty_rx = lp->dirty_tx = 0;
1779 1832
1780 for (i = 0; i < lp->rx_ring_size; i++) { 1833 for (i = 0; i < lp->rx_ring_size; i++) {
1781 struct sk_buff *rx_skbuff = lp->rx_skbuff[i]; 1834 struct sk_buff *rx_skbuff = lp->rx_skbuff[i];
1782 if (rx_skbuff == NULL) { 1835 if (rx_skbuff == NULL) {
1783 if (!(rx_skbuff = lp->rx_skbuff[i] = dev_alloc_skb (PKT_BUF_SZ))) { 1836 if (!
1784 /* there is not much, we can do at this point */ 1837 (rx_skbuff = lp->rx_skbuff[i] =
1785 if (pcnet32_debug & NETIF_MSG_DRV) 1838 dev_alloc_skb(PKT_BUF_SZ))) {
1786 printk(KERN_ERR "%s: pcnet32_init_ring dev_alloc_skb failed.\n", 1839 /* there is not much, we can do at this point */
1787 dev->name); 1840 if (pcnet32_debug & NETIF_MSG_DRV)
1788 return -1; 1841 printk(KERN_ERR
1789 } 1842 "%s: pcnet32_init_ring dev_alloc_skb failed.\n",
1790 skb_reserve (rx_skbuff, 2); 1843 dev->name);
1791 } 1844 return -1;
1792 1845 }
1793 rmb(); 1846 skb_reserve(rx_skbuff, 2);
1794 if (lp->rx_dma_addr[i] == 0) 1847 }
1795 lp->rx_dma_addr[i] = pci_map_single(lp->pci_dev, rx_skbuff->data, 1848
1796 PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE); 1849 rmb();
1797 lp->rx_ring[i].base = (u32)le32_to_cpu(lp->rx_dma_addr[i]); 1850 if (lp->rx_dma_addr[i] == 0)
1798 lp->rx_ring[i].buf_length = le16_to_cpu(2-PKT_BUF_SZ); 1851 lp->rx_dma_addr[i] =
1799 wmb(); /* Make sure owner changes after all others are visible */ 1852 pci_map_single(lp->pci_dev, rx_skbuff->data,
1800 lp->rx_ring[i].status = le16_to_cpu(0x8000); 1853 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
1801 } 1854 lp->rx_ring[i].base = (u32) le32_to_cpu(lp->rx_dma_addr[i]);
1802 /* The Tx buffer address is filled in as needed, but we do need to clear 1855 lp->rx_ring[i].buf_length = le16_to_cpu(2 - PKT_BUF_SZ);
1803 * the upper ownership bit. */ 1856 wmb(); /* Make sure owner changes after all others are visible */
1804 for (i = 0; i < lp->tx_ring_size; i++) { 1857 lp->rx_ring[i].status = le16_to_cpu(0x8000);
1805 lp->tx_ring[i].status = 0; /* CPU owns buffer */ 1858 }
1806 wmb(); /* Make sure adapter sees owner change */ 1859 /* The Tx buffer address is filled in as needed, but we do need to clear
1807 lp->tx_ring[i].base = 0; 1860 * the upper ownership bit. */
1808 lp->tx_dma_addr[i] = 0; 1861 for (i = 0; i < lp->tx_ring_size; i++) {
1809 } 1862 lp->tx_ring[i].status = 0; /* CPU owns buffer */
1810 1863 wmb(); /* Make sure adapter sees owner change */
1811 lp->init_block.tlen_rlen = le16_to_cpu(lp->tx_len_bits | lp->rx_len_bits); 1864 lp->tx_ring[i].base = 0;
1812 for (i = 0; i < 6; i++) 1865 lp->tx_dma_addr[i] = 0;
1813 lp->init_block.phys_addr[i] = dev->dev_addr[i]; 1866 }
1814 lp->init_block.rx_ring = (u32)le32_to_cpu(lp->rx_ring_dma_addr); 1867
1815 lp->init_block.tx_ring = (u32)le32_to_cpu(lp->tx_ring_dma_addr); 1868 lp->init_block.tlen_rlen =
1816 wmb(); /* Make sure all changes are visible */ 1869 le16_to_cpu(lp->tx_len_bits | lp->rx_len_bits);
1817 return 0; 1870 for (i = 0; i < 6; i++)
1871 lp->init_block.phys_addr[i] = dev->dev_addr[i];
1872 lp->init_block.rx_ring = (u32) le32_to_cpu(lp->rx_ring_dma_addr);
1873 lp->init_block.tx_ring = (u32) le32_to_cpu(lp->tx_ring_dma_addr);
1874 wmb(); /* Make sure all changes are visible */
1875 return 0;
1818} 1876}
1819 1877
1820/* the pcnet32 has been issued a stop or reset. Wait for the stop bit 1878/* the pcnet32 has been issued a stop or reset. Wait for the stop bit
1821 * then flush the pending transmit operations, re-initialize the ring, 1879 * then flush the pending transmit operations, re-initialize the ring,
1822 * and tell the chip to initialize. 1880 * and tell the chip to initialize.
1823 */ 1881 */
1824static void 1882static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
1825pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
1826{ 1883{
1827 struct pcnet32_private *lp = dev->priv; 1884 struct pcnet32_private *lp = dev->priv;
1828 unsigned long ioaddr = dev->base_addr; 1885 unsigned long ioaddr = dev->base_addr;
1829 int i; 1886 int i;
1830 1887
1831 /* wait for stop */ 1888 /* wait for stop */
1832 for (i=0; i<100; i++) 1889 for (i = 0; i < 100; i++)
1833 if (lp->a.read_csr(ioaddr, 0) & 0x0004) 1890 if (lp->a.read_csr(ioaddr, 0) & 0x0004)
1834 break; 1891 break;
1835 1892
1836 if (i >= 100 && netif_msg_drv(lp)) 1893 if (i >= 100 && netif_msg_drv(lp))
1837 printk(KERN_ERR "%s: pcnet32_restart timed out waiting for stop.\n", 1894 printk(KERN_ERR
1838 dev->name); 1895 "%s: pcnet32_restart timed out waiting for stop.\n",
1896 dev->name);
1839 1897
1840 pcnet32_purge_tx_ring(dev); 1898 pcnet32_purge_tx_ring(dev);
1841 if (pcnet32_init_ring(dev)) 1899 if (pcnet32_init_ring(dev))
1842 return; 1900 return;
1843 1901
1844 /* ReInit Ring */ 1902 /* ReInit Ring */
1845 lp->a.write_csr (ioaddr, 0, 1); 1903 lp->a.write_csr(ioaddr, 0, 1);
1846 i = 0; 1904 i = 0;
1847 while (i++ < 1000) 1905 while (i++ < 1000)
1848 if (lp->a.read_csr (ioaddr, 0) & 0x0100) 1906 if (lp->a.read_csr(ioaddr, 0) & 0x0100)
1849 break; 1907 break;
1850 1908
1851 lp->a.write_csr (ioaddr, 0, csr0_bits); 1909 lp->a.write_csr(ioaddr, 0, csr0_bits);
1852} 1910}
1853 1911
1854 1912static void pcnet32_tx_timeout(struct net_device *dev)
1855static void
1856pcnet32_tx_timeout (struct net_device *dev)
1857{ 1913{
1858 struct pcnet32_private *lp = dev->priv; 1914 struct pcnet32_private *lp = dev->priv;
1859 unsigned long ioaddr = dev->base_addr, flags; 1915 unsigned long ioaddr = dev->base_addr, flags;
1860 1916
1861 spin_lock_irqsave(&lp->lock, flags); 1917 spin_lock_irqsave(&lp->lock, flags);
1862 /* Transmitter timeout, serious problems. */ 1918 /* Transmitter timeout, serious problems. */
1863 if (pcnet32_debug & NETIF_MSG_DRV) 1919 if (pcnet32_debug & NETIF_MSG_DRV)
1864 printk(KERN_ERR "%s: transmit timed out, status %4.4x, resetting.\n", 1920 printk(KERN_ERR
1865 dev->name, lp->a.read_csr(ioaddr, 0)); 1921 "%s: transmit timed out, status %4.4x, resetting.\n",
1866 lp->a.write_csr (ioaddr, 0, 0x0004); 1922 dev->name, lp->a.read_csr(ioaddr, 0));
1867 lp->stats.tx_errors++; 1923 lp->a.write_csr(ioaddr, 0, 0x0004);
1868 if (netif_msg_tx_err(lp)) { 1924 lp->stats.tx_errors++;
1869 int i; 1925 if (netif_msg_tx_err(lp)) {
1870 printk(KERN_DEBUG " Ring data dump: dirty_tx %d cur_tx %d%s cur_rx %d.", 1926 int i;
1871 lp->dirty_tx, lp->cur_tx, lp->tx_full ? " (full)" : "", 1927 printk(KERN_DEBUG
1872 lp->cur_rx); 1928 " Ring data dump: dirty_tx %d cur_tx %d%s cur_rx %d.",
1873 for (i = 0 ; i < lp->rx_ring_size; i++) 1929 lp->dirty_tx, lp->cur_tx, lp->tx_full ? " (full)" : "",
1874 printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ", 1930 lp->cur_rx);
1875 le32_to_cpu(lp->rx_ring[i].base), 1931 for (i = 0; i < lp->rx_ring_size; i++)
1876 (-le16_to_cpu(lp->rx_ring[i].buf_length)) & 0xffff, 1932 printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ",
1877 le32_to_cpu(lp->rx_ring[i].msg_length), 1933 le32_to_cpu(lp->rx_ring[i].base),
1878 le16_to_cpu(lp->rx_ring[i].status)); 1934 (-le16_to_cpu(lp->rx_ring[i].buf_length)) &
1879 for (i = 0 ; i < lp->tx_ring_size; i++) 1935 0xffff, le32_to_cpu(lp->rx_ring[i].msg_length),
1880 printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ", 1936 le16_to_cpu(lp->rx_ring[i].status));
1881 le32_to_cpu(lp->tx_ring[i].base), 1937 for (i = 0; i < lp->tx_ring_size; i++)
1882 (-le16_to_cpu(lp->tx_ring[i].length)) & 0xffff, 1938 printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ",
1883 le32_to_cpu(lp->tx_ring[i].misc), 1939 le32_to_cpu(lp->tx_ring[i].base),
1884 le16_to_cpu(lp->tx_ring[i].status)); 1940 (-le16_to_cpu(lp->tx_ring[i].length)) & 0xffff,
1885 printk("\n"); 1941 le32_to_cpu(lp->tx_ring[i].misc),
1886 } 1942 le16_to_cpu(lp->tx_ring[i].status));
1887 pcnet32_restart(dev, 0x0042); 1943 printk("\n");
1888 1944 }
1889 dev->trans_start = jiffies; 1945 pcnet32_restart(dev, 0x0042);
1890 netif_wake_queue(dev); 1946
1891 1947 dev->trans_start = jiffies;
1892 spin_unlock_irqrestore(&lp->lock, flags); 1948 netif_wake_queue(dev);
1893}
1894 1949
1950 spin_unlock_irqrestore(&lp->lock, flags);
1951}
1895 1952
1896static int 1953static int pcnet32_start_xmit(struct sk_buff *skb, struct net_device *dev)
1897pcnet32_start_xmit(struct sk_buff *skb, struct net_device *dev)
1898{ 1954{
1899 struct pcnet32_private *lp = dev->priv; 1955 struct pcnet32_private *lp = dev->priv;
1900 unsigned long ioaddr = dev->base_addr; 1956 unsigned long ioaddr = dev->base_addr;
1901 u16 status; 1957 u16 status;
1902 int entry; 1958 int entry;
1903 unsigned long flags; 1959 unsigned long flags;
1904 1960
1905 spin_lock_irqsave(&lp->lock, flags); 1961 spin_lock_irqsave(&lp->lock, flags);
1906 1962
1907 if (netif_msg_tx_queued(lp)) { 1963 if (netif_msg_tx_queued(lp)) {
1908 printk(KERN_DEBUG "%s: pcnet32_start_xmit() called, csr0 %4.4x.\n", 1964 printk(KERN_DEBUG
1909 dev->name, lp->a.read_csr(ioaddr, 0)); 1965 "%s: pcnet32_start_xmit() called, csr0 %4.4x.\n",
1910 } 1966 dev->name, lp->a.read_csr(ioaddr, 0));
1967 }
1911 1968
1912 /* Default status -- will not enable Successful-TxDone 1969 /* Default status -- will not enable Successful-TxDone
1913 * interrupt when that option is available to us. 1970 * interrupt when that option is available to us.
1914 */ 1971 */
1915 status = 0x8300; 1972 status = 0x8300;
1916 1973
1917 /* Fill in a Tx ring entry */ 1974 /* Fill in a Tx ring entry */
1918 1975
1919 /* Mask to ring buffer boundary. */ 1976 /* Mask to ring buffer boundary. */
1920 entry = lp->cur_tx & lp->tx_mod_mask; 1977 entry = lp->cur_tx & lp->tx_mod_mask;
1921 1978
1922 /* Caution: the write order is important here, set the status 1979 /* Caution: the write order is important here, set the status
1923 * with the "ownership" bits last. */ 1980 * with the "ownership" bits last. */
1924 1981
1925 lp->tx_ring[entry].length = le16_to_cpu(-skb->len); 1982 lp->tx_ring[entry].length = le16_to_cpu(-skb->len);
1926 1983
1927 lp->tx_ring[entry].misc = 0x00000000; 1984 lp->tx_ring[entry].misc = 0x00000000;
1928 1985
1929 lp->tx_skbuff[entry] = skb; 1986 lp->tx_skbuff[entry] = skb;
1930 lp->tx_dma_addr[entry] = pci_map_single(lp->pci_dev, skb->data, skb->len, 1987 lp->tx_dma_addr[entry] =
1931 PCI_DMA_TODEVICE); 1988 pci_map_single(lp->pci_dev, skb->data, skb->len, PCI_DMA_TODEVICE);
1932 lp->tx_ring[entry].base = (u32)le32_to_cpu(lp->tx_dma_addr[entry]); 1989 lp->tx_ring[entry].base = (u32) le32_to_cpu(lp->tx_dma_addr[entry]);
1933 wmb(); /* Make sure owner changes after all others are visible */ 1990 wmb(); /* Make sure owner changes after all others are visible */
1934 lp->tx_ring[entry].status = le16_to_cpu(status); 1991 lp->tx_ring[entry].status = le16_to_cpu(status);
1935 1992
1936 lp->cur_tx++; 1993 lp->cur_tx++;
1937 lp->stats.tx_bytes += skb->len; 1994 lp->stats.tx_bytes += skb->len;
1938 1995
1939 /* Trigger an immediate send poll. */ 1996 /* Trigger an immediate send poll. */
1940 lp->a.write_csr (ioaddr, 0, 0x0048); 1997 lp->a.write_csr(ioaddr, 0, 0x0048);
1941 1998
1942 dev->trans_start = jiffies; 1999 dev->trans_start = jiffies;
1943 2000
1944 if (lp->tx_ring[(entry+1) & lp->tx_mod_mask].base != 0) { 2001 if (lp->tx_ring[(entry + 1) & lp->tx_mod_mask].base != 0) {
1945 lp->tx_full = 1; 2002 lp->tx_full = 1;
1946 netif_stop_queue(dev); 2003 netif_stop_queue(dev);
1947 } 2004 }
1948 spin_unlock_irqrestore(&lp->lock, flags); 2005 spin_unlock_irqrestore(&lp->lock, flags);
1949 return 0; 2006 return 0;
1950} 2007}
1951 2008
1952/* The PCNET32 interrupt handler. */ 2009/* The PCNET32 interrupt handler. */
1953static irqreturn_t 2010static irqreturn_t
1954pcnet32_interrupt(int irq, void *dev_id, struct pt_regs * regs) 2011pcnet32_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1955{ 2012{
1956 struct net_device *dev = dev_id; 2013 struct net_device *dev = dev_id;
1957 struct pcnet32_private *lp; 2014 struct pcnet32_private *lp;
1958 unsigned long ioaddr; 2015 unsigned long ioaddr;
1959 u16 csr0,rap; 2016 u16 csr0, rap;
1960 int boguscnt = max_interrupt_work; 2017 int boguscnt = max_interrupt_work;
1961 int must_restart; 2018 int must_restart;
1962 2019
1963 if (!dev) { 2020 if (!dev) {
1964 if (pcnet32_debug & NETIF_MSG_INTR) 2021 if (pcnet32_debug & NETIF_MSG_INTR)
1965 printk (KERN_DEBUG "%s(): irq %d for unknown device\n", 2022 printk(KERN_DEBUG "%s(): irq %d for unknown device\n",
1966 __FUNCTION__, irq); 2023 __FUNCTION__, irq);
1967 return IRQ_NONE; 2024 return IRQ_NONE;
1968 }
1969
1970 ioaddr = dev->base_addr;
1971 lp = dev->priv;
1972
1973 spin_lock(&lp->lock);
1974
1975 rap = lp->a.read_rap(ioaddr);
1976 while ((csr0 = lp->a.read_csr (ioaddr, 0)) & 0x8f00 && --boguscnt >= 0) {
1977 if (csr0 == 0xffff) {
1978 break; /* PCMCIA remove happened */
1979 } 2025 }
1980 /* Acknowledge all of the current interrupt sources ASAP. */
1981 lp->a.write_csr (ioaddr, 0, csr0 & ~0x004f);
1982 2026
1983 must_restart = 0; 2027 ioaddr = dev->base_addr;
2028 lp = dev->priv;
1984 2029
1985 if (netif_msg_intr(lp)) 2030 spin_lock(&lp->lock);
1986 printk(KERN_DEBUG "%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n", 2031
1987 dev->name, csr0, lp->a.read_csr (ioaddr, 0)); 2032 rap = lp->a.read_rap(ioaddr);
1988 2033 while ((csr0 = lp->a.read_csr(ioaddr, 0)) & 0x8f00 && --boguscnt >= 0) {
1989 if (csr0 & 0x0400) /* Rx interrupt */ 2034 if (csr0 == 0xffff) {
1990 pcnet32_rx(dev); 2035 break; /* PCMCIA remove happened */
1991 2036 }
1992 if (csr0 & 0x0200) { /* Tx-done interrupt */ 2037 /* Acknowledge all of the current interrupt sources ASAP. */
1993 unsigned int dirty_tx = lp->dirty_tx; 2038 lp->a.write_csr(ioaddr, 0, csr0 & ~0x004f);
1994 int delta; 2039
1995 2040 must_restart = 0;
1996 while (dirty_tx != lp->cur_tx) { 2041
1997 int entry = dirty_tx & lp->tx_mod_mask; 2042 if (netif_msg_intr(lp))
1998 int status = (short)le16_to_cpu(lp->tx_ring[entry].status); 2043 printk(KERN_DEBUG
1999 2044 "%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n",
2000 if (status < 0) 2045 dev->name, csr0, lp->a.read_csr(ioaddr, 0));
2001 break; /* It still hasn't been Txed */ 2046
2002 2047 if (csr0 & 0x0400) /* Rx interrupt */
2003 lp->tx_ring[entry].base = 0; 2048 pcnet32_rx(dev);
2004 2049
2005 if (status & 0x4000) { 2050 if (csr0 & 0x0200) { /* Tx-done interrupt */
2006 /* There was an major error, log it. */ 2051 unsigned int dirty_tx = lp->dirty_tx;
2007 int err_status = le32_to_cpu(lp->tx_ring[entry].misc); 2052 int delta;
2008 lp->stats.tx_errors++; 2053
2009 if (netif_msg_tx_err(lp)) 2054 while (dirty_tx != lp->cur_tx) {
2010 printk(KERN_ERR "%s: Tx error status=%04x err_status=%08x\n", 2055 int entry = dirty_tx & lp->tx_mod_mask;
2011 dev->name, status, err_status); 2056 int status =
2012 if (err_status & 0x04000000) lp->stats.tx_aborted_errors++; 2057 (short)le16_to_cpu(lp->tx_ring[entry].
2013 if (err_status & 0x08000000) lp->stats.tx_carrier_errors++; 2058 status);
2014 if (err_status & 0x10000000) lp->stats.tx_window_errors++; 2059
2060 if (status < 0)
2061 break; /* It still hasn't been Txed */
2062
2063 lp->tx_ring[entry].base = 0;
2064
2065 if (status & 0x4000) {
2066 /* There was an major error, log it. */
2067 int err_status =
2068 le32_to_cpu(lp->tx_ring[entry].
2069 misc);
2070 lp->stats.tx_errors++;
2071 if (netif_msg_tx_err(lp))
2072 printk(KERN_ERR
2073 "%s: Tx error status=%04x err_status=%08x\n",
2074 dev->name, status,
2075 err_status);
2076 if (err_status & 0x04000000)
2077 lp->stats.tx_aborted_errors++;
2078 if (err_status & 0x08000000)
2079 lp->stats.tx_carrier_errors++;
2080 if (err_status & 0x10000000)
2081 lp->stats.tx_window_errors++;
2015#ifndef DO_DXSUFLO 2082#ifndef DO_DXSUFLO
2016 if (err_status & 0x40000000) { 2083 if (err_status & 0x40000000) {
2017 lp->stats.tx_fifo_errors++; 2084 lp->stats.tx_fifo_errors++;
2018 /* Ackk! On FIFO errors the Tx unit is turned off! */ 2085 /* Ackk! On FIFO errors the Tx unit is turned off! */
2019 /* Remove this verbosity later! */ 2086 /* Remove this verbosity later! */
2020 if (netif_msg_tx_err(lp)) 2087 if (netif_msg_tx_err(lp))
2021 printk(KERN_ERR "%s: Tx FIFO error! CSR0=%4.4x\n", 2088 printk(KERN_ERR
2022 dev->name, csr0); 2089 "%s: Tx FIFO error! CSR0=%4.4x\n",
2023 must_restart = 1; 2090 dev->name, csr0);
2024 } 2091 must_restart = 1;
2092 }
2025#else 2093#else
2026 if (err_status & 0x40000000) { 2094 if (err_status & 0x40000000) {
2027 lp->stats.tx_fifo_errors++; 2095 lp->stats.tx_fifo_errors++;
2028 if (! lp->dxsuflo) { /* If controller doesn't recover ... */ 2096 if (!lp->dxsuflo) { /* If controller doesn't recover ... */
2029 /* Ackk! On FIFO errors the Tx unit is turned off! */ 2097 /* Ackk! On FIFO errors the Tx unit is turned off! */
2030 /* Remove this verbosity later! */ 2098 /* Remove this verbosity later! */
2031 if (netif_msg_tx_err(lp)) 2099 if (netif_msg_tx_err
2032 printk(KERN_ERR "%s: Tx FIFO error! CSR0=%4.4x\n", 2100 (lp))
2033 dev->name, csr0); 2101 printk(KERN_ERR
2034 must_restart = 1; 2102 "%s: Tx FIFO error! CSR0=%4.4x\n",
2035 } 2103 dev->
2036 } 2104 name,
2105 csr0);
2106 must_restart = 1;
2107 }
2108 }
2037#endif 2109#endif
2038 } else { 2110 } else {
2039 if (status & 0x1800) 2111 if (status & 0x1800)
2040 lp->stats.collisions++; 2112 lp->stats.collisions++;
2041 lp->stats.tx_packets++; 2113 lp->stats.tx_packets++;
2114 }
2115
2116 /* We must free the original skb */
2117 if (lp->tx_skbuff[entry]) {
2118 pci_unmap_single(lp->pci_dev,
2119 lp->tx_dma_addr[entry],
2120 lp->tx_skbuff[entry]->
2121 len, PCI_DMA_TODEVICE);
2122 dev_kfree_skb_irq(lp->tx_skbuff[entry]);
2123 lp->tx_skbuff[entry] = NULL;
2124 lp->tx_dma_addr[entry] = 0;
2125 }
2126 dirty_tx++;
2127 }
2128
2129 delta =
2130 (lp->cur_tx - dirty_tx) & (lp->tx_mod_mask +
2131 lp->tx_ring_size);
2132 if (delta > lp->tx_ring_size) {
2133 if (netif_msg_drv(lp))
2134 printk(KERN_ERR
2135 "%s: out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
2136 dev->name, dirty_tx, lp->cur_tx,
2137 lp->tx_full);
2138 dirty_tx += lp->tx_ring_size;
2139 delta -= lp->tx_ring_size;
2140 }
2141
2142 if (lp->tx_full &&
2143 netif_queue_stopped(dev) &&
2144 delta < lp->tx_ring_size - 2) {
2145 /* The ring is no longer full, clear tbusy. */
2146 lp->tx_full = 0;
2147 netif_wake_queue(dev);
2148 }
2149 lp->dirty_tx = dirty_tx;
2150 }
2151
2152 /* Log misc errors. */
2153 if (csr0 & 0x4000)
2154 lp->stats.tx_errors++; /* Tx babble. */
2155 if (csr0 & 0x1000) {
2156 /*
2157 * this happens when our receive ring is full. This shouldn't
2158 * be a problem as we will see normal rx interrupts for the frames
2159 * in the receive ring. But there are some PCI chipsets (I can
2160 * reproduce this on SP3G with Intel saturn chipset) which have
2161 * sometimes problems and will fill up the receive ring with
2162 * error descriptors. In this situation we don't get a rx
2163 * interrupt, but a missed frame interrupt sooner or later.
2164 * So we try to clean up our receive ring here.
2165 */
2166 pcnet32_rx(dev);
2167 lp->stats.rx_errors++; /* Missed a Rx frame. */
2168 }
2169 if (csr0 & 0x0800) {
2170 if (netif_msg_drv(lp))
2171 printk(KERN_ERR
2172 "%s: Bus master arbitration failure, status %4.4x.\n",
2173 dev->name, csr0);
2174 /* unlike for the lance, there is no restart needed */
2042 } 2175 }
2043 2176
2044 /* We must free the original skb */ 2177 if (must_restart) {
2045 if (lp->tx_skbuff[entry]) { 2178 /* reset the chip to clear the error condition, then restart */
2046 pci_unmap_single(lp->pci_dev, lp->tx_dma_addr[entry], 2179 lp->a.reset(ioaddr);
2047 lp->tx_skbuff[entry]->len, PCI_DMA_TODEVICE); 2180 lp->a.write_csr(ioaddr, 4, 0x0915);
2048 dev_kfree_skb_irq(lp->tx_skbuff[entry]); 2181 pcnet32_restart(dev, 0x0002);
2049 lp->tx_skbuff[entry] = NULL; 2182 netif_wake_queue(dev);
2050 lp->tx_dma_addr[entry] = 0;
2051 } 2183 }
2052 dirty_tx++; 2184 }
2053 } 2185
2054 2186 /* Set interrupt enable. */
2055 delta = (lp->cur_tx - dirty_tx) & (lp->tx_mod_mask + lp->tx_ring_size); 2187 lp->a.write_csr(ioaddr, 0, 0x0040);
2056 if (delta > lp->tx_ring_size) { 2188 lp->a.write_rap(ioaddr, rap);
2057 if (netif_msg_drv(lp)) 2189
2058 printk(KERN_ERR "%s: out-of-sync dirty pointer, %d vs. %d, full=%d.\n", 2190 if (netif_msg_intr(lp))
2059 dev->name, dirty_tx, lp->cur_tx, lp->tx_full); 2191 printk(KERN_DEBUG "%s: exiting interrupt, csr0=%#4.4x.\n",
2060 dirty_tx += lp->tx_ring_size; 2192 dev->name, lp->a.read_csr(ioaddr, 0));
2061 delta -= lp->tx_ring_size; 2193
2062 } 2194 spin_unlock(&lp->lock);
2063 2195
2064 if (lp->tx_full && 2196 return IRQ_HANDLED;
2065 netif_queue_stopped(dev) &&
2066 delta < lp->tx_ring_size - 2) {
2067 /* The ring is no longer full, clear tbusy. */
2068 lp->tx_full = 0;
2069 netif_wake_queue (dev);
2070 }
2071 lp->dirty_tx = dirty_tx;
2072 }
2073
2074 /* Log misc errors. */
2075 if (csr0 & 0x4000) lp->stats.tx_errors++; /* Tx babble. */
2076 if (csr0 & 0x1000) {
2077 /*
2078 * this happens when our receive ring is full. This shouldn't
2079 * be a problem as we will see normal rx interrupts for the frames
2080 * in the receive ring. But there are some PCI chipsets (I can
2081 * reproduce this on SP3G with Intel saturn chipset) which have
2082 * sometimes problems and will fill up the receive ring with
2083 * error descriptors. In this situation we don't get a rx
2084 * interrupt, but a missed frame interrupt sooner or later.
2085 * So we try to clean up our receive ring here.
2086 */
2087 pcnet32_rx(dev);
2088 lp->stats.rx_errors++; /* Missed a Rx frame. */
2089 }
2090 if (csr0 & 0x0800) {
2091 if (netif_msg_drv(lp))
2092 printk(KERN_ERR "%s: Bus master arbitration failure, status %4.4x.\n",
2093 dev->name, csr0);
2094 /* unlike for the lance, there is no restart needed */
2095 }
2096
2097 if (must_restart) {
2098 /* reset the chip to clear the error condition, then restart */
2099 lp->a.reset(ioaddr);
2100 lp->a.write_csr(ioaddr, 4, 0x0915);
2101 pcnet32_restart(dev, 0x0002);
2102 netif_wake_queue(dev);
2103 }
2104 }
2105
2106 /* Set interrupt enable. */
2107 lp->a.write_csr (ioaddr, 0, 0x0040);
2108 lp->a.write_rap (ioaddr,rap);
2109
2110 if (netif_msg_intr(lp))
2111 printk(KERN_DEBUG "%s: exiting interrupt, csr0=%#4.4x.\n",
2112 dev->name, lp->a.read_csr (ioaddr, 0));
2113
2114 spin_unlock(&lp->lock);
2115
2116 return IRQ_HANDLED;
2117} 2197}
2118 2198
2119static int 2199static int pcnet32_rx(struct net_device *dev)
2120pcnet32_rx(struct net_device *dev)
2121{ 2200{
2122 struct pcnet32_private *lp = dev->priv; 2201 struct pcnet32_private *lp = dev->priv;
2123 int entry = lp->cur_rx & lp->rx_mod_mask; 2202 int entry = lp->cur_rx & lp->rx_mod_mask;
2124 int boguscnt = lp->rx_ring_size / 2; 2203 int boguscnt = lp->rx_ring_size / 2;
2125 2204
2126 /* If we own the next entry, it's a new packet. Send it up. */ 2205 /* If we own the next entry, it's a new packet. Send it up. */
2127 while ((short)le16_to_cpu(lp->rx_ring[entry].status) >= 0) { 2206 while ((short)le16_to_cpu(lp->rx_ring[entry].status) >= 0) {
2128 int status = (short)le16_to_cpu(lp->rx_ring[entry].status) >> 8; 2207 int status = (short)le16_to_cpu(lp->rx_ring[entry].status) >> 8;
2129 2208
2130 if (status != 0x03) { /* There was an error. */ 2209 if (status != 0x03) { /* There was an error. */
2131 /* 2210 /*
2132 * There is a tricky error noted by John Murphy, 2211 * There is a tricky error noted by John Murphy,
2133 * <murf@perftech.com> to Russ Nelson: Even with full-sized 2212 * <murf@perftech.com> to Russ Nelson: Even with full-sized
2134 * buffers it's possible for a jabber packet to use two 2213 * buffers it's possible for a jabber packet to use two
2135 * buffers, with only the last correctly noting the error. 2214 * buffers, with only the last correctly noting the error.
2136 */ 2215 */
2137 if (status & 0x01) /* Only count a general error at the */ 2216 if (status & 0x01) /* Only count a general error at the */
2138 lp->stats.rx_errors++; /* end of a packet.*/ 2217 lp->stats.rx_errors++; /* end of a packet. */
2139 if (status & 0x20) lp->stats.rx_frame_errors++; 2218 if (status & 0x20)
2140 if (status & 0x10) lp->stats.rx_over_errors++; 2219 lp->stats.rx_frame_errors++;
2141 if (status & 0x08) lp->stats.rx_crc_errors++; 2220 if (status & 0x10)
2142 if (status & 0x04) lp->stats.rx_fifo_errors++; 2221 lp->stats.rx_over_errors++;
2143 lp->rx_ring[entry].status &= le16_to_cpu(0x03ff); 2222 if (status & 0x08)
2144 } else { 2223 lp->stats.rx_crc_errors++;
2145 /* Malloc up new buffer, compatible with net-2e. */ 2224 if (status & 0x04)
2146 short pkt_len = (le32_to_cpu(lp->rx_ring[entry].msg_length) & 0xfff)-4; 2225 lp->stats.rx_fifo_errors++;
2147 struct sk_buff *skb; 2226 lp->rx_ring[entry].status &= le16_to_cpu(0x03ff);
2148
2149 /* Discard oversize frames. */
2150 if (unlikely(pkt_len > PKT_BUF_SZ - 2)) {
2151 if (netif_msg_drv(lp))
2152 printk(KERN_ERR "%s: Impossible packet size %d!\n",
2153 dev->name, pkt_len);
2154 lp->stats.rx_errors++;
2155 } else if (pkt_len < 60) {
2156 if (netif_msg_rx_err(lp))
2157 printk(KERN_ERR "%s: Runt packet!\n", dev->name);
2158 lp->stats.rx_errors++;
2159 } else {
2160 int rx_in_place = 0;
2161
2162 if (pkt_len > rx_copybreak) {
2163 struct sk_buff *newskb;
2164
2165 if ((newskb = dev_alloc_skb(PKT_BUF_SZ))) {
2166 skb_reserve (newskb, 2);
2167 skb = lp->rx_skbuff[entry];
2168 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[entry],
2169 PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE);
2170 skb_put (skb, pkt_len);
2171 lp->rx_skbuff[entry] = newskb;
2172 newskb->dev = dev;
2173 lp->rx_dma_addr[entry] =
2174 pci_map_single(lp->pci_dev, newskb->data,
2175 PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE);
2176 lp->rx_ring[entry].base = le32_to_cpu(lp->rx_dma_addr[entry]);
2177 rx_in_place = 1;
2178 } else
2179 skb = NULL;
2180 } else { 2227 } else {
2181 skb = dev_alloc_skb(pkt_len+2); 2228 /* Malloc up new buffer, compatible with net-2e. */
2182 } 2229 short pkt_len =
2183 2230 (le32_to_cpu(lp->rx_ring[entry].msg_length) & 0xfff)
2184 if (skb == NULL) { 2231 - 4;
2185 int i; 2232 struct sk_buff *skb;
2186 if (netif_msg_drv(lp)) 2233
2187 printk(KERN_ERR "%s: Memory squeeze, deferring packet.\n", 2234 /* Discard oversize frames. */
2188 dev->name); 2235 if (unlikely(pkt_len > PKT_BUF_SZ - 2)) {
2189 for (i = 0; i < lp->rx_ring_size; i++) 2236 if (netif_msg_drv(lp))
2190 if ((short)le16_to_cpu(lp->rx_ring[(entry+i) 2237 printk(KERN_ERR
2191 & lp->rx_mod_mask].status) < 0) 2238 "%s: Impossible packet size %d!\n",
2192 break; 2239 dev->name, pkt_len);
2193 2240 lp->stats.rx_errors++;
2194 if (i > lp->rx_ring_size -2) { 2241 } else if (pkt_len < 60) {
2195 lp->stats.rx_dropped++; 2242 if (netif_msg_rx_err(lp))
2196 lp->rx_ring[entry].status |= le16_to_cpu(0x8000); 2243 printk(KERN_ERR "%s: Runt packet!\n",
2197 wmb(); /* Make sure adapter sees owner change */ 2244 dev->name);
2198 lp->cur_rx++; 2245 lp->stats.rx_errors++;
2199 } 2246 } else {
2200 break; 2247 int rx_in_place = 0;
2201 } 2248
2202 skb->dev = dev; 2249 if (pkt_len > rx_copybreak) {
2203 if (!rx_in_place) { 2250 struct sk_buff *newskb;
2204 skb_reserve(skb,2); /* 16 byte align */ 2251
2205 skb_put(skb,pkt_len); /* Make room */ 2252 if ((newskb =
2206 pci_dma_sync_single_for_cpu(lp->pci_dev, 2253 dev_alloc_skb(PKT_BUF_SZ))) {
2207 lp->rx_dma_addr[entry], 2254 skb_reserve(newskb, 2);
2208 PKT_BUF_SZ-2, 2255 skb = lp->rx_skbuff[entry];
2209 PCI_DMA_FROMDEVICE); 2256 pci_unmap_single(lp->pci_dev,
2210 eth_copy_and_sum(skb, 2257 lp->
2211 (unsigned char *)(lp->rx_skbuff[entry]->data), 2258 rx_dma_addr
2212 pkt_len,0); 2259 [entry],
2213 pci_dma_sync_single_for_device(lp->pci_dev, 2260 PKT_BUF_SZ - 2,
2214 lp->rx_dma_addr[entry], 2261 PCI_DMA_FROMDEVICE);
2215 PKT_BUF_SZ-2, 2262 skb_put(skb, pkt_len);
2216 PCI_DMA_FROMDEVICE); 2263 lp->rx_skbuff[entry] = newskb;
2264 newskb->dev = dev;
2265 lp->rx_dma_addr[entry] =
2266 pci_map_single(lp->pci_dev,
2267 newskb->data,
2268 PKT_BUF_SZ -
2269 2,
2270 PCI_DMA_FROMDEVICE);
2271 lp->rx_ring[entry].base =
2272 le32_to_cpu(lp->
2273 rx_dma_addr
2274 [entry]);
2275 rx_in_place = 1;
2276 } else
2277 skb = NULL;
2278 } else {
2279 skb = dev_alloc_skb(pkt_len + 2);
2280 }
2281
2282 if (skb == NULL) {
2283 int i;
2284 if (netif_msg_drv(lp))
2285 printk(KERN_ERR
2286 "%s: Memory squeeze, deferring packet.\n",
2287 dev->name);
2288 for (i = 0; i < lp->rx_ring_size; i++)
2289 if ((short)
2290 le16_to_cpu(lp->
2291 rx_ring[(entry +
2292 i)
2293 & lp->
2294 rx_mod_mask].
2295 status) < 0)
2296 break;
2297
2298 if (i > lp->rx_ring_size - 2) {
2299 lp->stats.rx_dropped++;
2300 lp->rx_ring[entry].status |=
2301 le16_to_cpu(0x8000);
2302 wmb(); /* Make sure adapter sees owner change */
2303 lp->cur_rx++;
2304 }
2305 break;
2306 }
2307 skb->dev = dev;
2308 if (!rx_in_place) {
2309 skb_reserve(skb, 2); /* 16 byte align */
2310 skb_put(skb, pkt_len); /* Make room */
2311 pci_dma_sync_single_for_cpu(lp->pci_dev,
2312 lp->
2313 rx_dma_addr
2314 [entry],
2315 PKT_BUF_SZ -
2316 2,
2317 PCI_DMA_FROMDEVICE);
2318 eth_copy_and_sum(skb,
2319 (unsigned char *)(lp->
2320 rx_skbuff
2321 [entry]->
2322 data),
2323 pkt_len, 0);
2324 pci_dma_sync_single_for_device(lp->
2325 pci_dev,
2326 lp->
2327 rx_dma_addr
2328 [entry],
2329 PKT_BUF_SZ
2330 - 2,
2331 PCI_DMA_FROMDEVICE);
2332 }
2333 lp->stats.rx_bytes += skb->len;
2334 skb->protocol = eth_type_trans(skb, dev);
2335 netif_rx(skb);
2336 dev->last_rx = jiffies;
2337 lp->stats.rx_packets++;
2338 }
2217 } 2339 }
2218 lp->stats.rx_bytes += skb->len; 2340 /*
2219 skb->protocol=eth_type_trans(skb,dev); 2341 * The docs say that the buffer length isn't touched, but Andrew Boyd
2220 netif_rx(skb); 2342 * of QNX reports that some revs of the 79C965 clear it.
2221 dev->last_rx = jiffies; 2343 */
2222 lp->stats.rx_packets++; 2344 lp->rx_ring[entry].buf_length = le16_to_cpu(2 - PKT_BUF_SZ);
2223 } 2345 wmb(); /* Make sure owner changes after all others are visible */
2346 lp->rx_ring[entry].status |= le16_to_cpu(0x8000);
2347 entry = (++lp->cur_rx) & lp->rx_mod_mask;
2348 if (--boguscnt <= 0)
2349 break; /* don't stay in loop forever */
2224 } 2350 }
2225 /* 2351
2226 * The docs say that the buffer length isn't touched, but Andrew Boyd 2352 return 0;
2227 * of QNX reports that some revs of the 79C965 clear it.
2228 */
2229 lp->rx_ring[entry].buf_length = le16_to_cpu(2-PKT_BUF_SZ);
2230 wmb(); /* Make sure owner changes after all others are visible */
2231 lp->rx_ring[entry].status |= le16_to_cpu(0x8000);
2232 entry = (++lp->cur_rx) & lp->rx_mod_mask;
2233 if (--boguscnt <= 0) break; /* don't stay in loop forever */
2234 }
2235
2236 return 0;
2237} 2353}
2238 2354
2239static int 2355static int pcnet32_close(struct net_device *dev)
2240pcnet32_close(struct net_device *dev)
2241{ 2356{
2242 unsigned long ioaddr = dev->base_addr; 2357 unsigned long ioaddr = dev->base_addr;
2243 struct pcnet32_private *lp = dev->priv; 2358 struct pcnet32_private *lp = dev->priv;
2244 int i; 2359 int i;
2245 unsigned long flags; 2360 unsigned long flags;
2246 2361
2247 del_timer_sync(&lp->watchdog_timer); 2362 del_timer_sync(&lp->watchdog_timer);
2248 2363
2249 netif_stop_queue(dev); 2364 netif_stop_queue(dev);
2250 2365
2251 spin_lock_irqsave(&lp->lock, flags); 2366 spin_lock_irqsave(&lp->lock, flags);
2252 2367
2253 lp->stats.rx_missed_errors = lp->a.read_csr (ioaddr, 112); 2368 lp->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
2254 2369
2255 if (netif_msg_ifdown(lp)) 2370 if (netif_msg_ifdown(lp))
2256 printk(KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n", 2371 printk(KERN_DEBUG
2257 dev->name, lp->a.read_csr (ioaddr, 0)); 2372 "%s: Shutting down ethercard, status was %2.2x.\n",
2373 dev->name, lp->a.read_csr(ioaddr, 0));
2258 2374
2259 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */ 2375 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */
2260 lp->a.write_csr (ioaddr, 0, 0x0004); 2376 lp->a.write_csr(ioaddr, 0, 0x0004);
2261 2377
2262 /* 2378 /*
2263 * Switch back to 16bit mode to avoid problems with dumb 2379 * Switch back to 16bit mode to avoid problems with dumb
2264 * DOS packet driver after a warm reboot 2380 * DOS packet driver after a warm reboot
2265 */ 2381 */
2266 lp->a.write_bcr (ioaddr, 20, 4); 2382 lp->a.write_bcr(ioaddr, 20, 4);
2267 2383
2268 spin_unlock_irqrestore(&lp->lock, flags); 2384 spin_unlock_irqrestore(&lp->lock, flags);
2269 2385
2270 free_irq(dev->irq, dev); 2386 free_irq(dev->irq, dev);
2271 2387
2272 spin_lock_irqsave(&lp->lock, flags); 2388 spin_lock_irqsave(&lp->lock, flags);
2273 2389
2274 /* free all allocated skbuffs */ 2390 /* free all allocated skbuffs */
2275 for (i = 0; i < lp->rx_ring_size; i++) { 2391 for (i = 0; i < lp->rx_ring_size; i++) {
2276 lp->rx_ring[i].status = 0; 2392 lp->rx_ring[i].status = 0;
2277 wmb(); /* Make sure adapter sees owner change */ 2393 wmb(); /* Make sure adapter sees owner change */
2278 if (lp->rx_skbuff[i]) { 2394 if (lp->rx_skbuff[i]) {
2279 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i], PKT_BUF_SZ-2, 2395 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i],
2280 PCI_DMA_FROMDEVICE); 2396 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
2281 dev_kfree_skb(lp->rx_skbuff[i]); 2397 dev_kfree_skb(lp->rx_skbuff[i]);
2398 }
2399 lp->rx_skbuff[i] = NULL;
2400 lp->rx_dma_addr[i] = 0;
2282 } 2401 }
2283 lp->rx_skbuff[i] = NULL;
2284 lp->rx_dma_addr[i] = 0;
2285 }
2286 2402
2287 for (i = 0; i < lp->tx_ring_size; i++) { 2403 for (i = 0; i < lp->tx_ring_size; i++) {
2288 lp->tx_ring[i].status = 0; /* CPU owns buffer */ 2404 lp->tx_ring[i].status = 0; /* CPU owns buffer */
2289 wmb(); /* Make sure adapter sees owner change */ 2405 wmb(); /* Make sure adapter sees owner change */
2290 if (lp->tx_skbuff[i]) { 2406 if (lp->tx_skbuff[i]) {
2291 pci_unmap_single(lp->pci_dev, lp->tx_dma_addr[i], 2407 pci_unmap_single(lp->pci_dev, lp->tx_dma_addr[i],
2292 lp->tx_skbuff[i]->len, PCI_DMA_TODEVICE); 2408 lp->tx_skbuff[i]->len,
2293 dev_kfree_skb(lp->tx_skbuff[i]); 2409 PCI_DMA_TODEVICE);
2410 dev_kfree_skb(lp->tx_skbuff[i]);
2411 }
2412 lp->tx_skbuff[i] = NULL;
2413 lp->tx_dma_addr[i] = 0;
2294 } 2414 }
2295 lp->tx_skbuff[i] = NULL;
2296 lp->tx_dma_addr[i] = 0;
2297 }
2298 2415
2299 spin_unlock_irqrestore(&lp->lock, flags); 2416 spin_unlock_irqrestore(&lp->lock, flags);
2300 2417
2301 return 0; 2418 return 0;
2302} 2419}
2303 2420
2304static struct net_device_stats * 2421static struct net_device_stats *pcnet32_get_stats(struct net_device *dev)
2305pcnet32_get_stats(struct net_device *dev)
2306{ 2422{
2307 struct pcnet32_private *lp = dev->priv; 2423 struct pcnet32_private *lp = dev->priv;
2308 unsigned long ioaddr = dev->base_addr; 2424 unsigned long ioaddr = dev->base_addr;
2309 u16 saved_addr; 2425 u16 saved_addr;
2310 unsigned long flags; 2426 unsigned long flags;
2311 2427
2312 spin_lock_irqsave(&lp->lock, flags); 2428 spin_lock_irqsave(&lp->lock, flags);
2313 saved_addr = lp->a.read_rap(ioaddr); 2429 saved_addr = lp->a.read_rap(ioaddr);
2314 lp->stats.rx_missed_errors = lp->a.read_csr (ioaddr, 112); 2430 lp->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
2315 lp->a.write_rap(ioaddr, saved_addr); 2431 lp->a.write_rap(ioaddr, saved_addr);
2316 spin_unlock_irqrestore(&lp->lock, flags); 2432 spin_unlock_irqrestore(&lp->lock, flags);
2317 2433
2318 return &lp->stats; 2434 return &lp->stats;
2319} 2435}
2320 2436
2321/* taken from the sunlance driver, which it took from the depca driver */ 2437/* taken from the sunlance driver, which it took from the depca driver */
2322static void pcnet32_load_multicast (struct net_device *dev) 2438static void pcnet32_load_multicast(struct net_device *dev)
2323{ 2439{
2324 struct pcnet32_private *lp = dev->priv; 2440 struct pcnet32_private *lp = dev->priv;
2325 volatile struct pcnet32_init_block *ib = &lp->init_block; 2441 volatile struct pcnet32_init_block *ib = &lp->init_block;
2326 volatile u16 *mcast_table = (u16 *)&ib->filter; 2442 volatile u16 *mcast_table = (u16 *) & ib->filter;
2327 struct dev_mc_list *dmi=dev->mc_list; 2443 struct dev_mc_list *dmi = dev->mc_list;
2328 char *addrs; 2444 char *addrs;
2329 int i; 2445 int i;
2330 u32 crc; 2446 u32 crc;
2331 2447
2332 /* set all multicast bits */ 2448 /* set all multicast bits */
2333 if (dev->flags & IFF_ALLMULTI) { 2449 if (dev->flags & IFF_ALLMULTI) {
2334 ib->filter[0] = 0xffffffff; 2450 ib->filter[0] = 0xffffffff;
2335 ib->filter[1] = 0xffffffff; 2451 ib->filter[1] = 0xffffffff;
2452 return;
2453 }
2454 /* clear the multicast filter */
2455 ib->filter[0] = 0;
2456 ib->filter[1] = 0;
2457
2458 /* Add addresses */
2459 for (i = 0; i < dev->mc_count; i++) {
2460 addrs = dmi->dmi_addr;
2461 dmi = dmi->next;
2462
2463 /* multicast address? */
2464 if (!(*addrs & 1))
2465 continue;
2466
2467 crc = ether_crc_le(6, addrs);
2468 crc = crc >> 26;
2469 mcast_table[crc >> 4] =
2470 le16_to_cpu(le16_to_cpu(mcast_table[crc >> 4]) |
2471 (1 << (crc & 0xf)));
2472 }
2336 return; 2473 return;
2337 }
2338 /* clear the multicast filter */
2339 ib->filter[0] = 0;
2340 ib->filter[1] = 0;
2341
2342 /* Add addresses */
2343 for (i = 0; i < dev->mc_count; i++) {
2344 addrs = dmi->dmi_addr;
2345 dmi = dmi->next;
2346
2347 /* multicast address? */
2348 if (!(*addrs & 1))
2349 continue;
2350
2351 crc = ether_crc_le(6, addrs);
2352 crc = crc >> 26;
2353 mcast_table [crc >> 4] = le16_to_cpu(
2354 le16_to_cpu(mcast_table [crc >> 4]) | (1 << (crc & 0xf)));
2355 }
2356 return;
2357} 2474}
2358 2475
2359
2360/* 2476/*
2361 * Set or clear the multicast filter for this adaptor. 2477 * Set or clear the multicast filter for this adaptor.
2362 */ 2478 */
2363static void pcnet32_set_multicast_list(struct net_device *dev) 2479static void pcnet32_set_multicast_list(struct net_device *dev)
2364{ 2480{
2365 unsigned long ioaddr = dev->base_addr, flags; 2481 unsigned long ioaddr = dev->base_addr, flags;
2366 struct pcnet32_private *lp = dev->priv; 2482 struct pcnet32_private *lp = dev->priv;
2367 2483
2368 spin_lock_irqsave(&lp->lock, flags); 2484 spin_lock_irqsave(&lp->lock, flags);
2369 if (dev->flags&IFF_PROMISC) { 2485 if (dev->flags & IFF_PROMISC) {
2370 /* Log any net taps. */ 2486 /* Log any net taps. */
2371 if (netif_msg_hw(lp)) 2487 if (netif_msg_hw(lp))
2372 printk(KERN_INFO "%s: Promiscuous mode enabled.\n", dev->name); 2488 printk(KERN_INFO "%s: Promiscuous mode enabled.\n",
2373 lp->init_block.mode = le16_to_cpu(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) << 7); 2489 dev->name);
2374 } else { 2490 lp->init_block.mode =
2375 lp->init_block.mode = le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7); 2491 le16_to_cpu(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
2376 pcnet32_load_multicast (dev); 2492 7);
2377 } 2493 } else {
2378 2494 lp->init_block.mode =
2379 lp->a.write_csr (ioaddr, 0, 0x0004); /* Temporarily stop the lance. */ 2495 le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);
2380 pcnet32_restart(dev, 0x0042); /* Resume normal operation */ 2496 pcnet32_load_multicast(dev);
2381 netif_wake_queue(dev); 2497 }
2382 2498
2383 spin_unlock_irqrestore(&lp->lock, flags); 2499 lp->a.write_csr(ioaddr, 0, 0x0004); /* Temporarily stop the lance. */
2500 pcnet32_restart(dev, 0x0042); /* Resume normal operation */
2501 netif_wake_queue(dev);
2502
2503 spin_unlock_irqrestore(&lp->lock, flags);
2384} 2504}
2385 2505
2386/* This routine assumes that the lp->lock is held */ 2506/* This routine assumes that the lp->lock is held */
2387static int mdio_read(struct net_device *dev, int phy_id, int reg_num) 2507static int mdio_read(struct net_device *dev, int phy_id, int reg_num)
2388{ 2508{
2389 struct pcnet32_private *lp = dev->priv; 2509 struct pcnet32_private *lp = dev->priv;
2390 unsigned long ioaddr = dev->base_addr; 2510 unsigned long ioaddr = dev->base_addr;
2391 u16 val_out; 2511 u16 val_out;
2392 2512
2393 if (!lp->mii) 2513 if (!lp->mii)
2394 return 0; 2514 return 0;
2395 2515
2396 lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f)); 2516 lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
2397 val_out = lp->a.read_bcr(ioaddr, 34); 2517 val_out = lp->a.read_bcr(ioaddr, 34);
2398 2518
2399 return val_out; 2519 return val_out;
2400} 2520}
2401 2521
2402/* This routine assumes that the lp->lock is held */ 2522/* This routine assumes that the lp->lock is held */
2403static void mdio_write(struct net_device *dev, int phy_id, int reg_num, int val) 2523static void mdio_write(struct net_device *dev, int phy_id, int reg_num, int val)
2404{ 2524{
2405 struct pcnet32_private *lp = dev->priv; 2525 struct pcnet32_private *lp = dev->priv;
2406 unsigned long ioaddr = dev->base_addr; 2526 unsigned long ioaddr = dev->base_addr;
2407 2527
2408 if (!lp->mii) 2528 if (!lp->mii)
2409 return; 2529 return;
2410 2530
2411 lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f)); 2531 lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
2412 lp->a.write_bcr(ioaddr, 34, val); 2532 lp->a.write_bcr(ioaddr, 34, val);
2413} 2533}
2414 2534
2415static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 2535static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2416{ 2536{
2417 struct pcnet32_private *lp = dev->priv; 2537 struct pcnet32_private *lp = dev->priv;
2418 int rc; 2538 int rc;
2419 unsigned long flags; 2539 unsigned long flags;
2540
2541 /* SIOC[GS]MIIxxx ioctls */
2542 if (lp->mii) {
2543 spin_lock_irqsave(&lp->lock, flags);
2544 rc = generic_mii_ioctl(&lp->mii_if, if_mii(rq), cmd, NULL);
2545 spin_unlock_irqrestore(&lp->lock, flags);
2546 } else {
2547 rc = -EOPNOTSUPP;
2548 }
2549
2550 return rc;
2551}
2552
2553static int pcnet32_check_otherphy(struct net_device *dev)
2554{
2555 struct pcnet32_private *lp = dev->priv;
2556 struct mii_if_info mii = lp->mii_if;
2557 u16 bmcr;
2558 int i;
2420 2559
2421 /* SIOC[GS]MIIxxx ioctls */ 2560 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
2422 if (lp->mii) { 2561 if (i == lp->mii_if.phy_id)
2423 spin_lock_irqsave(&lp->lock, flags); 2562 continue; /* skip active phy */
2424 rc = generic_mii_ioctl(&lp->mii_if, if_mii(rq), cmd, NULL); 2563 if (lp->phymask & (1 << i)) {
2425 spin_unlock_irqrestore(&lp->lock, flags); 2564 mii.phy_id = i;
2426 } else { 2565 if (mii_link_ok(&mii)) {
2427 rc = -EOPNOTSUPP; 2566 /* found PHY with active link */
2428 } 2567 if (netif_msg_link(lp))
2568 printk(KERN_INFO
2569 "%s: Using PHY number %d.\n",
2570 dev->name, i);
2571
2572 /* isolate inactive phy */
2573 bmcr =
2574 mdio_read(dev, lp->mii_if.phy_id, MII_BMCR);
2575 mdio_write(dev, lp->mii_if.phy_id, MII_BMCR,
2576 bmcr | BMCR_ISOLATE);
2577
2578 /* de-isolate new phy */
2579 bmcr = mdio_read(dev, i, MII_BMCR);
2580 mdio_write(dev, i, MII_BMCR,
2581 bmcr & ~BMCR_ISOLATE);
2582
2583 /* set new phy address */
2584 lp->mii_if.phy_id = i;
2585 return 1;
2586 }
2587 }
2588 }
2589 return 0;
2590}
2591
2592/*
2593 * Show the status of the media. Similar to mii_check_media however it
2594 * correctly shows the link speed for all (tested) pcnet32 variants.
2595 * Devices with no mii just report link state without speed.
2596 *
2597 * Caller is assumed to hold and release the lp->lock.
2598 */
2429 2599
2430 return rc; 2600static void pcnet32_check_media(struct net_device *dev, int verbose)
2601{
2602 struct pcnet32_private *lp = dev->priv;
2603 int curr_link;
2604 int prev_link = netif_carrier_ok(dev) ? 1 : 0;
2605 u32 bcr9;
2606
2607 if (lp->mii) {
2608 curr_link = mii_link_ok(&lp->mii_if);
2609 } else {
2610 ulong ioaddr = dev->base_addr; /* card base I/O address */
2611 curr_link = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
2612 }
2613 if (!curr_link) {
2614 if (prev_link || verbose) {
2615 netif_carrier_off(dev);
2616 if (netif_msg_link(lp))
2617 printk(KERN_INFO "%s: link down\n", dev->name);
2618 }
2619 if (lp->phycount > 1) {
2620 curr_link = pcnet32_check_otherphy(dev);
2621 prev_link = 0;
2622 }
2623 } else if (verbose || !prev_link) {
2624 netif_carrier_on(dev);
2625 if (lp->mii) {
2626 if (netif_msg_link(lp)) {
2627 struct ethtool_cmd ecmd;
2628 mii_ethtool_gset(&lp->mii_if, &ecmd);
2629 printk(KERN_INFO
2630 "%s: link up, %sMbps, %s-duplex\n",
2631 dev->name,
2632 (ecmd.speed == SPEED_100) ? "100" : "10",
2633 (ecmd.duplex ==
2634 DUPLEX_FULL) ? "full" : "half");
2635 }
2636 bcr9 = lp->a.read_bcr(dev->base_addr, 9);
2637 if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) {
2638 if (lp->mii_if.full_duplex)
2639 bcr9 |= (1 << 0);
2640 else
2641 bcr9 &= ~(1 << 0);
2642 lp->a.write_bcr(dev->base_addr, 9, bcr9);
2643 }
2644 } else {
2645 if (netif_msg_link(lp))
2646 printk(KERN_INFO "%s: link up\n", dev->name);
2647 }
2648 }
2431} 2649}
2432 2650
2651/*
2652 * Check for loss of link and link establishment.
2653 * Can not use mii_check_media because it does nothing if mode is forced.
2654 */
2655
2433static void pcnet32_watchdog(struct net_device *dev) 2656static void pcnet32_watchdog(struct net_device *dev)
2434{ 2657{
2435 struct pcnet32_private *lp = dev->priv; 2658 struct pcnet32_private *lp = dev->priv;
2436 unsigned long flags; 2659 unsigned long flags;
2437 2660
2438 /* Print the link status if it has changed */ 2661 /* Print the link status if it has changed */
2439 if (lp->mii) {
2440 spin_lock_irqsave(&lp->lock, flags); 2662 spin_lock_irqsave(&lp->lock, flags);
2441 mii_check_media (&lp->mii_if, netif_msg_link(lp), 0); 2663 pcnet32_check_media(dev, 0);
2442 spin_unlock_irqrestore(&lp->lock, flags); 2664 spin_unlock_irqrestore(&lp->lock, flags);
2443 }
2444 2665
2445 mod_timer (&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT); 2666 mod_timer(&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT);
2446} 2667}
2447 2668
2448static void __devexit pcnet32_remove_one(struct pci_dev *pdev) 2669static void __devexit pcnet32_remove_one(struct pci_dev *pdev)
2449{ 2670{
2450 struct net_device *dev = pci_get_drvdata(pdev); 2671 struct net_device *dev = pci_get_drvdata(pdev);
2451 2672
2452 if (dev) { 2673 if (dev) {
2453 struct pcnet32_private *lp = dev->priv; 2674 struct pcnet32_private *lp = dev->priv;
2454 2675
2455 unregister_netdev(dev); 2676 unregister_netdev(dev);
2456 pcnet32_free_ring(dev); 2677 pcnet32_free_ring(dev);
2457 release_region(dev->base_addr, PCNET32_TOTAL_SIZE); 2678 release_region(dev->base_addr, PCNET32_TOTAL_SIZE);
2458 pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr); 2679 pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr);
2459 free_netdev(dev); 2680 free_netdev(dev);
2460 pci_disable_device(pdev); 2681 pci_disable_device(pdev);
2461 pci_set_drvdata(pdev, NULL); 2682 pci_set_drvdata(pdev, NULL);
2462 } 2683 }
2463} 2684}
2464 2685
2465static struct pci_driver pcnet32_driver = { 2686static struct pci_driver pcnet32_driver = {
2466 .name = DRV_NAME, 2687 .name = DRV_NAME,
2467 .probe = pcnet32_probe_pci, 2688 .probe = pcnet32_probe_pci,
2468 .remove = __devexit_p(pcnet32_remove_one), 2689 .remove = __devexit_p(pcnet32_remove_one),
2469 .id_table = pcnet32_pci_tbl, 2690 .id_table = pcnet32_pci_tbl,
2470}; 2691};
2471 2692
2472/* An additional parameter that may be passed in... */ 2693/* An additional parameter that may be passed in... */
@@ -2477,9 +2698,11 @@ static int pcnet32_have_pci;
2477module_param(debug, int, 0); 2698module_param(debug, int, 0);
2478MODULE_PARM_DESC(debug, DRV_NAME " debug level"); 2699MODULE_PARM_DESC(debug, DRV_NAME " debug level");
2479module_param(max_interrupt_work, int, 0); 2700module_param(max_interrupt_work, int, 0);
2480MODULE_PARM_DESC(max_interrupt_work, DRV_NAME " maximum events handled per interrupt"); 2701MODULE_PARM_DESC(max_interrupt_work,
2702 DRV_NAME " maximum events handled per interrupt");
2481module_param(rx_copybreak, int, 0); 2703module_param(rx_copybreak, int, 0);
2482MODULE_PARM_DESC(rx_copybreak, DRV_NAME " copy breakpoint for copy-only-tiny-frames"); 2704MODULE_PARM_DESC(rx_copybreak,
2705 DRV_NAME " copy breakpoint for copy-only-tiny-frames");
2483module_param(tx_start_pt, int, 0); 2706module_param(tx_start_pt, int, 0);
2484MODULE_PARM_DESC(tx_start_pt, DRV_NAME " transmit start point (0-3)"); 2707MODULE_PARM_DESC(tx_start_pt, DRV_NAME " transmit start point (0-3)");
2485module_param(pcnet32vlb, int, 0); 2708module_param(pcnet32vlb, int, 0);
@@ -2490,7 +2713,9 @@ module_param_array(full_duplex, int, NULL, 0);
2490MODULE_PARM_DESC(full_duplex, DRV_NAME " full duplex setting(s) (1)"); 2713MODULE_PARM_DESC(full_duplex, DRV_NAME " full duplex setting(s) (1)");
2491/* Module Parameter for HomePNA cards added by Patrick Simmons, 2004 */ 2714/* Module Parameter for HomePNA cards added by Patrick Simmons, 2004 */
2492module_param_array(homepna, int, NULL, 0); 2715module_param_array(homepna, int, NULL, 0);
2493MODULE_PARM_DESC(homepna, DRV_NAME " mode for 79C978 cards (1 for HomePNA, 0 for Ethernet, default Ethernet"); 2716MODULE_PARM_DESC(homepna,
2717 DRV_NAME
2718 " mode for 79C978 cards (1 for HomePNA, 0 for Ethernet, default Ethernet");
2494 2719
2495MODULE_AUTHOR("Thomas Bogendoerfer"); 2720MODULE_AUTHOR("Thomas Bogendoerfer");
2496MODULE_DESCRIPTION("Driver for PCnet32 and PCnetPCI based ethercards"); 2721MODULE_DESCRIPTION("Driver for PCnet32 and PCnetPCI based ethercards");
@@ -2500,44 +2725,44 @@ MODULE_LICENSE("GPL");
2500 2725
2501static int __init pcnet32_init_module(void) 2726static int __init pcnet32_init_module(void)
2502{ 2727{
2503 printk(KERN_INFO "%s", version); 2728 printk(KERN_INFO "%s", version);
2504 2729
2505 pcnet32_debug = netif_msg_init(debug, PCNET32_MSG_DEFAULT); 2730 pcnet32_debug = netif_msg_init(debug, PCNET32_MSG_DEFAULT);
2506 2731
2507 if ((tx_start_pt >= 0) && (tx_start_pt <= 3)) 2732 if ((tx_start_pt >= 0) && (tx_start_pt <= 3))
2508 tx_start = tx_start_pt; 2733 tx_start = tx_start_pt;
2509 2734
2510 /* find the PCI devices */ 2735 /* find the PCI devices */
2511 if (!pci_module_init(&pcnet32_driver)) 2736 if (!pci_module_init(&pcnet32_driver))
2512 pcnet32_have_pci = 1; 2737 pcnet32_have_pci = 1;
2513 2738
2514 /* should we find any remaining VLbus devices ? */ 2739 /* should we find any remaining VLbus devices ? */
2515 if (pcnet32vlb) 2740 if (pcnet32vlb)
2516 pcnet32_probe_vlbus(); 2741 pcnet32_probe_vlbus();
2517 2742
2518 if (cards_found && (pcnet32_debug & NETIF_MSG_PROBE)) 2743 if (cards_found && (pcnet32_debug & NETIF_MSG_PROBE))
2519 printk(KERN_INFO PFX "%d cards_found.\n", cards_found); 2744 printk(KERN_INFO PFX "%d cards_found.\n", cards_found);
2520 2745
2521 return (pcnet32_have_pci + cards_found) ? 0 : -ENODEV; 2746 return (pcnet32_have_pci + cards_found) ? 0 : -ENODEV;
2522} 2747}
2523 2748
2524static void __exit pcnet32_cleanup_module(void) 2749static void __exit pcnet32_cleanup_module(void)
2525{ 2750{
2526 struct net_device *next_dev; 2751 struct net_device *next_dev;
2527 2752
2528 while (pcnet32_dev) { 2753 while (pcnet32_dev) {
2529 struct pcnet32_private *lp = pcnet32_dev->priv; 2754 struct pcnet32_private *lp = pcnet32_dev->priv;
2530 next_dev = lp->next; 2755 next_dev = lp->next;
2531 unregister_netdev(pcnet32_dev); 2756 unregister_netdev(pcnet32_dev);
2532 pcnet32_free_ring(pcnet32_dev); 2757 pcnet32_free_ring(pcnet32_dev);
2533 release_region(pcnet32_dev->base_addr, PCNET32_TOTAL_SIZE); 2758 release_region(pcnet32_dev->base_addr, PCNET32_TOTAL_SIZE);
2534 pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr); 2759 pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr);
2535 free_netdev(pcnet32_dev); 2760 free_netdev(pcnet32_dev);
2536 pcnet32_dev = next_dev; 2761 pcnet32_dev = next_dev;
2537 } 2762 }
2538 2763
2539 if (pcnet32_have_pci) 2764 if (pcnet32_have_pci)
2540 pci_unregister_driver(&pcnet32_driver); 2765 pci_unregister_driver(&pcnet32_driver);
2541} 2766}
2542 2767
2543module_init(pcnet32_init_module); 2768module_init(pcnet32_init_module);
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 0245e40b51a1..f608c12e3e8b 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -1691,8 +1691,8 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
1691 || ppp->npmode[npi] != NPMODE_PASS) { 1691 || ppp->npmode[npi] != NPMODE_PASS) {
1692 kfree_skb(skb); 1692 kfree_skb(skb);
1693 } else { 1693 } else {
1694 skb_pull(skb, 2); /* chop off protocol */ 1694 /* chop off protocol */
1695 skb_postpull_rcsum(skb, skb->data - 2, 2); 1695 skb_pull_rcsum(skb, 2);
1696 skb->dev = ppp->dev; 1696 skb->dev = ppp->dev;
1697 skb->protocol = htons(npindex_to_ethertype[npi]); 1697 skb->protocol = htons(npindex_to_ethertype[npi]);
1698 skb->mac.raw = skb->data; 1698 skb->mac.raw = skb->data;
diff --git a/drivers/net/pppoe.c b/drivers/net/pppoe.c
index 9369f811075d..475dc930380f 100644
--- a/drivers/net/pppoe.c
+++ b/drivers/net/pppoe.c
@@ -337,8 +337,7 @@ static int pppoe_rcv_core(struct sock *sk, struct sk_buff *skb)
337 if (sk->sk_state & PPPOX_BOUND) { 337 if (sk->sk_state & PPPOX_BOUND) {
338 struct pppoe_hdr *ph = (struct pppoe_hdr *) skb->nh.raw; 338 struct pppoe_hdr *ph = (struct pppoe_hdr *) skb->nh.raw;
339 int len = ntohs(ph->length); 339 int len = ntohs(ph->length);
340 skb_pull(skb, sizeof(struct pppoe_hdr)); 340 skb_pull_rcsum(skb, sizeof(struct pppoe_hdr));
341 skb_postpull_rcsum(skb, ph, sizeof(*ph));
342 if (pskb_trim_rcsum(skb, len)) 341 if (pskb_trim_rcsum(skb, len))
343 goto abort_kfree; 342 goto abort_kfree;
344 343
diff --git a/drivers/net/skfp/fplustm.c b/drivers/net/skfp/fplustm.c
index a4b2b6975d6c..0784f558ca9a 100644
--- a/drivers/net/skfp/fplustm.c
+++ b/drivers/net/skfp/fplustm.c
@@ -549,12 +549,12 @@ void formac_tx_restart(struct s_smc *smc)
549static void enable_formac(struct s_smc *smc) 549static void enable_formac(struct s_smc *smc)
550{ 550{
551 /* set formac IMSK : 0 enables irq */ 551 /* set formac IMSK : 0 enables irq */
552 outpw(FM_A(FM_IMSK1U),~mac_imsk1u) ; 552 outpw(FM_A(FM_IMSK1U),(unsigned short)~mac_imsk1u);
553 outpw(FM_A(FM_IMSK1L),~mac_imsk1l) ; 553 outpw(FM_A(FM_IMSK1L),(unsigned short)~mac_imsk1l);
554 outpw(FM_A(FM_IMSK2U),~mac_imsk2u) ; 554 outpw(FM_A(FM_IMSK2U),(unsigned short)~mac_imsk2u);
555 outpw(FM_A(FM_IMSK2L),~mac_imsk2l) ; 555 outpw(FM_A(FM_IMSK2L),(unsigned short)~mac_imsk2l);
556 outpw(FM_A(FM_IMSK3U),~mac_imsk3u) ; 556 outpw(FM_A(FM_IMSK3U),(unsigned short)~mac_imsk3u);
557 outpw(FM_A(FM_IMSK3L),~mac_imsk3l) ; 557 outpw(FM_A(FM_IMSK3L),(unsigned short)~mac_imsk3l);
558} 558}
559 559
560#if 0 /* Removed because the driver should use the ASICs TX complete IRQ. */ 560#if 0 /* Removed because the driver should use the ASICs TX complete IRQ. */
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index 25e028b7ce48..4eda81d41b10 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -44,7 +44,7 @@
44#include "skge.h" 44#include "skge.h"
45 45
46#define DRV_NAME "skge" 46#define DRV_NAME "skge"
47#define DRV_VERSION "1.3" 47#define DRV_VERSION "1.4"
48#define PFX DRV_NAME " " 48#define PFX DRV_NAME " "
49 49
50#define DEFAULT_TX_RING_SIZE 128 50#define DEFAULT_TX_RING_SIZE 128
@@ -104,7 +104,6 @@ static const int txqaddr[] = { Q_XA1, Q_XA2 };
104static const int rxqaddr[] = { Q_R1, Q_R2 }; 104static const int rxqaddr[] = { Q_R1, Q_R2 };
105static const u32 rxirqmask[] = { IS_R1_F, IS_R2_F }; 105static const u32 rxirqmask[] = { IS_R1_F, IS_R2_F };
106static const u32 txirqmask[] = { IS_XA1_F, IS_XA2_F }; 106static const u32 txirqmask[] = { IS_XA1_F, IS_XA2_F };
107static const u32 portirqmask[] = { IS_PORT_1, IS_PORT_2 };
108 107
109static int skge_get_regs_len(struct net_device *dev) 108static int skge_get_regs_len(struct net_device *dev)
110{ 109{
@@ -728,19 +727,18 @@ static struct ethtool_ops skge_ethtool_ops = {
728 * Allocate ring elements and chain them together 727 * Allocate ring elements and chain them together
729 * One-to-one association of board descriptors with ring elements 728 * One-to-one association of board descriptors with ring elements
730 */ 729 */
731static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u64 base) 730static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u32 base)
732{ 731{
733 struct skge_tx_desc *d; 732 struct skge_tx_desc *d;
734 struct skge_element *e; 733 struct skge_element *e;
735 int i; 734 int i;
736 735
737 ring->start = kmalloc(sizeof(*e)*ring->count, GFP_KERNEL); 736 ring->start = kcalloc(sizeof(*e), ring->count, GFP_KERNEL);
738 if (!ring->start) 737 if (!ring->start)
739 return -ENOMEM; 738 return -ENOMEM;
740 739
741 for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) { 740 for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) {
742 e->desc = d; 741 e->desc = d;
743 e->skb = NULL;
744 if (i == ring->count - 1) { 742 if (i == ring->count - 1) {
745 e->next = ring->start; 743 e->next = ring->start;
746 d->next_offset = base; 744 d->next_offset = base;
@@ -2169,27 +2167,31 @@ static int skge_up(struct net_device *dev)
2169 if (!skge->mem) 2167 if (!skge->mem)
2170 return -ENOMEM; 2168 return -ENOMEM;
2171 2169
2170 BUG_ON(skge->dma & 7);
2171
2172 if ((u64)skge->dma >> 32 != ((u64) skge->dma + skge->mem_size) >> 32) {
2173 printk(KERN_ERR PFX "pci_alloc_consistent region crosses 4G boundary\n");
2174 err = -EINVAL;
2175 goto free_pci_mem;
2176 }
2177
2172 memset(skge->mem, 0, skge->mem_size); 2178 memset(skge->mem, 0, skge->mem_size);
2173 2179
2174 if ((err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma))) 2180 err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma);
2181 if (err)
2175 goto free_pci_mem; 2182 goto free_pci_mem;
2176 2183
2177 err = skge_rx_fill(skge); 2184 err = skge_rx_fill(skge);
2178 if (err) 2185 if (err)
2179 goto free_rx_ring; 2186 goto free_rx_ring;
2180 2187
2181 if ((err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size, 2188 err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size,
2182 skge->dma + rx_size))) 2189 skge->dma + rx_size);
2190 if (err)
2183 goto free_rx_ring; 2191 goto free_rx_ring;
2184 2192
2185 skge->tx_avail = skge->tx_ring.count - 1; 2193 skge->tx_avail = skge->tx_ring.count - 1;
2186 2194
2187 /* Enable IRQ from port */
2188 spin_lock_irq(&hw->hw_lock);
2189 hw->intr_mask |= portirqmask[port];
2190 skge_write32(hw, B0_IMSK, hw->intr_mask);
2191 spin_unlock_irq(&hw->hw_lock);
2192
2193 /* Initialize MAC */ 2195 /* Initialize MAC */
2194 spin_lock_bh(&hw->phy_lock); 2196 spin_lock_bh(&hw->phy_lock);
2195 if (hw->chip_id == CHIP_ID_GENESIS) 2197 if (hw->chip_id == CHIP_ID_GENESIS)
@@ -2246,11 +2248,6 @@ static int skge_down(struct net_device *dev)
2246 else 2248 else
2247 yukon_stop(skge); 2249 yukon_stop(skge);
2248 2250
2249 spin_lock_irq(&hw->hw_lock);
2250 hw->intr_mask &= ~portirqmask[skge->port];
2251 skge_write32(hw, B0_IMSK, hw->intr_mask);
2252 spin_unlock_irq(&hw->hw_lock);
2253
2254 /* Stop transmitter */ 2251 /* Stop transmitter */
2255 skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP); 2252 skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP);
2256 skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), 2253 skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL),
@@ -2307,18 +2304,15 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
2307 int i; 2304 int i;
2308 u32 control, len; 2305 u32 control, len;
2309 u64 map; 2306 u64 map;
2310 unsigned long flags;
2311 2307
2312 skb = skb_padto(skb, ETH_ZLEN); 2308 skb = skb_padto(skb, ETH_ZLEN);
2313 if (!skb) 2309 if (!skb)
2314 return NETDEV_TX_OK; 2310 return NETDEV_TX_OK;
2315 2311
2316 local_irq_save(flags);
2317 if (!spin_trylock(&skge->tx_lock)) { 2312 if (!spin_trylock(&skge->tx_lock)) {
2318 /* Collision - tell upper layer to requeue */ 2313 /* Collision - tell upper layer to requeue */
2319 local_irq_restore(flags); 2314 return NETDEV_TX_LOCKED;
2320 return NETDEV_TX_LOCKED; 2315 }
2321 }
2322 2316
2323 if (unlikely(skge->tx_avail < skb_shinfo(skb)->nr_frags +1)) { 2317 if (unlikely(skge->tx_avail < skb_shinfo(skb)->nr_frags +1)) {
2324 if (!netif_queue_stopped(dev)) { 2318 if (!netif_queue_stopped(dev)) {
@@ -2327,7 +2321,7 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
2327 printk(KERN_WARNING PFX "%s: ring full when queue awake!\n", 2321 printk(KERN_WARNING PFX "%s: ring full when queue awake!\n",
2328 dev->name); 2322 dev->name);
2329 } 2323 }
2330 spin_unlock_irqrestore(&skge->tx_lock, flags); 2324 spin_unlock(&skge->tx_lock);
2331 return NETDEV_TX_BUSY; 2325 return NETDEV_TX_BUSY;
2332 } 2326 }
2333 2327
@@ -2402,8 +2396,10 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
2402 netif_stop_queue(dev); 2396 netif_stop_queue(dev);
2403 } 2397 }
2404 2398
2399 mmiowb();
2400 spin_unlock(&skge->tx_lock);
2401
2405 dev->trans_start = jiffies; 2402 dev->trans_start = jiffies;
2406 spin_unlock_irqrestore(&skge->tx_lock, flags);
2407 2403
2408 return NETDEV_TX_OK; 2404 return NETDEV_TX_OK;
2409} 2405}
@@ -2416,7 +2412,7 @@ static inline void skge_tx_free(struct skge_hw *hw, struct skge_element *e)
2416 pci_unmap_addr(e, mapaddr), 2412 pci_unmap_addr(e, mapaddr),
2417 pci_unmap_len(e, maplen), 2413 pci_unmap_len(e, maplen),
2418 PCI_DMA_TODEVICE); 2414 PCI_DMA_TODEVICE);
2419 dev_kfree_skb_any(e->skb); 2415 dev_kfree_skb(e->skb);
2420 e->skb = NULL; 2416 e->skb = NULL;
2421 } else { 2417 } else {
2422 pci_unmap_page(hw->pdev, 2418 pci_unmap_page(hw->pdev,
@@ -2430,15 +2426,14 @@ static void skge_tx_clean(struct skge_port *skge)
2430{ 2426{
2431 struct skge_ring *ring = &skge->tx_ring; 2427 struct skge_ring *ring = &skge->tx_ring;
2432 struct skge_element *e; 2428 struct skge_element *e;
2433 unsigned long flags;
2434 2429
2435 spin_lock_irqsave(&skge->tx_lock, flags); 2430 spin_lock_bh(&skge->tx_lock);
2436 for (e = ring->to_clean; e != ring->to_use; e = e->next) { 2431 for (e = ring->to_clean; e != ring->to_use; e = e->next) {
2437 ++skge->tx_avail; 2432 ++skge->tx_avail;
2438 skge_tx_free(skge->hw, e); 2433 skge_tx_free(skge->hw, e);
2439 } 2434 }
2440 ring->to_clean = e; 2435 ring->to_clean = e;
2441 spin_unlock_irqrestore(&skge->tx_lock, flags); 2436 spin_unlock_bh(&skge->tx_lock);
2442} 2437}
2443 2438
2444static void skge_tx_timeout(struct net_device *dev) 2439static void skge_tx_timeout(struct net_device *dev)
@@ -2663,6 +2658,37 @@ resubmit:
2663 return NULL; 2658 return NULL;
2664} 2659}
2665 2660
2661static void skge_tx_done(struct skge_port *skge)
2662{
2663 struct skge_ring *ring = &skge->tx_ring;
2664 struct skge_element *e;
2665
2666 spin_lock(&skge->tx_lock);
2667 for (e = ring->to_clean; prefetch(e->next), e != ring->to_use; e = e->next) {
2668 struct skge_tx_desc *td = e->desc;
2669 u32 control;
2670
2671 rmb();
2672 control = td->control;
2673 if (control & BMU_OWN)
2674 break;
2675
2676 if (unlikely(netif_msg_tx_done(skge)))
2677 printk(KERN_DEBUG PFX "%s: tx done slot %td status 0x%x\n",
2678 skge->netdev->name, e - ring->start, td->status);
2679
2680 skge_tx_free(skge->hw, e);
2681 e->skb = NULL;
2682 ++skge->tx_avail;
2683 }
2684 ring->to_clean = e;
2685 skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F);
2686
2687 if (skge->tx_avail > MAX_SKB_FRAGS + 1)
2688 netif_wake_queue(skge->netdev);
2689
2690 spin_unlock(&skge->tx_lock);
2691}
2666 2692
2667static int skge_poll(struct net_device *dev, int *budget) 2693static int skge_poll(struct net_device *dev, int *budget)
2668{ 2694{
@@ -2670,8 +2696,10 @@ static int skge_poll(struct net_device *dev, int *budget)
2670 struct skge_hw *hw = skge->hw; 2696 struct skge_hw *hw = skge->hw;
2671 struct skge_ring *ring = &skge->rx_ring; 2697 struct skge_ring *ring = &skge->rx_ring;
2672 struct skge_element *e; 2698 struct skge_element *e;
2673 unsigned int to_do = min(dev->quota, *budget); 2699 int to_do = min(dev->quota, *budget);
2674 unsigned int work_done = 0; 2700 int work_done = 0;
2701
2702 skge_tx_done(skge);
2675 2703
2676 for (e = ring->to_clean; prefetch(e->next), work_done < to_do; e = e->next) { 2704 for (e = ring->to_clean; prefetch(e->next), work_done < to_do; e = e->next) {
2677 struct skge_rx_desc *rd = e->desc; 2705 struct skge_rx_desc *rd = e->desc;
@@ -2683,8 +2711,8 @@ static int skge_poll(struct net_device *dev, int *budget)
2683 if (control & BMU_OWN) 2711 if (control & BMU_OWN)
2684 break; 2712 break;
2685 2713
2686 skb = skge_rx_get(skge, e, control, rd->status, 2714 skb = skge_rx_get(skge, e, control, rd->status,
2687 le16_to_cpu(rd->csum2)); 2715 le16_to_cpu(rd->csum2));
2688 if (likely(skb)) { 2716 if (likely(skb)) {
2689 dev->last_rx = jiffies; 2717 dev->last_rx = jiffies;
2690 netif_receive_skb(skb); 2718 netif_receive_skb(skb);
@@ -2705,49 +2733,15 @@ static int skge_poll(struct net_device *dev, int *budget)
2705 if (work_done >= to_do) 2733 if (work_done >= to_do)
2706 return 1; /* not done */ 2734 return 1; /* not done */
2707 2735
2708 spin_lock_irq(&hw->hw_lock); 2736 netif_rx_complete(dev);
2709 __netif_rx_complete(dev); 2737 mmiowb();
2710 hw->intr_mask |= portirqmask[skge->port]; 2738
2739 hw->intr_mask |= skge->port == 0 ? (IS_R1_F|IS_XA1_F) : (IS_R2_F|IS_XA2_F);
2711 skge_write32(hw, B0_IMSK, hw->intr_mask); 2740 skge_write32(hw, B0_IMSK, hw->intr_mask);
2712 spin_unlock_irq(&hw->hw_lock);
2713 2741
2714 return 0; 2742 return 0;
2715} 2743}
2716 2744
2717static inline void skge_tx_intr(struct net_device *dev)
2718{
2719 struct skge_port *skge = netdev_priv(dev);
2720 struct skge_hw *hw = skge->hw;
2721 struct skge_ring *ring = &skge->tx_ring;
2722 struct skge_element *e;
2723
2724 spin_lock(&skge->tx_lock);
2725 for (e = ring->to_clean; prefetch(e->next), e != ring->to_use; e = e->next) {
2726 struct skge_tx_desc *td = e->desc;
2727 u32 control;
2728
2729 rmb();
2730 control = td->control;
2731 if (control & BMU_OWN)
2732 break;
2733
2734 if (unlikely(netif_msg_tx_done(skge)))
2735 printk(KERN_DEBUG PFX "%s: tx done slot %td status 0x%x\n",
2736 dev->name, e - ring->start, td->status);
2737
2738 skge_tx_free(hw, e);
2739 e->skb = NULL;
2740 ++skge->tx_avail;
2741 }
2742 ring->to_clean = e;
2743 skge_write8(hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F);
2744
2745 if (skge->tx_avail > MAX_SKB_FRAGS + 1)
2746 netif_wake_queue(dev);
2747
2748 spin_unlock(&skge->tx_lock);
2749}
2750
2751/* Parity errors seem to happen when Genesis is connected to a switch 2745/* Parity errors seem to happen when Genesis is connected to a switch
2752 * with no other ports present. Heartbeat error?? 2746 * with no other ports present. Heartbeat error??
2753 */ 2747 */
@@ -2770,17 +2764,6 @@ static void skge_mac_parity(struct skge_hw *hw, int port)
2770 ? GMF_CLI_TX_FC : GMF_CLI_TX_PE); 2764 ? GMF_CLI_TX_FC : GMF_CLI_TX_PE);
2771} 2765}
2772 2766
2773static void skge_pci_clear(struct skge_hw *hw)
2774{
2775 u16 status;
2776
2777 pci_read_config_word(hw->pdev, PCI_STATUS, &status);
2778 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
2779 pci_write_config_word(hw->pdev, PCI_STATUS,
2780 status | PCI_STATUS_ERROR_BITS);
2781 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
2782}
2783
2784static void skge_mac_intr(struct skge_hw *hw, int port) 2767static void skge_mac_intr(struct skge_hw *hw, int port)
2785{ 2768{
2786 if (hw->chip_id == CHIP_ID_GENESIS) 2769 if (hw->chip_id == CHIP_ID_GENESIS)
@@ -2822,23 +2805,39 @@ static void skge_error_irq(struct skge_hw *hw)
2822 if (hwstatus & IS_M2_PAR_ERR) 2805 if (hwstatus & IS_M2_PAR_ERR)
2823 skge_mac_parity(hw, 1); 2806 skge_mac_parity(hw, 1);
2824 2807
2825 if (hwstatus & IS_R1_PAR_ERR) 2808 if (hwstatus & IS_R1_PAR_ERR) {
2809 printk(KERN_ERR PFX "%s: receive queue parity error\n",
2810 hw->dev[0]->name);
2826 skge_write32(hw, B0_R1_CSR, CSR_IRQ_CL_P); 2811 skge_write32(hw, B0_R1_CSR, CSR_IRQ_CL_P);
2812 }
2827 2813
2828 if (hwstatus & IS_R2_PAR_ERR) 2814 if (hwstatus & IS_R2_PAR_ERR) {
2815 printk(KERN_ERR PFX "%s: receive queue parity error\n",
2816 hw->dev[1]->name);
2829 skge_write32(hw, B0_R2_CSR, CSR_IRQ_CL_P); 2817 skge_write32(hw, B0_R2_CSR, CSR_IRQ_CL_P);
2818 }
2830 2819
2831 if (hwstatus & (IS_IRQ_MST_ERR|IS_IRQ_STAT)) { 2820 if (hwstatus & (IS_IRQ_MST_ERR|IS_IRQ_STAT)) {
2832 printk(KERN_ERR PFX "hardware error detected (status 0x%x)\n", 2821 u16 pci_status, pci_cmd;
2833 hwstatus); 2822
2823 pci_read_config_word(hw->pdev, PCI_COMMAND, &pci_cmd);
2824 pci_read_config_word(hw->pdev, PCI_STATUS, &pci_status);
2834 2825
2835 skge_pci_clear(hw); 2826 printk(KERN_ERR PFX "%s: PCI error cmd=%#x status=%#x\n",
2827 pci_name(hw->pdev), pci_cmd, pci_status);
2828
2829 /* Write the error bits back to clear them. */
2830 pci_status &= PCI_STATUS_ERROR_BITS;
2831 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
2832 pci_write_config_word(hw->pdev, PCI_COMMAND,
2833 pci_cmd | PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
2834 pci_write_config_word(hw->pdev, PCI_STATUS, pci_status);
2835 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
2836 2836
2837 /* if error still set then just ignore it */ 2837 /* if error still set then just ignore it */
2838 hwstatus = skge_read32(hw, B0_HWE_ISRC); 2838 hwstatus = skge_read32(hw, B0_HWE_ISRC);
2839 if (hwstatus & IS_IRQ_STAT) { 2839 if (hwstatus & IS_IRQ_STAT) {
2840 pr_debug("IRQ status %x: still set ignoring hardware errors\n", 2840 printk(KERN_INFO PFX "unable to clear error (so ignoring them)\n");
2841 hwstatus);
2842 hw->intr_mask &= ~IS_HW_ERR; 2841 hw->intr_mask &= ~IS_HW_ERR;
2843 } 2842 }
2844 } 2843 }
@@ -2855,12 +2854,11 @@ static void skge_extirq(unsigned long data)
2855 int port; 2854 int port;
2856 2855
2857 spin_lock(&hw->phy_lock); 2856 spin_lock(&hw->phy_lock);
2858 for (port = 0; port < 2; port++) { 2857 for (port = 0; port < hw->ports; port++) {
2859 struct net_device *dev = hw->dev[port]; 2858 struct net_device *dev = hw->dev[port];
2859 struct skge_port *skge = netdev_priv(dev);
2860 2860
2861 if (dev && netif_running(dev)) { 2861 if (netif_running(dev)) {
2862 struct skge_port *skge = netdev_priv(dev);
2863
2864 if (hw->chip_id != CHIP_ID_GENESIS) 2862 if (hw->chip_id != CHIP_ID_GENESIS)
2865 yukon_phy_intr(skge); 2863 yukon_phy_intr(skge);
2866 else 2864 else
@@ -2869,38 +2867,39 @@ static void skge_extirq(unsigned long data)
2869 } 2867 }
2870 spin_unlock(&hw->phy_lock); 2868 spin_unlock(&hw->phy_lock);
2871 2869
2872 spin_lock_irq(&hw->hw_lock);
2873 hw->intr_mask |= IS_EXT_REG; 2870 hw->intr_mask |= IS_EXT_REG;
2874 skge_write32(hw, B0_IMSK, hw->intr_mask); 2871 skge_write32(hw, B0_IMSK, hw->intr_mask);
2875 spin_unlock_irq(&hw->hw_lock);
2876} 2872}
2877 2873
2878static irqreturn_t skge_intr(int irq, void *dev_id, struct pt_regs *regs) 2874static irqreturn_t skge_intr(int irq, void *dev_id, struct pt_regs *regs)
2879{ 2875{
2880 struct skge_hw *hw = dev_id; 2876 struct skge_hw *hw = dev_id;
2881 u32 status = skge_read32(hw, B0_SP_ISRC); 2877 u32 status;
2882 2878
2883 if (status == 0 || status == ~0) /* hotplug or shared irq */ 2879 /* Reading this register masks IRQ */
2880 status = skge_read32(hw, B0_SP_ISRC);
2881 if (status == 0)
2884 return IRQ_NONE; 2882 return IRQ_NONE;
2885 2883
2886 spin_lock(&hw->hw_lock); 2884 if (status & IS_EXT_REG) {
2887 if (status & IS_R1_F) { 2885 hw->intr_mask &= ~IS_EXT_REG;
2886 tasklet_schedule(&hw->ext_tasklet);
2887 }
2888
2889 if (status & (IS_R1_F|IS_XA1_F)) {
2888 skge_write8(hw, Q_ADDR(Q_R1, Q_CSR), CSR_IRQ_CL_F); 2890 skge_write8(hw, Q_ADDR(Q_R1, Q_CSR), CSR_IRQ_CL_F);
2889 hw->intr_mask &= ~IS_R1_F; 2891 hw->intr_mask &= ~(IS_R1_F|IS_XA1_F);
2890 netif_rx_schedule(hw->dev[0]); 2892 netif_rx_schedule(hw->dev[0]);
2891 } 2893 }
2892 2894
2893 if (status & IS_R2_F) { 2895 if (status & (IS_R2_F|IS_XA2_F)) {
2894 skge_write8(hw, Q_ADDR(Q_R2, Q_CSR), CSR_IRQ_CL_F); 2896 skge_write8(hw, Q_ADDR(Q_R2, Q_CSR), CSR_IRQ_CL_F);
2895 hw->intr_mask &= ~IS_R2_F; 2897 hw->intr_mask &= ~(IS_R2_F|IS_XA2_F);
2896 netif_rx_schedule(hw->dev[1]); 2898 netif_rx_schedule(hw->dev[1]);
2897 } 2899 }
2898 2900
2899 if (status & IS_XA1_F) 2901 if (likely((status & hw->intr_mask) == 0))
2900 skge_tx_intr(hw->dev[0]); 2902 return IRQ_HANDLED;
2901
2902 if (status & IS_XA2_F)
2903 skge_tx_intr(hw->dev[1]);
2904 2903
2905 if (status & IS_PA_TO_RX1) { 2904 if (status & IS_PA_TO_RX1) {
2906 struct skge_port *skge = netdev_priv(hw->dev[0]); 2905 struct skge_port *skge = netdev_priv(hw->dev[0]);
@@ -2929,13 +2928,7 @@ static irqreturn_t skge_intr(int irq, void *dev_id, struct pt_regs *regs)
2929 if (status & IS_HW_ERR) 2928 if (status & IS_HW_ERR)
2930 skge_error_irq(hw); 2929 skge_error_irq(hw);
2931 2930
2932 if (status & IS_EXT_REG) {
2933 hw->intr_mask &= ~IS_EXT_REG;
2934 tasklet_schedule(&hw->ext_tasklet);
2935 }
2936
2937 skge_write32(hw, B0_IMSK, hw->intr_mask); 2931 skge_write32(hw, B0_IMSK, hw->intr_mask);
2938 spin_unlock(&hw->hw_lock);
2939 2932
2940 return IRQ_HANDLED; 2933 return IRQ_HANDLED;
2941} 2934}
@@ -3010,7 +3003,7 @@ static const char *skge_board_name(const struct skge_hw *hw)
3010static int skge_reset(struct skge_hw *hw) 3003static int skge_reset(struct skge_hw *hw)
3011{ 3004{
3012 u32 reg; 3005 u32 reg;
3013 u16 ctst; 3006 u16 ctst, pci_status;
3014 u8 t8, mac_cfg, pmd_type, phy_type; 3007 u8 t8, mac_cfg, pmd_type, phy_type;
3015 int i; 3008 int i;
3016 3009
@@ -3021,8 +3014,13 @@ static int skge_reset(struct skge_hw *hw)
3021 skge_write8(hw, B0_CTST, CS_RST_CLR); 3014 skge_write8(hw, B0_CTST, CS_RST_CLR);
3022 3015
3023 /* clear PCI errors, if any */ 3016 /* clear PCI errors, if any */
3024 skge_pci_clear(hw); 3017 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
3018 skge_write8(hw, B2_TST_CTRL2, 0);
3025 3019
3020 pci_read_config_word(hw->pdev, PCI_STATUS, &pci_status);
3021 pci_write_config_word(hw->pdev, PCI_STATUS,
3022 pci_status | PCI_STATUS_ERROR_BITS);
3023 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
3026 skge_write8(hw, B0_CTST, CS_MRST_CLR); 3024 skge_write8(hw, B0_CTST, CS_MRST_CLR);
3027 3025
3028 /* restore CLK_RUN bits (for Yukon-Lite) */ 3026 /* restore CLK_RUN bits (for Yukon-Lite) */
@@ -3081,7 +3079,10 @@ static int skge_reset(struct skge_hw *hw)
3081 else 3079 else
3082 hw->ram_size = t8 * 4096; 3080 hw->ram_size = t8 * 4096;
3083 3081
3084 hw->intr_mask = IS_HW_ERR | IS_EXT_REG; 3082 hw->intr_mask = IS_HW_ERR | IS_EXT_REG | IS_PORT_1;
3083 if (hw->ports > 1)
3084 hw->intr_mask |= IS_PORT_2;
3085
3085 if (hw->chip_id == CHIP_ID_GENESIS) 3086 if (hw->chip_id == CHIP_ID_GENESIS)
3086 genesis_init(hw); 3087 genesis_init(hw);
3087 else { 3088 else {
@@ -3251,13 +3252,15 @@ static int __devinit skge_probe(struct pci_dev *pdev,
3251 struct skge_hw *hw; 3252 struct skge_hw *hw;
3252 int err, using_dac = 0; 3253 int err, using_dac = 0;
3253 3254
3254 if ((err = pci_enable_device(pdev))) { 3255 err = pci_enable_device(pdev);
3256 if (err) {
3255 printk(KERN_ERR PFX "%s cannot enable PCI device\n", 3257 printk(KERN_ERR PFX "%s cannot enable PCI device\n",
3256 pci_name(pdev)); 3258 pci_name(pdev));
3257 goto err_out; 3259 goto err_out;
3258 } 3260 }
3259 3261
3260 if ((err = pci_request_regions(pdev, DRV_NAME))) { 3262 err = pci_request_regions(pdev, DRV_NAME);
3263 if (err) {
3261 printk(KERN_ERR PFX "%s cannot obtain PCI resources\n", 3264 printk(KERN_ERR PFX "%s cannot obtain PCI resources\n",
3262 pci_name(pdev)); 3265 pci_name(pdev));
3263 goto err_out_disable_pdev; 3266 goto err_out_disable_pdev;
@@ -3265,22 +3268,18 @@ static int __devinit skge_probe(struct pci_dev *pdev,
3265 3268
3266 pci_set_master(pdev); 3269 pci_set_master(pdev);
3267 3270
3268 if (sizeof(dma_addr_t) > sizeof(u32) && 3271 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
3269 !(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
3270 using_dac = 1; 3272 using_dac = 1;
3271 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); 3273 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
3272 if (err < 0) { 3274 } else if (!(err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
3273 printk(KERN_ERR PFX "%s unable to obtain 64 bit DMA " 3275 using_dac = 0;
3274 "for consistent allocations\n", pci_name(pdev)); 3276 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
3275 goto err_out_free_regions; 3277 }
3276 } 3278
3277 } else { 3279 if (err) {
3278 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 3280 printk(KERN_ERR PFX "%s no usable DMA configuration\n",
3279 if (err) { 3281 pci_name(pdev));
3280 printk(KERN_ERR PFX "%s no usable DMA configuration\n", 3282 goto err_out_free_regions;
3281 pci_name(pdev));
3282 goto err_out_free_regions;
3283 }
3284 } 3283 }
3285 3284
3286#ifdef __BIG_ENDIAN 3285#ifdef __BIG_ENDIAN
@@ -3304,7 +3303,6 @@ static int __devinit skge_probe(struct pci_dev *pdev,
3304 3303
3305 hw->pdev = pdev; 3304 hw->pdev = pdev;
3306 spin_lock_init(&hw->phy_lock); 3305 spin_lock_init(&hw->phy_lock);
3307 spin_lock_init(&hw->hw_lock);
3308 tasklet_init(&hw->ext_tasklet, skge_extirq, (unsigned long) hw); 3306 tasklet_init(&hw->ext_tasklet, skge_extirq, (unsigned long) hw);
3309 3307
3310 hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000); 3308 hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
@@ -3314,7 +3312,8 @@ static int __devinit skge_probe(struct pci_dev *pdev,
3314 goto err_out_free_hw; 3312 goto err_out_free_hw;
3315 } 3313 }
3316 3314
3317 if ((err = request_irq(pdev->irq, skge_intr, SA_SHIRQ, DRV_NAME, hw))) { 3315 err = request_irq(pdev->irq, skge_intr, SA_SHIRQ, DRV_NAME, hw);
3316 if (err) {
3318 printk(KERN_ERR PFX "%s: cannot assign irq %d\n", 3317 printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
3319 pci_name(pdev), pdev->irq); 3318 pci_name(pdev), pdev->irq);
3320 goto err_out_iounmap; 3319 goto err_out_iounmap;
@@ -3332,7 +3331,8 @@ static int __devinit skge_probe(struct pci_dev *pdev,
3332 if ((dev = skge_devinit(hw, 0, using_dac)) == NULL) 3331 if ((dev = skge_devinit(hw, 0, using_dac)) == NULL)
3333 goto err_out_led_off; 3332 goto err_out_led_off;
3334 3333
3335 if ((err = register_netdev(dev))) { 3334 err = register_netdev(dev);
3335 if (err) {
3336 printk(KERN_ERR PFX "%s: cannot register net device\n", 3336 printk(KERN_ERR PFX "%s: cannot register net device\n",
3337 pci_name(pdev)); 3337 pci_name(pdev));
3338 goto err_out_free_netdev; 3338 goto err_out_free_netdev;
@@ -3387,7 +3387,6 @@ static void __devexit skge_remove(struct pci_dev *pdev)
3387 3387
3388 skge_write32(hw, B0_IMSK, 0); 3388 skge_write32(hw, B0_IMSK, 0);
3389 skge_write16(hw, B0_LED, LED_STAT_OFF); 3389 skge_write16(hw, B0_LED, LED_STAT_OFF);
3390 skge_pci_clear(hw);
3391 skge_write8(hw, B0_CTST, CS_RST_SET); 3390 skge_write8(hw, B0_CTST, CS_RST_SET);
3392 3391
3393 tasklet_kill(&hw->ext_tasklet); 3392 tasklet_kill(&hw->ext_tasklet);
diff --git a/drivers/net/skge.h b/drivers/net/skge.h
index 941f12a333b6..2efdacc290e5 100644
--- a/drivers/net/skge.h
+++ b/drivers/net/skge.h
@@ -2402,7 +2402,6 @@ struct skge_hw {
2402 2402
2403 struct tasklet_struct ext_tasklet; 2403 struct tasklet_struct ext_tasklet;
2404 spinlock_t phy_lock; 2404 spinlock_t phy_lock;
2405 spinlock_t hw_lock;
2406}; 2405};
2407 2406
2408enum { 2407enum {
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index 73260364cba3..f08fe6c884b2 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -51,7 +51,7 @@
51#include "sky2.h" 51#include "sky2.h"
52 52
53#define DRV_NAME "sky2" 53#define DRV_NAME "sky2"
54#define DRV_VERSION "0.15" 54#define DRV_VERSION "1.1"
55#define PFX DRV_NAME " " 55#define PFX DRV_NAME " "
56 56
57/* 57/*
@@ -61,10 +61,6 @@
61 * a receive requires one (or two if using 64 bit dma). 61 * a receive requires one (or two if using 64 bit dma).
62 */ 62 */
63 63
64#define is_ec_a1(hw) \
65 unlikely((hw)->chip_id == CHIP_ID_YUKON_EC && \
66 (hw)->chip_rev == CHIP_REV_YU_EC_A1)
67
68#define RX_LE_SIZE 512 64#define RX_LE_SIZE 512
69#define RX_LE_BYTES (RX_LE_SIZE*sizeof(struct sky2_rx_le)) 65#define RX_LE_BYTES (RX_LE_SIZE*sizeof(struct sky2_rx_le))
70#define RX_MAX_PENDING (RX_LE_SIZE/2 - 2) 66#define RX_MAX_PENDING (RX_LE_SIZE/2 - 2)
@@ -96,6 +92,10 @@ static int copybreak __read_mostly = 256;
96module_param(copybreak, int, 0); 92module_param(copybreak, int, 0);
97MODULE_PARM_DESC(copybreak, "Receive copy threshold"); 93MODULE_PARM_DESC(copybreak, "Receive copy threshold");
98 94
95static int disable_msi = 0;
96module_param(disable_msi, int, 0);
97MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
98
99static const struct pci_device_id sky2_id_table[] = { 99static const struct pci_device_id sky2_id_table[] = {
100 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9000) }, 100 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9000) },
101 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) }, 101 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) },
@@ -504,9 +504,9 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
504/* Force a renegotiation */ 504/* Force a renegotiation */
505static void sky2_phy_reinit(struct sky2_port *sky2) 505static void sky2_phy_reinit(struct sky2_port *sky2)
506{ 506{
507 down(&sky2->phy_sema); 507 spin_lock_bh(&sky2->phy_lock);
508 sky2_phy_init(sky2->hw, sky2->port); 508 sky2_phy_init(sky2->hw, sky2->port);
509 up(&sky2->phy_sema); 509 spin_unlock_bh(&sky2->phy_lock);
510} 510}
511 511
512static void sky2_mac_init(struct sky2_hw *hw, unsigned port) 512static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
@@ -571,9 +571,9 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
571 571
572 sky2_read16(hw, SK_REG(port, GMAC_IRQ_SRC)); 572 sky2_read16(hw, SK_REG(port, GMAC_IRQ_SRC));
573 573
574 down(&sky2->phy_sema); 574 spin_lock_bh(&sky2->phy_lock);
575 sky2_phy_init(hw, port); 575 sky2_phy_init(hw, port);
576 up(&sky2->phy_sema); 576 spin_unlock_bh(&sky2->phy_lock);
577 577
578 /* MIB clear */ 578 /* MIB clear */
579 reg = gma_read16(hw, port, GM_PHY_ADDR); 579 reg = gma_read16(hw, port, GM_PHY_ADDR);
@@ -725,37 +725,11 @@ static inline struct sky2_tx_le *get_tx_le(struct sky2_port *sky2)
725 return le; 725 return le;
726} 726}
727 727
728/* 728/* Update chip's next pointer */
729 * This is a workaround code taken from SysKonnect sk98lin driver 729static inline void sky2_put_idx(struct sky2_hw *hw, unsigned q, u16 idx)
730 * to deal with chip bug on Yukon EC rev 0 in the wraparound case.
731 */
732static void sky2_put_idx(struct sky2_hw *hw, unsigned q,
733 u16 idx, u16 *last, u16 size)
734{ 730{
735 wmb(); 731 wmb();
736 if (is_ec_a1(hw) && idx < *last) { 732 sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), idx);
737 u16 hwget = sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_GET_IDX));
738
739 if (hwget == 0) {
740 /* Start prefetching again */
741 sky2_write8(hw, Y2_QADDR(q, PREF_UNIT_FIFO_WM), 0xe0);
742 goto setnew;
743 }
744
745 if (hwget == size - 1) {
746 /* set watermark to one list element */
747 sky2_write8(hw, Y2_QADDR(q, PREF_UNIT_FIFO_WM), 8);
748
749 /* set put index to first list element */
750 sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), 0);
751 } else /* have hardware go to end of list */
752 sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX),
753 size - 1);
754 } else {
755setnew:
756 sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), idx);
757 }
758 *last = idx;
759 mmiowb(); 733 mmiowb();
760} 734}
761 735
@@ -878,7 +852,7 @@ static int sky2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
878 if (!netif_running(dev)) 852 if (!netif_running(dev))
879 return -ENODEV; /* Phy still in reset */ 853 return -ENODEV; /* Phy still in reset */
880 854
881 switch(cmd) { 855 switch (cmd) {
882 case SIOCGMIIPHY: 856 case SIOCGMIIPHY:
883 data->phy_id = PHY_ADDR_MARV; 857 data->phy_id = PHY_ADDR_MARV;
884 858
@@ -886,9 +860,9 @@ static int sky2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
886 case SIOCGMIIREG: { 860 case SIOCGMIIREG: {
887 u16 val = 0; 861 u16 val = 0;
888 862
889 down(&sky2->phy_sema); 863 spin_lock_bh(&sky2->phy_lock);
890 err = __gm_phy_read(hw, sky2->port, data->reg_num & 0x1f, &val); 864 err = __gm_phy_read(hw, sky2->port, data->reg_num & 0x1f, &val);
891 up(&sky2->phy_sema); 865 spin_unlock_bh(&sky2->phy_lock);
892 866
893 data->val_out = val; 867 data->val_out = val;
894 break; 868 break;
@@ -898,10 +872,10 @@ static int sky2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
898 if (!capable(CAP_NET_ADMIN)) 872 if (!capable(CAP_NET_ADMIN))
899 return -EPERM; 873 return -EPERM;
900 874
901 down(&sky2->phy_sema); 875 spin_lock_bh(&sky2->phy_lock);
902 err = gm_phy_write(hw, sky2->port, data->reg_num & 0x1f, 876 err = gm_phy_write(hw, sky2->port, data->reg_num & 0x1f,
903 data->val_in); 877 data->val_in);
904 up(&sky2->phy_sema); 878 spin_unlock_bh(&sky2->phy_lock);
905 break; 879 break;
906 } 880 }
907 return err; 881 return err;
@@ -1001,7 +975,6 @@ static int sky2_rx_start(struct sky2_port *sky2)
1001 975
1002 /* Tell chip about available buffers */ 976 /* Tell chip about available buffers */
1003 sky2_write16(hw, Y2_QADDR(rxq, PREF_UNIT_PUT_IDX), sky2->rx_put); 977 sky2_write16(hw, Y2_QADDR(rxq, PREF_UNIT_PUT_IDX), sky2->rx_put);
1004 sky2->rx_last_put = sky2_read16(hw, Y2_QADDR(rxq, PREF_UNIT_PUT_IDX));
1005 return 0; 978 return 0;
1006nomem: 979nomem:
1007 sky2_rx_clean(sky2); 980 sky2_rx_clean(sky2);
@@ -1014,7 +987,7 @@ static int sky2_up(struct net_device *dev)
1014 struct sky2_port *sky2 = netdev_priv(dev); 987 struct sky2_port *sky2 = netdev_priv(dev);
1015 struct sky2_hw *hw = sky2->hw; 988 struct sky2_hw *hw = sky2->hw;
1016 unsigned port = sky2->port; 989 unsigned port = sky2->port;
1017 u32 ramsize, rxspace; 990 u32 ramsize, rxspace, imask;
1018 int err = -ENOMEM; 991 int err = -ENOMEM;
1019 992
1020 if (netif_msg_ifup(sky2)) 993 if (netif_msg_ifup(sky2))
@@ -1079,10 +1052,10 @@ static int sky2_up(struct net_device *dev)
1079 goto err_out; 1052 goto err_out;
1080 1053
1081 /* Enable interrupts from phy/mac for port */ 1054 /* Enable interrupts from phy/mac for port */
1082 spin_lock_irq(&hw->hw_lock); 1055 imask = sky2_read32(hw, B0_IMSK);
1083 hw->intr_mask |= (port == 0) ? Y2_IS_PORT_1 : Y2_IS_PORT_2; 1056 imask |= (port == 0) ? Y2_IS_PORT_1 : Y2_IS_PORT_2;
1084 sky2_write32(hw, B0_IMSK, hw->intr_mask); 1057 sky2_write32(hw, B0_IMSK, imask);
1085 spin_unlock_irq(&hw->hw_lock); 1058
1086 return 0; 1059 return 0;
1087 1060
1088err_out: 1061err_out:
@@ -1299,8 +1272,7 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
1299 netif_stop_queue(dev); 1272 netif_stop_queue(dev);
1300 } 1273 }
1301 1274
1302 sky2_put_idx(hw, txqaddr[sky2->port], sky2->tx_prod, 1275 sky2_put_idx(hw, txqaddr[sky2->port], sky2->tx_prod);
1303 &sky2->tx_last_put, TX_RING_SIZE);
1304 1276
1305out_unlock: 1277out_unlock:
1306 spin_unlock(&sky2->tx_lock); 1278 spin_unlock(&sky2->tx_lock);
@@ -1332,7 +1304,7 @@ static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
1332 struct tx_ring_info *re = sky2->tx_ring + put; 1304 struct tx_ring_info *re = sky2->tx_ring + put;
1333 struct sk_buff *skb = re->skb; 1305 struct sk_buff *skb = re->skb;
1334 1306
1335 nxt = re->idx; 1307 nxt = re->idx;
1336 BUG_ON(nxt >= TX_RING_SIZE); 1308 BUG_ON(nxt >= TX_RING_SIZE);
1337 prefetch(sky2->tx_ring + nxt); 1309 prefetch(sky2->tx_ring + nxt);
1338 1310
@@ -1348,7 +1320,7 @@ static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
1348 struct tx_ring_info *fre; 1320 struct tx_ring_info *fre;
1349 fre = sky2->tx_ring + (put + i + 1) % TX_RING_SIZE; 1321 fre = sky2->tx_ring + (put + i + 1) % TX_RING_SIZE;
1350 pci_unmap_page(pdev, pci_unmap_addr(fre, mapaddr), 1322 pci_unmap_page(pdev, pci_unmap_addr(fre, mapaddr),
1351 skb_shinfo(skb)->frags[i].size, 1323 skb_shinfo(skb)->frags[i].size,
1352 PCI_DMA_TODEVICE); 1324 PCI_DMA_TODEVICE);
1353 } 1325 }
1354 1326
@@ -1356,7 +1328,7 @@ static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
1356 } 1328 }
1357 1329
1358 sky2->tx_cons = put; 1330 sky2->tx_cons = put;
1359 if (netif_queue_stopped(dev) && tx_avail(sky2) > MAX_SKB_TX_LE) 1331 if (tx_avail(sky2) > MAX_SKB_TX_LE)
1360 netif_wake_queue(dev); 1332 netif_wake_queue(dev);
1361} 1333}
1362 1334
@@ -1375,6 +1347,7 @@ static int sky2_down(struct net_device *dev)
1375 struct sky2_hw *hw = sky2->hw; 1347 struct sky2_hw *hw = sky2->hw;
1376 unsigned port = sky2->port; 1348 unsigned port = sky2->port;
1377 u16 ctrl; 1349 u16 ctrl;
1350 u32 imask;
1378 1351
1379 /* Never really got started! */ 1352 /* Never really got started! */
1380 if (!sky2->tx_le) 1353 if (!sky2->tx_le)
@@ -1386,14 +1359,6 @@ static int sky2_down(struct net_device *dev)
1386 /* Stop more packets from being queued */ 1359 /* Stop more packets from being queued */
1387 netif_stop_queue(dev); 1360 netif_stop_queue(dev);
1388 1361
1389 /* Disable port IRQ */
1390 spin_lock_irq(&hw->hw_lock);
1391 hw->intr_mask &= ~((sky2->port == 0) ? Y2_IS_IRQ_PHY1 : Y2_IS_IRQ_PHY2);
1392 sky2_write32(hw, B0_IMSK, hw->intr_mask);
1393 spin_unlock_irq(&hw->hw_lock);
1394
1395 flush_scheduled_work();
1396
1397 sky2_phy_reset(hw, port); 1362 sky2_phy_reset(hw, port);
1398 1363
1399 /* Stop transmitter */ 1364 /* Stop transmitter */
@@ -1437,6 +1402,11 @@ static int sky2_down(struct net_device *dev)
1437 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); 1402 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
1438 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET); 1403 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
1439 1404
1405 /* Disable port IRQ */
1406 imask = sky2_read32(hw, B0_IMSK);
1407 imask &= ~(sky2->port == 0) ? Y2_IS_PORT_1 : Y2_IS_PORT_2;
1408 sky2_write32(hw, B0_IMSK, imask);
1409
1440 /* turn off LED's */ 1410 /* turn off LED's */
1441 sky2_write16(hw, B0_Y2LED, LED_STAT_OFF); 1411 sky2_write16(hw, B0_Y2LED, LED_STAT_OFF);
1442 1412
@@ -1631,20 +1601,19 @@ static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux)
1631 return 0; 1601 return 0;
1632} 1602}
1633 1603
1634/* 1604/* Interrupt from PHY */
1635 * Interrupt from PHY are handled outside of interrupt context 1605static void sky2_phy_intr(struct sky2_hw *hw, unsigned port)
1636 * because accessing phy registers requires spin wait which might
1637 * cause excess interrupt latency.
1638 */
1639static void sky2_phy_task(void *arg)
1640{ 1606{
1641 struct sky2_port *sky2 = arg; 1607 struct net_device *dev = hw->dev[port];
1642 struct sky2_hw *hw = sky2->hw; 1608 struct sky2_port *sky2 = netdev_priv(dev);
1643 u16 istatus, phystat; 1609 u16 istatus, phystat;
1644 1610
1645 down(&sky2->phy_sema); 1611 spin_lock(&sky2->phy_lock);
1646 istatus = gm_phy_read(hw, sky2->port, PHY_MARV_INT_STAT); 1612 istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT);
1647 phystat = gm_phy_read(hw, sky2->port, PHY_MARV_PHY_STAT); 1613 phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT);
1614
1615 if (!netif_running(dev))
1616 goto out;
1648 1617
1649 if (netif_msg_intr(sky2)) 1618 if (netif_msg_intr(sky2))
1650 printk(KERN_INFO PFX "%s: phy interrupt status 0x%x 0x%x\n", 1619 printk(KERN_INFO PFX "%s: phy interrupt status 0x%x 0x%x\n",
@@ -1670,12 +1639,7 @@ static void sky2_phy_task(void *arg)
1670 sky2_link_down(sky2); 1639 sky2_link_down(sky2);
1671 } 1640 }
1672out: 1641out:
1673 up(&sky2->phy_sema); 1642 spin_unlock(&sky2->phy_lock);
1674
1675 spin_lock_irq(&hw->hw_lock);
1676 hw->intr_mask |= (sky2->port == 0) ? Y2_IS_IRQ_PHY1 : Y2_IS_IRQ_PHY2;
1677 sky2_write32(hw, B0_IMSK, hw->intr_mask);
1678 spin_unlock_irq(&hw->hw_lock);
1679} 1643}
1680 1644
1681 1645
@@ -1687,31 +1651,40 @@ static void sky2_tx_timeout(struct net_device *dev)
1687 struct sky2_port *sky2 = netdev_priv(dev); 1651 struct sky2_port *sky2 = netdev_priv(dev);
1688 struct sky2_hw *hw = sky2->hw; 1652 struct sky2_hw *hw = sky2->hw;
1689 unsigned txq = txqaddr[sky2->port]; 1653 unsigned txq = txqaddr[sky2->port];
1690 u16 ridx; 1654 u16 report, done;
1691
1692 /* Maybe we just missed an status interrupt */
1693 spin_lock(&sky2->tx_lock);
1694 ridx = sky2_read16(hw,
1695 sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX);
1696 sky2_tx_complete(sky2, ridx);
1697 spin_unlock(&sky2->tx_lock);
1698
1699 if (!netif_queue_stopped(dev)) {
1700 if (net_ratelimit())
1701 pr_info(PFX "transmit interrupt missed? recovered\n");
1702 return;
1703 }
1704 1655
1705 if (netif_msg_timer(sky2)) 1656 if (netif_msg_timer(sky2))
1706 printk(KERN_ERR PFX "%s: tx timeout\n", dev->name); 1657 printk(KERN_ERR PFX "%s: tx timeout\n", dev->name);
1707 1658
1708 sky2_write32(hw, Q_ADDR(txq, Q_CSR), BMU_STOP); 1659 report = sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX);
1709 sky2_write32(hw, Y2_QADDR(txq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET); 1660 done = sky2_read16(hw, Q_ADDR(txq, Q_DONE));
1710 1661
1711 sky2_tx_clean(sky2); 1662 printk(KERN_DEBUG PFX "%s: transmit ring %u .. %u report=%u done=%u\n",
1663 dev->name,
1664 sky2->tx_cons, sky2->tx_prod, report, done);
1712 1665
1713 sky2_qset(hw, txq); 1666 if (report != done) {
1714 sky2_prefetch_init(hw, txq, sky2->tx_le_map, TX_RING_SIZE - 1); 1667 printk(KERN_INFO PFX "status burst pending (irq moderation?)\n");
1668
1669 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP);
1670 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
1671 } else if (report != sky2->tx_cons) {
1672 printk(KERN_INFO PFX "status report lost?\n");
1673
1674 spin_lock_bh(&sky2->tx_lock);
1675 sky2_tx_complete(sky2, report);
1676 spin_unlock_bh(&sky2->tx_lock);
1677 } else {
1678 printk(KERN_INFO PFX "hardware hung? flushing\n");
1679
1680 sky2_write32(hw, Q_ADDR(txq, Q_CSR), BMU_STOP);
1681 sky2_write32(hw, Y2_QADDR(txq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
1682
1683 sky2_tx_clean(sky2);
1684
1685 sky2_qset(hw, txq);
1686 sky2_prefetch_init(hw, txq, sky2->tx_le_map, TX_RING_SIZE - 1);
1687 }
1715} 1688}
1716 1689
1717 1690
@@ -1730,6 +1703,7 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
1730 struct sky2_hw *hw = sky2->hw; 1703 struct sky2_hw *hw = sky2->hw;
1731 int err; 1704 int err;
1732 u16 ctl, mode; 1705 u16 ctl, mode;
1706 u32 imask;
1733 1707
1734 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU) 1708 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
1735 return -EINVAL; 1709 return -EINVAL;
@@ -1742,12 +1716,15 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
1742 return 0; 1716 return 0;
1743 } 1717 }
1744 1718
1719 imask = sky2_read32(hw, B0_IMSK);
1745 sky2_write32(hw, B0_IMSK, 0); 1720 sky2_write32(hw, B0_IMSK, 0);
1746 1721
1747 dev->trans_start = jiffies; /* prevent tx timeout */ 1722 dev->trans_start = jiffies; /* prevent tx timeout */
1748 netif_stop_queue(dev); 1723 netif_stop_queue(dev);
1749 netif_poll_disable(hw->dev[0]); 1724 netif_poll_disable(hw->dev[0]);
1750 1725
1726 synchronize_irq(hw->pdev->irq);
1727
1751 ctl = gma_read16(hw, sky2->port, GM_GP_CTRL); 1728 ctl = gma_read16(hw, sky2->port, GM_GP_CTRL);
1752 gma_write16(hw, sky2->port, GM_GP_CTRL, ctl & ~GM_GPCR_RX_ENA); 1729 gma_write16(hw, sky2->port, GM_GP_CTRL, ctl & ~GM_GPCR_RX_ENA);
1753 sky2_rx_stop(sky2); 1730 sky2_rx_stop(sky2);
@@ -1766,7 +1743,7 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
1766 sky2_write8(hw, RB_ADDR(rxqaddr[sky2->port], RB_CTRL), RB_ENA_OP_MD); 1743 sky2_write8(hw, RB_ADDR(rxqaddr[sky2->port], RB_CTRL), RB_ENA_OP_MD);
1767 1744
1768 err = sky2_rx_start(sky2); 1745 err = sky2_rx_start(sky2);
1769 sky2_write32(hw, B0_IMSK, hw->intr_mask); 1746 sky2_write32(hw, B0_IMSK, imask);
1770 1747
1771 if (err) 1748 if (err)
1772 dev_close(dev); 1749 dev_close(dev);
@@ -1843,8 +1820,7 @@ resubmit:
1843 sky2_rx_add(sky2, re->mapaddr); 1820 sky2_rx_add(sky2, re->mapaddr);
1844 1821
1845 /* Tell receiver about new buffers. */ 1822 /* Tell receiver about new buffers. */
1846 sky2_put_idx(sky2->hw, rxqaddr[sky2->port], sky2->rx_put, 1823 sky2_put_idx(sky2->hw, rxqaddr[sky2->port], sky2->rx_put);
1847 &sky2->rx_last_put, RX_LE_SIZE);
1848 1824
1849 return skb; 1825 return skb;
1850 1826
@@ -1871,76 +1847,51 @@ error:
1871 goto resubmit; 1847 goto resubmit;
1872} 1848}
1873 1849
1874/* 1850/* Transmit complete */
1875 * Check for transmit complete 1851static inline void sky2_tx_done(struct net_device *dev, u16 last)
1876 */
1877#define TX_NO_STATUS 0xffff
1878
1879static void sky2_tx_check(struct sky2_hw *hw, int port, u16 last)
1880{ 1852{
1881 if (last != TX_NO_STATUS) { 1853 struct sky2_port *sky2 = netdev_priv(dev);
1882 struct net_device *dev = hw->dev[port];
1883 if (dev && netif_running(dev)) {
1884 struct sky2_port *sky2 = netdev_priv(dev);
1885 1854
1886 spin_lock(&sky2->tx_lock); 1855 if (netif_running(dev)) {
1887 sky2_tx_complete(sky2, last); 1856 spin_lock(&sky2->tx_lock);
1888 spin_unlock(&sky2->tx_lock); 1857 sky2_tx_complete(sky2, last);
1889 } 1858 spin_unlock(&sky2->tx_lock);
1890 } 1859 }
1891} 1860}
1892 1861
1893/* 1862/* Process status response ring */
1894 * Both ports share the same status interrupt, therefore there is only 1863static int sky2_status_intr(struct sky2_hw *hw, int to_do)
1895 * one poll routine.
1896 */
1897static int sky2_poll(struct net_device *dev0, int *budget)
1898{ 1864{
1899 struct sky2_hw *hw = ((struct sky2_port *) netdev_priv(dev0))->hw; 1865 int work_done = 0;
1900 unsigned int to_do = min(dev0->quota, *budget);
1901 unsigned int work_done = 0;
1902 u16 hwidx;
1903 u16 tx_done[2] = { TX_NO_STATUS, TX_NO_STATUS };
1904
1905 sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ);
1906
1907 /*
1908 * Kick the STAT_LEV_TIMER_CTRL timer.
1909 * This fixes my hangs on Yukon-EC (0xb6) rev 1.
1910 * The if clause is there to start the timer only if it has been
1911 * configured correctly and not been disabled via ethtool.
1912 */
1913 if (sky2_read8(hw, STAT_LEV_TIMER_CTRL) == TIM_START) {
1914 sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_STOP);
1915 sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START);
1916 }
1917 1866
1918 hwidx = sky2_read16(hw, STAT_PUT_IDX);
1919 BUG_ON(hwidx >= STATUS_RING_SIZE);
1920 rmb(); 1867 rmb();
1921 1868
1922 while (hwidx != hw->st_idx) { 1869 for(;;) {
1923 struct sky2_status_le *le = hw->st_le + hw->st_idx; 1870 struct sky2_status_le *le = hw->st_le + hw->st_idx;
1924 struct net_device *dev; 1871 struct net_device *dev;
1925 struct sky2_port *sky2; 1872 struct sky2_port *sky2;
1926 struct sk_buff *skb; 1873 struct sk_buff *skb;
1927 u32 status; 1874 u32 status;
1928 u16 length; 1875 u16 length;
1876 u8 link, opcode;
1877
1878 opcode = le->opcode;
1879 if (!opcode)
1880 break;
1881 opcode &= ~HW_OWNER;
1929 1882
1930 le = hw->st_le + hw->st_idx;
1931 hw->st_idx = (hw->st_idx + 1) % STATUS_RING_SIZE; 1883 hw->st_idx = (hw->st_idx + 1) % STATUS_RING_SIZE;
1932 prefetch(hw->st_le + hw->st_idx); 1884 le->opcode = 0;
1933 1885
1934 BUG_ON(le->link >= 2); 1886 link = le->link;
1935 dev = hw->dev[le->link]; 1887 BUG_ON(link >= 2);
1936 if (dev == NULL || !netif_running(dev)) 1888 dev = hw->dev[link];
1937 continue;
1938 1889
1939 sky2 = netdev_priv(dev); 1890 sky2 = netdev_priv(dev);
1940 status = le32_to_cpu(le->status); 1891 length = le->length;
1941 length = le16_to_cpu(le->length); 1892 status = le->status;
1942 1893
1943 switch (le->opcode & ~HW_OWNER) { 1894 switch (opcode) {
1944 case OP_RXSTAT: 1895 case OP_RXSTAT:
1945 skb = sky2_receive(sky2, length, status); 1896 skb = sky2_receive(sky2, length, status);
1946 if (!skb) 1897 if (!skb)
@@ -1980,42 +1931,23 @@ static int sky2_poll(struct net_device *dev0, int *budget)
1980 1931
1981 case OP_TXINDEXLE: 1932 case OP_TXINDEXLE:
1982 /* TX index reports status for both ports */ 1933 /* TX index reports status for both ports */
1983 tx_done[0] = status & 0xffff; 1934 sky2_tx_done(hw->dev[0], status & 0xffff);
1984 tx_done[1] = ((status >> 24) & 0xff) 1935 if (hw->dev[1])
1985 | (u16)(length & 0xf) << 8; 1936 sky2_tx_done(hw->dev[1],
1937 ((status >> 24) & 0xff)
1938 | (u16)(length & 0xf) << 8);
1986 break; 1939 break;
1987 1940
1988 default: 1941 default:
1989 if (net_ratelimit()) 1942 if (net_ratelimit())
1990 printk(KERN_WARNING PFX 1943 printk(KERN_WARNING PFX
1991 "unknown status opcode 0x%x\n", le->opcode); 1944 "unknown status opcode 0x%x\n", opcode);
1992 break; 1945 break;
1993 } 1946 }
1994 } 1947 }
1995 1948
1996exit_loop: 1949exit_loop:
1997 sky2_tx_check(hw, 0, tx_done[0]); 1950 return work_done;
1998 sky2_tx_check(hw, 1, tx_done[1]);
1999
2000 if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_START) {
2001 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP);
2002 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
2003 }
2004
2005 if (likely(work_done < to_do)) {
2006 spin_lock_irq(&hw->hw_lock);
2007 __netif_rx_complete(dev0);
2008
2009 hw->intr_mask |= Y2_IS_STAT_BMU;
2010 sky2_write32(hw, B0_IMSK, hw->intr_mask);
2011 spin_unlock_irq(&hw->hw_lock);
2012
2013 return 0;
2014 } else {
2015 *budget -= work_done;
2016 dev0->quota -= work_done;
2017 return 1;
2018 }
2019} 1951}
2020 1952
2021static void sky2_hw_error(struct sky2_hw *hw, unsigned port, u32 status) 1953static void sky2_hw_error(struct sky2_hw *hw, unsigned port, u32 status)
@@ -2134,57 +2066,97 @@ static void sky2_mac_intr(struct sky2_hw *hw, unsigned port)
2134 } 2066 }
2135} 2067}
2136 2068
2137static void sky2_phy_intr(struct sky2_hw *hw, unsigned port) 2069/* This should never happen it is a fatal situation */
2070static void sky2_descriptor_error(struct sky2_hw *hw, unsigned port,
2071 const char *rxtx, u32 mask)
2138{ 2072{
2139 struct net_device *dev = hw->dev[port]; 2073 struct net_device *dev = hw->dev[port];
2140 struct sky2_port *sky2 = netdev_priv(dev); 2074 struct sky2_port *sky2 = netdev_priv(dev);
2075 u32 imask;
2076
2077 printk(KERN_ERR PFX "%s: %s descriptor error (hardware problem)\n",
2078 dev ? dev->name : "<not registered>", rxtx);
2141 2079
2142 hw->intr_mask &= ~(port == 0 ? Y2_IS_IRQ_PHY1 : Y2_IS_IRQ_PHY2); 2080 imask = sky2_read32(hw, B0_IMSK);
2143 sky2_write32(hw, B0_IMSK, hw->intr_mask); 2081 imask &= ~mask;
2082 sky2_write32(hw, B0_IMSK, imask);
2144 2083
2145 schedule_work(&sky2->phy_task); 2084 if (dev) {
2085 spin_lock(&sky2->phy_lock);
2086 sky2_link_down(sky2);
2087 spin_unlock(&sky2->phy_lock);
2088 }
2146} 2089}
2147 2090
2148static irqreturn_t sky2_intr(int irq, void *dev_id, struct pt_regs *regs) 2091static int sky2_poll(struct net_device *dev0, int *budget)
2149{ 2092{
2150 struct sky2_hw *hw = dev_id; 2093 struct sky2_hw *hw = ((struct sky2_port *) netdev_priv(dev0))->hw;
2151 struct net_device *dev0 = hw->dev[0]; 2094 int work_limit = min(dev0->quota, *budget);
2152 u32 status; 2095 int work_done = 0;
2096 u32 status = sky2_read32(hw, B0_Y2_SP_EISR);
2153 2097
2154 status = sky2_read32(hw, B0_Y2_SP_ISRC2); 2098 if (unlikely(status & ~Y2_IS_STAT_BMU)) {
2155 if (status == 0 || status == ~0) 2099 if (status & Y2_IS_HW_ERR)
2156 return IRQ_NONE; 2100 sky2_hw_intr(hw);
2157 2101
2158 spin_lock(&hw->hw_lock); 2102 if (status & Y2_IS_IRQ_PHY1)
2159 if (status & Y2_IS_HW_ERR) 2103 sky2_phy_intr(hw, 0);
2160 sky2_hw_intr(hw);
2161 2104
2162 /* Do NAPI for Rx and Tx status */ 2105 if (status & Y2_IS_IRQ_PHY2)
2163 if (status & Y2_IS_STAT_BMU) { 2106 sky2_phy_intr(hw, 1);
2164 hw->intr_mask &= ~Y2_IS_STAT_BMU;
2165 sky2_write32(hw, B0_IMSK, hw->intr_mask);
2166 2107
2167 if (likely(__netif_rx_schedule_prep(dev0))) { 2108 if (status & Y2_IS_IRQ_MAC1)
2168 prefetch(&hw->st_le[hw->st_idx]); 2109 sky2_mac_intr(hw, 0);
2169 __netif_rx_schedule(dev0); 2110
2170 } 2111 if (status & Y2_IS_IRQ_MAC2)
2112 sky2_mac_intr(hw, 1);
2113
2114 if (status & Y2_IS_CHK_RX1)
2115 sky2_descriptor_error(hw, 0, "receive", Y2_IS_CHK_RX1);
2116
2117 if (status & Y2_IS_CHK_RX2)
2118 sky2_descriptor_error(hw, 1, "receive", Y2_IS_CHK_RX2);
2119
2120 if (status & Y2_IS_CHK_TXA1)
2121 sky2_descriptor_error(hw, 0, "transmit", Y2_IS_CHK_TXA1);
2122
2123 if (status & Y2_IS_CHK_TXA2)
2124 sky2_descriptor_error(hw, 1, "transmit", Y2_IS_CHK_TXA2);
2171 } 2125 }
2172 2126
2173 if (status & Y2_IS_IRQ_PHY1) 2127 if (status & Y2_IS_STAT_BMU) {
2174 sky2_phy_intr(hw, 0); 2128 work_done = sky2_status_intr(hw, work_limit);
2129 *budget -= work_done;
2130 dev0->quota -= work_done;
2131
2132 if (work_done >= work_limit)
2133 return 1;
2175 2134
2176 if (status & Y2_IS_IRQ_PHY2) 2135 sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ);
2177 sky2_phy_intr(hw, 1); 2136 }
2178 2137
2179 if (status & Y2_IS_IRQ_MAC1) 2138 netif_rx_complete(dev0);
2180 sky2_mac_intr(hw, 0);
2181 2139
2182 if (status & Y2_IS_IRQ_MAC2) 2140 status = sky2_read32(hw, B0_Y2_SP_LISR);
2183 sky2_mac_intr(hw, 1); 2141 return 0;
2142}
2184 2143
2185 sky2_write32(hw, B0_Y2_SP_ICR, 2); 2144static irqreturn_t sky2_intr(int irq, void *dev_id, struct pt_regs *regs)
2145{
2146 struct sky2_hw *hw = dev_id;
2147 struct net_device *dev0 = hw->dev[0];
2148 u32 status;
2186 2149
2187 spin_unlock(&hw->hw_lock); 2150 /* Reading this mask interrupts as side effect */
2151 status = sky2_read32(hw, B0_Y2_SP_ISRC2);
2152 if (status == 0 || status == ~0)
2153 return IRQ_NONE;
2154
2155 prefetch(&hw->st_le[hw->st_idx]);
2156 if (likely(__netif_rx_schedule_prep(dev0)))
2157 __netif_rx_schedule(dev0);
2158 else
2159 printk(KERN_DEBUG PFX "irq race detected\n");
2188 2160
2189 return IRQ_HANDLED; 2161 return IRQ_HANDLED;
2190} 2162}
@@ -2238,6 +2210,23 @@ static int sky2_reset(struct sky2_hw *hw)
2238 return -EOPNOTSUPP; 2210 return -EOPNOTSUPP;
2239 } 2211 }
2240 2212
2213 hw->chip_rev = (sky2_read8(hw, B2_MAC_CFG) & CFG_CHIP_R_MSK) >> 4;
2214
2215 /* This rev is really old, and requires untested workarounds */
2216 if (hw->chip_id == CHIP_ID_YUKON_EC && hw->chip_rev == CHIP_REV_YU_EC_A1) {
2217 printk(KERN_ERR PFX "%s: unsupported revision Yukon-%s (0x%x) rev %d\n",
2218 pci_name(hw->pdev), yukon2_name[hw->chip_id - CHIP_ID_YUKON_XL],
2219 hw->chip_id, hw->chip_rev);
2220 return -EOPNOTSUPP;
2221 }
2222
2223 /* This chip is new and not tested yet */
2224 if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
2225 pr_info(PFX "%s: is a version of Yukon 2 chipset that has not been tested yet.\n",
2226 pci_name(hw->pdev));
2227 pr_info("Please report success/failure to maintainer <shemminger@osdl.org>\n");
2228 }
2229
2241 /* disable ASF */ 2230 /* disable ASF */
2242 if (hw->chip_id <= CHIP_ID_YUKON_EC) { 2231 if (hw->chip_id <= CHIP_ID_YUKON_EC) {
2243 sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET); 2232 sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET);
@@ -2258,7 +2247,7 @@ static int sky2_reset(struct sky2_hw *hw)
2258 sky2_write8(hw, B0_CTST, CS_MRST_CLR); 2247 sky2_write8(hw, B0_CTST, CS_MRST_CLR);
2259 2248
2260 /* clear any PEX errors */ 2249 /* clear any PEX errors */
2261 if (pci_find_capability(hw->pdev, PCI_CAP_ID_EXP)) 2250 if (pci_find_capability(hw->pdev, PCI_CAP_ID_EXP))
2262 sky2_pci_write32(hw, PEX_UNC_ERR_STAT, 0xffffffffUL); 2251 sky2_pci_write32(hw, PEX_UNC_ERR_STAT, 0xffffffffUL);
2263 2252
2264 2253
@@ -2271,7 +2260,6 @@ static int sky2_reset(struct sky2_hw *hw)
2271 if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC)) 2260 if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC))
2272 ++hw->ports; 2261 ++hw->ports;
2273 } 2262 }
2274 hw->chip_rev = (sky2_read8(hw, B2_MAC_CFG) & CFG_CHIP_R_MSK) >> 4;
2275 2263
2276 sky2_set_power_state(hw, PCI_D0); 2264 sky2_set_power_state(hw, PCI_D0);
2277 2265
@@ -2337,30 +2325,18 @@ static int sky2_reset(struct sky2_hw *hw)
2337 /* Set the list last index */ 2325 /* Set the list last index */
2338 sky2_write16(hw, STAT_LAST_IDX, STATUS_RING_SIZE - 1); 2326 sky2_write16(hw, STAT_LAST_IDX, STATUS_RING_SIZE - 1);
2339 2327
2340 /* These status setup values are copied from SysKonnect's driver */ 2328 sky2_write16(hw, STAT_TX_IDX_TH, 10);
2341 if (is_ec_a1(hw)) { 2329 sky2_write8(hw, STAT_FIFO_WM, 16);
2342 /* WA for dev. #4.3 */
2343 sky2_write16(hw, STAT_TX_IDX_TH, 0xfff); /* Tx Threshold */
2344
2345 /* set Status-FIFO watermark */
2346 sky2_write8(hw, STAT_FIFO_WM, 0x21); /* WA for dev. #4.18 */
2347 2330
2348 /* set Status-FIFO ISR watermark */ 2331 /* set Status-FIFO ISR watermark */
2349 sky2_write8(hw, STAT_FIFO_ISR_WM, 0x07); /* WA for dev. #4.18 */ 2332 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0)
2350 sky2_write32(hw, STAT_TX_TIMER_INI, sky2_us2clk(hw, 10000)); 2333 sky2_write8(hw, STAT_FIFO_ISR_WM, 4);
2351 } else { 2334 else
2352 sky2_write16(hw, STAT_TX_IDX_TH, 10); 2335 sky2_write8(hw, STAT_FIFO_ISR_WM, 16);
2353 sky2_write8(hw, STAT_FIFO_WM, 16);
2354
2355 /* set Status-FIFO ISR watermark */
2356 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0)
2357 sky2_write8(hw, STAT_FIFO_ISR_WM, 4);
2358 else
2359 sky2_write8(hw, STAT_FIFO_ISR_WM, 16);
2360 2336
2361 sky2_write32(hw, STAT_TX_TIMER_INI, sky2_us2clk(hw, 1000)); 2337 sky2_write32(hw, STAT_TX_TIMER_INI, sky2_us2clk(hw, 1000));
2362 sky2_write32(hw, STAT_ISR_TIMER_INI, sky2_us2clk(hw, 7)); 2338 sky2_write32(hw, STAT_ISR_TIMER_INI, sky2_us2clk(hw, 20));
2363 } 2339 sky2_write32(hw, STAT_LEV_TIMER_INI, sky2_us2clk(hw, 100));
2364 2340
2365 /* enable status unit */ 2341 /* enable status unit */
2366 sky2_write32(hw, STAT_CTRL, SC_STAT_OP_ON); 2342 sky2_write32(hw, STAT_CTRL, SC_STAT_OP_ON);
@@ -2743,7 +2719,7 @@ static int sky2_phys_id(struct net_device *dev, u32 data)
2743 ms = data * 1000; 2719 ms = data * 1000;
2744 2720
2745 /* save initial values */ 2721 /* save initial values */
2746 down(&sky2->phy_sema); 2722 spin_lock_bh(&sky2->phy_lock);
2747 if (hw->chip_id == CHIP_ID_YUKON_XL) { 2723 if (hw->chip_id == CHIP_ID_YUKON_XL) {
2748 u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); 2724 u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
2749 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); 2725 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
@@ -2759,9 +2735,9 @@ static int sky2_phys_id(struct net_device *dev, u32 data)
2759 sky2_led(hw, port, onoff); 2735 sky2_led(hw, port, onoff);
2760 onoff = !onoff; 2736 onoff = !onoff;
2761 2737
2762 up(&sky2->phy_sema); 2738 spin_unlock_bh(&sky2->phy_lock);
2763 interrupted = msleep_interruptible(250); 2739 interrupted = msleep_interruptible(250);
2764 down(&sky2->phy_sema); 2740 spin_lock_bh(&sky2->phy_lock);
2765 2741
2766 ms -= 250; 2742 ms -= 250;
2767 } 2743 }
@@ -2776,7 +2752,7 @@ static int sky2_phys_id(struct net_device *dev, u32 data)
2776 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl); 2752 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl);
2777 gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover); 2753 gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover);
2778 } 2754 }
2779 up(&sky2->phy_sema); 2755 spin_unlock_bh(&sky2->phy_lock);
2780 2756
2781 return 0; 2757 return 0;
2782} 2758}
@@ -2806,38 +2782,6 @@ static int sky2_set_pauseparam(struct net_device *dev,
2806 return err; 2782 return err;
2807} 2783}
2808 2784
2809#ifdef CONFIG_PM
2810static void sky2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
2811{
2812 struct sky2_port *sky2 = netdev_priv(dev);
2813
2814 wol->supported = WAKE_MAGIC;
2815 wol->wolopts = sky2->wol ? WAKE_MAGIC : 0;
2816}
2817
2818static int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
2819{
2820 struct sky2_port *sky2 = netdev_priv(dev);
2821 struct sky2_hw *hw = sky2->hw;
2822
2823 if (wol->wolopts != WAKE_MAGIC && wol->wolopts != 0)
2824 return -EOPNOTSUPP;
2825
2826 sky2->wol = wol->wolopts == WAKE_MAGIC;
2827
2828 if (sky2->wol) {
2829 memcpy_toio(hw->regs + WOL_MAC_ADDR, dev->dev_addr, ETH_ALEN);
2830
2831 sky2_write16(hw, WOL_CTRL_STAT,
2832 WOL_CTL_ENA_PME_ON_MAGIC_PKT |
2833 WOL_CTL_ENA_MAGIC_PKT_UNIT);
2834 } else
2835 sky2_write16(hw, WOL_CTRL_STAT, WOL_CTL_DEFAULT);
2836
2837 return 0;
2838}
2839#endif
2840
2841static int sky2_get_coalesce(struct net_device *dev, 2785static int sky2_get_coalesce(struct net_device *dev,
2842 struct ethtool_coalesce *ecmd) 2786 struct ethtool_coalesce *ecmd)
2843{ 2787{
@@ -2878,19 +2822,11 @@ static int sky2_set_coalesce(struct net_device *dev,
2878{ 2822{
2879 struct sky2_port *sky2 = netdev_priv(dev); 2823 struct sky2_port *sky2 = netdev_priv(dev);
2880 struct sky2_hw *hw = sky2->hw; 2824 struct sky2_hw *hw = sky2->hw;
2881 const u32 tmin = sky2_clk2us(hw, 1); 2825 const u32 tmax = sky2_clk2us(hw, 0x0ffffff);
2882 const u32 tmax = 5000;
2883
2884 if (ecmd->tx_coalesce_usecs != 0 &&
2885 (ecmd->tx_coalesce_usecs < tmin || ecmd->tx_coalesce_usecs > tmax))
2886 return -EINVAL;
2887
2888 if (ecmd->rx_coalesce_usecs != 0 &&
2889 (ecmd->rx_coalesce_usecs < tmin || ecmd->rx_coalesce_usecs > tmax))
2890 return -EINVAL;
2891 2826
2892 if (ecmd->rx_coalesce_usecs_irq != 0 && 2827 if (ecmd->tx_coalesce_usecs > tmax ||
2893 (ecmd->rx_coalesce_usecs_irq < tmin || ecmd->rx_coalesce_usecs_irq > tmax)) 2828 ecmd->rx_coalesce_usecs > tmax ||
2829 ecmd->rx_coalesce_usecs_irq > tmax)
2894 return -EINVAL; 2830 return -EINVAL;
2895 2831
2896 if (ecmd->tx_max_coalesced_frames >= TX_RING_SIZE-1) 2832 if (ecmd->tx_max_coalesced_frames >= TX_RING_SIZE-1)
@@ -3025,10 +2961,6 @@ static struct ethtool_ops sky2_ethtool_ops = {
3025 .set_ringparam = sky2_set_ringparam, 2961 .set_ringparam = sky2_set_ringparam,
3026 .get_pauseparam = sky2_get_pauseparam, 2962 .get_pauseparam = sky2_get_pauseparam,
3027 .set_pauseparam = sky2_set_pauseparam, 2963 .set_pauseparam = sky2_set_pauseparam,
3028#ifdef CONFIG_PM
3029 .get_wol = sky2_get_wol,
3030 .set_wol = sky2_set_wol,
3031#endif
3032 .phys_id = sky2_phys_id, 2964 .phys_id = sky2_phys_id,
3033 .get_stats_count = sky2_get_stats_count, 2965 .get_stats_count = sky2_get_stats_count,
3034 .get_ethtool_stats = sky2_get_ethtool_stats, 2966 .get_ethtool_stats = sky2_get_ethtool_stats,
@@ -3082,16 +3014,15 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
3082 sky2->speed = -1; 3014 sky2->speed = -1;
3083 sky2->advertising = sky2_supported_modes(hw); 3015 sky2->advertising = sky2_supported_modes(hw);
3084 3016
3085 /* Receive checksum disabled for Yukon XL 3017 /* Receive checksum disabled for Yukon XL
3086 * because of observed problems with incorrect 3018 * because of observed problems with incorrect
3087 * values when multiple packets are received in one interrupt 3019 * values when multiple packets are received in one interrupt
3088 */ 3020 */
3089 sky2->rx_csum = (hw->chip_id != CHIP_ID_YUKON_XL); 3021 sky2->rx_csum = (hw->chip_id != CHIP_ID_YUKON_XL);
3090 3022
3091 INIT_WORK(&sky2->phy_task, sky2_phy_task, sky2); 3023 spin_lock_init(&sky2->phy_lock);
3092 init_MUTEX(&sky2->phy_sema);
3093 sky2->tx_pending = TX_DEF_PENDING; 3024 sky2->tx_pending = TX_DEF_PENDING;
3094 sky2->rx_pending = is_ec_a1(hw) ? 8 : RX_DEF_PENDING; 3025 sky2->rx_pending = RX_DEF_PENDING;
3095 sky2->rx_bufsize = sky2_buf_size(ETH_DATA_LEN); 3026 sky2->rx_bufsize = sky2_buf_size(ETH_DATA_LEN);
3096 3027
3097 hw->dev[port] = dev; 3028 hw->dev[port] = dev;
@@ -3133,6 +3064,66 @@ static void __devinit sky2_show_addr(struct net_device *dev)
3133 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); 3064 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
3134} 3065}
3135 3066
3067/* Handle software interrupt used during MSI test */
3068static irqreturn_t __devinit sky2_test_intr(int irq, void *dev_id,
3069 struct pt_regs *regs)
3070{
3071 struct sky2_hw *hw = dev_id;
3072 u32 status = sky2_read32(hw, B0_Y2_SP_ISRC2);
3073
3074 if (status == 0)
3075 return IRQ_NONE;
3076
3077 if (status & Y2_IS_IRQ_SW) {
3078 hw->msi_detected = 1;
3079 wake_up(&hw->msi_wait);
3080 sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ);
3081 }
3082 sky2_write32(hw, B0_Y2_SP_ICR, 2);
3083
3084 return IRQ_HANDLED;
3085}
3086
3087/* Test interrupt path by forcing a a software IRQ */
3088static int __devinit sky2_test_msi(struct sky2_hw *hw)
3089{
3090 struct pci_dev *pdev = hw->pdev;
3091 int err;
3092
3093 sky2_write32(hw, B0_IMSK, Y2_IS_IRQ_SW);
3094
3095 err = request_irq(pdev->irq, sky2_test_intr, SA_SHIRQ, DRV_NAME, hw);
3096 if (err) {
3097 printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
3098 pci_name(pdev), pdev->irq);
3099 return err;
3100 }
3101
3102 init_waitqueue_head (&hw->msi_wait);
3103
3104 sky2_write8(hw, B0_CTST, CS_ST_SW_IRQ);
3105 wmb();
3106
3107 wait_event_timeout(hw->msi_wait, hw->msi_detected, HZ/10);
3108
3109 if (!hw->msi_detected) {
3110 /* MSI test failed, go back to INTx mode */
3111 printk(KERN_WARNING PFX "%s: No interrupt was generated using MSI, "
3112 "switching to INTx mode. Please report this failure to "
3113 "the PCI maintainer and include system chipset information.\n",
3114 pci_name(pdev));
3115
3116 err = -EOPNOTSUPP;
3117 sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ);
3118 }
3119
3120 sky2_write32(hw, B0_IMSK, 0);
3121
3122 free_irq(pdev->irq, hw);
3123
3124 return err;
3125}
3126
3136static int __devinit sky2_probe(struct pci_dev *pdev, 3127static int __devinit sky2_probe(struct pci_dev *pdev,
3137 const struct pci_device_id *ent) 3128 const struct pci_device_id *ent)
3138{ 3129{
@@ -3201,7 +3192,6 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
3201 goto err_out_free_hw; 3192 goto err_out_free_hw;
3202 } 3193 }
3203 hw->pm_cap = pm_cap; 3194 hw->pm_cap = pm_cap;
3204 spin_lock_init(&hw->hw_lock);
3205 3195
3206#ifdef __BIG_ENDIAN 3196#ifdef __BIG_ENDIAN
3207 /* byte swap descriptors in hardware */ 3197 /* byte swap descriptors in hardware */
@@ -3254,21 +3244,29 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
3254 } 3244 }
3255 } 3245 }
3256 3246
3257 err = request_irq(pdev->irq, sky2_intr, SA_SHIRQ, DRV_NAME, hw); 3247 if (!disable_msi && pci_enable_msi(pdev) == 0) {
3248 err = sky2_test_msi(hw);
3249 if (err == -EOPNOTSUPP)
3250 pci_disable_msi(pdev);
3251 else if (err)
3252 goto err_out_unregister;
3253 }
3254
3255 err = request_irq(pdev->irq, sky2_intr, SA_SHIRQ, DRV_NAME, hw);
3258 if (err) { 3256 if (err) {
3259 printk(KERN_ERR PFX "%s: cannot assign irq %d\n", 3257 printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
3260 pci_name(pdev), pdev->irq); 3258 pci_name(pdev), pdev->irq);
3261 goto err_out_unregister; 3259 goto err_out_unregister;
3262 } 3260 }
3263 3261
3264 hw->intr_mask = Y2_IS_BASE; 3262 sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
3265 sky2_write32(hw, B0_IMSK, hw->intr_mask);
3266 3263
3267 pci_set_drvdata(pdev, hw); 3264 pci_set_drvdata(pdev, hw);
3268 3265
3269 return 0; 3266 return 0;
3270 3267
3271err_out_unregister: 3268err_out_unregister:
3269 pci_disable_msi(pdev);
3272 if (dev1) { 3270 if (dev1) {
3273 unregister_netdev(dev1); 3271 unregister_netdev(dev1);
3274 free_netdev(dev1); 3272 free_netdev(dev1);
@@ -3311,6 +3309,7 @@ static void __devexit sky2_remove(struct pci_dev *pdev)
3311 sky2_read8(hw, B0_CTST); 3309 sky2_read8(hw, B0_CTST);
3312 3310
3313 free_irq(pdev->irq, hw); 3311 free_irq(pdev->irq, hw);
3312 pci_disable_msi(pdev);
3314 pci_free_consistent(pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma); 3313 pci_free_consistent(pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma);
3315 pci_release_regions(pdev); 3314 pci_release_regions(pdev);
3316 pci_disable_device(pdev); 3315 pci_disable_device(pdev);
diff --git a/drivers/net/sky2.h b/drivers/net/sky2.h
index dce955c76f3c..d63cd5a1b71c 100644
--- a/drivers/net/sky2.h
+++ b/drivers/net/sky2.h
@@ -278,13 +278,11 @@ enum {
278 Y2_IS_CHK_TXS1 = 1<<1, /* Descriptor error TXS 1 */ 278 Y2_IS_CHK_TXS1 = 1<<1, /* Descriptor error TXS 1 */
279 Y2_IS_CHK_TXA1 = 1<<0, /* Descriptor error TXA 1 */ 279 Y2_IS_CHK_TXA1 = 1<<0, /* Descriptor error TXA 1 */
280 280
281 Y2_IS_BASE = Y2_IS_HW_ERR | Y2_IS_STAT_BMU | 281 Y2_IS_BASE = Y2_IS_HW_ERR | Y2_IS_STAT_BMU,
282 Y2_IS_POLL_CHK | Y2_IS_TWSI_RDY | 282 Y2_IS_PORT_1 = Y2_IS_IRQ_PHY1 | Y2_IS_IRQ_MAC1
283 Y2_IS_IRQ_SW | Y2_IS_TIMINT, 283 | Y2_IS_CHK_TXA1 | Y2_IS_CHK_RX1,
284 Y2_IS_PORT_1 = Y2_IS_IRQ_PHY1 | Y2_IS_IRQ_MAC1 | 284 Y2_IS_PORT_2 = Y2_IS_IRQ_PHY2 | Y2_IS_IRQ_MAC2
285 Y2_IS_CHK_RX1 | Y2_IS_CHK_TXA1 | Y2_IS_CHK_TXS1, 285 | Y2_IS_CHK_TXA2 | Y2_IS_CHK_RX2,
286 Y2_IS_PORT_2 = Y2_IS_IRQ_PHY2 | Y2_IS_IRQ_MAC2 |
287 Y2_IS_CHK_RX2 | Y2_IS_CHK_TXA2 | Y2_IS_CHK_TXS2,
288}; 286};
289 287
290/* B2_IRQM_HWE_MSK 32 bit IRQ Moderation HW Error Mask */ 288/* B2_IRQM_HWE_MSK 32 bit IRQ Moderation HW Error Mask */
@@ -1832,6 +1830,7 @@ struct sky2_port {
1832 struct net_device *netdev; 1830 struct net_device *netdev;
1833 unsigned port; 1831 unsigned port;
1834 u32 msg_enable; 1832 u32 msg_enable;
1833 spinlock_t phy_lock;
1835 1834
1836 spinlock_t tx_lock ____cacheline_aligned_in_smp; 1835 spinlock_t tx_lock ____cacheline_aligned_in_smp;
1837 struct tx_ring_info *tx_ring; 1836 struct tx_ring_info *tx_ring;
@@ -1840,7 +1839,6 @@ struct sky2_port {
1840 u16 tx_prod; /* next le to use */ 1839 u16 tx_prod; /* next le to use */
1841 u32 tx_addr64; 1840 u32 tx_addr64;
1842 u16 tx_pending; 1841 u16 tx_pending;
1843 u16 tx_last_put;
1844 u16 tx_last_mss; 1842 u16 tx_last_mss;
1845 1843
1846 struct ring_info *rx_ring ____cacheline_aligned_in_smp; 1844 struct ring_info *rx_ring ____cacheline_aligned_in_smp;
@@ -1849,7 +1847,6 @@ struct sky2_port {
1849 u16 rx_next; /* next re to check */ 1847 u16 rx_next; /* next re to check */
1850 u16 rx_put; /* next le index to use */ 1848 u16 rx_put; /* next le index to use */
1851 u16 rx_pending; 1849 u16 rx_pending;
1852 u16 rx_last_put;
1853 u16 rx_bufsize; 1850 u16 rx_bufsize;
1854#ifdef SKY2_VLAN_TAG_USED 1851#ifdef SKY2_VLAN_TAG_USED
1855 u16 rx_tag; 1852 u16 rx_tag;
@@ -1865,20 +1862,15 @@ struct sky2_port {
1865 u8 rx_pause; 1862 u8 rx_pause;
1866 u8 tx_pause; 1863 u8 tx_pause;
1867 u8 rx_csum; 1864 u8 rx_csum;
1868 u8 wol;
1869 1865
1870 struct net_device_stats net_stats; 1866 struct net_device_stats net_stats;
1871 1867
1872 struct work_struct phy_task;
1873 struct semaphore phy_sema;
1874}; 1868};
1875 1869
1876struct sky2_hw { 1870struct sky2_hw {
1877 void __iomem *regs; 1871 void __iomem *regs;
1878 struct pci_dev *pdev; 1872 struct pci_dev *pdev;
1879 struct net_device *dev[2]; 1873 struct net_device *dev[2];
1880 spinlock_t hw_lock;
1881 u32 intr_mask;
1882 1874
1883 int pm_cap; 1875 int pm_cap;
1884 u8 chip_id; 1876 u8 chip_id;
@@ -1889,6 +1881,8 @@ struct sky2_hw {
1889 struct sky2_status_le *st_le; 1881 struct sky2_status_le *st_le;
1890 u32 st_idx; 1882 u32 st_idx;
1891 dma_addr_t st_dma; 1883 dma_addr_t st_dma;
1884 int msi_detected;
1885 wait_queue_head_t msi_wait;
1892}; 1886};
1893 1887
1894/* Register accessor for memory mapped device */ 1888/* Register accessor for memory mapped device */
diff --git a/drivers/net/smc91x.c b/drivers/net/smc91x.c
index 7ec08127c9d6..0e9833adf9fe 100644
--- a/drivers/net/smc91x.c
+++ b/drivers/net/smc91x.c
@@ -215,15 +215,12 @@ struct smc_local {
215 215
216 spinlock_t lock; 216 spinlock_t lock;
217 217
218#ifdef SMC_CAN_USE_DATACS
219 u32 __iomem *datacs;
220#endif
221
222#ifdef SMC_USE_PXA_DMA 218#ifdef SMC_USE_PXA_DMA
223 /* DMA needs the physical address of the chip */ 219 /* DMA needs the physical address of the chip */
224 u_long physaddr; 220 u_long physaddr;
225#endif 221#endif
226 void __iomem *base; 222 void __iomem *base;
223 void __iomem *datacs;
227}; 224};
228 225
229#if SMC_DEBUG > 0 226#if SMC_DEBUG > 0
@@ -2104,9 +2101,8 @@ static int smc_enable_device(struct platform_device *pdev)
2104 * Set the appropriate byte/word mode. 2101 * Set the appropriate byte/word mode.
2105 */ 2102 */
2106 ecsr = readb(addr + (ECSR << SMC_IO_SHIFT)) & ~ECSR_IOIS8; 2103 ecsr = readb(addr + (ECSR << SMC_IO_SHIFT)) & ~ECSR_IOIS8;
2107#ifndef SMC_CAN_USE_16BIT 2104 if (!SMC_CAN_USE_16BIT)
2108 ecsr |= ECSR_IOIS8; 2105 ecsr |= ECSR_IOIS8;
2109#endif
2110 writeb(ecsr, addr + (ECSR << SMC_IO_SHIFT)); 2106 writeb(ecsr, addr + (ECSR << SMC_IO_SHIFT));
2111 local_irq_restore(flags); 2107 local_irq_restore(flags);
2112 2108
@@ -2143,40 +2139,39 @@ static void smc_release_attrib(struct platform_device *pdev)
2143 release_mem_region(res->start, ATTRIB_SIZE); 2139 release_mem_region(res->start, ATTRIB_SIZE);
2144} 2140}
2145 2141
2146#ifdef SMC_CAN_USE_DATACS 2142static inline void smc_request_datacs(struct platform_device *pdev, struct net_device *ndev)
2147static void smc_request_datacs(struct platform_device *pdev, struct net_device *ndev)
2148{ 2143{
2149 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-data32"); 2144 if (SMC_CAN_USE_DATACS) {
2150 struct smc_local *lp = netdev_priv(ndev); 2145 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-data32");
2146 struct smc_local *lp = netdev_priv(ndev);
2151 2147
2152 if (!res) 2148 if (!res)
2153 return; 2149 return;
2154 2150
2155 if(!request_mem_region(res->start, SMC_DATA_EXTENT, CARDNAME)) { 2151 if(!request_mem_region(res->start, SMC_DATA_EXTENT, CARDNAME)) {
2156 printk(KERN_INFO "%s: failed to request datacs memory region.\n", CARDNAME); 2152 printk(KERN_INFO "%s: failed to request datacs memory region.\n", CARDNAME);
2157 return; 2153 return;
2158 } 2154 }
2159 2155
2160 lp->datacs = ioremap(res->start, SMC_DATA_EXTENT); 2156 lp->datacs = ioremap(res->start, SMC_DATA_EXTENT);
2157 }
2161} 2158}
2162 2159
2163static void smc_release_datacs(struct platform_device *pdev, struct net_device *ndev) 2160static void smc_release_datacs(struct platform_device *pdev, struct net_device *ndev)
2164{ 2161{
2165 struct smc_local *lp = netdev_priv(ndev); 2162 if (SMC_CAN_USE_DATACS) {
2166 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-data32"); 2163 struct smc_local *lp = netdev_priv(ndev);
2164 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-data32");
2167 2165
2168 if (lp->datacs) 2166 if (lp->datacs)
2169 iounmap(lp->datacs); 2167 iounmap(lp->datacs);
2170 2168
2171 lp->datacs = NULL; 2169 lp->datacs = NULL;
2172 2170
2173 if (res) 2171 if (res)
2174 release_mem_region(res->start, SMC_DATA_EXTENT); 2172 release_mem_region(res->start, SMC_DATA_EXTENT);
2173 }
2175} 2174}
2176#else
2177static void smc_request_datacs(struct platform_device *pdev, struct net_device *ndev) {}
2178static void smc_release_datacs(struct platform_device *pdev, struct net_device *ndev) {}
2179#endif
2180 2175
2181/* 2176/*
2182 * smc_init(void) 2177 * smc_init(void)
@@ -2221,6 +2216,10 @@ static int smc_drv_probe(struct platform_device *pdev)
2221 2216
2222 ndev->dma = (unsigned char)-1; 2217 ndev->dma = (unsigned char)-1;
2223 ndev->irq = platform_get_irq(pdev, 0); 2218 ndev->irq = platform_get_irq(pdev, 0);
2219 if (ndev->irq < 0) {
2220 ret = -ENODEV;
2221 goto out_free_netdev;
2222 }
2224 2223
2225 ret = smc_request_attrib(pdev); 2224 ret = smc_request_attrib(pdev);
2226 if (ret) 2225 if (ret)
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index e0efd1964e72..e1be1af51201 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -275,7 +275,10 @@ SMC_outw(u16 val, void __iomem *ioaddr, int reg)
275#define SMC_insw(a,r,p,l) readsw ((void*) ((a) + (r)), p, l) 275#define SMC_insw(a,r,p,l) readsw ((void*) ((a) + (r)), p, l)
276#define SMC_outw(v,a,r) ({ writew ((v), (a) + (r)); LPD7A40X_IOBARRIER; }) 276#define SMC_outw(v,a,r) ({ writew ((v), (a) + (r)); LPD7A40X_IOBARRIER; })
277 277
278static inline void SMC_outsw (unsigned long a, int r, unsigned char* p, int l) 278#define SMC_outsw LPD7A40X_SMC_outsw
279
280static inline void LPD7A40X_SMC_outsw(unsigned long a, int r,
281 unsigned char* p, int l)
279{ 282{
280 unsigned short* ps = (unsigned short*) p; 283 unsigned short* ps = (unsigned short*) p;
281 while (l-- > 0) { 284 while (l-- > 0) {
@@ -342,10 +345,6 @@ static inline void SMC_outsw (unsigned long a, int r, unsigned char* p, int l)
342 345
343#endif 346#endif
344 347
345#ifndef SMC_IRQ_FLAGS
346#define SMC_IRQ_FLAGS SA_TRIGGER_RISING
347#endif
348
349#ifdef SMC_USE_PXA_DMA 348#ifdef SMC_USE_PXA_DMA
350/* 349/*
351 * Let's use the DMA engine on the XScale PXA2xx for RX packets. This is 350 * Let's use the DMA engine on the XScale PXA2xx for RX packets. This is
@@ -441,10 +440,85 @@ smc_pxa_dma_irq(int dma, void *dummy, struct pt_regs *regs)
441#endif /* SMC_USE_PXA_DMA */ 440#endif /* SMC_USE_PXA_DMA */
442 441
443 442
444/* Because of bank switching, the LAN91x uses only 16 I/O ports */ 443/*
444 * Everything a particular hardware setup needs should have been defined
445 * at this point. Add stubs for the undefined cases, mainly to avoid
446 * compilation warnings since they'll be optimized away, or to prevent buggy
447 * use of them.
448 */
449
450#if ! SMC_CAN_USE_32BIT
451#define SMC_inl(ioaddr, reg) ({ BUG(); 0; })
452#define SMC_outl(x, ioaddr, reg) BUG()
453#define SMC_insl(a, r, p, l) BUG()
454#define SMC_outsl(a, r, p, l) BUG()
455#endif
456
457#if !defined(SMC_insl) || !defined(SMC_outsl)
458#define SMC_insl(a, r, p, l) BUG()
459#define SMC_outsl(a, r, p, l) BUG()
460#endif
461
462#if ! SMC_CAN_USE_16BIT
463
464/*
465 * Any 16-bit access is performed with two 8-bit accesses if the hardware
466 * can't do it directly. Most registers are 16-bit so those are mandatory.
467 */
468#define SMC_outw(x, ioaddr, reg) \
469 do { \
470 unsigned int __val16 = (x); \
471 SMC_outb( __val16, ioaddr, reg ); \
472 SMC_outb( __val16 >> 8, ioaddr, reg + (1 << SMC_IO_SHIFT));\
473 } while (0)
474#define SMC_inw(ioaddr, reg) \
475 ({ \
476 unsigned int __val16; \
477 __val16 = SMC_inb( ioaddr, reg ); \
478 __val16 |= SMC_inb( ioaddr, reg + (1 << SMC_IO_SHIFT)) << 8; \
479 __val16; \
480 })
481
482#define SMC_insw(a, r, p, l) BUG()
483#define SMC_outsw(a, r, p, l) BUG()
484
485#endif
486
487#if !defined(SMC_insw) || !defined(SMC_outsw)
488#define SMC_insw(a, r, p, l) BUG()
489#define SMC_outsw(a, r, p, l) BUG()
490#endif
491
492#if ! SMC_CAN_USE_8BIT
493#define SMC_inb(ioaddr, reg) ({ BUG(); 0; })
494#define SMC_outb(x, ioaddr, reg) BUG()
495#define SMC_insb(a, r, p, l) BUG()
496#define SMC_outsb(a, r, p, l) BUG()
497#endif
498
499#if !defined(SMC_insb) || !defined(SMC_outsb)
500#define SMC_insb(a, r, p, l) BUG()
501#define SMC_outsb(a, r, p, l) BUG()
502#endif
503
504#ifndef SMC_CAN_USE_DATACS
505#define SMC_CAN_USE_DATACS 0
506#endif
507
445#ifndef SMC_IO_SHIFT 508#ifndef SMC_IO_SHIFT
446#define SMC_IO_SHIFT 0 509#define SMC_IO_SHIFT 0
447#endif 510#endif
511
512#ifndef SMC_IRQ_FLAGS
513#define SMC_IRQ_FLAGS SA_TRIGGER_RISING
514#endif
515
516#ifndef SMC_INTERRUPT_PREAMBLE
517#define SMC_INTERRUPT_PREAMBLE
518#endif
519
520
521/* Because of bank switching, the LAN91x uses only 16 I/O ports */
448#define SMC_IO_EXTENT (16 << SMC_IO_SHIFT) 522#define SMC_IO_EXTENT (16 << SMC_IO_SHIFT)
449#define SMC_DATA_EXTENT (4) 523#define SMC_DATA_EXTENT (4)
450 524
@@ -817,6 +891,11 @@ static const char * chip_ids[ 16 ] = {
817 * Note: the following macros do *not* select the bank -- this must 891 * Note: the following macros do *not* select the bank -- this must
818 * be done separately as needed in the main code. The SMC_REG() macro 892 * be done separately as needed in the main code. The SMC_REG() macro
819 * only uses the bank argument for debugging purposes (when enabled). 893 * only uses the bank argument for debugging purposes (when enabled).
894 *
895 * Note: despite inline functions being safer, everything leading to this
896 * should preferably be macros to let BUG() display the line number in
897 * the core source code since we're interested in the top call site
898 * not in any inline function location.
820 */ 899 */
821 900
822#if SMC_DEBUG > 0 901#if SMC_DEBUG > 0
@@ -834,62 +913,142 @@ static const char * chip_ids[ 16 ] = {
834#define SMC_REG(reg, bank) (reg<<SMC_IO_SHIFT) 913#define SMC_REG(reg, bank) (reg<<SMC_IO_SHIFT)
835#endif 914#endif
836 915
837#if SMC_CAN_USE_8BIT 916/*
838#define SMC_GET_PN() SMC_inb( ioaddr, PN_REG ) 917 * Hack Alert: Some setups just can't write 8 or 16 bits reliably when not
839#define SMC_SET_PN(x) SMC_outb( x, ioaddr, PN_REG ) 918 * aligned to a 32 bit boundary. I tell you that does exist!
840#define SMC_GET_AR() SMC_inb( ioaddr, AR_REG ) 919 * Fortunately the affected register accesses can be easily worked around
841#define SMC_GET_TXFIFO() SMC_inb( ioaddr, TXFIFO_REG ) 920 * since we can write zeroes to the preceeding 16 bits without adverse
842#define SMC_GET_RXFIFO() SMC_inb( ioaddr, RXFIFO_REG ) 921 * effects and use a 32-bit access.
843#define SMC_GET_INT() SMC_inb( ioaddr, INT_REG ) 922 *
844#define SMC_ACK_INT(x) SMC_outb( x, ioaddr, INT_REG ) 923 * Enforce it on any 32-bit capable setup for now.
845#define SMC_GET_INT_MASK() SMC_inb( ioaddr, IM_REG ) 924 */
846#define SMC_SET_INT_MASK(x) SMC_outb( x, ioaddr, IM_REG ) 925#define SMC_MUST_ALIGN_WRITE SMC_CAN_USE_32BIT
847#else 926
848#define SMC_GET_PN() (SMC_inw( ioaddr, PN_REG ) & 0xFF) 927#define SMC_GET_PN() \
849#define SMC_SET_PN(x) SMC_outw( x, ioaddr, PN_REG ) 928 ( SMC_CAN_USE_8BIT ? (SMC_inb(ioaddr, PN_REG)) \
850#define SMC_GET_AR() (SMC_inw( ioaddr, PN_REG ) >> 8) 929 : (SMC_inw(ioaddr, PN_REG) & 0xFF) )
851#define SMC_GET_TXFIFO() (SMC_inw( ioaddr, TXFIFO_REG ) & 0xFF) 930
852#define SMC_GET_RXFIFO() (SMC_inw( ioaddr, TXFIFO_REG ) >> 8) 931#define SMC_SET_PN(x) \
853#define SMC_GET_INT() (SMC_inw( ioaddr, INT_REG ) & 0xFF) 932 do { \
933 if (SMC_MUST_ALIGN_WRITE) \
934 SMC_outl((x)<<16, ioaddr, SMC_REG(0, 2)); \
935 else if (SMC_CAN_USE_8BIT) \
936 SMC_outb(x, ioaddr, PN_REG); \
937 else \
938 SMC_outw(x, ioaddr, PN_REG); \
939 } while (0)
940
941#define SMC_GET_AR() \
942 ( SMC_CAN_USE_8BIT ? (SMC_inb(ioaddr, AR_REG)) \
943 : (SMC_inw(ioaddr, PN_REG) >> 8) )
944
945#define SMC_GET_TXFIFO() \
946 ( SMC_CAN_USE_8BIT ? (SMC_inb(ioaddr, TXFIFO_REG)) \
947 : (SMC_inw(ioaddr, TXFIFO_REG) & 0xFF) )
948
949#define SMC_GET_RXFIFO() \
950 ( SMC_CAN_USE_8BIT ? (SMC_inb(ioaddr, RXFIFO_REG)) \
951 : (SMC_inw(ioaddr, TXFIFO_REG) >> 8) )
952
953#define SMC_GET_INT() \
954 ( SMC_CAN_USE_8BIT ? (SMC_inb(ioaddr, INT_REG)) \
955 : (SMC_inw(ioaddr, INT_REG) & 0xFF) )
956
854#define SMC_ACK_INT(x) \ 957#define SMC_ACK_INT(x) \
855 do { \ 958 do { \
856 unsigned long __flags; \ 959 if (SMC_CAN_USE_8BIT) \
857 int __mask; \ 960 SMC_outb(x, ioaddr, INT_REG); \
858 local_irq_save(__flags); \ 961 else { \
859 __mask = SMC_inw( ioaddr, INT_REG ) & ~0xff; \ 962 unsigned long __flags; \
860 SMC_outw( __mask | (x), ioaddr, INT_REG ); \ 963 int __mask; \
861 local_irq_restore(__flags); \ 964 local_irq_save(__flags); \
965 __mask = SMC_inw( ioaddr, INT_REG ) & ~0xff; \
966 SMC_outw( __mask | (x), ioaddr, INT_REG ); \
967 local_irq_restore(__flags); \
968 } \
969 } while (0)
970
971#define SMC_GET_INT_MASK() \
972 ( SMC_CAN_USE_8BIT ? (SMC_inb(ioaddr, IM_REG)) \
973 : (SMC_inw( ioaddr, INT_REG ) >> 8) )
974
975#define SMC_SET_INT_MASK(x) \
976 do { \
977 if (SMC_CAN_USE_8BIT) \
978 SMC_outb(x, ioaddr, IM_REG); \
979 else \
980 SMC_outw((x) << 8, ioaddr, INT_REG); \
981 } while (0)
982
983#define SMC_CURRENT_BANK() SMC_inw(ioaddr, BANK_SELECT)
984
985#define SMC_SELECT_BANK(x) \
986 do { \
987 if (SMC_MUST_ALIGN_WRITE) \
988 SMC_outl((x)<<16, ioaddr, 12<<SMC_IO_SHIFT); \
989 else \
990 SMC_outw(x, ioaddr, BANK_SELECT); \
991 } while (0)
992
993#define SMC_GET_BASE() SMC_inw(ioaddr, BASE_REG)
994
995#define SMC_SET_BASE(x) SMC_outw(x, ioaddr, BASE_REG)
996
997#define SMC_GET_CONFIG() SMC_inw(ioaddr, CONFIG_REG)
998
999#define SMC_SET_CONFIG(x) SMC_outw(x, ioaddr, CONFIG_REG)
1000
1001#define SMC_GET_COUNTER() SMC_inw(ioaddr, COUNTER_REG)
1002
1003#define SMC_GET_CTL() SMC_inw(ioaddr, CTL_REG)
1004
1005#define SMC_SET_CTL(x) SMC_outw(x, ioaddr, CTL_REG)
1006
1007#define SMC_GET_MII() SMC_inw(ioaddr, MII_REG)
1008
1009#define SMC_SET_MII(x) SMC_outw(x, ioaddr, MII_REG)
1010
1011#define SMC_GET_MIR() SMC_inw(ioaddr, MIR_REG)
1012
1013#define SMC_SET_MIR(x) SMC_outw(x, ioaddr, MIR_REG)
1014
1015#define SMC_GET_MMU_CMD() SMC_inw(ioaddr, MMU_CMD_REG)
1016
1017#define SMC_SET_MMU_CMD(x) SMC_outw(x, ioaddr, MMU_CMD_REG)
1018
1019#define SMC_GET_FIFO() SMC_inw(ioaddr, FIFO_REG)
1020
1021#define SMC_GET_PTR() SMC_inw(ioaddr, PTR_REG)
1022
1023#define SMC_SET_PTR(x) \
1024 do { \
1025 if (SMC_MUST_ALIGN_WRITE) \
1026 SMC_outl((x)<<16, ioaddr, SMC_REG(4, 2)); \
1027 else \
1028 SMC_outw(x, ioaddr, PTR_REG); \
862 } while (0) 1029 } while (0)
863#define SMC_GET_INT_MASK() (SMC_inw( ioaddr, INT_REG ) >> 8)
864#define SMC_SET_INT_MASK(x) SMC_outw( (x) << 8, ioaddr, INT_REG )
865#endif
866 1030
867#define SMC_CURRENT_BANK() SMC_inw( ioaddr, BANK_SELECT ) 1031#define SMC_GET_EPH_STATUS() SMC_inw(ioaddr, EPH_STATUS_REG)
868#define SMC_SELECT_BANK(x) SMC_outw( x, ioaddr, BANK_SELECT ) 1032
869#define SMC_GET_BASE() SMC_inw( ioaddr, BASE_REG ) 1033#define SMC_GET_RCR() SMC_inw(ioaddr, RCR_REG)
870#define SMC_SET_BASE(x) SMC_outw( x, ioaddr, BASE_REG ) 1034
871#define SMC_GET_CONFIG() SMC_inw( ioaddr, CONFIG_REG ) 1035#define SMC_SET_RCR(x) SMC_outw(x, ioaddr, RCR_REG)
872#define SMC_SET_CONFIG(x) SMC_outw( x, ioaddr, CONFIG_REG ) 1036
873#define SMC_GET_COUNTER() SMC_inw( ioaddr, COUNTER_REG ) 1037#define SMC_GET_REV() SMC_inw(ioaddr, REV_REG)
874#define SMC_GET_CTL() SMC_inw( ioaddr, CTL_REG ) 1038
875#define SMC_SET_CTL(x) SMC_outw( x, ioaddr, CTL_REG ) 1039#define SMC_GET_RPC() SMC_inw(ioaddr, RPC_REG)
876#define SMC_GET_MII() SMC_inw( ioaddr, MII_REG ) 1040
877#define SMC_SET_MII(x) SMC_outw( x, ioaddr, MII_REG ) 1041#define SMC_SET_RPC(x) \
878#define SMC_GET_MIR() SMC_inw( ioaddr, MIR_REG ) 1042 do { \
879#define SMC_SET_MIR(x) SMC_outw( x, ioaddr, MIR_REG ) 1043 if (SMC_MUST_ALIGN_WRITE) \
880#define SMC_GET_MMU_CMD() SMC_inw( ioaddr, MMU_CMD_REG ) 1044 SMC_outl((x)<<16, ioaddr, SMC_REG(8, 0)); \
881#define SMC_SET_MMU_CMD(x) SMC_outw( x, ioaddr, MMU_CMD_REG ) 1045 else \
882#define SMC_GET_FIFO() SMC_inw( ioaddr, FIFO_REG ) 1046 SMC_outw(x, ioaddr, RPC_REG); \
883#define SMC_GET_PTR() SMC_inw( ioaddr, PTR_REG ) 1047 } while (0)
884#define SMC_SET_PTR(x) SMC_outw( x, ioaddr, PTR_REG ) 1048
885#define SMC_GET_EPH_STATUS() SMC_inw( ioaddr, EPH_STATUS_REG ) 1049#define SMC_GET_TCR() SMC_inw(ioaddr, TCR_REG)
886#define SMC_GET_RCR() SMC_inw( ioaddr, RCR_REG ) 1050
887#define SMC_SET_RCR(x) SMC_outw( x, ioaddr, RCR_REG ) 1051#define SMC_SET_TCR(x) SMC_outw(x, ioaddr, TCR_REG)
888#define SMC_GET_REV() SMC_inw( ioaddr, REV_REG )
889#define SMC_GET_RPC() SMC_inw( ioaddr, RPC_REG )
890#define SMC_SET_RPC(x) SMC_outw( x, ioaddr, RPC_REG )
891#define SMC_GET_TCR() SMC_inw( ioaddr, TCR_REG )
892#define SMC_SET_TCR(x) SMC_outw( x, ioaddr, TCR_REG )
893 1052
894#ifndef SMC_GET_MAC_ADDR 1053#ifndef SMC_GET_MAC_ADDR
895#define SMC_GET_MAC_ADDR(addr) \ 1054#define SMC_GET_MAC_ADDR(addr) \
@@ -920,151 +1079,84 @@ static const char * chip_ids[ 16 ] = {
920 SMC_outw( mt[6] | (mt[7] << 8), ioaddr, MCAST_REG4 ); \ 1079 SMC_outw( mt[6] | (mt[7] << 8), ioaddr, MCAST_REG4 ); \
921 } while (0) 1080 } while (0)
922 1081
923#if SMC_CAN_USE_32BIT
924/*
925 * Some setups just can't write 8 or 16 bits reliably when not aligned
926 * to a 32 bit boundary. I tell you that exists!
927 * We re-do the ones here that can be easily worked around if they can have
928 * their low parts written to 0 without adverse effects.
929 */
930#undef SMC_SELECT_BANK
931#define SMC_SELECT_BANK(x) SMC_outl( (x)<<16, ioaddr, 12<<SMC_IO_SHIFT )
932#undef SMC_SET_RPC
933#define SMC_SET_RPC(x) SMC_outl( (x)<<16, ioaddr, SMC_REG(8, 0) )
934#undef SMC_SET_PN
935#define SMC_SET_PN(x) SMC_outl( (x)<<16, ioaddr, SMC_REG(0, 2) )
936#undef SMC_SET_PTR
937#define SMC_SET_PTR(x) SMC_outl( (x)<<16, ioaddr, SMC_REG(4, 2) )
938#endif
939
940#if SMC_CAN_USE_32BIT
941#define SMC_PUT_PKT_HDR(status, length) \
942 SMC_outl( (status) | (length) << 16, ioaddr, DATA_REG )
943#define SMC_GET_PKT_HDR(status, length) \
944 do { \
945 unsigned int __val = SMC_inl( ioaddr, DATA_REG ); \
946 (status) = __val & 0xffff; \
947 (length) = __val >> 16; \
948 } while (0)
949#else
950#define SMC_PUT_PKT_HDR(status, length) \ 1082#define SMC_PUT_PKT_HDR(status, length) \
951 do { \ 1083 do { \
952 SMC_outw( status, ioaddr, DATA_REG ); \ 1084 if (SMC_CAN_USE_32BIT) \
953 SMC_outw( length, ioaddr, DATA_REG ); \ 1085 SMC_outl((status) | (length)<<16, ioaddr, DATA_REG); \
954 } while (0) 1086 else { \
955#define SMC_GET_PKT_HDR(status, length) \ 1087 SMC_outw(status, ioaddr, DATA_REG); \
956 do { \ 1088 SMC_outw(length, ioaddr, DATA_REG); \
957 (status) = SMC_inw( ioaddr, DATA_REG ); \ 1089 } \
958 (length) = SMC_inw( ioaddr, DATA_REG ); \
959 } while (0) 1090 } while (0)
960#endif
961 1091
962#if SMC_CAN_USE_32BIT 1092#define SMC_GET_PKT_HDR(status, length) \
963#define _SMC_PUSH_DATA(p, l) \
964 do { \ 1093 do { \
965 char *__ptr = (p); \ 1094 if (SMC_CAN_USE_32BIT) { \
966 int __len = (l); \ 1095 unsigned int __val = SMC_inl(ioaddr, DATA_REG); \
967 if (__len >= 2 && (unsigned long)__ptr & 2) { \ 1096 (status) = __val & 0xffff; \
968 __len -= 2; \ 1097 (length) = __val >> 16; \
969 SMC_outw( *(u16 *)__ptr, ioaddr, DATA_REG ); \ 1098 } else { \
970 __ptr += 2; \ 1099 (status) = SMC_inw(ioaddr, DATA_REG); \
971 } \ 1100 (length) = SMC_inw(ioaddr, DATA_REG); \
972 SMC_outsl( ioaddr, DATA_REG, __ptr, __len >> 2); \
973 if (__len & 2) { \
974 __ptr += (__len & ~3); \
975 SMC_outw( *((u16 *)__ptr), ioaddr, DATA_REG ); \
976 } \ 1101 } \
977 } while (0) 1102 } while (0)
978#define _SMC_PULL_DATA(p, l) \
979 do { \
980 char *__ptr = (p); \
981 int __len = (l); \
982 if ((unsigned long)__ptr & 2) { \
983 /* \
984 * We want 32bit alignment here. \
985 * Since some buses perform a full 32bit \
986 * fetch even for 16bit data we can't use \
987 * SMC_inw() here. Back both source (on chip \
988 * and destination) pointers of 2 bytes. \
989 */ \
990 __ptr -= 2; \
991 __len += 2; \
992 SMC_SET_PTR( 2|PTR_READ|PTR_RCV|PTR_AUTOINC ); \
993 } \
994 __len += 2; \
995 SMC_insl( ioaddr, DATA_REG, __ptr, __len >> 2); \
996 } while (0)
997#elif SMC_CAN_USE_16BIT
998#define _SMC_PUSH_DATA(p, l) SMC_outsw( ioaddr, DATA_REG, p, (l) >> 1 )
999#define _SMC_PULL_DATA(p, l) SMC_insw ( ioaddr, DATA_REG, p, (l) >> 1 )
1000#elif SMC_CAN_USE_8BIT
1001#define _SMC_PUSH_DATA(p, l) SMC_outsb( ioaddr, DATA_REG, p, l )
1002#define _SMC_PULL_DATA(p, l) SMC_insb ( ioaddr, DATA_REG, p, l )
1003#endif
1004 1103
1005#if ! SMC_CAN_USE_16BIT 1104#define SMC_PUSH_DATA(p, l) \
1006#define SMC_outw(x, ioaddr, reg) \
1007 do { \ 1105 do { \
1008 unsigned int __val16 = (x); \ 1106 if (SMC_CAN_USE_32BIT) { \
1009 SMC_outb( __val16, ioaddr, reg ); \ 1107 void *__ptr = (p); \
1010 SMC_outb( __val16 >> 8, ioaddr, reg + (1 << SMC_IO_SHIFT));\ 1108 int __len = (l); \
1109 void *__ioaddr = ioaddr; \
1110 if (__len >= 2 && (unsigned long)__ptr & 2) { \
1111 __len -= 2; \
1112 SMC_outw(*(u16 *)__ptr, ioaddr, DATA_REG); \
1113 __ptr += 2; \
1114 } \
1115 if (SMC_CAN_USE_DATACS && lp->datacs) \
1116 __ioaddr = lp->datacs; \
1117 SMC_outsl(__ioaddr, DATA_REG, __ptr, __len>>2); \
1118 if (__len & 2) { \
1119 __ptr += (__len & ~3); \
1120 SMC_outw(*((u16 *)__ptr), ioaddr, DATA_REG); \
1121 } \
1122 } else if (SMC_CAN_USE_16BIT) \
1123 SMC_outsw(ioaddr, DATA_REG, p, (l) >> 1); \
1124 else if (SMC_CAN_USE_8BIT) \
1125 SMC_outsb(ioaddr, DATA_REG, p, l); \
1011 } while (0) 1126 } while (0)
1012#define SMC_inw(ioaddr, reg) \
1013 ({ \
1014 unsigned int __val16; \
1015 __val16 = SMC_inb( ioaddr, reg ); \
1016 __val16 |= SMC_inb( ioaddr, reg + (1 << SMC_IO_SHIFT)) << 8; \
1017 __val16; \
1018 })
1019#endif
1020
1021#ifdef SMC_CAN_USE_DATACS
1022#define SMC_PUSH_DATA(p, l) \
1023 if ( lp->datacs ) { \
1024 unsigned char *__ptr = (p); \
1025 int __len = (l); \
1026 if (__len >= 2 && (unsigned long)__ptr & 2) { \
1027 __len -= 2; \
1028 SMC_outw( *((u16 *)__ptr), ioaddr, DATA_REG ); \
1029 __ptr += 2; \
1030 } \
1031 outsl(lp->datacs, __ptr, __len >> 2); \
1032 if (__len & 2) { \
1033 __ptr += (__len & ~3); \
1034 SMC_outw( *((u16 *)__ptr), ioaddr, DATA_REG ); \
1035 } \
1036 } else { \
1037 _SMC_PUSH_DATA(p, l); \
1038 }
1039 1127
1040#define SMC_PULL_DATA(p, l) \ 1128#define SMC_PULL_DATA(p, l) \
1041 if ( lp->datacs ) { \ 1129 do { \
1042 unsigned char *__ptr = (p); \ 1130 if (SMC_CAN_USE_32BIT) { \
1043 int __len = (l); \ 1131 void *__ptr = (p); \
1044 if ((unsigned long)__ptr & 2) { \ 1132 int __len = (l); \
1045 /* \ 1133 void *__ioaddr = ioaddr; \
1046 * We want 32bit alignment here. \ 1134 if ((unsigned long)__ptr & 2) { \
1047 * Since some buses perform a full 32bit \ 1135 /* \
1048 * fetch even for 16bit data we can't use \ 1136 * We want 32bit alignment here. \
1049 * SMC_inw() here. Back both source (on chip \ 1137 * Since some buses perform a full \
1050 * and destination) pointers of 2 bytes. \ 1138 * 32bit fetch even for 16bit data \
1051 */ \ 1139 * we can't use SMC_inw() here. \
1052 __ptr -= 2; \ 1140 * Back both source (on-chip) and \
1141 * destination pointers of 2 bytes. \
1142 * This is possible since the call to \
1143 * SMC_GET_PKT_HDR() already advanced \
1144 * the source pointer of 4 bytes, and \
1145 * the skb_reserve(skb, 2) advanced \
1146 * the destination pointer of 2 bytes. \
1147 */ \
1148 __ptr -= 2; \
1149 __len += 2; \
1150 SMC_SET_PTR(2|PTR_READ|PTR_RCV|PTR_AUTOINC); \
1151 } \
1152 if (SMC_CAN_USE_DATACS && lp->datacs) \
1153 __ioaddr = lp->datacs; \
1053 __len += 2; \ 1154 __len += 2; \
1054 SMC_SET_PTR( 2|PTR_READ|PTR_RCV|PTR_AUTOINC ); \ 1155 SMC_insl(__ioaddr, DATA_REG, __ptr, __len>>2); \
1055 } \ 1156 } else if (SMC_CAN_USE_16BIT) \
1056 __len += 2; \ 1157 SMC_insw(ioaddr, DATA_REG, p, (l) >> 1); \
1057 insl( lp->datacs, __ptr, __len >> 2); \ 1158 else if (SMC_CAN_USE_8BIT) \
1058 } else { \ 1159 SMC_insb(ioaddr, DATA_REG, p, l); \
1059 _SMC_PULL_DATA(p, l); \ 1160 } while (0)
1060 }
1061#else
1062#define SMC_PUSH_DATA(p, l) _SMC_PUSH_DATA(p, l)
1063#define SMC_PULL_DATA(p, l) _SMC_PULL_DATA(p, l)
1064#endif
1065
1066#if !defined (SMC_INTERRUPT_PREAMBLE)
1067# define SMC_INTERRUPT_PREAMBLE
1068#endif
1069 1161
1070#endif /* _SMC91X_H_ */ 1162#endif /* _SMC91X_H_ */
diff --git a/drivers/net/sungem.c b/drivers/net/sungem.c
index 28ce47a02408..38cd30cb7c75 100644
--- a/drivers/net/sungem.c
+++ b/drivers/net/sungem.c
@@ -55,6 +55,7 @@
55#include <linux/workqueue.h> 55#include <linux/workqueue.h>
56#include <linux/if_vlan.h> 56#include <linux/if_vlan.h>
57#include <linux/bitops.h> 57#include <linux/bitops.h>
58#include <linux/mutex.h>
58 59
59#include <asm/system.h> 60#include <asm/system.h>
60#include <asm/io.h> 61#include <asm/io.h>
@@ -2284,7 +2285,7 @@ static void gem_reset_task(void *data)
2284{ 2285{
2285 struct gem *gp = (struct gem *) data; 2286 struct gem *gp = (struct gem *) data;
2286 2287
2287 down(&gp->pm_sem); 2288 mutex_lock(&gp->pm_mutex);
2288 2289
2289 netif_poll_disable(gp->dev); 2290 netif_poll_disable(gp->dev);
2290 2291
@@ -2311,7 +2312,7 @@ static void gem_reset_task(void *data)
2311 2312
2312 netif_poll_enable(gp->dev); 2313 netif_poll_enable(gp->dev);
2313 2314
2314 up(&gp->pm_sem); 2315 mutex_unlock(&gp->pm_mutex);
2315} 2316}
2316 2317
2317 2318
@@ -2320,14 +2321,14 @@ static int gem_open(struct net_device *dev)
2320 struct gem *gp = dev->priv; 2321 struct gem *gp = dev->priv;
2321 int rc = 0; 2322 int rc = 0;
2322 2323
2323 down(&gp->pm_sem); 2324 mutex_lock(&gp->pm_mutex);
2324 2325
2325 /* We need the cell enabled */ 2326 /* We need the cell enabled */
2326 if (!gp->asleep) 2327 if (!gp->asleep)
2327 rc = gem_do_start(dev); 2328 rc = gem_do_start(dev);
2328 gp->opened = (rc == 0); 2329 gp->opened = (rc == 0);
2329 2330
2330 up(&gp->pm_sem); 2331 mutex_unlock(&gp->pm_mutex);
2331 2332
2332 return rc; 2333 return rc;
2333} 2334}
@@ -2340,13 +2341,13 @@ static int gem_close(struct net_device *dev)
2340 * our caller (dev_close) already did it for us 2341 * our caller (dev_close) already did it for us
2341 */ 2342 */
2342 2343
2343 down(&gp->pm_sem); 2344 mutex_lock(&gp->pm_mutex);
2344 2345
2345 gp->opened = 0; 2346 gp->opened = 0;
2346 if (!gp->asleep) 2347 if (!gp->asleep)
2347 gem_do_stop(dev, 0); 2348 gem_do_stop(dev, 0);
2348 2349
2349 up(&gp->pm_sem); 2350 mutex_unlock(&gp->pm_mutex);
2350 2351
2351 return 0; 2352 return 0;
2352} 2353}
@@ -2358,7 +2359,7 @@ static int gem_suspend(struct pci_dev *pdev, pm_message_t state)
2358 struct gem *gp = dev->priv; 2359 struct gem *gp = dev->priv;
2359 unsigned long flags; 2360 unsigned long flags;
2360 2361
2361 down(&gp->pm_sem); 2362 mutex_lock(&gp->pm_mutex);
2362 2363
2363 netif_poll_disable(dev); 2364 netif_poll_disable(dev);
2364 2365
@@ -2391,11 +2392,11 @@ static int gem_suspend(struct pci_dev *pdev, pm_message_t state)
2391 /* Stop the link timer */ 2392 /* Stop the link timer */
2392 del_timer_sync(&gp->link_timer); 2393 del_timer_sync(&gp->link_timer);
2393 2394
2394 /* Now we release the semaphore to not block the reset task who 2395 /* Now we release the mutex to not block the reset task who
2395 * can take it too. We are marked asleep, so there will be no 2396 * can take it too. We are marked asleep, so there will be no
2396 * conflict here 2397 * conflict here
2397 */ 2398 */
2398 up(&gp->pm_sem); 2399 mutex_unlock(&gp->pm_mutex);
2399 2400
2400 /* Wait for a pending reset task to complete */ 2401 /* Wait for a pending reset task to complete */
2401 while (gp->reset_task_pending) 2402 while (gp->reset_task_pending)
@@ -2424,7 +2425,7 @@ static int gem_resume(struct pci_dev *pdev)
2424 2425
2425 printk(KERN_INFO "%s: resuming\n", dev->name); 2426 printk(KERN_INFO "%s: resuming\n", dev->name);
2426 2427
2427 down(&gp->pm_sem); 2428 mutex_lock(&gp->pm_mutex);
2428 2429
2429 /* Keep the cell enabled during the entire operation, no need to 2430 /* Keep the cell enabled during the entire operation, no need to
2430 * take a lock here tho since nothing else can happen while we are 2431 * take a lock here tho since nothing else can happen while we are
@@ -2440,7 +2441,7 @@ static int gem_resume(struct pci_dev *pdev)
2440 * still asleep, a new sleep cycle may bring it back 2441 * still asleep, a new sleep cycle may bring it back
2441 */ 2442 */
2442 gem_put_cell(gp); 2443 gem_put_cell(gp);
2443 up(&gp->pm_sem); 2444 mutex_unlock(&gp->pm_mutex);
2444 return 0; 2445 return 0;
2445 } 2446 }
2446 pci_set_master(gp->pdev); 2447 pci_set_master(gp->pdev);
@@ -2486,7 +2487,7 @@ static int gem_resume(struct pci_dev *pdev)
2486 2487
2487 netif_poll_enable(dev); 2488 netif_poll_enable(dev);
2488 2489
2489 up(&gp->pm_sem); 2490 mutex_unlock(&gp->pm_mutex);
2490 2491
2491 return 0; 2492 return 0;
2492} 2493}
@@ -2591,7 +2592,7 @@ static int gem_change_mtu(struct net_device *dev, int new_mtu)
2591 return 0; 2592 return 0;
2592 } 2593 }
2593 2594
2594 down(&gp->pm_sem); 2595 mutex_lock(&gp->pm_mutex);
2595 spin_lock_irq(&gp->lock); 2596 spin_lock_irq(&gp->lock);
2596 spin_lock(&gp->tx_lock); 2597 spin_lock(&gp->tx_lock);
2597 dev->mtu = new_mtu; 2598 dev->mtu = new_mtu;
@@ -2602,7 +2603,7 @@ static int gem_change_mtu(struct net_device *dev, int new_mtu)
2602 } 2603 }
2603 spin_unlock(&gp->tx_lock); 2604 spin_unlock(&gp->tx_lock);
2604 spin_unlock_irq(&gp->lock); 2605 spin_unlock_irq(&gp->lock);
2605 up(&gp->pm_sem); 2606 mutex_unlock(&gp->pm_mutex);
2606 2607
2607 return 0; 2608 return 0;
2608} 2609}
@@ -2771,10 +2772,10 @@ static int gem_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2771 int rc = -EOPNOTSUPP; 2772 int rc = -EOPNOTSUPP;
2772 unsigned long flags; 2773 unsigned long flags;
2773 2774
2774 /* Hold the PM semaphore while doing ioctl's or we may collide 2775 /* Hold the PM mutex while doing ioctl's or we may collide
2775 * with power management. 2776 * with power management.
2776 */ 2777 */
2777 down(&gp->pm_sem); 2778 mutex_lock(&gp->pm_mutex);
2778 2779
2779 spin_lock_irqsave(&gp->lock, flags); 2780 spin_lock_irqsave(&gp->lock, flags);
2780 gem_get_cell(gp); 2781 gem_get_cell(gp);
@@ -2812,7 +2813,7 @@ static int gem_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2812 gem_put_cell(gp); 2813 gem_put_cell(gp);
2813 spin_unlock_irqrestore(&gp->lock, flags); 2814 spin_unlock_irqrestore(&gp->lock, flags);
2814 2815
2815 up(&gp->pm_sem); 2816 mutex_unlock(&gp->pm_mutex);
2816 2817
2817 return rc; 2818 return rc;
2818} 2819}
@@ -3033,7 +3034,7 @@ static int __devinit gem_init_one(struct pci_dev *pdev,
3033 3034
3034 spin_lock_init(&gp->lock); 3035 spin_lock_init(&gp->lock);
3035 spin_lock_init(&gp->tx_lock); 3036 spin_lock_init(&gp->tx_lock);
3036 init_MUTEX(&gp->pm_sem); 3037 mutex_init(&gp->pm_mutex);
3037 3038
3038 init_timer(&gp->link_timer); 3039 init_timer(&gp->link_timer);
3039 gp->link_timer.function = gem_link_timer; 3040 gp->link_timer.function = gem_link_timer;
diff --git a/drivers/net/sungem.h b/drivers/net/sungem.h
index 13006d759ad8..89847215d006 100644
--- a/drivers/net/sungem.h
+++ b/drivers/net/sungem.h
@@ -980,15 +980,15 @@ struct gem {
980 int tx_new, tx_old; 980 int tx_new, tx_old;
981 981
982 unsigned int has_wol : 1; /* chip supports wake-on-lan */ 982 unsigned int has_wol : 1; /* chip supports wake-on-lan */
983 unsigned int asleep : 1; /* chip asleep, protected by pm_sem */ 983 unsigned int asleep : 1; /* chip asleep, protected by pm_mutex */
984 unsigned int asleep_wol : 1; /* was asleep with WOL enabled */ 984 unsigned int asleep_wol : 1; /* was asleep with WOL enabled */
985 unsigned int opened : 1; /* driver opened, protected by pm_sem */ 985 unsigned int opened : 1; /* driver opened, protected by pm_mutex */
986 unsigned int running : 1; /* chip running, protected by lock */ 986 unsigned int running : 1; /* chip running, protected by lock */
987 987
988 /* cell enable count, protected by lock */ 988 /* cell enable count, protected by lock */
989 int cell_enabled; 989 int cell_enabled;
990 990
991 struct semaphore pm_sem; 991 struct mutex pm_mutex;
992 992
993 u32 msg_enable; 993 u32 msg_enable;
994 u32 status; 994 u32 status;
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 6c6c5498899f..e03d1ae50c3e 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -69,8 +69,8 @@
69 69
70#define DRV_MODULE_NAME "tg3" 70#define DRV_MODULE_NAME "tg3"
71#define PFX DRV_MODULE_NAME ": " 71#define PFX DRV_MODULE_NAME ": "
72#define DRV_MODULE_VERSION "3.49" 72#define DRV_MODULE_VERSION "3.52"
73#define DRV_MODULE_RELDATE "Feb 2, 2006" 73#define DRV_MODULE_RELDATE "Mar 06, 2006"
74 74
75#define TG3_DEF_MAC_MODE 0 75#define TG3_DEF_MAC_MODE 0
76#define TG3_DEF_RX_MODE 0 76#define TG3_DEF_RX_MODE 0
@@ -221,10 +221,22 @@ static struct pci_device_id tg3_pci_tbl[] = {
221 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 221 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
222 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F, 222 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F,
223 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 223 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
224 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754,
225 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
226 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M,
227 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
228 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787,
229 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
230 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M,
231 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
224 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714, 232 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714,
225 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 233 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
234 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S,
235 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
226 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715, 236 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715,
227 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 237 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
238 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S,
239 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
228 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780, 240 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780,
229 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 241 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
230 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S, 242 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S,
@@ -534,6 +546,9 @@ static void tg3_enable_ints(struct tg3 *tp)
534 (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); 546 (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
535 tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 547 tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
536 (tp->last_tag << 24)); 548 (tp->last_tag << 24));
549 if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
550 tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
551 (tp->last_tag << 24));
537 tg3_cond_int(tp); 552 tg3_cond_int(tp);
538} 553}
539 554
@@ -1038,9 +1053,11 @@ static void tg3_frob_aux_power(struct tg3 *tp)
1038 struct net_device *dev_peer; 1053 struct net_device *dev_peer;
1039 1054
1040 dev_peer = pci_get_drvdata(tp->pdev_peer); 1055 dev_peer = pci_get_drvdata(tp->pdev_peer);
1056 /* remove_one() may have been run on the peer. */
1041 if (!dev_peer) 1057 if (!dev_peer)
1042 BUG(); 1058 tp_peer = tp;
1043 tp_peer = netdev_priv(dev_peer); 1059 else
1060 tp_peer = netdev_priv(dev_peer);
1044 } 1061 }
1045 1062
1046 if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 || 1063 if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
@@ -1131,7 +1148,7 @@ static int tg3_halt_cpu(struct tg3 *, u32);
1131static int tg3_nvram_lock(struct tg3 *); 1148static int tg3_nvram_lock(struct tg3 *);
1132static void tg3_nvram_unlock(struct tg3 *); 1149static void tg3_nvram_unlock(struct tg3 *);
1133 1150
1134static int tg3_set_power_state(struct tg3 *tp, int state) 1151static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
1135{ 1152{
1136 u32 misc_host_ctrl; 1153 u32 misc_host_ctrl;
1137 u16 power_control, power_caps; 1154 u16 power_control, power_caps;
@@ -1150,7 +1167,7 @@ static int tg3_set_power_state(struct tg3 *tp, int state)
1150 power_control |= PCI_PM_CTRL_PME_STATUS; 1167 power_control |= PCI_PM_CTRL_PME_STATUS;
1151 power_control &= ~(PCI_PM_CTRL_STATE_MASK); 1168 power_control &= ~(PCI_PM_CTRL_STATE_MASK);
1152 switch (state) { 1169 switch (state) {
1153 case 0: 1170 case PCI_D0:
1154 power_control |= 0; 1171 power_control |= 0;
1155 pci_write_config_word(tp->pdev, 1172 pci_write_config_word(tp->pdev,
1156 pm + PCI_PM_CTRL, 1173 pm + PCI_PM_CTRL,
@@ -1163,15 +1180,15 @@ static int tg3_set_power_state(struct tg3 *tp, int state)
1163 1180
1164 return 0; 1181 return 0;
1165 1182
1166 case 1: 1183 case PCI_D1:
1167 power_control |= 1; 1184 power_control |= 1;
1168 break; 1185 break;
1169 1186
1170 case 2: 1187 case PCI_D2:
1171 power_control |= 2; 1188 power_control |= 2;
1172 break; 1189 break;
1173 1190
1174 case 3: 1191 case PCI_D3hot:
1175 power_control |= 3; 1192 power_control |= 3;
1176 break; 1193 break;
1177 1194
@@ -2680,6 +2697,12 @@ static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
2680 2697
2681 err |= tg3_readphy(tp, MII_BMSR, &bmsr); 2698 err |= tg3_readphy(tp, MII_BMSR, &bmsr);
2682 err |= tg3_readphy(tp, MII_BMSR, &bmsr); 2699 err |= tg3_readphy(tp, MII_BMSR, &bmsr);
2700 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
2701 if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
2702 bmsr |= BMSR_LSTATUS;
2703 else
2704 bmsr &= ~BMSR_LSTATUS;
2705 }
2683 2706
2684 err |= tg3_readphy(tp, MII_BMCR, &bmcr); 2707 err |= tg3_readphy(tp, MII_BMCR, &bmcr);
2685 2708
@@ -2748,6 +2771,13 @@ static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
2748 bmcr = new_bmcr; 2771 bmcr = new_bmcr;
2749 err |= tg3_readphy(tp, MII_BMSR, &bmsr); 2772 err |= tg3_readphy(tp, MII_BMSR, &bmsr);
2750 err |= tg3_readphy(tp, MII_BMSR, &bmsr); 2773 err |= tg3_readphy(tp, MII_BMSR, &bmsr);
2774 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
2775 ASIC_REV_5714) {
2776 if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
2777 bmsr |= BMSR_LSTATUS;
2778 else
2779 bmsr &= ~BMSR_LSTATUS;
2780 }
2751 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT; 2781 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
2752 } 2782 }
2753 } 2783 }
@@ -3338,6 +3368,23 @@ static inline void tg3_full_unlock(struct tg3 *tp)
3338 spin_unlock_bh(&tp->lock); 3368 spin_unlock_bh(&tp->lock);
3339} 3369}
3340 3370
3371/* One-shot MSI handler - Chip automatically disables interrupt
3372 * after sending MSI so driver doesn't have to do it.
3373 */
3374static irqreturn_t tg3_msi_1shot(int irq, void *dev_id, struct pt_regs *regs)
3375{
3376 struct net_device *dev = dev_id;
3377 struct tg3 *tp = netdev_priv(dev);
3378
3379 prefetch(tp->hw_status);
3380 prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
3381
3382 if (likely(!tg3_irq_sync(tp)))
3383 netif_rx_schedule(dev); /* schedule NAPI poll */
3384
3385 return IRQ_HANDLED;
3386}
3387
3341/* MSI ISR - No need to check for interrupt sharing and no need to 3388/* MSI ISR - No need to check for interrupt sharing and no need to
3342 * flush status block and interrupt mailbox. PCI ordering rules 3389 * flush status block and interrupt mailbox. PCI ordering rules
3343 * guarantee that MSI will arrive after the status block. 3390 * guarantee that MSI will arrive after the status block.
@@ -3628,11 +3675,139 @@ static void tg3_set_txd(struct tg3 *tp, int entry,
3628 txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT; 3675 txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
3629} 3676}
3630 3677
3678/* hard_start_xmit for devices that don't have any bugs and
3679 * support TG3_FLG2_HW_TSO_2 only.
3680 */
3631static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev) 3681static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
3632{ 3682{
3633 struct tg3 *tp = netdev_priv(dev); 3683 struct tg3 *tp = netdev_priv(dev);
3634 dma_addr_t mapping; 3684 dma_addr_t mapping;
3635 u32 len, entry, base_flags, mss; 3685 u32 len, entry, base_flags, mss;
3686
3687 len = skb_headlen(skb);
3688
3689 /* No BH disabling for tx_lock here. We are running in BH disabled
3690 * context and TX reclaim runs via tp->poll inside of a software
3691 * interrupt. Furthermore, IRQ processing runs lockless so we have
3692 * no IRQ context deadlocks to worry about either. Rejoice!
3693 */
3694 if (!spin_trylock(&tp->tx_lock))
3695 return NETDEV_TX_LOCKED;
3696
3697 if (unlikely(TX_BUFFS_AVAIL(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
3698 if (!netif_queue_stopped(dev)) {
3699 netif_stop_queue(dev);
3700
3701 /* This is a hard error, log it. */
3702 printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
3703 "queue awake!\n", dev->name);
3704 }
3705 spin_unlock(&tp->tx_lock);
3706 return NETDEV_TX_BUSY;
3707 }
3708
3709 entry = tp->tx_prod;
3710 base_flags = 0;
3711#if TG3_TSO_SUPPORT != 0
3712 mss = 0;
3713 if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
3714 (mss = skb_shinfo(skb)->tso_size) != 0) {
3715 int tcp_opt_len, ip_tcp_len;
3716
3717 if (skb_header_cloned(skb) &&
3718 pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
3719 dev_kfree_skb(skb);
3720 goto out_unlock;
3721 }
3722
3723 tcp_opt_len = ((skb->h.th->doff - 5) * 4);
3724 ip_tcp_len = (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr);
3725
3726 base_flags |= (TXD_FLAG_CPU_PRE_DMA |
3727 TXD_FLAG_CPU_POST_DMA);
3728
3729 skb->nh.iph->check = 0;
3730 skb->nh.iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
3731
3732 skb->h.th->check = 0;
3733
3734 mss |= (ip_tcp_len + tcp_opt_len) << 9;
3735 }
3736 else if (skb->ip_summed == CHECKSUM_HW)
3737 base_flags |= TXD_FLAG_TCPUDP_CSUM;
3738#else
3739 mss = 0;
3740 if (skb->ip_summed == CHECKSUM_HW)
3741 base_flags |= TXD_FLAG_TCPUDP_CSUM;
3742#endif
3743#if TG3_VLAN_TAG_USED
3744 if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
3745 base_flags |= (TXD_FLAG_VLAN |
3746 (vlan_tx_tag_get(skb) << 16));
3747#endif
3748
3749 /* Queue skb data, a.k.a. the main skb fragment. */
3750 mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
3751
3752 tp->tx_buffers[entry].skb = skb;
3753 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
3754
3755 tg3_set_txd(tp, entry, mapping, len, base_flags,
3756 (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
3757
3758 entry = NEXT_TX(entry);
3759
3760 /* Now loop through additional data fragments, and queue them. */
3761 if (skb_shinfo(skb)->nr_frags > 0) {
3762 unsigned int i, last;
3763
3764 last = skb_shinfo(skb)->nr_frags - 1;
3765 for (i = 0; i <= last; i++) {
3766 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
3767
3768 len = frag->size;
3769 mapping = pci_map_page(tp->pdev,
3770 frag->page,
3771 frag->page_offset,
3772 len, PCI_DMA_TODEVICE);
3773
3774 tp->tx_buffers[entry].skb = NULL;
3775 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
3776
3777 tg3_set_txd(tp, entry, mapping, len,
3778 base_flags, (i == last) | (mss << 1));
3779
3780 entry = NEXT_TX(entry);
3781 }
3782 }
3783
3784 /* Packets are ready, update Tx producer idx local and on card. */
3785 tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
3786
3787 tp->tx_prod = entry;
3788 if (TX_BUFFS_AVAIL(tp) <= (MAX_SKB_FRAGS + 1)) {
3789 netif_stop_queue(dev);
3790 if (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH)
3791 netif_wake_queue(tp->dev);
3792 }
3793
3794out_unlock:
3795 mmiowb();
3796 spin_unlock(&tp->tx_lock);
3797
3798 dev->trans_start = jiffies;
3799
3800 return NETDEV_TX_OK;
3801}
3802
3803/* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
3804 * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
3805 */
3806static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
3807{
3808 struct tg3 *tp = netdev_priv(dev);
3809 dma_addr_t mapping;
3810 u32 len, entry, base_flags, mss;
3636 int would_hit_hwbug; 3811 int would_hit_hwbug;
3637 3812
3638 len = skb_headlen(skb); 3813 len = skb_headlen(skb);
@@ -4369,6 +4544,10 @@ static int tg3_chip_reset(struct tg3 *tp)
4369 tp->nvram_lock_cnt = 0; 4544 tp->nvram_lock_cnt = 0;
4370 } 4545 }
4371 4546
4547 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
4548 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
4549 tw32(GRC_FASTBOOT_PC, 0);
4550
4372 /* 4551 /*
4373 * We must avoid the readl() that normally takes place. 4552 * We must avoid the readl() that normally takes place.
4374 * It locks machines, causes machine checks, and other 4553 * It locks machines, causes machine checks, and other
@@ -5518,6 +5697,9 @@ static int tg3_set_mac_addr(struct net_device *dev, void *p)
5518 5697
5519 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); 5698 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
5520 5699
5700 if (!netif_running(dev))
5701 return 0;
5702
5521 spin_lock_bh(&tp->lock); 5703 spin_lock_bh(&tp->lock);
5522 __tg3_set_mac_addr(tp); 5704 __tg3_set_mac_addr(tp);
5523 spin_unlock_bh(&tp->lock); 5705 spin_unlock_bh(&tp->lock);
@@ -5585,6 +5767,9 @@ static int tg3_reset_hw(struct tg3 *tp)
5585 tg3_abort_hw(tp, 1); 5767 tg3_abort_hw(tp, 1);
5586 } 5768 }
5587 5769
5770 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
5771 tg3_phy_reset(tp);
5772
5588 err = tg3_chip_reset(tp); 5773 err = tg3_chip_reset(tp);
5589 if (err) 5774 if (err)
5590 return err; 5775 return err;
@@ -5993,6 +6178,10 @@ static int tg3_reset_hw(struct tg3 *tp)
5993 } 6178 }
5994 } 6179 }
5995 6180
6181 /* Enable host coalescing bug fix */
6182 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
6183 val |= (1 << 29);
6184
5996 tw32_f(WDMAC_MODE, val); 6185 tw32_f(WDMAC_MODE, val);
5997 udelay(40); 6186 udelay(40);
5998 6187
@@ -6097,6 +6286,17 @@ static int tg3_reset_hw(struct tg3 *tp)
6097 tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG; 6286 tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
6098 } 6287 }
6099 6288
6289 if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) &&
6290 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
6291 u32 tmp;
6292
6293 tmp = tr32(SERDES_RX_CTRL);
6294 tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT);
6295 tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT;
6296 tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT;
6297 tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
6298 }
6299
6100 err = tg3_setup_phy(tp, 1); 6300 err = tg3_setup_phy(tp, 1);
6101 if (err) 6301 if (err)
6102 return err; 6302 return err;
@@ -6175,7 +6375,7 @@ static int tg3_init_hw(struct tg3 *tp)
6175 int err; 6375 int err;
6176 6376
6177 /* Force the chip into D0. */ 6377 /* Force the chip into D0. */
6178 err = tg3_set_power_state(tp, 0); 6378 err = tg3_set_power_state(tp, PCI_D0);
6179 if (err) 6379 if (err)
6180 goto out; 6380 goto out;
6181 6381
@@ -6331,6 +6531,26 @@ static void tg3_timer(unsigned long __opaque)
6331 add_timer(&tp->timer); 6531 add_timer(&tp->timer);
6332} 6532}
6333 6533
6534static int tg3_request_irq(struct tg3 *tp)
6535{
6536 irqreturn_t (*fn)(int, void *, struct pt_regs *);
6537 unsigned long flags;
6538 struct net_device *dev = tp->dev;
6539
6540 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
6541 fn = tg3_msi;
6542 if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
6543 fn = tg3_msi_1shot;
6544 flags = SA_SAMPLE_RANDOM;
6545 } else {
6546 fn = tg3_interrupt;
6547 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
6548 fn = tg3_interrupt_tagged;
6549 flags = SA_SHIRQ | SA_SAMPLE_RANDOM;
6550 }
6551 return (request_irq(tp->pdev->irq, fn, flags, dev->name, dev));
6552}
6553
6334static int tg3_test_interrupt(struct tg3 *tp) 6554static int tg3_test_interrupt(struct tg3 *tp)
6335{ 6555{
6336 struct net_device *dev = tp->dev; 6556 struct net_device *dev = tp->dev;
@@ -6367,16 +6587,7 @@ static int tg3_test_interrupt(struct tg3 *tp)
6367 6587
6368 free_irq(tp->pdev->irq, dev); 6588 free_irq(tp->pdev->irq, dev);
6369 6589
6370 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) 6590 err = tg3_request_irq(tp);
6371 err = request_irq(tp->pdev->irq, tg3_msi,
6372 SA_SAMPLE_RANDOM, dev->name, dev);
6373 else {
6374 irqreturn_t (*fn)(int, void *, struct pt_regs *)=tg3_interrupt;
6375 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
6376 fn = tg3_interrupt_tagged;
6377 err = request_irq(tp->pdev->irq, fn,
6378 SA_SHIRQ | SA_SAMPLE_RANDOM, dev->name, dev);
6379 }
6380 6591
6381 if (err) 6592 if (err)
6382 return err; 6593 return err;
@@ -6428,14 +6639,7 @@ static int tg3_test_msi(struct tg3 *tp)
6428 6639
6429 tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI; 6640 tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
6430 6641
6431 { 6642 err = tg3_request_irq(tp);
6432 irqreturn_t (*fn)(int, void *, struct pt_regs *)=tg3_interrupt;
6433 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
6434 fn = tg3_interrupt_tagged;
6435
6436 err = request_irq(tp->pdev->irq, fn,
6437 SA_SHIRQ | SA_SAMPLE_RANDOM, dev->name, dev);
6438 }
6439 if (err) 6643 if (err)
6440 return err; 6644 return err;
6441 6645
@@ -6462,6 +6666,10 @@ static int tg3_open(struct net_device *dev)
6462 6666
6463 tg3_full_lock(tp, 0); 6667 tg3_full_lock(tp, 0);
6464 6668
6669 err = tg3_set_power_state(tp, PCI_D0);
6670 if (err)
6671 return err;
6672
6465 tg3_disable_ints(tp); 6673 tg3_disable_ints(tp);
6466 tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE; 6674 tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
6467 6675
@@ -6476,7 +6684,9 @@ static int tg3_open(struct net_device *dev)
6476 6684
6477 if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && 6685 if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
6478 (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_AX) && 6686 (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_AX) &&
6479 (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_BX)) { 6687 (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_BX) &&
6688 !((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) &&
6689 (tp->pdev_peer == tp->pdev))) {
6480 /* All MSI supporting chips should support tagged 6690 /* All MSI supporting chips should support tagged
6481 * status. Assert that this is the case. 6691 * status. Assert that this is the case.
6482 */ 6692 */
@@ -6491,17 +6701,7 @@ static int tg3_open(struct net_device *dev)
6491 tp->tg3_flags2 |= TG3_FLG2_USING_MSI; 6701 tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
6492 } 6702 }
6493 } 6703 }
6494 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) 6704 err = tg3_request_irq(tp);
6495 err = request_irq(tp->pdev->irq, tg3_msi,
6496 SA_SAMPLE_RANDOM, dev->name, dev);
6497 else {
6498 irqreturn_t (*fn)(int, void *, struct pt_regs *)=tg3_interrupt;
6499 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
6500 fn = tg3_interrupt_tagged;
6501
6502 err = request_irq(tp->pdev->irq, fn,
6503 SA_SHIRQ | SA_SAMPLE_RANDOM, dev->name, dev);
6504 }
6505 6705
6506 if (err) { 6706 if (err) {
6507 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) { 6707 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
@@ -6566,6 +6766,14 @@ static int tg3_open(struct net_device *dev)
6566 6766
6567 return err; 6767 return err;
6568 } 6768 }
6769
6770 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
6771 if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) {
6772 u32 val = tr32(0x7c04);
6773
6774 tw32(0x7c04, val | (1 << 29));
6775 }
6776 }
6569 } 6777 }
6570 6778
6571 tg3_full_lock(tp, 0); 6779 tg3_full_lock(tp, 0);
@@ -6839,7 +7047,6 @@ static int tg3_close(struct net_device *dev)
6839 tp->tg3_flags &= 7047 tp->tg3_flags &=
6840 ~(TG3_FLAG_INIT_COMPLETE | 7048 ~(TG3_FLAG_INIT_COMPLETE |
6841 TG3_FLAG_GOT_SERDES_FLOWCTL); 7049 TG3_FLAG_GOT_SERDES_FLOWCTL);
6842 netif_carrier_off(tp->dev);
6843 7050
6844 tg3_full_unlock(tp); 7051 tg3_full_unlock(tp);
6845 7052
@@ -6856,6 +7063,10 @@ static int tg3_close(struct net_device *dev)
6856 7063
6857 tg3_free_consistent(tp); 7064 tg3_free_consistent(tp);
6858 7065
7066 tg3_set_power_state(tp, PCI_D3hot);
7067
7068 netif_carrier_off(tp->dev);
7069
6859 return 0; 7070 return 0;
6860} 7071}
6861 7072
@@ -7150,6 +7361,9 @@ static void tg3_set_rx_mode(struct net_device *dev)
7150{ 7361{
7151 struct tg3 *tp = netdev_priv(dev); 7362 struct tg3 *tp = netdev_priv(dev);
7152 7363
7364 if (!netif_running(dev))
7365 return;
7366
7153 tg3_full_lock(tp, 0); 7367 tg3_full_lock(tp, 0);
7154 __tg3_set_rx_mode(dev); 7368 __tg3_set_rx_mode(dev);
7155 tg3_full_unlock(tp); 7369 tg3_full_unlock(tp);
@@ -7174,6 +7388,9 @@ static void tg3_get_regs(struct net_device *dev,
7174 7388
7175 memset(p, 0, TG3_REGDUMP_LEN); 7389 memset(p, 0, TG3_REGDUMP_LEN);
7176 7390
7391 if (tp->link_config.phy_is_low_power)
7392 return;
7393
7177 tg3_full_lock(tp, 0); 7394 tg3_full_lock(tp, 0);
7178 7395
7179#define __GET_REG32(reg) (*(p)++ = tr32(reg)) 7396#define __GET_REG32(reg) (*(p)++ = tr32(reg))
@@ -7240,6 +7457,7 @@ static int tg3_get_eeprom_len(struct net_device *dev)
7240} 7457}
7241 7458
7242static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val); 7459static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
7460static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val);
7243 7461
7244static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) 7462static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
7245{ 7463{
@@ -7248,6 +7466,9 @@ static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
7248 u8 *pd; 7466 u8 *pd;
7249 u32 i, offset, len, val, b_offset, b_count; 7467 u32 i, offset, len, val, b_offset, b_count;
7250 7468
7469 if (tp->link_config.phy_is_low_power)
7470 return -EAGAIN;
7471
7251 offset = eeprom->offset; 7472 offset = eeprom->offset;
7252 len = eeprom->len; 7473 len = eeprom->len;
7253 eeprom->len = 0; 7474 eeprom->len = 0;
@@ -7309,6 +7530,9 @@ static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
7309 u32 offset, len, b_offset, odd_len, start, end; 7530 u32 offset, len, b_offset, odd_len, start, end;
7310 u8 *buf; 7531 u8 *buf;
7311 7532
7533 if (tp->link_config.phy_is_low_power)
7534 return -EAGAIN;
7535
7312 if (eeprom->magic != TG3_EEPROM_MAGIC) 7536 if (eeprom->magic != TG3_EEPROM_MAGIC)
7313 return -EINVAL; 7537 return -EINVAL;
7314 7538
@@ -7442,6 +7666,7 @@ static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info
7442 7666
7443 strcpy(info->driver, DRV_MODULE_NAME); 7667 strcpy(info->driver, DRV_MODULE_NAME);
7444 strcpy(info->version, DRV_MODULE_VERSION); 7668 strcpy(info->version, DRV_MODULE_VERSION);
7669 strcpy(info->fw_version, tp->fw_ver);
7445 strcpy(info->bus_info, pci_name(tp->pdev)); 7670 strcpy(info->bus_info, pci_name(tp->pdev));
7446} 7671}
7447 7672
@@ -7536,11 +7761,20 @@ static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *
7536 7761
7537 ering->rx_max_pending = TG3_RX_RING_SIZE - 1; 7762 ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
7538 ering->rx_mini_max_pending = 0; 7763 ering->rx_mini_max_pending = 0;
7539 ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1; 7764 if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
7765 ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
7766 else
7767 ering->rx_jumbo_max_pending = 0;
7768
7769 ering->tx_max_pending = TG3_TX_RING_SIZE - 1;
7540 7770
7541 ering->rx_pending = tp->rx_pending; 7771 ering->rx_pending = tp->rx_pending;
7542 ering->rx_mini_pending = 0; 7772 ering->rx_mini_pending = 0;
7543 ering->rx_jumbo_pending = tp->rx_jumbo_pending; 7773 if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
7774 ering->rx_jumbo_pending = tp->rx_jumbo_pending;
7775 else
7776 ering->rx_jumbo_pending = 0;
7777
7544 ering->tx_pending = tp->tx_pending; 7778 ering->tx_pending = tp->tx_pending;
7545} 7779}
7546 7780
@@ -7661,10 +7895,10 @@ static int tg3_set_tx_csum(struct net_device *dev, u32 data)
7661 return 0; 7895 return 0;
7662 } 7896 }
7663 7897
7664 if (data) 7898 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
7665 dev->features |= NETIF_F_IP_CSUM; 7899 ethtool_op_set_tx_hw_csum(dev, data);
7666 else 7900 else
7667 dev->features &= ~NETIF_F_IP_CSUM; 7901 ethtool_op_set_tx_csum(dev, data);
7668 7902
7669 return 0; 7903 return 0;
7670} 7904}
@@ -7734,29 +7968,52 @@ static void tg3_get_ethtool_stats (struct net_device *dev,
7734} 7968}
7735 7969
7736#define NVRAM_TEST_SIZE 0x100 7970#define NVRAM_TEST_SIZE 0x100
7971#define NVRAM_SELFBOOT_FORMAT1_SIZE 0x14
7737 7972
7738static int tg3_test_nvram(struct tg3 *tp) 7973static int tg3_test_nvram(struct tg3 *tp)
7739{ 7974{
7740 u32 *buf, csum; 7975 u32 *buf, csum, magic;
7741 int i, j, err = 0; 7976 int i, j, err = 0, size;
7742 7977
7743 buf = kmalloc(NVRAM_TEST_SIZE, GFP_KERNEL); 7978 if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
7979 return -EIO;
7980
7981 if (magic == TG3_EEPROM_MAGIC)
7982 size = NVRAM_TEST_SIZE;
7983 else if ((magic & 0xff000000) == 0xa5000000) {
7984 if ((magic & 0xe00000) == 0x200000)
7985 size = NVRAM_SELFBOOT_FORMAT1_SIZE;
7986 else
7987 return 0;
7988 } else
7989 return -EIO;
7990
7991 buf = kmalloc(size, GFP_KERNEL);
7744 if (buf == NULL) 7992 if (buf == NULL)
7745 return -ENOMEM; 7993 return -ENOMEM;
7746 7994
7747 for (i = 0, j = 0; i < NVRAM_TEST_SIZE; i += 4, j++) { 7995 err = -EIO;
7996 for (i = 0, j = 0; i < size; i += 4, j++) {
7748 u32 val; 7997 u32 val;
7749 7998
7750 if ((err = tg3_nvram_read(tp, i, &val)) != 0) 7999 if ((err = tg3_nvram_read(tp, i, &val)) != 0)
7751 break; 8000 break;
7752 buf[j] = cpu_to_le32(val); 8001 buf[j] = cpu_to_le32(val);
7753 } 8002 }
7754 if (i < NVRAM_TEST_SIZE) 8003 if (i < size)
7755 goto out; 8004 goto out;
7756 8005
7757 err = -EIO; 8006 /* Selfboot format */
7758 if (cpu_to_be32(buf[0]) != TG3_EEPROM_MAGIC) 8007 if (cpu_to_be32(buf[0]) != TG3_EEPROM_MAGIC) {
7759 goto out; 8008 u8 *buf8 = (u8 *) buf, csum8 = 0;
8009
8010 for (i = 0; i < size; i++)
8011 csum8 += buf8[i];
8012
8013 if (csum8 == 0)
8014 return 0;
8015 return -EIO;
8016 }
7760 8017
7761 /* Bootstrap checksum at offset 0x10 */ 8018 /* Bootstrap checksum at offset 0x10 */
7762 csum = calc_crc((unsigned char *) buf, 0x10); 8019 csum = calc_crc((unsigned char *) buf, 0x10);
@@ -7802,7 +8059,7 @@ static int tg3_test_link(struct tg3 *tp)
7802} 8059}
7803 8060
7804/* Only test the commonly used registers */ 8061/* Only test the commonly used registers */
7805static const int tg3_test_registers(struct tg3 *tp) 8062static int tg3_test_registers(struct tg3 *tp)
7806{ 8063{
7807 int i, is_5705; 8064 int i, is_5705;
7808 u32 offset, read_mask, write_mask, val, save_val, read_val; 8065 u32 offset, read_mask, write_mask, val, save_val, read_val;
@@ -8050,14 +8307,24 @@ static int tg3_test_memory(struct tg3 *tp)
8050 { 0x00008000, 0x02000}, 8307 { 0x00008000, 0x02000},
8051 { 0x00010000, 0x0e000}, 8308 { 0x00010000, 0x0e000},
8052 { 0xffffffff, 0x00000} 8309 { 0xffffffff, 0x00000}
8310 }, mem_tbl_5755[] = {
8311 { 0x00000200, 0x00008},
8312 { 0x00004000, 0x00800},
8313 { 0x00006000, 0x00800},
8314 { 0x00008000, 0x02000},
8315 { 0x00010000, 0x0c000},
8316 { 0xffffffff, 0x00000}
8053 }; 8317 };
8054 struct mem_entry *mem_tbl; 8318 struct mem_entry *mem_tbl;
8055 int err = 0; 8319 int err = 0;
8056 int i; 8320 int i;
8057 8321
8058 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) 8322 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
8059 mem_tbl = mem_tbl_5705; 8323 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
8060 else 8324 mem_tbl = mem_tbl_5755;
8325 else
8326 mem_tbl = mem_tbl_5705;
8327 } else
8061 mem_tbl = mem_tbl_570x; 8328 mem_tbl = mem_tbl_570x;
8062 8329
8063 for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { 8330 for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
@@ -8229,6 +8496,9 @@ static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
8229{ 8496{
8230 struct tg3 *tp = netdev_priv(dev); 8497 struct tg3 *tp = netdev_priv(dev);
8231 8498
8499 if (tp->link_config.phy_is_low_power)
8500 tg3_set_power_state(tp, PCI_D0);
8501
8232 memset(data, 0, sizeof(u64) * TG3_NUM_TEST); 8502 memset(data, 0, sizeof(u64) * TG3_NUM_TEST);
8233 8503
8234 if (tg3_test_nvram(tp) != 0) { 8504 if (tg3_test_nvram(tp) != 0) {
@@ -8257,6 +8527,9 @@ static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
8257 if (!err) 8527 if (!err)
8258 tg3_nvram_unlock(tp); 8528 tg3_nvram_unlock(tp);
8259 8529
8530 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
8531 tg3_phy_reset(tp);
8532
8260 if (tg3_test_registers(tp) != 0) { 8533 if (tg3_test_registers(tp) != 0) {
8261 etest->flags |= ETH_TEST_FL_FAILED; 8534 etest->flags |= ETH_TEST_FL_FAILED;
8262 data[2] = 1; 8535 data[2] = 1;
@@ -8286,6 +8559,9 @@ static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
8286 8559
8287 tg3_full_unlock(tp); 8560 tg3_full_unlock(tp);
8288 } 8561 }
8562 if (tp->link_config.phy_is_low_power)
8563 tg3_set_power_state(tp, PCI_D3hot);
8564
8289} 8565}
8290 8566
8291static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 8567static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
@@ -8305,6 +8581,9 @@ static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
8305 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) 8581 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
8306 break; /* We have no PHY */ 8582 break; /* We have no PHY */
8307 8583
8584 if (tp->link_config.phy_is_low_power)
8585 return -EAGAIN;
8586
8308 spin_lock_bh(&tp->lock); 8587 spin_lock_bh(&tp->lock);
8309 err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval); 8588 err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
8310 spin_unlock_bh(&tp->lock); 8589 spin_unlock_bh(&tp->lock);
@@ -8321,6 +8600,9 @@ static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
8321 if (!capable(CAP_NET_ADMIN)) 8600 if (!capable(CAP_NET_ADMIN))
8322 return -EPERM; 8601 return -EPERM;
8323 8602
8603 if (tp->link_config.phy_is_low_power)
8604 return -EAGAIN;
8605
8324 spin_lock_bh(&tp->lock); 8606 spin_lock_bh(&tp->lock);
8325 err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in); 8607 err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
8326 spin_unlock_bh(&tp->lock); 8608 spin_unlock_bh(&tp->lock);
@@ -8464,14 +8746,14 @@ static struct ethtool_ops tg3_ethtool_ops = {
8464 8746
8465static void __devinit tg3_get_eeprom_size(struct tg3 *tp) 8747static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
8466{ 8748{
8467 u32 cursize, val; 8749 u32 cursize, val, magic;
8468 8750
8469 tp->nvram_size = EEPROM_CHIP_SIZE; 8751 tp->nvram_size = EEPROM_CHIP_SIZE;
8470 8752
8471 if (tg3_nvram_read(tp, 0, &val) != 0) 8753 if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
8472 return; 8754 return;
8473 8755
8474 if (swab32(val) != TG3_EEPROM_MAGIC) 8756 if ((magic != TG3_EEPROM_MAGIC) && ((magic & 0xff000000) != 0xa5000000))
8475 return; 8757 return;
8476 8758
8477 /* 8759 /*
@@ -8479,13 +8761,13 @@ static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
8479 * When we encounter our validation signature, we know the addressing 8761 * When we encounter our validation signature, we know the addressing
8480 * has wrapped around, and thus have our chip size. 8762 * has wrapped around, and thus have our chip size.
8481 */ 8763 */
8482 cursize = 0x800; 8764 cursize = 0x10;
8483 8765
8484 while (cursize < tp->nvram_size) { 8766 while (cursize < tp->nvram_size) {
8485 if (tg3_nvram_read(tp, cursize, &val) != 0) 8767 if (tg3_nvram_read_swab(tp, cursize, &val) != 0)
8486 return; 8768 return;
8487 8769
8488 if (swab32(val) == TG3_EEPROM_MAGIC) 8770 if (val == magic)
8489 break; 8771 break;
8490 8772
8491 cursize <<= 1; 8773 cursize <<= 1;
@@ -8498,6 +8780,15 @@ static void __devinit tg3_get_nvram_size(struct tg3 *tp)
8498{ 8780{
8499 u32 val; 8781 u32 val;
8500 8782
8783 if (tg3_nvram_read_swab(tp, 0, &val) != 0)
8784 return;
8785
8786 /* Selfboot format */
8787 if (val != TG3_EEPROM_MAGIC) {
8788 tg3_get_eeprom_size(tp);
8789 return;
8790 }
8791
8501 if (tg3_nvram_read(tp, 0xf0, &val) == 0) { 8792 if (tg3_nvram_read(tp, 0xf0, &val) == 0) {
8502 if (val != 0) { 8793 if (val != 0) {
8503 tp->nvram_size = (val >> 16) * 1024; 8794 tp->nvram_size = (val >> 16) * 1024;
@@ -8621,6 +8912,44 @@ static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
8621 } 8912 }
8622} 8913}
8623 8914
8915static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
8916{
8917 u32 nvcfg1;
8918
8919 nvcfg1 = tr32(NVRAM_CFG1);
8920
8921 switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
8922 case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ:
8923 case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
8924 case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ:
8925 case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
8926 tp->nvram_jedecnum = JEDEC_ATMEL;
8927 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8928 tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
8929
8930 nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
8931 tw32(NVRAM_CFG1, nvcfg1);
8932 break;
8933 case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
8934 case FLASH_5755VENDOR_ATMEL_FLASH_1:
8935 case FLASH_5755VENDOR_ATMEL_FLASH_2:
8936 case FLASH_5755VENDOR_ATMEL_FLASH_3:
8937 tp->nvram_jedecnum = JEDEC_ATMEL;
8938 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8939 tp->tg3_flags2 |= TG3_FLG2_FLASH;
8940 tp->nvram_pagesize = 264;
8941 break;
8942 case FLASH_5752VENDOR_ST_M45PE10:
8943 case FLASH_5752VENDOR_ST_M45PE20:
8944 case FLASH_5752VENDOR_ST_M45PE40:
8945 tp->nvram_jedecnum = JEDEC_ST;
8946 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8947 tp->tg3_flags2 |= TG3_FLG2_FLASH;
8948 tp->nvram_pagesize = 256;
8949 break;
8950 }
8951}
8952
8624/* Chips other than 5700/5701 use the NVRAM for fetching info. */ 8953/* Chips other than 5700/5701 use the NVRAM for fetching info. */
8625static void __devinit tg3_nvram_init(struct tg3 *tp) 8954static void __devinit tg3_nvram_init(struct tg3 *tp)
8626{ 8955{
@@ -8656,6 +8985,8 @@ static void __devinit tg3_nvram_init(struct tg3 *tp)
8656 8985
8657 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) 8986 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
8658 tg3_get_5752_nvram_info(tp); 8987 tg3_get_5752_nvram_info(tp);
8988 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
8989 tg3_get_5787_nvram_info(tp);
8659 else 8990 else
8660 tg3_get_nvram_info(tp); 8991 tg3_get_nvram_info(tp);
8661 8992
@@ -8725,6 +9056,34 @@ static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd)
8725 return 0; 9056 return 0;
8726} 9057}
8727 9058
9059static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr)
9060{
9061 if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
9062 (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
9063 (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
9064 (tp->nvram_jedecnum == JEDEC_ATMEL))
9065
9066 addr = ((addr / tp->nvram_pagesize) <<
9067 ATMEL_AT45DB0X1B_PAGE_POS) +
9068 (addr % tp->nvram_pagesize);
9069
9070 return addr;
9071}
9072
9073static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr)
9074{
9075 if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
9076 (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
9077 (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
9078 (tp->nvram_jedecnum == JEDEC_ATMEL))
9079
9080 addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) *
9081 tp->nvram_pagesize) +
9082 (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1));
9083
9084 return addr;
9085}
9086
8728static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) 9087static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
8729{ 9088{
8730 int ret; 9089 int ret;
@@ -8737,14 +9096,7 @@ static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
8737 if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) 9096 if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
8738 return tg3_nvram_read_using_eeprom(tp, offset, val); 9097 return tg3_nvram_read_using_eeprom(tp, offset, val);
8739 9098
8740 if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) && 9099 offset = tg3_nvram_phys_addr(tp, offset);
8741 (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
8742 (tp->nvram_jedecnum == JEDEC_ATMEL)) {
8743
8744 offset = ((offset / tp->nvram_pagesize) <<
8745 ATMEL_AT45DB0X1B_PAGE_POS) +
8746 (offset % tp->nvram_pagesize);
8747 }
8748 9100
8749 if (offset > NVRAM_ADDR_MSK) 9101 if (offset > NVRAM_ADDR_MSK)
8750 return -EINVAL; 9102 return -EINVAL;
@@ -8769,6 +9121,16 @@ static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
8769 return ret; 9121 return ret;
8770} 9122}
8771 9123
9124static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val)
9125{
9126 int err;
9127 u32 tmp;
9128
9129 err = tg3_nvram_read(tp, offset, &tmp);
9130 *val = swab32(tmp);
9131 return err;
9132}
9133
8772static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, 9134static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
8773 u32 offset, u32 len, u8 *buf) 9135 u32 offset, u32 len, u8 *buf)
8774{ 9136{
@@ -8921,15 +9283,7 @@ static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
8921 9283
8922 page_off = offset % tp->nvram_pagesize; 9284 page_off = offset % tp->nvram_pagesize;
8923 9285
8924 if ((tp->tg3_flags2 & TG3_FLG2_FLASH) && 9286 phy_addr = tg3_nvram_phys_addr(tp, offset);
8925 (tp->nvram_jedecnum == JEDEC_ATMEL)) {
8926
8927 phy_addr = ((offset / tp->nvram_pagesize) <<
8928 ATMEL_AT45DB0X1B_PAGE_POS) + page_off;
8929 }
8930 else {
8931 phy_addr = offset;
8932 }
8933 9287
8934 tw32(NVRAM_ADDR, phy_addr); 9288 tw32(NVRAM_ADDR, phy_addr);
8935 9289
@@ -8944,6 +9298,7 @@ static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
8944 nvram_cmd |= NVRAM_CMD_LAST; 9298 nvram_cmd |= NVRAM_CMD_LAST;
8945 9299
8946 if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) && 9300 if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
9301 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) &&
8947 (tp->nvram_jedecnum == JEDEC_ST) && 9302 (tp->nvram_jedecnum == JEDEC_ST) &&
8948 (nvram_cmd & NVRAM_CMD_FIRST)) { 9303 (nvram_cmd & NVRAM_CMD_FIRST)) {
8949 9304
@@ -9347,6 +9702,7 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
9347{ 9702{
9348 unsigned char vpd_data[256]; 9703 unsigned char vpd_data[256];
9349 int i; 9704 int i;
9705 u32 magic;
9350 9706
9351 if (tp->tg3_flags2 & TG3_FLG2_SUN_570X) { 9707 if (tp->tg3_flags2 & TG3_FLG2_SUN_570X) {
9352 /* Sun decided not to put the necessary bits in the 9708 /* Sun decided not to put the necessary bits in the
@@ -9356,16 +9712,43 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
9356 return; 9712 return;
9357 } 9713 }
9358 9714
9359 for (i = 0; i < 256; i += 4) { 9715 if (tg3_nvram_read_swab(tp, 0x0, &magic))
9360 u32 tmp; 9716 return;
9361 9717
9362 if (tg3_nvram_read(tp, 0x100 + i, &tmp)) 9718 if (magic == TG3_EEPROM_MAGIC) {
9363 goto out_not_found; 9719 for (i = 0; i < 256; i += 4) {
9720 u32 tmp;
9721
9722 if (tg3_nvram_read(tp, 0x100 + i, &tmp))
9723 goto out_not_found;
9364 9724
9365 vpd_data[i + 0] = ((tmp >> 0) & 0xff); 9725 vpd_data[i + 0] = ((tmp >> 0) & 0xff);
9366 vpd_data[i + 1] = ((tmp >> 8) & 0xff); 9726 vpd_data[i + 1] = ((tmp >> 8) & 0xff);
9367 vpd_data[i + 2] = ((tmp >> 16) & 0xff); 9727 vpd_data[i + 2] = ((tmp >> 16) & 0xff);
9368 vpd_data[i + 3] = ((tmp >> 24) & 0xff); 9728 vpd_data[i + 3] = ((tmp >> 24) & 0xff);
9729 }
9730 } else {
9731 int vpd_cap;
9732
9733 vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
9734 for (i = 0; i < 256; i += 4) {
9735 u32 tmp, j = 0;
9736 u16 tmp16;
9737
9738 pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR,
9739 i);
9740 while (j++ < 100) {
9741 pci_read_config_word(tp->pdev, vpd_cap +
9742 PCI_VPD_ADDR, &tmp16);
9743 if (tmp16 & 0x8000)
9744 break;
9745 msleep(1);
9746 }
9747 pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA,
9748 &tmp);
9749 tmp = cpu_to_le32(tmp);
9750 memcpy(&vpd_data[i], &tmp, 4);
9751 }
9369 } 9752 }
9370 9753
9371 /* Now parse and find the part number. */ 9754 /* Now parse and find the part number. */
@@ -9412,6 +9795,46 @@ out_not_found:
9412 strcpy(tp->board_part_number, "none"); 9795 strcpy(tp->board_part_number, "none");
9413} 9796}
9414 9797
9798static void __devinit tg3_read_fw_ver(struct tg3 *tp)
9799{
9800 u32 val, offset, start;
9801
9802 if (tg3_nvram_read_swab(tp, 0, &val))
9803 return;
9804
9805 if (val != TG3_EEPROM_MAGIC)
9806 return;
9807
9808 if (tg3_nvram_read_swab(tp, 0xc, &offset) ||
9809 tg3_nvram_read_swab(tp, 0x4, &start))
9810 return;
9811
9812 offset = tg3_nvram_logical_addr(tp, offset);
9813 if (tg3_nvram_read_swab(tp, offset, &val))
9814 return;
9815
9816 if ((val & 0xfc000000) == 0x0c000000) {
9817 u32 ver_offset, addr;
9818 int i;
9819
9820 if (tg3_nvram_read_swab(tp, offset + 4, &val) ||
9821 tg3_nvram_read_swab(tp, offset + 8, &ver_offset))
9822 return;
9823
9824 if (val != 0)
9825 return;
9826
9827 addr = offset + ver_offset - start;
9828 for (i = 0; i < 16; i += 4) {
9829 if (tg3_nvram_read(tp, addr + i, &val))
9830 return;
9831
9832 val = cpu_to_le32(val);
9833 memcpy(tp->fw_ver + i, &val, 4);
9834 }
9835 }
9836}
9837
9415#ifdef CONFIG_SPARC64 9838#ifdef CONFIG_SPARC64
9416static int __devinit tg3_is_sun_570X(struct tg3 *tp) 9839static int __devinit tg3_is_sun_570X(struct tg3 *tp)
9417{ 9840{
@@ -9603,6 +10026,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
9603 10026
9604 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || 10027 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
9605 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || 10028 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
10029 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
9606 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) 10030 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
9607 tp->tg3_flags2 |= TG3_FLG2_5750_PLUS; 10031 tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
9608 10032
@@ -9610,12 +10034,18 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
9610 (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)) 10034 (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
9611 tp->tg3_flags2 |= TG3_FLG2_5705_PLUS; 10035 tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
9612 10036
9613 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) 10037 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
9614 tp->tg3_flags2 |= TG3_FLG2_HW_TSO; 10038 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) {
10039 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
10040 tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
10041 } else
10042 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1;
10043 }
9615 10044
9616 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 && 10045 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
9617 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 && 10046 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 &&
9618 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) 10047 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
10048 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787)
9619 tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE; 10049 tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
9620 10050
9621 if (pci_find_capability(tp->pdev, PCI_CAP_ID_EXP) != 0) 10051 if (pci_find_capability(tp->pdev, PCI_CAP_ID_EXP) != 0)
@@ -9772,7 +10202,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
9772 tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; 10202 tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
9773 10203
9774 /* Force the chip into D0. */ 10204 /* Force the chip into D0. */
9775 err = tg3_set_power_state(tp, 0); 10205 err = tg3_set_power_state(tp, PCI_D0);
9776 if (err) { 10206 if (err) {
9777 printk(KERN_ERR PFX "(%s) transition to D0 failed\n", 10207 printk(KERN_ERR PFX "(%s) transition to D0 failed\n",
9778 pci_name(tp->pdev)); 10208 pci_name(tp->pdev));
@@ -9825,7 +10255,8 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
9825 if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) 10255 if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
9826 tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG; 10256 tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
9827 10257
9828 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) 10258 if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
10259 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787))
9829 tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG; 10260 tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
9830 10261
9831 tp->coalesce_mode = 0; 10262 tp->coalesce_mode = 0;
@@ -9925,6 +10356,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
9925 } 10356 }
9926 10357
9927 tg3_read_partno(tp); 10358 tg3_read_partno(tp);
10359 tg3_read_fw_ver(tp);
9928 10360
9929 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) { 10361 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
9930 tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT; 10362 tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
@@ -9960,10 +10392,13 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
9960 else 10392 else
9961 tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES; 10393 tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
9962 10394
9963 /* It seems all chips can get confused if TX buffers 10395 /* All chips before 5787 can get confused if TX buffers
9964 * straddle the 4GB address boundary in some cases. 10396 * straddle the 4GB address boundary in some cases.
9965 */ 10397 */
9966 tp->dev->hard_start_xmit = tg3_start_xmit; 10398 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
10399 tp->dev->hard_start_xmit = tg3_start_xmit;
10400 else
10401 tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
9967 10402
9968 tp->rx_offset = 2; 10403 tp->rx_offset = 2;
9969 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && 10404 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
@@ -10491,7 +10926,6 @@ static void __devinit tg3_init_link_config(struct tg3 *tp)
10491 tp->link_config.speed = SPEED_INVALID; 10926 tp->link_config.speed = SPEED_INVALID;
10492 tp->link_config.duplex = DUPLEX_INVALID; 10927 tp->link_config.duplex = DUPLEX_INVALID;
10493 tp->link_config.autoneg = AUTONEG_ENABLE; 10928 tp->link_config.autoneg = AUTONEG_ENABLE;
10494 netif_carrier_off(tp->dev);
10495 tp->link_config.active_speed = SPEED_INVALID; 10929 tp->link_config.active_speed = SPEED_INVALID;
10496 tp->link_config.active_duplex = DUPLEX_INVALID; 10930 tp->link_config.active_duplex = DUPLEX_INVALID;
10497 tp->link_config.phy_is_low_power = 0; 10931 tp->link_config.phy_is_low_power = 0;
@@ -10550,6 +10984,7 @@ static char * __devinit tg3_phy_string(struct tg3 *tp)
10550 case PHY_ID_BCM5752: return "5752"; 10984 case PHY_ID_BCM5752: return "5752";
10551 case PHY_ID_BCM5714: return "5714"; 10985 case PHY_ID_BCM5714: return "5714";
10552 case PHY_ID_BCM5780: return "5780"; 10986 case PHY_ID_BCM5780: return "5780";
10987 case PHY_ID_BCM5787: return "5787";
10553 case PHY_ID_BCM8002: return "8002/serdes"; 10988 case PHY_ID_BCM8002: return "8002/serdes";
10554 case 0: return "serdes"; 10989 case 0: return "serdes";
10555 default: return "unknown"; 10990 default: return "unknown";
@@ -10848,11 +11283,12 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
10848 tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; 11283 tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
10849 } 11284 }
10850 11285
10851 /* TSO is off by default, user can enable using ethtool. */ 11286 /* TSO is on by default on chips that support hardware TSO.
10852#if 0 11287 * Firmware TSO on older chips gives lower performance, so it
10853 if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) 11288 * is off by default, but can be enabled using ethtool.
11289 */
11290 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
10854 dev->features |= NETIF_F_TSO; 11291 dev->features |= NETIF_F_TSO;
10855#endif
10856 11292
10857#endif 11293#endif
10858 11294
@@ -10896,7 +11332,11 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
10896 * checksumming. 11332 * checksumming.
10897 */ 11333 */
10898 if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) { 11334 if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
10899 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM; 11335 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
11336 dev->features |= NETIF_F_HW_CSUM;
11337 else
11338 dev->features |= NETIF_F_IP_CSUM;
11339 dev->features |= NETIF_F_SG;
10900 tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS; 11340 tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
10901 } else 11341 } else
10902 tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS; 11342 tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
@@ -10949,6 +11389,8 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
10949 (pdev->dma_mask == DMA_32BIT_MASK) ? 32 : 11389 (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
10950 (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64)); 11390 (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
10951 11391
11392 netif_carrier_off(tp->dev);
11393
10952 return 0; 11394 return 0;
10953 11395
10954err_out_iounmap: 11396err_out_iounmap:
@@ -11044,7 +11486,7 @@ static int tg3_resume(struct pci_dev *pdev)
11044 11486
11045 pci_restore_state(tp->pdev); 11487 pci_restore_state(tp->pdev);
11046 11488
11047 err = tg3_set_power_state(tp, 0); 11489 err = tg3_set_power_state(tp, PCI_D0);
11048 if (err) 11490 if (err)
11049 return err; 11491 return err;
11050 11492
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index 7e3b613afb29..baa34c4721db 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -138,6 +138,7 @@
138#define ASIC_REV_5752 0x06 138#define ASIC_REV_5752 0x06
139#define ASIC_REV_5780 0x08 139#define ASIC_REV_5780 0x08
140#define ASIC_REV_5714 0x09 140#define ASIC_REV_5714 0x09
141#define ASIC_REV_5787 0x0b
141#define GET_CHIP_REV(CHIP_REV_ID) ((CHIP_REV_ID) >> 8) 142#define GET_CHIP_REV(CHIP_REV_ID) ((CHIP_REV_ID) >> 8)
142#define CHIPREV_5700_AX 0x70 143#define CHIPREV_5700_AX 0x70
143#define CHIPREV_5700_BX 0x71 144#define CHIPREV_5700_BX 0x71
@@ -1393,6 +1394,7 @@
1393#define GRC_MDI_CTRL 0x00006844 1394#define GRC_MDI_CTRL 0x00006844
1394#define GRC_SEEPROM_DELAY 0x00006848 1395#define GRC_SEEPROM_DELAY 0x00006848
1395/* 0x684c --> 0x6c00 unused */ 1396/* 0x684c --> 0x6c00 unused */
1397#define GRC_FASTBOOT_PC 0x00006894 /* 5752, 5755, 5787 */
1396 1398
1397/* 0x6c00 --> 0x7000 unused */ 1399/* 0x6c00 --> 0x7000 unused */
1398 1400
@@ -1436,6 +1438,13 @@
1436#define FLASH_5752VENDOR_ST_M45PE10 0x02400000 1438#define FLASH_5752VENDOR_ST_M45PE10 0x02400000
1437#define FLASH_5752VENDOR_ST_M45PE20 0x02400002 1439#define FLASH_5752VENDOR_ST_M45PE20 0x02400002
1438#define FLASH_5752VENDOR_ST_M45PE40 0x02400001 1440#define FLASH_5752VENDOR_ST_M45PE40 0x02400001
1441#define FLASH_5755VENDOR_ATMEL_FLASH_1 0x03400001
1442#define FLASH_5755VENDOR_ATMEL_FLASH_2 0x03400002
1443#define FLASH_5755VENDOR_ATMEL_FLASH_3 0x03400000
1444#define FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ 0x03000003
1445#define FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ 0x03000002
1446#define FLASH_5787VENDOR_MICRO_EEPROM_64KHZ 0x03000000
1447#define FLASH_5787VENDOR_MICRO_EEPROM_376KHZ 0x02000000
1439#define NVRAM_CFG1_5752PAGE_SIZE_MASK 0x70000000 1448#define NVRAM_CFG1_5752PAGE_SIZE_MASK 0x70000000
1440#define FLASH_5752PAGE_SIZE_256 0x00000000 1449#define FLASH_5752PAGE_SIZE_256 0x00000000
1441#define FLASH_5752PAGE_SIZE_512 0x10000000 1450#define FLASH_5752PAGE_SIZE_512 0x10000000
@@ -2185,7 +2194,7 @@ struct tg3 {
2185#define TG3_FLG2_PHY_SERDES 0x00002000 2194#define TG3_FLG2_PHY_SERDES 0x00002000
2186#define TG3_FLG2_CAPACITIVE_COUPLING 0x00004000 2195#define TG3_FLG2_CAPACITIVE_COUPLING 0x00004000
2187#define TG3_FLG2_FLASH 0x00008000 2196#define TG3_FLG2_FLASH 0x00008000
2188#define TG3_FLG2_HW_TSO 0x00010000 2197#define TG3_FLG2_HW_TSO_1 0x00010000
2189#define TG3_FLG2_SERDES_PREEMPHASIS 0x00020000 2198#define TG3_FLG2_SERDES_PREEMPHASIS 0x00020000
2190#define TG3_FLG2_5705_PLUS 0x00040000 2199#define TG3_FLG2_5705_PLUS 0x00040000
2191#define TG3_FLG2_5750_PLUS 0x00080000 2200#define TG3_FLG2_5750_PLUS 0x00080000
@@ -2198,6 +2207,9 @@ struct tg3 {
2198#define TG3_FLG2_PARALLEL_DETECT 0x01000000 2207#define TG3_FLG2_PARALLEL_DETECT 0x01000000
2199#define TG3_FLG2_ICH_WORKAROUND 0x02000000 2208#define TG3_FLG2_ICH_WORKAROUND 0x02000000
2200#define TG3_FLG2_5780_CLASS 0x04000000 2209#define TG3_FLG2_5780_CLASS 0x04000000
2210#define TG3_FLG2_HW_TSO_2 0x08000000
2211#define TG3_FLG2_HW_TSO (TG3_FLG2_HW_TSO_1 | TG3_FLG2_HW_TSO_2)
2212#define TG3_FLG2_1SHOT_MSI 0x10000000
2201 2213
2202 u32 split_mode_max_reqs; 2214 u32 split_mode_max_reqs;
2203#define SPLIT_MODE_5704_MAX_REQ 3 2215#define SPLIT_MODE_5704_MAX_REQ 3
@@ -2247,6 +2259,7 @@ struct tg3 {
2247#define PHY_ID_BCM5752 0x60008100 2259#define PHY_ID_BCM5752 0x60008100
2248#define PHY_ID_BCM5714 0x60008340 2260#define PHY_ID_BCM5714 0x60008340
2249#define PHY_ID_BCM5780 0x60008350 2261#define PHY_ID_BCM5780 0x60008350
2262#define PHY_ID_BCM5787 0xbc050ce0
2250#define PHY_ID_BCM8002 0x60010140 2263#define PHY_ID_BCM8002 0x60010140
2251#define PHY_ID_INVALID 0xffffffff 2264#define PHY_ID_INVALID 0xffffffff
2252#define PHY_ID_REV_MASK 0x0000000f 2265#define PHY_ID_REV_MASK 0x0000000f
@@ -2258,6 +2271,7 @@ struct tg3 {
2258 u32 led_ctrl; 2271 u32 led_ctrl;
2259 2272
2260 char board_part_number[24]; 2273 char board_part_number[24];
2274 char fw_ver[16];
2261 u32 nic_sram_data_cfg; 2275 u32 nic_sram_data_cfg;
2262 u32 pci_clock_ctrl; 2276 u32 pci_clock_ctrl;
2263 struct pci_dev *pdev_peer; 2277 struct pci_dev *pdev_peer;
@@ -2271,7 +2285,8 @@ struct tg3 {
2271 (X) == PHY_ID_BCM5703 || (X) == PHY_ID_BCM5704 || \ 2285 (X) == PHY_ID_BCM5703 || (X) == PHY_ID_BCM5704 || \
2272 (X) == PHY_ID_BCM5705 || (X) == PHY_ID_BCM5750 || \ 2286 (X) == PHY_ID_BCM5705 || (X) == PHY_ID_BCM5750 || \
2273 (X) == PHY_ID_BCM5752 || (X) == PHY_ID_BCM5714 || \ 2287 (X) == PHY_ID_BCM5752 || (X) == PHY_ID_BCM5714 || \
2274 (X) == PHY_ID_BCM5780 || (X) == PHY_ID_BCM8002) 2288 (X) == PHY_ID_BCM5780 || (X) == PHY_ID_BCM5787 || \
2289 (X) == PHY_ID_BCM8002)
2275 2290
2276 struct tg3_hw_stats *hw_stats; 2291 struct tg3_hw_stats *hw_stats;
2277 dma_addr_t stats_mapping; 2292 dma_addr_t stats_mapping;
diff --git a/drivers/net/wan/sbni.c b/drivers/net/wan/sbni.c
index db2c798ba89e..175ba13bce41 100644
--- a/drivers/net/wan/sbni.c
+++ b/drivers/net/wan/sbni.c
@@ -1495,8 +1495,7 @@ module_param(skip_pci_probe, bool, 0);
1495MODULE_LICENSE("GPL"); 1495MODULE_LICENSE("GPL");
1496 1496
1497 1497
1498int 1498int __init init_module( void )
1499init_module( void )
1500{ 1499{
1501 struct net_device *dev; 1500 struct net_device *dev;
1502 int err; 1501 int err;
diff --git a/drivers/pcmcia/omap_cf.c b/drivers/pcmcia/omap_cf.c
index 47b5ade95bde..2c23d7584399 100644
--- a/drivers/pcmcia/omap_cf.c
+++ b/drivers/pcmcia/omap_cf.c
@@ -218,7 +218,7 @@ static int __init omap_cf_probe(struct device *dev)
218 218
219 /* either CFLASH.IREQ (INT_1610_CF) or some GPIO */ 219 /* either CFLASH.IREQ (INT_1610_CF) or some GPIO */
220 irq = platform_get_irq(pdev, 0); 220 irq = platform_get_irq(pdev, 0);
221 if (!irq) 221 if (irq < 0)
222 return -EINVAL; 222 return -EINVAL;
223 223
224 cf = kcalloc(1, sizeof *cf, GFP_KERNEL); 224 cf = kcalloc(1, sizeof *cf, GFP_KERNEL);
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 3c606cf8c8ca..5c94a5d4efc0 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -379,6 +379,14 @@ config SCSI_AHA1740
379config SCSI_AACRAID 379config SCSI_AACRAID
380 tristate "Adaptec AACRAID support" 380 tristate "Adaptec AACRAID support"
381 depends on SCSI && PCI 381 depends on SCSI && PCI
382 help
383 This driver supports a variety of Dell, HP, Adaptec, IBM and
384 ICP storage products. For a list of supported products, refer
385 to <file:Documentation/scsi/aacraid.txt>.
386
387 To compile this driver as a module, choose M here: the module
388 will be called aacraid.
389
382 390
383source "drivers/scsi/aic7xxx/Kconfig.aic7xxx" 391source "drivers/scsi/aic7xxx/Kconfig.aic7xxx"
384 392
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index 320e765fa0cd..15dc2e00e1b2 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -163,7 +163,7 @@ ncr53c8xx-flags-$(CONFIG_SCSI_ZALON) \
163CFLAGS_ncr53c8xx.o := $(ncr53c8xx-flags-y) $(ncr53c8xx-flags-m) 163CFLAGS_ncr53c8xx.o := $(ncr53c8xx-flags-y) $(ncr53c8xx-flags-m)
164zalon7xx-objs := zalon.o ncr53c8xx.o 164zalon7xx-objs := zalon.o ncr53c8xx.o
165NCR_Q720_mod-objs := NCR_Q720.o ncr53c8xx.o 165NCR_Q720_mod-objs := NCR_Q720.o ncr53c8xx.o
166libata-objs := libata-core.o libata-scsi.o 166libata-objs := libata-core.o libata-scsi.o libata-bmdma.o
167oktagon_esp_mod-objs := oktagon_esp.o oktagon_io.o 167oktagon_esp_mod-objs := oktagon_esp.o oktagon_io.o
168 168
169# Files generated that shall be removed upon make clean 169# Files generated that shall be removed upon make clean
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index 559ff7aae3f1..e97ab3e6de4d 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -66,6 +66,9 @@ enum {
66 AHCI_IRQ_ON_SG = (1 << 31), 66 AHCI_IRQ_ON_SG = (1 << 31),
67 AHCI_CMD_ATAPI = (1 << 5), 67 AHCI_CMD_ATAPI = (1 << 5),
68 AHCI_CMD_WRITE = (1 << 6), 68 AHCI_CMD_WRITE = (1 << 6),
69 AHCI_CMD_PREFETCH = (1 << 7),
70 AHCI_CMD_RESET = (1 << 8),
71 AHCI_CMD_CLR_BUSY = (1 << 10),
69 72
70 RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */ 73 RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */
71 74
@@ -85,6 +88,7 @@ enum {
85 88
86 /* HOST_CAP bits */ 89 /* HOST_CAP bits */
87 HOST_CAP_64 = (1 << 31), /* PCI DAC (64-bit DMA) support */ 90 HOST_CAP_64 = (1 << 31), /* PCI DAC (64-bit DMA) support */
91 HOST_CAP_CLO = (1 << 24), /* Command List Override support */
88 92
89 /* registers for each SATA port */ 93 /* registers for each SATA port */
90 PORT_LST_ADDR = 0x00, /* command list DMA addr */ 94 PORT_LST_ADDR = 0x00, /* command list DMA addr */
@@ -138,6 +142,7 @@ enum {
138 PORT_CMD_LIST_ON = (1 << 15), /* cmd list DMA engine running */ 142 PORT_CMD_LIST_ON = (1 << 15), /* cmd list DMA engine running */
139 PORT_CMD_FIS_ON = (1 << 14), /* FIS DMA engine running */ 143 PORT_CMD_FIS_ON = (1 << 14), /* FIS DMA engine running */
140 PORT_CMD_FIS_RX = (1 << 4), /* Enable FIS receive DMA engine */ 144 PORT_CMD_FIS_RX = (1 << 4), /* Enable FIS receive DMA engine */
145 PORT_CMD_CLO = (1 << 3), /* Command list override */
141 PORT_CMD_POWER_ON = (1 << 2), /* Power up device */ 146 PORT_CMD_POWER_ON = (1 << 2), /* Power up device */
142 PORT_CMD_SPIN_UP = (1 << 1), /* Spin up device */ 147 PORT_CMD_SPIN_UP = (1 << 1), /* Spin up device */
143 PORT_CMD_START = (1 << 0), /* Enable port DMA engine */ 148 PORT_CMD_START = (1 << 0), /* Enable port DMA engine */
@@ -184,9 +189,9 @@ struct ahci_port_priv {
184static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg); 189static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg);
185static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 190static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
186static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 191static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
187static int ahci_qc_issue(struct ata_queued_cmd *qc); 192static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc);
188static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *regs); 193static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *regs);
189static void ahci_phy_reset(struct ata_port *ap); 194static int ahci_probe_reset(struct ata_port *ap, unsigned int *classes);
190static void ahci_irq_clear(struct ata_port *ap); 195static void ahci_irq_clear(struct ata_port *ap);
191static void ahci_eng_timeout(struct ata_port *ap); 196static void ahci_eng_timeout(struct ata_port *ap);
192static int ahci_port_start(struct ata_port *ap); 197static int ahci_port_start(struct ata_port *ap);
@@ -202,11 +207,11 @@ static struct scsi_host_template ahci_sht = {
202 .name = DRV_NAME, 207 .name = DRV_NAME,
203 .ioctl = ata_scsi_ioctl, 208 .ioctl = ata_scsi_ioctl,
204 .queuecommand = ata_scsi_queuecmd, 209 .queuecommand = ata_scsi_queuecmd,
210 .eh_timed_out = ata_scsi_timed_out,
205 .eh_strategy_handler = ata_scsi_error, 211 .eh_strategy_handler = ata_scsi_error,
206 .can_queue = ATA_DEF_QUEUE, 212 .can_queue = ATA_DEF_QUEUE,
207 .this_id = ATA_SHT_THIS_ID, 213 .this_id = ATA_SHT_THIS_ID,
208 .sg_tablesize = AHCI_MAX_SG, 214 .sg_tablesize = AHCI_MAX_SG,
209 .max_sectors = ATA_MAX_SECTORS,
210 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 215 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
211 .emulated = ATA_SHT_EMULATED, 216 .emulated = ATA_SHT_EMULATED,
212 .use_clustering = AHCI_USE_CLUSTERING, 217 .use_clustering = AHCI_USE_CLUSTERING,
@@ -225,7 +230,7 @@ static const struct ata_port_operations ahci_ops = {
225 230
226 .tf_read = ahci_tf_read, 231 .tf_read = ahci_tf_read,
227 232
228 .phy_reset = ahci_phy_reset, 233 .probe_reset = ahci_probe_reset,
229 234
230 .qc_prep = ahci_qc_prep, 235 .qc_prep = ahci_qc_prep,
231 .qc_issue = ahci_qc_issue, 236 .qc_issue = ahci_qc_issue,
@@ -247,8 +252,7 @@ static const struct ata_port_info ahci_port_info[] = {
247 { 252 {
248 .sht = &ahci_sht, 253 .sht = &ahci_sht,
249 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 254 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
250 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO | 255 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
251 ATA_FLAG_PIO_DMA,
252 .pio_mask = 0x1f, /* pio0-4 */ 256 .pio_mask = 0x1f, /* pio0-4 */
253 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 257 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
254 .port_ops = &ahci_ops, 258 .port_ops = &ahci_ops,
@@ -450,17 +454,48 @@ static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg_in,
450 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); 454 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
451} 455}
452 456
453static void ahci_phy_reset(struct ata_port *ap) 457static int ahci_stop_engine(struct ata_port *ap)
454{ 458{
455 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; 459 void __iomem *mmio = ap->host_set->mmio_base;
456 struct ata_taskfile tf; 460 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
457 struct ata_device *dev = &ap->device[0]; 461 int work;
458 u32 new_tmp, tmp; 462 u32 tmp;
459 463
460 __sata_phy_reset(ap); 464 tmp = readl(port_mmio + PORT_CMD);
465 tmp &= ~PORT_CMD_START;
466 writel(tmp, port_mmio + PORT_CMD);
461 467
462 if (ap->flags & ATA_FLAG_PORT_DISABLED) 468 /* wait for engine to stop. TODO: this could be
463 return; 469 * as long as 500 msec
470 */
471 work = 1000;
472 while (work-- > 0) {
473 tmp = readl(port_mmio + PORT_CMD);
474 if ((tmp & PORT_CMD_LIST_ON) == 0)
475 return 0;
476 udelay(10);
477 }
478
479 return -EIO;
480}
481
482static void ahci_start_engine(struct ata_port *ap)
483{
484 void __iomem *mmio = ap->host_set->mmio_base;
485 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
486 u32 tmp;
487
488 tmp = readl(port_mmio + PORT_CMD);
489 tmp |= PORT_CMD_START;
490 writel(tmp, port_mmio + PORT_CMD);
491 readl(port_mmio + PORT_CMD); /* flush */
492}
493
494static unsigned int ahci_dev_classify(struct ata_port *ap)
495{
496 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
497 struct ata_taskfile tf;
498 u32 tmp;
464 499
465 tmp = readl(port_mmio + PORT_SIG); 500 tmp = readl(port_mmio + PORT_SIG);
466 tf.lbah = (tmp >> 24) & 0xff; 501 tf.lbah = (tmp >> 24) & 0xff;
@@ -468,15 +503,46 @@ static void ahci_phy_reset(struct ata_port *ap)
468 tf.lbal = (tmp >> 8) & 0xff; 503 tf.lbal = (tmp >> 8) & 0xff;
469 tf.nsect = (tmp) & 0xff; 504 tf.nsect = (tmp) & 0xff;
470 505
471 dev->class = ata_dev_classify(&tf); 506 return ata_dev_classify(&tf);
472 if (!ata_dev_present(dev)) { 507}
473 ata_port_disable(ap); 508
474 return; 509static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, u32 opts)
475 } 510{
511 pp->cmd_slot[0].opts = cpu_to_le32(opts);
512 pp->cmd_slot[0].status = 0;
513 pp->cmd_slot[0].tbl_addr = cpu_to_le32(pp->cmd_tbl_dma & 0xffffffff);
514 pp->cmd_slot[0].tbl_addr_hi = cpu_to_le32((pp->cmd_tbl_dma >> 16) >> 16);
515}
516
517static int ahci_hardreset(struct ata_port *ap, int verbose, unsigned int *class)
518{
519 int rc;
520
521 DPRINTK("ENTER\n");
522
523 ahci_stop_engine(ap);
524 rc = sata_std_hardreset(ap, verbose, class);
525 ahci_start_engine(ap);
526
527 if (rc == 0)
528 *class = ahci_dev_classify(ap);
529 if (*class == ATA_DEV_UNKNOWN)
530 *class = ATA_DEV_NONE;
531
532 DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
533 return rc;
534}
535
536static void ahci_postreset(struct ata_port *ap, unsigned int *class)
537{
538 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
539 u32 new_tmp, tmp;
540
541 ata_std_postreset(ap, class);
476 542
477 /* Make sure port's ATAPI bit is set appropriately */ 543 /* Make sure port's ATAPI bit is set appropriately */
478 new_tmp = tmp = readl(port_mmio + PORT_CMD); 544 new_tmp = tmp = readl(port_mmio + PORT_CMD);
479 if (dev->class == ATA_DEV_ATAPI) 545 if (*class == ATA_DEV_ATAPI)
480 new_tmp |= PORT_CMD_ATAPI; 546 new_tmp |= PORT_CMD_ATAPI;
481 else 547 else
482 new_tmp &= ~PORT_CMD_ATAPI; 548 new_tmp &= ~PORT_CMD_ATAPI;
@@ -486,6 +552,12 @@ static void ahci_phy_reset(struct ata_port *ap)
486 } 552 }
487} 553}
488 554
555static int ahci_probe_reset(struct ata_port *ap, unsigned int *classes)
556{
557 return ata_drive_probe_reset(ap, NULL, NULL, ahci_hardreset,
558 ahci_postreset, classes);
559}
560
489static u8 ahci_check_status(struct ata_port *ap) 561static u8 ahci_check_status(struct ata_port *ap)
490{ 562{
491 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr; 563 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr;
@@ -533,42 +605,36 @@ static void ahci_qc_prep(struct ata_queued_cmd *qc)
533{ 605{
534 struct ata_port *ap = qc->ap; 606 struct ata_port *ap = qc->ap;
535 struct ahci_port_priv *pp = ap->private_data; 607 struct ahci_port_priv *pp = ap->private_data;
608 int is_atapi = is_atapi_taskfile(&qc->tf);
536 u32 opts; 609 u32 opts;
537 const u32 cmd_fis_len = 5; /* five dwords */ 610 const u32 cmd_fis_len = 5; /* five dwords */
538 unsigned int n_elem; 611 unsigned int n_elem;
539 612
540 /* 613 /*
541 * Fill in command slot information (currently only one slot,
542 * slot 0, is currently since we don't do queueing)
543 */
544
545 opts = cmd_fis_len;
546 if (qc->tf.flags & ATA_TFLAG_WRITE)
547 opts |= AHCI_CMD_WRITE;
548 if (is_atapi_taskfile(&qc->tf))
549 opts |= AHCI_CMD_ATAPI;
550
551 pp->cmd_slot[0].opts = cpu_to_le32(opts);
552 pp->cmd_slot[0].status = 0;
553 pp->cmd_slot[0].tbl_addr = cpu_to_le32(pp->cmd_tbl_dma & 0xffffffff);
554 pp->cmd_slot[0].tbl_addr_hi = cpu_to_le32((pp->cmd_tbl_dma >> 16) >> 16);
555
556 /*
557 * Fill in command table information. First, the header, 614 * Fill in command table information. First, the header,
558 * a SATA Register - Host to Device command FIS. 615 * a SATA Register - Host to Device command FIS.
559 */ 616 */
560 ata_tf_to_fis(&qc->tf, pp->cmd_tbl, 0); 617 ata_tf_to_fis(&qc->tf, pp->cmd_tbl, 0);
561 if (opts & AHCI_CMD_ATAPI) { 618 if (is_atapi) {
562 memset(pp->cmd_tbl + AHCI_CMD_TBL_CDB, 0, 32); 619 memset(pp->cmd_tbl + AHCI_CMD_TBL_CDB, 0, 32);
563 memcpy(pp->cmd_tbl + AHCI_CMD_TBL_CDB, qc->cdb, ap->cdb_len); 620 memcpy(pp->cmd_tbl + AHCI_CMD_TBL_CDB, qc->cdb,
621 qc->dev->cdb_len);
564 } 622 }
565 623
566 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 624 n_elem = 0;
567 return; 625 if (qc->flags & ATA_QCFLAG_DMAMAP)
626 n_elem = ahci_fill_sg(qc);
568 627
569 n_elem = ahci_fill_sg(qc); 628 /*
629 * Fill in command slot information.
630 */
631 opts = cmd_fis_len | n_elem << 16;
632 if (qc->tf.flags & ATA_TFLAG_WRITE)
633 opts |= AHCI_CMD_WRITE;
634 if (is_atapi)
635 opts |= AHCI_CMD_ATAPI | AHCI_CMD_PREFETCH;
570 636
571 pp->cmd_slot[0].opts |= cpu_to_le32(n_elem << 16); 637 ahci_fill_cmd_slot(pp, opts);
572} 638}
573 639
574static void ahci_restart_port(struct ata_port *ap, u32 irq_stat) 640static void ahci_restart_port(struct ata_port *ap, u32 irq_stat)
@@ -576,7 +642,6 @@ static void ahci_restart_port(struct ata_port *ap, u32 irq_stat)
576 void __iomem *mmio = ap->host_set->mmio_base; 642 void __iomem *mmio = ap->host_set->mmio_base;
577 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 643 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
578 u32 tmp; 644 u32 tmp;
579 int work;
580 645
581 if ((ap->device[0].class != ATA_DEV_ATAPI) || 646 if ((ap->device[0].class != ATA_DEV_ATAPI) ||
582 ((irq_stat & PORT_IRQ_TF_ERR) == 0)) 647 ((irq_stat & PORT_IRQ_TF_ERR) == 0))
@@ -592,20 +657,7 @@ static void ahci_restart_port(struct ata_port *ap, u32 irq_stat)
592 readl(port_mmio + PORT_SCR_ERR)); 657 readl(port_mmio + PORT_SCR_ERR));
593 658
594 /* stop DMA */ 659 /* stop DMA */
595 tmp = readl(port_mmio + PORT_CMD); 660 ahci_stop_engine(ap);
596 tmp &= ~PORT_CMD_START;
597 writel(tmp, port_mmio + PORT_CMD);
598
599 /* wait for engine to stop. TODO: this could be
600 * as long as 500 msec
601 */
602 work = 1000;
603 while (work-- > 0) {
604 tmp = readl(port_mmio + PORT_CMD);
605 if ((tmp & PORT_CMD_LIST_ON) == 0)
606 break;
607 udelay(10);
608 }
609 661
610 /* clear SATA phy error, if any */ 662 /* clear SATA phy error, if any */
611 tmp = readl(port_mmio + PORT_SCR_ERR); 663 tmp = readl(port_mmio + PORT_SCR_ERR);
@@ -624,10 +676,7 @@ static void ahci_restart_port(struct ata_port *ap, u32 irq_stat)
624 } 676 }
625 677
626 /* re-start DMA */ 678 /* re-start DMA */
627 tmp = readl(port_mmio + PORT_CMD); 679 ahci_start_engine(ap);
628 tmp |= PORT_CMD_START;
629 writel(tmp, port_mmio + PORT_CMD);
630 readl(port_mmio + PORT_CMD); /* flush */
631} 680}
632 681
633static void ahci_eng_timeout(struct ata_port *ap) 682static void ahci_eng_timeout(struct ata_port *ap)
@@ -642,25 +691,13 @@ static void ahci_eng_timeout(struct ata_port *ap)
642 691
643 spin_lock_irqsave(&host_set->lock, flags); 692 spin_lock_irqsave(&host_set->lock, flags);
644 693
694 ahci_restart_port(ap, readl(port_mmio + PORT_IRQ_STAT));
645 qc = ata_qc_from_tag(ap, ap->active_tag); 695 qc = ata_qc_from_tag(ap, ap->active_tag);
646 if (!qc) { 696 qc->err_mask |= AC_ERR_TIMEOUT;
647 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
648 ap->id);
649 } else {
650 ahci_restart_port(ap, readl(port_mmio + PORT_IRQ_STAT));
651
652 /* hack alert! We cannot use the supplied completion
653 * function from inside the ->eh_strategy_handler() thread.
654 * libata is the only user of ->eh_strategy_handler() in
655 * any kernel, so the default scsi_done() assumes it is
656 * not being called from the SCSI EH.
657 */
658 qc->scsidone = scsi_finish_command;
659 qc->err_mask |= AC_ERR_OTHER;
660 ata_qc_complete(qc);
661 }
662 697
663 spin_unlock_irqrestore(&host_set->lock, flags); 698 spin_unlock_irqrestore(&host_set->lock, flags);
699
700 ata_eh_qc_complete(qc);
664} 701}
665 702
666static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc) 703static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
@@ -678,7 +715,7 @@ static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
678 ci = readl(port_mmio + PORT_CMD_ISSUE); 715 ci = readl(port_mmio + PORT_CMD_ISSUE);
679 if (likely((ci & 0x1) == 0)) { 716 if (likely((ci & 0x1) == 0)) {
680 if (qc) { 717 if (qc) {
681 assert(qc->err_mask == 0); 718 WARN_ON(qc->err_mask);
682 ata_qc_complete(qc); 719 ata_qc_complete(qc);
683 qc = NULL; 720 qc = NULL;
684 } 721 }
@@ -697,7 +734,7 @@ static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
697 ahci_restart_port(ap, status); 734 ahci_restart_port(ap, status);
698 735
699 if (qc) { 736 if (qc) {
700 qc->err_mask |= AC_ERR_OTHER; 737 qc->err_mask |= err_mask;
701 ata_qc_complete(qc); 738 ata_qc_complete(qc);
702 } 739 }
703 } 740 }
@@ -770,7 +807,7 @@ static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *
770 return IRQ_RETVAL(handled); 807 return IRQ_RETVAL(handled);
771} 808}
772 809
773static int ahci_qc_issue(struct ata_queued_cmd *qc) 810static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
774{ 811{
775 struct ata_port *ap = qc->ap; 812 struct ata_port *ap = qc->ap;
776 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; 813 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c
index fc3ca051ceed..9327b62f97de 100644
--- a/drivers/scsi/ata_piix.c
+++ b/drivers/scsi/ata_piix.c
@@ -101,36 +101,54 @@ enum {
101 ICH5_PCS = 0x92, /* port control and status */ 101 ICH5_PCS = 0x92, /* port control and status */
102 PIIX_SCC = 0x0A, /* sub-class code register */ 102 PIIX_SCC = 0x0A, /* sub-class code register */
103 103
104 PIIX_FLAG_AHCI = (1 << 28), /* AHCI possible */ 104 PIIX_FLAG_IGNORE_PCS = (1 << 25), /* ignore PCS present bits */
105 PIIX_FLAG_CHECKINTR = (1 << 29), /* make sure PCI INTx enabled */ 105 PIIX_FLAG_SCR = (1 << 26), /* SCR available */
106 PIIX_FLAG_COMBINED = (1 << 30), /* combined mode possible */ 106 PIIX_FLAG_AHCI = (1 << 27), /* AHCI possible */
107 PIIX_FLAG_CHECKINTR = (1 << 28), /* make sure PCI INTx enabled */
108 PIIX_FLAG_COMBINED = (1 << 29), /* combined mode possible */
109 /* ICH6/7 use different scheme for map value */
110 PIIX_FLAG_COMBINED_ICH6 = PIIX_FLAG_COMBINED | (1 << 30),
107 111
108 /* combined mode. if set, PATA is channel 0. 112 /* combined mode. if set, PATA is channel 0.
109 * if clear, PATA is channel 1. 113 * if clear, PATA is channel 1.
110 */ 114 */
111 PIIX_COMB_PATA_P0 = (1 << 1),
112 PIIX_COMB = (1 << 2), /* combined mode enabled? */
113
114 PIIX_PORT_ENABLED = (1 << 0), 115 PIIX_PORT_ENABLED = (1 << 0),
115 PIIX_PORT_PRESENT = (1 << 4), 116 PIIX_PORT_PRESENT = (1 << 4),
116 117
117 PIIX_80C_PRI = (1 << 5) | (1 << 4), 118 PIIX_80C_PRI = (1 << 5) | (1 << 4),
118 PIIX_80C_SEC = (1 << 7) | (1 << 6), 119 PIIX_80C_SEC = (1 << 7) | (1 << 6),
119 120
120 ich5_pata = 0, 121 /* controller IDs */
121 ich5_sata = 1, 122 piix4_pata = 0,
122 piix4_pata = 2, 123 ich5_pata = 1,
123 ich6_sata = 3, 124 ich5_sata = 2,
124 ich6_sata_ahci = 4, 125 esb_sata = 3,
126 ich6_sata = 4,
127 ich6_sata_ahci = 5,
128 ich6m_sata_ahci = 6,
129
130 /* constants for mapping table */
131 P0 = 0, /* port 0 */
132 P1 = 1, /* port 1 */
133 P2 = 2, /* port 2 */
134 P3 = 3, /* port 3 */
135 IDE = -1, /* IDE */
136 NA = -2, /* not avaliable */
137 RV = -3, /* reserved */
125 138
126 PIIX_AHCI_DEVICE = 6, 139 PIIX_AHCI_DEVICE = 6,
127}; 140};
128 141
142struct piix_map_db {
143 const u32 mask;
144 const int map[][4];
145};
146
129static int piix_init_one (struct pci_dev *pdev, 147static int piix_init_one (struct pci_dev *pdev,
130 const struct pci_device_id *ent); 148 const struct pci_device_id *ent);
131 149
132static void piix_pata_phy_reset(struct ata_port *ap); 150static int piix_pata_probe_reset(struct ata_port *ap, unsigned int *classes);
133static void piix_sata_phy_reset(struct ata_port *ap); 151static int piix_sata_probe_reset(struct ata_port *ap, unsigned int *classes);
134static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev); 152static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev);
135static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev); 153static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev);
136 154
@@ -147,19 +165,32 @@ static const struct pci_device_id piix_pci_tbl[] = {
147 * list in drivers/pci/quirks.c. 165 * list in drivers/pci/quirks.c.
148 */ 166 */
149 167
168 /* 82801EB (ICH5) */
150 { 0x8086, 0x24d1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata }, 169 { 0x8086, 0x24d1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
170 /* 82801EB (ICH5) */
151 { 0x8086, 0x24df, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata }, 171 { 0x8086, 0x24df, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
152 { 0x8086, 0x25a3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata }, 172 /* 6300ESB (ICH5 variant with broken PCS present bits) */
153 { 0x8086, 0x25b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata }, 173 { 0x8086, 0x25a3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, esb_sata },
174 /* 6300ESB pretending RAID */
175 { 0x8086, 0x25b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, esb_sata },
176 /* 82801FB/FW (ICH6/ICH6W) */
154 { 0x8086, 0x2651, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata }, 177 { 0x8086, 0x2651, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata },
178 /* 82801FR/FRW (ICH6R/ICH6RW) */
155 { 0x8086, 0x2652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 179 { 0x8086, 0x2652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
156 { 0x8086, 0x2653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 180 /* 82801FBM ICH6M (ICH6R with only port 0 and 2 implemented) */
181 { 0x8086, 0x2653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6m_sata_ahci },
182 /* 82801GB/GR/GH (ICH7, identical to ICH6) */
157 { 0x8086, 0x27c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 183 { 0x8086, 0x27c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
158 { 0x8086, 0x27c4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 184 /* 2801GBM/GHM (ICH7M, identical to ICH6M) */
185 { 0x8086, 0x27c4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6m_sata_ahci },
186 /* Enterprise Southbridge 2 (where's the datasheet?) */
159 { 0x8086, 0x2680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 187 { 0x8086, 0x2680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
188 /* SATA Controller 1 IDE (ICH8, no datasheet yet) */
160 { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 189 { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
190 /* SATA Controller 2 IDE (ICH8, ditto) */
161 { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 191 { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
162 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 192 /* Mobile SATA Controller IDE (ICH8M, ditto) */
193 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6m_sata_ahci },
163 194
164 { } /* terminate list */ 195 { } /* terminate list */
165}; 196};
@@ -178,11 +209,11 @@ static struct scsi_host_template piix_sht = {
178 .name = DRV_NAME, 209 .name = DRV_NAME,
179 .ioctl = ata_scsi_ioctl, 210 .ioctl = ata_scsi_ioctl,
180 .queuecommand = ata_scsi_queuecmd, 211 .queuecommand = ata_scsi_queuecmd,
212 .eh_timed_out = ata_scsi_timed_out,
181 .eh_strategy_handler = ata_scsi_error, 213 .eh_strategy_handler = ata_scsi_error,
182 .can_queue = ATA_DEF_QUEUE, 214 .can_queue = ATA_DEF_QUEUE,
183 .this_id = ATA_SHT_THIS_ID, 215 .this_id = ATA_SHT_THIS_ID,
184 .sg_tablesize = LIBATA_MAX_PRD, 216 .sg_tablesize = LIBATA_MAX_PRD,
185 .max_sectors = ATA_MAX_SECTORS,
186 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 217 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
187 .emulated = ATA_SHT_EMULATED, 218 .emulated = ATA_SHT_EMULATED,
188 .use_clustering = ATA_SHT_USE_CLUSTERING, 219 .use_clustering = ATA_SHT_USE_CLUSTERING,
@@ -205,7 +236,7 @@ static const struct ata_port_operations piix_pata_ops = {
205 .exec_command = ata_exec_command, 236 .exec_command = ata_exec_command,
206 .dev_select = ata_std_dev_select, 237 .dev_select = ata_std_dev_select,
207 238
208 .phy_reset = piix_pata_phy_reset, 239 .probe_reset = piix_pata_probe_reset,
209 240
210 .bmdma_setup = ata_bmdma_setup, 241 .bmdma_setup = ata_bmdma_setup,
211 .bmdma_start = ata_bmdma_start, 242 .bmdma_start = ata_bmdma_start,
@@ -233,7 +264,7 @@ static const struct ata_port_operations piix_sata_ops = {
233 .exec_command = ata_exec_command, 264 .exec_command = ata_exec_command,
234 .dev_select = ata_std_dev_select, 265 .dev_select = ata_std_dev_select,
235 266
236 .phy_reset = piix_sata_phy_reset, 267 .probe_reset = piix_sata_probe_reset,
237 268
238 .bmdma_setup = ata_bmdma_setup, 269 .bmdma_setup = ata_bmdma_setup,
239 .bmdma_start = ata_bmdma_start, 270 .bmdma_start = ata_bmdma_start,
@@ -252,12 +283,62 @@ static const struct ata_port_operations piix_sata_ops = {
252 .host_stop = ata_host_stop, 283 .host_stop = ata_host_stop,
253}; 284};
254 285
286static struct piix_map_db ich5_map_db = {
287 .mask = 0x7,
288 .map = {
289 /* PM PS SM SS MAP */
290 { P0, NA, P1, NA }, /* 000b */
291 { P1, NA, P0, NA }, /* 001b */
292 { RV, RV, RV, RV },
293 { RV, RV, RV, RV },
294 { P0, P1, IDE, IDE }, /* 100b */
295 { P1, P0, IDE, IDE }, /* 101b */
296 { IDE, IDE, P0, P1 }, /* 110b */
297 { IDE, IDE, P1, P0 }, /* 111b */
298 },
299};
300
301static struct piix_map_db ich6_map_db = {
302 .mask = 0x3,
303 .map = {
304 /* PM PS SM SS MAP */
305 { P0, P1, P2, P3 }, /* 00b */
306 { IDE, IDE, P1, P3 }, /* 01b */
307 { P0, P2, IDE, IDE }, /* 10b */
308 { RV, RV, RV, RV },
309 },
310};
311
312static struct piix_map_db ich6m_map_db = {
313 .mask = 0x3,
314 .map = {
315 /* PM PS SM SS MAP */
316 { P0, P1, P2, P3 }, /* 00b */
317 { RV, RV, RV, RV },
318 { P0, P2, IDE, IDE }, /* 10b */
319 { RV, RV, RV, RV },
320 },
321};
322
255static struct ata_port_info piix_port_info[] = { 323static struct ata_port_info piix_port_info[] = {
324 /* piix4_pata */
325 {
326 .sht = &piix_sht,
327 .host_flags = ATA_FLAG_SLAVE_POSS,
328 .pio_mask = 0x1f, /* pio0-4 */
329#if 0
330 .mwdma_mask = 0x06, /* mwdma1-2 */
331#else
332 .mwdma_mask = 0x00, /* mwdma broken */
333#endif
334 .udma_mask = ATA_UDMA_MASK_40C,
335 .port_ops = &piix_pata_ops,
336 },
337
256 /* ich5_pata */ 338 /* ich5_pata */
257 { 339 {
258 .sht = &piix_sht, 340 .sht = &piix_sht,
259 .host_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | 341 .host_flags = ATA_FLAG_SLAVE_POSS | PIIX_FLAG_CHECKINTR,
260 PIIX_FLAG_CHECKINTR,
261 .pio_mask = 0x1f, /* pio0-4 */ 342 .pio_mask = 0x1f, /* pio0-4 */
262#if 0 343#if 0
263 .mwdma_mask = 0x06, /* mwdma1-2 */ 344 .mwdma_mask = 0x06, /* mwdma1-2 */
@@ -271,50 +352,63 @@ static struct ata_port_info piix_port_info[] = {
271 /* ich5_sata */ 352 /* ich5_sata */
272 { 353 {
273 .sht = &piix_sht, 354 .sht = &piix_sht,
274 .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST | 355 .host_flags = ATA_FLAG_SATA | PIIX_FLAG_COMBINED |
275 PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR, 356 PIIX_FLAG_CHECKINTR,
276 .pio_mask = 0x1f, /* pio0-4 */ 357 .pio_mask = 0x1f, /* pio0-4 */
277 .mwdma_mask = 0x07, /* mwdma0-2 */ 358 .mwdma_mask = 0x07, /* mwdma0-2 */
278 .udma_mask = 0x7f, /* udma0-6 */ 359 .udma_mask = 0x7f, /* udma0-6 */
279 .port_ops = &piix_sata_ops, 360 .port_ops = &piix_sata_ops,
361 .private_data = &ich5_map_db,
280 }, 362 },
281 363
282 /* piix4_pata */ 364 /* i6300esb_sata */
283 { 365 {
284 .sht = &piix_sht, 366 .sht = &piix_sht,
285 .host_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 367 .host_flags = ATA_FLAG_SATA | PIIX_FLAG_COMBINED |
368 PIIX_FLAG_CHECKINTR | PIIX_FLAG_IGNORE_PCS,
286 .pio_mask = 0x1f, /* pio0-4 */ 369 .pio_mask = 0x1f, /* pio0-4 */
287#if 0 370 .mwdma_mask = 0x07, /* mwdma0-2 */
288 .mwdma_mask = 0x06, /* mwdma1-2 */ 371 .udma_mask = 0x7f, /* udma0-6 */
289#else 372 .port_ops = &piix_sata_ops,
290 .mwdma_mask = 0x00, /* mwdma broken */ 373 .private_data = &ich5_map_db,
291#endif
292 .udma_mask = ATA_UDMA_MASK_40C,
293 .port_ops = &piix_pata_ops,
294 }, 374 },
295 375
296 /* ich6_sata */ 376 /* ich6_sata */
297 { 377 {
298 .sht = &piix_sht, 378 .sht = &piix_sht,
299 .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST | 379 .host_flags = ATA_FLAG_SATA | PIIX_FLAG_COMBINED_ICH6 |
300 PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR | 380 PIIX_FLAG_CHECKINTR | PIIX_FLAG_SCR,
301 ATA_FLAG_SLAVE_POSS,
302 .pio_mask = 0x1f, /* pio0-4 */ 381 .pio_mask = 0x1f, /* pio0-4 */
303 .mwdma_mask = 0x07, /* mwdma0-2 */ 382 .mwdma_mask = 0x07, /* mwdma0-2 */
304 .udma_mask = 0x7f, /* udma0-6 */ 383 .udma_mask = 0x7f, /* udma0-6 */
305 .port_ops = &piix_sata_ops, 384 .port_ops = &piix_sata_ops,
385 .private_data = &ich6_map_db,
306 }, 386 },
307 387
308 /* ich6_sata_ahci */ 388 /* ich6_sata_ahci */
309 { 389 {
310 .sht = &piix_sht, 390 .sht = &piix_sht,
311 .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST | 391 .host_flags = ATA_FLAG_SATA | PIIX_FLAG_COMBINED_ICH6 |
312 PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR | 392 PIIX_FLAG_CHECKINTR | PIIX_FLAG_SCR |
313 ATA_FLAG_SLAVE_POSS | PIIX_FLAG_AHCI, 393 PIIX_FLAG_AHCI,
394 .pio_mask = 0x1f, /* pio0-4 */
395 .mwdma_mask = 0x07, /* mwdma0-2 */
396 .udma_mask = 0x7f, /* udma0-6 */
397 .port_ops = &piix_sata_ops,
398 .private_data = &ich6_map_db,
399 },
400
401 /* ich6m_sata_ahci */
402 {
403 .sht = &piix_sht,
404 .host_flags = ATA_FLAG_SATA | PIIX_FLAG_COMBINED_ICH6 |
405 PIIX_FLAG_CHECKINTR | PIIX_FLAG_SCR |
406 PIIX_FLAG_AHCI,
314 .pio_mask = 0x1f, /* pio0-4 */ 407 .pio_mask = 0x1f, /* pio0-4 */
315 .mwdma_mask = 0x07, /* mwdma0-2 */ 408 .mwdma_mask = 0x07, /* mwdma0-2 */
316 .udma_mask = 0x7f, /* udma0-6 */ 409 .udma_mask = 0x7f, /* udma0-6 */
317 .port_ops = &piix_sata_ops, 410 .port_ops = &piix_sata_ops,
411 .private_data = &ich6m_map_db,
318 }, 412 },
319}; 413};
320 414
@@ -363,102 +457,123 @@ cbl40:
363} 457}
364 458
365/** 459/**
366 * piix_pata_phy_reset - Probe specified port on PATA host controller 460 * piix_pata_probeinit - probeinit for PATA host controller
367 * @ap: Port to probe 461 * @ap: Target port
368 * 462 *
369 * Probe PATA phy. 463 * Probeinit including cable detection.
370 * 464 *
371 * LOCKING: 465 * LOCKING:
372 * None (inherited from caller). 466 * None (inherited from caller).
373 */ 467 */
468static void piix_pata_probeinit(struct ata_port *ap)
469{
470 piix_pata_cbl_detect(ap);
471 ata_std_probeinit(ap);
472}
374 473
375static void piix_pata_phy_reset(struct ata_port *ap) 474/**
475 * piix_pata_probe_reset - Perform reset on PATA port and classify
476 * @ap: Port to reset
477 * @classes: Resulting classes of attached devices
478 *
479 * Reset PATA phy and classify attached devices.
480 *
481 * LOCKING:
482 * None (inherited from caller).
483 */
484static int piix_pata_probe_reset(struct ata_port *ap, unsigned int *classes)
376{ 485{
377 struct pci_dev *pdev = to_pci_dev(ap->host_set->dev); 486 struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
378 487
379 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->hard_port_no])) { 488 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->hard_port_no])) {
380 ata_port_disable(ap);
381 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id); 489 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
382 return; 490 return 0;
383 } 491 }
384 492
385 piix_pata_cbl_detect(ap); 493 return ata_drive_probe_reset(ap, piix_pata_probeinit,
386 494 ata_std_softreset, NULL,
387 ata_port_probe(ap); 495 ata_std_postreset, classes);
388
389 ata_bus_reset(ap);
390} 496}
391 497
392/** 498/**
393 * piix_sata_probe - Probe PCI device for present SATA devices 499 * piix_sata_probe - Probe PCI device for present SATA devices
394 * @ap: Port associated with the PCI device we wish to probe 500 * @ap: Port associated with the PCI device we wish to probe
395 * 501 *
396 * Reads SATA PCI device's PCI config register Port Configuration 502 * Reads and configures SATA PCI device's PCI config register
397 * and Status (PCS) to determine port and device availability. 503 * Port Configuration and Status (PCS) to determine port and
504 * device availability.
398 * 505 *
399 * LOCKING: 506 * LOCKING:
400 * None (inherited from caller). 507 * None (inherited from caller).
401 * 508 *
402 * RETURNS: 509 * RETURNS:
403 * Non-zero if port is enabled, it may or may not have a device 510 * Mask of avaliable devices on the port.
404 * attached in that case (PRESENT bit would only be set if BIOS probe
405 * was done). Zero is returned if port is disabled.
406 */ 511 */
407static int piix_sata_probe (struct ata_port *ap) 512static unsigned int piix_sata_probe (struct ata_port *ap)
408{ 513{
409 struct pci_dev *pdev = to_pci_dev(ap->host_set->dev); 514 struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
410 int combined = (ap->flags & ATA_FLAG_SLAVE_POSS); 515 const unsigned int *map = ap->host_set->private_data;
411 int orig_mask, mask, i; 516 int base = 2 * ap->hard_port_no;
517 unsigned int present_mask = 0;
518 int port, i;
412 u8 pcs; 519 u8 pcs;
413 520
414 mask = (PIIX_PORT_PRESENT << ap->hard_port_no) |
415 (PIIX_PORT_ENABLED << ap->hard_port_no);
416
417 pci_read_config_byte(pdev, ICH5_PCS, &pcs); 521 pci_read_config_byte(pdev, ICH5_PCS, &pcs);
418 orig_mask = (int) pcs & 0xff; 522 DPRINTK("ata%u: ENTER, pcs=0x%x base=%d\n", ap->id, pcs, base);
419
420 /* TODO: this is vaguely wrong for ICH6 combined mode,
421 * where only two of the four SATA ports are mapped
422 * onto a single ATA channel. It is also vaguely inaccurate
423 * for ICH5, which has only two ports. However, this is ok,
424 * as further device presence detection code will handle
425 * any false positives produced here.
426 */
427 523
428 for (i = 0; i < 4; i++) { 524 /* enable all ports on this ap and wait for them to settle */
429 mask = (PIIX_PORT_ENABLED << i); 525 for (i = 0; i < 2; i++) {
526 port = map[base + i];
527 if (port >= 0)
528 pcs |= 1 << port;
529 }
530
531 pci_write_config_byte(pdev, ICH5_PCS, pcs);
532 msleep(100);
430 533
431 if ((orig_mask & mask) == mask) 534 /* let's see which devices are present */
432 if (combined || (i == ap->hard_port_no)) 535 pci_read_config_byte(pdev, ICH5_PCS, &pcs);
433 return 1; 536
537 for (i = 0; i < 2; i++) {
538 port = map[base + i];
539 if (port < 0)
540 continue;
541 if (ap->flags & PIIX_FLAG_IGNORE_PCS || pcs & 1 << (4 + port))
542 present_mask |= 1 << i;
543 else
544 pcs &= ~(1 << port);
434 } 545 }
435 546
436 return 0; 547 /* disable offline ports on non-AHCI controllers */
548 if (!(ap->flags & PIIX_FLAG_AHCI))
549 pci_write_config_byte(pdev, ICH5_PCS, pcs);
550
551 DPRINTK("ata%u: LEAVE, pcs=0x%x present_mask=0x%x\n",
552 ap->id, pcs, present_mask);
553
554 return present_mask;
437} 555}
438 556
439/** 557/**
440 * piix_sata_phy_reset - Probe specified port on SATA host controller 558 * piix_sata_probe_reset - Perform reset on SATA port and classify
441 * @ap: Port to probe 559 * @ap: Port to reset
560 * @classes: Resulting classes of attached devices
442 * 561 *
443 * Probe SATA phy. 562 * Reset SATA phy and classify attached devices.
444 * 563 *
445 * LOCKING: 564 * LOCKING:
446 * None (inherited from caller). 565 * None (inherited from caller).
447 */ 566 */
448 567static int piix_sata_probe_reset(struct ata_port *ap, unsigned int *classes)
449static void piix_sata_phy_reset(struct ata_port *ap)
450{ 568{
451 if (!piix_sata_probe(ap)) { 569 if (!piix_sata_probe(ap)) {
452 ata_port_disable(ap);
453 printk(KERN_INFO "ata%u: SATA port has no device.\n", ap->id); 570 printk(KERN_INFO "ata%u: SATA port has no device.\n", ap->id);
454 return; 571 return 0;
455 } 572 }
456 573
457 ap->cbl = ATA_CBL_SATA; 574 return ata_drive_probe_reset(ap, ata_std_probeinit,
458 575 ata_std_softreset, NULL,
459 ata_port_probe(ap); 576 ata_std_postreset, classes);
460
461 ata_bus_reset(ap);
462} 577}
463 578
464/** 579/**
@@ -627,6 +742,7 @@ static int piix_disable_ahci(struct pci_dev *pdev)
627 742
628/** 743/**
629 * piix_check_450nx_errata - Check for problem 450NX setup 744 * piix_check_450nx_errata - Check for problem 450NX setup
745 * @ata_dev: the PCI device to check
630 * 746 *
631 * Check for the present of 450NX errata #19 and errata #25. If 747 * Check for the present of 450NX errata #19 and errata #25. If
632 * they are found return an error code so we can turn off DMA 748 * they are found return an error code so we can turn off DMA
@@ -659,6 +775,54 @@ static int __devinit piix_check_450nx_errata(struct pci_dev *ata_dev)
659 return no_piix_dma; 775 return no_piix_dma;
660} 776}
661 777
778static void __devinit piix_init_sata_map(struct pci_dev *pdev,
779 struct ata_port_info *pinfo)
780{
781 struct piix_map_db *map_db = pinfo[0].private_data;
782 const unsigned int *map;
783 int i, invalid_map = 0;
784 u8 map_value;
785
786 pci_read_config_byte(pdev, ICH5_PMR, &map_value);
787
788 map = map_db->map[map_value & map_db->mask];
789
790 dev_printk(KERN_INFO, &pdev->dev, "MAP [");
791 for (i = 0; i < 4; i++) {
792 switch (map[i]) {
793 case RV:
794 invalid_map = 1;
795 printk(" XX");
796 break;
797
798 case NA:
799 printk(" --");
800 break;
801
802 case IDE:
803 WARN_ON((i & 1) || map[i + 1] != IDE);
804 pinfo[i / 2] = piix_port_info[ich5_pata];
805 i++;
806 printk(" IDE IDE");
807 break;
808
809 default:
810 printk(" P%d", map[i]);
811 if (i & 1)
812 pinfo[i / 2].host_flags |= ATA_FLAG_SLAVE_POSS;
813 break;
814 }
815 }
816 printk(" ]\n");
817
818 if (invalid_map)
819 dev_printk(KERN_ERR, &pdev->dev,
820 "invalid MAP value %u\n", map_value);
821
822 pinfo[0].private_data = (void *)map;
823 pinfo[1].private_data = (void *)map;
824}
825
662/** 826/**
663 * piix_init_one - Register PIIX ATA PCI device with kernel services 827 * piix_init_one - Register PIIX ATA PCI device with kernel services
664 * @pdev: PCI device to register 828 * @pdev: PCI device to register
@@ -677,9 +841,9 @@ static int __devinit piix_check_450nx_errata(struct pci_dev *ata_dev)
677static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 841static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
678{ 842{
679 static int printed_version; 843 static int printed_version;
680 struct ata_port_info *port_info[2]; 844 struct ata_port_info port_info[2];
681 unsigned int combined = 0; 845 struct ata_port_info *ppinfo[2] = { &port_info[0], &port_info[1] };
682 unsigned int pata_chan = 0, sata_chan = 0; 846 unsigned long host_flags;
683 847
684 if (!printed_version++) 848 if (!printed_version++)
685 dev_printk(KERN_DEBUG, &pdev->dev, 849 dev_printk(KERN_DEBUG, &pdev->dev,
@@ -689,10 +853,12 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
689 if (!in_module_init) 853 if (!in_module_init)
690 return -ENODEV; 854 return -ENODEV;
691 855
692 port_info[0] = &piix_port_info[ent->driver_data]; 856 port_info[0] = piix_port_info[ent->driver_data];
693 port_info[1] = &piix_port_info[ent->driver_data]; 857 port_info[1] = piix_port_info[ent->driver_data];
858
859 host_flags = port_info[0].host_flags;
694 860
695 if (port_info[0]->host_flags & PIIX_FLAG_AHCI) { 861 if (host_flags & PIIX_FLAG_AHCI) {
696 u8 tmp; 862 u8 tmp;
697 pci_read_config_byte(pdev, PIIX_SCC, &tmp); 863 pci_read_config_byte(pdev, PIIX_SCC, &tmp);
698 if (tmp == PIIX_AHCI_DEVICE) { 864 if (tmp == PIIX_AHCI_DEVICE) {
@@ -702,18 +868,9 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
702 } 868 }
703 } 869 }
704 870
705 if (port_info[0]->host_flags & PIIX_FLAG_COMBINED) { 871 /* Initialize SATA map */
706 u8 tmp; 872 if (host_flags & ATA_FLAG_SATA)
707 pci_read_config_byte(pdev, ICH5_PMR, &tmp); 873 piix_init_sata_map(pdev, port_info);
708
709 if (tmp & PIIX_COMB) {
710 combined = 1;
711 if (tmp & PIIX_COMB_PATA_P0)
712 sata_chan = 1;
713 else
714 pata_chan = 1;
715 }
716 }
717 874
718 /* On ICH5, some BIOSen disable the interrupt using the 875 /* On ICH5, some BIOSen disable the interrupt using the
719 * PCI_COMMAND_INTX_DISABLE bit added in PCI 2.3. 876 * PCI_COMMAND_INTX_DISABLE bit added in PCI 2.3.
@@ -721,28 +878,19 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
721 * MSI is disabled (and it is disabled, as we don't use 878 * MSI is disabled (and it is disabled, as we don't use
722 * message-signalled interrupts currently). 879 * message-signalled interrupts currently).
723 */ 880 */
724 if (port_info[0]->host_flags & PIIX_FLAG_CHECKINTR) 881 if (host_flags & PIIX_FLAG_CHECKINTR)
725 pci_intx(pdev, 1); 882 pci_intx(pdev, 1);
726 883
727 if (combined) {
728 port_info[sata_chan] = &piix_port_info[ent->driver_data];
729 port_info[sata_chan]->host_flags |= ATA_FLAG_SLAVE_POSS;
730 port_info[pata_chan] = &piix_port_info[ich5_pata];
731
732 dev_printk(KERN_WARNING, &pdev->dev,
733 "combined mode detected (p=%u, s=%u)\n",
734 pata_chan, sata_chan);
735 }
736 if (piix_check_450nx_errata(pdev)) { 884 if (piix_check_450nx_errata(pdev)) {
737 /* This writes into the master table but it does not 885 /* This writes into the master table but it does not
738 really matter for this errata as we will apply it to 886 really matter for this errata as we will apply it to
739 all the PIIX devices on the board */ 887 all the PIIX devices on the board */
740 port_info[0]->mwdma_mask = 0; 888 port_info[0].mwdma_mask = 0;
741 port_info[0]->udma_mask = 0; 889 port_info[0].udma_mask = 0;
742 port_info[1]->mwdma_mask = 0; 890 port_info[1].mwdma_mask = 0;
743 port_info[1]->udma_mask = 0; 891 port_info[1].udma_mask = 0;
744 } 892 }
745 return ata_pci_init_one(pdev, port_info, 2); 893 return ata_pci_init_one(pdev, ppinfo, 2);
746} 894}
747 895
748static int __init piix_init(void) 896static int __init piix_init(void)
diff --git a/drivers/scsi/libata-bmdma.c b/drivers/scsi/libata-bmdma.c
new file mode 100644
index 000000000000..a93336adcd23
--- /dev/null
+++ b/drivers/scsi/libata-bmdma.c
@@ -0,0 +1,703 @@
1/*
2 * libata-bmdma.c - helper library for PCI IDE BMDMA
3 *
4 * Maintained by: Jeff Garzik <jgarzik@pobox.com>
5 * Please ALWAYS copy linux-ide@vger.kernel.org
6 * on emails.
7 *
8 * Copyright 2003-2006 Red Hat, Inc. All rights reserved.
9 * Copyright 2003-2006 Jeff Garzik
10 *
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; see the file COPYING. If not, write to
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 *
27 * libata documentation is available via 'make {ps|pdf}docs',
28 * as Documentation/DocBook/libata.*
29 *
30 * Hardware documentation available from http://www.t13.org/ and
31 * http://www.sata-io.org/
32 *
33 */
34
35#include <linux/config.h>
36#include <linux/kernel.h>
37#include <linux/pci.h>
38#include <linux/libata.h>
39
40#include "libata.h"
41
42/**
43 * ata_tf_load_pio - send taskfile registers to host controller
44 * @ap: Port to which output is sent
45 * @tf: ATA taskfile register set
46 *
47 * Outputs ATA taskfile to standard ATA host controller.
48 *
49 * LOCKING:
50 * Inherited from caller.
51 */
52
53static void ata_tf_load_pio(struct ata_port *ap, const struct ata_taskfile *tf)
54{
55 struct ata_ioports *ioaddr = &ap->ioaddr;
56 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
57
58 if (tf->ctl != ap->last_ctl) {
59 outb(tf->ctl, ioaddr->ctl_addr);
60 ap->last_ctl = tf->ctl;
61 ata_wait_idle(ap);
62 }
63
64 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
65 outb(tf->hob_feature, ioaddr->feature_addr);
66 outb(tf->hob_nsect, ioaddr->nsect_addr);
67 outb(tf->hob_lbal, ioaddr->lbal_addr);
68 outb(tf->hob_lbam, ioaddr->lbam_addr);
69 outb(tf->hob_lbah, ioaddr->lbah_addr);
70 VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
71 tf->hob_feature,
72 tf->hob_nsect,
73 tf->hob_lbal,
74 tf->hob_lbam,
75 tf->hob_lbah);
76 }
77
78 if (is_addr) {
79 outb(tf->feature, ioaddr->feature_addr);
80 outb(tf->nsect, ioaddr->nsect_addr);
81 outb(tf->lbal, ioaddr->lbal_addr);
82 outb(tf->lbam, ioaddr->lbam_addr);
83 outb(tf->lbah, ioaddr->lbah_addr);
84 VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
85 tf->feature,
86 tf->nsect,
87 tf->lbal,
88 tf->lbam,
89 tf->lbah);
90 }
91
92 if (tf->flags & ATA_TFLAG_DEVICE) {
93 outb(tf->device, ioaddr->device_addr);
94 VPRINTK("device 0x%X\n", tf->device);
95 }
96
97 ata_wait_idle(ap);
98}
99
100/**
101 * ata_tf_load_mmio - send taskfile registers to host controller
102 * @ap: Port to which output is sent
103 * @tf: ATA taskfile register set
104 *
105 * Outputs ATA taskfile to standard ATA host controller using MMIO.
106 *
107 * LOCKING:
108 * Inherited from caller.
109 */
110
111static void ata_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
112{
113 struct ata_ioports *ioaddr = &ap->ioaddr;
114 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
115
116 if (tf->ctl != ap->last_ctl) {
117 writeb(tf->ctl, (void __iomem *) ap->ioaddr.ctl_addr);
118 ap->last_ctl = tf->ctl;
119 ata_wait_idle(ap);
120 }
121
122 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
123 writeb(tf->hob_feature, (void __iomem *) ioaddr->feature_addr);
124 writeb(tf->hob_nsect, (void __iomem *) ioaddr->nsect_addr);
125 writeb(tf->hob_lbal, (void __iomem *) ioaddr->lbal_addr);
126 writeb(tf->hob_lbam, (void __iomem *) ioaddr->lbam_addr);
127 writeb(tf->hob_lbah, (void __iomem *) ioaddr->lbah_addr);
128 VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
129 tf->hob_feature,
130 tf->hob_nsect,
131 tf->hob_lbal,
132 tf->hob_lbam,
133 tf->hob_lbah);
134 }
135
136 if (is_addr) {
137 writeb(tf->feature, (void __iomem *) ioaddr->feature_addr);
138 writeb(tf->nsect, (void __iomem *) ioaddr->nsect_addr);
139 writeb(tf->lbal, (void __iomem *) ioaddr->lbal_addr);
140 writeb(tf->lbam, (void __iomem *) ioaddr->lbam_addr);
141 writeb(tf->lbah, (void __iomem *) ioaddr->lbah_addr);
142 VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
143 tf->feature,
144 tf->nsect,
145 tf->lbal,
146 tf->lbam,
147 tf->lbah);
148 }
149
150 if (tf->flags & ATA_TFLAG_DEVICE) {
151 writeb(tf->device, (void __iomem *) ioaddr->device_addr);
152 VPRINTK("device 0x%X\n", tf->device);
153 }
154
155 ata_wait_idle(ap);
156}
157
158
159/**
160 * ata_tf_load - send taskfile registers to host controller
161 * @ap: Port to which output is sent
162 * @tf: ATA taskfile register set
163 *
164 * Outputs ATA taskfile to standard ATA host controller using MMIO
165 * or PIO as indicated by the ATA_FLAG_MMIO flag.
166 * Writes the control, feature, nsect, lbal, lbam, and lbah registers.
167 * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,
168 * hob_lbal, hob_lbam, and hob_lbah.
169 *
170 * This function waits for idle (!BUSY and !DRQ) after writing
171 * registers. If the control register has a new value, this
172 * function also waits for idle after writing control and before
173 * writing the remaining registers.
174 *
175 * May be used as the tf_load() entry in ata_port_operations.
176 *
177 * LOCKING:
178 * Inherited from caller.
179 */
180void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
181{
182 if (ap->flags & ATA_FLAG_MMIO)
183 ata_tf_load_mmio(ap, tf);
184 else
185 ata_tf_load_pio(ap, tf);
186}
187
188/**
189 * ata_exec_command_pio - issue ATA command to host controller
190 * @ap: port to which command is being issued
191 * @tf: ATA taskfile register set
192 *
193 * Issues PIO write to ATA command register, with proper
194 * synchronization with interrupt handler / other threads.
195 *
196 * LOCKING:
197 * spin_lock_irqsave(host_set lock)
198 */
199
200static void ata_exec_command_pio(struct ata_port *ap, const struct ata_taskfile *tf)
201{
202 DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command);
203
204 outb(tf->command, ap->ioaddr.command_addr);
205 ata_pause(ap);
206}
207
208
209/**
210 * ata_exec_command_mmio - issue ATA command to host controller
211 * @ap: port to which command is being issued
212 * @tf: ATA taskfile register set
213 *
214 * Issues MMIO write to ATA command register, with proper
215 * synchronization with interrupt handler / other threads.
216 *
217 * LOCKING:
218 * spin_lock_irqsave(host_set lock)
219 */
220
221static void ata_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
222{
223 DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command);
224
225 writeb(tf->command, (void __iomem *) ap->ioaddr.command_addr);
226 ata_pause(ap);
227}
228
229
230/**
231 * ata_exec_command - issue ATA command to host controller
232 * @ap: port to which command is being issued
233 * @tf: ATA taskfile register set
234 *
235 * Issues PIO/MMIO write to ATA command register, with proper
236 * synchronization with interrupt handler / other threads.
237 *
238 * LOCKING:
239 * spin_lock_irqsave(host_set lock)
240 */
241void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf)
242{
243 if (ap->flags & ATA_FLAG_MMIO)
244 ata_exec_command_mmio(ap, tf);
245 else
246 ata_exec_command_pio(ap, tf);
247}
248
249/**
250 * ata_tf_read_pio - input device's ATA taskfile shadow registers
251 * @ap: Port from which input is read
252 * @tf: ATA taskfile register set for storing input
253 *
254 * Reads ATA taskfile registers for currently-selected device
255 * into @tf.
256 *
257 * LOCKING:
258 * Inherited from caller.
259 */
260
261static void ata_tf_read_pio(struct ata_port *ap, struct ata_taskfile *tf)
262{
263 struct ata_ioports *ioaddr = &ap->ioaddr;
264
265 tf->command = ata_check_status(ap);
266 tf->feature = inb(ioaddr->error_addr);
267 tf->nsect = inb(ioaddr->nsect_addr);
268 tf->lbal = inb(ioaddr->lbal_addr);
269 tf->lbam = inb(ioaddr->lbam_addr);
270 tf->lbah = inb(ioaddr->lbah_addr);
271 tf->device = inb(ioaddr->device_addr);
272
273 if (tf->flags & ATA_TFLAG_LBA48) {
274 outb(tf->ctl | ATA_HOB, ioaddr->ctl_addr);
275 tf->hob_feature = inb(ioaddr->error_addr);
276 tf->hob_nsect = inb(ioaddr->nsect_addr);
277 tf->hob_lbal = inb(ioaddr->lbal_addr);
278 tf->hob_lbam = inb(ioaddr->lbam_addr);
279 tf->hob_lbah = inb(ioaddr->lbah_addr);
280 }
281}
282
283/**
284 * ata_tf_read_mmio - input device's ATA taskfile shadow registers
285 * @ap: Port from which input is read
286 * @tf: ATA taskfile register set for storing input
287 *
288 * Reads ATA taskfile registers for currently-selected device
289 * into @tf via MMIO.
290 *
291 * LOCKING:
292 * Inherited from caller.
293 */
294
295static void ata_tf_read_mmio(struct ata_port *ap, struct ata_taskfile *tf)
296{
297 struct ata_ioports *ioaddr = &ap->ioaddr;
298
299 tf->command = ata_check_status(ap);
300 tf->feature = readb((void __iomem *)ioaddr->error_addr);
301 tf->nsect = readb((void __iomem *)ioaddr->nsect_addr);
302 tf->lbal = readb((void __iomem *)ioaddr->lbal_addr);
303 tf->lbam = readb((void __iomem *)ioaddr->lbam_addr);
304 tf->lbah = readb((void __iomem *)ioaddr->lbah_addr);
305 tf->device = readb((void __iomem *)ioaddr->device_addr);
306
307 if (tf->flags & ATA_TFLAG_LBA48) {
308 writeb(tf->ctl | ATA_HOB, (void __iomem *) ap->ioaddr.ctl_addr);
309 tf->hob_feature = readb((void __iomem *)ioaddr->error_addr);
310 tf->hob_nsect = readb((void __iomem *)ioaddr->nsect_addr);
311 tf->hob_lbal = readb((void __iomem *)ioaddr->lbal_addr);
312 tf->hob_lbam = readb((void __iomem *)ioaddr->lbam_addr);
313 tf->hob_lbah = readb((void __iomem *)ioaddr->lbah_addr);
314 }
315}
316
317
318/**
319 * ata_tf_read - input device's ATA taskfile shadow registers
320 * @ap: Port from which input is read
321 * @tf: ATA taskfile register set for storing input
322 *
323 * Reads ATA taskfile registers for currently-selected device
324 * into @tf.
325 *
326 * Reads nsect, lbal, lbam, lbah, and device. If ATA_TFLAG_LBA48
327 * is set, also reads the hob registers.
328 *
329 * May be used as the tf_read() entry in ata_port_operations.
330 *
331 * LOCKING:
332 * Inherited from caller.
333 */
334void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
335{
336 if (ap->flags & ATA_FLAG_MMIO)
337 ata_tf_read_mmio(ap, tf);
338 else
339 ata_tf_read_pio(ap, tf);
340}
341
342/**
343 * ata_check_status_pio - Read device status reg & clear interrupt
344 * @ap: port where the device is
345 *
346 * Reads ATA taskfile status register for currently-selected device
347 * and return its value. This also clears pending interrupts
348 * from this device
349 *
350 * LOCKING:
351 * Inherited from caller.
352 */
353static u8 ata_check_status_pio(struct ata_port *ap)
354{
355 return inb(ap->ioaddr.status_addr);
356}
357
358/**
359 * ata_check_status_mmio - Read device status reg & clear interrupt
360 * @ap: port where the device is
361 *
362 * Reads ATA taskfile status register for currently-selected device
363 * via MMIO and return its value. This also clears pending interrupts
364 * from this device
365 *
366 * LOCKING:
367 * Inherited from caller.
368 */
369static u8 ata_check_status_mmio(struct ata_port *ap)
370{
371 return readb((void __iomem *) ap->ioaddr.status_addr);
372}
373
374
375/**
376 * ata_check_status - Read device status reg & clear interrupt
377 * @ap: port where the device is
378 *
379 * Reads ATA taskfile status register for currently-selected device
380 * and return its value. This also clears pending interrupts
381 * from this device
382 *
383 * May be used as the check_status() entry in ata_port_operations.
384 *
385 * LOCKING:
386 * Inherited from caller.
387 */
388u8 ata_check_status(struct ata_port *ap)
389{
390 if (ap->flags & ATA_FLAG_MMIO)
391 return ata_check_status_mmio(ap);
392 return ata_check_status_pio(ap);
393}
394
395
396/**
397 * ata_altstatus - Read device alternate status reg
398 * @ap: port where the device is
399 *
400 * Reads ATA taskfile alternate status register for
401 * currently-selected device and return its value.
402 *
403 * Note: may NOT be used as the check_altstatus() entry in
404 * ata_port_operations.
405 *
406 * LOCKING:
407 * Inherited from caller.
408 */
409u8 ata_altstatus(struct ata_port *ap)
410{
411 if (ap->ops->check_altstatus)
412 return ap->ops->check_altstatus(ap);
413
414 if (ap->flags & ATA_FLAG_MMIO)
415 return readb((void __iomem *)ap->ioaddr.altstatus_addr);
416 return inb(ap->ioaddr.altstatus_addr);
417}
418
419#ifdef CONFIG_PCI
420static struct ata_probe_ent *
421ata_probe_ent_alloc(struct device *dev, const struct ata_port_info *port)
422{
423 struct ata_probe_ent *probe_ent;
424
425 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
426 if (!probe_ent) {
427 printk(KERN_ERR DRV_NAME "(%s): out of memory\n",
428 kobject_name(&(dev->kobj)));
429 return NULL;
430 }
431
432 INIT_LIST_HEAD(&probe_ent->node);
433 probe_ent->dev = dev;
434
435 probe_ent->sht = port->sht;
436 probe_ent->host_flags = port->host_flags;
437 probe_ent->pio_mask = port->pio_mask;
438 probe_ent->mwdma_mask = port->mwdma_mask;
439 probe_ent->udma_mask = port->udma_mask;
440 probe_ent->port_ops = port->port_ops;
441
442 return probe_ent;
443}
444
445
446/**
447 * ata_pci_init_native_mode - Initialize native-mode driver
448 * @pdev: pci device to be initialized
449 * @port: array[2] of pointers to port info structures.
450 * @ports: bitmap of ports present
451 *
452 * Utility function which allocates and initializes an
453 * ata_probe_ent structure for a standard dual-port
454 * PIO-based IDE controller. The returned ata_probe_ent
455 * structure can be passed to ata_device_add(). The returned
456 * ata_probe_ent structure should then be freed with kfree().
457 *
458 * The caller need only pass the address of the primary port, the
459 * secondary will be deduced automatically. If the device has non
460 * standard secondary port mappings this function can be called twice,
461 * once for each interface.
462 */
463
464struct ata_probe_ent *
465ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int ports)
466{
467 struct ata_probe_ent *probe_ent =
468 ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]);
469 int p = 0;
470
471 if (!probe_ent)
472 return NULL;
473
474 probe_ent->irq = pdev->irq;
475 probe_ent->irq_flags = SA_SHIRQ;
476 probe_ent->private_data = port[0]->private_data;
477
478 if (ports & ATA_PORT_PRIMARY) {
479 probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 0);
480 probe_ent->port[p].altstatus_addr =
481 probe_ent->port[p].ctl_addr =
482 pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS;
483 probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4);
484 ata_std_ports(&probe_ent->port[p]);
485 p++;
486 }
487
488 if (ports & ATA_PORT_SECONDARY) {
489 probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 2);
490 probe_ent->port[p].altstatus_addr =
491 probe_ent->port[p].ctl_addr =
492 pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS;
493 probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4) + 8;
494 ata_std_ports(&probe_ent->port[p]);
495 p++;
496 }
497
498 probe_ent->n_ports = p;
499 return probe_ent;
500}
501
502
503static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
504 struct ata_port_info *port, int port_num)
505{
506 struct ata_probe_ent *probe_ent;
507
508 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port);
509 if (!probe_ent)
510 return NULL;
511
512 probe_ent->legacy_mode = 1;
513 probe_ent->n_ports = 1;
514 probe_ent->hard_port_no = port_num;
515 probe_ent->private_data = port->private_data;
516
517 switch(port_num)
518 {
519 case 0:
520 probe_ent->irq = 14;
521 probe_ent->port[0].cmd_addr = 0x1f0;
522 probe_ent->port[0].altstatus_addr =
523 probe_ent->port[0].ctl_addr = 0x3f6;
524 break;
525 case 1:
526 probe_ent->irq = 15;
527 probe_ent->port[0].cmd_addr = 0x170;
528 probe_ent->port[0].altstatus_addr =
529 probe_ent->port[0].ctl_addr = 0x376;
530 break;
531 }
532
533 probe_ent->port[0].bmdma_addr =
534 pci_resource_start(pdev, 4) + 8 * port_num;
535 ata_std_ports(&probe_ent->port[0]);
536
537 return probe_ent;
538}
539
540
541/**
542 * ata_pci_init_one - Initialize/register PCI IDE host controller
543 * @pdev: Controller to be initialized
544 * @port_info: Information from low-level host driver
545 * @n_ports: Number of ports attached to host controller
546 *
547 * This is a helper function which can be called from a driver's
548 * xxx_init_one() probe function if the hardware uses traditional
549 * IDE taskfile registers.
550 *
551 * This function calls pci_enable_device(), reserves its register
552 * regions, sets the dma mask, enables bus master mode, and calls
553 * ata_device_add()
554 *
555 * LOCKING:
556 * Inherited from PCI layer (may sleep).
557 *
558 * RETURNS:
559 * Zero on success, negative on errno-based value on error.
560 */
561
562int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
563 unsigned int n_ports)
564{
565 struct ata_probe_ent *probe_ent = NULL, *probe_ent2 = NULL;
566 struct ata_port_info *port[2];
567 u8 tmp8, mask;
568 unsigned int legacy_mode = 0;
569 int disable_dev_on_err = 1;
570 int rc;
571
572 DPRINTK("ENTER\n");
573
574 port[0] = port_info[0];
575 if (n_ports > 1)
576 port[1] = port_info[1];
577 else
578 port[1] = port[0];
579
580 if ((port[0]->host_flags & ATA_FLAG_NO_LEGACY) == 0
581 && (pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
582 /* TODO: What if one channel is in native mode ... */
583 pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8);
584 mask = (1 << 2) | (1 << 0);
585 if ((tmp8 & mask) != mask)
586 legacy_mode = (1 << 3);
587 }
588
589 /* FIXME... */
590 if ((!legacy_mode) && (n_ports > 2)) {
591 printk(KERN_ERR "ata: BUG: native mode, n_ports > 2\n");
592 n_ports = 2;
593 /* For now */
594 }
595
596 /* FIXME: Really for ATA it isn't safe because the device may be
597 multi-purpose and we want to leave it alone if it was already
598 enabled. Secondly for shared use as Arjan says we want refcounting
599
600 Checking dev->is_enabled is insufficient as this is not set at
601 boot for the primary video which is BIOS enabled
602 */
603
604 rc = pci_enable_device(pdev);
605 if (rc)
606 return rc;
607
608 rc = pci_request_regions(pdev, DRV_NAME);
609 if (rc) {
610 disable_dev_on_err = 0;
611 goto err_out;
612 }
613
614 /* FIXME: Should use platform specific mappers for legacy port ranges */
615 if (legacy_mode) {
616 if (!request_region(0x1f0, 8, "libata")) {
617 struct resource *conflict, res;
618 res.start = 0x1f0;
619 res.end = 0x1f0 + 8 - 1;
620 conflict = ____request_resource(&ioport_resource, &res);
621 if (!strcmp(conflict->name, "libata"))
622 legacy_mode |= (1 << 0);
623 else {
624 disable_dev_on_err = 0;
625 printk(KERN_WARNING "ata: 0x1f0 IDE port busy\n");
626 }
627 } else
628 legacy_mode |= (1 << 0);
629
630 if (!request_region(0x170, 8, "libata")) {
631 struct resource *conflict, res;
632 res.start = 0x170;
633 res.end = 0x170 + 8 - 1;
634 conflict = ____request_resource(&ioport_resource, &res);
635 if (!strcmp(conflict->name, "libata"))
636 legacy_mode |= (1 << 1);
637 else {
638 disable_dev_on_err = 0;
639 printk(KERN_WARNING "ata: 0x170 IDE port busy\n");
640 }
641 } else
642 legacy_mode |= (1 << 1);
643 }
644
645 /* we have legacy mode, but all ports are unavailable */
646 if (legacy_mode == (1 << 3)) {
647 rc = -EBUSY;
648 goto err_out_regions;
649 }
650
651 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
652 if (rc)
653 goto err_out_regions;
654 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
655 if (rc)
656 goto err_out_regions;
657
658 if (legacy_mode) {
659 if (legacy_mode & (1 << 0))
660 probe_ent = ata_pci_init_legacy_port(pdev, port[0], 0);
661 if (legacy_mode & (1 << 1))
662 probe_ent2 = ata_pci_init_legacy_port(pdev, port[1], 1);
663 } else {
664 if (n_ports == 2)
665 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
666 else
667 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY);
668 }
669 if (!probe_ent && !probe_ent2) {
670 rc = -ENOMEM;
671 goto err_out_regions;
672 }
673
674 pci_set_master(pdev);
675
676 /* FIXME: check ata_device_add return */
677 if (legacy_mode) {
678 if (legacy_mode & (1 << 0))
679 ata_device_add(probe_ent);
680 if (legacy_mode & (1 << 1))
681 ata_device_add(probe_ent2);
682 } else
683 ata_device_add(probe_ent);
684
685 kfree(probe_ent);
686 kfree(probe_ent2);
687
688 return 0;
689
690err_out_regions:
691 if (legacy_mode & (1 << 0))
692 release_region(0x1f0, 8);
693 if (legacy_mode & (1 << 1))
694 release_region(0x170, 8);
695 pci_release_regions(pdev);
696err_out:
697 if (disable_dev_on_err)
698 pci_disable_device(pdev);
699 return rc;
700}
701
702#endif /* CONFIG_PCI */
703
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 4f91b0dc572b..714b42bad935 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -61,24 +61,17 @@
61 61
62#include "libata.h" 62#include "libata.h"
63 63
64static unsigned int ata_busy_sleep (struct ata_port *ap, 64static unsigned int ata_dev_init_params(struct ata_port *ap,
65 unsigned long tmout_pat, 65 struct ata_device *dev);
66 unsigned long tmout);
67static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev);
68static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev);
69static void ata_set_mode(struct ata_port *ap); 66static void ata_set_mode(struct ata_port *ap);
70static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev); 67static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev);
71static unsigned int ata_get_mode_mask(const struct ata_port *ap, int shift); 68static unsigned int ata_dev_xfermask(struct ata_port *ap,
72static int fgb(u32 bitmap); 69 struct ata_device *dev);
73static int ata_choose_xfer_mode(const struct ata_port *ap,
74 u8 *xfer_mode_out,
75 unsigned int *xfer_shift_out);
76static void __ata_qc_complete(struct ata_queued_cmd *qc);
77 70
78static unsigned int ata_unique_id = 1; 71static unsigned int ata_unique_id = 1;
79static struct workqueue_struct *ata_wq; 72static struct workqueue_struct *ata_wq;
80 73
81int atapi_enabled = 0; 74int atapi_enabled = 1;
82module_param(atapi_enabled, int, 0444); 75module_param(atapi_enabled, int, 0444);
83MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)"); 76MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)");
84 77
@@ -91,403 +84,6 @@ MODULE_DESCRIPTION("Library module for ATA devices");
91MODULE_LICENSE("GPL"); 84MODULE_LICENSE("GPL");
92MODULE_VERSION(DRV_VERSION); 85MODULE_VERSION(DRV_VERSION);
93 86
94/**
95 * ata_tf_load_pio - send taskfile registers to host controller
96 * @ap: Port to which output is sent
97 * @tf: ATA taskfile register set
98 *
99 * Outputs ATA taskfile to standard ATA host controller.
100 *
101 * LOCKING:
102 * Inherited from caller.
103 */
104
105static void ata_tf_load_pio(struct ata_port *ap, const struct ata_taskfile *tf)
106{
107 struct ata_ioports *ioaddr = &ap->ioaddr;
108 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
109
110 if (tf->ctl != ap->last_ctl) {
111 outb(tf->ctl, ioaddr->ctl_addr);
112 ap->last_ctl = tf->ctl;
113 ata_wait_idle(ap);
114 }
115
116 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
117 outb(tf->hob_feature, ioaddr->feature_addr);
118 outb(tf->hob_nsect, ioaddr->nsect_addr);
119 outb(tf->hob_lbal, ioaddr->lbal_addr);
120 outb(tf->hob_lbam, ioaddr->lbam_addr);
121 outb(tf->hob_lbah, ioaddr->lbah_addr);
122 VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
123 tf->hob_feature,
124 tf->hob_nsect,
125 tf->hob_lbal,
126 tf->hob_lbam,
127 tf->hob_lbah);
128 }
129
130 if (is_addr) {
131 outb(tf->feature, ioaddr->feature_addr);
132 outb(tf->nsect, ioaddr->nsect_addr);
133 outb(tf->lbal, ioaddr->lbal_addr);
134 outb(tf->lbam, ioaddr->lbam_addr);
135 outb(tf->lbah, ioaddr->lbah_addr);
136 VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
137 tf->feature,
138 tf->nsect,
139 tf->lbal,
140 tf->lbam,
141 tf->lbah);
142 }
143
144 if (tf->flags & ATA_TFLAG_DEVICE) {
145 outb(tf->device, ioaddr->device_addr);
146 VPRINTK("device 0x%X\n", tf->device);
147 }
148
149 ata_wait_idle(ap);
150}
151
152/**
153 * ata_tf_load_mmio - send taskfile registers to host controller
154 * @ap: Port to which output is sent
155 * @tf: ATA taskfile register set
156 *
157 * Outputs ATA taskfile to standard ATA host controller using MMIO.
158 *
159 * LOCKING:
160 * Inherited from caller.
161 */
162
163static void ata_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
164{
165 struct ata_ioports *ioaddr = &ap->ioaddr;
166 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
167
168 if (tf->ctl != ap->last_ctl) {
169 writeb(tf->ctl, (void __iomem *) ap->ioaddr.ctl_addr);
170 ap->last_ctl = tf->ctl;
171 ata_wait_idle(ap);
172 }
173
174 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
175 writeb(tf->hob_feature, (void __iomem *) ioaddr->feature_addr);
176 writeb(tf->hob_nsect, (void __iomem *) ioaddr->nsect_addr);
177 writeb(tf->hob_lbal, (void __iomem *) ioaddr->lbal_addr);
178 writeb(tf->hob_lbam, (void __iomem *) ioaddr->lbam_addr);
179 writeb(tf->hob_lbah, (void __iomem *) ioaddr->lbah_addr);
180 VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
181 tf->hob_feature,
182 tf->hob_nsect,
183 tf->hob_lbal,
184 tf->hob_lbam,
185 tf->hob_lbah);
186 }
187
188 if (is_addr) {
189 writeb(tf->feature, (void __iomem *) ioaddr->feature_addr);
190 writeb(tf->nsect, (void __iomem *) ioaddr->nsect_addr);
191 writeb(tf->lbal, (void __iomem *) ioaddr->lbal_addr);
192 writeb(tf->lbam, (void __iomem *) ioaddr->lbam_addr);
193 writeb(tf->lbah, (void __iomem *) ioaddr->lbah_addr);
194 VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
195 tf->feature,
196 tf->nsect,
197 tf->lbal,
198 tf->lbam,
199 tf->lbah);
200 }
201
202 if (tf->flags & ATA_TFLAG_DEVICE) {
203 writeb(tf->device, (void __iomem *) ioaddr->device_addr);
204 VPRINTK("device 0x%X\n", tf->device);
205 }
206
207 ata_wait_idle(ap);
208}
209
210
211/**
212 * ata_tf_load - send taskfile registers to host controller
213 * @ap: Port to which output is sent
214 * @tf: ATA taskfile register set
215 *
216 * Outputs ATA taskfile to standard ATA host controller using MMIO
217 * or PIO as indicated by the ATA_FLAG_MMIO flag.
218 * Writes the control, feature, nsect, lbal, lbam, and lbah registers.
219 * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,
220 * hob_lbal, hob_lbam, and hob_lbah.
221 *
222 * This function waits for idle (!BUSY and !DRQ) after writing
223 * registers. If the control register has a new value, this
224 * function also waits for idle after writing control and before
225 * writing the remaining registers.
226 *
227 * May be used as the tf_load() entry in ata_port_operations.
228 *
229 * LOCKING:
230 * Inherited from caller.
231 */
232void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
233{
234 if (ap->flags & ATA_FLAG_MMIO)
235 ata_tf_load_mmio(ap, tf);
236 else
237 ata_tf_load_pio(ap, tf);
238}
239
240/**
241 * ata_exec_command_pio - issue ATA command to host controller
242 * @ap: port to which command is being issued
243 * @tf: ATA taskfile register set
244 *
245 * Issues PIO write to ATA command register, with proper
246 * synchronization with interrupt handler / other threads.
247 *
248 * LOCKING:
249 * spin_lock_irqsave(host_set lock)
250 */
251
252static void ata_exec_command_pio(struct ata_port *ap, const struct ata_taskfile *tf)
253{
254 DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command);
255
256 outb(tf->command, ap->ioaddr.command_addr);
257 ata_pause(ap);
258}
259
260
261/**
262 * ata_exec_command_mmio - issue ATA command to host controller
263 * @ap: port to which command is being issued
264 * @tf: ATA taskfile register set
265 *
266 * Issues MMIO write to ATA command register, with proper
267 * synchronization with interrupt handler / other threads.
268 *
269 * LOCKING:
270 * spin_lock_irqsave(host_set lock)
271 */
272
273static void ata_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
274{
275 DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command);
276
277 writeb(tf->command, (void __iomem *) ap->ioaddr.command_addr);
278 ata_pause(ap);
279}
280
281
282/**
283 * ata_exec_command - issue ATA command to host controller
284 * @ap: port to which command is being issued
285 * @tf: ATA taskfile register set
286 *
287 * Issues PIO/MMIO write to ATA command register, with proper
288 * synchronization with interrupt handler / other threads.
289 *
290 * LOCKING:
291 * spin_lock_irqsave(host_set lock)
292 */
293void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf)
294{
295 if (ap->flags & ATA_FLAG_MMIO)
296 ata_exec_command_mmio(ap, tf);
297 else
298 ata_exec_command_pio(ap, tf);
299}
300
301/**
302 * ata_tf_to_host - issue ATA taskfile to host controller
303 * @ap: port to which command is being issued
304 * @tf: ATA taskfile register set
305 *
306 * Issues ATA taskfile register set to ATA host controller,
307 * with proper synchronization with interrupt handler and
308 * other threads.
309 *
310 * LOCKING:
311 * spin_lock_irqsave(host_set lock)
312 */
313
314static inline void ata_tf_to_host(struct ata_port *ap,
315 const struct ata_taskfile *tf)
316{
317 ap->ops->tf_load(ap, tf);
318 ap->ops->exec_command(ap, tf);
319}
320
321/**
322 * ata_tf_read_pio - input device's ATA taskfile shadow registers
323 * @ap: Port from which input is read
324 * @tf: ATA taskfile register set for storing input
325 *
326 * Reads ATA taskfile registers for currently-selected device
327 * into @tf.
328 *
329 * LOCKING:
330 * Inherited from caller.
331 */
332
333static void ata_tf_read_pio(struct ata_port *ap, struct ata_taskfile *tf)
334{
335 struct ata_ioports *ioaddr = &ap->ioaddr;
336
337 tf->command = ata_check_status(ap);
338 tf->feature = inb(ioaddr->error_addr);
339 tf->nsect = inb(ioaddr->nsect_addr);
340 tf->lbal = inb(ioaddr->lbal_addr);
341 tf->lbam = inb(ioaddr->lbam_addr);
342 tf->lbah = inb(ioaddr->lbah_addr);
343 tf->device = inb(ioaddr->device_addr);
344
345 if (tf->flags & ATA_TFLAG_LBA48) {
346 outb(tf->ctl | ATA_HOB, ioaddr->ctl_addr);
347 tf->hob_feature = inb(ioaddr->error_addr);
348 tf->hob_nsect = inb(ioaddr->nsect_addr);
349 tf->hob_lbal = inb(ioaddr->lbal_addr);
350 tf->hob_lbam = inb(ioaddr->lbam_addr);
351 tf->hob_lbah = inb(ioaddr->lbah_addr);
352 }
353}
354
355/**
356 * ata_tf_read_mmio - input device's ATA taskfile shadow registers
357 * @ap: Port from which input is read
358 * @tf: ATA taskfile register set for storing input
359 *
360 * Reads ATA taskfile registers for currently-selected device
361 * into @tf via MMIO.
362 *
363 * LOCKING:
364 * Inherited from caller.
365 */
366
367static void ata_tf_read_mmio(struct ata_port *ap, struct ata_taskfile *tf)
368{
369 struct ata_ioports *ioaddr = &ap->ioaddr;
370
371 tf->command = ata_check_status(ap);
372 tf->feature = readb((void __iomem *)ioaddr->error_addr);
373 tf->nsect = readb((void __iomem *)ioaddr->nsect_addr);
374 tf->lbal = readb((void __iomem *)ioaddr->lbal_addr);
375 tf->lbam = readb((void __iomem *)ioaddr->lbam_addr);
376 tf->lbah = readb((void __iomem *)ioaddr->lbah_addr);
377 tf->device = readb((void __iomem *)ioaddr->device_addr);
378
379 if (tf->flags & ATA_TFLAG_LBA48) {
380 writeb(tf->ctl | ATA_HOB, (void __iomem *) ap->ioaddr.ctl_addr);
381 tf->hob_feature = readb((void __iomem *)ioaddr->error_addr);
382 tf->hob_nsect = readb((void __iomem *)ioaddr->nsect_addr);
383 tf->hob_lbal = readb((void __iomem *)ioaddr->lbal_addr);
384 tf->hob_lbam = readb((void __iomem *)ioaddr->lbam_addr);
385 tf->hob_lbah = readb((void __iomem *)ioaddr->lbah_addr);
386 }
387}
388
389
390/**
391 * ata_tf_read - input device's ATA taskfile shadow registers
392 * @ap: Port from which input is read
393 * @tf: ATA taskfile register set for storing input
394 *
395 * Reads ATA taskfile registers for currently-selected device
396 * into @tf.
397 *
398 * Reads nsect, lbal, lbam, lbah, and device. If ATA_TFLAG_LBA48
399 * is set, also reads the hob registers.
400 *
401 * May be used as the tf_read() entry in ata_port_operations.
402 *
403 * LOCKING:
404 * Inherited from caller.
405 */
406void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
407{
408 if (ap->flags & ATA_FLAG_MMIO)
409 ata_tf_read_mmio(ap, tf);
410 else
411 ata_tf_read_pio(ap, tf);
412}
413
414/**
415 * ata_check_status_pio - Read device status reg & clear interrupt
416 * @ap: port where the device is
417 *
418 * Reads ATA taskfile status register for currently-selected device
419 * and return its value. This also clears pending interrupts
420 * from this device
421 *
422 * LOCKING:
423 * Inherited from caller.
424 */
425static u8 ata_check_status_pio(struct ata_port *ap)
426{
427 return inb(ap->ioaddr.status_addr);
428}
429
430/**
431 * ata_check_status_mmio - Read device status reg & clear interrupt
432 * @ap: port where the device is
433 *
434 * Reads ATA taskfile status register for currently-selected device
435 * via MMIO and return its value. This also clears pending interrupts
436 * from this device
437 *
438 * LOCKING:
439 * Inherited from caller.
440 */
441static u8 ata_check_status_mmio(struct ata_port *ap)
442{
443 return readb((void __iomem *) ap->ioaddr.status_addr);
444}
445
446
447/**
448 * ata_check_status - Read device status reg & clear interrupt
449 * @ap: port where the device is
450 *
451 * Reads ATA taskfile status register for currently-selected device
452 * and return its value. This also clears pending interrupts
453 * from this device
454 *
455 * May be used as the check_status() entry in ata_port_operations.
456 *
457 * LOCKING:
458 * Inherited from caller.
459 */
460u8 ata_check_status(struct ata_port *ap)
461{
462 if (ap->flags & ATA_FLAG_MMIO)
463 return ata_check_status_mmio(ap);
464 return ata_check_status_pio(ap);
465}
466
467
468/**
469 * ata_altstatus - Read device alternate status reg
470 * @ap: port where the device is
471 *
472 * Reads ATA taskfile alternate status register for
473 * currently-selected device and return its value.
474 *
475 * Note: may NOT be used as the check_altstatus() entry in
476 * ata_port_operations.
477 *
478 * LOCKING:
479 * Inherited from caller.
480 */
481u8 ata_altstatus(struct ata_port *ap)
482{
483 if (ap->ops->check_altstatus)
484 return ap->ops->check_altstatus(ap);
485
486 if (ap->flags & ATA_FLAG_MMIO)
487 return readb((void __iomem *)ap->ioaddr.altstatus_addr);
488 return inb(ap->ioaddr.altstatus_addr);
489}
490
491 87
492/** 88/**
493 * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure 89 * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure
@@ -632,58 +228,148 @@ int ata_rwcmd_protocol(struct ata_queued_cmd *qc)
632 return -1; 228 return -1;
633} 229}
634 230
635static const char * const xfer_mode_str[] = { 231/**
636 "UDMA/16", 232 * ata_pack_xfermask - Pack pio, mwdma and udma masks into xfer_mask
637 "UDMA/25", 233 * @pio_mask: pio_mask
638 "UDMA/33", 234 * @mwdma_mask: mwdma_mask
639 "UDMA/44", 235 * @udma_mask: udma_mask
640 "UDMA/66", 236 *
641 "UDMA/100", 237 * Pack @pio_mask, @mwdma_mask and @udma_mask into a single
642 "UDMA/133", 238 * unsigned int xfer_mask.
643 "UDMA7", 239 *
644 "MWDMA0", 240 * LOCKING:
645 "MWDMA1", 241 * None.
646 "MWDMA2", 242 *
647 "PIO0", 243 * RETURNS:
648 "PIO1", 244 * Packed xfer_mask.
649 "PIO2", 245 */
650 "PIO3", 246static unsigned int ata_pack_xfermask(unsigned int pio_mask,
651 "PIO4", 247 unsigned int mwdma_mask,
248 unsigned int udma_mask)
249{
250 return ((pio_mask << ATA_SHIFT_PIO) & ATA_MASK_PIO) |
251 ((mwdma_mask << ATA_SHIFT_MWDMA) & ATA_MASK_MWDMA) |
252 ((udma_mask << ATA_SHIFT_UDMA) & ATA_MASK_UDMA);
253}
254
255static const struct ata_xfer_ent {
256 unsigned int shift, bits;
257 u8 base;
258} ata_xfer_tbl[] = {
259 { ATA_SHIFT_PIO, ATA_BITS_PIO, XFER_PIO_0 },
260 { ATA_SHIFT_MWDMA, ATA_BITS_MWDMA, XFER_MW_DMA_0 },
261 { ATA_SHIFT_UDMA, ATA_BITS_UDMA, XFER_UDMA_0 },
262 { -1, },
652}; 263};
653 264
654/** 265/**
655 * ata_udma_string - convert UDMA bit offset to string 266 * ata_xfer_mask2mode - Find matching XFER_* for the given xfer_mask
656 * @mask: mask of bits supported; only highest bit counts. 267 * @xfer_mask: xfer_mask of interest
657 * 268 *
658 * Determine string which represents the highest speed 269 * Return matching XFER_* value for @xfer_mask. Only the highest
659 * (highest bit in @udma_mask). 270 * bit of @xfer_mask is considered.
660 * 271 *
661 * LOCKING: 272 * LOCKING:
662 * None. 273 * None.
663 * 274 *
664 * RETURNS: 275 * RETURNS:
665 * Constant C string representing highest speed listed in 276 * Matching XFER_* value, 0 if no match found.
666 * @udma_mask, or the constant C string "<n/a>".
667 */ 277 */
278static u8 ata_xfer_mask2mode(unsigned int xfer_mask)
279{
280 int highbit = fls(xfer_mask) - 1;
281 const struct ata_xfer_ent *ent;
668 282
669static const char *ata_mode_string(unsigned int mask) 283 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++)
284 if (highbit >= ent->shift && highbit < ent->shift + ent->bits)
285 return ent->base + highbit - ent->shift;
286 return 0;
287}
288
289/**
290 * ata_xfer_mode2mask - Find matching xfer_mask for XFER_*
291 * @xfer_mode: XFER_* of interest
292 *
293 * Return matching xfer_mask for @xfer_mode.
294 *
295 * LOCKING:
296 * None.
297 *
298 * RETURNS:
299 * Matching xfer_mask, 0 if no match found.
300 */
301static unsigned int ata_xfer_mode2mask(u8 xfer_mode)
670{ 302{
671 int i; 303 const struct ata_xfer_ent *ent;
672 304
673 for (i = 7; i >= 0; i--) 305 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++)
674 if (mask & (1 << i)) 306 if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits)
675 goto out; 307 return 1 << (ent->shift + xfer_mode - ent->base);
676 for (i = ATA_SHIFT_MWDMA + 2; i >= ATA_SHIFT_MWDMA; i--) 308 return 0;
677 if (mask & (1 << i)) 309}
678 goto out;
679 for (i = ATA_SHIFT_PIO + 4; i >= ATA_SHIFT_PIO; i--)
680 if (mask & (1 << i))
681 goto out;
682 310
683 return "<n/a>"; 311/**
312 * ata_xfer_mode2shift - Find matching xfer_shift for XFER_*
313 * @xfer_mode: XFER_* of interest
314 *
315 * Return matching xfer_shift for @xfer_mode.
316 *
317 * LOCKING:
318 * None.
319 *
320 * RETURNS:
321 * Matching xfer_shift, -1 if no match found.
322 */
323static int ata_xfer_mode2shift(unsigned int xfer_mode)
324{
325 const struct ata_xfer_ent *ent;
684 326
685out: 327 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++)
686 return xfer_mode_str[i]; 328 if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits)
329 return ent->shift;
330 return -1;
331}
332
333/**
334 * ata_mode_string - convert xfer_mask to string
335 * @xfer_mask: mask of bits supported; only highest bit counts.
336 *
337 * Determine string which represents the highest speed
338 * (highest bit in @modemask).
339 *
340 * LOCKING:
341 * None.
342 *
343 * RETURNS:
344 * Constant C string representing highest speed listed in
345 * @mode_mask, or the constant C string "<n/a>".
346 */
347static const char *ata_mode_string(unsigned int xfer_mask)
348{
349 static const char * const xfer_mode_str[] = {
350 "PIO0",
351 "PIO1",
352 "PIO2",
353 "PIO3",
354 "PIO4",
355 "MWDMA0",
356 "MWDMA1",
357 "MWDMA2",
358 "UDMA/16",
359 "UDMA/25",
360 "UDMA/33",
361 "UDMA/44",
362 "UDMA/66",
363 "UDMA/100",
364 "UDMA/133",
365 "UDMA7",
366 };
367 int highbit;
368
369 highbit = fls(xfer_mask) - 1;
370 if (highbit >= 0 && highbit < ARRAY_SIZE(xfer_mode_str))
371 return xfer_mode_str[highbit];
372 return "<n/a>";
687} 373}
688 374
689/** 375/**
@@ -838,6 +524,7 @@ unsigned int ata_dev_classify(const struct ata_taskfile *tf)
838 * ata_dev_try_classify - Parse returned ATA device signature 524 * ata_dev_try_classify - Parse returned ATA device signature
839 * @ap: ATA channel to examine 525 * @ap: ATA channel to examine
840 * @device: Device to examine (starting at zero) 526 * @device: Device to examine (starting at zero)
527 * @r_err: Value of error register on completion
841 * 528 *
842 * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs, 529 * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs,
843 * an ATA/ATAPI-defined set of values is placed in the ATA 530 * an ATA/ATAPI-defined set of values is placed in the ATA
@@ -850,11 +537,14 @@ unsigned int ata_dev_classify(const struct ata_taskfile *tf)
850 * 537 *
851 * LOCKING: 538 * LOCKING:
852 * caller. 539 * caller.
540 *
541 * RETURNS:
542 * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE.
853 */ 543 */
854 544
855static u8 ata_dev_try_classify(struct ata_port *ap, unsigned int device) 545static unsigned int
546ata_dev_try_classify(struct ata_port *ap, unsigned int device, u8 *r_err)
856{ 547{
857 struct ata_device *dev = &ap->device[device];
858 struct ata_taskfile tf; 548 struct ata_taskfile tf;
859 unsigned int class; 549 unsigned int class;
860 u8 err; 550 u8 err;
@@ -865,8 +555,8 @@ static u8 ata_dev_try_classify(struct ata_port *ap, unsigned int device)
865 555
866 ap->ops->tf_read(ap, &tf); 556 ap->ops->tf_read(ap, &tf);
867 err = tf.feature; 557 err = tf.feature;
868 558 if (r_err)
869 dev->class = ATA_DEV_NONE; 559 *r_err = err;
870 560
871 /* see if device passed diags */ 561 /* see if device passed diags */
872 if (err == 1) 562 if (err == 1)
@@ -874,22 +564,20 @@ static u8 ata_dev_try_classify(struct ata_port *ap, unsigned int device)
874 else if ((device == 0) && (err == 0x81)) 564 else if ((device == 0) && (err == 0x81))
875 /* do nothing */ ; 565 /* do nothing */ ;
876 else 566 else
877 return err; 567 return ATA_DEV_NONE;
878 568
879 /* determine if device if ATA or ATAPI */ 569 /* determine if device is ATA or ATAPI */
880 class = ata_dev_classify(&tf); 570 class = ata_dev_classify(&tf);
571
881 if (class == ATA_DEV_UNKNOWN) 572 if (class == ATA_DEV_UNKNOWN)
882 return err; 573 return ATA_DEV_NONE;
883 if ((class == ATA_DEV_ATA) && (ata_chk_status(ap) == 0)) 574 if ((class == ATA_DEV_ATA) && (ata_chk_status(ap) == 0))
884 return err; 575 return ATA_DEV_NONE;
885 576 return class;
886 dev->class = class;
887
888 return err;
889} 577}
890 578
891/** 579/**
892 * ata_dev_id_string - Convert IDENTIFY DEVICE page into string 580 * ata_id_string - Convert IDENTIFY DEVICE page into string
893 * @id: IDENTIFY DEVICE results we will examine 581 * @id: IDENTIFY DEVICE results we will examine
894 * @s: string into which data is output 582 * @s: string into which data is output
895 * @ofs: offset into identify device page 583 * @ofs: offset into identify device page
@@ -903,8 +591,8 @@ static u8 ata_dev_try_classify(struct ata_port *ap, unsigned int device)
903 * caller. 591 * caller.
904 */ 592 */
905 593
906void ata_dev_id_string(const u16 *id, unsigned char *s, 594void ata_id_string(const u16 *id, unsigned char *s,
907 unsigned int ofs, unsigned int len) 595 unsigned int ofs, unsigned int len)
908{ 596{
909 unsigned int c; 597 unsigned int c;
910 598
@@ -922,6 +610,49 @@ void ata_dev_id_string(const u16 *id, unsigned char *s,
922 } 610 }
923} 611}
924 612
613/**
614 * ata_id_c_string - Convert IDENTIFY DEVICE page into C string
615 * @id: IDENTIFY DEVICE results we will examine
616 * @s: string into which data is output
617 * @ofs: offset into identify device page
618 * @len: length of string to return. must be an odd number.
619 *
620 * This function is identical to ata_id_string except that it
621 * trims trailing spaces and terminates the resulting string with
622 * null. @len must be actual maximum length (even number) + 1.
623 *
624 * LOCKING:
625 * caller.
626 */
627void ata_id_c_string(const u16 *id, unsigned char *s,
628 unsigned int ofs, unsigned int len)
629{
630 unsigned char *p;
631
632 WARN_ON(!(len & 1));
633
634 ata_id_string(id, s, ofs, len - 1);
635
636 p = s + strnlen(s, len - 1);
637 while (p > s && p[-1] == ' ')
638 p--;
639 *p = '\0';
640}
641
642static u64 ata_id_n_sectors(const u16 *id)
643{
644 if (ata_id_has_lba(id)) {
645 if (ata_id_has_lba48(id))
646 return ata_id_u64(id, 100);
647 else
648 return ata_id_u32(id, 60);
649 } else {
650 if (ata_id_current_chs_valid(id))
651 return ata_id_u32(id, 57);
652 else
653 return id[1] * id[3] * id[6];
654 }
655}
925 656
926/** 657/**
927 * ata_noop_dev_select - Select device 0/1 on ATA bus 658 * ata_noop_dev_select - Select device 0/1 on ATA bus
@@ -1011,90 +742,172 @@ void ata_dev_select(struct ata_port *ap, unsigned int device,
1011 742
1012/** 743/**
1013 * ata_dump_id - IDENTIFY DEVICE info debugging output 744 * ata_dump_id - IDENTIFY DEVICE info debugging output
1014 * @dev: Device whose IDENTIFY DEVICE page we will dump 745 * @id: IDENTIFY DEVICE page to dump
1015 * 746 *
1016 * Dump selected 16-bit words from a detected device's 747 * Dump selected 16-bit words from the given IDENTIFY DEVICE
1017 * IDENTIFY PAGE page. 748 * page.
1018 * 749 *
1019 * LOCKING: 750 * LOCKING:
1020 * caller. 751 * caller.
1021 */ 752 */
1022 753
1023static inline void ata_dump_id(const struct ata_device *dev) 754static inline void ata_dump_id(const u16 *id)
1024{ 755{
1025 DPRINTK("49==0x%04x " 756 DPRINTK("49==0x%04x "
1026 "53==0x%04x " 757 "53==0x%04x "
1027 "63==0x%04x " 758 "63==0x%04x "
1028 "64==0x%04x " 759 "64==0x%04x "
1029 "75==0x%04x \n", 760 "75==0x%04x \n",
1030 dev->id[49], 761 id[49],
1031 dev->id[53], 762 id[53],
1032 dev->id[63], 763 id[63],
1033 dev->id[64], 764 id[64],
1034 dev->id[75]); 765 id[75]);
1035 DPRINTK("80==0x%04x " 766 DPRINTK("80==0x%04x "
1036 "81==0x%04x " 767 "81==0x%04x "
1037 "82==0x%04x " 768 "82==0x%04x "
1038 "83==0x%04x " 769 "83==0x%04x "
1039 "84==0x%04x \n", 770 "84==0x%04x \n",
1040 dev->id[80], 771 id[80],
1041 dev->id[81], 772 id[81],
1042 dev->id[82], 773 id[82],
1043 dev->id[83], 774 id[83],
1044 dev->id[84]); 775 id[84]);
1045 DPRINTK("88==0x%04x " 776 DPRINTK("88==0x%04x "
1046 "93==0x%04x\n", 777 "93==0x%04x\n",
1047 dev->id[88], 778 id[88],
1048 dev->id[93]); 779 id[93]);
1049} 780}
1050 781
1051/* 782/**
1052 * Compute the PIO modes available for this device. This is not as 783 * ata_id_xfermask - Compute xfermask from the given IDENTIFY data
1053 * trivial as it seems if we must consider early devices correctly. 784 * @id: IDENTIFY data to compute xfer mask from
785 *
786 * Compute the xfermask for this device. This is not as trivial
787 * as it seems if we must consider early devices correctly.
788 *
789 * FIXME: pre IDE drive timing (do we care ?).
790 *
791 * LOCKING:
792 * None.
1054 * 793 *
1055 * FIXME: pre IDE drive timing (do we care ?). 794 * RETURNS:
795 * Computed xfermask
1056 */ 796 */
1057 797static unsigned int ata_id_xfermask(const u16 *id)
1058static unsigned int ata_pio_modes(const struct ata_device *adev)
1059{ 798{
1060 u16 modes; 799 unsigned int pio_mask, mwdma_mask, udma_mask;
1061 800
1062 /* Usual case. Word 53 indicates word 64 is valid */ 801 /* Usual case. Word 53 indicates word 64 is valid */
1063 if (adev->id[ATA_ID_FIELD_VALID] & (1 << 1)) { 802 if (id[ATA_ID_FIELD_VALID] & (1 << 1)) {
1064 modes = adev->id[ATA_ID_PIO_MODES] & 0x03; 803 pio_mask = id[ATA_ID_PIO_MODES] & 0x03;
1065 modes <<= 3; 804 pio_mask <<= 3;
1066 modes |= 0x7; 805 pio_mask |= 0x7;
1067 return modes; 806 } else {
807 /* If word 64 isn't valid then Word 51 high byte holds
808 * the PIO timing number for the maximum. Turn it into
809 * a mask.
810 */
811 pio_mask = (2 << (id[ATA_ID_OLD_PIO_MODES] & 0xFF)) - 1 ;
812
813 /* But wait.. there's more. Design your standards by
814 * committee and you too can get a free iordy field to
815 * process. However its the speeds not the modes that
816 * are supported... Note drivers using the timing API
817 * will get this right anyway
818 */
1068 } 819 }
1069 820
1070 /* If word 64 isn't valid then Word 51 high byte holds the PIO timing 821 mwdma_mask = id[ATA_ID_MWDMA_MODES] & 0x07;
1071 number for the maximum. Turn it into a mask and return it */ 822
1072 modes = (2 << ((adev->id[ATA_ID_OLD_PIO_MODES] >> 8) & 0xFF)) - 1 ; 823 udma_mask = 0;
1073 return modes; 824 if (id[ATA_ID_FIELD_VALID] & (1 << 2))
1074 /* But wait.. there's more. Design your standards by committee and 825 udma_mask = id[ATA_ID_UDMA_MODES] & 0xff;
1075 you too can get a free iordy field to process. However its the 826
1076 speeds not the modes that are supported... Note drivers using the 827 return ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask);
1077 timing API will get this right anyway */
1078} 828}
1079 829
1080struct ata_exec_internal_arg { 830/**
1081 unsigned int err_mask; 831 * ata_port_queue_task - Queue port_task
1082 struct ata_taskfile *tf; 832 * @ap: The ata_port to queue port_task for
1083 struct completion *waiting; 833 *
1084}; 834 * Schedule @fn(@data) for execution after @delay jiffies using
835 * port_task. There is one port_task per port and it's the
836 * user(low level driver)'s responsibility to make sure that only
837 * one task is active at any given time.
838 *
839 * libata core layer takes care of synchronization between
840 * port_task and EH. ata_port_queue_task() may be ignored for EH
841 * synchronization.
842 *
843 * LOCKING:
844 * Inherited from caller.
845 */
846void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *), void *data,
847 unsigned long delay)
848{
849 int rc;
850
851 if (ap->flags & ATA_FLAG_FLUSH_PORT_TASK)
852 return;
853
854 PREPARE_WORK(&ap->port_task, fn, data);
855
856 if (!delay)
857 rc = queue_work(ata_wq, &ap->port_task);
858 else
859 rc = queue_delayed_work(ata_wq, &ap->port_task, delay);
860
861 /* rc == 0 means that another user is using port task */
862 WARN_ON(rc == 0);
863}
1085 864
1086int ata_qc_complete_internal(struct ata_queued_cmd *qc) 865/**
866 * ata_port_flush_task - Flush port_task
867 * @ap: The ata_port to flush port_task for
868 *
869 * After this function completes, port_task is guranteed not to
870 * be running or scheduled.
871 *
872 * LOCKING:
873 * Kernel thread context (may sleep)
874 */
875void ata_port_flush_task(struct ata_port *ap)
1087{ 876{
1088 struct ata_exec_internal_arg *arg = qc->private_data; 877 unsigned long flags;
1089 struct completion *waiting = arg->waiting;
1090 878
1091 if (!(qc->err_mask & ~AC_ERR_DEV)) 879 DPRINTK("ENTER\n");
1092 qc->ap->ops->tf_read(qc->ap, arg->tf);
1093 arg->err_mask = qc->err_mask;
1094 arg->waiting = NULL;
1095 complete(waiting);
1096 880
1097 return 0; 881 spin_lock_irqsave(&ap->host_set->lock, flags);
882 ap->flags |= ATA_FLAG_FLUSH_PORT_TASK;
883 spin_unlock_irqrestore(&ap->host_set->lock, flags);
884
885 DPRINTK("flush #1\n");
886 flush_workqueue(ata_wq);
887
888 /*
889 * At this point, if a task is running, it's guaranteed to see
890 * the FLUSH flag; thus, it will never queue pio tasks again.
891 * Cancel and flush.
892 */
893 if (!cancel_delayed_work(&ap->port_task)) {
894 DPRINTK("flush #2\n");
895 flush_workqueue(ata_wq);
896 }
897
898 spin_lock_irqsave(&ap->host_set->lock, flags);
899 ap->flags &= ~ATA_FLAG_FLUSH_PORT_TASK;
900 spin_unlock_irqrestore(&ap->host_set->lock, flags);
901
902 DPRINTK("EXIT\n");
903}
904
905void ata_qc_complete_internal(struct ata_queued_cmd *qc)
906{
907 struct completion *waiting = qc->private_data;
908
909 qc->ap->ops->tf_read(qc->ap, &qc->tf);
910 complete(waiting);
1098} 911}
1099 912
1100/** 913/**
@@ -1125,7 +938,7 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
1125 struct ata_queued_cmd *qc; 938 struct ata_queued_cmd *qc;
1126 DECLARE_COMPLETION(wait); 939 DECLARE_COMPLETION(wait);
1127 unsigned long flags; 940 unsigned long flags;
1128 struct ata_exec_internal_arg arg; 941 unsigned int err_mask;
1129 942
1130 spin_lock_irqsave(&ap->host_set->lock, flags); 943 spin_lock_irqsave(&ap->host_set->lock, flags);
1131 944
@@ -1139,13 +952,12 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
1139 qc->nsect = buflen / ATA_SECT_SIZE; 952 qc->nsect = buflen / ATA_SECT_SIZE;
1140 } 953 }
1141 954
1142 arg.waiting = &wait; 955 qc->private_data = &wait;
1143 arg.tf = tf;
1144 qc->private_data = &arg;
1145 qc->complete_fn = ata_qc_complete_internal; 956 qc->complete_fn = ata_qc_complete_internal;
1146 957
1147 if (ata_qc_issue(qc)) 958 qc->err_mask = ata_qc_issue(qc);
1148 goto issue_fail; 959 if (qc->err_mask)
960 ata_qc_complete(qc);
1149 961
1150 spin_unlock_irqrestore(&ap->host_set->lock, flags); 962 spin_unlock_irqrestore(&ap->host_set->lock, flags);
1151 963
@@ -1158,8 +970,8 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
1158 * before the caller cleans up, it will result in a 970 * before the caller cleans up, it will result in a
1159 * spurious interrupt. We can live with that. 971 * spurious interrupt. We can live with that.
1160 */ 972 */
1161 if (arg.waiting) { 973 if (qc->flags & ATA_QCFLAG_ACTIVE) {
1162 qc->err_mask = AC_ERR_OTHER; 974 qc->err_mask = AC_ERR_TIMEOUT;
1163 ata_qc_complete(qc); 975 ata_qc_complete(qc);
1164 printk(KERN_WARNING "ata%u: qc timeout (cmd 0x%x)\n", 976 printk(KERN_WARNING "ata%u: qc timeout (cmd 0x%x)\n",
1165 ap->id, command); 977 ap->id, command);
@@ -1168,12 +980,12 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
1168 spin_unlock_irqrestore(&ap->host_set->lock, flags); 980 spin_unlock_irqrestore(&ap->host_set->lock, flags);
1169 } 981 }
1170 982
1171 return arg.err_mask; 983 *tf = qc->tf;
984 err_mask = qc->err_mask;
1172 985
1173 issue_fail:
1174 ata_qc_free(qc); 986 ata_qc_free(qc);
1175 spin_unlock_irqrestore(&ap->host_set->lock, flags); 987
1176 return AC_ERR_OTHER; 988 return err_mask;
1177} 989}
1178 990
1179/** 991/**
@@ -1210,73 +1022,78 @@ unsigned int ata_pio_need_iordy(const struct ata_device *adev)
1210} 1022}
1211 1023
1212/** 1024/**
1213 * ata_dev_identify - obtain IDENTIFY x DEVICE page 1025 * ata_dev_read_id - Read ID data from the specified device
1214 * @ap: port on which device we wish to probe resides 1026 * @ap: port on which target device resides
1215 * @device: device bus address, starting at zero 1027 * @dev: target device
1216 * 1028 * @p_class: pointer to class of the target device (may be changed)
1217 * Following bus reset, we issue the IDENTIFY [PACKET] DEVICE 1029 * @post_reset: is this read ID post-reset?
1218 * command, and read back the 512-byte device information page. 1030 * @p_id: read IDENTIFY page (newly allocated)
1219 * The device information page is fed to us via the standard 1031 *
1220 * PIO-IN protocol, but we hand-code it here. (TODO: investigate 1032 * Read ID data from the specified device. ATA_CMD_ID_ATA is
1221 * using standard PIO-IN paths) 1033 * performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI
1222 * 1034 * devices. This function also takes care of EDD signature
1223 * After reading the device information page, we use several 1035 * misreporting (to be removed once EDD support is gone) and
1224 * bits of information from it to initialize data structures 1036 * issues ATA_CMD_INIT_DEV_PARAMS for pre-ATA4 drives.
1225 * that will be used during the lifetime of the ata_device.
1226 * Other data from the info page is used to disqualify certain
1227 * older ATA devices we do not wish to support.
1228 * 1037 *
1229 * LOCKING: 1038 * LOCKING:
1230 * Inherited from caller. Some functions called by this function 1039 * Kernel thread context (may sleep)
1231 * obtain the host_set lock. 1040 *
1041 * RETURNS:
1042 * 0 on success, -errno otherwise.
1232 */ 1043 */
1233 1044static int ata_dev_read_id(struct ata_port *ap, struct ata_device *dev,
1234static void ata_dev_identify(struct ata_port *ap, unsigned int device) 1045 unsigned int *p_class, int post_reset, u16 **p_id)
1235{ 1046{
1236 struct ata_device *dev = &ap->device[device]; 1047 unsigned int class = *p_class;
1237 unsigned int major_version;
1238 u16 tmp;
1239 unsigned long xfer_modes;
1240 unsigned int using_edd; 1048 unsigned int using_edd;
1241 struct ata_taskfile tf; 1049 struct ata_taskfile tf;
1242 unsigned int err_mask; 1050 unsigned int err_mask = 0;
1051 u16 *id;
1052 const char *reason;
1243 int rc; 1053 int rc;
1244 1054
1245 if (!ata_dev_present(dev)) { 1055 DPRINTK("ENTER, host %u, dev %u\n", ap->id, dev->devno);
1246 DPRINTK("ENTER/EXIT (host %u, dev %u) -- nodev\n",
1247 ap->id, device);
1248 return;
1249 }
1250 1056
1251 if (ap->flags & (ATA_FLAG_SRST | ATA_FLAG_SATA_RESET)) 1057 if (ap->ops->probe_reset ||
1058 ap->flags & (ATA_FLAG_SRST | ATA_FLAG_SATA_RESET))
1252 using_edd = 0; 1059 using_edd = 0;
1253 else 1060 else
1254 using_edd = 1; 1061 using_edd = 1;
1255 1062
1256 DPRINTK("ENTER, host %u, dev %u\n", ap->id, device); 1063 ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */
1257
1258 assert (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ATAPI ||
1259 dev->class == ATA_DEV_NONE);
1260 1064
1261 ata_dev_select(ap, device, 1, 1); /* select device 0/1 */ 1065 id = kmalloc(sizeof(id[0]) * ATA_ID_WORDS, GFP_KERNEL);
1066 if (id == NULL) {
1067 rc = -ENOMEM;
1068 reason = "out of memory";
1069 goto err_out;
1070 }
1262 1071
1263retry: 1072 retry:
1264 ata_tf_init(ap, &tf, device); 1073 ata_tf_init(ap, &tf, dev->devno);
1265 1074
1266 if (dev->class == ATA_DEV_ATA) { 1075 switch (class) {
1076 case ATA_DEV_ATA:
1267 tf.command = ATA_CMD_ID_ATA; 1077 tf.command = ATA_CMD_ID_ATA;
1268 DPRINTK("do ATA identify\n"); 1078 break;
1269 } else { 1079 case ATA_DEV_ATAPI:
1270 tf.command = ATA_CMD_ID_ATAPI; 1080 tf.command = ATA_CMD_ID_ATAPI;
1271 DPRINTK("do ATAPI identify\n"); 1081 break;
1082 default:
1083 rc = -ENODEV;
1084 reason = "unsupported class";
1085 goto err_out;
1272 } 1086 }
1273 1087
1274 tf.protocol = ATA_PROT_PIO; 1088 tf.protocol = ATA_PROT_PIO;
1275 1089
1276 err_mask = ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE, 1090 err_mask = ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE,
1277 dev->id, sizeof(dev->id)); 1091 id, sizeof(id[0]) * ATA_ID_WORDS);
1278 1092
1279 if (err_mask) { 1093 if (err_mask) {
1094 rc = -EIO;
1095 reason = "I/O error";
1096
1280 if (err_mask & ~AC_ERR_DEV) 1097 if (err_mask & ~AC_ERR_DEV)
1281 goto err_out; 1098 goto err_out;
1282 1099
@@ -1291,180 +1108,223 @@ retry:
1291 * ATA software reset (SRST, the default) does not appear 1108 * ATA software reset (SRST, the default) does not appear
1292 * to have this problem. 1109 * to have this problem.
1293 */ 1110 */
1294 if ((using_edd) && (dev->class == ATA_DEV_ATA)) { 1111 if ((using_edd) && (class == ATA_DEV_ATA)) {
1295 u8 err = tf.feature; 1112 u8 err = tf.feature;
1296 if (err & ATA_ABORTED) { 1113 if (err & ATA_ABORTED) {
1297 dev->class = ATA_DEV_ATAPI; 1114 class = ATA_DEV_ATAPI;
1298 goto retry; 1115 goto retry;
1299 } 1116 }
1300 } 1117 }
1301 goto err_out; 1118 goto err_out;
1302 } 1119 }
1303 1120
1304 swap_buf_le16(dev->id, ATA_ID_WORDS); 1121 swap_buf_le16(id, ATA_ID_WORDS);
1122
1123 /* sanity check */
1124 if ((class == ATA_DEV_ATA) != ata_id_is_ata(id)) {
1125 rc = -EINVAL;
1126 reason = "device reports illegal type";
1127 goto err_out;
1128 }
1129
1130 if (post_reset && class == ATA_DEV_ATA) {
1131 /*
1132 * The exact sequence expected by certain pre-ATA4 drives is:
1133 * SRST RESET
1134 * IDENTIFY
1135 * INITIALIZE DEVICE PARAMETERS
1136 * anything else..
1137 * Some drives were very specific about that exact sequence.
1138 */
1139 if (ata_id_major_version(id) < 4 || !ata_id_has_lba(id)) {
1140 err_mask = ata_dev_init_params(ap, dev);
1141 if (err_mask) {
1142 rc = -EIO;
1143 reason = "INIT_DEV_PARAMS failed";
1144 goto err_out;
1145 }
1146
1147 /* current CHS translation info (id[53-58]) might be
1148 * changed. reread the identify device info.
1149 */
1150 post_reset = 0;
1151 goto retry;
1152 }
1153 }
1154
1155 *p_class = class;
1156 *p_id = id;
1157 return 0;
1158
1159 err_out:
1160 printk(KERN_WARNING "ata%u: dev %u failed to IDENTIFY (%s)\n",
1161 ap->id, dev->devno, reason);
1162 kfree(id);
1163 return rc;
1164}
1165
1166static inline u8 ata_dev_knobble(const struct ata_port *ap,
1167 struct ata_device *dev)
1168{
1169 return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id)));
1170}
1171
1172/**
1173 * ata_dev_configure - Configure the specified ATA/ATAPI device
1174 * @ap: Port on which target device resides
1175 * @dev: Target device to configure
1176 * @print_info: Enable device info printout
1177 *
1178 * Configure @dev according to @dev->id. Generic and low-level
1179 * driver specific fixups are also applied.
1180 *
1181 * LOCKING:
1182 * Kernel thread context (may sleep)
1183 *
1184 * RETURNS:
1185 * 0 on success, -errno otherwise
1186 */
1187static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev,
1188 int print_info)
1189{
1190 const u16 *id = dev->id;
1191 unsigned int xfer_mask;
1192 int i, rc;
1193
1194 if (!ata_dev_present(dev)) {
1195 DPRINTK("ENTER/EXIT (host %u, dev %u) -- nodev\n",
1196 ap->id, dev->devno);
1197 return 0;
1198 }
1199
1200 DPRINTK("ENTER, host %u, dev %u\n", ap->id, dev->devno);
1305 1201
1306 /* print device capabilities */ 1202 /* print device capabilities */
1307 printk(KERN_DEBUG "ata%u: dev %u cfg " 1203 if (print_info)
1308 "49:%04x 82:%04x 83:%04x 84:%04x 85:%04x 86:%04x 87:%04x 88:%04x\n", 1204 printk(KERN_DEBUG "ata%u: dev %u cfg 49:%04x 82:%04x 83:%04x "
1309 ap->id, device, dev->id[49], 1205 "84:%04x 85:%04x 86:%04x 87:%04x 88:%04x\n",
1310 dev->id[82], dev->id[83], dev->id[84], 1206 ap->id, dev->devno, id[49], id[82], id[83],
1311 dev->id[85], dev->id[86], dev->id[87], 1207 id[84], id[85], id[86], id[87], id[88]);
1312 dev->id[88]); 1208
1209 /* initialize to-be-configured parameters */
1210 dev->flags = 0;
1211 dev->max_sectors = 0;
1212 dev->cdb_len = 0;
1213 dev->n_sectors = 0;
1214 dev->cylinders = 0;
1215 dev->heads = 0;
1216 dev->sectors = 0;
1313 1217
1314 /* 1218 /*
1315 * common ATA, ATAPI feature tests 1219 * common ATA, ATAPI feature tests
1316 */ 1220 */
1317 1221
1318 /* we require DMA support (bits 8 of word 49) */ 1222 /* we require DMA support (bits 8 of word 49) */
1319 if (!ata_id_has_dma(dev->id)) { 1223 if (!ata_id_has_dma(id)) {
1320 printk(KERN_DEBUG "ata%u: no dma\n", ap->id); 1224 printk(KERN_DEBUG "ata%u: no dma\n", ap->id);
1225 rc = -EINVAL;
1321 goto err_out_nosup; 1226 goto err_out_nosup;
1322 } 1227 }
1323 1228
1324 /* quick-n-dirty find max transfer mode; for printk only */ 1229 /* find max transfer mode; for printk only */
1325 xfer_modes = dev->id[ATA_ID_UDMA_MODES]; 1230 xfer_mask = ata_id_xfermask(id);
1326 if (!xfer_modes)
1327 xfer_modes = (dev->id[ATA_ID_MWDMA_MODES]) << ATA_SHIFT_MWDMA;
1328 if (!xfer_modes)
1329 xfer_modes = ata_pio_modes(dev);
1330 1231
1331 ata_dump_id(dev); 1232 ata_dump_id(id);
1332 1233
1333 /* ATA-specific feature tests */ 1234 /* ATA-specific feature tests */
1334 if (dev->class == ATA_DEV_ATA) { 1235 if (dev->class == ATA_DEV_ATA) {
1335 if (!ata_id_is_ata(dev->id)) /* sanity check */ 1236 dev->n_sectors = ata_id_n_sectors(id);
1336 goto err_out_nosup;
1337 1237
1338 /* get major version */ 1238 if (ata_id_has_lba(id)) {
1339 tmp = dev->id[ATA_ID_MAJOR_VER]; 1239 const char *lba_desc;
1340 for (major_version = 14; major_version >= 1; major_version--)
1341 if (tmp & (1 << major_version))
1342 break;
1343 1240
1344 /* 1241 lba_desc = "LBA";
1345 * The exact sequence expected by certain pre-ATA4 drives is:
1346 * SRST RESET
1347 * IDENTIFY
1348 * INITIALIZE DEVICE PARAMETERS
1349 * anything else..
1350 * Some drives were very specific about that exact sequence.
1351 */
1352 if (major_version < 4 || (!ata_id_has_lba(dev->id))) {
1353 ata_dev_init_params(ap, dev);
1354
1355 /* current CHS translation info (id[53-58]) might be
1356 * changed. reread the identify device info.
1357 */
1358 ata_dev_reread_id(ap, dev);
1359 }
1360
1361 if (ata_id_has_lba(dev->id)) {
1362 dev->flags |= ATA_DFLAG_LBA; 1242 dev->flags |= ATA_DFLAG_LBA;
1363 1243 if (ata_id_has_lba48(id)) {
1364 if (ata_id_has_lba48(dev->id)) {
1365 dev->flags |= ATA_DFLAG_LBA48; 1244 dev->flags |= ATA_DFLAG_LBA48;
1366 dev->n_sectors = ata_id_u64(dev->id, 100); 1245 lba_desc = "LBA48";
1367 } else {
1368 dev->n_sectors = ata_id_u32(dev->id, 60);
1369 } 1246 }
1370 1247
1371 /* print device info to dmesg */ 1248 /* print device info to dmesg */
1372 printk(KERN_INFO "ata%u: dev %u ATA-%d, max %s, %Lu sectors:%s\n", 1249 if (print_info)
1373 ap->id, device, 1250 printk(KERN_INFO "ata%u: dev %u ATA-%d, "
1374 major_version, 1251 "max %s, %Lu sectors: %s\n",
1375 ata_mode_string(xfer_modes), 1252 ap->id, dev->devno,
1376 (unsigned long long)dev->n_sectors, 1253 ata_id_major_version(id),
1377 dev->flags & ATA_DFLAG_LBA48 ? " LBA48" : " LBA"); 1254 ata_mode_string(xfer_mask),
1378 } else { 1255 (unsigned long long)dev->n_sectors,
1256 lba_desc);
1257 } else {
1379 /* CHS */ 1258 /* CHS */
1380 1259
1381 /* Default translation */ 1260 /* Default translation */
1382 dev->cylinders = dev->id[1]; 1261 dev->cylinders = id[1];
1383 dev->heads = dev->id[3]; 1262 dev->heads = id[3];
1384 dev->sectors = dev->id[6]; 1263 dev->sectors = id[6];
1385 dev->n_sectors = dev->cylinders * dev->heads * dev->sectors;
1386 1264
1387 if (ata_id_current_chs_valid(dev->id)) { 1265 if (ata_id_current_chs_valid(id)) {
1388 /* Current CHS translation is valid. */ 1266 /* Current CHS translation is valid. */
1389 dev->cylinders = dev->id[54]; 1267 dev->cylinders = id[54];
1390 dev->heads = dev->id[55]; 1268 dev->heads = id[55];
1391 dev->sectors = dev->id[56]; 1269 dev->sectors = id[56];
1392
1393 dev->n_sectors = ata_id_u32(dev->id, 57);
1394 } 1270 }
1395 1271
1396 /* print device info to dmesg */ 1272 /* print device info to dmesg */
1397 printk(KERN_INFO "ata%u: dev %u ATA-%d, max %s, %Lu sectors: CHS %d/%d/%d\n", 1273 if (print_info)
1398 ap->id, device, 1274 printk(KERN_INFO "ata%u: dev %u ATA-%d, "
1399 major_version, 1275 "max %s, %Lu sectors: CHS %u/%u/%u\n",
1400 ata_mode_string(xfer_modes), 1276 ap->id, dev->devno,
1401 (unsigned long long)dev->n_sectors, 1277 ata_id_major_version(id),
1402 (int)dev->cylinders, (int)dev->heads, (int)dev->sectors); 1278 ata_mode_string(xfer_mask),
1403 1279 (unsigned long long)dev->n_sectors,
1280 dev->cylinders, dev->heads, dev->sectors);
1404 } 1281 }
1405 1282
1406 ap->host->max_cmd_len = 16; 1283 dev->cdb_len = 16;
1407 } 1284 }
1408 1285
1409 /* ATAPI-specific feature tests */ 1286 /* ATAPI-specific feature tests */
1410 else if (dev->class == ATA_DEV_ATAPI) { 1287 else if (dev->class == ATA_DEV_ATAPI) {
1411 if (ata_id_is_ata(dev->id)) /* sanity check */ 1288 rc = atapi_cdb_len(id);
1412 goto err_out_nosup;
1413
1414 rc = atapi_cdb_len(dev->id);
1415 if ((rc < 12) || (rc > ATAPI_CDB_LEN)) { 1289 if ((rc < 12) || (rc > ATAPI_CDB_LEN)) {
1416 printk(KERN_WARNING "ata%u: unsupported CDB len\n", ap->id); 1290 printk(KERN_WARNING "ata%u: unsupported CDB len\n", ap->id);
1291 rc = -EINVAL;
1417 goto err_out_nosup; 1292 goto err_out_nosup;
1418 } 1293 }
1419 ap->cdb_len = (unsigned int) rc; 1294 dev->cdb_len = (unsigned int) rc;
1420 ap->host->max_cmd_len = (unsigned char) ap->cdb_len;
1421 1295
1422 /* print device info to dmesg */ 1296 /* print device info to dmesg */
1423 printk(KERN_INFO "ata%u: dev %u ATAPI, max %s\n", 1297 if (print_info)
1424 ap->id, device, 1298 printk(KERN_INFO "ata%u: dev %u ATAPI, max %s\n",
1425 ata_mode_string(xfer_modes)); 1299 ap->id, dev->devno, ata_mode_string(xfer_mask));
1426 } 1300 }
1427 1301
1428 DPRINTK("EXIT, drv_stat = 0x%x\n", ata_chk_status(ap)); 1302 ap->host->max_cmd_len = 0;
1429 return; 1303 for (i = 0; i < ATA_MAX_DEVICES; i++)
1430 1304 ap->host->max_cmd_len = max_t(unsigned int,
1431err_out_nosup: 1305 ap->host->max_cmd_len,
1432 printk(KERN_WARNING "ata%u: dev %u not supported, ignoring\n", 1306 ap->device[i].cdb_len);
1433 ap->id, device);
1434err_out:
1435 dev->class++; /* converts ATA_DEV_xxx into ATA_DEV_xxx_UNSUP */
1436 DPRINTK("EXIT, err\n");
1437}
1438
1439
1440static inline u8 ata_dev_knobble(const struct ata_port *ap)
1441{
1442 return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(ap->device->id)));
1443}
1444
1445/**
1446 * ata_dev_config - Run device specific handlers and check for
1447 * SATA->PATA bridges
1448 * @ap: Bus
1449 * @i: Device
1450 *
1451 * LOCKING:
1452 */
1453 1307
1454void ata_dev_config(struct ata_port *ap, unsigned int i)
1455{
1456 /* limit bridge transfers to udma5, 200 sectors */ 1308 /* limit bridge transfers to udma5, 200 sectors */
1457 if (ata_dev_knobble(ap)) { 1309 if (ata_dev_knobble(ap, dev)) {
1458 printk(KERN_INFO "ata%u(%u): applying bridge limits\n", 1310 if (print_info)
1459 ap->id, ap->device->devno); 1311 printk(KERN_INFO "ata%u(%u): applying bridge limits\n",
1312 ap->id, dev->devno);
1460 ap->udma_mask &= ATA_UDMA5; 1313 ap->udma_mask &= ATA_UDMA5;
1461 ap->host->max_sectors = ATA_MAX_SECTORS; 1314 dev->max_sectors = ATA_MAX_SECTORS;
1462 ap->host->hostt->max_sectors = ATA_MAX_SECTORS;
1463 ap->device[i].flags |= ATA_DFLAG_LOCK_SECTORS;
1464 } 1315 }
1465 1316
1466 if (ap->ops->dev_config) 1317 if (ap->ops->dev_config)
1467 ap->ops->dev_config(ap, &ap->device[i]); 1318 ap->ops->dev_config(ap, dev);
1319
1320 DPRINTK("EXIT, drv_stat = 0x%x\n", ata_chk_status(ap));
1321 return 0;
1322
1323err_out_nosup:
1324 printk(KERN_WARNING "ata%u: dev %u not supported, ignoring\n",
1325 ap->id, dev->devno);
1326 DPRINTK("EXIT, err\n");
1327 return rc;
1468} 1328}
1469 1329
1470/** 1330/**
@@ -1484,21 +1344,59 @@ void ata_dev_config(struct ata_port *ap, unsigned int i)
1484 1344
1485static int ata_bus_probe(struct ata_port *ap) 1345static int ata_bus_probe(struct ata_port *ap)
1486{ 1346{
1487 unsigned int i, found = 0; 1347 unsigned int classes[ATA_MAX_DEVICES];
1348 unsigned int i, rc, found = 0;
1488 1349
1489 ap->ops->phy_reset(ap); 1350 ata_port_probe(ap);
1490 if (ap->flags & ATA_FLAG_PORT_DISABLED) 1351
1491 goto err_out; 1352 /* reset and determine device classes */
1353 for (i = 0; i < ATA_MAX_DEVICES; i++)
1354 classes[i] = ATA_DEV_UNKNOWN;
1355
1356 if (ap->ops->probe_reset) {
1357 rc = ap->ops->probe_reset(ap, classes);
1358 if (rc) {
1359 printk("ata%u: reset failed (errno=%d)\n", ap->id, rc);
1360 return rc;
1361 }
1362 } else {
1363 ap->ops->phy_reset(ap);
1364
1365 if (!(ap->flags & ATA_FLAG_PORT_DISABLED))
1366 for (i = 0; i < ATA_MAX_DEVICES; i++)
1367 classes[i] = ap->device[i].class;
1368
1369 ata_port_probe(ap);
1370 }
1492 1371
1372 for (i = 0; i < ATA_MAX_DEVICES; i++)
1373 if (classes[i] == ATA_DEV_UNKNOWN)
1374 classes[i] = ATA_DEV_NONE;
1375
1376 /* read IDENTIFY page and configure devices */
1493 for (i = 0; i < ATA_MAX_DEVICES; i++) { 1377 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1494 ata_dev_identify(ap, i); 1378 struct ata_device *dev = &ap->device[i];
1495 if (ata_dev_present(&ap->device[i])) { 1379
1496 found = 1; 1380 dev->class = classes[i];
1497 ata_dev_config(ap,i); 1381
1382 if (!ata_dev_present(dev))
1383 continue;
1384
1385 WARN_ON(dev->id != NULL);
1386 if (ata_dev_read_id(ap, dev, &dev->class, 1, &dev->id)) {
1387 dev->class = ATA_DEV_NONE;
1388 continue;
1389 }
1390
1391 if (ata_dev_configure(ap, dev, 1)) {
1392 dev->class++; /* disable device */
1393 continue;
1498 } 1394 }
1395
1396 found = 1;
1499 } 1397 }
1500 1398
1501 if ((!found) || (ap->flags & ATA_FLAG_PORT_DISABLED)) 1399 if (!found)
1502 goto err_out_disable; 1400 goto err_out_disable;
1503 1401
1504 ata_set_mode(ap); 1402 ata_set_mode(ap);
@@ -1509,7 +1407,6 @@ static int ata_bus_probe(struct ata_port *ap)
1509 1407
1510err_out_disable: 1408err_out_disable:
1511 ap->ops->port_disable(ap); 1409 ap->ops->port_disable(ap);
1512err_out:
1513 return -1; 1410 return -1;
1514} 1411}
1515 1412
@@ -1530,6 +1427,41 @@ void ata_port_probe(struct ata_port *ap)
1530} 1427}
1531 1428
1532/** 1429/**
1430 * sata_print_link_status - Print SATA link status
1431 * @ap: SATA port to printk link status about
1432 *
1433 * This function prints link speed and status of a SATA link.
1434 *
1435 * LOCKING:
1436 * None.
1437 */
1438static void sata_print_link_status(struct ata_port *ap)
1439{
1440 u32 sstatus, tmp;
1441 const char *speed;
1442
1443 if (!ap->ops->scr_read)
1444 return;
1445
1446 sstatus = scr_read(ap, SCR_STATUS);
1447
1448 if (sata_dev_present(ap)) {
1449 tmp = (sstatus >> 4) & 0xf;
1450 if (tmp & (1 << 0))
1451 speed = "1.5";
1452 else if (tmp & (1 << 1))
1453 speed = "3.0";
1454 else
1455 speed = "<unknown>";
1456 printk(KERN_INFO "ata%u: SATA link up %s Gbps (SStatus %X)\n",
1457 ap->id, speed, sstatus);
1458 } else {
1459 printk(KERN_INFO "ata%u: SATA link down (SStatus %X)\n",
1460 ap->id, sstatus);
1461 }
1462}
1463
1464/**
1533 * __sata_phy_reset - Wake/reset a low-level SATA PHY 1465 * __sata_phy_reset - Wake/reset a low-level SATA PHY
1534 * @ap: SATA port associated with target SATA PHY. 1466 * @ap: SATA port associated with target SATA PHY.
1535 * 1467 *
@@ -1563,27 +1495,14 @@ void __sata_phy_reset(struct ata_port *ap)
1563 break; 1495 break;
1564 } while (time_before(jiffies, timeout)); 1496 } while (time_before(jiffies, timeout));
1565 1497
1566 /* TODO: phy layer with polling, timeouts, etc. */ 1498 /* print link status */
1567 sstatus = scr_read(ap, SCR_STATUS); 1499 sata_print_link_status(ap);
1568 if (sata_dev_present(ap)) {
1569 const char *speed;
1570 u32 tmp;
1571 1500
1572 tmp = (sstatus >> 4) & 0xf; 1501 /* TODO: phy layer with polling, timeouts, etc. */
1573 if (tmp & (1 << 0)) 1502 if (sata_dev_present(ap))
1574 speed = "1.5";
1575 else if (tmp & (1 << 1))
1576 speed = "3.0";
1577 else
1578 speed = "<unknown>";
1579 printk(KERN_INFO "ata%u: SATA link up %s Gbps (SStatus %X)\n",
1580 ap->id, speed, sstatus);
1581 ata_port_probe(ap); 1503 ata_port_probe(ap);
1582 } else { 1504 else
1583 printk(KERN_INFO "ata%u: SATA link down (SStatus %X)\n",
1584 ap->id, sstatus);
1585 ata_port_disable(ap); 1505 ata_port_disable(ap);
1586 }
1587 1506
1588 if (ap->flags & ATA_FLAG_PORT_DISABLED) 1507 if (ap->flags & ATA_FLAG_PORT_DISABLED)
1589 return; 1508 return;
@@ -1756,9 +1675,9 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
1756 ata_timing_quantize(t, t, T, UT); 1675 ata_timing_quantize(t, t, T, UT);
1757 1676
1758 /* 1677 /*
1759 * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, S.M.A.R.T 1678 * Even in DMA/UDMA modes we still use PIO access for IDENTIFY,
1760 * and some other commands. We have to ensure that the DMA cycle timing is 1679 * S.M.A.R.T * and some other commands. We have to ensure that the
1761 * slower/equal than the fastest PIO timing. 1680 * DMA cycle timing is slower/equal than the fastest PIO timing.
1762 */ 1681 */
1763 1682
1764 if (speed > XFER_PIO_4) { 1683 if (speed > XFER_PIO_4) {
@@ -1767,7 +1686,7 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
1767 } 1686 }
1768 1687
1769 /* 1688 /*
1770 * Lenghten active & recovery time so that cycle time is correct. 1689 * Lengthen active & recovery time so that cycle time is correct.
1771 */ 1690 */
1772 1691
1773 if (t->act8b + t->rec8b < t->cyc8b) { 1692 if (t->act8b + t->rec8b < t->cyc8b) {
@@ -1783,31 +1702,8 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
1783 return 0; 1702 return 0;
1784} 1703}
1785 1704
1786static const struct {
1787 unsigned int shift;
1788 u8 base;
1789} xfer_mode_classes[] = {
1790 { ATA_SHIFT_UDMA, XFER_UDMA_0 },
1791 { ATA_SHIFT_MWDMA, XFER_MW_DMA_0 },
1792 { ATA_SHIFT_PIO, XFER_PIO_0 },
1793};
1794
1795static u8 base_from_shift(unsigned int shift)
1796{
1797 int i;
1798
1799 for (i = 0; i < ARRAY_SIZE(xfer_mode_classes); i++)
1800 if (xfer_mode_classes[i].shift == shift)
1801 return xfer_mode_classes[i].base;
1802
1803 return 0xff;
1804}
1805
1806static void ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev) 1705static void ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
1807{ 1706{
1808 int ofs, idx;
1809 u8 base;
1810
1811 if (!ata_dev_present(dev) || (ap->flags & ATA_FLAG_PORT_DISABLED)) 1707 if (!ata_dev_present(dev) || (ap->flags & ATA_FLAG_PORT_DISABLED))
1812 return; 1708 return;
1813 1709
@@ -1816,65 +1712,58 @@ static void ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
1816 1712
1817 ata_dev_set_xfermode(ap, dev); 1713 ata_dev_set_xfermode(ap, dev);
1818 1714
1819 base = base_from_shift(dev->xfer_shift); 1715 if (ata_dev_revalidate(ap, dev, 0)) {
1820 ofs = dev->xfer_mode - base; 1716 printk(KERN_ERR "ata%u: failed to revalidate after set "
1821 idx = ofs + dev->xfer_shift; 1717 "xfermode, disabled\n", ap->id);
1822 WARN_ON(idx >= ARRAY_SIZE(xfer_mode_str)); 1718 ata_port_disable(ap);
1719 }
1823 1720
1824 DPRINTK("idx=%d xfer_shift=%u, xfer_mode=0x%x, base=0x%x, offset=%d\n", 1721 DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n",
1825 idx, dev->xfer_shift, (int)dev->xfer_mode, (int)base, ofs); 1722 dev->xfer_shift, (int)dev->xfer_mode);
1826 1723
1827 printk(KERN_INFO "ata%u: dev %u configured for %s\n", 1724 printk(KERN_INFO "ata%u: dev %u configured for %s\n",
1828 ap->id, dev->devno, xfer_mode_str[idx]); 1725 ap->id, dev->devno,
1726 ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)));
1829} 1727}
1830 1728
1831static int ata_host_set_pio(struct ata_port *ap) 1729static int ata_host_set_pio(struct ata_port *ap)
1832{ 1730{
1833 unsigned int mask; 1731 int i;
1834 int x, i;
1835 u8 base, xfer_mode;
1836
1837 mask = ata_get_mode_mask(ap, ATA_SHIFT_PIO);
1838 x = fgb(mask);
1839 if (x < 0) {
1840 printk(KERN_WARNING "ata%u: no PIO support\n", ap->id);
1841 return -1;
1842 }
1843
1844 base = base_from_shift(ATA_SHIFT_PIO);
1845 xfer_mode = base + x;
1846
1847 DPRINTK("base 0x%x xfer_mode 0x%x mask 0x%x x %d\n",
1848 (int)base, (int)xfer_mode, mask, x);
1849 1732
1850 for (i = 0; i < ATA_MAX_DEVICES; i++) { 1733 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1851 struct ata_device *dev = &ap->device[i]; 1734 struct ata_device *dev = &ap->device[i];
1852 if (ata_dev_present(dev)) { 1735
1853 dev->pio_mode = xfer_mode; 1736 if (!ata_dev_present(dev))
1854 dev->xfer_mode = xfer_mode; 1737 continue;
1855 dev->xfer_shift = ATA_SHIFT_PIO; 1738
1856 if (ap->ops->set_piomode) 1739 if (!dev->pio_mode) {
1857 ap->ops->set_piomode(ap, dev); 1740 printk(KERN_WARNING "ata%u: no PIO support\n", ap->id);
1741 return -1;
1858 } 1742 }
1743
1744 dev->xfer_mode = dev->pio_mode;
1745 dev->xfer_shift = ATA_SHIFT_PIO;
1746 if (ap->ops->set_piomode)
1747 ap->ops->set_piomode(ap, dev);
1859 } 1748 }
1860 1749
1861 return 0; 1750 return 0;
1862} 1751}
1863 1752
1864static void ata_host_set_dma(struct ata_port *ap, u8 xfer_mode, 1753static void ata_host_set_dma(struct ata_port *ap)
1865 unsigned int xfer_shift)
1866{ 1754{
1867 int i; 1755 int i;
1868 1756
1869 for (i = 0; i < ATA_MAX_DEVICES; i++) { 1757 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1870 struct ata_device *dev = &ap->device[i]; 1758 struct ata_device *dev = &ap->device[i];
1871 if (ata_dev_present(dev)) { 1759
1872 dev->dma_mode = xfer_mode; 1760 if (!ata_dev_present(dev) || !dev->dma_mode)
1873 dev->xfer_mode = xfer_mode; 1761 continue;
1874 dev->xfer_shift = xfer_shift; 1762
1875 if (ap->ops->set_dmamode) 1763 dev->xfer_mode = dev->dma_mode;
1876 ap->ops->set_dmamode(ap, dev); 1764 dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode);
1877 } 1765 if (ap->ops->set_dmamode)
1766 ap->ops->set_dmamode(ap, dev);
1878 } 1767 }
1879} 1768}
1880 1769
@@ -1886,32 +1775,37 @@ static void ata_host_set_dma(struct ata_port *ap, u8 xfer_mode,
1886 * 1775 *
1887 * LOCKING: 1776 * LOCKING:
1888 * PCI/etc. bus probe sem. 1777 * PCI/etc. bus probe sem.
1889 *
1890 */ 1778 */
1891static void ata_set_mode(struct ata_port *ap) 1779static void ata_set_mode(struct ata_port *ap)
1892{ 1780{
1893 unsigned int xfer_shift; 1781 int i, rc;
1894 u8 xfer_mode;
1895 int rc;
1896 1782
1897 /* step 1: always set host PIO timings */ 1783 /* step 1: calculate xfer_mask */
1898 rc = ata_host_set_pio(ap); 1784 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1899 if (rc) 1785 struct ata_device *dev = &ap->device[i];
1900 goto err_out; 1786 unsigned int xfer_mask;
1901 1787
1902 /* step 2: choose the best data xfer mode */ 1788 if (!ata_dev_present(dev))
1903 xfer_mode = xfer_shift = 0; 1789 continue;
1904 rc = ata_choose_xfer_mode(ap, &xfer_mode, &xfer_shift); 1790
1791 xfer_mask = ata_dev_xfermask(ap, dev);
1792
1793 dev->pio_mode = ata_xfer_mask2mode(xfer_mask & ATA_MASK_PIO);
1794 dev->dma_mode = ata_xfer_mask2mode(xfer_mask & (ATA_MASK_MWDMA |
1795 ATA_MASK_UDMA));
1796 }
1797
1798 /* step 2: always set host PIO timings */
1799 rc = ata_host_set_pio(ap);
1905 if (rc) 1800 if (rc)
1906 goto err_out; 1801 goto err_out;
1907 1802
1908 /* step 3: if that xfer mode isn't PIO, set host DMA timings */ 1803 /* step 3: set host DMA timings */
1909 if (xfer_shift != ATA_SHIFT_PIO) 1804 ata_host_set_dma(ap);
1910 ata_host_set_dma(ap, xfer_mode, xfer_shift);
1911 1805
1912 /* step 4: update devices' xfer mode */ 1806 /* step 4: update devices' xfer mode */
1913 ata_dev_set_mode(ap, &ap->device[0]); 1807 for (i = 0; i < ATA_MAX_DEVICES; i++)
1914 ata_dev_set_mode(ap, &ap->device[1]); 1808 ata_dev_set_mode(ap, &ap->device[i]);
1915 1809
1916 if (ap->flags & ATA_FLAG_PORT_DISABLED) 1810 if (ap->flags & ATA_FLAG_PORT_DISABLED)
1917 return; 1811 return;
@@ -1926,6 +1820,26 @@ err_out:
1926} 1820}
1927 1821
1928/** 1822/**
1823 * ata_tf_to_host - issue ATA taskfile to host controller
1824 * @ap: port to which command is being issued
1825 * @tf: ATA taskfile register set
1826 *
1827 * Issues ATA taskfile register set to ATA host controller,
1828 * with proper synchronization with interrupt handler and
1829 * other threads.
1830 *
1831 * LOCKING:
1832 * spin_lock_irqsave(host_set lock)
1833 */
1834
1835static inline void ata_tf_to_host(struct ata_port *ap,
1836 const struct ata_taskfile *tf)
1837{
1838 ap->ops->tf_load(ap, tf);
1839 ap->ops->exec_command(ap, tf);
1840}
1841
1842/**
1929 * ata_busy_sleep - sleep until BSY clears, or timeout 1843 * ata_busy_sleep - sleep until BSY clears, or timeout
1930 * @ap: port containing status register to be polled 1844 * @ap: port containing status register to be polled
1931 * @tmout_pat: impatience timeout 1845 * @tmout_pat: impatience timeout
@@ -1935,12 +1849,10 @@ err_out:
1935 * or a timeout occurs. 1849 * or a timeout occurs.
1936 * 1850 *
1937 * LOCKING: None. 1851 * LOCKING: None.
1938 *
1939 */ 1852 */
1940 1853
1941static unsigned int ata_busy_sleep (struct ata_port *ap, 1854unsigned int ata_busy_sleep (struct ata_port *ap,
1942 unsigned long tmout_pat, 1855 unsigned long tmout_pat, unsigned long tmout)
1943 unsigned long tmout)
1944{ 1856{
1945 unsigned long timer_start, timeout; 1857 unsigned long timer_start, timeout;
1946 u8 status; 1858 u8 status;
@@ -2159,9 +2071,9 @@ void ata_bus_reset(struct ata_port *ap)
2159 /* 2071 /*
2160 * determine by signature whether we have ATA or ATAPI devices 2072 * determine by signature whether we have ATA or ATAPI devices
2161 */ 2073 */
2162 err = ata_dev_try_classify(ap, 0); 2074 ap->device[0].class = ata_dev_try_classify(ap, 0, &err);
2163 if ((slave_possible) && (err != 0x81)) 2075 if ((slave_possible) && (err != 0x81))
2164 ata_dev_try_classify(ap, 1); 2076 ap->device[1].class = ata_dev_try_classify(ap, 1, &err);
2165 2077
2166 /* re-enable interrupts */ 2078 /* re-enable interrupts */
2167 if (ap->ioaddr.ctl_addr) /* FIXME: hack. create a hook instead */ 2079 if (ap->ioaddr.ctl_addr) /* FIXME: hack. create a hook instead */
@@ -2196,11 +2108,446 @@ err_out:
2196 DPRINTK("EXIT\n"); 2108 DPRINTK("EXIT\n");
2197} 2109}
2198 2110
2199static void ata_pr_blacklisted(const struct ata_port *ap, 2111static int sata_phy_resume(struct ata_port *ap)
2200 const struct ata_device *dev)
2201{ 2112{
2202 printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, disabling DMA\n", 2113 unsigned long timeout = jiffies + (HZ * 5);
2203 ap->id, dev->devno); 2114 u32 sstatus;
2115
2116 scr_write_flush(ap, SCR_CONTROL, 0x300);
2117
2118 /* Wait for phy to become ready, if necessary. */
2119 do {
2120 msleep(200);
2121 sstatus = scr_read(ap, SCR_STATUS);
2122 if ((sstatus & 0xf) != 1)
2123 return 0;
2124 } while (time_before(jiffies, timeout));
2125
2126 return -1;
2127}
2128
2129/**
2130 * ata_std_probeinit - initialize probing
2131 * @ap: port to be probed
2132 *
2133 * @ap is about to be probed. Initialize it. This function is
2134 * to be used as standard callback for ata_drive_probe_reset().
2135 *
2136 * NOTE!!! Do not use this function as probeinit if a low level
2137 * driver implements only hardreset. Just pass NULL as probeinit
2138 * in that case. Using this function is probably okay but doing
2139 * so makes reset sequence different from the original
2140 * ->phy_reset implementation and Jeff nervous. :-P
2141 */
2142extern void ata_std_probeinit(struct ata_port *ap)
2143{
2144 if (ap->flags & ATA_FLAG_SATA && ap->ops->scr_read) {
2145 sata_phy_resume(ap);
2146 if (sata_dev_present(ap))
2147 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
2148 }
2149}
2150
2151/**
2152 * ata_std_softreset - reset host port via ATA SRST
2153 * @ap: port to reset
2154 * @verbose: fail verbosely
2155 * @classes: resulting classes of attached devices
2156 *
2157 * Reset host port using ATA SRST. This function is to be used
2158 * as standard callback for ata_drive_*_reset() functions.
2159 *
2160 * LOCKING:
2161 * Kernel thread context (may sleep)
2162 *
2163 * RETURNS:
2164 * 0 on success, -errno otherwise.
2165 */
2166int ata_std_softreset(struct ata_port *ap, int verbose, unsigned int *classes)
2167{
2168 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
2169 unsigned int devmask = 0, err_mask;
2170 u8 err;
2171
2172 DPRINTK("ENTER\n");
2173
2174 if (ap->ops->scr_read && !sata_dev_present(ap)) {
2175 classes[0] = ATA_DEV_NONE;
2176 goto out;
2177 }
2178
2179 /* determine if device 0/1 are present */
2180 if (ata_devchk(ap, 0))
2181 devmask |= (1 << 0);
2182 if (slave_possible && ata_devchk(ap, 1))
2183 devmask |= (1 << 1);
2184
2185 /* select device 0 again */
2186 ap->ops->dev_select(ap, 0);
2187
2188 /* issue bus reset */
2189 DPRINTK("about to softreset, devmask=%x\n", devmask);
2190 err_mask = ata_bus_softreset(ap, devmask);
2191 if (err_mask) {
2192 if (verbose)
2193 printk(KERN_ERR "ata%u: SRST failed (err_mask=0x%x)\n",
2194 ap->id, err_mask);
2195 else
2196 DPRINTK("EXIT, softreset failed (err_mask=0x%x)\n",
2197 err_mask);
2198 return -EIO;
2199 }
2200
2201 /* determine by signature whether we have ATA or ATAPI devices */
2202 classes[0] = ata_dev_try_classify(ap, 0, &err);
2203 if (slave_possible && err != 0x81)
2204 classes[1] = ata_dev_try_classify(ap, 1, &err);
2205
2206 out:
2207 DPRINTK("EXIT, classes[0]=%u [1]=%u\n", classes[0], classes[1]);
2208 return 0;
2209}
2210
2211/**
2212 * sata_std_hardreset - reset host port via SATA phy reset
2213 * @ap: port to reset
2214 * @verbose: fail verbosely
2215 * @class: resulting class of attached device
2216 *
2217 * SATA phy-reset host port using DET bits of SControl register.
2218 * This function is to be used as standard callback for
2219 * ata_drive_*_reset().
2220 *
2221 * LOCKING:
2222 * Kernel thread context (may sleep)
2223 *
2224 * RETURNS:
2225 * 0 on success, -errno otherwise.
2226 */
2227int sata_std_hardreset(struct ata_port *ap, int verbose, unsigned int *class)
2228{
2229 DPRINTK("ENTER\n");
2230
2231 /* Issue phy wake/reset */
2232 scr_write_flush(ap, SCR_CONTROL, 0x301);
2233
2234 /*
2235 * Couldn't find anything in SATA I/II specs, but AHCI-1.1
2236 * 10.4.2 says at least 1 ms.
2237 */
2238 msleep(1);
2239
2240 /* Bring phy back */
2241 sata_phy_resume(ap);
2242
2243 /* TODO: phy layer with polling, timeouts, etc. */
2244 if (!sata_dev_present(ap)) {
2245 *class = ATA_DEV_NONE;
2246 DPRINTK("EXIT, link offline\n");
2247 return 0;
2248 }
2249
2250 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) {
2251 if (verbose)
2252 printk(KERN_ERR "ata%u: COMRESET failed "
2253 "(device not ready)\n", ap->id);
2254 else
2255 DPRINTK("EXIT, device not ready\n");
2256 return -EIO;
2257 }
2258
2259 ap->ops->dev_select(ap, 0); /* probably unnecessary */
2260
2261 *class = ata_dev_try_classify(ap, 0, NULL);
2262
2263 DPRINTK("EXIT, class=%u\n", *class);
2264 return 0;
2265}
2266
2267/**
2268 * ata_std_postreset - standard postreset callback
2269 * @ap: the target ata_port
2270 * @classes: classes of attached devices
2271 *
2272 * This function is invoked after a successful reset. Note that
2273 * the device might have been reset more than once using
2274 * different reset methods before postreset is invoked.
2275 *
2276 * This function is to be used as standard callback for
2277 * ata_drive_*_reset().
2278 *
2279 * LOCKING:
2280 * Kernel thread context (may sleep)
2281 */
2282void ata_std_postreset(struct ata_port *ap, unsigned int *classes)
2283{
2284 DPRINTK("ENTER\n");
2285
2286 /* set cable type if it isn't already set */
2287 if (ap->cbl == ATA_CBL_NONE && ap->flags & ATA_FLAG_SATA)
2288 ap->cbl = ATA_CBL_SATA;
2289
2290 /* print link status */
2291 if (ap->cbl == ATA_CBL_SATA)
2292 sata_print_link_status(ap);
2293
2294 /* re-enable interrupts */
2295 if (ap->ioaddr.ctl_addr) /* FIXME: hack. create a hook instead */
2296 ata_irq_on(ap);
2297
2298 /* is double-select really necessary? */
2299 if (classes[0] != ATA_DEV_NONE)
2300 ap->ops->dev_select(ap, 1);
2301 if (classes[1] != ATA_DEV_NONE)
2302 ap->ops->dev_select(ap, 0);
2303
2304 /* bail out if no device is present */
2305 if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) {
2306 DPRINTK("EXIT, no device\n");
2307 return;
2308 }
2309
2310 /* set up device control */
2311 if (ap->ioaddr.ctl_addr) {
2312 if (ap->flags & ATA_FLAG_MMIO)
2313 writeb(ap->ctl, (void __iomem *) ap->ioaddr.ctl_addr);
2314 else
2315 outb(ap->ctl, ap->ioaddr.ctl_addr);
2316 }
2317
2318 DPRINTK("EXIT\n");
2319}
2320
2321/**
2322 * ata_std_probe_reset - standard probe reset method
2323 * @ap: prot to perform probe-reset
2324 * @classes: resulting classes of attached devices
2325 *
2326 * The stock off-the-shelf ->probe_reset method.
2327 *
2328 * LOCKING:
2329 * Kernel thread context (may sleep)
2330 *
2331 * RETURNS:
2332 * 0 on success, -errno otherwise.
2333 */
2334int ata_std_probe_reset(struct ata_port *ap, unsigned int *classes)
2335{
2336 ata_reset_fn_t hardreset;
2337
2338 hardreset = NULL;
2339 if (ap->flags & ATA_FLAG_SATA && ap->ops->scr_read)
2340 hardreset = sata_std_hardreset;
2341
2342 return ata_drive_probe_reset(ap, ata_std_probeinit,
2343 ata_std_softreset, hardreset,
2344 ata_std_postreset, classes);
2345}
2346
2347static int do_probe_reset(struct ata_port *ap, ata_reset_fn_t reset,
2348 ata_postreset_fn_t postreset,
2349 unsigned int *classes)
2350{
2351 int i, rc;
2352
2353 for (i = 0; i < ATA_MAX_DEVICES; i++)
2354 classes[i] = ATA_DEV_UNKNOWN;
2355
2356 rc = reset(ap, 0, classes);
2357 if (rc)
2358 return rc;
2359
2360 /* If any class isn't ATA_DEV_UNKNOWN, consider classification
2361 * is complete and convert all ATA_DEV_UNKNOWN to
2362 * ATA_DEV_NONE.
2363 */
2364 for (i = 0; i < ATA_MAX_DEVICES; i++)
2365 if (classes[i] != ATA_DEV_UNKNOWN)
2366 break;
2367
2368 if (i < ATA_MAX_DEVICES)
2369 for (i = 0; i < ATA_MAX_DEVICES; i++)
2370 if (classes[i] == ATA_DEV_UNKNOWN)
2371 classes[i] = ATA_DEV_NONE;
2372
2373 if (postreset)
2374 postreset(ap, classes);
2375
2376 return classes[0] != ATA_DEV_UNKNOWN ? 0 : -ENODEV;
2377}
2378
2379/**
2380 * ata_drive_probe_reset - Perform probe reset with given methods
2381 * @ap: port to reset
2382 * @probeinit: probeinit method (can be NULL)
2383 * @softreset: softreset method (can be NULL)
2384 * @hardreset: hardreset method (can be NULL)
2385 * @postreset: postreset method (can be NULL)
2386 * @classes: resulting classes of attached devices
2387 *
2388 * Reset the specified port and classify attached devices using
2389 * given methods. This function prefers softreset but tries all
2390 * possible reset sequences to reset and classify devices. This
2391 * function is intended to be used for constructing ->probe_reset
2392 * callback by low level drivers.
2393 *
2394 * Reset methods should follow the following rules.
2395 *
2396 * - Return 0 on sucess, -errno on failure.
2397 * - If classification is supported, fill classes[] with
2398 * recognized class codes.
2399 * - If classification is not supported, leave classes[] alone.
2400 * - If verbose is non-zero, print error message on failure;
2401 * otherwise, shut up.
2402 *
2403 * LOCKING:
2404 * Kernel thread context (may sleep)
2405 *
2406 * RETURNS:
2407 * 0 on success, -EINVAL if no reset method is avaliable, -ENODEV
2408 * if classification fails, and any error code from reset
2409 * methods.
2410 */
2411int ata_drive_probe_reset(struct ata_port *ap, ata_probeinit_fn_t probeinit,
2412 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
2413 ata_postreset_fn_t postreset, unsigned int *classes)
2414{
2415 int rc = -EINVAL;
2416
2417 if (probeinit)
2418 probeinit(ap);
2419
2420 if (softreset) {
2421 rc = do_probe_reset(ap, softreset, postreset, classes);
2422 if (rc == 0)
2423 return 0;
2424 }
2425
2426 if (!hardreset)
2427 return rc;
2428
2429 rc = do_probe_reset(ap, hardreset, postreset, classes);
2430 if (rc == 0 || rc != -ENODEV)
2431 return rc;
2432
2433 if (softreset)
2434 rc = do_probe_reset(ap, softreset, postreset, classes);
2435
2436 return rc;
2437}
2438
2439/**
2440 * ata_dev_same_device - Determine whether new ID matches configured device
2441 * @ap: port on which the device to compare against resides
2442 * @dev: device to compare against
2443 * @new_class: class of the new device
2444 * @new_id: IDENTIFY page of the new device
2445 *
2446 * Compare @new_class and @new_id against @dev and determine
2447 * whether @dev is the device indicated by @new_class and
2448 * @new_id.
2449 *
2450 * LOCKING:
2451 * None.
2452 *
2453 * RETURNS:
2454 * 1 if @dev matches @new_class and @new_id, 0 otherwise.
2455 */
2456static int ata_dev_same_device(struct ata_port *ap, struct ata_device *dev,
2457 unsigned int new_class, const u16 *new_id)
2458{
2459 const u16 *old_id = dev->id;
2460 unsigned char model[2][41], serial[2][21];
2461 u64 new_n_sectors;
2462
2463 if (dev->class != new_class) {
2464 printk(KERN_INFO
2465 "ata%u: dev %u class mismatch %d != %d\n",
2466 ap->id, dev->devno, dev->class, new_class);
2467 return 0;
2468 }
2469
2470 ata_id_c_string(old_id, model[0], ATA_ID_PROD_OFS, sizeof(model[0]));
2471 ata_id_c_string(new_id, model[1], ATA_ID_PROD_OFS, sizeof(model[1]));
2472 ata_id_c_string(old_id, serial[0], ATA_ID_SERNO_OFS, sizeof(serial[0]));
2473 ata_id_c_string(new_id, serial[1], ATA_ID_SERNO_OFS, sizeof(serial[1]));
2474 new_n_sectors = ata_id_n_sectors(new_id);
2475
2476 if (strcmp(model[0], model[1])) {
2477 printk(KERN_INFO
2478 "ata%u: dev %u model number mismatch '%s' != '%s'\n",
2479 ap->id, dev->devno, model[0], model[1]);
2480 return 0;
2481 }
2482
2483 if (strcmp(serial[0], serial[1])) {
2484 printk(KERN_INFO
2485 "ata%u: dev %u serial number mismatch '%s' != '%s'\n",
2486 ap->id, dev->devno, serial[0], serial[1]);
2487 return 0;
2488 }
2489
2490 if (dev->class == ATA_DEV_ATA && dev->n_sectors != new_n_sectors) {
2491 printk(KERN_INFO
2492 "ata%u: dev %u n_sectors mismatch %llu != %llu\n",
2493 ap->id, dev->devno, (unsigned long long)dev->n_sectors,
2494 (unsigned long long)new_n_sectors);
2495 return 0;
2496 }
2497
2498 return 1;
2499}
2500
2501/**
2502 * ata_dev_revalidate - Revalidate ATA device
2503 * @ap: port on which the device to revalidate resides
2504 * @dev: device to revalidate
2505 * @post_reset: is this revalidation after reset?
2506 *
2507 * Re-read IDENTIFY page and make sure @dev is still attached to
2508 * the port.
2509 *
2510 * LOCKING:
2511 * Kernel thread context (may sleep)
2512 *
2513 * RETURNS:
2514 * 0 on success, negative errno otherwise
2515 */
2516int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev,
2517 int post_reset)
2518{
2519 unsigned int class;
2520 u16 *id;
2521 int rc;
2522
2523 if (!ata_dev_present(dev))
2524 return -ENODEV;
2525
2526 class = dev->class;
2527 id = NULL;
2528
2529 /* allocate & read ID data */
2530 rc = ata_dev_read_id(ap, dev, &class, post_reset, &id);
2531 if (rc)
2532 goto fail;
2533
2534 /* is the device still there? */
2535 if (!ata_dev_same_device(ap, dev, class, id)) {
2536 rc = -ENODEV;
2537 goto fail;
2538 }
2539
2540 kfree(dev->id);
2541 dev->id = id;
2542
2543 /* configure device according to the new ID */
2544 return ata_dev_configure(ap, dev, 0);
2545
2546 fail:
2547 printk(KERN_ERR "ata%u: dev %u revalidation failed (errno=%d)\n",
2548 ap->id, dev->devno, rc);
2549 kfree(id);
2550 return rc;
2204} 2551}
2205 2552
2206static const char * const ata_dma_blacklist [] = { 2553static const char * const ata_dma_blacklist [] = {
@@ -2237,151 +2584,57 @@ static const char * const ata_dma_blacklist [] = {
2237 2584
2238static int ata_dma_blacklisted(const struct ata_device *dev) 2585static int ata_dma_blacklisted(const struct ata_device *dev)
2239{ 2586{
2240 unsigned char model_num[40]; 2587 unsigned char model_num[41];
2241 char *s;
2242 unsigned int len;
2243 int i; 2588 int i;
2244 2589
2245 ata_dev_id_string(dev->id, model_num, ATA_ID_PROD_OFS, 2590 ata_id_c_string(dev->id, model_num, ATA_ID_PROD_OFS, sizeof(model_num));
2246 sizeof(model_num));
2247 s = &model_num[0];
2248 len = strnlen(s, sizeof(model_num));
2249
2250 /* ATAPI specifies that empty space is blank-filled; remove blanks */
2251 while ((len > 0) && (s[len - 1] == ' ')) {
2252 len--;
2253 s[len] = 0;
2254 }
2255 2591
2256 for (i = 0; i < ARRAY_SIZE(ata_dma_blacklist); i++) 2592 for (i = 0; i < ARRAY_SIZE(ata_dma_blacklist); i++)
2257 if (!strncmp(ata_dma_blacklist[i], s, len)) 2593 if (!strcmp(ata_dma_blacklist[i], model_num))
2258 return 1; 2594 return 1;
2259 2595
2260 return 0; 2596 return 0;
2261} 2597}
2262 2598
2263static unsigned int ata_get_mode_mask(const struct ata_port *ap, int shift)
2264{
2265 const struct ata_device *master, *slave;
2266 unsigned int mask;
2267
2268 master = &ap->device[0];
2269 slave = &ap->device[1];
2270
2271 assert (ata_dev_present(master) || ata_dev_present(slave));
2272
2273 if (shift == ATA_SHIFT_UDMA) {
2274 mask = ap->udma_mask;
2275 if (ata_dev_present(master)) {
2276 mask &= (master->id[ATA_ID_UDMA_MODES] & 0xff);
2277 if (ata_dma_blacklisted(master)) {
2278 mask = 0;
2279 ata_pr_blacklisted(ap, master);
2280 }
2281 }
2282 if (ata_dev_present(slave)) {
2283 mask &= (slave->id[ATA_ID_UDMA_MODES] & 0xff);
2284 if (ata_dma_blacklisted(slave)) {
2285 mask = 0;
2286 ata_pr_blacklisted(ap, slave);
2287 }
2288 }
2289 }
2290 else if (shift == ATA_SHIFT_MWDMA) {
2291 mask = ap->mwdma_mask;
2292 if (ata_dev_present(master)) {
2293 mask &= (master->id[ATA_ID_MWDMA_MODES] & 0x07);
2294 if (ata_dma_blacklisted(master)) {
2295 mask = 0;
2296 ata_pr_blacklisted(ap, master);
2297 }
2298 }
2299 if (ata_dev_present(slave)) {
2300 mask &= (slave->id[ATA_ID_MWDMA_MODES] & 0x07);
2301 if (ata_dma_blacklisted(slave)) {
2302 mask = 0;
2303 ata_pr_blacklisted(ap, slave);
2304 }
2305 }
2306 }
2307 else if (shift == ATA_SHIFT_PIO) {
2308 mask = ap->pio_mask;
2309 if (ata_dev_present(master)) {
2310 /* spec doesn't return explicit support for
2311 * PIO0-2, so we fake it
2312 */
2313 u16 tmp_mode = master->id[ATA_ID_PIO_MODES] & 0x03;
2314 tmp_mode <<= 3;
2315 tmp_mode |= 0x7;
2316 mask &= tmp_mode;
2317 }
2318 if (ata_dev_present(slave)) {
2319 /* spec doesn't return explicit support for
2320 * PIO0-2, so we fake it
2321 */
2322 u16 tmp_mode = slave->id[ATA_ID_PIO_MODES] & 0x03;
2323 tmp_mode <<= 3;
2324 tmp_mode |= 0x7;
2325 mask &= tmp_mode;
2326 }
2327 }
2328 else {
2329 mask = 0xffffffff; /* shut up compiler warning */
2330 BUG();
2331 }
2332
2333 return mask;
2334}
2335
2336/* find greatest bit */
2337static int fgb(u32 bitmap)
2338{
2339 unsigned int i;
2340 int x = -1;
2341
2342 for (i = 0; i < 32; i++)
2343 if (bitmap & (1 << i))
2344 x = i;
2345
2346 return x;
2347}
2348
2349/** 2599/**
2350 * ata_choose_xfer_mode - attempt to find best transfer mode 2600 * ata_dev_xfermask - Compute supported xfermask of the given device
2351 * @ap: Port for which an xfer mode will be selected 2601 * @ap: Port on which the device to compute xfermask for resides
2352 * @xfer_mode_out: (output) SET FEATURES - XFER MODE code 2602 * @dev: Device to compute xfermask for
2353 * @xfer_shift_out: (output) bit shift that selects this mode
2354 * 2603 *
2355 * Based on host and device capabilities, determine the 2604 * Compute supported xfermask of @dev. This function is
2356 * maximum transfer mode that is amenable to all. 2605 * responsible for applying all known limits including host
2606 * controller limits, device blacklist, etc...
2357 * 2607 *
2358 * LOCKING: 2608 * LOCKING:
2359 * PCI/etc. bus probe sem. 2609 * None.
2360 * 2610 *
2361 * RETURNS: 2611 * RETURNS:
2362 * Zero on success, negative on error. 2612 * Computed xfermask.
2363 */ 2613 */
2364 2614static unsigned int ata_dev_xfermask(struct ata_port *ap,
2365static int ata_choose_xfer_mode(const struct ata_port *ap, 2615 struct ata_device *dev)
2366 u8 *xfer_mode_out,
2367 unsigned int *xfer_shift_out)
2368{ 2616{
2369 unsigned int mask, shift; 2617 unsigned long xfer_mask;
2370 int x, i; 2618 int i;
2371 2619
2372 for (i = 0; i < ARRAY_SIZE(xfer_mode_classes); i++) { 2620 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask,
2373 shift = xfer_mode_classes[i].shift; 2621 ap->udma_mask);
2374 mask = ata_get_mode_mask(ap, shift);
2375 2622
2376 x = fgb(mask); 2623 /* use port-wide xfermask for now */
2377 if (x >= 0) { 2624 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2378 *xfer_mode_out = xfer_mode_classes[i].base + x; 2625 struct ata_device *d = &ap->device[i];
2379 *xfer_shift_out = shift; 2626 if (!ata_dev_present(d))
2380 return 0; 2627 continue;
2381 } 2628 xfer_mask &= ata_id_xfermask(d->id);
2629 if (ata_dma_blacklisted(d))
2630 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
2382 } 2631 }
2383 2632
2384 return -1; 2633 if (ata_dma_blacklisted(dev))
2634 printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, "
2635 "disabling DMA\n", ap->id, dev->devno);
2636
2637 return xfer_mask;
2385} 2638}
2386 2639
2387/** 2640/**
@@ -2420,63 +2673,28 @@ static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev)
2420} 2673}
2421 2674
2422/** 2675/**
2423 * ata_dev_reread_id - Reread the device identify device info
2424 * @ap: port where the device is
2425 * @dev: device to reread the identify device info
2426 *
2427 * LOCKING:
2428 */
2429
2430static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev)
2431{
2432 struct ata_taskfile tf;
2433
2434 ata_tf_init(ap, &tf, dev->devno);
2435
2436 if (dev->class == ATA_DEV_ATA) {
2437 tf.command = ATA_CMD_ID_ATA;
2438 DPRINTK("do ATA identify\n");
2439 } else {
2440 tf.command = ATA_CMD_ID_ATAPI;
2441 DPRINTK("do ATAPI identify\n");
2442 }
2443
2444 tf.flags |= ATA_TFLAG_DEVICE;
2445 tf.protocol = ATA_PROT_PIO;
2446
2447 if (ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE,
2448 dev->id, sizeof(dev->id)))
2449 goto err_out;
2450
2451 swap_buf_le16(dev->id, ATA_ID_WORDS);
2452
2453 ata_dump_id(dev);
2454
2455 DPRINTK("EXIT\n");
2456
2457 return;
2458err_out:
2459 printk(KERN_ERR "ata%u: failed to reread ID, disabled\n", ap->id);
2460 ata_port_disable(ap);
2461}
2462
2463/**
2464 * ata_dev_init_params - Issue INIT DEV PARAMS command 2676 * ata_dev_init_params - Issue INIT DEV PARAMS command
2465 * @ap: Port associated with device @dev 2677 * @ap: Port associated with device @dev
2466 * @dev: Device to which command will be sent 2678 * @dev: Device to which command will be sent
2467 * 2679 *
2468 * LOCKING: 2680 * LOCKING:
2681 * Kernel thread context (may sleep)
2682 *
2683 * RETURNS:
2684 * 0 on success, AC_ERR_* mask otherwise.
2469 */ 2685 */
2470 2686
2471static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev) 2687static unsigned int ata_dev_init_params(struct ata_port *ap,
2688 struct ata_device *dev)
2472{ 2689{
2473 struct ata_taskfile tf; 2690 struct ata_taskfile tf;
2691 unsigned int err_mask;
2474 u16 sectors = dev->id[6]; 2692 u16 sectors = dev->id[6];
2475 u16 heads = dev->id[3]; 2693 u16 heads = dev->id[3];
2476 2694
2477 /* Number of sectors per track 1-255. Number of heads 1-16 */ 2695 /* Number of sectors per track 1-255. Number of heads 1-16 */
2478 if (sectors < 1 || sectors > 255 || heads < 1 || heads > 16) 2696 if (sectors < 1 || sectors > 255 || heads < 1 || heads > 16)
2479 return; 2697 return 0;
2480 2698
2481 /* set up init dev params taskfile */ 2699 /* set up init dev params taskfile */
2482 DPRINTK("init dev params \n"); 2700 DPRINTK("init dev params \n");
@@ -2488,13 +2706,10 @@ static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev)
2488 tf.nsect = sectors; 2706 tf.nsect = sectors;
2489 tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ 2707 tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */
2490 2708
2491 if (ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0)) { 2709 err_mask = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0);
2492 printk(KERN_ERR "ata%u: failed to init parameters, disabled\n",
2493 ap->id);
2494 ata_port_disable(ap);
2495 }
2496 2710
2497 DPRINTK("EXIT\n"); 2711 DPRINTK("EXIT, err_mask=%x\n", err_mask);
2712 return err_mask;
2498} 2713}
2499 2714
2500/** 2715/**
@@ -2514,11 +2729,11 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
2514 int dir = qc->dma_dir; 2729 int dir = qc->dma_dir;
2515 void *pad_buf = NULL; 2730 void *pad_buf = NULL;
2516 2731
2517 assert(qc->flags & ATA_QCFLAG_DMAMAP); 2732 WARN_ON(!(qc->flags & ATA_QCFLAG_DMAMAP));
2518 assert(sg != NULL); 2733 WARN_ON(sg == NULL);
2519 2734
2520 if (qc->flags & ATA_QCFLAG_SINGLE) 2735 if (qc->flags & ATA_QCFLAG_SINGLE)
2521 assert(qc->n_elem <= 1); 2736 WARN_ON(qc->n_elem > 1);
2522 2737
2523 VPRINTK("unmapping %u sg elements\n", qc->n_elem); 2738 VPRINTK("unmapping %u sg elements\n", qc->n_elem);
2524 2739
@@ -2573,8 +2788,8 @@ static void ata_fill_sg(struct ata_queued_cmd *qc)
2573 struct scatterlist *sg; 2788 struct scatterlist *sg;
2574 unsigned int idx; 2789 unsigned int idx;
2575 2790
2576 assert(qc->__sg != NULL); 2791 WARN_ON(qc->__sg == NULL);
2577 assert(qc->n_elem > 0 || qc->pad_len > 0); 2792 WARN_ON(qc->n_elem == 0 && qc->pad_len == 0);
2578 2793
2579 idx = 0; 2794 idx = 0;
2580 ata_for_each_sg(sg, qc) { 2795 ata_for_each_sg(sg, qc) {
@@ -2727,7 +2942,7 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
2727 void *pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ); 2942 void *pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ);
2728 struct scatterlist *psg = &qc->pad_sgent; 2943 struct scatterlist *psg = &qc->pad_sgent;
2729 2944
2730 assert(qc->dev->class == ATA_DEV_ATAPI); 2945 WARN_ON(qc->dev->class != ATA_DEV_ATAPI);
2731 2946
2732 memset(pad_buf, 0, ATA_DMA_PAD_SZ); 2947 memset(pad_buf, 0, ATA_DMA_PAD_SZ);
2733 2948
@@ -2791,7 +3006,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
2791 int n_elem, pre_n_elem, dir, trim_sg = 0; 3006 int n_elem, pre_n_elem, dir, trim_sg = 0;
2792 3007
2793 VPRINTK("ENTER, ata%u\n", ap->id); 3008 VPRINTK("ENTER, ata%u\n", ap->id);
2794 assert(qc->flags & ATA_QCFLAG_SG); 3009 WARN_ON(!(qc->flags & ATA_QCFLAG_SG));
2795 3010
2796 /* we must lengthen transfers to end on a 32-bit boundary */ 3011 /* we must lengthen transfers to end on a 32-bit boundary */
2797 qc->pad_len = lsg->length & 3; 3012 qc->pad_len = lsg->length & 3;
@@ -2800,7 +3015,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
2800 struct scatterlist *psg = &qc->pad_sgent; 3015 struct scatterlist *psg = &qc->pad_sgent;
2801 unsigned int offset; 3016 unsigned int offset;
2802 3017
2803 assert(qc->dev->class == ATA_DEV_ATAPI); 3018 WARN_ON(qc->dev->class != ATA_DEV_ATAPI);
2804 3019
2805 memset(pad_buf, 0, ATA_DMA_PAD_SZ); 3020 memset(pad_buf, 0, ATA_DMA_PAD_SZ);
2806 3021
@@ -2876,7 +3091,7 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc)
2876} 3091}
2877 3092
2878/** 3093/**
2879 * ata_pio_poll - 3094 * ata_pio_poll - poll using PIO, depending on current state
2880 * @ap: the target ata_port 3095 * @ap: the target ata_port
2881 * 3096 *
2882 * LOCKING: 3097 * LOCKING:
@@ -2894,7 +3109,7 @@ static unsigned long ata_pio_poll(struct ata_port *ap)
2894 unsigned int reg_state = HSM_ST_UNKNOWN; 3109 unsigned int reg_state = HSM_ST_UNKNOWN;
2895 3110
2896 qc = ata_qc_from_tag(ap, ap->active_tag); 3111 qc = ata_qc_from_tag(ap, ap->active_tag);
2897 assert(qc != NULL); 3112 WARN_ON(qc == NULL);
2898 3113
2899 switch (ap->hsm_task_state) { 3114 switch (ap->hsm_task_state) {
2900 case HSM_ST: 3115 case HSM_ST:
@@ -2915,7 +3130,7 @@ static unsigned long ata_pio_poll(struct ata_port *ap)
2915 status = ata_chk_status(ap); 3130 status = ata_chk_status(ap);
2916 if (status & ATA_BUSY) { 3131 if (status & ATA_BUSY) {
2917 if (time_after(jiffies, ap->pio_task_timeout)) { 3132 if (time_after(jiffies, ap->pio_task_timeout)) {
2918 qc->err_mask |= AC_ERR_ATA_BUS; 3133 qc->err_mask |= AC_ERR_TIMEOUT;
2919 ap->hsm_task_state = HSM_ST_TMOUT; 3134 ap->hsm_task_state = HSM_ST_TMOUT;
2920 return 0; 3135 return 0;
2921 } 3136 }
@@ -2962,7 +3177,7 @@ static int ata_pio_complete (struct ata_port *ap)
2962 } 3177 }
2963 3178
2964 qc = ata_qc_from_tag(ap, ap->active_tag); 3179 qc = ata_qc_from_tag(ap, ap->active_tag);
2965 assert(qc != NULL); 3180 WARN_ON(qc == NULL);
2966 3181
2967 drv_stat = ata_wait_idle(ap); 3182 drv_stat = ata_wait_idle(ap);
2968 if (!ata_ok(drv_stat)) { 3183 if (!ata_ok(drv_stat)) {
@@ -2973,7 +3188,7 @@ static int ata_pio_complete (struct ata_port *ap)
2973 3188
2974 ap->hsm_task_state = HSM_ST_IDLE; 3189 ap->hsm_task_state = HSM_ST_IDLE;
2975 3190
2976 assert(qc->err_mask == 0); 3191 WARN_ON(qc->err_mask);
2977 ata_poll_qc_complete(qc); 3192 ata_poll_qc_complete(qc);
2978 3193
2979 /* another command may start at this point */ 3194 /* another command may start at this point */
@@ -2983,7 +3198,7 @@ static int ata_pio_complete (struct ata_port *ap)
2983 3198
2984 3199
2985/** 3200/**
2986 * swap_buf_le16 - swap halves of 16-words in place 3201 * swap_buf_le16 - swap halves of 16-bit words in place
2987 * @buf: Buffer to swap 3202 * @buf: Buffer to swap
2988 * @buf_words: Number of 16-bit words in buffer. 3203 * @buf_words: Number of 16-bit words in buffer.
2989 * 3204 *
@@ -3293,7 +3508,7 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
3293err_out: 3508err_out:
3294 printk(KERN_INFO "ata%u: dev %u: ATAPI check failed\n", 3509 printk(KERN_INFO "ata%u: dev %u: ATAPI check failed\n",
3295 ap->id, dev->devno); 3510 ap->id, dev->devno);
3296 qc->err_mask |= AC_ERR_ATA_BUS; 3511 qc->err_mask |= AC_ERR_HSM;
3297 ap->hsm_task_state = HSM_ST_ERR; 3512 ap->hsm_task_state = HSM_ST_ERR;
3298} 3513}
3299 3514
@@ -3330,7 +3545,7 @@ static void ata_pio_block(struct ata_port *ap)
3330 } 3545 }
3331 3546
3332 qc = ata_qc_from_tag(ap, ap->active_tag); 3547 qc = ata_qc_from_tag(ap, ap->active_tag);
3333 assert(qc != NULL); 3548 WARN_ON(qc == NULL);
3334 3549
3335 /* check error */ 3550 /* check error */
3336 if (status & (ATA_ERR | ATA_DF)) { 3551 if (status & (ATA_ERR | ATA_DF)) {
@@ -3351,7 +3566,7 @@ static void ata_pio_block(struct ata_port *ap)
3351 } else { 3566 } else {
3352 /* handle BSY=0, DRQ=0 as error */ 3567 /* handle BSY=0, DRQ=0 as error */
3353 if ((status & ATA_DRQ) == 0) { 3568 if ((status & ATA_DRQ) == 0) {
3354 qc->err_mask |= AC_ERR_ATA_BUS; 3569 qc->err_mask |= AC_ERR_HSM;
3355 ap->hsm_task_state = HSM_ST_ERR; 3570 ap->hsm_task_state = HSM_ST_ERR;
3356 return; 3571 return;
3357 } 3572 }
@@ -3365,7 +3580,7 @@ static void ata_pio_error(struct ata_port *ap)
3365 struct ata_queued_cmd *qc; 3580 struct ata_queued_cmd *qc;
3366 3581
3367 qc = ata_qc_from_tag(ap, ap->active_tag); 3582 qc = ata_qc_from_tag(ap, ap->active_tag);
3368 assert(qc != NULL); 3583 WARN_ON(qc == NULL);
3369 3584
3370 if (qc->tf.command != ATA_CMD_PACKET) 3585 if (qc->tf.command != ATA_CMD_PACKET)
3371 printk(KERN_WARNING "ata%u: PIO error\n", ap->id); 3586 printk(KERN_WARNING "ata%u: PIO error\n", ap->id);
@@ -3373,7 +3588,7 @@ static void ata_pio_error(struct ata_port *ap)
3373 /* make sure qc->err_mask is available to 3588 /* make sure qc->err_mask is available to
3374 * know what's wrong and recover 3589 * know what's wrong and recover
3375 */ 3590 */
3376 assert(qc->err_mask); 3591 WARN_ON(qc->err_mask == 0);
3377 3592
3378 ap->hsm_task_state = HSM_ST_IDLE; 3593 ap->hsm_task_state = HSM_ST_IDLE;
3379 3594
@@ -3414,12 +3629,84 @@ fsm_start:
3414 } 3629 }
3415 3630
3416 if (timeout) 3631 if (timeout)
3417 queue_delayed_work(ata_wq, &ap->pio_task, timeout); 3632 ata_port_queue_task(ap, ata_pio_task, ap, timeout);
3418 else if (!qc_completed) 3633 else if (!qc_completed)
3419 goto fsm_start; 3634 goto fsm_start;
3420} 3635}
3421 3636
3422/** 3637/**
3638 * atapi_packet_task - Write CDB bytes to hardware
3639 * @_data: Port to which ATAPI device is attached.
3640 *
3641 * When device has indicated its readiness to accept
3642 * a CDB, this function is called. Send the CDB.
3643 * If DMA is to be performed, exit immediately.
3644 * Otherwise, we are in polling mode, so poll
3645 * status under operation succeeds or fails.
3646 *
3647 * LOCKING:
3648 * Kernel thread context (may sleep)
3649 */
3650
3651static void atapi_packet_task(void *_data)
3652{
3653 struct ata_port *ap = _data;
3654 struct ata_queued_cmd *qc;
3655 u8 status;
3656
3657 qc = ata_qc_from_tag(ap, ap->active_tag);
3658 WARN_ON(qc == NULL);
3659 WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE));
3660
3661 /* sleep-wait for BSY to clear */
3662 DPRINTK("busy wait\n");
3663 if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) {
3664 qc->err_mask |= AC_ERR_TIMEOUT;
3665 goto err_out;
3666 }
3667
3668 /* make sure DRQ is set */
3669 status = ata_chk_status(ap);
3670 if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) {
3671 qc->err_mask |= AC_ERR_HSM;
3672 goto err_out;
3673 }
3674
3675 /* send SCSI cdb */
3676 DPRINTK("send cdb\n");
3677 WARN_ON(qc->dev->cdb_len < 12);
3678
3679 if (qc->tf.protocol == ATA_PROT_ATAPI_DMA ||
3680 qc->tf.protocol == ATA_PROT_ATAPI_NODATA) {
3681 unsigned long flags;
3682
3683 /* Once we're done issuing command and kicking bmdma,
3684 * irq handler takes over. To not lose irq, we need
3685 * to clear NOINTR flag before sending cdb, but
3686 * interrupt handler shouldn't be invoked before we're
3687 * finished. Hence, the following locking.
3688 */
3689 spin_lock_irqsave(&ap->host_set->lock, flags);
3690 ap->flags &= ~ATA_FLAG_NOINTR;
3691 ata_data_xfer(ap, qc->cdb, qc->dev->cdb_len, 1);
3692 if (qc->tf.protocol == ATA_PROT_ATAPI_DMA)
3693 ap->ops->bmdma_start(qc); /* initiate bmdma */
3694 spin_unlock_irqrestore(&ap->host_set->lock, flags);
3695 } else {
3696 ata_data_xfer(ap, qc->cdb, qc->dev->cdb_len, 1);
3697
3698 /* PIO commands are handled by polling */
3699 ap->hsm_task_state = HSM_ST;
3700 ata_port_queue_task(ap, ata_pio_task, ap, 0);
3701 }
3702
3703 return;
3704
3705err_out:
3706 ata_poll_qc_complete(qc);
3707}
3708
3709/**
3423 * ata_qc_timeout - Handle timeout of queued command 3710 * ata_qc_timeout - Handle timeout of queued command
3424 * @qc: Command that timed out 3711 * @qc: Command that timed out
3425 * 3712 *
@@ -3447,15 +3734,9 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc)
3447 3734
3448 DPRINTK("ENTER\n"); 3735 DPRINTK("ENTER\n");
3449 3736
3450 spin_lock_irqsave(&host_set->lock, flags); 3737 ap->hsm_task_state = HSM_ST_IDLE;
3451 3738
3452 /* hack alert! We cannot use the supplied completion 3739 spin_lock_irqsave(&host_set->lock, flags);
3453 * function from inside the ->eh_strategy_handler() thread.
3454 * libata is the only user of ->eh_strategy_handler() in
3455 * any kernel, so the default scsi_done() assumes it is
3456 * not being called from the SCSI EH.
3457 */
3458 qc->scsidone = scsi_finish_command;
3459 3740
3460 switch (qc->tf.protocol) { 3741 switch (qc->tf.protocol) {
3461 3742
@@ -3480,12 +3761,13 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc)
3480 3761
3481 /* complete taskfile transaction */ 3762 /* complete taskfile transaction */
3482 qc->err_mask |= ac_err_mask(drv_stat); 3763 qc->err_mask |= ac_err_mask(drv_stat);
3483 ata_qc_complete(qc);
3484 break; 3764 break;
3485 } 3765 }
3486 3766
3487 spin_unlock_irqrestore(&host_set->lock, flags); 3767 spin_unlock_irqrestore(&host_set->lock, flags);
3488 3768
3769 ata_eh_qc_complete(qc);
3770
3489 DPRINTK("EXIT\n"); 3771 DPRINTK("EXIT\n");
3490} 3772}
3491 3773
@@ -3510,20 +3792,10 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc)
3510 3792
3511void ata_eng_timeout(struct ata_port *ap) 3793void ata_eng_timeout(struct ata_port *ap)
3512{ 3794{
3513 struct ata_queued_cmd *qc;
3514
3515 DPRINTK("ENTER\n"); 3795 DPRINTK("ENTER\n");
3516 3796
3517 qc = ata_qc_from_tag(ap, ap->active_tag); 3797 ata_qc_timeout(ata_qc_from_tag(ap, ap->active_tag));
3518 if (qc)
3519 ata_qc_timeout(qc);
3520 else {
3521 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
3522 ap->id);
3523 goto out;
3524 }
3525 3798
3526out:
3527 DPRINTK("EXIT\n"); 3799 DPRINTK("EXIT\n");
3528} 3800}
3529 3801
@@ -3579,21 +3851,6 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
3579 return qc; 3851 return qc;
3580} 3852}
3581 3853
3582static void __ata_qc_complete(struct ata_queued_cmd *qc)
3583{
3584 struct ata_port *ap = qc->ap;
3585 unsigned int tag;
3586
3587 qc->flags = 0;
3588 tag = qc->tag;
3589 if (likely(ata_tag_valid(tag))) {
3590 if (tag == ap->active_tag)
3591 ap->active_tag = ATA_TAG_POISON;
3592 qc->tag = ATA_TAG_POISON;
3593 clear_bit(tag, &ap->qactive);
3594 }
3595}
3596
3597/** 3854/**
3598 * ata_qc_free - free unused ata_queued_cmd 3855 * ata_qc_free - free unused ata_queued_cmd
3599 * @qc: Command to complete 3856 * @qc: Command to complete
@@ -3606,29 +3863,25 @@ static void __ata_qc_complete(struct ata_queued_cmd *qc)
3606 */ 3863 */
3607void ata_qc_free(struct ata_queued_cmd *qc) 3864void ata_qc_free(struct ata_queued_cmd *qc)
3608{ 3865{
3609 assert(qc != NULL); /* ata_qc_from_tag _might_ return NULL */ 3866 struct ata_port *ap = qc->ap;
3867 unsigned int tag;
3610 3868
3611 __ata_qc_complete(qc); 3869 WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
3612}
3613 3870
3614/** 3871 qc->flags = 0;
3615 * ata_qc_complete - Complete an active ATA command 3872 tag = qc->tag;
3616 * @qc: Command to complete 3873 if (likely(ata_tag_valid(tag))) {
3617 * @err_mask: ATA Status register contents 3874 if (tag == ap->active_tag)
3618 * 3875 ap->active_tag = ATA_TAG_POISON;
3619 * Indicate to the mid and upper layers that an ATA 3876 qc->tag = ATA_TAG_POISON;
3620 * command has completed, with either an ok or not-ok status. 3877 clear_bit(tag, &ap->qactive);
3621 * 3878 }
3622 * LOCKING: 3879}
3623 * spin_lock_irqsave(host_set lock)
3624 */
3625 3880
3626void ata_qc_complete(struct ata_queued_cmd *qc) 3881void __ata_qc_complete(struct ata_queued_cmd *qc)
3627{ 3882{
3628 int rc; 3883 WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
3629 3884 WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE));
3630 assert(qc != NULL); /* ata_qc_from_tag _might_ return NULL */
3631 assert(qc->flags & ATA_QCFLAG_ACTIVE);
3632 3885
3633 if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) 3886 if (likely(qc->flags & ATA_QCFLAG_DMAMAP))
3634 ata_sg_clean(qc); 3887 ata_sg_clean(qc);
@@ -3640,17 +3893,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc)
3640 qc->flags &= ~ATA_QCFLAG_ACTIVE; 3893 qc->flags &= ~ATA_QCFLAG_ACTIVE;
3641 3894
3642 /* call completion callback */ 3895 /* call completion callback */
3643 rc = qc->complete_fn(qc); 3896 qc->complete_fn(qc);
3644
3645 /* if callback indicates not to complete command (non-zero),
3646 * return immediately
3647 */
3648 if (rc != 0)
3649 return;
3650
3651 __ata_qc_complete(qc);
3652
3653 VPRINTK("EXIT\n");
3654} 3897}
3655 3898
3656static inline int ata_should_dma_map(struct ata_queued_cmd *qc) 3899static inline int ata_should_dma_map(struct ata_queued_cmd *qc)
@@ -3690,20 +3933,20 @@ static inline int ata_should_dma_map(struct ata_queued_cmd *qc)
3690 * spin_lock_irqsave(host_set lock) 3933 * spin_lock_irqsave(host_set lock)
3691 * 3934 *
3692 * RETURNS: 3935 * RETURNS:
3693 * Zero on success, negative on error. 3936 * Zero on success, AC_ERR_* mask on failure
3694 */ 3937 */
3695 3938
3696int ata_qc_issue(struct ata_queued_cmd *qc) 3939unsigned int ata_qc_issue(struct ata_queued_cmd *qc)
3697{ 3940{
3698 struct ata_port *ap = qc->ap; 3941 struct ata_port *ap = qc->ap;
3699 3942
3700 if (ata_should_dma_map(qc)) { 3943 if (ata_should_dma_map(qc)) {
3701 if (qc->flags & ATA_QCFLAG_SG) { 3944 if (qc->flags & ATA_QCFLAG_SG) {
3702 if (ata_sg_setup(qc)) 3945 if (ata_sg_setup(qc))
3703 goto err_out; 3946 goto sg_err;
3704 } else if (qc->flags & ATA_QCFLAG_SINGLE) { 3947 } else if (qc->flags & ATA_QCFLAG_SINGLE) {
3705 if (ata_sg_setup_one(qc)) 3948 if (ata_sg_setup_one(qc))
3706 goto err_out; 3949 goto sg_err;
3707 } 3950 }
3708 } else { 3951 } else {
3709 qc->flags &= ~ATA_QCFLAG_DMAMAP; 3952 qc->flags &= ~ATA_QCFLAG_DMAMAP;
@@ -3716,8 +3959,9 @@ int ata_qc_issue(struct ata_queued_cmd *qc)
3716 3959
3717 return ap->ops->qc_issue(qc); 3960 return ap->ops->qc_issue(qc);
3718 3961
3719err_out: 3962sg_err:
3720 return -1; 3963 qc->flags &= ~ATA_QCFLAG_DMAMAP;
3964 return AC_ERR_SYSTEM;
3721} 3965}
3722 3966
3723 3967
@@ -3736,10 +3980,10 @@ err_out:
3736 * spin_lock_irqsave(host_set lock) 3980 * spin_lock_irqsave(host_set lock)
3737 * 3981 *
3738 * RETURNS: 3982 * RETURNS:
3739 * Zero on success, negative on error. 3983 * Zero on success, AC_ERR_* mask on failure
3740 */ 3984 */
3741 3985
3742int ata_qc_issue_prot(struct ata_queued_cmd *qc) 3986unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
3743{ 3987{
3744 struct ata_port *ap = qc->ap; 3988 struct ata_port *ap = qc->ap;
3745 3989
@@ -3760,31 +4004,31 @@ int ata_qc_issue_prot(struct ata_queued_cmd *qc)
3760 ata_qc_set_polling(qc); 4004 ata_qc_set_polling(qc);
3761 ata_tf_to_host(ap, &qc->tf); 4005 ata_tf_to_host(ap, &qc->tf);
3762 ap->hsm_task_state = HSM_ST; 4006 ap->hsm_task_state = HSM_ST;
3763 queue_work(ata_wq, &ap->pio_task); 4007 ata_port_queue_task(ap, ata_pio_task, ap, 0);
3764 break; 4008 break;
3765 4009
3766 case ATA_PROT_ATAPI: 4010 case ATA_PROT_ATAPI:
3767 ata_qc_set_polling(qc); 4011 ata_qc_set_polling(qc);
3768 ata_tf_to_host(ap, &qc->tf); 4012 ata_tf_to_host(ap, &qc->tf);
3769 queue_work(ata_wq, &ap->packet_task); 4013 ata_port_queue_task(ap, atapi_packet_task, ap, 0);
3770 break; 4014 break;
3771 4015
3772 case ATA_PROT_ATAPI_NODATA: 4016 case ATA_PROT_ATAPI_NODATA:
3773 ap->flags |= ATA_FLAG_NOINTR; 4017 ap->flags |= ATA_FLAG_NOINTR;
3774 ata_tf_to_host(ap, &qc->tf); 4018 ata_tf_to_host(ap, &qc->tf);
3775 queue_work(ata_wq, &ap->packet_task); 4019 ata_port_queue_task(ap, atapi_packet_task, ap, 0);
3776 break; 4020 break;
3777 4021
3778 case ATA_PROT_ATAPI_DMA: 4022 case ATA_PROT_ATAPI_DMA:
3779 ap->flags |= ATA_FLAG_NOINTR; 4023 ap->flags |= ATA_FLAG_NOINTR;
3780 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ 4024 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */
3781 ap->ops->bmdma_setup(qc); /* set up bmdma */ 4025 ap->ops->bmdma_setup(qc); /* set up bmdma */
3782 queue_work(ata_wq, &ap->packet_task); 4026 ata_port_queue_task(ap, atapi_packet_task, ap, 0);
3783 break; 4027 break;
3784 4028
3785 default: 4029 default:
3786 WARN_ON(1); 4030 WARN_ON(1);
3787 return -1; 4031 return AC_ERR_SYSTEM;
3788 } 4032 }
3789 4033
3790 return 0; 4034 return 0;
@@ -4147,91 +4391,6 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
4147 return IRQ_RETVAL(handled); 4391 return IRQ_RETVAL(handled);
4148} 4392}
4149 4393
4150/**
4151 * atapi_packet_task - Write CDB bytes to hardware
4152 * @_data: Port to which ATAPI device is attached.
4153 *
4154 * When device has indicated its readiness to accept
4155 * a CDB, this function is called. Send the CDB.
4156 * If DMA is to be performed, exit immediately.
4157 * Otherwise, we are in polling mode, so poll
4158 * status under operation succeeds or fails.
4159 *
4160 * LOCKING:
4161 * Kernel thread context (may sleep)
4162 */
4163
4164static void atapi_packet_task(void *_data)
4165{
4166 struct ata_port *ap = _data;
4167 struct ata_queued_cmd *qc;
4168 u8 status;
4169
4170 qc = ata_qc_from_tag(ap, ap->active_tag);
4171 assert(qc != NULL);
4172 assert(qc->flags & ATA_QCFLAG_ACTIVE);
4173
4174 /* sleep-wait for BSY to clear */
4175 DPRINTK("busy wait\n");
4176 if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) {
4177 qc->err_mask |= AC_ERR_ATA_BUS;
4178 goto err_out;
4179 }
4180
4181 /* make sure DRQ is set */
4182 status = ata_chk_status(ap);
4183 if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) {
4184 qc->err_mask |= AC_ERR_ATA_BUS;
4185 goto err_out;
4186 }
4187
4188 /* send SCSI cdb */
4189 DPRINTK("send cdb\n");
4190 assert(ap->cdb_len >= 12);
4191
4192 if (qc->tf.protocol == ATA_PROT_ATAPI_DMA ||
4193 qc->tf.protocol == ATA_PROT_ATAPI_NODATA) {
4194 unsigned long flags;
4195
4196 /* Once we're done issuing command and kicking bmdma,
4197 * irq handler takes over. To not lose irq, we need
4198 * to clear NOINTR flag before sending cdb, but
4199 * interrupt handler shouldn't be invoked before we're
4200 * finished. Hence, the following locking.
4201 */
4202 spin_lock_irqsave(&ap->host_set->lock, flags);
4203 ap->flags &= ~ATA_FLAG_NOINTR;
4204 ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1);
4205 if (qc->tf.protocol == ATA_PROT_ATAPI_DMA)
4206 ap->ops->bmdma_start(qc); /* initiate bmdma */
4207 spin_unlock_irqrestore(&ap->host_set->lock, flags);
4208 } else {
4209 ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1);
4210
4211 /* PIO commands are handled by polling */
4212 ap->hsm_task_state = HSM_ST;
4213 queue_work(ata_wq, &ap->pio_task);
4214 }
4215
4216 return;
4217
4218err_out:
4219 ata_poll_qc_complete(qc);
4220}
4221
4222
4223/**
4224 * ata_port_start - Set port up for dma.
4225 * @ap: Port to initialize
4226 *
4227 * Called just after data structures for each port are
4228 * initialized. Allocates space for PRD table.
4229 *
4230 * May be used as the port_start() entry in ata_port_operations.
4231 *
4232 * LOCKING:
4233 * Inherited from caller.
4234 */
4235 4394
4236/* 4395/*
4237 * Execute a 'simple' command, that only consists of the opcode 'cmd' itself, 4396 * Execute a 'simple' command, that only consists of the opcode 'cmd' itself,
@@ -4284,6 +4443,8 @@ static int ata_start_drive(struct ata_port *ap, struct ata_device *dev)
4284 4443
4285/** 4444/**
4286 * ata_device_resume - wakeup a previously suspended devices 4445 * ata_device_resume - wakeup a previously suspended devices
4446 * @ap: port the device is connected to
4447 * @dev: the device to resume
4287 * 4448 *
4288 * Kick the drive back into action, by sending it an idle immediate 4449 * Kick the drive back into action, by sending it an idle immediate
4289 * command and making sure its transfer mode matches between drive 4450 * command and making sure its transfer mode matches between drive
@@ -4306,10 +4467,11 @@ int ata_device_resume(struct ata_port *ap, struct ata_device *dev)
4306 4467
4307/** 4468/**
4308 * ata_device_suspend - prepare a device for suspend 4469 * ata_device_suspend - prepare a device for suspend
4470 * @ap: port the device is connected to
4471 * @dev: the device to suspend
4309 * 4472 *
4310 * Flush the cache on the drive, if appropriate, then issue a 4473 * Flush the cache on the drive, if appropriate, then issue a
4311 * standbynow command. 4474 * standbynow command.
4312 *
4313 */ 4475 */
4314int ata_device_suspend(struct ata_port *ap, struct ata_device *dev) 4476int ata_device_suspend(struct ata_port *ap, struct ata_device *dev)
4315{ 4477{
@@ -4323,6 +4485,19 @@ int ata_device_suspend(struct ata_port *ap, struct ata_device *dev)
4323 return 0; 4485 return 0;
4324} 4486}
4325 4487
4488/**
4489 * ata_port_start - Set port up for dma.
4490 * @ap: Port to initialize
4491 *
4492 * Called just after data structures for each port are
4493 * initialized. Allocates space for PRD table.
4494 *
4495 * May be used as the port_start() entry in ata_port_operations.
4496 *
4497 * LOCKING:
4498 * Inherited from caller.
4499 */
4500
4326int ata_port_start (struct ata_port *ap) 4501int ata_port_start (struct ata_port *ap)
4327{ 4502{
4328 struct device *dev = ap->host_set->dev; 4503 struct device *dev = ap->host_set->dev;
@@ -4436,8 +4611,8 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
4436 ap->active_tag = ATA_TAG_POISON; 4611 ap->active_tag = ATA_TAG_POISON;
4437 ap->last_ctl = 0xFF; 4612 ap->last_ctl = 0xFF;
4438 4613
4439 INIT_WORK(&ap->packet_task, atapi_packet_task, ap); 4614 INIT_WORK(&ap->port_task, NULL, NULL);
4440 INIT_WORK(&ap->pio_task, ata_pio_task, ap); 4615 INIT_LIST_HEAD(&ap->eh_done_q);
4441 4616
4442 for (i = 0; i < ATA_MAX_DEVICES; i++) 4617 for (i = 0; i < ATA_MAX_DEVICES; i++)
4443 ap->device[i].devno = i; 4618 ap->device[i].devno = i;
@@ -4579,9 +4754,9 @@ int ata_device_add(const struct ata_probe_ent *ent)
4579 4754
4580 ap = host_set->ports[i]; 4755 ap = host_set->ports[i];
4581 4756
4582 DPRINTK("ata%u: probe begin\n", ap->id); 4757 DPRINTK("ata%u: bus probe begin\n", ap->id);
4583 rc = ata_bus_probe(ap); 4758 rc = ata_bus_probe(ap);
4584 DPRINTK("ata%u: probe end\n", ap->id); 4759 DPRINTK("ata%u: bus probe end\n", ap->id);
4585 4760
4586 if (rc) { 4761 if (rc) {
4587 /* FIXME: do something useful here? 4762 /* FIXME: do something useful here?
@@ -4605,7 +4780,7 @@ int ata_device_add(const struct ata_probe_ent *ent)
4605 } 4780 }
4606 4781
4607 /* probes are done, now scan each port's disk(s) */ 4782 /* probes are done, now scan each port's disk(s) */
4608 DPRINTK("probe begin\n"); 4783 DPRINTK("host probe begin\n");
4609 for (i = 0; i < count; i++) { 4784 for (i = 0; i < count; i++) {
4610 struct ata_port *ap = host_set->ports[i]; 4785 struct ata_port *ap = host_set->ports[i];
4611 4786
@@ -4691,11 +4866,14 @@ void ata_host_set_remove(struct ata_host_set *host_set)
4691int ata_scsi_release(struct Scsi_Host *host) 4866int ata_scsi_release(struct Scsi_Host *host)
4692{ 4867{
4693 struct ata_port *ap = (struct ata_port *) &host->hostdata[0]; 4868 struct ata_port *ap = (struct ata_port *) &host->hostdata[0];
4869 int i;
4694 4870
4695 DPRINTK("ENTER\n"); 4871 DPRINTK("ENTER\n");
4696 4872
4697 ap->ops->port_disable(ap); 4873 ap->ops->port_disable(ap);
4698 ata_host_remove(ap, 0); 4874 ata_host_remove(ap, 0);
4875 for (i = 0; i < ATA_MAX_DEVICES; i++)
4876 kfree(ap->device[i].id);
4699 4877
4700 DPRINTK("EXIT\n"); 4878 DPRINTK("EXIT\n");
4701 return 1; 4879 return 1;
@@ -4727,32 +4905,6 @@ void ata_std_ports(struct ata_ioports *ioaddr)
4727 ioaddr->command_addr = ioaddr->cmd_addr + ATA_REG_CMD; 4905 ioaddr->command_addr = ioaddr->cmd_addr + ATA_REG_CMD;
4728} 4906}
4729 4907
4730static struct ata_probe_ent *
4731ata_probe_ent_alloc(struct device *dev, const struct ata_port_info *port)
4732{
4733 struct ata_probe_ent *probe_ent;
4734
4735 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
4736 if (!probe_ent) {
4737 printk(KERN_ERR DRV_NAME "(%s): out of memory\n",
4738 kobject_name(&(dev->kobj)));
4739 return NULL;
4740 }
4741
4742 INIT_LIST_HEAD(&probe_ent->node);
4743 probe_ent->dev = dev;
4744
4745 probe_ent->sht = port->sht;
4746 probe_ent->host_flags = port->host_flags;
4747 probe_ent->pio_mask = port->pio_mask;
4748 probe_ent->mwdma_mask = port->mwdma_mask;
4749 probe_ent->udma_mask = port->udma_mask;
4750 probe_ent->port_ops = port->port_ops;
4751
4752 return probe_ent;
4753}
4754
4755
4756 4908
4757#ifdef CONFIG_PCI 4909#ifdef CONFIG_PCI
4758 4910
@@ -4764,256 +4916,6 @@ void ata_pci_host_stop (struct ata_host_set *host_set)
4764} 4916}
4765 4917
4766/** 4918/**
4767 * ata_pci_init_native_mode - Initialize native-mode driver
4768 * @pdev: pci device to be initialized
4769 * @port: array[2] of pointers to port info structures.
4770 * @ports: bitmap of ports present
4771 *
4772 * Utility function which allocates and initializes an
4773 * ata_probe_ent structure for a standard dual-port
4774 * PIO-based IDE controller. The returned ata_probe_ent
4775 * structure can be passed to ata_device_add(). The returned
4776 * ata_probe_ent structure should then be freed with kfree().
4777 *
4778 * The caller need only pass the address of the primary port, the
4779 * secondary will be deduced automatically. If the device has non
4780 * standard secondary port mappings this function can be called twice,
4781 * once for each interface.
4782 */
4783
4784struct ata_probe_ent *
4785ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int ports)
4786{
4787 struct ata_probe_ent *probe_ent =
4788 ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]);
4789 int p = 0;
4790
4791 if (!probe_ent)
4792 return NULL;
4793
4794 probe_ent->irq = pdev->irq;
4795 probe_ent->irq_flags = SA_SHIRQ;
4796 probe_ent->private_data = port[0]->private_data;
4797
4798 if (ports & ATA_PORT_PRIMARY) {
4799 probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 0);
4800 probe_ent->port[p].altstatus_addr =
4801 probe_ent->port[p].ctl_addr =
4802 pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS;
4803 probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4);
4804 ata_std_ports(&probe_ent->port[p]);
4805 p++;
4806 }
4807
4808 if (ports & ATA_PORT_SECONDARY) {
4809 probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 2);
4810 probe_ent->port[p].altstatus_addr =
4811 probe_ent->port[p].ctl_addr =
4812 pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS;
4813 probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4) + 8;
4814 ata_std_ports(&probe_ent->port[p]);
4815 p++;
4816 }
4817
4818 probe_ent->n_ports = p;
4819 return probe_ent;
4820}
4821
4822static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev, struct ata_port_info *port, int port_num)
4823{
4824 struct ata_probe_ent *probe_ent;
4825
4826 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port);
4827 if (!probe_ent)
4828 return NULL;
4829
4830 probe_ent->legacy_mode = 1;
4831 probe_ent->n_ports = 1;
4832 probe_ent->hard_port_no = port_num;
4833 probe_ent->private_data = port->private_data;
4834
4835 switch(port_num)
4836 {
4837 case 0:
4838 probe_ent->irq = 14;
4839 probe_ent->port[0].cmd_addr = 0x1f0;
4840 probe_ent->port[0].altstatus_addr =
4841 probe_ent->port[0].ctl_addr = 0x3f6;
4842 break;
4843 case 1:
4844 probe_ent->irq = 15;
4845 probe_ent->port[0].cmd_addr = 0x170;
4846 probe_ent->port[0].altstatus_addr =
4847 probe_ent->port[0].ctl_addr = 0x376;
4848 break;
4849 }
4850 probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4) + 8 * port_num;
4851 ata_std_ports(&probe_ent->port[0]);
4852 return probe_ent;
4853}
4854
4855/**
4856 * ata_pci_init_one - Initialize/register PCI IDE host controller
4857 * @pdev: Controller to be initialized
4858 * @port_info: Information from low-level host driver
4859 * @n_ports: Number of ports attached to host controller
4860 *
4861 * This is a helper function which can be called from a driver's
4862 * xxx_init_one() probe function if the hardware uses traditional
4863 * IDE taskfile registers.
4864 *
4865 * This function calls pci_enable_device(), reserves its register
4866 * regions, sets the dma mask, enables bus master mode, and calls
4867 * ata_device_add()
4868 *
4869 * LOCKING:
4870 * Inherited from PCI layer (may sleep).
4871 *
4872 * RETURNS:
4873 * Zero on success, negative on errno-based value on error.
4874 */
4875
4876int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
4877 unsigned int n_ports)
4878{
4879 struct ata_probe_ent *probe_ent = NULL, *probe_ent2 = NULL;
4880 struct ata_port_info *port[2];
4881 u8 tmp8, mask;
4882 unsigned int legacy_mode = 0;
4883 int disable_dev_on_err = 1;
4884 int rc;
4885
4886 DPRINTK("ENTER\n");
4887
4888 port[0] = port_info[0];
4889 if (n_ports > 1)
4890 port[1] = port_info[1];
4891 else
4892 port[1] = port[0];
4893
4894 if ((port[0]->host_flags & ATA_FLAG_NO_LEGACY) == 0
4895 && (pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
4896 /* TODO: What if one channel is in native mode ... */
4897 pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8);
4898 mask = (1 << 2) | (1 << 0);
4899 if ((tmp8 & mask) != mask)
4900 legacy_mode = (1 << 3);
4901 }
4902
4903 /* FIXME... */
4904 if ((!legacy_mode) && (n_ports > 2)) {
4905 printk(KERN_ERR "ata: BUG: native mode, n_ports > 2\n");
4906 n_ports = 2;
4907 /* For now */
4908 }
4909
4910 /* FIXME: Really for ATA it isn't safe because the device may be
4911 multi-purpose and we want to leave it alone if it was already
4912 enabled. Secondly for shared use as Arjan says we want refcounting
4913
4914 Checking dev->is_enabled is insufficient as this is not set at
4915 boot for the primary video which is BIOS enabled
4916 */
4917
4918 rc = pci_enable_device(pdev);
4919 if (rc)
4920 return rc;
4921
4922 rc = pci_request_regions(pdev, DRV_NAME);
4923 if (rc) {
4924 disable_dev_on_err = 0;
4925 goto err_out;
4926 }
4927
4928 /* FIXME: Should use platform specific mappers for legacy port ranges */
4929 if (legacy_mode) {
4930 if (!request_region(0x1f0, 8, "libata")) {
4931 struct resource *conflict, res;
4932 res.start = 0x1f0;
4933 res.end = 0x1f0 + 8 - 1;
4934 conflict = ____request_resource(&ioport_resource, &res);
4935 if (!strcmp(conflict->name, "libata"))
4936 legacy_mode |= (1 << 0);
4937 else {
4938 disable_dev_on_err = 0;
4939 printk(KERN_WARNING "ata: 0x1f0 IDE port busy\n");
4940 }
4941 } else
4942 legacy_mode |= (1 << 0);
4943
4944 if (!request_region(0x170, 8, "libata")) {
4945 struct resource *conflict, res;
4946 res.start = 0x170;
4947 res.end = 0x170 + 8 - 1;
4948 conflict = ____request_resource(&ioport_resource, &res);
4949 if (!strcmp(conflict->name, "libata"))
4950 legacy_mode |= (1 << 1);
4951 else {
4952 disable_dev_on_err = 0;
4953 printk(KERN_WARNING "ata: 0x170 IDE port busy\n");
4954 }
4955 } else
4956 legacy_mode |= (1 << 1);
4957 }
4958
4959 /* we have legacy mode, but all ports are unavailable */
4960 if (legacy_mode == (1 << 3)) {
4961 rc = -EBUSY;
4962 goto err_out_regions;
4963 }
4964
4965 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
4966 if (rc)
4967 goto err_out_regions;
4968 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
4969 if (rc)
4970 goto err_out_regions;
4971
4972 if (legacy_mode) {
4973 if (legacy_mode & (1 << 0))
4974 probe_ent = ata_pci_init_legacy_port(pdev, port[0], 0);
4975 if (legacy_mode & (1 << 1))
4976 probe_ent2 = ata_pci_init_legacy_port(pdev, port[1], 1);
4977 } else {
4978 if (n_ports == 2)
4979 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
4980 else
4981 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY);
4982 }
4983 if (!probe_ent && !probe_ent2) {
4984 rc = -ENOMEM;
4985 goto err_out_regions;
4986 }
4987
4988 pci_set_master(pdev);
4989
4990 /* FIXME: check ata_device_add return */
4991 if (legacy_mode) {
4992 if (legacy_mode & (1 << 0))
4993 ata_device_add(probe_ent);
4994 if (legacy_mode & (1 << 1))
4995 ata_device_add(probe_ent2);
4996 } else
4997 ata_device_add(probe_ent);
4998
4999 kfree(probe_ent);
5000 kfree(probe_ent2);
5001
5002 return 0;
5003
5004err_out_regions:
5005 if (legacy_mode & (1 << 0))
5006 release_region(0x1f0, 8);
5007 if (legacy_mode & (1 << 1))
5008 release_region(0x170, 8);
5009 pci_release_regions(pdev);
5010err_out:
5011 if (disable_dev_on_err)
5012 pci_disable_device(pdev);
5013 return rc;
5014}
5015
5016/**
5017 * ata_pci_remove_one - PCI layer callback for device removal 4919 * ata_pci_remove_one - PCI layer callback for device removal
5018 * @pdev: PCI device that was removed 4920 * @pdev: PCI device that was removed
5019 * 4921 *
@@ -5143,7 +5045,7 @@ EXPORT_SYMBOL_GPL(ata_device_add);
5143EXPORT_SYMBOL_GPL(ata_host_set_remove); 5045EXPORT_SYMBOL_GPL(ata_host_set_remove);
5144EXPORT_SYMBOL_GPL(ata_sg_init); 5046EXPORT_SYMBOL_GPL(ata_sg_init);
5145EXPORT_SYMBOL_GPL(ata_sg_init_one); 5047EXPORT_SYMBOL_GPL(ata_sg_init_one);
5146EXPORT_SYMBOL_GPL(ata_qc_complete); 5048EXPORT_SYMBOL_GPL(__ata_qc_complete);
5147EXPORT_SYMBOL_GPL(ata_qc_issue_prot); 5049EXPORT_SYMBOL_GPL(ata_qc_issue_prot);
5148EXPORT_SYMBOL_GPL(ata_eng_timeout); 5050EXPORT_SYMBOL_GPL(ata_eng_timeout);
5149EXPORT_SYMBOL_GPL(ata_tf_load); 5051EXPORT_SYMBOL_GPL(ata_tf_load);
@@ -5169,18 +5071,30 @@ EXPORT_SYMBOL_GPL(ata_port_probe);
5169EXPORT_SYMBOL_GPL(sata_phy_reset); 5071EXPORT_SYMBOL_GPL(sata_phy_reset);
5170EXPORT_SYMBOL_GPL(__sata_phy_reset); 5072EXPORT_SYMBOL_GPL(__sata_phy_reset);
5171EXPORT_SYMBOL_GPL(ata_bus_reset); 5073EXPORT_SYMBOL_GPL(ata_bus_reset);
5074EXPORT_SYMBOL_GPL(ata_std_probeinit);
5075EXPORT_SYMBOL_GPL(ata_std_softreset);
5076EXPORT_SYMBOL_GPL(sata_std_hardreset);
5077EXPORT_SYMBOL_GPL(ata_std_postreset);
5078EXPORT_SYMBOL_GPL(ata_std_probe_reset);
5079EXPORT_SYMBOL_GPL(ata_drive_probe_reset);
5080EXPORT_SYMBOL_GPL(ata_dev_revalidate);
5172EXPORT_SYMBOL_GPL(ata_port_disable); 5081EXPORT_SYMBOL_GPL(ata_port_disable);
5173EXPORT_SYMBOL_GPL(ata_ratelimit); 5082EXPORT_SYMBOL_GPL(ata_ratelimit);
5083EXPORT_SYMBOL_GPL(ata_busy_sleep);
5084EXPORT_SYMBOL_GPL(ata_port_queue_task);
5174EXPORT_SYMBOL_GPL(ata_scsi_ioctl); 5085EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
5175EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); 5086EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
5087EXPORT_SYMBOL_GPL(ata_scsi_timed_out);
5176EXPORT_SYMBOL_GPL(ata_scsi_error); 5088EXPORT_SYMBOL_GPL(ata_scsi_error);
5177EXPORT_SYMBOL_GPL(ata_scsi_slave_config); 5089EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
5178EXPORT_SYMBOL_GPL(ata_scsi_release); 5090EXPORT_SYMBOL_GPL(ata_scsi_release);
5179EXPORT_SYMBOL_GPL(ata_host_intr); 5091EXPORT_SYMBOL_GPL(ata_host_intr);
5180EXPORT_SYMBOL_GPL(ata_dev_classify); 5092EXPORT_SYMBOL_GPL(ata_dev_classify);
5181EXPORT_SYMBOL_GPL(ata_dev_id_string); 5093EXPORT_SYMBOL_GPL(ata_id_string);
5182EXPORT_SYMBOL_GPL(ata_dev_config); 5094EXPORT_SYMBOL_GPL(ata_id_c_string);
5183EXPORT_SYMBOL_GPL(ata_scsi_simulate); 5095EXPORT_SYMBOL_GPL(ata_scsi_simulate);
5096EXPORT_SYMBOL_GPL(ata_eh_qc_complete);
5097EXPORT_SYMBOL_GPL(ata_eh_qc_retry);
5184 5098
5185EXPORT_SYMBOL_GPL(ata_pio_need_iordy); 5099EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
5186EXPORT_SYMBOL_GPL(ata_timing_compute); 5100EXPORT_SYMBOL_GPL(ata_timing_compute);
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 59503c9ccac9..ccedb4536977 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -151,7 +151,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
151 struct scsi_sense_hdr sshdr; 151 struct scsi_sense_hdr sshdr;
152 enum dma_data_direction data_dir; 152 enum dma_data_direction data_dir;
153 153
154 if (NULL == (void *)arg) 154 if (arg == NULL)
155 return -EINVAL; 155 return -EINVAL;
156 156
157 if (copy_from_user(args, arg, sizeof(args))) 157 if (copy_from_user(args, arg, sizeof(args)))
@@ -201,7 +201,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
201 /* Need code to retrieve data from check condition? */ 201 /* Need code to retrieve data from check condition? */
202 202
203 if ((argbuf) 203 if ((argbuf)
204 && copy_to_user((void *)(arg + sizeof(args)), argbuf, argsize)) 204 && copy_to_user(arg + sizeof(args), argbuf, argsize))
205 rc = -EFAULT; 205 rc = -EFAULT;
206error: 206error:
207 if (argbuf) 207 if (argbuf)
@@ -228,7 +228,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
228 u8 args[7]; 228 u8 args[7];
229 struct scsi_sense_hdr sshdr; 229 struct scsi_sense_hdr sshdr;
230 230
231 if (NULL == (void *)arg) 231 if (arg == NULL)
232 return -EINVAL; 232 return -EINVAL;
233 233
234 if (copy_from_user(args, arg, sizeof(args))) 234 if (copy_from_user(args, arg, sizeof(args)))
@@ -553,7 +553,7 @@ void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc)
553 /* 553 /*
554 * Read the controller registers. 554 * Read the controller registers.
555 */ 555 */
556 assert(NULL != qc->ap->ops->tf_read); 556 WARN_ON(qc->ap->ops->tf_read == NULL);
557 qc->ap->ops->tf_read(qc->ap, tf); 557 qc->ap->ops->tf_read(qc->ap, tf);
558 558
559 /* 559 /*
@@ -628,7 +628,7 @@ void ata_gen_fixed_sense(struct ata_queued_cmd *qc)
628 /* 628 /*
629 * Read the controller registers. 629 * Read the controller registers.
630 */ 630 */
631 assert(NULL != qc->ap->ops->tf_read); 631 WARN_ON(qc->ap->ops->tf_read == NULL);
632 qc->ap->ops->tf_read(qc->ap, tf); 632 qc->ap->ops->tf_read(qc->ap, tf);
633 633
634 /* 634 /*
@@ -684,23 +684,23 @@ int ata_scsi_slave_config(struct scsi_device *sdev)
684 if (sdev->id < ATA_MAX_DEVICES) { 684 if (sdev->id < ATA_MAX_DEVICES) {
685 struct ata_port *ap; 685 struct ata_port *ap;
686 struct ata_device *dev; 686 struct ata_device *dev;
687 unsigned int max_sectors;
687 688
688 ap = (struct ata_port *) &sdev->host->hostdata[0]; 689 ap = (struct ata_port *) &sdev->host->hostdata[0];
689 dev = &ap->device[sdev->id]; 690 dev = &ap->device[sdev->id];
690 691
691 /* TODO: 1024 is an arbitrary number, not the 692 /* TODO: 2048 is an arbitrary number, not the
692 * hardware maximum. This should be increased to 693 * hardware maximum. This should be increased to
693 * 65534 when Jens Axboe's patch for dynamically 694 * 65534 when Jens Axboe's patch for dynamically
694 * determining max_sectors is merged. 695 * determining max_sectors is merged.
695 */ 696 */
696 if ((dev->flags & ATA_DFLAG_LBA48) && 697 max_sectors = ATA_MAX_SECTORS;
697 ((dev->flags & ATA_DFLAG_LOCK_SECTORS) == 0)) { 698 if (dev->flags & ATA_DFLAG_LBA48)
698 /* 699 max_sectors = 2048;
699 * do not overwrite sdev->host->max_sectors, since 700 if (dev->max_sectors)
700 * other drives on this host may not support LBA48 701 max_sectors = dev->max_sectors;
701 */ 702
702 blk_queue_max_sectors(sdev->request_queue, 2048); 703 blk_queue_max_sectors(sdev->request_queue, max_sectors);
703 }
704 704
705 /* 705 /*
706 * SATA DMA transfers must be multiples of 4 byte, so 706 * SATA DMA transfers must be multiples of 4 byte, so
@@ -717,6 +717,47 @@ int ata_scsi_slave_config(struct scsi_device *sdev)
717} 717}
718 718
719/** 719/**
720 * ata_scsi_timed_out - SCSI layer time out callback
721 * @cmd: timed out SCSI command
722 *
723 * Handles SCSI layer timeout. We race with normal completion of
724 * the qc for @cmd. If the qc is already gone, we lose and let
725 * the scsi command finish (EH_HANDLED). Otherwise, the qc has
726 * timed out and EH should be invoked. Prevent ata_qc_complete()
727 * from finishing it by setting EH_SCHEDULED and return
728 * EH_NOT_HANDLED.
729 *
730 * LOCKING:
731 * Called from timer context
732 *
733 * RETURNS:
734 * EH_HANDLED or EH_NOT_HANDLED
735 */
736enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
737{
738 struct Scsi_Host *host = cmd->device->host;
739 struct ata_port *ap = (struct ata_port *) &host->hostdata[0];
740 unsigned long flags;
741 struct ata_queued_cmd *qc;
742 enum scsi_eh_timer_return ret = EH_HANDLED;
743
744 DPRINTK("ENTER\n");
745
746 spin_lock_irqsave(&ap->host_set->lock, flags);
747 qc = ata_qc_from_tag(ap, ap->active_tag);
748 if (qc) {
749 WARN_ON(qc->scsicmd != cmd);
750 qc->flags |= ATA_QCFLAG_EH_SCHEDULED;
751 qc->err_mask |= AC_ERR_TIMEOUT;
752 ret = EH_NOT_HANDLED;
753 }
754 spin_unlock_irqrestore(&ap->host_set->lock, flags);
755
756 DPRINTK("EXIT, ret=%d\n", ret);
757 return ret;
758}
759
760/**
720 * ata_scsi_error - SCSI layer error handler callback 761 * ata_scsi_error - SCSI layer error handler callback
721 * @host: SCSI host on which error occurred 762 * @host: SCSI host on which error occurred
722 * 763 *
@@ -732,23 +773,84 @@ int ata_scsi_slave_config(struct scsi_device *sdev)
732int ata_scsi_error(struct Scsi_Host *host) 773int ata_scsi_error(struct Scsi_Host *host)
733{ 774{
734 struct ata_port *ap; 775 struct ata_port *ap;
776 unsigned long flags;
735 777
736 DPRINTK("ENTER\n"); 778 DPRINTK("ENTER\n");
737 779
738 ap = (struct ata_port *) &host->hostdata[0]; 780 ap = (struct ata_port *) &host->hostdata[0];
781
782 spin_lock_irqsave(&ap->host_set->lock, flags);
783 WARN_ON(ap->flags & ATA_FLAG_IN_EH);
784 ap->flags |= ATA_FLAG_IN_EH;
785 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL);
786 spin_unlock_irqrestore(&ap->host_set->lock, flags);
787
788 ata_port_flush_task(ap);
789
739 ap->ops->eng_timeout(ap); 790 ap->ops->eng_timeout(ap);
740 791
741 /* TODO: this is per-command; when queueing is supported 792 WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q));
742 * this code will either change or move to a more 793
743 * appropriate place 794 scsi_eh_flush_done_q(&ap->eh_done_q);
744 */ 795
745 host->host_failed--; 796 spin_lock_irqsave(&ap->host_set->lock, flags);
746 INIT_LIST_HEAD(&host->eh_cmd_q); 797 ap->flags &= ~ATA_FLAG_IN_EH;
798 spin_unlock_irqrestore(&ap->host_set->lock, flags);
747 799
748 DPRINTK("EXIT\n"); 800 DPRINTK("EXIT\n");
749 return 0; 801 return 0;
750} 802}
751 803
804static void ata_eh_scsidone(struct scsi_cmnd *scmd)
805{
806 /* nada */
807}
808
809static void __ata_eh_qc_complete(struct ata_queued_cmd *qc)
810{
811 struct ata_port *ap = qc->ap;
812 struct scsi_cmnd *scmd = qc->scsicmd;
813 unsigned long flags;
814
815 spin_lock_irqsave(&ap->host_set->lock, flags);
816 qc->scsidone = ata_eh_scsidone;
817 __ata_qc_complete(qc);
818 WARN_ON(ata_tag_valid(qc->tag));
819 spin_unlock_irqrestore(&ap->host_set->lock, flags);
820
821 scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
822}
823
824/**
825 * ata_eh_qc_complete - Complete an active ATA command from EH
826 * @qc: Command to complete
827 *
828 * Indicate to the mid and upper layers that an ATA command has
829 * completed. To be used from EH.
830 */
831void ata_eh_qc_complete(struct ata_queued_cmd *qc)
832{
833 struct scsi_cmnd *scmd = qc->scsicmd;
834 scmd->retries = scmd->allowed;
835 __ata_eh_qc_complete(qc);
836}
837
838/**
839 * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
840 * @qc: Command to retry
841 *
842 * Indicate to the mid and upper layers that an ATA command
843 * should be retried. To be used from EH.
844 *
845 * SCSI midlayer limits the number of retries to scmd->allowed.
846 * This function might need to adjust scmd->retries for commands
847 * which get retried due to unrelated NCQ failures.
848 */
849void ata_eh_qc_retry(struct ata_queued_cmd *qc)
850{
851 __ata_eh_qc_complete(qc);
852}
853
752/** 854/**
753 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command 855 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command
754 * @qc: Storage for translated ATA taskfile 856 * @qc: Storage for translated ATA taskfile
@@ -985,9 +1087,13 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc
985 if (dev->flags & ATA_DFLAG_LBA) { 1087 if (dev->flags & ATA_DFLAG_LBA) {
986 tf->flags |= ATA_TFLAG_LBA; 1088 tf->flags |= ATA_TFLAG_LBA;
987 1089
988 if (dev->flags & ATA_DFLAG_LBA48) { 1090 if (lba_28_ok(block, n_block)) {
989 if (n_block > (64 * 1024)) 1091 /* use LBA28 */
990 goto invalid_fld; 1092 tf->command = ATA_CMD_VERIFY;
1093 tf->device |= (block >> 24) & 0xf;
1094 } else if (lba_48_ok(block, n_block)) {
1095 if (!(dev->flags & ATA_DFLAG_LBA48))
1096 goto out_of_range;
991 1097
992 /* use LBA48 */ 1098 /* use LBA48 */
993 tf->flags |= ATA_TFLAG_LBA48; 1099 tf->flags |= ATA_TFLAG_LBA48;
@@ -998,15 +1104,9 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc
998 tf->hob_lbah = (block >> 40) & 0xff; 1104 tf->hob_lbah = (block >> 40) & 0xff;
999 tf->hob_lbam = (block >> 32) & 0xff; 1105 tf->hob_lbam = (block >> 32) & 0xff;
1000 tf->hob_lbal = (block >> 24) & 0xff; 1106 tf->hob_lbal = (block >> 24) & 0xff;
1001 } else { 1107 } else
1002 if (n_block > 256) 1108 /* request too large even for LBA48 */
1003 goto invalid_fld; 1109 goto out_of_range;
1004
1005 /* use LBA28 */
1006 tf->command = ATA_CMD_VERIFY;
1007
1008 tf->device |= (block >> 24) & 0xf;
1009 }
1010 1110
1011 tf->nsect = n_block & 0xff; 1111 tf->nsect = n_block & 0xff;
1012 1112
@@ -1019,8 +1119,8 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc
1019 /* CHS */ 1119 /* CHS */
1020 u32 sect, head, cyl, track; 1120 u32 sect, head, cyl, track;
1021 1121
1022 if (n_block > 256) 1122 if (!lba_28_ok(block, n_block))
1023 goto invalid_fld; 1123 goto out_of_range;
1024 1124
1025 /* Convert LBA to CHS */ 1125 /* Convert LBA to CHS */
1026 track = (u32)block / dev->sectors; 1126 track = (u32)block / dev->sectors;
@@ -1139,9 +1239,11 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1139 if (dev->flags & ATA_DFLAG_LBA) { 1239 if (dev->flags & ATA_DFLAG_LBA) {
1140 tf->flags |= ATA_TFLAG_LBA; 1240 tf->flags |= ATA_TFLAG_LBA;
1141 1241
1142 if (dev->flags & ATA_DFLAG_LBA48) { 1242 if (lba_28_ok(block, n_block)) {
1143 /* The request -may- be too large for LBA48. */ 1243 /* use LBA28 */
1144 if ((block >> 48) || (n_block > 65536)) 1244 tf->device |= (block >> 24) & 0xf;
1245 } else if (lba_48_ok(block, n_block)) {
1246 if (!(dev->flags & ATA_DFLAG_LBA48))
1145 goto out_of_range; 1247 goto out_of_range;
1146 1248
1147 /* use LBA48 */ 1249 /* use LBA48 */
@@ -1152,15 +1254,9 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1152 tf->hob_lbah = (block >> 40) & 0xff; 1254 tf->hob_lbah = (block >> 40) & 0xff;
1153 tf->hob_lbam = (block >> 32) & 0xff; 1255 tf->hob_lbam = (block >> 32) & 0xff;
1154 tf->hob_lbal = (block >> 24) & 0xff; 1256 tf->hob_lbal = (block >> 24) & 0xff;
1155 } else { 1257 } else
1156 /* use LBA28 */ 1258 /* request too large even for LBA48 */
1157 1259 goto out_of_range;
1158 /* The request -may- be too large for LBA28. */
1159 if ((block >> 28) || (n_block > 256))
1160 goto out_of_range;
1161
1162 tf->device |= (block >> 24) & 0xf;
1163 }
1164 1260
1165 if (unlikely(ata_rwcmd_protocol(qc) < 0)) 1261 if (unlikely(ata_rwcmd_protocol(qc) < 0))
1166 goto invalid_fld; 1262 goto invalid_fld;
@@ -1178,7 +1274,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1178 u32 sect, head, cyl, track; 1274 u32 sect, head, cyl, track;
1179 1275
1180 /* The request -may- be too large for CHS addressing. */ 1276 /* The request -may- be too large for CHS addressing. */
1181 if ((block >> 28) || (n_block > 256)) 1277 if (!lba_28_ok(block, n_block))
1182 goto out_of_range; 1278 goto out_of_range;
1183 1279
1184 if (unlikely(ata_rwcmd_protocol(qc) < 0)) 1280 if (unlikely(ata_rwcmd_protocol(qc) < 0))
@@ -1225,7 +1321,7 @@ nothing_to_do:
1225 return 1; 1321 return 1;
1226} 1322}
1227 1323
1228static int ata_scsi_qc_complete(struct ata_queued_cmd *qc) 1324static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
1229{ 1325{
1230 struct scsi_cmnd *cmd = qc->scsicmd; 1326 struct scsi_cmnd *cmd = qc->scsicmd;
1231 u8 *cdb = cmd->cmnd; 1327 u8 *cdb = cmd->cmnd;
@@ -1262,7 +1358,7 @@ static int ata_scsi_qc_complete(struct ata_queued_cmd *qc)
1262 1358
1263 qc->scsidone(cmd); 1359 qc->scsidone(cmd);
1264 1360
1265 return 0; 1361 ata_qc_free(qc);
1266} 1362}
1267 1363
1268/** 1364/**
@@ -1328,8 +1424,9 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev,
1328 goto early_finish; 1424 goto early_finish;
1329 1425
1330 /* select device, send command to hardware */ 1426 /* select device, send command to hardware */
1331 if (ata_qc_issue(qc)) 1427 qc->err_mask = ata_qc_issue(qc);
1332 goto err_did; 1428 if (qc->err_mask)
1429 ata_qc_complete(qc);
1333 1430
1334 VPRINTK("EXIT\n"); 1431 VPRINTK("EXIT\n");
1335 return; 1432 return;
@@ -1472,8 +1569,8 @@ unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf,
1472 1569
1473 if (buflen > 35) { 1570 if (buflen > 35) {
1474 memcpy(&rbuf[8], "ATA ", 8); 1571 memcpy(&rbuf[8], "ATA ", 8);
1475 ata_dev_id_string(args->id, &rbuf[16], ATA_ID_PROD_OFS, 16); 1572 ata_id_string(args->id, &rbuf[16], ATA_ID_PROD_OFS, 16);
1476 ata_dev_id_string(args->id, &rbuf[32], ATA_ID_FW_REV_OFS, 4); 1573 ata_id_string(args->id, &rbuf[32], ATA_ID_FW_REV_OFS, 4);
1477 if (rbuf[32] == 0 || rbuf[32] == ' ') 1574 if (rbuf[32] == 0 || rbuf[32] == ' ')
1478 memcpy(&rbuf[32], "n/a ", 4); 1575 memcpy(&rbuf[32], "n/a ", 4);
1479 } 1576 }
@@ -1547,8 +1644,8 @@ unsigned int ata_scsiop_inq_80(struct ata_scsi_args *args, u8 *rbuf,
1547 memcpy(rbuf, hdr, sizeof(hdr)); 1644 memcpy(rbuf, hdr, sizeof(hdr));
1548 1645
1549 if (buflen > (ATA_SERNO_LEN + 4 - 1)) 1646 if (buflen > (ATA_SERNO_LEN + 4 - 1))
1550 ata_dev_id_string(args->id, (unsigned char *) &rbuf[4], 1647 ata_id_string(args->id, (unsigned char *) &rbuf[4],
1551 ATA_ID_SERNO_OFS, ATA_SERNO_LEN); 1648 ATA_ID_SERNO_OFS, ATA_SERNO_LEN);
1552 1649
1553 return 0; 1650 return 0;
1554} 1651}
@@ -1713,15 +1810,12 @@ static int ata_dev_supports_fua(u16 *id)
1713 if (!ata_id_has_fua(id)) 1810 if (!ata_id_has_fua(id))
1714 return 0; 1811 return 0;
1715 1812
1716 model[40] = '\0'; 1813 ata_id_c_string(id, model, ATA_ID_PROD_OFS, sizeof(model));
1717 fw[8] = '\0'; 1814 ata_id_c_string(id, fw, ATA_ID_FW_REV_OFS, sizeof(fw));
1718
1719 ata_dev_id_string(id, model, ATA_ID_PROD_OFS, sizeof(model) - 1);
1720 ata_dev_id_string(id, fw, ATA_ID_FW_REV_OFS, sizeof(fw) - 1);
1721 1815
1722 if (strncmp(model, "Maxtor", 6)) 1816 if (strcmp(model, "Maxtor"))
1723 return 1; 1817 return 1;
1724 if (strncmp(fw, "BANC1G10", 8)) 1818 if (strcmp(fw, "BANC1G10"))
1725 return 1; 1819 return 1;
1726 1820
1727 return 0; /* blacklisted */ 1821 return 0; /* blacklisted */
@@ -2015,7 +2109,7 @@ void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8
2015 done(cmd); 2109 done(cmd);
2016} 2110}
2017 2111
2018static int atapi_sense_complete(struct ata_queued_cmd *qc) 2112static void atapi_sense_complete(struct ata_queued_cmd *qc)
2019{ 2113{
2020 if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) 2114 if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0))
2021 /* FIXME: not quite right; we don't want the 2115 /* FIXME: not quite right; we don't want the
@@ -2026,7 +2120,7 @@ static int atapi_sense_complete(struct ata_queued_cmd *qc)
2026 ata_gen_ata_desc_sense(qc); 2120 ata_gen_ata_desc_sense(qc);
2027 2121
2028 qc->scsidone(qc->scsicmd); 2122 qc->scsidone(qc->scsicmd);
2029 return 0; 2123 ata_qc_free(qc);
2030} 2124}
2031 2125
2032/* is it pointless to prefer PIO for "safety reasons"? */ 2126/* is it pointless to prefer PIO for "safety reasons"? */
@@ -2056,7 +2150,7 @@ static void atapi_request_sense(struct ata_queued_cmd *qc)
2056 ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer)); 2150 ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer));
2057 qc->dma_dir = DMA_FROM_DEVICE; 2151 qc->dma_dir = DMA_FROM_DEVICE;
2058 2152
2059 memset(&qc->cdb, 0, ap->cdb_len); 2153 memset(&qc->cdb, 0, qc->dev->cdb_len);
2060 qc->cdb[0] = REQUEST_SENSE; 2154 qc->cdb[0] = REQUEST_SENSE;
2061 qc->cdb[4] = SCSI_SENSE_BUFFERSIZE; 2155 qc->cdb[4] = SCSI_SENSE_BUFFERSIZE;
2062 2156
@@ -2075,15 +2169,14 @@ static void atapi_request_sense(struct ata_queued_cmd *qc)
2075 2169
2076 qc->complete_fn = atapi_sense_complete; 2170 qc->complete_fn = atapi_sense_complete;
2077 2171
2078 if (ata_qc_issue(qc)) { 2172 qc->err_mask = ata_qc_issue(qc);
2079 qc->err_mask |= AC_ERR_OTHER; 2173 if (qc->err_mask)
2080 ata_qc_complete(qc); 2174 ata_qc_complete(qc);
2081 }
2082 2175
2083 DPRINTK("EXIT\n"); 2176 DPRINTK("EXIT\n");
2084} 2177}
2085 2178
2086static int atapi_qc_complete(struct ata_queued_cmd *qc) 2179static void atapi_qc_complete(struct ata_queued_cmd *qc)
2087{ 2180{
2088 struct scsi_cmnd *cmd = qc->scsicmd; 2181 struct scsi_cmnd *cmd = qc->scsicmd;
2089 unsigned int err_mask = qc->err_mask; 2182 unsigned int err_mask = qc->err_mask;
@@ -2093,7 +2186,7 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc)
2093 if (unlikely(err_mask & AC_ERR_DEV)) { 2186 if (unlikely(err_mask & AC_ERR_DEV)) {
2094 cmd->result = SAM_STAT_CHECK_CONDITION; 2187 cmd->result = SAM_STAT_CHECK_CONDITION;
2095 atapi_request_sense(qc); 2188 atapi_request_sense(qc);
2096 return 1; 2189 return;
2097 } 2190 }
2098 2191
2099 else if (unlikely(err_mask)) 2192 else if (unlikely(err_mask))
@@ -2133,7 +2226,7 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc)
2133 } 2226 }
2134 2227
2135 qc->scsidone(cmd); 2228 qc->scsidone(cmd);
2136 return 0; 2229 ata_qc_free(qc);
2137} 2230}
2138/** 2231/**
2139 * atapi_xlat - Initialize PACKET taskfile 2232 * atapi_xlat - Initialize PACKET taskfile
@@ -2159,7 +2252,7 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
2159 if (ata_check_atapi_dma(qc)) 2252 if (ata_check_atapi_dma(qc))
2160 using_pio = 1; 2253 using_pio = 1;
2161 2254
2162 memcpy(&qc->cdb, scsicmd, qc->ap->cdb_len); 2255 memcpy(&qc->cdb, scsicmd, dev->cdb_len);
2163 2256
2164 qc->complete_fn = atapi_qc_complete; 2257 qc->complete_fn = atapi_qc_complete;
2165 2258
@@ -2519,7 +2612,8 @@ out_unlock:
2519 2612
2520/** 2613/**
2521 * ata_scsi_simulate - simulate SCSI command on ATA device 2614 * ata_scsi_simulate - simulate SCSI command on ATA device
2522 * @id: current IDENTIFY data for target device. 2615 * @ap: port the device is connected to
2616 * @dev: the target device
2523 * @cmd: SCSI command being sent to device. 2617 * @cmd: SCSI command being sent to device.
2524 * @done: SCSI command completion function. 2618 * @done: SCSI command completion function.
2525 * 2619 *
diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h
index fddaf479a544..f4c48c91b63d 100644
--- a/drivers/scsi/libata.h
+++ b/drivers/scsi/libata.h
@@ -45,8 +45,9 @@ extern int libata_fua;
45extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, 45extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
46 struct ata_device *dev); 46 struct ata_device *dev);
47extern int ata_rwcmd_protocol(struct ata_queued_cmd *qc); 47extern int ata_rwcmd_protocol(struct ata_queued_cmd *qc);
48extern void ata_port_flush_task(struct ata_port *ap);
48extern void ata_qc_free(struct ata_queued_cmd *qc); 49extern void ata_qc_free(struct ata_queued_cmd *qc);
49extern int ata_qc_issue(struct ata_queued_cmd *qc); 50extern unsigned int ata_qc_issue(struct ata_queued_cmd *qc);
50extern int ata_check_atapi_dma(struct ata_queued_cmd *qc); 51extern int ata_check_atapi_dma(struct ata_queued_cmd *qc);
51extern void ata_dev_select(struct ata_port *ap, unsigned int device, 52extern void ata_dev_select(struct ata_port *ap, unsigned int device,
52 unsigned int wait, unsigned int can_sleep); 53 unsigned int wait, unsigned int can_sleep);
diff --git a/drivers/scsi/pdc_adma.c b/drivers/scsi/pdc_adma.c
index e8df0c9ec1e6..5f33cc932e70 100644
--- a/drivers/scsi/pdc_adma.c
+++ b/drivers/scsi/pdc_adma.c
@@ -131,7 +131,7 @@ static void adma_host_stop(struct ata_host_set *host_set);
131static void adma_port_stop(struct ata_port *ap); 131static void adma_port_stop(struct ata_port *ap);
132static void adma_phy_reset(struct ata_port *ap); 132static void adma_phy_reset(struct ata_port *ap);
133static void adma_qc_prep(struct ata_queued_cmd *qc); 133static void adma_qc_prep(struct ata_queued_cmd *qc);
134static int adma_qc_issue(struct ata_queued_cmd *qc); 134static unsigned int adma_qc_issue(struct ata_queued_cmd *qc);
135static int adma_check_atapi_dma(struct ata_queued_cmd *qc); 135static int adma_check_atapi_dma(struct ata_queued_cmd *qc);
136static void adma_bmdma_stop(struct ata_queued_cmd *qc); 136static void adma_bmdma_stop(struct ata_queued_cmd *qc);
137static u8 adma_bmdma_status(struct ata_port *ap); 137static u8 adma_bmdma_status(struct ata_port *ap);
@@ -143,11 +143,11 @@ static struct scsi_host_template adma_ata_sht = {
143 .name = DRV_NAME, 143 .name = DRV_NAME,
144 .ioctl = ata_scsi_ioctl, 144 .ioctl = ata_scsi_ioctl,
145 .queuecommand = ata_scsi_queuecmd, 145 .queuecommand = ata_scsi_queuecmd,
146 .eh_timed_out = ata_scsi_timed_out,
146 .eh_strategy_handler = ata_scsi_error, 147 .eh_strategy_handler = ata_scsi_error,
147 .can_queue = ATA_DEF_QUEUE, 148 .can_queue = ATA_DEF_QUEUE,
148 .this_id = ATA_SHT_THIS_ID, 149 .this_id = ATA_SHT_THIS_ID,
149 .sg_tablesize = LIBATA_MAX_PRD, 150 .sg_tablesize = LIBATA_MAX_PRD,
150 .max_sectors = ATA_MAX_SECTORS,
151 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 151 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
152 .emulated = ATA_SHT_EMULATED, 152 .emulated = ATA_SHT_EMULATED,
153 .use_clustering = ENABLE_CLUSTERING, 153 .use_clustering = ENABLE_CLUSTERING,
@@ -419,7 +419,7 @@ static inline void adma_packet_start(struct ata_queued_cmd *qc)
419 writew(aPIOMD4 | aGO, chan + ADMA_CONTROL); 419 writew(aPIOMD4 | aGO, chan + ADMA_CONTROL);
420} 420}
421 421
422static int adma_qc_issue(struct ata_queued_cmd *qc) 422static unsigned int adma_qc_issue(struct ata_queued_cmd *qc)
423{ 423{
424 struct adma_port_priv *pp = qc->ap->private_data; 424 struct adma_port_priv *pp = qc->ap->private_data;
425 425
diff --git a/drivers/scsi/sata_mv.c b/drivers/scsi/sata_mv.c
index 2770005324b4..e561281967dd 100644
--- a/drivers/scsi/sata_mv.c
+++ b/drivers/scsi/sata_mv.c
@@ -37,7 +37,7 @@
37#include <asm/io.h> 37#include <asm/io.h>
38 38
39#define DRV_NAME "sata_mv" 39#define DRV_NAME "sata_mv"
40#define DRV_VERSION "0.5" 40#define DRV_VERSION "0.6"
41 41
42enum { 42enum {
43 /* BAR's are enumerated in terms of pci_resource_start() terms */ 43 /* BAR's are enumerated in terms of pci_resource_start() terms */
@@ -228,7 +228,9 @@ enum {
228 MV_HP_ERRATA_50XXB2 = (1 << 2), 228 MV_HP_ERRATA_50XXB2 = (1 << 2),
229 MV_HP_ERRATA_60X1B2 = (1 << 3), 229 MV_HP_ERRATA_60X1B2 = (1 << 3),
230 MV_HP_ERRATA_60X1C0 = (1 << 4), 230 MV_HP_ERRATA_60X1C0 = (1 << 4),
231 MV_HP_50XX = (1 << 5), 231 MV_HP_ERRATA_XX42A0 = (1 << 5),
232 MV_HP_50XX = (1 << 6),
233 MV_HP_GEN_IIE = (1 << 7),
232 234
233 /* Port private flags (pp_flags) */ 235 /* Port private flags (pp_flags) */
234 MV_PP_FLAG_EDMA_EN = (1 << 0), 236 MV_PP_FLAG_EDMA_EN = (1 << 0),
@@ -237,6 +239,9 @@ enum {
237 239
238#define IS_50XX(hpriv) ((hpriv)->hp_flags & MV_HP_50XX) 240#define IS_50XX(hpriv) ((hpriv)->hp_flags & MV_HP_50XX)
239#define IS_60XX(hpriv) (((hpriv)->hp_flags & MV_HP_50XX) == 0) 241#define IS_60XX(hpriv) (((hpriv)->hp_flags & MV_HP_50XX) == 0)
242#define IS_GEN_I(hpriv) IS_50XX(hpriv)
243#define IS_GEN_II(hpriv) IS_60XX(hpriv)
244#define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE)
240 245
241enum { 246enum {
242 /* Our DMA boundary is determined by an ePRD being unable to handle 247 /* Our DMA boundary is determined by an ePRD being unable to handle
@@ -255,6 +260,8 @@ enum chip_type {
255 chip_5080, 260 chip_5080,
256 chip_604x, 261 chip_604x,
257 chip_608x, 262 chip_608x,
263 chip_6042,
264 chip_7042,
258}; 265};
259 266
260/* Command ReQuest Block: 32B */ 267/* Command ReQuest Block: 32B */
@@ -265,6 +272,14 @@ struct mv_crqb {
265 u16 ata_cmd[11]; 272 u16 ata_cmd[11];
266}; 273};
267 274
275struct mv_crqb_iie {
276 u32 addr;
277 u32 addr_hi;
278 u32 flags;
279 u32 len;
280 u32 ata_cmd[4];
281};
282
268/* Command ResPonse Block: 8B */ 283/* Command ResPonse Block: 8B */
269struct mv_crpb { 284struct mv_crpb {
270 u16 id; 285 u16 id;
@@ -328,7 +343,8 @@ static void mv_host_stop(struct ata_host_set *host_set);
328static int mv_port_start(struct ata_port *ap); 343static int mv_port_start(struct ata_port *ap);
329static void mv_port_stop(struct ata_port *ap); 344static void mv_port_stop(struct ata_port *ap);
330static void mv_qc_prep(struct ata_queued_cmd *qc); 345static void mv_qc_prep(struct ata_queued_cmd *qc);
331static int mv_qc_issue(struct ata_queued_cmd *qc); 346static void mv_qc_prep_iie(struct ata_queued_cmd *qc);
347static unsigned int mv_qc_issue(struct ata_queued_cmd *qc);
332static irqreturn_t mv_interrupt(int irq, void *dev_instance, 348static irqreturn_t mv_interrupt(int irq, void *dev_instance,
333 struct pt_regs *regs); 349 struct pt_regs *regs);
334static void mv_eng_timeout(struct ata_port *ap); 350static void mv_eng_timeout(struct ata_port *ap);
@@ -362,11 +378,11 @@ static struct scsi_host_template mv_sht = {
362 .name = DRV_NAME, 378 .name = DRV_NAME,
363 .ioctl = ata_scsi_ioctl, 379 .ioctl = ata_scsi_ioctl,
364 .queuecommand = ata_scsi_queuecmd, 380 .queuecommand = ata_scsi_queuecmd,
381 .eh_timed_out = ata_scsi_timed_out,
365 .eh_strategy_handler = ata_scsi_error, 382 .eh_strategy_handler = ata_scsi_error,
366 .can_queue = MV_USE_Q_DEPTH, 383 .can_queue = MV_USE_Q_DEPTH,
367 .this_id = ATA_SHT_THIS_ID, 384 .this_id = ATA_SHT_THIS_ID,
368 .sg_tablesize = MV_MAX_SG_CT / 2, 385 .sg_tablesize = MV_MAX_SG_CT / 2,
369 .max_sectors = ATA_MAX_SECTORS,
370 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 386 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
371 .emulated = ATA_SHT_EMULATED, 387 .emulated = ATA_SHT_EMULATED,
372 .use_clustering = ATA_SHT_USE_CLUSTERING, 388 .use_clustering = ATA_SHT_USE_CLUSTERING,
@@ -430,6 +446,33 @@ static const struct ata_port_operations mv6_ops = {
430 .host_stop = mv_host_stop, 446 .host_stop = mv_host_stop,
431}; 447};
432 448
449static const struct ata_port_operations mv_iie_ops = {
450 .port_disable = ata_port_disable,
451
452 .tf_load = ata_tf_load,
453 .tf_read = ata_tf_read,
454 .check_status = ata_check_status,
455 .exec_command = ata_exec_command,
456 .dev_select = ata_std_dev_select,
457
458 .phy_reset = mv_phy_reset,
459
460 .qc_prep = mv_qc_prep_iie,
461 .qc_issue = mv_qc_issue,
462
463 .eng_timeout = mv_eng_timeout,
464
465 .irq_handler = mv_interrupt,
466 .irq_clear = mv_irq_clear,
467
468 .scr_read = mv_scr_read,
469 .scr_write = mv_scr_write,
470
471 .port_start = mv_port_start,
472 .port_stop = mv_port_stop,
473 .host_stop = mv_host_stop,
474};
475
433static const struct ata_port_info mv_port_info[] = { 476static const struct ata_port_info mv_port_info[] = {
434 { /* chip_504x */ 477 { /* chip_504x */
435 .sht = &mv_sht, 478 .sht = &mv_sht,
@@ -467,6 +510,21 @@ static const struct ata_port_info mv_port_info[] = {
467 .udma_mask = 0x7f, /* udma0-6 */ 510 .udma_mask = 0x7f, /* udma0-6 */
468 .port_ops = &mv6_ops, 511 .port_ops = &mv6_ops,
469 }, 512 },
513 { /* chip_6042 */
514 .sht = &mv_sht,
515 .host_flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS),
516 .pio_mask = 0x1f, /* pio0-4 */
517 .udma_mask = 0x7f, /* udma0-6 */
518 .port_ops = &mv_iie_ops,
519 },
520 { /* chip_7042 */
521 .sht = &mv_sht,
522 .host_flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS |
523 MV_FLAG_DUAL_HC),
524 .pio_mask = 0x1f, /* pio0-4 */
525 .udma_mask = 0x7f, /* udma0-6 */
526 .port_ops = &mv_iie_ops,
527 },
470}; 528};
471 529
472static const struct pci_device_id mv_pci_tbl[] = { 530static const struct pci_device_id mv_pci_tbl[] = {
@@ -477,6 +535,7 @@ static const struct pci_device_id mv_pci_tbl[] = {
477 535
478 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6040), 0, 0, chip_604x}, 536 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6040), 0, 0, chip_604x},
479 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6041), 0, 0, chip_604x}, 537 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6041), 0, 0, chip_604x},
538 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6042), 0, 0, chip_6042},
480 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6080), 0, 0, chip_608x}, 539 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6080), 0, 0, chip_608x},
481 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6081), 0, 0, chip_608x}, 540 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6081), 0, 0, chip_608x},
482 541
@@ -572,8 +631,8 @@ static void mv_irq_clear(struct ata_port *ap)
572 * @base: port base address 631 * @base: port base address
573 * @pp: port private data 632 * @pp: port private data
574 * 633 *
575 * Verify the local cache of the eDMA state is accurate with an 634 * Verify the local cache of the eDMA state is accurate with a
576 * assert. 635 * WARN_ON.
577 * 636 *
578 * LOCKING: 637 * LOCKING:
579 * Inherited from caller. 638 * Inherited from caller.
@@ -584,15 +643,15 @@ static void mv_start_dma(void __iomem *base, struct mv_port_priv *pp)
584 writelfl(EDMA_EN, base + EDMA_CMD_OFS); 643 writelfl(EDMA_EN, base + EDMA_CMD_OFS);
585 pp->pp_flags |= MV_PP_FLAG_EDMA_EN; 644 pp->pp_flags |= MV_PP_FLAG_EDMA_EN;
586 } 645 }
587 assert(EDMA_EN & readl(base + EDMA_CMD_OFS)); 646 WARN_ON(!(EDMA_EN & readl(base + EDMA_CMD_OFS)));
588} 647}
589 648
590/** 649/**
591 * mv_stop_dma - Disable eDMA engine 650 * mv_stop_dma - Disable eDMA engine
592 * @ap: ATA channel to manipulate 651 * @ap: ATA channel to manipulate
593 * 652 *
594 * Verify the local cache of the eDMA state is accurate with an 653 * Verify the local cache of the eDMA state is accurate with a
595 * assert. 654 * WARN_ON.
596 * 655 *
597 * LOCKING: 656 * LOCKING:
598 * Inherited from caller. 657 * Inherited from caller.
@@ -610,7 +669,7 @@ static void mv_stop_dma(struct ata_port *ap)
610 writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); 669 writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS);
611 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 670 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
612 } else { 671 } else {
613 assert(!(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS))); 672 WARN_ON(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS));
614 } 673 }
615 674
616 /* now properly wait for the eDMA to stop */ 675 /* now properly wait for the eDMA to stop */
@@ -773,6 +832,33 @@ static inline void mv_priv_free(struct mv_port_priv *pp, struct device *dev)
773 dma_free_coherent(dev, MV_PORT_PRIV_DMA_SZ, pp->crpb, pp->crpb_dma); 832 dma_free_coherent(dev, MV_PORT_PRIV_DMA_SZ, pp->crpb, pp->crpb_dma);
774} 833}
775 834
835static void mv_edma_cfg(struct mv_host_priv *hpriv, void __iomem *port_mmio)
836{
837 u32 cfg = readl(port_mmio + EDMA_CFG_OFS);
838
839 /* set up non-NCQ EDMA configuration */
840 cfg &= ~0x1f; /* clear queue depth */
841 cfg &= ~EDMA_CFG_NCQ; /* clear NCQ mode */
842 cfg &= ~(1 << 9); /* disable equeue */
843
844 if (IS_GEN_I(hpriv))
845 cfg |= (1 << 8); /* enab config burst size mask */
846
847 else if (IS_GEN_II(hpriv))
848 cfg |= EDMA_CFG_RD_BRST_EXT | EDMA_CFG_WR_BUFF_LEN;
849
850 else if (IS_GEN_IIE(hpriv)) {
851 cfg |= (1 << 23); /* dis RX PM port mask */
852 cfg &= ~(1 << 16); /* dis FIS-based switching (for now) */
853 cfg &= ~(1 << 19); /* dis 128-entry queue (for now?) */
854 cfg |= (1 << 18); /* enab early completion */
855 cfg |= (1 << 17); /* enab host q cache */
856 cfg |= (1 << 22); /* enab cutthrough */
857 }
858
859 writelfl(cfg, port_mmio + EDMA_CFG_OFS);
860}
861
776/** 862/**
777 * mv_port_start - Port specific init/start routine. 863 * mv_port_start - Port specific init/start routine.
778 * @ap: ATA channel to manipulate 864 * @ap: ATA channel to manipulate
@@ -786,6 +872,7 @@ static inline void mv_priv_free(struct mv_port_priv *pp, struct device *dev)
786static int mv_port_start(struct ata_port *ap) 872static int mv_port_start(struct ata_port *ap)
787{ 873{
788 struct device *dev = ap->host_set->dev; 874 struct device *dev = ap->host_set->dev;
875 struct mv_host_priv *hpriv = ap->host_set->private_data;
789 struct mv_port_priv *pp; 876 struct mv_port_priv *pp;
790 void __iomem *port_mmio = mv_ap_base(ap); 877 void __iomem *port_mmio = mv_ap_base(ap);
791 void *mem; 878 void *mem;
@@ -829,17 +916,26 @@ static int mv_port_start(struct ata_port *ap)
829 pp->sg_tbl = mem; 916 pp->sg_tbl = mem;
830 pp->sg_tbl_dma = mem_dma; 917 pp->sg_tbl_dma = mem_dma;
831 918
832 writelfl(EDMA_CFG_Q_DEPTH | EDMA_CFG_RD_BRST_EXT | 919 mv_edma_cfg(hpriv, port_mmio);
833 EDMA_CFG_WR_BUFF_LEN, port_mmio + EDMA_CFG_OFS);
834 920
835 writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS); 921 writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS);
836 writelfl(pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK, 922 writelfl(pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK,
837 port_mmio + EDMA_REQ_Q_IN_PTR_OFS); 923 port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
838 924
839 writelfl(0, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); 925 if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0)
840 writelfl(0, port_mmio + EDMA_RSP_Q_IN_PTR_OFS); 926 writelfl(pp->crqb_dma & 0xffffffff,
927 port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
928 else
929 writelfl(0, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
841 930
842 writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS); 931 writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS);
932
933 if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0)
934 writelfl(pp->crpb_dma & 0xffffffff,
935 port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
936 else
937 writelfl(0, port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
938
843 writelfl(pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK, 939 writelfl(pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK,
844 port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); 940 port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
845 941
@@ -960,21 +1056,19 @@ static void mv_qc_prep(struct ata_queued_cmd *qc)
960 struct ata_taskfile *tf; 1056 struct ata_taskfile *tf;
961 u16 flags = 0; 1057 u16 flags = 0;
962 1058
963 if (ATA_PROT_DMA != qc->tf.protocol) { 1059 if (ATA_PROT_DMA != qc->tf.protocol)
964 return; 1060 return;
965 }
966 1061
967 /* the req producer index should be the same as we remember it */ 1062 /* the req producer index should be the same as we remember it */
968 assert(((readl(mv_ap_base(qc->ap) + EDMA_REQ_Q_IN_PTR_OFS) >> 1063 WARN_ON(((readl(mv_ap_base(qc->ap) + EDMA_REQ_Q_IN_PTR_OFS) >>
969 EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) == 1064 EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) !=
970 pp->req_producer); 1065 pp->req_producer);
971 1066
972 /* Fill in command request block 1067 /* Fill in command request block
973 */ 1068 */
974 if (!(qc->tf.flags & ATA_TFLAG_WRITE)) { 1069 if (!(qc->tf.flags & ATA_TFLAG_WRITE))
975 flags |= CRQB_FLAG_READ; 1070 flags |= CRQB_FLAG_READ;
976 } 1071 WARN_ON(MV_MAX_Q_DEPTH <= qc->tag);
977 assert(MV_MAX_Q_DEPTH > qc->tag);
978 flags |= qc->tag << CRQB_TAG_SHIFT; 1072 flags |= qc->tag << CRQB_TAG_SHIFT;
979 1073
980 pp->crqb[pp->req_producer].sg_addr = 1074 pp->crqb[pp->req_producer].sg_addr =
@@ -1029,9 +1123,76 @@ static void mv_qc_prep(struct ata_queued_cmd *qc)
1029 mv_crqb_pack_cmd(cw++, tf->device, ATA_REG_DEVICE, 0); 1123 mv_crqb_pack_cmd(cw++, tf->device, ATA_REG_DEVICE, 0);
1030 mv_crqb_pack_cmd(cw++, tf->command, ATA_REG_CMD, 1); /* last */ 1124 mv_crqb_pack_cmd(cw++, tf->command, ATA_REG_CMD, 1); /* last */
1031 1125
1032 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) { 1126 if (!(qc->flags & ATA_QCFLAG_DMAMAP))
1127 return;
1128 mv_fill_sg(qc);
1129}
1130
1131/**
1132 * mv_qc_prep_iie - Host specific command preparation.
1133 * @qc: queued command to prepare
1134 *
1135 * This routine simply redirects to the general purpose routine
1136 * if command is not DMA. Else, it handles prep of the CRQB
1137 * (command request block), does some sanity checking, and calls
1138 * the SG load routine.
1139 *
1140 * LOCKING:
1141 * Inherited from caller.
1142 */
1143static void mv_qc_prep_iie(struct ata_queued_cmd *qc)
1144{
1145 struct ata_port *ap = qc->ap;
1146 struct mv_port_priv *pp = ap->private_data;
1147 struct mv_crqb_iie *crqb;
1148 struct ata_taskfile *tf;
1149 u32 flags = 0;
1150
1151 if (ATA_PROT_DMA != qc->tf.protocol)
1152 return;
1153
1154 /* the req producer index should be the same as we remember it */
1155 WARN_ON(((readl(mv_ap_base(qc->ap) + EDMA_REQ_Q_IN_PTR_OFS) >>
1156 EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) !=
1157 pp->req_producer);
1158
1159 /* Fill in Gen IIE command request block
1160 */
1161 if (!(qc->tf.flags & ATA_TFLAG_WRITE))
1162 flags |= CRQB_FLAG_READ;
1163
1164 WARN_ON(MV_MAX_Q_DEPTH <= qc->tag);
1165 flags |= qc->tag << CRQB_TAG_SHIFT;
1166
1167 crqb = (struct mv_crqb_iie *) &pp->crqb[pp->req_producer];
1168 crqb->addr = cpu_to_le32(pp->sg_tbl_dma & 0xffffffff);
1169 crqb->addr_hi = cpu_to_le32((pp->sg_tbl_dma >> 16) >> 16);
1170 crqb->flags = cpu_to_le32(flags);
1171
1172 tf = &qc->tf;
1173 crqb->ata_cmd[0] = cpu_to_le32(
1174 (tf->command << 16) |
1175 (tf->feature << 24)
1176 );
1177 crqb->ata_cmd[1] = cpu_to_le32(
1178 (tf->lbal << 0) |
1179 (tf->lbam << 8) |
1180 (tf->lbah << 16) |
1181 (tf->device << 24)
1182 );
1183 crqb->ata_cmd[2] = cpu_to_le32(
1184 (tf->hob_lbal << 0) |
1185 (tf->hob_lbam << 8) |
1186 (tf->hob_lbah << 16) |
1187 (tf->hob_feature << 24)
1188 );
1189 crqb->ata_cmd[3] = cpu_to_le32(
1190 (tf->nsect << 0) |
1191 (tf->hob_nsect << 8)
1192 );
1193
1194 if (!(qc->flags & ATA_QCFLAG_DMAMAP))
1033 return; 1195 return;
1034 }
1035 mv_fill_sg(qc); 1196 mv_fill_sg(qc);
1036} 1197}
1037 1198
@@ -1047,7 +1208,7 @@ static void mv_qc_prep(struct ata_queued_cmd *qc)
1047 * LOCKING: 1208 * LOCKING:
1048 * Inherited from caller. 1209 * Inherited from caller.
1049 */ 1210 */
1050static int mv_qc_issue(struct ata_queued_cmd *qc) 1211static unsigned int mv_qc_issue(struct ata_queued_cmd *qc)
1051{ 1212{
1052 void __iomem *port_mmio = mv_ap_base(qc->ap); 1213 void __iomem *port_mmio = mv_ap_base(qc->ap);
1053 struct mv_port_priv *pp = qc->ap->private_data; 1214 struct mv_port_priv *pp = qc->ap->private_data;
@@ -1065,12 +1226,12 @@ static int mv_qc_issue(struct ata_queued_cmd *qc)
1065 in_ptr = readl(port_mmio + EDMA_REQ_Q_IN_PTR_OFS); 1226 in_ptr = readl(port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
1066 1227
1067 /* the req producer index should be the same as we remember it */ 1228 /* the req producer index should be the same as we remember it */
1068 assert(((in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) == 1229 WARN_ON(((in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) !=
1069 pp->req_producer); 1230 pp->req_producer);
1070 /* until we do queuing, the queue should be empty at this point */ 1231 /* until we do queuing, the queue should be empty at this point */
1071 assert(((in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) == 1232 WARN_ON(((in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) !=
1072 ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS) >> 1233 ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS) >>
1073 EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK)); 1234 EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK));
1074 1235
1075 mv_inc_q_index(&pp->req_producer); /* now incr producer index */ 1236 mv_inc_q_index(&pp->req_producer); /* now incr producer index */
1076 1237
@@ -1090,7 +1251,7 @@ static int mv_qc_issue(struct ata_queued_cmd *qc)
1090 * 1251 *
1091 * This routine is for use when the port is in DMA mode, when it 1252 * This routine is for use when the port is in DMA mode, when it
1092 * will be using the CRPB (command response block) method of 1253 * will be using the CRPB (command response block) method of
1093 * returning command completion information. We assert indices 1254 * returning command completion information. We check indices
1094 * are good, grab status, and bump the response consumer index to 1255 * are good, grab status, and bump the response consumer index to
1095 * prove that we're up to date. 1256 * prove that we're up to date.
1096 * 1257 *
@@ -1106,16 +1267,16 @@ static u8 mv_get_crpb_status(struct ata_port *ap)
1106 out_ptr = readl(port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); 1267 out_ptr = readl(port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
1107 1268
1108 /* the response consumer index should be the same as we remember it */ 1269 /* the response consumer index should be the same as we remember it */
1109 assert(((out_ptr >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) == 1270 WARN_ON(((out_ptr >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) !=
1110 pp->rsp_consumer); 1271 pp->rsp_consumer);
1111 1272
1112 /* increment our consumer index... */ 1273 /* increment our consumer index... */
1113 pp->rsp_consumer = mv_inc_q_index(&pp->rsp_consumer); 1274 pp->rsp_consumer = mv_inc_q_index(&pp->rsp_consumer);
1114 1275
1115 /* and, until we do NCQ, there should only be 1 CRPB waiting */ 1276 /* and, until we do NCQ, there should only be 1 CRPB waiting */
1116 assert(((readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) >> 1277 WARN_ON(((readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) >>
1117 EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) == 1278 EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) !=
1118 pp->rsp_consumer); 1279 pp->rsp_consumer);
1119 1280
1120 /* write out our inc'd consumer index so EDMA knows we're caught up */ 1281 /* write out our inc'd consumer index so EDMA knows we're caught up */
1121 out_ptr &= EDMA_RSP_Q_BASE_LO_MASK; 1282 out_ptr &= EDMA_RSP_Q_BASE_LO_MASK;
@@ -1192,7 +1353,6 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1192 u32 hc_irq_cause; 1353 u32 hc_irq_cause;
1193 int shift, port, port0, hard_port, handled; 1354 int shift, port, port0, hard_port, handled;
1194 unsigned int err_mask; 1355 unsigned int err_mask;
1195 u8 ata_status = 0;
1196 1356
1197 if (hc == 0) { 1357 if (hc == 0) {
1198 port0 = 0; 1358 port0 = 0;
@@ -1210,6 +1370,7 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1210 hc,relevant,hc_irq_cause); 1370 hc,relevant,hc_irq_cause);
1211 1371
1212 for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) { 1372 for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) {
1373 u8 ata_status = 0;
1213 ap = host_set->ports[port]; 1374 ap = host_set->ports[port];
1214 hard_port = port & MV_PORT_MASK; /* range 0-3 */ 1375 hard_port = port & MV_PORT_MASK; /* range 0-3 */
1215 handled = 0; /* ensure ata_status is set if handled++ */ 1376 handled = 0; /* ensure ata_status is set if handled++ */
@@ -1681,6 +1842,12 @@ static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
1681 m2 |= hpriv->signal[port].pre; 1842 m2 |= hpriv->signal[port].pre;
1682 m2 &= ~(1 << 16); 1843 m2 &= ~(1 << 16);
1683 1844
1845 /* according to mvSata 3.6.1, some IIE values are fixed */
1846 if (IS_GEN_IIE(hpriv)) {
1847 m2 &= ~0xC30FF01F;
1848 m2 |= 0x0000900F;
1849 }
1850
1684 writel(m2, port_mmio + PHY_MODE2); 1851 writel(m2, port_mmio + PHY_MODE2);
1685} 1852}
1686 1853
@@ -1846,7 +2013,6 @@ static void mv_phy_reset(struct ata_port *ap)
1846static void mv_eng_timeout(struct ata_port *ap) 2013static void mv_eng_timeout(struct ata_port *ap)
1847{ 2014{
1848 struct ata_queued_cmd *qc; 2015 struct ata_queued_cmd *qc;
1849 unsigned long flags;
1850 2016
1851 printk(KERN_ERR "ata%u: Entering mv_eng_timeout\n",ap->id); 2017 printk(KERN_ERR "ata%u: Entering mv_eng_timeout\n",ap->id);
1852 DPRINTK("All regs @ start of eng_timeout\n"); 2018 DPRINTK("All regs @ start of eng_timeout\n");
@@ -1861,22 +2027,8 @@ static void mv_eng_timeout(struct ata_port *ap)
1861 mv_err_intr(ap); 2027 mv_err_intr(ap);
1862 mv_stop_and_reset(ap); 2028 mv_stop_and_reset(ap);
1863 2029
1864 if (!qc) { 2030 qc->err_mask |= AC_ERR_TIMEOUT;
1865 printk(KERN_ERR "ata%u: BUG: timeout without command\n", 2031 ata_eh_qc_complete(qc);
1866 ap->id);
1867 } else {
1868 /* hack alert! We cannot use the supplied completion
1869 * function from inside the ->eh_strategy_handler() thread.
1870 * libata is the only user of ->eh_strategy_handler() in
1871 * any kernel, so the default scsi_done() assumes it is
1872 * not being called from the SCSI EH.
1873 */
1874 spin_lock_irqsave(&ap->host_set->lock, flags);
1875 qc->scsidone = scsi_finish_command;
1876 qc->err_mask |= AC_ERR_OTHER;
1877 ata_qc_complete(qc);
1878 spin_unlock_irqrestore(&ap->host_set->lock, flags);
1879 }
1880} 2032}
1881 2033
1882/** 2034/**
@@ -1995,6 +2147,27 @@ static int mv_chip_id(struct pci_dev *pdev, struct mv_host_priv *hpriv,
1995 } 2147 }
1996 break; 2148 break;
1997 2149
2150 case chip_7042:
2151 case chip_6042:
2152 hpriv->ops = &mv6xxx_ops;
2153
2154 hp_flags |= MV_HP_GEN_IIE;
2155
2156 switch (rev_id) {
2157 case 0x0:
2158 hp_flags |= MV_HP_ERRATA_XX42A0;
2159 break;
2160 case 0x1:
2161 hp_flags |= MV_HP_ERRATA_60X1C0;
2162 break;
2163 default:
2164 dev_printk(KERN_WARNING, &pdev->dev,
2165 "Applying 60X1C0 workarounds to unknown rev\n");
2166 hp_flags |= MV_HP_ERRATA_60X1C0;
2167 break;
2168 }
2169 break;
2170
1998 default: 2171 default:
1999 printk(KERN_ERR DRV_NAME ": BUG: invalid board index %u\n", board_idx); 2172 printk(KERN_ERR DRV_NAME ": BUG: invalid board index %u\n", board_idx);
2000 return 1; 2173 return 1;
diff --git a/drivers/scsi/sata_nv.c b/drivers/scsi/sata_nv.c
index bbbb55eeb73a..caffadc2e0ae 100644
--- a/drivers/scsi/sata_nv.c
+++ b/drivers/scsi/sata_nv.c
@@ -229,11 +229,11 @@ static struct scsi_host_template nv_sht = {
229 .name = DRV_NAME, 229 .name = DRV_NAME,
230 .ioctl = ata_scsi_ioctl, 230 .ioctl = ata_scsi_ioctl,
231 .queuecommand = ata_scsi_queuecmd, 231 .queuecommand = ata_scsi_queuecmd,
232 .eh_timed_out = ata_scsi_timed_out,
232 .eh_strategy_handler = ata_scsi_error, 233 .eh_strategy_handler = ata_scsi_error,
233 .can_queue = ATA_DEF_QUEUE, 234 .can_queue = ATA_DEF_QUEUE,
234 .this_id = ATA_SHT_THIS_ID, 235 .this_id = ATA_SHT_THIS_ID,
235 .sg_tablesize = LIBATA_MAX_PRD, 236 .sg_tablesize = LIBATA_MAX_PRD,
236 .max_sectors = ATA_MAX_SECTORS,
237 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 237 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
238 .emulated = ATA_SHT_EMULATED, 238 .emulated = ATA_SHT_EMULATED,
239 .use_clustering = ATA_SHT_USE_CLUSTERING, 239 .use_clustering = ATA_SHT_USE_CLUSTERING,
diff --git a/drivers/scsi/sata_promise.c b/drivers/scsi/sata_promise.c
index b0b0a69b3563..84cb3940ad88 100644
--- a/drivers/scsi/sata_promise.c
+++ b/drivers/scsi/sata_promise.c
@@ -46,7 +46,7 @@
46#include "sata_promise.h" 46#include "sata_promise.h"
47 47
48#define DRV_NAME "sata_promise" 48#define DRV_NAME "sata_promise"
49#define DRV_VERSION "1.03" 49#define DRV_VERSION "1.04"
50 50
51 51
52enum { 52enum {
@@ -58,6 +58,7 @@ enum {
58 PDC_GLOBAL_CTL = 0x48, /* Global control/status (per port) */ 58 PDC_GLOBAL_CTL = 0x48, /* Global control/status (per port) */
59 PDC_CTLSTAT = 0x60, /* IDE control and status (per port) */ 59 PDC_CTLSTAT = 0x60, /* IDE control and status (per port) */
60 PDC_SATA_PLUG_CSR = 0x6C, /* SATA Plug control/status reg */ 60 PDC_SATA_PLUG_CSR = 0x6C, /* SATA Plug control/status reg */
61 PDC2_SATA_PLUG_CSR = 0x60, /* SATAII Plug control/status reg */
61 PDC_SLEW_CTL = 0x470, /* slew rate control reg */ 62 PDC_SLEW_CTL = 0x470, /* slew rate control reg */
62 63
63 PDC_ERR_MASK = (1<<19) | (1<<20) | (1<<21) | (1<<22) | 64 PDC_ERR_MASK = (1<<19) | (1<<20) | (1<<21) | (1<<22) |
@@ -67,8 +68,10 @@ enum {
67 board_20319 = 1, /* FastTrak S150 TX4 */ 68 board_20319 = 1, /* FastTrak S150 TX4 */
68 board_20619 = 2, /* FastTrak TX4000 */ 69 board_20619 = 2, /* FastTrak TX4000 */
69 board_20771 = 3, /* FastTrak TX2300 */ 70 board_20771 = 3, /* FastTrak TX2300 */
71 board_2057x = 4, /* SATAII150 Tx2plus */
72 board_40518 = 5, /* SATAII150 Tx4 */
70 73
71 PDC_HAS_PATA = (1 << 1), /* PDC20375 has PATA */ 74 PDC_HAS_PATA = (1 << 1), /* PDC20375/20575 has PATA */
72 75
73 PDC_RESET = (1 << 11), /* HDMA reset */ 76 PDC_RESET = (1 << 11), /* HDMA reset */
74 77
@@ -82,6 +85,10 @@ struct pdc_port_priv {
82 dma_addr_t pkt_dma; 85 dma_addr_t pkt_dma;
83}; 86};
84 87
88struct pdc_host_priv {
89 int hotplug_offset;
90};
91
85static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg); 92static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg);
86static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 93static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
87static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 94static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
@@ -95,7 +102,8 @@ static void pdc_qc_prep(struct ata_queued_cmd *qc);
95static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 102static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
96static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 103static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
97static void pdc_irq_clear(struct ata_port *ap); 104static void pdc_irq_clear(struct ata_port *ap);
98static int pdc_qc_issue_prot(struct ata_queued_cmd *qc); 105static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
106static void pdc_host_stop(struct ata_host_set *host_set);
99 107
100 108
101static struct scsi_host_template pdc_ata_sht = { 109static struct scsi_host_template pdc_ata_sht = {
@@ -103,11 +111,11 @@ static struct scsi_host_template pdc_ata_sht = {
103 .name = DRV_NAME, 111 .name = DRV_NAME,
104 .ioctl = ata_scsi_ioctl, 112 .ioctl = ata_scsi_ioctl,
105 .queuecommand = ata_scsi_queuecmd, 113 .queuecommand = ata_scsi_queuecmd,
114 .eh_timed_out = ata_scsi_timed_out,
106 .eh_strategy_handler = ata_scsi_error, 115 .eh_strategy_handler = ata_scsi_error,
107 .can_queue = ATA_DEF_QUEUE, 116 .can_queue = ATA_DEF_QUEUE,
108 .this_id = ATA_SHT_THIS_ID, 117 .this_id = ATA_SHT_THIS_ID,
109 .sg_tablesize = LIBATA_MAX_PRD, 118 .sg_tablesize = LIBATA_MAX_PRD,
110 .max_sectors = ATA_MAX_SECTORS,
111 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 119 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
112 .emulated = ATA_SHT_EMULATED, 120 .emulated = ATA_SHT_EMULATED,
113 .use_clustering = ATA_SHT_USE_CLUSTERING, 121 .use_clustering = ATA_SHT_USE_CLUSTERING,
@@ -137,7 +145,7 @@ static const struct ata_port_operations pdc_sata_ops = {
137 .scr_write = pdc_sata_scr_write, 145 .scr_write = pdc_sata_scr_write,
138 .port_start = pdc_port_start, 146 .port_start = pdc_port_start,
139 .port_stop = pdc_port_stop, 147 .port_stop = pdc_port_stop,
140 .host_stop = ata_pci_host_stop, 148 .host_stop = pdc_host_stop,
141}; 149};
142 150
143static const struct ata_port_operations pdc_pata_ops = { 151static const struct ata_port_operations pdc_pata_ops = {
@@ -158,7 +166,7 @@ static const struct ata_port_operations pdc_pata_ops = {
158 166
159 .port_start = pdc_port_start, 167 .port_start = pdc_port_start,
160 .port_stop = pdc_port_stop, 168 .port_stop = pdc_port_stop,
161 .host_stop = ata_pci_host_stop, 169 .host_stop = pdc_host_stop,
162}; 170};
163 171
164static const struct ata_port_info pdc_port_info[] = { 172static const struct ata_port_info pdc_port_info[] = {
@@ -201,6 +209,26 @@ static const struct ata_port_info pdc_port_info[] = {
201 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 209 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
202 .port_ops = &pdc_sata_ops, 210 .port_ops = &pdc_sata_ops,
203 }, 211 },
212
213 /* board_2057x */
214 {
215 .sht = &pdc_ata_sht,
216 .host_flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA,
217 .pio_mask = 0x1f, /* pio0-4 */
218 .mwdma_mask = 0x07, /* mwdma0-2 */
219 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
220 .port_ops = &pdc_sata_ops,
221 },
222
223 /* board_40518 */
224 {
225 .sht = &pdc_ata_sht,
226 .host_flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA,
227 .pio_mask = 0x1f, /* pio0-4 */
228 .mwdma_mask = 0x07, /* mwdma0-2 */
229 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
230 .port_ops = &pdc_sata_ops,
231 },
204}; 232};
205 233
206static const struct pci_device_id pdc_ata_pci_tbl[] = { 234static const struct pci_device_id pdc_ata_pci_tbl[] = {
@@ -217,9 +245,9 @@ static const struct pci_device_id pdc_ata_pci_tbl[] = {
217 { PCI_VENDOR_ID_PROMISE, 0x3376, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 245 { PCI_VENDOR_ID_PROMISE, 0x3376, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
218 board_2037x }, 246 board_2037x },
219 { PCI_VENDOR_ID_PROMISE, 0x3574, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 247 { PCI_VENDOR_ID_PROMISE, 0x3574, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
220 board_2037x }, 248 board_2057x },
221 { PCI_VENDOR_ID_PROMISE, 0x3d75, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 249 { PCI_VENDOR_ID_PROMISE, 0x3d75, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
222 board_2037x }, 250 board_2057x },
223 { PCI_VENDOR_ID_PROMISE, 0x3d73, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 251 { PCI_VENDOR_ID_PROMISE, 0x3d73, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
224 board_2037x }, 252 board_2037x },
225 253
@@ -227,12 +255,14 @@ static const struct pci_device_id pdc_ata_pci_tbl[] = {
227 board_20319 }, 255 board_20319 },
228 { PCI_VENDOR_ID_PROMISE, 0x3319, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 256 { PCI_VENDOR_ID_PROMISE, 0x3319, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
229 board_20319 }, 257 board_20319 },
258 { PCI_VENDOR_ID_PROMISE, 0x3515, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
259 board_20319 },
230 { PCI_VENDOR_ID_PROMISE, 0x3519, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 260 { PCI_VENDOR_ID_PROMISE, 0x3519, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
231 board_20319 }, 261 board_20319 },
232 { PCI_VENDOR_ID_PROMISE, 0x3d17, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 262 { PCI_VENDOR_ID_PROMISE, 0x3d17, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
233 board_20319 }, 263 board_20319 },
234 { PCI_VENDOR_ID_PROMISE, 0x3d18, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 264 { PCI_VENDOR_ID_PROMISE, 0x3d18, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
235 board_20319 }, 265 board_40518 },
236 266
237 { PCI_VENDOR_ID_PROMISE, 0x6629, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 267 { PCI_VENDOR_ID_PROMISE, 0x6629, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
238 board_20619 }, 268 board_20619 },
@@ -261,12 +291,11 @@ static int pdc_port_start(struct ata_port *ap)
261 if (rc) 291 if (rc)
262 return rc; 292 return rc;
263 293
264 pp = kmalloc(sizeof(*pp), GFP_KERNEL); 294 pp = kzalloc(sizeof(*pp), GFP_KERNEL);
265 if (!pp) { 295 if (!pp) {
266 rc = -ENOMEM; 296 rc = -ENOMEM;
267 goto err_out; 297 goto err_out;
268 } 298 }
269 memset(pp, 0, sizeof(*pp));
270 299
271 pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL); 300 pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
272 if (!pp->pkt) { 301 if (!pp->pkt) {
@@ -298,6 +327,16 @@ static void pdc_port_stop(struct ata_port *ap)
298} 327}
299 328
300 329
330static void pdc_host_stop(struct ata_host_set *host_set)
331{
332 struct pdc_host_priv *hp = host_set->private_data;
333
334 ata_pci_host_stop(host_set);
335
336 kfree(hp);
337}
338
339
301static void pdc_reset_port(struct ata_port *ap) 340static void pdc_reset_port(struct ata_port *ap)
302{ 341{
303 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT; 342 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT;
@@ -394,19 +433,6 @@ static void pdc_eng_timeout(struct ata_port *ap)
394 spin_lock_irqsave(&host_set->lock, flags); 433 spin_lock_irqsave(&host_set->lock, flags);
395 434
396 qc = ata_qc_from_tag(ap, ap->active_tag); 435 qc = ata_qc_from_tag(ap, ap->active_tag);
397 if (!qc) {
398 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
399 ap->id);
400 goto out;
401 }
402
403 /* hack alert! We cannot use the supplied completion
404 * function from inside the ->eh_strategy_handler() thread.
405 * libata is the only user of ->eh_strategy_handler() in
406 * any kernel, so the default scsi_done() assumes it is
407 * not being called from the SCSI EH.
408 */
409 qc->scsidone = scsi_finish_command;
410 436
411 switch (qc->tf.protocol) { 437 switch (qc->tf.protocol) {
412 case ATA_PROT_DMA: 438 case ATA_PROT_DMA:
@@ -414,7 +440,6 @@ static void pdc_eng_timeout(struct ata_port *ap)
414 printk(KERN_ERR "ata%u: command timeout\n", ap->id); 440 printk(KERN_ERR "ata%u: command timeout\n", ap->id);
415 drv_stat = ata_wait_idle(ap); 441 drv_stat = ata_wait_idle(ap);
416 qc->err_mask |= __ac_err_mask(drv_stat); 442 qc->err_mask |= __ac_err_mask(drv_stat);
417 ata_qc_complete(qc);
418 break; 443 break;
419 444
420 default: 445 default:
@@ -424,12 +449,11 @@ static void pdc_eng_timeout(struct ata_port *ap)
424 ap->id, qc->tf.command, drv_stat); 449 ap->id, qc->tf.command, drv_stat);
425 450
426 qc->err_mask |= ac_err_mask(drv_stat); 451 qc->err_mask |= ac_err_mask(drv_stat);
427 ata_qc_complete(qc);
428 break; 452 break;
429 } 453 }
430 454
431out:
432 spin_unlock_irqrestore(&host_set->lock, flags); 455 spin_unlock_irqrestore(&host_set->lock, flags);
456 ata_eh_qc_complete(qc);
433 DPRINTK("EXIT\n"); 457 DPRINTK("EXIT\n");
434} 458}
435 459
@@ -495,14 +519,15 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *r
495 VPRINTK("QUICK EXIT 2\n"); 519 VPRINTK("QUICK EXIT 2\n");
496 return IRQ_NONE; 520 return IRQ_NONE;
497 } 521 }
522
523 spin_lock(&host_set->lock);
524
498 mask &= 0xffff; /* only 16 tags possible */ 525 mask &= 0xffff; /* only 16 tags possible */
499 if (!mask) { 526 if (!mask) {
500 VPRINTK("QUICK EXIT 3\n"); 527 VPRINTK("QUICK EXIT 3\n");
501 return IRQ_NONE; 528 goto done_irq;
502 } 529 }
503 530
504 spin_lock(&host_set->lock);
505
506 writel(mask, mmio_base + PDC_INT_SEQMASK); 531 writel(mask, mmio_base + PDC_INT_SEQMASK);
507 532
508 for (i = 0; i < host_set->n_ports; i++) { 533 for (i = 0; i < host_set->n_ports; i++) {
@@ -519,10 +544,10 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *r
519 } 544 }
520 } 545 }
521 546
522 spin_unlock(&host_set->lock);
523
524 VPRINTK("EXIT\n"); 547 VPRINTK("EXIT\n");
525 548
549done_irq:
550 spin_unlock(&host_set->lock);
526 return IRQ_RETVAL(handled); 551 return IRQ_RETVAL(handled);
527} 552}
528 553
@@ -544,7 +569,7 @@ static inline void pdc_packet_start(struct ata_queued_cmd *qc)
544 readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */ 569 readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */
545} 570}
546 571
547static int pdc_qc_issue_prot(struct ata_queued_cmd *qc) 572static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
548{ 573{
549 switch (qc->tf.protocol) { 574 switch (qc->tf.protocol) {
550 case ATA_PROT_DMA: 575 case ATA_PROT_DMA:
@@ -600,6 +625,8 @@ static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base)
600static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe) 625static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
601{ 626{
602 void __iomem *mmio = pe->mmio_base; 627 void __iomem *mmio = pe->mmio_base;
628 struct pdc_host_priv *hp = pe->private_data;
629 int hotplug_offset = hp->hotplug_offset;
603 u32 tmp; 630 u32 tmp;
604 631
605 /* 632 /*
@@ -614,12 +641,12 @@ static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
614 writel(tmp, mmio + PDC_FLASH_CTL); 641 writel(tmp, mmio + PDC_FLASH_CTL);
615 642
616 /* clear plug/unplug flags for all ports */ 643 /* clear plug/unplug flags for all ports */
617 tmp = readl(mmio + PDC_SATA_PLUG_CSR); 644 tmp = readl(mmio + hotplug_offset);
618 writel(tmp | 0xff, mmio + PDC_SATA_PLUG_CSR); 645 writel(tmp | 0xff, mmio + hotplug_offset);
619 646
620 /* mask plug/unplug ints */ 647 /* mask plug/unplug ints */
621 tmp = readl(mmio + PDC_SATA_PLUG_CSR); 648 tmp = readl(mmio + hotplug_offset);
622 writel(tmp | 0xff0000, mmio + PDC_SATA_PLUG_CSR); 649 writel(tmp | 0xff0000, mmio + hotplug_offset);
623 650
624 /* reduce TBG clock to 133 Mhz. */ 651 /* reduce TBG clock to 133 Mhz. */
625 tmp = readl(mmio + PDC_TBG_MODE); 652 tmp = readl(mmio + PDC_TBG_MODE);
@@ -641,6 +668,7 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
641{ 668{
642 static int printed_version; 669 static int printed_version;
643 struct ata_probe_ent *probe_ent = NULL; 670 struct ata_probe_ent *probe_ent = NULL;
671 struct pdc_host_priv *hp;
644 unsigned long base; 672 unsigned long base;
645 void __iomem *mmio_base; 673 void __iomem *mmio_base;
646 unsigned int board_idx = (unsigned int) ent->driver_data; 674 unsigned int board_idx = (unsigned int) ent->driver_data;
@@ -671,13 +699,12 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
671 if (rc) 699 if (rc)
672 goto err_out_regions; 700 goto err_out_regions;
673 701
674 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 702 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
675 if (probe_ent == NULL) { 703 if (probe_ent == NULL) {
676 rc = -ENOMEM; 704 rc = -ENOMEM;
677 goto err_out_regions; 705 goto err_out_regions;
678 } 706 }
679 707
680 memset(probe_ent, 0, sizeof(*probe_ent));
681 probe_ent->dev = pci_dev_to_dev(pdev); 708 probe_ent->dev = pci_dev_to_dev(pdev);
682 INIT_LIST_HEAD(&probe_ent->node); 709 INIT_LIST_HEAD(&probe_ent->node);
683 710
@@ -688,6 +715,16 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
688 } 715 }
689 base = (unsigned long) mmio_base; 716 base = (unsigned long) mmio_base;
690 717
718 hp = kzalloc(sizeof(*hp), GFP_KERNEL);
719 if (hp == NULL) {
720 rc = -ENOMEM;
721 goto err_out_free_ent;
722 }
723
724 /* Set default hotplug offset */
725 hp->hotplug_offset = PDC_SATA_PLUG_CSR;
726 probe_ent->private_data = hp;
727
691 probe_ent->sht = pdc_port_info[board_idx].sht; 728 probe_ent->sht = pdc_port_info[board_idx].sht;
692 probe_ent->host_flags = pdc_port_info[board_idx].host_flags; 729 probe_ent->host_flags = pdc_port_info[board_idx].host_flags;
693 probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask; 730 probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask;
@@ -707,6 +744,10 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
707 744
708 /* notice 4-port boards */ 745 /* notice 4-port boards */
709 switch (board_idx) { 746 switch (board_idx) {
747 case board_40518:
748 /* Override hotplug offset for SATAII150 */
749 hp->hotplug_offset = PDC2_SATA_PLUG_CSR;
750 /* Fall through */
710 case board_20319: 751 case board_20319:
711 probe_ent->n_ports = 4; 752 probe_ent->n_ports = 4;
712 753
@@ -716,6 +757,10 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
716 probe_ent->port[2].scr_addr = base + 0x600; 757 probe_ent->port[2].scr_addr = base + 0x600;
717 probe_ent->port[3].scr_addr = base + 0x700; 758 probe_ent->port[3].scr_addr = base + 0x700;
718 break; 759 break;
760 case board_2057x:
761 /* Override hotplug offset for SATAII150 */
762 hp->hotplug_offset = PDC2_SATA_PLUG_CSR;
763 /* Fall through */
719 case board_2037x: 764 case board_2037x:
720 probe_ent->n_ports = 2; 765 probe_ent->n_ports = 2;
721 break; 766 break;
@@ -741,8 +786,10 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
741 /* initialize adapter */ 786 /* initialize adapter */
742 pdc_host_init(board_idx, probe_ent); 787 pdc_host_init(board_idx, probe_ent);
743 788
744 /* FIXME: check ata_device_add return value */ 789 /* FIXME: Need any other frees than hp? */
745 ata_device_add(probe_ent); 790 if (!ata_device_add(probe_ent))
791 kfree(hp);
792
746 kfree(probe_ent); 793 kfree(probe_ent);
747 794
748 return 0; 795 return 0;
diff --git a/drivers/scsi/sata_qstor.c b/drivers/scsi/sata_qstor.c
index 80480f0fb2b8..9602f43a298e 100644
--- a/drivers/scsi/sata_qstor.c
+++ b/drivers/scsi/sata_qstor.c
@@ -120,7 +120,7 @@ static void qs_host_stop(struct ata_host_set *host_set);
120static void qs_port_stop(struct ata_port *ap); 120static void qs_port_stop(struct ata_port *ap);
121static void qs_phy_reset(struct ata_port *ap); 121static void qs_phy_reset(struct ata_port *ap);
122static void qs_qc_prep(struct ata_queued_cmd *qc); 122static void qs_qc_prep(struct ata_queued_cmd *qc);
123static int qs_qc_issue(struct ata_queued_cmd *qc); 123static unsigned int qs_qc_issue(struct ata_queued_cmd *qc);
124static int qs_check_atapi_dma(struct ata_queued_cmd *qc); 124static int qs_check_atapi_dma(struct ata_queued_cmd *qc);
125static void qs_bmdma_stop(struct ata_queued_cmd *qc); 125static void qs_bmdma_stop(struct ata_queued_cmd *qc);
126static u8 qs_bmdma_status(struct ata_port *ap); 126static u8 qs_bmdma_status(struct ata_port *ap);
@@ -132,11 +132,11 @@ static struct scsi_host_template qs_ata_sht = {
132 .name = DRV_NAME, 132 .name = DRV_NAME,
133 .ioctl = ata_scsi_ioctl, 133 .ioctl = ata_scsi_ioctl,
134 .queuecommand = ata_scsi_queuecmd, 134 .queuecommand = ata_scsi_queuecmd,
135 .eh_timed_out = ata_scsi_timed_out,
135 .eh_strategy_handler = ata_scsi_error, 136 .eh_strategy_handler = ata_scsi_error,
136 .can_queue = ATA_DEF_QUEUE, 137 .can_queue = ATA_DEF_QUEUE,
137 .this_id = ATA_SHT_THIS_ID, 138 .this_id = ATA_SHT_THIS_ID,
138 .sg_tablesize = QS_MAX_PRD, 139 .sg_tablesize = QS_MAX_PRD,
139 .max_sectors = ATA_MAX_SECTORS,
140 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 140 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
141 .emulated = ATA_SHT_EMULATED, 141 .emulated = ATA_SHT_EMULATED,
142 //FIXME .use_clustering = ATA_SHT_USE_CLUSTERING, 142 //FIXME .use_clustering = ATA_SHT_USE_CLUSTERING,
@@ -276,8 +276,8 @@ static unsigned int qs_fill_sg(struct ata_queued_cmd *qc)
276 unsigned int nelem; 276 unsigned int nelem;
277 u8 *prd = pp->pkt + QS_CPB_BYTES; 277 u8 *prd = pp->pkt + QS_CPB_BYTES;
278 278
279 assert(qc->__sg != NULL); 279 WARN_ON(qc->__sg == NULL);
280 assert(qc->n_elem > 0 || qc->pad_len > 0); 280 WARN_ON(qc->n_elem == 0 && qc->pad_len == 0);
281 281
282 nelem = 0; 282 nelem = 0;
283 ata_for_each_sg(sg, qc) { 283 ata_for_each_sg(sg, qc) {
@@ -352,7 +352,7 @@ static inline void qs_packet_start(struct ata_queued_cmd *qc)
352 readl(chan + QS_CCT_CFF); /* flush */ 352 readl(chan + QS_CCT_CFF); /* flush */
353} 353}
354 354
355static int qs_qc_issue(struct ata_queued_cmd *qc) 355static unsigned int qs_qc_issue(struct ata_queued_cmd *qc)
356{ 356{
357 struct qs_port_priv *pp = qc->ap->private_data; 357 struct qs_port_priv *pp = qc->ap->private_data;
358 358
diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c
index 9face3c6aa21..4f2a67ed39d8 100644
--- a/drivers/scsi/sata_sil.c
+++ b/drivers/scsi/sata_sil.c
@@ -49,24 +49,30 @@
49#define DRV_VERSION "0.9" 49#define DRV_VERSION "0.9"
50 50
51enum { 51enum {
52 /*
53 * host flags
54 */
52 SIL_FLAG_RERR_ON_DMA_ACT = (1 << 29), 55 SIL_FLAG_RERR_ON_DMA_ACT = (1 << 29),
53 SIL_FLAG_MOD15WRITE = (1 << 30), 56 SIL_FLAG_MOD15WRITE = (1 << 30),
57 SIL_DFL_HOST_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
58 ATA_FLAG_MMIO,
54 59
60 /*
61 * Controller IDs
62 */
55 sil_3112 = 0, 63 sil_3112 = 0,
56 sil_3112_m15w = 1, 64 sil_3512 = 1,
57 sil_3512 = 2, 65 sil_3114 = 2,
58 sil_3114 = 3,
59
60 SIL_FIFO_R0 = 0x40,
61 SIL_FIFO_W0 = 0x41,
62 SIL_FIFO_R1 = 0x44,
63 SIL_FIFO_W1 = 0x45,
64 SIL_FIFO_R2 = 0x240,
65 SIL_FIFO_W2 = 0x241,
66 SIL_FIFO_R3 = 0x244,
67 SIL_FIFO_W3 = 0x245,
68 66
67 /*
68 * Register offsets
69 */
69 SIL_SYSCFG = 0x48, 70 SIL_SYSCFG = 0x48,
71
72 /*
73 * Register bits
74 */
75 /* SYSCFG */
70 SIL_MASK_IDE0_INT = (1 << 22), 76 SIL_MASK_IDE0_INT = (1 << 22),
71 SIL_MASK_IDE1_INT = (1 << 23), 77 SIL_MASK_IDE1_INT = (1 << 23),
72 SIL_MASK_IDE2_INT = (1 << 24), 78 SIL_MASK_IDE2_INT = (1 << 24),
@@ -75,9 +81,12 @@ enum {
75 SIL_MASK_4PORT = SIL_MASK_2PORT | 81 SIL_MASK_4PORT = SIL_MASK_2PORT |
76 SIL_MASK_IDE2_INT | SIL_MASK_IDE3_INT, 82 SIL_MASK_IDE2_INT | SIL_MASK_IDE3_INT,
77 83
78 SIL_IDE2_BMDMA = 0x200, 84 /* BMDMA/BMDMA2 */
79
80 SIL_INTR_STEERING = (1 << 1), 85 SIL_INTR_STEERING = (1 << 1),
86
87 /*
88 * Others
89 */
81 SIL_QUIRK_MOD15WRITE = (1 << 0), 90 SIL_QUIRK_MOD15WRITE = (1 << 0),
82 SIL_QUIRK_UDMA5MAX = (1 << 1), 91 SIL_QUIRK_UDMA5MAX = (1 << 1),
83}; 92};
@@ -90,13 +99,13 @@ static void sil_post_set_mode (struct ata_port *ap);
90 99
91 100
92static const struct pci_device_id sil_pci_tbl[] = { 101static const struct pci_device_id sil_pci_tbl[] = {
93 { 0x1095, 0x3112, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112_m15w }, 102 { 0x1095, 0x3112, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112 },
94 { 0x1095, 0x0240, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112_m15w }, 103 { 0x1095, 0x0240, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112 },
95 { 0x1095, 0x3512, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3512 }, 104 { 0x1095, 0x3512, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3512 },
96 { 0x1095, 0x3114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3114 }, 105 { 0x1095, 0x3114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3114 },
97 { 0x1002, 0x436e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112_m15w }, 106 { 0x1002, 0x436e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112 },
98 { 0x1002, 0x4379, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112_m15w }, 107 { 0x1002, 0x4379, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112 },
99 { 0x1002, 0x437a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112_m15w }, 108 { 0x1002, 0x437a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112 },
100 { } /* terminate list */ 109 { } /* terminate list */
101}; 110};
102 111
@@ -137,11 +146,11 @@ static struct scsi_host_template sil_sht = {
137 .name = DRV_NAME, 146 .name = DRV_NAME,
138 .ioctl = ata_scsi_ioctl, 147 .ioctl = ata_scsi_ioctl,
139 .queuecommand = ata_scsi_queuecmd, 148 .queuecommand = ata_scsi_queuecmd,
149 .eh_timed_out = ata_scsi_timed_out,
140 .eh_strategy_handler = ata_scsi_error, 150 .eh_strategy_handler = ata_scsi_error,
141 .can_queue = ATA_DEF_QUEUE, 151 .can_queue = ATA_DEF_QUEUE,
142 .this_id = ATA_SHT_THIS_ID, 152 .this_id = ATA_SHT_THIS_ID,
143 .sg_tablesize = LIBATA_MAX_PRD, 153 .sg_tablesize = LIBATA_MAX_PRD,
144 .max_sectors = ATA_MAX_SECTORS,
145 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 154 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
146 .emulated = ATA_SHT_EMULATED, 155 .emulated = ATA_SHT_EMULATED,
147 .use_clustering = ATA_SHT_USE_CLUSTERING, 156 .use_clustering = ATA_SHT_USE_CLUSTERING,
@@ -159,7 +168,7 @@ static const struct ata_port_operations sil_ops = {
159 .check_status = ata_check_status, 168 .check_status = ata_check_status,
160 .exec_command = ata_exec_command, 169 .exec_command = ata_exec_command,
161 .dev_select = ata_std_dev_select, 170 .dev_select = ata_std_dev_select,
162 .phy_reset = sata_phy_reset, 171 .probe_reset = ata_std_probe_reset,
163 .post_set_mode = sil_post_set_mode, 172 .post_set_mode = sil_post_set_mode,
164 .bmdma_setup = ata_bmdma_setup, 173 .bmdma_setup = ata_bmdma_setup,
165 .bmdma_start = ata_bmdma_start, 174 .bmdma_start = ata_bmdma_start,
@@ -181,19 +190,7 @@ static const struct ata_port_info sil_port_info[] = {
181 /* sil_3112 */ 190 /* sil_3112 */
182 { 191 {
183 .sht = &sil_sht, 192 .sht = &sil_sht,
184 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 193 .host_flags = SIL_DFL_HOST_FLAGS | SIL_FLAG_MOD15WRITE,
185 ATA_FLAG_SRST | ATA_FLAG_MMIO,
186 .pio_mask = 0x1f, /* pio0-4 */
187 .mwdma_mask = 0x07, /* mwdma0-2 */
188 .udma_mask = 0x3f, /* udma0-5 */
189 .port_ops = &sil_ops,
190 },
191 /* sil_3112_15w - keep it sync'd w/ sil_3112 */
192 {
193 .sht = &sil_sht,
194 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
195 ATA_FLAG_SRST | ATA_FLAG_MMIO |
196 SIL_FLAG_MOD15WRITE,
197 .pio_mask = 0x1f, /* pio0-4 */ 194 .pio_mask = 0x1f, /* pio0-4 */
198 .mwdma_mask = 0x07, /* mwdma0-2 */ 195 .mwdma_mask = 0x07, /* mwdma0-2 */
199 .udma_mask = 0x3f, /* udma0-5 */ 196 .udma_mask = 0x3f, /* udma0-5 */
@@ -202,9 +199,7 @@ static const struct ata_port_info sil_port_info[] = {
202 /* sil_3512 */ 199 /* sil_3512 */
203 { 200 {
204 .sht = &sil_sht, 201 .sht = &sil_sht,
205 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 202 .host_flags = SIL_DFL_HOST_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT,
206 ATA_FLAG_SRST | ATA_FLAG_MMIO |
207 SIL_FLAG_RERR_ON_DMA_ACT,
208 .pio_mask = 0x1f, /* pio0-4 */ 203 .pio_mask = 0x1f, /* pio0-4 */
209 .mwdma_mask = 0x07, /* mwdma0-2 */ 204 .mwdma_mask = 0x07, /* mwdma0-2 */
210 .udma_mask = 0x3f, /* udma0-5 */ 205 .udma_mask = 0x3f, /* udma0-5 */
@@ -213,9 +208,7 @@ static const struct ata_port_info sil_port_info[] = {
213 /* sil_3114 */ 208 /* sil_3114 */
214 { 209 {
215 .sht = &sil_sht, 210 .sht = &sil_sht,
216 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 211 .host_flags = SIL_DFL_HOST_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT,
217 ATA_FLAG_SRST | ATA_FLAG_MMIO |
218 SIL_FLAG_RERR_ON_DMA_ACT,
219 .pio_mask = 0x1f, /* pio0-4 */ 212 .pio_mask = 0x1f, /* pio0-4 */
220 .mwdma_mask = 0x07, /* mwdma0-2 */ 213 .mwdma_mask = 0x07, /* mwdma0-2 */
221 .udma_mask = 0x3f, /* udma0-5 */ 214 .udma_mask = 0x3f, /* udma0-5 */
@@ -229,16 +222,17 @@ static const struct {
229 unsigned long tf; /* ATA taskfile register block */ 222 unsigned long tf; /* ATA taskfile register block */
230 unsigned long ctl; /* ATA control/altstatus register block */ 223 unsigned long ctl; /* ATA control/altstatus register block */
231 unsigned long bmdma; /* DMA register block */ 224 unsigned long bmdma; /* DMA register block */
225 unsigned long fifo_cfg; /* FIFO Valid Byte Count and Control */
232 unsigned long scr; /* SATA control register block */ 226 unsigned long scr; /* SATA control register block */
233 unsigned long sien; /* SATA Interrupt Enable register */ 227 unsigned long sien; /* SATA Interrupt Enable register */
234 unsigned long xfer_mode;/* data transfer mode register */ 228 unsigned long xfer_mode;/* data transfer mode register */
235 unsigned long sfis_cfg; /* SATA FIS reception config register */ 229 unsigned long sfis_cfg; /* SATA FIS reception config register */
236} sil_port[] = { 230} sil_port[] = {
237 /* port 0 ... */ 231 /* port 0 ... */
238 { 0x80, 0x8A, 0x00, 0x100, 0x148, 0xb4, 0x14c }, 232 { 0x80, 0x8A, 0x00, 0x40, 0x100, 0x148, 0xb4, 0x14c },
239 { 0xC0, 0xCA, 0x08, 0x180, 0x1c8, 0xf4, 0x1cc }, 233 { 0xC0, 0xCA, 0x08, 0x44, 0x180, 0x1c8, 0xf4, 0x1cc },
240 { 0x280, 0x28A, 0x200, 0x300, 0x348, 0x2b4, 0x34c }, 234 { 0x280, 0x28A, 0x200, 0x240, 0x300, 0x348, 0x2b4, 0x34c },
241 { 0x2C0, 0x2CA, 0x208, 0x380, 0x3c8, 0x2f4, 0x3cc }, 235 { 0x2C0, 0x2CA, 0x208, 0x244, 0x380, 0x3c8, 0x2f4, 0x3cc },
242 /* ... port 3 */ 236 /* ... port 3 */
243}; 237};
244 238
@@ -354,22 +348,12 @@ static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
354static void sil_dev_config(struct ata_port *ap, struct ata_device *dev) 348static void sil_dev_config(struct ata_port *ap, struct ata_device *dev)
355{ 349{
356 unsigned int n, quirks = 0; 350 unsigned int n, quirks = 0;
357 unsigned char model_num[40]; 351 unsigned char model_num[41];
358 const char *s;
359 unsigned int len;
360 352
361 ata_dev_id_string(dev->id, model_num, ATA_ID_PROD_OFS, 353 ata_id_c_string(dev->id, model_num, ATA_ID_PROD_OFS, sizeof(model_num));
362 sizeof(model_num));
363 s = &model_num[0];
364 len = strnlen(s, sizeof(model_num));
365
366 /* ATAPI specifies that empty space is blank-filled; remove blanks */
367 while ((len > 0) && (s[len - 1] == ' '))
368 len--;
369 354
370 for (n = 0; sil_blacklist[n].product; n++) 355 for (n = 0; sil_blacklist[n].product; n++)
371 if (!memcmp(sil_blacklist[n].product, s, 356 if (!strcmp(sil_blacklist[n].product, model_num)) {
372 strlen(sil_blacklist[n].product))) {
373 quirks = sil_blacklist[n].quirk; 357 quirks = sil_blacklist[n].quirk;
374 break; 358 break;
375 } 359 }
@@ -380,16 +364,14 @@ static void sil_dev_config(struct ata_port *ap, struct ata_device *dev)
380 (quirks & SIL_QUIRK_MOD15WRITE))) { 364 (quirks & SIL_QUIRK_MOD15WRITE))) {
381 printk(KERN_INFO "ata%u(%u): applying Seagate errata fix (mod15write workaround)\n", 365 printk(KERN_INFO "ata%u(%u): applying Seagate errata fix (mod15write workaround)\n",
382 ap->id, dev->devno); 366 ap->id, dev->devno);
383 ap->host->max_sectors = 15; 367 dev->max_sectors = 15;
384 ap->host->hostt->max_sectors = 15;
385 dev->flags |= ATA_DFLAG_LOCK_SECTORS;
386 return; 368 return;
387 } 369 }
388 370
389 /* limit to udma5 */ 371 /* limit to udma5 */
390 if (quirks & SIL_QUIRK_UDMA5MAX) { 372 if (quirks & SIL_QUIRK_UDMA5MAX) {
391 printk(KERN_INFO "ata%u(%u): applying Maxtor errata fix %s\n", 373 printk(KERN_INFO "ata%u(%u): applying Maxtor errata fix %s\n",
392 ap->id, dev->devno, s); 374 ap->id, dev->devno, model_num);
393 ap->udma_mask &= ATA_UDMA5; 375 ap->udma_mask &= ATA_UDMA5;
394 return; 376 return;
395 } 377 }
@@ -431,13 +413,12 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
431 if (rc) 413 if (rc)
432 goto err_out_regions; 414 goto err_out_regions;
433 415
434 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 416 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
435 if (probe_ent == NULL) { 417 if (probe_ent == NULL) {
436 rc = -ENOMEM; 418 rc = -ENOMEM;
437 goto err_out_regions; 419 goto err_out_regions;
438 } 420 }
439 421
440 memset(probe_ent, 0, sizeof(*probe_ent));
441 INIT_LIST_HEAD(&probe_ent->node); 422 INIT_LIST_HEAD(&probe_ent->node);
442 probe_ent->dev = pci_dev_to_dev(pdev); 423 probe_ent->dev = pci_dev_to_dev(pdev);
443 probe_ent->port_ops = sil_port_info[ent->driver_data].port_ops; 424 probe_ent->port_ops = sil_port_info[ent->driver_data].port_ops;
@@ -474,19 +455,12 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
474 if (cls) { 455 if (cls) {
475 cls >>= 3; 456 cls >>= 3;
476 cls++; /* cls = (line_size/8)+1 */ 457 cls++; /* cls = (line_size/8)+1 */
477 writeb(cls, mmio_base + SIL_FIFO_R0); 458 for (i = 0; i < probe_ent->n_ports; i++)
478 writeb(cls, mmio_base + SIL_FIFO_W0); 459 writew(cls << 8 | cls,
479 writeb(cls, mmio_base + SIL_FIFO_R1); 460 mmio_base + sil_port[i].fifo_cfg);
480 writeb(cls, mmio_base + SIL_FIFO_W1);
481 if (ent->driver_data == sil_3114) {
482 writeb(cls, mmio_base + SIL_FIFO_R2);
483 writeb(cls, mmio_base + SIL_FIFO_W2);
484 writeb(cls, mmio_base + SIL_FIFO_R3);
485 writeb(cls, mmio_base + SIL_FIFO_W3);
486 }
487 } else 461 } else
488 dev_printk(KERN_WARNING, &pdev->dev, 462 dev_printk(KERN_WARNING, &pdev->dev,
489 "cache line size not set. Driver may not function\n"); 463 "cache line size not set. Driver may not function\n");
490 464
491 /* Apply R_ERR on DMA activate FIS errata workaround */ 465 /* Apply R_ERR on DMA activate FIS errata workaround */
492 if (probe_ent->host_flags & SIL_FLAG_RERR_ON_DMA_ACT) { 466 if (probe_ent->host_flags & SIL_FLAG_RERR_ON_DMA_ACT) {
@@ -509,10 +483,10 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
509 irq_mask = SIL_MASK_4PORT; 483 irq_mask = SIL_MASK_4PORT;
510 484
511 /* flip the magic "make 4 ports work" bit */ 485 /* flip the magic "make 4 ports work" bit */
512 tmp = readl(mmio_base + SIL_IDE2_BMDMA); 486 tmp = readl(mmio_base + sil_port[2].bmdma);
513 if ((tmp & SIL_INTR_STEERING) == 0) 487 if ((tmp & SIL_INTR_STEERING) == 0)
514 writel(tmp | SIL_INTR_STEERING, 488 writel(tmp | SIL_INTR_STEERING,
515 mmio_base + SIL_IDE2_BMDMA); 489 mmio_base + sil_port[2].bmdma);
516 490
517 } else { 491 } else {
518 irq_mask = SIL_MASK_2PORT; 492 irq_mask = SIL_MASK_2PORT;
diff --git a/drivers/scsi/sata_sil24.c b/drivers/scsi/sata_sil24.c
index 923130185a9e..9a53a5ed38c5 100644
--- a/drivers/scsi/sata_sil24.c
+++ b/drivers/scsi/sata_sil24.c
@@ -249,9 +249,9 @@ static u8 sil24_check_status(struct ata_port *ap);
249static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg); 249static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg);
250static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val); 250static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val);
251static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf); 251static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
252static void sil24_phy_reset(struct ata_port *ap); 252static int sil24_probe_reset(struct ata_port *ap, unsigned int *classes);
253static void sil24_qc_prep(struct ata_queued_cmd *qc); 253static void sil24_qc_prep(struct ata_queued_cmd *qc);
254static int sil24_qc_issue(struct ata_queued_cmd *qc); 254static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc);
255static void sil24_irq_clear(struct ata_port *ap); 255static void sil24_irq_clear(struct ata_port *ap);
256static void sil24_eng_timeout(struct ata_port *ap); 256static void sil24_eng_timeout(struct ata_port *ap);
257static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *regs); 257static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
@@ -262,6 +262,7 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
262 262
263static const struct pci_device_id sil24_pci_tbl[] = { 263static const struct pci_device_id sil24_pci_tbl[] = {
264 { 0x1095, 0x3124, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3124 }, 264 { 0x1095, 0x3124, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3124 },
265 { 0x8086, 0x3124, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3124 },
265 { 0x1095, 0x3132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3132 }, 266 { 0x1095, 0x3132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3132 },
266 { 0x1095, 0x3131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3131 }, 267 { 0x1095, 0x3131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3131 },
267 { 0x1095, 0x3531, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3131 }, 268 { 0x1095, 0x3531, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3131 },
@@ -280,11 +281,11 @@ static struct scsi_host_template sil24_sht = {
280 .name = DRV_NAME, 281 .name = DRV_NAME,
281 .ioctl = ata_scsi_ioctl, 282 .ioctl = ata_scsi_ioctl,
282 .queuecommand = ata_scsi_queuecmd, 283 .queuecommand = ata_scsi_queuecmd,
284 .eh_timed_out = ata_scsi_timed_out,
283 .eh_strategy_handler = ata_scsi_error, 285 .eh_strategy_handler = ata_scsi_error,
284 .can_queue = ATA_DEF_QUEUE, 286 .can_queue = ATA_DEF_QUEUE,
285 .this_id = ATA_SHT_THIS_ID, 287 .this_id = ATA_SHT_THIS_ID,
286 .sg_tablesize = LIBATA_MAX_PRD, 288 .sg_tablesize = LIBATA_MAX_PRD,
287 .max_sectors = ATA_MAX_SECTORS,
288 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 289 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
289 .emulated = ATA_SHT_EMULATED, 290 .emulated = ATA_SHT_EMULATED,
290 .use_clustering = ATA_SHT_USE_CLUSTERING, 291 .use_clustering = ATA_SHT_USE_CLUSTERING,
@@ -305,7 +306,7 @@ static const struct ata_port_operations sil24_ops = {
305 306
306 .tf_read = sil24_tf_read, 307 .tf_read = sil24_tf_read,
307 308
308 .phy_reset = sil24_phy_reset, 309 .probe_reset = sil24_probe_reset,
309 310
310 .qc_prep = sil24_qc_prep, 311 .qc_prep = sil24_qc_prep,
311 .qc_issue = sil24_qc_issue, 312 .qc_issue = sil24_qc_issue,
@@ -335,8 +336,8 @@ static struct ata_port_info sil24_port_info[] = {
335 { 336 {
336 .sht = &sil24_sht, 337 .sht = &sil24_sht,
337 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 338 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
338 ATA_FLAG_SRST | ATA_FLAG_MMIO | 339 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
339 ATA_FLAG_PIO_DMA | SIL24_NPORTS2FLAG(4), 340 SIL24_NPORTS2FLAG(4),
340 .pio_mask = 0x1f, /* pio0-4 */ 341 .pio_mask = 0x1f, /* pio0-4 */
341 .mwdma_mask = 0x07, /* mwdma0-2 */ 342 .mwdma_mask = 0x07, /* mwdma0-2 */
342 .udma_mask = 0x3f, /* udma0-5 */ 343 .udma_mask = 0x3f, /* udma0-5 */
@@ -346,8 +347,8 @@ static struct ata_port_info sil24_port_info[] = {
346 { 347 {
347 .sht = &sil24_sht, 348 .sht = &sil24_sht,
348 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 349 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
349 ATA_FLAG_SRST | ATA_FLAG_MMIO | 350 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
350 ATA_FLAG_PIO_DMA | SIL24_NPORTS2FLAG(2), 351 SIL24_NPORTS2FLAG(2),
351 .pio_mask = 0x1f, /* pio0-4 */ 352 .pio_mask = 0x1f, /* pio0-4 */
352 .mwdma_mask = 0x07, /* mwdma0-2 */ 353 .mwdma_mask = 0x07, /* mwdma0-2 */
353 .udma_mask = 0x3f, /* udma0-5 */ 354 .udma_mask = 0x3f, /* udma0-5 */
@@ -357,8 +358,8 @@ static struct ata_port_info sil24_port_info[] = {
357 { 358 {
358 .sht = &sil24_sht, 359 .sht = &sil24_sht,
359 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 360 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
360 ATA_FLAG_SRST | ATA_FLAG_MMIO | 361 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
361 ATA_FLAG_PIO_DMA | SIL24_NPORTS2FLAG(1), 362 SIL24_NPORTS2FLAG(1),
362 .pio_mask = 0x1f, /* pio0-4 */ 363 .pio_mask = 0x1f, /* pio0-4 */
363 .mwdma_mask = 0x07, /* mwdma0-2 */ 364 .mwdma_mask = 0x07, /* mwdma0-2 */
364 .udma_mask = 0x3f, /* udma0-5 */ 365 .udma_mask = 0x3f, /* udma0-5 */
@@ -370,7 +371,7 @@ static void sil24_dev_config(struct ata_port *ap, struct ata_device *dev)
370{ 371{
371 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 372 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
372 373
373 if (ap->cdb_len == 16) 374 if (dev->cdb_len == 16)
374 writel(PORT_CS_CDB16, port + PORT_CTRL_STAT); 375 writel(PORT_CS_CDB16, port + PORT_CTRL_STAT);
375 else 376 else
376 writel(PORT_CS_CDB16, port + PORT_CTRL_CLR); 377 writel(PORT_CS_CDB16, port + PORT_CTRL_CLR);
@@ -427,14 +428,23 @@ static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
427 *tf = pp->tf; 428 *tf = pp->tf;
428} 429}
429 430
430static int sil24_issue_SRST(struct ata_port *ap) 431static int sil24_softreset(struct ata_port *ap, int verbose,
432 unsigned int *class)
431{ 433{
432 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 434 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
433 struct sil24_port_priv *pp = ap->private_data; 435 struct sil24_port_priv *pp = ap->private_data;
434 struct sil24_prb *prb = &pp->cmd_block[0].ata.prb; 436 struct sil24_prb *prb = &pp->cmd_block[0].ata.prb;
435 dma_addr_t paddr = pp->cmd_block_dma; 437 dma_addr_t paddr = pp->cmd_block_dma;
438 unsigned long timeout = jiffies + ATA_TMOUT_BOOT * HZ;
436 u32 irq_enable, irq_stat; 439 u32 irq_enable, irq_stat;
437 int cnt; 440
441 DPRINTK("ENTER\n");
442
443 if (!sata_dev_present(ap)) {
444 DPRINTK("PHY reports no device\n");
445 *class = ATA_DEV_NONE;
446 goto out;
447 }
438 448
439 /* temporarily turn off IRQs during SRST */ 449 /* temporarily turn off IRQs during SRST */
440 irq_enable = readl(port + PORT_IRQ_ENABLE_SET); 450 irq_enable = readl(port + PORT_IRQ_ENABLE_SET);
@@ -451,7 +461,7 @@ static int sil24_issue_SRST(struct ata_port *ap)
451 461
452 writel((u32)paddr, port + PORT_CMD_ACTIVATE); 462 writel((u32)paddr, port + PORT_CMD_ACTIVATE);
453 463
454 for (cnt = 0; cnt < 100; cnt++) { 464 do {
455 irq_stat = readl(port + PORT_IRQ_STAT); 465 irq_stat = readl(port + PORT_IRQ_STAT);
456 writel(irq_stat, port + PORT_IRQ_STAT); /* clear irq */ 466 writel(irq_stat, port + PORT_IRQ_STAT); /* clear irq */
457 467
@@ -459,36 +469,42 @@ static int sil24_issue_SRST(struct ata_port *ap)
459 if (irq_stat & (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR)) 469 if (irq_stat & (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR))
460 break; 470 break;
461 471
462 msleep(1); 472 msleep(100);
463 } 473 } while (time_before(jiffies, timeout));
464 474
465 /* restore IRQs */ 475 /* restore IRQs */
466 writel(irq_enable, port + PORT_IRQ_ENABLE_SET); 476 writel(irq_enable, port + PORT_IRQ_ENABLE_SET);
467 477
468 if (!(irq_stat & PORT_IRQ_COMPLETE)) 478 if (!(irq_stat & PORT_IRQ_COMPLETE)) {
469 return -1; 479 DPRINTK("EXIT, srst failed\n");
480 return -EIO;
481 }
470 482
471 /* update TF */
472 sil24_update_tf(ap); 483 sil24_update_tf(ap);
484 *class = ata_dev_classify(&pp->tf);
485
486 if (*class == ATA_DEV_UNKNOWN)
487 *class = ATA_DEV_NONE;
488
489 out:
490 DPRINTK("EXIT, class=%u\n", *class);
473 return 0; 491 return 0;
474} 492}
475 493
476static void sil24_phy_reset(struct ata_port *ap) 494static int sil24_hardreset(struct ata_port *ap, int verbose,
495 unsigned int *class)
477{ 496{
478 struct sil24_port_priv *pp = ap->private_data; 497 unsigned int dummy_class;
479 498
480 __sata_phy_reset(ap); 499 /* sil24 doesn't report device signature after hard reset */
481 if (ap->flags & ATA_FLAG_PORT_DISABLED) 500 return sata_std_hardreset(ap, verbose, &dummy_class);
482 return; 501}
483
484 if (sil24_issue_SRST(ap) < 0) {
485 printk(KERN_ERR DRV_NAME
486 " ata%u: SRST failed, disabling port\n", ap->id);
487 ap->ops->port_disable(ap);
488 return;
489 }
490 502
491 ap->device->class = ata_dev_classify(&pp->tf); 503static int sil24_probe_reset(struct ata_port *ap, unsigned int *classes)
504{
505 return ata_drive_probe_reset(ap, ata_std_probeinit,
506 sil24_softreset, sil24_hardreset,
507 ata_std_postreset, classes);
492} 508}
493 509
494static inline void sil24_fill_sg(struct ata_queued_cmd *qc, 510static inline void sil24_fill_sg(struct ata_queued_cmd *qc,
@@ -533,7 +549,7 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc)
533 prb = &cb->atapi.prb; 549 prb = &cb->atapi.prb;
534 sge = cb->atapi.sge; 550 sge = cb->atapi.sge;
535 memset(cb->atapi.cdb, 0, 32); 551 memset(cb->atapi.cdb, 0, 32);
536 memcpy(cb->atapi.cdb, qc->cdb, ap->cdb_len); 552 memcpy(cb->atapi.cdb, qc->cdb, qc->dev->cdb_len);
537 553
538 if (qc->tf.protocol != ATA_PROT_ATAPI_NODATA) { 554 if (qc->tf.protocol != ATA_PROT_ATAPI_NODATA) {
539 if (qc->tf.flags & ATA_TFLAG_WRITE) 555 if (qc->tf.flags & ATA_TFLAG_WRITE)
@@ -557,7 +573,7 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc)
557 sil24_fill_sg(qc, sge); 573 sil24_fill_sg(qc, sge);
558} 574}
559 575
560static int sil24_qc_issue(struct ata_queued_cmd *qc) 576static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc)
561{ 577{
562 struct ata_port *ap = qc->ap; 578 struct ata_port *ap = qc->ap;
563 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 579 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
@@ -638,23 +654,10 @@ static void sil24_eng_timeout(struct ata_port *ap)
638 struct ata_queued_cmd *qc; 654 struct ata_queued_cmd *qc;
639 655
640 qc = ata_qc_from_tag(ap, ap->active_tag); 656 qc = ata_qc_from_tag(ap, ap->active_tag);
641 if (!qc) {
642 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
643 ap->id);
644 return;
645 }
646 657
647 /*
648 * hack alert! We cannot use the supplied completion
649 * function from inside the ->eh_strategy_handler() thread.
650 * libata is the only user of ->eh_strategy_handler() in
651 * any kernel, so the default scsi_done() assumes it is
652 * not being called from the SCSI EH.
653 */
654 printk(KERN_ERR "ata%u: command timeout\n", ap->id); 658 printk(KERN_ERR "ata%u: command timeout\n", ap->id);
655 qc->scsidone = scsi_finish_command; 659 qc->err_mask |= AC_ERR_TIMEOUT;
656 qc->err_mask |= AC_ERR_OTHER; 660 ata_eh_qc_complete(qc);
657 ata_qc_complete(qc);
658 661
659 sil24_reset_controller(ap); 662 sil24_reset_controller(ap);
660} 663}
@@ -895,6 +898,7 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
895 probe_ent->sht = pinfo->sht; 898 probe_ent->sht = pinfo->sht;
896 probe_ent->host_flags = pinfo->host_flags; 899 probe_ent->host_flags = pinfo->host_flags;
897 probe_ent->pio_mask = pinfo->pio_mask; 900 probe_ent->pio_mask = pinfo->pio_mask;
901 probe_ent->mwdma_mask = pinfo->mwdma_mask;
898 probe_ent->udma_mask = pinfo->udma_mask; 902 probe_ent->udma_mask = pinfo->udma_mask;
899 probe_ent->port_ops = pinfo->port_ops; 903 probe_ent->port_ops = pinfo->port_ops;
900 probe_ent->n_ports = SIL24_FLAG2NPORTS(pinfo->host_flags); 904 probe_ent->n_ports = SIL24_FLAG2NPORTS(pinfo->host_flags);
diff --git a/drivers/scsi/sata_sis.c b/drivers/scsi/sata_sis.c
index 2df8c5632ac3..7fd45f86de99 100644
--- a/drivers/scsi/sata_sis.c
+++ b/drivers/scsi/sata_sis.c
@@ -87,11 +87,11 @@ static struct scsi_host_template sis_sht = {
87 .name = DRV_NAME, 87 .name = DRV_NAME,
88 .ioctl = ata_scsi_ioctl, 88 .ioctl = ata_scsi_ioctl,
89 .queuecommand = ata_scsi_queuecmd, 89 .queuecommand = ata_scsi_queuecmd,
90 .eh_timed_out = ata_scsi_timed_out,
90 .eh_strategy_handler = ata_scsi_error, 91 .eh_strategy_handler = ata_scsi_error,
91 .can_queue = ATA_DEF_QUEUE, 92 .can_queue = ATA_DEF_QUEUE,
92 .this_id = ATA_SHT_THIS_ID, 93 .this_id = ATA_SHT_THIS_ID,
93 .sg_tablesize = ATA_MAX_PRD, 94 .sg_tablesize = ATA_MAX_PRD,
94 .max_sectors = ATA_MAX_SECTORS,
95 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 95 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
96 .emulated = ATA_SHT_EMULATED, 96 .emulated = ATA_SHT_EMULATED,
97 .use_clustering = ATA_SHT_USE_CLUSTERING, 97 .use_clustering = ATA_SHT_USE_CLUSTERING,
diff --git a/drivers/scsi/sata_svw.c b/drivers/scsi/sata_svw.c
index d8472563fde8..4aaccd53e736 100644
--- a/drivers/scsi/sata_svw.c
+++ b/drivers/scsi/sata_svw.c
@@ -288,11 +288,11 @@ static struct scsi_host_template k2_sata_sht = {
288 .name = DRV_NAME, 288 .name = DRV_NAME,
289 .ioctl = ata_scsi_ioctl, 289 .ioctl = ata_scsi_ioctl,
290 .queuecommand = ata_scsi_queuecmd, 290 .queuecommand = ata_scsi_queuecmd,
291 .eh_timed_out = ata_scsi_timed_out,
291 .eh_strategy_handler = ata_scsi_error, 292 .eh_strategy_handler = ata_scsi_error,
292 .can_queue = ATA_DEF_QUEUE, 293 .can_queue = ATA_DEF_QUEUE,
293 .this_id = ATA_SHT_THIS_ID, 294 .this_id = ATA_SHT_THIS_ID,
294 .sg_tablesize = LIBATA_MAX_PRD, 295 .sg_tablesize = LIBATA_MAX_PRD,
295 .max_sectors = ATA_MAX_SECTORS,
296 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 296 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
297 .emulated = ATA_SHT_EMULATED, 297 .emulated = ATA_SHT_EMULATED,
298 .use_clustering = ATA_SHT_USE_CLUSTERING, 298 .use_clustering = ATA_SHT_USE_CLUSTERING,
diff --git a/drivers/scsi/sata_sx4.c b/drivers/scsi/sata_sx4.c
index bc87c16c80d2..9f8a76815402 100644
--- a/drivers/scsi/sata_sx4.c
+++ b/drivers/scsi/sata_sx4.c
@@ -174,7 +174,7 @@ static void pdc20621_get_from_dimm(struct ata_probe_ent *pe,
174static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, 174static void pdc20621_put_to_dimm(struct ata_probe_ent *pe,
175 void *psource, u32 offset, u32 size); 175 void *psource, u32 offset, u32 size);
176static void pdc20621_irq_clear(struct ata_port *ap); 176static void pdc20621_irq_clear(struct ata_port *ap);
177static int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc); 177static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc);
178 178
179 179
180static struct scsi_host_template pdc_sata_sht = { 180static struct scsi_host_template pdc_sata_sht = {
@@ -182,11 +182,11 @@ static struct scsi_host_template pdc_sata_sht = {
182 .name = DRV_NAME, 182 .name = DRV_NAME,
183 .ioctl = ata_scsi_ioctl, 183 .ioctl = ata_scsi_ioctl,
184 .queuecommand = ata_scsi_queuecmd, 184 .queuecommand = ata_scsi_queuecmd,
185 .eh_timed_out = ata_scsi_timed_out,
185 .eh_strategy_handler = ata_scsi_error, 186 .eh_strategy_handler = ata_scsi_error,
186 .can_queue = ATA_DEF_QUEUE, 187 .can_queue = ATA_DEF_QUEUE,
187 .this_id = ATA_SHT_THIS_ID, 188 .this_id = ATA_SHT_THIS_ID,
188 .sg_tablesize = LIBATA_MAX_PRD, 189 .sg_tablesize = LIBATA_MAX_PRD,
189 .max_sectors = ATA_MAX_SECTORS,
190 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 190 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
191 .emulated = ATA_SHT_EMULATED, 191 .emulated = ATA_SHT_EMULATED,
192 .use_clustering = ATA_SHT_USE_CLUSTERING, 192 .use_clustering = ATA_SHT_USE_CLUSTERING,
@@ -460,7 +460,7 @@ static void pdc20621_dma_prep(struct ata_queued_cmd *qc)
460 unsigned int i, idx, total_len = 0, sgt_len; 460 unsigned int i, idx, total_len = 0, sgt_len;
461 u32 *buf = (u32 *) &pp->dimm_buf[PDC_DIMM_HEADER_SZ]; 461 u32 *buf = (u32 *) &pp->dimm_buf[PDC_DIMM_HEADER_SZ];
462 462
463 assert(qc->flags & ATA_QCFLAG_DMAMAP); 463 WARN_ON(!(qc->flags & ATA_QCFLAG_DMAMAP));
464 464
465 VPRINTK("ata%u: ENTER\n", ap->id); 465 VPRINTK("ata%u: ENTER\n", ap->id);
466 466
@@ -678,7 +678,7 @@ static void pdc20621_packet_start(struct ata_queued_cmd *qc)
678 } 678 }
679} 679}
680 680
681static int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc) 681static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc)
682{ 682{
683 switch (qc->tf.protocol) { 683 switch (qc->tf.protocol) {
684 case ATA_PROT_DMA: 684 case ATA_PROT_DMA:
@@ -866,26 +866,12 @@ static void pdc_eng_timeout(struct ata_port *ap)
866 spin_lock_irqsave(&host_set->lock, flags); 866 spin_lock_irqsave(&host_set->lock, flags);
867 867
868 qc = ata_qc_from_tag(ap, ap->active_tag); 868 qc = ata_qc_from_tag(ap, ap->active_tag);
869 if (!qc) {
870 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
871 ap->id);
872 goto out;
873 }
874
875 /* hack alert! We cannot use the supplied completion
876 * function from inside the ->eh_strategy_handler() thread.
877 * libata is the only user of ->eh_strategy_handler() in
878 * any kernel, so the default scsi_done() assumes it is
879 * not being called from the SCSI EH.
880 */
881 qc->scsidone = scsi_finish_command;
882 869
883 switch (qc->tf.protocol) { 870 switch (qc->tf.protocol) {
884 case ATA_PROT_DMA: 871 case ATA_PROT_DMA:
885 case ATA_PROT_NODATA: 872 case ATA_PROT_NODATA:
886 printk(KERN_ERR "ata%u: command timeout\n", ap->id); 873 printk(KERN_ERR "ata%u: command timeout\n", ap->id);
887 qc->err_mask |= __ac_err_mask(ata_wait_idle(ap)); 874 qc->err_mask |= __ac_err_mask(ata_wait_idle(ap));
888 ata_qc_complete(qc);
889 break; 875 break;
890 876
891 default: 877 default:
@@ -895,12 +881,11 @@ static void pdc_eng_timeout(struct ata_port *ap)
895 ap->id, qc->tf.command, drv_stat); 881 ap->id, qc->tf.command, drv_stat);
896 882
897 qc->err_mask |= ac_err_mask(drv_stat); 883 qc->err_mask |= ac_err_mask(drv_stat);
898 ata_qc_complete(qc);
899 break; 884 break;
900 } 885 }
901 886
902out:
903 spin_unlock_irqrestore(&host_set->lock, flags); 887 spin_unlock_irqrestore(&host_set->lock, flags);
888 ata_eh_qc_complete(qc);
904 DPRINTK("EXIT\n"); 889 DPRINTK("EXIT\n");
905} 890}
906 891
diff --git a/drivers/scsi/sata_uli.c b/drivers/scsi/sata_uli.c
index 9635ca700977..37a487b7d655 100644
--- a/drivers/scsi/sata_uli.c
+++ b/drivers/scsi/sata_uli.c
@@ -75,11 +75,11 @@ static struct scsi_host_template uli_sht = {
75 .name = DRV_NAME, 75 .name = DRV_NAME,
76 .ioctl = ata_scsi_ioctl, 76 .ioctl = ata_scsi_ioctl,
77 .queuecommand = ata_scsi_queuecmd, 77 .queuecommand = ata_scsi_queuecmd,
78 .eh_timed_out = ata_scsi_timed_out,
78 .eh_strategy_handler = ata_scsi_error, 79 .eh_strategy_handler = ata_scsi_error,
79 .can_queue = ATA_DEF_QUEUE, 80 .can_queue = ATA_DEF_QUEUE,
80 .this_id = ATA_SHT_THIS_ID, 81 .this_id = ATA_SHT_THIS_ID,
81 .sg_tablesize = LIBATA_MAX_PRD, 82 .sg_tablesize = LIBATA_MAX_PRD,
82 .max_sectors = ATA_MAX_SECTORS,
83 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 83 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
84 .emulated = ATA_SHT_EMULATED, 84 .emulated = ATA_SHT_EMULATED,
85 .use_clustering = ATA_SHT_USE_CLUSTERING, 85 .use_clustering = ATA_SHT_USE_CLUSTERING,
diff --git a/drivers/scsi/sata_via.c b/drivers/scsi/sata_via.c
index 6d5b0a794cfd..ff65a0b0457f 100644
--- a/drivers/scsi/sata_via.c
+++ b/drivers/scsi/sata_via.c
@@ -94,11 +94,11 @@ static struct scsi_host_template svia_sht = {
94 .name = DRV_NAME, 94 .name = DRV_NAME,
95 .ioctl = ata_scsi_ioctl, 95 .ioctl = ata_scsi_ioctl,
96 .queuecommand = ata_scsi_queuecmd, 96 .queuecommand = ata_scsi_queuecmd,
97 .eh_timed_out = ata_scsi_timed_out,
97 .eh_strategy_handler = ata_scsi_error, 98 .eh_strategy_handler = ata_scsi_error,
98 .can_queue = ATA_DEF_QUEUE, 99 .can_queue = ATA_DEF_QUEUE,
99 .this_id = ATA_SHT_THIS_ID, 100 .this_id = ATA_SHT_THIS_ID,
100 .sg_tablesize = LIBATA_MAX_PRD, 101 .sg_tablesize = LIBATA_MAX_PRD,
101 .max_sectors = ATA_MAX_SECTORS,
102 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 102 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
103 .emulated = ATA_SHT_EMULATED, 103 .emulated = ATA_SHT_EMULATED,
104 .use_clustering = ATA_SHT_USE_CLUSTERING, 104 .use_clustering = ATA_SHT_USE_CLUSTERING,
diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c
index e484e8db6810..b574379a7a82 100644
--- a/drivers/scsi/sata_vsc.c
+++ b/drivers/scsi/sata_vsc.c
@@ -251,11 +251,11 @@ static struct scsi_host_template vsc_sata_sht = {
251 .name = DRV_NAME, 251 .name = DRV_NAME,
252 .ioctl = ata_scsi_ioctl, 252 .ioctl = ata_scsi_ioctl,
253 .queuecommand = ata_scsi_queuecmd, 253 .queuecommand = ata_scsi_queuecmd,
254 .eh_timed_out = ata_scsi_timed_out,
254 .eh_strategy_handler = ata_scsi_error, 255 .eh_strategy_handler = ata_scsi_error,
255 .can_queue = ATA_DEF_QUEUE, 256 .can_queue = ATA_DEF_QUEUE,
256 .this_id = ATA_SHT_THIS_ID, 257 .this_id = ATA_SHT_THIS_ID,
257 .sg_tablesize = LIBATA_MAX_PRD, 258 .sg_tablesize = LIBATA_MAX_PRD,
258 .max_sectors = ATA_MAX_SECTORS,
259 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 259 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
260 .emulated = ATA_SHT_EMULATED, 260 .emulated = ATA_SHT_EMULATED,
261 .use_clustering = ATA_SHT_USE_CLUSTERING, 261 .use_clustering = ATA_SHT_USE_CLUSTERING,
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index ff82ccfbb106..5d169a2881b9 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -584,8 +584,7 @@ static int scsi_request_sense(struct scsi_cmnd *scmd)
584 * keep a list of pending commands for final completion, and once we 584 * keep a list of pending commands for final completion, and once we
585 * are ready to leave error handling we handle completion for real. 585 * are ready to leave error handling we handle completion for real.
586 **/ 586 **/
587static void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, 587void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, struct list_head *done_q)
588 struct list_head *done_q)
589{ 588{
590 scmd->device->host->host_failed--; 589 scmd->device->host->host_failed--;
591 scmd->eh_eflags = 0; 590 scmd->eh_eflags = 0;
@@ -597,6 +596,7 @@ static void scsi_eh_finish_cmd(struct scsi_cmnd *scmd,
597 scsi_setup_cmd_retry(scmd); 596 scsi_setup_cmd_retry(scmd);
598 list_move_tail(&scmd->eh_entry, done_q); 597 list_move_tail(&scmd->eh_entry, done_q);
599} 598}
599EXPORT_SYMBOL(scsi_eh_finish_cmd);
600 600
601/** 601/**
602 * scsi_eh_get_sense - Get device sense data. 602 * scsi_eh_get_sense - Get device sense data.
@@ -1425,7 +1425,7 @@ static void scsi_eh_ready_devs(struct Scsi_Host *shost,
1425 * @done_q: list_head of processed commands. 1425 * @done_q: list_head of processed commands.
1426 * 1426 *
1427 **/ 1427 **/
1428static void scsi_eh_flush_done_q(struct list_head *done_q) 1428void scsi_eh_flush_done_q(struct list_head *done_q)
1429{ 1429{
1430 struct scsi_cmnd *scmd, *next; 1430 struct scsi_cmnd *scmd, *next;
1431 1431
@@ -1454,6 +1454,7 @@ static void scsi_eh_flush_done_q(struct list_head *done_q)
1454 } 1454 }
1455 } 1455 }
1456} 1456}
1457EXPORT_SYMBOL(scsi_eh_flush_done_q);
1457 1458
1458/** 1459/**
1459 * scsi_unjam_host - Attempt to fix a host which has a cmd that failed. 1460 * scsi_unjam_host - Attempt to fix a host which has a cmd that failed.
diff --git a/drivers/serial/s3c2410.c b/drivers/serial/s3c2410.c
index 7410e093a6b9..00d7c0ad8cbf 100644
--- a/drivers/serial/s3c2410.c
+++ b/drivers/serial/s3c2410.c
@@ -1066,6 +1066,8 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
1066 port->mapbase = res->start; 1066 port->mapbase = res->start;
1067 port->membase = S3C24XX_VA_UART + (res->start - S3C24XX_PA_UART); 1067 port->membase = S3C24XX_VA_UART + (res->start - S3C24XX_PA_UART);
1068 port->irq = platform_get_irq(platdev, 0); 1068 port->irq = platform_get_irq(platdev, 0);
1069 if (port->irq < 0)
1070 port->irq = 0;
1069 1071
1070 ourport->clk = clk_get(&platdev->dev, "uart"); 1072 ourport->clk = clk_get(&platdev->dev, "uart");
1071 1073
diff --git a/drivers/sn/ioc4.c b/drivers/sn/ioc4.c
index ea75b3d0612b..67140a5804f5 100644
--- a/drivers/sn/ioc4.c
+++ b/drivers/sn/ioc4.c
@@ -31,7 +31,7 @@
31#include <linux/ioc4.h> 31#include <linux/ioc4.h>
32#include <linux/mmtimer.h> 32#include <linux/mmtimer.h>
33#include <linux/rtc.h> 33#include <linux/rtc.h>
34#include <linux/rwsem.h> 34#include <linux/mutex.h>
35#include <asm/sn/addrs.h> 35#include <asm/sn/addrs.h>
36#include <asm/sn/clksupport.h> 36#include <asm/sn/clksupport.h>
37#include <asm/sn/shub_mmr.h> 37#include <asm/sn/shub_mmr.h>
@@ -54,11 +54,10 @@
54 * Submodule management * 54 * Submodule management *
55 ************************/ 55 ************************/
56 56
57static LIST_HEAD(ioc4_devices); 57static DEFINE_MUTEX(ioc4_mutex);
58static DECLARE_RWSEM(ioc4_devices_rwsem);
59 58
59static LIST_HEAD(ioc4_devices);
60static LIST_HEAD(ioc4_submodules); 60static LIST_HEAD(ioc4_submodules);
61static DECLARE_RWSEM(ioc4_submodules_rwsem);
62 61
63/* Register an IOC4 submodule */ 62/* Register an IOC4 submodule */
64int 63int
@@ -66,15 +65,13 @@ ioc4_register_submodule(struct ioc4_submodule *is)
66{ 65{
67 struct ioc4_driver_data *idd; 66 struct ioc4_driver_data *idd;
68 67
69 down_write(&ioc4_submodules_rwsem); 68 mutex_lock(&ioc4_mutex);
70 list_add(&is->is_list, &ioc4_submodules); 69 list_add(&is->is_list, &ioc4_submodules);
71 up_write(&ioc4_submodules_rwsem);
72 70
73 /* Initialize submodule for each IOC4 */ 71 /* Initialize submodule for each IOC4 */
74 if (!is->is_probe) 72 if (!is->is_probe)
75 return 0; 73 goto out;
76 74
77 down_read(&ioc4_devices_rwsem);
78 list_for_each_entry(idd, &ioc4_devices, idd_list) { 75 list_for_each_entry(idd, &ioc4_devices, idd_list) {
79 if (is->is_probe(idd)) { 76 if (is->is_probe(idd)) {
80 printk(KERN_WARNING 77 printk(KERN_WARNING
@@ -84,8 +81,8 @@ ioc4_register_submodule(struct ioc4_submodule *is)
84 pci_name(idd->idd_pdev)); 81 pci_name(idd->idd_pdev));
85 } 82 }
86 } 83 }
87 up_read(&ioc4_devices_rwsem); 84 out:
88 85 mutex_unlock(&ioc4_mutex);
89 return 0; 86 return 0;
90} 87}
91 88
@@ -95,15 +92,13 @@ ioc4_unregister_submodule(struct ioc4_submodule *is)
95{ 92{
96 struct ioc4_driver_data *idd; 93 struct ioc4_driver_data *idd;
97 94
98 down_write(&ioc4_submodules_rwsem); 95 mutex_lock(&ioc4_mutex);
99 list_del(&is->is_list); 96 list_del(&is->is_list);
100 up_write(&ioc4_submodules_rwsem);
101 97
102 /* Remove submodule for each IOC4 */ 98 /* Remove submodule for each IOC4 */
103 if (!is->is_remove) 99 if (!is->is_remove)
104 return; 100 goto out;
105 101
106 down_read(&ioc4_devices_rwsem);
107 list_for_each_entry(idd, &ioc4_devices, idd_list) { 102 list_for_each_entry(idd, &ioc4_devices, idd_list) {
108 if (is->is_remove(idd)) { 103 if (is->is_remove(idd)) {
109 printk(KERN_WARNING 104 printk(KERN_WARNING
@@ -113,7 +108,8 @@ ioc4_unregister_submodule(struct ioc4_submodule *is)
113 pci_name(idd->idd_pdev)); 108 pci_name(idd->idd_pdev));
114 } 109 }
115 } 110 }
116 up_read(&ioc4_devices_rwsem); 111 out:
112 mutex_unlock(&ioc4_mutex);
117} 113}
118 114
119/********************* 115/*********************
@@ -312,12 +308,11 @@ ioc4_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
312 /* Track PCI-device specific data */ 308 /* Track PCI-device specific data */
313 idd->idd_serial_data = NULL; 309 idd->idd_serial_data = NULL;
314 pci_set_drvdata(idd->idd_pdev, idd); 310 pci_set_drvdata(idd->idd_pdev, idd);
315 down_write(&ioc4_devices_rwsem); 311
312 mutex_lock(&ioc4_mutex);
316 list_add(&idd->idd_list, &ioc4_devices); 313 list_add(&idd->idd_list, &ioc4_devices);
317 up_write(&ioc4_devices_rwsem);
318 314
319 /* Add this IOC4 to all submodules */ 315 /* Add this IOC4 to all submodules */
320 down_read(&ioc4_submodules_rwsem);
321 list_for_each_entry(is, &ioc4_submodules, is_list) { 316 list_for_each_entry(is, &ioc4_submodules, is_list) {
322 if (is->is_probe && is->is_probe(idd)) { 317 if (is->is_probe && is->is_probe(idd)) {
323 printk(KERN_WARNING 318 printk(KERN_WARNING
@@ -327,7 +322,7 @@ ioc4_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
327 pci_name(idd->idd_pdev)); 322 pci_name(idd->idd_pdev));
328 } 323 }
329 } 324 }
330 up_read(&ioc4_submodules_rwsem); 325 mutex_unlock(&ioc4_mutex);
331 326
332 return 0; 327 return 0;
333 328
@@ -351,7 +346,7 @@ ioc4_remove(struct pci_dev *pdev)
351 idd = pci_get_drvdata(pdev); 346 idd = pci_get_drvdata(pdev);
352 347
353 /* Remove this IOC4 from all submodules */ 348 /* Remove this IOC4 from all submodules */
354 down_read(&ioc4_submodules_rwsem); 349 mutex_lock(&ioc4_mutex);
355 list_for_each_entry(is, &ioc4_submodules, is_list) { 350 list_for_each_entry(is, &ioc4_submodules, is_list) {
356 if (is->is_remove && is->is_remove(idd)) { 351 if (is->is_remove && is->is_remove(idd)) {
357 printk(KERN_WARNING 352 printk(KERN_WARNING
@@ -361,7 +356,7 @@ ioc4_remove(struct pci_dev *pdev)
361 pci_name(idd->idd_pdev)); 356 pci_name(idd->idd_pdev));
362 } 357 }
363 } 358 }
364 up_read(&ioc4_submodules_rwsem); 359 mutex_unlock(&ioc4_mutex);
365 360
366 /* Release resources */ 361 /* Release resources */
367 iounmap(idd->idd_misc_regs); 362 iounmap(idd->idd_misc_regs);
@@ -377,9 +372,9 @@ ioc4_remove(struct pci_dev *pdev)
377 pci_disable_device(pdev); 372 pci_disable_device(pdev);
378 373
379 /* Remove and free driver data */ 374 /* Remove and free driver data */
380 down_write(&ioc4_devices_rwsem); 375 mutex_lock(&ioc4_mutex);
381 list_del(&idd->idd_list); 376 list_del(&idd->idd_list);
382 up_write(&ioc4_devices_rwsem); 377 mutex_unlock(&ioc4_mutex);
383 kfree(idd); 378 kfree(idd);
384} 379}
385 380
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 85dacc92545a..b1222cd4aa46 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -10,6 +10,7 @@ menu "USB support"
10config USB_ARCH_HAS_HCD 10config USB_ARCH_HAS_HCD
11 boolean 11 boolean
12 default y if USB_ARCH_HAS_OHCI 12 default y if USB_ARCH_HAS_OHCI
13 default y if USB_ARCH_HAS_EHCI
13 default y if ARM # SL-811 14 default y if ARM # SL-811
14 default PCI 15 default PCI
15 16
@@ -22,6 +23,7 @@ config USB_ARCH_HAS_OHCI
22 default y if ARCH_LH7A404 23 default y if ARCH_LH7A404
23 default y if ARCH_S3C2410 24 default y if ARCH_S3C2410
24 default y if PXA27x 25 default y if PXA27x
26 default y if ARCH_AT91RM9200
25 # PPC: 27 # PPC:
26 default y if STB03xxx 28 default y if STB03xxx
27 default y if PPC_MPC52xx 29 default y if PPC_MPC52xx
@@ -30,6 +32,13 @@ config USB_ARCH_HAS_OHCI
30 # more: 32 # more:
31 default PCI 33 default PCI
32 34
35# some non-PCI hcds implement EHCI
36config USB_ARCH_HAS_EHCI
37 boolean
38 default y if PPC_83xx
39 default y if SOC_AU1200
40 default PCI
41
33# ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface. 42# ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface.
34config USB 43config USB
35 tristate "Support for Host-side USB" 44 tristate "Support for Host-side USB"
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 36e476dd9123..bb36a1c1dbb3 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -15,10 +15,9 @@ obj-$(CONFIG_USB_OHCI_HCD) += host/
15obj-$(CONFIG_USB_UHCI_HCD) += host/ 15obj-$(CONFIG_USB_UHCI_HCD) += host/
16obj-$(CONFIG_USB_SL811_HCD) += host/ 16obj-$(CONFIG_USB_SL811_HCD) += host/
17obj-$(CONFIG_ETRAX_USB_HOST) += host/ 17obj-$(CONFIG_ETRAX_USB_HOST) += host/
18obj-$(CONFIG_USB_OHCI_AT91) += host/
18 19
19obj-$(CONFIG_USB_ACM) += class/ 20obj-$(CONFIG_USB_ACM) += class/
20obj-$(CONFIG_USB_AUDIO) += class/
21obj-$(CONFIG_USB_MIDI) += class/
22obj-$(CONFIG_USB_PRINTER) += class/ 21obj-$(CONFIG_USB_PRINTER) += class/
23 22
24obj-$(CONFIG_USB_STORAGE) += storage/ 23obj-$(CONFIG_USB_STORAGE) += storage/
@@ -48,6 +47,7 @@ obj-$(CONFIG_USB_SN9C102) += media/
48obj-$(CONFIG_USB_STV680) += media/ 47obj-$(CONFIG_USB_STV680) += media/
49obj-$(CONFIG_USB_VICAM) += media/ 48obj-$(CONFIG_USB_VICAM) += media/
50obj-$(CONFIG_USB_W9968CF) += media/ 49obj-$(CONFIG_USB_W9968CF) += media/
50obj-$(CONFIG_USB_ZC0301) += media/
51 51
52obj-$(CONFIG_USB_CATC) += net/ 52obj-$(CONFIG_USB_CATC) += net/
53obj-$(CONFIG_USB_KAWETH) += net/ 53obj-$(CONFIG_USB_KAWETH) += net/
diff --git a/drivers/usb/class/Kconfig b/drivers/usb/class/Kconfig
index ef105a92a7bd..3a9102d2591b 100644
--- a/drivers/usb/class/Kconfig
+++ b/drivers/usb/class/Kconfig
@@ -4,53 +4,6 @@
4comment "USB Device Class drivers" 4comment "USB Device Class drivers"
5 depends on USB 5 depends on USB
6 6
7config OBSOLETE_OSS_USB_DRIVER
8 bool "Obsolete OSS USB drivers"
9 depends on USB && SOUND
10 help
11 This option enables support for the obsolete USB Audio and Midi
12 drivers that are scheduled for removal in the near future since
13 there are ALSA drivers for the same hardware.
14
15 Please contact Adrian Bunk <bunk@stusta.de> if you had to
16 say Y here because of missing support in the ALSA drivers.
17
18 If unsure, say N.
19
20config USB_AUDIO
21 tristate "USB Audio support"
22 depends on USB && SOUND && OBSOLETE_OSS_USB_DRIVER
23 help
24 Say Y here if you want to connect USB audio equipment such as
25 speakers to your computer's USB port. You only need this if you use
26 the OSS sound driver; ALSA has its own option for usb audio support.
27
28 To compile this driver as a module, choose M here: the
29 module will be called audio.
30
31config USB_MIDI
32 tristate "USB MIDI support"
33 depends on USB && SOUND && OBSOLETE_OSS_USB_DRIVER
34 ---help---
35 Say Y here if you want to connect a USB MIDI device to your
36 computer's USB port. You only need this if you use the OSS
37 sound system; USB MIDI devices are supported by ALSA's USB
38 audio driver. This driver is for devices that comply with
39 'Universal Serial Bus Device Class Definition for MIDI Device'.
40
41 The following devices are known to work:
42 * Steinberg USB2MIDI
43 * Roland MPU64
44 * Roland PC-300
45 * Roland SC8850
46 * Roland UM-1
47 * Roland UM-2
48 * Roland UA-100
49 * Yamaha MU1000
50
51 To compile this driver as a module, choose M here: the
52 module will be called usb-midi.
53
54config USB_ACM 7config USB_ACM
55 tristate "USB Modem (CDC ACM) support" 8 tristate "USB Modem (CDC ACM) support"
56 depends on USB 9 depends on USB
diff --git a/drivers/usb/class/Makefile b/drivers/usb/class/Makefile
index 229471247751..cc391e6c2af8 100644
--- a/drivers/usb/class/Makefile
+++ b/drivers/usb/class/Makefile
@@ -4,6 +4,4 @@
4# 4#
5 5
6obj-$(CONFIG_USB_ACM) += cdc-acm.o 6obj-$(CONFIG_USB_ACM) += cdc-acm.o
7obj-$(CONFIG_USB_AUDIO) += audio.o
8obj-$(CONFIG_USB_MIDI) += usb-midi.o
9obj-$(CONFIG_USB_PRINTER) += usblp.o 7obj-$(CONFIG_USB_PRINTER) += usblp.o
diff --git a/drivers/usb/class/audio.c b/drivers/usb/class/audio.c
deleted file mode 100644
index 3ad9ee8b84a9..000000000000
--- a/drivers/usb/class/audio.c
+++ /dev/null
@@ -1,3869 +0,0 @@
1/*****************************************************************************/
2
3/*
4 * audio.c -- USB Audio Class driver
5 *
6 * Copyright (C) 1999, 2000, 2001, 2003, 2004
7 * Alan Cox (alan@lxorguk.ukuu.org.uk)
8 * Thomas Sailer (sailer@ife.ee.ethz.ch)
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * Debugging:
16 * Use the 'lsusb' utility to dump the descriptors.
17 *
18 * 1999-09-07: Alan Cox
19 * Parsing Audio descriptor patch
20 * 1999-09-08: Thomas Sailer
21 * Added OSS compatible data io functions; both parts of the
22 * driver remain to be glued together
23 * 1999-09-10: Thomas Sailer
24 * Beautified the driver. Added sample format conversions.
25 * Still not properly glued with the parsing code.
26 * The parsing code seems to have its problems btw,
27 * Since it parses all available configs but doesn't
28 * store which iface/altsetting belongs to which config.
29 * 1999-09-20: Thomas Sailer
30 * Threw out Alan's parsing code and implemented my own one.
31 * You cannot reasonnably linearly parse audio descriptors,
32 * especially the AudioClass descriptors have to be considered
33 * pointer lists. Mixer parsing untested, due to lack of device.
34 * First stab at synch pipe implementation, the Dallas USB DAC
35 * wants to use an Asynch out pipe. usb_audio_state now basically
36 * only contains lists of mixer and wave devices. We can therefore
37 * now have multiple mixer/wave devices per USB device.
38 * 1999-10-28: Thomas Sailer
39 * Converted to URB API. Fixed a taskstate/wakeup semantics mistake
40 * that made the driver consume all available CPU cycles.
41 * Now runs stable on UHCI-Acher/Fliegl/Sailer.
42 * 1999-10-31: Thomas Sailer
43 * Audio can now be unloaded if it is not in use by any mixer
44 * or dsp client (formerly you had to disconnect the audio devices
45 * from the USB port)
46 * Finally, about three months after ordering, my "Maxxtro SPK222"
47 * speakers arrived, isn't disdata a great mail order company 8-)
48 * Parse class specific endpoint descriptor of the audiostreaming
49 * interfaces and take the endpoint attributes from there.
50 * Unbelievably, the Philips USB DAC has a sampling rate range
51 * of over a decade, yet does not support the sampling rate control!
52 * No wonder it sounds so bad, has very audible sampling rate
53 * conversion distortion. Don't try to listen to it using
54 * decent headphones!
55 * "Let's make things better" -> but please Philips start with your
56 * own stuff!!!!
57 * 1999-11-02: Thomas Sailer
58 * It takes the Philips boxes several seconds to acquire synchronisation
59 * that means they won't play short sounds. Should probably maintain
60 * the ISO datastream even if there's nothing to play.
61 * Fix counting the total_bytes counter, RealPlayer G2 depends on it.
62 * 1999-12-20: Thomas Sailer
63 * Fix bad bug in conversion to per interface probing.
64 * disconnect was called multiple times for the audio device,
65 * leading to a premature freeing of the audio structures
66 * 2000-05-13: Thomas Sailer
67 * I don't remember who changed the find_format routine,
68 * but the change was completely broken for the Dallas
69 * chip. Anyway taking sampling rate into account in find_format
70 * is bad and should not be done unless there are devices with
71 * completely broken audio descriptors. Unless someone shows
72 * me such a descriptor, I will not allow find_format to
73 * take the sampling rate into account.
74 * Also, the former find_format made:
75 * - mpg123 play mono instead of stereo
76 * - sox completely fail for wav's with sample rates < 44.1kHz
77 * for the Dallas chip.
78 * Also fix a rather long standing problem with applications that
79 * use "small" writes producing no sound at all.
80 * 2000-05-15: Thomas Sailer
81 * My fears came true, the Philips camera indeed has pretty stupid
82 * audio descriptors.
83 * 2000-05-17: Thomas Sailer
84 * Nemsoft spotted my stupid last minute change, thanks
85 * 2000-05-19: Thomas Sailer
86 * Fixed FEATURE_UNIT thinkos found thanks to the KC Technology
87 * Xtend device. Basically the driver treated FEATURE_UNIT's sourced
88 * by mono terminals as stereo.
89 * 2000-05-20: Thomas Sailer
90 * SELECTOR support (and thus selecting record channels from the mixer).
91 * Somewhat peculiar due to OSS interface limitations. Only works
92 * for channels where a "slider" is already in front of it (i.e.
93 * a MIXER unit or a FEATURE unit with volume capability).
94 * 2000-11-26: Thomas Sailer
95 * Workaround for Dallas DS4201. The DS4201 uses PCM8 as format tag for
96 * its 8 bit modes, but expects signed data (and should therefore have used PCM).
97 * 2001-03-10: Thomas Sailer
98 * provide abs function, prevent picking up a bogus kernel macro
99 * for abs. Bug report by Andrew Morton <andrewm@uow.edu.au>
100 * 2001-06-16: Bryce Nesbitt <bryce@obviously.com>
101 * Fix SNDCTL_DSP_STEREO API violation
102 * 2003-04-08: Oliver Neukum (oliver@neukum.name):
103 * Setting a configuration is done by usbcore and must not be overridden
104 * 2004-02-27: Workaround for broken synch descriptors
105 * 2004-03-07: Alan Stern <stern@rowland.harvard.edu>
106 * Add usb_ifnum_to_if() and usb_altnum_to_altsetting() support.
107 * Use the in-memory descriptors instead of reading them from the device.
108 *
109 */
110
111/*
112 * Strategy:
113 *
114 * Alan Cox and Thomas Sailer are starting to dig at opposite ends and
115 * are hoping to meet in the middle, just like tunnel diggers :)
116 * Alan tackles the descriptor parsing, Thomas the actual data IO and the
117 * OSS compatible interface.
118 *
119 * Data IO implementation issues
120 *
121 * A mmap'able ring buffer per direction is implemented, because
122 * almost every OSS app expects it. It is however impractical to
123 * transmit/receive USB data directly into and out of the ring buffer,
124 * due to alignment and synchronisation issues. Instead, the ring buffer
125 * feeds a constant time delay line that handles the USB issues.
126 *
127 * Now we first try to find an alternate setting that exactly matches
128 * the sample format requested by the user. If we find one, we do not
129 * need to perform any sample rate conversions. If there is no matching
130 * altsetting, we choose the closest one and perform sample format
131 * conversions. We never do sample rate conversion; these are too
132 * expensive to be performed in the kernel.
133 *
134 * Current status: no known HCD-specific issues.
135 *
136 * Generally: Due to the brokenness of the Audio Class spec
137 * it seems generally impossible to write a generic Audio Class driver,
138 * so a reasonable driver should implement the features that are actually
139 * used.
140 *
141 * Parsing implementation issues
142 *
143 * One cannot reasonably parse the AudioClass descriptors linearly.
144 * Therefore the current implementation features routines to look
145 * for a specific descriptor in the descriptor list.
146 *
147 * How does the parsing work? First, all interfaces are searched
148 * for an AudioControl class interface. If found, the config descriptor
149 * that belongs to the current configuration is searched and
150 * the HEADER descriptor is found. It contains a list of
151 * all AudioStreaming and MIDIStreaming devices. This list is then walked,
152 * and all AudioStreaming interfaces are classified into input and output
153 * interfaces (according to the endpoint0 direction in altsetting1) (MIDIStreaming
154 * is currently not supported). The input & output list is then used
155 * to group inputs and outputs together and issued pairwise to the
156 * AudioStreaming class parser. Finally, all OUTPUT_TERMINAL descriptors
157 * are walked and issued to the mixer construction routine.
158 *
159 * The AudioStreaming parser simply enumerates all altsettings belonging
160 * to the specified interface. It looks for AS_GENERAL and FORMAT_TYPE
161 * class specific descriptors to extract the sample format/sample rate
162 * data. Only sample format types PCM and PCM8 are supported right now, and
163 * only FORMAT_TYPE_I is handled. The isochronous data endpoint needs to
164 * be the first endpoint of the interface, and the optional synchronisation
165 * isochronous endpoint the second one.
166 *
167 * Mixer construction works as follows: The various TERMINAL and UNIT
168 * descriptors span a tree from the root (OUTPUT_TERMINAL) through the
169 * intermediate nodes (UNITs) to the leaves (INPUT_TERMINAL). We walk
170 * that tree in a depth first manner. FEATURE_UNITs may contribute volume,
171 * bass and treble sliders to the mixer, MIXER_UNITs volume sliders.
172 * The terminal type encoded in the INPUT_TERMINALs feeds a heuristic
173 * to determine "meaningful" OSS slider numbers, however we will see
174 * how well this works in practice. Other features are not used at the
175 * moment, they seem less often used. Also, it seems difficult at least
176 * to construct recording source switches from SELECTOR_UNITs, but
177 * since there are not many USB ADC's available, we leave that for later.
178 */
179
180/*****************************************************************************/
181
182#include <linux/kernel.h>
183#include <linux/slab.h>
184#include <linux/string.h>
185#include <linux/timer.h>
186#include <linux/sched.h>
187#include <linux/smp_lock.h>
188#include <linux/module.h>
189#include <linux/sound.h>
190#include <linux/soundcard.h>
191#include <linux/list.h>
192#include <linux/vmalloc.h>
193#include <linux/init.h>
194#include <linux/poll.h>
195#include <linux/bitops.h>
196#include <asm/uaccess.h>
197#include <asm/io.h>
198#include <linux/usb.h>
199
200#include "audio.h"
201
202/*
203 * Version Information
204 */
205#define DRIVER_VERSION "v1.0.0"
206#define DRIVER_AUTHOR "Alan Cox <alan@lxorguk.ukuu.org.uk>, Thomas Sailer (sailer@ife.ee.ethz.ch)"
207#define DRIVER_DESC "USB Audio Class driver"
208
209#define AUDIO_DEBUG 1
210
211#define SND_DEV_DSP16 5
212
213#define dprintk(x)
214
215/* --------------------------------------------------------------------- */
216
217/*
218 * Linked list of all audio devices...
219 */
220static struct list_head audiodevs = LIST_HEAD_INIT(audiodevs);
221static DECLARE_MUTEX(open_sem);
222
223/*
224 * wait queue for processes wanting to open an USB audio device
225 */
226static DECLARE_WAIT_QUEUE_HEAD(open_wait);
227
228
229#define MAXFORMATS MAX_ALT
230#define DMABUFSHIFT 17 /* 128k worth of DMA buffer */
231#define NRSGBUF (1U<<(DMABUFSHIFT-PAGE_SHIFT))
232
233/*
234 * This influences:
235 * - Latency
236 * - Interrupt rate
237 * - Synchronisation behaviour
238 * Don't touch this if you don't understand all of the above.
239 */
240#define DESCFRAMES 5
241#define SYNCFRAMES DESCFRAMES
242
243#define MIXFLG_STEREOIN 1
244#define MIXFLG_STEREOOUT 2
245
246struct mixerchannel {
247 __u16 value;
248 __u16 osschannel; /* number of the OSS channel */
249 __s16 minval, maxval;
250 __u16 slctunitid;
251 __u8 unitid;
252 __u8 selector;
253 __u8 chnum;
254 __u8 flags;
255};
256
257struct audioformat {
258 unsigned int format;
259 unsigned int sratelo;
260 unsigned int sratehi;
261 unsigned char altsetting;
262 unsigned char attributes;
263};
264
265struct dmabuf {
266 /* buffer data format */
267 unsigned int format;
268 unsigned int srate;
269 /* physical buffer */
270 unsigned char *sgbuf[NRSGBUF];
271 unsigned bufsize;
272 unsigned numfrag;
273 unsigned fragshift;
274 unsigned wrptr, rdptr;
275 unsigned total_bytes;
276 int count;
277 unsigned error; /* over/underrun */
278 wait_queue_head_t wait;
279 /* redundant, but makes calculations easier */
280 unsigned fragsize;
281 unsigned dmasize;
282 /* OSS stuff */
283 unsigned mapped:1;
284 unsigned ready:1;
285 unsigned ossfragshift;
286 int ossmaxfrags;
287 unsigned subdivision;
288};
289
290struct usb_audio_state;
291
292#define FLG_URB0RUNNING 1
293#define FLG_URB1RUNNING 2
294#define FLG_SYNC0RUNNING 4
295#define FLG_SYNC1RUNNING 8
296#define FLG_RUNNING 16
297#define FLG_CONNECTED 32
298
299struct my_data_urb {
300 struct urb *urb;
301};
302
303struct my_sync_urb {
304 struct urb *urb;
305};
306
307
308struct usb_audiodev {
309 struct list_head list;
310 struct usb_audio_state *state;
311
312 /* soundcore stuff */
313 int dev_audio;
314
315 /* wave stuff */
316 mode_t open_mode;
317 spinlock_t lock; /* DMA buffer access spinlock */
318
319 struct usbin {
320 int interface; /* Interface number, -1 means not used */
321 unsigned int format; /* USB data format */
322 unsigned int datapipe; /* the data input pipe */
323 unsigned int syncpipe; /* the synchronisation pipe - 0 for anything but adaptive IN mode */
324 unsigned int syncinterval; /* P for adaptive IN mode, 0 otherwise */
325 unsigned int freqn; /* nominal sampling rate in USB format, i.e. fs/1000 in Q10.14 */
326 unsigned int freqmax; /* maximum sampling rate, used for buffer management */
327 unsigned int phase; /* phase accumulator */
328 unsigned int flags; /* see FLG_ defines */
329
330 struct my_data_urb durb[2]; /* ISO descriptors for the data endpoint */
331 struct my_sync_urb surb[2]; /* ISO sync pipe descriptor if needed */
332
333 struct dmabuf dma;
334 } usbin;
335
336 struct usbout {
337 int interface; /* Interface number, -1 means not used */
338 unsigned int format; /* USB data format */
339 unsigned int datapipe; /* the data input pipe */
340 unsigned int syncpipe; /* the synchronisation pipe - 0 for anything but asynchronous OUT mode */
341 unsigned int syncinterval; /* P for asynchronous OUT mode, 0 otherwise */
342 unsigned int freqn; /* nominal sampling rate in USB format, i.e. fs/1000 in Q10.14 */
343 unsigned int freqm; /* momentary sampling rate in USB format, i.e. fs/1000 in Q10.14 */
344 unsigned int freqmax; /* maximum sampling rate, used for buffer management */
345 unsigned int phase; /* phase accumulator */
346 unsigned int flags; /* see FLG_ defines */
347
348 struct my_data_urb durb[2]; /* ISO descriptors for the data endpoint */
349 struct my_sync_urb surb[2]; /* ISO sync pipe descriptor if needed */
350
351 struct dmabuf dma;
352 } usbout;
353
354
355 unsigned int numfmtin, numfmtout;
356 struct audioformat fmtin[MAXFORMATS];
357 struct audioformat fmtout[MAXFORMATS];
358};
359
360struct usb_mixerdev {
361 struct list_head list;
362 struct usb_audio_state *state;
363
364 /* soundcore stuff */
365 int dev_mixer;
366
367 unsigned char iface; /* interface number of the AudioControl interface */
368
369 /* USB format descriptions */
370 unsigned int numch, modcnt;
371
372 /* mixch is last and gets allocated dynamically */
373 struct mixerchannel ch[0];
374};
375
376struct usb_audio_state {
377 struct list_head audiodev;
378
379 /* USB device */
380 struct usb_device *usbdev;
381
382 struct list_head audiolist;
383 struct list_head mixerlist;
384
385 unsigned count; /* usage counter; NOTE: the usb stack is also considered a user */
386};
387
388/* private audio format extensions */
389#define AFMT_STEREO 0x80000000
390#define AFMT_ISSTEREO(x) ((x) & AFMT_STEREO)
391#define AFMT_IS16BIT(x) ((x) & (AFMT_S16_LE|AFMT_S16_BE|AFMT_U16_LE|AFMT_U16_BE))
392#define AFMT_ISUNSIGNED(x) ((x) & (AFMT_U8|AFMT_U16_LE|AFMT_U16_BE))
393#define AFMT_BYTESSHIFT(x) ((AFMT_ISSTEREO(x) ? 1 : 0) + (AFMT_IS16BIT(x) ? 1 : 0))
394#define AFMT_BYTES(x) (1<<AFMT_BYTESSHFIT(x))
395
396/* --------------------------------------------------------------------- */
397
398static inline unsigned ld2(unsigned int x)
399{
400 unsigned r = 0;
401
402 if (x >= 0x10000) {
403 x >>= 16;
404 r += 16;
405 }
406 if (x >= 0x100) {
407 x >>= 8;
408 r += 8;
409 }
410 if (x >= 0x10) {
411 x >>= 4;
412 r += 4;
413 }
414 if (x >= 4) {
415 x >>= 2;
416 r += 2;
417 }
418 if (x >= 2)
419 r++;
420 return r;
421}
422
423/* --------------------------------------------------------------------- */
424
425/*
426 * OSS compatible ring buffer management. The ring buffer may be mmap'ed into
427 * an application address space.
428 *
429 * I first used the rvmalloc stuff copied from bttv. Alan Cox did not like it, so
430 * we now use an array of pointers to a single page each. This saves us the
431 * kernel page table manipulations, but we have to do a page table alike mechanism
432 * (though only one indirection) in software.
433 */
434
435static void dmabuf_release(struct dmabuf *db)
436{
437 unsigned int nr;
438 void *p;
439
440 for(nr = 0; nr < NRSGBUF; nr++) {
441 if (!(p = db->sgbuf[nr]))
442 continue;
443 ClearPageReserved(virt_to_page(p));
444 free_page((unsigned long)p);
445 db->sgbuf[nr] = NULL;
446 }
447 db->mapped = db->ready = 0;
448}
449
450static int dmabuf_init(struct dmabuf *db)
451{
452 unsigned int nr, bytepersec, bufs;
453 void *p;
454
455 /* initialize some fields */
456 db->rdptr = db->wrptr = db->total_bytes = db->count = db->error = 0;
457 /* calculate required buffer size */
458 bytepersec = db->srate << AFMT_BYTESSHIFT(db->format);
459 bufs = 1U << DMABUFSHIFT;
460 if (db->ossfragshift) {
461 if ((1000 << db->ossfragshift) < bytepersec)
462 db->fragshift = ld2(bytepersec/1000);
463 else
464 db->fragshift = db->ossfragshift;
465 } else {
466 db->fragshift = ld2(bytepersec/100/(db->subdivision ? db->subdivision : 1));
467 if (db->fragshift < 3)
468 db->fragshift = 3;
469 }
470 db->numfrag = bufs >> db->fragshift;
471 while (db->numfrag < 4 && db->fragshift > 3) {
472 db->fragshift--;
473 db->numfrag = bufs >> db->fragshift;
474 }
475 db->fragsize = 1 << db->fragshift;
476 if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
477 db->numfrag = db->ossmaxfrags;
478 db->dmasize = db->numfrag << db->fragshift;
479 for(nr = 0; nr < NRSGBUF; nr++) {
480 if (!db->sgbuf[nr]) {
481 p = (void *)get_zeroed_page(GFP_KERNEL);
482 if (!p)
483 return -ENOMEM;
484 db->sgbuf[nr] = p;
485 SetPageReserved(virt_to_page(p));
486 }
487 memset(db->sgbuf[nr], AFMT_ISUNSIGNED(db->format) ? 0x80 : 0, PAGE_SIZE);
488 if ((nr << PAGE_SHIFT) >= db->dmasize)
489 break;
490 }
491 db->bufsize = nr << PAGE_SHIFT;
492 db->ready = 1;
493 dprintk((KERN_DEBUG "usbaudio: dmabuf_init bytepersec %d bufs %d ossfragshift %d ossmaxfrags %d "
494 "fragshift %d fragsize %d numfrag %d dmasize %d bufsize %d fmt 0x%x srate %d\n",
495 bytepersec, bufs, db->ossfragshift, db->ossmaxfrags, db->fragshift, db->fragsize,
496 db->numfrag, db->dmasize, db->bufsize, db->format, db->srate));
497 return 0;
498}
499
500static int dmabuf_mmap(struct vm_area_struct *vma, struct dmabuf *db, unsigned long start, unsigned long size, pgprot_t prot)
501{
502 unsigned int nr;
503
504 if (!db->ready || db->mapped || (start | size) & (PAGE_SIZE-1) || size > db->bufsize)
505 return -EINVAL;
506 size >>= PAGE_SHIFT;
507 for(nr = 0; nr < size; nr++)
508 if (!db->sgbuf[nr])
509 return -EINVAL;
510 db->mapped = 1;
511 for(nr = 0; nr < size; nr++) {
512 unsigned long pfn;
513
514 pfn = virt_to_phys(db->sgbuf[nr]) >> PAGE_SHIFT;
515 if (remap_pfn_range(vma, start, pfn, PAGE_SIZE, prot))
516 return -EAGAIN;
517 start += PAGE_SIZE;
518 }
519 return 0;
520}
521
522static void dmabuf_copyin(struct dmabuf *db, const void *buffer, unsigned int size)
523{
524 unsigned int pgrem, rem;
525
526 db->total_bytes += size;
527 for (;;) {
528 if (size <= 0)
529 return;
530 pgrem = ((~db->wrptr) & (PAGE_SIZE-1)) + 1;
531 if (pgrem > size)
532 pgrem = size;
533 rem = db->dmasize - db->wrptr;
534 if (pgrem > rem)
535 pgrem = rem;
536 memcpy((db->sgbuf[db->wrptr >> PAGE_SHIFT]) + (db->wrptr & (PAGE_SIZE-1)), buffer, pgrem);
537 size -= pgrem;
538 buffer += pgrem;
539 db->wrptr += pgrem;
540 if (db->wrptr >= db->dmasize)
541 db->wrptr = 0;
542 }
543}
544
545static void dmabuf_copyout(struct dmabuf *db, void *buffer, unsigned int size)
546{
547 unsigned int pgrem, rem;
548
549 db->total_bytes += size;
550 for (;;) {
551 if (size <= 0)
552 return;
553 pgrem = ((~db->rdptr) & (PAGE_SIZE-1)) + 1;
554 if (pgrem > size)
555 pgrem = size;
556 rem = db->dmasize - db->rdptr;
557 if (pgrem > rem)
558 pgrem = rem;
559 memcpy(buffer, (db->sgbuf[db->rdptr >> PAGE_SHIFT]) + (db->rdptr & (PAGE_SIZE-1)), pgrem);
560 size -= pgrem;
561 buffer += pgrem;
562 db->rdptr += pgrem;
563 if (db->rdptr >= db->dmasize)
564 db->rdptr = 0;
565 }
566}
567
568static int dmabuf_copyin_user(struct dmabuf *db, unsigned int ptr, const void __user *buffer, unsigned int size)
569{
570 unsigned int pgrem, rem;
571
572 if (!db->ready || db->mapped)
573 return -EINVAL;
574 for (;;) {
575 if (size <= 0)
576 return 0;
577 pgrem = ((~ptr) & (PAGE_SIZE-1)) + 1;
578 if (pgrem > size)
579 pgrem = size;
580 rem = db->dmasize - ptr;
581 if (pgrem > rem)
582 pgrem = rem;
583 if (copy_from_user((db->sgbuf[ptr >> PAGE_SHIFT]) + (ptr & (PAGE_SIZE-1)), buffer, pgrem))
584 return -EFAULT;
585 size -= pgrem;
586 buffer += pgrem;
587 ptr += pgrem;
588 if (ptr >= db->dmasize)
589 ptr = 0;
590 }
591}
592
593static int dmabuf_copyout_user(struct dmabuf *db, unsigned int ptr, void __user *buffer, unsigned int size)
594{
595 unsigned int pgrem, rem;
596
597 if (!db->ready || db->mapped)
598 return -EINVAL;
599 for (;;) {
600 if (size <= 0)
601 return 0;
602 pgrem = ((~ptr) & (PAGE_SIZE-1)) + 1;
603 if (pgrem > size)
604 pgrem = size;
605 rem = db->dmasize - ptr;
606 if (pgrem > rem)
607 pgrem = rem;
608 if (copy_to_user(buffer, (db->sgbuf[ptr >> PAGE_SHIFT]) + (ptr & (PAGE_SIZE-1)), pgrem))
609 return -EFAULT;
610 size -= pgrem;
611 buffer += pgrem;
612 ptr += pgrem;
613 if (ptr >= db->dmasize)
614 ptr = 0;
615 }
616}
617
618/* --------------------------------------------------------------------- */
619/*
620 * USB I/O code. We do sample format conversion if necessary
621 */
622
623static void usbin_stop(struct usb_audiodev *as)
624{
625 struct usbin *u = &as->usbin;
626 unsigned long flags;
627 unsigned int i, notkilled = 1;
628
629 spin_lock_irqsave(&as->lock, flags);
630 u->flags &= ~FLG_RUNNING;
631 i = u->flags;
632 spin_unlock_irqrestore(&as->lock, flags);
633 while (i & (FLG_URB0RUNNING|FLG_URB1RUNNING|FLG_SYNC0RUNNING|FLG_SYNC1RUNNING)) {
634 if (notkilled)
635 schedule_timeout_interruptible(1);
636 else
637 schedule_timeout_uninterruptible(1);
638 spin_lock_irqsave(&as->lock, flags);
639 i = u->flags;
640 spin_unlock_irqrestore(&as->lock, flags);
641 if (notkilled && signal_pending(current)) {
642 if (i & FLG_URB0RUNNING)
643 usb_kill_urb(u->durb[0].urb);
644 if (i & FLG_URB1RUNNING)
645 usb_kill_urb(u->durb[1].urb);
646 if (i & FLG_SYNC0RUNNING)
647 usb_kill_urb(u->surb[0].urb);
648 if (i & FLG_SYNC1RUNNING)
649 usb_kill_urb(u->surb[1].urb);
650 notkilled = 0;
651 }
652 }
653 set_current_state(TASK_RUNNING);
654 kfree(u->durb[0].urb->transfer_buffer);
655 kfree(u->durb[1].urb->transfer_buffer);
656 kfree(u->surb[0].urb->transfer_buffer);
657 kfree(u->surb[1].urb->transfer_buffer);
658 u->durb[0].urb->transfer_buffer = u->durb[1].urb->transfer_buffer =
659 u->surb[0].urb->transfer_buffer = u->surb[1].urb->transfer_buffer = NULL;
660}
661
662static inline void usbin_release(struct usb_audiodev *as)
663{
664 usbin_stop(as);
665}
666
667static void usbin_disc(struct usb_audiodev *as)
668{
669 struct usbin *u = &as->usbin;
670
671 unsigned long flags;
672
673 spin_lock_irqsave(&as->lock, flags);
674 u->flags &= ~(FLG_RUNNING | FLG_CONNECTED);
675 spin_unlock_irqrestore(&as->lock, flags);
676 usbin_stop(as);
677}
678
679static void conversion(const void *ibuf, unsigned int ifmt, void *obuf, unsigned int ofmt, void *tmp, unsigned int scnt)
680{
681 unsigned int cnt, i;
682 __s16 *sp, *sp2, s;
683 unsigned char *bp;
684
685 cnt = scnt;
686 if (AFMT_ISSTEREO(ifmt))
687 cnt <<= 1;
688 sp = ((__s16 *)tmp) + cnt;
689 switch (ifmt & ~AFMT_STEREO) {
690 case AFMT_U8:
691 for (bp = ((unsigned char *)ibuf)+cnt, i = 0; i < cnt; i++) {
692 bp--;
693 sp--;
694 *sp = (*bp ^ 0x80) << 8;
695 }
696 break;
697
698 case AFMT_S8:
699 for (bp = ((unsigned char *)ibuf)+cnt, i = 0; i < cnt; i++) {
700 bp--;
701 sp--;
702 *sp = *bp << 8;
703 }
704 break;
705
706 case AFMT_U16_LE:
707 for (bp = ((unsigned char *)ibuf)+2*cnt, i = 0; i < cnt; i++) {
708 bp -= 2;
709 sp--;
710 *sp = (bp[0] | (bp[1] << 8)) ^ 0x8000;
711 }
712 break;
713
714 case AFMT_U16_BE:
715 for (bp = ((unsigned char *)ibuf)+2*cnt, i = 0; i < cnt; i++) {
716 bp -= 2;
717 sp--;
718 *sp = (bp[1] | (bp[0] << 8)) ^ 0x8000;
719 }
720 break;
721
722 case AFMT_S16_LE:
723 for (bp = ((unsigned char *)ibuf)+2*cnt, i = 0; i < cnt; i++) {
724 bp -= 2;
725 sp--;
726 *sp = bp[0] | (bp[1] << 8);
727 }
728 break;
729
730 case AFMT_S16_BE:
731 for (bp = ((unsigned char *)ibuf)+2*cnt, i = 0; i < cnt; i++) {
732 bp -= 2;
733 sp--;
734 *sp = bp[1] | (bp[0] << 8);
735 }
736 break;
737 }
738 if (!AFMT_ISSTEREO(ifmt) && AFMT_ISSTEREO(ofmt)) {
739 /* expand from mono to stereo */
740 for (sp = ((__s16 *)tmp)+scnt, sp2 = ((__s16 *)tmp)+2*scnt, i = 0; i < scnt; i++) {
741 sp--;
742 sp2 -= 2;
743 sp2[0] = sp2[1] = sp[0];
744 }
745 }
746 if (AFMT_ISSTEREO(ifmt) && !AFMT_ISSTEREO(ofmt)) {
747 /* contract from stereo to mono */
748 for (sp = sp2 = ((__s16 *)tmp), i = 0; i < scnt; i++, sp++, sp2 += 2)
749 sp[0] = (sp2[0] + sp2[1]) >> 1;
750 }
751 cnt = scnt;
752 if (AFMT_ISSTEREO(ofmt))
753 cnt <<= 1;
754 sp = ((__s16 *)tmp);
755 bp = ((unsigned char *)obuf);
756 switch (ofmt & ~AFMT_STEREO) {
757 case AFMT_U8:
758 for (i = 0; i < cnt; i++, sp++, bp++)
759 *bp = (*sp >> 8) ^ 0x80;
760 break;
761
762 case AFMT_S8:
763 for (i = 0; i < cnt; i++, sp++, bp++)
764 *bp = *sp >> 8;
765 break;
766
767 case AFMT_U16_LE:
768 for (i = 0; i < cnt; i++, sp++, bp += 2) {
769 s = *sp;
770 bp[0] = s;
771 bp[1] = (s >> 8) ^ 0x80;
772 }
773 break;
774
775 case AFMT_U16_BE:
776 for (i = 0; i < cnt; i++, sp++, bp += 2) {
777 s = *sp;
778 bp[1] = s;
779 bp[0] = (s >> 8) ^ 0x80;
780 }
781 break;
782
783 case AFMT_S16_LE:
784 for (i = 0; i < cnt; i++, sp++, bp += 2) {
785 s = *sp;
786 bp[0] = s;
787 bp[1] = s >> 8;
788 }
789 break;
790
791 case AFMT_S16_BE:
792 for (i = 0; i < cnt; i++, sp++, bp += 2) {
793 s = *sp;
794 bp[1] = s;
795 bp[0] = s >> 8;
796 }
797 break;
798 }
799
800}
801
802static void usbin_convert(struct usbin *u, unsigned char *buffer, unsigned int samples)
803{
804 union {
805 __s16 s[64];
806 unsigned char b[0];
807 } tmp;
808 unsigned int scnt, maxs, ufmtsh, dfmtsh;
809
810 ufmtsh = AFMT_BYTESSHIFT(u->format);
811 dfmtsh = AFMT_BYTESSHIFT(u->dma.format);
812 maxs = (AFMT_ISSTEREO(u->dma.format | u->format)) ? 32 : 64;
813 while (samples > 0) {
814 scnt = samples;
815 if (scnt > maxs)
816 scnt = maxs;
817 conversion(buffer, u->format, tmp.b, u->dma.format, tmp.b, scnt);
818 dmabuf_copyin(&u->dma, tmp.b, scnt << dfmtsh);
819 buffer += scnt << ufmtsh;
820 samples -= scnt;
821 }
822}
823
824static int usbin_prepare_desc(struct usbin *u, struct urb *urb)
825{
826 unsigned int i, maxsize, offs;
827
828 maxsize = (u->freqmax + 0x3fff) >> (14 - AFMT_BYTESSHIFT(u->format));
829 //printk(KERN_DEBUG "usbin_prepare_desc: maxsize %d freq 0x%x format 0x%x\n", maxsize, u->freqn, u->format);
830 for (i = offs = 0; i < DESCFRAMES; i++, offs += maxsize) {
831 urb->iso_frame_desc[i].length = maxsize;
832 urb->iso_frame_desc[i].offset = offs;
833 }
834 urb->interval = 1;
835 return 0;
836}
837
838/*
839 * return value: 0 if descriptor should be restarted, -1 otherwise
840 * convert sample format on the fly if necessary
841 */
842static int usbin_retire_desc(struct usbin *u, struct urb *urb)
843{
844 unsigned int i, ufmtsh, dfmtsh, err = 0, cnt, scnt, dmafree;
845 unsigned char *cp;
846
847 ufmtsh = AFMT_BYTESSHIFT(u->format);
848 dfmtsh = AFMT_BYTESSHIFT(u->dma.format);
849 for (i = 0; i < DESCFRAMES; i++) {
850 cp = ((unsigned char *)urb->transfer_buffer) + urb->iso_frame_desc[i].offset;
851 if (urb->iso_frame_desc[i].status) {
852 dprintk((KERN_DEBUG "usbin_retire_desc: frame %u status %d\n", i, urb->iso_frame_desc[i].status));
853 continue;
854 }
855 scnt = urb->iso_frame_desc[i].actual_length >> ufmtsh;
856 if (!scnt)
857 continue;
858 cnt = scnt << dfmtsh;
859 if (!u->dma.mapped) {
860 dmafree = u->dma.dmasize - u->dma.count;
861 if (cnt > dmafree) {
862 scnt = dmafree >> dfmtsh;
863 cnt = scnt << dfmtsh;
864 err++;
865 }
866 }
867 u->dma.count += cnt;
868 if (u->format == u->dma.format) {
869 /* we do not need format conversion */
870 dprintk((KERN_DEBUG "usbaudio: no sample format conversion\n"));
871 dmabuf_copyin(&u->dma, cp, cnt);
872 } else {
873 /* we need sampling format conversion */
874 dprintk((KERN_DEBUG "usbaudio: sample format conversion %x != %x\n", u->format, u->dma.format));
875 usbin_convert(u, cp, scnt);
876 }
877 }
878 if (err)
879 u->dma.error++;
880 if (u->dma.count >= (signed)u->dma.fragsize)
881 wake_up(&u->dma.wait);
882 return err ? -1 : 0;
883}
884
885static void usbin_completed(struct urb *urb, struct pt_regs *regs)
886{
887 struct usb_audiodev *as = (struct usb_audiodev *)urb->context;
888 struct usbin *u = &as->usbin;
889 unsigned long flags;
890 unsigned int mask;
891 int suret = 0;
892
893#if 0
894 printk(KERN_DEBUG "usbin_completed: status %d errcnt %d flags 0x%x\n", urb->status, urb->error_count, u->flags);
895#endif
896 if (urb == u->durb[0].urb)
897 mask = FLG_URB0RUNNING;
898 else if (urb == u->durb[1].urb)
899 mask = FLG_URB1RUNNING;
900 else {
901 mask = 0;
902 printk(KERN_ERR "usbin_completed: panic: unknown URB\n");
903 }
904 urb->dev = as->state->usbdev;
905 spin_lock_irqsave(&as->lock, flags);
906 if (!usbin_retire_desc(u, urb) &&
907 u->flags & FLG_RUNNING &&
908 !usbin_prepare_desc(u, urb) &&
909 (suret = usb_submit_urb(urb, GFP_ATOMIC)) == 0) {
910 u->flags |= mask;
911 } else {
912 u->flags &= ~(mask | FLG_RUNNING);
913 wake_up(&u->dma.wait);
914 printk(KERN_DEBUG "usbin_completed: descriptor not restarted (usb_submit_urb: %d)\n", suret);
915 }
916 spin_unlock_irqrestore(&as->lock, flags);
917}
918
919/*
920 * we output sync data
921 */
922static int usbin_sync_prepare_desc(struct usbin *u, struct urb *urb)
923{
924 unsigned char *cp = urb->transfer_buffer;
925 unsigned int i, offs;
926
927 for (i = offs = 0; i < SYNCFRAMES; i++, offs += 3, cp += 3) {
928 urb->iso_frame_desc[i].length = 3;
929 urb->iso_frame_desc[i].offset = offs;
930 cp[0] = u->freqn;
931 cp[1] = u->freqn >> 8;
932 cp[2] = u->freqn >> 16;
933 }
934 urb->interval = 1;
935 return 0;
936}
937
938/*
939 * return value: 0 if descriptor should be restarted, -1 otherwise
940 */
941static int usbin_sync_retire_desc(struct usbin *u, struct urb *urb)
942{
943 unsigned int i;
944
945 for (i = 0; i < SYNCFRAMES; i++)
946 if (urb->iso_frame_desc[0].status)
947 dprintk((KERN_DEBUG "usbin_sync_retire_desc: frame %u status %d\n", i, urb->iso_frame_desc[i].status));
948 return 0;
949}
950
951static void usbin_sync_completed(struct urb *urb, struct pt_regs *regs)
952{
953 struct usb_audiodev *as = (struct usb_audiodev *)urb->context;
954 struct usbin *u = &as->usbin;
955 unsigned long flags;
956 unsigned int mask;
957 int suret = 0;
958
959#if 0
960 printk(KERN_DEBUG "usbin_sync_completed: status %d errcnt %d flags 0x%x\n", urb->status, urb->error_count, u->flags);
961#endif
962 if (urb == u->surb[0].urb)
963 mask = FLG_SYNC0RUNNING;
964 else if (urb == u->surb[1].urb)
965 mask = FLG_SYNC1RUNNING;
966 else {
967 mask = 0;
968 printk(KERN_ERR "usbin_sync_completed: panic: unknown URB\n");
969 }
970 urb->dev = as->state->usbdev;
971 spin_lock_irqsave(&as->lock, flags);
972 if (!usbin_sync_retire_desc(u, urb) &&
973 u->flags & FLG_RUNNING &&
974 !usbin_sync_prepare_desc(u, urb) &&
975 (suret = usb_submit_urb(urb, GFP_ATOMIC)) == 0) {
976 u->flags |= mask;
977 } else {
978 u->flags &= ~(mask | FLG_RUNNING);
979 wake_up(&u->dma.wait);
980 dprintk((KERN_DEBUG "usbin_sync_completed: descriptor not restarted (usb_submit_urb: %d)\n", suret));
981 }
982 spin_unlock_irqrestore(&as->lock, flags);
983}
984
985static int usbin_start(struct usb_audiodev *as)
986{
987 struct usb_device *dev = as->state->usbdev;
988 struct usbin *u = &as->usbin;
989 struct urb *urb;
990 unsigned long flags;
991 unsigned int maxsze, bufsz;
992
993#if 0
994 printk(KERN_DEBUG "usbin_start: device %d ufmt 0x%08x dfmt 0x%08x srate %d\n",
995 dev->devnum, u->format, u->dma.format, u->dma.srate);
996#endif
997 /* allocate USB storage if not already done */
998 spin_lock_irqsave(&as->lock, flags);
999 if (!(u->flags & FLG_CONNECTED)) {
1000 spin_unlock_irqrestore(&as->lock, flags);
1001 return -EIO;
1002 }
1003 if (!(u->flags & FLG_RUNNING)) {
1004 spin_unlock_irqrestore(&as->lock, flags);
1005 u->freqn = ((u->dma.srate << 11) + 62) / 125; /* this will overflow at approx 2MSPS */
1006 u->freqmax = u->freqn + (u->freqn >> 2);
1007 u->phase = 0;
1008 maxsze = (u->freqmax + 0x3fff) >> (14 - AFMT_BYTESSHIFT(u->format));
1009 bufsz = DESCFRAMES * maxsze;
1010 kfree(u->durb[0].urb->transfer_buffer);
1011 u->durb[0].urb->transfer_buffer = kmalloc(bufsz, GFP_KERNEL);
1012 u->durb[0].urb->transfer_buffer_length = bufsz;
1013 kfree(u->durb[1].urb->transfer_buffer);
1014 u->durb[1].urb->transfer_buffer = kmalloc(bufsz, GFP_KERNEL);
1015 u->durb[1].urb->transfer_buffer_length = bufsz;
1016 if (u->syncpipe) {
1017 kfree(u->surb[0].urb->transfer_buffer);
1018 u->surb[0].urb->transfer_buffer = kmalloc(3*SYNCFRAMES, GFP_KERNEL);
1019 u->surb[0].urb->transfer_buffer_length = 3*SYNCFRAMES;
1020 kfree(u->surb[1].urb->transfer_buffer);
1021 u->surb[1].urb->transfer_buffer = kmalloc(3*SYNCFRAMES, GFP_KERNEL);
1022 u->surb[1].urb->transfer_buffer_length = 3*SYNCFRAMES;
1023 }
1024 if (!u->durb[0].urb->transfer_buffer || !u->durb[1].urb->transfer_buffer ||
1025 (u->syncpipe && (!u->surb[0].urb->transfer_buffer || !u->surb[1].urb->transfer_buffer))) {
1026 printk(KERN_ERR "usbaudio: cannot start playback device %d\n", dev->devnum);
1027 return 0;
1028 }
1029 spin_lock_irqsave(&as->lock, flags);
1030 }
1031 if (u->dma.count >= u->dma.dmasize && !u->dma.mapped) {
1032 spin_unlock_irqrestore(&as->lock, flags);
1033 return 0;
1034 }
1035 u->flags |= FLG_RUNNING;
1036 if (!(u->flags & FLG_URB0RUNNING)) {
1037 urb = u->durb[0].urb;
1038 urb->dev = dev;
1039 urb->pipe = u->datapipe;
1040 urb->transfer_flags = URB_ISO_ASAP;
1041 urb->number_of_packets = DESCFRAMES;
1042 urb->context = as;
1043 urb->complete = usbin_completed;
1044 if (!usbin_prepare_desc(u, urb) && !usb_submit_urb(urb, GFP_KERNEL))
1045 u->flags |= FLG_URB0RUNNING;
1046 else
1047 u->flags &= ~FLG_RUNNING;
1048 }
1049 if (u->flags & FLG_RUNNING && !(u->flags & FLG_URB1RUNNING)) {
1050 urb = u->durb[1].urb;
1051 urb->dev = dev;
1052 urb->pipe = u->datapipe;
1053 urb->transfer_flags = URB_ISO_ASAP;
1054 urb->number_of_packets = DESCFRAMES;
1055 urb->context = as;
1056 urb->complete = usbin_completed;
1057 if (!usbin_prepare_desc(u, urb) && !usb_submit_urb(urb, GFP_KERNEL))
1058 u->flags |= FLG_URB1RUNNING;
1059 else
1060 u->flags &= ~FLG_RUNNING;
1061 }
1062 if (u->syncpipe) {
1063 if (u->flags & FLG_RUNNING && !(u->flags & FLG_SYNC0RUNNING)) {
1064 urb = u->surb[0].urb;
1065 urb->dev = dev;
1066 urb->pipe = u->syncpipe;
1067 urb->transfer_flags = URB_ISO_ASAP;
1068 urb->number_of_packets = SYNCFRAMES;
1069 urb->context = as;
1070 urb->complete = usbin_sync_completed;
1071 /* stride: u->syncinterval */
1072 if (!usbin_sync_prepare_desc(u, urb) && !usb_submit_urb(urb, GFP_KERNEL))
1073 u->flags |= FLG_SYNC0RUNNING;
1074 else
1075 u->flags &= ~FLG_RUNNING;
1076 }
1077 if (u->flags & FLG_RUNNING && !(u->flags & FLG_SYNC1RUNNING)) {
1078 urb = u->surb[1].urb;
1079 urb->dev = dev;
1080 urb->pipe = u->syncpipe;
1081 urb->transfer_flags = URB_ISO_ASAP;
1082 urb->number_of_packets = SYNCFRAMES;
1083 urb->context = as;
1084 urb->complete = usbin_sync_completed;
1085 /* stride: u->syncinterval */
1086 if (!usbin_sync_prepare_desc(u, urb) && !usb_submit_urb(urb, GFP_KERNEL))
1087 u->flags |= FLG_SYNC1RUNNING;
1088 else
1089 u->flags &= ~FLG_RUNNING;
1090 }
1091 }
1092 spin_unlock_irqrestore(&as->lock, flags);
1093 return 0;
1094}
1095
1096static void usbout_stop(struct usb_audiodev *as)
1097{
1098 struct usbout *u = &as->usbout;
1099 unsigned long flags;
1100 unsigned int i, notkilled = 1;
1101
1102 spin_lock_irqsave(&as->lock, flags);
1103 u->flags &= ~FLG_RUNNING;
1104 i = u->flags;
1105 spin_unlock_irqrestore(&as->lock, flags);
1106 while (i & (FLG_URB0RUNNING|FLG_URB1RUNNING|FLG_SYNC0RUNNING|FLG_SYNC1RUNNING)) {
1107 if (notkilled)
1108 schedule_timeout_interruptible(1);
1109 else
1110 schedule_timeout_uninterruptible(1);
1111 spin_lock_irqsave(&as->lock, flags);
1112 i = u->flags;
1113 spin_unlock_irqrestore(&as->lock, flags);
1114 if (notkilled && signal_pending(current)) {
1115 if (i & FLG_URB0RUNNING)
1116 usb_kill_urb(u->durb[0].urb);
1117 if (i & FLG_URB1RUNNING)
1118 usb_kill_urb(u->durb[1].urb);
1119 if (i & FLG_SYNC0RUNNING)
1120 usb_kill_urb(u->surb[0].urb);
1121 if (i & FLG_SYNC1RUNNING)
1122 usb_kill_urb(u->surb[1].urb);
1123 notkilled = 0;
1124 }
1125 }
1126 set_current_state(TASK_RUNNING);
1127 kfree(u->durb[0].urb->transfer_buffer);
1128 kfree(u->durb[1].urb->transfer_buffer);
1129 kfree(u->surb[0].urb->transfer_buffer);
1130 kfree(u->surb[1].urb->transfer_buffer);
1131 u->durb[0].urb->transfer_buffer = u->durb[1].urb->transfer_buffer =
1132 u->surb[0].urb->transfer_buffer = u->surb[1].urb->transfer_buffer = NULL;
1133}
1134
1135static inline void usbout_release(struct usb_audiodev *as)
1136{
1137 usbout_stop(as);
1138}
1139
1140static void usbout_disc(struct usb_audiodev *as)
1141{
1142 struct usbout *u = &as->usbout;
1143 unsigned long flags;
1144
1145 spin_lock_irqsave(&as->lock, flags);
1146 u->flags &= ~(FLG_RUNNING | FLG_CONNECTED);
1147 spin_unlock_irqrestore(&as->lock, flags);
1148 usbout_stop(as);
1149}
1150
1151static void usbout_convert(struct usbout *u, unsigned char *buffer, unsigned int samples)
1152{
1153 union {
1154 __s16 s[64];
1155 unsigned char b[0];
1156 } tmp;
1157 unsigned int scnt, maxs, ufmtsh, dfmtsh;
1158
1159 ufmtsh = AFMT_BYTESSHIFT(u->format);
1160 dfmtsh = AFMT_BYTESSHIFT(u->dma.format);
1161 maxs = (AFMT_ISSTEREO(u->dma.format | u->format)) ? 32 : 64;
1162 while (samples > 0) {
1163 scnt = samples;
1164 if (scnt > maxs)
1165 scnt = maxs;
1166 dmabuf_copyout(&u->dma, tmp.b, scnt << dfmtsh);
1167 conversion(tmp.b, u->dma.format, buffer, u->format, tmp.b, scnt);
1168 buffer += scnt << ufmtsh;
1169 samples -= scnt;
1170 }
1171}
1172
1173static int usbout_prepare_desc(struct usbout *u, struct urb *urb)
1174{
1175 unsigned int i, ufmtsh, dfmtsh, err = 0, cnt, scnt, offs;
1176 unsigned char *cp = urb->transfer_buffer;
1177
1178 ufmtsh = AFMT_BYTESSHIFT(u->format);
1179 dfmtsh = AFMT_BYTESSHIFT(u->dma.format);
1180 for (i = offs = 0; i < DESCFRAMES; i++) {
1181 urb->iso_frame_desc[i].offset = offs;
1182 u->phase = (u->phase & 0x3fff) + u->freqm;
1183 scnt = u->phase >> 14;
1184 if (!scnt) {
1185 urb->iso_frame_desc[i].length = 0;
1186 continue;
1187 }
1188 cnt = scnt << dfmtsh;
1189 if (!u->dma.mapped) {
1190 if (cnt > u->dma.count) {
1191 scnt = u->dma.count >> dfmtsh;
1192 cnt = scnt << dfmtsh;
1193 err++;
1194 }
1195 u->dma.count -= cnt;
1196 } else
1197 u->dma.count += cnt;
1198 if (u->format == u->dma.format) {
1199 /* we do not need format conversion */
1200 dmabuf_copyout(&u->dma, cp, cnt);
1201 } else {
1202 /* we need sampling format conversion */
1203 usbout_convert(u, cp, scnt);
1204 }
1205 cnt = scnt << ufmtsh;
1206 urb->iso_frame_desc[i].length = cnt;
1207 offs += cnt;
1208 cp += cnt;
1209 }
1210 urb->interval = 1;
1211 if (err)
1212 u->dma.error++;
1213 if (u->dma.mapped) {
1214 if (u->dma.count >= (signed)u->dma.fragsize)
1215 wake_up(&u->dma.wait);
1216 } else {
1217 if ((signed)u->dma.dmasize >= u->dma.count + (signed)u->dma.fragsize)
1218 wake_up(&u->dma.wait);
1219 }
1220 return err ? -1 : 0;
1221}
1222
1223/*
1224 * return value: 0 if descriptor should be restarted, -1 otherwise
1225 */
1226static int usbout_retire_desc(struct usbout *u, struct urb *urb)
1227{
1228 unsigned int i;
1229
1230 for (i = 0; i < DESCFRAMES; i++) {
1231 if (urb->iso_frame_desc[i].status) {
1232 dprintk((KERN_DEBUG "usbout_retire_desc: frame %u status %d\n", i, urb->iso_frame_desc[i].status));
1233 continue;
1234 }
1235 }
1236 return 0;
1237}
1238
1239static void usbout_completed(struct urb *urb, struct pt_regs *regs)
1240{
1241 struct usb_audiodev *as = (struct usb_audiodev *)urb->context;
1242 struct usbout *u = &as->usbout;
1243 unsigned long flags;
1244 unsigned int mask;
1245 int suret = 0;
1246
1247#if 0
1248 printk(KERN_DEBUG "usbout_completed: status %d errcnt %d flags 0x%x\n", urb->status, urb->error_count, u->flags);
1249#endif
1250 if (urb == u->durb[0].urb)
1251 mask = FLG_URB0RUNNING;
1252 else if (urb == u->durb[1].urb)
1253 mask = FLG_URB1RUNNING;
1254 else {
1255 mask = 0;
1256 printk(KERN_ERR "usbout_completed: panic: unknown URB\n");
1257 }
1258 urb->dev = as->state->usbdev;
1259 spin_lock_irqsave(&as->lock, flags);
1260 if (!usbout_retire_desc(u, urb) &&
1261 u->flags & FLG_RUNNING &&
1262 !usbout_prepare_desc(u, urb) &&
1263 (suret = usb_submit_urb(urb, GFP_ATOMIC)) == 0) {
1264 u->flags |= mask;
1265 } else {
1266 u->flags &= ~(mask | FLG_RUNNING);
1267 wake_up(&u->dma.wait);
1268 dprintk((KERN_DEBUG "usbout_completed: descriptor not restarted (usb_submit_urb: %d)\n", suret));
1269 }
1270 spin_unlock_irqrestore(&as->lock, flags);
1271}
1272
1273static int usbout_sync_prepare_desc(struct usbout *u, struct urb *urb)
1274{
1275 unsigned int i, offs;
1276
1277 for (i = offs = 0; i < SYNCFRAMES; i++, offs += 3) {
1278 urb->iso_frame_desc[i].length = 3;
1279 urb->iso_frame_desc[i].offset = offs;
1280 }
1281 urb->interval = 1;
1282 return 0;
1283}
1284
1285/*
1286 * return value: 0 if descriptor should be restarted, -1 otherwise
1287 */
1288static int usbout_sync_retire_desc(struct usbout *u, struct urb *urb)
1289{
1290 unsigned char *cp = urb->transfer_buffer;
1291 unsigned int f, i;
1292
1293 for (i = 0; i < SYNCFRAMES; i++, cp += 3) {
1294 if (urb->iso_frame_desc[i].status) {
1295 dprintk((KERN_DEBUG "usbout_sync_retire_desc: frame %u status %d\n", i, urb->iso_frame_desc[i].status));
1296 continue;
1297 }
1298 if (urb->iso_frame_desc[i].actual_length < 3) {
1299 dprintk((KERN_DEBUG "usbout_sync_retire_desc: frame %u length %d\n", i, urb->iso_frame_desc[i].actual_length));
1300 continue;
1301 }
1302 f = cp[0] | (cp[1] << 8) | (cp[2] << 16);
1303 if (abs(f - u->freqn) > (u->freqn >> 3) || f > u->freqmax) {
1304 printk(KERN_WARNING "usbout_sync_retire_desc: requested frequency %u (nominal %u) out of range!\n", f, u->freqn);
1305 continue;
1306 }
1307 u->freqm = f;
1308 }
1309 return 0;
1310}
1311
1312static void usbout_sync_completed(struct urb *urb, struct pt_regs *regs)
1313{
1314 struct usb_audiodev *as = (struct usb_audiodev *)urb->context;
1315 struct usbout *u = &as->usbout;
1316 unsigned long flags;
1317 unsigned int mask;
1318 int suret = 0;
1319
1320#if 0
1321 printk(KERN_DEBUG "usbout_sync_completed: status %d errcnt %d flags 0x%x\n", urb->status, urb->error_count, u->flags);
1322#endif
1323 if (urb == u->surb[0].urb)
1324 mask = FLG_SYNC0RUNNING;
1325 else if (urb == u->surb[1].urb)
1326 mask = FLG_SYNC1RUNNING;
1327 else {
1328 mask = 0;
1329 printk(KERN_ERR "usbout_sync_completed: panic: unknown URB\n");
1330 }
1331 urb->dev = as->state->usbdev;
1332 spin_lock_irqsave(&as->lock, flags);
1333 if (!usbout_sync_retire_desc(u, urb) &&
1334 u->flags & FLG_RUNNING &&
1335 !usbout_sync_prepare_desc(u, urb) &&
1336 (suret = usb_submit_urb(urb, GFP_ATOMIC)) == 0) {
1337 u->flags |= mask;
1338 } else {
1339 u->flags &= ~(mask | FLG_RUNNING);
1340 wake_up(&u->dma.wait);
1341 dprintk((KERN_DEBUG "usbout_sync_completed: descriptor not restarted (usb_submit_urb: %d)\n", suret));
1342 }
1343 spin_unlock_irqrestore(&as->lock, flags);
1344}
1345
1346static int usbout_start(struct usb_audiodev *as)
1347{
1348 struct usb_device *dev = as->state->usbdev;
1349 struct usbout *u = &as->usbout;
1350 struct urb *urb;
1351 unsigned long flags;
1352 unsigned int maxsze, bufsz;
1353
1354#if 0
1355 printk(KERN_DEBUG "usbout_start: device %d ufmt 0x%08x dfmt 0x%08x srate %d\n",
1356 dev->devnum, u->format, u->dma.format, u->dma.srate);
1357#endif
1358 /* allocate USB storage if not already done */
1359 spin_lock_irqsave(&as->lock, flags);
1360 if (!(u->flags & FLG_CONNECTED)) {
1361 spin_unlock_irqrestore(&as->lock, flags);
1362 return -EIO;
1363 }
1364 if (!(u->flags & FLG_RUNNING)) {
1365 spin_unlock_irqrestore(&as->lock, flags);
1366 u->freqn = u->freqm = ((u->dma.srate << 11) + 62) / 125; /* this will overflow at approx 2MSPS */
1367 u->freqmax = u->freqn + (u->freqn >> 2);
1368 u->phase = 0;
1369 maxsze = (u->freqmax + 0x3fff) >> (14 - AFMT_BYTESSHIFT(u->format));
1370 bufsz = DESCFRAMES * maxsze;
1371 kfree(u->durb[0].urb->transfer_buffer);
1372 u->durb[0].urb->transfer_buffer = kmalloc(bufsz, GFP_KERNEL);
1373 u->durb[0].urb->transfer_buffer_length = bufsz;
1374 kfree(u->durb[1].urb->transfer_buffer);
1375 u->durb[1].urb->transfer_buffer = kmalloc(bufsz, GFP_KERNEL);
1376 u->durb[1].urb->transfer_buffer_length = bufsz;
1377 if (u->syncpipe) {
1378 kfree(u->surb[0].urb->transfer_buffer);
1379 u->surb[0].urb->transfer_buffer = kmalloc(3*SYNCFRAMES, GFP_KERNEL);
1380 u->surb[0].urb->transfer_buffer_length = 3*SYNCFRAMES;
1381 kfree(u->surb[1].urb->transfer_buffer);
1382 u->surb[1].urb->transfer_buffer = kmalloc(3*SYNCFRAMES, GFP_KERNEL);
1383 u->surb[1].urb->transfer_buffer_length = 3*SYNCFRAMES;
1384 }
1385 if (!u->durb[0].urb->transfer_buffer || !u->durb[1].urb->transfer_buffer ||
1386 (u->syncpipe && (!u->surb[0].urb->transfer_buffer || !u->surb[1].urb->transfer_buffer))) {
1387 printk(KERN_ERR "usbaudio: cannot start playback device %d\n", dev->devnum);
1388 return 0;
1389 }
1390 spin_lock_irqsave(&as->lock, flags);
1391 }
1392 if (u->dma.count <= 0 && !u->dma.mapped) {
1393 spin_unlock_irqrestore(&as->lock, flags);
1394 return 0;
1395 }
1396 u->flags |= FLG_RUNNING;
1397 if (!(u->flags & FLG_URB0RUNNING)) {
1398 urb = u->durb[0].urb;
1399 urb->dev = dev;
1400 urb->pipe = u->datapipe;
1401 urb->transfer_flags = URB_ISO_ASAP;
1402 urb->number_of_packets = DESCFRAMES;
1403 urb->context = as;
1404 urb->complete = usbout_completed;
1405 if (!usbout_prepare_desc(u, urb) && !usb_submit_urb(urb, GFP_ATOMIC))
1406 u->flags |= FLG_URB0RUNNING;
1407 else
1408 u->flags &= ~FLG_RUNNING;
1409 }
1410 if (u->flags & FLG_RUNNING && !(u->flags & FLG_URB1RUNNING)) {
1411 urb = u->durb[1].urb;
1412 urb->dev = dev;
1413 urb->pipe = u->datapipe;
1414 urb->transfer_flags = URB_ISO_ASAP;
1415 urb->number_of_packets = DESCFRAMES;
1416 urb->context = as;
1417 urb->complete = usbout_completed;
1418 if (!usbout_prepare_desc(u, urb) && !usb_submit_urb(urb, GFP_ATOMIC))
1419 u->flags |= FLG_URB1RUNNING;
1420 else
1421 u->flags &= ~FLG_RUNNING;
1422 }
1423 if (u->syncpipe) {
1424 if (u->flags & FLG_RUNNING && !(u->flags & FLG_SYNC0RUNNING)) {
1425 urb = u->surb[0].urb;
1426 urb->dev = dev;
1427 urb->pipe = u->syncpipe;
1428 urb->transfer_flags = URB_ISO_ASAP;
1429 urb->number_of_packets = SYNCFRAMES;
1430 urb->context = as;
1431 urb->complete = usbout_sync_completed;
1432 /* stride: u->syncinterval */
1433 if (!usbout_sync_prepare_desc(u, urb) && !usb_submit_urb(urb, GFP_ATOMIC))
1434 u->flags |= FLG_SYNC0RUNNING;
1435 else
1436 u->flags &= ~FLG_RUNNING;
1437 }
1438 if (u->flags & FLG_RUNNING && !(u->flags & FLG_SYNC1RUNNING)) {
1439 urb = u->surb[1].urb;
1440 urb->dev = dev;
1441 urb->pipe = u->syncpipe;
1442 urb->transfer_flags = URB_ISO_ASAP;
1443 urb->number_of_packets = SYNCFRAMES;
1444 urb->context = as;
1445 urb->complete = usbout_sync_completed;
1446 /* stride: u->syncinterval */
1447 if (!usbout_sync_prepare_desc(u, urb) && !usb_submit_urb(urb, GFP_ATOMIC))
1448 u->flags |= FLG_SYNC1RUNNING;
1449 else
1450 u->flags &= ~FLG_RUNNING;
1451 }
1452 }
1453 spin_unlock_irqrestore(&as->lock, flags);
1454 return 0;
1455}
1456
1457/* --------------------------------------------------------------------- */
1458
1459static unsigned int format_goodness(struct audioformat *afp, unsigned int fmt, unsigned int srate)
1460{
1461 unsigned int g = 0;
1462
1463 if (srate < afp->sratelo)
1464 g += afp->sratelo - srate;
1465 if (srate > afp->sratehi)
1466 g += srate - afp->sratehi;
1467 if (AFMT_ISSTEREO(afp->format) && !AFMT_ISSTEREO(fmt))
1468 g += 0x100000;
1469 if (!AFMT_ISSTEREO(afp->format) && AFMT_ISSTEREO(fmt))
1470 g += 0x400000;
1471 if (AFMT_IS16BIT(afp->format) && !AFMT_IS16BIT(fmt))
1472 g += 0x100000;
1473 if (!AFMT_IS16BIT(afp->format) && AFMT_IS16BIT(fmt))
1474 g += 0x400000;
1475 return g;
1476}
1477
1478static int find_format(struct audioformat *afp, unsigned int nr, unsigned int fmt, unsigned int srate)
1479{
1480 unsigned int i, g, gb = ~0;
1481 int j = -1; /* default to failure */
1482
1483 /* find "best" format (according to format_goodness) */
1484 for (i = 0; i < nr; i++) {
1485 g = format_goodness(&afp[i], fmt, srate);
1486 if (g >= gb)
1487 continue;
1488 j = i;
1489 gb = g;
1490 }
1491 return j;
1492}
1493
1494static int set_format_in(struct usb_audiodev *as)
1495{
1496 struct usb_device *dev = as->state->usbdev;
1497 struct usb_host_interface *alts;
1498 struct usb_interface *iface;
1499 struct usbin *u = &as->usbin;
1500 struct dmabuf *d = &u->dma;
1501 struct audioformat *fmt;
1502 unsigned int ep;
1503 unsigned char data[3];
1504 int fmtnr, ret;
1505
1506 iface = usb_ifnum_to_if(dev, u->interface);
1507 if (!iface)
1508 return 0;
1509
1510 fmtnr = find_format(as->fmtin, as->numfmtin, d->format, d->srate);
1511 if (fmtnr < 0) {
1512 printk(KERN_ERR "usbaudio: set_format_in(): failed to find desired format/speed combination.\n");
1513 return -1;
1514 }
1515
1516 fmt = as->fmtin + fmtnr;
1517 alts = usb_altnum_to_altsetting(iface, fmt->altsetting);
1518 u->format = fmt->format;
1519 u->datapipe = usb_rcvisocpipe(dev, alts->endpoint[0].desc.bEndpointAddress & 0xf);
1520 u->syncpipe = u->syncinterval = 0;
1521 if ((alts->endpoint[0].desc.bmAttributes & 0x0c) == 0x08) {
1522 if (alts->desc.bNumEndpoints < 2 ||
1523 alts->endpoint[1].desc.bmAttributes != 0x01 ||
1524 alts->endpoint[1].desc.bSynchAddress != 0 ||
1525 alts->endpoint[1].desc.bEndpointAddress != (alts->endpoint[0].desc.bSynchAddress & 0x7f)) {
1526 printk(KERN_WARNING "usbaudio: device %d interface %d altsetting %d claims adaptive in "
1527 "but has invalid synch pipe; treating as asynchronous in\n",
1528 dev->devnum, u->interface, fmt->altsetting);
1529 } else {
1530 u->syncpipe = usb_sndisocpipe(dev, alts->endpoint[1].desc.bEndpointAddress & 0xf);
1531 u->syncinterval = alts->endpoint[1].desc.bRefresh;
1532 }
1533 }
1534 if (d->srate < fmt->sratelo)
1535 d->srate = fmt->sratelo;
1536 if (d->srate > fmt->sratehi)
1537 d->srate = fmt->sratehi;
1538 dprintk((KERN_DEBUG "usbaudio: set_format_in: usb_set_interface %u %u\n",
1539 u->interface, fmt->altsetting));
1540 if (usb_set_interface(dev, alts->desc.bInterfaceNumber, fmt->altsetting) < 0) {
1541 printk(KERN_WARNING "usbaudio: usb_set_interface failed, device %d interface %d altsetting %d\n",
1542 dev->devnum, u->interface, fmt->altsetting);
1543 return -1;
1544 }
1545 if (fmt->sratelo == fmt->sratehi)
1546 return 0;
1547 ep = usb_pipeendpoint(u->datapipe) | (u->datapipe & USB_DIR_IN);
1548 /* if endpoint has pitch control, enable it */
1549 if (fmt->attributes & 0x02) {
1550 data[0] = 1;
1551 if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
1552 PITCH_CONTROL << 8, ep, data, 1, 1000)) < 0) {
1553 printk(KERN_ERR "usbaudio: failure (error %d) to set output pitch control device %d interface %u endpoint 0x%x to %u\n",
1554 ret, dev->devnum, u->interface, ep, d->srate);
1555 return -1;
1556 }
1557 }
1558 /* if endpoint has sampling rate control, set it */
1559 if (fmt->attributes & 0x01) {
1560 data[0] = d->srate;
1561 data[1] = d->srate >> 8;
1562 data[2] = d->srate >> 16;
1563 if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
1564 SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) {
1565 printk(KERN_ERR "usbaudio: failure (error %d) to set input sampling frequency device %d interface %u endpoint 0x%x to %u\n",
1566 ret, dev->devnum, u->interface, ep, d->srate);
1567 return -1;
1568 }
1569 if ((ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR, USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_IN,
1570 SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) {
1571 printk(KERN_ERR "usbaudio: failure (error %d) to get input sampling frequency device %d interface %u endpoint 0x%x\n",
1572 ret, dev->devnum, u->interface, ep);
1573 return -1;
1574 }
1575 dprintk((KERN_DEBUG "usbaudio: set_format_in: device %d interface %d altsetting %d srate req: %u real %u\n",
1576 dev->devnum, u->interface, fmt->altsetting, d->srate, data[0] | (data[1] << 8) | (data[2] << 16)));
1577 d->srate = data[0] | (data[1] << 8) | (data[2] << 16);
1578 }
1579 dprintk((KERN_DEBUG "usbaudio: set_format_in: USB format 0x%x, DMA format 0x%x srate %u\n", u->format, d->format, d->srate));
1580 return 0;
1581}
1582
1583static int set_format_out(struct usb_audiodev *as)
1584{
1585 struct usb_device *dev = as->state->usbdev;
1586 struct usb_host_interface *alts;
1587 struct usb_interface *iface;
1588 struct usbout *u = &as->usbout;
1589 struct dmabuf *d = &u->dma;
1590 struct audioformat *fmt;
1591 unsigned int ep;
1592 unsigned char data[3];
1593 int fmtnr, ret;
1594
1595 iface = usb_ifnum_to_if(dev, u->interface);
1596 if (!iface)
1597 return 0;
1598
1599 fmtnr = find_format(as->fmtout, as->numfmtout, d->format, d->srate);
1600 if (fmtnr < 0) {
1601 printk(KERN_ERR "usbaudio: set_format_out(): failed to find desired format/speed combination.\n");
1602 return -1;
1603 }
1604
1605 fmt = as->fmtout + fmtnr;
1606 u->format = fmt->format;
1607 alts = usb_altnum_to_altsetting(iface, fmt->altsetting);
1608 u->datapipe = usb_sndisocpipe(dev, alts->endpoint[0].desc.bEndpointAddress & 0xf);
1609 u->syncpipe = u->syncinterval = 0;
1610 if ((alts->endpoint[0].desc.bmAttributes & 0x0c) == 0x04) {
1611#if 0
1612 printk(KERN_DEBUG "bNumEndpoints 0x%02x endpoint[1].bmAttributes 0x%02x\n"
1613 KERN_DEBUG "endpoint[1].bSynchAddress 0x%02x endpoint[1].bEndpointAddress 0x%02x\n"
1614 KERN_DEBUG "endpoint[0].bSynchAddress 0x%02x\n", alts->bNumEndpoints,
1615 alts->endpoint[1].bmAttributes, alts->endpoint[1].bSynchAddress,
1616 alts->endpoint[1].bEndpointAddress, alts->endpoint[0].bSynchAddress);
1617#endif
1618 if (alts->desc.bNumEndpoints < 2 ||
1619 alts->endpoint[1].desc.bmAttributes != 0x01 ||
1620 alts->endpoint[1].desc.bSynchAddress != 0 ||
1621 alts->endpoint[1].desc.bEndpointAddress != (alts->endpoint[0].desc.bSynchAddress | 0x80)) {
1622 printk(KERN_WARNING "usbaudio: device %d interface %d altsetting %d claims asynch out "
1623 "but has invalid synch pipe; treating as adaptive out\n",
1624 dev->devnum, u->interface, fmt->altsetting);
1625 } else {
1626 u->syncpipe = usb_rcvisocpipe(dev, alts->endpoint[1].desc.bEndpointAddress & 0xf);
1627 u->syncinterval = alts->endpoint[1].desc.bRefresh;
1628 }
1629 }
1630 if (d->srate < fmt->sratelo)
1631 d->srate = fmt->sratelo;
1632 if (d->srate > fmt->sratehi)
1633 d->srate = fmt->sratehi;
1634 dprintk((KERN_DEBUG "usbaudio: set_format_out: usb_set_interface %u %u\n",
1635 u->interface, fmt->altsetting));
1636 if (usb_set_interface(dev, u->interface, fmt->altsetting) < 0) {
1637 printk(KERN_WARNING "usbaudio: usb_set_interface failed, device %d interface %d altsetting %d\n",
1638 dev->devnum, u->interface, fmt->altsetting);
1639 return -1;
1640 }
1641 if (fmt->sratelo == fmt->sratehi)
1642 return 0;
1643 ep = usb_pipeendpoint(u->datapipe) | (u->datapipe & USB_DIR_IN);
1644 /* if endpoint has pitch control, enable it */
1645 if (fmt->attributes & 0x02) {
1646 data[0] = 1;
1647 if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
1648 PITCH_CONTROL << 8, ep, data, 1, 1000)) < 0) {
1649 printk(KERN_ERR "usbaudio: failure (error %d) to set output pitch control device %d interface %u endpoint 0x%x to %u\n",
1650 ret, dev->devnum, u->interface, ep, d->srate);
1651 return -1;
1652 }
1653 }
1654 /* if endpoint has sampling rate control, set it */
1655 if (fmt->attributes & 0x01) {
1656 data[0] = d->srate;
1657 data[1] = d->srate >> 8;
1658 data[2] = d->srate >> 16;
1659 if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
1660 SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) {
1661 printk(KERN_ERR "usbaudio: failure (error %d) to set output sampling frequency device %d interface %u endpoint 0x%x to %u\n",
1662 ret, dev->devnum, u->interface, ep, d->srate);
1663 return -1;
1664 }
1665 if ((ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR, USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_IN,
1666 SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) {
1667 printk(KERN_ERR "usbaudio: failure (error %d) to get output sampling frequency device %d interface %u endpoint 0x%x\n",
1668 ret, dev->devnum, u->interface, ep);
1669 return -1;
1670 }
1671 dprintk((KERN_DEBUG "usbaudio: set_format_out: device %d interface %d altsetting %d srate req: %u real %u\n",
1672 dev->devnum, u->interface, fmt->altsetting, d->srate, data[0] | (data[1] << 8) | (data[2] << 16)));
1673 d->srate = data[0] | (data[1] << 8) | (data[2] << 16);
1674 }
1675 dprintk((KERN_DEBUG "usbaudio: set_format_out: USB format 0x%x, DMA format 0x%x srate %u\n", u->format, d->format, d->srate));
1676 return 0;
1677}
1678
1679static int set_format(struct usb_audiodev *s, unsigned int fmode, unsigned int fmt, unsigned int srate)
1680{
1681 int ret1 = 0, ret2 = 0;
1682
1683 if (!(fmode & (FMODE_READ|FMODE_WRITE)))
1684 return -EINVAL;
1685 if (fmode & FMODE_READ) {
1686 usbin_stop(s);
1687 s->usbin.dma.ready = 0;
1688 if (fmt == AFMT_QUERY)
1689 fmt = s->usbin.dma.format;
1690 else
1691 s->usbin.dma.format = fmt;
1692 if (!srate)
1693 srate = s->usbin.dma.srate;
1694 else
1695 s->usbin.dma.srate = srate;
1696 }
1697 if (fmode & FMODE_WRITE) {
1698 usbout_stop(s);
1699 s->usbout.dma.ready = 0;
1700 if (fmt == AFMT_QUERY)
1701 fmt = s->usbout.dma.format;
1702 else
1703 s->usbout.dma.format = fmt;
1704 if (!srate)
1705 srate = s->usbout.dma.srate;
1706 else
1707 s->usbout.dma.srate = srate;
1708 }
1709 if (fmode & FMODE_READ)
1710 ret1 = set_format_in(s);
1711 if (fmode & FMODE_WRITE)
1712 ret2 = set_format_out(s);
1713 return ret1 ? ret1 : ret2;
1714}
1715
1716/* --------------------------------------------------------------------- */
1717
1718static int wrmixer(struct usb_mixerdev *ms, unsigned mixch, unsigned value)
1719{
1720 struct usb_device *dev = ms->state->usbdev;
1721 unsigned char data[2];
1722 struct mixerchannel *ch;
1723 int v1, v2, v3;
1724
1725 if (mixch >= ms->numch)
1726 return -1;
1727 ch = &ms->ch[mixch];
1728 v3 = ch->maxval - ch->minval;
1729 v1 = value & 0xff;
1730 v2 = (value >> 8) & 0xff;
1731 if (v1 > 100)
1732 v1 = 100;
1733 if (v2 > 100)
1734 v2 = 100;
1735 if (!(ch->flags & (MIXFLG_STEREOIN | MIXFLG_STEREOOUT)))
1736 v2 = v1;
1737 ch->value = v1 | (v2 << 8);
1738 v1 = (v1 * v3) / 100 + ch->minval;
1739 v2 = (v2 * v3) / 100 + ch->minval;
1740 switch (ch->selector) {
1741 case 0: /* mixer unit request */
1742 data[0] = v1;
1743 data[1] = v1 >> 8;
1744 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1745 (ch->chnum << 8) | 1, ms->iface | (ch->unitid << 8), data, 2, 1000) < 0)
1746 goto err;
1747 if (!(ch->flags & (MIXFLG_STEREOIN | MIXFLG_STEREOOUT)))
1748 return 0;
1749 data[0] = v2;
1750 data[1] = v2 >> 8;
1751 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1752 ((ch->chnum + !!(ch->flags & MIXFLG_STEREOIN)) << 8) | (1 + !!(ch->flags & MIXFLG_STEREOOUT)),
1753 ms->iface | (ch->unitid << 8), data, 2, 1000) < 0)
1754 goto err;
1755 return 0;
1756
1757 /* various feature unit controls */
1758 case VOLUME_CONTROL:
1759 data[0] = v1;
1760 data[1] = v1 >> 8;
1761 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1762 (ch->selector << 8) | ch->chnum, ms->iface | (ch->unitid << 8), data, 2, 1000) < 0)
1763 goto err;
1764 if (!(ch->flags & (MIXFLG_STEREOIN | MIXFLG_STEREOOUT)))
1765 return 0;
1766 data[0] = v2;
1767 data[1] = v2 >> 8;
1768 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1769 (ch->selector << 8) | (ch->chnum + 1), ms->iface | (ch->unitid << 8), data, 2, 1000) < 0)
1770 goto err;
1771 return 0;
1772
1773 case BASS_CONTROL:
1774 case MID_CONTROL:
1775 case TREBLE_CONTROL:
1776 data[0] = v1 >> 8;
1777 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1778 (ch->selector << 8) | ch->chnum, ms->iface | (ch->unitid << 8), data, 1, 1000) < 0)
1779 goto err;
1780 if (!(ch->flags & (MIXFLG_STEREOIN | MIXFLG_STEREOOUT)))
1781 return 0;
1782 data[0] = v2 >> 8;
1783 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1784 (ch->selector << 8) | (ch->chnum + 1), ms->iface | (ch->unitid << 8), data, 1, 1000) < 0)
1785 goto err;
1786 return 0;
1787
1788 default:
1789 return -1;
1790 }
1791 return 0;
1792
1793 err:
1794 printk(KERN_ERR "usbaudio: mixer request device %u if %u unit %u ch %u selector %u failed\n",
1795 dev->devnum, ms->iface, ch->unitid, ch->chnum, ch->selector);
1796 return -1;
1797}
1798
1799static int get_rec_src(struct usb_mixerdev *ms)
1800{
1801 struct usb_device *dev = ms->state->usbdev;
1802 unsigned int mask = 0, retmask = 0;
1803 unsigned int i, j;
1804 unsigned char buf;
1805 int err = 0;
1806
1807 for (i = 0; i < ms->numch; i++) {
1808 if (!ms->ch[i].slctunitid || (mask & (1 << i)))
1809 continue;
1810 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
1811 0, ms->iface | (ms->ch[i].slctunitid << 8), &buf, 1, 1000) < 0) {
1812 err = -EIO;
1813 printk(KERN_ERR "usbaudio: selector read request device %u if %u unit %u failed\n",
1814 dev->devnum, ms->iface, ms->ch[i].slctunitid & 0xff);
1815 continue;
1816 }
1817 for (j = i; j < ms->numch; j++) {
1818 if ((ms->ch[i].slctunitid ^ ms->ch[j].slctunitid) & 0xff)
1819 continue;
1820 mask |= 1 << j;
1821 if (buf == (ms->ch[j].slctunitid >> 8))
1822 retmask |= 1 << ms->ch[j].osschannel;
1823 }
1824 }
1825 if (err)
1826 return -EIO;
1827 return retmask;
1828}
1829
1830static int set_rec_src(struct usb_mixerdev *ms, int srcmask)
1831{
1832 struct usb_device *dev = ms->state->usbdev;
1833 unsigned int mask = 0, smask, bmask;
1834 unsigned int i, j;
1835 unsigned char buf;
1836 int err = 0;
1837
1838 for (i = 0; i < ms->numch; i++) {
1839 if (!ms->ch[i].slctunitid || (mask & (1 << i)))
1840 continue;
1841 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
1842 0, ms->iface | (ms->ch[i].slctunitid << 8), &buf, 1, 1000) < 0) {
1843 err = -EIO;
1844 printk(KERN_ERR "usbaudio: selector read request device %u if %u unit %u failed\n",
1845 dev->devnum, ms->iface, ms->ch[i].slctunitid & 0xff);
1846 continue;
1847 }
1848 /* first generate smask */
1849 smask = bmask = 0;
1850 for (j = i; j < ms->numch; j++) {
1851 if ((ms->ch[i].slctunitid ^ ms->ch[j].slctunitid) & 0xff)
1852 continue;
1853 smask |= 1 << ms->ch[j].osschannel;
1854 if (buf == (ms->ch[j].slctunitid >> 8))
1855 bmask |= 1 << ms->ch[j].osschannel;
1856 mask |= 1 << j;
1857 }
1858 /* check for multiple set sources */
1859 j = hweight32(srcmask & smask);
1860 if (j == 0)
1861 continue;
1862 if (j > 1)
1863 srcmask &= ~bmask;
1864 for (j = i; j < ms->numch; j++) {
1865 if ((ms->ch[i].slctunitid ^ ms->ch[j].slctunitid) & 0xff)
1866 continue;
1867 if (!(srcmask & (1 << ms->ch[j].osschannel)))
1868 continue;
1869 buf = ms->ch[j].slctunitid >> 8;
1870 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1871 0, ms->iface | (ms->ch[j].slctunitid << 8), &buf, 1, 1000) < 0) {
1872 err = -EIO;
1873 printk(KERN_ERR "usbaudio: selector write request device %u if %u unit %u failed\n",
1874 dev->devnum, ms->iface, ms->ch[j].slctunitid & 0xff);
1875 continue;
1876 }
1877 }
1878 }
1879 return err ? -EIO : 0;
1880}
1881
1882/* --------------------------------------------------------------------- */
1883
1884/*
1885 * should be called with open_sem hold, so that no new processes
1886 * look at the audio device to be destroyed
1887 */
1888
1889static void release(struct usb_audio_state *s)
1890{
1891 struct usb_audiodev *as;
1892 struct usb_mixerdev *ms;
1893
1894 s->count--;
1895 if (s->count) {
1896 up(&open_sem);
1897 return;
1898 }
1899 up(&open_sem);
1900 wake_up(&open_wait);
1901 while (!list_empty(&s->audiolist)) {
1902 as = list_entry(s->audiolist.next, struct usb_audiodev, list);
1903 list_del(&as->list);
1904 usbin_release(as);
1905 usbout_release(as);
1906 dmabuf_release(&as->usbin.dma);
1907 dmabuf_release(&as->usbout.dma);
1908 usb_free_urb(as->usbin.durb[0].urb);
1909 usb_free_urb(as->usbin.durb[1].urb);
1910 usb_free_urb(as->usbin.surb[0].urb);
1911 usb_free_urb(as->usbin.surb[1].urb);
1912 usb_free_urb(as->usbout.durb[0].urb);
1913 usb_free_urb(as->usbout.durb[1].urb);
1914 usb_free_urb(as->usbout.surb[0].urb);
1915 usb_free_urb(as->usbout.surb[1].urb);
1916 kfree(as);
1917 }
1918 while (!list_empty(&s->mixerlist)) {
1919 ms = list_entry(s->mixerlist.next, struct usb_mixerdev, list);
1920 list_del(&ms->list);
1921 kfree(ms);
1922 }
1923 kfree(s);
1924}
1925
1926static inline int prog_dmabuf_in(struct usb_audiodev *as)
1927{
1928 usbin_stop(as);
1929 return dmabuf_init(&as->usbin.dma);
1930}
1931
1932static inline int prog_dmabuf_out(struct usb_audiodev *as)
1933{
1934 usbout_stop(as);
1935 return dmabuf_init(&as->usbout.dma);
1936}
1937
1938/* --------------------------------------------------------------------- */
1939
1940static int usb_audio_open_mixdev(struct inode *inode, struct file *file)
1941{
1942 unsigned int minor = iminor(inode);
1943 struct usb_mixerdev *ms;
1944 struct usb_audio_state *s;
1945
1946 down(&open_sem);
1947 list_for_each_entry(s, &audiodevs, audiodev) {
1948 list_for_each_entry(ms, &s->mixerlist, list) {
1949 if (ms->dev_mixer == minor)
1950 goto mixer_found;
1951 }
1952 }
1953 up(&open_sem);
1954 return -ENODEV;
1955
1956 mixer_found:
1957 if (!s->usbdev) {
1958 up(&open_sem);
1959 return -EIO;
1960 }
1961 file->private_data = ms;
1962 s->count++;
1963
1964 up(&open_sem);
1965 return nonseekable_open(inode, file);
1966}
1967
1968static int usb_audio_release_mixdev(struct inode *inode, struct file *file)
1969{
1970 struct usb_mixerdev *ms = (struct usb_mixerdev *)file->private_data;
1971 struct usb_audio_state *s;
1972
1973 lock_kernel();
1974 s = ms->state;
1975 down(&open_sem);
1976 release(s);
1977 unlock_kernel();
1978 return 0;
1979}
1980
1981static int usb_audio_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1982{
1983 struct usb_mixerdev *ms = (struct usb_mixerdev *)file->private_data;
1984 int i, j, val;
1985 int __user *user_arg = (int __user *)arg;
1986
1987 if (!ms->state->usbdev)
1988 return -ENODEV;
1989
1990 if (cmd == SOUND_MIXER_INFO) {
1991 mixer_info info;
1992
1993 memset(&info, 0, sizeof(info));
1994 strncpy(info.id, "USB_AUDIO", sizeof(info.id));
1995 strncpy(info.name, "USB Audio Class Driver", sizeof(info.name));
1996 info.modify_counter = ms->modcnt;
1997 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
1998 return -EFAULT;
1999 return 0;
2000 }
2001 if (cmd == SOUND_OLD_MIXER_INFO) {
2002 _old_mixer_info info;
2003
2004 memset(&info, 0, sizeof(info));
2005 strncpy(info.id, "USB_AUDIO", sizeof(info.id));
2006 strncpy(info.name, "USB Audio Class Driver", sizeof(info.name));
2007 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
2008 return -EFAULT;
2009 return 0;
2010 }
2011 if (cmd == OSS_GETVERSION)
2012 return put_user(SOUND_VERSION, user_arg);
2013 if (_IOC_TYPE(cmd) != 'M' || _IOC_SIZE(cmd) != sizeof(int))
2014 return -EINVAL;
2015 if (_IOC_DIR(cmd) == _IOC_READ) {
2016 switch (_IOC_NR(cmd)) {
2017 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
2018 val = get_rec_src(ms);
2019 if (val < 0)
2020 return val;
2021 return put_user(val, user_arg);
2022
2023 case SOUND_MIXER_DEVMASK: /* Arg contains a bit for each supported device */
2024 for (val = i = 0; i < ms->numch; i++)
2025 val |= 1 << ms->ch[i].osschannel;
2026 return put_user(val, user_arg);
2027
2028 case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
2029 for (val = i = 0; i < ms->numch; i++)
2030 if (ms->ch[i].slctunitid)
2031 val |= 1 << ms->ch[i].osschannel;
2032 return put_user(val, user_arg);
2033
2034 case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
2035 for (val = i = 0; i < ms->numch; i++)
2036 if (ms->ch[i].flags & (MIXFLG_STEREOIN | MIXFLG_STEREOOUT))
2037 val |= 1 << ms->ch[i].osschannel;
2038 return put_user(val, user_arg);
2039
2040 case SOUND_MIXER_CAPS:
2041 return put_user(SOUND_CAP_EXCL_INPUT, user_arg);
2042
2043 default:
2044 i = _IOC_NR(cmd);
2045 if (i >= SOUND_MIXER_NRDEVICES)
2046 return -EINVAL;
2047 for (j = 0; j < ms->numch; j++) {
2048 if (ms->ch[j].osschannel == i) {
2049 return put_user(ms->ch[j].value, user_arg);
2050 }
2051 }
2052 return -EINVAL;
2053 }
2054 }
2055 if (_IOC_DIR(cmd) != (_IOC_READ|_IOC_WRITE))
2056 return -EINVAL;
2057 ms->modcnt++;
2058 switch (_IOC_NR(cmd)) {
2059 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
2060 if (get_user(val, user_arg))
2061 return -EFAULT;
2062 return set_rec_src(ms, val);
2063
2064 default:
2065 i = _IOC_NR(cmd);
2066 if (i >= SOUND_MIXER_NRDEVICES)
2067 return -EINVAL;
2068 for (j = 0; j < ms->numch && ms->ch[j].osschannel != i; j++);
2069 if (j >= ms->numch)
2070 return -EINVAL;
2071 if (get_user(val, user_arg))
2072 return -EFAULT;
2073 if (wrmixer(ms, j, val))
2074 return -EIO;
2075 return put_user(ms->ch[j].value, user_arg);
2076 }
2077}
2078
2079static /*const*/ struct file_operations usb_mixer_fops = {
2080 .owner = THIS_MODULE,
2081 .llseek = no_llseek,
2082 .ioctl = usb_audio_ioctl_mixdev,
2083 .open = usb_audio_open_mixdev,
2084 .release = usb_audio_release_mixdev,
2085};
2086
2087/* --------------------------------------------------------------------- */
2088
2089static int drain_out(struct usb_audiodev *as, int nonblock)
2090{
2091 DECLARE_WAITQUEUE(wait, current);
2092 unsigned long flags;
2093 int count, tmo;
2094
2095 if (as->usbout.dma.mapped || !as->usbout.dma.ready)
2096 return 0;
2097 usbout_start(as);
2098 add_wait_queue(&as->usbout.dma.wait, &wait);
2099 for (;;) {
2100 __set_current_state(TASK_INTERRUPTIBLE);
2101 spin_lock_irqsave(&as->lock, flags);
2102 count = as->usbout.dma.count;
2103 spin_unlock_irqrestore(&as->lock, flags);
2104 if (count <= 0)
2105 break;
2106 if (signal_pending(current))
2107 break;
2108 if (nonblock) {
2109 remove_wait_queue(&as->usbout.dma.wait, &wait);
2110 set_current_state(TASK_RUNNING);
2111 return -EBUSY;
2112 }
2113 tmo = 3 * HZ * count / as->usbout.dma.srate;
2114 tmo >>= AFMT_BYTESSHIFT(as->usbout.dma.format);
2115 if (!schedule_timeout(tmo + 1)) {
2116 printk(KERN_DEBUG "usbaudio: dma timed out??\n");
2117 break;
2118 }
2119 }
2120 remove_wait_queue(&as->usbout.dma.wait, &wait);
2121 set_current_state(TASK_RUNNING);
2122 if (signal_pending(current))
2123 return -ERESTARTSYS;
2124 return 0;
2125}
2126
2127/* --------------------------------------------------------------------- */
2128
2129static ssize_t usb_audio_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
2130{
2131 struct usb_audiodev *as = (struct usb_audiodev *)file->private_data;
2132 DECLARE_WAITQUEUE(wait, current);
2133 ssize_t ret = 0;
2134 unsigned long flags;
2135 unsigned int ptr;
2136 int cnt, err;
2137
2138 if (as->usbin.dma.mapped)
2139 return -ENXIO;
2140 if (!as->usbin.dma.ready && (ret = prog_dmabuf_in(as)))
2141 return ret;
2142 if (!access_ok(VERIFY_WRITE, buffer, count))
2143 return -EFAULT;
2144 add_wait_queue(&as->usbin.dma.wait, &wait);
2145 while (count > 0) {
2146 spin_lock_irqsave(&as->lock, flags);
2147 ptr = as->usbin.dma.rdptr;
2148 cnt = as->usbin.dma.count;
2149 /* set task state early to avoid wakeup races */
2150 if (cnt <= 0)
2151 __set_current_state(TASK_INTERRUPTIBLE);
2152 spin_unlock_irqrestore(&as->lock, flags);
2153 if (cnt > count)
2154 cnt = count;
2155 if (cnt <= 0) {
2156 if (usbin_start(as)) {
2157 if (!ret)
2158 ret = -ENODEV;
2159 break;
2160 }
2161 if (file->f_flags & O_NONBLOCK) {
2162 if (!ret)
2163 ret = -EAGAIN;
2164 break;
2165 }
2166 schedule();
2167 if (signal_pending(current)) {
2168 if (!ret)
2169 ret = -ERESTARTSYS;
2170 break;
2171 }
2172 continue;
2173 }
2174 if ((err = dmabuf_copyout_user(&as->usbin.dma, ptr, buffer, cnt))) {
2175 if (!ret)
2176 ret = err;
2177 break;
2178 }
2179 ptr += cnt;
2180 if (ptr >= as->usbin.dma.dmasize)
2181 ptr -= as->usbin.dma.dmasize;
2182 spin_lock_irqsave(&as->lock, flags);
2183 as->usbin.dma.rdptr = ptr;
2184 as->usbin.dma.count -= cnt;
2185 spin_unlock_irqrestore(&as->lock, flags);
2186 count -= cnt;
2187 buffer += cnt;
2188 ret += cnt;
2189 }
2190 __set_current_state(TASK_RUNNING);
2191 remove_wait_queue(&as->usbin.dma.wait, &wait);
2192 return ret;
2193}
2194
2195static ssize_t usb_audio_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
2196{
2197 struct usb_audiodev *as = (struct usb_audiodev *)file->private_data;
2198 DECLARE_WAITQUEUE(wait, current);
2199 ssize_t ret = 0;
2200 unsigned long flags;
2201 unsigned int ptr;
2202 unsigned int start_thr;
2203 int cnt, err;
2204
2205 if (as->usbout.dma.mapped)
2206 return -ENXIO;
2207 if (!as->usbout.dma.ready && (ret = prog_dmabuf_out(as)))
2208 return ret;
2209 if (!access_ok(VERIFY_READ, buffer, count))
2210 return -EFAULT;
2211 start_thr = (as->usbout.dma.srate << AFMT_BYTESSHIFT(as->usbout.dma.format)) / (1000 / (3 * DESCFRAMES));
2212 add_wait_queue(&as->usbout.dma.wait, &wait);
2213 while (count > 0) {
2214#if 0
2215 printk(KERN_DEBUG "usb_audio_write: count %u dma: count %u rdptr %u wrptr %u dmasize %u fragsize %u flags 0x%02x taskst 0x%lx\n",
2216 count, as->usbout.dma.count, as->usbout.dma.rdptr, as->usbout.dma.wrptr, as->usbout.dma.dmasize, as->usbout.dma.fragsize,
2217 as->usbout.flags, current->state);
2218#endif
2219 spin_lock_irqsave(&as->lock, flags);
2220 if (as->usbout.dma.count < 0) {
2221 as->usbout.dma.count = 0;
2222 as->usbout.dma.rdptr = as->usbout.dma.wrptr;
2223 }
2224 ptr = as->usbout.dma.wrptr;
2225 cnt = as->usbout.dma.dmasize - as->usbout.dma.count;
2226 /* set task state early to avoid wakeup races */
2227 if (cnt <= 0)
2228 __set_current_state(TASK_INTERRUPTIBLE);
2229 spin_unlock_irqrestore(&as->lock, flags);
2230 if (cnt > count)
2231 cnt = count;
2232 if (cnt <= 0) {
2233 if (usbout_start(as)) {
2234 if (!ret)
2235 ret = -ENODEV;
2236 break;
2237 }
2238 if (file->f_flags & O_NONBLOCK) {
2239 if (!ret)
2240 ret = -EAGAIN;
2241 break;
2242 }
2243 schedule();
2244 if (signal_pending(current)) {
2245 if (!ret)
2246 ret = -ERESTARTSYS;
2247 break;
2248 }
2249 continue;
2250 }
2251 if ((err = dmabuf_copyin_user(&as->usbout.dma, ptr, buffer, cnt))) {
2252 if (!ret)
2253 ret = err;
2254 break;
2255 }
2256 ptr += cnt;
2257 if (ptr >= as->usbout.dma.dmasize)
2258 ptr -= as->usbout.dma.dmasize;
2259 spin_lock_irqsave(&as->lock, flags);
2260 as->usbout.dma.wrptr = ptr;
2261 as->usbout.dma.count += cnt;
2262 spin_unlock_irqrestore(&as->lock, flags);
2263 count -= cnt;
2264 buffer += cnt;
2265 ret += cnt;
2266 if (as->usbout.dma.count >= start_thr && usbout_start(as)) {
2267 if (!ret)
2268 ret = -ENODEV;
2269 break;
2270 }
2271 }
2272 __set_current_state(TASK_RUNNING);
2273 remove_wait_queue(&as->usbout.dma.wait, &wait);
2274 return ret;
2275}
2276
2277/* Called without the kernel lock - fine */
2278static unsigned int usb_audio_poll(struct file *file, struct poll_table_struct *wait)
2279{
2280 struct usb_audiodev *as = (struct usb_audiodev *)file->private_data;
2281 unsigned long flags;
2282 unsigned int mask = 0;
2283
2284 if (file->f_mode & FMODE_WRITE) {
2285 if (!as->usbout.dma.ready)
2286 prog_dmabuf_out(as);
2287 poll_wait(file, &as->usbout.dma.wait, wait);
2288 }
2289 if (file->f_mode & FMODE_READ) {
2290 if (!as->usbin.dma.ready)
2291 prog_dmabuf_in(as);
2292 poll_wait(file, &as->usbin.dma.wait, wait);
2293 }
2294 spin_lock_irqsave(&as->lock, flags);
2295 if (file->f_mode & FMODE_READ) {
2296 if (as->usbin.dma.count >= (signed)as->usbin.dma.fragsize)
2297 mask |= POLLIN | POLLRDNORM;
2298 }
2299 if (file->f_mode & FMODE_WRITE) {
2300 if (as->usbout.dma.mapped) {
2301 if (as->usbout.dma.count >= (signed)as->usbout.dma.fragsize)
2302 mask |= POLLOUT | POLLWRNORM;
2303 } else {
2304 if ((signed)as->usbout.dma.dmasize >= as->usbout.dma.count + (signed)as->usbout.dma.fragsize)
2305 mask |= POLLOUT | POLLWRNORM;
2306 }
2307 }
2308 spin_unlock_irqrestore(&as->lock, flags);
2309 return mask;
2310}
2311
2312static int usb_audio_mmap(struct file *file, struct vm_area_struct *vma)
2313{
2314 struct usb_audiodev *as = (struct usb_audiodev *)file->private_data;
2315 struct dmabuf *db;
2316 int ret = -EINVAL;
2317
2318 lock_kernel();
2319 if (vma->vm_flags & VM_WRITE) {
2320 if ((ret = prog_dmabuf_out(as)) != 0)
2321 goto out;
2322 db = &as->usbout.dma;
2323 } else if (vma->vm_flags & VM_READ) {
2324 if ((ret = prog_dmabuf_in(as)) != 0)
2325 goto out;
2326 db = &as->usbin.dma;
2327 } else
2328 goto out;
2329
2330 ret = -EINVAL;
2331 if (vma->vm_pgoff != 0)
2332 goto out;
2333
2334 ret = dmabuf_mmap(vma, db, vma->vm_start, vma->vm_end - vma->vm_start, vma->vm_page_prot);
2335out:
2336 unlock_kernel();
2337 return ret;
2338}
2339
2340static int usb_audio_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
2341{
2342 struct usb_audiodev *as = (struct usb_audiodev *)file->private_data;
2343 struct usb_audio_state *s = as->state;
2344 int __user *user_arg = (int __user *)arg;
2345 unsigned long flags;
2346 audio_buf_info abinfo;
2347 count_info cinfo;
2348 int val = 0;
2349 int val2, mapped, ret;
2350
2351 if (!s->usbdev)
2352 return -EIO;
2353 mapped = ((file->f_mode & FMODE_WRITE) && as->usbout.dma.mapped) ||
2354 ((file->f_mode & FMODE_READ) && as->usbin.dma.mapped);
2355#if 0
2356 if (arg)
2357 get_user(val, (int *)arg);
2358 printk(KERN_DEBUG "usbaudio: usb_audio_ioctl cmd=%x arg=%lx *arg=%d\n", cmd, arg, val)
2359#endif
2360 switch (cmd) {
2361 case OSS_GETVERSION:
2362 return put_user(SOUND_VERSION, user_arg);
2363
2364 case SNDCTL_DSP_SYNC:
2365 if (file->f_mode & FMODE_WRITE)
2366 return drain_out(as, 0/*file->f_flags & O_NONBLOCK*/);
2367 return 0;
2368
2369 case SNDCTL_DSP_SETDUPLEX:
2370 return 0;
2371
2372 case SNDCTL_DSP_GETCAPS:
2373 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER |
2374 DSP_CAP_MMAP | DSP_CAP_BATCH, user_arg);
2375
2376 case SNDCTL_DSP_RESET:
2377 if (file->f_mode & FMODE_WRITE) {
2378 usbout_stop(as);
2379 as->usbout.dma.rdptr = as->usbout.dma.wrptr = as->usbout.dma.count = as->usbout.dma.total_bytes = 0;
2380 }
2381 if (file->f_mode & FMODE_READ) {
2382 usbin_stop(as);
2383 as->usbin.dma.rdptr = as->usbin.dma.wrptr = as->usbin.dma.count = as->usbin.dma.total_bytes = 0;
2384 }
2385 return 0;
2386
2387 case SNDCTL_DSP_SPEED:
2388 if (get_user(val, user_arg))
2389 return -EFAULT;
2390 if (val >= 0) {
2391 if (val < 4000)
2392 val = 4000;
2393 if (val > 100000)
2394 val = 100000;
2395 if (set_format(as, file->f_mode, AFMT_QUERY, val))
2396 return -EIO;
2397 }
2398 return put_user((file->f_mode & FMODE_READ) ?
2399 as->usbin.dma.srate : as->usbout.dma.srate,
2400 user_arg);
2401
2402 case SNDCTL_DSP_STEREO:
2403 if (get_user(val, user_arg))
2404 return -EFAULT;
2405 val2 = (file->f_mode & FMODE_READ) ? as->usbin.dma.format : as->usbout.dma.format;
2406 if (val)
2407 val2 |= AFMT_STEREO;
2408 else
2409 val2 &= ~AFMT_STEREO;
2410 if (set_format(as, file->f_mode, val2, 0))
2411 return -EIO;
2412 return 0;
2413
2414 case SNDCTL_DSP_CHANNELS:
2415 if (get_user(val, user_arg))
2416 return -EFAULT;
2417 if (val != 0) {
2418 val2 = (file->f_mode & FMODE_READ) ? as->usbin.dma.format : as->usbout.dma.format;
2419 if (val == 1)
2420 val2 &= ~AFMT_STEREO;
2421 else
2422 val2 |= AFMT_STEREO;
2423 if (set_format(as, file->f_mode, val2, 0))
2424 return -EIO;
2425 }
2426 val2 = (file->f_mode & FMODE_READ) ? as->usbin.dma.format : as->usbout.dma.format;
2427 return put_user(AFMT_ISSTEREO(val2) ? 2 : 1, user_arg);
2428
2429 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
2430 return put_user(AFMT_U8 | AFMT_U16_LE | AFMT_U16_BE |
2431 AFMT_S8 | AFMT_S16_LE | AFMT_S16_BE, user_arg);
2432
2433 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
2434 if (get_user(val, user_arg))
2435 return -EFAULT;
2436 if (val != AFMT_QUERY) {
2437 if (hweight32(val) != 1)
2438 return -EINVAL;
2439 if (!(val & (AFMT_U8 | AFMT_U16_LE | AFMT_U16_BE |
2440 AFMT_S8 | AFMT_S16_LE | AFMT_S16_BE)))
2441 return -EINVAL;
2442 val2 = (file->f_mode & FMODE_READ) ? as->usbin.dma.format : as->usbout.dma.format;
2443 val |= val2 & AFMT_STEREO;
2444 if (set_format(as, file->f_mode, val, 0))
2445 return -EIO;
2446 }
2447 val2 = (file->f_mode & FMODE_READ) ? as->usbin.dma.format : as->usbout.dma.format;
2448 return put_user(val2 & ~AFMT_STEREO, user_arg);
2449
2450 case SNDCTL_DSP_POST:
2451 return 0;
2452
2453 case SNDCTL_DSP_GETTRIGGER:
2454 val = 0;
2455 if (file->f_mode & FMODE_READ && as->usbin.flags & FLG_RUNNING)
2456 val |= PCM_ENABLE_INPUT;
2457 if (file->f_mode & FMODE_WRITE && as->usbout.flags & FLG_RUNNING)
2458 val |= PCM_ENABLE_OUTPUT;
2459 return put_user(val, user_arg);
2460
2461 case SNDCTL_DSP_SETTRIGGER:
2462 if (get_user(val, user_arg))
2463 return -EFAULT;
2464 if (file->f_mode & FMODE_READ) {
2465 if (val & PCM_ENABLE_INPUT) {
2466 if (!as->usbin.dma.ready && (ret = prog_dmabuf_in(as)))
2467 return ret;
2468 if (usbin_start(as))
2469 return -ENODEV;
2470 } else
2471 usbin_stop(as);
2472 }
2473 if (file->f_mode & FMODE_WRITE) {
2474 if (val & PCM_ENABLE_OUTPUT) {
2475 if (!as->usbout.dma.ready && (ret = prog_dmabuf_out(as)))
2476 return ret;
2477 if (usbout_start(as))
2478 return -ENODEV;
2479 } else
2480 usbout_stop(as);
2481 }
2482 return 0;
2483
2484 case SNDCTL_DSP_GETOSPACE:
2485 if (!(file->f_mode & FMODE_WRITE))
2486 return -EINVAL;
2487 if (!(as->usbout.flags & FLG_RUNNING) && (val = prog_dmabuf_out(as)) != 0)
2488 return val;
2489 spin_lock_irqsave(&as->lock, flags);
2490 abinfo.fragsize = as->usbout.dma.fragsize;
2491 abinfo.bytes = as->usbout.dma.dmasize - as->usbout.dma.count;
2492 abinfo.fragstotal = as->usbout.dma.numfrag;
2493 abinfo.fragments = abinfo.bytes >> as->usbout.dma.fragshift;
2494 spin_unlock_irqrestore(&as->lock, flags);
2495 return copy_to_user((void __user *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2496
2497 case SNDCTL_DSP_GETISPACE:
2498 if (!(file->f_mode & FMODE_READ))
2499 return -EINVAL;
2500 if (!(as->usbin.flags & FLG_RUNNING) && (val = prog_dmabuf_in(as)) != 0)
2501 return val;
2502 spin_lock_irqsave(&as->lock, flags);
2503 abinfo.fragsize = as->usbin.dma.fragsize;
2504 abinfo.bytes = as->usbin.dma.count;
2505 abinfo.fragstotal = as->usbin.dma.numfrag;
2506 abinfo.fragments = abinfo.bytes >> as->usbin.dma.fragshift;
2507 spin_unlock_irqrestore(&as->lock, flags);
2508 return copy_to_user((void __user *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2509
2510 case SNDCTL_DSP_NONBLOCK:
2511 file->f_flags |= O_NONBLOCK;
2512 return 0;
2513
2514 case SNDCTL_DSP_GETODELAY:
2515 if (!(file->f_mode & FMODE_WRITE))
2516 return -EINVAL;
2517 spin_lock_irqsave(&as->lock, flags);
2518 val = as->usbout.dma.count;
2519 spin_unlock_irqrestore(&as->lock, flags);
2520 return put_user(val, user_arg);
2521
2522 case SNDCTL_DSP_GETIPTR:
2523 if (!(file->f_mode & FMODE_READ))
2524 return -EINVAL;
2525 spin_lock_irqsave(&as->lock, flags);
2526 cinfo.bytes = as->usbin.dma.total_bytes;
2527 cinfo.blocks = as->usbin.dma.count >> as->usbin.dma.fragshift;
2528 cinfo.ptr = as->usbin.dma.wrptr;
2529 if (as->usbin.dma.mapped)
2530 as->usbin.dma.count &= as->usbin.dma.fragsize-1;
2531 spin_unlock_irqrestore(&as->lock, flags);
2532 if (copy_to_user((void __user *)arg, &cinfo, sizeof(cinfo)))
2533 return -EFAULT;
2534 return 0;
2535
2536 case SNDCTL_DSP_GETOPTR:
2537 if (!(file->f_mode & FMODE_WRITE))
2538 return -EINVAL;
2539 spin_lock_irqsave(&as->lock, flags);
2540 cinfo.bytes = as->usbout.dma.total_bytes;
2541 cinfo.blocks = as->usbout.dma.count >> as->usbout.dma.fragshift;
2542 cinfo.ptr = as->usbout.dma.rdptr;
2543 if (as->usbout.dma.mapped)
2544 as->usbout.dma.count &= as->usbout.dma.fragsize-1;
2545 spin_unlock_irqrestore(&as->lock, flags);
2546 if (copy_to_user((void __user *)arg, &cinfo, sizeof(cinfo)))
2547 return -EFAULT;
2548 return 0;
2549
2550 case SNDCTL_DSP_GETBLKSIZE:
2551 if (file->f_mode & FMODE_WRITE) {
2552 if ((val = prog_dmabuf_out(as)))
2553 return val;
2554 return put_user(as->usbout.dma.fragsize, user_arg);
2555 }
2556 if ((val = prog_dmabuf_in(as)))
2557 return val;
2558 return put_user(as->usbin.dma.fragsize, user_arg);
2559
2560 case SNDCTL_DSP_SETFRAGMENT:
2561 if (get_user(val, user_arg))
2562 return -EFAULT;
2563 if (file->f_mode & FMODE_READ) {
2564 as->usbin.dma.ossfragshift = val & 0xffff;
2565 as->usbin.dma.ossmaxfrags = (val >> 16) & 0xffff;
2566 if (as->usbin.dma.ossfragshift < 4)
2567 as->usbin.dma.ossfragshift = 4;
2568 if (as->usbin.dma.ossfragshift > 15)
2569 as->usbin.dma.ossfragshift = 15;
2570 if (as->usbin.dma.ossmaxfrags < 4)
2571 as->usbin.dma.ossmaxfrags = 4;
2572 }
2573 if (file->f_mode & FMODE_WRITE) {
2574 as->usbout.dma.ossfragshift = val & 0xffff;
2575 as->usbout.dma.ossmaxfrags = (val >> 16) & 0xffff;
2576 if (as->usbout.dma.ossfragshift < 4)
2577 as->usbout.dma.ossfragshift = 4;
2578 if (as->usbout.dma.ossfragshift > 15)
2579 as->usbout.dma.ossfragshift = 15;
2580 if (as->usbout.dma.ossmaxfrags < 4)
2581 as->usbout.dma.ossmaxfrags = 4;
2582 }
2583 return 0;
2584
2585 case SNDCTL_DSP_SUBDIVIDE:
2586 if ((file->f_mode & FMODE_READ && as->usbin.dma.subdivision) ||
2587 (file->f_mode & FMODE_WRITE && as->usbout.dma.subdivision))
2588 return -EINVAL;
2589 if (get_user(val, user_arg))
2590 return -EFAULT;
2591 if (val != 1 && val != 2 && val != 4)
2592 return -EINVAL;
2593 if (file->f_mode & FMODE_READ)
2594 as->usbin.dma.subdivision = val;
2595 if (file->f_mode & FMODE_WRITE)
2596 as->usbout.dma.subdivision = val;
2597 return 0;
2598
2599 case SOUND_PCM_READ_RATE:
2600 return put_user((file->f_mode & FMODE_READ) ?
2601 as->usbin.dma.srate : as->usbout.dma.srate,
2602 user_arg);
2603
2604 case SOUND_PCM_READ_CHANNELS:
2605 val2 = (file->f_mode & FMODE_READ) ? as->usbin.dma.format : as->usbout.dma.format;
2606 return put_user(AFMT_ISSTEREO(val2) ? 2 : 1, user_arg);
2607
2608 case SOUND_PCM_READ_BITS:
2609 val2 = (file->f_mode & FMODE_READ) ? as->usbin.dma.format : as->usbout.dma.format;
2610 return put_user(AFMT_IS16BIT(val2) ? 16 : 8, user_arg);
2611
2612 case SOUND_PCM_WRITE_FILTER:
2613 case SNDCTL_DSP_SETSYNCRO:
2614 case SOUND_PCM_READ_FILTER:
2615 return -EINVAL;
2616 }
2617 dprintk((KERN_DEBUG "usbaudio: usb_audio_ioctl - no command found\n"));
2618 return -ENOIOCTLCMD;
2619}
2620
2621static int usb_audio_open(struct inode *inode, struct file *file)
2622{
2623 unsigned int minor = iminor(inode);
2624 DECLARE_WAITQUEUE(wait, current);
2625 struct usb_audiodev *as;
2626 struct usb_audio_state *s;
2627
2628 for (;;) {
2629 down(&open_sem);
2630 list_for_each_entry(s, &audiodevs, audiodev) {
2631 list_for_each_entry(as, &s->audiolist, list) {
2632 if (!((as->dev_audio ^ minor) & ~0xf))
2633 goto device_found;
2634 }
2635 }
2636 up(&open_sem);
2637 return -ENODEV;
2638
2639 device_found:
2640 if (!s->usbdev) {
2641 up(&open_sem);
2642 return -EIO;
2643 }
2644 /* wait for device to become free */
2645 if (!(as->open_mode & file->f_mode))
2646 break;
2647 if (file->f_flags & O_NONBLOCK) {
2648 up(&open_sem);
2649 return -EBUSY;
2650 }
2651 __set_current_state(TASK_INTERRUPTIBLE);
2652 add_wait_queue(&open_wait, &wait);
2653 up(&open_sem);
2654 schedule();
2655 __set_current_state(TASK_RUNNING);
2656 remove_wait_queue(&open_wait, &wait);
2657 if (signal_pending(current))
2658 return -ERESTARTSYS;
2659 }
2660 if (file->f_mode & FMODE_READ)
2661 as->usbin.dma.ossfragshift = as->usbin.dma.ossmaxfrags = as->usbin.dma.subdivision = 0;
2662 if (file->f_mode & FMODE_WRITE)
2663 as->usbout.dma.ossfragshift = as->usbout.dma.ossmaxfrags = as->usbout.dma.subdivision = 0;
2664 if (set_format(as, file->f_mode, ((minor & 0xf) == SND_DEV_DSP16) ? AFMT_S16_LE : AFMT_U8 /* AFMT_ULAW */, 8000)) {
2665 up(&open_sem);
2666 return -EIO;
2667 }
2668 file->private_data = as;
2669 as->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
2670 s->count++;
2671 up(&open_sem);
2672 return nonseekable_open(inode, file);
2673}
2674
2675static int usb_audio_release(struct inode *inode, struct file *file)
2676{
2677 struct usb_audiodev *as = (struct usb_audiodev *)file->private_data;
2678 struct usb_audio_state *s;
2679 struct usb_device *dev;
2680
2681 lock_kernel();
2682 s = as->state;
2683 dev = s->usbdev;
2684 if (file->f_mode & FMODE_WRITE)
2685 drain_out(as, file->f_flags & O_NONBLOCK);
2686 down(&open_sem);
2687 if (file->f_mode & FMODE_WRITE) {
2688 usbout_stop(as);
2689 if (dev && as->usbout.interface >= 0)
2690 usb_set_interface(dev, as->usbout.interface, 0);
2691 dmabuf_release(&as->usbout.dma);
2692 usbout_release(as);
2693 }
2694 if (file->f_mode & FMODE_READ) {
2695 usbin_stop(as);
2696 if (dev && as->usbin.interface >= 0)
2697 usb_set_interface(dev, as->usbin.interface, 0);
2698 dmabuf_release(&as->usbin.dma);
2699 usbin_release(as);
2700 }
2701 as->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
2702 release(s);
2703 wake_up(&open_wait);
2704 unlock_kernel();
2705 return 0;
2706}
2707
2708static /*const*/ struct file_operations usb_audio_fops = {
2709 .owner = THIS_MODULE,
2710 .llseek = no_llseek,
2711 .read = usb_audio_read,
2712 .write = usb_audio_write,
2713 .poll = usb_audio_poll,
2714 .ioctl = usb_audio_ioctl,
2715 .mmap = usb_audio_mmap,
2716 .open = usb_audio_open,
2717 .release = usb_audio_release,
2718};
2719
2720/* --------------------------------------------------------------------- */
2721
2722static int usb_audio_probe(struct usb_interface *iface,
2723 const struct usb_device_id *id);
2724static void usb_audio_disconnect(struct usb_interface *iface);
2725
2726static struct usb_device_id usb_audio_ids [] = {
2727 { .match_flags = (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS),
2728 .bInterfaceClass = USB_CLASS_AUDIO, .bInterfaceSubClass = 1},
2729 { } /* Terminating entry */
2730};
2731
2732MODULE_DEVICE_TABLE (usb, usb_audio_ids);
2733
2734static struct usb_driver usb_audio_driver = {
2735 .name = "audio",
2736 .probe = usb_audio_probe,
2737 .disconnect = usb_audio_disconnect,
2738 .id_table = usb_audio_ids,
2739};
2740
2741static void *find_descriptor(void *descstart, unsigned int desclen, void *after,
2742 u8 dtype, int iface, int altsetting)
2743{
2744 u8 *p, *end, *next;
2745 int ifc = -1, as = -1;
2746
2747 p = descstart;
2748 end = p + desclen;
2749 for (; p < end;) {
2750 if (p[0] < 2)
2751 return NULL;
2752 next = p + p[0];
2753 if (next > end)
2754 return NULL;
2755 if (p[1] == USB_DT_INTERFACE) {
2756 /* minimum length of interface descriptor */
2757 if (p[0] < 9)
2758 return NULL;
2759 ifc = p[2];
2760 as = p[3];
2761 }
2762 if (p[1] == dtype && (!after || (void *)p > after) &&
2763 (iface == -1 || iface == ifc) && (altsetting == -1 || altsetting == as)) {
2764 return p;
2765 }
2766 p = next;
2767 }
2768 return NULL;
2769}
2770
2771static void *find_csinterface_descriptor(void *descstart, unsigned int desclen, void *after, u8 dsubtype, int iface, int altsetting)
2772{
2773 unsigned char *p;
2774
2775 p = find_descriptor(descstart, desclen, after, USB_DT_CS_INTERFACE, iface, altsetting);
2776 while (p) {
2777 if (p[0] >= 3 && p[2] == dsubtype)
2778 return p;
2779 p = find_descriptor(descstart, desclen, p, USB_DT_CS_INTERFACE, iface, altsetting);
2780 }
2781 return NULL;
2782}
2783
2784static void *find_audiocontrol_unit(void *descstart, unsigned int desclen, void *after, u8 unit, int iface)
2785{
2786 unsigned char *p;
2787
2788 p = find_descriptor(descstart, desclen, after, USB_DT_CS_INTERFACE, iface, -1);
2789 while (p) {
2790 if (p[0] >= 4 && p[2] >= INPUT_TERMINAL && p[2] <= EXTENSION_UNIT && p[3] == unit)
2791 return p;
2792 p = find_descriptor(descstart, desclen, p, USB_DT_CS_INTERFACE, iface, -1);
2793 }
2794 return NULL;
2795}
2796
2797static void usb_audio_parsestreaming(struct usb_audio_state *s, unsigned char *buffer, unsigned int buflen, int asifin, int asifout)
2798{
2799 struct usb_device *dev = s->usbdev;
2800 struct usb_audiodev *as;
2801 struct usb_host_interface *alts;
2802 struct usb_interface *iface;
2803 struct audioformat *fp;
2804 unsigned char *fmt, *csep;
2805 unsigned int i, j, k, format, idx;
2806
2807 if (!(as = kmalloc(sizeof(struct usb_audiodev), GFP_KERNEL)))
2808 return;
2809 memset(as, 0, sizeof(struct usb_audiodev));
2810 init_waitqueue_head(&as->usbin.dma.wait);
2811 init_waitqueue_head(&as->usbout.dma.wait);
2812 spin_lock_init(&as->lock);
2813 as->usbin.durb[0].urb = usb_alloc_urb (DESCFRAMES, GFP_KERNEL);
2814 as->usbin.durb[1].urb = usb_alloc_urb (DESCFRAMES, GFP_KERNEL);
2815 as->usbin.surb[0].urb = usb_alloc_urb (SYNCFRAMES, GFP_KERNEL);
2816 as->usbin.surb[1].urb = usb_alloc_urb (SYNCFRAMES, GFP_KERNEL);
2817 as->usbout.durb[0].urb = usb_alloc_urb (DESCFRAMES, GFP_KERNEL);
2818 as->usbout.durb[1].urb = usb_alloc_urb (DESCFRAMES, GFP_KERNEL);
2819 as->usbout.surb[0].urb = usb_alloc_urb (SYNCFRAMES, GFP_KERNEL);
2820 as->usbout.surb[1].urb = usb_alloc_urb (SYNCFRAMES, GFP_KERNEL);
2821 if ((!as->usbin.durb[0].urb) ||
2822 (!as->usbin.durb[1].urb) ||
2823 (!as->usbin.surb[0].urb) ||
2824 (!as->usbin.surb[1].urb) ||
2825 (!as->usbout.durb[0].urb) ||
2826 (!as->usbout.durb[1].urb) ||
2827 (!as->usbout.surb[0].urb) ||
2828 (!as->usbout.surb[1].urb)) {
2829 usb_free_urb(as->usbin.durb[0].urb);
2830 usb_free_urb(as->usbin.durb[1].urb);
2831 usb_free_urb(as->usbin.surb[0].urb);
2832 usb_free_urb(as->usbin.surb[1].urb);
2833 usb_free_urb(as->usbout.durb[0].urb);
2834 usb_free_urb(as->usbout.durb[1].urb);
2835 usb_free_urb(as->usbout.surb[0].urb);
2836 usb_free_urb(as->usbout.surb[1].urb);
2837 kfree(as);
2838 return;
2839 }
2840 as->state = s;
2841 as->usbin.interface = asifin;
2842 as->usbout.interface = asifout;
2843 /* search for input formats */
2844 if (asifin >= 0) {
2845 as->usbin.flags = FLG_CONNECTED;
2846 iface = usb_ifnum_to_if(dev, asifin);
2847 for (idx = 0; idx < iface->num_altsetting; idx++) {
2848 alts = &iface->altsetting[idx];
2849 i = alts->desc.bAlternateSetting;
2850 if (alts->desc.bInterfaceClass != USB_CLASS_AUDIO || alts->desc.bInterfaceSubClass != 2)
2851 continue;
2852 if (alts->desc.bNumEndpoints < 1) {
2853 if (i != 0) { /* altsetting 0 has no endpoints (Section B.3.4.1) */
2854 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u does not have an endpoint\n",
2855 dev->devnum, asifin, i);
2856 }
2857 continue;
2858 }
2859 if ((alts->endpoint[0].desc.bmAttributes & 0x03) != 0x01 ||
2860 !(alts->endpoint[0].desc.bEndpointAddress & 0x80)) {
2861 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u first endpoint not isochronous in\n",
2862 dev->devnum, asifin, i);
2863 continue;
2864 }
2865 fmt = find_csinterface_descriptor(buffer, buflen, NULL, AS_GENERAL, asifin, i);
2866 if (!fmt) {
2867 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u FORMAT_TYPE descriptor not found\n",
2868 dev->devnum, asifin, i);
2869 continue;
2870 }
2871 if (fmt[0] < 7 || fmt[6] != 0 || (fmt[5] != 1 && fmt[5] != 2)) {
2872 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u format not supported\n",
2873 dev->devnum, asifin, i);
2874 continue;
2875 }
2876 format = (fmt[5] == 2) ? (AFMT_U16_LE | AFMT_U8) : (AFMT_S16_LE | AFMT_S8);
2877 fmt = find_csinterface_descriptor(buffer, buflen, NULL, FORMAT_TYPE, asifin, i);
2878 if (!fmt) {
2879 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u FORMAT_TYPE descriptor not found\n",
2880 dev->devnum, asifin, i);
2881 continue;
2882 }
2883 if (fmt[0] < 8+3*(fmt[7] ? fmt[7] : 2) || fmt[3] != 1) {
2884 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u FORMAT_TYPE descriptor not supported\n",
2885 dev->devnum, asifin, i);
2886 continue;
2887 }
2888 if (fmt[4] < 1 || fmt[4] > 2 || fmt[5] < 1 || fmt[5] > 2) {
2889 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u unsupported channels %u framesize %u\n",
2890 dev->devnum, asifin, i, fmt[4], fmt[5]);
2891 continue;
2892 }
2893 csep = find_descriptor(buffer, buflen, NULL, USB_DT_CS_ENDPOINT, asifin, i);
2894 if (!csep || csep[0] < 7 || csep[2] != EP_GENERAL) {
2895 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u no or invalid class specific endpoint descriptor\n",
2896 dev->devnum, asifin, i);
2897 continue;
2898 }
2899 if (as->numfmtin >= MAXFORMATS)
2900 continue;
2901 fp = &as->fmtin[as->numfmtin++];
2902 if (fmt[5] == 2)
2903 format &= (AFMT_U16_LE | AFMT_S16_LE);
2904 else
2905 format &= (AFMT_U8 | AFMT_S8);
2906 if (fmt[4] == 2)
2907 format |= AFMT_STEREO;
2908 fp->format = format;
2909 fp->altsetting = i;
2910 fp->sratelo = fp->sratehi = fmt[8] | (fmt[9] << 8) | (fmt[10] << 16);
2911 printk(KERN_INFO "usbaudio: valid input sample rate %u\n", fp->sratelo);
2912 for (j = fmt[7] ? (fmt[7]-1) : 1; j > 0; j--) {
2913 k = fmt[8+3*j] | (fmt[9+3*j] << 8) | (fmt[10+3*j] << 16);
2914 printk(KERN_INFO "usbaudio: valid input sample rate %u\n", k);
2915 if (k > fp->sratehi)
2916 fp->sratehi = k;
2917 if (k < fp->sratelo)
2918 fp->sratelo = k;
2919 }
2920 fp->attributes = csep[3];
2921 printk(KERN_INFO "usbaudio: device %u interface %u altsetting %u: format 0x%08x sratelo %u sratehi %u attributes 0x%02x\n",
2922 dev->devnum, asifin, i, fp->format, fp->sratelo, fp->sratehi, fp->attributes);
2923 }
2924 }
2925 /* search for output formats */
2926 if (asifout >= 0) {
2927 as->usbout.flags = FLG_CONNECTED;
2928 iface = usb_ifnum_to_if(dev, asifout);
2929 for (idx = 0; idx < iface->num_altsetting; idx++) {
2930 alts = &iface->altsetting[idx];
2931 i = alts->desc.bAlternateSetting;
2932 if (alts->desc.bInterfaceClass != USB_CLASS_AUDIO || alts->desc.bInterfaceSubClass != 2)
2933 continue;
2934 if (alts->desc.bNumEndpoints < 1) {
2935 /* altsetting 0 should never have iso EPs */
2936 if (i != 0)
2937 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u does not have an endpoint\n",
2938 dev->devnum, asifout, i);
2939 continue;
2940 }
2941 if ((alts->endpoint[0].desc.bmAttributes & 0x03) != 0x01 ||
2942 (alts->endpoint[0].desc.bEndpointAddress & 0x80)) {
2943 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u first endpoint not isochronous out\n",
2944 dev->devnum, asifout, i);
2945 continue;
2946 }
2947 /* See USB audio formats manual, section 2 */
2948 fmt = find_csinterface_descriptor(buffer, buflen, NULL, AS_GENERAL, asifout, i);
2949 if (!fmt) {
2950 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u FORMAT_TYPE descriptor not found\n",
2951 dev->devnum, asifout, i);
2952 continue;
2953 }
2954 if (fmt[0] < 7 || fmt[6] != 0 || (fmt[5] != 1 && fmt[5] != 2)) {
2955 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u format not supported\n",
2956 dev->devnum, asifout, i);
2957 continue;
2958 }
2959 format = (fmt[5] == 2) ? (AFMT_U16_LE | AFMT_U8) : (AFMT_S16_LE | AFMT_S8);
2960 /* Dallas DS4201 workaround */
2961 if (le16_to_cpu(dev->descriptor.idVendor) == 0x04fa &&
2962 le16_to_cpu(dev->descriptor.idProduct) == 0x4201)
2963 format = (AFMT_S16_LE | AFMT_S8);
2964 fmt = find_csinterface_descriptor(buffer, buflen, NULL, FORMAT_TYPE, asifout, i);
2965 if (!fmt) {
2966 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u FORMAT_TYPE descriptor not found\n",
2967 dev->devnum, asifout, i);
2968 continue;
2969 }
2970 if (fmt[0] < 8+3*(fmt[7] ? fmt[7] : 2) || fmt[3] != 1) {
2971 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u FORMAT_TYPE descriptor not supported\n",
2972 dev->devnum, asifout, i);
2973 continue;
2974 }
2975 if (fmt[4] < 1 || fmt[4] > 2 || fmt[5] < 1 || fmt[5] > 2) {
2976 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u unsupported channels %u framesize %u\n",
2977 dev->devnum, asifout, i, fmt[4], fmt[5]);
2978 continue;
2979 }
2980 csep = find_descriptor(buffer, buflen, NULL, USB_DT_CS_ENDPOINT, asifout, i);
2981 if (!csep || csep[0] < 7 || csep[2] != EP_GENERAL) {
2982 printk(KERN_ERR "usbaudio: device %u interface %u altsetting %u no or invalid class specific endpoint descriptor\n",
2983 dev->devnum, asifout, i);
2984 continue;
2985 }
2986 if (as->numfmtout >= MAXFORMATS)
2987 continue;
2988 fp = &as->fmtout[as->numfmtout++];
2989 if (fmt[5] == 2)
2990 format &= (AFMT_U16_LE | AFMT_S16_LE);
2991 else
2992 format &= (AFMT_U8 | AFMT_S8);
2993 if (fmt[4] == 2)
2994 format |= AFMT_STEREO;
2995 fp->format = format;
2996 fp->altsetting = i;
2997 fp->sratelo = fp->sratehi = fmt[8] | (fmt[9] << 8) | (fmt[10] << 16);
2998 printk(KERN_INFO "usbaudio: valid output sample rate %u\n", fp->sratelo);
2999 for (j = fmt[7] ? (fmt[7]-1) : 1; j > 0; j--) {
3000 k = fmt[8+3*j] | (fmt[9+3*j] << 8) | (fmt[10+3*j] << 16);
3001 printk(KERN_INFO "usbaudio: valid output sample rate %u\n", k);
3002 if (k > fp->sratehi)
3003 fp->sratehi = k;
3004 if (k < fp->sratelo)
3005 fp->sratelo = k;
3006 }
3007 fp->attributes = csep[3];
3008 printk(KERN_INFO "usbaudio: device %u interface %u altsetting %u: format 0x%08x sratelo %u sratehi %u attributes 0x%02x\n",
3009 dev->devnum, asifout, i, fp->format, fp->sratelo, fp->sratehi, fp->attributes);
3010 }
3011 }
3012 if (as->numfmtin == 0 && as->numfmtout == 0) {
3013 usb_free_urb(as->usbin.durb[0].urb);
3014 usb_free_urb(as->usbin.durb[1].urb);
3015 usb_free_urb(as->usbin.surb[0].urb);
3016 usb_free_urb(as->usbin.surb[1].urb);
3017 usb_free_urb(as->usbout.durb[0].urb);
3018 usb_free_urb(as->usbout.durb[1].urb);
3019 usb_free_urb(as->usbout.surb[0].urb);
3020 usb_free_urb(as->usbout.surb[1].urb);
3021 kfree(as);
3022 return;
3023 }
3024 if ((as->dev_audio = register_sound_dsp(&usb_audio_fops, -1)) < 0) {
3025 printk(KERN_ERR "usbaudio: cannot register dsp\n");
3026 usb_free_urb(as->usbin.durb[0].urb);
3027 usb_free_urb(as->usbin.durb[1].urb);
3028 usb_free_urb(as->usbin.surb[0].urb);
3029 usb_free_urb(as->usbin.surb[1].urb);
3030 usb_free_urb(as->usbout.durb[0].urb);
3031 usb_free_urb(as->usbout.durb[1].urb);
3032 usb_free_urb(as->usbout.surb[0].urb);
3033 usb_free_urb(as->usbout.surb[1].urb);
3034 kfree(as);
3035 return;
3036 }
3037 printk(KERN_INFO "usbaudio: registered dsp 14,%d\n", as->dev_audio);
3038 /* everything successful */
3039 list_add_tail(&as->list, &s->audiolist);
3040}
3041
3042struct consmixstate {
3043 struct usb_audio_state *s;
3044 unsigned char *buffer;
3045 unsigned int buflen;
3046 unsigned int ctrlif;
3047 struct mixerchannel mixch[SOUND_MIXER_NRDEVICES];
3048 unsigned int nrmixch;
3049 unsigned int mixchmask;
3050 unsigned long unitbitmap[32/sizeof(unsigned long)];
3051 /* return values */
3052 unsigned int nrchannels;
3053 unsigned int termtype;
3054 unsigned int chconfig;
3055};
3056
3057static struct mixerchannel *getmixchannel(struct consmixstate *state, unsigned int nr)
3058{
3059 struct mixerchannel *c;
3060
3061 if (nr >= SOUND_MIXER_NRDEVICES) {
3062 printk(KERN_ERR "usbaudio: invalid OSS mixer channel %u\n", nr);
3063 return NULL;
3064 }
3065 if (!(state->mixchmask & (1 << nr))) {
3066 printk(KERN_WARNING "usbaudio: OSS mixer channel %u already in use\n", nr);
3067 return NULL;
3068 }
3069 c = &state->mixch[state->nrmixch++];
3070 c->osschannel = nr;
3071 state->mixchmask &= ~(1 << nr);
3072 return c;
3073}
3074
3075static unsigned int getvolchannel(struct consmixstate *state)
3076{
3077 unsigned int u;
3078
3079 if ((state->termtype & 0xff00) == 0x0000 && (state->mixchmask & SOUND_MASK_VOLUME))
3080 return SOUND_MIXER_VOLUME;
3081 if ((state->termtype & 0xff00) == 0x0100) {
3082 if (state->mixchmask & SOUND_MASK_PCM)
3083 return SOUND_MIXER_PCM;
3084 if (state->mixchmask & SOUND_MASK_ALTPCM)
3085 return SOUND_MIXER_ALTPCM;
3086 }
3087 if ((state->termtype & 0xff00) == 0x0200 && (state->mixchmask & SOUND_MASK_MIC))
3088 return SOUND_MIXER_MIC;
3089 if ((state->termtype & 0xff00) == 0x0300 && (state->mixchmask & SOUND_MASK_SPEAKER))
3090 return SOUND_MIXER_SPEAKER;
3091 if ((state->termtype & 0xff00) == 0x0500) {
3092 if (state->mixchmask & SOUND_MASK_PHONEIN)
3093 return SOUND_MIXER_PHONEIN;
3094 if (state->mixchmask & SOUND_MASK_PHONEOUT)
3095 return SOUND_MIXER_PHONEOUT;
3096 }
3097 if (state->termtype >= 0x710 && state->termtype <= 0x711 && (state->mixchmask & SOUND_MASK_RADIO))
3098 return SOUND_MIXER_RADIO;
3099 if (state->termtype >= 0x709 && state->termtype <= 0x70f && (state->mixchmask & SOUND_MASK_VIDEO))
3100 return SOUND_MIXER_VIDEO;
3101 u = ffs(state->mixchmask & (SOUND_MASK_LINE | SOUND_MASK_CD | SOUND_MASK_LINE1 | SOUND_MASK_LINE2 | SOUND_MASK_LINE3 |
3102 SOUND_MASK_DIGITAL1 | SOUND_MASK_DIGITAL2 | SOUND_MASK_DIGITAL3));
3103 return u-1;
3104}
3105
3106static void prepmixch(struct consmixstate *state)
3107{
3108 struct usb_device *dev = state->s->usbdev;
3109 struct mixerchannel *ch;
3110 unsigned char *buf;
3111 __s16 v1;
3112 unsigned int v2, v3;
3113
3114 if (!state->nrmixch || state->nrmixch > SOUND_MIXER_NRDEVICES)
3115 return;
3116 buf = kmalloc(sizeof(*buf) * 2, GFP_KERNEL);
3117 if (!buf) {
3118 printk(KERN_ERR "prepmixch: out of memory\n") ;
3119 return;
3120 }
3121
3122 ch = &state->mixch[state->nrmixch-1];
3123 switch (ch->selector) {
3124 case 0: /* mixer unit request */
3125 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_MIN, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
3126 (ch->chnum << 8) | 1, state->ctrlif | (ch->unitid << 8), buf, 2, 1000) < 0)
3127 goto err;
3128 ch->minval = buf[0] | (buf[1] << 8);
3129 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_MAX, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
3130 (ch->chnum << 8) | 1, state->ctrlif | (ch->unitid << 8), buf, 2, 1000) < 0)
3131 goto err;
3132 ch->maxval = buf[0] | (buf[1] << 8);
3133 v2 = ch->maxval - ch->minval;
3134 if (!v2)
3135 v2 = 1;
3136 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
3137 (ch->chnum << 8) | 1, state->ctrlif | (ch->unitid << 8), buf, 2, 1000) < 0)
3138 goto err;
3139 v1 = buf[0] | (buf[1] << 8);
3140 v3 = v1 - ch->minval;
3141 v3 = 100 * v3 / v2;
3142 if (v3 > 100)
3143 v3 = 100;
3144 ch->value = v3;
3145 if (ch->flags & (MIXFLG_STEREOIN | MIXFLG_STEREOOUT)) {
3146 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
3147 ((ch->chnum + !!(ch->flags & MIXFLG_STEREOIN)) << 8) | (1 + !!(ch->flags & MIXFLG_STEREOOUT)),
3148 state->ctrlif | (ch->unitid << 8), buf, 2, 1000) < 0)
3149 goto err;
3150 v1 = buf[0] | (buf[1] << 8);
3151 v3 = v1 - ch->minval;
3152 v3 = 100 * v3 / v2;
3153 if (v3 > 100)
3154 v3 = 100;
3155 }
3156 ch->value |= v3 << 8;
3157 break;
3158
3159 /* various feature unit controls */
3160 case VOLUME_CONTROL:
3161 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_MIN, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
3162 (ch->selector << 8) | ch->chnum, state->ctrlif | (ch->unitid << 8), buf, 2, 1000) < 0)
3163 goto err;
3164 ch->minval = buf[0] | (buf[1] << 8);
3165 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_MAX, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
3166 (ch->selector << 8) | ch->chnum, state->ctrlif | (ch->unitid << 8), buf, 2, 1000) < 0)
3167 goto err;
3168 ch->maxval = buf[0] | (buf[1] << 8);
3169 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
3170 (ch->selector << 8) | ch->chnum, state->ctrlif | (ch->unitid << 8), buf, 2, 1000) < 0)
3171 goto err;
3172 v1 = buf[0] | (buf[1] << 8);
3173 v2 = ch->maxval - ch->minval;
3174 v3 = v1 - ch->minval;
3175 if (!v2)
3176 v2 = 1;
3177 v3 = 100 * v3 / v2;
3178 if (v3 > 100)
3179 v3 = 100;
3180 ch->value = v3;
3181 if (ch->flags & (MIXFLG_STEREOIN | MIXFLG_STEREOOUT)) {
3182 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
3183 (ch->selector << 8) | (ch->chnum + 1), state->ctrlif | (ch->unitid << 8), buf, 2, 1000) < 0)
3184 goto err;
3185 v1 = buf[0] | (buf[1] << 8);
3186 v3 = v1 - ch->minval;
3187 v3 = 100 * v3 / v2;
3188 if (v3 > 100)
3189 v3 = 100;
3190 }
3191 ch->value |= v3 << 8;
3192 break;
3193
3194 case BASS_CONTROL:
3195 case MID_CONTROL:
3196 case TREBLE_CONTROL:
3197 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_MIN, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
3198 (ch->selector << 8) | ch->chnum, state->ctrlif | (ch->unitid << 8), buf, 1, 1000) < 0)
3199 goto err;
3200 ch->minval = buf[0] << 8;
3201 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_MAX, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
3202 (ch->selector << 8) | ch->chnum, state->ctrlif | (ch->unitid << 8), buf, 1, 1000) < 0)
3203 goto err;
3204 ch->maxval = buf[0] << 8;
3205 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
3206 (ch->selector << 8) | ch->chnum, state->ctrlif | (ch->unitid << 8), buf, 1, 1000) < 0)
3207 goto err;
3208 v1 = buf[0] << 8;
3209 v2 = ch->maxval - ch->minval;
3210 v3 = v1 - ch->minval;
3211 if (!v2)
3212 v2 = 1;
3213 v3 = 100 * v3 / v2;
3214 if (v3 > 100)
3215 v3 = 100;
3216 ch->value = v3;
3217 if (ch->flags & (MIXFLG_STEREOIN | MIXFLG_STEREOOUT)) {
3218 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
3219 (ch->selector << 8) | (ch->chnum + 1), state->ctrlif | (ch->unitid << 8), buf, 1, 1000) < 0)
3220 goto err;
3221 v1 = buf[0] << 8;
3222 v3 = v1 - ch->minval;
3223 v3 = 100 * v3 / v2;
3224 if (v3 > 100)
3225 v3 = 100;
3226 }
3227 ch->value |= v3 << 8;
3228 break;
3229
3230 default:
3231 goto err;
3232 }
3233
3234 freebuf:
3235 kfree(buf);
3236 return;
3237 err:
3238 printk(KERN_ERR "usbaudio: mixer request device %u if %u unit %u ch %u selector %u failed\n",
3239 dev->devnum, state->ctrlif, ch->unitid, ch->chnum, ch->selector);
3240 if (state->nrmixch)
3241 state->nrmixch--;
3242 goto freebuf;
3243}
3244
3245
3246static void usb_audio_recurseunit(struct consmixstate *state, unsigned char unitid);
3247
3248static inline int checkmixbmap(unsigned char *bmap, unsigned char flg, unsigned int inidx, unsigned int numoch)
3249{
3250 unsigned int idx;
3251
3252 idx = inidx*numoch;
3253 if (!(bmap[-(idx >> 3)] & (0x80 >> (idx & 7))))
3254 return 0;
3255 if (!(flg & (MIXFLG_STEREOIN | MIXFLG_STEREOOUT)))
3256 return 1;
3257 idx = (inidx+!!(flg & MIXFLG_STEREOIN))*numoch+!!(flg & MIXFLG_STEREOOUT);
3258 if (!(bmap[-(idx >> 3)] & (0x80 >> (idx & 7))))
3259 return 0;
3260 return 1;
3261}
3262
3263static void usb_audio_mixerunit(struct consmixstate *state, unsigned char *mixer)
3264{
3265 unsigned int nroutch = mixer[5+mixer[4]];
3266 unsigned int chidx[SOUND_MIXER_NRDEVICES+1];
3267 unsigned int termt[SOUND_MIXER_NRDEVICES];
3268 unsigned char flg = (nroutch >= 2) ? MIXFLG_STEREOOUT : 0;
3269 unsigned char *bmap = &mixer[9+mixer[4]];
3270 unsigned int bmapsize;
3271 struct mixerchannel *ch;
3272 unsigned int i;
3273
3274 if (!mixer[4]) {
3275 printk(KERN_ERR "usbaudio: unit %u invalid MIXER_UNIT descriptor\n", mixer[3]);
3276 return;
3277 }
3278 if (mixer[4] > SOUND_MIXER_NRDEVICES) {
3279 printk(KERN_ERR "usbaudio: mixer unit %u: too many input pins\n", mixer[3]);
3280 return;
3281 }
3282 chidx[0] = 0;
3283 for (i = 0; i < mixer[4]; i++) {
3284 usb_audio_recurseunit(state, mixer[5+i]);
3285 chidx[i+1] = chidx[i] + state->nrchannels;
3286 termt[i] = state->termtype;
3287 }
3288 state->termtype = 0;
3289 state->chconfig = mixer[6+mixer[4]] | (mixer[7+mixer[4]] << 8);
3290 bmapsize = (nroutch * chidx[mixer[4]] + 7) >> 3;
3291 bmap += bmapsize - 1;
3292 if (mixer[0] < 10+mixer[4]+bmapsize) {
3293 printk(KERN_ERR "usbaudio: unit %u invalid MIXER_UNIT descriptor (bitmap too small)\n", mixer[3]);
3294 return;
3295 }
3296 for (i = 0; i < mixer[4]; i++) {
3297 state->termtype = termt[i];
3298 if (chidx[i+1]-chidx[i] >= 2) {
3299 flg |= MIXFLG_STEREOIN;
3300 if (checkmixbmap(bmap, flg, chidx[i], nroutch)) {
3301 ch = getmixchannel(state, getvolchannel(state));
3302 if (ch) {
3303 ch->unitid = mixer[3];
3304 ch->selector = 0;
3305 ch->chnum = chidx[i]+1;
3306 ch->flags = flg;
3307 prepmixch(state);
3308 }
3309 continue;
3310 }
3311 }
3312 flg &= ~MIXFLG_STEREOIN;
3313 if (checkmixbmap(bmap, flg, chidx[i], nroutch)) {
3314 ch = getmixchannel(state, getvolchannel(state));
3315 if (ch) {
3316 ch->unitid = mixer[3];
3317 ch->selector = 0;
3318 ch->chnum = chidx[i]+1;
3319 ch->flags = flg;
3320 prepmixch(state);
3321 }
3322 }
3323 }
3324 state->termtype = 0;
3325}
3326
3327static struct mixerchannel *slctsrc_findunit(struct consmixstate *state, __u8 unitid)
3328{
3329 unsigned int i;
3330
3331 for (i = 0; i < state->nrmixch; i++)
3332 if (state->mixch[i].unitid == unitid)
3333 return &state->mixch[i];
3334 return NULL;
3335}
3336
3337static void usb_audio_selectorunit(struct consmixstate *state, unsigned char *selector)
3338{
3339 unsigned int chnum, i, mixch;
3340 struct mixerchannel *mch;
3341
3342 if (!selector[4]) {
3343 printk(KERN_ERR "usbaudio: unit %u invalid SELECTOR_UNIT descriptor\n", selector[3]);
3344 return;
3345 }
3346 mixch = state->nrmixch;
3347 usb_audio_recurseunit(state, selector[5]);
3348 if (state->nrmixch != mixch) {
3349 mch = &state->mixch[state->nrmixch-1];
3350 mch->slctunitid = selector[3] | (1 << 8);
3351 } else if ((mch = slctsrc_findunit(state, selector[5]))) {
3352 mch->slctunitid = selector[3] | (1 << 8);
3353 } else {
3354 printk(KERN_INFO "usbaudio: selector unit %u: ignoring channel 1\n", selector[3]);
3355 }
3356 chnum = state->nrchannels;
3357 for (i = 1; i < selector[4]; i++) {
3358 mixch = state->nrmixch;
3359 usb_audio_recurseunit(state, selector[5+i]);
3360 if (chnum != state->nrchannels) {
3361 printk(KERN_ERR "usbaudio: selector unit %u: input pins with varying channel numbers\n", selector[3]);
3362 state->termtype = 0;
3363 state->chconfig = 0;
3364 state->nrchannels = 0;
3365 return;
3366 }
3367 if (state->nrmixch != mixch) {
3368 mch = &state->mixch[state->nrmixch-1];
3369 mch->slctunitid = selector[3] | ((i + 1) << 8);
3370 } else if ((mch = slctsrc_findunit(state, selector[5+i]))) {
3371 mch->slctunitid = selector[3] | ((i + 1) << 8);
3372 } else {
3373 printk(KERN_INFO "usbaudio: selector unit %u: ignoring channel %u\n", selector[3], i+1);
3374 }
3375 }
3376 state->termtype = 0;
3377 state->chconfig = 0;
3378}
3379
3380/* in the future we might try to handle 3D etc. effect units */
3381
3382static void usb_audio_processingunit(struct consmixstate *state, unsigned char *proc)
3383{
3384 unsigned int i;
3385
3386 for (i = 0; i < proc[6]; i++)
3387 usb_audio_recurseunit(state, proc[7+i]);
3388 state->nrchannels = proc[7+proc[6]];
3389 state->termtype = 0;
3390 state->chconfig = proc[8+proc[6]] | (proc[9+proc[6]] << 8);
3391}
3392
3393
3394/* See Audio Class Spec, section 4.3.2.5 */
3395static void usb_audio_featureunit(struct consmixstate *state, unsigned char *ftr)
3396{
3397 struct mixerchannel *ch;
3398 unsigned short chftr, mchftr;
3399#if 0
3400 struct usb_device *dev = state->s->usbdev;
3401 unsigned char data[1];
3402#endif
3403 unsigned char nr_logical_channels, i;
3404
3405 usb_audio_recurseunit(state, ftr[4]);
3406
3407 if (ftr[5] == 0 ) {
3408 printk(KERN_ERR "usbaudio: wrong controls size in feature unit %u\n",ftr[3]);
3409 return;
3410 }
3411
3412 if (state->nrchannels == 0) {
3413 printk(KERN_ERR "usbaudio: feature unit %u source has no channels\n", ftr[3]);
3414 return;
3415 }
3416 if (state->nrchannels > 2)
3417 printk(KERN_WARNING "usbaudio: feature unit %u: OSS mixer interface does not support more than 2 channels\n", ftr[3]);
3418
3419 nr_logical_channels=(ftr[0]-7)/ftr[5]-1;
3420
3421 if (nr_logical_channels != state->nrchannels) {
3422 printk(KERN_WARNING "usbaudio: warning: found %d of %d logical channels.\n", state->nrchannels,nr_logical_channels);
3423
3424 if (state->nrchannels == 1 && nr_logical_channels==0) {
3425 printk(KERN_INFO "usbaudio: assuming the channel found is the master channel (got a Philips camera?). Should be fine.\n");
3426 } else if (state->nrchannels == 1 && nr_logical_channels==2) {
3427 printk(KERN_INFO "usbaudio: assuming that a stereo channel connected directly to a mixer is missing in search (got Labtec headset?). Should be fine.\n");
3428 state->nrchannels=nr_logical_channels;
3429 } else {
3430 printk(KERN_WARNING "usbaudio: no idea what's going on..., contact linux-usb-devel@lists.sourceforge.net\n");
3431 }
3432 }
3433
3434 /* There is always a master channel */
3435 mchftr = ftr[6];
3436 /* Binary AND over logical channels if they exist */
3437 if (nr_logical_channels) {
3438 chftr = ftr[6+ftr[5]];
3439 for (i = 2; i <= nr_logical_channels; i++)
3440 chftr &= ftr[6+i*ftr[5]];
3441 } else {
3442 chftr = 0;
3443 }
3444
3445 /* volume control */
3446 if (chftr & 2) {
3447 ch = getmixchannel(state, getvolchannel(state));
3448 if (ch) {
3449 ch->unitid = ftr[3];
3450 ch->selector = VOLUME_CONTROL;
3451 ch->chnum = 1;
3452 ch->flags = (state->nrchannels > 1) ? (MIXFLG_STEREOIN | MIXFLG_STEREOOUT) : 0;
3453 prepmixch(state);
3454 }
3455 } else if (mchftr & 2) {
3456 ch = getmixchannel(state, getvolchannel(state));
3457 if (ch) {
3458 ch->unitid = ftr[3];
3459 ch->selector = VOLUME_CONTROL;
3460 ch->chnum = 0;
3461 ch->flags = 0;
3462 prepmixch(state);
3463 }
3464 }
3465 /* bass control */
3466 if (chftr & 4) {
3467 ch = getmixchannel(state, SOUND_MIXER_BASS);
3468 if (ch) {
3469 ch->unitid = ftr[3];
3470 ch->selector = BASS_CONTROL;
3471 ch->chnum = 1;
3472 ch->flags = (state->nrchannels > 1) ? (MIXFLG_STEREOIN | MIXFLG_STEREOOUT) : 0;
3473 prepmixch(state);
3474 }
3475 } else if (mchftr & 4) {
3476 ch = getmixchannel(state, SOUND_MIXER_BASS);
3477 if (ch) {
3478 ch->unitid = ftr[3];
3479 ch->selector = BASS_CONTROL;
3480 ch->chnum = 0;
3481 ch->flags = 0;
3482 prepmixch(state);
3483 }
3484 }
3485 /* treble control */
3486 if (chftr & 16) {
3487 ch = getmixchannel(state, SOUND_MIXER_TREBLE);
3488 if (ch) {
3489 ch->unitid = ftr[3];
3490 ch->selector = TREBLE_CONTROL;
3491 ch->chnum = 1;
3492 ch->flags = (state->nrchannels > 1) ? (MIXFLG_STEREOIN | MIXFLG_STEREOOUT) : 0;
3493 prepmixch(state);
3494 }
3495 } else if (mchftr & 16) {
3496 ch = getmixchannel(state, SOUND_MIXER_TREBLE);
3497 if (ch) {
3498 ch->unitid = ftr[3];
3499 ch->selector = TREBLE_CONTROL;
3500 ch->chnum = 0;
3501 ch->flags = 0;
3502 prepmixch(state);
3503 }
3504 }
3505#if 0
3506 /* if there are mute controls, unmute them */
3507 /* does not seem to be necessary, and the Dallas chip does not seem to support the "all" channel (255) */
3508 if ((chftr & 1) || (mchftr & 1)) {
3509 printk(KERN_DEBUG "usbaudio: unmuting feature unit %u interface %u\n", ftr[3], state->ctrlif);
3510 data[0] = 0;
3511 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
3512 (MUTE_CONTROL << 8) | 0xff, state->ctrlif | (ftr[3] << 8), data, 1, 1000) < 0)
3513 printk(KERN_WARNING "usbaudio: failure to unmute feature unit %u interface %u\n", ftr[3], state->ctrlif);
3514 }
3515#endif
3516}
3517
3518static void usb_audio_recurseunit(struct consmixstate *state, unsigned char unitid)
3519{
3520 unsigned char *p1;
3521 unsigned int i, j;
3522
3523 if (test_and_set_bit(unitid, state->unitbitmap)) {
3524 printk(KERN_INFO "usbaudio: mixer path revisits unit %d\n", unitid);
3525 return;
3526 }
3527 p1 = find_audiocontrol_unit(state->buffer, state->buflen, NULL, unitid, state->ctrlif);
3528 if (!p1) {
3529 printk(KERN_ERR "usbaudio: unit %d not found!\n", unitid);
3530 return;
3531 }
3532 state->nrchannels = 0;
3533 state->termtype = 0;
3534 state->chconfig = 0;
3535 switch (p1[2]) {
3536 case INPUT_TERMINAL:
3537 if (p1[0] < 12) {
3538 printk(KERN_ERR "usbaudio: unit %u: invalid INPUT_TERMINAL descriptor\n", unitid);
3539 return;
3540 }
3541 state->nrchannels = p1[7];
3542 state->termtype = p1[4] | (p1[5] << 8);
3543 state->chconfig = p1[8] | (p1[9] << 8);
3544 return;
3545
3546 case MIXER_UNIT:
3547 if (p1[0] < 10 || p1[0] < 10+p1[4]) {
3548 printk(KERN_ERR "usbaudio: unit %u: invalid MIXER_UNIT descriptor\n", unitid);
3549 return;
3550 }
3551 usb_audio_mixerunit(state, p1);
3552 return;
3553
3554 case SELECTOR_UNIT:
3555 if (p1[0] < 6 || p1[0] < 6+p1[4]) {
3556 printk(KERN_ERR "usbaudio: unit %u: invalid SELECTOR_UNIT descriptor\n", unitid);
3557 return;
3558 }
3559 usb_audio_selectorunit(state, p1);
3560 return;
3561
3562 case FEATURE_UNIT: /* See USB Audio Class Spec 4.3.2.5 */
3563 if (p1[0] < 7 || p1[0] < 7+p1[5]) {
3564 printk(KERN_ERR "usbaudio: unit %u: invalid FEATURE_UNIT descriptor\n", unitid);
3565 return;
3566 }
3567 usb_audio_featureunit(state, p1);
3568 return;
3569
3570 case PROCESSING_UNIT:
3571 if (p1[0] < 13 || p1[0] < 13+p1[6] || p1[0] < 13+p1[6]+p1[11+p1[6]]) {
3572 printk(KERN_ERR "usbaudio: unit %u: invalid PROCESSING_UNIT descriptor\n", unitid);
3573 return;
3574 }
3575 usb_audio_processingunit(state, p1);
3576 return;
3577
3578 case EXTENSION_UNIT:
3579 if (p1[0] < 13 || p1[0] < 13+p1[6] || p1[0] < 13+p1[6]+p1[11+p1[6]]) {
3580 printk(KERN_ERR "usbaudio: unit %u: invalid EXTENSION_UNIT descriptor\n", unitid);
3581 return;
3582 }
3583 for (j = i = 0; i < p1[6]; i++) {
3584 usb_audio_recurseunit(state, p1[7+i]);
3585 if (!i)
3586 j = state->termtype;
3587 else if (j != state->termtype)
3588 j = 0;
3589 }
3590 state->nrchannels = p1[7+p1[6]];
3591 state->chconfig = p1[8+p1[6]] | (p1[9+p1[6]] << 8);
3592 state->termtype = j;
3593 return;
3594
3595 default:
3596 printk(KERN_ERR "usbaudio: unit %u: unexpected type 0x%02x\n", unitid, p1[2]);
3597 return;
3598 }
3599}
3600
3601static void usb_audio_constructmixer(struct usb_audio_state *s, unsigned char *buffer, unsigned int buflen, unsigned int ctrlif, unsigned char *oterm)
3602{
3603 struct usb_mixerdev *ms;
3604 struct consmixstate state;
3605
3606 memset(&state, 0, sizeof(state));
3607 state.s = s;
3608 state.nrmixch = 0;
3609 state.mixchmask = ~0;
3610 state.buffer = buffer;
3611 state.buflen = buflen;
3612 state.ctrlif = ctrlif;
3613 set_bit(oterm[3], state.unitbitmap); /* mark terminal ID as visited */
3614 printk(KERN_DEBUG "usbaudio: constructing mixer for Terminal %u type 0x%04x\n",
3615 oterm[3], oterm[4] | (oterm[5] << 8));
3616 usb_audio_recurseunit(&state, oterm[7]);
3617 if (!state.nrmixch) {
3618 printk(KERN_INFO "usbaudio: no mixer controls found for Terminal %u\n", oterm[3]);
3619 return;
3620 }
3621 if (!(ms = kmalloc(sizeof(struct usb_mixerdev)+state.nrmixch*sizeof(struct mixerchannel), GFP_KERNEL)))
3622 return;
3623 memset(ms, 0, sizeof(struct usb_mixerdev));
3624 memcpy(&ms->ch, &state.mixch, state.nrmixch*sizeof(struct mixerchannel));
3625 ms->state = s;
3626 ms->iface = ctrlif;
3627 ms->numch = state.nrmixch;
3628 if ((ms->dev_mixer = register_sound_mixer(&usb_mixer_fops, -1)) < 0) {
3629 printk(KERN_ERR "usbaudio: cannot register mixer\n");
3630 kfree(ms);
3631 return;
3632 }
3633 printk(KERN_INFO "usbaudio: registered mixer 14,%d\n", ms->dev_mixer);
3634 list_add_tail(&ms->list, &s->mixerlist);
3635}
3636
3637/* arbitrary limit, we won't check more interfaces than this */
3638#define USB_MAXINTERFACES 32
3639
3640static struct usb_audio_state *usb_audio_parsecontrol(struct usb_device *dev, unsigned char *buffer, unsigned int buflen, unsigned int ctrlif)
3641{
3642 struct usb_audio_state *s;
3643 struct usb_interface *iface;
3644 struct usb_host_interface *alt;
3645 unsigned char ifin[USB_MAXINTERFACES], ifout[USB_MAXINTERFACES];
3646 unsigned char *p1;
3647 unsigned int i, j, k, numifin = 0, numifout = 0;
3648
3649 if (!(s = kmalloc(sizeof(struct usb_audio_state), GFP_KERNEL)))
3650 return NULL;
3651 memset(s, 0, sizeof(struct usb_audio_state));
3652 INIT_LIST_HEAD(&s->audiolist);
3653 INIT_LIST_HEAD(&s->mixerlist);
3654 s->usbdev = dev;
3655 s->count = 1;
3656
3657 /* find audiocontrol interface */
3658 if (!(p1 = find_csinterface_descriptor(buffer, buflen, NULL, HEADER, ctrlif, -1))) {
3659 printk(KERN_ERR "usbaudio: device %d audiocontrol interface %u no HEADER found\n",
3660 dev->devnum, ctrlif);
3661 goto ret;
3662 }
3663 if (p1[0] < 8 + p1[7]) {
3664 printk(KERN_ERR "usbaudio: device %d audiocontrol interface %u HEADER error\n",
3665 dev->devnum, ctrlif);
3666 goto ret;
3667 }
3668 if (!p1[7])
3669 printk(KERN_INFO "usbaudio: device %d audiocontrol interface %u has no AudioStreaming and MidiStreaming interfaces\n",
3670 dev->devnum, ctrlif);
3671 for (i = 0; i < p1[7]; i++) {
3672 j = p1[8+i];
3673 iface = usb_ifnum_to_if(dev, j);
3674 if (!iface) {
3675 printk(KERN_ERR "usbaudio: device %d audiocontrol interface %u interface %u does not exist\n",
3676 dev->devnum, ctrlif, j);
3677 continue;
3678 }
3679 if (iface->num_altsetting == 1) {
3680 printk(KERN_ERR "usbaudio: device %d audiocontrol interface %u has only 1 altsetting.\n", dev->devnum, ctrlif);
3681 continue;
3682 }
3683 alt = usb_altnum_to_altsetting(iface, 0);
3684 if (!alt) {
3685 printk(KERN_ERR "usbaudio: device %d audiocontrol interface %u interface %u has no altsetting 0\n",
3686 dev->devnum, ctrlif, j);
3687 continue;
3688 }
3689 if (alt->desc.bInterfaceClass != USB_CLASS_AUDIO) {
3690 printk(KERN_ERR "usbaudio: device %d audiocontrol interface %u interface %u is not an AudioClass interface\n",
3691 dev->devnum, ctrlif, j);
3692 continue;
3693 }
3694 if (alt->desc.bInterfaceSubClass == 3) {
3695 printk(KERN_INFO "usbaudio: device %d audiocontrol interface %u interface %u MIDIStreaming not supported\n",
3696 dev->devnum, ctrlif, j);
3697 continue;
3698 }
3699 if (alt->desc.bInterfaceSubClass != 2) {
3700 printk(KERN_ERR "usbaudio: device %d audiocontrol interface %u interface %u invalid AudioClass subtype\n",
3701 dev->devnum, ctrlif, j);
3702 continue;
3703 }
3704 if (alt->desc.bNumEndpoints > 0) {
3705 /* Check all endpoints; should they all have a bandwidth of 0 ? */
3706 for (k = 0; k < alt->desc.bNumEndpoints; k++) {
3707 if (le16_to_cpu(alt->endpoint[k].desc.wMaxPacketSize) > 0) {
3708 printk(KERN_ERR "usbaudio: device %d audiocontrol interface %u endpoint %d does not have 0 bandwidth at alt[0]\n", dev->devnum, ctrlif, k);
3709 break;
3710 }
3711 }
3712 if (k < alt->desc.bNumEndpoints)
3713 continue;
3714 }
3715
3716 alt = usb_altnum_to_altsetting(iface, 1);
3717 if (!alt) {
3718 printk(KERN_ERR "usbaudio: device %d audiocontrol interface %u interface %u has no altsetting 1\n",
3719 dev->devnum, ctrlif, j);
3720 continue;
3721 }
3722 if (alt->desc.bNumEndpoints < 1) {
3723 printk(KERN_ERR "usbaudio: device %d audiocontrol interface %u interface %u has no endpoint\n",
3724 dev->devnum, ctrlif, j);
3725 continue;
3726 }
3727 /* note: this requires the data endpoint to be ep0 and the optional sync
3728 ep to be ep1, which seems to be the case */
3729 if (alt->endpoint[0].desc.bEndpointAddress & USB_DIR_IN) {
3730 if (numifin < USB_MAXINTERFACES) {
3731 ifin[numifin++] = j;
3732 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1);
3733 }
3734 } else {
3735 if (numifout < USB_MAXINTERFACES) {
3736 ifout[numifout++] = j;
3737 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1);
3738 }
3739 }
3740 }
3741 printk(KERN_INFO "usbaudio: device %d audiocontrol interface %u has %u input and %u output AudioStreaming interfaces\n",
3742 dev->devnum, ctrlif, numifin, numifout);
3743 for (i = 0; i < numifin && i < numifout; i++)
3744 usb_audio_parsestreaming(s, buffer, buflen, ifin[i], ifout[i]);
3745 for (j = i; j < numifin; j++)
3746 usb_audio_parsestreaming(s, buffer, buflen, ifin[i], -1);
3747 for (j = i; j < numifout; j++)
3748 usb_audio_parsestreaming(s, buffer, buflen, -1, ifout[i]);
3749 /* now walk through all OUTPUT_TERMINAL descriptors to search for mixers */
3750 p1 = find_csinterface_descriptor(buffer, buflen, NULL, OUTPUT_TERMINAL, ctrlif, -1);
3751 while (p1) {
3752 if (p1[0] >= 9)
3753 usb_audio_constructmixer(s, buffer, buflen, ctrlif, p1);
3754 p1 = find_csinterface_descriptor(buffer, buflen, p1, OUTPUT_TERMINAL, ctrlif, -1);
3755 }
3756
3757ret:
3758 if (list_empty(&s->audiolist) && list_empty(&s->mixerlist)) {
3759 kfree(s);
3760 return NULL;
3761 }
3762 /* everything successful */
3763 down(&open_sem);
3764 list_add_tail(&s->audiodev, &audiodevs);
3765 up(&open_sem);
3766 printk(KERN_DEBUG "usb_audio_parsecontrol: usb_audio_state at %p\n", s);
3767 return s;
3768}
3769
3770/* we only care for the currently active configuration */
3771
3772static int usb_audio_probe(struct usb_interface *intf,
3773 const struct usb_device_id *id)
3774{
3775 struct usb_device *dev = interface_to_usbdev (intf);
3776 struct usb_audio_state *s;
3777 unsigned char *buffer;
3778 unsigned int buflen;
3779
3780#if 0
3781 printk(KERN_DEBUG "usbaudio: Probing if %i: IC %x, ISC %x\n", ifnum,
3782 config->interface[ifnum].altsetting[0].desc.bInterfaceClass,
3783 config->interface[ifnum].altsetting[0].desc.bInterfaceSubClass);
3784#endif
3785
3786 /*
3787 * audiocontrol interface found
3788 * find which configuration number is active
3789 */
3790 buffer = dev->rawdescriptors[dev->actconfig - dev->config];
3791 buflen = le16_to_cpu(dev->actconfig->desc.wTotalLength);
3792 s = usb_audio_parsecontrol(dev, buffer, buflen, intf->altsetting->desc.bInterfaceNumber);
3793 if (s) {
3794 usb_set_intfdata (intf, s);
3795 return 0;
3796 }
3797 return -ENODEV;
3798}
3799
3800
3801/* a revoke facility would make things simpler */
3802
3803static void usb_audio_disconnect(struct usb_interface *intf)
3804{
3805 struct usb_audio_state *s = usb_get_intfdata (intf);
3806 struct usb_audiodev *as;
3807 struct usb_mixerdev *ms;
3808
3809 if (!s)
3810 return;
3811
3812 /* we get called with -1 for every audiostreaming interface registered */
3813 if (s == (struct usb_audio_state *)-1) {
3814 dprintk((KERN_DEBUG "usbaudio: note, usb_audio_disconnect called with -1\n"));
3815 return;
3816 }
3817 if (!s->usbdev) {
3818 dprintk((KERN_DEBUG "usbaudio: error, usb_audio_disconnect already called for %p!\n", s));
3819 return;
3820 }
3821 down(&open_sem);
3822 list_del_init(&s->audiodev);
3823 s->usbdev = NULL;
3824 usb_set_intfdata (intf, NULL);
3825
3826 /* deregister all audio and mixer devices, so no new processes can open this device */
3827 list_for_each_entry(as, &s->audiolist, list) {
3828 usbin_disc(as);
3829 usbout_disc(as);
3830 wake_up(&as->usbin.dma.wait);
3831 wake_up(&as->usbout.dma.wait);
3832 if (as->dev_audio >= 0) {
3833 unregister_sound_dsp(as->dev_audio);
3834 printk(KERN_INFO "usbaudio: unregister dsp 14,%d\n", as->dev_audio);
3835 }
3836 as->dev_audio = -1;
3837 }
3838 list_for_each_entry(ms, &s->mixerlist, list) {
3839 if (ms->dev_mixer >= 0) {
3840 unregister_sound_mixer(ms->dev_mixer);
3841 printk(KERN_INFO "usbaudio: unregister mixer 14,%d\n", ms->dev_mixer);
3842 }
3843 ms->dev_mixer = -1;
3844 }
3845 release(s);
3846 wake_up(&open_wait);
3847}
3848
3849static int __init usb_audio_init(void)
3850{
3851 int result = usb_register(&usb_audio_driver);
3852 if (result == 0)
3853 info(DRIVER_VERSION ":" DRIVER_DESC);
3854 return result;
3855}
3856
3857
3858static void __exit usb_audio_cleanup(void)
3859{
3860 usb_deregister(&usb_audio_driver);
3861}
3862
3863module_init(usb_audio_init);
3864module_exit(usb_audio_cleanup);
3865
3866MODULE_AUTHOR( DRIVER_AUTHOR );
3867MODULE_DESCRIPTION( DRIVER_DESC );
3868MODULE_LICENSE("GPL");
3869
diff --git a/drivers/usb/class/audio.h b/drivers/usb/class/audio.h
deleted file mode 100644
index 45916eb12103..000000000000
--- a/drivers/usb/class/audio.h
+++ /dev/null
@@ -1,110 +0,0 @@
1#define CS_AUDIO_UNDEFINED 0x20
2#define CS_AUDIO_DEVICE 0x21
3#define CS_AUDIO_CONFIGURATION 0x22
4#define CS_AUDIO_STRING 0x23
5#define CS_AUDIO_INTERFACE 0x24
6#define CS_AUDIO_ENDPOINT 0x25
7
8#define HEADER 0x01
9#define INPUT_TERMINAL 0x02
10#define OUTPUT_TERMINAL 0x03
11#define MIXER_UNIT 0x04
12#define SELECTOR_UNIT 0x05
13#define FEATURE_UNIT 0x06
14#define PROCESSING_UNIT 0x07
15#define EXTENSION_UNIT 0x08
16
17#define AS_GENERAL 0x01
18#define FORMAT_TYPE 0x02
19#define FORMAT_SPECIFIC 0x03
20
21#define EP_GENERAL 0x01
22
23#define MAX_CHAN 9
24#define MAX_FREQ 16
25#define MAX_IFACE 8
26#define MAX_FORMAT 8
27#define MAX_ALT 32 /* Sorry, we need quite a few for the Philips webcams */
28
29struct usb_audio_terminal
30{
31 u8 flags;
32 u8 assoc;
33 u16 type; /* Mic etc */
34 u8 channels;
35 u8 source;
36 u16 chancfg;
37};
38
39struct usb_audio_format
40{
41 u8 type;
42 u8 channels;
43 u8 num_freq;
44 u8 sfz;
45 u8 bits;
46 u16 freq[MAX_FREQ];
47};
48
49struct usb_audio_interface
50{
51 u8 terminal;
52 u8 delay;
53 u16 num_formats;
54 u16 format_type;
55 u8 flags;
56 u8 idleconf; /* Idle config */
57#define AU_IFACE_FOUND 1
58 struct usb_audio_format format[MAX_FORMAT];
59};
60
61struct usb_audio_device
62{
63 struct list_head list;
64 u8 mixer;
65 u8 selector;
66 void *irq_handle;
67 u8 num_channels;
68 u8 num_dsp_iface;
69 u8 channel_map[MAX_CHAN];
70 struct usb_audio_terminal terminal[MAX_CHAN];
71 struct usb_audio_interface interface[MAX_IFACE][MAX_ALT];
72};
73
74
75
76/* Audio Class specific Request Codes */
77
78#define SET_CUR 0x01
79#define GET_CUR 0x81
80#define SET_MIN 0x02
81#define GET_MIN 0x82
82#define SET_MAX 0x03
83#define GET_MAX 0x83
84#define SET_RES 0x04
85#define GET_RES 0x84
86#define SET_MEM 0x05
87#define GET_MEM 0x85
88#define GET_STAT 0xff
89
90/* Terminal Control Selectors */
91
92#define COPY_PROTECT_CONTROL 0x01
93
94/* Feature Unit Control Selectors */
95
96#define MUTE_CONTROL 0x01
97#define VOLUME_CONTROL 0x02
98#define BASS_CONTROL 0x03
99#define MID_CONTROL 0x04
100#define TREBLE_CONTROL 0x05
101#define GRAPHIC_EQUALIZER_CONTROL 0x06
102#define AUTOMATIC_GAIN_CONTROL 0x07
103#define DELAY_CONTROL 0x08
104#define BASS_BOOST_CONTROL 0x09
105#define LOUDNESS_CONTROL 0x0a
106
107/* Endpoint Control Selectors */
108
109#define SAMPLING_FREQ_CONTROL 0x01
110#define PITCH_CONTROL 0x02
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 97bdeb1c2181..6dd339f4c0fc 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -60,6 +60,7 @@
60#include <linux/tty_flip.h> 60#include <linux/tty_flip.h>
61#include <linux/module.h> 61#include <linux/module.h>
62#include <linux/smp_lock.h> 62#include <linux/smp_lock.h>
63#include <linux/mutex.h>
63#include <asm/uaccess.h> 64#include <asm/uaccess.h>
64#include <linux/usb.h> 65#include <linux/usb.h>
65#include <linux/usb_cdc.h> 66#include <linux/usb_cdc.h>
@@ -80,7 +81,7 @@ static struct usb_driver acm_driver;
80static struct tty_driver *acm_tty_driver; 81static struct tty_driver *acm_tty_driver;
81static struct acm *acm_table[ACM_TTY_MINORS]; 82static struct acm *acm_table[ACM_TTY_MINORS];
82 83
83static DECLARE_MUTEX(open_sem); 84static DEFINE_MUTEX(open_mutex);
84 85
85#define ACM_READY(acm) (acm && acm->dev && acm->used) 86#define ACM_READY(acm) (acm && acm->dev && acm->used)
86 87
@@ -431,8 +432,8 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
431 int rv = -EINVAL; 432 int rv = -EINVAL;
432 int i; 433 int i;
433 dbg("Entering acm_tty_open.\n"); 434 dbg("Entering acm_tty_open.\n");
434 435
435 down(&open_sem); 436 mutex_lock(&open_mutex);
436 437
437 acm = acm_table[tty->index]; 438 acm = acm_table[tty->index];
438 if (!acm || !acm->dev) 439 if (!acm || !acm->dev)
@@ -474,14 +475,14 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
474 475
475done: 476done:
476err_out: 477err_out:
477 up(&open_sem); 478 mutex_unlock(&open_mutex);
478 return rv; 479 return rv;
479 480
480full_bailout: 481full_bailout:
481 usb_kill_urb(acm->ctrlurb); 482 usb_kill_urb(acm->ctrlurb);
482bail_out: 483bail_out:
483 acm->used--; 484 acm->used--;
484 up(&open_sem); 485 mutex_unlock(&open_mutex);
485 return -EIO; 486 return -EIO;
486} 487}
487 488
@@ -507,7 +508,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
507 if (!acm || !acm->used) 508 if (!acm || !acm->used)
508 return; 509 return;
509 510
510 down(&open_sem); 511 mutex_lock(&open_mutex);
511 if (!--acm->used) { 512 if (!--acm->used) {
512 if (acm->dev) { 513 if (acm->dev) {
513 acm_set_control(acm, acm->ctrlout = 0); 514 acm_set_control(acm, acm->ctrlout = 0);
@@ -518,7 +519,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
518 } else 519 } else
519 acm_tty_unregister(acm); 520 acm_tty_unregister(acm);
520 } 521 }
521 up(&open_sem); 522 mutex_unlock(&open_mutex);
522} 523}
523 524
524static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) 525static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
@@ -1013,9 +1014,9 @@ static void acm_disconnect(struct usb_interface *intf)
1013 return; 1014 return;
1014 } 1015 }
1015 1016
1016 down(&open_sem); 1017 mutex_lock(&open_mutex);
1017 if (!usb_get_intfdata(intf)) { 1018 if (!usb_get_intfdata(intf)) {
1018 up(&open_sem); 1019 mutex_unlock(&open_mutex);
1019 return; 1020 return;
1020 } 1021 }
1021 acm->dev = NULL; 1022 acm->dev = NULL;
@@ -1045,11 +1046,11 @@ static void acm_disconnect(struct usb_interface *intf)
1045 1046
1046 if (!acm->used) { 1047 if (!acm->used) {
1047 acm_tty_unregister(acm); 1048 acm_tty_unregister(acm);
1048 up(&open_sem); 1049 mutex_unlock(&open_mutex);
1049 return; 1050 return;
1050 } 1051 }
1051 1052
1052 up(&open_sem); 1053 mutex_unlock(&open_mutex);
1053 1054
1054 if (acm->tty) 1055 if (acm->tty)
1055 tty_hangup(acm->tty); 1056 tty_hangup(acm->tty);
diff --git a/drivers/usb/class/usb-midi.c b/drivers/usb/class/usb-midi.c
deleted file mode 100644
index f13f004d311f..000000000000
--- a/drivers/usb/class/usb-midi.c
+++ /dev/null
@@ -1,2153 +0,0 @@
1/*
2 usb-midi.c -- USB-MIDI driver
3
4 Copyright (C) 2001
5 NAGANO Daisuke <breeze.nagano@nifty.ne.jp>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 This driver is based on:
22 - 'Universal Serial Bus Device Class Definition for MIDI Device'
23 - linux/drivers/sound/es1371.c, linux/drivers/usb/audio.c
24 - alsa/lowlevel/pci/cs64xx.c
25 - umidi.c for NetBSD
26 */
27
28/* ------------------------------------------------------------------------- */
29
30
31#include <linux/module.h>
32#include <linux/kernel.h>
33#include <linux/sched.h>
34#include <linux/list.h>
35#include <linux/slab.h>
36#include <linux/usb.h>
37#include <linux/poll.h>
38#include <linux/sound.h>
39#include <linux/init.h>
40#include <asm/semaphore.h>
41
42#include "usb-midi.h"
43
44/* ------------------------------------------------------------------------- */
45
46/* More verbose on syslog */
47#undef MIDI_DEBUG
48
49#define MIDI_IN_BUFSIZ 1024
50
51#define HAVE_SUPPORT_USB_MIDI_CLASS
52
53#undef HAVE_SUPPORT_ALSA
54
55/* ------------------------------------------------------------------------- */
56
57static int singlebyte = 0;
58module_param(singlebyte, int, 0);
59MODULE_PARM_DESC(singlebyte,"Enable sending MIDI messages with single message packet");
60
61static int maxdevices = 4;
62module_param(maxdevices, int, 0);
63MODULE_PARM_DESC(maxdevices,"Max number of allocatable MIDI device");
64
65static int uvendor = -1;
66module_param(uvendor, int, 0);
67MODULE_PARM_DESC(uvendor, "The USB Vendor ID of a semi-compliant interface");
68
69static int uproduct = -1;
70module_param(uproduct, int, 0);
71MODULE_PARM_DESC(uproduct, "The USB Product ID of a semi-compliant interface");
72
73static int uinterface = -1;
74module_param(uinterface, int, 0);
75MODULE_PARM_DESC(uinterface, "The Interface number of a semi-compliant interface");
76
77static int ualt = -1;
78module_param(ualt, int, 0);
79MODULE_PARM_DESC(ualt, "The optional alternative setting of a semi-compliant interface");
80
81static int umin = -1;
82module_param(umin, int, 0);
83MODULE_PARM_DESC(umin, "The input endpoint of a semi-compliant interface");
84
85static int umout = -1;
86module_param(umout, int, 0);
87MODULE_PARM_DESC(umout, "The output endpoint of a semi-compliant interface");
88
89static int ucable = -1;
90module_param(ucable, int, 0);
91MODULE_PARM_DESC(ucable, "The cable number used for a semi-compliant interface");
92
93/** Note -- the usb_string() returns only Latin-1 characters.
94 * (unicode chars <= 255). To support Japanese, a unicode16LE-to-EUC or
95 * unicode16LE-to-JIS routine is needed to wrap around usb_get_string().
96 **/
97static unsigned short ulangid = 0x0409; /** 0x0411 for Japanese **/
98module_param(ulangid, ushort, 0);
99MODULE_PARM_DESC(ulangid, "The optional preferred USB Language ID for all devices");
100
101MODULE_AUTHOR("NAGANO Daisuke <breeze.nagano@nifty.ne.jp>");
102MODULE_DESCRIPTION("USB-MIDI driver");
103MODULE_LICENSE("GPL");
104
105/* ------------------------------------------------------------------------- */
106
107/** MIDIStreaming Class-Specific Interface Descriptor Subtypes **/
108
109#define MS_DESCRIPTOR_UNDEFINED 0
110#define MS_HEADER 1
111#define MIDI_IN_JACK 2
112#define MIDI_OUT_JACK 3
113/* Spec reads: ELEMENT */
114#define ELEMENT_DESCRIPTOR 4
115
116#define MS_HEADER_LENGTH 7
117
118/** MIDIStreaming Class-Specific Endpoint Descriptor Subtypes **/
119
120#define DESCRIPTOR_UNDEFINED 0
121/* Spec reads: MS_GENERAL */
122#define MS_GENERAL_ENDPOINT 1
123
124/** MIDIStreaming MIDI IN and OUT Jack Types **/
125
126#define JACK_TYPE_UNDEFINED 0
127/* Spec reads: EMBEDDED */
128#define EMBEDDED_JACK 1
129/* Spec reads: EXTERNAL */
130#define EXTERNAL_JACK 2
131
132
133/* structure summary
134
135 usb_midi_state usb_device
136 | |
137 *| *| per ep
138 in_ep out_ep
139 | |
140 *| *| per cable
141 min mout
142 | | (cable to device pairing magic)
143 | |
144 usb_midi_dev dev_id (major,minor) == file->private_data
145
146*/
147
148/* usb_midi_state: corresponds to a USB-MIDI module */
149struct usb_midi_state {
150 struct list_head mididev;
151
152 struct usb_device *usbdev;
153
154 struct list_head midiDevList;
155 struct list_head inEndpointList;
156 struct list_head outEndpointList;
157
158 spinlock_t lock;
159
160 unsigned int count; /* usage counter */
161};
162
163/* midi_out_endpoint: corresponds to an output endpoint */
164struct midi_out_endpoint {
165 struct list_head list;
166
167 struct usb_device *usbdev;
168 int endpoint;
169 spinlock_t lock;
170 wait_queue_head_t wait;
171
172 unsigned char *buf;
173 int bufWrPtr;
174 int bufSize;
175
176 struct urb *urb;
177};
178
179/* midi_in_endpoint: corresponds to an input endpoint */
180struct midi_in_endpoint {
181 struct list_head list;
182
183 struct usb_device *usbdev;
184 int endpoint;
185 spinlock_t lock;
186 wait_queue_head_t wait;
187
188 struct usb_mididev *cables[16]; // cables open for read
189 int readers; // number of cables open for read
190
191 struct urb *urb;
192 unsigned char *recvBuf;
193 int recvBufSize;
194 int urbSubmitted; //FIXME: == readers > 0
195};
196
197/* usb_mididev: corresponds to a logical device */
198struct usb_mididev {
199 struct list_head list;
200
201 struct usb_midi_state *midi;
202 int dev_midi;
203 mode_t open_mode;
204
205 struct {
206 struct midi_in_endpoint *ep;
207 int cableId;
208
209// as we are pushing data from usb_bulk_read to usb_midi_read,
210// we need a larger, cyclic buffer here.
211 unsigned char buf[MIDI_IN_BUFSIZ];
212 int bufRdPtr;
213 int bufWrPtr;
214 int bufRemains;
215 } min;
216
217 struct {
218 struct midi_out_endpoint *ep;
219 int cableId;
220
221 unsigned char buf[3];
222 int bufPtr;
223 int bufRemains;
224
225 int isInExclusive;
226 unsigned char lastEvent;
227 } mout;
228
229 int singlebyte;
230};
231
232/** Map the high nybble of MIDI voice messages to number of Message bytes.
233 * High nyble ranges from 0x8 to 0xe
234 */
235
236static int remains_80e0[] = {
237 3, /** 0x8X Note Off **/
238 3, /** 0x9X Note On **/
239 3, /** 0xAX Poly-key pressure **/
240 3, /** 0xBX Control Change **/
241 2, /** 0xCX Program Change **/
242 2, /** 0xDX Channel pressure **/
243 3 /** 0xEX PitchBend Change **/
244};
245
246/** Map the messages to a number of Message bytes.
247 *
248 **/
249static int remains_f0f6[] = {
250 0, /** 0xF0 **/
251 2, /** 0XF1 **/
252 3, /** 0XF2 **/
253 2, /** 0XF3 **/
254 2, /** 0XF4 (Undefined by MIDI Spec, and subject to change) **/
255 2, /** 0XF5 (Undefined by MIDI Spec, and subject to change) **/
256 1 /** 0XF6 **/
257};
258
259/** Map the messages to a CIN (Code Index Number).
260 *
261 **/
262static int cin_f0ff[] = {
263 4, /** 0xF0 System Exclusive Message Start (special cases may be 6 or 7) */
264 2, /** 0xF1 **/
265 3, /** 0xF2 **/
266 2, /** 0xF3 **/
267 2, /** 0xF4 **/
268 2, /** 0xF5 **/
269 5, /** 0xF6 **/
270 5, /** 0xF7 End of System Exclusive Message (May be 6 or 7) **/
271 5, /** 0xF8 **/
272 5, /** 0xF9 **/
273 5, /** 0xFA **/
274 5, /** 0xFB **/
275 5, /** 0xFC **/
276 5, /** 0xFD **/
277 5, /** 0xFE **/
278 5 /** 0xFF **/
279};
280
281/** Map MIDIStreaming Event packet Code Index Number (low nybble of byte 0)
282 * to the number of bytes of valid MIDI data.
283 *
284 * CIN of 0 and 1 are NOT USED in MIDIStreaming 1.0.
285 *
286 **/
287static int cin_to_len[] = {
288 0, 0, 2, 3,
289 3, 1, 2, 3,
290 3, 3, 3, 3,
291 2, 2, 3, 1
292};
293
294
295/* ------------------------------------------------------------------------- */
296
297static struct list_head mididevs = LIST_HEAD_INIT(mididevs);
298
299static DECLARE_MUTEX(open_sem);
300static DECLARE_WAIT_QUEUE_HEAD(open_wait);
301
302
303/* ------------------------------------------------------------------------- */
304
305static void usb_write_callback(struct urb *urb, struct pt_regs *regs)
306{
307 struct midi_out_endpoint *ep = (struct midi_out_endpoint *)urb->context;
308
309 if ( waitqueue_active( &ep->wait ) )
310 wake_up_interruptible( &ep->wait );
311}
312
313
314static int usb_write( struct midi_out_endpoint *ep, unsigned char *buf, int len )
315{
316 struct usb_device *d;
317 int pipe;
318 int ret = 0;
319 int status;
320 int maxretry = 50;
321
322 DECLARE_WAITQUEUE(wait,current);
323 init_waitqueue_head(&ep->wait);
324
325 d = ep->usbdev;
326 pipe = usb_sndbulkpipe(d, ep->endpoint);
327 usb_fill_bulk_urb( ep->urb, d, pipe, (unsigned char*)buf, len,
328 usb_write_callback, ep );
329
330 status = usb_submit_urb(ep->urb, GFP_KERNEL);
331
332 if (status) {
333 printk(KERN_ERR "usbmidi: Cannot submit urb (%d)\n",status);
334 ret = -EIO;
335 goto error;
336 }
337
338 add_wait_queue( &ep->wait, &wait );
339 set_current_state( TASK_INTERRUPTIBLE );
340
341 while( ep->urb->status == -EINPROGRESS ) {
342 if ( maxretry-- < 0 ) {
343 printk(KERN_ERR "usbmidi: usb_bulk_msg timed out\n");
344 ret = -ETIME;
345 break;
346 }
347 interruptible_sleep_on_timeout( &ep->wait, 10 );
348 }
349 set_current_state( TASK_RUNNING );
350 remove_wait_queue( &ep->wait, &wait );
351
352error:
353 return ret;
354}
355
356
357/** Copy data from URB to In endpoint buf.
358 * Discard if CIN == 0 or CIN = 1.
359 *
360 *
361 **/
362
363static void usb_bulk_read(struct urb *urb, struct pt_regs *regs)
364{
365 struct midi_in_endpoint *ep = (struct midi_in_endpoint *)(urb->context);
366 unsigned char *data = urb->transfer_buffer;
367 int i, j, wake;
368
369 if ( !ep->urbSubmitted ) {
370 return;
371 }
372
373 if ( (urb->status == 0) && (urb->actual_length > 0) ) {
374 wake = 0;
375 spin_lock( &ep->lock );
376
377 for(j = 0; j < urb->actual_length; j += 4) {
378 int cin = (data[j]>>0)&0xf;
379 int cab = (data[j]>>4)&0xf;
380 struct usb_mididev *cable = ep->cables[cab];
381 if ( cable ) {
382 int len = cin_to_len[cin]; /** length of MIDI data **/
383 for (i = 0; i < len; i++) {
384 cable->min.buf[cable->min.bufWrPtr] = data[1+i+j];
385 cable->min.bufWrPtr = (cable->min.bufWrPtr+1)%MIDI_IN_BUFSIZ;
386 if (cable->min.bufRemains < MIDI_IN_BUFSIZ)
387 cable->min.bufRemains += 1;
388 else /** need to drop data **/
389 cable->min.bufRdPtr += (cable->min.bufRdPtr+1)%MIDI_IN_BUFSIZ;
390 wake = 1;
391 }
392 }
393 }
394
395 spin_unlock ( &ep->lock );
396 if ( wake ) {
397 wake_up( &ep->wait );
398 }
399 }
400
401 /* urb->dev must be reinitialized on 2.4.x kernels */
402 urb->dev = ep->usbdev;
403
404 urb->actual_length = 0;
405 usb_submit_urb(urb, GFP_ATOMIC);
406}
407
408
409
410/* ------------------------------------------------------------------------- */
411
412/* This routine must be called with spin_lock */
413
414/** Wrapper around usb_write().
415 * This routine must be called with spin_lock held on ep.
416 * Called by midiWrite(), putOneMidiEvent(), and usb_midi_write();
417 **/
418static int flush_midi_buffer( struct midi_out_endpoint *ep )
419{
420 int ret=0;
421
422 if ( ep->bufWrPtr > 0 ) {
423 ret = usb_write( ep, ep->buf, ep->bufWrPtr );
424 ep->bufWrPtr = 0;
425 }
426
427 return ret;
428}
429
430
431/* ------------------------------------------------------------------------- */
432
433
434/** Given a MIDI Event, determine size of data to be attached to
435 * USB-MIDI packet.
436 * Returns 1, 2 or 3.
437 * Called by midiWrite();
438 * Uses remains_80e0 and remains_f0f6;
439 **/
440static int get_remains(int event)
441{
442 int ret;
443
444 if ( event < 0x80 ) {
445 ret = 1;
446 } else if ( event < 0xf0 ) {
447 ret = remains_80e0[((event-0x80)>>4)&0x0f];
448 } else if ( event < 0xf7 ) {
449 ret = remains_f0f6[event-0xf0];
450 } else {
451 ret = 1;
452 }
453
454 return ret;
455}
456
457/** Given the output MIDI data in the output buffer, computes a reasonable
458 * CIN.
459 * Called by putOneMidiEvent().
460 **/
461static int get_CIN( struct usb_mididev *m )
462{
463 int cin;
464
465 if ( m->mout.buf[0] == 0xf7 ) {
466 cin = 5;
467 }
468 else if ( m->mout.buf[1] == 0xf7 ) {
469 cin = 6;
470 }
471 else if ( m->mout.buf[2] == 0xf7 ) {
472 cin = 7;
473 }
474 else {
475 if ( m->mout.isInExclusive == 1 ) {
476 cin = 4;
477 } else if ( m->mout.buf[0] < 0x80 ) {
478 /** One byte that we know nothing about. **/
479 cin = 0xF;
480 } else if ( m->mout.buf[0] < 0xf0 ) {
481 /** MIDI Voice messages 0x8X to 0xEX map to cin 0x8 to 0xE. **/
482 cin = (m->mout.buf[0]>>4)&0x0f;
483 }
484 else {
485 /** Special lookup table exists for real-time events. **/
486 cin = cin_f0ff[m->mout.buf[0]-0xf0];
487 }
488 }
489
490 return cin;
491}
492
493
494/* ------------------------------------------------------------------------- */
495
496
497
498/** Move data to USB endpoint buffer.
499 *
500 **/
501static int put_one_midi_event(struct usb_mididev *m)
502{
503 int cin;
504 unsigned long flags;
505 struct midi_out_endpoint *ep = m->mout.ep;
506 int ret=0;
507
508 cin = get_CIN( m );
509 if ( cin > 0x0f || cin < 0 ) {
510 return -EINVAL;
511 }
512
513 spin_lock_irqsave( &ep->lock, flags );
514 ep->buf[ep->bufWrPtr++] = (m->mout.cableId<<4) | cin;
515 ep->buf[ep->bufWrPtr++] = m->mout.buf[0];
516 ep->buf[ep->bufWrPtr++] = m->mout.buf[1];
517 ep->buf[ep->bufWrPtr++] = m->mout.buf[2];
518 if ( ep->bufWrPtr >= ep->bufSize ) {
519 ret = flush_midi_buffer( ep );
520 }
521 spin_unlock_irqrestore( &ep->lock, flags);
522
523 m->mout.buf[0] = m->mout.buf[1] = m->mout.buf[2] = 0;
524 m->mout.bufPtr = 0;
525
526 return ret;
527}
528
529/** Write the MIDI message v on the midi device.
530 * Called by usb_midi_write();
531 * Responsible for packaging a MIDI data stream into USB-MIDI packets.
532 **/
533
534static int midi_write( struct usb_mididev *m, int v )
535{
536 unsigned long flags;
537 struct midi_out_endpoint *ep = m->mout.ep;
538 int ret=0;
539 unsigned char c = (unsigned char)v;
540 unsigned char sysrt_buf[4];
541
542 if ( m->singlebyte != 0 ) {
543 /** Simple code to handle the single-byte USB-MIDI protocol. */
544 spin_lock_irqsave( &ep->lock, flags );
545 if ( ep->bufWrPtr+4 > ep->bufSize ) {
546 ret = flush_midi_buffer( ep );
547 if ( !ret ) {
548 spin_unlock_irqrestore( &ep->lock, flags );
549 return ret;
550 }
551 }
552 ep->buf[ep->bufWrPtr++] = (m->mout.cableId<<4) | 0x0f; /* single byte */
553 ep->buf[ep->bufWrPtr++] = c;
554 ep->buf[ep->bufWrPtr++] = 0;
555 ep->buf[ep->bufWrPtr++] = 0;
556 if ( ep->bufWrPtr >= ep->bufSize ) {
557 ret = flush_midi_buffer( ep );
558 }
559 spin_unlock_irqrestore( &ep->lock, flags );
560
561 return ret;
562 }
563 /** Normal USB-MIDI protocol begins here. */
564
565 if ( c > 0xf7 ) { /* system: Realtime messages */
566 /** Realtime messages are written IMMEDIATELY. */
567 sysrt_buf[0] = (m->mout.cableId<<4) | 0x0f;
568 sysrt_buf[1] = c;
569 sysrt_buf[2] = 0;
570 sysrt_buf[3] = 0;
571 spin_lock_irqsave( &ep->lock, flags );
572 ret = usb_write( ep, sysrt_buf, 4 );
573 spin_unlock_irqrestore( &ep->lock, flags );
574 /* m->mout.lastEvent = 0; */
575
576 return ret;
577 }
578
579 if ( c >= 0x80 ) {
580 if ( c < 0xf0 ) {
581 m->mout.lastEvent = c;
582 m->mout.isInExclusive = 0;
583 m->mout.bufRemains = get_remains(c);
584 } else if ( c == 0xf0 ) {
585 /* m->mout.lastEvent = 0; */
586 m->mout.isInExclusive = 1;
587 m->mout.bufRemains = get_remains(c);
588 } else if ( c == 0xf7 && m->mout.isInExclusive == 1 ) {
589 /* m->mout.lastEvent = 0; */
590 m->mout.isInExclusive = 0;
591 m->mout.bufRemains = 1;
592 } else if ( c > 0xf0 ) {
593 /* m->mout.lastEvent = 0; */
594 m->mout.isInExclusive = 0;
595 m->mout.bufRemains = get_remains(c);
596 }
597
598 } else if ( m->mout.bufRemains == 0 && m->mout.isInExclusive == 0 ) {
599 if ( m->mout.lastEvent == 0 ) {
600 return 0; /* discard, waiting for the first event */
601 }
602 /** track status **/
603 m->mout.buf[0] = m->mout.lastEvent;
604 m->mout.bufPtr = 1;
605 m->mout.bufRemains = get_remains(m->mout.lastEvent)-1;
606 }
607
608 m->mout.buf[m->mout.bufPtr++] = c;
609 m->mout.bufRemains--;
610 if ( m->mout.bufRemains == 0 || m->mout.bufPtr >= 3) {
611 ret = put_one_midi_event(m);
612 }
613
614 return ret;
615}
616
617
618/* ------------------------------------------------------------------------- */
619
620/** Basic operation on /dev/midiXX as registered through struct file_operations.
621 *
622 * Basic contract: Used to change the current read/write position in a file.
623 * On success, the non-negative position is reported.
624 * On failure, the negative of an error code is reported.
625 *
626 * Because a MIDIStream is not a file, all seek operations are doomed to fail.
627 *
628 **/
629static loff_t usb_midi_llseek(struct file *file, loff_t offset, int origin)
630{
631 /** Tell user you cannot seek on a PIPE-like device. **/
632 return -ESPIPE;
633}
634
635
636/** Basic operation on /dev/midiXX as registered through struct file_operations.
637 *
638 * Basic contract: Block until count bytes have been read or an error occurs.
639 *
640 **/
641
642static ssize_t usb_midi_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
643{
644 struct usb_mididev *m = (struct usb_mididev *)file->private_data;
645 struct midi_in_endpoint *ep = m->min.ep;
646 ssize_t ret;
647 DECLARE_WAITQUEUE(wait, current);
648
649 if ( !access_ok(VERIFY_READ, buffer, count) ) {
650 return -EFAULT;
651 }
652 if ( count == 0 ) {
653 return 0;
654 }
655
656 add_wait_queue( &ep->wait, &wait );
657 ret = 0;
658 while( count > 0 ) {
659 int cnt;
660 int d = (int)count;
661
662 cnt = m->min.bufRemains;
663 if ( cnt > d ) {
664 cnt = d;
665 }
666
667 if ( cnt <= 0 ) {
668 if ( file->f_flags & O_NONBLOCK ) {
669 if (!ret)
670 ret = -EAGAIN;
671 break;
672 }
673 __set_current_state(TASK_INTERRUPTIBLE);
674 schedule();
675 if (signal_pending(current)) {
676 if(!ret)
677 ret=-ERESTARTSYS;
678 break;
679 }
680 continue;
681 }
682
683 {
684 int i;
685 unsigned long flags; /* used to synchronize access to the endpoint */
686 spin_lock_irqsave( &ep->lock, flags );
687 for (i = 0; i < cnt; i++) {
688 if ( copy_to_user( buffer+i, m->min.buf+m->min.bufRdPtr, 1 ) ) {
689 if ( !ret )
690 ret = -EFAULT;
691 break;
692 }
693 m->min.bufRdPtr = (m->min.bufRdPtr+1)%MIDI_IN_BUFSIZ;
694 m->min.bufRemains -= 1;
695 }
696 spin_unlock_irqrestore( &ep->lock, flags );
697 }
698
699 count-=cnt;
700 buffer+=cnt;
701 ret+=cnt;
702
703 break;
704 }
705
706 remove_wait_queue( &ep->wait, &wait );
707 set_current_state(TASK_RUNNING);
708
709 return ret;
710}
711
712
713/** Basic operation on /dev/midiXX as registered through struct file_operations.
714 *
715 * Basic Contract: Take MIDI data byte-by-byte and pass it to
716 * writeMidi() which packages MIDI data into USB-MIDI stream.
717 * Then flushMidiData() is called to ensure all bytes have been written
718 * in a timely fashion.
719 *
720 **/
721
722static ssize_t usb_midi_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
723{
724 struct usb_mididev *m = (struct usb_mididev *)file->private_data;
725 ssize_t ret;
726 unsigned long int flags;
727
728 if ( !access_ok(VERIFY_READ, buffer, count) ) {
729 return -EFAULT;
730 }
731 if ( count == 0 ) {
732 return 0;
733 }
734
735 ret = 0;
736 while( count > 0 ) {
737 unsigned char c;
738
739 if (copy_from_user((unsigned char *)&c, buffer, 1)) {
740 if ( ret == 0 )
741 ret = -EFAULT;
742 break;
743 }
744 if( midi_write(m, (int)c) ) {
745 if ( ret == 0 )
746 ret = -EFAULT;
747 break;
748 }
749 count--;
750 buffer++;
751 ret++;
752 }
753
754 spin_lock_irqsave( &m->mout.ep->lock, flags );
755 if ( flush_midi_buffer(m->mout.ep) < 0 ) {
756 ret = -EFAULT;
757 }
758 spin_unlock_irqrestore( &m->mout.ep->lock, flags );
759
760 return ret;
761}
762
763/** Basic operation on /dev/midiXX as registered through struct file_operations.
764 *
765 * Basic contract: Wait (spin) until ready to read or write on the file.
766 *
767 **/
768static unsigned int usb_midi_poll(struct file *file, struct poll_table_struct *wait)
769{
770 struct usb_mididev *m = (struct usb_mididev *)file->private_data;
771 struct midi_in_endpoint *iep = m->min.ep;
772 struct midi_out_endpoint *oep = m->mout.ep;
773 unsigned long flags;
774 unsigned int mask = 0;
775
776 if ( file->f_mode & FMODE_READ ) {
777 poll_wait( file, &iep->wait, wait );
778 spin_lock_irqsave( &iep->lock, flags );
779 if ( m->min.bufRemains > 0 )
780 mask |= POLLIN | POLLRDNORM;
781 spin_unlock_irqrestore( &iep->lock, flags );
782 }
783
784 if ( file->f_mode & FMODE_WRITE ) {
785 poll_wait( file, &oep->wait, wait );
786 spin_lock_irqsave( &oep->lock, flags );
787 if ( oep->bufWrPtr < oep->bufSize )
788 mask |= POLLOUT | POLLWRNORM;
789 spin_unlock_irqrestore( &oep->lock, flags );
790 }
791
792 return mask;
793}
794
795
796/** Basic operation on /dev/midiXX as registered through struct file_operations.
797 *
798 * Basic contract: This is always the first operation performed on the
799 * device node. If no method is defined, the open succeeds without any
800 * notification given to the module.
801 *
802 **/
803
804static int usb_midi_open(struct inode *inode, struct file *file)
805{
806 int minor = iminor(inode);
807 DECLARE_WAITQUEUE(wait, current);
808 struct usb_midi_state *s;
809 struct usb_mididev *m;
810 unsigned long flags;
811 int succeed = 0;
812
813#if 0
814 printk(KERN_INFO "usb-midi: Open minor= %d.\n", minor);
815#endif
816
817 for(;;) {
818 down(&open_sem);
819 list_for_each_entry(s, &mididevs, mididev) {
820 list_for_each_entry(m, &s->midiDevList, list) {
821 if ( !((m->dev_midi ^ minor) & ~0xf) )
822 goto device_found;
823 }
824 }
825 up(&open_sem);
826 return -ENODEV;
827
828 device_found:
829 if ( !s->usbdev ) {
830 up(&open_sem);
831 return -EIO;
832 }
833 if ( !(m->open_mode & file->f_mode) ) {
834 break;
835 }
836 if ( file->f_flags & O_NONBLOCK ) {
837 up(&open_sem);
838 return -EBUSY;
839 }
840 __set_current_state(TASK_INTERRUPTIBLE);
841 add_wait_queue( &open_wait, &wait );
842 up(&open_sem);
843 schedule();
844 remove_wait_queue( &open_wait, &wait );
845 if ( signal_pending(current) ) {
846 return -ERESTARTSYS;
847 }
848 }
849
850 file->private_data = m;
851 spin_lock_irqsave( &s->lock, flags );
852
853 if ( !(m->open_mode & (FMODE_READ | FMODE_WRITE)) ) {
854 //FIXME: intented semantics unclear here
855 m->min.bufRdPtr = 0;
856 m->min.bufWrPtr = 0;
857 m->min.bufRemains = 0;
858 spin_lock_init(&m->min.ep->lock);
859
860 m->mout.bufPtr = 0;
861 m->mout.bufRemains = 0;
862 m->mout.isInExclusive = 0;
863 m->mout.lastEvent = 0;
864 spin_lock_init(&m->mout.ep->lock);
865 }
866
867 if ( (file->f_mode & FMODE_READ) && m->min.ep != NULL ) {
868 unsigned long int flagsep;
869 spin_lock_irqsave( &m->min.ep->lock, flagsep );
870 m->min.ep->cables[m->min.cableId] = m;
871 m->min.ep->readers += 1;
872 m->min.bufRdPtr = 0;
873 m->min.bufWrPtr = 0;
874 m->min.bufRemains = 0;
875 spin_unlock_irqrestore( &m->min.ep->lock, flagsep );
876
877 if ( !(m->min.ep->urbSubmitted)) {
878
879 /* urb->dev must be reinitialized on 2.4.x kernels */
880 m->min.ep->urb->dev = m->min.ep->usbdev;
881
882 if ( usb_submit_urb(m->min.ep->urb, GFP_ATOMIC) ) {
883 printk(KERN_ERR "usbmidi: Cannot submit urb for MIDI-IN\n");
884 }
885 m->min.ep->urbSubmitted = 1;
886 }
887 m->open_mode |= FMODE_READ;
888 succeed = 1;
889 }
890
891 if ( (file->f_mode & FMODE_WRITE) && m->mout.ep != NULL ) {
892 m->mout.bufPtr = 0;
893 m->mout.bufRemains = 0;
894 m->mout.isInExclusive = 0;
895 m->mout.lastEvent = 0;
896 m->open_mode |= FMODE_WRITE;
897 succeed = 1;
898 }
899
900 spin_unlock_irqrestore( &s->lock, flags );
901
902 s->count++;
903 up(&open_sem);
904
905 /** Changed to prevent extra increments to USE_COUNT. **/
906 if (!succeed) {
907 return -EBUSY;
908 }
909
910#if 0
911 printk(KERN_INFO "usb-midi: Open Succeeded. minor= %d.\n", minor);
912#endif
913
914 return nonseekable_open(inode, file); /** Success. **/
915}
916
917
918/** Basic operation on /dev/midiXX as registered through struct file_operations.
919 *
920 * Basic contract: Close an opened file and deallocate anything we allocated.
921 * Like open(), this can be missing. If open set file->private_data,
922 * release() must clear it.
923 *
924 **/
925
926static int usb_midi_release(struct inode *inode, struct file *file)
927{
928 struct usb_mididev *m = (struct usb_mididev *)file->private_data;
929 struct usb_midi_state *s = (struct usb_midi_state *)m->midi;
930
931#if 0
932 printk(KERN_INFO "usb-midi: Close.\n");
933#endif
934
935 down(&open_sem);
936
937 if ( m->open_mode & FMODE_WRITE ) {
938 m->open_mode &= ~FMODE_WRITE;
939 usb_kill_urb( m->mout.ep->urb );
940 }
941
942 if ( m->open_mode & FMODE_READ ) {
943 unsigned long int flagsep;
944 spin_lock_irqsave( &m->min.ep->lock, flagsep );
945 m->min.ep->cables[m->min.cableId] = NULL; // discard cable
946 m->min.ep->readers -= 1;
947 m->open_mode &= ~FMODE_READ;
948 if ( m->min.ep->readers == 0 &&
949 m->min.ep->urbSubmitted ) {
950 m->min.ep->urbSubmitted = 0;
951 usb_kill_urb(m->min.ep->urb);
952 }
953 spin_unlock_irqrestore( &m->min.ep->lock, flagsep );
954 }
955
956 s->count--;
957
958 up(&open_sem);
959 wake_up(&open_wait);
960
961 file->private_data = NULL;
962 return 0;
963}
964
965static struct file_operations usb_midi_fops = {
966 .owner = THIS_MODULE,
967 .llseek = usb_midi_llseek,
968 .read = usb_midi_read,
969 .write = usb_midi_write,
970 .poll = usb_midi_poll,
971 .open = usb_midi_open,
972 .release = usb_midi_release,
973};
974
975/* ------------------------------------------------------------------------- */
976
977/** Returns filled midi_in_endpoint structure or null on failure.
978 *
979 * Parameters:
980 * d - a usb_device
981 * endPoint - An usb endpoint in the range 0 to 15.
982 * Called by allocUsbMidiDev();
983 *
984 **/
985
986static struct midi_in_endpoint *alloc_midi_in_endpoint( struct usb_device *d, int endPoint )
987{
988 struct midi_in_endpoint *ep;
989 int bufSize;
990 int pipe;
991
992 endPoint &= 0x0f; /* Silently force endPoint to lie in range 0 to 15. */
993
994 pipe = usb_rcvbulkpipe( d, endPoint );
995 bufSize = usb_maxpacket( d, pipe, 0 );
996 /* usb_pipein() = ! usb_pipeout() = true for an in Endpoint */
997
998 ep = (struct midi_in_endpoint *)kmalloc(sizeof(struct midi_in_endpoint), GFP_KERNEL);
999 if ( !ep ) {
1000 printk(KERN_ERR "usbmidi: no memory for midi in-endpoint\n");
1001 return NULL;
1002 }
1003 memset( ep, 0, sizeof(struct midi_in_endpoint) );
1004// this sets cables[] and readers to 0, too.
1005// for (i=0; i<16; i++) ep->cables[i] = 0; // discard cable
1006// ep->readers = 0;
1007
1008 ep->endpoint = endPoint;
1009
1010 ep->recvBuf = (unsigned char *)kmalloc(sizeof(unsigned char)*(bufSize), GFP_KERNEL);
1011 if ( !ep->recvBuf ) {
1012 printk(KERN_ERR "usbmidi: no memory for midi in-endpoint buffer\n");
1013 kfree(ep);
1014 return NULL;
1015 }
1016
1017 ep->urb = usb_alloc_urb(0, GFP_KERNEL); /* no ISO */
1018 if ( !ep->urb ) {
1019 printk(KERN_ERR "usbmidi: no memory for midi in-endpoint urb\n");
1020 kfree(ep->recvBuf);
1021 kfree(ep);
1022 return NULL;
1023 }
1024 usb_fill_bulk_urb( ep->urb, d,
1025 usb_rcvbulkpipe(d, endPoint),
1026 (unsigned char *)ep->recvBuf, bufSize,
1027 usb_bulk_read, ep );
1028
1029 /* ep->bufRdPtr = 0; */
1030 /* ep->bufWrPtr = 0; */
1031 /* ep->bufRemains = 0; */
1032 /* ep->urbSubmitted = 0; */
1033 ep->recvBufSize = bufSize;
1034
1035 init_waitqueue_head(&ep->wait);
1036
1037 return ep;
1038}
1039
1040static int remove_midi_in_endpoint( struct midi_in_endpoint *min )
1041{
1042 usb_kill_urb( min->urb );
1043 usb_free_urb( min->urb );
1044 kfree( min->recvBuf );
1045 kfree( min );
1046
1047 return 0;
1048}
1049
1050/** Returns filled midi_out_endpoint structure or null on failure.
1051 *
1052 * Parameters:
1053 * d - a usb_device
1054 * endPoint - An usb endpoint in the range 0 to 15.
1055 * Called by allocUsbMidiDev();
1056 *
1057 **/
1058static struct midi_out_endpoint *alloc_midi_out_endpoint( struct usb_device *d, int endPoint )
1059{
1060 struct midi_out_endpoint *ep = NULL;
1061 int pipe;
1062 int bufSize;
1063
1064 endPoint &= 0x0f;
1065 pipe = usb_sndbulkpipe( d, endPoint );
1066 bufSize = usb_maxpacket( d, pipe, 1 );
1067
1068 ep = (struct midi_out_endpoint *)kmalloc(sizeof(struct midi_out_endpoint), GFP_KERNEL);
1069 if ( !ep ) {
1070 printk(KERN_ERR "usbmidi: no memory for midi out-endpoint\n");
1071 return NULL;
1072 }
1073 memset( ep, 0, sizeof(struct midi_out_endpoint) );
1074
1075 ep->endpoint = endPoint;
1076 ep->buf = (unsigned char *)kmalloc(sizeof(unsigned char)*bufSize, GFP_KERNEL);
1077 if ( !ep->buf ) {
1078 printk(KERN_ERR "usbmidi: no memory for midi out-endpoint buffer\n");
1079 kfree(ep);
1080 return NULL;
1081 }
1082
1083 ep->urb = usb_alloc_urb(0, GFP_KERNEL); /* no ISO */
1084 if ( !ep->urb ) {
1085 printk(KERN_ERR "usbmidi: no memory for midi out-endpoint urb\n");
1086 kfree(ep->buf);
1087 kfree(ep);
1088 return NULL;
1089 }
1090
1091 ep->bufSize = bufSize;
1092 /* ep->bufWrPtr = 0; */
1093
1094 init_waitqueue_head(&ep->wait);
1095
1096 return ep;
1097}
1098
1099
1100static int remove_midi_out_endpoint( struct midi_out_endpoint *mout )
1101{
1102 usb_kill_urb( mout->urb );
1103 usb_free_urb( mout->urb );
1104 kfree( mout->buf );
1105 kfree( mout );
1106
1107 return 0;
1108}
1109
1110
1111/** Returns a filled usb_mididev structure, registered as a Linux MIDI device.
1112 *
1113 * Returns null if memory is not available or the device cannot be registered.
1114 * Called by allocUsbMidiDev();
1115 *
1116 **/
1117static struct usb_mididev *allocMidiDev(
1118 struct usb_midi_state *s,
1119 struct midi_in_endpoint *min,
1120 struct midi_out_endpoint *mout,
1121 int inCableId,
1122 int outCableId )
1123{
1124 struct usb_mididev *m;
1125
1126 m = (struct usb_mididev *)kmalloc(sizeof(struct usb_mididev), GFP_KERNEL);
1127 if (!m) {
1128 printk(KERN_ERR "usbmidi: no memory for midi device\n");
1129 return NULL;
1130 }
1131
1132 memset(m, 0, sizeof(struct usb_mididev));
1133
1134 if ((m->dev_midi = register_sound_midi(&usb_midi_fops, -1)) < 0) {
1135 printk(KERN_ERR "usbmidi: cannot register midi device\n");
1136 kfree(m);
1137 return NULL;
1138 }
1139
1140 m->midi = s;
1141 /* m->open_mode = 0; */
1142
1143 if ( min ) {
1144 m->min.ep = min;
1145 m->min.ep->usbdev = s->usbdev;
1146 m->min.cableId = inCableId;
1147 }
1148 /* m->min.bufPtr = 0; */
1149 /* m->min.bufRemains = 0; */
1150
1151 if ( mout ) {
1152 m->mout.ep = mout;
1153 m->mout.ep->usbdev = s->usbdev;
1154 m->mout.cableId = outCableId;
1155 }
1156 /* m->mout.bufPtr = 0; */
1157 /* m->mout.bufRemains = 0; */
1158 /* m->mout.isInExclusive = 0; */
1159 /* m->mout.lastEvent = 0; */
1160
1161 m->singlebyte = singlebyte;
1162
1163 return m;
1164}
1165
1166
1167static void release_midi_device( struct usb_midi_state *s )
1168{
1169 struct usb_mididev *m;
1170 struct midi_in_endpoint *min;
1171 struct midi_out_endpoint *mout;
1172
1173 if ( s->count > 0 ) {
1174 up(&open_sem);
1175 return;
1176 }
1177 up( &open_sem );
1178 wake_up( &open_wait );
1179
1180 while(!list_empty(&s->inEndpointList)) {
1181 min = list_entry(s->inEndpointList.next, struct midi_in_endpoint, list);
1182 list_del(&min->list);
1183 remove_midi_in_endpoint(min);
1184 }
1185
1186 while(!list_empty(&s->outEndpointList)) {
1187 mout = list_entry(s->outEndpointList.next, struct midi_out_endpoint, list);
1188 list_del(&mout->list);
1189 remove_midi_out_endpoint(mout);
1190 }
1191
1192 while(!list_empty(&s->midiDevList)) {
1193 m = list_entry(s->midiDevList.next, struct usb_mididev, list);
1194 list_del(&m->list);
1195 kfree(m);
1196 }
1197
1198 kfree(s);
1199
1200 return;
1201}
1202
1203
1204/* ------------------------------------------------------------------------- */
1205
1206/** Utility routine to find a descriptor in a dump of many descriptors.
1207 * Returns start of descriptor or NULL if not found.
1208 * descStart pointer to list of interfaces.
1209 * descLength length (in bytes) of dump
1210 * after (ignored if NULL) this routine returns only descriptors after "after"
1211 * dtype (mandatory) The descriptor type.
1212 * iface (ignored if -1) returns descriptor at/following given interface
1213 * altSetting (ignored if -1) returns descriptor at/following given altSetting
1214 *
1215 *
1216 * Called by parseDescriptor(), find_csinterface_descriptor();
1217 *
1218 */
1219static void *find_descriptor( void *descStart, unsigned int descLength, void *after, unsigned char dtype, int iface, int altSetting )
1220{
1221 unsigned char *p, *end, *next;
1222 int interfaceNumber = -1, altSet = -1;
1223
1224 p = descStart;
1225 end = p + descLength;
1226 for( ; p < end; ) {
1227 if ( p[0] < 2 )
1228 return NULL;
1229 next = p + p[0];
1230 if ( next > end )
1231 return NULL;
1232 if ( p[1] == USB_DT_INTERFACE ) {
1233 if ( p[0] < USB_DT_INTERFACE_SIZE )
1234 return NULL;
1235 interfaceNumber = p[2];
1236 altSet = p[3];
1237 }
1238 if ( p[1] == dtype &&
1239 ( !after || ( p > (unsigned char *)after) ) &&
1240 ( ( iface == -1) || (iface == interfaceNumber) ) &&
1241 ( (altSetting == -1) || (altSetting == altSet) )) {
1242 return p;
1243 }
1244 p = next;
1245 }
1246 return NULL;
1247}
1248
1249/** Utility to find a class-specific interface descriptor.
1250 * dsubtype is a descriptor subtype
1251 * Called by parseDescriptor();
1252 **/
1253static void *find_csinterface_descriptor(void *descStart, unsigned int descLength, void *after, u8 dsubtype, int iface, int altSetting)
1254{
1255 unsigned char *p;
1256
1257 p = find_descriptor( descStart, descLength, after, USB_DT_CS_INTERFACE, iface, altSetting );
1258 while ( p ) {
1259 if ( p[0] >= 3 && p[2] == dsubtype )
1260 return p;
1261 p = find_descriptor( descStart, descLength, p, USB_DT_CS_INTERFACE,
1262 iface, altSetting );
1263 }
1264 return NULL;
1265}
1266
1267
1268/** The magic of making a new usb_midi_device from config happens here.
1269 *
1270 * The caller is responsible for free-ing this return value (if not NULL).
1271 *
1272 **/
1273static struct usb_midi_device *parse_descriptor( struct usb_device *d, unsigned char *buffer, int bufSize, unsigned int ifnum , unsigned int altSetting, int quirks)
1274{
1275 struct usb_midi_device *u;
1276 unsigned char *p1;
1277 unsigned char *p2;
1278 unsigned char *next;
1279 int iep, oep;
1280 int length;
1281 unsigned long longBits;
1282 int pins, nbytes, offset, shift, jack;
1283#ifdef HAVE_JACK_STRINGS
1284 /** Jacks can have associated names. **/
1285 unsigned char jack2string[256];
1286#endif
1287
1288 u = NULL;
1289 /* find audiocontrol interface */
1290 p1 = find_csinterface_descriptor( buffer, bufSize, NULL,
1291 MS_HEADER, ifnum, altSetting);
1292
1293 if ( !p1 ) {
1294 goto error_end;
1295 }
1296
1297 if ( p1[0] < MS_HEADER_LENGTH ) {
1298 goto error_end;
1299 }
1300
1301 /* Assume success. Since the device corresponds to USB-MIDI spec, we assume
1302 that the rest of the USB 2.0 spec is obeyed. */
1303
1304 u = (struct usb_midi_device *)kmalloc( sizeof(struct usb_midi_device), GFP_KERNEL );
1305 if ( !u ) {
1306 return NULL;
1307 }
1308 u->deviceName = NULL;
1309 u->idVendor = le16_to_cpu(d->descriptor.idVendor);
1310 u->idProduct = le16_to_cpu(d->descriptor.idProduct);
1311 u->interface = ifnum;
1312 u->altSetting = altSetting;
1313 u->in[0].endpoint = -1;
1314 u->in[0].cableId = -1;
1315 u->out[0].endpoint = -1;
1316 u->out[0].cableId = -1;
1317
1318
1319 printk(KERN_INFO "usb-midi: Found MIDIStreaming device corresponding to Release %d.%02d of spec.\n",
1320 (p1[4] >> 4) * 10 + (p1[4] & 0x0f ),
1321 (p1[3] >> 4) * 10 + (p1[3] & 0x0f )
1322 );
1323
1324 length = p1[5] | (p1[6] << 8);
1325
1326#ifdef HAVE_JACK_STRINGS
1327 memset(jack2string, 0, sizeof(unsigned char) * 256);
1328#endif
1329
1330 length -= p1[0];
1331 for (p2 = p1 + p1[0]; length > 0; p2 = next) {
1332 next = p2 + p2[0];
1333 length -= p2[0];
1334
1335 if (p2[0] < 2 )
1336 break;
1337 if (p2[1] != USB_DT_CS_INTERFACE)
1338 break;
1339 if (p2[2] == MIDI_IN_JACK && p2[0] >= 6 ) {
1340 jack = p2[4];
1341#ifdef HAVE_JACK_STRINGS
1342 jack2string[jack] = p2[5];
1343#endif
1344 printk(KERN_INFO "usb-midi: Found IN Jack 0x%02x %s\n",
1345 jack, (p2[3] == EMBEDDED_JACK)?"EMBEDDED":"EXTERNAL" );
1346 } else if ( p2[2] == MIDI_OUT_JACK && p2[0] >= 6) {
1347 pins = p2[5];
1348 if ( p2[0] < (6 + 2 * pins) )
1349 continue;
1350 jack = p2[4];
1351#ifdef HAVE_JACK_STRINGS
1352 jack2string[jack] = p2[5 + 2 * pins];
1353#endif
1354 printk(KERN_INFO "usb-midi: Found OUT Jack 0x%02x %s, %d pins\n",
1355 jack, (p2[3] == EMBEDDED_JACK)?"EMBEDDED":"EXTERNAL", pins );
1356 } else if ( p2[2] == ELEMENT_DESCRIPTOR && p2[0] >= 10) {
1357 pins = p2[4];
1358 if ( p2[0] < (9 + 2 * pins ) )
1359 continue;
1360 nbytes = p2[8 + 2 * pins ];
1361 if ( p2[0] < (10 + 2 * pins + nbytes) )
1362 continue;
1363 longBits = 0L;
1364 for ( offset = 0, shift = 0; offset < nbytes && offset < 8; offset ++, shift += 8) {
1365 longBits |= ((long)(p2[9 + 2 * pins + offset])) << shift;
1366 }
1367 jack = p2[3];
1368#ifdef HAVE_JACK_STRINGS
1369 jack2string[jack] = p2[9 + 2 * pins + nbytes];
1370#endif
1371 printk(KERN_INFO "usb-midi: Found ELEMENT 0x%02x, %d/%d pins in/out, bits: 0x%016lx\n",
1372 jack, pins, (int)(p2[5 + 2 * pins]), (long)longBits );
1373 } else {
1374 }
1375 }
1376
1377 iep=0;
1378 oep=0;
1379
1380 if (quirks==0) {
1381 /* MIDISTREAM */
1382 p2 = NULL;
1383 for (p1 = find_descriptor(buffer, bufSize, NULL, USB_DT_ENDPOINT,
1384 ifnum, altSetting ); p1; p1 = next ) {
1385 next = find_descriptor(buffer, bufSize, p1, USB_DT_ENDPOINT,
1386 ifnum, altSetting );
1387 p2 = find_descriptor(buffer, bufSize, p1, USB_DT_CS_ENDPOINT,
1388 ifnum, altSetting );
1389
1390 if ( p2 && next && ( p2 > next ) )
1391 p2 = NULL;
1392
1393 if ( p1[0] < 9 || !p2 || p2[0] < 4 )
1394 continue;
1395
1396 if ( (p1[2] & 0x80) == 0x80 ) {
1397 if ( iep < 15 ) {
1398 pins = p2[3]; /* not pins -- actually "cables" */
1399 if ( pins > 16 )
1400 pins = 16;
1401 u->in[iep].endpoint = p1[2];
1402 u->in[iep].cableId = ( 1 << pins ) - 1;
1403 if ( u->in[iep].cableId )
1404 iep ++;
1405 if ( iep < 15 ) {
1406 u->in[iep].endpoint = -1;
1407 u->in[iep].cableId = -1;
1408 }
1409 }
1410 } else {
1411 if ( oep < 15 ) {
1412 pins = p2[3]; /* not pins -- actually "cables" */
1413 if ( pins > 16 )
1414 pins = 16;
1415 u->out[oep].endpoint = p1[2];
1416 u->out[oep].cableId = ( 1 << pins ) - 1;
1417 if ( u->out[oep].cableId )
1418 oep ++;
1419 if ( oep < 15 ) {
1420 u->out[oep].endpoint = -1;
1421 u->out[oep].cableId = -1;
1422 }
1423 }
1424 }
1425
1426 }
1427 } else if (quirks==1) {
1428 /* YAMAHA quirks */
1429 for (p1 = find_descriptor(buffer, bufSize, NULL, USB_DT_ENDPOINT,
1430 ifnum, altSetting ); p1; p1 = next ) {
1431 next = find_descriptor(buffer, bufSize, p1, USB_DT_ENDPOINT,
1432 ifnum, altSetting );
1433
1434 if ( p1[0] < 7 )
1435 continue;
1436
1437 if ( (p1[2] & 0x80) == 0x80 ) {
1438 if ( iep < 15 ) {
1439 pins = iep+1;
1440 if ( pins > 16 )
1441 pins = 16;
1442 u->in[iep].endpoint = p1[2];
1443 u->in[iep].cableId = ( 1 << pins ) - 1;
1444 if ( u->in[iep].cableId )
1445 iep ++;
1446 if ( iep < 15 ) {
1447 u->in[iep].endpoint = -1;
1448 u->in[iep].cableId = -1;
1449 }
1450 }
1451 } else {
1452 if ( oep < 15 ) {
1453 pins = oep+1;
1454 u->out[oep].endpoint = p1[2];
1455 u->out[oep].cableId = ( 1 << pins ) - 1;
1456 if ( u->out[oep].cableId )
1457 oep ++;
1458 if ( oep < 15 ) {
1459 u->out[oep].endpoint = -1;
1460 u->out[oep].cableId = -1;
1461 }
1462 }
1463 }
1464
1465 }
1466 }
1467
1468 if ( !iep && ! oep ) {
1469 goto error_end;
1470 }
1471
1472 return u;
1473
1474error_end:
1475 kfree(u);
1476 return NULL;
1477}
1478
1479/* ------------------------------------------------------------------------- */
1480
1481/** Returns number between 0 and 16.
1482 *
1483 **/
1484static int on_bits( unsigned short v )
1485{
1486 int i;
1487 int ret=0;
1488
1489 for ( i=0 ; i<16 ; i++ ) {
1490 if ( v & (1<<i) )
1491 ret++;
1492 }
1493
1494 return ret;
1495}
1496
1497
1498/** USB-device will be interrogated for altSetting.
1499 *
1500 * Returns negative on error.
1501 * Called by allocUsbMidiDev();
1502 *
1503 **/
1504
1505static int get_alt_setting( struct usb_device *d, int ifnum )
1506{
1507 int alts, alt=0;
1508 struct usb_interface *iface;
1509 struct usb_host_interface *interface;
1510 struct usb_endpoint_descriptor *ep;
1511 int epin, epout;
1512 int i;
1513
1514 iface = usb_ifnum_to_if( d, ifnum );
1515 alts = iface->num_altsetting;
1516
1517 for ( alt=0 ; alt<alts ; alt++ ) {
1518 interface = &iface->altsetting[alt];
1519 epin = -1;
1520 epout = -1;
1521
1522 for ( i=0 ; i<interface->desc.bNumEndpoints ; i++ ) {
1523 ep = &interface->endpoint[i].desc;
1524 if ( (ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_BULK ) {
1525 continue;
1526 }
1527 if ( (ep->bEndpointAddress & USB_DIR_IN) && epin < 0 ) {
1528 epin = i;
1529 } else if ( epout < 0 ) {
1530 epout = i;
1531 }
1532 if ( epin >= 0 && epout >= 0 ) {
1533 return interface->desc.bAlternateSetting;
1534 }
1535 }
1536 }
1537
1538 return -ENODEV;
1539}
1540
1541
1542/* ------------------------------------------------------------------------- */
1543
1544
1545/** Returns 0 if successful in allocating and registering internal structures.
1546 * Returns negative on failure.
1547 * Calls allocMidiDev which additionally registers /dev/midiXX devices.
1548 * Writes messages on success to indicate which /dev/midiXX is which physical
1549 * endpoint.
1550 *
1551 **/
1552static int alloc_usb_midi_device( struct usb_device *d, struct usb_midi_state *s, struct usb_midi_device *u )
1553{
1554 struct usb_mididev **mdevs=NULL;
1555 struct midi_in_endpoint *mins[15], *min;
1556 struct midi_out_endpoint *mouts[15], *mout;
1557 int inDevs=0, outDevs=0;
1558 int inEndpoints=0, outEndpoints=0;
1559 int inEndpoint, outEndpoint;
1560 int inCableId, outCableId;
1561 int i;
1562 int devices = 0;
1563 int alt = 0;
1564
1565 /* Obtain altSetting or die.. */
1566 alt = u->altSetting;
1567 if ( alt < 0 ) {
1568 alt = get_alt_setting( d, u->interface );
1569 }
1570 if ( alt < 0 )
1571 return -ENXIO;
1572
1573 /* Configure interface */
1574 if ( usb_set_interface( d, u->interface, alt ) < 0 ) {
1575 return -ENXIO;
1576 }
1577
1578 for ( i = 0 ; i < 15 ; i++ ) {
1579 mins[i] = NULL;
1580 mouts[i] = NULL;
1581 }
1582
1583 /* Begin Allocation */
1584 while( inEndpoints < 15
1585 && inDevs < maxdevices
1586 && u->in[inEndpoints].cableId >= 0 ) {
1587 inDevs += on_bits((unsigned short)u->in[inEndpoints].cableId);
1588 mins[inEndpoints] = alloc_midi_in_endpoint( d, u->in[inEndpoints].endpoint );
1589 if ( mins[inEndpoints] == NULL )
1590 goto error_end;
1591 inEndpoints++;
1592 }
1593
1594 while( outEndpoints < 15
1595 && outDevs < maxdevices
1596 && u->out[outEndpoints].cableId >= 0 ) {
1597 outDevs += on_bits((unsigned short)u->out[outEndpoints].cableId);
1598 mouts[outEndpoints] = alloc_midi_out_endpoint( d, u->out[outEndpoints].endpoint );
1599 if ( mouts[outEndpoints] == NULL )
1600 goto error_end;
1601 outEndpoints++;
1602 }
1603
1604 devices = inDevs > outDevs ? inDevs : outDevs;
1605 devices = maxdevices > devices ? devices : maxdevices;
1606
1607 /* obtain space for device name (iProduct) if not known. */
1608 if ( ! u->deviceName ) {
1609 mdevs = (struct usb_mididev **)
1610 kmalloc(sizeof(struct usb_mididevs *)*devices
1611 + sizeof(char) * 256, GFP_KERNEL);
1612 } else {
1613 mdevs = (struct usb_mididev **)
1614 kmalloc(sizeof(struct usb_mididevs *)*devices, GFP_KERNEL);
1615 }
1616
1617 if ( !mdevs ) {
1618 /* devices = 0; */
1619 /* mdevs = NULL; */
1620 goto error_end;
1621 }
1622 for ( i=0 ; i<devices ; i++ ) {
1623 mdevs[i] = NULL;
1624 }
1625
1626 /* obtain device name (iProduct) if not known. */
1627 if ( ! u->deviceName ) {
1628 u->deviceName = (char *) (mdevs + devices);
1629 if ( ! d->have_langid && d->descriptor.iProduct) {
1630 alt = usb_get_string(d, 0, 0, u->deviceName, 250);
1631 if (alt < 0) {
1632 printk(KERN_INFO "error getting string descriptor 0 (error=%d)\n", alt);
1633 } else if (u->deviceName[0] < 4) {
1634 printk(KERN_INFO "string descriptor 0 too short (length = %d)\n", alt);
1635 } else {
1636 printk(KERN_INFO "string descriptor 0 found (length = %d)\n", alt);
1637 for(; alt >= 4; alt -= 2) {
1638 i = u->deviceName[alt-2] | (u->deviceName[alt-1]<< 8);
1639 printk(KERN_INFO "usb-midi: langid(%d) 0x%04x\n",
1640 (alt-4) >> 1, i);
1641 if ( ( ( i ^ ulangid ) & 0xff ) == 0 ) {
1642 d->have_langid = 1;
1643 d->string_langid = i;
1644 printk(KERN_INFO "usb-midi: langid(match) 0x%04x\n", i);
1645 if ( i == ulangid )
1646 break;
1647 }
1648 }
1649 }
1650 }
1651 u->deviceName[0] = (char) 0;
1652 if (d->descriptor.iProduct) {
1653 printk(KERN_INFO "usb-midi: fetchString(%d)\n", d->descriptor.iProduct);
1654 alt = usb_string(d, d->descriptor.iProduct, u->deviceName, 255);
1655 if( alt < 0 ) {
1656 u->deviceName[0] = (char) 0;
1657 }
1658 printk(KERN_INFO "usb-midi: fetchString = %d\n", alt);
1659 }
1660 /* Failsafe */
1661 if ( !u->deviceName[0] ) {
1662 if (le16_to_cpu(d->descriptor.idVendor) == USB_VENDOR_ID_ROLAND ) {
1663 strcpy(u->deviceName, "Unknown Roland");
1664 } else if (le16_to_cpu(d->descriptor.idVendor) == USB_VENDOR_ID_STEINBERG ) {
1665 strcpy(u->deviceName, "Unknown Steinberg");
1666 } else if (le16_to_cpu(d->descriptor.idVendor) == USB_VENDOR_ID_YAMAHA ) {
1667 strcpy(u->deviceName, "Unknown Yamaha");
1668 } else {
1669 strcpy(u->deviceName, "Unknown");
1670 }
1671 }
1672 }
1673
1674 inEndpoint = 0; inCableId = -1;
1675 outEndpoint = 0; outCableId = -1;
1676
1677 for ( i=0 ; i<devices ; i++ ) {
1678 for ( inCableId ++ ;
1679 inEndpoint <15
1680 && mins[inEndpoint]
1681 && !(u->in[inEndpoint].cableId & (1<<inCableId)) ;
1682 inCableId++ ) {
1683 if ( inCableId >= 16 ) {
1684 inEndpoint ++;
1685 inCableId = 0;
1686 }
1687 }
1688 min = mins[inEndpoint];
1689 for ( outCableId ++ ;
1690 outEndpoint <15
1691 && mouts[outEndpoint]
1692 && !(u->out[outEndpoint].cableId & (1<<outCableId)) ;
1693 outCableId++ ) {
1694 if ( outCableId >= 16 ) {
1695 outEndpoint ++;
1696 outCableId = 0;
1697 }
1698 }
1699 mout = mouts[outEndpoint];
1700
1701 mdevs[i] = allocMidiDev( s, min, mout, inCableId, outCableId );
1702 if ( mdevs[i] == NULL )
1703 goto error_end;
1704
1705 }
1706
1707 /* Success! */
1708 for ( i=0 ; i<devices ; i++ ) {
1709 list_add_tail( &mdevs[i]->list, &s->midiDevList );
1710 }
1711 for ( i=0 ; i<inEndpoints ; i++ ) {
1712 list_add_tail( &mins[i]->list, &s->inEndpointList );
1713 }
1714 for ( i=0 ; i<outEndpoints ; i++ ) {
1715 list_add_tail( &mouts[i]->list, &s->outEndpointList );
1716 }
1717
1718 printk(KERN_INFO "usbmidi: found [ %s ] (0x%04x:0x%04x), attached:\n", u->deviceName, u->idVendor, u->idProduct );
1719 for ( i=0 ; i<devices ; i++ ) {
1720 int dm = (mdevs[i]->dev_midi-2)>>4;
1721 if ( mdevs[i]->mout.ep != NULL && mdevs[i]->min.ep != NULL ) {
1722 printk(KERN_INFO "usbmidi: /dev/midi%02d: in (ep:%02x cid:%2d bufsiz:%2d) out (ep:%02x cid:%2d bufsiz:%2d)\n",
1723 dm,
1724 mdevs[i]->min.ep->endpoint|USB_DIR_IN, mdevs[i]->min.cableId, mdevs[i]->min.ep->recvBufSize,
1725 mdevs[i]->mout.ep->endpoint, mdevs[i]->mout.cableId, mdevs[i]->mout.ep->bufSize);
1726 } else if ( mdevs[i]->min.ep != NULL ) {
1727 printk(KERN_INFO "usbmidi: /dev/midi%02d: in (ep:%02x cid:%2d bufsiz:%02d)\n",
1728 dm,
1729 mdevs[i]->min.ep->endpoint|USB_DIR_IN, mdevs[i]->min.cableId, mdevs[i]->min.ep->recvBufSize);
1730 } else if ( mdevs[i]->mout.ep != NULL ) {
1731 printk(KERN_INFO "usbmidi: /dev/midi%02d: out (ep:%02x cid:%2d bufsiz:%02d)\n",
1732 dm,
1733 mdevs[i]->mout.ep->endpoint, mdevs[i]->mout.cableId, mdevs[i]->mout.ep->bufSize);
1734 }
1735 }
1736
1737 kfree(mdevs);
1738 return 0;
1739
1740 error_end:
1741 if ( mdevs != NULL ) {
1742 for ( i=0 ; i<devices ; i++ ) {
1743 if ( mdevs[i] != NULL ) {
1744 unregister_sound_midi( mdevs[i]->dev_midi );
1745 kfree(mdevs[i]);
1746 }
1747 }
1748 kfree(mdevs);
1749 }
1750
1751 for ( i=0 ; i<15 ; i++ ) {
1752 if ( mins[i] != NULL ) {
1753 remove_midi_in_endpoint( mins[i] );
1754 }
1755 if ( mouts[i] != NULL ) {
1756 remove_midi_out_endpoint( mouts[i] );
1757 }
1758 }
1759
1760 return -ENOMEM;
1761}
1762
1763/* ------------------------------------------------------------------------- */
1764
1765/** Attempt to scan YAMAHA's device descriptor and detect correct values of
1766 * them.
1767 * Return 0 on succes, negative on failure.
1768 * Called by usb_midi_probe();
1769 **/
1770
1771static int detect_yamaha_device( struct usb_device *d,
1772 struct usb_interface *iface, unsigned int ifnum,
1773 struct usb_midi_state *s)
1774{
1775 struct usb_host_interface *interface;
1776 struct usb_midi_device *u;
1777 unsigned char *buffer;
1778 int bufSize;
1779 int i;
1780 int alts=-1;
1781 int ret;
1782
1783 if (le16_to_cpu(d->descriptor.idVendor) != USB_VENDOR_ID_YAMAHA) {
1784 return -EINVAL;
1785 }
1786
1787 for ( i=0 ; i < iface->num_altsetting; i++ ) {
1788 interface = iface->altsetting + i;
1789
1790 if ( interface->desc.bInterfaceClass != 255 ||
1791 interface->desc.bInterfaceSubClass != 0 )
1792 continue;
1793 alts = interface->desc.bAlternateSetting;
1794 }
1795 if ( alts == -1 ) {
1796 return -EINVAL;
1797 }
1798
1799 printk(KERN_INFO "usb-midi: Found YAMAHA USB-MIDI device on dev %04x:%04x, iface %d\n",
1800 le16_to_cpu(d->descriptor.idVendor),
1801 le16_to_cpu(d->descriptor.idProduct), ifnum);
1802
1803 i = d->actconfig - d->config;
1804 buffer = d->rawdescriptors[i];
1805 bufSize = le16_to_cpu(d->actconfig->desc.wTotalLength);
1806
1807 u = parse_descriptor( d, buffer, bufSize, ifnum, alts, 1);
1808 if ( u == NULL ) {
1809 return -EINVAL;
1810 }
1811
1812 ret = alloc_usb_midi_device( d, s, u );
1813
1814 kfree(u);
1815
1816 return ret;
1817}
1818
1819
1820/** Scan table of known devices which are only partially compliant with
1821 * the MIDIStreaming specification.
1822 * Called by usb_midi_probe();
1823 *
1824 **/
1825
1826static int detect_vendor_specific_device( struct usb_device *d, unsigned int ifnum, struct usb_midi_state *s )
1827{
1828 struct usb_midi_device *u;
1829 int i;
1830 int ret = -ENXIO;
1831
1832 for ( i=0; i<VENDOR_SPECIFIC_USB_MIDI_DEVICES ; i++ ) {
1833 u=&(usb_midi_devices[i]);
1834
1835 if ( le16_to_cpu(d->descriptor.idVendor) != u->idVendor ||
1836 le16_to_cpu(d->descriptor.idProduct) != u->idProduct ||
1837 ifnum != u->interface )
1838 continue;
1839
1840 ret = alloc_usb_midi_device( d, s, u );
1841 break;
1842 }
1843
1844 return ret;
1845}
1846
1847
1848/** Attempt to match any config of an interface to a MIDISTREAMING interface.
1849 * Returns 0 on success, negative on failure.
1850 * Called by usb_midi_probe();
1851 **/
1852static int detect_midi_subclass(struct usb_device *d,
1853 struct usb_interface *iface, unsigned int ifnum,
1854 struct usb_midi_state *s)
1855{
1856 struct usb_host_interface *interface;
1857 struct usb_midi_device *u;
1858 unsigned char *buffer;
1859 int bufSize;
1860 int i;
1861 int alts=-1;
1862 int ret;
1863
1864 for ( i=0 ; i < iface->num_altsetting; i++ ) {
1865 interface = iface->altsetting + i;
1866
1867 if ( interface->desc.bInterfaceClass != USB_CLASS_AUDIO ||
1868 interface->desc.bInterfaceSubClass != USB_SUBCLASS_MIDISTREAMING )
1869 continue;
1870 alts = interface->desc.bAlternateSetting;
1871 }
1872 if ( alts == -1 ) {
1873 return -EINVAL;
1874 }
1875
1876 printk(KERN_INFO "usb-midi: Found MIDISTREAMING on dev %04x:%04x, iface %d\n",
1877 le16_to_cpu(d->descriptor.idVendor),
1878 le16_to_cpu(d->descriptor.idProduct), ifnum);
1879
1880
1881 /* From USB Spec v2.0, Section 9.5.
1882 If the class or vendor specific descriptors use the same format
1883 as standard descriptors (e.g., start with a length byte and
1884 followed by a type byte), they must be returned interleaved with
1885 standard descriptors in the configuration information returned by
1886 a GetDescriptor(Configuration) request. In this case, the class
1887 or vendor-specific descriptors must follow a related standard
1888 descriptor they modify or extend.
1889 */
1890
1891 i = d->actconfig - d->config;
1892 buffer = d->rawdescriptors[i];
1893 bufSize = le16_to_cpu(d->actconfig->desc.wTotalLength);
1894
1895 u = parse_descriptor( d, buffer, bufSize, ifnum, alts, 0);
1896 if ( u == NULL ) {
1897 return -EINVAL;
1898 }
1899
1900 ret = alloc_usb_midi_device( d, s, u );
1901
1902 kfree(u);
1903
1904 return ret;
1905}
1906
1907
1908/** When user has requested a specific device, match it exactly.
1909 *
1910 * Uses uvendor, uproduct, uinterface, ualt, umin, umout and ucable.
1911 * Called by usb_midi_probe();
1912 *
1913 **/
1914static int detect_by_hand(struct usb_device *d, unsigned int ifnum, struct usb_midi_state *s)
1915{
1916 struct usb_midi_device u;
1917
1918 if ( le16_to_cpu(d->descriptor.idVendor) != uvendor ||
1919 le16_to_cpu(d->descriptor.idProduct) != uproduct ||
1920 ifnum != uinterface ) {
1921 return -EINVAL;
1922 }
1923
1924 if ( ualt < 0 )
1925 ualt = -1;
1926
1927 if ( umin < 0 || umin > 15 )
1928 umin = 0x01 | USB_DIR_IN;
1929 if ( umout < 0 || umout > 15 )
1930 umout = 0x01;
1931 if ( ucable < 0 || ucable > 15 )
1932 ucable = 0;
1933
1934 u.deviceName = NULL; /* A flag for alloc_usb_midi_device to get device
1935 name from device. */
1936 u.idVendor = uvendor;
1937 u.idProduct = uproduct;
1938 u.interface = uinterface;
1939 u.altSetting = ualt;
1940
1941 u.in[0].endpoint = umin;
1942 u.in[0].cableId = (1<<ucable);
1943
1944 u.out[0].endpoint = umout;
1945 u.out[0].cableId = (1<<ucable);
1946
1947 return alloc_usb_midi_device( d, s, &u );
1948}
1949
1950
1951
1952/* ------------------------------------------------------------------------- */
1953
1954static int usb_midi_probe(struct usb_interface *intf,
1955 const struct usb_device_id *id)
1956{
1957 struct usb_midi_state *s;
1958 struct usb_device *dev = interface_to_usbdev(intf);
1959 int ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
1960
1961 s = (struct usb_midi_state *)kmalloc(sizeof(struct usb_midi_state), GFP_KERNEL);
1962 if ( !s )
1963 return -ENOMEM;
1964
1965 memset( s, 0, sizeof(struct usb_midi_state) );
1966 INIT_LIST_HEAD(&s->midiDevList);
1967 INIT_LIST_HEAD(&s->inEndpointList);
1968 INIT_LIST_HEAD(&s->outEndpointList);
1969 s->usbdev = dev;
1970 s->count = 0;
1971 spin_lock_init(&s->lock);
1972
1973 if (
1974 detect_by_hand( dev, ifnum, s ) &&
1975 detect_midi_subclass( dev, intf, ifnum, s ) &&
1976 detect_vendor_specific_device( dev, ifnum, s ) &&
1977 detect_yamaha_device( dev, intf, ifnum, s) ) {
1978 kfree(s);
1979 return -EIO;
1980 }
1981
1982 down(&open_sem);
1983 list_add_tail(&s->mididev, &mididevs);
1984 up(&open_sem);
1985
1986 usb_set_intfdata (intf, s);
1987 return 0;
1988}
1989
1990
1991static void usb_midi_disconnect(struct usb_interface *intf)
1992{
1993 struct usb_midi_state *s = usb_get_intfdata (intf);
1994 struct usb_mididev *m;
1995
1996 if ( !s )
1997 return;
1998
1999 if ( s == (struct usb_midi_state *)-1 ) {
2000 return;
2001 }
2002 if ( !s->usbdev ) {
2003 return;
2004 }
2005 down(&open_sem);
2006 list_del(&s->mididev);
2007 INIT_LIST_HEAD(&s->mididev);
2008 s->usbdev = NULL;
2009 usb_set_intfdata (intf, NULL);
2010
2011 list_for_each_entry(m, &s->midiDevList, list) {
2012 wake_up(&(m->min.ep->wait));
2013 wake_up(&(m->mout.ep->wait));
2014 if ( m->dev_midi >= 0 ) {
2015 unregister_sound_midi(m->dev_midi);
2016 }
2017 m->dev_midi = -1;
2018 }
2019 release_midi_device(s);
2020 wake_up(&open_wait);
2021}
2022
2023/* we want to look at all devices by hand */
2024static struct usb_device_id id_table[] = {
2025 {.driver_info = 42},
2026 {}
2027};
2028
2029static struct usb_driver usb_midi_driver = {
2030 .name = "midi",
2031 .probe = usb_midi_probe,
2032 .disconnect = usb_midi_disconnect,
2033 .id_table = id_table,
2034};
2035
2036/* ------------------------------------------------------------------------- */
2037
2038static int __init usb_midi_init(void)
2039{
2040 return usb_register(&usb_midi_driver);
2041}
2042
2043static void __exit usb_midi_exit(void)
2044{
2045 usb_deregister(&usb_midi_driver);
2046}
2047
2048module_init(usb_midi_init) ;
2049module_exit(usb_midi_exit) ;
2050
2051#ifdef HAVE_ALSA_SUPPORT
2052#define SNDRV_MAIN_OBJECT_FILE
2053#include "../../include/driver.h"
2054#include "../../include/control.h"
2055#include "../../include/info.h"
2056#include "../../include/cs46xx.h"
2057
2058/* ------------------------------------------------------------------------- */
2059
2060static int snd_usbmidi_input_close(snd_rawmidi_substream_t * substream)
2061{
2062 return 0;
2063}
2064
2065static int snd_usbmidi_input_open(snd_rawmidi_substream_t * substream )
2066{
2067 return 0;
2068}
2069
2070static void snd_usbmidi_input_trigger(snd_rawmidi_substream_t * substream, int up)
2071{
2072 return 0;
2073}
2074
2075
2076/* ------------------------------------------------------------------------- */
2077
2078static int snd_usbmidi_output_close(snd_rawmidi_substream_t * substream)
2079{
2080 return 0;
2081}
2082
2083static int snd_usbmidi_output_open(snd_rawmidi_substream_t * substream)
2084{
2085 return 0;
2086}
2087
2088static void snd_usb_midi_output_trigger(snd_rawmidi_substream_t * substream,
2089 int up)
2090{
2091 return 0;
2092}
2093
2094/* ------------------------------------------------------------------------- */
2095
2096static snd_rawmidi_ops_t snd_usbmidi_output =
2097{
2098 .open = snd_usbmidi_output_open,
2099 .close = snd_usbmidi_output_close,
2100 .trigger = snd_usbmidi_output_trigger,
2101};
2102static snd_rawmidi_ops_t snd_usbmidi_input =
2103{
2104 .open = snd_usbmidi_input_open,
2105 .close = snd_usbmidi_input_close,
2106 .trigger = snd_usbmidi_input_trigger,
2107};
2108
2109int snd_usbmidi_midi(cs46xx_t *chip, int device, snd_rawmidi_t **rrawmidi)
2110{
2111 snd_rawmidi_t *rmidi;
2112 int err;
2113
2114 if (rrawmidi)
2115 *rrawmidi = NULL;
2116 if ((err = snd_rawmidi_new(chip->card, "USB-MIDI", device, 1, 1, &rmidi)) < 0)
2117 return err;
2118 strcpy(rmidi->name, "USB-MIDI");
2119
2120 snd_rawmidi_set_ops( rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_usbmidi_output );
2121 snd_rawmidi_set_ops( rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_usbmidi_input );
2122
2123 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX;
2124
2125 rmidi->private_data = chip;
2126 chip->rmidi = rmidi;
2127 if (rrawmidi)
2128 *rrawmidi = NULL;
2129
2130 return 0;
2131}
2132
2133int snd_usbmidi_create( snd_card_t * card,
2134 struct pci_dev * pci,
2135 usbmidi_t ** rchip )
2136{
2137 usbmidi_t *chip;
2138 int err, idx;
2139 snd_region_t *region;
2140 static snd_device_opt_t ops = {
2141 .dev_free = snd_usbmidi_dev_free,
2142 };
2143
2144 *rchip = NULL;
2145 chip = snd_magic_kcalloc( usbmidi_t, 0, GFP_KERNEL );
2146 if ( chip == NULL )
2147 return -ENOMEM;
2148}
2149
2150EXPORT_SYMBOL(snd_usbmidi_create);
2151EXPORT_SYMBOL(snd_usbmidi_midi);
2152#endif /* HAVE_ALSA_SUPPORT */
2153
diff --git a/drivers/usb/class/usb-midi.h b/drivers/usb/class/usb-midi.h
deleted file mode 100644
index 358cdef8492e..000000000000
--- a/drivers/usb/class/usb-midi.h
+++ /dev/null
@@ -1,164 +0,0 @@
1/*
2 usb-midi.h -- USB-MIDI driver
3
4 Copyright (C) 2001
5 NAGANO Daisuke <breeze.nagano@nifty.ne.jp>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22/* ------------------------------------------------------------------------- */
23
24#ifndef _USB_MIDI_H_
25#define _USB_MIDI_H_
26
27#ifndef USB_SUBCLASS_MIDISTREAMING
28#define USB_SUBCLASS_MIDISTREAMING 3
29#endif
30
31/* ------------------------------------------------------------------------- */
32/* Roland MIDI Devices */
33
34#define USB_VENDOR_ID_ROLAND 0x0582
35#define USBMIDI_ROLAND_UA100G 0x0000
36#define USBMIDI_ROLAND_MPU64 0x0002
37#define USBMIDI_ROLAND_SC8850 0x0003
38#define USBMIDI_ROLAND_SC8820 0x0007
39#define USBMIDI_ROLAND_UM2 0x0005
40#define USBMIDI_ROLAND_UM1 0x0009
41#define USBMIDI_ROLAND_PC300 0x0008
42
43/* YAMAHA MIDI Devices */
44#define USB_VENDOR_ID_YAMAHA 0x0499
45#define USBMIDI_YAMAHA_MU1000 0x1001
46
47/* Steinberg MIDI Devices */
48#define USB_VENDOR_ID_STEINBERG 0x0763
49#define USBMIDI_STEINBERG_USB2MIDI 0x1001
50
51/* Mark of the Unicorn MIDI Devices */
52#define USB_VENDOR_ID_MOTU 0x07fd
53#define USBMIDI_MOTU_FASTLANE 0x0001
54
55/* ------------------------------------------------------------------------- */
56/* Supported devices */
57
58struct usb_midi_endpoint {
59 int endpoint;
60 int cableId; /* if bit-n == 1 then cableId-n is enabled (n: 0 - 15) */
61};
62
63struct usb_midi_device {
64 char *deviceName;
65
66 u16 idVendor;
67 u16 idProduct;
68 int interface;
69 int altSetting; /* -1: auto detect */
70
71 struct usb_midi_endpoint in[15];
72 struct usb_midi_endpoint out[15];
73};
74
75static struct usb_midi_device usb_midi_devices[] = {
76 { /* Roland UM-1 */
77 "Roland UM-1",
78 USB_VENDOR_ID_ROLAND, USBMIDI_ROLAND_UM1, 2, -1,
79 { { 0x81, 1 }, {-1, -1} },
80 { { 0x01, 1,}, {-1, -1} },
81 },
82
83 { /* Roland UM-2 */
84 "Roland UM-2" ,
85 USB_VENDOR_ID_ROLAND, USBMIDI_ROLAND_UM2, 2, -1,
86 { { 0x81, 3 }, {-1, -1} },
87 { { 0x01, 3,}, {-1, -1} },
88 },
89
90/** Next entry courtesy research by Michael Minn <michael@michaelminn.com> **/
91 { /* Roland UA-100 */
92 "Roland UA-100",
93 USB_VENDOR_ID_ROLAND, USBMIDI_ROLAND_UA100G, 2, -1,
94 { { 0x82, 7 }, {-1, -1} }, /** cables 0,1 and 2 for SYSEX **/
95 { { 0x02, 7 }, {-1, -1} },
96 },
97
98/** Next entry courtesy research by Michael Minn <michael@michaelminn.com> **/
99 { /* Roland SC8850 */
100 "Roland SC8850",
101 USB_VENDOR_ID_ROLAND, USBMIDI_ROLAND_SC8850, 2, -1,
102 { { 0x81, 0x3f }, {-1, -1} },
103 { { 0x01, 0x3f }, {-1, -1} },
104 },
105
106 { /* Roland SC8820 */
107 "Roland SC8820",
108 USB_VENDOR_ID_ROLAND, USBMIDI_ROLAND_SC8820, 2, -1,
109 { { 0x81, 0x13 }, {-1, -1} },
110 { { 0x01, 0x13 }, {-1, -1} },
111 },
112
113 { /* Roland SC8820 */
114 "Roland SC8820",
115 USB_VENDOR_ID_ROLAND, USBMIDI_ROLAND_SC8820, 2, -1,
116 { { 0x81, 17 }, {-1, -1} },
117 { { 0x01, 17 }, {-1, -1} },
118 },
119
120 { /* YAMAHA MU1000 */
121 "YAMAHA MU1000",
122 USB_VENDOR_ID_YAMAHA, USBMIDI_YAMAHA_MU1000, 0, -1,
123 { { 0x81, 1 }, {-1, -1} },
124 { { 0x01, 15 }, {-1, -1} },
125 },
126 { /* Roland PC-300 */
127 "Roland PC-300",
128 USB_VENDOR_ID_ROLAND, USBMIDI_ROLAND_PC300, 2, -1,
129 { { 0x81, 1 }, {-1, -1} },
130 { { 0x01, 1 }, {-1, -1} },
131 },
132 { /* MOTU Fastlane USB */
133 "MOTU Fastlane USB",
134 USB_VENDOR_ID_MOTU, USBMIDI_MOTU_FASTLANE, 1, 0,
135 { { 0x82, 3 }, {-1, -1} },
136 { { 0x02, 3 }, {-1, -1} },
137 }
138};
139
140#define VENDOR_SPECIFIC_USB_MIDI_DEVICES (sizeof(usb_midi_devices)/sizeof(struct usb_midi_device))
141
142/* for Hot-Plugging */
143
144static struct usb_device_id usb_midi_ids [] = {
145 { .match_flags = (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS),
146 .bInterfaceClass = USB_CLASS_AUDIO, .bInterfaceSubClass = USB_SUBCLASS_MIDISTREAMING},
147 { USB_DEVICE( USB_VENDOR_ID_ROLAND, USBMIDI_ROLAND_UM1 ) },
148 { USB_DEVICE( USB_VENDOR_ID_ROLAND, USBMIDI_ROLAND_UM2 ) },
149 { USB_DEVICE( USB_VENDOR_ID_ROLAND, USBMIDI_ROLAND_UA100G ) },
150 { USB_DEVICE( USB_VENDOR_ID_ROLAND, USBMIDI_ROLAND_PC300 ) },
151 { USB_DEVICE( USB_VENDOR_ID_ROLAND, USBMIDI_ROLAND_SC8850 ) },
152 { USB_DEVICE( USB_VENDOR_ID_ROLAND, USBMIDI_ROLAND_SC8820 ) },
153 { USB_DEVICE( USB_VENDOR_ID_YAMAHA, USBMIDI_YAMAHA_MU1000 ) },
154 { USB_DEVICE( USB_VENDOR_ID_MOTU, USBMIDI_MOTU_FASTLANE ) },
155/* { USB_DEVICE( USB_VENDOR_ID_STEINBERG, USBMIDI_STEINBERG_USB2MIDI ) },*/
156 { } /* Terminating entry */
157};
158
159MODULE_DEVICE_TABLE (usb, usb_midi_ids);
160
161/* ------------------------------------------------------------------------- */
162#endif /* _USB_MIDI_H_ */
163
164
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index d34848ac30b0..48dee4b8d8e5 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -55,6 +55,7 @@
55#include <linux/init.h> 55#include <linux/init.h>
56#include <linux/slab.h> 56#include <linux/slab.h>
57#include <linux/lp.h> 57#include <linux/lp.h>
58#include <linux/mutex.h>
58#undef DEBUG 59#undef DEBUG
59#include <linux/usb.h> 60#include <linux/usb.h>
60 61
@@ -223,7 +224,7 @@ static int usblp_cache_device_id_string(struct usblp *usblp);
223 224
224/* forward reference to make our lives easier */ 225/* forward reference to make our lives easier */
225static struct usb_driver usblp_driver; 226static struct usb_driver usblp_driver;
226static DECLARE_MUTEX(usblp_sem); /* locks the existence of usblp's */ 227static DEFINE_MUTEX(usblp_mutex); /* locks the existence of usblp's */
227 228
228/* 229/*
229 * Functions for usblp control messages. 230 * Functions for usblp control messages.
@@ -351,7 +352,7 @@ static int usblp_open(struct inode *inode, struct file *file)
351 if (minor < 0) 352 if (minor < 0)
352 return -ENODEV; 353 return -ENODEV;
353 354
354 down (&usblp_sem); 355 mutex_lock (&usblp_mutex);
355 356
356 retval = -ENODEV; 357 retval = -ENODEV;
357 intf = usb_find_interface(&usblp_driver, minor); 358 intf = usb_find_interface(&usblp_driver, minor);
@@ -399,7 +400,7 @@ static int usblp_open(struct inode *inode, struct file *file)
399 } 400 }
400 } 401 }
401out: 402out:
402 up (&usblp_sem); 403 mutex_unlock (&usblp_mutex);
403 return retval; 404 return retval;
404} 405}
405 406
@@ -425,13 +426,13 @@ static int usblp_release(struct inode *inode, struct file *file)
425{ 426{
426 struct usblp *usblp = file->private_data; 427 struct usblp *usblp = file->private_data;
427 428
428 down (&usblp_sem); 429 mutex_lock (&usblp_mutex);
429 usblp->used = 0; 430 usblp->used = 0;
430 if (usblp->present) { 431 if (usblp->present) {
431 usblp_unlink_urbs(usblp); 432 usblp_unlink_urbs(usblp);
432 } else /* finish cleanup from disconnect */ 433 } else /* finish cleanup from disconnect */
433 usblp_cleanup (usblp); 434 usblp_cleanup (usblp);
434 up (&usblp_sem); 435 mutex_unlock (&usblp_mutex);
435 return 0; 436 return 0;
436} 437}
437 438
@@ -1152,7 +1153,7 @@ static void usblp_disconnect(struct usb_interface *intf)
1152 1153
1153 device_remove_file(&intf->dev, &dev_attr_ieee1284_id); 1154 device_remove_file(&intf->dev, &dev_attr_ieee1284_id);
1154 1155
1155 down (&usblp_sem); 1156 mutex_lock (&usblp_mutex);
1156 down (&usblp->sem); 1157 down (&usblp->sem);
1157 usblp->present = 0; 1158 usblp->present = 0;
1158 usb_set_intfdata (intf, NULL); 1159 usb_set_intfdata (intf, NULL);
@@ -1166,7 +1167,7 @@ static void usblp_disconnect(struct usb_interface *intf)
1166 1167
1167 if (!usblp->used) 1168 if (!usblp->used)
1168 usblp_cleanup (usblp); 1169 usblp_cleanup (usblp);
1169 up (&usblp_sem); 1170 mutex_unlock (&usblp_mutex);
1170} 1171}
1171 1172
1172static struct usb_device_id usblp_ids [] = { 1173static struct usb_device_id usblp_ids [] = {
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index 2684e15b813b..c0f37343a276 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -57,6 +57,7 @@
57#include <linux/usb.h> 57#include <linux/usb.h>
58#include <linux/smp_lock.h> 58#include <linux/smp_lock.h>
59#include <linux/usbdevice_fs.h> 59#include <linux/usbdevice_fs.h>
60#include <linux/mutex.h>
60#include <asm/uaccess.h> 61#include <asm/uaccess.h>
61 62
62#include "usb.h" 63#include "usb.h"
@@ -570,7 +571,7 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbyte
570 if (!access_ok(VERIFY_WRITE, buf, nbytes)) 571 if (!access_ok(VERIFY_WRITE, buf, nbytes))
571 return -EFAULT; 572 return -EFAULT;
572 573
573 down (&usb_bus_list_lock); 574 mutex_lock(&usb_bus_list_lock);
574 /* print devices for all busses */ 575 /* print devices for all busses */
575 list_for_each_entry(bus, &usb_bus_list, bus_list) { 576 list_for_each_entry(bus, &usb_bus_list, bus_list) {
576 /* recurse through all children of the root hub */ 577 /* recurse through all children of the root hub */
@@ -580,12 +581,12 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbyte
580 ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, bus->root_hub, bus, 0, 0, 0); 581 ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, bus->root_hub, bus, 0, 0, 0);
581 usb_unlock_device(bus->root_hub); 582 usb_unlock_device(bus->root_hub);
582 if (ret < 0) { 583 if (ret < 0) {
583 up(&usb_bus_list_lock); 584 mutex_unlock(&usb_bus_list_lock);
584 return ret; 585 return ret;
585 } 586 }
586 total_written += ret; 587 total_written += ret;
587 } 588 }
588 up (&usb_bus_list_lock); 589 mutex_unlock(&usb_bus_list_lock);
589 return total_written; 590 return total_written;
590} 591}
591 592
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 2b68998fe4b3..545da37afca7 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -134,26 +134,21 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l
134 } 134 }
135 135
136 if (pos < sizeof(struct usb_device_descriptor)) { 136 if (pos < sizeof(struct usb_device_descriptor)) {
137 struct usb_device_descriptor *desc = kmalloc(sizeof(*desc), GFP_KERNEL); 137 struct usb_device_descriptor temp_desc ; /* 18 bytes - fits on the stack */
138 if (!desc) { 138
139 ret = -ENOMEM; 139 memcpy(&temp_desc, &dev->descriptor, sizeof(dev->descriptor));
140 goto err; 140 le16_to_cpus(&temp_desc.bcdUSB);
141 } 141 le16_to_cpus(&temp_desc.idVendor);
142 memcpy(desc, &dev->descriptor, sizeof(dev->descriptor)); 142 le16_to_cpus(&temp_desc.idProduct);
143 le16_to_cpus(&desc->bcdUSB); 143 le16_to_cpus(&temp_desc.bcdDevice);
144 le16_to_cpus(&desc->idVendor);
145 le16_to_cpus(&desc->idProduct);
146 le16_to_cpus(&desc->bcdDevice);
147 144
148 len = sizeof(struct usb_device_descriptor) - pos; 145 len = sizeof(struct usb_device_descriptor) - pos;
149 if (len > nbytes) 146 if (len > nbytes)
150 len = nbytes; 147 len = nbytes;
151 if (copy_to_user(buf, ((char *)desc) + pos, len)) { 148 if (copy_to_user(buf, ((char *)&temp_desc) + pos, len)) {
152 kfree(desc);
153 ret = -EFAULT; 149 ret = -EFAULT;
154 goto err; 150 goto err;
155 } 151 }
156 kfree(desc);
157 152
158 *ppos += len; 153 *ppos += len;
159 buf += len; 154 buf += len;
@@ -498,7 +493,8 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype, unsig
498{ 493{
499 int ret = 0; 494 int ret = 0;
500 495
501 if (ps->dev->state != USB_STATE_CONFIGURED) 496 if (ps->dev->state != USB_STATE_ADDRESS
497 && ps->dev->state != USB_STATE_CONFIGURED)
502 return -EHOSTUNREACH; 498 return -EHOSTUNREACH;
503 if (USB_TYPE_VENDOR == (USB_TYPE_MASK & requesttype)) 499 if (USB_TYPE_VENDOR == (USB_TYPE_MASK & requesttype))
504 return 0; 500 return 0;
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index dce9d987f0fc..c196f3845305 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -378,7 +378,7 @@ const struct usb_device_id *usb_match_id(struct usb_interface *interface,
378 378
379 return NULL; 379 return NULL;
380} 380}
381EXPORT_SYMBOL(usb_match_id); 381EXPORT_SYMBOL_GPL_FUTURE(usb_match_id);
382 382
383int usb_device_match(struct device *dev, struct device_driver *drv) 383int usb_device_match(struct device *dev, struct device_driver *drv)
384{ 384{
@@ -446,7 +446,7 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner)
446 446
447 return retval; 447 return retval;
448} 448}
449EXPORT_SYMBOL(usb_register_driver); 449EXPORT_SYMBOL_GPL_FUTURE(usb_register_driver);
450 450
451/** 451/**
452 * usb_deregister - unregister a USB driver 452 * usb_deregister - unregister a USB driver
@@ -469,4 +469,4 @@ void usb_deregister(struct usb_driver *driver)
469 469
470 usbfs_update_special(); 470 usbfs_update_special();
471} 471}
472EXPORT_SYMBOL(usb_deregister); 472EXPORT_SYMBOL_GPL_FUTURE(usb_deregister);
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 29b5b2a6e183..e0afb5ad29e5 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -264,14 +264,19 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
264 */ 264 */
265 retval = pci_set_power_state (dev, PCI_D3hot); 265 retval = pci_set_power_state (dev, PCI_D3hot);
266 if (retval == 0) { 266 if (retval == 0) {
267 dev_dbg (hcd->self.controller, "--> PCI D3\n"); 267 int wake = device_can_wakeup(&hcd->self.root_hub->dev);
268
269 wake = wake && device_may_wakeup(hcd->self.controller);
270
271 dev_dbg (hcd->self.controller, "--> PCI D3%s\n",
272 wake ? "/wakeup" : "");
268 273
269 /* Ignore these return values. We rely on pci code to 274 /* Ignore these return values. We rely on pci code to
270 * reject requests the hardware can't implement, rather 275 * reject requests the hardware can't implement, rather
271 * than coding the same thing. 276 * than coding the same thing.
272 */ 277 */
273 (void) pci_enable_wake (dev, PCI_D3hot, hcd->remote_wakeup); 278 (void) pci_enable_wake (dev, PCI_D3hot, wake);
274 (void) pci_enable_wake (dev, PCI_D3cold, hcd->remote_wakeup); 279 (void) pci_enable_wake (dev, PCI_D3cold, wake);
275 } else { 280 } else {
276 dev_dbg (&dev->dev, "PCI D3 suspend fail, %d\n", 281 dev_dbg (&dev->dev, "PCI D3 suspend fail, %d\n",
277 retval); 282 retval);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 0018bbc4de34..fbd938d4ea58 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -34,6 +34,7 @@
34#include <asm/scatterlist.h> 34#include <asm/scatterlist.h>
35#include <linux/device.h> 35#include <linux/device.h>
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/mutex.h>
37#include <asm/irq.h> 38#include <asm/irq.h>
38#include <asm/byteorder.h> 39#include <asm/byteorder.h>
39 40
@@ -93,7 +94,7 @@ struct usb_busmap {
93static struct usb_busmap busmap; 94static struct usb_busmap busmap;
94 95
95/* used when updating list of hcds */ 96/* used when updating list of hcds */
96DECLARE_MUTEX (usb_bus_list_lock); /* exported only for usbfs */ 97DEFINE_MUTEX(usb_bus_list_lock); /* exported only for usbfs */
97EXPORT_SYMBOL_GPL (usb_bus_list_lock); 98EXPORT_SYMBOL_GPL (usb_bus_list_lock);
98 99
99/* used for controlling access to virtual root hubs */ 100/* used for controlling access to virtual root hubs */
@@ -366,21 +367,39 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
366 367
367 /* DEVICE REQUESTS */ 368 /* DEVICE REQUESTS */
368 369
370 /* The root hub's remote wakeup enable bit is implemented using
371 * driver model wakeup flags. If this system supports wakeup
372 * through USB, userspace may change the default "allow wakeup"
373 * policy through sysfs or these calls.
374 *
375 * Most root hubs support wakeup from downstream devices, for
376 * runtime power management (disabling USB clocks and reducing
377 * VBUS power usage). However, not all of them do so; silicon,
378 * board, and BIOS bugs here are not uncommon, so these can't
379 * be treated quite like external hubs.
380 *
381 * Likewise, not all root hubs will pass wakeup events upstream,
382 * to wake up the whole system. So don't assume root hub and
383 * controller capabilities are identical.
384 */
385
369 case DeviceRequest | USB_REQ_GET_STATUS: 386 case DeviceRequest | USB_REQ_GET_STATUS:
370 tbuf [0] = (hcd->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP) 387 tbuf [0] = (device_may_wakeup(&hcd->self.root_hub->dev)
388 << USB_DEVICE_REMOTE_WAKEUP)
371 | (1 << USB_DEVICE_SELF_POWERED); 389 | (1 << USB_DEVICE_SELF_POWERED);
372 tbuf [1] = 0; 390 tbuf [1] = 0;
373 len = 2; 391 len = 2;
374 break; 392 break;
375 case DeviceOutRequest | USB_REQ_CLEAR_FEATURE: 393 case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
376 if (wValue == USB_DEVICE_REMOTE_WAKEUP) 394 if (wValue == USB_DEVICE_REMOTE_WAKEUP)
377 hcd->remote_wakeup = 0; 395 device_set_wakeup_enable(&hcd->self.root_hub->dev, 0);
378 else 396 else
379 goto error; 397 goto error;
380 break; 398 break;
381 case DeviceOutRequest | USB_REQ_SET_FEATURE: 399 case DeviceOutRequest | USB_REQ_SET_FEATURE:
382 if (hcd->can_wakeup && wValue == USB_DEVICE_REMOTE_WAKEUP) 400 if (device_can_wakeup(&hcd->self.root_hub->dev)
383 hcd->remote_wakeup = 1; 401 && wValue == USB_DEVICE_REMOTE_WAKEUP)
402 device_set_wakeup_enable(&hcd->self.root_hub->dev, 1);
384 else 403 else
385 goto error; 404 goto error;
386 break; 405 break;
@@ -409,7 +428,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
409 bufp = fs_rh_config_descriptor; 428 bufp = fs_rh_config_descriptor;
410 len = sizeof fs_rh_config_descriptor; 429 len = sizeof fs_rh_config_descriptor;
411 } 430 }
412 if (hcd->can_wakeup) 431 if (device_can_wakeup(&hcd->self.root_hub->dev))
413 patch_wakeup = 1; 432 patch_wakeup = 1;
414 break; 433 break;
415 case USB_DT_STRING << 8: 434 case USB_DT_STRING << 8:
@@ -761,14 +780,14 @@ static int usb_register_bus(struct usb_bus *bus)
761{ 780{
762 int busnum; 781 int busnum;
763 782
764 down (&usb_bus_list_lock); 783 mutex_lock(&usb_bus_list_lock);
765 busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1); 784 busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1);
766 if (busnum < USB_MAXBUS) { 785 if (busnum < USB_MAXBUS) {
767 set_bit (busnum, busmap.busmap); 786 set_bit (busnum, busmap.busmap);
768 bus->busnum = busnum; 787 bus->busnum = busnum;
769 } else { 788 } else {
770 printk (KERN_ERR "%s: too many buses\n", usbcore_name); 789 printk (KERN_ERR "%s: too many buses\n", usbcore_name);
771 up(&usb_bus_list_lock); 790 mutex_unlock(&usb_bus_list_lock);
772 return -E2BIG; 791 return -E2BIG;
773 } 792 }
774 793
@@ -776,7 +795,7 @@ static int usb_register_bus(struct usb_bus *bus)
776 bus->controller, "usb_host%d", busnum); 795 bus->controller, "usb_host%d", busnum);
777 if (IS_ERR(bus->class_dev)) { 796 if (IS_ERR(bus->class_dev)) {
778 clear_bit(busnum, busmap.busmap); 797 clear_bit(busnum, busmap.busmap);
779 up(&usb_bus_list_lock); 798 mutex_unlock(&usb_bus_list_lock);
780 return PTR_ERR(bus->class_dev); 799 return PTR_ERR(bus->class_dev);
781 } 800 }
782 801
@@ -784,7 +803,7 @@ static int usb_register_bus(struct usb_bus *bus)
784 803
785 /* Add it to the local list of buses */ 804 /* Add it to the local list of buses */
786 list_add (&bus->bus_list, &usb_bus_list); 805 list_add (&bus->bus_list, &usb_bus_list);
787 up (&usb_bus_list_lock); 806 mutex_unlock(&usb_bus_list_lock);
788 807
789 usb_notify_add_bus(bus); 808 usb_notify_add_bus(bus);
790 809
@@ -809,9 +828,9 @@ static void usb_deregister_bus (struct usb_bus *bus)
809 * controller code, as well as having it call this when cleaning 828 * controller code, as well as having it call this when cleaning
810 * itself up 829 * itself up
811 */ 830 */
812 down (&usb_bus_list_lock); 831 mutex_lock(&usb_bus_list_lock);
813 list_del (&bus->bus_list); 832 list_del (&bus->bus_list);
814 up (&usb_bus_list_lock); 833 mutex_unlock(&usb_bus_list_lock);
815 834
816 usb_notify_remove_bus(bus); 835 usb_notify_remove_bus(bus);
817 836
@@ -822,18 +841,17 @@ static void usb_deregister_bus (struct usb_bus *bus)
822 841
823/** 842/**
824 * register_root_hub - called by usb_add_hcd() to register a root hub 843 * register_root_hub - called by usb_add_hcd() to register a root hub
825 * @usb_dev: the usb root hub device to be registered.
826 * @hcd: host controller for this root hub 844 * @hcd: host controller for this root hub
827 * 845 *
828 * This function registers the root hub with the USB subsystem. It sets up 846 * This function registers the root hub with the USB subsystem. It sets up
829 * the device properly in the device tree and stores the root_hub pointer 847 * the device properly in the device tree and then calls usb_new_device()
830 * in the bus structure, then calls usb_new_device() to register the usb 848 * to register the usb device. It also assigns the root hub's USB address
831 * device. It also assigns the root hub's USB address (always 1). 849 * (always 1).
832 */ 850 */
833static int register_root_hub (struct usb_device *usb_dev, 851static int register_root_hub(struct usb_hcd *hcd)
834 struct usb_hcd *hcd)
835{ 852{
836 struct device *parent_dev = hcd->self.controller; 853 struct device *parent_dev = hcd->self.controller;
854 struct usb_device *usb_dev = hcd->self.root_hub;
837 const int devnum = 1; 855 const int devnum = 1;
838 int retval; 856 int retval;
839 857
@@ -844,14 +862,12 @@ static int register_root_hub (struct usb_device *usb_dev,
844 set_bit (devnum, usb_dev->bus->devmap.devicemap); 862 set_bit (devnum, usb_dev->bus->devmap.devicemap);
845 usb_set_device_state(usb_dev, USB_STATE_ADDRESS); 863 usb_set_device_state(usb_dev, USB_STATE_ADDRESS);
846 864
847 down (&usb_bus_list_lock); 865 mutex_lock(&usb_bus_list_lock);
848 usb_dev->bus->root_hub = usb_dev;
849 866
850 usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64); 867 usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64);
851 retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE); 868 retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE);
852 if (retval != sizeof usb_dev->descriptor) { 869 if (retval != sizeof usb_dev->descriptor) {
853 usb_dev->bus->root_hub = NULL; 870 mutex_unlock(&usb_bus_list_lock);
854 up (&usb_bus_list_lock);
855 dev_dbg (parent_dev, "can't read %s device descriptor %d\n", 871 dev_dbg (parent_dev, "can't read %s device descriptor %d\n",
856 usb_dev->dev.bus_id, retval); 872 usb_dev->dev.bus_id, retval);
857 return (retval < 0) ? retval : -EMSGSIZE; 873 return (retval < 0) ? retval : -EMSGSIZE;
@@ -859,11 +875,10 @@ static int register_root_hub (struct usb_device *usb_dev,
859 875
860 retval = usb_new_device (usb_dev); 876 retval = usb_new_device (usb_dev);
861 if (retval) { 877 if (retval) {
862 usb_dev->bus->root_hub = NULL;
863 dev_err (parent_dev, "can't register root hub for %s, %d\n", 878 dev_err (parent_dev, "can't register root hub for %s, %d\n",
864 usb_dev->dev.bus_id, retval); 879 usb_dev->dev.bus_id, retval);
865 } 880 }
866 up (&usb_bus_list_lock); 881 mutex_unlock(&usb_bus_list_lock);
867 882
868 if (retval == 0) { 883 if (retval == 0) {
869 spin_lock_irq (&hcd_root_hub_lock); 884 spin_lock_irq (&hcd_root_hub_lock);
@@ -1090,7 +1105,6 @@ static void urb_unlink (struct urb *urb)
1090 spin_lock_irqsave (&hcd_data_lock, flags); 1105 spin_lock_irqsave (&hcd_data_lock, flags);
1091 list_del_init (&urb->urb_list); 1106 list_del_init (&urb->urb_list);
1092 spin_unlock_irqrestore (&hcd_data_lock, flags); 1107 spin_unlock_irqrestore (&hcd_data_lock, flags);
1093 usb_put_dev (urb->dev);
1094} 1108}
1095 1109
1096 1110
@@ -1130,7 +1144,6 @@ static int hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
1130 case HC_STATE_RUNNING: 1144 case HC_STATE_RUNNING:
1131 case HC_STATE_RESUMING: 1145 case HC_STATE_RESUMING:
1132doit: 1146doit:
1133 usb_get_dev (urb->dev);
1134 list_add_tail (&urb->urb_list, &ep->urb_list); 1147 list_add_tail (&urb->urb_list, &ep->urb_list);
1135 status = 0; 1148 status = 0;
1136 break; 1149 break;
@@ -1771,12 +1784,10 @@ int usb_add_hcd(struct usb_hcd *hcd,
1771 1784
1772 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 1785 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1773 1786
1774 /* till now HC has been in an indeterminate state ... */ 1787 /* HC is in reset state, but accessible. Now do the one-time init,
1775 if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) { 1788 * bottom up so that hcds can customize the root hubs before khubd
1776 dev_err(hcd->self.controller, "can't reset\n"); 1789 * starts talking to them. (Note, bus id is assigned early too.)
1777 return retval; 1790 */
1778 }
1779
1780 if ((retval = hcd_buffer_create(hcd)) != 0) { 1791 if ((retval = hcd_buffer_create(hcd)) != 0) {
1781 dev_dbg(hcd->self.controller, "pool alloc failed\n"); 1792 dev_dbg(hcd->self.controller, "pool alloc failed\n");
1782 return retval; 1793 return retval;
@@ -1785,6 +1796,36 @@ int usb_add_hcd(struct usb_hcd *hcd,
1785 if ((retval = usb_register_bus(&hcd->self)) < 0) 1796 if ((retval = usb_register_bus(&hcd->self)) < 0)
1786 goto err_register_bus; 1797 goto err_register_bus;
1787 1798
1799 if ((rhdev = usb_alloc_dev(NULL, &hcd->self, 0)) == NULL) {
1800 dev_err(hcd->self.controller, "unable to allocate root hub\n");
1801 retval = -ENOMEM;
1802 goto err_allocate_root_hub;
1803 }
1804 rhdev->speed = (hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH :
1805 USB_SPEED_FULL;
1806 hcd->self.root_hub = rhdev;
1807
1808 /* "reset" is misnamed; its role is now one-time init. the controller
1809 * should already have been reset (and boot firmware kicked off etc).
1810 */
1811 if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) {
1812 dev_err(hcd->self.controller, "can't setup\n");
1813 goto err_hcd_driver_setup;
1814 }
1815
1816 /* wakeup flag init is in transition; for now we can't rely on PCI to
1817 * initialize these bits properly, so we let reset() override it.
1818 * This init should _precede_ the reset() once PCI behaves.
1819 */
1820 device_init_wakeup(&rhdev->dev,
1821 device_can_wakeup(hcd->self.controller));
1822
1823 /* NOTE: root hub and controller capabilities may not be the same */
1824 if (device_can_wakeup(hcd->self.controller)
1825 && device_can_wakeup(&hcd->self.root_hub->dev))
1826 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n");
1827
1828 /* enable irqs just before we start the controller */
1788 if (hcd->driver->irq) { 1829 if (hcd->driver->irq) {
1789 char buf[8], *bufp = buf; 1830 char buf[8], *bufp = buf;
1790 1831
@@ -1816,56 +1857,32 @@ int usb_add_hcd(struct usb_hcd *hcd,
1816 (unsigned long long)hcd->rsrc_start); 1857 (unsigned long long)hcd->rsrc_start);
1817 } 1858 }
1818 1859
1819 /* Allocate the root hub before calling hcd->driver->start(),
1820 * but don't register it until afterward so that the hardware
1821 * is running.
1822 */
1823 if ((rhdev = usb_alloc_dev(NULL, &hcd->self, 0)) == NULL) {
1824 dev_err(hcd->self.controller, "unable to allocate root hub\n");
1825 retval = -ENOMEM;
1826 goto err_allocate_root_hub;
1827 }
1828
1829 /* Although in principle hcd->driver->start() might need to use rhdev,
1830 * none of the current drivers do.
1831 */
1832 if ((retval = hcd->driver->start(hcd)) < 0) { 1860 if ((retval = hcd->driver->start(hcd)) < 0) {
1833 dev_err(hcd->self.controller, "startup error %d\n", retval); 1861 dev_err(hcd->self.controller, "startup error %d\n", retval);
1834 goto err_hcd_driver_start; 1862 goto err_hcd_driver_start;
1835 } 1863 }
1836 1864
1837 /* hcd->driver->start() reported can_wakeup, probably with 1865 /* starting here, usbcore will pay attention to this root hub */
1838 * assistance from board's boot firmware.
1839 * NOTE: normal devices won't enable wakeup by default.
1840 */
1841 if (hcd->can_wakeup)
1842 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n");
1843 hcd->remote_wakeup = hcd->can_wakeup;
1844
1845 rhdev->speed = (hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH :
1846 USB_SPEED_FULL;
1847 rhdev->bus_mA = min(500u, hcd->power_budget); 1866 rhdev->bus_mA = min(500u, hcd->power_budget);
1848 if ((retval = register_root_hub(rhdev, hcd)) != 0) 1867 if ((retval = register_root_hub(hcd)) != 0)
1849 goto err_register_root_hub; 1868 goto err_register_root_hub;
1850 1869
1851 if (hcd->uses_new_polling && hcd->poll_rh) 1870 if (hcd->uses_new_polling && hcd->poll_rh)
1852 usb_hcd_poll_rh_status(hcd); 1871 usb_hcd_poll_rh_status(hcd);
1853 return retval; 1872 return retval;
1854 1873
1855 err_register_root_hub: 1874err_register_root_hub:
1856 hcd->driver->stop(hcd); 1875 hcd->driver->stop(hcd);
1857 1876err_hcd_driver_start:
1858 err_hcd_driver_start:
1859 usb_put_dev(rhdev);
1860
1861 err_allocate_root_hub:
1862 if (hcd->irq >= 0) 1877 if (hcd->irq >= 0)
1863 free_irq(irqnum, hcd); 1878 free_irq(irqnum, hcd);
1864 1879err_request_irq:
1865 err_request_irq: 1880err_hcd_driver_setup:
1881 hcd->self.root_hub = NULL;
1882 usb_put_dev(rhdev);
1883err_allocate_root_hub:
1866 usb_deregister_bus(&hcd->self); 1884 usb_deregister_bus(&hcd->self);
1867 1885err_register_bus:
1868 err_register_bus:
1869 hcd_buffer_destroy(hcd); 1886 hcd_buffer_destroy(hcd);
1870 return retval; 1887 return retval;
1871} 1888}
@@ -1891,9 +1908,9 @@ void usb_remove_hcd(struct usb_hcd *hcd)
1891 hcd->rh_registered = 0; 1908 hcd->rh_registered = 0;
1892 spin_unlock_irq (&hcd_root_hub_lock); 1909 spin_unlock_irq (&hcd_root_hub_lock);
1893 1910
1894 down(&usb_bus_list_lock); 1911 mutex_lock(&usb_bus_list_lock);
1895 usb_disconnect(&hcd->self.root_hub); 1912 usb_disconnect(&hcd->self.root_hub);
1896 up(&usb_bus_list_lock); 1913 mutex_unlock(&usb_bus_list_lock);
1897 1914
1898 hcd->poll_rh = 0; 1915 hcd->poll_rh = 0;
1899 del_timer_sync(&hcd->rh_timer); 1916 del_timer_sync(&hcd->rh_timer);
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 591b5aad1a18..7022aafb2ae8 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -78,8 +78,6 @@ struct usb_hcd { /* usb_bus.hcpriv points to this */
78#define HCD_FLAG_HW_ACCESSIBLE 0x00000001 78#define HCD_FLAG_HW_ACCESSIBLE 0x00000001
79#define HCD_FLAG_SAW_IRQ 0x00000002 79#define HCD_FLAG_SAW_IRQ 0x00000002
80 80
81 unsigned can_wakeup:1; /* hw supports wakeup? */
82 unsigned remote_wakeup:1;/* sw should use wakeup? */
83 unsigned rh_registered:1;/* is root hub registered? */ 81 unsigned rh_registered:1;/* is root hub registered? */
84 82
85 /* The next flag is a stopgap, to be removed when all the HCDs 83 /* The next flag is a stopgap, to be removed when all the HCDs
@@ -364,7 +362,7 @@ extern void usb_set_device_state(struct usb_device *udev,
364/* exported only within usbcore */ 362/* exported only within usbcore */
365 363
366extern struct list_head usb_bus_list; 364extern struct list_head usb_bus_list;
367extern struct semaphore usb_bus_list_lock; 365extern struct mutex usb_bus_list_lock;
368extern wait_queue_head_t usb_kill_urb_queue; 366extern wait_queue_head_t usb_kill_urb_queue;
369 367
370extern struct usb_bus *usb_bus_get (struct usb_bus *bus); 368extern struct usb_bus *usb_bus_get (struct usb_bus *bus);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 650d5ee5871b..8e65f7a237e4 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -22,6 +22,7 @@
22#include <linux/usb.h> 22#include <linux/usb.h>
23#include <linux/usbdevice_fs.h> 23#include <linux/usbdevice_fs.h>
24#include <linux/kthread.h> 24#include <linux/kthread.h>
25#include <linux/mutex.h>
25 26
26#include <asm/semaphore.h> 27#include <asm/semaphore.h>
27#include <asm/uaccess.h> 28#include <asm/uaccess.h>
@@ -1005,12 +1006,18 @@ void usb_set_device_state(struct usb_device *udev,
1005 ; /* do nothing */ 1006 ; /* do nothing */
1006 else if (new_state != USB_STATE_NOTATTACHED) { 1007 else if (new_state != USB_STATE_NOTATTACHED) {
1007 udev->state = new_state; 1008 udev->state = new_state;
1008 if (new_state == USB_STATE_CONFIGURED) 1009
1009 device_init_wakeup(&udev->dev, 1010 /* root hub wakeup capabilities are managed out-of-band
1010 (udev->actconfig->desc.bmAttributes 1011 * and may involve silicon errata ... ignore them here.
1011 & USB_CONFIG_ATT_WAKEUP)); 1012 */
1012 else if (new_state != USB_STATE_SUSPENDED) 1013 if (udev->parent) {
1013 device_init_wakeup(&udev->dev, 0); 1014 if (new_state == USB_STATE_CONFIGURED)
1015 device_init_wakeup(&udev->dev,
1016 (udev->actconfig->desc.bmAttributes
1017 & USB_CONFIG_ATT_WAKEUP));
1018 else if (new_state != USB_STATE_SUSPENDED)
1019 device_init_wakeup(&udev->dev, 0);
1020 }
1014 } else 1021 } else
1015 recursively_mark_NOTATTACHED(udev); 1022 recursively_mark_NOTATTACHED(udev);
1016 spin_unlock_irqrestore(&device_state_lock, flags); 1023 spin_unlock_irqrestore(&device_state_lock, flags);
@@ -1172,8 +1179,11 @@ static int choose_configuration(struct usb_device *udev)
1172 c = udev->config; 1179 c = udev->config;
1173 num_configs = udev->descriptor.bNumConfigurations; 1180 num_configs = udev->descriptor.bNumConfigurations;
1174 for (i = 0; i < num_configs; (i++, c++)) { 1181 for (i = 0; i < num_configs; (i++, c++)) {
1175 struct usb_interface_descriptor *desc = 1182 struct usb_interface_descriptor *desc = NULL;
1176 &c->intf_cache[0]->altsetting->desc; 1183
1184 /* It's possible that a config has no interfaces! */
1185 if (c->desc.bNumInterfaces > 0)
1186 desc = &c->intf_cache[0]->altsetting->desc;
1177 1187
1178 /* 1188 /*
1179 * HP's USB bus-powered keyboard has only one configuration 1189 * HP's USB bus-powered keyboard has only one configuration
@@ -1208,7 +1218,8 @@ static int choose_configuration(struct usb_device *udev)
1208 /* If the first config's first interface is COMM/2/0xff 1218 /* If the first config's first interface is COMM/2/0xff
1209 * (MSFT RNDIS), rule it out unless Linux has host-side 1219 * (MSFT RNDIS), rule it out unless Linux has host-side
1210 * RNDIS support. */ 1220 * RNDIS support. */
1211 if (i == 0 && desc->bInterfaceClass == USB_CLASS_COMM 1221 if (i == 0 && desc
1222 && desc->bInterfaceClass == USB_CLASS_COMM
1212 && desc->bInterfaceSubClass == 2 1223 && desc->bInterfaceSubClass == 2
1213 && desc->bInterfaceProtocol == 0xff) { 1224 && desc->bInterfaceProtocol == 0xff) {
1214#ifndef CONFIG_USB_NET_RNDIS 1225#ifndef CONFIG_USB_NET_RNDIS
@@ -1224,8 +1235,8 @@ static int choose_configuration(struct usb_device *udev)
1224 * than a vendor-specific driver. */ 1235 * than a vendor-specific driver. */
1225 else if (udev->descriptor.bDeviceClass != 1236 else if (udev->descriptor.bDeviceClass !=
1226 USB_CLASS_VENDOR_SPEC && 1237 USB_CLASS_VENDOR_SPEC &&
1227 desc->bInterfaceClass != 1238 (!desc || desc->bInterfaceClass !=
1228 USB_CLASS_VENDOR_SPEC) { 1239 USB_CLASS_VENDOR_SPEC)) {
1229 best = c; 1240 best = c;
1230 break; 1241 break;
1231 } 1242 }
@@ -1876,18 +1887,18 @@ int usb_resume_device(struct usb_device *udev)
1876 if (udev->state == USB_STATE_NOTATTACHED) 1887 if (udev->state == USB_STATE_NOTATTACHED)
1877 return -ENODEV; 1888 return -ENODEV;
1878 1889
1879#ifdef CONFIG_USB_SUSPEND
1880 /* selective resume of one downstream hub-to-device port */ 1890 /* selective resume of one downstream hub-to-device port */
1881 if (udev->parent) { 1891 if (udev->parent) {
1892#ifdef CONFIG_USB_SUSPEND
1882 if (udev->state == USB_STATE_SUSPENDED) { 1893 if (udev->state == USB_STATE_SUSPENDED) {
1883 // NOTE swsusp may bork us, device state being wrong... 1894 // NOTE swsusp may bork us, device state being wrong...
1884 // NOTE this fails if parent is also suspended... 1895 // NOTE this fails if parent is also suspended...
1885 status = hub_port_resume(hdev_to_hub(udev->parent), 1896 status = hub_port_resume(hdev_to_hub(udev->parent),
1886 udev->portnum, udev); 1897 udev->portnum, udev);
1887 } else 1898 } else
1899#endif
1888 status = 0; 1900 status = 0;
1889 } else 1901 } else
1890#endif
1891 status = finish_device_resume(udev); 1902 status = finish_device_resume(udev);
1892 if (status < 0) 1903 if (status < 0)
1893 dev_dbg(&udev->dev, "can't resume, status %d\n", 1904 dev_dbg(&udev->dev, "can't resume, status %d\n",
@@ -2162,7 +2173,7 @@ static int
2162hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, 2173hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2163 int retry_counter) 2174 int retry_counter)
2164{ 2175{
2165 static DECLARE_MUTEX(usb_address0_sem); 2176 static DEFINE_MUTEX(usb_address0_mutex);
2166 2177
2167 struct usb_device *hdev = hub->hdev; 2178 struct usb_device *hdev = hub->hdev;
2168 int i, j, retval; 2179 int i, j, retval;
@@ -2183,7 +2194,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2183 if (oldspeed == USB_SPEED_LOW) 2194 if (oldspeed == USB_SPEED_LOW)
2184 delay = HUB_LONG_RESET_TIME; 2195 delay = HUB_LONG_RESET_TIME;
2185 2196
2186 down(&usb_address0_sem); 2197 mutex_lock(&usb_address0_mutex);
2187 2198
2188 /* Reset the device; full speed may morph to high speed */ 2199 /* Reset the device; full speed may morph to high speed */
2189 retval = hub_port_reset(hub, port1, udev, delay); 2200 retval = hub_port_reset(hub, port1, udev, delay);
@@ -2381,7 +2392,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2381fail: 2392fail:
2382 if (retval) 2393 if (retval)
2383 hub_port_disable(hub, port1, 0); 2394 hub_port_disable(hub, port1, 0);
2384 up(&usb_address0_sem); 2395 mutex_unlock(&usb_address0_mutex);
2385 return retval; 2396 return retval;
2386} 2397}
2387 2398
@@ -3017,7 +3028,7 @@ int usb_reset_device(struct usb_device *udev)
3017 parent_hub = hdev_to_hub(parent_hdev); 3028 parent_hub = hdev_to_hub(parent_hdev);
3018 3029
3019 /* If we're resetting an active hub, take some special actions */ 3030 /* If we're resetting an active hub, take some special actions */
3020 if (udev->actconfig && 3031 if (udev->actconfig && udev->actconfig->desc.bNumInterfaces > 0 &&
3021 udev->actconfig->interface[0]->dev.driver == 3032 udev->actconfig->interface[0]->dev.driver ==
3022 &hub_driver.driver && 3033 &hub_driver.driver &&
3023 (hub = hdev_to_hub(udev)) != NULL) { 3034 (hub = hdev_to_hub(udev)) != NULL) {
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 7135e542679d..08fb20f06f3e 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -631,8 +631,8 @@ int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char
631 * Returns the number of bytes received on success, or else the status code 631 * Returns the number of bytes received on success, or else the status code
632 * returned by the underlying usb_control_msg() call. 632 * returned by the underlying usb_control_msg() call.
633 */ 633 */
634int usb_get_string(struct usb_device *dev, unsigned short langid, 634static int usb_get_string(struct usb_device *dev, unsigned short langid,
635 unsigned char index, void *buf, int size) 635 unsigned char index, void *buf, int size)
636{ 636{
637 int i; 637 int i;
638 int result; 638 int result;
@@ -1388,11 +1388,13 @@ free_interfaces:
1388 if (dev->state != USB_STATE_ADDRESS) 1388 if (dev->state != USB_STATE_ADDRESS)
1389 usb_disable_device (dev, 1); // Skip ep0 1389 usb_disable_device (dev, 1); // Skip ep0
1390 1390
1391 i = dev->bus_mA - cp->desc.bMaxPower * 2; 1391 if (cp) {
1392 if (i < 0) 1392 i = dev->bus_mA - cp->desc.bMaxPower * 2;
1393 dev_warn(&dev->dev, "new config #%d exceeds power " 1393 if (i < 0)
1394 "limit by %dmA\n", 1394 dev_warn(&dev->dev, "new config #%d exceeds power "
1395 configuration, -i); 1395 "limit by %dmA\n",
1396 configuration, -i);
1397 }
1396 1398
1397 if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 1399 if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1398 USB_REQ_SET_CONFIGURATION, 0, configuration, 0, 1400 USB_REQ_SET_CONFIGURATION, 0, configuration, 0,
@@ -1488,7 +1490,6 @@ EXPORT_SYMBOL(usb_sg_wait);
1488// synchronous control message convenience routines 1490// synchronous control message convenience routines
1489EXPORT_SYMBOL(usb_get_descriptor); 1491EXPORT_SYMBOL(usb_get_descriptor);
1490EXPORT_SYMBOL(usb_get_status); 1492EXPORT_SYMBOL(usb_get_status);
1491EXPORT_SYMBOL(usb_get_string);
1492EXPORT_SYMBOL(usb_string); 1493EXPORT_SYMBOL(usb_string);
1493 1494
1494// synchronous calls that also maintain usbcore state 1495// synchronous calls that also maintain usbcore state
diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c
index fbbebab52fbd..4b55285de9a0 100644
--- a/drivers/usb/core/notify.c
+++ b/drivers/usb/core/notify.c
@@ -13,16 +13,17 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/notifier.h> 14#include <linux/notifier.h>
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include <linux/mutex.h>
16#include "usb.h" 17#include "usb.h"
17 18
18 19
19static struct notifier_block *usb_notifier_list; 20static struct notifier_block *usb_notifier_list;
20static DECLARE_MUTEX(usb_notifier_lock); 21static DEFINE_MUTEX(usb_notifier_lock);
21 22
22static void usb_notifier_chain_register(struct notifier_block **list, 23static void usb_notifier_chain_register(struct notifier_block **list,
23 struct notifier_block *n) 24 struct notifier_block *n)
24{ 25{
25 down(&usb_notifier_lock); 26 mutex_lock(&usb_notifier_lock);
26 while (*list) { 27 while (*list) {
27 if (n->priority > (*list)->priority) 28 if (n->priority > (*list)->priority)
28 break; 29 break;
@@ -30,13 +31,13 @@ static void usb_notifier_chain_register(struct notifier_block **list,
30 } 31 }
31 n->next = *list; 32 n->next = *list;
32 *list = n; 33 *list = n;
33 up(&usb_notifier_lock); 34 mutex_unlock(&usb_notifier_lock);
34} 35}
35 36
36static void usb_notifier_chain_unregister(struct notifier_block **nl, 37static void usb_notifier_chain_unregister(struct notifier_block **nl,
37 struct notifier_block *n) 38 struct notifier_block *n)
38{ 39{
39 down(&usb_notifier_lock); 40 mutex_lock(&usb_notifier_lock);
40 while ((*nl)!=NULL) { 41 while ((*nl)!=NULL) {
41 if ((*nl)==n) { 42 if ((*nl)==n) {
42 *nl = n->next; 43 *nl = n->next;
@@ -45,7 +46,7 @@ static void usb_notifier_chain_unregister(struct notifier_block **nl,
45 nl=&((*nl)->next); 46 nl=&((*nl)->next);
46 } 47 }
47exit: 48exit:
48 up(&usb_notifier_lock); 49 mutex_unlock(&usb_notifier_lock);
49} 50}
50 51
51static int usb_notifier_call_chain(struct notifier_block **n, 52static int usb_notifier_call_chain(struct notifier_block **n,
@@ -54,7 +55,7 @@ static int usb_notifier_call_chain(struct notifier_block **n,
54 int ret=NOTIFY_DONE; 55 int ret=NOTIFY_DONE;
55 struct notifier_block *nb = *n; 56 struct notifier_block *nb = *n;
56 57
57 down(&usb_notifier_lock); 58 mutex_lock(&usb_notifier_lock);
58 while (nb) { 59 while (nb) {
59 ret = nb->notifier_call(nb,val,v); 60 ret = nb->notifier_call(nb,val,v);
60 if (ret&NOTIFY_STOP_MASK) { 61 if (ret&NOTIFY_STOP_MASK) {
@@ -63,7 +64,7 @@ static int usb_notifier_call_chain(struct notifier_block **n,
63 nb = nb->next; 64 nb = nb->next;
64 } 65 }
65exit: 66exit:
66 up(&usb_notifier_lock); 67 mutex_unlock(&usb_notifier_lock);
67 return ret; 68 return ret;
68} 69}
69 70
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 13d1d367f7f1..d7352aa73b5e 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -33,6 +33,7 @@
33#include <linux/errno.h> 33#include <linux/errno.h>
34#include <linux/smp_lock.h> 34#include <linux/smp_lock.h>
35#include <linux/usb.h> 35#include <linux/usb.h>
36#include <linux/mutex.h>
36 37
37#include <asm/io.h> 38#include <asm/io.h>
38#include <asm/scatterlist.h> 39#include <asm/scatterlist.h>
@@ -639,7 +640,7 @@ struct usb_device *usb_find_device(u16 vendor_id, u16 product_id)
639 struct usb_bus *bus; 640 struct usb_bus *bus;
640 struct usb_device *dev = NULL; 641 struct usb_device *dev = NULL;
641 642
642 down(&usb_bus_list_lock); 643 mutex_lock(&usb_bus_list_lock);
643 for (buslist = usb_bus_list.next; 644 for (buslist = usb_bus_list.next;
644 buslist != &usb_bus_list; 645 buslist != &usb_bus_list;
645 buslist = buslist->next) { 646 buslist = buslist->next) {
@@ -653,7 +654,7 @@ struct usb_device *usb_find_device(u16 vendor_id, u16 product_id)
653 goto exit; 654 goto exit;
654 } 655 }
655exit: 656exit:
656 up(&usb_bus_list_lock); 657 mutex_unlock(&usb_bus_list_lock);
657 return dev; 658 return dev;
658} 659}
659 660
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index ff075a53c8d6..d80f71877d68 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -187,6 +187,23 @@ config USB_OTG
187 187
188 Select this only if your OMAP board has a Mini-AB connector. 188 Select this only if your OMAP board has a Mini-AB connector.
189 189
190config USB_GADGET_AT91
191 boolean "AT91 USB Device Port"
192 depends on ARCH_AT91RM9200
193 select USB_GADGET_SELECTED
194 help
195 Many Atmel AT91 processors (such as the AT91RM2000) have a
196 full speed USB Device Port with support for five configurable
197 endpoints (plus endpoint zero).
198
199 Say "y" to link the driver statically, or "m" to build a
200 dynamically linked module called "at91_udc" and force all
201 gadget drivers to also be dynamically linked.
202
203config USB_AT91
204 tristate
205 depends on USB_GADGET_AT91
206 default USB_GADGET
190 207
191config USB_GADGET_DUMMY_HCD 208config USB_GADGET_DUMMY_HCD
192 boolean "Dummy HCD (DEVELOPMENT)" 209 boolean "Dummy HCD (DEVELOPMENT)"
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index d5fd04d886e6..5a28e61392ec 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_USB_PXA2XX) += pxa2xx_udc.o
7obj-$(CONFIG_USB_GOKU) += goku_udc.o 7obj-$(CONFIG_USB_GOKU) += goku_udc.o
8obj-$(CONFIG_USB_OMAP) += omap_udc.o 8obj-$(CONFIG_USB_OMAP) += omap_udc.o
9obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o 9obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o
10obj-$(CONFIG_USB_AT91) += at91_udc.o
10 11
11# 12#
12# USB gadget drivers 13# USB gadget drivers
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
new file mode 100644
index 000000000000..865858cfd1c2
--- /dev/null
+++ b/drivers/usb/gadget/at91_udc.c
@@ -0,0 +1,1773 @@
1/*
2 * at91_udc -- driver for at91-series USB peripheral controller
3 *
4 * Copyright (C) 2004 by Thomas Rathbone
5 * Copyright (C) 2005 by HP Labs
6 * Copyright (C) 2005 by David Brownell
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
23
24#undef DEBUG
25#undef VERBOSE
26#undef PACKET_TRACE
27
28#include <linux/config.h>
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/platform_device.h>
32#include <linux/delay.h>
33#include <linux/ioport.h>
34#include <linux/sched.h>
35#include <linux/slab.h>
36#include <linux/smp_lock.h>
37#include <linux/errno.h>
38#include <linux/init.h>
39#include <linux/list.h>
40#include <linux/interrupt.h>
41#include <linux/proc_fs.h>
42#include <linux/clk.h>
43#include <linux/usb_ch9.h>
44#include <linux/usb_gadget.h>
45
46#include <asm/byteorder.h>
47#include <asm/io.h>
48#include <asm/irq.h>
49#include <asm/system.h>
50#include <asm/mach-types.h>
51
52#include <asm/arch/hardware.h>
53#include <asm/arch/gpio.h>
54#include <asm/arch/board.h>
55
56#include "at91_udc.h"
57
58
59/*
60 * This controller is simple and PIO-only. It's used in many AT91-series
61 * ARMv4T controllers, including the at91rm9200 (arm920T, with MMU),
62 * at91sam9261 (arm926ejs, with MMU), and several no-mmu versions.
63 *
64 * This driver expects the board has been wired with two GPIOs suppporting
65 * a VBUS sensing IRQ, and a D+ pullup. (They may be omitted, but the
66 * testing hasn't covered such cases.) The pullup is most important; it
67 * provides software control over whether the host enumerates the device.
68 * The VBUS sensing helps during enumeration, and allows both USB clocks
69 * (and the transceiver) to stay gated off until they're necessary, saving
70 * power. During USB suspend, the 48 MHz clock is gated off.
71 */
72
73#define DRIVER_VERSION "8 March 2005"
74
75static const char driver_name [] = "at91_udc";
76static const char ep0name[] = "ep0";
77
78/*-------------------------------------------------------------------------*/
79
80/*
81 * Read from a UDP register.
82 */
83static inline unsigned long at91_udp_read(unsigned int reg)
84{
85 void __iomem *udp_base = (void __iomem *)AT91_VA_BASE_UDP;
86
87 return __raw_readl(udp_base + reg);
88}
89
90/*
91 * Write to a UDP register.
92 */
93static inline void at91_udp_write(unsigned int reg, unsigned long value)
94{
95 void __iomem *udp_base = (void __iomem *)AT91_VA_BASE_UDP;
96
97 __raw_writel(value, udp_base + reg);
98}
99
100/*-------------------------------------------------------------------------*/
101
102#ifdef CONFIG_USB_GADGET_DEBUG_FILES
103
104#include <linux/seq_file.h>
105
106static const char debug_filename[] = "driver/udc";
107
108#define FOURBITS "%s%s%s%s"
109#define EIGHTBITS FOURBITS FOURBITS
110
111static void proc_ep_show(struct seq_file *s, struct at91_ep *ep)
112{
113 static char *types[] = {
114 "control", "out-iso", "out-bulk", "out-int",
115 "BOGUS", "in-iso", "in-bulk", "in-int"};
116
117 u32 csr;
118 struct at91_request *req;
119 unsigned long flags;
120
121 local_irq_save(flags);
122
123 csr = __raw_readl(ep->creg);
124
125 /* NOTE: not collecting per-endpoint irq statistics... */
126
127 seq_printf(s, "\n");
128 seq_printf(s, "%s, maxpacket %d %s%s %s%s\n",
129 ep->ep.name, ep->ep.maxpacket,
130 ep->is_in ? "in" : "out",
131 ep->is_iso ? " iso" : "",
132 ep->is_pingpong
133 ? (ep->fifo_bank ? "pong" : "ping")
134 : "",
135 ep->stopped ? " stopped" : "");
136 seq_printf(s, "csr %08x rxbytes=%d %s %s %s" EIGHTBITS "\n",
137 csr,
138 (csr & 0x07ff0000) >> 16,
139 (csr & (1 << 15)) ? "enabled" : "disabled",
140 (csr & (1 << 11)) ? "DATA1" : "DATA0",
141 types[(csr & 0x700) >> 8],
142
143 /* iff type is control then print current direction */
144 (!(csr & 0x700))
145 ? ((csr & (1 << 7)) ? " IN" : " OUT")
146 : "",
147 (csr & (1 << 6)) ? " rxdatabk1" : "",
148 (csr & (1 << 5)) ? " forcestall" : "",
149 (csr & (1 << 4)) ? " txpktrdy" : "",
150
151 (csr & (1 << 3)) ? " stallsent" : "",
152 (csr & (1 << 2)) ? " rxsetup" : "",
153 (csr & (1 << 1)) ? " rxdatabk0" : "",
154 (csr & (1 << 0)) ? " txcomp" : "");
155 if (list_empty (&ep->queue))
156 seq_printf(s, "\t(queue empty)\n");
157
158 else list_for_each_entry (req, &ep->queue, queue) {
159 unsigned length = req->req.actual;
160
161 seq_printf(s, "\treq %p len %d/%d buf %p\n",
162 &req->req, length,
163 req->req.length, req->req.buf);
164 }
165 local_irq_restore(flags);
166}
167
168static void proc_irq_show(struct seq_file *s, const char *label, u32 mask)
169{
170 int i;
171
172 seq_printf(s, "%s %04x:%s%s" FOURBITS, label, mask,
173 (mask & (1 << 13)) ? " wakeup" : "",
174 (mask & (1 << 12)) ? " endbusres" : "",
175
176 (mask & (1 << 11)) ? " sofint" : "",
177 (mask & (1 << 10)) ? " extrsm" : "",
178 (mask & (1 << 9)) ? " rxrsm" : "",
179 (mask & (1 << 8)) ? " rxsusp" : "");
180 for (i = 0; i < 8; i++) {
181 if (mask & (1 << i))
182 seq_printf(s, " ep%d", i);
183 }
184 seq_printf(s, "\n");
185}
186
187static int proc_udc_show(struct seq_file *s, void *unused)
188{
189 struct at91_udc *udc = s->private;
190 struct at91_ep *ep;
191 u32 tmp;
192
193 seq_printf(s, "%s: version %s\n", driver_name, DRIVER_VERSION);
194
195 seq_printf(s, "vbus %s, pullup %s, %s powered%s, gadget %s\n\n",
196 udc->vbus ? "present" : "off",
197 udc->enabled
198 ? (udc->vbus ? "active" : "enabled")
199 : "disabled",
200 udc->selfpowered ? "self" : "VBUS",
201 udc->suspended ? ", suspended" : "",
202 udc->driver ? udc->driver->driver.name : "(none)");
203
204 /* don't access registers when interface isn't clocked */
205 if (!udc->clocked) {
206 seq_printf(s, "(not clocked)\n");
207 return 0;
208 }
209
210 tmp = at91_udp_read(AT91_UDP_FRM_NUM);
211 seq_printf(s, "frame %05x:%s%s frame=%d\n", tmp,
212 (tmp & AT91_UDP_FRM_OK) ? " ok" : "",
213 (tmp & AT91_UDP_FRM_ERR) ? " err" : "",
214 (tmp & AT91_UDP_NUM));
215
216 tmp = at91_udp_read(AT91_UDP_GLB_STAT);
217 seq_printf(s, "glbstate %02x:%s" FOURBITS "\n", tmp,
218 (tmp & AT91_UDP_RMWUPE) ? " rmwupe" : "",
219 (tmp & AT91_UDP_RSMINPR) ? " rsminpr" : "",
220 (tmp & AT91_UDP_ESR) ? " esr" : "",
221 (tmp & AT91_UDP_CONFG) ? " confg" : "",
222 (tmp & AT91_UDP_FADDEN) ? " fadden" : "");
223
224 tmp = at91_udp_read(AT91_UDP_FADDR);
225 seq_printf(s, "faddr %03x:%s fadd=%d\n", tmp,
226 (tmp & AT91_UDP_FEN) ? " fen" : "",
227 (tmp & AT91_UDP_FADD));
228
229 proc_irq_show(s, "imr ", at91_udp_read(AT91_UDP_IMR));
230 proc_irq_show(s, "isr ", at91_udp_read(AT91_UDP_ISR));
231
232 if (udc->enabled && udc->vbus) {
233 proc_ep_show(s, &udc->ep[0]);
234 list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) {
235 if (ep->desc)
236 proc_ep_show(s, ep);
237 }
238 }
239 return 0;
240}
241
242static int proc_udc_open(struct inode *inode, struct file *file)
243{
244 return single_open(file, proc_udc_show, PDE(inode)->data);
245}
246
247static struct file_operations proc_ops = {
248 .open = proc_udc_open,
249 .read = seq_read,
250 .llseek = seq_lseek,
251 .release = single_release,
252};
253
254static void create_debug_file(struct at91_udc *udc)
255{
256 struct proc_dir_entry *pde;
257
258 pde = create_proc_entry (debug_filename, 0, NULL);
259 udc->pde = pde;
260 if (pde == NULL)
261 return;
262
263 pde->proc_fops = &proc_ops;
264 pde->data = udc;
265}
266
267static void remove_debug_file(struct at91_udc *udc)
268{
269 if (udc->pde)
270 remove_proc_entry(debug_filename, NULL);
271}
272
273#else
274
275static inline void create_debug_file(struct at91_udc *udc) {}
276static inline void remove_debug_file(struct at91_udc *udc) {}
277
278#endif
279
280
281/*-------------------------------------------------------------------------*/
282
283static void done(struct at91_ep *ep, struct at91_request *req, int status)
284{
285 unsigned stopped = ep->stopped;
286
287 list_del_init(&req->queue);
288 if (req->req.status == -EINPROGRESS)
289 req->req.status = status;
290 else
291 status = req->req.status;
292 if (status && status != -ESHUTDOWN)
293 VDBG("%s done %p, status %d\n", ep->ep.name, req, status);
294
295 ep->stopped = 1;
296 req->req.complete(&ep->ep, &req->req);
297 ep->stopped = stopped;
298
299 /* ep0 is always ready; other endpoints need a non-empty queue */
300 if (list_empty(&ep->queue) && ep->int_mask != (1 << 0))
301 at91_udp_write(AT91_UDP_IDR, ep->int_mask);
302}
303
304/*-------------------------------------------------------------------------*/
305
306/* bits indicating OUT fifo has data ready */
307#define RX_DATA_READY (AT91_UDP_RX_DATA_BK0 | AT91_UDP_RX_DATA_BK1)
308
309/*
310 * Endpoint FIFO CSR bits have a mix of bits, making it unsafe to just write
311 * back most of the value you just read (because of side effects, including
312 * bits that may change after reading and before writing).
313 *
314 * Except when changing a specific bit, always write values which:
315 * - clear SET_FX bits (setting them could change something)
316 * - set CLR_FX bits (clearing them could change something)
317 *
318 * There are also state bits like FORCESTALL, EPEDS, DIR, and EPTYPE
319 * that shouldn't normally be changed.
320 */
321#define SET_FX (AT91_UDP_TXPKTRDY)
322#define CLR_FX (RX_DATA_READY | AT91_UDP_RXSETUP | AT91_UDP_STALLSENT | AT91_UDP_TXCOMP)
323
324/* pull OUT packet data from the endpoint's fifo */
325static int read_fifo (struct at91_ep *ep, struct at91_request *req)
326{
327 u32 __iomem *creg = ep->creg;
328 u8 __iomem *dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0));
329 u32 csr;
330 u8 *buf;
331 unsigned int count, bufferspace, is_done;
332
333 buf = req->req.buf + req->req.actual;
334 bufferspace = req->req.length - req->req.actual;
335
336 /*
337 * there might be nothing to read if ep_queue() calls us,
338 * or if we already emptied both pingpong buffers
339 */
340rescan:
341 csr = __raw_readl(creg);
342 if ((csr & RX_DATA_READY) == 0)
343 return 0;
344
345 count = (csr & AT91_UDP_RXBYTECNT) >> 16;
346 if (count > ep->ep.maxpacket)
347 count = ep->ep.maxpacket;
348 if (count > bufferspace) {
349 DBG("%s buffer overflow\n", ep->ep.name);
350 req->req.status = -EOVERFLOW;
351 count = bufferspace;
352 }
353 __raw_readsb(dreg, buf, count);
354
355 /* release and swap pingpong mem bank */
356 csr |= CLR_FX;
357 if (ep->is_pingpong) {
358 if (ep->fifo_bank == 0) {
359 csr &= ~(SET_FX | AT91_UDP_RX_DATA_BK0);
360 ep->fifo_bank = 1;
361 } else {
362 csr &= ~(SET_FX | AT91_UDP_RX_DATA_BK1);
363 ep->fifo_bank = 0;
364 }
365 } else
366 csr &= ~(SET_FX | AT91_UDP_RX_DATA_BK0);
367 __raw_writel(csr, creg);
368
369 req->req.actual += count;
370 is_done = (count < ep->ep.maxpacket);
371 if (count == bufferspace)
372 is_done = 1;
373
374 PACKET("%s %p out/%d%s\n", ep->ep.name, &req->req, count,
375 is_done ? " (done)" : "");
376
377 /*
378 * avoid extra trips through IRQ logic for packets already in
379 * the fifo ... maybe preventing an extra (expensive) OUT-NAK
380 */
381 if (is_done)
382 done(ep, req, 0);
383 else if (ep->is_pingpong) {
384 bufferspace -= count;
385 buf += count;
386 goto rescan;
387 }
388
389 return is_done;
390}
391
392/* load fifo for an IN packet */
393static int write_fifo(struct at91_ep *ep, struct at91_request *req)
394{
395 u32 __iomem *creg = ep->creg;
396 u32 csr = __raw_readl(creg);
397 u8 __iomem *dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0));
398 unsigned total, count, is_last;
399
400 /*
401 * TODO: allow for writing two packets to the fifo ... that'll
402 * reduce the amount of IN-NAKing, but probably won't affect
403 * throughput much. (Unlike preventing OUT-NAKing!)
404 */
405
406 /*
407 * If ep_queue() calls us, the queue is empty and possibly in
408 * odd states like TXCOMP not yet cleared (we do it, saving at
409 * least one IRQ) or the fifo not yet being free. Those aren't
410 * issues normally (IRQ handler fast path).
411 */
412 if (unlikely(csr & (AT91_UDP_TXCOMP | AT91_UDP_TXPKTRDY))) {
413 if (csr & AT91_UDP_TXCOMP) {
414 csr |= CLR_FX;
415 csr &= ~(SET_FX | AT91_UDP_TXCOMP);
416 __raw_writel(csr, creg);
417 csr = __raw_readl(creg);
418 }
419 if (csr & AT91_UDP_TXPKTRDY)
420 return 0;
421 }
422
423 total = req->req.length - req->req.actual;
424 if (ep->ep.maxpacket < total) {
425 count = ep->ep.maxpacket;
426 is_last = 0;
427 } else {
428 count = total;
429 is_last = (count < ep->ep.maxpacket) || !req->req.zero;
430 }
431
432 /*
433 * Write the packet, maybe it's a ZLP.
434 *
435 * NOTE: incrementing req->actual before we receive the ACK means
436 * gadget driver IN bytecounts can be wrong in fault cases. That's
437 * fixable with PIO drivers like this one (save "count" here, and
438 * do the increment later on TX irq), but not for most DMA hardware.
439 *
440 * So all gadget drivers must accept that potential error. Some
441 * hardware supports precise fifo status reporting, letting them
442 * recover when the actual bytecount matters (e.g. for USB Test
443 * and Measurement Class devices).
444 */
445 __raw_writesb(dreg, req->req.buf + req->req.actual, count);
446 csr &= ~SET_FX;
447 csr |= CLR_FX | AT91_UDP_TXPKTRDY;
448 __raw_writel(csr, creg);
449 req->req.actual += count;
450
451 PACKET("%s %p in/%d%s\n", ep->ep.name, &req->req, count,
452 is_last ? " (done)" : "");
453 if (is_last)
454 done(ep, req, 0);
455 return is_last;
456}
457
458static void nuke(struct at91_ep *ep, int status)
459{
460 struct at91_request *req;
461
462 // terminer chaque requete dans la queue
463 ep->stopped = 1;
464 if (list_empty(&ep->queue))
465 return;
466
467 VDBG("%s %s\n", __FUNCTION__, ep->ep.name);
468 while (!list_empty(&ep->queue)) {
469 req = list_entry(ep->queue.next, struct at91_request, queue);
470 done(ep, req, status);
471 }
472}
473
474/*-------------------------------------------------------------------------*/
475
476static int at91_ep_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
477{
478 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep);
479 struct at91_udc *dev = ep->udc;
480 u16 maxpacket;
481 u32 tmp;
482 unsigned long flags;
483
484 if (!_ep || !ep
485 || !desc || ep->desc
486 || _ep->name == ep0name
487 || desc->bDescriptorType != USB_DT_ENDPOINT
488 || (maxpacket = le16_to_cpu(desc->wMaxPacketSize)) == 0
489 || maxpacket > ep->maxpacket) {
490 DBG("bad ep or descriptor\n");
491 return -EINVAL;
492 }
493
494 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
495 DBG("bogus device state\n");
496 return -ESHUTDOWN;
497 }
498
499 tmp = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
500 switch (tmp) {
501 case USB_ENDPOINT_XFER_CONTROL:
502 DBG("only one control endpoint\n");
503 return -EINVAL;
504 case USB_ENDPOINT_XFER_INT:
505 if (maxpacket > 64)
506 goto bogus_max;
507 break;
508 case USB_ENDPOINT_XFER_BULK:
509 switch (maxpacket) {
510 case 8:
511 case 16:
512 case 32:
513 case 64:
514 goto ok;
515 }
516bogus_max:
517 DBG("bogus maxpacket %d\n", maxpacket);
518 return -EINVAL;
519 case USB_ENDPOINT_XFER_ISOC:
520 if (!ep->is_pingpong) {
521 DBG("iso requires double buffering\n");
522 return -EINVAL;
523 }
524 break;
525 }
526
527ok:
528 local_irq_save(flags);
529
530 /* initialize endpoint to match this descriptor */
531 ep->is_in = (desc->bEndpointAddress & USB_DIR_IN) != 0;
532 ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC);
533 ep->stopped = 0;
534 if (ep->is_in)
535 tmp |= 0x04;
536 tmp <<= 8;
537 tmp |= AT91_UDP_EPEDS;
538 __raw_writel(tmp, ep->creg);
539
540 ep->desc = desc;
541 ep->ep.maxpacket = maxpacket;
542
543 /*
544 * reset/init endpoint fifo. NOTE: leaves fifo_bank alone,
545 * since endpoint resets don't reset hw pingpong state.
546 */
547 at91_udp_write(AT91_UDP_RST_EP, ep->int_mask);
548 at91_udp_write(AT91_UDP_RST_EP, 0);
549
550 local_irq_restore(flags);
551 return 0;
552}
553
554static int at91_ep_disable (struct usb_ep * _ep)
555{
556 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep);
557 unsigned long flags;
558
559 if (ep == &ep->udc->ep[0])
560 return -EINVAL;
561
562 local_irq_save(flags);
563
564 nuke(ep, -ESHUTDOWN);
565
566 /* restore the endpoint's pristine config */
567 ep->desc = NULL;
568 ep->ep.maxpacket = ep->maxpacket;
569
570 /* reset fifos and endpoint */
571 if (ep->udc->clocked) {
572 at91_udp_write(AT91_UDP_RST_EP, ep->int_mask);
573 at91_udp_write(AT91_UDP_RST_EP, 0);
574 __raw_writel(0, ep->creg);
575 }
576
577 local_irq_restore(flags);
578 return 0;
579}
580
581/*
582 * this is a PIO-only driver, so there's nothing
583 * interesting for request or buffer allocation.
584 */
585
586static struct usb_request *at91_ep_alloc_request (struct usb_ep *_ep, unsigned int gfp_flags)
587{
588 struct at91_request *req;
589
590 req = kcalloc(1, sizeof (struct at91_request), SLAB_KERNEL);
591 if (!req)
592 return NULL;
593
594 INIT_LIST_HEAD(&req->queue);
595 return &req->req;
596}
597
598static void at91_ep_free_request(struct usb_ep *_ep, struct usb_request *_req)
599{
600 struct at91_request *req;
601
602 req = container_of(_req, struct at91_request, req);
603 BUG_ON(!list_empty(&req->queue));
604 kfree(req);
605}
606
607static void *at91_ep_alloc_buffer(
608 struct usb_ep *_ep,
609 unsigned bytes,
610 dma_addr_t *dma,
611 gfp_t gfp_flags)
612{
613 *dma = ~0;
614 return kmalloc(bytes, gfp_flags);
615}
616
617static void at91_ep_free_buffer(
618 struct usb_ep *ep,
619 void *buf,
620 dma_addr_t dma,
621 unsigned bytes)
622{
623 kfree(buf);
624}
625
626static int at91_ep_queue(struct usb_ep *_ep,
627 struct usb_request *_req, gfp_t gfp_flags)
628{
629 struct at91_request *req;
630 struct at91_ep *ep;
631 struct at91_udc *dev;
632 int status;
633 unsigned long flags;
634
635 req = container_of(_req, struct at91_request, req);
636 ep = container_of(_ep, struct at91_ep, ep);
637
638 if (!_req || !_req->complete
639 || !_req->buf || !list_empty(&req->queue)) {
640 DBG("invalid request\n");
641 return -EINVAL;
642 }
643
644 if (!_ep || (!ep->desc && ep->ep.name != ep0name)) {
645 DBG("invalid ep\n");
646 return -EINVAL;
647 }
648
649 dev = ep->udc;
650
651 if (!dev || !dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
652 DBG("invalid device\n");
653 return -EINVAL;
654 }
655
656 _req->status = -EINPROGRESS;
657 _req->actual = 0;
658
659 local_irq_save(flags);
660
661 /* try to kickstart any empty and idle queue */
662 if (list_empty(&ep->queue) && !ep->stopped) {
663 int is_ep0;
664
665 /*
666 * If this control request has a non-empty DATA stage, this
667 * will start that stage. It works just like a non-control
668 * request (until the status stage starts, maybe early).
669 *
670 * If the data stage is empty, then this starts a successful
671 * IN/STATUS stage. (Unsuccessful ones use set_halt.)
672 */
673 is_ep0 = (ep->ep.name == ep0name);
674 if (is_ep0) {
675 u32 tmp;
676
677 if (!dev->req_pending) {
678 status = -EINVAL;
679 goto done;
680 }
681
682 /*
683 * defer changing CONFG until after the gadget driver
684 * reconfigures the endpoints.
685 */
686 if (dev->wait_for_config_ack) {
687 tmp = at91_udp_read(AT91_UDP_GLB_STAT);
688 tmp ^= AT91_UDP_CONFG;
689 VDBG("toggle config\n");
690 at91_udp_write(AT91_UDP_GLB_STAT, tmp);
691 }
692 if (req->req.length == 0) {
693ep0_in_status:
694 PACKET("ep0 in/status\n");
695 status = 0;
696 tmp = __raw_readl(ep->creg);
697 tmp &= ~SET_FX;
698 tmp |= CLR_FX | AT91_UDP_TXPKTRDY;
699 __raw_writel(tmp, ep->creg);
700 dev->req_pending = 0;
701 goto done;
702 }
703 }
704
705 if (ep->is_in)
706 status = write_fifo(ep, req);
707 else {
708 status = read_fifo(ep, req);
709
710 /* IN/STATUS stage is otherwise triggered by irq */
711 if (status && is_ep0)
712 goto ep0_in_status;
713 }
714 } else
715 status = 0;
716
717 if (req && !status) {
718 list_add_tail (&req->queue, &ep->queue);
719 at91_udp_write(AT91_UDP_IER, ep->int_mask);
720 }
721done:
722 local_irq_restore(flags);
723 return (status < 0) ? status : 0;
724}
725
726static int at91_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
727{
728 struct at91_ep *ep;
729 struct at91_request *req;
730
731 ep = container_of(_ep, struct at91_ep, ep);
732 if (!_ep || ep->ep.name == ep0name)
733 return -EINVAL;
734
735 /* make sure it's actually queued on this endpoint */
736 list_for_each_entry (req, &ep->queue, queue) {
737 if (&req->req == _req)
738 break;
739 }
740 if (&req->req != _req)
741 return -EINVAL;
742
743 done(ep, req, -ECONNRESET);
744 return 0;
745}
746
747static int at91_ep_set_halt(struct usb_ep *_ep, int value)
748{
749 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep);
750 u32 __iomem *creg;
751 u32 csr;
752 unsigned long flags;
753 int status = 0;
754
755 if (!_ep || ep->is_iso || !ep->udc->clocked)
756 return -EINVAL;
757
758 creg = ep->creg;
759 local_irq_save(flags);
760
761 csr = __raw_readl(creg);
762
763 /*
764 * fail with still-busy IN endpoints, ensuring correct sequencing
765 * of data tx then stall. note that the fifo rx bytecount isn't
766 * completely accurate as a tx bytecount.
767 */
768 if (ep->is_in && (!list_empty(&ep->queue) || (csr >> 16) != 0))
769 status = -EAGAIN;
770 else {
771 csr |= CLR_FX;
772 csr &= ~SET_FX;
773 if (value) {
774 csr |= AT91_UDP_FORCESTALL;
775 VDBG("halt %s\n", ep->ep.name);
776 } else {
777 at91_udp_write(AT91_UDP_RST_EP, ep->int_mask);
778 at91_udp_write(AT91_UDP_RST_EP, 0);
779 csr &= ~AT91_UDP_FORCESTALL;
780 }
781 __raw_writel(csr, creg);
782 }
783
784 local_irq_restore(flags);
785 return status;
786}
787
788static struct usb_ep_ops at91_ep_ops = {
789 .enable = at91_ep_enable,
790 .disable = at91_ep_disable,
791 .alloc_request = at91_ep_alloc_request,
792 .free_request = at91_ep_free_request,
793 .alloc_buffer = at91_ep_alloc_buffer,
794 .free_buffer = at91_ep_free_buffer,
795 .queue = at91_ep_queue,
796 .dequeue = at91_ep_dequeue,
797 .set_halt = at91_ep_set_halt,
798 // there's only imprecise fifo status reporting
799};
800
801/*-------------------------------------------------------------------------*/
802
803static int at91_get_frame(struct usb_gadget *gadget)
804{
805 if (!to_udc(gadget)->clocked)
806 return -EINVAL;
807 return at91_udp_read(AT91_UDP_FRM_NUM) & AT91_UDP_NUM;
808}
809
810static int at91_wakeup(struct usb_gadget *gadget)
811{
812 struct at91_udc *udc = to_udc(gadget);
813 u32 glbstate;
814 int status = -EINVAL;
815 unsigned long flags;
816
817 DBG("%s\n", __FUNCTION__ );
818 local_irq_save(flags);
819
820 if (!udc->clocked || !udc->suspended)
821 goto done;
822
823 /* NOTE: some "early versions" handle ESR differently ... */
824
825 glbstate = at91_udp_read(AT91_UDP_GLB_STAT);
826 if (!(glbstate & AT91_UDP_ESR))
827 goto done;
828 glbstate |= AT91_UDP_ESR;
829 at91_udp_write(AT91_UDP_GLB_STAT, glbstate);
830
831done:
832 local_irq_restore(flags);
833 return status;
834}
835
836/* reinit == restore inital software state */
837static void udc_reinit(struct at91_udc *udc)
838{
839 u32 i;
840
841 INIT_LIST_HEAD(&udc->gadget.ep_list);
842 INIT_LIST_HEAD(&udc->gadget.ep0->ep_list);
843
844 for (i = 0; i < NUM_ENDPOINTS; i++) {
845 struct at91_ep *ep = &udc->ep[i];
846
847 if (i != 0)
848 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
849 ep->desc = NULL;
850 ep->stopped = 0;
851 ep->fifo_bank = 0;
852 ep->ep.maxpacket = ep->maxpacket;
853 // initialiser une queue par endpoint
854 INIT_LIST_HEAD(&ep->queue);
855 }
856}
857
858static void stop_activity(struct at91_udc *udc)
859{
860 struct usb_gadget_driver *driver = udc->driver;
861 int i;
862
863 if (udc->gadget.speed == USB_SPEED_UNKNOWN)
864 driver = NULL;
865 udc->gadget.speed = USB_SPEED_UNKNOWN;
866
867 for (i = 0; i < NUM_ENDPOINTS; i++) {
868 struct at91_ep *ep = &udc->ep[i];
869 ep->stopped = 1;
870 nuke(ep, -ESHUTDOWN);
871 }
872 if (driver)
873 driver->disconnect(&udc->gadget);
874
875 udc_reinit(udc);
876}
877
878static void clk_on(struct at91_udc *udc)
879{
880 if (udc->clocked)
881 return;
882 udc->clocked = 1;
883 clk_enable(udc->iclk);
884 clk_enable(udc->fclk);
885}
886
887static void clk_off(struct at91_udc *udc)
888{
889 if (!udc->clocked)
890 return;
891 udc->clocked = 0;
892 udc->gadget.speed = USB_SPEED_UNKNOWN;
893 clk_disable(udc->iclk);
894 clk_disable(udc->fclk);
895}
896
897/*
898 * activate/deactivate link with host; minimize power usage for
899 * inactive links by cutting clocks and transceiver power.
900 */
901static void pullup(struct at91_udc *udc, int is_on)
902{
903 if (!udc->enabled || !udc->vbus)
904 is_on = 0;
905 DBG("%sactive\n", is_on ? "" : "in");
906 if (is_on) {
907 clk_on(udc);
908 at91_udp_write(AT91_UDP_TXVC, 0);
909 at91_set_gpio_value(udc->board.pullup_pin, 1);
910 } else {
911 stop_activity(udc);
912 at91_udp_write(AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
913 at91_set_gpio_value(udc->board.pullup_pin, 0);
914 clk_off(udc);
915
916 // REVISIT: with transceiver disabled, will D- float
917 // so that a host would falsely detect a device?
918 }
919}
920
921/* vbus is here! turn everything on that's ready */
922static int at91_vbus_session(struct usb_gadget *gadget, int is_active)
923{
924 struct at91_udc *udc = to_udc(gadget);
925 unsigned long flags;
926
927 // VDBG("vbus %s\n", is_active ? "on" : "off");
928 local_irq_save(flags);
929 udc->vbus = (is_active != 0);
930 pullup(udc, is_active);
931 local_irq_restore(flags);
932 return 0;
933}
934
935static int at91_pullup(struct usb_gadget *gadget, int is_on)
936{
937 struct at91_udc *udc = to_udc(gadget);
938 unsigned long flags;
939
940 local_irq_save(flags);
941 udc->enabled = is_on = !!is_on;
942 pullup(udc, is_on);
943 local_irq_restore(flags);
944 return 0;
945}
946
947static int at91_set_selfpowered(struct usb_gadget *gadget, int is_on)
948{
949 struct at91_udc *udc = to_udc(gadget);
950 unsigned long flags;
951
952 local_irq_save(flags);
953 udc->selfpowered = (is_on != 0);
954 local_irq_restore(flags);
955 return 0;
956}
957
958static const struct usb_gadget_ops at91_udc_ops = {
959 .get_frame = at91_get_frame,
960 .wakeup = at91_wakeup,
961 .set_selfpowered = at91_set_selfpowered,
962 .vbus_session = at91_vbus_session,
963 .pullup = at91_pullup,
964
965 /*
966 * VBUS-powered devices may also also want to support bigger
967 * power budgets after an appropriate SET_CONFIGURATION.
968 */
969 // .vbus_power = at91_vbus_power,
970};
971
972/*-------------------------------------------------------------------------*/
973
974static int handle_ep(struct at91_ep *ep)
975{
976 struct at91_request *req;
977 u32 __iomem *creg = ep->creg;
978 u32 csr = __raw_readl(creg);
979
980 if (!list_empty(&ep->queue))
981 req = list_entry(ep->queue.next,
982 struct at91_request, queue);
983 else
984 req = NULL;
985
986 if (ep->is_in) {
987 if (csr & (AT91_UDP_STALLSENT | AT91_UDP_TXCOMP)) {
988 csr |= CLR_FX;
989 csr &= ~(SET_FX | AT91_UDP_STALLSENT | AT91_UDP_TXCOMP);
990 __raw_writel(csr, creg);
991 }
992 if (req)
993 return write_fifo(ep, req);
994
995 } else {
996 if (csr & AT91_UDP_STALLSENT) {
997 /* STALLSENT bit == ISOERR */
998 if (ep->is_iso && req)
999 req->req.status = -EILSEQ;
1000 csr |= CLR_FX;
1001 csr &= ~(SET_FX | AT91_UDP_STALLSENT);
1002 __raw_writel(csr, creg);
1003 csr = __raw_readl(creg);
1004 }
1005 if (req && (csr & RX_DATA_READY))
1006 return read_fifo(ep, req);
1007 }
1008 return 0;
1009}
1010
1011union setup {
1012 u8 raw[8];
1013 struct usb_ctrlrequest r;
1014};
1015
1016static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1017{
1018 u32 __iomem *creg = ep->creg;
1019 u8 __iomem *dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0));
1020 unsigned rxcount, i = 0;
1021 u32 tmp;
1022 union setup pkt;
1023 int status = 0;
1024
1025 /* read and ack SETUP; hard-fail for bogus packets */
1026 rxcount = (csr & AT91_UDP_RXBYTECNT) >> 16;
1027 if (likely(rxcount == 8)) {
1028 while (rxcount--)
1029 pkt.raw[i++] = __raw_readb(dreg);
1030 if (pkt.r.bRequestType & USB_DIR_IN) {
1031 csr |= AT91_UDP_DIR;
1032 ep->is_in = 1;
1033 } else {
1034 csr &= ~AT91_UDP_DIR;
1035 ep->is_in = 0;
1036 }
1037 } else {
1038 // REVISIT this happens sometimes under load; why??
1039 ERR("SETUP len %d, csr %08x\n", rxcount, csr);
1040 status = -EINVAL;
1041 }
1042 csr |= CLR_FX;
1043 csr &= ~(SET_FX | AT91_UDP_RXSETUP);
1044 __raw_writel(csr, creg);
1045 udc->wait_for_addr_ack = 0;
1046 udc->wait_for_config_ack = 0;
1047 ep->stopped = 0;
1048 if (unlikely(status != 0))
1049 goto stall;
1050
1051#define w_index le16_to_cpu(pkt.r.wIndex)
1052#define w_value le16_to_cpu(pkt.r.wValue)
1053#define w_length le16_to_cpu(pkt.r.wLength)
1054
1055 VDBG("SETUP %02x.%02x v%04x i%04x l%04x\n",
1056 pkt.r.bRequestType, pkt.r.bRequest,
1057 w_value, w_index, w_length);
1058
1059 /*
1060 * A few standard requests get handled here, ones that touch
1061 * hardware ... notably for device and endpoint features.
1062 */
1063 udc->req_pending = 1;
1064 csr = __raw_readl(creg);
1065 csr |= CLR_FX;
1066 csr &= ~SET_FX;
1067 switch ((pkt.r.bRequestType << 8) | pkt.r.bRequest) {
1068
1069 case ((USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8)
1070 | USB_REQ_SET_ADDRESS:
1071 __raw_writel(csr | AT91_UDP_TXPKTRDY, creg);
1072 udc->addr = w_value;
1073 udc->wait_for_addr_ack = 1;
1074 udc->req_pending = 0;
1075 /* FADDR is set later, when we ack host STATUS */
1076 return;
1077
1078 case ((USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8)
1079 | USB_REQ_SET_CONFIGURATION:
1080 tmp = at91_udp_read(AT91_UDP_GLB_STAT) & AT91_UDP_CONFG;
1081 if (pkt.r.wValue)
1082 udc->wait_for_config_ack = (tmp == 0);
1083 else
1084 udc->wait_for_config_ack = (tmp != 0);
1085 if (udc->wait_for_config_ack)
1086 VDBG("wait for config\n");
1087 /* CONFG is toggled later, if gadget driver succeeds */
1088 break;
1089
1090 /*
1091 * Hosts may set or clear remote wakeup status, and
1092 * devices may report they're VBUS powered.
1093 */
1094 case ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8)
1095 | USB_REQ_GET_STATUS:
1096 tmp = (udc->selfpowered << USB_DEVICE_SELF_POWERED);
1097 if (at91_udp_read(AT91_UDP_GLB_STAT) & AT91_UDP_ESR)
1098 tmp |= (1 << USB_DEVICE_REMOTE_WAKEUP);
1099 PACKET("get device status\n");
1100 __raw_writeb(tmp, dreg);
1101 __raw_writeb(0, dreg);
1102 goto write_in;
1103 /* then STATUS starts later, automatically */
1104 case ((USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8)
1105 | USB_REQ_SET_FEATURE:
1106 if (w_value != USB_DEVICE_REMOTE_WAKEUP)
1107 goto stall;
1108 tmp = at91_udp_read(AT91_UDP_GLB_STAT);
1109 tmp |= AT91_UDP_ESR;
1110 at91_udp_write(AT91_UDP_GLB_STAT, tmp);
1111 goto succeed;
1112 case ((USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8)
1113 | USB_REQ_CLEAR_FEATURE:
1114 if (w_value != USB_DEVICE_REMOTE_WAKEUP)
1115 goto stall;
1116 tmp = at91_udp_read(AT91_UDP_GLB_STAT);
1117 tmp &= ~AT91_UDP_ESR;
1118 at91_udp_write(AT91_UDP_GLB_STAT, tmp);
1119 goto succeed;
1120
1121 /*
1122 * Interfaces have no feature settings; this is pretty useless.
1123 * we won't even insist the interface exists...
1124 */
1125 case ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE) << 8)
1126 | USB_REQ_GET_STATUS:
1127 PACKET("get interface status\n");
1128 __raw_writeb(0, dreg);
1129 __raw_writeb(0, dreg);
1130 goto write_in;
1131 /* then STATUS starts later, automatically */
1132 case ((USB_TYPE_STANDARD|USB_RECIP_INTERFACE) << 8)
1133 | USB_REQ_SET_FEATURE:
1134 case ((USB_TYPE_STANDARD|USB_RECIP_INTERFACE) << 8)
1135 | USB_REQ_CLEAR_FEATURE:
1136 goto stall;
1137
1138 /*
1139 * Hosts may clear bulk/intr endpoint halt after the gadget
1140 * driver sets it (not widely used); or set it (for testing)
1141 */
1142 case ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT) << 8)
1143 | USB_REQ_GET_STATUS:
1144 tmp = w_index & USB_ENDPOINT_NUMBER_MASK;
1145 ep = &udc->ep[tmp];
1146 if (tmp > NUM_ENDPOINTS || (tmp && !ep->desc))
1147 goto stall;
1148
1149 if (tmp) {
1150 if ((w_index & USB_DIR_IN)) {
1151 if (!ep->is_in)
1152 goto stall;
1153 } else if (ep->is_in)
1154 goto stall;
1155 }
1156 PACKET("get %s status\n", ep->ep.name);
1157 if (__raw_readl(ep->creg) & AT91_UDP_FORCESTALL)
1158 tmp = (1 << USB_ENDPOINT_HALT);
1159 else
1160 tmp = 0;
1161 __raw_writeb(tmp, dreg);
1162 __raw_writeb(0, dreg);
1163 goto write_in;
1164 /* then STATUS starts later, automatically */
1165 case ((USB_TYPE_STANDARD|USB_RECIP_ENDPOINT) << 8)
1166 | USB_REQ_SET_FEATURE:
1167 tmp = w_index & USB_ENDPOINT_NUMBER_MASK;
1168 ep = &udc->ep[tmp];
1169 if (w_value != USB_ENDPOINT_HALT || tmp > NUM_ENDPOINTS)
1170 goto stall;
1171 if (!ep->desc || ep->is_iso)
1172 goto stall;
1173 if ((w_index & USB_DIR_IN)) {
1174 if (!ep->is_in)
1175 goto stall;
1176 } else if (ep->is_in)
1177 goto stall;
1178
1179 tmp = __raw_readl(ep->creg);
1180 tmp &= ~SET_FX;
1181 tmp |= CLR_FX | AT91_UDP_FORCESTALL;
1182 __raw_writel(tmp, ep->creg);
1183 goto succeed;
1184 case ((USB_TYPE_STANDARD|USB_RECIP_ENDPOINT) << 8)
1185 | USB_REQ_CLEAR_FEATURE:
1186 tmp = w_index & USB_ENDPOINT_NUMBER_MASK;
1187 ep = &udc->ep[tmp];
1188 if (w_value != USB_ENDPOINT_HALT || tmp > NUM_ENDPOINTS)
1189 goto stall;
1190 if (tmp == 0)
1191 goto succeed;
1192 if (!ep->desc || ep->is_iso)
1193 goto stall;
1194 if ((w_index & USB_DIR_IN)) {
1195 if (!ep->is_in)
1196 goto stall;
1197 } else if (ep->is_in)
1198 goto stall;
1199
1200 at91_udp_write(AT91_UDP_RST_EP, ep->int_mask);
1201 at91_udp_write(AT91_UDP_RST_EP, 0);
1202 tmp = __raw_readl(ep->creg);
1203 tmp |= CLR_FX;
1204 tmp &= ~(SET_FX | AT91_UDP_FORCESTALL);
1205 __raw_writel(tmp, ep->creg);
1206 if (!list_empty(&ep->queue))
1207 handle_ep(ep);
1208 goto succeed;
1209 }
1210
1211#undef w_value
1212#undef w_index
1213#undef w_length
1214
1215 /* pass request up to the gadget driver */
1216 status = udc->driver->setup(&udc->gadget, &pkt.r);
1217 if (status < 0) {
1218stall:
1219 VDBG("req %02x.%02x protocol STALL; stat %d\n",
1220 pkt.r.bRequestType, pkt.r.bRequest, status);
1221 csr |= AT91_UDP_FORCESTALL;
1222 __raw_writel(csr, creg);
1223 udc->req_pending = 0;
1224 }
1225 return;
1226
1227succeed:
1228 /* immediate successful (IN) STATUS after zero length DATA */
1229 PACKET("ep0 in/status\n");
1230write_in:
1231 csr |= AT91_UDP_TXPKTRDY;
1232 __raw_writel(csr, creg);
1233 udc->req_pending = 0;
1234 return;
1235}
1236
1237static void handle_ep0(struct at91_udc *udc)
1238{
1239 struct at91_ep *ep0 = &udc->ep[0];
1240 u32 __iomem *creg = ep0->creg;
1241 u32 csr = __raw_readl(creg);
1242 struct at91_request *req;
1243
1244 if (unlikely(csr & AT91_UDP_STALLSENT)) {
1245 nuke(ep0, -EPROTO);
1246 udc->req_pending = 0;
1247 csr |= CLR_FX;
1248 csr &= ~(SET_FX | AT91_UDP_STALLSENT | AT91_UDP_FORCESTALL);
1249 __raw_writel(csr, creg);
1250 VDBG("ep0 stalled\n");
1251 csr = __raw_readl(creg);
1252 }
1253 if (csr & AT91_UDP_RXSETUP) {
1254 nuke(ep0, 0);
1255 udc->req_pending = 0;
1256 handle_setup(udc, ep0, csr);
1257 return;
1258 }
1259
1260 if (list_empty(&ep0->queue))
1261 req = NULL;
1262 else
1263 req = list_entry(ep0->queue.next, struct at91_request, queue);
1264
1265 /* host ACKed an IN packet that we sent */
1266 if (csr & AT91_UDP_TXCOMP) {
1267 csr |= CLR_FX;
1268 csr &= ~(SET_FX | AT91_UDP_TXCOMP);
1269
1270 /* write more IN DATA? */
1271 if (req && ep0->is_in) {
1272 if (handle_ep(ep0))
1273 udc->req_pending = 0;
1274
1275 /*
1276 * Ack after:
1277 * - last IN DATA packet (including GET_STATUS)
1278 * - IN/STATUS for OUT DATA
1279 * - IN/STATUS for any zero-length DATA stage
1280 * except for the IN DATA case, the host should send
1281 * an OUT status later, which we'll ack.
1282 */
1283 } else {
1284 udc->req_pending = 0;
1285 __raw_writel(csr, creg);
1286
1287 /*
1288 * SET_ADDRESS takes effect only after the STATUS
1289 * (to the original address) gets acked.
1290 */
1291 if (udc->wait_for_addr_ack) {
1292 u32 tmp;
1293
1294 at91_udp_write(AT91_UDP_FADDR, AT91_UDP_FEN | udc->addr);
1295 tmp = at91_udp_read(AT91_UDP_GLB_STAT);
1296 tmp &= ~AT91_UDP_FADDEN;
1297 if (udc->addr)
1298 tmp |= AT91_UDP_FADDEN;
1299 at91_udp_write(AT91_UDP_GLB_STAT, tmp);
1300
1301 udc->wait_for_addr_ack = 0;
1302 VDBG("address %d\n", udc->addr);
1303 }
1304 }
1305 }
1306
1307 /* OUT packet arrived ... */
1308 else if (csr & AT91_UDP_RX_DATA_BK0) {
1309 csr |= CLR_FX;
1310 csr &= ~(SET_FX | AT91_UDP_RX_DATA_BK0);
1311
1312 /* OUT DATA stage */
1313 if (!ep0->is_in) {
1314 if (req) {
1315 if (handle_ep(ep0)) {
1316 /* send IN/STATUS */
1317 PACKET("ep0 in/status\n");
1318 csr = __raw_readl(creg);
1319 csr &= ~SET_FX;
1320 csr |= CLR_FX | AT91_UDP_TXPKTRDY;
1321 __raw_writel(csr, creg);
1322 udc->req_pending = 0;
1323 }
1324 } else if (udc->req_pending) {
1325 /*
1326 * AT91 hardware has a hard time with this
1327 * "deferred response" mode for control-OUT
1328 * transfers. (For control-IN it's fine.)
1329 *
1330 * The normal solution leaves OUT data in the
1331 * fifo until the gadget driver is ready.
1332 * We couldn't do that here without disabling
1333 * the IRQ that tells about SETUP packets,
1334 * e.g. when the host gets impatient...
1335 *
1336 * Working around it by copying into a buffer
1337 * would almost be a non-deferred response,
1338 * except that it wouldn't permit reliable
1339 * stalling of the request. Instead, demand
1340 * that gadget drivers not use this mode.
1341 */
1342 DBG("no control-OUT deferred responses!\n");
1343 __raw_writel(csr | AT91_UDP_FORCESTALL, creg);
1344 udc->req_pending = 0;
1345 }
1346
1347 /* STATUS stage for control-IN; ack. */
1348 } else {
1349 PACKET("ep0 out/status ACK\n");
1350 __raw_writel(csr, creg);
1351
1352 /* "early" status stage */
1353 if (req)
1354 done(ep0, req, 0);
1355 }
1356 }
1357}
1358
1359static irqreturn_t at91_udc_irq (int irq, void *_udc, struct pt_regs *r)
1360{
1361 struct at91_udc *udc = _udc;
1362 u32 rescans = 5;
1363
1364 while (rescans--) {
1365 u32 status = at91_udp_read(AT91_UDP_ISR);
1366
1367 status &= at91_udp_read(AT91_UDP_IMR);
1368 if (!status)
1369 break;
1370
1371 /* USB reset irq: not maskable */
1372 if (status & AT91_UDP_ENDBUSRES) {
1373 at91_udp_write(AT91_UDP_IDR, ~MINIMUS_INTERRUPTUS);
1374 at91_udp_write(AT91_UDP_IER, MINIMUS_INTERRUPTUS);
1375 /* Atmel code clears this irq twice */
1376 at91_udp_write(AT91_UDP_ICR, AT91_UDP_ENDBUSRES);
1377 at91_udp_write(AT91_UDP_ICR, AT91_UDP_ENDBUSRES);
1378 VDBG("end bus reset\n");
1379 udc->addr = 0;
1380 stop_activity(udc);
1381
1382 /* enable ep0 */
1383 at91_udp_write(AT91_UDP_CSR(0), AT91_UDP_EPEDS | AT91_UDP_EPTYPE_CTRL);
1384 udc->gadget.speed = USB_SPEED_FULL;
1385 udc->suspended = 0;
1386 at91_udp_write(AT91_UDP_IER, AT91_UDP_EP(0));
1387
1388 /*
1389 * NOTE: this driver keeps clocks off unless the
1390 * USB host is present. That saves power, and also
1391 * eliminates IRQs (reset, resume, suspend) that can
1392 * otherwise flood from the controller. If your
1393 * board doesn't support VBUS detection, suspend and
1394 * resume irq logic may need more attention...
1395 */
1396
1397 /* host initiated suspend (3+ms bus idle) */
1398 } else if (status & AT91_UDP_RXSUSP) {
1399 at91_udp_write(AT91_UDP_IDR, AT91_UDP_RXSUSP);
1400 at91_udp_write(AT91_UDP_IER, AT91_UDP_RXRSM);
1401 at91_udp_write(AT91_UDP_ICR, AT91_UDP_RXSUSP);
1402 // VDBG("bus suspend\n");
1403 if (udc->suspended)
1404 continue;
1405 udc->suspended = 1;
1406
1407 /*
1408 * NOTE: when suspending a VBUS-powered device, the
1409 * gadget driver should switch into slow clock mode
1410 * and then into standby to avoid drawing more than
1411 * 500uA power (2500uA for some high-power configs).
1412 */
1413 if (udc->driver && udc->driver->suspend)
1414 udc->driver->suspend(&udc->gadget);
1415
1416 /* host initiated resume */
1417 } else if (status & AT91_UDP_RXRSM) {
1418 at91_udp_write(AT91_UDP_IDR, AT91_UDP_RXRSM);
1419 at91_udp_write(AT91_UDP_IER, AT91_UDP_RXSUSP);
1420 at91_udp_write(AT91_UDP_ICR, AT91_UDP_RXRSM);
1421 // VDBG("bus resume\n");
1422 if (!udc->suspended)
1423 continue;
1424 udc->suspended = 0;
1425
1426 /*
1427 * NOTE: for a VBUS-powered device, the gadget driver
1428 * would normally want to switch out of slow clock
1429 * mode into normal mode.
1430 */
1431 if (udc->driver && udc->driver->resume)
1432 udc->driver->resume(&udc->gadget);
1433
1434 /* endpoint IRQs are cleared by handling them */
1435 } else {
1436 int i;
1437 unsigned mask = 1;
1438 struct at91_ep *ep = &udc->ep[1];
1439
1440 if (status & mask)
1441 handle_ep0(udc);
1442 for (i = 1; i < NUM_ENDPOINTS; i++) {
1443 mask <<= 1;
1444 if (status & mask)
1445 handle_ep(ep);
1446 ep++;
1447 }
1448 }
1449 }
1450
1451 return IRQ_HANDLED;
1452}
1453
1454/*-------------------------------------------------------------------------*/
1455
1456static struct at91_udc controller = {
1457 .gadget = {
1458 .ops = &at91_udc_ops,
1459 .ep0 = &controller.ep[0].ep,
1460 .name = driver_name,
1461 .dev = {
1462 .bus_id = "gadget"
1463 }
1464 },
1465 .ep[0] = {
1466 .ep = {
1467 .name = ep0name,
1468 .ops = &at91_ep_ops,
1469 },
1470 .udc = &controller,
1471 .maxpacket = 8,
1472 .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(0)),
1473 .int_mask = 1 << 0,
1474 },
1475 .ep[1] = {
1476 .ep = {
1477 .name = "ep1",
1478 .ops = &at91_ep_ops,
1479 },
1480 .udc = &controller,
1481 .is_pingpong = 1,
1482 .maxpacket = 64,
1483 .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(1)),
1484 .int_mask = 1 << 1,
1485 },
1486 .ep[2] = {
1487 .ep = {
1488 .name = "ep2",
1489 .ops = &at91_ep_ops,
1490 },
1491 .udc = &controller,
1492 .is_pingpong = 1,
1493 .maxpacket = 64,
1494 .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(2)),
1495 .int_mask = 1 << 2,
1496 },
1497 .ep[3] = {
1498 .ep = {
1499 /* could actually do bulk too */
1500 .name = "ep3-int",
1501 .ops = &at91_ep_ops,
1502 },
1503 .udc = &controller,
1504 .maxpacket = 8,
1505 .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(3)),
1506 .int_mask = 1 << 3,
1507 },
1508 .ep[4] = {
1509 .ep = {
1510 .name = "ep4",
1511 .ops = &at91_ep_ops,
1512 },
1513 .udc = &controller,
1514 .is_pingpong = 1,
1515 .maxpacket = 256,
1516 .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(4)),
1517 .int_mask = 1 << 4,
1518 },
1519 .ep[5] = {
1520 .ep = {
1521 .name = "ep5",
1522 .ops = &at91_ep_ops,
1523 },
1524 .udc = &controller,
1525 .is_pingpong = 1,
1526 .maxpacket = 256,
1527 .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(5)),
1528 .int_mask = 1 << 5,
1529 },
1530 /* ep6 and ep7 are also reserved */
1531};
1532
1533static irqreturn_t at91_vbus_irq(int irq, void *_udc, struct pt_regs *r)
1534{
1535 struct at91_udc *udc = _udc;
1536 unsigned value;
1537
1538 /* vbus needs at least brief debouncing */
1539 udelay(10);
1540 value = at91_get_gpio_value(udc->board.vbus_pin);
1541 if (value != udc->vbus)
1542 at91_vbus_session(&udc->gadget, value);
1543
1544 return IRQ_HANDLED;
1545}
1546
1547int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1548{
1549 struct at91_udc *udc = &controller;
1550 int retval;
1551
1552 if (!driver
1553 || driver->speed != USB_SPEED_FULL
1554 || !driver->bind
1555 || !driver->unbind
1556 || !driver->setup) {
1557 DBG("bad parameter.\n");
1558 return -EINVAL;
1559 }
1560
1561 if (udc->driver) {
1562 DBG("UDC already has a gadget driver\n");
1563 return -EBUSY;
1564 }
1565
1566 udc->driver = driver;
1567 udc->gadget.dev.driver = &driver->driver;
1568 udc->gadget.dev.driver_data = &driver->driver;
1569 udc->enabled = 1;
1570 udc->selfpowered = 1;
1571
1572 retval = driver->bind(&udc->gadget);
1573 if (retval) {
1574 DBG("driver->bind() returned %d\n", retval);
1575 udc->driver = NULL;
1576 return retval;
1577 }
1578
1579 local_irq_disable();
1580 pullup(udc, 1);
1581 local_irq_enable();
1582
1583 DBG("bound to %s\n", driver->driver.name);
1584 return 0;
1585}
1586EXPORT_SYMBOL (usb_gadget_register_driver);
1587
1588int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
1589{
1590 struct at91_udc *udc = &controller;
1591
1592 if (!driver || driver != udc->driver)
1593 return -EINVAL;
1594
1595 local_irq_disable();
1596 udc->enabled = 0;
1597 pullup(udc, 0);
1598 local_irq_enable();
1599
1600 driver->unbind(&udc->gadget);
1601 udc->driver = NULL;
1602
1603 DBG("unbound from %s\n", driver->driver.name);
1604 return 0;
1605}
1606EXPORT_SYMBOL (usb_gadget_unregister_driver);
1607
1608/*-------------------------------------------------------------------------*/
1609
1610static void at91udc_shutdown(struct platform_device *dev)
1611{
1612 /* force disconnect on reboot */
1613 pullup(platform_get_drvdata(dev), 0);
1614}
1615
1616static int __devinit at91udc_probe(struct platform_device *pdev)
1617{
1618 struct device *dev = &pdev->dev;
1619 struct at91_udc *udc;
1620 int retval;
1621
1622 if (!dev->platform_data) {
1623 /* small (so we copy it) but critical! */
1624 DBG("missing platform_data\n");
1625 return -ENODEV;
1626 }
1627
1628 if (!request_mem_region(AT91_BASE_UDP, SZ_16K, driver_name)) {
1629 DBG("someone's using UDC memory\n");
1630 return -EBUSY;
1631 }
1632
1633 /* init software state */
1634 udc = &controller;
1635 udc->gadget.dev.parent = dev;
1636 udc->board = *(struct at91_udc_data *) dev->platform_data;
1637 udc->pdev = pdev;
1638 udc_reinit(udc);
1639 udc->enabled = 0;
1640
1641 /* get interface and function clocks */
1642 udc->iclk = clk_get(dev, "udc_clk");
1643 udc->fclk = clk_get(dev, "udpck");
1644 if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) {
1645 DBG("clocks missing\n");
1646 return -ENODEV;
1647 }
1648
1649 retval = device_register(&udc->gadget.dev);
1650 if (retval < 0)
1651 goto fail0;
1652
1653 /* disable everything until there's a gadget driver and vbus */
1654 pullup(udc, 0);
1655
1656 /* request UDC and maybe VBUS irqs */
1657 if (request_irq(AT91_ID_UDP, at91_udc_irq, SA_INTERRUPT, driver_name, udc)) {
1658 DBG("request irq %d failed\n", AT91_ID_UDP);
1659 retval = -EBUSY;
1660 goto fail1;
1661 }
1662 if (udc->board.vbus_pin > 0) {
1663 if (request_irq(udc->board.vbus_pin, at91_vbus_irq, SA_INTERRUPT, driver_name, udc)) {
1664 DBG("request vbus irq %d failed\n", udc->board.vbus_pin);
1665 free_irq(AT91_ID_UDP, udc);
1666 retval = -EBUSY;
1667 goto fail1;
1668 }
1669 } else {
1670 DBG("no VBUS detection, assuming always-on\n");
1671 udc->vbus = 1;
1672 }
1673 dev_set_drvdata(dev, udc);
1674 create_debug_file(udc);
1675
1676 INFO("%s version %s\n", driver_name, DRIVER_VERSION);
1677 return 0;
1678
1679fail1:
1680 device_unregister(&udc->gadget.dev);
1681fail0:
1682 release_mem_region(AT91_VA_BASE_UDP, SZ_16K);
1683 DBG("%s probe failed, %d\n", driver_name, retval);
1684 return retval;
1685}
1686
1687static int __devexit at91udc_remove(struct platform_device *dev)
1688{
1689 struct at91_udc *udc = platform_get_drvdata(dev);
1690
1691 DBG("remove\n");
1692
1693 pullup(udc, 0);
1694
1695 if (udc->driver != 0)
1696 usb_gadget_unregister_driver(udc->driver);
1697
1698 remove_debug_file(udc);
1699 if (udc->board.vbus_pin > 0)
1700 free_irq(udc->board.vbus_pin, udc);
1701 free_irq(AT91_ID_UDP, udc);
1702 device_unregister(&udc->gadget.dev);
1703 release_mem_region(AT91_BASE_UDP, SZ_16K);
1704
1705 clk_put(udc->iclk);
1706 clk_put(udc->fclk);
1707
1708 return 0;
1709}
1710
1711#ifdef CONFIG_PM
1712static int at91udc_suspend(struct platform_device *dev, u32 state, u32 level)
1713{
1714 struct at91_udc *udc = platform_get_drvdata(dev);
1715
1716 /*
1717 * The "safe" suspend transitions are opportunistic ... e.g. when
1718 * the USB link is suspended (48MHz clock autogated off), or when
1719 * it's disconnected (programmatically gated off, elsewhere).
1720 * Then we can suspend, and the chip can enter slow clock mode.
1721 *
1722 * The problem case is some component (user mode?) suspending this
1723 * device while it's active, with the 48 MHz clock in use. There
1724 * are two basic approaches: (a) veto suspend levels involving slow
1725 * clock mode, (b) disconnect, so 48 MHz will no longer be in use
1726 * and we can enter slow clock mode. This uses (b) for now, since
1727 * it's simplest until AT91 PM exists and supports the other option.
1728 */
1729 if (udc->vbus && !udc->suspended)
1730 pullup(udc, 0);
1731 return 0;
1732}
1733
1734static int at91udc_resume(struct platform_device *dev, u32 level)
1735{
1736 struct at91_udc *udc = platform_get_drvdata(dev);
1737
1738 /* maybe reconnect to host; if so, clocks on */
1739 pullup(udc, 1);
1740 return 0;
1741}
1742#else
1743#define at91udc_suspend NULL
1744#define at91udc_resume NULL
1745#endif
1746
1747static struct platform_driver at91_udc = {
1748 .probe = at91udc_probe,
1749 .remove = __devexit_p(at91udc_remove),
1750 .shutdown = at91udc_shutdown,
1751 .suspend = at91udc_suspend,
1752 .resume = at91udc_resume,
1753 .driver = {
1754 .name = (char *) driver_name,
1755 .owner = THIS_MODULE,
1756 },
1757};
1758
1759static int __devinit udc_init_module(void)
1760{
1761 return platform_driver_register(&at91_udc);
1762}
1763module_init(udc_init_module);
1764
1765static void __devexit udc_exit_module(void)
1766{
1767 platform_driver_unregister(&at91_udc);
1768}
1769module_exit(udc_exit_module);
1770
1771MODULE_DESCRIPTION("AT91RM9200 udc driver");
1772MODULE_AUTHOR("Thomas Rathbone, David Brownell");
1773MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h
new file mode 100644
index 000000000000..5a4799cedd19
--- /dev/null
+++ b/drivers/usb/gadget/at91_udc.h
@@ -0,0 +1,181 @@
1/*
2 * Copyright (C) 2004 by Thomas Rathbone, HP Labs
3 * Copyright (C) 2005 by Ivan Kokshaysky
4 * Copyright (C) 2006 by SAN People
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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, write to the
18 * Free Software Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#ifndef AT91_UDC_H
23#define AT91_UDC_H
24
25/*
26 * USB Device Port (UDP) registers.
27 * Based on AT91RM9200 datasheet revision E.
28 */
29
30#define AT91_UDP_FRM_NUM 0x00 /* Frame Number Register */
31#define AT91_UDP_NUM (0x7ff << 0) /* Frame Number */
32#define AT91_UDP_FRM_ERR (1 << 16) /* Frame Error */
33#define AT91_UDP_FRM_OK (1 << 17) /* Frame OK */
34
35#define AT91_UDP_GLB_STAT 0x04 /* Global State Register */
36#define AT91_UDP_FADDEN (1 << 0) /* Function Address Enable */
37#define AT91_UDP_CONFG (1 << 1) /* Configured */
38#define AT91_UDP_ESR (1 << 2) /* Enable Send Resume */
39#define AT91_UDP_RSMINPR (1 << 3) /* Resume has been sent */
40#define AT91_UDP_RMWUPE (1 << 4) /* Remote Wake Up Enable */
41
42#define AT91_UDP_FADDR 0x08 /* Function Address Register */
43#define AT91_UDP_FADD (0x7f << 0) /* Function Address Value */
44#define AT91_UDP_FEN (1 << 8) /* Function Enable */
45
46#define AT91_UDP_IER 0x10 /* Interrupt Enable Register */
47#define AT91_UDP_IDR 0x14 /* Interrupt Disable Register */
48#define AT91_UDP_IMR 0x18 /* Interrupt Mask Register */
49
50#define AT91_UDP_ISR 0x1c /* Interrupt Status Register */
51#define AT91_UDP_EP(n) (1 << (n)) /* Endpoint Interrupt Status */
52#define AT91_UDP_RXSUSP (1 << 8) /* USB Suspend Interrupt Status */
53#define AT91_UDP_RXRSM (1 << 9) /* USB Resume Interrupt Status */
54#define AT91_UDP_EXTRSM (1 << 10) /* External Resume Interrupt Status */
55#define AT91_UDP_SOFINT (1 << 11) /* Start of Frame Interrupt Status */
56#define AT91_UDP_ENDBUSRES (1 << 12) /* End of Bus Reset Interrpt Status */
57#define AT91_UDP_WAKEUP (1 << 13) /* USB Wakeup Interrupt Status */
58
59#define AT91_UDP_ICR 0x20 /* Interrupt Clear Register */
60#define AT91_UDP_RST_EP 0x28 /* Reset Endpoint Register */
61
62#define AT91_UDP_CSR(n) (0x30+((n)*4)) /* Endpoint Control/Status Registers 0-7 */
63#define AT91_UDP_TXCOMP (1 << 0) /* Generates IN packet with data previously written in DPR */
64#define AT91_UDP_RX_DATA_BK0 (1 << 1) /* Receive Data Bank 0 */
65#define AT91_UDP_RXSETUP (1 << 2) /* Send STALL to the host */
66#define AT91_UDP_STALLSENT (1 << 3) /* Stall Sent / Isochronous error (Isochronous endpoints) */
67#define AT91_UDP_TXPKTRDY (1 << 4) /* Transmit Packet Ready */
68#define AT91_UDP_FORCESTALL (1 << 5) /* Force Stall */
69#define AT91_UDP_RX_DATA_BK1 (1 << 6) /* Receive Data Bank 1 */
70#define AT91_UDP_DIR (1 << 7) /* Transfer Direction */
71#define AT91_UDP_EPTYPE (7 << 8) /* Endpoint Type */
72#define AT91_UDP_EPTYPE_CTRL (0 << 8)
73#define AT91_UDP_EPTYPE_ISO_OUT (1 << 8)
74#define AT91_UDP_EPTYPE_BULK_OUT (2 << 8)
75#define AT91_UDP_EPTYPE_INT_OUT (3 << 8)
76#define AT91_UDP_EPTYPE_ISO_IN (5 << 8)
77#define AT91_UDP_EPTYPE_BULK_IN (6 << 8)
78#define AT91_UDP_EPTYPE_INT_IN (7 << 8)
79#define AT91_UDP_DTGLE (1 << 11) /* Data Toggle */
80#define AT91_UDP_EPEDS (1 << 15) /* Endpoint Enable/Disable */
81#define AT91_UDP_RXBYTECNT (0x7ff << 16) /* Number of bytes in FIFO */
82
83#define AT91_UDP_FDR(n) (0x50+((n)*4)) /* Endpoint FIFO Data Registers 0-7 */
84
85#define AT91_UDP_TXVC 0x74 /* Transceiver Control Register */
86#define AT91_UDP_TXVC_TXVDIS (1 << 8) /* Transceiver Disable */
87
88
89/*-------------------------------------------------------------------------*/
90
91/*
92 * controller driver data structures
93 */
94
95#define NUM_ENDPOINTS 6
96
97/*
98 * hardware won't disable bus reset, or resume while the controller
99 * is suspended ... watching suspend helps keep the logic symmetric.
100 */
101#define MINIMUS_INTERRUPTUS \
102 (AT91_UDP_ENDBUSRES | AT91_UDP_RXRSM | AT91_UDP_RXSUSP)
103
104struct at91_ep {
105 struct usb_ep ep;
106 struct list_head queue;
107 struct at91_udc *udc;
108 void __iomem *creg;
109
110 unsigned maxpacket:16;
111 u8 int_mask;
112 unsigned is_pingpong:1;
113
114 unsigned stopped:1;
115 unsigned is_in:1;
116 unsigned is_iso:1;
117 unsigned fifo_bank:1;
118
119 const struct usb_endpoint_descriptor
120 *desc;
121};
122
123/*
124 * driver is non-SMP, and just blocks IRQs whenever it needs
125 * access protection for chip registers or driver state
126 */
127struct at91_udc {
128 struct usb_gadget gadget;
129 struct at91_ep ep[NUM_ENDPOINTS];
130 struct usb_gadget_driver *driver;
131 unsigned vbus:1;
132 unsigned enabled:1;
133 unsigned clocked:1;
134 unsigned suspended:1;
135 unsigned req_pending:1;
136 unsigned wait_for_addr_ack:1;
137 unsigned wait_for_config_ack:1;
138 unsigned selfpowered:1;
139 u8 addr;
140 struct at91_udc_data board;
141 struct clk *iclk, *fclk;
142 struct platform_device *pdev;
143 struct proc_dir_entry *pde;
144};
145
146static inline struct at91_udc *to_udc(struct usb_gadget *g)
147{
148 return container_of(g, struct at91_udc, gadget);
149}
150
151struct at91_request {
152 struct usb_request req;
153 struct list_head queue;
154};
155
156/*-------------------------------------------------------------------------*/
157
158#ifdef DEBUG
159#define DBG(stuff...) printk(KERN_DEBUG "udc: " stuff)
160#else
161#define DBG(stuff...) do{}while(0)
162#endif
163
164#ifdef VERBOSE
165# define VDBG DBG
166#else
167# define VDBG(stuff...) do{}while(0)
168#endif
169
170#ifdef PACKET_TRACE
171# define PACKET VDBG
172#else
173# define PACKET(stuff...) do{}while(0)
174#endif
175
176#define ERR(stuff...) printk(KERN_ERR "udc: " stuff)
177#define WARN(stuff...) printk(KERN_WARNING "udc: " stuff)
178#define INFO(stuff...) printk(KERN_INFO "udc: " stuff)
179
180#endif
181
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 9734cb76dd6c..42ce41d71b7f 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -478,10 +478,9 @@ dummy_alloc_request (struct usb_ep *_ep, gfp_t mem_flags)
478 return NULL; 478 return NULL;
479 ep = usb_ep_to_dummy_ep (_ep); 479 ep = usb_ep_to_dummy_ep (_ep);
480 480
481 req = kmalloc (sizeof *req, mem_flags); 481 req = kzalloc(sizeof(*req), mem_flags);
482 if (!req) 482 if (!req)
483 return NULL; 483 return NULL;
484 memset (req, 0, sizeof *req);
485 INIT_LIST_HEAD (&req->queue); 484 INIT_LIST_HEAD (&req->queue);
486 return &req->req; 485 return &req->req;
487} 486}
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index afc84cfb61f9..c3d8e5c5bf28 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -182,33 +182,37 @@ struct eth_dev {
182 * parameters are in UTF-8 (superset of ASCII's 7 bit characters). 182 * parameters are in UTF-8 (superset of ASCII's 7 bit characters).
183 */ 183 */
184 184
185static ushort __initdata idVendor; 185static ushort idVendor;
186module_param(idVendor, ushort, S_IRUGO); 186module_param(idVendor, ushort, S_IRUGO);
187MODULE_PARM_DESC(idVendor, "USB Vendor ID"); 187MODULE_PARM_DESC(idVendor, "USB Vendor ID");
188 188
189static ushort __initdata idProduct; 189static ushort idProduct;
190module_param(idProduct, ushort, S_IRUGO); 190module_param(idProduct, ushort, S_IRUGO);
191MODULE_PARM_DESC(idProduct, "USB Product ID"); 191MODULE_PARM_DESC(idProduct, "USB Product ID");
192 192
193static ushort __initdata bcdDevice; 193static ushort bcdDevice;
194module_param(bcdDevice, ushort, S_IRUGO); 194module_param(bcdDevice, ushort, S_IRUGO);
195MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); 195MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)");
196 196
197static char *__initdata iManufacturer; 197static char *iManufacturer;
198module_param(iManufacturer, charp, S_IRUGO); 198module_param(iManufacturer, charp, S_IRUGO);
199MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); 199MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string");
200 200
201static char *__initdata iProduct; 201static char *iProduct;
202module_param(iProduct, charp, S_IRUGO); 202module_param(iProduct, charp, S_IRUGO);
203MODULE_PARM_DESC(iProduct, "USB Product string"); 203MODULE_PARM_DESC(iProduct, "USB Product string");
204 204
205static char *iSerialNumber;
206module_param(iSerialNumber, charp, S_IRUGO);
207MODULE_PARM_DESC(iSerialNumber, "SerialNumber");
208
205/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */ 209/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */
206static char *__initdata dev_addr; 210static char *dev_addr;
207module_param(dev_addr, charp, S_IRUGO); 211module_param(dev_addr, charp, S_IRUGO);
208MODULE_PARM_DESC(dev_addr, "Device Ethernet Address"); 212MODULE_PARM_DESC(dev_addr, "Device Ethernet Address");
209 213
210/* this address is invisible to ifconfig */ 214/* this address is invisible to ifconfig */
211static char *__initdata host_addr; 215static char *host_addr;
212module_param(host_addr, charp, S_IRUGO); 216module_param(host_addr, charp, S_IRUGO);
213MODULE_PARM_DESC(host_addr, "Host Ethernet Address"); 217MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
214 218
@@ -253,6 +257,14 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
253#define DEV_CONFIG_CDC 257#define DEV_CONFIG_CDC
254#endif 258#endif
255 259
260#ifdef CONFIG_USB_GADGET_MUSBHSFC
261#define DEV_CONFIG_CDC
262#endif
263
264#ifdef CONFIG_USB_GADGET_MUSBHDRC
265#define DEV_CONFIG_CDC
266#endif
267
256 268
257/* For CDC-incapable hardware, choose the simple cdc subset. 269/* For CDC-incapable hardware, choose the simple cdc subset.
258 * Anything that talks bulk (without notable bugs) can do this. 270 * Anything that talks bulk (without notable bugs) can do this.
@@ -395,6 +407,7 @@ static inline int BITRATE(struct usb_gadget *g)
395#define STRING_CDC 7 407#define STRING_CDC 7
396#define STRING_SUBSET 8 408#define STRING_SUBSET 8
397#define STRING_RNDIS 9 409#define STRING_RNDIS 9
410#define STRING_SERIALNUMBER 10
398 411
399/* holds our biggest descriptor (or RNDIS response) */ 412/* holds our biggest descriptor (or RNDIS response) */
400#define USB_BUFSIZ 256 413#define USB_BUFSIZ 256
@@ -862,6 +875,7 @@ static inline void __init hs_subset_descriptors(void)
862 875
863static char manufacturer [50]; 876static char manufacturer [50];
864static char product_desc [40] = DRIVER_DESC; 877static char product_desc [40] = DRIVER_DESC;
878static char serial_number [20];
865 879
866#ifdef DEV_CONFIG_CDC 880#ifdef DEV_CONFIG_CDC
867/* address that the host will use ... usually assigned at random */ 881/* address that the host will use ... usually assigned at random */
@@ -872,6 +886,7 @@ static char ethaddr [2 * ETH_ALEN + 1];
872static struct usb_string strings [] = { 886static struct usb_string strings [] = {
873 { STRING_MANUFACTURER, manufacturer, }, 887 { STRING_MANUFACTURER, manufacturer, },
874 { STRING_PRODUCT, product_desc, }, 888 { STRING_PRODUCT, product_desc, },
889 { STRING_SERIALNUMBER, serial_number, },
875 { STRING_DATA, "Ethernet Data", }, 890 { STRING_DATA, "Ethernet Data", },
876#ifdef DEV_CONFIG_CDC 891#ifdef DEV_CONFIG_CDC
877 { STRING_CDC, "CDC Ethernet", }, 892 { STRING_CDC, "CDC Ethernet", },
@@ -1549,7 +1564,8 @@ static int eth_change_mtu (struct net_device *net, int new_mtu)
1549{ 1564{
1550 struct eth_dev *dev = netdev_priv(net); 1565 struct eth_dev *dev = netdev_priv(net);
1551 1566
1552 // FIXME if rndis, don't change while link's live 1567 if (dev->rndis)
1568 return -EBUSY;
1553 1569
1554 if (new_mtu <= ETH_HLEN || new_mtu > ETH_FRAME_LEN) 1570 if (new_mtu <= ETH_HLEN || new_mtu > ETH_FRAME_LEN)
1555 return -ERANGE; 1571 return -ERANGE;
@@ -2116,7 +2132,7 @@ eth_req_free (struct usb_ep *ep, struct usb_request *req)
2116} 2132}
2117 2133
2118 2134
2119static void 2135static void __exit
2120eth_unbind (struct usb_gadget *gadget) 2136eth_unbind (struct usb_gadget *gadget)
2121{ 2137{
2122 struct eth_dev *dev = get_gadget_data (gadget); 2138 struct eth_dev *dev = get_gadget_data (gadget);
@@ -2153,7 +2169,7 @@ static u8 __init nibble (unsigned char c)
2153 return 0; 2169 return 0;
2154} 2170}
2155 2171
2156static void __init get_ether_addr (const char *str, u8 *dev_addr) 2172static int __init get_ether_addr(const char *str, u8 *dev_addr)
2157{ 2173{
2158 if (str) { 2174 if (str) {
2159 unsigned i; 2175 unsigned i;
@@ -2168,9 +2184,10 @@ static void __init get_ether_addr (const char *str, u8 *dev_addr)
2168 dev_addr [i] = num; 2184 dev_addr [i] = num;
2169 } 2185 }
2170 if (is_valid_ether_addr (dev_addr)) 2186 if (is_valid_ether_addr (dev_addr))
2171 return; 2187 return 0;
2172 } 2188 }
2173 random_ether_addr(dev_addr); 2189 random_ether_addr(dev_addr);
2190 return 1;
2174} 2191}
2175 2192
2176static int __init 2193static int __init
@@ -2268,6 +2285,10 @@ eth_bind (struct usb_gadget *gadget)
2268 strlcpy (manufacturer, iManufacturer, sizeof manufacturer); 2285 strlcpy (manufacturer, iManufacturer, sizeof manufacturer);
2269 if (iProduct) 2286 if (iProduct)
2270 strlcpy (product_desc, iProduct, sizeof product_desc); 2287 strlcpy (product_desc, iProduct, sizeof product_desc);
2288 if (iSerialNumber) {
2289 device_desc.iSerialNumber = STRING_SERIALNUMBER,
2290 strlcpy(serial_number, iSerialNumber, sizeof serial_number);
2291 }
2271 2292
2272 /* all we really need is bulk IN/OUT */ 2293 /* all we really need is bulk IN/OUT */
2273 usb_ep_autoconfig_reset (gadget); 2294 usb_ep_autoconfig_reset (gadget);
@@ -2377,9 +2398,13 @@ autoconf_fail:
2377 * The host side address is used with CDC and RNDIS, and commonly 2398 * The host side address is used with CDC and RNDIS, and commonly
2378 * ends up in a persistent config database. 2399 * ends up in a persistent config database.
2379 */ 2400 */
2380 get_ether_addr(dev_addr, net->dev_addr); 2401 if (get_ether_addr(dev_addr, net->dev_addr))
2402 dev_warn(&gadget->dev,
2403 "using random %s ethernet address\n", "self");
2381 if (cdc || rndis) { 2404 if (cdc || rndis) {
2382 get_ether_addr(host_addr, dev->host_mac); 2405 if (get_ether_addr(host_addr, dev->host_mac))
2406 dev_warn(&gadget->dev,
2407 "using random %s ethernet address\n", "host");
2383#ifdef DEV_CONFIG_CDC 2408#ifdef DEV_CONFIG_CDC
2384 snprintf (ethaddr, sizeof ethaddr, "%02X%02X%02X%02X%02X%02X", 2409 snprintf (ethaddr, sizeof ethaddr, "%02X%02X%02X%02X%02X%02X",
2385 dev->host_mac [0], dev->host_mac [1], 2410 dev->host_mac [0], dev->host_mac [1],
@@ -2523,7 +2548,7 @@ static struct usb_gadget_driver eth_driver = {
2523 2548
2524 .function = (char *) driver_desc, 2549 .function = (char *) driver_desc,
2525 .bind = eth_bind, 2550 .bind = eth_bind,
2526 .unbind = eth_unbind, 2551 .unbind = __exit_p(eth_unbind),
2527 2552
2528 .setup = eth_setup, 2553 .setup = eth_setup,
2529 .disconnect = eth_disconnect, 2554 .disconnect = eth_disconnect,
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index de59c58896d6..cf3be299e353 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -3678,7 +3678,7 @@ static void lun_release(struct device *dev)
3678 kref_put(&fsg->ref, fsg_release); 3678 kref_put(&fsg->ref, fsg_release);
3679} 3679}
3680 3680
3681static void fsg_unbind(struct usb_gadget *gadget) 3681static void __exit fsg_unbind(struct usb_gadget *gadget)
3682{ 3682{
3683 struct fsg_dev *fsg = get_gadget_data(gadget); 3683 struct fsg_dev *fsg = get_gadget_data(gadget);
3684 int i; 3684 int i;
@@ -4064,7 +4064,7 @@ static struct usb_gadget_driver fsg_driver = {
4064#endif 4064#endif
4065 .function = (char *) longname, 4065 .function = (char *) longname,
4066 .bind = fsg_bind, 4066 .bind = fsg_bind,
4067 .unbind = fsg_unbind, 4067 .unbind = __exit_p(fsg_unbind),
4068 .disconnect = fsg_disconnect, 4068 .disconnect = fsg_disconnect,
4069 .setup = fsg_setup, 4069 .setup = fsg_setup,
4070 .suspend = fsg_suspend, 4070 .suspend = fsg_suspend,
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h
index 8cbae21d84b9..c4081407171f 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -3,9 +3,9 @@
3 * gadget drivers or other code that needs to deal with them, and which 3 * gadget drivers or other code that needs to deal with them, and which
4 * autoconfigures instead of using early binding to the hardware. 4 * autoconfigures instead of using early binding to the hardware.
5 * 5 *
6 * This could eventually work like the ARM mach_is_*() stuff, driven by 6 * This SHOULD eventually work like the ARM mach_is_*() stuff, driven by
7 * some config file that gets updated as new hardware is supported. 7 * some config file that gets updated as new hardware is supported.
8 * (And avoiding the runtime comparisons in typical one-choice cases.) 8 * (And avoiding all runtime comparisons in typical one-choice configs!)
9 * 9 *
10 * NOTE: some of these controller drivers may not be available yet. 10 * NOTE: some of these controller drivers may not be available yet.
11 */ 11 */
@@ -93,6 +93,26 @@
93#define gadget_is_imx(g) 0 93#define gadget_is_imx(g) 0
94#endif 94#endif
95 95
96/* Mentor high speed function controller */
97#ifdef CONFIG_USB_GADGET_MUSBHSFC
98#define gadget_is_musbhsfc(g) !strcmp("musbhsfc_udc", (g)->name)
99#else
100#define gadget_is_musbhsfc(g) 0
101#endif
102
103/* Mentor high speed "dual role" controller, peripheral mode */
104#ifdef CONFIG_USB_GADGET_MUSBHDRC
105#define gadget_is_musbhdrc(g) !strcmp("musbhdrc_udc", (g)->name)
106#else
107#define gadget_is_musbhdrc(g) 0
108#endif
109
110#ifdef CONFIG_USB_GADGET_MPC8272
111#define gadget_is_mpc8272(g) !strcmp("mpc8272_udc", (g)->name)
112#else
113#define gadget_is_mpc8272(g) 0
114#endif
115
96// CONFIG_USB_GADGET_SX2 116// CONFIG_USB_GADGET_SX2
97// CONFIG_USB_GADGET_AU1X00 117// CONFIG_USB_GADGET_AU1X00
98// ... 118// ...
@@ -143,5 +163,11 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
143 return 0x13; 163 return 0x13;
144 else if (gadget_is_imx(gadget)) 164 else if (gadget_is_imx(gadget))
145 return 0x14; 165 return 0x14;
166 else if (gadget_is_musbhsfc(gadget))
167 return 0x15;
168 else if (gadget_is_musbhdrc(gadget))
169 return 0x16;
170 else if (gadget_is_mpc8272(gadget))
171 return 0x17;
146 return -ENOENT; 172 return -ENOENT;
147} 173}
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index b0f3cd63e3b9..66b81bbf6bee 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -275,11 +275,10 @@ goku_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
275 275
276 if (!_ep) 276 if (!_ep)
277 return NULL; 277 return NULL;
278 req = kmalloc(sizeof *req, gfp_flags); 278 req = kzalloc(sizeof *req, gfp_flags);
279 if (!req) 279 if (!req)
280 return NULL; 280 return NULL;
281 281
282 memset(req, 0, sizeof *req);
283 req->req.dma = DMA_ADDR_INVALID; 282 req->req.dma = DMA_ADDR_INVALID;
284 INIT_LIST_HEAD(&req->queue); 283 INIT_LIST_HEAD(&req->queue);
285 return &req->req; 284 return &req->req;
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 0aab7d24c768..b44cfda76b61 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -170,10 +170,9 @@ static struct dev_data *dev_new (void)
170{ 170{
171 struct dev_data *dev; 171 struct dev_data *dev;
172 172
173 dev = kmalloc (sizeof *dev, GFP_KERNEL); 173 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
174 if (!dev) 174 if (!dev)
175 return NULL; 175 return NULL;
176 memset (dev, 0, sizeof *dev);
177 dev->state = STATE_DEV_DISABLED; 176 dev->state = STATE_DEV_DISABLED;
178 atomic_set (&dev->count, 1); 177 atomic_set (&dev->count, 1);
179 spin_lock_init (&dev->lock); 178 spin_lock_init (&dev->lock);
@@ -1592,10 +1591,9 @@ static int activate_ep_files (struct dev_data *dev)
1592 gadget_for_each_ep (ep, dev->gadget) { 1591 gadget_for_each_ep (ep, dev->gadget) {
1593 struct ep_data *data; 1592 struct ep_data *data;
1594 1593
1595 data = kmalloc (sizeof *data, GFP_KERNEL); 1594 data = kzalloc(sizeof(*data), GFP_KERNEL);
1596 if (!data) 1595 if (!data)
1597 goto enomem; 1596 goto enomem;
1598 memset (data, 0, sizeof data);
1599 data->state = STATE_EP_DISABLED; 1597 data->state = STATE_EP_DISABLED;
1600 init_MUTEX (&data->lock); 1598 init_MUTEX (&data->lock);
1601 init_waitqueue_head (&data->wait); 1599 init_waitqueue_head (&data->wait);
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index 1a362c5e7f3d..0d3424eda038 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -1114,11 +1114,10 @@ static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep,
1114 1114
1115 DEBUG("%s, %p\n", __FUNCTION__, ep); 1115 DEBUG("%s, %p\n", __FUNCTION__, ep);
1116 1116
1117 req = kmalloc(sizeof *req, gfp_flags); 1117 req = kzalloc(sizeof(*req), gfp_flags);
1118 if (!req) 1118 if (!req)
1119 return 0; 1119 return 0;
1120 1120
1121 memset(req, 0, sizeof *req);
1122 INIT_LIST_HEAD(&req->queue); 1121 INIT_LIST_HEAD(&req->queue);
1123 1122
1124 return &req->req; 1123 return &req->req;
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 67b13ab2f3f5..fb73dc100535 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -386,11 +386,10 @@ net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
386 return NULL; 386 return NULL;
387 ep = container_of (_ep, struct net2280_ep, ep); 387 ep = container_of (_ep, struct net2280_ep, ep);
388 388
389 req = kmalloc (sizeof *req, gfp_flags); 389 req = kzalloc(sizeof(*req), gfp_flags);
390 if (!req) 390 if (!req)
391 return NULL; 391 return NULL;
392 392
393 memset (req, 0, sizeof *req);
394 req->req.dma = DMA_ADDR_INVALID; 393 req->req.dma = DMA_ADDR_INVALID;
395 INIT_LIST_HEAD (&req->queue); 394 INIT_LIST_HEAD (&req->queue);
396 395
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index a8972d7c97be..fbea51448909 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -273,9 +273,8 @@ omap_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
273{ 273{
274 struct omap_req *req; 274 struct omap_req *req;
275 275
276 req = kmalloc(sizeof *req, gfp_flags); 276 req = kzalloc(sizeof(*req), gfp_flags);
277 if (req) { 277 if (req) {
278 memset (req, 0, sizeof *req);
279 req->req.dma = DMA_ADDR_INVALID; 278 req->req.dma = DMA_ADDR_INVALID;
280 INIT_LIST_HEAD (&req->queue); 279 INIT_LIST_HEAD (&req->queue);
281 } 280 }
@@ -2586,11 +2585,10 @@ omap_udc_setup(struct platform_device *odev, struct otg_transceiver *xceiv)
2586 /* UDC_PULLUP_EN gates the chip clock */ 2585 /* UDC_PULLUP_EN gates the chip clock */
2587 // OTG_SYSCON_1_REG |= DEV_IDLE_EN; 2586 // OTG_SYSCON_1_REG |= DEV_IDLE_EN;
2588 2587
2589 udc = kmalloc (sizeof *udc, SLAB_KERNEL); 2588 udc = kzalloc(sizeof(*udc), SLAB_KERNEL);
2590 if (!udc) 2589 if (!udc)
2591 return -ENOMEM; 2590 return -ENOMEM;
2592 2591
2593 memset(udc, 0, sizeof *udc);
2594 spin_lock_init (&udc->lock); 2592 spin_lock_init (&udc->lock);
2595 2593
2596 udc->gadget.ops = &omap_gadget_ops; 2594 udc->gadget.ops = &omap_gadget_ops;
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index bb028c5b8952..680f7fc5b171 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -335,11 +335,10 @@ pxa2xx_ep_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
335{ 335{
336 struct pxa2xx_request *req; 336 struct pxa2xx_request *req;
337 337
338 req = kmalloc (sizeof *req, gfp_flags); 338 req = kzalloc(sizeof(*req), gfp_flags);
339 if (!req) 339 if (!req)
340 return NULL; 340 return NULL;
341 341
342 memset (req, 0, sizeof *req);
343 INIT_LIST_HEAD (&req->queue); 342 INIT_LIST_HEAD (&req->queue);
344 return &req->req; 343 return &req->req;
345} 344}
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index ba9acd531024..b992546c394d 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -369,7 +369,7 @@ static struct usb_gadget_driver gs_gadget_driver = {
369#endif /* CONFIG_USB_GADGET_DUALSPEED */ 369#endif /* CONFIG_USB_GADGET_DUALSPEED */
370 .function = GS_LONG_NAME, 370 .function = GS_LONG_NAME,
371 .bind = gs_bind, 371 .bind = gs_bind,
372 .unbind = gs_unbind, 372 .unbind = __exit_p(gs_unbind),
373 .setup = gs_setup, 373 .setup = gs_setup,
374 .disconnect = gs_disconnect, 374 .disconnect = gs_disconnect,
375 .driver = { 375 .driver = {
@@ -1413,7 +1413,7 @@ requeue:
1413 * Called on module load. Allocates and initializes the device 1413 * Called on module load. Allocates and initializes the device
1414 * structure and a control request. 1414 * structure and a control request.
1415 */ 1415 */
1416static int gs_bind(struct usb_gadget *gadget) 1416static int __init gs_bind(struct usb_gadget *gadget)
1417{ 1417{
1418 int ret; 1418 int ret;
1419 struct usb_ep *ep; 1419 struct usb_ep *ep;
@@ -1538,7 +1538,7 @@ autoconf_fail:
1538 * Called on module unload. Frees the control request and device 1538 * Called on module unload. Frees the control request and device
1539 * structure. 1539 * structure.
1540 */ 1540 */
1541static void gs_unbind(struct usb_gadget *gadget) 1541static void __exit gs_unbind(struct usb_gadget *gadget)
1542{ 1542{
1543 struct gs_dev *dev = get_gadget_data(gadget); 1543 struct gs_dev *dev = get_gadget_data(gadget);
1544 1544
@@ -2178,10 +2178,9 @@ static int gs_alloc_ports(struct gs_dev *dev, gfp_t kmalloc_flags)
2178 return -EIO; 2178 return -EIO;
2179 2179
2180 for (i=0; i<GS_NUM_PORTS; i++) { 2180 for (i=0; i<GS_NUM_PORTS; i++) {
2181 if ((port=(struct gs_port *)kmalloc(sizeof(struct gs_port), kmalloc_flags)) == NULL) 2181 if ((port=kzalloc(sizeof(struct gs_port), kmalloc_flags)) == NULL)
2182 return -ENOMEM; 2182 return -ENOMEM;
2183 2183
2184 memset(port, 0, sizeof(struct gs_port));
2185 port->port_dev = dev; 2184 port->port_dev = dev;
2186 port->port_num = i; 2185 port->port_num = i;
2187 port->port_line_coding.dwDTERate = cpu_to_le32(GS_DEFAULT_DTE_RATE); 2186 port->port_line_coding.dwDTERate = cpu_to_le32(GS_DEFAULT_DTE_RATE);
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index ae7a1c0f5748..51424f66a765 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -1119,7 +1119,7 @@ zero_autoresume (unsigned long _dev)
1119 1119
1120/*-------------------------------------------------------------------------*/ 1120/*-------------------------------------------------------------------------*/
1121 1121
1122static void 1122static void __exit
1123zero_unbind (struct usb_gadget *gadget) 1123zero_unbind (struct usb_gadget *gadget)
1124{ 1124{
1125 struct zero_dev *dev = get_gadget_data (gadget); 1125 struct zero_dev *dev = get_gadget_data (gadget);
@@ -1136,7 +1136,7 @@ zero_unbind (struct usb_gadget *gadget)
1136 set_gadget_data (gadget, NULL); 1136 set_gadget_data (gadget, NULL);
1137} 1137}
1138 1138
1139static int 1139static int __init
1140zero_bind (struct usb_gadget *gadget) 1140zero_bind (struct usb_gadget *gadget)
1141{ 1141{
1142 struct zero_dev *dev; 1142 struct zero_dev *dev;
@@ -1188,10 +1188,9 @@ autoconf_fail:
1188 1188
1189 1189
1190 /* ok, we made sense of the hardware ... */ 1190 /* ok, we made sense of the hardware ... */
1191 dev = kmalloc (sizeof *dev, SLAB_KERNEL); 1191 dev = kzalloc(sizeof(*dev), SLAB_KERNEL);
1192 if (!dev) 1192 if (!dev)
1193 return -ENOMEM; 1193 return -ENOMEM;
1194 memset (dev, 0, sizeof *dev);
1195 spin_lock_init (&dev->lock); 1194 spin_lock_init (&dev->lock);
1196 dev->gadget = gadget; 1195 dev->gadget = gadget;
1197 set_gadget_data (gadget, dev); 1196 set_gadget_data (gadget, dev);
@@ -1224,12 +1223,6 @@ autoconf_fail:
1224 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 1223 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1225 } 1224 }
1226 1225
1227 if (gadget->is_otg) {
1228 otg_descriptor.bmAttributes |= USB_OTG_HNP,
1229 source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1230 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1231 }
1232
1233 usb_gadget_set_selfpowered (gadget); 1226 usb_gadget_set_selfpowered (gadget);
1234 1227
1235 init_timer (&dev->resume); 1228 init_timer (&dev->resume);
@@ -1294,7 +1287,7 @@ static struct usb_gadget_driver zero_driver = {
1294#endif 1287#endif
1295 .function = (char *) longname, 1288 .function = (char *) longname,
1296 .bind = zero_bind, 1289 .bind = zero_bind,
1297 .unbind = zero_unbind, 1290 .unbind = __exit_p(zero_unbind),
1298 1291
1299 .setup = zero_setup, 1292 .setup = zero_setup,
1300 .disconnect = zero_disconnect, 1293 .disconnect = zero_disconnect,
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index be3fd9bce573..e27b79a3c05f 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -6,7 +6,7 @@ comment "USB Host Controller Drivers"
6 6
7config USB_EHCI_HCD 7config USB_EHCI_HCD
8 tristate "EHCI HCD (USB 2.0) support" 8 tristate "EHCI HCD (USB 2.0) support"
9 depends on USB && PCI 9 depends on USB && USB_ARCH_HAS_EHCI
10 ---help--- 10 ---help---
11 The Enhanced Host Controller Interface (EHCI) is standard for USB 2.0 11 The Enhanced Host Controller Interface (EHCI) is standard for USB 2.0
12 "high speed" (480 Mbit/sec, 60 Mbyte/sec) host controller hardware. 12 "high speed" (480 Mbit/sec, 60 Mbyte/sec) host controller hardware.
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
new file mode 100644
index 000000000000..63eadeec1324
--- /dev/null
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -0,0 +1,297 @@
1/*
2 * EHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
5 *
6 * Bus Glue for AMD Alchemy Au1xxx
7 *
8 * Based on "ohci-au1xxx.c" by Matt Porter <mporter@kernel.crashing.org>
9 *
10 * Modified for AMD Alchemy Au1200 EHC
11 * by K.Boge <karsten.boge@amd.com>
12 *
13 * This file is licenced under the GPL.
14 */
15
16#include <linux/platform_device.h>
17#include <asm/mach-au1x00/au1000.h>
18
19#ifndef CONFIG_SOC_AU1200
20#error "this Alchemy chip doesn't have EHCI"
21#else /* Au1200 */
22
23#define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG)
24#define USB_MCFG_PFEN (1<<31)
25#define USB_MCFG_RDCOMB (1<<30)
26#define USB_MCFG_SSDEN (1<<23)
27#define USB_MCFG_PHYPLLEN (1<<19)
28#define USB_MCFG_EHCCLKEN (1<<17)
29#define USB_MCFG_UCAM (1<<7)
30#define USB_MCFG_EBMEN (1<<3)
31#define USB_MCFG_EMEMEN (1<<2)
32
33#define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN)
34
35#ifdef CONFIG_DMA_COHERENT
36#define USBH_ENABLE_INIT (USBH_ENABLE_CE \
37 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
38 | USB_MCFG_SSDEN | USB_MCFG_UCAM \
39 | USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
40#else
41#define USBH_ENABLE_INIT (USBH_ENABLE_CE \
42 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
43 | USB_MCFG_SSDEN \
44 | USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
45#endif
46#define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
47
48#endif /* Au1200 */
49
50extern int usb_disabled(void);
51
52/*-------------------------------------------------------------------------*/
53
54static void au1xxx_start_ehc(struct platform_device *dev)
55{
56 pr_debug(__FILE__ ": starting Au1xxx EHCI USB Controller\n");
57
58 /* write HW defaults again in case Yamon cleared them */
59 if (au_readl(USB_HOST_CONFIG) == 0) {
60 au_writel(0x00d02000, USB_HOST_CONFIG);
61 au_readl(USB_HOST_CONFIG);
62 udelay(1000);
63 }
64 /* enable host controller */
65 au_writel(USBH_ENABLE_CE | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
66 au_readl(USB_HOST_CONFIG);
67 udelay(1000);
68 au_writel(USBH_ENABLE_INIT | au_readl(USB_HOST_CONFIG),
69 USB_HOST_CONFIG);
70 au_readl(USB_HOST_CONFIG);
71 udelay(1000);
72
73 pr_debug(__FILE__ ": Clock to USB host has been enabled\n");
74}
75
76static void au1xxx_stop_ehc(struct platform_device *dev)
77{
78 pr_debug(__FILE__ ": stopping Au1xxx EHCI USB Controller\n");
79
80 /* Disable mem */
81 au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
82 udelay(1000);
83 /* Disable clock */
84 au_writel(~USB_MCFG_EHCCLKEN & au_readl(USB_HOST_CONFIG),
85 USB_HOST_CONFIG);
86 au_readl(USB_HOST_CONFIG);
87}
88
89/*-------------------------------------------------------------------------*/
90
91/* configure so an HC device and id are always provided */
92/* always called with process context; sleeping is OK */
93
94/**
95 * usb_ehci_au1xxx_probe - initialize Au1xxx-based HCDs
96 * Context: !in_interrupt()
97 *
98 * Allocates basic resources for this USB host controller, and
99 * then invokes the start() method for the HCD associated with it
100 * through the hotplug entry's driver_data.
101 *
102 */
103int usb_ehci_au1xxx_probe(const struct hc_driver *driver,
104 struct usb_hcd **hcd_out, struct platform_device *dev)
105{
106 int retval;
107 struct usb_hcd *hcd;
108 struct ehci_hcd *ehci;
109
110#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
111
112 /* Au1200 AB USB does not support coherent memory */
113 if (!(read_c0_prid() & 0xff)) {
114 pr_info("%s: this is chip revision AB!\n", dev->dev.name);
115 pr_info("%s: update your board or re-configure the kernel\n",
116 dev->dev.name);
117 return -ENODEV;
118 }
119#endif
120
121 au1xxx_start_ehc(dev);
122
123 if (dev->resource[1].flags != IORESOURCE_IRQ) {
124 pr_debug("resource[1] is not IORESOURCE_IRQ");
125 retval = -ENOMEM;
126 }
127 hcd = usb_create_hcd(driver, &dev->dev, "Au1xxx");
128 if (!hcd)
129 return -ENOMEM;
130 hcd->rsrc_start = dev->resource[0].start;
131 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
132
133 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
134 pr_debug("request_mem_region failed");
135 retval = -EBUSY;
136 goto err1;
137 }
138
139 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
140 if (!hcd->regs) {
141 pr_debug("ioremap failed");
142 retval = -ENOMEM;
143 goto err2;
144 }
145
146 ehci = hcd_to_ehci(hcd);
147 ehci->caps = hcd->regs;
148 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
149 /* cache this readonly data; minimize chip reads */
150 ehci->hcs_params = readl(&ehci->caps->hcs_params);
151
152 /* ehci_hcd_init(hcd_to_ehci(hcd)); */
153
154 retval =
155 usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT | SA_SHIRQ);
156 if (retval == 0)
157 return retval;
158
159 au1xxx_stop_ehc(dev);
160 iounmap(hcd->regs);
161err2:
162 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
163err1:
164 usb_put_hcd(hcd);
165 return retval;
166}
167
168/* may be called without controller electrically present */
169/* may be called with controller, bus, and devices active */
170
171/**
172 * usb_ehci_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
173 * @dev: USB Host Controller being removed
174 * Context: !in_interrupt()
175 *
176 * Reverses the effect of usb_ehci_hcd_au1xxx_probe(), first invoking
177 * the HCD's stop() method. It is always called from a thread
178 * context, normally "rmmod", "apmd", or something similar.
179 *
180 */
181void usb_ehci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
182{
183 usb_remove_hcd(hcd);
184 iounmap(hcd->regs);
185 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
186 usb_put_hcd(hcd);
187 au1xxx_stop_ehc(dev);
188}
189
190/*-------------------------------------------------------------------------*/
191
192static const struct hc_driver ehci_au1xxx_hc_driver = {
193 .description = hcd_name,
194 .product_desc = "Au1xxx EHCI",
195 .hcd_priv_size = sizeof(struct ehci_hcd),
196
197 /*
198 * generic hardware linkage
199 */
200 .irq = ehci_irq,
201 .flags = HCD_MEMORY | HCD_USB2,
202
203 /*
204 * basic lifecycle operations
205 */
206 .reset = ehci_init,
207 .start = ehci_run,
208 .stop = ehci_stop,
209
210 /*
211 * managing i/o requests and associated device resources
212 */
213 .urb_enqueue = ehci_urb_enqueue,
214 .urb_dequeue = ehci_urb_dequeue,
215 .endpoint_disable = ehci_endpoint_disable,
216
217 /*
218 * scheduling support
219 */
220 .get_frame_number = ehci_get_frame,
221
222 /*
223 * root hub support
224 */
225 .hub_status_data = ehci_hub_status_data,
226 .hub_control = ehci_hub_control,
227#ifdef CONFIG_PM
228 .hub_suspend = ehci_hub_suspend,
229 .hub_resume = ehci_hub_resume,
230#endif
231};
232
233/*-------------------------------------------------------------------------*/
234
235static int ehci_hcd_au1xxx_drv_probe(struct device *dev)
236{
237 struct platform_device *pdev = to_platform_device(dev);
238 struct usb_hcd *hcd = NULL;
239 int ret;
240
241 pr_debug("In ehci_hcd_au1xxx_drv_probe\n");
242
243 if (usb_disabled())
244 return -ENODEV;
245
246 ret = usb_ehci_au1xxx_probe(&ehci_au1xxx_hc_driver, &hcd, pdev);
247 return ret;
248}
249
250static int ehci_hcd_au1xxx_drv_remove(struct device *dev)
251{
252 struct platform_device *pdev = to_platform_device(dev);
253 struct usb_hcd *hcd = dev_get_drvdata(dev);
254
255 usb_ehci_au1xxx_remove(hcd, pdev);
256 return 0;
257}
258
259 /*TBD*/
260/*static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
261{
262 struct platform_device *pdev = to_platform_device(dev);
263 struct usb_hcd *hcd = dev_get_drvdata(dev);
264
265 return 0;
266}
267static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
268{
269 struct platform_device *pdev = to_platform_device(dev);
270 struct usb_hcd *hcd = dev_get_drvdata(dev);
271
272 return 0;
273}
274*/
275static struct device_driver ehci_hcd_au1xxx_driver = {
276 .name = "au1xxx-ehci",
277 .bus = &platform_bus_type,
278 .probe = ehci_hcd_au1xxx_drv_probe,
279 .remove = ehci_hcd_au1xxx_drv_remove,
280 /*.suspend = ehci_hcd_au1xxx_drv_suspend, */
281 /*.resume = ehci_hcd_au1xxx_drv_resume, */
282};
283
284static int __init ehci_hcd_au1xxx_init(void)
285{
286 pr_debug(DRIVER_INFO " (Au1xxx)\n");
287
288 return driver_register(&ehci_hcd_au1xxx_driver);
289}
290
291static void __exit ehci_hcd_au1xxx_cleanup(void)
292{
293 driver_unregister(&ehci_hcd_au1xxx_driver);
294}
295
296module_init(ehci_hcd_au1xxx_init);
297module_exit(ehci_hcd_au1xxx_cleanup);
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
new file mode 100644
index 000000000000..f985f121a245
--- /dev/null
+++ b/drivers/usb/host/ehci-fsl.c
@@ -0,0 +1,366 @@
1/*
2 * (C) Copyright David Brownell 2000-2002
3 * Copyright (c) 2005 MontaVista Software
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 * Ported to 834x by Randy Vinson <rvinson@mvista.com> using code provided
20 * by Hunter Wu.
21 */
22
23#include <linux/platform_device.h>
24#include <linux/fsl_devices.h>
25
26#include "ehci-fsl.h"
27
28/* FIXME: Power Managment is un-ported so temporarily disable it */
29#undef CONFIG_PM
30
31/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */
32
33/* configure so an HC device and id are always provided */
34/* always called with process context; sleeping is OK */
35
36/**
37 * usb_hcd_fsl_probe - initialize FSL-based HCDs
38 * @drvier: Driver to be used for this HCD
39 * @pdev: USB Host Controller being probed
40 * Context: !in_interrupt()
41 *
42 * Allocates basic resources for this USB host controller.
43 *
44 */
45int usb_hcd_fsl_probe(const struct hc_driver *driver,
46 struct platform_device *pdev)
47{
48 struct fsl_usb2_platform_data *pdata;
49 struct usb_hcd *hcd;
50 struct resource *res;
51 int irq;
52 int retval;
53 unsigned int temp;
54
55 pr_debug("initializing FSL-SOC USB Controller\n");
56
57 /* Need platform data for setup */
58 pdata = (struct fsl_usb2_platform_data *)pdev->dev.platform_data;
59 if (!pdata) {
60 dev_err(&pdev->dev,
61 "No platform data for %s.\n", pdev->dev.bus_id);
62 return -ENODEV;
63 }
64
65 /*
66 * This is a host mode driver, verify that we're supposed to be
67 * in host mode.
68 */
69 if (!((pdata->operating_mode == FSL_USB2_DR_HOST) ||
70 (pdata->operating_mode == FSL_USB2_MPH_HOST))) {
71 dev_err(&pdev->dev,
72 "Non Host Mode configured for %s. Wrong driver linked.\n",
73 pdev->dev.bus_id);
74 return -ENODEV;
75 }
76
77 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
78 if (!res) {
79 dev_err(&pdev->dev,
80 "Found HC with no IRQ. Check %s setup!\n",
81 pdev->dev.bus_id);
82 return -ENODEV;
83 }
84 irq = res->start;
85
86 hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id);
87 if (!hcd) {
88 retval = -ENOMEM;
89 goto err1;
90 }
91
92 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
93 if (!res) {
94 dev_err(&pdev->dev,
95 "Found HC with no register addr. Check %s setup!\n",
96 pdev->dev.bus_id);
97 retval = -ENODEV;
98 goto err2;
99 }
100 hcd->rsrc_start = res->start;
101 hcd->rsrc_len = res->end - res->start + 1;
102 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
103 driver->description)) {
104 dev_dbg(&pdev->dev, "controller already in use\n");
105 retval = -EBUSY;
106 goto err2;
107 }
108 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
109
110 if (hcd->regs == NULL) {
111 dev_dbg(&pdev->dev, "error mapping memory\n");
112 retval = -EFAULT;
113 goto err3;
114 }
115
116 /* Enable USB controller */
117 temp = in_be32(hcd->regs + 0x500);
118 out_be32(hcd->regs + 0x500, temp | 0x4);
119
120 /* Set to Host mode */
121 temp = in_le32(hcd->regs + 0x1a8);
122 out_le32(hcd->regs + 0x1a8, temp | 0x3);
123
124 retval = usb_add_hcd(hcd, irq, SA_SHIRQ);
125 if (retval != 0)
126 goto err4;
127 return retval;
128
129 err4:
130 iounmap(hcd->regs);
131 err3:
132 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
133 err2:
134 usb_put_hcd(hcd);
135 err1:
136 dev_err(&pdev->dev, "init %s fail, %d\n", pdev->dev.bus_id, retval);
137 return retval;
138}
139
140/* may be called without controller electrically present */
141/* may be called with controller, bus, and devices active */
142
143/**
144 * usb_hcd_fsl_remove - shutdown processing for FSL-based HCDs
145 * @dev: USB Host Controller being removed
146 * Context: !in_interrupt()
147 *
148 * Reverses the effect of usb_hcd_fsl_probe().
149 *
150 */
151void usb_hcd_fsl_remove(struct usb_hcd *hcd, struct platform_device *pdev)
152{
153 usb_remove_hcd(hcd);
154 iounmap(hcd->regs);
155 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
156 usb_put_hcd(hcd);
157}
158
159static void mpc83xx_setup_phy(struct ehci_hcd *ehci,
160 enum fsl_usb2_phy_modes phy_mode,
161 unsigned int port_offset)
162{
163 u32 portsc = 0;
164 switch (phy_mode) {
165 case FSL_USB2_PHY_ULPI:
166 portsc |= PORT_PTS_ULPI;
167 break;
168 case FSL_USB2_PHY_SERIAL:
169 portsc |= PORT_PTS_SERIAL;
170 break;
171 case FSL_USB2_PHY_UTMI_WIDE:
172 portsc |= PORT_PTS_PTW;
173 /* fall through */
174 case FSL_USB2_PHY_UTMI:
175 portsc |= PORT_PTS_UTMI;
176 break;
177 case FSL_USB2_PHY_NONE:
178 break;
179 }
180 writel(portsc, &ehci->regs->port_status[port_offset]);
181}
182
183static void mpc83xx_usb_setup(struct usb_hcd *hcd)
184{
185 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
186 struct fsl_usb2_platform_data *pdata;
187 void __iomem *non_ehci = hcd->regs;
188
189 pdata =
190 (struct fsl_usb2_platform_data *)hcd->self.controller->
191 platform_data;
192 /* Enable PHY interface in the control reg. */
193 out_be32(non_ehci + FSL_SOC_USB_CTRL, 0x00000004);
194 out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0000001b);
195
196 if (pdata->operating_mode == FSL_USB2_DR_HOST)
197 mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
198
199 if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
200 unsigned int chip, rev, svr;
201
202 svr = mfspr(SPRN_SVR);
203 chip = svr >> 16;
204 rev = (svr >> 4) & 0xf;
205
206 /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */
207 if ((rev == 1) && (chip >= 0x8050) && (chip <= 0x8055))
208 ehci->has_fsl_port_bug = 1;
209
210 if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
211 mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
212 if (pdata->port_enables & FSL_USB2_PORT1_ENABLED)
213 mpc83xx_setup_phy(ehci, pdata->phy_mode, 1);
214 }
215
216 /* put controller in host mode. */
217 writel(0x00000003, non_ehci + FSL_SOC_USB_USBMODE);
218 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c);
219 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040);
220 out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001);
221}
222
223/* called after powerup, by probe or system-pm "wakeup" */
224static int ehci_fsl_reinit(struct ehci_hcd *ehci)
225{
226 mpc83xx_usb_setup(ehci_to_hcd(ehci));
227 ehci_port_power(ehci, 0);
228
229 return 0;
230}
231
232/* called during probe() after chip reset completes */
233static int ehci_fsl_setup(struct usb_hcd *hcd)
234{
235 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
236 int retval;
237
238 /* EHCI registers start at offset 0x100 */
239 ehci->caps = hcd->regs + 0x100;
240 ehci->regs = hcd->regs + 0x100 +
241 HC_LENGTH(readl(&ehci->caps->hc_capbase));
242 dbg_hcs_params(ehci, "reset");
243 dbg_hcc_params(ehci, "reset");
244
245 /* cache this readonly data; minimize chip reads */
246 ehci->hcs_params = readl(&ehci->caps->hcs_params);
247
248 retval = ehci_halt(ehci);
249 if (retval)
250 return retval;
251
252 /* data structure init */
253 retval = ehci_init(hcd);
254 if (retval)
255 return retval;
256
257 ehci->is_tdi_rh_tt = 1;
258
259 ehci->sbrn = 0x20;
260
261 ehci_reset(ehci);
262
263 retval = ehci_fsl_reinit(ehci);
264 return retval;
265}
266
267static const struct hc_driver ehci_fsl_hc_driver = {
268 .description = hcd_name,
269 .product_desc = "Freescale On-Chip EHCI Host Controller",
270 .hcd_priv_size = sizeof(struct ehci_hcd),
271
272 /*
273 * generic hardware linkage
274 */
275 .irq = ehci_irq,
276 .flags = HCD_USB2,
277
278 /*
279 * basic lifecycle operations
280 */
281 .reset = ehci_fsl_setup,
282 .start = ehci_run,
283#ifdef CONFIG_PM
284 .suspend = ehci_bus_suspend,
285 .resume = ehci_bus_resume,
286#endif
287 .stop = ehci_stop,
288
289 /*
290 * managing i/o requests and associated device resources
291 */
292 .urb_enqueue = ehci_urb_enqueue,
293 .urb_dequeue = ehci_urb_dequeue,
294 .endpoint_disable = ehci_endpoint_disable,
295
296 /*
297 * scheduling support
298 */
299 .get_frame_number = ehci_get_frame,
300
301 /*
302 * root hub support
303 */
304 .hub_status_data = ehci_hub_status_data,
305 .hub_control = ehci_hub_control,
306 .bus_suspend = ehci_bus_suspend,
307 .bus_resume = ehci_bus_resume,
308};
309
310static int ehci_fsl_drv_probe(struct platform_device *pdev)
311{
312 if (usb_disabled())
313 return -ENODEV;
314
315 return usb_hcd_fsl_probe(&ehci_fsl_hc_driver, pdev);
316}
317
318static int ehci_fsl_drv_remove(struct platform_device *pdev)
319{
320 struct usb_hcd *hcd = platform_get_drvdata(pdev);
321
322 usb_hcd_fsl_remove(hcd, pdev);
323
324 return 0;
325}
326
327static struct platform_driver ehci_fsl_dr_driver = {
328 .probe = ehci_fsl_drv_probe,
329 .remove = ehci_fsl_drv_remove,
330 .driver = {
331 .name = "fsl-usb2-dr",
332 },
333};
334
335static struct platform_driver ehci_fsl_mph_driver = {
336 .probe = ehci_fsl_drv_probe,
337 .remove = ehci_fsl_drv_remove,
338 .driver = {
339 .name = "fsl-usb2-mph",
340 },
341};
342
343static int __init ehci_fsl_init(void)
344{
345 int retval;
346
347 pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
348 hcd_name,
349 sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
350 sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
351
352 retval = platform_driver_register(&ehci_fsl_dr_driver);
353 if (retval)
354 return retval;
355
356 return platform_driver_register(&ehci_fsl_mph_driver);
357}
358
359static void __exit ehci_fsl_cleanup(void)
360{
361 platform_driver_unregister(&ehci_fsl_mph_driver);
362 platform_driver_unregister(&ehci_fsl_dr_driver);
363}
364
365module_init(ehci_fsl_init);
366module_exit(ehci_fsl_cleanup);
diff --git a/drivers/usb/host/ehci-fsl.h b/drivers/usb/host/ehci-fsl.h
new file mode 100644
index 000000000000..caac0d1967d0
--- /dev/null
+++ b/drivers/usb/host/ehci-fsl.h
@@ -0,0 +1,37 @@
1/* Copyright (c) 2005 freescale semiconductor
2 * Copyright (c) 2005 MontaVista Software
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18#ifndef _EHCI_FSL_H
19#define _EHCI_FSL_H
20
21/* offsets for the non-ehci registers in the FSL SOC USB controller */
22#define FSL_SOC_USB_ULPIVP 0x170
23#define FSL_SOC_USB_PORTSC1 0x184
24#define PORT_PTS_MSK (3<<30)
25#define PORT_PTS_UTMI (0<<30)
26#define PORT_PTS_ULPI (2<<30)
27#define PORT_PTS_SERIAL (3<<30)
28#define PORT_PTS_PTW (1<<28)
29#define FSL_SOC_USB_PORTSC2 0x188
30#define FSL_SOC_USB_USBMODE 0x1a8
31#define FSL_SOC_USB_SNOOP1 0x400 /* NOTE: big-endian */
32#define FSL_SOC_USB_SNOOP2 0x404 /* NOTE: big-endian */
33#define FSL_SOC_USB_AGECNTTHRSH 0x408 /* NOTE: big-endian */
34#define FSL_SOC_USB_SICTRL 0x40c /* NOTE: big-endian */
35#define FSL_SOC_USB_PRICTRL 0x410 /* NOTE: big-endian */
36#define FSL_SOC_USB_CTRL 0x500 /* NOTE: big-endian */
37#endif /* _EHCI_FSL_H */
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 9dd3d14c64f3..79f2d8b9bfb6 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -889,8 +889,19 @@ MODULE_LICENSE ("GPL");
889 889
890#ifdef CONFIG_PCI 890#ifdef CONFIG_PCI
891#include "ehci-pci.c" 891#include "ehci-pci.c"
892#define EHCI_BUS_GLUED
892#endif 893#endif
893 894
894#if !defined(CONFIG_PCI) 895#ifdef CONFIG_PPC_83xx
896#include "ehci-fsl.c"
897#define EHCI_BUS_GLUED
898#endif
899
900#ifdef CONFIG_SOC_AU1X00
901#include "ehci-au1xxx.c"
902#define EHCI_BUS_GLUED
903#endif
904
905#ifndef EHCI_BUS_GLUED
895#error "missing bus glue for ehci-hcd" 906#error "missing bus glue for ehci-hcd"
896#endif 907#endif
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 69b0b9be7a64..d03e3cad5ca8 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -359,6 +359,8 @@ static int ehci_hub_control (
359 case USB_PORT_FEAT_SUSPEND: 359 case USB_PORT_FEAT_SUSPEND:
360 if (temp & PORT_RESET) 360 if (temp & PORT_RESET)
361 goto error; 361 goto error;
362 if (ehci->no_selective_suspend)
363 break;
362 if (temp & PORT_SUSPEND) { 364 if (temp & PORT_SUSPEND) {
363 if ((temp & PORT_PE) == 0) 365 if ((temp & PORT_PE) == 0)
364 goto error; 366 goto error;
@@ -514,6 +516,8 @@ static int ehci_hub_control (
514 temp &= ~PORT_RWC_BITS; 516 temp &= ~PORT_RWC_BITS;
515 switch (wValue) { 517 switch (wValue) {
516 case USB_PORT_FEAT_SUSPEND: 518 case USB_PORT_FEAT_SUSPEND:
519 if (ehci->no_selective_suspend)
520 break;
517 if ((temp & PORT_PE) == 0 521 if ((temp & PORT_PE) == 0
518 || (temp & PORT_RESET) != 0) 522 || (temp & PORT_RESET) != 0)
519 goto error; 523 goto error;
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c
index 91c2ab43cbcc..766061e0260a 100644
--- a/drivers/usb/host/ehci-mem.c
+++ b/drivers/usb/host/ehci-mem.c
@@ -75,7 +75,6 @@ static void qh_destroy (struct kref *kref)
75 } 75 }
76 if (qh->dummy) 76 if (qh->dummy)
77 ehci_qtd_free (ehci, qh->dummy); 77 ehci_qtd_free (ehci, qh->dummy);
78 usb_put_dev (qh->dev);
79 dma_pool_free (ehci->qh_pool, qh, qh->qh_dma); 78 dma_pool_free (ehci->qh_pool, qh, qh->qh_dma);
80} 79}
81 80
@@ -221,13 +220,9 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags)
221 ehci->periodic [i] = EHCI_LIST_END; 220 ehci->periodic [i] = EHCI_LIST_END;
222 221
223 /* software shadow of hardware table */ 222 /* software shadow of hardware table */
224 ehci->pshadow = kmalloc (ehci->periodic_size * sizeof (void *), flags); 223 ehci->pshadow = kcalloc(ehci->periodic_size, sizeof(void *), flags);
225 if (ehci->pshadow == NULL) { 224 if (ehci->pshadow != NULL)
226 goto fail; 225 return 0;
227 }
228 memset (ehci->pshadow, 0, ehci->periodic_size * sizeof (void *));
229
230 return 0;
231 226
232fail: 227fail:
233 ehci_dbg (ehci, "couldn't init memory\n"); 228 ehci_dbg (ehci, "couldn't init memory\n");
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 3a6687df5594..1e03f1a5a5fd 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -106,11 +106,11 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
106 } 106 }
107 break; 107 break;
108 case PCI_VENDOR_ID_NVIDIA: 108 case PCI_VENDOR_ID_NVIDIA:
109 switch (pdev->device) {
109 /* NVidia reports that certain chips don't handle 110 /* NVidia reports that certain chips don't handle
110 * QH, ITD, or SITD addresses above 2GB. (But TD, 111 * QH, ITD, or SITD addresses above 2GB. (But TD,
111 * data buffer, and periodic schedule are normal.) 112 * data buffer, and periodic schedule are normal.)
112 */ 113 */
113 switch (pdev->device) {
114 case 0x003c: /* MCP04 */ 114 case 0x003c: /* MCP04 */
115 case 0x005b: /* CK804 */ 115 case 0x005b: /* CK804 */
116 case 0x00d8: /* CK8 */ 116 case 0x00d8: /* CK8 */
@@ -120,6 +120,14 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
120 ehci_warn(ehci, "can't enable NVidia " 120 ehci_warn(ehci, "can't enable NVidia "
121 "workaround for >2GB RAM\n"); 121 "workaround for >2GB RAM\n");
122 break; 122 break;
123 /* Some NForce2 chips have problems with selective suspend;
124 * fixed in newer silicon.
125 */
126 case 0x0068:
127 pci_read_config_dword(pdev, PCI_REVISION_ID, &temp);
128 if ((temp & 0xff) < 0xa4)
129 ehci->no_selective_suspend = 1;
130 break;
123 } 131 }
124 break; 132 break;
125 } 133 }
@@ -163,6 +171,21 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
163 device_init_wakeup(&pdev->dev, 1); 171 device_init_wakeup(&pdev->dev, 1);
164 } 172 }
165 173
174#ifdef CONFIG_USB_SUSPEND
175 /* REVISIT: the controller works fine for wakeup iff the root hub
176 * itself is "globally" suspended, but usbcore currently doesn't
177 * understand such things.
178 *
179 * System suspend currently expects to be able to suspend the entire
180 * device tree, device-at-a-time. If we failed selective suspend
181 * reports, system suspend would fail; so the root hub code must claim
182 * success. That's lying to usbcore, and it matters for for runtime
183 * PM scenarios with selective suspend and remote wakeup...
184 */
185 if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
186 ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
187#endif
188
166 retval = ehci_pci_reinit(ehci, pdev); 189 retval = ehci_pci_reinit(ehci, pdev);
167done: 190done:
168 return retval; 191 return retval;
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 9b13bf2fa98d..e469221e7ec3 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -702,7 +702,7 @@ qh_make (
702 } 702 }
703 703
704 /* support for tt scheduling, and access to toggles */ 704 /* support for tt scheduling, and access to toggles */
705 qh->dev = usb_get_dev (urb->dev); 705 qh->dev = urb->dev;
706 706
707 /* using TT? */ 707 /* using TT? */
708 switch (urb->dev->speed) { 708 switch (urb->dev->speed) {
@@ -721,7 +721,14 @@ qh_make (
721 info1 |= maxp << 16; 721 info1 |= maxp << 16;
722 722
723 info2 |= (EHCI_TUNE_MULT_TT << 30); 723 info2 |= (EHCI_TUNE_MULT_TT << 30);
724 info2 |= urb->dev->ttport << 23; 724
725 /* Some Freescale processors have an erratum in which the
726 * port number in the queue head was 0..N-1 instead of 1..N.
727 */
728 if (ehci_has_fsl_portno_bug(ehci))
729 info2 |= (urb->dev->ttport-1) << 23;
730 else
731 info2 |= urb->dev->ttport << 23;
725 732
726 /* set the address of the TT; for TDI's integrated 733 /* set the address of the TT; for TDI's integrated
727 * root hub tt, leave it zeroed. 734 * root hub tt, leave it zeroed.
@@ -1015,12 +1022,14 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1015 /* stop async schedule right now? */ 1022 /* stop async schedule right now? */
1016 if (unlikely (qh == ehci->async)) { 1023 if (unlikely (qh == ehci->async)) {
1017 /* can't get here without STS_ASS set */ 1024 /* can't get here without STS_ASS set */
1018 if (ehci_to_hcd(ehci)->state != HC_STATE_HALT) { 1025 if (ehci_to_hcd(ehci)->state != HC_STATE_HALT
1026 && !ehci->reclaim) {
1027 /* ... and CMD_IAAD clear */
1019 writel (cmd & ~CMD_ASE, &ehci->regs->command); 1028 writel (cmd & ~CMD_ASE, &ehci->regs->command);
1020 wmb (); 1029 wmb ();
1021 // handshake later, if we need to 1030 // handshake later, if we need to
1031 timer_action_done (ehci, TIMER_ASYNC_OFF);
1022 } 1032 }
1023 timer_action_done (ehci, TIMER_ASYNC_OFF);
1024 return; 1033 return;
1025 } 1034 }
1026 1035
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index ebcca9700671..5871944e6145 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -707,6 +707,7 @@ iso_stream_init (
707 } else { 707 } else {
708 u32 addr; 708 u32 addr;
709 int think_time; 709 int think_time;
710 int hs_transfers;
710 711
711 addr = dev->ttport << 24; 712 addr = dev->ttport << 24;
712 if (!ehci_is_TDI(ehci) 713 if (!ehci_is_TDI(ehci)
@@ -719,6 +720,7 @@ iso_stream_init (
719 think_time = dev->tt ? dev->tt->think_time : 0; 720 think_time = dev->tt ? dev->tt->think_time : 0;
720 stream->tt_usecs = NS_TO_US (think_time + usb_calc_bus_time ( 721 stream->tt_usecs = NS_TO_US (think_time + usb_calc_bus_time (
721 dev->speed, is_input, 1, maxp)); 722 dev->speed, is_input, 1, maxp));
723 hs_transfers = max (1u, (maxp + 187) / 188);
722 if (is_input) { 724 if (is_input) {
723 u32 tmp; 725 u32 tmp;
724 726
@@ -727,12 +729,11 @@ iso_stream_init (
727 stream->usecs = HS_USECS_ISO (1); 729 stream->usecs = HS_USECS_ISO (1);
728 stream->raw_mask = 1; 730 stream->raw_mask = 1;
729 731
730 /* pessimistic c-mask */ 732 /* c-mask as specified in USB 2.0 11.18.4 3.c */
731 tmp = usb_calc_bus_time (USB_SPEED_FULL, 1, 0, maxp) 733 tmp = (1 << (hs_transfers + 2)) - 1;
732 / (125 * 1000); 734 stream->raw_mask |= tmp << (8 + 2);
733 stream->raw_mask |= 3 << (tmp + 9);
734 } else 735 } else
735 stream->raw_mask = smask_out [maxp / 188]; 736 stream->raw_mask = smask_out [hs_transfers - 1];
736 bandwidth = stream->usecs + stream->c_usecs; 737 bandwidth = stream->usecs + stream->c_usecs;
737 bandwidth /= 1 << (interval + 2); 738 bandwidth /= 1 << (interval + 2);
738 739
@@ -863,9 +864,8 @@ iso_sched_alloc (unsigned packets, gfp_t mem_flags)
863 int size = sizeof *iso_sched; 864 int size = sizeof *iso_sched;
864 865
865 size += packets * sizeof (struct ehci_iso_packet); 866 size += packets * sizeof (struct ehci_iso_packet);
866 iso_sched = kmalloc (size, mem_flags); 867 iso_sched = kzalloc(size, mem_flags);
867 if (likely (iso_sched != NULL)) { 868 if (likely (iso_sched != NULL)) {
868 memset(iso_sched, 0, size);
869 INIT_LIST_HEAD (&iso_sched->td_list); 869 INIT_LIST_HEAD (&iso_sched->td_list);
870 } 870 }
871 return iso_sched; 871 return iso_sched;
@@ -1398,7 +1398,7 @@ itd_complete (
1398 */ 1398 */
1399 1399
1400 /* give urb back to the driver ... can be out-of-order */ 1400 /* give urb back to the driver ... can be out-of-order */
1401 dev = usb_get_dev (urb->dev); 1401 dev = urb->dev;
1402 ehci_urb_done (ehci, urb, regs); 1402 ehci_urb_done (ehci, urb, regs);
1403 urb = NULL; 1403 urb = NULL;
1404 1404
@@ -1417,7 +1417,6 @@ itd_complete (
1417 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); 1417 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
1418 } 1418 }
1419 iso_stream_put (ehci, stream); 1419 iso_stream_put (ehci, stream);
1420 usb_put_dev (dev);
1421 1420
1422 return 1; 1421 return 1;
1423} 1422}
@@ -1764,7 +1763,7 @@ sitd_complete (
1764 */ 1763 */
1765 1764
1766 /* give urb back to the driver */ 1765 /* give urb back to the driver */
1767 dev = usb_get_dev (urb->dev); 1766 dev = urb->dev;
1768 ehci_urb_done (ehci, urb, regs); 1767 ehci_urb_done (ehci, urb, regs);
1769 urb = NULL; 1768 urb = NULL;
1770 1769
@@ -1783,7 +1782,6 @@ sitd_complete (
1783 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); 1782 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
1784 } 1783 }
1785 iso_stream_put (ehci, stream); 1784 iso_stream_put (ehci, stream);
1786 usb_put_dev (dev);
1787 1785
1788 return 1; 1786 return 1;
1789} 1787}
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 18e257c2bdb5..679c1cdcc915 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -88,7 +88,12 @@ struct ehci_hcd { /* one per controller */
88 unsigned long next_statechange; 88 unsigned long next_statechange;
89 u32 command; 89 u32 command;
90 90
91 /* SILICON QUIRKS */
91 unsigned is_tdi_rh_tt:1; /* TDI roothub with TT */ 92 unsigned is_tdi_rh_tt:1; /* TDI roothub with TT */
93 unsigned no_selective_suspend:1;
94 unsigned has_fsl_port_bug:1; /* FreeScale */
95
96 u8 sbrn; /* packed release number */
92 97
93 /* irq statistics */ 98 /* irq statistics */
94#ifdef EHCI_STATS 99#ifdef EHCI_STATS
@@ -97,7 +102,6 @@ struct ehci_hcd { /* one per controller */
97#else 102#else
98# define COUNT(x) do {} while (0) 103# define COUNT(x) do {} while (0)
99#endif 104#endif
100 u8 sbrn; /* packed release number */
101}; 105};
102 106
103/* convert between an HCD pointer and the corresponding EHCI_HCD */ 107/* convert between an HCD pointer and the corresponding EHCI_HCD */
@@ -638,6 +642,18 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
638 642
639/*-------------------------------------------------------------------------*/ 643/*-------------------------------------------------------------------------*/
640 644
645#ifdef CONFIG_PPC_83xx
646/* Some Freescale processors have an erratum in which the TT
647 * port number in the queue head was 0..N-1 instead of 1..N.
648 */
649#define ehci_has_fsl_portno_bug(e) ((e)->has_fsl_port_bug)
650#else
651#define ehci_has_fsl_portno_bug(e) (0)
652#endif
653
654
655/*-------------------------------------------------------------------------*/
656
641#ifndef DEBUG 657#ifndef DEBUG
642#define STUB_DEBUG_FILES 658#define STUB_DEBUG_FILES
643#endif /* DEBUG */ 659#endif /* DEBUG */
diff --git a/drivers/usb/host/hc_crisv10.c b/drivers/usb/host/hc_crisv10.c
index 641268d7e6f3..2fe7fd19437b 100644
--- a/drivers/usb/host/hc_crisv10.c
+++ b/drivers/usb/host/hc_crisv10.c
@@ -2137,10 +2137,9 @@ static int etrax_usb_submit_bulk_urb(struct urb *urb)
2137 urb->status = -EINPROGRESS; 2137 urb->status = -EINPROGRESS;
2138 2138
2139 /* Setup the hcpriv data. */ 2139 /* Setup the hcpriv data. */
2140 urb_priv = kmalloc(sizeof(etrax_urb_priv_t), KMALLOC_FLAG); 2140 urb_priv = kzalloc(sizeof(etrax_urb_priv_t), KMALLOC_FLAG);
2141 assert(urb_priv != NULL); 2141 assert(urb_priv != NULL);
2142 /* This sets rx_offset to 0. */ 2142 /* This sets rx_offset to 0. */
2143 memset(urb_priv, 0, sizeof(etrax_urb_priv_t));
2144 urb_priv->urb_state = NOT_STARTED; 2143 urb_priv->urb_state = NOT_STARTED;
2145 urb->hcpriv = urb_priv; 2144 urb->hcpriv = urb_priv;
2146 2145
@@ -2475,10 +2474,9 @@ static int etrax_usb_submit_ctrl_urb(struct urb *urb)
2475 urb->status = -EINPROGRESS; 2474 urb->status = -EINPROGRESS;
2476 2475
2477 /* Setup the hcpriv data. */ 2476 /* Setup the hcpriv data. */
2478 urb_priv = kmalloc(sizeof(etrax_urb_priv_t), KMALLOC_FLAG); 2477 urb_priv = kzalloc(sizeof(etrax_urb_priv_t), KMALLOC_FLAG);
2479 assert(urb_priv != NULL); 2478 assert(urb_priv != NULL);
2480 /* This sets rx_offset to 0. */ 2479 /* This sets rx_offset to 0. */
2481 memset(urb_priv, 0, sizeof(etrax_urb_priv_t));
2482 urb_priv->urb_state = NOT_STARTED; 2480 urb_priv->urb_state = NOT_STARTED;
2483 urb->hcpriv = urb_priv; 2481 urb->hcpriv = urb_priv;
2484 2482
@@ -2767,9 +2765,8 @@ static void etrax_usb_add_to_intr_sb_list(struct urb *urb, int epid)
2767 maxlen = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); 2765 maxlen = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe));
2768 interval = urb->interval; 2766 interval = urb->interval;
2769 2767
2770 urb_priv = kmalloc(sizeof(etrax_urb_priv_t), KMALLOC_FLAG); 2768 urb_priv = kzalloc(sizeof(etrax_urb_priv_t), KMALLOC_FLAG);
2771 assert(urb_priv != NULL); 2769 assert(urb_priv != NULL);
2772 memset(urb_priv, 0, sizeof(etrax_urb_priv_t));
2773 urb->hcpriv = urb_priv; 2770 urb->hcpriv = urb_priv;
2774 2771
2775 first_ep = &TxIntrEPList[0]; 2772 first_ep = &TxIntrEPList[0];
@@ -2997,9 +2994,8 @@ static void etrax_usb_add_to_isoc_sb_list(struct urb *urb, int epid)
2997 2994
2998 prev_sb_desc = next_sb_desc = temp_sb_desc = NULL; 2995 prev_sb_desc = next_sb_desc = temp_sb_desc = NULL;
2999 2996
3000 urb_priv = kmalloc(sizeof(etrax_urb_priv_t), GFP_ATOMIC); 2997 urb_priv = kzalloc(sizeof(etrax_urb_priv_t), GFP_ATOMIC);
3001 assert(urb_priv != NULL); 2998 assert(urb_priv != NULL);
3002 memset(urb_priv, 0, sizeof(etrax_urb_priv_t));
3003 2999
3004 urb->hcpriv = urb_priv; 3000 urb->hcpriv = urb_priv;
3005 urb_priv->epid = epid; 3001 urb_priv->epid = epid;
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 972ce04889f8..e99210b7909b 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -724,7 +724,7 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
724 ep = hep->hcpriv; 724 ep = hep->hcpriv;
725 else { 725 else {
726 INIT_LIST_HEAD(&ep->schedule); 726 INIT_LIST_HEAD(&ep->schedule);
727 ep->udev = usb_get_dev(udev); 727 ep->udev = udev;
728 ep->epnum = epnum; 728 ep->epnum = epnum;
729 ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out); 729 ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
730 usb_settoggle(udev, epnum, is_out, 0); 730 usb_settoggle(udev, epnum, is_out, 0);
@@ -891,7 +891,6 @@ static void isp116x_endpoint_disable(struct usb_hcd *hcd,
891 if (!list_empty(&hep->urb_list)) 891 if (!list_empty(&hep->urb_list))
892 WARN("ep %p not empty?\n", ep); 892 WARN("ep %p not empty?\n", ep);
893 893
894 usb_put_dev(ep->udev);
895 kfree(ep); 894 kfree(ep);
896 hep->hcpriv = NULL; 895 hep->hcpriv = NULL;
897} 896}
@@ -1553,7 +1552,7 @@ static struct hc_driver isp116x_hc_driver = {
1553 1552
1554/*----------------------------------------------------------------*/ 1553/*----------------------------------------------------------------*/
1555 1554
1556static int __init_or_module isp116x_remove(struct platform_device *pdev) 1555static int isp116x_remove(struct platform_device *pdev)
1557{ 1556{
1558 struct usb_hcd *hcd = platform_get_drvdata(pdev); 1557 struct usb_hcd *hcd = platform_get_drvdata(pdev);
1559 struct isp116x *isp116x; 1558 struct isp116x *isp116x;
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
new file mode 100644
index 000000000000..980030d684d5
--- /dev/null
+++ b/drivers/usb/host/ohci-at91.c
@@ -0,0 +1,306 @@
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * Copyright (C) 2004 SAN People (Pty) Ltd.
5 * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
6 *
7 * AT91RM9200 Bus Glue
8 *
9 * Based on fragments of 2.4 driver by Rick Bronson.
10 * Based on ohci-omap.c
11 *
12 * This file is licenced under the GPL.
13 */
14
15#include <linux/clk.h>
16#include <linux/platform_device.h>
17
18#include <asm/mach-types.h>
19#include <asm/hardware.h>
20#include <asm/arch/board.h>
21
22#ifndef CONFIG_ARCH_AT91RM9200
23#error "This file is AT91RM9200 bus glue. CONFIG_ARCH_AT91RM9200 must be defined."
24#endif
25
26/* interface and function clocks */
27static struct clk *iclk, *fclk;
28
29extern int usb_disabled(void);
30
31/*-------------------------------------------------------------------------*/
32
33static void at91_start_hc(struct platform_device *pdev)
34{
35 struct usb_hcd *hcd = platform_get_drvdata(pdev);
36 struct ohci_regs __iomem *regs = hcd->regs;
37
38 dev_dbg(&pdev->dev, "starting AT91RM9200 OHCI USB Controller\n");
39
40 /*
41 * Start the USB clocks.
42 */
43 clk_enable(iclk);
44 clk_enable(fclk);
45
46 /*
47 * The USB host controller must remain in reset.
48 */
49 writel(0, &regs->control);
50}
51
52static void at91_stop_hc(struct platform_device *pdev)
53{
54 struct usb_hcd *hcd = platform_get_drvdata(pdev);
55 struct ohci_regs __iomem *regs = hcd->regs;
56
57 dev_dbg(&pdev->dev, "stopping AT91RM9200 OHCI USB Controller\n");
58
59 /*
60 * Put the USB host controller into reset.
61 */
62 writel(0, &regs->control);
63
64 /*
65 * Stop the USB clocks.
66 */
67 clk_disable(fclk);
68 clk_disable(iclk);
69}
70
71
72/*-------------------------------------------------------------------------*/
73
74static int usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
75
76/* configure so an HC device and id are always provided */
77/* always called with process context; sleeping is OK */
78
79
80/**
81 * usb_hcd_at91_probe - initialize AT91RM9200-based HCDs
82 * Context: !in_interrupt()
83 *
84 * Allocates basic resources for this USB host controller, and
85 * then invokes the start() method for the HCD associated with it
86 * through the hotplug entry's driver_data.
87 *
88 * Store this function in the HCD's struct pci_driver as probe().
89 */
90int usb_hcd_at91_probe (const struct hc_driver *driver, struct platform_device *pdev)
91{
92 int retval;
93 struct usb_hcd *hcd = NULL;
94
95 if (pdev->num_resources != 2) {
96 pr_debug("hcd probe: invalid num_resources");
97 return -ENODEV;
98 }
99
100 if ((pdev->resource[0].flags != IORESOURCE_MEM) || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
101 pr_debug("hcd probe: invalid resource type\n");
102 return -ENODEV;
103 }
104
105 hcd = usb_create_hcd(driver, &pdev->dev, "at91rm9200");
106 if (!hcd)
107 return -ENOMEM;
108 hcd->rsrc_start = pdev->resource[0].start;
109 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
110
111 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
112 pr_debug("request_mem_region failed\n");
113 retval = -EBUSY;
114 goto err1;
115 }
116
117 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
118 if (!hcd->regs) {
119 pr_debug("ioremap failed\n");
120 retval = -EIO;
121 goto err2;
122 }
123
124 iclk = clk_get(&pdev->dev, "ohci_clk");
125 fclk = clk_get(&pdev->dev, "uhpck");
126
127 at91_start_hc(pdev);
128 ohci_hcd_init(hcd_to_ohci(hcd));
129
130 retval = usb_add_hcd(hcd, pdev->resource[1].start, SA_INTERRUPT);
131 if (retval == 0)
132 return retval;
133
134 /* Error handling */
135 at91_stop_hc(pdev);
136
137 clk_put(fclk);
138 clk_put(iclk);
139
140 iounmap(hcd->regs);
141
142 err2:
143 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
144
145 err1:
146 usb_put_hcd(hcd);
147 return retval;
148}
149
150
151/* may be called without controller electrically present */
152/* may be called with controller, bus, and devices active */
153
154/**
155 * usb_hcd_at91_remove - shutdown processing for AT91RM9200-based HCDs
156 * @dev: USB Host Controller being removed
157 * Context: !in_interrupt()
158 *
159 * Reverses the effect of usb_hcd_at91_probe(), first invoking
160 * the HCD's stop() method. It is always called from a thread
161 * context, normally "rmmod", "apmd", or something similar.
162 *
163 */
164static int usb_hcd_at91_remove (struct usb_hcd *hcd, struct platform_device *pdev)
165{
166 usb_remove_hcd(hcd);
167 at91_stop_hc(pdev);
168 iounmap(hcd->regs);
169 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
170
171 clk_put(fclk);
172 clk_put(iclk);
173 fclk = iclk = NULL;
174
175 dev_set_drvdata(&pdev->dev, NULL);
176 return 0;
177}
178
179/*-------------------------------------------------------------------------*/
180
181static int __devinit
182ohci_at91_start (struct usb_hcd *hcd)
183{
184// struct at91_ohci_data *board = hcd->self.controller->platform_data;
185 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
186 int ret;
187
188 if ((ret = ohci_init(ohci)) < 0)
189 return ret;
190
191 if ((ret = ohci_run(ohci)) < 0) {
192 err("can't start %s", hcd->self.bus_name);
193 ohci_stop(hcd);
194 return ret;
195 }
196// hcd->self.root_hub->maxchild = board->ports;
197 return 0;
198}
199
200/*-------------------------------------------------------------------------*/
201
202static const struct hc_driver ohci_at91_hc_driver = {
203 .description = hcd_name,
204 .product_desc = "AT91RM9200 OHCI",
205 .hcd_priv_size = sizeof(struct ohci_hcd),
206
207 /*
208 * generic hardware linkage
209 */
210 .irq = ohci_irq,
211 .flags = HCD_USB11 | HCD_MEMORY,
212
213 /*
214 * basic lifecycle operations
215 */
216 .start = ohci_at91_start,
217 .stop = ohci_stop,
218
219 /*
220 * managing i/o requests and associated device resources
221 */
222 .urb_enqueue = ohci_urb_enqueue,
223 .urb_dequeue = ohci_urb_dequeue,
224 .endpoint_disable = ohci_endpoint_disable,
225
226 /*
227 * scheduling support
228 */
229 .get_frame_number = ohci_get_frame,
230
231 /*
232 * root hub support
233 */
234 .hub_status_data = ohci_hub_status_data,
235 .hub_control = ohci_hub_control,
236
237#ifdef CONFIG_PM
238 .hub_suspend = ohci_hub_suspend,
239 .hub_resume = ohci_hub_resume,
240#endif
241 .start_port_reset = ohci_start_port_reset,
242};
243
244/*-------------------------------------------------------------------------*/
245
246static int ohci_hcd_at91_drv_probe(struct platform_device *dev)
247{
248 return usb_hcd_at91_probe(&ohci_at91_hc_driver, dev);
249}
250
251static int ohci_hcd_at91_drv_remove(struct platform_device *dev)
252{
253 return usb_hcd_at91_remove(platform_get_drvdata(dev), dev);
254}
255
256#ifdef CONFIG_PM
257static int ohci_hcd_at91_drv_suspend(struct platform_device *dev, u32 state, u32 level)
258{
259 printk("%s(%s:%d): not implemented yet\n",
260 __func__, __FILE__, __LINE__);
261
262 clk_disable(fclk);
263
264 return 0;
265}
266
267static int ohci_hcd_at91_drv_resume(struct platform_device *dev, u32 state)
268{
269 printk("%s(%s:%d): not implemented yet\n",
270 __func__, __FILE__, __LINE__);
271
272 clk_enable(fclk);
273
274 return 0;
275}
276#else
277#define ohci_hcd_at91_drv_suspend NULL
278#define ohci_hcd_at91_drv_resume NULL
279#endif
280
281static struct platform_driver ohci_hcd_at91_driver = {
282 .probe = ohci_hcd_at91_drv_probe,
283 .remove = ohci_hcd_at91_drv_remove,
284 .suspend = ohci_hcd_at91_drv_suspend,
285 .resume = ohci_hcd_at91_drv_resume,
286 .driver = {
287 .name = "at91rm9200-ohci",
288 .owner = THIS_MODULE,
289 },
290};
291
292static int __init ohci_hcd_at91_init (void)
293{
294 if (usb_disabled())
295 return -ENODEV;
296
297 return platform_driver_register(&ohci_hcd_at91_driver);
298}
299
300static void __exit ohci_hcd_at91_cleanup (void)
301{
302 platform_driver_unregister(&ohci_hcd_at91_driver);
303}
304
305module_init (ohci_hcd_at91_init);
306module_exit (ohci_hcd_at91_cleanup);
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index db280ca7b7a0..a1c8b3b2fcc7 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -23,6 +23,8 @@
23 23
24#include <asm/mach-au1x00/au1000.h> 24#include <asm/mach-au1x00/au1000.h>
25 25
26#ifndef CONFIG_SOC_AU1200
27
26#define USBH_ENABLE_BE (1<<0) 28#define USBH_ENABLE_BE (1<<0)
27#define USBH_ENABLE_C (1<<1) 29#define USBH_ENABLE_C (1<<1)
28#define USBH_ENABLE_E (1<<2) 30#define USBH_ENABLE_E (1<<2)
@@ -37,21 +39,68 @@
37#error not byte order defined 39#error not byte order defined
38#endif 40#endif
39 41
42#else /* Au1200 */
43
44#define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG)
45#define USB_MCFG_PFEN (1<<31)
46#define USB_MCFG_RDCOMB (1<<30)
47#define USB_MCFG_SSDEN (1<<23)
48#define USB_MCFG_OHCCLKEN (1<<16)
49#define USB_MCFG_UCAM (1<<7)
50#define USB_MCFG_OBMEN (1<<1)
51#define USB_MCFG_OMEMEN (1<<0)
52
53#define USBH_ENABLE_CE USB_MCFG_OHCCLKEN
54#ifdef CONFIG_DMA_COHERENT
55#define USBH_ENABLE_INIT (USB_MCFG_OHCCLKEN \
56 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
57 | USB_MCFG_SSDEN | USB_MCFG_UCAM \
58 | USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
59#else
60#define USBH_ENABLE_INIT (USB_MCFG_OHCCLKEN \
61 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
62 | USB_MCFG_SSDEN \
63 | USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
64#endif
65#define USBH_DISABLE (USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
66
67#endif /* Au1200 */
68
40extern int usb_disabled(void); 69extern int usb_disabled(void);
41 70
42/*-------------------------------------------------------------------------*/ 71/*-------------------------------------------------------------------------*/
43 72
44static void au1xxx_start_hc(struct platform_device *dev) 73static void au1xxx_start_ohc(struct platform_device *dev)
45{ 74{
46 printk(KERN_DEBUG __FILE__ 75 printk(KERN_DEBUG __FILE__
47 ": starting Au1xxx OHCI USB Controller\n"); 76 ": starting Au1xxx OHCI USB Controller\n");
48 77
49 /* enable host controller */ 78 /* enable host controller */
79
80#ifndef CONFIG_SOC_AU1200
81
50 au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG); 82 au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG);
51 udelay(1000); 83 udelay(1000);
52 au_writel(USBH_ENABLE_INIT, USB_HOST_CONFIG); 84 au_writel(USBH_ENABLE_INIT, USB_HOST_CONFIG);
53 udelay(1000); 85 udelay(1000);
54 86
87#else /* Au1200 */
88
89 /* write HW defaults again in case Yamon cleared them */
90 if (au_readl(USB_HOST_CONFIG) == 0) {
91 au_writel(0x00d02000, USB_HOST_CONFIG);
92 au_readl(USB_HOST_CONFIG);
93 udelay(1000);
94 }
95 au_writel(USBH_ENABLE_CE | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
96 au_readl(USB_HOST_CONFIG);
97 udelay(1000);
98 au_writel(USBH_ENABLE_INIT | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
99 au_readl(USB_HOST_CONFIG);
100 udelay(1000);
101
102#endif /* Au1200 */
103
55 /* wait for reset complete (read register twice; see au1500 errata) */ 104 /* wait for reset complete (read register twice; see au1500 errata) */
56 while (au_readl(USB_HOST_CONFIG), 105 while (au_readl(USB_HOST_CONFIG),
57 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD)) 106 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
@@ -61,13 +110,25 @@ static void au1xxx_start_hc(struct platform_device *dev)
61 ": Clock to USB host has been enabled \n"); 110 ": Clock to USB host has been enabled \n");
62} 111}
63 112
64static void au1xxx_stop_hc(struct platform_device *dev) 113static void au1xxx_stop_ohc(struct platform_device *dev)
65{ 114{
66 printk(KERN_DEBUG __FILE__ 115 printk(KERN_DEBUG __FILE__
67 ": stopping Au1xxx OHCI USB Controller\n"); 116 ": stopping Au1xxx OHCI USB Controller\n");
68 117
118#ifndef CONFIG_SOC_AU1200
119
69 /* Disable clock */ 120 /* Disable clock */
70 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG); 121 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
122
123#else /* Au1200 */
124
125 /* Disable mem */
126 au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
127 udelay(1000);
128 /* Disable clock */
129 au_writel(~USBH_ENABLE_CE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
130 au_readl(USB_HOST_CONFIG);
131#endif /* Au1200 */
71} 132}
72 133
73 134
@@ -78,7 +139,7 @@ static void au1xxx_stop_hc(struct platform_device *dev)
78 139
79 140
80/** 141/**
81 * usb_hcd_au1xxx_probe - initialize Au1xxx-based HCDs 142 * usb_ohci_au1xxx_probe - initialize Au1xxx-based HCDs
82 * Context: !in_interrupt() 143 * Context: !in_interrupt()
83 * 144 *
84 * Allocates basic resources for this USB host controller, and 145 * Allocates basic resources for this USB host controller, and
@@ -86,14 +147,25 @@ static void au1xxx_stop_hc(struct platform_device *dev)
86 * through the hotplug entry's driver_data. 147 * through the hotplug entry's driver_data.
87 * 148 *
88 */ 149 */
89int usb_hcd_au1xxx_probe (const struct hc_driver *driver, 150static int usb_ohci_au1xxx_probe(const struct hc_driver *driver,
90 struct platform_device *dev) 151 struct platform_device *dev)
91{ 152{
92 int retval; 153 int retval;
93 struct usb_hcd *hcd; 154 struct usb_hcd *hcd;
94 155
95 if(dev->resource[1].flags != IORESOURCE_IRQ) { 156#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
96 pr_debug ("resource[1] is not IORESOURCE_IRQ"); 157 /* Au1200 AB USB does not support coherent memory */
158 if (!(read_c0_prid() & 0xff)) {
159 pr_info("%s: this is chip revision AB !!\n",
160 dev->dev.name);
161 pr_info("%s: update your board or re-configure the kernel\n",
162 dev->dev.name);
163 return -ENODEV;
164 }
165#endif
166
167 if (dev->resource[1].flags != IORESOURCE_IRQ) {
168 pr_debug("resource[1] is not IORESOURCE_IRQ\n");
97 return -ENOMEM; 169 return -ENOMEM;
98 } 170 }
99 171
@@ -104,26 +176,26 @@ int usb_hcd_au1xxx_probe (const struct hc_driver *driver,
104 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1; 176 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
105 177
106 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 178 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
107 pr_debug("request_mem_region failed"); 179 pr_debug("request_mem_region failed\n");
108 retval = -EBUSY; 180 retval = -EBUSY;
109 goto err1; 181 goto err1;
110 } 182 }
111 183
112 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 184 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
113 if (!hcd->regs) { 185 if (!hcd->regs) {
114 pr_debug("ioremap failed"); 186 pr_debug("ioremap failed\n");
115 retval = -ENOMEM; 187 retval = -ENOMEM;
116 goto err2; 188 goto err2;
117 } 189 }
118 190
119 au1xxx_start_hc(dev); 191 au1xxx_start_ohc(dev);
120 ohci_hcd_init(hcd_to_ohci(hcd)); 192 ohci_hcd_init(hcd_to_ohci(hcd));
121 193
122 retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT); 194 retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT | SA_SHIRQ);
123 if (retval == 0) 195 if (retval == 0)
124 return retval; 196 return retval;
125 197
126 au1xxx_stop_hc(dev); 198 au1xxx_stop_ohc(dev);
127 iounmap(hcd->regs); 199 iounmap(hcd->regs);
128 err2: 200 err2:
129 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 201 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
@@ -146,10 +218,10 @@ int usb_hcd_au1xxx_probe (const struct hc_driver *driver,
146 * context, normally "rmmod", "apmd", or something similar. 218 * context, normally "rmmod", "apmd", or something similar.
147 * 219 *
148 */ 220 */
149void usb_hcd_au1xxx_remove (struct usb_hcd *hcd, struct platform_device *dev) 221static void usb_ohci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
150{ 222{
151 usb_remove_hcd(hcd); 223 usb_remove_hcd(hcd);
152 au1xxx_stop_hc(dev); 224 au1xxx_stop_ohc(dev);
153 iounmap(hcd->regs); 225 iounmap(hcd->regs);
154 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 226 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
155 usb_put_hcd(hcd); 227 usb_put_hcd(hcd);
@@ -235,7 +307,7 @@ static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
235 if (usb_disabled()) 307 if (usb_disabled())
236 return -ENODEV; 308 return -ENODEV;
237 309
238 ret = usb_hcd_au1xxx_probe(&ohci_au1xxx_hc_driver, pdev); 310 ret = usb_ohci_au1xxx_probe(&ohci_au1xxx_hc_driver, pdev);
239 return ret; 311 return ret;
240} 312}
241 313
@@ -243,7 +315,7 @@ static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
243{ 315{
244 struct usb_hcd *hcd = platform_get_drvdata(pdev); 316 struct usb_hcd *hcd = platform_get_drvdata(pdev);
245 317
246 usb_hcd_au1xxx_remove(hcd, pdev); 318 usb_ohci_au1xxx_remove(hcd, pdev);
247 return 0; 319 return 0;
248} 320}
249 /*TBD*/ 321 /*TBD*/
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index a4b12404ae08..544f7589912f 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -443,11 +443,16 @@ ohci_reboot (struct notifier_block *block, unsigned long code, void *null)
443static int ohci_init (struct ohci_hcd *ohci) 443static int ohci_init (struct ohci_hcd *ohci)
444{ 444{
445 int ret; 445 int ret;
446 struct usb_hcd *hcd = ohci_to_hcd(ohci);
446 447
447 disable (ohci); 448 disable (ohci);
448 ohci->regs = ohci_to_hcd(ohci)->regs; 449 ohci->regs = hcd->regs;
449 ohci->next_statechange = jiffies; 450 ohci->next_statechange = jiffies;
450 451
452 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
453 * was never needed for most non-PCI systems ... remove the code?
454 */
455
451#ifndef IR_DISABLE 456#ifndef IR_DISABLE
452 /* SMM owns the HC? not for long! */ 457 /* SMM owns the HC? not for long! */
453 if (!no_handshake && ohci_readl (ohci, 458 if (!no_handshake && ohci_readl (ohci,
@@ -478,8 +483,10 @@ static int ohci_init (struct ohci_hcd *ohci)
478 483
479 /* Disable HC interrupts */ 484 /* Disable HC interrupts */
480 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 485 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
481 // flush the writes 486
482 (void) ohci_readl (ohci, &ohci->regs->control); 487 /* flush the writes, and save key bits like RWC */
488 if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
489 ohci->hc_control |= OHCI_CTRL_RWC;
483 490
484 /* Read the number of ports unless overridden */ 491 /* Read the number of ports unless overridden */
485 if (ohci->num_ports == 0) 492 if (ohci->num_ports == 0)
@@ -488,16 +495,19 @@ static int ohci_init (struct ohci_hcd *ohci)
488 if (ohci->hcca) 495 if (ohci->hcca)
489 return 0; 496 return 0;
490 497
491 ohci->hcca = dma_alloc_coherent (ohci_to_hcd(ohci)->self.controller, 498 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
492 sizeof *ohci->hcca, &ohci->hcca_dma, 0); 499 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
493 if (!ohci->hcca) 500 if (!ohci->hcca)
494 return -ENOMEM; 501 return -ENOMEM;
495 502
496 if ((ret = ohci_mem_init (ohci)) < 0) 503 if ((ret = ohci_mem_init (ohci)) < 0)
497 ohci_stop (ohci_to_hcd(ohci)); 504 ohci_stop (hcd);
505 else {
506 register_reboot_notifier (&ohci->reboot_notifier);
507 create_debug_files (ohci);
508 }
498 509
499 return ret; 510 return ret;
500
501} 511}
502 512
503/*-------------------------------------------------------------------------*/ 513/*-------------------------------------------------------------------------*/
@@ -510,6 +520,7 @@ static int ohci_run (struct ohci_hcd *ohci)
510{ 520{
511 u32 mask, temp; 521 u32 mask, temp;
512 int first = ohci->fminterval == 0; 522 int first = ohci->fminterval == 0;
523 struct usb_hcd *hcd = ohci_to_hcd(ohci);
513 524
514 disable (ohci); 525 disable (ohci);
515 526
@@ -525,18 +536,17 @@ static int ohci_run (struct ohci_hcd *ohci)
525 /* also: power/overcurrent flags in roothub.a */ 536 /* also: power/overcurrent flags in roothub.a */
526 } 537 }
527 538
528 /* Reset USB nearly "by the book". RemoteWakeupConnected 539 /* Reset USB nearly "by the book". RemoteWakeupConnected was
529 * saved if boot firmware (BIOS/SMM/...) told us it's connected 540 * saved if boot firmware (BIOS/SMM/...) told us it's connected,
530 * (for OHCI integrated on mainboard, it normally is) 541 * or if bus glue did the same (e.g. for PCI add-in cards with
542 * PCI PM support).
531 */ 543 */
532 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
533 ohci_dbg (ohci, "resetting from state '%s', control = 0x%x\n", 544 ohci_dbg (ohci, "resetting from state '%s', control = 0x%x\n",
534 hcfs2string (ohci->hc_control & OHCI_CTRL_HCFS), 545 hcfs2string (ohci->hc_control & OHCI_CTRL_HCFS),
535 ohci->hc_control); 546 ohci_readl (ohci, &ohci->regs->control));
536 547 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0
537 if (ohci->hc_control & OHCI_CTRL_RWC 548 && !device_may_wakeup(hcd->self.controller))
538 && !(ohci->flags & OHCI_QUIRK_AMD756)) 549 device_init_wakeup(hcd->self.controller, 1);
539 ohci_to_hcd(ohci)->can_wakeup = 1;
540 550
541 switch (ohci->hc_control & OHCI_CTRL_HCFS) { 551 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
542 case OHCI_USB_OPER: 552 case OHCI_USB_OPER:
@@ -632,7 +642,7 @@ retry:
632 ohci->hc_control &= OHCI_CTRL_RWC; 642 ohci->hc_control &= OHCI_CTRL_RWC;
633 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER; 643 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
634 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 644 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
635 ohci_to_hcd(ohci)->state = HC_STATE_RUNNING; 645 hcd->state = HC_STATE_RUNNING;
636 646
637 /* wake on ConnectStatusChange, matching external hubs */ 647 /* wake on ConnectStatusChange, matching external hubs */
638 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status); 648 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
@@ -667,15 +677,10 @@ retry:
667 677
668 // POTPGT delay is bits 24-31, in 2 ms units. 678 // POTPGT delay is bits 24-31, in 2 ms units.
669 mdelay ((temp >> 23) & 0x1fe); 679 mdelay ((temp >> 23) & 0x1fe);
670 ohci_to_hcd(ohci)->state = HC_STATE_RUNNING; 680 hcd->state = HC_STATE_RUNNING;
671 681
672 ohci_dump (ohci, 1); 682 ohci_dump (ohci, 1);
673 683
674 if (ohci_to_hcd(ohci)->self.root_hub == NULL) {
675 register_reboot_notifier (&ohci->reboot_notifier);
676 create_debug_files (ohci);
677 }
678
679 return 0; 684 return 0;
680} 685}
681 686
@@ -905,6 +910,10 @@ MODULE_LICENSE ("GPL");
905#include "ohci-ppc-soc.c" 910#include "ohci-ppc-soc.c"
906#endif 911#endif
907 912
913#ifdef CONFIG_ARCH_AT91RM9200
914#include "ohci-at91.c"
915#endif
916
908#if !(defined(CONFIG_PCI) \ 917#if !(defined(CONFIG_PCI) \
909 || defined(CONFIG_SA1111) \ 918 || defined(CONFIG_SA1111) \
910 || defined(CONFIG_ARCH_S3C2410) \ 919 || defined(CONFIG_ARCH_S3C2410) \
@@ -913,6 +922,7 @@ MODULE_LICENSE ("GPL");
913 || defined (CONFIG_PXA27x) \ 922 || defined (CONFIG_PXA27x) \
914 || defined (CONFIG_SOC_AU1X00) \ 923 || defined (CONFIG_SOC_AU1X00) \
915 || defined (CONFIG_USB_OHCI_HCD_PPC_SOC) \ 924 || defined (CONFIG_USB_OHCI_HCD_PPC_SOC) \
925 || defined (CONFIG_ARCH_AT91RM9200) \
916 ) 926 )
917#error "missing bus glue for ohci-hcd" 927#error "missing bus glue for ohci-hcd"
918#endif 928#endif
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 4b2226d77b34..0bb972b58336 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -107,7 +107,7 @@ static int ohci_bus_suspend (struct usb_hcd *hcd)
107 &ohci->regs->intrstatus); 107 &ohci->regs->intrstatus);
108 108
109 /* maybe resume can wake root hub */ 109 /* maybe resume can wake root hub */
110 if (hcd->remote_wakeup) 110 if (device_may_wakeup(&ohci_to_hcd(ohci)->self.root_hub->dev))
111 ohci->hc_control |= OHCI_CTRL_RWE; 111 ohci->hc_control |= OHCI_CTRL_RWE;
112 else 112 else
113 ohci->hc_control &= ~OHCI_CTRL_RWE; 113 ohci->hc_control &= ~OHCI_CTRL_RWE;
@@ -246,9 +246,9 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
246 (void) ohci_readl (ohci, &ohci->regs->control); 246 (void) ohci_readl (ohci, &ohci->regs->control);
247 msleep (3); 247 msleep (3);
248 248
249 temp = OHCI_CONTROL_INIT | OHCI_USB_OPER; 249 temp = ohci->hc_control;
250 if (hcd->can_wakeup) 250 temp &= OHCI_CTRL_RWC;
251 temp |= OHCI_CTRL_RWC; 251 temp |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
252 ohci->hc_control = temp; 252 ohci->hc_control = temp;
253 ohci_writel (ohci, temp, &ohci->regs->control); 253 ohci_writel (ohci, temp, &ohci->regs->control);
254 (void) ohci_readl (ohci, &ohci->regs->control); 254 (void) ohci_readl (ohci, &ohci->regs->control);
@@ -302,7 +302,7 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
302{ 302{
303 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 303 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
304 int i, changed = 0, length = 1; 304 int i, changed = 0, length = 1;
305 int can_suspend = hcd->can_wakeup; 305 int can_suspend = device_may_wakeup(&hcd->self.root_hub->dev);
306 unsigned long flags; 306 unsigned long flags;
307 307
308 spin_lock_irqsave (&ohci->lock, flags); 308 spin_lock_irqsave (&ohci->lock, flags);
@@ -354,7 +354,7 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
354 */ 354 */
355 if (!(status & RH_PS_CCS)) 355 if (!(status & RH_PS_CCS))
356 continue; 356 continue;
357 if ((status & RH_PS_PSS) && hcd->remote_wakeup) 357 if ((status & RH_PS_PSS) && can_suspend)
358 continue; 358 continue;
359 can_suspend = 0; 359 can_suspend = 0;
360 } 360 }
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 3785b3f7df1b..ca19abe01c53 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -286,7 +286,7 @@ void usb_hcd_omap_remove (struct usb_hcd *, struct platform_device *);
286int usb_hcd_omap_probe (const struct hc_driver *driver, 286int usb_hcd_omap_probe (const struct hc_driver *driver,
287 struct platform_device *pdev) 287 struct platform_device *pdev)
288{ 288{
289 int retval; 289 int retval, irq;
290 struct usb_hcd *hcd = 0; 290 struct usb_hcd *hcd = 0;
291 struct ohci_hcd *ohci; 291 struct ohci_hcd *ohci;
292 292
@@ -329,7 +329,12 @@ int usb_hcd_omap_probe (const struct hc_driver *driver,
329 if (retval < 0) 329 if (retval < 0)
330 goto err2; 330 goto err2;
331 331
332 retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), SA_INTERRUPT); 332 irq = platform_get_irq(pdev, 0);
333 if (irq < 0) {
334 retval = -ENXIO;
335 goto err2;
336 }
337 retval = usb_add_hcd(hcd, irq, SA_INTERRUPT);
333 if (retval == 0) 338 if (retval == 0)
334 return retval; 339 return retval;
335 340
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index 1b09dde068e1..1bfe96f4d045 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -35,7 +35,10 @@ ohci_pci_start (struct usb_hcd *hcd)
35 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 35 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
36 int ret; 36 int ret;
37 37
38 if(hcd->self.controller && hcd->self.controller->bus == &pci_bus_type) { 38 /* REVISIT this whole block should move to reset(), which handles
39 * all the other one-time init.
40 */
41 if (hcd->self.controller) {
39 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 42 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
40 43
41 /* AMD 756, for most chips (early revs), corrupts register 44 /* AMD 756, for most chips (early revs), corrupts register
@@ -45,7 +48,8 @@ ohci_pci_start (struct usb_hcd *hcd)
45 && pdev->device == 0x740c) { 48 && pdev->device == 0x740c) {
46 ohci->flags = OHCI_QUIRK_AMD756; 49 ohci->flags = OHCI_QUIRK_AMD756;
47 ohci_dbg (ohci, "AMD756 erratum 4 workaround\n"); 50 ohci_dbg (ohci, "AMD756 erratum 4 workaround\n");
48 // also somewhat erratum 10 (suspend/resume issues) 51 /* also erratum 10 (suspend/resume issues) */
52 device_init_wakeup(&hcd->self.root_hub->dev, 0);
49 } 53 }
50 54
51 /* FIXME for some of the early AMD 760 southbridges, OHCI 55 /* FIXME for some of the early AMD 760 southbridges, OHCI
@@ -88,6 +92,13 @@ ohci_pci_start (struct usb_hcd *hcd)
88 ohci_dbg (ohci, 92 ohci_dbg (ohci,
89 "enabled Compaq ZFMicro chipset quirk\n"); 93 "enabled Compaq ZFMicro chipset quirk\n");
90 } 94 }
95
96 /* RWC may not be set for add-in PCI cards, since boot
97 * firmware probably ignored them. This transfers PCI
98 * PM wakeup capabilities (once the PCI layer is fixed).
99 */
100 if (device_may_wakeup(&pdev->dev))
101 ohci->hc_control |= OHCI_CTRL_RWC;
91 } 102 }
92 103
93 /* NOTE: there may have already been a first reset, to 104 /* NOTE: there may have already been a first reset, to
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 517360b77d8e..a92343052751 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -853,7 +853,7 @@ static int sl811h_urb_enqueue(
853 853
854 } else { 854 } else {
855 INIT_LIST_HEAD(&ep->schedule); 855 INIT_LIST_HEAD(&ep->schedule);
856 ep->udev = usb_get_dev(udev); 856 ep->udev = udev;
857 ep->epnum = epnum; 857 ep->epnum = epnum;
858 ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out); 858 ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
859 ep->defctrl = SL11H_HCTLMASK_ARM | SL11H_HCTLMASK_ENABLE; 859 ep->defctrl = SL11H_HCTLMASK_ARM | SL11H_HCTLMASK_ENABLE;
@@ -1052,7 +1052,6 @@ sl811h_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep)
1052 if (!list_empty(&hep->urb_list)) 1052 if (!list_empty(&hep->urb_list))
1053 WARN("ep %p not empty?\n", ep); 1053 WARN("ep %p not empty?\n", ep);
1054 1054
1055 usb_put_dev(ep->udev);
1056 kfree(ep); 1055 kfree(ep);
1057 hep->hcpriv = NULL; 1056 hep->hcpriv = NULL;
1058} 1057}
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index 5832953086f8..e1239319655c 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -17,10 +17,13 @@
17 17
18#include "uhci-hcd.h" 18#include "uhci-hcd.h"
19 19
20static struct dentry *uhci_debugfs_root = NULL; 20#define uhci_debug_operations (* (struct file_operations *) NULL)
21static struct dentry *uhci_debugfs_root;
22
23#ifdef DEBUG
21 24
22/* Handle REALLY large printks so we don't overflow buffers */ 25/* Handle REALLY large printks so we don't overflow buffers */
23static inline void lprintk(char *buf) 26static void lprintk(char *buf)
24{ 27{
25 char *p; 28 char *p;
26 29
@@ -90,13 +93,59 @@ static int uhci_show_td(struct uhci_td *td, char *buf, int len, int space)
90 return out - buf; 93 return out - buf;
91} 94}
92 95
93static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space) 96static int uhci_show_urbp(struct urb_priv *urbp, char *buf, int len, int space)
94{ 97{
95 char *out = buf; 98 char *out = buf;
96 struct urb_priv *urbp;
97 struct list_head *head, *tmp;
98 struct uhci_td *td; 99 struct uhci_td *td;
99 int i = 0, checked = 0, prevactive = 0; 100 int i, nactive, ninactive;
101
102 if (len < 200)
103 return 0;
104
105 out += sprintf(out, "urb_priv [%p] ", urbp);
106 out += sprintf(out, "urb [%p] ", urbp->urb);
107 out += sprintf(out, "qh [%p] ", urbp->qh);
108 out += sprintf(out, "Dev=%d ", usb_pipedevice(urbp->urb->pipe));
109 out += sprintf(out, "EP=%x(%s) ", usb_pipeendpoint(urbp->urb->pipe),
110 (usb_pipein(urbp->urb->pipe) ? "IN" : "OUT"));
111
112 switch (usb_pipetype(urbp->urb->pipe)) {
113 case PIPE_ISOCHRONOUS: out += sprintf(out, "ISO"); break;
114 case PIPE_INTERRUPT: out += sprintf(out, "INT"); break;
115 case PIPE_BULK: out += sprintf(out, "BLK"); break;
116 case PIPE_CONTROL: out += sprintf(out, "CTL"); break;
117 }
118
119 out += sprintf(out, "%s", (urbp->fsbr ? " FSBR" : ""));
120
121 if (urbp->urb->status != -EINPROGRESS)
122 out += sprintf(out, " Status=%d", urbp->urb->status);
123 out += sprintf(out, "\n");
124
125 i = nactive = ninactive = 0;
126 list_for_each_entry(td, &urbp->td_list, list) {
127 if (++i <= 10 || debug > 2) {
128 out += sprintf(out, "%*s%d: ", space + 2, "", i);
129 out += uhci_show_td(td, out, len - (out - buf), 0);
130 } else {
131 if (td_status(td) & TD_CTRL_ACTIVE)
132 ++nactive;
133 else
134 ++ninactive;
135 }
136 }
137 if (nactive + ninactive > 0)
138 out += sprintf(out, "%*s[skipped %d inactive and %d active "
139 "TDs]\n",
140 space, "", ninactive, nactive);
141
142 return out - buf;
143}
144
145static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space)
146{
147 char *out = buf;
148 int i, nurbs;
100 __le32 element = qh_element(qh); 149 __le32 element = qh_element(qh);
101 150
102 /* Try to make sure there's enough memory */ 151 /* Try to make sure there's enough memory */
@@ -118,86 +167,40 @@ static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space)
118 if (!(element & ~(UHCI_PTR_QH | UHCI_PTR_DEPTH))) 167 if (!(element & ~(UHCI_PTR_QH | UHCI_PTR_DEPTH)))
119 out += sprintf(out, "%*s Element is NULL (bug?)\n", space, ""); 168 out += sprintf(out, "%*s Element is NULL (bug?)\n", space, "");
120 169
121 if (!qh->urbp) { 170 if (list_empty(&qh->queue)) {
122 out += sprintf(out, "%*s urbp == NULL\n", space, ""); 171 out += sprintf(out, "%*s queue is empty\n", space, "");
123 goto out; 172 } else {
124 } 173 struct urb_priv *urbp = list_entry(qh->queue.next,
125 174 struct urb_priv, node);
126 urbp = qh->urbp; 175 struct uhci_td *td = list_entry(urbp->td_list.next,
127 176 struct uhci_td, list);
128 head = &urbp->td_list; 177
129 tmp = head->next; 178 if (cpu_to_le32(td->dma_handle) != (element & ~UHCI_PTR_BITS))
130 179 out += sprintf(out, "%*s Element != First TD\n",
131 td = list_entry(tmp, struct uhci_td, list); 180 space, "");
132 181 i = nurbs = 0;
133 if (cpu_to_le32(td->dma_handle) != (element & ~UHCI_PTR_BITS)) 182 list_for_each_entry(urbp, &qh->queue, node) {
134 out += sprintf(out, "%*s Element != First TD\n", space, ""); 183 if (++i <= 10)
135 184 out += uhci_show_urbp(urbp, out,
136 while (tmp != head) { 185 len - (out - buf), space + 2);
137 struct uhci_td *td = list_entry(tmp, struct uhci_td, list); 186 else
138 187 ++nurbs;
139 tmp = tmp->next;
140
141 out += sprintf(out, "%*s%d: ", space + 2, "", i++);
142 out += uhci_show_td(td, out, len - (out - buf), 0);
143
144 if (i > 10 && !checked && prevactive && tmp != head &&
145 debug <= 2) {
146 struct list_head *ntmp = tmp;
147 struct uhci_td *ntd = td;
148 int active = 1, ni = i;
149
150 checked = 1;
151
152 while (ntmp != head && ntmp->next != head && active) {
153 ntd = list_entry(ntmp, struct uhci_td, list);
154
155 ntmp = ntmp->next;
156
157 active = td_status(ntd) & TD_CTRL_ACTIVE;
158
159 ni++;
160 }
161
162 if (active && ni > i) {
163 out += sprintf(out, "%*s[skipped %d active TDs]\n", space, "", ni - i);
164 tmp = ntmp;
165 td = ntd;
166 i = ni;
167 }
168 } 188 }
169 189 if (nurbs > 0)
170 prevactive = td_status(td) & TD_CTRL_ACTIVE; 190 out += sprintf(out, "%*s Skipped %d URBs\n",
191 space, "", nurbs);
171 } 192 }
172 193
173 if (list_empty(&urbp->queue_list) || urbp->queued) 194 if (qh->udev) {
174 goto out; 195 out += sprintf(out, "%*s Dummy TD\n", space, "");
175 196 out += uhci_show_td(qh->dummy_td, out, len - (out - buf), 0);
176 out += sprintf(out, "%*sQueued QHs:\n", -space, "--");
177
178 head = &urbp->queue_list;
179 tmp = head->next;
180
181 while (tmp != head) {
182 struct urb_priv *nurbp = list_entry(tmp, struct urb_priv,
183 queue_list);
184 tmp = tmp->next;
185
186 out += uhci_show_qh(nurbp->qh, out, len - (out - buf), space);
187 } 197 }
188 198
189out:
190 return out - buf; 199 return out - buf;
191} 200}
192 201
193#define show_frame_num() \
194 if (!shown) { \
195 shown = 1; \
196 out += sprintf(out, "- Frame %d\n", i); \
197 }
198
199#ifdef CONFIG_PROC_FS
200static const char * const qh_names[] = { 202static const char * const qh_names[] = {
203 "skel_unlink_qh", "skel_iso_qh",
201 "skel_int128_qh", "skel_int64_qh", 204 "skel_int128_qh", "skel_int64_qh",
202 "skel_int32_qh", "skel_int16_qh", 205 "skel_int32_qh", "skel_int16_qh",
203 "skel_int8_qh", "skel_int4_qh", 206 "skel_int8_qh", "skel_int4_qh",
@@ -206,12 +209,6 @@ static const char * const qh_names[] = {
206 "skel_bulk_qh", "skel_term_qh" 209 "skel_bulk_qh", "skel_term_qh"
207}; 210};
208 211
209#define show_qh_name() \
210 if (!shown) { \
211 shown = 1; \
212 out += sprintf(out, "- %s\n", qh_names[i]); \
213 }
214
215static int uhci_show_sc(int port, unsigned short status, char *buf, int len) 212static int uhci_show_sc(int port, unsigned short status, char *buf, int len)
216{ 213{
217 char *out = buf; 214 char *out = buf;
@@ -321,139 +318,29 @@ static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len)
321 return out - buf; 318 return out - buf;
322} 319}
323 320
324static int uhci_show_urbp(struct uhci_hcd *uhci, struct urb_priv *urbp, char *buf, int len)
325{
326 struct list_head *tmp;
327 char *out = buf;
328 int count = 0;
329
330 if (len < 200)
331 return 0;
332
333 out += sprintf(out, "urb_priv [%p] ", urbp);
334 out += sprintf(out, "urb [%p] ", urbp->urb);
335 out += sprintf(out, "qh [%p] ", urbp->qh);
336 out += sprintf(out, "Dev=%d ", usb_pipedevice(urbp->urb->pipe));
337 out += sprintf(out, "EP=%x(%s) ", usb_pipeendpoint(urbp->urb->pipe), (usb_pipein(urbp->urb->pipe) ? "IN" : "OUT"));
338
339 switch (usb_pipetype(urbp->urb->pipe)) {
340 case PIPE_ISOCHRONOUS: out += sprintf(out, "ISO "); break;
341 case PIPE_INTERRUPT: out += sprintf(out, "INT "); break;
342 case PIPE_BULK: out += sprintf(out, "BLK "); break;
343 case PIPE_CONTROL: out += sprintf(out, "CTL "); break;
344 }
345
346 out += sprintf(out, "%s", (urbp->fsbr ? "FSBR " : ""));
347 out += sprintf(out, "%s", (urbp->fsbr_timeout ? "FSBR_TO " : ""));
348
349 if (urbp->urb->status != -EINPROGRESS)
350 out += sprintf(out, "Status=%d ", urbp->urb->status);
351 //out += sprintf(out, "FSBRtime=%lx ",urbp->fsbrtime);
352
353 count = 0;
354 list_for_each(tmp, &urbp->td_list)
355 count++;
356 out += sprintf(out, "TDs=%d ",count);
357
358 if (urbp->queued)
359 out += sprintf(out, "queued\n");
360 else {
361 count = 0;
362 list_for_each(tmp, &urbp->queue_list)
363 count++;
364 out += sprintf(out, "queued URBs=%d\n", count);
365 }
366
367 return out - buf;
368}
369
370static int uhci_show_lists(struct uhci_hcd *uhci, char *buf, int len)
371{
372 char *out = buf;
373 struct list_head *head, *tmp;
374 int count;
375
376 out += sprintf(out, "Main list URBs:");
377 if (list_empty(&uhci->urb_list))
378 out += sprintf(out, " Empty\n");
379 else {
380 out += sprintf(out, "\n");
381 count = 0;
382 head = &uhci->urb_list;
383 tmp = head->next;
384 while (tmp != head) {
385 struct urb_priv *urbp = list_entry(tmp, struct urb_priv, urb_list);
386
387 out += sprintf(out, " %d: ", ++count);
388 out += uhci_show_urbp(uhci, urbp, out, len - (out - buf));
389 tmp = tmp->next;
390 }
391 }
392
393 out += sprintf(out, "Remove list URBs:");
394 if (list_empty(&uhci->urb_remove_list))
395 out += sprintf(out, " Empty\n");
396 else {
397 out += sprintf(out, "\n");
398 count = 0;
399 head = &uhci->urb_remove_list;
400 tmp = head->next;
401 while (tmp != head) {
402 struct urb_priv *urbp = list_entry(tmp, struct urb_priv, urb_list);
403
404 out += sprintf(out, " %d: ", ++count);
405 out += uhci_show_urbp(uhci, urbp, out, len - (out - buf));
406 tmp = tmp->next;
407 }
408 }
409
410 out += sprintf(out, "Complete list URBs:");
411 if (list_empty(&uhci->complete_list))
412 out += sprintf(out, " Empty\n");
413 else {
414 out += sprintf(out, "\n");
415 count = 0;
416 head = &uhci->complete_list;
417 tmp = head->next;
418 while (tmp != head) {
419 struct urb_priv *urbp = list_entry(tmp, struct urb_priv, urb_list);
420
421 out += sprintf(out, " %d: ", ++count);
422 out += uhci_show_urbp(uhci, urbp, out, len - (out - buf));
423 tmp = tmp->next;
424 }
425 }
426
427 return out - buf;
428}
429
430static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len) 321static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
431{ 322{
432 unsigned long flags;
433 char *out = buf; 323 char *out = buf;
434 int i, j; 324 int i, j;
435 struct uhci_qh *qh; 325 struct uhci_qh *qh;
436 struct uhci_td *td; 326 struct uhci_td *td;
437 struct list_head *tmp, *head; 327 struct list_head *tmp, *head;
438 328
439 spin_lock_irqsave(&uhci->lock, flags);
440
441 out += uhci_show_root_hub_state(uhci, out, len - (out - buf)); 329 out += uhci_show_root_hub_state(uhci, out, len - (out - buf));
442 out += sprintf(out, "HC status\n"); 330 out += sprintf(out, "HC status\n");
443 out += uhci_show_status(uhci, out, len - (out - buf)); 331 out += uhci_show_status(uhci, out, len - (out - buf));
332 if (debug <= 1)
333 return out - buf;
444 334
445 out += sprintf(out, "Frame List\n"); 335 out += sprintf(out, "Frame List\n");
446 for (i = 0; i < UHCI_NUMFRAMES; ++i) { 336 for (i = 0; i < UHCI_NUMFRAMES; ++i) {
447 int shown = 0;
448 td = uhci->frame_cpu[i]; 337 td = uhci->frame_cpu[i];
449 if (!td) 338 if (!td)
450 continue; 339 continue;
451 340
452 if (td->dma_handle != (dma_addr_t)uhci->frame[i]) { 341 out += sprintf(out, "- Frame %d\n", i); \
453 show_frame_num(); 342 if (td->dma_handle != (dma_addr_t)uhci->frame[i])
454 out += sprintf(out, " frame list does not match td->dma_handle!\n"); 343 out += sprintf(out, " frame list does not match td->dma_handle!\n");
455 }
456 show_frame_num();
457 344
458 head = &td->fl_list; 345 head = &td->fl_list;
459 tmp = head; 346 tmp = head;
@@ -467,14 +354,11 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
467 out += sprintf(out, "Skeleton QHs\n"); 354 out += sprintf(out, "Skeleton QHs\n");
468 355
469 for (i = 0; i < UHCI_NUM_SKELQH; ++i) { 356 for (i = 0; i < UHCI_NUM_SKELQH; ++i) {
470 int shown = 0; 357 int cnt = 0;
471 358
472 qh = uhci->skelqh[i]; 359 qh = uhci->skelqh[i];
473 360 out += sprintf(out, "- %s\n", qh_names[i]); \
474 if (debug > 1) { 361 out += uhci_show_qh(qh, out, len - (out - buf), 4);
475 show_qh_name();
476 out += uhci_show_qh(qh, out, len - (out - buf), 4);
477 }
478 362
479 /* Last QH is the Terminating QH, it's different */ 363 /* Last QH is the Terminating QH, it's different */
480 if (i == UHCI_NUM_SKELQH - 1) { 364 if (i == UHCI_NUM_SKELQH - 1) {
@@ -487,53 +371,37 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
487 continue; 371 continue;
488 } 372 }
489 373
490 j = (i < 7) ? 7 : i+1; /* Next skeleton */ 374 j = (i < 9) ? 9 : i+1; /* Next skeleton */
491 if (list_empty(&qh->list)) { 375 head = &qh->node;
492 if (i < UHCI_NUM_SKELQH - 1) {
493 if (qh->link !=
494 (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH)) {
495 show_qh_name();
496 out += sprintf(out, " skeleton QH not linked to next skeleton QH!\n");
497 }
498 }
499
500 continue;
501 }
502
503 show_qh_name();
504
505 head = &qh->list;
506 tmp = head->next; 376 tmp = head->next;
507 377
508 while (tmp != head) { 378 while (tmp != head) {
509 qh = list_entry(tmp, struct uhci_qh, list); 379 qh = list_entry(tmp, struct uhci_qh, node);
510
511 tmp = tmp->next; 380 tmp = tmp->next;
512 381 if (++cnt <= 10)
513 out += uhci_show_qh(qh, out, len - (out - buf), 4); 382 out += uhci_show_qh(qh, out,
383 len - (out - buf), 4);
514 } 384 }
385 if ((cnt -= 10) > 0)
386 out += sprintf(out, " Skipped %d QHs\n", cnt);
515 387
516 if (i < UHCI_NUM_SKELQH - 1) { 388 if (i > 1 && i < UHCI_NUM_SKELQH - 1) {
517 if (qh->link != 389 if (qh->link !=
518 (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH)) 390 (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH))
519 out += sprintf(out, " last QH not linked to next skeleton!\n"); 391 out += sprintf(out, " last QH not linked to next skeleton!\n");
520 } 392 }
521 } 393 }
522 394
523 if (debug > 2)
524 out += uhci_show_lists(uhci, out, len - (out - buf));
525
526 spin_unlock_irqrestore(&uhci->lock, flags);
527
528 return out - buf; 395 return out - buf;
529} 396}
530 397
398#ifdef CONFIG_DEBUG_FS
399
531#define MAX_OUTPUT (64 * 1024) 400#define MAX_OUTPUT (64 * 1024)
532 401
533struct uhci_debug { 402struct uhci_debug {
534 int size; 403 int size;
535 char *data; 404 char *data;
536 struct uhci_hcd *uhci;
537}; 405};
538 406
539static int uhci_debug_open(struct inode *inode, struct file *file) 407static int uhci_debug_open(struct inode *inode, struct file *file)
@@ -541,6 +409,7 @@ static int uhci_debug_open(struct inode *inode, struct file *file)
541 struct uhci_hcd *uhci = inode->u.generic_ip; 409 struct uhci_hcd *uhci = inode->u.generic_ip;
542 struct uhci_debug *up; 410 struct uhci_debug *up;
543 int ret = -ENOMEM; 411 int ret = -ENOMEM;
412 unsigned long flags;
544 413
545 lock_kernel(); 414 lock_kernel();
546 up = kmalloc(sizeof(*up), GFP_KERNEL); 415 up = kmalloc(sizeof(*up), GFP_KERNEL);
@@ -553,7 +422,11 @@ static int uhci_debug_open(struct inode *inode, struct file *file)
553 goto out; 422 goto out;
554 } 423 }
555 424
556 up->size = uhci_sprint_schedule(uhci, up->data, MAX_OUTPUT); 425 up->size = 0;
426 spin_lock_irqsave(&uhci->lock, flags);
427 if (uhci->is_initialized)
428 up->size = uhci_sprint_schedule(uhci, up->data, MAX_OUTPUT);
429 spin_unlock_irqrestore(&uhci->lock, flags);
557 430
558 file->private_data = up; 431 file->private_data = up;
559 432
@@ -604,15 +477,32 @@ static int uhci_debug_release(struct inode *inode, struct file *file)
604 return 0; 477 return 0;
605} 478}
606 479
480#undef uhci_debug_operations
607static struct file_operations uhci_debug_operations = { 481static struct file_operations uhci_debug_operations = {
482 .owner = THIS_MODULE,
608 .open = uhci_debug_open, 483 .open = uhci_debug_open,
609 .llseek = uhci_debug_lseek, 484 .llseek = uhci_debug_lseek,
610 .read = uhci_debug_read, 485 .read = uhci_debug_read,
611 .release = uhci_debug_release, 486 .release = uhci_debug_release,
612}; 487};
613 488
614#else /* CONFIG_DEBUG_FS */ 489#endif /* CONFIG_DEBUG_FS */
615 490
616#define uhci_debug_operations (* (struct file_operations *) NULL) 491#else /* DEBUG */
492
493static inline void lprintk(char *buf)
494{}
495
496static inline int uhci_show_qh(struct uhci_qh *qh, char *buf,
497 int len, int space)
498{
499 return 0;
500}
501
502static inline int uhci_sprint_schedule(struct uhci_hcd *uhci,
503 char *buf, int len)
504{
505 return 0;
506}
617 507
618#endif 508#endif
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index dfe121d35887..4edb8330c440 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -54,7 +54,7 @@
54/* 54/*
55 * Version Information 55 * Version Information
56 */ 56 */
57#define DRIVER_VERSION "v2.3" 57#define DRIVER_VERSION "v3.0"
58#define DRIVER_AUTHOR "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, \ 58#define DRIVER_AUTHOR "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, \
59Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, \ 59Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, \
60Alan Stern" 60Alan Stern"
@@ -68,12 +68,16 @@ Alan Stern"
68 * debug = 3, show all TDs in URBs when dumping 68 * debug = 3, show all TDs in URBs when dumping
69 */ 69 */
70#ifdef DEBUG 70#ifdef DEBUG
71#define DEBUG_CONFIGURED 1
71static int debug = 1; 72static int debug = 1;
72#else
73static int debug = 0;
74#endif
75module_param(debug, int, S_IRUGO | S_IWUSR); 73module_param(debug, int, S_IRUGO | S_IWUSR);
76MODULE_PARM_DESC(debug, "Debug level"); 74MODULE_PARM_DESC(debug, "Debug level");
75
76#else
77#define DEBUG_CONFIGURED 0
78#define debug 0
79#endif
80
77static char *errbuf; 81static char *errbuf;
78#define ERRBUF_LEN (32 * 1024) 82#define ERRBUF_LEN (32 * 1024)
79 83
@@ -338,6 +342,12 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs)
338 dev_err(uhci_dev(uhci), 342 dev_err(uhci_dev(uhci),
339 "host controller halted, " 343 "host controller halted, "
340 "very bad!\n"); 344 "very bad!\n");
345 if (debug > 1 && errbuf) {
346 /* Print the schedule for debugging */
347 uhci_sprint_schedule(uhci,
348 errbuf, ERRBUF_LEN);
349 lprintk(errbuf);
350 }
341 hc_died(uhci); 351 hc_died(uhci);
342 352
343 /* Force a callback in case there are 353 /* Force a callback in case there are
@@ -376,6 +386,14 @@ static void release_uhci(struct uhci_hcd *uhci)
376{ 386{
377 int i; 387 int i;
378 388
389 if (DEBUG_CONFIGURED) {
390 spin_lock_irq(&uhci->lock);
391 uhci->is_initialized = 0;
392 spin_unlock_irq(&uhci->lock);
393
394 debugfs_remove(uhci->dentry);
395 }
396
379 for (i = 0; i < UHCI_NUM_SKELQH; i++) 397 for (i = 0; i < UHCI_NUM_SKELQH; i++)
380 uhci_free_qh(uhci, uhci->skelqh[i]); 398 uhci_free_qh(uhci, uhci->skelqh[i]);
381 399
@@ -390,8 +408,6 @@ static void release_uhci(struct uhci_hcd *uhci)
390 dma_free_coherent(uhci_dev(uhci), 408 dma_free_coherent(uhci_dev(uhci),
391 UHCI_NUMFRAMES * sizeof(*uhci->frame), 409 UHCI_NUMFRAMES * sizeof(*uhci->frame),
392 uhci->frame, uhci->frame_dma_handle); 410 uhci->frame, uhci->frame_dma_handle);
393
394 debugfs_remove(uhci->dentry);
395} 411}
396 412
397static int uhci_reset(struct usb_hcd *hcd) 413static int uhci_reset(struct usb_hcd *hcd)
@@ -474,33 +490,29 @@ static int uhci_start(struct usb_hcd *hcd)
474 490
475 hcd->uses_new_polling = 1; 491 hcd->uses_new_polling = 1;
476 492
477 dentry = debugfs_create_file(hcd->self.bus_name,
478 S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root, uhci,
479 &uhci_debug_operations);
480 if (!dentry) {
481 dev_err(uhci_dev(uhci),
482 "couldn't create uhci debugfs entry\n");
483 retval = -ENOMEM;
484 goto err_create_debug_entry;
485 }
486 uhci->dentry = dentry;
487
488 uhci->fsbr = 0; 493 uhci->fsbr = 0;
489 uhci->fsbrtimeout = 0; 494 uhci->fsbrtimeout = 0;
490 495
491 spin_lock_init(&uhci->lock); 496 spin_lock_init(&uhci->lock);
492 INIT_LIST_HEAD(&uhci->qh_remove_list);
493 497
494 INIT_LIST_HEAD(&uhci->td_remove_list); 498 INIT_LIST_HEAD(&uhci->td_remove_list);
495 499 INIT_LIST_HEAD(&uhci->idle_qh_list);
496 INIT_LIST_HEAD(&uhci->urb_remove_list);
497
498 INIT_LIST_HEAD(&uhci->urb_list);
499
500 INIT_LIST_HEAD(&uhci->complete_list);
501 500
502 init_waitqueue_head(&uhci->waitqh); 501 init_waitqueue_head(&uhci->waitqh);
503 502
503 if (DEBUG_CONFIGURED) {
504 dentry = debugfs_create_file(hcd->self.bus_name,
505 S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root,
506 uhci, &uhci_debug_operations);
507 if (!dentry) {
508 dev_err(uhci_dev(uhci), "couldn't create uhci "
509 "debugfs entry\n");
510 retval = -ENOMEM;
511 goto err_create_debug_entry;
512 }
513 uhci->dentry = dentry;
514 }
515
504 uhci->frame = dma_alloc_coherent(uhci_dev(uhci), 516 uhci->frame = dma_alloc_coherent(uhci_dev(uhci),
505 UHCI_NUMFRAMES * sizeof(*uhci->frame), 517 UHCI_NUMFRAMES * sizeof(*uhci->frame),
506 &uhci->frame_dma_handle, 0); 518 &uhci->frame_dma_handle, 0);
@@ -540,7 +552,7 @@ static int uhci_start(struct usb_hcd *hcd)
540 } 552 }
541 553
542 for (i = 0; i < UHCI_NUM_SKELQH; i++) { 554 for (i = 0; i < UHCI_NUM_SKELQH; i++) {
543 uhci->skelqh[i] = uhci_alloc_qh(uhci); 555 uhci->skelqh[i] = uhci_alloc_qh(uhci, NULL, NULL);
544 if (!uhci->skelqh[i]) { 556 if (!uhci->skelqh[i]) {
545 dev_err(uhci_dev(uhci), "unable to allocate QH\n"); 557 dev_err(uhci_dev(uhci), "unable to allocate QH\n");
546 goto err_alloc_skelqh; 558 goto err_alloc_skelqh;
@@ -557,13 +569,17 @@ static int uhci_start(struct usb_hcd *hcd)
557 uhci->skel_int16_qh->link = 569 uhci->skel_int16_qh->link =
558 uhci->skel_int8_qh->link = 570 uhci->skel_int8_qh->link =
559 uhci->skel_int4_qh->link = 571 uhci->skel_int4_qh->link =
560 uhci->skel_int2_qh->link = 572 uhci->skel_int2_qh->link = UHCI_PTR_QH |
561 cpu_to_le32(uhci->skel_int1_qh->dma_handle) | UHCI_PTR_QH; 573 cpu_to_le32(uhci->skel_int1_qh->dma_handle);
562 uhci->skel_int1_qh->link = cpu_to_le32(uhci->skel_ls_control_qh->dma_handle) | UHCI_PTR_QH; 574
563 575 uhci->skel_int1_qh->link = UHCI_PTR_QH |
564 uhci->skel_ls_control_qh->link = cpu_to_le32(uhci->skel_fs_control_qh->dma_handle) | UHCI_PTR_QH; 576 cpu_to_le32(uhci->skel_ls_control_qh->dma_handle);
565 uhci->skel_fs_control_qh->link = cpu_to_le32(uhci->skel_bulk_qh->dma_handle) | UHCI_PTR_QH; 577 uhci->skel_ls_control_qh->link = UHCI_PTR_QH |
566 uhci->skel_bulk_qh->link = cpu_to_le32(uhci->skel_term_qh->dma_handle) | UHCI_PTR_QH; 578 cpu_to_le32(uhci->skel_fs_control_qh->dma_handle);
579 uhci->skel_fs_control_qh->link = UHCI_PTR_QH |
580 cpu_to_le32(uhci->skel_bulk_qh->dma_handle);
581 uhci->skel_bulk_qh->link = UHCI_PTR_QH |
582 cpu_to_le32(uhci->skel_term_qh->dma_handle);
567 583
568 /* This dummy TD is to work around a bug in Intel PIIX controllers */ 584 /* This dummy TD is to work around a bug in Intel PIIX controllers */
569 uhci_fill_td(uhci->term_td, 0, uhci_explen(0) | 585 uhci_fill_td(uhci->term_td, 0, uhci_explen(0) |
@@ -589,15 +605,15 @@ static int uhci_start(struct usb_hcd *hcd)
589 605
590 /* 606 /*
591 * ffs (Find First bit Set) does exactly what we need: 607 * ffs (Find First bit Set) does exactly what we need:
592 * 1,3,5,... => ffs = 0 => use skel_int2_qh = skelqh[6], 608 * 1,3,5,... => ffs = 0 => use skel_int2_qh = skelqh[8],
593 * 2,6,10,... => ffs = 1 => use skel_int4_qh = skelqh[5], etc. 609 * 2,6,10,... => ffs = 1 => use skel_int4_qh = skelqh[7], etc.
594 * ffs > 6 => not on any high-period queue, so use 610 * ffs >= 7 => not on any high-period queue, so use
595 * skel_int1_qh = skelqh[7]. 611 * skel_int1_qh = skelqh[9].
596 * Add UHCI_NUMFRAMES to insure at least one bit is set. 612 * Add UHCI_NUMFRAMES to insure at least one bit is set.
597 */ 613 */
598 irq = 6 - (int) __ffs(i + UHCI_NUMFRAMES); 614 irq = 8 - (int) __ffs(i + UHCI_NUMFRAMES);
599 if (irq < 0) 615 if (irq <= 1)
600 irq = 7; 616 irq = 9;
601 617
602 /* Only place we don't use the frame list routines */ 618 /* Only place we don't use the frame list routines */
603 uhci->frame[i] = UHCI_PTR_QH | 619 uhci->frame[i] = UHCI_PTR_QH |
@@ -611,6 +627,7 @@ static int uhci_start(struct usb_hcd *hcd)
611 mb(); 627 mb();
612 628
613 configure_hc(uhci); 629 configure_hc(uhci);
630 uhci->is_initialized = 1;
614 start_rh(uhci); 631 start_rh(uhci);
615 return 0; 632 return 0;
616 633
@@ -767,13 +784,30 @@ static int uhci_resume(struct usb_hcd *hcd)
767} 784}
768#endif 785#endif
769 786
770/* Wait until all the URBs for a particular device/endpoint are gone */ 787/* Wait until a particular device/endpoint's QH is idle, and free it */
771static void uhci_hcd_endpoint_disable(struct usb_hcd *hcd, 788static void uhci_hcd_endpoint_disable(struct usb_hcd *hcd,
772 struct usb_host_endpoint *ep) 789 struct usb_host_endpoint *hep)
773{ 790{
774 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 791 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
792 struct uhci_qh *qh;
793
794 spin_lock_irq(&uhci->lock);
795 qh = (struct uhci_qh *) hep->hcpriv;
796 if (qh == NULL)
797 goto done;
798
799 while (qh->state != QH_STATE_IDLE) {
800 ++uhci->num_waiting;
801 spin_unlock_irq(&uhci->lock);
802 wait_event_interruptible(uhci->waitqh,
803 qh->state == QH_STATE_IDLE);
804 spin_lock_irq(&uhci->lock);
805 --uhci->num_waiting;
806 }
775 807
776 wait_event_interruptible(uhci->waitqh, list_empty(&ep->urb_list)); 808 uhci_free_qh(uhci, qh);
809done:
810 spin_unlock_irq(&uhci->lock);
777} 811}
778 812
779static int uhci_hcd_get_frame_number(struct usb_hcd *hcd) 813static int uhci_hcd_get_frame_number(struct usb_hcd *hcd)
@@ -857,16 +891,15 @@ static int __init uhci_hcd_init(void)
857 if (usb_disabled()) 891 if (usb_disabled())
858 return -ENODEV; 892 return -ENODEV;
859 893
860 if (debug) { 894 if (DEBUG_CONFIGURED) {
861 errbuf = kmalloc(ERRBUF_LEN, GFP_KERNEL); 895 errbuf = kmalloc(ERRBUF_LEN, GFP_KERNEL);
862 if (!errbuf) 896 if (!errbuf)
863 goto errbuf_failed; 897 goto errbuf_failed;
898 uhci_debugfs_root = debugfs_create_dir("uhci", NULL);
899 if (!uhci_debugfs_root)
900 goto debug_failed;
864 } 901 }
865 902
866 uhci_debugfs_root = debugfs_create_dir("uhci", NULL);
867 if (!uhci_debugfs_root)
868 goto debug_failed;
869
870 uhci_up_cachep = kmem_cache_create("uhci_urb_priv", 903 uhci_up_cachep = kmem_cache_create("uhci_urb_priv",
871 sizeof(struct urb_priv), 0, 0, NULL, NULL); 904 sizeof(struct urb_priv), 0, 0, NULL, NULL);
872 if (!uhci_up_cachep) 905 if (!uhci_up_cachep)
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index 8b4b887a7d41..4a69c7eb09bd 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -28,8 +28,9 @@
28#define USBSTS_USBINT 0x0001 /* Interrupt due to IOC */ 28#define USBSTS_USBINT 0x0001 /* Interrupt due to IOC */
29#define USBSTS_ERROR 0x0002 /* Interrupt due to error */ 29#define USBSTS_ERROR 0x0002 /* Interrupt due to error */
30#define USBSTS_RD 0x0004 /* Resume Detect */ 30#define USBSTS_RD 0x0004 /* Resume Detect */
31#define USBSTS_HSE 0x0008 /* Host System Error - basically PCI problems */ 31#define USBSTS_HSE 0x0008 /* Host System Error: PCI problems */
32#define USBSTS_HCPE 0x0010 /* Host Controller Process Error - the scripts were buggy */ 32#define USBSTS_HCPE 0x0010 /* Host Controller Process Error:
33 * the schedule is buggy */
33#define USBSTS_HCH 0x0020 /* HC Halted */ 34#define USBSTS_HCH 0x0020 /* HC Halted */
34 35
35/* Interrupt enable register */ 36/* Interrupt enable register */
@@ -47,7 +48,8 @@
47/* USB port status and control registers */ 48/* USB port status and control registers */
48#define USBPORTSC1 16 49#define USBPORTSC1 16
49#define USBPORTSC2 18 50#define USBPORTSC2 18
50#define USBPORTSC_CCS 0x0001 /* Current Connect Status ("device present") */ 51#define USBPORTSC_CCS 0x0001 /* Current Connect Status
52 * ("device present") */
51#define USBPORTSC_CSC 0x0002 /* Connect Status Change */ 53#define USBPORTSC_CSC 0x0002 /* Connect Status Change */
52#define USBPORTSC_PE 0x0004 /* Port Enable */ 54#define USBPORTSC_PE 0x0004 /* Port Enable */
53#define USBPORTSC_PEC 0x0008 /* Port Enable Change */ 55#define USBPORTSC_PEC 0x0008 /* Port Enable Change */
@@ -71,15 +73,16 @@
71#define USBLEGSUP_RWC 0x8f00 /* the R/WC bits */ 73#define USBLEGSUP_RWC 0x8f00 /* the R/WC bits */
72#define USBLEGSUP_RO 0x5040 /* R/O and reserved bits */ 74#define USBLEGSUP_RO 0x5040 /* R/O and reserved bits */
73 75
74#define UHCI_PTR_BITS cpu_to_le32(0x000F) 76#define UHCI_PTR_BITS __constant_cpu_to_le32(0x000F)
75#define UHCI_PTR_TERM cpu_to_le32(0x0001) 77#define UHCI_PTR_TERM __constant_cpu_to_le32(0x0001)
76#define UHCI_PTR_QH cpu_to_le32(0x0002) 78#define UHCI_PTR_QH __constant_cpu_to_le32(0x0002)
77#define UHCI_PTR_DEPTH cpu_to_le32(0x0004) 79#define UHCI_PTR_DEPTH __constant_cpu_to_le32(0x0004)
78#define UHCI_PTR_BREADTH cpu_to_le32(0x0000) 80#define UHCI_PTR_BREADTH __constant_cpu_to_le32(0x0000)
79 81
80#define UHCI_NUMFRAMES 1024 /* in the frame list [array] */ 82#define UHCI_NUMFRAMES 1024 /* in the frame list [array] */
81#define UHCI_MAX_SOF_NUMBER 2047 /* in an SOF packet */ 83#define UHCI_MAX_SOF_NUMBER 2047 /* in an SOF packet */
82#define CAN_SCHEDULE_FRAMES 1000 /* how far future frames can be scheduled */ 84#define CAN_SCHEDULE_FRAMES 1000 /* how far in the future frames
85 * can be scheduled */
83 86
84 87
85/* 88/*
@@ -87,38 +90,59 @@
87 */ 90 */
88 91
89/* 92/*
90 * One role of a QH is to hold a queue of TDs for some endpoint. Each QH is 93 * One role of a QH is to hold a queue of TDs for some endpoint. One QH goes
91 * used with one URB, and qh->element (updated by the HC) is either: 94 * with each endpoint, and qh->element (updated by the HC) is either:
92 * - the next unprocessed TD for the URB, or 95 * - the next unprocessed TD in the endpoint's queue, or
93 * - UHCI_PTR_TERM (when there's no more traffic for this endpoint), or 96 * - UHCI_PTR_TERM (when there's no more traffic for this endpoint).
94 * - the QH for the next URB queued to the same endpoint.
95 * 97 *
96 * The other role of a QH is to serve as a "skeleton" framelist entry, so we 98 * The other role of a QH is to serve as a "skeleton" framelist entry, so we
97 * can easily splice a QH for some endpoint into the schedule at the right 99 * can easily splice a QH for some endpoint into the schedule at the right
98 * place. Then qh->element is UHCI_PTR_TERM. 100 * place. Then qh->element is UHCI_PTR_TERM.
99 * 101 *
100 * In the frame list, qh->link maintains a list of QHs seen by the HC: 102 * In the schedule, qh->link maintains a list of QHs seen by the HC:
101 * skel1 --> ep1-qh --> ep2-qh --> ... --> skel2 --> ... 103 * skel1 --> ep1-qh --> ep2-qh --> ... --> skel2 --> ...
104 *
105 * qh->node is the software equivalent of qh->link. The differences
106 * are that the software list is doubly-linked and QHs in the UNLINKING
107 * state are on the software list but not the hardware schedule.
108 *
109 * For bookkeeping purposes we maintain QHs even for Isochronous endpoints,
110 * but they never get added to the hardware schedule.
102 */ 111 */
112#define QH_STATE_IDLE 1 /* QH is not being used */
113#define QH_STATE_UNLINKING 2 /* QH has been removed from the
114 * schedule but the hardware may
115 * still be using it */
116#define QH_STATE_ACTIVE 3 /* QH is on the schedule */
117
103struct uhci_qh { 118struct uhci_qh {
104 /* Hardware fields */ 119 /* Hardware fields */
105 __le32 link; /* Next queue */ 120 __le32 link; /* Next QH in the schedule */
106 __le32 element; /* Queue element pointer */ 121 __le32 element; /* Queue element (TD) pointer */
107 122
108 /* Software fields */ 123 /* Software fields */
109 dma_addr_t dma_handle; 124 dma_addr_t dma_handle;
110 125
111 struct urb_priv *urbp; 126 struct list_head node; /* Node in the list of QHs */
127 struct usb_host_endpoint *hep; /* Endpoint information */
128 struct usb_device *udev;
129 struct list_head queue; /* Queue of urbps for this QH */
130 struct uhci_qh *skel; /* Skeleton for this QH */
131 struct uhci_td *dummy_td; /* Dummy TD to end the queue */
112 132
113 struct list_head list; 133 unsigned int unlink_frame; /* When the QH was unlinked */
114 struct list_head remove_list; 134 int state; /* QH_STATE_xxx; see above */
135
136 unsigned int initial_toggle:1; /* Endpoint's current toggle value */
137 unsigned int needs_fixup:1; /* Must fix the TD toggle values */
138 unsigned int is_stopped:1; /* Queue was stopped by an error */
115} __attribute__((aligned(16))); 139} __attribute__((aligned(16)));
116 140
117/* 141/*
118 * We need a special accessor for the element pointer because it is 142 * We need a special accessor for the element pointer because it is
119 * subject to asynchronous updates by the controller. 143 * subject to asynchronous updates by the controller.
120 */ 144 */
121static __le32 inline qh_element(struct uhci_qh *qh) { 145static inline __le32 qh_element(struct uhci_qh *qh) {
122 __le32 element = qh->element; 146 __le32 element = qh->element;
123 147
124 barrier(); 148 barrier();
@@ -149,11 +173,13 @@ static __le32 inline qh_element(struct uhci_qh *qh) {
149#define TD_CTRL_ACTLEN_MASK 0x7FF /* actual length, encoded as n - 1 */ 173#define TD_CTRL_ACTLEN_MASK 0x7FF /* actual length, encoded as n - 1 */
150 174
151#define TD_CTRL_ANY_ERROR (TD_CTRL_STALLED | TD_CTRL_DBUFERR | \ 175#define TD_CTRL_ANY_ERROR (TD_CTRL_STALLED | TD_CTRL_DBUFERR | \
152 TD_CTRL_BABBLE | TD_CTRL_CRCTIME | TD_CTRL_BITSTUFF) 176 TD_CTRL_BABBLE | TD_CTRL_CRCTIME | \
177 TD_CTRL_BITSTUFF)
153 178
154#define uhci_maxerr(err) ((err) << TD_CTRL_C_ERR_SHIFT) 179#define uhci_maxerr(err) ((err) << TD_CTRL_C_ERR_SHIFT)
155#define uhci_status_bits(ctrl_sts) ((ctrl_sts) & 0xF60000) 180#define uhci_status_bits(ctrl_sts) ((ctrl_sts) & 0xF60000)
156#define uhci_actual_length(ctrl_sts) (((ctrl_sts) + 1) & TD_CTRL_ACTLEN_MASK) /* 1-based */ 181#define uhci_actual_length(ctrl_sts) (((ctrl_sts) + 1) & \
182 TD_CTRL_ACTLEN_MASK) /* 1-based */
157 183
158/* 184/*
159 * for TD <info>: (a.k.a. Token) 185 * for TD <info>: (a.k.a. Token)
@@ -163,7 +189,7 @@ static __le32 inline qh_element(struct uhci_qh *qh) {
163#define TD_TOKEN_TOGGLE_SHIFT 19 189#define TD_TOKEN_TOGGLE_SHIFT 19
164#define TD_TOKEN_TOGGLE (1 << 19) 190#define TD_TOKEN_TOGGLE (1 << 19)
165#define TD_TOKEN_EXPLEN_SHIFT 21 191#define TD_TOKEN_EXPLEN_SHIFT 21
166#define TD_TOKEN_EXPLEN_MASK 0x7FF /* expected length, encoded as n - 1 */ 192#define TD_TOKEN_EXPLEN_MASK 0x7FF /* expected length, encoded as n-1 */
167#define TD_TOKEN_PID_MASK 0xFF 193#define TD_TOKEN_PID_MASK 0xFF
168 194
169#define uhci_explen(len) ((((len) - 1) & TD_TOKEN_EXPLEN_MASK) << \ 195#define uhci_explen(len) ((((len) - 1) & TD_TOKEN_EXPLEN_MASK) << \
@@ -187,7 +213,7 @@ static __le32 inline qh_element(struct uhci_qh *qh) {
187 * sw space after the TD entry. 213 * sw space after the TD entry.
188 * 214 *
189 * td->link points to either another TD (not necessarily for the same urb or 215 * td->link points to either another TD (not necessarily for the same urb or
190 * even the same endpoint), or nothing (PTR_TERM), or a QH (for queued urbs). 216 * even the same endpoint), or nothing (PTR_TERM), or a QH.
191 */ 217 */
192struct uhci_td { 218struct uhci_td {
193 /* Hardware fields */ 219 /* Hardware fields */
@@ -210,7 +236,7 @@ struct uhci_td {
210 * We need a special accessor for the control/status word because it is 236 * We need a special accessor for the control/status word because it is
211 * subject to asynchronous updates by the controller. 237 * subject to asynchronous updates by the controller.
212 */ 238 */
213static u32 inline td_status(struct uhci_td *td) { 239static inline u32 td_status(struct uhci_td *td) {
214 __le32 status = td->status; 240 __le32 status = td->status;
215 241
216 barrier(); 242 barrier();
@@ -223,17 +249,14 @@ static u32 inline td_status(struct uhci_td *td) {
223 */ 249 */
224 250
225/* 251/*
226 * The UHCI driver places Interrupt, Control and Bulk into QHs both 252 * The UHCI driver uses QHs with Interrupt, Control and Bulk URBs for
227 * to group together TDs for one transfer, and also to facilitate queuing 253 * automatic queuing. To make it easy to insert entries into the schedule,
228 * of URBs. To make it easy to insert entries into the schedule, we have 254 * we have a skeleton of QHs for each predefined Interrupt latency,
229 * a skeleton of QHs for each predefined Interrupt latency, low-speed 255 * low-speed control, full-speed control, bulk, and terminating QH
230 * control, full-speed control and terminating QH (see explanation for 256 * (see explanation for the terminating QH below).
231 * the terminating QH below).
232 * 257 *
233 * When we want to add a new QH, we add it to the end of the list for the 258 * When we want to add a new QH, we add it to the end of the list for the
234 * skeleton QH. 259 * skeleton QH. For instance, the schedule list can look like this:
235 *
236 * For instance, the queue can look like this:
237 * 260 *
238 * skel int128 QH 261 * skel int128 QH
239 * dev 1 interrupt QH 262 * dev 1 interrupt QH
@@ -256,26 +279,31 @@ static u32 inline td_status(struct uhci_td *td) {
256 * - To loop back to the full-speed control queue for full-speed bandwidth 279 * - To loop back to the full-speed control queue for full-speed bandwidth
257 * reclamation. 280 * reclamation.
258 * 281 *
259 * Isochronous transfers are stored before the start of the skeleton 282 * There's a special skeleton QH for Isochronous QHs. It never appears
260 * schedule and don't use QHs. While the UHCI spec doesn't forbid the 283 * on the schedule, and Isochronous TDs go on the schedule before the
261 * use of QHs for Isochronous, it doesn't use them either. And the spec 284 * the skeleton QHs. The hardware accesses them directly rather than
262 * says that queues never advance on an error completion status, which 285 * through their QH, which is used only for bookkeeping purposes.
263 * makes them totally unsuitable for Isochronous transfers. 286 * While the UHCI spec doesn't forbid the use of QHs for Isochronous,
287 * it doesn't use them either. And the spec says that queues never
288 * advance on an error completion status, which makes them totally
289 * unsuitable for Isochronous transfers.
264 */ 290 */
265 291
266#define UHCI_NUM_SKELQH 12 292#define UHCI_NUM_SKELQH 14
267#define skel_int128_qh skelqh[0] 293#define skel_unlink_qh skelqh[0]
268#define skel_int64_qh skelqh[1] 294#define skel_iso_qh skelqh[1]
269#define skel_int32_qh skelqh[2] 295#define skel_int128_qh skelqh[2]
270#define skel_int16_qh skelqh[3] 296#define skel_int64_qh skelqh[3]
271#define skel_int8_qh skelqh[4] 297#define skel_int32_qh skelqh[4]
272#define skel_int4_qh skelqh[5] 298#define skel_int16_qh skelqh[5]
273#define skel_int2_qh skelqh[6] 299#define skel_int8_qh skelqh[6]
274#define skel_int1_qh skelqh[7] 300#define skel_int4_qh skelqh[7]
275#define skel_ls_control_qh skelqh[8] 301#define skel_int2_qh skelqh[8]
276#define skel_fs_control_qh skelqh[9] 302#define skel_int1_qh skelqh[9]
277#define skel_bulk_qh skelqh[10] 303#define skel_ls_control_qh skelqh[10]
278#define skel_term_qh skelqh[11] 304#define skel_fs_control_qh skelqh[11]
305#define skel_bulk_qh skelqh[12]
306#define skel_term_qh skelqh[13]
279 307
280/* 308/*
281 * Search tree for determining where <interval> fits in the skelqh[] 309 * Search tree for determining where <interval> fits in the skelqh[]
@@ -293,21 +321,21 @@ static inline int __interval_to_skel(int interval)
293 if (interval < 16) { 321 if (interval < 16) {
294 if (interval < 4) { 322 if (interval < 4) {
295 if (interval < 2) 323 if (interval < 2)
296 return 7; /* int1 for 0-1 ms */ 324 return 9; /* int1 for 0-1 ms */
297 return 6; /* int2 for 2-3 ms */ 325 return 8; /* int2 for 2-3 ms */
298 } 326 }
299 if (interval < 8) 327 if (interval < 8)
300 return 5; /* int4 for 4-7 ms */ 328 return 7; /* int4 for 4-7 ms */
301 return 4; /* int8 for 8-15 ms */ 329 return 6; /* int8 for 8-15 ms */
302 } 330 }
303 if (interval < 64) { 331 if (interval < 64) {
304 if (interval < 32) 332 if (interval < 32)
305 return 3; /* int16 for 16-31 ms */ 333 return 5; /* int16 for 16-31 ms */
306 return 2; /* int32 for 32-63 ms */ 334 return 4; /* int32 for 32-63 ms */
307 } 335 }
308 if (interval < 128) 336 if (interval < 128)
309 return 1; /* int64 for 64-127 ms */ 337 return 3; /* int64 for 64-127 ms */
310 return 0; /* int128 for 128-255 ms (Max.) */ 338 return 2; /* int128 for 128-255 ms (Max.) */
311} 339}
312 340
313 341
@@ -360,15 +388,16 @@ struct uhci_hcd {
360 388
361 struct uhci_td *term_td; /* Terminating TD, see UHCI bug */ 389 struct uhci_td *term_td; /* Terminating TD, see UHCI bug */
362 struct uhci_qh *skelqh[UHCI_NUM_SKELQH]; /* Skeleton QHs */ 390 struct uhci_qh *skelqh[UHCI_NUM_SKELQH]; /* Skeleton QHs */
391 struct uhci_qh *next_qh; /* Next QH to scan */
363 392
364 spinlock_t lock; 393 spinlock_t lock;
365 394
366 dma_addr_t frame_dma_handle; /* Hardware frame list */ 395 dma_addr_t frame_dma_handle; /* Hardware frame list */
367 __le32 *frame; 396 __le32 *frame;
368 void **frame_cpu; /* CPU's frame list */ 397 void **frame_cpu; /* CPU's frame list */
369 398
370 int fsbr; /* Full-speed bandwidth reclamation */ 399 int fsbr; /* Full-speed bandwidth reclamation */
371 unsigned long fsbrtimeout; /* FSBR delay */ 400 unsigned long fsbrtimeout; /* FSBR delay */
372 401
373 enum uhci_rh_state rh_state; 402 enum uhci_rh_state rh_state;
374 unsigned long auto_stop_time; /* When to AUTO_STOP */ 403 unsigned long auto_stop_time; /* When to AUTO_STOP */
@@ -382,6 +411,7 @@ struct uhci_hcd {
382 unsigned int hc_inaccessible:1; /* HC is suspended or dead */ 411 unsigned int hc_inaccessible:1; /* HC is suspended or dead */
383 unsigned int working_RD:1; /* Suspended root hub doesn't 412 unsigned int working_RD:1; /* Suspended root hub doesn't
384 need to be polled */ 413 need to be polled */
414 unsigned int is_initialized:1; /* Data structure is usable */
385 415
386 /* Support for port suspend/resume/reset */ 416 /* Support for port suspend/resume/reset */
387 unsigned long port_c_suspend; /* Bit-arrays of ports */ 417 unsigned long port_c_suspend; /* Bit-arrays of ports */
@@ -389,27 +419,16 @@ struct uhci_hcd {
389 unsigned long resuming_ports; 419 unsigned long resuming_ports;
390 unsigned long ports_timeout; /* Time to stop signalling */ 420 unsigned long ports_timeout; /* Time to stop signalling */
391 421
392 /* Main list of URBs currently controlled by this HC */
393 struct list_head urb_list;
394
395 /* List of QHs that are done, but waiting to be unlinked (race) */
396 struct list_head qh_remove_list;
397 unsigned int qh_remove_age; /* Age in frames */
398
399 /* List of TDs that are done, but waiting to be freed (race) */ 422 /* List of TDs that are done, but waiting to be freed (race) */
400 struct list_head td_remove_list; 423 struct list_head td_remove_list;
401 unsigned int td_remove_age; /* Age in frames */ 424 unsigned int td_remove_age; /* Age in frames */
402 425
403 /* List of asynchronously unlinked URBs */ 426 struct list_head idle_qh_list; /* Where the idle QHs live */
404 struct list_head urb_remove_list;
405 unsigned int urb_remove_age; /* Age in frames */
406
407 /* List of URBs awaiting completion callback */
408 struct list_head complete_list;
409 427
410 int rh_numports; /* Number of root-hub ports */ 428 int rh_numports; /* Number of root-hub ports */
411 429
412 wait_queue_head_t waitqh; /* endpoint_disable waiters */ 430 wait_queue_head_t waitqh; /* endpoint_disable waiters */
431 int num_waiting; /* Number of waiters */
413}; 432};
414 433
415/* Convert between a usb_hcd pointer and the corresponding uhci_hcd */ 434/* Convert between a usb_hcd pointer and the corresponding uhci_hcd */
@@ -429,7 +448,7 @@ static inline struct usb_hcd *uhci_to_hcd(struct uhci_hcd *uhci)
429 * Private per-URB data 448 * Private per-URB data
430 */ 449 */
431struct urb_priv { 450struct urb_priv {
432 struct list_head urb_list; 451 struct list_head node; /* Node in the QH's urbp list */
433 452
434 struct urb *urb; 453 struct urb *urb;
435 454
@@ -437,15 +456,8 @@ struct urb_priv {
437 struct list_head td_list; 456 struct list_head td_list;
438 457
439 unsigned fsbr : 1; /* URB turned on FSBR */ 458 unsigned fsbr : 1; /* URB turned on FSBR */
440 unsigned fsbr_timeout : 1; /* URB timed out on FSBR */ 459 unsigned short_transfer : 1; /* URB got a short transfer, no
441 unsigned queued : 1; /* QH was queued (not linked in) */ 460 * need to rescan */
442 unsigned short_control_packet : 1; /* If we get a short packet during */
443 /* a control transfer, retrigger */
444 /* the status phase */
445
446 unsigned long fsbrtime; /* In jiffies */
447
448 struct list_head queue_list;
449}; 461};
450 462
451 463
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index a71e48a66805..152971d16769 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -99,6 +99,21 @@ static void uhci_finish_suspend(struct uhci_hcd *uhci, int port,
99 } 99 }
100} 100}
101 101
102/* Wait for the UHCI controller in HP's iLO2 server management chip.
103 * It can take up to 250 us to finish a reset and set the CSC bit.
104 */
105static void wait_for_HP(unsigned long port_addr)
106{
107 int i;
108
109 for (i = 10; i < 250; i += 10) {
110 if (inw(port_addr) & USBPORTSC_CSC)
111 return;
112 udelay(10);
113 }
114 /* Log a warning? */
115}
116
102static void uhci_check_ports(struct uhci_hcd *uhci) 117static void uhci_check_ports(struct uhci_hcd *uhci)
103{ 118{
104 unsigned int port; 119 unsigned int port;
@@ -113,6 +128,12 @@ static void uhci_check_ports(struct uhci_hcd *uhci)
113 CLR_RH_PORTSTAT(USBPORTSC_PR); 128 CLR_RH_PORTSTAT(USBPORTSC_PR);
114 udelay(10); 129 udelay(10);
115 130
131 /* HP's server management chip requires
132 * a longer delay. */
133 if (to_pci_dev(uhci_dev(uhci))->vendor ==
134 PCI_VENDOR_ID_HP)
135 wait_for_HP(port_addr);
136
116 /* If the port was enabled before, turning 137 /* If the port was enabled before, turning
117 * reset on caused a port enable change. 138 * reset on caused a port enable change.
118 * Turning reset off causes a port connect 139 * Turning reset off causes a port connect
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 782398045f9f..a06d84c19e13 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -13,13 +13,9 @@
13 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface 13 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface
14 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). 14 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
15 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) 15 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c)
16 * (C) Copyright 2004 Alan Stern, stern@rowland.harvard.edu 16 * (C) Copyright 2004-2005 Alan Stern, stern@rowland.harvard.edu
17 */ 17 */
18 18
19static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb);
20static void uhci_unlink_generic(struct uhci_hcd *uhci, struct urb *urb);
21static void uhci_remove_pending_urbps(struct uhci_hcd *uhci);
22static void uhci_free_pending_qhs(struct uhci_hcd *uhci);
23static void uhci_free_pending_tds(struct uhci_hcd *uhci); 19static void uhci_free_pending_tds(struct uhci_hcd *uhci);
24 20
25/* 21/*
@@ -30,7 +26,7 @@ static void uhci_free_pending_tds(struct uhci_hcd *uhci);
30 * games with the FSBR code to make sure we get the correct order in all 26 * games with the FSBR code to make sure we get the correct order in all
31 * the cases. I don't think it's worth the effort 27 * the cases. I don't think it's worth the effort
32 */ 28 */
33static inline void uhci_set_next_interrupt(struct uhci_hcd *uhci) 29static void uhci_set_next_interrupt(struct uhci_hcd *uhci)
34{ 30{
35 if (uhci->is_stopped) 31 if (uhci->is_stopped)
36 mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies); 32 mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies);
@@ -42,12 +38,6 @@ static inline void uhci_clear_next_interrupt(struct uhci_hcd *uhci)
42 uhci->term_td->status &= ~cpu_to_le32(TD_CTRL_IOC); 38 uhci->term_td->status &= ~cpu_to_le32(TD_CTRL_IOC);
43} 39}
44 40
45static inline void uhci_moveto_complete(struct uhci_hcd *uhci,
46 struct urb_priv *urbp)
47{
48 list_move_tail(&urbp->urb_list, &uhci->complete_list);
49}
50
51static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci) 41static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci)
52{ 42{
53 dma_addr_t dma_handle; 43 dma_addr_t dma_handle;
@@ -58,10 +48,6 @@ static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci)
58 return NULL; 48 return NULL;
59 49
60 td->dma_handle = dma_handle; 50 td->dma_handle = dma_handle;
61
62 td->link = UHCI_PTR_TERM;
63 td->buffer = 0;
64
65 td->frame = -1; 51 td->frame = -1;
66 52
67 INIT_LIST_HEAD(&td->list); 53 INIT_LIST_HEAD(&td->list);
@@ -71,6 +57,18 @@ static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci)
71 return td; 57 return td;
72} 58}
73 59
60static void uhci_free_td(struct uhci_hcd *uhci, struct uhci_td *td)
61{
62 if (!list_empty(&td->list))
63 dev_warn(uhci_dev(uhci), "td %p still in list!\n", td);
64 if (!list_empty(&td->remove_list))
65 dev_warn(uhci_dev(uhci), "td %p still in remove_list!\n", td);
66 if (!list_empty(&td->fl_list))
67 dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td);
68
69 dma_pool_free(uhci->td_pool, td, td->dma_handle);
70}
71
74static inline void uhci_fill_td(struct uhci_td *td, u32 status, 72static inline void uhci_fill_td(struct uhci_td *td, u32 status,
75 u32 token, u32 buffer) 73 u32 token, u32 buffer)
76{ 74{
@@ -82,7 +80,8 @@ static inline void uhci_fill_td(struct uhci_td *td, u32 status,
82/* 80/*
83 * We insert Isochronous URBs directly into the frame list at the beginning 81 * We insert Isochronous URBs directly into the frame list at the beginning
84 */ 82 */
85static void uhci_insert_td_frame_list(struct uhci_hcd *uhci, struct uhci_td *td, unsigned framenum) 83static inline void uhci_insert_td_in_frame_list(struct uhci_hcd *uhci,
84 struct uhci_td *td, unsigned framenum)
86{ 85{
87 framenum &= (UHCI_NUMFRAMES - 1); 86 framenum &= (UHCI_NUMFRAMES - 1);
88 87
@@ -108,7 +107,7 @@ static void uhci_insert_td_frame_list(struct uhci_hcd *uhci, struct uhci_td *td,
108 } 107 }
109} 108}
110 109
111static inline void uhci_remove_td_frame_list(struct uhci_hcd *uhci, 110static inline void uhci_remove_td_from_frame_list(struct uhci_hcd *uhci,
112 struct uhci_td *td) 111 struct uhci_td *td)
113{ 112{
114 /* If it's not inserted, don't remove it */ 113 /* If it's not inserted, don't remove it */
@@ -139,48 +138,21 @@ static inline void uhci_remove_td_frame_list(struct uhci_hcd *uhci,
139 td->frame = -1; 138 td->frame = -1;
140} 139}
141 140
142static void unlink_isochronous_tds(struct uhci_hcd *uhci, struct urb *urb) 141/*
142 * Remove all the TDs for an Isochronous URB from the frame list
143 */
144static void uhci_unlink_isochronous_tds(struct uhci_hcd *uhci, struct urb *urb)
143{ 145{
144 struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; 146 struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv;
145 struct uhci_td *td; 147 struct uhci_td *td;
146 148
147 list_for_each_entry(td, &urbp->td_list, list) 149 list_for_each_entry(td, &urbp->td_list, list)
148 uhci_remove_td_frame_list(uhci, td); 150 uhci_remove_td_from_frame_list(uhci, td);
149 wmb(); 151 wmb();
150} 152}
151 153
152/* 154static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci,
153 * Inserts a td list into qh. 155 struct usb_device *udev, struct usb_host_endpoint *hep)
154 */
155static void uhci_insert_tds_in_qh(struct uhci_qh *qh, struct urb *urb, __le32 breadth)
156{
157 struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv;
158 struct uhci_td *td;
159 __le32 *plink;
160
161 /* Ordering isn't important here yet since the QH hasn't been */
162 /* inserted into the schedule yet */
163 plink = &qh->element;
164 list_for_each_entry(td, &urbp->td_list, list) {
165 *plink = cpu_to_le32(td->dma_handle) | breadth;
166 plink = &td->link;
167 }
168 *plink = UHCI_PTR_TERM;
169}
170
171static void uhci_free_td(struct uhci_hcd *uhci, struct uhci_td *td)
172{
173 if (!list_empty(&td->list))
174 dev_warn(uhci_dev(uhci), "td %p still in list!\n", td);
175 if (!list_empty(&td->remove_list))
176 dev_warn(uhci_dev(uhci), "td %p still in remove_list!\n", td);
177 if (!list_empty(&td->fl_list))
178 dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td);
179
180 dma_pool_free(uhci->td_pool, td, td->dma_handle);
181}
182
183static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci)
184{ 156{
185 dma_addr_t dma_handle; 157 dma_addr_t dma_handle;
186 struct uhci_qh *qh; 158 struct uhci_qh *qh;
@@ -194,256 +166,217 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci)
194 qh->element = UHCI_PTR_TERM; 166 qh->element = UHCI_PTR_TERM;
195 qh->link = UHCI_PTR_TERM; 167 qh->link = UHCI_PTR_TERM;
196 168
197 qh->urbp = NULL; 169 INIT_LIST_HEAD(&qh->queue);
198 170 INIT_LIST_HEAD(&qh->node);
199 INIT_LIST_HEAD(&qh->list);
200 INIT_LIST_HEAD(&qh->remove_list);
201 171
172 if (udev) { /* Normal QH */
173 qh->dummy_td = uhci_alloc_td(uhci);
174 if (!qh->dummy_td) {
175 dma_pool_free(uhci->qh_pool, qh, dma_handle);
176 return NULL;
177 }
178 qh->state = QH_STATE_IDLE;
179 qh->hep = hep;
180 qh->udev = udev;
181 hep->hcpriv = qh;
182
183 } else { /* Skeleton QH */
184 qh->state = QH_STATE_ACTIVE;
185 qh->udev = NULL;
186 }
202 return qh; 187 return qh;
203} 188}
204 189
205static void uhci_free_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) 190static void uhci_free_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
206{ 191{
207 if (!list_empty(&qh->list)) 192 WARN_ON(qh->state != QH_STATE_IDLE && qh->udev);
193 if (!list_empty(&qh->queue))
208 dev_warn(uhci_dev(uhci), "qh %p list not empty!\n", qh); 194 dev_warn(uhci_dev(uhci), "qh %p list not empty!\n", qh);
209 if (!list_empty(&qh->remove_list))
210 dev_warn(uhci_dev(uhci), "qh %p still in remove_list!\n", qh);
211 195
196 list_del(&qh->node);
197 if (qh->udev) {
198 qh->hep->hcpriv = NULL;
199 uhci_free_td(uhci, qh->dummy_td);
200 }
212 dma_pool_free(uhci->qh_pool, qh, qh->dma_handle); 201 dma_pool_free(uhci->qh_pool, qh, qh->dma_handle);
213} 202}
214 203
215/* 204/*
216 * Append this urb's qh after the last qh in skelqh->list 205 * When the currently executing URB is dequeued, save its current toggle value
217 *
218 * Note that urb_priv.queue_list doesn't have a separate queue head;
219 * it's a ring with every element "live".
220 */ 206 */
221static void uhci_insert_qh(struct uhci_hcd *uhci, struct uhci_qh *skelqh, struct urb *urb) 207static void uhci_save_toggle(struct uhci_qh *qh, struct urb *urb)
222{ 208{
223 struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; 209 struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv;
224 struct urb_priv *turbp; 210 struct uhci_td *td;
225 struct uhci_qh *lqh;
226 211
227 /* Grab the last QH */ 212 /* If the QH element pointer is UHCI_PTR_TERM then then currently
228 lqh = list_entry(skelqh->list.prev, struct uhci_qh, list); 213 * executing URB has already been unlinked, so this one isn't it. */
214 if (qh_element(qh) == UHCI_PTR_TERM ||
215 qh->queue.next != &urbp->node)
216 return;
217 qh->element = UHCI_PTR_TERM;
229 218
230 /* Point to the next skelqh */ 219 /* Only bulk and interrupt pipes have to worry about toggles */
231 urbp->qh->link = lqh->link; 220 if (!(usb_pipetype(urb->pipe) == PIPE_BULK ||
232 wmb(); /* Ordering is important */ 221 usb_pipetype(urb->pipe) == PIPE_INTERRUPT))
222 return;
233 223
234 /* 224 /* Find the first active TD; that's the device's toggle state */
235 * Patch QHs for previous endpoint's queued URBs? HC goes 225 list_for_each_entry(td, &urbp->td_list, list) {
236 * here next, not to the next skelqh it now points to. 226 if (td_status(td) & TD_CTRL_ACTIVE) {
237 * 227 qh->needs_fixup = 1;
238 * lqh --> td ... --> qh ... --> td --> qh ... --> td 228 qh->initial_toggle = uhci_toggle(td_token(td));
239 * | | | 229 return;
240 * v v v 230 }
241 * +<----------------+-----------------+
242 * v
243 * newqh --> td ... --> td
244 * |
245 * v
246 * ...
247 *
248 * The HC could see (and use!) any of these as we write them.
249 */
250 lqh->link = cpu_to_le32(urbp->qh->dma_handle) | UHCI_PTR_QH;
251 if (lqh->urbp) {
252 list_for_each_entry(turbp, &lqh->urbp->queue_list, queue_list)
253 turbp->qh->link = lqh->link;
254 } 231 }
255 232
256 list_add_tail(&urbp->qh->list, &skelqh->list); 233 WARN_ON(1);
257} 234}
258 235
259/* 236/*
260 * Start removal of QH from schedule; it finishes next frame. 237 * Fix up the data toggles for URBs in a queue, when one of them
261 * TDs should be unlinked before this is called. 238 * terminates early (short transfer, error, or dequeued).
262 */ 239 */
263static void uhci_remove_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) 240static void uhci_fixup_toggles(struct uhci_qh *qh, int skip_first)
264{ 241{
265 struct uhci_qh *pqh; 242 struct urb_priv *urbp = NULL;
266 __le32 newlink; 243 struct uhci_td *td;
267 244 unsigned int toggle = qh->initial_toggle;
268 if (!qh) 245 unsigned int pipe;
269 return; 246
270 247 /* Fixups for a short transfer start with the second URB in the
271 /* 248 * queue (the short URB is the first). */
272 * Only go through the hoops if it's actually linked in 249 if (skip_first)
273 */ 250 urbp = list_entry(qh->queue.next, struct urb_priv, node);
274 if (!list_empty(&qh->list)) { 251
275 252 /* When starting with the first URB, if the QH element pointer is
276 /* If our queue is nonempty, make the next URB the head */ 253 * still valid then we know the URB's toggles are okay. */
277 if (!list_empty(&qh->urbp->queue_list)) { 254 else if (qh_element(qh) != UHCI_PTR_TERM)
278 struct urb_priv *nurbp; 255 toggle = 2;
279 256
280 nurbp = list_entry(qh->urbp->queue_list.next, 257 /* Fix up the toggle for the URBs in the queue. Normally this
281 struct urb_priv, queue_list); 258 * loop won't run more than once: When an error or short transfer
282 nurbp->queued = 0; 259 * occurs, the queue usually gets emptied. */
283 list_add(&nurbp->qh->list, &qh->list); 260 urbp = list_prepare_entry(urbp, &qh->queue, node);
284 newlink = cpu_to_le32(nurbp->qh->dma_handle) | UHCI_PTR_QH; 261 list_for_each_entry_continue(urbp, &qh->queue, node) {
285 } else 262
286 newlink = qh->link; 263 /* If the first TD has the right toggle value, we don't
287 264 * need to change any toggles in this URB */
288 /* Fix up the previous QH's queue to link to either 265 td = list_entry(urbp->td_list.next, struct uhci_td, list);
289 * the new head of this queue or the start of the 266 if (toggle > 1 || uhci_toggle(td_token(td)) == toggle) {
290 * next endpoint's queue. */ 267 td = list_entry(urbp->td_list.next, struct uhci_td,
291 pqh = list_entry(qh->list.prev, struct uhci_qh, list); 268 list);
292 pqh->link = newlink; 269 toggle = uhci_toggle(td_token(td)) ^ 1;
293 if (pqh->urbp) { 270
294 struct urb_priv *turbp; 271 /* Otherwise all the toggles in the URB have to be switched */
295 272 } else {
296 list_for_each_entry(turbp, &pqh->urbp->queue_list, 273 list_for_each_entry(td, &urbp->td_list, list) {
297 queue_list) 274 td->token ^= __constant_cpu_to_le32(
298 turbp->qh->link = newlink; 275 TD_TOKEN_TOGGLE);
276 toggle ^= 1;
277 }
299 } 278 }
300 wmb();
301
302 /* Leave qh->link in case the HC is on the QH now, it will */
303 /* continue the rest of the schedule */
304 qh->element = UHCI_PTR_TERM;
305
306 list_del_init(&qh->list);
307 }
308
309 list_del_init(&qh->urbp->queue_list);
310 qh->urbp = NULL;
311
312 uhci_get_current_frame_number(uhci);
313 if (uhci->frame_number + uhci->is_stopped != uhci->qh_remove_age) {
314 uhci_free_pending_qhs(uhci);
315 uhci->qh_remove_age = uhci->frame_number;
316 } 279 }
317 280
318 /* Check to see if the remove list is empty. Set the IOC bit */ 281 wmb();
319 /* to force an interrupt so we can remove the QH */ 282 pipe = list_entry(qh->queue.next, struct urb_priv, node)->urb->pipe;
320 if (list_empty(&uhci->qh_remove_list)) 283 usb_settoggle(qh->udev, usb_pipeendpoint(pipe),
321 uhci_set_next_interrupt(uhci); 284 usb_pipeout(pipe), toggle);
322 285 qh->needs_fixup = 0;
323 list_add(&qh->remove_list, &uhci->qh_remove_list);
324} 286}
325 287
326static int uhci_fixup_toggle(struct urb *urb, unsigned int toggle) 288/*
289 * Put a QH on the schedule in both hardware and software
290 */
291static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
327{ 292{
328 struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; 293 struct uhci_qh *pqh;
329 struct uhci_td *td;
330
331 list_for_each_entry(td, &urbp->td_list, list) {
332 if (toggle)
333 td->token |= cpu_to_le32(TD_TOKEN_TOGGLE);
334 else
335 td->token &= ~cpu_to_le32(TD_TOKEN_TOGGLE);
336
337 toggle ^= 1;
338 }
339
340 return toggle;
341}
342 294
343/* This function will append one URB's QH to another URB's QH. This is for */ 295 WARN_ON(list_empty(&qh->queue));
344/* queuing interrupt, control or bulk transfers */
345static void uhci_append_queued_urb(struct uhci_hcd *uhci, struct urb *eurb, struct urb *urb)
346{
347 struct urb_priv *eurbp, *urbp, *furbp, *lurbp;
348 struct uhci_td *lltd;
349 296
350 eurbp = eurb->hcpriv; 297 /* Set the element pointer if it isn't set already.
351 urbp = urb->hcpriv; 298 * This isn't needed for Isochronous queues, but it doesn't hurt. */
299 if (qh_element(qh) == UHCI_PTR_TERM) {
300 struct urb_priv *urbp = list_entry(qh->queue.next,
301 struct urb_priv, node);
302 struct uhci_td *td = list_entry(urbp->td_list.next,
303 struct uhci_td, list);
352 304
353 /* Find the first URB in the queue */ 305 qh->element = cpu_to_le32(td->dma_handle);
354 furbp = eurbp;
355 if (eurbp->queued) {
356 list_for_each_entry(furbp, &eurbp->queue_list, queue_list)
357 if (!furbp->queued)
358 break;
359 } 306 }
360 307
361 lurbp = list_entry(furbp->queue_list.prev, struct urb_priv, queue_list); 308 if (qh->state == QH_STATE_ACTIVE)
362 309 return;
363 lltd = list_entry(lurbp->td_list.prev, struct uhci_td, list); 310 qh->state = QH_STATE_ACTIVE;
364 311
365 /* Control transfers always start with toggle 0 */ 312 /* Move the QH from its old list to the end of the appropriate
366 if (!usb_pipecontrol(urb->pipe)) 313 * skeleton's list */
367 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), 314 if (qh == uhci->next_qh)
368 usb_pipeout(urb->pipe), 315 uhci->next_qh = list_entry(qh->node.next, struct uhci_qh,
369 uhci_fixup_toggle(urb, 316 node);
370 uhci_toggle(td_token(lltd)) ^ 1)); 317 list_move_tail(&qh->node, &qh->skel->node);
371 318
372 /* All qhs in the queue need to link to the next queue */ 319 /* Link it into the schedule */
373 urbp->qh->link = eurbp->qh->link; 320 pqh = list_entry(qh->node.prev, struct uhci_qh, node);
374 321 qh->link = pqh->link;
375 wmb(); /* Make sure we flush everything */ 322 wmb();
376 323 pqh->link = UHCI_PTR_QH | cpu_to_le32(qh->dma_handle);
377 lltd->link = cpu_to_le32(urbp->qh->dma_handle) | UHCI_PTR_QH;
378
379 list_add_tail(&urbp->queue_list, &furbp->queue_list);
380
381 urbp->queued = 1;
382} 324}
383 325
384static void uhci_delete_queued_urb(struct uhci_hcd *uhci, struct urb *urb) 326/*
327 * Take a QH off the hardware schedule
328 */
329static void uhci_unlink_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
385{ 330{
386 struct urb_priv *urbp, *nurbp, *purbp, *turbp; 331 struct uhci_qh *pqh;
387 struct uhci_td *pltd;
388 unsigned int toggle;
389
390 urbp = urb->hcpriv;
391 332
392 if (list_empty(&urbp->queue_list)) 333 if (qh->state == QH_STATE_UNLINKING)
393 return; 334 return;
335 WARN_ON(qh->state != QH_STATE_ACTIVE || !qh->udev);
336 qh->state = QH_STATE_UNLINKING;
394 337
395 nurbp = list_entry(urbp->queue_list.next, struct urb_priv, queue_list); 338 /* Unlink the QH from the schedule and record when we did it */
339 pqh = list_entry(qh->node.prev, struct uhci_qh, node);
340 pqh->link = qh->link;
341 mb();
396 342
397 /* 343 uhci_get_current_frame_number(uhci);
398 * Fix up the toggle for the following URBs in the queue. 344 qh->unlink_frame = uhci->frame_number;
399 * Only needed for bulk and interrupt: control and isochronous
400 * endpoints don't propagate toggles between messages.
401 */
402 if (usb_pipebulk(urb->pipe) || usb_pipeint(urb->pipe)) {
403 if (!urbp->queued)
404 /* We just set the toggle in uhci_unlink_generic */
405 toggle = usb_gettoggle(urb->dev,
406 usb_pipeendpoint(urb->pipe),
407 usb_pipeout(urb->pipe));
408 else {
409 /* If we're in the middle of the queue, grab the */
410 /* toggle from the TD previous to us */
411 purbp = list_entry(urbp->queue_list.prev,
412 struct urb_priv, queue_list);
413 pltd = list_entry(purbp->td_list.prev,
414 struct uhci_td, list);
415 toggle = uhci_toggle(td_token(pltd)) ^ 1;
416 }
417 345
418 list_for_each_entry(turbp, &urbp->queue_list, queue_list) { 346 /* Force an interrupt so we know when the QH is fully unlinked */
419 if (!turbp->queued) 347 if (list_empty(&uhci->skel_unlink_qh->node))
420 break; 348 uhci_set_next_interrupt(uhci);
421 toggle = uhci_fixup_toggle(turbp->urb, toggle);
422 }
423 349
424 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), 350 /* Move the QH from its old list to the end of the unlinking list */
425 usb_pipeout(urb->pipe), toggle); 351 if (qh == uhci->next_qh)
426 } 352 uhci->next_qh = list_entry(qh->node.next, struct uhci_qh,
353 node);
354 list_move_tail(&qh->node, &uhci->skel_unlink_qh->node);
355}
427 356
428 if (urbp->queued) { 357/*
429 /* We're somewhere in the middle (or end). The case where 358 * When we and the controller are through with a QH, it becomes IDLE.
430 * we're at the head is handled in uhci_remove_qh(). */ 359 * This happens when a QH has been off the schedule (on the unlinking
431 purbp = list_entry(urbp->queue_list.prev, struct urb_priv, 360 * list) for more than one frame, or when an error occurs while adding
432 queue_list); 361 * the first URB onto a new QH.
362 */
363static void uhci_make_qh_idle(struct uhci_hcd *uhci, struct uhci_qh *qh)
364{
365 WARN_ON(qh->state == QH_STATE_ACTIVE);
433 366
434 pltd = list_entry(purbp->td_list.prev, struct uhci_td, list); 367 if (qh == uhci->next_qh)
435 if (nurbp->queued) 368 uhci->next_qh = list_entry(qh->node.next, struct uhci_qh,
436 pltd->link = cpu_to_le32(nurbp->qh->dma_handle) | UHCI_PTR_QH; 369 node);
437 else 370 list_move(&qh->node, &uhci->idle_qh_list);
438 /* The next URB happens to be the beginning, so */ 371 qh->state = QH_STATE_IDLE;
439 /* we're the last, end the chain */
440 pltd->link = UHCI_PTR_TERM;
441 }
442 372
443 /* urbp->queue_list is handled in uhci_remove_qh() */ 373 /* If anyone is waiting for a QH to become idle, wake them up */
374 if (uhci->num_waiting)
375 wake_up_all(&uhci->waitqh);
444} 376}
445 377
446static struct urb_priv *uhci_alloc_urb_priv(struct uhci_hcd *uhci, struct urb *urb) 378static inline struct urb_priv *uhci_alloc_urb_priv(struct uhci_hcd *uhci,
379 struct urb *urb)
447{ 380{
448 struct urb_priv *urbp; 381 struct urb_priv *urbp;
449 382
@@ -453,16 +386,11 @@ static struct urb_priv *uhci_alloc_urb_priv(struct uhci_hcd *uhci, struct urb *u
453 386
454 memset((void *)urbp, 0, sizeof(*urbp)); 387 memset((void *)urbp, 0, sizeof(*urbp));
455 388
456 urbp->fsbrtime = jiffies;
457 urbp->urb = urb; 389 urbp->urb = urb;
390 urb->hcpriv = urbp;
458 391
392 INIT_LIST_HEAD(&urbp->node);
459 INIT_LIST_HEAD(&urbp->td_list); 393 INIT_LIST_HEAD(&urbp->td_list);
460 INIT_LIST_HEAD(&urbp->queue_list);
461 INIT_LIST_HEAD(&urbp->urb_list);
462
463 list_add_tail(&urbp->urb_list, &uhci->urb_list);
464
465 urb->hcpriv = urbp;
466 394
467 return urbp; 395 return urbp;
468} 396}
@@ -482,18 +410,14 @@ static void uhci_remove_td_from_urb(struct uhci_td *td)
482 list_del_init(&td->list); 410 list_del_init(&td->list);
483} 411}
484 412
485static void uhci_destroy_urb_priv(struct uhci_hcd *uhci, struct urb *urb) 413static void uhci_free_urb_priv(struct uhci_hcd *uhci,
414 struct urb_priv *urbp)
486{ 415{
487 struct uhci_td *td, *tmp; 416 struct uhci_td *td, *tmp;
488 struct urb_priv *urbp;
489
490 urbp = (struct urb_priv *)urb->hcpriv;
491 if (!urbp)
492 return;
493 417
494 if (!list_empty(&urbp->urb_list)) 418 if (!list_empty(&urbp->node))
495 dev_warn(uhci_dev(uhci), "urb %p still on uhci->urb_list " 419 dev_warn(uhci_dev(uhci), "urb %p still on QH's list!\n",
496 "or uhci->remove_list!\n", urb); 420 urbp->urb);
497 421
498 uhci_get_current_frame_number(uhci); 422 uhci_get_current_frame_number(uhci);
499 if (uhci->frame_number + uhci->is_stopped != uhci->td_remove_age) { 423 if (uhci->frame_number + uhci->is_stopped != uhci->td_remove_age) {
@@ -502,7 +426,7 @@ static void uhci_destroy_urb_priv(struct uhci_hcd *uhci, struct urb *urb)
502 } 426 }
503 427
504 /* Check to see if the remove list is empty. Set the IOC bit */ 428 /* Check to see if the remove list is empty. Set the IOC bit */
505 /* to force an interrupt so we can remove the TDs*/ 429 /* to force an interrupt so we can remove the TDs. */
506 if (list_empty(&uhci->td_remove_list)) 430 if (list_empty(&uhci->td_remove_list))
507 uhci_set_next_interrupt(uhci); 431 uhci_set_next_interrupt(uhci);
508 432
@@ -511,7 +435,7 @@ static void uhci_destroy_urb_priv(struct uhci_hcd *uhci, struct urb *urb)
511 list_add(&td->remove_list, &uhci->td_remove_list); 435 list_add(&td->remove_list, &uhci->td_remove_list);
512 } 436 }
513 437
514 urb->hcpriv = NULL; 438 urbp->urb->hcpriv = NULL;
515 kmem_cache_free(uhci_up_cachep, urbp); 439 kmem_cache_free(uhci_up_cachep, urbp);
516} 440}
517 441
@@ -570,34 +494,33 @@ static int uhci_map_status(int status, int dir_out)
570/* 494/*
571 * Control transfers 495 * Control transfers
572 */ 496 */
573static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, struct urb *eurb) 497static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
498 struct uhci_qh *qh)
574{ 499{
575 struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv;
576 struct uhci_td *td; 500 struct uhci_td *td;
577 struct uhci_qh *qh, *skelqh;
578 unsigned long destination, status; 501 unsigned long destination, status;
579 int maxsze = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); 502 int maxsze = le16_to_cpu(qh->hep->desc.wMaxPacketSize);
580 int len = urb->transfer_buffer_length; 503 int len = urb->transfer_buffer_length;
581 dma_addr_t data = urb->transfer_dma; 504 dma_addr_t data = urb->transfer_dma;
505 __le32 *plink;
582 506
583 /* The "pipe" thing contains the destination in bits 8--18 */ 507 /* The "pipe" thing contains the destination in bits 8--18 */
584 destination = (urb->pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP; 508 destination = (urb->pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP;
585 509
586 /* 3 errors */ 510 /* 3 errors, dummy TD remains inactive */
587 status = TD_CTRL_ACTIVE | uhci_maxerr(3); 511 status = uhci_maxerr(3);
588 if (urb->dev->speed == USB_SPEED_LOW) 512 if (urb->dev->speed == USB_SPEED_LOW)
589 status |= TD_CTRL_LS; 513 status |= TD_CTRL_LS;
590 514
591 /* 515 /*
592 * Build the TD for the control request setup packet 516 * Build the TD for the control request setup packet
593 */ 517 */
594 td = uhci_alloc_td(uhci); 518 td = qh->dummy_td;
595 if (!td)
596 return -ENOMEM;
597
598 uhci_add_td_to_urb(urb, td); 519 uhci_add_td_to_urb(urb, td);
599 uhci_fill_td(td, status, destination | uhci_explen(8), 520 uhci_fill_td(td, status, destination | uhci_explen(8),
600 urb->setup_dma); 521 urb->setup_dma);
522 plink = &td->link;
523 status |= TD_CTRL_ACTIVE;
601 524
602 /* 525 /*
603 * If direction is "send", change the packet ID from SETUP (0x2D) 526 * If direction is "send", change the packet ID from SETUP (0x2D)
@@ -615,21 +538,20 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, struct ur
615 * Build the DATA TDs 538 * Build the DATA TDs
616 */ 539 */
617 while (len > 0) { 540 while (len > 0) {
618 int pktsze = len; 541 int pktsze = min(len, maxsze);
619
620 if (pktsze > maxsze)
621 pktsze = maxsze;
622 542
623 td = uhci_alloc_td(uhci); 543 td = uhci_alloc_td(uhci);
624 if (!td) 544 if (!td)
625 return -ENOMEM; 545 goto nomem;
546 *plink = cpu_to_le32(td->dma_handle);
626 547
627 /* Alternate Data0/1 (start with Data1) */ 548 /* Alternate Data0/1 (start with Data1) */
628 destination ^= TD_TOKEN_TOGGLE; 549 destination ^= TD_TOKEN_TOGGLE;
629 550
630 uhci_add_td_to_urb(urb, td); 551 uhci_add_td_to_urb(urb, td);
631 uhci_fill_td(td, status, destination | uhci_explen(pktsze), 552 uhci_fill_td(td, status, destination | uhci_explen(pktsze),
632 data); 553 data);
554 plink = &td->link;
633 555
634 data += pktsze; 556 data += pktsze;
635 len -= pktsze; 557 len -= pktsze;
@@ -640,7 +562,8 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, struct ur
640 */ 562 */
641 td = uhci_alloc_td(uhci); 563 td = uhci_alloc_td(uhci);
642 if (!td) 564 if (!td)
643 return -ENOMEM; 565 goto nomem;
566 *plink = cpu_to_le32(td->dma_handle);
644 567
645 /* 568 /*
646 * It's IN if the pipe is an output pipe or we're not expecting 569 * It's IN if the pipe is an output pipe or we're not expecting
@@ -658,16 +581,21 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, struct ur
658 581
659 uhci_add_td_to_urb(urb, td); 582 uhci_add_td_to_urb(urb, td);
660 uhci_fill_td(td, status | TD_CTRL_IOC, 583 uhci_fill_td(td, status | TD_CTRL_IOC,
661 destination | uhci_explen(0), 0); 584 destination | uhci_explen(0), 0);
662 585 plink = &td->link;
663 qh = uhci_alloc_qh(uhci);
664 if (!qh)
665 return -ENOMEM;
666 586
667 urbp->qh = qh; 587 /*
668 qh->urbp = urbp; 588 * Build the new dummy TD and activate the old one
589 */
590 td = uhci_alloc_td(uhci);
591 if (!td)
592 goto nomem;
593 *plink = cpu_to_le32(td->dma_handle);
669 594
670 uhci_insert_tds_in_qh(qh, urb, UHCI_PTR_BREADTH); 595 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0);
596 wmb();
597 qh->dummy_td->status |= __constant_cpu_to_le32(TD_CTRL_ACTIVE);
598 qh->dummy_td = td;
671 599
672 /* Low-speed transfers get a different queue, and won't hog the bus. 600 /* Low-speed transfers get a different queue, and won't hog the bus.
673 * Also, some devices enumerate better without FSBR; the easiest way 601 * Also, some devices enumerate better without FSBR; the easiest way
@@ -675,18 +603,17 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, struct ur
675 * isn't in the CONFIGURED state. */ 603 * isn't in the CONFIGURED state. */
676 if (urb->dev->speed == USB_SPEED_LOW || 604 if (urb->dev->speed == USB_SPEED_LOW ||
677 urb->dev->state != USB_STATE_CONFIGURED) 605 urb->dev->state != USB_STATE_CONFIGURED)
678 skelqh = uhci->skel_ls_control_qh; 606 qh->skel = uhci->skel_ls_control_qh;
679 else { 607 else {
680 skelqh = uhci->skel_fs_control_qh; 608 qh->skel = uhci->skel_fs_control_qh;
681 uhci_inc_fsbr(uhci, urb); 609 uhci_inc_fsbr(uhci, urb);
682 } 610 }
611 return 0;
683 612
684 if (eurb) 613nomem:
685 uhci_append_queued_urb(uhci, eurb, urb); 614 /* Remove the dummy TD from the td_list so it doesn't get freed */
686 else 615 uhci_remove_td_from_urb(qh->dummy_td);
687 uhci_insert_qh(uhci, skelqh, urb); 616 return -ENOMEM;
688
689 return -EINPROGRESS;
690} 617}
691 618
692/* 619/*
@@ -703,7 +630,7 @@ static int usb_control_retrigger_status(struct uhci_hcd *uhci, struct urb *urb)
703 struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; 630 struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv;
704 struct uhci_td *td; 631 struct uhci_td *td;
705 632
706 urbp->short_control_packet = 1; 633 urbp->short_transfer = 1;
707 634
708 td = list_entry(urbp->td_list.prev, struct uhci_td, list); 635 td = list_entry(urbp->td_list.prev, struct uhci_td, list);
709 urbp->qh->element = cpu_to_le32(td->dma_handle); 636 urbp->qh->element = cpu_to_le32(td->dma_handle);
@@ -720,16 +647,14 @@ static int uhci_result_control(struct uhci_hcd *uhci, struct urb *urb)
720 unsigned int status; 647 unsigned int status;
721 int ret = 0; 648 int ret = 0;
722 649
723 if (list_empty(&urbp->td_list))
724 return -EINVAL;
725
726 head = &urbp->td_list; 650 head = &urbp->td_list;
727 651 if (urbp->short_transfer) {
728 if (urbp->short_control_packet) {
729 tmp = head->prev; 652 tmp = head->prev;
730 goto status_stage; 653 goto status_stage;
731 } 654 }
732 655
656 urb->actual_length = 0;
657
733 tmp = head->next; 658 tmp = head->next;
734 td = list_entry(tmp, struct uhci_td, list); 659 td = list_entry(tmp, struct uhci_td, list);
735 660
@@ -742,8 +667,6 @@ static int uhci_result_control(struct uhci_hcd *uhci, struct urb *urb)
742 if (status) 667 if (status)
743 goto td_error; 668 goto td_error;
744 669
745 urb->actual_length = 0;
746
747 /* The rest of the TDs (but the last) are data */ 670 /* The rest of the TDs (but the last) are data */
748 tmp = tmp->next; 671 tmp = tmp->next;
749 while (tmp != head && tmp->next != head) { 672 while (tmp != head && tmp->next != head) {
@@ -770,10 +693,7 @@ static int uhci_result_control(struct uhci_hcd *uhci, struct urb *urb)
770 goto err; 693 goto err;
771 } 694 }
772 695
773 if (uhci_packetid(td_token(td)) == USB_PID_IN) 696 return usb_control_retrigger_status(uhci, urb);
774 return usb_control_retrigger_status(uhci, urb);
775 else
776 return 0;
777 } 697 }
778 } 698 }
779 699
@@ -814,34 +734,40 @@ err:
814 if (errbuf) { 734 if (errbuf) {
815 /* Print the chain for debugging purposes */ 735 /* Print the chain for debugging purposes */
816 uhci_show_qh(urbp->qh, errbuf, ERRBUF_LEN, 0); 736 uhci_show_qh(urbp->qh, errbuf, ERRBUF_LEN, 0);
817
818 lprintk(errbuf); 737 lprintk(errbuf);
819 } 738 }
820 } 739 }
821 740
741 /* Note that the queue has stopped */
742 urbp->qh->element = UHCI_PTR_TERM;
743 urbp->qh->is_stopped = 1;
822 return ret; 744 return ret;
823} 745}
824 746
825/* 747/*
826 * Common submit for bulk and interrupt 748 * Common submit for bulk and interrupt
827 */ 749 */
828static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, struct urb *eurb, struct uhci_qh *skelqh) 750static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb,
751 struct uhci_qh *qh)
829{ 752{
830 struct uhci_td *td; 753 struct uhci_td *td;
831 struct uhci_qh *qh;
832 unsigned long destination, status; 754 unsigned long destination, status;
833 int maxsze = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); 755 int maxsze = le16_to_cpu(qh->hep->desc.wMaxPacketSize);
834 int len = urb->transfer_buffer_length; 756 int len = urb->transfer_buffer_length;
835 struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv;
836 dma_addr_t data = urb->transfer_dma; 757 dma_addr_t data = urb->transfer_dma;
758 __le32 *plink;
759 unsigned int toggle;
837 760
838 if (len < 0) 761 if (len < 0)
839 return -EINVAL; 762 return -EINVAL;
840 763
841 /* The "pipe" thing contains the destination in bits 8--18 */ 764 /* The "pipe" thing contains the destination in bits 8--18 */
842 destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid(urb->pipe); 765 destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid(urb->pipe);
766 toggle = usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe),
767 usb_pipeout(urb->pipe));
843 768
844 status = uhci_maxerr(3) | TD_CTRL_ACTIVE; 769 /* 3 errors, dummy TD remains inactive */
770 status = uhci_maxerr(3);
845 if (urb->dev->speed == USB_SPEED_LOW) 771 if (urb->dev->speed == USB_SPEED_LOW)
846 status |= TD_CTRL_LS; 772 status |= TD_CTRL_LS;
847 if (usb_pipein(urb->pipe)) 773 if (usb_pipein(urb->pipe))
@@ -850,30 +776,34 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, struct urb
850 /* 776 /*
851 * Build the DATA TDs 777 * Build the DATA TDs
852 */ 778 */
779 plink = NULL;
780 td = qh->dummy_td;
853 do { /* Allow zero length packets */ 781 do { /* Allow zero length packets */
854 int pktsze = maxsze; 782 int pktsze = maxsze;
855 783
856 if (pktsze >= len) { 784 if (len <= pktsze) { /* The last packet */
857 pktsze = len; 785 pktsze = len;
858 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) 786 if (!(urb->transfer_flags & URB_SHORT_NOT_OK))
859 status &= ~TD_CTRL_SPD; 787 status &= ~TD_CTRL_SPD;
860 } 788 }
861 789
862 td = uhci_alloc_td(uhci); 790 if (plink) {
863 if (!td) 791 td = uhci_alloc_td(uhci);
864 return -ENOMEM; 792 if (!td)
865 793 goto nomem;
794 *plink = cpu_to_le32(td->dma_handle);
795 }
866 uhci_add_td_to_urb(urb, td); 796 uhci_add_td_to_urb(urb, td);
867 uhci_fill_td(td, status, destination | uhci_explen(pktsze) | 797 uhci_fill_td(td, status,
868 (usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe), 798 destination | uhci_explen(pktsze) |
869 usb_pipeout(urb->pipe)) << TD_TOKEN_TOGGLE_SHIFT), 799 (toggle << TD_TOKEN_TOGGLE_SHIFT),
870 data); 800 data);
801 plink = &td->link;
802 status |= TD_CTRL_ACTIVE;
871 803
872 data += pktsze; 804 data += pktsze;
873 len -= maxsze; 805 len -= maxsze;
874 806 toggle ^= 1;
875 usb_dotoggle(urb->dev, usb_pipeendpoint(urb->pipe),
876 usb_pipeout(urb->pipe));
877 } while (len > 0); 807 } while (len > 0);
878 808
879 /* 809 /*
@@ -883,20 +813,22 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, struct urb
883 * however, if transfer_length == 0, the zero packet was already 813 * however, if transfer_length == 0, the zero packet was already
884 * prepared above. 814 * prepared above.
885 */ 815 */
886 if (usb_pipeout(urb->pipe) && (urb->transfer_flags & URB_ZERO_PACKET) && 816 if ((urb->transfer_flags & URB_ZERO_PACKET) &&
887 !len && urb->transfer_buffer_length) { 817 usb_pipeout(urb->pipe) && len == 0 &&
818 urb->transfer_buffer_length > 0) {
888 td = uhci_alloc_td(uhci); 819 td = uhci_alloc_td(uhci);
889 if (!td) 820 if (!td)
890 return -ENOMEM; 821 goto nomem;
822 *plink = cpu_to_le32(td->dma_handle);
891 823
892 uhci_add_td_to_urb(urb, td); 824 uhci_add_td_to_urb(urb, td);
893 uhci_fill_td(td, status, destination | uhci_explen(0) | 825 uhci_fill_td(td, status,
894 (usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe), 826 destination | uhci_explen(0) |
895 usb_pipeout(urb->pipe)) << TD_TOKEN_TOGGLE_SHIFT), 827 (toggle << TD_TOKEN_TOGGLE_SHIFT),
896 data); 828 data);
829 plink = &td->link;
897 830
898 usb_dotoggle(urb->dev, usb_pipeendpoint(urb->pipe), 831 toggle ^= 1;
899 usb_pipeout(urb->pipe));
900 } 832 }
901 833
902 /* Set the interrupt-on-completion flag on the last packet. 834 /* Set the interrupt-on-completion flag on the last packet.
@@ -905,24 +837,29 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, struct urb
905 * fast side but not enough to justify delaying an interrupt 837 * fast side but not enough to justify delaying an interrupt
906 * more than 2 or 3 URBs, so we will ignore the URB_NO_INTERRUPT 838 * more than 2 or 3 URBs, so we will ignore the URB_NO_INTERRUPT
907 * flag setting. */ 839 * flag setting. */
908 td->status |= cpu_to_le32(TD_CTRL_IOC); 840 td->status |= __constant_cpu_to_le32(TD_CTRL_IOC);
909 841
910 qh = uhci_alloc_qh(uhci); 842 /*
911 if (!qh) 843 * Build the new dummy TD and activate the old one
912 return -ENOMEM; 844 */
913 845 td = uhci_alloc_td(uhci);
914 urbp->qh = qh; 846 if (!td)
915 qh->urbp = urbp; 847 goto nomem;
848 *plink = cpu_to_le32(td->dma_handle);
916 849
917 /* Always breadth first */ 850 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0);
918 uhci_insert_tds_in_qh(qh, urb, UHCI_PTR_BREADTH); 851 wmb();
852 qh->dummy_td->status |= __constant_cpu_to_le32(TD_CTRL_ACTIVE);
853 qh->dummy_td = td;
919 854
920 if (eurb) 855 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
921 uhci_append_queued_urb(uhci, eurb, urb); 856 usb_pipeout(urb->pipe), toggle);
922 else 857 return 0;
923 uhci_insert_qh(uhci, skelqh, urb);
924 858
925 return -EINPROGRESS; 859nomem:
860 /* Remove the dummy TD from the td_list so it doesn't get freed */
861 uhci_remove_td_from_urb(qh->dummy_td);
862 return -ENOMEM;
926} 863}
927 864
928/* 865/*
@@ -954,8 +891,27 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb)
954 if (urb->transfer_flags & URB_SHORT_NOT_OK) { 891 if (urb->transfer_flags & URB_SHORT_NOT_OK) {
955 ret = -EREMOTEIO; 892 ret = -EREMOTEIO;
956 goto err; 893 goto err;
957 } else 894 }
958 return 0; 895
896 /*
897 * This URB stopped short of its end. We have to
898 * fix up the toggles of the following URBs on the
899 * queue and restart the queue.
900 *
901 * Do this only the first time we encounter the
902 * short URB.
903 */
904 if (!urbp->short_transfer) {
905 urbp->short_transfer = 1;
906 urbp->qh->initial_toggle =
907 uhci_toggle(td_token(td)) ^ 1;
908 uhci_fixup_toggles(urbp->qh, 1);
909
910 td = list_entry(urbp->td_list.prev,
911 struct uhci_td, list);
912 urbp->qh->element = td->link;
913 }
914 break;
959 } 915 }
960 } 916 }
961 917
@@ -964,31 +920,30 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb)
964td_error: 920td_error:
965 ret = uhci_map_status(status, uhci_packetout(td_token(td))); 921 ret = uhci_map_status(status, uhci_packetout(td_token(td)));
966 922
967err:
968 /*
969 * Enable this chunk of code if you want to see some more debugging.
970 * But be careful, it has the tendancy to starve out khubd and prevent
971 * disconnects from happening successfully if you have a slow debug
972 * log interface (like a serial console.
973 */
974#if 0
975 if ((debug == 1 && ret != -EPIPE) || debug > 1) { 923 if ((debug == 1 && ret != -EPIPE) || debug > 1) {
976 /* Some debugging code */ 924 /* Some debugging code */
977 dev_dbg(uhci_dev(uhci), "%s: failed with status %x\n", 925 dev_dbg(uhci_dev(uhci), "%s: failed with status %x\n",
978 __FUNCTION__, status); 926 __FUNCTION__, status);
979 927
980 if (errbuf) { 928 if (debug > 1 && errbuf) {
981 /* Print the chain for debugging purposes */ 929 /* Print the chain for debugging purposes */
982 uhci_show_qh(urbp->qh, errbuf, ERRBUF_LEN, 0); 930 uhci_show_qh(urbp->qh, errbuf, ERRBUF_LEN, 0);
983
984 lprintk(errbuf); 931 lprintk(errbuf);
985 } 932 }
986 } 933 }
987#endif 934err:
935
936 /* Note that the queue has stopped and save the next toggle value */
937 urbp->qh->element = UHCI_PTR_TERM;
938 urbp->qh->is_stopped = 1;
939 urbp->qh->needs_fixup = 1;
940 urbp->qh->initial_toggle = uhci_toggle(td_token(td)) ^
941 (ret == -EREMOTEIO);
988 return ret; 942 return ret;
989} 943}
990 944
991static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb, struct urb *eurb) 945static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb,
946 struct uhci_qh *qh)
992{ 947{
993 int ret; 948 int ret;
994 949
@@ -996,95 +951,60 @@ static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb, struc
996 if (urb->dev->speed == USB_SPEED_LOW) 951 if (urb->dev->speed == USB_SPEED_LOW)
997 return -EINVAL; 952 return -EINVAL;
998 953
999 ret = uhci_submit_common(uhci, urb, eurb, uhci->skel_bulk_qh); 954 qh->skel = uhci->skel_bulk_qh;
1000 if (ret == -EINPROGRESS) 955 ret = uhci_submit_common(uhci, urb, qh);
956 if (ret == 0)
1001 uhci_inc_fsbr(uhci, urb); 957 uhci_inc_fsbr(uhci, urb);
1002
1003 return ret; 958 return ret;
1004} 959}
1005 960
1006static inline int uhci_submit_interrupt(struct uhci_hcd *uhci, struct urb *urb, struct urb *eurb) 961static inline int uhci_submit_interrupt(struct uhci_hcd *uhci, struct urb *urb,
962 struct uhci_qh *qh)
1007{ 963{
1008 /* USB 1.1 interrupt transfers only involve one packet per interval; 964 /* USB 1.1 interrupt transfers only involve one packet per interval.
1009 * that's the uhci_submit_common() "breadth first" policy. Drivers 965 * Drivers can submit URBs of any length, but longer ones will need
1010 * can submit urbs of any length, but longer ones might need many 966 * multiple intervals to complete.
1011 * intervals to complete.
1012 */ 967 */
1013 return uhci_submit_common(uhci, urb, eurb, uhci->skelqh[__interval_to_skel(urb->interval)]); 968 qh->skel = uhci->skelqh[__interval_to_skel(urb->interval)];
969 return uhci_submit_common(uhci, urb, qh);
1014} 970}
1015 971
1016/* 972/*
1017 * Isochronous transfers 973 * Isochronous transfers
1018 */ 974 */
1019static int isochronous_find_limits(struct uhci_hcd *uhci, struct urb *urb, unsigned int *start, unsigned int *end) 975static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb,
1020{ 976 struct uhci_qh *qh)
1021 struct urb *last_urb = NULL;
1022 struct urb_priv *up;
1023 int ret = 0;
1024
1025 list_for_each_entry(up, &uhci->urb_list, urb_list) {
1026 struct urb *u = up->urb;
1027
1028 /* look for pending URBs with identical pipe handle */
1029 if ((urb->pipe == u->pipe) && (urb->dev == u->dev) &&
1030 (u->status == -EINPROGRESS) && (u != urb)) {
1031 if (!last_urb)
1032 *start = u->start_frame;
1033 last_urb = u;
1034 }
1035 }
1036
1037 if (last_urb) {
1038 *end = (last_urb->start_frame + last_urb->number_of_packets *
1039 last_urb->interval) & (UHCI_NUMFRAMES-1);
1040 ret = 0;
1041 } else
1042 ret = -1; /* no previous urb found */
1043
1044 return ret;
1045}
1046
1047static int isochronous_find_start(struct uhci_hcd *uhci, struct urb *urb)
1048{ 977{
1049 int limits; 978 struct uhci_td *td = NULL; /* Since urb->number_of_packets > 0 */
1050 unsigned int start = 0, end = 0; 979 int i, frame;
980 unsigned long destination, status;
981 struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv;
1051 982
1052 if (urb->number_of_packets > 900) /* 900? Why? */ 983 if (urb->number_of_packets > 900) /* 900? Why? */
1053 return -EFBIG; 984 return -EFBIG;
1054 985
1055 limits = isochronous_find_limits(uhci, urb, &start, &end); 986 status = TD_CTRL_ACTIVE | TD_CTRL_IOS;
987 destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid(urb->pipe);
1056 988
989 /* Figure out the starting frame number */
1057 if (urb->transfer_flags & URB_ISO_ASAP) { 990 if (urb->transfer_flags & URB_ISO_ASAP) {
1058 if (limits) { 991 if (list_empty(&qh->queue)) {
1059 uhci_get_current_frame_number(uhci); 992 uhci_get_current_frame_number(uhci);
1060 urb->start_frame = (uhci->frame_number + 10) 993 urb->start_frame = (uhci->frame_number + 10);
1061 & (UHCI_NUMFRAMES - 1); 994
1062 } else 995 } else { /* Go right after the last one */
1063 urb->start_frame = end; 996 struct urb *last_urb;
997
998 last_urb = list_entry(qh->queue.prev,
999 struct urb_priv, node)->urb;
1000 urb->start_frame = (last_urb->start_frame +
1001 last_urb->number_of_packets *
1002 last_urb->interval);
1003 }
1064 } else { 1004 } else {
1065 urb->start_frame &= (UHCI_NUMFRAMES - 1);
1066 /* FIXME: Sanity check */ 1005 /* FIXME: Sanity check */
1067 } 1006 }
1068 1007 urb->start_frame &= (UHCI_NUMFRAMES - 1);
1069 return 0;
1070}
1071
1072/*
1073 * Isochronous transfers
1074 */
1075static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb)
1076{
1077 struct uhci_td *td;
1078 int i, ret, frame;
1079 int status, destination;
1080 struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv;
1081
1082 status = TD_CTRL_ACTIVE | TD_CTRL_IOS;
1083 destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid(urb->pipe);
1084
1085 ret = isochronous_find_start(uhci, urb);
1086 if (ret)
1087 return ret;
1088 1008
1089 for (i = 0; i < urb->number_of_packets; i++) { 1009 for (i = 0; i < urb->number_of_packets; i++) {
1090 td = uhci_alloc_td(uhci); 1010 td = uhci_alloc_td(uhci);
@@ -1092,20 +1012,25 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb)
1092 return -ENOMEM; 1012 return -ENOMEM;
1093 1013
1094 uhci_add_td_to_urb(urb, td); 1014 uhci_add_td_to_urb(urb, td);
1095 uhci_fill_td(td, status, destination | uhci_explen(urb->iso_frame_desc[i].length), 1015 uhci_fill_td(td, status, destination |
1096 urb->transfer_dma + urb->iso_frame_desc[i].offset); 1016 uhci_explen(urb->iso_frame_desc[i].length),
1097 1017 urb->transfer_dma +
1098 if (i + 1 >= urb->number_of_packets) 1018 urb->iso_frame_desc[i].offset);
1099 td->status |= cpu_to_le32(TD_CTRL_IOC);
1100 } 1019 }
1101 1020
1021 /* Set the interrupt-on-completion flag on the last packet. */
1022 td->status |= __constant_cpu_to_le32(TD_CTRL_IOC);
1023
1024 qh->skel = uhci->skel_iso_qh;
1025
1026 /* Add the TDs to the frame list */
1102 frame = urb->start_frame; 1027 frame = urb->start_frame;
1103 list_for_each_entry(td, &urbp->td_list, list) { 1028 list_for_each_entry(td, &urbp->td_list, list) {
1104 uhci_insert_td_frame_list(uhci, td, frame); 1029 uhci_insert_td_in_frame_list(uhci, td, frame);
1105 frame += urb->interval; 1030 frame += urb->interval;
1106 } 1031 }
1107 1032
1108 return -EINPROGRESS; 1033 return 0;
1109} 1034}
1110 1035
1111static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb) 1036static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb)
@@ -1139,80 +1064,67 @@ static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb)
1139 1064
1140 i++; 1065 i++;
1141 } 1066 }
1142 unlink_isochronous_tds(uhci, urb);
1143 1067
1144 return ret; 1068 return ret;
1145} 1069}
1146 1070
1147static struct urb *uhci_find_urb_ep(struct uhci_hcd *uhci, struct urb *urb)
1148{
1149 struct urb_priv *up;
1150
1151 /* We don't match Isoc transfers since they are special */
1152 if (usb_pipeisoc(urb->pipe))
1153 return NULL;
1154
1155 list_for_each_entry(up, &uhci->urb_list, urb_list) {
1156 struct urb *u = up->urb;
1157
1158 if (u->dev == urb->dev && u->status == -EINPROGRESS) {
1159 /* For control, ignore the direction */
1160 if (usb_pipecontrol(urb->pipe) &&
1161 (u->pipe & ~USB_DIR_IN) == (urb->pipe & ~USB_DIR_IN))
1162 return u;
1163 else if (u->pipe == urb->pipe)
1164 return u;
1165 }
1166 }
1167
1168 return NULL;
1169}
1170
1171static int uhci_urb_enqueue(struct usb_hcd *hcd, 1071static int uhci_urb_enqueue(struct usb_hcd *hcd,
1172 struct usb_host_endpoint *ep, 1072 struct usb_host_endpoint *hep,
1173 struct urb *urb, gfp_t mem_flags) 1073 struct urb *urb, gfp_t mem_flags)
1174{ 1074{
1175 int ret; 1075 int ret;
1176 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 1076 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
1177 unsigned long flags; 1077 unsigned long flags;
1178 struct urb *eurb; 1078 struct urb_priv *urbp;
1079 struct uhci_qh *qh;
1179 int bustime; 1080 int bustime;
1180 1081
1181 spin_lock_irqsave(&uhci->lock, flags); 1082 spin_lock_irqsave(&uhci->lock, flags);
1182 1083
1183 ret = urb->status; 1084 ret = urb->status;
1184 if (ret != -EINPROGRESS) /* URB already unlinked! */ 1085 if (ret != -EINPROGRESS) /* URB already unlinked! */
1185 goto out; 1086 goto done;
1186 1087
1187 eurb = uhci_find_urb_ep(uhci, urb); 1088 ret = -ENOMEM;
1089 urbp = uhci_alloc_urb_priv(uhci, urb);
1090 if (!urbp)
1091 goto done;
1188 1092
1189 if (!uhci_alloc_urb_priv(uhci, urb)) { 1093 if (hep->hcpriv)
1190 ret = -ENOMEM; 1094 qh = (struct uhci_qh *) hep->hcpriv;
1191 goto out; 1095 else {
1096 qh = uhci_alloc_qh(uhci, urb->dev, hep);
1097 if (!qh)
1098 goto err_no_qh;
1192 } 1099 }
1100 urbp->qh = qh;
1193 1101
1194 switch (usb_pipetype(urb->pipe)) { 1102 switch (usb_pipetype(urb->pipe)) {
1195 case PIPE_CONTROL: 1103 case PIPE_CONTROL:
1196 ret = uhci_submit_control(uhci, urb, eurb); 1104 ret = uhci_submit_control(uhci, urb, qh);
1105 break;
1106 case PIPE_BULK:
1107 ret = uhci_submit_bulk(uhci, urb, qh);
1197 break; 1108 break;
1198 case PIPE_INTERRUPT: 1109 case PIPE_INTERRUPT:
1199 if (!eurb) { 1110 if (list_empty(&qh->queue)) {
1200 bustime = usb_check_bandwidth(urb->dev, urb); 1111 bustime = usb_check_bandwidth(urb->dev, urb);
1201 if (bustime < 0) 1112 if (bustime < 0)
1202 ret = bustime; 1113 ret = bustime;
1203 else { 1114 else {
1204 ret = uhci_submit_interrupt(uhci, urb, eurb); 1115 ret = uhci_submit_interrupt(uhci, urb, qh);
1205 if (ret == -EINPROGRESS) 1116 if (ret == 0)
1206 usb_claim_bandwidth(urb->dev, urb, bustime, 0); 1117 usb_claim_bandwidth(urb->dev, urb, bustime, 0);
1207 } 1118 }
1208 } else { /* inherit from parent */ 1119 } else { /* inherit from parent */
1209 urb->bandwidth = eurb->bandwidth; 1120 struct urb_priv *eurbp;
1210 ret = uhci_submit_interrupt(uhci, urb, eurb); 1121
1122 eurbp = list_entry(qh->queue.prev, struct urb_priv,
1123 node);
1124 urb->bandwidth = eurbp->urb->bandwidth;
1125 ret = uhci_submit_interrupt(uhci, urb, qh);
1211 } 1126 }
1212 break; 1127 break;
1213 case PIPE_BULK:
1214 ret = uhci_submit_bulk(uhci, urb, eurb);
1215 break;
1216 case PIPE_ISOCHRONOUS: 1128 case PIPE_ISOCHRONOUS:
1217 bustime = usb_check_bandwidth(urb->dev, urb); 1129 bustime = usb_check_bandwidth(urb->dev, urb);
1218 if (bustime < 0) { 1130 if (bustime < 0) {
@@ -1220,221 +1132,208 @@ static int uhci_urb_enqueue(struct usb_hcd *hcd,
1220 break; 1132 break;
1221 } 1133 }
1222 1134
1223 ret = uhci_submit_isochronous(uhci, urb); 1135 ret = uhci_submit_isochronous(uhci, urb, qh);
1224 if (ret == -EINPROGRESS) 1136 if (ret == 0)
1225 usb_claim_bandwidth(urb->dev, urb, bustime, 1); 1137 usb_claim_bandwidth(urb->dev, urb, bustime, 1);
1226 break; 1138 break;
1227 } 1139 }
1140 if (ret != 0)
1141 goto err_submit_failed;
1142
1143 /* Add this URB to the QH */
1144 urbp->qh = qh;
1145 list_add_tail(&urbp->node, &qh->queue);
1228 1146
1229 if (ret != -EINPROGRESS) { 1147 /* If the new URB is the first and only one on this QH then either
1230 /* Submit failed, so delete it from the urb_list */ 1148 * the QH is new and idle or else it's unlinked and waiting to
1231 struct urb_priv *urbp = urb->hcpriv; 1149 * become idle, so we can activate it right away. */
1150 if (qh->queue.next == &urbp->node)
1151 uhci_activate_qh(uhci, qh);
1152 goto done;
1232 1153
1233 list_del_init(&urbp->urb_list); 1154err_submit_failed:
1234 uhci_destroy_urb_priv(uhci, urb); 1155 if (qh->state == QH_STATE_IDLE)
1235 } else 1156 uhci_make_qh_idle(uhci, qh); /* Reclaim unused QH */
1236 ret = 0;
1237 1157
1238out: 1158err_no_qh:
1159 uhci_free_urb_priv(uhci, urbp);
1160
1161done:
1239 spin_unlock_irqrestore(&uhci->lock, flags); 1162 spin_unlock_irqrestore(&uhci->lock, flags);
1240 return ret; 1163 return ret;
1241} 1164}
1242 1165
1243/* 1166static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
1244 * Return the result of a transfer
1245 */
1246static void uhci_transfer_result(struct uhci_hcd *uhci, struct urb *urb)
1247{ 1167{
1248 int ret = -EINPROGRESS; 1168 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
1169 unsigned long flags;
1249 struct urb_priv *urbp; 1170 struct urb_priv *urbp;
1250 1171
1251 spin_lock(&urb->lock); 1172 spin_lock_irqsave(&uhci->lock, flags);
1173 urbp = urb->hcpriv;
1174 if (!urbp) /* URB was never linked! */
1175 goto done;
1176
1177 /* Remove Isochronous TDs from the frame list ASAP */
1178 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
1179 uhci_unlink_isochronous_tds(uhci, urb);
1180 uhci_unlink_qh(uhci, urbp->qh);
1181
1182done:
1183 spin_unlock_irqrestore(&uhci->lock, flags);
1184 return 0;
1185}
1252 1186
1253 urbp = (struct urb_priv *)urb->hcpriv; 1187/*
1188 * Finish unlinking an URB and give it back
1189 */
1190static void uhci_giveback_urb(struct uhci_hcd *uhci, struct uhci_qh *qh,
1191 struct urb *urb, struct pt_regs *regs)
1192__releases(uhci->lock)
1193__acquires(uhci->lock)
1194{
1195 struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv;
1254 1196
1255 if (urb->status != -EINPROGRESS) /* URB already dequeued */ 1197 /* Isochronous TDs get unlinked directly from the frame list */
1256 goto out; 1198 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
1199 uhci_unlink_isochronous_tds(uhci, urb);
1200
1201 /* If the URB isn't first on its queue, adjust the link pointer
1202 * of the last TD in the previous URB. */
1203 else if (qh->queue.next != &urbp->node) {
1204 struct urb_priv *purbp;
1205 struct uhci_td *ptd, *ltd;
1206
1207 purbp = list_entry(urbp->node.prev, struct urb_priv, node);
1208 ptd = list_entry(purbp->td_list.prev, struct uhci_td,
1209 list);
1210 ltd = list_entry(urbp->td_list.prev, struct uhci_td,
1211 list);
1212 ptd->link = ltd->link;
1213 }
1257 1214
1258 switch (usb_pipetype(urb->pipe)) { 1215 /* Take the URB off the QH's queue. If the queue is now empty,
1259 case PIPE_CONTROL: 1216 * this is a perfect time for a toggle fixup. */
1260 ret = uhci_result_control(uhci, urb); 1217 list_del_init(&urbp->node);
1261 break; 1218 if (list_empty(&qh->queue) && qh->needs_fixup) {
1262 case PIPE_BULK: 1219 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1263 case PIPE_INTERRUPT: 1220 usb_pipeout(urb->pipe), qh->initial_toggle);
1264 ret = uhci_result_common(uhci, urb); 1221 qh->needs_fixup = 0;
1265 break;
1266 case PIPE_ISOCHRONOUS:
1267 ret = uhci_result_isochronous(uhci, urb);
1268 break;
1269 } 1222 }
1270 1223
1271 if (ret == -EINPROGRESS) 1224 uhci_dec_fsbr(uhci, urb); /* Safe since it checks */
1272 goto out; 1225 uhci_free_urb_priv(uhci, urbp);
1273 urb->status = ret;
1274 1226
1275 switch (usb_pipetype(urb->pipe)) { 1227 switch (usb_pipetype(urb->pipe)) {
1276 case PIPE_CONTROL:
1277 case PIPE_BULK:
1278 case PIPE_ISOCHRONOUS: 1228 case PIPE_ISOCHRONOUS:
1279 /* Release bandwidth for Interrupt or Isoc. transfers */ 1229 /* Release bandwidth for Interrupt or Isoc. transfers */
1280 if (urb->bandwidth) 1230 if (urb->bandwidth)
1281 usb_release_bandwidth(urb->dev, urb, 1); 1231 usb_release_bandwidth(urb->dev, urb, 1);
1282 uhci_unlink_generic(uhci, urb);
1283 break; 1232 break;
1284 case PIPE_INTERRUPT: 1233 case PIPE_INTERRUPT:
1285 /* Release bandwidth for Interrupt or Isoc. transfers */ 1234 /* Release bandwidth for Interrupt or Isoc. transfers */
1286 /* Make sure we don't release if we have a queued URB */ 1235 /* Make sure we don't release if we have a queued URB */
1287 if (list_empty(&urbp->queue_list) && urb->bandwidth) 1236 if (list_empty(&qh->queue) && urb->bandwidth)
1288 usb_release_bandwidth(urb->dev, urb, 0); 1237 usb_release_bandwidth(urb->dev, urb, 0);
1289 else 1238 else
1290 /* bandwidth was passed on to queued URB, */ 1239 /* bandwidth was passed on to queued URB, */
1291 /* so don't let usb_unlink_urb() release it */ 1240 /* so don't let usb_unlink_urb() release it */
1292 urb->bandwidth = 0; 1241 urb->bandwidth = 0;
1293 uhci_unlink_generic(uhci, urb);
1294 break; 1242 break;
1295 default:
1296 dev_info(uhci_dev(uhci), "%s: unknown pipe type %d "
1297 "for urb %p\n",
1298 __FUNCTION__, usb_pipetype(urb->pipe), urb);
1299 } 1243 }
1300 1244
1301 /* Move it from uhci->urb_list to uhci->complete_list */ 1245 spin_unlock(&uhci->lock);
1302 uhci_moveto_complete(uhci, urbp); 1246 usb_hcd_giveback_urb(uhci_to_hcd(uhci), urb, regs);
1303 1247 spin_lock(&uhci->lock);
1304out:
1305 spin_unlock(&urb->lock);
1306}
1307
1308static void uhci_unlink_generic(struct uhci_hcd *uhci, struct urb *urb)
1309{
1310 struct list_head *head;
1311 struct uhci_td *td;
1312 struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv;
1313 int prevactive = 0;
1314
1315 uhci_dec_fsbr(uhci, urb); /* Safe since it checks */
1316 1248
1317 /* 1249 /* If the queue is now empty, we can unlink the QH and give up its
1318 * Now we need to find out what the last successful toggle was 1250 * reserved bandwidth. */
1319 * so we can update the local data toggle for the next transfer 1251 if (list_empty(&qh->queue)) {
1320 * 1252 uhci_unlink_qh(uhci, qh);
1321 * There are 2 ways the last successful completed TD is found:
1322 *
1323 * 1) The TD is NOT active and the actual length < expected length
1324 * 2) The TD is NOT active and it's the last TD in the chain
1325 *
1326 * and a third way the first uncompleted TD is found:
1327 *
1328 * 3) The TD is active and the previous TD is NOT active
1329 *
1330 * Control and Isochronous ignore the toggle, so this is safe
1331 * for all types
1332 *
1333 * FIXME: The toggle fixups won't be 100% reliable until we
1334 * change over to using a single queue for each endpoint and
1335 * stop the queue before unlinking.
1336 */
1337 head = &urbp->td_list;
1338 list_for_each_entry(td, head, list) {
1339 unsigned int ctrlstat = td_status(td);
1340 1253
1341 if (!(ctrlstat & TD_CTRL_ACTIVE) && 1254 /* Bandwidth stuff not yet implemented */
1342 (uhci_actual_length(ctrlstat) <
1343 uhci_expected_length(td_token(td)) ||
1344 td->list.next == head))
1345 usb_settoggle(urb->dev, uhci_endpoint(td_token(td)),
1346 uhci_packetout(td_token(td)),
1347 uhci_toggle(td_token(td)) ^ 1);
1348 else if ((ctrlstat & TD_CTRL_ACTIVE) && !prevactive)
1349 usb_settoggle(urb->dev, uhci_endpoint(td_token(td)),
1350 uhci_packetout(td_token(td)),
1351 uhci_toggle(td_token(td)));
1352
1353 prevactive = ctrlstat & TD_CTRL_ACTIVE;
1354 } 1255 }
1355
1356 uhci_delete_queued_urb(uhci, urb);
1357
1358 /* The interrupt loop will reclaim the QHs */
1359 uhci_remove_qh(uhci, urbp->qh);
1360 urbp->qh = NULL;
1361} 1256}
1362 1257
1363static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) 1258/*
1259 * Scan the URBs in a QH's queue
1260 */
1261#define QH_FINISHED_UNLINKING(qh) \
1262 (qh->state == QH_STATE_UNLINKING && \
1263 uhci->frame_number + uhci->is_stopped != qh->unlink_frame)
1264
1265static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh,
1266 struct pt_regs *regs)
1364{ 1267{
1365 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
1366 unsigned long flags;
1367 struct urb_priv *urbp; 1268 struct urb_priv *urbp;
1269 struct urb *urb;
1270 int status;
1368 1271
1369 spin_lock_irqsave(&uhci->lock, flags); 1272 while (!list_empty(&qh->queue)) {
1370 urbp = urb->hcpriv; 1273 urbp = list_entry(qh->queue.next, struct urb_priv, node);
1371 if (!urbp) /* URB was never linked! */ 1274 urb = urbp->urb;
1372 goto done;
1373 list_del_init(&urbp->urb_list);
1374
1375 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
1376 unlink_isochronous_tds(uhci, urb);
1377 uhci_unlink_generic(uhci, urb);
1378
1379 uhci_get_current_frame_number(uhci);
1380 if (uhci->frame_number + uhci->is_stopped != uhci->urb_remove_age) {
1381 uhci_remove_pending_urbps(uhci);
1382 uhci->urb_remove_age = uhci->frame_number;
1383 }
1384
1385 /* If we're the first, set the next interrupt bit */
1386 if (list_empty(&uhci->urb_remove_list))
1387 uhci_set_next_interrupt(uhci);
1388 list_add_tail(&urbp->urb_list, &uhci->urb_remove_list);
1389
1390done:
1391 spin_unlock_irqrestore(&uhci->lock, flags);
1392 return 0;
1393}
1394 1275
1395static int uhci_fsbr_timeout(struct uhci_hcd *uhci, struct urb *urb) 1276 switch (usb_pipetype(urb->pipe)) {
1396{ 1277 case PIPE_CONTROL:
1397 struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; 1278 status = uhci_result_control(uhci, urb);
1398 struct list_head *head; 1279 break;
1399 struct uhci_td *td; 1280 case PIPE_ISOCHRONOUS:
1400 int count = 0; 1281 status = uhci_result_isochronous(uhci, urb);
1401 1282 break;
1402 uhci_dec_fsbr(uhci, urb); 1283 default: /* PIPE_BULK or PIPE_INTERRUPT */
1284 status = uhci_result_common(uhci, urb);
1285 break;
1286 }
1287 if (status == -EINPROGRESS)
1288 break;
1403 1289
1404 urbp->fsbr_timeout = 1; 1290 spin_lock(&urb->lock);
1291 if (urb->status == -EINPROGRESS) /* Not dequeued */
1292 urb->status = status;
1293 else
1294 status = -ECONNRESET;
1295 spin_unlock(&urb->lock);
1405 1296
1406 /* 1297 /* Dequeued but completed URBs can't be given back unless
1407 * Ideally we would want to fix qh->element as well, but it's 1298 * the QH is stopped or has finished unlinking. */
1408 * read/write by the HC, so that can introduce a race. It's not 1299 if (status == -ECONNRESET &&
1409 * really worth the hassle 1300 !(qh->is_stopped || QH_FINISHED_UNLINKING(qh)))
1410 */ 1301 return;
1411 1302
1412 head = &urbp->td_list; 1303 uhci_giveback_urb(uhci, qh, urb, regs);
1413 list_for_each_entry(td, head, list) { 1304 if (qh->is_stopped)
1414 /* 1305 break;
1415 * Make sure we don't do the last one (since it'll have the
1416 * TERM bit set) as well as we skip every so many TDs to
1417 * make sure it doesn't hog the bandwidth
1418 */
1419 if (td->list.next != head && (count % DEPTH_INTERVAL) ==
1420 (DEPTH_INTERVAL - 1))
1421 td->link |= UHCI_PTR_DEPTH;
1422
1423 count++;
1424 } 1306 }
1425 1307
1426 return 0; 1308 /* If the QH is neither stopped nor finished unlinking (normal case),
1427} 1309 * our work here is done. */
1428 1310 restart:
1429static void uhci_free_pending_qhs(struct uhci_hcd *uhci) 1311 if (!(qh->is_stopped || QH_FINISHED_UNLINKING(qh)))
1430{ 1312 return;
1431 struct uhci_qh *qh, *tmp;
1432
1433 list_for_each_entry_safe(qh, tmp, &uhci->qh_remove_list, remove_list) {
1434 list_del_init(&qh->remove_list);
1435 1313
1436 uhci_free_qh(uhci, qh); 1314 /* Otherwise give back each of the dequeued URBs */
1315 list_for_each_entry(urbp, &qh->queue, node) {
1316 urb = urbp->urb;
1317 if (urb->status != -EINPROGRESS) {
1318 uhci_save_toggle(qh, urb);
1319 uhci_giveback_urb(uhci, qh, urb, regs);
1320 goto restart;
1321 }
1322 }
1323 qh->is_stopped = 0;
1324
1325 /* There are no more dequeued URBs. If there are still URBs on the
1326 * queue, the QH can now be re-activated. */
1327 if (!list_empty(&qh->queue)) {
1328 if (qh->needs_fixup)
1329 uhci_fixup_toggles(qh, 0);
1330 uhci_activate_qh(uhci, qh);
1437 } 1331 }
1332
1333 /* The queue is empty. The QH can become idle if it is fully
1334 * unlinked. */
1335 else if (QH_FINISHED_UNLINKING(qh))
1336 uhci_make_qh_idle(uhci, qh);
1438} 1337}
1439 1338
1440static void uhci_free_pending_tds(struct uhci_hcd *uhci) 1339static void uhci_free_pending_tds(struct uhci_hcd *uhci)
@@ -1448,43 +1347,13 @@ static void uhci_free_pending_tds(struct uhci_hcd *uhci)
1448 } 1347 }
1449} 1348}
1450 1349
1451static void 1350/*
1452uhci_finish_urb(struct usb_hcd *hcd, struct urb *urb, struct pt_regs *regs) 1351 * Process events in the schedule, but only in one thread at a time
1453__releases(uhci->lock) 1352 */
1454__acquires(uhci->lock)
1455{
1456 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
1457
1458 uhci_destroy_urb_priv(uhci, urb);
1459
1460 spin_unlock(&uhci->lock);
1461 usb_hcd_giveback_urb(hcd, urb, regs);
1462 spin_lock(&uhci->lock);
1463}
1464
1465static void uhci_finish_completion(struct uhci_hcd *uhci, struct pt_regs *regs)
1466{
1467 struct urb_priv *urbp, *tmp;
1468
1469 list_for_each_entry_safe(urbp, tmp, &uhci->complete_list, urb_list) {
1470 struct urb *urb = urbp->urb;
1471
1472 list_del_init(&urbp->urb_list);
1473 uhci_finish_urb(uhci_to_hcd(uhci), urb, regs);
1474 }
1475}
1476
1477static void uhci_remove_pending_urbps(struct uhci_hcd *uhci)
1478{
1479
1480 /* Splice the urb_remove_list onto the end of the complete_list */
1481 list_splice_init(&uhci->urb_remove_list, uhci->complete_list.prev);
1482}
1483
1484/* Process events in the schedule, but only in one thread at a time */
1485static void uhci_scan_schedule(struct uhci_hcd *uhci, struct pt_regs *regs) 1353static void uhci_scan_schedule(struct uhci_hcd *uhci, struct pt_regs *regs)
1486{ 1354{
1487 struct urb_priv *urbp, *tmp; 1355 int i;
1356 struct uhci_qh *qh;
1488 1357
1489 /* Don't allow re-entrant calls */ 1358 /* Don't allow re-entrant calls */
1490 if (uhci->scan_in_progress) { 1359 if (uhci->scan_in_progress) {
@@ -1498,60 +1367,39 @@ static void uhci_scan_schedule(struct uhci_hcd *uhci, struct pt_regs *regs)
1498 uhci_clear_next_interrupt(uhci); 1367 uhci_clear_next_interrupt(uhci);
1499 uhci_get_current_frame_number(uhci); 1368 uhci_get_current_frame_number(uhci);
1500 1369
1501 if (uhci->frame_number + uhci->is_stopped != uhci->qh_remove_age)
1502 uhci_free_pending_qhs(uhci);
1503 if (uhci->frame_number + uhci->is_stopped != uhci->td_remove_age) 1370 if (uhci->frame_number + uhci->is_stopped != uhci->td_remove_age)
1504 uhci_free_pending_tds(uhci); 1371 uhci_free_pending_tds(uhci);
1505 if (uhci->frame_number + uhci->is_stopped != uhci->urb_remove_age)
1506 uhci_remove_pending_urbps(uhci);
1507
1508 /* Walk the list of pending URBs to see which ones completed
1509 * (must be _safe because uhci_transfer_result() dequeues URBs) */
1510 list_for_each_entry_safe(urbp, tmp, &uhci->urb_list, urb_list) {
1511 struct urb *urb = urbp->urb;
1512 1372
1513 /* Checks the status and does all of the magic necessary */ 1373 /* Go through all the QH queues and process the URBs in each one */
1514 uhci_transfer_result(uhci, urb); 1374 for (i = 0; i < UHCI_NUM_SKELQH - 1; ++i) {
1515 } 1375 uhci->next_qh = list_entry(uhci->skelqh[i]->node.next,
1516 uhci_finish_completion(uhci, regs); 1376 struct uhci_qh, node);
1517 1377 while ((qh = uhci->next_qh) != uhci->skelqh[i]) {
1518 /* If the controller is stopped, we can finish these off right now */ 1378 uhci->next_qh = list_entry(qh->node.next,
1519 if (uhci->is_stopped) { 1379 struct uhci_qh, node);
1520 uhci_free_pending_qhs(uhci); 1380 uhci_scan_qh(uhci, qh, regs);
1521 uhci_free_pending_tds(uhci); 1381 }
1522 uhci_remove_pending_urbps(uhci);
1523 } 1382 }
1524 1383
1525 if (uhci->need_rescan) 1384 if (uhci->need_rescan)
1526 goto rescan; 1385 goto rescan;
1527 uhci->scan_in_progress = 0; 1386 uhci->scan_in_progress = 0;
1528 1387
1529 if (list_empty(&uhci->urb_remove_list) && 1388 /* If the controller is stopped, we can finish these off right now */
1530 list_empty(&uhci->td_remove_list) && 1389 if (uhci->is_stopped)
1531 list_empty(&uhci->qh_remove_list)) 1390 uhci_free_pending_tds(uhci);
1391
1392 if (list_empty(&uhci->td_remove_list) &&
1393 list_empty(&uhci->skel_unlink_qh->node))
1532 uhci_clear_next_interrupt(uhci); 1394 uhci_clear_next_interrupt(uhci);
1533 else 1395 else
1534 uhci_set_next_interrupt(uhci); 1396 uhci_set_next_interrupt(uhci);
1535
1536 /* Wake up anyone waiting for an URB to complete */
1537 wake_up_all(&uhci->waitqh);
1538} 1397}
1539 1398
1540static void check_fsbr(struct uhci_hcd *uhci) 1399static void check_fsbr(struct uhci_hcd *uhci)
1541{ 1400{
1542 struct urb_priv *up; 1401 /* For now, don't scan URBs for FSBR timeouts.
1543 1402 * Add it back in later... */
1544 list_for_each_entry(up, &uhci->urb_list, urb_list) {
1545 struct urb *u = up->urb;
1546
1547 spin_lock(&u->lock);
1548
1549 /* Check if the FSBR timed out */
1550 if (up->fsbr && !up->fsbr_timeout && time_after_eq(jiffies, up->fsbrtime + IDLE_TIMEOUT))
1551 uhci_fsbr_timeout(uhci, u);
1552
1553 spin_unlock(&u->lock);
1554 }
1555 1403
1556 /* Really disable FSBR */ 1404 /* Really disable FSBR */
1557 if (!uhci->fsbr && uhci->fsbrtimeout && time_after_eq(jiffies, uhci->fsbrtimeout)) { 1405 if (!uhci->fsbr && uhci->fsbrtimeout && time_after_eq(jiffies, uhci->fsbrtimeout)) {
diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c
index 049871145d63..08daf400f985 100644
--- a/drivers/usb/image/mdc800.c
+++ b/drivers/usb/image/mdc800.c
@@ -96,6 +96,7 @@
96#include <linux/module.h> 96#include <linux/module.h>
97#include <linux/smp_lock.h> 97#include <linux/smp_lock.h>
98#include <linux/wait.h> 98#include <linux/wait.h>
99#include <linux/mutex.h>
99 100
100#include <linux/usb.h> 101#include <linux/usb.h>
101#include <linux/fs.h> 102#include <linux/fs.h>
@@ -169,7 +170,7 @@ struct mdc800_data
169 int out_count; // Bytes in the buffer 170 int out_count; // Bytes in the buffer
170 171
171 int open; // Camera device open ? 172 int open; // Camera device open ?
172 struct semaphore io_lock; // IO -lock 173 struct mutex io_lock; // IO -lock
173 174
174 char in [8]; // Command Input Buffer 175 char in [8]; // Command Input Buffer
175 int in_count; 176 int in_count;
@@ -497,7 +498,7 @@ static int mdc800_usb_probe (struct usb_interface *intf,
497 498
498 info ("Found Mustek MDC800 on USB."); 499 info ("Found Mustek MDC800 on USB.");
499 500
500 down (&mdc800->io_lock); 501 mutex_lock(&mdc800->io_lock);
501 502
502 retval = usb_register_dev(intf, &mdc800_class); 503 retval = usb_register_dev(intf, &mdc800_class);
503 if (retval) { 504 if (retval) {
@@ -542,7 +543,7 @@ static int mdc800_usb_probe (struct usb_interface *intf,
542 543
543 mdc800->state=READY; 544 mdc800->state=READY;
544 545
545 up (&mdc800->io_lock); 546 mutex_unlock(&mdc800->io_lock);
546 547
547 usb_set_intfdata(intf, mdc800); 548 usb_set_intfdata(intf, mdc800);
548 return 0; 549 return 0;
@@ -620,7 +621,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file)
620 int retval=0; 621 int retval=0;
621 int errn=0; 622 int errn=0;
622 623
623 down (&mdc800->io_lock); 624 mutex_lock(&mdc800->io_lock);
624 625
625 if (mdc800->state == NOT_CONNECTED) 626 if (mdc800->state == NOT_CONNECTED)
626 { 627 {
@@ -656,7 +657,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file)
656 dbg ("Mustek MDC800 device opened."); 657 dbg ("Mustek MDC800 device opened.");
657 658
658error_out: 659error_out:
659 up (&mdc800->io_lock); 660 mutex_unlock(&mdc800->io_lock);
660 return errn; 661 return errn;
661} 662}
662 663
@@ -669,7 +670,7 @@ static int mdc800_device_release (struct inode* inode, struct file *file)
669 int retval=0; 670 int retval=0;
670 dbg ("Mustek MDC800 device closed."); 671 dbg ("Mustek MDC800 device closed.");
671 672
672 down (&mdc800->io_lock); 673 mutex_lock(&mdc800->io_lock);
673 if (mdc800->open && (mdc800->state != NOT_CONNECTED)) 674 if (mdc800->open && (mdc800->state != NOT_CONNECTED))
674 { 675 {
675 usb_kill_urb(mdc800->irq_urb); 676 usb_kill_urb(mdc800->irq_urb);
@@ -682,7 +683,7 @@ static int mdc800_device_release (struct inode* inode, struct file *file)
682 retval=-EIO; 683 retval=-EIO;
683 } 684 }
684 685
685 up(&mdc800->io_lock); 686 mutex_unlock(&mdc800->io_lock);
686 return retval; 687 return retval;
687} 688}
688 689
@@ -695,21 +696,21 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
695 size_t left=len, sts=len; /* single transfer size */ 696 size_t left=len, sts=len; /* single transfer size */
696 char __user *ptr = buf; 697 char __user *ptr = buf;
697 698
698 down (&mdc800->io_lock); 699 mutex_lock(&mdc800->io_lock);
699 if (mdc800->state == NOT_CONNECTED) 700 if (mdc800->state == NOT_CONNECTED)
700 { 701 {
701 up (&mdc800->io_lock); 702 mutex_unlock(&mdc800->io_lock);
702 return -EBUSY; 703 return -EBUSY;
703 } 704 }
704 if (mdc800->state == WORKING) 705 if (mdc800->state == WORKING)
705 { 706 {
706 warn ("Illegal State \"working\" reached during read ?!"); 707 warn ("Illegal State \"working\" reached during read ?!");
707 up (&mdc800->io_lock); 708 mutex_unlock(&mdc800->io_lock);
708 return -EBUSY; 709 return -EBUSY;
709 } 710 }
710 if (!mdc800->open) 711 if (!mdc800->open)
711 { 712 {
712 up (&mdc800->io_lock); 713 mutex_unlock(&mdc800->io_lock);
713 return -EBUSY; 714 return -EBUSY;
714 } 715 }
715 716
@@ -717,7 +718,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
717 { 718 {
718 if (signal_pending (current)) 719 if (signal_pending (current))
719 { 720 {
720 up (&mdc800->io_lock); 721 mutex_unlock(&mdc800->io_lock);
721 return -EINTR; 722 return -EINTR;
722 } 723 }
723 724
@@ -736,7 +737,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
736 if (usb_submit_urb (mdc800->download_urb, GFP_KERNEL)) 737 if (usb_submit_urb (mdc800->download_urb, GFP_KERNEL))
737 { 738 {
738 err ("Can't submit download urb (status=%i)",mdc800->download_urb->status); 739 err ("Can't submit download urb (status=%i)",mdc800->download_urb->status);
739 up (&mdc800->io_lock); 740 mutex_unlock(&mdc800->io_lock);
740 return len-left; 741 return len-left;
741 } 742 }
742 wait_event_timeout(mdc800->download_wait, mdc800->downloaded, 743 wait_event_timeout(mdc800->download_wait, mdc800->downloaded,
@@ -745,14 +746,14 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
745 if (mdc800->download_urb->status != 0) 746 if (mdc800->download_urb->status != 0)
746 { 747 {
747 err ("request download-bytes fails (status=%i)",mdc800->download_urb->status); 748 err ("request download-bytes fails (status=%i)",mdc800->download_urb->status);
748 up (&mdc800->io_lock); 749 mutex_unlock(&mdc800->io_lock);
749 return len-left; 750 return len-left;
750 } 751 }
751 } 752 }
752 else 753 else
753 { 754 {
754 /* No more bytes -> that's an error*/ 755 /* No more bytes -> that's an error*/
755 up (&mdc800->io_lock); 756 mutex_unlock(&mdc800->io_lock);
756 return -EIO; 757 return -EIO;
757 } 758 }
758 } 759 }
@@ -761,7 +762,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
761 /* Copy Bytes */ 762 /* Copy Bytes */
762 if (copy_to_user(ptr, &mdc800->out [mdc800->out_ptr], 763 if (copy_to_user(ptr, &mdc800->out [mdc800->out_ptr],
763 sts)) { 764 sts)) {
764 up(&mdc800->io_lock); 765 mutex_unlock(&mdc800->io_lock);
765 return -EFAULT; 766 return -EFAULT;
766 } 767 }
767 ptr+=sts; 768 ptr+=sts;
@@ -770,7 +771,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
770 } 771 }
771 } 772 }
772 773
773 up (&mdc800->io_lock); 774 mutex_unlock(&mdc800->io_lock);
774 return len-left; 775 return len-left;
775} 776}
776 777
@@ -785,15 +786,15 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
785{ 786{
786 size_t i=0; 787 size_t i=0;
787 788
788 down (&mdc800->io_lock); 789 mutex_lock(&mdc800->io_lock);
789 if (mdc800->state != READY) 790 if (mdc800->state != READY)
790 { 791 {
791 up (&mdc800->io_lock); 792 mutex_unlock(&mdc800->io_lock);
792 return -EBUSY; 793 return -EBUSY;
793 } 794 }
794 if (!mdc800->open ) 795 if (!mdc800->open )
795 { 796 {
796 up (&mdc800->io_lock); 797 mutex_unlock(&mdc800->io_lock);
797 return -EBUSY; 798 return -EBUSY;
798 } 799 }
799 800
@@ -802,13 +803,13 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
802 unsigned char c; 803 unsigned char c;
803 if (signal_pending (current)) 804 if (signal_pending (current))
804 { 805 {
805 up (&mdc800->io_lock); 806 mutex_unlock(&mdc800->io_lock);
806 return -EINTR; 807 return -EINTR;
807 } 808 }
808 809
809 if(get_user(c, buf+i)) 810 if(get_user(c, buf+i))
810 { 811 {
811 up(&mdc800->io_lock); 812 mutex_unlock(&mdc800->io_lock);
812 return -EFAULT; 813 return -EFAULT;
813 } 814 }
814 815
@@ -829,7 +830,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
829 } 830 }
830 else 831 else
831 { 832 {
832 up (&mdc800->io_lock); 833 mutex_unlock(&mdc800->io_lock);
833 return -EIO; 834 return -EIO;
834 } 835 }
835 836
@@ -841,7 +842,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
841 if (mdc800_usb_waitForIRQ (0,TO_GET_READY)) 842 if (mdc800_usb_waitForIRQ (0,TO_GET_READY))
842 { 843 {
843 err ("Camera didn't get ready.\n"); 844 err ("Camera didn't get ready.\n");
844 up (&mdc800->io_lock); 845 mutex_unlock(&mdc800->io_lock);
845 return -EIO; 846 return -EIO;
846 } 847 }
847 848
@@ -853,7 +854,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
853 if (usb_submit_urb (mdc800->write_urb, GFP_KERNEL)) 854 if (usb_submit_urb (mdc800->write_urb, GFP_KERNEL))
854 { 855 {
855 err ("submitting write urb fails (status=%i)", mdc800->write_urb->status); 856 err ("submitting write urb fails (status=%i)", mdc800->write_urb->status);
856 up (&mdc800->io_lock); 857 mutex_unlock(&mdc800->io_lock);
857 return -EIO; 858 return -EIO;
858 } 859 }
859 wait_event_timeout(mdc800->write_wait, mdc800->written, TO_WRITE_GET_READY*HZ/1000); 860 wait_event_timeout(mdc800->write_wait, mdc800->written, TO_WRITE_GET_READY*HZ/1000);
@@ -861,7 +862,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
861 if (mdc800->state == WORKING) 862 if (mdc800->state == WORKING)
862 { 863 {
863 usb_kill_urb(mdc800->write_urb); 864 usb_kill_urb(mdc800->write_urb);
864 up (&mdc800->io_lock); 865 mutex_unlock(&mdc800->io_lock);
865 return -EIO; 866 return -EIO;
866 } 867 }
867 868
@@ -873,7 +874,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
873 { 874 {
874 err ("call 0x07 before 0x05,0x3e"); 875 err ("call 0x07 before 0x05,0x3e");
875 mdc800->state=READY; 876 mdc800->state=READY;
876 up (&mdc800->io_lock); 877 mutex_unlock(&mdc800->io_lock);
877 return -EIO; 878 return -EIO;
878 } 879 }
879 mdc800->pic_len=-1; 880 mdc800->pic_len=-1;
@@ -892,7 +893,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
892 if (mdc800_usb_waitForIRQ (1,TO_READ_FROM_IRQ)) 893 if (mdc800_usb_waitForIRQ (1,TO_READ_FROM_IRQ))
893 { 894 {
894 err ("requesting answer from irq fails"); 895 err ("requesting answer from irq fails");
895 up (&mdc800->io_lock); 896 mutex_unlock(&mdc800->io_lock);
896 return -EIO; 897 return -EIO;
897 } 898 }
898 899
@@ -920,7 +921,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
920 if (mdc800_usb_waitForIRQ (0,TO_DEFAULT_COMMAND)) 921 if (mdc800_usb_waitForIRQ (0,TO_DEFAULT_COMMAND))
921 { 922 {
922 err ("Command Timeout."); 923 err ("Command Timeout.");
923 up (&mdc800->io_lock); 924 mutex_unlock(&mdc800->io_lock);
924 return -EIO; 925 return -EIO;
925 } 926 }
926 } 927 }
@@ -930,7 +931,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
930 } 931 }
931 i++; 932 i++;
932 } 933 }
933 up (&mdc800->io_lock); 934 mutex_unlock(&mdc800->io_lock);
934 return i; 935 return i;
935} 936}
936 937
@@ -978,15 +979,13 @@ static int __init usb_mdc800_init (void)
978{ 979{
979 int retval = -ENODEV; 980 int retval = -ENODEV;
980 /* Allocate Memory */ 981 /* Allocate Memory */
981 mdc800=kmalloc (sizeof (struct mdc800_data), GFP_KERNEL); 982 mdc800=kzalloc (sizeof (struct mdc800_data), GFP_KERNEL);
982 if (!mdc800) 983 if (!mdc800)
983 goto cleanup_on_fail; 984 goto cleanup_on_fail;
984 985
985 memset(mdc800, 0, sizeof(struct mdc800_data));
986 mdc800->dev = NULL; 986 mdc800->dev = NULL;
987 mdc800->open=0;
988 mdc800->state=NOT_CONNECTED; 987 mdc800->state=NOT_CONNECTED;
989 init_MUTEX (&mdc800->io_lock); 988 mutex_init (&mdc800->io_lock);
990 989
991 init_waitqueue_head (&mdc800->irq_wait); 990 init_waitqueue_head (&mdc800->irq_wait);
992 init_waitqueue_head (&mdc800->write_wait); 991 init_waitqueue_head (&mdc800->write_wait);
diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c
index f7bdc506e613..99f986cb6e95 100644
--- a/drivers/usb/input/ati_remote.c
+++ b/drivers/usb/input/ati_remote.c
@@ -159,8 +159,6 @@ static const char accel[] = { 1, 2, 4, 6, 9, 13, 20 };
159 */ 159 */
160#define FILTER_TIME (HZ / 20) 160#define FILTER_TIME (HZ / 20)
161 161
162static DECLARE_MUTEX(disconnect_sem);
163
164struct ati_remote { 162struct ati_remote {
165 struct input_dev *idev; 163 struct input_dev *idev;
166 struct usb_device *udev; 164 struct usb_device *udev;
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 07a012f88772..58b59f6e9881 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -66,9 +66,8 @@ static struct hid_report *hid_register_report(struct hid_device *device, unsigne
66 if (report_enum->report_id_hash[id]) 66 if (report_enum->report_id_hash[id])
67 return report_enum->report_id_hash[id]; 67 return report_enum->report_id_hash[id];
68 68
69 if (!(report = kmalloc(sizeof(struct hid_report), GFP_KERNEL))) 69 if (!(report = kzalloc(sizeof(struct hid_report), GFP_KERNEL)))
70 return NULL; 70 return NULL;
71 memset(report, 0, sizeof(struct hid_report));
72 71
73 if (id != 0) 72 if (id != 0)
74 report_enum->numbered = 1; 73 report_enum->numbered = 1;
@@ -97,12 +96,9 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
97 return NULL; 96 return NULL;
98 } 97 }
99 98
100 if (!(field = kmalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage) 99 if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
101 + values * sizeof(unsigned), GFP_KERNEL))) return NULL; 100 + values * sizeof(unsigned), GFP_KERNEL))) return NULL;
102 101
103 memset(field, 0, sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
104 + values * sizeof(unsigned));
105
106 field->index = report->maxfield++; 102 field->index = report->maxfield++;
107 report->field[field->index] = field; 103 report->field[field->index] = field;
108 field->usage = (struct hid_usage *)(field + 1); 104 field->usage = (struct hid_usage *)(field + 1);
@@ -651,17 +647,14 @@ static struct hid_device *hid_parse_report(__u8 *start, unsigned size)
651 hid_parser_reserved 647 hid_parser_reserved
652 }; 648 };
653 649
654 if (!(device = kmalloc(sizeof(struct hid_device), GFP_KERNEL))) 650 if (!(device = kzalloc(sizeof(struct hid_device), GFP_KERNEL)))
655 return NULL; 651 return NULL;
656 memset(device, 0, sizeof(struct hid_device));
657 652
658 if (!(device->collection = kmalloc(sizeof(struct hid_collection) * 653 if (!(device->collection = kzalloc(sizeof(struct hid_collection) *
659 HID_DEFAULT_NUM_COLLECTIONS, GFP_KERNEL))) { 654 HID_DEFAULT_NUM_COLLECTIONS, GFP_KERNEL))) {
660 kfree(device); 655 kfree(device);
661 return NULL; 656 return NULL;
662 } 657 }
663 memset(device->collection, 0, sizeof(struct hid_collection) *
664 HID_DEFAULT_NUM_COLLECTIONS);
665 device->collection_size = HID_DEFAULT_NUM_COLLECTIONS; 658 device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
666 659
667 for (i = 0; i < HID_REPORT_TYPES; i++) 660 for (i = 0; i < HID_REPORT_TYPES; i++)
@@ -675,13 +668,12 @@ static struct hid_device *hid_parse_report(__u8 *start, unsigned size)
675 memcpy(device->rdesc, start, size); 668 memcpy(device->rdesc, start, size);
676 device->rsize = size; 669 device->rsize = size;
677 670
678 if (!(parser = kmalloc(sizeof(struct hid_parser), GFP_KERNEL))) { 671 if (!(parser = kzalloc(sizeof(struct hid_parser), GFP_KERNEL))) {
679 kfree(device->rdesc); 672 kfree(device->rdesc);
680 kfree(device->collection); 673 kfree(device->collection);
681 kfree(device); 674 kfree(device);
682 return NULL; 675 return NULL;
683 } 676 }
684 memset(parser, 0, sizeof(struct hid_parser));
685 parser->device = device; 677 parser->device = device;
686 678
687 end = start + size; 679 end = start + size;
@@ -911,6 +903,99 @@ static int hid_input_report(int type, struct urb *urb, int interrupt, struct pt_
911} 903}
912 904
913/* 905/*
906 * Input submission and I/O error handler.
907 */
908
909static void hid_io_error(struct hid_device *hid);
910
911/* Start up the input URB */
912static int hid_start_in(struct hid_device *hid)
913{
914 unsigned long flags;
915 int rc = 0;
916
917 spin_lock_irqsave(&hid->inlock, flags);
918 if (hid->open > 0 && !test_bit(HID_SUSPENDED, &hid->iofl) &&
919 !test_and_set_bit(HID_IN_RUNNING, &hid->iofl)) {
920 rc = usb_submit_urb(hid->urbin, GFP_ATOMIC);
921 if (rc != 0)
922 clear_bit(HID_IN_RUNNING, &hid->iofl);
923 }
924 spin_unlock_irqrestore(&hid->inlock, flags);
925 return rc;
926}
927
928/* I/O retry timer routine */
929static void hid_retry_timeout(unsigned long _hid)
930{
931 struct hid_device *hid = (struct hid_device *) _hid;
932
933 dev_dbg(&hid->intf->dev, "retrying intr urb\n");
934 if (hid_start_in(hid))
935 hid_io_error(hid);
936}
937
938/* Workqueue routine to reset the device */
939static void hid_reset(void *_hid)
940{
941 struct hid_device *hid = (struct hid_device *) _hid;
942 int rc_lock, rc;
943
944 dev_dbg(&hid->intf->dev, "resetting device\n");
945 rc = rc_lock = usb_lock_device_for_reset(hid->dev, hid->intf);
946 if (rc_lock >= 0) {
947 rc = usb_reset_device(hid->dev);
948 if (rc_lock)
949 usb_unlock_device(hid->dev);
950 }
951 clear_bit(HID_RESET_PENDING, &hid->iofl);
952
953 if (rc == 0) {
954 hid->retry_delay = 0;
955 if (hid_start_in(hid))
956 hid_io_error(hid);
957 } else if (!(rc == -ENODEV || rc == -EHOSTUNREACH || rc == -EINTR))
958 err("can't reset device, %s-%s/input%d, status %d",
959 hid->dev->bus->bus_name,
960 hid->dev->devpath,
961 hid->ifnum, rc);
962}
963
964/* Main I/O error handler */
965static void hid_io_error(struct hid_device *hid)
966{
967 unsigned long flags;
968
969 spin_lock_irqsave(&hid->inlock, flags);
970
971 /* Stop when disconnected */
972 if (usb_get_intfdata(hid->intf) == NULL)
973 goto done;
974
975 /* When an error occurs, retry at increasing intervals */
976 if (hid->retry_delay == 0) {
977 hid->retry_delay = 13; /* Then 26, 52, 104, 104, ... */
978 hid->stop_retry = jiffies + msecs_to_jiffies(1000);
979 } else if (hid->retry_delay < 100)
980 hid->retry_delay *= 2;
981
982 if (time_after(jiffies, hid->stop_retry)) {
983
984 /* Retries failed, so do a port reset */
985 if (!test_and_set_bit(HID_RESET_PENDING, &hid->iofl)) {
986 if (schedule_work(&hid->reset_work))
987 goto done;
988 clear_bit(HID_RESET_PENDING, &hid->iofl);
989 }
990 }
991
992 mod_timer(&hid->io_retry,
993 jiffies + msecs_to_jiffies(hid->retry_delay));
994done:
995 spin_unlock_irqrestore(&hid->inlock, flags);
996}
997
998/*
914 * Input interrupt completion handler. 999 * Input interrupt completion handler.
915 */ 1000 */
916 1001
@@ -921,25 +1006,35 @@ static void hid_irq_in(struct urb *urb, struct pt_regs *regs)
921 1006
922 switch (urb->status) { 1007 switch (urb->status) {
923 case 0: /* success */ 1008 case 0: /* success */
1009 hid->retry_delay = 0;
924 hid_input_report(HID_INPUT_REPORT, urb, 1, regs); 1010 hid_input_report(HID_INPUT_REPORT, urb, 1, regs);
925 break; 1011 break;
926 case -ECONNRESET: /* unlink */ 1012 case -ECONNRESET: /* unlink */
927 case -ENOENT: 1013 case -ENOENT:
928 case -EPERM:
929 case -ESHUTDOWN: /* unplug */ 1014 case -ESHUTDOWN: /* unplug */
930 case -EILSEQ: /* unplug timeout on uhci */ 1015 clear_bit(HID_IN_RUNNING, &hid->iofl);
931 return; 1016 return;
1017 case -EILSEQ: /* protocol error or unplug */
1018 case -EPROTO: /* protocol error or unplug */
932 case -ETIMEDOUT: /* NAK */ 1019 case -ETIMEDOUT: /* NAK */
933 break; 1020 clear_bit(HID_IN_RUNNING, &hid->iofl);
1021 hid_io_error(hid);
1022 return;
934 default: /* error */ 1023 default: /* error */
935 warn("input irq status %d received", urb->status); 1024 warn("input irq status %d received", urb->status);
936 } 1025 }
937 1026
938 status = usb_submit_urb(urb, SLAB_ATOMIC); 1027 status = usb_submit_urb(urb, SLAB_ATOMIC);
939 if (status) 1028 if (status) {
940 err("can't resubmit intr, %s-%s/input%d, status %d", 1029 clear_bit(HID_IN_RUNNING, &hid->iofl);
941 hid->dev->bus->bus_name, hid->dev->devpath, 1030 if (status != -EPERM) {
942 hid->ifnum, status); 1031 err("can't resubmit intr, %s-%s/input%d, status %d",
1032 hid->dev->bus->bus_name,
1033 hid->dev->devpath,
1034 hid->ifnum, status);
1035 hid_io_error(hid);
1036 }
1037 }
943} 1038}
944 1039
945/* 1040/*
@@ -1101,8 +1196,9 @@ static void hid_irq_out(struct urb *urb, struct pt_regs *regs)
1101 case 0: /* success */ 1196 case 0: /* success */
1102 break; 1197 break;
1103 case -ESHUTDOWN: /* unplug */ 1198 case -ESHUTDOWN: /* unplug */
1104 case -EILSEQ: /* unplug timeout on uhci */
1105 unplug = 1; 1199 unplug = 1;
1200 case -EILSEQ: /* protocol error or unplug */
1201 case -EPROTO: /* protocol error or unplug */
1106 case -ECONNRESET: /* unlink */ 1202 case -ECONNRESET: /* unlink */
1107 case -ENOENT: 1203 case -ENOENT:
1108 break; 1204 break;
@@ -1149,8 +1245,9 @@ static void hid_ctrl(struct urb *urb, struct pt_regs *regs)
1149 hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0, regs); 1245 hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0, regs);
1150 break; 1246 break;
1151 case -ESHUTDOWN: /* unplug */ 1247 case -ESHUTDOWN: /* unplug */
1152 case -EILSEQ: /* unplug timectrl on uhci */
1153 unplug = 1; 1248 unplug = 1;
1249 case -EILSEQ: /* protocol error or unplug */
1250 case -EPROTO: /* protocol error or unplug */
1154 case -ECONNRESET: /* unlink */ 1251 case -ECONNRESET: /* unlink */
1155 case -ENOENT: 1252 case -ENOENT:
1156 case -EPIPE: /* report not available */ 1253 case -EPIPE: /* report not available */
@@ -1263,14 +1360,9 @@ static int hid_get_class_descriptor(struct usb_device *dev, int ifnum,
1263 1360
1264int hid_open(struct hid_device *hid) 1361int hid_open(struct hid_device *hid)
1265{ 1362{
1266 if (hid->open++) 1363 ++hid->open;
1267 return 0; 1364 if (hid_start_in(hid))
1268 1365 hid_io_error(hid);
1269 hid->urbin->dev = hid->dev;
1270
1271 if (usb_submit_urb(hid->urbin, GFP_KERNEL))
1272 return -EIO;
1273
1274 return 0; 1366 return 0;
1275} 1367}
1276 1368
@@ -1460,6 +1552,9 @@ void hid_init_reports(struct hid_device *hid)
1460#define USB_VENDOR_ID_HP 0x03f0 1552#define USB_VENDOR_ID_HP 0x03f0
1461#define USB_DEVICE_ID_HP_USBHUB_KB 0x020c 1553#define USB_DEVICE_ID_HP_USBHUB_KB 0x020c
1462 1554
1555#define USB_VENDOR_ID_CREATIVELABS 0x062a
1556#define USB_DEVICE_ID_CREATIVELABS_SILVERCREST 0x0201
1557
1463/* 1558/*
1464 * Alphabetically sorted blacklist by quirk type. 1559 * Alphabetically sorted blacklist by quirk type.
1465 */ 1560 */
@@ -1576,6 +1671,7 @@ static const struct hid_blacklist {
1576 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, 1671 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET },
1577 { USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_KEYBOARD, HID_QUIRK_NOGET}, 1672 { USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_KEYBOARD, HID_QUIRK_NOGET},
1578 { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_USBHUB_KB, HID_QUIRK_NOGET}, 1673 { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_USBHUB_KB, HID_QUIRK_NOGET},
1674 { USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_CREATIVELABS_SILVERCREST, HID_QUIRK_NOGET },
1579 { USB_VENDOR_ID_HP, USB_DEVICE_ID_HP_USBHUB_KB, HID_QUIRK_NOGET }, 1675 { USB_VENDOR_ID_HP, USB_DEVICE_ID_HP_USBHUB_KB, HID_QUIRK_NOGET },
1580 { USB_VENDOR_ID_TANGTOP, USB_DEVICE_ID_TANGTOP_USBPS2, HID_QUIRK_NOGET }, 1676 { USB_VENDOR_ID_TANGTOP, USB_DEVICE_ID_TANGTOP_USBPS2, HID_QUIRK_NOGET },
1581 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 1677 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
@@ -1795,6 +1891,10 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1795 1891
1796 init_waitqueue_head(&hid->wait); 1892 init_waitqueue_head(&hid->wait);
1797 1893
1894 INIT_WORK(&hid->reset_work, hid_reset, hid);
1895 setup_timer(&hid->io_retry, hid_retry_timeout, (unsigned long) hid);
1896
1897 spin_lock_init(&hid->inlock);
1798 spin_lock_init(&hid->outlock); 1898 spin_lock_init(&hid->outlock);
1799 spin_lock_init(&hid->ctrllock); 1899 spin_lock_init(&hid->ctrllock);
1800 1900
@@ -1863,11 +1963,16 @@ static void hid_disconnect(struct usb_interface *intf)
1863 if (!hid) 1963 if (!hid)
1864 return; 1964 return;
1865 1965
1966 spin_lock_irq(&hid->inlock); /* Sync with error handler */
1866 usb_set_intfdata(intf, NULL); 1967 usb_set_intfdata(intf, NULL);
1968 spin_unlock_irq(&hid->inlock);
1867 usb_kill_urb(hid->urbin); 1969 usb_kill_urb(hid->urbin);
1868 usb_kill_urb(hid->urbout); 1970 usb_kill_urb(hid->urbout);
1869 usb_kill_urb(hid->urbctrl); 1971 usb_kill_urb(hid->urbctrl);
1870 1972
1973 del_timer_sync(&hid->io_retry);
1974 flush_scheduled_work();
1975
1871 if (hid->claimed & HID_CLAIMED_INPUT) 1976 if (hid->claimed & HID_CLAIMED_INPUT)
1872 hidinput_disconnect(hid); 1977 hidinput_disconnect(hid);
1873 if (hid->claimed & HID_CLAIMED_HIDDEV) 1978 if (hid->claimed & HID_CLAIMED_HIDDEV)
@@ -1942,6 +2047,10 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1942{ 2047{
1943 struct hid_device *hid = usb_get_intfdata (intf); 2048 struct hid_device *hid = usb_get_intfdata (intf);
1944 2049
2050 spin_lock_irq(&hid->inlock); /* Sync with error handler */
2051 set_bit(HID_SUSPENDED, &hid->iofl);
2052 spin_unlock_irq(&hid->inlock);
2053 del_timer(&hid->io_retry);
1945 usb_kill_urb(hid->urbin); 2054 usb_kill_urb(hid->urbin);
1946 dev_dbg(&intf->dev, "suspend\n"); 2055 dev_dbg(&intf->dev, "suspend\n");
1947 return 0; 2056 return 0;
@@ -1952,10 +2061,8 @@ static int hid_resume(struct usb_interface *intf)
1952 struct hid_device *hid = usb_get_intfdata (intf); 2061 struct hid_device *hid = usb_get_intfdata (intf);
1953 int status; 2062 int status;
1954 2063
1955 if (hid->open) 2064 clear_bit(HID_SUSPENDED, &hid->iofl);
1956 status = usb_submit_urb(hid->urbin, GFP_NOIO); 2065 status = hid_start_in(hid);
1957 else
1958 status = 0;
1959 dev_dbg(&intf->dev, "resume status %d\n", status); 2066 dev_dbg(&intf->dev, "resume status %d\n", status);
1960 return status; 2067 return status;
1961} 2068}
diff --git a/drivers/usb/input/hid-lgff.c b/drivers/usb/input/hid-lgff.c
index f82c9c9e5d51..f07d44357ff1 100644
--- a/drivers/usb/input/hid-lgff.c
+++ b/drivers/usb/input/hid-lgff.c
@@ -154,10 +154,9 @@ int hid_lgff_init(struct hid_device* hid)
154 return -1; 154 return -1;
155 } 155 }
156 156
157 private = kmalloc(sizeof(struct lgff_device), GFP_KERNEL); 157 private = kzalloc(sizeof(struct lgff_device), GFP_KERNEL);
158 if (!private) 158 if (!private)
159 return -1; 159 return -1;
160 memset(private, 0, sizeof(struct lgff_device));
161 hid->ff_private = private; 160 hid->ff_private = private;
162 161
163 /* Input init */ 162 /* Input init */
@@ -228,13 +227,12 @@ static struct hid_report* hid_lgff_duplicate_report(struct hid_report* report)
228 } 227 }
229 *ret->field[0] = *report->field[0]; 228 *ret->field[0] = *report->field[0];
230 229
231 ret->field[0]->value = kmalloc(sizeof(s32[8]), GFP_KERNEL); 230 ret->field[0]->value = kzalloc(sizeof(s32[8]), GFP_KERNEL);
232 if (!ret->field[0]->value) { 231 if (!ret->field[0]->value) {
233 kfree(ret->field[0]); 232 kfree(ret->field[0]);
234 kfree(ret); 233 kfree(ret);
235 return NULL; 234 return NULL;
236 } 235 }
237 memset(ret->field[0]->value, 0, sizeof(s32[8]));
238 236
239 return ret; 237 return ret;
240} 238}
diff --git a/drivers/usb/input/hid-tmff.c b/drivers/usb/input/hid-tmff.c
index 023fd5ac31c8..534425c69c0a 100644
--- a/drivers/usb/input/hid-tmff.c
+++ b/drivers/usb/input/hid-tmff.c
@@ -113,11 +113,10 @@ int hid_tmff_init(struct hid_device *hid)
113 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); 113 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
114 struct input_dev *input_dev = hidinput->input; 114 struct input_dev *input_dev = hidinput->input;
115 115
116 private = kmalloc(sizeof(struct tmff_device), GFP_KERNEL); 116 private = kzalloc(sizeof(struct tmff_device), GFP_KERNEL);
117 if (!private) 117 if (!private)
118 return -ENOMEM; 118 return -ENOMEM;
119 119
120 memset(private, 0, sizeof(struct tmff_device));
121 hid->ff_private = private; 120 hid->ff_private = private;
122 121
123 /* Find the report to use */ 122 /* Find the report to use */
diff --git a/drivers/usb/input/hid.h b/drivers/usb/input/hid.h
index 8b0d4346ce9c..4e1b784fe527 100644
--- a/drivers/usb/input/hid.h
+++ b/drivers/usb/input/hid.h
@@ -31,6 +31,8 @@
31#include <linux/types.h> 31#include <linux/types.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/list.h> 33#include <linux/list.h>
34#include <linux/timer.h>
35#include <linux/workqueue.h>
34 36
35/* 37/*
36 * USB HID (Human Interface Device) interface class code 38 * USB HID (Human Interface Device) interface class code
@@ -370,6 +372,9 @@ struct hid_control_fifo {
370 372
371#define HID_CTRL_RUNNING 1 373#define HID_CTRL_RUNNING 1
372#define HID_OUT_RUNNING 2 374#define HID_OUT_RUNNING 2
375#define HID_IN_RUNNING 3
376#define HID_RESET_PENDING 4
377#define HID_SUSPENDED 5
373 378
374struct hid_input { 379struct hid_input {
375 struct list_head list; 380 struct list_head list;
@@ -393,12 +398,17 @@ struct hid_device { /* device report descriptor */
393 int ifnum; /* USB interface number */ 398 int ifnum; /* USB interface number */
394 399
395 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */ 400 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
401 struct timer_list io_retry; /* Retry timer */
402 unsigned long stop_retry; /* Time to give up, in jiffies */
403 unsigned int retry_delay; /* Delay length in ms */
404 struct work_struct reset_work; /* Task context for resets */
396 405
397 unsigned int bufsize; /* URB buffer size */ 406 unsigned int bufsize; /* URB buffer size */
398 407
399 struct urb *urbin; /* Input URB */ 408 struct urb *urbin; /* Input URB */
400 char *inbuf; /* Input buffer */ 409 char *inbuf; /* Input buffer */
401 dma_addr_t inbuf_dma; /* Input buffer dma */ 410 dma_addr_t inbuf_dma; /* Input buffer dma */
411 spinlock_t inlock; /* Input fifo spinlock */
402 412
403 struct urb *urbctrl; /* Control URB */ 413 struct urb *urbctrl; /* Control URB */
404 struct usb_ctrlrequest *cr; /* Control request struct */ 414 struct usb_ctrlrequest *cr; /* Control request struct */
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
index 925f5aba06f5..6dd666696178 100644
--- a/drivers/usb/input/hiddev.c
+++ b/drivers/usb/input/hiddev.c
@@ -257,9 +257,8 @@ static int hiddev_open(struct inode * inode, struct file * file) {
257 if (i >= HIDDEV_MINORS || !hiddev_table[i]) 257 if (i >= HIDDEV_MINORS || !hiddev_table[i])
258 return -ENODEV; 258 return -ENODEV;
259 259
260 if (!(list = kmalloc(sizeof(struct hiddev_list), GFP_KERNEL))) 260 if (!(list = kzalloc(sizeof(struct hiddev_list), GFP_KERNEL)))
261 return -ENOMEM; 261 return -ENOMEM;
262 memset(list, 0, sizeof(struct hiddev_list));
263 262
264 list->hiddev = hiddev_table[i]; 263 list->hiddev = hiddev_table[i];
265 list->next = hiddev_table[i]->list; 264 list->next = hiddev_table[i]->list;
@@ -754,9 +753,8 @@ int hiddev_connect(struct hid_device *hid)
754 if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDDEV) == 0) 753 if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDDEV) == 0)
755 return -1; 754 return -1;
756 755
757 if (!(hiddev = kmalloc(sizeof(struct hiddev), GFP_KERNEL))) 756 if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL)))
758 return -1; 757 return -1;
759 memset(hiddev, 0, sizeof(struct hiddev));
760 758
761 retval = usb_register_dev(hid->intf, &hiddev_class); 759 retval = usb_register_dev(hid->intf, &hiddev_class);
762 if (retval) { 760 if (retval) {
diff --git a/drivers/usb/media/Kconfig b/drivers/usb/media/Kconfig
index 0d3d2cc5d7be..189d40f96be5 100644
--- a/drivers/usb/media/Kconfig
+++ b/drivers/usb/media/Kconfig
@@ -191,6 +191,21 @@ config USB_W9968CF
191 To compile this driver as a module, choose M here: the 191 To compile this driver as a module, choose M here: the
192 module will be called w9968cf. 192 module will be called w9968cf.
193 193
194config USB_ZC0301
195 tristate "USB ZC0301 Image Processor and Control Chip support"
196 depends on USB && VIDEO_DEV
197 ---help---
198 Say Y here if you want support for cameras based on the ZC0301
199 Image Processor and Control Chip.
200
201 See <file:Documentation/usb/zc0301.txt> for more informations.
202
203 This driver uses the Video For Linux API. You must say Y or M to
204 "Video For Linux" to use this driver.
205
206 To compile this driver as a module, choose M here: the
207 module will be called zc0301.
208
194config USB_PWC 209config USB_PWC
195 tristate "USB Philips Cameras" 210 tristate "USB Philips Cameras"
196 depends on USB && VIDEO_DEV 211 depends on USB && VIDEO_DEV
diff --git a/drivers/usb/media/Makefile b/drivers/usb/media/Makefile
index 3957aa1be0f2..50e89a33b85e 100644
--- a/drivers/usb/media/Makefile
+++ b/drivers/usb/media/Makefile
@@ -2,8 +2,12 @@
2# Makefile for USB Media drivers 2# Makefile for USB Media drivers
3# 3#
4 4
5sn9c102-objs := sn9c102_core.o sn9c102_hv7131d.o sn9c102_mi0343.o sn9c102_ov7630.o sn9c102_pas106b.o sn9c102_pas202bcb.o sn9c102_tas5110c1b.o sn9c102_tas5130d1b.o 5sn9c102-objs := sn9c102_core.o sn9c102_hv7131d.o sn9c102_mi0343.o \
6 sn9c102_ov7630.o sn9c102_pas106b.o sn9c102_pas202bca.o \
7 sn9c102_pas202bcb.o sn9c102_tas5110c1b.o \
8 sn9c102_tas5130d1b.o
6et61x251-objs := et61x251_core.o et61x251_tas5130d1b.o 9et61x251-objs := et61x251_core.o et61x251_tas5130d1b.o
10zc0301-objs := zc0301_core.o zc0301_pas202bcb.o
7 11
8obj-$(CONFIG_USB_DABUSB) += dabusb.o 12obj-$(CONFIG_USB_DABUSB) += dabusb.o
9obj-$(CONFIG_USB_DSBR) += dsbr100.o 13obj-$(CONFIG_USB_DSBR) += dsbr100.o
@@ -16,4 +20,5 @@ obj-$(CONFIG_USB_SN9C102) += sn9c102.o
16obj-$(CONFIG_USB_STV680) += stv680.o 20obj-$(CONFIG_USB_STV680) += stv680.o
17obj-$(CONFIG_USB_VICAM) += vicam.o usbvideo.o 21obj-$(CONFIG_USB_VICAM) += vicam.o usbvideo.o
18obj-$(CONFIG_USB_W9968CF) += w9968cf.o 22obj-$(CONFIG_USB_W9968CF) += w9968cf.o
23obj-$(CONFIG_USB_ZC0301) += zc0301.o
19obj-$(CONFIG_USB_PWC) += pwc/ 24obj-$(CONFIG_USB_PWC) += pwc/
diff --git a/drivers/usb/media/dabusb.c b/drivers/usb/media/dabusb.c
index 18d8eaf408d5..1774ab7a40d2 100644
--- a/drivers/usb/media/dabusb.c
+++ b/drivers/usb/media/dabusb.c
@@ -38,6 +38,7 @@
38#include <linux/delay.h> 38#include <linux/delay.h>
39#include <linux/usb.h> 39#include <linux/usb.h>
40#include <linux/smp_lock.h> 40#include <linux/smp_lock.h>
41#include <linux/mutex.h>
41 42
42#include "dabusb.h" 43#include "dabusb.h"
43#include "dabfirmware.h" 44#include "dabfirmware.h"
@@ -217,12 +218,11 @@ static int dabusb_alloc_buffers (pdabusb_t s)
217 pipesize, packets, transfer_buffer_length); 218 pipesize, packets, transfer_buffer_length);
218 219
219 while (buffers < (s->total_buffer_size << 10)) { 220 while (buffers < (s->total_buffer_size << 10)) {
220 b = (pbuff_t) kmalloc (sizeof (buff_t), GFP_KERNEL); 221 b = (pbuff_t) kzalloc (sizeof (buff_t), GFP_KERNEL);
221 if (!b) { 222 if (!b) {
222 err("kmalloc(sizeof(buff_t))==NULL"); 223 err("kzalloc(sizeof(buff_t))==NULL");
223 goto err; 224 goto err;
224 } 225 }
225 memset (b, 0, sizeof (buff_t));
226 b->s = s; 226 b->s = s;
227 b->purb = usb_alloc_urb(packets, GFP_KERNEL); 227 b->purb = usb_alloc_urb(packets, GFP_KERNEL);
228 if (!b->purb) { 228 if (!b->purb) {
@@ -571,7 +571,7 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l
571 s->readptr = 0; 571 s->readptr = 0;
572 } 572 }
573 } 573 }
574 err: //up(&s->mutex); 574 err: //mutex_unlock(&s->mutex);
575 return ret; 575 return ret;
576} 576}
577 577
@@ -586,10 +586,10 @@ static int dabusb_open (struct inode *inode, struct file *file)
586 s = &dabusb[devnum - DABUSB_MINOR]; 586 s = &dabusb[devnum - DABUSB_MINOR];
587 587
588 dbg("dabusb_open"); 588 dbg("dabusb_open");
589 down (&s->mutex); 589 mutex_lock(&s->mutex);
590 590
591 while (!s->usbdev || s->opened) { 591 while (!s->usbdev || s->opened) {
592 up (&s->mutex); 592 mutex_unlock(&s->mutex);
593 593
594 if (file->f_flags & O_NONBLOCK) { 594 if (file->f_flags & O_NONBLOCK) {
595 return -EBUSY; 595 return -EBUSY;
@@ -599,15 +599,15 @@ static int dabusb_open (struct inode *inode, struct file *file)
599 if (signal_pending (current)) { 599 if (signal_pending (current)) {
600 return -EAGAIN; 600 return -EAGAIN;
601 } 601 }
602 down (&s->mutex); 602 mutex_lock(&s->mutex);
603 } 603 }
604 if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) { 604 if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) {
605 up(&s->mutex); 605 mutex_unlock(&s->mutex);
606 err("set_interface failed"); 606 err("set_interface failed");
607 return -EINVAL; 607 return -EINVAL;
608 } 608 }
609 s->opened = 1; 609 s->opened = 1;
610 up (&s->mutex); 610 mutex_unlock(&s->mutex);
611 611
612 file->f_pos = 0; 612 file->f_pos = 0;
613 file->private_data = s; 613 file->private_data = s;
@@ -621,10 +621,10 @@ static int dabusb_release (struct inode *inode, struct file *file)
621 621
622 dbg("dabusb_release"); 622 dbg("dabusb_release");
623 623
624 down (&s->mutex); 624 mutex_lock(&s->mutex);
625 dabusb_stop (s); 625 dabusb_stop (s);
626 dabusb_free_buffers (s); 626 dabusb_free_buffers (s);
627 up (&s->mutex); 627 mutex_unlock(&s->mutex);
628 628
629 if (!s->remove_pending) { 629 if (!s->remove_pending) {
630 if (usb_set_interface (s->usbdev, _DABUSB_IF, 0) < 0) 630 if (usb_set_interface (s->usbdev, _DABUSB_IF, 0) < 0)
@@ -649,10 +649,10 @@ static int dabusb_ioctl (struct inode *inode, struct file *file, unsigned int cm
649 if (s->remove_pending) 649 if (s->remove_pending)
650 return -EIO; 650 return -EIO;
651 651
652 down (&s->mutex); 652 mutex_lock(&s->mutex);
653 653
654 if (!s->usbdev) { 654 if (!s->usbdev) {
655 up (&s->mutex); 655 mutex_unlock(&s->mutex);
656 return -EIO; 656 return -EIO;
657 } 657 }
658 658
@@ -692,7 +692,7 @@ static int dabusb_ioctl (struct inode *inode, struct file *file, unsigned int cm
692 ret = -ENOIOCTLCMD; 692 ret = -ENOIOCTLCMD;
693 break; 693 break;
694 } 694 }
695 up (&s->mutex); 695 mutex_unlock(&s->mutex);
696 return ret; 696 return ret;
697} 697}
698 698
@@ -738,7 +738,7 @@ static int dabusb_probe (struct usb_interface *intf,
738 738
739 s = &dabusb[intf->minor]; 739 s = &dabusb[intf->minor];
740 740
741 down (&s->mutex); 741 mutex_lock(&s->mutex);
742 s->remove_pending = 0; 742 s->remove_pending = 0;
743 s->usbdev = usbdev; 743 s->usbdev = usbdev;
744 s->devnum = intf->minor; 744 s->devnum = intf->minor;
@@ -761,7 +761,7 @@ static int dabusb_probe (struct usb_interface *intf,
761 } 761 }
762 dbg("bound to interface: %d", intf->altsetting->desc.bInterfaceNumber); 762 dbg("bound to interface: %d", intf->altsetting->desc.bInterfaceNumber);
763 usb_set_intfdata (intf, s); 763 usb_set_intfdata (intf, s);
764 up (&s->mutex); 764 mutex_unlock(&s->mutex);
765 765
766 retval = usb_register_dev(intf, &dabusb_class); 766 retval = usb_register_dev(intf, &dabusb_class);
767 if (retval) { 767 if (retval) {
@@ -772,7 +772,7 @@ static int dabusb_probe (struct usb_interface *intf,
772 return 0; 772 return 0;
773 773
774 reject: 774 reject:
775 up (&s->mutex); 775 mutex_unlock(&s->mutex);
776 s->usbdev = NULL; 776 s->usbdev = NULL;
777 return -ENODEV; 777 return -ENODEV;
778} 778}
@@ -829,7 +829,7 @@ static int __init dabusb_init (void)
829 for (u = 0; u < NRDABUSB; u++) { 829 for (u = 0; u < NRDABUSB; u++) {
830 pdabusb_t s = &dabusb[u]; 830 pdabusb_t s = &dabusb[u];
831 memset (s, 0, sizeof (dabusb_t)); 831 memset (s, 0, sizeof (dabusb_t));
832 init_MUTEX (&s->mutex); 832 mutex_init (&s->mutex);
833 s->usbdev = NULL; 833 s->usbdev = NULL;
834 s->total_buffer_size = buffers; 834 s->total_buffer_size = buffers;
835 init_waitqueue_head (&s->wait); 835 init_waitqueue_head (&s->wait);
diff --git a/drivers/usb/media/dabusb.h b/drivers/usb/media/dabusb.h
index 10b666e43abc..96b03e4af8b9 100644
--- a/drivers/usb/media/dabusb.h
+++ b/drivers/usb/media/dabusb.h
@@ -18,7 +18,7 @@ typedef enum { _stopped=0, _started } driver_state_t;
18 18
19typedef struct 19typedef struct
20{ 20{
21 struct semaphore mutex; 21 struct mutex mutex;
22 struct usb_device *usbdev; 22 struct usb_device *usbdev;
23 wait_queue_head_t wait; 23 wait_queue_head_t wait;
24 wait_queue_head_t remove_ok; 24 wait_queue_head_t remove_ok;
diff --git a/drivers/usb/media/et61x251.h b/drivers/usb/media/et61x251.h
index 652238f329f3..eee8afc9be72 100644
--- a/drivers/usb/media/et61x251.h
+++ b/drivers/usb/media/et61x251.h
@@ -33,7 +33,9 @@
33#include <linux/types.h> 33#include <linux/types.h>
34#include <linux/param.h> 34#include <linux/param.h>
35#include <linux/rwsem.h> 35#include <linux/rwsem.h>
36#include <asm/semaphore.h> 36#include <linux/mutex.h>
37#include <linux/stddef.h>
38#include <linux/string.h>
37 39
38#include "et61x251_sensor.h" 40#include "et61x251_sensor.h"
39 41
@@ -51,6 +53,7 @@
51#define ET61X251_ALTERNATE_SETTING 13 53#define ET61X251_ALTERNATE_SETTING 13
52#define ET61X251_URB_TIMEOUT msecs_to_jiffies(2 * ET61X251_ISO_PACKETS) 54#define ET61X251_URB_TIMEOUT msecs_to_jiffies(2 * ET61X251_ISO_PACKETS)
53#define ET61X251_CTRL_TIMEOUT 100 55#define ET61X251_CTRL_TIMEOUT 100
56#define ET61X251_FRAME_TIMEOUT 2
54 57
55/*****************************************************************************/ 58/*****************************************************************************/
56 59
@@ -127,15 +130,16 @@ struct et61x251_sysfs_attr {
127 130
128struct et61x251_module_param { 131struct et61x251_module_param {
129 u8 force_munmap; 132 u8 force_munmap;
133 u16 frame_timeout;
130}; 134};
131 135
132static DECLARE_MUTEX(et61x251_sysfs_lock); 136static DEFINE_MUTEX(et61x251_sysfs_lock);
133static DECLARE_RWSEM(et61x251_disconnect); 137static DECLARE_RWSEM(et61x251_disconnect);
134 138
135struct et61x251_device { 139struct et61x251_device {
136 struct video_device* v4ldev; 140 struct video_device* v4ldev;
137 141
138 struct et61x251_sensor* sensor; 142 struct et61x251_sensor sensor;
139 143
140 struct usb_device* usbdev; 144 struct usb_device* usbdev;
141 struct urb* urb[ET61X251_URBS]; 145 struct urb* urb[ET61X251_URBS];
@@ -157,19 +161,28 @@ struct et61x251_device {
157 enum et61x251_dev_state state; 161 enum et61x251_dev_state state;
158 u8 users; 162 u8 users;
159 163
160 struct semaphore dev_sem, fileop_sem; 164 struct mutex dev_mutex, fileop_mutex;
161 spinlock_t queue_lock; 165 spinlock_t queue_lock;
162 wait_queue_head_t open, wait_frame, wait_stream; 166 wait_queue_head_t open, wait_frame, wait_stream;
163}; 167};
164 168
165/*****************************************************************************/ 169/*****************************************************************************/
166 170
171struct et61x251_device*
172et61x251_match_id(struct et61x251_device* cam, const struct usb_device_id *id)
173{
174 if (usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id))
175 return cam;
176
177 return NULL;
178}
179
180
167void 181void
168et61x251_attach_sensor(struct et61x251_device* cam, 182et61x251_attach_sensor(struct et61x251_device* cam,
169 struct et61x251_sensor* sensor) 183 struct et61x251_sensor* sensor)
170{ 184{
171 cam->sensor = sensor; 185 memcpy(&cam->sensor, sensor, sizeof(struct et61x251_sensor));
172 cam->sensor->usbdev = cam->usbdev;
173} 186}
174 187
175/*****************************************************************************/ 188/*****************************************************************************/
@@ -212,7 +225,8 @@ do { \
212 225
213#undef PDBG 226#undef PDBG
214#define PDBG(fmt, args...) \ 227#define PDBG(fmt, args...) \
215dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args) 228dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
229 __FUNCTION__, __LINE__ , ## args)
216 230
217#undef PDBGG 231#undef PDBGG
218#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */ 232#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
diff --git a/drivers/usb/media/et61x251_core.c b/drivers/usb/media/et61x251_core.c
index 2c0171a5ad62..7cc01b828b3d 100644
--- a/drivers/usb/media/et61x251_core.c
+++ b/drivers/usb/media/et61x251_core.c
@@ -25,11 +25,9 @@
25#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/string.h>
29#include <linux/device.h> 28#include <linux/device.h>
30#include <linux/fs.h> 29#include <linux/fs.h>
31#include <linux/delay.h> 30#include <linux/delay.h>
32#include <linux/stddef.h>
33#include <linux/compiler.h> 31#include <linux/compiler.h>
34#include <linux/ioctl.h> 32#include <linux/ioctl.h>
35#include <linux/poll.h> 33#include <linux/poll.h>
@@ -50,8 +48,8 @@
50#define ET61X251_MODULE_AUTHOR "(C) 2006 Luca Risolia" 48#define ET61X251_MODULE_AUTHOR "(C) 2006 Luca Risolia"
51#define ET61X251_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 49#define ET61X251_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
52#define ET61X251_MODULE_LICENSE "GPL" 50#define ET61X251_MODULE_LICENSE "GPL"
53#define ET61X251_MODULE_VERSION "1:1.01" 51#define ET61X251_MODULE_VERSION "1:1.02"
54#define ET61X251_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 1) 52#define ET61X251_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 2)
55 53
56/*****************************************************************************/ 54/*****************************************************************************/
57 55
@@ -90,6 +88,16 @@ MODULE_PARM_DESC(force_munmap,
90 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"." 88 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"."
91 "\n"); 89 "\n");
92 90
91static unsigned int frame_timeout[] = {[0 ... ET61X251_MAX_DEVICES-1] =
92 ET61X251_FRAME_TIMEOUT};
93module_param_array(frame_timeout, uint, NULL, 0644);
94MODULE_PARM_DESC(frame_timeout,
95 "\n<n[,...]> Timeout for a video frame in seconds."
96 "\nThis parameter is specific for each detected camera."
97 "\nDefault value is "
98 __MODULE_STRING(ET61X251_FRAME_TIMEOUT)"."
99 "\n");
100
93#ifdef ET61X251_DEBUG 101#ifdef ET61X251_DEBUG
94static unsigned short debug = ET61X251_DEBUG_LEVEL; 102static unsigned short debug = ET61X251_DEBUG_LEVEL;
95module_param(debug, ushort, 0644); 103module_param(debug, ushort, 0644);
@@ -111,8 +119,8 @@ static u32
111et61x251_request_buffers(struct et61x251_device* cam, u32 count, 119et61x251_request_buffers(struct et61x251_device* cam, u32 count,
112 enum et61x251_io_method io) 120 enum et61x251_io_method io)
113{ 121{
114 struct v4l2_pix_format* p = &(cam->sensor->pix_format); 122 struct v4l2_pix_format* p = &(cam->sensor.pix_format);
115 struct v4l2_rect* r = &(cam->sensor->cropcap.bounds); 123 struct v4l2_rect* r = &(cam->sensor.cropcap.bounds);
116 const size_t imagesize = cam->module_param.force_munmap || 124 const size_t imagesize = cam->module_param.force_munmap ||
117 io == IO_READ ? 125 io == IO_READ ?
118 (p->width * p->height * p->priv) / 8 : 126 (p->width * p->height * p->priv) / 8 :
@@ -268,8 +276,8 @@ et61x251_i2c_try_read(struct et61x251_device* cam,
268 int err = 0, res; 276 int err = 0, res;
269 277
270 data[0] = address; 278 data[0] = address;
271 data[1] = cam->sensor->i2c_slave_id; 279 data[1] = cam->sensor.i2c_slave_id;
272 data[2] = cam->sensor->rsta | 0x10; 280 data[2] = cam->sensor.rsta | 0x10;
273 data[3] = !(et61x251_read_reg(cam, 0x8b) & 0x02); 281 data[3] = !(et61x251_read_reg(cam, 0x8b) & 0x02);
274 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41, 282 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
275 0, 0x88, data, 4, ET61X251_CTRL_TIMEOUT); 283 0, 0x88, data, 4, ET61X251_CTRL_TIMEOUT);
@@ -301,8 +309,8 @@ et61x251_i2c_try_write(struct et61x251_device* cam,
301 int err = 0, res; 309 int err = 0, res;
302 310
303 data[0] = address; 311 data[0] = address;
304 data[1] = cam->sensor->i2c_slave_id; 312 data[1] = cam->sensor.i2c_slave_id;
305 data[2] = cam->sensor->rsta | 0x12; 313 data[2] = cam->sensor.rsta | 0x12;
306 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41, 314 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
307 0, 0x88, data, 3, ET61X251_CTRL_TIMEOUT); 315 0, 0x88, data, 3, ET61X251_CTRL_TIMEOUT);
308 if (res < 0) 316 if (res < 0)
@@ -334,9 +342,6 @@ et61x251_i2c_raw_write(struct et61x251_device* cam, u8 n, u8 data1, u8 data2,
334 u8* data = cam->control_buffer; 342 u8* data = cam->control_buffer;
335 int err = 0, res; 343 int err = 0, res;
336 344
337 if (!cam->sensor)
338 return -1;
339
340 data[0] = data2; 345 data[0] = data2;
341 data[1] = data3; 346 data[1] = data3;
342 data[2] = data4; 347 data[2] = data4;
@@ -350,8 +355,8 @@ et61x251_i2c_raw_write(struct et61x251_device* cam, u8 n, u8 data1, u8 data2,
350 err += res; 355 err += res;
351 356
352 data[0] = address; 357 data[0] = address;
353 data[1] = cam->sensor->i2c_slave_id; 358 data[1] = cam->sensor.i2c_slave_id;
354 data[2] = cam->sensor->rsta | 0x02 | (n << 4); 359 data[2] = cam->sensor.rsta | 0x02 | (n << 4);
355 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41, 360 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
356 0, 0x88, data, 3, ET61X251_CTRL_TIMEOUT); 361 0, 0x88, data, 3, ET61X251_CTRL_TIMEOUT);
357 if (res < 0) 362 if (res < 0)
@@ -364,11 +369,11 @@ et61x251_i2c_raw_write(struct et61x251_device* cam, u8 n, u8 data1, u8 data2,
364 if (res < 0) 369 if (res < 0)
365 err += res; 370 err += res;
366 371
367 err += et61x251_i2c_wait(cam, cam->sensor); 372 err += et61x251_i2c_wait(cam, &cam->sensor);
368 373
369 if (err) 374 if (err)
370 DBG(3, "I2C raw write failed for %s image sensor", 375 DBG(3, "I2C raw write failed for %s image sensor",
371 cam->sensor->name); 376 cam->sensor.name);
372 377
373 PDBGG("I2C raw write: %u bytes, address = 0x%02X, data1 = 0x%02X, " 378 PDBGG("I2C raw write: %u bytes, address = 0x%02X, data1 = 0x%02X, "
374 "data2 = 0x%02X, data3 = 0x%02X, data4 = 0x%02X, data5 = 0x%02X," 379 "data2 = 0x%02X, data3 = 0x%02X, data4 = 0x%02X, data5 = 0x%02X,"
@@ -382,19 +387,13 @@ et61x251_i2c_raw_write(struct et61x251_device* cam, u8 n, u8 data1, u8 data2,
382 387
383int et61x251_i2c_read(struct et61x251_device* cam, u8 address) 388int et61x251_i2c_read(struct et61x251_device* cam, u8 address)
384{ 389{
385 if (!cam->sensor) 390 return et61x251_i2c_try_read(cam, &cam->sensor, address);
386 return -1;
387
388 return et61x251_i2c_try_read(cam, cam->sensor, address);
389} 391}
390 392
391 393
392int et61x251_i2c_write(struct et61x251_device* cam, u8 address, u8 value) 394int et61x251_i2c_write(struct et61x251_device* cam, u8 address, u8 value)
393{ 395{
394 if (!cam->sensor) 396 return et61x251_i2c_try_write(cam, &cam->sensor, address, value);
395 return -1;
396
397 return et61x251_i2c_try_write(cam, cam->sensor, address, value);
398} 397}
399 398
400/*****************************************************************************/ 399/*****************************************************************************/
@@ -417,7 +416,7 @@ static void et61x251_urb_complete(struct urb *urb, struct pt_regs* regs)
417 if ((*f)) 416 if ((*f))
418 (*f)->state = F_QUEUED; 417 (*f)->state = F_QUEUED;
419 DBG(3, "Stream interrupted"); 418 DBG(3, "Stream interrupted");
420 wake_up_interruptible(&cam->wait_stream); 419 wake_up(&cam->wait_stream);
421 } 420 }
422 421
423 if (cam->state & DEV_DISCONNECTED) 422 if (cam->state & DEV_DISCONNECTED)
@@ -435,9 +434,9 @@ static void et61x251_urb_complete(struct urb *urb, struct pt_regs* regs)
435 (*f) = list_entry(cam->inqueue.next, struct et61x251_frame_t, 434 (*f) = list_entry(cam->inqueue.next, struct et61x251_frame_t,
436 frame); 435 frame);
437 436
438 imagesize = (cam->sensor->pix_format.width * 437 imagesize = (cam->sensor.pix_format.width *
439 cam->sensor->pix_format.height * 438 cam->sensor.pix_format.height *
440 cam->sensor->pix_format.priv) / 8; 439 cam->sensor.pix_format.priv) / 8;
441 440
442 for (i = 0; i < urb->number_of_packets; i++) { 441 for (i = 0; i < urb->number_of_packets; i++) {
443 unsigned int len, status; 442 unsigned int len, status;
@@ -476,7 +475,7 @@ start_of_frame:
476 475
477 if ((*f)->state == F_GRABBING) { 476 if ((*f)->state == F_GRABBING) {
478 if (sof && (*f)->buf.bytesused) { 477 if (sof && (*f)->buf.bytesused) {
479 if (cam->sensor->pix_format.pixelformat == 478 if (cam->sensor.pix_format.pixelformat ==
480 V4L2_PIX_FMT_ET61X251) 479 V4L2_PIX_FMT_ET61X251)
481 goto end_of_frame; 480 goto end_of_frame;
482 else { 481 else {
@@ -521,7 +520,7 @@ end_of_frame:
521 goto resubmit_urb; 520 goto resubmit_urb;
522 521
523 if (sof && 522 if (sof &&
524 cam->sensor->pix_format.pixelformat == 523 cam->sensor.pix_format.pixelformat ==
525 V4L2_PIX_FMT_ET61X251) 524 V4L2_PIX_FMT_ET61X251)
526 goto start_of_frame; 525 goto start_of_frame;
527 } 526 }
@@ -650,21 +649,21 @@ static int et61x251_stop_transfer(struct et61x251_device* cam)
650 649
651static int et61x251_stream_interrupt(struct et61x251_device* cam) 650static int et61x251_stream_interrupt(struct et61x251_device* cam)
652{ 651{
653 int err = 0; 652 long timeout;
654 653
655 cam->stream = STREAM_INTERRUPT; 654 cam->stream = STREAM_INTERRUPT;
656 err = wait_event_timeout(cam->wait_stream, 655 timeout = wait_event_timeout(cam->wait_stream,
657 (cam->stream == STREAM_OFF) || 656 (cam->stream == STREAM_OFF) ||
658 (cam->state & DEV_DISCONNECTED), 657 (cam->state & DEV_DISCONNECTED),
659 ET61X251_URB_TIMEOUT); 658 ET61X251_URB_TIMEOUT);
660 if (cam->state & DEV_DISCONNECTED) 659 if (cam->state & DEV_DISCONNECTED)
661 return -ENODEV; 660 return -ENODEV;
662 else if (err) { 661 else if (cam->stream != STREAM_OFF) {
663 cam->state |= DEV_MISCONFIGURED; 662 cam->state |= DEV_MISCONFIGURED;
664 DBG(1, "URB timeout reached. The camera is misconfigured. To " 663 DBG(1, "URB timeout reached. The camera is misconfigured. To "
665 "use it, close and open /dev/video%d again.", 664 "use it, close and open /dev/video%d again.",
666 cam->v4ldev->minor); 665 cam->v4ldev->minor);
667 return err; 666 return -EIO;
668 } 667 }
669 668
670 return 0; 669 return 0;
@@ -709,18 +708,18 @@ static ssize_t et61x251_show_reg(struct class_device* cd, char* buf)
709 struct et61x251_device* cam; 708 struct et61x251_device* cam;
710 ssize_t count; 709 ssize_t count;
711 710
712 if (down_interruptible(&et61x251_sysfs_lock)) 711 if (mutex_lock_interruptible(&et61x251_sysfs_lock))
713 return -ERESTARTSYS; 712 return -ERESTARTSYS;
714 713
715 cam = video_get_drvdata(to_video_device(cd)); 714 cam = video_get_drvdata(to_video_device(cd));
716 if (!cam) { 715 if (!cam) {
717 up(&et61x251_sysfs_lock); 716 mutex_unlock(&et61x251_sysfs_lock);
718 return -ENODEV; 717 return -ENODEV;
719 } 718 }
720 719
721 count = sprintf(buf, "%u\n", cam->sysfs.reg); 720 count = sprintf(buf, "%u\n", cam->sysfs.reg);
722 721
723 up(&et61x251_sysfs_lock); 722 mutex_unlock(&et61x251_sysfs_lock);
724 723
725 return count; 724 return count;
726} 725}
@@ -733,18 +732,18 @@ et61x251_store_reg(struct class_device* cd, const char* buf, size_t len)
733 u8 index; 732 u8 index;
734 ssize_t count; 733 ssize_t count;
735 734
736 if (down_interruptible(&et61x251_sysfs_lock)) 735 if (mutex_lock_interruptible(&et61x251_sysfs_lock))
737 return -ERESTARTSYS; 736 return -ERESTARTSYS;
738 737
739 cam = video_get_drvdata(to_video_device(cd)); 738 cam = video_get_drvdata(to_video_device(cd));
740 if (!cam) { 739 if (!cam) {
741 up(&et61x251_sysfs_lock); 740 mutex_unlock(&et61x251_sysfs_lock);
742 return -ENODEV; 741 return -ENODEV;
743 } 742 }
744 743
745 index = et61x251_strtou8(buf, len, &count); 744 index = et61x251_strtou8(buf, len, &count);
746 if (index > 0x8e || !count) { 745 if (index > 0x8e || !count) {
747 up(&et61x251_sysfs_lock); 746 mutex_unlock(&et61x251_sysfs_lock);
748 return -EINVAL; 747 return -EINVAL;
749 } 748 }
750 749
@@ -753,7 +752,7 @@ et61x251_store_reg(struct class_device* cd, const char* buf, size_t len)
753 DBG(2, "Moved ET61X[12]51 register index to 0x%02X", cam->sysfs.reg); 752 DBG(2, "Moved ET61X[12]51 register index to 0x%02X", cam->sysfs.reg);
754 DBG(3, "Written bytes: %zd", count); 753 DBG(3, "Written bytes: %zd", count);
755 754
756 up(&et61x251_sysfs_lock); 755 mutex_unlock(&et61x251_sysfs_lock);
757 756
758 return count; 757 return count;
759} 758}
@@ -765,17 +764,17 @@ static ssize_t et61x251_show_val(struct class_device* cd, char* buf)
765 ssize_t count; 764 ssize_t count;
766 int val; 765 int val;
767 766
768 if (down_interruptible(&et61x251_sysfs_lock)) 767 if (mutex_lock_interruptible(&et61x251_sysfs_lock))
769 return -ERESTARTSYS; 768 return -ERESTARTSYS;
770 769
771 cam = video_get_drvdata(to_video_device(cd)); 770 cam = video_get_drvdata(to_video_device(cd));
772 if (!cam) { 771 if (!cam) {
773 up(&et61x251_sysfs_lock); 772 mutex_unlock(&et61x251_sysfs_lock);
774 return -ENODEV; 773 return -ENODEV;
775 } 774 }
776 775
777 if ((val = et61x251_read_reg(cam, cam->sysfs.reg)) < 0) { 776 if ((val = et61x251_read_reg(cam, cam->sysfs.reg)) < 0) {
778 up(&et61x251_sysfs_lock); 777 mutex_unlock(&et61x251_sysfs_lock);
779 return -EIO; 778 return -EIO;
780 } 779 }
781 780
@@ -783,7 +782,7 @@ static ssize_t et61x251_show_val(struct class_device* cd, char* buf)
783 782
784 DBG(3, "Read bytes: %zd", count); 783 DBG(3, "Read bytes: %zd", count);
785 784
786 up(&et61x251_sysfs_lock); 785 mutex_unlock(&et61x251_sysfs_lock);
787 786
788 return count; 787 return count;
789} 788}
@@ -797,24 +796,24 @@ et61x251_store_val(struct class_device* cd, const char* buf, size_t len)
797 ssize_t count; 796 ssize_t count;
798 int err; 797 int err;
799 798
800 if (down_interruptible(&et61x251_sysfs_lock)) 799 if (mutex_lock_interruptible(&et61x251_sysfs_lock))
801 return -ERESTARTSYS; 800 return -ERESTARTSYS;
802 801
803 cam = video_get_drvdata(to_video_device(cd)); 802 cam = video_get_drvdata(to_video_device(cd));
804 if (!cam) { 803 if (!cam) {
805 up(&et61x251_sysfs_lock); 804 mutex_unlock(&et61x251_sysfs_lock);
806 return -ENODEV; 805 return -ENODEV;
807 } 806 }
808 807
809 value = et61x251_strtou8(buf, len, &count); 808 value = et61x251_strtou8(buf, len, &count);
810 if (!count) { 809 if (!count) {
811 up(&et61x251_sysfs_lock); 810 mutex_unlock(&et61x251_sysfs_lock);
812 return -EINVAL; 811 return -EINVAL;
813 } 812 }
814 813
815 err = et61x251_write_reg(cam, value, cam->sysfs.reg); 814 err = et61x251_write_reg(cam, value, cam->sysfs.reg);
816 if (err) { 815 if (err) {
817 up(&et61x251_sysfs_lock); 816 mutex_unlock(&et61x251_sysfs_lock);
818 return -EIO; 817 return -EIO;
819 } 818 }
820 819
@@ -822,7 +821,7 @@ et61x251_store_val(struct class_device* cd, const char* buf, size_t len)
822 cam->sysfs.reg, value); 821 cam->sysfs.reg, value);
823 DBG(3, "Written bytes: %zd", count); 822 DBG(3, "Written bytes: %zd", count);
824 823
825 up(&et61x251_sysfs_lock); 824 mutex_unlock(&et61x251_sysfs_lock);
826 825
827 return count; 826 return count;
828} 827}
@@ -833,12 +832,12 @@ static ssize_t et61x251_show_i2c_reg(struct class_device* cd, char* buf)
833 struct et61x251_device* cam; 832 struct et61x251_device* cam;
834 ssize_t count; 833 ssize_t count;
835 834
836 if (down_interruptible(&et61x251_sysfs_lock)) 835 if (mutex_lock_interruptible(&et61x251_sysfs_lock))
837 return -ERESTARTSYS; 836 return -ERESTARTSYS;
838 837
839 cam = video_get_drvdata(to_video_device(cd)); 838 cam = video_get_drvdata(to_video_device(cd));
840 if (!cam) { 839 if (!cam) {
841 up(&et61x251_sysfs_lock); 840 mutex_unlock(&et61x251_sysfs_lock);
842 return -ENODEV; 841 return -ENODEV;
843 } 842 }
844 843
@@ -846,7 +845,7 @@ static ssize_t et61x251_show_i2c_reg(struct class_device* cd, char* buf)
846 845
847 DBG(3, "Read bytes: %zd", count); 846 DBG(3, "Read bytes: %zd", count);
848 847
849 up(&et61x251_sysfs_lock); 848 mutex_unlock(&et61x251_sysfs_lock);
850 849
851 return count; 850 return count;
852} 851}
@@ -859,18 +858,18 @@ et61x251_store_i2c_reg(struct class_device* cd, const char* buf, size_t len)
859 u8 index; 858 u8 index;
860 ssize_t count; 859 ssize_t count;
861 860
862 if (down_interruptible(&et61x251_sysfs_lock)) 861 if (mutex_lock_interruptible(&et61x251_sysfs_lock))
863 return -ERESTARTSYS; 862 return -ERESTARTSYS;
864 863
865 cam = video_get_drvdata(to_video_device(cd)); 864 cam = video_get_drvdata(to_video_device(cd));
866 if (!cam) { 865 if (!cam) {
867 up(&et61x251_sysfs_lock); 866 mutex_unlock(&et61x251_sysfs_lock);
868 return -ENODEV; 867 return -ENODEV;
869 } 868 }
870 869
871 index = et61x251_strtou8(buf, len, &count); 870 index = et61x251_strtou8(buf, len, &count);
872 if (!count) { 871 if (!count) {
873 up(&et61x251_sysfs_lock); 872 mutex_unlock(&et61x251_sysfs_lock);
874 return -EINVAL; 873 return -EINVAL;
875 } 874 }
876 875
@@ -879,7 +878,7 @@ et61x251_store_i2c_reg(struct class_device* cd, const char* buf, size_t len)
879 DBG(2, "Moved sensor register index to 0x%02X", cam->sysfs.i2c_reg); 878 DBG(2, "Moved sensor register index to 0x%02X", cam->sysfs.i2c_reg);
880 DBG(3, "Written bytes: %zd", count); 879 DBG(3, "Written bytes: %zd", count);
881 880
882 up(&et61x251_sysfs_lock); 881 mutex_unlock(&et61x251_sysfs_lock);
883 882
884 return count; 883 return count;
885} 884}
@@ -891,22 +890,22 @@ static ssize_t et61x251_show_i2c_val(struct class_device* cd, char* buf)
891 ssize_t count; 890 ssize_t count;
892 int val; 891 int val;
893 892
894 if (down_interruptible(&et61x251_sysfs_lock)) 893 if (mutex_lock_interruptible(&et61x251_sysfs_lock))
895 return -ERESTARTSYS; 894 return -ERESTARTSYS;
896 895
897 cam = video_get_drvdata(to_video_device(cd)); 896 cam = video_get_drvdata(to_video_device(cd));
898 if (!cam) { 897 if (!cam) {
899 up(&et61x251_sysfs_lock); 898 mutex_unlock(&et61x251_sysfs_lock);
900 return -ENODEV; 899 return -ENODEV;
901 } 900 }
902 901
903 if (!(cam->sensor->sysfs_ops & ET61X251_I2C_READ)) { 902 if (!(cam->sensor.sysfs_ops & ET61X251_I2C_READ)) {
904 up(&et61x251_sysfs_lock); 903 mutex_unlock(&et61x251_sysfs_lock);
905 return -ENOSYS; 904 return -ENOSYS;
906 } 905 }
907 906
908 if ((val = et61x251_i2c_read(cam, cam->sysfs.i2c_reg)) < 0) { 907 if ((val = et61x251_i2c_read(cam, cam->sysfs.i2c_reg)) < 0) {
909 up(&et61x251_sysfs_lock); 908 mutex_unlock(&et61x251_sysfs_lock);
910 return -EIO; 909 return -EIO;
911 } 910 }
912 911
@@ -914,7 +913,7 @@ static ssize_t et61x251_show_i2c_val(struct class_device* cd, char* buf)
914 913
915 DBG(3, "Read bytes: %zd", count); 914 DBG(3, "Read bytes: %zd", count);
916 915
917 up(&et61x251_sysfs_lock); 916 mutex_unlock(&et61x251_sysfs_lock);
918 917
919 return count; 918 return count;
920} 919}
@@ -928,29 +927,29 @@ et61x251_store_i2c_val(struct class_device* cd, const char* buf, size_t len)
928 ssize_t count; 927 ssize_t count;
929 int err; 928 int err;
930 929
931 if (down_interruptible(&et61x251_sysfs_lock)) 930 if (mutex_lock_interruptible(&et61x251_sysfs_lock))
932 return -ERESTARTSYS; 931 return -ERESTARTSYS;
933 932
934 cam = video_get_drvdata(to_video_device(cd)); 933 cam = video_get_drvdata(to_video_device(cd));
935 if (!cam) { 934 if (!cam) {
936 up(&et61x251_sysfs_lock); 935 mutex_unlock(&et61x251_sysfs_lock);
937 return -ENODEV; 936 return -ENODEV;
938 } 937 }
939 938
940 if (!(cam->sensor->sysfs_ops & ET61X251_I2C_READ)) { 939 if (!(cam->sensor.sysfs_ops & ET61X251_I2C_READ)) {
941 up(&et61x251_sysfs_lock); 940 mutex_unlock(&et61x251_sysfs_lock);
942 return -ENOSYS; 941 return -ENOSYS;
943 } 942 }
944 943
945 value = et61x251_strtou8(buf, len, &count); 944 value = et61x251_strtou8(buf, len, &count);
946 if (!count) { 945 if (!count) {
947 up(&et61x251_sysfs_lock); 946 mutex_unlock(&et61x251_sysfs_lock);
948 return -EINVAL; 947 return -EINVAL;
949 } 948 }
950 949
951 err = et61x251_i2c_write(cam, cam->sysfs.i2c_reg, value); 950 err = et61x251_i2c_write(cam, cam->sysfs.i2c_reg, value);
952 if (err) { 951 if (err) {
953 up(&et61x251_sysfs_lock); 952 mutex_unlock(&et61x251_sysfs_lock);
954 return -EIO; 953 return -EIO;
955 } 954 }
956 955
@@ -958,7 +957,7 @@ et61x251_store_i2c_val(struct class_device* cd, const char* buf, size_t len)
958 cam->sysfs.i2c_reg, value); 957 cam->sysfs.i2c_reg, value);
959 DBG(3, "Written bytes: %zd", count); 958 DBG(3, "Written bytes: %zd", count);
960 959
961 up(&et61x251_sysfs_lock); 960 mutex_unlock(&et61x251_sysfs_lock);
962 961
963 return count; 962 return count;
964} 963}
@@ -980,7 +979,7 @@ static void et61x251_create_sysfs(struct et61x251_device* cam)
980 979
981 video_device_create_file(v4ldev, &class_device_attr_reg); 980 video_device_create_file(v4ldev, &class_device_attr_reg);
982 video_device_create_file(v4ldev, &class_device_attr_val); 981 video_device_create_file(v4ldev, &class_device_attr_val);
983 if (cam->sensor && cam->sensor->sysfs_ops) { 982 if (cam->sensor.sysfs_ops) {
984 video_device_create_file(v4ldev, &class_device_attr_i2c_reg); 983 video_device_create_file(v4ldev, &class_device_attr_i2c_reg);
985 video_device_create_file(v4ldev, &class_device_attr_i2c_val); 984 video_device_create_file(v4ldev, &class_device_attr_i2c_val);
986 } 985 }
@@ -1048,7 +1047,7 @@ static int et61x251_set_scale(struct et61x251_device* cam, u8 scale)
1048static int 1047static int
1049et61x251_set_crop(struct et61x251_device* cam, struct v4l2_rect* rect) 1048et61x251_set_crop(struct et61x251_device* cam, struct v4l2_rect* rect)
1050{ 1049{
1051 struct et61x251_sensor* s = cam->sensor; 1050 struct et61x251_sensor* s = &cam->sensor;
1052 u16 fmw_sx = (u16)(rect->left - s->cropcap.bounds.left + 1051 u16 fmw_sx = (u16)(rect->left - s->cropcap.bounds.left +
1053 s->active_pixel.left), 1052 s->active_pixel.left),
1054 fmw_sy = (u16)(rect->top - s->cropcap.bounds.top + 1053 fmw_sy = (u16)(rect->top - s->cropcap.bounds.top +
@@ -1076,7 +1075,7 @@ et61x251_set_crop(struct et61x251_device* cam, struct v4l2_rect* rect)
1076 1075
1077static int et61x251_init(struct et61x251_device* cam) 1076static int et61x251_init(struct et61x251_device* cam)
1078{ 1077{
1079 struct et61x251_sensor* s = cam->sensor; 1078 struct et61x251_sensor* s = &cam->sensor;
1080 struct v4l2_control ctrl; 1079 struct v4l2_control ctrl;
1081 struct v4l2_queryctrl *qctrl; 1080 struct v4l2_queryctrl *qctrl;
1082 struct v4l2_rect* rect; 1081 struct v4l2_rect* rect;
@@ -1143,7 +1142,7 @@ static int et61x251_init(struct et61x251_device* cam)
1143 } 1142 }
1144 1143
1145 if (!(cam->state & DEV_INITIALIZED)) { 1144 if (!(cam->state & DEV_INITIALIZED)) {
1146 init_MUTEX(&cam->fileop_sem); 1145 mutex_init(&cam->fileop_mutex);
1147 spin_lock_init(&cam->queue_lock); 1146 spin_lock_init(&cam->queue_lock);
1148 init_waitqueue_head(&cam->wait_frame); 1147 init_waitqueue_head(&cam->wait_frame);
1149 init_waitqueue_head(&cam->wait_stream); 1148 init_waitqueue_head(&cam->wait_stream);
@@ -1161,13 +1160,15 @@ static int et61x251_init(struct et61x251_device* cam)
1161 1160
1162static void et61x251_release_resources(struct et61x251_device* cam) 1161static void et61x251_release_resources(struct et61x251_device* cam)
1163{ 1162{
1164 down(&et61x251_sysfs_lock); 1163 mutex_lock(&et61x251_sysfs_lock);
1165 1164
1166 DBG(2, "V4L2 device /dev/video%d deregistered", cam->v4ldev->minor); 1165 DBG(2, "V4L2 device /dev/video%d deregistered", cam->v4ldev->minor);
1167 video_set_drvdata(cam->v4ldev, NULL); 1166 video_set_drvdata(cam->v4ldev, NULL);
1168 video_unregister_device(cam->v4ldev); 1167 video_unregister_device(cam->v4ldev);
1169 1168
1170 up(&et61x251_sysfs_lock); 1169 usb_put_dev(cam->usbdev);
1170
1171 mutex_unlock(&et61x251_sysfs_lock);
1171 1172
1172 kfree(cam->control_buffer); 1173 kfree(cam->control_buffer);
1173} 1174}
@@ -1188,7 +1189,7 @@ static int et61x251_open(struct inode* inode, struct file* filp)
1188 1189
1189 cam = video_get_drvdata(video_devdata(filp)); 1190 cam = video_get_drvdata(video_devdata(filp));
1190 1191
1191 if (down_interruptible(&cam->dev_sem)) { 1192 if (mutex_lock_interruptible(&cam->dev_mutex)) {
1192 up_read(&et61x251_disconnect); 1193 up_read(&et61x251_disconnect);
1193 return -ERESTARTSYS; 1194 return -ERESTARTSYS;
1194 } 1195 }
@@ -1200,7 +1201,7 @@ static int et61x251_open(struct inode* inode, struct file* filp)
1200 err = -EWOULDBLOCK; 1201 err = -EWOULDBLOCK;
1201 goto out; 1202 goto out;
1202 } 1203 }
1203 up(&cam->dev_sem); 1204 mutex_unlock(&cam->dev_mutex);
1204 err = wait_event_interruptible_exclusive(cam->open, 1205 err = wait_event_interruptible_exclusive(cam->open,
1205 cam->state & DEV_DISCONNECTED 1206 cam->state & DEV_DISCONNECTED
1206 || !cam->users); 1207 || !cam->users);
@@ -1212,7 +1213,7 @@ static int et61x251_open(struct inode* inode, struct file* filp)
1212 up_read(&et61x251_disconnect); 1213 up_read(&et61x251_disconnect);
1213 return -ENODEV; 1214 return -ENODEV;
1214 } 1215 }
1215 down(&cam->dev_sem); 1216 mutex_lock(&cam->dev_mutex);
1216 } 1217 }
1217 1218
1218 1219
@@ -1240,7 +1241,7 @@ static int et61x251_open(struct inode* inode, struct file* filp)
1240 DBG(3, "Video device /dev/video%d is open", cam->v4ldev->minor); 1241 DBG(3, "Video device /dev/video%d is open", cam->v4ldev->minor);
1241 1242
1242out: 1243out:
1243 up(&cam->dev_sem); 1244 mutex_unlock(&cam->dev_mutex);
1244 up_read(&et61x251_disconnect); 1245 up_read(&et61x251_disconnect);
1245 return err; 1246 return err;
1246} 1247}
@@ -1250,7 +1251,7 @@ static int et61x251_release(struct inode* inode, struct file* filp)
1250{ 1251{
1251 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp)); 1252 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp));
1252 1253
1253 down(&cam->dev_sem); /* prevent disconnect() to be called */ 1254 mutex_lock(&cam->dev_mutex); /* prevent disconnect() to be called */
1254 1255
1255 et61x251_stop_transfer(cam); 1256 et61x251_stop_transfer(cam);
1256 1257
@@ -1258,7 +1259,7 @@ static int et61x251_release(struct inode* inode, struct file* filp)
1258 1259
1259 if (cam->state & DEV_DISCONNECTED) { 1260 if (cam->state & DEV_DISCONNECTED) {
1260 et61x251_release_resources(cam); 1261 et61x251_release_resources(cam);
1261 up(&cam->dev_sem); 1262 mutex_unlock(&cam->dev_mutex);
1262 kfree(cam); 1263 kfree(cam);
1263 return 0; 1264 return 0;
1264 } 1265 }
@@ -1268,7 +1269,7 @@ static int et61x251_release(struct inode* inode, struct file* filp)
1268 1269
1269 DBG(3, "Video device /dev/video%d closed", cam->v4ldev->minor); 1270 DBG(3, "Video device /dev/video%d closed", cam->v4ldev->minor);
1270 1271
1271 up(&cam->dev_sem); 1272 mutex_unlock(&cam->dev_mutex);
1272 1273
1273 return 0; 1274 return 0;
1274} 1275}
@@ -1281,28 +1282,29 @@ et61x251_read(struct file* filp, char __user * buf,
1281 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp)); 1282 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp));
1282 struct et61x251_frame_t* f, * i; 1283 struct et61x251_frame_t* f, * i;
1283 unsigned long lock_flags; 1284 unsigned long lock_flags;
1285 long timeout;
1284 int err = 0; 1286 int err = 0;
1285 1287
1286 if (down_interruptible(&cam->fileop_sem)) 1288 if (mutex_lock_interruptible(&cam->fileop_mutex))
1287 return -ERESTARTSYS; 1289 return -ERESTARTSYS;
1288 1290
1289 if (cam->state & DEV_DISCONNECTED) { 1291 if (cam->state & DEV_DISCONNECTED) {
1290 DBG(1, "Device not present"); 1292 DBG(1, "Device not present");
1291 up(&cam->fileop_sem); 1293 mutex_unlock(&cam->fileop_mutex);
1292 return -ENODEV; 1294 return -ENODEV;
1293 } 1295 }
1294 1296
1295 if (cam->state & DEV_MISCONFIGURED) { 1297 if (cam->state & DEV_MISCONFIGURED) {
1296 DBG(1, "The camera is misconfigured. Close and open it " 1298 DBG(1, "The camera is misconfigured. Close and open it "
1297 "again."); 1299 "again.");
1298 up(&cam->fileop_sem); 1300 mutex_unlock(&cam->fileop_mutex);
1299 return -EIO; 1301 return -EIO;
1300 } 1302 }
1301 1303
1302 if (cam->io == IO_MMAP) { 1304 if (cam->io == IO_MMAP) {
1303 DBG(3, "Close and open the device again to choose the read " 1305 DBG(3, "Close and open the device again to choose the read "
1304 "method"); 1306 "method");
1305 up(&cam->fileop_sem); 1307 mutex_unlock(&cam->fileop_mutex);
1306 return -EINVAL; 1308 return -EINVAL;
1307 } 1309 }
1308 1310
@@ -1310,7 +1312,7 @@ et61x251_read(struct file* filp, char __user * buf,
1310 if (!et61x251_request_buffers(cam, cam->nreadbuffers, 1312 if (!et61x251_request_buffers(cam, cam->nreadbuffers,
1311 IO_READ)) { 1313 IO_READ)) {
1312 DBG(1, "read() failed, not enough memory"); 1314 DBG(1, "read() failed, not enough memory");
1313 up(&cam->fileop_sem); 1315 mutex_unlock(&cam->fileop_mutex);
1314 return -ENOMEM; 1316 return -ENOMEM;
1315 } 1317 }
1316 cam->io = IO_READ; 1318 cam->io = IO_READ;
@@ -1324,30 +1326,32 @@ et61x251_read(struct file* filp, char __user * buf,
1324 } 1326 }
1325 1327
1326 if (!count) { 1328 if (!count) {
1327 up(&cam->fileop_sem); 1329 mutex_unlock(&cam->fileop_mutex);
1328 return 0; 1330 return 0;
1329 } 1331 }
1330 1332
1331 if (list_empty(&cam->outqueue)) { 1333 if (list_empty(&cam->outqueue)) {
1332 if (filp->f_flags & O_NONBLOCK) { 1334 if (filp->f_flags & O_NONBLOCK) {
1333 up(&cam->fileop_sem); 1335 mutex_unlock(&cam->fileop_mutex);
1334 return -EAGAIN; 1336 return -EAGAIN;
1335 } 1337 }
1336 err = wait_event_interruptible 1338 timeout = wait_event_interruptible_timeout
1337 ( cam->wait_frame, 1339 ( cam->wait_frame,
1338 (!list_empty(&cam->outqueue)) || 1340 (!list_empty(&cam->outqueue)) ||
1339 (cam->state & DEV_DISCONNECTED) || 1341 (cam->state & DEV_DISCONNECTED) ||
1340 (cam->state & DEV_MISCONFIGURED) ); 1342 (cam->state & DEV_MISCONFIGURED),
1341 if (err) { 1343 cam->module_param.frame_timeout *
1342 up(&cam->fileop_sem); 1344 1000 * msecs_to_jiffies(1) );
1343 return err; 1345 if (timeout < 0) {
1346 mutex_unlock(&cam->fileop_mutex);
1347 return timeout;
1344 } 1348 }
1345 if (cam->state & DEV_DISCONNECTED) { 1349 if (cam->state & DEV_DISCONNECTED) {
1346 up(&cam->fileop_sem); 1350 mutex_unlock(&cam->fileop_mutex);
1347 return -ENODEV; 1351 return -ENODEV;
1348 } 1352 }
1349 if (cam->state & DEV_MISCONFIGURED) { 1353 if (!timeout || (cam->state & DEV_MISCONFIGURED)) {
1350 up(&cam->fileop_sem); 1354 mutex_unlock(&cam->fileop_mutex);
1351 return -EIO; 1355 return -EIO;
1352 } 1356 }
1353 } 1357 }
@@ -1375,7 +1379,7 @@ exit:
1375 PDBGG("Frame #%lu, bytes read: %zu", 1379 PDBGG("Frame #%lu, bytes read: %zu",
1376 (unsigned long)f->buf.index, count); 1380 (unsigned long)f->buf.index, count);
1377 1381
1378 up(&cam->fileop_sem); 1382 mutex_unlock(&cam->fileop_mutex);
1379 1383
1380 return err ? err : count; 1384 return err ? err : count;
1381} 1385}
@@ -1388,7 +1392,7 @@ static unsigned int et61x251_poll(struct file *filp, poll_table *wait)
1388 unsigned long lock_flags; 1392 unsigned long lock_flags;
1389 unsigned int mask = 0; 1393 unsigned int mask = 0;
1390 1394
1391 if (down_interruptible(&cam->fileop_sem)) 1395 if (mutex_lock_interruptible(&cam->fileop_mutex))
1392 return POLLERR; 1396 return POLLERR;
1393 1397
1394 if (cam->state & DEV_DISCONNECTED) { 1398 if (cam->state & DEV_DISCONNECTED) {
@@ -1426,12 +1430,12 @@ static unsigned int et61x251_poll(struct file *filp, poll_table *wait)
1426 if (!list_empty(&cam->outqueue)) 1430 if (!list_empty(&cam->outqueue))
1427 mask |= POLLIN | POLLRDNORM; 1431 mask |= POLLIN | POLLRDNORM;
1428 1432
1429 up(&cam->fileop_sem); 1433 mutex_unlock(&cam->fileop_mutex);
1430 1434
1431 return mask; 1435 return mask;
1432 1436
1433error: 1437error:
1434 up(&cam->fileop_sem); 1438 mutex_unlock(&cam->fileop_mutex);
1435 return POLLERR; 1439 return POLLERR;
1436} 1440}
1437 1441
@@ -1465,25 +1469,25 @@ static int et61x251_mmap(struct file* filp, struct vm_area_struct *vma)
1465 void *pos; 1469 void *pos;
1466 u32 i; 1470 u32 i;
1467 1471
1468 if (down_interruptible(&cam->fileop_sem)) 1472 if (mutex_lock_interruptible(&cam->fileop_mutex))
1469 return -ERESTARTSYS; 1473 return -ERESTARTSYS;
1470 1474
1471 if (cam->state & DEV_DISCONNECTED) { 1475 if (cam->state & DEV_DISCONNECTED) {
1472 DBG(1, "Device not present"); 1476 DBG(1, "Device not present");
1473 up(&cam->fileop_sem); 1477 mutex_unlock(&cam->fileop_mutex);
1474 return -ENODEV; 1478 return -ENODEV;
1475 } 1479 }
1476 1480
1477 if (cam->state & DEV_MISCONFIGURED) { 1481 if (cam->state & DEV_MISCONFIGURED) {
1478 DBG(1, "The camera is misconfigured. Close and open it " 1482 DBG(1, "The camera is misconfigured. Close and open it "
1479 "again."); 1483 "again.");
1480 up(&cam->fileop_sem); 1484 mutex_unlock(&cam->fileop_mutex);
1481 return -EIO; 1485 return -EIO;
1482 } 1486 }
1483 1487
1484 if (cam->io != IO_MMAP || !(vma->vm_flags & VM_WRITE) || 1488 if (cam->io != IO_MMAP || !(vma->vm_flags & VM_WRITE) ||
1485 size != PAGE_ALIGN(cam->frame[0].buf.length)) { 1489 size != PAGE_ALIGN(cam->frame[0].buf.length)) {
1486 up(&cam->fileop_sem); 1490 mutex_unlock(&cam->fileop_mutex);
1487 return -EINVAL; 1491 return -EINVAL;
1488 } 1492 }
1489 1493
@@ -1492,7 +1496,7 @@ static int et61x251_mmap(struct file* filp, struct vm_area_struct *vma)
1492 break; 1496 break;
1493 } 1497 }
1494 if (i == cam->nbuffers) { 1498 if (i == cam->nbuffers) {
1495 up(&cam->fileop_sem); 1499 mutex_unlock(&cam->fileop_mutex);
1496 return -EINVAL; 1500 return -EINVAL;
1497 } 1501 }
1498 1502
@@ -1502,7 +1506,7 @@ static int et61x251_mmap(struct file* filp, struct vm_area_struct *vma)
1502 pos = cam->frame[i].bufmem; 1506 pos = cam->frame[i].bufmem;
1503 while (size > 0) { /* size is page-aligned */ 1507 while (size > 0) { /* size is page-aligned */
1504 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) { 1508 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
1505 up(&cam->fileop_sem); 1509 mutex_unlock(&cam->fileop_mutex);
1506 return -EAGAIN; 1510 return -EAGAIN;
1507 } 1511 }
1508 start += PAGE_SIZE; 1512 start += PAGE_SIZE;
@@ -1515,7 +1519,7 @@ static int et61x251_mmap(struct file* filp, struct vm_area_struct *vma)
1515 1519
1516 et61x251_vm_open(vma); 1520 et61x251_vm_open(vma);
1517 1521
1518 up(&cam->fileop_sem); 1522 mutex_unlock(&cam->fileop_mutex);
1519 1523
1520 return 0; 1524 return 0;
1521} 1525}
@@ -1557,6 +1561,7 @@ et61x251_vidioc_enuminput(struct et61x251_device* cam, void __user * arg)
1557 1561
1558 memset(&i, 0, sizeof(i)); 1562 memset(&i, 0, sizeof(i));
1559 strcpy(i.name, "Camera"); 1563 strcpy(i.name, "Camera");
1564 i.type = V4L2_INPUT_TYPE_CAMERA;
1560 1565
1561 if (copy_to_user(arg, &i, sizeof(i))) 1566 if (copy_to_user(arg, &i, sizeof(i)))
1562 return -EFAULT; 1567 return -EFAULT;
@@ -1566,7 +1571,19 @@ et61x251_vidioc_enuminput(struct et61x251_device* cam, void __user * arg)
1566 1571
1567 1572
1568static int 1573static int
1569et61x251_vidioc_gs_input(struct et61x251_device* cam, void __user * arg) 1574et61x251_vidioc_g_input(struct et61x251_device* cam, void __user * arg)
1575{
1576 int index = 0;
1577
1578 if (copy_to_user(arg, &index, sizeof(index)))
1579 return -EFAULT;
1580
1581 return 0;
1582}
1583
1584
1585static int
1586et61x251_vidioc_s_input(struct et61x251_device* cam, void __user * arg)
1570{ 1587{
1571 int index; 1588 int index;
1572 1589
@@ -1583,7 +1600,7 @@ et61x251_vidioc_gs_input(struct et61x251_device* cam, void __user * arg)
1583static int 1600static int
1584et61x251_vidioc_query_ctrl(struct et61x251_device* cam, void __user * arg) 1601et61x251_vidioc_query_ctrl(struct et61x251_device* cam, void __user * arg)
1585{ 1602{
1586 struct et61x251_sensor* s = cam->sensor; 1603 struct et61x251_sensor* s = &cam->sensor;
1587 struct v4l2_queryctrl qc; 1604 struct v4l2_queryctrl qc;
1588 u8 i; 1605 u8 i;
1589 1606
@@ -1605,7 +1622,7 @@ et61x251_vidioc_query_ctrl(struct et61x251_device* cam, void __user * arg)
1605static int 1622static int
1606et61x251_vidioc_g_ctrl(struct et61x251_device* cam, void __user * arg) 1623et61x251_vidioc_g_ctrl(struct et61x251_device* cam, void __user * arg)
1607{ 1624{
1608 struct et61x251_sensor* s = cam->sensor; 1625 struct et61x251_sensor* s = &cam->sensor;
1609 struct v4l2_control ctrl; 1626 struct v4l2_control ctrl;
1610 int err = 0; 1627 int err = 0;
1611 u8 i; 1628 u8 i;
@@ -1637,7 +1654,7 @@ exit:
1637static int 1654static int
1638et61x251_vidioc_s_ctrl(struct et61x251_device* cam, void __user * arg) 1655et61x251_vidioc_s_ctrl(struct et61x251_device* cam, void __user * arg)
1639{ 1656{
1640 struct et61x251_sensor* s = cam->sensor; 1657 struct et61x251_sensor* s = &cam->sensor;
1641 struct v4l2_control ctrl; 1658 struct v4l2_control ctrl;
1642 u8 i; 1659 u8 i;
1643 int err = 0; 1660 int err = 0;
@@ -1650,6 +1667,8 @@ et61x251_vidioc_s_ctrl(struct et61x251_device* cam, void __user * arg)
1650 1667
1651 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++) 1668 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
1652 if (ctrl.id == s->qctrl[i].id) { 1669 if (ctrl.id == s->qctrl[i].id) {
1670 if (s->qctrl[i].flags & V4L2_CTRL_FLAG_DISABLED)
1671 return -EINVAL;
1653 if (ctrl.value < s->qctrl[i].minimum || 1672 if (ctrl.value < s->qctrl[i].minimum ||
1654 ctrl.value > s->qctrl[i].maximum) 1673 ctrl.value > s->qctrl[i].maximum)
1655 return -ERANGE; 1674 return -ERANGE;
@@ -1669,7 +1688,7 @@ et61x251_vidioc_s_ctrl(struct et61x251_device* cam, void __user * arg)
1669static int 1688static int
1670et61x251_vidioc_cropcap(struct et61x251_device* cam, void __user * arg) 1689et61x251_vidioc_cropcap(struct et61x251_device* cam, void __user * arg)
1671{ 1690{
1672 struct v4l2_cropcap* cc = &(cam->sensor->cropcap); 1691 struct v4l2_cropcap* cc = &(cam->sensor.cropcap);
1673 1692
1674 cc->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1693 cc->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1675 cc->pixelaspect.numerator = 1; 1694 cc->pixelaspect.numerator = 1;
@@ -1685,7 +1704,7 @@ et61x251_vidioc_cropcap(struct et61x251_device* cam, void __user * arg)
1685static int 1704static int
1686et61x251_vidioc_g_crop(struct et61x251_device* cam, void __user * arg) 1705et61x251_vidioc_g_crop(struct et61x251_device* cam, void __user * arg)
1687{ 1706{
1688 struct et61x251_sensor* s = cam->sensor; 1707 struct et61x251_sensor* s = &cam->sensor;
1689 struct v4l2_crop crop = { 1708 struct v4l2_crop crop = {
1690 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, 1709 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
1691 }; 1710 };
@@ -1702,7 +1721,7 @@ et61x251_vidioc_g_crop(struct et61x251_device* cam, void __user * arg)
1702static int 1721static int
1703et61x251_vidioc_s_crop(struct et61x251_device* cam, void __user * arg) 1722et61x251_vidioc_s_crop(struct et61x251_device* cam, void __user * arg)
1704{ 1723{
1705 struct et61x251_sensor* s = cam->sensor; 1724 struct et61x251_sensor* s = &cam->sensor;
1706 struct v4l2_crop crop; 1725 struct v4l2_crop crop;
1707 struct v4l2_rect* rect; 1726 struct v4l2_rect* rect;
1708 struct v4l2_rect* bounds = &(s->cropcap.bounds); 1727 struct v4l2_rect* bounds = &(s->cropcap.bounds);
@@ -1843,7 +1862,7 @@ static int
1843et61x251_vidioc_g_fmt(struct et61x251_device* cam, void __user * arg) 1862et61x251_vidioc_g_fmt(struct et61x251_device* cam, void __user * arg)
1844{ 1863{
1845 struct v4l2_format format; 1864 struct v4l2_format format;
1846 struct v4l2_pix_format* pfmt = &(cam->sensor->pix_format); 1865 struct v4l2_pix_format* pfmt = &(cam->sensor.pix_format);
1847 1866
1848 if (copy_from_user(&format, arg, sizeof(format))) 1867 if (copy_from_user(&format, arg, sizeof(format)))
1849 return -EFAULT; 1868 return -EFAULT;
@@ -1868,7 +1887,7 @@ static int
1868et61x251_vidioc_try_s_fmt(struct et61x251_device* cam, unsigned int cmd, 1887et61x251_vidioc_try_s_fmt(struct et61x251_device* cam, unsigned int cmd,
1869 void __user * arg) 1888 void __user * arg)
1870{ 1889{
1871 struct et61x251_sensor* s = cam->sensor; 1890 struct et61x251_sensor* s = &cam->sensor;
1872 struct v4l2_format format; 1891 struct v4l2_format format;
1873 struct v4l2_pix_format* pix; 1892 struct v4l2_pix_format* pix;
1874 struct v4l2_pix_format* pfmt = &(s->pix_format); 1893 struct v4l2_pix_format* pfmt = &(s->pix_format);
@@ -2155,7 +2174,7 @@ et61x251_vidioc_dqbuf(struct et61x251_device* cam, struct file* filp,
2155 struct v4l2_buffer b; 2174 struct v4l2_buffer b;
2156 struct et61x251_frame_t *f; 2175 struct et61x251_frame_t *f;
2157 unsigned long lock_flags; 2176 unsigned long lock_flags;
2158 int err = 0; 2177 long timeout;
2159 2178
2160 if (copy_from_user(&b, arg, sizeof(b))) 2179 if (copy_from_user(&b, arg, sizeof(b)))
2161 return -EFAULT; 2180 return -EFAULT;
@@ -2168,16 +2187,18 @@ et61x251_vidioc_dqbuf(struct et61x251_device* cam, struct file* filp,
2168 return -EINVAL; 2187 return -EINVAL;
2169 if (filp->f_flags & O_NONBLOCK) 2188 if (filp->f_flags & O_NONBLOCK)
2170 return -EAGAIN; 2189 return -EAGAIN;
2171 err = wait_event_interruptible 2190 timeout = wait_event_interruptible_timeout
2172 ( cam->wait_frame, 2191 ( cam->wait_frame,
2173 (!list_empty(&cam->outqueue)) || 2192 (!list_empty(&cam->outqueue)) ||
2174 (cam->state & DEV_DISCONNECTED) || 2193 (cam->state & DEV_DISCONNECTED) ||
2175 (cam->state & DEV_MISCONFIGURED) ); 2194 (cam->state & DEV_MISCONFIGURED),
2176 if (err) 2195 cam->module_param.frame_timeout *
2177 return err; 2196 1000 * msecs_to_jiffies(1) );
2197 if (timeout < 0)
2198 return timeout;
2178 if (cam->state & DEV_DISCONNECTED) 2199 if (cam->state & DEV_DISCONNECTED)
2179 return -ENODEV; 2200 return -ENODEV;
2180 if (cam->state & DEV_MISCONFIGURED) 2201 if (!timeout || (cam->state & DEV_MISCONFIGURED))
2181 return -EIO; 2202 return -EIO;
2182 } 2203 }
2183 2204
@@ -2309,8 +2330,10 @@ static int et61x251_ioctl_v4l2(struct inode* inode, struct file* filp,
2309 return et61x251_vidioc_enuminput(cam, arg); 2330 return et61x251_vidioc_enuminput(cam, arg);
2310 2331
2311 case VIDIOC_G_INPUT: 2332 case VIDIOC_G_INPUT:
2333 return et61x251_vidioc_g_input(cam, arg);
2334
2312 case VIDIOC_S_INPUT: 2335 case VIDIOC_S_INPUT:
2313 return et61x251_vidioc_gs_input(cam, arg); 2336 return et61x251_vidioc_s_input(cam, arg);
2314 2337
2315 case VIDIOC_QUERYCTRL: 2338 case VIDIOC_QUERYCTRL:
2316 return et61x251_vidioc_query_ctrl(cam, arg); 2339 return et61x251_vidioc_query_ctrl(cam, arg);
@@ -2393,19 +2416,19 @@ static int et61x251_ioctl(struct inode* inode, struct file* filp,
2393 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp)); 2416 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp));
2394 int err = 0; 2417 int err = 0;
2395 2418
2396 if (down_interruptible(&cam->fileop_sem)) 2419 if (mutex_lock_interruptible(&cam->fileop_mutex))
2397 return -ERESTARTSYS; 2420 return -ERESTARTSYS;
2398 2421
2399 if (cam->state & DEV_DISCONNECTED) { 2422 if (cam->state & DEV_DISCONNECTED) {
2400 DBG(1, "Device not present"); 2423 DBG(1, "Device not present");
2401 up(&cam->fileop_sem); 2424 mutex_unlock(&cam->fileop_mutex);
2402 return -ENODEV; 2425 return -ENODEV;
2403 } 2426 }
2404 2427
2405 if (cam->state & DEV_MISCONFIGURED) { 2428 if (cam->state & DEV_MISCONFIGURED) {
2406 DBG(1, "The camera is misconfigured. Close and open it " 2429 DBG(1, "The camera is misconfigured. Close and open it "
2407 "again."); 2430 "again.");
2408 up(&cam->fileop_sem); 2431 mutex_unlock(&cam->fileop_mutex);
2409 return -EIO; 2432 return -EIO;
2410 } 2433 }
2411 2434
@@ -2413,7 +2436,7 @@ static int et61x251_ioctl(struct inode* inode, struct file* filp,
2413 2436
2414 err = et61x251_ioctl_v4l2(inode, filp, cmd, (void __user *)arg); 2437 err = et61x251_ioctl_v4l2(inode, filp, cmd, (void __user *)arg);
2415 2438
2416 up(&cam->fileop_sem); 2439 mutex_unlock(&cam->fileop_mutex);
2417 2440
2418 return err; 2441 return err;
2419} 2442}
@@ -2459,7 +2482,7 @@ et61x251_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2459 goto fail; 2482 goto fail;
2460 } 2483 }
2461 2484
2462 init_MUTEX(&cam->dev_sem); 2485 mutex_init(&cam->dev_mutex);
2463 2486
2464 DBG(2, "ET61X[12]51 PC Camera Controller detected " 2487 DBG(2, "ET61X[12]51 PC Camera Controller detected "
2465 "(vid/pid 0x%04X/0x%04X)",id->idVendor, id->idProduct); 2488 "(vid/pid 0x%04X/0x%04X)",id->idVendor, id->idProduct);
@@ -2470,8 +2493,8 @@ et61x251_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2470 break; 2493 break;
2471 } 2494 }
2472 2495
2473 if (!err && cam->sensor) 2496 if (!err)
2474 DBG(2, "%s image sensor detected", cam->sensor->name); 2497 DBG(2, "%s image sensor detected", cam->sensor.name);
2475 else { 2498 else {
2476 DBG(1, "No supported image sensor detected"); 2499 DBG(1, "No supported image sensor detected");
2477 err = -ENODEV; 2500 err = -ENODEV;
@@ -2492,7 +2515,7 @@ et61x251_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2492 cam->v4ldev->release = video_device_release; 2515 cam->v4ldev->release = video_device_release;
2493 video_set_drvdata(cam->v4ldev, cam); 2516 video_set_drvdata(cam->v4ldev, cam);
2494 2517
2495 down(&cam->dev_sem); 2518 mutex_lock(&cam->dev_mutex);
2496 2519
2497 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER, 2520 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
2498 video_nr[dev_nr]); 2521 video_nr[dev_nr]);
@@ -2502,13 +2525,14 @@ et61x251_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2502 DBG(1, "Free /dev/videoX node not found"); 2525 DBG(1, "Free /dev/videoX node not found");
2503 video_nr[dev_nr] = -1; 2526 video_nr[dev_nr] = -1;
2504 dev_nr = (dev_nr < ET61X251_MAX_DEVICES-1) ? dev_nr+1 : 0; 2527 dev_nr = (dev_nr < ET61X251_MAX_DEVICES-1) ? dev_nr+1 : 0;
2505 up(&cam->dev_sem); 2528 mutex_unlock(&cam->dev_mutex);
2506 goto fail; 2529 goto fail;
2507 } 2530 }
2508 2531
2509 DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->minor); 2532 DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->minor);
2510 2533
2511 cam->module_param.force_munmap = force_munmap[dev_nr]; 2534 cam->module_param.force_munmap = force_munmap[dev_nr];
2535 cam->module_param.frame_timeout = frame_timeout[dev_nr];
2512 2536
2513 dev_nr = (dev_nr < ET61X251_MAX_DEVICES-1) ? dev_nr+1 : 0; 2537 dev_nr = (dev_nr < ET61X251_MAX_DEVICES-1) ? dev_nr+1 : 0;
2514 2538
@@ -2519,7 +2543,7 @@ et61x251_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2519 2543
2520 usb_set_intfdata(intf, cam); 2544 usb_set_intfdata(intf, cam);
2521 2545
2522 up(&cam->dev_sem); 2546 mutex_unlock(&cam->dev_mutex);
2523 2547
2524 return 0; 2548 return 0;
2525 2549
@@ -2543,7 +2567,7 @@ static void et61x251_usb_disconnect(struct usb_interface* intf)
2543 2567
2544 down_write(&et61x251_disconnect); 2568 down_write(&et61x251_disconnect);
2545 2569
2546 down(&cam->dev_sem); 2570 mutex_lock(&cam->dev_mutex);
2547 2571
2548 DBG(2, "Disconnecting %s...", cam->v4ldev->name); 2572 DBG(2, "Disconnecting %s...", cam->v4ldev->name);
2549 2573
@@ -2557,13 +2581,14 @@ static void et61x251_usb_disconnect(struct usb_interface* intf)
2557 et61x251_stop_transfer(cam); 2581 et61x251_stop_transfer(cam);
2558 cam->state |= DEV_DISCONNECTED; 2582 cam->state |= DEV_DISCONNECTED;
2559 wake_up_interruptible(&cam->wait_frame); 2583 wake_up_interruptible(&cam->wait_frame);
2560 wake_up_interruptible(&cam->wait_stream); 2584 wake_up(&cam->wait_stream);
2585 usb_get_dev(cam->usbdev);
2561 } else { 2586 } else {
2562 cam->state |= DEV_DISCONNECTED; 2587 cam->state |= DEV_DISCONNECTED;
2563 et61x251_release_resources(cam); 2588 et61x251_release_resources(cam);
2564 } 2589 }
2565 2590
2566 up(&cam->dev_sem); 2591 mutex_unlock(&cam->dev_mutex);
2567 2592
2568 if (!cam->users) 2593 if (!cam->users)
2569 kfree(cam); 2594 kfree(cam);
diff --git a/drivers/usb/media/et61x251_sensor.h b/drivers/usb/media/et61x251_sensor.h
index b9df91062fc0..56841ae8a207 100644
--- a/drivers/usb/media/et61x251_sensor.h
+++ b/drivers/usb/media/et61x251_sensor.h
@@ -42,6 +42,9 @@ static int (*et61x251_sensor_table[])(struct et61x251_device*) = { \
42 NULL, \ 42 NULL, \
43}; 43};
44 44
45extern struct et61x251_device*
46et61x251_match_id(struct et61x251_device* cam, const struct usb_device_id *id);
47
45extern void 48extern void
46et61x251_attach_sensor(struct et61x251_device* cam, 49et61x251_attach_sensor(struct et61x251_device* cam,
47 struct et61x251_sensor* sensor); 50 struct et61x251_sensor* sensor);
@@ -105,8 +108,6 @@ struct et61x251_sensor {
105 int (*set_pix_format)(struct et61x251_device* cam, 108 int (*set_pix_format)(struct et61x251_device* cam,
106 const struct v4l2_pix_format* pix); 109 const struct v4l2_pix_format* pix);
107 110
108 const struct usb_device* usbdev;
109
110 /* Private */ 111 /* Private */
111 struct v4l2_queryctrl _qctrl[ET61X251_MAX_CTRLS]; 112 struct v4l2_queryctrl _qctrl[ET61X251_MAX_CTRLS];
112 struct v4l2_rect _rect; 113 struct v4l2_rect _rect;
diff --git a/drivers/usb/media/et61x251_tas5130d1b.c b/drivers/usb/media/et61x251_tas5130d1b.c
index 65f1ae9cf2b3..3998d76a307a 100644
--- a/drivers/usb/media/et61x251_tas5130d1b.c
+++ b/drivers/usb/media/et61x251_tas5130d1b.c
@@ -126,12 +126,16 @@ static struct et61x251_sensor tas5130d1b = {
126 126
127int et61x251_probe_tas5130d1b(struct et61x251_device* cam) 127int et61x251_probe_tas5130d1b(struct et61x251_device* cam)
128{ 128{
129 /* This sensor has no identifiers, so let's attach it anyway */ 129 const struct usb_device_id tas5130d1b_id_table[] = {
130 et61x251_attach_sensor(cam, &tas5130d1b); 130 { USB_DEVICE(0x102c, 0x6251), },
131 { }
132 };
131 133
132 /* Sensor detection is based on USB pid/vid */ 134 /* Sensor detection is based on USB pid/vid */
133 if (le16_to_cpu(tas5130d1b.usbdev->descriptor.idProduct) != 0x6251) 135 if (!et61x251_match_id(cam, tas5130d1b_id_table))
134 return -ENODEV; 136 return -ENODEV;
135 137
138 et61x251_attach_sensor(cam, &tas5130d1b);
139
136 return 0; 140 return 0;
137} 141}
diff --git a/drivers/usb/media/ov511.c b/drivers/usb/media/ov511.c
index 51e9cc06f7e3..da44579d6f29 100644
--- a/drivers/usb/media/ov511.c
+++ b/drivers/usb/media/ov511.c
@@ -365,14 +365,14 @@ reg_w(struct usb_ov511 *ov, unsigned char reg, unsigned char value)
365 365
366 PDEBUG(5, "0x%02X:0x%02X", reg, value); 366 PDEBUG(5, "0x%02X:0x%02X", reg, value);
367 367
368 down(&ov->cbuf_lock); 368 mutex_lock(&ov->cbuf_lock);
369 ov->cbuf[0] = value; 369 ov->cbuf[0] = value;
370 rc = usb_control_msg(ov->dev, 370 rc = usb_control_msg(ov->dev,
371 usb_sndctrlpipe(ov->dev, 0), 371 usb_sndctrlpipe(ov->dev, 0),
372 (ov->bclass == BCL_OV518)?1:2 /* REG_IO */, 372 (ov->bclass == BCL_OV518)?1:2 /* REG_IO */,
373 USB_TYPE_VENDOR | USB_RECIP_DEVICE, 373 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
374 0, (__u16)reg, &ov->cbuf[0], 1, 1000); 374 0, (__u16)reg, &ov->cbuf[0], 1, 1000);
375 up(&ov->cbuf_lock); 375 mutex_unlock(&ov->cbuf_lock);
376 376
377 if (rc < 0) 377 if (rc < 0)
378 err("reg write: error %d: %s", rc, symbolic(urb_errlist, rc)); 378 err("reg write: error %d: %s", rc, symbolic(urb_errlist, rc));
@@ -387,7 +387,7 @@ reg_r(struct usb_ov511 *ov, unsigned char reg)
387{ 387{
388 int rc; 388 int rc;
389 389
390 down(&ov->cbuf_lock); 390 mutex_lock(&ov->cbuf_lock);
391 rc = usb_control_msg(ov->dev, 391 rc = usb_control_msg(ov->dev,
392 usb_rcvctrlpipe(ov->dev, 0), 392 usb_rcvctrlpipe(ov->dev, 0),
393 (ov->bclass == BCL_OV518)?1:3 /* REG_IO */, 393 (ov->bclass == BCL_OV518)?1:3 /* REG_IO */,
@@ -401,7 +401,7 @@ reg_r(struct usb_ov511 *ov, unsigned char reg)
401 PDEBUG(5, "0x%02X:0x%02X", reg, ov->cbuf[0]); 401 PDEBUG(5, "0x%02X:0x%02X", reg, ov->cbuf[0]);
402 } 402 }
403 403
404 up(&ov->cbuf_lock); 404 mutex_unlock(&ov->cbuf_lock);
405 405
406 return rc; 406 return rc;
407} 407}
@@ -444,7 +444,7 @@ ov518_reg_w32(struct usb_ov511 *ov, unsigned char reg, u32 val, int n)
444 444
445 PDEBUG(5, "0x%02X:%7d, n=%d", reg, val, n); 445 PDEBUG(5, "0x%02X:%7d, n=%d", reg, val, n);
446 446
447 down(&ov->cbuf_lock); 447 mutex_lock(&ov->cbuf_lock);
448 448
449 *((__le32 *)ov->cbuf) = __cpu_to_le32(val); 449 *((__le32 *)ov->cbuf) = __cpu_to_le32(val);
450 450
@@ -453,7 +453,7 @@ ov518_reg_w32(struct usb_ov511 *ov, unsigned char reg, u32 val, int n)
453 1 /* REG_IO */, 453 1 /* REG_IO */,
454 USB_TYPE_VENDOR | USB_RECIP_DEVICE, 454 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
455 0, (__u16)reg, ov->cbuf, n, 1000); 455 0, (__u16)reg, ov->cbuf, n, 1000);
456 up(&ov->cbuf_lock); 456 mutex_unlock(&ov->cbuf_lock);
457 457
458 if (rc < 0) 458 if (rc < 0)
459 err("reg write multiple: error %d: %s", rc, 459 err("reg write multiple: error %d: %s", rc,
@@ -768,14 +768,14 @@ i2c_r(struct usb_ov511 *ov, unsigned char reg)
768{ 768{
769 int rc; 769 int rc;
770 770
771 down(&ov->i2c_lock); 771 mutex_lock(&ov->i2c_lock);
772 772
773 if (ov->bclass == BCL_OV518) 773 if (ov->bclass == BCL_OV518)
774 rc = ov518_i2c_read_internal(ov, reg); 774 rc = ov518_i2c_read_internal(ov, reg);
775 else 775 else
776 rc = ov511_i2c_read_internal(ov, reg); 776 rc = ov511_i2c_read_internal(ov, reg);
777 777
778 up(&ov->i2c_lock); 778 mutex_unlock(&ov->i2c_lock);
779 779
780 return rc; 780 return rc;
781} 781}
@@ -785,14 +785,14 @@ i2c_w(struct usb_ov511 *ov, unsigned char reg, unsigned char value)
785{ 785{
786 int rc; 786 int rc;
787 787
788 down(&ov->i2c_lock); 788 mutex_lock(&ov->i2c_lock);
789 789
790 if (ov->bclass == BCL_OV518) 790 if (ov->bclass == BCL_OV518)
791 rc = ov518_i2c_write_internal(ov, reg, value); 791 rc = ov518_i2c_write_internal(ov, reg, value);
792 else 792 else
793 rc = ov511_i2c_write_internal(ov, reg, value); 793 rc = ov511_i2c_write_internal(ov, reg, value);
794 794
795 up(&ov->i2c_lock); 795 mutex_unlock(&ov->i2c_lock);
796 796
797 return rc; 797 return rc;
798} 798}
@@ -842,9 +842,9 @@ i2c_w_mask(struct usb_ov511 *ov,
842{ 842{
843 int rc; 843 int rc;
844 844
845 down(&ov->i2c_lock); 845 mutex_lock(&ov->i2c_lock);
846 rc = ov51x_i2c_write_mask_internal(ov, reg, value, mask); 846 rc = ov51x_i2c_write_mask_internal(ov, reg, value, mask);
847 up(&ov->i2c_lock); 847 mutex_unlock(&ov->i2c_lock);
848 848
849 return rc; 849 return rc;
850} 850}
@@ -880,7 +880,7 @@ i2c_w_slave(struct usb_ov511 *ov,
880{ 880{
881 int rc = 0; 881 int rc = 0;
882 882
883 down(&ov->i2c_lock); 883 mutex_lock(&ov->i2c_lock);
884 884
885 /* Set new slave IDs */ 885 /* Set new slave IDs */
886 rc = i2c_set_slave_internal(ov, slave); 886 rc = i2c_set_slave_internal(ov, slave);
@@ -894,7 +894,7 @@ out:
894 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0) 894 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0)
895 err("Couldn't restore primary I2C slave"); 895 err("Couldn't restore primary I2C slave");
896 896
897 up(&ov->i2c_lock); 897 mutex_unlock(&ov->i2c_lock);
898 return rc; 898 return rc;
899} 899}
900 900
@@ -906,7 +906,7 @@ i2c_r_slave(struct usb_ov511 *ov,
906{ 906{
907 int rc; 907 int rc;
908 908
909 down(&ov->i2c_lock); 909 mutex_lock(&ov->i2c_lock);
910 910
911 /* Set new slave IDs */ 911 /* Set new slave IDs */
912 rc = i2c_set_slave_internal(ov, slave); 912 rc = i2c_set_slave_internal(ov, slave);
@@ -923,7 +923,7 @@ out:
923 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0) 923 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0)
924 err("Couldn't restore primary I2C slave"); 924 err("Couldn't restore primary I2C slave");
925 925
926 up(&ov->i2c_lock); 926 mutex_unlock(&ov->i2c_lock);
927 return rc; 927 return rc;
928} 928}
929 929
@@ -933,7 +933,7 @@ ov51x_set_slave_ids(struct usb_ov511 *ov, unsigned char sid)
933{ 933{
934 int rc; 934 int rc;
935 935
936 down(&ov->i2c_lock); 936 mutex_lock(&ov->i2c_lock);
937 937
938 rc = i2c_set_slave_internal(ov, sid); 938 rc = i2c_set_slave_internal(ov, sid);
939 if (rc < 0) 939 if (rc < 0)
@@ -942,7 +942,7 @@ ov51x_set_slave_ids(struct usb_ov511 *ov, unsigned char sid)
942 // FIXME: Is this actually necessary? 942 // FIXME: Is this actually necessary?
943 rc = ov51x_reset(ov, OV511_RESET_NOREGS); 943 rc = ov51x_reset(ov, OV511_RESET_NOREGS);
944out: 944out:
945 up(&ov->i2c_lock); 945 mutex_unlock(&ov->i2c_lock);
946 return rc; 946 return rc;
947} 947}
948 948
@@ -3832,7 +3832,7 @@ ov51x_alloc(struct usb_ov511 *ov)
3832 const int raw_bufsize = OV511_NUMFRAMES * MAX_RAW_DATA_SIZE(w, h); 3832 const int raw_bufsize = OV511_NUMFRAMES * MAX_RAW_DATA_SIZE(w, h);
3833 3833
3834 PDEBUG(4, "entered"); 3834 PDEBUG(4, "entered");
3835 down(&ov->buf_lock); 3835 mutex_lock(&ov->buf_lock);
3836 3836
3837 if (ov->buf_state == BUF_ALLOCATED) 3837 if (ov->buf_state == BUF_ALLOCATED)
3838 goto out; 3838 goto out;
@@ -3879,12 +3879,12 @@ ov51x_alloc(struct usb_ov511 *ov)
3879 3879
3880 ov->buf_state = BUF_ALLOCATED; 3880 ov->buf_state = BUF_ALLOCATED;
3881out: 3881out:
3882 up(&ov->buf_lock); 3882 mutex_unlock(&ov->buf_lock);
3883 PDEBUG(4, "leaving"); 3883 PDEBUG(4, "leaving");
3884 return 0; 3884 return 0;
3885error: 3885error:
3886 ov51x_do_dealloc(ov); 3886 ov51x_do_dealloc(ov);
3887 up(&ov->buf_lock); 3887 mutex_unlock(&ov->buf_lock);
3888 PDEBUG(4, "errored"); 3888 PDEBUG(4, "errored");
3889 return -ENOMEM; 3889 return -ENOMEM;
3890} 3890}
@@ -3893,9 +3893,9 @@ static void
3893ov51x_dealloc(struct usb_ov511 *ov) 3893ov51x_dealloc(struct usb_ov511 *ov)
3894{ 3894{
3895 PDEBUG(4, "entered"); 3895 PDEBUG(4, "entered");
3896 down(&ov->buf_lock); 3896 mutex_lock(&ov->buf_lock);
3897 ov51x_do_dealloc(ov); 3897 ov51x_do_dealloc(ov);
3898 up(&ov->buf_lock); 3898 mutex_unlock(&ov->buf_lock);
3899 PDEBUG(4, "leaving"); 3899 PDEBUG(4, "leaving");
3900} 3900}
3901 3901
@@ -3914,7 +3914,7 @@ ov51x_v4l1_open(struct inode *inode, struct file *file)
3914 3914
3915 PDEBUG(4, "opening"); 3915 PDEBUG(4, "opening");
3916 3916
3917 down(&ov->lock); 3917 mutex_lock(&ov->lock);
3918 3918
3919 err = -EBUSY; 3919 err = -EBUSY;
3920 if (ov->user) 3920 if (ov->user)
@@ -3958,7 +3958,7 @@ ov51x_v4l1_open(struct inode *inode, struct file *file)
3958 ov51x_led_control(ov, 1); 3958 ov51x_led_control(ov, 1);
3959 3959
3960out: 3960out:
3961 up(&ov->lock); 3961 mutex_unlock(&ov->lock);
3962 return err; 3962 return err;
3963} 3963}
3964 3964
@@ -3970,7 +3970,7 @@ ov51x_v4l1_close(struct inode *inode, struct file *file)
3970 3970
3971 PDEBUG(4, "ov511_close"); 3971 PDEBUG(4, "ov511_close");
3972 3972
3973 down(&ov->lock); 3973 mutex_lock(&ov->lock);
3974 3974
3975 ov->user--; 3975 ov->user--;
3976 ov51x_stop_isoc(ov); 3976 ov51x_stop_isoc(ov);
@@ -3981,15 +3981,15 @@ ov51x_v4l1_close(struct inode *inode, struct file *file)
3981 if (ov->dev) 3981 if (ov->dev)
3982 ov51x_dealloc(ov); 3982 ov51x_dealloc(ov);
3983 3983
3984 up(&ov->lock); 3984 mutex_unlock(&ov->lock);
3985 3985
3986 /* Device unplugged while open. Only a minimum of unregistration is done 3986 /* Device unplugged while open. Only a minimum of unregistration is done
3987 * here; the disconnect callback already did the rest. */ 3987 * here; the disconnect callback already did the rest. */
3988 if (!ov->dev) { 3988 if (!ov->dev) {
3989 down(&ov->cbuf_lock); 3989 mutex_lock(&ov->cbuf_lock);
3990 kfree(ov->cbuf); 3990 kfree(ov->cbuf);
3991 ov->cbuf = NULL; 3991 ov->cbuf = NULL;
3992 up(&ov->cbuf_lock); 3992 mutex_unlock(&ov->cbuf_lock);
3993 3993
3994 ov51x_dealloc(ov); 3994 ov51x_dealloc(ov);
3995 kfree(ov); 3995 kfree(ov);
@@ -4449,12 +4449,12 @@ ov51x_v4l1_ioctl(struct inode *inode, struct file *file,
4449 struct usb_ov511 *ov = video_get_drvdata(vdev); 4449 struct usb_ov511 *ov = video_get_drvdata(vdev);
4450 int rc; 4450 int rc;
4451 4451
4452 if (down_interruptible(&ov->lock)) 4452 if (mutex_lock_interruptible(&ov->lock))
4453 return -EINTR; 4453 return -EINTR;
4454 4454
4455 rc = video_usercopy(inode, file, cmd, arg, ov51x_v4l1_ioctl_internal); 4455 rc = video_usercopy(inode, file, cmd, arg, ov51x_v4l1_ioctl_internal);
4456 4456
4457 up(&ov->lock); 4457 mutex_unlock(&ov->lock);
4458 return rc; 4458 return rc;
4459} 4459}
4460 4460
@@ -4468,7 +4468,7 @@ ov51x_v4l1_read(struct file *file, char __user *buf, size_t cnt, loff_t *ppos)
4468 int i, rc = 0, frmx = -1; 4468 int i, rc = 0, frmx = -1;
4469 struct ov511_frame *frame; 4469 struct ov511_frame *frame;
4470 4470
4471 if (down_interruptible(&ov->lock)) 4471 if (mutex_lock_interruptible(&ov->lock))
4472 return -EINTR; 4472 return -EINTR;
4473 4473
4474 PDEBUG(4, "%ld bytes, noblock=%d", count, noblock); 4474 PDEBUG(4, "%ld bytes, noblock=%d", count, noblock);
@@ -4604,11 +4604,11 @@ restart:
4604 4604
4605 PDEBUG(4, "read finished, returning %ld (sweet)", count); 4605 PDEBUG(4, "read finished, returning %ld (sweet)", count);
4606 4606
4607 up(&ov->lock); 4607 mutex_unlock(&ov->lock);
4608 return count; 4608 return count;
4609 4609
4610error: 4610error:
4611 up(&ov->lock); 4611 mutex_unlock(&ov->lock);
4612 return rc; 4612 return rc;
4613} 4613}
4614 4614
@@ -4631,14 +4631,14 @@ ov51x_v4l1_mmap(struct file *file, struct vm_area_struct *vma)
4631 + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)))) 4631 + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))))
4632 return -EINVAL; 4632 return -EINVAL;
4633 4633
4634 if (down_interruptible(&ov->lock)) 4634 if (mutex_lock_interruptible(&ov->lock))
4635 return -EINTR; 4635 return -EINTR;
4636 4636
4637 pos = (unsigned long)ov->fbuf; 4637 pos = (unsigned long)ov->fbuf;
4638 while (size > 0) { 4638 while (size > 0) {
4639 page = vmalloc_to_pfn((void *)pos); 4639 page = vmalloc_to_pfn((void *)pos);
4640 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) { 4640 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
4641 up(&ov->lock); 4641 mutex_unlock(&ov->lock);
4642 return -EAGAIN; 4642 return -EAGAIN;
4643 } 4643 }
4644 start += PAGE_SIZE; 4644 start += PAGE_SIZE;
@@ -4649,7 +4649,7 @@ ov51x_v4l1_mmap(struct file *file, struct vm_area_struct *vma)
4649 size = 0; 4649 size = 0;
4650 } 4650 }
4651 4651
4652 up(&ov->lock); 4652 mutex_unlock(&ov->lock);
4653 return 0; 4653 return 0;
4654} 4654}
4655 4655
@@ -5639,7 +5639,7 @@ static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
5639static ssize_t show_exposure(struct class_device *cd, char *buf) 5639static ssize_t show_exposure(struct class_device *cd, char *buf)
5640{ 5640{
5641 struct usb_ov511 *ov = cd_to_ov(cd); 5641 struct usb_ov511 *ov = cd_to_ov(cd);
5642 unsigned char exp; 5642 unsigned char exp = 0;
5643 5643
5644 if (!ov->dev) 5644 if (!ov->dev)
5645 return -ENODEV; 5645 return -ENODEV;
@@ -5686,13 +5686,11 @@ ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
5686 if (idesc->bInterfaceSubClass != 0x00) 5686 if (idesc->bInterfaceSubClass != 0x00)
5687 return -ENODEV; 5687 return -ENODEV;
5688 5688
5689 if ((ov = kmalloc(sizeof(*ov), GFP_KERNEL)) == NULL) { 5689 if ((ov = kzalloc(sizeof(*ov), GFP_KERNEL)) == NULL) {
5690 err("couldn't kmalloc ov struct"); 5690 err("couldn't kmalloc ov struct");
5691 goto error_out; 5691 goto error_out;
5692 } 5692 }
5693 5693
5694 memset(ov, 0, sizeof(*ov));
5695
5696 ov->dev = dev; 5694 ov->dev = dev;
5697 ov->iface = idesc->bInterfaceNumber; 5695 ov->iface = idesc->bInterfaceNumber;
5698 ov->led_policy = led; 5696 ov->led_policy = led;
@@ -5738,11 +5736,10 @@ ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
5738 5736
5739 init_waitqueue_head(&ov->wq); 5737 init_waitqueue_head(&ov->wq);
5740 5738
5741 init_MUTEX(&ov->lock); /* to 1 == available */ 5739 mutex_init(&ov->lock); /* to 1 == available */
5742 init_MUTEX(&ov->buf_lock); 5740 mutex_init(&ov->buf_lock);
5743 init_MUTEX(&ov->param_lock); 5741 mutex_init(&ov->i2c_lock);
5744 init_MUTEX(&ov->i2c_lock); 5742 mutex_init(&ov->cbuf_lock);
5745 init_MUTEX(&ov->cbuf_lock);
5746 5743
5747 ov->buf_state = BUF_NOT_ALLOCATED; 5744 ov->buf_state = BUF_NOT_ALLOCATED;
5748 5745
@@ -5833,10 +5830,10 @@ error:
5833 } 5830 }
5834 5831
5835 if (ov->cbuf) { 5832 if (ov->cbuf) {
5836 down(&ov->cbuf_lock); 5833 mutex_lock(&ov->cbuf_lock);
5837 kfree(ov->cbuf); 5834 kfree(ov->cbuf);
5838 ov->cbuf = NULL; 5835 ov->cbuf = NULL;
5839 up(&ov->cbuf_lock); 5836 mutex_unlock(&ov->cbuf_lock);
5840 } 5837 }
5841 5838
5842 kfree(ov); 5839 kfree(ov);
@@ -5881,10 +5878,10 @@ ov51x_disconnect(struct usb_interface *intf)
5881 5878
5882 /* Free the memory */ 5879 /* Free the memory */
5883 if (ov && !ov->user) { 5880 if (ov && !ov->user) {
5884 down(&ov->cbuf_lock); 5881 mutex_lock(&ov->cbuf_lock);
5885 kfree(ov->cbuf); 5882 kfree(ov->cbuf);
5886 ov->cbuf = NULL; 5883 ov->cbuf = NULL;
5887 up(&ov->cbuf_lock); 5884 mutex_unlock(&ov->cbuf_lock);
5888 5885
5889 ov51x_dealloc(ov); 5886 ov51x_dealloc(ov);
5890 kfree(ov); 5887 kfree(ov);
diff --git a/drivers/usb/media/ov511.h b/drivers/usb/media/ov511.h
index 086509a137c6..bce9b3633889 100644
--- a/drivers/usb/media/ov511.h
+++ b/drivers/usb/media/ov511.h
@@ -5,6 +5,7 @@
5#include <linux/videodev.h> 5#include <linux/videodev.h>
6#include <linux/smp_lock.h> 6#include <linux/smp_lock.h>
7#include <linux/usb.h> 7#include <linux/usb.h>
8#include <linux/mutex.h>
8 9
9#define OV511_DEBUG /* Turn on debug messages */ 10#define OV511_DEBUG /* Turn on debug messages */
10 11
@@ -435,7 +436,7 @@ struct usb_ov511 {
435 436
436 int led_policy; /* LED: off|on|auto; OV511+ only */ 437 int led_policy; /* LED: off|on|auto; OV511+ only */
437 438
438 struct semaphore lock; /* Serializes user-accessible operations */ 439 struct mutex lock; /* Serializes user-accessible operations */
439 int user; /* user count for exclusive use */ 440 int user; /* user count for exclusive use */
440 441
441 int streaming; /* Are we streaming Isochronous? */ 442 int streaming; /* Are we streaming Isochronous? */
@@ -473,11 +474,9 @@ struct usb_ov511 {
473 int packet_size; /* Frame size per isoc desc */ 474 int packet_size; /* Frame size per isoc desc */
474 int packet_numbering; /* Is ISO frame numbering enabled? */ 475 int packet_numbering; /* Is ISO frame numbering enabled? */
475 476
476 struct semaphore param_lock; /* params lock for this camera */
477
478 /* Framebuffer/sbuf management */ 477 /* Framebuffer/sbuf management */
479 int buf_state; 478 int buf_state;
480 struct semaphore buf_lock; 479 struct mutex buf_lock;
481 480
482 struct ov51x_decomp_ops *decomp_ops; 481 struct ov51x_decomp_ops *decomp_ops;
483 482
@@ -494,12 +493,12 @@ struct usb_ov511 {
494 int pal; /* Device is designed for PAL resolution */ 493 int pal; /* Device is designed for PAL resolution */
495 494
496 /* I2C interface */ 495 /* I2C interface */
497 struct semaphore i2c_lock; /* Protect I2C controller regs */ 496 struct mutex i2c_lock; /* Protect I2C controller regs */
498 unsigned char primary_i2c_slave; /* I2C write id of sensor */ 497 unsigned char primary_i2c_slave; /* I2C write id of sensor */
499 498
500 /* Control transaction stuff */ 499 /* Control transaction stuff */
501 unsigned char *cbuf; /* Buffer for payload */ 500 unsigned char *cbuf; /* Buffer for payload */
502 struct semaphore cbuf_lock; 501 struct mutex cbuf_lock;
503}; 502};
504 503
505/* Used to represent a list of values and their respective symbolic names */ 504/* Used to represent a list of values and their respective symbolic names */
diff --git a/drivers/usb/media/pwc/pwc-ctrl.c b/drivers/usb/media/pwc/pwc-ctrl.c
index 3ebb6e9cdf92..0398b812e0ce 100644
--- a/drivers/usb/media/pwc/pwc-ctrl.c
+++ b/drivers/usb/media/pwc/pwc-ctrl.c
@@ -41,7 +41,6 @@
41#include <asm/uaccess.h> 41#include <asm/uaccess.h>
42#endif 42#endif
43#include <asm/errno.h> 43#include <asm/errno.h>
44#include <linux/version.h>
45 44
46#include "pwc.h" 45#include "pwc.h"
47#include "pwc-ioctl.h" 46#include "pwc-ioctl.h"
diff --git a/drivers/usb/media/pwc/pwc-if.c b/drivers/usb/media/pwc/pwc-if.c
index 4f9b0dc6fd7b..90eb26042817 100644
--- a/drivers/usb/media/pwc/pwc-if.c
+++ b/drivers/usb/media/pwc/pwc-if.c
@@ -62,7 +62,6 @@
62#include <linux/poll.h> 62#include <linux/poll.h>
63#include <linux/slab.h> 63#include <linux/slab.h>
64#include <linux/vmalloc.h> 64#include <linux/vmalloc.h>
65#include <linux/version.h>
66#include <asm/io.h> 65#include <asm/io.h>
67 66
68#include "pwc.h" 67#include "pwc.h"
@@ -827,13 +826,10 @@ static int pwc_isoc_init(struct pwc_device *pdev)
827 /* Get the current alternate interface, adjust packet size */ 826 /* Get the current alternate interface, adjust packet size */
828 if (!udev->actconfig) 827 if (!udev->actconfig)
829 return -EFAULT; 828 return -EFAULT;
830#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,5) 829
831 idesc = &udev->actconfig->interface[0]->altsetting[pdev->valternate];
832#else
833 intf = usb_ifnum_to_if(udev, 0); 830 intf = usb_ifnum_to_if(udev, 0);
834 if (intf) 831 if (intf)
835 idesc = usb_altnum_to_altsetting(intf, pdev->valternate); 832 idesc = usb_altnum_to_altsetting(intf, pdev->valternate);
836#endif
837 833
838 if (!idesc) 834 if (!idesc)
839 return -EFAULT; 835 return -EFAULT;
@@ -1871,12 +1867,11 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1871 Info("Warning: more than 1 configuration available.\n"); 1867 Info("Warning: more than 1 configuration available.\n");
1872 1868
1873 /* Allocate structure, initialize pointers, mutexes, etc. and link it to the usb_device */ 1869 /* Allocate structure, initialize pointers, mutexes, etc. and link it to the usb_device */
1874 pdev = kmalloc(sizeof(struct pwc_device), GFP_KERNEL); 1870 pdev = kzalloc(sizeof(struct pwc_device), GFP_KERNEL);
1875 if (pdev == NULL) { 1871 if (pdev == NULL) {
1876 Err("Oops, could not allocate memory for pwc_device.\n"); 1872 Err("Oops, could not allocate memory for pwc_device.\n");
1877 return -ENOMEM; 1873 return -ENOMEM;
1878 } 1874 }
1879 memset(pdev, 0, sizeof(struct pwc_device));
1880 pdev->type = type_id; 1875 pdev->type = type_id;
1881 pdev->vsize = default_size; 1876 pdev->vsize = default_size;
1882 pdev->vframes = default_fps; 1877 pdev->vframes = default_fps;
diff --git a/drivers/usb/media/se401.c b/drivers/usb/media/se401.c
index 2ba562285fda..f03ea7f89596 100644
--- a/drivers/usb/media/se401.c
+++ b/drivers/usb/media/se401.c
@@ -1157,21 +1157,21 @@ static int se401_mmap(struct file *file, struct vm_area_struct *vma)
1157 unsigned long size = vma->vm_end-vma->vm_start; 1157 unsigned long size = vma->vm_end-vma->vm_start;
1158 unsigned long page, pos; 1158 unsigned long page, pos;
1159 1159
1160 down(&se401->lock); 1160 mutex_lock(&se401->lock);
1161 1161
1162 if (se401->dev == NULL) { 1162 if (se401->dev == NULL) {
1163 up(&se401->lock); 1163 mutex_unlock(&se401->lock);
1164 return -EIO; 1164 return -EIO;
1165 } 1165 }
1166 if (size > (((SE401_NUMFRAMES * se401->maxframesize) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))) { 1166 if (size > (((SE401_NUMFRAMES * se401->maxframesize) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))) {
1167 up(&se401->lock); 1167 mutex_unlock(&se401->lock);
1168 return -EINVAL; 1168 return -EINVAL;
1169 } 1169 }
1170 pos = (unsigned long)se401->fbuf; 1170 pos = (unsigned long)se401->fbuf;
1171 while (size > 0) { 1171 while (size > 0) {
1172 page = vmalloc_to_pfn((void *)pos); 1172 page = vmalloc_to_pfn((void *)pos);
1173 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) { 1173 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
1174 up(&se401->lock); 1174 mutex_unlock(&se401->lock);
1175 return -EAGAIN; 1175 return -EAGAIN;
1176 } 1176 }
1177 start += PAGE_SIZE; 1177 start += PAGE_SIZE;
@@ -1181,7 +1181,7 @@ static int se401_mmap(struct file *file, struct vm_area_struct *vma)
1181 else 1181 else
1182 size = 0; 1182 size = 0;
1183 } 1183 }
1184 up(&se401->lock); 1184 mutex_unlock(&se401->lock);
1185 1185
1186 return 0; 1186 return 0;
1187} 1187}
@@ -1345,13 +1345,11 @@ static int se401_probe(struct usb_interface *intf,
1345 /* We found one */ 1345 /* We found one */
1346 info("SE401 camera found: %s", camera_name); 1346 info("SE401 camera found: %s", camera_name);
1347 1347
1348 if ((se401 = kmalloc(sizeof(*se401), GFP_KERNEL)) == NULL) { 1348 if ((se401 = kzalloc(sizeof(*se401), GFP_KERNEL)) == NULL) {
1349 err("couldn't kmalloc se401 struct"); 1349 err("couldn't kmalloc se401 struct");
1350 return -ENOMEM; 1350 return -ENOMEM;
1351 } 1351 }
1352 1352
1353 memset(se401, 0, sizeof(*se401));
1354
1355 se401->dev = dev; 1353 se401->dev = dev;
1356 se401->iface = interface->bInterfaceNumber; 1354 se401->iface = interface->bInterfaceNumber;
1357 se401->camera_name = camera_name; 1355 se401->camera_name = camera_name;
@@ -1366,7 +1364,7 @@ static int se401_probe(struct usb_interface *intf,
1366 memcpy(&se401->vdev, &se401_template, sizeof(se401_template)); 1364 memcpy(&se401->vdev, &se401_template, sizeof(se401_template));
1367 memcpy(se401->vdev.name, se401->camera_name, strlen(se401->camera_name)); 1365 memcpy(se401->vdev.name, se401->camera_name, strlen(se401->camera_name));
1368 init_waitqueue_head(&se401->wq); 1366 init_waitqueue_head(&se401->wq);
1369 init_MUTEX(&se401->lock); 1367 mutex_init(&se401->lock);
1370 wmb(); 1368 wmb();
1371 1369
1372 if (video_register_device(&se401->vdev, VFL_TYPE_GRABBER, video_nr) == -1) { 1370 if (video_register_device(&se401->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
diff --git a/drivers/usb/media/se401.h b/drivers/usb/media/se401.h
index 2e5846f1eb20..e88a40d4c86a 100644
--- a/drivers/usb/media/se401.h
+++ b/drivers/usb/media/se401.h
@@ -5,6 +5,7 @@
5#include <asm/uaccess.h> 5#include <asm/uaccess.h>
6#include <linux/videodev.h> 6#include <linux/videodev.h>
7#include <linux/smp_lock.h> 7#include <linux/smp_lock.h>
8#include <linux/mutex.h>
8 9
9#define se401_DEBUG /* Turn on debug messages */ 10#define se401_DEBUG /* Turn on debug messages */
10 11
@@ -189,7 +190,7 @@ struct usb_se401 {
189 int maxframesize; 190 int maxframesize;
190 int cframesize; /* current framesize */ 191 int cframesize; /* current framesize */
191 192
192 struct semaphore lock; 193 struct mutex lock;
193 int user; /* user count for exclusive use */ 194 int user; /* user count for exclusive use */
194 int removed; /* device disconnected */ 195 int removed; /* device disconnected */
195 196
diff --git a/drivers/usb/media/sn9c102.h b/drivers/usb/media/sn9c102.h
index 17d60c1eea7e..1d70a62b9f23 100644
--- a/drivers/usb/media/sn9c102.h
+++ b/drivers/usb/media/sn9c102.h
@@ -33,7 +33,9 @@
33#include <linux/types.h> 33#include <linux/types.h>
34#include <linux/param.h> 34#include <linux/param.h>
35#include <linux/rwsem.h> 35#include <linux/rwsem.h>
36#include <asm/semaphore.h> 36#include <linux/mutex.h>
37#include <linux/string.h>
38#include <linux/stddef.h>
37 39
38#include "sn9c102_sensor.h" 40#include "sn9c102_sensor.h"
39 41
@@ -50,6 +52,7 @@
50#define SN9C102_ALTERNATE_SETTING 8 52#define SN9C102_ALTERNATE_SETTING 8
51#define SN9C102_URB_TIMEOUT msecs_to_jiffies(2 * SN9C102_ISO_PACKETS) 53#define SN9C102_URB_TIMEOUT msecs_to_jiffies(2 * SN9C102_ISO_PACKETS)
52#define SN9C102_CTRL_TIMEOUT 300 54#define SN9C102_CTRL_TIMEOUT 300
55#define SN9C102_FRAME_TIMEOUT 2
53 56
54/*****************************************************************************/ 57/*****************************************************************************/
55 58
@@ -107,16 +110,17 @@ struct sn9c102_sysfs_attr {
107 110
108struct sn9c102_module_param { 111struct sn9c102_module_param {
109 u8 force_munmap; 112 u8 force_munmap;
113 u16 frame_timeout;
110}; 114};
111 115
112static DECLARE_MUTEX(sn9c102_sysfs_lock); 116static DEFINE_MUTEX(sn9c102_sysfs_lock);
113static DECLARE_RWSEM(sn9c102_disconnect); 117static DECLARE_RWSEM(sn9c102_disconnect);
114 118
115struct sn9c102_device { 119struct sn9c102_device {
116 struct video_device* v4ldev; 120 struct video_device* v4ldev;
117 121
118 enum sn9c102_bridge bridge; 122 enum sn9c102_bridge bridge;
119 struct sn9c102_sensor* sensor; 123 struct sn9c102_sensor sensor;
120 124
121 struct usb_device* usbdev; 125 struct usb_device* usbdev;
122 struct urb* urb[SN9C102_URBS]; 126 struct urb* urb[SN9C102_URBS];
@@ -141,19 +145,28 @@ struct sn9c102_device {
141 enum sn9c102_dev_state state; 145 enum sn9c102_dev_state state;
142 u8 users; 146 u8 users;
143 147
144 struct semaphore dev_sem, fileop_sem; 148 struct mutex dev_mutex, fileop_mutex;
145 spinlock_t queue_lock; 149 spinlock_t queue_lock;
146 wait_queue_head_t open, wait_frame, wait_stream; 150 wait_queue_head_t open, wait_frame, wait_stream;
147}; 151};
148 152
149/*****************************************************************************/ 153/*****************************************************************************/
150 154
155struct sn9c102_device*
156sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id)
157{
158 if (usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id))
159 return cam;
160
161 return NULL;
162}
163
164
151void 165void
152sn9c102_attach_sensor(struct sn9c102_device* cam, 166sn9c102_attach_sensor(struct sn9c102_device* cam,
153 struct sn9c102_sensor* sensor) 167 struct sn9c102_sensor* sensor)
154{ 168{
155 cam->sensor = sensor; 169 memcpy(&cam->sensor, sensor, sizeof(struct sn9c102_sensor));
156 cam->sensor->usbdev = cam->usbdev;
157} 170}
158 171
159/*****************************************************************************/ 172/*****************************************************************************/
@@ -196,7 +209,8 @@ do { \
196 209
197#undef PDBG 210#undef PDBG
198#define PDBG(fmt, args...) \ 211#define PDBG(fmt, args...) \
199dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args) 212dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
213 __FUNCTION__, __LINE__ , ## args)
200 214
201#undef PDBGG 215#undef PDBGG
202#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */ 216#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
diff --git a/drivers/usb/media/sn9c102_core.c b/drivers/usb/media/sn9c102_core.c
index c81397e4714b..4c6cc6395723 100644
--- a/drivers/usb/media/sn9c102_core.c
+++ b/drivers/usb/media/sn9c102_core.c
@@ -25,11 +25,9 @@
25#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/string.h>
29#include <linux/device.h> 28#include <linux/device.h>
30#include <linux/fs.h> 29#include <linux/fs.h>
31#include <linux/delay.h> 30#include <linux/delay.h>
32#include <linux/stddef.h>
33#include <linux/compiler.h> 31#include <linux/compiler.h>
34#include <linux/ioctl.h> 32#include <linux/ioctl.h>
35#include <linux/poll.h> 33#include <linux/poll.h>
@@ -49,8 +47,8 @@
49#define SN9C102_MODULE_AUTHOR "(C) 2004-2006 Luca Risolia" 47#define SN9C102_MODULE_AUTHOR "(C) 2004-2006 Luca Risolia"
50#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 48#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
51#define SN9C102_MODULE_LICENSE "GPL" 49#define SN9C102_MODULE_LICENSE "GPL"
52#define SN9C102_MODULE_VERSION "1:1.26" 50#define SN9C102_MODULE_VERSION "1:1.27"
53#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 26) 51#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 27)
54 52
55/*****************************************************************************/ 53/*****************************************************************************/
56 54
@@ -89,6 +87,15 @@ MODULE_PARM_DESC(force_munmap,
89 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"." 87 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"."
90 "\n"); 88 "\n");
91 89
90static unsigned int frame_timeout[] = {[0 ... SN9C102_MAX_DEVICES-1] =
91 SN9C102_FRAME_TIMEOUT};
92module_param_array(frame_timeout, uint, NULL, 0644);
93MODULE_PARM_DESC(frame_timeout,
94 "\n<n[,...]> Timeout for a video frame in seconds."
95 "\nThis parameter is specific for each detected camera."
96 "\nDefault value is "__MODULE_STRING(SN9C102_FRAME_TIMEOUT)"."
97 "\n");
98
92#ifdef SN9C102_DEBUG 99#ifdef SN9C102_DEBUG
93static unsigned short debug = SN9C102_DEBUG_LEVEL; 100static unsigned short debug = SN9C102_DEBUG_LEVEL;
94module_param(debug, ushort, 0644); 101module_param(debug, ushort, 0644);
@@ -128,8 +135,8 @@ static u32
128sn9c102_request_buffers(struct sn9c102_device* cam, u32 count, 135sn9c102_request_buffers(struct sn9c102_device* cam, u32 count,
129 enum sn9c102_io_method io) 136 enum sn9c102_io_method io)
130{ 137{
131 struct v4l2_pix_format* p = &(cam->sensor->pix_format); 138 struct v4l2_pix_format* p = &(cam->sensor.pix_format);
132 struct v4l2_rect* r = &(cam->sensor->cropcap.bounds); 139 struct v4l2_rect* r = &(cam->sensor.cropcap.bounds);
133 const size_t imagesize = cam->module_param.force_munmap || 140 const size_t imagesize = cam->module_param.force_munmap ||
134 io == IO_READ ? 141 io == IO_READ ?
135 (p->width * p->height * p->priv) / 8 : 142 (p->width * p->height * p->priv) / 8 :
@@ -449,19 +456,13 @@ sn9c102_i2c_try_write(struct sn9c102_device* cam,
449 456
450int sn9c102_i2c_read(struct sn9c102_device* cam, u8 address) 457int sn9c102_i2c_read(struct sn9c102_device* cam, u8 address)
451{ 458{
452 if (!cam->sensor) 459 return sn9c102_i2c_try_read(cam, &cam->sensor, address);
453 return -1;
454
455 return sn9c102_i2c_try_read(cam, cam->sensor, address);
456} 460}
457 461
458 462
459int sn9c102_i2c_write(struct sn9c102_device* cam, u8 address, u8 value) 463int sn9c102_i2c_write(struct sn9c102_device* cam, u8 address, u8 value)
460{ 464{
461 if (!cam->sensor) 465 return sn9c102_i2c_try_write(cam, &cam->sensor, address, value);
462 return -1;
463
464 return sn9c102_i2c_try_write(cam, cam->sensor, address, value);
465} 466}
466 467
467/*****************************************************************************/ 468/*****************************************************************************/
@@ -505,7 +506,7 @@ sn9c102_find_eof_header(struct sn9c102_device* cam, void* mem, size_t len)
505 size_t eoflen = sizeof(sn9c102_eof_header_t), i; 506 size_t eoflen = sizeof(sn9c102_eof_header_t), i;
506 unsigned j, n = sizeof(sn9c102_eof_header) / eoflen; 507 unsigned j, n = sizeof(sn9c102_eof_header) / eoflen;
507 508
508 if (cam->sensor->pix_format.pixelformat == V4L2_PIX_FMT_SN9C10X) 509 if (cam->sensor.pix_format.pixelformat == V4L2_PIX_FMT_SN9C10X)
509 return NULL; /* EOF header does not exist in compressed data */ 510 return NULL; /* EOF header does not exist in compressed data */
510 511
511 for (i = 0; (len >= eoflen) && (i <= len - eoflen); i++) 512 for (i = 0; (len >= eoflen) && (i <= len - eoflen); i++)
@@ -535,7 +536,7 @@ static void sn9c102_urb_complete(struct urb *urb, struct pt_regs* regs)
535 if ((*f)) 536 if ((*f))
536 (*f)->state = F_QUEUED; 537 (*f)->state = F_QUEUED;
537 DBG(3, "Stream interrupted"); 538 DBG(3, "Stream interrupted");
538 wake_up_interruptible(&cam->wait_stream); 539 wake_up(&cam->wait_stream);
539 } 540 }
540 541
541 if (cam->state & DEV_DISCONNECTED) 542 if (cam->state & DEV_DISCONNECTED)
@@ -553,9 +554,9 @@ static void sn9c102_urb_complete(struct urb *urb, struct pt_regs* regs)
553 (*f) = list_entry(cam->inqueue.next, struct sn9c102_frame_t, 554 (*f) = list_entry(cam->inqueue.next, struct sn9c102_frame_t,
554 frame); 555 frame);
555 556
556 imagesize = (cam->sensor->pix_format.width * 557 imagesize = (cam->sensor.pix_format.width *
557 cam->sensor->pix_format.height * 558 cam->sensor.pix_format.height *
558 cam->sensor->pix_format.priv) / 8; 559 cam->sensor.pix_format.priv) / 8;
559 560
560 soflen = (cam->bridge) == BRIDGE_SN9C103 ? 561 soflen = (cam->bridge) == BRIDGE_SN9C103 ?
561 sizeof(sn9c103_sof_header_t) : 562 sizeof(sn9c103_sof_header_t) :
@@ -579,7 +580,7 @@ static void sn9c102_urb_complete(struct urb *urb, struct pt_regs* regs)
579 580
580redo: 581redo:
581 sof = sn9c102_find_sof_header(cam, pos, len); 582 sof = sn9c102_find_sof_header(cam, pos, len);
582 if (!sof) { 583 if (likely(!sof)) {
583 eof = sn9c102_find_eof_header(cam, pos, len); 584 eof = sn9c102_find_eof_header(cam, pos, len);
584 if ((*f)->state == F_GRABBING) { 585 if ((*f)->state == F_GRABBING) {
585end_of_frame: 586end_of_frame:
@@ -589,8 +590,9 @@ end_of_frame:
589 img = (eof > pos) ? eof - pos - 1 : 0; 590 img = (eof > pos) ? eof - pos - 1 : 0;
590 591
591 if ((*f)->buf.bytesused+img > imagesize) { 592 if ((*f)->buf.bytesused+img > imagesize) {
592 u32 b = (*f)->buf.bytesused + img - 593 u32 b;
593 imagesize; 594 b = (*f)->buf.bytesused + img -
595 imagesize;
594 img = imagesize - (*f)->buf.bytesused; 596 img = imagesize - (*f)->buf.bytesused;
595 DBG(3, "Expected EOF not found: " 597 DBG(3, "Expected EOF not found: "
596 "video frame cut"); 598 "video frame cut");
@@ -608,9 +610,10 @@ end_of_frame:
608 (*f)->buf.bytesused += img; 610 (*f)->buf.bytesused += img;
609 611
610 if ((*f)->buf.bytesused == imagesize || 612 if ((*f)->buf.bytesused == imagesize ||
611 (cam->sensor->pix_format.pixelformat == 613 (cam->sensor.pix_format.pixelformat ==
612 V4L2_PIX_FMT_SN9C10X && eof)) { 614 V4L2_PIX_FMT_SN9C10X && eof)) {
613 u32 b = (*f)->buf.bytesused; 615 u32 b;
616 b = (*f)->buf.bytesused;
614 (*f)->state = F_DONE; 617 (*f)->state = F_DONE;
615 (*f)->buf.sequence= ++cam->frame_count; 618 (*f)->buf.sequence= ++cam->frame_count;
616 spin_lock(&cam->queue_lock); 619 spin_lock(&cam->queue_lock);
@@ -667,7 +670,7 @@ start_of_frame:
667 if (eof && eof < sof) 670 if (eof && eof < sof)
668 goto end_of_frame; /* (1) */ 671 goto end_of_frame; /* (1) */
669 else { 672 else {
670 if (cam->sensor->pix_format.pixelformat == 673 if (cam->sensor.pix_format.pixelformat ==
671 V4L2_PIX_FMT_SN9C10X) { 674 V4L2_PIX_FMT_SN9C10X) {
672 eof = sof - soflen; 675 eof = sof - soflen;
673 goto end_of_frame; 676 goto end_of_frame;
@@ -808,20 +811,21 @@ static int sn9c102_stop_transfer(struct sn9c102_device* cam)
808 811
809static int sn9c102_stream_interrupt(struct sn9c102_device* cam) 812static int sn9c102_stream_interrupt(struct sn9c102_device* cam)
810{ 813{
811 int err = 0; 814 long timeout;
812 815
813 cam->stream = STREAM_INTERRUPT; 816 cam->stream = STREAM_INTERRUPT;
814 err = wait_event_timeout(cam->wait_stream, 817 timeout = wait_event_timeout(cam->wait_stream,
815 (cam->stream == STREAM_OFF) || 818 (cam->stream == STREAM_OFF) ||
816 (cam->state & DEV_DISCONNECTED), 819 (cam->state & DEV_DISCONNECTED),
817 SN9C102_URB_TIMEOUT); 820 SN9C102_URB_TIMEOUT);
818 if (cam->state & DEV_DISCONNECTED) 821 if (cam->state & DEV_DISCONNECTED)
819 return -ENODEV; 822 return -ENODEV;
820 else if (err) { 823 else if (cam->stream != STREAM_OFF) {
821 cam->state |= DEV_MISCONFIGURED; 824 cam->state |= DEV_MISCONFIGURED;
822 DBG(1, "The camera is misconfigured. To use it, close and " 825 DBG(1, "URB timeout reached. The camera is misconfigured. "
823 "open /dev/video%d again.", cam->v4ldev->minor); 826 "To use it, close and open /dev/video%d again.",
824 return err; 827 cam->v4ldev->minor);
828 return -EIO;
825 } 829 }
826 830
827 return 0; 831 return 0;
@@ -866,18 +870,18 @@ static ssize_t sn9c102_show_reg(struct class_device* cd, char* buf)
866 struct sn9c102_device* cam; 870 struct sn9c102_device* cam;
867 ssize_t count; 871 ssize_t count;
868 872
869 if (down_interruptible(&sn9c102_sysfs_lock)) 873 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
870 return -ERESTARTSYS; 874 return -ERESTARTSYS;
871 875
872 cam = video_get_drvdata(to_video_device(cd)); 876 cam = video_get_drvdata(to_video_device(cd));
873 if (!cam) { 877 if (!cam) {
874 up(&sn9c102_sysfs_lock); 878 mutex_unlock(&sn9c102_sysfs_lock);
875 return -ENODEV; 879 return -ENODEV;
876 } 880 }
877 881
878 count = sprintf(buf, "%u\n", cam->sysfs.reg); 882 count = sprintf(buf, "%u\n", cam->sysfs.reg);
879 883
880 up(&sn9c102_sysfs_lock); 884 mutex_unlock(&sn9c102_sysfs_lock);
881 885
882 return count; 886 return count;
883} 887}
@@ -890,18 +894,18 @@ sn9c102_store_reg(struct class_device* cd, const char* buf, size_t len)
890 u8 index; 894 u8 index;
891 ssize_t count; 895 ssize_t count;
892 896
893 if (down_interruptible(&sn9c102_sysfs_lock)) 897 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
894 return -ERESTARTSYS; 898 return -ERESTARTSYS;
895 899
896 cam = video_get_drvdata(to_video_device(cd)); 900 cam = video_get_drvdata(to_video_device(cd));
897 if (!cam) { 901 if (!cam) {
898 up(&sn9c102_sysfs_lock); 902 mutex_unlock(&sn9c102_sysfs_lock);
899 return -ENODEV; 903 return -ENODEV;
900 } 904 }
901 905
902 index = sn9c102_strtou8(buf, len, &count); 906 index = sn9c102_strtou8(buf, len, &count);
903 if (index > 0x1f || !count) { 907 if (index > 0x1f || !count) {
904 up(&sn9c102_sysfs_lock); 908 mutex_unlock(&sn9c102_sysfs_lock);
905 return -EINVAL; 909 return -EINVAL;
906 } 910 }
907 911
@@ -910,7 +914,7 @@ sn9c102_store_reg(struct class_device* cd, const char* buf, size_t len)
910 DBG(2, "Moved SN9C10X register index to 0x%02X", cam->sysfs.reg); 914 DBG(2, "Moved SN9C10X register index to 0x%02X", cam->sysfs.reg);
911 DBG(3, "Written bytes: %zd", count); 915 DBG(3, "Written bytes: %zd", count);
912 916
913 up(&sn9c102_sysfs_lock); 917 mutex_unlock(&sn9c102_sysfs_lock);
914 918
915 return count; 919 return count;
916} 920}
@@ -922,17 +926,17 @@ static ssize_t sn9c102_show_val(struct class_device* cd, char* buf)
922 ssize_t count; 926 ssize_t count;
923 int val; 927 int val;
924 928
925 if (down_interruptible(&sn9c102_sysfs_lock)) 929 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
926 return -ERESTARTSYS; 930 return -ERESTARTSYS;
927 931
928 cam = video_get_drvdata(to_video_device(cd)); 932 cam = video_get_drvdata(to_video_device(cd));
929 if (!cam) { 933 if (!cam) {
930 up(&sn9c102_sysfs_lock); 934 mutex_unlock(&sn9c102_sysfs_lock);
931 return -ENODEV; 935 return -ENODEV;
932 } 936 }
933 937
934 if ((val = sn9c102_read_reg(cam, cam->sysfs.reg)) < 0) { 938 if ((val = sn9c102_read_reg(cam, cam->sysfs.reg)) < 0) {
935 up(&sn9c102_sysfs_lock); 939 mutex_unlock(&sn9c102_sysfs_lock);
936 return -EIO; 940 return -EIO;
937 } 941 }
938 942
@@ -940,7 +944,7 @@ static ssize_t sn9c102_show_val(struct class_device* cd, char* buf)
940 944
941 DBG(3, "Read bytes: %zd", count); 945 DBG(3, "Read bytes: %zd", count);
942 946
943 up(&sn9c102_sysfs_lock); 947 mutex_unlock(&sn9c102_sysfs_lock);
944 948
945 return count; 949 return count;
946} 950}
@@ -954,24 +958,24 @@ sn9c102_store_val(struct class_device* cd, const char* buf, size_t len)
954 ssize_t count; 958 ssize_t count;
955 int err; 959 int err;
956 960
957 if (down_interruptible(&sn9c102_sysfs_lock)) 961 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
958 return -ERESTARTSYS; 962 return -ERESTARTSYS;
959 963
960 cam = video_get_drvdata(to_video_device(cd)); 964 cam = video_get_drvdata(to_video_device(cd));
961 if (!cam) { 965 if (!cam) {
962 up(&sn9c102_sysfs_lock); 966 mutex_unlock(&sn9c102_sysfs_lock);
963 return -ENODEV; 967 return -ENODEV;
964 } 968 }
965 969
966 value = sn9c102_strtou8(buf, len, &count); 970 value = sn9c102_strtou8(buf, len, &count);
967 if (!count) { 971 if (!count) {
968 up(&sn9c102_sysfs_lock); 972 mutex_unlock(&sn9c102_sysfs_lock);
969 return -EINVAL; 973 return -EINVAL;
970 } 974 }
971 975
972 err = sn9c102_write_reg(cam, value, cam->sysfs.reg); 976 err = sn9c102_write_reg(cam, value, cam->sysfs.reg);
973 if (err) { 977 if (err) {
974 up(&sn9c102_sysfs_lock); 978 mutex_unlock(&sn9c102_sysfs_lock);
975 return -EIO; 979 return -EIO;
976 } 980 }
977 981
@@ -979,7 +983,7 @@ sn9c102_store_val(struct class_device* cd, const char* buf, size_t len)
979 cam->sysfs.reg, value); 983 cam->sysfs.reg, value);
980 DBG(3, "Written bytes: %zd", count); 984 DBG(3, "Written bytes: %zd", count);
981 985
982 up(&sn9c102_sysfs_lock); 986 mutex_unlock(&sn9c102_sysfs_lock);
983 987
984 return count; 988 return count;
985} 989}
@@ -990,12 +994,12 @@ static ssize_t sn9c102_show_i2c_reg(struct class_device* cd, char* buf)
990 struct sn9c102_device* cam; 994 struct sn9c102_device* cam;
991 ssize_t count; 995 ssize_t count;
992 996
993 if (down_interruptible(&sn9c102_sysfs_lock)) 997 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
994 return -ERESTARTSYS; 998 return -ERESTARTSYS;
995 999
996 cam = video_get_drvdata(to_video_device(cd)); 1000 cam = video_get_drvdata(to_video_device(cd));
997 if (!cam) { 1001 if (!cam) {
998 up(&sn9c102_sysfs_lock); 1002 mutex_unlock(&sn9c102_sysfs_lock);
999 return -ENODEV; 1003 return -ENODEV;
1000 } 1004 }
1001 1005
@@ -1003,7 +1007,7 @@ static ssize_t sn9c102_show_i2c_reg(struct class_device* cd, char* buf)
1003 1007
1004 DBG(3, "Read bytes: %zd", count); 1008 DBG(3, "Read bytes: %zd", count);
1005 1009
1006 up(&sn9c102_sysfs_lock); 1010 mutex_unlock(&sn9c102_sysfs_lock);
1007 1011
1008 return count; 1012 return count;
1009} 1013}
@@ -1016,18 +1020,18 @@ sn9c102_store_i2c_reg(struct class_device* cd, const char* buf, size_t len)
1016 u8 index; 1020 u8 index;
1017 ssize_t count; 1021 ssize_t count;
1018 1022
1019 if (down_interruptible(&sn9c102_sysfs_lock)) 1023 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1020 return -ERESTARTSYS; 1024 return -ERESTARTSYS;
1021 1025
1022 cam = video_get_drvdata(to_video_device(cd)); 1026 cam = video_get_drvdata(to_video_device(cd));
1023 if (!cam) { 1027 if (!cam) {
1024 up(&sn9c102_sysfs_lock); 1028 mutex_unlock(&sn9c102_sysfs_lock);
1025 return -ENODEV; 1029 return -ENODEV;
1026 } 1030 }
1027 1031
1028 index = sn9c102_strtou8(buf, len, &count); 1032 index = sn9c102_strtou8(buf, len, &count);
1029 if (!count) { 1033 if (!count) {
1030 up(&sn9c102_sysfs_lock); 1034 mutex_unlock(&sn9c102_sysfs_lock);
1031 return -EINVAL; 1035 return -EINVAL;
1032 } 1036 }
1033 1037
@@ -1036,7 +1040,7 @@ sn9c102_store_i2c_reg(struct class_device* cd, const char* buf, size_t len)
1036 DBG(2, "Moved sensor register index to 0x%02X", cam->sysfs.i2c_reg); 1040 DBG(2, "Moved sensor register index to 0x%02X", cam->sysfs.i2c_reg);
1037 DBG(3, "Written bytes: %zd", count); 1041 DBG(3, "Written bytes: %zd", count);
1038 1042
1039 up(&sn9c102_sysfs_lock); 1043 mutex_unlock(&sn9c102_sysfs_lock);
1040 1044
1041 return count; 1045 return count;
1042} 1046}
@@ -1048,22 +1052,22 @@ static ssize_t sn9c102_show_i2c_val(struct class_device* cd, char* buf)
1048 ssize_t count; 1052 ssize_t count;
1049 int val; 1053 int val;
1050 1054
1051 if (down_interruptible(&sn9c102_sysfs_lock)) 1055 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1052 return -ERESTARTSYS; 1056 return -ERESTARTSYS;
1053 1057
1054 cam = video_get_drvdata(to_video_device(cd)); 1058 cam = video_get_drvdata(to_video_device(cd));
1055 if (!cam) { 1059 if (!cam) {
1056 up(&sn9c102_sysfs_lock); 1060 mutex_unlock(&sn9c102_sysfs_lock);
1057 return -ENODEV; 1061 return -ENODEV;
1058 } 1062 }
1059 1063
1060 if (!(cam->sensor->sysfs_ops & SN9C102_I2C_READ)) { 1064 if (!(cam->sensor.sysfs_ops & SN9C102_I2C_READ)) {
1061 up(&sn9c102_sysfs_lock); 1065 mutex_unlock(&sn9c102_sysfs_lock);
1062 return -ENOSYS; 1066 return -ENOSYS;
1063 } 1067 }
1064 1068
1065 if ((val = sn9c102_i2c_read(cam, cam->sysfs.i2c_reg)) < 0) { 1069 if ((val = sn9c102_i2c_read(cam, cam->sysfs.i2c_reg)) < 0) {
1066 up(&sn9c102_sysfs_lock); 1070 mutex_unlock(&sn9c102_sysfs_lock);
1067 return -EIO; 1071 return -EIO;
1068 } 1072 }
1069 1073
@@ -1071,7 +1075,7 @@ static ssize_t sn9c102_show_i2c_val(struct class_device* cd, char* buf)
1071 1075
1072 DBG(3, "Read bytes: %zd", count); 1076 DBG(3, "Read bytes: %zd", count);
1073 1077
1074 up(&sn9c102_sysfs_lock); 1078 mutex_unlock(&sn9c102_sysfs_lock);
1075 1079
1076 return count; 1080 return count;
1077} 1081}
@@ -1085,29 +1089,29 @@ sn9c102_store_i2c_val(struct class_device* cd, const char* buf, size_t len)
1085 ssize_t count; 1089 ssize_t count;
1086 int err; 1090 int err;
1087 1091
1088 if (down_interruptible(&sn9c102_sysfs_lock)) 1092 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1089 return -ERESTARTSYS; 1093 return -ERESTARTSYS;
1090 1094
1091 cam = video_get_drvdata(to_video_device(cd)); 1095 cam = video_get_drvdata(to_video_device(cd));
1092 if (!cam) { 1096 if (!cam) {
1093 up(&sn9c102_sysfs_lock); 1097 mutex_unlock(&sn9c102_sysfs_lock);
1094 return -ENODEV; 1098 return -ENODEV;
1095 } 1099 }
1096 1100
1097 if (!(cam->sensor->sysfs_ops & SN9C102_I2C_WRITE)) { 1101 if (!(cam->sensor.sysfs_ops & SN9C102_I2C_WRITE)) {
1098 up(&sn9c102_sysfs_lock); 1102 mutex_unlock(&sn9c102_sysfs_lock);
1099 return -ENOSYS; 1103 return -ENOSYS;
1100 } 1104 }
1101 1105
1102 value = sn9c102_strtou8(buf, len, &count); 1106 value = sn9c102_strtou8(buf, len, &count);
1103 if (!count) { 1107 if (!count) {
1104 up(&sn9c102_sysfs_lock); 1108 mutex_unlock(&sn9c102_sysfs_lock);
1105 return -EINVAL; 1109 return -EINVAL;
1106 } 1110 }
1107 1111
1108 err = sn9c102_i2c_write(cam, cam->sysfs.i2c_reg, value); 1112 err = sn9c102_i2c_write(cam, cam->sysfs.i2c_reg, value);
1109 if (err) { 1113 if (err) {
1110 up(&sn9c102_sysfs_lock); 1114 mutex_unlock(&sn9c102_sysfs_lock);
1111 return -EIO; 1115 return -EIO;
1112 } 1116 }
1113 1117
@@ -1115,7 +1119,7 @@ sn9c102_store_i2c_val(struct class_device* cd, const char* buf, size_t len)
1115 cam->sysfs.i2c_reg, value); 1119 cam->sysfs.i2c_reg, value);
1116 DBG(3, "Written bytes: %zd", count); 1120 DBG(3, "Written bytes: %zd", count);
1117 1121
1118 up(&sn9c102_sysfs_lock); 1122 mutex_unlock(&sn9c102_sysfs_lock);
1119 1123
1120 return count; 1124 return count;
1121} 1125}
@@ -1130,18 +1134,18 @@ sn9c102_store_green(struct class_device* cd, const char* buf, size_t len)
1130 u8 value; 1134 u8 value;
1131 ssize_t count; 1135 ssize_t count;
1132 1136
1133 if (down_interruptible(&sn9c102_sysfs_lock)) 1137 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1134 return -ERESTARTSYS; 1138 return -ERESTARTSYS;
1135 1139
1136 cam = video_get_drvdata(to_video_device(cd)); 1140 cam = video_get_drvdata(to_video_device(cd));
1137 if (!cam) { 1141 if (!cam) {
1138 up(&sn9c102_sysfs_lock); 1142 mutex_unlock(&sn9c102_sysfs_lock);
1139 return -ENODEV; 1143 return -ENODEV;
1140 } 1144 }
1141 1145
1142 bridge = cam->bridge; 1146 bridge = cam->bridge;
1143 1147
1144 up(&sn9c102_sysfs_lock); 1148 mutex_unlock(&sn9c102_sysfs_lock);
1145 1149
1146 value = sn9c102_strtou8(buf, len, &count); 1150 value = sn9c102_strtou8(buf, len, &count);
1147 if (!count) 1151 if (!count)
@@ -1249,7 +1253,7 @@ static void sn9c102_create_sysfs(struct sn9c102_device* cam)
1249 video_device_create_file(v4ldev, &class_device_attr_blue); 1253 video_device_create_file(v4ldev, &class_device_attr_blue);
1250 video_device_create_file(v4ldev, &class_device_attr_red); 1254 video_device_create_file(v4ldev, &class_device_attr_red);
1251 } 1255 }
1252 if (cam->sensor && cam->sensor->sysfs_ops) { 1256 if (cam->sensor.sysfs_ops) {
1253 video_device_create_file(v4ldev, &class_device_attr_i2c_reg); 1257 video_device_create_file(v4ldev, &class_device_attr_i2c_reg);
1254 video_device_create_file(v4ldev, &class_device_attr_i2c_val); 1258 video_device_create_file(v4ldev, &class_device_attr_i2c_val);
1255 } 1259 }
@@ -1312,7 +1316,7 @@ static int sn9c102_set_scale(struct sn9c102_device* cam, u8 scale)
1312 1316
1313static int sn9c102_set_crop(struct sn9c102_device* cam, struct v4l2_rect* rect) 1317static int sn9c102_set_crop(struct sn9c102_device* cam, struct v4l2_rect* rect)
1314{ 1318{
1315 struct sn9c102_sensor* s = cam->sensor; 1319 struct sn9c102_sensor* s = &cam->sensor;
1316 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left), 1320 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left),
1317 v_start = (u8)(rect->top - s->cropcap.bounds.top), 1321 v_start = (u8)(rect->top - s->cropcap.bounds.top),
1318 h_size = (u8)(rect->width / 16), 1322 h_size = (u8)(rect->width / 16),
@@ -1335,7 +1339,7 @@ static int sn9c102_set_crop(struct sn9c102_device* cam, struct v4l2_rect* rect)
1335 1339
1336static int sn9c102_init(struct sn9c102_device* cam) 1340static int sn9c102_init(struct sn9c102_device* cam)
1337{ 1341{
1338 struct sn9c102_sensor* s = cam->sensor; 1342 struct sn9c102_sensor* s = &cam->sensor;
1339 struct v4l2_control ctrl; 1343 struct v4l2_control ctrl;
1340 struct v4l2_queryctrl *qctrl; 1344 struct v4l2_queryctrl *qctrl;
1341 struct v4l2_rect* rect; 1345 struct v4l2_rect* rect;
@@ -1404,7 +1408,7 @@ static int sn9c102_init(struct sn9c102_device* cam)
1404 } 1408 }
1405 1409
1406 if (!(cam->state & DEV_INITIALIZED)) { 1410 if (!(cam->state & DEV_INITIALIZED)) {
1407 init_MUTEX(&cam->fileop_sem); 1411 mutex_init(&cam->fileop_mutex);
1408 spin_lock_init(&cam->queue_lock); 1412 spin_lock_init(&cam->queue_lock);
1409 init_waitqueue_head(&cam->wait_frame); 1413 init_waitqueue_head(&cam->wait_frame);
1410 init_waitqueue_head(&cam->wait_stream); 1414 init_waitqueue_head(&cam->wait_stream);
@@ -1422,13 +1426,15 @@ static int sn9c102_init(struct sn9c102_device* cam)
1422 1426
1423static void sn9c102_release_resources(struct sn9c102_device* cam) 1427static void sn9c102_release_resources(struct sn9c102_device* cam)
1424{ 1428{
1425 down(&sn9c102_sysfs_lock); 1429 mutex_lock(&sn9c102_sysfs_lock);
1426 1430
1427 DBG(2, "V4L2 device /dev/video%d deregistered", cam->v4ldev->minor); 1431 DBG(2, "V4L2 device /dev/video%d deregistered", cam->v4ldev->minor);
1428 video_set_drvdata(cam->v4ldev, NULL); 1432 video_set_drvdata(cam->v4ldev, NULL);
1429 video_unregister_device(cam->v4ldev); 1433 video_unregister_device(cam->v4ldev);
1430 1434
1431 up(&sn9c102_sysfs_lock); 1435 usb_put_dev(cam->usbdev);
1436
1437 mutex_unlock(&sn9c102_sysfs_lock);
1432 1438
1433 kfree(cam->control_buffer); 1439 kfree(cam->control_buffer);
1434} 1440}
@@ -1449,7 +1455,7 @@ static int sn9c102_open(struct inode* inode, struct file* filp)
1449 1455
1450 cam = video_get_drvdata(video_devdata(filp)); 1456 cam = video_get_drvdata(video_devdata(filp));
1451 1457
1452 if (down_interruptible(&cam->dev_sem)) { 1458 if (mutex_lock_interruptible(&cam->dev_mutex)) {
1453 up_read(&sn9c102_disconnect); 1459 up_read(&sn9c102_disconnect);
1454 return -ERESTARTSYS; 1460 return -ERESTARTSYS;
1455 } 1461 }
@@ -1461,7 +1467,7 @@ static int sn9c102_open(struct inode* inode, struct file* filp)
1461 err = -EWOULDBLOCK; 1467 err = -EWOULDBLOCK;
1462 goto out; 1468 goto out;
1463 } 1469 }
1464 up(&cam->dev_sem); 1470 mutex_unlock(&cam->dev_mutex);
1465 err = wait_event_interruptible_exclusive(cam->open, 1471 err = wait_event_interruptible_exclusive(cam->open,
1466 cam->state & DEV_DISCONNECTED 1472 cam->state & DEV_DISCONNECTED
1467 || !cam->users); 1473 || !cam->users);
@@ -1473,7 +1479,7 @@ static int sn9c102_open(struct inode* inode, struct file* filp)
1473 up_read(&sn9c102_disconnect); 1479 up_read(&sn9c102_disconnect);
1474 return -ENODEV; 1480 return -ENODEV;
1475 } 1481 }
1476 down(&cam->dev_sem); 1482 mutex_lock(&cam->dev_mutex);
1477 } 1483 }
1478 1484
1479 1485
@@ -1501,7 +1507,7 @@ static int sn9c102_open(struct inode* inode, struct file* filp)
1501 DBG(3, "Video device /dev/video%d is open", cam->v4ldev->minor); 1507 DBG(3, "Video device /dev/video%d is open", cam->v4ldev->minor);
1502 1508
1503out: 1509out:
1504 up(&cam->dev_sem); 1510 mutex_unlock(&cam->dev_mutex);
1505 up_read(&sn9c102_disconnect); 1511 up_read(&sn9c102_disconnect);
1506 return err; 1512 return err;
1507} 1513}
@@ -1511,7 +1517,7 @@ static int sn9c102_release(struct inode* inode, struct file* filp)
1511{ 1517{
1512 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 1518 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
1513 1519
1514 down(&cam->dev_sem); /* prevent disconnect() to be called */ 1520 mutex_lock(&cam->dev_mutex); /* prevent disconnect() to be called */
1515 1521
1516 sn9c102_stop_transfer(cam); 1522 sn9c102_stop_transfer(cam);
1517 1523
@@ -1519,7 +1525,7 @@ static int sn9c102_release(struct inode* inode, struct file* filp)
1519 1525
1520 if (cam->state & DEV_DISCONNECTED) { 1526 if (cam->state & DEV_DISCONNECTED) {
1521 sn9c102_release_resources(cam); 1527 sn9c102_release_resources(cam);
1522 up(&cam->dev_sem); 1528 mutex_unlock(&cam->dev_mutex);
1523 kfree(cam); 1529 kfree(cam);
1524 return 0; 1530 return 0;
1525 } 1531 }
@@ -1529,7 +1535,7 @@ static int sn9c102_release(struct inode* inode, struct file* filp)
1529 1535
1530 DBG(3, "Video device /dev/video%d closed", cam->v4ldev->minor); 1536 DBG(3, "Video device /dev/video%d closed", cam->v4ldev->minor);
1531 1537
1532 up(&cam->dev_sem); 1538 mutex_unlock(&cam->dev_mutex);
1533 1539
1534 return 0; 1540 return 0;
1535} 1541}
@@ -1541,35 +1547,36 @@ sn9c102_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
1541 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 1547 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
1542 struct sn9c102_frame_t* f, * i; 1548 struct sn9c102_frame_t* f, * i;
1543 unsigned long lock_flags; 1549 unsigned long lock_flags;
1550 long timeout;
1544 int err = 0; 1551 int err = 0;
1545 1552
1546 if (down_interruptible(&cam->fileop_sem)) 1553 if (mutex_lock_interruptible(&cam->fileop_mutex))
1547 return -ERESTARTSYS; 1554 return -ERESTARTSYS;
1548 1555
1549 if (cam->state & DEV_DISCONNECTED) { 1556 if (cam->state & DEV_DISCONNECTED) {
1550 DBG(1, "Device not present"); 1557 DBG(1, "Device not present");
1551 up(&cam->fileop_sem); 1558 mutex_unlock(&cam->fileop_mutex);
1552 return -ENODEV; 1559 return -ENODEV;
1553 } 1560 }
1554 1561
1555 if (cam->state & DEV_MISCONFIGURED) { 1562 if (cam->state & DEV_MISCONFIGURED) {
1556 DBG(1, "The camera is misconfigured. Close and open it " 1563 DBG(1, "The camera is misconfigured. Close and open it "
1557 "again."); 1564 "again.");
1558 up(&cam->fileop_sem); 1565 mutex_unlock(&cam->fileop_mutex);
1559 return -EIO; 1566 return -EIO;
1560 } 1567 }
1561 1568
1562 if (cam->io == IO_MMAP) { 1569 if (cam->io == IO_MMAP) {
1563 DBG(3, "Close and open the device again to choose " 1570 DBG(3, "Close and open the device again to choose "
1564 "the read method"); 1571 "the read method");
1565 up(&cam->fileop_sem); 1572 mutex_unlock(&cam->fileop_mutex);
1566 return -EINVAL; 1573 return -EINVAL;
1567 } 1574 }
1568 1575
1569 if (cam->io == IO_NONE) { 1576 if (cam->io == IO_NONE) {
1570 if (!sn9c102_request_buffers(cam,cam->nreadbuffers, IO_READ)) { 1577 if (!sn9c102_request_buffers(cam,cam->nreadbuffers, IO_READ)) {
1571 DBG(1, "read() failed, not enough memory"); 1578 DBG(1, "read() failed, not enough memory");
1572 up(&cam->fileop_sem); 1579 mutex_unlock(&cam->fileop_mutex);
1573 return -ENOMEM; 1580 return -ENOMEM;
1574 } 1581 }
1575 cam->io = IO_READ; 1582 cam->io = IO_READ;
@@ -1583,30 +1590,32 @@ sn9c102_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
1583 } 1590 }
1584 1591
1585 if (!count) { 1592 if (!count) {
1586 up(&cam->fileop_sem); 1593 mutex_unlock(&cam->fileop_mutex);
1587 return 0; 1594 return 0;
1588 } 1595 }
1589 1596
1590 if (list_empty(&cam->outqueue)) { 1597 if (list_empty(&cam->outqueue)) {
1591 if (filp->f_flags & O_NONBLOCK) { 1598 if (filp->f_flags & O_NONBLOCK) {
1592 up(&cam->fileop_sem); 1599 mutex_unlock(&cam->fileop_mutex);
1593 return -EAGAIN; 1600 return -EAGAIN;
1594 } 1601 }
1595 err = wait_event_interruptible 1602 timeout = wait_event_interruptible_timeout
1596 ( cam->wait_frame, 1603 ( cam->wait_frame,
1597 (!list_empty(&cam->outqueue)) || 1604 (!list_empty(&cam->outqueue)) ||
1598 (cam->state & DEV_DISCONNECTED) || 1605 (cam->state & DEV_DISCONNECTED) ||
1599 (cam->state & DEV_MISCONFIGURED) ); 1606 (cam->state & DEV_MISCONFIGURED),
1600 if (err) { 1607 cam->module_param.frame_timeout *
1601 up(&cam->fileop_sem); 1608 1000 * msecs_to_jiffies(1) );
1602 return err; 1609 if (timeout < 0) {
1610 mutex_unlock(&cam->fileop_mutex);
1611 return timeout;
1603 } 1612 }
1604 if (cam->state & DEV_DISCONNECTED) { 1613 if (cam->state & DEV_DISCONNECTED) {
1605 up(&cam->fileop_sem); 1614 mutex_unlock(&cam->fileop_mutex);
1606 return -ENODEV; 1615 return -ENODEV;
1607 } 1616 }
1608 if (cam->state & DEV_MISCONFIGURED) { 1617 if (!timeout || (cam->state & DEV_MISCONFIGURED)) {
1609 up(&cam->fileop_sem); 1618 mutex_unlock(&cam->fileop_mutex);
1610 return -EIO; 1619 return -EIO;
1611 } 1620 }
1612 } 1621 }
@@ -1634,7 +1643,7 @@ exit:
1634 PDBGG("Frame #%lu, bytes read: %zu", 1643 PDBGG("Frame #%lu, bytes read: %zu",
1635 (unsigned long)f->buf.index, count); 1644 (unsigned long)f->buf.index, count);
1636 1645
1637 up(&cam->fileop_sem); 1646 mutex_unlock(&cam->fileop_mutex);
1638 1647
1639 return count; 1648 return count;
1640} 1649}
@@ -1647,7 +1656,7 @@ static unsigned int sn9c102_poll(struct file *filp, poll_table *wait)
1647 unsigned long lock_flags; 1656 unsigned long lock_flags;
1648 unsigned int mask = 0; 1657 unsigned int mask = 0;
1649 1658
1650 if (down_interruptible(&cam->fileop_sem)) 1659 if (mutex_lock_interruptible(&cam->fileop_mutex))
1651 return POLLERR; 1660 return POLLERR;
1652 1661
1653 if (cam->state & DEV_DISCONNECTED) { 1662 if (cam->state & DEV_DISCONNECTED) {
@@ -1685,12 +1694,12 @@ static unsigned int sn9c102_poll(struct file *filp, poll_table *wait)
1685 if (!list_empty(&cam->outqueue)) 1694 if (!list_empty(&cam->outqueue))
1686 mask |= POLLIN | POLLRDNORM; 1695 mask |= POLLIN | POLLRDNORM;
1687 1696
1688 up(&cam->fileop_sem); 1697 mutex_unlock(&cam->fileop_mutex);
1689 1698
1690 return mask; 1699 return mask;
1691 1700
1692error: 1701error:
1693 up(&cam->fileop_sem); 1702 mutex_unlock(&cam->fileop_mutex);
1694 return POLLERR; 1703 return POLLERR;
1695} 1704}
1696 1705
@@ -1724,25 +1733,25 @@ static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
1724 void *pos; 1733 void *pos;
1725 u32 i; 1734 u32 i;
1726 1735
1727 if (down_interruptible(&cam->fileop_sem)) 1736 if (mutex_lock_interruptible(&cam->fileop_mutex))
1728 return -ERESTARTSYS; 1737 return -ERESTARTSYS;
1729 1738
1730 if (cam->state & DEV_DISCONNECTED) { 1739 if (cam->state & DEV_DISCONNECTED) {
1731 DBG(1, "Device not present"); 1740 DBG(1, "Device not present");
1732 up(&cam->fileop_sem); 1741 mutex_unlock(&cam->fileop_mutex);
1733 return -ENODEV; 1742 return -ENODEV;
1734 } 1743 }
1735 1744
1736 if (cam->state & DEV_MISCONFIGURED) { 1745 if (cam->state & DEV_MISCONFIGURED) {
1737 DBG(1, "The camera is misconfigured. Close and open it " 1746 DBG(1, "The camera is misconfigured. Close and open it "
1738 "again."); 1747 "again.");
1739 up(&cam->fileop_sem); 1748 mutex_unlock(&cam->fileop_mutex);
1740 return -EIO; 1749 return -EIO;
1741 } 1750 }
1742 1751
1743 if (cam->io != IO_MMAP || !(vma->vm_flags & VM_WRITE) || 1752 if (cam->io != IO_MMAP || !(vma->vm_flags & VM_WRITE) ||
1744 size != PAGE_ALIGN(cam->frame[0].buf.length)) { 1753 size != PAGE_ALIGN(cam->frame[0].buf.length)) {
1745 up(&cam->fileop_sem); 1754 mutex_unlock(&cam->fileop_mutex);
1746 return -EINVAL; 1755 return -EINVAL;
1747 } 1756 }
1748 1757
@@ -1751,7 +1760,7 @@ static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
1751 break; 1760 break;
1752 } 1761 }
1753 if (i == cam->nbuffers) { 1762 if (i == cam->nbuffers) {
1754 up(&cam->fileop_sem); 1763 mutex_unlock(&cam->fileop_mutex);
1755 return -EINVAL; 1764 return -EINVAL;
1756 } 1765 }
1757 1766
@@ -1761,7 +1770,7 @@ static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
1761 pos = cam->frame[i].bufmem; 1770 pos = cam->frame[i].bufmem;
1762 while (size > 0) { /* size is page-aligned */ 1771 while (size > 0) { /* size is page-aligned */
1763 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) { 1772 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
1764 up(&cam->fileop_sem); 1773 mutex_unlock(&cam->fileop_mutex);
1765 return -EAGAIN; 1774 return -EAGAIN;
1766 } 1775 }
1767 start += PAGE_SIZE; 1776 start += PAGE_SIZE;
@@ -1774,7 +1783,7 @@ static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
1774 1783
1775 sn9c102_vm_open(vma); 1784 sn9c102_vm_open(vma);
1776 1785
1777 up(&cam->fileop_sem); 1786 mutex_unlock(&cam->fileop_mutex);
1778 1787
1779 return 0; 1788 return 0;
1780} 1789}
@@ -1816,6 +1825,7 @@ sn9c102_vidioc_enuminput(struct sn9c102_device* cam, void __user * arg)
1816 1825
1817 memset(&i, 0, sizeof(i)); 1826 memset(&i, 0, sizeof(i));
1818 strcpy(i.name, "Camera"); 1827 strcpy(i.name, "Camera");
1828 i.type = V4L2_INPUT_TYPE_CAMERA;
1819 1829
1820 if (copy_to_user(arg, &i, sizeof(i))) 1830 if (copy_to_user(arg, &i, sizeof(i)))
1821 return -EFAULT; 1831 return -EFAULT;
@@ -1825,7 +1835,19 @@ sn9c102_vidioc_enuminput(struct sn9c102_device* cam, void __user * arg)
1825 1835
1826 1836
1827static int 1837static int
1828sn9c102_vidioc_gs_input(struct sn9c102_device* cam, void __user * arg) 1838sn9c102_vidioc_g_input(struct sn9c102_device* cam, void __user * arg)
1839{
1840 int index = 0;
1841
1842 if (copy_to_user(arg, &index, sizeof(index)))
1843 return -EFAULT;
1844
1845 return 0;
1846}
1847
1848
1849static int
1850sn9c102_vidioc_s_input(struct sn9c102_device* cam, void __user * arg)
1829{ 1851{
1830 int index; 1852 int index;
1831 1853
@@ -1842,7 +1864,7 @@ sn9c102_vidioc_gs_input(struct sn9c102_device* cam, void __user * arg)
1842static int 1864static int
1843sn9c102_vidioc_query_ctrl(struct sn9c102_device* cam, void __user * arg) 1865sn9c102_vidioc_query_ctrl(struct sn9c102_device* cam, void __user * arg)
1844{ 1866{
1845 struct sn9c102_sensor* s = cam->sensor; 1867 struct sn9c102_sensor* s = &cam->sensor;
1846 struct v4l2_queryctrl qc; 1868 struct v4l2_queryctrl qc;
1847 u8 i; 1869 u8 i;
1848 1870
@@ -1864,7 +1886,7 @@ sn9c102_vidioc_query_ctrl(struct sn9c102_device* cam, void __user * arg)
1864static int 1886static int
1865sn9c102_vidioc_g_ctrl(struct sn9c102_device* cam, void __user * arg) 1887sn9c102_vidioc_g_ctrl(struct sn9c102_device* cam, void __user * arg)
1866{ 1888{
1867 struct sn9c102_sensor* s = cam->sensor; 1889 struct sn9c102_sensor* s = &cam->sensor;
1868 struct v4l2_control ctrl; 1890 struct v4l2_control ctrl;
1869 int err = 0; 1891 int err = 0;
1870 u8 i; 1892 u8 i;
@@ -1896,7 +1918,7 @@ exit:
1896static int 1918static int
1897sn9c102_vidioc_s_ctrl(struct sn9c102_device* cam, void __user * arg) 1919sn9c102_vidioc_s_ctrl(struct sn9c102_device* cam, void __user * arg)
1898{ 1920{
1899 struct sn9c102_sensor* s = cam->sensor; 1921 struct sn9c102_sensor* s = &cam->sensor;
1900 struct v4l2_control ctrl; 1922 struct v4l2_control ctrl;
1901 u8 i; 1923 u8 i;
1902 int err = 0; 1924 int err = 0;
@@ -1909,6 +1931,8 @@ sn9c102_vidioc_s_ctrl(struct sn9c102_device* cam, void __user * arg)
1909 1931
1910 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++) 1932 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
1911 if (ctrl.id == s->qctrl[i].id) { 1933 if (ctrl.id == s->qctrl[i].id) {
1934 if (s->qctrl[i].flags & V4L2_CTRL_FLAG_DISABLED)
1935 return -EINVAL;
1912 if (ctrl.value < s->qctrl[i].minimum || 1936 if (ctrl.value < s->qctrl[i].minimum ||
1913 ctrl.value > s->qctrl[i].maximum) 1937 ctrl.value > s->qctrl[i].maximum)
1914 return -ERANGE; 1938 return -ERANGE;
@@ -1931,7 +1955,7 @@ sn9c102_vidioc_s_ctrl(struct sn9c102_device* cam, void __user * arg)
1931static int 1955static int
1932sn9c102_vidioc_cropcap(struct sn9c102_device* cam, void __user * arg) 1956sn9c102_vidioc_cropcap(struct sn9c102_device* cam, void __user * arg)
1933{ 1957{
1934 struct v4l2_cropcap* cc = &(cam->sensor->cropcap); 1958 struct v4l2_cropcap* cc = &(cam->sensor.cropcap);
1935 1959
1936 cc->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1960 cc->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1937 cc->pixelaspect.numerator = 1; 1961 cc->pixelaspect.numerator = 1;
@@ -1947,7 +1971,7 @@ sn9c102_vidioc_cropcap(struct sn9c102_device* cam, void __user * arg)
1947static int 1971static int
1948sn9c102_vidioc_g_crop(struct sn9c102_device* cam, void __user * arg) 1972sn9c102_vidioc_g_crop(struct sn9c102_device* cam, void __user * arg)
1949{ 1973{
1950 struct sn9c102_sensor* s = cam->sensor; 1974 struct sn9c102_sensor* s = &cam->sensor;
1951 struct v4l2_crop crop = { 1975 struct v4l2_crop crop = {
1952 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, 1976 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
1953 }; 1977 };
@@ -1964,7 +1988,7 @@ sn9c102_vidioc_g_crop(struct sn9c102_device* cam, void __user * arg)
1964static int 1988static int
1965sn9c102_vidioc_s_crop(struct sn9c102_device* cam, void __user * arg) 1989sn9c102_vidioc_s_crop(struct sn9c102_device* cam, void __user * arg)
1966{ 1990{
1967 struct sn9c102_sensor* s = cam->sensor; 1991 struct sn9c102_sensor* s = &cam->sensor;
1968 struct v4l2_crop crop; 1992 struct v4l2_crop crop;
1969 struct v4l2_rect* rect; 1993 struct v4l2_rect* rect;
1970 struct v4l2_rect* bounds = &(s->cropcap.bounds); 1994 struct v4l2_rect* bounds = &(s->cropcap.bounds);
@@ -2105,7 +2129,7 @@ static int
2105sn9c102_vidioc_g_fmt(struct sn9c102_device* cam, void __user * arg) 2129sn9c102_vidioc_g_fmt(struct sn9c102_device* cam, void __user * arg)
2106{ 2130{
2107 struct v4l2_format format; 2131 struct v4l2_format format;
2108 struct v4l2_pix_format* pfmt = &(cam->sensor->pix_format); 2132 struct v4l2_pix_format* pfmt = &(cam->sensor.pix_format);
2109 2133
2110 if (copy_from_user(&format, arg, sizeof(format))) 2134 if (copy_from_user(&format, arg, sizeof(format)))
2111 return -EFAULT; 2135 return -EFAULT;
@@ -2130,7 +2154,7 @@ static int
2130sn9c102_vidioc_try_s_fmt(struct sn9c102_device* cam, unsigned int cmd, 2154sn9c102_vidioc_try_s_fmt(struct sn9c102_device* cam, unsigned int cmd,
2131 void __user * arg) 2155 void __user * arg)
2132{ 2156{
2133 struct sn9c102_sensor* s = cam->sensor; 2157 struct sn9c102_sensor* s = &cam->sensor;
2134 struct v4l2_format format; 2158 struct v4l2_format format;
2135 struct v4l2_pix_format* pix; 2159 struct v4l2_pix_format* pix;
2136 struct v4l2_pix_format* pfmt = &(s->pix_format); 2160 struct v4l2_pix_format* pfmt = &(s->pix_format);
@@ -2417,7 +2441,7 @@ sn9c102_vidioc_dqbuf(struct sn9c102_device* cam, struct file* filp,
2417 struct v4l2_buffer b; 2441 struct v4l2_buffer b;
2418 struct sn9c102_frame_t *f; 2442 struct sn9c102_frame_t *f;
2419 unsigned long lock_flags; 2443 unsigned long lock_flags;
2420 int err = 0; 2444 long timeout;
2421 2445
2422 if (copy_from_user(&b, arg, sizeof(b))) 2446 if (copy_from_user(&b, arg, sizeof(b)))
2423 return -EFAULT; 2447 return -EFAULT;
@@ -2430,16 +2454,18 @@ sn9c102_vidioc_dqbuf(struct sn9c102_device* cam, struct file* filp,
2430 return -EINVAL; 2454 return -EINVAL;
2431 if (filp->f_flags & O_NONBLOCK) 2455 if (filp->f_flags & O_NONBLOCK)
2432 return -EAGAIN; 2456 return -EAGAIN;
2433 err = wait_event_interruptible 2457 timeout = wait_event_interruptible_timeout
2434 ( cam->wait_frame, 2458 ( cam->wait_frame,
2435 (!list_empty(&cam->outqueue)) || 2459 (!list_empty(&cam->outqueue)) ||
2436 (cam->state & DEV_DISCONNECTED) || 2460 (cam->state & DEV_DISCONNECTED) ||
2437 (cam->state & DEV_MISCONFIGURED) ); 2461 (cam->state & DEV_MISCONFIGURED),
2438 if (err) 2462 cam->module_param.frame_timeout *
2439 return err; 2463 1000 * msecs_to_jiffies(1) );
2464 if (timeout < 0)
2465 return timeout;
2440 if (cam->state & DEV_DISCONNECTED) 2466 if (cam->state & DEV_DISCONNECTED)
2441 return -ENODEV; 2467 return -ENODEV;
2442 if (cam->state & DEV_MISCONFIGURED) 2468 if (!timeout || (cam->state & DEV_MISCONFIGURED))
2443 return -EIO; 2469 return -EIO;
2444 } 2470 }
2445 2471
@@ -2571,8 +2597,10 @@ static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
2571 return sn9c102_vidioc_enuminput(cam, arg); 2597 return sn9c102_vidioc_enuminput(cam, arg);
2572 2598
2573 case VIDIOC_G_INPUT: 2599 case VIDIOC_G_INPUT:
2600 return sn9c102_vidioc_g_input(cam, arg);
2601
2574 case VIDIOC_S_INPUT: 2602 case VIDIOC_S_INPUT:
2575 return sn9c102_vidioc_gs_input(cam, arg); 2603 return sn9c102_vidioc_s_input(cam, arg);
2576 2604
2577 case VIDIOC_QUERYCTRL: 2605 case VIDIOC_QUERYCTRL:
2578 return sn9c102_vidioc_query_ctrl(cam, arg); 2606 return sn9c102_vidioc_query_ctrl(cam, arg);
@@ -2655,19 +2683,19 @@ static int sn9c102_ioctl(struct inode* inode, struct file* filp,
2655 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 2683 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
2656 int err = 0; 2684 int err = 0;
2657 2685
2658 if (down_interruptible(&cam->fileop_sem)) 2686 if (mutex_lock_interruptible(&cam->fileop_mutex))
2659 return -ERESTARTSYS; 2687 return -ERESTARTSYS;
2660 2688
2661 if (cam->state & DEV_DISCONNECTED) { 2689 if (cam->state & DEV_DISCONNECTED) {
2662 DBG(1, "Device not present"); 2690 DBG(1, "Device not present");
2663 up(&cam->fileop_sem); 2691 mutex_unlock(&cam->fileop_mutex);
2664 return -ENODEV; 2692 return -ENODEV;
2665 } 2693 }
2666 2694
2667 if (cam->state & DEV_MISCONFIGURED) { 2695 if (cam->state & DEV_MISCONFIGURED) {
2668 DBG(1, "The camera is misconfigured. Close and open it " 2696 DBG(1, "The camera is misconfigured. Close and open it "
2669 "again."); 2697 "again.");
2670 up(&cam->fileop_sem); 2698 mutex_unlock(&cam->fileop_mutex);
2671 return -EIO; 2699 return -EIO;
2672 } 2700 }
2673 2701
@@ -2675,7 +2703,7 @@ static int sn9c102_ioctl(struct inode* inode, struct file* filp,
2675 2703
2676 err = sn9c102_ioctl_v4l2(inode, filp, cmd, (void __user *)arg); 2704 err = sn9c102_ioctl_v4l2(inode, filp, cmd, (void __user *)arg);
2677 2705
2678 up(&cam->fileop_sem); 2706 mutex_unlock(&cam->fileop_mutex);
2679 2707
2680 return err; 2708 return err;
2681} 2709}
@@ -2722,7 +2750,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2722 goto fail; 2750 goto fail;
2723 } 2751 }
2724 2752
2725 init_MUTEX(&cam->dev_sem); 2753 mutex_init(&cam->dev_mutex);
2726 2754
2727 r = sn9c102_read_reg(cam, 0x00); 2755 r = sn9c102_read_reg(cam, 0x00);
2728 if (r < 0 || r != 0x10) { 2756 if (r < 0 || r != 0x10) {
@@ -2752,10 +2780,10 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2752 break; 2780 break;
2753 } 2781 }
2754 2782
2755 if (!err && cam->sensor) { 2783 if (!err) {
2756 DBG(2, "%s image sensor detected", cam->sensor->name); 2784 DBG(2, "%s image sensor detected", cam->sensor.name);
2757 DBG(3, "Support for %s maintained by %s", 2785 DBG(3, "Support for %s maintained by %s",
2758 cam->sensor->name, cam->sensor->maintainer); 2786 cam->sensor.name, cam->sensor.maintainer);
2759 } else { 2787 } else {
2760 DBG(1, "No supported image sensor detected"); 2788 DBG(1, "No supported image sensor detected");
2761 err = -ENODEV; 2789 err = -ENODEV;
@@ -2776,7 +2804,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2776 cam->v4ldev->release = video_device_release; 2804 cam->v4ldev->release = video_device_release;
2777 video_set_drvdata(cam->v4ldev, cam); 2805 video_set_drvdata(cam->v4ldev, cam);
2778 2806
2779 down(&cam->dev_sem); 2807 mutex_lock(&cam->dev_mutex);
2780 2808
2781 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER, 2809 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
2782 video_nr[dev_nr]); 2810 video_nr[dev_nr]);
@@ -2786,13 +2814,14 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2786 DBG(1, "Free /dev/videoX node not found"); 2814 DBG(1, "Free /dev/videoX node not found");
2787 video_nr[dev_nr] = -1; 2815 video_nr[dev_nr] = -1;
2788 dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0; 2816 dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0;
2789 up(&cam->dev_sem); 2817 mutex_unlock(&cam->dev_mutex);
2790 goto fail; 2818 goto fail;
2791 } 2819 }
2792 2820
2793 DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->minor); 2821 DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->minor);
2794 2822
2795 cam->module_param.force_munmap = force_munmap[dev_nr]; 2823 cam->module_param.force_munmap = force_munmap[dev_nr];
2824 cam->module_param.frame_timeout = frame_timeout[dev_nr];
2796 2825
2797 dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0; 2826 dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0;
2798 2827
@@ -2803,7 +2832,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2803 2832
2804 usb_set_intfdata(intf, cam); 2833 usb_set_intfdata(intf, cam);
2805 2834
2806 up(&cam->dev_sem); 2835 mutex_unlock(&cam->dev_mutex);
2807 2836
2808 return 0; 2837 return 0;
2809 2838
@@ -2827,7 +2856,7 @@ static void sn9c102_usb_disconnect(struct usb_interface* intf)
2827 2856
2828 down_write(&sn9c102_disconnect); 2857 down_write(&sn9c102_disconnect);
2829 2858
2830 down(&cam->dev_sem); 2859 mutex_lock(&cam->dev_mutex);
2831 2860
2832 DBG(2, "Disconnecting %s...", cam->v4ldev->name); 2861 DBG(2, "Disconnecting %s...", cam->v4ldev->name);
2833 2862
@@ -2841,13 +2870,14 @@ static void sn9c102_usb_disconnect(struct usb_interface* intf)
2841 sn9c102_stop_transfer(cam); 2870 sn9c102_stop_transfer(cam);
2842 cam->state |= DEV_DISCONNECTED; 2871 cam->state |= DEV_DISCONNECTED;
2843 wake_up_interruptible(&cam->wait_frame); 2872 wake_up_interruptible(&cam->wait_frame);
2844 wake_up_interruptible(&cam->wait_stream); 2873 wake_up(&cam->wait_stream);
2874 usb_get_dev(cam->usbdev);
2845 } else { 2875 } else {
2846 cam->state |= DEV_DISCONNECTED; 2876 cam->state |= DEV_DISCONNECTED;
2847 sn9c102_release_resources(cam); 2877 sn9c102_release_resources(cam);
2848 } 2878 }
2849 2879
2850 up(&cam->dev_sem); 2880 mutex_unlock(&cam->dev_mutex);
2851 2881
2852 if (!cam->users) 2882 if (!cam->users)
2853 kfree(cam); 2883 kfree(cam);
diff --git a/drivers/usb/media/sn9c102_ov7630.c b/drivers/usb/media/sn9c102_ov7630.c
index 4a36519b5af4..42852b7cb042 100644
--- a/drivers/usb/media/sn9c102_ov7630.c
+++ b/drivers/usb/media/sn9c102_ov7630.c
@@ -34,8 +34,8 @@ static int ov7630_init(struct sn9c102_device* cam)
34 err += sn9c102_write_reg(cam, 0x0f, 0x18); 34 err += sn9c102_write_reg(cam, 0x0f, 0x18);
35 err += sn9c102_write_reg(cam, 0x50, 0x19); 35 err += sn9c102_write_reg(cam, 0x50, 0x19);
36 36
37 err += sn9c102_i2c_write(cam, 0x12, 0x8d); 37 err += sn9c102_i2c_write(cam, 0x12, 0x80);
38 err += sn9c102_i2c_write(cam, 0x11, 0x00); 38 err += sn9c102_i2c_write(cam, 0x11, 0x01);
39 err += sn9c102_i2c_write(cam, 0x15, 0x34); 39 err += sn9c102_i2c_write(cam, 0x15, 0x34);
40 err += sn9c102_i2c_write(cam, 0x16, 0x03); 40 err += sn9c102_i2c_write(cam, 0x16, 0x03);
41 err += sn9c102_i2c_write(cam, 0x17, 0x1c); 41 err += sn9c102_i2c_write(cam, 0x17, 0x1c);
@@ -43,12 +43,14 @@ static int ov7630_init(struct sn9c102_device* cam)
43 err += sn9c102_i2c_write(cam, 0x19, 0x06); 43 err += sn9c102_i2c_write(cam, 0x19, 0x06);
44 err += sn9c102_i2c_write(cam, 0x1a, 0xf6); 44 err += sn9c102_i2c_write(cam, 0x1a, 0xf6);
45 err += sn9c102_i2c_write(cam, 0x1b, 0x04); 45 err += sn9c102_i2c_write(cam, 0x1b, 0x04);
46 err += sn9c102_i2c_write(cam, 0x20, 0x44); 46 err += sn9c102_i2c_write(cam, 0x20, 0xf6);
47 err += sn9c102_i2c_write(cam, 0x23, 0xee); 47 err += sn9c102_i2c_write(cam, 0x23, 0xee);
48 err += sn9c102_i2c_write(cam, 0x26, 0xa0); 48 err += sn9c102_i2c_write(cam, 0x26, 0xa0);
49 err += sn9c102_i2c_write(cam, 0x27, 0x9a); 49 err += sn9c102_i2c_write(cam, 0x27, 0x9a);
50 err += sn9c102_i2c_write(cam, 0x28, 0x20); 50 err += sn9c102_i2c_write(cam, 0x28, 0xa0);
51 err += sn9c102_i2c_write(cam, 0x29, 0x30); 51 err += sn9c102_i2c_write(cam, 0x29, 0x30);
52 err += sn9c102_i2c_write(cam, 0x2a, 0xa0);
53 err += sn9c102_i2c_write(cam, 0x2b, 0x1f);
52 err += sn9c102_i2c_write(cam, 0x2f, 0x3d); 54 err += sn9c102_i2c_write(cam, 0x2f, 0x3d);
53 err += sn9c102_i2c_write(cam, 0x30, 0x24); 55 err += sn9c102_i2c_write(cam, 0x30, 0x24);
54 err += sn9c102_i2c_write(cam, 0x32, 0x86); 56 err += sn9c102_i2c_write(cam, 0x32, 0x86);
@@ -80,7 +82,7 @@ static int ov7630_set_ctrl(struct sn9c102_device* cam,
80 err += sn9c102_i2c_write(cam, 0x02, ctrl->value); 82 err += sn9c102_i2c_write(cam, 0x02, ctrl->value);
81 break; 83 break;
82 case V4L2_CID_BLUE_BALANCE: 84 case V4L2_CID_BLUE_BALANCE:
83 err += sn9c102_i2c_write(cam, 0x03, ctrl->value); 85 err += sn9c102_i2c_write(cam, 0x01, ctrl->value);
84 break; 86 break;
85 case V4L2_CID_GAIN: 87 case V4L2_CID_GAIN:
86 err += sn9c102_i2c_write(cam, 0x00, ctrl->value); 88 err += sn9c102_i2c_write(cam, 0x00, ctrl->value);
@@ -108,7 +110,7 @@ static int ov7630_set_ctrl(struct sn9c102_device* cam,
108 err += sn9c102_i2c_write(cam, 0x0d, ctrl->value); 110 err += sn9c102_i2c_write(cam, 0x0d, ctrl->value);
109 break; 111 break;
110 case V4L2_CID_AUTO_WHITE_BALANCE: 112 case V4L2_CID_AUTO_WHITE_BALANCE:
111 err += sn9c102_i2c_write(cam, 0x12, (ctrl->value << 2) | 0x09); 113 err += sn9c102_i2c_write(cam, 0x12, (ctrl->value << 2) | 0x78);
112 break; 114 break;
113 case V4L2_CID_AUTOGAIN: 115 case V4L2_CID_AUTOGAIN:
114 err += sn9c102_i2c_write(cam, 0x13, ctrl->value); 116 err += sn9c102_i2c_write(cam, 0x13, ctrl->value);
@@ -371,26 +373,29 @@ static struct sn9c102_sensor ov7630 = {
371 373
372int sn9c102_probe_ov7630(struct sn9c102_device* cam) 374int sn9c102_probe_ov7630(struct sn9c102_device* cam)
373{ 375{
376 const struct usb_device_id ov7630_id_table[] = {
377 { USB_DEVICE(0x0c45, 0x602c), },
378 { USB_DEVICE(0x0c45, 0x602d), },
379 { USB_DEVICE(0x0c45, 0x608f), },
380 { USB_DEVICE(0x0c45, 0x60b0), },
381 { }
382 };
374 int err = 0; 383 int err = 0;
375 384
376 sn9c102_attach_sensor(cam, &ov7630); 385 if (!sn9c102_match_id(cam, ov7630_id_table))
377
378 if (le16_to_cpu(ov7630.usbdev->descriptor.idProduct) != 0x602c &&
379 le16_to_cpu(ov7630.usbdev->descriptor.idProduct) != 0x602d &&
380 le16_to_cpu(ov7630.usbdev->descriptor.idProduct) != 0x608f &&
381 le16_to_cpu(ov7630.usbdev->descriptor.idProduct) != 0x60b0)
382 return -ENODEV; 386 return -ENODEV;
383 387
384 err += sn9c102_write_reg(cam, 0x01, 0x01); 388 err += sn9c102_write_reg(cam, 0x01, 0x01);
385 err += sn9c102_write_reg(cam, 0x00, 0x01); 389 err += sn9c102_write_reg(cam, 0x00, 0x01);
386 err += sn9c102_write_reg(cam, 0x28, 0x17); 390 err += sn9c102_write_reg(cam, 0x28, 0x17);
387
388 if (err) 391 if (err)
389 return -EIO; 392 return -EIO;
390 393
391 err += sn9c102_i2c_write(cam, 0x0b, 0); 394 err += sn9c102_i2c_try_write(cam, &ov7630, 0x0b, 0);
392 if (err) 395 if (err)
393 return -ENODEV; 396 return -ENODEV;
394 397
398 sn9c102_attach_sensor(cam, &ov7630);
399
395 return 0; 400 return 0;
396} 401}
diff --git a/drivers/usb/media/sn9c102_pas202bca.c b/drivers/usb/media/sn9c102_pas202bca.c
new file mode 100644
index 000000000000..3453237055bb
--- /dev/null
+++ b/drivers/usb/media/sn9c102_pas202bca.c
@@ -0,0 +1,238 @@
1/***************************************************************************
2 * Plug-in for PAS202BCA image sensor connected to the SN9C10x PC Camera *
3 * Controllers *
4 * *
5 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
20 ***************************************************************************/
21
22#include <linux/delay.h>
23#include "sn9c102_sensor.h"
24
25
26static struct sn9c102_sensor pas202bca;
27
28
29static int pas202bca_init(struct sn9c102_device* cam)
30{
31 int err = 0;
32
33 err += sn9c102_write_reg(cam, 0x00, 0x10);
34 err += sn9c102_write_reg(cam, 0x00, 0x11);
35 err += sn9c102_write_reg(cam, 0x00, 0x14);
36 err += sn9c102_write_reg(cam, 0x20, 0x17);
37 err += sn9c102_write_reg(cam, 0x30, 0x19);
38 err += sn9c102_write_reg(cam, 0x09, 0x18);
39
40 err += sn9c102_i2c_write(cam, 0x02, 0x14);
41 err += sn9c102_i2c_write(cam, 0x03, 0x40);
42 err += sn9c102_i2c_write(cam, 0x0d, 0x2c);
43 err += sn9c102_i2c_write(cam, 0x0e, 0x01);
44 err += sn9c102_i2c_write(cam, 0x0f, 0xa9);
45 err += sn9c102_i2c_write(cam, 0x10, 0x08);
46 err += sn9c102_i2c_write(cam, 0x13, 0x63);
47 err += sn9c102_i2c_write(cam, 0x15, 0x70);
48 err += sn9c102_i2c_write(cam, 0x11, 0x01);
49
50 msleep(400);
51
52 return err;
53}
54
55
56static int pas202bca_set_pix_format(struct sn9c102_device* cam,
57 const struct v4l2_pix_format* pix)
58{
59 int err = 0;
60
61 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X)
62 err += sn9c102_write_reg(cam, 0x24, 0x17);
63 else
64 err += sn9c102_write_reg(cam, 0x20, 0x17);
65
66 return err;
67}
68
69
70static int pas202bca_set_ctrl(struct sn9c102_device* cam,
71 const struct v4l2_control* ctrl)
72{
73 int err = 0;
74
75 switch (ctrl->id) {
76 case V4L2_CID_EXPOSURE:
77 err += sn9c102_i2c_write(cam, 0x04, ctrl->value >> 6);
78 err += sn9c102_i2c_write(cam, 0x05, ctrl->value & 0x3f);
79 break;
80 case V4L2_CID_RED_BALANCE:
81 err += sn9c102_i2c_write(cam, 0x09, ctrl->value);
82 break;
83 case V4L2_CID_BLUE_BALANCE:
84 err += sn9c102_i2c_write(cam, 0x07, ctrl->value);
85 break;
86 case V4L2_CID_GAIN:
87 err += sn9c102_i2c_write(cam, 0x10, ctrl->value);
88 break;
89 case SN9C102_V4L2_CID_GREEN_BALANCE:
90 err += sn9c102_i2c_write(cam, 0x08, ctrl->value);
91 break;
92 case SN9C102_V4L2_CID_DAC_MAGNITUDE:
93 err += sn9c102_i2c_write(cam, 0x0c, ctrl->value);
94 break;
95 default:
96 return -EINVAL;
97 }
98 err += sn9c102_i2c_write(cam, 0x11, 0x01);
99
100 return err ? -EIO : 0;
101}
102
103
104static int pas202bca_set_crop(struct sn9c102_device* cam,
105 const struct v4l2_rect* rect)
106{
107 struct sn9c102_sensor* s = &pas202bca;
108 int err = 0;
109 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 3,
110 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 3;
111
112 err += sn9c102_write_reg(cam, h_start, 0x12);
113 err += sn9c102_write_reg(cam, v_start, 0x13);
114
115 return err;
116}
117
118
119static struct sn9c102_sensor pas202bca = {
120 .name = "PAS202BCA",
121 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
122 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE,
123 .frequency = SN9C102_I2C_400KHZ | SN9C102_I2C_100KHZ,
124 .interface = SN9C102_I2C_2WIRES,
125 .i2c_slave_id = 0x40,
126 .init = &pas202bca_init,
127 .qctrl = {
128 {
129 .id = V4L2_CID_EXPOSURE,
130 .type = V4L2_CTRL_TYPE_INTEGER,
131 .name = "exposure",
132 .minimum = 0x01e5,
133 .maximum = 0x3fff,
134 .step = 0x0001,
135 .default_value = 0x01e5,
136 .flags = 0,
137 },
138 {
139 .id = V4L2_CID_GAIN,
140 .type = V4L2_CTRL_TYPE_INTEGER,
141 .name = "global gain",
142 .minimum = 0x00,
143 .maximum = 0x1f,
144 .step = 0x01,
145 .default_value = 0x0c,
146 .flags = 0,
147 },
148 {
149 .id = V4L2_CID_RED_BALANCE,
150 .type = V4L2_CTRL_TYPE_INTEGER,
151 .name = "red balance",
152 .minimum = 0x00,
153 .maximum = 0x0f,
154 .step = 0x01,
155 .default_value = 0x01,
156 .flags = 0,
157 },
158 {
159 .id = V4L2_CID_BLUE_BALANCE,
160 .type = V4L2_CTRL_TYPE_INTEGER,
161 .name = "blue balance",
162 .minimum = 0x00,
163 .maximum = 0x0f,
164 .step = 0x01,
165 .default_value = 0x05,
166 .flags = 0,
167 },
168 {
169 .id = SN9C102_V4L2_CID_GREEN_BALANCE,
170 .type = V4L2_CTRL_TYPE_INTEGER,
171 .name = "green balance",
172 .minimum = 0x00,
173 .maximum = 0x0f,
174 .step = 0x01,
175 .default_value = 0x00,
176 .flags = 0,
177 },
178 {
179 .id = SN9C102_V4L2_CID_DAC_MAGNITUDE,
180 .type = V4L2_CTRL_TYPE_INTEGER,
181 .name = "DAC magnitude",
182 .minimum = 0x00,
183 .maximum = 0xff,
184 .step = 0x01,
185 .default_value = 0x04,
186 .flags = 0,
187 },
188 },
189 .set_ctrl = &pas202bca_set_ctrl,
190 .cropcap = {
191 .bounds = {
192 .left = 0,
193 .top = 0,
194 .width = 640,
195 .height = 480,
196 },
197 .defrect = {
198 .left = 0,
199 .top = 0,
200 .width = 640,
201 .height = 480,
202 },
203 },
204 .set_crop = &pas202bca_set_crop,
205 .pix_format = {
206 .width = 640,
207 .height = 480,
208 .pixelformat = V4L2_PIX_FMT_SBGGR8,
209 .priv = 8,
210 },
211 .set_pix_format = &pas202bca_set_pix_format
212};
213
214
215int sn9c102_probe_pas202bca(struct sn9c102_device* cam)
216{
217 const struct usb_device_id pas202bca_id_table[] = {
218 { USB_DEVICE(0x0c45, 0x60af), },
219 { }
220 };
221 int err = 0;
222
223 if (!sn9c102_match_id(cam,pas202bca_id_table))
224 return -ENODEV;
225
226 err += sn9c102_write_reg(cam, 0x01, 0x01);
227 err += sn9c102_write_reg(cam, 0x40, 0x01);
228 err += sn9c102_write_reg(cam, 0x28, 0x17);
229 if (err)
230 return -EIO;
231
232 if (sn9c102_i2c_try_write(cam, &pas202bca, 0x10, 0)) /* try to write */
233 return -ENODEV;
234
235 sn9c102_attach_sensor(cam, &pas202bca);
236
237 return 0;
238}
diff --git a/drivers/usb/media/sn9c102_pas202bcb.c b/drivers/usb/media/sn9c102_pas202bcb.c
index 5ca54c7daaf2..d068616ab337 100644
--- a/drivers/usb/media/sn9c102_pas202bcb.c
+++ b/drivers/usb/media/sn9c102_pas202bcb.c
@@ -263,7 +263,7 @@ static struct sn9c102_sensor pas202bcb = {
263 263
264 264
265int sn9c102_probe_pas202bcb(struct sn9c102_device* cam) 265int sn9c102_probe_pas202bcb(struct sn9c102_device* cam)
266{ 266{
267 int r0 = 0, r1 = 0, err = 0; 267 int r0 = 0, r1 = 0, err = 0;
268 unsigned int pid = 0; 268 unsigned int pid = 0;
269 269
diff --git a/drivers/usb/media/sn9c102_sensor.h b/drivers/usb/media/sn9c102_sensor.h
index 7d953b24f2f2..2afd9e9d09bb 100644
--- a/drivers/usb/media/sn9c102_sensor.h
+++ b/drivers/usb/media/sn9c102_sensor.h
@@ -66,6 +66,7 @@ extern int sn9c102_probe_hv7131d(struct sn9c102_device* cam);
66extern int sn9c102_probe_mi0343(struct sn9c102_device* cam); 66extern int sn9c102_probe_mi0343(struct sn9c102_device* cam);
67extern int sn9c102_probe_ov7630(struct sn9c102_device* cam); 67extern int sn9c102_probe_ov7630(struct sn9c102_device* cam);
68extern int sn9c102_probe_pas106b(struct sn9c102_device* cam); 68extern int sn9c102_probe_pas106b(struct sn9c102_device* cam);
69extern int sn9c102_probe_pas202bca(struct sn9c102_device* cam);
69extern int sn9c102_probe_pas202bcb(struct sn9c102_device* cam); 70extern int sn9c102_probe_pas202bcb(struct sn9c102_device* cam);
70extern int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam); 71extern int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam);
71extern int sn9c102_probe_tas5130d1b(struct sn9c102_device* cam); 72extern int sn9c102_probe_tas5130d1b(struct sn9c102_device* cam);
@@ -81,12 +82,17 @@ static int (*sn9c102_sensor_table[])(struct sn9c102_device*) = { \
81 &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */ \ 82 &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */ \
82 &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */ \ 83 &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */ \
83 &sn9c102_probe_hv7131d, /* strong detection based on SENSOR ids */ \ 84 &sn9c102_probe_hv7131d, /* strong detection based on SENSOR ids */ \
85 &sn9c102_probe_pas202bca, /* detection mostly based on USB pid/vid */ \
84 &sn9c102_probe_ov7630, /* detection mostly based on USB pid/vid */ \ 86 &sn9c102_probe_ov7630, /* detection mostly based on USB pid/vid */ \
85 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */ \ 87 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */ \
86 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */ \ 88 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */ \
87 NULL, \ 89 NULL, \
88}; 90};
89 91
92/* Device identification */
93extern struct sn9c102_device*
94sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id);
95
90/* Attach a probed sensor to the camera. */ 96/* Attach a probed sensor to the camera. */
91extern void 97extern void
92sn9c102_attach_sensor(struct sn9c102_device* cam, 98sn9c102_attach_sensor(struct sn9c102_device* cam,
@@ -108,6 +114,7 @@ sn9c102_attach_sensor(struct sn9c102_device* cam,
108static const struct usb_device_id sn9c102_id_table[] = { \ 114static const struct usb_device_id sn9c102_id_table[] = { \
109 { USB_DEVICE(0x0c45, 0x6001), }, /* TAS5110C1B */ \ 115 { USB_DEVICE(0x0c45, 0x6001), }, /* TAS5110C1B */ \
110 { USB_DEVICE(0x0c45, 0x6005), }, /* TAS5110C1B */ \ 116 { USB_DEVICE(0x0c45, 0x6005), }, /* TAS5110C1B */ \
117 { USB_DEVICE(0x0c45, 0x6007), }, \
111 { USB_DEVICE(0x0c45, 0x6009), }, /* PAS106B */ \ 118 { USB_DEVICE(0x0c45, 0x6009), }, /* PAS106B */ \
112 { USB_DEVICE(0x0c45, 0x600d), }, /* PAS106B */ \ 119 { USB_DEVICE(0x0c45, 0x600d), }, /* PAS106B */ \
113 { USB_DEVICE(0x0c45, 0x6024), }, \ 120 { USB_DEVICE(0x0c45, 0x6024), }, \
@@ -126,7 +133,7 @@ static const struct usb_device_id sn9c102_id_table[] = { \
126 { SN9C102_USB_DEVICE(0x0c45, 0x6088, 0xff), }, \ 133 { SN9C102_USB_DEVICE(0x0c45, 0x6088, 0xff), }, \
127 { SN9C102_USB_DEVICE(0x0c45, 0x608a, 0xff), }, \ 134 { SN9C102_USB_DEVICE(0x0c45, 0x608a, 0xff), }, \
128 { SN9C102_USB_DEVICE(0x0c45, 0x608b, 0xff), }, \ 135 { SN9C102_USB_DEVICE(0x0c45, 0x608b, 0xff), }, \
129 { SN9C102_USB_DEVICE(0x0c45, 0x608c, 0xff), }, /* HV7131x */ \ 136 { SN9C102_USB_DEVICE(0x0c45, 0x608c, 0xff), }, /* HV7131/R */ \
130 { SN9C102_USB_DEVICE(0x0c45, 0x608e, 0xff), }, /* CIS-VF10 */ \ 137 { SN9C102_USB_DEVICE(0x0c45, 0x608e, 0xff), }, /* CIS-VF10 */ \
131 { SN9C102_USB_DEVICE(0x0c45, 0x608f, 0xff), }, /* OV7630 */ \ 138 { SN9C102_USB_DEVICE(0x0c45, 0x608f, 0xff), }, /* OV7630 */ \
132 { SN9C102_USB_DEVICE(0x0c45, 0x60a0, 0xff), }, \ 139 { SN9C102_USB_DEVICE(0x0c45, 0x60a0, 0xff), }, \
@@ -359,12 +366,6 @@ struct sn9c102_sensor {
359 error code without rolling back. 366 error code without rolling back.
360 */ 367 */
361 368
362 const struct usb_device* usbdev;
363 /*
364 Points to the usb_device struct after the sensor is attached.
365 Do not touch unless you know what you are doing.
366 */
367
368 /* 369 /*
369 Do NOT write to the data below, it's READ ONLY. It is used by the 370 Do NOT write to the data below, it's READ ONLY. It is used by the
370 core module to store successfully updated values of the above 371 core module to store successfully updated values of the above
diff --git a/drivers/usb/media/sn9c102_tas5110c1b.c b/drivers/usb/media/sn9c102_tas5110c1b.c
index 32ddf236cafe..2e08c552f40a 100644
--- a/drivers/usb/media/sn9c102_tas5110c1b.c
+++ b/drivers/usb/media/sn9c102_tas5110c1b.c
@@ -142,14 +142,18 @@ static struct sn9c102_sensor tas5110c1b = {
142 142
143int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam) 143int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam)
144{ 144{
145 /* This sensor has no identifiers, so let's attach it anyway */ 145 const struct usb_device_id tas5110c1b_id_table[] = {
146 sn9c102_attach_sensor(cam, &tas5110c1b); 146 { USB_DEVICE(0x0c45, 0x6001), },
147 { USB_DEVICE(0x0c45, 0x6005), },
148 { USB_DEVICE(0x0c45, 0x60ab), },
149 { }
150 };
147 151
148 /* Sensor detection is based on USB pid/vid */ 152 /* Sensor detection is based on USB pid/vid */
149 if (le16_to_cpu(tas5110c1b.usbdev->descriptor.idProduct) != 0x6001 && 153 if (!sn9c102_match_id(cam, tas5110c1b_id_table))
150 le16_to_cpu(tas5110c1b.usbdev->descriptor.idProduct) != 0x6005 &&
151 le16_to_cpu(tas5110c1b.usbdev->descriptor.idProduct) != 0x60ab)
152 return -ENODEV; 154 return -ENODEV;
153 155
156 sn9c102_attach_sensor(cam, &tas5110c1b);
157
154 return 0; 158 return 0;
155} 159}
diff --git a/drivers/usb/media/sn9c102_tas5130d1b.c b/drivers/usb/media/sn9c102_tas5130d1b.c
index a0728f0ae00c..c7b339740bbf 100644
--- a/drivers/usb/media/sn9c102_tas5130d1b.c
+++ b/drivers/usb/media/sn9c102_tas5130d1b.c
@@ -153,13 +153,17 @@ static struct sn9c102_sensor tas5130d1b = {
153 153
154int sn9c102_probe_tas5130d1b(struct sn9c102_device* cam) 154int sn9c102_probe_tas5130d1b(struct sn9c102_device* cam)
155{ 155{
156 /* This sensor has no identifiers, so let's attach it anyway */ 156 const struct usb_device_id tas5130d1b_id_table[] = {
157 sn9c102_attach_sensor(cam, &tas5130d1b); 157 { USB_DEVICE(0x0c45, 0x6025), },
158 { USB_DEVICE(0x0c45, 0x60aa), },
159 { }
160 };
158 161
159 /* Sensor detection is based on USB pid/vid */ 162 /* Sensor detection is based on USB pid/vid */
160 if (le16_to_cpu(tas5130d1b.usbdev->descriptor.idProduct) != 0x6025 && 163 if (!sn9c102_match_id(cam, tas5130d1b_id_table))
161 le16_to_cpu(tas5130d1b.usbdev->descriptor.idProduct) != 0x60aa)
162 return -ENODEV; 164 return -ENODEV;
163 165
166 sn9c102_attach_sensor(cam, &tas5130d1b);
167
164 return 0; 168 return 0;
165} 169}
diff --git a/drivers/usb/media/stv680.c b/drivers/usb/media/stv680.c
index b497a6a0a206..9636da20748d 100644
--- a/drivers/usb/media/stv680.c
+++ b/drivers/usb/media/stv680.c
@@ -67,6 +67,7 @@
67#include <linux/errno.h> 67#include <linux/errno.h>
68#include <linux/videodev.h> 68#include <linux/videodev.h>
69#include <linux/usb.h> 69#include <linux/usb.h>
70#include <linux/mutex.h>
70 71
71#include "stv680.h" 72#include "stv680.h"
72 73
@@ -317,12 +318,11 @@ static int stv_init (struct usb_stv *stv680)
317 unsigned char *buffer; 318 unsigned char *buffer;
318 unsigned long int bufsize; 319 unsigned long int bufsize;
319 320
320 buffer = kmalloc (40, GFP_KERNEL); 321 buffer = kzalloc (40, GFP_KERNEL);
321 if (buffer == NULL) { 322 if (buffer == NULL) {
322 PDEBUG (0, "STV(e): Out of (small buf) memory"); 323 PDEBUG (0, "STV(e): Out of (small buf) memory");
323 return -1; 324 return -1;
324 } 325 }
325 memset (buffer, 0, 40);
326 udelay (100); 326 udelay (100);
327 327
328 /* set config 1, interface 0, alternate 0 */ 328 /* set config 1, interface 0, alternate 0 */
@@ -1258,22 +1258,22 @@ static int stv680_mmap (struct file *file, struct vm_area_struct *vma)
1258 unsigned long size = vma->vm_end-vma->vm_start; 1258 unsigned long size = vma->vm_end-vma->vm_start;
1259 unsigned long page, pos; 1259 unsigned long page, pos;
1260 1260
1261 down (&stv680->lock); 1261 mutex_lock(&stv680->lock);
1262 1262
1263 if (stv680->udev == NULL) { 1263 if (stv680->udev == NULL) {
1264 up (&stv680->lock); 1264 mutex_unlock(&stv680->lock);
1265 return -EIO; 1265 return -EIO;
1266 } 1266 }
1267 if (size > (((STV680_NUMFRAMES * stv680->maxframesize) + PAGE_SIZE - 1) 1267 if (size > (((STV680_NUMFRAMES * stv680->maxframesize) + PAGE_SIZE - 1)
1268 & ~(PAGE_SIZE - 1))) { 1268 & ~(PAGE_SIZE - 1))) {
1269 up (&stv680->lock); 1269 mutex_unlock(&stv680->lock);
1270 return -EINVAL; 1270 return -EINVAL;
1271 } 1271 }
1272 pos = (unsigned long) stv680->fbuf; 1272 pos = (unsigned long) stv680->fbuf;
1273 while (size > 0) { 1273 while (size > 0) {
1274 page = vmalloc_to_pfn((void *)pos); 1274 page = vmalloc_to_pfn((void *)pos);
1275 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) { 1275 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
1276 up (&stv680->lock); 1276 mutex_unlock(&stv680->lock);
1277 return -EAGAIN; 1277 return -EAGAIN;
1278 } 1278 }
1279 start += PAGE_SIZE; 1279 start += PAGE_SIZE;
@@ -1283,7 +1283,7 @@ static int stv680_mmap (struct file *file, struct vm_area_struct *vma)
1283 else 1283 else
1284 size = 0; 1284 size = 0;
1285 } 1285 }
1286 up (&stv680->lock); 1286 mutex_unlock(&stv680->lock);
1287 1287
1288 return 0; 1288 return 0;
1289} 1289}
@@ -1387,14 +1387,12 @@ static int stv680_probe (struct usb_interface *intf, const struct usb_device_id
1387 goto error; 1387 goto error;
1388 } 1388 }
1389 /* We found one */ 1389 /* We found one */
1390 if ((stv680 = kmalloc (sizeof (*stv680), GFP_KERNEL)) == NULL) { 1390 if ((stv680 = kzalloc (sizeof (*stv680), GFP_KERNEL)) == NULL) {
1391 PDEBUG (0, "STV(e): couldn't kmalloc stv680 struct."); 1391 PDEBUG (0, "STV(e): couldn't kmalloc stv680 struct.");
1392 retval = -ENOMEM; 1392 retval = -ENOMEM;
1393 goto error; 1393 goto error;
1394 } 1394 }
1395 1395
1396 memset (stv680, 0, sizeof (*stv680));
1397
1398 stv680->udev = dev; 1396 stv680->udev = dev;
1399 stv680->camera_name = camera_name; 1397 stv680->camera_name = camera_name;
1400 1398
@@ -1409,7 +1407,7 @@ static int stv680_probe (struct usb_interface *intf, const struct usb_device_id
1409 1407
1410 memcpy (stv680->vdev->name, stv680->camera_name, strlen (stv680->camera_name)); 1408 memcpy (stv680->vdev->name, stv680->camera_name, strlen (stv680->camera_name));
1411 init_waitqueue_head (&stv680->wq); 1409 init_waitqueue_head (&stv680->wq);
1412 init_MUTEX (&stv680->lock); 1410 mutex_init (&stv680->lock);
1413 wmb (); 1411 wmb ();
1414 1412
1415 if (video_register_device (stv680->vdev, VFL_TYPE_GRABBER, video_nr) == -1) { 1413 if (video_register_device (stv680->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
diff --git a/drivers/usb/media/stv680.h b/drivers/usb/media/stv680.h
index b0551cdb280b..ea46e0001e6d 100644
--- a/drivers/usb/media/stv680.h
+++ b/drivers/usb/media/stv680.h
@@ -118,7 +118,7 @@ struct usb_stv {
118 int origGain; 118 int origGain;
119 int origMode; /* original camera mode */ 119 int origMode; /* original camera mode */
120 120
121 struct semaphore lock; /* to lock the structure */ 121 struct mutex lock; /* to lock the structure */
122 int user; /* user count for exclusive use */ 122 int user; /* user count for exclusive use */
123 int removed; /* device disconnected */ 123 int removed; /* device disconnected */
124 int streaming; /* Are we streaming video? */ 124 int streaming; /* Are we streaming video? */
diff --git a/drivers/usb/media/usbvideo.c b/drivers/usb/media/usbvideo.c
index 63a72e550a1b..0b51fae720a9 100644
--- a/drivers/usb/media/usbvideo.c
+++ b/drivers/usb/media/usbvideo.c
@@ -690,14 +690,13 @@ int usbvideo_register(
690 } 690 }
691 691
692 base_size = num_cams * sizeof(struct uvd) + sizeof(struct usbvideo); 692 base_size = num_cams * sizeof(struct uvd) + sizeof(struct usbvideo);
693 cams = (struct usbvideo *) kmalloc(base_size, GFP_KERNEL); 693 cams = (struct usbvideo *) kzalloc(base_size, GFP_KERNEL);
694 if (cams == NULL) { 694 if (cams == NULL) {
695 err("Failed to allocate %d. bytes for usbvideo struct", base_size); 695 err("Failed to allocate %d. bytes for usbvideo struct", base_size);
696 return -ENOMEM; 696 return -ENOMEM;
697 } 697 }
698 dbg("%s: Allocated $%p (%d. bytes) for %d. cameras", 698 dbg("%s: Allocated $%p (%d. bytes) for %d. cameras",
699 __FUNCTION__, cams, base_size, num_cams); 699 __FUNCTION__, cams, base_size, num_cams);
700 memset(cams, 0, base_size);
701 700
702 /* Copy callbacks, apply defaults for those that are not set */ 701 /* Copy callbacks, apply defaults for those that are not set */
703 memmove(&cams->cb, cbTbl, sizeof(cams->cb)); 702 memmove(&cams->cb, cbTbl, sizeof(cams->cb));
@@ -715,7 +714,7 @@ int usbvideo_register(
715 cams->md_module = md; 714 cams->md_module = md;
716 if (cams->md_module == NULL) 715 if (cams->md_module == NULL)
717 warn("%s: module == NULL!", __FUNCTION__); 716 warn("%s: module == NULL!", __FUNCTION__);
718 init_MUTEX(&cams->lock); /* to 1 == available */ 717 mutex_init(&cams->lock); /* to 1 == available */
719 718
720 for (i = 0; i < num_cams; i++) { 719 for (i = 0; i < num_cams; i++) {
721 struct uvd *up = &cams->cam[i]; 720 struct uvd *up = &cams->cam[i];
@@ -863,7 +862,7 @@ static void usbvideo_Disconnect(struct usb_interface *intf)
863 if (uvd->debug > 0) 862 if (uvd->debug > 0)
864 info("%s(%p.)", __FUNCTION__, intf); 863 info("%s(%p.)", __FUNCTION__, intf);
865 864
866 down(&uvd->lock); 865 mutex_lock(&uvd->lock);
867 uvd->remove_pending = 1; /* Now all ISO data will be ignored */ 866 uvd->remove_pending = 1; /* Now all ISO data will be ignored */
868 867
869 /* At this time we ask to cancel outstanding URBs */ 868 /* At this time we ask to cancel outstanding URBs */
@@ -883,7 +882,7 @@ static void usbvideo_Disconnect(struct usb_interface *intf)
883 info("%s: In use, disconnect pending.", __FUNCTION__); 882 info("%s: In use, disconnect pending.", __FUNCTION__);
884 else 883 else
885 usbvideo_CameraRelease(uvd); 884 usbvideo_CameraRelease(uvd);
886 up(&uvd->lock); 885 mutex_unlock(&uvd->lock);
887 info("USB camera disconnected."); 886 info("USB camera disconnected.");
888 887
889 usbvideo_ClientDecModCount(uvd); 888 usbvideo_ClientDecModCount(uvd);
@@ -930,19 +929,19 @@ static int usbvideo_find_struct(struct usbvideo *cams)
930 err("No usbvideo handle?"); 929 err("No usbvideo handle?");
931 return -1; 930 return -1;
932 } 931 }
933 down(&cams->lock); 932 mutex_lock(&cams->lock);
934 for (u = 0; u < cams->num_cameras; u++) { 933 for (u = 0; u < cams->num_cameras; u++) {
935 struct uvd *uvd = &cams->cam[u]; 934 struct uvd *uvd = &cams->cam[u];
936 if (!uvd->uvd_used) /* This one is free */ 935 if (!uvd->uvd_used) /* This one is free */
937 { 936 {
938 uvd->uvd_used = 1; /* In use now */ 937 uvd->uvd_used = 1; /* In use now */
939 init_MUTEX(&uvd->lock); /* to 1 == available */ 938 mutex_init(&uvd->lock); /* to 1 == available */
940 uvd->dev = NULL; 939 uvd->dev = NULL;
941 rv = u; 940 rv = u;
942 break; 941 break;
943 } 942 }
944 } 943 }
945 up(&cams->lock); 944 mutex_unlock(&cams->lock);
946 return rv; 945 return rv;
947} 946}
948 947
@@ -984,7 +983,7 @@ struct uvd *usbvideo_AllocateDevice(struct usbvideo *cams)
984 /* Not relying upon caller we increase module counter ourselves */ 983 /* Not relying upon caller we increase module counter ourselves */
985 usbvideo_ClientIncModCount(uvd); 984 usbvideo_ClientIncModCount(uvd);
986 985
987 down(&uvd->lock); 986 mutex_lock(&uvd->lock);
988 for (i=0; i < USBVIDEO_NUMSBUF; i++) { 987 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
989 uvd->sbuf[i].urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL); 988 uvd->sbuf[i].urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
990 if (uvd->sbuf[i].urb == NULL) { 989 if (uvd->sbuf[i].urb == NULL) {
@@ -1007,7 +1006,7 @@ struct uvd *usbvideo_AllocateDevice(struct usbvideo *cams)
1007 * return control to the client's probe function right now. 1006 * return control to the client's probe function right now.
1008 */ 1007 */
1009allocate_done: 1008allocate_done:
1010 up (&uvd->lock); 1009 mutex_unlock(&uvd->lock);
1011 usbvideo_ClientDecModCount(uvd); 1010 usbvideo_ClientDecModCount(uvd);
1012 return uvd; 1011 return uvd;
1013} 1012}
@@ -1121,7 +1120,7 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
1121 info("%s($%p)", __FUNCTION__, dev); 1120 info("%s($%p)", __FUNCTION__, dev);
1122 1121
1123 usbvideo_ClientIncModCount(uvd); 1122 usbvideo_ClientIncModCount(uvd);
1124 down(&uvd->lock); 1123 mutex_lock(&uvd->lock);
1125 1124
1126 if (uvd->user) { 1125 if (uvd->user) {
1127 err("%s: Someone tried to open an already opened device!", __FUNCTION__); 1126 err("%s: Someone tried to open an already opened device!", __FUNCTION__);
@@ -1202,7 +1201,7 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
1202 } 1201 }
1203 } 1202 }
1204 } 1203 }
1205 up(&uvd->lock); 1204 mutex_unlock(&uvd->lock);
1206 if (errCode != 0) 1205 if (errCode != 0)
1207 usbvideo_ClientDecModCount(uvd); 1206 usbvideo_ClientDecModCount(uvd);
1208 if (uvd->debug > 0) 1207 if (uvd->debug > 0)
@@ -1231,7 +1230,7 @@ static int usbvideo_v4l_close(struct inode *inode, struct file *file)
1231 if (uvd->debug > 1) 1230 if (uvd->debug > 1)
1232 info("%s($%p)", __FUNCTION__, dev); 1231 info("%s($%p)", __FUNCTION__, dev);
1233 1232
1234 down(&uvd->lock); 1233 mutex_lock(&uvd->lock);
1235 GET_CALLBACK(uvd, stopDataPump)(uvd); 1234 GET_CALLBACK(uvd, stopDataPump)(uvd);
1236 usbvideo_rvfree(uvd->fbuf, uvd->fbuf_size); 1235 usbvideo_rvfree(uvd->fbuf, uvd->fbuf_size);
1237 uvd->fbuf = NULL; 1236 uvd->fbuf = NULL;
@@ -1252,7 +1251,7 @@ static int usbvideo_v4l_close(struct inode *inode, struct file *file)
1252 info("usbvideo_v4l_close: Final disconnect."); 1251 info("usbvideo_v4l_close: Final disconnect.");
1253 usbvideo_CameraRelease(uvd); 1252 usbvideo_CameraRelease(uvd);
1254 } 1253 }
1255 up(&uvd->lock); 1254 mutex_unlock(&uvd->lock);
1256 usbvideo_ClientDecModCount(uvd); 1255 usbvideo_ClientDecModCount(uvd);
1257 1256
1258 if (uvd->debug > 1) 1257 if (uvd->debug > 1)
@@ -1512,7 +1511,7 @@ static ssize_t usbvideo_v4l_read(struct file *file, char __user *buf,
1512 if (uvd->debug >= 1) 1511 if (uvd->debug >= 1)
1513 info("%s: %Zd. bytes, noblock=%d.", __FUNCTION__, count, noblock); 1512 info("%s: %Zd. bytes, noblock=%d.", __FUNCTION__, count, noblock);
1514 1513
1515 down(&uvd->lock); 1514 mutex_lock(&uvd->lock);
1516 1515
1517 /* See if a frame is completed, then use it. */ 1516 /* See if a frame is completed, then use it. */
1518 for(i = 0; i < USBVIDEO_NUMFRAMES; i++) { 1517 for(i = 0; i < USBVIDEO_NUMFRAMES; i++) {
@@ -1644,7 +1643,7 @@ static ssize_t usbvideo_v4l_read(struct file *file, char __user *buf,
1644 } 1643 }
1645 } 1644 }
1646read_done: 1645read_done:
1647 up(&uvd->lock); 1646 mutex_unlock(&uvd->lock);
1648 return count; 1647 return count;
1649} 1648}
1650 1649
diff --git a/drivers/usb/media/usbvideo.h b/drivers/usb/media/usbvideo.h
index 6c390a1f981b..135433c2680a 100644
--- a/drivers/usb/media/usbvideo.h
+++ b/drivers/usb/media/usbvideo.h
@@ -19,6 +19,7 @@
19#include <linux/config.h> 19#include <linux/config.h>
20#include <linux/videodev.h> 20#include <linux/videodev.h>
21#include <linux/usb.h> 21#include <linux/usb.h>
22#include <linux/mutex.h>
22 23
23/* Most helpful debugging aid */ 24/* Most helpful debugging aid */
24#define assert(expr) ((void) ((expr) ? 0 : (err("assert failed at line %d",__LINE__)))) 25#define assert(expr) ((void) ((expr) ? 0 : (err("assert failed at line %d",__LINE__))))
@@ -213,7 +214,7 @@ struct uvd {
213 unsigned long flags; /* FLAGS_USBVIDEO_xxx */ 214 unsigned long flags; /* FLAGS_USBVIDEO_xxx */
214 unsigned long paletteBits; /* Which palettes we accept? */ 215 unsigned long paletteBits; /* Which palettes we accept? */
215 unsigned short defaultPalette; /* What palette to use for read() */ 216 unsigned short defaultPalette; /* What palette to use for read() */
216 struct semaphore lock; 217 struct mutex lock;
217 int user; /* user count for exclusive use */ 218 int user; /* user count for exclusive use */
218 219
219 videosize_t videosize; /* Current setting */ 220 videosize_t videosize; /* Current setting */
@@ -272,7 +273,7 @@ struct usbvideo {
272 int num_cameras; /* As allocated */ 273 int num_cameras; /* As allocated */
273 struct usb_driver usbdrv; /* Interface to the USB stack */ 274 struct usb_driver usbdrv; /* Interface to the USB stack */
274 char drvName[80]; /* Driver name */ 275 char drvName[80]; /* Driver name */
275 struct semaphore lock; /* Mutex protecting camera structures */ 276 struct mutex lock; /* Mutex protecting camera structures */
276 struct usbvideo_cb cb; /* Table of callbacks (virtual methods) */ 277 struct usbvideo_cb cb; /* Table of callbacks (virtual methods) */
277 struct video_device vdt; /* Video device template */ 278 struct video_device vdt; /* Video device template */
278 struct uvd *cam; /* Array of camera structures */ 279 struct uvd *cam; /* Array of camera structures */
diff --git a/drivers/usb/media/vicam.c b/drivers/usb/media/vicam.c
index 5df144073871..1d06e53ec7c5 100644
--- a/drivers/usb/media/vicam.c
+++ b/drivers/usb/media/vicam.c
@@ -42,6 +42,7 @@
42#include <linux/vmalloc.h> 42#include <linux/vmalloc.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/proc_fs.h> 44#include <linux/proc_fs.h>
45#include <linux/mutex.h>
45#include "usbvideo.h" 46#include "usbvideo.h"
46 47
47// #define VICAM_DEBUG 48// #define VICAM_DEBUG
@@ -407,7 +408,7 @@ struct vicam_camera {
407 struct usb_device *udev; // usb device 408 struct usb_device *udev; // usb device
408 409
409 /* guard against simultaneous accesses to the camera */ 410 /* guard against simultaneous accesses to the camera */
410 struct semaphore cam_lock; 411 struct mutex cam_lock;
411 412
412 int is_initialized; 413 int is_initialized;
413 u8 open_count; 414 u8 open_count;
@@ -461,12 +462,12 @@ static int send_control_msg(struct vicam_camera *cam,
461 u16 size) 462 u16 size)
462{ 463{
463 int status = -ENODEV; 464 int status = -ENODEV;
464 down(&cam->cam_lock); 465 mutex_lock(&cam->cam_lock);
465 if (cam->udev) { 466 if (cam->udev) {
466 status = __send_control_msg(cam, request, value, 467 status = __send_control_msg(cam, request, value,
467 index, cp, size); 468 index, cp, size);
468 } 469 }
469 up(&cam->cam_lock); 470 mutex_unlock(&cam->cam_lock);
470 return status; 471 return status;
471} 472}
472static int 473static int
@@ -763,6 +764,7 @@ vicam_open(struct inode *inode, struct file *file)
763 if (!cam) { 764 if (!cam) {
764 printk(KERN_ERR 765 printk(KERN_ERR
765 "vicam video_device improperly initialized"); 766 "vicam video_device improperly initialized");
767 return -EINVAL;
766 } 768 }
767 769
768 /* the videodev_lock held above us protects us from 770 /* the videodev_lock held above us protects us from
@@ -831,13 +833,13 @@ vicam_close(struct inode *inode, struct file *file)
831 rvfree(cam->framebuf, VICAM_MAX_FRAME_SIZE * VICAM_FRAMES); 833 rvfree(cam->framebuf, VICAM_MAX_FRAME_SIZE * VICAM_FRAMES);
832 kfree(cam->cntrlbuf); 834 kfree(cam->cntrlbuf);
833 835
834 down(&cam->cam_lock); 836 mutex_lock(&cam->cam_lock);
835 837
836 cam->open_count--; 838 cam->open_count--;
837 open_count = cam->open_count; 839 open_count = cam->open_count;
838 udev = cam->udev; 840 udev = cam->udev;
839 841
840 up(&cam->cam_lock); 842 mutex_unlock(&cam->cam_lock);
841 843
842 if (!open_count && !udev) { 844 if (!open_count && !udev) {
843 kfree(cam); 845 kfree(cam);
@@ -960,7 +962,7 @@ read_frame(struct vicam_camera *cam, int framenum)
960 request[8] = 0; 962 request[8] = 0;
961 // bytes 9-15 do not seem to affect exposure or image quality 963 // bytes 9-15 do not seem to affect exposure or image quality
962 964
963 down(&cam->cam_lock); 965 mutex_lock(&cam->cam_lock);
964 966
965 if (!cam->udev) { 967 if (!cam->udev) {
966 goto done; 968 goto done;
@@ -985,7 +987,7 @@ read_frame(struct vicam_camera *cam, int framenum)
985 } 987 }
986 988
987 done: 989 done:
988 up(&cam->cam_lock); 990 mutex_unlock(&cam->cam_lock);
989} 991}
990 992
991static ssize_t 993static ssize_t
@@ -1309,7 +1311,7 @@ vicam_probe( struct usb_interface *intf, const struct usb_device_id *id)
1309 1311
1310 cam->shutter_speed = 15; 1312 cam->shutter_speed = 15;
1311 1313
1312 init_MUTEX(&cam->cam_lock); 1314 mutex_init(&cam->cam_lock);
1313 1315
1314 memcpy(&cam->vdev, &vicam_template, 1316 memcpy(&cam->vdev, &vicam_template,
1315 sizeof (vicam_template)); 1317 sizeof (vicam_template));
@@ -1351,7 +1353,7 @@ vicam_disconnect(struct usb_interface *intf)
1351 1353
1352 /* stop the camera from being used */ 1354 /* stop the camera from being used */
1353 1355
1354 down(&cam->cam_lock); 1356 mutex_lock(&cam->cam_lock);
1355 1357
1356 /* mark the camera as gone */ 1358 /* mark the camera as gone */
1357 1359
@@ -1368,7 +1370,7 @@ vicam_disconnect(struct usb_interface *intf)
1368 1370
1369 open_count = cam->open_count; 1371 open_count = cam->open_count;
1370 1372
1371 up(&cam->cam_lock); 1373 mutex_unlock(&cam->cam_lock);
1372 1374
1373 if (!open_count) { 1375 if (!open_count) {
1374 kfree(cam); 1376 kfree(cam);
diff --git a/drivers/usb/media/w9968cf.c b/drivers/usb/media/w9968cf.c
index 9937fc64c8bf..b57dec3782e0 100644
--- a/drivers/usb/media/w9968cf.c
+++ b/drivers/usb/media/w9968cf.c
@@ -47,6 +47,13 @@
47#include "w9968cf.h" 47#include "w9968cf.h"
48#include "w9968cf_decoder.h" 48#include "w9968cf_decoder.h"
49 49
50static struct w9968cf_vpp_t* w9968cf_vpp;
51static DECLARE_WAIT_QUEUE_HEAD(w9968cf_vppmod_wait);
52
53static LIST_HEAD(w9968cf_dev_list); /* head of V4L registered cameras list */
54static DEFINE_MUTEX(w9968cf_devlist_mutex); /* semaphore for list traversal */
55
56static DECLARE_RWSEM(w9968cf_disconnect); /* prevent races with open() */
50 57
51 58
52/**************************************************************************** 59/****************************************************************************
@@ -695,13 +702,12 @@ static int w9968cf_allocate_memory(struct w9968cf_device* cam)
695 /* Allocate memory for the isochronous transfer buffers */ 702 /* Allocate memory for the isochronous transfer buffers */
696 for (i = 0; i < W9968CF_URBS; i++) { 703 for (i = 0; i < W9968CF_URBS; i++) {
697 if (!(cam->transfer_buffer[i] = 704 if (!(cam->transfer_buffer[i] =
698 kmalloc(W9968CF_ISO_PACKETS*p_size, GFP_KERNEL))) { 705 kzalloc(W9968CF_ISO_PACKETS*p_size, GFP_KERNEL))) {
699 DBG(1, "Couldn't allocate memory for the isochronous " 706 DBG(1, "Couldn't allocate memory for the isochronous "
700 "transfer buffers (%u bytes)", 707 "transfer buffers (%u bytes)",
701 p_size * W9968CF_ISO_PACKETS) 708 p_size * W9968CF_ISO_PACKETS)
702 return -ENOMEM; 709 return -ENOMEM;
703 } 710 }
704 memset(cam->transfer_buffer[i], 0, W9968CF_ISO_PACKETS*p_size);
705 } 711 }
706 712
707 /* Allocate memory for the temporary frame buffer */ 713 /* Allocate memory for the temporary frame buffer */
@@ -2419,7 +2425,7 @@ w9968cf_configure_camera(struct w9968cf_device* cam,
2419 enum w9968cf_model_id mod_id, 2425 enum w9968cf_model_id mod_id,
2420 const unsigned short dev_nr) 2426 const unsigned short dev_nr)
2421{ 2427{
2422 init_MUTEX(&cam->fileop_sem); 2428 mutex_init(&cam->fileop_mutex);
2423 init_waitqueue_head(&cam->open); 2429 init_waitqueue_head(&cam->open);
2424 spin_lock_init(&cam->urb_lock); 2430 spin_lock_init(&cam->urb_lock);
2425 spin_lock_init(&cam->flist_lock); 2431 spin_lock_init(&cam->flist_lock);
@@ -2647,7 +2653,7 @@ static void w9968cf_adjust_configuration(struct w9968cf_device* cam)
2647 --------------------------------------------------------------------------*/ 2653 --------------------------------------------------------------------------*/
2648static void w9968cf_release_resources(struct w9968cf_device* cam) 2654static void w9968cf_release_resources(struct w9968cf_device* cam)
2649{ 2655{
2650 down(&w9968cf_devlist_sem); 2656 mutex_lock(&w9968cf_devlist_mutex);
2651 2657
2652 DBG(2, "V4L device deregistered: /dev/video%d", cam->v4ldev->minor) 2658 DBG(2, "V4L device deregistered: /dev/video%d", cam->v4ldev->minor)
2653 2659
@@ -2658,7 +2664,7 @@ static void w9968cf_release_resources(struct w9968cf_device* cam)
2658 kfree(cam->control_buffer); 2664 kfree(cam->control_buffer);
2659 kfree(cam->data_buffer); 2665 kfree(cam->data_buffer);
2660 2666
2661 up(&w9968cf_devlist_sem); 2667 mutex_unlock(&w9968cf_devlist_mutex);
2662} 2668}
2663 2669
2664 2670
@@ -2678,14 +2684,14 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
2678 2684
2679 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp)); 2685 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
2680 2686
2681 down(&cam->dev_sem); 2687 mutex_lock(&cam->dev_mutex);
2682 2688
2683 if (cam->sensor == CC_UNKNOWN) { 2689 if (cam->sensor == CC_UNKNOWN) {
2684 DBG(2, "No supported image sensor has been detected by the " 2690 DBG(2, "No supported image sensor has been detected by the "
2685 "'ovcamchip' module for the %s (/dev/video%d). Make " 2691 "'ovcamchip' module for the %s (/dev/video%d). Make "
2686 "sure it is loaded *before* (re)connecting the camera.", 2692 "sure it is loaded *before* (re)connecting the camera.",
2687 symbolic(camlist, cam->id), cam->v4ldev->minor) 2693 symbolic(camlist, cam->id), cam->v4ldev->minor)
2688 up(&cam->dev_sem); 2694 mutex_unlock(&cam->dev_mutex);
2689 up_read(&w9968cf_disconnect); 2695 up_read(&w9968cf_disconnect);
2690 return -ENODEV; 2696 return -ENODEV;
2691 } 2697 }
@@ -2694,11 +2700,11 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
2694 DBG(2, "%s (/dev/video%d) has been already occupied by '%s'", 2700 DBG(2, "%s (/dev/video%d) has been already occupied by '%s'",
2695 symbolic(camlist, cam->id),cam->v4ldev->minor,cam->command) 2701 symbolic(camlist, cam->id),cam->v4ldev->minor,cam->command)
2696 if ((filp->f_flags & O_NONBLOCK)||(filp->f_flags & O_NDELAY)) { 2702 if ((filp->f_flags & O_NONBLOCK)||(filp->f_flags & O_NDELAY)) {
2697 up(&cam->dev_sem); 2703 mutex_unlock(&cam->dev_mutex);
2698 up_read(&w9968cf_disconnect); 2704 up_read(&w9968cf_disconnect);
2699 return -EWOULDBLOCK; 2705 return -EWOULDBLOCK;
2700 } 2706 }
2701 up(&cam->dev_sem); 2707 mutex_unlock(&cam->dev_mutex);
2702 err = wait_event_interruptible_exclusive(cam->open, 2708 err = wait_event_interruptible_exclusive(cam->open,
2703 cam->disconnected || 2709 cam->disconnected ||
2704 !cam->users); 2710 !cam->users);
@@ -2710,7 +2716,7 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
2710 up_read(&w9968cf_disconnect); 2716 up_read(&w9968cf_disconnect);
2711 return -ENODEV; 2717 return -ENODEV;
2712 } 2718 }
2713 down(&cam->dev_sem); 2719 mutex_lock(&cam->dev_mutex);
2714 } 2720 }
2715 2721
2716 DBG(5, "Opening '%s', /dev/video%d ...", 2722 DBG(5, "Opening '%s', /dev/video%d ...",
@@ -2739,7 +2745,7 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
2739 2745
2740 DBG(5, "Video device is open") 2746 DBG(5, "Video device is open")
2741 2747
2742 up(&cam->dev_sem); 2748 mutex_unlock(&cam->dev_mutex);
2743 up_read(&w9968cf_disconnect); 2749 up_read(&w9968cf_disconnect);
2744 2750
2745 return 0; 2751 return 0;
@@ -2747,7 +2753,7 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
2747deallocate_memory: 2753deallocate_memory:
2748 w9968cf_deallocate_memory(cam); 2754 w9968cf_deallocate_memory(cam);
2749 DBG(2, "Failed to open the video device") 2755 DBG(2, "Failed to open the video device")
2750 up(&cam->dev_sem); 2756 mutex_unlock(&cam->dev_mutex);
2751 up_read(&w9968cf_disconnect); 2757 up_read(&w9968cf_disconnect);
2752 return err; 2758 return err;
2753} 2759}
@@ -2759,13 +2765,13 @@ static int w9968cf_release(struct inode* inode, struct file* filp)
2759 2765
2760 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp)); 2766 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
2761 2767
2762 down(&cam->dev_sem); /* prevent disconnect() to be called */ 2768 mutex_lock(&cam->dev_mutex); /* prevent disconnect() to be called */
2763 2769
2764 w9968cf_stop_transfer(cam); 2770 w9968cf_stop_transfer(cam);
2765 2771
2766 if (cam->disconnected) { 2772 if (cam->disconnected) {
2767 w9968cf_release_resources(cam); 2773 w9968cf_release_resources(cam);
2768 up(&cam->dev_sem); 2774 mutex_unlock(&cam->dev_mutex);
2769 kfree(cam); 2775 kfree(cam);
2770 return 0; 2776 return 0;
2771 } 2777 }
@@ -2775,7 +2781,7 @@ static int w9968cf_release(struct inode* inode, struct file* filp)
2775 wake_up_interruptible_nr(&cam->open, 1); 2781 wake_up_interruptible_nr(&cam->open, 1);
2776 2782
2777 DBG(5, "Video device closed") 2783 DBG(5, "Video device closed")
2778 up(&cam->dev_sem); 2784 mutex_unlock(&cam->dev_mutex);
2779 return 0; 2785 return 0;
2780} 2786}
2781 2787
@@ -2792,18 +2798,18 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
2792 if (filp->f_flags & O_NONBLOCK) 2798 if (filp->f_flags & O_NONBLOCK)
2793 return -EWOULDBLOCK; 2799 return -EWOULDBLOCK;
2794 2800
2795 if (down_interruptible(&cam->fileop_sem)) 2801 if (mutex_lock_interruptible(&cam->fileop_mutex))
2796 return -ERESTARTSYS; 2802 return -ERESTARTSYS;
2797 2803
2798 if (cam->disconnected) { 2804 if (cam->disconnected) {
2799 DBG(2, "Device not present") 2805 DBG(2, "Device not present")
2800 up(&cam->fileop_sem); 2806 mutex_unlock(&cam->fileop_mutex);
2801 return -ENODEV; 2807 return -ENODEV;
2802 } 2808 }
2803 2809
2804 if (cam->misconfigured) { 2810 if (cam->misconfigured) {
2805 DBG(2, "The camera is misconfigured. Close and open it again.") 2811 DBG(2, "The camera is misconfigured. Close and open it again.")
2806 up(&cam->fileop_sem); 2812 mutex_unlock(&cam->fileop_mutex);
2807 return -EIO; 2813 return -EIO;
2808 } 2814 }
2809 2815
@@ -2818,11 +2824,11 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
2818 cam->frame[1].status == F_READY || 2824 cam->frame[1].status == F_READY ||
2819 cam->disconnected); 2825 cam->disconnected);
2820 if (err) { 2826 if (err) {
2821 up(&cam->fileop_sem); 2827 mutex_unlock(&cam->fileop_mutex);
2822 return err; 2828 return err;
2823 } 2829 }
2824 if (cam->disconnected) { 2830 if (cam->disconnected) {
2825 up(&cam->fileop_sem); 2831 mutex_unlock(&cam->fileop_mutex);
2826 return -ENODEV; 2832 return -ENODEV;
2827 } 2833 }
2828 2834
@@ -2836,7 +2842,7 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
2836 2842
2837 if (copy_to_user(buf, fr->buffer, count)) { 2843 if (copy_to_user(buf, fr->buffer, count)) {
2838 fr->status = F_UNUSED; 2844 fr->status = F_UNUSED;
2839 up(&cam->fileop_sem); 2845 mutex_unlock(&cam->fileop_mutex);
2840 return -EFAULT; 2846 return -EFAULT;
2841 } 2847 }
2842 *f_pos += count; 2848 *f_pos += count;
@@ -2845,7 +2851,7 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
2845 2851
2846 DBG(5, "%zu bytes read", count) 2852 DBG(5, "%zu bytes read", count)
2847 2853
2848 up(&cam->fileop_sem); 2854 mutex_unlock(&cam->fileop_mutex);
2849 return count; 2855 return count;
2850} 2856}
2851 2857
@@ -2899,24 +2905,24 @@ w9968cf_ioctl(struct inode* inode, struct file* filp,
2899 2905
2900 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp)); 2906 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
2901 2907
2902 if (down_interruptible(&cam->fileop_sem)) 2908 if (mutex_lock_interruptible(&cam->fileop_mutex))
2903 return -ERESTARTSYS; 2909 return -ERESTARTSYS;
2904 2910
2905 if (cam->disconnected) { 2911 if (cam->disconnected) {
2906 DBG(2, "Device not present") 2912 DBG(2, "Device not present")
2907 up(&cam->fileop_sem); 2913 mutex_unlock(&cam->fileop_mutex);
2908 return -ENODEV; 2914 return -ENODEV;
2909 } 2915 }
2910 2916
2911 if (cam->misconfigured) { 2917 if (cam->misconfigured) {
2912 DBG(2, "The camera is misconfigured. Close and open it again.") 2918 DBG(2, "The camera is misconfigured. Close and open it again.")
2913 up(&cam->fileop_sem); 2919 mutex_unlock(&cam->fileop_mutex);
2914 return -EIO; 2920 return -EIO;
2915 } 2921 }
2916 2922
2917 err = w9968cf_v4l_ioctl(inode, filp, cmd, (void __user *)arg); 2923 err = w9968cf_v4l_ioctl(inode, filp, cmd, (void __user *)arg);
2918 2924
2919 up(&cam->fileop_sem); 2925 mutex_unlock(&cam->fileop_mutex);
2920 return err; 2926 return err;
2921} 2927}
2922 2928
@@ -3499,14 +3505,12 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3499 return -ENODEV; 3505 return -ENODEV;
3500 3506
3501 cam = (struct w9968cf_device*) 3507 cam = (struct w9968cf_device*)
3502 kmalloc(sizeof(struct w9968cf_device), GFP_KERNEL); 3508 kzalloc(sizeof(struct w9968cf_device), GFP_KERNEL);
3503 if (!cam) 3509 if (!cam)
3504 return -ENOMEM; 3510 return -ENOMEM;
3505 3511
3506 memset(cam, 0, sizeof(*cam)); 3512 mutex_init(&cam->dev_mutex);
3507 3513 mutex_lock(&cam->dev_mutex);
3508 init_MUTEX(&cam->dev_sem);
3509 down(&cam->dev_sem);
3510 3514
3511 cam->usbdev = udev; 3515 cam->usbdev = udev;
3512 /* NOTE: a local copy is used to avoid possible race conditions */ 3516 /* NOTE: a local copy is used to avoid possible race conditions */
@@ -3518,10 +3522,10 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3518 simcams = W9968CF_SIMCAMS; 3522 simcams = W9968CF_SIMCAMS;
3519 3523
3520 /* How many cameras are connected ? */ 3524 /* How many cameras are connected ? */
3521 down(&w9968cf_devlist_sem); 3525 mutex_lock(&w9968cf_devlist_mutex);
3522 list_for_each(ptr, &w9968cf_dev_list) 3526 list_for_each(ptr, &w9968cf_dev_list)
3523 sc++; 3527 sc++;
3524 up(&w9968cf_devlist_sem); 3528 mutex_unlock(&w9968cf_devlist_mutex);
3525 3529
3526 if (sc >= simcams) { 3530 if (sc >= simcams) {
3527 DBG(2, "Device rejected: too many connected cameras " 3531 DBG(2, "Device rejected: too many connected cameras "
@@ -3532,21 +3536,19 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3532 3536
3533 3537
3534 /* Allocate 2 bytes of memory for camera control USB transfers */ 3538 /* Allocate 2 bytes of memory for camera control USB transfers */
3535 if (!(cam->control_buffer = kmalloc(2, GFP_KERNEL))) { 3539 if (!(cam->control_buffer = kzalloc(2, GFP_KERNEL))) {
3536 DBG(1,"Couldn't allocate memory for camera control transfers") 3540 DBG(1,"Couldn't allocate memory for camera control transfers")
3537 err = -ENOMEM; 3541 err = -ENOMEM;
3538 goto fail; 3542 goto fail;
3539 } 3543 }
3540 memset(cam->control_buffer, 0, 2);
3541 3544
3542 /* Allocate 8 bytes of memory for USB data transfers to the FSB */ 3545 /* Allocate 8 bytes of memory for USB data transfers to the FSB */
3543 if (!(cam->data_buffer = kmalloc(8, GFP_KERNEL))) { 3546 if (!(cam->data_buffer = kzalloc(8, GFP_KERNEL))) {
3544 DBG(1, "Couldn't allocate memory for data " 3547 DBG(1, "Couldn't allocate memory for data "
3545 "transfers to the FSB") 3548 "transfers to the FSB")
3546 err = -ENOMEM; 3549 err = -ENOMEM;
3547 goto fail; 3550 goto fail;
3548 } 3551 }
3549 memset(cam->data_buffer, 0, 8);
3550 3552
3551 /* Register the V4L device */ 3553 /* Register the V4L device */
3552 cam->v4ldev = video_device_alloc(); 3554 cam->v4ldev = video_device_alloc();
@@ -3583,9 +3585,9 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3583 w9968cf_configure_camera(cam, udev, mod_id, dev_nr); 3585 w9968cf_configure_camera(cam, udev, mod_id, dev_nr);
3584 3586
3585 /* Add a new entry into the list of V4L registered devices */ 3587 /* Add a new entry into the list of V4L registered devices */
3586 down(&w9968cf_devlist_sem); 3588 mutex_lock(&w9968cf_devlist_mutex);
3587 list_add(&cam->v4llist, &w9968cf_dev_list); 3589 list_add(&cam->v4llist, &w9968cf_dev_list);
3588 up(&w9968cf_devlist_sem); 3590 mutex_unlock(&w9968cf_devlist_mutex);
3589 dev_nr = (dev_nr < W9968CF_MAX_DEVICES-1) ? dev_nr+1 : 0; 3591 dev_nr = (dev_nr < W9968CF_MAX_DEVICES-1) ? dev_nr+1 : 0;
3590 3592
3591 w9968cf_turn_on_led(cam); 3593 w9968cf_turn_on_led(cam);
@@ -3593,7 +3595,7 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3593 w9968cf_i2c_init(cam); 3595 w9968cf_i2c_init(cam);
3594 3596
3595 usb_set_intfdata(intf, cam); 3597 usb_set_intfdata(intf, cam);
3596 up(&cam->dev_sem); 3598 mutex_unlock(&cam->dev_mutex);
3597 return 0; 3599 return 0;
3598 3600
3599fail: /* Free unused memory */ 3601fail: /* Free unused memory */
@@ -3601,7 +3603,7 @@ fail: /* Free unused memory */
3601 kfree(cam->data_buffer); 3603 kfree(cam->data_buffer);
3602 if (cam->v4ldev) 3604 if (cam->v4ldev)
3603 video_device_release(cam->v4ldev); 3605 video_device_release(cam->v4ldev);
3604 up(&cam->dev_sem); 3606 mutex_unlock(&cam->dev_mutex);
3605 kfree(cam); 3607 kfree(cam);
3606 return err; 3608 return err;
3607} 3609}
@@ -3616,7 +3618,7 @@ static void w9968cf_usb_disconnect(struct usb_interface* intf)
3616 3618
3617 if (cam) { 3619 if (cam) {
3618 /* Prevent concurrent accesses to data */ 3620 /* Prevent concurrent accesses to data */
3619 down(&cam->dev_sem); 3621 mutex_lock(&cam->dev_mutex);
3620 3622
3621 cam->disconnected = 1; 3623 cam->disconnected = 1;
3622 3624
@@ -3635,7 +3637,7 @@ static void w9968cf_usb_disconnect(struct usb_interface* intf)
3635 } else 3637 } else
3636 w9968cf_release_resources(cam); 3638 w9968cf_release_resources(cam);
3637 3639
3638 up(&cam->dev_sem); 3640 mutex_unlock(&cam->dev_mutex);
3639 3641
3640 if (!cam->users) 3642 if (!cam->users)
3641 kfree(cam); 3643 kfree(cam);
diff --git a/drivers/usb/media/w9968cf.h b/drivers/usb/media/w9968cf.h
index 47a6ff794171..a87be719a281 100644
--- a/drivers/usb/media/w9968cf.h
+++ b/drivers/usb/media/w9968cf.h
@@ -32,7 +32,7 @@
32#include <linux/param.h> 32#include <linux/param.h>
33#include <linux/types.h> 33#include <linux/types.h>
34#include <linux/rwsem.h> 34#include <linux/rwsem.h>
35#include <asm/semaphore.h> 35#include <linux/mutex.h>
36 36
37#include <media/ovcamchip.h> 37#include <media/ovcamchip.h>
38 38
@@ -194,14 +194,6 @@ enum w9968cf_vpp_flag {
194 VPP_UYVY_TO_RGBX = 0x08, 194 VPP_UYVY_TO_RGBX = 0x08,
195}; 195};
196 196
197static struct w9968cf_vpp_t* w9968cf_vpp;
198static DECLARE_WAIT_QUEUE_HEAD(w9968cf_vppmod_wait);
199
200static LIST_HEAD(w9968cf_dev_list); /* head of V4L registered cameras list */
201static DECLARE_MUTEX(w9968cf_devlist_sem); /* semaphore for list traversal */
202
203static DECLARE_RWSEM(w9968cf_disconnect); /* prevent races with open() */
204
205/* Main device driver structure */ 197/* Main device driver structure */
206struct w9968cf_device { 198struct w9968cf_device {
207 struct device dev; /* device structure */ 199 struct device dev; /* device structure */
@@ -277,8 +269,8 @@ struct w9968cf_device {
277 struct i2c_client* sensor_client; 269 struct i2c_client* sensor_client;
278 270
279 /* Locks */ 271 /* Locks */
280 struct semaphore dev_sem, /* for probe, disconnect,open and close */ 272 struct mutex dev_mutex, /* for probe, disconnect,open and close */
281 fileop_sem; /* for read and ioctl */ 273 fileop_mutex; /* for read and ioctl */
282 spinlock_t urb_lock, /* for submit_urb() and unlink_urb() */ 274 spinlock_t urb_lock, /* for submit_urb() and unlink_urb() */
283 flist_lock; /* for requested frame list accesses */ 275 flist_lock; /* for requested frame list accesses */
284 wait_queue_head_t open, wait_queue; 276 wait_queue_head_t open, wait_queue;
diff --git a/drivers/usb/media/zc0301.h b/drivers/usb/media/zc0301.h
new file mode 100644
index 000000000000..8e0655140e60
--- /dev/null
+++ b/drivers/usb/media/zc0301.h
@@ -0,0 +1,192 @@
1/***************************************************************************
2 * V4L2 driver for ZC0301 Image Processor and Control Chip *
3 * *
4 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (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, write to the Free Software *
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
19 ***************************************************************************/
20
21#ifndef _ZC0301_H_
22#define _ZC0301_H_
23
24#include <linux/version.h>
25#include <linux/usb.h>
26#include <linux/videodev2.h>
27#include <media/v4l2-common.h>
28#include <linux/device.h>
29#include <linux/list.h>
30#include <linux/spinlock.h>
31#include <linux/time.h>
32#include <linux/wait.h>
33#include <linux/types.h>
34#include <linux/param.h>
35#include <linux/mutex.h>
36#include <linux/rwsem.h>
37#include <linux/stddef.h>
38#include <linux/string.h>
39
40#include "zc0301_sensor.h"
41
42/*****************************************************************************/
43
44#define ZC0301_DEBUG
45#define ZC0301_DEBUG_LEVEL 2
46#define ZC0301_MAX_DEVICES 64
47#define ZC0301_FORCE_MUNMAP 0
48#define ZC0301_MAX_FRAMES 32
49#define ZC0301_COMPRESSION_QUALITY 0
50#define ZC0301_URBS 2
51#define ZC0301_ISO_PACKETS 7
52#define ZC0301_ALTERNATE_SETTING 7
53#define ZC0301_URB_TIMEOUT msecs_to_jiffies(2 * ZC0301_ISO_PACKETS)
54#define ZC0301_CTRL_TIMEOUT 100
55#define ZC0301_FRAME_TIMEOUT 2
56
57/*****************************************************************************/
58
59ZC0301_ID_TABLE
60ZC0301_SENSOR_TABLE
61
62enum zc0301_frame_state {
63 F_UNUSED,
64 F_QUEUED,
65 F_GRABBING,
66 F_DONE,
67 F_ERROR,
68};
69
70struct zc0301_frame_t {
71 void* bufmem;
72 struct v4l2_buffer buf;
73 enum zc0301_frame_state state;
74 struct list_head frame;
75 unsigned long vma_use_count;
76};
77
78enum zc0301_dev_state {
79 DEV_INITIALIZED = 0x01,
80 DEV_DISCONNECTED = 0x02,
81 DEV_MISCONFIGURED = 0x04,
82};
83
84enum zc0301_io_method {
85 IO_NONE,
86 IO_READ,
87 IO_MMAP,
88};
89
90enum zc0301_stream_state {
91 STREAM_OFF,
92 STREAM_INTERRUPT,
93 STREAM_ON,
94};
95
96struct zc0301_module_param {
97 u8 force_munmap;
98 u16 frame_timeout;
99};
100
101static DECLARE_RWSEM(zc0301_disconnect);
102
103struct zc0301_device {
104 struct video_device* v4ldev;
105
106 struct zc0301_sensor sensor;
107
108 struct usb_device* usbdev;
109 struct urb* urb[ZC0301_URBS];
110 void* transfer_buffer[ZC0301_URBS];
111 u8* control_buffer;
112
113 struct zc0301_frame_t *frame_current, frame[ZC0301_MAX_FRAMES];
114 struct list_head inqueue, outqueue;
115 u32 frame_count, nbuffers, nreadbuffers;
116
117 enum zc0301_io_method io;
118 enum zc0301_stream_state stream;
119
120 struct v4l2_jpegcompression compression;
121
122 struct zc0301_module_param module_param;
123
124 enum zc0301_dev_state state;
125 u8 users;
126
127 struct mutex dev_mutex, fileop_mutex;
128 spinlock_t queue_lock;
129 wait_queue_head_t open, wait_frame, wait_stream;
130};
131
132/*****************************************************************************/
133
134struct zc0301_device*
135zc0301_match_id(struct zc0301_device* cam, const struct usb_device_id *id)
136{
137 return usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id) ? cam : NULL;
138}
139
140void
141zc0301_attach_sensor(struct zc0301_device* cam, struct zc0301_sensor* sensor)
142{
143 memcpy(&cam->sensor, sensor, sizeof(struct zc0301_sensor));
144}
145
146/*****************************************************************************/
147
148#undef DBG
149#undef KDBG
150#ifdef ZC0301_DEBUG
151# define DBG(level, fmt, args...) \
152do { \
153 if (debug >= (level)) { \
154 if ((level) == 1) \
155 dev_err(&cam->usbdev->dev, fmt "\n", ## args); \
156 else if ((level) == 2) \
157 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
158 else if ((level) >= 3) \
159 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
160 __FUNCTION__, __LINE__ , ## args); \
161 } \
162} while (0)
163# define KDBG(level, fmt, args...) \
164do { \
165 if (debug >= (level)) { \
166 if ((level) == 1 || (level) == 2) \
167 pr_info("zc0301: " fmt "\n", ## args); \
168 else if ((level) == 3) \
169 pr_debug("zc0301: [%s:%d] " fmt "\n", __FUNCTION__, \
170 __LINE__ , ## args); \
171 } \
172} while (0)
173# define V4LDBG(level, name, cmd) \
174do { \
175 if (debug >= (level)) \
176 v4l_print_ioctl(name, cmd); \
177} while (0)
178#else
179# define DBG(level, fmt, args...) do {;} while(0)
180# define KDBG(level, fmt, args...) do {;} while(0)
181# define V4LDBG(level, name, cmd) do {;} while(0)
182#endif
183
184#undef PDBG
185#define PDBG(fmt, args...) \
186dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
187 __FUNCTION__, __LINE__ , ## args)
188
189#undef PDBGG
190#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
191
192#endif /* _ZC0301_H_ */
diff --git a/drivers/usb/media/zc0301_core.c b/drivers/usb/media/zc0301_core.c
new file mode 100644
index 000000000000..4036c6268bff
--- /dev/null
+++ b/drivers/usb/media/zc0301_core.c
@@ -0,0 +1,2055 @@
1/***************************************************************************
2 * Video4Linux2 driver for ZC0301 Image Processor and Control Chip *
3 * *
4 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> *
5 * *
6 * Informations about the chip internals needed to enable the I2C protocol *
7 * have been taken from the documentation of the ZC030x Video4Linux1 *
8 * driver written by Andrew Birkett <andy@nobugs.org> *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the Free Software *
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
23 ***************************************************************************/
24
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/kernel.h>
28#include <linux/param.h>
29#include <linux/moduleparam.h>
30#include <linux/errno.h>
31#include <linux/slab.h>
32#include <linux/device.h>
33#include <linux/fs.h>
34#include <linux/delay.h>
35#include <linux/compiler.h>
36#include <linux/ioctl.h>
37#include <linux/poll.h>
38#include <linux/stat.h>
39#include <linux/mm.h>
40#include <linux/vmalloc.h>
41#include <linux/page-flags.h>
42#include <linux/byteorder/generic.h>
43#include <asm/page.h>
44#include <asm/uaccess.h>
45
46#include "zc0301.h"
47
48/*****************************************************************************/
49
50#define ZC0301_MODULE_NAME "V4L2 driver for ZC0301 " \
51 "Image Processor and Control Chip"
52#define ZC0301_MODULE_AUTHOR "(C) 2006 Luca Risolia"
53#define ZC0301_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
54#define ZC0301_MODULE_LICENSE "GPL"
55#define ZC0301_MODULE_VERSION "1:1.03"
56#define ZC0301_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 3)
57
58/*****************************************************************************/
59
60MODULE_DEVICE_TABLE(usb, zc0301_id_table);
61
62MODULE_AUTHOR(ZC0301_MODULE_AUTHOR " " ZC0301_AUTHOR_EMAIL);
63MODULE_DESCRIPTION(ZC0301_MODULE_NAME);
64MODULE_VERSION(ZC0301_MODULE_VERSION);
65MODULE_LICENSE(ZC0301_MODULE_LICENSE);
66
67static short video_nr[] = {[0 ... ZC0301_MAX_DEVICES-1] = -1};
68module_param_array(video_nr, short, NULL, 0444);
69MODULE_PARM_DESC(video_nr,
70 "\n<-1|n[,...]> Specify V4L2 minor mode number."
71 "\n -1 = use next available (default)"
72 "\n n = use minor number n (integer >= 0)"
73 "\nYou can specify up to "
74 __MODULE_STRING(ZC0301_MAX_DEVICES) " cameras this way."
75 "\nFor example:"
76 "\nvideo_nr=-1,2,-1 would assign minor number 2 to"
77 "\nthe second registered camera and use auto for the first"
78 "\none and for every other camera."
79 "\n");
80
81static short force_munmap[] = {[0 ... ZC0301_MAX_DEVICES-1] =
82 ZC0301_FORCE_MUNMAP};
83module_param_array(force_munmap, bool, NULL, 0444);
84MODULE_PARM_DESC(force_munmap,
85 "\n<0|1[,...]> Force the application to unmap previously"
86 "\nmapped buffer memory before calling any VIDIOC_S_CROP or"
87 "\nVIDIOC_S_FMT ioctl's. Not all the applications support"
88 "\nthis feature. This parameter is specific for each"
89 "\ndetected camera."
90 "\n 0 = do not force memory unmapping"
91 "\n 1 = force memory unmapping (save memory)"
92 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"."
93 "\n");
94
95static unsigned int frame_timeout[] = {[0 ... ZC0301_MAX_DEVICES-1] =
96 ZC0301_FRAME_TIMEOUT};
97module_param_array(frame_timeout, uint, NULL, 0644);
98MODULE_PARM_DESC(frame_timeout,
99 "\n<n[,...]> Timeout for a video frame in seconds."
100 "\nThis parameter is specific for each detected camera."
101 "\nDefault value is "__MODULE_STRING(ZC0301_FRAME_TIMEOUT)"."
102 "\n");
103
104#ifdef ZC0301_DEBUG
105static unsigned short debug = ZC0301_DEBUG_LEVEL;
106module_param(debug, ushort, 0644);
107MODULE_PARM_DESC(debug,
108 "\n<n> Debugging information level, from 0 to 3:"
109 "\n0 = none (use carefully)"
110 "\n1 = critical errors"
111 "\n2 = significant informations"
112 "\n3 = more verbose messages"
113 "\nLevel 3 is useful for testing only, when only "
114 "one device is used."
115 "\nDefault value is "__MODULE_STRING(ZC0301_DEBUG_LEVEL)"."
116 "\n");
117#endif
118
119/*****************************************************************************/
120
121static u32
122zc0301_request_buffers(struct zc0301_device* cam, u32 count,
123 enum zc0301_io_method io)
124{
125 struct v4l2_pix_format* p = &(cam->sensor.pix_format);
126 struct v4l2_rect* r = &(cam->sensor.cropcap.bounds);
127 const size_t imagesize = cam->module_param.force_munmap ||
128 io == IO_READ ?
129 (p->width * p->height * p->priv) / 8 :
130 (r->width * r->height * p->priv) / 8;
131 void* buff = NULL;
132 u32 i;
133
134 if (count > ZC0301_MAX_FRAMES)
135 count = ZC0301_MAX_FRAMES;
136
137 cam->nbuffers = count;
138 while (cam->nbuffers > 0) {
139 if ((buff = vmalloc_32(cam->nbuffers * PAGE_ALIGN(imagesize))))
140 break;
141 cam->nbuffers--;
142 }
143
144 for (i = 0; i < cam->nbuffers; i++) {
145 cam->frame[i].bufmem = buff + i*PAGE_ALIGN(imagesize);
146 cam->frame[i].buf.index = i;
147 cam->frame[i].buf.m.offset = i*PAGE_ALIGN(imagesize);
148 cam->frame[i].buf.length = imagesize;
149 cam->frame[i].buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
150 cam->frame[i].buf.sequence = 0;
151 cam->frame[i].buf.field = V4L2_FIELD_NONE;
152 cam->frame[i].buf.memory = V4L2_MEMORY_MMAP;
153 cam->frame[i].buf.flags = 0;
154 }
155
156 return cam->nbuffers;
157}
158
159
160static void zc0301_release_buffers(struct zc0301_device* cam)
161{
162 if (cam->nbuffers) {
163 vfree(cam->frame[0].bufmem);
164 cam->nbuffers = 0;
165 }
166 cam->frame_current = NULL;
167}
168
169
170static void zc0301_empty_framequeues(struct zc0301_device* cam)
171{
172 u32 i;
173
174 INIT_LIST_HEAD(&cam->inqueue);
175 INIT_LIST_HEAD(&cam->outqueue);
176
177 for (i = 0; i < ZC0301_MAX_FRAMES; i++) {
178 cam->frame[i].state = F_UNUSED;
179 cam->frame[i].buf.bytesused = 0;
180 }
181}
182
183
184static void zc0301_requeue_outqueue(struct zc0301_device* cam)
185{
186 struct zc0301_frame_t *i;
187
188 list_for_each_entry(i, &cam->outqueue, frame) {
189 i->state = F_QUEUED;
190 list_add(&i->frame, &cam->inqueue);
191 }
192
193 INIT_LIST_HEAD(&cam->outqueue);
194}
195
196
197static void zc0301_queue_unusedframes(struct zc0301_device* cam)
198{
199 unsigned long lock_flags;
200 u32 i;
201
202 for (i = 0; i < cam->nbuffers; i++)
203 if (cam->frame[i].state == F_UNUSED) {
204 cam->frame[i].state = F_QUEUED;
205 spin_lock_irqsave(&cam->queue_lock, lock_flags);
206 list_add_tail(&cam->frame[i].frame, &cam->inqueue);
207 spin_unlock_irqrestore(&cam->queue_lock, lock_flags);
208 }
209}
210
211/*****************************************************************************/
212
213int zc0301_write_reg(struct zc0301_device* cam, u16 index, u16 value)
214{
215 struct usb_device* udev = cam->usbdev;
216 int res;
217
218 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0xa0, 0x40,
219 value, index, NULL, 0, ZC0301_CTRL_TIMEOUT);
220 if (res < 0) {
221 DBG(3, "Failed to write a register (index 0x%04X, "
222 "value 0x%02X, error %d)",index, value, res);
223 return -1;
224 }
225
226 return 0;
227}
228
229
230int zc0301_read_reg(struct zc0301_device* cam, u16 index)
231{
232 struct usb_device* udev = cam->usbdev;
233 u8* buff = cam->control_buffer;
234 int res;
235
236 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0xa1, 0xc0,
237 0x0001, index, buff, 1, ZC0301_CTRL_TIMEOUT);
238 if (res < 0)
239 DBG(3, "Failed to read a register (index 0x%04X, error %d)",
240 index, res);
241
242 PDBGG("Read: index 0x%04X, value: 0x%04X", index, (int)(*buff));
243
244 return (res >= 0) ? (int)(*buff) : -1;
245}
246
247
248int zc0301_i2c_read(struct zc0301_device* cam, u16 address, u8 length)
249{
250 int err = 0, res, r0, r1;
251
252 err += zc0301_write_reg(cam, 0x0092, address);
253 err += zc0301_write_reg(cam, 0x0090, 0x02);
254
255 msleep(1);
256
257 res = zc0301_read_reg(cam, 0x0091);
258 if (res < 0)
259 err += res;
260 r0 = zc0301_read_reg(cam, 0x0095);
261 if (r0 < 0)
262 err += r0;
263 r1 = zc0301_read_reg(cam, 0x0096);
264 if (r1 < 0)
265 err += r1;
266
267 res = (length <= 1) ? r0 : r0 | (r1 << 8);
268
269 if (err)
270 DBG(3, "I2C read failed at address 0x%04X, value: 0x%04X",
271 address, res);
272
273
274 PDBGG("I2C read: address 0x%04X, value: 0x%04X", address, res);
275
276 return err ? -1 : res;
277}
278
279
280int zc0301_i2c_write(struct zc0301_device* cam, u16 address, u16 value)
281{
282 int err = 0, res;
283
284 err += zc0301_write_reg(cam, 0x0092, address);
285 err += zc0301_write_reg(cam, 0x0093, value & 0xff);
286 err += zc0301_write_reg(cam, 0x0094, value >> 8);
287 err += zc0301_write_reg(cam, 0x0090, 0x01);
288
289 msleep(1);
290
291 res = zc0301_read_reg(cam, 0x0091);
292 if (res < 0)
293 err += res;
294
295 if (err)
296 DBG(3, "I2C write failed at address 0x%04X, value: 0x%04X",
297 address, value);
298
299 PDBGG("I2C write: address 0x%04X, value: 0x%04X", address, value);
300
301 return err ? -1 : 0;
302}
303
304/*****************************************************************************/
305
306static void zc0301_urb_complete(struct urb *urb, struct pt_regs* regs)
307{
308 struct zc0301_device* cam = urb->context;
309 struct zc0301_frame_t** f;
310 size_t imagesize;
311 u8 i;
312 int err = 0;
313
314 if (urb->status == -ENOENT)
315 return;
316
317 f = &cam->frame_current;
318
319 if (cam->stream == STREAM_INTERRUPT) {
320 cam->stream = STREAM_OFF;
321 if ((*f))
322 (*f)->state = F_QUEUED;
323 DBG(3, "Stream interrupted");
324 wake_up(&cam->wait_stream);
325 }
326
327 if (cam->state & DEV_DISCONNECTED)
328 return;
329
330 if (cam->state & DEV_MISCONFIGURED) {
331 wake_up_interruptible(&cam->wait_frame);
332 return;
333 }
334
335 if (cam->stream == STREAM_OFF || list_empty(&cam->inqueue))
336 goto resubmit_urb;
337
338 if (!(*f))
339 (*f) = list_entry(cam->inqueue.next, struct zc0301_frame_t,
340 frame);
341
342 imagesize = (cam->sensor.pix_format.width *
343 cam->sensor.pix_format.height *
344 cam->sensor.pix_format.priv) / 8;
345
346 for (i = 0; i < urb->number_of_packets; i++) {
347 unsigned int len, status;
348 void *pos;
349 u16* soi;
350 u8 sof;
351
352 len = urb->iso_frame_desc[i].actual_length;
353 status = urb->iso_frame_desc[i].status;
354 pos = urb->iso_frame_desc[i].offset + urb->transfer_buffer;
355
356 if (status) {
357 DBG(3, "Error in isochronous frame");
358 (*f)->state = F_ERROR;
359 continue;
360 }
361
362 sof = (*(soi = pos) == 0xd8ff);
363
364 PDBGG("Isochrnous frame: length %u, #%u i,", len, i);
365
366 if ((*f)->state == F_QUEUED || (*f)->state == F_ERROR)
367start_of_frame:
368 if (sof) {
369 (*f)->state = F_GRABBING;
370 (*f)->buf.bytesused = 0;
371 do_gettimeofday(&(*f)->buf.timestamp);
372 DBG(3, "SOF detected: new video frame");
373 }
374
375 if ((*f)->state == F_GRABBING) {
376 if (sof && (*f)->buf.bytesused)
377 goto end_of_frame;
378
379 if ((*f)->buf.bytesused + len > imagesize) {
380 DBG(3, "Video frame size exceeded");
381 (*f)->state = F_ERROR;
382 continue;
383 }
384
385 memcpy((*f)->bufmem+(*f)->buf.bytesused, pos, len);
386 (*f)->buf.bytesused += len;
387
388 if ((*f)->buf.bytesused == imagesize) {
389 u32 b;
390end_of_frame:
391 b = (*f)->buf.bytesused;
392 (*f)->state = F_DONE;
393 (*f)->buf.sequence= ++cam->frame_count;
394 spin_lock(&cam->queue_lock);
395 list_move_tail(&(*f)->frame, &cam->outqueue);
396 if (!list_empty(&cam->inqueue))
397 (*f) = list_entry(cam->inqueue.next,
398 struct zc0301_frame_t,
399 frame);
400 else
401 (*f) = NULL;
402 spin_unlock(&cam->queue_lock);
403 DBG(3, "Video frame captured: : %lu bytes",
404 (unsigned long)(b));
405
406 if (!(*f))
407 goto resubmit_urb;
408
409 if (sof)
410 goto start_of_frame;
411 }
412 }
413 }
414
415resubmit_urb:
416 urb->dev = cam->usbdev;
417 err = usb_submit_urb(urb, GFP_ATOMIC);
418 if (err < 0 && err != -EPERM) {
419 cam->state |= DEV_MISCONFIGURED;
420 DBG(1, "usb_submit_urb() failed");
421 }
422
423 wake_up_interruptible(&cam->wait_frame);
424}
425
426
427static int zc0301_start_transfer(struct zc0301_device* cam)
428{
429 struct usb_device *udev = cam->usbdev;
430 struct urb* urb;
431 const unsigned int wMaxPacketSize[] = {0, 128, 192, 256, 384,
432 512, 768, 1023};
433 const unsigned int psz = wMaxPacketSize[ZC0301_ALTERNATE_SETTING];
434 s8 i, j;
435 int err = 0;
436
437 for (i = 0; i < ZC0301_URBS; i++) {
438 cam->transfer_buffer[i] = kzalloc(ZC0301_ISO_PACKETS * psz,
439 GFP_KERNEL);
440 if (!cam->transfer_buffer[i]) {
441 err = -ENOMEM;
442 DBG(1, "Not enough memory");
443 goto free_buffers;
444 }
445 }
446
447 for (i = 0; i < ZC0301_URBS; i++) {
448 urb = usb_alloc_urb(ZC0301_ISO_PACKETS, GFP_KERNEL);
449 cam->urb[i] = urb;
450 if (!urb) {
451 err = -ENOMEM;
452 DBG(1, "usb_alloc_urb() failed");
453 goto free_urbs;
454 }
455 urb->dev = udev;
456 urb->context = cam;
457 urb->pipe = usb_rcvisocpipe(udev, 1);
458 urb->transfer_flags = URB_ISO_ASAP;
459 urb->number_of_packets = ZC0301_ISO_PACKETS;
460 urb->complete = zc0301_urb_complete;
461 urb->transfer_buffer = cam->transfer_buffer[i];
462 urb->transfer_buffer_length = psz * ZC0301_ISO_PACKETS;
463 urb->interval = 1;
464 for (j = 0; j < ZC0301_ISO_PACKETS; j++) {
465 urb->iso_frame_desc[j].offset = psz * j;
466 urb->iso_frame_desc[j].length = psz;
467 }
468 }
469
470 err = usb_set_interface(udev, 0, ZC0301_ALTERNATE_SETTING);
471 if (err) {
472 DBG(1, "usb_set_interface() failed");
473 goto free_urbs;
474 }
475
476 cam->frame_current = NULL;
477
478 for (i = 0; i < ZC0301_URBS; i++) {
479 err = usb_submit_urb(cam->urb[i], GFP_KERNEL);
480 if (err) {
481 for (j = i-1; j >= 0; j--)
482 usb_kill_urb(cam->urb[j]);
483 DBG(1, "usb_submit_urb() failed, error %d", err);
484 goto free_urbs;
485 }
486 }
487
488 return 0;
489
490free_urbs:
491 for (i = 0; (i < ZC0301_URBS) && cam->urb[i]; i++)
492 usb_free_urb(cam->urb[i]);
493
494free_buffers:
495 for (i = 0; (i < ZC0301_URBS) && cam->transfer_buffer[i]; i++)
496 kfree(cam->transfer_buffer[i]);
497
498 return err;
499}
500
501
502static int zc0301_stop_transfer(struct zc0301_device* cam)
503{
504 struct usb_device *udev = cam->usbdev;
505 s8 i;
506 int err = 0;
507
508 if (cam->state & DEV_DISCONNECTED)
509 return 0;
510
511 for (i = ZC0301_URBS-1; i >= 0; i--) {
512 usb_kill_urb(cam->urb[i]);
513 usb_free_urb(cam->urb[i]);
514 kfree(cam->transfer_buffer[i]);
515 }
516
517 err = usb_set_interface(udev, 0, 0); /* 0 Mb/s */
518 if (err)
519 DBG(3, "usb_set_interface() failed");
520
521 return err;
522}
523
524
525static int zc0301_stream_interrupt(struct zc0301_device* cam)
526{
527 long timeout;
528
529 cam->stream = STREAM_INTERRUPT;
530 timeout = wait_event_timeout(cam->wait_stream,
531 (cam->stream == STREAM_OFF) ||
532 (cam->state & DEV_DISCONNECTED),
533 ZC0301_URB_TIMEOUT);
534 if (cam->state & DEV_DISCONNECTED)
535 return -ENODEV;
536 else if (cam->stream != STREAM_OFF) {
537 cam->state |= DEV_MISCONFIGURED;
538 DBG(1, "URB timeout reached. The camera is misconfigured. To "
539 "use it, close and open /dev/video%d again.",
540 cam->v4ldev->minor);
541 return -EIO;
542 }
543
544 return 0;
545}
546
547/*****************************************************************************/
548
549static int
550zc0301_set_compression(struct zc0301_device* cam,
551 struct v4l2_jpegcompression* compression)
552{
553 int r, err = 0;
554
555 if ((r = zc0301_read_reg(cam, 0x0008)) < 0)
556 err += r;
557 err += zc0301_write_reg(cam, 0x0008, r | 0x11 | compression->quality);
558
559 return err ? -EIO : 0;
560}
561
562
563static int zc0301_init(struct zc0301_device* cam)
564{
565 struct zc0301_sensor* s = &cam->sensor;
566 struct v4l2_control ctrl;
567 struct v4l2_queryctrl *qctrl;
568 struct v4l2_rect* rect;
569 u8 i = 0;
570 int err = 0;
571
572 if (!(cam->state & DEV_INITIALIZED)) {
573 init_waitqueue_head(&cam->open);
574 qctrl = s->qctrl;
575 rect = &(s->cropcap.defrect);
576 cam->compression.quality = ZC0301_COMPRESSION_QUALITY;
577 } else { /* use current values */
578 qctrl = s->_qctrl;
579 rect = &(s->_rect);
580 }
581
582 if (s->init) {
583 err = s->init(cam);
584 if (err) {
585 DBG(3, "Sensor initialization failed");
586 return err;
587 }
588 }
589
590 if ((err = zc0301_set_compression(cam, &cam->compression))) {
591 DBG(3, "set_compression() failed");
592 return err;
593 }
594
595 if (s->set_crop)
596 if ((err = s->set_crop(cam, rect))) {
597 DBG(3, "set_crop() failed");
598 return err;
599 }
600
601 if (s->set_ctrl) {
602 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
603 if (s->qctrl[i].id != 0 &&
604 !(s->qctrl[i].flags & V4L2_CTRL_FLAG_DISABLED)) {
605 ctrl.id = s->qctrl[i].id;
606 ctrl.value = qctrl[i].default_value;
607 err = s->set_ctrl(cam, &ctrl);
608 if (err) {
609 DBG(3, "Set %s control failed",
610 s->qctrl[i].name);
611 return err;
612 }
613 DBG(3, "Image sensor supports '%s' control",
614 s->qctrl[i].name);
615 }
616 }
617
618 if (!(cam->state & DEV_INITIALIZED)) {
619 mutex_init(&cam->fileop_mutex);
620 spin_lock_init(&cam->queue_lock);
621 init_waitqueue_head(&cam->wait_frame);
622 init_waitqueue_head(&cam->wait_stream);
623 cam->nreadbuffers = 2;
624 memcpy(s->_qctrl, s->qctrl, sizeof(s->qctrl));
625 memcpy(&(s->_rect), &(s->cropcap.defrect),
626 sizeof(struct v4l2_rect));
627 cam->state |= DEV_INITIALIZED;
628 }
629
630 DBG(2, "Initialization succeeded");
631 return 0;
632}
633
634
635static void zc0301_release_resources(struct zc0301_device* cam)
636{
637 DBG(2, "V4L2 device /dev/video%d deregistered", cam->v4ldev->minor);
638 video_set_drvdata(cam->v4ldev, NULL);
639 video_unregister_device(cam->v4ldev);
640 kfree(cam->control_buffer);
641}
642
643/*****************************************************************************/
644
645static int zc0301_open(struct inode* inode, struct file* filp)
646{
647 struct zc0301_device* cam;
648 int err = 0;
649
650 /*
651 This is the only safe way to prevent race conditions with
652 disconnect
653 */
654 if (!down_read_trylock(&zc0301_disconnect))
655 return -ERESTARTSYS;
656
657 cam = video_get_drvdata(video_devdata(filp));
658
659 if (mutex_lock_interruptible(&cam->dev_mutex)) {
660 up_read(&zc0301_disconnect);
661 return -ERESTARTSYS;
662 }
663
664 if (cam->users) {
665 DBG(2, "Device /dev/video%d is busy...", cam->v4ldev->minor);
666 if ((filp->f_flags & O_NONBLOCK) ||
667 (filp->f_flags & O_NDELAY)) {
668 err = -EWOULDBLOCK;
669 goto out;
670 }
671 mutex_unlock(&cam->dev_mutex);
672 err = wait_event_interruptible_exclusive(cam->open,
673 cam->state & DEV_DISCONNECTED
674 || !cam->users);
675 if (err) {
676 up_read(&zc0301_disconnect);
677 return err;
678 }
679 if (cam->state & DEV_DISCONNECTED) {
680 up_read(&zc0301_disconnect);
681 return -ENODEV;
682 }
683 mutex_lock(&cam->dev_mutex);
684 }
685
686
687 if (cam->state & DEV_MISCONFIGURED) {
688 err = zc0301_init(cam);
689 if (err) {
690 DBG(1, "Initialization failed again. "
691 "I will retry on next open().");
692 goto out;
693 }
694 cam->state &= ~DEV_MISCONFIGURED;
695 }
696
697 if ((err = zc0301_start_transfer(cam)))
698 goto out;
699
700 filp->private_data = cam;
701 cam->users++;
702 cam->io = IO_NONE;
703 cam->stream = STREAM_OFF;
704 cam->nbuffers = 0;
705 cam->frame_count = 0;
706 zc0301_empty_framequeues(cam);
707
708 DBG(3, "Video device /dev/video%d is open", cam->v4ldev->minor);
709
710out:
711 mutex_unlock(&cam->dev_mutex);
712 up_read(&zc0301_disconnect);
713 return err;
714}
715
716
717static int zc0301_release(struct inode* inode, struct file* filp)
718{
719 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
720
721 mutex_lock(&cam->dev_mutex); /* prevent disconnect() to be called */
722
723 zc0301_stop_transfer(cam);
724
725 zc0301_release_buffers(cam);
726
727 if (cam->state & DEV_DISCONNECTED) {
728 zc0301_release_resources(cam);
729 usb_put_dev(cam->usbdev);
730 mutex_unlock(&cam->dev_mutex);
731 kfree(cam);
732 return 0;
733 }
734
735 cam->users--;
736 wake_up_interruptible_nr(&cam->open, 1);
737
738 DBG(3, "Video device /dev/video%d closed", cam->v4ldev->minor);
739
740 mutex_unlock(&cam->dev_mutex);
741
742 return 0;
743}
744
745
746static ssize_t
747zc0301_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
748{
749 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
750 struct zc0301_frame_t* f, * i;
751 unsigned long lock_flags;
752 long timeout;
753 int err = 0;
754
755 if (mutex_lock_interruptible(&cam->fileop_mutex))
756 return -ERESTARTSYS;
757
758 if (cam->state & DEV_DISCONNECTED) {
759 DBG(1, "Device not present");
760 mutex_unlock(&cam->fileop_mutex);
761 return -ENODEV;
762 }
763
764 if (cam->state & DEV_MISCONFIGURED) {
765 DBG(1, "The camera is misconfigured. Close and open it "
766 "again.");
767 mutex_unlock(&cam->fileop_mutex);
768 return -EIO;
769 }
770
771 if (cam->io == IO_MMAP) {
772 DBG(3, "Close and open the device again to choose the read "
773 "method");
774 mutex_unlock(&cam->fileop_mutex);
775 return -EINVAL;
776 }
777
778 if (cam->io == IO_NONE) {
779 if (!zc0301_request_buffers(cam, cam->nreadbuffers, IO_READ)) {
780 DBG(1, "read() failed, not enough memory");
781 mutex_unlock(&cam->fileop_mutex);
782 return -ENOMEM;
783 }
784 cam->io = IO_READ;
785 cam->stream = STREAM_ON;
786 }
787
788 if (list_empty(&cam->inqueue)) {
789 if (!list_empty(&cam->outqueue))
790 zc0301_empty_framequeues(cam);
791 zc0301_queue_unusedframes(cam);
792 }
793
794 if (!count) {
795 mutex_unlock(&cam->fileop_mutex);
796 return 0;
797 }
798
799 if (list_empty(&cam->outqueue)) {
800 if (filp->f_flags & O_NONBLOCK) {
801 mutex_unlock(&cam->fileop_mutex);
802 return -EAGAIN;
803 }
804 timeout = wait_event_interruptible_timeout
805 ( cam->wait_frame,
806 (!list_empty(&cam->outqueue)) ||
807 (cam->state & DEV_DISCONNECTED) ||
808 (cam->state & DEV_MISCONFIGURED),
809 cam->module_param.frame_timeout *
810 1000 * msecs_to_jiffies(1) );
811 if (timeout < 0) {
812 mutex_unlock(&cam->fileop_mutex);
813 return timeout;
814 }
815 if (cam->state & DEV_DISCONNECTED) {
816 mutex_unlock(&cam->fileop_mutex);
817 return -ENODEV;
818 }
819 if (!timeout || (cam->state & DEV_MISCONFIGURED)) {
820 mutex_unlock(&cam->fileop_mutex);
821 return -EIO;
822 }
823 }
824
825 f = list_entry(cam->outqueue.prev, struct zc0301_frame_t, frame);
826
827 if (count > f->buf.bytesused)
828 count = f->buf.bytesused;
829
830 if (copy_to_user(buf, f->bufmem, count)) {
831 err = -EFAULT;
832 goto exit;
833 }
834 *f_pos += count;
835
836exit:
837 spin_lock_irqsave(&cam->queue_lock, lock_flags);
838 list_for_each_entry(i, &cam->outqueue, frame)
839 i->state = F_UNUSED;
840 INIT_LIST_HEAD(&cam->outqueue);
841 spin_unlock_irqrestore(&cam->queue_lock, lock_flags);
842
843 zc0301_queue_unusedframes(cam);
844
845 PDBGG("Frame #%lu, bytes read: %zu",
846 (unsigned long)f->buf.index, count);
847
848 mutex_unlock(&cam->fileop_mutex);
849
850 return err ? err : count;
851}
852
853
854static unsigned int zc0301_poll(struct file *filp, poll_table *wait)
855{
856 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
857 struct zc0301_frame_t* f;
858 unsigned long lock_flags;
859 unsigned int mask = 0;
860
861 if (mutex_lock_interruptible(&cam->fileop_mutex))
862 return POLLERR;
863
864 if (cam->state & DEV_DISCONNECTED) {
865 DBG(1, "Device not present");
866 goto error;
867 }
868
869 if (cam->state & DEV_MISCONFIGURED) {
870 DBG(1, "The camera is misconfigured. Close and open it "
871 "again.");
872 goto error;
873 }
874
875 if (cam->io == IO_NONE) {
876 if (!zc0301_request_buffers(cam, cam->nreadbuffers, IO_READ)) {
877 DBG(1, "poll() failed, not enough memory");
878 goto error;
879 }
880 cam->io = IO_READ;
881 cam->stream = STREAM_ON;
882 }
883
884 if (cam->io == IO_READ) {
885 spin_lock_irqsave(&cam->queue_lock, lock_flags);
886 list_for_each_entry(f, &cam->outqueue, frame)
887 f->state = F_UNUSED;
888 INIT_LIST_HEAD(&cam->outqueue);
889 spin_unlock_irqrestore(&cam->queue_lock, lock_flags);
890 zc0301_queue_unusedframes(cam);
891 }
892
893 poll_wait(filp, &cam->wait_frame, wait);
894
895 if (!list_empty(&cam->outqueue))
896 mask |= POLLIN | POLLRDNORM;
897
898 mutex_unlock(&cam->fileop_mutex);
899
900 return mask;
901
902error:
903 mutex_unlock(&cam->fileop_mutex);
904 return POLLERR;
905}
906
907
908static void zc0301_vm_open(struct vm_area_struct* vma)
909{
910 struct zc0301_frame_t* f = vma->vm_private_data;
911 f->vma_use_count++;
912}
913
914
915static void zc0301_vm_close(struct vm_area_struct* vma)
916{
917 /* NOTE: buffers are not freed here */
918 struct zc0301_frame_t* f = vma->vm_private_data;
919 f->vma_use_count--;
920}
921
922
923static struct vm_operations_struct zc0301_vm_ops = {
924 .open = zc0301_vm_open,
925 .close = zc0301_vm_close,
926};
927
928
929static int zc0301_mmap(struct file* filp, struct vm_area_struct *vma)
930{
931 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
932 unsigned long size = vma->vm_end - vma->vm_start,
933 start = vma->vm_start;
934 void *pos;
935 u32 i;
936
937 if (mutex_lock_interruptible(&cam->fileop_mutex))
938 return -ERESTARTSYS;
939
940 if (cam->state & DEV_DISCONNECTED) {
941 DBG(1, "Device not present");
942 mutex_unlock(&cam->fileop_mutex);
943 return -ENODEV;
944 }
945
946 if (cam->state & DEV_MISCONFIGURED) {
947 DBG(1, "The camera is misconfigured. Close and open it "
948 "again.");
949 mutex_unlock(&cam->fileop_mutex);
950 return -EIO;
951 }
952
953 if (cam->io != IO_MMAP || !(vma->vm_flags & VM_WRITE) ||
954 size != PAGE_ALIGN(cam->frame[0].buf.length)) {
955 mutex_unlock(&cam->fileop_mutex);
956 return -EINVAL;
957 }
958
959 for (i = 0; i < cam->nbuffers; i++) {
960 if ((cam->frame[i].buf.m.offset>>PAGE_SHIFT) == vma->vm_pgoff)
961 break;
962 }
963 if (i == cam->nbuffers) {
964 mutex_unlock(&cam->fileop_mutex);
965 return -EINVAL;
966 }
967
968 vma->vm_flags |= VM_IO;
969 vma->vm_flags |= VM_RESERVED;
970
971 pos = cam->frame[i].bufmem;
972 while (size > 0) { /* size is page-aligned */
973 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
974 mutex_unlock(&cam->fileop_mutex);
975 return -EAGAIN;
976 }
977 start += PAGE_SIZE;
978 pos += PAGE_SIZE;
979 size -= PAGE_SIZE;
980 }
981
982 vma->vm_ops = &zc0301_vm_ops;
983 vma->vm_private_data = &cam->frame[i];
984
985 zc0301_vm_open(vma);
986
987 mutex_unlock(&cam->fileop_mutex);
988
989 return 0;
990}
991
992/*****************************************************************************/
993
994static int
995zc0301_vidioc_querycap(struct zc0301_device* cam, void __user * arg)
996{
997 struct v4l2_capability cap = {
998 .driver = "zc0301",
999 .version = ZC0301_MODULE_VERSION_CODE,
1000 .capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
1001 V4L2_CAP_STREAMING,
1002 };
1003
1004 strlcpy(cap.card, cam->v4ldev->name, sizeof(cap.card));
1005 if (usb_make_path(cam->usbdev, cap.bus_info, sizeof(cap.bus_info)) < 0)
1006 strlcpy(cap.bus_info, cam->usbdev->dev.bus_id,
1007 sizeof(cap.bus_info));
1008
1009 if (copy_to_user(arg, &cap, sizeof(cap)))
1010 return -EFAULT;
1011
1012 return 0;
1013}
1014
1015
1016static int
1017zc0301_vidioc_enuminput(struct zc0301_device* cam, void __user * arg)
1018{
1019 struct v4l2_input i;
1020
1021 if (copy_from_user(&i, arg, sizeof(i)))
1022 return -EFAULT;
1023
1024 if (i.index)
1025 return -EINVAL;
1026
1027 memset(&i, 0, sizeof(i));
1028 strcpy(i.name, "Camera");
1029 i.type = V4L2_INPUT_TYPE_CAMERA;
1030
1031 if (copy_to_user(arg, &i, sizeof(i)))
1032 return -EFAULT;
1033
1034 return 0;
1035}
1036
1037
1038static int
1039zc0301_vidioc_g_input(struct zc0301_device* cam, void __user * arg)
1040{
1041 int index = 0;
1042
1043 if (copy_to_user(arg, &index, sizeof(index)))
1044 return -EFAULT;
1045
1046 return 0;
1047}
1048
1049
1050static int
1051zc0301_vidioc_s_input(struct zc0301_device* cam, void __user * arg)
1052{
1053 int index;
1054
1055 if (copy_from_user(&index, arg, sizeof(index)))
1056 return -EFAULT;
1057
1058 if (index != 0)
1059 return -EINVAL;
1060
1061 return 0;
1062}
1063
1064
1065static int
1066zc0301_vidioc_query_ctrl(struct zc0301_device* cam, void __user * arg)
1067{
1068 struct zc0301_sensor* s = &cam->sensor;
1069 struct v4l2_queryctrl qc;
1070 u8 i;
1071
1072 if (copy_from_user(&qc, arg, sizeof(qc)))
1073 return -EFAULT;
1074
1075 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
1076 if (qc.id && qc.id == s->qctrl[i].id) {
1077 memcpy(&qc, &(s->qctrl[i]), sizeof(qc));
1078 if (copy_to_user(arg, &qc, sizeof(qc)))
1079 return -EFAULT;
1080 return 0;
1081 }
1082
1083 return -EINVAL;
1084}
1085
1086
1087static int
1088zc0301_vidioc_g_ctrl(struct zc0301_device* cam, void __user * arg)
1089{
1090 struct zc0301_sensor* s = &cam->sensor;
1091 struct v4l2_control ctrl;
1092 int err = 0;
1093 u8 i;
1094
1095 if (!s->get_ctrl && !s->set_ctrl)
1096 return -EINVAL;
1097
1098 if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
1099 return -EFAULT;
1100
1101 if (!s->get_ctrl) {
1102 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
1103 if (ctrl.id == s->qctrl[i].id) {
1104 ctrl.value = s->_qctrl[i].default_value;
1105 goto exit;
1106 }
1107 return -EINVAL;
1108 } else
1109 err = s->get_ctrl(cam, &ctrl);
1110
1111exit:
1112 if (copy_to_user(arg, &ctrl, sizeof(ctrl)))
1113 return -EFAULT;
1114
1115 return err;
1116}
1117
1118
1119static int
1120zc0301_vidioc_s_ctrl(struct zc0301_device* cam, void __user * arg)
1121{
1122 struct zc0301_sensor* s = &cam->sensor;
1123 struct v4l2_control ctrl;
1124 u8 i;
1125 int err = 0;
1126
1127 if (!s->set_ctrl)
1128 return -EINVAL;
1129
1130 if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
1131 return -EFAULT;
1132
1133 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
1134 if (ctrl.id == s->qctrl[i].id) {
1135 if (s->qctrl[i].flags & V4L2_CTRL_FLAG_DISABLED)
1136 return -EINVAL;
1137 if (ctrl.value < s->qctrl[i].minimum ||
1138 ctrl.value > s->qctrl[i].maximum)
1139 return -ERANGE;
1140 ctrl.value -= ctrl.value % s->qctrl[i].step;
1141 break;
1142 }
1143
1144 if ((err = s->set_ctrl(cam, &ctrl)))
1145 return err;
1146
1147 s->_qctrl[i].default_value = ctrl.value;
1148
1149 return 0;
1150}
1151
1152
1153static int
1154zc0301_vidioc_cropcap(struct zc0301_device* cam, void __user * arg)
1155{
1156 struct v4l2_cropcap* cc = &(cam->sensor.cropcap);
1157
1158 cc->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1159 cc->pixelaspect.numerator = 1;
1160 cc->pixelaspect.denominator = 1;
1161
1162 if (copy_to_user(arg, cc, sizeof(*cc)))
1163 return -EFAULT;
1164
1165 return 0;
1166}
1167
1168
1169static int
1170zc0301_vidioc_g_crop(struct zc0301_device* cam, void __user * arg)
1171{
1172 struct zc0301_sensor* s = &cam->sensor;
1173 struct v4l2_crop crop = {
1174 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
1175 };
1176
1177 memcpy(&(crop.c), &(s->_rect), sizeof(struct v4l2_rect));
1178
1179 if (copy_to_user(arg, &crop, sizeof(crop)))
1180 return -EFAULT;
1181
1182 return 0;
1183}
1184
1185
1186static int
1187zc0301_vidioc_s_crop(struct zc0301_device* cam, void __user * arg)
1188{
1189 struct zc0301_sensor* s = &cam->sensor;
1190 struct v4l2_crop crop;
1191 struct v4l2_rect* rect;
1192 struct v4l2_rect* bounds = &(s->cropcap.bounds);
1193 const enum zc0301_stream_state stream = cam->stream;
1194 const u32 nbuffers = cam->nbuffers;
1195 u32 i;
1196 int err = 0;
1197
1198 if (copy_from_user(&crop, arg, sizeof(crop)))
1199 return -EFAULT;
1200
1201 rect = &(crop.c);
1202
1203 if (crop.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1204 return -EINVAL;
1205
1206 if (cam->module_param.force_munmap)
1207 for (i = 0; i < cam->nbuffers; i++)
1208 if (cam->frame[i].vma_use_count) {
1209 DBG(3, "VIDIOC_S_CROP failed. "
1210 "Unmap the buffers first.");
1211 return -EINVAL;
1212 }
1213
1214 if (!s->set_crop) {
1215 memcpy(rect, &(s->_rect), sizeof(*rect));
1216 if (copy_to_user(arg, &crop, sizeof(crop)))
1217 return -EFAULT;
1218 return 0;
1219 }
1220
1221 rect->left &= ~7L;
1222 rect->top &= ~7L;
1223 if (rect->width < 8)
1224 rect->width = 8;
1225 if (rect->height < 8)
1226 rect->height = 8;
1227 if (rect->width > bounds->width)
1228 rect->width = bounds->width;
1229 if (rect->height > bounds->height)
1230 rect->height = bounds->height;
1231 if (rect->left < bounds->left)
1232 rect->left = bounds->left;
1233 if (rect->top < bounds->top)
1234 rect->top = bounds->top;
1235 if (rect->left + rect->width > bounds->left + bounds->width)
1236 rect->left = bounds->left+bounds->width - rect->width;
1237 if (rect->top + rect->height > bounds->top + bounds->height)
1238 rect->top = bounds->top+bounds->height - rect->height;
1239 rect->width &= ~7L;
1240 rect->height &= ~7L;
1241
1242 if (cam->stream == STREAM_ON)
1243 if ((err = zc0301_stream_interrupt(cam)))
1244 return err;
1245
1246 if (copy_to_user(arg, &crop, sizeof(crop))) {
1247 cam->stream = stream;
1248 return -EFAULT;
1249 }
1250
1251 if (cam->module_param.force_munmap || cam->io == IO_READ)
1252 zc0301_release_buffers(cam);
1253
1254 if (s->set_crop)
1255 err += s->set_crop(cam, rect);
1256
1257 if (err) { /* atomic, no rollback in ioctl() */
1258 cam->state |= DEV_MISCONFIGURED;
1259 DBG(1, "VIDIOC_S_CROP failed because of hardware problems. To "
1260 "use the camera, close and open /dev/video%d again.",
1261 cam->v4ldev->minor);
1262 return -EIO;
1263 }
1264
1265 s->pix_format.width = rect->width;
1266 s->pix_format.height = rect->height;
1267 memcpy(&(s->_rect), rect, sizeof(*rect));
1268
1269 if ((cam->module_param.force_munmap || cam->io == IO_READ) &&
1270 nbuffers != zc0301_request_buffers(cam, nbuffers, cam->io)) {
1271 cam->state |= DEV_MISCONFIGURED;
1272 DBG(1, "VIDIOC_S_CROP failed because of not enough memory. To "
1273 "use the camera, close and open /dev/video%d again.",
1274 cam->v4ldev->minor);
1275 return -ENOMEM;
1276 }
1277
1278 if (cam->io == IO_READ)
1279 zc0301_empty_framequeues(cam);
1280 else if (cam->module_param.force_munmap)
1281 zc0301_requeue_outqueue(cam);
1282
1283 cam->stream = stream;
1284
1285 return 0;
1286}
1287
1288
1289static int
1290zc0301_vidioc_enum_fmt(struct zc0301_device* cam, void __user * arg)
1291{
1292 struct v4l2_fmtdesc fmtd;
1293
1294 if (copy_from_user(&fmtd, arg, sizeof(fmtd)))
1295 return -EFAULT;
1296
1297 if (fmtd.index == 0) {
1298 strcpy(fmtd.description, "JPEG");
1299 fmtd.pixelformat = V4L2_PIX_FMT_JPEG;
1300 fmtd.flags = V4L2_FMT_FLAG_COMPRESSED;
1301 } else
1302 return -EINVAL;
1303
1304 fmtd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1305 memset(&fmtd.reserved, 0, sizeof(fmtd.reserved));
1306
1307 if (copy_to_user(arg, &fmtd, sizeof(fmtd)))
1308 return -EFAULT;
1309
1310 return 0;
1311}
1312
1313
1314static int
1315zc0301_vidioc_g_fmt(struct zc0301_device* cam, void __user * arg)
1316{
1317 struct v4l2_format format;
1318 struct v4l2_pix_format* pfmt = &(cam->sensor.pix_format);
1319
1320 if (copy_from_user(&format, arg, sizeof(format)))
1321 return -EFAULT;
1322
1323 if (format.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1324 return -EINVAL;
1325
1326 pfmt->bytesperline = 0;
1327 pfmt->sizeimage = pfmt->height * ((pfmt->width*pfmt->priv)/8);
1328 pfmt->field = V4L2_FIELD_NONE;
1329 memcpy(&(format.fmt.pix), pfmt, sizeof(*pfmt));
1330
1331 if (copy_to_user(arg, &format, sizeof(format)))
1332 return -EFAULT;
1333
1334 return 0;
1335}
1336
1337
1338static int
1339zc0301_vidioc_try_s_fmt(struct zc0301_device* cam, unsigned int cmd,
1340 void __user * arg)
1341{
1342 struct zc0301_sensor* s = &cam->sensor;
1343 struct v4l2_format format;
1344 struct v4l2_pix_format* pix;
1345 struct v4l2_pix_format* pfmt = &(s->pix_format);
1346 struct v4l2_rect* bounds = &(s->cropcap.bounds);
1347 struct v4l2_rect rect;
1348 const enum zc0301_stream_state stream = cam->stream;
1349 const u32 nbuffers = cam->nbuffers;
1350 u32 i;
1351 int err = 0;
1352
1353 if (copy_from_user(&format, arg, sizeof(format)))
1354 return -EFAULT;
1355
1356 pix = &(format.fmt.pix);
1357
1358 if (format.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1359 return -EINVAL;
1360
1361 memcpy(&rect, &(s->_rect), sizeof(rect));
1362
1363 if (!s->set_crop) {
1364 pix->width = rect.width;
1365 pix->height = rect.height;
1366 } else {
1367 rect.width = pix->width;
1368 rect.height = pix->height;
1369 }
1370
1371 if (rect.width < 8)
1372 rect.width = 8;
1373 if (rect.height < 8)
1374 rect.height = 8;
1375 if (rect.width > bounds->left + bounds->width - rect.left)
1376 rect.width = bounds->left + bounds->width - rect.left;
1377 if (rect.height > bounds->top + bounds->height - rect.top)
1378 rect.height = bounds->top + bounds->height - rect.top;
1379 rect.width &= ~7L;
1380 rect.height &= ~7L;
1381
1382 pix->width = rect.width;
1383 pix->height = rect.height;
1384 pix->pixelformat = pfmt->pixelformat;
1385 pix->priv = pfmt->priv;
1386 pix->colorspace = pfmt->colorspace;
1387 pix->bytesperline = 0;
1388 pix->sizeimage = pix->height * ((pix->width * pix->priv) / 8);
1389 pix->field = V4L2_FIELD_NONE;
1390
1391 if (cmd == VIDIOC_TRY_FMT) {
1392 if (copy_to_user(arg, &format, sizeof(format)))
1393 return -EFAULT;
1394 return 0;
1395 }
1396
1397 if (cam->module_param.force_munmap)
1398 for (i = 0; i < cam->nbuffers; i++)
1399 if (cam->frame[i].vma_use_count) {
1400 DBG(3, "VIDIOC_S_FMT failed. "
1401 "Unmap the buffers first.");
1402 return -EINVAL;
1403 }
1404
1405 if (cam->stream == STREAM_ON)
1406 if ((err = zc0301_stream_interrupt(cam)))
1407 return err;
1408
1409 if (copy_to_user(arg, &format, sizeof(format))) {
1410 cam->stream = stream;
1411 return -EFAULT;
1412 }
1413
1414 if (cam->module_param.force_munmap || cam->io == IO_READ)
1415 zc0301_release_buffers(cam);
1416
1417 if (s->set_crop)
1418 err += s->set_crop(cam, &rect);
1419
1420 if (err) { /* atomic, no rollback in ioctl() */
1421 cam->state |= DEV_MISCONFIGURED;
1422 DBG(1, "VIDIOC_S_FMT failed because of hardware problems. To "
1423 "use the camera, close and open /dev/video%d again.",
1424 cam->v4ldev->minor);
1425 return -EIO;
1426 }
1427
1428 memcpy(pfmt, pix, sizeof(*pix));
1429 memcpy(&(s->_rect), &rect, sizeof(rect));
1430
1431 if ((cam->module_param.force_munmap || cam->io == IO_READ) &&
1432 nbuffers != zc0301_request_buffers(cam, nbuffers, cam->io)) {
1433 cam->state |= DEV_MISCONFIGURED;
1434 DBG(1, "VIDIOC_S_FMT failed because of not enough memory. To "
1435 "use the camera, close and open /dev/video%d again.",
1436 cam->v4ldev->minor);
1437 return -ENOMEM;
1438 }
1439
1440 if (cam->io == IO_READ)
1441 zc0301_empty_framequeues(cam);
1442 else if (cam->module_param.force_munmap)
1443 zc0301_requeue_outqueue(cam);
1444
1445 cam->stream = stream;
1446
1447 return 0;
1448}
1449
1450
1451static int
1452zc0301_vidioc_g_jpegcomp(struct zc0301_device* cam, void __user * arg)
1453{
1454 if (copy_to_user(arg, &cam->compression, sizeof(cam->compression)))
1455 return -EFAULT;
1456
1457 return 0;
1458}
1459
1460
1461static int
1462zc0301_vidioc_s_jpegcomp(struct zc0301_device* cam, void __user * arg)
1463{
1464 struct v4l2_jpegcompression jc;
1465 const enum zc0301_stream_state stream = cam->stream;
1466 int err = 0;
1467
1468 if (copy_from_user(&jc, arg, sizeof(jc)))
1469 return -EFAULT;
1470
1471 if (jc.quality != 0)
1472 return -EINVAL;
1473
1474 if (cam->stream == STREAM_ON)
1475 if ((err = zc0301_stream_interrupt(cam)))
1476 return err;
1477
1478 err += zc0301_set_compression(cam, &jc);
1479 if (err) { /* atomic, no rollback in ioctl() */
1480 cam->state |= DEV_MISCONFIGURED;
1481 DBG(1, "VIDIOC_S_JPEGCOMP failed because of hardware "
1482 "problems. To use the camera, close and open "
1483 "/dev/video%d again.", cam->v4ldev->minor);
1484 return -EIO;
1485 }
1486
1487 cam->compression.quality = jc.quality;
1488
1489 cam->stream = stream;
1490
1491 return 0;
1492}
1493
1494
1495static int
1496zc0301_vidioc_reqbufs(struct zc0301_device* cam, void __user * arg)
1497{
1498 struct v4l2_requestbuffers rb;
1499 u32 i;
1500 int err;
1501
1502 if (copy_from_user(&rb, arg, sizeof(rb)))
1503 return -EFAULT;
1504
1505 if (rb.type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1506 rb.memory != V4L2_MEMORY_MMAP)
1507 return -EINVAL;
1508
1509 if (cam->io == IO_READ) {
1510 DBG(3, "Close and open the device again to choose the mmap "
1511 "I/O method");
1512 return -EINVAL;
1513 }
1514
1515 for (i = 0; i < cam->nbuffers; i++)
1516 if (cam->frame[i].vma_use_count) {
1517 DBG(3, "VIDIOC_REQBUFS failed. "
1518 "Previous buffers are still mapped.");
1519 return -EINVAL;
1520 }
1521
1522 if (cam->stream == STREAM_ON)
1523 if ((err = zc0301_stream_interrupt(cam)))
1524 return err;
1525
1526 zc0301_empty_framequeues(cam);
1527
1528 zc0301_release_buffers(cam);
1529 if (rb.count)
1530 rb.count = zc0301_request_buffers(cam, rb.count, IO_MMAP);
1531
1532 if (copy_to_user(arg, &rb, sizeof(rb))) {
1533 zc0301_release_buffers(cam);
1534 cam->io = IO_NONE;
1535 return -EFAULT;
1536 }
1537
1538 cam->io = rb.count ? IO_MMAP : IO_NONE;
1539
1540 return 0;
1541}
1542
1543
1544static int
1545zc0301_vidioc_querybuf(struct zc0301_device* cam, void __user * arg)
1546{
1547 struct v4l2_buffer b;
1548
1549 if (copy_from_user(&b, arg, sizeof(b)))
1550 return -EFAULT;
1551
1552 if (b.type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1553 b.index >= cam->nbuffers || cam->io != IO_MMAP)
1554 return -EINVAL;
1555
1556 memcpy(&b, &cam->frame[b.index].buf, sizeof(b));
1557
1558 if (cam->frame[b.index].vma_use_count)
1559 b.flags |= V4L2_BUF_FLAG_MAPPED;
1560
1561 if (cam->frame[b.index].state == F_DONE)
1562 b.flags |= V4L2_BUF_FLAG_DONE;
1563 else if (cam->frame[b.index].state != F_UNUSED)
1564 b.flags |= V4L2_BUF_FLAG_QUEUED;
1565
1566 if (copy_to_user(arg, &b, sizeof(b)))
1567 return -EFAULT;
1568
1569 return 0;
1570}
1571
1572
1573static int
1574zc0301_vidioc_qbuf(struct zc0301_device* cam, void __user * arg)
1575{
1576 struct v4l2_buffer b;
1577 unsigned long lock_flags;
1578
1579 if (copy_from_user(&b, arg, sizeof(b)))
1580 return -EFAULT;
1581
1582 if (b.type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1583 b.index >= cam->nbuffers || cam->io != IO_MMAP)
1584 return -EINVAL;
1585
1586 if (cam->frame[b.index].state != F_UNUSED)
1587 return -EINVAL;
1588
1589 cam->frame[b.index].state = F_QUEUED;
1590
1591 spin_lock_irqsave(&cam->queue_lock, lock_flags);
1592 list_add_tail(&cam->frame[b.index].frame, &cam->inqueue);
1593 spin_unlock_irqrestore(&cam->queue_lock, lock_flags);
1594
1595 PDBGG("Frame #%lu queued", (unsigned long)b.index);
1596
1597 return 0;
1598}
1599
1600
1601static int
1602zc0301_vidioc_dqbuf(struct zc0301_device* cam, struct file* filp,
1603 void __user * arg)
1604{
1605 struct v4l2_buffer b;
1606 struct zc0301_frame_t *f;
1607 unsigned long lock_flags;
1608 long timeout;
1609
1610 if (copy_from_user(&b, arg, sizeof(b)))
1611 return -EFAULT;
1612
1613 if (b.type != V4L2_BUF_TYPE_VIDEO_CAPTURE || cam->io!= IO_MMAP)
1614 return -EINVAL;
1615
1616 if (list_empty(&cam->outqueue)) {
1617 if (cam->stream == STREAM_OFF)
1618 return -EINVAL;
1619 if (filp->f_flags & O_NONBLOCK)
1620 return -EAGAIN;
1621 timeout = wait_event_interruptible_timeout
1622 ( cam->wait_frame,
1623 (!list_empty(&cam->outqueue)) ||
1624 (cam->state & DEV_DISCONNECTED) ||
1625 (cam->state & DEV_MISCONFIGURED),
1626 cam->module_param.frame_timeout *
1627 1000 * msecs_to_jiffies(1) );
1628 if (timeout < 0)
1629 return timeout;
1630 if (cam->state & DEV_DISCONNECTED)
1631 return -ENODEV;
1632 if (!timeout || (cam->state & DEV_MISCONFIGURED))
1633 return -EIO;
1634 }
1635
1636 spin_lock_irqsave(&cam->queue_lock, lock_flags);
1637 f = list_entry(cam->outqueue.next, struct zc0301_frame_t, frame);
1638 list_del(cam->outqueue.next);
1639 spin_unlock_irqrestore(&cam->queue_lock, lock_flags);
1640
1641 f->state = F_UNUSED;
1642
1643 memcpy(&b, &f->buf, sizeof(b));
1644 if (f->vma_use_count)
1645 b.flags |= V4L2_BUF_FLAG_MAPPED;
1646
1647 if (copy_to_user(arg, &b, sizeof(b)))
1648 return -EFAULT;
1649
1650 PDBGG("Frame #%lu dequeued", (unsigned long)f->buf.index);
1651
1652 return 0;
1653}
1654
1655
1656static int
1657zc0301_vidioc_streamon(struct zc0301_device* cam, void __user * arg)
1658{
1659 int type;
1660
1661 if (copy_from_user(&type, arg, sizeof(type)))
1662 return -EFAULT;
1663
1664 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE || cam->io != IO_MMAP)
1665 return -EINVAL;
1666
1667 if (list_empty(&cam->inqueue))
1668 return -EINVAL;
1669
1670 cam->stream = STREAM_ON;
1671
1672 DBG(3, "Stream on");
1673
1674 return 0;
1675}
1676
1677
1678static int
1679zc0301_vidioc_streamoff(struct zc0301_device* cam, void __user * arg)
1680{
1681 int type, err;
1682
1683 if (copy_from_user(&type, arg, sizeof(type)))
1684 return -EFAULT;
1685
1686 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE || cam->io != IO_MMAP)
1687 return -EINVAL;
1688
1689 if (cam->stream == STREAM_ON)
1690 if ((err = zc0301_stream_interrupt(cam)))
1691 return err;
1692
1693 zc0301_empty_framequeues(cam);
1694
1695 DBG(3, "Stream off");
1696
1697 return 0;
1698}
1699
1700
1701static int
1702zc0301_vidioc_g_parm(struct zc0301_device* cam, void __user * arg)
1703{
1704 struct v4l2_streamparm sp;
1705
1706 if (copy_from_user(&sp, arg, sizeof(sp)))
1707 return -EFAULT;
1708
1709 if (sp.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1710 return -EINVAL;
1711
1712 sp.parm.capture.extendedmode = 0;
1713 sp.parm.capture.readbuffers = cam->nreadbuffers;
1714
1715 if (copy_to_user(arg, &sp, sizeof(sp)))
1716 return -EFAULT;
1717
1718 return 0;
1719}
1720
1721
1722static int
1723zc0301_vidioc_s_parm(struct zc0301_device* cam, void __user * arg)
1724{
1725 struct v4l2_streamparm sp;
1726
1727 if (copy_from_user(&sp, arg, sizeof(sp)))
1728 return -EFAULT;
1729
1730 if (sp.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1731 return -EINVAL;
1732
1733 sp.parm.capture.extendedmode = 0;
1734
1735 if (sp.parm.capture.readbuffers == 0)
1736 sp.parm.capture.readbuffers = cam->nreadbuffers;
1737
1738 if (sp.parm.capture.readbuffers > ZC0301_MAX_FRAMES)
1739 sp.parm.capture.readbuffers = ZC0301_MAX_FRAMES;
1740
1741 if (copy_to_user(arg, &sp, sizeof(sp)))
1742 return -EFAULT;
1743
1744 cam->nreadbuffers = sp.parm.capture.readbuffers;
1745
1746 return 0;
1747}
1748
1749
1750static int zc0301_ioctl_v4l2(struct inode* inode, struct file* filp,
1751 unsigned int cmd, void __user * arg)
1752{
1753 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
1754
1755 switch (cmd) {
1756
1757 case VIDIOC_QUERYCAP:
1758 return zc0301_vidioc_querycap(cam, arg);
1759
1760 case VIDIOC_ENUMINPUT:
1761 return zc0301_vidioc_enuminput(cam, arg);
1762
1763 case VIDIOC_G_INPUT:
1764 return zc0301_vidioc_g_input(cam, arg);
1765
1766 case VIDIOC_S_INPUT:
1767 return zc0301_vidioc_s_input(cam, arg);
1768
1769 case VIDIOC_QUERYCTRL:
1770 return zc0301_vidioc_query_ctrl(cam, arg);
1771
1772 case VIDIOC_G_CTRL:
1773 return zc0301_vidioc_g_ctrl(cam, arg);
1774
1775 case VIDIOC_S_CTRL_OLD:
1776 case VIDIOC_S_CTRL:
1777 return zc0301_vidioc_s_ctrl(cam, arg);
1778
1779 case VIDIOC_CROPCAP_OLD:
1780 case VIDIOC_CROPCAP:
1781 return zc0301_vidioc_cropcap(cam, arg);
1782
1783 case VIDIOC_G_CROP:
1784 return zc0301_vidioc_g_crop(cam, arg);
1785
1786 case VIDIOC_S_CROP:
1787 return zc0301_vidioc_s_crop(cam, arg);
1788
1789 case VIDIOC_ENUM_FMT:
1790 return zc0301_vidioc_enum_fmt(cam, arg);
1791
1792 case VIDIOC_G_FMT:
1793 return zc0301_vidioc_g_fmt(cam, arg);
1794
1795 case VIDIOC_TRY_FMT:
1796 case VIDIOC_S_FMT:
1797 return zc0301_vidioc_try_s_fmt(cam, cmd, arg);
1798
1799 case VIDIOC_G_JPEGCOMP:
1800 return zc0301_vidioc_g_jpegcomp(cam, arg);
1801
1802 case VIDIOC_S_JPEGCOMP:
1803 return zc0301_vidioc_s_jpegcomp(cam, arg);
1804
1805 case VIDIOC_REQBUFS:
1806 return zc0301_vidioc_reqbufs(cam, arg);
1807
1808 case VIDIOC_QUERYBUF:
1809 return zc0301_vidioc_querybuf(cam, arg);
1810
1811 case VIDIOC_QBUF:
1812 return zc0301_vidioc_qbuf(cam, arg);
1813
1814 case VIDIOC_DQBUF:
1815 return zc0301_vidioc_dqbuf(cam, filp, arg);
1816
1817 case VIDIOC_STREAMON:
1818 return zc0301_vidioc_streamon(cam, arg);
1819
1820 case VIDIOC_STREAMOFF:
1821 return zc0301_vidioc_streamoff(cam, arg);
1822
1823 case VIDIOC_G_PARM:
1824 return zc0301_vidioc_g_parm(cam, arg);
1825
1826 case VIDIOC_S_PARM_OLD:
1827 case VIDIOC_S_PARM:
1828 return zc0301_vidioc_s_parm(cam, arg);
1829
1830 case VIDIOC_G_STD:
1831 case VIDIOC_S_STD:
1832 case VIDIOC_QUERYSTD:
1833 case VIDIOC_ENUMSTD:
1834 case VIDIOC_QUERYMENU:
1835 return -EINVAL;
1836
1837 default:
1838 return -EINVAL;
1839
1840 }
1841}
1842
1843
1844static int zc0301_ioctl(struct inode* inode, struct file* filp,
1845 unsigned int cmd, unsigned long arg)
1846{
1847 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
1848 int err = 0;
1849
1850 if (mutex_lock_interruptible(&cam->fileop_mutex))
1851 return -ERESTARTSYS;
1852
1853 if (cam->state & DEV_DISCONNECTED) {
1854 DBG(1, "Device not present");
1855 mutex_unlock(&cam->fileop_mutex);
1856 return -ENODEV;
1857 }
1858
1859 if (cam->state & DEV_MISCONFIGURED) {
1860 DBG(1, "The camera is misconfigured. Close and open it "
1861 "again.");
1862 mutex_unlock(&cam->fileop_mutex);
1863 return -EIO;
1864 }
1865
1866 V4LDBG(3, "zc0301", cmd);
1867
1868 err = zc0301_ioctl_v4l2(inode, filp, cmd, (void __user *)arg);
1869
1870 mutex_unlock(&cam->fileop_mutex);
1871
1872 return err;
1873}
1874
1875
1876static struct file_operations zc0301_fops = {
1877 .owner = THIS_MODULE,
1878 .open = zc0301_open,
1879 .release = zc0301_release,
1880 .ioctl = zc0301_ioctl,
1881 .read = zc0301_read,
1882 .poll = zc0301_poll,
1883 .mmap = zc0301_mmap,
1884 .llseek = no_llseek,
1885};
1886
1887/*****************************************************************************/
1888
1889static int
1890zc0301_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
1891{
1892 struct usb_device *udev = interface_to_usbdev(intf);
1893 struct zc0301_device* cam;
1894 static unsigned int dev_nr = 0;
1895 unsigned int i;
1896 int err = 0;
1897
1898 if (!(cam = kzalloc(sizeof(struct zc0301_device), GFP_KERNEL)))
1899 return -ENOMEM;
1900
1901 cam->usbdev = udev;
1902
1903 if (!(cam->control_buffer = kzalloc(4, GFP_KERNEL))) {
1904 DBG(1, "kmalloc() failed");
1905 err = -ENOMEM;
1906 goto fail;
1907 }
1908
1909 if (!(cam->v4ldev = video_device_alloc())) {
1910 DBG(1, "video_device_alloc() failed");
1911 err = -ENOMEM;
1912 goto fail;
1913 }
1914
1915 mutex_init(&cam->dev_mutex);
1916
1917 DBG(2, "ZC0301 Image Processor and Control Chip detected "
1918 "(vid/pid 0x%04X/0x%04X)",id->idVendor, id->idProduct);
1919
1920 for (i = 0; zc0301_sensor_table[i]; i++) {
1921 err = zc0301_sensor_table[i](cam);
1922 if (!err)
1923 break;
1924 }
1925
1926 if (!err)
1927 DBG(2, "%s image sensor detected", cam->sensor.name);
1928 else {
1929 DBG(1, "No supported image sensor detected");
1930 err = -ENODEV;
1931 goto fail;
1932 }
1933
1934 if (zc0301_init(cam)) {
1935 DBG(1, "Initialization failed. I will retry on open().");
1936 cam->state |= DEV_MISCONFIGURED;
1937 }
1938
1939 strcpy(cam->v4ldev->name, "ZC0301 PC Camera");
1940 cam->v4ldev->owner = THIS_MODULE;
1941 cam->v4ldev->type = VID_TYPE_CAPTURE | VID_TYPE_SCALES;
1942 cam->v4ldev->hardware = 0;
1943 cam->v4ldev->fops = &zc0301_fops;
1944 cam->v4ldev->minor = video_nr[dev_nr];
1945 cam->v4ldev->release = video_device_release;
1946 video_set_drvdata(cam->v4ldev, cam);
1947
1948 mutex_lock(&cam->dev_mutex);
1949
1950 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
1951 video_nr[dev_nr]);
1952 if (err) {
1953 DBG(1, "V4L2 device registration failed");
1954 if (err == -ENFILE && video_nr[dev_nr] == -1)
1955 DBG(1, "Free /dev/videoX node not found");
1956 video_nr[dev_nr] = -1;
1957 dev_nr = (dev_nr < ZC0301_MAX_DEVICES-1) ? dev_nr+1 : 0;
1958 mutex_unlock(&cam->dev_mutex);
1959 goto fail;
1960 }
1961
1962 DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->minor);
1963
1964 cam->module_param.force_munmap = force_munmap[dev_nr];
1965 cam->module_param.frame_timeout = frame_timeout[dev_nr];
1966
1967 dev_nr = (dev_nr < ZC0301_MAX_DEVICES-1) ? dev_nr+1 : 0;
1968
1969 usb_set_intfdata(intf, cam);
1970
1971 mutex_unlock(&cam->dev_mutex);
1972
1973 return 0;
1974
1975fail:
1976 if (cam) {
1977 kfree(cam->control_buffer);
1978 if (cam->v4ldev)
1979 video_device_release(cam->v4ldev);
1980 kfree(cam);
1981 }
1982 return err;
1983}
1984
1985
1986static void zc0301_usb_disconnect(struct usb_interface* intf)
1987{
1988 struct zc0301_device* cam = usb_get_intfdata(intf);
1989
1990 if (!cam)
1991 return;
1992
1993 down_write(&zc0301_disconnect);
1994
1995 mutex_lock(&cam->dev_mutex);
1996
1997 DBG(2, "Disconnecting %s...", cam->v4ldev->name);
1998
1999 wake_up_interruptible_all(&cam->open);
2000
2001 if (cam->users) {
2002 DBG(2, "Device /dev/video%d is open! Deregistration and "
2003 "memory deallocation are deferred on close.",
2004 cam->v4ldev->minor);
2005 cam->state |= DEV_MISCONFIGURED;
2006 zc0301_stop_transfer(cam);
2007 cam->state |= DEV_DISCONNECTED;
2008 wake_up_interruptible(&cam->wait_frame);
2009 wake_up(&cam->wait_stream);
2010 usb_get_dev(cam->usbdev);
2011 } else {
2012 cam->state |= DEV_DISCONNECTED;
2013 zc0301_release_resources(cam);
2014 }
2015
2016 mutex_unlock(&cam->dev_mutex);
2017
2018 if (!cam->users)
2019 kfree(cam);
2020
2021 up_write(&zc0301_disconnect);
2022}
2023
2024
2025static struct usb_driver zc0301_usb_driver = {
2026 .name = "zc0301",
2027 .id_table = zc0301_id_table,
2028 .probe = zc0301_usb_probe,
2029 .disconnect = zc0301_usb_disconnect,
2030};
2031
2032/*****************************************************************************/
2033
2034static int __init zc0301_module_init(void)
2035{
2036 int err = 0;
2037
2038 KDBG(2, ZC0301_MODULE_NAME " v" ZC0301_MODULE_VERSION);
2039 KDBG(3, ZC0301_MODULE_AUTHOR);
2040
2041 if ((err = usb_register(&zc0301_usb_driver)))
2042 KDBG(1, "usb_register() failed");
2043
2044 return err;
2045}
2046
2047
2048static void __exit zc0301_module_exit(void)
2049{
2050 usb_deregister(&zc0301_usb_driver);
2051}
2052
2053
2054module_init(zc0301_module_init);
2055module_exit(zc0301_module_exit);
diff --git a/drivers/usb/media/zc0301_pas202bcb.c b/drivers/usb/media/zc0301_pas202bcb.c
new file mode 100644
index 000000000000..9d282a22c15f
--- /dev/null
+++ b/drivers/usb/media/zc0301_pas202bcb.c
@@ -0,0 +1,361 @@
1/***************************************************************************
2 * Plug-in for PAS202BCB image sensor connected to the ZC030! Image *
3 * Processor and Control Chip *
4 * *
5 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> *
6 * *
7 * Initialization values of the ZC0301 have been taken from the SPCA5XX *
8 * driver maintained by Michel Xhaard <mxhaard@magic.fr> *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the Free Software *
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
23 ***************************************************************************/
24
25/*
26 NOTE: Sensor controls are disabled for now, becouse changing them while
27 streaming sometimes results in out-of-sync video frames. We'll use
28 the default initialization, until we know how to stop and start video
29 in the chip. However, the image quality still looks good under various
30 light conditions.
31*/
32
33#include <linux/delay.h>
34#include "zc0301_sensor.h"
35
36
37static struct zc0301_sensor pas202bcb;
38
39
40static int pas202bcb_init(struct zc0301_device* cam)
41{
42 int err = 0;
43
44 err += zc0301_write_reg(cam, 0x0002, 0x00);
45 err += zc0301_write_reg(cam, 0x0003, 0x02);
46 err += zc0301_write_reg(cam, 0x0004, 0x80);
47 err += zc0301_write_reg(cam, 0x0005, 0x01);
48 err += zc0301_write_reg(cam, 0x0006, 0xE0);
49 err += zc0301_write_reg(cam, 0x0098, 0x00);
50 err += zc0301_write_reg(cam, 0x009A, 0x03);
51 err += zc0301_write_reg(cam, 0x011A, 0x00);
52 err += zc0301_write_reg(cam, 0x011C, 0x03);
53 err += zc0301_write_reg(cam, 0x009B, 0x01);
54 err += zc0301_write_reg(cam, 0x009C, 0xE6);
55 err += zc0301_write_reg(cam, 0x009D, 0x02);
56 err += zc0301_write_reg(cam, 0x009E, 0x86);
57
58 err += zc0301_i2c_write(cam, 0x02, 0x02);
59 err += zc0301_i2c_write(cam, 0x0A, 0x01);
60 err += zc0301_i2c_write(cam, 0x0B, 0x01);
61 err += zc0301_i2c_write(cam, 0x0D, 0x00);
62 err += zc0301_i2c_write(cam, 0x12, 0x05);
63 err += zc0301_i2c_write(cam, 0x13, 0x63);
64 err += zc0301_i2c_write(cam, 0x15, 0x70);
65
66 err += zc0301_write_reg(cam, 0x0101, 0xB7);
67 err += zc0301_write_reg(cam, 0x0100, 0x0D);
68 err += zc0301_write_reg(cam, 0x0189, 0x06);
69 err += zc0301_write_reg(cam, 0x01AD, 0x00);
70 err += zc0301_write_reg(cam, 0x01C5, 0x03);
71 err += zc0301_write_reg(cam, 0x01CB, 0x13);
72 err += zc0301_write_reg(cam, 0x0250, 0x08);
73 err += zc0301_write_reg(cam, 0x0301, 0x08);
74 err += zc0301_write_reg(cam, 0x018D, 0x70);
75 err += zc0301_write_reg(cam, 0x0008, 0x03);
76 err += zc0301_write_reg(cam, 0x01C6, 0x04);
77 err += zc0301_write_reg(cam, 0x01CB, 0x07);
78 err += zc0301_write_reg(cam, 0x0120, 0x11);
79 err += zc0301_write_reg(cam, 0x0121, 0x37);
80 err += zc0301_write_reg(cam, 0x0122, 0x58);
81 err += zc0301_write_reg(cam, 0x0123, 0x79);
82 err += zc0301_write_reg(cam, 0x0124, 0x91);
83 err += zc0301_write_reg(cam, 0x0125, 0xA6);
84 err += zc0301_write_reg(cam, 0x0126, 0xB8);
85 err += zc0301_write_reg(cam, 0x0127, 0xC7);
86 err += zc0301_write_reg(cam, 0x0128, 0xD3);
87 err += zc0301_write_reg(cam, 0x0129, 0xDE);
88 err += zc0301_write_reg(cam, 0x012A, 0xE6);
89 err += zc0301_write_reg(cam, 0x012B, 0xED);
90 err += zc0301_write_reg(cam, 0x012C, 0xF3);
91 err += zc0301_write_reg(cam, 0x012D, 0xF8);
92 err += zc0301_write_reg(cam, 0x012E, 0xFB);
93 err += zc0301_write_reg(cam, 0x012F, 0xFF);
94 err += zc0301_write_reg(cam, 0x0130, 0x26);
95 err += zc0301_write_reg(cam, 0x0131, 0x23);
96 err += zc0301_write_reg(cam, 0x0132, 0x20);
97 err += zc0301_write_reg(cam, 0x0133, 0x1C);
98 err += zc0301_write_reg(cam, 0x0134, 0x16);
99 err += zc0301_write_reg(cam, 0x0135, 0x13);
100 err += zc0301_write_reg(cam, 0x0136, 0x10);
101 err += zc0301_write_reg(cam, 0x0137, 0x0D);
102 err += zc0301_write_reg(cam, 0x0138, 0x0B);
103 err += zc0301_write_reg(cam, 0x0139, 0x09);
104 err += zc0301_write_reg(cam, 0x013A, 0x07);
105 err += zc0301_write_reg(cam, 0x013B, 0x06);
106 err += zc0301_write_reg(cam, 0x013C, 0x05);
107 err += zc0301_write_reg(cam, 0x013D, 0x04);
108 err += zc0301_write_reg(cam, 0x013E, 0x03);
109 err += zc0301_write_reg(cam, 0x013F, 0x02);
110 err += zc0301_write_reg(cam, 0x010A, 0x4C);
111 err += zc0301_write_reg(cam, 0x010B, 0xF5);
112 err += zc0301_write_reg(cam, 0x010C, 0xFF);
113 err += zc0301_write_reg(cam, 0x010D, 0xF9);
114 err += zc0301_write_reg(cam, 0x010E, 0x51);
115 err += zc0301_write_reg(cam, 0x010F, 0xF5);
116 err += zc0301_write_reg(cam, 0x0110, 0xFB);
117 err += zc0301_write_reg(cam, 0x0111, 0xED);
118 err += zc0301_write_reg(cam, 0x0112, 0x5F);
119 err += zc0301_write_reg(cam, 0x0180, 0x00);
120 err += zc0301_write_reg(cam, 0x0019, 0x00);
121 err += zc0301_write_reg(cam, 0x0087, 0x20);
122 err += zc0301_write_reg(cam, 0x0088, 0x21);
123
124 err += zc0301_i2c_write(cam, 0x20, 0x02);
125 err += zc0301_i2c_write(cam, 0x21, 0x1B);
126 err += zc0301_i2c_write(cam, 0x03, 0x44);
127 err += zc0301_i2c_write(cam, 0x0E, 0x01);
128 err += zc0301_i2c_write(cam, 0x0F, 0x00);
129
130 err += zc0301_write_reg(cam, 0x01A9, 0x14);
131 err += zc0301_write_reg(cam, 0x01AA, 0x24);
132 err += zc0301_write_reg(cam, 0x0190, 0x00);
133 err += zc0301_write_reg(cam, 0x0191, 0x02);
134 err += zc0301_write_reg(cam, 0x0192, 0x1B);
135 err += zc0301_write_reg(cam, 0x0195, 0x00);
136 err += zc0301_write_reg(cam, 0x0196, 0x00);
137 err += zc0301_write_reg(cam, 0x0197, 0x4D);
138 err += zc0301_write_reg(cam, 0x018C, 0x10);
139 err += zc0301_write_reg(cam, 0x018F, 0x20);
140 err += zc0301_write_reg(cam, 0x001D, 0x44);
141 err += zc0301_write_reg(cam, 0x001E, 0x6F);
142 err += zc0301_write_reg(cam, 0x001F, 0xAD);
143 err += zc0301_write_reg(cam, 0x0020, 0xEB);
144 err += zc0301_write_reg(cam, 0x0087, 0x0F);
145 err += zc0301_write_reg(cam, 0x0088, 0x0E);
146 err += zc0301_write_reg(cam, 0x0180, 0x40);
147 err += zc0301_write_reg(cam, 0x0192, 0x1B);
148 err += zc0301_write_reg(cam, 0x0191, 0x02);
149 err += zc0301_write_reg(cam, 0x0190, 0x00);
150 err += zc0301_write_reg(cam, 0x0116, 0x1D);
151 err += zc0301_write_reg(cam, 0x0117, 0x40);
152 err += zc0301_write_reg(cam, 0x0118, 0x99);
153 err += zc0301_write_reg(cam, 0x0180, 0x42);
154 err += zc0301_write_reg(cam, 0x0116, 0x1D);
155 err += zc0301_write_reg(cam, 0x0117, 0x40);
156 err += zc0301_write_reg(cam, 0x0118, 0x99);
157 err += zc0301_write_reg(cam, 0x0007, 0x00);
158
159 err += zc0301_i2c_write(cam, 0x11, 0x01);
160
161 msleep(100);
162
163 return err;
164}
165
166
167static int pas202bcb_get_ctrl(struct zc0301_device* cam,
168 struct v4l2_control* ctrl)
169{
170 switch (ctrl->id) {
171 case V4L2_CID_EXPOSURE:
172 {
173 int r1 = zc0301_i2c_read(cam, 0x04, 1),
174 r2 = zc0301_i2c_read(cam, 0x05, 1);
175 if (r1 < 0 || r2 < 0)
176 return -EIO;
177 ctrl->value = (r1 << 6) | (r2 & 0x3f);
178 }
179 return 0;
180 case V4L2_CID_RED_BALANCE:
181 if ((ctrl->value = zc0301_i2c_read(cam, 0x09, 1)) < 0)
182 return -EIO;
183 ctrl->value &= 0x0f;
184 return 0;
185 case V4L2_CID_BLUE_BALANCE:
186 if ((ctrl->value = zc0301_i2c_read(cam, 0x07, 1)) < 0)
187 return -EIO;
188 ctrl->value &= 0x0f;
189 return 0;
190 case V4L2_CID_GAIN:
191 if ((ctrl->value = zc0301_i2c_read(cam, 0x10, 1)) < 0)
192 return -EIO;
193 ctrl->value &= 0x1f;
194 return 0;
195 case ZC0301_V4L2_CID_GREEN_BALANCE:
196 if ((ctrl->value = zc0301_i2c_read(cam, 0x08, 1)) < 0)
197 return -EIO;
198 ctrl->value &= 0x0f;
199 return 0;
200 case ZC0301_V4L2_CID_DAC_MAGNITUDE:
201 if ((ctrl->value = zc0301_i2c_read(cam, 0x0c, 1)) < 0)
202 return -EIO;
203 return 0;
204 default:
205 return -EINVAL;
206 }
207}
208
209
210static int pas202bcb_set_ctrl(struct zc0301_device* cam,
211 const struct v4l2_control* ctrl)
212{
213 int err = 0;
214
215 switch (ctrl->id) {
216 case V4L2_CID_EXPOSURE:
217 err += zc0301_i2c_write(cam, 0x04, ctrl->value >> 6);
218 err += zc0301_i2c_write(cam, 0x05, ctrl->value & 0x3f);
219 break;
220 case V4L2_CID_RED_BALANCE:
221 err += zc0301_i2c_write(cam, 0x09, ctrl->value);
222 break;
223 case V4L2_CID_BLUE_BALANCE:
224 err += zc0301_i2c_write(cam, 0x07, ctrl->value);
225 break;
226 case V4L2_CID_GAIN:
227 err += zc0301_i2c_write(cam, 0x10, ctrl->value);
228 break;
229 case ZC0301_V4L2_CID_GREEN_BALANCE:
230 err += zc0301_i2c_write(cam, 0x08, ctrl->value);
231 break;
232 case ZC0301_V4L2_CID_DAC_MAGNITUDE:
233 err += zc0301_i2c_write(cam, 0x0c, ctrl->value);
234 break;
235 default:
236 return -EINVAL;
237 }
238 err += zc0301_i2c_write(cam, 0x11, 0x01);
239
240 return err ? -EIO : 0;
241}
242
243
244static struct zc0301_sensor pas202bcb = {
245 .name = "PAS202BCB",
246 .init = &pas202bcb_init,
247 .qctrl = {
248 {
249 .id = V4L2_CID_EXPOSURE,
250 .type = V4L2_CTRL_TYPE_INTEGER,
251 .name = "exposure",
252 .minimum = 0x01e5,
253 .maximum = 0x3fff,
254 .step = 0x0001,
255 .default_value = 0x01e5,
256 .flags = V4L2_CTRL_FLAG_DISABLED,
257 },
258 {
259 .id = V4L2_CID_GAIN,
260 .type = V4L2_CTRL_TYPE_INTEGER,
261 .name = "global gain",
262 .minimum = 0x00,
263 .maximum = 0x1f,
264 .step = 0x01,
265 .default_value = 0x0c,
266 .flags = V4L2_CTRL_FLAG_DISABLED,
267 },
268 {
269 .id = ZC0301_V4L2_CID_DAC_MAGNITUDE,
270 .type = V4L2_CTRL_TYPE_INTEGER,
271 .name = "DAC magnitude",
272 .minimum = 0x00,
273 .maximum = 0xff,
274 .step = 0x01,
275 .default_value = 0x00,
276 .flags = V4L2_CTRL_FLAG_DISABLED,
277 },
278 {
279 .id = V4L2_CID_RED_BALANCE,
280 .type = V4L2_CTRL_TYPE_INTEGER,
281 .name = "red balance",
282 .minimum = 0x00,
283 .maximum = 0x0f,
284 .step = 0x01,
285 .default_value = 0x01,
286 .flags = V4L2_CTRL_FLAG_DISABLED,
287 },
288 {
289 .id = V4L2_CID_BLUE_BALANCE,
290 .type = V4L2_CTRL_TYPE_INTEGER,
291 .name = "blue balance",
292 .minimum = 0x00,
293 .maximum = 0x0f,
294 .step = 0x01,
295 .default_value = 0x05,
296 .flags = V4L2_CTRL_FLAG_DISABLED,
297 },
298 {
299 .id = ZC0301_V4L2_CID_GREEN_BALANCE,
300 .type = V4L2_CTRL_TYPE_INTEGER,
301 .name = "green balance",
302 .minimum = 0x00,
303 .maximum = 0x0f,
304 .step = 0x01,
305 .default_value = 0x00,
306 .flags = V4L2_CTRL_FLAG_DISABLED,
307 },
308 },
309 .get_ctrl = &pas202bcb_get_ctrl,
310 .set_ctrl = &pas202bcb_set_ctrl,
311 .cropcap = {
312 .bounds = {
313 .left = 0,
314 .top = 0,
315 .width = 640,
316 .height = 480,
317 },
318 .defrect = {
319 .left = 0,
320 .top = 0,
321 .width = 640,
322 .height = 480,
323 },
324 },
325 .pix_format = {
326 .width = 640,
327 .height = 480,
328 .pixelformat = V4L2_PIX_FMT_JPEG,
329 .priv = 8,
330 },
331};
332
333
334int zc0301_probe_pas202bcb(struct zc0301_device* cam)
335{
336 int r0 = 0, r1 = 0, err = 0;
337 unsigned int pid = 0;
338
339 err += zc0301_write_reg(cam, 0x0000, 0x01);
340 err += zc0301_write_reg(cam, 0x0010, 0x0e);
341 err += zc0301_write_reg(cam, 0x0001, 0x01);
342 err += zc0301_write_reg(cam, 0x0012, 0x03);
343 err += zc0301_write_reg(cam, 0x0012, 0x01);
344 err += zc0301_write_reg(cam, 0x008d, 0x08);
345
346 msleep(10);
347
348 r0 = zc0301_i2c_read(cam, 0x00, 1);
349 r1 = zc0301_i2c_read(cam, 0x01, 1);
350
351 if (r0 < 0 || r1 < 0 || err)
352 return -EIO;
353
354 pid = (r0 << 4) | ((r1 & 0xf0) >> 4);
355 if (pid != 0x017)
356 return -ENODEV;
357
358 zc0301_attach_sensor(cam, &pas202bcb);
359
360 return 0;
361}
diff --git a/drivers/usb/media/zc0301_sensor.h b/drivers/usb/media/zc0301_sensor.h
new file mode 100644
index 000000000000..cf0965a81d01
--- /dev/null
+++ b/drivers/usb/media/zc0301_sensor.h
@@ -0,0 +1,103 @@
1/***************************************************************************
2 * API for image sensors connected to the ZC030! Image Processor and *
3 * Control Chip *
4 * *
5 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
20 ***************************************************************************/
21
22#ifndef _ZC0301_SENSOR_H_
23#define _ZC0301_SENSOR_H_
24
25#include <linux/usb.h>
26#include <linux/videodev.h>
27#include <linux/device.h>
28#include <linux/stddef.h>
29#include <linux/errno.h>
30#include <asm/types.h>
31
32struct zc0301_device;
33struct zc0301_sensor;
34
35/*****************************************************************************/
36
37extern int zc0301_probe_pas202bcb(struct zc0301_device* cam);
38
39#define ZC0301_SENSOR_TABLE \
40/* Weak detections must go at the end of the list */ \
41static int (*zc0301_sensor_table[])(struct zc0301_device*) = { \
42 &zc0301_probe_pas202bcb, \
43 NULL, \
44};
45
46extern struct zc0301_device*
47zc0301_match_id(struct zc0301_device* cam, const struct usb_device_id *id);
48
49extern void
50zc0301_attach_sensor(struct zc0301_device* cam, struct zc0301_sensor* sensor);
51
52#define ZC0301_USB_DEVICE(vend, prod, intclass) \
53 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
54 USB_DEVICE_ID_MATCH_INT_CLASS, \
55 .idVendor = (vend), \
56 .idProduct = (prod), \
57 .bInterfaceClass = (intclass)
58
59#define ZC0301_ID_TABLE \
60static const struct usb_device_id zc0301_id_table[] = { \
61 { ZC0301_USB_DEVICE(0x041e, 0x4017, 0xff), }, \
62 { ZC0301_USB_DEVICE(0x041e, 0x401c, 0xff), }, /* PAS106 */ \
63 { ZC0301_USB_DEVICE(0x041e, 0x401e, 0xff), }, /* HV7131B */ \
64 { ZC0301_USB_DEVICE(0x041e, 0x4034, 0xff), }, /* PAS106 */ \
65 { ZC0301_USB_DEVICE(0x041e, 0x4035, 0xff), }, /* PAS106 */ \
66 { ZC0301_USB_DEVICE(0x046d, 0x08ae, 0xff), }, /* PAS202BCB */ \
67 { ZC0301_USB_DEVICE(0x0ac8, 0x0301, 0xff), }, \
68 { ZC0301_USB_DEVICE(0x10fd, 0x8050, 0xff), }, /* TAS5130D */ \
69 { } \
70};
71
72/*****************************************************************************/
73
74extern int zc0301_write_reg(struct zc0301_device*, u16 index, u16 value);
75extern int zc0301_read_reg(struct zc0301_device*, u16 index);
76extern int zc0301_i2c_write(struct zc0301_device*, u16 address, u16 value);
77extern int zc0301_i2c_read(struct zc0301_device*, u16 address, u8 length);
78
79/*****************************************************************************/
80
81#define ZC0301_MAX_CTRLS V4L2_CID_LASTP1-V4L2_CID_BASE+10
82#define ZC0301_V4L2_CID_DAC_MAGNITUDE V4L2_CID_PRIVATE_BASE
83#define ZC0301_V4L2_CID_GREEN_BALANCE V4L2_CID_PRIVATE_BASE + 1
84
85struct zc0301_sensor {
86 char name[32];
87
88 struct v4l2_queryctrl qctrl[ZC0301_MAX_CTRLS];
89 struct v4l2_cropcap cropcap;
90 struct v4l2_pix_format pix_format;
91
92 int (*init)(struct zc0301_device*);
93 int (*get_ctrl)(struct zc0301_device*, struct v4l2_control* ctrl);
94 int (*set_ctrl)(struct zc0301_device*,
95 const struct v4l2_control* ctrl);
96 int (*set_crop)(struct zc0301_device*, const struct v4l2_rect* rect);
97
98 /* Private */
99 struct v4l2_queryctrl _qctrl[ZC0301_MAX_CTRLS];
100 struct v4l2_rect _rect;
101};
102
103#endif /* _ZC0301_SENSOR_H_ */
diff --git a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c
index ad2f4cccd388..1fef36e71c57 100644
--- a/drivers/usb/misc/auerswald.c
+++ b/drivers/usb/misc/auerswald.c
@@ -570,10 +570,9 @@ static int auerchain_setup (pauerchain_t acp, unsigned int numElements)
570 570
571 /* fill the list of free elements */ 571 /* fill the list of free elements */
572 for (;numElements; numElements--) { 572 for (;numElements; numElements--) {
573 acep = (pauerchainelement_t) kmalloc (sizeof (auerchainelement_t), GFP_KERNEL); 573 acep = kzalloc(sizeof(auerchainelement_t), GFP_KERNEL);
574 if (!acep) 574 if (!acep)
575 goto ac_fail; 575 goto ac_fail;
576 memset (acep, 0, sizeof (auerchainelement_t));
577 INIT_LIST_HEAD (&acep->list); 576 INIT_LIST_HEAD (&acep->list);
578 list_add_tail (&acep->list, &acp->free_list); 577 list_add_tail (&acep->list, &acp->free_list);
579 } 578 }
@@ -761,10 +760,9 @@ static int auerbuf_setup (pauerbufctl_t bcp, unsigned int numElements, unsigned
761 760
762 /* fill the list of free elements */ 761 /* fill the list of free elements */
763 for (;numElements; numElements--) { 762 for (;numElements; numElements--) {
764 bep = (pauerbuf_t) kmalloc (sizeof (auerbuf_t), GFP_KERNEL); 763 bep = kzalloc(sizeof(auerbuf_t), GFP_KERNEL);
765 if (!bep) 764 if (!bep)
766 goto bl_fail; 765 goto bl_fail;
767 memset (bep, 0, sizeof (auerbuf_t));
768 bep->list = bcp; 766 bep->list = bcp;
769 INIT_LIST_HEAD (&bep->buff_list); 767 INIT_LIST_HEAD (&bep->buff_list);
770 bep->bufp = kmalloc (bufsize, GFP_KERNEL); 768 bep->bufp = kmalloc (bufsize, GFP_KERNEL);
diff --git a/drivers/usb/misc/cytherm.c b/drivers/usb/misc/cytherm.c
index 6671317b495f..a04204292aa3 100644
--- a/drivers/usb/misc/cytherm.c
+++ b/drivers/usb/misc/cytherm.c
@@ -351,12 +351,11 @@ static int cytherm_probe(struct usb_interface *interface,
351 struct usb_cytherm *dev = NULL; 351 struct usb_cytherm *dev = NULL;
352 int retval = -ENOMEM; 352 int retval = -ENOMEM;
353 353
354 dev = kmalloc (sizeof(struct usb_cytherm), GFP_KERNEL); 354 dev = kzalloc (sizeof(struct usb_cytherm), GFP_KERNEL);
355 if (dev == NULL) { 355 if (dev == NULL) {
356 dev_err (&interface->dev, "Out of memory\n"); 356 dev_err (&interface->dev, "Out of memory\n");
357 goto error; 357 goto error;
358 } 358 }
359 memset (dev, 0x00, sizeof (*dev));
360 359
361 dev->udev = usb_get_dev(udev); 360 dev->udev = usb_get_dev(udev);
362 361
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c
index d8cde1017985..d0b167256699 100644
--- a/drivers/usb/misc/idmouse.c
+++ b/drivers/usb/misc/idmouse.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/smp_lock.h> 26#include <linux/smp_lock.h>
27#include <linux/completion.h> 27#include <linux/completion.h>
28#include <linux/mutex.h>
28#include <asm/uaccess.h> 29#include <asm/uaccess.h>
29#include <linux/usb.h> 30#include <linux/usb.h>
30 31
@@ -121,7 +122,7 @@ static struct usb_driver idmouse_driver = {
121}; 122};
122 123
123/* prevent races between open() and disconnect() */ 124/* prevent races between open() and disconnect() */
124static DECLARE_MUTEX(disconnect_sem); 125static DEFINE_MUTEX(disconnect_mutex);
125 126
126static int idmouse_create_image(struct usb_idmouse *dev) 127static int idmouse_create_image(struct usb_idmouse *dev)
127{ 128{
@@ -213,18 +214,18 @@ static int idmouse_open(struct inode *inode, struct file *file)
213 int result = 0; 214 int result = 0;
214 215
215 /* prevent disconnects */ 216 /* prevent disconnects */
216 down(&disconnect_sem); 217 mutex_lock(&disconnect_mutex);
217 218
218 /* get the interface from minor number and driver information */ 219 /* get the interface from minor number and driver information */
219 interface = usb_find_interface (&idmouse_driver, iminor (inode)); 220 interface = usb_find_interface (&idmouse_driver, iminor (inode));
220 if (!interface) { 221 if (!interface) {
221 up(&disconnect_sem); 222 mutex_unlock(&disconnect_mutex);
222 return -ENODEV; 223 return -ENODEV;
223 } 224 }
224 /* get the device information block from the interface */ 225 /* get the device information block from the interface */
225 dev = usb_get_intfdata(interface); 226 dev = usb_get_intfdata(interface);
226 if (!dev) { 227 if (!dev) {
227 up(&disconnect_sem); 228 mutex_unlock(&disconnect_mutex);
228 return -ENODEV; 229 return -ENODEV;
229 } 230 }
230 231
@@ -258,7 +259,7 @@ error:
258 up(&dev->sem); 259 up(&dev->sem);
259 260
260 /* unlock the disconnect semaphore */ 261 /* unlock the disconnect semaphore */
261 up(&disconnect_sem); 262 mutex_unlock(&disconnect_mutex);
262 return result; 263 return result;
263} 264}
264 265
@@ -267,12 +268,12 @@ static int idmouse_release(struct inode *inode, struct file *file)
267 struct usb_idmouse *dev; 268 struct usb_idmouse *dev;
268 269
269 /* prevent a race condition with open() */ 270 /* prevent a race condition with open() */
270 down(&disconnect_sem); 271 mutex_lock(&disconnect_mutex);
271 272
272 dev = (struct usb_idmouse *) file->private_data; 273 dev = (struct usb_idmouse *) file->private_data;
273 274
274 if (dev == NULL) { 275 if (dev == NULL) {
275 up(&disconnect_sem); 276 mutex_unlock(&disconnect_mutex);
276 return -ENODEV; 277 return -ENODEV;
277 } 278 }
278 279
@@ -282,7 +283,7 @@ static int idmouse_release(struct inode *inode, struct file *file)
282 /* are we really open? */ 283 /* are we really open? */
283 if (dev->open <= 0) { 284 if (dev->open <= 0) {
284 up(&dev->sem); 285 up(&dev->sem);
285 up(&disconnect_sem); 286 mutex_unlock(&disconnect_mutex);
286 return -ENODEV; 287 return -ENODEV;
287 } 288 }
288 289
@@ -292,12 +293,12 @@ static int idmouse_release(struct inode *inode, struct file *file)
292 /* the device was unplugged before the file was released */ 293 /* the device was unplugged before the file was released */
293 up(&dev->sem); 294 up(&dev->sem);
294 idmouse_delete(dev); 295 idmouse_delete(dev);
295 up(&disconnect_sem); 296 mutex_unlock(&disconnect_mutex);
296 return 0; 297 return 0;
297 } 298 }
298 299
299 up(&dev->sem); 300 up(&dev->sem);
300 up(&disconnect_sem); 301 mutex_unlock(&disconnect_mutex);
301 return 0; 302 return 0;
302} 303}
303 304
@@ -340,10 +341,9 @@ static int idmouse_probe(struct usb_interface *interface,
340 return -ENODEV; 341 return -ENODEV;
341 342
342 /* allocate memory for our device state and initialize it */ 343 /* allocate memory for our device state and initialize it */
343 dev = kmalloc(sizeof(*dev), GFP_KERNEL); 344 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
344 if (dev == NULL) 345 if (dev == NULL)
345 return -ENOMEM; 346 return -ENOMEM;
346 memset(dev, 0x00, sizeof(*dev));
347 347
348 init_MUTEX(&dev->sem); 348 init_MUTEX(&dev->sem);
349 dev->udev = udev; 349 dev->udev = udev;
@@ -400,7 +400,7 @@ static void idmouse_disconnect(struct usb_interface *interface)
400 struct usb_idmouse *dev; 400 struct usb_idmouse *dev;
401 401
402 /* prevent races with open() */ 402 /* prevent races with open() */
403 down(&disconnect_sem); 403 mutex_lock(&disconnect_mutex);
404 404
405 /* get device structure */ 405 /* get device structure */
406 dev = usb_get_intfdata(interface); 406 dev = usb_get_intfdata(interface);
@@ -422,7 +422,7 @@ static void idmouse_disconnect(struct usb_interface *interface)
422 if (!dev->open) 422 if (!dev->open)
423 idmouse_delete(dev); 423 idmouse_delete(dev);
424 424
425 up(&disconnect_sem); 425 mutex_unlock(&disconnect_mutex);
426 426
427 info("%s disconnected", DRIVER_DESC); 427 info("%s disconnected", DRIVER_DESC);
428} 428}
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index e2d1198623eb..966acb474f67 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -33,6 +33,7 @@
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/mutex.h>
36 37
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
38#include <linux/input.h> 39#include <linux/input.h>
@@ -172,7 +173,7 @@ struct ld_usb {
172}; 173};
173 174
174/* prevent races between open() and disconnect() */ 175/* prevent races between open() and disconnect() */
175static DECLARE_MUTEX(disconnect_sem); 176static DEFINE_MUTEX(disconnect_mutex);
176 177
177static struct usb_driver ld_usb_driver; 178static struct usb_driver ld_usb_driver;
178 179
@@ -293,7 +294,7 @@ static int ld_usb_open(struct inode *inode, struct file *file)
293 nonseekable_open(inode, file); 294 nonseekable_open(inode, file);
294 subminor = iminor(inode); 295 subminor = iminor(inode);
295 296
296 down(&disconnect_sem); 297 mutex_lock(&disconnect_mutex);
297 298
298 interface = usb_find_interface(&ld_usb_driver, subminor); 299 interface = usb_find_interface(&ld_usb_driver, subminor);
299 300
@@ -355,7 +356,7 @@ unlock_exit:
355 up(&dev->sem); 356 up(&dev->sem);
356 357
357unlock_disconnect_exit: 358unlock_disconnect_exit:
358 up(&disconnect_sem); 359 mutex_unlock(&disconnect_mutex);
359 360
360 return retval; 361 return retval;
361} 362}
@@ -626,12 +627,11 @@ static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *
626 627
627 /* allocate memory for our device state and intialize it */ 628 /* allocate memory for our device state and intialize it */
628 629
629 dev = kmalloc(sizeof(*dev), GFP_KERNEL); 630 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
630 if (dev == NULL) { 631 if (dev == NULL) {
631 dev_err(&intf->dev, "Out of memory\n"); 632 dev_err(&intf->dev, "Out of memory\n");
632 goto exit; 633 goto exit;
633 } 634 }
634 memset(dev, 0x00, sizeof(*dev));
635 init_MUTEX(&dev->sem); 635 init_MUTEX(&dev->sem);
636 dev->intf = intf; 636 dev->intf = intf;
637 init_waitqueue_head(&dev->read_wait); 637 init_waitqueue_head(&dev->read_wait);
@@ -741,7 +741,7 @@ static void ld_usb_disconnect(struct usb_interface *intf)
741 struct ld_usb *dev; 741 struct ld_usb *dev;
742 int minor; 742 int minor;
743 743
744 down(&disconnect_sem); 744 mutex_lock(&disconnect_mutex);
745 745
746 dev = usb_get_intfdata(intf); 746 dev = usb_get_intfdata(intf);
747 usb_set_intfdata(intf, NULL); 747 usb_set_intfdata(intf, NULL);
@@ -762,7 +762,7 @@ static void ld_usb_disconnect(struct usb_interface *intf)
762 up(&dev->sem); 762 up(&dev->sem);
763 } 763 }
764 764
765 up(&disconnect_sem); 765 mutex_unlock(&disconnect_mutex);
766 766
767 dev_info(&intf->dev, "LD USB Device #%d now disconnected\n", 767 dev_info(&intf->dev, "LD USB Device #%d now disconnected\n",
768 (minor - USB_LD_MINOR_BASE)); 768 (minor - USB_LD_MINOR_BASE));
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 1336745b8f55..779bcf0373ad 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -83,6 +83,7 @@
83#include <linux/module.h> 83#include <linux/module.h>
84#include <linux/smp_lock.h> 84#include <linux/smp_lock.h>
85#include <linux/completion.h> 85#include <linux/completion.h>
86#include <linux/mutex.h>
86#include <asm/uaccess.h> 87#include <asm/uaccess.h>
87#include <linux/usb.h> 88#include <linux/usb.h>
88#include <linux/poll.h> 89#include <linux/poll.h>
@@ -256,7 +257,7 @@ static void tower_disconnect (struct usb_interface *interface);
256 257
257 258
258/* prevent races between open() and disconnect */ 259/* prevent races between open() and disconnect */
259static DECLARE_MUTEX (disconnect_sem); 260static DEFINE_MUTEX (disconnect_mutex);
260 261
261/* file operations needed when we register this driver */ 262/* file operations needed when we register this driver */
262static struct file_operations tower_fops = { 263static struct file_operations tower_fops = {
@@ -349,7 +350,7 @@ static int tower_open (struct inode *inode, struct file *file)
349 nonseekable_open(inode, file); 350 nonseekable_open(inode, file);
350 subminor = iminor(inode); 351 subminor = iminor(inode);
351 352
352 down (&disconnect_sem); 353 mutex_lock (&disconnect_mutex);
353 354
354 interface = usb_find_interface (&tower_driver, subminor); 355 interface = usb_find_interface (&tower_driver, subminor);
355 356
@@ -427,7 +428,7 @@ unlock_exit:
427 up (&dev->sem); 428 up (&dev->sem);
428 429
429unlock_disconnect_exit: 430unlock_disconnect_exit:
430 up (&disconnect_sem); 431 mutex_unlock (&disconnect_mutex);
431 432
432 dbg(2, "%s: leave, return value %d ", __FUNCTION__, retval); 433 dbg(2, "%s: leave, return value %d ", __FUNCTION__, retval);
433 434
@@ -1005,7 +1006,7 @@ static void tower_disconnect (struct usb_interface *interface)
1005 1006
1006 dbg(2, "%s: enter", __FUNCTION__); 1007 dbg(2, "%s: enter", __FUNCTION__);
1007 1008
1008 down (&disconnect_sem); 1009 mutex_lock (&disconnect_mutex);
1009 1010
1010 dev = usb_get_intfdata (interface); 1011 dev = usb_get_intfdata (interface);
1011 usb_set_intfdata (interface, NULL); 1012 usb_set_intfdata (interface, NULL);
@@ -1027,7 +1028,7 @@ static void tower_disconnect (struct usb_interface *interface)
1027 up (&dev->sem); 1028 up (&dev->sem);
1028 } 1029 }
1029 1030
1030 up (&disconnect_sem); 1031 mutex_unlock (&disconnect_mutex);
1031 1032
1032 info("LEGO USB Tower #%d now disconnected", (minor - LEGO_USB_TOWER_MINOR_BASE)); 1033 info("LEGO USB Tower #%d now disconnected", (minor - LEGO_USB_TOWER_MINOR_BASE));
1033 1034
diff --git a/drivers/usb/misc/phidgetkit.c b/drivers/usb/misc/phidgetkit.c
index 605a3c87e05c..997db5d8e35b 100644
--- a/drivers/usb/misc/phidgetkit.c
+++ b/drivers/usb/misc/phidgetkit.c
@@ -88,7 +88,7 @@ static int change_outputs(struct phidget_interfacekit *kit, int output_num, int
88 int retval; 88 int retval;
89 int n; 89 int n;
90 90
91 buffer = kmalloc(4, GFP_KERNEL); 91 buffer = kzalloc(4, GFP_KERNEL);
92 if (!buffer) { 92 if (!buffer) {
93 dev_err(&kit->udev->dev, "%s - out of memory\n", 93 dev_err(&kit->udev->dev, "%s - out of memory\n",
94 __FUNCTION__); 94 __FUNCTION__);
@@ -96,7 +96,6 @@ static int change_outputs(struct phidget_interfacekit *kit, int output_num, int
96 } 96 }
97 97
98 kit->outputs[output_num] = enable; 98 kit->outputs[output_num] = enable;
99 memset(buffer, 0, 4);
100 for (n=0; n<8; n++) { 99 for (n=0; n<8; n++) {
101 if (kit->outputs[n]) { 100 if (kit->outputs[n]) {
102 buffer[0] |= 1 << n; 101 buffer[0] |= 1 << n;
@@ -192,7 +191,7 @@ static ssize_t set_backlight(struct device *dev, struct device_attribute *attr,
192 unsigned char *buffer; 191 unsigned char *buffer;
193 int retval = -ENOMEM; 192 int retval = -ENOMEM;
194 193
195 buffer = kmalloc(8, GFP_KERNEL); 194 buffer = kzalloc(8, GFP_KERNEL);
196 if (!buffer) { 195 if (!buffer) {
197 dev_err(&kit->udev->dev, "%s - out of memory\n", __FUNCTION__); 196 dev_err(&kit->udev->dev, "%s - out of memory\n", __FUNCTION__);
198 goto exit; 197 goto exit;
@@ -202,7 +201,6 @@ static ssize_t set_backlight(struct device *dev, struct device_attribute *attr,
202 retval = -EINVAL; 201 retval = -EINVAL;
203 goto exit; 202 goto exit;
204 } 203 }
205 memset(buffer, 0x00, 8);
206 if (enabled) 204 if (enabled)
207 buffer[0] = 0x01; 205 buffer[0] = 0x01;
208 buffer[7] = 0x11; 206 buffer[7] = 0x11;
@@ -406,12 +404,11 @@ static int interfacekit_probe(struct usb_interface *intf, const struct usb_devic
406 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); 404 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
407 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); 405 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
408 406
409 kit = kmalloc(sizeof(*kit), GFP_KERNEL); 407 kit = kzalloc(sizeof(*kit), GFP_KERNEL);
410 if (kit == NULL) { 408 if (kit == NULL) {
411 dev_err(&intf->dev, "%s - out of memory\n", __FUNCTION__); 409 dev_err(&intf->dev, "%s - out of memory\n", __FUNCTION__);
412 return -ENOMEM; 410 return -ENOMEM;
413 } 411 }
414 memset(kit, 0, sizeof(*kit));
415 kit->ifkit = ifkit; 412 kit->ifkit = ifkit;
416 413
417 kit->data = usb_buffer_alloc(dev, 8, SLAB_ATOMIC, &kit->data_dma); 414 kit->data = usb_buffer_alloc(dev, 8, SLAB_ATOMIC, &kit->data_dma);
diff --git a/drivers/usb/misc/phidgetservo.c b/drivers/usb/misc/phidgetservo.c
index b3418d2bcc69..5a040c205eed 100644
--- a/drivers/usb/misc/phidgetservo.c
+++ b/drivers/usb/misc/phidgetservo.c
@@ -252,12 +252,11 @@ servo_probe(struct usb_interface *interface, const struct usb_device_id *id)
252 struct usb_device *udev = interface_to_usbdev(interface); 252 struct usb_device *udev = interface_to_usbdev(interface);
253 struct phidget_servo *dev; 253 struct phidget_servo *dev;
254 254
255 dev = kmalloc(sizeof (struct phidget_servo), GFP_KERNEL); 255 dev = kzalloc(sizeof (struct phidget_servo), GFP_KERNEL);
256 if (dev == NULL) { 256 if (dev == NULL) {
257 dev_err(&interface->dev, "%s - out of memory\n", __FUNCTION__); 257 dev_err(&interface->dev, "%s - out of memory\n", __FUNCTION__);
258 return -ENOMEM; 258 return -ENOMEM;
259 } 259 }
260 memset(dev, 0x00, sizeof (*dev));
261 260
262 dev->udev = usb_get_dev(udev); 261 dev->udev = usb_get_dev(udev);
263 dev->type = id->driver_info; 262 dev->type = id->driver_info;
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index 3260d595441f..196c8794a73c 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -3188,7 +3188,7 @@ sisusb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
3188 break; 3188 break;
3189 3189
3190 default: 3190 default:
3191 retval = -EINVAL; 3191 retval = -ENOTTY;
3192 break; 3192 break;
3193 } 3193 }
3194 3194
@@ -3251,12 +3251,11 @@ static int sisusb_probe(struct usb_interface *intf,
3251 dev->devnum); 3251 dev->devnum);
3252 3252
3253 /* Allocate memory for our private */ 3253 /* Allocate memory for our private */
3254 if (!(sisusb = kmalloc(sizeof(*sisusb), GFP_KERNEL))) { 3254 if (!(sisusb = kzalloc(sizeof(*sisusb), GFP_KERNEL))) {
3255 printk(KERN_ERR 3255 printk(KERN_ERR
3256 "sisusb: Failed to allocate memory for private data\n"); 3256 "sisusb: Failed to allocate memory for private data\n");
3257 return -ENOMEM; 3257 return -ENOMEM;
3258 } 3258 }
3259 memset(sisusb, 0, sizeof(*sisusb));
3260 kref_init(&sisusb->kref); 3259 kref_init(&sisusb->kref);
3261 3260
3262 init_MUTEX(&(sisusb->lock)); 3261 init_MUTEX(&(sisusb->lock));
diff --git a/drivers/usb/misc/sisusbvga/sisusb.h b/drivers/usb/misc/sisusbvga/sisusb.h
index 1d7a77cc7c4a..a716825d1f9b 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.h
+++ b/drivers/usb/misc/sisusbvga/sisusb.h
@@ -37,24 +37,16 @@
37#ifndef _SISUSB_H_ 37#ifndef _SISUSB_H_
38#define _SISUSB_H_ 38#define _SISUSB_H_
39 39
40#include <linux/version.h>
41#ifdef CONFIG_COMPAT 40#ifdef CONFIG_COMPAT
42#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,10)
43#include <linux/ioctl32.h>
44#define SISUSB_OLD_CONFIG_COMPAT
45#else
46#define SISUSB_NEW_CONFIG_COMPAT 41#define SISUSB_NEW_CONFIG_COMPAT
47#endif 42#endif
48#endif
49 43
50/* For older kernels, support for text consoles is by default 44/* For older kernels, support for text consoles is by default
51 * off. To ensable text console support, change the following: 45 * off. To ensable text console support, change the following:
52 */ 46 */
53#if 0 47#if 0
54#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,13)
55#define CONFIG_USB_SISUSBVGA_CON 48#define CONFIG_USB_SISUSBVGA_CON
56#endif 49#endif
57#endif
58 50
59/* Version Information */ 51/* Version Information */
60 52
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
index cc3dae3f34e0..c82c402285a0 100644
--- a/drivers/usb/misc/usblcd.c
+++ b/drivers/usb/misc/usblcd.c
@@ -270,12 +270,11 @@ static int lcd_probe(struct usb_interface *interface, const struct usb_device_id
270 int retval = -ENOMEM; 270 int retval = -ENOMEM;
271 271
272 /* allocate memory for our device state and initialize it */ 272 /* allocate memory for our device state and initialize it */
273 dev = kmalloc(sizeof(*dev), GFP_KERNEL); 273 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
274 if (dev == NULL) { 274 if (dev == NULL) {
275 err("Out of memory"); 275 err("Out of memory");
276 goto error; 276 goto error;
277 } 277 }
278 memset(dev, 0x00, sizeof(*dev));
279 kref_init(&dev->kref); 278 kref_init(&dev->kref);
280 279
281 dev->udev = usb_get_dev(interface_to_usbdev(interface)); 280 dev->udev = usb_get_dev(interface_to_usbdev(interface));
diff --git a/drivers/usb/misc/usbled.c b/drivers/usb/misc/usbled.c
index 877b081a3a6e..f441964132c0 100644
--- a/drivers/usb/misc/usbled.c
+++ b/drivers/usb/misc/usbled.c
@@ -106,12 +106,11 @@ static int led_probe(struct usb_interface *interface, const struct usb_device_id
106 struct usb_led *dev = NULL; 106 struct usb_led *dev = NULL;
107 int retval = -ENOMEM; 107 int retval = -ENOMEM;
108 108
109 dev = kmalloc(sizeof(struct usb_led), GFP_KERNEL); 109 dev = kzalloc(sizeof(struct usb_led), GFP_KERNEL);
110 if (dev == NULL) { 110 if (dev == NULL) {
111 dev_err(&interface->dev, "Out of memory\n"); 111 dev_err(&interface->dev, "Out of memory\n");
112 goto error; 112 goto error;
113 } 113 }
114 memset (dev, 0x00, sizeof (*dev));
115 114
116 dev->udev = usb_get_dev(udev); 115 dev->udev = usb_get_dev(udev);
117 116
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 84fa1728f052..9d59b901841c 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -382,12 +382,11 @@ alloc_sglist (int nents, int max, int vary)
382 for (i = 0; i < nents; i++) { 382 for (i = 0; i < nents; i++) {
383 char *buf; 383 char *buf;
384 384
385 buf = kmalloc (size, SLAB_KERNEL); 385 buf = kzalloc (size, SLAB_KERNEL);
386 if (!buf) { 386 if (!buf) {
387 free_sglist (sg, i); 387 free_sglist (sg, i);
388 return NULL; 388 return NULL;
389 } 389 }
390 memset (buf, 0, size);
391 390
392 /* kmalloc pages are always physically contiguous! */ 391 /* kmalloc pages are always physically contiguous! */
393 sg_init_one(&sg[i], buf, size); 392 sg_init_one(&sg[i], buf, size);
@@ -842,10 +841,9 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
842 * as with bulk/intr sglists, sglen is the queue depth; it also 841 * as with bulk/intr sglists, sglen is the queue depth; it also
843 * controls which subtests run (more tests than sglen) or rerun. 842 * controls which subtests run (more tests than sglen) or rerun.
844 */ 843 */
845 urb = kmalloc (param->sglen * sizeof (struct urb *), SLAB_KERNEL); 844 urb = kcalloc(param->sglen, sizeof(struct urb *), SLAB_KERNEL);
846 if (!urb) 845 if (!urb)
847 return -ENOMEM; 846 return -ENOMEM;
848 memset (urb, 0, param->sglen * sizeof (struct urb *));
849 for (i = 0; i < param->sglen; i++) { 847 for (i = 0; i < param->sglen; i++) {
850 int pipe = usb_rcvctrlpipe (udev, 0); 848 int pipe = usb_rcvctrlpipe (udev, 0);
851 unsigned len; 849 unsigned len;
@@ -1865,10 +1863,9 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1865 } 1863 }
1866#endif 1864#endif
1867 1865
1868 dev = kmalloc (sizeof *dev, SLAB_KERNEL); 1866 dev = kzalloc(sizeof(*dev), SLAB_KERNEL);
1869 if (!dev) 1867 if (!dev)
1870 return -ENOMEM; 1868 return -ENOMEM;
1871 memset (dev, 0, sizeof *dev);
1872 info = (struct usbtest_info *) id->driver_info; 1869 info = (struct usbtest_info *) id->driver_info;
1873 dev->info = info; 1870 dev->info = info;
1874 init_MUTEX (&dev->sem); 1871 init_MUTEX (&dev->sem);
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
index c34944c75047..6ecc27302211 100644
--- a/drivers/usb/mon/mon_main.c
+++ b/drivers/usb/mon/mon_main.c
@@ -12,6 +12,7 @@
12#include <linux/debugfs.h> 12#include <linux/debugfs.h>
13#include <linux/smp_lock.h> 13#include <linux/smp_lock.h>
14#include <linux/notifier.h> 14#include <linux/notifier.h>
15#include <linux/mutex.h>
15 16
16#include "usb_mon.h" 17#include "usb_mon.h"
17#include "../core/hcd.h" 18#include "../core/hcd.h"
@@ -23,7 +24,7 @@ static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus);
23static void mon_bus_drop(struct kref *r); 24static void mon_bus_drop(struct kref *r);
24static void mon_bus_init(struct dentry *mondir, struct usb_bus *ubus); 25static void mon_bus_init(struct dentry *mondir, struct usb_bus *ubus);
25 26
26DECLARE_MUTEX(mon_lock); 27DEFINE_MUTEX(mon_lock);
27 28
28static struct dentry *mon_dir; /* /dbg/usbmon */ 29static struct dentry *mon_dir; /* /dbg/usbmon */
29static LIST_HEAD(mon_buses); /* All buses we know: struct mon_bus */ 30static LIST_HEAD(mon_buses); /* All buses we know: struct mon_bus */
@@ -196,14 +197,14 @@ static void mon_bus_remove(struct usb_bus *ubus)
196{ 197{
197 struct mon_bus *mbus = ubus->mon_bus; 198 struct mon_bus *mbus = ubus->mon_bus;
198 199
199 down(&mon_lock); 200 mutex_lock(&mon_lock);
200 list_del(&mbus->bus_link); 201 list_del(&mbus->bus_link);
201 debugfs_remove(mbus->dent_t); 202 debugfs_remove(mbus->dent_t);
202 debugfs_remove(mbus->dent_s); 203 debugfs_remove(mbus->dent_s);
203 204
204 mon_dissolve(mbus, ubus); 205 mon_dissolve(mbus, ubus);
205 kref_put(&mbus->ref, mon_bus_drop); 206 kref_put(&mbus->ref, mon_bus_drop);
206 up(&mon_lock); 207 mutex_unlock(&mon_lock);
207} 208}
208 209
209static int mon_notify(struct notifier_block *self, unsigned long action, 210static int mon_notify(struct notifier_block *self, unsigned long action,
@@ -276,9 +277,8 @@ static void mon_bus_init(struct dentry *mondir, struct usb_bus *ubus)
276 char name[NAMESZ]; 277 char name[NAMESZ];
277 int rc; 278 int rc;
278 279
279 if ((mbus = kmalloc(sizeof(struct mon_bus), GFP_KERNEL)) == NULL) 280 if ((mbus = kzalloc(sizeof(struct mon_bus), GFP_KERNEL)) == NULL)
280 goto err_alloc; 281 goto err_alloc;
281 memset(mbus, 0, sizeof(struct mon_bus));
282 kref_init(&mbus->ref); 282 kref_init(&mbus->ref);
283 spin_lock_init(&mbus->lock); 283 spin_lock_init(&mbus->lock);
284 INIT_LIST_HEAD(&mbus->r_list); 284 INIT_LIST_HEAD(&mbus->r_list);
@@ -307,9 +307,9 @@ static void mon_bus_init(struct dentry *mondir, struct usb_bus *ubus)
307 goto err_create_s; 307 goto err_create_s;
308 mbus->dent_s = d; 308 mbus->dent_s = d;
309 309
310 down(&mon_lock); 310 mutex_lock(&mon_lock);
311 list_add_tail(&mbus->bus_link, &mon_buses); 311 list_add_tail(&mbus->bus_link, &mon_buses);
312 up(&mon_lock); 312 mutex_unlock(&mon_lock);
313 return; 313 return;
314 314
315err_create_s: 315err_create_s:
@@ -347,11 +347,11 @@ static int __init mon_init(void)
347 347
348 usb_register_notify(&mon_nb); 348 usb_register_notify(&mon_nb);
349 349
350 down(&usb_bus_list_lock); 350 mutex_lock(&usb_bus_list_lock);
351 list_for_each_entry (ubus, &usb_bus_list, bus_list) { 351 list_for_each_entry (ubus, &usb_bus_list, bus_list) {
352 mon_bus_init(mondir, ubus); 352 mon_bus_init(mondir, ubus);
353 } 353 }
354 up(&usb_bus_list_lock); 354 mutex_unlock(&usb_bus_list_lock);
355 return 0; 355 return 0;
356} 356}
357 357
@@ -363,7 +363,7 @@ static void __exit mon_exit(void)
363 usb_unregister_notify(&mon_nb); 363 usb_unregister_notify(&mon_nb);
364 usb_mon_deregister(); 364 usb_mon_deregister();
365 365
366 down(&mon_lock); 366 mutex_lock(&mon_lock);
367 while (!list_empty(&mon_buses)) { 367 while (!list_empty(&mon_buses)) {
368 p = mon_buses.next; 368 p = mon_buses.next;
369 mbus = list_entry(p, struct mon_bus, bus_link); 369 mbus = list_entry(p, struct mon_bus, bus_link);
@@ -387,7 +387,7 @@ static void __exit mon_exit(void)
387 mon_dissolve(mbus, mbus->u_bus); 387 mon_dissolve(mbus, mbus->u_bus);
388 kref_put(&mbus->ref, mon_bus_drop); 388 kref_put(&mbus->ref, mon_bus_drop);
389 } 389 }
390 up(&mon_lock); 390 mutex_unlock(&mon_lock);
391 391
392 debugfs_remove(mon_dir); 392 debugfs_remove(mon_dir);
393} 393}
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index 611612146ae9..ac043ec2b8dc 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -8,6 +8,7 @@
8#include <linux/list.h> 8#include <linux/list.h>
9#include <linux/usb.h> 9#include <linux/usb.h>
10#include <linux/time.h> 10#include <linux/time.h>
11#include <linux/mutex.h>
11#include <asm/uaccess.h> 12#include <asm/uaccess.h>
12 13
13#include "usb_mon.h" 14#include "usb_mon.h"
@@ -54,7 +55,7 @@ struct mon_reader_text {
54 wait_queue_head_t wait; 55 wait_queue_head_t wait;
55 int printf_size; 56 int printf_size;
56 char *printf_buf; 57 char *printf_buf;
57 struct semaphore printf_lock; 58 struct mutex printf_lock;
58 59
59 char slab_name[SLAB_NAME_SZ]; 60 char slab_name[SLAB_NAME_SZ];
60}; 61};
@@ -208,19 +209,18 @@ static int mon_text_open(struct inode *inode, struct file *file)
208 struct mon_reader_text *rp; 209 struct mon_reader_text *rp;
209 int rc; 210 int rc;
210 211
211 down(&mon_lock); 212 mutex_lock(&mon_lock);
212 mbus = inode->u.generic_ip; 213 mbus = inode->u.generic_ip;
213 ubus = mbus->u_bus; 214 ubus = mbus->u_bus;
214 215
215 rp = kmalloc(sizeof(struct mon_reader_text), GFP_KERNEL); 216 rp = kzalloc(sizeof(struct mon_reader_text), GFP_KERNEL);
216 if (rp == NULL) { 217 if (rp == NULL) {
217 rc = -ENOMEM; 218 rc = -ENOMEM;
218 goto err_alloc; 219 goto err_alloc;
219 } 220 }
220 memset(rp, 0, sizeof(struct mon_reader_text));
221 INIT_LIST_HEAD(&rp->e_list); 221 INIT_LIST_HEAD(&rp->e_list);
222 init_waitqueue_head(&rp->wait); 222 init_waitqueue_head(&rp->wait);
223 init_MUTEX(&rp->printf_lock); 223 mutex_init(&rp->printf_lock);
224 224
225 rp->printf_size = PRINTF_DFL; 225 rp->printf_size = PRINTF_DFL;
226 rp->printf_buf = kmalloc(rp->printf_size, GFP_KERNEL); 226 rp->printf_buf = kmalloc(rp->printf_size, GFP_KERNEL);
@@ -247,7 +247,7 @@ static int mon_text_open(struct inode *inode, struct file *file)
247 mon_reader_add(mbus, &rp->r); 247 mon_reader_add(mbus, &rp->r);
248 248
249 file->private_data = rp; 249 file->private_data = rp;
250 up(&mon_lock); 250 mutex_unlock(&mon_lock);
251 return 0; 251 return 0;
252 252
253// err_busy: 253// err_busy:
@@ -257,7 +257,7 @@ err_slab:
257err_alloc_pr: 257err_alloc_pr:
258 kfree(rp); 258 kfree(rp);
259err_alloc: 259err_alloc:
260 up(&mon_lock); 260 mutex_unlock(&mon_lock);
261 return rc; 261 return rc;
262} 262}
263 263
@@ -301,7 +301,7 @@ static ssize_t mon_text_read(struct file *file, char __user *buf,
301 set_current_state(TASK_RUNNING); 301 set_current_state(TASK_RUNNING);
302 remove_wait_queue(&rp->wait, &waita); 302 remove_wait_queue(&rp->wait, &waita);
303 303
304 down(&rp->printf_lock); 304 mutex_lock(&rp->printf_lock);
305 cnt = 0; 305 cnt = 0;
306 pbuf = rp->printf_buf; 306 pbuf = rp->printf_buf;
307 limit = rp->printf_size; 307 limit = rp->printf_size;
@@ -358,7 +358,7 @@ static ssize_t mon_text_read(struct file *file, char __user *buf,
358 358
359 if (copy_to_user(buf, rp->printf_buf, cnt)) 359 if (copy_to_user(buf, rp->printf_buf, cnt))
360 cnt = -EFAULT; 360 cnt = -EFAULT;
361 up(&rp->printf_lock); 361 mutex_unlock(&rp->printf_lock);
362 kmem_cache_free(rp->e_slab, ep); 362 kmem_cache_free(rp->e_slab, ep);
363 return cnt; 363 return cnt;
364} 364}
@@ -371,12 +371,12 @@ static int mon_text_release(struct inode *inode, struct file *file)
371 struct list_head *p; 371 struct list_head *p;
372 struct mon_event_text *ep; 372 struct mon_event_text *ep;
373 373
374 down(&mon_lock); 374 mutex_lock(&mon_lock);
375 mbus = inode->u.generic_ip; 375 mbus = inode->u.generic_ip;
376 376
377 if (mbus->nreaders <= 0) { 377 if (mbus->nreaders <= 0) {
378 printk(KERN_ERR TAG ": consistency error on close\n"); 378 printk(KERN_ERR TAG ": consistency error on close\n");
379 up(&mon_lock); 379 mutex_unlock(&mon_lock);
380 return 0; 380 return 0;
381 } 381 }
382 mon_reader_del(mbus, &rp->r); 382 mon_reader_del(mbus, &rp->r);
@@ -402,7 +402,7 @@ static int mon_text_release(struct inode *inode, struct file *file)
402 kfree(rp->printf_buf); 402 kfree(rp->printf_buf);
403 kfree(rp); 403 kfree(rp);
404 404
405 up(&mon_lock); 405 mutex_unlock(&mon_lock);
406 return 0; 406 return 0;
407} 407}
408 408
diff --git a/drivers/usb/mon/usb_mon.h b/drivers/usb/mon/usb_mon.h
index 4be0f9346071..8e0613c350cc 100644
--- a/drivers/usb/mon/usb_mon.h
+++ b/drivers/usb/mon/usb_mon.h
@@ -49,7 +49,7 @@ void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r);
49 */ 49 */
50extern char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len); 50extern char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len);
51 51
52extern struct semaphore mon_lock; 52extern struct mutex mon_lock;
53 53
54extern struct file_operations mon_fops_text; 54extern struct file_operations mon_fops_text;
55extern struct file_operations mon_fops_stat; 55extern struct file_operations mon_fops_stat;
diff --git a/drivers/usb/net/pegasus.c b/drivers/usb/net/pegasus.c
index 156a2f1cb39a..5b6675684567 100644
--- a/drivers/usb/net/pegasus.c
+++ b/drivers/usb/net/pegasus.c
@@ -524,6 +524,7 @@ static int enable_net_traffic(struct net_device *dev, struct usb_device *usb)
524 ret = set_registers(pegasus, EthCtrl0, 3, data); 524 ret = set_registers(pegasus, EthCtrl0, 3, data);
525 525
526 if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS || 526 if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
527 usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS2 ||
527 usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) { 528 usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
528 u16 auxmode; 529 u16 auxmode;
529 read_mii_word(pegasus, 0, 0x1b, &auxmode); 530 read_mii_word(pegasus, 0, 0x1b, &auxmode);
diff --git a/drivers/usb/net/pegasus.h b/drivers/usb/net/pegasus.h
index 9fbd59b55cb6..a54752ce1493 100644
--- a/drivers/usb/net/pegasus.h
+++ b/drivers/usb/net/pegasus.h
@@ -25,7 +25,6 @@
25#define PHY_READ 0x40 25#define PHY_READ 0x40
26#define PHY_WRITE 0x20 26#define PHY_WRITE 0x20
27#define DEFAULT_GPIO_RESET 0x24 27#define DEFAULT_GPIO_RESET 0x24
28#define LINKSYS_GPIO_RESET 0x24
29#define DEFAULT_GPIO_SET 0x26 28#define DEFAULT_GPIO_SET 0x26
30 29
31#define PEGASUS_PRESENT 0x00000001 30#define PEGASUS_PRESENT 0x00000001
@@ -140,6 +139,7 @@ struct usb_eth_dev {
140#define VENDOR_KINGSTON 0x0951 139#define VENDOR_KINGSTON 0x0951
141#define VENDOR_LANEED 0x056e 140#define VENDOR_LANEED 0x056e
142#define VENDOR_LINKSYS 0x066b 141#define VENDOR_LINKSYS 0x066b
142#define VENDOR_LINKSYS2 0x077b
143#define VENDOR_MELCO 0x0411 143#define VENDOR_MELCO 0x0411
144#define VENDOR_MICROSOFT 0x045e 144#define VENDOR_MICROSOFT 0x045e
145#define VENDOR_MOBILITY 0x1342 145#define VENDOR_MOBILITY 0x1342
@@ -218,15 +218,15 @@ PEGASUS_DEV( "Corega FEter USB-TX", VENDOR_COREGA, 0x0004,
218PEGASUS_DEV( "Corega FEter USB-TXS", VENDOR_COREGA, 0x000d, 218PEGASUS_DEV( "Corega FEter USB-TXS", VENDOR_COREGA, 0x000d,
219 DEFAULT_GPIO_RESET | PEGASUS_II ) 219 DEFAULT_GPIO_RESET | PEGASUS_II )
220PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x4001, 220PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x4001,
221 LINKSYS_GPIO_RESET ) 221 DEFAULT_GPIO_RESET )
222PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x4002, 222PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x4002,
223 LINKSYS_GPIO_RESET ) 223 DEFAULT_GPIO_RESET )
224PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x4102, 224PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x4102,
225 LINKSYS_GPIO_RESET | PEGASUS_II ) 225 DEFAULT_GPIO_RESET | PEGASUS_II )
226PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x400b, 226PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x400b,
227 LINKSYS_GPIO_RESET | PEGASUS_II ) 227 DEFAULT_GPIO_RESET | PEGASUS_II )
228PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x200c, 228PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x200c,
229 LINKSYS_GPIO_RESET | PEGASUS_II ) 229 DEFAULT_GPIO_RESET | PEGASUS_II )
230PEGASUS_DEV( "D-Link DSB-650TX(PNA)", VENDOR_DLINK, 0x4003, 230PEGASUS_DEV( "D-Link DSB-650TX(PNA)", VENDOR_DLINK, 0x4003,
231 DEFAULT_GPIO_RESET | HAS_HOME_PNA ) 231 DEFAULT_GPIO_RESET | HAS_HOME_PNA )
232PEGASUS_DEV( "D-Link DSB-650", VENDOR_DLINK, 0xabc1, 232PEGASUS_DEV( "D-Link DSB-650", VENDOR_DLINK, 0xabc1,
@@ -260,17 +260,19 @@ PEGASUS_DEV( "LANEED USB Ethernet LD-USB/T", VENDOR_LANEED, 0xabc1,
260PEGASUS_DEV( "LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x200c, 260PEGASUS_DEV( "LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x200c,
261 DEFAULT_GPIO_RESET | PEGASUS_II ) 261 DEFAULT_GPIO_RESET | PEGASUS_II )
262PEGASUS_DEV( "Linksys USB10TX", VENDOR_LINKSYS, 0x2202, 262PEGASUS_DEV( "Linksys USB10TX", VENDOR_LINKSYS, 0x2202,
263 LINKSYS_GPIO_RESET ) 263 DEFAULT_GPIO_RESET )
264PEGASUS_DEV( "Linksys USB100TX", VENDOR_LINKSYS, 0x2203, 264PEGASUS_DEV( "Linksys USB100TX", VENDOR_LINKSYS, 0x2203,
265 LINKSYS_GPIO_RESET ) 265 DEFAULT_GPIO_RESET )
266PEGASUS_DEV( "Linksys USB100TX", VENDOR_LINKSYS, 0x2204, 266PEGASUS_DEV( "Linksys USB100TX", VENDOR_LINKSYS, 0x2204,
267 LINKSYS_GPIO_RESET | HAS_HOME_PNA ) 267 DEFAULT_GPIO_RESET | HAS_HOME_PNA )
268PEGASUS_DEV( "Linksys USB10T Ethernet Adapter", VENDOR_LINKSYS, 0x2206, 268PEGASUS_DEV( "Linksys USB10T Ethernet Adapter", VENDOR_LINKSYS, 0x2206,
269 LINKSYS_GPIO_RESET | PEGASUS_II) 269 DEFAULT_GPIO_RESET | PEGASUS_II)
270PEGASUS_DEV( "Linksys USBVPN1", VENDOR_LINKSYS2, 0x08b4,
271 DEFAULT_GPIO_RESET )
270PEGASUS_DEV( "Linksys USB USB100TX", VENDOR_LINKSYS, 0x400b, 272PEGASUS_DEV( "Linksys USB USB100TX", VENDOR_LINKSYS, 0x400b,
271 LINKSYS_GPIO_RESET | PEGASUS_II ) 273 DEFAULT_GPIO_RESET | PEGASUS_II )
272PEGASUS_DEV( "Linksys USB10TX", VENDOR_LINKSYS, 0x200c, 274PEGASUS_DEV( "Linksys USB10TX", VENDOR_LINKSYS, 0x200c,
273 LINKSYS_GPIO_RESET | PEGASUS_II ) 275 DEFAULT_GPIO_RESET | PEGASUS_II )
274PEGASUS_DEV( "MELCO/BUFFALO LUA-TX", VENDOR_MELCO, 0x0001, 276PEGASUS_DEV( "MELCO/BUFFALO LUA-TX", VENDOR_MELCO, 0x0001,
275 DEFAULT_GPIO_RESET ) 277 DEFAULT_GPIO_RESET )
276PEGASUS_DEV( "MELCO/BUFFALO LUA-TX", VENDOR_MELCO, 0x0005, 278PEGASUS_DEV( "MELCO/BUFFALO LUA-TX", VENDOR_MELCO, 0x0005,
diff --git a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c
index 8ca52be23976..1bbbae283c0b 100644
--- a/drivers/usb/net/rtl8150.c
+++ b/drivers/usb/net/rtl8150.c
@@ -880,7 +880,6 @@ static int rtl8150_probe(struct usb_interface *intf,
880 } 880 }
881 fill_skb_pool(dev); 881 fill_skb_pool(dev);
882 set_ethernet_addr(dev); 882 set_ethernet_addr(dev);
883 info("%s: rtl8150 is detected", netdev->name);
884 883
885 usb_set_intfdata(intf, dev); 884 usb_set_intfdata(intf, dev);
886 SET_NETDEV_DEV(netdev, &intf->dev); 885 SET_NETDEV_DEV(netdev, &intf->dev);
@@ -888,6 +887,9 @@ static int rtl8150_probe(struct usb_interface *intf,
888 err("couldn't register the device"); 887 err("couldn't register the device");
889 goto out2; 888 goto out2;
890 } 889 }
890
891 info("%s: rtl8150 is detected", netdev->name);
892
891 return 0; 893 return 0;
892 894
893out2: 895out2:
diff --git a/drivers/usb/net/zd1201.c b/drivers/usb/net/zd1201.c
index f3a8e2807c3b..fe9b60cd8d95 100644
--- a/drivers/usb/net/zd1201.c
+++ b/drivers/usb/net/zd1201.c
@@ -621,10 +621,9 @@ static int zd1201_drvr_start(struct zd1201 *zd)
621 __le16 zdmax; 621 __le16 zdmax;
622 unsigned char *buffer; 622 unsigned char *buffer;
623 623
624 buffer = kmalloc(ZD1201_RXSIZE, GFP_KERNEL); 624 buffer = kzalloc(ZD1201_RXSIZE, GFP_KERNEL);
625 if (!buffer) 625 if (!buffer)
626 return -ENOMEM; 626 return -ENOMEM;
627 memset(buffer, 0, ZD1201_RXSIZE);
628 627
629 usb_fill_bulk_urb(zd->rx_urb, zd->usb, 628 usb_fill_bulk_urb(zd->rx_urb, zd->usb,
630 usb_rcvbulkpipe(zd->usb, zd->endp_in), buffer, ZD1201_RXSIZE, 629 usb_rcvbulkpipe(zd->usb, zd->endp_in), buffer, ZD1201_RXSIZE,
@@ -1750,11 +1749,9 @@ static int zd1201_probe(struct usb_interface *interface,
1750 1749
1751 usb = interface_to_usbdev(interface); 1750 usb = interface_to_usbdev(interface);
1752 1751
1753 zd = kmalloc(sizeof(struct zd1201), GFP_KERNEL); 1752 zd = kzalloc(sizeof(struct zd1201), GFP_KERNEL);
1754 if (!zd) { 1753 if (!zd)
1755 return -ENOMEM; 1754 return -ENOMEM;
1756 }
1757 memset(zd, 0, sizeof(struct zd1201));
1758 zd->ap = ap; 1755 zd->ap = ap;
1759 zd->usb = usb; 1756 zd->usb = usb;
1760 zd->removed = 0; 1757 zd->removed = 0;
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index be5dc80836c3..5a8a2c91c2b2 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -403,6 +403,13 @@ config USB_SERIAL_MCT_U232
403 To compile this driver as a module, choose M here: the 403 To compile this driver as a module, choose M here: the
404 module will be called mct_u232. 404 module will be called mct_u232.
405 405
406config USB_SERIAL_NAVMAN
407 tristate "USB Navman GPS device"
408 depends on USB_SERIAL
409 help
410 To compile this driver as a module, choose M here: the
411 module will be called navman.
412
406config USB_SERIAL_PL2303 413config USB_SERIAL_PL2303
407 tristate "USB Prolific 2303 Single Port Serial Driver" 414 tristate "USB Prolific 2303 Single Port Serial Driver"
408 depends on USB_SERIAL 415 depends on USB_SERIAL
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index f0b04420cea1..f7fe4172efed 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -32,6 +32,7 @@ obj-$(CONFIG_USB_SERIAL_KEYSPAN_PDA) += keyspan_pda.o
32obj-$(CONFIG_USB_SERIAL_KLSI) += kl5kusb105.o 32obj-$(CONFIG_USB_SERIAL_KLSI) += kl5kusb105.o
33obj-$(CONFIG_USB_SERIAL_KOBIL_SCT) += kobil_sct.o 33obj-$(CONFIG_USB_SERIAL_KOBIL_SCT) += kobil_sct.o
34obj-$(CONFIG_USB_SERIAL_MCT_U232) += mct_u232.o 34obj-$(CONFIG_USB_SERIAL_MCT_U232) += mct_u232.o
35obj-$(CONFIG_USB_SERIAL_NAVMAN) += navman.o
35obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o 36obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o
36obj-$(CONFIG_USB_SERIAL_OPTION) += option.o 37obj-$(CONFIG_USB_SERIAL_OPTION) += option.o
37obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o 38obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index dc7a069503e0..e0c2acdb3f06 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -32,7 +32,7 @@
32/* 32/*
33 * Version Information 33 * Version Information
34 */ 34 */
35#define DRIVER_VERSION "v0.06" 35#define DRIVER_VERSION "v0.07"
36#define DRIVER_DESC "Silicon Labs CP2101/CP2102 RS232 serial adaptor driver" 36#define DRIVER_DESC "Silicon Labs CP2101/CP2102 RS232 serial adaptor driver"
37 37
38/* 38/*
@@ -58,6 +58,7 @@ static struct usb_device_id id_table [] = {
58 { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */ 58 { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */
59 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ 59 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */
60 { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ 60 { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */
61 { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */
61 { USB_DEVICE(0x10C4, 0x807A) }, /* Crumb128 board */ 62 { USB_DEVICE(0x10C4, 0x807A) }, /* Crumb128 board */
62 { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */ 63 { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */
63 { USB_DEVICE(0x10C4, 0x80F6) }, /* Suunto sports instrument */ 64 { USB_DEVICE(0x10C4, 0x80F6) }, /* Suunto sports instrument */
@@ -169,9 +170,7 @@ static int cp2101_get_config(struct usb_serial_port* port, u8 request,
169 /* Number of integers required to contain the array */ 170 /* Number of integers required to contain the array */
170 length = (((size - 1) | 3) + 1)/4; 171 length = (((size - 1) | 3) + 1)/4;
171 172
172 buf = kmalloc (length * sizeof(u32), GFP_KERNEL); 173 buf = kcalloc(length, sizeof(u32), GFP_KERNEL);
173 memset(buf, 0, length * sizeof(u32));
174
175 if (!buf) { 174 if (!buf) {
176 dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__); 175 dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__);
177 return -ENOMEM; 176 return -ENOMEM;
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 68067fe117a4..7212fbe3b6f2 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -98,10 +98,16 @@ static struct usb_device_id id_table_cyphidcomrs232 [] = {
98 { } /* Terminating entry */ 98 { } /* Terminating entry */
99}; 99};
100 100
101static struct usb_device_id id_table_nokiaca42v2 [] = {
102 { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) },
103 { } /* Terminating entry */
104};
105
101static struct usb_device_id id_table_combined [] = { 106static struct usb_device_id id_table_combined [] = {
102 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) }, 107 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) },
103 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) }, 108 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) },
104 { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) }, 109 { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) },
110 { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) },
105 { } /* Terminating entry */ 111 { } /* Terminating entry */
106}; 112};
107 113
@@ -149,6 +155,7 @@ struct cypress_buf {
149/* function prototypes for the Cypress USB to serial device */ 155/* function prototypes for the Cypress USB to serial device */
150static int cypress_earthmate_startup (struct usb_serial *serial); 156static int cypress_earthmate_startup (struct usb_serial *serial);
151static int cypress_hidcom_startup (struct usb_serial *serial); 157static int cypress_hidcom_startup (struct usb_serial *serial);
158static int cypress_ca42v2_startup (struct usb_serial *serial);
152static void cypress_shutdown (struct usb_serial *serial); 159static void cypress_shutdown (struct usb_serial *serial);
153static int cypress_open (struct usb_serial_port *port, struct file *filp); 160static int cypress_open (struct usb_serial_port *port, struct file *filp);
154static void cypress_close (struct usb_serial_port *port, struct file *filp); 161static void cypress_close (struct usb_serial_port *port, struct file *filp);
@@ -235,6 +242,34 @@ static struct usb_serial_driver cypress_hidcom_device = {
235 .write_int_callback = cypress_write_int_callback, 242 .write_int_callback = cypress_write_int_callback,
236}; 243};
237 244
245static struct usb_serial_driver cypress_ca42v2_device = {
246 .driver = {
247 .owner = THIS_MODULE,
248 .name = "nokiaca42v2",
249 },
250 .description = "Nokia CA-42 V2 Adapter",
251 .id_table = id_table_nokiaca42v2,
252 .num_interrupt_in = 1,
253 .num_interrupt_out = 1,
254 .num_bulk_in = NUM_DONT_CARE,
255 .num_bulk_out = NUM_DONT_CARE,
256 .num_ports = 1,
257 .attach = cypress_ca42v2_startup,
258 .shutdown = cypress_shutdown,
259 .open = cypress_open,
260 .close = cypress_close,
261 .write = cypress_write,
262 .write_room = cypress_write_room,
263 .ioctl = cypress_ioctl,
264 .set_termios = cypress_set_termios,
265 .tiocmget = cypress_tiocmget,
266 .tiocmset = cypress_tiocmset,
267 .chars_in_buffer = cypress_chars_in_buffer,
268 .throttle = cypress_throttle,
269 .unthrottle = cypress_unthrottle,
270 .read_int_callback = cypress_read_int_callback,
271 .write_int_callback = cypress_write_int_callback,
272};
238 273
239/***************************************************************************** 274/*****************************************************************************
240 * Cypress serial helper functions 275 * Cypress serial helper functions
@@ -286,6 +321,12 @@ static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_m
286 __FUNCTION__); 321 __FUNCTION__);
287 new_baudrate = priv->baud_rate; 322 new_baudrate = priv->baud_rate;
288 } 323 }
324 } else if (priv->chiptype == CT_CA42V2) {
325 if ( (new_baudrate = mask_to_rate(baud_mask)) == -1) {
326 err("%s - failed setting baud rate, unsupported speed",
327 __FUNCTION__);
328 new_baudrate = priv->baud_rate;
329 }
289 } else if (priv->chiptype == CT_GENERIC) { 330 } else if (priv->chiptype == CT_GENERIC) {
290 if ( (new_baudrate = mask_to_rate(baud_mask)) == -1) { 331 if ( (new_baudrate = mask_to_rate(baud_mask)) == -1) {
291 err("%s - failed setting baud rate, unsupported speed", 332 err("%s - failed setting baud rate, unsupported speed",
@@ -435,11 +476,10 @@ static int generic_startup (struct usb_serial *serial)
435 476
436 dbg("%s - port %d", __FUNCTION__, serial->port[0]->number); 477 dbg("%s - port %d", __FUNCTION__, serial->port[0]->number);
437 478
438 priv = kmalloc(sizeof (struct cypress_private), GFP_KERNEL); 479 priv = kzalloc(sizeof (struct cypress_private), GFP_KERNEL);
439 if (!priv) 480 if (!priv)
440 return -ENOMEM; 481 return -ENOMEM;
441 482
442 memset(priv, 0x00, sizeof (struct cypress_private));
443 spin_lock_init(&priv->lock); 483 spin_lock_init(&priv->lock);
444 priv->buf = cypress_buf_alloc(CYPRESS_BUF_SIZE); 484 priv->buf = cypress_buf_alloc(CYPRESS_BUF_SIZE);
445 if (priv->buf == NULL) { 485 if (priv->buf == NULL) {
@@ -500,6 +540,25 @@ static int cypress_hidcom_startup (struct usb_serial *serial)
500} /* cypress_hidcom_startup */ 540} /* cypress_hidcom_startup */
501 541
502 542
543static int cypress_ca42v2_startup (struct usb_serial *serial)
544{
545 struct cypress_private *priv;
546
547 dbg("%s", __FUNCTION__);
548
549 if (generic_startup(serial)) {
550 dbg("%s - Failed setting up port %d", __FUNCTION__,
551 serial->port[0]->number);
552 return 1;
553 }
554
555 priv = usb_get_serial_port_data(serial->port[0]);
556 priv->chiptype = CT_CA42V2;
557
558 return 0;
559} /* cypress_ca42v2_startup */
560
561
503static void cypress_shutdown (struct usb_serial *serial) 562static void cypress_shutdown (struct usb_serial *serial)
504{ 563{
505 struct cypress_private *priv; 564 struct cypress_private *priv;
@@ -944,6 +1003,10 @@ static void cypress_set_termios (struct usb_serial_port *port,
944 *(tty->termios) = tty_std_termios; 1003 *(tty->termios) = tty_std_termios;
945 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | 1004 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL |
946 CLOCAL; 1005 CLOCAL;
1006 } else if (priv->chiptype == CT_CA42V2) {
1007 *(tty->termios) = tty_std_termios;
1008 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL |
1009 CLOCAL;
947 } 1010 }
948 priv->termios_initialized = 1; 1011 priv->termios_initialized = 1;
949 } 1012 }
@@ -1542,6 +1605,9 @@ static int __init cypress_init(void)
1542 retval = usb_serial_register(&cypress_hidcom_device); 1605 retval = usb_serial_register(&cypress_hidcom_device);
1543 if (retval) 1606 if (retval)
1544 goto failed_hidcom_register; 1607 goto failed_hidcom_register;
1608 retval = usb_serial_register(&cypress_ca42v2_device);
1609 if (retval)
1610 goto failed_ca42v2_register;
1545 retval = usb_register(&cypress_driver); 1611 retval = usb_register(&cypress_driver);
1546 if (retval) 1612 if (retval)
1547 goto failed_usb_register; 1613 goto failed_usb_register;
@@ -1550,6 +1616,8 @@ static int __init cypress_init(void)
1550 return 0; 1616 return 0;
1551failed_usb_register: 1617failed_usb_register:
1552 usb_deregister(&cypress_driver); 1618 usb_deregister(&cypress_driver);
1619failed_ca42v2_register:
1620 usb_serial_deregister(&cypress_ca42v2_device);
1553failed_hidcom_register: 1621failed_hidcom_register:
1554 usb_serial_deregister(&cypress_hidcom_device); 1622 usb_serial_deregister(&cypress_hidcom_device);
1555failed_em_register: 1623failed_em_register:
@@ -1566,6 +1634,7 @@ static void __exit cypress_exit (void)
1566 usb_deregister (&cypress_driver); 1634 usb_deregister (&cypress_driver);
1567 usb_serial_deregister (&cypress_earthmate_device); 1635 usb_serial_deregister (&cypress_earthmate_device);
1568 usb_serial_deregister (&cypress_hidcom_device); 1636 usb_serial_deregister (&cypress_hidcom_device);
1637 usb_serial_deregister (&cypress_ca42v2_device);
1569} 1638}
1570 1639
1571 1640
diff --git a/drivers/usb/serial/cypress_m8.h b/drivers/usb/serial/cypress_m8.h
index 1fa119efe41a..e1c7c27e18b7 100644
--- a/drivers/usb/serial/cypress_m8.h
+++ b/drivers/usb/serial/cypress_m8.h
@@ -18,6 +18,10 @@
18/* Cypress HID->COM RS232 Adapter */ 18/* Cypress HID->COM RS232 Adapter */
19#define VENDOR_ID_CYPRESS 0x04b4 19#define VENDOR_ID_CYPRESS 0x04b4
20#define PRODUCT_ID_CYPHIDCOM 0x5500 20#define PRODUCT_ID_CYPHIDCOM 0x5500
21
22/* Nokia CA-42 USB to serial cable */
23#define VENDOR_ID_DAZZLE 0x07d0
24#define PRODUCT_ID_CA42 0x4101
21/* End of device listing */ 25/* End of device listing */
22 26
23/* Used for setting / requesting serial line settings */ 27/* Used for setting / requesting serial line settings */
@@ -34,6 +38,7 @@
34 38
35#define CT_EARTHMATE 0x01 39#define CT_EARTHMATE 0x01
36#define CT_CYPHIDCOM 0x02 40#define CT_CYPHIDCOM 0x02
41#define CT_CA42V2 0x03
37#define CT_GENERIC 0x0F 42#define CT_GENERIC 0x0F
38/* End of chiptype definitions */ 43/* End of chiptype definitions */
39 44
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index c145e1ed8429..f3af81b4dd29 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -492,6 +492,7 @@ static struct usb_device_id id_table_combined [] = {
492 { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_777_PID) }, 492 { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_777_PID) },
493 { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_8900F_PID) }, 493 { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_8900F_PID) },
494 { USB_DEVICE(FTDI_VID, FTDI_PCDJ_DAC2_PID) }, 494 { USB_DEVICE(FTDI_VID, FTDI_PCDJ_DAC2_PID) },
495 { USB_DEVICE(ICOM_ID1_VID, ICOM_ID1_PID) },
495 { }, /* Optional parameter entry */ 496 { }, /* Optional parameter entry */
496 { } /* Terminating entry */ 497 { } /* Terminating entry */
497}; 498};
@@ -1141,12 +1142,11 @@ static int ftdi_sio_attach (struct usb_serial *serial)
1141 1142
1142 dbg("%s",__FUNCTION__); 1143 dbg("%s",__FUNCTION__);
1143 1144
1144 priv = kmalloc(sizeof(struct ftdi_private), GFP_KERNEL); 1145 priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL);
1145 if (!priv){ 1146 if (!priv){
1146 err("%s- kmalloc(%Zd) failed.", __FUNCTION__, sizeof(struct ftdi_private)); 1147 err("%s- kmalloc(%Zd) failed.", __FUNCTION__, sizeof(struct ftdi_private));
1147 return -ENOMEM; 1148 return -ENOMEM;
1148 } 1149 }
1149 memset(priv, 0, sizeof(*priv));
1150 1150
1151 spin_lock_init(&priv->rx_lock); 1151 spin_lock_init(&priv->rx_lock);
1152 init_waitqueue_head(&priv->delta_msr_wait); 1152 init_waitqueue_head(&priv->delta_msr_wait);
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index bdef3b8c731f..8da773c2744d 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -146,6 +146,13 @@
146#define KOBIL_CONV_KAAN_PID 0x2021 /* KOBIL_Konverter for KAAN */ 146#define KOBIL_CONV_KAAN_PID 0x2021 /* KOBIL_Konverter for KAAN */
147 147
148/* 148/*
149 * Icom ID-1 digital transceiver
150 */
151
152#define ICOM_ID1_VID 0x0C26
153#define ICOM_ID1_PID 0x0004
154
155/*
149 * DSS-20 Sync Station for Sony Ericsson P800 156 * DSS-20 Sync Station for Sony Ericsson P800
150 */ 157 */
151 158
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index d6f55e9dccae..5ec9bf5bac8d 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -1422,12 +1422,11 @@ static int garmin_attach (struct usb_serial *serial)
1422 1422
1423 dbg("%s", __FUNCTION__); 1423 dbg("%s", __FUNCTION__);
1424 1424
1425 garmin_data_p = kmalloc (sizeof(struct garmin_data), GFP_KERNEL); 1425 garmin_data_p = kzalloc(sizeof(struct garmin_data), GFP_KERNEL);
1426 if (garmin_data_p == NULL) { 1426 if (garmin_data_p == NULL) {
1427 dev_err(&port->dev, "%s - Out of memory\n", __FUNCTION__); 1427 dev_err(&port->dev, "%s - Out of memory\n", __FUNCTION__);
1428 return -ENOMEM; 1428 return -ENOMEM;
1429 } 1429 }
1430 memset (garmin_data_p, 0, sizeof(struct garmin_data));
1431 init_timer(&garmin_data_p->timer); 1430 init_timer(&garmin_data_p->timer);
1432 spin_lock_init(&garmin_data_p->lock); 1431 spin_lock_init(&garmin_data_p->lock);
1433 INIT_LIST_HEAD(&garmin_data_p->pktlist); 1432 INIT_LIST_HEAD(&garmin_data_p->pktlist);
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 3f29e6b0fd19..b606c5968102 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -2725,12 +2725,11 @@ static int edge_startup (struct usb_serial *serial)
2725 dev = serial->dev; 2725 dev = serial->dev;
2726 2726
2727 /* create our private serial structure */ 2727 /* create our private serial structure */
2728 edge_serial = kmalloc (sizeof(struct edgeport_serial), GFP_KERNEL); 2728 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
2729 if (edge_serial == NULL) { 2729 if (edge_serial == NULL) {
2730 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__); 2730 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
2731 return -ENOMEM; 2731 return -ENOMEM;
2732 } 2732 }
2733 memset (edge_serial, 0, sizeof(struct edgeport_serial));
2734 spin_lock_init(&edge_serial->es_lock); 2733 spin_lock_init(&edge_serial->es_lock);
2735 edge_serial->serial = serial; 2734 edge_serial->serial = serial;
2736 usb_set_serial_data(serial, edge_serial); 2735 usb_set_serial_data(serial, edge_serial);
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index afc0f34b3a46..8e1e2253748b 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -2727,12 +2727,11 @@ static int edge_startup (struct usb_serial *serial)
2727 dev = serial->dev; 2727 dev = serial->dev;
2728 2728
2729 /* create our private serial structure */ 2729 /* create our private serial structure */
2730 edge_serial = kmalloc (sizeof(struct edgeport_serial), GFP_KERNEL); 2730 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
2731 if (edge_serial == NULL) { 2731 if (edge_serial == NULL) {
2732 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__); 2732 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
2733 return -ENOMEM; 2733 return -ENOMEM;
2734 } 2734 }
2735 memset (edge_serial, 0, sizeof(struct edgeport_serial));
2736 sema_init(&edge_serial->es_sem, 1); 2735 sema_init(&edge_serial->es_sem, 1);
2737 edge_serial->serial = serial; 2736 edge_serial->serial = serial;
2738 usb_set_serial_data(serial, edge_serial); 2737 usb_set_serial_data(serial, edge_serial);
@@ -2745,12 +2744,11 @@ static int edge_startup (struct usb_serial *serial)
2745 2744
2746 /* set up our port private structures */ 2745 /* set up our port private structures */
2747 for (i = 0; i < serial->num_ports; ++i) { 2746 for (i = 0; i < serial->num_ports; ++i) {
2748 edge_port = kmalloc (sizeof(struct edgeport_port), GFP_KERNEL); 2747 edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL);
2749 if (edge_port == NULL) { 2748 if (edge_port == NULL) {
2750 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__); 2749 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
2751 goto cleanup; 2750 goto cleanup;
2752 } 2751 }
2753 memset (edge_port, 0, sizeof(struct edgeport_port));
2754 spin_lock_init(&edge_port->ep_lock); 2752 spin_lock_init(&edge_port->ep_lock);
2755 edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE); 2753 edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE);
2756 if (edge_port->ep_out_buf == NULL) { 2754 if (edge_port->ep_out_buf == NULL) {
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index a59010421444..426182ddc42a 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -184,10 +184,9 @@ static struct irda_class_desc *irda_usb_find_class_desc(struct usb_device *dev,
184 struct irda_class_desc *desc; 184 struct irda_class_desc *desc;
185 int ret; 185 int ret;
186 186
187 desc = kmalloc(sizeof (struct irda_class_desc), GFP_KERNEL); 187 desc = kzalloc(sizeof (struct irda_class_desc), GFP_KERNEL);
188 if (desc == NULL) 188 if (desc == NULL)
189 return NULL; 189 return NULL;
190 memset(desc, 0, sizeof(struct irda_class_desc));
191 190
192 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev,0), 191 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev,0),
193 IU_REQ_GET_CLASS_DESC, 192 IU_REQ_GET_CLASS_DESC,
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 3b958e60f5e8..052b735c4fbd 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -2250,12 +2250,11 @@ static int keyspan_startup (struct usb_serial *serial)
2250 } 2250 }
2251 2251
2252 /* Setup private data for serial driver */ 2252 /* Setup private data for serial driver */
2253 s_priv = kmalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL); 2253 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2254 if (!s_priv) { 2254 if (!s_priv) {
2255 dbg("%s - kmalloc for keyspan_serial_private failed.", __FUNCTION__); 2255 dbg("%s - kmalloc for keyspan_serial_private failed.", __FUNCTION__);
2256 return -ENOMEM; 2256 return -ENOMEM;
2257 } 2257 }
2258 memset(s_priv, 0, sizeof(struct keyspan_serial_private));
2259 2258
2260 s_priv->device_details = d_details; 2259 s_priv->device_details = d_details;
2261 usb_set_serial_data(serial, s_priv); 2260 usb_set_serial_data(serial, s_priv);
@@ -2263,12 +2262,11 @@ static int keyspan_startup (struct usb_serial *serial)
2263 /* Now setup per port private data */ 2262 /* Now setup per port private data */
2264 for (i = 0; i < serial->num_ports; i++) { 2263 for (i = 0; i < serial->num_ports; i++) {
2265 port = serial->port[i]; 2264 port = serial->port[i];
2266 p_priv = kmalloc(sizeof(struct keyspan_port_private), GFP_KERNEL); 2265 p_priv = kzalloc(sizeof(struct keyspan_port_private), GFP_KERNEL);
2267 if (!p_priv) { 2266 if (!p_priv) {
2268 dbg("%s - kmalloc for keyspan_port_private (%d) failed!.", __FUNCTION__, i); 2267 dbg("%s - kmalloc for keyspan_port_private (%d) failed!.", __FUNCTION__, i);
2269 return (1); 2268 return (1);
2270 } 2269 }
2271 memset(p_priv, 0, sizeof(struct keyspan_port_private));
2272 p_priv->device_details = d_details; 2270 p_priv->device_details = d_details;
2273 usb_set_serial_port_data(port, p_priv); 2271 usb_set_serial_port_data(port, p_priv);
2274 } 2272 }
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index b8b213185d0f..87dfcd89ffab 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -255,11 +255,9 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
255 } 255 }
256 256
257 // allocate memory for transfer buffer 257 // allocate memory for transfer buffer
258 transfer_buffer = (unsigned char *) kmalloc(transfer_buffer_length, GFP_KERNEL); 258 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
259 if (! transfer_buffer) { 259 if (! transfer_buffer) {
260 return -ENOMEM; 260 return -ENOMEM;
261 } else {
262 memset(transfer_buffer, 0, transfer_buffer_length);
263 } 261 }
264 262
265 // allocate write_urb 263 // allocate write_urb
@@ -383,11 +381,10 @@ static void kobil_read_int_callback( struct urb *purb, struct pt_regs *regs)
383 381
384 // BEGIN DEBUG 382 // BEGIN DEBUG
385 /* 383 /*
386 dbg_data = (unsigned char *) kmalloc((3 * purb->actual_length + 10) * sizeof(char), GFP_KERNEL); 384 dbg_data = kzalloc((3 * purb->actual_length + 10) * sizeof(char), GFP_KERNEL);
387 if (! dbg_data) { 385 if (! dbg_data) {
388 return; 386 return;
389 } 387 }
390 memset(dbg_data, 0, (3 * purb->actual_length + 10));
391 for (i = 0; i < purb->actual_length; i++) { 388 for (i = 0; i < purb->actual_length; i++) {
392 sprintf(dbg_data +3*i, "%02X ", data[i]); 389 sprintf(dbg_data +3*i, "%02X ", data[i]);
393 } 390 }
@@ -518,11 +515,10 @@ static int kobil_tiocmget(struct usb_serial_port *port, struct file *file)
518 } 515 }
519 516
520 // allocate memory for transfer buffer 517 // allocate memory for transfer buffer
521 transfer_buffer = (unsigned char *) kmalloc(transfer_buffer_length, GFP_KERNEL); 518 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
522 if (!transfer_buffer) { 519 if (!transfer_buffer) {
523 return -ENOMEM; 520 return -ENOMEM;
524 } 521 }
525 memset(transfer_buffer, 0, transfer_buffer_length);
526 522
527 result = usb_control_msg( port->serial->dev, 523 result = usb_control_msg( port->serial->dev,
528 usb_rcvctrlpipe(port->serial->dev, 0 ), 524 usb_rcvctrlpipe(port->serial->dev, 0 ),
@@ -564,11 +560,10 @@ static int kobil_tiocmset(struct usb_serial_port *port, struct file *file,
564 } 560 }
565 561
566 // allocate memory for transfer buffer 562 // allocate memory for transfer buffer
567 transfer_buffer = (unsigned char *) kmalloc(transfer_buffer_length, GFP_KERNEL); 563 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
568 if (! transfer_buffer) { 564 if (! transfer_buffer) {
569 return -ENOMEM; 565 return -ENOMEM;
570 } 566 }
571 memset(transfer_buffer, 0, transfer_buffer_length);
572 567
573 if (set & TIOCM_RTS) 568 if (set & TIOCM_RTS)
574 rts = 1; 569 rts = 1;
@@ -655,11 +650,10 @@ static int kobil_ioctl(struct usb_serial_port *port, struct file *file,
655 (struct termios __user *)arg)) 650 (struct termios __user *)arg))
656 return -EFAULT; 651 return -EFAULT;
657 652
658 settings = (unsigned char *) kmalloc(50, GFP_KERNEL); 653 settings = kzalloc(50, GFP_KERNEL);
659 if (! settings) { 654 if (! settings) {
660 return -ENOBUFS; 655 return -ENOBUFS;
661 } 656 }
662 memset(settings, 0, 50);
663 657
664 switch (priv->internal_termios.c_cflag & CBAUD) { 658 switch (priv->internal_termios.c_cflag & CBAUD) {
665 case B1200: 659 case B1200:
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index b6d6cab9c859..35bd29b6c408 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -348,10 +348,9 @@ static int mct_u232_startup (struct usb_serial *serial)
348 struct mct_u232_private *priv; 348 struct mct_u232_private *priv;
349 struct usb_serial_port *port, *rport; 349 struct usb_serial_port *port, *rport;
350 350
351 priv = kmalloc(sizeof(struct mct_u232_private), GFP_KERNEL); 351 priv = kzalloc(sizeof(struct mct_u232_private), GFP_KERNEL);
352 if (!priv) 352 if (!priv)
353 return -ENOMEM; 353 return -ENOMEM;
354 memset(priv, 0, sizeof(struct mct_u232_private));
355 spin_lock_init(&priv->lock); 354 spin_lock_init(&priv->lock);
356 usb_set_serial_port_data(serial->port[0], priv); 355 usb_set_serial_port_data(serial->port[0], priv);
357 356
diff --git a/drivers/usb/serial/navman.c b/drivers/usb/serial/navman.c
new file mode 100644
index 000000000000..7f544081032e
--- /dev/null
+++ b/drivers/usb/serial/navman.c
@@ -0,0 +1,157 @@
1/*
2 * Navman Serial USB driver
3 *
4 * Copyright (C) 2006 Greg Kroah-Hartman <gregkh@suse.de>
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 * version 2 as published by the Free Software Foundation.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/tty.h>
14#include <linux/tty_flip.h>
15#include <linux/module.h>
16#include <linux/usb.h>
17#include "usb-serial.h"
18
19static int debug;
20
21static struct usb_device_id id_table [] = {
22 { USB_DEVICE(0x0a99, 0x0001) }, /* Talon Technology device */
23 { },
24};
25MODULE_DEVICE_TABLE(usb, id_table);
26
27static struct usb_driver navman_driver = {
28 .name = "navman",
29 .probe = usb_serial_probe,
30 .disconnect = usb_serial_disconnect,
31 .id_table = id_table,
32 .no_dynamic_id = 1,
33};
34
35static void navman_read_int_callback(struct urb *urb, struct pt_regs *regs)
36{
37 struct usb_serial_port *port = urb->context;
38 unsigned char *data = urb->transfer_buffer;
39 struct tty_struct *tty;
40 int result;
41
42 switch (urb->status) {
43 case 0:
44 /* success */
45 break;
46 case -ECONNRESET:
47 case -ENOENT:
48 case -ESHUTDOWN:
49 /* this urb is terminated, clean up */
50 dbg("%s - urb shutting down with status: %d",
51 __FUNCTION__, urb->status);
52 return;
53 default:
54 dbg("%s - nonzero urb status received: %d",
55 __FUNCTION__, urb->status);
56 goto exit;
57 }
58
59 usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
60 urb->actual_length, data);
61
62 tty = port->tty;
63 if (tty && urb->actual_length) {
64 tty_buffer_request_room(tty, urb->actual_length);
65 tty_insert_flip_string(tty, data, urb->actual_length);
66 tty_flip_buffer_push(tty);
67 }
68
69exit:
70 result = usb_submit_urb(urb, GFP_ATOMIC);
71 if (result)
72 dev_err(&urb->dev->dev,
73 "%s - Error %d submitting interrupt urb\n",
74 __FUNCTION__, result);
75}
76
77static int navman_open(struct usb_serial_port *port, struct file *filp)
78{
79 int result = 0;
80
81 dbg("%s - port %d", __FUNCTION__, port->number);
82
83 if (port->interrupt_in_urb) {
84 dbg("%s - adding interrupt input for treo", __FUNCTION__);
85 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
86 if (result)
87 dev_err(&port->dev,
88 "%s - failed submitting interrupt urb, error %d\n",
89 __FUNCTION__, result);
90 }
91 return result;
92}
93
94static void navman_close(struct usb_serial_port *port, struct file *filp)
95{
96 dbg("%s - port %d", __FUNCTION__, port->number);
97
98 if (port->interrupt_in_urb)
99 usb_kill_urb(port->interrupt_in_urb);
100}
101
102static int navman_write(struct usb_serial_port *port,
103 const unsigned char *buf, int count)
104{
105 dbg("%s - port %d", __FUNCTION__, port->number);
106
107 /*
108 * This device can't write any data, only read from the device
109 * so we just silently eat all data sent to us and say it was
110 * successfully sent.
111 * Evil, I know, but do you have a better idea?
112 */
113
114 return count;
115}
116
117static struct usb_serial_driver navman_device = {
118 .driver = {
119 .owner = THIS_MODULE,
120 .name = "navman",
121 },
122 .id_table = id_table,
123 .num_interrupt_in = NUM_DONT_CARE,
124 .num_bulk_in = NUM_DONT_CARE,
125 .num_bulk_out = NUM_DONT_CARE,
126 .num_ports = 1,
127 .open = navman_open,
128 .close = navman_close,
129 .write = navman_write,
130 .read_int_callback = navman_read_int_callback,
131};
132
133static int __init navman_init(void)
134{
135 int retval;
136
137 retval = usb_serial_register(&navman_device);
138 if (retval)
139 return retval;
140 retval = usb_register(&navman_driver);
141 if (retval)
142 usb_serial_deregister(&navman_device);
143 return retval;
144}
145
146static void __exit navman_exit(void)
147{
148 usb_deregister(&navman_driver);
149 usb_serial_deregister(&navman_device);
150}
151
152module_init(navman_init);
153module_exit(navman_exit);
154MODULE_LICENSE("GPL");
155
156module_param(debug, bool, S_IRUGO | S_IWUSR);
157MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index 762d8ff9a1e4..4d40704dea2c 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -204,7 +204,7 @@ static void omninet_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
204 int i; 204 int i;
205 int result; 205 int result;
206 206
207// dbg("omninet_read_bulk_callback"); 207 dbg("%s - port %d", __FUNCTION__, port->number);
208 208
209 if (urb->status) { 209 if (urb->status) {
210 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status); 210 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
@@ -250,7 +250,7 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
250 250
251 int result; 251 int result;
252 252
253// dbg("omninet_write port %d", port->number); 253 dbg("%s - port %d", __FUNCTION__, port->number);
254 254
255 if (count == 0) { 255 if (count == 0) {
256 dbg("%s - write request of 0 bytes", __FUNCTION__); 256 dbg("%s - write request of 0 bytes", __FUNCTION__);
@@ -302,7 +302,7 @@ static int omninet_write_room (struct usb_serial_port *port)
302 if (wport->write_urb_busy) 302 if (wport->write_urb_busy)
303 room = wport->bulk_out_size - OMNINET_HEADERLEN; 303 room = wport->bulk_out_size - OMNINET_HEADERLEN;
304 304
305// dbg("omninet_write_room returns %d", room); 305 dbg("%s - returns %d", __FUNCTION__, room);
306 306
307 return (room); 307 return (room);
308} 308}
@@ -312,7 +312,7 @@ static void omninet_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
312/* struct omninet_header *header = (struct omninet_header *) urb->transfer_buffer; */ 312/* struct omninet_header *header = (struct omninet_header *) urb->transfer_buffer; */
313 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 313 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
314 314
315// dbg("omninet_write_bulk_callback, port %0x\n", port); 315 dbg("%s - port %0x\n", __FUNCTION__, port->number);
316 316
317 port->write_urb_busy = 0; 317 port->write_urb_busy = 0;
318 if (urb->status) { 318 if (urb->status) {
@@ -321,8 +321,6 @@ static void omninet_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
321 } 321 }
322 322
323 schedule_work(&port->work); 323 schedule_work(&port->work);
324
325// dbg("omninet_write_bulk_callback, tty %0x\n", tty);
326} 324}
327 325
328 326
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 52bdf6fe46f2..a8455c9e79dd 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -631,13 +631,12 @@ static int option_startup(struct usb_serial *serial)
631 /* Now setup per port private data */ 631 /* Now setup per port private data */
632 for (i = 0; i < serial->num_ports; i++) { 632 for (i = 0; i < serial->num_ports; i++) {
633 port = serial->port[i]; 633 port = serial->port[i];
634 portdata = kmalloc(sizeof(*portdata), GFP_KERNEL); 634 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
635 if (!portdata) { 635 if (!portdata) {
636 dbg("%s: kmalloc for option_port_private (%d) failed!.", 636 dbg("%s: kmalloc for option_port_private (%d) failed!.",
637 __FUNCTION__, i); 637 __FUNCTION__, i);
638 return (1); 638 return (1);
639 } 639 }
640 memset(portdata, 0, sizeof(struct option_port_private));
641 640
642 usb_set_serial_port_data(port, portdata); 641 usb_set_serial_port_data(port, portdata);
643 642
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 37c81c08faad..b3014fda645c 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -77,6 +77,7 @@ static struct usb_device_id id_table [] = {
77 { USB_DEVICE(CA_42_CA42_VENDOR_ID, CA_42_CA42_PRODUCT_ID) }, 77 { USB_DEVICE(CA_42_CA42_VENDOR_ID, CA_42_CA42_PRODUCT_ID) },
78 { USB_DEVICE(SAGEM_VENDOR_ID, SAGEM_PRODUCT_ID) }, 78 { USB_DEVICE(SAGEM_VENDOR_ID, SAGEM_PRODUCT_ID) },
79 { USB_DEVICE(LEADTEK_VENDOR_ID, LEADTEK_9531_PRODUCT_ID) }, 79 { USB_DEVICE(LEADTEK_VENDOR_ID, LEADTEK_9531_PRODUCT_ID) },
80 { USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) },
80 { } /* Terminating entry */ 81 { } /* Terminating entry */
81}; 82};
82 83
@@ -218,10 +219,9 @@ static int pl2303_startup (struct usb_serial *serial)
218 dbg("device type: %d", type); 219 dbg("device type: %d", type);
219 220
220 for (i = 0; i < serial->num_ports; ++i) { 221 for (i = 0; i < serial->num_ports; ++i) {
221 priv = kmalloc (sizeof (struct pl2303_private), GFP_KERNEL); 222 priv = kzalloc(sizeof(struct pl2303_private), GFP_KERNEL);
222 if (!priv) 223 if (!priv)
223 goto cleanup; 224 goto cleanup;
224 memset (priv, 0x00, sizeof (struct pl2303_private));
225 spin_lock_init(&priv->lock); 225 spin_lock_init(&priv->lock);
226 priv->buf = pl2303_buf_alloc(PL2303_BUF_SIZE); 226 priv->buf = pl2303_buf_alloc(PL2303_BUF_SIZE);
227 if (priv->buf == NULL) { 227 if (priv->buf == NULL) {
@@ -383,12 +383,11 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol
383 } 383 }
384 } 384 }
385 385
386 buf = kmalloc (7, GFP_KERNEL); 386 buf = kzalloc (7, GFP_KERNEL);
387 if (!buf) { 387 if (!buf) {
388 dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__); 388 dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__);
389 return; 389 return;
390 } 390 }
391 memset (buf, 0x00, 0x07);
392 391
393 i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0), 392 i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0),
394 GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, 393 GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
@@ -828,6 +827,7 @@ static void pl2303_update_line_status(struct usb_serial_port *port,
828 spin_lock_irqsave(&priv->lock, flags); 827 spin_lock_irqsave(&priv->lock, flags);
829 priv->line_status = data[status_idx]; 828 priv->line_status = data[status_idx];
830 spin_unlock_irqrestore(&priv->lock, flags); 829 spin_unlock_irqrestore(&priv->lock, flags);
830 wake_up_interruptible (&priv->delta_msr_wait);
831 831
832exit: 832exit:
833 return; 833 return;
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index 9bc4755162ad..77901d143979 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -75,3 +75,7 @@
75/* Leadtek GPS 9531 (ID 0413:2101) */ 75/* Leadtek GPS 9531 (ID 0413:2101) */
76#define LEADTEK_VENDOR_ID 0x0413 76#define LEADTEK_VENDOR_ID 0x0413
77#define LEADTEK_9531_PRODUCT_ID 0x2101 77#define LEADTEK_9531_PRODUCT_ID 0x2101
78
79/* USB GSM cable from Speed Dragon Multimedia, Ltd */
80#define SPEEDDRAGON_VENDOR_ID 0x0e55
81#define SPEEDDRAGON_PRODUCT_ID 0x110b
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index c18db3257073..c3a2071b802d 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -416,12 +416,11 @@ static int ti_startup(struct usb_serial *serial)
416 dev->actconfig->desc.bConfigurationValue); 416 dev->actconfig->desc.bConfigurationValue);
417 417
418 /* create device structure */ 418 /* create device structure */
419 tdev = kmalloc(sizeof(struct ti_device), GFP_KERNEL); 419 tdev = kzalloc(sizeof(struct ti_device), GFP_KERNEL);
420 if (tdev == NULL) { 420 if (tdev == NULL) {
421 dev_err(&dev->dev, "%s - out of memory\n", __FUNCTION__); 421 dev_err(&dev->dev, "%s - out of memory\n", __FUNCTION__);
422 return -ENOMEM; 422 return -ENOMEM;
423 } 423 }
424 memset(tdev, 0, sizeof(struct ti_device));
425 sema_init(&tdev->td_open_close_sem, 1); 424 sema_init(&tdev->td_open_close_sem, 1);
426 tdev->td_serial = serial; 425 tdev->td_serial = serial;
427 usb_set_serial_data(serial, tdev); 426 usb_set_serial_data(serial, tdev);
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index b5c96e74a903..097f4e8488fe 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -564,12 +564,11 @@ static struct usb_serial * create_serial (struct usb_device *dev,
564{ 564{
565 struct usb_serial *serial; 565 struct usb_serial *serial;
566 566
567 serial = kmalloc (sizeof (*serial), GFP_KERNEL); 567 serial = kzalloc(sizeof(*serial), GFP_KERNEL);
568 if (!serial) { 568 if (!serial) {
569 dev_err(&dev->dev, "%s - out of memory\n", __FUNCTION__); 569 dev_err(&dev->dev, "%s - out of memory\n", __FUNCTION__);
570 return NULL; 570 return NULL;
571 } 571 }
572 memset (serial, 0, sizeof(*serial));
573 serial->dev = usb_get_dev(dev); 572 serial->dev = usb_get_dev(dev);
574 serial->type = driver; 573 serial->type = driver;
575 serial->interface = interface; 574 serial->interface = interface;
@@ -778,10 +777,9 @@ int usb_serial_probe(struct usb_interface *interface,
778 serial->num_port_pointers = max_endpoints; 777 serial->num_port_pointers = max_endpoints;
779 dbg("%s - setting up %d port structures for this device", __FUNCTION__, max_endpoints); 778 dbg("%s - setting up %d port structures for this device", __FUNCTION__, max_endpoints);
780 for (i = 0; i < max_endpoints; ++i) { 779 for (i = 0; i < max_endpoints; ++i) {
781 port = kmalloc(sizeof(struct usb_serial_port), GFP_KERNEL); 780 port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL);
782 if (!port) 781 if (!port)
783 goto probe_error; 782 goto probe_error;
784 memset(port, 0x00, sizeof(struct usb_serial_port));
785 port->number = i + serial->minor; 783 port->number = i + serial->minor;
786 port->serial = serial; 784 port->serial = serial;
787 spin_lock_init(&port->lock); 785 spin_lock_init(&port->lock);
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index 11a48d874752..f5c3841d4843 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -763,10 +763,9 @@ static int generic_startup(struct usb_serial *serial)
763 int i; 763 int i;
764 764
765 for (i = 0; i < serial->num_ports; ++i) { 765 for (i = 0; i < serial->num_ports; ++i) {
766 priv = kmalloc (sizeof(*priv), GFP_KERNEL); 766 priv = kzalloc (sizeof(*priv), GFP_KERNEL);
767 if (!priv) 767 if (!priv)
768 return -ENOMEM; 768 return -ENOMEM;
769 memset (priv, 0x00, sizeof(*priv));
770 spin_lock_init(&priv->lock); 769 spin_lock_init(&priv->lock);
771 usb_set_serial_port_data(serial->port[i], priv); 770 usb_set_serial_port_data(serial->port[i], priv);
772 } 771 }
diff --git a/drivers/usb/storage/datafab.c b/drivers/usb/storage/datafab.c
index 54e3e6c7ecd8..01d8971ad7db 100644
--- a/drivers/usb/storage/datafab.c
+++ b/drivers/usb/storage/datafab.c
@@ -512,13 +512,12 @@ int datafab_transport(struct scsi_cmnd * srb, struct us_data *us)
512 }; 512 };
513 513
514 if (!us->extra) { 514 if (!us->extra) {
515 us->extra = kmalloc(sizeof(struct datafab_info), GFP_NOIO); 515 us->extra = kzalloc(sizeof(struct datafab_info), GFP_NOIO);
516 if (!us->extra) { 516 if (!us->extra) {
517 US_DEBUGP("datafab_transport: Gah! " 517 US_DEBUGP("datafab_transport: Gah! "
518 "Can't allocate storage for Datafab info struct!\n"); 518 "Can't allocate storage for Datafab info struct!\n");
519 return USB_STOR_TRANSPORT_ERROR; 519 return USB_STOR_TRANSPORT_ERROR;
520 } 520 }
521 memset(us->extra, 0, sizeof(struct datafab_info));
522 us->extra_destructor = datafab_info_destructor; 521 us->extra_destructor = datafab_info_destructor;
523 ((struct datafab_info *)us->extra)->lun = -1; 522 ((struct datafab_info *)us->extra)->lun = -1;
524 } 523 }
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index ecb328aa9ea1..6831dca93c1b 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -1361,21 +1361,19 @@ static int isd200_init_info(struct us_data *us)
1361 struct isd200_info *info; 1361 struct isd200_info *info;
1362 1362
1363 info = (struct isd200_info *) 1363 info = (struct isd200_info *)
1364 kmalloc(sizeof(struct isd200_info), GFP_KERNEL); 1364 kzalloc(sizeof(struct isd200_info), GFP_KERNEL);
1365 if (!info) 1365 if (!info)
1366 retStatus = ISD200_ERROR; 1366 retStatus = ISD200_ERROR;
1367 else { 1367 else {
1368 memset(info, 0, sizeof(struct isd200_info));
1369 info->id = (struct hd_driveid *) 1368 info->id = (struct hd_driveid *)
1370 kmalloc(sizeof(struct hd_driveid), GFP_KERNEL); 1369 kzalloc(sizeof(struct hd_driveid), GFP_KERNEL);
1371 info->RegsBuf = (unsigned char *) 1370 info->RegsBuf = (unsigned char *)
1372 kmalloc(sizeof(info->ATARegs), GFP_KERNEL); 1371 kmalloc(sizeof(info->ATARegs), GFP_KERNEL);
1373 if (!info->id || !info->RegsBuf) { 1372 if (!info->id || !info->RegsBuf) {
1374 isd200_free_info_ptrs(info); 1373 isd200_free_info_ptrs(info);
1375 kfree(info); 1374 kfree(info);
1376 retStatus = ISD200_ERROR; 1375 retStatus = ISD200_ERROR;
1377 } else 1376 }
1378 memset(info->id, 0, sizeof(struct hd_driveid));
1379 } 1377 }
1380 1378
1381 if (retStatus == ISD200_GOOD) { 1379 if (retStatus == ISD200_GOOD) {
@@ -1384,7 +1382,7 @@ static int isd200_init_info(struct us_data *us)
1384 } else 1382 } else
1385 US_DEBUGP("ERROR - kmalloc failure\n"); 1383 US_DEBUGP("ERROR - kmalloc failure\n");
1386 1384
1387 return(retStatus); 1385 return retStatus;
1388} 1386}
1389 1387
1390/************************************************************************** 1388/**************************************************************************
diff --git a/drivers/usb/storage/jumpshot.c b/drivers/usb/storage/jumpshot.c
index aff9d51c327c..5031aa98f6a9 100644
--- a/drivers/usb/storage/jumpshot.c
+++ b/drivers/usb/storage/jumpshot.c
@@ -441,12 +441,11 @@ int jumpshot_transport(struct scsi_cmnd * srb, struct us_data *us)
441 }; 441 };
442 442
443 if (!us->extra) { 443 if (!us->extra) {
444 us->extra = kmalloc(sizeof(struct jumpshot_info), GFP_NOIO); 444 us->extra = kzalloc(sizeof(struct jumpshot_info), GFP_NOIO);
445 if (!us->extra) { 445 if (!us->extra) {
446 US_DEBUGP("jumpshot_transport: Gah! Can't allocate storage for jumpshot info struct!\n"); 446 US_DEBUGP("jumpshot_transport: Gah! Can't allocate storage for jumpshot info struct!\n");
447 return USB_STOR_TRANSPORT_ERROR; 447 return USB_STOR_TRANSPORT_ERROR;
448 } 448 }
449 memset(us->extra, 0, sizeof(struct jumpshot_info));
450 us->extra_destructor = jumpshot_info_destructor; 449 us->extra_destructor = jumpshot_info_destructor;
451 } 450 }
452 451
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 4ef5527028c5..5f11e19eaae3 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -47,6 +47,7 @@
47 47
48#include <linux/slab.h> 48#include <linux/slab.h>
49#include <linux/module.h> 49#include <linux/module.h>
50#include <linux/mutex.h>
50 51
51#include <scsi/scsi.h> 52#include <scsi/scsi.h>
52#include <scsi/scsi_cmnd.h> 53#include <scsi/scsi_cmnd.h>
@@ -271,9 +272,9 @@ static int device_reset(struct scsi_cmnd *srb)
271 US_DEBUGP("%s called\n", __FUNCTION__); 272 US_DEBUGP("%s called\n", __FUNCTION__);
272 273
273 /* lock the device pointers and do the reset */ 274 /* lock the device pointers and do the reset */
274 down(&(us->dev_semaphore)); 275 mutex_lock(&(us->dev_mutex));
275 result = us->transport_reset(us); 276 result = us->transport_reset(us);
276 up(&(us->dev_semaphore)); 277 mutex_unlock(&us->dev_mutex);
277 278
278 return result < 0 ? FAILED : SUCCESS; 279 return result < 0 ? FAILED : SUCCESS;
279} 280}
@@ -286,9 +287,9 @@ static int bus_reset(struct scsi_cmnd *srb)
286 287
287 US_DEBUGP("%s called\n", __FUNCTION__); 288 US_DEBUGP("%s called\n", __FUNCTION__);
288 289
289 down(&(us->dev_semaphore)); 290 mutex_lock(&(us->dev_mutex));
290 result = usb_stor_port_reset(us); 291 result = usb_stor_port_reset(us);
291 up(&(us->dev_semaphore)); 292 mutex_unlock(&us->dev_mutex);
292 293
293 return result < 0 ? FAILED : SUCCESS; 294 return result < 0 ? FAILED : SUCCESS;
294} 295}
diff --git a/drivers/usb/storage/sddr55.c b/drivers/usb/storage/sddr55.c
index 8451779f4269..0b1b5b59ca7b 100644
--- a/drivers/usb/storage/sddr55.c
+++ b/drivers/usb/storage/sddr55.c
@@ -751,11 +751,10 @@ int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us)
751 struct sddr55_card_info *info; 751 struct sddr55_card_info *info;
752 752
753 if (!us->extra) { 753 if (!us->extra) {
754 us->extra = kmalloc( 754 us->extra = kzalloc(
755 sizeof(struct sddr55_card_info), GFP_NOIO); 755 sizeof(struct sddr55_card_info), GFP_NOIO);
756 if (!us->extra) 756 if (!us->extra)
757 return USB_STOR_TRANSPORT_ERROR; 757 return USB_STOR_TRANSPORT_ERROR;
758 memset(us->extra, 0, sizeof(struct sddr55_card_info));
759 us->extra_destructor = sddr55_card_info_destructor; 758 us->extra_destructor = sddr55_card_info_destructor;
760 } 759 }
761 760
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index fea176d7e79a..f2bc5c9e23d5 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -1318,12 +1318,11 @@ int init_usbat(struct us_data *us)
1318 unsigned char subcountL = USBAT_ATA_LBA_ME; 1318 unsigned char subcountL = USBAT_ATA_LBA_ME;
1319 unsigned char *status = us->iobuf; 1319 unsigned char *status = us->iobuf;
1320 1320
1321 us->extra = kmalloc(sizeof(struct usbat_info), GFP_NOIO); 1321 us->extra = kzalloc(sizeof(struct usbat_info), GFP_NOIO);
1322 if (!us->extra) { 1322 if (!us->extra) {
1323 US_DEBUGP("init_usbat: Gah! Can't allocate storage for usbat info struct!\n"); 1323 US_DEBUGP("init_usbat: Gah! Can't allocate storage for usbat info struct!\n");
1324 return 1; 1324 return 1;
1325 } 1325 }
1326 memset(us->extra, 0, sizeof(struct usbat_info));
1327 info = (struct usbat_info *) (us->extra); 1326 info = (struct usbat_info *) (us->extra);
1328 1327
1329 /* Enable peripheral control signals */ 1328 /* Enable peripheral control signals */
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 31ca92056c27..c4a9dcff5f2b 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -62,6 +62,13 @@ UNUSUAL_DEV( 0x03ee, 0x6901, 0x0000, 0x0100,
62 US_SC_DEVICE, US_PR_DEVICE, NULL, 62 US_SC_DEVICE, US_PR_DEVICE, NULL,
63 US_FL_SINGLE_LUN ), 63 US_FL_SINGLE_LUN ),
64 64
65/* Reported by Rodolfo Quesada <rquesada@roqz.net> */
66UNUSUAL_DEV( 0x03ee, 0x6906, 0x0003, 0x0003,
67 "VIA Technologies Inc.",
68 "Mitsumi multi cardreader",
69 US_SC_DEVICE, US_PR_DEVICE, NULL,
70 US_FL_IGNORE_RESIDUE ),
71
65UNUSUAL_DEV( 0x03f0, 0x0107, 0x0200, 0x0200, 72UNUSUAL_DEV( 0x03f0, 0x0107, 0x0200, 0x0200,
66 "HP", 73 "HP",
67 "CD-Writer+", 74 "CD-Writer+",
@@ -120,6 +127,12 @@ UNUSUAL_DEV( 0x0419, 0xaaf6, 0x0100, 0x0100,
120 US_SC_DEVICE, US_PR_DEVICE, NULL, 127 US_SC_DEVICE, US_PR_DEVICE, NULL,
121 US_FL_IGNORE_RESIDUE ), 128 US_FL_IGNORE_RESIDUE ),
122 129
130/* Reported by Pete Zaitcev <zaitcev@redhat.com>, bz#176584 */
131UNUSUAL_DEV( 0x0420, 0x0001, 0x0100, 0x0100,
132 "GENERIC", "MP3 PLAYER", /* MyMusix PD-205 on the outside. */
133 US_SC_DEVICE, US_PR_DEVICE, NULL,
134 US_FL_IGNORE_RESIDUE ),
135
123/* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */ 136/* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */
124UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210, 137UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210,
125 "SMSC", 138 "SMSC",
@@ -760,12 +773,19 @@ UNUSUAL_DEV( 0x069b, 0x3004, 0x0001, 0x0001,
760 US_SC_DEVICE, US_PR_DEVICE, NULL, 773 US_SC_DEVICE, US_PR_DEVICE, NULL,
761 US_FL_FIX_CAPACITY ), 774 US_FL_FIX_CAPACITY ),
762 775
763UNUSUAL_DEV( 0x0781, 0x0001, 0x0200, 0x0200, 776/* Submitted by Roman Hodek <roman@hodek.net> */
777UNUSUAL_DEV( 0x0781, 0x0001, 0x0200, 0x0200,
764 "Sandisk", 778 "Sandisk",
765 "ImageMate SDDR-05a", 779 "ImageMate SDDR-05a",
766 US_SC_SCSI, US_PR_CB, NULL, 780 US_SC_SCSI, US_PR_CB, NULL,
767 US_FL_SINGLE_LUN ), 781 US_FL_SINGLE_LUN ),
768 782
783UNUSUAL_DEV( 0x0781, 0x0002, 0x0009, 0x0009,
784 "SanDisk Corporation",
785 "ImageMate CompactFlash USB",
786 US_SC_DEVICE, US_PR_DEVICE, NULL,
787 US_FL_FIX_CAPACITY ),
788
769#ifdef CONFIG_USB_STORAGE_USBAT 789#ifdef CONFIG_USB_STORAGE_USBAT
770UNUSUAL_DEV( 0x0781, 0x0005, 0x0005, 0x0005, 790UNUSUAL_DEV( 0x0781, 0x0005, 0x0005, 0x0005,
771 "Sandisk", 791 "Sandisk",
@@ -1073,6 +1093,16 @@ UNUSUAL_DEV( 0x0c0b, 0xa109, 0x0000, 0xffff,
1073 0), 1093 0),
1074#endif 1094#endif
1075 1095
1096/*
1097 * Pete Zaitcev <zaitcev@yahoo.com>, bz#164688.
1098 * The device blatantly ignores LUN and returns 1 in GetMaxLUN.
1099 */
1100UNUSUAL_DEV( 0x0c45, 0x1060, 0x0100, 0x0100,
1101 "Unknown",
1102 "Unknown",
1103 US_SC_DEVICE, US_PR_DEVICE, NULL,
1104 US_FL_SINGLE_LUN ),
1105
1076/* Submitted by Joris Struyve <joris@struyve.be> */ 1106/* Submitted by Joris Struyve <joris@struyve.be> */
1077UNUSUAL_DEV( 0x0d96, 0x410a, 0x0001, 0xffff, 1107UNUSUAL_DEV( 0x0d96, 0x410a, 0x0001, 0xffff,
1078 "Medion", 1108 "Medion",
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index dbcf23980ff1..dd108634348e 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -55,6 +55,7 @@
55#include <linux/init.h> 55#include <linux/init.h>
56#include <linux/slab.h> 56#include <linux/slab.h>
57#include <linux/kthread.h> 57#include <linux/kthread.h>
58#include <linux/mutex.h>
58 59
59#include <scsi/scsi.h> 60#include <scsi/scsi.h>
60#include <scsi/scsi_cmnd.h> 61#include <scsi/scsi_cmnd.h>
@@ -188,7 +189,7 @@ static int storage_suspend(struct usb_interface *iface, pm_message_t message)
188 struct us_data *us = usb_get_intfdata(iface); 189 struct us_data *us = usb_get_intfdata(iface);
189 190
190 /* Wait until no command is running */ 191 /* Wait until no command is running */
191 down(&us->dev_semaphore); 192 mutex_lock(&us->dev_mutex);
192 193
193 US_DEBUGP("%s\n", __FUNCTION__); 194 US_DEBUGP("%s\n", __FUNCTION__);
194 if (us->suspend_resume_hook) 195 if (us->suspend_resume_hook)
@@ -198,7 +199,7 @@ static int storage_suspend(struct usb_interface *iface, pm_message_t message)
198 /* When runtime PM is working, we'll set a flag to indicate 199 /* When runtime PM is working, we'll set a flag to indicate
199 * whether we should autoresume when a SCSI request arrives. */ 200 * whether we should autoresume when a SCSI request arrives. */
200 201
201 up(&us->dev_semaphore); 202 mutex_unlock(&us->dev_mutex);
202 return 0; 203 return 0;
203} 204}
204 205
@@ -206,14 +207,14 @@ static int storage_resume(struct usb_interface *iface)
206{ 207{
207 struct us_data *us = usb_get_intfdata(iface); 208 struct us_data *us = usb_get_intfdata(iface);
208 209
209 down(&us->dev_semaphore); 210 mutex_lock(&us->dev_mutex);
210 211
211 US_DEBUGP("%s\n", __FUNCTION__); 212 US_DEBUGP("%s\n", __FUNCTION__);
212 if (us->suspend_resume_hook) 213 if (us->suspend_resume_hook)
213 (us->suspend_resume_hook)(us, US_RESUME); 214 (us->suspend_resume_hook)(us, US_RESUME);
214 iface->dev.power.power_state.event = PM_EVENT_ON; 215 iface->dev.power.power_state.event = PM_EVENT_ON;
215 216
216 up(&us->dev_semaphore); 217 mutex_unlock(&us->dev_mutex);
217 return 0; 218 return 0;
218} 219}
219 220
@@ -276,12 +277,12 @@ static int usb_stor_control_thread(void * __us)
276 US_DEBUGP("*** thread awakened.\n"); 277 US_DEBUGP("*** thread awakened.\n");
277 278
278 /* lock the device pointers */ 279 /* lock the device pointers */
279 down(&(us->dev_semaphore)); 280 mutex_lock(&(us->dev_mutex));
280 281
281 /* if the device has disconnected, we are free to exit */ 282 /* if the device has disconnected, we are free to exit */
282 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 283 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
283 US_DEBUGP("-- exiting\n"); 284 US_DEBUGP("-- exiting\n");
284 up(&(us->dev_semaphore)); 285 mutex_unlock(&us->dev_mutex);
285 break; 286 break;
286 } 287 }
287 288
@@ -370,7 +371,7 @@ SkipForAbort:
370 scsi_unlock(host); 371 scsi_unlock(host);
371 372
372 /* unlock the device pointers */ 373 /* unlock the device pointers */
373 up(&(us->dev_semaphore)); 374 mutex_unlock(&us->dev_mutex);
374 } /* for (;;) */ 375 } /* for (;;) */
375 376
376 scsi_host_put(host); 377 scsi_host_put(host);
@@ -815,8 +816,8 @@ static void quiesce_and_remove_host(struct us_data *us)
815 * The thread will exit when it sees the DISCONNECTING flag. */ 816 * The thread will exit when it sees the DISCONNECTING flag. */
816 817
817 /* Wait for the current command to finish, then remove the host */ 818 /* Wait for the current command to finish, then remove the host */
818 down(&us->dev_semaphore); 819 mutex_lock(&us->dev_mutex);
819 up(&us->dev_semaphore); 820 mutex_unlock(&us->dev_mutex);
820 821
821 /* queuecommand won't accept any new commands and the control 822 /* queuecommand won't accept any new commands and the control
822 * thread won't execute a previously-queued command. If there 823 * thread won't execute a previously-queued command. If there
@@ -870,9 +871,9 @@ retry:
870 /* For bulk-only devices, determine the max LUN value */ 871 /* For bulk-only devices, determine the max LUN value */
871 if (us->protocol == US_PR_BULK && 872 if (us->protocol == US_PR_BULK &&
872 !(us->flags & US_FL_SINGLE_LUN)) { 873 !(us->flags & US_FL_SINGLE_LUN)) {
873 down(&us->dev_semaphore); 874 mutex_lock(&us->dev_mutex);
874 us->max_lun = usb_stor_Bulk_max_lun(us); 875 us->max_lun = usb_stor_Bulk_max_lun(us);
875 up(&us->dev_semaphore); 876 mutex_unlock(&us->dev_mutex);
876 } 877 }
877 scsi_scan_host(us_to_host(us)); 878 scsi_scan_host(us_to_host(us));
878 printk(KERN_DEBUG "usb-storage: device scan complete\n"); 879 printk(KERN_DEBUG "usb-storage: device scan complete\n");
@@ -912,7 +913,7 @@ static int storage_probe(struct usb_interface *intf,
912 913
913 us = host_to_us(host); 914 us = host_to_us(host);
914 memset(us, 0, sizeof(struct us_data)); 915 memset(us, 0, sizeof(struct us_data));
915 init_MUTEX(&(us->dev_semaphore)); 916 mutex_init(&(us->dev_mutex));
916 init_MUTEX_LOCKED(&(us->sema)); 917 init_MUTEX_LOCKED(&(us->sema));
917 init_completion(&(us->notify)); 918 init_completion(&(us->notify));
918 init_waitqueue_head(&us->delay_wait); 919 init_waitqueue_head(&us->delay_wait);
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index 7259fd1f6b0d..009fb0953a56 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -49,6 +49,7 @@
49#include <linux/blkdev.h> 49#include <linux/blkdev.h>
50#include <linux/smp_lock.h> 50#include <linux/smp_lock.h>
51#include <linux/completion.h> 51#include <linux/completion.h>
52#include <linux/mutex.h>
52#include <scsi/scsi_host.h> 53#include <scsi/scsi_host.h>
53 54
54struct us_data; 55struct us_data;
@@ -103,9 +104,9 @@ typedef void (*pm_hook)(struct us_data *, int); /* power management hook */
103struct us_data { 104struct us_data {
104 /* The device we're working with 105 /* The device we're working with
105 * It's important to note: 106 * It's important to note:
106 * (o) you must hold dev_semaphore to change pusb_dev 107 * (o) you must hold dev_mutex to change pusb_dev
107 */ 108 */
108 struct semaphore dev_semaphore; /* protect pusb_dev */ 109 struct mutex dev_mutex; /* protect pusb_dev */
109 struct usb_device *pusb_dev; /* this usb_device */ 110 struct usb_device *pusb_dev; /* this usb_device */
110 struct usb_interface *pusb_intf; /* this interface */ 111 struct usb_interface *pusb_intf; /* this interface */
111 struct us_unusual_dev *unusual_dev; /* device-filter entry */ 112 struct us_unusual_dev *unusual_dev; /* device-filter entry */
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index f5079c78ba4e..fdebd60a3250 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -899,8 +899,6 @@ config FB_RADEON_OLD
899 Choose this option if you want to use an ATI Radeon graphics card as 899 Choose this option if you want to use an ATI Radeon graphics card as
900 a framebuffer device. There are both PCI and AGP versions. You 900 a framebuffer device. There are both PCI and AGP versions. You
901 don't need to choose this to run the Radeon in plain VGA mode. 901 don't need to choose this to run the Radeon in plain VGA mode.
902 There is a product page at
903 <http://www.ati.com/na/pages/products/pc/radeon32/index.html>.
904 902
905config FB_RADEON 903config FB_RADEON
906 tristate "ATI Radeon display support" 904 tristate "ATI Radeon display support"
diff --git a/drivers/video/epson1355fb.c b/drivers/video/epson1355fb.c
index 3b0e71383448..082759447bf6 100644
--- a/drivers/video/epson1355fb.c
+++ b/drivers/video/epson1355fb.c
@@ -607,6 +607,7 @@ static void clearfb16(struct fb_info *info)
607 607
608static void epson1355fb_platform_release(struct device *device) 608static void epson1355fb_platform_release(struct device *device)
609{ 609{
610 dev_err(device, "This driver is broken, please bug the authors so they will fix it.\n");
610} 611}
611 612
612static int epson1355fb_remove(struct platform_device *dev) 613static int epson1355fb_remove(struct platform_device *dev)
diff --git a/drivers/video/sa1100fb.c b/drivers/video/sa1100fb.c
index 8a893ce7040d..d9831fd42341 100644
--- a/drivers/video/sa1100fb.c
+++ b/drivers/video/sa1100fb.c
@@ -1457,7 +1457,7 @@ static int __init sa1100fb_probe(struct platform_device *pdev)
1457 int ret, irq; 1457 int ret, irq;
1458 1458
1459 irq = platform_get_irq(pdev, 0); 1459 irq = platform_get_irq(pdev, 0);
1460 if (irq <= 0) 1460 if (irq < 0)
1461 return -EINVAL; 1461 return -EINVAL;
1462 1462
1463 if (!request_mem_region(0xb0100000, 0x10000, "LCD")) 1463 if (!request_mem_region(0xb0100000, 0x10000, "LCD"))
diff --git a/drivers/video/vfb.c b/drivers/video/vfb.c
index 53208cb58396..77eed1fd9943 100644
--- a/drivers/video/vfb.c
+++ b/drivers/video/vfb.c
@@ -401,6 +401,7 @@ static int __init vfb_setup(char *options)
401static void vfb_platform_release(struct device *device) 401static void vfb_platform_release(struct device *device)
402{ 402{
403 // This is called when the reference count goes to zero. 403 // This is called when the reference count goes to zero.
404 dev_err(device, "This driver is broken, please bug the authors so they will fix it.\n");
404} 405}
405 406
406static int __init vfb_probe(struct platform_device *dev) 407static int __init vfb_probe(struct platform_device *dev)
diff --git a/fs/char_dev.c b/fs/char_dev.c
index 21195c481637..5c36345c9bf7 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -19,6 +19,7 @@
19#include <linux/kobject.h> 19#include <linux/kobject.h>
20#include <linux/kobj_map.h> 20#include <linux/kobj_map.h>
21#include <linux/cdev.h> 21#include <linux/cdev.h>
22#include <linux/mutex.h>
22 23
23#ifdef CONFIG_KMOD 24#ifdef CONFIG_KMOD
24#include <linux/kmod.h> 25#include <linux/kmod.h>
@@ -28,7 +29,7 @@ static struct kobj_map *cdev_map;
28 29
29#define MAX_PROBE_HASH 255 /* random */ 30#define MAX_PROBE_HASH 255 /* random */
30 31
31static DECLARE_MUTEX(chrdevs_lock); 32static DEFINE_MUTEX(chrdevs_lock);
32 33
33static struct char_device_struct { 34static struct char_device_struct {
34 struct char_device_struct *next; 35 struct char_device_struct *next;
@@ -88,13 +89,13 @@ out:
88 89
89void *acquire_chrdev_list(void) 90void *acquire_chrdev_list(void)
90{ 91{
91 down(&chrdevs_lock); 92 mutex_lock(&chrdevs_lock);
92 return get_next_chrdev(NULL); 93 return get_next_chrdev(NULL);
93} 94}
94 95
95void release_chrdev_list(void *dev) 96void release_chrdev_list(void *dev)
96{ 97{
97 up(&chrdevs_lock); 98 mutex_unlock(&chrdevs_lock);
98 kfree(dev); 99 kfree(dev);
99} 100}
100 101
@@ -151,7 +152,7 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
151 152
152 memset(cd, 0, sizeof(struct char_device_struct)); 153 memset(cd, 0, sizeof(struct char_device_struct));
153 154
154 down(&chrdevs_lock); 155 mutex_lock(&chrdevs_lock);
155 156
156 /* temporary */ 157 /* temporary */
157 if (major == 0) { 158 if (major == 0) {
@@ -186,10 +187,10 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
186 } 187 }
187 cd->next = *cp; 188 cd->next = *cp;
188 *cp = cd; 189 *cp = cd;
189 up(&chrdevs_lock); 190 mutex_unlock(&chrdevs_lock);
190 return cd; 191 return cd;
191out: 192out:
192 up(&chrdevs_lock); 193 mutex_unlock(&chrdevs_lock);
193 kfree(cd); 194 kfree(cd);
194 return ERR_PTR(ret); 195 return ERR_PTR(ret);
195} 196}
@@ -200,7 +201,7 @@ __unregister_chrdev_region(unsigned major, unsigned baseminor, int minorct)
200 struct char_device_struct *cd = NULL, **cp; 201 struct char_device_struct *cd = NULL, **cp;
201 int i = major_to_index(major); 202 int i = major_to_index(major);
202 203
203 down(&chrdevs_lock); 204 mutex_lock(&chrdevs_lock);
204 for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next) 205 for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next)
205 if ((*cp)->major == major && 206 if ((*cp)->major == major &&
206 (*cp)->baseminor == baseminor && 207 (*cp)->baseminor == baseminor &&
@@ -210,7 +211,7 @@ __unregister_chrdev_region(unsigned major, unsigned baseminor, int minorct)
210 cd = *cp; 211 cd = *cp;
211 *cp = cd->next; 212 *cp = cd->next;
212 } 213 }
213 up(&chrdevs_lock); 214 mutex_unlock(&chrdevs_lock);
214 return cd; 215 return cd;
215} 216}
216 217
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index d575452cd9f7..40c4fc973fad 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -251,3 +251,49 @@ struct dentry *debugfs_create_bool(const char *name, mode_t mode,
251} 251}
252EXPORT_SYMBOL_GPL(debugfs_create_bool); 252EXPORT_SYMBOL_GPL(debugfs_create_bool);
253 253
254static ssize_t read_file_blob(struct file *file, char __user *user_buf,
255 size_t count, loff_t *ppos)
256{
257 struct debugfs_blob_wrapper *blob = file->private_data;
258 return simple_read_from_buffer(user_buf, count, ppos, blob->data,
259 blob->size);
260}
261
262static struct file_operations fops_blob = {
263 .read = read_file_blob,
264 .open = default_open,
265};
266
267/**
268 * debugfs_create_blob - create a file in the debugfs filesystem that is
269 * used to read and write a binary blob.
270 *
271 * @name: a pointer to a string containing the name of the file to create.
272 * @mode: the permission that the file should have
273 * @parent: a pointer to the parent dentry for this file. This should be a
274 * directory dentry if set. If this paramater is NULL, then the
275 * file will be created in the root of the debugfs filesystem.
276 * @blob: a pointer to a struct debugfs_blob_wrapper which contains a pointer
277 * to the blob data and the size of the data.
278 *
279 * This function creates a file in debugfs with the given name that exports
280 * @blob->data as a binary blob. If the @mode variable is so set it can be
281 * read from. Writing is not supported.
282 *
283 * This function will return a pointer to a dentry if it succeeds. This
284 * pointer must be passed to the debugfs_remove() function when the file is
285 * to be removed (no automatic cleanup happens if your module is unloaded,
286 * you are responsible here.) If an error occurs, NULL will be returned.
287 *
288 * If debugfs is not enabled in the kernel, the value -ENODEV will be
289 * returned. It is not wise to check for this value, but rather, check for
290 * NULL or !NULL instead as to eliminate the need for #ifdef in the calling
291 * code.
292 */
293struct dentry *debugfs_create_blob(const char *name, mode_t mode,
294 struct dentry *parent,
295 struct debugfs_blob_wrapper *blob)
296{
297 return debugfs_create_file(name, mode, parent, blob, &fops_blob);
298}
299EXPORT_SYMBOL_GPL(debugfs_create_blob);
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 49bd219275db..9ee956864445 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -50,6 +50,32 @@ static struct sysfs_dirent * sysfs_new_dirent(struct sysfs_dirent * parent_sd,
50 return sd; 50 return sd;
51} 51}
52 52
53/**
54 *
55 * Return -EEXIST if there is already a sysfs element with the same name for
56 * the same parent.
57 *
58 * called with parent inode's i_mutex held
59 */
60int sysfs_dirent_exist(struct sysfs_dirent *parent_sd,
61 const unsigned char *new)
62{
63 struct sysfs_dirent * sd;
64
65 list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
66 if (sd->s_element) {
67 const unsigned char *existing = sysfs_get_name(sd);
68 if (strcmp(existing, new))
69 continue;
70 else
71 return -EEXIST;
72 }
73 }
74
75 return 0;
76}
77
78
53int sysfs_make_dirent(struct sysfs_dirent * parent_sd, struct dentry * dentry, 79int sysfs_make_dirent(struct sysfs_dirent * parent_sd, struct dentry * dentry,
54 void * element, umode_t mode, int type) 80 void * element, umode_t mode, int type)
55{ 81{
@@ -102,7 +128,11 @@ static int create_dir(struct kobject * k, struct dentry * p,
102 mutex_lock(&p->d_inode->i_mutex); 128 mutex_lock(&p->d_inode->i_mutex);
103 *d = lookup_one_len(n, p, strlen(n)); 129 *d = lookup_one_len(n, p, strlen(n));
104 if (!IS_ERR(*d)) { 130 if (!IS_ERR(*d)) {
105 error = sysfs_make_dirent(p->d_fsdata, *d, k, mode, SYSFS_DIR); 131 if (sysfs_dirent_exist(p->d_fsdata, n))
132 error = -EEXIST;
133 else
134 error = sysfs_make_dirent(p->d_fsdata, *d, k, mode,
135 SYSFS_DIR);
106 if (!error) { 136 if (!error) {
107 error = sysfs_create(*d, mode, init_dir); 137 error = sysfs_create(*d, mode, init_dir);
108 if (!error) { 138 if (!error) {
@@ -302,6 +332,7 @@ void sysfs_remove_dir(struct kobject * kobj)
302 * Drop reference from dget() on entrance. 332 * Drop reference from dget() on entrance.
303 */ 333 */
304 dput(dentry); 334 dput(dentry);
335 kobj->dentry = NULL;
305} 336}
306 337
307int sysfs_rename_dir(struct kobject * kobj, const char *new_name) 338int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
@@ -479,7 +510,3 @@ struct file_operations sysfs_dir_operations = {
479 .read = generic_read_dir, 510 .read = generic_read_dir,
480 .readdir = sysfs_readdir, 511 .readdir = sysfs_readdir,
481}; 512};
482
483EXPORT_SYMBOL_GPL(sysfs_create_dir);
484EXPORT_SYMBOL_GPL(sysfs_remove_dir);
485EXPORT_SYMBOL_GPL(sysfs_rename_dir);
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index d0e3d8495165..5e83e7246788 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -301,9 +301,8 @@ static int check_perm(struct inode * inode, struct file * file)
301 /* No error? Great, allocate a buffer for the file, and store it 301 /* No error? Great, allocate a buffer for the file, and store it
302 * it in file->private_data for easy access. 302 * it in file->private_data for easy access.
303 */ 303 */
304 buffer = kmalloc(sizeof(struct sysfs_buffer),GFP_KERNEL); 304 buffer = kzalloc(sizeof(struct sysfs_buffer), GFP_KERNEL);
305 if (buffer) { 305 if (buffer) {
306 memset(buffer,0,sizeof(struct sysfs_buffer));
307 init_MUTEX(&buffer->sem); 306 init_MUTEX(&buffer->sem);
308 buffer->needs_read_fill = 1; 307 buffer->needs_read_fill = 1;
309 buffer->ops = ops; 308 buffer->ops = ops;
@@ -362,10 +361,12 @@ int sysfs_add_file(struct dentry * dir, const struct attribute * attr, int type)
362{ 361{
363 struct sysfs_dirent * parent_sd = dir->d_fsdata; 362 struct sysfs_dirent * parent_sd = dir->d_fsdata;
364 umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; 363 umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG;
365 int error = 0; 364 int error = -EEXIST;
366 365
367 mutex_lock(&dir->d_inode->i_mutex); 366 mutex_lock(&dir->d_inode->i_mutex);
368 error = sysfs_make_dirent(parent_sd, NULL, (void *) attr, mode, type); 367 if (!sysfs_dirent_exist(parent_sd, attr->name))
368 error = sysfs_make_dirent(parent_sd, NULL, (void *)attr,
369 mode, type);
369 mutex_unlock(&dir->d_inode->i_mutex); 370 mutex_unlock(&dir->d_inode->i_mutex);
370 371
371 return error; 372 return error;
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 689f7bcfaf30..4c29ac41ac3e 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -54,11 +54,10 @@ int sysfs_setattr(struct dentry * dentry, struct iattr * iattr)
54 54
55 if (!sd_iattr) { 55 if (!sd_iattr) {
56 /* setting attributes for the first time, allocate now */ 56 /* setting attributes for the first time, allocate now */
57 sd_iattr = kmalloc(sizeof(struct iattr), GFP_KERNEL); 57 sd_iattr = kzalloc(sizeof(struct iattr), GFP_KERNEL);
58 if (!sd_iattr) 58 if (!sd_iattr)
59 return -ENOMEM; 59 return -ENOMEM;
60 /* assign default attributes */ 60 /* assign default attributes */
61 memset(sd_iattr, 0, sizeof(struct iattr));
62 sd_iattr->ia_mode = sd->s_mode; 61 sd_iattr->ia_mode = sd->s_mode;
63 sd_iattr->ia_uid = 0; 62 sd_iattr->ia_uid = 0;
64 sd_iattr->ia_gid = 0; 63 sd_iattr->ia_gid = 0;
@@ -227,12 +226,16 @@ void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
227void sysfs_hash_and_remove(struct dentry * dir, const char * name) 226void sysfs_hash_and_remove(struct dentry * dir, const char * name)
228{ 227{
229 struct sysfs_dirent * sd; 228 struct sysfs_dirent * sd;
230 struct sysfs_dirent * parent_sd = dir->d_fsdata; 229 struct sysfs_dirent * parent_sd;
230
231 if (!dir)
232 return;
231 233
232 if (dir->d_inode == NULL) 234 if (dir->d_inode == NULL)
233 /* no inode means this hasn't been made visible yet */ 235 /* no inode means this hasn't been made visible yet */
234 return; 236 return;
235 237
238 parent_sd = dir->d_fsdata;
236 mutex_lock(&dir->d_inode->i_mutex); 239 mutex_lock(&dir->d_inode->i_mutex);
237 list_for_each_entry(sd, &parent_sd->s_children, s_sibling) { 240 list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
238 if (!sd->s_element) 241 if (!sd->s_element)
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index e38d6338a20d..d2eac3ceed5f 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -66,6 +66,7 @@ static int sysfs_add_link(struct dentry * parent, const char * name, struct kobj
66 if (!error) 66 if (!error)
67 return 0; 67 return 0;
68 68
69 kobject_put(target);
69 kfree(sl->link_name); 70 kfree(sl->link_name);
70exit2: 71exit2:
71 kfree(sl); 72 kfree(sl);
@@ -82,12 +83,13 @@ exit1:
82int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name) 83int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name)
83{ 84{
84 struct dentry * dentry = kobj->dentry; 85 struct dentry * dentry = kobj->dentry;
85 int error = 0; 86 int error = -EEXIST;
86 87
87 BUG_ON(!kobj || !kobj->dentry || !name); 88 BUG_ON(!kobj || !kobj->dentry || !name);
88 89
89 mutex_lock(&dentry->d_inode->i_mutex); 90 mutex_lock(&dentry->d_inode->i_mutex);
90 error = sysfs_add_link(dentry, name, target); 91 if (!sysfs_dirent_exist(dentry->d_fsdata, name))
92 error = sysfs_add_link(dentry, name, target);
91 mutex_unlock(&dentry->d_inode->i_mutex); 93 mutex_unlock(&dentry->d_inode->i_mutex);
92 return error; 94 return error;
93} 95}
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 3f8953e0e5d0..cf11d5b789d9 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -5,6 +5,7 @@ extern kmem_cache_t *sysfs_dir_cachep;
5extern struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent *); 5extern struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent *);
6extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *)); 6extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *));
7 7
8extern int sysfs_dirent_exist(struct sysfs_dirent *, const unsigned char *);
8extern int sysfs_make_dirent(struct sysfs_dirent *, struct dentry *, void *, 9extern int sysfs_make_dirent(struct sysfs_dirent *, struct dentry *, void *,
9 umode_t, int); 10 umode_t, int);
10 11
diff --git a/include/asm-arm/irq.h b/include/asm-arm/irq.h
index 7772432d3fd7..60b5105c9c93 100644
--- a/include/asm-arm/irq.h
+++ b/include/asm-arm/irq.h
@@ -27,7 +27,7 @@ extern void enable_irq(unsigned int);
27 27
28/* 28/*
29 * These correspond with the SA_TRIGGER_* defines, and therefore the 29 * These correspond with the SA_TRIGGER_* defines, and therefore the
30 * IRQRESOURCE_IRQ_* defines. 30 * IORESOURCE_IRQ_* defines.
31 */ 31 */
32#define __IRQT_RISEDGE (1 << 0) 32#define __IRQT_RISEDGE (1 << 0)
33#define __IRQT_FALEDGE (1 << 1) 33#define __IRQT_FALEDGE (1 << 1)
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 35de20cf8fac..9d11550b4818 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -58,6 +58,13 @@
58 VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .; \ 58 VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .; \
59 } \ 59 } \
60 \ 60 \
61 /* Kernel symbol table: GPL-future-only symbols */ \
62 __ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \
63 VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .; \
64 *(__ksymtab_gpl_future) \
65 VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .; \
66 } \
67 \
61 /* Kernel symbol table: Normal symbols */ \ 68 /* Kernel symbol table: Normal symbols */ \
62 __kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \ 69 __kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \
63 VMLINUX_SYMBOL(__start___kcrctab) = .; \ 70 VMLINUX_SYMBOL(__start___kcrctab) = .; \
@@ -72,6 +79,13 @@
72 VMLINUX_SYMBOL(__stop___kcrctab_gpl) = .; \ 79 VMLINUX_SYMBOL(__stop___kcrctab_gpl) = .; \
73 } \ 80 } \
74 \ 81 \
82 /* Kernel symbol table: GPL-future-only symbols */ \
83 __kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \
84 VMLINUX_SYMBOL(__start___kcrctab_gpl_future) = .; \
85 *(__kcrctab_gpl_future) \
86 VMLINUX_SYMBOL(__stop___kcrctab_gpl_future) = .; \
87 } \
88 \
75 /* Kernel symbol table: strings */ \ 89 /* Kernel symbol table: strings */ \
76 __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \ 90 __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \
77 *(__ksymtab_strings) \ 91 *(__ksymtab_strings) \
diff --git a/include/asm-ia64/intel_intrin.h b/include/asm-ia64/intel_intrin.h
index a7122d850177..d069b6acddce 100644
--- a/include/asm-ia64/intel_intrin.h
+++ b/include/asm-ia64/intel_intrin.h
@@ -5,113 +5,10 @@
5 * 5 *
6 * Copyright (C) 2002,2003 Jun Nakajima <jun.nakajima@intel.com> 6 * Copyright (C) 2002,2003 Jun Nakajima <jun.nakajima@intel.com>
7 * Copyright (C) 2002,2003 Suresh Siddha <suresh.b.siddha@intel.com> 7 * Copyright (C) 2002,2003 Suresh Siddha <suresh.b.siddha@intel.com>
8 * Copyright (C) 2005,2006 Hongjiu Lu <hongjiu.lu@intel.com>
8 * 9 *
9 */ 10 */
10#include <asm/types.h> 11#include <ia64intrin.h>
11
12void __lfetch(int lfhint, void *y);
13void __lfetch_excl(int lfhint, void *y);
14void __lfetch_fault(int lfhint, void *y);
15void __lfetch_fault_excl(int lfhint, void *y);
16
17/* In the following, whichFloatReg should be an integer from 0-127 */
18void __ldfs(const int whichFloatReg, void *src);
19void __ldfd(const int whichFloatReg, void *src);
20void __ldfe(const int whichFloatReg, void *src);
21void __ldf8(const int whichFloatReg, void *src);
22void __ldf_fill(const int whichFloatReg, void *src);
23void __stfs(void *dst, const int whichFloatReg);
24void __stfd(void *dst, const int whichFloatReg);
25void __stfe(void *dst, const int whichFloatReg);
26void __stf8(void *dst, const int whichFloatReg);
27void __stf_spill(void *dst, const int whichFloatReg);
28
29void __st1_rel(void *dst, const __s8 value);
30void __st2_rel(void *dst, const __s16 value);
31void __st4_rel(void *dst, const __s32 value);
32void __st8_rel(void *dst, const __s64 value);
33__u8 __ld1_acq(void *src);
34__u16 __ld2_acq(void *src);
35__u32 __ld4_acq(void *src);
36__u64 __ld8_acq(void *src);
37
38__u64 __fetchadd4_acq(__u32 *addend, const int increment);
39__u64 __fetchadd4_rel(__u32 *addend, const int increment);
40__u64 __fetchadd8_acq(__u64 *addend, const int increment);
41__u64 __fetchadd8_rel(__u64 *addend, const int increment);
42
43__u64 __getf_exp(double d);
44
45/* OS Related Itanium(R) Intrinsics */
46
47/* The names to use for whichReg and whichIndReg below come from
48 the include file asm/ia64regs.h */
49
50__u64 __getIndReg(const int whichIndReg, __s64 index);
51__u64 __getReg(const int whichReg);
52
53void __setIndReg(const int whichIndReg, __s64 index, __u64 value);
54void __setReg(const int whichReg, __u64 value);
55
56void __mf(void);
57void __mfa(void);
58void __synci(void);
59void __itcd(__s64 pa);
60void __itci(__s64 pa);
61void __itrd(__s64 whichTransReg, __s64 pa);
62void __itri(__s64 whichTransReg, __s64 pa);
63void __ptce(__s64 va);
64void __ptcl(__s64 va, __s64 pagesz);
65void __ptcg(__s64 va, __s64 pagesz);
66void __ptcga(__s64 va, __s64 pagesz);
67void __ptri(__s64 va, __s64 pagesz);
68void __ptrd(__s64 va, __s64 pagesz);
69void __invala (void);
70void __invala_gr(const int whichGeneralReg /* 0-127 */ );
71void __invala_fr(const int whichFloatReg /* 0-127 */ );
72void __nop(const int);
73void __fc(__u64 *addr);
74void __sum(int mask);
75void __rum(int mask);
76void __ssm(int mask);
77void __rsm(int mask);
78__u64 __thash(__s64);
79__u64 __ttag(__s64);
80__s64 __tpa(__s64);
81
82/* Intrinsics for implementing get/put_user macros */
83void __st_user(const char *tableName, __u64 addr, char size, char relocType, __u64 val);
84void __ld_user(const char *tableName, __u64 addr, char size, char relocType);
85
86/* This intrinsic does not generate code, it creates a barrier across which
87 * the compiler will not schedule data access instructions.
88 */
89void __memory_barrier(void);
90
91void __isrlz(void);
92void __dsrlz(void);
93
94__u64 _m64_mux1(__u64 a, const int n);
95__u64 __thash(__u64);
96
97/* Lock and Atomic Operation Related Intrinsics */
98__u64 _InterlockedExchange8(volatile __u8 *trgt, __u8 value);
99__u64 _InterlockedExchange16(volatile __u16 *trgt, __u16 value);
100__s64 _InterlockedExchange(volatile __u32 *trgt, __u32 value);
101__s64 _InterlockedExchange64(volatile __u64 *trgt, __u64 value);
102
103__u64 _InterlockedCompareExchange8_rel(volatile __u8 *dest, __u64 xchg, __u64 comp);
104__u64 _InterlockedCompareExchange8_acq(volatile __u8 *dest, __u64 xchg, __u64 comp);
105__u64 _InterlockedCompareExchange16_rel(volatile __u16 *dest, __u64 xchg, __u64 comp);
106__u64 _InterlockedCompareExchange16_acq(volatile __u16 *dest, __u64 xchg, __u64 comp);
107__u64 _InterlockedCompareExchange_rel(volatile __u32 *dest, __u64 xchg, __u64 comp);
108__u64 _InterlockedCompareExchange_acq(volatile __u32 *dest, __u64 xchg, __u64 comp);
109__u64 _InterlockedCompareExchange64_rel(volatile __u64 *dest, __u64 xchg, __u64 comp);
110__u64 _InterlockedCompareExchange64_acq(volatile __u64 *dest, __u64 xchg, __u64 comp);
111
112__s64 _m64_dep_mi(const int v, __s64 s, const int p, const int len);
113__s64 _m64_shrp(__s64 a, __s64 b, const int count);
114__s64 _m64_popcnt(__s64 a);
115 12
116#define ia64_barrier() __memory_barrier() 13#define ia64_barrier() __memory_barrier()
117 14
@@ -122,15 +19,16 @@ __s64 _m64_popcnt(__s64 a);
122#define ia64_getreg __getReg 19#define ia64_getreg __getReg
123#define ia64_setreg __setReg 20#define ia64_setreg __setReg
124 21
125#define ia64_hint(x) 22#define ia64_hint __hint
23#define ia64_hint_pause __hint_pause
126 24
127#define ia64_mux1_brcst 0 25#define ia64_mux1_brcst _m64_mux1_brcst
128#define ia64_mux1_mix 8 26#define ia64_mux1_mix _m64_mux1_mix
129#define ia64_mux1_shuf 9 27#define ia64_mux1_shuf _m64_mux1_shuf
130#define ia64_mux1_alt 10 28#define ia64_mux1_alt _m64_mux1_alt
131#define ia64_mux1_rev 11 29#define ia64_mux1_rev _m64_mux1_rev
132 30
133#define ia64_mux1 _m64_mux1 31#define ia64_mux1(x,v) _m_to_int64(_m64_mux1(_m_from_int64(x), (v)))
134#define ia64_popcnt _m64_popcnt 32#define ia64_popcnt _m64_popcnt
135#define ia64_getf_exp __getf_exp 33#define ia64_getf_exp __getf_exp
136#define ia64_shrp _m64_shrp 34#define ia64_shrp _m64_shrp
@@ -158,7 +56,7 @@ __s64 _m64_popcnt(__s64 a);
158#define ia64_stf8 __stf8 56#define ia64_stf8 __stf8
159#define ia64_stf_spill __stf_spill 57#define ia64_stf_spill __stf_spill
160 58
161#define ia64_mf __mf 59#define ia64_mf __mf
162#define ia64_mfa __mfa 60#define ia64_mfa __mfa
163 61
164#define ia64_fetchadd4_acq __fetchadd4_acq 62#define ia64_fetchadd4_acq __fetchadd4_acq
@@ -234,10 +132,10 @@ __s64 _m64_popcnt(__s64 a);
234 132
235/* Values for lfhint in __lfetch and __lfetch_fault */ 133/* Values for lfhint in __lfetch and __lfetch_fault */
236 134
237#define ia64_lfhint_none 0 135#define ia64_lfhint_none __lfhint_none
238#define ia64_lfhint_nt1 1 136#define ia64_lfhint_nt1 __lfhint_nt1
239#define ia64_lfhint_nt2 2 137#define ia64_lfhint_nt2 __lfhint_nt2
240#define ia64_lfhint_nta 3 138#define ia64_lfhint_nta __lfhint_nta
241 139
242#define ia64_lfetch __lfetch 140#define ia64_lfetch __lfetch
243#define ia64_lfetch_excl __lfetch_excl 141#define ia64_lfetch_excl __lfetch_excl
@@ -254,4 +152,6 @@ do { \
254 } \ 152 } \
255} while (0) 153} while (0)
256 154
155#define __builtin_trap() __break(0);
156
257#endif /* _ASM_IA64_INTEL_INTRIN_H */ 157#endif /* _ASM_IA64_INTEL_INTRIN_H */
diff --git a/include/asm-ia64/machvec.h b/include/asm-ia64/machvec.h
index ca5ea994d688..c3e4ed8a3e17 100644
--- a/include/asm-ia64/machvec.h
+++ b/include/asm-ia64/machvec.h
@@ -20,6 +20,7 @@ struct scatterlist;
20struct page; 20struct page;
21struct mm_struct; 21struct mm_struct;
22struct pci_bus; 22struct pci_bus;
23struct task_struct;
23 24
24typedef void ia64_mv_setup_t (char **); 25typedef void ia64_mv_setup_t (char **);
25typedef void ia64_mv_cpu_init_t (void); 26typedef void ia64_mv_cpu_init_t (void);
@@ -34,6 +35,7 @@ typedef int ia64_mv_pci_legacy_read_t (struct pci_bus *, u16 port, u32 *val,
34 u8 size); 35 u8 size);
35typedef int ia64_mv_pci_legacy_write_t (struct pci_bus *, u16 port, u32 val, 36typedef int ia64_mv_pci_legacy_write_t (struct pci_bus *, u16 port, u32 val,
36 u8 size); 37 u8 size);
38typedef void ia64_mv_migrate_t(struct task_struct * task);
37 39
38/* DMA-mapping interface: */ 40/* DMA-mapping interface: */
39typedef void ia64_mv_dma_init (void); 41typedef void ia64_mv_dma_init (void);
@@ -85,6 +87,11 @@ machvec_noop_mm (struct mm_struct *mm)
85{ 87{
86} 88}
87 89
90static inline void
91machvec_noop_task (struct task_struct *task)
92{
93}
94
88extern void machvec_setup (char **); 95extern void machvec_setup (char **);
89extern void machvec_timer_interrupt (int, void *, struct pt_regs *); 96extern void machvec_timer_interrupt (int, void *, struct pt_regs *);
90extern void machvec_dma_sync_single (struct device *, dma_addr_t, size_t, int); 97extern void machvec_dma_sync_single (struct device *, dma_addr_t, size_t, int);
@@ -146,6 +153,7 @@ extern void machvec_tlb_migrate_finish (struct mm_struct *);
146# define platform_readw_relaxed ia64_mv.readw_relaxed 153# define platform_readw_relaxed ia64_mv.readw_relaxed
147# define platform_readl_relaxed ia64_mv.readl_relaxed 154# define platform_readl_relaxed ia64_mv.readl_relaxed
148# define platform_readq_relaxed ia64_mv.readq_relaxed 155# define platform_readq_relaxed ia64_mv.readq_relaxed
156# define platform_migrate ia64_mv.migrate
149# endif 157# endif
150 158
151/* __attribute__((__aligned__(16))) is required to make size of the 159/* __attribute__((__aligned__(16))) is required to make size of the
@@ -194,6 +202,7 @@ struct ia64_machine_vector {
194 ia64_mv_readw_relaxed_t *readw_relaxed; 202 ia64_mv_readw_relaxed_t *readw_relaxed;
195 ia64_mv_readl_relaxed_t *readl_relaxed; 203 ia64_mv_readl_relaxed_t *readl_relaxed;
196 ia64_mv_readq_relaxed_t *readq_relaxed; 204 ia64_mv_readq_relaxed_t *readq_relaxed;
205 ia64_mv_migrate_t *migrate;
197} __attribute__((__aligned__(16))); /* align attrib? see above comment */ 206} __attribute__((__aligned__(16))); /* align attrib? see above comment */
198 207
199#define MACHVEC_INIT(name) \ 208#define MACHVEC_INIT(name) \
@@ -238,6 +247,7 @@ struct ia64_machine_vector {
238 platform_readw_relaxed, \ 247 platform_readw_relaxed, \
239 platform_readl_relaxed, \ 248 platform_readl_relaxed, \
240 platform_readq_relaxed, \ 249 platform_readq_relaxed, \
250 platform_migrate, \
241} 251}
242 252
243extern struct ia64_machine_vector ia64_mv; 253extern struct ia64_machine_vector ia64_mv;
@@ -386,5 +396,8 @@ extern ia64_mv_dma_supported swiotlb_dma_supported;
386#ifndef platform_readq_relaxed 396#ifndef platform_readq_relaxed
387# define platform_readq_relaxed __ia64_readq_relaxed 397# define platform_readq_relaxed __ia64_readq_relaxed
388#endif 398#endif
399#ifndef platform_migrate
400# define platform_migrate machvec_noop_task
401#endif
389 402
390#endif /* _ASM_IA64_MACHVEC_H */ 403#endif /* _ASM_IA64_MACHVEC_H */
diff --git a/include/asm-ia64/machvec_sn2.h b/include/asm-ia64/machvec_sn2.h
index 03d00faf03b5..da1d43755afe 100644
--- a/include/asm-ia64/machvec_sn2.h
+++ b/include/asm-ia64/machvec_sn2.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2002-2003, 2006 Silicon Graphics, Inc. All Rights Reserved. 2 * Copyright (c) 2002-2003,2006 Silicon Graphics, Inc. All Rights Reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License 5 * under the terms of version 2 of the GNU General Public License
@@ -66,6 +66,7 @@ extern ia64_mv_dma_sync_single_for_device sn_dma_sync_single_for_device;
66extern ia64_mv_dma_sync_sg_for_device sn_dma_sync_sg_for_device; 66extern ia64_mv_dma_sync_sg_for_device sn_dma_sync_sg_for_device;
67extern ia64_mv_dma_mapping_error sn_dma_mapping_error; 67extern ia64_mv_dma_mapping_error sn_dma_mapping_error;
68extern ia64_mv_dma_supported sn_dma_supported; 68extern ia64_mv_dma_supported sn_dma_supported;
69extern ia64_mv_migrate_t sn_migrate;
69 70
70/* 71/*
71 * This stuff has dual use! 72 * This stuff has dual use!
@@ -115,6 +116,7 @@ extern ia64_mv_dma_supported sn_dma_supported;
115#define platform_dma_sync_sg_for_device sn_dma_sync_sg_for_device 116#define platform_dma_sync_sg_for_device sn_dma_sync_sg_for_device
116#define platform_dma_mapping_error sn_dma_mapping_error 117#define platform_dma_mapping_error sn_dma_mapping_error
117#define platform_dma_supported sn_dma_supported 118#define platform_dma_supported sn_dma_supported
119#define platform_migrate sn_migrate
118 120
119#include <asm/sn/io.h> 121#include <asm/sn/io.h>
120 122
diff --git a/include/asm-ia64/mca.h b/include/asm-ia64/mca.h
index c7d9c9ed38ba..bfbbb8da79c7 100644
--- a/include/asm-ia64/mca.h
+++ b/include/asm-ia64/mca.h
@@ -131,6 +131,8 @@ struct ia64_mca_cpu {
131/* Array of physical addresses of each CPU's MCA area. */ 131/* Array of physical addresses of each CPU's MCA area. */
132extern unsigned long __per_cpu_mca[NR_CPUS]; 132extern unsigned long __per_cpu_mca[NR_CPUS];
133 133
134extern int cpe_vector;
135extern int ia64_cpe_irq;
134extern void ia64_mca_init(void); 136extern void ia64_mca_init(void);
135extern void ia64_mca_cpu_init(void *); 137extern void ia64_mca_cpu_init(void *);
136extern void ia64_os_mca_dispatch(void); 138extern void ia64_os_mca_dispatch(void);
diff --git a/include/asm-ia64/mutex.h b/include/asm-ia64/mutex.h
index 458c1f7fbc18..5a3224f6af38 100644
--- a/include/asm-ia64/mutex.h
+++ b/include/asm-ia64/mutex.h
@@ -1,9 +1,92 @@
1/* 1/*
2 * Pull in the generic implementation for the mutex fastpath. 2 * ia64 implementation of the mutex fastpath.
3 * 3 *
4 * TODO: implement optimized primitives instead, or leave the generic 4 * Copyright (C) 2006 Ken Chen <kenneth.w.chen@intel.com>
5 * implementation in place, or pick the atomic_xchg() based generic 5 *
6 * implementation. (see asm-generic/mutex-xchg.h for details) 6 */
7
8#ifndef _ASM_MUTEX_H
9#define _ASM_MUTEX_H
10
11/**
12 * __mutex_fastpath_lock - try to take the lock by moving the count
13 * from 1 to a 0 value
14 * @count: pointer of type atomic_t
15 * @fail_fn: function to call if the original value was not 1
16 *
17 * Change the count from 1 to a value lower than 1, and call <fail_fn> if
18 * it wasn't 1 originally. This function MUST leave the value lower than
19 * 1 even when the "1" assertion wasn't true.
20 */
21static inline void
22__mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
23{
24 if (unlikely(ia64_fetchadd4_acq(count, -1) != 1))
25 fail_fn(count);
26}
27
28/**
29 * __mutex_fastpath_lock_retval - try to take the lock by moving the count
30 * from 1 to a 0 value
31 * @count: pointer of type atomic_t
32 * @fail_fn: function to call if the original value was not 1
33 *
34 * Change the count from 1 to a value lower than 1, and call <fail_fn> if
35 * it wasn't 1 originally. This function returns 0 if the fastpath succeeds,
36 * or anything the slow path function returns.
37 */
38static inline int
39__mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
40{
41 if (unlikely(ia64_fetchadd4_acq(count, -1) != 1))
42 return fail_fn(count);
43 return 0;
44}
45
46/**
47 * __mutex_fastpath_unlock - try to promote the count from 0 to 1
48 * @count: pointer of type atomic_t
49 * @fail_fn: function to call if the original value was not 0
50 *
51 * Try to promote the count from 0 to 1. If it wasn't 0, call <fail_fn>.
52 * In the failure case, this function is allowed to either set the value to
53 * 1, or to set it to a value lower than 1.
54 *
55 * If the implementation sets it to a value of lower than 1, then the
56 * __mutex_slowpath_needs_to_unlock() macro needs to return 1, it needs
57 * to return 0 otherwise.
58 */
59static inline void
60__mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
61{
62 int ret = ia64_fetchadd4_rel(count, 1);
63 if (unlikely(ret < 0))
64 fail_fn(count);
65}
66
67#define __mutex_slowpath_needs_to_unlock() 1
68
69/**
70 * __mutex_fastpath_trylock - try to acquire the mutex, without waiting
71 *
72 * @count: pointer of type atomic_t
73 * @fail_fn: fallback function
74 *
75 * Change the count from 1 to a value lower than 1, and return 0 (failure)
76 * if it wasn't 1 originally, or return 1 (success) otherwise. This function
77 * MUST leave the value lower than 1 even when the "1" assertion wasn't true.
78 * Additionally, if the value was < 0 originally, this function must not leave
79 * it to 0 on failure.
80 *
81 * If the architecture has no effective trylock variant, it should call the
82 * <fail_fn> spinlock-based trylock variant unconditionally.
7 */ 83 */
84static inline int
85__mutex_fastpath_trylock(atomic_t *count, int (*fail_fn)(atomic_t *))
86{
87 if (likely(cmpxchg_acq(count, 1, 0)) == 1)
88 return 1;
89 return 0;
90}
8 91
9#include <asm-generic/mutex-dec.h> 92#endif
diff --git a/include/asm-ia64/processor.h b/include/asm-ia64/processor.h
index 23c8e1be1911..128fefd8056f 100644
--- a/include/asm-ia64/processor.h
+++ b/include/asm-ia64/processor.h
@@ -50,7 +50,8 @@
50#define IA64_THREAD_PM_VALID (__IA64_UL(1) << 2) /* performance registers valid? */ 50#define IA64_THREAD_PM_VALID (__IA64_UL(1) << 2) /* performance registers valid? */
51#define IA64_THREAD_UAC_NOPRINT (__IA64_UL(1) << 3) /* don't log unaligned accesses */ 51#define IA64_THREAD_UAC_NOPRINT (__IA64_UL(1) << 3) /* don't log unaligned accesses */
52#define IA64_THREAD_UAC_SIGBUS (__IA64_UL(1) << 4) /* generate SIGBUS on unaligned acc. */ 52#define IA64_THREAD_UAC_SIGBUS (__IA64_UL(1) << 4) /* generate SIGBUS on unaligned acc. */
53 /* bit 5 is currently unused */ 53#define IA64_THREAD_MIGRATION (__IA64_UL(1) << 5) /* require migration
54 sync at ctx sw */
54#define IA64_THREAD_FPEMU_NOPRINT (__IA64_UL(1) << 6) /* don't log any fpswa faults */ 55#define IA64_THREAD_FPEMU_NOPRINT (__IA64_UL(1) << 6) /* don't log any fpswa faults */
55#define IA64_THREAD_FPEMU_SIGFPE (__IA64_UL(1) << 7) /* send a SIGFPE for fpswa faults */ 56#define IA64_THREAD_FPEMU_SIGFPE (__IA64_UL(1) << 7) /* send a SIGFPE for fpswa faults */
56 57
diff --git a/include/asm-ia64/signal.h b/include/asm-ia64/signal.h
index 608168d713d3..5e328ed5d01d 100644
--- a/include/asm-ia64/signal.h
+++ b/include/asm-ia64/signal.h
@@ -158,8 +158,6 @@ struct k_sigaction {
158 158
159#define ptrace_signal_deliver(regs, cookie) do { } while (0) 159#define ptrace_signal_deliver(regs, cookie) do { } while (0)
160 160
161void set_sigdelayed(pid_t pid, int signo, int code, void __user *addr);
162
163#endif /* __KERNEL__ */ 161#endif /* __KERNEL__ */
164 162
165# endif /* !__ASSEMBLY__ */ 163# endif /* !__ASSEMBLY__ */
diff --git a/include/asm-ia64/sn/addrs.h b/include/asm-ia64/sn/addrs.h
index 2c32e4b77b54..1d9efe541662 100644
--- a/include/asm-ia64/sn/addrs.h
+++ b/include/asm-ia64/sn/addrs.h
@@ -283,5 +283,13 @@
283#define REMOTE_HUB_L(n, a) HUB_L(REMOTE_HUB_ADDR((n), (a))) 283#define REMOTE_HUB_L(n, a) HUB_L(REMOTE_HUB_ADDR((n), (a)))
284#define REMOTE_HUB_S(n, a, d) HUB_S(REMOTE_HUB_ADDR((n), (a)), (d)) 284#define REMOTE_HUB_S(n, a, d) HUB_S(REMOTE_HUB_ADDR((n), (a)), (d))
285 285
286/*
287 * Coretalk address breakdown
288 */
289#define CTALK_NASID_SHFT 40
290#define CTALK_NASID_MASK (0x3FFFULL << CTALK_NASID_SHFT)
291#define CTALK_CID_SHFT 38
292#define CTALK_CID_MASK (0x3ULL << CTALK_CID_SHFT)
293#define CTALK_NODE_OFFSET 0x3FFFFFFFFF
286 294
287#endif /* _ASM_IA64_SN_ADDRS_H */ 295#endif /* _ASM_IA64_SN_ADDRS_H */
diff --git a/include/asm-ia64/sn/rw_mmr.h b/include/asm-ia64/sn/rw_mmr.h
index f40fd1a5510d..2d78f4c5a45e 100644
--- a/include/asm-ia64/sn/rw_mmr.h
+++ b/include/asm-ia64/sn/rw_mmr.h
@@ -3,15 +3,14 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (C) 2002-2004 Silicon Graphics, Inc. All Rights Reserved. 6 * Copyright (C) 2002-2006 Silicon Graphics, Inc. All Rights Reserved.
7 */ 7 */
8#ifndef _ASM_IA64_SN_RW_MMR_H 8#ifndef _ASM_IA64_SN_RW_MMR_H
9#define _ASM_IA64_SN_RW_MMR_H 9#define _ASM_IA64_SN_RW_MMR_H
10 10
11 11
12/* 12/*
13 * This file contains macros used to access MMR registers via 13 * This file that access MMRs via uncached physical addresses.
14 * uncached physical addresses.
15 * pio_phys_read_mmr - read an MMR 14 * pio_phys_read_mmr - read an MMR
16 * pio_phys_write_mmr - write an MMR 15 * pio_phys_write_mmr - write an MMR
17 * pio_atomic_phys_write_mmrs - atomically write 1 or 2 MMRs with psr.ic=0 16 * pio_atomic_phys_write_mmrs - atomically write 1 or 2 MMRs with psr.ic=0
@@ -22,53 +21,8 @@
22 */ 21 */
23 22
24 23
25extern inline long 24extern long pio_phys_read_mmr(volatile long *mmr);
26pio_phys_read_mmr(volatile long *mmr) 25extern void pio_phys_write_mmr(volatile long *mmr, long val);
27{ 26extern void pio_atomic_phys_write_mmrs(volatile long *mmr1, long val1, volatile long *mmr2, long val2);
28 long val;
29 asm volatile
30 ("mov r2=psr;;"
31 "rsm psr.i | psr.dt;;"
32 "srlz.i;;"
33 "ld8.acq %0=[%1];;"
34 "mov psr.l=r2;;"
35 "srlz.i;;"
36 : "=r"(val)
37 : "r"(mmr)
38 : "r2");
39 return val;
40}
41
42
43
44extern inline void
45pio_phys_write_mmr(volatile long *mmr, long val)
46{
47 asm volatile
48 ("mov r2=psr;;"
49 "rsm psr.i | psr.dt;;"
50 "srlz.i;;"
51 "st8.rel [%0]=%1;;"
52 "mov psr.l=r2;;"
53 "srlz.i;;"
54 :: "r"(mmr), "r"(val)
55 : "r2", "memory");
56}
57
58extern inline void
59pio_atomic_phys_write_mmrs(volatile long *mmr1, long val1, volatile long *mmr2, long val2)
60{
61 asm volatile
62 ("mov r2=psr;;"
63 "rsm psr.i | psr.dt | psr.ic;;"
64 "cmp.ne p9,p0=%2,r0;"
65 "srlz.i;;"
66 "st8.rel [%0]=%1;"
67 "(p9) st8.rel [%2]=%3;;"
68 "mov psr.l=r2;;"
69 "srlz.i;;"
70 :: "r"(mmr1), "r"(val1), "r"(mmr2), "r"(val2)
71 : "p9", "r2", "memory");
72}
73 27
74#endif /* _ASM_IA64_SN_RW_MMR_H */ 28#endif /* _ASM_IA64_SN_RW_MMR_H */
diff --git a/include/asm-ia64/sn/tioce.h b/include/asm-ia64/sn/tioce.h
index d4c990712eac..893468e1b41b 100644
--- a/include/asm-ia64/sn/tioce.h
+++ b/include/asm-ia64/sn/tioce.h
@@ -11,7 +11,7 @@
11 11
12/* CE ASIC part & mfgr information */ 12/* CE ASIC part & mfgr information */
13#define TIOCE_PART_NUM 0xCE00 13#define TIOCE_PART_NUM 0xCE00
14#define TIOCE_MFGR_NUM 0x36 14#define TIOCE_SRC_ID 0x01
15#define TIOCE_REV_A 0x1 15#define TIOCE_REV_A 0x1
16 16
17/* CE Virtual PPB Vendor/Device IDs */ 17/* CE Virtual PPB Vendor/Device IDs */
@@ -20,7 +20,7 @@
20 20
21/* CE Host Bridge Vendor/Device IDs */ 21/* CE Host Bridge Vendor/Device IDs */
22#define CE_HOST_BRIDGE_VENDOR_ID 0x10a9 22#define CE_HOST_BRIDGE_VENDOR_ID 0x10a9
23#define CE_HOST_BRIDGE_DEVICE_ID 0x4003 23#define CE_HOST_BRIDGE_DEVICE_ID 0x4001
24 24
25 25
26#define TIOCE_NUM_M40_ATES 4096 26#define TIOCE_NUM_M40_ATES 4096
@@ -463,6 +463,25 @@ typedef volatile struct tioce {
463 u64 ce_end_of_struct; /* 0x044400 */ 463 u64 ce_end_of_struct; /* 0x044400 */
464} tioce_t; 464} tioce_t;
465 465
466/* ce_lsiX_gb_cfg1 register bit masks & shifts */
467#define CE_LSI_GB_CFG1_RXL0S_THS_SHFT 0
468#define CE_LSI_GB_CFG1_RXL0S_THS_MASK (0xffULL << 0)
469#define CE_LSI_GB_CFG1_RXL0S_SMP_SHFT 8
470#define CE_LSI_GB_CFG1_RXL0S_SMP_MASK (0xfULL << 8);
471#define CE_LSI_GB_CFG1_RXL0S_ADJ_SHFT 12
472#define CE_LSI_GB_CFG1_RXL0S_ADJ_MASK (0x7ULL << 12)
473#define CE_LSI_GB_CFG1_RXL0S_FLT_SHFT 15
474#define CE_LSI_GB_CFG1_RXL0S_FLT_MASK (0x1ULL << 15)
475#define CE_LSI_GB_CFG1_LPBK_SEL_SHFT 16
476#define CE_LSI_GB_CFG1_LPBK_SEL_MASK (0x3ULL << 16)
477#define CE_LSI_GB_CFG1_LPBK_EN_SHFT 18
478#define CE_LSI_GB_CFG1_LPBK_EN_MASK (0x1ULL << 18)
479#define CE_LSI_GB_CFG1_RVRS_LB_SHFT 19
480#define CE_LSI_GB_CFG1_RVRS_LB_MASK (0x1ULL << 19)
481#define CE_LSI_GB_CFG1_RVRS_CLK_SHFT 20
482#define CE_LSI_GB_CFG1_RVRS_CLK_MASK (0x3ULL << 20)
483#define CE_LSI_GB_CFG1_SLF_TS_SHFT 24
484#define CE_LSI_GB_CFG1_SLF_TS_MASK (0xfULL << 24)
466 485
467/* ce_adm_int_mask/ce_adm_int_status register bit defines */ 486/* ce_adm_int_mask/ce_adm_int_status register bit defines */
468#define CE_ADM_INT_CE_ERROR_SHFT 0 487#define CE_ADM_INT_CE_ERROR_SHFT 0
@@ -592,6 +611,11 @@ typedef volatile struct tioce {
592#define CE_URE_RD_MRG_ENABLE (0x1ULL << 0) 611#define CE_URE_RD_MRG_ENABLE (0x1ULL << 0)
593#define CE_URE_WRT_MRG_ENABLE1 (0x1ULL << 4) 612#define CE_URE_WRT_MRG_ENABLE1 (0x1ULL << 4)
594#define CE_URE_WRT_MRG_ENABLE2 (0x1ULL << 5) 613#define CE_URE_WRT_MRG_ENABLE2 (0x1ULL << 5)
614#define CE_URE_WRT_MRG_TIMER_SHFT 12
615#define CE_URE_WRT_MRG_TIMER_MASK (0x7FFULL << CE_URE_WRT_MRG_TIMER_SHFT)
616#define CE_URE_WRT_MRG_TIMER(x) (((u64)(x) << \
617 CE_URE_WRT_MRG_TIMER_SHFT) & \
618 CE_URE_WRT_MRG_TIMER_MASK)
595#define CE_URE_RSPQ_BYPASS_DISABLE (0x1ULL << 24) 619#define CE_URE_RSPQ_BYPASS_DISABLE (0x1ULL << 24)
596#define CE_URE_UPS_DAT1_PAR_DISABLE (0x1ULL << 32) 620#define CE_URE_UPS_DAT1_PAR_DISABLE (0x1ULL << 32)
597#define CE_URE_UPS_HDR1_PAR_DISABLE (0x1ULL << 33) 621#define CE_URE_UPS_HDR1_PAR_DISABLE (0x1ULL << 33)
@@ -653,8 +677,12 @@ typedef volatile struct tioce {
653#define CE_URE_SI (0x1ULL << 0) 677#define CE_URE_SI (0x1ULL << 0)
654#define CE_URE_ELAL_SHFT 4 678#define CE_URE_ELAL_SHFT 4
655#define CE_URE_ELAL_MASK (0x7ULL << CE_URE_ELAL_SHFT) 679#define CE_URE_ELAL_MASK (0x7ULL << CE_URE_ELAL_SHFT)
680#define CE_URE_ELAL_SET(n) (((u64)(n) << CE_URE_ELAL_SHFT) & \
681 CE_URE_ELAL_MASK)
656#define CE_URE_ELAL1_SHFT 8 682#define CE_URE_ELAL1_SHFT 8
657#define CE_URE_ELAL1_MASK (0x7ULL << CE_URE_ELAL1_SHFT) 683#define CE_URE_ELAL1_MASK (0x7ULL << CE_URE_ELAL1_SHFT)
684#define CE_URE_ELAL1_SET(n) (((u64)(n) << CE_URE_ELAL1_SHFT) & \
685 CE_URE_ELAL1_MASK)
658#define CE_URE_SCC (0x1ULL << 12) 686#define CE_URE_SCC (0x1ULL << 12)
659#define CE_URE_PN1_SHFT 16 687#define CE_URE_PN1_SHFT 16
660#define CE_URE_PN1_MASK (0xFFULL << CE_URE_PN1_SHFT) 688#define CE_URE_PN1_MASK (0xFFULL << CE_URE_PN1_SHFT)
@@ -675,8 +703,12 @@ typedef volatile struct tioce {
675#define CE_URE_HPC (0x1ULL << 6) 703#define CE_URE_HPC (0x1ULL << 6)
676#define CE_URE_SPLV_SHFT 7 704#define CE_URE_SPLV_SHFT 7
677#define CE_URE_SPLV_MASK (0xFFULL << CE_URE_SPLV_SHFT) 705#define CE_URE_SPLV_MASK (0xFFULL << CE_URE_SPLV_SHFT)
706#define CE_URE_SPLV_SET(n) (((u64)(n) << CE_URE_SPLV_SHFT) & \
707 CE_URE_SPLV_MASK)
678#define CE_URE_SPLS_SHFT 15 708#define CE_URE_SPLS_SHFT 15
679#define CE_URE_SPLS_MASK (0x3ULL << CE_URE_SPLS_SHFT) 709#define CE_URE_SPLS_MASK (0x3ULL << CE_URE_SPLS_SHFT)
710#define CE_URE_SPLS_SET(n) (((u64)(n) << CE_URE_SPLS_SHFT) & \
711 CE_URE_SPLS_MASK)
680#define CE_URE_PSN1_SHFT 19 712#define CE_URE_PSN1_SHFT 19
681#define CE_URE_PSN1_MASK (0x1FFFULL << CE_URE_PSN1_SHFT) 713#define CE_URE_PSN1_MASK (0x1FFFULL << CE_URE_PSN1_SHFT)
682#define CE_URE_PSN2_SHFT 32 714#define CE_URE_PSN2_SHFT 32
diff --git a/include/asm-ia64/sn/xpc.h b/include/asm-ia64/sn/xpc.h
index df7f5f4f3cde..aa3b8ace9030 100644
--- a/include/asm-ia64/sn/xpc.h
+++ b/include/asm-ia64/sn/xpc.h
@@ -1227,28 +1227,6 @@ xpc_map_bte_errors(bte_result_t error)
1227 1227
1228 1228
1229 1229
1230static inline void *
1231xpc_kmalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
1232{
1233 /* see if kmalloc will give us cachline aligned memory by default */
1234 *base = kmalloc(size, flags);
1235 if (*base == NULL) {
1236 return NULL;
1237 }
1238 if ((u64) *base == L1_CACHE_ALIGN((u64) *base)) {
1239 return *base;
1240 }
1241 kfree(*base);
1242
1243 /* nope, we'll have to do it ourselves */
1244 *base = kmalloc(size + L1_CACHE_BYTES, flags);
1245 if (*base == NULL) {
1246 return NULL;
1247 }
1248 return (void *) L1_CACHE_ALIGN((u64) *base);
1249}
1250
1251
1252/* 1230/*
1253 * Check to see if there is any channel activity to/from the specified 1231 * Check to see if there is any channel activity to/from the specified
1254 * partition. 1232 * partition.
diff --git a/include/asm-ia64/system.h b/include/asm-ia64/system.h
index 062538715623..cd4233d66f15 100644
--- a/include/asm-ia64/system.h
+++ b/include/asm-ia64/system.h
@@ -244,6 +244,13 @@ extern void ia64_load_extra (struct task_struct *task);
244 __ia64_save_fpu((prev)->thread.fph); \ 244 __ia64_save_fpu((prev)->thread.fph); \
245 } \ 245 } \
246 __switch_to(prev, next, last); \ 246 __switch_to(prev, next, last); \
247 /* "next" in old context is "current" in new context */ \
248 if (unlikely((current->thread.flags & IA64_THREAD_MIGRATION) && \
249 (task_cpu(current) != \
250 task_thread_info(current)->last_cpu))) { \
251 platform_migrate(current); \
252 task_thread_info(current)->last_cpu = task_cpu(current); \
253 } \
247} while (0) 254} while (0)
248#else 255#else
249# define switch_to(prev,next,last) __switch_to(prev, next, last) 256# define switch_to(prev,next,last) __switch_to(prev, next, last)
diff --git a/include/asm-ia64/thread_info.h b/include/asm-ia64/thread_info.h
index 1d6518fe1f02..56394a2c7055 100644
--- a/include/asm-ia64/thread_info.h
+++ b/include/asm-ia64/thread_info.h
@@ -26,16 +26,10 @@ struct thread_info {
26 struct exec_domain *exec_domain;/* execution domain */ 26 struct exec_domain *exec_domain;/* execution domain */
27 __u32 flags; /* thread_info flags (see TIF_*) */ 27 __u32 flags; /* thread_info flags (see TIF_*) */
28 __u32 cpu; /* current CPU */ 28 __u32 cpu; /* current CPU */
29 __u32 last_cpu; /* Last CPU thread ran on */
29 mm_segment_t addr_limit; /* user-level address space limit */ 30 mm_segment_t addr_limit; /* user-level address space limit */
30 int preempt_count; /* 0=premptable, <0=BUG; will also serve as bh-counter */ 31 int preempt_count; /* 0=premptable, <0=BUG; will also serve as bh-counter */
31 struct restart_block restart_block; 32 struct restart_block restart_block;
32 struct {
33 int signo;
34 int code;
35 void __user *addr;
36 unsigned long start_time;
37 pid_t pid;
38 } sigdelayed; /* Saved information for TIF_SIGDELAYED */
39}; 33};
40 34
41#define THREAD_SIZE KERNEL_STACK_SIZE 35#define THREAD_SIZE KERNEL_STACK_SIZE
@@ -89,7 +83,6 @@ struct thread_info {
89#define TIF_NEED_RESCHED 2 /* rescheduling necessary */ 83#define TIF_NEED_RESCHED 2 /* rescheduling necessary */
90#define TIF_SYSCALL_TRACE 3 /* syscall trace active */ 84#define TIF_SYSCALL_TRACE 3 /* syscall trace active */
91#define TIF_SYSCALL_AUDIT 4 /* syscall auditing active */ 85#define TIF_SYSCALL_AUDIT 4 /* syscall auditing active */
92#define TIF_SIGDELAYED 5 /* signal delayed from MCA/INIT/NMI/PMI context */
93#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */ 86#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */
94#define TIF_MEMDIE 17 87#define TIF_MEMDIE 17
95#define TIF_MCA_INIT 18 /* this task is processing MCA or INIT */ 88#define TIF_MCA_INIT 18 /* this task is processing MCA or INIT */
@@ -101,13 +94,12 @@ struct thread_info {
101#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) 94#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
102#define _TIF_SIGPENDING (1 << TIF_SIGPENDING) 95#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
103#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) 96#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
104#define _TIF_SIGDELAYED (1 << TIF_SIGDELAYED)
105#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG) 97#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
106#define _TIF_MCA_INIT (1 << TIF_MCA_INIT) 98#define _TIF_MCA_INIT (1 << TIF_MCA_INIT)
107#define _TIF_DB_DISABLED (1 << TIF_DB_DISABLED) 99#define _TIF_DB_DISABLED (1 << TIF_DB_DISABLED)
108 100
109/* "work to do on user-return" bits */ 101/* "work to do on user-return" bits */
110#define TIF_ALLWORK_MASK (_TIF_NOTIFY_RESUME|_TIF_SIGPENDING|_TIF_NEED_RESCHED|_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SIGDELAYED) 102#define TIF_ALLWORK_MASK (_TIF_NOTIFY_RESUME|_TIF_SIGPENDING|_TIF_NEED_RESCHED|_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
111/* like TIF_ALLWORK_BITS but sans TIF_SYSCALL_TRACE or TIF_SYSCALL_AUDIT */ 103/* like TIF_ALLWORK_BITS but sans TIF_SYSCALL_TRACE or TIF_SYSCALL_AUDIT */
112#define TIF_WORK_MASK (TIF_ALLWORK_MASK&~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)) 104#define TIF_WORK_MASK (TIF_ALLWORK_MASK&~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT))
113 105
diff --git a/include/asm-mips/byteorder.h b/include/asm-mips/byteorder.h
index 584f8128fffd..aefc02f16fd8 100644
--- a/include/asm-mips/byteorder.h
+++ b/include/asm-mips/byteorder.h
@@ -39,6 +39,24 @@ static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
39} 39}
40#define __arch__swab32(x) ___arch__swab32(x) 40#define __arch__swab32(x) ___arch__swab32(x)
41 41
42#ifdef CONFIG_CPU_MIPS64_R2
43
44static __inline__ __attribute_const__ __u64 ___arch__swab64(__u64 x)
45{
46 __asm__(
47 " dsbh %0, %1 \n"
48 " dshd %0, %0 \n"
49 " drotr %0, %0, 32 \n"
50 : "=r" (x)
51 : "r" (x));
52
53 return x;
54}
55
56#define __arch__swab64(x) ___arch__swab64(x)
57
58#endif /* CONFIG_CPU_MIPS64_R2 */
59
42#endif /* CONFIG_CPU_MIPSR2 */ 60#endif /* CONFIG_CPU_MIPSR2 */
43 61
44#if !defined(__STRICT_ANSI__) || defined(__KERNEL__) 62#if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
diff --git a/include/asm-mips/compat.h b/include/asm-mips/compat.h
index 35d2604fe69c..0012bd804d2d 100644
--- a/include/asm-mips/compat.h
+++ b/include/asm-mips/compat.h
@@ -128,17 +128,17 @@ typedef u32 compat_sigset_word;
128 */ 128 */
129typedef u32 compat_uptr_t; 129typedef u32 compat_uptr_t;
130 130
131static inline void *compat_ptr(compat_uptr_t uptr) 131static inline void __user *compat_ptr(compat_uptr_t uptr)
132{ 132{
133 return (void *)(long)uptr; 133 return (void __user *)(long)uptr;
134} 134}
135 135
136static inline void *compat_alloc_user_space(long len) 136static inline void __user *compat_alloc_user_space(long len)
137{ 137{
138 struct pt_regs *regs = (struct pt_regs *) 138 struct pt_regs *regs = (struct pt_regs *)
139 ((unsigned long) current_thread_info() + THREAD_SIZE - 32) - 1; 139 ((unsigned long) current_thread_info() + THREAD_SIZE - 32) - 1;
140 140
141 return (void *) (regs->regs[29] - len); 141 return (void __user *) (regs->regs[29] - len);
142} 142}
143#if defined (__MIPSEL__) 143#if defined (__MIPSEL__)
144#define __COMPAT_ENDIAN_SWAP__ 1 144#define __COMPAT_ENDIAN_SWAP__ 1
diff --git a/include/asm-mips/io.h b/include/asm-mips/io.h
index ba1d7bbc15d2..546a17e56a9b 100644
--- a/include/asm-mips/io.h
+++ b/include/asm-mips/io.h
@@ -40,56 +40,13 @@
40 * hardware. An example use would be for flash memory that's used for 40 * hardware. An example use would be for flash memory that's used for
41 * execute in place. 41 * execute in place.
42 */ 42 */
43# define __raw_ioswabb(x) (x) 43# define __raw_ioswabb(a,x) (x)
44# define __raw_ioswabw(x) (x) 44# define __raw_ioswabw(a,x) (x)
45# define __raw_ioswabl(x) (x) 45# define __raw_ioswabl(a,x) (x)
46# define __raw_ioswabq(x) (x) 46# define __raw_ioswabq(a,x) (x)
47# define ____raw_ioswabq(x) (x) 47# define ____raw_ioswabq(a,x) (x)
48 48
49/* 49/* ioswab[bwlq], __mem_ioswab[bwlq] are defined in mangle-port.h */
50 * Sane hardware offers swapping of PCI/ISA I/O space accesses in hardware;
51 * less sane hardware forces software to fiddle with this...
52 *
53 * Regardless, if the host bus endianness mismatches that of PCI/ISA, then
54 * you can't have the numerical value of data and byte addresses within
55 * multibyte quantities both preserved at the same time. Hence two
56 * variations of functions: non-prefixed ones that preserve the value
57 * and prefixed ones that preserve byte addresses. The latters are
58 * typically used for moving raw data between a peripheral and memory (cf.
59 * string I/O functions), hence the "__mem_" prefix.
60 */
61#if defined(CONFIG_SWAP_IO_SPACE)
62
63# define ioswabb(x) (x)
64# define __mem_ioswabb(x) (x)
65# ifdef CONFIG_SGI_IP22
66/*
67 * IP22 seems braindead enough to swap 16bits values in hardware, but
68 * not 32bits. Go figure... Can't tell without documentation.
69 */
70# define ioswabw(x) (x)
71# define __mem_ioswabw(x) le16_to_cpu(x)
72# else
73# define ioswabw(x) le16_to_cpu(x)
74# define __mem_ioswabw(x) (x)
75# endif
76# define ioswabl(x) le32_to_cpu(x)
77# define __mem_ioswabl(x) (x)
78# define ioswabq(x) le64_to_cpu(x)
79# define __mem_ioswabq(x) (x)
80
81#else
82
83# define ioswabb(x) (x)
84# define __mem_ioswabb(x) (x)
85# define ioswabw(x) (x)
86# define __mem_ioswabw(x) cpu_to_le16(x)
87# define ioswabl(x) (x)
88# define __mem_ioswabl(x) cpu_to_le32(x)
89# define ioswabq(x) (x)
90# define __mem_ioswabq(x) cpu_to_le32(x)
91
92#endif
93 50
94#define IO_SPACE_LIMIT 0xffff 51#define IO_SPACE_LIMIT 0xffff
95 52
@@ -346,7 +303,7 @@ static inline void pfx##write##bwlq(type val, \
346 \ 303 \
347 __mem = (void *)__swizzle_addr_##bwlq((unsigned long)(mem)); \ 304 __mem = (void *)__swizzle_addr_##bwlq((unsigned long)(mem)); \
348 \ 305 \
349 __val = pfx##ioswab##bwlq(val); \ 306 __val = pfx##ioswab##bwlq(__mem, val); \
350 \ 307 \
351 if (sizeof(type) != sizeof(u64) || sizeof(u64) == sizeof(long)) \ 308 if (sizeof(type) != sizeof(u64) || sizeof(u64) == sizeof(long)) \
352 *__mem = __val; \ 309 *__mem = __val; \
@@ -401,7 +358,7 @@ static inline type pfx##read##bwlq(const volatile void __iomem *mem) \
401 BUG(); \ 358 BUG(); \
402 } \ 359 } \
403 \ 360 \
404 return pfx##ioswab##bwlq(__val); \ 361 return pfx##ioswab##bwlq(__mem, __val); \
405} 362}
406 363
407#define __BUILD_IOPORT_SINGLE(pfx, bwlq, type, p, slow) \ 364#define __BUILD_IOPORT_SINGLE(pfx, bwlq, type, p, slow) \
@@ -411,10 +368,9 @@ static inline void pfx##out##bwlq##p(type val, unsigned long port) \
411 volatile type *__addr; \ 368 volatile type *__addr; \
412 type __val; \ 369 type __val; \
413 \ 370 \
414 port = __swizzle_addr_##bwlq(port); \ 371 __addr = (void *)__swizzle_addr_##bwlq(mips_io_port_base + port); \
415 __addr = (void *)(mips_io_port_base + port); \
416 \ 372 \
417 __val = pfx##ioswab##bwlq(val); \ 373 __val = pfx##ioswab##bwlq(__addr, val); \
418 \ 374 \
419 /* Really, we want this to be atomic */ \ 375 /* Really, we want this to be atomic */ \
420 BUILD_BUG_ON(sizeof(type) > sizeof(unsigned long)); \ 376 BUILD_BUG_ON(sizeof(type) > sizeof(unsigned long)); \
@@ -428,15 +384,14 @@ static inline type pfx##in##bwlq##p(unsigned long port) \
428 volatile type *__addr; \ 384 volatile type *__addr; \
429 type __val; \ 385 type __val; \
430 \ 386 \
431 port = __swizzle_addr_##bwlq(port); \ 387 __addr = (void *)__swizzle_addr_##bwlq(mips_io_port_base + port); \
432 __addr = (void *)(mips_io_port_base + port); \
433 \ 388 \
434 BUILD_BUG_ON(sizeof(type) > sizeof(unsigned long)); \ 389 BUILD_BUG_ON(sizeof(type) > sizeof(unsigned long)); \
435 \ 390 \
436 __val = *__addr; \ 391 __val = *__addr; \
437 slow; \ 392 slow; \
438 \ 393 \
439 return pfx##ioswab##bwlq(__val); \ 394 return pfx##ioswab##bwlq(__addr, __val); \
440} 395}
441 396
442#define __BUILD_MEMORY_PFX(bus, bwlq, type) \ 397#define __BUILD_MEMORY_PFX(bus, bwlq, type) \
diff --git a/include/asm-mips/mach-cobalt/cobalt.h b/include/asm-mips/mach-cobalt/cobalt.h
index 78e1df2095fb..b3c5ecbec03c 100644
--- a/include/asm-mips/mach-cobalt/cobalt.h
+++ b/include/asm-mips/mach-cobalt/cobalt.h
@@ -113,4 +113,6 @@ do { \
113# define COBALT_KEY_SELECT (1 << 7) 113# define COBALT_KEY_SELECT (1 << 7)
114# define COBALT_KEY_MASK 0xfe 114# define COBALT_KEY_MASK 0xfe
115 115
116#define COBALT_UART ((volatile unsigned char *) CKSEG1ADDR(0x1c800000))
117
116#endif /* __ASM_COBALT_H */ 118#endif /* __ASM_COBALT_H */
diff --git a/include/asm-mips/mach-generic/mangle-port.h b/include/asm-mips/mach-generic/mangle-port.h
index 4a98d83b8ec7..6e1b0c075de7 100644
--- a/include/asm-mips/mach-generic/mangle-port.h
+++ b/include/asm-mips/mach-generic/mangle-port.h
@@ -13,4 +13,40 @@
13#define __swizzle_addr_l(port) (port) 13#define __swizzle_addr_l(port) (port)
14#define __swizzle_addr_q(port) (port) 14#define __swizzle_addr_q(port) (port)
15 15
16/*
17 * Sane hardware offers swapping of PCI/ISA I/O space accesses in hardware;
18 * less sane hardware forces software to fiddle with this...
19 *
20 * Regardless, if the host bus endianness mismatches that of PCI/ISA, then
21 * you can't have the numerical value of data and byte addresses within
22 * multibyte quantities both preserved at the same time. Hence two
23 * variations of functions: non-prefixed ones that preserve the value
24 * and prefixed ones that preserve byte addresses. The latters are
25 * typically used for moving raw data between a peripheral and memory (cf.
26 * string I/O functions), hence the "__mem_" prefix.
27 */
28#if defined(CONFIG_SWAP_IO_SPACE)
29
30# define ioswabb(a,x) (x)
31# define __mem_ioswabb(a,x) (x)
32# define ioswabw(a,x) le16_to_cpu(x)
33# define __mem_ioswabw(a,x) (x)
34# define ioswabl(a,x) le32_to_cpu(x)
35# define __mem_ioswabl(a,x) (x)
36# define ioswabq(a,x) le64_to_cpu(x)
37# define __mem_ioswabq(a,x) (x)
38
39#else
40
41# define ioswabb(a,x) (x)
42# define __mem_ioswabb(a,x) (x)
43# define ioswabw(a,x) (x)
44# define __mem_ioswabw(a,x) cpu_to_le16(x)
45# define ioswabl(a,x) (x)
46# define __mem_ioswabl(a,x) cpu_to_le32(x)
47# define ioswabq(a,x) (x)
48# define __mem_ioswabq(a,x) cpu_to_le32(x)
49
50#endif
51
16#endif /* __ASM_MACH_GENERIC_MANGLE_PORT_H */ 52#endif /* __ASM_MACH_GENERIC_MANGLE_PORT_H */
diff --git a/include/asm-mips/mach-ip27/mangle-port.h b/include/asm-mips/mach-ip27/mangle-port.h
index f76c44880451..d615312a451a 100644
--- a/include/asm-mips/mach-ip27/mangle-port.h
+++ b/include/asm-mips/mach-ip27/mangle-port.h
@@ -13,4 +13,13 @@
13#define __swizzle_addr_l(port) (port) 13#define __swizzle_addr_l(port) (port)
14#define __swizzle_addr_q(port) (port) 14#define __swizzle_addr_q(port) (port)
15 15
16# define ioswabb(a,x) (x)
17# define __mem_ioswabb(a,x) (x)
18# define ioswabw(a,x) (x)
19# define __mem_ioswabw(a,x) cpu_to_le16(x)
20# define ioswabl(a,x) (x)
21# define __mem_ioswabl(a,x) cpu_to_le32(x)
22# define ioswabq(a,x) (x)
23# define __mem_ioswabq(a,x) cpu_to_le32(x)
24
16#endif /* __ASM_MACH_IP27_MANGLE_PORT_H */ 25#endif /* __ASM_MACH_IP27_MANGLE_PORT_H */
diff --git a/include/asm-mips/mach-ip32/mangle-port.h b/include/asm-mips/mach-ip32/mangle-port.h
index 6e25b52ed8f2..81320eb55324 100644
--- a/include/asm-mips/mach-ip32/mangle-port.h
+++ b/include/asm-mips/mach-ip32/mangle-port.h
@@ -14,4 +14,13 @@
14#define __swizzle_addr_l(port) (port) 14#define __swizzle_addr_l(port) (port)
15#define __swizzle_addr_q(port) (port) 15#define __swizzle_addr_q(port) (port)
16 16
17# define ioswabb(a,x) (x)
18# define __mem_ioswabb(a,x) (x)
19# define ioswabw(a,x) (x)
20# define __mem_ioswabw(a,x) cpu_to_le16(x)
21# define ioswabl(a,x) (x)
22# define __mem_ioswabl(a,x) cpu_to_le32(x)
23# define ioswabq(a,x) (x)
24# define __mem_ioswabq(a,x) cpu_to_le32(x)
25
17#endif /* __ASM_MACH_IP32_MANGLE_PORT_H */ 26#endif /* __ASM_MACH_IP32_MANGLE_PORT_H */
diff --git a/include/asm-mips/mach-mips/cpu-feature-overrides.h b/include/asm-mips/mach-mips/cpu-feature-overrides.h
index 9f92aed17754..e06af6c86f86 100644
--- a/include/asm-mips/mach-mips/cpu-feature-overrides.h
+++ b/include/asm-mips/mach-mips/cpu-feature-overrides.h
@@ -29,7 +29,11 @@
29/* #define cpu_has_prefetch ? */ 29/* #define cpu_has_prefetch ? */
30#define cpu_has_mcheck 1 30#define cpu_has_mcheck 1
31/* #define cpu_has_ejtag ? */ 31/* #define cpu_has_ejtag ? */
32#ifdef CONFIG_CPU_HAS_LLSC
32#define cpu_has_llsc 1 33#define cpu_has_llsc 1
34#else
35#define cpu_has_llsc 0
36#endif
33/* #define cpu_has_vtag_icache ? */ 37/* #define cpu_has_vtag_icache ? */
34/* #define cpu_has_dc_aliases ? */ 38/* #define cpu_has_dc_aliases ? */
35/* #define cpu_has_ic_fills_f_dc ? */ 39/* #define cpu_has_ic_fills_f_dc ? */
diff --git a/include/asm-mips/mmu_context.h b/include/asm-mips/mmu_context.h
index 19cdf7642e66..61cf22588137 100644
--- a/include/asm-mips/mmu_context.h
+++ b/include/asm-mips/mmu_context.h
@@ -33,12 +33,7 @@ extern unsigned long pgd_current[];
33 write_c0_context((unsigned long) smp_processor_id() << 25); \ 33 write_c0_context((unsigned long) smp_processor_id() << 25); \
34 TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir) 34 TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir)
35#endif 35#endif
36#if defined(CONFIG_64BIT) && !defined(CONFIG_BUILD_ELF64) 36#ifdef CONFIG_64BIT
37#define TLBMISS_HANDLER_SETUP() \
38 write_c0_context((unsigned long) &pgd_current[smp_processor_id()] << 23); \
39 TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir)
40#endif
41#if defined(CONFIG_64BIT) && defined(CONFIG_BUILD_ELF64)
42#define TLBMISS_HANDLER_SETUP() \ 37#define TLBMISS_HANDLER_SETUP() \
43 write_c0_context((unsigned long) smp_processor_id() << 26); \ 38 write_c0_context((unsigned long) smp_processor_id() << 26); \
44 TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir) 39 TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir)
diff --git a/include/asm-mips/pgtable-32.h b/include/asm-mips/pgtable-32.h
index 0cff64ce0fb8..4d6bc45df594 100644
--- a/include/asm-mips/pgtable-32.h
+++ b/include/asm-mips/pgtable-32.h
@@ -206,7 +206,7 @@ pfn_pte(unsigned long pfn, pgprot_t prot)
206 /* fixme */ 206 /* fixme */
207#define pte_to_pgoff(_pte) (((_pte).pte_high >> 6) + ((_pte).pte_high & 0x3f)) 207#define pte_to_pgoff(_pte) (((_pte).pte_high >> 6) + ((_pte).pte_high & 0x3f))
208#define pgoff_to_pte(off) \ 208#define pgoff_to_pte(off) \
209 ((pte_t){(((off) & 0x3f) + ((off) << 6) + _PAGE_FILE)}) 209 ((pte_t){(((off) & 0x3f) + ((off) << 6) + _PAGE_FILE)})
210 210
211#else 211#else
212#define pte_to_pgoff(_pte) \ 212#define pte_to_pgoff(_pte) \
diff --git a/include/asm-mips/r4kcache.h b/include/asm-mips/r4kcache.h
index 0bcb79a58ee9..90c374700977 100644
--- a/include/asm-mips/r4kcache.h
+++ b/include/asm-mips/r4kcache.h
@@ -303,5 +303,6 @@ __BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, )
303__BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, ) 303__BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, )
304/* blast_inv_dcache_range */ 304/* blast_inv_dcache_range */
305__BUILD_BLAST_CACHE_RANGE(inv_d, dcache, Hit_Invalidate_D, ) 305__BUILD_BLAST_CACHE_RANGE(inv_d, dcache, Hit_Invalidate_D, )
306__BUILD_BLAST_CACHE_RANGE(inv_s, scache, Hit_Invalidate_SD, )
306 307
307#endif /* _ASM_R4KCACHE_H */ 308#endif /* _ASM_R4KCACHE_H */
diff --git a/include/asm-mips/signal.h b/include/asm-mips/signal.h
index 6fe903e09c62..d8349e4b55ee 100644
--- a/include/asm-mips/signal.h
+++ b/include/asm-mips/signal.h
@@ -147,16 +147,34 @@ struct k_sigaction {
147 147
148/* IRIX compatible stack_t */ 148/* IRIX compatible stack_t */
149typedef struct sigaltstack { 149typedef struct sigaltstack {
150 void *ss_sp; 150 void __user *ss_sp;
151 size_t ss_size; 151 size_t ss_size;
152 int ss_flags; 152 int ss_flags;
153} stack_t; 153} stack_t;
154 154
155#ifdef __KERNEL__ 155#ifdef __KERNEL__
156#include <asm/sigcontext.h> 156#include <asm/sigcontext.h>
157#include <asm/siginfo.h>
157 158
158#define ptrace_signal_deliver(regs, cookie) do { } while (0) 159#define ptrace_signal_deliver(regs, cookie) do { } while (0)
159 160
161struct pt_regs;
162extern void do_signal(struct pt_regs *regs);
163extern void do_signal32(struct pt_regs *regs);
164
165extern int setup_frame(struct k_sigaction * ka, struct pt_regs *regs,
166 int signr, sigset_t *set);
167extern int setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
168 int signr, sigset_t *set, siginfo_t *info);
169
170extern int setup_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
171 int signr, sigset_t *set);
172extern int setup_rt_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
173 int signr, sigset_t *set, siginfo_t *info);
174
175extern int setup_rt_frame_n32(struct k_sigaction * ka, struct pt_regs *regs,
176 int signr, sigset_t *set, siginfo_t *info);
177
160#endif /* __KERNEL__ */ 178#endif /* __KERNEL__ */
161 179
162#endif /* _ASM_SIGNAL_H */ 180#endif /* _ASM_SIGNAL_H */
diff --git a/include/asm-mips/sn/klconfig.h b/include/asm-mips/sn/klconfig.h
index d028e28d6239..9709ff701d9b 100644
--- a/include/asm-mips/sn/klconfig.h
+++ b/include/asm-mips/sn/klconfig.h
@@ -99,7 +99,7 @@ typedef s32 klconf_off_t;
99#define ENABLE_BOARD 0x01 99#define ENABLE_BOARD 0x01
100#define FAILED_BOARD 0x02 100#define FAILED_BOARD 0x02
101#define DUPLICATE_BOARD 0x04 /* Boards like midplanes/routers which 101#define DUPLICATE_BOARD 0x04 /* Boards like midplanes/routers which
102 are discovered twice. Use one of them */ 102 are discovered twice. Use one of them */
103#define VISITED_BOARD 0x08 /* Used for compact hub numbering. */ 103#define VISITED_BOARD 0x08 /* Used for compact hub numbering. */
104#define LOCAL_MASTER_IO6 0x10 /* master io6 for that node */ 104#define LOCAL_MASTER_IO6 0x10 /* master io6 for that node */
105#define GLOBAL_MASTER_IO6 0x20 105#define GLOBAL_MASTER_IO6 0x20
diff --git a/include/asm-mips/sn/mapped_kernel.h b/include/asm-mips/sn/mapped_kernel.h
index 3a17846df849..59edb20f8ec5 100644
--- a/include/asm-mips/sn/mapped_kernel.h
+++ b/include/asm-mips/sn/mapped_kernel.h
@@ -23,11 +23,7 @@
23#include <linux/config.h> 23#include <linux/config.h>
24#include <asm/addrspace.h> 24#include <asm/addrspace.h>
25 25
26#ifdef CONFIG_BUILD_ELF64
27#define REP_BASE CAC_BASE 26#define REP_BASE CAC_BASE
28#else
29#define REP_BASE CKSEG0
30#endif
31 27
32#ifdef CONFIG_MAPPED_KERNEL 28#ifdef CONFIG_MAPPED_KERNEL
33 29
diff --git a/include/asm-mips/sn/sn0/hubio.h b/include/asm-mips/sn/sn0/hubio.h
index 80cf6a52ed3b..f314da21b970 100644
--- a/include/asm-mips/sn/sn0/hubio.h
+++ b/include/asm-mips/sn/sn0/hubio.h
@@ -229,7 +229,7 @@ typedef union hubii_ilcsr_u {
229 icsr_llp_en: 1, /* LLP enable bit */ 229 icsr_llp_en: 1, /* LLP enable bit */
230 icsr_rsvd2: 1, /* reserver */ 230 icsr_rsvd2: 1, /* reserver */
231 icsr_wrm_reset: 1, /* Warm reset bit */ 231 icsr_wrm_reset: 1, /* Warm reset bit */
232 icsr_rsvd1: 2, /* Data ready offset */ 232 icsr_rsvd1: 2, /* Data ready offset */
233 icsr_null_to: 6; /* Null timeout */ 233 icsr_null_to: 6; /* Null timeout */
234 234
235 } icsr_fields_s; 235 } icsr_fields_s;
@@ -274,9 +274,9 @@ typedef union io_perf_sel {
274 u64 perf_sel_reg; 274 u64 perf_sel_reg;
275 struct { 275 struct {
276 u64 perf_rsvd : 48, 276 u64 perf_rsvd : 48,
277 perf_icct : 8, 277 perf_icct : 8,
278 perf_ippr1 : 4, 278 perf_ippr1 : 4,
279 perf_ippr0 : 4; 279 perf_ippr0 : 4;
280 } perf_sel_bits; 280 } perf_sel_bits;
281} io_perf_sel_t; 281} io_perf_sel_t;
282 282
@@ -287,8 +287,8 @@ typedef union io_perf_cnt {
287 u64 perf_cnt; 287 u64 perf_cnt;
288 struct { 288 struct {
289 u64 perf_rsvd1 : 32, 289 u64 perf_rsvd1 : 32,
290 perf_rsvd2 : 12, 290 perf_rsvd2 : 12,
291 perf_cnt : 20; 291 perf_cnt : 20;
292 } perf_cnt_bits; 292 } perf_cnt_bits;
293} io_perf_cnt_t; 293} io_perf_cnt_t;
294 294
diff --git a/include/asm-mips/stackframe.h b/include/asm-mips/stackframe.h
index a8919dcc93c8..2acf3e844f00 100644
--- a/include/asm-mips/stackframe.h
+++ b/include/asm-mips/stackframe.h
@@ -63,17 +63,7 @@
63 addu k1, k0 63 addu k1, k0
64 LONG_L k1, %lo(kernelsp)(k1) 64 LONG_L k1, %lo(kernelsp)(k1)
65#endif 65#endif
66#if defined(CONFIG_64BIT) && !defined(CONFIG_BUILD_ELF64) 66#ifdef CONFIG_64BIT
67 MFC0 k1, CP0_CONTEXT
68 dsra k1, 23
69 lui k0, %hi(pgd_current)
70 addiu k0, %lo(pgd_current)
71 dsubu k1, k0
72 lui k0, %hi(kernelsp)
73 daddu k1, k0
74 LONG_L k1, %lo(kernelsp)(k1)
75#endif
76#if defined(CONFIG_64BIT) && defined(CONFIG_BUILD_ELF64)
77 MFC0 k1, CP0_CONTEXT 67 MFC0 k1, CP0_CONTEXT
78 lui k0, %highest(kernelsp) 68 lui k0, %highest(kernelsp)
79 dsrl k1, 23 69 dsrl k1, 23
@@ -91,11 +81,7 @@
91 mfc0 \temp, CP0_CONTEXT 81 mfc0 \temp, CP0_CONTEXT
92 srl \temp, 23 82 srl \temp, 23
93#endif 83#endif
94#if defined(CONFIG_64BIT) && !defined(CONFIG_BUILD_ELF64) 84#ifdef CONFIG_64BIT
95 lw \temp, TI_CPU(gp)
96 dsll \temp, 3
97#endif
98#if defined(CONFIG_64BIT) && defined(CONFIG_BUILD_ELF64)
99 MFC0 \temp, CP0_CONTEXT 85 MFC0 \temp, CP0_CONTEXT
100 dsrl \temp, 23 86 dsrl \temp, 23
101#endif 87#endif
@@ -103,7 +89,7 @@
103 .endm 89 .endm
104#else 90#else
105 .macro get_saved_sp /* Uniprocessor variation */ 91 .macro get_saved_sp /* Uniprocessor variation */
106#if defined(CONFIG_64BIT) && defined(CONFIG_BUILD_ELF64) 92#ifdef CONFIG_64BIT
107 lui k1, %highest(kernelsp) 93 lui k1, %highest(kernelsp)
108 daddiu k1, %higher(kernelsp) 94 daddiu k1, %higher(kernelsp)
109 dsll k1, k1, 16 95 dsll k1, k1, 16
diff --git a/include/asm-mips/system.h b/include/asm-mips/system.h
index ddae9bae31af..4097fac5ac3c 100644
--- a/include/asm-mips/system.h
+++ b/include/asm-mips/system.h
@@ -286,10 +286,10 @@ extern void __xchg_called_with_bad_pointer(void);
286static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size) 286static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
287{ 287{
288 switch (size) { 288 switch (size) {
289 case 4: 289 case 4:
290 return __xchg_u32(ptr, x); 290 return __xchg_u32(ptr, x);
291 case 8: 291 case 8:
292 return __xchg_u64(ptr, x); 292 return __xchg_u64(ptr, x);
293 } 293 }
294 __xchg_called_with_bad_pointer(); 294 __xchg_called_with_bad_pointer();
295 return x; 295 return x;
diff --git a/include/asm-mips/thread_info.h b/include/asm-mips/thread_info.h
index fa193f861e71..f8d97dafd2f4 100644
--- a/include/asm-mips/thread_info.h
+++ b/include/asm-mips/thread_info.h
@@ -31,7 +31,7 @@ struct thread_info {
31 int preempt_count; /* 0 => preemptable, <0 => BUG */ 31 int preempt_count; /* 0 => preemptable, <0 => BUG */
32 32
33 mm_segment_t addr_limit; /* thread address space: 33 mm_segment_t addr_limit; /* thread address space:
34 0-0xBFFFFFFF for user-thead 34 0-0xBFFFFFFF for user-thead
35 0-0xFFFFFFFF for kernel-thread 35 0-0xFFFFFFFF for kernel-thread
36 */ 36 */
37 struct restart_block restart_block; 37 struct restart_block restart_block;
diff --git a/include/asm-sparc/socket.h b/include/asm-sparc/socket.h
index 09575b608adb..4e0ce3a35ea9 100644
--- a/include/asm-sparc/socket.h
+++ b/include/asm-sparc/socket.h
@@ -47,7 +47,7 @@
47#define SO_TIMESTAMP 0x001d 47#define SO_TIMESTAMP 0x001d
48#define SCM_TIMESTAMP SO_TIMESTAMP 48#define SCM_TIMESTAMP SO_TIMESTAMP
49 49
50#define SO_PEERSEC 0x100e 50#define SO_PEERSEC 0x001e
51 51
52/* Security levels - as per NRL IPv6 - don't actually do anything */ 52/* Security levels - as per NRL IPv6 - don't actually do anything */
53#define SO_SECURITY_AUTHENTICATION 0x5001 53#define SO_SECURITY_AUTHENTICATION 0x5001
diff --git a/include/linux/amba/clcd.h b/include/linux/amba/clcd.h
index 6b8d73dc1ab0..9cf64b1b688b 100644
--- a/include/linux/amba/clcd.h
+++ b/include/linux/amba/clcd.h
@@ -54,6 +54,7 @@
54#define CNTL_LCDBPP4 (2 << 1) 54#define CNTL_LCDBPP4 (2 << 1)
55#define CNTL_LCDBPP8 (3 << 1) 55#define CNTL_LCDBPP8 (3 << 1)
56#define CNTL_LCDBPP16 (4 << 1) 56#define CNTL_LCDBPP16 (4 << 1)
57#define CNTL_LCDBPP16_565 (6 << 1)
57#define CNTL_LCDBPP24 (5 << 1) 58#define CNTL_LCDBPP24 (5 << 1)
58#define CNTL_LCDBW (1 << 4) 59#define CNTL_LCDBW (1 << 4)
59#define CNTL_LCDTFT (1 << 5) 60#define CNTL_LCDTFT (1 << 5)
@@ -209,7 +210,16 @@ static inline void clcdfb_decode(struct clcd_fb *fb, struct clcd_regs *regs)
209 val |= CNTL_LCDBPP8; 210 val |= CNTL_LCDBPP8;
210 break; 211 break;
211 case 16: 212 case 16:
212 val |= CNTL_LCDBPP16; 213 /*
214 * PL110 cannot choose between 5551 and 565 modes in
215 * its control register
216 */
217 if ((fb->dev->periphid & 0x000fffff) == 0x00041110)
218 val |= CNTL_LCDBPP16;
219 else if (fb->fb.var.green.length == 5)
220 val |= CNTL_LCDBPP16;
221 else
222 val |= CNTL_LCDBPP16_565;
213 break; 223 break;
214 case 32: 224 case 32:
215 val |= CNTL_LCDBPP24; 225 val |= CNTL_LCDBPP24;
diff --git a/include/linux/ata.h b/include/linux/ata.h
index 94f77cce27fa..b02a16c435e7 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -267,6 +267,16 @@ struct ata_taskfile {
267 ((u64) (id)[(n) + 1] << 16) | \ 267 ((u64) (id)[(n) + 1] << 16) | \
268 ((u64) (id)[(n) + 0]) ) 268 ((u64) (id)[(n) + 0]) )
269 269
270static inline unsigned int ata_id_major_version(const u16 *id)
271{
272 unsigned int mver;
273
274 for (mver = 14; mver >= 1; mver--)
275 if (id[ATA_ID_MAJOR_VER] & (1 << mver))
276 break;
277 return mver;
278}
279
270static inline int ata_id_current_chs_valid(const u16 *id) 280static inline int ata_id_current_chs_valid(const u16 *id)
271{ 281{
272 /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command 282 /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command
@@ -302,4 +312,16 @@ static inline int ata_ok(u8 status)
302 == ATA_DRDY); 312 == ATA_DRDY);
303} 313}
304 314
315static inline int lba_28_ok(u64 block, u32 n_block)
316{
317 /* check the ending block number */
318 return ((block + n_block - 1) < ((u64)1 << 28)) && (n_block <= 256);
319}
320
321static inline int lba_48_ok(u64 block, u32 n_block)
322{
323 /* check the ending block number */
324 return ((block + n_block - 1) < ((u64)1 << 48)) && (n_block <= 65536);
325}
326
305#endif /* __LINUX_ATA_H__ */ 327#endif /* __LINUX_ATA_H__ */
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 0ed1d4853c69..d612b89dce33 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -32,7 +32,7 @@ struct cpu {
32}; 32};
33 33
34extern int register_cpu(struct cpu *, int, struct node *); 34extern int register_cpu(struct cpu *, int, struct node *);
35extern struct sys_device *get_cpu_sysdev(int cpu); 35extern struct sys_device *get_cpu_sysdev(unsigned cpu);
36#ifdef CONFIG_HOTPLUG_CPU 36#ifdef CONFIG_HOTPLUG_CPU
37extern void unregister_cpu(struct cpu *, struct node *); 37extern void unregister_cpu(struct cpu *, struct node *);
38#endif 38#endif
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index d88bf8aa8b47..0ab1bc1152ca 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -229,6 +229,8 @@ struct crypto_tfm {
229 } crt_u; 229 } crt_u;
230 230
231 struct crypto_alg *__crt_alg; 231 struct crypto_alg *__crt_alg;
232
233 char __crt_ctx[] __attribute__ ((__aligned__));
232}; 234};
233 235
234/* 236/*
@@ -301,7 +303,13 @@ static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm)
301 303
302static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm) 304static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
303{ 305{
304 return (void *)&tfm[1]; 306 return tfm->__crt_ctx;
307}
308
309static inline unsigned int crypto_tfm_ctx_alignment(void)
310{
311 struct crypto_tfm *tfm;
312 return __alignof__(tfm->__crt_ctx);
305} 313}
306 314
307/* 315/*
diff --git a/include/linux/dccp.h b/include/linux/dccp.h
index 088529f54965..676333b9fad0 100644
--- a/include/linux/dccp.h
+++ b/include/linux/dccp.h
@@ -18,7 +18,7 @@
18 * @dccph_seq - sequence number high or low order 24 bits, depends on dccph_x 18 * @dccph_seq - sequence number high or low order 24 bits, depends on dccph_x
19 */ 19 */
20struct dccp_hdr { 20struct dccp_hdr {
21 __u16 dccph_sport, 21 __be16 dccph_sport,
22 dccph_dport; 22 dccph_dport;
23 __u8 dccph_doff; 23 __u8 dccph_doff;
24#if defined(__LITTLE_ENDIAN_BITFIELD) 24#if defined(__LITTLE_ENDIAN_BITFIELD)
@@ -32,18 +32,18 @@ struct dccp_hdr {
32#endif 32#endif
33 __u16 dccph_checksum; 33 __u16 dccph_checksum;
34#if defined(__LITTLE_ENDIAN_BITFIELD) 34#if defined(__LITTLE_ENDIAN_BITFIELD)
35 __u32 dccph_x:1, 35 __u8 dccph_x:1,
36 dccph_type:4, 36 dccph_type:4,
37 dccph_reserved:3, 37 dccph_reserved:3;
38 dccph_seq:24;
39#elif defined(__BIG_ENDIAN_BITFIELD) 38#elif defined(__BIG_ENDIAN_BITFIELD)
40 __u32 dccph_reserved:3, 39 __u8 dccph_reserved:3,
41 dccph_type:4, 40 dccph_type:4,
42 dccph_x:1, 41 dccph_x:1;
43 dccph_seq:24;
44#else 42#else
45#error "Adjust your <asm/byteorder.h> defines" 43#error "Adjust your <asm/byteorder.h> defines"
46#endif 44#endif
45 __u8 dccph_seq2;
46 __be16 dccph_seq;
47}; 47};
48 48
49/** 49/**
@@ -52,7 +52,7 @@ struct dccp_hdr {
52 * @dccph_seq_low - low 24 bits of a 48 bit seq packet 52 * @dccph_seq_low - low 24 bits of a 48 bit seq packet
53 */ 53 */
54struct dccp_hdr_ext { 54struct dccp_hdr_ext {
55 __u32 dccph_seq_low; 55 __be32 dccph_seq_low;
56}; 56};
57 57
58/** 58/**
@@ -62,7 +62,7 @@ struct dccp_hdr_ext {
62 * @dccph_req_options - list of options (must be a multiple of 32 bits 62 * @dccph_req_options - list of options (must be a multiple of 32 bits
63 */ 63 */
64struct dccp_hdr_request { 64struct dccp_hdr_request {
65 __u32 dccph_req_service; 65 __be32 dccph_req_service;
66}; 66};
67/** 67/**
68 * struct dccp_hdr_ack_bits - acknowledgment bits common to most packets 68 * struct dccp_hdr_ack_bits - acknowledgment bits common to most packets
@@ -71,9 +71,9 @@ struct dccp_hdr_request {
71 * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR 71 * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR
72 */ 72 */
73struct dccp_hdr_ack_bits { 73struct dccp_hdr_ack_bits {
74 __u32 dccph_reserved1:8, 74 __be16 dccph_reserved1;
75 dccph_ack_nr_high:24; 75 __be16 dccph_ack_nr_high;
76 __u32 dccph_ack_nr_low; 76 __be32 dccph_ack_nr_low;
77}; 77};
78/** 78/**
79 * struct dccp_hdr_response - Conection initiation response header 79 * struct dccp_hdr_response - Conection initiation response header
@@ -85,7 +85,7 @@ struct dccp_hdr_ack_bits {
85 */ 85 */
86struct dccp_hdr_response { 86struct dccp_hdr_response {
87 struct dccp_hdr_ack_bits dccph_resp_ack; 87 struct dccp_hdr_ack_bits dccph_resp_ack;
88 __u32 dccph_resp_service; 88 __be32 dccph_resp_service;
89}; 89};
90 90
91/** 91/**
@@ -154,6 +154,10 @@ enum {
154 DCCPO_MANDATORY = 1, 154 DCCPO_MANDATORY = 1,
155 DCCPO_MIN_RESERVED = 3, 155 DCCPO_MIN_RESERVED = 3,
156 DCCPO_MAX_RESERVED = 31, 156 DCCPO_MAX_RESERVED = 31,
157 DCCPO_CHANGE_L = 32,
158 DCCPO_CONFIRM_L = 33,
159 DCCPO_CHANGE_R = 34,
160 DCCPO_CONFIRM_R = 35,
157 DCCPO_NDP_COUNT = 37, 161 DCCPO_NDP_COUNT = 37,
158 DCCPO_ACK_VECTOR_0 = 38, 162 DCCPO_ACK_VECTOR_0 = 38,
159 DCCPO_ACK_VECTOR_1 = 39, 163 DCCPO_ACK_VECTOR_1 = 39,
@@ -168,7 +172,9 @@ enum {
168/* DCCP features */ 172/* DCCP features */
169enum { 173enum {
170 DCCPF_RESERVED = 0, 174 DCCPF_RESERVED = 0,
175 DCCPF_CCID = 1,
171 DCCPF_SEQUENCE_WINDOW = 3, 176 DCCPF_SEQUENCE_WINDOW = 3,
177 DCCPF_ACK_RATIO = 5,
172 DCCPF_SEND_ACK_VECTOR = 6, 178 DCCPF_SEND_ACK_VECTOR = 6,
173 DCCPF_SEND_NDP_COUNT = 7, 179 DCCPF_SEND_NDP_COUNT = 7,
174 /* 10-127 reserved */ 180 /* 10-127 reserved */
@@ -176,9 +182,18 @@ enum {
176 DCCPF_MAX_CCID_SPECIFIC = 255, 182 DCCPF_MAX_CCID_SPECIFIC = 255,
177}; 183};
178 184
185/* this structure is argument to DCCP_SOCKOPT_CHANGE_X */
186struct dccp_so_feat {
187 __u8 dccpsf_feat;
188 __u8 *dccpsf_val;
189 __u8 dccpsf_len;
190};
191
179/* DCCP socket options */ 192/* DCCP socket options */
180#define DCCP_SOCKOPT_PACKET_SIZE 1 193#define DCCP_SOCKOPT_PACKET_SIZE 1
181#define DCCP_SOCKOPT_SERVICE 2 194#define DCCP_SOCKOPT_SERVICE 2
195#define DCCP_SOCKOPT_CHANGE_L 3
196#define DCCP_SOCKOPT_CHANGE_R 4
182#define DCCP_SOCKOPT_CCID_RX_INFO 128 197#define DCCP_SOCKOPT_CCID_RX_INFO 128
183#define DCCP_SOCKOPT_CCID_TX_INFO 192 198#define DCCP_SOCKOPT_CCID_TX_INFO 192
184 199
@@ -254,16 +269,12 @@ static inline unsigned int dccp_basic_hdr_len(const struct sk_buff *skb)
254static inline __u64 dccp_hdr_seq(const struct sk_buff *skb) 269static inline __u64 dccp_hdr_seq(const struct sk_buff *skb)
255{ 270{
256 const struct dccp_hdr *dh = dccp_hdr(skb); 271 const struct dccp_hdr *dh = dccp_hdr(skb);
257#if defined(__LITTLE_ENDIAN_BITFIELD) 272 __u64 seq_nr = ntohs(dh->dccph_seq);
258 __u64 seq_nr = ntohl(dh->dccph_seq << 8);
259#elif defined(__BIG_ENDIAN_BITFIELD)
260 __u64 seq_nr = ntohl(dh->dccph_seq);
261#else
262#error "Adjust your <asm/byteorder.h> defines"
263#endif
264 273
265 if (dh->dccph_x != 0) 274 if (dh->dccph_x != 0)
266 seq_nr = (seq_nr << 32) + ntohl(dccp_hdrx(skb)->dccph_seq_low); 275 seq_nr = (seq_nr << 32) + ntohl(dccp_hdrx(skb)->dccph_seq_low);
276 else
277 seq_nr += (u32)dh->dccph_seq2 << 16;
267 278
268 return seq_nr; 279 return seq_nr;
269} 280}
@@ -281,13 +292,7 @@ static inline struct dccp_hdr_ack_bits *dccp_hdr_ack_bits(const struct sk_buff *
281static inline u64 dccp_hdr_ack_seq(const struct sk_buff *skb) 292static inline u64 dccp_hdr_ack_seq(const struct sk_buff *skb)
282{ 293{
283 const struct dccp_hdr_ack_bits *dhack = dccp_hdr_ack_bits(skb); 294 const struct dccp_hdr_ack_bits *dhack = dccp_hdr_ack_bits(skb);
284#if defined(__LITTLE_ENDIAN_BITFIELD) 295 return ((u64)ntohs(dhack->dccph_ack_nr_high) << 32) + ntohl(dhack->dccph_ack_nr_low);
285 return (((u64)ntohl(dhack->dccph_ack_nr_high << 8)) << 32) + ntohl(dhack->dccph_ack_nr_low);
286#elif defined(__BIG_ENDIAN_BITFIELD)
287 return (((u64)ntohl(dhack->dccph_ack_nr_high)) << 32) + ntohl(dhack->dccph_ack_nr_low);
288#else
289#error "Adjust your <asm/byteorder.h> defines"
290#endif
291} 296}
292 297
293static inline struct dccp_hdr_response *dccp_hdr_response(struct sk_buff *skb) 298static inline struct dccp_hdr_response *dccp_hdr_response(struct sk_buff *skb)
@@ -314,38 +319,60 @@ static inline unsigned int dccp_hdr_len(const struct sk_buff *skb)
314 319
315/* initial values for each feature */ 320/* initial values for each feature */
316#define DCCPF_INITIAL_SEQUENCE_WINDOW 100 321#define DCCPF_INITIAL_SEQUENCE_WINDOW 100
317/* FIXME: for now we're using CCID 3 (TFRC) */ 322#define DCCPF_INITIAL_ACK_RATIO 2
318#define DCCPF_INITIAL_CCID 3 323#define DCCPF_INITIAL_CCID 2
319#define DCCPF_INITIAL_SEND_ACK_VECTOR 0 324#define DCCPF_INITIAL_SEND_ACK_VECTOR 1
320/* FIXME: for now we're default to 1 but it should really be 0 */ 325/* FIXME: for now we're default to 1 but it should really be 0 */
321#define DCCPF_INITIAL_SEND_NDP_COUNT 1 326#define DCCPF_INITIAL_SEND_NDP_COUNT 1
322 327
323#define DCCP_NDP_LIMIT 0xFFFFFF 328#define DCCP_NDP_LIMIT 0xFFFFFF
324 329
325/** 330/**
326 * struct dccp_options - option values for a DCCP connection 331 * struct dccp_minisock - Minimal DCCP connection representation
327 * @dccpo_sequence_window - Sequence Window Feature (section 7.5.2) 332 *
328 * @dccpo_ccid - Congestion Control Id (CCID) (section 10) 333 * Will be used to pass the state from dccp_request_sock to dccp_sock.
329 * @dccpo_send_ack_vector - Send Ack Vector Feature (section 11.5) 334 *
330 * @dccpo_send_ndp_count - Send NDP Count Feature (7.7.2) 335 * @dccpms_sequence_window - Sequence Window Feature (section 7.5.2)
336 * @dccpms_ccid - Congestion Control Id (CCID) (section 10)
337 * @dccpms_send_ack_vector - Send Ack Vector Feature (section 11.5)
338 * @dccpms_send_ndp_count - Send NDP Count Feature (7.7.2)
331 */ 339 */
332struct dccp_options { 340struct dccp_minisock {
333 __u64 dccpo_sequence_window; 341 __u64 dccpms_sequence_window;
334 __u8 dccpo_rx_ccid; 342 __u8 dccpms_rx_ccid;
335 __u8 dccpo_tx_ccid; 343 __u8 dccpms_tx_ccid;
336 __u8 dccpo_send_ack_vector; 344 __u8 dccpms_send_ack_vector;
337 __u8 dccpo_send_ndp_count; 345 __u8 dccpms_send_ndp_count;
346 __u8 dccpms_ack_ratio;
347 struct list_head dccpms_pending;
348 struct list_head dccpms_conf;
349};
350
351struct dccp_opt_conf {
352 __u8 *dccpoc_val;
353 __u8 dccpoc_len;
354};
355
356struct dccp_opt_pend {
357 struct list_head dccpop_node;
358 __u8 dccpop_type;
359 __u8 dccpop_feat;
360 __u8 *dccpop_val;
361 __u8 dccpop_len;
362 int dccpop_conf;
363 struct dccp_opt_conf *dccpop_sc;
338}; 364};
339 365
340extern void __dccp_options_init(struct dccp_options *dccpo); 366extern void __dccp_minisock_init(struct dccp_minisock *dmsk);
341extern void dccp_options_init(struct dccp_options *dccpo); 367extern void dccp_minisock_init(struct dccp_minisock *dmsk);
368
342extern int dccp_parse_options(struct sock *sk, struct sk_buff *skb); 369extern int dccp_parse_options(struct sock *sk, struct sk_buff *skb);
343 370
344struct dccp_request_sock { 371struct dccp_request_sock {
345 struct inet_request_sock dreq_inet_rsk; 372 struct inet_request_sock dreq_inet_rsk;
346 __u64 dreq_iss; 373 __u64 dreq_iss;
347 __u64 dreq_isr; 374 __u64 dreq_isr;
348 __u32 dreq_service; 375 __be32 dreq_service;
349}; 376};
350 377
351static inline struct dccp_request_sock *dccp_rsk(const struct request_sock *req) 378static inline struct dccp_request_sock *dccp_rsk(const struct request_sock *req)
@@ -373,13 +400,13 @@ enum dccp_role {
373 400
374struct dccp_service_list { 401struct dccp_service_list {
375 __u32 dccpsl_nr; 402 __u32 dccpsl_nr;
376 __u32 dccpsl_list[0]; 403 __be32 dccpsl_list[0];
377}; 404};
378 405
379#define DCCP_SERVICE_INVALID_VALUE htonl((__u32)-1) 406#define DCCP_SERVICE_INVALID_VALUE htonl((__u32)-1)
380 407
381static inline int dccp_list_has_service(const struct dccp_service_list *sl, 408static inline int dccp_list_has_service(const struct dccp_service_list *sl,
382 const u32 service) 409 const __be32 service)
383{ 410{
384 if (likely(sl != NULL)) { 411 if (likely(sl != NULL)) {
385 u32 i = sl->dccpsl_nr; 412 u32 i = sl->dccpsl_nr;
@@ -425,17 +452,17 @@ struct dccp_sock {
425 __u64 dccps_gss; 452 __u64 dccps_gss;
426 __u64 dccps_gsr; 453 __u64 dccps_gsr;
427 __u64 dccps_gar; 454 __u64 dccps_gar;
428 __u32 dccps_service; 455 __be32 dccps_service;
429 struct dccp_service_list *dccps_service_list; 456 struct dccp_service_list *dccps_service_list;
430 struct timeval dccps_timestamp_time; 457 struct timeval dccps_timestamp_time;
431 __u32 dccps_timestamp_echo; 458 __u32 dccps_timestamp_echo;
432 __u32 dccps_packet_size; 459 __u32 dccps_packet_size;
460 __u16 dccps_l_ack_ratio;
461 __u16 dccps_r_ack_ratio;
433 unsigned long dccps_ndp_count; 462 unsigned long dccps_ndp_count;
434 __u32 dccps_mss_cache; 463 __u32 dccps_mss_cache;
435 struct dccp_options dccps_options; 464 struct dccp_minisock dccps_minisock;
436 struct dccp_ackvec *dccps_hc_rx_ackvec; 465 struct dccp_ackvec *dccps_hc_rx_ackvec;
437 void *dccps_hc_rx_ccid_private;
438 void *dccps_hc_tx_ccid_private;
439 struct ccid *dccps_hc_rx_ccid; 466 struct ccid *dccps_hc_rx_ccid;
440 struct ccid *dccps_hc_tx_ccid; 467 struct ccid *dccps_hc_tx_ccid;
441 struct dccp_options_received dccps_options_received; 468 struct dccp_options_received dccps_options_received;
@@ -450,6 +477,11 @@ static inline struct dccp_sock *dccp_sk(const struct sock *sk)
450 return (struct dccp_sock *)sk; 477 return (struct dccp_sock *)sk;
451} 478}
452 479
480static inline struct dccp_minisock *dccp_msk(const struct sock *sk)
481{
482 return (struct dccp_minisock *)&dccp_sk(sk)->dccps_minisock;
483}
484
453static inline int dccp_service_not_initialized(const struct sock *sk) 485static inline int dccp_service_not_initialized(const struct sock *sk)
454{ 486{
455 return dccp_sk(sk)->dccps_service == DCCP_SERVICE_INVALID_VALUE; 487 return dccp_sk(sk)->dccps_service == DCCP_SERVICE_INVALID_VALUE;
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index a5fa6a6eede8..4b0428e335be 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -21,6 +21,11 @@
21 21
22struct file_operations; 22struct file_operations;
23 23
24struct debugfs_blob_wrapper {
25 void *data;
26 unsigned long size;
27};
28
24#if defined(CONFIG_DEBUG_FS) 29#if defined(CONFIG_DEBUG_FS)
25struct dentry *debugfs_create_file(const char *name, mode_t mode, 30struct dentry *debugfs_create_file(const char *name, mode_t mode,
26 struct dentry *parent, void *data, 31 struct dentry *parent, void *data,
@@ -39,6 +44,9 @@ struct dentry *debugfs_create_u32(const char *name, mode_t mode,
39struct dentry *debugfs_create_bool(const char *name, mode_t mode, 44struct dentry *debugfs_create_bool(const char *name, mode_t mode,
40 struct dentry *parent, u32 *value); 45 struct dentry *parent, u32 *value);
41 46
47struct dentry *debugfs_create_blob(const char *name, mode_t mode,
48 struct dentry *parent,
49 struct debugfs_blob_wrapper *blob);
42#else 50#else
43 51
44#include <linux/err.h> 52#include <linux/err.h>
@@ -94,6 +102,13 @@ static inline struct dentry *debugfs_create_bool(const char *name, mode_t mode,
94 return ERR_PTR(-ENODEV); 102 return ERR_PTR(-ENODEV);
95} 103}
96 104
105static inline struct dentry *debugfs_create_blob(const char *name, mode_t mode,
106 struct dentry *parent,
107 struct debugfs_blob_wrapper *blob)
108{
109 return ERR_PTR(-ENODEV);
110}
111
97#endif 112#endif
98 113
99#endif 114#endif
diff --git a/include/linux/device.h b/include/linux/device.h
index 58df18d9cd3e..5b595fdfb672 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -424,6 +424,8 @@ extern void firmware_unregister(struct subsystem *);
424 dev_printk(KERN_INFO , dev , format , ## arg) 424 dev_printk(KERN_INFO , dev , format , ## arg)
425#define dev_warn(dev, format, arg...) \ 425#define dev_warn(dev, format, arg...) \
426 dev_printk(KERN_WARNING , dev , format , ## arg) 426 dev_printk(KERN_WARNING , dev , format , ## arg)
427#define dev_notice(dev, format, arg...) \
428 dev_printk(KERN_NOTICE , dev , format , ## arg)
427 429
428/* Create alias, so I can be autoloaded. */ 430/* Create alias, so I can be autoloaded. */
429#define MODULE_ALIAS_CHARDEV(major,minor) \ 431#define MODULE_ALIAS_CHARDEV(major,minor) \
diff --git a/include/linux/dn.h b/include/linux/dn.h
index 782cae49e64c..10b6a6fd5837 100644
--- a/include/linux/dn.h
+++ b/include/linux/dn.h
@@ -71,17 +71,17 @@
71 71
72struct dn_naddr 72struct dn_naddr
73{ 73{
74 unsigned short a_len; 74 __le16 a_len;
75 unsigned char a_addr[DN_MAXADDL]; 75 __u8 a_addr[DN_MAXADDL]; /* Two bytes little endian */
76}; 76};
77 77
78struct sockaddr_dn 78struct sockaddr_dn
79{ 79{
80 unsigned short sdn_family; 80 __u16 sdn_family;
81 unsigned char sdn_flags; 81 __u8 sdn_flags;
82 unsigned char sdn_objnum; 82 __u8 sdn_objnum;
83 unsigned short sdn_objnamel; 83 __le16 sdn_objnamel;
84 unsigned char sdn_objname[DN_MAXOBJL]; 84 __u8 sdn_objname[DN_MAXOBJL];
85 struct dn_naddr sdn_add; 85 struct dn_naddr sdn_add;
86}; 86};
87#define sdn_nodeaddrl sdn_add.a_len /* Node address length */ 87#define sdn_nodeaddrl sdn_add.a_len /* Node address length */
@@ -93,38 +93,38 @@ struct sockaddr_dn
93 * DECnet set/get DSO_CONDATA, DSO_DISDATA (optional data) structure 93 * DECnet set/get DSO_CONDATA, DSO_DISDATA (optional data) structure
94 */ 94 */
95struct optdata_dn { 95struct optdata_dn {
96 unsigned short opt_status; /* Extended status return */ 96 __le16 opt_status; /* Extended status return */
97#define opt_sts opt_status 97#define opt_sts opt_status
98 unsigned short opt_optl; /* Length of user data */ 98 __le16 opt_optl; /* Length of user data */
99 unsigned char opt_data[16]; /* User data */ 99 __u8 opt_data[16]; /* User data */
100}; 100};
101 101
102struct accessdata_dn 102struct accessdata_dn
103{ 103{
104 unsigned char acc_accl; 104 __u8 acc_accl;
105 unsigned char acc_acc[DN_MAXACCL]; 105 __u8 acc_acc[DN_MAXACCL];
106 unsigned char acc_passl; 106 __u8 acc_passl;
107 unsigned char acc_pass[DN_MAXACCL]; 107 __u8 acc_pass[DN_MAXACCL];
108 unsigned char acc_userl; 108 __u8 acc_userl;
109 unsigned char acc_user[DN_MAXACCL]; 109 __u8 acc_user[DN_MAXACCL];
110}; 110};
111 111
112/* 112/*
113 * DECnet logical link information structure 113 * DECnet logical link information structure
114 */ 114 */
115struct linkinfo_dn { 115struct linkinfo_dn {
116 unsigned short idn_segsize; /* Segment size for link */ 116 __le16 idn_segsize; /* Segment size for link */
117 unsigned char idn_linkstate; /* Logical link state */ 117 __u8 idn_linkstate; /* Logical link state */
118}; 118};
119 119
120/* 120/*
121 * Ethernet address format (for DECnet) 121 * Ethernet address format (for DECnet)
122 */ 122 */
123union etheraddress { 123union etheraddress {
124 unsigned char dne_addr[6]; /* Full ethernet address */ 124 __u8 dne_addr[6]; /* Full ethernet address */
125 struct { 125 struct {
126 unsigned char dne_hiord[4]; /* DECnet HIORD prefix */ 126 __u8 dne_hiord[4]; /* DECnet HIORD prefix */
127 unsigned char dne_nodeaddr[2]; /* DECnet node address */ 127 __u8 dne_nodeaddr[2]; /* DECnet node address */
128 } dne_remote; 128 } dne_remote;
129}; 129};
130 130
@@ -133,7 +133,7 @@ union etheraddress {
133 * DECnet physical socket address format 133 * DECnet physical socket address format
134 */ 134 */
135struct dn_addr { 135struct dn_addr {
136 unsigned short dna_family; /* AF_DECnet */ 136 __le16 dna_family; /* AF_DECnet */
137 union etheraddress dna_netaddr; /* DECnet ethernet address */ 137 union etheraddress dna_netaddr; /* DECnet ethernet address */
138}; 138};
139 139
diff --git a/include/linux/dvb/audio.h b/include/linux/dvb/audio.h
index 2b8797084685..0874a67c6b92 100644
--- a/include/linux/dvb/audio.h
+++ b/include/linux/dvb/audio.h
@@ -121,4 +121,17 @@ typedef uint16_t audio_attributes_t;
121#define AUDIO_SET_ATTRIBUTES _IOW('o', 17, audio_attributes_t) 121#define AUDIO_SET_ATTRIBUTES _IOW('o', 17, audio_attributes_t)
122#define AUDIO_SET_KARAOKE _IOW('o', 18, audio_karaoke_t) 122#define AUDIO_SET_KARAOKE _IOW('o', 18, audio_karaoke_t)
123 123
124/**
125 * AUDIO_GET_PTS
126 *
127 * Read the 33 bit presentation time stamp as defined
128 * in ITU T-REC-H.222.0 / ISO/IEC 13818-1.
129 *
130 * The PTS should belong to the currently played
131 * frame if possible, but may also be a value close to it
132 * like the PTS of the last decoded frame or the last PTS
133 * extracted by the PES parser.
134 */
135#define AUDIO_GET_PTS _IOR('o', 19, __u64)
136
124#endif /* _DVBAUDIO_H_ */ 137#endif /* _DVBAUDIO_H_ */
diff --git a/include/linux/dvb/video.h b/include/linux/dvb/video.h
index b81e58b2ebf8..faebfda397ff 100644
--- a/include/linux/dvb/video.h
+++ b/include/linux/dvb/video.h
@@ -200,4 +200,17 @@ typedef uint16_t video_attributes_t;
200#define VIDEO_GET_SIZE _IOR('o', 55, video_size_t) 200#define VIDEO_GET_SIZE _IOR('o', 55, video_size_t)
201#define VIDEO_GET_FRAME_RATE _IOR('o', 56, unsigned int) 201#define VIDEO_GET_FRAME_RATE _IOR('o', 56, unsigned int)
202 202
203/**
204 * VIDEO_GET_PTS
205 *
206 * Read the 33 bit presentation time stamp as defined
207 * in ITU T-REC-H.222.0 / ISO/IEC 13818-1.
208 *
209 * The PTS should belong to the currently played
210 * frame if possible, but may also be a value close to it
211 * like the PTS of the last decoded frame or the last PTS
212 * extracted by the PES parser.
213 */
214#define VIDEO_GET_PTS _IOR('o', 57, __u64)
215
203#endif /*_DVBVIDEO_H_*/ 216#endif /*_DVBVIDEO_H_*/
diff --git a/include/linux/fsl_devices.h b/include/linux/fsl_devices.h
index a9f1cfd096ff..a3a0e078f79d 100644
--- a/include/linux/fsl_devices.h
+++ b/include/linux/fsl_devices.h
@@ -83,5 +83,32 @@ struct fsl_i2c_platform_data {
83#define FSL_I2C_DEV_SEPARATE_DFSRR 0x00000001 83#define FSL_I2C_DEV_SEPARATE_DFSRR 0x00000001
84#define FSL_I2C_DEV_CLOCK_5200 0x00000002 84#define FSL_I2C_DEV_CLOCK_5200 0x00000002
85 85
86
87enum fsl_usb2_operating_modes {
88 FSL_USB2_MPH_HOST,
89 FSL_USB2_DR_HOST,
90 FSL_USB2_DR_DEVICE,
91 FSL_USB2_DR_OTG,
92};
93
94enum fsl_usb2_phy_modes {
95 FSL_USB2_PHY_NONE,
96 FSL_USB2_PHY_ULPI,
97 FSL_USB2_PHY_UTMI,
98 FSL_USB2_PHY_UTMI_WIDE,
99 FSL_USB2_PHY_SERIAL,
100};
101
102struct fsl_usb2_platform_data {
103 /* board specific information */
104 enum fsl_usb2_operating_modes operating_mode;
105 enum fsl_usb2_phy_modes phy_mode;
106 unsigned int port_enables;
107};
108
109/* Flags in fsl_usb2_mph_platform_data */
110#define FSL_USB2_PORT0_ENABLED 0x00000001
111#define FSL_USB2_PORT1_ENABLED 0x00000002
112
86#endif /* _FSL_DEVICE_H_ */ 113#endif /* _FSL_DEVICE_H_ */
87#endif /* __KERNEL__ */ 114#endif /* __KERNEL__ */
diff --git a/include/linux/icmpv6.h b/include/linux/icmpv6.h
index 0cf6c8b12caf..c771a7db9871 100644
--- a/include/linux/icmpv6.h
+++ b/include/linux/icmpv6.h
@@ -40,14 +40,16 @@ struct icmp6hdr {
40 struct icmpv6_nd_ra { 40 struct icmpv6_nd_ra {
41 __u8 hop_limit; 41 __u8 hop_limit;
42#if defined(__LITTLE_ENDIAN_BITFIELD) 42#if defined(__LITTLE_ENDIAN_BITFIELD)
43 __u8 reserved:6, 43 __u8 reserved:4,
44 router_pref:2,
44 other:1, 45 other:1,
45 managed:1; 46 managed:1;
46 47
47#elif defined(__BIG_ENDIAN_BITFIELD) 48#elif defined(__BIG_ENDIAN_BITFIELD)
48 __u8 managed:1, 49 __u8 managed:1,
49 other:1, 50 other:1,
50 reserved:6; 51 router_pref:2,
52 reserved:4;
51#else 53#else
52#error "Please fix <asm/byteorder.h>" 54#error "Please fix <asm/byteorder.h>"
53#endif 55#endif
@@ -70,8 +72,13 @@ struct icmp6hdr {
70#define icmp6_addrconf_managed icmp6_dataun.u_nd_ra.managed 72#define icmp6_addrconf_managed icmp6_dataun.u_nd_ra.managed
71#define icmp6_addrconf_other icmp6_dataun.u_nd_ra.other 73#define icmp6_addrconf_other icmp6_dataun.u_nd_ra.other
72#define icmp6_rt_lifetime icmp6_dataun.u_nd_ra.rt_lifetime 74#define icmp6_rt_lifetime icmp6_dataun.u_nd_ra.rt_lifetime
75#define icmp6_router_pref icmp6_dataun.u_nd_ra.router_pref
73}; 76};
74 77
78#define ICMPV6_ROUTER_PREF_LOW 0x3
79#define ICMPV6_ROUTER_PREF_MEDIUM 0x0
80#define ICMPV6_ROUTER_PREF_HIGH 0x1
81#define ICMPV6_ROUTER_PREF_INVALID 0x2
75 82
76#define ICMPV6_DEST_UNREACH 1 83#define ICMPV6_DEST_UNREACH 1
77#define ICMPV6_PKT_TOOBIG 2 84#define ICMPV6_PKT_TOOBIG 2
diff --git a/include/linux/if.h b/include/linux/if.h
index 12c6f6d157c3..374e20ad8b0d 100644
--- a/include/linux/if.h
+++ b/include/linux/if.h
@@ -33,7 +33,7 @@
33#define IFF_LOOPBACK 0x8 /* is a loopback net */ 33#define IFF_LOOPBACK 0x8 /* is a loopback net */
34#define IFF_POINTOPOINT 0x10 /* interface is has p-p link */ 34#define IFF_POINTOPOINT 0x10 /* interface is has p-p link */
35#define IFF_NOTRAILERS 0x20 /* avoid use of trailers */ 35#define IFF_NOTRAILERS 0x20 /* avoid use of trailers */
36#define IFF_RUNNING 0x40 /* interface running and carrier ok */ 36#define IFF_RUNNING 0x40 /* interface RFC2863 OPER_UP */
37#define IFF_NOARP 0x80 /* no ARP protocol */ 37#define IFF_NOARP 0x80 /* no ARP protocol */
38#define IFF_PROMISC 0x100 /* receive all packets */ 38#define IFF_PROMISC 0x100 /* receive all packets */
39#define IFF_ALLMULTI 0x200 /* receive all multicast packets*/ 39#define IFF_ALLMULTI 0x200 /* receive all multicast packets*/
@@ -43,12 +43,16 @@
43 43
44#define IFF_MULTICAST 0x1000 /* Supports multicast */ 44#define IFF_MULTICAST 0x1000 /* Supports multicast */
45 45
46#define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|IFF_MASTER|IFF_SLAVE|IFF_RUNNING)
47
48#define IFF_PORTSEL 0x2000 /* can set media type */ 46#define IFF_PORTSEL 0x2000 /* can set media type */
49#define IFF_AUTOMEDIA 0x4000 /* auto media select active */ 47#define IFF_AUTOMEDIA 0x4000 /* auto media select active */
50#define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses*/ 48#define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses*/
51 49
50#define IFF_LOWER_UP 0x10000 /* driver signals L1 up */
51#define IFF_DORMANT 0x20000 /* driver signals dormant */
52
53#define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|\
54 IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT)
55
52/* Private (from user) interface flags (netdevice->priv_flags). */ 56/* Private (from user) interface flags (netdevice->priv_flags). */
53#define IFF_802_1Q_VLAN 0x1 /* 802.1Q VLAN device. */ 57#define IFF_802_1Q_VLAN 0x1 /* 802.1Q VLAN device. */
54#define IFF_EBRIDGE 0x2 /* Ethernet bridging device. */ 58#define IFF_EBRIDGE 0x2 /* Ethernet bridging device. */
@@ -83,6 +87,22 @@
83#define IF_PROTO_FR_ETH_PVC 0x200B 87#define IF_PROTO_FR_ETH_PVC 0x200B
84#define IF_PROTO_RAW 0x200C /* RAW Socket */ 88#define IF_PROTO_RAW 0x200C /* RAW Socket */
85 89
90/* RFC 2863 operational status */
91enum {
92 IF_OPER_UNKNOWN,
93 IF_OPER_NOTPRESENT,
94 IF_OPER_DOWN,
95 IF_OPER_LOWERLAYERDOWN,
96 IF_OPER_TESTING,
97 IF_OPER_DORMANT,
98 IF_OPER_UP,
99};
100
101/* link modes */
102enum {
103 IF_LINK_MODE_DEFAULT,
104 IF_LINK_MODE_DORMANT, /* limit upward transition to dormant */
105};
86 106
87/* 107/*
88 * Device mapping structure. I'd just gone off and designed a 108 * Device mapping structure. I'd just gone off and designed a
diff --git a/include/linux/in.h b/include/linux/in.h
index ba355384016a..94f557fa4636 100644
--- a/include/linux/in.h
+++ b/include/linux/in.h
@@ -72,6 +72,7 @@ struct in_addr {
72#define IP_FREEBIND 15 72#define IP_FREEBIND 15
73#define IP_IPSEC_POLICY 16 73#define IP_IPSEC_POLICY 16
74#define IP_XFRM_POLICY 17 74#define IP_XFRM_POLICY 17
75#define IP_PASSSEC 18
75 76
76/* BSD compatibility */ 77/* BSD compatibility */
77#define IP_RECVRETOPTS IP_RETOPTS 78#define IP_RECVRETOPTS IP_RETOPTS
diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h
index fd7af86151b1..92297ff24e85 100644
--- a/include/linux/inetdevice.h
+++ b/include/linux/inetdevice.h
@@ -25,6 +25,7 @@ struct ipv4_devconf
25 int arp_filter; 25 int arp_filter;
26 int arp_announce; 26 int arp_announce;
27 int arp_ignore; 27 int arp_ignore;
28 int arp_accept;
28 int medium_id; 29 int medium_id;
29 int no_xfrm; 30 int no_xfrm;
30 int no_policy; 31 int no_policy;
diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h
index 9c8f4c9ed429..1263d8cb3c18 100644
--- a/include/linux/ipv6.h
+++ b/include/linux/ipv6.h
@@ -145,6 +145,15 @@ struct ipv6_devconf {
145 __s32 max_desync_factor; 145 __s32 max_desync_factor;
146#endif 146#endif
147 __s32 max_addresses; 147 __s32 max_addresses;
148 __s32 accept_ra_defrtr;
149 __s32 accept_ra_pinfo;
150#ifdef CONFIG_IPV6_ROUTER_PREF
151 __s32 accept_ra_rtr_pref;
152 __s32 rtr_probe_interval;
153#ifdef CONFIG_IPV6_ROUTE_INFO
154 __s32 accept_ra_rt_info_max_plen;
155#endif
156#endif
148 void *sysctl; 157 void *sysctl;
149}; 158};
150 159
@@ -167,6 +176,11 @@ enum {
167 DEVCONF_MAX_DESYNC_FACTOR, 176 DEVCONF_MAX_DESYNC_FACTOR,
168 DEVCONF_MAX_ADDRESSES, 177 DEVCONF_MAX_ADDRESSES,
169 DEVCONF_FORCE_MLD_VERSION, 178 DEVCONF_FORCE_MLD_VERSION,
179 DEVCONF_ACCEPT_RA_DEFRTR,
180 DEVCONF_ACCEPT_RA_PINFO,
181 DEVCONF_ACCEPT_RA_RTR_PREF,
182 DEVCONF_RTR_PROBE_INTERVAL,
183 DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN,
170 DEVCONF_MAX 184 DEVCONF_MAX
171}; 185};
172 186
diff --git a/include/linux/ipv6_route.h b/include/linux/ipv6_route.h
index d7c41d1d706a..b323ff577967 100644
--- a/include/linux/ipv6_route.h
+++ b/include/linux/ipv6_route.h
@@ -23,12 +23,22 @@
23#define RTF_NONEXTHOP 0x00200000 /* route with no nexthop */ 23#define RTF_NONEXTHOP 0x00200000 /* route with no nexthop */
24#define RTF_EXPIRES 0x00400000 24#define RTF_EXPIRES 0x00400000
25 25
26#define RTF_ROUTEINFO 0x00800000 /* route information - RA */
27
26#define RTF_CACHE 0x01000000 /* cache entry */ 28#define RTF_CACHE 0x01000000 /* cache entry */
27#define RTF_FLOW 0x02000000 /* flow significant route */ 29#define RTF_FLOW 0x02000000 /* flow significant route */
28#define RTF_POLICY 0x04000000 /* policy route */ 30#define RTF_POLICY 0x04000000 /* policy route */
29 31
32#define RTF_PREF(pref) ((pref) << 27)
33#define RTF_PREF_MASK 0x18000000
34
30#define RTF_LOCAL 0x80000000 35#define RTF_LOCAL 0x80000000
31 36
37#ifdef __KERNEL__
38#define IPV6_EXTRACT_PREF(flag) (((flag) & RTF_PREF_MASK) >> 27)
39#define IPV6_DECODE_PREF(pref) ((pref) ^ 2) /* 1:low,2:med,3:high */
40#endif
41
32struct in6_rtmsg { 42struct in6_rtmsg {
33 struct in6_addr rtmsg_dst; 43 struct in6_addr rtmsg_dst;
34 struct in6_addr rtmsg_src; 44 struct in6_addr rtmsg_src;
diff --git a/include/linux/irda.h b/include/linux/irda.h
index 95dee174cdc5..09d8f105a5a8 100644
--- a/include/linux/irda.h
+++ b/include/linux/irda.h
@@ -76,6 +76,7 @@ typedef enum {
76 IRDA_MCP2120_DONGLE = 9, 76 IRDA_MCP2120_DONGLE = 9,
77 IRDA_ACT200L_DONGLE = 10, 77 IRDA_ACT200L_DONGLE = 10,
78 IRDA_MA600_DONGLE = 11, 78 IRDA_MA600_DONGLE = 11,
79 IRDA_TOIM3232_DONGLE = 12,
79} IRDA_DONGLE; 80} IRDA_DONGLE;
80 81
81/* Protocol types to be used for SOCK_DGRAM */ 82/* Protocol types to be used for SOCK_DGRAM */
diff --git a/include/linux/kobj_map.h b/include/linux/kobj_map.h
index cbe7d8008042..bafe178a381f 100644
--- a/include/linux/kobj_map.h
+++ b/include/linux/kobj_map.h
@@ -1,6 +1,6 @@
1#ifdef __KERNEL__ 1#ifdef __KERNEL__
2 2
3#include <asm/semaphore.h> 3#include <linux/mutex.h>
4 4
5typedef struct kobject *kobj_probe_t(dev_t, int *, void *); 5typedef struct kobject *kobj_probe_t(dev_t, int *, void *);
6struct kobj_map; 6struct kobj_map;
@@ -9,6 +9,6 @@ int kobj_map(struct kobj_map *, dev_t, unsigned long, struct module *,
9 kobj_probe_t *, int (*)(dev_t, void *), void *); 9 kobj_probe_t *, int (*)(dev_t, void *), void *);
10void kobj_unmap(struct kobj_map *, dev_t, unsigned long); 10void kobj_unmap(struct kobj_map *, dev_t, unsigned long);
11struct kobject *kobj_lookup(struct kobj_map *, dev_t, int *); 11struct kobject *kobj_lookup(struct kobj_map *, dev_t, int *);
12struct kobj_map *kobj_map_init(kobj_probe_t *, struct semaphore *); 12struct kobj_map *kobj_map_init(kobj_probe_t *, struct mutex *);
13 13
14#endif 14#endif
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index c374b5fa8d3b..4cb1214ec290 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -80,6 +80,8 @@ extern void kobject_unregister(struct kobject *);
80extern struct kobject * kobject_get(struct kobject *); 80extern struct kobject * kobject_get(struct kobject *);
81extern void kobject_put(struct kobject *); 81extern void kobject_put(struct kobject *);
82 82
83extern struct kobject *kobject_add_dir(struct kobject *, const char *);
84
83extern char * kobject_get_path(struct kobject *, gfp_t); 85extern char * kobject_get_path(struct kobject *, gfp_t);
84 86
85struct kobj_type { 87struct kobj_type {
@@ -255,7 +257,7 @@ struct subsys_attribute {
255extern int subsys_create_file(struct subsystem * , struct subsys_attribute *); 257extern int subsys_create_file(struct subsystem * , struct subsys_attribute *);
256extern void subsys_remove_file(struct subsystem * , struct subsys_attribute *); 258extern void subsys_remove_file(struct subsystem * , struct subsys_attribute *);
257 259
258#if defined(CONFIG_HOTPLUG) & defined(CONFIG_NET) 260#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
259void kobject_uevent(struct kobject *kobj, enum kobject_action action); 261void kobject_uevent(struct kobject *kobj, enum kobject_action action);
260 262
261int add_uevent_var(char **envp, int num_envp, int *cur_index, 263int add_uevent_var(char **envp, int num_envp, int *cur_index,
diff --git a/include/linux/libata.h b/include/linux/libata.h
index c91be5e64ede..239408ecfddf 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -35,7 +35,8 @@
35#include <linux/workqueue.h> 35#include <linux/workqueue.h>
36 36
37/* 37/*
38 * compile-time options 38 * compile-time options: to be removed as soon as all the drivers are
39 * converted to the new debugging mechanism
39 */ 40 */
40#undef ATA_DEBUG /* debugging output */ 41#undef ATA_DEBUG /* debugging output */
41#undef ATA_VERBOSE_DEBUG /* yet more debugging output */ 42#undef ATA_VERBOSE_DEBUG /* yet more debugging output */
@@ -61,15 +62,37 @@
61 62
62#define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __FUNCTION__, ## args) 63#define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __FUNCTION__, ## args)
63 64
64#ifdef ATA_NDEBUG 65/* NEW: debug levels */
65#define assert(expr) 66#define HAVE_LIBATA_MSG 1
66#else 67
67#define assert(expr) \ 68enum {
68 if(unlikely(!(expr))) { \ 69 ATA_MSG_DRV = 0x0001,
69 printk(KERN_ERR "Assertion failed! %s,%s,%s,line=%d\n", \ 70 ATA_MSG_INFO = 0x0002,
70 #expr,__FILE__,__FUNCTION__,__LINE__); \ 71 ATA_MSG_PROBE = 0x0004,
71 } 72 ATA_MSG_WARN = 0x0008,
72#endif 73 ATA_MSG_MALLOC = 0x0010,
74 ATA_MSG_CTL = 0x0020,
75 ATA_MSG_INTR = 0x0040,
76 ATA_MSG_ERR = 0x0080,
77};
78
79#define ata_msg_drv(p) ((p)->msg_enable & ATA_MSG_DRV)
80#define ata_msg_info(p) ((p)->msg_enable & ATA_MSG_INFO)
81#define ata_msg_probe(p) ((p)->msg_enable & ATA_MSG_PROBE)
82#define ata_msg_warn(p) ((p)->msg_enable & ATA_MSG_WARN)
83#define ata_msg_malloc(p) ((p)->msg_enable & ATA_MSG_MALLOC)
84#define ata_msg_ctl(p) ((p)->msg_enable & ATA_MSG_CTL)
85#define ata_msg_intr(p) ((p)->msg_enable & ATA_MSG_INTR)
86#define ata_msg_err(p) ((p)->msg_enable & ATA_MSG_ERR)
87
88static inline u32 ata_msg_init(int dval, int default_msg_enable_bits)
89{
90 if (dval < 0 || dval >= (sizeof(u32) * 8))
91 return default_msg_enable_bits; /* should be 0x1 - only driver info msgs */
92 if (!dval)
93 return 0;
94 return (1 << dval) - 1;
95}
73 96
74/* defines only for the constants which don't work well as enums */ 97/* defines only for the constants which don't work well as enums */
75#define ATA_TAG_POISON 0xfafbfcfdU 98#define ATA_TAG_POISON 0xfafbfcfdU
@@ -99,8 +122,7 @@ enum {
99 /* struct ata_device stuff */ 122 /* struct ata_device stuff */
100 ATA_DFLAG_LBA48 = (1 << 0), /* device supports LBA48 */ 123 ATA_DFLAG_LBA48 = (1 << 0), /* device supports LBA48 */
101 ATA_DFLAG_PIO = (1 << 1), /* device currently in PIO mode */ 124 ATA_DFLAG_PIO = (1 << 1), /* device currently in PIO mode */
102 ATA_DFLAG_LOCK_SECTORS = (1 << 2), /* don't adjust max_sectors */ 125 ATA_DFLAG_LBA = (1 << 2), /* device supports LBA */
103 ATA_DFLAG_LBA = (1 << 3), /* device supports LBA */
104 126
105 ATA_DEV_UNKNOWN = 0, /* unknown device */ 127 ATA_DEV_UNKNOWN = 0, /* unknown device */
106 ATA_DEV_ATA = 1, /* ATA device */ 128 ATA_DEV_ATA = 1, /* ATA device */
@@ -115,9 +137,9 @@ enum {
115 ATA_FLAG_PORT_DISABLED = (1 << 2), /* port is disabled, ignore it */ 137 ATA_FLAG_PORT_DISABLED = (1 << 2), /* port is disabled, ignore it */
116 ATA_FLAG_SATA = (1 << 3), 138 ATA_FLAG_SATA = (1 << 3),
117 ATA_FLAG_NO_LEGACY = (1 << 4), /* no legacy mode check */ 139 ATA_FLAG_NO_LEGACY = (1 << 4), /* no legacy mode check */
118 ATA_FLAG_SRST = (1 << 5), /* use ATA SRST, not E.D.D. */ 140 ATA_FLAG_SRST = (1 << 5), /* (obsolete) use ATA SRST, not E.D.D. */
119 ATA_FLAG_MMIO = (1 << 6), /* use MMIO, not PIO */ 141 ATA_FLAG_MMIO = (1 << 6), /* use MMIO, not PIO */
120 ATA_FLAG_SATA_RESET = (1 << 7), /* use COMRESET */ 142 ATA_FLAG_SATA_RESET = (1 << 7), /* (obsolete) use COMRESET */
121 ATA_FLAG_PIO_DMA = (1 << 8), /* PIO cmds via DMA */ 143 ATA_FLAG_PIO_DMA = (1 << 8), /* PIO cmds via DMA */
122 ATA_FLAG_NOINTR = (1 << 9), /* FIXME: Remove this once 144 ATA_FLAG_NOINTR = (1 << 9), /* FIXME: Remove this once
123 * proper HSM is in place. */ 145 * proper HSM is in place. */
@@ -129,10 +151,14 @@ enum {
129 ATA_FLAG_PIO_LBA48 = (1 << 13), /* Host DMA engine is LBA28 only */ 151 ATA_FLAG_PIO_LBA48 = (1 << 13), /* Host DMA engine is LBA28 only */
130 ATA_FLAG_IRQ_MASK = (1 << 14), /* Mask IRQ in PIO xfers */ 152 ATA_FLAG_IRQ_MASK = (1 << 14), /* Mask IRQ in PIO xfers */
131 153
154 ATA_FLAG_FLUSH_PORT_TASK = (1 << 15), /* Flush port task */
155 ATA_FLAG_IN_EH = (1 << 16), /* EH in progress */
156
132 ATA_QCFLAG_ACTIVE = (1 << 1), /* cmd not yet ack'd to scsi lyer */ 157 ATA_QCFLAG_ACTIVE = (1 << 1), /* cmd not yet ack'd to scsi lyer */
133 ATA_QCFLAG_SG = (1 << 3), /* have s/g table? */ 158 ATA_QCFLAG_SG = (1 << 3), /* have s/g table? */
134 ATA_QCFLAG_SINGLE = (1 << 4), /* no s/g, just a single buffer */ 159 ATA_QCFLAG_SINGLE = (1 << 4), /* no s/g, just a single buffer */
135 ATA_QCFLAG_DMAMAP = ATA_QCFLAG_SG | ATA_QCFLAG_SINGLE, 160 ATA_QCFLAG_DMAMAP = ATA_QCFLAG_SG | ATA_QCFLAG_SINGLE,
161 ATA_QCFLAG_EH_SCHEDULED = (1 << 5), /* EH scheduled */
136 162
137 /* various lengths of time */ 163 /* various lengths of time */
138 ATA_TMOUT_EDD = 5 * HZ, /* heuristic */ 164 ATA_TMOUT_EDD = 5 * HZ, /* heuristic */
@@ -162,11 +188,19 @@ enum {
162 PORT_DISABLED = 2, 188 PORT_DISABLED = 2,
163 189
164 /* encoding various smaller bitmaps into a single 190 /* encoding various smaller bitmaps into a single
165 * unsigned long bitmap 191 * unsigned int bitmap
166 */ 192 */
167 ATA_SHIFT_UDMA = 0, 193 ATA_BITS_PIO = 5,
168 ATA_SHIFT_MWDMA = 8, 194 ATA_BITS_MWDMA = 3,
169 ATA_SHIFT_PIO = 11, 195 ATA_BITS_UDMA = 8,
196
197 ATA_SHIFT_PIO = 0,
198 ATA_SHIFT_MWDMA = ATA_SHIFT_PIO + ATA_BITS_PIO,
199 ATA_SHIFT_UDMA = ATA_SHIFT_MWDMA + ATA_BITS_MWDMA,
200
201 ATA_MASK_PIO = ((1 << ATA_BITS_PIO) - 1) << ATA_SHIFT_PIO,
202 ATA_MASK_MWDMA = ((1 << ATA_BITS_MWDMA) - 1) << ATA_SHIFT_MWDMA,
203 ATA_MASK_UDMA = ((1 << ATA_BITS_UDMA) - 1) << ATA_SHIFT_UDMA,
170 204
171 /* size of buffer to pad xfers ending on unaligned boundaries */ 205 /* size of buffer to pad xfers ending on unaligned boundaries */
172 ATA_DMA_PAD_SZ = 4, 206 ATA_DMA_PAD_SZ = 4,
@@ -189,10 +223,15 @@ enum hsm_task_states {
189}; 223};
190 224
191enum ata_completion_errors { 225enum ata_completion_errors {
192 AC_ERR_OTHER = (1 << 0), 226 AC_ERR_DEV = (1 << 0), /* device reported error */
193 AC_ERR_DEV = (1 << 1), 227 AC_ERR_HSM = (1 << 1), /* host state machine violation */
194 AC_ERR_ATA_BUS = (1 << 2), 228 AC_ERR_TIMEOUT = (1 << 2), /* timeout */
195 AC_ERR_HOST_BUS = (1 << 3), 229 AC_ERR_MEDIA = (1 << 3), /* media error */
230 AC_ERR_ATA_BUS = (1 << 4), /* ATA bus error */
231 AC_ERR_HOST_BUS = (1 << 5), /* host bus error */
232 AC_ERR_SYSTEM = (1 << 6), /* system error */
233 AC_ERR_INVALID = (1 << 7), /* invalid argument */
234 AC_ERR_OTHER = (1 << 8), /* unknown */
196}; 235};
197 236
198/* forward declarations */ 237/* forward declarations */
@@ -202,7 +241,10 @@ struct ata_port;
202struct ata_queued_cmd; 241struct ata_queued_cmd;
203 242
204/* typedefs */ 243/* typedefs */
205typedef int (*ata_qc_cb_t) (struct ata_queued_cmd *qc); 244typedef void (*ata_qc_cb_t) (struct ata_queued_cmd *qc);
245typedef void (*ata_probeinit_fn_t)(struct ata_port *);
246typedef int (*ata_reset_fn_t)(struct ata_port *, int, unsigned int *);
247typedef void (*ata_postreset_fn_t)(struct ata_port *ap, unsigned int *);
206 248
207struct ata_ioports { 249struct ata_ioports {
208 unsigned long cmd_addr; 250 unsigned long cmd_addr;
@@ -305,7 +347,7 @@ struct ata_device {
305 unsigned long flags; /* ATA_DFLAG_xxx */ 347 unsigned long flags; /* ATA_DFLAG_xxx */
306 unsigned int class; /* ATA_DEV_xxx */ 348 unsigned int class; /* ATA_DEV_xxx */
307 unsigned int devno; /* 0 or 1 */ 349 unsigned int devno; /* 0 or 1 */
308 u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */ 350 u16 *id; /* IDENTIFY xxx DEVICE data */
309 u8 pio_mode; 351 u8 pio_mode;
310 u8 dma_mode; 352 u8 dma_mode;
311 u8 xfer_mode; 353 u8 xfer_mode;
@@ -313,6 +355,8 @@ struct ata_device {
313 355
314 unsigned int multi_count; /* sectors count for 356 unsigned int multi_count; /* sectors count for
315 READ/WRITE MULTIPLE */ 357 READ/WRITE MULTIPLE */
358 unsigned int max_sectors; /* per-device max sectors */
359 unsigned int cdb_len;
316 360
317 /* for CHS addressing */ 361 /* for CHS addressing */
318 u16 cylinders; /* Number of cylinders */ 362 u16 cylinders; /* Number of cylinders */
@@ -342,7 +386,6 @@ struct ata_port {
342 unsigned int mwdma_mask; 386 unsigned int mwdma_mask;
343 unsigned int udma_mask; 387 unsigned int udma_mask;
344 unsigned int cbl; /* cable type; ATA_CBL_xxx */ 388 unsigned int cbl; /* cable type; ATA_CBL_xxx */
345 unsigned int cdb_len;
346 389
347 struct ata_device device[ATA_MAX_DEVICES]; 390 struct ata_device device[ATA_MAX_DEVICES];
348 391
@@ -353,12 +396,14 @@ struct ata_port {
353 struct ata_host_stats stats; 396 struct ata_host_stats stats;
354 struct ata_host_set *host_set; 397 struct ata_host_set *host_set;
355 398
356 struct work_struct packet_task; 399 struct work_struct port_task;
357 400
358 struct work_struct pio_task;
359 unsigned int hsm_task_state; 401 unsigned int hsm_task_state;
360 unsigned long pio_task_timeout; 402 unsigned long pio_task_timeout;
361 403
404 u32 msg_enable;
405 struct list_head eh_done_q;
406
362 void *private_data; 407 void *private_data;
363}; 408};
364 409
@@ -378,7 +423,9 @@ struct ata_port_operations {
378 u8 (*check_altstatus)(struct ata_port *ap); 423 u8 (*check_altstatus)(struct ata_port *ap);
379 void (*dev_select)(struct ata_port *ap, unsigned int device); 424 void (*dev_select)(struct ata_port *ap, unsigned int device);
380 425
381 void (*phy_reset) (struct ata_port *ap); 426 void (*phy_reset) (struct ata_port *ap); /* obsolete */
427 int (*probe_reset) (struct ata_port *ap, unsigned int *classes);
428
382 void (*post_set_mode) (struct ata_port *ap); 429 void (*post_set_mode) (struct ata_port *ap);
383 430
384 int (*check_atapi_dma) (struct ata_queued_cmd *qc); 431 int (*check_atapi_dma) (struct ata_queued_cmd *qc);
@@ -387,7 +434,7 @@ struct ata_port_operations {
387 void (*bmdma_start) (struct ata_queued_cmd *qc); 434 void (*bmdma_start) (struct ata_queued_cmd *qc);
388 435
389 void (*qc_prep) (struct ata_queued_cmd *qc); 436 void (*qc_prep) (struct ata_queued_cmd *qc);
390 int (*qc_issue) (struct ata_queued_cmd *qc); 437 unsigned int (*qc_issue) (struct ata_queued_cmd *qc);
391 438
392 void (*eng_timeout) (struct ata_port *ap); 439 void (*eng_timeout) (struct ata_port *ap);
393 440
@@ -435,6 +482,18 @@ extern void ata_port_probe(struct ata_port *);
435extern void __sata_phy_reset(struct ata_port *ap); 482extern void __sata_phy_reset(struct ata_port *ap);
436extern void sata_phy_reset(struct ata_port *ap); 483extern void sata_phy_reset(struct ata_port *ap);
437extern void ata_bus_reset(struct ata_port *ap); 484extern void ata_bus_reset(struct ata_port *ap);
485extern int ata_drive_probe_reset(struct ata_port *ap,
486 ata_probeinit_fn_t probeinit,
487 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
488 ata_postreset_fn_t postreset, unsigned int *classes);
489extern void ata_std_probeinit(struct ata_port *ap);
490extern int ata_std_softreset(struct ata_port *ap, int verbose,
491 unsigned int *classes);
492extern int sata_std_hardreset(struct ata_port *ap, int verbose,
493 unsigned int *class);
494extern void ata_std_postreset(struct ata_port *ap, unsigned int *classes);
495extern int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev,
496 int post_reset);
438extern void ata_port_disable(struct ata_port *); 497extern void ata_port_disable(struct ata_port *);
439extern void ata_std_ports(struct ata_ioports *ioaddr); 498extern void ata_std_ports(struct ata_ioports *ioaddr);
440#ifdef CONFIG_PCI 499#ifdef CONFIG_PCI
@@ -449,7 +508,10 @@ extern void ata_host_set_remove(struct ata_host_set *host_set);
449extern int ata_scsi_detect(struct scsi_host_template *sht); 508extern int ata_scsi_detect(struct scsi_host_template *sht);
450extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg); 509extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
451extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)); 510extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
511extern enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
452extern int ata_scsi_error(struct Scsi_Host *host); 512extern int ata_scsi_error(struct Scsi_Host *host);
513extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
514extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
453extern int ata_scsi_release(struct Scsi_Host *host); 515extern int ata_scsi_release(struct Scsi_Host *host);
454extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc); 516extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
455extern int ata_scsi_device_resume(struct scsi_device *); 517extern int ata_scsi_device_resume(struct scsi_device *);
@@ -457,6 +519,11 @@ extern int ata_scsi_device_suspend(struct scsi_device *);
457extern int ata_device_resume(struct ata_port *, struct ata_device *); 519extern int ata_device_resume(struct ata_port *, struct ata_device *);
458extern int ata_device_suspend(struct ata_port *, struct ata_device *); 520extern int ata_device_suspend(struct ata_port *, struct ata_device *);
459extern int ata_ratelimit(void); 521extern int ata_ratelimit(void);
522extern unsigned int ata_busy_sleep(struct ata_port *ap,
523 unsigned long timeout_pat,
524 unsigned long timeout);
525extern void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *),
526 void *data, unsigned long delay);
460 527
461/* 528/*
462 * Default driver ops implementations 529 * Default driver ops implementations
@@ -470,26 +537,28 @@ extern void ata_std_dev_select (struct ata_port *ap, unsigned int device);
470extern u8 ata_check_status(struct ata_port *ap); 537extern u8 ata_check_status(struct ata_port *ap);
471extern u8 ata_altstatus(struct ata_port *ap); 538extern u8 ata_altstatus(struct ata_port *ap);
472extern void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf); 539extern void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf);
540extern int ata_std_probe_reset(struct ata_port *ap, unsigned int *classes);
473extern int ata_port_start (struct ata_port *ap); 541extern int ata_port_start (struct ata_port *ap);
474extern void ata_port_stop (struct ata_port *ap); 542extern void ata_port_stop (struct ata_port *ap);
475extern void ata_host_stop (struct ata_host_set *host_set); 543extern void ata_host_stop (struct ata_host_set *host_set);
476extern irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs); 544extern irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs);
477extern void ata_qc_prep(struct ata_queued_cmd *qc); 545extern void ata_qc_prep(struct ata_queued_cmd *qc);
478extern int ata_qc_issue_prot(struct ata_queued_cmd *qc); 546extern unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc);
479extern void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, 547extern void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf,
480 unsigned int buflen); 548 unsigned int buflen);
481extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, 549extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
482 unsigned int n_elem); 550 unsigned int n_elem);
483extern unsigned int ata_dev_classify(const struct ata_taskfile *tf); 551extern unsigned int ata_dev_classify(const struct ata_taskfile *tf);
484extern void ata_dev_id_string(const u16 *id, unsigned char *s, 552extern void ata_id_string(const u16 *id, unsigned char *s,
485 unsigned int ofs, unsigned int len); 553 unsigned int ofs, unsigned int len);
486extern void ata_dev_config(struct ata_port *ap, unsigned int i); 554extern void ata_id_c_string(const u16 *id, unsigned char *s,
555 unsigned int ofs, unsigned int len);
487extern void ata_bmdma_setup (struct ata_queued_cmd *qc); 556extern void ata_bmdma_setup (struct ata_queued_cmd *qc);
488extern void ata_bmdma_start (struct ata_queued_cmd *qc); 557extern void ata_bmdma_start (struct ata_queued_cmd *qc);
489extern void ata_bmdma_stop(struct ata_queued_cmd *qc); 558extern void ata_bmdma_stop(struct ata_queued_cmd *qc);
490extern u8 ata_bmdma_status(struct ata_port *ap); 559extern u8 ata_bmdma_status(struct ata_port *ap);
491extern void ata_bmdma_irq_clear(struct ata_port *ap); 560extern void ata_bmdma_irq_clear(struct ata_port *ap);
492extern void ata_qc_complete(struct ata_queued_cmd *qc); 561extern void __ata_qc_complete(struct ata_queued_cmd *qc);
493extern void ata_eng_timeout(struct ata_port *ap); 562extern void ata_eng_timeout(struct ata_port *ap);
494extern void ata_scsi_simulate(struct ata_port *ap, struct ata_device *dev, 563extern void ata_scsi_simulate(struct ata_port *ap, struct ata_device *dev,
495 struct scsi_cmnd *cmd, 564 struct scsi_cmnd *cmd,
@@ -586,10 +655,14 @@ static inline unsigned int ata_tag_valid(unsigned int tag)
586 return (tag < ATA_MAX_QUEUE) ? 1 : 0; 655 return (tag < ATA_MAX_QUEUE) ? 1 : 0;
587} 656}
588 657
658static inline unsigned int ata_class_present(unsigned int class)
659{
660 return class == ATA_DEV_ATA || class == ATA_DEV_ATAPI;
661}
662
589static inline unsigned int ata_dev_present(const struct ata_device *dev) 663static inline unsigned int ata_dev_present(const struct ata_device *dev)
590{ 664{
591 return ((dev->class == ATA_DEV_ATA) || 665 return ata_class_present(dev->class);
592 (dev->class == ATA_DEV_ATAPI));
593} 666}
594 667
595static inline u8 ata_chk_status(struct ata_port *ap) 668static inline u8 ata_chk_status(struct ata_port *ap)
@@ -657,9 +730,9 @@ static inline u8 ata_wait_idle(struct ata_port *ap)
657 730
658 if (status & (ATA_BUSY | ATA_DRQ)) { 731 if (status & (ATA_BUSY | ATA_DRQ)) {
659 unsigned long l = ap->ioaddr.status_addr; 732 unsigned long l = ap->ioaddr.status_addr;
660 printk(KERN_WARNING 733 if (ata_msg_warn(ap))
661 "ATA: abnormal status 0x%X on port 0x%lX\n", 734 printk(KERN_WARNING "ATA: abnormal status 0x%X on port 0x%lX\n",
662 status, l); 735 status, l);
663 } 736 }
664 737
665 return status; 738 return status;
@@ -701,6 +774,24 @@ static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
701 ata_tf_init(qc->ap, &qc->tf, qc->dev->devno); 774 ata_tf_init(qc->ap, &qc->tf, qc->dev->devno);
702} 775}
703 776
777/**
778 * ata_qc_complete - Complete an active ATA command
779 * @qc: Command to complete
780 * @err_mask: ATA Status register contents
781 *
782 * Indicate to the mid and upper layers that an ATA
783 * command has completed, with either an ok or not-ok status.
784 *
785 * LOCKING:
786 * spin_lock_irqsave(host_set lock)
787 */
788static inline void ata_qc_complete(struct ata_queued_cmd *qc)
789{
790 if (unlikely(qc->flags & ATA_QCFLAG_EH_SCHEDULED))
791 return;
792
793 __ata_qc_complete(qc);
794}
704 795
705/** 796/**
706 * ata_irq_on - Enable interrupts on a port. 797 * ata_irq_on - Enable interrupts on a port.
@@ -751,7 +842,8 @@ static inline u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq)
751 842
752 status = ata_busy_wait(ap, bits, 1000); 843 status = ata_busy_wait(ap, bits, 1000);
753 if (status & bits) 844 if (status & bits)
754 DPRINTK("abnormal status 0x%X\n", status); 845 if (ata_msg_err(ap))
846 printk(KERN_ERR "abnormal status 0x%X\n", status);
755 847
756 /* get controller status; clear intr, err bits */ 848 /* get controller status; clear intr, err bits */
757 if (ap->flags & ATA_FLAG_MMIO) { 849 if (ap->flags & ATA_FLAG_MMIO) {
@@ -769,8 +861,10 @@ static inline u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq)
769 post_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); 861 post_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
770 } 862 }
771 863
772 VPRINTK("irq ack: host_stat 0x%X, new host_stat 0x%X, drv_stat 0x%X\n", 864 if (ata_msg_intr(ap))
773 host_stat, post_stat, status); 865 printk(KERN_INFO "%s: irq ack: host_stat 0x%X, new host_stat 0x%X, drv_stat 0x%X\n",
866 __FUNCTION__,
867 host_stat, post_stat, status);
774 868
775 return status; 869 return status;
776} 870}
@@ -807,7 +901,7 @@ static inline int ata_try_flush_cache(const struct ata_device *dev)
807static inline unsigned int ac_err_mask(u8 status) 901static inline unsigned int ac_err_mask(u8 status)
808{ 902{
809 if (status & ATA_BUSY) 903 if (status & ATA_BUSY)
810 return AC_ERR_ATA_BUS; 904 return AC_ERR_HSM;
811 if (status & (ATA_ERR | ATA_DF)) 905 if (status & (ATA_ERR | ATA_DF))
812 return AC_ERR_DEV; 906 return AC_ERR_DEV;
813 return 0; 907 return 0;
diff --git a/include/linux/list.h b/include/linux/list.h
index 47208bd99f9e..67258b47e9ca 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -411,6 +411,17 @@ static inline void list_splice_init(struct list_head *list,
411 pos = list_entry(pos->member.next, typeof(*pos), member)) 411 pos = list_entry(pos->member.next, typeof(*pos), member))
412 412
413/** 413/**
414 * list_for_each_entry_from - iterate over list of given type
415 * continuing from existing point
416 * @pos: the type * to use as a loop counter.
417 * @head: the head for your list.
418 * @member: the name of the list_struct within the struct.
419 */
420#define list_for_each_entry_from(pos, head, member) \
421 for (; prefetch(pos->member.next), &pos->member != (head); \
422 pos = list_entry(pos->member.next, typeof(*pos), member))
423
424/**
414 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry 425 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
415 * @pos: the type * to use as a loop counter. 426 * @pos: the type * to use as a loop counter.
416 * @n: another type * to use as temporary storage 427 * @n: another type * to use as temporary storage
@@ -438,6 +449,19 @@ static inline void list_splice_init(struct list_head *list,
438 pos = n, n = list_entry(n->member.next, typeof(*n), member)) 449 pos = n, n = list_entry(n->member.next, typeof(*n), member))
439 450
440/** 451/**
452 * list_for_each_entry_safe_from - iterate over list of given type
453 * from existing point safe against removal of list entry
454 * @pos: the type * to use as a loop counter.
455 * @n: another type * to use as temporary storage
456 * @head: the head for your list.
457 * @member: the name of the list_struct within the struct.
458 */
459#define list_for_each_entry_safe_from(pos, n, head, member) \
460 for (n = list_entry(pos->member.next, typeof(*pos), member); \
461 &pos->member != (head); \
462 pos = n, n = list_entry(n->member.next, typeof(*n), member))
463
464/**
441 * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against 465 * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against
442 * removal of list entry 466 * removal of list entry
443 * @pos: the type * to use as a loop counter. 467 * @pos: the type * to use as a loop counter.
diff --git a/include/linux/module.h b/include/linux/module.h
index 84d75f3a8aca..70bd843c71cb 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -198,6 +198,9 @@ void *__symbol_get_gpl(const char *symbol);
198#define EXPORT_SYMBOL_GPL(sym) \ 198#define EXPORT_SYMBOL_GPL(sym) \
199 __EXPORT_SYMBOL(sym, "_gpl") 199 __EXPORT_SYMBOL(sym, "_gpl")
200 200
201#define EXPORT_SYMBOL_GPL_FUTURE(sym) \
202 __EXPORT_SYMBOL(sym, "_gpl_future")
203
201#endif 204#endif
202 205
203struct module_ref 206struct module_ref
@@ -242,6 +245,7 @@ struct module
242 /* Sysfs stuff. */ 245 /* Sysfs stuff. */
243 struct module_kobject mkobj; 246 struct module_kobject mkobj;
244 struct module_param_attrs *param_attrs; 247 struct module_param_attrs *param_attrs;
248 struct module_attribute *modinfo_attrs;
245 const char *version; 249 const char *version;
246 const char *srcversion; 250 const char *srcversion;
247 251
@@ -255,6 +259,11 @@ struct module
255 unsigned int num_gpl_syms; 259 unsigned int num_gpl_syms;
256 const unsigned long *gpl_crcs; 260 const unsigned long *gpl_crcs;
257 261
262 /* symbols that will be GPL-only in the near future. */
263 const struct kernel_symbol *gpl_future_syms;
264 unsigned int num_gpl_future_syms;
265 const unsigned long *gpl_future_crcs;
266
258 /* Exception table */ 267 /* Exception table */
259 unsigned int num_exentries; 268 unsigned int num_exentries;
260 const struct exception_table_entry *extable; 269 const struct exception_table_entry *extable;
@@ -441,6 +450,7 @@ void module_remove_driver(struct device_driver *);
441#else /* !CONFIG_MODULES... */ 450#else /* !CONFIG_MODULES... */
442#define EXPORT_SYMBOL(sym) 451#define EXPORT_SYMBOL(sym)
443#define EXPORT_SYMBOL_GPL(sym) 452#define EXPORT_SYMBOL_GPL(sym)
453#define EXPORT_SYMBOL_GPL_FUTURE(sym)
444 454
445/* Given an address, look for it in the exception tables. */ 455/* Given an address, look for it in the exception tables. */
446static inline const struct exception_table_entry * 456static inline const struct exception_table_entry *
diff --git a/include/linux/net.h b/include/linux/net.h
index 28195a2d8ff0..152fa6551fd8 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -149,6 +149,10 @@ struct proto_ops {
149 int optname, char __user *optval, int optlen); 149 int optname, char __user *optval, int optlen);
150 int (*getsockopt)(struct socket *sock, int level, 150 int (*getsockopt)(struct socket *sock, int level,
151 int optname, char __user *optval, int __user *optlen); 151 int optname, char __user *optval, int __user *optlen);
152 int (*compat_setsockopt)(struct socket *sock, int level,
153 int optname, char __user *optval, int optlen);
154 int (*compat_getsockopt)(struct socket *sock, int level,
155 int optname, char __user *optval, int __user *optlen);
152 int (*sendmsg) (struct kiocb *iocb, struct socket *sock, 156 int (*sendmsg) (struct kiocb *iocb, struct socket *sock,
153 struct msghdr *m, size_t total_len); 157 struct msghdr *m, size_t total_len);
154 int (*recvmsg) (struct kiocb *iocb, struct socket *sock, 158 int (*recvmsg) (struct kiocb *iocb, struct socket *sock,
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 7fda03d338d1..950dc55e5192 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -230,7 +230,8 @@ enum netdev_state_t
230 __LINK_STATE_SCHED, 230 __LINK_STATE_SCHED,
231 __LINK_STATE_NOCARRIER, 231 __LINK_STATE_NOCARRIER,
232 __LINK_STATE_RX_SCHED, 232 __LINK_STATE_RX_SCHED,
233 __LINK_STATE_LINKWATCH_PENDING 233 __LINK_STATE_LINKWATCH_PENDING,
234 __LINK_STATE_DORMANT,
234}; 235};
235 236
236 237
@@ -335,11 +336,14 @@ struct net_device
335 */ 336 */
336 337
337 338
338 unsigned short flags; /* interface flags (a la BSD) */ 339 unsigned int flags; /* interface flags (a la BSD) */
339 unsigned short gflags; 340 unsigned short gflags;
340 unsigned short priv_flags; /* Like 'flags' but invisible to userspace. */ 341 unsigned short priv_flags; /* Like 'flags' but invisible to userspace. */
341 unsigned short padded; /* How much padding added by alloc_netdev() */ 342 unsigned short padded; /* How much padding added by alloc_netdev() */
342 343
344 unsigned char operstate; /* RFC2863 operstate */
345 unsigned char link_mode; /* mapping policy to operstate */
346
343 unsigned mtu; /* interface MTU value */ 347 unsigned mtu; /* interface MTU value */
344 unsigned short type; /* interface hardware type */ 348 unsigned short type; /* interface hardware type */
345 unsigned short hard_header_len; /* hardware hdr length */ 349 unsigned short hard_header_len; /* hardware hdr length */
@@ -708,12 +712,18 @@ static inline void dev_put(struct net_device *dev)
708 atomic_dec(&dev->refcnt); 712 atomic_dec(&dev->refcnt);
709} 713}
710 714
711#define __dev_put(dev) atomic_dec(&(dev)->refcnt) 715static inline void dev_hold(struct net_device *dev)
712#define dev_hold(dev) atomic_inc(&(dev)->refcnt) 716{
717 atomic_inc(&dev->refcnt);
718}
713 719
714/* Carrier loss detection, dial on demand. The functions netif_carrier_on 720/* Carrier loss detection, dial on demand. The functions netif_carrier_on
715 * and _off may be called from IRQ context, but it is caller 721 * and _off may be called from IRQ context, but it is caller
716 * who is responsible for serialization of these calls. 722 * who is responsible for serialization of these calls.
723 *
724 * The name carrier is inappropriate, these functions should really be
725 * called netif_lowerlayer_*() because they represent the state of any
726 * kind of lower layer not just hardware media.
717 */ 727 */
718 728
719extern void linkwatch_fire_event(struct net_device *dev); 729extern void linkwatch_fire_event(struct net_device *dev);
@@ -729,6 +739,29 @@ extern void netif_carrier_on(struct net_device *dev);
729 739
730extern void netif_carrier_off(struct net_device *dev); 740extern void netif_carrier_off(struct net_device *dev);
731 741
742static inline void netif_dormant_on(struct net_device *dev)
743{
744 if (!test_and_set_bit(__LINK_STATE_DORMANT, &dev->state))
745 linkwatch_fire_event(dev);
746}
747
748static inline void netif_dormant_off(struct net_device *dev)
749{
750 if (test_and_clear_bit(__LINK_STATE_DORMANT, &dev->state))
751 linkwatch_fire_event(dev);
752}
753
754static inline int netif_dormant(const struct net_device *dev)
755{
756 return test_bit(__LINK_STATE_DORMANT, &dev->state);
757}
758
759
760static inline int netif_oper_up(const struct net_device *dev) {
761 return (dev->operstate == IF_OPER_UP ||
762 dev->operstate == IF_OPER_UNKNOWN /* backward compat */);
763}
764
732/* Hot-plugging. */ 765/* Hot-plugging. */
733static inline int netif_device_present(struct net_device *dev) 766static inline int netif_device_present(struct net_device *dev)
734{ 767{
diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
index 468896939843..412e52ca9720 100644
--- a/include/linux/netfilter.h
+++ b/include/linux/netfilter.h
@@ -80,10 +80,14 @@ struct nf_sockopt_ops
80 int set_optmin; 80 int set_optmin;
81 int set_optmax; 81 int set_optmax;
82 int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len); 82 int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len);
83 int (*compat_set)(struct sock *sk, int optval,
84 void __user *user, unsigned int len);
83 85
84 int get_optmin; 86 int get_optmin;
85 int get_optmax; 87 int get_optmax;
86 int (*get)(struct sock *sk, int optval, void __user *user, int *len); 88 int (*get)(struct sock *sk, int optval, void __user *user, int *len);
89 int (*compat_get)(struct sock *sk, int optval,
90 void __user *user, int *len);
87 91
88 /* Number of users inside set() or get(). */ 92 /* Number of users inside set() or get(). */
89 unsigned int use; 93 unsigned int use;
@@ -246,6 +250,11 @@ int nf_setsockopt(struct sock *sk, int pf, int optval, char __user *opt,
246int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt, 250int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt,
247 int *len); 251 int *len);
248 252
253int compat_nf_setsockopt(struct sock *sk, int pf, int optval,
254 char __user *opt, int len);
255int compat_nf_getsockopt(struct sock *sk, int pf, int optval,
256 char __user *opt, int *len);
257
249/* Packet queuing */ 258/* Packet queuing */
250struct nf_queue_handler { 259struct nf_queue_handler {
251 int (*outfn)(struct sk_buff *skb, struct nf_info *info, 260 int (*outfn)(struct sk_buff *skb, struct nf_info *info,
diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
index 934a2479f160..9f5b12cf489b 100644
--- a/include/linux/netfilter/nfnetlink.h
+++ b/include/linux/netfilter/nfnetlink.h
@@ -164,6 +164,7 @@ extern void nfattr_parse(struct nfattr *tb[], int maxattr,
164 __res; \ 164 __res; \
165}) 165})
166 166
167extern int nfnetlink_has_listeners(unsigned int group);
167extern int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, 168extern int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group,
168 int echo); 169 int echo);
169extern int nfnetlink_unicast(struct sk_buff *skb, u_int32_t pid, int flags); 170extern int nfnetlink_unicast(struct sk_buff *skb, u_int32_t pid, int flags);
diff --git a/include/linux/netfilter/nfnetlink_log.h b/include/linux/netfilter/nfnetlink_log.h
index b04b03880595..a7497c7436df 100644
--- a/include/linux/netfilter/nfnetlink_log.h
+++ b/include/linux/netfilter/nfnetlink_log.h
@@ -47,6 +47,8 @@ enum nfulnl_attr_type {
47 NFULA_PAYLOAD, /* opaque data payload */ 47 NFULA_PAYLOAD, /* opaque data payload */
48 NFULA_PREFIX, /* string prefix */ 48 NFULA_PREFIX, /* string prefix */
49 NFULA_UID, /* user id of socket */ 49 NFULA_UID, /* user id of socket */
50 NFULA_SEQ, /* instance-local sequence number */
51 NFULA_SEQ_GLOBAL, /* global sequence number */
50 52
51 __NFULA_MAX 53 __NFULA_MAX
52}; 54};
@@ -77,6 +79,7 @@ enum nfulnl_attr_config {
77 NFULA_CFG_NLBUFSIZ, /* u_int32_t buffer size */ 79 NFULA_CFG_NLBUFSIZ, /* u_int32_t buffer size */
78 NFULA_CFG_TIMEOUT, /* u_int32_t in 1/100 s */ 80 NFULA_CFG_TIMEOUT, /* u_int32_t in 1/100 s */
79 NFULA_CFG_QTHRESH, /* u_int32_t */ 81 NFULA_CFG_QTHRESH, /* u_int32_t */
82 NFULA_CFG_FLAGS, /* u_int16_t */
80 __NFULA_CFG_MAX 83 __NFULA_CFG_MAX
81}; 84};
82#define NFULA_CFG_MAX (__NFULA_CFG_MAX -1) 85#define NFULA_CFG_MAX (__NFULA_CFG_MAX -1)
@@ -85,4 +88,7 @@ enum nfulnl_attr_config {
85#define NFULNL_COPY_META 0x01 88#define NFULNL_COPY_META 0x01
86#define NFULNL_COPY_PACKET 0x02 89#define NFULNL_COPY_PACKET 0x02
87 90
91#define NFULNL_CFG_F_SEQ 0x0001
92#define NFULNL_CFG_F_SEQ_GLOBAL 0x0002
93
88#endif /* _NFNETLINK_LOG_H */ 94#endif /* _NFNETLINK_LOG_H */
diff --git a/include/linux/netfilter/x_tables.h b/include/linux/netfilter/x_tables.h
index 6500d4e59d46..46a0f974f87c 100644
--- a/include/linux/netfilter/x_tables.h
+++ b/include/linux/netfilter/x_tables.h
@@ -92,8 +92,6 @@ struct xt_match
92 92
93 const char name[XT_FUNCTION_MAXNAMELEN-1]; 93 const char name[XT_FUNCTION_MAXNAMELEN-1];
94 94
95 u_int8_t revision;
96
97 /* Return true or false: return FALSE and set *hotdrop = 1 to 95 /* Return true or false: return FALSE and set *hotdrop = 1 to
98 force immediate packet drop. */ 96 force immediate packet drop. */
99 /* Arguments changed since 2.6.9, as this must now handle 97 /* Arguments changed since 2.6.9, as this must now handle
@@ -102,6 +100,7 @@ struct xt_match
102 int (*match)(const struct sk_buff *skb, 100 int (*match)(const struct sk_buff *skb,
103 const struct net_device *in, 101 const struct net_device *in,
104 const struct net_device *out, 102 const struct net_device *out,
103 const struct xt_match *match,
105 const void *matchinfo, 104 const void *matchinfo,
106 int offset, 105 int offset,
107 unsigned int protoff, 106 unsigned int protoff,
@@ -111,15 +110,25 @@ struct xt_match
111 /* Should return true or false. */ 110 /* Should return true or false. */
112 int (*checkentry)(const char *tablename, 111 int (*checkentry)(const char *tablename,
113 const void *ip, 112 const void *ip,
113 const struct xt_match *match,
114 void *matchinfo, 114 void *matchinfo,
115 unsigned int matchinfosize, 115 unsigned int matchinfosize,
116 unsigned int hook_mask); 116 unsigned int hook_mask);
117 117
118 /* Called when entry of this type deleted. */ 118 /* Called when entry of this type deleted. */
119 void (*destroy)(void *matchinfo, unsigned int matchinfosize); 119 void (*destroy)(const struct xt_match *match, void *matchinfo,
120 unsigned int matchinfosize);
120 121
121 /* Set this to THIS_MODULE if you are a module, otherwise NULL */ 122 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
122 struct module *me; 123 struct module *me;
124
125 char *table;
126 unsigned int matchsize;
127 unsigned int hooks;
128 unsigned short proto;
129
130 unsigned short family;
131 u_int8_t revision;
123}; 132};
124 133
125/* Registration hooks for targets. */ 134/* Registration hooks for targets. */
@@ -129,8 +138,6 @@ struct xt_target
129 138
130 const char name[XT_FUNCTION_MAXNAMELEN-1]; 139 const char name[XT_FUNCTION_MAXNAMELEN-1];
131 140
132 u_int8_t revision;
133
134 /* Returns verdict. Argument order changed since 2.6.9, as this 141 /* Returns verdict. Argument order changed since 2.6.9, as this
135 must now handle non-linear skbs, using skb_copy_bits and 142 must now handle non-linear skbs, using skb_copy_bits and
136 skb_ip_make_writable. */ 143 skb_ip_make_writable. */
@@ -138,6 +145,7 @@ struct xt_target
138 const struct net_device *in, 145 const struct net_device *in,
139 const struct net_device *out, 146 const struct net_device *out,
140 unsigned int hooknum, 147 unsigned int hooknum,
148 const struct xt_target *target,
141 const void *targinfo, 149 const void *targinfo,
142 void *userdata); 150 void *userdata);
143 151
@@ -147,15 +155,25 @@ struct xt_target
147 /* Should return true or false. */ 155 /* Should return true or false. */
148 int (*checkentry)(const char *tablename, 156 int (*checkentry)(const char *tablename,
149 const void *entry, 157 const void *entry,
158 const struct xt_target *target,
150 void *targinfo, 159 void *targinfo,
151 unsigned int targinfosize, 160 unsigned int targinfosize,
152 unsigned int hook_mask); 161 unsigned int hook_mask);
153 162
154 /* Called when entry of this type deleted. */ 163 /* Called when entry of this type deleted. */
155 void (*destroy)(void *targinfo, unsigned int targinfosize); 164 void (*destroy)(const struct xt_target *target, void *targinfo,
165 unsigned int targinfosize);
156 166
157 /* Set this to THIS_MODULE if you are a module, otherwise NULL */ 167 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
158 struct module *me; 168 struct module *me;
169
170 char *table;
171 unsigned int targetsize;
172 unsigned int hooks;
173 unsigned short proto;
174
175 unsigned short family;
176 u_int8_t revision;
159}; 177};
160 178
161/* Furniture shopping... */ 179/* Furniture shopping... */
@@ -207,6 +225,13 @@ extern void xt_unregister_target(int af, struct xt_target *target);
207extern int xt_register_match(int af, struct xt_match *target); 225extern int xt_register_match(int af, struct xt_match *target);
208extern void xt_unregister_match(int af, struct xt_match *target); 226extern void xt_unregister_match(int af, struct xt_match *target);
209 227
228extern int xt_check_match(const struct xt_match *match, unsigned short family,
229 unsigned int size, const char *table, unsigned int hook,
230 unsigned short proto, int inv_proto);
231extern int xt_check_target(const struct xt_target *target, unsigned short family,
232 unsigned int size, const char *table, unsigned int hook,
233 unsigned short proto, int inv_proto);
234
210extern int xt_register_table(struct xt_table *table, 235extern int xt_register_table(struct xt_table *table,
211 struct xt_table_info *bootstrap, 236 struct xt_table_info *bootstrap,
212 struct xt_table_info *newinfo); 237 struct xt_table_info *newinfo);
diff --git a/include/linux/netfilter/xt_policy.h b/include/linux/netfilter/xt_policy.h
new file mode 100644
index 000000000000..a8132ec076fb
--- /dev/null
+++ b/include/linux/netfilter/xt_policy.h
@@ -0,0 +1,58 @@
1#ifndef _XT_POLICY_H
2#define _XT_POLICY_H
3
4#define XT_POLICY_MAX_ELEM 4
5
6enum xt_policy_flags
7{
8 XT_POLICY_MATCH_IN = 0x1,
9 XT_POLICY_MATCH_OUT = 0x2,
10 XT_POLICY_MATCH_NONE = 0x4,
11 XT_POLICY_MATCH_STRICT = 0x8,
12};
13
14enum xt_policy_modes
15{
16 XT_POLICY_MODE_TRANSPORT,
17 XT_POLICY_MODE_TUNNEL
18};
19
20struct xt_policy_spec
21{
22 u_int8_t saddr:1,
23 daddr:1,
24 proto:1,
25 mode:1,
26 spi:1,
27 reqid:1;
28};
29
30union xt_policy_addr
31{
32 struct in_addr a4;
33 struct in6_addr a6;
34};
35
36struct xt_policy_elem
37{
38 union xt_policy_addr saddr;
39 union xt_policy_addr smask;
40 union xt_policy_addr daddr;
41 union xt_policy_addr dmask;
42 u_int32_t spi;
43 u_int32_t reqid;
44 u_int8_t proto;
45 u_int8_t mode;
46
47 struct xt_policy_spec match;
48 struct xt_policy_spec invert;
49};
50
51struct xt_policy_info
52{
53 struct xt_policy_elem pol[XT_POLICY_MAX_ELEM];
54 u_int16_t flags;
55 u_int16_t len;
56};
57
58#endif /* _XT_POLICY_H */
diff --git a/include/linux/netfilter_bridge.h b/include/linux/netfilter_bridge.h
index de4d397865ce..a75b84bb9a88 100644
--- a/include/linux/netfilter_bridge.h
+++ b/include/linux/netfilter_bridge.h
@@ -47,22 +47,6 @@ enum nf_br_hook_priorities {
47#define BRNF_BRIDGED 0x08 47#define BRNF_BRIDGED 0x08
48#define BRNF_NF_BRIDGE_PREROUTING 0x10 48#define BRNF_NF_BRIDGE_PREROUTING 0x10
49 49
50static inline
51struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
52{
53 struct nf_bridge_info **nf_bridge = &(skb->nf_bridge);
54
55 if ((*nf_bridge = kmalloc(sizeof(**nf_bridge), GFP_ATOMIC)) != NULL) {
56 atomic_set(&(*nf_bridge)->use, 1);
57 (*nf_bridge)->mask = 0;
58 (*nf_bridge)->physindev = (*nf_bridge)->physoutdev = NULL;
59#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
60 (*nf_bridge)->netoutdev = NULL;
61#endif
62 }
63
64 return *nf_bridge;
65}
66 50
67/* Only used in br_forward.c */ 51/* Only used in br_forward.c */
68static inline 52static inline
@@ -77,17 +61,6 @@ void nf_bridge_maybe_copy_header(struct sk_buff *skb)
77 } 61 }
78} 62}
79 63
80static inline
81void nf_bridge_save_header(struct sk_buff *skb)
82{
83 int header_size = 16;
84
85 if (skb->protocol == __constant_htons(ETH_P_8021Q))
86 header_size = 18;
87
88 memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
89}
90
91/* This is called by the IP fragmenting code and it ensures there is 64/* This is called by the IP fragmenting code and it ensures there is
92 * enough room for the encapsulating header (if there is one). */ 65 * enough room for the encapsulating header (if there is one). */
93static inline 66static inline
diff --git a/include/linux/netfilter_ipv4/ip_conntrack.h b/include/linux/netfilter_ipv4/ip_conntrack.h
index 215765f043e6..f32d75c4f4cf 100644
--- a/include/linux/netfilter_ipv4/ip_conntrack.h
+++ b/include/linux/netfilter_ipv4/ip_conntrack.h
@@ -29,6 +29,7 @@ union ip_conntrack_expect_proto {
29}; 29};
30 30
31/* Add protocol helper include file here */ 31/* Add protocol helper include file here */
32#include <linux/netfilter_ipv4/ip_conntrack_h323.h>
32#include <linux/netfilter_ipv4/ip_conntrack_pptp.h> 33#include <linux/netfilter_ipv4/ip_conntrack_pptp.h>
33#include <linux/netfilter_ipv4/ip_conntrack_amanda.h> 34#include <linux/netfilter_ipv4/ip_conntrack_amanda.h>
34#include <linux/netfilter_ipv4/ip_conntrack_ftp.h> 35#include <linux/netfilter_ipv4/ip_conntrack_ftp.h>
@@ -37,6 +38,7 @@ union ip_conntrack_expect_proto {
37/* per conntrack: application helper private data */ 38/* per conntrack: application helper private data */
38union ip_conntrack_help { 39union ip_conntrack_help {
39 /* insert conntrack helper private data (master) here */ 40 /* insert conntrack helper private data (master) here */
41 struct ip_ct_h323_master ct_h323_info;
40 struct ip_ct_pptp_master ct_pptp_info; 42 struct ip_ct_pptp_master ct_pptp_info;
41 struct ip_ct_ftp_master ct_ftp_info; 43 struct ip_ct_ftp_master ct_ftp_info;
42 struct ip_ct_irc_master ct_irc_info; 44 struct ip_ct_irc_master ct_irc_info;
diff --git a/include/linux/netfilter_ipv4/ip_conntrack_h323.h b/include/linux/netfilter_ipv4/ip_conntrack_h323.h
new file mode 100644
index 000000000000..0987cea53840
--- /dev/null
+++ b/include/linux/netfilter_ipv4/ip_conntrack_h323.h
@@ -0,0 +1,30 @@
1#ifndef _IP_CONNTRACK_H323_H
2#define _IP_CONNTRACK_H323_H
3
4#ifdef __KERNEL__
5
6#define RAS_PORT 1719
7#define Q931_PORT 1720
8#define H323_RTP_CHANNEL_MAX 4 /* Audio, video, FAX and other */
9
10/* This structure exists only once per master */
11struct ip_ct_h323_master {
12
13 /* Original and NATed Q.931 or H.245 signal ports */
14 u_int16_t sig_port[IP_CT_DIR_MAX];
15
16 /* Original and NATed RTP ports */
17 u_int16_t rtp_port[H323_RTP_CHANNEL_MAX][IP_CT_DIR_MAX];
18
19 union {
20 /* RAS connection timeout */
21 u_int32_t timeout;
22
23 /* Next TPKT length (for separate TPKT header and data) */
24 u_int16_t tpkt_len[IP_CT_DIR_MAX];
25 };
26};
27
28#endif
29
30#endif
diff --git a/include/linux/netfilter_ipv4/ip_nat.h b/include/linux/netfilter_ipv4/ip_nat.h
index 41a107de17cf..e9f5ed1d9f68 100644
--- a/include/linux/netfilter_ipv4/ip_nat.h
+++ b/include/linux/netfilter_ipv4/ip_nat.h
@@ -23,7 +23,7 @@ struct ip_nat_seq {
23 * modification (if any) */ 23 * modification (if any) */
24 u_int32_t correction_pos; 24 u_int32_t correction_pos;
25 /* sequence number offset before and after last modification */ 25 /* sequence number offset before and after last modification */
26 int32_t offset_before, offset_after; 26 int16_t offset_before, offset_after;
27}; 27};
28 28
29/* Single range specification. */ 29/* Single range specification. */
diff --git a/include/linux/netfilter_ipv4/ipt_policy.h b/include/linux/netfilter_ipv4/ipt_policy.h
index a3f6eff39d33..b9478a255301 100644
--- a/include/linux/netfilter_ipv4/ipt_policy.h
+++ b/include/linux/netfilter_ipv4/ipt_policy.h
@@ -1,58 +1,21 @@
1#ifndef _IPT_POLICY_H 1#ifndef _IPT_POLICY_H
2#define _IPT_POLICY_H 2#define _IPT_POLICY_H
3 3
4#define IPT_POLICY_MAX_ELEM 4 4#define IPT_POLICY_MAX_ELEM XT_POLICY_MAX_ELEM
5 5
6enum ipt_policy_flags 6/* ipt_policy_flags */
7{ 7#define IPT_POLICY_MATCH_IN XT_POLICY_MATCH_IN
8 IPT_POLICY_MATCH_IN = 0x1, 8#define IPT_POLICY_MATCH_OUT XT_POLICY_MATCH_OUT
9 IPT_POLICY_MATCH_OUT = 0x2, 9#define IPT_POLICY_MATCH_NONE XT_POLICY_MATCH_NONE
10 IPT_POLICY_MATCH_NONE = 0x4, 10#define IPT_POLICY_MATCH_STRICT XT_POLICY_MATCH_STRICT
11 IPT_POLICY_MATCH_STRICT = 0x8, 11
12}; 12/* ipt_policy_modes */
13 13#define IPT_POLICY_MODE_TRANSPORT XT_POLICY_MODE_TRANSPORT
14enum ipt_policy_modes 14#define IPT_POLICY_MODE_TUNNEL XT_POLICY_MODE_TUNNEL
15{ 15
16 IPT_POLICY_MODE_TRANSPORT, 16#define ipt_policy_spec xt_policy_spec
17 IPT_POLICY_MODE_TUNNEL 17#define ipt_policy_addr xt_policy_addr
18}; 18#define ipt_policy_elem xt_policy_elem
19 19#define ipt_policy_info xt_policy_info
20struct ipt_policy_spec
21{
22 u_int8_t saddr:1,
23 daddr:1,
24 proto:1,
25 mode:1,
26 spi:1,
27 reqid:1;
28};
29
30union ipt_policy_addr
31{
32 struct in_addr a4;
33 struct in6_addr a6;
34};
35
36struct ipt_policy_elem
37{
38 union ipt_policy_addr saddr;
39 union ipt_policy_addr smask;
40 union ipt_policy_addr daddr;
41 union ipt_policy_addr dmask;
42 u_int32_t spi;
43 u_int32_t reqid;
44 u_int8_t proto;
45 u_int8_t mode;
46
47 struct ipt_policy_spec match;
48 struct ipt_policy_spec invert;
49};
50
51struct ipt_policy_info
52{
53 struct ipt_policy_elem pol[IPT_POLICY_MAX_ELEM];
54 u_int16_t flags;
55 u_int16_t len;
56};
57 20
58#endif /* _IPT_POLICY_H */ 21#endif /* _IPT_POLICY_H */
diff --git a/include/linux/netfilter_ipv6/ip6t_policy.h b/include/linux/netfilter_ipv6/ip6t_policy.h
index 671bd818300f..6bab3163d2fb 100644
--- a/include/linux/netfilter_ipv6/ip6t_policy.h
+++ b/include/linux/netfilter_ipv6/ip6t_policy.h
@@ -1,58 +1,21 @@
1#ifndef _IP6T_POLICY_H 1#ifndef _IP6T_POLICY_H
2#define _IP6T_POLICY_H 2#define _IP6T_POLICY_H
3 3
4#define IP6T_POLICY_MAX_ELEM 4 4#define IP6T_POLICY_MAX_ELEM XT_POLICY_MAX_ELEM
5 5
6enum ip6t_policy_flags 6/* ip6t_policy_flags */
7{ 7#define IP6T_POLICY_MATCH_IN XT_POLICY_MATCH_IN
8 IP6T_POLICY_MATCH_IN = 0x1, 8#define IP6T_POLICY_MATCH_OUT XT_POLICY_MATCH_OUT
9 IP6T_POLICY_MATCH_OUT = 0x2, 9#define IP6T_POLICY_MATCH_NONE XT_POLICY_MATCH_NONE
10 IP6T_POLICY_MATCH_NONE = 0x4, 10#define IP6T_POLICY_MATCH_STRICT XT_POLICY_MATCH_STRICT
11 IP6T_POLICY_MATCH_STRICT = 0x8, 11
12}; 12/* ip6t_policy_modes */
13 13#define IP6T_POLICY_MODE_TRANSPORT XT_POLICY_MODE_TRANSPORT
14enum ip6t_policy_modes 14#define IP6T_POLICY_MODE_TUNNEL XT_POLICY_MODE_TUNNEL
15{ 15
16 IP6T_POLICY_MODE_TRANSPORT, 16#define ip6t_policy_spec xt_policy_spec
17 IP6T_POLICY_MODE_TUNNEL 17#define ip6t_policy_addr xt_policy_addr
18}; 18#define ip6t_policy_elem xt_policy_elem
19 19#define ip6t_policy_info xt_policy_info
20struct ip6t_policy_spec
21{
22 u_int8_t saddr:1,
23 daddr:1,
24 proto:1,
25 mode:1,
26 spi:1,
27 reqid:1;
28};
29
30union ip6t_policy_addr
31{
32 struct in_addr a4;
33 struct in6_addr a6;
34};
35
36struct ip6t_policy_elem
37{
38 union ip6t_policy_addr saddr;
39 union ip6t_policy_addr smask;
40 union ip6t_policy_addr daddr;
41 union ip6t_policy_addr dmask;
42 u_int32_t spi;
43 u_int32_t reqid;
44 u_int8_t proto;
45 u_int8_t mode;
46
47 struct ip6t_policy_spec match;
48 struct ip6t_policy_spec invert;
49};
50
51struct ip6t_policy_info
52{
53 struct ip6t_policy_elem pol[IP6T_POLICY_MAX_ELEM];
54 u_int16_t flags;
55 u_int16_t len;
56};
57 20
58#endif /* _IP6T_POLICY_H */ 21#endif /* _IP6T_POLICY_H */
diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index c256ebe2a7b4..f8f3d1c927f8 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -151,6 +151,7 @@ struct netlink_skb_parms
151 151
152extern struct sock *netlink_kernel_create(int unit, unsigned int groups, void (*input)(struct sock *sk, int len), struct module *module); 152extern struct sock *netlink_kernel_create(int unit, unsigned int groups, void (*input)(struct sock *sk, int len), struct module *module);
153extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err); 153extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
154extern int netlink_has_listeners(struct sock *sk, unsigned int group);
154extern int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 pid, int nonblock); 155extern int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 pid, int nonblock);
155extern int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 pid, 156extern int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 pid,
156 __u32 group, gfp_t allocation); 157 __u32 group, gfp_t allocation);
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 751eea58bde8..b9810ddf435a 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -1857,16 +1857,22 @@
1857#define PCI_DEVICE_ID_TIGON3_5705M 0x165d 1857#define PCI_DEVICE_ID_TIGON3_5705M 0x165d
1858#define PCI_DEVICE_ID_TIGON3_5705M_2 0x165e 1858#define PCI_DEVICE_ID_TIGON3_5705M_2 0x165e
1859#define PCI_DEVICE_ID_TIGON3_5714 0x1668 1859#define PCI_DEVICE_ID_TIGON3_5714 0x1668
1860#define PCI_DEVICE_ID_TIGON3_5714S 0x1669
1860#define PCI_DEVICE_ID_TIGON3_5780 0x166a 1861#define PCI_DEVICE_ID_TIGON3_5780 0x166a
1861#define PCI_DEVICE_ID_TIGON3_5780S 0x166b 1862#define PCI_DEVICE_ID_TIGON3_5780S 0x166b
1862#define PCI_DEVICE_ID_TIGON3_5705F 0x166e 1863#define PCI_DEVICE_ID_TIGON3_5705F 0x166e
1864#define PCI_DEVICE_ID_TIGON3_5754M 0x1672
1863#define PCI_DEVICE_ID_TIGON3_5750 0x1676 1865#define PCI_DEVICE_ID_TIGON3_5750 0x1676
1864#define PCI_DEVICE_ID_TIGON3_5751 0x1677 1866#define PCI_DEVICE_ID_TIGON3_5751 0x1677
1865#define PCI_DEVICE_ID_TIGON3_5715 0x1678 1867#define PCI_DEVICE_ID_TIGON3_5715 0x1678
1868#define PCI_DEVICE_ID_TIGON3_5715S 0x1679
1869#define PCI_DEVICE_ID_TIGON3_5754 0x167a
1866#define PCI_DEVICE_ID_TIGON3_5750M 0x167c 1870#define PCI_DEVICE_ID_TIGON3_5750M 0x167c
1867#define PCI_DEVICE_ID_TIGON3_5751M 0x167d 1871#define PCI_DEVICE_ID_TIGON3_5751M 0x167d
1868#define PCI_DEVICE_ID_TIGON3_5751F 0x167e 1872#define PCI_DEVICE_ID_TIGON3_5751F 0x167e
1873#define PCI_DEVICE_ID_TIGON3_5787M 0x1693
1869#define PCI_DEVICE_ID_TIGON3_5782 0x1696 1874#define PCI_DEVICE_ID_TIGON3_5782 0x1696
1875#define PCI_DEVICE_ID_TIGON3_5787 0x169b
1870#define PCI_DEVICE_ID_TIGON3_5788 0x169c 1876#define PCI_DEVICE_ID_TIGON3_5788 0x169c
1871#define PCI_DEVICE_ID_TIGON3_5789 0x169d 1877#define PCI_DEVICE_ID_TIGON3_5789 0x169d
1872#define PCI_DEVICE_ID_TIGON3_5702X 0x16a6 1878#define PCI_DEVICE_ID_TIGON3_5702X 0x16a6
diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index d50482ba27fe..d572d5376319 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -199,6 +199,7 @@ enum
199#define RTPROT_BIRD 12 /* BIRD */ 199#define RTPROT_BIRD 12 /* BIRD */
200#define RTPROT_DNROUTED 13 /* DECnet routing daemon */ 200#define RTPROT_DNROUTED 13 /* DECnet routing daemon */
201#define RTPROT_XORP 14 /* XORP */ 201#define RTPROT_XORP 14 /* XORP */
202#define RTPROT_NTK 15 /* Netsukuku */
202 203
203/* rtm_scope 204/* rtm_scope
204 205
@@ -733,6 +734,8 @@ enum
733#define IFLA_MAP IFLA_MAP 734#define IFLA_MAP IFLA_MAP
734 IFLA_WEIGHT, 735 IFLA_WEIGHT,
735#define IFLA_WEIGHT IFLA_WEIGHT 736#define IFLA_WEIGHT IFLA_WEIGHT
737 IFLA_OPERSTATE,
738 IFLA_LINKMODE,
736 __IFLA_MAX 739 __IFLA_MAX
737}; 740};
738 741
@@ -905,6 +908,7 @@ struct tcamsg
905#ifdef __KERNEL__ 908#ifdef __KERNEL__
906 909
907#include <linux/config.h> 910#include <linux/config.h>
911#include <linux/mutex.h>
908 912
909extern size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size); 913extern size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size);
910static __inline__ int rtattr_strcmp(const struct rtattr *rta, const char *str) 914static __inline__ int rtattr_strcmp(const struct rtattr *rta, const char *str)
@@ -1036,24 +1040,17 @@ __rta_reserve(struct sk_buff *skb, int attrtype, int attrlen)
1036 1040
1037extern void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change); 1041extern void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change);
1038 1042
1039extern struct semaphore rtnl_sem; 1043/* RTNL is used as a global lock for all changes to network configuration */
1040
1041#define rtnl_shlock() down(&rtnl_sem)
1042#define rtnl_shlock_nowait() down_trylock(&rtnl_sem)
1043
1044#define rtnl_shunlock() do { up(&rtnl_sem); \
1045 if (rtnl && rtnl->sk_receive_queue.qlen) \
1046 rtnl->sk_data_ready(rtnl, 0); \
1047 } while(0)
1048
1049extern void rtnl_lock(void); 1044extern void rtnl_lock(void);
1050extern int rtnl_lock_interruptible(void);
1051extern void rtnl_unlock(void); 1045extern void rtnl_unlock(void);
1046extern int rtnl_trylock(void);
1047
1052extern void rtnetlink_init(void); 1048extern void rtnetlink_init(void);
1049extern void __rtnl_unlock(void);
1053 1050
1054#define ASSERT_RTNL() do { \ 1051#define ASSERT_RTNL() do { \
1055 if (unlikely(down_trylock(&rtnl_sem) == 0)) { \ 1052 if (unlikely(rtnl_trylock())) { \
1056 up(&rtnl_sem); \ 1053 rtnl_unlock(); \
1057 printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \ 1054 printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \
1058 __FILE__, __LINE__); \ 1055 __FILE__, __LINE__); \
1059 dump_stack(); \ 1056 dump_stack(); \
diff --git a/include/linux/security.h b/include/linux/security.h
index 7cbef482e13a..b18eb8cfa639 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -1286,7 +1286,8 @@ struct security_operations {
1286 int (*socket_setsockopt) (struct socket * sock, int level, int optname); 1286 int (*socket_setsockopt) (struct socket * sock, int level, int optname);
1287 int (*socket_shutdown) (struct socket * sock, int how); 1287 int (*socket_shutdown) (struct socket * sock, int how);
1288 int (*socket_sock_rcv_skb) (struct sock * sk, struct sk_buff * skb); 1288 int (*socket_sock_rcv_skb) (struct sock * sk, struct sk_buff * skb);
1289 int (*socket_getpeersec) (struct socket *sock, char __user *optval, int __user *optlen, unsigned len); 1289 int (*socket_getpeersec_stream) (struct socket *sock, char __user *optval, int __user *optlen, unsigned len);
1290 int (*socket_getpeersec_dgram) (struct sk_buff *skb, char **secdata, u32 *seclen);
1290 int (*sk_alloc_security) (struct sock *sk, int family, gfp_t priority); 1291 int (*sk_alloc_security) (struct sock *sk, int family, gfp_t priority);
1291 void (*sk_free_security) (struct sock *sk); 1292 void (*sk_free_security) (struct sock *sk);
1292 unsigned int (*sk_getsid) (struct sock *sk, struct flowi *fl, u8 dir); 1293 unsigned int (*sk_getsid) (struct sock *sk, struct flowi *fl, u8 dir);
@@ -2741,10 +2742,16 @@ static inline int security_sock_rcv_skb (struct sock * sk,
2741 return security_ops->socket_sock_rcv_skb (sk, skb); 2742 return security_ops->socket_sock_rcv_skb (sk, skb);
2742} 2743}
2743 2744
2744static inline int security_socket_getpeersec(struct socket *sock, char __user *optval, 2745static inline int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
2745 int __user *optlen, unsigned len) 2746 int __user *optlen, unsigned len)
2746{ 2747{
2747 return security_ops->socket_getpeersec(sock, optval, optlen, len); 2748 return security_ops->socket_getpeersec_stream(sock, optval, optlen, len);
2749}
2750
2751static inline int security_socket_getpeersec_dgram(struct sk_buff *skb, char **secdata,
2752 u32 *seclen)
2753{
2754 return security_ops->socket_getpeersec_dgram(skb, secdata, seclen);
2748} 2755}
2749 2756
2750static inline int security_sk_alloc(struct sock *sk, int family, gfp_t priority) 2757static inline int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
@@ -2863,8 +2870,14 @@ static inline int security_sock_rcv_skb (struct sock * sk,
2863 return 0; 2870 return 0;
2864} 2871}
2865 2872
2866static inline int security_socket_getpeersec(struct socket *sock, char __user *optval, 2873static inline int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
2867 int __user *optlen, unsigned len) 2874 int __user *optlen, unsigned len)
2875{
2876 return -ENOPROTOOPT;
2877}
2878
2879static inline int security_socket_getpeersec_dgram(struct sk_buff *skb, char **secdata,
2880 u32 *seclen)
2868{ 2881{
2869 return -ENOPROTOOPT; 2882 return -ENOPROTOOPT;
2870} 2883}
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index ad7cc22bd424..613b9513f8b9 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -270,7 +270,6 @@ struct sk_buff {
270 270
271 void (*destructor)(struct sk_buff *skb); 271 void (*destructor)(struct sk_buff *skb);
272#ifdef CONFIG_NETFILTER 272#ifdef CONFIG_NETFILTER
273 __u32 nfmark;
274 struct nf_conntrack *nfct; 273 struct nf_conntrack *nfct;
275#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 274#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
276 struct sk_buff *nfct_reasm; 275 struct sk_buff *nfct_reasm;
@@ -278,6 +277,7 @@ struct sk_buff {
278#ifdef CONFIG_BRIDGE_NETFILTER 277#ifdef CONFIG_BRIDGE_NETFILTER
279 struct nf_bridge_info *nf_bridge; 278 struct nf_bridge_info *nf_bridge;
280#endif 279#endif
280 __u32 nfmark;
281#endif /* CONFIG_NETFILTER */ 281#endif /* CONFIG_NETFILTER */
282#ifdef CONFIG_NET_SCHED 282#ifdef CONFIG_NET_SCHED
283 __u16 tc_index; /* traffic control index */ 283 __u16 tc_index; /* traffic control index */
@@ -304,6 +304,7 @@ struct sk_buff {
304 304
305#include <asm/system.h> 305#include <asm/system.h>
306 306
307extern void kfree_skb(struct sk_buff *skb);
307extern void __kfree_skb(struct sk_buff *skb); 308extern void __kfree_skb(struct sk_buff *skb);
308extern struct sk_buff *__alloc_skb(unsigned int size, 309extern struct sk_buff *__alloc_skb(unsigned int size,
309 gfp_t priority, int fclone); 310 gfp_t priority, int fclone);
@@ -404,22 +405,6 @@ static inline struct sk_buff *skb_get(struct sk_buff *skb)
404 */ 405 */
405 406
406/** 407/**
407 * kfree_skb - free an sk_buff
408 * @skb: buffer to free
409 *
410 * Drop a reference to the buffer and free it if the usage count has
411 * hit zero.
412 */
413static inline void kfree_skb(struct sk_buff *skb)
414{
415 if (likely(atomic_read(&skb->users) == 1))
416 smp_rmb();
417 else if (likely(!atomic_dec_and_test(&skb->users)))
418 return;
419 __kfree_skb(skb);
420}
421
422/**
423 * skb_cloned - is the buffer a clone 408 * skb_cloned - is the buffer a clone
424 * @skb: buffer to check 409 * @skb: buffer to check
425 * 410 *
@@ -1174,12 +1159,14 @@ static inline int skb_linearize(struct sk_buff *skb, gfp_t gfp)
1174 */ 1159 */
1175 1160
1176static inline void skb_postpull_rcsum(struct sk_buff *skb, 1161static inline void skb_postpull_rcsum(struct sk_buff *skb,
1177 const void *start, int len) 1162 const void *start, unsigned int len)
1178{ 1163{
1179 if (skb->ip_summed == CHECKSUM_HW) 1164 if (skb->ip_summed == CHECKSUM_HW)
1180 skb->csum = csum_sub(skb->csum, csum_partial(start, len, 0)); 1165 skb->csum = csum_sub(skb->csum, csum_partial(start, len, 0));
1181} 1166}
1182 1167
1168unsigned char *skb_pull_rcsum(struct sk_buff *skb, unsigned int len);
1169
1183/** 1170/**
1184 * pskb_trim_rcsum - trim received skb and update checksum 1171 * pskb_trim_rcsum - trim received skb and update checksum
1185 * @skb: buffer to trim 1172 * @skb: buffer to trim
@@ -1351,16 +1338,6 @@ static inline void nf_conntrack_put_reasm(struct sk_buff *skb)
1351 kfree_skb(skb); 1338 kfree_skb(skb);
1352} 1339}
1353#endif 1340#endif
1354static inline void nf_reset(struct sk_buff *skb)
1355{
1356 nf_conntrack_put(skb->nfct);
1357 skb->nfct = NULL;
1358#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1359 nf_conntrack_put_reasm(skb->nfct_reasm);
1360 skb->nfct_reasm = NULL;
1361#endif
1362}
1363
1364#ifdef CONFIG_BRIDGE_NETFILTER 1341#ifdef CONFIG_BRIDGE_NETFILTER
1365static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge) 1342static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
1366{ 1343{
@@ -1373,6 +1350,20 @@ static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
1373 atomic_inc(&nf_bridge->use); 1350 atomic_inc(&nf_bridge->use);
1374} 1351}
1375#endif /* CONFIG_BRIDGE_NETFILTER */ 1352#endif /* CONFIG_BRIDGE_NETFILTER */
1353static inline void nf_reset(struct sk_buff *skb)
1354{
1355 nf_conntrack_put(skb->nfct);
1356 skb->nfct = NULL;
1357#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1358 nf_conntrack_put_reasm(skb->nfct_reasm);
1359 skb->nfct_reasm = NULL;
1360#endif
1361#ifdef CONFIG_BRIDGE_NETFILTER
1362 nf_bridge_put(skb->nf_bridge);
1363 skb->nf_bridge = NULL;
1364#endif
1365}
1366
1376#else /* CONFIG_NETFILTER */ 1367#else /* CONFIG_NETFILTER */
1377static inline void nf_reset(struct sk_buff *skb) {} 1368static inline void nf_reset(struct sk_buff *skb) {}
1378#endif /* CONFIG_NETFILTER */ 1369#endif /* CONFIG_NETFILTER */
diff --git a/include/linux/socket.h b/include/linux/socket.h
index b02dda4ee83d..9ab2ddd80221 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -150,6 +150,7 @@ __KINLINE struct cmsghdr * cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr *__
150 150
151#define SCM_RIGHTS 0x01 /* rw: access rights (array of int) */ 151#define SCM_RIGHTS 0x01 /* rw: access rights (array of int) */
152#define SCM_CREDENTIALS 0x02 /* rw: struct ucred */ 152#define SCM_CREDENTIALS 0x02 /* rw: struct ucred */
153#define SCM_SECURITY 0x03 /* rw: security label */
153 154
154struct ucred { 155struct ucred {
155 __u32 pid; 156 __u32 pid;
diff --git a/include/linux/sunrpc/svcsock.h b/include/linux/sunrpc/svcsock.h
index d33c6face032..b4acb3d37c3f 100644
--- a/include/linux/sunrpc/svcsock.h
+++ b/include/linux/sunrpc/svcsock.h
@@ -36,7 +36,7 @@ struct svc_sock {
36 36
37 struct list_head sk_deferred; /* deferred requests that need to 37 struct list_head sk_deferred; /* deferred requests that need to
38 * be revisted */ 38 * be revisted */
39 struct semaphore sk_sem; /* to serialize sending data */ 39 struct mutex sk_mutex; /* to serialize sending data */
40 40
41 int (*sk_recvfrom)(struct svc_rqst *rqstp); 41 int (*sk_recvfrom)(struct svc_rqst *rqstp);
42 int (*sk_sendto)(struct svc_rqst *rqstp); 42 int (*sk_sendto)(struct svc_rqst *rqstp);
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index bac61db26456..76eaeff76f82 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -211,6 +211,7 @@ enum
211 NET_SCTP=17, 211 NET_SCTP=17,
212 NET_LLC=18, 212 NET_LLC=18,
213 NET_NETFILTER=19, 213 NET_NETFILTER=19,
214 NET_DCCP=20,
214}; 215};
215 216
216/* /proc/sys/kernel/random */ 217/* /proc/sys/kernel/random */
@@ -261,6 +262,8 @@ enum
261 NET_CORE_DEV_WEIGHT=17, 262 NET_CORE_DEV_WEIGHT=17,
262 NET_CORE_SOMAXCONN=18, 263 NET_CORE_SOMAXCONN=18,
263 NET_CORE_BUDGET=19, 264 NET_CORE_BUDGET=19,
265 NET_CORE_AEVENT_ETIME=20,
266 NET_CORE_AEVENT_RSEQTH=21,
264}; 267};
265 268
266/* /proc/sys/net/ethernet */ 269/* /proc/sys/net/ethernet */
@@ -397,6 +400,9 @@ enum
397 NET_TCP_CONG_CONTROL=110, 400 NET_TCP_CONG_CONTROL=110,
398 NET_TCP_ABC=111, 401 NET_TCP_ABC=111,
399 NET_IPV4_IPFRAG_MAX_DIST=112, 402 NET_IPV4_IPFRAG_MAX_DIST=112,
403 NET_TCP_MTU_PROBING=113,
404 NET_TCP_BASE_MSS=114,
405 NET_IPV4_TCP_WORKAROUND_SIGNED_WINDOWS=115,
400}; 406};
401 407
402enum { 408enum {
@@ -451,6 +457,7 @@ enum
451 NET_IPV4_CONF_ARP_ANNOUNCE=18, 457 NET_IPV4_CONF_ARP_ANNOUNCE=18,
452 NET_IPV4_CONF_ARP_IGNORE=19, 458 NET_IPV4_CONF_ARP_IGNORE=19,
453 NET_IPV4_CONF_PROMOTE_SECONDARIES=20, 459 NET_IPV4_CONF_PROMOTE_SECONDARIES=20,
460 NET_IPV4_CONF_ARP_ACCEPT=21,
454 __NET_IPV4_CONF_MAX 461 __NET_IPV4_CONF_MAX
455}; 462};
456 463
@@ -531,6 +538,11 @@ enum {
531 NET_IPV6_MAX_DESYNC_FACTOR=15, 538 NET_IPV6_MAX_DESYNC_FACTOR=15,
532 NET_IPV6_MAX_ADDRESSES=16, 539 NET_IPV6_MAX_ADDRESSES=16,
533 NET_IPV6_FORCE_MLD_VERSION=17, 540 NET_IPV6_FORCE_MLD_VERSION=17,
541 NET_IPV6_ACCEPT_RA_DEFRTR=18,
542 NET_IPV6_ACCEPT_RA_PINFO=19,
543 NET_IPV6_ACCEPT_RA_RTR_PREF=20,
544 NET_IPV6_RTR_PROBE_INTERVAL=21,
545 NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN=22,
534 __NET_IPV6_MAX 546 __NET_IPV6_MAX
535}; 547};
536 548
@@ -562,6 +574,21 @@ enum {
562 __NET_NEIGH_MAX 574 __NET_NEIGH_MAX
563}; 575};
564 576
577/* /proc/sys/net/dccp */
578enum {
579 NET_DCCP_DEFAULT=1,
580};
581
582/* /proc/sys/net/dccp/default */
583enum {
584 NET_DCCP_DEFAULT_SEQ_WINDOW = 1,
585 NET_DCCP_DEFAULT_RX_CCID = 2,
586 NET_DCCP_DEFAULT_TX_CCID = 3,
587 NET_DCCP_DEFAULT_ACK_RATIO = 4,
588 NET_DCCP_DEFAULT_SEND_ACKVEC = 5,
589 NET_DCCP_DEFAULT_SEND_NDP = 6,
590};
591
565/* /proc/sys/net/ipx */ 592/* /proc/sys/net/ipx */
566enum { 593enum {
567 NET_IPX_PPROP_BROADCASTING=1, 594 NET_IPX_PPROP_BROADCASTING=1,
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index f2bb2396853f..542d39596bd8 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -343,6 +343,12 @@ struct tcp_sock {
343 __u32 seq; 343 __u32 seq;
344 __u32 time; 344 __u32 time;
345 } rcvq_space; 345 } rcvq_space;
346
347/* TCP-specific MTU probe information. */
348 struct {
349 __u32 probe_seq_start;
350 __u32 probe_seq_end;
351 } mtu_probe;
346}; 352};
347 353
348static inline struct tcp_sock *tcp_sk(const struct sock *sk) 354static inline struct tcp_sock *tcp_sk(const struct sock *sk)
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 827cc6de5f5c..130d125fda12 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -1018,8 +1018,6 @@ extern int usb_get_descriptor(struct usb_device *dev, unsigned char desctype,
1018 unsigned char descindex, void *buf, int size); 1018 unsigned char descindex, void *buf, int size);
1019extern int usb_get_status(struct usb_device *dev, 1019extern int usb_get_status(struct usb_device *dev,
1020 int type, int target, void *data); 1020 int type, int target, void *data);
1021extern int usb_get_string(struct usb_device *dev,
1022 unsigned short langid, unsigned char index, void *buf, int size);
1023extern int usb_string(struct usb_device *dev, int index, 1021extern int usb_string(struct usb_device *dev, int index,
1024 char *buf, size_t size); 1022 char *buf, size_t size);
1025 1023
diff --git a/include/linux/usb_gadget.h b/include/linux/usb_gadget.h
index ff81117eb733..1d78870ed8af 100644
--- a/include/linux/usb_gadget.h
+++ b/include/linux/usb_gadget.h
@@ -801,7 +801,9 @@ struct usb_gadget_driver {
801 * Call this in your gadget driver's module initialization function, 801 * Call this in your gadget driver's module initialization function,
802 * to tell the underlying usb controller driver about your driver. 802 * to tell the underlying usb controller driver about your driver.
803 * The driver's bind() function will be called to bind it to a 803 * The driver's bind() function will be called to bind it to a
804 * gadget. This function must be called in a context that can sleep. 804 * gadget before this registration call returns. It's expected that
805 * the bind() functions will be in init sections.
806 * This function must be called in a context that can sleep.
805 */ 807 */
806int usb_gadget_register_driver (struct usb_gadget_driver *driver); 808int usb_gadget_register_driver (struct usb_gadget_driver *driver);
807 809
@@ -814,7 +816,8 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver);
814 * going away. If the controller is connected to a USB host, 816 * going away. If the controller is connected to a USB host,
815 * it will first disconnect(). The driver is also requested 817 * it will first disconnect(). The driver is also requested
816 * to unbind() and clean up any device state, before this procedure 818 * to unbind() and clean up any device state, before this procedure
817 * finally returns. 819 * finally returns. It's expected that the unbind() functions
820 * will in in exit sections, so may not be linked in some kernels.
818 * This function must be called in a context that can sleep. 821 * This function must be called in a context that can sleep.
819 */ 822 */
820int usb_gadget_unregister_driver (struct usb_gadget_driver *driver); 823int usb_gadget_unregister_driver (struct usb_gadget_driver *driver);
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index 5208b12d5550..724cfbf54b8a 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -17,11 +17,12 @@
17#include <linux/time.h> /* need struct timeval */ 17#include <linux/time.h> /* need struct timeval */
18#include <linux/poll.h> 18#include <linux/poll.h>
19#include <linux/device.h> 19#include <linux/device.h>
20#include <linux/mutex.h>
20#endif 21#endif
21#include <linux/compiler.h> /* need __user */ 22#include <linux/compiler.h> /* need __user */
22 23
23 24
24#define OBSOLETE_OWNER 1 /* It will be removed for 2.6.15 */ 25#define OBSOLETE_OWNER 1 /* It will be removed for 2.6.17 */
25#define HAVE_V4L2 1 26#define HAVE_V4L2 1
26 27
27/* 28/*
@@ -48,6 +49,16 @@
48 49
49#ifdef __KERNEL__ 50#ifdef __KERNEL__
50 51
52/* Minor device allocation */
53#define MINOR_VFL_TYPE_GRABBER_MIN 0
54#define MINOR_VFL_TYPE_GRABBER_MAX 63
55#define MINOR_VFL_TYPE_RADIO_MIN 64
56#define MINOR_VFL_TYPE_RADIO_MAX 127
57#define MINOR_VFL_TYPE_VTX_MIN 192
58#define MINOR_VFL_TYPE_VTX_MAX 223
59#define MINOR_VFL_TYPE_VBI_MIN 224
60#define MINOR_VFL_TYPE_VBI_MAX 255
61
51#define VFL_TYPE_GRABBER 0 62#define VFL_TYPE_GRABBER 0
52#define VFL_TYPE_VBI 1 63#define VFL_TYPE_VBI 1
53#define VFL_TYPE_RADIO 2 64#define VFL_TYPE_RADIO 2
@@ -80,7 +91,7 @@ struct video_device
80 91
81 /* for videodev.c intenal usage -- please don't touch */ 92 /* for videodev.c intenal usage -- please don't touch */
82 int users; /* video_exclusive_{open|close} ... */ 93 int users; /* video_exclusive_{open|close} ... */
83 struct semaphore lock; /* ... helper function uses these */ 94 struct mutex lock; /* ... helper function uses these */
84 char devfs_name[64]; /* devfs */ 95 char devfs_name[64]; /* devfs */
85 struct class_device class_dev; /* sysfs */ 96 struct class_device class_dev; /* sysfs */
86}; 97};
@@ -952,13 +963,68 @@ struct v4l2_sliced_vbi_format
952 __u32 reserved[2]; /* must be zero */ 963 __u32 reserved[2]; /* must be zero */
953}; 964};
954 965
955#define V4L2_SLICED_TELETEXT_B (0x0001) 966/* Teletext World System Teletext
956#define V4L2_SLICED_VPS (0x0400) 967 (WST), defined on ITU-R BT.653-2 */
957#define V4L2_SLICED_CAPTION_525 (0x1000) 968#define V4L2_SLICED_TELETEXT_PAL_B (0x000001)
958#define V4L2_SLICED_WSS_625 (0x4000) 969#define V4L2_SLICED_TELETEXT_PAL_C (0x000002)
959 970#define V4L2_SLICED_TELETEXT_NTSC_B (0x000010)
960#define V4L2_SLICED_VBI_525 (V4L2_SLICED_CAPTION_525) 971#define V4L2_SLICED_TELETEXT_SECAM (0x000020)
961#define V4L2_SLICED_VBI_625 (V4L2_SLICED_TELETEXT_B | V4L2_SLICED_VPS | V4L2_SLICED_WSS_625) 972
973/* Teletext North American Broadcast Teletext Specification
974 (NABTS), defined on ITU-R BT.653-2 */
975#define V4L2_SLICED_TELETEXT_NTSC_C (0x000040)
976#define V4L2_SLICED_TELETEXT_NTSC_D (0x000080)
977
978/* Video Program System, defined on ETS 300 231*/
979#define V4L2_SLICED_VPS (0x000400)
980
981/* Closed Caption, defined on EIA-608 */
982#define V4L2_SLICED_CAPTION_525 (0x001000)
983#define V4L2_SLICED_CAPTION_625 (0x002000)
984
985/* Wide Screen System, defined on ITU-R BT1119.1 */
986#define V4L2_SLICED_WSS_625 (0x004000)
987
988/* Wide Screen System, defined on IEC 61880 */
989#define V4L2_SLICED_WSS_525 (0x008000)
990
991/* Vertical Interval Timecode (VITC), defined on SMPTE 12M */
992#define V4l2_SLICED_VITC_625 (0x010000)
993#define V4l2_SLICED_VITC_525 (0x020000)
994
995#define V4L2_SLICED_TELETEXT_B (V4L2_SLICED_TELETEXT_PAL_B |\
996 V4L2_SLICED_TELETEXT_NTSC_B)
997
998#define V4L2_SLICED_TELETEXT (V4L2_SLICED_TELETEXT_PAL_B |\
999 V4L2_SLICED_TELETEXT_PAL_C |\
1000 V4L2_SLICED_TELETEXT_SECAM |\
1001 V4L2_SLICED_TELETEXT_NTSC_B |\
1002 V4L2_SLICED_TELETEXT_NTSC_C |\
1003 V4L2_SLICED_TELETEXT_NTSC_D)
1004
1005#define V4L2_SLICED_CAPTION (V4L2_SLICED_CAPTION_525 |\
1006 V4L2_SLICED_CAPTION_625)
1007
1008#define V4L2_SLICED_WSS (V4L2_SLICED_WSS_525 |\
1009 V4L2_SLICED_WSS_625)
1010
1011#define V4L2_SLICED_VITC (V4L2_SLICED_VITC_525 |\
1012 V4L2_SLICED_VITC_625)
1013
1014#define V4L2_SLICED_VBI_525 (V4L2_SLICED_TELETEXT_NTSC_B |\
1015 V4L2_SLICED_TELETEXT_NTSC_C |\
1016 V4L2_SLICED_TELETEXT_NTSC_D |\
1017 V4L2_SLICED_CAPTION_525 |\
1018 V4L2_SLICED_WSS_525 |\
1019 V4l2_SLICED_VITC_525)
1020
1021#define V4L2_SLICED_VBI_625 (V4L2_SLICED_TELETEXT_PAL_B |\
1022 V4L2_SLICED_TELETEXT_PAL_C |\
1023 V4L2_SLICED_TELETEXT_SECAM |\
1024 V4L2_SLICED_VPS |\
1025 V4L2_SLICED_CAPTION_625 |\
1026 V4L2_SLICED_WSS_625 |\
1027 V4l2_SLICED_VITC_625)
962 1028
963struct v4l2_sliced_vbi_cap 1029struct v4l2_sliced_vbi_cap
964{ 1030{
diff --git a/include/linux/xfrm.h b/include/linux/xfrm.h
index 82fbb758e28f..6b42cc474c01 100644
--- a/include/linux/xfrm.h
+++ b/include/linux/xfrm.h
@@ -156,6 +156,10 @@ enum {
156 XFRM_MSG_FLUSHPOLICY, 156 XFRM_MSG_FLUSHPOLICY,
157#define XFRM_MSG_FLUSHPOLICY XFRM_MSG_FLUSHPOLICY 157#define XFRM_MSG_FLUSHPOLICY XFRM_MSG_FLUSHPOLICY
158 158
159 XFRM_MSG_NEWAE,
160#define XFRM_MSG_NEWAE XFRM_MSG_NEWAE
161 XFRM_MSG_GETAE,
162#define XFRM_MSG_GETAE XFRM_MSG_GETAE
159 __XFRM_MSG_MAX 163 __XFRM_MSG_MAX
160}; 164};
161#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1) 165#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)
@@ -194,6 +198,21 @@ struct xfrm_encap_tmpl {
194 xfrm_address_t encap_oa; 198 xfrm_address_t encap_oa;
195}; 199};
196 200
201/* AEVENT flags */
202enum xfrm_ae_ftype_t {
203 XFRM_AE_UNSPEC,
204 XFRM_AE_RTHR=1, /* replay threshold*/
205 XFRM_AE_RVAL=2, /* replay value */
206 XFRM_AE_LVAL=4, /* lifetime value */
207 XFRM_AE_ETHR=8, /* expiry timer threshold */
208 XFRM_AE_CR=16, /* Event cause is replay update */
209 XFRM_AE_CE=32, /* Event cause is timer expiry */
210 XFRM_AE_CU=64, /* Event cause is policy update */
211 __XFRM_AE_MAX
212
213#define XFRM_AE_MAX (__XFRM_AE_MAX - 1)
214};
215
197/* Netlink message attributes. */ 216/* Netlink message attributes. */
198enum xfrm_attr_type_t { 217enum xfrm_attr_type_t {
199 XFRMA_UNSPEC, 218 XFRMA_UNSPEC,
@@ -205,6 +224,10 @@ enum xfrm_attr_type_t {
205 XFRMA_SA, 224 XFRMA_SA,
206 XFRMA_POLICY, 225 XFRMA_POLICY,
207 XFRMA_SEC_CTX, /* struct xfrm_sec_ctx */ 226 XFRMA_SEC_CTX, /* struct xfrm_sec_ctx */
227 XFRMA_LTIME_VAL,
228 XFRMA_REPLAY_VAL,
229 XFRMA_REPLAY_THRESH,
230 XFRMA_ETIMER_THRESH,
208 __XFRMA_MAX 231 __XFRMA_MAX
209 232
210#define XFRMA_MAX (__XFRMA_MAX - 1) 233#define XFRMA_MAX (__XFRMA_MAX - 1)
@@ -235,6 +258,11 @@ struct xfrm_usersa_id {
235 __u8 proto; 258 __u8 proto;
236}; 259};
237 260
261struct xfrm_aevent_id {
262 struct xfrm_usersa_id sa_id;
263 __u32 flags;
264};
265
238struct xfrm_userspi_info { 266struct xfrm_userspi_info {
239 struct xfrm_usersa_info info; 267 struct xfrm_usersa_info info;
240 __u32 min; 268 __u32 min;
@@ -306,6 +334,8 @@ enum xfrm_nlgroups {
306#define XFRMNLGRP_SA XFRMNLGRP_SA 334#define XFRMNLGRP_SA XFRMNLGRP_SA
307 XFRMNLGRP_POLICY, 335 XFRMNLGRP_POLICY,
308#define XFRMNLGRP_POLICY XFRMNLGRP_POLICY 336#define XFRMNLGRP_POLICY XFRMNLGRP_POLICY
337 XFRMNLGRP_AEVENTS,
338#define XFRMNLGRP_AEVENTS XFRMNLGRP_AEVENTS
309 __XFRMNLGRP_MAX 339 __XFRMNLGRP_MAX
310}; 340};
311#define XFRMNLGRP_MAX (__XFRMNLGRP_MAX - 1) 341#define XFRMNLGRP_MAX (__XFRMNLGRP_MAX - 1)
diff --git a/include/media/ir-common.h b/include/media/ir-common.h
index ad3e9bb670c3..302d5b3946e7 100644
--- a/include/media/ir-common.h
+++ b/include/media/ir-common.h
@@ -47,13 +47,6 @@ struct ir_input_state {
47 int keypressed; /* current state */ 47 int keypressed; /* current state */
48}; 48};
49 49
50extern IR_KEYTAB_TYPE ir_codes_rc5_tv[IR_KEYTAB_SIZE];
51extern IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE];
52extern IR_KEYTAB_TYPE ir_codes_pinnacle[IR_KEYTAB_SIZE];
53extern IR_KEYTAB_TYPE ir_codes_empty[IR_KEYTAB_SIZE];
54extern IR_KEYTAB_TYPE ir_codes_hauppauge_new[IR_KEYTAB_SIZE];
55extern IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE];
56
57void ir_input_init(struct input_dev *dev, struct ir_input_state *ir, 50void ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
58 int ir_type, IR_KEYTAB_TYPE *ir_codes); 51 int ir_type, IR_KEYTAB_TYPE *ir_codes);
59void ir_input_nokey(struct input_dev *dev, struct ir_input_state *ir); 52void ir_input_nokey(struct input_dev *dev, struct ir_input_state *ir);
@@ -64,6 +57,39 @@ int ir_dump_samples(u32 *samples, int count);
64int ir_decode_biphase(u32 *samples, int count, int low, int high); 57int ir_decode_biphase(u32 *samples, int count, int low, int high);
65int ir_decode_pulsedistance(u32 *samples, int count, int low, int high); 58int ir_decode_pulsedistance(u32 *samples, int count, int low, int high);
66 59
60/* Keymaps to be used by other modules */
61
62extern IR_KEYTAB_TYPE ir_codes_empty[IR_KEYTAB_SIZE];
63extern IR_KEYTAB_TYPE ir_codes_avermedia[IR_KEYTAB_SIZE];
64extern IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE];
65extern IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE];
66extern IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE];
67extern IR_KEYTAB_TYPE ir_codes_nebula[IR_KEYTAB_SIZE];
68extern IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t[IR_KEYTAB_SIZE];
69extern IR_KEYTAB_TYPE ir_codes_iodata_bctv7e[IR_KEYTAB_SIZE];
70extern IR_KEYTAB_TYPE ir_codes_adstech_dvb_t_pci[IR_KEYTAB_SIZE];
71extern IR_KEYTAB_TYPE ir_codes_msi_tvanywhere[IR_KEYTAB_SIZE];
72extern IR_KEYTAB_TYPE ir_codes_cinergy_1400[IR_KEYTAB_SIZE];
73extern IR_KEYTAB_TYPE ir_codes_avertv_303[IR_KEYTAB_SIZE];
74extern IR_KEYTAB_TYPE ir_codes_dntv_live_dvbt_pro[IR_KEYTAB_SIZE];
75extern IR_KEYTAB_TYPE ir_codes_em_terratec[IR_KEYTAB_SIZE];
76extern IR_KEYTAB_TYPE ir_codes_em_pinnacle_usb[IR_KEYTAB_SIZE];
77extern IR_KEYTAB_TYPE ir_codes_flyvideo[IR_KEYTAB_SIZE];
78extern IR_KEYTAB_TYPE ir_codes_flydvb[IR_KEYTAB_SIZE];
79extern IR_KEYTAB_TYPE ir_codes_cinergy[IR_KEYTAB_SIZE];
80extern IR_KEYTAB_TYPE ir_codes_eztv[IR_KEYTAB_SIZE];
81extern IR_KEYTAB_TYPE ir_codes_avermedia[IR_KEYTAB_SIZE];
82extern IR_KEYTAB_TYPE ir_codes_videomate_tv_pvr[IR_KEYTAB_SIZE];
83extern IR_KEYTAB_TYPE ir_codes_manli[IR_KEYTAB_SIZE];
84extern IR_KEYTAB_TYPE ir_codes_gotview7135[IR_KEYTAB_SIZE];
85extern IR_KEYTAB_TYPE ir_codes_purpletv[IR_KEYTAB_SIZE];
86extern IR_KEYTAB_TYPE ir_codes_pctv_sedna[IR_KEYTAB_SIZE];
87extern IR_KEYTAB_TYPE ir_codes_pv951[IR_KEYTAB_SIZE];
88extern IR_KEYTAB_TYPE ir_codes_rc5_tv[IR_KEYTAB_SIZE];
89extern IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE];
90extern IR_KEYTAB_TYPE ir_codes_pinnacle[IR_KEYTAB_SIZE];
91extern IR_KEYTAB_TYPE ir_codes_hauppauge_new[IR_KEYTAB_SIZE];
92
67#endif 93#endif
68 94
69/* 95/*
diff --git a/include/media/saa7146.h b/include/media/saa7146.h
index 2bc634fcb7bb..fee579f10b32 100644
--- a/include/media/saa7146.h
+++ b/include/media/saa7146.h
@@ -11,6 +11,8 @@
11#include <linux/i2c.h> /* for i2c subsystem */ 11#include <linux/i2c.h> /* for i2c subsystem */
12#include <asm/io.h> /* for accessing devices */ 12#include <asm/io.h> /* for accessing devices */
13#include <linux/stringify.h> 13#include <linux/stringify.h>
14#include <linux/mutex.h>
15
14#include <linux/vmalloc.h> /* for vmalloc() */ 16#include <linux/vmalloc.h> /* for vmalloc() */
15#include <linux/mm.h> /* for vmalloc_to_page() */ 17#include <linux/mm.h> /* for vmalloc_to_page() */
16 18
@@ -112,7 +114,7 @@ struct saa7146_dev
112 114
113 /* different device locks */ 115 /* different device locks */
114 spinlock_t slock; 116 spinlock_t slock;
115 struct semaphore lock; 117 struct mutex lock;
116 118
117 unsigned char __iomem *mem; /* pointer to mapped IO memory */ 119 unsigned char __iomem *mem; /* pointer to mapped IO memory */
118 int revision; /* chip revision; needed for bug-workarounds*/ 120 int revision; /* chip revision; needed for bug-workarounds*/
@@ -133,15 +135,16 @@ struct saa7146_dev
133 void (*vv_callback)(struct saa7146_dev *dev, unsigned long status); 135 void (*vv_callback)(struct saa7146_dev *dev, unsigned long status);
134 136
135 /* i2c-stuff */ 137 /* i2c-stuff */
136 struct semaphore i2c_lock; 138 struct mutex i2c_lock;
137 u32 i2c_bitrate; 139
138 struct saa7146_dma d_i2c; /* pointer to i2c memory */ 140 u32 i2c_bitrate;
139 wait_queue_head_t i2c_wq; 141 struct saa7146_dma d_i2c; /* pointer to i2c memory */
140 int i2c_op; 142 wait_queue_head_t i2c_wq;
143 int i2c_op;
141 144
142 /* memories */ 145 /* memories */
143 struct saa7146_dma d_rps0; 146 struct saa7146_dma d_rps0;
144 struct saa7146_dma d_rps1; 147 struct saa7146_dma d_rps1;
145}; 148};
146 149
147/* from saa7146_i2c.c */ 150/* from saa7146_i2c.c */
@@ -150,7 +153,7 @@ int saa7146_i2c_transfer(struct saa7146_dev *saa, const struct i2c_msg *msgs, in
150 153
151/* from saa7146_core.c */ 154/* from saa7146_core.c */
152extern struct list_head saa7146_devices; 155extern struct list_head saa7146_devices;
153extern struct semaphore saa7146_devices_lock; 156extern struct mutex saa7146_devices_lock;
154int saa7146_register_extension(struct saa7146_extension*); 157int saa7146_register_extension(struct saa7146_extension*);
155int saa7146_unregister_extension(struct saa7146_extension*); 158int saa7146_unregister_extension(struct saa7146_extension*);
156struct saa7146_format* format_by_fourcc(struct saa7146_dev *dev, int fourcc); 159struct saa7146_format* format_by_fourcc(struct saa7146_dev *dev, int fourcc);
diff --git a/include/media/tuner-types.h b/include/media/tuner-types.h
index 15821ab14a9e..ad9c171bfa07 100644
--- a/include/media/tuner-types.h
+++ b/include/media/tuner-types.h
@@ -14,6 +14,7 @@ enum param_type {
14 14
15struct tuner_range { 15struct tuner_range {
16 unsigned short limit; 16 unsigned short limit;
17 unsigned char config;
17 unsigned char cb; 18 unsigned char cb;
18}; 19};
19 20
@@ -38,7 +39,6 @@ struct tuner_params {
38 * static unless the control byte was sent first. 39 * static unless the control byte was sent first.
39 */ 40 */
40 unsigned int cb_first_if_lower_freq:1; 41 unsigned int cb_first_if_lower_freq:1;
41 unsigned char config; /* to be moved into struct tuner_range for dvb-pll merge */
42 42
43 unsigned int count; 43 unsigned int count;
44 struct tuner_range *ranges; 44 struct tuner_range *ranges;
@@ -46,6 +46,7 @@ struct tuner_params {
46 46
47struct tunertype { 47struct tunertype {
48 char *name; 48 char *name;
49 unsigned int count;
49 struct tuner_params *params; 50 struct tuner_params *params;
50}; 51};
51 52
diff --git a/include/media/tuner.h b/include/media/tuner.h
index a5beeac495c7..017fed7d5e4d 100644
--- a/include/media/tuner.h
+++ b/include/media/tuner.h
@@ -110,12 +110,15 @@
110 110
111#define TUNER_LG_TDVS_H062F 64 /* DViCO FusionHDTV 5 */ 111#define TUNER_LG_TDVS_H062F 64 /* DViCO FusionHDTV 5 */
112#define TUNER_YMEC_TVF66T5_B_DFF 65 /* Acorp Y878F */ 112#define TUNER_YMEC_TVF66T5_B_DFF 65 /* Acorp Y878F */
113#define TUNER_LG_NTSC_TALN_MINI 66 113#define TUNER_LG_TALN 66
114#define TUNER_PHILIPS_TD1316 67 114#define TUNER_PHILIPS_TD1316 67
115 115
116#define TUNER_PHILIPS_TUV1236D 68 /* ATI HDTV Wonder */ 116#define TUNER_PHILIPS_TUV1236D 68 /* ATI HDTV Wonder */
117#define TUNER_TNF_5335MF 69 /* Sabrent Bt848 */ 117#define TUNER_TNF_5335MF 69 /* Sabrent Bt848 */
118#define TUNER_SAMSUNG_TCPN_2121P30A 70 /* Hauppauge PVR-500MCE NTSC */ 118#define TUNER_SAMSUNG_TCPN_2121P30A 70 /* Hauppauge PVR-500MCE NTSC */
119#define TUNER_XCEIVE_XC3028 71
120
121#define TUNER_THOMSON_FE6600 72 /* DViCO FusionHDTV DVB-T Hybrid */
119 122
120/* tv card specific */ 123/* tv card specific */
121#define TDA9887_PRESENT (1<<0) 124#define TDA9887_PRESENT (1<<0)
@@ -209,6 +212,7 @@ struct tuner {
209extern unsigned const int tuner_count; 212extern unsigned const int tuner_count;
210 213
211extern int microtune_init(struct i2c_client *c); 214extern int microtune_init(struct i2c_client *c);
215extern int xc3028_init(struct i2c_client *c);
212extern int tda8290_init(struct i2c_client *c); 216extern int tda8290_init(struct i2c_client *c);
213extern int tda8290_probe(struct i2c_client *c); 217extern int tda8290_probe(struct i2c_client *c);
214extern int tea5767_tuner_init(struct i2c_client *c); 218extern int tea5767_tuner_init(struct i2c_client *c);
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index d4030a7e16e0..2360453e7496 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -58,6 +58,9 @@
58/* Prints the ioctl in a human-readable format */ 58/* Prints the ioctl in a human-readable format */
59extern void v4l_printk_ioctl(unsigned int cmd); 59extern void v4l_printk_ioctl(unsigned int cmd);
60 60
61/* Prints the ioctl and arg in a human-readable format */
62extern void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg);
63
61/* Use this macro for non-I2C drivers. Pass the driver name as the first arg. */ 64/* Use this macro for non-I2C drivers. Pass the driver name as the first arg. */
62#define v4l_print_ioctl(name, cmd) \ 65#define v4l_print_ioctl(name, cmd) \
63 do { \ 66 do { \
@@ -100,6 +103,7 @@ enum v4l2_chip_ident {
100 V4L2_IDENT_UNKNOWN = 0, 103 V4L2_IDENT_UNKNOWN = 0,
101 104
102 /* module saa7115: reserved range 100-149 */ 105 /* module saa7115: reserved range 100-149 */
106 V4L2_IDENT_SAA7113 = 103,
103 V4L2_IDENT_SAA7114 = 104, 107 V4L2_IDENT_SAA7114 = 104,
104 V4L2_IDENT_SAA7115 = 105, 108 V4L2_IDENT_SAA7115 = 105,
105 109
@@ -115,12 +119,15 @@ enum v4l2_chip_ident {
115}; 119};
116 120
117/* audio ioctls */ 121/* audio ioctls */
118/* v4l device was opened in Radio mode */ 122
123/* v4l device was opened in Radio mode, to be replaced by VIDIOC_INT_S_TUNER_MODE */
119#define AUDC_SET_RADIO _IO('d',88) 124#define AUDC_SET_RADIO _IO('d',88)
120/* select from TV,radio,extern,MUTE */ 125
126/* select from TV,radio,extern,MUTE, to be replaced with VIDIOC_INT_S_AUDIO_ROUTING */
121#define AUDC_SET_INPUT _IOW('d',89,int) 127#define AUDC_SET_INPUT _IOW('d',89,int)
122 128
123/* msp3400 ioctl: will be removed in the near future */ 129/* msp3400 ioctl: will be removed in the near future, to be replaced by
130 VIDIOC_INT_S_AUDIO_ROUTING. */
124struct msp_matrix { 131struct msp_matrix {
125 int input; 132 int input;
126 int output; 133 int output;
@@ -128,12 +135,25 @@ struct msp_matrix {
128#define MSP_SET_MATRIX _IOW('m',17,struct msp_matrix) 135#define MSP_SET_MATRIX _IOW('m',17,struct msp_matrix)
129 136
130/* tuner ioctls */ 137/* tuner ioctls */
138
131/* Sets tuner type and its I2C addr */ 139/* Sets tuner type and its I2C addr */
132#define TUNER_SET_TYPE_ADDR _IOW('d',90,int) 140#define TUNER_SET_TYPE_ADDR _IOW('d', 90, int)
133/* Puts tuner on powersaving state, disabling it, except for i2c */ 141
134#define TUNER_SET_STANDBY _IOW('d',91,int) 142/* Puts tuner on powersaving state, disabling it, except for i2c. To be replaced
143 by VIDIOC_INT_S_STANDBY. */
144#define TUNER_SET_STANDBY _IOW('d', 91, int)
145
135/* Sets tda9887 specific stuff, like port1, port2 and qss */ 146/* Sets tda9887 specific stuff, like port1, port2 and qss */
136#define TDA9887_SET_CONFIG _IOW('d',92,int) 147#define TDA9887_SET_CONFIG _IOW('d', 92, int)
148
149/* Switch the tuner to a specific tuner mode. Replacement of AUDC_SET_RADIO */
150#define VIDIOC_INT_S_TUNER_MODE _IOW('d', 93, enum v4l2_tuner_type)
151
152/* Generic standby command. Passing -1 (all bits set to 1) will put the whole
153 chip into standby mode, value 0 will make the chip fully active. Specific
154 bits can be used by certain chips to enable/disable specific subsystems.
155 Replacement of TUNER_SET_STANDBY. */
156#define VIDIOC_INT_S_STANDBY _IOW('d', 94, u32)
137 157
138/* only implemented if CONFIG_VIDEO_ADV_DEBUG is defined */ 158/* only implemented if CONFIG_VIDEO_ADV_DEBUG is defined */
139#define VIDIOC_INT_S_REGISTER _IOR ('d', 100, struct v4l2_register) 159#define VIDIOC_INT_S_REGISTER _IOR ('d', 100, struct v4l2_register)
@@ -160,7 +180,8 @@ struct msp_matrix {
160 180
161/* Used to generate VBI signals on a video signal. v4l2_sliced_vbi_data is 181/* Used to generate VBI signals on a video signal. v4l2_sliced_vbi_data is
162 filled with the data packets that should be output. Note that if you set 182 filled with the data packets that should be output. Note that if you set
163 the line field to 0, then that VBI signal is disabled. */ 183 the line field to 0, then that VBI signal is disabled. If no
184 valid VBI data was found, then the type field is set to 0 on return. */
164#define VIDIOC_INT_S_VBI_DATA _IOW ('d', 105, struct v4l2_sliced_vbi_data) 185#define VIDIOC_INT_S_VBI_DATA _IOW ('d', 105, struct v4l2_sliced_vbi_data)
165 186
166/* Used to obtain the sliced VBI packet from a readback register. Not all 187/* Used to obtain the sliced VBI packet from a readback register. Not all
@@ -168,11 +189,11 @@ struct msp_matrix {
168 register contains invalid or erroneous data -EIO is returned. Note that 189 register contains invalid or erroneous data -EIO is returned. Note that
169 you must fill in the 'id' member and the 'field' member (to determine 190 you must fill in the 'id' member and the 'field' member (to determine
170 whether CC data from the first or second field should be obtained). */ 191 whether CC data from the first or second field should be obtained). */
171#define VIDIOC_INT_G_VBI_DATA _IOWR('d', 106, struct v4l2_sliced_vbi_data *) 192#define VIDIOC_INT_G_VBI_DATA _IOWR('d', 106, struct v4l2_sliced_vbi_data)
172 193
173/* Returns the chip identifier or V4L2_IDENT_UNKNOWN if no identification can 194/* Returns the chip identifier or V4L2_IDENT_UNKNOWN if no identification can
174 be made. */ 195 be made. */
175#define VIDIOC_INT_G_CHIP_IDENT _IOR ('d', 107, enum v4l2_chip_ident *) 196#define VIDIOC_INT_G_CHIP_IDENT _IOR ('d', 107, enum v4l2_chip_ident)
176 197
177/* Sets I2S speed in bps. This is used to provide a standard way to select I2S 198/* Sets I2S speed in bps. This is used to provide a standard way to select I2S
178 clock used by driving digital audio streams at some board designs. 199 clock used by driving digital audio streams at some board designs.
@@ -180,4 +201,25 @@ struct msp_matrix {
180 If the frequency is not supported, then -EINVAL is returned. */ 201 If the frequency is not supported, then -EINVAL is returned. */
181#define VIDIOC_INT_I2S_CLOCK_FREQ _IOW ('d', 108, u32) 202#define VIDIOC_INT_I2S_CLOCK_FREQ _IOW ('d', 108, u32)
182 203
204/* Routing definition, device dependent. It specifies which inputs (if any)
205 should be routed to which outputs (if any). */
206struct v4l2_routing {
207 u32 input;
208 u32 output;
209};
210
211/* These internal commands should be used to define the inputs and outputs
212 of an audio/video chip. They will replace AUDC_SET_INPUT.
213 The v4l2 API commands VIDIOC_S/G_INPUT, VIDIOC_S/G_OUTPUT,
214 VIDIOC_S/G_AUDIO and VIDIOC_S/G_AUDOUT are meant to be used by the
215 user. Internally these commands should be used to switch inputs/outputs
216 because only the driver knows how to map a 'Television' input to the precise
217 input/output routing of an A/D converter, or a DSP, or a video digitizer.
218 These four commands should only be sent directly to an i2c device, they
219 should not be broadcast as the routing is very device specific. */
220#define VIDIOC_INT_S_AUDIO_ROUTING _IOW ('d', 109, struct v4l2_routing)
221#define VIDIOC_INT_G_AUDIO_ROUTING _IOR ('d', 110, struct v4l2_routing)
222#define VIDIOC_INT_S_VIDEO_ROUTING _IOW ('d', 111, struct v4l2_routing)
223#define VIDIOC_INT_G_VIDEO_ROUTING _IOR ('d', 112, struct v4l2_routing)
224
183#endif /* V4L2_COMMON_H_ */ 225#endif /* V4L2_COMMON_H_ */
diff --git a/include/media/video-buf-dvb.h b/include/media/video-buf-dvb.h
index ad0a07a3a895..b78d90fe629f 100644
--- a/include/media/video-buf-dvb.h
+++ b/include/media/video-buf-dvb.h
@@ -11,7 +11,7 @@ struct videobuf_dvb {
11 struct videobuf_queue dvbq; 11 struct videobuf_queue dvbq;
12 12
13 /* video-buf-dvb state info */ 13 /* video-buf-dvb state info */
14 struct semaphore lock; 14 struct mutex lock;
15 struct task_struct *thread; 15 struct task_struct *thread;
16 int nfeeds; 16 int nfeeds;
17 17
diff --git a/include/media/video-buf.h b/include/media/video-buf.h
index 8ecfd78e0027..d90dec5484ee 100644
--- a/include/media/video-buf.h
+++ b/include/media/video-buf.h
@@ -177,7 +177,7 @@ struct videobuf_queue_ops {
177}; 177};
178 178
179struct videobuf_queue { 179struct videobuf_queue {
180 struct semaphore lock; 180 struct mutex lock;
181 spinlock_t *irqlock; 181 spinlock_t *irqlock;
182 struct pci_dev *pci; 182 struct pci_dev *pci;
183 183
diff --git a/include/net/af_unix.h b/include/net/af_unix.h
index bfc1779fc753..427dac94bc7e 100644
--- a/include/net/af_unix.h
+++ b/include/net/af_unix.h
@@ -4,6 +4,7 @@
4#include <linux/config.h> 4#include <linux/config.h>
5#include <linux/socket.h> 5#include <linux/socket.h>
6#include <linux/un.h> 6#include <linux/un.h>
7#include <linux/mutex.h>
7#include <net/sock.h> 8#include <net/sock.h>
8 9
9extern void unix_inflight(struct file *fp); 10extern void unix_inflight(struct file *fp);
@@ -71,7 +72,7 @@ struct unix_sock {
71 struct unix_address *addr; 72 struct unix_address *addr;
72 struct dentry *dentry; 73 struct dentry *dentry;
73 struct vfsmount *mnt; 74 struct vfsmount *mnt;
74 struct semaphore readsem; 75 struct mutex readlock;
75 struct sock *peer; 76 struct sock *peer;
76 struct sock *other; 77 struct sock *other;
77 struct sock *gc_tree; 78 struct sock *gc_tree;
diff --git a/include/net/dn.h b/include/net/dn.h
index a4b6168e1e25..465b78302782 100644
--- a/include/net/dn.h
+++ b/include/net/dn.h
@@ -6,10 +6,8 @@
6#include <net/tcp.h> 6#include <net/tcp.h>
7#include <asm/byteorder.h> 7#include <asm/byteorder.h>
8 8
9typedef unsigned short dn_address; 9#define dn_ntohs(x) le16_to_cpu(x)
10 10#define dn_htons(x) cpu_to_le16(x)
11#define dn_ntohs(x) le16_to_cpu((unsigned short)(x))
12#define dn_htons(x) cpu_to_le16((unsigned short)(x))
13 11
14struct dn_scp /* Session Control Port */ 12struct dn_scp /* Session Control Port */
15{ 13{
@@ -31,36 +29,36 @@ struct dn_scp /* Session Control Port */
31#define DN_CL 15 /* Closed */ 29#define DN_CL 15 /* Closed */
32#define DN_CN 16 /* Closed Notification */ 30#define DN_CN 16 /* Closed Notification */
33 31
34 unsigned short addrloc; 32 __le16 addrloc;
35 unsigned short addrrem; 33 __le16 addrrem;
36 unsigned short numdat; 34 __u16 numdat;
37 unsigned short numoth; 35 __u16 numoth;
38 unsigned short numoth_rcv; 36 __u16 numoth_rcv;
39 unsigned short numdat_rcv; 37 __u16 numdat_rcv;
40 unsigned short ackxmt_dat; 38 __u16 ackxmt_dat;
41 unsigned short ackxmt_oth; 39 __u16 ackxmt_oth;
42 unsigned short ackrcv_dat; 40 __u16 ackrcv_dat;
43 unsigned short ackrcv_oth; 41 __u16 ackrcv_oth;
44 unsigned char flowrem_sw; 42 __u8 flowrem_sw;
45 unsigned char flowloc_sw; 43 __u8 flowloc_sw;
46#define DN_SEND 2 44#define DN_SEND 2
47#define DN_DONTSEND 1 45#define DN_DONTSEND 1
48#define DN_NOCHANGE 0 46#define DN_NOCHANGE 0
49 unsigned short flowrem_dat; 47 __u16 flowrem_dat;
50 unsigned short flowrem_oth; 48 __u16 flowrem_oth;
51 unsigned short flowloc_dat; 49 __u16 flowloc_dat;
52 unsigned short flowloc_oth; 50 __u16 flowloc_oth;
53 unsigned char services_rem; 51 __u8 services_rem;
54 unsigned char services_loc; 52 __u8 services_loc;
55 unsigned char info_rem; 53 __u8 info_rem;
56 unsigned char info_loc; 54 __u8 info_loc;
57 55
58 unsigned short segsize_rem; 56 __u16 segsize_rem;
59 unsigned short segsize_loc; 57 __u16 segsize_loc;
60 58
61 unsigned char nonagle; 59 __u8 nonagle;
62 unsigned char multi_ireq; 60 __u8 multi_ireq;
63 unsigned char accept_mode; 61 __u8 accept_mode;
64 unsigned long seg_total; /* Running total of current segment */ 62 unsigned long seg_total; /* Running total of current segment */
65 63
66 struct optdata_dn conndata_in; 64 struct optdata_dn conndata_in;
@@ -160,40 +158,41 @@ static inline struct dn_scp *DN_SK(struct sock *sk)
160 */ 158 */
161#define DN_SKB_CB(skb) ((struct dn_skb_cb *)(skb)->cb) 159#define DN_SKB_CB(skb) ((struct dn_skb_cb *)(skb)->cb)
162struct dn_skb_cb { 160struct dn_skb_cb {
163 unsigned short dst; 161 __le16 dst;
164 unsigned short src; 162 __le16 src;
165 unsigned short hops; 163 __u16 hops;
166 unsigned short dst_port; 164 __le16 dst_port;
167 unsigned short src_port; 165 __le16 src_port;
168 unsigned char services; 166 __u8 services;
169 unsigned char info; 167 __u8 info;
170 unsigned char rt_flags; 168 __u8 rt_flags;
171 unsigned char nsp_flags; 169 __u8 nsp_flags;
172 unsigned short segsize; 170 __u16 segsize;
173 unsigned short segnum; 171 __u16 segnum;
174 unsigned short xmit_count; 172 __u16 xmit_count;
175 unsigned long stamp; 173 unsigned long stamp;
176 int iif; 174 int iif;
177}; 175};
178 176
179static inline dn_address dn_eth2dn(unsigned char *ethaddr) 177static inline __le16 dn_eth2dn(unsigned char *ethaddr)
180{ 178{
181 return ethaddr[4] | (ethaddr[5] << 8); 179 return dn_htons(ethaddr[4] | (ethaddr[5] << 8));
182} 180}
183 181
184static inline dn_address dn_saddr2dn(struct sockaddr_dn *saddr) 182static inline __le16 dn_saddr2dn(struct sockaddr_dn *saddr)
185{ 183{
186 return *(dn_address *)saddr->sdn_nodeaddr; 184 return *(__le16 *)saddr->sdn_nodeaddr;
187} 185}
188 186
189static inline void dn_dn2eth(unsigned char *ethaddr, dn_address addr) 187static inline void dn_dn2eth(unsigned char *ethaddr, __le16 addr)
190{ 188{
189 __u16 a = dn_ntohs(addr);
191 ethaddr[0] = 0xAA; 190 ethaddr[0] = 0xAA;
192 ethaddr[1] = 0x00; 191 ethaddr[1] = 0x00;
193 ethaddr[2] = 0x04; 192 ethaddr[2] = 0x04;
194 ethaddr[3] = 0x00; 193 ethaddr[3] = 0x00;
195 ethaddr[4] = (unsigned char)(addr & 0xff); 194 ethaddr[4] = (__u8)(a & 0xff);
196 ethaddr[5] = (unsigned char)(addr >> 8); 195 ethaddr[5] = (__u8)(a >> 8);
197} 196}
198 197
199static inline void dn_sk_ports_copy(struct flowi *fl, struct dn_scp *scp) 198static inline void dn_sk_ports_copy(struct flowi *fl, struct dn_scp *scp)
@@ -202,7 +201,7 @@ static inline void dn_sk_ports_copy(struct flowi *fl, struct dn_scp *scp)
202 fl->uli_u.dnports.dport = scp->addrrem; 201 fl->uli_u.dnports.dport = scp->addrrem;
203 fl->uli_u.dnports.objnum = scp->addr.sdn_objnum; 202 fl->uli_u.dnports.objnum = scp->addr.sdn_objnum;
204 if (fl->uli_u.dnports.objnum == 0) { 203 if (fl->uli_u.dnports.objnum == 0) {
205 fl->uli_u.dnports.objnamel = scp->addr.sdn_objnamel; 204 fl->uli_u.dnports.objnamel = (__u8)dn_ntohs(scp->addr.sdn_objnamel);
206 memcpy(fl->uli_u.dnports.objname, scp->addr.sdn_objname, 16); 205 memcpy(fl->uli_u.dnports.objname, scp->addr.sdn_objname, 16);
207 } 206 }
208} 207}
@@ -217,7 +216,7 @@ extern unsigned dn_mss_from_pmtu(struct net_device *dev, int mtu);
217extern struct sock *dn_sklist_find_listener(struct sockaddr_dn *addr); 216extern struct sock *dn_sklist_find_listener(struct sockaddr_dn *addr);
218extern struct sock *dn_find_by_skb(struct sk_buff *skb); 217extern struct sock *dn_find_by_skb(struct sk_buff *skb);
219#define DN_ASCBUF_LEN 9 218#define DN_ASCBUF_LEN 9
220extern char *dn_addr2asc(dn_address, char *); 219extern char *dn_addr2asc(__u16, char *);
221extern int dn_destroy_timer(struct sock *sk); 220extern int dn_destroy_timer(struct sock *sk);
222 221
223extern int dn_sockaddr2username(struct sockaddr_dn *addr, unsigned char *buf, unsigned char type); 222extern int dn_sockaddr2username(struct sockaddr_dn *addr, unsigned char *buf, unsigned char type);
@@ -226,7 +225,7 @@ extern int dn_username2sockaddr(unsigned char *data, int len, struct sockaddr_dn
226extern void dn_start_slow_timer(struct sock *sk); 225extern void dn_start_slow_timer(struct sock *sk);
227extern void dn_stop_slow_timer(struct sock *sk); 226extern void dn_stop_slow_timer(struct sock *sk);
228 227
229extern dn_address decnet_address; 228extern __le16 decnet_address;
230extern int decnet_debug_level; 229extern int decnet_debug_level;
231extern int decnet_time_wait; 230extern int decnet_time_wait;
232extern int decnet_dn_count; 231extern int decnet_dn_count;
diff --git a/include/net/dn_dev.h b/include/net/dn_dev.h
index 5a86e78081bf..cee46821dc53 100644
--- a/include/net/dn_dev.h
+++ b/include/net/dn_dev.h
@@ -7,11 +7,11 @@ struct dn_dev;
7struct dn_ifaddr { 7struct dn_ifaddr {
8 struct dn_ifaddr *ifa_next; 8 struct dn_ifaddr *ifa_next;
9 struct dn_dev *ifa_dev; 9 struct dn_dev *ifa_dev;
10 dn_address ifa_local; 10 __le16 ifa_local;
11 dn_address ifa_address; 11 __le16 ifa_address;
12 unsigned char ifa_flags; 12 __u8 ifa_flags;
13 unsigned char ifa_scope; 13 __u8 ifa_scope;
14 char ifa_label[IFNAMSIZ]; 14 char ifa_label[IFNAMSIZ];
15}; 15};
16 16
17#define DN_DEV_S_RU 0 /* Run - working normally */ 17#define DN_DEV_S_RU 0 /* Run - working normally */
@@ -91,7 +91,7 @@ struct dn_dev {
91 struct timer_list timer; 91 struct timer_list timer;
92 unsigned long t3; 92 unsigned long t3;
93 struct neigh_parms *neigh_parms; 93 struct neigh_parms *neigh_parms;
94 unsigned char addr[ETH_ALEN]; 94 __u8 addr[ETH_ALEN];
95 struct neighbour *router; /* Default router on circuit */ 95 struct neighbour *router; /* Default router on circuit */
96 struct neighbour *peer; /* Peer on pointopoint links */ 96 struct neighbour *peer; /* Peer on pointopoint links */
97 unsigned long uptime; /* Time device went up in jiffies */ 97 unsigned long uptime; /* Time device went up in jiffies */
@@ -99,56 +99,56 @@ struct dn_dev {
99 99
100struct dn_short_packet 100struct dn_short_packet
101{ 101{
102 unsigned char msgflg; 102 __u8 msgflg;
103 unsigned short dstnode; 103 __le16 dstnode;
104 unsigned short srcnode; 104 __le16 srcnode;
105 unsigned char forward; 105 __u8 forward;
106} __attribute__((packed)); 106} __attribute__((packed));
107 107
108struct dn_long_packet 108struct dn_long_packet
109{ 109{
110 unsigned char msgflg; 110 __u8 msgflg;
111 unsigned char d_area; 111 __u8 d_area;
112 unsigned char d_subarea; 112 __u8 d_subarea;
113 unsigned char d_id[6]; 113 __u8 d_id[6];
114 unsigned char s_area; 114 __u8 s_area;
115 unsigned char s_subarea; 115 __u8 s_subarea;
116 unsigned char s_id[6]; 116 __u8 s_id[6];
117 unsigned char nl2; 117 __u8 nl2;
118 unsigned char visit_ct; 118 __u8 visit_ct;
119 unsigned char s_class; 119 __u8 s_class;
120 unsigned char pt; 120 __u8 pt;
121} __attribute__((packed)); 121} __attribute__((packed));
122 122
123/*------------------------- DRP - Routing messages ---------------------*/ 123/*------------------------- DRP - Routing messages ---------------------*/
124 124
125struct endnode_hello_message 125struct endnode_hello_message
126{ 126{
127 unsigned char msgflg; 127 __u8 msgflg;
128 unsigned char tiver[3]; 128 __u8 tiver[3];
129 unsigned char id[6]; 129 __u8 id[6];
130 unsigned char iinfo; 130 __u8 iinfo;
131 unsigned short blksize; 131 __le16 blksize;
132 unsigned char area; 132 __u8 area;
133 unsigned char seed[8]; 133 __u8 seed[8];
134 unsigned char neighbor[6]; 134 __u8 neighbor[6];
135 unsigned short timer; 135 __le16 timer;
136 unsigned char mpd; 136 __u8 mpd;
137 unsigned char datalen; 137 __u8 datalen;
138 unsigned char data[2]; 138 __u8 data[2];
139} __attribute__((packed)); 139} __attribute__((packed));
140 140
141struct rtnode_hello_message 141struct rtnode_hello_message
142{ 142{
143 unsigned char msgflg; 143 __u8 msgflg;
144 unsigned char tiver[3]; 144 __u8 tiver[3];
145 unsigned char id[6]; 145 __u8 id[6];
146 unsigned char iinfo; 146 __u8 iinfo;
147 unsigned short blksize; 147 __le16 blksize;
148 unsigned char priority; 148 __u8 priority;
149 unsigned char area; 149 __u8 area;
150 unsigned short timer; 150 __le16 timer;
151 unsigned char mpd; 151 __u8 mpd;
152} __attribute__((packed)); 152} __attribute__((packed));
153 153
154 154
@@ -169,12 +169,12 @@ extern void dn_dev_down(struct net_device *);
169 169
170extern int dn_dev_set_default(struct net_device *dev, int force); 170extern int dn_dev_set_default(struct net_device *dev, int force);
171extern struct net_device *dn_dev_get_default(void); 171extern struct net_device *dn_dev_get_default(void);
172extern int dn_dev_bind_default(dn_address *addr); 172extern int dn_dev_bind_default(__le16 *addr);
173 173
174extern int register_dnaddr_notifier(struct notifier_block *nb); 174extern int register_dnaddr_notifier(struct notifier_block *nb);
175extern int unregister_dnaddr_notifier(struct notifier_block *nb); 175extern int unregister_dnaddr_notifier(struct notifier_block *nb);
176 176
177static inline int dn_dev_islocal(struct net_device *dev, dn_address addr) 177static inline int dn_dev_islocal(struct net_device *dev, __le16 addr)
178{ 178{
179 struct dn_dev *dn_db = dev->dn_ptr; 179 struct dn_dev *dn_db = dev->dn_ptr;
180 struct dn_ifaddr *ifa; 180 struct dn_ifaddr *ifa;
diff --git a/include/net/dn_fib.h b/include/net/dn_fib.h
index cd3c96d9601b..a15dcf0d5c1e 100644
--- a/include/net/dn_fib.h
+++ b/include/net/dn_fib.h
@@ -37,7 +37,7 @@ struct dn_fib_nh {
37 int nh_weight; 37 int nh_weight;
38 int nh_power; 38 int nh_power;
39 int nh_oif; 39 int nh_oif;
40 u32 nh_gw; 40 __le16 nh_gw;
41}; 41};
42 42
43struct dn_fib_info { 43struct dn_fib_info {
@@ -48,7 +48,7 @@ struct dn_fib_info {
48 int fib_dead; 48 int fib_dead;
49 unsigned fib_flags; 49 unsigned fib_flags;
50 int fib_protocol; 50 int fib_protocol;
51 dn_address fib_prefsrc; 51 __le16 fib_prefsrc;
52 __u32 fib_priority; 52 __u32 fib_priority;
53 __u32 fib_metrics[RTAX_MAX]; 53 __u32 fib_metrics[RTAX_MAX];
54#define dn_fib_mtu fib_metrics[RTAX_MTU-1] 54#define dn_fib_mtu fib_metrics[RTAX_MTU-1]
@@ -71,15 +71,15 @@ struct dn_fib_info {
71#define DN_FIB_RES_OIF(res) (DN_FIB_RES_NH(res).nh_oif) 71#define DN_FIB_RES_OIF(res) (DN_FIB_RES_NH(res).nh_oif)
72 72
73typedef struct { 73typedef struct {
74 u16 datum; 74 __le16 datum;
75} dn_fib_key_t; 75} dn_fib_key_t;
76 76
77typedef struct { 77typedef struct {
78 u16 datum; 78 __le16 datum;
79} dn_fib_hash_t; 79} dn_fib_hash_t;
80 80
81typedef struct { 81typedef struct {
82 u16 datum; 82 __u16 datum;
83} dn_fib_idx_t; 83} dn_fib_idx_t;
84 84
85struct dn_fib_node { 85struct dn_fib_node {
@@ -126,11 +126,11 @@ extern int dn_fib_semantic_match(int type, struct dn_fib_info *fi,
126 const struct flowi *fl, 126 const struct flowi *fl,
127 struct dn_fib_res *res); 127 struct dn_fib_res *res);
128extern void dn_fib_release_info(struct dn_fib_info *fi); 128extern void dn_fib_release_info(struct dn_fib_info *fi);
129extern u16 dn_fib_get_attr16(struct rtattr *attr, int attrlen, int type); 129extern __le16 dn_fib_get_attr16(struct rtattr *attr, int attrlen, int type);
130extern void dn_fib_flush(void); 130extern void dn_fib_flush(void);
131extern void dn_fib_select_multipath(const struct flowi *fl, 131extern void dn_fib_select_multipath(const struct flowi *fl,
132 struct dn_fib_res *res); 132 struct dn_fib_res *res);
133extern int dn_fib_sync_down(dn_address local, struct net_device *dev, 133extern int dn_fib_sync_down(__le16 local, struct net_device *dev,
134 int force); 134 int force);
135extern int dn_fib_sync_up(struct net_device *dev); 135extern int dn_fib_sync_up(struct net_device *dev);
136 136
@@ -148,8 +148,8 @@ extern void dn_fib_table_cleanup(void);
148extern void dn_fib_rules_init(void); 148extern void dn_fib_rules_init(void);
149extern void dn_fib_rules_cleanup(void); 149extern void dn_fib_rules_cleanup(void);
150extern void dn_fib_rule_put(struct dn_fib_rule *); 150extern void dn_fib_rule_put(struct dn_fib_rule *);
151extern __u16 dn_fib_rules_policy(__u16 saddr, struct dn_fib_res *res, unsigned *flags); 151extern __le16 dn_fib_rules_policy(__le16 saddr, struct dn_fib_res *res, unsigned *flags);
152extern unsigned dnet_addr_type(__u16 addr); 152extern unsigned dnet_addr_type(__le16 addr);
153extern int dn_fib_lookup(const struct flowi *fl, struct dn_fib_res *res); 153extern int dn_fib_lookup(const struct flowi *fl, struct dn_fib_res *res);
154 154
155/* 155/*
@@ -194,10 +194,10 @@ extern struct dn_fib_table *dn_fib_tables[];
194 194
195#endif /* CONFIG_DECNET_ROUTER */ 195#endif /* CONFIG_DECNET_ROUTER */
196 196
197static inline u16 dnet_make_mask(int n) 197static inline __le16 dnet_make_mask(int n)
198{ 198{
199 if (n) 199 if (n)
200 return htons(~((1<<(16-n))-1)); 200 return dn_htons(~((1<<(16-n))-1));
201 return 0; 201 return 0;
202} 202}
203 203
diff --git a/include/net/dn_neigh.h b/include/net/dn_neigh.h
index 4b1eb038d637..4cb4ae7fb81f 100644
--- a/include/net/dn_neigh.h
+++ b/include/net/dn_neigh.h
@@ -7,13 +7,13 @@
7 */ 7 */
8struct dn_neigh { 8struct dn_neigh {
9 struct neighbour n; 9 struct neighbour n;
10 dn_address addr; 10 __le16 addr;
11 unsigned long flags; 11 unsigned long flags;
12#define DN_NDFLAG_R1 0x0001 /* Router L1 */ 12#define DN_NDFLAG_R1 0x0001 /* Router L1 */
13#define DN_NDFLAG_R2 0x0002 /* Router L2 */ 13#define DN_NDFLAG_R2 0x0002 /* Router L2 */
14#define DN_NDFLAG_P3 0x0004 /* Phase III Node */ 14#define DN_NDFLAG_P3 0x0004 /* Phase III Node */
15 unsigned long blksize; 15 unsigned long blksize;
16 unsigned char priority; 16 __u8 priority;
17}; 17};
18 18
19extern void dn_neigh_init(void); 19extern void dn_neigh_init(void);
diff --git a/include/net/dn_nsp.h b/include/net/dn_nsp.h
index e6182b86262b..96e816b6974d 100644
--- a/include/net/dn_nsp.h
+++ b/include/net/dn_nsp.h
@@ -72,77 +72,77 @@ extern struct sk_buff *dn_alloc_send_skb(struct sock *sk, size_t *size, int nobl
72 72
73struct nsp_data_seg_msg 73struct nsp_data_seg_msg
74{ 74{
75 unsigned char msgflg; 75 __u8 msgflg;
76 unsigned short dstaddr; 76 __le16 dstaddr;
77 unsigned short srcaddr; 77 __le16 srcaddr;
78} __attribute__((packed)); 78} __attribute__((packed));
79 79
80struct nsp_data_opt_msg 80struct nsp_data_opt_msg
81{ 81{
82 unsigned short acknum; 82 __le16 acknum;
83 unsigned short segnum; 83 __le16 segnum;
84 unsigned short lsflgs; 84 __le16 lsflgs;
85} __attribute__((packed)); 85} __attribute__((packed));
86 86
87struct nsp_data_opt_msg1 87struct nsp_data_opt_msg1
88{ 88{
89 unsigned short acknum; 89 __le16 acknum;
90 unsigned short segnum; 90 __le16 segnum;
91} __attribute__((packed)); 91} __attribute__((packed));
92 92
93 93
94/* Acknowledgment Message (data/other data) */ 94/* Acknowledgment Message (data/other data) */
95struct nsp_data_ack_msg 95struct nsp_data_ack_msg
96{ 96{
97 unsigned char msgflg; 97 __u8 msgflg;
98 unsigned short dstaddr; 98 __le16 dstaddr;
99 unsigned short srcaddr; 99 __le16 srcaddr;
100 unsigned short acknum; 100 __le16 acknum;
101} __attribute__((packed)); 101} __attribute__((packed));
102 102
103/* Connect Acknowledgment Message */ 103/* Connect Acknowledgment Message */
104struct nsp_conn_ack_msg 104struct nsp_conn_ack_msg
105{ 105{
106 unsigned char msgflg; 106 __u8 msgflg;
107 unsigned short dstaddr; 107 __le16 dstaddr;
108} __attribute__((packed)); 108} __attribute__((packed));
109 109
110 110
111/* Connect Initiate/Retransmit Initiate/Connect Confirm */ 111/* Connect Initiate/Retransmit Initiate/Connect Confirm */
112struct nsp_conn_init_msg 112struct nsp_conn_init_msg
113{ 113{
114 unsigned char msgflg; 114 __u8 msgflg;
115#define NSP_CI 0x18 /* Connect Initiate */ 115#define NSP_CI 0x18 /* Connect Initiate */
116#define NSP_RCI 0x68 /* Retrans. Conn Init */ 116#define NSP_RCI 0x68 /* Retrans. Conn Init */
117 unsigned short dstaddr; 117 __le16 dstaddr;
118 unsigned short srcaddr; 118 __le16 srcaddr;
119 unsigned char services; 119 __u8 services;
120#define NSP_FC_NONE 0x00 /* Flow Control None */ 120#define NSP_FC_NONE 0x00 /* Flow Control None */
121#define NSP_FC_SRC 0x04 /* Seg Req. Count */ 121#define NSP_FC_SRC 0x04 /* Seg Req. Count */
122#define NSP_FC_SCMC 0x08 /* Sess. Control Mess */ 122#define NSP_FC_SCMC 0x08 /* Sess. Control Mess */
123#define NSP_FC_MASK 0x0c /* FC type mask */ 123#define NSP_FC_MASK 0x0c /* FC type mask */
124 unsigned char info; 124 __u8 info;
125 unsigned short segsize; 125 __le16 segsize;
126} __attribute__((packed)); 126} __attribute__((packed));
127 127
128/* Disconnect Initiate/Disconnect Confirm */ 128/* Disconnect Initiate/Disconnect Confirm */
129struct nsp_disconn_init_msg 129struct nsp_disconn_init_msg
130{ 130{
131 unsigned char msgflg; 131 __u8 msgflg;
132 unsigned short dstaddr; 132 __le16 dstaddr;
133 unsigned short srcaddr; 133 __le16 srcaddr;
134 unsigned short reason; 134 __le16 reason;
135} __attribute__((packed)); 135} __attribute__((packed));
136 136
137 137
138 138
139struct srcobj_fmt 139struct srcobj_fmt
140{ 140{
141 char format; 141 __u8 format;
142 unsigned char task; 142 __u8 task;
143 unsigned short grpcode; 143 __le16 grpcode;
144 unsigned short usrcode; 144 __le16 usrcode;
145 char dlen; 145 __u8 dlen;
146} __attribute__((packed)); 146} __attribute__((packed));
147 147
148/* 148/*
@@ -150,7 +150,7 @@ struct srcobj_fmt
150 * numbers used in NSP. Similar in operation to the functions 150 * numbers used in NSP. Similar in operation to the functions
151 * of the same name in TCP. 151 * of the same name in TCP.
152 */ 152 */
153static __inline__ int dn_before(unsigned short seq1, unsigned short seq2) 153static __inline__ int dn_before(__u16 seq1, __u16 seq2)
154{ 154{
155 seq1 &= 0x0fff; 155 seq1 &= 0x0fff;
156 seq2 &= 0x0fff; 156 seq2 &= 0x0fff;
@@ -159,7 +159,7 @@ static __inline__ int dn_before(unsigned short seq1, unsigned short seq2)
159} 159}
160 160
161 161
162static __inline__ int dn_after(unsigned short seq1, unsigned short seq2) 162static __inline__ int dn_after(__u16 seq1, __u16 seq2)
163{ 163{
164 seq1 &= 0x0fff; 164 seq1 &= 0x0fff;
165 seq2 &= 0x0fff; 165 seq2 &= 0x0fff;
@@ -167,23 +167,23 @@ static __inline__ int dn_after(unsigned short seq1, unsigned short seq2)
167 return (int)((seq2 - seq1) & 0x0fff) > 2048; 167 return (int)((seq2 - seq1) & 0x0fff) > 2048;
168} 168}
169 169
170static __inline__ int dn_equal(unsigned short seq1, unsigned short seq2) 170static __inline__ int dn_equal(__u16 seq1, __u16 seq2)
171{ 171{
172 return ((seq1 ^ seq2) & 0x0fff) == 0; 172 return ((seq1 ^ seq2) & 0x0fff) == 0;
173} 173}
174 174
175static __inline__ int dn_before_or_equal(unsigned short seq1, unsigned short seq2) 175static __inline__ int dn_before_or_equal(__u16 seq1, __u16 seq2)
176{ 176{
177 return (dn_before(seq1, seq2) || dn_equal(seq1, seq2)); 177 return (dn_before(seq1, seq2) || dn_equal(seq1, seq2));
178} 178}
179 179
180static __inline__ void seq_add(unsigned short *seq, unsigned short off) 180static __inline__ void seq_add(__u16 *seq, __u16 off)
181{ 181{
182 (*seq) += off; 182 (*seq) += off;
183 (*seq) &= 0x0fff; 183 (*seq) &= 0x0fff;
184} 184}
185 185
186static __inline__ int seq_next(unsigned short seq1, unsigned short seq2) 186static __inline__ int seq_next(__u16 seq1, __u16 seq2)
187{ 187{
188 return dn_equal(seq1 + 1, seq2); 188 return dn_equal(seq1 + 1, seq2);
189} 189}
@@ -191,7 +191,7 @@ static __inline__ int seq_next(unsigned short seq1, unsigned short seq2)
191/* 191/*
192 * Can we delay the ack ? 192 * Can we delay the ack ?
193 */ 193 */
194static __inline__ int sendack(unsigned short seq) 194static __inline__ int sendack(__u16 seq)
195{ 195{
196 return (int)((seq & 0x1000) ? 0 : 1); 196 return (int)((seq & 0x1000) ? 0 : 1);
197} 197}
diff --git a/include/net/dn_route.h b/include/net/dn_route.h
index 5122da3f2eb3..76f957e258b0 100644
--- a/include/net/dn_route.h
+++ b/include/net/dn_route.h
@@ -71,12 +71,12 @@ struct dn_route {
71 struct dn_route *rt_next; 71 struct dn_route *rt_next;
72 } u; 72 } u;
73 73
74 __u16 rt_saddr; 74 __le16 rt_saddr;
75 __u16 rt_daddr; 75 __le16 rt_daddr;
76 __u16 rt_gateway; 76 __le16 rt_gateway;
77 __u16 rt_local_src; /* Source used for forwarding packets */ 77 __le16 rt_local_src; /* Source used for forwarding packets */
78 __u16 rt_src_map; 78 __le16 rt_src_map;
79 __u16 rt_dst_map; 79 __le16 rt_dst_map;
80 80
81 unsigned rt_flags; 81 unsigned rt_flags;
82 unsigned rt_type; 82 unsigned rt_type;
diff --git a/include/net/flow.h b/include/net/flow.h
index ec7eb86eb203..04d89f763451 100644
--- a/include/net/flow.h
+++ b/include/net/flow.h
@@ -30,8 +30,8 @@ struct flowi {
30 } ip6_u; 30 } ip6_u;
31 31
32 struct { 32 struct {
33 __u16 daddr; 33 __le16 daddr;
34 __u16 saddr; 34 __le16 saddr;
35 __u32 fwmark; 35 __u32 fwmark;
36 __u8 scope; 36 __u8 scope;
37 } dn_u; 37 } dn_u;
@@ -64,8 +64,8 @@ struct flowi {
64 } icmpt; 64 } icmpt;
65 65
66 struct { 66 struct {
67 __u16 sport; 67 __le16 sport;
68 __u16 dport; 68 __le16 dport;
69 __u8 objnum; 69 __u8 objnum;
70 __u8 objnamel; /* Not 16 bits since max val is 16 */ 70 __u8 objnamel; /* Not 16 bits since max val is 16 */
71 __u8 objname[16]; /* Not zero terminated */ 71 __u8 objname[16]; /* Not zero terminated */
diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h
index eb8afe3499a9..e459e1a0ae4a 100644
--- a/include/net/if_inet6.h
+++ b/include/net/if_inet6.h
@@ -180,11 +180,8 @@ struct inet6_dev
180 180
181#ifdef CONFIG_IPV6_PRIVACY 181#ifdef CONFIG_IPV6_PRIVACY
182 u8 rndid[8]; 182 u8 rndid[8];
183 u8 entropy[8];
184 struct timer_list regen_timer; 183 struct timer_list regen_timer;
185 struct inet6_ifaddr *tempaddr_list; 184 struct inet6_ifaddr *tempaddr_list;
186 __u8 work_eui64[8];
187 __u8 work_digest[16];
188#endif 185#endif
189 186
190 struct neigh_parms *nd_parms; 187 struct neigh_parms *nd_parms;
diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
index fa587c94e9d0..9bf73fe50948 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -50,6 +50,12 @@ struct inet_connection_sock_af_ops {
50 char __user *optval, int optlen); 50 char __user *optval, int optlen);
51 int (*getsockopt)(struct sock *sk, int level, int optname, 51 int (*getsockopt)(struct sock *sk, int level, int optname,
52 char __user *optval, int __user *optlen); 52 char __user *optval, int __user *optlen);
53 int (*compat_setsockopt)(struct sock *sk,
54 int level, int optname,
55 char __user *optval, int optlen);
56 int (*compat_getsockopt)(struct sock *sk,
57 int level, int optname,
58 char __user *optval, int __user *optlen);
53 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *); 59 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
54 int sockaddr_len; 60 int sockaddr_len;
55}; 61};
@@ -72,6 +78,7 @@ struct inet_connection_sock_af_ops {
72 * @icsk_probes_out: unanswered 0 window probes 78 * @icsk_probes_out: unanswered 0 window probes
73 * @icsk_ext_hdr_len: Network protocol overhead (IP/IPv6 options) 79 * @icsk_ext_hdr_len: Network protocol overhead (IP/IPv6 options)
74 * @icsk_ack: Delayed ACK control data 80 * @icsk_ack: Delayed ACK control data
81 * @icsk_mtup; MTU probing control data
75 */ 82 */
76struct inet_connection_sock { 83struct inet_connection_sock {
77 /* inet_sock has to be the first member! */ 84 /* inet_sock has to be the first member! */
@@ -104,6 +111,16 @@ struct inet_connection_sock {
104 __u16 last_seg_size; /* Size of last incoming segment */ 111 __u16 last_seg_size; /* Size of last incoming segment */
105 __u16 rcv_mss; /* MSS used for delayed ACK decisions */ 112 __u16 rcv_mss; /* MSS used for delayed ACK decisions */
106 } icsk_ack; 113 } icsk_ack;
114 struct {
115 int enabled;
116
117 /* Range of MTUs to search */
118 int search_high;
119 int search_low;
120
121 /* Information on the current probe. */
122 int probe_size;
123 } icsk_mtup;
107 u32 icsk_ca_priv[16]; 124 u32 icsk_ca_priv[16];
108#define ICSK_CA_PRIV_SIZE (16 * sizeof(u32)) 125#define ICSK_CA_PRIV_SIZE (16 * sizeof(u32))
109}; 126};
@@ -310,4 +327,13 @@ extern void inet_csk_listen_stop(struct sock *sk);
310 327
311extern void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr); 328extern void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr);
312 329
330extern int inet_csk_ctl_sock_create(struct socket **sock,
331 unsigned short family,
332 unsigned short type,
333 unsigned char protocol);
334
335extern int inet_csk_compat_getsockopt(struct sock *sk, int level, int optname,
336 char __user *optval, int __user *optlen);
337extern int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname,
338 char __user *optval, int optlen);
313#endif /* _INET_CONNECTION_SOCK_H */ 339#endif /* _INET_CONNECTION_SOCK_H */
diff --git a/include/net/ip.h b/include/net/ip.h
index fab3d5b3ab1c..8fe6156ca9b0 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -356,6 +356,10 @@ extern void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb);
356extern int ip_cmsg_send(struct msghdr *msg, struct ipcm_cookie *ipc); 356extern int ip_cmsg_send(struct msghdr *msg, struct ipcm_cookie *ipc);
357extern int ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval, int optlen); 357extern int ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval, int optlen);
358extern int ip_getsockopt(struct sock *sk, int level, int optname, char __user *optval, int __user *optlen); 358extern int ip_getsockopt(struct sock *sk, int level, int optname, char __user *optval, int __user *optlen);
359extern int compat_ip_setsockopt(struct sock *sk, int level,
360 int optname, char __user *optval, int optlen);
361extern int compat_ip_getsockopt(struct sock *sk, int level,
362 int optname, char __user *optval, int __user *optlen);
359extern int ip_ra_control(struct sock *sk, unsigned char on, void (*destructor)(struct sock *)); 363extern int ip_ra_control(struct sock *sk, unsigned char on, void (*destructor)(struct sock *));
360 364
361extern int ip_recv_error(struct sock *sk, struct msghdr *msg, int len); 365extern int ip_recv_error(struct sock *sk, struct msghdr *msg, int len);
diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h
index 1f2e428ca364..a398ae5e30f9 100644
--- a/include/net/ip6_route.h
+++ b/include/net/ip6_route.h
@@ -7,6 +7,23 @@
7#define IP6_RT_PRIO_KERN 512 7#define IP6_RT_PRIO_KERN 512
8#define IP6_RT_FLOW_MASK 0x00ff 8#define IP6_RT_FLOW_MASK 0x00ff
9 9
10struct route_info {
11 __u8 type;
12 __u8 length;
13 __u8 prefix_len;
14#if defined(__BIG_ENDIAN_BITFIELD)
15 __u8 reserved_h:3,
16 route_pref:2,
17 reserved_l:3;
18#elif defined(__LITTLE_ENDIAN_BITFIELD)
19 __u8 reserved_l:3,
20 route_pref:2,
21 reserved_h:3;
22#endif
23 __u32 lifetime;
24 __u8 prefix[0]; /* 0,8 or 16 */
25};
26
10#ifdef __KERNEL__ 27#ifdef __KERNEL__
11 28
12#include <net/flow.h> 29#include <net/flow.h>
@@ -87,11 +104,14 @@ extern struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
87extern struct rt6_info * rt6_get_dflt_router(struct in6_addr *addr, 104extern struct rt6_info * rt6_get_dflt_router(struct in6_addr *addr,
88 struct net_device *dev); 105 struct net_device *dev);
89extern struct rt6_info * rt6_add_dflt_router(struct in6_addr *gwaddr, 106extern struct rt6_info * rt6_add_dflt_router(struct in6_addr *gwaddr,
90 struct net_device *dev); 107 struct net_device *dev,
108 unsigned int pref);
91 109
92extern void rt6_purge_dflt_routers(void); 110extern void rt6_purge_dflt_routers(void);
93 111
94extern void rt6_reset_dflt_pointer(struct rt6_info *rt); 112extern int rt6_route_rcv(struct net_device *dev,
113 u8 *opt, int len,
114 struct in6_addr *gwaddr);
95 115
96extern void rt6_redirect(struct in6_addr *dest, 116extern void rt6_redirect(struct in6_addr *dest,
97 struct in6_addr *saddr, 117 struct in6_addr *saddr,
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index 3b1d963d396c..6d6f0634ae41 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -282,6 +282,18 @@ static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr
282 return memcmp((const void *) a1, (const void *) a2, sizeof(struct in6_addr)); 282 return memcmp((const void *) a1, (const void *) a2, sizeof(struct in6_addr));
283} 283}
284 284
285static inline int
286ipv6_masked_addr_cmp(const struct in6_addr *a1, const struct in6_addr *m,
287 const struct in6_addr *a2)
288{
289 unsigned int i;
290
291 for (i = 0; i < 4; i++)
292 if ((a1->s6_addr32[i] ^ a2->s6_addr32[i]) & m->s6_addr32[i])
293 return 1;
294 return 0;
295}
296
285static inline void ipv6_addr_copy(struct in6_addr *a1, const struct in6_addr *a2) 297static inline void ipv6_addr_copy(struct in6_addr *a1, const struct in6_addr *a2)
286{ 298{
287 memcpy((void *) a1, (const void *) a2, sizeof(struct in6_addr)); 299 memcpy((void *) a1, (const void *) a2, sizeof(struct in6_addr));
@@ -508,6 +520,16 @@ extern int ipv6_getsockopt(struct sock *sk, int level,
508 int optname, 520 int optname,
509 char __user *optval, 521 char __user *optval,
510 int __user *optlen); 522 int __user *optlen);
523extern int compat_ipv6_setsockopt(struct sock *sk,
524 int level,
525 int optname,
526 char __user *optval,
527 int optlen);
528extern int compat_ipv6_getsockopt(struct sock *sk,
529 int level,
530 int optname,
531 char __user *optval,
532 int __user *optlen);
511 533
512extern void ipv6_packet_init(void); 534extern void ipv6_packet_init(void);
513 535
diff --git a/include/net/llc.h b/include/net/llc.h
index 1adb2ef3f6f7..f5024583fc8b 100644
--- a/include/net/llc.h
+++ b/include/net/llc.h
@@ -71,7 +71,7 @@ extern int llc_rcv(struct sk_buff *skb, struct net_device *dev,
71 struct packet_type *pt, struct net_device *orig_dev); 71 struct packet_type *pt, struct net_device *orig_dev);
72 72
73extern int llc_mac_hdr_init(struct sk_buff *skb, 73extern int llc_mac_hdr_init(struct sk_buff *skb,
74 unsigned char *sa, unsigned char *da); 74 const unsigned char *sa, const unsigned char *da);
75 75
76extern void llc_add_pack(int type, void (*handler)(struct llc_sap *sap, 76extern void llc_add_pack(int type, void (*handler)(struct llc_sap *sap,
77 struct sk_buff *skb)); 77 struct sk_buff *skb));
diff --git a/include/net/ndisc.h b/include/net/ndisc.h
index bbac87eeb422..91fa271a0064 100644
--- a/include/net/ndisc.h
+++ b/include/net/ndisc.h
@@ -22,6 +22,8 @@ enum {
22 ND_OPT_PREFIX_INFO = 3, /* RFC2461 */ 22 ND_OPT_PREFIX_INFO = 3, /* RFC2461 */
23 ND_OPT_REDIRECT_HDR = 4, /* RFC2461 */ 23 ND_OPT_REDIRECT_HDR = 4, /* RFC2461 */
24 ND_OPT_MTU = 5, /* RFC2461 */ 24 ND_OPT_MTU = 5, /* RFC2461 */
25 __ND_OPT_ARRAY_MAX,
26 ND_OPT_ROUTE_INFO = 24, /* RFC4191 */
25 __ND_OPT_MAX 27 __ND_OPT_MAX
26}; 28};
27 29
diff --git a/include/net/neighbour.h b/include/net/neighbour.h
index 6fa9ae190741..b0666d66293f 100644
--- a/include/net/neighbour.h
+++ b/include/net/neighbour.h
@@ -68,6 +68,7 @@ struct neigh_parms
68 struct net_device *dev; 68 struct net_device *dev;
69 struct neigh_parms *next; 69 struct neigh_parms *next;
70 int (*neigh_setup)(struct neighbour *); 70 int (*neigh_setup)(struct neighbour *);
71 void (*neigh_destructor)(struct neighbour *);
71 struct neigh_table *tbl; 72 struct neigh_table *tbl;
72 73
73 void *sysctl_table; 74 void *sysctl_table;
@@ -145,7 +146,6 @@ struct neighbour
145struct neigh_ops 146struct neigh_ops
146{ 147{
147 int family; 148 int family;
148 void (*destructor)(struct neighbour *);
149 void (*solicit)(struct neighbour *, struct sk_buff*); 149 void (*solicit)(struct neighbour *, struct sk_buff*);
150 void (*error_report)(struct neighbour *, struct sk_buff*); 150 void (*error_report)(struct neighbour *, struct sk_buff*);
151 int (*output)(struct sk_buff*); 151 int (*output)(struct sk_buff*);
diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index 6d075ca16e6e..2743c156caa0 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -67,6 +67,18 @@ do { \
67 67
68struct nf_conntrack_helper; 68struct nf_conntrack_helper;
69 69
70/* nf_conn feature for connections that have a helper */
71struct nf_conn_help {
72 /* Helper. if any */
73 struct nf_conntrack_helper *helper;
74
75 union nf_conntrack_help help;
76
77 /* Current number of expected connections */
78 unsigned int expecting;
79};
80
81
70#include <net/netfilter/ipv4/nf_conntrack_ipv4.h> 82#include <net/netfilter/ipv4/nf_conntrack_ipv4.h>
71struct nf_conn 83struct nf_conn
72{ 84{
@@ -81,6 +93,9 @@ struct nf_conn
81 /* Have we seen traffic both ways yet? (bitset) */ 93 /* Have we seen traffic both ways yet? (bitset) */
82 unsigned long status; 94 unsigned long status;
83 95
96 /* If we were expected by an expectation, this will be it */
97 struct nf_conn *master;
98
84 /* Timer function; drops refcnt when it goes off. */ 99 /* Timer function; drops refcnt when it goes off. */
85 struct timer_list timeout; 100 struct timer_list timeout;
86 101
@@ -88,38 +103,22 @@ struct nf_conn
88 /* Accounting Information (same cache line as other written members) */ 103 /* Accounting Information (same cache line as other written members) */
89 struct ip_conntrack_counter counters[IP_CT_DIR_MAX]; 104 struct ip_conntrack_counter counters[IP_CT_DIR_MAX];
90#endif 105#endif
91 /* If we were expected by an expectation, this will be it */
92 struct nf_conn *master;
93
94 /* Current number of expected connections */
95 unsigned int expecting;
96 106
97 /* Unique ID that identifies this conntrack*/ 107 /* Unique ID that identifies this conntrack*/
98 unsigned int id; 108 unsigned int id;
99 109
100 /* Helper. if any */
101 struct nf_conntrack_helper *helper;
102
103 /* features - nat, helper, ... used by allocating system */ 110 /* features - nat, helper, ... used by allocating system */
104 u_int32_t features; 111 u_int32_t features;
105 112
106 /* Storage reserved for other modules: */
107
108 union nf_conntrack_proto proto;
109
110#if defined(CONFIG_NF_CONNTRACK_MARK) 113#if defined(CONFIG_NF_CONNTRACK_MARK)
111 u_int32_t mark; 114 u_int32_t mark;
112#endif 115#endif
113 116
114 /* These members are dynamically allocated. */ 117 /* Storage reserved for other modules: */
115 118 union nf_conntrack_proto proto;
116 union nf_conntrack_help *help;
117 119
118 /* Layer 3 dependent members. (ex: NAT) */ 120 /* features dynamically at the end: helper, nat (both optional) */
119 union { 121 char data[0];
120 struct nf_conntrack_ipv4 *ipv4;
121 } l3proto;
122 void *data[0];
123}; 122};
124 123
125struct nf_conntrack_expect 124struct nf_conntrack_expect
@@ -373,10 +372,23 @@ nf_conntrack_expect_event(enum ip_conntrack_expect_events event,
373#define NF_CT_F_NUM 4 372#define NF_CT_F_NUM 4
374 373
375extern int 374extern int
376nf_conntrack_register_cache(u_int32_t features, const char *name, size_t size, 375nf_conntrack_register_cache(u_int32_t features, const char *name, size_t size);
377 int (*init_conntrack)(struct nf_conn *, u_int32_t));
378extern void 376extern void
379nf_conntrack_unregister_cache(u_int32_t features); 377nf_conntrack_unregister_cache(u_int32_t features);
380 378
379/* valid combinations:
380 * basic: nf_conn, nf_conn .. nf_conn_help
381 * nat: nf_conn .. nf_conn_nat, nf_conn .. nf_conn_nat, nf_conn help
382 */
383static inline struct nf_conn_help *nfct_help(const struct nf_conn *ct)
384{
385 unsigned int offset = sizeof(struct nf_conn);
386
387 if (!(ct->features & NF_CT_F_HELP))
388 return NULL;
389
390 return (struct nf_conn_help *) ((void *)ct + offset);
391}
392
381#endif /* __KERNEL__ */ 393#endif /* __KERNEL__ */
382#endif /* _NF_CONNTRACK_H */ 394#endif /* _NF_CONNTRACK_H */
diff --git a/include/net/scm.h b/include/net/scm.h
index c3fa3d5ab606..540619cb7160 100644
--- a/include/net/scm.h
+++ b/include/net/scm.h
@@ -37,10 +37,12 @@ static __inline__ void scm_destroy(struct scm_cookie *scm)
37static __inline__ int scm_send(struct socket *sock, struct msghdr *msg, 37static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
38 struct scm_cookie *scm) 38 struct scm_cookie *scm)
39{ 39{
40 memset(scm, 0, sizeof(*scm)); 40 struct task_struct *p = current;
41 scm->creds.uid = current->uid; 41 scm->creds.uid = p->uid;
42 scm->creds.gid = current->gid; 42 scm->creds.gid = p->gid;
43 scm->creds.pid = current->tgid; 43 scm->creds.pid = p->tgid;
44 scm->fp = NULL;
45 scm->seq = 0;
44 if (msg->msg_controllen <= 0) 46 if (msg->msg_controllen <= 0)
45 return 0; 47 return 0;
46 return __scm_send(sock, msg, scm); 48 return __scm_send(sock, msg, scm);
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 072f407848a6..eba99f375517 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -514,6 +514,16 @@ struct sctp_af {
514 int optname, 514 int optname,
515 char __user *optval, 515 char __user *optval,
516 int __user *optlen); 516 int __user *optlen);
517 int (*compat_setsockopt) (struct sock *sk,
518 int level,
519 int optname,
520 char __user *optval,
521 int optlen);
522 int (*compat_getsockopt) (struct sock *sk,
523 int level,
524 int optname,
525 char __user *optval,
526 int __user *optlen);
517 struct dst_entry *(*get_dst) (struct sctp_association *asoc, 527 struct dst_entry *(*get_dst) (struct sctp_association *asoc,
518 union sctp_addr *daddr, 528 union sctp_addr *daddr,
519 union sctp_addr *saddr); 529 union sctp_addr *saddr);
diff --git a/include/net/sock.h b/include/net/sock.h
index f63d0d56712c..ec226f31dc2a 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -520,6 +520,14 @@ struct proto {
520 int (*getsockopt)(struct sock *sk, int level, 520 int (*getsockopt)(struct sock *sk, int level,
521 int optname, char __user *optval, 521 int optname, char __user *optval,
522 int __user *option); 522 int __user *option);
523 int (*compat_setsockopt)(struct sock *sk,
524 int level,
525 int optname, char __user *optval,
526 int optlen);
527 int (*compat_getsockopt)(struct sock *sk,
528 int level,
529 int optname, char __user *optval,
530 int __user *option);
523 int (*sendmsg)(struct kiocb *iocb, struct sock *sk, 531 int (*sendmsg)(struct kiocb *iocb, struct sock *sk,
524 struct msghdr *msg, size_t len); 532 struct msghdr *msg, size_t len);
525 int (*recvmsg)(struct kiocb *iocb, struct sock *sk, 533 int (*recvmsg)(struct kiocb *iocb, struct sock *sk,
@@ -816,6 +824,10 @@ extern int sock_common_recvmsg(struct kiocb *iocb, struct socket *sock,
816 struct msghdr *msg, size_t size, int flags); 824 struct msghdr *msg, size_t size, int flags);
817extern int sock_common_setsockopt(struct socket *sock, int level, int optname, 825extern int sock_common_setsockopt(struct socket *sock, int level, int optname,
818 char __user *optval, int optlen); 826 char __user *optval, int optlen);
827extern int compat_sock_common_getsockopt(struct socket *sock, int level,
828 int optname, char __user *optval, int __user *optlen);
829extern int compat_sock_common_setsockopt(struct socket *sock, int level,
830 int optname, char __user *optval, int optlen);
819 831
820extern void sk_common_release(struct sock *sk); 832extern void sk_common_release(struct sock *sk);
821 833
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 77f21c65bbca..9418f4d1afbb 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -60,6 +60,9 @@ extern void tcp_time_wait(struct sock *sk, int state, int timeo);
60/* Minimal RCV_MSS. */ 60/* Minimal RCV_MSS. */
61#define TCP_MIN_RCVMSS 536U 61#define TCP_MIN_RCVMSS 536U
62 62
63/* The least MTU to use for probing */
64#define TCP_BASE_MSS 512
65
63/* After receiving this amount of duplicate ACKs fast retransmit starts. */ 66/* After receiving this amount of duplicate ACKs fast retransmit starts. */
64#define TCP_FASTRETRANS_THRESH 3 67#define TCP_FASTRETRANS_THRESH 3
65 68
@@ -219,6 +222,9 @@ extern int sysctl_tcp_nometrics_save;
219extern int sysctl_tcp_moderate_rcvbuf; 222extern int sysctl_tcp_moderate_rcvbuf;
220extern int sysctl_tcp_tso_win_divisor; 223extern int sysctl_tcp_tso_win_divisor;
221extern int sysctl_tcp_abc; 224extern int sysctl_tcp_abc;
225extern int sysctl_tcp_mtu_probing;
226extern int sysctl_tcp_base_mss;
227extern int sysctl_tcp_workaround_signed_windows;
222 228
223extern atomic_t tcp_memory_allocated; 229extern atomic_t tcp_memory_allocated;
224extern atomic_t tcp_sockets_allocated; 230extern atomic_t tcp_sockets_allocated;
@@ -347,6 +353,12 @@ extern int tcp_getsockopt(struct sock *sk, int level,
347extern int tcp_setsockopt(struct sock *sk, int level, 353extern int tcp_setsockopt(struct sock *sk, int level,
348 int optname, char __user *optval, 354 int optname, char __user *optval,
349 int optlen); 355 int optlen);
356extern int compat_tcp_getsockopt(struct sock *sk,
357 int level, int optname,
358 char __user *optval, int __user *optlen);
359extern int compat_tcp_setsockopt(struct sock *sk,
360 int level, int optname,
361 char __user *optval, int optlen);
350extern void tcp_set_keepalive(struct sock *sk, int val); 362extern void tcp_set_keepalive(struct sock *sk, int val);
351extern int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, 363extern int tcp_recvmsg(struct kiocb *iocb, struct sock *sk,
352 struct msghdr *msg, 364 struct msghdr *msg,
@@ -447,6 +459,10 @@ extern int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
447 459
448extern void tcp_initialize_rcv_mss(struct sock *sk); 460extern void tcp_initialize_rcv_mss(struct sock *sk);
449 461
462extern int tcp_mtu_to_mss(struct sock *sk, int pmtu);
463extern int tcp_mss_to_mtu(struct sock *sk, int mss);
464extern void tcp_mtup_init(struct sock *sk);
465
450static inline void __tcp_fast_path_on(struct tcp_sock *tp, u32 snd_wnd) 466static inline void __tcp_fast_path_on(struct tcp_sock *tp, u32 snd_wnd)
451{ 467{
452 tp->pred_flags = htonl((tp->tcp_header_len << 26) | 468 tp->pred_flags = htonl((tp->tcp_header_len << 26) |
diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 8d362c49b8a9..61b7504fc2ba 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -11,6 +11,7 @@
11#include <linux/crypto.h> 11#include <linux/crypto.h>
12#include <linux/pfkeyv2.h> 12#include <linux/pfkeyv2.h>
13#include <linux/in6.h> 13#include <linux/in6.h>
14#include <linux/mutex.h>
14 15
15#include <net/sock.h> 16#include <net/sock.h>
16#include <net/dst.h> 17#include <net/dst.h>
@@ -20,7 +21,11 @@
20 21
21#define XFRM_ALIGN8(len) (((len) + 7) & ~7) 22#define XFRM_ALIGN8(len) (((len) + 7) & ~7)
22 23
23extern struct semaphore xfrm_cfg_sem; 24extern struct sock *xfrm_nl;
25extern u32 sysctl_xfrm_aevent_etime;
26extern u32 sysctl_xfrm_aevent_rseqth;
27
28extern struct mutex xfrm_cfg_mutex;
24 29
25/* Organization of SPD aka "XFRM rules" 30/* Organization of SPD aka "XFRM rules"
26 ------------------------------------ 31 ------------------------------------
@@ -135,6 +140,16 @@ struct xfrm_state
135 /* State for replay detection */ 140 /* State for replay detection */
136 struct xfrm_replay_state replay; 141 struct xfrm_replay_state replay;
137 142
143 /* Replay detection state at the time we sent the last notification */
144 struct xfrm_replay_state preplay;
145
146 /* Replay detection notification settings */
147 u32 replay_maxage;
148 u32 replay_maxdiff;
149
150 /* Replay detection notification timer */
151 struct timer_list rtimer;
152
138 /* Statistics */ 153 /* Statistics */
139 struct xfrm_stats stats; 154 struct xfrm_stats stats;
140 155
@@ -169,6 +184,7 @@ struct km_event
169 u32 hard; 184 u32 hard;
170 u32 proto; 185 u32 proto;
171 u32 byid; 186 u32 byid;
187 u32 aevent;
172 } data; 188 } data;
173 189
174 u32 seq; 190 u32 seq;
@@ -199,10 +215,13 @@ extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
199extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo); 215extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
200extern void km_policy_notify(struct xfrm_policy *xp, int dir, struct km_event *c); 216extern void km_policy_notify(struct xfrm_policy *xp, int dir, struct km_event *c);
201extern void km_state_notify(struct xfrm_state *x, struct km_event *c); 217extern void km_state_notify(struct xfrm_state *x, struct km_event *c);
202
203#define XFRM_ACQ_EXPIRES 30 218#define XFRM_ACQ_EXPIRES 30
204 219
205struct xfrm_tmpl; 220struct xfrm_tmpl;
221extern int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol);
222extern void km_state_expired(struct xfrm_state *x, int hard, u32 pid);
223extern int __xfrm_state_delete(struct xfrm_state *x);
224
206struct xfrm_state_afinfo { 225struct xfrm_state_afinfo {
207 unsigned short family; 226 unsigned short family;
208 rwlock_t lock; 227 rwlock_t lock;
@@ -305,7 +324,21 @@ struct xfrm_policy
305 struct xfrm_tmpl xfrm_vec[XFRM_MAX_DEPTH]; 324 struct xfrm_tmpl xfrm_vec[XFRM_MAX_DEPTH];
306}; 325};
307 326
308#define XFRM_KM_TIMEOUT 30 327#define XFRM_KM_TIMEOUT 30
328/* which seqno */
329#define XFRM_REPLAY_SEQ 1
330#define XFRM_REPLAY_OSEQ 2
331#define XFRM_REPLAY_SEQ_MASK 3
332/* what happened */
333#define XFRM_REPLAY_UPDATE XFRM_AE_CR
334#define XFRM_REPLAY_TIMEOUT XFRM_AE_CE
335
336/* default aevent timeout in units of 100ms */
337#define XFRM_AE_ETIME 10
338/* Async Event timer multiplier */
339#define XFRM_AE_ETH_M 10
340/* default seq threshold size */
341#define XFRM_AE_SEQT_SIZE 2
309 342
310struct xfrm_mgr 343struct xfrm_mgr
311{ 344{
@@ -865,6 +898,7 @@ extern int xfrm_state_delete(struct xfrm_state *x);
865extern void xfrm_state_flush(u8 proto); 898extern void xfrm_state_flush(u8 proto);
866extern int xfrm_replay_check(struct xfrm_state *x, u32 seq); 899extern int xfrm_replay_check(struct xfrm_state *x, u32 seq);
867extern void xfrm_replay_advance(struct xfrm_state *x, u32 seq); 900extern void xfrm_replay_advance(struct xfrm_state *x, u32 seq);
901extern void xfrm_replay_notify(struct xfrm_state *x, int event);
868extern int xfrm_state_check(struct xfrm_state *x, struct sk_buff *skb); 902extern int xfrm_state_check(struct xfrm_state *x, struct sk_buff *skb);
869extern int xfrm_state_mtu(struct xfrm_state *x, int mtu); 903extern int xfrm_state_mtu(struct xfrm_state *x, int mtu);
870extern int xfrm_init_state(struct xfrm_state *x); 904extern int xfrm_init_state(struct xfrm_state *x);
@@ -924,7 +958,7 @@ extern void xfrm_init_pmtu(struct dst_entry *dst);
924 958
925extern wait_queue_head_t km_waitq; 959extern wait_queue_head_t km_waitq;
926extern int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport); 960extern int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport);
927extern void km_policy_expired(struct xfrm_policy *pol, int dir, int hard); 961extern void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 pid);
928 962
929extern void xfrm_input_init(void); 963extern void xfrm_input_init(void);
930extern int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, u32 *spi, u32 *seq); 964extern int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, u32 *spi, u32 *seq);
@@ -965,4 +999,24 @@ static inline int xfrm_policy_id2dir(u32 index)
965 return index & 7; 999 return index & 7;
966} 1000}
967 1001
1002static inline int xfrm_aevent_is_on(void)
1003{
1004 struct sock *nlsk;
1005 int ret = 0;
1006
1007 rcu_read_lock();
1008 nlsk = rcu_dereference(xfrm_nl);
1009 if (nlsk)
1010 ret = netlink_has_listeners(nlsk, XFRMNLGRP_AEVENTS);
1011 rcu_read_unlock();
1012 return ret;
1013}
1014
1015static inline void xfrm_aevent_doreplay(struct xfrm_state *x)
1016{
1017 if (xfrm_aevent_is_on())
1018 xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
1019}
1020
1021
968#endif /* _NET_XFRM_H */ 1022#endif /* _NET_XFRM_H */
diff --git a/include/rdma/ib_fmr_pool.h b/include/rdma/ib_fmr_pool.h
index 86b7e93f198b..4ace54cd0cce 100644
--- a/include/rdma/ib_fmr_pool.h
+++ b/include/rdma/ib_fmr_pool.h
@@ -43,6 +43,7 @@ struct ib_fmr_pool;
43/** 43/**
44 * struct ib_fmr_pool_param - Parameters for creating FMR pool 44 * struct ib_fmr_pool_param - Parameters for creating FMR pool
45 * @max_pages_per_fmr:Maximum number of pages per map request. 45 * @max_pages_per_fmr:Maximum number of pages per map request.
46 * @page_shift: Log2 of sizeof "pages" mapped by this fmr
46 * @access:Access flags for FMRs in pool. 47 * @access:Access flags for FMRs in pool.
47 * @pool_size:Number of FMRs to allocate for pool. 48 * @pool_size:Number of FMRs to allocate for pool.
48 * @dirty_watermark:Flush is triggered when @dirty_watermark dirty 49 * @dirty_watermark:Flush is triggered when @dirty_watermark dirty
@@ -55,6 +56,7 @@ struct ib_fmr_pool;
55 */ 56 */
56struct ib_fmr_pool_param { 57struct ib_fmr_pool_param {
57 int max_pages_per_fmr; 58 int max_pages_per_fmr;
59 int page_shift;
58 enum ib_access_flags access; 60 enum ib_access_flags access;
59 int pool_size; 61 int pool_size;
60 int dirty_watermark; 62 int dirty_watermark;
diff --git a/include/rdma/ib_mad.h b/include/rdma/ib_mad.h
index 2c133506742b..51ab8eddb295 100644
--- a/include/rdma/ib_mad.h
+++ b/include/rdma/ib_mad.h
@@ -33,7 +33,7 @@
33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * SOFTWARE. 34 * SOFTWARE.
35 * 35 *
36 * $Id: ib_mad.h 2775 2005-07-02 13:42:12Z halr $ 36 * $Id: ib_mad.h 5596 2006-03-03 01:00:07Z sean.hefty $
37 */ 37 */
38 38
39#if !defined( IB_MAD_H ) 39#if !defined( IB_MAD_H )
@@ -208,15 +208,23 @@ struct ib_class_port_info
208/** 208/**
209 * ib_mad_send_buf - MAD data buffer and work request for sends. 209 * ib_mad_send_buf - MAD data buffer and work request for sends.
210 * @next: A pointer used to chain together MADs for posting. 210 * @next: A pointer used to chain together MADs for posting.
211 * @mad: References an allocated MAD data buffer. 211 * @mad: References an allocated MAD data buffer for MADs that do not have
212 * RMPP active. For MADs using RMPP, references the common and management
213 * class specific headers.
212 * @mad_agent: MAD agent that allocated the buffer. 214 * @mad_agent: MAD agent that allocated the buffer.
213 * @ah: The address handle to use when sending the MAD. 215 * @ah: The address handle to use when sending the MAD.
214 * @context: User-controlled context fields. 216 * @context: User-controlled context fields.
217 * @hdr_len: Indicates the size of the data header of the MAD. This length
218 * includes the common MAD, RMPP, and class specific headers.
219 * @data_len: Indicates the total size of user-transferred data.
220 * @seg_count: The number of RMPP segments allocated for this send.
221 * @seg_size: Size of each RMPP segment.
215 * @timeout_ms: Time to wait for a response. 222 * @timeout_ms: Time to wait for a response.
216 * @retries: Number of times to retry a request for a response. 223 * @retries: Number of times to retry a request for a response.
217 * 224 *
218 * Users are responsible for initializing the MAD buffer itself, with the 225 * Users are responsible for initializing the MAD buffer itself, with the
219 * exception of specifying the payload length field in any RMPP MAD. 226 * exception of any RMPP header. Additional segment buffer space allocated
227 * beyond data_len is padding.
220 */ 228 */
221struct ib_mad_send_buf { 229struct ib_mad_send_buf {
222 struct ib_mad_send_buf *next; 230 struct ib_mad_send_buf *next;
@@ -224,6 +232,10 @@ struct ib_mad_send_buf {
224 struct ib_mad_agent *mad_agent; 232 struct ib_mad_agent *mad_agent;
225 struct ib_ah *ah; 233 struct ib_ah *ah;
226 void *context[2]; 234 void *context[2];
235 int hdr_len;
236 int data_len;
237 int seg_count;
238 int seg_size;
227 int timeout_ms; 239 int timeout_ms;
228 int retries; 240 int retries;
229}; 241};
@@ -299,7 +311,7 @@ typedef void (*ib_mad_snoop_handler)(struct ib_mad_agent *mad_agent,
299 * @mad_recv_wc: Received work completion information on the received MAD. 311 * @mad_recv_wc: Received work completion information on the received MAD.
300 * 312 *
301 * MADs received in response to a send request operation will be handed to 313 * MADs received in response to a send request operation will be handed to
302 * the user after the send operation completes. All data buffers given 314 * the user before the send operation completes. All data buffers given
303 * to registered agents through this routine are owned by the receiving 315 * to registered agents through this routine are owned by the receiving
304 * client, except for snooping agents. Clients snooping MADs should not 316 * client, except for snooping agents. Clients snooping MADs should not
305 * modify the data referenced by @mad_recv_wc. 317 * modify the data referenced by @mad_recv_wc.
@@ -485,17 +497,6 @@ int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);
485int ib_post_send_mad(struct ib_mad_send_buf *send_buf, 497int ib_post_send_mad(struct ib_mad_send_buf *send_buf,
486 struct ib_mad_send_buf **bad_send_buf); 498 struct ib_mad_send_buf **bad_send_buf);
487 499
488/**
489 * ib_coalesce_recv_mad - Coalesces received MAD data into a single buffer.
490 * @mad_recv_wc: Work completion information for a received MAD.
491 * @buf: User-provided data buffer to receive the coalesced buffers. The
492 * referenced buffer should be at least the size of the mad_len specified
493 * by @mad_recv_wc.
494 *
495 * This call copies a chain of received MAD segments into a single data buffer,
496 * removing duplicated headers.
497 */
498void ib_coalesce_recv_mad(struct ib_mad_recv_wc *mad_recv_wc, void *buf);
499 500
500/** 501/**
501 * ib_free_recv_mad - Returns data buffers used to receive a MAD. 502 * ib_free_recv_mad - Returns data buffers used to receive a MAD.
@@ -590,9 +591,10 @@ int ib_process_mad_wc(struct ib_mad_agent *mad_agent,
590 * with an initialized work request structure. Users may modify the returned 591 * with an initialized work request structure. Users may modify the returned
591 * MAD data buffer before posting the send. 592 * MAD data buffer before posting the send.
592 * 593 *
593 * The returned data buffer will be cleared. Users are responsible for 594 * The returned MAD header, class specific headers, and any padding will be
594 * initializing the common MAD and any class specific headers. If @rmpp_active 595 * cleared. Users are responsible for initializing the common MAD header,
595 * is set, the RMPP header will be initialized for sending. 596 * any class specific header, and MAD data area.
597 * If @rmpp_active is set, the RMPP header will be initialized for sending.
596 */ 598 */
597struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent, 599struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
598 u32 remote_qpn, u16 pkey_index, 600 u32 remote_qpn, u16 pkey_index,
@@ -601,6 +603,16 @@ struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
601 gfp_t gfp_mask); 603 gfp_t gfp_mask);
602 604
603/** 605/**
606 * ib_get_rmpp_segment - returns the data buffer for a given RMPP segment.
607 * @send_buf: Previously allocated send data buffer.
608 * @seg_num: number of segment to return
609 *
610 * This routine returns a pointer to the data buffer of an RMPP MAD.
611 * Users must provide synchronization to @send_buf around this call.
612 */
613void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num);
614
615/**
604 * ib_free_send_mad - Returns data buffers used to send a MAD. 616 * ib_free_send_mad - Returns data buffers used to send a MAD.
605 * @send_buf: Previously allocated send data buffer. 617 * @send_buf: Previously allocated send data buffer.
606 */ 618 */
diff --git a/include/rdma/ib_user_verbs.h b/include/rdma/ib_user_verbs.h
index 5ff1490c08db..338ed4333063 100644
--- a/include/rdma/ib_user_verbs.h
+++ b/include/rdma/ib_user_verbs.h
@@ -1,7 +1,8 @@
1/* 1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 3 * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 PathScale, Inc. All rights reserved. 4 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
5 * Copyright (c) 2006 Mellanox Technologies. All rights reserved.
5 * 6 *
6 * This software is available to you under a choice of one of two 7 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU 8 * licenses. You may choose to be licensed under the terms of the GNU
@@ -43,7 +44,7 @@
43 * Increment this value if any changes that break userspace ABI 44 * Increment this value if any changes that break userspace ABI
44 * compatibility are made. 45 * compatibility are made.
45 */ 46 */
46#define IB_USER_VERBS_ABI_VERSION 4 47#define IB_USER_VERBS_ABI_VERSION 6
47 48
48enum { 49enum {
49 IB_USER_VERBS_CMD_GET_CONTEXT, 50 IB_USER_VERBS_CMD_GET_CONTEXT,
@@ -265,6 +266,17 @@ struct ib_uverbs_create_cq_resp {
265 __u32 cqe; 266 __u32 cqe;
266}; 267};
267 268
269struct ib_uverbs_resize_cq {
270 __u64 response;
271 __u32 cq_handle;
272 __u32 cqe;
273 __u64 driver_data[0];
274};
275
276struct ib_uverbs_resize_cq_resp {
277 __u32 cqe;
278};
279
268struct ib_uverbs_poll_cq { 280struct ib_uverbs_poll_cq {
269 __u64 response; 281 __u64 response;
270 __u32 cq_handle; 282 __u32 cq_handle;
@@ -338,6 +350,7 @@ struct ib_uverbs_create_qp_resp {
338 __u32 max_send_sge; 350 __u32 max_send_sge;
339 __u32 max_recv_sge; 351 __u32 max_recv_sge;
340 __u32 max_inline_data; 352 __u32 max_inline_data;
353 __u32 reserved;
341}; 354};
342 355
343/* 356/*
@@ -359,6 +372,47 @@ struct ib_uverbs_qp_dest {
359 __u8 port_num; 372 __u8 port_num;
360}; 373};
361 374
375struct ib_uverbs_query_qp {
376 __u64 response;
377 __u32 qp_handle;
378 __u32 attr_mask;
379 __u64 driver_data[0];
380};
381
382struct ib_uverbs_query_qp_resp {
383 struct ib_uverbs_qp_dest dest;
384 struct ib_uverbs_qp_dest alt_dest;
385 __u32 max_send_wr;
386 __u32 max_recv_wr;
387 __u32 max_send_sge;
388 __u32 max_recv_sge;
389 __u32 max_inline_data;
390 __u32 qkey;
391 __u32 rq_psn;
392 __u32 sq_psn;
393 __u32 dest_qp_num;
394 __u32 qp_access_flags;
395 __u16 pkey_index;
396 __u16 alt_pkey_index;
397 __u8 qp_state;
398 __u8 cur_qp_state;
399 __u8 path_mtu;
400 __u8 path_mig_state;
401 __u8 en_sqd_async_notify;
402 __u8 max_rd_atomic;
403 __u8 max_dest_rd_atomic;
404 __u8 min_rnr_timer;
405 __u8 port_num;
406 __u8 timeout;
407 __u8 retry_cnt;
408 __u8 rnr_retry;
409 __u8 alt_port_num;
410 __u8 alt_timeout;
411 __u8 sq_sig_all;
412 __u8 reserved[5];
413 __u64 driver_data[0];
414};
415
362struct ib_uverbs_modify_qp { 416struct ib_uverbs_modify_qp {
363 struct ib_uverbs_qp_dest dest; 417 struct ib_uverbs_qp_dest dest;
364 struct ib_uverbs_qp_dest alt_dest; 418 struct ib_uverbs_qp_dest alt_dest;
@@ -415,7 +469,7 @@ struct ib_uverbs_sge {
415}; 469};
416 470
417struct ib_uverbs_send_wr { 471struct ib_uverbs_send_wr {
418 __u64 wr_id; 472 __u64 wr_id;
419 __u32 num_sge; 473 __u32 num_sge;
420 __u32 opcode; 474 __u32 opcode;
421 __u32 send_flags; 475 __u32 send_flags;
@@ -489,7 +543,7 @@ struct ib_uverbs_post_srq_recv_resp {
489 543
490struct ib_uverbs_global_route { 544struct ib_uverbs_global_route {
491 __u8 dgid[16]; 545 __u8 dgid[16];
492 __u32 flow_label; 546 __u32 flow_label;
493 __u8 sgid_index; 547 __u8 sgid_index;
494 __u8 hop_limit; 548 __u8 hop_limit;
495 __u8 traffic_class; 549 __u8 traffic_class;
@@ -551,6 +605,9 @@ struct ib_uverbs_create_srq {
551 605
552struct ib_uverbs_create_srq_resp { 606struct ib_uverbs_create_srq_resp {
553 __u32 srq_handle; 607 __u32 srq_handle;
608 __u32 max_wr;
609 __u32 max_sge;
610 __u32 reserved;
554}; 611};
555 612
556struct ib_uverbs_modify_srq { 613struct ib_uverbs_modify_srq {
@@ -561,6 +618,20 @@ struct ib_uverbs_modify_srq {
561 __u64 driver_data[0]; 618 __u64 driver_data[0];
562}; 619};
563 620
621struct ib_uverbs_query_srq {
622 __u64 response;
623 __u32 srq_handle;
624 __u32 reserved;
625 __u64 driver_data[0];
626};
627
628struct ib_uverbs_query_srq_resp {
629 __u32 max_wr;
630 __u32 max_sge;
631 __u32 srq_limit;
632 __u32 reserved;
633};
634
564struct ib_uverbs_destroy_srq { 635struct ib_uverbs_destroy_srq {
565 __u64 response; 636 __u64 response;
566 __u32 srq_handle; 637 __u32 srq_handle;
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 22fc886b9695..c1ad6273ac6c 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -5,7 +5,7 @@
5 * Copyright (c) 2004 Topspin Corporation. All rights reserved. 5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved. 6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
7 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. 7 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
8 * Copyright (c) 2005 Cisco Systems. All rights reserved. 8 * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
9 * 9 *
10 * This software is available to you under a choice of one of two 10 * This software is available to you under a choice of one of two
11 * licenses. You may choose to be licensed under the terms of the GNU 11 * licenses. You may choose to be licensed under the terms of the GNU
@@ -222,11 +222,13 @@ struct ib_port_attr {
222}; 222};
223 223
224enum ib_device_modify_flags { 224enum ib_device_modify_flags {
225 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 225 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
226 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
226}; 227};
227 228
228struct ib_device_modify { 229struct ib_device_modify {
229 u64 sys_image_guid; 230 u64 sys_image_guid;
231 char node_desc[64];
230}; 232};
231 233
232enum ib_port_modify_flags { 234enum ib_port_modify_flags {
@@ -649,7 +651,7 @@ struct ib_mw_bind {
649struct ib_fmr_attr { 651struct ib_fmr_attr {
650 int max_pages; 652 int max_pages;
651 int max_maps; 653 int max_maps;
652 u8 page_size; 654 u8 page_shift;
653}; 655};
654 656
655struct ib_ucontext { 657struct ib_ucontext {
@@ -880,7 +882,8 @@ struct ib_device {
880 struct ib_ucontext *context, 882 struct ib_ucontext *context,
881 struct ib_udata *udata); 883 struct ib_udata *udata);
882 int (*destroy_cq)(struct ib_cq *cq); 884 int (*destroy_cq)(struct ib_cq *cq);
883 int (*resize_cq)(struct ib_cq *cq, int cqe); 885 int (*resize_cq)(struct ib_cq *cq, int cqe,
886 struct ib_udata *udata);
884 int (*poll_cq)(struct ib_cq *cq, int num_entries, 887 int (*poll_cq)(struct ib_cq *cq, int num_entries,
885 struct ib_wc *wc); 888 struct ib_wc *wc);
886 int (*peek_cq)(struct ib_cq *cq, int wc_cnt); 889 int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
@@ -950,6 +953,7 @@ struct ib_device {
950 u64 uverbs_cmd_mask; 953 u64 uverbs_cmd_mask;
951 int uverbs_abi_ver; 954 int uverbs_abi_ver;
952 955
956 char node_desc[64];
953 __be64 node_guid; 957 __be64 node_guid;
954 u8 node_type; 958 u8 node_type;
955 u8 phys_port_cnt; 959 u8 phys_port_cnt;
@@ -986,6 +990,24 @@ static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len
986 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0; 990 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
987} 991}
988 992
993/**
994 * ib_modify_qp_is_ok - Check that the supplied attribute mask
995 * contains all required attributes and no attributes not allowed for
996 * the given QP state transition.
997 * @cur_state: Current QP state
998 * @next_state: Next QP state
999 * @type: QP type
1000 * @mask: Mask of supplied QP attributes
1001 *
1002 * This function is a helper function that a low-level driver's
1003 * modify_qp method can use to validate the consumer's input. It
1004 * checks that cur_state and next_state are valid QP states, that a
1005 * transition from cur_state to next_state is allowed by the IB spec,
1006 * and that the attribute mask supplied is allowed for the transition.
1007 */
1008int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
1009 enum ib_qp_type type, enum ib_qp_attr_mask mask);
1010
989int ib_register_event_handler (struct ib_event_handler *event_handler); 1011int ib_register_event_handler (struct ib_event_handler *event_handler);
990int ib_unregister_event_handler(struct ib_event_handler *event_handler); 1012int ib_unregister_event_handler(struct ib_event_handler *event_handler);
991void ib_dispatch_event(struct ib_event *event); 1013void ib_dispatch_event(struct ib_event *event);
@@ -1078,7 +1100,9 @@ int ib_destroy_ah(struct ib_ah *ah);
1078 * ib_create_srq - Creates a SRQ associated with the specified protection 1100 * ib_create_srq - Creates a SRQ associated with the specified protection
1079 * domain. 1101 * domain.
1080 * @pd: The protection domain associated with the SRQ. 1102 * @pd: The protection domain associated with the SRQ.
1081 * @srq_init_attr: A list of initial attributes required to create the SRQ. 1103 * @srq_init_attr: A list of initial attributes required to create the
1104 * SRQ. If SRQ creation succeeds, then the attributes are updated to
1105 * the actual capabilities of the created SRQ.
1082 * 1106 *
1083 * srq_attr->max_wr and srq_attr->max_sge are read the determine the 1107 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1084 * requested size of the SRQ, and set to the actual values allocated 1108 * requested size of the SRQ, and set to the actual values allocated
@@ -1137,7 +1161,9 @@ static inline int ib_post_srq_recv(struct ib_srq *srq,
1137 * ib_create_qp - Creates a QP associated with the specified protection 1161 * ib_create_qp - Creates a QP associated with the specified protection
1138 * domain. 1162 * domain.
1139 * @pd: The protection domain associated with the QP. 1163 * @pd: The protection domain associated with the QP.
1140 * @qp_init_attr: A list of initial attributes required to create the QP. 1164 * @qp_init_attr: A list of initial attributes required to create the
1165 * QP. If QP creation succeeds, then the attributes are updated to
1166 * the actual capabilities of the created QP.
1141 */ 1167 */
1142struct ib_qp *ib_create_qp(struct ib_pd *pd, 1168struct ib_qp *ib_create_qp(struct ib_pd *pd,
1143 struct ib_qp_init_attr *qp_init_attr); 1169 struct ib_qp_init_attr *qp_init_attr);
diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h
index fabd879c2f2e..d160880b2a87 100644
--- a/include/scsi/scsi_eh.h
+++ b/include/scsi/scsi_eh.h
@@ -35,6 +35,9 @@ static inline int scsi_sense_valid(struct scsi_sense_hdr *sshdr)
35} 35}
36 36
37 37
38extern void scsi_eh_finish_cmd(struct scsi_cmnd *scmd,
39 struct list_head *done_q);
40extern void scsi_eh_flush_done_q(struct list_head *done_q);
38extern void scsi_report_bus_reset(struct Scsi_Host *, int); 41extern void scsi_report_bus_reset(struct Scsi_Host *, int);
39extern void scsi_report_device_reset(struct Scsi_Host *, int, int); 42extern void scsi_report_device_reset(struct Scsi_Host *, int, int);
40extern int scsi_block_when_processing_errors(struct scsi_device *); 43extern int scsi_block_when_processing_errors(struct scsi_device *);
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index d5eeae0fa5bc..f2690ed74530 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -15,9 +15,6 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/init.h> 16#include <linux/init.h>
17 17
18u64 uevent_seqnum;
19char uevent_helper[UEVENT_HELPER_PATH_LEN] = "/sbin/hotplug";
20
21#define KERNEL_ATTR_RO(_name) \ 18#define KERNEL_ATTR_RO(_name) \
22static struct subsys_attribute _name##_attr = __ATTR_RO(_name) 19static struct subsys_attribute _name##_attr = __ATTR_RO(_name)
23 20
diff --git a/kernel/module.c b/kernel/module.c
index 5aad477ddc79..77764f22f021 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -126,8 +126,11 @@ extern const struct kernel_symbol __start___ksymtab[];
126extern const struct kernel_symbol __stop___ksymtab[]; 126extern const struct kernel_symbol __stop___ksymtab[];
127extern const struct kernel_symbol __start___ksymtab_gpl[]; 127extern const struct kernel_symbol __start___ksymtab_gpl[];
128extern const struct kernel_symbol __stop___ksymtab_gpl[]; 128extern const struct kernel_symbol __stop___ksymtab_gpl[];
129extern const struct kernel_symbol __start___ksymtab_gpl_future[];
130extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
129extern const unsigned long __start___kcrctab[]; 131extern const unsigned long __start___kcrctab[];
130extern const unsigned long __start___kcrctab_gpl[]; 132extern const unsigned long __start___kcrctab_gpl[];
133extern const unsigned long __start___kcrctab_gpl_future[];
131 134
132#ifndef CONFIG_MODVERSIONS 135#ifndef CONFIG_MODVERSIONS
133#define symversion(base, idx) NULL 136#define symversion(base, idx) NULL
@@ -135,6 +138,18 @@ extern const unsigned long __start___kcrctab_gpl[];
135#define symversion(base, idx) ((base) ? ((base) + (idx)) : NULL) 138#define symversion(base, idx) ((base) ? ((base) + (idx)) : NULL)
136#endif 139#endif
137 140
141/* lookup symbol in given range of kernel_symbols */
142static const struct kernel_symbol *lookup_symbol(const char *name,
143 const struct kernel_symbol *start,
144 const struct kernel_symbol *stop)
145{
146 const struct kernel_symbol *ks = start;
147 for (; ks < stop; ks++)
148 if (strcmp(ks->name, name) == 0)
149 return ks;
150 return NULL;
151}
152
138/* Find a symbol, return value, crc and module which owns it */ 153/* Find a symbol, return value, crc and module which owns it */
139static unsigned long __find_symbol(const char *name, 154static unsigned long __find_symbol(const char *name,
140 struct module **owner, 155 struct module **owner,
@@ -142,40 +157,75 @@ static unsigned long __find_symbol(const char *name,
142 int gplok) 157 int gplok)
143{ 158{
144 struct module *mod; 159 struct module *mod;
145 unsigned int i; 160 const struct kernel_symbol *ks;
146 161
147 /* Core kernel first. */ 162 /* Core kernel first. */
148 *owner = NULL; 163 *owner = NULL;
149 for (i = 0; __start___ksymtab+i < __stop___ksymtab; i++) { 164 ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab);
150 if (strcmp(__start___ksymtab[i].name, name) == 0) { 165 if (ks) {
151 *crc = symversion(__start___kcrctab, i); 166 *crc = symversion(__start___kcrctab, (ks - __start___ksymtab));
152 return __start___ksymtab[i].value; 167 return ks->value;
153 }
154 } 168 }
155 if (gplok) { 169 if (gplok) {
156 for (i = 0; __start___ksymtab_gpl+i<__stop___ksymtab_gpl; i++) 170 ks = lookup_symbol(name, __start___ksymtab_gpl,
157 if (strcmp(__start___ksymtab_gpl[i].name, name) == 0) { 171 __stop___ksymtab_gpl);
158 *crc = symversion(__start___kcrctab_gpl, i); 172 if (ks) {
159 return __start___ksymtab_gpl[i].value; 173 *crc = symversion(__start___kcrctab_gpl,
160 } 174 (ks - __start___ksymtab_gpl));
175 return ks->value;
176 }
177 }
178 ks = lookup_symbol(name, __start___ksymtab_gpl_future,
179 __stop___ksymtab_gpl_future);
180 if (ks) {
181 if (!gplok) {
182 printk(KERN_WARNING "Symbol %s is being used "
183 "by a non-GPL module, which will not "
184 "be allowed in the future\n", name);
185 printk(KERN_WARNING "Please see the file "
186 "Documentation/feature-removal-schedule.txt "
187 "in the kernel source tree for more "
188 "details.\n");
189 }
190 *crc = symversion(__start___kcrctab_gpl_future,
191 (ks - __start___ksymtab_gpl_future));
192 return ks->value;
161 } 193 }
162 194
163 /* Now try modules. */ 195 /* Now try modules. */
164 list_for_each_entry(mod, &modules, list) { 196 list_for_each_entry(mod, &modules, list) {
165 *owner = mod; 197 *owner = mod;
166 for (i = 0; i < mod->num_syms; i++) 198 ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms);
167 if (strcmp(mod->syms[i].name, name) == 0) { 199 if (ks) {
168 *crc = symversion(mod->crcs, i); 200 *crc = symversion(mod->crcs, (ks - mod->syms));
169 return mod->syms[i].value; 201 return ks->value;
170 } 202 }
171 203
172 if (gplok) { 204 if (gplok) {
173 for (i = 0; i < mod->num_gpl_syms; i++) { 205 ks = lookup_symbol(name, mod->gpl_syms,
174 if (strcmp(mod->gpl_syms[i].name, name) == 0) { 206 mod->gpl_syms + mod->num_gpl_syms);
175 *crc = symversion(mod->gpl_crcs, i); 207 if (ks) {
176 return mod->gpl_syms[i].value; 208 *crc = symversion(mod->gpl_crcs,
177 } 209 (ks - mod->gpl_syms));
210 return ks->value;
211 }
212 }
213 ks = lookup_symbol(name, mod->gpl_future_syms,
214 (mod->gpl_future_syms +
215 mod->num_gpl_future_syms));
216 if (ks) {
217 if (!gplok) {
218 printk(KERN_WARNING "Symbol %s is being used "
219 "by a non-GPL module, which will not "
220 "be allowed in the future\n", name);
221 printk(KERN_WARNING "Please see the file "
222 "Documentation/feature-removal-schedule.txt "
223 "in the kernel source tree for more "
224 "details.\n");
178 } 225 }
226 *crc = symversion(mod->gpl_future_crcs,
227 (ks - mod->gpl_future_syms));
228 return ks->value;
179 } 229 }
180 } 230 }
181 DEBUGP("Failed to find symbol %s\n", name); 231 DEBUGP("Failed to find symbol %s\n", name);
@@ -379,7 +429,6 @@ static inline void percpu_modcopy(void *pcpudst, const void *src,
379} 429}
380#endif /* CONFIG_SMP */ 430#endif /* CONFIG_SMP */
381 431
382#ifdef CONFIG_MODULE_UNLOAD
383#define MODINFO_ATTR(field) \ 432#define MODINFO_ATTR(field) \
384static void setup_modinfo_##field(struct module *mod, const char *s) \ 433static void setup_modinfo_##field(struct module *mod, const char *s) \
385{ \ 434{ \
@@ -411,12 +460,7 @@ static struct module_attribute modinfo_##field = { \
411MODINFO_ATTR(version); 460MODINFO_ATTR(version);
412MODINFO_ATTR(srcversion); 461MODINFO_ATTR(srcversion);
413 462
414static struct module_attribute *modinfo_attrs[] = { 463#ifdef CONFIG_MODULE_UNLOAD
415 &modinfo_version,
416 &modinfo_srcversion,
417 NULL,
418};
419
420/* Init the unload section of the module. */ 464/* Init the unload section of the module. */
421static void module_unload_init(struct module *mod) 465static void module_unload_init(struct module *mod)
422{ 466{
@@ -731,6 +775,15 @@ static inline void module_unload_init(struct module *mod)
731} 775}
732#endif /* CONFIG_MODULE_UNLOAD */ 776#endif /* CONFIG_MODULE_UNLOAD */
733 777
778static struct module_attribute *modinfo_attrs[] = {
779 &modinfo_version,
780 &modinfo_srcversion,
781#ifdef CONFIG_MODULE_UNLOAD
782 &refcnt,
783#endif
784 NULL,
785};
786
734#ifdef CONFIG_OBSOLETE_MODPARM 787#ifdef CONFIG_OBSOLETE_MODPARM
735/* Bounds checking done below */ 788/* Bounds checking done below */
736static int obsparm_copy_string(const char *val, struct kernel_param *kp) 789static int obsparm_copy_string(const char *val, struct kernel_param *kp)
@@ -1056,37 +1109,28 @@ static inline void remove_sect_attrs(struct module *mod)
1056} 1109}
1057#endif /* CONFIG_KALLSYMS */ 1110#endif /* CONFIG_KALLSYMS */
1058 1111
1059
1060#ifdef CONFIG_MODULE_UNLOAD
1061static inline int module_add_refcnt_attr(struct module *mod)
1062{
1063 return sysfs_create_file(&mod->mkobj.kobj, &refcnt.attr);
1064}
1065static void module_remove_refcnt_attr(struct module *mod)
1066{
1067 return sysfs_remove_file(&mod->mkobj.kobj, &refcnt.attr);
1068}
1069#else
1070static inline int module_add_refcnt_attr(struct module *mod)
1071{
1072 return 0;
1073}
1074static void module_remove_refcnt_attr(struct module *mod)
1075{
1076}
1077#endif
1078
1079#ifdef CONFIG_MODULE_UNLOAD
1080static int module_add_modinfo_attrs(struct module *mod) 1112static int module_add_modinfo_attrs(struct module *mod)
1081{ 1113{
1082 struct module_attribute *attr; 1114 struct module_attribute *attr;
1115 struct module_attribute *temp_attr;
1083 int error = 0; 1116 int error = 0;
1084 int i; 1117 int i;
1085 1118
1119 mod->modinfo_attrs = kzalloc((sizeof(struct module_attribute) *
1120 (ARRAY_SIZE(modinfo_attrs) + 1)),
1121 GFP_KERNEL);
1122 if (!mod->modinfo_attrs)
1123 return -ENOMEM;
1124
1125 temp_attr = mod->modinfo_attrs;
1086 for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) { 1126 for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) {
1087 if (!attr->test || 1127 if (!attr->test ||
1088 (attr->test && attr->test(mod))) 1128 (attr->test && attr->test(mod))) {
1089 error = sysfs_create_file(&mod->mkobj.kobj,&attr->attr); 1129 memcpy(temp_attr, attr, sizeof(*temp_attr));
1130 temp_attr->attr.owner = mod;
1131 error = sysfs_create_file(&mod->mkobj.kobj,&temp_attr->attr);
1132 ++temp_attr;
1133 }
1090 } 1134 }
1091 return error; 1135 return error;
1092} 1136}
@@ -1096,12 +1140,16 @@ static void module_remove_modinfo_attrs(struct module *mod)
1096 struct module_attribute *attr; 1140 struct module_attribute *attr;
1097 int i; 1141 int i;
1098 1142
1099 for (i = 0; (attr = modinfo_attrs[i]); i++) { 1143 for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) {
1144 /* pick a field to test for end of list */
1145 if (!attr->attr.name)
1146 break;
1100 sysfs_remove_file(&mod->mkobj.kobj,&attr->attr); 1147 sysfs_remove_file(&mod->mkobj.kobj,&attr->attr);
1101 attr->free(mod); 1148 if (attr->free)
1149 attr->free(mod);
1102 } 1150 }
1151 kfree(mod->modinfo_attrs);
1103} 1152}
1104#endif
1105 1153
1106static int mod_sysfs_setup(struct module *mod, 1154static int mod_sysfs_setup(struct module *mod,
1107 struct kernel_param *kparam, 1155 struct kernel_param *kparam,
@@ -1119,19 +1167,13 @@ static int mod_sysfs_setup(struct module *mod,
1119 if (err) 1167 if (err)
1120 goto out; 1168 goto out;
1121 1169
1122 err = module_add_refcnt_attr(mod);
1123 if (err)
1124 goto out_unreg;
1125
1126 err = module_param_sysfs_setup(mod, kparam, num_params); 1170 err = module_param_sysfs_setup(mod, kparam, num_params);
1127 if (err) 1171 if (err)
1128 goto out_unreg; 1172 goto out_unreg;
1129 1173
1130#ifdef CONFIG_MODULE_UNLOAD
1131 err = module_add_modinfo_attrs(mod); 1174 err = module_add_modinfo_attrs(mod);
1132 if (err) 1175 if (err)
1133 goto out_unreg; 1176 goto out_unreg;
1134#endif
1135 1177
1136 return 0; 1178 return 0;
1137 1179
@@ -1143,10 +1185,7 @@ out:
1143 1185
1144static void mod_kobject_remove(struct module *mod) 1186static void mod_kobject_remove(struct module *mod)
1145{ 1187{
1146#ifdef CONFIG_MODULE_UNLOAD
1147 module_remove_modinfo_attrs(mod); 1188 module_remove_modinfo_attrs(mod);
1148#endif
1149 module_remove_refcnt_attr(mod);
1150 module_param_sysfs_remove(mod); 1189 module_param_sysfs_remove(mod);
1151 1190
1152 kobject_unregister(&mod->mkobj.kobj); 1191 kobject_unregister(&mod->mkobj.kobj);
@@ -1424,7 +1463,6 @@ static char *get_modinfo(Elf_Shdr *sechdrs,
1424 return NULL; 1463 return NULL;
1425} 1464}
1426 1465
1427#ifdef CONFIG_MODULE_UNLOAD
1428static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, 1466static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs,
1429 unsigned int infoindex) 1467 unsigned int infoindex)
1430{ 1468{
@@ -1439,23 +1477,17 @@ static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs,
1439 attr->attr.name)); 1477 attr->attr.name));
1440 } 1478 }
1441} 1479}
1442#endif
1443 1480
1444#ifdef CONFIG_KALLSYMS 1481#ifdef CONFIG_KALLSYMS
1445int is_exported(const char *name, const struct module *mod) 1482int is_exported(const char *name, const struct module *mod)
1446{ 1483{
1447 unsigned int i; 1484 if (!mod && lookup_symbol(name, __start___ksymtab, __stop___ksymtab))
1448 1485 return 1;
1449 if (!mod) { 1486 else
1450 for (i = 0; __start___ksymtab+i < __stop___ksymtab; i++) 1487 if (lookup_symbol(name, mod->syms, mod->syms + mod->num_syms))
1451 if (strcmp(__start___ksymtab[i].name, name) == 0)
1452 return 1;
1453 return 0;
1454 }
1455 for (i = 0; i < mod->num_syms; i++)
1456 if (strcmp(mod->syms[i].name, name) == 0)
1457 return 1; 1488 return 1;
1458 return 0; 1489 else
1490 return 0;
1459} 1491}
1460 1492
1461/* As per nm */ 1493/* As per nm */
@@ -1537,7 +1569,8 @@ static struct module *load_module(void __user *umod,
1537 char *secstrings, *args, *modmagic, *strtab = NULL; 1569 char *secstrings, *args, *modmagic, *strtab = NULL;
1538 unsigned int i, symindex = 0, strindex = 0, setupindex, exindex, 1570 unsigned int i, symindex = 0, strindex = 0, setupindex, exindex,
1539 exportindex, modindex, obsparmindex, infoindex, gplindex, 1571 exportindex, modindex, obsparmindex, infoindex, gplindex,
1540 crcindex, gplcrcindex, versindex, pcpuindex; 1572 crcindex, gplcrcindex, versindex, pcpuindex, gplfutureindex,
1573 gplfuturecrcindex;
1541 long arglen; 1574 long arglen;
1542 struct module *mod; 1575 struct module *mod;
1543 long err = 0; 1576 long err = 0;
@@ -1618,8 +1651,10 @@ static struct module *load_module(void __user *umod,
1618 /* Optional sections */ 1651 /* Optional sections */
1619 exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab"); 1652 exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab");
1620 gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl"); 1653 gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl");
1654 gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future");
1621 crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab"); 1655 crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab");
1622 gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl"); 1656 gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl");
1657 gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future");
1623 setupindex = find_sec(hdr, sechdrs, secstrings, "__param"); 1658 setupindex = find_sec(hdr, sechdrs, secstrings, "__param");
1624 exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table"); 1659 exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table");
1625 obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm"); 1660 obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm");
@@ -1755,10 +1790,8 @@ static struct module *load_module(void __user *umod,
1755 if (strcmp(mod->name, "driverloader") == 0) 1790 if (strcmp(mod->name, "driverloader") == 0)
1756 add_taint(TAINT_PROPRIETARY_MODULE); 1791 add_taint(TAINT_PROPRIETARY_MODULE);
1757 1792
1758#ifdef CONFIG_MODULE_UNLOAD
1759 /* Set up MODINFO_ATTR fields */ 1793 /* Set up MODINFO_ATTR fields */
1760 setup_modinfo(mod, sechdrs, infoindex); 1794 setup_modinfo(mod, sechdrs, infoindex);
1761#endif
1762 1795
1763 /* Fix up syms, so that st_value is a pointer to location. */ 1796 /* Fix up syms, so that st_value is a pointer to location. */
1764 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex, 1797 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex,
@@ -1775,10 +1808,16 @@ static struct module *load_module(void __user *umod,
1775 mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr; 1808 mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr;
1776 if (gplcrcindex) 1809 if (gplcrcindex)
1777 mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; 1810 mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr;
1811 mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size /
1812 sizeof(*mod->gpl_future_syms);
1813 mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr;
1814 if (gplfuturecrcindex)
1815 mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr;
1778 1816
1779#ifdef CONFIG_MODVERSIONS 1817#ifdef CONFIG_MODVERSIONS
1780 if ((mod->num_syms && !crcindex) || 1818 if ((mod->num_syms && !crcindex) ||
1781 (mod->num_gpl_syms && !gplcrcindex)) { 1819 (mod->num_gpl_syms && !gplcrcindex) ||
1820 (mod->num_gpl_future_syms && !gplfuturecrcindex)) {
1782 printk(KERN_WARNING "%s: No versions for exported symbols." 1821 printk(KERN_WARNING "%s: No versions for exported symbols."
1783 " Tainting kernel.\n", mod->name); 1822 " Tainting kernel.\n", mod->name);
1784 add_taint(TAINT_FORCED_MODULE); 1823 add_taint(TAINT_FORCED_MODULE);
diff --git a/kernel/params.c b/kernel/params.c
index c76ad25e6a21..a29150582310 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -638,13 +638,8 @@ static ssize_t module_attr_show(struct kobject *kobj,
638 if (!attribute->show) 638 if (!attribute->show)
639 return -EIO; 639 return -EIO;
640 640
641 if (!try_module_get(mk->mod))
642 return -ENODEV;
643
644 ret = attribute->show(attribute, mk->mod, buf); 641 ret = attribute->show(attribute, mk->mod, buf);
645 642
646 module_put(mk->mod);
647
648 return ret; 643 return ret;
649} 644}
650 645
@@ -662,13 +657,8 @@ static ssize_t module_attr_store(struct kobject *kobj,
662 if (!attribute->store) 657 if (!attribute->store)
663 return -EIO; 658 return -EIO;
664 659
665 if (!try_module_get(mk->mod))
666 return -ENODEV;
667
668 ret = attribute->store(attribute, mk->mod, buf, len); 660 ret = attribute->store(attribute, mk->mod, buf, len);
669 661
670 module_put(mk->mod);
671
672 return ret; 662 return ret;
673} 663}
674 664
diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
index 8cf15a569fcd..fedf5e369755 100644
--- a/kernel/rcupdate.c
+++ b/kernel/rcupdate.c
@@ -609,7 +609,7 @@ module_param(qlowmark, int, 0);
609module_param(rsinterval, int, 0); 609module_param(rsinterval, int, 0);
610#endif 610#endif
611EXPORT_SYMBOL_GPL(rcu_batches_completed); 611EXPORT_SYMBOL_GPL(rcu_batches_completed);
612EXPORT_SYMBOL(call_rcu); /* WARNING: GPL-only in April 2006. */ 612EXPORT_SYMBOL_GPL_FUTURE(call_rcu); /* WARNING: GPL-only in April 2006. */
613EXPORT_SYMBOL(call_rcu_bh); /* WARNING: GPL-only in April 2006. */ 613EXPORT_SYMBOL_GPL_FUTURE(call_rcu_bh); /* WARNING: GPL-only in April 2006. */
614EXPORT_SYMBOL_GPL(synchronize_rcu); 614EXPORT_SYMBOL_GPL(synchronize_rcu);
615EXPORT_SYMBOL(synchronize_kernel); /* WARNING: GPL-only in April 2006. */ 615EXPORT_SYMBOL_GPL_FUTURE(synchronize_kernel); /* WARNING: GPL-only in April 2006. */
diff --git a/lib/kobject.c b/lib/kobject.c
index efe67fa96a71..25204a41a9b0 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -194,6 +194,17 @@ int kobject_add(struct kobject * kobj)
194 unlink(kobj); 194 unlink(kobj);
195 if (parent) 195 if (parent)
196 kobject_put(parent); 196 kobject_put(parent);
197
198 /* be noisy on error issues */
199 if (error == -EEXIST)
200 printk("kobject_add failed for %s with -EEXIST, "
201 "don't try to register things with the "
202 "same name in the same directory.\n",
203 kobject_name(kobj));
204 else
205 printk("kobject_add failed for %s (%d)\n",
206 kobject_name(kobj), error);
207 dump_stack();
197 } 208 }
198 209
199 return error; 210 return error;
@@ -207,18 +218,13 @@ int kobject_add(struct kobject * kobj)
207 218
208int kobject_register(struct kobject * kobj) 219int kobject_register(struct kobject * kobj)
209{ 220{
210 int error = 0; 221 int error = -EINVAL;
211 if (kobj) { 222 if (kobj) {
212 kobject_init(kobj); 223 kobject_init(kobj);
213 error = kobject_add(kobj); 224 error = kobject_add(kobj);
214 if (error) { 225 if (!error)
215 printk("kobject_register failed for %s (%d)\n",
216 kobject_name(kobj),error);
217 dump_stack();
218 } else
219 kobject_uevent(kobj, KOBJ_ADD); 226 kobject_uevent(kobj, KOBJ_ADD);
220 } else 227 }
221 error = -EINVAL;
222 return error; 228 return error;
223} 229}
224 230
@@ -379,6 +385,44 @@ void kobject_put(struct kobject * kobj)
379} 385}
380 386
381 387
388static void dir_release(struct kobject *kobj)
389{
390 kfree(kobj);
391}
392
393static struct kobj_type dir_ktype = {
394 .release = dir_release,
395 .sysfs_ops = NULL,
396 .default_attrs = NULL,
397};
398
399/**
400 * kobject_add_dir - add sub directory of object.
401 * @parent: object in which a directory is created.
402 * @name: directory name.
403 *
404 * Add a plain directory object as child of given object.
405 */
406struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
407{
408 struct kobject *k;
409
410 if (!parent)
411 return NULL;
412
413 k = kzalloc(sizeof(*k), GFP_KERNEL);
414 if (!k)
415 return NULL;
416
417 k->parent = parent;
418 k->ktype = &dir_ktype;
419 kobject_set_name(k, name);
420 kobject_register(k);
421
422 return k;
423}
424EXPORT_SYMBOL_GPL(kobject_add_dir);
425
382/** 426/**
383 * kset_init - initialize a kset for use 427 * kset_init - initialize a kset for use
384 * @k: kset 428 * @k: kset
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 086a0c6e888e..982226daf939 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -26,6 +26,8 @@
26#define NUM_ENVP 32 /* number of env pointers */ 26#define NUM_ENVP 32 /* number of env pointers */
27 27
28#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) 28#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
29u64 uevent_seqnum;
30char uevent_helper[UEVENT_HELPER_PATH_LEN] = "/sbin/hotplug";
29static DEFINE_SPINLOCK(sequence_lock); 31static DEFINE_SPINLOCK(sequence_lock);
30static struct sock *uevent_sock; 32static struct sock *uevent_sock;
31 33
diff --git a/lib/kref.c b/lib/kref.c
index 0d07cc31c818..4a467faf1367 100644
--- a/lib/kref.c
+++ b/lib/kref.c
@@ -52,7 +52,12 @@ int kref_put(struct kref *kref, void (*release)(struct kref *kref))
52 WARN_ON(release == NULL); 52 WARN_ON(release == NULL);
53 WARN_ON(release == (void (*)(struct kref *))kfree); 53 WARN_ON(release == (void (*)(struct kref *))kfree);
54 54
55 if (atomic_dec_and_test(&kref->refcount)) { 55 /*
56 * if current count is one, we are the last user and can release object
57 * right now, avoiding an atomic operation on 'refcount'
58 */
59 if ((atomic_read(&kref->refcount) == 1) ||
60 (atomic_dec_and_test(&kref->refcount))) {
56 release(kref); 61 release(kref);
57 return 1; 62 return 1;
58 } 63 }
diff --git a/net/802/psnap.c b/net/802/psnap.c
index 34e42968b477..270b9d2cae65 100644
--- a/net/802/psnap.c
+++ b/net/802/psnap.c
@@ -59,10 +59,8 @@ static int snap_rcv(struct sk_buff *skb, struct net_device *dev,
59 proto = find_snap_client(skb->h.raw); 59 proto = find_snap_client(skb->h.raw);
60 if (proto) { 60 if (proto) {
61 /* Pass the frame on. */ 61 /* Pass the frame on. */
62 u8 *hdr = skb->data;
63 skb->h.raw += 5; 62 skb->h.raw += 5;
64 skb_pull(skb, 5); 63 skb_pull_rcsum(skb, 5);
65 skb_postpull_rcsum(skb, hdr, 5);
66 rc = proto->rcvfunc(skb, dev, &snap_packet_type, orig_dev); 64 rc = proto->rcvfunc(skb, dev, &snap_packet_type, orig_dev);
67 } else { 65 } else {
68 skb->sk = NULL; 66 skb->sk = NULL;
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index fa76220708ce..3948949a609a 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -69,7 +69,7 @@ static struct packet_type vlan_packet_type = {
69 69
70/* Bits of netdev state that are propagated from real device to virtual */ 70/* Bits of netdev state that are propagated from real device to virtual */
71#define VLAN_LINK_STATE_MASK \ 71#define VLAN_LINK_STATE_MASK \
72 ((1<<__LINK_STATE_PRESENT)|(1<<__LINK_STATE_NOCARRIER)) 72 ((1<<__LINK_STATE_PRESENT)|(1<<__LINK_STATE_NOCARRIER)|(1<<__LINK_STATE_DORMANT))
73 73
74/* End of global variables definitions. */ 74/* End of global variables definitions. */
75 75
@@ -344,6 +344,26 @@ static void vlan_setup(struct net_device *new_dev)
344 new_dev->do_ioctl = vlan_dev_ioctl; 344 new_dev->do_ioctl = vlan_dev_ioctl;
345} 345}
346 346
347static void vlan_transfer_operstate(const struct net_device *dev, struct net_device *vlandev)
348{
349 /* Have to respect userspace enforced dormant state
350 * of real device, also must allow supplicant running
351 * on VLAN device
352 */
353 if (dev->operstate == IF_OPER_DORMANT)
354 netif_dormant_on(vlandev);
355 else
356 netif_dormant_off(vlandev);
357
358 if (netif_carrier_ok(dev)) {
359 if (!netif_carrier_ok(vlandev))
360 netif_carrier_on(vlandev);
361 } else {
362 if (netif_carrier_ok(vlandev))
363 netif_carrier_off(vlandev);
364 }
365}
366
347/* Attach a VLAN device to a mac address (ie Ethernet Card). 367/* Attach a VLAN device to a mac address (ie Ethernet Card).
348 * Returns the device that was created, or NULL if there was 368 * Returns the device that was created, or NULL if there was
349 * an error of some kind. 369 * an error of some kind.
@@ -450,7 +470,7 @@ static struct net_device *register_vlan_device(const char *eth_IF_name,
450 new_dev->flags = real_dev->flags; 470 new_dev->flags = real_dev->flags;
451 new_dev->flags &= ~IFF_UP; 471 new_dev->flags &= ~IFF_UP;
452 472
453 new_dev->state = real_dev->state & VLAN_LINK_STATE_MASK; 473 new_dev->state = real_dev->state & ~(1<<__LINK_STATE_START);
454 474
455 /* need 4 bytes for extra VLAN header info, 475 /* need 4 bytes for extra VLAN header info,
456 * hope the underlying device can handle it. 476 * hope the underlying device can handle it.
@@ -498,6 +518,10 @@ static struct net_device *register_vlan_device(const char *eth_IF_name,
498 if (register_netdevice(new_dev)) 518 if (register_netdevice(new_dev))
499 goto out_free_newdev; 519 goto out_free_newdev;
500 520
521 new_dev->iflink = real_dev->ifindex;
522 vlan_transfer_operstate(real_dev, new_dev);
523 linkwatch_fire_event(new_dev); /* _MUST_ call rfc2863_policy() */
524
501 /* So, got the sucker initialized, now lets place 525 /* So, got the sucker initialized, now lets place
502 * it into our local structure. 526 * it into our local structure.
503 */ 527 */
@@ -573,25 +597,12 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
573 switch (event) { 597 switch (event) {
574 case NETDEV_CHANGE: 598 case NETDEV_CHANGE:
575 /* Propagate real device state to vlan devices */ 599 /* Propagate real device state to vlan devices */
576 flgs = dev->state & VLAN_LINK_STATE_MASK;
577 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { 600 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
578 vlandev = grp->vlan_devices[i]; 601 vlandev = grp->vlan_devices[i];
579 if (!vlandev) 602 if (!vlandev)
580 continue; 603 continue;
581 604
582 if (netif_carrier_ok(dev)) { 605 vlan_transfer_operstate(dev, vlandev);
583 if (!netif_carrier_ok(vlandev))
584 netif_carrier_on(vlandev);
585 } else {
586 if (netif_carrier_ok(vlandev))
587 netif_carrier_off(vlandev);
588 }
589
590 if ((vlandev->state & VLAN_LINK_STATE_MASK) != flgs) {
591 vlandev->state = (vlandev->state &~ VLAN_LINK_STATE_MASK)
592 | flgs;
593 netdev_state_change(vlandev);
594 }
595 } 606 }
596 break; 607 break;
597 608
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index 0f604d227da2..da9cfe927158 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -163,10 +163,8 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
163 stats->rx_packets++; 163 stats->rx_packets++;
164 stats->rx_bytes += skb->len; 164 stats->rx_bytes += skb->len;
165 165
166 skb_pull(skb, VLAN_HLEN); /* take off the VLAN header (4 bytes currently) */ 166 /* Take off the VLAN header (4 bytes currently) */
167 167 skb_pull_rcsum(skb, VLAN_HLEN);
168 /* Need to correct hardware checksum */
169 skb_postpull_rcsum(skb, vhdr, VLAN_HLEN);
170 168
171 /* Ok, lets check to make sure the device (dev) we 169 /* Ok, lets check to make sure the device (dev) we
172 * came in on is what this VLAN is attached to. 170 * came in on is what this VLAN is attached to.
diff --git a/net/atm/clip.c b/net/atm/clip.c
index 73370de97539..3ab4e7947bab 100644
--- a/net/atm/clip.c
+++ b/net/atm/clip.c
@@ -289,7 +289,6 @@ static void clip_neigh_error(struct neighbour *neigh,struct sk_buff *skb)
289 289
290static struct neigh_ops clip_neigh_ops = { 290static struct neigh_ops clip_neigh_ops = {
291 .family = AF_INET, 291 .family = AF_INET,
292 .destructor = clip_neigh_destroy,
293 .solicit = clip_neigh_solicit, 292 .solicit = clip_neigh_solicit,
294 .error_report = clip_neigh_error, 293 .error_report = clip_neigh_error,
295 .output = dev_queue_xmit, 294 .output = dev_queue_xmit,
@@ -347,6 +346,7 @@ static struct neigh_table clip_tbl = {
347 /* parameters are copied from ARP ... */ 346 /* parameters are copied from ARP ... */
348 .parms = { 347 .parms = {
349 .tbl = &clip_tbl, 348 .tbl = &clip_tbl,
349 .neigh_destructor = clip_neigh_destroy,
350 .base_reachable_time = 30 * HZ, 350 .base_reachable_time = 30 * HZ,
351 .retrans_time = 1 * HZ, 351 .retrans_time = 1 * HZ,
352 .gc_staletime = 60 * HZ, 352 .gc_staletime = 60 * HZ,
diff --git a/net/atm/common.c b/net/atm/common.c
index 6656b111cc05..ae002220fa99 100644
--- a/net/atm/common.c
+++ b/net/atm/common.c
@@ -451,12 +451,12 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
451 dev = try_then_request_module(atm_dev_lookup(itf), "atm-device-%d", itf); 451 dev = try_then_request_module(atm_dev_lookup(itf), "atm-device-%d", itf);
452 } else { 452 } else {
453 dev = NULL; 453 dev = NULL;
454 down(&atm_dev_mutex); 454 mutex_lock(&atm_dev_mutex);
455 if (!list_empty(&atm_devs)) { 455 if (!list_empty(&atm_devs)) {
456 dev = list_entry(atm_devs.next, struct atm_dev, dev_list); 456 dev = list_entry(atm_devs.next, struct atm_dev, dev_list);
457 atm_dev_hold(dev); 457 atm_dev_hold(dev);
458 } 458 }
459 up(&atm_dev_mutex); 459 mutex_unlock(&atm_dev_mutex);
460 } 460 }
461 if (!dev) 461 if (!dev)
462 return -ENODEV; 462 return -ENODEV;
diff --git a/net/atm/ioctl.c b/net/atm/ioctl.c
index eb109af7eb4a..851cfa6312af 100644
--- a/net/atm/ioctl.c
+++ b/net/atm/ioctl.c
@@ -18,6 +18,7 @@
18#include <linux/atmmpc.h> 18#include <linux/atmmpc.h>
19#include <net/atmclip.h> 19#include <net/atmclip.h>
20#include <linux/atmlec.h> 20#include <linux/atmlec.h>
21#include <linux/mutex.h>
21#include <asm/ioctls.h> 22#include <asm/ioctls.h>
22 23
23#include "resources.h" 24#include "resources.h"
@@ -25,22 +26,22 @@
25#include "common.h" 26#include "common.h"
26 27
27 28
28static DECLARE_MUTEX(ioctl_mutex); 29static DEFINE_MUTEX(ioctl_mutex);
29static LIST_HEAD(ioctl_list); 30static LIST_HEAD(ioctl_list);
30 31
31 32
32void register_atm_ioctl(struct atm_ioctl *ioctl) 33void register_atm_ioctl(struct atm_ioctl *ioctl)
33{ 34{
34 down(&ioctl_mutex); 35 mutex_lock(&ioctl_mutex);
35 list_add_tail(&ioctl->list, &ioctl_list); 36 list_add_tail(&ioctl->list, &ioctl_list);
36 up(&ioctl_mutex); 37 mutex_unlock(&ioctl_mutex);
37} 38}
38 39
39void deregister_atm_ioctl(struct atm_ioctl *ioctl) 40void deregister_atm_ioctl(struct atm_ioctl *ioctl)
40{ 41{
41 down(&ioctl_mutex); 42 mutex_lock(&ioctl_mutex);
42 list_del(&ioctl->list); 43 list_del(&ioctl->list);
43 up(&ioctl_mutex); 44 mutex_unlock(&ioctl_mutex);
44} 45}
45 46
46EXPORT_SYMBOL(register_atm_ioctl); 47EXPORT_SYMBOL(register_atm_ioctl);
@@ -137,7 +138,7 @@ int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
137 138
138 error = -ENOIOCTLCMD; 139 error = -ENOIOCTLCMD;
139 140
140 down(&ioctl_mutex); 141 mutex_lock(&ioctl_mutex);
141 list_for_each(pos, &ioctl_list) { 142 list_for_each(pos, &ioctl_list) {
142 struct atm_ioctl * ic = list_entry(pos, struct atm_ioctl, list); 143 struct atm_ioctl * ic = list_entry(pos, struct atm_ioctl, list);
143 if (try_module_get(ic->owner)) { 144 if (try_module_get(ic->owner)) {
@@ -147,7 +148,7 @@ int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
147 break; 148 break;
148 } 149 }
149 } 150 }
150 up(&ioctl_mutex); 151 mutex_unlock(&ioctl_mutex);
151 152
152 if (error != -ENOIOCTLCMD) 153 if (error != -ENOIOCTLCMD)
153 goto done; 154 goto done;
diff --git a/net/atm/resources.c b/net/atm/resources.c
index 224190537c90..18ac80698f83 100644
--- a/net/atm/resources.c
+++ b/net/atm/resources.c
@@ -18,6 +18,8 @@
18#include <linux/bitops.h> 18#include <linux/bitops.h>
19#include <linux/capability.h> 19#include <linux/capability.h>
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/mutex.h>
22
21#include <net/sock.h> /* for struct sock */ 23#include <net/sock.h> /* for struct sock */
22 24
23#include "common.h" 25#include "common.h"
@@ -26,7 +28,7 @@
26 28
27 29
28LIST_HEAD(atm_devs); 30LIST_HEAD(atm_devs);
29DECLARE_MUTEX(atm_dev_mutex); 31DEFINE_MUTEX(atm_dev_mutex);
30 32
31static struct atm_dev *__alloc_atm_dev(const char *type) 33static struct atm_dev *__alloc_atm_dev(const char *type)
32{ 34{
@@ -65,9 +67,9 @@ struct atm_dev *atm_dev_lookup(int number)
65{ 67{
66 struct atm_dev *dev; 68 struct atm_dev *dev;
67 69
68 down(&atm_dev_mutex); 70 mutex_lock(&atm_dev_mutex);
69 dev = __atm_dev_lookup(number); 71 dev = __atm_dev_lookup(number);
70 up(&atm_dev_mutex); 72 mutex_unlock(&atm_dev_mutex);
71 return dev; 73 return dev;
72} 74}
73 75
@@ -83,11 +85,11 @@ struct atm_dev *atm_dev_register(const char *type, const struct atmdev_ops *ops,
83 type); 85 type);
84 return NULL; 86 return NULL;
85 } 87 }
86 down(&atm_dev_mutex); 88 mutex_lock(&atm_dev_mutex);
87 if (number != -1) { 89 if (number != -1) {
88 if ((inuse = __atm_dev_lookup(number))) { 90 if ((inuse = __atm_dev_lookup(number))) {
89 atm_dev_put(inuse); 91 atm_dev_put(inuse);
90 up(&atm_dev_mutex); 92 mutex_unlock(&atm_dev_mutex);
91 kfree(dev); 93 kfree(dev);
92 return NULL; 94 return NULL;
93 } 95 }
@@ -112,12 +114,12 @@ struct atm_dev *atm_dev_register(const char *type, const struct atmdev_ops *ops,
112 printk(KERN_ERR "atm_dev_register: " 114 printk(KERN_ERR "atm_dev_register: "
113 "atm_proc_dev_register failed for dev %s\n", 115 "atm_proc_dev_register failed for dev %s\n",
114 type); 116 type);
115 up(&atm_dev_mutex); 117 mutex_unlock(&atm_dev_mutex);
116 kfree(dev); 118 kfree(dev);
117 return NULL; 119 return NULL;
118 } 120 }
119 list_add_tail(&dev->dev_list, &atm_devs); 121 list_add_tail(&dev->dev_list, &atm_devs);
120 up(&atm_dev_mutex); 122 mutex_unlock(&atm_dev_mutex);
121 123
122 return dev; 124 return dev;
123} 125}
@@ -133,9 +135,9 @@ void atm_dev_deregister(struct atm_dev *dev)
133 * with same number can appear, such we need deregister proc, 135 * with same number can appear, such we need deregister proc,
134 * release async all vccs and remove them from vccs list too 136 * release async all vccs and remove them from vccs list too
135 */ 137 */
136 down(&atm_dev_mutex); 138 mutex_lock(&atm_dev_mutex);
137 list_del(&dev->dev_list); 139 list_del(&dev->dev_list);
138 up(&atm_dev_mutex); 140 mutex_unlock(&atm_dev_mutex);
139 141
140 atm_dev_release_vccs(dev); 142 atm_dev_release_vccs(dev);
141 atm_proc_dev_deregister(dev); 143 atm_proc_dev_deregister(dev);
@@ -196,16 +198,16 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg)
196 return -EFAULT; 198 return -EFAULT;
197 if (get_user(len, &iobuf->length)) 199 if (get_user(len, &iobuf->length))
198 return -EFAULT; 200 return -EFAULT;
199 down(&atm_dev_mutex); 201 mutex_lock(&atm_dev_mutex);
200 list_for_each(p, &atm_devs) 202 list_for_each(p, &atm_devs)
201 size += sizeof(int); 203 size += sizeof(int);
202 if (size > len) { 204 if (size > len) {
203 up(&atm_dev_mutex); 205 mutex_unlock(&atm_dev_mutex);
204 return -E2BIG; 206 return -E2BIG;
205 } 207 }
206 tmp_buf = kmalloc(size, GFP_ATOMIC); 208 tmp_buf = kmalloc(size, GFP_ATOMIC);
207 if (!tmp_buf) { 209 if (!tmp_buf) {
208 up(&atm_dev_mutex); 210 mutex_unlock(&atm_dev_mutex);
209 return -ENOMEM; 211 return -ENOMEM;
210 } 212 }
211 tmp_p = tmp_buf; 213 tmp_p = tmp_buf;
@@ -213,7 +215,7 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg)
213 dev = list_entry(p, struct atm_dev, dev_list); 215 dev = list_entry(p, struct atm_dev, dev_list);
214 *tmp_p++ = dev->number; 216 *tmp_p++ = dev->number;
215 } 217 }
216 up(&atm_dev_mutex); 218 mutex_unlock(&atm_dev_mutex);
217 error = ((copy_to_user(buf, tmp_buf, size)) || 219 error = ((copy_to_user(buf, tmp_buf, size)) ||
218 put_user(size, &iobuf->length)) 220 put_user(size, &iobuf->length))
219 ? -EFAULT : 0; 221 ? -EFAULT : 0;
@@ -400,13 +402,13 @@ static __inline__ void *dev_get_idx(loff_t left)
400 402
401void *atm_dev_seq_start(struct seq_file *seq, loff_t *pos) 403void *atm_dev_seq_start(struct seq_file *seq, loff_t *pos)
402{ 404{
403 down(&atm_dev_mutex); 405 mutex_lock(&atm_dev_mutex);
404 return *pos ? dev_get_idx(*pos) : (void *) 1; 406 return *pos ? dev_get_idx(*pos) : (void *) 1;
405} 407}
406 408
407void atm_dev_seq_stop(struct seq_file *seq, void *v) 409void atm_dev_seq_stop(struct seq_file *seq, void *v)
408{ 410{
409 up(&atm_dev_mutex); 411 mutex_unlock(&atm_dev_mutex);
410} 412}
411 413
412void *atm_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) 414void *atm_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
diff --git a/net/atm/resources.h b/net/atm/resources.h
index b7fb82a93b42..ac7222fee7a8 100644
--- a/net/atm/resources.h
+++ b/net/atm/resources.h
@@ -8,10 +8,11 @@
8 8
9#include <linux/config.h> 9#include <linux/config.h>
10#include <linux/atmdev.h> 10#include <linux/atmdev.h>
11#include <linux/mutex.h>
11 12
12 13
13extern struct list_head atm_devs; 14extern struct list_head atm_devs;
14extern struct semaphore atm_dev_mutex; 15extern struct mutex atm_dev_mutex;
15 16
16int atm_dev_ioctl(unsigned int cmd, void __user *arg); 17int atm_dev_ioctl(unsigned int cmd, void __user *arg);
17 18
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index 5b4253c61f62..e99010ce8bb2 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -37,6 +37,8 @@
37#include <linux/wait.h> 37#include <linux/wait.h>
38#include <linux/device.h> 38#include <linux/device.h>
39#include <linux/net.h> 39#include <linux/net.h>
40#include <linux/mutex.h>
41
40#include <net/sock.h> 42#include <net/sock.h>
41#include <asm/uaccess.h> 43#include <asm/uaccess.h>
42#include <asm/unaligned.h> 44#include <asm/unaligned.h>
@@ -57,9 +59,9 @@ static unsigned int l2cap_mtu = RFCOMM_MAX_L2CAP_MTU;
57 59
58static struct task_struct *rfcomm_thread; 60static struct task_struct *rfcomm_thread;
59 61
60static DECLARE_MUTEX(rfcomm_sem); 62static DEFINE_MUTEX(rfcomm_mutex);
61#define rfcomm_lock() down(&rfcomm_sem); 63#define rfcomm_lock() mutex_lock(&rfcomm_mutex)
62#define rfcomm_unlock() up(&rfcomm_sem); 64#define rfcomm_unlock() mutex_unlock(&rfcomm_mutex)
63 65
64static unsigned long rfcomm_event; 66static unsigned long rfcomm_event;
65 67
diff --git a/net/bridge/Kconfig b/net/bridge/Kconfig
index db23d59746cf..12265aff7099 100644
--- a/net/bridge/Kconfig
+++ b/net/bridge/Kconfig
@@ -4,6 +4,7 @@
4 4
5config BRIDGE 5config BRIDGE
6 tristate "802.1d Ethernet Bridging" 6 tristate "802.1d Ethernet Bridging"
7 select LLC
7 ---help--- 8 ---help---
8 If you say Y here, then your Linux box will be able to act as an 9 If you say Y here, then your Linux box will be able to act as an
9 Ethernet bridge, which means that the different Ethernet segments it 10 Ethernet bridge, which means that the different Ethernet segments it
diff --git a/net/bridge/br.c b/net/bridge/br.c
index 188cc1ac49eb..22d806cf40ca 100644
--- a/net/bridge/br.c
+++ b/net/bridge/br.c
@@ -19,13 +19,23 @@
19#include <linux/netdevice.h> 19#include <linux/netdevice.h>
20#include <linux/etherdevice.h> 20#include <linux/etherdevice.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/llc.h>
23#include <net/llc.h>
22 24
23#include "br_private.h" 25#include "br_private.h"
24 26
25int (*br_should_route_hook) (struct sk_buff **pskb) = NULL; 27int (*br_should_route_hook) (struct sk_buff **pskb) = NULL;
26 28
29static struct llc_sap *br_stp_sap;
30
27static int __init br_init(void) 31static int __init br_init(void)
28{ 32{
33 br_stp_sap = llc_sap_open(LLC_SAP_BSPAN, br_stp_rcv);
34 if (!br_stp_sap) {
35 printk(KERN_ERR "bridge: can't register sap for STP\n");
36 return -EBUSY;
37 }
38
29 br_fdb_init(); 39 br_fdb_init();
30 40
31#ifdef CONFIG_BRIDGE_NETFILTER 41#ifdef CONFIG_BRIDGE_NETFILTER
@@ -45,6 +55,8 @@ static int __init br_init(void)
45 55
46static void __exit br_deinit(void) 56static void __exit br_deinit(void)
47{ 57{
58 llc_sap_close(br_stp_sap);
59
48#ifdef CONFIG_BRIDGE_NETFILTER 60#ifdef CONFIG_BRIDGE_NETFILTER
49 br_netfilter_fini(); 61 br_netfilter_fini();
50#endif 62#endif
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index 0b33a7b3a00c..0c88a2ac32c1 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -27,6 +27,7 @@ static struct net_device_stats *br_dev_get_stats(struct net_device *dev)
27 return &br->statistics; 27 return &br->statistics;
28} 28}
29 29
30/* net device transmit always called with no BH (preempt_disabled) */
30int br_dev_xmit(struct sk_buff *skb, struct net_device *dev) 31int br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
31{ 32{
32 struct net_bridge *br = netdev_priv(dev); 33 struct net_bridge *br = netdev_priv(dev);
@@ -39,7 +40,6 @@ int br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
39 skb->mac.raw = skb->data; 40 skb->mac.raw = skb->data;
40 skb_pull(skb, ETH_HLEN); 41 skb_pull(skb, ETH_HLEN);
41 42
42 rcu_read_lock();
43 if (dest[0] & 1) 43 if (dest[0] & 1)
44 br_flood_deliver(br, skb, 0); 44 br_flood_deliver(br, skb, 0);
45 else if ((dst = __br_fdb_get(br, dest)) != NULL) 45 else if ((dst = __br_fdb_get(br, dest)) != NULL)
@@ -47,7 +47,6 @@ int br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
47 else 47 else
48 br_flood_deliver(br, skb, 0); 48 br_flood_deliver(br, skb, 0);
49 49
50 rcu_read_unlock();
51 return 0; 50 return 0;
52} 51}
53 52
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index 1f08a59b51ea..3a73b8c94271 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -341,7 +341,6 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
341 if (hold_time(br) == 0) 341 if (hold_time(br) == 0)
342 return; 342 return;
343 343
344 rcu_read_lock();
345 fdb = fdb_find(head, addr); 344 fdb = fdb_find(head, addr);
346 if (likely(fdb)) { 345 if (likely(fdb)) {
347 /* attempt to update an entry for a local interface */ 346 /* attempt to update an entry for a local interface */
@@ -356,13 +355,12 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
356 fdb->ageing_timer = jiffies; 355 fdb->ageing_timer = jiffies;
357 } 356 }
358 } else { 357 } else {
359 spin_lock_bh(&br->hash_lock); 358 spin_lock(&br->hash_lock);
360 if (!fdb_find(head, addr)) 359 if (!fdb_find(head, addr))
361 fdb_create(head, source, addr, 0); 360 fdb_create(head, source, addr, 0);
362 /* else we lose race and someone else inserts 361 /* else we lose race and someone else inserts
363 * it first, don't bother updating 362 * it first, don't bother updating
364 */ 363 */
365 spin_unlock_bh(&br->hash_lock); 364 spin_unlock(&br->hash_lock);
366 } 365 }
367 rcu_read_unlock();
368} 366}
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index f36b35edd60c..59eef42d4a42 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -210,7 +210,8 @@ static struct net_device *new_bridge_dev(const char *name)
210 210
211 br->bridge_id.prio[0] = 0x80; 211 br->bridge_id.prio[0] = 0x80;
212 br->bridge_id.prio[1] = 0x00; 212 br->bridge_id.prio[1] = 0x00;
213 memset(br->bridge_id.addr, 0, ETH_ALEN); 213
214 memcpy(br->group_addr, br_group_address, ETH_ALEN);
214 215
215 br->feature_mask = dev->features; 216 br->feature_mask = dev->features;
216 br->stp_enabled = 0; 217 br->stp_enabled = 0;
@@ -237,12 +238,11 @@ static int find_portno(struct net_bridge *br)
237 struct net_bridge_port *p; 238 struct net_bridge_port *p;
238 unsigned long *inuse; 239 unsigned long *inuse;
239 240
240 inuse = kmalloc(BITS_TO_LONGS(BR_MAX_PORTS)*sizeof(unsigned long), 241 inuse = kcalloc(BITS_TO_LONGS(BR_MAX_PORTS), sizeof(unsigned long),
241 GFP_KERNEL); 242 GFP_KERNEL);
242 if (!inuse) 243 if (!inuse)
243 return -ENOMEM; 244 return -ENOMEM;
244 245
245 memset(inuse, 0, BITS_TO_LONGS(BR_MAX_PORTS)*sizeof(unsigned long));
246 set_bit(0, inuse); /* zero is reserved */ 246 set_bit(0, inuse); /* zero is reserved */
247 list_for_each_entry(p, &br->port_list, list) { 247 list_for_each_entry(p, &br->port_list, list) {
248 set_bit(p->port_no, inuse); 248 set_bit(p->port_no, inuse);
@@ -264,11 +264,10 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br,
264 if (index < 0) 264 if (index < 0)
265 return ERR_PTR(index); 265 return ERR_PTR(index);
266 266
267 p = kmalloc(sizeof(*p), GFP_KERNEL); 267 p = kzalloc(sizeof(*p), GFP_KERNEL);
268 if (p == NULL) 268 if (p == NULL)
269 return ERR_PTR(-ENOMEM); 269 return ERR_PTR(-ENOMEM);
270 270
271 memset(p, 0, sizeof(*p));
272 p->br = br; 271 p->br = br;
273 dev_hold(dev); 272 dev_hold(dev);
274 p->dev = dev; 273 p->dev = dev;
diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c
index 4eef83755315..b7766562d72c 100644
--- a/net/bridge/br_input.c
+++ b/net/bridge/br_input.c
@@ -19,13 +19,8 @@
19#include <linux/netfilter_bridge.h> 19#include <linux/netfilter_bridge.h>
20#include "br_private.h" 20#include "br_private.h"
21 21
22const unsigned char bridge_ula[6] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 }; 22/* Bridge group multicast address 802.1d (pg 51). */
23 23const u8 br_group_address[ETH_ALEN] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
24static int br_pass_frame_up_finish(struct sk_buff *skb)
25{
26 netif_receive_skb(skb);
27 return 0;
28}
29 24
30static void br_pass_frame_up(struct net_bridge *br, struct sk_buff *skb) 25static void br_pass_frame_up(struct net_bridge *br, struct sk_buff *skb)
31{ 26{
@@ -38,7 +33,7 @@ static void br_pass_frame_up(struct net_bridge *br, struct sk_buff *skb)
38 skb->dev = br->dev; 33 skb->dev = br->dev;
39 34
40 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL, 35 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
41 br_pass_frame_up_finish); 36 netif_receive_skb);
42} 37}
43 38
44/* note: already called with rcu_read_lock (preempt_disabled) */ 39/* note: already called with rcu_read_lock (preempt_disabled) */
@@ -100,6 +95,25 @@ drop:
100 goto out; 95 goto out;
101} 96}
102 97
98/* note: already called with rcu_read_lock (preempt_disabled) */
99static int br_handle_local_finish(struct sk_buff *skb)
100{
101 struct net_bridge_port *p = rcu_dereference(skb->dev->br_port);
102
103 if (p && p->state != BR_STATE_DISABLED)
104 br_fdb_update(p->br, p, eth_hdr(skb)->h_source);
105
106 return 0; /* process further */
107}
108
109/* Does address match the link local multicast address.
110 * 01:80:c2:00:00:0X
111 */
112static inline int is_link_local(const unsigned char *dest)
113{
114 return memcmp(dest, br_group_address, 5) == 0 && (dest[5] & 0xf0) == 0;
115}
116
103/* 117/*
104 * Called via br_handle_frame_hook. 118 * Called via br_handle_frame_hook.
105 * Return 0 if *pskb should be processed furthur 119 * Return 0 if *pskb should be processed furthur
@@ -117,15 +131,10 @@ int br_handle_frame(struct net_bridge_port *p, struct sk_buff **pskb)
117 if (!is_valid_ether_addr(eth_hdr(skb)->h_source)) 131 if (!is_valid_ether_addr(eth_hdr(skb)->h_source))
118 goto err; 132 goto err;
119 133
120 if (p->br->stp_enabled && 134 if (unlikely(is_link_local(dest))) {
121 !memcmp(dest, bridge_ula, 5) && 135 skb->pkt_type = PACKET_HOST;
122 !(dest[5] & 0xF0)) { 136 return NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,
123 if (!dest[5]) { 137 NULL, br_handle_local_finish) != 0;
124 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,
125 NULL, br_stp_handle_bpdu);
126 return 1;
127 }
128 goto err;
129 } 138 }
130 139
131 if (p->state == BR_STATE_FORWARDING || p->state == BR_STATE_LEARNING) { 140 if (p->state == BR_STATE_FORWARDING || p->state == BR_STATE_LEARNING) {
diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
index e060aad8624d..f29450b788be 100644
--- a/net/bridge/br_netfilter.c
+++ b/net/bridge/br_netfilter.c
@@ -61,15 +61,25 @@ static int brnf_filter_vlan_tagged = 1;
61#define brnf_filter_vlan_tagged 1 61#define brnf_filter_vlan_tagged 1
62#endif 62#endif
63 63
64#define IS_VLAN_IP (skb->protocol == __constant_htons(ETH_P_8021Q) && \ 64static __be16 inline vlan_proto(const struct sk_buff *skb)
65 hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IP) && \ 65{
66 brnf_filter_vlan_tagged) 66 return vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
67#define IS_VLAN_IPV6 (skb->protocol == __constant_htons(ETH_P_8021Q) && \ 67}
68 hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IPV6) && \ 68
69 brnf_filter_vlan_tagged) 69#define IS_VLAN_IP(skb) \
70#define IS_VLAN_ARP (skb->protocol == __constant_htons(ETH_P_8021Q) && \ 70 (skb->protocol == htons(ETH_P_8021Q) && \
71 hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_ARP) && \ 71 vlan_proto(skb) == htons(ETH_P_IP) && \
72 brnf_filter_vlan_tagged) 72 brnf_filter_vlan_tagged)
73
74#define IS_VLAN_IPV6(skb) \
75 (skb->protocol == htons(ETH_P_8021Q) && \
76 vlan_proto(skb) == htons(ETH_P_IPV6) &&\
77 brnf_filter_vlan_tagged)
78
79#define IS_VLAN_ARP(skb) \
80 (skb->protocol == htons(ETH_P_8021Q) && \
81 vlan_proto(skb) == htons(ETH_P_ARP) && \
82 brnf_filter_vlan_tagged)
73 83
74/* We need these fake structures to make netfilter happy -- 84/* We need these fake structures to make netfilter happy --
75 * lots of places assume that skb->dst != NULL, which isn't 85 * lots of places assume that skb->dst != NULL, which isn't
@@ -103,6 +113,25 @@ static inline struct net_device *bridge_parent(const struct net_device *dev)
103 return port ? port->br->dev : NULL; 113 return port ? port->br->dev : NULL;
104} 114}
105 115
116static inline struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
117{
118 skb->nf_bridge = kzalloc(sizeof(struct nf_bridge_info), GFP_ATOMIC);
119 if (likely(skb->nf_bridge))
120 atomic_set(&(skb->nf_bridge->use), 1);
121
122 return skb->nf_bridge;
123}
124
125static inline void nf_bridge_save_header(struct sk_buff *skb)
126{
127 int header_size = 16;
128
129 if (skb->protocol == htons(ETH_P_8021Q))
130 header_size = 18;
131
132 memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
133}
134
106/* PF_BRIDGE/PRE_ROUTING *********************************************/ 135/* PF_BRIDGE/PRE_ROUTING *********************************************/
107/* Undo the changes made for ip6tables PREROUTING and continue the 136/* Undo the changes made for ip6tables PREROUTING and continue the
108 * bridge PRE_ROUTING hook. */ 137 * bridge PRE_ROUTING hook. */
@@ -120,7 +149,7 @@ static int br_nf_pre_routing_finish_ipv6(struct sk_buff *skb)
120 dst_hold(skb->dst); 149 dst_hold(skb->dst);
121 150
122 skb->dev = nf_bridge->physindev; 151 skb->dev = nf_bridge->physindev;
123 if (skb->protocol == __constant_htons(ETH_P_8021Q)) { 152 if (skb->protocol == htons(ETH_P_8021Q)) {
124 skb_push(skb, VLAN_HLEN); 153 skb_push(skb, VLAN_HLEN);
125 skb->nh.raw -= VLAN_HLEN; 154 skb->nh.raw -= VLAN_HLEN;
126 } 155 }
@@ -136,7 +165,7 @@ static void __br_dnat_complain(void)
136 165
137 if (jiffies - last_complaint >= 5 * HZ) { 166 if (jiffies - last_complaint >= 5 * HZ) {
138 printk(KERN_WARNING "Performing cross-bridge DNAT requires IP " 167 printk(KERN_WARNING "Performing cross-bridge DNAT requires IP "
139 "forwarding to be enabled\n"); 168 "forwarding to be enabled\n");
140 last_complaint = jiffies; 169 last_complaint = jiffies;
141 } 170 }
142} 171}
@@ -196,7 +225,7 @@ static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
196 if (!skb->dev) 225 if (!skb->dev)
197 kfree_skb(skb); 226 kfree_skb(skb);
198 else { 227 else {
199 if (skb->protocol == __constant_htons(ETH_P_8021Q)) { 228 if (skb->protocol == htons(ETH_P_8021Q)) {
200 skb_pull(skb, VLAN_HLEN); 229 skb_pull(skb, VLAN_HLEN);
201 skb->nh.raw += VLAN_HLEN; 230 skb->nh.raw += VLAN_HLEN;
202 } 231 }
@@ -218,12 +247,17 @@ static int br_nf_pre_routing_finish(struct sk_buff *skb)
218 nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING; 247 nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
219 248
220 if (dnat_took_place(skb)) { 249 if (dnat_took_place(skb)) {
221 if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, 250 if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev)) {
222 dev)) {
223 struct rtable *rt; 251 struct rtable *rt;
224 struct flowi fl = { .nl_u = 252 struct flowi fl = {
225 { .ip4_u = { .daddr = iph->daddr, .saddr = 0 , 253 .nl_u = {
226 .tos = RT_TOS(iph->tos)} }, .proto = 0}; 254 .ip4_u = {
255 .daddr = iph->daddr,
256 .saddr = 0,
257 .tos = RT_TOS(iph->tos) },
258 },
259 .proto = 0,
260 };
227 261
228 if (!ip_route_output_key(&rt, &fl)) { 262 if (!ip_route_output_key(&rt, &fl)) {
229 /* - Bridged-and-DNAT'ed traffic doesn't 263 /* - Bridged-and-DNAT'ed traffic doesn't
@@ -247,7 +281,7 @@ bridged_dnat:
247 nf_bridge->mask |= BRNF_BRIDGED_DNAT; 281 nf_bridge->mask |= BRNF_BRIDGED_DNAT;
248 skb->dev = nf_bridge->physindev; 282 skb->dev = nf_bridge->physindev;
249 if (skb->protocol == 283 if (skb->protocol ==
250 __constant_htons(ETH_P_8021Q)) { 284 htons(ETH_P_8021Q)) {
251 skb_push(skb, VLAN_HLEN); 285 skb_push(skb, VLAN_HLEN);
252 skb->nh.raw -= VLAN_HLEN; 286 skb->nh.raw -= VLAN_HLEN;
253 } 287 }
@@ -257,8 +291,7 @@ bridged_dnat:
257 1); 291 1);
258 return 0; 292 return 0;
259 } 293 }
260 memcpy(eth_hdr(skb)->h_dest, dev->dev_addr, 294 memcpy(eth_hdr(skb)->h_dest, dev->dev_addr, ETH_ALEN);
261 ETH_ALEN);
262 skb->pkt_type = PACKET_HOST; 295 skb->pkt_type = PACKET_HOST;
263 } 296 }
264 } else { 297 } else {
@@ -267,7 +300,7 @@ bridged_dnat:
267 } 300 }
268 301
269 skb->dev = nf_bridge->physindev; 302 skb->dev = nf_bridge->physindev;
270 if (skb->protocol == __constant_htons(ETH_P_8021Q)) { 303 if (skb->protocol == htons(ETH_P_8021Q)) {
271 skb_push(skb, VLAN_HLEN); 304 skb_push(skb, VLAN_HLEN);
272 skb->nh.raw -= VLAN_HLEN; 305 skb->nh.raw -= VLAN_HLEN;
273 } 306 }
@@ -297,10 +330,10 @@ static struct net_device *setup_pre_routing(struct sk_buff *skb)
297/* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */ 330/* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */
298static int check_hbh_len(struct sk_buff *skb) 331static int check_hbh_len(struct sk_buff *skb)
299{ 332{
300 unsigned char *raw = (u8*)(skb->nh.ipv6h+1); 333 unsigned char *raw = (u8 *) (skb->nh.ipv6h + 1);
301 u32 pkt_len; 334 u32 pkt_len;
302 int off = raw - skb->nh.raw; 335 int off = raw - skb->nh.raw;
303 int len = (raw[1]+1)<<3; 336 int len = (raw[1] + 1) << 3;
304 337
305 if ((raw + len) - skb->data > skb_headlen(skb)) 338 if ((raw + len) - skb->data > skb_headlen(skb))
306 goto bad; 339 goto bad;
@@ -309,7 +342,7 @@ static int check_hbh_len(struct sk_buff *skb)
309 len -= 2; 342 len -= 2;
310 343
311 while (len > 0) { 344 while (len > 0) {
312 int optlen = skb->nh.raw[off+1]+2; 345 int optlen = skb->nh.raw[off + 1] + 2;
313 346
314 switch (skb->nh.raw[off]) { 347 switch (skb->nh.raw[off]) {
315 case IPV6_TLV_PAD0: 348 case IPV6_TLV_PAD0:
@@ -320,16 +353,16 @@ static int check_hbh_len(struct sk_buff *skb)
320 break; 353 break;
321 354
322 case IPV6_TLV_JUMBO: 355 case IPV6_TLV_JUMBO:
323 if (skb->nh.raw[off+1] != 4 || (off&3) != 2) 356 if (skb->nh.raw[off + 1] != 4 || (off & 3) != 2)
324 goto bad; 357 goto bad;
325 pkt_len = ntohl(*(u32*)(skb->nh.raw+off+2)); 358 pkt_len = ntohl(*(u32 *) (skb->nh.raw + off + 2));
326 if (pkt_len <= IPV6_MAXPLEN || 359 if (pkt_len <= IPV6_MAXPLEN ||
327 skb->nh.ipv6h->payload_len) 360 skb->nh.ipv6h->payload_len)
328 goto bad; 361 goto bad;
329 if (pkt_len > skb->len - sizeof(struct ipv6hdr)) 362 if (pkt_len > skb->len - sizeof(struct ipv6hdr))
330 goto bad; 363 goto bad;
331 if (pskb_trim_rcsum(skb, 364 if (pskb_trim_rcsum(skb,
332 pkt_len+sizeof(struct ipv6hdr))) 365 pkt_len + sizeof(struct ipv6hdr)))
333 goto bad; 366 goto bad;
334 break; 367 break;
335 default: 368 default:
@@ -350,12 +383,13 @@ bad:
350/* Replicate the checks that IPv6 does on packet reception and pass the packet 383/* Replicate the checks that IPv6 does on packet reception and pass the packet
351 * to ip6tables, which doesn't support NAT, so things are fairly simple. */ 384 * to ip6tables, which doesn't support NAT, so things are fairly simple. */
352static unsigned int br_nf_pre_routing_ipv6(unsigned int hook, 385static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,
353 struct sk_buff *skb, const struct net_device *in, 386 struct sk_buff *skb,
354 const struct net_device *out, int (*okfn)(struct sk_buff *)) 387 const struct net_device *in,
388 const struct net_device *out,
389 int (*okfn)(struct sk_buff *))
355{ 390{
356 struct ipv6hdr *hdr; 391 struct ipv6hdr *hdr;
357 u32 pkt_len; 392 u32 pkt_len;
358 struct nf_bridge_info *nf_bridge;
359 393
360 if (skb->len < sizeof(struct ipv6hdr)) 394 if (skb->len < sizeof(struct ipv6hdr))
361 goto inhdr_error; 395 goto inhdr_error;
@@ -381,10 +415,10 @@ static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,
381 } 415 }
382 } 416 }
383 if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb)) 417 if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb))
384 goto inhdr_error; 418 goto inhdr_error;
385 419
386 nf_bridge_put(skb->nf_bridge); 420 nf_bridge_put(skb->nf_bridge);
387 if ((nf_bridge = nf_bridge_alloc(skb)) == NULL) 421 if (!nf_bridge_alloc(skb))
388 return NF_DROP; 422 return NF_DROP;
389 if (!setup_pre_routing(skb)) 423 if (!setup_pre_routing(skb))
390 return NF_DROP; 424 return NF_DROP;
@@ -412,10 +446,8 @@ static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
412 struct iphdr *iph; 446 struct iphdr *iph;
413 __u32 len; 447 __u32 len;
414 struct sk_buff *skb = *pskb; 448 struct sk_buff *skb = *pskb;
415 struct nf_bridge_info *nf_bridge;
416 struct vlan_ethhdr *hdr = vlan_eth_hdr(*pskb);
417 449
418 if (skb->protocol == __constant_htons(ETH_P_IPV6) || IS_VLAN_IPV6) { 450 if (skb->protocol == htons(ETH_P_IPV6) || IS_VLAN_IPV6(skb)) {
419#ifdef CONFIG_SYSCTL 451#ifdef CONFIG_SYSCTL
420 if (!brnf_call_ip6tables) 452 if (!brnf_call_ip6tables)
421 return NF_ACCEPT; 453 return NF_ACCEPT;
@@ -423,10 +455,8 @@ static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
423 if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL) 455 if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
424 goto out; 456 goto out;
425 457
426 if (skb->protocol == __constant_htons(ETH_P_8021Q)) { 458 if (skb->protocol == htons(ETH_P_8021Q)) {
427 u8 *vhdr = skb->data; 459 skb_pull_rcsum(skb, VLAN_HLEN);
428 skb_pull(skb, VLAN_HLEN);
429 skb_postpull_rcsum(skb, vhdr, VLAN_HLEN);
430 skb->nh.raw += VLAN_HLEN; 460 skb->nh.raw += VLAN_HLEN;
431 } 461 }
432 return br_nf_pre_routing_ipv6(hook, skb, in, out, okfn); 462 return br_nf_pre_routing_ipv6(hook, skb, in, out, okfn);
@@ -436,16 +466,14 @@ static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
436 return NF_ACCEPT; 466 return NF_ACCEPT;
437#endif 467#endif
438 468
439 if (skb->protocol != __constant_htons(ETH_P_IP) && !IS_VLAN_IP) 469 if (skb->protocol != htons(ETH_P_IP) && !IS_VLAN_IP(skb))
440 return NF_ACCEPT; 470 return NF_ACCEPT;
441 471
442 if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL) 472 if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
443 goto out; 473 goto out;
444 474
445 if (skb->protocol == __constant_htons(ETH_P_8021Q)) { 475 if (skb->protocol == htons(ETH_P_8021Q)) {
446 u8 *vhdr = skb->data; 476 skb_pull_rcsum(skb, VLAN_HLEN);
447 skb_pull(skb, VLAN_HLEN);
448 skb_postpull_rcsum(skb, vhdr, VLAN_HLEN);
449 skb->nh.raw += VLAN_HLEN; 477 skb->nh.raw += VLAN_HLEN;
450 } 478 }
451 479
@@ -456,15 +484,15 @@ static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
456 if (iph->ihl < 5 || iph->version != 4) 484 if (iph->ihl < 5 || iph->version != 4)
457 goto inhdr_error; 485 goto inhdr_error;
458 486
459 if (!pskb_may_pull(skb, 4*iph->ihl)) 487 if (!pskb_may_pull(skb, 4 * iph->ihl))
460 goto inhdr_error; 488 goto inhdr_error;
461 489
462 iph = skb->nh.iph; 490 iph = skb->nh.iph;
463 if (ip_fast_csum((__u8 *)iph, iph->ihl) != 0) 491 if (ip_fast_csum((__u8 *) iph, iph->ihl) != 0)
464 goto inhdr_error; 492 goto inhdr_error;
465 493
466 len = ntohs(iph->tot_len); 494 len = ntohs(iph->tot_len);
467 if (skb->len < len || len < 4*iph->ihl) 495 if (skb->len < len || len < 4 * iph->ihl)
468 goto inhdr_error; 496 goto inhdr_error;
469 497
470 if (skb->len > len) { 498 if (skb->len > len) {
@@ -473,8 +501,8 @@ static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
473 skb->ip_summed = CHECKSUM_NONE; 501 skb->ip_summed = CHECKSUM_NONE;
474 } 502 }
475 503
476 nf_bridge_put(skb->nf_bridge); 504 nf_bridge_put(skb->nf_bridge);
477 if ((nf_bridge = nf_bridge_alloc(skb)) == NULL) 505 if (!nf_bridge_alloc(skb))
478 return NF_DROP; 506 return NF_DROP;
479 if (!setup_pre_routing(skb)) 507 if (!setup_pre_routing(skb))
480 return NF_DROP; 508 return NF_DROP;
@@ -486,7 +514,7 @@ static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
486 return NF_STOLEN; 514 return NF_STOLEN;
487 515
488inhdr_error: 516inhdr_error:
489// IP_INC_STATS_BH(IpInHdrErrors); 517// IP_INC_STATS_BH(IpInHdrErrors);
490out: 518out:
491 return NF_DROP; 519 return NF_DROP;
492} 520}
@@ -500,8 +528,9 @@ out:
500 * register an IPv4 PRE_ROUTING 'sabotage' hook that will 528 * register an IPv4 PRE_ROUTING 'sabotage' hook that will
501 * prevent this from happening. */ 529 * prevent this from happening. */
502static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff **pskb, 530static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff **pskb,
503 const struct net_device *in, const struct net_device *out, 531 const struct net_device *in,
504 int (*okfn)(struct sk_buff *)) 532 const struct net_device *out,
533 int (*okfn)(struct sk_buff *))
505{ 534{
506 struct sk_buff *skb = *pskb; 535 struct sk_buff *skb = *pskb;
507 536
@@ -513,15 +542,13 @@ static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff **pskb,
513 return NF_ACCEPT; 542 return NF_ACCEPT;
514} 543}
515 544
516
517/* PF_BRIDGE/FORWARD *************************************************/ 545/* PF_BRIDGE/FORWARD *************************************************/
518static int br_nf_forward_finish(struct sk_buff *skb) 546static int br_nf_forward_finish(struct sk_buff *skb)
519{ 547{
520 struct nf_bridge_info *nf_bridge = skb->nf_bridge; 548 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
521 struct net_device *in; 549 struct net_device *in;
522 struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
523 550
524 if (skb->protocol != __constant_htons(ETH_P_ARP) && !IS_VLAN_ARP) { 551 if (skb->protocol != htons(ETH_P_ARP) && !IS_VLAN_ARP(skb)) {
525 in = nf_bridge->physindev; 552 in = nf_bridge->physindev;
526 if (nf_bridge->mask & BRNF_PKT_TYPE) { 553 if (nf_bridge->mask & BRNF_PKT_TYPE) {
527 skb->pkt_type = PACKET_OTHERHOST; 554 skb->pkt_type = PACKET_OTHERHOST;
@@ -530,12 +557,12 @@ static int br_nf_forward_finish(struct sk_buff *skb)
530 } else { 557 } else {
531 in = *((struct net_device **)(skb->cb)); 558 in = *((struct net_device **)(skb->cb));
532 } 559 }
533 if (skb->protocol == __constant_htons(ETH_P_8021Q)) { 560 if (skb->protocol == htons(ETH_P_8021Q)) {
534 skb_push(skb, VLAN_HLEN); 561 skb_push(skb, VLAN_HLEN);
535 skb->nh.raw -= VLAN_HLEN; 562 skb->nh.raw -= VLAN_HLEN;
536 } 563 }
537 NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in, 564 NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in,
538 skb->dev, br_forward_finish, 1); 565 skb->dev, br_forward_finish, 1);
539 return 0; 566 return 0;
540} 567}
541 568
@@ -545,12 +572,12 @@ static int br_nf_forward_finish(struct sk_buff *skb)
545 * because of the physdev module. For ARP, indev and outdev are the 572 * because of the physdev module. For ARP, indev and outdev are the
546 * bridge ports. */ 573 * bridge ports. */
547static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb, 574static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
548 const struct net_device *in, const struct net_device *out, 575 const struct net_device *in,
549 int (*okfn)(struct sk_buff *)) 576 const struct net_device *out,
577 int (*okfn)(struct sk_buff *))
550{ 578{
551 struct sk_buff *skb = *pskb; 579 struct sk_buff *skb = *pskb;
552 struct nf_bridge_info *nf_bridge; 580 struct nf_bridge_info *nf_bridge;
553 struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
554 struct net_device *parent; 581 struct net_device *parent;
555 int pf; 582 int pf;
556 583
@@ -561,12 +588,12 @@ static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
561 if (!parent) 588 if (!parent)
562 return NF_DROP; 589 return NF_DROP;
563 590
564 if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP) 591 if (skb->protocol == htons(ETH_P_IP) || IS_VLAN_IP(skb))
565 pf = PF_INET; 592 pf = PF_INET;
566 else 593 else
567 pf = PF_INET6; 594 pf = PF_INET6;
568 595
569 if (skb->protocol == __constant_htons(ETH_P_8021Q)) { 596 if (skb->protocol == htons(ETH_P_8021Q)) {
570 skb_pull(*pskb, VLAN_HLEN); 597 skb_pull(*pskb, VLAN_HLEN);
571 (*pskb)->nh.raw += VLAN_HLEN; 598 (*pskb)->nh.raw += VLAN_HLEN;
572 } 599 }
@@ -588,11 +615,11 @@ static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
588} 615}
589 616
590static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb, 617static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
591 const struct net_device *in, const struct net_device *out, 618 const struct net_device *in,
592 int (*okfn)(struct sk_buff *)) 619 const struct net_device *out,
620 int (*okfn)(struct sk_buff *))
593{ 621{
594 struct sk_buff *skb = *pskb; 622 struct sk_buff *skb = *pskb;
595 struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
596 struct net_device **d = (struct net_device **)(skb->cb); 623 struct net_device **d = (struct net_device **)(skb->cb);
597 624
598#ifdef CONFIG_SYSCTL 625#ifdef CONFIG_SYSCTL
@@ -600,15 +627,15 @@ static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
600 return NF_ACCEPT; 627 return NF_ACCEPT;
601#endif 628#endif
602 629
603 if (skb->protocol != __constant_htons(ETH_P_ARP)) { 630 if (skb->protocol != htons(ETH_P_ARP)) {
604 if (!IS_VLAN_ARP) 631 if (!IS_VLAN_ARP(skb))
605 return NF_ACCEPT; 632 return NF_ACCEPT;
606 skb_pull(*pskb, VLAN_HLEN); 633 skb_pull(*pskb, VLAN_HLEN);
607 (*pskb)->nh.raw += VLAN_HLEN; 634 (*pskb)->nh.raw += VLAN_HLEN;
608 } 635 }
609 636
610 if (skb->nh.arph->ar_pln != 4) { 637 if (skb->nh.arph->ar_pln != 4) {
611 if (IS_VLAN_ARP) { 638 if (IS_VLAN_ARP(skb)) {
612 skb_push(*pskb, VLAN_HLEN); 639 skb_push(*pskb, VLAN_HLEN);
613 (*pskb)->nh.raw -= VLAN_HLEN; 640 (*pskb)->nh.raw -= VLAN_HLEN;
614 } 641 }
@@ -621,17 +648,16 @@ static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
621 return NF_STOLEN; 648 return NF_STOLEN;
622} 649}
623 650
624
625/* PF_BRIDGE/LOCAL_OUT ***********************************************/ 651/* PF_BRIDGE/LOCAL_OUT ***********************************************/
626static int br_nf_local_out_finish(struct sk_buff *skb) 652static int br_nf_local_out_finish(struct sk_buff *skb)
627{ 653{
628 if (skb->protocol == __constant_htons(ETH_P_8021Q)) { 654 if (skb->protocol == htons(ETH_P_8021Q)) {
629 skb_push(skb, VLAN_HLEN); 655 skb_push(skb, VLAN_HLEN);
630 skb->nh.raw -= VLAN_HLEN; 656 skb->nh.raw -= VLAN_HLEN;
631 } 657 }
632 658
633 NF_HOOK_THRESH(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev, 659 NF_HOOK_THRESH(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
634 br_forward_finish, NF_BR_PRI_FIRST + 1); 660 br_forward_finish, NF_BR_PRI_FIRST + 1);
635 661
636 return 0; 662 return 0;
637} 663}
@@ -657,19 +683,19 @@ static int br_nf_local_out_finish(struct sk_buff *skb)
657 * even routed packets that didn't arrive on a bridge interface have their 683 * even routed packets that didn't arrive on a bridge interface have their
658 * nf_bridge->physindev set. */ 684 * nf_bridge->physindev set. */
659static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb, 685static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb,
660 const struct net_device *in, const struct net_device *out, 686 const struct net_device *in,
661 int (*okfn)(struct sk_buff *)) 687 const struct net_device *out,
688 int (*okfn)(struct sk_buff *))
662{ 689{
663 struct net_device *realindev, *realoutdev; 690 struct net_device *realindev, *realoutdev;
664 struct sk_buff *skb = *pskb; 691 struct sk_buff *skb = *pskb;
665 struct nf_bridge_info *nf_bridge; 692 struct nf_bridge_info *nf_bridge;
666 struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
667 int pf; 693 int pf;
668 694
669 if (!skb->nf_bridge) 695 if (!skb->nf_bridge)
670 return NF_ACCEPT; 696 return NF_ACCEPT;
671 697
672 if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP) 698 if (skb->protocol == htons(ETH_P_IP) || IS_VLAN_IP(skb))
673 pf = PF_INET; 699 pf = PF_INET;
674 else 700 else
675 pf = PF_INET6; 701 pf = PF_INET6;
@@ -695,7 +721,7 @@ static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb,
695 skb->pkt_type = PACKET_OTHERHOST; 721 skb->pkt_type = PACKET_OTHERHOST;
696 nf_bridge->mask ^= BRNF_PKT_TYPE; 722 nf_bridge->mask ^= BRNF_PKT_TYPE;
697 } 723 }
698 if (skb->protocol == __constant_htons(ETH_P_8021Q)) { 724 if (skb->protocol == htons(ETH_P_8021Q)) {
699 skb_push(skb, VLAN_HLEN); 725 skb_push(skb, VLAN_HLEN);
700 skb->nh.raw -= VLAN_HLEN; 726 skb->nh.raw -= VLAN_HLEN;
701 } 727 }
@@ -713,14 +739,14 @@ static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb,
713 if (nf_bridge->netoutdev) 739 if (nf_bridge->netoutdev)
714 realoutdev = nf_bridge->netoutdev; 740 realoutdev = nf_bridge->netoutdev;
715#endif 741#endif
716 if (skb->protocol == __constant_htons(ETH_P_8021Q)) { 742 if (skb->protocol == htons(ETH_P_8021Q)) {
717 skb_pull(skb, VLAN_HLEN); 743 skb_pull(skb, VLAN_HLEN);
718 (*pskb)->nh.raw += VLAN_HLEN; 744 (*pskb)->nh.raw += VLAN_HLEN;
719 } 745 }
720 /* IP forwarded traffic has a physindev, locally 746 /* IP forwarded traffic has a physindev, locally
721 * generated traffic hasn't. */ 747 * generated traffic hasn't. */
722 if (realindev != NULL) { 748 if (realindev != NULL) {
723 if (!(nf_bridge->mask & BRNF_DONT_TAKE_PARENT) ) { 749 if (!(nf_bridge->mask & BRNF_DONT_TAKE_PARENT)) {
724 struct net_device *parent = bridge_parent(realindev); 750 struct net_device *parent = bridge_parent(realindev);
725 if (parent) 751 if (parent)
726 realindev = parent; 752 realindev = parent;
@@ -742,12 +768,12 @@ out:
742 768
743/* PF_BRIDGE/POST_ROUTING ********************************************/ 769/* PF_BRIDGE/POST_ROUTING ********************************************/
744static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb, 770static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
745 const struct net_device *in, const struct net_device *out, 771 const struct net_device *in,
746 int (*okfn)(struct sk_buff *)) 772 const struct net_device *out,
773 int (*okfn)(struct sk_buff *))
747{ 774{
748 struct sk_buff *skb = *pskb; 775 struct sk_buff *skb = *pskb;
749 struct nf_bridge_info *nf_bridge = (*pskb)->nf_bridge; 776 struct nf_bridge_info *nf_bridge = (*pskb)->nf_bridge;
750 struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
751 struct net_device *realoutdev = bridge_parent(skb->dev); 777 struct net_device *realoutdev = bridge_parent(skb->dev);
752 int pf; 778 int pf;
753 779
@@ -756,7 +782,7 @@ static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
756 * keep the check just to be sure... */ 782 * keep the check just to be sure... */
757 if (skb->mac.raw < skb->head || skb->mac.raw + ETH_HLEN > skb->data) { 783 if (skb->mac.raw < skb->head || skb->mac.raw + ETH_HLEN > skb->data) {
758 printk(KERN_CRIT "br_netfilter: Argh!! br_nf_post_routing: " 784 printk(KERN_CRIT "br_netfilter: Argh!! br_nf_post_routing: "
759 "bad mac.raw pointer."); 785 "bad mac.raw pointer.");
760 goto print_error; 786 goto print_error;
761 } 787 }
762#endif 788#endif
@@ -767,7 +793,7 @@ static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
767 if (!realoutdev) 793 if (!realoutdev)
768 return NF_DROP; 794 return NF_DROP;
769 795
770 if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP) 796 if (skb->protocol == htons(ETH_P_IP) || IS_VLAN_IP(skb))
771 pf = PF_INET; 797 pf = PF_INET;
772 else 798 else
773 pf = PF_INET6; 799 pf = PF_INET6;
@@ -786,7 +812,7 @@ static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
786 nf_bridge->mask |= BRNF_PKT_TYPE; 812 nf_bridge->mask |= BRNF_PKT_TYPE;
787 } 813 }
788 814
789 if (skb->protocol == __constant_htons(ETH_P_8021Q)) { 815 if (skb->protocol == htons(ETH_P_8021Q)) {
790 skb_pull(skb, VLAN_HLEN); 816 skb_pull(skb, VLAN_HLEN);
791 skb->nh.raw += VLAN_HLEN; 817 skb->nh.raw += VLAN_HLEN;
792 } 818 }
@@ -798,7 +824,7 @@ static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
798 realoutdev = nf_bridge->netoutdev; 824 realoutdev = nf_bridge->netoutdev;
799#endif 825#endif
800 NF_HOOK(pf, NF_IP_POST_ROUTING, skb, NULL, realoutdev, 826 NF_HOOK(pf, NF_IP_POST_ROUTING, skb, NULL, realoutdev,
801 br_dev_queue_push_xmit); 827 br_dev_queue_push_xmit);
802 828
803 return NF_STOLEN; 829 return NF_STOLEN;
804 830
@@ -810,18 +836,18 @@ print_error:
810 printk("[%s]", realoutdev->name); 836 printk("[%s]", realoutdev->name);
811 } 837 }
812 printk(" head:%p, raw:%p, data:%p\n", skb->head, skb->mac.raw, 838 printk(" head:%p, raw:%p, data:%p\n", skb->head, skb->mac.raw,
813 skb->data); 839 skb->data);
814 return NF_ACCEPT; 840 return NF_ACCEPT;
815#endif 841#endif
816} 842}
817 843
818
819/* IP/SABOTAGE *****************************************************/ 844/* IP/SABOTAGE *****************************************************/
820/* Don't hand locally destined packets to PF_INET(6)/PRE_ROUTING 845/* Don't hand locally destined packets to PF_INET(6)/PRE_ROUTING
821 * for the second time. */ 846 * for the second time. */
822static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff **pskb, 847static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff **pskb,
823 const struct net_device *in, const struct net_device *out, 848 const struct net_device *in,
824 int (*okfn)(struct sk_buff *)) 849 const struct net_device *out,
850 int (*okfn)(struct sk_buff *))
825{ 851{
826 if ((*pskb)->nf_bridge && 852 if ((*pskb)->nf_bridge &&
827 !((*pskb)->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) { 853 !((*pskb)->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
@@ -835,18 +861,18 @@ static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff **pskb,
835 * and PF_INET(6)/POST_ROUTING until we have done the forwarding 861 * and PF_INET(6)/POST_ROUTING until we have done the forwarding
836 * decision in the bridge code and have determined nf_bridge->physoutdev. */ 862 * decision in the bridge code and have determined nf_bridge->physoutdev. */
837static unsigned int ip_sabotage_out(unsigned int hook, struct sk_buff **pskb, 863static unsigned int ip_sabotage_out(unsigned int hook, struct sk_buff **pskb,
838 const struct net_device *in, const struct net_device *out, 864 const struct net_device *in,
839 int (*okfn)(struct sk_buff *)) 865 const struct net_device *out,
866 int (*okfn)(struct sk_buff *))
840{ 867{
841 struct sk_buff *skb = *pskb; 868 struct sk_buff *skb = *pskb;
842 869
843 if ((out->hard_start_xmit == br_dev_xmit && 870 if ((out->hard_start_xmit == br_dev_xmit &&
844 okfn != br_nf_forward_finish && 871 okfn != br_nf_forward_finish &&
845 okfn != br_nf_local_out_finish && 872 okfn != br_nf_local_out_finish && okfn != br_dev_queue_push_xmit)
846 okfn != br_dev_queue_push_xmit)
847#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) 873#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
848 || ((out->priv_flags & IFF_802_1Q_VLAN) && 874 || ((out->priv_flags & IFF_802_1Q_VLAN) &&
849 VLAN_DEV_INFO(out)->real_dev->hard_start_xmit == br_dev_xmit) 875 VLAN_DEV_INFO(out)->real_dev->hard_start_xmit == br_dev_xmit)
850#endif 876#endif
851 ) { 877 ) {
852 struct nf_bridge_info *nf_bridge; 878 struct nf_bridge_info *nf_bridge;
@@ -971,8 +997,8 @@ static struct nf_hook_ops br_nf_ops[] = {
971 997
972#ifdef CONFIG_SYSCTL 998#ifdef CONFIG_SYSCTL
973static 999static
974int brnf_sysctl_call_tables(ctl_table *ctl, int write, struct file * filp, 1000int brnf_sysctl_call_tables(ctl_table * ctl, int write, struct file *filp,
975 void __user *buffer, size_t *lenp, loff_t *ppos) 1001 void __user * buffer, size_t * lenp, loff_t * ppos)
976{ 1002{
977 int ret; 1003 int ret;
978 1004
@@ -1059,7 +1085,8 @@ int br_netfilter_init(void)
1059#ifdef CONFIG_SYSCTL 1085#ifdef CONFIG_SYSCTL
1060 brnf_sysctl_header = register_sysctl_table(brnf_net_table, 0); 1086 brnf_sysctl_header = register_sysctl_table(brnf_net_table, 0);
1061 if (brnf_sysctl_header == NULL) { 1087 if (brnf_sysctl_header == NULL) {
1062 printk(KERN_WARNING "br_netfilter: can't register to sysctl.\n"); 1088 printk(KERN_WARNING
1089 "br_netfilter: can't register to sysctl.\n");
1063 for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++) 1090 for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++)
1064 nf_unregister_hook(&br_nf_ops[i]); 1091 nf_unregister_hook(&br_nf_ops[i]);
1065 return -EFAULT; 1092 return -EFAULT;
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 8f10e09f251b..86ecea7ed372 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -109,6 +109,7 @@ struct net_bridge
109 unsigned long bridge_hello_time; 109 unsigned long bridge_hello_time;
110 unsigned long bridge_forward_delay; 110 unsigned long bridge_forward_delay;
111 111
112 u8 group_addr[ETH_ALEN];
112 u16 root_port; 113 u16 root_port;
113 unsigned char stp_enabled; 114 unsigned char stp_enabled;
114 unsigned char topology_change; 115 unsigned char topology_change;
@@ -122,7 +123,7 @@ struct net_bridge
122}; 123};
123 124
124extern struct notifier_block br_device_notifier; 125extern struct notifier_block br_device_notifier;
125extern const unsigned char bridge_ula[6]; 126extern const u8 br_group_address[ETH_ALEN];
126 127
127/* called under bridge lock */ 128/* called under bridge lock */
128static inline int br_is_root_bridge(const struct net_bridge *br) 129static inline int br_is_root_bridge(const struct net_bridge *br)
@@ -217,7 +218,8 @@ extern void br_stp_set_path_cost(struct net_bridge_port *p,
217extern ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id); 218extern ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id);
218 219
219/* br_stp_bpdu.c */ 220/* br_stp_bpdu.c */
220extern int br_stp_handle_bpdu(struct sk_buff *skb); 221extern int br_stp_rcv(struct sk_buff *skb, struct net_device *dev,
222 struct packet_type *pt, struct net_device *orig_dev);
221 223
222/* br_stp_timer.c */ 224/* br_stp_timer.c */
223extern void br_stp_timer_init(struct net_bridge *br); 225extern void br_stp_timer_init(struct net_bridge *br);
diff --git a/net/bridge/br_stp_bpdu.c b/net/bridge/br_stp_bpdu.c
index 296f6a487c52..8934a54792be 100644
--- a/net/bridge/br_stp_bpdu.c
+++ b/net/bridge/br_stp_bpdu.c
@@ -15,158 +15,162 @@
15 15
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/netfilter_bridge.h> 17#include <linux/netfilter_bridge.h>
18#include <linux/etherdevice.h>
19#include <linux/llc.h>
20#include <net/llc.h>
21#include <net/llc_pdu.h>
18 22
19#include "br_private.h" 23#include "br_private.h"
20#include "br_private_stp.h" 24#include "br_private_stp.h"
21 25
22#define JIFFIES_TO_TICKS(j) (((j) << 8) / HZ) 26#define STP_HZ 256
23#define TICKS_TO_JIFFIES(j) (((j) * HZ) >> 8)
24 27
25static void br_send_bpdu(struct net_bridge_port *p, unsigned char *data, int length) 28#define LLC_RESERVE sizeof(struct llc_pdu_un)
29
30static void br_send_bpdu(struct net_bridge_port *p,
31 const unsigned char *data, int length)
26{ 32{
27 struct net_device *dev;
28 struct sk_buff *skb; 33 struct sk_buff *skb;
29 int size;
30 34
31 if (!p->br->stp_enabled) 35 if (!p->br->stp_enabled)
32 return; 36 return;
33 37
34 size = length + 2*ETH_ALEN + 2; 38 skb = dev_alloc_skb(length+LLC_RESERVE);
35 if (size < 60) 39 if (!skb)
36 size = 60;
37
38 dev = p->dev;
39
40 if ((skb = dev_alloc_skb(size)) == NULL) {
41 printk(KERN_INFO "br: memory squeeze!\n");
42 return; 40 return;
43 }
44 41
45 skb->dev = dev; 42 skb->dev = p->dev;
46 skb->protocol = htons(ETH_P_802_2); 43 skb->protocol = htons(ETH_P_802_2);
47 skb->mac.raw = skb_put(skb, size); 44
48 memcpy(skb->mac.raw, bridge_ula, ETH_ALEN); 45 skb_reserve(skb, LLC_RESERVE);
49 memcpy(skb->mac.raw+ETH_ALEN, dev->dev_addr, ETH_ALEN); 46 memcpy(__skb_put(skb, length), data, length);
50 skb->mac.raw[2*ETH_ALEN] = 0; 47
51 skb->mac.raw[2*ETH_ALEN+1] = length; 48 llc_pdu_header_init(skb, LLC_PDU_TYPE_U, LLC_SAP_BSPAN,
52 skb->nh.raw = skb->mac.raw + 2*ETH_ALEN + 2; 49 LLC_SAP_BSPAN, LLC_PDU_CMD);
53 memcpy(skb->nh.raw, data, length); 50 llc_pdu_init_as_ui_cmd(skb);
54 memset(skb->nh.raw + length, 0xa5, size - length - 2*ETH_ALEN - 2); 51
52 llc_mac_hdr_init(skb, p->dev->dev_addr, p->br->group_addr);
55 53
56 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev, 54 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
57 dev_queue_xmit); 55 dev_queue_xmit);
58} 56}
59 57
60static __inline__ void br_set_ticks(unsigned char *dest, int jiff) 58static inline void br_set_ticks(unsigned char *dest, int j)
61{ 59{
62 __u16 ticks; 60 unsigned long ticks = (STP_HZ * j)/ HZ;
63 61
64 ticks = JIFFIES_TO_TICKS(jiff); 62 *((__be16 *) dest) = htons(ticks);
65 dest[0] = (ticks >> 8) & 0xFF;
66 dest[1] = ticks & 0xFF;
67} 63}
68 64
69static __inline__ int br_get_ticks(unsigned char *dest) 65static inline int br_get_ticks(const unsigned char *src)
70{ 66{
71 return TICKS_TO_JIFFIES((dest[0] << 8) | dest[1]); 67 unsigned long ticks = ntohs(*(__be16 *)src);
68
69 return (ticks * HZ + STP_HZ - 1) / STP_HZ;
72} 70}
73 71
74/* called under bridge lock */ 72/* called under bridge lock */
75void br_send_config_bpdu(struct net_bridge_port *p, struct br_config_bpdu *bpdu) 73void br_send_config_bpdu(struct net_bridge_port *p, struct br_config_bpdu *bpdu)
76{ 74{
77 unsigned char buf[38]; 75 unsigned char buf[35];
78 76
79 buf[0] = 0x42; 77 buf[0] = 0;
80 buf[1] = 0x42; 78 buf[1] = 0;
81 buf[2] = 0x03; 79 buf[2] = 0;
82 buf[3] = 0; 80 buf[3] = BPDU_TYPE_CONFIG;
83 buf[4] = 0; 81 buf[4] = (bpdu->topology_change ? 0x01 : 0) |
84 buf[5] = 0;
85 buf[6] = BPDU_TYPE_CONFIG;
86 buf[7] = (bpdu->topology_change ? 0x01 : 0) |
87 (bpdu->topology_change_ack ? 0x80 : 0); 82 (bpdu->topology_change_ack ? 0x80 : 0);
88 buf[8] = bpdu->root.prio[0]; 83 buf[5] = bpdu->root.prio[0];
89 buf[9] = bpdu->root.prio[1]; 84 buf[6] = bpdu->root.prio[1];
90 buf[10] = bpdu->root.addr[0]; 85 buf[7] = bpdu->root.addr[0];
91 buf[11] = bpdu->root.addr[1]; 86 buf[8] = bpdu->root.addr[1];
92 buf[12] = bpdu->root.addr[2]; 87 buf[9] = bpdu->root.addr[2];
93 buf[13] = bpdu->root.addr[3]; 88 buf[10] = bpdu->root.addr[3];
94 buf[14] = bpdu->root.addr[4]; 89 buf[11] = bpdu->root.addr[4];
95 buf[15] = bpdu->root.addr[5]; 90 buf[12] = bpdu->root.addr[5];
96 buf[16] = (bpdu->root_path_cost >> 24) & 0xFF; 91 buf[13] = (bpdu->root_path_cost >> 24) & 0xFF;
97 buf[17] = (bpdu->root_path_cost >> 16) & 0xFF; 92 buf[14] = (bpdu->root_path_cost >> 16) & 0xFF;
98 buf[18] = (bpdu->root_path_cost >> 8) & 0xFF; 93 buf[15] = (bpdu->root_path_cost >> 8) & 0xFF;
99 buf[19] = bpdu->root_path_cost & 0xFF; 94 buf[16] = bpdu->root_path_cost & 0xFF;
100 buf[20] = bpdu->bridge_id.prio[0]; 95 buf[17] = bpdu->bridge_id.prio[0];
101 buf[21] = bpdu->bridge_id.prio[1]; 96 buf[18] = bpdu->bridge_id.prio[1];
102 buf[22] = bpdu->bridge_id.addr[0]; 97 buf[19] = bpdu->bridge_id.addr[0];
103 buf[23] = bpdu->bridge_id.addr[1]; 98 buf[20] = bpdu->bridge_id.addr[1];
104 buf[24] = bpdu->bridge_id.addr[2]; 99 buf[21] = bpdu->bridge_id.addr[2];
105 buf[25] = bpdu->bridge_id.addr[3]; 100 buf[22] = bpdu->bridge_id.addr[3];
106 buf[26] = bpdu->bridge_id.addr[4]; 101 buf[23] = bpdu->bridge_id.addr[4];
107 buf[27] = bpdu->bridge_id.addr[5]; 102 buf[24] = bpdu->bridge_id.addr[5];
108 buf[28] = (bpdu->port_id >> 8) & 0xFF; 103 buf[25] = (bpdu->port_id >> 8) & 0xFF;
109 buf[29] = bpdu->port_id & 0xFF; 104 buf[26] = bpdu->port_id & 0xFF;
110 105
111 br_set_ticks(buf+30, bpdu->message_age); 106 br_set_ticks(buf+27, bpdu->message_age);
112 br_set_ticks(buf+32, bpdu->max_age); 107 br_set_ticks(buf+29, bpdu->max_age);
113 br_set_ticks(buf+34, bpdu->hello_time); 108 br_set_ticks(buf+31, bpdu->hello_time);
114 br_set_ticks(buf+36, bpdu->forward_delay); 109 br_set_ticks(buf+33, bpdu->forward_delay);
115 110
116 br_send_bpdu(p, buf, 38); 111 br_send_bpdu(p, buf, 35);
117} 112}
118 113
119/* called under bridge lock */ 114/* called under bridge lock */
120void br_send_tcn_bpdu(struct net_bridge_port *p) 115void br_send_tcn_bpdu(struct net_bridge_port *p)
121{ 116{
122 unsigned char buf[7]; 117 unsigned char buf[4];
123 118
124 buf[0] = 0x42; 119 buf[0] = 0;
125 buf[1] = 0x42; 120 buf[1] = 0;
126 buf[2] = 0x03; 121 buf[2] = 0;
127 buf[3] = 0; 122 buf[3] = BPDU_TYPE_TCN;
128 buf[4] = 0;
129 buf[5] = 0;
130 buf[6] = BPDU_TYPE_TCN;
131 br_send_bpdu(p, buf, 7); 123 br_send_bpdu(p, buf, 7);
132} 124}
133 125
134static const unsigned char header[6] = {0x42, 0x42, 0x03, 0x00, 0x00, 0x00}; 126/*
135 127 * Called from llc.
136/* NO locks, but rcu_read_lock (preempt_disabled) */ 128 *
137int br_stp_handle_bpdu(struct sk_buff *skb) 129 * NO locks, but rcu_read_lock (preempt_disabled)
130 */
131int br_stp_rcv(struct sk_buff *skb, struct net_device *dev,
132 struct packet_type *pt, struct net_device *orig_dev)
138{ 133{
139 struct net_bridge_port *p = rcu_dereference(skb->dev->br_port); 134 const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
135 const unsigned char *dest = eth_hdr(skb)->h_dest;
136 struct net_bridge_port *p = rcu_dereference(dev->br_port);
140 struct net_bridge *br; 137 struct net_bridge *br;
141 unsigned char *buf; 138 const unsigned char *buf;
142 139
143 if (!p) 140 if (!p)
144 goto err; 141 goto err;
145 142
146 br = p->br; 143 if (pdu->ssap != LLC_SAP_BSPAN
147 spin_lock(&br->lock); 144 || pdu->dsap != LLC_SAP_BSPAN
145 || pdu->ctrl_1 != LLC_PDU_TYPE_U)
146 goto err;
148 147
149 if (p->state == BR_STATE_DISABLED || !(br->dev->flags & IFF_UP)) 148 if (!pskb_may_pull(skb, 4))
150 goto out; 149 goto err;
150
151 /* compare of protocol id and version */
152 buf = skb->data;
153 if (buf[0] != 0 || buf[1] != 0 || buf[2] != 0)
154 goto err;
151 155
152 /* insert into forwarding database after filtering to avoid spoofing */ 156 br = p->br;
153 br_fdb_update(br, p, eth_hdr(skb)->h_source); 157 spin_lock(&br->lock);
154 158
155 if (!br->stp_enabled) 159 if (p->state == BR_STATE_DISABLED
160 || !br->stp_enabled
161 || !(br->dev->flags & IFF_UP))
156 goto out; 162 goto out;
157 163
158 /* need at least the 802 and STP headers */ 164 if (compare_ether_addr(dest, br->group_addr) != 0)
159 if (!pskb_may_pull(skb, sizeof(header)+1) ||
160 memcmp(skb->data, header, sizeof(header)))
161 goto out; 165 goto out;
162 166
163 buf = skb_pull(skb, sizeof(header)); 167 buf = skb_pull(skb, 3);
164 168
165 if (buf[0] == BPDU_TYPE_CONFIG) { 169 if (buf[0] == BPDU_TYPE_CONFIG) {
166 struct br_config_bpdu bpdu; 170 struct br_config_bpdu bpdu;
167 171
168 if (!pskb_may_pull(skb, 32)) 172 if (!pskb_may_pull(skb, 32))
169 goto out; 173 goto out;
170 174
171 buf = skb->data; 175 buf = skb->data;
172 bpdu.topology_change = (buf[1] & 0x01) ? 1 : 0; 176 bpdu.topology_change = (buf[1] & 0x01) ? 1 : 0;
diff --git a/net/bridge/br_stp_timer.c b/net/bridge/br_stp_timer.c
index 9bef55f56425..d0fcde82c6fc 100644
--- a/net/bridge/br_stp_timer.c
+++ b/net/bridge/br_stp_timer.c
@@ -39,13 +39,13 @@ static void br_hello_timer_expired(unsigned long arg)
39 struct net_bridge *br = (struct net_bridge *)arg; 39 struct net_bridge *br = (struct net_bridge *)arg;
40 40
41 pr_debug("%s: hello timer expired\n", br->dev->name); 41 pr_debug("%s: hello timer expired\n", br->dev->name);
42 spin_lock_bh(&br->lock); 42 spin_lock(&br->lock);
43 if (br->dev->flags & IFF_UP) { 43 if (br->dev->flags & IFF_UP) {
44 br_config_bpdu_generation(br); 44 br_config_bpdu_generation(br);
45 45
46 mod_timer(&br->hello_timer, jiffies + br->hello_time); 46 mod_timer(&br->hello_timer, jiffies + br->hello_time);
47 } 47 }
48 spin_unlock_bh(&br->lock); 48 spin_unlock(&br->lock);
49} 49}
50 50
51static void br_message_age_timer_expired(unsigned long arg) 51static void br_message_age_timer_expired(unsigned long arg)
@@ -71,7 +71,7 @@ static void br_message_age_timer_expired(unsigned long arg)
71 * running when we are the root bridge. So.. this was_root 71 * running when we are the root bridge. So.. this was_root
72 * check is redundant. I'm leaving it in for now, though. 72 * check is redundant. I'm leaving it in for now, though.
73 */ 73 */
74 spin_lock_bh(&br->lock); 74 spin_lock(&br->lock);
75 if (p->state == BR_STATE_DISABLED) 75 if (p->state == BR_STATE_DISABLED)
76 goto unlock; 76 goto unlock;
77 was_root = br_is_root_bridge(br); 77 was_root = br_is_root_bridge(br);
@@ -82,7 +82,7 @@ static void br_message_age_timer_expired(unsigned long arg)
82 if (br_is_root_bridge(br) && !was_root) 82 if (br_is_root_bridge(br) && !was_root)
83 br_become_root_bridge(br); 83 br_become_root_bridge(br);
84 unlock: 84 unlock:
85 spin_unlock_bh(&br->lock); 85 spin_unlock(&br->lock);
86} 86}
87 87
88static void br_forward_delay_timer_expired(unsigned long arg) 88static void br_forward_delay_timer_expired(unsigned long arg)
@@ -92,7 +92,7 @@ static void br_forward_delay_timer_expired(unsigned long arg)
92 92
93 pr_debug("%s: %d(%s) forward delay timer\n", 93 pr_debug("%s: %d(%s) forward delay timer\n",
94 br->dev->name, p->port_no, p->dev->name); 94 br->dev->name, p->port_no, p->dev->name);
95 spin_lock_bh(&br->lock); 95 spin_lock(&br->lock);
96 if (p->state == BR_STATE_LISTENING) { 96 if (p->state == BR_STATE_LISTENING) {
97 p->state = BR_STATE_LEARNING; 97 p->state = BR_STATE_LEARNING;
98 mod_timer(&p->forward_delay_timer, 98 mod_timer(&p->forward_delay_timer,
@@ -103,7 +103,7 @@ static void br_forward_delay_timer_expired(unsigned long arg)
103 br_topology_change_detection(br); 103 br_topology_change_detection(br);
104 } 104 }
105 br_log_state(p); 105 br_log_state(p);
106 spin_unlock_bh(&br->lock); 106 spin_unlock(&br->lock);
107} 107}
108 108
109static void br_tcn_timer_expired(unsigned long arg) 109static void br_tcn_timer_expired(unsigned long arg)
@@ -111,13 +111,13 @@ static void br_tcn_timer_expired(unsigned long arg)
111 struct net_bridge *br = (struct net_bridge *) arg; 111 struct net_bridge *br = (struct net_bridge *) arg;
112 112
113 pr_debug("%s: tcn timer expired\n", br->dev->name); 113 pr_debug("%s: tcn timer expired\n", br->dev->name);
114 spin_lock_bh(&br->lock); 114 spin_lock(&br->lock);
115 if (br->dev->flags & IFF_UP) { 115 if (br->dev->flags & IFF_UP) {
116 br_transmit_tcn(br); 116 br_transmit_tcn(br);
117 117
118 mod_timer(&br->tcn_timer,jiffies + br->bridge_hello_time); 118 mod_timer(&br->tcn_timer,jiffies + br->bridge_hello_time);
119 } 119 }
120 spin_unlock_bh(&br->lock); 120 spin_unlock(&br->lock);
121} 121}
122 122
123static void br_topology_change_timer_expired(unsigned long arg) 123static void br_topology_change_timer_expired(unsigned long arg)
@@ -125,10 +125,10 @@ static void br_topology_change_timer_expired(unsigned long arg)
125 struct net_bridge *br = (struct net_bridge *) arg; 125 struct net_bridge *br = (struct net_bridge *) arg;
126 126
127 pr_debug("%s: topo change timer expired\n", br->dev->name); 127 pr_debug("%s: topo change timer expired\n", br->dev->name);
128 spin_lock_bh(&br->lock); 128 spin_lock(&br->lock);
129 br->topology_change_detected = 0; 129 br->topology_change_detected = 0;
130 br->topology_change = 0; 130 br->topology_change = 0;
131 spin_unlock_bh(&br->lock); 131 spin_unlock(&br->lock);
132} 132}
133 133
134static void br_hold_timer_expired(unsigned long arg) 134static void br_hold_timer_expired(unsigned long arg)
@@ -138,45 +138,36 @@ static void br_hold_timer_expired(unsigned long arg)
138 pr_debug("%s: %d(%s) hold timer expired\n", 138 pr_debug("%s: %d(%s) hold timer expired\n",
139 p->br->dev->name, p->port_no, p->dev->name); 139 p->br->dev->name, p->port_no, p->dev->name);
140 140
141 spin_lock_bh(&p->br->lock); 141 spin_lock(&p->br->lock);
142 if (p->config_pending) 142 if (p->config_pending)
143 br_transmit_config(p); 143 br_transmit_config(p);
144 spin_unlock_bh(&p->br->lock); 144 spin_unlock(&p->br->lock);
145}
146
147static inline void br_timer_init(struct timer_list *timer,
148 void (*_function)(unsigned long),
149 unsigned long _data)
150{
151 init_timer(timer);
152 timer->function = _function;
153 timer->data = _data;
154} 145}
155 146
156void br_stp_timer_init(struct net_bridge *br) 147void br_stp_timer_init(struct net_bridge *br)
157{ 148{
158 br_timer_init(&br->hello_timer, br_hello_timer_expired, 149 setup_timer(&br->hello_timer, br_hello_timer_expired,
159 (unsigned long) br); 150 (unsigned long) br);
160 151
161 br_timer_init(&br->tcn_timer, br_tcn_timer_expired, 152 setup_timer(&br->tcn_timer, br_tcn_timer_expired,
162 (unsigned long) br); 153 (unsigned long) br);
163 154
164 br_timer_init(&br->topology_change_timer, 155 setup_timer(&br->topology_change_timer,
165 br_topology_change_timer_expired, 156 br_topology_change_timer_expired,
166 (unsigned long) br); 157 (unsigned long) br);
167 158
168 br_timer_init(&br->gc_timer, br_fdb_cleanup, (unsigned long) br); 159 setup_timer(&br->gc_timer, br_fdb_cleanup, (unsigned long) br);
169} 160}
170 161
171void br_stp_port_timer_init(struct net_bridge_port *p) 162void br_stp_port_timer_init(struct net_bridge_port *p)
172{ 163{
173 br_timer_init(&p->message_age_timer, br_message_age_timer_expired, 164 setup_timer(&p->message_age_timer, br_message_age_timer_expired,
174 (unsigned long) p); 165 (unsigned long) p);
175 166
176 br_timer_init(&p->forward_delay_timer, br_forward_delay_timer_expired, 167 setup_timer(&p->forward_delay_timer, br_forward_delay_timer_expired,
177 (unsigned long) p); 168 (unsigned long) p);
178 169
179 br_timer_init(&p->hold_timer, br_hold_timer_expired, 170 setup_timer(&p->hold_timer, br_hold_timer_expired,
180 (unsigned long) p); 171 (unsigned long) p);
181} 172}
182 173
diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
index 6f577f16c4c0..96bcb2ff59ab 100644
--- a/net/bridge/br_sysfs_br.c
+++ b/net/bridge/br_sysfs_br.c
@@ -242,6 +242,54 @@ static ssize_t show_gc_timer(struct class_device *cd, char *buf)
242} 242}
243static CLASS_DEVICE_ATTR(gc_timer, S_IRUGO, show_gc_timer, NULL); 243static CLASS_DEVICE_ATTR(gc_timer, S_IRUGO, show_gc_timer, NULL);
244 244
245static ssize_t show_group_addr(struct class_device *cd, char *buf)
246{
247 struct net_bridge *br = to_bridge(cd);
248 return sprintf(buf, "%x:%x:%x:%x:%x:%x\n",
249 br->group_addr[0], br->group_addr[1],
250 br->group_addr[2], br->group_addr[3],
251 br->group_addr[4], br->group_addr[5]);
252}
253
254static ssize_t store_group_addr(struct class_device *cd, const char *buf,
255 size_t len)
256{
257 struct net_bridge *br = to_bridge(cd);
258 unsigned new_addr[6];
259 int i;
260
261 if (!capable(CAP_NET_ADMIN))
262 return -EPERM;
263
264 if (sscanf(buf, "%x:%x:%x:%x:%x:%x",
265 &new_addr[0], &new_addr[1], &new_addr[2],
266 &new_addr[3], &new_addr[4], &new_addr[5]) != 6)
267 return -EINVAL;
268
269 /* Must be 01:80:c2:00:00:0X */
270 for (i = 0; i < 5; i++)
271 if (new_addr[i] != br_group_address[i])
272 return -EINVAL;
273
274 if (new_addr[5] & ~0xf)
275 return -EINVAL;
276
277 if (new_addr[5] == 1 /* 802.3x Pause address */
278 || new_addr[5] == 2 /* 802.3ad Slow protocols */
279 || new_addr[5] == 3) /* 802.1X PAE address */
280 return -EINVAL;
281
282 spin_lock_bh(&br->lock);
283 for (i = 0; i < 6; i++)
284 br->group_addr[i] = new_addr[i];
285 spin_unlock_bh(&br->lock);
286 return len;
287}
288
289static CLASS_DEVICE_ATTR(group_addr, S_IRUGO | S_IWUSR,
290 show_group_addr, store_group_addr);
291
292
245static struct attribute *bridge_attrs[] = { 293static struct attribute *bridge_attrs[] = {
246 &class_device_attr_forward_delay.attr, 294 &class_device_attr_forward_delay.attr,
247 &class_device_attr_hello_time.attr, 295 &class_device_attr_hello_time.attr,
@@ -259,6 +307,7 @@ static struct attribute *bridge_attrs[] = {
259 &class_device_attr_tcn_timer.attr, 307 &class_device_attr_tcn_timer.attr,
260 &class_device_attr_topology_change_timer.attr, 308 &class_device_attr_topology_change_timer.attr,
261 &class_device_attr_gc_timer.attr, 309 &class_device_attr_gc_timer.attr,
310 &class_device_attr_group_addr.attr,
262 NULL 311 NULL
263}; 312};
264 313
diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index cbd4020cc84d..997953367204 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -35,6 +35,7 @@
35#define ASSERT_READ_LOCK(x) 35#define ASSERT_READ_LOCK(x)
36#define ASSERT_WRITE_LOCK(x) 36#define ASSERT_WRITE_LOCK(x)
37#include <linux/netfilter_ipv4/listhelp.h> 37#include <linux/netfilter_ipv4/listhelp.h>
38#include <linux/mutex.h>
38 39
39#if 0 40#if 0
40/* use this for remote debugging 41/* use this for remote debugging
@@ -81,7 +82,7 @@ static void print_string(char *str)
81 82
82 83
83 84
84static DECLARE_MUTEX(ebt_mutex); 85static DEFINE_MUTEX(ebt_mutex);
85static LIST_HEAD(ebt_tables); 86static LIST_HEAD(ebt_tables);
86static LIST_HEAD(ebt_targets); 87static LIST_HEAD(ebt_targets);
87static LIST_HEAD(ebt_matches); 88static LIST_HEAD(ebt_matches);
@@ -296,18 +297,18 @@ letscontinue:
296/* If it succeeds, returns element and locks mutex */ 297/* If it succeeds, returns element and locks mutex */
297static inline void * 298static inline void *
298find_inlist_lock_noload(struct list_head *head, const char *name, int *error, 299find_inlist_lock_noload(struct list_head *head, const char *name, int *error,
299 struct semaphore *mutex) 300 struct mutex *mutex)
300{ 301{
301 void *ret; 302 void *ret;
302 303
303 *error = down_interruptible(mutex); 304 *error = mutex_lock_interruptible(mutex);
304 if (*error != 0) 305 if (*error != 0)
305 return NULL; 306 return NULL;
306 307
307 ret = list_named_find(head, name); 308 ret = list_named_find(head, name);
308 if (!ret) { 309 if (!ret) {
309 *error = -ENOENT; 310 *error = -ENOENT;
310 up(mutex); 311 mutex_unlock(mutex);
311 } 312 }
312 return ret; 313 return ret;
313} 314}
@@ -317,7 +318,7 @@ find_inlist_lock_noload(struct list_head *head, const char *name, int *error,
317#else 318#else
318static void * 319static void *
319find_inlist_lock(struct list_head *head, const char *name, const char *prefix, 320find_inlist_lock(struct list_head *head, const char *name, const char *prefix,
320 int *error, struct semaphore *mutex) 321 int *error, struct mutex *mutex)
321{ 322{
322 void *ret; 323 void *ret;
323 324
@@ -331,25 +332,25 @@ find_inlist_lock(struct list_head *head, const char *name, const char *prefix,
331#endif 332#endif
332 333
333static inline struct ebt_table * 334static inline struct ebt_table *
334find_table_lock(const char *name, int *error, struct semaphore *mutex) 335find_table_lock(const char *name, int *error, struct mutex *mutex)
335{ 336{
336 return find_inlist_lock(&ebt_tables, name, "ebtable_", error, mutex); 337 return find_inlist_lock(&ebt_tables, name, "ebtable_", error, mutex);
337} 338}
338 339
339static inline struct ebt_match * 340static inline struct ebt_match *
340find_match_lock(const char *name, int *error, struct semaphore *mutex) 341find_match_lock(const char *name, int *error, struct mutex *mutex)
341{ 342{
342 return find_inlist_lock(&ebt_matches, name, "ebt_", error, mutex); 343 return find_inlist_lock(&ebt_matches, name, "ebt_", error, mutex);
343} 344}
344 345
345static inline struct ebt_watcher * 346static inline struct ebt_watcher *
346find_watcher_lock(const char *name, int *error, struct semaphore *mutex) 347find_watcher_lock(const char *name, int *error, struct mutex *mutex)
347{ 348{
348 return find_inlist_lock(&ebt_watchers, name, "ebt_", error, mutex); 349 return find_inlist_lock(&ebt_watchers, name, "ebt_", error, mutex);
349} 350}
350 351
351static inline struct ebt_target * 352static inline struct ebt_target *
352find_target_lock(const char *name, int *error, struct semaphore *mutex) 353find_target_lock(const char *name, int *error, struct mutex *mutex)
353{ 354{
354 return find_inlist_lock(&ebt_targets, name, "ebt_", error, mutex); 355 return find_inlist_lock(&ebt_targets, name, "ebt_", error, mutex);
355} 356}
@@ -369,10 +370,10 @@ ebt_check_match(struct ebt_entry_match *m, struct ebt_entry *e,
369 return ret; 370 return ret;
370 m->u.match = match; 371 m->u.match = match;
371 if (!try_module_get(match->me)) { 372 if (!try_module_get(match->me)) {
372 up(&ebt_mutex); 373 mutex_unlock(&ebt_mutex);
373 return -ENOENT; 374 return -ENOENT;
374 } 375 }
375 up(&ebt_mutex); 376 mutex_unlock(&ebt_mutex);
376 if (match->check && 377 if (match->check &&
377 match->check(name, hookmask, e, m->data, m->match_size) != 0) { 378 match->check(name, hookmask, e, m->data, m->match_size) != 0) {
378 BUGPRINT("match->check failed\n"); 379 BUGPRINT("match->check failed\n");
@@ -398,10 +399,10 @@ ebt_check_watcher(struct ebt_entry_watcher *w, struct ebt_entry *e,
398 return ret; 399 return ret;
399 w->u.watcher = watcher; 400 w->u.watcher = watcher;
400 if (!try_module_get(watcher->me)) { 401 if (!try_module_get(watcher->me)) {
401 up(&ebt_mutex); 402 mutex_unlock(&ebt_mutex);
402 return -ENOENT; 403 return -ENOENT;
403 } 404 }
404 up(&ebt_mutex); 405 mutex_unlock(&ebt_mutex);
405 if (watcher->check && 406 if (watcher->check &&
406 watcher->check(name, hookmask, e, w->data, w->watcher_size) != 0) { 407 watcher->check(name, hookmask, e, w->data, w->watcher_size) != 0) {
407 BUGPRINT("watcher->check failed\n"); 408 BUGPRINT("watcher->check failed\n");
@@ -638,11 +639,11 @@ ebt_check_entry(struct ebt_entry *e, struct ebt_table_info *newinfo,
638 if (!target) 639 if (!target)
639 goto cleanup_watchers; 640 goto cleanup_watchers;
640 if (!try_module_get(target->me)) { 641 if (!try_module_get(target->me)) {
641 up(&ebt_mutex); 642 mutex_unlock(&ebt_mutex);
642 ret = -ENOENT; 643 ret = -ENOENT;
643 goto cleanup_watchers; 644 goto cleanup_watchers;
644 } 645 }
645 up(&ebt_mutex); 646 mutex_unlock(&ebt_mutex);
646 647
647 t->u.target = target; 648 t->u.target = target;
648 if (t->u.target == &ebt_standard_target) { 649 if (t->u.target == &ebt_standard_target) {
@@ -1015,7 +1016,7 @@ static int do_replace(void __user *user, unsigned int len)
1015 1016
1016 t->private = newinfo; 1017 t->private = newinfo;
1017 write_unlock_bh(&t->lock); 1018 write_unlock_bh(&t->lock);
1018 up(&ebt_mutex); 1019 mutex_unlock(&ebt_mutex);
1019 /* so, a user can change the chains while having messed up her counter 1020 /* so, a user can change the chains while having messed up her counter
1020 allocation. Only reason why this is done is because this way the lock 1021 allocation. Only reason why this is done is because this way the lock
1021 is held only once, while this doesn't bring the kernel into a 1022 is held only once, while this doesn't bring the kernel into a
@@ -1045,7 +1046,7 @@ static int do_replace(void __user *user, unsigned int len)
1045 return ret; 1046 return ret;
1046 1047
1047free_unlock: 1048free_unlock:
1048 up(&ebt_mutex); 1049 mutex_unlock(&ebt_mutex);
1049free_iterate: 1050free_iterate:
1050 EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size, 1051 EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
1051 ebt_cleanup_entry, NULL); 1052 ebt_cleanup_entry, NULL);
@@ -1068,69 +1069,69 @@ int ebt_register_target(struct ebt_target *target)
1068{ 1069{
1069 int ret; 1070 int ret;
1070 1071
1071 ret = down_interruptible(&ebt_mutex); 1072 ret = mutex_lock_interruptible(&ebt_mutex);
1072 if (ret != 0) 1073 if (ret != 0)
1073 return ret; 1074 return ret;
1074 if (!list_named_insert(&ebt_targets, target)) { 1075 if (!list_named_insert(&ebt_targets, target)) {
1075 up(&ebt_mutex); 1076 mutex_unlock(&ebt_mutex);
1076 return -EEXIST; 1077 return -EEXIST;
1077 } 1078 }
1078 up(&ebt_mutex); 1079 mutex_unlock(&ebt_mutex);
1079 1080
1080 return 0; 1081 return 0;
1081} 1082}
1082 1083
1083void ebt_unregister_target(struct ebt_target *target) 1084void ebt_unregister_target(struct ebt_target *target)
1084{ 1085{
1085 down(&ebt_mutex); 1086 mutex_lock(&ebt_mutex);
1086 LIST_DELETE(&ebt_targets, target); 1087 LIST_DELETE(&ebt_targets, target);
1087 up(&ebt_mutex); 1088 mutex_unlock(&ebt_mutex);
1088} 1089}
1089 1090
1090int ebt_register_match(struct ebt_match *match) 1091int ebt_register_match(struct ebt_match *match)
1091{ 1092{
1092 int ret; 1093 int ret;
1093 1094
1094 ret = down_interruptible(&ebt_mutex); 1095 ret = mutex_lock_interruptible(&ebt_mutex);
1095 if (ret != 0) 1096 if (ret != 0)
1096 return ret; 1097 return ret;
1097 if (!list_named_insert(&ebt_matches, match)) { 1098 if (!list_named_insert(&ebt_matches, match)) {
1098 up(&ebt_mutex); 1099 mutex_unlock(&ebt_mutex);
1099 return -EEXIST; 1100 return -EEXIST;
1100 } 1101 }
1101 up(&ebt_mutex); 1102 mutex_unlock(&ebt_mutex);
1102 1103
1103 return 0; 1104 return 0;
1104} 1105}
1105 1106
1106void ebt_unregister_match(struct ebt_match *match) 1107void ebt_unregister_match(struct ebt_match *match)
1107{ 1108{
1108 down(&ebt_mutex); 1109 mutex_lock(&ebt_mutex);
1109 LIST_DELETE(&ebt_matches, match); 1110 LIST_DELETE(&ebt_matches, match);
1110 up(&ebt_mutex); 1111 mutex_unlock(&ebt_mutex);
1111} 1112}
1112 1113
1113int ebt_register_watcher(struct ebt_watcher *watcher) 1114int ebt_register_watcher(struct ebt_watcher *watcher)
1114{ 1115{
1115 int ret; 1116 int ret;
1116 1117
1117 ret = down_interruptible(&ebt_mutex); 1118 ret = mutex_lock_interruptible(&ebt_mutex);
1118 if (ret != 0) 1119 if (ret != 0)
1119 return ret; 1120 return ret;
1120 if (!list_named_insert(&ebt_watchers, watcher)) { 1121 if (!list_named_insert(&ebt_watchers, watcher)) {
1121 up(&ebt_mutex); 1122 mutex_unlock(&ebt_mutex);
1122 return -EEXIST; 1123 return -EEXIST;
1123 } 1124 }
1124 up(&ebt_mutex); 1125 mutex_unlock(&ebt_mutex);
1125 1126
1126 return 0; 1127 return 0;
1127} 1128}
1128 1129
1129void ebt_unregister_watcher(struct ebt_watcher *watcher) 1130void ebt_unregister_watcher(struct ebt_watcher *watcher)
1130{ 1131{
1131 down(&ebt_mutex); 1132 mutex_lock(&ebt_mutex);
1132 LIST_DELETE(&ebt_watchers, watcher); 1133 LIST_DELETE(&ebt_watchers, watcher);
1133 up(&ebt_mutex); 1134 mutex_unlock(&ebt_mutex);
1134} 1135}
1135 1136
1136int ebt_register_table(struct ebt_table *table) 1137int ebt_register_table(struct ebt_table *table)
@@ -1178,7 +1179,7 @@ int ebt_register_table(struct ebt_table *table)
1178 1179
1179 table->private = newinfo; 1180 table->private = newinfo;
1180 rwlock_init(&table->lock); 1181 rwlock_init(&table->lock);
1181 ret = down_interruptible(&ebt_mutex); 1182 ret = mutex_lock_interruptible(&ebt_mutex);
1182 if (ret != 0) 1183 if (ret != 0)
1183 goto free_chainstack; 1184 goto free_chainstack;
1184 1185
@@ -1194,10 +1195,10 @@ int ebt_register_table(struct ebt_table *table)
1194 goto free_unlock; 1195 goto free_unlock;
1195 } 1196 }
1196 list_prepend(&ebt_tables, table); 1197 list_prepend(&ebt_tables, table);
1197 up(&ebt_mutex); 1198 mutex_unlock(&ebt_mutex);
1198 return 0; 1199 return 0;
1199free_unlock: 1200free_unlock:
1200 up(&ebt_mutex); 1201 mutex_unlock(&ebt_mutex);
1201free_chainstack: 1202free_chainstack:
1202 if (newinfo->chainstack) { 1203 if (newinfo->chainstack) {
1203 for_each_cpu(i) 1204 for_each_cpu(i)
@@ -1218,9 +1219,9 @@ void ebt_unregister_table(struct ebt_table *table)
1218 BUGPRINT("Request to unregister NULL table!!!\n"); 1219 BUGPRINT("Request to unregister NULL table!!!\n");
1219 return; 1220 return;
1220 } 1221 }
1221 down(&ebt_mutex); 1222 mutex_lock(&ebt_mutex);
1222 LIST_DELETE(&ebt_tables, table); 1223 LIST_DELETE(&ebt_tables, table);
1223 up(&ebt_mutex); 1224 mutex_unlock(&ebt_mutex);
1224 vfree(table->private->entries); 1225 vfree(table->private->entries);
1225 if (table->private->chainstack) { 1226 if (table->private->chainstack) {
1226 for_each_cpu(i) 1227 for_each_cpu(i)
@@ -1281,7 +1282,7 @@ static int update_counters(void __user *user, unsigned int len)
1281 write_unlock_bh(&t->lock); 1282 write_unlock_bh(&t->lock);
1282 ret = 0; 1283 ret = 0;
1283unlock_mutex: 1284unlock_mutex:
1284 up(&ebt_mutex); 1285 mutex_unlock(&ebt_mutex);
1285free_tmp: 1286free_tmp:
1286 vfree(tmp); 1287 vfree(tmp);
1287 return ret; 1288 return ret;
@@ -1328,7 +1329,7 @@ static inline int ebt_make_names(struct ebt_entry *e, char *base, char *ubase)
1328 return 0; 1329 return 0;
1329} 1330}
1330 1331
1331/* called with ebt_mutex down */ 1332/* called with ebt_mutex locked */
1332static int copy_everything_to_user(struct ebt_table *t, void __user *user, 1333static int copy_everything_to_user(struct ebt_table *t, void __user *user,
1333 int *len, int cmd) 1334 int *len, int cmd)
1334{ 1335{
@@ -1440,7 +1441,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1440 case EBT_SO_GET_INIT_INFO: 1441 case EBT_SO_GET_INIT_INFO:
1441 if (*len != sizeof(struct ebt_replace)){ 1442 if (*len != sizeof(struct ebt_replace)){
1442 ret = -EINVAL; 1443 ret = -EINVAL;
1443 up(&ebt_mutex); 1444 mutex_unlock(&ebt_mutex);
1444 break; 1445 break;
1445 } 1446 }
1446 if (cmd == EBT_SO_GET_INFO) { 1447 if (cmd == EBT_SO_GET_INFO) {
@@ -1452,7 +1453,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1452 tmp.entries_size = t->table->entries_size; 1453 tmp.entries_size = t->table->entries_size;
1453 tmp.valid_hooks = t->table->valid_hooks; 1454 tmp.valid_hooks = t->table->valid_hooks;
1454 } 1455 }
1455 up(&ebt_mutex); 1456 mutex_unlock(&ebt_mutex);
1456 if (copy_to_user(user, &tmp, *len) != 0){ 1457 if (copy_to_user(user, &tmp, *len) != 0){
1457 BUGPRINT("c2u Didn't work\n"); 1458 BUGPRINT("c2u Didn't work\n");
1458 ret = -EFAULT; 1459 ret = -EFAULT;
@@ -1464,11 +1465,11 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1464 case EBT_SO_GET_ENTRIES: 1465 case EBT_SO_GET_ENTRIES:
1465 case EBT_SO_GET_INIT_ENTRIES: 1466 case EBT_SO_GET_INIT_ENTRIES:
1466 ret = copy_everything_to_user(t, user, len, cmd); 1467 ret = copy_everything_to_user(t, user, len, cmd);
1467 up(&ebt_mutex); 1468 mutex_unlock(&ebt_mutex);
1468 break; 1469 break;
1469 1470
1470 default: 1471 default:
1471 up(&ebt_mutex); 1472 mutex_unlock(&ebt_mutex);
1472 ret = -EINVAL; 1473 ret = -EINVAL;
1473 } 1474 }
1474 1475
@@ -1476,17 +1477,23 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1476} 1477}
1477 1478
1478static struct nf_sockopt_ops ebt_sockopts = 1479static struct nf_sockopt_ops ebt_sockopts =
1479{ { NULL, NULL }, PF_INET, EBT_BASE_CTL, EBT_SO_SET_MAX + 1, do_ebt_set_ctl, 1480{
1480 EBT_BASE_CTL, EBT_SO_GET_MAX + 1, do_ebt_get_ctl, 0, NULL 1481 .pf = PF_INET,
1482 .set_optmin = EBT_BASE_CTL,
1483 .set_optmax = EBT_SO_SET_MAX + 1,
1484 .set = do_ebt_set_ctl,
1485 .get_optmin = EBT_BASE_CTL,
1486 .get_optmax = EBT_SO_GET_MAX + 1,
1487 .get = do_ebt_get_ctl,
1481}; 1488};
1482 1489
1483static int __init init(void) 1490static int __init init(void)
1484{ 1491{
1485 int ret; 1492 int ret;
1486 1493
1487 down(&ebt_mutex); 1494 mutex_lock(&ebt_mutex);
1488 list_named_insert(&ebt_targets, &ebt_standard_target); 1495 list_named_insert(&ebt_targets, &ebt_standard_target);
1489 up(&ebt_mutex); 1496 mutex_unlock(&ebt_mutex);
1490 if ((ret = nf_register_sockopt(&ebt_sockopts)) < 0) 1497 if ((ret = nf_register_sockopt(&ebt_sockopts)) < 0)
1491 return ret; 1498 return ret;
1492 1499
diff --git a/net/compat.c b/net/compat.c
index e593dace2fdb..13177a1a4b39 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -416,7 +416,7 @@ struct compat_sock_fprog {
416 compat_uptr_t filter; /* struct sock_filter * */ 416 compat_uptr_t filter; /* struct sock_filter * */
417}; 417};
418 418
419static int do_set_attach_filter(int fd, int level, int optname, 419static int do_set_attach_filter(struct socket *sock, int level, int optname,
420 char __user *optval, int optlen) 420 char __user *optval, int optlen)
421{ 421{
422 struct compat_sock_fprog __user *fprog32 = (struct compat_sock_fprog __user *)optval; 422 struct compat_sock_fprog __user *fprog32 = (struct compat_sock_fprog __user *)optval;
@@ -432,11 +432,12 @@ static int do_set_attach_filter(int fd, int level, int optname,
432 __put_user(compat_ptr(ptr), &kfprog->filter)) 432 __put_user(compat_ptr(ptr), &kfprog->filter))
433 return -EFAULT; 433 return -EFAULT;
434 434
435 return sys_setsockopt(fd, level, optname, (char __user *)kfprog, 435 return sock_setsockopt(sock, level, optname, (char __user *)kfprog,
436 sizeof(struct sock_fprog)); 436 sizeof(struct sock_fprog));
437} 437}
438 438
439static int do_set_sock_timeout(int fd, int level, int optname, char __user *optval, int optlen) 439static int do_set_sock_timeout(struct socket *sock, int level,
440 int optname, char __user *optval, int optlen)
440{ 441{
441 struct compat_timeval __user *up = (struct compat_timeval __user *) optval; 442 struct compat_timeval __user *up = (struct compat_timeval __user *) optval;
442 struct timeval ktime; 443 struct timeval ktime;
@@ -451,30 +452,61 @@ static int do_set_sock_timeout(int fd, int level, int optname, char __user *optv
451 return -EFAULT; 452 return -EFAULT;
452 old_fs = get_fs(); 453 old_fs = get_fs();
453 set_fs(KERNEL_DS); 454 set_fs(KERNEL_DS);
454 err = sys_setsockopt(fd, level, optname, (char *) &ktime, sizeof(ktime)); 455 err = sock_setsockopt(sock, level, optname, (char *) &ktime, sizeof(ktime));
455 set_fs(old_fs); 456 set_fs(old_fs);
456 457
457 return err; 458 return err;
458} 459}
459 460
461static int compat_sock_setsockopt(struct socket *sock, int level, int optname,
462 char __user *optval, int optlen)
463{
464 if (optname == SO_ATTACH_FILTER)
465 return do_set_attach_filter(sock, level, optname,
466 optval, optlen);
467 if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
468 return do_set_sock_timeout(sock, level, optname, optval, optlen);
469
470 return sock_setsockopt(sock, level, optname, optval, optlen);
471}
472
460asmlinkage long compat_sys_setsockopt(int fd, int level, int optname, 473asmlinkage long compat_sys_setsockopt(int fd, int level, int optname,
461 char __user *optval, int optlen) 474 char __user *optval, int optlen)
462{ 475{
476 int err;
477 struct socket *sock;
478
463 /* SO_SET_REPLACE seems to be the same in all levels */ 479 /* SO_SET_REPLACE seems to be the same in all levels */
464 if (optname == IPT_SO_SET_REPLACE) 480 if (optname == IPT_SO_SET_REPLACE)
465 return do_netfilter_replace(fd, level, optname, 481 return do_netfilter_replace(fd, level, optname,
466 optval, optlen); 482 optval, optlen);
467 if (level == SOL_SOCKET && optname == SO_ATTACH_FILTER)
468 return do_set_attach_filter(fd, level, optname,
469 optval, optlen);
470 if (level == SOL_SOCKET &&
471 (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO))
472 return do_set_sock_timeout(fd, level, optname, optval, optlen);
473 483
474 return sys_setsockopt(fd, level, optname, optval, optlen); 484 if (optlen < 0)
485 return -EINVAL;
486
487 if ((sock = sockfd_lookup(fd, &err))!=NULL)
488 {
489 err = security_socket_setsockopt(sock,level,optname);
490 if (err) {
491 sockfd_put(sock);
492 return err;
493 }
494
495 if (level == SOL_SOCKET)
496 err = compat_sock_setsockopt(sock, level,
497 optname, optval, optlen);
498 else if (sock->ops->compat_setsockopt)
499 err = sock->ops->compat_setsockopt(sock, level,
500 optname, optval, optlen);
501 else
502 err = sock->ops->setsockopt(sock, level,
503 optname, optval, optlen);
504 sockfd_put(sock);
505 }
506 return err;
475} 507}
476 508
477static int do_get_sock_timeout(int fd, int level, int optname, 509static int do_get_sock_timeout(struct socket *sock, int level, int optname,
478 char __user *optval, int __user *optlen) 510 char __user *optval, int __user *optlen)
479{ 511{
480 struct compat_timeval __user *up; 512 struct compat_timeval __user *up;
@@ -490,7 +522,7 @@ static int do_get_sock_timeout(int fd, int level, int optname,
490 len = sizeof(ktime); 522 len = sizeof(ktime);
491 old_fs = get_fs(); 523 old_fs = get_fs();
492 set_fs(KERNEL_DS); 524 set_fs(KERNEL_DS);
493 err = sys_getsockopt(fd, level, optname, (char *) &ktime, &len); 525 err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
494 set_fs(old_fs); 526 set_fs(old_fs);
495 527
496 if (!err) { 528 if (!err) {
@@ -503,15 +535,42 @@ static int do_get_sock_timeout(int fd, int level, int optname,
503 return err; 535 return err;
504} 536}
505 537
506asmlinkage long compat_sys_getsockopt(int fd, int level, int optname, 538static int compat_sock_getsockopt(struct socket *sock, int level, int optname,
507 char __user *optval, int __user *optlen) 539 char __user *optval, int __user *optlen)
508{ 540{
509 if (level == SOL_SOCKET && 541 if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
510 (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)) 542 return do_get_sock_timeout(sock, level, optname, optval, optlen);
511 return do_get_sock_timeout(fd, level, optname, optval, optlen); 543 return sock_getsockopt(sock, level, optname, optval, optlen);
512 return sys_getsockopt(fd, level, optname, optval, optlen);
513} 544}
514 545
546asmlinkage long compat_sys_getsockopt(int fd, int level, int optname,
547 char __user *optval, int __user *optlen)
548{
549 int err;
550 struct socket *sock;
551
552 if ((sock = sockfd_lookup(fd, &err))!=NULL)
553 {
554 err = security_socket_getsockopt(sock, level,
555 optname);
556 if (err) {
557 sockfd_put(sock);
558 return err;
559 }
560
561 if (level == SOL_SOCKET)
562 err = compat_sock_getsockopt(sock, level,
563 optname, optval, optlen);
564 else if (sock->ops->compat_getsockopt)
565 err = sock->ops->compat_getsockopt(sock, level,
566 optname, optval, optlen);
567 else
568 err = sock->ops->getsockopt(sock, level,
569 optname, optval, optlen);
570 sockfd_put(sock);
571 }
572 return err;
573}
515/* Argument list sizes for compat_sys_socketcall */ 574/* Argument list sizes for compat_sys_socketcall */
516#define AL(x) ((x) * sizeof(u32)) 575#define AL(x) ((x) * sizeof(u32))
517static unsigned char nas[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), 576static unsigned char nas[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
diff --git a/net/core/dev.c b/net/core/dev.c
index ef56c035d44e..08dec6eb922b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -81,6 +81,7 @@
81#include <linux/types.h> 81#include <linux/types.h>
82#include <linux/kernel.h> 82#include <linux/kernel.h>
83#include <linux/sched.h> 83#include <linux/sched.h>
84#include <linux/mutex.h>
84#include <linux/string.h> 85#include <linux/string.h>
85#include <linux/mm.h> 86#include <linux/mm.h>
86#include <linux/socket.h> 87#include <linux/socket.h>
@@ -1759,8 +1760,7 @@ static void net_rx_action(struct softirq_action *h)
1759 if (dev->quota <= 0 || dev->poll(dev, &budget)) { 1760 if (dev->quota <= 0 || dev->poll(dev, &budget)) {
1760 netpoll_poll_unlock(have); 1761 netpoll_poll_unlock(have);
1761 local_irq_disable(); 1762 local_irq_disable();
1762 list_del(&dev->poll_list); 1763 list_move_tail(&dev->poll_list, &queue->poll_list);
1763 list_add_tail(&dev->poll_list, &queue->poll_list);
1764 if (dev->quota < 0) 1764 if (dev->quota < 0)
1765 dev->quota += dev->weight; 1765 dev->quota += dev->weight;
1766 else 1766 else
@@ -2174,12 +2174,20 @@ unsigned dev_get_flags(const struct net_device *dev)
2174 2174
2175 flags = (dev->flags & ~(IFF_PROMISC | 2175 flags = (dev->flags & ~(IFF_PROMISC |
2176 IFF_ALLMULTI | 2176 IFF_ALLMULTI |
2177 IFF_RUNNING)) | 2177 IFF_RUNNING |
2178 IFF_LOWER_UP |
2179 IFF_DORMANT)) |
2178 (dev->gflags & (IFF_PROMISC | 2180 (dev->gflags & (IFF_PROMISC |
2179 IFF_ALLMULTI)); 2181 IFF_ALLMULTI));
2180 2182
2181 if (netif_running(dev) && netif_carrier_ok(dev)) 2183 if (netif_running(dev)) {
2182 flags |= IFF_RUNNING; 2184 if (netif_oper_up(dev))
2185 flags |= IFF_RUNNING;
2186 if (netif_carrier_ok(dev))
2187 flags |= IFF_LOWER_UP;
2188 if (netif_dormant(dev))
2189 flags |= IFF_DORMANT;
2190 }
2183 2191
2184 return flags; 2192 return flags;
2185} 2193}
@@ -2458,9 +2466,9 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
2458 */ 2466 */
2459 2467
2460 if (cmd == SIOCGIFCONF) { 2468 if (cmd == SIOCGIFCONF) {
2461 rtnl_shlock(); 2469 rtnl_lock();
2462 ret = dev_ifconf((char __user *) arg); 2470 ret = dev_ifconf((char __user *) arg);
2463 rtnl_shunlock(); 2471 rtnl_unlock();
2464 return ret; 2472 return ret;
2465 } 2473 }
2466 if (cmd == SIOCGIFNAME) 2474 if (cmd == SIOCGIFNAME)
@@ -2869,7 +2877,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
2869 rebroadcast_time = warning_time = jiffies; 2877 rebroadcast_time = warning_time = jiffies;
2870 while (atomic_read(&dev->refcnt) != 0) { 2878 while (atomic_read(&dev->refcnt) != 0) {
2871 if (time_after(jiffies, rebroadcast_time + 1 * HZ)) { 2879 if (time_after(jiffies, rebroadcast_time + 1 * HZ)) {
2872 rtnl_shlock(); 2880 rtnl_lock();
2873 2881
2874 /* Rebroadcast unregister notification */ 2882 /* Rebroadcast unregister notification */
2875 notifier_call_chain(&netdev_chain, 2883 notifier_call_chain(&netdev_chain,
@@ -2886,7 +2894,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
2886 linkwatch_run_queue(); 2894 linkwatch_run_queue();
2887 } 2895 }
2888 2896
2889 rtnl_shunlock(); 2897 __rtnl_unlock();
2890 2898
2891 rebroadcast_time = jiffies; 2899 rebroadcast_time = jiffies;
2892 } 2900 }
@@ -2924,7 +2932,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
2924 * 2) Since we run with the RTNL semaphore not held, we can sleep 2932 * 2) Since we run with the RTNL semaphore not held, we can sleep
2925 * safely in order to wait for the netdev refcnt to drop to zero. 2933 * safely in order to wait for the netdev refcnt to drop to zero.
2926 */ 2934 */
2927static DECLARE_MUTEX(net_todo_run_mutex); 2935static DEFINE_MUTEX(net_todo_run_mutex);
2928void netdev_run_todo(void) 2936void netdev_run_todo(void)
2929{ 2937{
2930 struct list_head list = LIST_HEAD_INIT(list); 2938 struct list_head list = LIST_HEAD_INIT(list);
@@ -2932,7 +2940,7 @@ void netdev_run_todo(void)
2932 2940
2933 2941
2934 /* Need to guard against multiple cpu's getting out of order. */ 2942 /* Need to guard against multiple cpu's getting out of order. */
2935 down(&net_todo_run_mutex); 2943 mutex_lock(&net_todo_run_mutex);
2936 2944
2937 /* Not safe to do outside the semaphore. We must not return 2945 /* Not safe to do outside the semaphore. We must not return
2938 * until all unregister events invoked by the local processor 2946 * until all unregister events invoked by the local processor
@@ -2989,7 +2997,7 @@ void netdev_run_todo(void)
2989 } 2997 }
2990 2998
2991out: 2999out:
2992 up(&net_todo_run_mutex); 3000 mutex_unlock(&net_todo_run_mutex);
2993} 3001}
2994 3002
2995/** 3003/**
diff --git a/net/core/flow.c b/net/core/flow.c
index c4f25385029f..55789f832eda 100644
--- a/net/core/flow.c
+++ b/net/core/flow.c
@@ -20,6 +20,7 @@
20#include <linux/notifier.h> 20#include <linux/notifier.h>
21#include <linux/cpu.h> 21#include <linux/cpu.h>
22#include <linux/cpumask.h> 22#include <linux/cpumask.h>
23#include <linux/mutex.h>
23#include <net/flow.h> 24#include <net/flow.h>
24#include <asm/atomic.h> 25#include <asm/atomic.h>
25#include <asm/semaphore.h> 26#include <asm/semaphore.h>
@@ -287,11 +288,11 @@ static void flow_cache_flush_per_cpu(void *data)
287void flow_cache_flush(void) 288void flow_cache_flush(void)
288{ 289{
289 struct flow_flush_info info; 290 struct flow_flush_info info;
290 static DECLARE_MUTEX(flow_flush_sem); 291 static DEFINE_MUTEX(flow_flush_sem);
291 292
292 /* Don't want cpus going down or up during this. */ 293 /* Don't want cpus going down or up during this. */
293 lock_cpu_hotplug(); 294 lock_cpu_hotplug();
294 down(&flow_flush_sem); 295 mutex_lock(&flow_flush_sem);
295 atomic_set(&info.cpuleft, num_online_cpus()); 296 atomic_set(&info.cpuleft, num_online_cpus());
296 init_completion(&info.completion); 297 init_completion(&info.completion);
297 298
@@ -301,7 +302,7 @@ void flow_cache_flush(void)
301 local_bh_enable(); 302 local_bh_enable();
302 303
303 wait_for_completion(&info.completion); 304 wait_for_completion(&info.completion);
304 up(&flow_flush_sem); 305 mutex_unlock(&flow_flush_sem);
305 unlock_cpu_hotplug(); 306 unlock_cpu_hotplug();
306} 307}
307 308
diff --git a/net/core/link_watch.c b/net/core/link_watch.c
index d43d1201275c..341de44c7ed1 100644
--- a/net/core/link_watch.c
+++ b/net/core/link_watch.c
@@ -49,6 +49,45 @@ struct lw_event {
49/* Avoid kmalloc() for most systems */ 49/* Avoid kmalloc() for most systems */
50static struct lw_event singleevent; 50static struct lw_event singleevent;
51 51
52static unsigned char default_operstate(const struct net_device *dev)
53{
54 if (!netif_carrier_ok(dev))
55 return (dev->ifindex != dev->iflink ?
56 IF_OPER_LOWERLAYERDOWN : IF_OPER_DOWN);
57
58 if (netif_dormant(dev))
59 return IF_OPER_DORMANT;
60
61 return IF_OPER_UP;
62}
63
64
65static void rfc2863_policy(struct net_device *dev)
66{
67 unsigned char operstate = default_operstate(dev);
68
69 if (operstate == dev->operstate)
70 return;
71
72 write_lock_bh(&dev_base_lock);
73
74 switch(dev->link_mode) {
75 case IF_LINK_MODE_DORMANT:
76 if (operstate == IF_OPER_UP)
77 operstate = IF_OPER_DORMANT;
78 break;
79
80 case IF_LINK_MODE_DEFAULT:
81 default:
82 break;
83 };
84
85 dev->operstate = operstate;
86
87 write_unlock_bh(&dev_base_lock);
88}
89
90
52/* Must be called with the rtnl semaphore held */ 91/* Must be called with the rtnl semaphore held */
53void linkwatch_run_queue(void) 92void linkwatch_run_queue(void)
54{ 93{
@@ -74,6 +113,7 @@ void linkwatch_run_queue(void)
74 */ 113 */
75 clear_bit(__LINK_STATE_LINKWATCH_PENDING, &dev->state); 114 clear_bit(__LINK_STATE_LINKWATCH_PENDING, &dev->state);
76 115
116 rfc2863_policy(dev);
77 if (dev->flags & IFF_UP) { 117 if (dev->flags & IFF_UP) {
78 if (netif_carrier_ok(dev)) { 118 if (netif_carrier_ok(dev)) {
79 WARN_ON(dev->qdisc_sleeping == &noop_qdisc); 119 WARN_ON(dev->qdisc_sleeping == &noop_qdisc);
@@ -99,9 +139,9 @@ static void linkwatch_event(void *dummy)
99 linkwatch_nextevent = jiffies + HZ; 139 linkwatch_nextevent = jiffies + HZ;
100 clear_bit(LW_RUNNING, &linkwatch_flags); 140 clear_bit(LW_RUNNING, &linkwatch_flags);
101 141
102 rtnl_shlock(); 142 rtnl_lock();
103 linkwatch_run_queue(); 143 linkwatch_run_queue();
104 rtnl_shunlock(); 144 rtnl_unlock();
105} 145}
106 146
107 147
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index e68700f950a5..0c8666872d10 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -586,8 +586,8 @@ void neigh_destroy(struct neighbour *neigh)
586 kfree(hh); 586 kfree(hh);
587 } 587 }
588 588
589 if (neigh->ops && neigh->ops->destructor) 589 if (neigh->parms->neigh_destructor)
590 (neigh->ops->destructor)(neigh); 590 (neigh->parms->neigh_destructor)(neigh);
591 591
592 skb_queue_purge(&neigh->arp_queue); 592 skb_queue_purge(&neigh->arp_queue);
593 593
@@ -750,11 +750,13 @@ static void neigh_timer_handler(unsigned long arg)
750 neigh->used + neigh->parms->delay_probe_time)) { 750 neigh->used + neigh->parms->delay_probe_time)) {
751 NEIGH_PRINTK2("neigh %p is delayed.\n", neigh); 751 NEIGH_PRINTK2("neigh %p is delayed.\n", neigh);
752 neigh->nud_state = NUD_DELAY; 752 neigh->nud_state = NUD_DELAY;
753 neigh->updated = jiffies;
753 neigh_suspect(neigh); 754 neigh_suspect(neigh);
754 next = now + neigh->parms->delay_probe_time; 755 next = now + neigh->parms->delay_probe_time;
755 } else { 756 } else {
756 NEIGH_PRINTK2("neigh %p is suspected.\n", neigh); 757 NEIGH_PRINTK2("neigh %p is suspected.\n", neigh);
757 neigh->nud_state = NUD_STALE; 758 neigh->nud_state = NUD_STALE;
759 neigh->updated = jiffies;
758 neigh_suspect(neigh); 760 neigh_suspect(neigh);
759 } 761 }
760 } else if (state & NUD_DELAY) { 762 } else if (state & NUD_DELAY) {
@@ -762,11 +764,13 @@ static void neigh_timer_handler(unsigned long arg)
762 neigh->confirmed + neigh->parms->delay_probe_time)) { 764 neigh->confirmed + neigh->parms->delay_probe_time)) {
763 NEIGH_PRINTK2("neigh %p is now reachable.\n", neigh); 765 NEIGH_PRINTK2("neigh %p is now reachable.\n", neigh);
764 neigh->nud_state = NUD_REACHABLE; 766 neigh->nud_state = NUD_REACHABLE;
767 neigh->updated = jiffies;
765 neigh_connect(neigh); 768 neigh_connect(neigh);
766 next = neigh->confirmed + neigh->parms->reachable_time; 769 next = neigh->confirmed + neigh->parms->reachable_time;
767 } else { 770 } else {
768 NEIGH_PRINTK2("neigh %p is probed.\n", neigh); 771 NEIGH_PRINTK2("neigh %p is probed.\n", neigh);
769 neigh->nud_state = NUD_PROBE; 772 neigh->nud_state = NUD_PROBE;
773 neigh->updated = jiffies;
770 atomic_set(&neigh->probes, 0); 774 atomic_set(&neigh->probes, 0);
771 next = now + neigh->parms->retrans_time; 775 next = now + neigh->parms->retrans_time;
772 } 776 }
@@ -780,6 +784,7 @@ static void neigh_timer_handler(unsigned long arg)
780 struct sk_buff *skb; 784 struct sk_buff *skb;
781 785
782 neigh->nud_state = NUD_FAILED; 786 neigh->nud_state = NUD_FAILED;
787 neigh->updated = jiffies;
783 notify = 1; 788 notify = 1;
784 NEIGH_CACHE_STAT_INC(neigh->tbl, res_failed); 789 NEIGH_CACHE_STAT_INC(neigh->tbl, res_failed);
785 NEIGH_PRINTK2("neigh %p is failed.\n", neigh); 790 NEIGH_PRINTK2("neigh %p is failed.\n", neigh);
@@ -843,10 +848,12 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
843 if (neigh->parms->mcast_probes + neigh->parms->app_probes) { 848 if (neigh->parms->mcast_probes + neigh->parms->app_probes) {
844 atomic_set(&neigh->probes, neigh->parms->ucast_probes); 849 atomic_set(&neigh->probes, neigh->parms->ucast_probes);
845 neigh->nud_state = NUD_INCOMPLETE; 850 neigh->nud_state = NUD_INCOMPLETE;
851 neigh->updated = jiffies;
846 neigh_hold(neigh); 852 neigh_hold(neigh);
847 neigh_add_timer(neigh, now + 1); 853 neigh_add_timer(neigh, now + 1);
848 } else { 854 } else {
849 neigh->nud_state = NUD_FAILED; 855 neigh->nud_state = NUD_FAILED;
856 neigh->updated = jiffies;
850 write_unlock_bh(&neigh->lock); 857 write_unlock_bh(&neigh->lock);
851 858
852 if (skb) 859 if (skb)
@@ -857,6 +864,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
857 NEIGH_PRINTK2("neigh %p is delayed.\n", neigh); 864 NEIGH_PRINTK2("neigh %p is delayed.\n", neigh);
858 neigh_hold(neigh); 865 neigh_hold(neigh);
859 neigh->nud_state = NUD_DELAY; 866 neigh->nud_state = NUD_DELAY;
867 neigh->updated = jiffies;
860 neigh_add_timer(neigh, 868 neigh_add_timer(neigh,
861 jiffies + neigh->parms->delay_probe_time); 869 jiffies + neigh->parms->delay_probe_time);
862 } 870 }
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index e8b2acbc8ea2..21b68464cabb 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -91,6 +91,7 @@ NETDEVICE_SHOW(iflink, fmt_dec);
91NETDEVICE_SHOW(ifindex, fmt_dec); 91NETDEVICE_SHOW(ifindex, fmt_dec);
92NETDEVICE_SHOW(features, fmt_long_hex); 92NETDEVICE_SHOW(features, fmt_long_hex);
93NETDEVICE_SHOW(type, fmt_dec); 93NETDEVICE_SHOW(type, fmt_dec);
94NETDEVICE_SHOW(link_mode, fmt_dec);
94 95
95/* use same locking rules as GIFHWADDR ioctl's */ 96/* use same locking rules as GIFHWADDR ioctl's */
96static ssize_t format_addr(char *buf, const unsigned char *addr, int len) 97static ssize_t format_addr(char *buf, const unsigned char *addr, int len)
@@ -133,6 +134,43 @@ static ssize_t show_carrier(struct class_device *dev, char *buf)
133 return -EINVAL; 134 return -EINVAL;
134} 135}
135 136
137static ssize_t show_dormant(struct class_device *dev, char *buf)
138{
139 struct net_device *netdev = to_net_dev(dev);
140
141 if (netif_running(netdev))
142 return sprintf(buf, fmt_dec, !!netif_dormant(netdev));
143
144 return -EINVAL;
145}
146
147static const char *operstates[] = {
148 "unknown",
149 "notpresent", /* currently unused */
150 "down",
151 "lowerlayerdown",
152 "testing", /* currently unused */
153 "dormant",
154 "up"
155};
156
157static ssize_t show_operstate(struct class_device *dev, char *buf)
158{
159 const struct net_device *netdev = to_net_dev(dev);
160 unsigned char operstate;
161
162 read_lock(&dev_base_lock);
163 operstate = netdev->operstate;
164 if (!netif_running(netdev))
165 operstate = IF_OPER_DOWN;
166 read_unlock(&dev_base_lock);
167
168 if (operstate >= sizeof(operstates))
169 return -EINVAL; /* should not happen */
170
171 return sprintf(buf, "%s\n", operstates[operstate]);
172}
173
136/* read-write attributes */ 174/* read-write attributes */
137NETDEVICE_SHOW(mtu, fmt_dec); 175NETDEVICE_SHOW(mtu, fmt_dec);
138 176
@@ -190,9 +228,12 @@ static struct class_device_attribute net_class_attributes[] = {
190 __ATTR(ifindex, S_IRUGO, show_ifindex, NULL), 228 __ATTR(ifindex, S_IRUGO, show_ifindex, NULL),
191 __ATTR(features, S_IRUGO, show_features, NULL), 229 __ATTR(features, S_IRUGO, show_features, NULL),
192 __ATTR(type, S_IRUGO, show_type, NULL), 230 __ATTR(type, S_IRUGO, show_type, NULL),
231 __ATTR(link_mode, S_IRUGO, show_link_mode, NULL),
193 __ATTR(address, S_IRUGO, show_address, NULL), 232 __ATTR(address, S_IRUGO, show_address, NULL),
194 __ATTR(broadcast, S_IRUGO, show_broadcast, NULL), 233 __ATTR(broadcast, S_IRUGO, show_broadcast, NULL),
195 __ATTR(carrier, S_IRUGO, show_carrier, NULL), 234 __ATTR(carrier, S_IRUGO, show_carrier, NULL),
235 __ATTR(dormant, S_IRUGO, show_dormant, NULL),
236 __ATTR(operstate, S_IRUGO, show_operstate, NULL),
196 __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu), 237 __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu),
197 __ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags), 238 __ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags),
198 __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len, 239 __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index ea51f8d02eb8..e8e05cebd95a 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -669,14 +669,14 @@ int netpoll_setup(struct netpoll *np)
669 printk(KERN_INFO "%s: device %s not up yet, forcing it\n", 669 printk(KERN_INFO "%s: device %s not up yet, forcing it\n",
670 np->name, np->dev_name); 670 np->name, np->dev_name);
671 671
672 rtnl_shlock(); 672 rtnl_lock();
673 if (dev_change_flags(ndev, ndev->flags | IFF_UP) < 0) { 673 if (dev_change_flags(ndev, ndev->flags | IFF_UP) < 0) {
674 printk(KERN_ERR "%s: failed to open %s\n", 674 printk(KERN_ERR "%s: failed to open %s\n",
675 np->name, np->dev_name); 675 np->name, np->dev_name);
676 rtnl_shunlock(); 676 rtnl_unlock();
677 goto release; 677 goto release;
678 } 678 }
679 rtnl_shunlock(); 679 rtnl_unlock();
680 680
681 atleast = jiffies + HZ/10; 681 atleast = jiffies + HZ/10;
682 atmost = jiffies + 4*HZ; 682 atmost = jiffies + 4*HZ;
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index da16f8fd1494..8eedaedba743 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -113,6 +113,7 @@
113#include <linux/moduleparam.h> 113#include <linux/moduleparam.h>
114#include <linux/kernel.h> 114#include <linux/kernel.h>
115#include <linux/smp_lock.h> 115#include <linux/smp_lock.h>
116#include <linux/mutex.h>
116#include <linux/sched.h> 117#include <linux/sched.h>
117#include <linux/slab.h> 118#include <linux/slab.h>
118#include <linux/vmalloc.h> 119#include <linux/vmalloc.h>
@@ -125,6 +126,7 @@
125#include <linux/capability.h> 126#include <linux/capability.h>
126#include <linux/delay.h> 127#include <linux/delay.h>
127#include <linux/timer.h> 128#include <linux/timer.h>
129#include <linux/list.h>
128#include <linux/init.h> 130#include <linux/init.h>
129#include <linux/skbuff.h> 131#include <linux/skbuff.h>
130#include <linux/netdevice.h> 132#include <linux/netdevice.h>
@@ -149,38 +151,34 @@
149#include <asm/io.h> 151#include <asm/io.h>
150#include <asm/dma.h> 152#include <asm/dma.h>
151#include <asm/uaccess.h> 153#include <asm/uaccess.h>
152#include <asm/div64.h> /* do_div */ 154#include <asm/div64.h> /* do_div */
153#include <asm/timex.h> 155#include <asm/timex.h>
154 156
155 157#define VERSION "pktgen v2.66: Packet Generator for packet performance testing.\n"
156#define VERSION "pktgen v2.63: Packet Generator for packet performance testing.\n"
157 158
158/* #define PG_DEBUG(a) a */ 159/* #define PG_DEBUG(a) a */
159#define PG_DEBUG(a) 160#define PG_DEBUG(a)
160 161
161/* The buckets are exponential in 'width' */ 162/* The buckets are exponential in 'width' */
162#define LAT_BUCKETS_MAX 32 163#define LAT_BUCKETS_MAX 32
163#define IP_NAME_SZ 32 164#define IP_NAME_SZ 32
164 165
165/* Device flag bits */ 166/* Device flag bits */
166#define F_IPSRC_RND (1<<0) /* IP-Src Random */ 167#define F_IPSRC_RND (1<<0) /* IP-Src Random */
167#define F_IPDST_RND (1<<1) /* IP-Dst Random */ 168#define F_IPDST_RND (1<<1) /* IP-Dst Random */
168#define F_UDPSRC_RND (1<<2) /* UDP-Src Random */ 169#define F_UDPSRC_RND (1<<2) /* UDP-Src Random */
169#define F_UDPDST_RND (1<<3) /* UDP-Dst Random */ 170#define F_UDPDST_RND (1<<3) /* UDP-Dst Random */
170#define F_MACSRC_RND (1<<4) /* MAC-Src Random */ 171#define F_MACSRC_RND (1<<4) /* MAC-Src Random */
171#define F_MACDST_RND (1<<5) /* MAC-Dst Random */ 172#define F_MACDST_RND (1<<5) /* MAC-Dst Random */
172#define F_TXSIZE_RND (1<<6) /* Transmit size is random */ 173#define F_TXSIZE_RND (1<<6) /* Transmit size is random */
173#define F_IPV6 (1<<7) /* Interface in IPV6 Mode */ 174#define F_IPV6 (1<<7) /* Interface in IPV6 Mode */
174 175
175/* Thread control flag bits */ 176/* Thread control flag bits */
176#define T_TERMINATE (1<<0) 177#define T_TERMINATE (1<<0)
177#define T_STOP (1<<1) /* Stop run */ 178#define T_STOP (1<<1) /* Stop run */
178#define T_RUN (1<<2) /* Start run */ 179#define T_RUN (1<<2) /* Start run */
179#define T_REMDEV (1<<3) /* Remove all devs */ 180#define T_REMDEVALL (1<<3) /* Remove all devs */
180 181#define T_REMDEV (1<<4) /* Remove one dev */
181/* Locks */
182#define thread_lock() down(&pktgen_sem)
183#define thread_unlock() up(&pktgen_sem)
184 182
185/* If lock -- can be removed after some work */ 183/* If lock -- can be removed after some work */
186#define if_lock(t) spin_lock(&(t->if_lock)); 184#define if_lock(t) spin_lock(&(t->if_lock));
@@ -194,10 +192,9 @@ static struct proc_dir_entry *pg_proc_dir = NULL;
194 192
195#define MAX_CFLOWS 65536 193#define MAX_CFLOWS 65536
196 194
197struct flow_state 195struct flow_state {
198{ 196 __u32 cur_daddr;
199 __u32 cur_daddr; 197 int count;
200 int count;
201}; 198};
202 199
203struct pktgen_dev { 200struct pktgen_dev {
@@ -206,141 +203,144 @@ struct pktgen_dev {
206 * Try to keep frequent/infrequent used vars. separated. 203 * Try to keep frequent/infrequent used vars. separated.
207 */ 204 */
208 205
209 char ifname[IFNAMSIZ]; 206 char ifname[IFNAMSIZ];
210 char result[512]; 207 char result[512];
211 208
212 struct pktgen_thread* pg_thread; /* the owner */ 209 struct pktgen_thread *pg_thread; /* the owner */
213 struct pktgen_dev *next; /* Used for chaining in the thread's run-queue */ 210 struct list_head list; /* Used for chaining in the thread's run-queue */
214 211
215 int running; /* if this changes to false, the test will stop */ 212 int running; /* if this changes to false, the test will stop */
216 213
217 /* If min != max, then we will either do a linear iteration, or 214 /* If min != max, then we will either do a linear iteration, or
218 * we will do a random selection from within the range. 215 * we will do a random selection from within the range.
219 */ 216 */
220 __u32 flags; 217 __u32 flags;
221 218 int removal_mark; /* non-zero => the device is marked for
222 int min_pkt_size; /* = ETH_ZLEN; */ 219 * removal by worker thread */
223 int max_pkt_size; /* = ETH_ZLEN; */ 220
224 int nfrags; 221 int min_pkt_size; /* = ETH_ZLEN; */
225 __u32 delay_us; /* Default delay */ 222 int max_pkt_size; /* = ETH_ZLEN; */
226 __u32 delay_ns; 223 int nfrags;
227 __u64 count; /* Default No packets to send */ 224 __u32 delay_us; /* Default delay */
228 __u64 sofar; /* How many pkts we've sent so far */ 225 __u32 delay_ns;
229 __u64 tx_bytes; /* How many bytes we've transmitted */ 226 __u64 count; /* Default No packets to send */
230 __u64 errors; /* Errors when trying to transmit, pkts will be re-sent */ 227 __u64 sofar; /* How many pkts we've sent so far */
231 228 __u64 tx_bytes; /* How many bytes we've transmitted */
232 /* runtime counters relating to clone_skb */ 229 __u64 errors; /* Errors when trying to transmit, pkts will be re-sent */
233 __u64 next_tx_us; /* timestamp of when to tx next */ 230
234 __u32 next_tx_ns; 231 /* runtime counters relating to clone_skb */
235 232 __u64 next_tx_us; /* timestamp of when to tx next */
236 __u64 allocated_skbs; 233 __u32 next_tx_ns;
237 __u32 clone_count; 234
238 int last_ok; /* Was last skb sent? 235 __u64 allocated_skbs;
239 * Or a failed transmit of some sort? This will keep 236 __u32 clone_count;
240 * sequence numbers in order, for example. 237 int last_ok; /* Was last skb sent?
241 */ 238 * Or a failed transmit of some sort? This will keep
242 __u64 started_at; /* micro-seconds */ 239 * sequence numbers in order, for example.
243 __u64 stopped_at; /* micro-seconds */ 240 */
244 __u64 idle_acc; /* micro-seconds */ 241 __u64 started_at; /* micro-seconds */
245 __u32 seq_num; 242 __u64 stopped_at; /* micro-seconds */
246 243 __u64 idle_acc; /* micro-seconds */
247 int clone_skb; /* Use multiple SKBs during packet gen. If this number 244 __u32 seq_num;
248 * is greater than 1, then that many copies of the same 245
249 * packet will be sent before a new packet is allocated. 246 int clone_skb; /* Use multiple SKBs during packet gen. If this number
250 * For instance, if you want to send 1024 identical packets 247 * is greater than 1, then that many copies of the same
251 * before creating a new packet, set clone_skb to 1024. 248 * packet will be sent before a new packet is allocated.
252 */ 249 * For instance, if you want to send 1024 identical packets
253 250 * before creating a new packet, set clone_skb to 1024.
254 char dst_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ 251 */
255 char dst_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ 252
256 char src_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ 253 char dst_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
257 char src_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ 254 char dst_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
258 255 char src_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
259 struct in6_addr in6_saddr; 256 char src_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
260 struct in6_addr in6_daddr; 257
261 struct in6_addr cur_in6_daddr; 258 struct in6_addr in6_saddr;
262 struct in6_addr cur_in6_saddr; 259 struct in6_addr in6_daddr;
260 struct in6_addr cur_in6_daddr;
261 struct in6_addr cur_in6_saddr;
263 /* For ranges */ 262 /* For ranges */
264 struct in6_addr min_in6_daddr; 263 struct in6_addr min_in6_daddr;
265 struct in6_addr max_in6_daddr; 264 struct in6_addr max_in6_daddr;
266 struct in6_addr min_in6_saddr; 265 struct in6_addr min_in6_saddr;
267 struct in6_addr max_in6_saddr; 266 struct in6_addr max_in6_saddr;
268 267
269 /* If we're doing ranges, random or incremental, then this 268 /* If we're doing ranges, random or incremental, then this
270 * defines the min/max for those ranges. 269 * defines the min/max for those ranges.
271 */ 270 */
272 __u32 saddr_min; /* inclusive, source IP address */ 271 __u32 saddr_min; /* inclusive, source IP address */
273 __u32 saddr_max; /* exclusive, source IP address */ 272 __u32 saddr_max; /* exclusive, source IP address */
274 __u32 daddr_min; /* inclusive, dest IP address */ 273 __u32 daddr_min; /* inclusive, dest IP address */
275 __u32 daddr_max; /* exclusive, dest IP address */ 274 __u32 daddr_max; /* exclusive, dest IP address */
276 275
277 __u16 udp_src_min; /* inclusive, source UDP port */ 276 __u16 udp_src_min; /* inclusive, source UDP port */
278 __u16 udp_src_max; /* exclusive, source UDP port */ 277 __u16 udp_src_max; /* exclusive, source UDP port */
279 __u16 udp_dst_min; /* inclusive, dest UDP port */ 278 __u16 udp_dst_min; /* inclusive, dest UDP port */
280 __u16 udp_dst_max; /* exclusive, dest UDP port */ 279 __u16 udp_dst_max; /* exclusive, dest UDP port */
281 280
282 __u32 src_mac_count; /* How many MACs to iterate through */ 281 __u32 src_mac_count; /* How many MACs to iterate through */
283 __u32 dst_mac_count; /* How many MACs to iterate through */ 282 __u32 dst_mac_count; /* How many MACs to iterate through */
284 283
285 unsigned char dst_mac[ETH_ALEN]; 284 unsigned char dst_mac[ETH_ALEN];
286 unsigned char src_mac[ETH_ALEN]; 285 unsigned char src_mac[ETH_ALEN];
287 286
288 __u32 cur_dst_mac_offset; 287 __u32 cur_dst_mac_offset;
289 __u32 cur_src_mac_offset; 288 __u32 cur_src_mac_offset;
290 __u32 cur_saddr; 289 __u32 cur_saddr;
291 __u32 cur_daddr; 290 __u32 cur_daddr;
292 __u16 cur_udp_dst; 291 __u16 cur_udp_dst;
293 __u16 cur_udp_src; 292 __u16 cur_udp_src;
294 __u32 cur_pkt_size; 293 __u32 cur_pkt_size;
295 294
296 __u8 hh[14]; 295 __u8 hh[14];
297 /* = { 296 /* = {
298 0x00, 0x80, 0xC8, 0x79, 0xB3, 0xCB, 297 0x00, 0x80, 0xC8, 0x79, 0xB3, 0xCB,
299 298
300 We fill in SRC address later 299 We fill in SRC address later
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
302 0x08, 0x00 301 0x08, 0x00
303 }; 302 };
304 */ 303 */
305 __u16 pad; /* pad out the hh struct to an even 16 bytes */ 304 __u16 pad; /* pad out the hh struct to an even 16 bytes */
306 305
307 struct sk_buff* skb; /* skb we are to transmit next, mainly used for when we 306 struct sk_buff *skb; /* skb we are to transmit next, mainly used for when we
308 * are transmitting the same one multiple times 307 * are transmitting the same one multiple times
309 */ 308 */
310 struct net_device* odev; /* The out-going device. Note that the device should 309 struct net_device *odev; /* The out-going device. Note that the device should
311 * have it's pg_info pointer pointing back to this 310 * have it's pg_info pointer pointing back to this
312 * device. This will be set when the user specifies 311 * device. This will be set when the user specifies
313 * the out-going device name (not when the inject is 312 * the out-going device name (not when the inject is
314 * started as it used to do.) 313 * started as it used to do.)
315 */ 314 */
316 struct flow_state *flows; 315 struct flow_state *flows;
317 unsigned cflows; /* Concurrent flows (config) */ 316 unsigned cflows; /* Concurrent flows (config) */
318 unsigned lflow; /* Flow length (config) */ 317 unsigned lflow; /* Flow length (config) */
319 unsigned nflows; /* accumulated flows (stats) */ 318 unsigned nflows; /* accumulated flows (stats) */
320}; 319};
321 320
322struct pktgen_hdr { 321struct pktgen_hdr {
323 __u32 pgh_magic; 322 __u32 pgh_magic;
324 __u32 seq_num; 323 __u32 seq_num;
325 __u32 tv_sec; 324 __u32 tv_sec;
326 __u32 tv_usec; 325 __u32 tv_usec;
327}; 326};
328 327
329struct pktgen_thread { 328struct pktgen_thread {
330 spinlock_t if_lock; 329 spinlock_t if_lock;
331 struct pktgen_dev *if_list; /* All device here */ 330 struct list_head if_list; /* All device here */
332 struct pktgen_thread* next; 331 struct list_head th_list;
333 char name[32]; 332 int removed;
334 char result[512]; 333 char name[32];
335 u32 max_before_softirq; /* We'll call do_softirq to prevent starvation. */ 334 char result[512];
336 335 u32 max_before_softirq; /* We'll call do_softirq to prevent starvation. */
337 /* Field for thread to receive "posted" events terminate, stop ifs etc.*/ 336
338 337 /* Field for thread to receive "posted" events terminate, stop ifs etc. */
339 u32 control; 338
339 u32 control;
340 int pid; 340 int pid;
341 int cpu; 341 int cpu;
342 342
343 wait_queue_head_t queue; 343 wait_queue_head_t queue;
344}; 344};
345 345
346#define REMOVE 1 346#define REMOVE 1
@@ -364,77 +364,76 @@ struct pktgen_thread {
364 */ 364 */
365static inline s64 divremdi3(s64 x, s64 y, int type) 365static inline s64 divremdi3(s64 x, s64 y, int type)
366{ 366{
367 u64 a = (x < 0) ? -x : x; 367 u64 a = (x < 0) ? -x : x;
368 u64 b = (y < 0) ? -y : y; 368 u64 b = (y < 0) ? -y : y;
369 u64 res = 0, d = 1; 369 u64 res = 0, d = 1;
370 370
371 if (b > 0) { 371 if (b > 0) {
372 while (b < a) { 372 while (b < a) {
373 b <<= 1; 373 b <<= 1;
374 d <<= 1; 374 d <<= 1;
375 } 375 }
376 } 376 }
377 377
378 do { 378 do {
379 if ( a >= b ) { 379 if (a >= b) {
380 a -= b; 380 a -= b;
381 res += d; 381 res += d;
382 } 382 }
383 b >>= 1; 383 b >>= 1;
384 d >>= 1; 384 d >>= 1;
385 } 385 }
386 while (d); 386 while (d);
387 387
388 if (PG_DIV == type) { 388 if (PG_DIV == type) {
389 return (((x ^ y) & (1ll<<63)) == 0) ? res : -(s64)res; 389 return (((x ^ y) & (1ll << 63)) == 0) ? res : -(s64) res;
390 } 390 } else {
391 else { 391 return ((x & (1ll << 63)) == 0) ? a : -(s64) a;
392 return ((x & (1ll<<63)) == 0) ? a : -(s64)a; 392 }
393 }
394} 393}
395 394
396/* End of hacks to deal with 64-bit math on x86 */ 395/* End of hacks to deal with 64-bit math on x86 */
397 396
398/** Convert to milliseconds */ 397/** Convert to milliseconds */
399static inline __u64 tv_to_ms(const struct timeval* tv) 398static inline __u64 tv_to_ms(const struct timeval *tv)
400{ 399{
401 __u64 ms = tv->tv_usec / 1000; 400 __u64 ms = tv->tv_usec / 1000;
402 ms += (__u64)tv->tv_sec * (__u64)1000; 401 ms += (__u64) tv->tv_sec * (__u64) 1000;
403 return ms; 402 return ms;
404} 403}
405 404
406
407/** Convert to micro-seconds */ 405/** Convert to micro-seconds */
408static inline __u64 tv_to_us(const struct timeval* tv) 406static inline __u64 tv_to_us(const struct timeval *tv)
409{ 407{
410 __u64 us = tv->tv_usec; 408 __u64 us = tv->tv_usec;
411 us += (__u64)tv->tv_sec * (__u64)1000000; 409 us += (__u64) tv->tv_sec * (__u64) 1000000;
412 return us; 410 return us;
413} 411}
414 412
415static inline __u64 pg_div(__u64 n, __u32 base) { 413static inline __u64 pg_div(__u64 n, __u32 base)
416 __u64 tmp = n; 414{
417 do_div(tmp, base); 415 __u64 tmp = n;
418 /* printk("pktgen: pg_div, n: %llu base: %d rv: %llu\n", 416 do_div(tmp, base);
419 n, base, tmp); */ 417 /* printk("pktgen: pg_div, n: %llu base: %d rv: %llu\n",
420 return tmp; 418 n, base, tmp); */
419 return tmp;
421} 420}
422 421
423static inline __u64 pg_div64(__u64 n, __u64 base) 422static inline __u64 pg_div64(__u64 n, __u64 base)
424{ 423{
425 __u64 tmp = n; 424 __u64 tmp = n;
426/* 425/*
427 * How do we know if the architecture we are running on 426 * How do we know if the architecture we are running on
428 * supports division with 64 bit base? 427 * supports division with 64 bit base?
429 * 428 *
430 */ 429 */
431#if defined(__sparc_v9__) || defined(__powerpc64__) || defined(__alpha__) || defined(__x86_64__) || defined(__ia64__) 430#if defined(__sparc_v9__) || defined(__powerpc64__) || defined(__alpha__) || defined(__x86_64__) || defined(__ia64__)
432 431
433 do_div(tmp, base); 432 do_div(tmp, base);
434#else 433#else
435 tmp = divremdi3(n, base, PG_DIV); 434 tmp = divremdi3(n, base, PG_DIV);
436#endif 435#endif
437 return tmp; 436 return tmp;
438} 437}
439 438
440static inline u32 pktgen_random(void) 439static inline u32 pktgen_random(void)
@@ -448,51 +447,51 @@ static inline u32 pktgen_random(void)
448#endif 447#endif
449} 448}
450 449
451static inline __u64 getCurMs(void) 450static inline __u64 getCurMs(void)
452{ 451{
453 struct timeval tv; 452 struct timeval tv;
454 do_gettimeofday(&tv); 453 do_gettimeofday(&tv);
455 return tv_to_ms(&tv); 454 return tv_to_ms(&tv);
456} 455}
457 456
458static inline __u64 getCurUs(void) 457static inline __u64 getCurUs(void)
459{ 458{
460 struct timeval tv; 459 struct timeval tv;
461 do_gettimeofday(&tv); 460 do_gettimeofday(&tv);
462 return tv_to_us(&tv); 461 return tv_to_us(&tv);
463} 462}
464 463
465static inline __u64 tv_diff(const struct timeval* a, const struct timeval* b) 464static inline __u64 tv_diff(const struct timeval *a, const struct timeval *b)
466{ 465{
467 return tv_to_us(a) - tv_to_us(b); 466 return tv_to_us(a) - tv_to_us(b);
468} 467}
469 468
470
471/* old include end */ 469/* old include end */
472 470
473static char version[] __initdata = VERSION; 471static char version[] __initdata = VERSION;
474 472
475static int pktgen_remove_device(struct pktgen_thread* t, struct pktgen_dev *i); 473static int pktgen_remove_device(struct pktgen_thread *t, struct pktgen_dev *i);
476static int pktgen_add_device(struct pktgen_thread* t, const char* ifname); 474static int pktgen_add_device(struct pktgen_thread *t, const char *ifname);
477static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread* t, const char* ifname); 475static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
476 const char *ifname);
478static int pktgen_device_event(struct notifier_block *, unsigned long, void *); 477static int pktgen_device_event(struct notifier_block *, unsigned long, void *);
479static void pktgen_run_all_threads(void); 478static void pktgen_run_all_threads(void);
480static void pktgen_stop_all_threads_ifs(void); 479static void pktgen_stop_all_threads_ifs(void);
481static int pktgen_stop_device(struct pktgen_dev *pkt_dev); 480static int pktgen_stop_device(struct pktgen_dev *pkt_dev);
482static void pktgen_stop(struct pktgen_thread* t); 481static void pktgen_stop(struct pktgen_thread *t);
483static void pktgen_clear_counters(struct pktgen_dev *pkt_dev); 482static void pktgen_clear_counters(struct pktgen_dev *pkt_dev);
484static struct pktgen_dev *pktgen_NN_threads(const char* dev_name, int remove); 483static int pktgen_mark_device(const char *ifname);
485static unsigned int scan_ip6(const char *s,char ip[16]); 484static unsigned int scan_ip6(const char *s, char ip[16]);
486static unsigned int fmt_ip6(char *s,const char ip[16]); 485static unsigned int fmt_ip6(char *s, const char ip[16]);
487 486
488/* Module parameters, defaults. */ 487/* Module parameters, defaults. */
489static int pg_count_d = 1000; /* 1000 pkts by default */ 488static int pg_count_d = 1000; /* 1000 pkts by default */
490static int pg_delay_d; 489static int pg_delay_d;
491static int pg_clone_skb_d; 490static int pg_clone_skb_d;
492static int debug; 491static int debug;
493 492
494static DECLARE_MUTEX(pktgen_sem); 493static DEFINE_MUTEX(pktgen_thread_lock);
495static struct pktgen_thread *pktgen_threads = NULL; 494static LIST_HEAD(pktgen_threads);
496 495
497static struct notifier_block pktgen_notifier_block = { 496static struct notifier_block pktgen_notifier_block = {
498 .notifier_call = pktgen_device_event, 497 .notifier_call = pktgen_device_event,
@@ -504,21 +503,21 @@ static struct notifier_block pktgen_notifier_block = {
504 */ 503 */
505 504
506static int pgctrl_show(struct seq_file *seq, void *v) 505static int pgctrl_show(struct seq_file *seq, void *v)
507{ 506{
508 seq_puts(seq, VERSION); 507 seq_puts(seq, VERSION);
509 return 0; 508 return 0;
510} 509}
511 510
512static ssize_t pgctrl_write(struct file* file,const char __user * buf, 511static ssize_t pgctrl_write(struct file *file, const char __user * buf,
513 size_t count, loff_t *ppos) 512 size_t count, loff_t * ppos)
514{ 513{
515 int err = 0; 514 int err = 0;
516 char data[128]; 515 char data[128];
517 516
518 if (!capable(CAP_NET_ADMIN)){ 517 if (!capable(CAP_NET_ADMIN)) {
519 err = -EPERM; 518 err = -EPERM;
520 goto out; 519 goto out;
521 } 520 }
522 521
523 if (count > sizeof(data)) 522 if (count > sizeof(data))
524 count = sizeof(data); 523 count = sizeof(data);
@@ -526,22 +525,22 @@ static ssize_t pgctrl_write(struct file* file,const char __user * buf,
526 if (copy_from_user(data, buf, count)) { 525 if (copy_from_user(data, buf, count)) {
527 err = -EFAULT; 526 err = -EFAULT;
528 goto out; 527 goto out;
529 } 528 }
530 data[count-1] = 0; /* Make string */ 529 data[count - 1] = 0; /* Make string */
531 530
532 if (!strcmp(data, "stop")) 531 if (!strcmp(data, "stop"))
533 pktgen_stop_all_threads_ifs(); 532 pktgen_stop_all_threads_ifs();
534 533
535 else if (!strcmp(data, "start")) 534 else if (!strcmp(data, "start"))
536 pktgen_run_all_threads(); 535 pktgen_run_all_threads();
537 536
538 else 537 else
539 printk("pktgen: Unknown command: %s\n", data); 538 printk("pktgen: Unknown command: %s\n", data);
540 539
541 err = count; 540 err = count;
542 541
543 out: 542out:
544 return err; 543 return err;
545} 544}
546 545
547static int pgctrl_open(struct inode *inode, struct file *file) 546static int pgctrl_open(struct inode *inode, struct file *file)
@@ -550,147 +549,158 @@ static int pgctrl_open(struct inode *inode, struct file *file)
550} 549}
551 550
552static struct file_operations pktgen_fops = { 551static struct file_operations pktgen_fops = {
553 .owner = THIS_MODULE, 552 .owner = THIS_MODULE,
554 .open = pgctrl_open, 553 .open = pgctrl_open,
555 .read = seq_read, 554 .read = seq_read,
556 .llseek = seq_lseek, 555 .llseek = seq_lseek,
557 .write = pgctrl_write, 556 .write = pgctrl_write,
558 .release = single_release, 557 .release = single_release,
559}; 558};
560 559
561static int pktgen_if_show(struct seq_file *seq, void *v) 560static int pktgen_if_show(struct seq_file *seq, void *v)
562{ 561{
563 int i; 562 int i;
564 struct pktgen_dev *pkt_dev = seq->private; 563 struct pktgen_dev *pkt_dev = seq->private;
565 __u64 sa; 564 __u64 sa;
566 __u64 stopped; 565 __u64 stopped;
567 __u64 now = getCurUs(); 566 __u64 now = getCurUs();
568 567
569 seq_printf(seq, "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n", 568 seq_printf(seq,
570 (unsigned long long) pkt_dev->count, 569 "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n",
571 pkt_dev->min_pkt_size, pkt_dev->max_pkt_size); 570 (unsigned long long)pkt_dev->count, pkt_dev->min_pkt_size,
571 pkt_dev->max_pkt_size);
572
573 seq_printf(seq,
574 " frags: %d delay: %u clone_skb: %d ifname: %s\n",
575 pkt_dev->nfrags,
576 1000 * pkt_dev->delay_us + pkt_dev->delay_ns,
577 pkt_dev->clone_skb, pkt_dev->ifname);
578
579 seq_printf(seq, " flows: %u flowlen: %u\n", pkt_dev->cflows,
580 pkt_dev->lflow);
581
582 if (pkt_dev->flags & F_IPV6) {
583 char b1[128], b2[128], b3[128];
584 fmt_ip6(b1, pkt_dev->in6_saddr.s6_addr);
585 fmt_ip6(b2, pkt_dev->min_in6_saddr.s6_addr);
586 fmt_ip6(b3, pkt_dev->max_in6_saddr.s6_addr);
587 seq_printf(seq,
588 " saddr: %s min_saddr: %s max_saddr: %s\n", b1,
589 b2, b3);
590
591 fmt_ip6(b1, pkt_dev->in6_daddr.s6_addr);
592 fmt_ip6(b2, pkt_dev->min_in6_daddr.s6_addr);
593 fmt_ip6(b3, pkt_dev->max_in6_daddr.s6_addr);
594 seq_printf(seq,
595 " daddr: %s min_daddr: %s max_daddr: %s\n", b1,
596 b2, b3);
597
598 } else
599 seq_printf(seq,
600 " dst_min: %s dst_max: %s\n src_min: %s src_max: %s\n",
601 pkt_dev->dst_min, pkt_dev->dst_max, pkt_dev->src_min,
602 pkt_dev->src_max);
572 603
573 seq_printf(seq, " frags: %d delay: %u clone_skb: %d ifname: %s\n", 604 seq_puts(seq, " src_mac: ");
574 pkt_dev->nfrags, 1000*pkt_dev->delay_us+pkt_dev->delay_ns, pkt_dev->clone_skb, pkt_dev->ifname);
575 605
576 seq_printf(seq, " flows: %u flowlen: %u\n", pkt_dev->cflows, pkt_dev->lflow); 606 if (is_zero_ether_addr(pkt_dev->src_mac))
607 for (i = 0; i < 6; i++)
608 seq_printf(seq, "%02X%s", pkt_dev->odev->dev_addr[i],
609 i == 5 ? " " : ":");
610 else
611 for (i = 0; i < 6; i++)
612 seq_printf(seq, "%02X%s", pkt_dev->src_mac[i],
613 i == 5 ? " " : ":");
614
615 seq_printf(seq, "dst_mac: ");
616 for (i = 0; i < 6; i++)
617 seq_printf(seq, "%02X%s", pkt_dev->dst_mac[i],
618 i == 5 ? "\n" : ":");
619
620 seq_printf(seq,
621 " udp_src_min: %d udp_src_max: %d udp_dst_min: %d udp_dst_max: %d\n",
622 pkt_dev->udp_src_min, pkt_dev->udp_src_max,
623 pkt_dev->udp_dst_min, pkt_dev->udp_dst_max);
624
625 seq_printf(seq,
626 " src_mac_count: %d dst_mac_count: %d \n Flags: ",
627 pkt_dev->src_mac_count, pkt_dev->dst_mac_count);
577 628
629 if (pkt_dev->flags & F_IPV6)
630 seq_printf(seq, "IPV6 ");
578 631
579 if(pkt_dev->flags & F_IPV6) { 632 if (pkt_dev->flags & F_IPSRC_RND)
580 char b1[128], b2[128], b3[128]; 633 seq_printf(seq, "IPSRC_RND ");
581 fmt_ip6(b1, pkt_dev->in6_saddr.s6_addr);
582 fmt_ip6(b2, pkt_dev->min_in6_saddr.s6_addr);
583 fmt_ip6(b3, pkt_dev->max_in6_saddr.s6_addr);
584 seq_printf(seq, " saddr: %s min_saddr: %s max_saddr: %s\n", b1, b2, b3);
585 634
586 fmt_ip6(b1, pkt_dev->in6_daddr.s6_addr); 635 if (pkt_dev->flags & F_IPDST_RND)
587 fmt_ip6(b2, pkt_dev->min_in6_daddr.s6_addr); 636 seq_printf(seq, "IPDST_RND ");
588 fmt_ip6(b3, pkt_dev->max_in6_daddr.s6_addr);
589 seq_printf(seq, " daddr: %s min_daddr: %s max_daddr: %s\n", b1, b2, b3);
590 637
591 } 638 if (pkt_dev->flags & F_TXSIZE_RND)
592 else 639 seq_printf(seq, "TXSIZE_RND ");
593 seq_printf(seq," dst_min: %s dst_max: %s\n src_min: %s src_max: %s\n",
594 pkt_dev->dst_min, pkt_dev->dst_max, pkt_dev->src_min, pkt_dev->src_max);
595 640
596 seq_puts(seq, " src_mac: "); 641 if (pkt_dev->flags & F_UDPSRC_RND)
642 seq_printf(seq, "UDPSRC_RND ");
597 643
598 if (is_zero_ether_addr(pkt_dev->src_mac)) 644 if (pkt_dev->flags & F_UDPDST_RND)
599 for (i = 0; i < 6; i++) 645 seq_printf(seq, "UDPDST_RND ");
600 seq_printf(seq, "%02X%s", pkt_dev->odev->dev_addr[i], i == 5 ? " " : ":");
601 else
602 for (i = 0; i < 6; i++)
603 seq_printf(seq, "%02X%s", pkt_dev->src_mac[i], i == 5 ? " " : ":");
604 646
605 seq_printf(seq, "dst_mac: "); 647 if (pkt_dev->flags & F_MACSRC_RND)
606 for (i = 0; i < 6; i++) 648 seq_printf(seq, "MACSRC_RND ");
607 seq_printf(seq, "%02X%s", pkt_dev->dst_mac[i], i == 5 ? "\n" : ":");
608 649
609 seq_printf(seq, " udp_src_min: %d udp_src_max: %d udp_dst_min: %d udp_dst_max: %d\n", 650 if (pkt_dev->flags & F_MACDST_RND)
610 pkt_dev->udp_src_min, pkt_dev->udp_src_max, pkt_dev->udp_dst_min, 651 seq_printf(seq, "MACDST_RND ");
611 pkt_dev->udp_dst_max);
612 652
613 seq_printf(seq, " src_mac_count: %d dst_mac_count: %d \n Flags: ", 653 seq_puts(seq, "\n");
614 pkt_dev->src_mac_count, pkt_dev->dst_mac_count); 654
655 sa = pkt_dev->started_at;
656 stopped = pkt_dev->stopped_at;
657 if (pkt_dev->running)
658 stopped = now; /* not really stopped, more like last-running-at */
615 659
660 seq_printf(seq,
661 "Current:\n pkts-sofar: %llu errors: %llu\n started: %lluus stopped: %lluus idle: %lluus\n",
662 (unsigned long long)pkt_dev->sofar,
663 (unsigned long long)pkt_dev->errors, (unsigned long long)sa,
664 (unsigned long long)stopped,
665 (unsigned long long)pkt_dev->idle_acc);
616 666
617 if (pkt_dev->flags & F_IPV6) 667 seq_printf(seq,
618 seq_printf(seq, "IPV6 "); 668 " seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n",
619
620 if (pkt_dev->flags & F_IPSRC_RND)
621 seq_printf(seq, "IPSRC_RND ");
622
623 if (pkt_dev->flags & F_IPDST_RND)
624 seq_printf(seq, "IPDST_RND ");
625
626 if (pkt_dev->flags & F_TXSIZE_RND)
627 seq_printf(seq, "TXSIZE_RND ");
628
629 if (pkt_dev->flags & F_UDPSRC_RND)
630 seq_printf(seq, "UDPSRC_RND ");
631
632 if (pkt_dev->flags & F_UDPDST_RND)
633 seq_printf(seq, "UDPDST_RND ");
634
635 if (pkt_dev->flags & F_MACSRC_RND)
636 seq_printf(seq, "MACSRC_RND ");
637
638 if (pkt_dev->flags & F_MACDST_RND)
639 seq_printf(seq, "MACDST_RND ");
640
641
642 seq_puts(seq, "\n");
643
644 sa = pkt_dev->started_at;
645 stopped = pkt_dev->stopped_at;
646 if (pkt_dev->running)
647 stopped = now; /* not really stopped, more like last-running-at */
648
649 seq_printf(seq, "Current:\n pkts-sofar: %llu errors: %llu\n started: %lluus stopped: %lluus idle: %lluus\n",
650 (unsigned long long) pkt_dev->sofar,
651 (unsigned long long) pkt_dev->errors,
652 (unsigned long long) sa,
653 (unsigned long long) stopped,
654 (unsigned long long) pkt_dev->idle_acc);
655
656 seq_printf(seq, " seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n",
657 pkt_dev->seq_num, pkt_dev->cur_dst_mac_offset, 669 pkt_dev->seq_num, pkt_dev->cur_dst_mac_offset,
658 pkt_dev->cur_src_mac_offset); 670 pkt_dev->cur_src_mac_offset);
659 671
660 if(pkt_dev->flags & F_IPV6) { 672 if (pkt_dev->flags & F_IPV6) {
661 char b1[128], b2[128]; 673 char b1[128], b2[128];
662 fmt_ip6(b1, pkt_dev->cur_in6_daddr.s6_addr); 674 fmt_ip6(b1, pkt_dev->cur_in6_daddr.s6_addr);
663 fmt_ip6(b2, pkt_dev->cur_in6_saddr.s6_addr); 675 fmt_ip6(b2, pkt_dev->cur_in6_saddr.s6_addr);
664 seq_printf(seq, " cur_saddr: %s cur_daddr: %s\n", b2, b1); 676 seq_printf(seq, " cur_saddr: %s cur_daddr: %s\n", b2, b1);
665 } 677 } else
666 else 678 seq_printf(seq, " cur_saddr: 0x%x cur_daddr: 0x%x\n",
667 seq_printf(seq, " cur_saddr: 0x%x cur_daddr: 0x%x\n",
668 pkt_dev->cur_saddr, pkt_dev->cur_daddr); 679 pkt_dev->cur_saddr, pkt_dev->cur_daddr);
669 680
670 681 seq_printf(seq, " cur_udp_dst: %d cur_udp_src: %d\n",
671 seq_printf(seq, " cur_udp_dst: %d cur_udp_src: %d\n",
672 pkt_dev->cur_udp_dst, pkt_dev->cur_udp_src); 682 pkt_dev->cur_udp_dst, pkt_dev->cur_udp_src);
673 683
674 seq_printf(seq, " flows: %u\n", pkt_dev->nflows); 684 seq_printf(seq, " flows: %u\n", pkt_dev->nflows);
675 685
676 if (pkt_dev->result[0]) 686 if (pkt_dev->result[0])
677 seq_printf(seq, "Result: %s\n", pkt_dev->result); 687 seq_printf(seq, "Result: %s\n", pkt_dev->result);
678 else 688 else
679 seq_printf(seq, "Result: Idle\n"); 689 seq_printf(seq, "Result: Idle\n");
680 690
681 return 0; 691 return 0;
682} 692}
683 693
684 694static int count_trail_chars(const char __user * user_buffer,
685static int count_trail_chars(const char __user *user_buffer, unsigned int maxlen) 695 unsigned int maxlen)
686{ 696{
687 int i; 697 int i;
688 698
689 for (i = 0; i < maxlen; i++) { 699 for (i = 0; i < maxlen; i++) {
690 char c; 700 char c;
691 if (get_user(c, &user_buffer[i])) 701 if (get_user(c, &user_buffer[i]))
692 return -EFAULT; 702 return -EFAULT;
693 switch (c) { 703 switch (c) {
694 case '\"': 704 case '\"':
695 case '\n': 705 case '\n':
696 case '\r': 706 case '\r':
@@ -706,34 +716,34 @@ done:
706 return i; 716 return i;
707} 717}
708 718
709static unsigned long num_arg(const char __user *user_buffer, unsigned long maxlen, 719static unsigned long num_arg(const char __user * user_buffer,
710 unsigned long *num) 720 unsigned long maxlen, unsigned long *num)
711{ 721{
712 int i = 0; 722 int i = 0;
713 *num = 0; 723 *num = 0;
714 724
715 for(; i < maxlen; i++) { 725 for (; i < maxlen; i++) {
716 char c; 726 char c;
717 if (get_user(c, &user_buffer[i])) 727 if (get_user(c, &user_buffer[i]))
718 return -EFAULT; 728 return -EFAULT;
719 if ((c >= '0') && (c <= '9')) { 729 if ((c >= '0') && (c <= '9')) {
720 *num *= 10; 730 *num *= 10;
721 *num += c -'0'; 731 *num += c - '0';
722 } else 732 } else
723 break; 733 break;
724 } 734 }
725 return i; 735 return i;
726} 736}
727 737
728static int strn_len(const char __user *user_buffer, unsigned int maxlen) 738static int strn_len(const char __user * user_buffer, unsigned int maxlen)
729{ 739{
730 int i = 0; 740 int i = 0;
731 741
732 for(; i < maxlen; i++) { 742 for (; i < maxlen; i++) {
733 char c; 743 char c;
734 if (get_user(c, &user_buffer[i])) 744 if (get_user(c, &user_buffer[i]))
735 return -EFAULT; 745 return -EFAULT;
736 switch (c) { 746 switch (c) {
737 case '\"': 747 case '\"':
738 case '\n': 748 case '\n':
739 case '\r': 749 case '\r':
@@ -746,119 +756,133 @@ static int strn_len(const char __user *user_buffer, unsigned int maxlen)
746 }; 756 };
747 } 757 }
748done_str: 758done_str:
749
750 return i; 759 return i;
751} 760}
752 761
753static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer, 762static ssize_t pktgen_if_write(struct file *file,
754 size_t count, loff_t *offset) 763 const char __user * user_buffer, size_t count,
764 loff_t * offset)
755{ 765{
756 struct seq_file *seq = (struct seq_file *) file->private_data; 766 struct seq_file *seq = (struct seq_file *)file->private_data;
757 struct pktgen_dev *pkt_dev = seq->private; 767 struct pktgen_dev *pkt_dev = seq->private;
758 int i = 0, max, len; 768 int i = 0, max, len;
759 char name[16], valstr[32]; 769 char name[16], valstr[32];
760 unsigned long value = 0; 770 unsigned long value = 0;
761 char* pg_result = NULL; 771 char *pg_result = NULL;
762 int tmp = 0; 772 int tmp = 0;
763 char buf[128]; 773 char buf[128];
764 774
765 pg_result = &(pkt_dev->result[0]); 775 pg_result = &(pkt_dev->result[0]);
766 776
767 if (count < 1) { 777 if (count < 1) {
768 printk("pktgen: wrong command format\n"); 778 printk("pktgen: wrong command format\n");
769 return -EINVAL; 779 return -EINVAL;
770 } 780 }
771 781
772 max = count - i; 782 max = count - i;
773 tmp = count_trail_chars(&user_buffer[i], max); 783 tmp = count_trail_chars(&user_buffer[i], max);
774 if (tmp < 0) { 784 if (tmp < 0) {
775 printk("pktgen: illegal format\n"); 785 printk("pktgen: illegal format\n");
776 return tmp; 786 return tmp;
777 } 787 }
778 i += tmp; 788 i += tmp;
779 789
780 /* Read variable name */ 790 /* Read variable name */
781 791
782 len = strn_len(&user_buffer[i], sizeof(name) - 1); 792 len = strn_len(&user_buffer[i], sizeof(name) - 1);
783 if (len < 0) { return len; } 793 if (len < 0) {
794 return len;
795 }
784 memset(name, 0, sizeof(name)); 796 memset(name, 0, sizeof(name));
785 if (copy_from_user(name, &user_buffer[i], len) ) 797 if (copy_from_user(name, &user_buffer[i], len))
786 return -EFAULT; 798 return -EFAULT;
787 i += len; 799 i += len;
788 800
789 max = count -i; 801 max = count - i;
790 len = count_trail_chars(&user_buffer[i], max); 802 len = count_trail_chars(&user_buffer[i], max);
791 if (len < 0) 803 if (len < 0)
792 return len; 804 return len;
793 805
794 i += len; 806 i += len;
795 807
796 if (debug) { 808 if (debug) {
797 char tb[count + 1]; 809 char tb[count + 1];
798 if (copy_from_user(tb, user_buffer, count)) 810 if (copy_from_user(tb, user_buffer, count))
799 return -EFAULT; 811 return -EFAULT;
800 tb[count] = 0; 812 tb[count] = 0;
801 printk("pktgen: %s,%lu buffer -:%s:-\n", name, 813 printk("pktgen: %s,%lu buffer -:%s:-\n", name,
802 (unsigned long) count, tb); 814 (unsigned long)count, tb);
803 } 815 }
804 816
805 if (!strcmp(name, "min_pkt_size")) { 817 if (!strcmp(name, "min_pkt_size")) {
806 len = num_arg(&user_buffer[i], 10, &value); 818 len = num_arg(&user_buffer[i], 10, &value);
807 if (len < 0) { return len; } 819 if (len < 0) {
820 return len;
821 }
808 i += len; 822 i += len;
809 if (value < 14+20+8) 823 if (value < 14 + 20 + 8)
810 value = 14+20+8; 824 value = 14 + 20 + 8;
811 if (value != pkt_dev->min_pkt_size) { 825 if (value != pkt_dev->min_pkt_size) {
812 pkt_dev->min_pkt_size = value; 826 pkt_dev->min_pkt_size = value;
813 pkt_dev->cur_pkt_size = value; 827 pkt_dev->cur_pkt_size = value;
814 } 828 }
815 sprintf(pg_result, "OK: min_pkt_size=%u", pkt_dev->min_pkt_size); 829 sprintf(pg_result, "OK: min_pkt_size=%u",
830 pkt_dev->min_pkt_size);
816 return count; 831 return count;
817 } 832 }
818 833
819 if (!strcmp(name, "max_pkt_size")) { 834 if (!strcmp(name, "max_pkt_size")) {
820 len = num_arg(&user_buffer[i], 10, &value); 835 len = num_arg(&user_buffer[i], 10, &value);
821 if (len < 0) { return len; } 836 if (len < 0) {
837 return len;
838 }
822 i += len; 839 i += len;
823 if (value < 14+20+8) 840 if (value < 14 + 20 + 8)
824 value = 14+20+8; 841 value = 14 + 20 + 8;
825 if (value != pkt_dev->max_pkt_size) { 842 if (value != pkt_dev->max_pkt_size) {
826 pkt_dev->max_pkt_size = value; 843 pkt_dev->max_pkt_size = value;
827 pkt_dev->cur_pkt_size = value; 844 pkt_dev->cur_pkt_size = value;
828 } 845 }
829 sprintf(pg_result, "OK: max_pkt_size=%u", pkt_dev->max_pkt_size); 846 sprintf(pg_result, "OK: max_pkt_size=%u",
847 pkt_dev->max_pkt_size);
830 return count; 848 return count;
831 } 849 }
832 850
833 /* Shortcut for min = max */ 851 /* Shortcut for min = max */
834 852
835 if (!strcmp(name, "pkt_size")) { 853 if (!strcmp(name, "pkt_size")) {
836 len = num_arg(&user_buffer[i], 10, &value); 854 len = num_arg(&user_buffer[i], 10, &value);
837 if (len < 0) { return len; } 855 if (len < 0) {
856 return len;
857 }
838 i += len; 858 i += len;
839 if (value < 14+20+8) 859 if (value < 14 + 20 + 8)
840 value = 14+20+8; 860 value = 14 + 20 + 8;
841 if (value != pkt_dev->min_pkt_size) { 861 if (value != pkt_dev->min_pkt_size) {
842 pkt_dev->min_pkt_size = value; 862 pkt_dev->min_pkt_size = value;
843 pkt_dev->max_pkt_size = value; 863 pkt_dev->max_pkt_size = value;
844 pkt_dev->cur_pkt_size = value; 864 pkt_dev->cur_pkt_size = value;
845 } 865 }
846 sprintf(pg_result, "OK: pkt_size=%u", pkt_dev->min_pkt_size); 866 sprintf(pg_result, "OK: pkt_size=%u", pkt_dev->min_pkt_size);
847 return count; 867 return count;
848 } 868 }
849 869
850 if (!strcmp(name, "debug")) { 870 if (!strcmp(name, "debug")) {
851 len = num_arg(&user_buffer[i], 10, &value); 871 len = num_arg(&user_buffer[i], 10, &value);
852 if (len < 0) { return len; } 872 if (len < 0) {
873 return len;
874 }
853 i += len; 875 i += len;
854 debug = value; 876 debug = value;
855 sprintf(pg_result, "OK: debug=%u", debug); 877 sprintf(pg_result, "OK: debug=%u", debug);
856 return count; 878 return count;
857 } 879 }
858 880
859 if (!strcmp(name, "frags")) { 881 if (!strcmp(name, "frags")) {
860 len = num_arg(&user_buffer[i], 10, &value); 882 len = num_arg(&user_buffer[i], 10, &value);
861 if (len < 0) { return len; } 883 if (len < 0) {
884 return len;
885 }
862 i += len; 886 i += len;
863 pkt_dev->nfrags = value; 887 pkt_dev->nfrags = value;
864 sprintf(pg_result, "OK: frags=%u", pkt_dev->nfrags); 888 sprintf(pg_result, "OK: frags=%u", pkt_dev->nfrags);
@@ -866,7 +890,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
866 } 890 }
867 if (!strcmp(name, "delay")) { 891 if (!strcmp(name, "delay")) {
868 len = num_arg(&user_buffer[i], 10, &value); 892 len = num_arg(&user_buffer[i], 10, &value);
869 if (len < 0) { return len; } 893 if (len < 0) {
894 return len;
895 }
870 i += len; 896 i += len;
871 if (value == 0x7FFFFFFF) { 897 if (value == 0x7FFFFFFF) {
872 pkt_dev->delay_us = 0x7FFFFFFF; 898 pkt_dev->delay_us = 0x7FFFFFFF;
@@ -875,308 +901,347 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
875 pkt_dev->delay_us = value / 1000; 901 pkt_dev->delay_us = value / 1000;
876 pkt_dev->delay_ns = value % 1000; 902 pkt_dev->delay_ns = value % 1000;
877 } 903 }
878 sprintf(pg_result, "OK: delay=%u", 1000*pkt_dev->delay_us+pkt_dev->delay_ns); 904 sprintf(pg_result, "OK: delay=%u",
905 1000 * pkt_dev->delay_us + pkt_dev->delay_ns);
879 return count; 906 return count;
880 } 907 }
881 if (!strcmp(name, "udp_src_min")) { 908 if (!strcmp(name, "udp_src_min")) {
882 len = num_arg(&user_buffer[i], 10, &value); 909 len = num_arg(&user_buffer[i], 10, &value);
883 if (len < 0) { return len; } 910 if (len < 0) {
911 return len;
912 }
884 i += len; 913 i += len;
885 if (value != pkt_dev->udp_src_min) { 914 if (value != pkt_dev->udp_src_min) {
886 pkt_dev->udp_src_min = value; 915 pkt_dev->udp_src_min = value;
887 pkt_dev->cur_udp_src = value; 916 pkt_dev->cur_udp_src = value;
888 } 917 }
889 sprintf(pg_result, "OK: udp_src_min=%u", pkt_dev->udp_src_min); 918 sprintf(pg_result, "OK: udp_src_min=%u", pkt_dev->udp_src_min);
890 return count; 919 return count;
891 } 920 }
892 if (!strcmp(name, "udp_dst_min")) { 921 if (!strcmp(name, "udp_dst_min")) {
893 len = num_arg(&user_buffer[i], 10, &value); 922 len = num_arg(&user_buffer[i], 10, &value);
894 if (len < 0) { return len; } 923 if (len < 0) {
924 return len;
925 }
895 i += len; 926 i += len;
896 if (value != pkt_dev->udp_dst_min) { 927 if (value != pkt_dev->udp_dst_min) {
897 pkt_dev->udp_dst_min = value; 928 pkt_dev->udp_dst_min = value;
898 pkt_dev->cur_udp_dst = value; 929 pkt_dev->cur_udp_dst = value;
899 } 930 }
900 sprintf(pg_result, "OK: udp_dst_min=%u", pkt_dev->udp_dst_min); 931 sprintf(pg_result, "OK: udp_dst_min=%u", pkt_dev->udp_dst_min);
901 return count; 932 return count;
902 } 933 }
903 if (!strcmp(name, "udp_src_max")) { 934 if (!strcmp(name, "udp_src_max")) {
904 len = num_arg(&user_buffer[i], 10, &value); 935 len = num_arg(&user_buffer[i], 10, &value);
905 if (len < 0) { return len; } 936 if (len < 0) {
937 return len;
938 }
906 i += len; 939 i += len;
907 if (value != pkt_dev->udp_src_max) { 940 if (value != pkt_dev->udp_src_max) {
908 pkt_dev->udp_src_max = value; 941 pkt_dev->udp_src_max = value;
909 pkt_dev->cur_udp_src = value; 942 pkt_dev->cur_udp_src = value;
910 } 943 }
911 sprintf(pg_result, "OK: udp_src_max=%u", pkt_dev->udp_src_max); 944 sprintf(pg_result, "OK: udp_src_max=%u", pkt_dev->udp_src_max);
912 return count; 945 return count;
913 } 946 }
914 if (!strcmp(name, "udp_dst_max")) { 947 if (!strcmp(name, "udp_dst_max")) {
915 len = num_arg(&user_buffer[i], 10, &value); 948 len = num_arg(&user_buffer[i], 10, &value);
916 if (len < 0) { return len; } 949 if (len < 0) {
950 return len;
951 }
917 i += len; 952 i += len;
918 if (value != pkt_dev->udp_dst_max) { 953 if (value != pkt_dev->udp_dst_max) {
919 pkt_dev->udp_dst_max = value; 954 pkt_dev->udp_dst_max = value;
920 pkt_dev->cur_udp_dst = value; 955 pkt_dev->cur_udp_dst = value;
921 } 956 }
922 sprintf(pg_result, "OK: udp_dst_max=%u", pkt_dev->udp_dst_max); 957 sprintf(pg_result, "OK: udp_dst_max=%u", pkt_dev->udp_dst_max);
923 return count; 958 return count;
924 } 959 }
925 if (!strcmp(name, "clone_skb")) { 960 if (!strcmp(name, "clone_skb")) {
926 len = num_arg(&user_buffer[i], 10, &value); 961 len = num_arg(&user_buffer[i], 10, &value);
927 if (len < 0) { return len; } 962 if (len < 0) {
963 return len;
964 }
928 i += len; 965 i += len;
929 pkt_dev->clone_skb = value; 966 pkt_dev->clone_skb = value;
930 967
931 sprintf(pg_result, "OK: clone_skb=%d", pkt_dev->clone_skb); 968 sprintf(pg_result, "OK: clone_skb=%d", pkt_dev->clone_skb);
932 return count; 969 return count;
933 } 970 }
934 if (!strcmp(name, "count")) { 971 if (!strcmp(name, "count")) {
935 len = num_arg(&user_buffer[i], 10, &value); 972 len = num_arg(&user_buffer[i], 10, &value);
936 if (len < 0) { return len; } 973 if (len < 0) {
974 return len;
975 }
937 i += len; 976 i += len;
938 pkt_dev->count = value; 977 pkt_dev->count = value;
939 sprintf(pg_result, "OK: count=%llu", 978 sprintf(pg_result, "OK: count=%llu",
940 (unsigned long long) pkt_dev->count); 979 (unsigned long long)pkt_dev->count);
941 return count; 980 return count;
942 } 981 }
943 if (!strcmp(name, "src_mac_count")) { 982 if (!strcmp(name, "src_mac_count")) {
944 len = num_arg(&user_buffer[i], 10, &value); 983 len = num_arg(&user_buffer[i], 10, &value);
945 if (len < 0) { return len; } 984 if (len < 0) {
985 return len;
986 }
946 i += len; 987 i += len;
947 if (pkt_dev->src_mac_count != value) { 988 if (pkt_dev->src_mac_count != value) {
948 pkt_dev->src_mac_count = value; 989 pkt_dev->src_mac_count = value;
949 pkt_dev->cur_src_mac_offset = 0; 990 pkt_dev->cur_src_mac_offset = 0;
950 } 991 }
951 sprintf(pg_result, "OK: src_mac_count=%d", pkt_dev->src_mac_count); 992 sprintf(pg_result, "OK: src_mac_count=%d",
993 pkt_dev->src_mac_count);
952 return count; 994 return count;
953 } 995 }
954 if (!strcmp(name, "dst_mac_count")) { 996 if (!strcmp(name, "dst_mac_count")) {
955 len = num_arg(&user_buffer[i], 10, &value); 997 len = num_arg(&user_buffer[i], 10, &value);
956 if (len < 0) { return len; } 998 if (len < 0) {
999 return len;
1000 }
957 i += len; 1001 i += len;
958 if (pkt_dev->dst_mac_count != value) { 1002 if (pkt_dev->dst_mac_count != value) {
959 pkt_dev->dst_mac_count = value; 1003 pkt_dev->dst_mac_count = value;
960 pkt_dev->cur_dst_mac_offset = 0; 1004 pkt_dev->cur_dst_mac_offset = 0;
961 } 1005 }
962 sprintf(pg_result, "OK: dst_mac_count=%d", pkt_dev->dst_mac_count); 1006 sprintf(pg_result, "OK: dst_mac_count=%d",
1007 pkt_dev->dst_mac_count);
963 return count; 1008 return count;
964 } 1009 }
965 if (!strcmp(name, "flag")) { 1010 if (!strcmp(name, "flag")) {
966 char f[32]; 1011 char f[32];
967 memset(f, 0, 32); 1012 memset(f, 0, 32);
968 len = strn_len(&user_buffer[i], sizeof(f) - 1); 1013 len = strn_len(&user_buffer[i], sizeof(f) - 1);
969 if (len < 0) { return len; } 1014 if (len < 0) {
1015 return len;
1016 }
970 if (copy_from_user(f, &user_buffer[i], len)) 1017 if (copy_from_user(f, &user_buffer[i], len))
971 return -EFAULT; 1018 return -EFAULT;
972 i += len; 1019 i += len;
973 if (strcmp(f, "IPSRC_RND") == 0) 1020 if (strcmp(f, "IPSRC_RND") == 0)
974 pkt_dev->flags |= F_IPSRC_RND; 1021 pkt_dev->flags |= F_IPSRC_RND;
975 1022
976 else if (strcmp(f, "!IPSRC_RND") == 0) 1023 else if (strcmp(f, "!IPSRC_RND") == 0)
977 pkt_dev->flags &= ~F_IPSRC_RND; 1024 pkt_dev->flags &= ~F_IPSRC_RND;
978 1025
979 else if (strcmp(f, "TXSIZE_RND") == 0) 1026 else if (strcmp(f, "TXSIZE_RND") == 0)
980 pkt_dev->flags |= F_TXSIZE_RND; 1027 pkt_dev->flags |= F_TXSIZE_RND;
981 1028
982 else if (strcmp(f, "!TXSIZE_RND") == 0) 1029 else if (strcmp(f, "!TXSIZE_RND") == 0)
983 pkt_dev->flags &= ~F_TXSIZE_RND; 1030 pkt_dev->flags &= ~F_TXSIZE_RND;
984 1031
985 else if (strcmp(f, "IPDST_RND") == 0) 1032 else if (strcmp(f, "IPDST_RND") == 0)
986 pkt_dev->flags |= F_IPDST_RND; 1033 pkt_dev->flags |= F_IPDST_RND;
987 1034
988 else if (strcmp(f, "!IPDST_RND") == 0) 1035 else if (strcmp(f, "!IPDST_RND") == 0)
989 pkt_dev->flags &= ~F_IPDST_RND; 1036 pkt_dev->flags &= ~F_IPDST_RND;
990 1037
991 else if (strcmp(f, "UDPSRC_RND") == 0) 1038 else if (strcmp(f, "UDPSRC_RND") == 0)
992 pkt_dev->flags |= F_UDPSRC_RND; 1039 pkt_dev->flags |= F_UDPSRC_RND;
993 1040
994 else if (strcmp(f, "!UDPSRC_RND") == 0) 1041 else if (strcmp(f, "!UDPSRC_RND") == 0)
995 pkt_dev->flags &= ~F_UDPSRC_RND; 1042 pkt_dev->flags &= ~F_UDPSRC_RND;
996 1043
997 else if (strcmp(f, "UDPDST_RND") == 0) 1044 else if (strcmp(f, "UDPDST_RND") == 0)
998 pkt_dev->flags |= F_UDPDST_RND; 1045 pkt_dev->flags |= F_UDPDST_RND;
999 1046
1000 else if (strcmp(f, "!UDPDST_RND") == 0) 1047 else if (strcmp(f, "!UDPDST_RND") == 0)
1001 pkt_dev->flags &= ~F_UDPDST_RND; 1048 pkt_dev->flags &= ~F_UDPDST_RND;
1002 1049
1003 else if (strcmp(f, "MACSRC_RND") == 0) 1050 else if (strcmp(f, "MACSRC_RND") == 0)
1004 pkt_dev->flags |= F_MACSRC_RND; 1051 pkt_dev->flags |= F_MACSRC_RND;
1005 1052
1006 else if (strcmp(f, "!MACSRC_RND") == 0) 1053 else if (strcmp(f, "!MACSRC_RND") == 0)
1007 pkt_dev->flags &= ~F_MACSRC_RND; 1054 pkt_dev->flags &= ~F_MACSRC_RND;
1008 1055
1009 else if (strcmp(f, "MACDST_RND") == 0) 1056 else if (strcmp(f, "MACDST_RND") == 0)
1010 pkt_dev->flags |= F_MACDST_RND; 1057 pkt_dev->flags |= F_MACDST_RND;
1011 1058
1012 else if (strcmp(f, "!MACDST_RND") == 0) 1059 else if (strcmp(f, "!MACDST_RND") == 0)
1013 pkt_dev->flags &= ~F_MACDST_RND; 1060 pkt_dev->flags &= ~F_MACDST_RND;
1014 1061
1015 else { 1062 else {
1016 sprintf(pg_result, "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s", 1063 sprintf(pg_result,
1017 f, 1064 "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
1018 "IPSRC_RND, IPDST_RND, TXSIZE_RND, UDPSRC_RND, UDPDST_RND, MACSRC_RND, MACDST_RND\n"); 1065 f,
1019 return count; 1066 "IPSRC_RND, IPDST_RND, TXSIZE_RND, UDPSRC_RND, UDPDST_RND, MACSRC_RND, MACDST_RND\n");
1020 } 1067 return count;
1068 }
1021 sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags); 1069 sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags);
1022 return count; 1070 return count;
1023 } 1071 }
1024 if (!strcmp(name, "dst_min") || !strcmp(name, "dst")) { 1072 if (!strcmp(name, "dst_min") || !strcmp(name, "dst")) {
1025 len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_min) - 1); 1073 len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_min) - 1);
1026 if (len < 0) { return len; } 1074 if (len < 0) {
1075 return len;
1076 }
1027 1077
1028 if (copy_from_user(buf, &user_buffer[i], len)) 1078 if (copy_from_user(buf, &user_buffer[i], len))
1029 return -EFAULT; 1079 return -EFAULT;
1030 buf[len] = 0; 1080 buf[len] = 0;
1031 if (strcmp(buf, pkt_dev->dst_min) != 0) { 1081 if (strcmp(buf, pkt_dev->dst_min) != 0) {
1032 memset(pkt_dev->dst_min, 0, sizeof(pkt_dev->dst_min)); 1082 memset(pkt_dev->dst_min, 0, sizeof(pkt_dev->dst_min));
1033 strncpy(pkt_dev->dst_min, buf, len); 1083 strncpy(pkt_dev->dst_min, buf, len);
1034 pkt_dev->daddr_min = in_aton(pkt_dev->dst_min); 1084 pkt_dev->daddr_min = in_aton(pkt_dev->dst_min);
1035 pkt_dev->cur_daddr = pkt_dev->daddr_min; 1085 pkt_dev->cur_daddr = pkt_dev->daddr_min;
1036 } 1086 }
1037 if(debug) 1087 if (debug)
1038 printk("pktgen: dst_min set to: %s\n", pkt_dev->dst_min); 1088 printk("pktgen: dst_min set to: %s\n",
1039 i += len; 1089 pkt_dev->dst_min);
1090 i += len;
1040 sprintf(pg_result, "OK: dst_min=%s", pkt_dev->dst_min); 1091 sprintf(pg_result, "OK: dst_min=%s", pkt_dev->dst_min);
1041 return count; 1092 return count;
1042 } 1093 }
1043 if (!strcmp(name, "dst_max")) { 1094 if (!strcmp(name, "dst_max")) {
1044 len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_max) - 1); 1095 len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_max) - 1);
1045 if (len < 0) { return len; } 1096 if (len < 0) {
1097 return len;
1098 }
1046 1099
1047 if (copy_from_user(buf, &user_buffer[i], len)) 1100 if (copy_from_user(buf, &user_buffer[i], len))
1048 return -EFAULT; 1101 return -EFAULT;
1049 1102
1050 buf[len] = 0; 1103 buf[len] = 0;
1051 if (strcmp(buf, pkt_dev->dst_max) != 0) { 1104 if (strcmp(buf, pkt_dev->dst_max) != 0) {
1052 memset(pkt_dev->dst_max, 0, sizeof(pkt_dev->dst_max)); 1105 memset(pkt_dev->dst_max, 0, sizeof(pkt_dev->dst_max));
1053 strncpy(pkt_dev->dst_max, buf, len); 1106 strncpy(pkt_dev->dst_max, buf, len);
1054 pkt_dev->daddr_max = in_aton(pkt_dev->dst_max); 1107 pkt_dev->daddr_max = in_aton(pkt_dev->dst_max);
1055 pkt_dev->cur_daddr = pkt_dev->daddr_max; 1108 pkt_dev->cur_daddr = pkt_dev->daddr_max;
1056 } 1109 }
1057 if(debug) 1110 if (debug)
1058 printk("pktgen: dst_max set to: %s\n", pkt_dev->dst_max); 1111 printk("pktgen: dst_max set to: %s\n",
1112 pkt_dev->dst_max);
1059 i += len; 1113 i += len;
1060 sprintf(pg_result, "OK: dst_max=%s", pkt_dev->dst_max); 1114 sprintf(pg_result, "OK: dst_max=%s", pkt_dev->dst_max);
1061 return count; 1115 return count;
1062 } 1116 }
1063 if (!strcmp(name, "dst6")) { 1117 if (!strcmp(name, "dst6")) {
1064 len = strn_len(&user_buffer[i], sizeof(buf) - 1); 1118 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
1065 if (len < 0) return len; 1119 if (len < 0)
1120 return len;
1066 1121
1067 pkt_dev->flags |= F_IPV6; 1122 pkt_dev->flags |= F_IPV6;
1068 1123
1069 if (copy_from_user(buf, &user_buffer[i], len)) 1124 if (copy_from_user(buf, &user_buffer[i], len))
1070 return -EFAULT; 1125 return -EFAULT;
1071 buf[len] = 0; 1126 buf[len] = 0;
1072 1127
1073 scan_ip6(buf, pkt_dev->in6_daddr.s6_addr); 1128 scan_ip6(buf, pkt_dev->in6_daddr.s6_addr);
1074 fmt_ip6(buf, pkt_dev->in6_daddr.s6_addr); 1129 fmt_ip6(buf, pkt_dev->in6_daddr.s6_addr);
1075 1130
1076 ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->in6_daddr); 1131 ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->in6_daddr);
1077 1132
1078 if(debug) 1133 if (debug)
1079 printk("pktgen: dst6 set to: %s\n", buf); 1134 printk("pktgen: dst6 set to: %s\n", buf);
1080 1135
1081 i += len; 1136 i += len;
1082 sprintf(pg_result, "OK: dst6=%s", buf); 1137 sprintf(pg_result, "OK: dst6=%s", buf);
1083 return count; 1138 return count;
1084 } 1139 }
1085 if (!strcmp(name, "dst6_min")) { 1140 if (!strcmp(name, "dst6_min")) {
1086 len = strn_len(&user_buffer[i], sizeof(buf) - 1); 1141 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
1087 if (len < 0) return len; 1142 if (len < 0)
1143 return len;
1088 1144
1089 pkt_dev->flags |= F_IPV6; 1145 pkt_dev->flags |= F_IPV6;
1090 1146
1091 if (copy_from_user(buf, &user_buffer[i], len)) 1147 if (copy_from_user(buf, &user_buffer[i], len))
1092 return -EFAULT; 1148 return -EFAULT;
1093 buf[len] = 0; 1149 buf[len] = 0;
1094 1150
1095 scan_ip6(buf, pkt_dev->min_in6_daddr.s6_addr); 1151 scan_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
1096 fmt_ip6(buf, pkt_dev->min_in6_daddr.s6_addr); 1152 fmt_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
1097 1153
1098 ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->min_in6_daddr); 1154 ipv6_addr_copy(&pkt_dev->cur_in6_daddr,
1099 if(debug) 1155 &pkt_dev->min_in6_daddr);
1156 if (debug)
1100 printk("pktgen: dst6_min set to: %s\n", buf); 1157 printk("pktgen: dst6_min set to: %s\n", buf);
1101 1158
1102 i += len; 1159 i += len;
1103 sprintf(pg_result, "OK: dst6_min=%s", buf); 1160 sprintf(pg_result, "OK: dst6_min=%s", buf);
1104 return count; 1161 return count;
1105 } 1162 }
1106 if (!strcmp(name, "dst6_max")) { 1163 if (!strcmp(name, "dst6_max")) {
1107 len = strn_len(&user_buffer[i], sizeof(buf) - 1); 1164 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
1108 if (len < 0) return len; 1165 if (len < 0)
1166 return len;
1109 1167
1110 pkt_dev->flags |= F_IPV6; 1168 pkt_dev->flags |= F_IPV6;
1111 1169
1112 if (copy_from_user(buf, &user_buffer[i], len)) 1170 if (copy_from_user(buf, &user_buffer[i], len))
1113 return -EFAULT; 1171 return -EFAULT;
1114 buf[len] = 0; 1172 buf[len] = 0;
1115 1173
1116 scan_ip6(buf, pkt_dev->max_in6_daddr.s6_addr); 1174 scan_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
1117 fmt_ip6(buf, pkt_dev->max_in6_daddr.s6_addr); 1175 fmt_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
1118 1176
1119 if(debug) 1177 if (debug)
1120 printk("pktgen: dst6_max set to: %s\n", buf); 1178 printk("pktgen: dst6_max set to: %s\n", buf);
1121 1179
1122 i += len; 1180 i += len;
1123 sprintf(pg_result, "OK: dst6_max=%s", buf); 1181 sprintf(pg_result, "OK: dst6_max=%s", buf);
1124 return count; 1182 return count;
1125 } 1183 }
1126 if (!strcmp(name, "src6")) { 1184 if (!strcmp(name, "src6")) {
1127 len = strn_len(&user_buffer[i], sizeof(buf) - 1); 1185 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
1128 if (len < 0) return len; 1186 if (len < 0)
1187 return len;
1129 1188
1130 pkt_dev->flags |= F_IPV6; 1189 pkt_dev->flags |= F_IPV6;
1131 1190
1132 if (copy_from_user(buf, &user_buffer[i], len)) 1191 if (copy_from_user(buf, &user_buffer[i], len))
1133 return -EFAULT; 1192 return -EFAULT;
1134 buf[len] = 0; 1193 buf[len] = 0;
1135 1194
1136 scan_ip6(buf, pkt_dev->in6_saddr.s6_addr); 1195 scan_ip6(buf, pkt_dev->in6_saddr.s6_addr);
1137 fmt_ip6(buf, pkt_dev->in6_saddr.s6_addr); 1196 fmt_ip6(buf, pkt_dev->in6_saddr.s6_addr);
1138 1197
1139 ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &pkt_dev->in6_saddr); 1198 ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &pkt_dev->in6_saddr);
1140 1199
1141 if(debug) 1200 if (debug)
1142 printk("pktgen: src6 set to: %s\n", buf); 1201 printk("pktgen: src6 set to: %s\n", buf);
1143 1202
1144 i += len; 1203 i += len;
1145 sprintf(pg_result, "OK: src6=%s", buf); 1204 sprintf(pg_result, "OK: src6=%s", buf);
1146 return count; 1205 return count;
1147 } 1206 }
1148 if (!strcmp(name, "src_min")) { 1207 if (!strcmp(name, "src_min")) {
1149 len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_min) - 1); 1208 len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_min) - 1);
1150 if (len < 0) { return len; } 1209 if (len < 0) {
1151 if (copy_from_user(buf, &user_buffer[i], len)) 1210 return len;
1211 }
1212 if (copy_from_user(buf, &user_buffer[i], len))
1152 return -EFAULT; 1213 return -EFAULT;
1153 buf[len] = 0; 1214 buf[len] = 0;
1154 if (strcmp(buf, pkt_dev->src_min) != 0) { 1215 if (strcmp(buf, pkt_dev->src_min) != 0) {
1155 memset(pkt_dev->src_min, 0, sizeof(pkt_dev->src_min)); 1216 memset(pkt_dev->src_min, 0, sizeof(pkt_dev->src_min));
1156 strncpy(pkt_dev->src_min, buf, len); 1217 strncpy(pkt_dev->src_min, buf, len);
1157 pkt_dev->saddr_min = in_aton(pkt_dev->src_min); 1218 pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
1158 pkt_dev->cur_saddr = pkt_dev->saddr_min; 1219 pkt_dev->cur_saddr = pkt_dev->saddr_min;
1159 } 1220 }
1160 if(debug) 1221 if (debug)
1161 printk("pktgen: src_min set to: %s\n", pkt_dev->src_min); 1222 printk("pktgen: src_min set to: %s\n",
1223 pkt_dev->src_min);
1162 i += len; 1224 i += len;
1163 sprintf(pg_result, "OK: src_min=%s", pkt_dev->src_min); 1225 sprintf(pg_result, "OK: src_min=%s", pkt_dev->src_min);
1164 return count; 1226 return count;
1165 } 1227 }
1166 if (!strcmp(name, "src_max")) { 1228 if (!strcmp(name, "src_max")) {
1167 len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_max) - 1); 1229 len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_max) - 1);
1168 if (len < 0) { return len; } 1230 if (len < 0) {
1169 if (copy_from_user(buf, &user_buffer[i], len)) 1231 return len;
1232 }
1233 if (copy_from_user(buf, &user_buffer[i], len))
1170 return -EFAULT; 1234 return -EFAULT;
1171 buf[len] = 0; 1235 buf[len] = 0;
1172 if (strcmp(buf, pkt_dev->src_max) != 0) { 1236 if (strcmp(buf, pkt_dev->src_max) != 0) {
1173 memset(pkt_dev->src_max, 0, sizeof(pkt_dev->src_max)); 1237 memset(pkt_dev->src_max, 0, sizeof(pkt_dev->src_max));
1174 strncpy(pkt_dev->src_max, buf, len); 1238 strncpy(pkt_dev->src_max, buf, len);
1175 pkt_dev->saddr_max = in_aton(pkt_dev->src_max); 1239 pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
1176 pkt_dev->cur_saddr = pkt_dev->saddr_max; 1240 pkt_dev->cur_saddr = pkt_dev->saddr_max;
1177 } 1241 }
1178 if(debug) 1242 if (debug)
1179 printk("pktgen: src_max set to: %s\n", pkt_dev->src_max); 1243 printk("pktgen: src_max set to: %s\n",
1244 pkt_dev->src_max);
1180 i += len; 1245 i += len;
1181 sprintf(pg_result, "OK: src_max=%s", pkt_dev->src_max); 1246 sprintf(pg_result, "OK: src_max=%s", pkt_dev->src_max);
1182 return count; 1247 return count;
@@ -1186,15 +1251,17 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
1186 unsigned char old_dmac[ETH_ALEN]; 1251 unsigned char old_dmac[ETH_ALEN];
1187 unsigned char *m = pkt_dev->dst_mac; 1252 unsigned char *m = pkt_dev->dst_mac;
1188 memcpy(old_dmac, pkt_dev->dst_mac, ETH_ALEN); 1253 memcpy(old_dmac, pkt_dev->dst_mac, ETH_ALEN);
1189 1254
1190 len = strn_len(&user_buffer[i], sizeof(valstr) - 1); 1255 len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
1191 if (len < 0) { return len; } 1256 if (len < 0) {
1257 return len;
1258 }
1192 memset(valstr, 0, sizeof(valstr)); 1259 memset(valstr, 0, sizeof(valstr));
1193 if( copy_from_user(valstr, &user_buffer[i], len)) 1260 if (copy_from_user(valstr, &user_buffer[i], len))
1194 return -EFAULT; 1261 return -EFAULT;
1195 i += len; 1262 i += len;
1196 1263
1197 for(*m = 0;*v && m < pkt_dev->dst_mac + 6; v++) { 1264 for (*m = 0; *v && m < pkt_dev->dst_mac + 6; v++) {
1198 if (*v >= '0' && *v <= '9') { 1265 if (*v >= '0' && *v <= '9') {
1199 *m *= 16; 1266 *m *= 16;
1200 *m += *v - '0'; 1267 *m += *v - '0';
@@ -1216,7 +1283,7 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
1216 /* Set up Dest MAC */ 1283 /* Set up Dest MAC */
1217 if (compare_ether_addr(old_dmac, pkt_dev->dst_mac)) 1284 if (compare_ether_addr(old_dmac, pkt_dev->dst_mac))
1218 memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN); 1285 memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN);
1219 1286
1220 sprintf(pg_result, "OK: dstmac"); 1287 sprintf(pg_result, "OK: dstmac");
1221 return count; 1288 return count;
1222 } 1289 }
@@ -1225,13 +1292,15 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
1225 unsigned char *m = pkt_dev->src_mac; 1292 unsigned char *m = pkt_dev->src_mac;
1226 1293
1227 len = strn_len(&user_buffer[i], sizeof(valstr) - 1); 1294 len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
1228 if (len < 0) { return len; } 1295 if (len < 0) {
1296 return len;
1297 }
1229 memset(valstr, 0, sizeof(valstr)); 1298 memset(valstr, 0, sizeof(valstr));
1230 if( copy_from_user(valstr, &user_buffer[i], len)) 1299 if (copy_from_user(valstr, &user_buffer[i], len))
1231 return -EFAULT; 1300 return -EFAULT;
1232 i += len; 1301 i += len;
1233 1302
1234 for(*m = 0;*v && m < pkt_dev->src_mac + 6; v++) { 1303 for (*m = 0; *v && m < pkt_dev->src_mac + 6; v++) {
1235 if (*v >= '0' && *v <= '9') { 1304 if (*v >= '0' && *v <= '9') {
1236 *m *= 16; 1305 *m *= 16;
1237 *m += *v - '0'; 1306 *m += *v - '0';
@@ -1248,21 +1317,23 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
1248 m++; 1317 m++;
1249 *m = 0; 1318 *m = 0;
1250 } 1319 }
1251 } 1320 }
1252 1321
1253 sprintf(pg_result, "OK: srcmac"); 1322 sprintf(pg_result, "OK: srcmac");
1254 return count; 1323 return count;
1255 } 1324 }
1256 1325
1257 if (!strcmp(name, "clear_counters")) { 1326 if (!strcmp(name, "clear_counters")) {
1258 pktgen_clear_counters(pkt_dev); 1327 pktgen_clear_counters(pkt_dev);
1259 sprintf(pg_result, "OK: Clearing counters.\n"); 1328 sprintf(pg_result, "OK: Clearing counters.\n");
1260 return count; 1329 return count;
1261 } 1330 }
1262 1331
1263 if (!strcmp(name, "flows")) { 1332 if (!strcmp(name, "flows")) {
1264 len = num_arg(&user_buffer[i], 10, &value); 1333 len = num_arg(&user_buffer[i], 10, &value);
1265 if (len < 0) { return len; } 1334 if (len < 0) {
1335 return len;
1336 }
1266 i += len; 1337 i += len;
1267 if (value > MAX_CFLOWS) 1338 if (value > MAX_CFLOWS)
1268 value = MAX_CFLOWS; 1339 value = MAX_CFLOWS;
@@ -1274,13 +1345,15 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
1274 1345
1275 if (!strcmp(name, "flowlen")) { 1346 if (!strcmp(name, "flowlen")) {
1276 len = num_arg(&user_buffer[i], 10, &value); 1347 len = num_arg(&user_buffer[i], 10, &value);
1277 if (len < 0) { return len; } 1348 if (len < 0) {
1349 return len;
1350 }
1278 i += len; 1351 i += len;
1279 pkt_dev->lflow = value; 1352 pkt_dev->lflow = value;
1280 sprintf(pg_result, "OK: flowlen=%u", pkt_dev->lflow); 1353 sprintf(pg_result, "OK: flowlen=%u", pkt_dev->lflow);
1281 return count; 1354 return count;
1282 } 1355 }
1283 1356
1284 sprintf(pkt_dev->result, "No such parameter \"%s\"", name); 1357 sprintf(pkt_dev->result, "No such parameter \"%s\"", name);
1285 return -EINVAL; 1358 return -EINVAL;
1286} 1359}
@@ -1291,35 +1364,35 @@ static int pktgen_if_open(struct inode *inode, struct file *file)
1291} 1364}
1292 1365
1293static struct file_operations pktgen_if_fops = { 1366static struct file_operations pktgen_if_fops = {
1294 .owner = THIS_MODULE, 1367 .owner = THIS_MODULE,
1295 .open = pktgen_if_open, 1368 .open = pktgen_if_open,
1296 .read = seq_read, 1369 .read = seq_read,
1297 .llseek = seq_lseek, 1370 .llseek = seq_lseek,
1298 .write = pktgen_if_write, 1371 .write = pktgen_if_write,
1299 .release = single_release, 1372 .release = single_release,
1300}; 1373};
1301 1374
1302static int pktgen_thread_show(struct seq_file *seq, void *v) 1375static int pktgen_thread_show(struct seq_file *seq, void *v)
1303{ 1376{
1304 struct pktgen_thread *t = seq->private; 1377 struct pktgen_thread *t = seq->private;
1305 struct pktgen_dev *pkt_dev = NULL; 1378 struct pktgen_dev *pkt_dev;
1306 1379
1307 BUG_ON(!t); 1380 BUG_ON(!t);
1308 1381
1309 seq_printf(seq, "Name: %s max_before_softirq: %d\n", 1382 seq_printf(seq, "Name: %s max_before_softirq: %d\n",
1310 t->name, t->max_before_softirq); 1383 t->name, t->max_before_softirq);
1384
1385 seq_printf(seq, "Running: ");
1311 1386
1312 seq_printf(seq, "Running: "); 1387 if_lock(t);
1313 1388 list_for_each_entry(pkt_dev, &t->if_list, list)
1314 if_lock(t); 1389 if (pkt_dev->running)
1315 for(pkt_dev = t->if_list;pkt_dev; pkt_dev = pkt_dev->next)
1316 if(pkt_dev->running)
1317 seq_printf(seq, "%s ", pkt_dev->ifname); 1390 seq_printf(seq, "%s ", pkt_dev->ifname);
1318
1319 seq_printf(seq, "\nStopped: ");
1320 1391
1321 for(pkt_dev = t->if_list;pkt_dev; pkt_dev = pkt_dev->next) 1392 seq_printf(seq, "\nStopped: ");
1322 if(!pkt_dev->running) 1393
1394 list_for_each_entry(pkt_dev, &t->if_list, list)
1395 if (!pkt_dev->running)
1323 seq_printf(seq, "%s ", pkt_dev->ifname); 1396 seq_printf(seq, "%s ", pkt_dev->ifname);
1324 1397
1325 if (t->result[0]) 1398 if (t->result[0])
@@ -1327,30 +1400,30 @@ static int pktgen_thread_show(struct seq_file *seq, void *v)
1327 else 1400 else
1328 seq_printf(seq, "\nResult: NA\n"); 1401 seq_printf(seq, "\nResult: NA\n");
1329 1402
1330 if_unlock(t); 1403 if_unlock(t);
1331 1404
1332 return 0; 1405 return 0;
1333} 1406}
1334 1407
1335static ssize_t pktgen_thread_write(struct file *file, 1408static ssize_t pktgen_thread_write(struct file *file,
1336 const char __user *user_buffer, 1409 const char __user * user_buffer,
1337 size_t count, loff_t *offset) 1410 size_t count, loff_t * offset)
1338{ 1411{
1339 struct seq_file *seq = (struct seq_file *) file->private_data; 1412 struct seq_file *seq = (struct seq_file *)file->private_data;
1340 struct pktgen_thread *t = seq->private; 1413 struct pktgen_thread *t = seq->private;
1341 int i = 0, max, len, ret; 1414 int i = 0, max, len, ret;
1342 char name[40]; 1415 char name[40];
1343 char *pg_result; 1416 char *pg_result;
1344 unsigned long value = 0; 1417 unsigned long value = 0;
1345 1418
1346 if (count < 1) { 1419 if (count < 1) {
1347 // sprintf(pg_result, "Wrong command format"); 1420 // sprintf(pg_result, "Wrong command format");
1348 return -EINVAL; 1421 return -EINVAL;
1349 } 1422 }
1350 1423
1351 max = count - i; 1424 max = count - i;
1352 len = count_trail_chars(&user_buffer[i], max); 1425 len = count_trail_chars(&user_buffer[i], max);
1353 if (len < 0) 1426 if (len < 0)
1354 return len; 1427 return len;
1355 1428
1356 i += len; 1429 i += len;
@@ -1358,26 +1431,25 @@ static ssize_t pktgen_thread_write(struct file *file,
1358 /* Read variable name */ 1431 /* Read variable name */
1359 1432
1360 len = strn_len(&user_buffer[i], sizeof(name) - 1); 1433 len = strn_len(&user_buffer[i], sizeof(name) - 1);
1361 if (len < 0) 1434 if (len < 0)
1362 return len; 1435 return len;
1363 1436
1364 memset(name, 0, sizeof(name)); 1437 memset(name, 0, sizeof(name));
1365 if (copy_from_user(name, &user_buffer[i], len)) 1438 if (copy_from_user(name, &user_buffer[i], len))
1366 return -EFAULT; 1439 return -EFAULT;
1367 i += len; 1440 i += len;
1368 1441
1369 max = count -i; 1442 max = count - i;
1370 len = count_trail_chars(&user_buffer[i], max); 1443 len = count_trail_chars(&user_buffer[i], max);
1371 if (len < 0) 1444 if (len < 0)
1372 return len; 1445 return len;
1373 1446
1374 i += len; 1447 i += len;
1375 1448
1376 if (debug) 1449 if (debug)
1377 printk("pktgen: t=%s, count=%lu\n", name, 1450 printk("pktgen: t=%s, count=%lu\n", name, (unsigned long)count);
1378 (unsigned long) count);
1379 1451
1380 if(!t) { 1452 if (!t) {
1381 printk("pktgen: ERROR: No thread\n"); 1453 printk("pktgen: ERROR: No thread\n");
1382 ret = -EINVAL; 1454 ret = -EINVAL;
1383 goto out; 1455 goto out;
@@ -1385,48 +1457,47 @@ static ssize_t pktgen_thread_write(struct file *file,
1385 1457
1386 pg_result = &(t->result[0]); 1458 pg_result = &(t->result[0]);
1387 1459
1388 if (!strcmp(name, "add_device")) { 1460 if (!strcmp(name, "add_device")) {
1389 char f[32]; 1461 char f[32];
1390 memset(f, 0, 32); 1462 memset(f, 0, 32);
1391 len = strn_len(&user_buffer[i], sizeof(f) - 1); 1463 len = strn_len(&user_buffer[i], sizeof(f) - 1);
1392 if (len < 0) { 1464 if (len < 0) {
1393 ret = len; 1465 ret = len;
1394 goto out; 1466 goto out;
1395 } 1467 }
1396 if( copy_from_user(f, &user_buffer[i], len) ) 1468 if (copy_from_user(f, &user_buffer[i], len))
1397 return -EFAULT; 1469 return -EFAULT;
1398 i += len; 1470 i += len;
1399 thread_lock(); 1471 mutex_lock(&pktgen_thread_lock);
1400 pktgen_add_device(t, f); 1472 pktgen_add_device(t, f);
1401 thread_unlock(); 1473 mutex_unlock(&pktgen_thread_lock);
1402 ret = count; 1474 ret = count;
1403 sprintf(pg_result, "OK: add_device=%s", f); 1475 sprintf(pg_result, "OK: add_device=%s", f);
1404 goto out; 1476 goto out;
1405 } 1477 }
1406 1478
1407 if (!strcmp(name, "rem_device_all")) { 1479 if (!strcmp(name, "rem_device_all")) {
1408 thread_lock(); 1480 mutex_lock(&pktgen_thread_lock);
1409 t->control |= T_REMDEV; 1481 t->control |= T_REMDEVALL;
1410 thread_unlock(); 1482 mutex_unlock(&pktgen_thread_lock);
1411 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */ 1483 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
1412 ret = count; 1484 ret = count;
1413 sprintf(pg_result, "OK: rem_device_all"); 1485 sprintf(pg_result, "OK: rem_device_all");
1414 goto out; 1486 goto out;
1415 } 1487 }
1416 1488
1417 if (!strcmp(name, "max_before_softirq")) { 1489 if (!strcmp(name, "max_before_softirq")) {
1418 len = num_arg(&user_buffer[i], 10, &value); 1490 len = num_arg(&user_buffer[i], 10, &value);
1419 thread_lock(); 1491 mutex_lock(&pktgen_thread_lock);
1420 t->max_before_softirq = value; 1492 t->max_before_softirq = value;
1421 thread_unlock(); 1493 mutex_unlock(&pktgen_thread_lock);
1422 ret = count; 1494 ret = count;
1423 sprintf(pg_result, "OK: max_before_softirq=%lu", value); 1495 sprintf(pg_result, "OK: max_before_softirq=%lu", value);
1424 goto out; 1496 goto out;
1425 } 1497 }
1426 1498
1427 ret = -EINVAL; 1499 ret = -EINVAL;
1428 out: 1500out:
1429
1430 return ret; 1501 return ret;
1431} 1502}
1432 1503
@@ -1436,47 +1507,78 @@ static int pktgen_thread_open(struct inode *inode, struct file *file)
1436} 1507}
1437 1508
1438static struct file_operations pktgen_thread_fops = { 1509static struct file_operations pktgen_thread_fops = {
1439 .owner = THIS_MODULE, 1510 .owner = THIS_MODULE,
1440 .open = pktgen_thread_open, 1511 .open = pktgen_thread_open,
1441 .read = seq_read, 1512 .read = seq_read,
1442 .llseek = seq_lseek, 1513 .llseek = seq_lseek,
1443 .write = pktgen_thread_write, 1514 .write = pktgen_thread_write,
1444 .release = single_release, 1515 .release = single_release,
1445}; 1516};
1446 1517
1447/* Think find or remove for NN */ 1518/* Think find or remove for NN */
1448static struct pktgen_dev *__pktgen_NN_threads(const char* ifname, int remove) 1519static struct pktgen_dev *__pktgen_NN_threads(const char *ifname, int remove)
1449{ 1520{
1450 struct pktgen_thread *t; 1521 struct pktgen_thread *t;
1451 struct pktgen_dev *pkt_dev = NULL; 1522 struct pktgen_dev *pkt_dev = NULL;
1452 1523
1453 t = pktgen_threads; 1524 list_for_each_entry(t, &pktgen_threads, th_list) {
1454
1455 while (t) {
1456 pkt_dev = pktgen_find_dev(t, ifname); 1525 pkt_dev = pktgen_find_dev(t, ifname);
1457 if (pkt_dev) { 1526 if (pkt_dev) {
1458 if(remove) { 1527 if (remove) {
1459 if_lock(t); 1528 if_lock(t);
1460 pktgen_remove_device(t, pkt_dev); 1529 pkt_dev->removal_mark = 1;
1461 if_unlock(t); 1530 t->control |= T_REMDEV;
1462 } 1531 if_unlock(t);
1532 }
1463 break; 1533 break;
1464 } 1534 }
1465 t = t->next;
1466 } 1535 }
1467 return pkt_dev; 1536 return pkt_dev;
1468} 1537}
1469 1538
1470static struct pktgen_dev *pktgen_NN_threads(const char* ifname, int remove) 1539/*
1540 * mark a device for removal
1541 */
1542static int pktgen_mark_device(const char *ifname)
1471{ 1543{
1472 struct pktgen_dev *pkt_dev = NULL; 1544 struct pktgen_dev *pkt_dev = NULL;
1473 thread_lock(); 1545 const int max_tries = 10, msec_per_try = 125;
1474 pkt_dev = __pktgen_NN_threads(ifname, remove); 1546 int i = 0;
1475 thread_unlock(); 1547 int ret = 0;
1476 return pkt_dev; 1548
1549 mutex_lock(&pktgen_thread_lock);
1550 PG_DEBUG(printk("pktgen: pktgen_mark_device marking %s for removal\n",
1551 ifname));
1552
1553 while (1) {
1554
1555 pkt_dev = __pktgen_NN_threads(ifname, REMOVE);
1556 if (pkt_dev == NULL)
1557 break; /* success */
1558
1559 mutex_unlock(&pktgen_thread_lock);
1560 PG_DEBUG(printk("pktgen: pktgen_mark_device waiting for %s "
1561 "to disappear....\n", ifname));
1562 schedule_timeout_interruptible(msecs_to_jiffies(msec_per_try));
1563 mutex_lock(&pktgen_thread_lock);
1564
1565 if (++i >= max_tries) {
1566 printk("pktgen_mark_device: timed out after waiting "
1567 "%d msec for device %s to be removed\n",
1568 msec_per_try * i, ifname);
1569 ret = 1;
1570 break;
1571 }
1572
1573 }
1574
1575 mutex_unlock(&pktgen_thread_lock);
1576
1577 return ret;
1477} 1578}
1478 1579
1479static int pktgen_device_event(struct notifier_block *unused, unsigned long event, void *ptr) 1580static int pktgen_device_event(struct notifier_block *unused,
1581 unsigned long event, void *ptr)
1480{ 1582{
1481 struct net_device *dev = (struct net_device *)(ptr); 1583 struct net_device *dev = (struct net_device *)(ptr);
1482 1584
@@ -1491,9 +1593,9 @@ static int pktgen_device_event(struct notifier_block *unused, unsigned long even
1491 case NETDEV_UP: 1593 case NETDEV_UP:
1492 /* Ignore for now */ 1594 /* Ignore for now */
1493 break; 1595 break;
1494 1596
1495 case NETDEV_UNREGISTER: 1597 case NETDEV_UNREGISTER:
1496 pktgen_NN_threads(dev->name, REMOVE); 1598 pktgen_mark_device(dev->name);
1497 break; 1599 break;
1498 }; 1600 };
1499 1601
@@ -1502,15 +1604,16 @@ static int pktgen_device_event(struct notifier_block *unused, unsigned long even
1502 1604
1503/* Associate pktgen_dev with a device. */ 1605/* Associate pktgen_dev with a device. */
1504 1606
1505static struct net_device* pktgen_setup_dev(struct pktgen_dev *pkt_dev) { 1607static struct net_device *pktgen_setup_dev(struct pktgen_dev *pkt_dev)
1608{
1506 struct net_device *odev; 1609 struct net_device *odev;
1507 1610
1508 /* Clean old setups */ 1611 /* Clean old setups */
1509 1612
1510 if (pkt_dev->odev) { 1613 if (pkt_dev->odev) {
1511 dev_put(pkt_dev->odev); 1614 dev_put(pkt_dev->odev);
1512 pkt_dev->odev = NULL; 1615 pkt_dev->odev = NULL;
1513 } 1616 }
1514 1617
1515 odev = dev_get_by_name(pkt_dev->ifname); 1618 odev = dev_get_by_name(pkt_dev->ifname);
1516 1619
@@ -1519,7 +1622,8 @@ static struct net_device* pktgen_setup_dev(struct pktgen_dev *pkt_dev) {
1519 goto out; 1622 goto out;
1520 } 1623 }
1521 if (odev->type != ARPHRD_ETHER) { 1624 if (odev->type != ARPHRD_ETHER) {
1522 printk("pktgen: not an ethernet device: \"%s\"\n", pkt_dev->ifname); 1625 printk("pktgen: not an ethernet device: \"%s\"\n",
1626 pkt_dev->ifname);
1523 goto out_put; 1627 goto out_put;
1524 } 1628 }
1525 if (!netif_running(odev)) { 1629 if (!netif_running(odev)) {
@@ -1527,13 +1631,13 @@ static struct net_device* pktgen_setup_dev(struct pktgen_dev *pkt_dev) {
1527 goto out_put; 1631 goto out_put;
1528 } 1632 }
1529 pkt_dev->odev = odev; 1633 pkt_dev->odev = odev;
1530 1634
1531 return pkt_dev->odev; 1635 return pkt_dev->odev;
1532 1636
1533out_put: 1637out_put:
1534 dev_put(odev); 1638 dev_put(odev);
1535out: 1639out:
1536 return NULL; 1640 return NULL;
1537 1641
1538} 1642}
1539 1643
@@ -1543,59 +1647,64 @@ out:
1543static void pktgen_setup_inject(struct pktgen_dev *pkt_dev) 1647static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
1544{ 1648{
1545 /* Try once more, just in case it works now. */ 1649 /* Try once more, just in case it works now. */
1546 if (!pkt_dev->odev) 1650 if (!pkt_dev->odev)
1547 pktgen_setup_dev(pkt_dev); 1651 pktgen_setup_dev(pkt_dev);
1548 1652
1549 if (!pkt_dev->odev) { 1653 if (!pkt_dev->odev) {
1550 printk("pktgen: ERROR: pkt_dev->odev == NULL in setup_inject.\n"); 1654 printk("pktgen: ERROR: pkt_dev->odev == NULL in setup_inject.\n");
1551 sprintf(pkt_dev->result, "ERROR: pkt_dev->odev == NULL in setup_inject.\n"); 1655 sprintf(pkt_dev->result,
1552 return; 1656 "ERROR: pkt_dev->odev == NULL in setup_inject.\n");
1553 } 1657 return;
1554 1658 }
1555 /* Default to the interface's mac if not explicitly set. */ 1659
1660 /* Default to the interface's mac if not explicitly set. */
1556 1661
1557 if (is_zero_ether_addr(pkt_dev->src_mac)) 1662 if (is_zero_ether_addr(pkt_dev->src_mac))
1558 memcpy(&(pkt_dev->hh[6]), pkt_dev->odev->dev_addr, ETH_ALEN); 1663 memcpy(&(pkt_dev->hh[6]), pkt_dev->odev->dev_addr, ETH_ALEN);
1559 1664
1560 /* Set up Dest MAC */ 1665 /* Set up Dest MAC */
1561 memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN); 1666 memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN);
1562 1667
1563 /* Set up pkt size */ 1668 /* Set up pkt size */
1564 pkt_dev->cur_pkt_size = pkt_dev->min_pkt_size; 1669 pkt_dev->cur_pkt_size = pkt_dev->min_pkt_size;
1565 1670
1566 if(pkt_dev->flags & F_IPV6) { 1671 if (pkt_dev->flags & F_IPV6) {
1567 /* 1672 /*
1568 * Skip this automatic address setting until locks or functions 1673 * Skip this automatic address setting until locks or functions
1569 * gets exported 1674 * gets exported
1570 */ 1675 */
1571 1676
1572#ifdef NOTNOW 1677#ifdef NOTNOW
1573 int i, set = 0, err=1; 1678 int i, set = 0, err = 1;
1574 struct inet6_dev *idev; 1679 struct inet6_dev *idev;
1575 1680
1576 for(i=0; i< IN6_ADDR_HSIZE; i++) 1681 for (i = 0; i < IN6_ADDR_HSIZE; i++)
1577 if(pkt_dev->cur_in6_saddr.s6_addr[i]) { 1682 if (pkt_dev->cur_in6_saddr.s6_addr[i]) {
1578 set = 1; 1683 set = 1;
1579 break; 1684 break;
1580 } 1685 }
1581 1686
1582 if(!set) { 1687 if (!set) {
1583 1688
1584 /* 1689 /*
1585 * Use linklevel address if unconfigured. 1690 * Use linklevel address if unconfigured.
1586 * 1691 *
1587 * use ipv6_get_lladdr if/when it's get exported 1692 * use ipv6_get_lladdr if/when it's get exported
1588 */ 1693 */
1589 1694
1590
1591 read_lock(&addrconf_lock); 1695 read_lock(&addrconf_lock);
1592 if ((idev = __in6_dev_get(pkt_dev->odev)) != NULL) { 1696 if ((idev = __in6_dev_get(pkt_dev->odev)) != NULL) {
1593 struct inet6_ifaddr *ifp; 1697 struct inet6_ifaddr *ifp;
1594 1698
1595 read_lock_bh(&idev->lock); 1699 read_lock_bh(&idev->lock);
1596 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) { 1700 for (ifp = idev->addr_list; ifp;
1597 if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) { 1701 ifp = ifp->if_next) {
1598 ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &ifp->addr); 1702 if (ifp->scope == IFA_LINK
1703 && !(ifp->
1704 flags & IFA_F_TENTATIVE)) {
1705 ipv6_addr_copy(&pkt_dev->
1706 cur_in6_saddr,
1707 &ifp->addr);
1599 err = 0; 1708 err = 0;
1600 break; 1709 break;
1601 } 1710 }
@@ -1603,28 +1712,28 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
1603 read_unlock_bh(&idev->lock); 1712 read_unlock_bh(&idev->lock);
1604 } 1713 }
1605 read_unlock(&addrconf_lock); 1714 read_unlock(&addrconf_lock);
1606 if(err) printk("pktgen: ERROR: IPv6 link address not availble.\n"); 1715 if (err)
1716 printk("pktgen: ERROR: IPv6 link address not availble.\n");
1607 } 1717 }
1608#endif 1718#endif
1609 } 1719 } else {
1610 else {
1611 pkt_dev->saddr_min = 0; 1720 pkt_dev->saddr_min = 0;
1612 pkt_dev->saddr_max = 0; 1721 pkt_dev->saddr_max = 0;
1613 if (strlen(pkt_dev->src_min) == 0) { 1722 if (strlen(pkt_dev->src_min) == 0) {
1614 1723
1615 struct in_device *in_dev; 1724 struct in_device *in_dev;
1616 1725
1617 rcu_read_lock(); 1726 rcu_read_lock();
1618 in_dev = __in_dev_get_rcu(pkt_dev->odev); 1727 in_dev = __in_dev_get_rcu(pkt_dev->odev);
1619 if (in_dev) { 1728 if (in_dev) {
1620 if (in_dev->ifa_list) { 1729 if (in_dev->ifa_list) {
1621 pkt_dev->saddr_min = in_dev->ifa_list->ifa_address; 1730 pkt_dev->saddr_min =
1731 in_dev->ifa_list->ifa_address;
1622 pkt_dev->saddr_max = pkt_dev->saddr_min; 1732 pkt_dev->saddr_max = pkt_dev->saddr_min;
1623 } 1733 }
1624 } 1734 }
1625 rcu_read_unlock(); 1735 rcu_read_unlock();
1626 } 1736 } else {
1627 else {
1628 pkt_dev->saddr_min = in_aton(pkt_dev->src_min); 1737 pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
1629 pkt_dev->saddr_max = in_aton(pkt_dev->src_max); 1738 pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
1630 } 1739 }
@@ -1632,13 +1741,13 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
1632 pkt_dev->daddr_min = in_aton(pkt_dev->dst_min); 1741 pkt_dev->daddr_min = in_aton(pkt_dev->dst_min);
1633 pkt_dev->daddr_max = in_aton(pkt_dev->dst_max); 1742 pkt_dev->daddr_max = in_aton(pkt_dev->dst_max);
1634 } 1743 }
1635 /* Initialize current values. */ 1744 /* Initialize current values. */
1636 pkt_dev->cur_dst_mac_offset = 0; 1745 pkt_dev->cur_dst_mac_offset = 0;
1637 pkt_dev->cur_src_mac_offset = 0; 1746 pkt_dev->cur_src_mac_offset = 0;
1638 pkt_dev->cur_saddr = pkt_dev->saddr_min; 1747 pkt_dev->cur_saddr = pkt_dev->saddr_min;
1639 pkt_dev->cur_daddr = pkt_dev->daddr_min; 1748 pkt_dev->cur_daddr = pkt_dev->daddr_min;
1640 pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min; 1749 pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min;
1641 pkt_dev->cur_udp_src = pkt_dev->udp_src_min; 1750 pkt_dev->cur_udp_src = pkt_dev->udp_src_min;
1642 pkt_dev->nflows = 0; 1751 pkt_dev->nflows = 0;
1643} 1752}
1644 1753
@@ -1651,7 +1760,7 @@ static void spin(struct pktgen_dev *pkt_dev, __u64 spin_until_us)
1651 printk(KERN_INFO "sleeping for %d\n", (int)(spin_until_us - now)); 1760 printk(KERN_INFO "sleeping for %d\n", (int)(spin_until_us - now));
1652 while (now < spin_until_us) { 1761 while (now < spin_until_us) {
1653 /* TODO: optimize sleeping behavior */ 1762 /* TODO: optimize sleeping behavior */
1654 if (spin_until_us - now > jiffies_to_usecs(1)+1) 1763 if (spin_until_us - now > jiffies_to_usecs(1) + 1)
1655 schedule_timeout_interruptible(1); 1764 schedule_timeout_interruptible(1);
1656 else if (spin_until_us - now > 100) { 1765 else if (spin_until_us - now > 100) {
1657 do_softirq(); 1766 do_softirq();
@@ -1667,102 +1776,110 @@ static void spin(struct pktgen_dev *pkt_dev, __u64 spin_until_us)
1667 pkt_dev->idle_acc += now - start; 1776 pkt_dev->idle_acc += now - start;
1668} 1777}
1669 1778
1670
1671/* Increment/randomize headers according to flags and current values 1779/* Increment/randomize headers according to flags and current values
1672 * for IP src/dest, UDP src/dst port, MAC-Addr src/dst 1780 * for IP src/dest, UDP src/dst port, MAC-Addr src/dst
1673 */ 1781 */
1674static void mod_cur_headers(struct pktgen_dev *pkt_dev) { 1782static void mod_cur_headers(struct pktgen_dev *pkt_dev)
1675 __u32 imn; 1783{
1676 __u32 imx; 1784 __u32 imn;
1677 int flow = 0; 1785 __u32 imx;
1786 int flow = 0;
1678 1787
1679 if(pkt_dev->cflows) { 1788 if (pkt_dev->cflows) {
1680 flow = pktgen_random() % pkt_dev->cflows; 1789 flow = pktgen_random() % pkt_dev->cflows;
1681 1790
1682 if (pkt_dev->flows[flow].count > pkt_dev->lflow) 1791 if (pkt_dev->flows[flow].count > pkt_dev->lflow)
1683 pkt_dev->flows[flow].count = 0; 1792 pkt_dev->flows[flow].count = 0;
1684 } 1793 }
1685
1686 1794
1687 /* Deal with source MAC */ 1795 /* Deal with source MAC */
1688 if (pkt_dev->src_mac_count > 1) { 1796 if (pkt_dev->src_mac_count > 1) {
1689 __u32 mc; 1797 __u32 mc;
1690 __u32 tmp; 1798 __u32 tmp;
1691 1799
1692 if (pkt_dev->flags & F_MACSRC_RND) 1800 if (pkt_dev->flags & F_MACSRC_RND)
1693 mc = pktgen_random() % (pkt_dev->src_mac_count); 1801 mc = pktgen_random() % (pkt_dev->src_mac_count);
1694 else { 1802 else {
1695 mc = pkt_dev->cur_src_mac_offset++; 1803 mc = pkt_dev->cur_src_mac_offset++;
1696 if (pkt_dev->cur_src_mac_offset > pkt_dev->src_mac_count) 1804 if (pkt_dev->cur_src_mac_offset >
1697 pkt_dev->cur_src_mac_offset = 0; 1805 pkt_dev->src_mac_count)
1698 } 1806 pkt_dev->cur_src_mac_offset = 0;
1699 1807 }
1700 tmp = pkt_dev->src_mac[5] + (mc & 0xFF); 1808
1701 pkt_dev->hh[11] = tmp; 1809 tmp = pkt_dev->src_mac[5] + (mc & 0xFF);
1702 tmp = (pkt_dev->src_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8)); 1810 pkt_dev->hh[11] = tmp;
1703 pkt_dev->hh[10] = tmp; 1811 tmp = (pkt_dev->src_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8));
1704 tmp = (pkt_dev->src_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8)); 1812 pkt_dev->hh[10] = tmp;
1705 pkt_dev->hh[9] = tmp; 1813 tmp = (pkt_dev->src_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8));
1706 tmp = (pkt_dev->src_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8)); 1814 pkt_dev->hh[9] = tmp;
1707 pkt_dev->hh[8] = tmp; 1815 tmp = (pkt_dev->src_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8));
1708 tmp = (pkt_dev->src_mac[1] + (tmp >> 8)); 1816 pkt_dev->hh[8] = tmp;
1709 pkt_dev->hh[7] = tmp; 1817 tmp = (pkt_dev->src_mac[1] + (tmp >> 8));
1710 } 1818 pkt_dev->hh[7] = tmp;
1711 1819 }
1712 /* Deal with Destination MAC */ 1820
1713 if (pkt_dev->dst_mac_count > 1) { 1821 /* Deal with Destination MAC */
1714 __u32 mc; 1822 if (pkt_dev->dst_mac_count > 1) {
1715 __u32 tmp; 1823 __u32 mc;
1716 1824 __u32 tmp;
1717 if (pkt_dev->flags & F_MACDST_RND) 1825
1718 mc = pktgen_random() % (pkt_dev->dst_mac_count); 1826 if (pkt_dev->flags & F_MACDST_RND)
1719 1827 mc = pktgen_random() % (pkt_dev->dst_mac_count);
1720 else { 1828
1721 mc = pkt_dev->cur_dst_mac_offset++; 1829 else {
1722 if (pkt_dev->cur_dst_mac_offset > pkt_dev->dst_mac_count) { 1830 mc = pkt_dev->cur_dst_mac_offset++;
1723 pkt_dev->cur_dst_mac_offset = 0; 1831 if (pkt_dev->cur_dst_mac_offset >
1724 } 1832 pkt_dev->dst_mac_count) {
1725 } 1833 pkt_dev->cur_dst_mac_offset = 0;
1726 1834 }
1727 tmp = pkt_dev->dst_mac[5] + (mc & 0xFF); 1835 }
1728 pkt_dev->hh[5] = tmp; 1836
1729 tmp = (pkt_dev->dst_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8)); 1837 tmp = pkt_dev->dst_mac[5] + (mc & 0xFF);
1730 pkt_dev->hh[4] = tmp; 1838 pkt_dev->hh[5] = tmp;
1731 tmp = (pkt_dev->dst_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8)); 1839 tmp = (pkt_dev->dst_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8));
1732 pkt_dev->hh[3] = tmp; 1840 pkt_dev->hh[4] = tmp;
1733 tmp = (pkt_dev->dst_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8)); 1841 tmp = (pkt_dev->dst_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8));
1734 pkt_dev->hh[2] = tmp; 1842 pkt_dev->hh[3] = tmp;
1735 tmp = (pkt_dev->dst_mac[1] + (tmp >> 8)); 1843 tmp = (pkt_dev->dst_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8));
1736 pkt_dev->hh[1] = tmp; 1844 pkt_dev->hh[2] = tmp;
1737 } 1845 tmp = (pkt_dev->dst_mac[1] + (tmp >> 8));
1738 1846 pkt_dev->hh[1] = tmp;
1739 if (pkt_dev->udp_src_min < pkt_dev->udp_src_max) { 1847 }
1740 if (pkt_dev->flags & F_UDPSRC_RND) 1848
1741 pkt_dev->cur_udp_src = ((pktgen_random() % (pkt_dev->udp_src_max - pkt_dev->udp_src_min)) + pkt_dev->udp_src_min); 1849 if (pkt_dev->udp_src_min < pkt_dev->udp_src_max) {
1742 1850 if (pkt_dev->flags & F_UDPSRC_RND)
1743 else { 1851 pkt_dev->cur_udp_src =
1852 ((pktgen_random() %
1853 (pkt_dev->udp_src_max - pkt_dev->udp_src_min)) +
1854 pkt_dev->udp_src_min);
1855
1856 else {
1744 pkt_dev->cur_udp_src++; 1857 pkt_dev->cur_udp_src++;
1745 if (pkt_dev->cur_udp_src >= pkt_dev->udp_src_max) 1858 if (pkt_dev->cur_udp_src >= pkt_dev->udp_src_max)
1746 pkt_dev->cur_udp_src = pkt_dev->udp_src_min; 1859 pkt_dev->cur_udp_src = pkt_dev->udp_src_min;
1747 } 1860 }
1748 } 1861 }
1749 1862
1750 if (pkt_dev->udp_dst_min < pkt_dev->udp_dst_max) { 1863 if (pkt_dev->udp_dst_min < pkt_dev->udp_dst_max) {
1751 if (pkt_dev->flags & F_UDPDST_RND) { 1864 if (pkt_dev->flags & F_UDPDST_RND) {
1752 pkt_dev->cur_udp_dst = ((pktgen_random() % (pkt_dev->udp_dst_max - pkt_dev->udp_dst_min)) + pkt_dev->udp_dst_min); 1865 pkt_dev->cur_udp_dst =
1753 } 1866 ((pktgen_random() %
1754 else { 1867 (pkt_dev->udp_dst_max - pkt_dev->udp_dst_min)) +
1868 pkt_dev->udp_dst_min);
1869 } else {
1755 pkt_dev->cur_udp_dst++; 1870 pkt_dev->cur_udp_dst++;
1756 if (pkt_dev->cur_udp_dst >= pkt_dev->udp_dst_max) 1871 if (pkt_dev->cur_udp_dst >= pkt_dev->udp_dst_max)
1757 pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min; 1872 pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min;
1758 } 1873 }
1759 } 1874 }
1760 1875
1761 if (!(pkt_dev->flags & F_IPV6)) { 1876 if (!(pkt_dev->flags & F_IPV6)) {
1762 1877
1763 if ((imn = ntohl(pkt_dev->saddr_min)) < (imx = ntohl(pkt_dev->saddr_max))) { 1878 if ((imn = ntohl(pkt_dev->saddr_min)) < (imx =
1879 ntohl(pkt_dev->
1880 saddr_max))) {
1764 __u32 t; 1881 __u32 t;
1765 if (pkt_dev->flags & F_IPSRC_RND) 1882 if (pkt_dev->flags & F_IPSRC_RND)
1766 t = ((pktgen_random() % (imx - imn)) + imn); 1883 t = ((pktgen_random() % (imx - imn)) + imn);
1767 else { 1884 else {
1768 t = ntohl(pkt_dev->cur_saddr); 1885 t = ntohl(pkt_dev->cur_saddr);
@@ -1773,25 +1890,32 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
1773 } 1890 }
1774 pkt_dev->cur_saddr = htonl(t); 1891 pkt_dev->cur_saddr = htonl(t);
1775 } 1892 }
1776 1893
1777 if (pkt_dev->cflows && pkt_dev->flows[flow].count != 0) { 1894 if (pkt_dev->cflows && pkt_dev->flows[flow].count != 0) {
1778 pkt_dev->cur_daddr = pkt_dev->flows[flow].cur_daddr; 1895 pkt_dev->cur_daddr = pkt_dev->flows[flow].cur_daddr;
1779 } else { 1896 } else {
1780 1897
1781 if ((imn = ntohl(pkt_dev->daddr_min)) < (imx = ntohl(pkt_dev->daddr_max))) { 1898 if ((imn = ntohl(pkt_dev->daddr_min)) < (imx =
1899 ntohl(pkt_dev->
1900 daddr_max)))
1901 {
1782 __u32 t; 1902 __u32 t;
1783 if (pkt_dev->flags & F_IPDST_RND) { 1903 if (pkt_dev->flags & F_IPDST_RND) {
1784 1904
1785 t = ((pktgen_random() % (imx - imn)) + imn); 1905 t = ((pktgen_random() % (imx - imn)) +
1906 imn);
1786 t = htonl(t); 1907 t = htonl(t);
1787 1908
1788 while( LOOPBACK(t) || MULTICAST(t) || BADCLASS(t) || ZERONET(t) || LOCAL_MCAST(t) ) { 1909 while (LOOPBACK(t) || MULTICAST(t)
1789 t = ((pktgen_random() % (imx - imn)) + imn); 1910 || BADCLASS(t) || ZERONET(t)
1911 || LOCAL_MCAST(t)) {
1912 t = ((pktgen_random() %
1913 (imx - imn)) + imn);
1790 t = htonl(t); 1914 t = htonl(t);
1791 } 1915 }
1792 pkt_dev->cur_daddr = t; 1916 pkt_dev->cur_daddr = t;
1793 } 1917 }
1794 1918
1795 else { 1919 else {
1796 t = ntohl(pkt_dev->cur_daddr); 1920 t = ntohl(pkt_dev->cur_daddr);
1797 t++; 1921 t++;
@@ -1801,60 +1925,59 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
1801 pkt_dev->cur_daddr = htonl(t); 1925 pkt_dev->cur_daddr = htonl(t);
1802 } 1926 }
1803 } 1927 }
1804 if(pkt_dev->cflows) { 1928 if (pkt_dev->cflows) {
1805 pkt_dev->flows[flow].cur_daddr = pkt_dev->cur_daddr; 1929 pkt_dev->flows[flow].cur_daddr =
1930 pkt_dev->cur_daddr;
1806 pkt_dev->nflows++; 1931 pkt_dev->nflows++;
1807 } 1932 }
1808 } 1933 }
1809 } 1934 } else { /* IPV6 * */
1810 else /* IPV6 * */ 1935
1811 { 1936 if (pkt_dev->min_in6_daddr.s6_addr32[0] == 0 &&
1812 if(pkt_dev->min_in6_daddr.s6_addr32[0] == 0 && 1937 pkt_dev->min_in6_daddr.s6_addr32[1] == 0 &&
1813 pkt_dev->min_in6_daddr.s6_addr32[1] == 0 && 1938 pkt_dev->min_in6_daddr.s6_addr32[2] == 0 &&
1814 pkt_dev->min_in6_daddr.s6_addr32[2] == 0 && 1939 pkt_dev->min_in6_daddr.s6_addr32[3] == 0) ;
1815 pkt_dev->min_in6_daddr.s6_addr32[3] == 0);
1816 else { 1940 else {
1817 int i; 1941 int i;
1818 1942
1819 /* Only random destinations yet */ 1943 /* Only random destinations yet */
1820 1944
1821 for(i=0; i < 4; i++) { 1945 for (i = 0; i < 4; i++) {
1822 pkt_dev->cur_in6_daddr.s6_addr32[i] = 1946 pkt_dev->cur_in6_daddr.s6_addr32[i] =
1823 ((pktgen_random() | 1947 ((pktgen_random() |
1824 pkt_dev->min_in6_daddr.s6_addr32[i]) & 1948 pkt_dev->min_in6_daddr.s6_addr32[i]) &
1825 pkt_dev->max_in6_daddr.s6_addr32[i]); 1949 pkt_dev->max_in6_daddr.s6_addr32[i]);
1826 } 1950 }
1827 } 1951 }
1828 } 1952 }
1829 1953
1830 if (pkt_dev->min_pkt_size < pkt_dev->max_pkt_size) { 1954 if (pkt_dev->min_pkt_size < pkt_dev->max_pkt_size) {
1831 __u32 t; 1955 __u32 t;
1832 if (pkt_dev->flags & F_TXSIZE_RND) { 1956 if (pkt_dev->flags & F_TXSIZE_RND) {
1833 t = ((pktgen_random() % (pkt_dev->max_pkt_size - pkt_dev->min_pkt_size)) 1957 t = ((pktgen_random() %
1834 + pkt_dev->min_pkt_size); 1958 (pkt_dev->max_pkt_size - pkt_dev->min_pkt_size))
1835 } 1959 + pkt_dev->min_pkt_size);
1836 else { 1960 } else {
1837 t = pkt_dev->cur_pkt_size + 1; 1961 t = pkt_dev->cur_pkt_size + 1;
1838 if (t > pkt_dev->max_pkt_size) 1962 if (t > pkt_dev->max_pkt_size)
1839 t = pkt_dev->min_pkt_size; 1963 t = pkt_dev->min_pkt_size;
1840 } 1964 }
1841 pkt_dev->cur_pkt_size = t; 1965 pkt_dev->cur_pkt_size = t;
1842 } 1966 }
1843 1967
1844 pkt_dev->flows[flow].count++; 1968 pkt_dev->flows[flow].count++;
1845} 1969}
1846 1970
1847 1971static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
1848static struct sk_buff *fill_packet_ipv4(struct net_device *odev, 1972 struct pktgen_dev *pkt_dev)
1849 struct pktgen_dev *pkt_dev)
1850{ 1973{
1851 struct sk_buff *skb = NULL; 1974 struct sk_buff *skb = NULL;
1852 __u8 *eth; 1975 __u8 *eth;
1853 struct udphdr *udph; 1976 struct udphdr *udph;
1854 int datalen, iplen; 1977 int datalen, iplen;
1855 struct iphdr *iph; 1978 struct iphdr *iph;
1856 struct pktgen_hdr *pgh = NULL; 1979 struct pktgen_hdr *pgh = NULL;
1857 1980
1858 /* Update any of the values, used when we're incrementing various 1981 /* Update any of the values, used when we're incrementing various
1859 * fields. 1982 * fields.
1860 */ 1983 */
@@ -1875,47 +1998,47 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
1875 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr)); 1998 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
1876 1999
1877 memcpy(eth, pkt_dev->hh, 12); 2000 memcpy(eth, pkt_dev->hh, 12);
1878 *(u16*)&eth[12] = __constant_htons(ETH_P_IP); 2001 *(u16 *) & eth[12] = __constant_htons(ETH_P_IP);
1879 2002
1880 datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8; /* Eth + IPh + UDPh */ 2003 datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8; /* Eth + IPh + UDPh */
1881 if (datalen < sizeof(struct pktgen_hdr)) 2004 if (datalen < sizeof(struct pktgen_hdr))
1882 datalen = sizeof(struct pktgen_hdr); 2005 datalen = sizeof(struct pktgen_hdr);
1883 2006
1884 udph->source = htons(pkt_dev->cur_udp_src); 2007 udph->source = htons(pkt_dev->cur_udp_src);
1885 udph->dest = htons(pkt_dev->cur_udp_dst); 2008 udph->dest = htons(pkt_dev->cur_udp_dst);
1886 udph->len = htons(datalen + 8); /* DATA + udphdr */ 2009 udph->len = htons(datalen + 8); /* DATA + udphdr */
1887 udph->check = 0; /* No checksum */ 2010 udph->check = 0; /* No checksum */
1888 2011
1889 iph->ihl = 5; 2012 iph->ihl = 5;
1890 iph->version = 4; 2013 iph->version = 4;
1891 iph->ttl = 32; 2014 iph->ttl = 32;
1892 iph->tos = 0; 2015 iph->tos = 0;
1893 iph->protocol = IPPROTO_UDP; /* UDP */ 2016 iph->protocol = IPPROTO_UDP; /* UDP */
1894 iph->saddr = pkt_dev->cur_saddr; 2017 iph->saddr = pkt_dev->cur_saddr;
1895 iph->daddr = pkt_dev->cur_daddr; 2018 iph->daddr = pkt_dev->cur_daddr;
1896 iph->frag_off = 0; 2019 iph->frag_off = 0;
1897 iplen = 20 + 8 + datalen; 2020 iplen = 20 + 8 + datalen;
1898 iph->tot_len = htons(iplen); 2021 iph->tot_len = htons(iplen);
1899 iph->check = 0; 2022 iph->check = 0;
1900 iph->check = ip_fast_csum((void *) iph, iph->ihl); 2023 iph->check = ip_fast_csum((void *)iph, iph->ihl);
1901 skb->protocol = __constant_htons(ETH_P_IP); 2024 skb->protocol = __constant_htons(ETH_P_IP);
1902 skb->mac.raw = ((u8 *)iph) - 14; 2025 skb->mac.raw = ((u8 *) iph) - 14;
1903 skb->dev = odev; 2026 skb->dev = odev;
1904 skb->pkt_type = PACKET_HOST; 2027 skb->pkt_type = PACKET_HOST;
1905 2028
1906 if (pkt_dev->nfrags <= 0) 2029 if (pkt_dev->nfrags <= 0)
1907 pgh = (struct pktgen_hdr *)skb_put(skb, datalen); 2030 pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
1908 else { 2031 else {
1909 int frags = pkt_dev->nfrags; 2032 int frags = pkt_dev->nfrags;
1910 int i; 2033 int i;
1911 2034
1912 pgh = (struct pktgen_hdr*)(((char*)(udph)) + 8); 2035 pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8);
1913 2036
1914 if (frags > MAX_SKB_FRAGS) 2037 if (frags > MAX_SKB_FRAGS)
1915 frags = MAX_SKB_FRAGS; 2038 frags = MAX_SKB_FRAGS;
1916 if (datalen > frags*PAGE_SIZE) { 2039 if (datalen > frags * PAGE_SIZE) {
1917 skb_put(skb, datalen-frags*PAGE_SIZE); 2040 skb_put(skb, datalen - frags * PAGE_SIZE);
1918 datalen = frags*PAGE_SIZE; 2041 datalen = frags * PAGE_SIZE;
1919 } 2042 }
1920 2043
1921 i = 0; 2044 i = 0;
@@ -1924,7 +2047,7 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
1924 skb_shinfo(skb)->frags[i].page = page; 2047 skb_shinfo(skb)->frags[i].page = page;
1925 skb_shinfo(skb)->frags[i].page_offset = 0; 2048 skb_shinfo(skb)->frags[i].page_offset = 0;
1926 skb_shinfo(skb)->frags[i].size = 2049 skb_shinfo(skb)->frags[i].size =
1927 (datalen < PAGE_SIZE ? datalen : PAGE_SIZE); 2050 (datalen < PAGE_SIZE ? datalen : PAGE_SIZE);
1928 datalen -= skb_shinfo(skb)->frags[i].size; 2051 datalen -= skb_shinfo(skb)->frags[i].size;
1929 skb->len += skb_shinfo(skb)->frags[i].size; 2052 skb->len += skb_shinfo(skb)->frags[i].size;
1930 skb->data_len += skb_shinfo(skb)->frags[i].size; 2053 skb->data_len += skb_shinfo(skb)->frags[i].size;
@@ -1944,30 +2067,33 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
1944 2067
1945 skb_shinfo(skb)->frags[i - 1].size -= rem; 2068 skb_shinfo(skb)->frags[i - 1].size -= rem;
1946 2069
1947 skb_shinfo(skb)->frags[i] = skb_shinfo(skb)->frags[i - 1]; 2070 skb_shinfo(skb)->frags[i] =
2071 skb_shinfo(skb)->frags[i - 1];
1948 get_page(skb_shinfo(skb)->frags[i].page); 2072 get_page(skb_shinfo(skb)->frags[i].page);
1949 skb_shinfo(skb)->frags[i].page = skb_shinfo(skb)->frags[i - 1].page; 2073 skb_shinfo(skb)->frags[i].page =
1950 skb_shinfo(skb)->frags[i].page_offset += skb_shinfo(skb)->frags[i - 1].size; 2074 skb_shinfo(skb)->frags[i - 1].page;
2075 skb_shinfo(skb)->frags[i].page_offset +=
2076 skb_shinfo(skb)->frags[i - 1].size;
1951 skb_shinfo(skb)->frags[i].size = rem; 2077 skb_shinfo(skb)->frags[i].size = rem;
1952 i++; 2078 i++;
1953 skb_shinfo(skb)->nr_frags = i; 2079 skb_shinfo(skb)->nr_frags = i;
1954 } 2080 }
1955 } 2081 }
1956 2082
1957 /* Stamp the time, and sequence number, convert them to network byte order */ 2083 /* Stamp the time, and sequence number, convert them to network byte order */
2084
2085 if (pgh) {
2086 struct timeval timestamp;
2087
2088 pgh->pgh_magic = htonl(PKTGEN_MAGIC);
2089 pgh->seq_num = htonl(pkt_dev->seq_num);
2090
2091 do_gettimeofday(&timestamp);
2092 pgh->tv_sec = htonl(timestamp.tv_sec);
2093 pgh->tv_usec = htonl(timestamp.tv_usec);
2094 }
2095 pkt_dev->seq_num++;
1958 2096
1959 if (pgh) {
1960 struct timeval timestamp;
1961
1962 pgh->pgh_magic = htonl(PKTGEN_MAGIC);
1963 pgh->seq_num = htonl(pkt_dev->seq_num);
1964
1965 do_gettimeofday(&timestamp);
1966 pgh->tv_sec = htonl(timestamp.tv_sec);
1967 pgh->tv_usec = htonl(timestamp.tv_usec);
1968 }
1969 pkt_dev->seq_num++;
1970
1971 return skb; 2097 return skb;
1972} 2098}
1973 2099
@@ -1980,23 +2106,24 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
1980 * --ro 2106 * --ro
1981 */ 2107 */
1982 2108
1983static unsigned int scan_ip6(const char *s,char ip[16]) 2109static unsigned int scan_ip6(const char *s, char ip[16])
1984{ 2110{
1985 unsigned int i; 2111 unsigned int i;
1986 unsigned int len=0; 2112 unsigned int len = 0;
1987 unsigned long u; 2113 unsigned long u;
1988 char suffix[16]; 2114 char suffix[16];
1989 unsigned int prefixlen=0; 2115 unsigned int prefixlen = 0;
1990 unsigned int suffixlen=0; 2116 unsigned int suffixlen = 0;
1991 __u32 tmp; 2117 __u32 tmp;
1992 2118
1993 for (i=0; i<16; i++) ip[i]=0; 2119 for (i = 0; i < 16; i++)
2120 ip[i] = 0;
1994 2121
1995 for (;;) { 2122 for (;;) {
1996 if (*s == ':') { 2123 if (*s == ':') {
1997 len++; 2124 len++;
1998 if (s[1] == ':') { /* Found "::", skip to part 2 */ 2125 if (s[1] == ':') { /* Found "::", skip to part 2 */
1999 s+=2; 2126 s += 2;
2000 len++; 2127 len++;
2001 break; 2128 break;
2002 } 2129 }
@@ -2004,129 +2131,149 @@ static unsigned int scan_ip6(const char *s,char ip[16])
2004 } 2131 }
2005 { 2132 {
2006 char *tmp; 2133 char *tmp;
2007 u=simple_strtoul(s,&tmp,16); 2134 u = simple_strtoul(s, &tmp, 16);
2008 i=tmp-s; 2135 i = tmp - s;
2009 } 2136 }
2010 2137
2011 if (!i) return 0; 2138 if (!i)
2012 if (prefixlen==12 && s[i]=='.') { 2139 return 0;
2140 if (prefixlen == 12 && s[i] == '.') {
2013 2141
2014 /* the last 4 bytes may be written as IPv4 address */ 2142 /* the last 4 bytes may be written as IPv4 address */
2015 2143
2016 tmp = in_aton(s); 2144 tmp = in_aton(s);
2017 memcpy((struct in_addr*)(ip+12), &tmp, sizeof(tmp)); 2145 memcpy((struct in_addr *)(ip + 12), &tmp, sizeof(tmp));
2018 return i+len; 2146 return i + len;
2019 } 2147 }
2020 ip[prefixlen++] = (u >> 8); 2148 ip[prefixlen++] = (u >> 8);
2021 ip[prefixlen++] = (u & 255); 2149 ip[prefixlen++] = (u & 255);
2022 s += i; len += i; 2150 s += i;
2023 if (prefixlen==16) 2151 len += i;
2152 if (prefixlen == 16)
2024 return len; 2153 return len;
2025 } 2154 }
2026 2155
2027/* part 2, after "::" */ 2156/* part 2, after "::" */
2028 for (;;) { 2157 for (;;) {
2029 if (*s == ':') { 2158 if (*s == ':') {
2030 if (suffixlen==0) 2159 if (suffixlen == 0)
2031 break; 2160 break;
2032 s++; 2161 s++;
2033 len++; 2162 len++;
2034 } else if (suffixlen!=0) 2163 } else if (suffixlen != 0)
2035 break; 2164 break;
2036 { 2165 {
2037 char *tmp; 2166 char *tmp;
2038 u=simple_strtol(s,&tmp,16); 2167 u = simple_strtol(s, &tmp, 16);
2039 i=tmp-s; 2168 i = tmp - s;
2040 } 2169 }
2041 if (!i) { 2170 if (!i) {
2042 if (*s) len--; 2171 if (*s)
2172 len--;
2043 break; 2173 break;
2044 } 2174 }
2045 if (suffixlen+prefixlen<=12 && s[i]=='.') { 2175 if (suffixlen + prefixlen <= 12 && s[i] == '.') {
2046 tmp = in_aton(s); 2176 tmp = in_aton(s);
2047 memcpy((struct in_addr*)(suffix+suffixlen), &tmp, sizeof(tmp)); 2177 memcpy((struct in_addr *)(suffix + suffixlen), &tmp,
2048 suffixlen+=4; 2178 sizeof(tmp));
2049 len+=strlen(s); 2179 suffixlen += 4;
2180 len += strlen(s);
2050 break; 2181 break;
2051 } 2182 }
2052 suffix[suffixlen++] = (u >> 8); 2183 suffix[suffixlen++] = (u >> 8);
2053 suffix[suffixlen++] = (u & 255); 2184 suffix[suffixlen++] = (u & 255);
2054 s += i; len += i; 2185 s += i;
2055 if (prefixlen+suffixlen==16) 2186 len += i;
2187 if (prefixlen + suffixlen == 16)
2056 break; 2188 break;
2057 } 2189 }
2058 for (i=0; i<suffixlen; i++) 2190 for (i = 0; i < suffixlen; i++)
2059 ip[16-suffixlen+i] = suffix[i]; 2191 ip[16 - suffixlen + i] = suffix[i];
2060 return len; 2192 return len;
2061} 2193}
2062 2194
2063static char tohex(char hexdigit) { 2195static char tohex(char hexdigit)
2064 return hexdigit>9?hexdigit+'a'-10:hexdigit+'0'; 2196{
2197 return hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0';
2065} 2198}
2066 2199
2067static int fmt_xlong(char* s,unsigned int i) { 2200static int fmt_xlong(char *s, unsigned int i)
2068 char* bak=s; 2201{
2069 *s=tohex((i>>12)&0xf); if (s!=bak || *s!='0') ++s; 2202 char *bak = s;
2070 *s=tohex((i>>8)&0xf); if (s!=bak || *s!='0') ++s; 2203 *s = tohex((i >> 12) & 0xf);
2071 *s=tohex((i>>4)&0xf); if (s!=bak || *s!='0') ++s; 2204 if (s != bak || *s != '0')
2072 *s=tohex(i&0xf); 2205 ++s;
2073 return s-bak+1; 2206 *s = tohex((i >> 8) & 0xf);
2207 if (s != bak || *s != '0')
2208 ++s;
2209 *s = tohex((i >> 4) & 0xf);
2210 if (s != bak || *s != '0')
2211 ++s;
2212 *s = tohex(i & 0xf);
2213 return s - bak + 1;
2074} 2214}
2075 2215
2076static unsigned int fmt_ip6(char *s,const char ip[16]) { 2216static unsigned int fmt_ip6(char *s, const char ip[16])
2217{
2077 unsigned int len; 2218 unsigned int len;
2078 unsigned int i; 2219 unsigned int i;
2079 unsigned int temp; 2220 unsigned int temp;
2080 unsigned int compressing; 2221 unsigned int compressing;
2081 int j; 2222 int j;
2082 2223
2083 len = 0; compressing = 0; 2224 len = 0;
2084 for (j=0; j<16; j+=2) { 2225 compressing = 0;
2226 for (j = 0; j < 16; j += 2) {
2085 2227
2086#ifdef V4MAPPEDPREFIX 2228#ifdef V4MAPPEDPREFIX
2087 if (j==12 && !memcmp(ip,V4mappedprefix,12)) { 2229 if (j == 12 && !memcmp(ip, V4mappedprefix, 12)) {
2088 inet_ntoa_r(*(struct in_addr*)(ip+12),s); 2230 inet_ntoa_r(*(struct in_addr *)(ip + 12), s);
2089 temp=strlen(s); 2231 temp = strlen(s);
2090 return len+temp; 2232 return len + temp;
2091 } 2233 }
2092#endif 2234#endif
2093 temp = ((unsigned long) (unsigned char) ip[j] << 8) + 2235 temp = ((unsigned long)(unsigned char)ip[j] << 8) +
2094 (unsigned long) (unsigned char) ip[j+1]; 2236 (unsigned long)(unsigned char)ip[j + 1];
2095 if (temp == 0) { 2237 if (temp == 0) {
2096 if (!compressing) { 2238 if (!compressing) {
2097 compressing=1; 2239 compressing = 1;
2098 if (j==0) { 2240 if (j == 0) {
2099 *s++=':'; ++len; 2241 *s++ = ':';
2242 ++len;
2100 } 2243 }
2101 } 2244 }
2102 } else { 2245 } else {
2103 if (compressing) { 2246 if (compressing) {
2104 compressing=0; 2247 compressing = 0;
2105 *s++=':'; ++len; 2248 *s++ = ':';
2249 ++len;
2106 } 2250 }
2107 i = fmt_xlong(s,temp); len += i; s += i; 2251 i = fmt_xlong(s, temp);
2108 if (j<14) { 2252 len += i;
2253 s += i;
2254 if (j < 14) {
2109 *s++ = ':'; 2255 *s++ = ':';
2110 ++len; 2256 ++len;
2111 } 2257 }
2112 } 2258 }
2113 } 2259 }
2114 if (compressing) { 2260 if (compressing) {
2115 *s++=':'; ++len; 2261 *s++ = ':';
2262 ++len;
2116 } 2263 }
2117 *s=0; 2264 *s = 0;
2118 return len; 2265 return len;
2119} 2266}
2120 2267
2121static struct sk_buff *fill_packet_ipv6(struct net_device *odev, 2268static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2122 struct pktgen_dev *pkt_dev) 2269 struct pktgen_dev *pkt_dev)
2123{ 2270{
2124 struct sk_buff *skb = NULL; 2271 struct sk_buff *skb = NULL;
2125 __u8 *eth; 2272 __u8 *eth;
2126 struct udphdr *udph; 2273 struct udphdr *udph;
2127 int datalen; 2274 int datalen;
2128 struct ipv6hdr *iph; 2275 struct ipv6hdr *iph;
2129 struct pktgen_hdr *pgh = NULL; 2276 struct pktgen_hdr *pgh = NULL;
2130 2277
2131 /* Update any of the values, used when we're incrementing various 2278 /* Update any of the values, used when we're incrementing various
2132 * fields. 2279 * fields.
@@ -2147,23 +2294,23 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2147 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr)); 2294 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
2148 2295
2149 memcpy(eth, pkt_dev->hh, 12); 2296 memcpy(eth, pkt_dev->hh, 12);
2150 *(u16*)&eth[12] = __constant_htons(ETH_P_IPV6); 2297 *(u16 *) & eth[12] = __constant_htons(ETH_P_IPV6);
2151 2298
2152 datalen = pkt_dev->cur_pkt_size-14- 2299 datalen = pkt_dev->cur_pkt_size - 14 - sizeof(struct ipv6hdr) - sizeof(struct udphdr); /* Eth + IPh + UDPh */
2153 sizeof(struct ipv6hdr)-sizeof(struct udphdr); /* Eth + IPh + UDPh */
2154 2300
2155 if (datalen < sizeof(struct pktgen_hdr)) { 2301 if (datalen < sizeof(struct pktgen_hdr)) {
2156 datalen = sizeof(struct pktgen_hdr); 2302 datalen = sizeof(struct pktgen_hdr);
2157 if (net_ratelimit()) 2303 if (net_ratelimit())
2158 printk(KERN_INFO "pktgen: increased datalen to %d\n", datalen); 2304 printk(KERN_INFO "pktgen: increased datalen to %d\n",
2305 datalen);
2159 } 2306 }
2160 2307
2161 udph->source = htons(pkt_dev->cur_udp_src); 2308 udph->source = htons(pkt_dev->cur_udp_src);
2162 udph->dest = htons(pkt_dev->cur_udp_dst); 2309 udph->dest = htons(pkt_dev->cur_udp_dst);
2163 udph->len = htons(datalen + sizeof(struct udphdr)); 2310 udph->len = htons(datalen + sizeof(struct udphdr));
2164 udph->check = 0; /* No checksum */ 2311 udph->check = 0; /* No checksum */
2165 2312
2166 *(u32*)iph = __constant_htonl(0x60000000); /* Version + flow */ 2313 *(u32 *) iph = __constant_htonl(0x60000000); /* Version + flow */
2167 2314
2168 iph->hop_limit = 32; 2315 iph->hop_limit = 32;
2169 2316
@@ -2173,24 +2320,24 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2173 ipv6_addr_copy(&iph->daddr, &pkt_dev->cur_in6_daddr); 2320 ipv6_addr_copy(&iph->daddr, &pkt_dev->cur_in6_daddr);
2174 ipv6_addr_copy(&iph->saddr, &pkt_dev->cur_in6_saddr); 2321 ipv6_addr_copy(&iph->saddr, &pkt_dev->cur_in6_saddr);
2175 2322
2176 skb->mac.raw = ((u8 *)iph) - 14; 2323 skb->mac.raw = ((u8 *) iph) - 14;
2177 skb->protocol = __constant_htons(ETH_P_IPV6); 2324 skb->protocol = __constant_htons(ETH_P_IPV6);
2178 skb->dev = odev; 2325 skb->dev = odev;
2179 skb->pkt_type = PACKET_HOST; 2326 skb->pkt_type = PACKET_HOST;
2180 2327
2181 if (pkt_dev->nfrags <= 0) 2328 if (pkt_dev->nfrags <= 0)
2182 pgh = (struct pktgen_hdr *)skb_put(skb, datalen); 2329 pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
2183 else { 2330 else {
2184 int frags = pkt_dev->nfrags; 2331 int frags = pkt_dev->nfrags;
2185 int i; 2332 int i;
2186 2333
2187 pgh = (struct pktgen_hdr*)(((char*)(udph)) + 8); 2334 pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8);
2188 2335
2189 if (frags > MAX_SKB_FRAGS) 2336 if (frags > MAX_SKB_FRAGS)
2190 frags = MAX_SKB_FRAGS; 2337 frags = MAX_SKB_FRAGS;
2191 if (datalen > frags*PAGE_SIZE) { 2338 if (datalen > frags * PAGE_SIZE) {
2192 skb_put(skb, datalen-frags*PAGE_SIZE); 2339 skb_put(skb, datalen - frags * PAGE_SIZE);
2193 datalen = frags*PAGE_SIZE; 2340 datalen = frags * PAGE_SIZE;
2194 } 2341 }
2195 2342
2196 i = 0; 2343 i = 0;
@@ -2199,7 +2346,7 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2199 skb_shinfo(skb)->frags[i].page = page; 2346 skb_shinfo(skb)->frags[i].page = page;
2200 skb_shinfo(skb)->frags[i].page_offset = 0; 2347 skb_shinfo(skb)->frags[i].page_offset = 0;
2201 skb_shinfo(skb)->frags[i].size = 2348 skb_shinfo(skb)->frags[i].size =
2202 (datalen < PAGE_SIZE ? datalen : PAGE_SIZE); 2349 (datalen < PAGE_SIZE ? datalen : PAGE_SIZE);
2203 datalen -= skb_shinfo(skb)->frags[i].size; 2350 datalen -= skb_shinfo(skb)->frags[i].size;
2204 skb->len += skb_shinfo(skb)->frags[i].size; 2351 skb->len += skb_shinfo(skb)->frags[i].size;
2205 skb->data_len += skb_shinfo(skb)->frags[i].size; 2352 skb->data_len += skb_shinfo(skb)->frags[i].size;
@@ -2219,305 +2366,333 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2219 2366
2220 skb_shinfo(skb)->frags[i - 1].size -= rem; 2367 skb_shinfo(skb)->frags[i - 1].size -= rem;
2221 2368
2222 skb_shinfo(skb)->frags[i] = skb_shinfo(skb)->frags[i - 1]; 2369 skb_shinfo(skb)->frags[i] =
2370 skb_shinfo(skb)->frags[i - 1];
2223 get_page(skb_shinfo(skb)->frags[i].page); 2371 get_page(skb_shinfo(skb)->frags[i].page);
2224 skb_shinfo(skb)->frags[i].page = skb_shinfo(skb)->frags[i - 1].page; 2372 skb_shinfo(skb)->frags[i].page =
2225 skb_shinfo(skb)->frags[i].page_offset += skb_shinfo(skb)->frags[i - 1].size; 2373 skb_shinfo(skb)->frags[i - 1].page;
2374 skb_shinfo(skb)->frags[i].page_offset +=
2375 skb_shinfo(skb)->frags[i - 1].size;
2226 skb_shinfo(skb)->frags[i].size = rem; 2376 skb_shinfo(skb)->frags[i].size = rem;
2227 i++; 2377 i++;
2228 skb_shinfo(skb)->nr_frags = i; 2378 skb_shinfo(skb)->nr_frags = i;
2229 } 2379 }
2230 } 2380 }
2231 2381
2232 /* Stamp the time, and sequence number, convert them to network byte order */ 2382 /* Stamp the time, and sequence number, convert them to network byte order */
2233 /* should we update cloned packets too ? */ 2383 /* should we update cloned packets too ? */
2234 if (pgh) { 2384 if (pgh) {
2235 struct timeval timestamp; 2385 struct timeval timestamp;
2236 2386
2237 pgh->pgh_magic = htonl(PKTGEN_MAGIC); 2387 pgh->pgh_magic = htonl(PKTGEN_MAGIC);
2238 pgh->seq_num = htonl(pkt_dev->seq_num); 2388 pgh->seq_num = htonl(pkt_dev->seq_num);
2239 2389
2240 do_gettimeofday(&timestamp); 2390 do_gettimeofday(&timestamp);
2241 pgh->tv_sec = htonl(timestamp.tv_sec); 2391 pgh->tv_sec = htonl(timestamp.tv_sec);
2242 pgh->tv_usec = htonl(timestamp.tv_usec); 2392 pgh->tv_usec = htonl(timestamp.tv_usec);
2243 } 2393 }
2244 pkt_dev->seq_num++; 2394 pkt_dev->seq_num++;
2245 2395
2246 return skb; 2396 return skb;
2247} 2397}
2248 2398
2249static inline struct sk_buff *fill_packet(struct net_device *odev, 2399static inline struct sk_buff *fill_packet(struct net_device *odev,
2250 struct pktgen_dev *pkt_dev) 2400 struct pktgen_dev *pkt_dev)
2251{ 2401{
2252 if(pkt_dev->flags & F_IPV6) 2402 if (pkt_dev->flags & F_IPV6)
2253 return fill_packet_ipv6(odev, pkt_dev); 2403 return fill_packet_ipv6(odev, pkt_dev);
2254 else 2404 else
2255 return fill_packet_ipv4(odev, pkt_dev); 2405 return fill_packet_ipv4(odev, pkt_dev);
2256} 2406}
2257 2407
2258static void pktgen_clear_counters(struct pktgen_dev *pkt_dev) 2408static void pktgen_clear_counters(struct pktgen_dev *pkt_dev)
2259{ 2409{
2260 pkt_dev->seq_num = 1; 2410 pkt_dev->seq_num = 1;
2261 pkt_dev->idle_acc = 0; 2411 pkt_dev->idle_acc = 0;
2262 pkt_dev->sofar = 0; 2412 pkt_dev->sofar = 0;
2263 pkt_dev->tx_bytes = 0; 2413 pkt_dev->tx_bytes = 0;
2264 pkt_dev->errors = 0; 2414 pkt_dev->errors = 0;
2265} 2415}
2266 2416
2267/* Set up structure for sending pkts, clear counters */ 2417/* Set up structure for sending pkts, clear counters */
2268 2418
2269static void pktgen_run(struct pktgen_thread *t) 2419static void pktgen_run(struct pktgen_thread *t)
2270{ 2420{
2271 struct pktgen_dev *pkt_dev = NULL; 2421 struct pktgen_dev *pkt_dev;
2272 int started = 0; 2422 int started = 0;
2273 2423
2274 PG_DEBUG(printk("pktgen: entering pktgen_run. %p\n", t)); 2424 PG_DEBUG(printk("pktgen: entering pktgen_run. %p\n", t));
2275 2425
2276 if_lock(t); 2426 if_lock(t);
2277 for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next ) { 2427 list_for_each_entry(pkt_dev, &t->if_list, list) {
2278 2428
2279 /* 2429 /*
2280 * setup odev and create initial packet. 2430 * setup odev and create initial packet.
2281 */ 2431 */
2282 pktgen_setup_inject(pkt_dev); 2432 pktgen_setup_inject(pkt_dev);
2283 2433
2284 if(pkt_dev->odev) { 2434 if (pkt_dev->odev) {
2285 pktgen_clear_counters(pkt_dev); 2435 pktgen_clear_counters(pkt_dev);
2286 pkt_dev->running = 1; /* Cranke yeself! */ 2436 pkt_dev->running = 1; /* Cranke yeself! */
2287 pkt_dev->skb = NULL; 2437 pkt_dev->skb = NULL;
2288 pkt_dev->started_at = getCurUs(); 2438 pkt_dev->started_at = getCurUs();
2289 pkt_dev->next_tx_us = getCurUs(); /* Transmit immediately */ 2439 pkt_dev->next_tx_us = getCurUs(); /* Transmit immediately */
2290 pkt_dev->next_tx_ns = 0; 2440 pkt_dev->next_tx_ns = 0;
2291 2441
2292 strcpy(pkt_dev->result, "Starting"); 2442 strcpy(pkt_dev->result, "Starting");
2293 started++; 2443 started++;
2294 } 2444 } else
2295 else
2296 strcpy(pkt_dev->result, "Error starting"); 2445 strcpy(pkt_dev->result, "Error starting");
2297 } 2446 }
2298 if_unlock(t); 2447 if_unlock(t);
2299 if(started) t->control &= ~(T_STOP); 2448 if (started)
2449 t->control &= ~(T_STOP);
2300} 2450}
2301 2451
2302static void pktgen_stop_all_threads_ifs(void) 2452static void pktgen_stop_all_threads_ifs(void)
2303{ 2453{
2304 struct pktgen_thread *t = pktgen_threads; 2454 struct pktgen_thread *t;
2305 2455
2306 PG_DEBUG(printk("pktgen: entering pktgen_stop_all_threads.\n")); 2456 PG_DEBUG(printk("pktgen: entering pktgen_stop_all_threads_ifs.\n"));
2307 2457
2308 thread_lock(); 2458 mutex_lock(&pktgen_thread_lock);
2309 while(t) { 2459
2310 pktgen_stop(t); 2460 list_for_each_entry(t, &pktgen_threads, th_list)
2311 t = t->next; 2461 t->control |= T_STOP;
2312 } 2462
2313 thread_unlock(); 2463 mutex_unlock(&pktgen_thread_lock);
2314} 2464}
2315 2465
2316static int thread_is_running(struct pktgen_thread *t ) 2466static int thread_is_running(struct pktgen_thread *t)
2317{ 2467{
2318 struct pktgen_dev *next; 2468 struct pktgen_dev *pkt_dev;
2319 int res = 0; 2469 int res = 0;
2320 2470
2321 for(next=t->if_list; next; next=next->next) { 2471 list_for_each_entry(pkt_dev, &t->if_list, list)
2322 if(next->running) { 2472 if (pkt_dev->running) {
2323 res = 1; 2473 res = 1;
2324 break; 2474 break;
2325 } 2475 }
2326 } 2476 return res;
2327 return res;
2328} 2477}
2329 2478
2330static int pktgen_wait_thread_run(struct pktgen_thread *t ) 2479static int pktgen_wait_thread_run(struct pktgen_thread *t)
2331{ 2480{
2332 if_lock(t); 2481 if_lock(t);
2333 2482
2334 while(thread_is_running(t)) { 2483 while (thread_is_running(t)) {
2335 2484
2336 if_unlock(t); 2485 if_unlock(t);
2337 2486
2338 msleep_interruptible(100); 2487 msleep_interruptible(100);
2339 2488
2340 if (signal_pending(current)) 2489 if (signal_pending(current))
2341 goto signal; 2490 goto signal;
2342 if_lock(t); 2491 if_lock(t);
2343 } 2492 }
2344 if_unlock(t); 2493 if_unlock(t);
2345 return 1; 2494 return 1;
2346 signal: 2495signal:
2347 return 0; 2496 return 0;
2348} 2497}
2349 2498
2350static int pktgen_wait_all_threads_run(void) 2499static int pktgen_wait_all_threads_run(void)
2351{ 2500{
2352 struct pktgen_thread *t = pktgen_threads; 2501 struct pktgen_thread *t;
2353 int sig = 1; 2502 int sig = 1;
2354 2503
2355 while (t) { 2504 mutex_lock(&pktgen_thread_lock);
2505
2506 list_for_each_entry(t, &pktgen_threads, th_list) {
2356 sig = pktgen_wait_thread_run(t); 2507 sig = pktgen_wait_thread_run(t);
2357 if( sig == 0 ) break; 2508 if (sig == 0)
2358 thread_lock(); 2509 break;
2359 t=t->next;
2360 thread_unlock();
2361 }
2362 if(sig == 0) {
2363 thread_lock();
2364 while (t) {
2365 t->control |= (T_STOP);
2366 t=t->next;
2367 }
2368 thread_unlock();
2369 } 2510 }
2511
2512 if (sig == 0)
2513 list_for_each_entry(t, &pktgen_threads, th_list)
2514 t->control |= (T_STOP);
2515
2516 mutex_unlock(&pktgen_thread_lock);
2370 return sig; 2517 return sig;
2371} 2518}
2372 2519
2373static void pktgen_run_all_threads(void) 2520static void pktgen_run_all_threads(void)
2374{ 2521{
2375 struct pktgen_thread *t = pktgen_threads; 2522 struct pktgen_thread *t;
2376 2523
2377 PG_DEBUG(printk("pktgen: entering pktgen_run_all_threads.\n")); 2524 PG_DEBUG(printk("pktgen: entering pktgen_run_all_threads.\n"));
2378 2525
2379 thread_lock(); 2526 mutex_lock(&pktgen_thread_lock);
2380 2527
2381 while(t) { 2528 list_for_each_entry(t, &pktgen_threads, th_list)
2382 t->control |= (T_RUN); 2529 t->control |= (T_RUN);
2383 t = t->next;
2384 }
2385 thread_unlock();
2386 2530
2387 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */ 2531 mutex_unlock(&pktgen_thread_lock);
2388 2532
2533 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
2534
2389 pktgen_wait_all_threads_run(); 2535 pktgen_wait_all_threads_run();
2390} 2536}
2391 2537
2392
2393static void show_results(struct pktgen_dev *pkt_dev, int nr_frags) 2538static void show_results(struct pktgen_dev *pkt_dev, int nr_frags)
2394{ 2539{
2395 __u64 total_us, bps, mbps, pps, idle; 2540 __u64 total_us, bps, mbps, pps, idle;
2396 char *p = pkt_dev->result; 2541 char *p = pkt_dev->result;
2397 2542
2398 total_us = pkt_dev->stopped_at - pkt_dev->started_at; 2543 total_us = pkt_dev->stopped_at - pkt_dev->started_at;
2399 2544
2400 idle = pkt_dev->idle_acc; 2545 idle = pkt_dev->idle_acc;
2401 2546
2402 p += sprintf(p, "OK: %llu(c%llu+d%llu) usec, %llu (%dbyte,%dfrags)\n", 2547 p += sprintf(p, "OK: %llu(c%llu+d%llu) usec, %llu (%dbyte,%dfrags)\n",
2403 (unsigned long long) total_us, 2548 (unsigned long long)total_us,
2404 (unsigned long long)(total_us - idle), 2549 (unsigned long long)(total_us - idle),
2405 (unsigned long long) idle, 2550 (unsigned long long)idle,
2406 (unsigned long long) pkt_dev->sofar, 2551 (unsigned long long)pkt_dev->sofar,
2407 pkt_dev->cur_pkt_size, nr_frags); 2552 pkt_dev->cur_pkt_size, nr_frags);
2408 2553
2409 pps = pkt_dev->sofar * USEC_PER_SEC; 2554 pps = pkt_dev->sofar * USEC_PER_SEC;
2410 2555
2411 while ((total_us >> 32) != 0) { 2556 while ((total_us >> 32) != 0) {
2412 pps >>= 1; 2557 pps >>= 1;
2413 total_us >>= 1; 2558 total_us >>= 1;
2414 } 2559 }
2415 2560
2416 do_div(pps, total_us); 2561 do_div(pps, total_us);
2417 2562
2418 bps = pps * 8 * pkt_dev->cur_pkt_size; 2563 bps = pps * 8 * pkt_dev->cur_pkt_size;
2419 2564
2420 mbps = bps; 2565 mbps = bps;
2421 do_div(mbps, 1000000); 2566 do_div(mbps, 1000000);
2422 p += sprintf(p, " %llupps %lluMb/sec (%llubps) errors: %llu", 2567 p += sprintf(p, " %llupps %lluMb/sec (%llubps) errors: %llu",
2423 (unsigned long long) pps, 2568 (unsigned long long)pps,
2424 (unsigned long long) mbps, 2569 (unsigned long long)mbps,
2425 (unsigned long long) bps, 2570 (unsigned long long)bps,
2426 (unsigned long long) pkt_dev->errors); 2571 (unsigned long long)pkt_dev->errors);
2427} 2572}
2428
2429 2573
2430/* Set stopped-at timer, remove from running list, do counters & statistics */ 2574/* Set stopped-at timer, remove from running list, do counters & statistics */
2431 2575
2432static int pktgen_stop_device(struct pktgen_dev *pkt_dev) 2576static int pktgen_stop_device(struct pktgen_dev *pkt_dev)
2433{ 2577{
2434 2578 int nr_frags = pkt_dev->skb ? skb_shinfo(pkt_dev->skb)->nr_frags : -1;
2435 if (!pkt_dev->running) {
2436 printk("pktgen: interface: %s is already stopped\n", pkt_dev->ifname);
2437 return -EINVAL;
2438 }
2439 2579
2440 pkt_dev->stopped_at = getCurUs(); 2580 if (!pkt_dev->running) {
2441 pkt_dev->running = 0; 2581 printk("pktgen: interface: %s is already stopped\n",
2582 pkt_dev->ifname);
2583 return -EINVAL;
2584 }
2442 2585
2443 show_results(pkt_dev, skb_shinfo(pkt_dev->skb)->nr_frags); 2586 pkt_dev->stopped_at = getCurUs();
2587 pkt_dev->running = 0;
2444 2588
2445 if (pkt_dev->skb) 2589 show_results(pkt_dev, nr_frags);
2446 kfree_skb(pkt_dev->skb);
2447 2590
2448 pkt_dev->skb = NULL; 2591 return 0;
2449
2450 return 0;
2451} 2592}
2452 2593
2453static struct pktgen_dev *next_to_run(struct pktgen_thread *t ) 2594static struct pktgen_dev *next_to_run(struct pktgen_thread *t)
2454{ 2595{
2455 struct pktgen_dev *next, *best = NULL; 2596 struct pktgen_dev *pkt_dev, *best = NULL;
2456 2597
2457 if_lock(t); 2598 if_lock(t);
2458 2599
2459 for(next=t->if_list; next ; next=next->next) { 2600 list_for_each_entry(pkt_dev, &t->if_list, list) {
2460 if(!next->running) continue; 2601 if (!pkt_dev->running)
2461 if(best == NULL) best=next; 2602 continue;
2462 else if ( next->next_tx_us < best->next_tx_us) 2603 if (best == NULL)
2463 best = next; 2604 best = pkt_dev;
2605 else if (pkt_dev->next_tx_us < best->next_tx_us)
2606 best = pkt_dev;
2464 } 2607 }
2465 if_unlock(t); 2608 if_unlock(t);
2466 return best; 2609 return best;
2467} 2610}
2468 2611
2469static void pktgen_stop(struct pktgen_thread *t) { 2612static void pktgen_stop(struct pktgen_thread *t)
2470 struct pktgen_dev *next = NULL; 2613{
2614 struct pktgen_dev *pkt_dev;
2471 2615
2472 PG_DEBUG(printk("pktgen: entering pktgen_stop.\n")); 2616 PG_DEBUG(printk("pktgen: entering pktgen_stop\n"));
2473 2617
2474 if_lock(t); 2618 if_lock(t);
2475 2619
2476 for(next=t->if_list; next; next=next->next) 2620 list_for_each_entry(pkt_dev, &t->if_list, list) {
2477 pktgen_stop_device(next); 2621 pktgen_stop_device(pkt_dev);
2622 if (pkt_dev->skb)
2623 kfree_skb(pkt_dev->skb);
2478 2624
2479 if_unlock(t); 2625 pkt_dev->skb = NULL;
2626 }
2627
2628 if_unlock(t);
2480} 2629}
2481 2630
2482static void pktgen_rem_all_ifs(struct pktgen_thread *t) 2631/*
2632 * one of our devices needs to be removed - find it
2633 * and remove it
2634 */
2635static void pktgen_rem_one_if(struct pktgen_thread *t)
2483{ 2636{
2484 struct pktgen_dev *cur, *next = NULL; 2637 struct list_head *q, *n;
2485 2638 struct pktgen_dev *cur;
2486 /* Remove all devices, free mem */ 2639
2487 2640 PG_DEBUG(printk("pktgen: entering pktgen_rem_one_if\n"));
2488 if_lock(t); 2641
2489 2642 if_lock(t);
2490 for(cur=t->if_list; cur; cur=next) { 2643
2491 next = cur->next; 2644 list_for_each_safe(q, n, &t->if_list) {
2645 cur = list_entry(q, struct pktgen_dev, list);
2646
2647 if (!cur->removal_mark)
2648 continue;
2649
2650 if (cur->skb)
2651 kfree_skb(cur->skb);
2652 cur->skb = NULL;
2653
2492 pktgen_remove_device(t, cur); 2654 pktgen_remove_device(t, cur);
2655
2656 break;
2493 } 2657 }
2494 2658
2495 if_unlock(t); 2659 if_unlock(t);
2496} 2660}
2497 2661
2498static void pktgen_rem_thread(struct pktgen_thread *t) 2662static void pktgen_rem_all_ifs(struct pktgen_thread *t)
2499{ 2663{
2500 /* Remove from the thread list */ 2664 struct list_head *q, *n;
2665 struct pktgen_dev *cur;
2501 2666
2502 struct pktgen_thread *tmp = pktgen_threads; 2667 /* Remove all devices, free mem */
2503 2668
2504 remove_proc_entry(t->name, pg_proc_dir); 2669 PG_DEBUG(printk("pktgen: entering pktgen_rem_all_ifs\n"));
2670 if_lock(t);
2505 2671
2506 thread_lock(); 2672 list_for_each_safe(q, n, &t->if_list) {
2673 cur = list_entry(q, struct pktgen_dev, list);
2507 2674
2508 if (tmp == t) 2675 if (cur->skb)
2509 pktgen_threads = tmp->next; 2676 kfree_skb(cur->skb);
2510 else { 2677 cur->skb = NULL;
2511 while (tmp) { 2678
2512 if (tmp->next == t) { 2679 pktgen_remove_device(t, cur);
2513 tmp->next = t->next;
2514 t->next = NULL;
2515 break;
2516 }
2517 tmp = tmp->next;
2518 }
2519 } 2680 }
2520 thread_unlock(); 2681
2682 if_unlock(t);
2683}
2684
2685static void pktgen_rem_thread(struct pktgen_thread *t)
2686{
2687 /* Remove from the thread list */
2688
2689 remove_proc_entry(t->name, pg_proc_dir);
2690
2691 mutex_lock(&pktgen_thread_lock);
2692
2693 list_del(&t->th_list);
2694
2695 mutex_unlock(&pktgen_thread_lock);
2521} 2696}
2522 2697
2523static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev) 2698static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
@@ -2527,7 +2702,7 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
2527 int ret; 2702 int ret;
2528 2703
2529 odev = pkt_dev->odev; 2704 odev = pkt_dev->odev;
2530 2705
2531 if (pkt_dev->delay_us || pkt_dev->delay_ns) { 2706 if (pkt_dev->delay_us || pkt_dev->delay_ns) {
2532 u64 now; 2707 u64 now;
2533 2708
@@ -2544,67 +2719,71 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
2544 goto out; 2719 goto out;
2545 } 2720 }
2546 } 2721 }
2547 2722
2548 if (netif_queue_stopped(odev) || need_resched()) { 2723 if (netif_queue_stopped(odev) || need_resched()) {
2549 idle_start = getCurUs(); 2724 idle_start = getCurUs();
2550 2725
2551 if (!netif_running(odev)) { 2726 if (!netif_running(odev)) {
2552 pktgen_stop_device(pkt_dev); 2727 pktgen_stop_device(pkt_dev);
2728 if (pkt_dev->skb)
2729 kfree_skb(pkt_dev->skb);
2730 pkt_dev->skb = NULL;
2553 goto out; 2731 goto out;
2554 } 2732 }
2555 if (need_resched()) 2733 if (need_resched())
2556 schedule(); 2734 schedule();
2557 2735
2558 pkt_dev->idle_acc += getCurUs() - idle_start; 2736 pkt_dev->idle_acc += getCurUs() - idle_start;
2559 2737
2560 if (netif_queue_stopped(odev)) { 2738 if (netif_queue_stopped(odev)) {
2561 pkt_dev->next_tx_us = getCurUs(); /* TODO */ 2739 pkt_dev->next_tx_us = getCurUs(); /* TODO */
2562 pkt_dev->next_tx_ns = 0; 2740 pkt_dev->next_tx_ns = 0;
2563 goto out; /* Try the next interface */ 2741 goto out; /* Try the next interface */
2564 } 2742 }
2565 } 2743 }
2566 2744
2567 if (pkt_dev->last_ok || !pkt_dev->skb) { 2745 if (pkt_dev->last_ok || !pkt_dev->skb) {
2568 if ((++pkt_dev->clone_count >= pkt_dev->clone_skb ) || (!pkt_dev->skb)) { 2746 if ((++pkt_dev->clone_count >= pkt_dev->clone_skb)
2747 || (!pkt_dev->skb)) {
2569 /* build a new pkt */ 2748 /* build a new pkt */
2570 if (pkt_dev->skb) 2749 if (pkt_dev->skb)
2571 kfree_skb(pkt_dev->skb); 2750 kfree_skb(pkt_dev->skb);
2572 2751
2573 pkt_dev->skb = fill_packet(odev, pkt_dev); 2752 pkt_dev->skb = fill_packet(odev, pkt_dev);
2574 if (pkt_dev->skb == NULL) { 2753 if (pkt_dev->skb == NULL) {
2575 printk("pktgen: ERROR: couldn't allocate skb in fill_packet.\n"); 2754 printk("pktgen: ERROR: couldn't allocate skb in fill_packet.\n");
2576 schedule(); 2755 schedule();
2577 pkt_dev->clone_count--; /* back out increment, OOM */ 2756 pkt_dev->clone_count--; /* back out increment, OOM */
2578 goto out; 2757 goto out;
2579 } 2758 }
2580 pkt_dev->allocated_skbs++; 2759 pkt_dev->allocated_skbs++;
2581 pkt_dev->clone_count = 0; /* reset counter */ 2760 pkt_dev->clone_count = 0; /* reset counter */
2582 } 2761 }
2583 } 2762 }
2584 2763
2585 spin_lock_bh(&odev->xmit_lock); 2764 spin_lock_bh(&odev->xmit_lock);
2586 if (!netif_queue_stopped(odev)) { 2765 if (!netif_queue_stopped(odev)) {
2587 2766
2588 atomic_inc(&(pkt_dev->skb->users)); 2767 atomic_inc(&(pkt_dev->skb->users));
2589retry_now: 2768 retry_now:
2590 ret = odev->hard_start_xmit(pkt_dev->skb, odev); 2769 ret = odev->hard_start_xmit(pkt_dev->skb, odev);
2591 if (likely(ret == NETDEV_TX_OK)) { 2770 if (likely(ret == NETDEV_TX_OK)) {
2592 pkt_dev->last_ok = 1; 2771 pkt_dev->last_ok = 1;
2593 pkt_dev->sofar++; 2772 pkt_dev->sofar++;
2594 pkt_dev->seq_num++; 2773 pkt_dev->seq_num++;
2595 pkt_dev->tx_bytes += pkt_dev->cur_pkt_size; 2774 pkt_dev->tx_bytes += pkt_dev->cur_pkt_size;
2596 2775
2597 } else if (ret == NETDEV_TX_LOCKED 2776 } else if (ret == NETDEV_TX_LOCKED
2598 && (odev->features & NETIF_F_LLTX)) { 2777 && (odev->features & NETIF_F_LLTX)) {
2599 cpu_relax(); 2778 cpu_relax();
2600 goto retry_now; 2779 goto retry_now;
2601 } else { /* Retry it next time */ 2780 } else { /* Retry it next time */
2602 2781
2603 atomic_dec(&(pkt_dev->skb->users)); 2782 atomic_dec(&(pkt_dev->skb->users));
2604 2783
2605 if (debug && net_ratelimit()) 2784 if (debug && net_ratelimit())
2606 printk(KERN_INFO "pktgen: Hard xmit error\n"); 2785 printk(KERN_INFO "pktgen: Hard xmit error\n");
2607 2786
2608 pkt_dev->errors++; 2787 pkt_dev->errors++;
2609 pkt_dev->last_ok = 0; 2788 pkt_dev->last_ok = 0;
2610 } 2789 }
@@ -2619,16 +2798,16 @@ retry_now:
2619 pkt_dev->next_tx_us++; 2798 pkt_dev->next_tx_us++;
2620 pkt_dev->next_tx_ns -= 1000; 2799 pkt_dev->next_tx_ns -= 1000;
2621 } 2800 }
2622 } 2801 }
2623 2802
2624 else { /* Retry it next time */ 2803 else { /* Retry it next time */
2625 pkt_dev->last_ok = 0; 2804 pkt_dev->last_ok = 0;
2626 pkt_dev->next_tx_us = getCurUs(); /* TODO */ 2805 pkt_dev->next_tx_us = getCurUs(); /* TODO */
2627 pkt_dev->next_tx_ns = 0; 2806 pkt_dev->next_tx_ns = 0;
2628 } 2807 }
2629 2808
2630 spin_unlock_bh(&odev->xmit_lock); 2809 spin_unlock_bh(&odev->xmit_lock);
2631 2810
2632 /* If pkt_dev->count is zero, then run forever */ 2811 /* If pkt_dev->count is zero, then run forever */
2633 if ((pkt_dev->count != 0) && (pkt_dev->sofar >= pkt_dev->count)) { 2812 if ((pkt_dev->count != 0) && (pkt_dev->sofar >= pkt_dev->count)) {
2634 if (atomic_read(&(pkt_dev->skb->users)) != 1) { 2813 if (atomic_read(&(pkt_dev->skb->users)) != 1) {
@@ -2641,72 +2820,74 @@ retry_now:
2641 } 2820 }
2642 pkt_dev->idle_acc += getCurUs() - idle_start; 2821 pkt_dev->idle_acc += getCurUs() - idle_start;
2643 } 2822 }
2644 2823
2645 /* Done with this */ 2824 /* Done with this */
2646 pktgen_stop_device(pkt_dev); 2825 pktgen_stop_device(pkt_dev);
2647 } 2826 if (pkt_dev->skb)
2648 out:; 2827 kfree_skb(pkt_dev->skb);
2649 } 2828 pkt_dev->skb = NULL;
2829 }
2830out:;
2831}
2650 2832
2651/* 2833/*
2652 * Main loop of the thread goes here 2834 * Main loop of the thread goes here
2653 */ 2835 */
2654 2836
2655static void pktgen_thread_worker(struct pktgen_thread *t) 2837static void pktgen_thread_worker(struct pktgen_thread *t)
2656{ 2838{
2657 DEFINE_WAIT(wait); 2839 DEFINE_WAIT(wait);
2658 struct pktgen_dev *pkt_dev = NULL; 2840 struct pktgen_dev *pkt_dev = NULL;
2659 int cpu = t->cpu; 2841 int cpu = t->cpu;
2660 sigset_t tmpsig; 2842 sigset_t tmpsig;
2661 u32 max_before_softirq; 2843 u32 max_before_softirq;
2662 u32 tx_since_softirq = 0; 2844 u32 tx_since_softirq = 0;
2663 2845
2664 daemonize("pktgen/%d", cpu); 2846 daemonize("pktgen/%d", cpu);
2665 2847
2666 /* Block all signals except SIGKILL, SIGSTOP and SIGTERM */ 2848 /* Block all signals except SIGKILL, SIGSTOP and SIGTERM */
2667 2849
2668 spin_lock_irq(&current->sighand->siglock); 2850 spin_lock_irq(&current->sighand->siglock);
2669 tmpsig = current->blocked; 2851 tmpsig = current->blocked;
2670 siginitsetinv(&current->blocked, 2852 siginitsetinv(&current->blocked,
2671 sigmask(SIGKILL) | 2853 sigmask(SIGKILL) | sigmask(SIGSTOP) | sigmask(SIGTERM));
2672 sigmask(SIGSTOP)|
2673 sigmask(SIGTERM));
2674 2854
2675 recalc_sigpending(); 2855 recalc_sigpending();
2676 spin_unlock_irq(&current->sighand->siglock); 2856 spin_unlock_irq(&current->sighand->siglock);
2677 2857
2678 /* Migrate to the right CPU */ 2858 /* Migrate to the right CPU */
2679 set_cpus_allowed(current, cpumask_of_cpu(cpu)); 2859 set_cpus_allowed(current, cpumask_of_cpu(cpu));
2680 if (smp_processor_id() != cpu) 2860 if (smp_processor_id() != cpu)
2681 BUG(); 2861 BUG();
2682 2862
2683 init_waitqueue_head(&t->queue); 2863 init_waitqueue_head(&t->queue);
2684 2864
2685 t->control &= ~(T_TERMINATE); 2865 t->control &= ~(T_TERMINATE);
2686 t->control &= ~(T_RUN); 2866 t->control &= ~(T_RUN);
2687 t->control &= ~(T_STOP); 2867 t->control &= ~(T_STOP);
2868 t->control &= ~(T_REMDEVALL);
2688 t->control &= ~(T_REMDEV); 2869 t->control &= ~(T_REMDEV);
2689 2870
2690 t->pid = current->pid; 2871 t->pid = current->pid;
2691 2872
2692 PG_DEBUG(printk("pktgen: starting pktgen/%d: pid=%d\n", cpu, current->pid)); 2873 PG_DEBUG(printk("pktgen: starting pktgen/%d: pid=%d\n", cpu, current->pid));
2693 2874
2694 max_before_softirq = t->max_before_softirq; 2875 max_before_softirq = t->max_before_softirq;
2695
2696 __set_current_state(TASK_INTERRUPTIBLE);
2697 mb();
2698 2876
2699 while (1) { 2877 __set_current_state(TASK_INTERRUPTIBLE);
2700 2878 mb();
2879
2880 while (1) {
2881
2701 __set_current_state(TASK_RUNNING); 2882 __set_current_state(TASK_RUNNING);
2702 2883
2703 /* 2884 /*
2704 * Get next dev to xmit -- if any. 2885 * Get next dev to xmit -- if any.
2705 */ 2886 */
2706 2887
2707 pkt_dev = next_to_run(t); 2888 pkt_dev = next_to_run(t);
2708 2889
2709 if (pkt_dev) { 2890 if (pkt_dev) {
2710 2891
2711 pktgen_xmit(pkt_dev); 2892 pktgen_xmit(pkt_dev);
2712 2893
@@ -2724,115 +2905,125 @@ static void pktgen_thread_worker(struct pktgen_thread *t)
2724 } 2905 }
2725 } else { 2906 } else {
2726 prepare_to_wait(&(t->queue), &wait, TASK_INTERRUPTIBLE); 2907 prepare_to_wait(&(t->queue), &wait, TASK_INTERRUPTIBLE);
2727 schedule_timeout(HZ/10); 2908 schedule_timeout(HZ / 10);
2728 finish_wait(&(t->queue), &wait); 2909 finish_wait(&(t->queue), &wait);
2729 } 2910 }
2730 2911
2731 /* 2912 /*
2732 * Back from sleep, either due to the timeout or signal. 2913 * Back from sleep, either due to the timeout or signal.
2733 * We check if we have any "posted" work for us. 2914 * We check if we have any "posted" work for us.
2734 */ 2915 */
2735 2916
2736 if (t->control & T_TERMINATE || signal_pending(current)) 2917 if (t->control & T_TERMINATE || signal_pending(current))
2737 /* we received a request to terminate ourself */ 2918 /* we received a request to terminate ourself */
2738 break; 2919 break;
2739
2740 2920
2741 if(t->control & T_STOP) { 2921 if (t->control & T_STOP) {
2742 pktgen_stop(t); 2922 pktgen_stop(t);
2743 t->control &= ~(T_STOP); 2923 t->control &= ~(T_STOP);
2744 } 2924 }
2745 2925
2746 if(t->control & T_RUN) { 2926 if (t->control & T_RUN) {
2747 pktgen_run(t); 2927 pktgen_run(t);
2748 t->control &= ~(T_RUN); 2928 t->control &= ~(T_RUN);
2749 } 2929 }
2750 2930
2751 if(t->control & T_REMDEV) { 2931 if (t->control & T_REMDEVALL) {
2752 pktgen_rem_all_ifs(t); 2932 pktgen_rem_all_ifs(t);
2933 t->control &= ~(T_REMDEVALL);
2934 }
2935
2936 if (t->control & T_REMDEV) {
2937 pktgen_rem_one_if(t);
2753 t->control &= ~(T_REMDEV); 2938 t->control &= ~(T_REMDEV);
2754 } 2939 }
2755 2940
2756 if (need_resched()) 2941 if (need_resched())
2757 schedule(); 2942 schedule();
2758 } 2943 }
2944
2945 PG_DEBUG(printk("pktgen: %s stopping all device\n", t->name));
2946 pktgen_stop(t);
2759 2947
2760 PG_DEBUG(printk("pktgen: %s stopping all device\n", t->name)); 2948 PG_DEBUG(printk("pktgen: %s removing all device\n", t->name));
2761 pktgen_stop(t); 2949 pktgen_rem_all_ifs(t);
2762 2950
2763 PG_DEBUG(printk("pktgen: %s removing all device\n", t->name)); 2951 PG_DEBUG(printk("pktgen: %s removing thread.\n", t->name));
2764 pktgen_rem_all_ifs(t); 2952 pktgen_rem_thread(t);
2765 2953
2766 PG_DEBUG(printk("pktgen: %s removing thread.\n", t->name)); 2954 t->removed = 1;
2767 pktgen_rem_thread(t);
2768} 2955}
2769 2956
2770static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t, const char* ifname) 2957static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
2958 const char *ifname)
2771{ 2959{
2772 struct pktgen_dev *pkt_dev = NULL; 2960 struct pktgen_dev *p, *pkt_dev = NULL;
2773 if_lock(t); 2961 if_lock(t);
2774 2962
2775 for(pkt_dev=t->if_list; pkt_dev; pkt_dev = pkt_dev->next ) { 2963 list_for_each_entry(p, &t->if_list, list)
2776 if (strncmp(pkt_dev->ifname, ifname, IFNAMSIZ) == 0) { 2964 if (strncmp(p->ifname, ifname, IFNAMSIZ) == 0) {
2777 break; 2965 pkt_dev = p;
2778 } 2966 break;
2779 } 2967 }
2780 2968
2781 if_unlock(t); 2969 if_unlock(t);
2782 PG_DEBUG(printk("pktgen: find_dev(%s) returning %p\n", ifname,pkt_dev)); 2970 PG_DEBUG(printk("pktgen: find_dev(%s) returning %p\n", ifname, pkt_dev));
2783 return pkt_dev; 2971 return pkt_dev;
2784} 2972}
2785 2973
2786/* 2974/*
2787 * Adds a dev at front of if_list. 2975 * Adds a dev at front of if_list.
2788 */ 2976 */
2789 2977
2790static int add_dev_to_thread(struct pktgen_thread *t, struct pktgen_dev *pkt_dev) 2978static int add_dev_to_thread(struct pktgen_thread *t,
2979 struct pktgen_dev *pkt_dev)
2791{ 2980{
2792 int rv = 0; 2981 int rv = 0;
2793 2982
2794 if_lock(t); 2983 if_lock(t);
2795 2984
2796 if (pkt_dev->pg_thread) { 2985 if (pkt_dev->pg_thread) {
2797 printk("pktgen: ERROR: already assigned to a thread.\n"); 2986 printk("pktgen: ERROR: already assigned to a thread.\n");
2798 rv = -EBUSY; 2987 rv = -EBUSY;
2799 goto out; 2988 goto out;
2800 } 2989 }
2801 pkt_dev->next =t->if_list; t->if_list=pkt_dev; 2990
2802 pkt_dev->pg_thread = t; 2991 list_add(&pkt_dev->list, &t->if_list);
2992 pkt_dev->pg_thread = t;
2803 pkt_dev->running = 0; 2993 pkt_dev->running = 0;
2804 2994
2805 out: 2995out:
2806 if_unlock(t); 2996 if_unlock(t);
2807 return rv; 2997 return rv;
2808} 2998}
2809 2999
2810/* Called under thread lock */ 3000/* Called under thread lock */
2811 3001
2812static int pktgen_add_device(struct pktgen_thread *t, const char* ifname) 3002static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
2813{ 3003{
2814 struct pktgen_dev *pkt_dev; 3004 struct pktgen_dev *pkt_dev;
2815 struct proc_dir_entry *pe; 3005 struct proc_dir_entry *pe;
2816 3006
2817 /* We don't allow a device to be on several threads */ 3007 /* We don't allow a device to be on several threads */
2818 3008
2819 pkt_dev = __pktgen_NN_threads(ifname, FIND); 3009 pkt_dev = __pktgen_NN_threads(ifname, FIND);
2820 if (pkt_dev) { 3010 if (pkt_dev) {
2821 printk("pktgen: ERROR: interface already used.\n"); 3011 printk("pktgen: ERROR: interface already used.\n");
2822 return -EBUSY; 3012 return -EBUSY;
2823 } 3013 }
2824 3014
2825 pkt_dev = kzalloc(sizeof(struct pktgen_dev), GFP_KERNEL); 3015 pkt_dev = kzalloc(sizeof(struct pktgen_dev), GFP_KERNEL);
2826 if (!pkt_dev) 3016 if (!pkt_dev)
2827 return -ENOMEM; 3017 return -ENOMEM;
2828 3018
2829 pkt_dev->flows = vmalloc(MAX_CFLOWS*sizeof(struct flow_state)); 3019 pkt_dev->flows = vmalloc(MAX_CFLOWS * sizeof(struct flow_state));
2830 if (pkt_dev->flows == NULL) { 3020 if (pkt_dev->flows == NULL) {
2831 kfree(pkt_dev); 3021 kfree(pkt_dev);
2832 return -ENOMEM; 3022 return -ENOMEM;
2833 } 3023 }
2834 memset(pkt_dev->flows, 0, MAX_CFLOWS*sizeof(struct flow_state)); 3024 memset(pkt_dev->flows, 0, MAX_CFLOWS * sizeof(struct flow_state));
2835 3025
3026 pkt_dev->removal_mark = 0;
2836 pkt_dev->min_pkt_size = ETH_ZLEN; 3027 pkt_dev->min_pkt_size = ETH_ZLEN;
2837 pkt_dev->max_pkt_size = ETH_ZLEN; 3028 pkt_dev->max_pkt_size = ETH_ZLEN;
2838 pkt_dev->nfrags = 0; 3029 pkt_dev->nfrags = 0;
@@ -2841,14 +3032,14 @@ static int pktgen_add_device(struct pktgen_thread *t, const char* ifname)
2841 pkt_dev->delay_ns = pg_delay_d % 1000; 3032 pkt_dev->delay_ns = pg_delay_d % 1000;
2842 pkt_dev->count = pg_count_d; 3033 pkt_dev->count = pg_count_d;
2843 pkt_dev->sofar = 0; 3034 pkt_dev->sofar = 0;
2844 pkt_dev->udp_src_min = 9; /* sink port */ 3035 pkt_dev->udp_src_min = 9; /* sink port */
2845 pkt_dev->udp_src_max = 9; 3036 pkt_dev->udp_src_max = 9;
2846 pkt_dev->udp_dst_min = 9; 3037 pkt_dev->udp_dst_min = 9;
2847 pkt_dev->udp_dst_max = 9; 3038 pkt_dev->udp_dst_max = 9;
2848 3039
2849 strncpy(pkt_dev->ifname, ifname, IFNAMSIZ); 3040 strncpy(pkt_dev->ifname, ifname, IFNAMSIZ);
2850 3041
2851 if (! pktgen_setup_dev(pkt_dev)) { 3042 if (!pktgen_setup_dev(pkt_dev)) {
2852 printk("pktgen: ERROR: pktgen_setup_dev failed.\n"); 3043 printk("pktgen: ERROR: pktgen_setup_dev failed.\n");
2853 if (pkt_dev->flows) 3044 if (pkt_dev->flows)
2854 vfree(pkt_dev->flows); 3045 vfree(pkt_dev->flows);
@@ -2871,65 +3062,74 @@ static int pktgen_add_device(struct pktgen_thread *t, const char* ifname)
2871 return add_dev_to_thread(t, pkt_dev); 3062 return add_dev_to_thread(t, pkt_dev);
2872} 3063}
2873 3064
2874static struct pktgen_thread * __init pktgen_find_thread(const char* name) 3065static struct pktgen_thread *__init pktgen_find_thread(const char *name)
2875{ 3066{
2876 struct pktgen_thread *t = NULL; 3067 struct pktgen_thread *t;
2877 3068
2878 thread_lock(); 3069 mutex_lock(&pktgen_thread_lock);
2879 3070
2880 t = pktgen_threads; 3071 list_for_each_entry(t, &pktgen_threads, th_list)
2881 while (t) { 3072 if (strcmp(t->name, name) == 0) {
2882 if (strcmp(t->name, name) == 0) 3073 mutex_unlock(&pktgen_thread_lock);
2883 break; 3074 return t;
3075 }
2884 3076
2885 t = t->next; 3077 mutex_unlock(&pktgen_thread_lock);
2886 } 3078 return NULL;
2887 thread_unlock();
2888 return t;
2889} 3079}
2890 3080
2891static int __init pktgen_create_thread(const char* name, int cpu) 3081static int __init pktgen_create_thread(const char *name, int cpu)
2892{ 3082{
2893 struct pktgen_thread *t = NULL; 3083 int err;
3084 struct pktgen_thread *t = NULL;
2894 struct proc_dir_entry *pe; 3085 struct proc_dir_entry *pe;
2895 3086
2896 if (strlen(name) > 31) { 3087 if (strlen(name) > 31) {
2897 printk("pktgen: ERROR: Thread name cannot be more than 31 characters.\n"); 3088 printk("pktgen: ERROR: Thread name cannot be more than 31 characters.\n");
2898 return -EINVAL; 3089 return -EINVAL;
2899 } 3090 }
2900 3091
2901 if (pktgen_find_thread(name)) { 3092 if (pktgen_find_thread(name)) {
2902 printk("pktgen: ERROR: thread: %s already exists\n", name); 3093 printk("pktgen: ERROR: thread: %s already exists\n", name);
2903 return -EINVAL; 3094 return -EINVAL;
2904 } 3095 }
2905 3096
2906 t = kzalloc(sizeof(struct pktgen_thread), GFP_KERNEL); 3097 t = kzalloc(sizeof(struct pktgen_thread), GFP_KERNEL);
2907 if (!t) { 3098 if (!t) {
2908 printk("pktgen: ERROR: out of memory, can't create new thread.\n"); 3099 printk("pktgen: ERROR: out of memory, can't create new thread.\n");
2909 return -ENOMEM; 3100 return -ENOMEM;
2910 } 3101 }
2911 3102
2912 strcpy(t->name, name); 3103 strcpy(t->name, name);
2913 spin_lock_init(&t->if_lock); 3104 spin_lock_init(&t->if_lock);
2914 t->cpu = cpu; 3105 t->cpu = cpu;
2915 3106
2916 pe = create_proc_entry(t->name, 0600, pg_proc_dir); 3107 pe = create_proc_entry(t->name, 0600, pg_proc_dir);
2917 if (!pe) { 3108 if (!pe) {
2918 printk("pktgen: cannot create %s/%s procfs entry.\n", 3109 printk("pktgen: cannot create %s/%s procfs entry.\n",
2919 PG_PROC_DIR, t->name); 3110 PG_PROC_DIR, t->name);
2920 kfree(t); 3111 kfree(t);
2921 return -EINVAL; 3112 return -EINVAL;
2922 } 3113 }
2923 3114
2924 pe->proc_fops = &pktgen_thread_fops; 3115 pe->proc_fops = &pktgen_thread_fops;
2925 pe->data = t; 3116 pe->data = t;
2926 3117
2927 t->next = pktgen_threads; 3118 INIT_LIST_HEAD(&t->if_list);
2928 pktgen_threads = t;
2929 3119
2930 if (kernel_thread((void *) pktgen_thread_worker, (void *) t, 3120 list_add_tail(&t->th_list, &pktgen_threads);
2931 CLONE_FS | CLONE_FILES | CLONE_SIGHAND) < 0) 3121
3122 t->removed = 0;
3123
3124 err = kernel_thread((void *)pktgen_thread_worker, (void *)t,
3125 CLONE_FS | CLONE_FILES | CLONE_SIGHAND);
3126 if (err < 0) {
2932 printk("pktgen: kernel_thread() failed for cpu %d\n", t->cpu); 3127 printk("pktgen: kernel_thread() failed for cpu %d\n", t->cpu);
3128 remove_proc_entry(t->name, pg_proc_dir);
3129 list_del(&t->th_list);
3130 kfree(t);
3131 return err;
3132 }
2933 3133
2934 return 0; 3134 return 0;
2935} 3135}
@@ -2937,55 +3137,52 @@ static int __init pktgen_create_thread(const char* name, int cpu)
2937/* 3137/*
2938 * Removes a device from the thread if_list. 3138 * Removes a device from the thread if_list.
2939 */ 3139 */
2940static void _rem_dev_from_if_list(struct pktgen_thread *t, struct pktgen_dev *pkt_dev) 3140static void _rem_dev_from_if_list(struct pktgen_thread *t,
3141 struct pktgen_dev *pkt_dev)
2941{ 3142{
2942 struct pktgen_dev *i, *prev = NULL; 3143 struct list_head *q, *n;
2943 3144 struct pktgen_dev *p;
2944 i = t->if_list;
2945 3145
2946 while(i) { 3146 list_for_each_safe(q, n, &t->if_list) {
2947 if(i == pkt_dev) { 3147 p = list_entry(q, struct pktgen_dev, list);
2948 if(prev) prev->next = i->next; 3148 if (p == pkt_dev)
2949 else t->if_list = NULL; 3149 list_del(&p->list);
2950 break;
2951 }
2952 prev = i;
2953 i=i->next;
2954 } 3150 }
2955} 3151}
2956 3152
2957static int pktgen_remove_device(struct pktgen_thread *t, struct pktgen_dev *pkt_dev) 3153static int pktgen_remove_device(struct pktgen_thread *t,
3154 struct pktgen_dev *pkt_dev)
2958{ 3155{
2959 3156
2960 PG_DEBUG(printk("pktgen: remove_device pkt_dev=%p\n", pkt_dev)); 3157 PG_DEBUG(printk("pktgen: remove_device pkt_dev=%p\n", pkt_dev));
2961 3158
2962 if (pkt_dev->running) { 3159 if (pkt_dev->running) {
2963 printk("pktgen:WARNING: trying to remove a running interface, stopping it now.\n"); 3160 printk("pktgen:WARNING: trying to remove a running interface, stopping it now.\n");
2964 pktgen_stop_device(pkt_dev); 3161 pktgen_stop_device(pkt_dev);
2965 } 3162 }
2966 3163
2967 /* Dis-associate from the interface */ 3164 /* Dis-associate from the interface */
2968 3165
2969 if (pkt_dev->odev) { 3166 if (pkt_dev->odev) {
2970 dev_put(pkt_dev->odev); 3167 dev_put(pkt_dev->odev);
2971 pkt_dev->odev = NULL; 3168 pkt_dev->odev = NULL;
2972 } 3169 }
2973 3170
2974 /* And update the thread if_list */ 3171 /* And update the thread if_list */
2975 3172
2976 _rem_dev_from_if_list(t, pkt_dev); 3173 _rem_dev_from_if_list(t, pkt_dev);
2977 3174
2978 /* Clean up proc file system */ 3175 /* Clean up proc file system */
2979 3176
2980 remove_proc_entry(pkt_dev->ifname, pg_proc_dir); 3177 remove_proc_entry(pkt_dev->ifname, pg_proc_dir);
2981 3178
2982 if (pkt_dev->flows) 3179 if (pkt_dev->flows)
2983 vfree(pkt_dev->flows); 3180 vfree(pkt_dev->flows);
2984 kfree(pkt_dev); 3181 kfree(pkt_dev);
2985 return 0; 3182 return 0;
2986} 3183}
2987 3184
2988static int __init pg_init(void) 3185static int __init pg_init(void)
2989{ 3186{
2990 int cpu; 3187 int cpu;
2991 struct proc_dir_entry *pe; 3188 struct proc_dir_entry *pe;
@@ -2998,50 +3195,65 @@ static int __init pg_init(void)
2998 pg_proc_dir->owner = THIS_MODULE; 3195 pg_proc_dir->owner = THIS_MODULE;
2999 3196
3000 pe = create_proc_entry(PGCTRL, 0600, pg_proc_dir); 3197 pe = create_proc_entry(PGCTRL, 0600, pg_proc_dir);
3001 if (pe == NULL) { 3198 if (pe == NULL) {
3002 printk("pktgen: ERROR: cannot create %s procfs entry.\n", PGCTRL); 3199 printk("pktgen: ERROR: cannot create %s procfs entry.\n",
3200 PGCTRL);
3003 proc_net_remove(PG_PROC_DIR); 3201 proc_net_remove(PG_PROC_DIR);
3004 return -EINVAL; 3202 return -EINVAL;
3005 } 3203 }
3006 3204
3007 pe->proc_fops = &pktgen_fops; 3205 pe->proc_fops = &pktgen_fops;
3008 pe->data = NULL; 3206 pe->data = NULL;
3009 3207
3010 /* Register us to receive netdevice events */ 3208 /* Register us to receive netdevice events */
3011 register_netdevice_notifier(&pktgen_notifier_block); 3209 register_netdevice_notifier(&pktgen_notifier_block);
3012 3210
3013 for_each_online_cpu(cpu) { 3211 for_each_online_cpu(cpu) {
3212 int err;
3014 char buf[30]; 3213 char buf[30];
3015 3214
3016 sprintf(buf, "kpktgend_%i", cpu); 3215 sprintf(buf, "kpktgend_%i", cpu);
3017 pktgen_create_thread(buf, cpu); 3216 err = pktgen_create_thread(buf, cpu);
3018 } 3217 if (err)
3019 return 0; 3218 printk("pktgen: WARNING: Cannot create thread for cpu %d (%d)\n",
3219 cpu, err);
3220 }
3221
3222 if (list_empty(&pktgen_threads)) {
3223 printk("pktgen: ERROR: Initialization failed for all threads\n");
3224 unregister_netdevice_notifier(&pktgen_notifier_block);
3225 remove_proc_entry(PGCTRL, pg_proc_dir);
3226 proc_net_remove(PG_PROC_DIR);
3227 return -ENODEV;
3228 }
3229
3230 return 0;
3020} 3231}
3021 3232
3022static void __exit pg_cleanup(void) 3233static void __exit pg_cleanup(void)
3023{ 3234{
3235 struct pktgen_thread *t;
3236 struct list_head *q, *n;
3024 wait_queue_head_t queue; 3237 wait_queue_head_t queue;
3025 init_waitqueue_head(&queue); 3238 init_waitqueue_head(&queue);
3026 3239
3027 /* Stop all interfaces & threads */ 3240 /* Stop all interfaces & threads */
3028 3241
3029 while (pktgen_threads) { 3242 list_for_each_safe(q, n, &pktgen_threads) {
3030 struct pktgen_thread *t = pktgen_threads; 3243 t = list_entry(q, struct pktgen_thread, th_list);
3031 pktgen_threads->control |= (T_TERMINATE); 3244 t->control |= (T_TERMINATE);
3032 3245
3033 wait_event_interruptible_timeout(queue, (t != pktgen_threads), HZ); 3246 wait_event_interruptible_timeout(queue, (t->removed == 1), HZ);
3034 } 3247 }
3035 3248
3036 /* Un-register us from receiving netdevice events */ 3249 /* Un-register us from receiving netdevice events */
3037 unregister_netdevice_notifier(&pktgen_notifier_block); 3250 unregister_netdevice_notifier(&pktgen_notifier_block);
3038 3251
3039 /* Clean up proc file system */ 3252 /* Clean up proc file system */
3040 remove_proc_entry(PGCTRL, pg_proc_dir); 3253 remove_proc_entry(PGCTRL, pg_proc_dir);
3041 proc_net_remove(PG_PROC_DIR); 3254 proc_net_remove(PG_PROC_DIR);
3042} 3255}
3043 3256
3044
3045module_init(pg_init); 3257module_init(pg_init);
3046module_exit(pg_cleanup); 3258module_exit(pg_cleanup);
3047 3259
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index eca2976abb25..ae10d3740faa 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -35,6 +35,7 @@
35#include <linux/skbuff.h> 35#include <linux/skbuff.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/security.h> 37#include <linux/security.h>
38#include <linux/mutex.h>
38 39
39#include <asm/uaccess.h> 40#include <asm/uaccess.h>
40#include <asm/system.h> 41#include <asm/system.h>
@@ -51,25 +52,31 @@
51#include <net/pkt_sched.h> 52#include <net/pkt_sched.h>
52#include <net/netlink.h> 53#include <net/netlink.h>
53 54
54DECLARE_MUTEX(rtnl_sem); 55static DEFINE_MUTEX(rtnl_mutex);
55 56
56void rtnl_lock(void) 57void rtnl_lock(void)
57{ 58{
58 rtnl_shlock(); 59 mutex_lock(&rtnl_mutex);
59} 60}
60 61
61int rtnl_lock_interruptible(void) 62void __rtnl_unlock(void)
62{ 63{
63 return down_interruptible(&rtnl_sem); 64 mutex_unlock(&rtnl_mutex);
64} 65}
65 66
66void rtnl_unlock(void) 67void rtnl_unlock(void)
67{ 68{
68 rtnl_shunlock(); 69 mutex_unlock(&rtnl_mutex);
69 70 if (rtnl && rtnl->sk_receive_queue.qlen)
71 rtnl->sk_data_ready(rtnl, 0);
70 netdev_run_todo(); 72 netdev_run_todo();
71} 73}
72 74
75int rtnl_trylock(void)
76{
77 return mutex_trylock(&rtnl_mutex);
78}
79
73int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len) 80int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len)
74{ 81{
75 memset(tb, 0, sizeof(struct rtattr*)*maxattr); 82 memset(tb, 0, sizeof(struct rtattr*)*maxattr);
@@ -179,6 +186,33 @@ rtattr_failure:
179} 186}
180 187
181 188
189static void set_operstate(struct net_device *dev, unsigned char transition)
190{
191 unsigned char operstate = dev->operstate;
192
193 switch(transition) {
194 case IF_OPER_UP:
195 if ((operstate == IF_OPER_DORMANT ||
196 operstate == IF_OPER_UNKNOWN) &&
197 !netif_dormant(dev))
198 operstate = IF_OPER_UP;
199 break;
200
201 case IF_OPER_DORMANT:
202 if (operstate == IF_OPER_UP ||
203 operstate == IF_OPER_UNKNOWN)
204 operstate = IF_OPER_DORMANT;
205 break;
206 };
207
208 if (dev->operstate != operstate) {
209 write_lock_bh(&dev_base_lock);
210 dev->operstate = operstate;
211 write_unlock_bh(&dev_base_lock);
212 netdev_state_change(dev);
213 }
214}
215
182static int rtnetlink_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, 216static int rtnetlink_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
183 int type, u32 pid, u32 seq, u32 change, 217 int type, u32 pid, u32 seq, u32 change,
184 unsigned int flags) 218 unsigned int flags)
@@ -209,6 +243,13 @@ static int rtnetlink_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
209 } 243 }
210 244
211 if (1) { 245 if (1) {
246 u8 operstate = netif_running(dev)?dev->operstate:IF_OPER_DOWN;
247 u8 link_mode = dev->link_mode;
248 RTA_PUT(skb, IFLA_OPERSTATE, sizeof(operstate), &operstate);
249 RTA_PUT(skb, IFLA_LINKMODE, sizeof(link_mode), &link_mode);
250 }
251
252 if (1) {
212 struct rtnl_link_ifmap map = { 253 struct rtnl_link_ifmap map = {
213 .mem_start = dev->mem_start, 254 .mem_start = dev->mem_start,
214 .mem_end = dev->mem_end, 255 .mem_end = dev->mem_end,
@@ -399,6 +440,22 @@ static int do_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
399 dev->weight = *((u32 *) RTA_DATA(ida[IFLA_WEIGHT - 1])); 440 dev->weight = *((u32 *) RTA_DATA(ida[IFLA_WEIGHT - 1]));
400 } 441 }
401 442
443 if (ida[IFLA_OPERSTATE - 1]) {
444 if (ida[IFLA_OPERSTATE - 1]->rta_len != RTA_LENGTH(sizeof(u8)))
445 goto out;
446
447 set_operstate(dev, *((u8 *) RTA_DATA(ida[IFLA_OPERSTATE - 1])));
448 }
449
450 if (ida[IFLA_LINKMODE - 1]) {
451 if (ida[IFLA_LINKMODE - 1]->rta_len != RTA_LENGTH(sizeof(u8)))
452 goto out;
453
454 write_lock_bh(&dev_base_lock);
455 dev->link_mode = *((u8 *) RTA_DATA(ida[IFLA_LINKMODE - 1]));
456 write_unlock_bh(&dev_base_lock);
457 }
458
402 if (ifm->ifi_index >= 0 && ida[IFLA_IFNAME - 1]) { 459 if (ifm->ifi_index >= 0 && ida[IFLA_IFNAME - 1]) {
403 char ifname[IFNAMSIZ]; 460 char ifname[IFNAMSIZ];
404 461
@@ -575,9 +632,9 @@ static void rtnetlink_rcv(struct sock *sk, int len)
575 unsigned int qlen = 0; 632 unsigned int qlen = 0;
576 633
577 do { 634 do {
578 rtnl_lock(); 635 mutex_lock(&rtnl_mutex);
579 netlink_run_queue(sk, &qlen, &rtnetlink_rcv_msg); 636 netlink_run_queue(sk, &qlen, &rtnetlink_rcv_msg);
580 up(&rtnl_sem); 637 mutex_unlock(&rtnl_mutex);
581 638
582 netdev_run_todo(); 639 netdev_run_todo();
583 } while (qlen); 640 } while (qlen);
@@ -654,6 +711,5 @@ EXPORT_SYMBOL(rtnetlink_links);
654EXPORT_SYMBOL(rtnetlink_put_metrics); 711EXPORT_SYMBOL(rtnetlink_put_metrics);
655EXPORT_SYMBOL(rtnl); 712EXPORT_SYMBOL(rtnl);
656EXPORT_SYMBOL(rtnl_lock); 713EXPORT_SYMBOL(rtnl_lock);
657EXPORT_SYMBOL(rtnl_lock_interruptible); 714EXPORT_SYMBOL(rtnl_trylock);
658EXPORT_SYMBOL(rtnl_sem);
659EXPORT_SYMBOL(rtnl_unlock); 715EXPORT_SYMBOL(rtnl_unlock);
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 2144952d1c6c..c9f878454531 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -356,6 +356,24 @@ void __kfree_skb(struct sk_buff *skb)
356} 356}
357 357
358/** 358/**
359 * kfree_skb - free an sk_buff
360 * @skb: buffer to free
361 *
362 * Drop a reference to the buffer and free it if the usage count has
363 * hit zero.
364 */
365void kfree_skb(struct sk_buff *skb)
366{
367 if (unlikely(!skb))
368 return;
369 if (likely(atomic_read(&skb->users) == 1))
370 smp_rmb();
371 else if (likely(!atomic_dec_and_test(&skb->users)))
372 return;
373 __kfree_skb(skb);
374}
375
376/**
359 * skb_clone - duplicate an sk_buff 377 * skb_clone - duplicate an sk_buff
360 * @skb: buffer to clone 378 * @skb: buffer to clone
361 * @gfp_mask: allocation priority 379 * @gfp_mask: allocation priority
@@ -1777,6 +1795,29 @@ int skb_append_datato_frags(struct sock *sk, struct sk_buff *skb,
1777 return 0; 1795 return 0;
1778} 1796}
1779 1797
1798/**
1799 * skb_pull_rcsum - pull skb and update receive checksum
1800 * @skb: buffer to update
1801 * @start: start of data before pull
1802 * @len: length of data pulled
1803 *
1804 * This function performs an skb_pull on the packet and updates
1805 * update the CHECKSUM_HW checksum. It should be used on receive
1806 * path processing instead of skb_pull unless you know that the
1807 * checksum difference is zero (e.g., a valid IP header) or you
1808 * are setting ip_summed to CHECKSUM_NONE.
1809 */
1810unsigned char *skb_pull_rcsum(struct sk_buff *skb, unsigned int len)
1811{
1812 BUG_ON(len > skb->len);
1813 skb->len -= len;
1814 BUG_ON(skb->len < skb->data_len);
1815 skb_postpull_rcsum(skb, skb->data, len);
1816 return skb->data += len;
1817}
1818
1819EXPORT_SYMBOL_GPL(skb_pull_rcsum);
1820
1780void __init skb_init(void) 1821void __init skb_init(void)
1781{ 1822{
1782 skbuff_head_cache = kmem_cache_create("skbuff_head_cache", 1823 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
@@ -1799,6 +1840,7 @@ void __init skb_init(void)
1799 1840
1800EXPORT_SYMBOL(___pskb_trim); 1841EXPORT_SYMBOL(___pskb_trim);
1801EXPORT_SYMBOL(__kfree_skb); 1842EXPORT_SYMBOL(__kfree_skb);
1843EXPORT_SYMBOL(kfree_skb);
1802EXPORT_SYMBOL(__pskb_pull_tail); 1844EXPORT_SYMBOL(__pskb_pull_tail);
1803EXPORT_SYMBOL(__alloc_skb); 1845EXPORT_SYMBOL(__alloc_skb);
1804EXPORT_SYMBOL(pskb_copy); 1846EXPORT_SYMBOL(pskb_copy);
diff --git a/net/core/sock.c b/net/core/sock.c
index 6e00811d44bc..1a7e6eac90b0 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -616,7 +616,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
616 break; 616 break;
617 617
618 case SO_PEERSEC: 618 case SO_PEERSEC:
619 return security_socket_getpeersec(sock, optval, optlen, len); 619 return security_socket_getpeersec_stream(sock, optval, optlen, len);
620 620
621 default: 621 default:
622 return(-ENOPROTOOPT); 622 return(-ENOPROTOOPT);
@@ -1385,6 +1385,20 @@ int sock_common_getsockopt(struct socket *sock, int level, int optname,
1385 1385
1386EXPORT_SYMBOL(sock_common_getsockopt); 1386EXPORT_SYMBOL(sock_common_getsockopt);
1387 1387
1388#ifdef CONFIG_COMPAT
1389int compat_sock_common_getsockopt(struct socket *sock, int level, int optname,
1390 char __user *optval, int __user *optlen)
1391{
1392 struct sock *sk = sock->sk;
1393
1394 if (sk->sk_prot->compat_setsockopt != NULL)
1395 return sk->sk_prot->compat_getsockopt(sk, level, optname,
1396 optval, optlen);
1397 return sk->sk_prot->getsockopt(sk, level, optname, optval, optlen);
1398}
1399EXPORT_SYMBOL(compat_sock_common_getsockopt);
1400#endif
1401
1388int sock_common_recvmsg(struct kiocb *iocb, struct socket *sock, 1402int sock_common_recvmsg(struct kiocb *iocb, struct socket *sock,
1389 struct msghdr *msg, size_t size, int flags) 1403 struct msghdr *msg, size_t size, int flags)
1390{ 1404{
@@ -1414,6 +1428,20 @@ int sock_common_setsockopt(struct socket *sock, int level, int optname,
1414 1428
1415EXPORT_SYMBOL(sock_common_setsockopt); 1429EXPORT_SYMBOL(sock_common_setsockopt);
1416 1430
1431#ifdef CONFIG_COMPAT
1432int compat_sock_common_setsockopt(struct socket *sock, int level, int optname,
1433 char __user *optval, int optlen)
1434{
1435 struct sock *sk = sock->sk;
1436
1437 if (sk->sk_prot->compat_setsockopt != NULL)
1438 return sk->sk_prot->compat_setsockopt(sk, level, optname,
1439 optval, optlen);
1440 return sk->sk_prot->setsockopt(sk, level, optname, optval, optlen);
1441}
1442EXPORT_SYMBOL(compat_sock_common_setsockopt);
1443#endif
1444
1417void sk_common_release(struct sock *sk) 1445void sk_common_release(struct sock *sk)
1418{ 1446{
1419 if (sk->sk_prot->destroy) 1447 if (sk->sk_prot->destroy)
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index 2f278c8e4743..710453656721 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -26,6 +26,11 @@ extern int sysctl_core_destroy_delay;
26extern char sysctl_divert_version[]; 26extern char sysctl_divert_version[];
27#endif /* CONFIG_NET_DIVERT */ 27#endif /* CONFIG_NET_DIVERT */
28 28
29#ifdef CONFIG_XFRM
30extern u32 sysctl_xfrm_aevent_etime;
31extern u32 sysctl_xfrm_aevent_rseqth;
32#endif
33
29ctl_table core_table[] = { 34ctl_table core_table[] = {
30#ifdef CONFIG_NET 35#ifdef CONFIG_NET
31 { 36 {
@@ -111,6 +116,24 @@ ctl_table core_table[] = {
111 .proc_handler = &proc_dostring 116 .proc_handler = &proc_dostring
112 }, 117 },
113#endif /* CONFIG_NET_DIVERT */ 118#endif /* CONFIG_NET_DIVERT */
119#ifdef CONFIG_XFRM
120 {
121 .ctl_name = NET_CORE_AEVENT_ETIME,
122 .procname = "xfrm_aevent_etime",
123 .data = &sysctl_xfrm_aevent_etime,
124 .maxlen = sizeof(u32),
125 .mode = 0644,
126 .proc_handler = &proc_dointvec
127 },
128 {
129 .ctl_name = NET_CORE_AEVENT_RSEQTH,
130 .procname = "xfrm_aevent_rseqth",
131 .data = &sysctl_xfrm_aevent_rseqth,
132 .maxlen = sizeof(u32),
133 .mode = 0644,
134 .proc_handler = &proc_dointvec
135 },
136#endif /* CONFIG_XFRM */
114#endif /* CONFIG_NET */ 137#endif /* CONFIG_NET */
115 { 138 {
116 .ctl_name = NET_CORE_SOMAXCONN, 139 .ctl_name = NET_CORE_SOMAXCONN,
diff --git a/net/dccp/Kconfig b/net/dccp/Kconfig
index 187ac182e24b..7e096ba8454f 100644
--- a/net/dccp/Kconfig
+++ b/net/dccp/Kconfig
@@ -24,6 +24,10 @@ config INET_DCCP_DIAG
24 def_tristate y if (IP_DCCP = y && INET_DIAG = y) 24 def_tristate y if (IP_DCCP = y && INET_DIAG = y)
25 def_tristate m 25 def_tristate m
26 26
27config IP_DCCP_ACKVEC
28 depends on IP_DCCP
29 def_bool N
30
27source "net/dccp/ccids/Kconfig" 31source "net/dccp/ccids/Kconfig"
28 32
29menu "DCCP Kernel Hacking" 33menu "DCCP Kernel Hacking"
@@ -36,15 +40,6 @@ config IP_DCCP_DEBUG
36 40
37 Just say N. 41 Just say N.
38 42
39config IP_DCCP_UNLOAD_HACK
40 depends on IP_DCCP=m && IP_DCCP_CCID3=m
41 bool "DCCP control sock unload hack"
42 ---help---
43 Enable this to be able to unload the dccp module when the it
44 has only one refcount held, the control sock one. Just execute
45 "rmmod dccp_ccid3 dccp"
46
47 Just say N.
48endmenu 43endmenu
49 44
50endmenu 45endmenu
diff --git a/net/dccp/Makefile b/net/dccp/Makefile
index 87b27fff6e3b..7696e219b05d 100644
--- a/net/dccp/Makefile
+++ b/net/dccp/Makefile
@@ -2,15 +2,18 @@ obj-$(CONFIG_IPV6) += dccp_ipv6.o
2 2
3dccp_ipv6-y := ipv6.o 3dccp_ipv6-y := ipv6.o
4 4
5obj-$(CONFIG_IP_DCCP) += dccp.o 5obj-$(CONFIG_IP_DCCP) += dccp.o dccp_ipv4.o
6 6
7dccp-y := ccid.o input.o ipv4.o minisocks.o options.o output.o proto.o \ 7dccp-y := ccid.o feat.o input.o minisocks.o options.o output.o proto.o timer.o
8 timer.o 8
9dccp_ipv4-y := ipv4.o
9 10
10dccp-$(CONFIG_IP_DCCP_ACKVEC) += ackvec.o 11dccp-$(CONFIG_IP_DCCP_ACKVEC) += ackvec.o
11 12
12obj-$(CONFIG_INET_DCCP_DIAG) += dccp_diag.o 13obj-$(CONFIG_INET_DCCP_DIAG) += dccp_diag.o
13 14
15dccp-$(CONFIG_SYSCTL) += sysctl.o
16
14dccp_diag-y := diag.o 17dccp_diag-y := diag.o
15 18
16obj-y += ccids/ 19obj-y += ccids/
diff --git a/net/dccp/ackvec.c b/net/dccp/ackvec.c
index 2c77dafbd091..b5981e5f6b00 100644
--- a/net/dccp/ackvec.c
+++ b/net/dccp/ackvec.c
@@ -13,36 +13,83 @@
13#include "dccp.h" 13#include "dccp.h"
14 14
15#include <linux/dccp.h> 15#include <linux/dccp.h>
16#include <linux/init.h>
17#include <linux/errno.h>
18#include <linux/kernel.h>
16#include <linux/skbuff.h> 19#include <linux/skbuff.h>
20#include <linux/slab.h>
17 21
18#include <net/sock.h> 22#include <net/sock.h>
19 23
24static kmem_cache_t *dccp_ackvec_slab;
25static kmem_cache_t *dccp_ackvec_record_slab;
26
27static struct dccp_ackvec_record *dccp_ackvec_record_new(void)
28{
29 struct dccp_ackvec_record *avr =
30 kmem_cache_alloc(dccp_ackvec_record_slab, GFP_ATOMIC);
31
32 if (avr != NULL)
33 INIT_LIST_HEAD(&avr->dccpavr_node);
34
35 return avr;
36}
37
38static void dccp_ackvec_record_delete(struct dccp_ackvec_record *avr)
39{
40 if (unlikely(avr == NULL))
41 return;
42 /* Check if deleting a linked record */
43 WARN_ON(!list_empty(&avr->dccpavr_node));
44 kmem_cache_free(dccp_ackvec_record_slab, avr);
45}
46
47static void dccp_ackvec_insert_avr(struct dccp_ackvec *av,
48 struct dccp_ackvec_record *avr)
49{
50 /*
51 * AVRs are sorted by seqno. Since we are sending them in order, we
52 * just add the AVR at the head of the list.
53 * -sorbo.
54 */
55 if (!list_empty(&av->dccpav_records)) {
56 const struct dccp_ackvec_record *head =
57 list_entry(av->dccpav_records.next,
58 struct dccp_ackvec_record,
59 dccpavr_node);
60 BUG_ON(before48(avr->dccpavr_ack_seqno,
61 head->dccpavr_ack_seqno));
62 }
63
64 list_add(&avr->dccpavr_node, &av->dccpav_records);
65}
66
20int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb) 67int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb)
21{ 68{
22 struct dccp_sock *dp = dccp_sk(sk); 69 struct dccp_sock *dp = dccp_sk(sk);
70#ifdef CONFIG_IP_DCCP_DEBUG
71 const char *debug_prefix = dp->dccps_role == DCCP_ROLE_CLIENT ?
72 "CLIENT tx: " : "server tx: ";
73#endif
23 struct dccp_ackvec *av = dp->dccps_hc_rx_ackvec; 74 struct dccp_ackvec *av = dp->dccps_hc_rx_ackvec;
24 int len = av->dccpav_vec_len + 2; 75 int len = av->dccpav_vec_len + 2;
25 struct timeval now; 76 struct timeval now;
26 u32 elapsed_time; 77 u32 elapsed_time;
27 unsigned char *to, *from; 78 unsigned char *to, *from;
79 struct dccp_ackvec_record *avr;
80
81 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN)
82 return -1;
28 83
29 dccp_timestamp(sk, &now); 84 dccp_timestamp(sk, &now);
30 elapsed_time = timeval_delta(&now, &av->dccpav_time) / 10; 85 elapsed_time = timeval_delta(&now, &av->dccpav_time) / 10;
31 86
32 if (elapsed_time != 0) 87 if (elapsed_time != 0 &&
33 dccp_insert_option_elapsed_time(sk, skb, elapsed_time); 88 dccp_insert_option_elapsed_time(sk, skb, elapsed_time))
34
35 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN)
36 return -1; 89 return -1;
37 90
38 /* 91 avr = dccp_ackvec_record_new();
39 * XXX: now we have just one ack vector sent record, so 92 if (avr == NULL)
40 * we have to wait for it to be cleared.
41 *
42 * Of course this is not acceptable, but this is just for
43 * basic testing now.
44 */
45 if (av->dccpav_ack_seqno != DCCP_MAX_SEQNO + 1)
46 return -1; 93 return -1;
47 94
48 DCCP_SKB_CB(skb)->dccpd_opt_len += len; 95 DCCP_SKB_CB(skb)->dccpd_opt_len += len;
@@ -55,8 +102,8 @@ int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb)
55 from = av->dccpav_buf + av->dccpav_buf_head; 102 from = av->dccpav_buf + av->dccpav_buf_head;
56 103
57 /* Check if buf_head wraps */ 104 /* Check if buf_head wraps */
58 if ((int)av->dccpav_buf_head + len > av->dccpav_vec_len) { 105 if ((int)av->dccpav_buf_head + len > DCCP_MAX_ACKVEC_LEN) {
59 const u32 tailsize = av->dccpav_vec_len - av->dccpav_buf_head; 106 const u32 tailsize = DCCP_MAX_ACKVEC_LEN - av->dccpav_buf_head;
60 107
61 memcpy(to, from, tailsize); 108 memcpy(to, from, tailsize);
62 to += tailsize; 109 to += tailsize;
@@ -73,45 +120,37 @@ int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb)
73 * sequence number it used for the ack packet; ack_ptr will equal 120 * sequence number it used for the ack packet; ack_ptr will equal
74 * buf_head; ack_ackno will equal buf_ackno; and ack_nonce will 121 * buf_head; ack_ackno will equal buf_ackno; and ack_nonce will
75 * equal buf_nonce. 122 * equal buf_nonce.
76 *
77 * This implemention uses just one ack record for now.
78 */ 123 */
79 av->dccpav_ack_seqno = DCCP_SKB_CB(skb)->dccpd_seq; 124 avr->dccpavr_ack_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
80 av->dccpav_ack_ptr = av->dccpav_buf_head; 125 avr->dccpavr_ack_ptr = av->dccpav_buf_head;
81 av->dccpav_ack_ackno = av->dccpav_buf_ackno; 126 avr->dccpavr_ack_ackno = av->dccpav_buf_ackno;
82 av->dccpav_ack_nonce = av->dccpav_buf_nonce; 127 avr->dccpavr_ack_nonce = av->dccpav_buf_nonce;
83 av->dccpav_sent_len = av->dccpav_vec_len; 128 avr->dccpavr_sent_len = av->dccpav_vec_len;
129
130 dccp_ackvec_insert_avr(av, avr);
84 131
85 dccp_pr_debug("%sACK Vector 0, len=%d, ack_seqno=%llu, " 132 dccp_pr_debug("%sACK Vector 0, len=%d, ack_seqno=%llu, "
86 "ack_ackno=%llu\n", 133 "ack_ackno=%llu\n",
87 debug_prefix, av->dccpav_sent_len, 134 debug_prefix, avr->dccpavr_sent_len,
88 (unsigned long long)av->dccpav_ack_seqno, 135 (unsigned long long)avr->dccpavr_ack_seqno,
89 (unsigned long long)av->dccpav_ack_ackno); 136 (unsigned long long)avr->dccpavr_ack_ackno);
90 return -1; 137 return 0;
91} 138}
92 139
93struct dccp_ackvec *dccp_ackvec_alloc(const unsigned int len, 140struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority)
94 const gfp_t priority)
95{ 141{
96 struct dccp_ackvec *av; 142 struct dccp_ackvec *av = kmem_cache_alloc(dccp_ackvec_slab, priority);
97
98 BUG_ON(len == 0);
99 143
100 if (len > DCCP_MAX_ACKVEC_LEN)
101 return NULL;
102
103 av = kmalloc(sizeof(*av) + len, priority);
104 if (av != NULL) { 144 if (av != NULL) {
105 av->dccpav_buf_len = len;
106 av->dccpav_buf_head = 145 av->dccpav_buf_head =
107 av->dccpav_buf_tail = av->dccpav_buf_len - 1; 146 av->dccpav_buf_tail = DCCP_MAX_ACKVEC_LEN - 1;
108 av->dccpav_buf_ackno = 147 av->dccpav_buf_ackno = DCCP_MAX_SEQNO + 1;
109 av->dccpav_ack_ackno = av->dccpav_ack_seqno = ~0LLU;
110 av->dccpav_buf_nonce = av->dccpav_buf_nonce = 0; 148 av->dccpav_buf_nonce = av->dccpav_buf_nonce = 0;
111 av->dccpav_ack_ptr = 0; 149 av->dccpav_ack_ptr = 0;
112 av->dccpav_time.tv_sec = 0; 150 av->dccpav_time.tv_sec = 0;
113 av->dccpav_time.tv_usec = 0; 151 av->dccpav_time.tv_usec = 0;
114 av->dccpav_sent_len = av->dccpav_vec_len = 0; 152 av->dccpav_sent_len = av->dccpav_vec_len = 0;
153 INIT_LIST_HEAD(&av->dccpav_records);
115 } 154 }
116 155
117 return av; 156 return av;
@@ -119,7 +158,20 @@ struct dccp_ackvec *dccp_ackvec_alloc(const unsigned int len,
119 158
120void dccp_ackvec_free(struct dccp_ackvec *av) 159void dccp_ackvec_free(struct dccp_ackvec *av)
121{ 160{
122 kfree(av); 161 if (unlikely(av == NULL))
162 return;
163
164 if (!list_empty(&av->dccpav_records)) {
165 struct dccp_ackvec_record *avr, *next;
166
167 list_for_each_entry_safe(avr, next, &av->dccpav_records,
168 dccpavr_node) {
169 list_del_init(&avr->dccpavr_node);
170 dccp_ackvec_record_delete(avr);
171 }
172 }
173
174 kmem_cache_free(dccp_ackvec_slab, av);
123} 175}
124 176
125static inline u8 dccp_ackvec_state(const struct dccp_ackvec *av, 177static inline u8 dccp_ackvec_state(const struct dccp_ackvec *av,
@@ -146,7 +198,7 @@ static inline int dccp_ackvec_set_buf_head_state(struct dccp_ackvec *av,
146 unsigned int gap; 198 unsigned int gap;
147 long new_head; 199 long new_head;
148 200
149 if (av->dccpav_vec_len + packets > av->dccpav_buf_len) 201 if (av->dccpav_vec_len + packets > DCCP_MAX_ACKVEC_LEN)
150 return -ENOBUFS; 202 return -ENOBUFS;
151 203
152 gap = packets - 1; 204 gap = packets - 1;
@@ -158,7 +210,7 @@ static inline int dccp_ackvec_set_buf_head_state(struct dccp_ackvec *av,
158 gap + new_head + 1); 210 gap + new_head + 1);
159 gap = -new_head; 211 gap = -new_head;
160 } 212 }
161 new_head += av->dccpav_buf_len; 213 new_head += DCCP_MAX_ACKVEC_LEN;
162 } 214 }
163 215
164 av->dccpav_buf_head = new_head; 216 av->dccpav_buf_head = new_head;
@@ -251,7 +303,7 @@ int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
251 goto out_duplicate; 303 goto out_duplicate;
252 304
253 delta -= len + 1; 305 delta -= len + 1;
254 if (++index == av->dccpav_buf_len) 306 if (++index == DCCP_MAX_ACKVEC_LEN)
255 index = 0; 307 index = 0;
256 } 308 }
257 } 309 }
@@ -259,7 +311,6 @@ int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
259 av->dccpav_buf_ackno = ackno; 311 av->dccpav_buf_ackno = ackno;
260 dccp_timestamp(sk, &av->dccpav_time); 312 dccp_timestamp(sk, &av->dccpav_time);
261out: 313out:
262 dccp_pr_debug("");
263 return 0; 314 return 0;
264 315
265out_duplicate: 316out_duplicate:
@@ -297,44 +348,50 @@ void dccp_ackvec_print(const struct dccp_ackvec *av)
297} 348}
298#endif 349#endif
299 350
300static void dccp_ackvec_throw_away_ack_record(struct dccp_ackvec *av) 351static void dccp_ackvec_throw_record(struct dccp_ackvec *av,
352 struct dccp_ackvec_record *avr)
301{ 353{
302 /* 354 struct dccp_ackvec_record *next;
303 * As we're keeping track of the ack vector size (dccpav_vec_len) and 355
304 * the sent ack vector size (dccpav_sent_len) we don't need 356 av->dccpav_buf_tail = avr->dccpavr_ack_ptr - 1;
305 * dccpav_buf_tail at all, but keep this code here as in the future 357 if (av->dccpav_buf_tail == 0)
306 * we'll implement a vector of ack records, as suggested in 358 av->dccpav_buf_tail = DCCP_MAX_ACKVEC_LEN - 1;
307 * draft-ietf-dccp-spec-11.txt Appendix A. -acme 359
308 */ 360 av->dccpav_vec_len -= avr->dccpavr_sent_len;
309#if 0 361
310 u32 new_buf_tail = av->dccpav_ack_ptr + 1; 362 /* free records */
311 if (new_buf_tail >= av->dccpav_vec_len) 363 list_for_each_entry_safe_from(avr, next, &av->dccpav_records,
312 new_buf_tail -= av->dccpav_vec_len; 364 dccpavr_node) {
313 av->dccpav_buf_tail = new_buf_tail; 365 list_del_init(&avr->dccpavr_node);
314#endif 366 dccp_ackvec_record_delete(avr);
315 av->dccpav_vec_len -= av->dccpav_sent_len; 367 }
316} 368}
317 369
318void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av, struct sock *sk, 370void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av, struct sock *sk,
319 const u64 ackno) 371 const u64 ackno)
320{ 372{
321 /* Check if we actually sent an ACK vector */ 373 struct dccp_ackvec_record *avr;
322 if (av->dccpav_ack_seqno == DCCP_MAX_SEQNO + 1)
323 return;
324 374
325 if (ackno == av->dccpav_ack_seqno) { 375 /*
376 * If we traverse backwards, it should be faster when we have large
377 * windows. We will be receiving ACKs for stuff we sent a while back
378 * -sorbo.
379 */
380 list_for_each_entry_reverse(avr, &av->dccpav_records, dccpavr_node) {
381 if (ackno == avr->dccpavr_ack_seqno) {
326#ifdef CONFIG_IP_DCCP_DEBUG 382#ifdef CONFIG_IP_DCCP_DEBUG
327 struct dccp_sock *dp = dccp_sk(sk); 383 struct dccp_sock *dp = dccp_sk(sk);
328 const char *debug_prefix = dp->dccps_role == DCCP_ROLE_CLIENT ? 384 const char *debug_prefix = dp->dccps_role == DCCP_ROLE_CLIENT ?
329 "CLIENT rx ack: " : "server rx ack: "; 385 "CLIENT rx ack: " : "server rx ack: ";
330#endif 386#endif
331 dccp_pr_debug("%sACK packet 0, len=%d, ack_seqno=%llu, " 387 dccp_pr_debug("%sACK packet 0, len=%d, ack_seqno=%llu, "
332 "ack_ackno=%llu, ACKED!\n", 388 "ack_ackno=%llu, ACKED!\n",
333 debug_prefix, 1, 389 debug_prefix, 1,
334 (unsigned long long)av->dccpav_ack_seqno, 390 (unsigned long long)avr->dccpavr_ack_seqno,
335 (unsigned long long)av->dccpav_ack_ackno); 391 (unsigned long long)avr->dccpavr_ack_ackno);
336 dccp_ackvec_throw_away_ack_record(av); 392 dccp_ackvec_throw_record(av, avr);
337 av->dccpav_ack_seqno = DCCP_MAX_SEQNO + 1; 393 break;
394 }
338 } 395 }
339} 396}
340 397
@@ -344,28 +401,20 @@ static void dccp_ackvec_check_rcv_ackvector(struct dccp_ackvec *av,
344 const unsigned char *vector) 401 const unsigned char *vector)
345{ 402{
346 unsigned char i; 403 unsigned char i;
404 struct dccp_ackvec_record *avr;
347 405
348 /* Check if we actually sent an ACK vector */ 406 /* Check if we actually sent an ACK vector */
349 if (av->dccpav_ack_seqno == DCCP_MAX_SEQNO + 1) 407 if (list_empty(&av->dccpav_records))
350 return;
351 /*
352 * We're in the receiver half connection, so if the received an ACK
353 * vector ackno (e.g. 50) before dccpav_ack_seqno (e.g. 52), we're
354 * not interested.
355 *
356 * Extra explanation with example:
357 *
358 * if we received an ACK vector with ackno 50, it can only be acking
359 * 50, 49, 48, etc, not 52 (the seqno for the ACK vector we sent).
360 */
361 /* dccp_pr_debug("is %llu < %llu? ", ackno, av->dccpav_ack_seqno); */
362 if (before48(ackno, av->dccpav_ack_seqno)) {
363 /* dccp_pr_debug_cat("yes\n"); */
364 return; 408 return;
365 }
366 /* dccp_pr_debug_cat("no\n"); */
367 409
368 i = len; 410 i = len;
411 /*
412 * XXX
413 * I think it might be more efficient to work backwards. See comment on
414 * rcv_ackno. -sorbo.
415 */
416 avr = list_entry(av->dccpav_records.next, struct dccp_ackvec_record,
417 dccpavr_node);
369 while (i--) { 418 while (i--) {
370 const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK; 419 const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK;
371 u64 ackno_end_rl; 420 u64 ackno_end_rl;
@@ -373,14 +422,20 @@ static void dccp_ackvec_check_rcv_ackvector(struct dccp_ackvec *av,
373 dccp_set_seqno(&ackno_end_rl, ackno - rl); 422 dccp_set_seqno(&ackno_end_rl, ackno - rl);
374 423
375 /* 424 /*
376 * dccp_pr_debug("is %llu <= %llu <= %llu? ", ackno_end_rl, 425 * If our AVR sequence number is greater than the ack, go
377 * av->dccpav_ack_seqno, ackno); 426 * forward in the AVR list until it is not so.
378 */ 427 */
379 if (between48(av->dccpav_ack_seqno, ackno_end_rl, ackno)) { 428 list_for_each_entry_from(avr, &av->dccpav_records,
429 dccpavr_node) {
430 if (!after48(avr->dccpavr_ack_seqno, ackno))
431 goto found;
432 }
433 /* End of the dccpav_records list, not found, exit */
434 break;
435found:
436 if (between48(avr->dccpavr_ack_seqno, ackno_end_rl, ackno)) {
380 const u8 state = (*vector & 437 const u8 state = (*vector &
381 DCCP_ACKVEC_STATE_MASK) >> 6; 438 DCCP_ACKVEC_STATE_MASK) >> 6;
382 /* dccp_pr_debug_cat("yes\n"); */
383
384 if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED) { 439 if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED) {
385#ifdef CONFIG_IP_DCCP_DEBUG 440#ifdef CONFIG_IP_DCCP_DEBUG
386 struct dccp_sock *dp = dccp_sk(sk); 441 struct dccp_sock *dp = dccp_sk(sk);
@@ -393,19 +448,16 @@ static void dccp_ackvec_check_rcv_ackvector(struct dccp_ackvec *av,
393 "ACKED!\n", 448 "ACKED!\n",
394 debug_prefix, len, 449 debug_prefix, len,
395 (unsigned long long) 450 (unsigned long long)
396 av->dccpav_ack_seqno, 451 avr->dccpavr_ack_seqno,
397 (unsigned long long) 452 (unsigned long long)
398 av->dccpav_ack_ackno); 453 avr->dccpavr_ack_ackno);
399 dccp_ackvec_throw_away_ack_record(av); 454 dccp_ackvec_throw_record(av, avr);
400 } 455 }
401 /* 456 /*
402 * If dccpav_ack_seqno was not received, no problem 457 * If it wasn't received, continue scanning... we might
403 * we'll send another ACK vector. 458 * find another one.
404 */ 459 */
405 av->dccpav_ack_seqno = DCCP_MAX_SEQNO + 1;
406 break;
407 } 460 }
408 /* dccp_pr_debug_cat("no\n"); */
409 461
410 dccp_set_seqno(&ackno, ackno_end_rl - 1); 462 dccp_set_seqno(&ackno, ackno_end_rl - 1);
411 ++vector; 463 ++vector;
@@ -424,3 +476,43 @@ int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
424 len, value); 476 len, value);
425 return 0; 477 return 0;
426} 478}
479
480static char dccp_ackvec_slab_msg[] __initdata =
481 KERN_CRIT "DCCP: Unable to create ack vectors slab caches\n";
482
483int __init dccp_ackvec_init(void)
484{
485 dccp_ackvec_slab = kmem_cache_create("dccp_ackvec",
486 sizeof(struct dccp_ackvec), 0,
487 SLAB_HWCACHE_ALIGN, NULL, NULL);
488 if (dccp_ackvec_slab == NULL)
489 goto out_err;
490
491 dccp_ackvec_record_slab =
492 kmem_cache_create("dccp_ackvec_record",
493 sizeof(struct dccp_ackvec_record),
494 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
495 if (dccp_ackvec_record_slab == NULL)
496 goto out_destroy_slab;
497
498 return 0;
499
500out_destroy_slab:
501 kmem_cache_destroy(dccp_ackvec_slab);
502 dccp_ackvec_slab = NULL;
503out_err:
504 printk(dccp_ackvec_slab_msg);
505 return -ENOBUFS;
506}
507
508void dccp_ackvec_exit(void)
509{
510 if (dccp_ackvec_slab != NULL) {
511 kmem_cache_destroy(dccp_ackvec_slab);
512 dccp_ackvec_slab = NULL;
513 }
514 if (dccp_ackvec_record_slab != NULL) {
515 kmem_cache_destroy(dccp_ackvec_record_slab);
516 dccp_ackvec_record_slab = NULL;
517 }
518}
diff --git a/net/dccp/ackvec.h b/net/dccp/ackvec.h
index f7dfb5f67b87..ec7a89bb7b39 100644
--- a/net/dccp/ackvec.h
+++ b/net/dccp/ackvec.h
@@ -13,6 +13,7 @@
13 13
14#include <linux/config.h> 14#include <linux/config.h>
15#include <linux/compiler.h> 15#include <linux/compiler.h>
16#include <linux/list.h>
16#include <linux/time.h> 17#include <linux/time.h>
17#include <linux/types.h> 18#include <linux/types.h>
18 19
@@ -42,39 +43,57 @@
42 * Ack Vectors it has recently sent. For each packet sent carrying an 43 * Ack Vectors it has recently sent. For each packet sent carrying an
43 * Ack Vector, it remembers four variables: 44 * Ack Vector, it remembers four variables:
44 * 45 *
45 * @dccpav_ack_seqno - the Sequence Number used for the packet
46 * (HC-Receiver seqno)
47 * @dccpav_ack_ptr - the value of buf_head at the time of acknowledgement. 46 * @dccpav_ack_ptr - the value of buf_head at the time of acknowledgement.
48 * @dccpav_ack_ackno - the Acknowledgement Number used for the packet 47 * @dccpav_records - list of dccp_ackvec_record
49 * (HC-Sender seqno)
50 * @dccpav_ack_nonce - the one-bit sum of the ECN Nonces for all State 0. 48 * @dccpav_ack_nonce - the one-bit sum of the ECN Nonces for all State 0.
51 * 49 *
52 * @dccpav_buf_len - circular buffer length
53 * @dccpav_time - the time in usecs 50 * @dccpav_time - the time in usecs
54 * @dccpav_buf - circular buffer of acknowledgeable packets 51 * @dccpav_buf - circular buffer of acknowledgeable packets
55 */ 52 */
56struct dccp_ackvec { 53struct dccp_ackvec {
57 u64 dccpav_buf_ackno; 54 u64 dccpav_buf_ackno;
58 u64 dccpav_ack_seqno; 55 struct list_head dccpav_records;
59 u64 dccpav_ack_ackno;
60 struct timeval dccpav_time; 56 struct timeval dccpav_time;
61 u8 dccpav_buf_head; 57 u8 dccpav_buf_head;
62 u8 dccpav_buf_tail; 58 u8 dccpav_buf_tail;
63 u8 dccpav_ack_ptr; 59 u8 dccpav_ack_ptr;
64 u8 dccpav_sent_len; 60 u8 dccpav_sent_len;
65 u8 dccpav_vec_len; 61 u8 dccpav_vec_len;
66 u8 dccpav_buf_len;
67 u8 dccpav_buf_nonce; 62 u8 dccpav_buf_nonce;
68 u8 dccpav_ack_nonce; 63 u8 dccpav_ack_nonce;
69 u8 dccpav_buf[0]; 64 u8 dccpav_buf[DCCP_MAX_ACKVEC_LEN];
65};
66
67/** struct dccp_ackvec_record - ack vector record
68 *
69 * ACK vector record as defined in Appendix A of spec.
70 *
71 * The list is sorted by dccpavr_ack_seqno
72 *
73 * @dccpavr_node - node in dccpav_records
74 * @dccpavr_ack_seqno - sequence number of the packet this record was sent on
75 * @dccpavr_ack_ackno - sequence number being acknowledged
76 * @dccpavr_ack_ptr - pointer into dccpav_buf where this record starts
77 * @dccpavr_ack_nonce - dccpav_ack_nonce at the time this record was sent
78 * @dccpavr_sent_len - lenght of the record in dccpav_buf
79 */
80struct dccp_ackvec_record {
81 struct list_head dccpavr_node;
82 u64 dccpavr_ack_seqno;
83 u64 dccpavr_ack_ackno;
84 u8 dccpavr_ack_ptr;
85 u8 dccpavr_ack_nonce;
86 u8 dccpavr_sent_len;
70}; 87};
71 88
72struct sock; 89struct sock;
73struct sk_buff; 90struct sk_buff;
74 91
75#ifdef CONFIG_IP_DCCP_ACKVEC 92#ifdef CONFIG_IP_DCCP_ACKVEC
76extern struct dccp_ackvec *dccp_ackvec_alloc(unsigned int len, 93extern int dccp_ackvec_init(void);
77 const gfp_t priority); 94extern void dccp_ackvec_exit(void);
95
96extern struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority);
78extern void dccp_ackvec_free(struct dccp_ackvec *av); 97extern void dccp_ackvec_free(struct dccp_ackvec *av);
79 98
80extern int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk, 99extern int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
@@ -92,8 +111,16 @@ static inline int dccp_ackvec_pending(const struct dccp_ackvec *av)
92 return av->dccpav_sent_len != av->dccpav_vec_len; 111 return av->dccpav_sent_len != av->dccpav_vec_len;
93} 112}
94#else /* CONFIG_IP_DCCP_ACKVEC */ 113#else /* CONFIG_IP_DCCP_ACKVEC */
95static inline struct dccp_ackvec *dccp_ackvec_alloc(unsigned int len, 114static inline int dccp_ackvec_init(void)
96 const gfp_t priority) 115{
116 return 0;
117}
118
119static inline void dccp_ackvec_exit(void)
120{
121}
122
123static inline struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority)
97{ 124{
98 return NULL; 125 return NULL;
99} 126}
diff --git a/net/dccp/ccid.c b/net/dccp/ccid.c
index 9d8fc0e289ea..ff05e59043cd 100644
--- a/net/dccp/ccid.c
+++ b/net/dccp/ccid.c
@@ -13,7 +13,7 @@
13 13
14#include "ccid.h" 14#include "ccid.h"
15 15
16static struct ccid *ccids[CCID_MAX]; 16static struct ccid_operations *ccids[CCID_MAX];
17#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT) 17#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT)
18static atomic_t ccids_lockct = ATOMIC_INIT(0); 18static atomic_t ccids_lockct = ATOMIC_INIT(0);
19static DEFINE_SPINLOCK(ccids_lock); 19static DEFINE_SPINLOCK(ccids_lock);
@@ -55,85 +55,202 @@ static inline void ccids_read_unlock(void)
55#define ccids_read_unlock() do { } while(0) 55#define ccids_read_unlock() do { } while(0)
56#endif 56#endif
57 57
58int ccid_register(struct ccid *ccid) 58static kmem_cache_t *ccid_kmem_cache_create(int obj_size, const char *fmt,...)
59{ 59{
60 int err; 60 kmem_cache_t *slab;
61 char slab_name_fmt[32], *slab_name;
62 va_list args;
61 63
62 if (ccid->ccid_init == NULL) 64 va_start(args, fmt);
63 return -1; 65 vsnprintf(slab_name_fmt, sizeof(slab_name_fmt), fmt, args);
66 va_end(args);
67
68 slab_name = kstrdup(slab_name_fmt, GFP_KERNEL);
69 if (slab_name == NULL)
70 return NULL;
71 slab = kmem_cache_create(slab_name, sizeof(struct ccid) + obj_size, 0,
72 SLAB_HWCACHE_ALIGN, NULL, NULL);
73 if (slab == NULL)
74 kfree(slab_name);
75 return slab;
76}
77
78static void ccid_kmem_cache_destroy(kmem_cache_t *slab)
79{
80 if (slab != NULL) {
81 const char *name = kmem_cache_name(slab);
82
83 kmem_cache_destroy(slab);
84 kfree(name);
85 }
86}
87
88int ccid_register(struct ccid_operations *ccid_ops)
89{
90 int err = -ENOBUFS;
91
92 ccid_ops->ccid_hc_rx_slab =
93 ccid_kmem_cache_create(ccid_ops->ccid_hc_rx_obj_size,
94 "%s_hc_rx_sock",
95 ccid_ops->ccid_name);
96 if (ccid_ops->ccid_hc_rx_slab == NULL)
97 goto out;
98
99 ccid_ops->ccid_hc_tx_slab =
100 ccid_kmem_cache_create(ccid_ops->ccid_hc_tx_obj_size,
101 "%s_hc_tx_sock",
102 ccid_ops->ccid_name);
103 if (ccid_ops->ccid_hc_tx_slab == NULL)
104 goto out_free_rx_slab;
64 105
65 ccids_write_lock(); 106 ccids_write_lock();
66 err = -EEXIST; 107 err = -EEXIST;
67 if (ccids[ccid->ccid_id] == NULL) { 108 if (ccids[ccid_ops->ccid_id] == NULL) {
68 ccids[ccid->ccid_id] = ccid; 109 ccids[ccid_ops->ccid_id] = ccid_ops;
69 err = 0; 110 err = 0;
70 } 111 }
71 ccids_write_unlock(); 112 ccids_write_unlock();
72 if (err == 0) 113 if (err != 0)
73 pr_info("CCID: Registered CCID %d (%s)\n", 114 goto out_free_tx_slab;
74 ccid->ccid_id, ccid->ccid_name); 115
116 pr_info("CCID: Registered CCID %d (%s)\n",
117 ccid_ops->ccid_id, ccid_ops->ccid_name);
118out:
75 return err; 119 return err;
120out_free_tx_slab:
121 ccid_kmem_cache_destroy(ccid_ops->ccid_hc_tx_slab);
122 ccid_ops->ccid_hc_tx_slab = NULL;
123 goto out;
124out_free_rx_slab:
125 ccid_kmem_cache_destroy(ccid_ops->ccid_hc_rx_slab);
126 ccid_ops->ccid_hc_rx_slab = NULL;
127 goto out;
76} 128}
77 129
78EXPORT_SYMBOL_GPL(ccid_register); 130EXPORT_SYMBOL_GPL(ccid_register);
79 131
80int ccid_unregister(struct ccid *ccid) 132int ccid_unregister(struct ccid_operations *ccid_ops)
81{ 133{
82 ccids_write_lock(); 134 ccids_write_lock();
83 ccids[ccid->ccid_id] = NULL; 135 ccids[ccid_ops->ccid_id] = NULL;
84 ccids_write_unlock(); 136 ccids_write_unlock();
137
138 ccid_kmem_cache_destroy(ccid_ops->ccid_hc_tx_slab);
139 ccid_ops->ccid_hc_tx_slab = NULL;
140 ccid_kmem_cache_destroy(ccid_ops->ccid_hc_rx_slab);
141 ccid_ops->ccid_hc_rx_slab = NULL;
142
85 pr_info("CCID: Unregistered CCID %d (%s)\n", 143 pr_info("CCID: Unregistered CCID %d (%s)\n",
86 ccid->ccid_id, ccid->ccid_name); 144 ccid_ops->ccid_id, ccid_ops->ccid_name);
87 return 0; 145 return 0;
88} 146}
89 147
90EXPORT_SYMBOL_GPL(ccid_unregister); 148EXPORT_SYMBOL_GPL(ccid_unregister);
91 149
92struct ccid *ccid_init(unsigned char id, struct sock *sk) 150struct ccid *ccid_new(unsigned char id, struct sock *sk, int rx, gfp_t gfp)
93{ 151{
94 struct ccid *ccid; 152 struct ccid_operations *ccid_ops;
153 struct ccid *ccid = NULL;
95 154
155 ccids_read_lock();
96#ifdef CONFIG_KMOD 156#ifdef CONFIG_KMOD
97 if (ccids[id] == NULL) 157 if (ccids[id] == NULL) {
158 /* We only try to load if in process context */
159 ccids_read_unlock();
160 if (gfp & GFP_ATOMIC)
161 goto out;
98 request_module("net-dccp-ccid-%d", id); 162 request_module("net-dccp-ccid-%d", id);
163 ccids_read_lock();
164 }
99#endif 165#endif
100 ccids_read_lock(); 166 ccid_ops = ccids[id];
167 if (ccid_ops == NULL)
168 goto out_unlock;
101 169
102 ccid = ccids[id]; 170 if (!try_module_get(ccid_ops->ccid_owner))
103 if (ccid == NULL) 171 goto out_unlock;
104 goto out;
105 172
106 if (!try_module_get(ccid->ccid_owner)) 173 ccids_read_unlock();
107 goto out_err;
108 174
109 if (ccid->ccid_init(sk) != 0) 175 ccid = kmem_cache_alloc(rx ? ccid_ops->ccid_hc_rx_slab :
176 ccid_ops->ccid_hc_tx_slab, gfp);
177 if (ccid == NULL)
110 goto out_module_put; 178 goto out_module_put;
179 ccid->ccid_ops = ccid_ops;
180 if (rx) {
181 memset(ccid + 1, 0, ccid_ops->ccid_hc_rx_obj_size);
182 if (ccid->ccid_ops->ccid_hc_rx_init != NULL &&
183 ccid->ccid_ops->ccid_hc_rx_init(ccid, sk) != 0)
184 goto out_free_ccid;
185 } else {
186 memset(ccid + 1, 0, ccid_ops->ccid_hc_tx_obj_size);
187 if (ccid->ccid_ops->ccid_hc_tx_init != NULL &&
188 ccid->ccid_ops->ccid_hc_tx_init(ccid, sk) != 0)
189 goto out_free_ccid;
190 }
111out: 191out:
112 ccids_read_unlock();
113 return ccid; 192 return ccid;
114out_module_put: 193out_unlock:
115 module_put(ccid->ccid_owner); 194 ccids_read_unlock();
116out_err: 195 goto out;
196out_free_ccid:
197 kmem_cache_free(rx ? ccid_ops->ccid_hc_rx_slab :
198 ccid_ops->ccid_hc_tx_slab, ccid);
117 ccid = NULL; 199 ccid = NULL;
200out_module_put:
201 module_put(ccid_ops->ccid_owner);
118 goto out; 202 goto out;
119} 203}
120 204
121EXPORT_SYMBOL_GPL(ccid_init); 205EXPORT_SYMBOL_GPL(ccid_new);
206
207struct ccid *ccid_hc_rx_new(unsigned char id, struct sock *sk, gfp_t gfp)
208{
209 return ccid_new(id, sk, 1, gfp);
210}
211
212EXPORT_SYMBOL_GPL(ccid_hc_rx_new);
213
214struct ccid *ccid_hc_tx_new(unsigned char id,struct sock *sk, gfp_t gfp)
215{
216 return ccid_new(id, sk, 0, gfp);
217}
218
219EXPORT_SYMBOL_GPL(ccid_hc_tx_new);
122 220
123void ccid_exit(struct ccid *ccid, struct sock *sk) 221static void ccid_delete(struct ccid *ccid, struct sock *sk, int rx)
124{ 222{
223 struct ccid_operations *ccid_ops;
224
125 if (ccid == NULL) 225 if (ccid == NULL)
126 return; 226 return;
127 227
228 ccid_ops = ccid->ccid_ops;
229 if (rx) {
230 if (ccid_ops->ccid_hc_rx_exit != NULL)
231 ccid_ops->ccid_hc_rx_exit(sk);
232 kmem_cache_free(ccid_ops->ccid_hc_rx_slab, ccid);
233 } else {
234 if (ccid_ops->ccid_hc_tx_exit != NULL)
235 ccid_ops->ccid_hc_tx_exit(sk);
236 kmem_cache_free(ccid_ops->ccid_hc_tx_slab, ccid);
237 }
128 ccids_read_lock(); 238 ccids_read_lock();
239 if (ccids[ccid_ops->ccid_id] != NULL)
240 module_put(ccid_ops->ccid_owner);
241 ccids_read_unlock();
242}
129 243
130 if (ccids[ccid->ccid_id] != NULL) { 244void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk)
131 if (ccid->ccid_exit != NULL) 245{
132 ccid->ccid_exit(sk); 246 ccid_delete(ccid, sk, 1);
133 module_put(ccid->ccid_owner); 247}
134 }
135 248
136 ccids_read_unlock(); 249EXPORT_SYMBOL_GPL(ccid_hc_rx_delete);
250
251void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk)
252{
253 ccid_delete(ccid, sk, 0);
137} 254}
138 255
139EXPORT_SYMBOL_GPL(ccid_exit); 256EXPORT_SYMBOL_GPL(ccid_hc_tx_delete);
diff --git a/net/dccp/ccid.h b/net/dccp/ccid.h
index de681c6ad081..f7eb6c613414 100644
--- a/net/dccp/ccid.h
+++ b/net/dccp/ccid.h
@@ -23,14 +23,16 @@
23 23
24struct tcp_info; 24struct tcp_info;
25 25
26struct ccid { 26struct ccid_operations {
27 unsigned char ccid_id; 27 unsigned char ccid_id;
28 const char *ccid_name; 28 const char *ccid_name;
29 struct module *ccid_owner; 29 struct module *ccid_owner;
30 int (*ccid_init)(struct sock *sk); 30 kmem_cache_t *ccid_hc_rx_slab;
31 void (*ccid_exit)(struct sock *sk); 31 __u32 ccid_hc_rx_obj_size;
32 int (*ccid_hc_rx_init)(struct sock *sk); 32 kmem_cache_t *ccid_hc_tx_slab;
33 int (*ccid_hc_tx_init)(struct sock *sk); 33 __u32 ccid_hc_tx_obj_size;
34 int (*ccid_hc_rx_init)(struct ccid *ccid, struct sock *sk);
35 int (*ccid_hc_tx_init)(struct ccid *ccid, struct sock *sk);
34 void (*ccid_hc_rx_exit)(struct sock *sk); 36 void (*ccid_hc_rx_exit)(struct sock *sk);
35 void (*ccid_hc_tx_exit)(struct sock *sk); 37 void (*ccid_hc_tx_exit)(struct sock *sk);
36 void (*ccid_hc_rx_packet_recv)(struct sock *sk, 38 void (*ccid_hc_rx_packet_recv)(struct sock *sk,
@@ -39,9 +41,9 @@ struct ccid {
39 unsigned char option, 41 unsigned char option,
40 unsigned char len, u16 idx, 42 unsigned char len, u16 idx,
41 unsigned char* value); 43 unsigned char* value);
42 void (*ccid_hc_rx_insert_options)(struct sock *sk, 44 int (*ccid_hc_rx_insert_options)(struct sock *sk,
43 struct sk_buff *skb); 45 struct sk_buff *skb);
44 void (*ccid_hc_tx_insert_options)(struct sock *sk, 46 int (*ccid_hc_tx_insert_options)(struct sock *sk,
45 struct sk_buff *skb); 47 struct sk_buff *skb);
46 void (*ccid_hc_tx_packet_recv)(struct sock *sk, 48 void (*ccid_hc_tx_packet_recv)(struct sock *sk,
47 struct sk_buff *skb); 49 struct sk_buff *skb);
@@ -67,75 +69,58 @@ struct ccid {
67 int __user *optlen); 69 int __user *optlen);
68}; 70};
69 71
70extern int ccid_register(struct ccid *ccid); 72extern int ccid_register(struct ccid_operations *ccid_ops);
71extern int ccid_unregister(struct ccid *ccid); 73extern int ccid_unregister(struct ccid_operations *ccid_ops);
72 74
73extern struct ccid *ccid_init(unsigned char id, struct sock *sk); 75struct ccid {
74extern void ccid_exit(struct ccid *ccid, struct sock *sk); 76 struct ccid_operations *ccid_ops;
77 char ccid_priv[0];
78};
75 79
76static inline void __ccid_get(struct ccid *ccid) 80static inline void *ccid_priv(const struct ccid *ccid)
77{ 81{
78 __module_get(ccid->ccid_owner); 82 return (void *)ccid->ccid_priv;
79} 83}
80 84
85extern struct ccid *ccid_new(unsigned char id, struct sock *sk, int rx,
86 gfp_t gfp);
87
88extern struct ccid *ccid_hc_rx_new(unsigned char id, struct sock *sk,
89 gfp_t gfp);
90extern struct ccid *ccid_hc_tx_new(unsigned char id, struct sock *sk,
91 gfp_t gfp);
92
93extern void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk);
94extern void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk);
95
81static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk, 96static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
82 struct sk_buff *skb, int len) 97 struct sk_buff *skb, int len)
83{ 98{
84 int rc = 0; 99 int rc = 0;
85 if (ccid->ccid_hc_tx_send_packet != NULL) 100 if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
86 rc = ccid->ccid_hc_tx_send_packet(sk, skb, len); 101 rc = ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb, len);
87 return rc; 102 return rc;
88} 103}
89 104
90static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk, 105static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk,
91 int more, int len) 106 int more, int len)
92{ 107{
93 if (ccid->ccid_hc_tx_packet_sent != NULL) 108 if (ccid->ccid_ops->ccid_hc_tx_packet_sent != NULL)
94 ccid->ccid_hc_tx_packet_sent(sk, more, len); 109 ccid->ccid_ops->ccid_hc_tx_packet_sent(sk, more, len);
95}
96
97static inline int ccid_hc_rx_init(struct ccid *ccid, struct sock *sk)
98{
99 int rc = 0;
100 if (ccid->ccid_hc_rx_init != NULL)
101 rc = ccid->ccid_hc_rx_init(sk);
102 return rc;
103}
104
105static inline int ccid_hc_tx_init(struct ccid *ccid, struct sock *sk)
106{
107 int rc = 0;
108 if (ccid->ccid_hc_tx_init != NULL)
109 rc = ccid->ccid_hc_tx_init(sk);
110 return rc;
111}
112
113static inline void ccid_hc_rx_exit(struct ccid *ccid, struct sock *sk)
114{
115 if (ccid != NULL && ccid->ccid_hc_rx_exit != NULL &&
116 dccp_sk(sk)->dccps_hc_rx_ccid_private != NULL)
117 ccid->ccid_hc_rx_exit(sk);
118}
119
120static inline void ccid_hc_tx_exit(struct ccid *ccid, struct sock *sk)
121{
122 if (ccid != NULL && ccid->ccid_hc_tx_exit != NULL &&
123 dccp_sk(sk)->dccps_hc_tx_ccid_private != NULL)
124 ccid->ccid_hc_tx_exit(sk);
125} 110}
126 111
127static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk, 112static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk,
128 struct sk_buff *skb) 113 struct sk_buff *skb)
129{ 114{
130 if (ccid->ccid_hc_rx_packet_recv != NULL) 115 if (ccid->ccid_ops->ccid_hc_rx_packet_recv != NULL)
131 ccid->ccid_hc_rx_packet_recv(sk, skb); 116 ccid->ccid_ops->ccid_hc_rx_packet_recv(sk, skb);
132} 117}
133 118
134static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk, 119static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk,
135 struct sk_buff *skb) 120 struct sk_buff *skb)
136{ 121{
137 if (ccid->ccid_hc_tx_packet_recv != NULL) 122 if (ccid->ccid_ops->ccid_hc_tx_packet_recv != NULL)
138 ccid->ccid_hc_tx_packet_recv(sk, skb); 123 ccid->ccid_ops->ccid_hc_tx_packet_recv(sk, skb);
139} 124}
140 125
141static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk, 126static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk,
@@ -144,8 +129,8 @@ static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk,
144 unsigned char* value) 129 unsigned char* value)
145{ 130{
146 int rc = 0; 131 int rc = 0;
147 if (ccid->ccid_hc_tx_parse_options != NULL) 132 if (ccid->ccid_ops->ccid_hc_tx_parse_options != NULL)
148 rc = ccid->ccid_hc_tx_parse_options(sk, option, len, idx, 133 rc = ccid->ccid_ops->ccid_hc_tx_parse_options(sk, option, len, idx,
149 value); 134 value);
150 return rc; 135 return rc;
151} 136}
@@ -156,37 +141,39 @@ static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk,
156 unsigned char* value) 141 unsigned char* value)
157{ 142{
158 int rc = 0; 143 int rc = 0;
159 if (ccid->ccid_hc_rx_parse_options != NULL) 144 if (ccid->ccid_ops->ccid_hc_rx_parse_options != NULL)
160 rc = ccid->ccid_hc_rx_parse_options(sk, option, len, idx, value); 145 rc = ccid->ccid_ops->ccid_hc_rx_parse_options(sk, option, len, idx, value);
161 return rc; 146 return rc;
162} 147}
163 148
164static inline void ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk, 149static inline int ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk,
165 struct sk_buff *skb) 150 struct sk_buff *skb)
166{ 151{
167 if (ccid->ccid_hc_tx_insert_options != NULL) 152 if (ccid->ccid_ops->ccid_hc_tx_insert_options != NULL)
168 ccid->ccid_hc_tx_insert_options(sk, skb); 153 return ccid->ccid_ops->ccid_hc_tx_insert_options(sk, skb);
154 return 0;
169} 155}
170 156
171static inline void ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk, 157static inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk,
172 struct sk_buff *skb) 158 struct sk_buff *skb)
173{ 159{
174 if (ccid->ccid_hc_rx_insert_options != NULL) 160 if (ccid->ccid_ops->ccid_hc_rx_insert_options != NULL)
175 ccid->ccid_hc_rx_insert_options(sk, skb); 161 return ccid->ccid_ops->ccid_hc_rx_insert_options(sk, skb);
162 return 0;
176} 163}
177 164
178static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk, 165static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk,
179 struct tcp_info *info) 166 struct tcp_info *info)
180{ 167{
181 if (ccid->ccid_hc_rx_get_info != NULL) 168 if (ccid->ccid_ops->ccid_hc_rx_get_info != NULL)
182 ccid->ccid_hc_rx_get_info(sk, info); 169 ccid->ccid_ops->ccid_hc_rx_get_info(sk, info);
183} 170}
184 171
185static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk, 172static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk,
186 struct tcp_info *info) 173 struct tcp_info *info)
187{ 174{
188 if (ccid->ccid_hc_tx_get_info != NULL) 175 if (ccid->ccid_ops->ccid_hc_tx_get_info != NULL)
189 ccid->ccid_hc_tx_get_info(sk, info); 176 ccid->ccid_ops->ccid_hc_tx_get_info(sk, info);
190} 177}
191 178
192static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk, 179static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
@@ -194,8 +181,8 @@ static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
194 u32 __user *optval, int __user *optlen) 181 u32 __user *optval, int __user *optlen)
195{ 182{
196 int rc = -ENOPROTOOPT; 183 int rc = -ENOPROTOOPT;
197 if (ccid->ccid_hc_rx_getsockopt != NULL) 184 if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
198 rc = ccid->ccid_hc_rx_getsockopt(sk, optname, len, 185 rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len,
199 optval, optlen); 186 optval, optlen);
200 return rc; 187 return rc;
201} 188}
@@ -205,8 +192,8 @@ static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
205 u32 __user *optval, int __user *optlen) 192 u32 __user *optval, int __user *optlen)
206{ 193{
207 int rc = -ENOPROTOOPT; 194 int rc = -ENOPROTOOPT;
208 if (ccid->ccid_hc_tx_getsockopt != NULL) 195 if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
209 rc = ccid->ccid_hc_tx_getsockopt(sk, optname, len, 196 rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len,
210 optval, optlen); 197 optval, optlen);
211 return rc; 198 return rc;
212} 199}
diff --git a/net/dccp/ccids/Kconfig b/net/dccp/ccids/Kconfig
index 7684d83946a4..ca00191628f7 100644
--- a/net/dccp/ccids/Kconfig
+++ b/net/dccp/ccids/Kconfig
@@ -1,9 +1,39 @@
1menu "DCCP CCIDs Configuration (EXPERIMENTAL)" 1menu "DCCP CCIDs Configuration (EXPERIMENTAL)"
2 depends on IP_DCCP && EXPERIMENTAL 2 depends on IP_DCCP && EXPERIMENTAL
3 3
4config IP_DCCP_CCID2
5 tristate "CCID2 (TCP-Like) (EXPERIMENTAL)"
6 depends on IP_DCCP
7 def_tristate IP_DCCP
8 select IP_DCCP_ACKVEC
9 ---help---
10 CCID 2, TCP-like Congestion Control, denotes Additive Increase,
11 Multiplicative Decrease (AIMD) congestion control with behavior
12 modelled directly on TCP, including congestion window, slow start,
13 timeouts, and so forth [RFC 2581]. CCID 2 achieves maximum
14 bandwidth over the long term, consistent with the use of end-to-end
15 congestion control, but halves its congestion window in response to
16 each congestion event. This leads to the abrupt rate changes
17 typical of TCP. Applications should use CCID 2 if they prefer
18 maximum bandwidth utilization to steadiness of rate. This is often
19 the case for applications that are not playing their data directly
20 to the user. For example, a hypothetical application that
21 transferred files over DCCP, using application-level retransmissions
22 for lost packets, would prefer CCID 2 to CCID 3. On-line games may
23 also prefer CCID 2.
24
25 CCID 2 is further described in:
26 http://www.icir.org/kohler/dccp/draft-ietf-dccp-ccid2-10.txt
27
28 This text was extracted from:
29 http://www.icir.org/kohler/dccp/draft-ietf-dccp-spec-13.txt
30
31 If in doubt, say M.
32
4config IP_DCCP_CCID3 33config IP_DCCP_CCID3
5 tristate "CCID3 (TFRC) (EXPERIMENTAL)" 34 tristate "CCID3 (TCP-Friendly) (EXPERIMENTAL)"
6 depends on IP_DCCP 35 depends on IP_DCCP
36 def_tristate IP_DCCP
7 ---help--- 37 ---help---
8 CCID 3 denotes TCP-Friendly Rate Control (TFRC), an equation-based 38 CCID 3 denotes TCP-Friendly Rate Control (TFRC), an equation-based
9 rate-controlled congestion control mechanism. TFRC is designed to 39 rate-controlled congestion control mechanism. TFRC is designed to
@@ -15,10 +45,15 @@ config IP_DCCP_CCID3
15 suitable than CCID 2 for applications such streaming media where a 45 suitable than CCID 2 for applications such streaming media where a
16 relatively smooth sending rate is of importance. 46 relatively smooth sending rate is of importance.
17 47
18 CCID 3 is further described in [CCID 3 PROFILE]. The TFRC 48 CCID 3 is further described in:
19 congestion control algorithms were initially described in RFC 3448. 49
50 http://www.icir.org/kohler/dccp/draft-ietf-dccp-ccid3-11.txt.
51
52 The TFRC congestion control algorithms were initially described in
53 RFC 3448.
20 54
21 This text was extracted from draft-ietf-dccp-spec-11.txt. 55 This text was extracted from:
56 http://www.icir.org/kohler/dccp/draft-ietf-dccp-spec-13.txt
22 57
23 If in doubt, say M. 58 If in doubt, say M.
24 59
diff --git a/net/dccp/ccids/Makefile b/net/dccp/ccids/Makefile
index 956f79f50743..438f20bccff7 100644
--- a/net/dccp/ccids/Makefile
+++ b/net/dccp/ccids/Makefile
@@ -2,4 +2,8 @@ obj-$(CONFIG_IP_DCCP_CCID3) += dccp_ccid3.o
2 2
3dccp_ccid3-y := ccid3.o 3dccp_ccid3-y := ccid3.o
4 4
5obj-$(CONFIG_IP_DCCP_CCID2) += dccp_ccid2.o
6
7dccp_ccid2-y := ccid2.o
8
5obj-y += lib/ 9obj-y += lib/
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c
new file mode 100644
index 000000000000..d4f9e2d33453
--- /dev/null
+++ b/net/dccp/ccids/ccid2.c
@@ -0,0 +1,779 @@
1/*
2 * net/dccp/ccids/ccid2.c
3 *
4 * Copyright (c) 2005, 2006 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
5 *
6 * Changes to meet Linux coding standards, and DCCP infrastructure fixes.
7 *
8 * Copyright (c) 2006 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25/*
26 * This implementation should follow: draft-ietf-dccp-ccid2-10.txt
27 *
28 * BUGS:
29 * - sequence number wrapping
30 * - jiffies wrapping
31 */
32
33#include <linux/config.h>
34#include "../ccid.h"
35#include "../dccp.h"
36#include "ccid2.h"
37
38static int ccid2_debug;
39
40#undef CCID2_DEBUG
41#ifdef CCID2_DEBUG
42#define ccid2_pr_debug(format, a...) \
43 do { if (ccid2_debug) \
44 printk(KERN_DEBUG "%s: " format, __FUNCTION__, ##a); \
45 } while (0)
46#else
47#define ccid2_pr_debug(format, a...)
48#endif
49
50static const int ccid2_seq_len = 128;
51
52#ifdef CCID2_DEBUG
53static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock *hctx)
54{
55 int len = 0;
56 int pipe = 0;
57 struct ccid2_seq *seqp = hctx->ccid2hctx_seqh;
58
59 /* there is data in the chain */
60 if (seqp != hctx->ccid2hctx_seqt) {
61 seqp = seqp->ccid2s_prev;
62 len++;
63 if (!seqp->ccid2s_acked)
64 pipe++;
65
66 while (seqp != hctx->ccid2hctx_seqt) {
67 struct ccid2_seq *prev = seqp->ccid2s_prev;
68
69 len++;
70 if (!prev->ccid2s_acked)
71 pipe++;
72
73 /* packets are sent sequentially */
74 BUG_ON(seqp->ccid2s_seq <= prev->ccid2s_seq);
75 BUG_ON(seqp->ccid2s_sent < prev->ccid2s_sent);
76 BUG_ON(len > ccid2_seq_len);
77
78 seqp = prev;
79 }
80 }
81
82 BUG_ON(pipe != hctx->ccid2hctx_pipe);
83 ccid2_pr_debug("len of chain=%d\n", len);
84
85 do {
86 seqp = seqp->ccid2s_prev;
87 len++;
88 BUG_ON(len > ccid2_seq_len);
89 } while (seqp != hctx->ccid2hctx_seqh);
90
91 BUG_ON(len != ccid2_seq_len);
92 ccid2_pr_debug("total len=%d\n", len);
93}
94#else
95#define ccid2_hc_tx_check_sanity(hctx) do {} while (0)
96#endif
97
98static int ccid2_hc_tx_send_packet(struct sock *sk,
99 struct sk_buff *skb, int len)
100{
101 struct ccid2_hc_tx_sock *hctx;
102
103 switch (DCCP_SKB_CB(skb)->dccpd_type) {
104 case 0: /* XXX data packets from userland come through like this */
105 case DCCP_PKT_DATA:
106 case DCCP_PKT_DATAACK:
107 break;
108 /* No congestion control on other packets */
109 default:
110 return 0;
111 }
112
113 hctx = ccid2_hc_tx_sk(sk);
114
115 ccid2_pr_debug("pipe=%d cwnd=%d\n", hctx->ccid2hctx_pipe,
116 hctx->ccid2hctx_cwnd);
117
118 if (hctx->ccid2hctx_pipe < hctx->ccid2hctx_cwnd) {
119 /* OK we can send... make sure previous packet was sent off */
120 if (!hctx->ccid2hctx_sendwait) {
121 hctx->ccid2hctx_sendwait = 1;
122 return 0;
123 }
124 }
125
126 return 100; /* XXX */
127}
128
129static void ccid2_change_l_ack_ratio(struct sock *sk, int val)
130{
131 struct dccp_sock *dp = dccp_sk(sk);
132 /*
133 * XXX I don't really agree with val != 2. If cwnd is 1, ack ratio
134 * should be 1... it shouldn't be allowed to become 2.
135 * -sorbo.
136 */
137 if (val != 2) {
138 const struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
139 int max = hctx->ccid2hctx_cwnd / 2;
140
141 /* round up */
142 if (hctx->ccid2hctx_cwnd & 1)
143 max++;
144
145 if (val > max)
146 val = max;
147 }
148
149 ccid2_pr_debug("changing local ack ratio to %d\n", val);
150 WARN_ON(val <= 0);
151 dp->dccps_l_ack_ratio = val;
152}
153
154static void ccid2_change_cwnd(struct sock *sk, int val)
155{
156 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
157
158 if (val == 0)
159 val = 1;
160
161 /* XXX do we need to change ack ratio? */
162 ccid2_pr_debug("change cwnd to %d\n", val);
163
164 BUG_ON(val < 1);
165 hctx->ccid2hctx_cwnd = val;
166}
167
168static void ccid2_start_rto_timer(struct sock *sk);
169
170static void ccid2_hc_tx_rto_expire(unsigned long data)
171{
172 struct sock *sk = (struct sock *)data;
173 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
174 long s;
175
176 bh_lock_sock(sk);
177 if (sock_owned_by_user(sk)) {
178 sk_reset_timer(sk, &hctx->ccid2hctx_rtotimer,
179 jiffies + HZ / 5);
180 goto out;
181 }
182
183 ccid2_pr_debug("RTO_EXPIRE\n");
184
185 ccid2_hc_tx_check_sanity(hctx);
186
187 /* back-off timer */
188 hctx->ccid2hctx_rto <<= 1;
189
190 s = hctx->ccid2hctx_rto / HZ;
191 if (s > 60)
192 hctx->ccid2hctx_rto = 60 * HZ;
193
194 ccid2_start_rto_timer(sk);
195
196 /* adjust pipe, cwnd etc */
197 hctx->ccid2hctx_pipe = 0;
198 hctx->ccid2hctx_ssthresh = hctx->ccid2hctx_cwnd >> 1;
199 if (hctx->ccid2hctx_ssthresh < 2)
200 hctx->ccid2hctx_ssthresh = 2;
201 ccid2_change_cwnd(sk, 1);
202
203 /* clear state about stuff we sent */
204 hctx->ccid2hctx_seqt = hctx->ccid2hctx_seqh;
205 hctx->ccid2hctx_ssacks = 0;
206 hctx->ccid2hctx_acks = 0;
207 hctx->ccid2hctx_sent = 0;
208
209 /* clear ack ratio state. */
210 hctx->ccid2hctx_arsent = 0;
211 hctx->ccid2hctx_ackloss = 0;
212 hctx->ccid2hctx_rpseq = 0;
213 hctx->ccid2hctx_rpdupack = -1;
214 ccid2_change_l_ack_ratio(sk, 1);
215 ccid2_hc_tx_check_sanity(hctx);
216out:
217 bh_unlock_sock(sk);
218 sock_put(sk);
219}
220
221static void ccid2_start_rto_timer(struct sock *sk)
222{
223 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
224
225 ccid2_pr_debug("setting RTO timeout=%ld\n", hctx->ccid2hctx_rto);
226
227 BUG_ON(timer_pending(&hctx->ccid2hctx_rtotimer));
228 sk_reset_timer(sk, &hctx->ccid2hctx_rtotimer,
229 jiffies + hctx->ccid2hctx_rto);
230}
231
232static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, int len)
233{
234 struct dccp_sock *dp = dccp_sk(sk);
235 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
236 u64 seq;
237
238 ccid2_hc_tx_check_sanity(hctx);
239
240 BUG_ON(!hctx->ccid2hctx_sendwait);
241 hctx->ccid2hctx_sendwait = 0;
242 hctx->ccid2hctx_pipe++;
243 BUG_ON(hctx->ccid2hctx_pipe < 0);
244
245 /* There is an issue. What if another packet is sent between
246 * packet_send() and packet_sent(). Then the sequence number would be
247 * wrong.
248 * -sorbo.
249 */
250 seq = dp->dccps_gss;
251
252 hctx->ccid2hctx_seqh->ccid2s_seq = seq;
253 hctx->ccid2hctx_seqh->ccid2s_acked = 0;
254 hctx->ccid2hctx_seqh->ccid2s_sent = jiffies;
255 hctx->ccid2hctx_seqh = hctx->ccid2hctx_seqh->ccid2s_next;
256
257 ccid2_pr_debug("cwnd=%d pipe=%d\n", hctx->ccid2hctx_cwnd,
258 hctx->ccid2hctx_pipe);
259
260 if (hctx->ccid2hctx_seqh == hctx->ccid2hctx_seqt) {
261 /* XXX allocate more space */
262 WARN_ON(1);
263 }
264
265 hctx->ccid2hctx_sent++;
266
267 /* Ack Ratio. Need to maintain a concept of how many windows we sent */
268 hctx->ccid2hctx_arsent++;
269 /* We had an ack loss in this window... */
270 if (hctx->ccid2hctx_ackloss) {
271 if (hctx->ccid2hctx_arsent >= hctx->ccid2hctx_cwnd) {
272 hctx->ccid2hctx_arsent = 0;
273 hctx->ccid2hctx_ackloss = 0;
274 }
275 } else {
276 /* No acks lost up to now... */
277 /* decrease ack ratio if enough packets were sent */
278 if (dp->dccps_l_ack_ratio > 1) {
279 /* XXX don't calculate denominator each time */
280 int denom = dp->dccps_l_ack_ratio * dp->dccps_l_ack_ratio -
281 dp->dccps_l_ack_ratio;
282
283 denom = hctx->ccid2hctx_cwnd * hctx->ccid2hctx_cwnd / denom;
284
285 if (hctx->ccid2hctx_arsent >= denom) {
286 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio - 1);
287 hctx->ccid2hctx_arsent = 0;
288 }
289 } else {
290 /* we can't increase ack ratio further [1] */
291 hctx->ccid2hctx_arsent = 0; /* or maybe set it to cwnd*/
292 }
293 }
294
295 /* setup RTO timer */
296 if (!timer_pending(&hctx->ccid2hctx_rtotimer))
297 ccid2_start_rto_timer(sk);
298
299#ifdef CCID2_DEBUG
300 ccid2_pr_debug("pipe=%d\n", hctx->ccid2hctx_pipe);
301 ccid2_pr_debug("Sent: seq=%llu\n", seq);
302 do {
303 struct ccid2_seq *seqp = hctx->ccid2hctx_seqt;
304
305 while (seqp != hctx->ccid2hctx_seqh) {
306 ccid2_pr_debug("out seq=%llu acked=%d time=%lu\n",
307 seqp->ccid2s_seq, seqp->ccid2s_acked,
308 seqp->ccid2s_sent);
309 seqp = seqp->ccid2s_next;
310 }
311 } while (0);
312 ccid2_pr_debug("=========\n");
313 ccid2_hc_tx_check_sanity(hctx);
314#endif
315}
316
317/* XXX Lame code duplication!
318 * returns -1 if none was found.
319 * else returns the next offset to use in the function call.
320 */
321static int ccid2_ackvector(struct sock *sk, struct sk_buff *skb, int offset,
322 unsigned char **vec, unsigned char *veclen)
323{
324 const struct dccp_hdr *dh = dccp_hdr(skb);
325 unsigned char *options = (unsigned char *)dh + dccp_hdr_len(skb);
326 unsigned char *opt_ptr;
327 const unsigned char *opt_end = (unsigned char *)dh +
328 (dh->dccph_doff * 4);
329 unsigned char opt, len;
330 unsigned char *value;
331
332 BUG_ON(offset < 0);
333 options += offset;
334 opt_ptr = options;
335 if (opt_ptr >= opt_end)
336 return -1;
337
338 while (opt_ptr != opt_end) {
339 opt = *opt_ptr++;
340 len = 0;
341 value = NULL;
342
343 /* Check if this isn't a single byte option */
344 if (opt > DCCPO_MAX_RESERVED) {
345 if (opt_ptr == opt_end)
346 goto out_invalid_option;
347
348 len = *opt_ptr++;
349 if (len < 3)
350 goto out_invalid_option;
351 /*
352 * Remove the type and len fields, leaving
353 * just the value size
354 */
355 len -= 2;
356 value = opt_ptr;
357 opt_ptr += len;
358
359 if (opt_ptr > opt_end)
360 goto out_invalid_option;
361 }
362
363 switch (opt) {
364 case DCCPO_ACK_VECTOR_0:
365 case DCCPO_ACK_VECTOR_1:
366 *vec = value;
367 *veclen = len;
368 return offset + (opt_ptr - options);
369 }
370 }
371
372 return -1;
373
374out_invalid_option:
375 BUG_ON(1); /* should never happen... options were previously parsed ! */
376 return -1;
377}
378
379static void ccid2_hc_tx_kill_rto_timer(struct sock *sk)
380{
381 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
382
383 sk_stop_timer(sk, &hctx->ccid2hctx_rtotimer);
384 ccid2_pr_debug("deleted RTO timer\n");
385}
386
387static inline void ccid2_new_ack(struct sock *sk,
388 struct ccid2_seq *seqp,
389 unsigned int *maxincr)
390{
391 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
392
393 /* slow start */
394 if (hctx->ccid2hctx_cwnd < hctx->ccid2hctx_ssthresh) {
395 hctx->ccid2hctx_acks = 0;
396
397 /* We can increase cwnd at most maxincr [ack_ratio/2] */
398 if (*maxincr) {
399 /* increase every 2 acks */
400 hctx->ccid2hctx_ssacks++;
401 if (hctx->ccid2hctx_ssacks == 2) {
402 ccid2_change_cwnd(sk, hctx->ccid2hctx_cwnd + 1);
403 hctx->ccid2hctx_ssacks = 0;
404 *maxincr = *maxincr - 1;
405 }
406 } else {
407 /* increased cwnd enough for this single ack */
408 hctx->ccid2hctx_ssacks = 0;
409 }
410 } else {
411 hctx->ccid2hctx_ssacks = 0;
412 hctx->ccid2hctx_acks++;
413
414 if (hctx->ccid2hctx_acks >= hctx->ccid2hctx_cwnd) {
415 ccid2_change_cwnd(sk, hctx->ccid2hctx_cwnd + 1);
416 hctx->ccid2hctx_acks = 0;
417 }
418 }
419
420 /* update RTO */
421 if (hctx->ccid2hctx_srtt == -1 ||
422 (jiffies - hctx->ccid2hctx_lastrtt) >= hctx->ccid2hctx_srtt) {
423 unsigned long r = jiffies - seqp->ccid2s_sent;
424 int s;
425
426 /* first measurement */
427 if (hctx->ccid2hctx_srtt == -1) {
428 ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n",
429 r, jiffies, seqp->ccid2s_seq);
430 hctx->ccid2hctx_srtt = r;
431 hctx->ccid2hctx_rttvar = r >> 1;
432 } else {
433 /* RTTVAR */
434 long tmp = hctx->ccid2hctx_srtt - r;
435 if (tmp < 0)
436 tmp *= -1;
437
438 tmp >>= 2;
439 hctx->ccid2hctx_rttvar *= 3;
440 hctx->ccid2hctx_rttvar >>= 2;
441 hctx->ccid2hctx_rttvar += tmp;
442
443 /* SRTT */
444 hctx->ccid2hctx_srtt *= 7;
445 hctx->ccid2hctx_srtt >>= 3;
446 tmp = r >> 3;
447 hctx->ccid2hctx_srtt += tmp;
448 }
449 s = hctx->ccid2hctx_rttvar << 2;
450 /* clock granularity is 1 when based on jiffies */
451 if (!s)
452 s = 1;
453 hctx->ccid2hctx_rto = hctx->ccid2hctx_srtt + s;
454
455 /* must be at least a second */
456 s = hctx->ccid2hctx_rto / HZ;
457 /* DCCP doesn't require this [but I like it cuz my code sux] */
458#if 1
459 if (s < 1)
460 hctx->ccid2hctx_rto = HZ;
461#endif
462 /* max 60 seconds */
463 if (s > 60)
464 hctx->ccid2hctx_rto = HZ * 60;
465
466 hctx->ccid2hctx_lastrtt = jiffies;
467
468 ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n",
469 hctx->ccid2hctx_srtt, hctx->ccid2hctx_rttvar,
470 hctx->ccid2hctx_rto, HZ, r);
471 hctx->ccid2hctx_sent = 0;
472 }
473
474 /* we got a new ack, so re-start RTO timer */
475 ccid2_hc_tx_kill_rto_timer(sk);
476 ccid2_start_rto_timer(sk);
477}
478
479static void ccid2_hc_tx_dec_pipe(struct sock *sk)
480{
481 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
482
483 hctx->ccid2hctx_pipe--;
484 BUG_ON(hctx->ccid2hctx_pipe < 0);
485
486 if (hctx->ccid2hctx_pipe == 0)
487 ccid2_hc_tx_kill_rto_timer(sk);
488}
489
490static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
491{
492 struct dccp_sock *dp = dccp_sk(sk);
493 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
494 u64 ackno, seqno;
495 struct ccid2_seq *seqp;
496 unsigned char *vector;
497 unsigned char veclen;
498 int offset = 0;
499 int done = 0;
500 int loss = 0;
501 unsigned int maxincr = 0;
502
503 ccid2_hc_tx_check_sanity(hctx);
504 /* check reverse path congestion */
505 seqno = DCCP_SKB_CB(skb)->dccpd_seq;
506
507 /* XXX this whole "algorithm" is broken. Need to fix it to keep track
508 * of the seqnos of the dupacks so that rpseq and rpdupack are correct
509 * -sorbo.
510 */
511 /* need to bootstrap */
512 if (hctx->ccid2hctx_rpdupack == -1) {
513 hctx->ccid2hctx_rpdupack = 0;
514 hctx->ccid2hctx_rpseq = seqno;
515 } else {
516 /* check if packet is consecutive */
517 if ((hctx->ccid2hctx_rpseq + 1) == seqno)
518 hctx->ccid2hctx_rpseq++;
519 /* it's a later packet */
520 else if (after48(seqno, hctx->ccid2hctx_rpseq)) {
521 hctx->ccid2hctx_rpdupack++;
522
523 /* check if we got enough dupacks */
524 if (hctx->ccid2hctx_rpdupack >=
525 hctx->ccid2hctx_numdupack) {
526 hctx->ccid2hctx_rpdupack = -1; /* XXX lame */
527 hctx->ccid2hctx_rpseq = 0;
528
529 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio << 1);
530 }
531 }
532 }
533
534 /* check forward path congestion */
535 /* still didn't send out new data packets */
536 if (hctx->ccid2hctx_seqh == hctx->ccid2hctx_seqt)
537 return;
538
539 switch (DCCP_SKB_CB(skb)->dccpd_type) {
540 case DCCP_PKT_ACK:
541 case DCCP_PKT_DATAACK:
542 break;
543 default:
544 return;
545 }
546
547 ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
548 seqp = hctx->ccid2hctx_seqh->ccid2s_prev;
549
550 /* If in slow-start, cwnd can increase at most Ack Ratio / 2 packets for
551 * this single ack. I round up.
552 * -sorbo.
553 */
554 maxincr = dp->dccps_l_ack_ratio >> 1;
555 maxincr++;
556
557 /* go through all ack vectors */
558 while ((offset = ccid2_ackvector(sk, skb, offset,
559 &vector, &veclen)) != -1) {
560 /* go through this ack vector */
561 while (veclen--) {
562 const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK;
563 u64 ackno_end_rl;
564
565 dccp_set_seqno(&ackno_end_rl, ackno - rl);
566 ccid2_pr_debug("ackvec start:%llu end:%llu\n", ackno,
567 ackno_end_rl);
568 /* if the seqno we are analyzing is larger than the
569 * current ackno, then move towards the tail of our
570 * seqnos.
571 */
572 while (after48(seqp->ccid2s_seq, ackno)) {
573 if (seqp == hctx->ccid2hctx_seqt) {
574 done = 1;
575 break;
576 }
577 seqp = seqp->ccid2s_prev;
578 }
579 if (done)
580 break;
581
582 /* check all seqnos in the range of the vector
583 * run length
584 */
585 while (between48(seqp->ccid2s_seq,ackno_end_rl,ackno)) {
586 const u8 state = (*vector &
587 DCCP_ACKVEC_STATE_MASK) >> 6;
588
589 /* new packet received or marked */
590 if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED &&
591 !seqp->ccid2s_acked) {
592 if (state ==
593 DCCP_ACKVEC_STATE_ECN_MARKED) {
594 loss = 1;
595 } else
596 ccid2_new_ack(sk, seqp,
597 &maxincr);
598
599 seqp->ccid2s_acked = 1;
600 ccid2_pr_debug("Got ack for %llu\n",
601 seqp->ccid2s_seq);
602 ccid2_hc_tx_dec_pipe(sk);
603 }
604 if (seqp == hctx->ccid2hctx_seqt) {
605 done = 1;
606 break;
607 }
608 seqp = seqp->ccid2s_next;
609 }
610 if (done)
611 break;
612
613
614 dccp_set_seqno(&ackno, ackno_end_rl - 1);
615 vector++;
616 }
617 if (done)
618 break;
619 }
620
621 /* The state about what is acked should be correct now
622 * Check for NUMDUPACK
623 */
624 seqp = hctx->ccid2hctx_seqh->ccid2s_prev;
625 done = 0;
626 while (1) {
627 if (seqp->ccid2s_acked) {
628 done++;
629 if (done == hctx->ccid2hctx_numdupack)
630 break;
631 }
632 if (seqp == hctx->ccid2hctx_seqt)
633 break;
634 seqp = seqp->ccid2s_prev;
635 }
636
637 /* If there are at least 3 acknowledgements, anything unacknowledged
638 * below the last sequence number is considered lost
639 */
640 if (done == hctx->ccid2hctx_numdupack) {
641 struct ccid2_seq *last_acked = seqp;
642
643 /* check for lost packets */
644 while (1) {
645 if (!seqp->ccid2s_acked) {
646 loss = 1;
647 ccid2_hc_tx_dec_pipe(sk);
648 }
649 if (seqp == hctx->ccid2hctx_seqt)
650 break;
651 seqp = seqp->ccid2s_prev;
652 }
653
654 hctx->ccid2hctx_seqt = last_acked;
655 }
656
657 /* trim acked packets in tail */
658 while (hctx->ccid2hctx_seqt != hctx->ccid2hctx_seqh) {
659 if (!hctx->ccid2hctx_seqt->ccid2s_acked)
660 break;
661
662 hctx->ccid2hctx_seqt = hctx->ccid2hctx_seqt->ccid2s_next;
663 }
664
665 if (loss) {
666 /* XXX do bit shifts guarantee a 0 as the new bit? */
667 ccid2_change_cwnd(sk, hctx->ccid2hctx_cwnd >> 1);
668 hctx->ccid2hctx_ssthresh = hctx->ccid2hctx_cwnd;
669 if (hctx->ccid2hctx_ssthresh < 2)
670 hctx->ccid2hctx_ssthresh = 2;
671 }
672
673 ccid2_hc_tx_check_sanity(hctx);
674}
675
676static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
677{
678 struct ccid2_hc_tx_sock *hctx = ccid_priv(ccid);
679 int seqcount = ccid2_seq_len;
680 int i;
681
682 /* XXX init variables with proper values */
683 hctx->ccid2hctx_cwnd = 1;
684 hctx->ccid2hctx_ssthresh = 10;
685 hctx->ccid2hctx_numdupack = 3;
686
687 /* XXX init ~ to window size... */
688 hctx->ccid2hctx_seqbuf = kmalloc(sizeof(*hctx->ccid2hctx_seqbuf) *
689 seqcount, gfp_any());
690 if (hctx->ccid2hctx_seqbuf == NULL)
691 return -ENOMEM;
692
693 for (i = 0; i < (seqcount - 1); i++) {
694 hctx->ccid2hctx_seqbuf[i].ccid2s_next =
695 &hctx->ccid2hctx_seqbuf[i + 1];
696 hctx->ccid2hctx_seqbuf[i + 1].ccid2s_prev =
697 &hctx->ccid2hctx_seqbuf[i];
698 }
699 hctx->ccid2hctx_seqbuf[seqcount - 1].ccid2s_next =
700 hctx->ccid2hctx_seqbuf;
701 hctx->ccid2hctx_seqbuf->ccid2s_prev =
702 &hctx->ccid2hctx_seqbuf[seqcount - 1];
703
704 hctx->ccid2hctx_seqh = hctx->ccid2hctx_seqbuf;
705 hctx->ccid2hctx_seqt = hctx->ccid2hctx_seqh;
706 hctx->ccid2hctx_sent = 0;
707 hctx->ccid2hctx_rto = 3 * HZ;
708 hctx->ccid2hctx_srtt = -1;
709 hctx->ccid2hctx_rttvar = -1;
710 hctx->ccid2hctx_lastrtt = 0;
711 hctx->ccid2hctx_rpdupack = -1;
712
713 hctx->ccid2hctx_rtotimer.function = &ccid2_hc_tx_rto_expire;
714 hctx->ccid2hctx_rtotimer.data = (unsigned long)sk;
715 init_timer(&hctx->ccid2hctx_rtotimer);
716
717 ccid2_hc_tx_check_sanity(hctx);
718 return 0;
719}
720
721static void ccid2_hc_tx_exit(struct sock *sk)
722{
723 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
724
725 ccid2_hc_tx_kill_rto_timer(sk);
726 kfree(hctx->ccid2hctx_seqbuf);
727 hctx->ccid2hctx_seqbuf = NULL;
728}
729
730static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
731{
732 const struct dccp_sock *dp = dccp_sk(sk);
733 struct ccid2_hc_rx_sock *hcrx = ccid2_hc_rx_sk(sk);
734
735 switch (DCCP_SKB_CB(skb)->dccpd_type) {
736 case DCCP_PKT_DATA:
737 case DCCP_PKT_DATAACK:
738 hcrx->ccid2hcrx_data++;
739 if (hcrx->ccid2hcrx_data >= dp->dccps_r_ack_ratio) {
740 dccp_send_ack(sk);
741 hcrx->ccid2hcrx_data = 0;
742 }
743 break;
744 }
745}
746
747static struct ccid_operations ccid2 = {
748 .ccid_id = 2,
749 .ccid_name = "ccid2",
750 .ccid_owner = THIS_MODULE,
751 .ccid_hc_tx_obj_size = sizeof(struct ccid2_hc_tx_sock),
752 .ccid_hc_tx_init = ccid2_hc_tx_init,
753 .ccid_hc_tx_exit = ccid2_hc_tx_exit,
754 .ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet,
755 .ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent,
756 .ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv,
757 .ccid_hc_rx_obj_size = sizeof(struct ccid2_hc_rx_sock),
758 .ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv,
759};
760
761module_param(ccid2_debug, int, 0444);
762MODULE_PARM_DESC(ccid2_debug, "Enable debug messages");
763
764static __init int ccid2_module_init(void)
765{
766 return ccid_register(&ccid2);
767}
768module_init(ccid2_module_init);
769
770static __exit void ccid2_module_exit(void)
771{
772 ccid_unregister(&ccid2);
773}
774module_exit(ccid2_module_exit);
775
776MODULE_AUTHOR("Andrea Bittau <a.bittau@cs.ucl.ac.uk>");
777MODULE_DESCRIPTION("DCCP TCP-Like (CCID2) CCID");
778MODULE_LICENSE("GPL");
779MODULE_ALIAS("net-dccp-ccid-2");
diff --git a/net/dccp/ccids/ccid2.h b/net/dccp/ccids/ccid2.h
new file mode 100644
index 000000000000..451a87464fa5
--- /dev/null
+++ b/net/dccp/ccids/ccid2.h
@@ -0,0 +1,85 @@
1/*
2 * net/dccp/ccids/ccid2.h
3 *
4 * Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20#ifndef _DCCP_CCID2_H_
21#define _DCCP_CCID2_H_
22
23#include <linux/dccp.h>
24#include <linux/timer.h>
25#include <linux/types.h>
26#include "../ccid.h"
27
28struct sock;
29
30struct ccid2_seq {
31 u64 ccid2s_seq;
32 unsigned long ccid2s_sent;
33 int ccid2s_acked;
34 struct ccid2_seq *ccid2s_prev;
35 struct ccid2_seq *ccid2s_next;
36};
37
38/** struct ccid2_hc_tx_sock - CCID2 TX half connection
39 *
40 * @ccid2hctx_ssacks - ACKs recv in slow start
41 * @ccid2hctx_acks - ACKS recv in AI phase
42 * @ccid2hctx_sent - packets sent in this window
43 * @ccid2hctx_lastrtt -time RTT was last measured
44 * @ccid2hctx_arsent - packets sent [ack ratio]
45 * @ccid2hctx_ackloss - ack was lost in this win
46 * @ccid2hctx_rpseq - last consecutive seqno
47 * @ccid2hctx_rpdupack - dupacks since rpseq
48*/
49struct ccid2_hc_tx_sock {
50 int ccid2hctx_cwnd;
51 int ccid2hctx_ssacks;
52 int ccid2hctx_acks;
53 int ccid2hctx_ssthresh;
54 int ccid2hctx_pipe;
55 int ccid2hctx_numdupack;
56 struct ccid2_seq *ccid2hctx_seqbuf;
57 struct ccid2_seq *ccid2hctx_seqh;
58 struct ccid2_seq *ccid2hctx_seqt;
59 long ccid2hctx_rto;
60 long ccid2hctx_srtt;
61 long ccid2hctx_rttvar;
62 int ccid2hctx_sent;
63 unsigned long ccid2hctx_lastrtt;
64 struct timer_list ccid2hctx_rtotimer;
65 unsigned long ccid2hctx_arsent;
66 int ccid2hctx_ackloss;
67 u64 ccid2hctx_rpseq;
68 int ccid2hctx_rpdupack;
69 int ccid2hctx_sendwait;
70};
71
72struct ccid2_hc_rx_sock {
73 int ccid2hcrx_data;
74};
75
76static inline struct ccid2_hc_tx_sock *ccid2_hc_tx_sk(const struct sock *sk)
77{
78 return ccid_priv(dccp_sk(sk)->dccps_hc_tx_ccid);
79}
80
81static inline struct ccid2_hc_rx_sock *ccid2_hc_rx_sk(const struct sock *sk)
82{
83 return ccid_priv(dccp_sk(sk)->dccps_hc_rx_ccid);
84}
85#endif /* _DCCP_CCID2_H_ */
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
index 35d1d347541c..b4a51d0355a5 100644
--- a/net/dccp/ccids/ccid3.c
+++ b/net/dccp/ccids/ccid3.c
@@ -46,7 +46,7 @@
46 * Reason for maths here is to avoid 32 bit overflow when a is big. 46 * Reason for maths here is to avoid 32 bit overflow when a is big.
47 * With this we get close to the limit. 47 * With this we get close to the limit.
48 */ 48 */
49static inline u32 usecs_div(const u32 a, const u32 b) 49static u32 usecs_div(const u32 a, const u32 b)
50{ 50{
51 const u32 div = a < (UINT_MAX / (USEC_PER_SEC / 10)) ? 10 : 51 const u32 div = a < (UINT_MAX / (USEC_PER_SEC / 10)) ? 10 :
52 a < (UINT_MAX / (USEC_PER_SEC / 50)) ? 50 : 52 a < (UINT_MAX / (USEC_PER_SEC / 50)) ? 50 :
@@ -76,15 +76,6 @@ static struct dccp_tx_hist *ccid3_tx_hist;
76static struct dccp_rx_hist *ccid3_rx_hist; 76static struct dccp_rx_hist *ccid3_rx_hist;
77static struct dccp_li_hist *ccid3_li_hist; 77static struct dccp_li_hist *ccid3_li_hist;
78 78
79static int ccid3_init(struct sock *sk)
80{
81 return 0;
82}
83
84static void ccid3_exit(struct sock *sk)
85{
86}
87
88/* TFRC sender states */ 79/* TFRC sender states */
89enum ccid3_hc_tx_states { 80enum ccid3_hc_tx_states {
90 TFRC_SSTATE_NO_SENT = 1, 81 TFRC_SSTATE_NO_SENT = 1,
@@ -107,8 +98,8 @@ static const char *ccid3_tx_state_name(enum ccid3_hc_tx_states state)
107} 98}
108#endif 99#endif
109 100
110static inline void ccid3_hc_tx_set_state(struct sock *sk, 101static void ccid3_hc_tx_set_state(struct sock *sk,
111 enum ccid3_hc_tx_states state) 102 enum ccid3_hc_tx_states state)
112{ 103{
113 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 104 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
114 enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state; 105 enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state;
@@ -316,8 +307,6 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
316 307
317 switch (hctx->ccid3hctx_state) { 308 switch (hctx->ccid3hctx_state) {
318 case TFRC_SSTATE_NO_SENT: 309 case TFRC_SSTATE_NO_SENT:
319 hctx->ccid3hctx_no_feedback_timer.function = ccid3_hc_tx_no_feedback_timer;
320 hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk;
321 sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, 310 sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
322 jiffies + usecs_to_jiffies(TFRC_INITIAL_TIMEOUT)); 311 jiffies + usecs_to_jiffies(TFRC_INITIAL_TIMEOUT));
323 hctx->ccid3hctx_last_win_count = 0; 312 hctx->ccid3hctx_last_win_count = 0;
@@ -585,16 +574,15 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
585 } 574 }
586} 575}
587 576
588static void ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb) 577static int ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb)
589{ 578{
590 const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 579 const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
591 580
592 BUG_ON(hctx == NULL); 581 BUG_ON(hctx == NULL);
593 582
594 if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)) 583 if (sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)
595 return; 584 DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count;
596 585 return 0;
597 DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count;
598} 586}
599 587
600static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option, 588static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
@@ -626,7 +614,7 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
626 __FUNCTION__, dccp_role(sk), sk); 614 __FUNCTION__, dccp_role(sk), sk);
627 rc = -EINVAL; 615 rc = -EINVAL;
628 } else { 616 } else {
629 opt_recv->ccid3or_loss_event_rate = ntohl(*(u32 *)value); 617 opt_recv->ccid3or_loss_event_rate = ntohl(*(__be32 *)value);
630 ccid3_pr_debug("%s, sk=%p, LOSS_EVENT_RATE=%u\n", 618 ccid3_pr_debug("%s, sk=%p, LOSS_EVENT_RATE=%u\n",
631 dccp_role(sk), sk, 619 dccp_role(sk), sk,
632 opt_recv->ccid3or_loss_event_rate); 620 opt_recv->ccid3or_loss_event_rate);
@@ -647,7 +635,7 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
647 __FUNCTION__, dccp_role(sk), sk); 635 __FUNCTION__, dccp_role(sk), sk);
648 rc = -EINVAL; 636 rc = -EINVAL;
649 } else { 637 } else {
650 opt_recv->ccid3or_receive_rate = ntohl(*(u32 *)value); 638 opt_recv->ccid3or_receive_rate = ntohl(*(__be32 *)value);
651 ccid3_pr_debug("%s, sk=%p, RECEIVE_RATE=%u\n", 639 ccid3_pr_debug("%s, sk=%p, RECEIVE_RATE=%u\n",
652 dccp_role(sk), sk, 640 dccp_role(sk), sk,
653 opt_recv->ccid3or_receive_rate); 641 opt_recv->ccid3or_receive_rate);
@@ -658,17 +646,10 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
658 return rc; 646 return rc;
659} 647}
660 648
661static int ccid3_hc_tx_init(struct sock *sk) 649static int ccid3_hc_tx_init(struct ccid *ccid, struct sock *sk)
662{ 650{
663 struct dccp_sock *dp = dccp_sk(sk); 651 struct dccp_sock *dp = dccp_sk(sk);
664 struct ccid3_hc_tx_sock *hctx; 652 struct ccid3_hc_tx_sock *hctx = ccid_priv(ccid);
665
666 dp->dccps_hc_tx_ccid_private = kmalloc(sizeof(*hctx), gfp_any());
667 if (dp->dccps_hc_tx_ccid_private == NULL)
668 return -ENOMEM;
669
670 hctx = ccid3_hc_tx_sk(sk);
671 memset(hctx, 0, sizeof(*hctx));
672 653
673 if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE && 654 if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE &&
674 dp->dccps_packet_size <= TFRC_MAX_PACKET_SIZE) 655 dp->dccps_packet_size <= TFRC_MAX_PACKET_SIZE)
@@ -681,6 +662,9 @@ static int ccid3_hc_tx_init(struct sock *sk)
681 hctx->ccid3hctx_t_rto = USEC_PER_SEC; 662 hctx->ccid3hctx_t_rto = USEC_PER_SEC;
682 hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT; 663 hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT;
683 INIT_LIST_HEAD(&hctx->ccid3hctx_hist); 664 INIT_LIST_HEAD(&hctx->ccid3hctx_hist);
665
666 hctx->ccid3hctx_no_feedback_timer.function = ccid3_hc_tx_no_feedback_timer;
667 hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk;
684 init_timer(&hctx->ccid3hctx_no_feedback_timer); 668 init_timer(&hctx->ccid3hctx_no_feedback_timer);
685 669
686 return 0; 670 return 0;
@@ -688,7 +672,6 @@ static int ccid3_hc_tx_init(struct sock *sk)
688 672
689static void ccid3_hc_tx_exit(struct sock *sk) 673static void ccid3_hc_tx_exit(struct sock *sk)
690{ 674{
691 struct dccp_sock *dp = dccp_sk(sk);
692 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 675 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
693 676
694 BUG_ON(hctx == NULL); 677 BUG_ON(hctx == NULL);
@@ -698,9 +681,6 @@ static void ccid3_hc_tx_exit(struct sock *sk)
698 681
699 /* Empty packet history */ 682 /* Empty packet history */
700 dccp_tx_hist_purge(ccid3_tx_hist, &hctx->ccid3hctx_hist); 683 dccp_tx_hist_purge(ccid3_tx_hist, &hctx->ccid3hctx_hist);
701
702 kfree(dp->dccps_hc_tx_ccid_private);
703 dp->dccps_hc_tx_ccid_private = NULL;
704} 684}
705 685
706/* 686/*
@@ -727,8 +707,8 @@ static const char *ccid3_rx_state_name(enum ccid3_hc_rx_states state)
727} 707}
728#endif 708#endif
729 709
730static inline void ccid3_hc_rx_set_state(struct sock *sk, 710static void ccid3_hc_rx_set_state(struct sock *sk,
731 enum ccid3_hc_rx_states state) 711 enum ccid3_hc_rx_states state)
732{ 712{
733 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 713 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
734 enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state; 714 enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state;
@@ -793,31 +773,35 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
793 dccp_send_ack(sk); 773 dccp_send_ack(sk);
794} 774}
795 775
796static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb) 776static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
797{ 777{
798 const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 778 const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
799 u32 x_recv, pinv; 779 __be32 x_recv, pinv;
800 780
801 BUG_ON(hcrx == NULL); 781 BUG_ON(hcrx == NULL);
802 782
803 if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)) 783 if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN))
804 return; 784 return 0;
805 785
806 DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_last_counter; 786 DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_last_counter;
807 787
808 if (dccp_packet_without_ack(skb)) 788 if (dccp_packet_without_ack(skb))
809 return; 789 return 0;
810 790
811 if (hcrx->ccid3hcrx_elapsed_time != 0)
812 dccp_insert_option_elapsed_time(sk, skb,
813 hcrx->ccid3hcrx_elapsed_time);
814 dccp_insert_option_timestamp(sk, skb);
815 x_recv = htonl(hcrx->ccid3hcrx_x_recv); 791 x_recv = htonl(hcrx->ccid3hcrx_x_recv);
816 pinv = htonl(hcrx->ccid3hcrx_pinv); 792 pinv = htonl(hcrx->ccid3hcrx_pinv);
817 dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE, 793
818 &pinv, sizeof(pinv)); 794 if ((hcrx->ccid3hcrx_elapsed_time != 0 &&
819 dccp_insert_option(sk, skb, TFRC_OPT_RECEIVE_RATE, 795 dccp_insert_option_elapsed_time(sk, skb,
820 &x_recv, sizeof(x_recv)); 796 hcrx->ccid3hcrx_elapsed_time)) ||
797 dccp_insert_option_timestamp(sk, skb) ||
798 dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE,
799 &pinv, sizeof(pinv)) ||
800 dccp_insert_option(sk, skb, TFRC_OPT_RECEIVE_RATE,
801 &x_recv, sizeof(x_recv)))
802 return -1;
803
804 return 0;
821} 805}
822 806
823/* calculate first loss interval 807/* calculate first loss interval
@@ -1047,20 +1031,13 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
1047 } 1031 }
1048} 1032}
1049 1033
1050static int ccid3_hc_rx_init(struct sock *sk) 1034static int ccid3_hc_rx_init(struct ccid *ccid, struct sock *sk)
1051{ 1035{
1052 struct dccp_sock *dp = dccp_sk(sk); 1036 struct dccp_sock *dp = dccp_sk(sk);
1053 struct ccid3_hc_rx_sock *hcrx; 1037 struct ccid3_hc_rx_sock *hcrx = ccid_priv(ccid);
1054 1038
1055 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 1039 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
1056 1040
1057 dp->dccps_hc_rx_ccid_private = kmalloc(sizeof(*hcrx), gfp_any());
1058 if (dp->dccps_hc_rx_ccid_private == NULL)
1059 return -ENOMEM;
1060
1061 hcrx = ccid3_hc_rx_sk(sk);
1062 memset(hcrx, 0, sizeof(*hcrx));
1063
1064 if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE && 1041 if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE &&
1065 dp->dccps_packet_size <= TFRC_MAX_PACKET_SIZE) 1042 dp->dccps_packet_size <= TFRC_MAX_PACKET_SIZE)
1066 hcrx->ccid3hcrx_s = dp->dccps_packet_size; 1043 hcrx->ccid3hcrx_s = dp->dccps_packet_size;
@@ -1079,7 +1056,6 @@ static int ccid3_hc_rx_init(struct sock *sk)
1079static void ccid3_hc_rx_exit(struct sock *sk) 1056static void ccid3_hc_rx_exit(struct sock *sk)
1080{ 1057{
1081 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 1058 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
1082 struct dccp_sock *dp = dccp_sk(sk);
1083 1059
1084 BUG_ON(hcrx == NULL); 1060 BUG_ON(hcrx == NULL);
1085 1061
@@ -1090,9 +1066,6 @@ static void ccid3_hc_rx_exit(struct sock *sk)
1090 1066
1091 /* Empty loss interval history */ 1067 /* Empty loss interval history */
1092 dccp_li_hist_purge(ccid3_li_hist, &hcrx->ccid3hcrx_li_hist); 1068 dccp_li_hist_purge(ccid3_li_hist, &hcrx->ccid3hcrx_li_hist);
1093
1094 kfree(dp->dccps_hc_rx_ccid_private);
1095 dp->dccps_hc_rx_ccid_private = NULL;
1096} 1069}
1097 1070
1098static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info) 1071static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
@@ -1178,12 +1151,11 @@ static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len,
1178 return 0; 1151 return 0;
1179} 1152}
1180 1153
1181static struct ccid ccid3 = { 1154static struct ccid_operations ccid3 = {
1182 .ccid_id = 3, 1155 .ccid_id = 3,
1183 .ccid_name = "ccid3", 1156 .ccid_name = "ccid3",
1184 .ccid_owner = THIS_MODULE, 1157 .ccid_owner = THIS_MODULE,
1185 .ccid_init = ccid3_init, 1158 .ccid_hc_tx_obj_size = sizeof(struct ccid3_hc_tx_sock),
1186 .ccid_exit = ccid3_exit,
1187 .ccid_hc_tx_init = ccid3_hc_tx_init, 1159 .ccid_hc_tx_init = ccid3_hc_tx_init,
1188 .ccid_hc_tx_exit = ccid3_hc_tx_exit, 1160 .ccid_hc_tx_exit = ccid3_hc_tx_exit,
1189 .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet, 1161 .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet,
@@ -1191,6 +1163,7 @@ static struct ccid ccid3 = {
1191 .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv, 1163 .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv,
1192 .ccid_hc_tx_insert_options = ccid3_hc_tx_insert_options, 1164 .ccid_hc_tx_insert_options = ccid3_hc_tx_insert_options,
1193 .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options, 1165 .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options,
1166 .ccid_hc_rx_obj_size = sizeof(struct ccid3_hc_rx_sock),
1194 .ccid_hc_rx_init = ccid3_hc_rx_init, 1167 .ccid_hc_rx_init = ccid3_hc_rx_init,
1195 .ccid_hc_rx_exit = ccid3_hc_rx_exit, 1168 .ccid_hc_rx_exit = ccid3_hc_rx_exit,
1196 .ccid_hc_rx_insert_options = ccid3_hc_rx_insert_options, 1169 .ccid_hc_rx_insert_options = ccid3_hc_rx_insert_options,
@@ -1241,15 +1214,6 @@ module_init(ccid3_module_init);
1241 1214
1242static __exit void ccid3_module_exit(void) 1215static __exit void ccid3_module_exit(void)
1243{ 1216{
1244#ifdef CONFIG_IP_DCCP_UNLOAD_HACK
1245 /*
1246 * Hack to use while developing, so that we get rid of the control
1247 * sock, that is what keeps a refcount on dccp.ko -acme
1248 */
1249 extern void dccp_ctl_sock_exit(void);
1250
1251 dccp_ctl_sock_exit();
1252#endif
1253 ccid_unregister(&ccid3); 1217 ccid_unregister(&ccid3);
1254 1218
1255 if (ccid3_tx_hist != NULL) { 1219 if (ccid3_tx_hist != NULL) {
diff --git a/net/dccp/ccids/ccid3.h b/net/dccp/ccids/ccid3.h
index 0bde4583d091..f18b96d4e5a2 100644
--- a/net/dccp/ccids/ccid3.h
+++ b/net/dccp/ccids/ccid3.h
@@ -41,6 +41,7 @@
41#include <linux/time.h> 41#include <linux/time.h>
42#include <linux/types.h> 42#include <linux/types.h>
43#include <linux/tfrc.h> 43#include <linux/tfrc.h>
44#include "../ccid.h"
44 45
45#define TFRC_MIN_PACKET_SIZE 16 46#define TFRC_MIN_PACKET_SIZE 16
46#define TFRC_STD_PACKET_SIZE 256 47#define TFRC_STD_PACKET_SIZE 256
@@ -135,12 +136,12 @@ struct ccid3_hc_rx_sock {
135 136
136static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk) 137static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk)
137{ 138{
138 return dccp_sk(sk)->dccps_hc_tx_ccid_private; 139 return ccid_priv(dccp_sk(sk)->dccps_hc_tx_ccid);
139} 140}
140 141
141static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk) 142static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk)
142{ 143{
143 return dccp_sk(sk)->dccps_hc_rx_ccid_private; 144 return ccid_priv(dccp_sk(sk)->dccps_hc_rx_ccid);
144} 145}
145 146
146#endif /* _DCCP_CCID3_H_ */ 147#endif /* _DCCP_CCID3_H_ */
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
index 93f26dd6e6cb..1fe509148689 100644
--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -59,8 +59,6 @@ extern void dccp_time_wait(struct sock *sk, int state, int timeo);
59 59
60#define DCCP_RTO_MAX ((unsigned)(120 * HZ)) /* FIXME: using TCP value */ 60#define DCCP_RTO_MAX ((unsigned)(120 * HZ)) /* FIXME: using TCP value */
61 61
62extern struct proto dccp_prot;
63
64/* is seq1 < seq2 ? */ 62/* is seq1 < seq2 ? */
65static inline int before48(const u64 seq1, const u64 seq2) 63static inline int before48(const u64 seq1, const u64 seq2)
66{ 64{
@@ -120,7 +118,6 @@ DECLARE_SNMP_STAT(struct dccp_mib, dccp_statistics);
120 118
121extern int dccp_retransmit_skb(struct sock *sk, struct sk_buff *skb); 119extern int dccp_retransmit_skb(struct sock *sk, struct sk_buff *skb);
122 120
123extern int dccp_send_response(struct sock *sk);
124extern void dccp_send_ack(struct sock *sk); 121extern void dccp_send_ack(struct sock *sk);
125extern void dccp_send_delayed_ack(struct sock *sk); 122extern void dccp_send_delayed_ack(struct sock *sk);
126extern void dccp_send_sync(struct sock *sk, const u64 seq, 123extern void dccp_send_sync(struct sock *sk, const u64 seq,
@@ -140,53 +137,8 @@ extern unsigned int dccp_sync_mss(struct sock *sk, u32 pmtu);
140extern const char *dccp_packet_name(const int type); 137extern const char *dccp_packet_name(const int type);
141extern const char *dccp_state_name(const int state); 138extern const char *dccp_state_name(const int state);
142 139
143static inline void dccp_set_state(struct sock *sk, const int state) 140extern void dccp_set_state(struct sock *sk, const int state);
144{ 141extern void dccp_done(struct sock *sk);
145 const int oldstate = sk->sk_state;
146
147 dccp_pr_debug("%s(%p) %-10.10s -> %s\n",
148 dccp_role(sk), sk,
149 dccp_state_name(oldstate), dccp_state_name(state));
150 WARN_ON(state == oldstate);
151
152 switch (state) {
153 case DCCP_OPEN:
154 if (oldstate != DCCP_OPEN)
155 DCCP_INC_STATS(DCCP_MIB_CURRESTAB);
156 break;
157
158 case DCCP_CLOSED:
159 if (oldstate == DCCP_CLOSING || oldstate == DCCP_OPEN)
160 DCCP_INC_STATS(DCCP_MIB_ESTABRESETS);
161
162 sk->sk_prot->unhash(sk);
163 if (inet_csk(sk)->icsk_bind_hash != NULL &&
164 !(sk->sk_userlocks & SOCK_BINDPORT_LOCK))
165 inet_put_port(&dccp_hashinfo, sk);
166 /* fall through */
167 default:
168 if (oldstate == DCCP_OPEN)
169 DCCP_DEC_STATS(DCCP_MIB_CURRESTAB);
170 }
171
172 /* Change state AFTER socket is unhashed to avoid closed
173 * socket sitting in hash tables.
174 */
175 sk->sk_state = state;
176}
177
178static inline void dccp_done(struct sock *sk)
179{
180 dccp_set_state(sk, DCCP_CLOSED);
181 dccp_clear_xmit_timers(sk);
182
183 sk->sk_shutdown = SHUTDOWN_MASK;
184
185 if (!sock_flag(sk, SOCK_DEAD))
186 sk->sk_state_change(sk);
187 else
188 inet_csk_destroy_sock(sk);
189}
190 142
191static inline void dccp_openreq_init(struct request_sock *req, 143static inline void dccp_openreq_init(struct request_sock *req,
192 struct dccp_sock *dp, 144 struct dccp_sock *dp,
@@ -209,10 +161,6 @@ extern struct sock *dccp_create_openreq_child(struct sock *sk,
209 161
210extern int dccp_v4_do_rcv(struct sock *sk, struct sk_buff *skb); 162extern int dccp_v4_do_rcv(struct sock *sk, struct sk_buff *skb);
211 163
212extern void dccp_v4_err(struct sk_buff *skb, u32);
213
214extern int dccp_v4_rcv(struct sk_buff *skb);
215
216extern struct sock *dccp_v4_request_recv_sock(struct sock *sk, 164extern struct sock *dccp_v4_request_recv_sock(struct sock *sk,
217 struct sk_buff *skb, 165 struct sk_buff *skb,
218 struct request_sock *req, 166 struct request_sock *req,
@@ -228,24 +176,30 @@ extern int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
228extern int dccp_rcv_established(struct sock *sk, struct sk_buff *skb, 176extern int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
229 const struct dccp_hdr *dh, const unsigned len); 177 const struct dccp_hdr *dh, const unsigned len);
230 178
231extern int dccp_v4_init_sock(struct sock *sk); 179extern int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized);
232extern int dccp_v4_destroy_sock(struct sock *sk); 180extern int dccp_destroy_sock(struct sock *sk);
233 181
234extern void dccp_close(struct sock *sk, long timeout); 182extern void dccp_close(struct sock *sk, long timeout);
235extern struct sk_buff *dccp_make_response(struct sock *sk, 183extern struct sk_buff *dccp_make_response(struct sock *sk,
236 struct dst_entry *dst, 184 struct dst_entry *dst,
237 struct request_sock *req); 185 struct request_sock *req);
238extern struct sk_buff *dccp_make_reset(struct sock *sk,
239 struct dst_entry *dst,
240 enum dccp_reset_codes code);
241 186
242extern int dccp_connect(struct sock *sk); 187extern int dccp_connect(struct sock *sk);
243extern int dccp_disconnect(struct sock *sk, int flags); 188extern int dccp_disconnect(struct sock *sk, int flags);
189extern void dccp_hash(struct sock *sk);
244extern void dccp_unhash(struct sock *sk); 190extern void dccp_unhash(struct sock *sk);
245extern int dccp_getsockopt(struct sock *sk, int level, int optname, 191extern int dccp_getsockopt(struct sock *sk, int level, int optname,
246 char __user *optval, int __user *optlen); 192 char __user *optval, int __user *optlen);
247extern int dccp_setsockopt(struct sock *sk, int level, int optname, 193extern int dccp_setsockopt(struct sock *sk, int level, int optname,
248 char __user *optval, int optlen); 194 char __user *optval, int optlen);
195#ifdef CONFIG_COMPAT
196extern int compat_dccp_getsockopt(struct sock *sk,
197 int level, int optname,
198 char __user *optval, int __user *optlen);
199extern int compat_dccp_setsockopt(struct sock *sk,
200 int level, int optname,
201 char __user *optval, int optlen);
202#endif
249extern int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg); 203extern int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg);
250extern int dccp_sendmsg(struct kiocb *iocb, struct sock *sk, 204extern int dccp_sendmsg(struct kiocb *iocb, struct sock *sk,
251 struct msghdr *msg, size_t size); 205 struct msghdr *msg, size_t size);
@@ -262,15 +216,14 @@ extern int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr,
262 int addr_len); 216 int addr_len);
263 217
264extern int dccp_v4_checksum(const struct sk_buff *skb, 218extern int dccp_v4_checksum(const struct sk_buff *skb,
265 const u32 saddr, const u32 daddr); 219 const __be32 saddr, const __be32 daddr);
266 220
267extern int dccp_v4_send_reset(struct sock *sk, 221extern int dccp_send_reset(struct sock *sk, enum dccp_reset_codes code);
268 enum dccp_reset_codes code);
269extern void dccp_send_close(struct sock *sk, const int active); 222extern void dccp_send_close(struct sock *sk, const int active);
270extern int dccp_invalid_packet(struct sk_buff *skb); 223extern int dccp_invalid_packet(struct sk_buff *skb);
271 224
272static inline int dccp_bad_service_code(const struct sock *sk, 225static inline int dccp_bad_service_code(const struct sock *sk,
273 const __u32 service) 226 const __be32 service)
274{ 227{
275 const struct dccp_sock *dp = dccp_sk(sk); 228 const struct dccp_sock *dp = dccp_sk(sk);
276 229
@@ -334,41 +287,29 @@ static inline void dccp_hdr_set_seq(struct dccp_hdr *dh, const u64 gss)
334{ 287{
335 struct dccp_hdr_ext *dhx = (struct dccp_hdr_ext *)((void *)dh + 288 struct dccp_hdr_ext *dhx = (struct dccp_hdr_ext *)((void *)dh +
336 sizeof(*dh)); 289 sizeof(*dh));
337 290 dh->dccph_seq2 = 0;
338#if defined(__LITTLE_ENDIAN_BITFIELD) 291 dh->dccph_seq = htons((gss >> 32) & 0xfffff);
339 dh->dccph_seq = htonl((gss >> 32)) >> 8;
340#elif defined(__BIG_ENDIAN_BITFIELD)
341 dh->dccph_seq = htonl((gss >> 32));
342#else
343#error "Adjust your <asm/byteorder.h> defines"
344#endif
345 dhx->dccph_seq_low = htonl(gss & 0xffffffff); 292 dhx->dccph_seq_low = htonl(gss & 0xffffffff);
346} 293}
347 294
348static inline void dccp_hdr_set_ack(struct dccp_hdr_ack_bits *dhack, 295static inline void dccp_hdr_set_ack(struct dccp_hdr_ack_bits *dhack,
349 const u64 gsr) 296 const u64 gsr)
350{ 297{
351#if defined(__LITTLE_ENDIAN_BITFIELD) 298 dhack->dccph_reserved1 = 0;
352 dhack->dccph_ack_nr_high = htonl((gsr >> 32)) >> 8; 299 dhack->dccph_ack_nr_high = htons(gsr >> 32);
353#elif defined(__BIG_ENDIAN_BITFIELD)
354 dhack->dccph_ack_nr_high = htonl((gsr >> 32));
355#else
356#error "Adjust your <asm/byteorder.h> defines"
357#endif
358 dhack->dccph_ack_nr_low = htonl(gsr & 0xffffffff); 300 dhack->dccph_ack_nr_low = htonl(gsr & 0xffffffff);
359} 301}
360 302
361static inline void dccp_update_gsr(struct sock *sk, u64 seq) 303static inline void dccp_update_gsr(struct sock *sk, u64 seq)
362{ 304{
363 struct dccp_sock *dp = dccp_sk(sk); 305 struct dccp_sock *dp = dccp_sk(sk);
306 const struct dccp_minisock *dmsk = dccp_msk(sk);
364 307
365 dp->dccps_gsr = seq; 308 dp->dccps_gsr = seq;
366 dccp_set_seqno(&dp->dccps_swl, 309 dccp_set_seqno(&dp->dccps_swl,
367 (dp->dccps_gsr + 1 - 310 dp->dccps_gsr + 1 - (dmsk->dccpms_sequence_window / 4));
368 (dp->dccps_options.dccpo_sequence_window / 4)));
369 dccp_set_seqno(&dp->dccps_swh, 311 dccp_set_seqno(&dp->dccps_swh,
370 (dp->dccps_gsr + 312 dp->dccps_gsr + (3 * dmsk->dccpms_sequence_window) / 4);
371 (3 * dp->dccps_options.dccpo_sequence_window) / 4));
372} 313}
373 314
374static inline void dccp_update_gss(struct sock *sk, u64 seq) 315static inline void dccp_update_gss(struct sock *sk, u64 seq)
@@ -378,7 +319,7 @@ static inline void dccp_update_gss(struct sock *sk, u64 seq)
378 dp->dccps_awh = dp->dccps_gss = seq; 319 dp->dccps_awh = dp->dccps_gss = seq;
379 dccp_set_seqno(&dp->dccps_awl, 320 dccp_set_seqno(&dp->dccps_awl,
380 (dp->dccps_gss - 321 (dp->dccps_gss -
381 dp->dccps_options.dccpo_sequence_window + 1)); 322 dccp_msk(sk)->dccpms_sequence_window + 1));
382} 323}
383 324
384static inline int dccp_ack_pending(const struct sock *sk) 325static inline int dccp_ack_pending(const struct sock *sk)
@@ -386,24 +327,22 @@ static inline int dccp_ack_pending(const struct sock *sk)
386 const struct dccp_sock *dp = dccp_sk(sk); 327 const struct dccp_sock *dp = dccp_sk(sk);
387 return dp->dccps_timestamp_echo != 0 || 328 return dp->dccps_timestamp_echo != 0 ||
388#ifdef CONFIG_IP_DCCP_ACKVEC 329#ifdef CONFIG_IP_DCCP_ACKVEC
389 (dp->dccps_options.dccpo_send_ack_vector && 330 (dccp_msk(sk)->dccpms_send_ack_vector &&
390 dccp_ackvec_pending(dp->dccps_hc_rx_ackvec)) || 331 dccp_ackvec_pending(dp->dccps_hc_rx_ackvec)) ||
391#endif 332#endif
392 inet_csk_ack_scheduled(sk); 333 inet_csk_ack_scheduled(sk);
393} 334}
394 335
395extern void dccp_insert_options(struct sock *sk, struct sk_buff *skb); 336extern int dccp_insert_options(struct sock *sk, struct sk_buff *skb);
396extern void dccp_insert_option_elapsed_time(struct sock *sk, 337extern int dccp_insert_option_elapsed_time(struct sock *sk,
397 struct sk_buff *skb, 338 struct sk_buff *skb,
398 u32 elapsed_time); 339 u32 elapsed_time);
399extern void dccp_insert_option_timestamp(struct sock *sk, 340extern int dccp_insert_option_timestamp(struct sock *sk,
400 struct sk_buff *skb); 341 struct sk_buff *skb);
401extern void dccp_insert_option(struct sock *sk, struct sk_buff *skb, 342extern int dccp_insert_option(struct sock *sk, struct sk_buff *skb,
402 unsigned char option, 343 unsigned char option,
403 const void *value, unsigned char len); 344 const void *value, unsigned char len);
404 345
405extern struct socket *dccp_ctl_socket;
406
407extern void dccp_timestamp(const struct sock *sk, struct timeval *tv); 346extern void dccp_timestamp(const struct sock *sk, struct timeval *tv);
408 347
409static inline suseconds_t timeval_usecs(const struct timeval *tv) 348static inline suseconds_t timeval_usecs(const struct timeval *tv)
@@ -444,4 +383,18 @@ static inline void timeval_sub_usecs(struct timeval *tv,
444 } 383 }
445} 384}
446 385
386#ifdef CONFIG_SYSCTL
387extern int dccp_sysctl_init(void);
388extern void dccp_sysctl_exit(void);
389#else
390static inline int dccp_sysctl_init(void)
391{
392 return 0;
393}
394
395static inline void dccp_sysctl_exit(void)
396{
397}
398#endif
399
447#endif /* _DCCP_H */ 400#endif /* _DCCP_H */
diff --git a/net/dccp/diag.c b/net/dccp/diag.c
index 3f78c00e3822..0f25dc395967 100644
--- a/net/dccp/diag.c
+++ b/net/dccp/diag.c
@@ -30,7 +30,7 @@ static void dccp_get_info(struct sock *sk, struct tcp_info *info)
30 info->tcpi_backoff = icsk->icsk_backoff; 30 info->tcpi_backoff = icsk->icsk_backoff;
31 info->tcpi_pmtu = icsk->icsk_pmtu_cookie; 31 info->tcpi_pmtu = icsk->icsk_pmtu_cookie;
32 32
33 if (dp->dccps_options.dccpo_send_ack_vector) 33 if (dccp_msk(sk)->dccpms_send_ack_vector)
34 info->tcpi_options |= TCPI_OPT_SACK; 34 info->tcpi_options |= TCPI_OPT_SACK;
35 35
36 ccid_hc_rx_get_info(dp->dccps_hc_rx_ccid, sk, info); 36 ccid_hc_rx_get_info(dp->dccps_hc_rx_ccid, sk, info);
diff --git a/net/dccp/feat.c b/net/dccp/feat.c
new file mode 100644
index 000000000000..e3dd30d36c8a
--- /dev/null
+++ b/net/dccp/feat.c
@@ -0,0 +1,586 @@
1/*
2 * net/dccp/feat.c
3 *
4 * An implementation of the DCCP protocol
5 * Andrea Bittau <a.bittau@cs.ucl.ac.uk>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
13#include <linux/config.h>
14#include <linux/module.h>
15
16#include "dccp.h"
17#include "ccid.h"
18#include "feat.h"
19
20#define DCCP_FEAT_SP_NOAGREE (-123)
21
22int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature,
23 u8 *val, u8 len, gfp_t gfp)
24{
25 struct dccp_opt_pend *opt;
26
27 dccp_pr_debug("feat change type=%d feat=%d\n", type, feature);
28
29 /* XXX sanity check feat change request */
30
31 /* check if that feature is already being negotiated */
32 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
33 /* ok we found a negotiation for this option already */
34 if (opt->dccpop_feat == feature && opt->dccpop_type == type) {
35 dccp_pr_debug("Replacing old\n");
36 /* replace */
37 BUG_ON(opt->dccpop_val == NULL);
38 kfree(opt->dccpop_val);
39 opt->dccpop_val = val;
40 opt->dccpop_len = len;
41 opt->dccpop_conf = 0;
42 return 0;
43 }
44 }
45
46 /* negotiation for a new feature */
47 opt = kmalloc(sizeof(*opt), gfp);
48 if (opt == NULL)
49 return -ENOMEM;
50
51 opt->dccpop_type = type;
52 opt->dccpop_feat = feature;
53 opt->dccpop_len = len;
54 opt->dccpop_val = val;
55 opt->dccpop_conf = 0;
56 opt->dccpop_sc = NULL;
57
58 BUG_ON(opt->dccpop_val == NULL);
59
60 list_add_tail(&opt->dccpop_node, &dmsk->dccpms_pending);
61 return 0;
62}
63
64EXPORT_SYMBOL_GPL(dccp_feat_change);
65
66static int dccp_feat_update_ccid(struct sock *sk, u8 type, u8 new_ccid_nr)
67{
68 struct dccp_sock *dp = dccp_sk(sk);
69 struct dccp_minisock *dmsk = dccp_msk(sk);
70 /* figure out if we are changing our CCID or the peer's */
71 const int rx = type == DCCPO_CHANGE_R;
72 const u8 ccid_nr = rx ? dmsk->dccpms_rx_ccid : dmsk->dccpms_tx_ccid;
73 struct ccid *new_ccid;
74
75 /* Check if nothing is being changed. */
76 if (ccid_nr == new_ccid_nr)
77 return 0;
78
79 new_ccid = ccid_new(new_ccid_nr, sk, rx, GFP_ATOMIC);
80 if (new_ccid == NULL)
81 return -ENOMEM;
82
83 if (rx) {
84 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
85 dp->dccps_hc_rx_ccid = new_ccid;
86 dmsk->dccpms_rx_ccid = new_ccid_nr;
87 } else {
88 ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
89 dp->dccps_hc_tx_ccid = new_ccid;
90 dmsk->dccpms_tx_ccid = new_ccid_nr;
91 }
92
93 return 0;
94}
95
96/* XXX taking only u8 vals */
97static int dccp_feat_update(struct sock *sk, u8 type, u8 feat, u8 val)
98{
99 dccp_pr_debug("changing [%d] feat %d to %d\n", type, feat, val);
100
101 switch (feat) {
102 case DCCPF_CCID:
103 return dccp_feat_update_ccid(sk, type, val);
104 default:
105 dccp_pr_debug("IMPLEMENT changing [%d] feat %d to %d\n",
106 type, feat, val);
107 break;
108 }
109 return 0;
110}
111
112static int dccp_feat_reconcile(struct sock *sk, struct dccp_opt_pend *opt,
113 u8 *rpref, u8 rlen)
114{
115 struct dccp_sock *dp = dccp_sk(sk);
116 u8 *spref, slen, *res = NULL;
117 int i, j, rc, agree = 1;
118
119 BUG_ON(rpref == NULL);
120
121 /* check if we are the black sheep */
122 if (dp->dccps_role == DCCP_ROLE_CLIENT) {
123 spref = rpref;
124 slen = rlen;
125 rpref = opt->dccpop_val;
126 rlen = opt->dccpop_len;
127 } else {
128 spref = opt->dccpop_val;
129 slen = opt->dccpop_len;
130 }
131 /*
132 * Now we have server preference list in spref and client preference in
133 * rpref
134 */
135 BUG_ON(spref == NULL);
136 BUG_ON(rpref == NULL);
137
138 /* FIXME sanity check vals */
139
140 /* Are values in any order? XXX Lame "algorithm" here */
141 /* XXX assume values are 1 byte */
142 for (i = 0; i < slen; i++) {
143 for (j = 0; j < rlen; j++) {
144 if (spref[i] == rpref[j]) {
145 res = &spref[i];
146 break;
147 }
148 }
149 if (res)
150 break;
151 }
152
153 /* we didn't agree on anything */
154 if (res == NULL) {
155 /* confirm previous value */
156 switch (opt->dccpop_feat) {
157 case DCCPF_CCID:
158 /* XXX did i get this right? =P */
159 if (opt->dccpop_type == DCCPO_CHANGE_L)
160 res = &dccp_msk(sk)->dccpms_tx_ccid;
161 else
162 res = &dccp_msk(sk)->dccpms_rx_ccid;
163 break;
164
165 default:
166 WARN_ON(1); /* XXX implement res */
167 return -EFAULT;
168 }
169
170 dccp_pr_debug("Don't agree... reconfirming %d\n", *res);
171 agree = 0; /* this is used for mandatory options... */
172 }
173
174 /* need to put result and our preference list */
175 /* XXX assume 1 byte vals */
176 rlen = 1 + opt->dccpop_len;
177 rpref = kmalloc(rlen, GFP_ATOMIC);
178 if (rpref == NULL)
179 return -ENOMEM;
180
181 *rpref = *res;
182 memcpy(&rpref[1], opt->dccpop_val, opt->dccpop_len);
183
184 /* put it in the "confirm queue" */
185 if (opt->dccpop_sc == NULL) {
186 opt->dccpop_sc = kmalloc(sizeof(*opt->dccpop_sc), GFP_ATOMIC);
187 if (opt->dccpop_sc == NULL) {
188 kfree(rpref);
189 return -ENOMEM;
190 }
191 } else {
192 /* recycle the confirm slot */
193 BUG_ON(opt->dccpop_sc->dccpoc_val == NULL);
194 kfree(opt->dccpop_sc->dccpoc_val);
195 dccp_pr_debug("recycling confirm slot\n");
196 }
197 memset(opt->dccpop_sc, 0, sizeof(*opt->dccpop_sc));
198
199 opt->dccpop_sc->dccpoc_val = rpref;
200 opt->dccpop_sc->dccpoc_len = rlen;
201
202 /* update the option on our side [we are about to send the confirm] */
203 rc = dccp_feat_update(sk, opt->dccpop_type, opt->dccpop_feat, *res);
204 if (rc) {
205 kfree(opt->dccpop_sc->dccpoc_val);
206 kfree(opt->dccpop_sc);
207 opt->dccpop_sc = 0;
208 return rc;
209 }
210
211 dccp_pr_debug("Will confirm %d\n", *rpref);
212
213 /* say we want to change to X but we just got a confirm X, suppress our
214 * change
215 */
216 if (!opt->dccpop_conf) {
217 if (*opt->dccpop_val == *res)
218 opt->dccpop_conf = 1;
219 dccp_pr_debug("won't ask for change of same feature\n");
220 }
221
222 return agree ? 0 : DCCP_FEAT_SP_NOAGREE; /* used for mandatory opts */
223}
224
225static int dccp_feat_sp(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
226{
227 struct dccp_minisock *dmsk = dccp_msk(sk);
228 struct dccp_opt_pend *opt;
229 int rc = 1;
230 u8 t;
231
232 /*
233 * We received a CHANGE. We gotta match it against our own preference
234 * list. If we got a CHANGE_R it means it's a change for us, so we need
235 * to compare our CHANGE_L list.
236 */
237 if (type == DCCPO_CHANGE_L)
238 t = DCCPO_CHANGE_R;
239 else
240 t = DCCPO_CHANGE_L;
241
242 /* find our preference list for this feature */
243 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
244 if (opt->dccpop_type != t || opt->dccpop_feat != feature)
245 continue;
246
247 /* find the winner from the two preference lists */
248 rc = dccp_feat_reconcile(sk, opt, val, len);
249 break;
250 }
251
252 /* We didn't deal with the change. This can happen if we have no
253 * preference list for the feature. In fact, it just shouldn't
254 * happen---if we understand a feature, we should have a preference list
255 * with at least the default value.
256 */
257 BUG_ON(rc == 1);
258
259 return rc;
260}
261
262static int dccp_feat_nn(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
263{
264 struct dccp_opt_pend *opt;
265 struct dccp_minisock *dmsk = dccp_msk(sk);
266 u8 *copy;
267 int rc;
268
269 /* NN features must be change L */
270 if (type == DCCPO_CHANGE_R) {
271 dccp_pr_debug("received CHANGE_R %d for NN feat %d\n",
272 type, feature);
273 return -EFAULT;
274 }
275
276 /* XXX sanity check opt val */
277
278 /* copy option so we can confirm it */
279 opt = kzalloc(sizeof(*opt), GFP_ATOMIC);
280 if (opt == NULL)
281 return -ENOMEM;
282
283 copy = kmalloc(len, GFP_ATOMIC);
284 if (copy == NULL) {
285 kfree(opt);
286 return -ENOMEM;
287 }
288 memcpy(copy, val, len);
289
290 opt->dccpop_type = DCCPO_CONFIRM_R; /* NN can only confirm R */
291 opt->dccpop_feat = feature;
292 opt->dccpop_val = copy;
293 opt->dccpop_len = len;
294
295 /* change feature */
296 rc = dccp_feat_update(sk, type, feature, *val);
297 if (rc) {
298 kfree(opt->dccpop_val);
299 kfree(opt);
300 return rc;
301 }
302
303 dccp_pr_debug("Confirming NN feature %d (val=%d)\n", feature, *copy);
304 list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf);
305
306 return 0;
307}
308
309static void dccp_feat_empty_confirm(struct dccp_minisock *dmsk,
310 u8 type, u8 feature)
311{
312 /* XXX check if other confirms for that are queued and recycle slot */
313 struct dccp_opt_pend *opt = kzalloc(sizeof(*opt), GFP_ATOMIC);
314
315 if (opt == NULL) {
316 /* XXX what do we do? Ignoring should be fine. It's a change
317 * after all =P
318 */
319 return;
320 }
321
322 opt->dccpop_type = type == DCCPO_CHANGE_L ? DCCPO_CONFIRM_R :
323 DCCPO_CONFIRM_L;
324 opt->dccpop_feat = feature;
325 opt->dccpop_val = 0;
326 opt->dccpop_len = 0;
327
328 /* change feature */
329 dccp_pr_debug("Empty confirm feature %d type %d\n", feature, type);
330 list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf);
331}
332
333static void dccp_feat_flush_confirm(struct sock *sk)
334{
335 struct dccp_minisock *dmsk = dccp_msk(sk);
336 /* Check if there is anything to confirm in the first place */
337 int yes = !list_empty(&dmsk->dccpms_conf);
338
339 if (!yes) {
340 struct dccp_opt_pend *opt;
341
342 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
343 if (opt->dccpop_conf) {
344 yes = 1;
345 break;
346 }
347 }
348 }
349
350 if (!yes)
351 return;
352
353 /* OK there is something to confirm... */
354 /* XXX check if packet is in flight? Send delayed ack?? */
355 if (sk->sk_state == DCCP_OPEN)
356 dccp_send_ack(sk);
357}
358
359int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
360{
361 int rc;
362
363 dccp_pr_debug("got feat change type=%d feat=%d\n", type, feature);
364
365 /* figure out if it's SP or NN feature */
366 switch (feature) {
367 /* deal with SP features */
368 case DCCPF_CCID:
369 rc = dccp_feat_sp(sk, type, feature, val, len);
370 break;
371
372 /* deal with NN features */
373 case DCCPF_ACK_RATIO:
374 rc = dccp_feat_nn(sk, type, feature, val, len);
375 break;
376
377 /* XXX implement other features */
378 default:
379 rc = -EFAULT;
380 break;
381 }
382
383 /* check if there were problems changing features */
384 if (rc) {
385 /* If we don't agree on SP, we sent a confirm for old value.
386 * However we propagate rc to caller in case option was
387 * mandatory
388 */
389 if (rc != DCCP_FEAT_SP_NOAGREE)
390 dccp_feat_empty_confirm(dccp_msk(sk), type, feature);
391 }
392
393 /* generate the confirm [if required] */
394 dccp_feat_flush_confirm(sk);
395
396 return rc;
397}
398
399EXPORT_SYMBOL_GPL(dccp_feat_change_recv);
400
401int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature,
402 u8 *val, u8 len)
403{
404 u8 t;
405 struct dccp_opt_pend *opt;
406 struct dccp_minisock *dmsk = dccp_msk(sk);
407 int rc = 1;
408 int all_confirmed = 1;
409
410 dccp_pr_debug("got feat confirm type=%d feat=%d\n", type, feature);
411
412 /* XXX sanity check type & feat */
413
414 /* locate our change request */
415 t = type == DCCPO_CONFIRM_L ? DCCPO_CHANGE_R : DCCPO_CHANGE_L;
416
417 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
418 if (!opt->dccpop_conf && opt->dccpop_type == t &&
419 opt->dccpop_feat == feature) {
420 /* we found it */
421 /* XXX do sanity check */
422
423 opt->dccpop_conf = 1;
424
425 /* We got a confirmation---change the option */
426 dccp_feat_update(sk, opt->dccpop_type,
427 opt->dccpop_feat, *val);
428
429 dccp_pr_debug("feat %d type %d confirmed %d\n",
430 feature, type, *val);
431 rc = 0;
432 break;
433 }
434
435 if (!opt->dccpop_conf)
436 all_confirmed = 0;
437 }
438
439 /* fix re-transmit timer */
440 /* XXX gotta make sure that no option negotiation occurs during
441 * connection shutdown. Consider that the CLOSEREQ is sent and timer is
442 * on. if all options are confirmed it might kill timer which should
443 * remain alive until close is received.
444 */
445 if (all_confirmed) {
446 dccp_pr_debug("clear feat negotiation timer %p\n", sk);
447 inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS);
448 }
449
450 if (rc)
451 dccp_pr_debug("feat %d type %d never requested\n",
452 feature, type);
453 return 0;
454}
455
456EXPORT_SYMBOL_GPL(dccp_feat_confirm_recv);
457
458void dccp_feat_clean(struct dccp_minisock *dmsk)
459{
460 struct dccp_opt_pend *opt, *next;
461
462 list_for_each_entry_safe(opt, next, &dmsk->dccpms_pending,
463 dccpop_node) {
464 BUG_ON(opt->dccpop_val == NULL);
465 kfree(opt->dccpop_val);
466
467 if (opt->dccpop_sc != NULL) {
468 BUG_ON(opt->dccpop_sc->dccpoc_val == NULL);
469 kfree(opt->dccpop_sc->dccpoc_val);
470 kfree(opt->dccpop_sc);
471 }
472
473 kfree(opt);
474 }
475 INIT_LIST_HEAD(&dmsk->dccpms_pending);
476
477 list_for_each_entry_safe(opt, next, &dmsk->dccpms_conf, dccpop_node) {
478 BUG_ON(opt == NULL);
479 if (opt->dccpop_val != NULL)
480 kfree(opt->dccpop_val);
481 kfree(opt);
482 }
483 INIT_LIST_HEAD(&dmsk->dccpms_conf);
484}
485
486EXPORT_SYMBOL_GPL(dccp_feat_clean);
487
488/* this is to be called only when a listening sock creates its child. It is
489 * assumed by the function---the confirm is not duplicated, but rather it is
490 * "passed on".
491 */
492int dccp_feat_clone(struct sock *oldsk, struct sock *newsk)
493{
494 struct dccp_minisock *olddmsk = dccp_msk(oldsk);
495 struct dccp_minisock *newdmsk = dccp_msk(newsk);
496 struct dccp_opt_pend *opt;
497 int rc = 0;
498
499 INIT_LIST_HEAD(&newdmsk->dccpms_pending);
500 INIT_LIST_HEAD(&newdmsk->dccpms_conf);
501
502 list_for_each_entry(opt, &olddmsk->dccpms_pending, dccpop_node) {
503 struct dccp_opt_pend *newopt;
504 /* copy the value of the option */
505 u8 *val = kmalloc(opt->dccpop_len, GFP_ATOMIC);
506
507 if (val == NULL)
508 goto out_clean;
509 memcpy(val, opt->dccpop_val, opt->dccpop_len);
510
511 newopt = kmalloc(sizeof(*newopt), GFP_ATOMIC);
512 if (newopt == NULL) {
513 kfree(val);
514 goto out_clean;
515 }
516
517 /* insert the option */
518 memcpy(newopt, opt, sizeof(*newopt));
519 newopt->dccpop_val = val;
520 list_add_tail(&newopt->dccpop_node, &newdmsk->dccpms_pending);
521
522 /* XXX what happens with backlogs and multiple connections at
523 * once...
524 */
525 /* the master socket no longer needs to worry about confirms */
526 opt->dccpop_sc = 0; /* it's not a memleak---new socket has it */
527
528 /* reset state for a new socket */
529 opt->dccpop_conf = 0;
530 }
531
532 /* XXX not doing anything about the conf queue */
533
534out:
535 return rc;
536
537out_clean:
538 dccp_feat_clean(newdmsk);
539 rc = -ENOMEM;
540 goto out;
541}
542
543EXPORT_SYMBOL_GPL(dccp_feat_clone);
544
545static int __dccp_feat_init(struct dccp_minisock *dmsk, u8 type, u8 feat,
546 u8 *val, u8 len)
547{
548 int rc = -ENOMEM;
549 u8 *copy = kmalloc(len, GFP_KERNEL);
550
551 if (copy != NULL) {
552 memcpy(copy, val, len);
553 rc = dccp_feat_change(dmsk, type, feat, copy, len, GFP_KERNEL);
554 if (rc)
555 kfree(copy);
556 }
557 return rc;
558}
559
560int dccp_feat_init(struct dccp_minisock *dmsk)
561{
562 int rc;
563
564 INIT_LIST_HEAD(&dmsk->dccpms_pending);
565 INIT_LIST_HEAD(&dmsk->dccpms_conf);
566
567 /* CCID L */
568 rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_L, DCCPF_CCID,
569 &dmsk->dccpms_tx_ccid, 1);
570 if (rc)
571 goto out;
572
573 /* CCID R */
574 rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_R, DCCPF_CCID,
575 &dmsk->dccpms_rx_ccid, 1);
576 if (rc)
577 goto out;
578
579 /* Ack ratio */
580 rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_L, DCCPF_ACK_RATIO,
581 &dmsk->dccpms_ack_ratio, 1);
582out:
583 return rc;
584}
585
586EXPORT_SYMBOL_GPL(dccp_feat_init);
diff --git a/net/dccp/feat.h b/net/dccp/feat.h
new file mode 100644
index 000000000000..6048373c7186
--- /dev/null
+++ b/net/dccp/feat.h
@@ -0,0 +1,29 @@
1#ifndef _DCCP_FEAT_H
2#define _DCCP_FEAT_H
3/*
4 * net/dccp/feat.h
5 *
6 * An implementation of the DCCP protocol
7 * Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/types.h>
15
16struct sock;
17struct dccp_minisock;
18
19extern int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature,
20 u8 *val, u8 len, gfp_t gfp);
21extern int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature,
22 u8 *val, u8 len);
23extern int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature,
24 u8 *val, u8 len);
25extern void dccp_feat_clean(struct dccp_minisock *dmsk);
26extern int dccp_feat_clone(struct sock *oldsk, struct sock *newsk);
27extern int dccp_feat_init(struct dccp_minisock *dmsk);
28
29#endif /* _DCCP_FEAT_H */
diff --git a/net/dccp/input.c b/net/dccp/input.c
index b6cba72b44e8..bfc53665516b 100644
--- a/net/dccp/input.c
+++ b/net/dccp/input.c
@@ -32,7 +32,7 @@ static void dccp_fin(struct sock *sk, struct sk_buff *skb)
32 32
33static void dccp_rcv_close(struct sock *sk, struct sk_buff *skb) 33static void dccp_rcv_close(struct sock *sk, struct sk_buff *skb)
34{ 34{
35 dccp_v4_send_reset(sk, DCCP_RESET_CODE_CLOSED); 35 dccp_send_reset(sk, DCCP_RESET_CODE_CLOSED);
36 dccp_fin(sk, skb); 36 dccp_fin(sk, skb);
37 dccp_set_state(sk, DCCP_CLOSED); 37 dccp_set_state(sk, DCCP_CLOSED);
38 sk_wake_async(sk, 1, POLL_HUP); 38 sk_wake_async(sk, 1, POLL_HUP);
@@ -56,11 +56,11 @@ static void dccp_rcv_closereq(struct sock *sk, struct sk_buff *skb)
56 dccp_send_close(sk, 0); 56 dccp_send_close(sk, 0);
57} 57}
58 58
59static inline void dccp_event_ack_recv(struct sock *sk, struct sk_buff *skb) 59static void dccp_event_ack_recv(struct sock *sk, struct sk_buff *skb)
60{ 60{
61 struct dccp_sock *dp = dccp_sk(sk); 61 struct dccp_sock *dp = dccp_sk(sk);
62 62
63 if (dp->dccps_options.dccpo_send_ack_vector) 63 if (dccp_msk(sk)->dccpms_send_ack_vector)
64 dccp_ackvec_check_rcv_ackno(dp->dccps_hc_rx_ackvec, sk, 64 dccp_ackvec_check_rcv_ackno(dp->dccps_hc_rx_ackvec, sk,
65 DCCP_SKB_CB(skb)->dccpd_ack_seq); 65 DCCP_SKB_CB(skb)->dccpd_ack_seq);
66} 66}
@@ -151,9 +151,8 @@ static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb)
151 return 0; 151 return 0;
152} 152}
153 153
154static inline int __dccp_rcv_established(struct sock *sk, struct sk_buff *skb, 154static int __dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
155 const struct dccp_hdr *dh, 155 const struct dccp_hdr *dh, const unsigned len)
156 const unsigned len)
157{ 156{
158 struct dccp_sock *dp = dccp_sk(sk); 157 struct dccp_sock *dp = dccp_sk(sk);
159 158
@@ -247,7 +246,7 @@ int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
247 if (DCCP_SKB_CB(skb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ) 246 if (DCCP_SKB_CB(skb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
248 dccp_event_ack_recv(sk, skb); 247 dccp_event_ack_recv(sk, skb);
249 248
250 if (dp->dccps_options.dccpo_send_ack_vector && 249 if (dccp_msk(sk)->dccpms_send_ack_vector &&
251 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, 250 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
252 DCCP_SKB_CB(skb)->dccpd_seq, 251 DCCP_SKB_CB(skb)->dccpd_seq,
253 DCCP_ACKVEC_STATE_RECEIVED)) 252 DCCP_ACKVEC_STATE_RECEIVED))
@@ -300,7 +299,10 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk,
300 goto out_invalid_packet; 299 goto out_invalid_packet;
301 } 300 }
302 301
303 if (dp->dccps_options.dccpo_send_ack_vector && 302 if (dccp_parse_options(sk, skb))
303 goto out_invalid_packet;
304
305 if (dccp_msk(sk)->dccpms_send_ack_vector &&
304 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, 306 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
305 DCCP_SKB_CB(skb)->dccpd_seq, 307 DCCP_SKB_CB(skb)->dccpd_seq,
306 DCCP_ACKVEC_STATE_RECEIVED)) 308 DCCP_ACKVEC_STATE_RECEIVED))
@@ -321,14 +323,6 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk,
321 dccp_set_seqno(&dp->dccps_swl, 323 dccp_set_seqno(&dp->dccps_swl,
322 max48(dp->dccps_swl, dp->dccps_isr)); 324 max48(dp->dccps_swl, dp->dccps_isr));
323 325
324 if (ccid_hc_rx_init(dp->dccps_hc_rx_ccid, sk) != 0 ||
325 ccid_hc_tx_init(dp->dccps_hc_tx_ccid, sk) != 0) {
326 ccid_hc_rx_exit(dp->dccps_hc_rx_ccid, sk);
327 ccid_hc_tx_exit(dp->dccps_hc_tx_ccid, sk);
328 /* FIXME: send appropriate RESET code */
329 goto out_invalid_packet;
330 }
331
332 dccp_sync_mss(sk, icsk->icsk_pmtu_cookie); 326 dccp_sync_mss(sk, icsk->icsk_pmtu_cookie);
333 327
334 /* 328 /*
@@ -492,7 +486,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
492 if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ) 486 if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
493 dccp_event_ack_recv(sk, skb); 487 dccp_event_ack_recv(sk, skb);
494 488
495 if (dp->dccps_options.dccpo_send_ack_vector && 489 if (dccp_msk(sk)->dccpms_send_ack_vector &&
496 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, 490 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
497 DCCP_SKB_CB(skb)->dccpd_seq, 491 DCCP_SKB_CB(skb)->dccpd_seq,
498 DCCP_ACKVEC_STATE_RECEIVED)) 492 DCCP_ACKVEC_STATE_RECEIVED))
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index dc0487b5bace..29047995c695 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -18,8 +18,10 @@
18#include <linux/random.h> 18#include <linux/random.h>
19 19
20#include <net/icmp.h> 20#include <net/icmp.h>
21#include <net/inet_common.h>
21#include <net/inet_hashtables.h> 22#include <net/inet_hashtables.h>
22#include <net/inet_sock.h> 23#include <net/inet_sock.h>
24#include <net/protocol.h>
23#include <net/sock.h> 25#include <net/sock.h>
24#include <net/timewait_sock.h> 26#include <net/timewait_sock.h>
25#include <net/tcp_states.h> 27#include <net/tcp_states.h>
@@ -28,14 +30,14 @@
28#include "ackvec.h" 30#include "ackvec.h"
29#include "ccid.h" 31#include "ccid.h"
30#include "dccp.h" 32#include "dccp.h"
33#include "feat.h"
31 34
32struct inet_hashinfo __cacheline_aligned dccp_hashinfo = { 35/*
33 .lhash_lock = RW_LOCK_UNLOCKED, 36 * This is the global socket data structure used for responding to
34 .lhash_users = ATOMIC_INIT(0), 37 * the Out-of-the-blue (OOTB) packets. A control sock will be created
35 .lhash_wait = __WAIT_QUEUE_HEAD_INITIALIZER(dccp_hashinfo.lhash_wait), 38 * for this socket at the initialization time.
36}; 39 */
37 40static struct socket *dccp_v4_ctl_socket;
38EXPORT_SYMBOL_GPL(dccp_hashinfo);
39 41
40static int dccp_v4_get_port(struct sock *sk, const unsigned short snum) 42static int dccp_v4_get_port(struct sock *sk, const unsigned short snum)
41{ 43{
@@ -43,18 +45,6 @@ static int dccp_v4_get_port(struct sock *sk, const unsigned short snum)
43 inet_csk_bind_conflict); 45 inet_csk_bind_conflict);
44} 46}
45 47
46static void dccp_v4_hash(struct sock *sk)
47{
48 inet_hash(&dccp_hashinfo, sk);
49}
50
51void dccp_unhash(struct sock *sk)
52{
53 inet_unhash(&dccp_hashinfo, sk);
54}
55
56EXPORT_SYMBOL_GPL(dccp_unhash);
57
58int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) 48int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
59{ 49{
60 struct inet_sock *inet = inet_sk(sk); 50 struct inet_sock *inet = inet_sk(sk);
@@ -207,11 +197,12 @@ static inline void dccp_do_pmtu_discovery(struct sock *sk,
207 } /* else let the usual retransmit timer handle it */ 197 } /* else let the usual retransmit timer handle it */
208} 198}
209 199
210static void dccp_v4_ctl_send_ack(struct sk_buff *rxskb) 200static void dccp_v4_reqsk_send_ack(struct sk_buff *rxskb,
201 struct request_sock *req)
211{ 202{
212 int err; 203 int err;
213 struct dccp_hdr *rxdh = dccp_hdr(rxskb), *dh; 204 struct dccp_hdr *rxdh = dccp_hdr(rxskb), *dh;
214 const int dccp_hdr_ack_len = sizeof(struct dccp_hdr) + 205 const u32 dccp_hdr_ack_len = sizeof(struct dccp_hdr) +
215 sizeof(struct dccp_hdr_ext) + 206 sizeof(struct dccp_hdr_ext) +
216 sizeof(struct dccp_hdr_ack_bits); 207 sizeof(struct dccp_hdr_ack_bits);
217 struct sk_buff *skb; 208 struct sk_buff *skb;
@@ -219,12 +210,12 @@ static void dccp_v4_ctl_send_ack(struct sk_buff *rxskb)
219 if (((struct rtable *)rxskb->dst)->rt_type != RTN_LOCAL) 210 if (((struct rtable *)rxskb->dst)->rt_type != RTN_LOCAL)
220 return; 211 return;
221 212
222 skb = alloc_skb(MAX_DCCP_HEADER + 15, GFP_ATOMIC); 213 skb = alloc_skb(dccp_v4_ctl_socket->sk->sk_prot->max_header, GFP_ATOMIC);
223 if (skb == NULL) 214 if (skb == NULL)
224 return; 215 return;
225 216
226 /* Reserve space for headers. */ 217 /* Reserve space for headers. */
227 skb_reserve(skb, MAX_DCCP_HEADER); 218 skb_reserve(skb, dccp_v4_ctl_socket->sk->sk_prot->max_header);
228 219
229 skb->dst = dst_clone(rxskb->dst); 220 skb->dst = dst_clone(rxskb->dst);
230 221
@@ -243,11 +234,11 @@ static void dccp_v4_ctl_send_ack(struct sk_buff *rxskb)
243 dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), 234 dccp_hdr_set_ack(dccp_hdr_ack_bits(skb),
244 DCCP_SKB_CB(rxskb)->dccpd_seq); 235 DCCP_SKB_CB(rxskb)->dccpd_seq);
245 236
246 bh_lock_sock(dccp_ctl_socket->sk); 237 bh_lock_sock(dccp_v4_ctl_socket->sk);
247 err = ip_build_and_send_pkt(skb, dccp_ctl_socket->sk, 238 err = ip_build_and_send_pkt(skb, dccp_v4_ctl_socket->sk,
248 rxskb->nh.iph->daddr, 239 rxskb->nh.iph->daddr,
249 rxskb->nh.iph->saddr, NULL); 240 rxskb->nh.iph->saddr, NULL);
250 bh_unlock_sock(dccp_ctl_socket->sk); 241 bh_unlock_sock(dccp_v4_ctl_socket->sk);
251 242
252 if (err == NET_XMIT_CN || err == 0) { 243 if (err == NET_XMIT_CN || err == 0) {
253 DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS); 244 DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS);
@@ -255,12 +246,6 @@ static void dccp_v4_ctl_send_ack(struct sk_buff *rxskb)
255 } 246 }
256} 247}
257 248
258static void dccp_v4_reqsk_send_ack(struct sk_buff *skb,
259 struct request_sock *req)
260{
261 dccp_v4_ctl_send_ack(skb);
262}
263
264static int dccp_v4_send_response(struct sock *sk, struct request_sock *req, 249static int dccp_v4_send_response(struct sock *sk, struct request_sock *req,
265 struct dst_entry *dst) 250 struct dst_entry *dst)
266{ 251{
@@ -275,7 +260,10 @@ static int dccp_v4_send_response(struct sock *sk, struct request_sock *req,
275 skb = dccp_make_response(sk, dst, req); 260 skb = dccp_make_response(sk, dst, req);
276 if (skb != NULL) { 261 if (skb != NULL) {
277 const struct inet_request_sock *ireq = inet_rsk(req); 262 const struct inet_request_sock *ireq = inet_rsk(req);
263 struct dccp_hdr *dh = dccp_hdr(skb);
278 264
265 dh->dccph_checksum = dccp_v4_checksum(skb, ireq->loc_addr,
266 ireq->rmt_addr);
279 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); 267 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
280 err = ip_build_and_send_pkt(skb, sk, ireq->loc_addr, 268 err = ip_build_and_send_pkt(skb, sk, ireq->loc_addr,
281 ireq->rmt_addr, 269 ireq->rmt_addr,
@@ -301,7 +289,7 @@ out:
301 * check at all. A more general error queue to queue errors for later handling 289 * check at all. A more general error queue to queue errors for later handling
302 * is probably better. 290 * is probably better.
303 */ 291 */
304void dccp_v4_err(struct sk_buff *skb, u32 info) 292static void dccp_v4_err(struct sk_buff *skb, u32 info)
305{ 293{
306 const struct iphdr *iph = (struct iphdr *)skb->data; 294 const struct iphdr *iph = (struct iphdr *)skb->data;
307 const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data + 295 const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data +
@@ -456,32 +444,6 @@ void dccp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb)
456 444
457EXPORT_SYMBOL_GPL(dccp_v4_send_check); 445EXPORT_SYMBOL_GPL(dccp_v4_send_check);
458 446
459int dccp_v4_send_reset(struct sock *sk, enum dccp_reset_codes code)
460{
461 struct sk_buff *skb;
462 /*
463 * FIXME: what if rebuild_header fails?
464 * Should we be doing a rebuild_header here?
465 */
466 int err = inet_sk_rebuild_header(sk);
467
468 if (err != 0)
469 return err;
470
471 skb = dccp_make_reset(sk, sk->sk_dst_cache, code);
472 if (skb != NULL) {
473 const struct inet_sock *inet = inet_sk(sk);
474
475 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
476 err = ip_build_and_send_pkt(skb, sk,
477 inet->saddr, inet->daddr, NULL);
478 if (err == NET_XMIT_CN)
479 err = 0;
480 }
481
482 return err;
483}
484
485static inline u64 dccp_v4_init_sequence(const struct sock *sk, 447static inline u64 dccp_v4_init_sequence(const struct sock *sk,
486 const struct sk_buff *skb) 448 const struct sk_buff *skb)
487{ 449{
@@ -497,9 +459,9 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
497 struct dccp_sock dp; 459 struct dccp_sock dp;
498 struct request_sock *req; 460 struct request_sock *req;
499 struct dccp_request_sock *dreq; 461 struct dccp_request_sock *dreq;
500 const __u32 saddr = skb->nh.iph->saddr; 462 const __be32 saddr = skb->nh.iph->saddr;
501 const __u32 daddr = skb->nh.iph->daddr; 463 const __be32 daddr = skb->nh.iph->daddr;
502 const __u32 service = dccp_hdr_request(skb)->dccph_req_service; 464 const __be32 service = dccp_hdr_request(skb)->dccph_req_service;
503 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); 465 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
504 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY; 466 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY;
505 467
@@ -535,7 +497,8 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
535 if (req == NULL) 497 if (req == NULL)
536 goto drop; 498 goto drop;
537 499
538 /* FIXME: process options */ 500 if (dccp_parse_options(sk, skb))
501 goto drop;
539 502
540 dccp_openreq_init(req, &dp, skb); 503 dccp_openreq_init(req, &dp, skb);
541 504
@@ -660,8 +623,8 @@ static struct sock *dccp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
660 return sk; 623 return sk;
661} 624}
662 625
663int dccp_v4_checksum(const struct sk_buff *skb, const u32 saddr, 626int dccp_v4_checksum(const struct sk_buff *skb, const __be32 saddr,
664 const u32 daddr) 627 const __be32 daddr)
665{ 628{
666 const struct dccp_hdr* dh = dccp_hdr(skb); 629 const struct dccp_hdr* dh = dccp_hdr(skb);
667 int checksum_len; 630 int checksum_len;
@@ -680,8 +643,10 @@ int dccp_v4_checksum(const struct sk_buff *skb, const u32 saddr,
680 IPPROTO_DCCP, tmp); 643 IPPROTO_DCCP, tmp);
681} 644}
682 645
646EXPORT_SYMBOL_GPL(dccp_v4_checksum);
647
683static int dccp_v4_verify_checksum(struct sk_buff *skb, 648static int dccp_v4_verify_checksum(struct sk_buff *skb,
684 const u32 saddr, const u32 daddr) 649 const __be32 saddr, const __be32 daddr)
685{ 650{
686 struct dccp_hdr *dh = dccp_hdr(skb); 651 struct dccp_hdr *dh = dccp_hdr(skb);
687 int checksum_len; 652 int checksum_len;
@@ -741,16 +706,17 @@ static void dccp_v4_ctl_send_reset(struct sk_buff *rxskb)
741 if (((struct rtable *)rxskb->dst)->rt_type != RTN_LOCAL) 706 if (((struct rtable *)rxskb->dst)->rt_type != RTN_LOCAL)
742 return; 707 return;
743 708
744 dst = dccp_v4_route_skb(dccp_ctl_socket->sk, rxskb); 709 dst = dccp_v4_route_skb(dccp_v4_ctl_socket->sk, rxskb);
745 if (dst == NULL) 710 if (dst == NULL)
746 return; 711 return;
747 712
748 skb = alloc_skb(MAX_DCCP_HEADER + 15, GFP_ATOMIC); 713 skb = alloc_skb(dccp_v4_ctl_socket->sk->sk_prot->max_header,
714 GFP_ATOMIC);
749 if (skb == NULL) 715 if (skb == NULL)
750 goto out; 716 goto out;
751 717
752 /* Reserve space for headers. */ 718 /* Reserve space for headers. */
753 skb_reserve(skb, MAX_DCCP_HEADER); 719 skb_reserve(skb, dccp_v4_ctl_socket->sk->sk_prot->max_header);
754 skb->dst = dst_clone(dst); 720 skb->dst = dst_clone(dst);
755 721
756 skb->h.raw = skb_push(skb, dccp_hdr_reset_len); 722 skb->h.raw = skb_push(skb, dccp_hdr_reset_len);
@@ -778,11 +744,11 @@ static void dccp_v4_ctl_send_reset(struct sk_buff *rxskb)
778 dh->dccph_checksum = dccp_v4_checksum(skb, rxskb->nh.iph->saddr, 744 dh->dccph_checksum = dccp_v4_checksum(skb, rxskb->nh.iph->saddr,
779 rxskb->nh.iph->daddr); 745 rxskb->nh.iph->daddr);
780 746
781 bh_lock_sock(dccp_ctl_socket->sk); 747 bh_lock_sock(dccp_v4_ctl_socket->sk);
782 err = ip_build_and_send_pkt(skb, dccp_ctl_socket->sk, 748 err = ip_build_and_send_pkt(skb, dccp_v4_ctl_socket->sk,
783 rxskb->nh.iph->daddr, 749 rxskb->nh.iph->daddr,
784 rxskb->nh.iph->saddr, NULL); 750 rxskb->nh.iph->saddr, NULL);
785 bh_unlock_sock(dccp_ctl_socket->sk); 751 bh_unlock_sock(dccp_v4_ctl_socket->sk);
786 752
787 if (err == NET_XMIT_CN || err == 0) { 753 if (err == NET_XMIT_CN || err == 0) {
788 DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS); 754 DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS);
@@ -912,7 +878,7 @@ int dccp_invalid_packet(struct sk_buff *skb)
912EXPORT_SYMBOL_GPL(dccp_invalid_packet); 878EXPORT_SYMBOL_GPL(dccp_invalid_packet);
913 879
914/* this is called when real data arrives */ 880/* this is called when real data arrives */
915int dccp_v4_rcv(struct sk_buff *skb) 881static int dccp_v4_rcv(struct sk_buff *skb)
916{ 882{
917 const struct dccp_hdr *dh; 883 const struct dccp_hdr *dh;
918 struct sock *sk; 884 struct sock *sk;
@@ -1019,111 +985,37 @@ do_time_wait:
1019 goto no_dccp_socket; 985 goto no_dccp_socket;
1020} 986}
1021 987
1022struct inet_connection_sock_af_ops dccp_ipv4_af_ops = { 988static struct inet_connection_sock_af_ops dccp_ipv4_af_ops = {
1023 .queue_xmit = ip_queue_xmit, 989 .queue_xmit = ip_queue_xmit,
1024 .send_check = dccp_v4_send_check, 990 .send_check = dccp_v4_send_check,
1025 .rebuild_header = inet_sk_rebuild_header, 991 .rebuild_header = inet_sk_rebuild_header,
1026 .conn_request = dccp_v4_conn_request, 992 .conn_request = dccp_v4_conn_request,
1027 .syn_recv_sock = dccp_v4_request_recv_sock, 993 .syn_recv_sock = dccp_v4_request_recv_sock,
1028 .net_header_len = sizeof(struct iphdr), 994 .net_header_len = sizeof(struct iphdr),
1029 .setsockopt = ip_setsockopt, 995 .setsockopt = ip_setsockopt,
1030 .getsockopt = ip_getsockopt, 996 .getsockopt = ip_getsockopt,
1031 .addr2sockaddr = inet_csk_addr2sockaddr, 997 .addr2sockaddr = inet_csk_addr2sockaddr,
1032 .sockaddr_len = sizeof(struct sockaddr_in), 998 .sockaddr_len = sizeof(struct sockaddr_in),
999#ifdef CONFIG_COMPAT
1000 .compat_setsockopt = compat_ip_setsockopt,
1001 .compat_getsockopt = compat_ip_getsockopt,
1002#endif
1033}; 1003};
1034 1004
1035int dccp_v4_init_sock(struct sock *sk) 1005static int dccp_v4_init_sock(struct sock *sk)
1036{
1037 struct dccp_sock *dp = dccp_sk(sk);
1038 struct inet_connection_sock *icsk = inet_csk(sk);
1039 static int dccp_ctl_socket_init = 1;
1040
1041 dccp_options_init(&dp->dccps_options);
1042 do_gettimeofday(&dp->dccps_epoch);
1043
1044 if (dp->dccps_options.dccpo_send_ack_vector) {
1045 dp->dccps_hc_rx_ackvec = dccp_ackvec_alloc(DCCP_MAX_ACKVEC_LEN,
1046 GFP_KERNEL);
1047 if (dp->dccps_hc_rx_ackvec == NULL)
1048 return -ENOMEM;
1049 }
1050
1051 /*
1052 * FIXME: We're hardcoding the CCID, and doing this at this point makes
1053 * the listening (master) sock get CCID control blocks, which is not
1054 * necessary, but for now, to not mess with the test userspace apps,
1055 * lets leave it here, later the real solution is to do this in a
1056 * setsockopt(CCIDs-I-want/accept). -acme
1057 */
1058 if (likely(!dccp_ctl_socket_init)) {
1059 dp->dccps_hc_rx_ccid = ccid_init(dp->dccps_options.dccpo_rx_ccid,
1060 sk);
1061 dp->dccps_hc_tx_ccid = ccid_init(dp->dccps_options.dccpo_tx_ccid,
1062 sk);
1063 if (dp->dccps_hc_rx_ccid == NULL ||
1064 dp->dccps_hc_tx_ccid == NULL) {
1065 ccid_exit(dp->dccps_hc_rx_ccid, sk);
1066 ccid_exit(dp->dccps_hc_tx_ccid, sk);
1067 if (dp->dccps_options.dccpo_send_ack_vector) {
1068 dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
1069 dp->dccps_hc_rx_ackvec = NULL;
1070 }
1071 dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL;
1072 return -ENOMEM;
1073 }
1074 } else
1075 dccp_ctl_socket_init = 0;
1076
1077 dccp_init_xmit_timers(sk);
1078 icsk->icsk_rto = DCCP_TIMEOUT_INIT;
1079 sk->sk_state = DCCP_CLOSED;
1080 sk->sk_write_space = dccp_write_space;
1081 icsk->icsk_af_ops = &dccp_ipv4_af_ops;
1082 icsk->icsk_sync_mss = dccp_sync_mss;
1083 dp->dccps_mss_cache = 536;
1084 dp->dccps_role = DCCP_ROLE_UNDEFINED;
1085 dp->dccps_service = DCCP_SERVICE_INVALID_VALUE;
1086
1087 return 0;
1088}
1089
1090EXPORT_SYMBOL_GPL(dccp_v4_init_sock);
1091
1092int dccp_v4_destroy_sock(struct sock *sk)
1093{ 1006{
1094 struct dccp_sock *dp = dccp_sk(sk); 1007 static __u8 dccp_v4_ctl_sock_initialized;
1008 int err = dccp_init_sock(sk, dccp_v4_ctl_sock_initialized);
1095 1009
1096 /* 1010 if (err == 0) {
1097 * DCCP doesn't use sk_write_queue, just sk_send_head 1011 if (unlikely(!dccp_v4_ctl_sock_initialized))
1098 * for retransmissions 1012 dccp_v4_ctl_sock_initialized = 1;
1099 */ 1013 inet_csk(sk)->icsk_af_ops = &dccp_ipv4_af_ops;
1100 if (sk->sk_send_head != NULL) {
1101 kfree_skb(sk->sk_send_head);
1102 sk->sk_send_head = NULL;
1103 } 1014 }
1104 1015
1105 /* Clean up a referenced DCCP bind bucket. */ 1016 return err;
1106 if (inet_csk(sk)->icsk_bind_hash != NULL)
1107 inet_put_port(&dccp_hashinfo, sk);
1108
1109 kfree(dp->dccps_service_list);
1110 dp->dccps_service_list = NULL;
1111
1112 ccid_hc_rx_exit(dp->dccps_hc_rx_ccid, sk);
1113 ccid_hc_tx_exit(dp->dccps_hc_tx_ccid, sk);
1114 if (dp->dccps_options.dccpo_send_ack_vector) {
1115 dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
1116 dp->dccps_hc_rx_ackvec = NULL;
1117 }
1118 ccid_exit(dp->dccps_hc_rx_ccid, sk);
1119 ccid_exit(dp->dccps_hc_tx_ccid, sk);
1120 dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL;
1121
1122 return 0;
1123} 1017}
1124 1018
1125EXPORT_SYMBOL_GPL(dccp_v4_destroy_sock);
1126
1127static void dccp_v4_reqsk_destructor(struct request_sock *req) 1019static void dccp_v4_reqsk_destructor(struct request_sock *req)
1128{ 1020{
1129 kfree(inet_rsk(req)->opt); 1021 kfree(inet_rsk(req)->opt);
@@ -1142,7 +1034,7 @@ static struct timewait_sock_ops dccp_timewait_sock_ops = {
1142 .twsk_obj_size = sizeof(struct inet_timewait_sock), 1034 .twsk_obj_size = sizeof(struct inet_timewait_sock),
1143}; 1035};
1144 1036
1145struct proto dccp_prot = { 1037static struct proto dccp_v4_prot = {
1146 .name = "DCCP", 1038 .name = "DCCP",
1147 .owner = THIS_MODULE, 1039 .owner = THIS_MODULE,
1148 .close = dccp_close, 1040 .close = dccp_close,
@@ -1155,17 +1047,110 @@ struct proto dccp_prot = {
1155 .sendmsg = dccp_sendmsg, 1047 .sendmsg = dccp_sendmsg,
1156 .recvmsg = dccp_recvmsg, 1048 .recvmsg = dccp_recvmsg,
1157 .backlog_rcv = dccp_v4_do_rcv, 1049 .backlog_rcv = dccp_v4_do_rcv,
1158 .hash = dccp_v4_hash, 1050 .hash = dccp_hash,
1159 .unhash = dccp_unhash, 1051 .unhash = dccp_unhash,
1160 .accept = inet_csk_accept, 1052 .accept = inet_csk_accept,
1161 .get_port = dccp_v4_get_port, 1053 .get_port = dccp_v4_get_port,
1162 .shutdown = dccp_shutdown, 1054 .shutdown = dccp_shutdown,
1163 .destroy = dccp_v4_destroy_sock, 1055 .destroy = dccp_destroy_sock,
1164 .orphan_count = &dccp_orphan_count, 1056 .orphan_count = &dccp_orphan_count,
1165 .max_header = MAX_DCCP_HEADER, 1057 .max_header = MAX_DCCP_HEADER,
1166 .obj_size = sizeof(struct dccp_sock), 1058 .obj_size = sizeof(struct dccp_sock),
1167 .rsk_prot = &dccp_request_sock_ops, 1059 .rsk_prot = &dccp_request_sock_ops,
1168 .twsk_prot = &dccp_timewait_sock_ops, 1060 .twsk_prot = &dccp_timewait_sock_ops,
1061#ifdef CONFIG_COMPAT
1062 .compat_setsockopt = compat_dccp_setsockopt,
1063 .compat_getsockopt = compat_dccp_getsockopt,
1064#endif
1065};
1066
1067static struct net_protocol dccp_v4_protocol = {
1068 .handler = dccp_v4_rcv,
1069 .err_handler = dccp_v4_err,
1070 .no_policy = 1,
1071};
1072
1073static const struct proto_ops inet_dccp_ops = {
1074 .family = PF_INET,
1075 .owner = THIS_MODULE,
1076 .release = inet_release,
1077 .bind = inet_bind,
1078 .connect = inet_stream_connect,
1079 .socketpair = sock_no_socketpair,
1080 .accept = inet_accept,
1081 .getname = inet_getname,
1082 /* FIXME: work on tcp_poll to rename it to inet_csk_poll */
1083 .poll = dccp_poll,
1084 .ioctl = inet_ioctl,
1085 /* FIXME: work on inet_listen to rename it to sock_common_listen */
1086 .listen = inet_dccp_listen,
1087 .shutdown = inet_shutdown,
1088 .setsockopt = sock_common_setsockopt,
1089 .getsockopt = sock_common_getsockopt,
1090 .sendmsg = inet_sendmsg,
1091 .recvmsg = sock_common_recvmsg,
1092 .mmap = sock_no_mmap,
1093 .sendpage = sock_no_sendpage,
1094#ifdef CONFIG_COMPAT
1095 .compat_setsockopt = compat_sock_common_setsockopt,
1096 .compat_getsockopt = compat_sock_common_getsockopt,
1097#endif
1169}; 1098};
1170 1099
1171EXPORT_SYMBOL_GPL(dccp_prot); 1100static struct inet_protosw dccp_v4_protosw = {
1101 .type = SOCK_DCCP,
1102 .protocol = IPPROTO_DCCP,
1103 .prot = &dccp_v4_prot,
1104 .ops = &inet_dccp_ops,
1105 .capability = -1,
1106 .no_check = 0,
1107 .flags = INET_PROTOSW_ICSK,
1108};
1109
1110static int __init dccp_v4_init(void)
1111{
1112 int err = proto_register(&dccp_v4_prot, 1);
1113
1114 if (err != 0)
1115 goto out;
1116
1117 err = inet_add_protocol(&dccp_v4_protocol, IPPROTO_DCCP);
1118 if (err != 0)
1119 goto out_proto_unregister;
1120
1121 inet_register_protosw(&dccp_v4_protosw);
1122
1123 err = inet_csk_ctl_sock_create(&dccp_v4_ctl_socket, PF_INET,
1124 SOCK_DCCP, IPPROTO_DCCP);
1125 if (err)
1126 goto out_unregister_protosw;
1127out:
1128 return err;
1129out_unregister_protosw:
1130 inet_unregister_protosw(&dccp_v4_protosw);
1131 inet_del_protocol(&dccp_v4_protocol, IPPROTO_DCCP);
1132out_proto_unregister:
1133 proto_unregister(&dccp_v4_prot);
1134 goto out;
1135}
1136
1137static void __exit dccp_v4_exit(void)
1138{
1139 inet_unregister_protosw(&dccp_v4_protosw);
1140 inet_del_protocol(&dccp_v4_protocol, IPPROTO_DCCP);
1141 proto_unregister(&dccp_v4_prot);
1142}
1143
1144module_init(dccp_v4_init);
1145module_exit(dccp_v4_exit);
1146
1147/*
1148 * __stringify doesn't likes enums, so use SOCK_DCCP (6) and IPPROTO_DCCP (33)
1149 * values directly, Also cover the case where the protocol is not specified,
1150 * i.e. net-pf-PF_INET-proto-0-type-SOCK_DCCP
1151 */
1152MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-33-type-6");
1153MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-0-type-6");
1154MODULE_LICENSE("GPL");
1155MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@mandriva.com>");
1156MODULE_DESCRIPTION("DCCP - Datagram Congestion Controlled Protocol");
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index 80c4d048869e..65e2ab0886e6 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * DCCP over IPv6 2 * DCCP over IPv6
3 * Linux INET6 implementation 3 * Linux INET6 implementation
4 * 4 *
5 * Based on net/dccp6/ipv6.c 5 * Based on net/dccp6/ipv6.c
6 * 6 *
@@ -33,6 +33,9 @@
33#include "dccp.h" 33#include "dccp.h"
34#include "ipv6.h" 34#include "ipv6.h"
35 35
36/* Socket used for sending RSTs and ACKs */
37static struct socket *dccp_v6_ctl_socket;
38
36static void dccp_v6_ctl_send_reset(struct sk_buff *skb); 39static void dccp_v6_ctl_send_reset(struct sk_buff *skb);
37static void dccp_v6_reqsk_send_ack(struct sk_buff *skb, 40static void dccp_v6_reqsk_send_ack(struct sk_buff *skb,
38 struct request_sock *req); 41 struct request_sock *req);
@@ -53,7 +56,7 @@ static void dccp_v6_hash(struct sock *sk)
53{ 56{
54 if (sk->sk_state != DCCP_CLOSED) { 57 if (sk->sk_state != DCCP_CLOSED) {
55 if (inet_csk(sk)->icsk_af_ops == &dccp_ipv6_mapped) { 58 if (inet_csk(sk)->icsk_af_ops == &dccp_ipv6_mapped) {
56 dccp_prot.hash(sk); 59 dccp_hash(sk);
57 return; 60 return;
58 } 61 }
59 local_bh_disable(); 62 local_bh_disable();
@@ -63,8 +66,8 @@ static void dccp_v6_hash(struct sock *sk)
63} 66}
64 67
65static inline u16 dccp_v6_check(struct dccp_hdr *dh, int len, 68static inline u16 dccp_v6_check(struct dccp_hdr *dh, int len,
66 struct in6_addr *saddr, 69 struct in6_addr *saddr,
67 struct in6_addr *daddr, 70 struct in6_addr *daddr,
68 unsigned long base) 71 unsigned long base)
69{ 72{
70 return csum_ipv6_magic(saddr, daddr, len, IPPROTO_DCCP, base); 73 return csum_ipv6_magic(saddr, daddr, len, IPPROTO_DCCP, base);
@@ -79,17 +82,17 @@ static __u32 dccp_v6_init_sequence(struct sock *sk, struct sk_buff *skb)
79 skb->nh.ipv6h->saddr.s6_addr32, 82 skb->nh.ipv6h->saddr.s6_addr32,
80 dh->dccph_dport, 83 dh->dccph_dport,
81 dh->dccph_sport); 84 dh->dccph_sport);
82 else 85
83 return secure_dccp_sequence_number(skb->nh.iph->daddr, 86 return secure_dccp_sequence_number(skb->nh.iph->daddr,
84 skb->nh.iph->saddr, 87 skb->nh.iph->saddr,
85 dh->dccph_dport, 88 dh->dccph_dport,
86 dh->dccph_sport); 89 dh->dccph_sport);
87} 90}
88 91
89static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr, 92static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
90 int addr_len) 93 int addr_len)
91{ 94{
92 struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr; 95 struct sockaddr_in6 *usin = (struct sockaddr_in6 *)uaddr;
93 struct inet_connection_sock *icsk = inet_csk(sk); 96 struct inet_connection_sock *icsk = inet_csk(sk);
94 struct inet_sock *inet = inet_sk(sk); 97 struct inet_sock *inet = inet_sk(sk);
95 struct ipv6_pinfo *np = inet6_sk(sk); 98 struct ipv6_pinfo *np = inet6_sk(sk);
@@ -102,10 +105,10 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
102 105
103 dp->dccps_role = DCCP_ROLE_CLIENT; 106 dp->dccps_role = DCCP_ROLE_CLIENT;
104 107
105 if (addr_len < SIN6_LEN_RFC2133) 108 if (addr_len < SIN6_LEN_RFC2133)
106 return -EINVAL; 109 return -EINVAL;
107 110
108 if (usin->sin6_family != AF_INET6) 111 if (usin->sin6_family != AF_INET6)
109 return -EAFNOSUPPORT; 112 return -EAFNOSUPPORT;
110 113
111 memset(&fl, 0, sizeof(fl)); 114 memset(&fl, 0, sizeof(fl));
@@ -122,17 +125,15 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
122 fl6_sock_release(flowlabel); 125 fl6_sock_release(flowlabel);
123 } 126 }
124 } 127 }
125
126 /* 128 /*
127 * connect() to INADDR_ANY means loopback (BSD'ism). 129 * connect() to INADDR_ANY means loopback (BSD'ism).
128 */ 130 */
129 131 if (ipv6_addr_any(&usin->sin6_addr))
130 if (ipv6_addr_any(&usin->sin6_addr)) 132 usin->sin6_addr.s6_addr[15] = 1;
131 usin->sin6_addr.s6_addr[15] = 0x1;
132 133
133 addr_type = ipv6_addr_type(&usin->sin6_addr); 134 addr_type = ipv6_addr_type(&usin->sin6_addr);
134 135
135 if(addr_type & IPV6_ADDR_MULTICAST) 136 if (addr_type & IPV6_ADDR_MULTICAST)
136 return -ENETUNREACH; 137 return -ENETUNREACH;
137 138
138 if (addr_type & IPV6_ADDR_LINKLOCAL) { 139 if (addr_type & IPV6_ADDR_LINKLOCAL) {
@@ -157,9 +158,8 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
157 np->flow_label = fl.fl6_flowlabel; 158 np->flow_label = fl.fl6_flowlabel;
158 159
159 /* 160 /*
160 * DCCP over IPv4 161 * DCCP over IPv4
161 */ 162 */
162
163 if (addr_type == IPV6_ADDR_MAPPED) { 163 if (addr_type == IPV6_ADDR_MAPPED) {
164 u32 exthdrlen = icsk->icsk_ext_hdr_len; 164 u32 exthdrlen = icsk->icsk_ext_hdr_len;
165 struct sockaddr_in sin; 165 struct sockaddr_in sin;
@@ -177,7 +177,6 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
177 sk->sk_backlog_rcv = dccp_v4_do_rcv; 177 sk->sk_backlog_rcv = dccp_v4_do_rcv;
178 178
179 err = dccp_v4_connect(sk, (struct sockaddr *)&sin, sizeof(sin)); 179 err = dccp_v4_connect(sk, (struct sockaddr *)&sin, sizeof(sin));
180
181 if (err) { 180 if (err) {
182 icsk->icsk_ext_hdr_len = exthdrlen; 181 icsk->icsk_ext_hdr_len = exthdrlen;
183 icsk->icsk_af_ops = &dccp_ipv6_af_ops; 182 icsk->icsk_af_ops = &dccp_ipv6_af_ops;
@@ -203,8 +202,9 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
203 fl.fl_ip_dport = usin->sin6_port; 202 fl.fl_ip_dport = usin->sin6_port;
204 fl.fl_ip_sport = inet->sport; 203 fl.fl_ip_sport = inet->sport;
205 204
206 if (np->opt && np->opt->srcrt) { 205 if (np->opt != NULL && np->opt->srcrt != NULL) {
207 struct rt0_hdr *rt0 = (struct rt0_hdr *)np->opt->srcrt; 206 const struct rt0_hdr *rt0 = (struct rt0_hdr *)np->opt->srcrt;
207
208 ipv6_addr_copy(&final, &fl.fl6_dst); 208 ipv6_addr_copy(&final, &fl.fl6_dst);
209 ipv6_addr_copy(&fl.fl6_dst, rt0->addr); 209 ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
210 final_p = &final; 210 final_p = &final;
@@ -213,10 +213,12 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
213 err = ip6_dst_lookup(sk, &dst, &fl); 213 err = ip6_dst_lookup(sk, &dst, &fl);
214 if (err) 214 if (err)
215 goto failure; 215 goto failure;
216
216 if (final_p) 217 if (final_p)
217 ipv6_addr_copy(&fl.fl6_dst, final_p); 218 ipv6_addr_copy(&fl.fl6_dst, final_p);
218 219
219 if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) 220 err = xfrm_lookup(&dst, &fl, sk, 0);
221 if (err < 0)
220 goto failure; 222 goto failure;
221 223
222 if (saddr == NULL) { 224 if (saddr == NULL) {
@@ -231,7 +233,7 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
231 ip6_dst_store(sk, dst, NULL); 233 ip6_dst_store(sk, dst, NULL);
232 234
233 icsk->icsk_ext_hdr_len = 0; 235 icsk->icsk_ext_hdr_len = 0;
234 if (np->opt) 236 if (np->opt != NULL)
235 icsk->icsk_ext_hdr_len = (np->opt->opt_flen + 237 icsk->icsk_ext_hdr_len = (np->opt->opt_flen +
236 np->opt->opt_nflen); 238 np->opt->opt_nflen);
237 239
@@ -264,7 +266,7 @@ failure:
264} 266}
265 267
266static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 268static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
267 int type, int code, int offset, __u32 info) 269 int type, int code, int offset, __be32 info)
268{ 270{
269 struct ipv6hdr *hdr = (struct ipv6hdr *)skb->data; 271 struct ipv6hdr *hdr = (struct ipv6hdr *)skb->data;
270 const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data + offset); 272 const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data + offset);
@@ -305,7 +307,6 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
305 307
306 /* icmp should have updated the destination cache entry */ 308 /* icmp should have updated the destination cache entry */
307 dst = __sk_dst_check(sk, np->dst_cookie); 309 dst = __sk_dst_check(sk, np->dst_cookie);
308
309 if (dst == NULL) { 310 if (dst == NULL) {
310 struct inet_sock *inet = inet_sk(sk); 311 struct inet_sock *inet = inet_sk(sk);
311 struct flowi fl; 312 struct flowi fl;
@@ -322,16 +323,17 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
322 fl.fl_ip_dport = inet->dport; 323 fl.fl_ip_dport = inet->dport;
323 fl.fl_ip_sport = inet->sport; 324 fl.fl_ip_sport = inet->sport;
324 325
325 if ((err = ip6_dst_lookup(sk, &dst, &fl))) { 326 err = ip6_dst_lookup(sk, &dst, &fl);
327 if (err) {
326 sk->sk_err_soft = -err; 328 sk->sk_err_soft = -err;
327 goto out; 329 goto out;
328 } 330 }
329 331
330 if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) { 332 err = xfrm_lookup(&dst, &fl, sk, 0);
333 if (err < 0) {
331 sk->sk_err_soft = -err; 334 sk->sk_err_soft = -err;
332 goto out; 335 goto out;
333 } 336 }
334
335 } else 337 } else
336 dst_hold(dst); 338 dst_hold(dst);
337 339
@@ -355,11 +357,12 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
355 req = inet6_csk_search_req(sk, &prev, dh->dccph_dport, 357 req = inet6_csk_search_req(sk, &prev, dh->dccph_dport,
356 &hdr->daddr, &hdr->saddr, 358 &hdr->daddr, &hdr->saddr,
357 inet6_iif(skb)); 359 inet6_iif(skb));
358 if (!req) 360 if (req == NULL)
359 goto out; 361 goto out;
360 362
361 /* ICMPs are not backlogged, hence we cannot get 363 /*
362 * an established socket here. 364 * ICMPs are not backlogged, hence we cannot get an established
365 * socket here.
363 */ 366 */
364 BUG_TRAP(req->sk == NULL); 367 BUG_TRAP(req->sk == NULL);
365 368
@@ -373,7 +376,7 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
373 376
374 case DCCP_REQUESTING: 377 case DCCP_REQUESTING:
375 case DCCP_RESPOND: /* Cannot happen. 378 case DCCP_RESPOND: /* Cannot happen.
376 It can, it SYNs are crossed. --ANK */ 379 It can, it SYNs are crossed. --ANK */
377 if (!sock_owned_by_user(sk)) { 380 if (!sock_owned_by_user(sk)) {
378 DCCP_INC_STATS_BH(DCCP_MIB_ATTEMPTFAILS); 381 DCCP_INC_STATS_BH(DCCP_MIB_ATTEMPTFAILS);
379 sk->sk_err = err; 382 sk->sk_err = err;
@@ -382,7 +385,6 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
382 * (see connect in sock.c) 385 * (see connect in sock.c)
383 */ 386 */
384 sk->sk_error_report(sk); 387 sk->sk_error_report(sk);
385
386 dccp_done(sk); 388 dccp_done(sk);
387 } else 389 } else
388 sk->sk_err_soft = err; 390 sk->sk_err_soft = err;
@@ -428,14 +430,16 @@ static int dccp_v6_send_response(struct sock *sk, struct request_sock *req,
428 ireq6->pktopts) { 430 ireq6->pktopts) {
429 struct sk_buff *pktopts = ireq6->pktopts; 431 struct sk_buff *pktopts = ireq6->pktopts;
430 struct inet6_skb_parm *rxopt = IP6CB(pktopts); 432 struct inet6_skb_parm *rxopt = IP6CB(pktopts);
433
431 if (rxopt->srcrt) 434 if (rxopt->srcrt)
432 opt = ipv6_invert_rthdr(sk, 435 opt = ipv6_invert_rthdr(sk,
433 (struct ipv6_rt_hdr *)(pktopts->nh.raw + 436 (struct ipv6_rt_hdr *)(pktopts->nh.raw +
434 rxopt->srcrt)); 437 rxopt->srcrt));
435 } 438 }
436 439
437 if (opt && opt->srcrt) { 440 if (opt != NULL && opt->srcrt != NULL) {
438 struct rt0_hdr *rt0 = (struct rt0_hdr *)opt->srcrt; 441 const struct rt0_hdr *rt0 = (struct rt0_hdr *)opt->srcrt;
442
439 ipv6_addr_copy(&final, &fl.fl6_dst); 443 ipv6_addr_copy(&final, &fl.fl6_dst);
440 ipv6_addr_copy(&fl.fl6_dst, rt0->addr); 444 ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
441 final_p = &final; 445 final_p = &final;
@@ -444,15 +448,19 @@ static int dccp_v6_send_response(struct sock *sk, struct request_sock *req,
444 err = ip6_dst_lookup(sk, &dst, &fl); 448 err = ip6_dst_lookup(sk, &dst, &fl);
445 if (err) 449 if (err)
446 goto done; 450 goto done;
451
447 if (final_p) 452 if (final_p)
448 ipv6_addr_copy(&fl.fl6_dst, final_p); 453 ipv6_addr_copy(&fl.fl6_dst, final_p);
449 if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) 454
455 err = xfrm_lookup(&dst, &fl, sk, 0);
456 if (err < 0)
450 goto done; 457 goto done;
451 } 458 }
452 459
453 skb = dccp_make_response(sk, dst, req); 460 skb = dccp_make_response(sk, dst, req);
454 if (skb != NULL) { 461 if (skb != NULL) {
455 struct dccp_hdr *dh = dccp_hdr(skb); 462 struct dccp_hdr *dh = dccp_hdr(skb);
463
456 dh->dccph_checksum = dccp_v6_check(dh, skb->len, 464 dh->dccph_checksum = dccp_v6_check(dh, skb->len,
457 &ireq6->loc_addr, 465 &ireq6->loc_addr,
458 &ireq6->rmt_addr, 466 &ireq6->rmt_addr,
@@ -466,7 +474,7 @@ static int dccp_v6_send_response(struct sock *sk, struct request_sock *req,
466 } 474 }
467 475
468done: 476done:
469 if (opt && opt != np->opt) 477 if (opt != NULL && opt != np->opt)
470 sock_kfree_s(sk, opt, opt->tot_len); 478 sock_kfree_s(sk, opt, opt->tot_len);
471 dst_release(dst); 479 dst_release(dst);
472 return err; 480 return err;
@@ -497,7 +505,7 @@ static void dccp_v6_send_check(struct sock *sk, int len, struct sk_buff *skb)
497 struct dccp_hdr *dh = dccp_hdr(skb); 505 struct dccp_hdr *dh = dccp_hdr(skb);
498 506
499 dh->dccph_checksum = csum_ipv6_magic(&np->saddr, &np->daddr, 507 dh->dccph_checksum = csum_ipv6_magic(&np->saddr, &np->daddr,
500 len, IPPROTO_DCCP, 508 len, IPPROTO_DCCP,
501 csum_partial((char *)dh, 509 csum_partial((char *)dh,
502 dh->dccph_doff << 2, 510 dh->dccph_doff << 2,
503 skb->csum)); 511 skb->csum));
@@ -505,8 +513,8 @@ static void dccp_v6_send_check(struct sock *sk, int len, struct sk_buff *skb)
505 513
506static void dccp_v6_ctl_send_reset(struct sk_buff *rxskb) 514static void dccp_v6_ctl_send_reset(struct sk_buff *rxskb)
507{ 515{
508 struct dccp_hdr *rxdh = dccp_hdr(rxskb), *dh; 516 struct dccp_hdr *rxdh = dccp_hdr(rxskb), *dh;
509 const int dccp_hdr_reset_len = sizeof(struct dccp_hdr) + 517 const u32 dccp_hdr_reset_len = sizeof(struct dccp_hdr) +
510 sizeof(struct dccp_hdr_ext) + 518 sizeof(struct dccp_hdr_ext) +
511 sizeof(struct dccp_hdr_reset); 519 sizeof(struct dccp_hdr_reset);
512 struct sk_buff *skb; 520 struct sk_buff *skb;
@@ -517,20 +525,14 @@ static void dccp_v6_ctl_send_reset(struct sk_buff *rxskb)
517 return; 525 return;
518 526
519 if (!ipv6_unicast_destination(rxskb)) 527 if (!ipv6_unicast_destination(rxskb))
520 return; 528 return;
521
522 /*
523 * We need to grab some memory, and put together an RST,
524 * and then put it into the queue to be sent.
525 */
526 529
527 skb = alloc_skb(MAX_HEADER + sizeof(struct ipv6hdr) + 530 skb = alloc_skb(dccp_v6_ctl_socket->sk->sk_prot->max_header,
528 dccp_hdr_reset_len, GFP_ATOMIC); 531 GFP_ATOMIC);
529 if (skb == NULL) 532 if (skb == NULL)
530 return; 533 return;
531 534
532 skb_reserve(skb, MAX_HEADER + sizeof(struct ipv6hdr) + 535 skb_reserve(skb, dccp_v6_ctl_socket->sk->sk_prot->max_header);
533 dccp_hdr_reset_len);
534 536
535 skb->h.raw = skb_push(skb, dccp_hdr_reset_len); 537 skb->h.raw = skb_push(skb, dccp_hdr_reset_len);
536 dh = dccp_hdr(skb); 538 dh = dccp_hdr(skb);
@@ -568,7 +570,7 @@ static void dccp_v6_ctl_send_reset(struct sk_buff *rxskb)
568 /* sk = NULL, but it is safe for now. RST socket required. */ 570 /* sk = NULL, but it is safe for now. RST socket required. */
569 if (!ip6_dst_lookup(NULL, &skb->dst, &fl)) { 571 if (!ip6_dst_lookup(NULL, &skb->dst, &fl)) {
570 if (xfrm_lookup(&skb->dst, &fl, NULL, 0) >= 0) { 572 if (xfrm_lookup(&skb->dst, &fl, NULL, 0) >= 0) {
571 ip6_xmit(NULL, skb, &fl, NULL, 0); 573 ip6_xmit(dccp_v6_ctl_socket->sk, skb, &fl, NULL, 0);
572 DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS); 574 DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS);
573 DCCP_INC_STATS_BH(DCCP_MIB_OUTRSTS); 575 DCCP_INC_STATS_BH(DCCP_MIB_OUTRSTS);
574 return; 576 return;
@@ -578,22 +580,22 @@ static void dccp_v6_ctl_send_reset(struct sk_buff *rxskb)
578 kfree_skb(skb); 580 kfree_skb(skb);
579} 581}
580 582
581static void dccp_v6_ctl_send_ack(struct sk_buff *rxskb) 583static void dccp_v6_reqsk_send_ack(struct sk_buff *rxskb,
584 struct request_sock *req)
582{ 585{
583 struct flowi fl; 586 struct flowi fl;
584 struct dccp_hdr *rxdh = dccp_hdr(rxskb), *dh; 587 struct dccp_hdr *rxdh = dccp_hdr(rxskb), *dh;
585 const int dccp_hdr_ack_len = sizeof(struct dccp_hdr) + 588 const u32 dccp_hdr_ack_len = sizeof(struct dccp_hdr) +
586 sizeof(struct dccp_hdr_ext) + 589 sizeof(struct dccp_hdr_ext) +
587 sizeof(struct dccp_hdr_ack_bits); 590 sizeof(struct dccp_hdr_ack_bits);
588 struct sk_buff *skb; 591 struct sk_buff *skb;
589 592
590 skb = alloc_skb(MAX_HEADER + sizeof(struct ipv6hdr) + 593 skb = alloc_skb(dccp_v6_ctl_socket->sk->sk_prot->max_header,
591 dccp_hdr_ack_len, GFP_ATOMIC); 594 GFP_ATOMIC);
592 if (skb == NULL) 595 if (skb == NULL)
593 return; 596 return;
594 597
595 skb_reserve(skb, MAX_HEADER + sizeof(struct ipv6hdr) + 598 skb_reserve(skb, dccp_v6_ctl_socket->sk->sk_prot->max_header);
596 dccp_hdr_ack_len);
597 599
598 skb->h.raw = skb_push(skb, dccp_hdr_ack_len); 600 skb->h.raw = skb_push(skb, dccp_hdr_ack_len);
599 dh = dccp_hdr(skb); 601 dh = dccp_hdr(skb);
@@ -605,7 +607,7 @@ static void dccp_v6_ctl_send_ack(struct sk_buff *rxskb)
605 dh->dccph_dport = rxdh->dccph_sport; 607 dh->dccph_dport = rxdh->dccph_sport;
606 dh->dccph_doff = dccp_hdr_ack_len / 4; 608 dh->dccph_doff = dccp_hdr_ack_len / 4;
607 dh->dccph_x = 1; 609 dh->dccph_x = 1;
608 610
609 dccp_hdr_set_seq(dh, DCCP_SKB_CB(rxskb)->dccpd_ack_seq); 611 dccp_hdr_set_seq(dh, DCCP_SKB_CB(rxskb)->dccpd_ack_seq);
610 dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), 612 dccp_hdr_set_ack(dccp_hdr_ack_bits(skb),
611 DCCP_SKB_CB(rxskb)->dccpd_seq); 613 DCCP_SKB_CB(rxskb)->dccpd_seq);
@@ -623,7 +625,7 @@ static void dccp_v6_ctl_send_ack(struct sk_buff *rxskb)
623 625
624 if (!ip6_dst_lookup(NULL, &skb->dst, &fl)) { 626 if (!ip6_dst_lookup(NULL, &skb->dst, &fl)) {
625 if (xfrm_lookup(&skb->dst, &fl, NULL, 0) >= 0) { 627 if (xfrm_lookup(&skb->dst, &fl, NULL, 0) >= 0) {
626 ip6_xmit(NULL, skb, &fl, NULL, 0); 628 ip6_xmit(dccp_v6_ctl_socket->sk, skb, &fl, NULL, 0);
627 DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS); 629 DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS);
628 return; 630 return;
629 } 631 }
@@ -632,12 +634,6 @@ static void dccp_v6_ctl_send_ack(struct sk_buff *rxskb)
632 kfree_skb(skb); 634 kfree_skb(skb);
633} 635}
634 636
635static void dccp_v6_reqsk_send_ack(struct sk_buff *skb,
636 struct request_sock *req)
637{
638 dccp_v6_ctl_send_ack(skb);
639}
640
641static struct sock *dccp_v6_hnd_req(struct sock *sk,struct sk_buff *skb) 637static struct sock *dccp_v6_hnd_req(struct sock *sk,struct sk_buff *skb)
642{ 638{
643 const struct dccp_hdr *dh = dccp_hdr(skb); 639 const struct dccp_hdr *dh = dccp_hdr(skb);
@@ -657,7 +653,6 @@ static struct sock *dccp_v6_hnd_req(struct sock *sk,struct sk_buff *skb)
657 &iph->saddr, dh->dccph_sport, 653 &iph->saddr, dh->dccph_sport,
658 &iph->daddr, ntohs(dh->dccph_dport), 654 &iph->daddr, ntohs(dh->dccph_dport),
659 inet6_iif(skb)); 655 inet6_iif(skb));
660
661 if (nsk != NULL) { 656 if (nsk != NULL) {
662 if (nsk->sk_state != DCCP_TIME_WAIT) { 657 if (nsk->sk_state != DCCP_TIME_WAIT) {
663 bh_lock_sock(nsk); 658 bh_lock_sock(nsk);
@@ -678,7 +673,7 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
678 struct dccp_request_sock *dreq; 673 struct dccp_request_sock *dreq;
679 struct inet6_request_sock *ireq6; 674 struct inet6_request_sock *ireq6;
680 struct ipv6_pinfo *np = inet6_sk(sk); 675 struct ipv6_pinfo *np = inet6_sk(sk);
681 const __u32 service = dccp_hdr_request(skb)->dccph_req_service; 676 const __be32 service = dccp_hdr_request(skb)->dccph_req_service;
682 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); 677 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
683 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY; 678 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY;
684 679
@@ -686,17 +681,17 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
686 return dccp_v4_conn_request(sk, skb); 681 return dccp_v4_conn_request(sk, skb);
687 682
688 if (!ipv6_unicast_destination(skb)) 683 if (!ipv6_unicast_destination(skb))
689 goto drop; 684 goto drop;
690 685
691 if (dccp_bad_service_code(sk, service)) { 686 if (dccp_bad_service_code(sk, service)) {
692 reset_code = DCCP_RESET_CODE_BAD_SERVICE_CODE; 687 reset_code = DCCP_RESET_CODE_BAD_SERVICE_CODE;
693 goto drop; 688 goto drop;
694 } 689 }
695 /* 690 /*
696 * There are no SYN attacks on IPv6, yet... 691 * There are no SYN attacks on IPv6, yet...
697 */ 692 */
698 if (inet_csk_reqsk_queue_is_full(sk)) 693 if (inet_csk_reqsk_queue_is_full(sk))
699 goto drop; 694 goto drop;
700 695
701 if (sk_acceptq_is_full(sk) && inet_csk_reqsk_queue_young(sk) > 1) 696 if (sk_acceptq_is_full(sk) && inet_csk_reqsk_queue_young(sk) > 1)
702 goto drop; 697 goto drop;
@@ -730,7 +725,7 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
730 ipv6_addr_type(&ireq6->rmt_addr) & IPV6_ADDR_LINKLOCAL) 725 ipv6_addr_type(&ireq6->rmt_addr) & IPV6_ADDR_LINKLOCAL)
731 ireq6->iif = inet6_iif(skb); 726 ireq6->iif = inet6_iif(skb);
732 727
733 /* 728 /*
734 * Step 3: Process LISTEN state 729 * Step 3: Process LISTEN state
735 * 730 *
736 * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookie 731 * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookie
@@ -774,9 +769,8 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
774 /* 769 /*
775 * v6 mapped 770 * v6 mapped
776 */ 771 */
777
778 newsk = dccp_v4_request_recv_sock(sk, skb, req, dst); 772 newsk = dccp_v4_request_recv_sock(sk, skb, req, dst);
779 if (newsk == NULL) 773 if (newsk == NULL)
780 return NULL; 774 return NULL;
781 775
782 newdp6 = (struct dccp6_sock *)newsk; 776 newdp6 = (struct dccp6_sock *)newsk;
@@ -822,9 +816,9 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
822 if (sk_acceptq_is_full(sk)) 816 if (sk_acceptq_is_full(sk))
823 goto out_overflow; 817 goto out_overflow;
824 818
825 if (np->rxopt.bits.osrcrt == 2 && 819 if (np->rxopt.bits.osrcrt == 2 && opt == NULL && ireq6->pktopts) {
826 opt == NULL && ireq6->pktopts) { 820 const struct inet6_skb_parm *rxopt = IP6CB(ireq6->pktopts);
827 struct inet6_skb_parm *rxopt = IP6CB(ireq6->pktopts); 821
828 if (rxopt->srcrt) 822 if (rxopt->srcrt)
829 opt = ipv6_invert_rthdr(sk, 823 opt = ipv6_invert_rthdr(sk,
830 (struct ipv6_rt_hdr *)(ireq6->pktopts->nh.raw + 824 (struct ipv6_rt_hdr *)(ireq6->pktopts->nh.raw +
@@ -838,8 +832,9 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
838 memset(&fl, 0, sizeof(fl)); 832 memset(&fl, 0, sizeof(fl));
839 fl.proto = IPPROTO_DCCP; 833 fl.proto = IPPROTO_DCCP;
840 ipv6_addr_copy(&fl.fl6_dst, &ireq6->rmt_addr); 834 ipv6_addr_copy(&fl.fl6_dst, &ireq6->rmt_addr);
841 if (opt && opt->srcrt) { 835 if (opt != NULL && opt->srcrt != NULL) {
842 struct rt0_hdr *rt0 = (struct rt0_hdr *) opt->srcrt; 836 const struct rt0_hdr *rt0 = (struct rt0_hdr *)opt->srcrt;
837
843 ipv6_addr_copy(&final, &fl.fl6_dst); 838 ipv6_addr_copy(&final, &fl.fl6_dst);
844 ipv6_addr_copy(&fl.fl6_dst, rt0->addr); 839 ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
845 final_p = &final; 840 final_p = &final;
@@ -857,7 +852,7 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
857 852
858 if ((xfrm_lookup(&dst, &fl, sk, 0)) < 0) 853 if ((xfrm_lookup(&dst, &fl, sk, 0)) < 0)
859 goto out; 854 goto out;
860 } 855 }
861 856
862 newsk = dccp_create_openreq_child(sk, req, skb); 857 newsk = dccp_create_openreq_child(sk, req, skb);
863 if (newsk == NULL) 858 if (newsk == NULL)
@@ -870,9 +865,8 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
870 */ 865 */
871 866
872 ip6_dst_store(newsk, dst, NULL); 867 ip6_dst_store(newsk, dst, NULL);
873 newsk->sk_route_caps = dst->dev->features & 868 newsk->sk_route_caps = dst->dev->features & ~(NETIF_F_IP_CSUM |
874 ~(NETIF_F_IP_CSUM | NETIF_F_TSO); 869 NETIF_F_TSO);
875
876 newdp6 = (struct dccp6_sock *)newsk; 870 newdp6 = (struct dccp6_sock *)newsk;
877 newinet = inet_sk(newsk); 871 newinet = inet_sk(newsk);
878 newinet->pinet6 = &newdp6->inet6; 872 newinet->pinet6 = &newdp6->inet6;
@@ -886,7 +880,7 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
886 ipv6_addr_copy(&newnp->rcv_saddr, &ireq6->loc_addr); 880 ipv6_addr_copy(&newnp->rcv_saddr, &ireq6->loc_addr);
887 newsk->sk_bound_dev_if = ireq6->iif; 881 newsk->sk_bound_dev_if = ireq6->iif;
888 882
889 /* Now IPv6 options... 883 /* Now IPv6 options...
890 884
891 First: no IPv4 options. 885 First: no IPv4 options.
892 */ 886 */
@@ -908,20 +902,20 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
908 newnp->mcast_oif = inet6_iif(skb); 902 newnp->mcast_oif = inet6_iif(skb);
909 newnp->mcast_hops = skb->nh.ipv6h->hop_limit; 903 newnp->mcast_hops = skb->nh.ipv6h->hop_limit;
910 904
911 /* Clone native IPv6 options from listening socket (if any) 905 /*
912 906 * Clone native IPv6 options from listening socket (if any)
913 Yes, keeping reference count would be much more clever, 907 *
914 but we make one more one thing there: reattach optmem 908 * Yes, keeping reference count would be much more clever, but we make
915 to newsk. 909 * one more one thing there: reattach optmem to newsk.
916 */ 910 */
917 if (opt) { 911 if (opt != NULL) {
918 newnp->opt = ipv6_dup_options(newsk, opt); 912 newnp->opt = ipv6_dup_options(newsk, opt);
919 if (opt != np->opt) 913 if (opt != np->opt)
920 sock_kfree_s(sk, opt, opt->tot_len); 914 sock_kfree_s(sk, opt, opt->tot_len);
921 } 915 }
922 916
923 inet_csk(newsk)->icsk_ext_hdr_len = 0; 917 inet_csk(newsk)->icsk_ext_hdr_len = 0;
924 if (newnp->opt) 918 if (newnp->opt != NULL)
925 inet_csk(newsk)->icsk_ext_hdr_len = (newnp->opt->opt_nflen + 919 inet_csk(newsk)->icsk_ext_hdr_len = (newnp->opt->opt_nflen +
926 newnp->opt->opt_flen); 920 newnp->opt->opt_flen);
927 921
@@ -938,7 +932,7 @@ out_overflow:
938 NET_INC_STATS_BH(LINUX_MIB_LISTENOVERFLOWS); 932 NET_INC_STATS_BH(LINUX_MIB_LISTENOVERFLOWS);
939out: 933out:
940 NET_INC_STATS_BH(LINUX_MIB_LISTENDROPS); 934 NET_INC_STATS_BH(LINUX_MIB_LISTENDROPS);
941 if (opt && opt != np->opt) 935 if (opt != NULL && opt != np->opt)
942 sock_kfree_s(sk, opt, opt->tot_len); 936 sock_kfree_s(sk, opt, opt->tot_len);
943 dst_release(dst); 937 dst_release(dst);
944 return NULL; 938 return NULL;
@@ -972,8 +966,8 @@ static int dccp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
972 goto discard; 966 goto discard;
973 967
974 /* 968 /*
975 * socket locking is here for SMP purposes as backlog rcv 969 * socket locking is here for SMP purposes as backlog rcv is currently
976 * is currently called with bh processing disabled. 970 * called with bh processing disabled.
977 */ 971 */
978 972
979 /* Do Stevens' IPV6_PKTOPTIONS. 973 /* Do Stevens' IPV6_PKTOPTIONS.
@@ -998,20 +992,20 @@ static int dccp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
998 return 0; 992 return 0;
999 } 993 }
1000 994
1001 if (sk->sk_state == DCCP_LISTEN) { 995 if (sk->sk_state == DCCP_LISTEN) {
1002 struct sock *nsk = dccp_v6_hnd_req(sk, skb); 996 struct sock *nsk = dccp_v6_hnd_req(sk, skb);
1003 if (!nsk)
1004 goto discard;
1005 997
998 if (nsk == NULL)
999 goto discard;
1006 /* 1000 /*
1007 * Queue it on the new socket if the new socket is active, 1001 * Queue it on the new socket if the new socket is active,
1008 * otherwise we just shortcircuit this and continue with 1002 * otherwise we just shortcircuit this and continue with
1009 * the new socket.. 1003 * the new socket..
1010 */ 1004 */
1011 if(nsk != sk) { 1005 if (nsk != sk) {
1012 if (dccp_child_process(sk, nsk, skb)) 1006 if (dccp_child_process(sk, nsk, skb))
1013 goto reset; 1007 goto reset;
1014 if (opt_skb) 1008 if (opt_skb != NULL)
1015 __kfree_skb(opt_skb); 1009 __kfree_skb(opt_skb);
1016 return 0; 1010 return 0;
1017 } 1011 }
@@ -1024,7 +1018,7 @@ static int dccp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
1024reset: 1018reset:
1025 dccp_v6_ctl_send_reset(skb); 1019 dccp_v6_ctl_send_reset(skb);
1026discard: 1020discard:
1027 if (opt_skb) 1021 if (opt_skb != NULL)
1028 __kfree_skb(opt_skb); 1022 __kfree_skb(opt_skb);
1029 kfree_skb(skb); 1023 kfree_skb(skb);
1030 return 0; 1024 return 0;
@@ -1057,7 +1051,7 @@ static int dccp_v6_rcv(struct sk_buff **pskb)
1057 dh->dccph_sport, 1051 dh->dccph_sport,
1058 &skb->nh.ipv6h->daddr, ntohs(dh->dccph_dport), 1052 &skb->nh.ipv6h->daddr, ntohs(dh->dccph_dport),
1059 inet6_iif(skb)); 1053 inet6_iif(skb));
1060 /* 1054 /*
1061 * Step 2: 1055 * Step 2:
1062 * If no socket ... 1056 * If no socket ...
1063 * Generate Reset(No Connection) unless P.type == Reset 1057 * Generate Reset(No Connection) unless P.type == Reset
@@ -1066,15 +1060,14 @@ static int dccp_v6_rcv(struct sk_buff **pskb)
1066 if (sk == NULL) 1060 if (sk == NULL)
1067 goto no_dccp_socket; 1061 goto no_dccp_socket;
1068 1062
1069 /* 1063 /*
1070 * Step 2: 1064 * Step 2:
1071 * ... or S.state == TIMEWAIT, 1065 * ... or S.state == TIMEWAIT,
1072 * Generate Reset(No Connection) unless P.type == Reset 1066 * Generate Reset(No Connection) unless P.type == Reset
1073 * Drop packet and return 1067 * Drop packet and return
1074 */ 1068 */
1075
1076 if (sk->sk_state == DCCP_TIME_WAIT) 1069 if (sk->sk_state == DCCP_TIME_WAIT)
1077 goto do_time_wait; 1070 goto do_time_wait;
1078 1071
1079 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) 1072 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
1080 goto discard_and_relse; 1073 goto discard_and_relse;
@@ -1113,32 +1106,40 @@ do_time_wait:
1113} 1106}
1114 1107
1115static struct inet_connection_sock_af_ops dccp_ipv6_af_ops = { 1108static struct inet_connection_sock_af_ops dccp_ipv6_af_ops = {
1116 .queue_xmit = inet6_csk_xmit, 1109 .queue_xmit = inet6_csk_xmit,
1117 .send_check = dccp_v6_send_check, 1110 .send_check = dccp_v6_send_check,
1118 .rebuild_header = inet6_sk_rebuild_header, 1111 .rebuild_header = inet6_sk_rebuild_header,
1119 .conn_request = dccp_v6_conn_request, 1112 .conn_request = dccp_v6_conn_request,
1120 .syn_recv_sock = dccp_v6_request_recv_sock, 1113 .syn_recv_sock = dccp_v6_request_recv_sock,
1121 .net_header_len = sizeof(struct ipv6hdr), 1114 .net_header_len = sizeof(struct ipv6hdr),
1122 .setsockopt = ipv6_setsockopt, 1115 .setsockopt = ipv6_setsockopt,
1123 .getsockopt = ipv6_getsockopt, 1116 .getsockopt = ipv6_getsockopt,
1124 .addr2sockaddr = inet6_csk_addr2sockaddr, 1117 .addr2sockaddr = inet6_csk_addr2sockaddr,
1125 .sockaddr_len = sizeof(struct sockaddr_in6) 1118 .sockaddr_len = sizeof(struct sockaddr_in6),
1119#ifdef CONFIG_COMPAT
1120 .compat_setsockopt = compat_ipv6_setsockopt,
1121 .compat_getsockopt = compat_ipv6_getsockopt,
1122#endif
1126}; 1123};
1127 1124
1128/* 1125/*
1129 * DCCP over IPv4 via INET6 API 1126 * DCCP over IPv4 via INET6 API
1130 */ 1127 */
1131static struct inet_connection_sock_af_ops dccp_ipv6_mapped = { 1128static struct inet_connection_sock_af_ops dccp_ipv6_mapped = {
1132 .queue_xmit = ip_queue_xmit, 1129 .queue_xmit = ip_queue_xmit,
1133 .send_check = dccp_v4_send_check, 1130 .send_check = dccp_v4_send_check,
1134 .rebuild_header = inet_sk_rebuild_header, 1131 .rebuild_header = inet_sk_rebuild_header,
1135 .conn_request = dccp_v6_conn_request, 1132 .conn_request = dccp_v6_conn_request,
1136 .syn_recv_sock = dccp_v6_request_recv_sock, 1133 .syn_recv_sock = dccp_v6_request_recv_sock,
1137 .net_header_len = sizeof(struct iphdr), 1134 .net_header_len = sizeof(struct iphdr),
1138 .setsockopt = ipv6_setsockopt, 1135 .setsockopt = ipv6_setsockopt,
1139 .getsockopt = ipv6_getsockopt, 1136 .getsockopt = ipv6_getsockopt,
1140 .addr2sockaddr = inet6_csk_addr2sockaddr, 1137 .addr2sockaddr = inet6_csk_addr2sockaddr,
1141 .sockaddr_len = sizeof(struct sockaddr_in6) 1138 .sockaddr_len = sizeof(struct sockaddr_in6),
1139#ifdef CONFIG_COMPAT
1140 .compat_setsockopt = compat_ipv6_setsockopt,
1141 .compat_getsockopt = compat_ipv6_getsockopt,
1142#endif
1142}; 1143};
1143 1144
1144/* NOTE: A lot of things set to zero explicitly by call to 1145/* NOTE: A lot of things set to zero explicitly by call to
@@ -1146,71 +1147,83 @@ static struct inet_connection_sock_af_ops dccp_ipv6_mapped = {
1146 */ 1147 */
1147static int dccp_v6_init_sock(struct sock *sk) 1148static int dccp_v6_init_sock(struct sock *sk)
1148{ 1149{
1149 int err = dccp_v4_init_sock(sk); 1150 static __u8 dccp_v6_ctl_sock_initialized;
1151 int err = dccp_init_sock(sk, dccp_v6_ctl_sock_initialized);
1150 1152
1151 if (err == 0) 1153 if (err == 0) {
1154 if (unlikely(!dccp_v6_ctl_sock_initialized))
1155 dccp_v6_ctl_sock_initialized = 1;
1152 inet_csk(sk)->icsk_af_ops = &dccp_ipv6_af_ops; 1156 inet_csk(sk)->icsk_af_ops = &dccp_ipv6_af_ops;
1157 }
1153 1158
1154 return err; 1159 return err;
1155} 1160}
1156 1161
1157static int dccp_v6_destroy_sock(struct sock *sk) 1162static int dccp_v6_destroy_sock(struct sock *sk)
1158{ 1163{
1159 dccp_v4_destroy_sock(sk); 1164 dccp_destroy_sock(sk);
1160 return inet6_destroy_sock(sk); 1165 return inet6_destroy_sock(sk);
1161} 1166}
1162 1167
1163static struct proto dccp_v6_prot = { 1168static struct proto dccp_v6_prot = {
1164 .name = "DCCPv6", 1169 .name = "DCCPv6",
1165 .owner = THIS_MODULE, 1170 .owner = THIS_MODULE,
1166 .close = dccp_close, 1171 .close = dccp_close,
1167 .connect = dccp_v6_connect, 1172 .connect = dccp_v6_connect,
1168 .disconnect = dccp_disconnect, 1173 .disconnect = dccp_disconnect,
1169 .ioctl = dccp_ioctl, 1174 .ioctl = dccp_ioctl,
1170 .init = dccp_v6_init_sock, 1175 .init = dccp_v6_init_sock,
1171 .setsockopt = dccp_setsockopt, 1176 .setsockopt = dccp_setsockopt,
1172 .getsockopt = dccp_getsockopt, 1177 .getsockopt = dccp_getsockopt,
1173 .sendmsg = dccp_sendmsg, 1178 .sendmsg = dccp_sendmsg,
1174 .recvmsg = dccp_recvmsg, 1179 .recvmsg = dccp_recvmsg,
1175 .backlog_rcv = dccp_v6_do_rcv, 1180 .backlog_rcv = dccp_v6_do_rcv,
1176 .hash = dccp_v6_hash, 1181 .hash = dccp_v6_hash,
1177 .unhash = dccp_unhash, 1182 .unhash = dccp_unhash,
1178 .accept = inet_csk_accept, 1183 .accept = inet_csk_accept,
1179 .get_port = dccp_v6_get_port, 1184 .get_port = dccp_v6_get_port,
1180 .shutdown = dccp_shutdown, 1185 .shutdown = dccp_shutdown,
1181 .destroy = dccp_v6_destroy_sock, 1186 .destroy = dccp_v6_destroy_sock,
1182 .orphan_count = &dccp_orphan_count, 1187 .orphan_count = &dccp_orphan_count,
1183 .max_header = MAX_DCCP_HEADER, 1188 .max_header = MAX_DCCP_HEADER,
1184 .obj_size = sizeof(struct dccp6_sock), 1189 .obj_size = sizeof(struct dccp6_sock),
1185 .rsk_prot = &dccp6_request_sock_ops, 1190 .rsk_prot = &dccp6_request_sock_ops,
1186 .twsk_prot = &dccp6_timewait_sock_ops, 1191 .twsk_prot = &dccp6_timewait_sock_ops,
1192#ifdef CONFIG_COMPAT
1193 .compat_setsockopt = compat_dccp_setsockopt,
1194 .compat_getsockopt = compat_dccp_getsockopt,
1195#endif
1187}; 1196};
1188 1197
1189static struct inet6_protocol dccp_v6_protocol = { 1198static struct inet6_protocol dccp_v6_protocol = {
1190 .handler = dccp_v6_rcv, 1199 .handler = dccp_v6_rcv,
1191 .err_handler = dccp_v6_err, 1200 .err_handler = dccp_v6_err,
1192 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL, 1201 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
1193}; 1202};
1194 1203
1195static struct proto_ops inet6_dccp_ops = { 1204static struct proto_ops inet6_dccp_ops = {
1196 .family = PF_INET6, 1205 .family = PF_INET6,
1197 .owner = THIS_MODULE, 1206 .owner = THIS_MODULE,
1198 .release = inet6_release, 1207 .release = inet6_release,
1199 .bind = inet6_bind, 1208 .bind = inet6_bind,
1200 .connect = inet_stream_connect, 1209 .connect = inet_stream_connect,
1201 .socketpair = sock_no_socketpair, 1210 .socketpair = sock_no_socketpair,
1202 .accept = inet_accept, 1211 .accept = inet_accept,
1203 .getname = inet6_getname, 1212 .getname = inet6_getname,
1204 .poll = dccp_poll, 1213 .poll = dccp_poll,
1205 .ioctl = inet6_ioctl, 1214 .ioctl = inet6_ioctl,
1206 .listen = inet_dccp_listen, 1215 .listen = inet_dccp_listen,
1207 .shutdown = inet_shutdown, 1216 .shutdown = inet_shutdown,
1208 .setsockopt = sock_common_setsockopt, 1217 .setsockopt = sock_common_setsockopt,
1209 .getsockopt = sock_common_getsockopt, 1218 .getsockopt = sock_common_getsockopt,
1210 .sendmsg = inet_sendmsg, 1219 .sendmsg = inet_sendmsg,
1211 .recvmsg = sock_common_recvmsg, 1220 .recvmsg = sock_common_recvmsg,
1212 .mmap = sock_no_mmap, 1221 .mmap = sock_no_mmap,
1213 .sendpage = sock_no_sendpage, 1222 .sendpage = sock_no_sendpage,
1223#ifdef CONFIG_COMPAT
1224 .compat_setsockopt = compat_sock_common_setsockopt,
1225 .compat_getsockopt = compat_sock_common_getsockopt,
1226#endif
1214}; 1227};
1215 1228
1216static struct inet_protosw dccp_v6_protosw = { 1229static struct inet_protosw dccp_v6_protosw = {
@@ -1234,8 +1247,16 @@ static int __init dccp_v6_init(void)
1234 goto out_unregister_proto; 1247 goto out_unregister_proto;
1235 1248
1236 inet6_register_protosw(&dccp_v6_protosw); 1249 inet6_register_protosw(&dccp_v6_protosw);
1250
1251 err = inet_csk_ctl_sock_create(&dccp_v6_ctl_socket, PF_INET6,
1252 SOCK_DCCP, IPPROTO_DCCP);
1253 if (err != 0)
1254 goto out_unregister_protosw;
1237out: 1255out:
1238 return err; 1256 return err;
1257out_unregister_protosw:
1258 inet6_del_protocol(&dccp_v6_protocol, IPPROTO_DCCP);
1259 inet6_unregister_protosw(&dccp_v6_protosw);
1239out_unregister_proto: 1260out_unregister_proto:
1240 proto_unregister(&dccp_v6_prot); 1261 proto_unregister(&dccp_v6_prot);
1241 goto out; 1262 goto out;
diff --git a/net/dccp/minisocks.c b/net/dccp/minisocks.c
index 29261fc198e7..c0349e5b0551 100644
--- a/net/dccp/minisocks.c
+++ b/net/dccp/minisocks.c
@@ -22,6 +22,7 @@
22#include "ackvec.h" 22#include "ackvec.h"
23#include "ccid.h" 23#include "ccid.h"
24#include "dccp.h" 24#include "dccp.h"
25#include "feat.h"
25 26
26struct inet_timewait_death_row dccp_death_row = { 27struct inet_timewait_death_row dccp_death_row = {
27 .sysctl_max_tw_buckets = NR_FILE * 2, 28 .sysctl_max_tw_buckets = NR_FILE * 2,
@@ -106,6 +107,7 @@ struct sock *dccp_create_openreq_child(struct sock *sk,
106 const struct dccp_request_sock *dreq = dccp_rsk(req); 107 const struct dccp_request_sock *dreq = dccp_rsk(req);
107 struct inet_connection_sock *newicsk = inet_csk(sk); 108 struct inet_connection_sock *newicsk = inet_csk(sk);
108 struct dccp_sock *newdp = dccp_sk(newsk); 109 struct dccp_sock *newdp = dccp_sk(newsk);
110 struct dccp_minisock *newdmsk = dccp_msk(newsk);
109 111
110 newdp->dccps_role = DCCP_ROLE_SERVER; 112 newdp->dccps_role = DCCP_ROLE_SERVER;
111 newdp->dccps_hc_rx_ackvec = NULL; 113 newdp->dccps_hc_rx_ackvec = NULL;
@@ -114,27 +116,27 @@ struct sock *dccp_create_openreq_child(struct sock *sk,
114 newicsk->icsk_rto = DCCP_TIMEOUT_INIT; 116 newicsk->icsk_rto = DCCP_TIMEOUT_INIT;
115 do_gettimeofday(&newdp->dccps_epoch); 117 do_gettimeofday(&newdp->dccps_epoch);
116 118
117 if (newdp->dccps_options.dccpo_send_ack_vector) { 119 if (dccp_feat_clone(sk, newsk))
120 goto out_free;
121
122 if (newdmsk->dccpms_send_ack_vector) {
118 newdp->dccps_hc_rx_ackvec = 123 newdp->dccps_hc_rx_ackvec =
119 dccp_ackvec_alloc(DCCP_MAX_ACKVEC_LEN, 124 dccp_ackvec_alloc(GFP_ATOMIC);
120 GFP_ATOMIC);
121 /*
122 * XXX: We're using the same CCIDs set on the parent,
123 * i.e. sk_clone copied the master sock and left the
124 * CCID pointers for this child, that is why we do the
125 * __ccid_get calls.
126 */
127 if (unlikely(newdp->dccps_hc_rx_ackvec == NULL)) 125 if (unlikely(newdp->dccps_hc_rx_ackvec == NULL))
128 goto out_free; 126 goto out_free;
129 } 127 }
130 128
131 if (unlikely(ccid_hc_rx_init(newdp->dccps_hc_rx_ccid, 129 newdp->dccps_hc_rx_ccid =
132 newsk) != 0 || 130 ccid_hc_rx_new(newdmsk->dccpms_rx_ccid,
133 ccid_hc_tx_init(newdp->dccps_hc_tx_ccid, 131 newsk, GFP_ATOMIC);
134 newsk) != 0)) { 132 newdp->dccps_hc_tx_ccid =
133 ccid_hc_tx_new(newdmsk->dccpms_tx_ccid,
134 newsk, GFP_ATOMIC);
135 if (unlikely(newdp->dccps_hc_rx_ccid == NULL ||
136 newdp->dccps_hc_tx_ccid == NULL)) {
135 dccp_ackvec_free(newdp->dccps_hc_rx_ackvec); 137 dccp_ackvec_free(newdp->dccps_hc_rx_ackvec);
136 ccid_hc_rx_exit(newdp->dccps_hc_rx_ccid, newsk); 138 ccid_hc_rx_delete(newdp->dccps_hc_rx_ccid, newsk);
137 ccid_hc_tx_exit(newdp->dccps_hc_tx_ccid, newsk); 139 ccid_hc_tx_delete(newdp->dccps_hc_tx_ccid, newsk);
138out_free: 140out_free:
139 /* It is still raw copy of parent, so invalidate 141 /* It is still raw copy of parent, so invalidate
140 * destructor and make plain sk_free() */ 142 * destructor and make plain sk_free() */
@@ -143,9 +145,6 @@ out_free:
143 return NULL; 145 return NULL;
144 } 146 }
145 147
146 __ccid_get(newdp->dccps_hc_rx_ccid);
147 __ccid_get(newdp->dccps_hc_tx_ccid);
148
149 /* 148 /*
150 * Step 3: Process LISTEN state 149 * Step 3: Process LISTEN state
151 * 150 *
@@ -155,7 +154,7 @@ out_free:
155 */ 154 */
156 155
157 /* See dccp_v4_conn_request */ 156 /* See dccp_v4_conn_request */
158 newdp->dccps_options.dccpo_sequence_window = req->rcv_wnd; 157 newdmsk->dccpms_sequence_window = req->rcv_wnd;
159 158
160 newdp->dccps_gar = newdp->dccps_isr = dreq->dreq_isr; 159 newdp->dccps_gar = newdp->dccps_isr = dreq->dreq_isr;
161 dccp_update_gsr(newsk, dreq->dreq_isr); 160 dccp_update_gsr(newsk, dreq->dreq_isr);
diff --git a/net/dccp/options.c b/net/dccp/options.c
index 0a76426c9aea..e9feb2a0c770 100644
--- a/net/dccp/options.c
+++ b/net/dccp/options.c
@@ -21,19 +21,23 @@
21#include "ackvec.h" 21#include "ackvec.h"
22#include "ccid.h" 22#include "ccid.h"
23#include "dccp.h" 23#include "dccp.h"
24#include "feat.h"
24 25
25/* stores the default values for new connection. may be changed with sysctl */ 26int dccp_feat_default_sequence_window = DCCPF_INITIAL_SEQUENCE_WINDOW;
26static const struct dccp_options dccpo_default_values = { 27int dccp_feat_default_rx_ccid = DCCPF_INITIAL_CCID;
27 .dccpo_sequence_window = DCCPF_INITIAL_SEQUENCE_WINDOW, 28int dccp_feat_default_tx_ccid = DCCPF_INITIAL_CCID;
28 .dccpo_rx_ccid = DCCPF_INITIAL_CCID, 29int dccp_feat_default_ack_ratio = DCCPF_INITIAL_ACK_RATIO;
29 .dccpo_tx_ccid = DCCPF_INITIAL_CCID, 30int dccp_feat_default_send_ack_vector = DCCPF_INITIAL_SEND_ACK_VECTOR;
30 .dccpo_send_ack_vector = DCCPF_INITIAL_SEND_ACK_VECTOR, 31int dccp_feat_default_send_ndp_count = DCCPF_INITIAL_SEND_NDP_COUNT;
31 .dccpo_send_ndp_count = DCCPF_INITIAL_SEND_NDP_COUNT,
32};
33 32
34void dccp_options_init(struct dccp_options *dccpo) 33void dccp_minisock_init(struct dccp_minisock *dmsk)
35{ 34{
36 memcpy(dccpo, &dccpo_default_values, sizeof(*dccpo)); 35 dmsk->dccpms_sequence_window = dccp_feat_default_sequence_window;
36 dmsk->dccpms_rx_ccid = dccp_feat_default_rx_ccid;
37 dmsk->dccpms_tx_ccid = dccp_feat_default_tx_ccid;
38 dmsk->dccpms_ack_ratio = dccp_feat_default_ack_ratio;
39 dmsk->dccpms_send_ack_vector = dccp_feat_default_send_ack_vector;
40 dmsk->dccpms_send_ndp_count = dccp_feat_default_send_ndp_count;
37} 41}
38 42
39static u32 dccp_decode_value_var(const unsigned char *bf, const u8 len) 43static u32 dccp_decode_value_var(const unsigned char *bf, const u8 len)
@@ -69,9 +73,12 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
69 unsigned char opt, len; 73 unsigned char opt, len;
70 unsigned char *value; 74 unsigned char *value;
71 u32 elapsed_time; 75 u32 elapsed_time;
76 int rc;
77 int mandatory = 0;
72 78
73 memset(opt_recv, 0, sizeof(*opt_recv)); 79 memset(opt_recv, 0, sizeof(*opt_recv));
74 80
81 opt = len = 0;
75 while (opt_ptr != opt_end) { 82 while (opt_ptr != opt_end) {
76 opt = *opt_ptr++; 83 opt = *opt_ptr++;
77 len = 0; 84 len = 0;
@@ -100,6 +107,12 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
100 switch (opt) { 107 switch (opt) {
101 case DCCPO_PADDING: 108 case DCCPO_PADDING:
102 break; 109 break;
110 case DCCPO_MANDATORY:
111 if (mandatory)
112 goto out_invalid_option;
113 if (pkt_type != DCCP_PKT_DATA)
114 mandatory = 1;
115 break;
103 case DCCPO_NDP_COUNT: 116 case DCCPO_NDP_COUNT:
104 if (len > 3) 117 if (len > 3)
105 goto out_invalid_option; 118 goto out_invalid_option;
@@ -108,12 +121,37 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
108 dccp_pr_debug("%sNDP count=%d\n", debug_prefix, 121 dccp_pr_debug("%sNDP count=%d\n", debug_prefix,
109 opt_recv->dccpor_ndp); 122 opt_recv->dccpor_ndp);
110 break; 123 break;
124 case DCCPO_CHANGE_L:
125 /* fall through */
126 case DCCPO_CHANGE_R:
127 if (len < 2)
128 goto out_invalid_option;
129 rc = dccp_feat_change_recv(sk, opt, *value, value + 1,
130 len - 1);
131 /*
132 * When there is a change error, change_recv is
133 * responsible for dealing with it. i.e. reply with an
134 * empty confirm.
135 * If the change was mandatory, then we need to die.
136 */
137 if (rc && mandatory)
138 goto out_invalid_option;
139 break;
140 case DCCPO_CONFIRM_L:
141 /* fall through */
142 case DCCPO_CONFIRM_R:
143 if (len < 2)
144 goto out_invalid_option;
145 if (dccp_feat_confirm_recv(sk, opt, *value,
146 value + 1, len - 1))
147 goto out_invalid_option;
148 break;
111 case DCCPO_ACK_VECTOR_0: 149 case DCCPO_ACK_VECTOR_0:
112 case DCCPO_ACK_VECTOR_1: 150 case DCCPO_ACK_VECTOR_1:
113 if (pkt_type == DCCP_PKT_DATA) 151 if (pkt_type == DCCP_PKT_DATA)
114 continue; 152 break;
115 153
116 if (dp->dccps_options.dccpo_send_ack_vector && 154 if (dccp_msk(sk)->dccpms_send_ack_vector &&
117 dccp_ackvec_parse(sk, skb, opt, value, len)) 155 dccp_ackvec_parse(sk, skb, opt, value, len))
118 goto out_invalid_option; 156 goto out_invalid_option;
119 break; 157 break;
@@ -121,7 +159,7 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
121 if (len != 4) 159 if (len != 4)
122 goto out_invalid_option; 160 goto out_invalid_option;
123 161
124 opt_recv->dccpor_timestamp = ntohl(*(u32 *)value); 162 opt_recv->dccpor_timestamp = ntohl(*(__be32 *)value);
125 163
126 dp->dccps_timestamp_echo = opt_recv->dccpor_timestamp; 164 dp->dccps_timestamp_echo = opt_recv->dccpor_timestamp;
127 dccp_timestamp(sk, &dp->dccps_timestamp_time); 165 dccp_timestamp(sk, &dp->dccps_timestamp_time);
@@ -135,7 +173,7 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
135 if (len != 4 && len != 6 && len != 8) 173 if (len != 4 && len != 6 && len != 8)
136 goto out_invalid_option; 174 goto out_invalid_option;
137 175
138 opt_recv->dccpor_timestamp_echo = ntohl(*(u32 *)value); 176 opt_recv->dccpor_timestamp_echo = ntohl(*(__be32 *)value);
139 177
140 dccp_pr_debug("%sTIMESTAMP_ECHO=%u, len=%d, ackno=%llu, ", 178 dccp_pr_debug("%sTIMESTAMP_ECHO=%u, len=%d, ackno=%llu, ",
141 debug_prefix, 179 debug_prefix,
@@ -149,9 +187,9 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
149 break; 187 break;
150 188
151 if (len == 6) 189 if (len == 6)
152 elapsed_time = ntohs(*(u16 *)(value + 4)); 190 elapsed_time = ntohs(*(__be16 *)(value + 4));
153 else 191 else
154 elapsed_time = ntohl(*(u32 *)(value + 4)); 192 elapsed_time = ntohl(*(__be32 *)(value + 4));
155 193
156 /* Give precedence to the biggest ELAPSED_TIME */ 194 /* Give precedence to the biggest ELAPSED_TIME */
157 if (elapsed_time > opt_recv->dccpor_elapsed_time) 195 if (elapsed_time > opt_recv->dccpor_elapsed_time)
@@ -165,9 +203,9 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
165 continue; 203 continue;
166 204
167 if (len == 2) 205 if (len == 2)
168 elapsed_time = ntohs(*(u16 *)value); 206 elapsed_time = ntohs(*(__be16 *)value);
169 else 207 else
170 elapsed_time = ntohl(*(u32 *)value); 208 elapsed_time = ntohl(*(__be32 *)value);
171 209
172 if (elapsed_time > opt_recv->dccpor_elapsed_time) 210 if (elapsed_time > opt_recv->dccpor_elapsed_time)
173 opt_recv->dccpor_elapsed_time = elapsed_time; 211 opt_recv->dccpor_elapsed_time = elapsed_time;
@@ -208,8 +246,15 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
208 sk, opt, len); 246 sk, opt, len);
209 break; 247 break;
210 } 248 }
249
250 if (opt != DCCPO_MANDATORY)
251 mandatory = 0;
211 } 252 }
212 253
254 /* mandatory was the last byte in option list -> reset connection */
255 if (mandatory)
256 goto out_invalid_option;
257
213 return 0; 258 return 0;
214 259
215out_invalid_option: 260out_invalid_option:
@@ -219,6 +264,8 @@ out_invalid_option:
219 return -1; 264 return -1;
220} 265}
221 266
267EXPORT_SYMBOL_GPL(dccp_parse_options);
268
222static void dccp_encode_value_var(const u32 value, unsigned char *to, 269static void dccp_encode_value_var(const u32 value, unsigned char *to,
223 const unsigned int len) 270 const unsigned int len)
224{ 271{
@@ -237,17 +284,14 @@ static inline int dccp_ndp_len(const int ndp)
237 return likely(ndp <= 0xFF) ? 1 : ndp <= 0xFFFF ? 2 : 3; 284 return likely(ndp <= 0xFF) ? 1 : ndp <= 0xFFFF ? 2 : 3;
238} 285}
239 286
240void dccp_insert_option(struct sock *sk, struct sk_buff *skb, 287int dccp_insert_option(struct sock *sk, struct sk_buff *skb,
241 const unsigned char option, 288 const unsigned char option,
242 const void *value, const unsigned char len) 289 const void *value, const unsigned char len)
243{ 290{
244 unsigned char *to; 291 unsigned char *to;
245 292
246 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len + 2 > DCCP_MAX_OPT_LEN) { 293 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len + 2 > DCCP_MAX_OPT_LEN)
247 LIMIT_NETDEBUG(KERN_INFO "DCCP: packet too small to insert " 294 return -1;
248 "%d option!\n", option);
249 return;
250 }
251 295
252 DCCP_SKB_CB(skb)->dccpd_opt_len += len + 2; 296 DCCP_SKB_CB(skb)->dccpd_opt_len += len + 2;
253 297
@@ -256,11 +300,12 @@ void dccp_insert_option(struct sock *sk, struct sk_buff *skb,
256 *to++ = len + 2; 300 *to++ = len + 2;
257 301
258 memcpy(to, value, len); 302 memcpy(to, value, len);
303 return 0;
259} 304}
260 305
261EXPORT_SYMBOL_GPL(dccp_insert_option); 306EXPORT_SYMBOL_GPL(dccp_insert_option);
262 307
263static void dccp_insert_option_ndp(struct sock *sk, struct sk_buff *skb) 308static int dccp_insert_option_ndp(struct sock *sk, struct sk_buff *skb)
264{ 309{
265 struct dccp_sock *dp = dccp_sk(sk); 310 struct dccp_sock *dp = dccp_sk(sk);
266 int ndp = dp->dccps_ndp_count; 311 int ndp = dp->dccps_ndp_count;
@@ -276,7 +321,7 @@ static void dccp_insert_option_ndp(struct sock *sk, struct sk_buff *skb)
276 const int len = ndp_len + 2; 321 const int len = ndp_len + 2;
277 322
278 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN) 323 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN)
279 return; 324 return -1;
280 325
281 DCCP_SKB_CB(skb)->dccpd_opt_len += len; 326 DCCP_SKB_CB(skb)->dccpd_opt_len += len;
282 327
@@ -285,6 +330,8 @@ static void dccp_insert_option_ndp(struct sock *sk, struct sk_buff *skb)
285 *ptr++ = len; 330 *ptr++ = len;
286 dccp_encode_value_var(ndp, ptr, ndp_len); 331 dccp_encode_value_var(ndp, ptr, ndp_len);
287 } 332 }
333
334 return 0;
288} 335}
289 336
290static inline int dccp_elapsed_time_len(const u32 elapsed_time) 337static inline int dccp_elapsed_time_len(const u32 elapsed_time)
@@ -292,27 +339,18 @@ static inline int dccp_elapsed_time_len(const u32 elapsed_time)
292 return elapsed_time == 0 ? 0 : elapsed_time <= 0xFFFF ? 2 : 4; 339 return elapsed_time == 0 ? 0 : elapsed_time <= 0xFFFF ? 2 : 4;
293} 340}
294 341
295void dccp_insert_option_elapsed_time(struct sock *sk, 342int dccp_insert_option_elapsed_time(struct sock *sk, struct sk_buff *skb,
296 struct sk_buff *skb, 343 u32 elapsed_time)
297 u32 elapsed_time)
298{ 344{
299#ifdef CONFIG_IP_DCCP_DEBUG
300 struct dccp_sock *dp = dccp_sk(sk);
301 const char *debug_prefix = dp->dccps_role == DCCP_ROLE_CLIENT ?
302 "CLIENT TX opt: " : "server TX opt: ";
303#endif
304 const int elapsed_time_len = dccp_elapsed_time_len(elapsed_time); 345 const int elapsed_time_len = dccp_elapsed_time_len(elapsed_time);
305 const int len = 2 + elapsed_time_len; 346 const int len = 2 + elapsed_time_len;
306 unsigned char *to; 347 unsigned char *to;
307 348
308 if (elapsed_time_len == 0) 349 if (elapsed_time_len == 0)
309 return; 350 return 0;
310 351
311 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN) { 352 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN)
312 LIMIT_NETDEBUG(KERN_INFO "DCCP: packet too small to " 353 return -1;
313 "insert elapsed time!\n");
314 return;
315 }
316 354
317 DCCP_SKB_CB(skb)->dccpd_opt_len += len; 355 DCCP_SKB_CB(skb)->dccpd_opt_len += len;
318 356
@@ -321,17 +359,14 @@ void dccp_insert_option_elapsed_time(struct sock *sk,
321 *to++ = len; 359 *to++ = len;
322 360
323 if (elapsed_time_len == 2) { 361 if (elapsed_time_len == 2) {
324 const u16 var16 = htons((u16)elapsed_time); 362 const __be16 var16 = htons((u16)elapsed_time);
325 memcpy(to, &var16, 2); 363 memcpy(to, &var16, 2);
326 } else { 364 } else {
327 const u32 var32 = htonl(elapsed_time); 365 const __be32 var32 = htonl(elapsed_time);
328 memcpy(to, &var32, 4); 366 memcpy(to, &var32, 4);
329 } 367 }
330 368
331 dccp_pr_debug("%sELAPSED_TIME=%u, len=%d, seqno=%llu\n", 369 return 0;
332 debug_prefix, elapsed_time,
333 len,
334 (unsigned long long) DCCP_SKB_CB(skb)->dccpd_seq);
335} 370}
336 371
337EXPORT_SYMBOL_GPL(dccp_insert_option_elapsed_time); 372EXPORT_SYMBOL_GPL(dccp_insert_option_elapsed_time);
@@ -352,32 +387,27 @@ void dccp_timestamp(const struct sock *sk, struct timeval *tv)
352 387
353EXPORT_SYMBOL_GPL(dccp_timestamp); 388EXPORT_SYMBOL_GPL(dccp_timestamp);
354 389
355void dccp_insert_option_timestamp(struct sock *sk, struct sk_buff *skb) 390int dccp_insert_option_timestamp(struct sock *sk, struct sk_buff *skb)
356{ 391{
357 struct timeval tv; 392 struct timeval tv;
358 u32 now; 393 __be32 now;
359 394
360 dccp_timestamp(sk, &tv); 395 dccp_timestamp(sk, &tv);
361 now = timeval_usecs(&tv) / 10; 396 now = htonl(timeval_usecs(&tv) / 10);
362 /* yes this will overflow but that is the point as we want a 397 /* yes this will overflow but that is the point as we want a
363 * 10 usec 32 bit timer which mean it wraps every 11.9 hours */ 398 * 10 usec 32 bit timer which mean it wraps every 11.9 hours */
364 399
365 now = htonl(now); 400 return dccp_insert_option(sk, skb, DCCPO_TIMESTAMP, &now, sizeof(now));
366 dccp_insert_option(sk, skb, DCCPO_TIMESTAMP, &now, sizeof(now));
367} 401}
368 402
369EXPORT_SYMBOL_GPL(dccp_insert_option_timestamp); 403EXPORT_SYMBOL_GPL(dccp_insert_option_timestamp);
370 404
371static void dccp_insert_option_timestamp_echo(struct sock *sk, 405static int dccp_insert_option_timestamp_echo(struct sock *sk,
372 struct sk_buff *skb) 406 struct sk_buff *skb)
373{ 407{
374 struct dccp_sock *dp = dccp_sk(sk); 408 struct dccp_sock *dp = dccp_sk(sk);
375#ifdef CONFIG_IP_DCCP_DEBUG
376 const char *debug_prefix = dp->dccps_role == DCCP_ROLE_CLIENT ?
377 "CLIENT TX opt: " : "server TX opt: ";
378#endif
379 struct timeval now; 409 struct timeval now;
380 u32 tstamp_echo; 410 __be32 tstamp_echo;
381 u32 elapsed_time; 411 u32 elapsed_time;
382 int len, elapsed_time_len; 412 int len, elapsed_time_len;
383 unsigned char *to; 413 unsigned char *to;
@@ -387,11 +417,8 @@ static void dccp_insert_option_timestamp_echo(struct sock *sk,
387 elapsed_time_len = dccp_elapsed_time_len(elapsed_time); 417 elapsed_time_len = dccp_elapsed_time_len(elapsed_time);
388 len = 6 + elapsed_time_len; 418 len = 6 + elapsed_time_len;
389 419
390 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN) { 420 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN)
391 LIMIT_NETDEBUG(KERN_INFO "DCCP: packet too small to insert " 421 return -1;
392 "timestamp echo!\n");
393 return;
394 }
395 422
396 DCCP_SKB_CB(skb)->dccpd_opt_len += len; 423 DCCP_SKB_CB(skb)->dccpd_opt_len += len;
397 424
@@ -402,51 +429,149 @@ static void dccp_insert_option_timestamp_echo(struct sock *sk,
402 tstamp_echo = htonl(dp->dccps_timestamp_echo); 429 tstamp_echo = htonl(dp->dccps_timestamp_echo);
403 memcpy(to, &tstamp_echo, 4); 430 memcpy(to, &tstamp_echo, 4);
404 to += 4; 431 to += 4;
405 432
406 if (elapsed_time_len == 2) { 433 if (elapsed_time_len == 2) {
407 const u16 var16 = htons((u16)elapsed_time); 434 const __be16 var16 = htons((u16)elapsed_time);
408 memcpy(to, &var16, 2); 435 memcpy(to, &var16, 2);
409 } else if (elapsed_time_len == 4) { 436 } else if (elapsed_time_len == 4) {
410 const u32 var32 = htonl(elapsed_time); 437 const __be32 var32 = htonl(elapsed_time);
411 memcpy(to, &var32, 4); 438 memcpy(to, &var32, 4);
412 } 439 }
413 440
414 dccp_pr_debug("%sTIMESTAMP_ECHO=%u, len=%d, seqno=%llu\n",
415 debug_prefix, dp->dccps_timestamp_echo,
416 len,
417 (unsigned long long) DCCP_SKB_CB(skb)->dccpd_seq);
418
419 dp->dccps_timestamp_echo = 0; 441 dp->dccps_timestamp_echo = 0;
420 dp->dccps_timestamp_time.tv_sec = 0; 442 dp->dccps_timestamp_time.tv_sec = 0;
421 dp->dccps_timestamp_time.tv_usec = 0; 443 dp->dccps_timestamp_time.tv_usec = 0;
444 return 0;
422} 445}
423 446
424void dccp_insert_options(struct sock *sk, struct sk_buff *skb) 447static int dccp_insert_feat_opt(struct sk_buff *skb, u8 type, u8 feat,
448 u8 *val, u8 len)
449{
450 u8 *to;
451
452 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len + 3 > DCCP_MAX_OPT_LEN) {
453 LIMIT_NETDEBUG(KERN_INFO "DCCP: packet too small"
454 " to insert feature %d option!\n", feat);
455 return -1;
456 }
457
458 DCCP_SKB_CB(skb)->dccpd_opt_len += len + 3;
459
460 to = skb_push(skb, len + 3);
461 *to++ = type;
462 *to++ = len + 3;
463 *to++ = feat;
464
465 if (len)
466 memcpy(to, val, len);
467 dccp_pr_debug("option %d feat %d len %d\n", type, feat, len);
468
469 return 0;
470}
471
472static int dccp_insert_options_feat(struct sock *sk, struct sk_buff *skb)
425{ 473{
426 struct dccp_sock *dp = dccp_sk(sk); 474 struct dccp_sock *dp = dccp_sk(sk);
475 struct dccp_minisock *dmsk = dccp_msk(sk);
476 struct dccp_opt_pend *opt, *next;
477 int change = 0;
478
479 /* confirm any options [NN opts] */
480 list_for_each_entry_safe(opt, next, &dmsk->dccpms_conf, dccpop_node) {
481 dccp_insert_feat_opt(skb, opt->dccpop_type,
482 opt->dccpop_feat, opt->dccpop_val,
483 opt->dccpop_len);
484 /* fear empty confirms */
485 if (opt->dccpop_val)
486 kfree(opt->dccpop_val);
487 kfree(opt);
488 }
489 INIT_LIST_HEAD(&dmsk->dccpms_conf);
490
491 /* see which features we need to send */
492 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
493 /* see if we need to send any confirm */
494 if (opt->dccpop_sc) {
495 dccp_insert_feat_opt(skb, opt->dccpop_type + 1,
496 opt->dccpop_feat,
497 opt->dccpop_sc->dccpoc_val,
498 opt->dccpop_sc->dccpoc_len);
499
500 BUG_ON(!opt->dccpop_sc->dccpoc_val);
501 kfree(opt->dccpop_sc->dccpoc_val);
502 kfree(opt->dccpop_sc);
503 opt->dccpop_sc = NULL;
504 }
505
506 /* any option not confirmed, re-send it */
507 if (!opt->dccpop_conf) {
508 dccp_insert_feat_opt(skb, opt->dccpop_type,
509 opt->dccpop_feat, opt->dccpop_val,
510 opt->dccpop_len);
511 change++;
512 }
513 }
514
515 /* Retransmit timer.
516 * If this is the master listening sock, we don't set a timer on it. It
517 * should be fine because if the dude doesn't receive our RESPONSE
518 * [which will contain the CHANGE] he will send another REQUEST which
519 * will "retrnasmit" the change.
520 */
521 if (change && dp->dccps_role != DCCP_ROLE_LISTEN) {
522 dccp_pr_debug("reset feat negotiation timer %p\n", sk);
523
524 /* XXX don't reset the timer on re-transmissions. I.e. reset it
525 * only when sending new stuff i guess. Currently the timer
526 * never backs off because on re-transmission it just resets it!
527 */
528 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
529 inet_csk(sk)->icsk_rto, DCCP_RTO_MAX);
530 }
531
532 return 0;
533}
534
535int dccp_insert_options(struct sock *sk, struct sk_buff *skb)
536{
537 struct dccp_sock *dp = dccp_sk(sk);
538 struct dccp_minisock *dmsk = dccp_msk(sk);
427 539
428 DCCP_SKB_CB(skb)->dccpd_opt_len = 0; 540 DCCP_SKB_CB(skb)->dccpd_opt_len = 0;
429 541
430 if (dp->dccps_options.dccpo_send_ndp_count) 542 if (dmsk->dccpms_send_ndp_count &&
431 dccp_insert_option_ndp(sk, skb); 543 dccp_insert_option_ndp(sk, skb))
544 return -1;
432 545
433 if (!dccp_packet_without_ack(skb)) { 546 if (!dccp_packet_without_ack(skb)) {
434 if (dp->dccps_options.dccpo_send_ack_vector && 547 if (dmsk->dccpms_send_ack_vector &&
435 dccp_ackvec_pending(dp->dccps_hc_rx_ackvec)) 548 dccp_ackvec_pending(dp->dccps_hc_rx_ackvec) &&
436 dccp_insert_option_ackvec(sk, skb); 549 dccp_insert_option_ackvec(sk, skb))
437 if (dp->dccps_timestamp_echo != 0) 550 return -1;
438 dccp_insert_option_timestamp_echo(sk, skb); 551
552 if (dp->dccps_timestamp_echo != 0 &&
553 dccp_insert_option_timestamp_echo(sk, skb))
554 return -1;
439 } 555 }
440 556
441 if (dp->dccps_hc_rx_insert_options) { 557 if (dp->dccps_hc_rx_insert_options) {
442 ccid_hc_rx_insert_options(dp->dccps_hc_rx_ccid, sk, skb); 558 if (ccid_hc_rx_insert_options(dp->dccps_hc_rx_ccid, sk, skb))
559 return -1;
443 dp->dccps_hc_rx_insert_options = 0; 560 dp->dccps_hc_rx_insert_options = 0;
444 } 561 }
445 if (dp->dccps_hc_tx_insert_options) { 562 if (dp->dccps_hc_tx_insert_options) {
446 ccid_hc_tx_insert_options(dp->dccps_hc_tx_ccid, sk, skb); 563 if (ccid_hc_tx_insert_options(dp->dccps_hc_tx_ccid, sk, skb))
564 return -1;
447 dp->dccps_hc_tx_insert_options = 0; 565 dp->dccps_hc_tx_insert_options = 0;
448 } 566 }
449 567
568 /* Feature negotiation */
569 /* Data packets can't do feat negotiation */
570 if (DCCP_SKB_CB(skb)->dccpd_type != DCCP_PKT_DATA &&
571 DCCP_SKB_CB(skb)->dccpd_type != DCCP_PKT_DATAACK &&
572 dccp_insert_options_feat(sk, skb))
573 return -1;
574
450 /* XXX: insert other options when appropriate */ 575 /* XXX: insert other options when appropriate */
451 576
452 if (DCCP_SKB_CB(skb)->dccpd_opt_len != 0) { 577 if (DCCP_SKB_CB(skb)->dccpd_opt_len != 0) {
@@ -459,4 +584,6 @@ void dccp_insert_options(struct sock *sk, struct sk_buff *skb)
459 DCCP_SKB_CB(skb)->dccpd_opt_len += padding; 584 DCCP_SKB_CB(skb)->dccpd_opt_len += padding;
460 } 585 }
461 } 586 }
587
588 return 0;
462} 589}
diff --git a/net/dccp/output.c b/net/dccp/output.c
index efd7ffb903a1..7409e4a3abdf 100644
--- a/net/dccp/output.c
+++ b/net/dccp/output.c
@@ -27,7 +27,7 @@ static inline void dccp_event_ack_sent(struct sock *sk)
27 inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK); 27 inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
28} 28}
29 29
30static inline void dccp_skb_entail(struct sock *sk, struct sk_buff *skb) 30static void dccp_skb_entail(struct sock *sk, struct sk_buff *skb)
31{ 31{
32 skb_set_owner_w(skb, sk); 32 skb_set_owner_w(skb, sk);
33 WARN_ON(sk->sk_send_head); 33 WARN_ON(sk->sk_send_head);
@@ -49,7 +49,7 @@ static int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb)
49 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); 49 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
50 struct dccp_hdr *dh; 50 struct dccp_hdr *dh;
51 /* XXX For now we're using only 48 bits sequence numbers */ 51 /* XXX For now we're using only 48 bits sequence numbers */
52 const int dccp_header_size = sizeof(*dh) + 52 const u32 dccp_header_size = sizeof(*dh) +
53 sizeof(struct dccp_hdr_ext) + 53 sizeof(struct dccp_hdr_ext) +
54 dccp_packet_hdr_len(dcb->dccpd_type); 54 dccp_packet_hdr_len(dcb->dccpd_type);
55 int err, set_ack = 1; 55 int err, set_ack = 1;
@@ -64,6 +64,10 @@ static int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb)
64 case DCCP_PKT_DATAACK: 64 case DCCP_PKT_DATAACK:
65 break; 65 break;
66 66
67 case DCCP_PKT_REQUEST:
68 set_ack = 0;
69 /* fall through */
70
67 case DCCP_PKT_SYNC: 71 case DCCP_PKT_SYNC:
68 case DCCP_PKT_SYNCACK: 72 case DCCP_PKT_SYNCACK:
69 ackno = dcb->dccpd_seq; 73 ackno = dcb->dccpd_seq;
@@ -79,7 +83,11 @@ static int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb)
79 } 83 }
80 84
81 dcb->dccpd_seq = dp->dccps_gss; 85 dcb->dccpd_seq = dp->dccps_gss;
82 dccp_insert_options(sk, skb); 86
87 if (dccp_insert_options(sk, skb)) {
88 kfree_skb(skb);
89 return -EPROTO;
90 }
83 91
84 skb->h.raw = skb_push(skb, dccp_header_size); 92 skb->h.raw = skb_push(skb, dccp_header_size);
85 dh = dccp_hdr(skb); 93 dh = dccp_hdr(skb);
@@ -275,17 +283,16 @@ struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst,
275{ 283{
276 struct dccp_hdr *dh; 284 struct dccp_hdr *dh;
277 struct dccp_request_sock *dreq; 285 struct dccp_request_sock *dreq;
278 const int dccp_header_size = sizeof(struct dccp_hdr) + 286 const u32 dccp_header_size = sizeof(struct dccp_hdr) +
279 sizeof(struct dccp_hdr_ext) + 287 sizeof(struct dccp_hdr_ext) +
280 sizeof(struct dccp_hdr_response); 288 sizeof(struct dccp_hdr_response);
281 struct sk_buff *skb = sock_wmalloc(sk, MAX_HEADER + DCCP_MAX_OPT_LEN + 289 struct sk_buff *skb = sock_wmalloc(sk, sk->sk_prot->max_header, 1,
282 dccp_header_size, 1,
283 GFP_ATOMIC); 290 GFP_ATOMIC);
284 if (skb == NULL) 291 if (skb == NULL)
285 return NULL; 292 return NULL;
286 293
287 /* Reserve space for headers. */ 294 /* Reserve space for headers. */
288 skb_reserve(skb, MAX_HEADER + DCCP_MAX_OPT_LEN + dccp_header_size); 295 skb_reserve(skb, sk->sk_prot->max_header);
289 296
290 skb->dst = dst_clone(dst); 297 skb->dst = dst_clone(dst);
291 skb->csum = 0; 298 skb->csum = 0;
@@ -293,7 +300,11 @@ struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst,
293 dreq = dccp_rsk(req); 300 dreq = dccp_rsk(req);
294 DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_RESPONSE; 301 DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_RESPONSE;
295 DCCP_SKB_CB(skb)->dccpd_seq = dreq->dreq_iss; 302 DCCP_SKB_CB(skb)->dccpd_seq = dreq->dreq_iss;
296 dccp_insert_options(sk, skb); 303
304 if (dccp_insert_options(sk, skb)) {
305 kfree_skb(skb);
306 return NULL;
307 }
297 308
298 skb->h.raw = skb_push(skb, dccp_header_size); 309 skb->h.raw = skb_push(skb, dccp_header_size);
299 310
@@ -310,32 +321,28 @@ struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst,
310 dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), dreq->dreq_isr); 321 dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), dreq->dreq_isr);
311 dccp_hdr_response(skb)->dccph_resp_service = dreq->dreq_service; 322 dccp_hdr_response(skb)->dccph_resp_service = dreq->dreq_service;
312 323
313 dh->dccph_checksum = dccp_v4_checksum(skb, inet_rsk(req)->loc_addr,
314 inet_rsk(req)->rmt_addr);
315
316 DCCP_INC_STATS(DCCP_MIB_OUTSEGS); 324 DCCP_INC_STATS(DCCP_MIB_OUTSEGS);
317 return skb; 325 return skb;
318} 326}
319 327
320EXPORT_SYMBOL_GPL(dccp_make_response); 328EXPORT_SYMBOL_GPL(dccp_make_response);
321 329
322struct sk_buff *dccp_make_reset(struct sock *sk, struct dst_entry *dst, 330static struct sk_buff *dccp_make_reset(struct sock *sk, struct dst_entry *dst,
323 const enum dccp_reset_codes code) 331 const enum dccp_reset_codes code)
324 332
325{ 333{
326 struct dccp_hdr *dh; 334 struct dccp_hdr *dh;
327 struct dccp_sock *dp = dccp_sk(sk); 335 struct dccp_sock *dp = dccp_sk(sk);
328 const int dccp_header_size = sizeof(struct dccp_hdr) + 336 const u32 dccp_header_size = sizeof(struct dccp_hdr) +
329 sizeof(struct dccp_hdr_ext) + 337 sizeof(struct dccp_hdr_ext) +
330 sizeof(struct dccp_hdr_reset); 338 sizeof(struct dccp_hdr_reset);
331 struct sk_buff *skb = sock_wmalloc(sk, MAX_HEADER + DCCP_MAX_OPT_LEN + 339 struct sk_buff *skb = sock_wmalloc(sk, sk->sk_prot->max_header, 1,
332 dccp_header_size, 1,
333 GFP_ATOMIC); 340 GFP_ATOMIC);
334 if (skb == NULL) 341 if (skb == NULL)
335 return NULL; 342 return NULL;
336 343
337 /* Reserve space for headers. */ 344 /* Reserve space for headers. */
338 skb_reserve(skb, MAX_HEADER + DCCP_MAX_OPT_LEN + dccp_header_size); 345 skb_reserve(skb, sk->sk_prot->max_header);
339 346
340 skb->dst = dst_clone(dst); 347 skb->dst = dst_clone(dst);
341 skb->csum = 0; 348 skb->csum = 0;
@@ -345,7 +352,11 @@ struct sk_buff *dccp_make_reset(struct sock *sk, struct dst_entry *dst,
345 DCCP_SKB_CB(skb)->dccpd_reset_code = code; 352 DCCP_SKB_CB(skb)->dccpd_reset_code = code;
346 DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_RESET; 353 DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_RESET;
347 DCCP_SKB_CB(skb)->dccpd_seq = dp->dccps_gss; 354 DCCP_SKB_CB(skb)->dccpd_seq = dp->dccps_gss;
348 dccp_insert_options(sk, skb); 355
356 if (dccp_insert_options(sk, skb)) {
357 kfree_skb(skb);
358 return NULL;
359 }
349 360
350 skb->h.raw = skb_push(skb, dccp_header_size); 361 skb->h.raw = skb_push(skb, dccp_header_size);
351 362
@@ -362,14 +373,34 @@ struct sk_buff *dccp_make_reset(struct sock *sk, struct dst_entry *dst,
362 dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), dp->dccps_gsr); 373 dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), dp->dccps_gsr);
363 374
364 dccp_hdr_reset(skb)->dccph_reset_code = code; 375 dccp_hdr_reset(skb)->dccph_reset_code = code;
365 376 inet_csk(sk)->icsk_af_ops->send_check(sk, skb->len, skb);
366 dh->dccph_checksum = dccp_v4_checksum(skb, inet_sk(sk)->saddr,
367 inet_sk(sk)->daddr);
368 377
369 DCCP_INC_STATS(DCCP_MIB_OUTSEGS); 378 DCCP_INC_STATS(DCCP_MIB_OUTSEGS);
370 return skb; 379 return skb;
371} 380}
372 381
382int dccp_send_reset(struct sock *sk, enum dccp_reset_codes code)
383{
384 /*
385 * FIXME: what if rebuild_header fails?
386 * Should we be doing a rebuild_header here?
387 */
388 int err = inet_sk_rebuild_header(sk);
389
390 if (err == 0) {
391 struct sk_buff *skb = dccp_make_reset(sk, sk->sk_dst_cache,
392 code);
393 if (skb != NULL) {
394 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
395 err = inet_csk(sk)->icsk_af_ops->queue_xmit(skb, 0);
396 if (err == NET_XMIT_CN)
397 err = 0;
398 }
399 }
400
401 return err;
402}
403
373/* 404/*
374 * Do all connect socket setups that can be done AF independent. 405 * Do all connect socket setups that can be done AF independent.
375 */ 406 */
@@ -405,12 +436,12 @@ int dccp_connect(struct sock *sk)
405 436
406 dccp_connect_init(sk); 437 dccp_connect_init(sk);
407 438
408 skb = alloc_skb(MAX_DCCP_HEADER + 15, sk->sk_allocation); 439 skb = alloc_skb(sk->sk_prot->max_header, sk->sk_allocation);
409 if (unlikely(skb == NULL)) 440 if (unlikely(skb == NULL))
410 return -ENOBUFS; 441 return -ENOBUFS;
411 442
412 /* Reserve space for headers. */ 443 /* Reserve space for headers. */
413 skb_reserve(skb, MAX_DCCP_HEADER); 444 skb_reserve(skb, sk->sk_prot->max_header);
414 445
415 DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_REQUEST; 446 DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_REQUEST;
416 skb->csum = 0; 447 skb->csum = 0;
@@ -431,7 +462,8 @@ void dccp_send_ack(struct sock *sk)
431{ 462{
432 /* If we have been reset, we may not send again. */ 463 /* If we have been reset, we may not send again. */
433 if (sk->sk_state != DCCP_CLOSED) { 464 if (sk->sk_state != DCCP_CLOSED) {
434 struct sk_buff *skb = alloc_skb(MAX_DCCP_HEADER, GFP_ATOMIC); 465 struct sk_buff *skb = alloc_skb(sk->sk_prot->max_header,
466 GFP_ATOMIC);
435 467
436 if (skb == NULL) { 468 if (skb == NULL) {
437 inet_csk_schedule_ack(sk); 469 inet_csk_schedule_ack(sk);
@@ -443,7 +475,7 @@ void dccp_send_ack(struct sock *sk)
443 } 475 }
444 476
445 /* Reserve space for headers */ 477 /* Reserve space for headers */
446 skb_reserve(skb, MAX_DCCP_HEADER); 478 skb_reserve(skb, sk->sk_prot->max_header);
447 skb->csum = 0; 479 skb->csum = 0;
448 DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_ACK; 480 DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_ACK;
449 dccp_transmit_skb(sk, skb); 481 dccp_transmit_skb(sk, skb);
@@ -490,14 +522,14 @@ void dccp_send_sync(struct sock *sk, const u64 seq,
490 * dccp_transmit_skb() will set the ownership to this 522 * dccp_transmit_skb() will set the ownership to this
491 * sock. 523 * sock.
492 */ 524 */
493 struct sk_buff *skb = alloc_skb(MAX_DCCP_HEADER, GFP_ATOMIC); 525 struct sk_buff *skb = alloc_skb(sk->sk_prot->max_header, GFP_ATOMIC);
494 526
495 if (skb == NULL) 527 if (skb == NULL)
496 /* FIXME: how to make sure the sync is sent? */ 528 /* FIXME: how to make sure the sync is sent? */
497 return; 529 return;
498 530
499 /* Reserve space for headers and prepare control bits. */ 531 /* Reserve space for headers and prepare control bits. */
500 skb_reserve(skb, MAX_DCCP_HEADER); 532 skb_reserve(skb, sk->sk_prot->max_header);
501 skb->csum = 0; 533 skb->csum = 0;
502 DCCP_SKB_CB(skb)->dccpd_type = pkt_type; 534 DCCP_SKB_CB(skb)->dccpd_type = pkt_type;
503 DCCP_SKB_CB(skb)->dccpd_seq = seq; 535 DCCP_SKB_CB(skb)->dccpd_seq = seq;
@@ -505,6 +537,8 @@ void dccp_send_sync(struct sock *sk, const u64 seq,
505 dccp_transmit_skb(sk, skb); 537 dccp_transmit_skb(sk, skb);
506} 538}
507 539
540EXPORT_SYMBOL_GPL(dccp_send_sync);
541
508/* 542/*
509 * Send a DCCP_PKT_CLOSE/CLOSEREQ. The caller locks the socket for us. This 543 * Send a DCCP_PKT_CLOSE/CLOSEREQ. The caller locks the socket for us. This
510 * cannot be allowed to fail queueing a DCCP_PKT_CLOSE/CLOSEREQ frame under 544 * cannot be allowed to fail queueing a DCCP_PKT_CLOSE/CLOSEREQ frame under
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index 65b11ea90d85..d4b293e16283 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -23,9 +23,7 @@
23#include <linux/random.h> 23#include <linux/random.h>
24#include <net/checksum.h> 24#include <net/checksum.h>
25 25
26#include <net/inet_common.h>
27#include <net/inet_sock.h> 26#include <net/inet_sock.h>
28#include <net/protocol.h>
29#include <net/sock.h> 27#include <net/sock.h>
30#include <net/xfrm.h> 28#include <net/xfrm.h>
31 29
@@ -37,6 +35,7 @@
37 35
38#include "ccid.h" 36#include "ccid.h"
39#include "dccp.h" 37#include "dccp.h"
38#include "feat.h"
40 39
41DEFINE_SNMP_STAT(struct dccp_mib, dccp_statistics) __read_mostly; 40DEFINE_SNMP_STAT(struct dccp_mib, dccp_statistics) __read_mostly;
42 41
@@ -46,12 +45,66 @@ atomic_t dccp_orphan_count = ATOMIC_INIT(0);
46 45
47EXPORT_SYMBOL_GPL(dccp_orphan_count); 46EXPORT_SYMBOL_GPL(dccp_orphan_count);
48 47
49static struct net_protocol dccp_protocol = { 48struct inet_hashinfo __cacheline_aligned dccp_hashinfo = {
50 .handler = dccp_v4_rcv, 49 .lhash_lock = RW_LOCK_UNLOCKED,
51 .err_handler = dccp_v4_err, 50 .lhash_users = ATOMIC_INIT(0),
52 .no_policy = 1, 51 .lhash_wait = __WAIT_QUEUE_HEAD_INITIALIZER(dccp_hashinfo.lhash_wait),
53}; 52};
54 53
54EXPORT_SYMBOL_GPL(dccp_hashinfo);
55
56void dccp_set_state(struct sock *sk, const int state)
57{
58 const int oldstate = sk->sk_state;
59
60 dccp_pr_debug("%s(%p) %-10.10s -> %s\n",
61 dccp_role(sk), sk,
62 dccp_state_name(oldstate), dccp_state_name(state));
63 WARN_ON(state == oldstate);
64
65 switch (state) {
66 case DCCP_OPEN:
67 if (oldstate != DCCP_OPEN)
68 DCCP_INC_STATS(DCCP_MIB_CURRESTAB);
69 break;
70
71 case DCCP_CLOSED:
72 if (oldstate == DCCP_CLOSING || oldstate == DCCP_OPEN)
73 DCCP_INC_STATS(DCCP_MIB_ESTABRESETS);
74
75 sk->sk_prot->unhash(sk);
76 if (inet_csk(sk)->icsk_bind_hash != NULL &&
77 !(sk->sk_userlocks & SOCK_BINDPORT_LOCK))
78 inet_put_port(&dccp_hashinfo, sk);
79 /* fall through */
80 default:
81 if (oldstate == DCCP_OPEN)
82 DCCP_DEC_STATS(DCCP_MIB_CURRESTAB);
83 }
84
85 /* Change state AFTER socket is unhashed to avoid closed
86 * socket sitting in hash tables.
87 */
88 sk->sk_state = state;
89}
90
91EXPORT_SYMBOL_GPL(dccp_set_state);
92
93void dccp_done(struct sock *sk)
94{
95 dccp_set_state(sk, DCCP_CLOSED);
96 dccp_clear_xmit_timers(sk);
97
98 sk->sk_shutdown = SHUTDOWN_MASK;
99
100 if (!sock_flag(sk, SOCK_DEAD))
101 sk->sk_state_change(sk);
102 else
103 inet_csk_destroy_sock(sk);
104}
105
106EXPORT_SYMBOL_GPL(dccp_done);
107
55const char *dccp_packet_name(const int type) 108const char *dccp_packet_name(const int type)
56{ 109{
57 static const char *dccp_packet_names[] = { 110 static const char *dccp_packet_names[] = {
@@ -96,6 +149,120 @@ const char *dccp_state_name(const int state)
96 149
97EXPORT_SYMBOL_GPL(dccp_state_name); 150EXPORT_SYMBOL_GPL(dccp_state_name);
98 151
152void dccp_hash(struct sock *sk)
153{
154 inet_hash(&dccp_hashinfo, sk);
155}
156
157EXPORT_SYMBOL_GPL(dccp_hash);
158
159void dccp_unhash(struct sock *sk)
160{
161 inet_unhash(&dccp_hashinfo, sk);
162}
163
164EXPORT_SYMBOL_GPL(dccp_unhash);
165
166int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized)
167{
168 struct dccp_sock *dp = dccp_sk(sk);
169 struct dccp_minisock *dmsk = dccp_msk(sk);
170 struct inet_connection_sock *icsk = inet_csk(sk);
171
172 dccp_minisock_init(&dp->dccps_minisock);
173 do_gettimeofday(&dp->dccps_epoch);
174
175 /*
176 * FIXME: We're hardcoding the CCID, and doing this at this point makes
177 * the listening (master) sock get CCID control blocks, which is not
178 * necessary, but for now, to not mess with the test userspace apps,
179 * lets leave it here, later the real solution is to do this in a
180 * setsockopt(CCIDs-I-want/accept). -acme
181 */
182 if (likely(ctl_sock_initialized)) {
183 int rc = dccp_feat_init(dmsk);
184
185 if (rc)
186 return rc;
187
188 if (dmsk->dccpms_send_ack_vector) {
189 dp->dccps_hc_rx_ackvec = dccp_ackvec_alloc(GFP_KERNEL);
190 if (dp->dccps_hc_rx_ackvec == NULL)
191 return -ENOMEM;
192 }
193 dp->dccps_hc_rx_ccid = ccid_hc_rx_new(dmsk->dccpms_rx_ccid,
194 sk, GFP_KERNEL);
195 dp->dccps_hc_tx_ccid = ccid_hc_tx_new(dmsk->dccpms_tx_ccid,
196 sk, GFP_KERNEL);
197 if (unlikely(dp->dccps_hc_rx_ccid == NULL ||
198 dp->dccps_hc_tx_ccid == NULL)) {
199 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
200 ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
201 if (dmsk->dccpms_send_ack_vector) {
202 dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
203 dp->dccps_hc_rx_ackvec = NULL;
204 }
205 dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL;
206 return -ENOMEM;
207 }
208 } else {
209 /* control socket doesn't need feat nego */
210 INIT_LIST_HEAD(&dmsk->dccpms_pending);
211 INIT_LIST_HEAD(&dmsk->dccpms_conf);
212 }
213
214 dccp_init_xmit_timers(sk);
215 icsk->icsk_rto = DCCP_TIMEOUT_INIT;
216 sk->sk_state = DCCP_CLOSED;
217 sk->sk_write_space = dccp_write_space;
218 icsk->icsk_sync_mss = dccp_sync_mss;
219 dp->dccps_mss_cache = 536;
220 dp->dccps_role = DCCP_ROLE_UNDEFINED;
221 dp->dccps_service = DCCP_SERVICE_INVALID_VALUE;
222 dp->dccps_l_ack_ratio = dp->dccps_r_ack_ratio = 1;
223
224 return 0;
225}
226
227EXPORT_SYMBOL_GPL(dccp_init_sock);
228
229int dccp_destroy_sock(struct sock *sk)
230{
231 struct dccp_sock *dp = dccp_sk(sk);
232 struct dccp_minisock *dmsk = dccp_msk(sk);
233
234 /*
235 * DCCP doesn't use sk_write_queue, just sk_send_head
236 * for retransmissions
237 */
238 if (sk->sk_send_head != NULL) {
239 kfree_skb(sk->sk_send_head);
240 sk->sk_send_head = NULL;
241 }
242
243 /* Clean up a referenced DCCP bind bucket. */
244 if (inet_csk(sk)->icsk_bind_hash != NULL)
245 inet_put_port(&dccp_hashinfo, sk);
246
247 kfree(dp->dccps_service_list);
248 dp->dccps_service_list = NULL;
249
250 if (dmsk->dccpms_send_ack_vector) {
251 dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
252 dp->dccps_hc_rx_ackvec = NULL;
253 }
254 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
255 ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
256 dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL;
257
258 /* clean up feature negotiation state */
259 dccp_feat_clean(dmsk);
260
261 return 0;
262}
263
264EXPORT_SYMBOL_GPL(dccp_destroy_sock);
265
99static inline int dccp_listen_start(struct sock *sk) 266static inline int dccp_listen_start(struct sock *sk)
100{ 267{
101 struct dccp_sock *dp = dccp_sk(sk); 268 struct dccp_sock *dp = dccp_sk(sk);
@@ -220,7 +387,7 @@ int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg)
220 387
221EXPORT_SYMBOL_GPL(dccp_ioctl); 388EXPORT_SYMBOL_GPL(dccp_ioctl);
222 389
223static int dccp_setsockopt_service(struct sock *sk, const u32 service, 390static int dccp_setsockopt_service(struct sock *sk, const __be32 service,
224 char __user *optval, int optlen) 391 char __user *optval, int optlen)
225{ 392{
226 struct dccp_sock *dp = dccp_sk(sk); 393 struct dccp_sock *dp = dccp_sk(sk);
@@ -255,18 +422,46 @@ static int dccp_setsockopt_service(struct sock *sk, const u32 service,
255 return 0; 422 return 0;
256} 423}
257 424
258int dccp_setsockopt(struct sock *sk, int level, int optname, 425/* byte 1 is feature. the rest is the preference list */
259 char __user *optval, int optlen) 426static int dccp_setsockopt_change(struct sock *sk, int type,
427 struct dccp_so_feat __user *optval)
428{
429 struct dccp_so_feat opt;
430 u8 *val;
431 int rc;
432
433 if (copy_from_user(&opt, optval, sizeof(opt)))
434 return -EFAULT;
435
436 val = kmalloc(opt.dccpsf_len, GFP_KERNEL);
437 if (!val)
438 return -ENOMEM;
439
440 if (copy_from_user(val, opt.dccpsf_val, opt.dccpsf_len)) {
441 rc = -EFAULT;
442 goto out_free_val;
443 }
444
445 rc = dccp_feat_change(dccp_msk(sk), type, opt.dccpsf_feat,
446 val, opt.dccpsf_len, GFP_KERNEL);
447 if (rc)
448 goto out_free_val;
449
450out:
451 return rc;
452
453out_free_val:
454 kfree(val);
455 goto out;
456}
457
458static int do_dccp_setsockopt(struct sock *sk, int level, int optname,
459 char __user *optval, int optlen)
260{ 460{
261 struct dccp_sock *dp; 461 struct dccp_sock *dp;
262 int err; 462 int err;
263 int val; 463 int val;
264 464
265 if (level != SOL_DCCP)
266 return inet_csk(sk)->icsk_af_ops->setsockopt(sk, level,
267 optname, optval,
268 optlen);
269
270 if (optlen < sizeof(int)) 465 if (optlen < sizeof(int))
271 return -EINVAL; 466 return -EINVAL;
272 467
@@ -284,6 +479,25 @@ int dccp_setsockopt(struct sock *sk, int level, int optname,
284 case DCCP_SOCKOPT_PACKET_SIZE: 479 case DCCP_SOCKOPT_PACKET_SIZE:
285 dp->dccps_packet_size = val; 480 dp->dccps_packet_size = val;
286 break; 481 break;
482
483 case DCCP_SOCKOPT_CHANGE_L:
484 if (optlen != sizeof(struct dccp_so_feat))
485 err = -EINVAL;
486 else
487 err = dccp_setsockopt_change(sk, DCCPO_CHANGE_L,
488 (struct dccp_so_feat *)
489 optval);
490 break;
491
492 case DCCP_SOCKOPT_CHANGE_R:
493 if (optlen != sizeof(struct dccp_so_feat))
494 err = -EINVAL;
495 else
496 err = dccp_setsockopt_change(sk, DCCPO_CHANGE_R,
497 (struct dccp_so_feat *)
498 optval);
499 break;
500
287 default: 501 default:
288 err = -ENOPROTOOPT; 502 err = -ENOPROTOOPT;
289 break; 503 break;
@@ -293,10 +507,33 @@ int dccp_setsockopt(struct sock *sk, int level, int optname,
293 return err; 507 return err;
294} 508}
295 509
510int dccp_setsockopt(struct sock *sk, int level, int optname,
511 char __user *optval, int optlen)
512{
513 if (level != SOL_DCCP)
514 return inet_csk(sk)->icsk_af_ops->setsockopt(sk, level,
515 optname, optval,
516 optlen);
517 return do_dccp_setsockopt(sk, level, optname, optval, optlen);
518}
519
296EXPORT_SYMBOL_GPL(dccp_setsockopt); 520EXPORT_SYMBOL_GPL(dccp_setsockopt);
297 521
522#ifdef CONFIG_COMPAT
523int compat_dccp_setsockopt(struct sock *sk, int level, int optname,
524 char __user *optval, int optlen)
525{
526 if (level != SOL_DCCP)
527 return inet_csk_compat_setsockopt(sk, level, optname,
528 optval, optlen);
529 return do_dccp_setsockopt(sk, level, optname, optval, optlen);
530}
531
532EXPORT_SYMBOL_GPL(compat_dccp_setsockopt);
533#endif
534
298static int dccp_getsockopt_service(struct sock *sk, int len, 535static int dccp_getsockopt_service(struct sock *sk, int len,
299 u32 __user *optval, 536 __be32 __user *optval,
300 int __user *optlen) 537 int __user *optlen)
301{ 538{
302 const struct dccp_sock *dp = dccp_sk(sk); 539 const struct dccp_sock *dp = dccp_sk(sk);
@@ -326,16 +563,12 @@ out:
326 return err; 563 return err;
327} 564}
328 565
329int dccp_getsockopt(struct sock *sk, int level, int optname, 566static int do_dccp_getsockopt(struct sock *sk, int level, int optname,
330 char __user *optval, int __user *optlen) 567 char __user *optval, int __user *optlen)
331{ 568{
332 struct dccp_sock *dp; 569 struct dccp_sock *dp;
333 int val, len; 570 int val, len;
334 571
335 if (level != SOL_DCCP)
336 return inet_csk(sk)->icsk_af_ops->getsockopt(sk, level,
337 optname, optval,
338 optlen);
339 if (get_user(len, optlen)) 572 if (get_user(len, optlen))
340 return -EFAULT; 573 return -EFAULT;
341 574
@@ -351,7 +584,7 @@ int dccp_getsockopt(struct sock *sk, int level, int optname,
351 break; 584 break;
352 case DCCP_SOCKOPT_SERVICE: 585 case DCCP_SOCKOPT_SERVICE:
353 return dccp_getsockopt_service(sk, len, 586 return dccp_getsockopt_service(sk, len,
354 (u32 __user *)optval, optlen); 587 (__be32 __user *)optval, optlen);
355 case 128 ... 191: 588 case 128 ... 191:
356 return ccid_hc_rx_getsockopt(dp->dccps_hc_rx_ccid, sk, optname, 589 return ccid_hc_rx_getsockopt(dp->dccps_hc_rx_ccid, sk, optname,
357 len, (u32 __user *)optval, optlen); 590 len, (u32 __user *)optval, optlen);
@@ -368,8 +601,31 @@ int dccp_getsockopt(struct sock *sk, int level, int optname,
368 return 0; 601 return 0;
369} 602}
370 603
604int dccp_getsockopt(struct sock *sk, int level, int optname,
605 char __user *optval, int __user *optlen)
606{
607 if (level != SOL_DCCP)
608 return inet_csk(sk)->icsk_af_ops->getsockopt(sk, level,
609 optname, optval,
610 optlen);
611 return do_dccp_getsockopt(sk, level, optname, optval, optlen);
612}
613
371EXPORT_SYMBOL_GPL(dccp_getsockopt); 614EXPORT_SYMBOL_GPL(dccp_getsockopt);
372 615
616#ifdef CONFIG_COMPAT
617int compat_dccp_getsockopt(struct sock *sk, int level, int optname,
618 char __user *optval, int __user *optlen)
619{
620 if (level != SOL_DCCP)
621 return inet_csk_compat_getsockopt(sk, level, optname,
622 optval, optlen);
623 return do_dccp_getsockopt(sk, level, optname, optval, optlen);
624}
625
626EXPORT_SYMBOL_GPL(compat_dccp_getsockopt);
627#endif
628
373int dccp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, 629int dccp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
374 size_t len) 630 size_t len)
375{ 631{
@@ -679,84 +935,7 @@ void dccp_shutdown(struct sock *sk, int how)
679 935
680EXPORT_SYMBOL_GPL(dccp_shutdown); 936EXPORT_SYMBOL_GPL(dccp_shutdown);
681 937
682static const struct proto_ops inet_dccp_ops = { 938static int __init dccp_mib_init(void)
683 .family = PF_INET,
684 .owner = THIS_MODULE,
685 .release = inet_release,
686 .bind = inet_bind,
687 .connect = inet_stream_connect,
688 .socketpair = sock_no_socketpair,
689 .accept = inet_accept,
690 .getname = inet_getname,
691 /* FIXME: work on tcp_poll to rename it to inet_csk_poll */
692 .poll = dccp_poll,
693 .ioctl = inet_ioctl,
694 /* FIXME: work on inet_listen to rename it to sock_common_listen */
695 .listen = inet_dccp_listen,
696 .shutdown = inet_shutdown,
697 .setsockopt = sock_common_setsockopt,
698 .getsockopt = sock_common_getsockopt,
699 .sendmsg = inet_sendmsg,
700 .recvmsg = sock_common_recvmsg,
701 .mmap = sock_no_mmap,
702 .sendpage = sock_no_sendpage,
703};
704
705extern struct net_proto_family inet_family_ops;
706
707static struct inet_protosw dccp_v4_protosw = {
708 .type = SOCK_DCCP,
709 .protocol = IPPROTO_DCCP,
710 .prot = &dccp_prot,
711 .ops = &inet_dccp_ops,
712 .capability = -1,
713 .no_check = 0,
714 .flags = INET_PROTOSW_ICSK,
715};
716
717/*
718 * This is the global socket data structure used for responding to
719 * the Out-of-the-blue (OOTB) packets. A control sock will be created
720 * for this socket at the initialization time.
721 */
722struct socket *dccp_ctl_socket;
723
724static char dccp_ctl_socket_err_msg[] __initdata =
725 KERN_ERR "DCCP: Failed to create the control socket.\n";
726
727static int __init dccp_ctl_sock_init(void)
728{
729 int rc = sock_create_kern(PF_INET, SOCK_DCCP, IPPROTO_DCCP,
730 &dccp_ctl_socket);
731 if (rc < 0)
732 printk(dccp_ctl_socket_err_msg);
733 else {
734 dccp_ctl_socket->sk->sk_allocation = GFP_ATOMIC;
735 inet_sk(dccp_ctl_socket->sk)->uc_ttl = -1;
736
737 /* Unhash it so that IP input processing does not even
738 * see it, we do not wish this socket to see incoming
739 * packets.
740 */
741 dccp_ctl_socket->sk->sk_prot->unhash(dccp_ctl_socket->sk);
742 }
743
744 return rc;
745}
746
747#ifdef CONFIG_IP_DCCP_UNLOAD_HACK
748void dccp_ctl_sock_exit(void)
749{
750 if (dccp_ctl_socket != NULL) {
751 sock_release(dccp_ctl_socket);
752 dccp_ctl_socket = NULL;
753 }
754}
755
756EXPORT_SYMBOL_GPL(dccp_ctl_sock_exit);
757#endif
758
759static int __init init_dccp_v4_mibs(void)
760{ 939{
761 int rc = -ENOMEM; 940 int rc = -ENOMEM;
762 941
@@ -778,6 +957,13 @@ out_free_one:
778 957
779} 958}
780 959
960static void dccp_mib_exit(void)
961{
962 free_percpu(dccp_statistics[0]);
963 free_percpu(dccp_statistics[1]);
964 dccp_statistics[0] = dccp_statistics[1] = NULL;
965}
966
781static int thash_entries; 967static int thash_entries;
782module_param(thash_entries, int, 0444); 968module_param(thash_entries, int, 0444);
783MODULE_PARM_DESC(thash_entries, "Number of ehash buckets"); 969MODULE_PARM_DESC(thash_entries, "Number of ehash buckets");
@@ -794,17 +980,14 @@ static int __init dccp_init(void)
794{ 980{
795 unsigned long goal; 981 unsigned long goal;
796 int ehash_order, bhash_order, i; 982 int ehash_order, bhash_order, i;
797 int rc = proto_register(&dccp_prot, 1); 983 int rc = -ENOBUFS;
798
799 if (rc)
800 goto out;
801 984
802 dccp_hashinfo.bind_bucket_cachep = 985 dccp_hashinfo.bind_bucket_cachep =
803 kmem_cache_create("dccp_bind_bucket", 986 kmem_cache_create("dccp_bind_bucket",
804 sizeof(struct inet_bind_bucket), 0, 987 sizeof(struct inet_bind_bucket), 0,
805 SLAB_HWCACHE_ALIGN, NULL, NULL); 988 SLAB_HWCACHE_ALIGN, NULL, NULL);
806 if (!dccp_hashinfo.bind_bucket_cachep) 989 if (!dccp_hashinfo.bind_bucket_cachep)
807 goto out_proto_unregister; 990 goto out;
808 991
809 /* 992 /*
810 * Size and allocate the main established and bind bucket 993 * Size and allocate the main established and bind bucket
@@ -866,27 +1049,23 @@ static int __init dccp_init(void)
866 INIT_HLIST_HEAD(&dccp_hashinfo.bhash[i].chain); 1049 INIT_HLIST_HEAD(&dccp_hashinfo.bhash[i].chain);
867 } 1050 }
868 1051
869 if (init_dccp_v4_mibs()) 1052 rc = dccp_mib_init();
1053 if (rc)
870 goto out_free_dccp_bhash; 1054 goto out_free_dccp_bhash;
871 1055
872 rc = -EAGAIN; 1056 rc = dccp_ackvec_init();
873 if (inet_add_protocol(&dccp_protocol, IPPROTO_DCCP)) 1057 if (rc)
874 goto out_free_dccp_v4_mibs; 1058 goto out_free_dccp_mib;
875
876 inet_register_protosw(&dccp_v4_protosw);
877 1059
878 rc = dccp_ctl_sock_init(); 1060 rc = dccp_sysctl_init();
879 if (rc) 1061 if (rc)
880 goto out_unregister_protosw; 1062 goto out_ackvec_exit;
881out: 1063out:
882 return rc; 1064 return rc;
883out_unregister_protosw: 1065out_ackvec_exit:
884 inet_unregister_protosw(&dccp_v4_protosw); 1066 dccp_ackvec_exit();
885 inet_del_protocol(&dccp_protocol, IPPROTO_DCCP); 1067out_free_dccp_mib:
886out_free_dccp_v4_mibs: 1068 dccp_mib_exit();
887 free_percpu(dccp_statistics[0]);
888 free_percpu(dccp_statistics[1]);
889 dccp_statistics[0] = dccp_statistics[1] = NULL;
890out_free_dccp_bhash: 1069out_free_dccp_bhash:
891 free_pages((unsigned long)dccp_hashinfo.bhash, bhash_order); 1070 free_pages((unsigned long)dccp_hashinfo.bhash, bhash_order);
892 dccp_hashinfo.bhash = NULL; 1071 dccp_hashinfo.bhash = NULL;
@@ -896,23 +1075,12 @@ out_free_dccp_ehash:
896out_free_bind_bucket_cachep: 1075out_free_bind_bucket_cachep:
897 kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); 1076 kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
898 dccp_hashinfo.bind_bucket_cachep = NULL; 1077 dccp_hashinfo.bind_bucket_cachep = NULL;
899out_proto_unregister:
900 proto_unregister(&dccp_prot);
901 goto out; 1078 goto out;
902} 1079}
903 1080
904static const char dccp_del_proto_err_msg[] __exitdata =
905 KERN_ERR "can't remove dccp net_protocol\n";
906
907static void __exit dccp_fini(void) 1081static void __exit dccp_fini(void)
908{ 1082{
909 inet_unregister_protosw(&dccp_v4_protosw); 1083 dccp_mib_exit();
910
911 if (inet_del_protocol(&dccp_protocol, IPPROTO_DCCP) < 0)
912 printk(dccp_del_proto_err_msg);
913
914 free_percpu(dccp_statistics[0]);
915 free_percpu(dccp_statistics[1]);
916 free_pages((unsigned long)dccp_hashinfo.bhash, 1084 free_pages((unsigned long)dccp_hashinfo.bhash,
917 get_order(dccp_hashinfo.bhash_size * 1085 get_order(dccp_hashinfo.bhash_size *
918 sizeof(struct inet_bind_hashbucket))); 1086 sizeof(struct inet_bind_hashbucket)));
@@ -920,19 +1088,13 @@ static void __exit dccp_fini(void)
920 get_order(dccp_hashinfo.ehash_size * 1088 get_order(dccp_hashinfo.ehash_size *
921 sizeof(struct inet_ehash_bucket))); 1089 sizeof(struct inet_ehash_bucket)));
922 kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); 1090 kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
923 proto_unregister(&dccp_prot); 1091 dccp_ackvec_exit();
1092 dccp_sysctl_exit();
924} 1093}
925 1094
926module_init(dccp_init); 1095module_init(dccp_init);
927module_exit(dccp_fini); 1096module_exit(dccp_fini);
928 1097
929/*
930 * __stringify doesn't likes enums, so use SOCK_DCCP (6) and IPPROTO_DCCP (33)
931 * values directly, Also cover the case where the protocol is not specified,
932 * i.e. net-pf-PF_INET-proto-0-type-SOCK_DCCP
933 */
934MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-33-type-6");
935MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-0-type-6");
936MODULE_LICENSE("GPL"); 1098MODULE_LICENSE("GPL");
937MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@conectiva.com.br>"); 1099MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@conectiva.com.br>");
938MODULE_DESCRIPTION("DCCP - Datagram Congestion Controlled Protocol"); 1100MODULE_DESCRIPTION("DCCP - Datagram Congestion Controlled Protocol");
diff --git a/net/dccp/sysctl.c b/net/dccp/sysctl.c
new file mode 100644
index 000000000000..64c89e9c229e
--- /dev/null
+++ b/net/dccp/sysctl.c
@@ -0,0 +1,124 @@
1/*
2 * net/dccp/sysctl.c
3 *
4 * An implementation of the DCCP protocol
5 * Arnaldo Carvalho de Melo <acme@mandriva.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License v2
9 * as published by the Free Software Foundation.
10 */
11
12#include <linux/config.h>
13#include <linux/mm.h>
14#include <linux/sysctl.h>
15
16#ifndef CONFIG_SYSCTL
17#error This file should not be compiled without CONFIG_SYSCTL defined
18#endif
19
20extern int dccp_feat_default_sequence_window;
21extern int dccp_feat_default_rx_ccid;
22extern int dccp_feat_default_tx_ccid;
23extern int dccp_feat_default_ack_ratio;
24extern int dccp_feat_default_send_ack_vector;
25extern int dccp_feat_default_send_ndp_count;
26
27static struct ctl_table dccp_default_table[] = {
28 {
29 .ctl_name = NET_DCCP_DEFAULT_SEQ_WINDOW,
30 .procname = "seq_window",
31 .data = &dccp_feat_default_sequence_window,
32 .maxlen = sizeof(dccp_feat_default_sequence_window),
33 .mode = 0644,
34 .proc_handler = proc_dointvec,
35 },
36 {
37 .ctl_name = NET_DCCP_DEFAULT_RX_CCID,
38 .procname = "rx_ccid",
39 .data = &dccp_feat_default_rx_ccid,
40 .maxlen = sizeof(dccp_feat_default_rx_ccid),
41 .mode = 0644,
42 .proc_handler = proc_dointvec,
43 },
44 {
45 .ctl_name = NET_DCCP_DEFAULT_TX_CCID,
46 .procname = "tx_ccid",
47 .data = &dccp_feat_default_tx_ccid,
48 .maxlen = sizeof(dccp_feat_default_tx_ccid),
49 .mode = 0644,
50 .proc_handler = proc_dointvec,
51 },
52 {
53 .ctl_name = NET_DCCP_DEFAULT_ACK_RATIO,
54 .procname = "ack_ratio",
55 .data = &dccp_feat_default_ack_ratio,
56 .maxlen = sizeof(dccp_feat_default_ack_ratio),
57 .mode = 0644,
58 .proc_handler = proc_dointvec,
59 },
60 {
61 .ctl_name = NET_DCCP_DEFAULT_SEND_ACKVEC,
62 .procname = "send_ackvec",
63 .data = &dccp_feat_default_send_ack_vector,
64 .maxlen = sizeof(dccp_feat_default_send_ack_vector),
65 .mode = 0644,
66 .proc_handler = proc_dointvec,
67 },
68 {
69 .ctl_name = NET_DCCP_DEFAULT_SEND_NDP,
70 .procname = "send_ndp",
71 .data = &dccp_feat_default_send_ndp_count,
72 .maxlen = sizeof(dccp_feat_default_send_ndp_count),
73 .mode = 0644,
74 .proc_handler = proc_dointvec,
75 },
76 { .ctl_name = 0, }
77};
78
79static struct ctl_table dccp_table[] = {
80 {
81 .ctl_name = NET_DCCP_DEFAULT,
82 .procname = "default",
83 .mode = 0555,
84 .child = dccp_default_table,
85 },
86 { .ctl_name = 0, },
87};
88
89static struct ctl_table dccp_dir_table[] = {
90 {
91 .ctl_name = NET_DCCP,
92 .procname = "dccp",
93 .mode = 0555,
94 .child = dccp_table,
95 },
96 { .ctl_name = 0, },
97};
98
99static struct ctl_table dccp_root_table[] = {
100 {
101 .ctl_name = CTL_NET,
102 .procname = "net",
103 .mode = 0555,
104 .child = dccp_dir_table,
105 },
106 { .ctl_name = 0, },
107};
108
109static struct ctl_table_header *dccp_table_header;
110
111int __init dccp_sysctl_init(void)
112{
113 dccp_table_header = register_sysctl_table(dccp_root_table, 1);
114
115 return dccp_table_header != NULL ? 0 : -ENOMEM;
116}
117
118void dccp_sysctl_exit(void)
119{
120 if (dccp_table_header != NULL) {
121 unregister_sysctl_table(dccp_table_header);
122 dccp_table_header = NULL;
123 }
124}
diff --git a/net/dccp/timer.c b/net/dccp/timer.c
index aa34b576e228..5244415e5f18 100644
--- a/net/dccp/timer.c
+++ b/net/dccp/timer.c
@@ -31,7 +31,7 @@ static void dccp_write_err(struct sock *sk)
31 sk->sk_err = sk->sk_err_soft ? : ETIMEDOUT; 31 sk->sk_err = sk->sk_err_soft ? : ETIMEDOUT;
32 sk->sk_error_report(sk); 32 sk->sk_error_report(sk);
33 33
34 dccp_v4_send_reset(sk, DCCP_RESET_CODE_ABORTED); 34 dccp_send_reset(sk, DCCP_RESET_CODE_ABORTED);
35 dccp_done(sk); 35 dccp_done(sk);
36 DCCP_INC_STATS_BH(DCCP_MIB_ABORTONTIMEOUT); 36 DCCP_INC_STATS_BH(DCCP_MIB_ABORTONTIMEOUT);
37} 37}
@@ -141,6 +141,17 @@ static void dccp_retransmit_timer(struct sock *sk)
141{ 141{
142 struct inet_connection_sock *icsk = inet_csk(sk); 142 struct inet_connection_sock *icsk = inet_csk(sk);
143 143
144 /* retransmit timer is used for feature negotiation throughout
145 * connection. In this case, no packet is re-transmitted, but rather an
146 * ack is generated and pending changes are splaced into its options.
147 */
148 if (sk->sk_send_head == NULL) {
149 dccp_pr_debug("feat negotiation retransmit timeout %p\n", sk);
150 if (sk->sk_state == DCCP_OPEN)
151 dccp_send_ack(sk);
152 goto backoff;
153 }
154
144 /* 155 /*
145 * sk->sk_send_head has to have one skb with 156 * sk->sk_send_head has to have one skb with
146 * DCCP_SKB_CB(skb)->dccpd_type set to one of the retransmittable DCCP 157 * DCCP_SKB_CB(skb)->dccpd_type set to one of the retransmittable DCCP
@@ -177,6 +188,7 @@ static void dccp_retransmit_timer(struct sock *sk)
177 goto out; 188 goto out;
178 } 189 }
179 190
191backoff:
180 icsk->icsk_backoff++; 192 icsk->icsk_backoff++;
181 icsk->icsk_retransmits++; 193 icsk->icsk_retransmits++;
182 194
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index ce4aaf94860d..2b289ef20ab3 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -172,7 +172,7 @@ static struct hlist_head *dn_find_list(struct sock *sk)
172/* 172/*
173 * Valid ports are those greater than zero and not already in use. 173 * Valid ports are those greater than zero and not already in use.
174 */ 174 */
175static int check_port(unsigned short port) 175static int check_port(__le16 port)
176{ 176{
177 struct sock *sk; 177 struct sock *sk;
178 struct hlist_node *node; 178 struct hlist_node *node;
@@ -661,7 +661,7 @@ disc_reject:
661 } 661 }
662} 662}
663 663
664char *dn_addr2asc(dn_address addr, char *buf) 664char *dn_addr2asc(__u16 addr, char *buf)
665{ 665{
666 unsigned short node, area; 666 unsigned short node, area;
667 667
@@ -801,7 +801,7 @@ static int dn_auto_bind(struct socket *sock)
801 /* End of compatibility stuff */ 801 /* End of compatibility stuff */
802 802
803 scp->addr.sdn_add.a_len = dn_htons(2); 803 scp->addr.sdn_add.a_len = dn_htons(2);
804 rv = dn_dev_bind_default((dn_address *)scp->addr.sdn_add.a_addr); 804 rv = dn_dev_bind_default((__le16 *)scp->addr.sdn_add.a_addr);
805 if (rv == 0) { 805 if (rv == 0) {
806 rv = dn_hash_sock(sk); 806 rv = dn_hash_sock(sk);
807 if (rv) 807 if (rv)
@@ -1021,7 +1021,7 @@ static void dn_user_copy(struct sk_buff *skb, struct optdata_dn *opt)
1021 opt->opt_optl = *ptr++; 1021 opt->opt_optl = *ptr++;
1022 opt->opt_status = 0; 1022 opt->opt_status = 0;
1023 memcpy(opt->opt_data, ptr, opt->opt_optl); 1023 memcpy(opt->opt_data, ptr, opt->opt_optl);
1024 skb_pull(skb, opt->opt_optl + 1); 1024 skb_pull(skb, dn_ntohs(opt->opt_optl) + 1);
1025 1025
1026} 1026}
1027 1027
@@ -1121,8 +1121,8 @@ static int dn_accept(struct socket *sock, struct socket *newsock, int flags)
1121 1121
1122 skb_pull(skb, dn_username2sockaddr(skb->data, skb->len, &(DN_SK(newsk)->addr), &type)); 1122 skb_pull(skb, dn_username2sockaddr(skb->data, skb->len, &(DN_SK(newsk)->addr), &type));
1123 skb_pull(skb, dn_username2sockaddr(skb->data, skb->len, &(DN_SK(newsk)->peer), &type)); 1123 skb_pull(skb, dn_username2sockaddr(skb->data, skb->len, &(DN_SK(newsk)->peer), &type));
1124 *(dn_address *)(DN_SK(newsk)->peer.sdn_add.a_addr) = cb->src; 1124 *(__le16 *)(DN_SK(newsk)->peer.sdn_add.a_addr) = cb->src;
1125 *(dn_address *)(DN_SK(newsk)->addr.sdn_add.a_addr) = cb->dst; 1125 *(__le16 *)(DN_SK(newsk)->addr.sdn_add.a_addr) = cb->dst;
1126 1126
1127 menuver = *skb->data; 1127 menuver = *skb->data;
1128 skb_pull(skb, 1); 1128 skb_pull(skb, 1);
@@ -1365,7 +1365,7 @@ static int __dn_setsockopt(struct socket *sock, int level,int optname, char __us
1365 if (optlen != sizeof(struct optdata_dn)) 1365 if (optlen != sizeof(struct optdata_dn))
1366 return -EINVAL; 1366 return -EINVAL;
1367 1367
1368 if (u.opt.opt_optl > 16) 1368 if (dn_ntohs(u.opt.opt_optl) > 16)
1369 return -EINVAL; 1369 return -EINVAL;
1370 1370
1371 memcpy(&scp->conndata_out, &u.opt, optlen); 1371 memcpy(&scp->conndata_out, &u.opt, optlen);
@@ -1378,7 +1378,7 @@ static int __dn_setsockopt(struct socket *sock, int level,int optname, char __us
1378 if (optlen != sizeof(struct optdata_dn)) 1378 if (optlen != sizeof(struct optdata_dn))
1379 return -EINVAL; 1379 return -EINVAL;
1380 1380
1381 if (u.opt.opt_optl > 16) 1381 if (dn_ntohs(u.opt.opt_optl) > 16)
1382 return -EINVAL; 1382 return -EINVAL;
1383 1383
1384 memcpy(&scp->discdata_out, &u.opt, optlen); 1384 memcpy(&scp->discdata_out, &u.opt, optlen);
@@ -1693,7 +1693,7 @@ static int dn_recvmsg(struct kiocb *iocb, struct socket *sock,
1693 if (rv) 1693 if (rv)
1694 goto out; 1694 goto out;
1695 1695
1696 if (flags & ~(MSG_PEEK|MSG_OOB|MSG_WAITALL|MSG_DONTWAIT|MSG_NOSIGNAL)) { 1696 if (flags & ~(MSG_CMSG_COMPAT|MSG_PEEK|MSG_OOB|MSG_WAITALL|MSG_DONTWAIT|MSG_NOSIGNAL)) {
1697 rv = -EOPNOTSUPP; 1697 rv = -EOPNOTSUPP;
1698 goto out; 1698 goto out;
1699 } 1699 }
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index efbead83ba7f..cc7b9d9255ef 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -64,7 +64,7 @@ extern struct neigh_table dn_neigh_table;
64/* 64/*
65 * decnet_address is kept in network order. 65 * decnet_address is kept in network order.
66 */ 66 */
67dn_address decnet_address = 0; 67__le16 decnet_address = 0;
68 68
69static DEFINE_RWLOCK(dndev_lock); 69static DEFINE_RWLOCK(dndev_lock);
70static struct net_device *decnet_default_device; 70static struct net_device *decnet_default_device;
@@ -439,7 +439,7 @@ static void dn_dev_del_ifa(struct dn_dev *dn_db, struct dn_ifaddr **ifap, int de
439 *ifap = ifa1->ifa_next; 439 *ifap = ifa1->ifa_next;
440 440
441 if (dn_db->dev->type == ARPHRD_ETHER) { 441 if (dn_db->dev->type == ARPHRD_ETHER) {
442 if (ifa1->ifa_local != dn_htons(dn_eth2dn(dev->dev_addr))) { 442 if (ifa1->ifa_local != dn_eth2dn(dev->dev_addr)) {
443 dn_dn2eth(mac_addr, ifa1->ifa_local); 443 dn_dn2eth(mac_addr, ifa1->ifa_local);
444 dev_mc_delete(dev, mac_addr, ETH_ALEN, 0); 444 dev_mc_delete(dev, mac_addr, ETH_ALEN, 0);
445 } 445 }
@@ -470,7 +470,7 @@ static int dn_dev_insert_ifa(struct dn_dev *dn_db, struct dn_ifaddr *ifa)
470 } 470 }
471 471
472 if (dev->type == ARPHRD_ETHER) { 472 if (dev->type == ARPHRD_ETHER) {
473 if (ifa->ifa_local != dn_htons(dn_eth2dn(dev->dev_addr))) { 473 if (ifa->ifa_local != dn_eth2dn(dev->dev_addr)) {
474 dn_dn2eth(mac_addr, ifa->ifa_local); 474 dn_dn2eth(mac_addr, ifa->ifa_local);
475 dev_mc_add(dev, mac_addr, ETH_ALEN, 0); 475 dev_mc_add(dev, mac_addr, ETH_ALEN, 0);
476 dev_mc_upload(dev); 476 dev_mc_upload(dev);
@@ -561,7 +561,7 @@ int dn_dev_ioctl(unsigned int cmd, void __user *arg)
561 561
562 switch(cmd) { 562 switch(cmd) {
563 case SIOCGIFADDR: 563 case SIOCGIFADDR:
564 *((dn_address *)sdn->sdn_nodeaddr) = ifa->ifa_local; 564 *((__le16 *)sdn->sdn_nodeaddr) = ifa->ifa_local;
565 goto rarok; 565 goto rarok;
566 566
567 case SIOCSIFADDR: 567 case SIOCSIFADDR:
@@ -804,7 +804,7 @@ done:
804 return skb->len; 804 return skb->len;
805} 805}
806 806
807static int dn_dev_get_first(struct net_device *dev, dn_address *addr) 807static int dn_dev_get_first(struct net_device *dev, __le16 *addr)
808{ 808{
809 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr; 809 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
810 struct dn_ifaddr *ifa; 810 struct dn_ifaddr *ifa;
@@ -830,7 +830,7 @@ out:
830 * a sensible default. Eventually the routing code will take care of all the 830 * a sensible default. Eventually the routing code will take care of all the
831 * nasties for us I hope. 831 * nasties for us I hope.
832 */ 832 */
833int dn_dev_bind_default(dn_address *addr) 833int dn_dev_bind_default(__le16 *addr)
834{ 834{
835 struct net_device *dev; 835 struct net_device *dev;
836 int rv; 836 int rv;
@@ -853,7 +853,7 @@ static void dn_send_endnode_hello(struct net_device *dev, struct dn_ifaddr *ifa)
853{ 853{
854 struct endnode_hello_message *msg; 854 struct endnode_hello_message *msg;
855 struct sk_buff *skb = NULL; 855 struct sk_buff *skb = NULL;
856 unsigned short int *pktlen; 856 __le16 *pktlen;
857 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr; 857 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
858 858
859 if ((skb = dn_alloc_skb(NULL, sizeof(*msg), GFP_ATOMIC)) == NULL) 859 if ((skb = dn_alloc_skb(NULL, sizeof(*msg), GFP_ATOMIC)) == NULL)
@@ -882,7 +882,7 @@ static void dn_send_endnode_hello(struct net_device *dev, struct dn_ifaddr *ifa)
882 msg->datalen = 0x02; 882 msg->datalen = 0x02;
883 memset(msg->data, 0xAA, 2); 883 memset(msg->data, 0xAA, 2);
884 884
885 pktlen = (unsigned short *)skb_push(skb,2); 885 pktlen = (__le16 *)skb_push(skb,2);
886 *pktlen = dn_htons(skb->len - 2); 886 *pktlen = dn_htons(skb->len - 2);
887 887
888 skb->nh.raw = skb->data; 888 skb->nh.raw = skb->data;
@@ -926,7 +926,7 @@ static void dn_send_router_hello(struct net_device *dev, struct dn_ifaddr *ifa)
926 size_t size; 926 size_t size;
927 unsigned char *ptr; 927 unsigned char *ptr;
928 unsigned char *i1, *i2; 928 unsigned char *i1, *i2;
929 unsigned short *pktlen; 929 __le16 *pktlen;
930 char *src; 930 char *src;
931 931
932 if (mtu2blksize(dev) < (26 + 7)) 932 if (mtu2blksize(dev) < (26 + 7))
@@ -955,11 +955,11 @@ static void dn_send_router_hello(struct net_device *dev, struct dn_ifaddr *ifa)
955 ptr += ETH_ALEN; 955 ptr += ETH_ALEN;
956 *ptr++ = dn_db->parms.forwarding == 1 ? 956 *ptr++ = dn_db->parms.forwarding == 1 ?
957 DN_RT_INFO_L1RT : DN_RT_INFO_L2RT; 957 DN_RT_INFO_L1RT : DN_RT_INFO_L2RT;
958 *((unsigned short *)ptr) = dn_htons(mtu2blksize(dev)); 958 *((__le16 *)ptr) = dn_htons(mtu2blksize(dev));
959 ptr += 2; 959 ptr += 2;
960 *ptr++ = dn_db->parms.priority; /* Priority */ 960 *ptr++ = dn_db->parms.priority; /* Priority */
961 *ptr++ = 0; /* Area: Reserved */ 961 *ptr++ = 0; /* Area: Reserved */
962 *((unsigned short *)ptr) = dn_htons((unsigned short)dn_db->parms.t3); 962 *((__le16 *)ptr) = dn_htons((unsigned short)dn_db->parms.t3);
963 ptr += 2; 963 ptr += 2;
964 *ptr++ = 0; /* MPD: Reserved */ 964 *ptr++ = 0; /* MPD: Reserved */
965 i1 = ptr++; 965 i1 = ptr++;
@@ -974,7 +974,7 @@ static void dn_send_router_hello(struct net_device *dev, struct dn_ifaddr *ifa)
974 974
975 skb_trim(skb, (27 + *i2)); 975 skb_trim(skb, (27 + *i2));
976 976
977 pktlen = (unsigned short *)skb_push(skb, 2); 977 pktlen = (__le16 *)skb_push(skb, 2);
978 *pktlen = dn_htons(skb->len - 2); 978 *pktlen = dn_htons(skb->len - 2);
979 979
980 skb->nh.raw = skb->data; 980 skb->nh.raw = skb->data;
@@ -1016,7 +1016,7 @@ static void dn_send_ptp_hello(struct net_device *dev, struct dn_ifaddr *ifa)
1016 ptr = skb_put(skb, 2 + 4 + tdlen); 1016 ptr = skb_put(skb, 2 + 4 + tdlen);
1017 1017
1018 *ptr++ = DN_RT_PKT_HELO; 1018 *ptr++ = DN_RT_PKT_HELO;
1019 *((dn_address *)ptr) = ifa->ifa_local; 1019 *((__le16 *)ptr) = ifa->ifa_local;
1020 ptr += 2; 1020 ptr += 2;
1021 *ptr++ = tdlen; 1021 *ptr++ = tdlen;
1022 1022
@@ -1150,7 +1150,7 @@ struct dn_dev *dn_dev_create(struct net_device *dev, int *err)
1150void dn_dev_up(struct net_device *dev) 1150void dn_dev_up(struct net_device *dev)
1151{ 1151{
1152 struct dn_ifaddr *ifa; 1152 struct dn_ifaddr *ifa;
1153 dn_address addr = decnet_address; 1153 __le16 addr = decnet_address;
1154 int maybe_default = 0; 1154 int maybe_default = 0;
1155 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr; 1155 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
1156 1156
@@ -1173,7 +1173,7 @@ void dn_dev_up(struct net_device *dev)
1173 if (dev->type == ARPHRD_ETHER) { 1173 if (dev->type == ARPHRD_ETHER) {
1174 if (memcmp(dev->dev_addr, dn_hiord, 4) != 0) 1174 if (memcmp(dev->dev_addr, dn_hiord, 4) != 0)
1175 return; 1175 return;
1176 addr = dn_htons(dn_eth2dn(dev->dev_addr)); 1176 addr = dn_eth2dn(dev->dev_addr);
1177 maybe_default = 1; 1177 maybe_default = 1;
1178 } 1178 }
1179 1179
@@ -1385,8 +1385,8 @@ static int dn_dev_seq_show(struct seq_file *seq, void *v)
1385 mtu2blksize(dev), 1385 mtu2blksize(dev),
1386 dn_db->parms.priority, 1386 dn_db->parms.priority,
1387 dn_db->parms.state, dn_db->parms.name, 1387 dn_db->parms.state, dn_db->parms.name,
1388 dn_db->router ? dn_addr2asc(dn_ntohs(*(dn_address *)dn_db->router->primary_key), router_buf) : "", 1388 dn_db->router ? dn_addr2asc(dn_ntohs(*(__le16 *)dn_db->router->primary_key), router_buf) : "",
1389 dn_db->peer ? dn_addr2asc(dn_ntohs(*(dn_address *)dn_db->peer->primary_key), peer_buf) : ""); 1389 dn_db->peer ? dn_addr2asc(dn_ntohs(*(__le16 *)dn_db->peer->primary_key), peer_buf) : "");
1390 } 1390 }
1391 return 0; 1391 return 0;
1392} 1392}
diff --git a/net/decnet/dn_fib.c b/net/decnet/dn_fib.c
index 99bc061759c3..bd4ce8681a12 100644
--- a/net/decnet/dn_fib.c
+++ b/net/decnet/dn_fib.c
@@ -143,11 +143,11 @@ static inline struct dn_fib_info *dn_fib_find_info(const struct dn_fib_info *nfi
143 return NULL; 143 return NULL;
144} 144}
145 145
146u16 dn_fib_get_attr16(struct rtattr *attr, int attrlen, int type) 146__le16 dn_fib_get_attr16(struct rtattr *attr, int attrlen, int type)
147{ 147{
148 while(RTA_OK(attr,attrlen)) { 148 while(RTA_OK(attr,attrlen)) {
149 if (attr->rta_type == type) 149 if (attr->rta_type == type)
150 return *(u16*)RTA_DATA(attr); 150 return *(__le16*)RTA_DATA(attr);
151 attr = RTA_NEXT(attr, attrlen); 151 attr = RTA_NEXT(attr, attrlen);
152 } 152 }
153 153
@@ -565,7 +565,7 @@ int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb)
565 return skb->len; 565 return skb->len;
566} 566}
567 567
568static void fib_magic(int cmd, int type, __u16 dst, int dst_len, struct dn_ifaddr *ifa) 568static void fib_magic(int cmd, int type, __le16 dst, int dst_len, struct dn_ifaddr *ifa)
569{ 569{
570 struct dn_fib_table *tb; 570 struct dn_fib_table *tb;
571 struct { 571 struct {
@@ -684,7 +684,7 @@ static int dn_fib_dnaddr_event(struct notifier_block *this, unsigned long event,
684 return NOTIFY_DONE; 684 return NOTIFY_DONE;
685} 685}
686 686
687int dn_fib_sync_down(dn_address local, struct net_device *dev, int force) 687int dn_fib_sync_down(__le16 local, struct net_device *dev, int force)
688{ 688{
689 int ret = 0; 689 int ret = 0;
690 int scope = RT_SCOPE_NOWHERE; 690 int scope = RT_SCOPE_NOWHERE;
diff --git a/net/decnet/dn_neigh.c b/net/decnet/dn_neigh.c
index 33ab256cfd4a..7c8692c26bfe 100644
--- a/net/decnet/dn_neigh.c
+++ b/net/decnet/dn_neigh.c
@@ -95,7 +95,7 @@ static struct neigh_ops dn_phase3_ops = {
95struct neigh_table dn_neigh_table = { 95struct neigh_table dn_neigh_table = {
96 .family = PF_DECnet, 96 .family = PF_DECnet,
97 .entry_size = sizeof(struct dn_neigh), 97 .entry_size = sizeof(struct dn_neigh),
98 .key_len = sizeof(dn_address), 98 .key_len = sizeof(__le16),
99 .hash = dn_neigh_hash, 99 .hash = dn_neigh_hash,
100 .constructor = dn_neigh_construct, 100 .constructor = dn_neigh_construct,
101 .id = "dn_neigh_cache", 101 .id = "dn_neigh_cache",
@@ -123,7 +123,7 @@ struct neigh_table dn_neigh_table = {
123 123
124static u32 dn_neigh_hash(const void *pkey, const struct net_device *dev) 124static u32 dn_neigh_hash(const void *pkey, const struct net_device *dev)
125{ 125{
126 return jhash_2words(*(dn_address *)pkey, 0, dn_neigh_table.hash_rnd); 126 return jhash_2words(*(__u16 *)pkey, 0, dn_neigh_table.hash_rnd);
127} 127}
128 128
129static int dn_neigh_construct(struct neighbour *neigh) 129static int dn_neigh_construct(struct neighbour *neigh)
@@ -249,14 +249,14 @@ static int dn_long_output(struct sk_buff *skb)
249 data = skb_push(skb, sizeof(struct dn_long_packet) + 3); 249 data = skb_push(skb, sizeof(struct dn_long_packet) + 3);
250 lp = (struct dn_long_packet *)(data+3); 250 lp = (struct dn_long_packet *)(data+3);
251 251
252 *((unsigned short *)data) = dn_htons(skb->len - 2); 252 *((__le16 *)data) = dn_htons(skb->len - 2);
253 *(data + 2) = 1 | DN_RT_F_PF; /* Padding */ 253 *(data + 2) = 1 | DN_RT_F_PF; /* Padding */
254 254
255 lp->msgflg = DN_RT_PKT_LONG|(cb->rt_flags&(DN_RT_F_IE|DN_RT_F_RQR|DN_RT_F_RTS)); 255 lp->msgflg = DN_RT_PKT_LONG|(cb->rt_flags&(DN_RT_F_IE|DN_RT_F_RQR|DN_RT_F_RTS));
256 lp->d_area = lp->d_subarea = 0; 256 lp->d_area = lp->d_subarea = 0;
257 dn_dn2eth(lp->d_id, dn_ntohs(cb->dst)); 257 dn_dn2eth(lp->d_id, cb->dst);
258 lp->s_area = lp->s_subarea = 0; 258 lp->s_area = lp->s_subarea = 0;
259 dn_dn2eth(lp->s_id, dn_ntohs(cb->src)); 259 dn_dn2eth(lp->s_id, cb->src);
260 lp->nl2 = 0; 260 lp->nl2 = 0;
261 lp->visit_ct = cb->hops & 0x3f; 261 lp->visit_ct = cb->hops & 0x3f;
262 lp->s_class = 0; 262 lp->s_class = 0;
@@ -293,7 +293,7 @@ static int dn_short_output(struct sk_buff *skb)
293 } 293 }
294 294
295 data = skb_push(skb, sizeof(struct dn_short_packet) + 2); 295 data = skb_push(skb, sizeof(struct dn_short_packet) + 2);
296 *((unsigned short *)data) = dn_htons(skb->len - 2); 296 *((__le16 *)data) = dn_htons(skb->len - 2);
297 sp = (struct dn_short_packet *)(data+2); 297 sp = (struct dn_short_packet *)(data+2);
298 298
299 sp->msgflg = DN_RT_PKT_SHORT|(cb->rt_flags&(DN_RT_F_RQR|DN_RT_F_RTS)); 299 sp->msgflg = DN_RT_PKT_SHORT|(cb->rt_flags&(DN_RT_F_RQR|DN_RT_F_RTS));
@@ -335,7 +335,7 @@ static int dn_phase3_output(struct sk_buff *skb)
335 } 335 }
336 336
337 data = skb_push(skb, sizeof(struct dn_short_packet) + 2); 337 data = skb_push(skb, sizeof(struct dn_short_packet) + 2);
338 *((unsigned short *)data) = dn_htons(skb->len - 2); 338 *((__le16 *)data) = dn_htons(skb->len - 2);
339 sp = (struct dn_short_packet *)(data + 2); 339 sp = (struct dn_short_packet *)(data + 2);
340 340
341 sp->msgflg = DN_RT_PKT_SHORT|(cb->rt_flags&(DN_RT_F_RQR|DN_RT_F_RTS)); 341 sp->msgflg = DN_RT_PKT_SHORT|(cb->rt_flags&(DN_RT_F_RQR|DN_RT_F_RTS));
@@ -373,9 +373,9 @@ int dn_neigh_router_hello(struct sk_buff *skb)
373 struct neighbour *neigh; 373 struct neighbour *neigh;
374 struct dn_neigh *dn; 374 struct dn_neigh *dn;
375 struct dn_dev *dn_db; 375 struct dn_dev *dn_db;
376 dn_address src; 376 __le16 src;
377 377
378 src = dn_htons(dn_eth2dn(msg->id)); 378 src = dn_eth2dn(msg->id);
379 379
380 neigh = __neigh_lookup(&dn_neigh_table, &src, skb->dev, 1); 380 neigh = __neigh_lookup(&dn_neigh_table, &src, skb->dev, 1);
381 381
@@ -409,7 +409,7 @@ int dn_neigh_router_hello(struct sk_buff *skb)
409 } 409 }
410 410
411 /* Only use routers in our area */ 411 /* Only use routers in our area */
412 if ((dn_ntohs(src)>>10) == dn_ntohs((decnet_address)>>10)) { 412 if ((dn_ntohs(src)>>10) == (dn_ntohs((decnet_address))>>10)) {
413 if (!dn_db->router) { 413 if (!dn_db->router) {
414 dn_db->router = neigh_clone(neigh); 414 dn_db->router = neigh_clone(neigh);
415 } else { 415 } else {
@@ -433,9 +433,9 @@ int dn_neigh_endnode_hello(struct sk_buff *skb)
433 struct endnode_hello_message *msg = (struct endnode_hello_message *)skb->data; 433 struct endnode_hello_message *msg = (struct endnode_hello_message *)skb->data;
434 struct neighbour *neigh; 434 struct neighbour *neigh;
435 struct dn_neigh *dn; 435 struct dn_neigh *dn;
436 dn_address src; 436 __le16 src;
437 437
438 src = dn_htons(dn_eth2dn(msg->id)); 438 src = dn_eth2dn(msg->id);
439 439
440 neigh = __neigh_lookup(&dn_neigh_table, &src, skb->dev, 1); 440 neigh = __neigh_lookup(&dn_neigh_table, &src, skb->dev, 1);
441 441
diff --git a/net/decnet/dn_nsp_in.c b/net/decnet/dn_nsp_in.c
index 44bda85e678f..547523b41c81 100644
--- a/net/decnet/dn_nsp_in.c
+++ b/net/decnet/dn_nsp_in.c
@@ -85,7 +85,7 @@ static void dn_log_martian(struct sk_buff *skb, const char *msg)
85 if (decnet_log_martians && net_ratelimit()) { 85 if (decnet_log_martians && net_ratelimit()) {
86 char *devname = skb->dev ? skb->dev->name : "???"; 86 char *devname = skb->dev ? skb->dev->name : "???";
87 struct dn_skb_cb *cb = DN_SKB_CB(skb); 87 struct dn_skb_cb *cb = DN_SKB_CB(skb);
88 printk(KERN_INFO "DECnet: Martian packet (%s) dev=%s src=0x%04hx dst=0x%04hx srcport=0x%04hx dstport=0x%04hx\n", msg, devname, cb->src, cb->dst, cb->src_port, cb->dst_port); 88 printk(KERN_INFO "DECnet: Martian packet (%s) dev=%s src=0x%04hx dst=0x%04hx srcport=0x%04hx dstport=0x%04hx\n", msg, devname, dn_ntohs(cb->src), dn_ntohs(cb->dst), dn_ntohs(cb->src_port), dn_ntohs(cb->dst_port));
89 } 89 }
90} 90}
91 91
@@ -128,7 +128,7 @@ static void dn_ack(struct sock *sk, struct sk_buff *skb, unsigned short ack)
128 */ 128 */
129static int dn_process_ack(struct sock *sk, struct sk_buff *skb, int oth) 129static int dn_process_ack(struct sock *sk, struct sk_buff *skb, int oth)
130{ 130{
131 unsigned short *ptr = (unsigned short *)skb->data; 131 __le16 *ptr = (__le16 *)skb->data;
132 int len = 0; 132 int len = 0;
133 unsigned short ack; 133 unsigned short ack;
134 134
@@ -346,7 +346,7 @@ static void dn_nsp_conn_conf(struct sock *sk, struct sk_buff *skb)
346 ptr = skb->data; 346 ptr = skb->data;
347 cb->services = *ptr++; 347 cb->services = *ptr++;
348 cb->info = *ptr++; 348 cb->info = *ptr++;
349 cb->segsize = dn_ntohs(*(__u16 *)ptr); 349 cb->segsize = dn_ntohs(*(__le16 *)ptr);
350 350
351 if ((scp->state == DN_CI) || (scp->state == DN_CD)) { 351 if ((scp->state == DN_CI) || (scp->state == DN_CD)) {
352 scp->persist = 0; 352 scp->persist = 0;
@@ -363,7 +363,7 @@ static void dn_nsp_conn_conf(struct sock *sk, struct sk_buff *skb)
363 if (skb->len > 0) { 363 if (skb->len > 0) {
364 unsigned char dlen = *skb->data; 364 unsigned char dlen = *skb->data;
365 if ((dlen <= 16) && (dlen <= skb->len)) { 365 if ((dlen <= 16) && (dlen <= skb->len)) {
366 scp->conndata_in.opt_optl = dlen; 366 scp->conndata_in.opt_optl = dn_htons((__u16)dlen);
367 memcpy(scp->conndata_in.opt_data, skb->data + 1, dlen); 367 memcpy(scp->conndata_in.opt_data, skb->data + 1, dlen);
368 } 368 }
369 } 369 }
@@ -397,17 +397,17 @@ static void dn_nsp_disc_init(struct sock *sk, struct sk_buff *skb)
397 if (skb->len < 2) 397 if (skb->len < 2)
398 goto out; 398 goto out;
399 399
400 reason = dn_ntohs(*(__u16 *)skb->data); 400 reason = dn_ntohs(*(__le16 *)skb->data);
401 skb_pull(skb, 2); 401 skb_pull(skb, 2);
402 402
403 scp->discdata_in.opt_status = reason; 403 scp->discdata_in.opt_status = dn_htons(reason);
404 scp->discdata_in.opt_optl = 0; 404 scp->discdata_in.opt_optl = 0;
405 memset(scp->discdata_in.opt_data, 0, 16); 405 memset(scp->discdata_in.opt_data, 0, 16);
406 406
407 if (skb->len > 0) { 407 if (skb->len > 0) {
408 unsigned char dlen = *skb->data; 408 unsigned char dlen = *skb->data;
409 if ((dlen <= 16) && (dlen <= skb->len)) { 409 if ((dlen <= 16) && (dlen <= skb->len)) {
410 scp->discdata_in.opt_optl = dlen; 410 scp->discdata_in.opt_optl = dn_htons((__u16)dlen);
411 memcpy(scp->discdata_in.opt_data, skb->data + 1, dlen); 411 memcpy(scp->discdata_in.opt_data, skb->data + 1, dlen);
412 } 412 }
413 } 413 }
@@ -464,7 +464,7 @@ static void dn_nsp_disc_conf(struct sock *sk, struct sk_buff *skb)
464 if (skb->len != 2) 464 if (skb->len != 2)
465 goto out; 465 goto out;
466 466
467 reason = dn_ntohs(*(__u16 *)skb->data); 467 reason = dn_ntohs(*(__le16 *)skb->data);
468 468
469 sk->sk_state = TCP_CLOSE; 469 sk->sk_state = TCP_CLOSE;
470 470
@@ -513,7 +513,7 @@ static void dn_nsp_linkservice(struct sock *sk, struct sk_buff *skb)
513 if (skb->len != 4) 513 if (skb->len != 4)
514 goto out; 514 goto out;
515 515
516 segnum = dn_ntohs(*(__u16 *)ptr); 516 segnum = dn_ntohs(*(__le16 *)ptr);
517 ptr += 2; 517 ptr += 2;
518 lsflags = *(unsigned char *)ptr++; 518 lsflags = *(unsigned char *)ptr++;
519 fcval = *ptr; 519 fcval = *ptr;
@@ -621,7 +621,7 @@ static void dn_nsp_otherdata(struct sock *sk, struct sk_buff *skb)
621 if (skb->len < 2) 621 if (skb->len < 2)
622 goto out; 622 goto out;
623 623
624 cb->segnum = segnum = dn_ntohs(*(__u16 *)skb->data); 624 cb->segnum = segnum = dn_ntohs(*(__le16 *)skb->data);
625 skb_pull(skb, 2); 625 skb_pull(skb, 2);
626 626
627 if (seq_next(scp->numoth_rcv, segnum)) { 627 if (seq_next(scp->numoth_rcv, segnum)) {
@@ -649,7 +649,7 @@ static void dn_nsp_data(struct sock *sk, struct sk_buff *skb)
649 if (skb->len < 2) 649 if (skb->len < 2)
650 goto out; 650 goto out;
651 651
652 cb->segnum = segnum = dn_ntohs(*(__u16 *)skb->data); 652 cb->segnum = segnum = dn_ntohs(*(__le16 *)skb->data);
653 skb_pull(skb, 2); 653 skb_pull(skb, 2);
654 654
655 if (seq_next(scp->numdat_rcv, segnum)) { 655 if (seq_next(scp->numdat_rcv, segnum)) {
@@ -760,7 +760,7 @@ static int dn_nsp_rx_packet(struct sk_buff *skb)
760 /* 760 /*
761 * Grab the destination address. 761 * Grab the destination address.
762 */ 762 */
763 cb->dst_port = *(unsigned short *)ptr; 763 cb->dst_port = *(__le16 *)ptr;
764 cb->src_port = 0; 764 cb->src_port = 0;
765 ptr += 2; 765 ptr += 2;
766 766
@@ -768,7 +768,7 @@ static int dn_nsp_rx_packet(struct sk_buff *skb)
768 * If not a connack, grab the source address too. 768 * If not a connack, grab the source address too.
769 */ 769 */
770 if (pskb_may_pull(skb, 5)) { 770 if (pskb_may_pull(skb, 5)) {
771 cb->src_port = *(unsigned short *)ptr; 771 cb->src_port = *(__le16 *)ptr;
772 ptr += 2; 772 ptr += 2;
773 skb_pull(skb, 5); 773 skb_pull(skb, 5);
774 } 774 }
@@ -778,7 +778,7 @@ static int dn_nsp_rx_packet(struct sk_buff *skb)
778 * Swap src & dst and look up in the normal way. 778 * Swap src & dst and look up in the normal way.
779 */ 779 */
780 if (unlikely(cb->rt_flags & DN_RT_F_RTS)) { 780 if (unlikely(cb->rt_flags & DN_RT_F_RTS)) {
781 unsigned short tmp = cb->dst_port; 781 __le16 tmp = cb->dst_port;
782 cb->dst_port = cb->src_port; 782 cb->dst_port = cb->src_port;
783 cb->src_port = tmp; 783 cb->src_port = tmp;
784 tmp = cb->dst; 784 tmp = cb->dst;
diff --git a/net/decnet/dn_nsp_out.c b/net/decnet/dn_nsp_out.c
index c96c767b1f74..c2e21cd89b3c 100644
--- a/net/decnet/dn_nsp_out.c
+++ b/net/decnet/dn_nsp_out.c
@@ -287,26 +287,26 @@ int dn_nsp_xmit_timeout(struct sock *sk)
287 return 0; 287 return 0;
288} 288}
289 289
290static inline unsigned char *dn_mk_common_header(struct dn_scp *scp, struct sk_buff *skb, unsigned char msgflag, int len) 290static inline __le16 *dn_mk_common_header(struct dn_scp *scp, struct sk_buff *skb, unsigned char msgflag, int len)
291{ 291{
292 unsigned char *ptr = skb_push(skb, len); 292 unsigned char *ptr = skb_push(skb, len);
293 293
294 BUG_ON(len < 5); 294 BUG_ON(len < 5);
295 295
296 *ptr++ = msgflag; 296 *ptr++ = msgflag;
297 *((unsigned short *)ptr) = scp->addrrem; 297 *((__le16 *)ptr) = scp->addrrem;
298 ptr += 2; 298 ptr += 2;
299 *((unsigned short *)ptr) = scp->addrloc; 299 *((__le16 *)ptr) = scp->addrloc;
300 ptr += 2; 300 ptr += 2;
301 return ptr; 301 return (__le16 __force *)ptr;
302} 302}
303 303
304static unsigned short *dn_mk_ack_header(struct sock *sk, struct sk_buff *skb, unsigned char msgflag, int hlen, int other) 304static __le16 *dn_mk_ack_header(struct sock *sk, struct sk_buff *skb, unsigned char msgflag, int hlen, int other)
305{ 305{
306 struct dn_scp *scp = DN_SK(sk); 306 struct dn_scp *scp = DN_SK(sk);
307 unsigned short acknum = scp->numdat_rcv & 0x0FFF; 307 unsigned short acknum = scp->numdat_rcv & 0x0FFF;
308 unsigned short ackcrs = scp->numoth_rcv & 0x0FFF; 308 unsigned short ackcrs = scp->numoth_rcv & 0x0FFF;
309 unsigned short *ptr; 309 __le16 *ptr;
310 310
311 BUG_ON(hlen < 9); 311 BUG_ON(hlen < 9);
312 312
@@ -325,7 +325,7 @@ static unsigned short *dn_mk_ack_header(struct sock *sk, struct sk_buff *skb, un
325 /* Set "cross subchannel" bit in ackcrs */ 325 /* Set "cross subchannel" bit in ackcrs */
326 ackcrs |= 0x2000; 326 ackcrs |= 0x2000;
327 327
328 ptr = (unsigned short *)dn_mk_common_header(scp, skb, msgflag, hlen); 328 ptr = (__le16 *)dn_mk_common_header(scp, skb, msgflag, hlen);
329 329
330 *ptr++ = dn_htons(acknum); 330 *ptr++ = dn_htons(acknum);
331 *ptr++ = dn_htons(ackcrs); 331 *ptr++ = dn_htons(ackcrs);
@@ -333,11 +333,11 @@ static unsigned short *dn_mk_ack_header(struct sock *sk, struct sk_buff *skb, un
333 return ptr; 333 return ptr;
334} 334}
335 335
336static unsigned short *dn_nsp_mk_data_header(struct sock *sk, struct sk_buff *skb, int oth) 336static __le16 *dn_nsp_mk_data_header(struct sock *sk, struct sk_buff *skb, int oth)
337{ 337{
338 struct dn_scp *scp = DN_SK(sk); 338 struct dn_scp *scp = DN_SK(sk);
339 struct dn_skb_cb *cb = DN_SKB_CB(skb); 339 struct dn_skb_cb *cb = DN_SKB_CB(skb);
340 unsigned short *ptr = dn_mk_ack_header(sk, skb, cb->nsp_flags, 11, oth); 340 __le16 *ptr = dn_mk_ack_header(sk, skb, cb->nsp_flags, 11, oth);
341 341
342 if (unlikely(oth)) { 342 if (unlikely(oth)) {
343 cb->segnum = scp->numoth; 343 cb->segnum = scp->numoth;
@@ -524,9 +524,9 @@ void dn_send_conn_conf(struct sock *sk, gfp_t gfp)
524 struct dn_scp *scp = DN_SK(sk); 524 struct dn_scp *scp = DN_SK(sk);
525 struct sk_buff *skb = NULL; 525 struct sk_buff *skb = NULL;
526 struct nsp_conn_init_msg *msg; 526 struct nsp_conn_init_msg *msg;
527 unsigned char len = scp->conndata_out.opt_optl; 527 __u8 len = (__u8)dn_ntohs(scp->conndata_out.opt_optl);
528 528
529 if ((skb = dn_alloc_skb(sk, 50 + scp->conndata_out.opt_optl, gfp)) == NULL) 529 if ((skb = dn_alloc_skb(sk, 50 + dn_ntohs(scp->conndata_out.opt_optl), gfp)) == NULL)
530 return; 530 return;
531 531
532 msg = (struct nsp_conn_init_msg *)skb_put(skb, sizeof(*msg)); 532 msg = (struct nsp_conn_init_msg *)skb_put(skb, sizeof(*msg));
@@ -553,7 +553,7 @@ void dn_send_conn_conf(struct sock *sk, gfp_t gfp)
553static __inline__ void dn_nsp_do_disc(struct sock *sk, unsigned char msgflg, 553static __inline__ void dn_nsp_do_disc(struct sock *sk, unsigned char msgflg,
554 unsigned short reason, gfp_t gfp, 554 unsigned short reason, gfp_t gfp,
555 struct dst_entry *dst, 555 struct dst_entry *dst,
556 int ddl, unsigned char *dd, __u16 rem, __u16 loc) 556 int ddl, unsigned char *dd, __le16 rem, __le16 loc)
557{ 557{
558 struct sk_buff *skb = NULL; 558 struct sk_buff *skb = NULL;
559 int size = 7 + ddl + ((msgflg == NSP_DISCINIT) ? 1 : 0); 559 int size = 7 + ddl + ((msgflg == NSP_DISCINIT) ? 1 : 0);
@@ -561,7 +561,7 @@ static __inline__ void dn_nsp_do_disc(struct sock *sk, unsigned char msgflg,
561 561
562 if ((dst == NULL) || (rem == 0)) { 562 if ((dst == NULL) || (rem == 0)) {
563 if (net_ratelimit()) 563 if (net_ratelimit())
564 printk(KERN_DEBUG "DECnet: dn_nsp_do_disc: BUG! Please report this to SteveW@ACM.org rem=%u dst=%p\n", (unsigned)rem, dst); 564 printk(KERN_DEBUG "DECnet: dn_nsp_do_disc: BUG! Please report this to SteveW@ACM.org rem=%u dst=%p\n", dn_ntohs(rem), dst);
565 return; 565 return;
566 } 566 }
567 567
@@ -570,11 +570,11 @@ static __inline__ void dn_nsp_do_disc(struct sock *sk, unsigned char msgflg,
570 570
571 msg = skb_put(skb, size); 571 msg = skb_put(skb, size);
572 *msg++ = msgflg; 572 *msg++ = msgflg;
573 *(__u16 *)msg = rem; 573 *(__le16 *)msg = rem;
574 msg += 2; 574 msg += 2;
575 *(__u16 *)msg = loc; 575 *(__le16 *)msg = loc;
576 msg += 2; 576 msg += 2;
577 *(__u16 *)msg = dn_htons(reason); 577 *(__le16 *)msg = dn_htons(reason);
578 msg += 2; 578 msg += 2;
579 if (msgflg == NSP_DISCINIT) 579 if (msgflg == NSP_DISCINIT)
580 *msg++ = ddl; 580 *msg++ = ddl;
@@ -600,10 +600,10 @@ void dn_nsp_send_disc(struct sock *sk, unsigned char msgflg,
600 int ddl = 0; 600 int ddl = 0;
601 601
602 if (msgflg == NSP_DISCINIT) 602 if (msgflg == NSP_DISCINIT)
603 ddl = scp->discdata_out.opt_optl; 603 ddl = dn_ntohs(scp->discdata_out.opt_optl);
604 604
605 if (reason == 0) 605 if (reason == 0)
606 reason = scp->discdata_out.opt_status; 606 reason = dn_ntohs(scp->discdata_out.opt_status);
607 607
608 dn_nsp_do_disc(sk, msgflg, reason, gfp, sk->sk_dst_cache, ddl, 608 dn_nsp_do_disc(sk, msgflg, reason, gfp, sk->sk_dst_cache, ddl,
609 scp->discdata_out.opt_data, scp->addrrem, scp->addrloc); 609 scp->discdata_out.opt_data, scp->addrrem, scp->addrloc);
@@ -708,7 +708,7 @@ void dn_nsp_send_conninit(struct sock *sk, unsigned char msgflg)
708 if (aux > 0) 708 if (aux > 0)
709 memcpy(skb_put(skb, aux), scp->accessdata.acc_acc, aux); 709 memcpy(skb_put(skb, aux), scp->accessdata.acc_acc, aux);
710 710
711 aux = scp->conndata_out.opt_optl; 711 aux = (__u8)dn_ntohs(scp->conndata_out.opt_optl);
712 *skb_put(skb, 1) = aux; 712 *skb_put(skb, 1) = aux;
713 if (aux > 0) 713 if (aux > 0)
714 memcpy(skb_put(skb,aux), scp->conndata_out.opt_data, aux); 714 memcpy(skb_put(skb,aux), scp->conndata_out.opt_data, aux);
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 3407f190afe8..e172cf98d7fc 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -133,9 +133,9 @@ static struct dst_ops dn_dst_ops = {
133 .entries = ATOMIC_INIT(0), 133 .entries = ATOMIC_INIT(0),
134}; 134};
135 135
136static __inline__ unsigned dn_hash(unsigned short src, unsigned short dst) 136static __inline__ unsigned dn_hash(__le16 src, __le16 dst)
137{ 137{
138 unsigned short tmp = src ^ dst; 138 __u16 tmp = (__u16 __force)(src ^ dst);
139 tmp ^= (tmp >> 3); 139 tmp ^= (tmp >> 3);
140 tmp ^= (tmp >> 5); 140 tmp ^= (tmp >> 5);
141 tmp ^= (tmp >> 10); 141 tmp ^= (tmp >> 10);
@@ -149,8 +149,7 @@ static inline void dnrt_free(struct dn_route *rt)
149 149
150static inline void dnrt_drop(struct dn_route *rt) 150static inline void dnrt_drop(struct dn_route *rt)
151{ 151{
152 if (rt) 152 dst_release(&rt->u.dst);
153 dst_release(&rt->u.dst);
154 call_rcu_bh(&rt->u.dst.rcu_head, dst_rcu_free); 153 call_rcu_bh(&rt->u.dst.rcu_head, dst_rcu_free);
155} 154}
156 155
@@ -379,9 +378,9 @@ static int dn_return_short(struct sk_buff *skb)
379{ 378{
380 struct dn_skb_cb *cb; 379 struct dn_skb_cb *cb;
381 unsigned char *ptr; 380 unsigned char *ptr;
382 dn_address *src; 381 __le16 *src;
383 dn_address *dst; 382 __le16 *dst;
384 dn_address tmp; 383 __le16 tmp;
385 384
386 /* Add back headers */ 385 /* Add back headers */
387 skb_push(skb, skb->data - skb->nh.raw); 386 skb_push(skb, skb->data - skb->nh.raw);
@@ -394,9 +393,9 @@ static int dn_return_short(struct sk_buff *skb)
394 ptr = skb->data + 2; 393 ptr = skb->data + 2;
395 *ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS; 394 *ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;
396 395
397 dst = (dn_address *)ptr; 396 dst = (__le16 *)ptr;
398 ptr += 2; 397 ptr += 2;
399 src = (dn_address *)ptr; 398 src = (__le16 *)ptr;
400 ptr += 2; 399 ptr += 2;
401 *ptr = 0; /* Zero hop count */ 400 *ptr = 0; /* Zero hop count */
402 401
@@ -475,7 +474,8 @@ static int dn_route_rx_packet(struct sk_buff *skb)
475 struct dn_skb_cb *cb = DN_SKB_CB(skb); 474 struct dn_skb_cb *cb = DN_SKB_CB(skb);
476 printk(KERN_DEBUG 475 printk(KERN_DEBUG
477 "DECnet: dn_route_rx_packet: rt_flags=0x%02x dev=%s len=%d src=0x%04hx dst=0x%04hx err=%d type=%d\n", 476 "DECnet: dn_route_rx_packet: rt_flags=0x%02x dev=%s len=%d src=0x%04hx dst=0x%04hx err=%d type=%d\n",
478 (int)cb->rt_flags, devname, skb->len, cb->src, cb->dst, 477 (int)cb->rt_flags, devname, skb->len,
478 dn_ntohs(cb->src), dn_ntohs(cb->dst),
479 err, skb->pkt_type); 479 err, skb->pkt_type);
480 } 480 }
481 481
@@ -505,7 +505,7 @@ static int dn_route_rx_long(struct sk_buff *skb)
505 505
506 /* Destination info */ 506 /* Destination info */
507 ptr += 2; 507 ptr += 2;
508 cb->dst = dn_htons(dn_eth2dn(ptr)); 508 cb->dst = dn_eth2dn(ptr);
509 if (memcmp(ptr, dn_hiord_addr, 4) != 0) 509 if (memcmp(ptr, dn_hiord_addr, 4) != 0)
510 goto drop_it; 510 goto drop_it;
511 ptr += 6; 511 ptr += 6;
@@ -513,7 +513,7 @@ static int dn_route_rx_long(struct sk_buff *skb)
513 513
514 /* Source info */ 514 /* Source info */
515 ptr += 2; 515 ptr += 2;
516 cb->src = dn_htons(dn_eth2dn(ptr)); 516 cb->src = dn_eth2dn(ptr);
517 if (memcmp(ptr, dn_hiord_addr, 4) != 0) 517 if (memcmp(ptr, dn_hiord_addr, 4) != 0)
518 goto drop_it; 518 goto drop_it;
519 ptr += 6; 519 ptr += 6;
@@ -541,9 +541,9 @@ static int dn_route_rx_short(struct sk_buff *skb)
541 skb_pull(skb, 5); 541 skb_pull(skb, 5);
542 skb->h.raw = skb->data; 542 skb->h.raw = skb->data;
543 543
544 cb->dst = *(dn_address *)ptr; 544 cb->dst = *(__le16 *)ptr;
545 ptr += 2; 545 ptr += 2;
546 cb->src = *(dn_address *)ptr; 546 cb->src = *(__le16 *)ptr;
547 ptr += 2; 547 ptr += 2;
548 cb->hops = *ptr & 0x3f; 548 cb->hops = *ptr & 0x3f;
549 549
@@ -575,7 +575,7 @@ int dn_route_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type
575{ 575{
576 struct dn_skb_cb *cb; 576 struct dn_skb_cb *cb;
577 unsigned char flags = 0; 577 unsigned char flags = 0;
578 __u16 len = dn_ntohs(*(__u16 *)skb->data); 578 __u16 len = dn_ntohs(*(__le16 *)skb->data);
579 struct dn_dev *dn = (struct dn_dev *)dev->dn_ptr; 579 struct dn_dev *dn = (struct dn_dev *)dev->dn_ptr;
580 unsigned char padlen = 0; 580 unsigned char padlen = 0;
581 581
@@ -782,7 +782,7 @@ static int dn_rt_bug(struct sk_buff *skb)
782 struct dn_skb_cb *cb = DN_SKB_CB(skb); 782 struct dn_skb_cb *cb = DN_SKB_CB(skb);
783 783
784 printk(KERN_DEBUG "dn_rt_bug: skb from:%04x to:%04x\n", 784 printk(KERN_DEBUG "dn_rt_bug: skb from:%04x to:%04x\n",
785 cb->src, cb->dst); 785 dn_ntohs(cb->src), dn_ntohs(cb->dst));
786 } 786 }
787 787
788 kfree_skb(skb); 788 kfree_skb(skb);
@@ -823,7 +823,7 @@ static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)
823 return 0; 823 return 0;
824} 824}
825 825
826static inline int dn_match_addr(__u16 addr1, __u16 addr2) 826static inline int dn_match_addr(__le16 addr1, __le16 addr2)
827{ 827{
828 __u16 tmp = dn_ntohs(addr1) ^ dn_ntohs(addr2); 828 __u16 tmp = dn_ntohs(addr1) ^ dn_ntohs(addr2);
829 int match = 16; 829 int match = 16;
@@ -834,9 +834,9 @@ static inline int dn_match_addr(__u16 addr1, __u16 addr2)
834 return match; 834 return match;
835} 835}
836 836
837static __u16 dnet_select_source(const struct net_device *dev, __u16 daddr, int scope) 837static __le16 dnet_select_source(const struct net_device *dev, __le16 daddr, int scope)
838{ 838{
839 __u16 saddr = 0; 839 __le16 saddr = 0;
840 struct dn_dev *dn_db = dev->dn_ptr; 840 struct dn_dev *dn_db = dev->dn_ptr;
841 struct dn_ifaddr *ifa; 841 struct dn_ifaddr *ifa;
842 int best_match = 0; 842 int best_match = 0;
@@ -861,14 +861,14 @@ static __u16 dnet_select_source(const struct net_device *dev, __u16 daddr, int s
861 return saddr; 861 return saddr;
862} 862}
863 863
864static inline __u16 __dn_fib_res_prefsrc(struct dn_fib_res *res) 864static inline __le16 __dn_fib_res_prefsrc(struct dn_fib_res *res)
865{ 865{
866 return dnet_select_source(DN_FIB_RES_DEV(*res), DN_FIB_RES_GW(*res), res->scope); 866 return dnet_select_source(DN_FIB_RES_DEV(*res), DN_FIB_RES_GW(*res), res->scope);
867} 867}
868 868
869static inline __u16 dn_fib_rules_map_destination(__u16 daddr, struct dn_fib_res *res) 869static inline __le16 dn_fib_rules_map_destination(__le16 daddr, struct dn_fib_res *res)
870{ 870{
871 __u16 mask = dnet_make_mask(res->prefixlen); 871 __le16 mask = dnet_make_mask(res->prefixlen);
872 return (daddr&~mask)|res->fi->fib_nh->nh_gw; 872 return (daddr&~mask)|res->fi->fib_nh->nh_gw;
873} 873}
874 874
@@ -892,12 +892,13 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *old
892 struct dn_fib_res res = { .fi = NULL, .type = RTN_UNICAST }; 892 struct dn_fib_res res = { .fi = NULL, .type = RTN_UNICAST };
893 int err; 893 int err;
894 int free_res = 0; 894 int free_res = 0;
895 __u16 gateway = 0; 895 __le16 gateway = 0;
896 896
897 if (decnet_debug_level & 16) 897 if (decnet_debug_level & 16)
898 printk(KERN_DEBUG 898 printk(KERN_DEBUG
899 "dn_route_output_slow: dst=%04x src=%04x mark=%d" 899 "dn_route_output_slow: dst=%04x src=%04x mark=%d"
900 " iif=%d oif=%d\n", oldflp->fld_dst, oldflp->fld_src, 900 " iif=%d oif=%d\n", dn_ntohs(oldflp->fld_dst),
901 dn_ntohs(oldflp->fld_src),
901 oldflp->fld_fwmark, loopback_dev.ifindex, oldflp->oif); 902 oldflp->fld_fwmark, loopback_dev.ifindex, oldflp->oif);
902 903
903 /* If we have an output interface, verify its a DECnet device */ 904 /* If we have an output interface, verify its a DECnet device */
@@ -961,8 +962,9 @@ source_ok:
961 if (decnet_debug_level & 16) 962 if (decnet_debug_level & 16)
962 printk(KERN_DEBUG 963 printk(KERN_DEBUG
963 "dn_route_output_slow: initial checks complete." 964 "dn_route_output_slow: initial checks complete."
964 " dst=%o4x src=%04x oif=%d try_hard=%d\n", fl.fld_dst, 965 " dst=%o4x src=%04x oif=%d try_hard=%d\n",
965 fl.fld_src, fl.oif, try_hard); 966 dn_ntohs(fl.fld_dst), dn_ntohs(fl.fld_src),
967 fl.oif, try_hard);
966 968
967 /* 969 /*
968 * N.B. If the kernel is compiled without router support then 970 * N.B. If the kernel is compiled without router support then
@@ -1218,8 +1220,8 @@ static int dn_route_input_slow(struct sk_buff *skb)
1218 struct neighbour *neigh = NULL; 1220 struct neighbour *neigh = NULL;
1219 unsigned hash; 1221 unsigned hash;
1220 int flags = 0; 1222 int flags = 0;
1221 __u16 gateway = 0; 1223 __le16 gateway = 0;
1222 __u16 local_src = 0; 1224 __le16 local_src = 0;
1223 struct flowi fl = { .nl_u = { .dn_u = 1225 struct flowi fl = { .nl_u = { .dn_u =
1224 { .daddr = cb->dst, 1226 { .daddr = cb->dst,
1225 .saddr = cb->src, 1227 .saddr = cb->src,
@@ -1266,7 +1268,7 @@ static int dn_route_input_slow(struct sk_buff *skb)
1266 res.type = RTN_LOCAL; 1268 res.type = RTN_LOCAL;
1267 flags |= RTCF_DIRECTSRC; 1269 flags |= RTCF_DIRECTSRC;
1268 } else { 1270 } else {
1269 __u16 src_map = fl.fld_src; 1271 __le16 src_map = fl.fld_src;
1270 free_res = 1; 1272 free_res = 1;
1271 1273
1272 out_dev = DN_FIB_RES_DEV(res); 1274 out_dev = DN_FIB_RES_DEV(res);
diff --git a/net/decnet/dn_rules.c b/net/decnet/dn_rules.c
index 1060de70bc0c..446faafe2065 100644
--- a/net/decnet/dn_rules.c
+++ b/net/decnet/dn_rules.c
@@ -27,6 +27,8 @@
27#include <linux/timer.h> 27#include <linux/timer.h>
28#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29#include <linux/in_route.h> 29#include <linux/in_route.h>
30#include <linux/list.h>
31#include <linux/rcupdate.h>
30#include <asm/atomic.h> 32#include <asm/atomic.h>
31#include <asm/uaccess.h> 33#include <asm/uaccess.h>
32#include <net/neighbour.h> 34#include <net/neighbour.h>
@@ -39,18 +41,18 @@
39 41
40struct dn_fib_rule 42struct dn_fib_rule
41{ 43{
42 struct dn_fib_rule *r_next; 44 struct hlist_node r_hlist;
43 atomic_t r_clntref; 45 atomic_t r_clntref;
44 u32 r_preference; 46 u32 r_preference;
45 unsigned char r_table; 47 unsigned char r_table;
46 unsigned char r_action; 48 unsigned char r_action;
47 unsigned char r_dst_len; 49 unsigned char r_dst_len;
48 unsigned char r_src_len; 50 unsigned char r_src_len;
49 dn_address r_src; 51 __le16 r_src;
50 dn_address r_srcmask; 52 __le16 r_srcmask;
51 dn_address r_dst; 53 __le16 r_dst;
52 dn_address r_dstmask; 54 __le16 r_dstmask;
53 dn_address r_srcmap; 55 __le16 r_srcmap;
54 u8 r_flags; 56 u8 r_flags;
55#ifdef CONFIG_DECNET_ROUTE_FWMARK 57#ifdef CONFIG_DECNET_ROUTE_FWMARK
56 u32 r_fwmark; 58 u32 r_fwmark;
@@ -58,6 +60,7 @@ struct dn_fib_rule
58 int r_ifindex; 60 int r_ifindex;
59 char r_ifname[IFNAMSIZ]; 61 char r_ifname[IFNAMSIZ];
60 int r_dead; 62 int r_dead;
63 struct rcu_head rcu;
61}; 64};
62 65
63static struct dn_fib_rule default_rule = { 66static struct dn_fib_rule default_rule = {
@@ -67,18 +70,17 @@ static struct dn_fib_rule default_rule = {
67 .r_action = RTN_UNICAST 70 .r_action = RTN_UNICAST
68}; 71};
69 72
70static struct dn_fib_rule *dn_fib_rules = &default_rule; 73static struct hlist_head dn_fib_rules;
71static DEFINE_RWLOCK(dn_fib_rules_lock);
72
73 74
74int dn_fib_rtm_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 75int dn_fib_rtm_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
75{ 76{
76 struct rtattr **rta = arg; 77 struct rtattr **rta = arg;
77 struct rtmsg *rtm = NLMSG_DATA(nlh); 78 struct rtmsg *rtm = NLMSG_DATA(nlh);
78 struct dn_fib_rule *r, **rp; 79 struct dn_fib_rule *r;
80 struct hlist_node *node;
79 int err = -ESRCH; 81 int err = -ESRCH;
80 82
81 for(rp=&dn_fib_rules; (r=*rp) != NULL; rp = &r->r_next) { 83 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) {
82 if ((!rta[RTA_SRC-1] || memcmp(RTA_DATA(rta[RTA_SRC-1]), &r->r_src, 2) == 0) && 84 if ((!rta[RTA_SRC-1] || memcmp(RTA_DATA(rta[RTA_SRC-1]), &r->r_src, 2) == 0) &&
83 rtm->rtm_src_len == r->r_src_len && 85 rtm->rtm_src_len == r->r_src_len &&
84 rtm->rtm_dst_len == r->r_dst_len && 86 rtm->rtm_dst_len == r->r_dst_len &&
@@ -95,10 +97,8 @@ int dn_fib_rtm_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
95 if (r == &default_rule) 97 if (r == &default_rule)
96 break; 98 break;
97 99
98 write_lock_bh(&dn_fib_rules_lock); 100 hlist_del_rcu(&r->r_hlist);
99 *rp = r->r_next;
100 r->r_dead = 1; 101 r->r_dead = 1;
101 write_unlock_bh(&dn_fib_rules_lock);
102 dn_fib_rule_put(r); 102 dn_fib_rule_put(r);
103 err = 0; 103 err = 0;
104 break; 104 break;
@@ -108,11 +108,17 @@ int dn_fib_rtm_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
108 return err; 108 return err;
109} 109}
110 110
111static inline void dn_fib_rule_put_rcu(struct rcu_head *head)
112{
113 struct dn_fib_rule *r = container_of(head, struct dn_fib_rule, rcu);
114 kfree(r);
115}
116
111void dn_fib_rule_put(struct dn_fib_rule *r) 117void dn_fib_rule_put(struct dn_fib_rule *r)
112{ 118{
113 if (atomic_dec_and_test(&r->r_clntref)) { 119 if (atomic_dec_and_test(&r->r_clntref)) {
114 if (r->r_dead) 120 if (r->r_dead)
115 kfree(r); 121 call_rcu(&r->rcu, dn_fib_rule_put_rcu);
116 else 122 else
117 printk(KERN_DEBUG "Attempt to free alive dn_fib_rule\n"); 123 printk(KERN_DEBUG "Attempt to free alive dn_fib_rule\n");
118 } 124 }
@@ -123,7 +129,8 @@ int dn_fib_rtm_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
123{ 129{
124 struct rtattr **rta = arg; 130 struct rtattr **rta = arg;
125 struct rtmsg *rtm = NLMSG_DATA(nlh); 131 struct rtmsg *rtm = NLMSG_DATA(nlh);
126 struct dn_fib_rule *r, *new_r, **rp; 132 struct dn_fib_rule *r, *new_r, *last = NULL;
133 struct hlist_node *node = NULL;
127 unsigned char table_id; 134 unsigned char table_id;
128 135
129 if (rtm->rtm_src_len > 16 || rtm->rtm_dst_len > 16) 136 if (rtm->rtm_src_len > 16 || rtm->rtm_dst_len > 16)
@@ -149,6 +156,7 @@ int dn_fib_rtm_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
149 if (!new_r) 156 if (!new_r)
150 return -ENOMEM; 157 return -ENOMEM;
151 memset(new_r, 0, sizeof(*new_r)); 158 memset(new_r, 0, sizeof(*new_r));
159
152 if (rta[RTA_SRC-1]) 160 if (rta[RTA_SRC-1])
153 memcpy(&new_r->r_src, RTA_DATA(rta[RTA_SRC-1]), 2); 161 memcpy(&new_r->r_src, RTA_DATA(rta[RTA_SRC-1]), 2);
154 if (rta[RTA_DST-1]) 162 if (rta[RTA_DST-1])
@@ -179,27 +187,26 @@ int dn_fib_rtm_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
179 } 187 }
180 } 188 }
181 189
182 rp = &dn_fib_rules; 190 r = container_of(dn_fib_rules.first, struct dn_fib_rule, r_hlist);
183 if (!new_r->r_preference) { 191 if (!new_r->r_preference) {
184 r = dn_fib_rules; 192 if (r && r->r_hlist.next != NULL) {
185 if (r && (r = r->r_next) != NULL) { 193 r = container_of(r->r_hlist.next, struct dn_fib_rule, r_hlist);
186 rp = &dn_fib_rules->r_next;
187 if (r->r_preference) 194 if (r->r_preference)
188 new_r->r_preference = r->r_preference - 1; 195 new_r->r_preference = r->r_preference - 1;
189 } 196 }
190 } 197 }
191 198
192 while((r=*rp) != NULL) { 199 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) {
193 if (r->r_preference > new_r->r_preference) 200 if (r->r_preference > new_r->r_preference)
194 break; 201 break;
195 rp = &r->r_next; 202 last = r;
196 } 203 }
197
198 new_r->r_next = r;
199 atomic_inc(&new_r->r_clntref); 204 atomic_inc(&new_r->r_clntref);
200 write_lock_bh(&dn_fib_rules_lock); 205
201 *rp = new_r; 206 if (last)
202 write_unlock_bh(&dn_fib_rules_lock); 207 hlist_add_after_rcu(&last->r_hlist, &new_r->r_hlist);
208 else
209 hlist_add_before_rcu(&new_r->r_hlist, &r->r_hlist);
203 return 0; 210 return 0;
204} 211}
205 212
@@ -208,12 +215,14 @@ int dn_fib_lookup(const struct flowi *flp, struct dn_fib_res *res)
208{ 215{
209 struct dn_fib_rule *r, *policy; 216 struct dn_fib_rule *r, *policy;
210 struct dn_fib_table *tb; 217 struct dn_fib_table *tb;
211 dn_address saddr = flp->fld_src; 218 __le16 saddr = flp->fld_src;
212 dn_address daddr = flp->fld_dst; 219 __le16 daddr = flp->fld_dst;
220 struct hlist_node *node;
213 int err; 221 int err;
214 222
215 read_lock(&dn_fib_rules_lock); 223 rcu_read_lock();
216 for(r = dn_fib_rules; r; r = r->r_next) { 224
225 hlist_for_each_entry_rcu(r, node, &dn_fib_rules, r_hlist) {
217 if (((saddr^r->r_src) & r->r_srcmask) || 226 if (((saddr^r->r_src) & r->r_srcmask) ||
218 ((daddr^r->r_dst) & r->r_dstmask) || 227 ((daddr^r->r_dst) & r->r_dstmask) ||
219#ifdef CONFIG_DECNET_ROUTE_FWMARK 228#ifdef CONFIG_DECNET_ROUTE_FWMARK
@@ -228,14 +237,14 @@ int dn_fib_lookup(const struct flowi *flp, struct dn_fib_res *res)
228 policy = r; 237 policy = r;
229 break; 238 break;
230 case RTN_UNREACHABLE: 239 case RTN_UNREACHABLE:
231 read_unlock(&dn_fib_rules_lock); 240 rcu_read_unlock();
232 return -ENETUNREACH; 241 return -ENETUNREACH;
233 default: 242 default:
234 case RTN_BLACKHOLE: 243 case RTN_BLACKHOLE:
235 read_unlock(&dn_fib_rules_lock); 244 rcu_read_unlock();
236 return -EINVAL; 245 return -EINVAL;
237 case RTN_PROHIBIT: 246 case RTN_PROHIBIT:
238 read_unlock(&dn_fib_rules_lock); 247 rcu_read_unlock();
239 return -EACCES; 248 return -EACCES;
240 } 249 }
241 250
@@ -246,20 +255,20 @@ int dn_fib_lookup(const struct flowi *flp, struct dn_fib_res *res)
246 res->r = policy; 255 res->r = policy;
247 if (policy) 256 if (policy)
248 atomic_inc(&policy->r_clntref); 257 atomic_inc(&policy->r_clntref);
249 read_unlock(&dn_fib_rules_lock); 258 rcu_read_unlock();
250 return 0; 259 return 0;
251 } 260 }
252 if (err < 0 && err != -EAGAIN) { 261 if (err < 0 && err != -EAGAIN) {
253 read_unlock(&dn_fib_rules_lock); 262 rcu_read_unlock();
254 return err; 263 return err;
255 } 264 }
256 } 265 }
257 266
258 read_unlock(&dn_fib_rules_lock); 267 rcu_read_unlock();
259 return -ESRCH; 268 return -ESRCH;
260} 269}
261 270
262unsigned dnet_addr_type(__u16 addr) 271unsigned dnet_addr_type(__le16 addr)
263{ 272{
264 struct flowi fl = { .nl_u = { .dn_u = { .daddr = addr } } }; 273 struct flowi fl = { .nl_u = { .dn_u = { .daddr = addr } } };
265 struct dn_fib_res res; 274 struct dn_fib_res res;
@@ -277,7 +286,7 @@ unsigned dnet_addr_type(__u16 addr)
277 return ret; 286 return ret;
278} 287}
279 288
280__u16 dn_fib_rules_policy(__u16 saddr, struct dn_fib_res *res, unsigned *flags) 289__le16 dn_fib_rules_policy(__le16 saddr, struct dn_fib_res *res, unsigned *flags)
281{ 290{
282 struct dn_fib_rule *r = res->r; 291 struct dn_fib_rule *r = res->r;
283 292
@@ -297,27 +306,23 @@ __u16 dn_fib_rules_policy(__u16 saddr, struct dn_fib_res *res, unsigned *flags)
297 306
298static void dn_fib_rules_detach(struct net_device *dev) 307static void dn_fib_rules_detach(struct net_device *dev)
299{ 308{
309 struct hlist_node *node;
300 struct dn_fib_rule *r; 310 struct dn_fib_rule *r;
301 311
302 for(r = dn_fib_rules; r; r = r->r_next) { 312 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) {
303 if (r->r_ifindex == dev->ifindex) { 313 if (r->r_ifindex == dev->ifindex)
304 write_lock_bh(&dn_fib_rules_lock);
305 r->r_ifindex = -1; 314 r->r_ifindex = -1;
306 write_unlock_bh(&dn_fib_rules_lock);
307 }
308 } 315 }
309} 316}
310 317
311static void dn_fib_rules_attach(struct net_device *dev) 318static void dn_fib_rules_attach(struct net_device *dev)
312{ 319{
320 struct hlist_node *node;
313 struct dn_fib_rule *r; 321 struct dn_fib_rule *r;
314 322
315 for(r = dn_fib_rules; r; r = r->r_next) { 323 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) {
316 if (r->r_ifindex == -1 && strcmp(dev->name, r->r_ifname) == 0) { 324 if (r->r_ifindex == -1 && strcmp(dev->name, r->r_ifname) == 0)
317 write_lock_bh(&dn_fib_rules_lock);
318 r->r_ifindex = dev->ifindex; 325 r->r_ifindex = dev->ifindex;
319 write_unlock_bh(&dn_fib_rules_lock);
320 }
321 } 326 }
322} 327}
323 328
@@ -387,18 +392,20 @@ rtattr_failure:
387 392
388int dn_fib_dump_rules(struct sk_buff *skb, struct netlink_callback *cb) 393int dn_fib_dump_rules(struct sk_buff *skb, struct netlink_callback *cb)
389{ 394{
390 int idx; 395 int idx = 0;
391 int s_idx = cb->args[0]; 396 int s_idx = cb->args[0];
392 struct dn_fib_rule *r; 397 struct dn_fib_rule *r;
398 struct hlist_node *node;
393 399
394 read_lock(&dn_fib_rules_lock); 400 rcu_read_lock();
395 for(r = dn_fib_rules, idx = 0; r; r = r->r_next, idx++) { 401 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) {
396 if (idx < s_idx) 402 if (idx < s_idx)
397 continue; 403 continue;
398 if (dn_fib_fill_rule(skb, r, cb, NLM_F_MULTI) < 0) 404 if (dn_fib_fill_rule(skb, r, cb, NLM_F_MULTI) < 0)
399 break; 405 break;
406 idx++;
400 } 407 }
401 read_unlock(&dn_fib_rules_lock); 408 rcu_read_unlock();
402 cb->args[0] = idx; 409 cb->args[0] = idx;
403 410
404 return skb->len; 411 return skb->len;
@@ -406,6 +413,8 @@ int dn_fib_dump_rules(struct sk_buff *skb, struct netlink_callback *cb)
406 413
407void __init dn_fib_rules_init(void) 414void __init dn_fib_rules_init(void)
408{ 415{
416 INIT_HLIST_HEAD(&dn_fib_rules);
417 hlist_add_head(&default_rule.r_hlist, &dn_fib_rules);
409 register_netdevice_notifier(&dn_fib_rules_notifier); 418 register_netdevice_notifier(&dn_fib_rules_notifier);
410} 419}
411 420
diff --git a/net/decnet/dn_table.c b/net/decnet/dn_table.c
index 6f8b5658cb4e..0ebc46af1bdd 100644
--- a/net/decnet/dn_table.c
+++ b/net/decnet/dn_table.c
@@ -46,7 +46,7 @@ struct dn_zone
46 u32 dz_hashmask; 46 u32 dz_hashmask;
47#define DZ_HASHMASK(dz) ((dz)->dz_hashmask) 47#define DZ_HASHMASK(dz) ((dz)->dz_hashmask)
48 int dz_order; 48 int dz_order;
49 u16 dz_mask; 49 __le16 dz_mask;
50#define DZ_MASK(dz) ((dz)->dz_mask) 50#define DZ_MASK(dz) ((dz)->dz_mask)
51}; 51};
52 52
@@ -84,14 +84,14 @@ static int dn_fib_hash_zombies;
84 84
85static inline dn_fib_idx_t dn_hash(dn_fib_key_t key, struct dn_zone *dz) 85static inline dn_fib_idx_t dn_hash(dn_fib_key_t key, struct dn_zone *dz)
86{ 86{
87 u16 h = ntohs(key.datum)>>(16 - dz->dz_order); 87 u16 h = dn_ntohs(key.datum)>>(16 - dz->dz_order);
88 h ^= (h >> 10); 88 h ^= (h >> 10);
89 h ^= (h >> 6); 89 h ^= (h >> 6);
90 h &= DZ_HASHMASK(dz); 90 h &= DZ_HASHMASK(dz);
91 return *(dn_fib_idx_t *)&h; 91 return *(dn_fib_idx_t *)&h;
92} 92}
93 93
94static inline dn_fib_key_t dz_key(u16 dst, struct dn_zone *dz) 94static inline dn_fib_key_t dz_key(__le16 dst, struct dn_zone *dz)
95{ 95{
96 dn_fib_key_t k; 96 dn_fib_key_t k;
97 k.datum = dst & DZ_MASK(dz); 97 k.datum = dst & DZ_MASK(dz);
@@ -250,7 +250,7 @@ static int dn_fib_nh_match(struct rtmsg *r, struct nlmsghdr *nlh, struct dn_kern
250 250
251 for_nexthops(fi) { 251 for_nexthops(fi) {
252 int attrlen = nhlen - sizeof(struct rtnexthop); 252 int attrlen = nhlen - sizeof(struct rtnexthop);
253 dn_address gw; 253 __le16 gw;
254 254
255 if (attrlen < 0 || (nhlen -= nhp->rtnh_len) < 0) 255 if (attrlen < 0 || (nhlen -= nhp->rtnh_len) < 0)
256 return -EINVAL; 256 return -EINVAL;
@@ -457,7 +457,7 @@ static int dn_fib_table_insert(struct dn_fib_table *tb, struct rtmsg *r, struct
457 457
458 dz_key_0(key); 458 dz_key_0(key);
459 if (rta->rta_dst) { 459 if (rta->rta_dst) {
460 dn_address dst; 460 __le16 dst;
461 memcpy(&dst, rta->rta_dst, 2); 461 memcpy(&dst, rta->rta_dst, 2);
462 if (dst & ~DZ_MASK(dz)) 462 if (dst & ~DZ_MASK(dz))
463 return -EINVAL; 463 return -EINVAL;
@@ -593,7 +593,7 @@ static int dn_fib_table_delete(struct dn_fib_table *tb, struct rtmsg *r, struct
593 593
594 dz_key_0(key); 594 dz_key_0(key);
595 if (rta->rta_dst) { 595 if (rta->rta_dst) {
596 dn_address dst; 596 __le16 dst;
597 memcpy(&dst, rta->rta_dst, 2); 597 memcpy(&dst, rta->rta_dst, 2);
598 if (dst & ~DZ_MASK(dz)) 598 if (dst & ~DZ_MASK(dz))
599 return -EINVAL; 599 return -EINVAL;
diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
index 0e9d2c571165..bda5920215fd 100644
--- a/net/decnet/sysctl_net_decnet.c
+++ b/net/decnet/sysctl_net_decnet.c
@@ -86,9 +86,9 @@ static void strip_it(char *str)
86 * Simple routine to parse an ascii DECnet address 86 * Simple routine to parse an ascii DECnet address
87 * into a network order address. 87 * into a network order address.
88 */ 88 */
89static int parse_addr(dn_address *addr, char *str) 89static int parse_addr(__le16 *addr, char *str)
90{ 90{
91 dn_address area, node; 91 __u16 area, node;
92 92
93 while(*str && !ISNUM(*str)) str++; 93 while(*str && !ISNUM(*str)) str++;
94 94
@@ -139,7 +139,7 @@ static int dn_node_address_strategy(ctl_table *table, int __user *name, int nlen
139 void **context) 139 void **context)
140{ 140{
141 size_t len; 141 size_t len;
142 dn_address addr; 142 __le16 addr;
143 143
144 if (oldval && oldlenp) { 144 if (oldval && oldlenp) {
145 if (get_user(len, oldlenp)) 145 if (get_user(len, oldlenp))
@@ -147,14 +147,14 @@ static int dn_node_address_strategy(ctl_table *table, int __user *name, int nlen
147 if (len) { 147 if (len) {
148 if (len != sizeof(unsigned short)) 148 if (len != sizeof(unsigned short))
149 return -EINVAL; 149 return -EINVAL;
150 if (put_user(decnet_address, (unsigned short __user *)oldval)) 150 if (put_user(decnet_address, (__le16 __user *)oldval))
151 return -EFAULT; 151 return -EFAULT;
152 } 152 }
153 } 153 }
154 if (newval && newlen) { 154 if (newval && newlen) {
155 if (newlen != sizeof(unsigned short)) 155 if (newlen != sizeof(unsigned short))
156 return -EINVAL; 156 return -EINVAL;
157 if (get_user(addr, (unsigned short __user *)newval)) 157 if (get_user(addr, (__le16 __user *)newval))
158 return -EFAULT; 158 return -EFAULT;
159 159
160 dn_dev_devices_off(); 160 dn_dev_devices_off();
@@ -173,7 +173,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
173{ 173{
174 char addr[DN_ASCBUF_LEN]; 174 char addr[DN_ASCBUF_LEN];
175 size_t len; 175 size_t len;
176 dn_address dnaddr; 176 __le16 dnaddr;
177 177
178 if (!*lenp || (*ppos && !write)) { 178 if (!*lenp || (*ppos && !write)) {
179 *lenp = 0; 179 *lenp = 0;
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 97c276f95b35..dc206f1f914f 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -788,45 +788,53 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
788} 788}
789 789
790const struct proto_ops inet_stream_ops = { 790const struct proto_ops inet_stream_ops = {
791 .family = PF_INET, 791 .family = PF_INET,
792 .owner = THIS_MODULE, 792 .owner = THIS_MODULE,
793 .release = inet_release, 793 .release = inet_release,
794 .bind = inet_bind, 794 .bind = inet_bind,
795 .connect = inet_stream_connect, 795 .connect = inet_stream_connect,
796 .socketpair = sock_no_socketpair, 796 .socketpair = sock_no_socketpair,
797 .accept = inet_accept, 797 .accept = inet_accept,
798 .getname = inet_getname, 798 .getname = inet_getname,
799 .poll = tcp_poll, 799 .poll = tcp_poll,
800 .ioctl = inet_ioctl, 800 .ioctl = inet_ioctl,
801 .listen = inet_listen, 801 .listen = inet_listen,
802 .shutdown = inet_shutdown, 802 .shutdown = inet_shutdown,
803 .setsockopt = sock_common_setsockopt, 803 .setsockopt = sock_common_setsockopt,
804 .getsockopt = sock_common_getsockopt, 804 .getsockopt = sock_common_getsockopt,
805 .sendmsg = inet_sendmsg, 805 .sendmsg = inet_sendmsg,
806 .recvmsg = sock_common_recvmsg, 806 .recvmsg = sock_common_recvmsg,
807 .mmap = sock_no_mmap, 807 .mmap = sock_no_mmap,
808 .sendpage = tcp_sendpage 808 .sendpage = tcp_sendpage,
809#ifdef CONFIG_COMPAT
810 .compat_setsockopt = compat_sock_common_setsockopt,
811 .compat_getsockopt = compat_sock_common_getsockopt,
812#endif
809}; 813};
810 814
811const struct proto_ops inet_dgram_ops = { 815const struct proto_ops inet_dgram_ops = {
812 .family = PF_INET, 816 .family = PF_INET,
813 .owner = THIS_MODULE, 817 .owner = THIS_MODULE,
814 .release = inet_release, 818 .release = inet_release,
815 .bind = inet_bind, 819 .bind = inet_bind,
816 .connect = inet_dgram_connect, 820 .connect = inet_dgram_connect,
817 .socketpair = sock_no_socketpair, 821 .socketpair = sock_no_socketpair,
818 .accept = sock_no_accept, 822 .accept = sock_no_accept,
819 .getname = inet_getname, 823 .getname = inet_getname,
820 .poll = udp_poll, 824 .poll = udp_poll,
821 .ioctl = inet_ioctl, 825 .ioctl = inet_ioctl,
822 .listen = sock_no_listen, 826 .listen = sock_no_listen,
823 .shutdown = inet_shutdown, 827 .shutdown = inet_shutdown,
824 .setsockopt = sock_common_setsockopt, 828 .setsockopt = sock_common_setsockopt,
825 .getsockopt = sock_common_getsockopt, 829 .getsockopt = sock_common_getsockopt,
826 .sendmsg = inet_sendmsg, 830 .sendmsg = inet_sendmsg,
827 .recvmsg = sock_common_recvmsg, 831 .recvmsg = sock_common_recvmsg,
828 .mmap = sock_no_mmap, 832 .mmap = sock_no_mmap,
829 .sendpage = inet_sendpage, 833 .sendpage = inet_sendpage,
834#ifdef CONFIG_COMPAT
835 .compat_setsockopt = compat_sock_common_setsockopt,
836 .compat_getsockopt = compat_sock_common_getsockopt,
837#endif
830}; 838};
831 839
832/* 840/*
@@ -834,24 +842,28 @@ const struct proto_ops inet_dgram_ops = {
834 * udp_poll 842 * udp_poll
835 */ 843 */
836static const struct proto_ops inet_sockraw_ops = { 844static const struct proto_ops inet_sockraw_ops = {
837 .family = PF_INET, 845 .family = PF_INET,
838 .owner = THIS_MODULE, 846 .owner = THIS_MODULE,
839 .release = inet_release, 847 .release = inet_release,
840 .bind = inet_bind, 848 .bind = inet_bind,
841 .connect = inet_dgram_connect, 849 .connect = inet_dgram_connect,
842 .socketpair = sock_no_socketpair, 850 .socketpair = sock_no_socketpair,
843 .accept = sock_no_accept, 851 .accept = sock_no_accept,
844 .getname = inet_getname, 852 .getname = inet_getname,
845 .poll = datagram_poll, 853 .poll = datagram_poll,
846 .ioctl = inet_ioctl, 854 .ioctl = inet_ioctl,
847 .listen = sock_no_listen, 855 .listen = sock_no_listen,
848 .shutdown = inet_shutdown, 856 .shutdown = inet_shutdown,
849 .setsockopt = sock_common_setsockopt, 857 .setsockopt = sock_common_setsockopt,
850 .getsockopt = sock_common_getsockopt, 858 .getsockopt = sock_common_getsockopt,
851 .sendmsg = inet_sendmsg, 859 .sendmsg = inet_sendmsg,
852 .recvmsg = sock_common_recvmsg, 860 .recvmsg = sock_common_recvmsg,
853 .mmap = sock_no_mmap, 861 .mmap = sock_no_mmap,
854 .sendpage = inet_sendpage, 862 .sendpage = inet_sendpage,
863#ifdef CONFIG_COMPAT
864 .compat_setsockopt = compat_sock_common_setsockopt,
865 .compat_getsockopt = compat_sock_common_getsockopt,
866#endif
855}; 867};
856 868
857static struct net_proto_family inet_family_ops = { 869static struct net_proto_family inet_family_ops = {
diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
index aed537fa2c88..e16d8b42b953 100644
--- a/net/ipv4/ah4.c
+++ b/net/ipv4/ah4.c
@@ -97,6 +97,7 @@ static int ah_output(struct xfrm_state *x, struct sk_buff *skb)
97 ah->reserved = 0; 97 ah->reserved = 0;
98 ah->spi = x->id.spi; 98 ah->spi = x->id.spi;
99 ah->seq_no = htonl(++x->replay.oseq); 99 ah->seq_no = htonl(++x->replay.oseq);
100 xfrm_aevent_doreplay(x);
100 ahp->icv(ahp, skb, ah->auth_data); 101 ahp->icv(ahp, skb, ah->auth_data);
101 102
102 top_iph->tos = iph->tos; 103 top_iph->tos = iph->tos;
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index accdefedfed7..041dadde31af 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -879,16 +879,16 @@ static int arp_process(struct sk_buff *skb)
879 879
880 n = __neigh_lookup(&arp_tbl, &sip, dev, 0); 880 n = __neigh_lookup(&arp_tbl, &sip, dev, 0);
881 881
882#ifdef CONFIG_IP_ACCEPT_UNSOLICITED_ARP 882 if (ipv4_devconf.arp_accept) {
883 /* Unsolicited ARP is not accepted by default. 883 /* Unsolicited ARP is not accepted by default.
884 It is possible, that this option should be enabled for some 884 It is possible, that this option should be enabled for some
885 devices (strip is candidate) 885 devices (strip is candidate)
886 */ 886 */
887 if (n == NULL && 887 if (n == NULL &&
888 arp->ar_op == htons(ARPOP_REPLY) && 888 arp->ar_op == htons(ARPOP_REPLY) &&
889 inet_addr_type(sip) == RTN_UNICAST) 889 inet_addr_type(sip) == RTN_UNICAST)
890 n = __neigh_lookup(&arp_tbl, &sip, dev, -1); 890 n = __neigh_lookup(&arp_tbl, &sip, dev, -1);
891#endif 891 }
892 892
893 if (n) { 893 if (n) {
894 int state = NUD_REACHABLE; 894 int state = NUD_REACHABLE;
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 3ffa60dadc0c..44fdf1413e2c 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1394,6 +1394,14 @@ static struct devinet_sysctl_table {
1394 .proc_handler = &proc_dointvec, 1394 .proc_handler = &proc_dointvec,
1395 }, 1395 },
1396 { 1396 {
1397 .ctl_name = NET_IPV4_CONF_ARP_ACCEPT,
1398 .procname = "arp_accept",
1399 .data = &ipv4_devconf.arp_accept,
1400 .maxlen = sizeof(int),
1401 .mode = 0644,
1402 .proc_handler = &proc_dointvec,
1403 },
1404 {
1397 .ctl_name = NET_IPV4_CONF_NOXFRM, 1405 .ctl_name = NET_IPV4_CONF_NOXFRM,
1398 .procname = "disable_xfrm", 1406 .procname = "disable_xfrm",
1399 .data = &ipv4_devconf.no_xfrm, 1407 .data = &ipv4_devconf.no_xfrm,
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index 09590f356086..bf88c620a954 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -90,6 +90,7 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)
90 90
91 esph->spi = x->id.spi; 91 esph->spi = x->id.spi;
92 esph->seq_no = htonl(++x->replay.oseq); 92 esph->seq_no = htonl(++x->replay.oseq);
93 xfrm_aevent_doreplay(x);
93 94
94 if (esp->conf.ivlen) 95 if (esp->conf.ivlen)
95 crypto_cipher_set_iv(tfm, esp->conf.ivec, crypto_tfm_alg_ivsize(tfm)); 96 crypto_cipher_set_iv(tfm, esp->conf.ivec, crypto_tfm_alg_ivsize(tfm));
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index 0dd4d06e456d..768e8f5d7daa 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -40,6 +40,8 @@
40#include <linux/skbuff.h> 40#include <linux/skbuff.h>
41#include <linux/netlink.h> 41#include <linux/netlink.h>
42#include <linux/init.h> 42#include <linux/init.h>
43#include <linux/list.h>
44#include <linux/rcupdate.h>
43 45
44#include <net/ip.h> 46#include <net/ip.h>
45#include <net/protocol.h> 47#include <net/protocol.h>
@@ -52,7 +54,7 @@
52 54
53struct fib_rule 55struct fib_rule
54{ 56{
55 struct fib_rule *r_next; 57 struct hlist_node hlist;
56 atomic_t r_clntref; 58 atomic_t r_clntref;
57 u32 r_preference; 59 u32 r_preference;
58 unsigned char r_table; 60 unsigned char r_table;
@@ -75,6 +77,7 @@ struct fib_rule
75#endif 77#endif
76 char r_ifname[IFNAMSIZ]; 78 char r_ifname[IFNAMSIZ];
77 int r_dead; 79 int r_dead;
80 struct rcu_head rcu;
78}; 81};
79 82
80static struct fib_rule default_rule = { 83static struct fib_rule default_rule = {
@@ -85,7 +88,6 @@ static struct fib_rule default_rule = {
85}; 88};
86 89
87static struct fib_rule main_rule = { 90static struct fib_rule main_rule = {
88 .r_next = &default_rule,
89 .r_clntref = ATOMIC_INIT(2), 91 .r_clntref = ATOMIC_INIT(2),
90 .r_preference = 0x7FFE, 92 .r_preference = 0x7FFE,
91 .r_table = RT_TABLE_MAIN, 93 .r_table = RT_TABLE_MAIN,
@@ -93,23 +95,24 @@ static struct fib_rule main_rule = {
93}; 95};
94 96
95static struct fib_rule local_rule = { 97static struct fib_rule local_rule = {
96 .r_next = &main_rule,
97 .r_clntref = ATOMIC_INIT(2), 98 .r_clntref = ATOMIC_INIT(2),
98 .r_table = RT_TABLE_LOCAL, 99 .r_table = RT_TABLE_LOCAL,
99 .r_action = RTN_UNICAST, 100 .r_action = RTN_UNICAST,
100}; 101};
101 102
102static struct fib_rule *fib_rules = &local_rule; 103static struct hlist_head fib_rules;
103static DEFINE_RWLOCK(fib_rules_lock); 104
105/* writer func called from netlink -- rtnl_sem hold*/
104 106
105int inet_rtm_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) 107int inet_rtm_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
106{ 108{
107 struct rtattr **rta = arg; 109 struct rtattr **rta = arg;
108 struct rtmsg *rtm = NLMSG_DATA(nlh); 110 struct rtmsg *rtm = NLMSG_DATA(nlh);
109 struct fib_rule *r, **rp; 111 struct fib_rule *r;
112 struct hlist_node *node;
110 int err = -ESRCH; 113 int err = -ESRCH;
111 114
112 for (rp=&fib_rules; (r=*rp) != NULL; rp=&r->r_next) { 115 hlist_for_each_entry(r, node, &fib_rules, hlist) {
113 if ((!rta[RTA_SRC-1] || memcmp(RTA_DATA(rta[RTA_SRC-1]), &r->r_src, 4) == 0) && 116 if ((!rta[RTA_SRC-1] || memcmp(RTA_DATA(rta[RTA_SRC-1]), &r->r_src, 4) == 0) &&
114 rtm->rtm_src_len == r->r_src_len && 117 rtm->rtm_src_len == r->r_src_len &&
115 rtm->rtm_dst_len == r->r_dst_len && 118 rtm->rtm_dst_len == r->r_dst_len &&
@@ -126,10 +129,8 @@ int inet_rtm_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
126 if (r == &local_rule) 129 if (r == &local_rule)
127 break; 130 break;
128 131
129 write_lock_bh(&fib_rules_lock); 132 hlist_del_rcu(&r->hlist);
130 *rp = r->r_next;
131 r->r_dead = 1; 133 r->r_dead = 1;
132 write_unlock_bh(&fib_rules_lock);
133 fib_rule_put(r); 134 fib_rule_put(r);
134 err = 0; 135 err = 0;
135 break; 136 break;
@@ -150,21 +151,30 @@ static struct fib_table *fib_empty_table(void)
150 return NULL; 151 return NULL;
151} 152}
152 153
154static inline void fib_rule_put_rcu(struct rcu_head *head)
155{
156 struct fib_rule *r = container_of(head, struct fib_rule, rcu);
157 kfree(r);
158}
159
153void fib_rule_put(struct fib_rule *r) 160void fib_rule_put(struct fib_rule *r)
154{ 161{
155 if (atomic_dec_and_test(&r->r_clntref)) { 162 if (atomic_dec_and_test(&r->r_clntref)) {
156 if (r->r_dead) 163 if (r->r_dead)
157 kfree(r); 164 call_rcu(&r->rcu, fib_rule_put_rcu);
158 else 165 else
159 printk("Freeing alive rule %p\n", r); 166 printk("Freeing alive rule %p\n", r);
160 } 167 }
161} 168}
162 169
170/* writer func called from netlink -- rtnl_sem hold*/
171
163int inet_rtm_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) 172int inet_rtm_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
164{ 173{
165 struct rtattr **rta = arg; 174 struct rtattr **rta = arg;
166 struct rtmsg *rtm = NLMSG_DATA(nlh); 175 struct rtmsg *rtm = NLMSG_DATA(nlh);
167 struct fib_rule *r, *new_r, **rp; 176 struct fib_rule *r, *new_r, *last = NULL;
177 struct hlist_node *node = NULL;
168 unsigned char table_id; 178 unsigned char table_id;
169 179
170 if (rtm->rtm_src_len > 32 || rtm->rtm_dst_len > 32 || 180 if (rtm->rtm_src_len > 32 || rtm->rtm_dst_len > 32 ||
@@ -188,6 +198,7 @@ int inet_rtm_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
188 if (!new_r) 198 if (!new_r)
189 return -ENOMEM; 199 return -ENOMEM;
190 memset(new_r, 0, sizeof(*new_r)); 200 memset(new_r, 0, sizeof(*new_r));
201
191 if (rta[RTA_SRC-1]) 202 if (rta[RTA_SRC-1])
192 memcpy(&new_r->r_src, RTA_DATA(rta[RTA_SRC-1]), 4); 203 memcpy(&new_r->r_src, RTA_DATA(rta[RTA_SRC-1]), 4);
193 if (rta[RTA_DST-1]) 204 if (rta[RTA_DST-1])
@@ -220,28 +231,28 @@ int inet_rtm_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
220 if (rta[RTA_FLOW-1]) 231 if (rta[RTA_FLOW-1])
221 memcpy(&new_r->r_tclassid, RTA_DATA(rta[RTA_FLOW-1]), 4); 232 memcpy(&new_r->r_tclassid, RTA_DATA(rta[RTA_FLOW-1]), 4);
222#endif 233#endif
234 r = container_of(fib_rules.first, struct fib_rule, hlist);
223 235
224 rp = &fib_rules;
225 if (!new_r->r_preference) { 236 if (!new_r->r_preference) {
226 r = fib_rules; 237 if (r && r->hlist.next != NULL) {
227 if (r && (r = r->r_next) != NULL) { 238 r = container_of(r->hlist.next, struct fib_rule, hlist);
228 rp = &fib_rules->r_next;
229 if (r->r_preference) 239 if (r->r_preference)
230 new_r->r_preference = r->r_preference - 1; 240 new_r->r_preference = r->r_preference - 1;
231 } 241 }
232 } 242 }
233 243
234 while ( (r = *rp) != NULL ) { 244 hlist_for_each_entry(r, node, &fib_rules, hlist) {
235 if (r->r_preference > new_r->r_preference) 245 if (r->r_preference > new_r->r_preference)
236 break; 246 break;
237 rp = &r->r_next; 247 last = r;
238 } 248 }
239
240 new_r->r_next = r;
241 atomic_inc(&new_r->r_clntref); 249 atomic_inc(&new_r->r_clntref);
242 write_lock_bh(&fib_rules_lock); 250
243 *rp = new_r; 251 if (last)
244 write_unlock_bh(&fib_rules_lock); 252 hlist_add_after_rcu(&last->hlist, &new_r->hlist);
253 else
254 hlist_add_before_rcu(&new_r->hlist, &r->hlist);
255
245 return 0; 256 return 0;
246} 257}
247 258
@@ -254,30 +265,30 @@ u32 fib_rules_tclass(struct fib_result *res)
254} 265}
255#endif 266#endif
256 267
268/* callers should hold rtnl semaphore */
257 269
258static void fib_rules_detach(struct net_device *dev) 270static void fib_rules_detach(struct net_device *dev)
259{ 271{
272 struct hlist_node *node;
260 struct fib_rule *r; 273 struct fib_rule *r;
261 274
262 for (r=fib_rules; r; r=r->r_next) { 275 hlist_for_each_entry(r, node, &fib_rules, hlist) {
263 if (r->r_ifindex == dev->ifindex) { 276 if (r->r_ifindex == dev->ifindex)
264 write_lock_bh(&fib_rules_lock);
265 r->r_ifindex = -1; 277 r->r_ifindex = -1;
266 write_unlock_bh(&fib_rules_lock); 278
267 }
268 } 279 }
269} 280}
270 281
282/* callers should hold rtnl semaphore */
283
271static void fib_rules_attach(struct net_device *dev) 284static void fib_rules_attach(struct net_device *dev)
272{ 285{
286 struct hlist_node *node;
273 struct fib_rule *r; 287 struct fib_rule *r;
274 288
275 for (r=fib_rules; r; r=r->r_next) { 289 hlist_for_each_entry(r, node, &fib_rules, hlist) {
276 if (r->r_ifindex == -1 && strcmp(dev->name, r->r_ifname) == 0) { 290 if (r->r_ifindex == -1 && strcmp(dev->name, r->r_ifname) == 0)
277 write_lock_bh(&fib_rules_lock);
278 r->r_ifindex = dev->ifindex; 291 r->r_ifindex = dev->ifindex;
279 write_unlock_bh(&fib_rules_lock);
280 }
281 } 292 }
282} 293}
283 294
@@ -286,14 +297,17 @@ int fib_lookup(const struct flowi *flp, struct fib_result *res)
286 int err; 297 int err;
287 struct fib_rule *r, *policy; 298 struct fib_rule *r, *policy;
288 struct fib_table *tb; 299 struct fib_table *tb;
300 struct hlist_node *node;
289 301
290 u32 daddr = flp->fl4_dst; 302 u32 daddr = flp->fl4_dst;
291 u32 saddr = flp->fl4_src; 303 u32 saddr = flp->fl4_src;
292 304
293FRprintk("Lookup: %u.%u.%u.%u <- %u.%u.%u.%u ", 305FRprintk("Lookup: %u.%u.%u.%u <- %u.%u.%u.%u ",
294 NIPQUAD(flp->fl4_dst), NIPQUAD(flp->fl4_src)); 306 NIPQUAD(flp->fl4_dst), NIPQUAD(flp->fl4_src));
295 read_lock(&fib_rules_lock); 307
296 for (r = fib_rules; r; r=r->r_next) { 308 rcu_read_lock();
309
310 hlist_for_each_entry_rcu(r, node, &fib_rules, hlist) {
297 if (((saddr^r->r_src) & r->r_srcmask) || 311 if (((saddr^r->r_src) & r->r_srcmask) ||
298 ((daddr^r->r_dst) & r->r_dstmask) || 312 ((daddr^r->r_dst) & r->r_dstmask) ||
299 (r->r_tos && r->r_tos != flp->fl4_tos) || 313 (r->r_tos && r->r_tos != flp->fl4_tos) ||
@@ -309,14 +323,14 @@ FRprintk("tb %d r %d ", r->r_table, r->r_action);
309 policy = r; 323 policy = r;
310 break; 324 break;
311 case RTN_UNREACHABLE: 325 case RTN_UNREACHABLE:
312 read_unlock(&fib_rules_lock); 326 rcu_read_unlock();
313 return -ENETUNREACH; 327 return -ENETUNREACH;
314 default: 328 default:
315 case RTN_BLACKHOLE: 329 case RTN_BLACKHOLE:
316 read_unlock(&fib_rules_lock); 330 rcu_read_unlock();
317 return -EINVAL; 331 return -EINVAL;
318 case RTN_PROHIBIT: 332 case RTN_PROHIBIT:
319 read_unlock(&fib_rules_lock); 333 rcu_read_unlock();
320 return -EACCES; 334 return -EACCES;
321 } 335 }
322 336
@@ -327,16 +341,16 @@ FRprintk("tb %d r %d ", r->r_table, r->r_action);
327 res->r = policy; 341 res->r = policy;
328 if (policy) 342 if (policy)
329 atomic_inc(&policy->r_clntref); 343 atomic_inc(&policy->r_clntref);
330 read_unlock(&fib_rules_lock); 344 rcu_read_unlock();
331 return 0; 345 return 0;
332 } 346 }
333 if (err < 0 && err != -EAGAIN) { 347 if (err < 0 && err != -EAGAIN) {
334 read_unlock(&fib_rules_lock); 348 rcu_read_unlock();
335 return err; 349 return err;
336 } 350 }
337 } 351 }
338FRprintk("FAILURE\n"); 352FRprintk("FAILURE\n");
339 read_unlock(&fib_rules_lock); 353 rcu_read_unlock();
340 return -ENETUNREACH; 354 return -ENETUNREACH;
341} 355}
342 356
@@ -414,20 +428,25 @@ rtattr_failure:
414 return -1; 428 return -1;
415} 429}
416 430
431/* callers should hold rtnl semaphore */
432
417int inet_dump_rules(struct sk_buff *skb, struct netlink_callback *cb) 433int inet_dump_rules(struct sk_buff *skb, struct netlink_callback *cb)
418{ 434{
419 int idx; 435 int idx = 0;
420 int s_idx = cb->args[0]; 436 int s_idx = cb->args[0];
421 struct fib_rule *r; 437 struct fib_rule *r;
438 struct hlist_node *node;
439
440 rcu_read_lock();
441 hlist_for_each_entry(r, node, &fib_rules, hlist) {
422 442
423 read_lock(&fib_rules_lock);
424 for (r=fib_rules, idx=0; r; r = r->r_next, idx++) {
425 if (idx < s_idx) 443 if (idx < s_idx)
426 continue; 444 continue;
427 if (inet_fill_rule(skb, r, cb, NLM_F_MULTI) < 0) 445 if (inet_fill_rule(skb, r, cb, NLM_F_MULTI) < 0)
428 break; 446 break;
447 idx++;
429 } 448 }
430 read_unlock(&fib_rules_lock); 449 rcu_read_unlock();
431 cb->args[0] = idx; 450 cb->args[0] = idx;
432 451
433 return skb->len; 452 return skb->len;
@@ -435,5 +454,9 @@ int inet_dump_rules(struct sk_buff *skb, struct netlink_callback *cb)
435 454
436void __init fib_rules_init(void) 455void __init fib_rules_init(void)
437{ 456{
457 INIT_HLIST_HEAD(&fib_rules);
458 hlist_add_head(&local_rule.hlist, &fib_rules);
459 hlist_add_after(&local_rule.hlist, &main_rule.hlist);
460 hlist_add_after(&main_rule.hlist, &default_rule.hlist);
438 register_netdevice_notifier(&fib_rules_notifier); 461 register_netdevice_notifier(&fib_rules_notifier);
439} 462}
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index e320b32373e5..ccd3efc6a173 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -50,7 +50,7 @@
50 * Patrick McHardy <kaber@trash.net> 50 * Patrick McHardy <kaber@trash.net>
51 */ 51 */
52 52
53#define VERSION "0.404" 53#define VERSION "0.406"
54 54
55#include <linux/config.h> 55#include <linux/config.h>
56#include <asm/uaccess.h> 56#include <asm/uaccess.h>
@@ -84,7 +84,7 @@
84#include "fib_lookup.h" 84#include "fib_lookup.h"
85 85
86#undef CONFIG_IP_FIB_TRIE_STATS 86#undef CONFIG_IP_FIB_TRIE_STATS
87#define MAX_CHILDS 16384 87#define MAX_STAT_DEPTH 32
88 88
89#define KEYLENGTH (8*sizeof(t_key)) 89#define KEYLENGTH (8*sizeof(t_key))
90#define MASK_PFX(k, l) (((l)==0)?0:(k >> (KEYLENGTH-l)) << (KEYLENGTH-l)) 90#define MASK_PFX(k, l) (((l)==0)?0:(k >> (KEYLENGTH-l)) << (KEYLENGTH-l))
@@ -154,7 +154,7 @@ struct trie_stat {
154 unsigned int tnodes; 154 unsigned int tnodes;
155 unsigned int leaves; 155 unsigned int leaves;
156 unsigned int nullpointers; 156 unsigned int nullpointers;
157 unsigned int nodesizes[MAX_CHILDS]; 157 unsigned int nodesizes[MAX_STAT_DEPTH];
158}; 158};
159 159
160struct trie { 160struct trie {
@@ -2040,7 +2040,15 @@ rescan:
2040static struct node *fib_trie_get_first(struct fib_trie_iter *iter, 2040static struct node *fib_trie_get_first(struct fib_trie_iter *iter,
2041 struct trie *t) 2041 struct trie *t)
2042{ 2042{
2043 struct node *n = rcu_dereference(t->trie); 2043 struct node *n ;
2044
2045 if(!t)
2046 return NULL;
2047
2048 n = rcu_dereference(t->trie);
2049
2050 if(!iter)
2051 return NULL;
2044 2052
2045 if (n && IS_TNODE(n)) { 2053 if (n && IS_TNODE(n)) {
2046 iter->tnode = (struct tnode *) n; 2054 iter->tnode = (struct tnode *) n;
@@ -2072,7 +2080,9 @@ static void trie_collect_stats(struct trie *t, struct trie_stat *s)
2072 int i; 2080 int i;
2073 2081
2074 s->tnodes++; 2082 s->tnodes++;
2075 s->nodesizes[tn->bits]++; 2083 if(tn->bits < MAX_STAT_DEPTH)
2084 s->nodesizes[tn->bits]++;
2085
2076 for (i = 0; i < (1<<tn->bits); i++) 2086 for (i = 0; i < (1<<tn->bits); i++)
2077 if (!tn->child[i]) 2087 if (!tn->child[i])
2078 s->nullpointers++; 2088 s->nullpointers++;
@@ -2102,8 +2112,8 @@ static void trie_show_stats(struct seq_file *seq, struct trie_stat *stat)
2102 seq_printf(seq, "\tInternal nodes: %d\n\t", stat->tnodes); 2112 seq_printf(seq, "\tInternal nodes: %d\n\t", stat->tnodes);
2103 bytes += sizeof(struct tnode) * stat->tnodes; 2113 bytes += sizeof(struct tnode) * stat->tnodes;
2104 2114
2105 max = MAX_CHILDS-1; 2115 max = MAX_STAT_DEPTH;
2106 while (max >= 0 && stat->nodesizes[max] == 0) 2116 while (max > 0 && stat->nodesizes[max-1] == 0)
2107 max--; 2117 max--;
2108 2118
2109 pointers = 0; 2119 pointers = 0;
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index 64ce52bf0485..d512239a1473 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -1382,7 +1382,7 @@ static struct in_device * ip_mc_find_dev(struct ip_mreqn *imr)
1382 dev = ip_dev_find(imr->imr_address.s_addr); 1382 dev = ip_dev_find(imr->imr_address.s_addr);
1383 if (!dev) 1383 if (!dev)
1384 return NULL; 1384 return NULL;
1385 __dev_put(dev); 1385 dev_put(dev);
1386 } 1386 }
1387 1387
1388 if (!dev && !ip_route_output_key(&rt, &fl)) { 1388 if (!dev && !ip_route_output_key(&rt, &fl)) {
@@ -1730,7 +1730,7 @@ int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr)
1730 if (!MULTICAST(addr)) 1730 if (!MULTICAST(addr))
1731 return -EINVAL; 1731 return -EINVAL;
1732 1732
1733 rtnl_shlock(); 1733 rtnl_lock();
1734 1734
1735 in_dev = ip_mc_find_dev(imr); 1735 in_dev = ip_mc_find_dev(imr);
1736 1736
@@ -1763,7 +1763,7 @@ int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr)
1763 ip_mc_inc_group(in_dev, addr); 1763 ip_mc_inc_group(in_dev, addr);
1764 err = 0; 1764 err = 0;
1765done: 1765done:
1766 rtnl_shunlock(); 1766 rtnl_unlock();
1767 return err; 1767 return err;
1768} 1768}
1769 1769
@@ -1837,7 +1837,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
1837 if (!MULTICAST(addr)) 1837 if (!MULTICAST(addr))
1838 return -EINVAL; 1838 return -EINVAL;
1839 1839
1840 rtnl_shlock(); 1840 rtnl_lock();
1841 1841
1842 imr.imr_multiaddr.s_addr = mreqs->imr_multiaddr; 1842 imr.imr_multiaddr.s_addr = mreqs->imr_multiaddr;
1843 imr.imr_address.s_addr = mreqs->imr_interface; 1843 imr.imr_address.s_addr = mreqs->imr_interface;
@@ -1947,7 +1947,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
1947 ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, omode, 1, 1947 ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, omode, 1,
1948 &mreqs->imr_sourceaddr, 1); 1948 &mreqs->imr_sourceaddr, 1);
1949done: 1949done:
1950 rtnl_shunlock(); 1950 rtnl_unlock();
1951 if (leavegroup) 1951 if (leavegroup)
1952 return ip_mc_leave_group(sk, &imr); 1952 return ip_mc_leave_group(sk, &imr);
1953 return err; 1953 return err;
@@ -1970,7 +1970,7 @@ int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf, int ifindex)
1970 msf->imsf_fmode != MCAST_EXCLUDE) 1970 msf->imsf_fmode != MCAST_EXCLUDE)
1971 return -EINVAL; 1971 return -EINVAL;
1972 1972
1973 rtnl_shlock(); 1973 rtnl_lock();
1974 1974
1975 imr.imr_multiaddr.s_addr = msf->imsf_multiaddr; 1975 imr.imr_multiaddr.s_addr = msf->imsf_multiaddr;
1976 imr.imr_address.s_addr = msf->imsf_interface; 1976 imr.imr_address.s_addr = msf->imsf_interface;
@@ -2030,7 +2030,7 @@ int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf, int ifindex)
2030 pmc->sfmode = msf->imsf_fmode; 2030 pmc->sfmode = msf->imsf_fmode;
2031 err = 0; 2031 err = 0;
2032done: 2032done:
2033 rtnl_shunlock(); 2033 rtnl_unlock();
2034 if (leavegroup) 2034 if (leavegroup)
2035 err = ip_mc_leave_group(sk, &imr); 2035 err = ip_mc_leave_group(sk, &imr);
2036 return err; 2036 return err;
@@ -2050,7 +2050,7 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
2050 if (!MULTICAST(addr)) 2050 if (!MULTICAST(addr))
2051 return -EINVAL; 2051 return -EINVAL;
2052 2052
2053 rtnl_shlock(); 2053 rtnl_lock();
2054 2054
2055 imr.imr_multiaddr.s_addr = msf->imsf_multiaddr; 2055 imr.imr_multiaddr.s_addr = msf->imsf_multiaddr;
2056 imr.imr_address.s_addr = msf->imsf_interface; 2056 imr.imr_address.s_addr = msf->imsf_interface;
@@ -2072,7 +2072,7 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
2072 goto done; 2072 goto done;
2073 msf->imsf_fmode = pmc->sfmode; 2073 msf->imsf_fmode = pmc->sfmode;
2074 psl = pmc->sflist; 2074 psl = pmc->sflist;
2075 rtnl_shunlock(); 2075 rtnl_unlock();
2076 if (!psl) { 2076 if (!psl) {
2077 len = 0; 2077 len = 0;
2078 count = 0; 2078 count = 0;
@@ -2091,7 +2091,7 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
2091 return -EFAULT; 2091 return -EFAULT;
2092 return 0; 2092 return 0;
2093done: 2093done:
2094 rtnl_shunlock(); 2094 rtnl_unlock();
2095 return err; 2095 return err;
2096} 2096}
2097 2097
@@ -2112,7 +2112,7 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
2112 if (!MULTICAST(addr)) 2112 if (!MULTICAST(addr))
2113 return -EINVAL; 2113 return -EINVAL;
2114 2114
2115 rtnl_shlock(); 2115 rtnl_lock();
2116 2116
2117 err = -EADDRNOTAVAIL; 2117 err = -EADDRNOTAVAIL;
2118 2118
@@ -2125,7 +2125,7 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
2125 goto done; 2125 goto done;
2126 gsf->gf_fmode = pmc->sfmode; 2126 gsf->gf_fmode = pmc->sfmode;
2127 psl = pmc->sflist; 2127 psl = pmc->sflist;
2128 rtnl_shunlock(); 2128 rtnl_unlock();
2129 count = psl ? psl->sl_count : 0; 2129 count = psl ? psl->sl_count : 0;
2130 copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc; 2130 copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc;
2131 gsf->gf_numsrc = count; 2131 gsf->gf_numsrc = count;
@@ -2146,7 +2146,7 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
2146 } 2146 }
2147 return 0; 2147 return 0;
2148done: 2148done:
2149 rtnl_shunlock(); 2149 rtnl_unlock();
2150 return err; 2150 return err;
2151} 2151}
2152 2152
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index ae20281d8deb..9a01bb81f8bf 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -648,3 +648,52 @@ void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr)
648} 648}
649 649
650EXPORT_SYMBOL_GPL(inet_csk_addr2sockaddr); 650EXPORT_SYMBOL_GPL(inet_csk_addr2sockaddr);
651
652int inet_csk_ctl_sock_create(struct socket **sock, unsigned short family,
653 unsigned short type, unsigned char protocol)
654{
655 int rc = sock_create_kern(family, type, protocol, sock);
656
657 if (rc == 0) {
658 (*sock)->sk->sk_allocation = GFP_ATOMIC;
659 inet_sk((*sock)->sk)->uc_ttl = -1;
660 /*
661 * Unhash it so that IP input processing does not even see it,
662 * we do not wish this socket to see incoming packets.
663 */
664 (*sock)->sk->sk_prot->unhash((*sock)->sk);
665 }
666 return rc;
667}
668
669EXPORT_SYMBOL_GPL(inet_csk_ctl_sock_create);
670
671#ifdef CONFIG_COMPAT
672int inet_csk_compat_getsockopt(struct sock *sk, int level, int optname,
673 char __user *optval, int __user *optlen)
674{
675 const struct inet_connection_sock *icsk = inet_csk(sk);
676
677 if (icsk->icsk_af_ops->compat_getsockopt != NULL)
678 return icsk->icsk_af_ops->compat_getsockopt(sk, level, optname,
679 optval, optlen);
680 return icsk->icsk_af_ops->getsockopt(sk, level, optname,
681 optval, optlen);
682}
683
684EXPORT_SYMBOL_GPL(inet_csk_compat_getsockopt);
685
686int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname,
687 char __user *optval, int optlen)
688{
689 const struct inet_connection_sock *icsk = inet_csk(sk);
690
691 if (icsk->icsk_af_ops->compat_setsockopt != NULL)
692 return icsk->icsk_af_ops->compat_setsockopt(sk, level, optname,
693 optval, optlen);
694 return icsk->icsk_af_ops->setsockopt(sk, level, optname,
695 optval, optlen);
696}
697
698EXPORT_SYMBOL_GPL(inet_csk_compat_setsockopt);
699#endif
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 2bf8d782f678..12e0bf19f24a 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -50,6 +50,7 @@
50#define IP_CMSG_TOS 4 50#define IP_CMSG_TOS 4
51#define IP_CMSG_RECVOPTS 8 51#define IP_CMSG_RECVOPTS 8
52#define IP_CMSG_RETOPTS 16 52#define IP_CMSG_RETOPTS 16
53#define IP_CMSG_PASSSEC 32
53 54
54/* 55/*
55 * SOL_IP control messages. 56 * SOL_IP control messages.
@@ -109,6 +110,19 @@ static void ip_cmsg_recv_retopts(struct msghdr *msg, struct sk_buff *skb)
109 put_cmsg(msg, SOL_IP, IP_RETOPTS, opt->optlen, opt->__data); 110 put_cmsg(msg, SOL_IP, IP_RETOPTS, opt->optlen, opt->__data);
110} 111}
111 112
113static void ip_cmsg_recv_security(struct msghdr *msg, struct sk_buff *skb)
114{
115 char *secdata;
116 u32 seclen;
117 int err;
118
119 err = security_socket_getpeersec_dgram(skb, &secdata, &seclen);
120 if (err)
121 return;
122
123 put_cmsg(msg, SOL_IP, SCM_SECURITY, seclen, secdata);
124}
125
112 126
113void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb) 127void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb)
114{ 128{
@@ -138,6 +152,11 @@ void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb)
138 152
139 if (flags & 1) 153 if (flags & 1)
140 ip_cmsg_recv_retopts(msg, skb); 154 ip_cmsg_recv_retopts(msg, skb);
155 if ((flags>>=1) == 0)
156 return;
157
158 if (flags & 1)
159 ip_cmsg_recv_security(msg, skb);
141} 160}
142 161
143int ip_cmsg_send(struct msghdr *msg, struct ipcm_cookie *ipc) 162int ip_cmsg_send(struct msghdr *msg, struct ipcm_cookie *ipc)
@@ -380,20 +399,19 @@ out:
380 * an IP socket. 399 * an IP socket.
381 */ 400 */
382 401
383int ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval, int optlen) 402static int do_ip_setsockopt(struct sock *sk, int level,
403 int optname, char __user *optval, int optlen)
384{ 404{
385 struct inet_sock *inet = inet_sk(sk); 405 struct inet_sock *inet = inet_sk(sk);
386 int val=0,err; 406 int val=0,err;
387 407
388 if (level != SOL_IP)
389 return -ENOPROTOOPT;
390
391 if (((1<<optname) & ((1<<IP_PKTINFO) | (1<<IP_RECVTTL) | 408 if (((1<<optname) & ((1<<IP_PKTINFO) | (1<<IP_RECVTTL) |
392 (1<<IP_RECVOPTS) | (1<<IP_RECVTOS) | 409 (1<<IP_RECVOPTS) | (1<<IP_RECVTOS) |
393 (1<<IP_RETOPTS) | (1<<IP_TOS) | 410 (1<<IP_RETOPTS) | (1<<IP_TOS) |
394 (1<<IP_TTL) | (1<<IP_HDRINCL) | 411 (1<<IP_TTL) | (1<<IP_HDRINCL) |
395 (1<<IP_MTU_DISCOVER) | (1<<IP_RECVERR) | 412 (1<<IP_MTU_DISCOVER) | (1<<IP_RECVERR) |
396 (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND))) || 413 (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND) |
414 (1<<IP_PASSSEC))) ||
397 optname == IP_MULTICAST_TTL || 415 optname == IP_MULTICAST_TTL ||
398 optname == IP_MULTICAST_LOOP) { 416 optname == IP_MULTICAST_LOOP) {
399 if (optlen >= sizeof(int)) { 417 if (optlen >= sizeof(int)) {
@@ -478,6 +496,12 @@ int ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval,
478 else 496 else
479 inet->cmsg_flags &= ~IP_CMSG_RETOPTS; 497 inet->cmsg_flags &= ~IP_CMSG_RETOPTS;
480 break; 498 break;
499 case IP_PASSSEC:
500 if (val)
501 inet->cmsg_flags |= IP_CMSG_PASSSEC;
502 else
503 inet->cmsg_flags &= ~IP_CMSG_PASSSEC;
504 break;
481 case IP_TOS: /* This sets both TOS and Precedence */ 505 case IP_TOS: /* This sets both TOS and Precedence */
482 if (sk->sk_type == SOCK_STREAM) { 506 if (sk->sk_type == SOCK_STREAM) {
483 val &= ~3; 507 val &= ~3;
@@ -849,12 +873,7 @@ mc_msf_out:
849 break; 873 break;
850 874
851 default: 875 default:
852#ifdef CONFIG_NETFILTER
853 err = nf_setsockopt(sk, PF_INET, optname, optval,
854 optlen);
855#else
856 err = -ENOPROTOOPT; 876 err = -ENOPROTOOPT;
857#endif
858 break; 877 break;
859 } 878 }
860 release_sock(sk); 879 release_sock(sk);
@@ -865,12 +884,68 @@ e_inval:
865 return -EINVAL; 884 return -EINVAL;
866} 885}
867 886
887int ip_setsockopt(struct sock *sk, int level,
888 int optname, char __user *optval, int optlen)
889{
890 int err;
891
892 if (level != SOL_IP)
893 return -ENOPROTOOPT;
894
895 err = do_ip_setsockopt(sk, level, optname, optval, optlen);
896#ifdef CONFIG_NETFILTER
897 /* we need to exclude all possible ENOPROTOOPTs except default case */
898 if (err == -ENOPROTOOPT && optname != IP_HDRINCL &&
899 optname != IP_IPSEC_POLICY && optname != IP_XFRM_POLICY
900#ifdef CONFIG_IP_MROUTE
901 && (optname < MRT_BASE || optname > (MRT_BASE + 10))
902#endif
903 ) {
904 lock_sock(sk);
905 err = nf_setsockopt(sk, PF_INET, optname, optval, optlen);
906 release_sock(sk);
907 }
908#endif
909 return err;
910}
911
912#ifdef CONFIG_COMPAT
913int compat_ip_setsockopt(struct sock *sk, int level, int optname,
914 char __user *optval, int optlen)
915{
916 int err;
917
918 if (level != SOL_IP)
919 return -ENOPROTOOPT;
920
921 err = do_ip_setsockopt(sk, level, optname, optval, optlen);
922#ifdef CONFIG_NETFILTER
923 /* we need to exclude all possible ENOPROTOOPTs except default case */
924 if (err == -ENOPROTOOPT && optname != IP_HDRINCL &&
925 optname != IP_IPSEC_POLICY && optname != IP_XFRM_POLICY
926#ifdef CONFIG_IP_MROUTE
927 && (optname < MRT_BASE || optname > (MRT_BASE + 10))
928#endif
929 ) {
930 lock_sock(sk);
931 err = compat_nf_setsockopt(sk, PF_INET, optname,
932 optval, optlen);
933 release_sock(sk);
934 }
935#endif
936 return err;
937}
938
939EXPORT_SYMBOL(compat_ip_setsockopt);
940#endif
941
868/* 942/*
869 * Get the options. Note for future reference. The GET of IP options gets the 943 * Get the options. Note for future reference. The GET of IP options gets the
870 * _received_ ones. The set sets the _sent_ ones. 944 * _received_ ones. The set sets the _sent_ ones.
871 */ 945 */
872 946
873int ip_getsockopt(struct sock *sk, int level, int optname, char __user *optval, int __user *optlen) 947static int do_ip_getsockopt(struct sock *sk, int level, int optname,
948 char __user *optval, int __user *optlen)
874{ 949{
875 struct inet_sock *inet = inet_sk(sk); 950 struct inet_sock *inet = inet_sk(sk);
876 int val; 951 int val;
@@ -932,6 +1007,9 @@ int ip_getsockopt(struct sock *sk, int level, int optname, char __user *optval,
932 case IP_RETOPTS: 1007 case IP_RETOPTS:
933 val = (inet->cmsg_flags & IP_CMSG_RETOPTS) != 0; 1008 val = (inet->cmsg_flags & IP_CMSG_RETOPTS) != 0;
934 break; 1009 break;
1010 case IP_PASSSEC:
1011 val = (inet->cmsg_flags & IP_CMSG_PASSSEC) != 0;
1012 break;
935 case IP_TOS: 1013 case IP_TOS:
936 val = inet->tos; 1014 val = inet->tos;
937 break; 1015 break;
@@ -1051,17 +1129,8 @@ int ip_getsockopt(struct sock *sk, int level, int optname, char __user *optval,
1051 val = inet->freebind; 1129 val = inet->freebind;
1052 break; 1130 break;
1053 default: 1131 default:
1054#ifdef CONFIG_NETFILTER
1055 val = nf_getsockopt(sk, PF_INET, optname, optval,
1056 &len);
1057 release_sock(sk);
1058 if (val >= 0)
1059 val = put_user(len, optlen);
1060 return val;
1061#else
1062 release_sock(sk); 1132 release_sock(sk);
1063 return -ENOPROTOOPT; 1133 return -ENOPROTOOPT;
1064#endif
1065 } 1134 }
1066 release_sock(sk); 1135 release_sock(sk);
1067 1136
@@ -1082,6 +1151,67 @@ int ip_getsockopt(struct sock *sk, int level, int optname, char __user *optval,
1082 return 0; 1151 return 0;
1083} 1152}
1084 1153
1154int ip_getsockopt(struct sock *sk, int level,
1155 int optname, char __user *optval, int __user *optlen)
1156{
1157 int err;
1158
1159 err = do_ip_getsockopt(sk, level, optname, optval, optlen);
1160#ifdef CONFIG_NETFILTER
1161 /* we need to exclude all possible ENOPROTOOPTs except default case */
1162 if (err == -ENOPROTOOPT && optname != IP_PKTOPTIONS
1163#ifdef CONFIG_IP_MROUTE
1164 && (optname < MRT_BASE || optname > MRT_BASE+10)
1165#endif
1166 ) {
1167 int len;
1168
1169 if(get_user(len,optlen))
1170 return -EFAULT;
1171
1172 lock_sock(sk);
1173 err = nf_getsockopt(sk, PF_INET, optname, optval,
1174 &len);
1175 release_sock(sk);
1176 if (err >= 0)
1177 err = put_user(len, optlen);
1178 return err;
1179 }
1180#endif
1181 return err;
1182}
1183
1184#ifdef CONFIG_COMPAT
1185int compat_ip_getsockopt(struct sock *sk, int level, int optname,
1186 char __user *optval, int __user *optlen)
1187{
1188 int err = do_ip_getsockopt(sk, level, optname, optval, optlen);
1189#ifdef CONFIG_NETFILTER
1190 /* we need to exclude all possible ENOPROTOOPTs except default case */
1191 if (err == -ENOPROTOOPT && optname != IP_PKTOPTIONS
1192#ifdef CONFIG_IP_MROUTE
1193 && (optname < MRT_BASE || optname > MRT_BASE+10)
1194#endif
1195 ) {
1196 int len;
1197
1198 if (get_user(len, optlen))
1199 return -EFAULT;
1200
1201 lock_sock(sk);
1202 err = compat_nf_getsockopt(sk, PF_INET, optname, optval, &len);
1203 release_sock(sk);
1204 if (err >= 0)
1205 err = put_user(len, optlen);
1206 return err;
1207 }
1208#endif
1209 return err;
1210}
1211
1212EXPORT_SYMBOL(compat_ip_getsockopt);
1213#endif
1214
1085EXPORT_SYMBOL(ip_cmsg_recv); 1215EXPORT_SYMBOL(ip_cmsg_recv);
1086 1216
1087EXPORT_SYMBOL(ip_getsockopt); 1217EXPORT_SYMBOL(ip_getsockopt);
diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
index d64e2ec8da7b..c95020f7c81e 100644
--- a/net/ipv4/ipcomp.c
+++ b/net/ipv4/ipcomp.c
@@ -24,6 +24,7 @@
24#include <linux/list.h> 24#include <linux/list.h>
25#include <linux/vmalloc.h> 25#include <linux/vmalloc.h>
26#include <linux/rtnetlink.h> 26#include <linux/rtnetlink.h>
27#include <linux/mutex.h>
27#include <net/ip.h> 28#include <net/ip.h>
28#include <net/xfrm.h> 29#include <net/xfrm.h>
29#include <net/icmp.h> 30#include <net/icmp.h>
@@ -36,7 +37,7 @@ struct ipcomp_tfms {
36 int users; 37 int users;
37}; 38};
38 39
39static DECLARE_MUTEX(ipcomp_resource_sem); 40static DEFINE_MUTEX(ipcomp_resource_mutex);
40static void **ipcomp_scratches; 41static void **ipcomp_scratches;
41static int ipcomp_scratch_users; 42static int ipcomp_scratch_users;
42static LIST_HEAD(ipcomp_tfms_list); 43static LIST_HEAD(ipcomp_tfms_list);
@@ -253,7 +254,7 @@ error:
253} 254}
254 255
255/* 256/*
256 * Must be protected by xfrm_cfg_sem. State and tunnel user references are 257 * Must be protected by xfrm_cfg_mutex. State and tunnel user references are
257 * always incremented on success. 258 * always incremented on success.
258 */ 259 */
259static int ipcomp_tunnel_attach(struct xfrm_state *x) 260static int ipcomp_tunnel_attach(struct xfrm_state *x)
@@ -411,9 +412,9 @@ static void ipcomp_destroy(struct xfrm_state *x)
411 if (!ipcd) 412 if (!ipcd)
412 return; 413 return;
413 xfrm_state_delete_tunnel(x); 414 xfrm_state_delete_tunnel(x);
414 down(&ipcomp_resource_sem); 415 mutex_lock(&ipcomp_resource_mutex);
415 ipcomp_free_data(ipcd); 416 ipcomp_free_data(ipcd);
416 up(&ipcomp_resource_sem); 417 mutex_unlock(&ipcomp_resource_mutex);
417 kfree(ipcd); 418 kfree(ipcd);
418} 419}
419 420
@@ -440,14 +441,14 @@ static int ipcomp_init_state(struct xfrm_state *x)
440 if (x->props.mode) 441 if (x->props.mode)
441 x->props.header_len += sizeof(struct iphdr); 442 x->props.header_len += sizeof(struct iphdr);
442 443
443 down(&ipcomp_resource_sem); 444 mutex_lock(&ipcomp_resource_mutex);
444 if (!ipcomp_alloc_scratches()) 445 if (!ipcomp_alloc_scratches())
445 goto error; 446 goto error;
446 447
447 ipcd->tfms = ipcomp_alloc_tfms(x->calg->alg_name); 448 ipcd->tfms = ipcomp_alloc_tfms(x->calg->alg_name);
448 if (!ipcd->tfms) 449 if (!ipcd->tfms)
449 goto error; 450 goto error;
450 up(&ipcomp_resource_sem); 451 mutex_unlock(&ipcomp_resource_mutex);
451 452
452 if (x->props.mode) { 453 if (x->props.mode) {
453 err = ipcomp_tunnel_attach(x); 454 err = ipcomp_tunnel_attach(x);
@@ -464,10 +465,10 @@ out:
464 return err; 465 return err;
465 466
466error_tunnel: 467error_tunnel:
467 down(&ipcomp_resource_sem); 468 mutex_lock(&ipcomp_resource_mutex);
468error: 469error:
469 ipcomp_free_data(ipcd); 470 ipcomp_free_data(ipcd);
470 up(&ipcomp_resource_sem); 471 mutex_unlock(&ipcomp_resource_mutex);
471 kfree(ipcd); 472 kfree(ipcd);
472 goto out; 473 goto out;
473} 474}
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index bb3613ec448c..cb8a92f18ef6 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -186,7 +186,7 @@ static int __init ic_open_devs(void)
186 unsigned short oflags; 186 unsigned short oflags;
187 187
188 last = &ic_first_dev; 188 last = &ic_first_dev;
189 rtnl_shlock(); 189 rtnl_lock();
190 190
191 /* bring loopback device up first */ 191 /* bring loopback device up first */
192 if (dev_change_flags(&loopback_dev, loopback_dev.flags | IFF_UP) < 0) 192 if (dev_change_flags(&loopback_dev, loopback_dev.flags | IFF_UP) < 0)
@@ -215,7 +215,7 @@ static int __init ic_open_devs(void)
215 continue; 215 continue;
216 } 216 }
217 if (!(d = kmalloc(sizeof(struct ic_device), GFP_KERNEL))) { 217 if (!(d = kmalloc(sizeof(struct ic_device), GFP_KERNEL))) {
218 rtnl_shunlock(); 218 rtnl_unlock();
219 return -1; 219 return -1;
220 } 220 }
221 d->dev = dev; 221 d->dev = dev;
@@ -232,7 +232,7 @@ static int __init ic_open_devs(void)
232 dev->name, able, d->xid)); 232 dev->name, able, d->xid));
233 } 233 }
234 } 234 }
235 rtnl_shunlock(); 235 rtnl_unlock();
236 236
237 *last = NULL; 237 *last = NULL;
238 238
@@ -251,7 +251,7 @@ static void __init ic_close_devs(void)
251 struct ic_device *d, *next; 251 struct ic_device *d, *next;
252 struct net_device *dev; 252 struct net_device *dev;
253 253
254 rtnl_shlock(); 254 rtnl_lock();
255 next = ic_first_dev; 255 next = ic_first_dev;
256 while ((d = next)) { 256 while ((d = next)) {
257 next = d->next; 257 next = d->next;
@@ -262,7 +262,7 @@ static void __init ic_close_devs(void)
262 } 262 }
263 kfree(d); 263 kfree(d);
264 } 264 }
265 rtnl_shunlock(); 265 rtnl_unlock();
266} 266}
267 267
268/* 268/*
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 5c94c222e3f3..717ab7d6d7b6 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -415,10 +415,10 @@ static int vif_add(struct vifctl *vifc, int mrtsock)
415 return -ENOBUFS; 415 return -ENOBUFS;
416 break; 416 break;
417 case 0: 417 case 0:
418 dev=ip_dev_find(vifc->vifc_lcl_addr.s_addr); 418 dev = ip_dev_find(vifc->vifc_lcl_addr.s_addr);
419 if (!dev) 419 if (!dev)
420 return -EADDRNOTAVAIL; 420 return -EADDRNOTAVAIL;
421 __dev_put(dev); 421 dev_put(dev);
422 break; 422 break;
423 default: 423 default:
424 return -EINVAL; 424 return -EINVAL;
diff --git a/net/ipv4/ipvs/ip_vs_app.c b/net/ipv4/ipvs/ip_vs_app.c
index 9b176a942ac5..e7752334d296 100644
--- a/net/ipv4/ipvs/ip_vs_app.c
+++ b/net/ipv4/ipvs/ip_vs_app.c
@@ -31,6 +31,7 @@
31#include <linux/stat.h> 31#include <linux/stat.h>
32#include <linux/proc_fs.h> 32#include <linux/proc_fs.h>
33#include <linux/seq_file.h> 33#include <linux/seq_file.h>
34#include <linux/mutex.h>
34 35
35#include <net/ip_vs.h> 36#include <net/ip_vs.h>
36 37
@@ -40,7 +41,7 @@ EXPORT_SYMBOL(register_ip_vs_app_inc);
40 41
41/* ipvs application list head */ 42/* ipvs application list head */
42static LIST_HEAD(ip_vs_app_list); 43static LIST_HEAD(ip_vs_app_list);
43static DECLARE_MUTEX(__ip_vs_app_mutex); 44static DEFINE_MUTEX(__ip_vs_app_mutex);
44 45
45 46
46/* 47/*
@@ -173,11 +174,11 @@ register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port)
173{ 174{
174 int result; 175 int result;
175 176
176 down(&__ip_vs_app_mutex); 177 mutex_lock(&__ip_vs_app_mutex);
177 178
178 result = ip_vs_app_inc_new(app, proto, port); 179 result = ip_vs_app_inc_new(app, proto, port);
179 180
180 up(&__ip_vs_app_mutex); 181 mutex_unlock(&__ip_vs_app_mutex);
181 182
182 return result; 183 return result;
183} 184}
@@ -191,11 +192,11 @@ int register_ip_vs_app(struct ip_vs_app *app)
191 /* increase the module use count */ 192 /* increase the module use count */
192 ip_vs_use_count_inc(); 193 ip_vs_use_count_inc();
193 194
194 down(&__ip_vs_app_mutex); 195 mutex_lock(&__ip_vs_app_mutex);
195 196
196 list_add(&app->a_list, &ip_vs_app_list); 197 list_add(&app->a_list, &ip_vs_app_list);
197 198
198 up(&__ip_vs_app_mutex); 199 mutex_unlock(&__ip_vs_app_mutex);
199 200
200 return 0; 201 return 0;
201} 202}
@@ -209,7 +210,7 @@ void unregister_ip_vs_app(struct ip_vs_app *app)
209{ 210{
210 struct ip_vs_app *inc, *nxt; 211 struct ip_vs_app *inc, *nxt;
211 212
212 down(&__ip_vs_app_mutex); 213 mutex_lock(&__ip_vs_app_mutex);
213 214
214 list_for_each_entry_safe(inc, nxt, &app->incs_list, a_list) { 215 list_for_each_entry_safe(inc, nxt, &app->incs_list, a_list) {
215 ip_vs_app_inc_release(inc); 216 ip_vs_app_inc_release(inc);
@@ -217,7 +218,7 @@ void unregister_ip_vs_app(struct ip_vs_app *app)
217 218
218 list_del(&app->a_list); 219 list_del(&app->a_list);
219 220
220 up(&__ip_vs_app_mutex); 221 mutex_unlock(&__ip_vs_app_mutex);
221 222
222 /* decrease the module use count */ 223 /* decrease the module use count */
223 ip_vs_use_count_dec(); 224 ip_vs_use_count_dec();
@@ -498,7 +499,7 @@ static struct ip_vs_app *ip_vs_app_idx(loff_t pos)
498 499
499static void *ip_vs_app_seq_start(struct seq_file *seq, loff_t *pos) 500static void *ip_vs_app_seq_start(struct seq_file *seq, loff_t *pos)
500{ 501{
501 down(&__ip_vs_app_mutex); 502 mutex_lock(&__ip_vs_app_mutex);
502 503
503 return *pos ? ip_vs_app_idx(*pos - 1) : SEQ_START_TOKEN; 504 return *pos ? ip_vs_app_idx(*pos - 1) : SEQ_START_TOKEN;
504} 505}
@@ -530,7 +531,7 @@ static void *ip_vs_app_seq_next(struct seq_file *seq, void *v, loff_t *pos)
530 531
531static void ip_vs_app_seq_stop(struct seq_file *seq, void *v) 532static void ip_vs_app_seq_stop(struct seq_file *seq, void *v)
532{ 533{
533 up(&__ip_vs_app_mutex); 534 mutex_unlock(&__ip_vs_app_mutex);
534} 535}
535 536
536static int ip_vs_app_seq_show(struct seq_file *seq, void *v) 537static int ip_vs_app_seq_show(struct seq_file *seq, void *v)
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
index db783036e4d8..882b842c25d4 100644
--- a/net/ipv4/netfilter/Kconfig
+++ b/net/ipv4/netfilter/Kconfig
@@ -168,6 +168,26 @@ config IP_NF_PPTP
168 If you want to compile it as a module, say M here and read 168 If you want to compile it as a module, say M here and read
169 Documentation/modules.txt. If unsure, say `N'. 169 Documentation/modules.txt. If unsure, say `N'.
170 170
171config IP_NF_H323
172 tristate 'H.323 protocol support'
173 depends on IP_NF_CONNTRACK
174 help
175 H.323 is a VoIP signalling protocol from ITU-T. As one of the most
176 important VoIP protocols, it is widely used by voice hardware and
177 software including voice gateways, IP phones, Netmeeting, OpenPhone,
178 Gnomemeeting, etc.
179
180 With this module you can support H.323 on a connection tracking/NAT
181 firewall.
182
183 This module supports RAS, Fast-start, H.245 tunnelling, RTP/RTCP
184 and T.120 based data and applications including audio, video, FAX,
185 chat, whiteboard, file transfer, etc. For more information, please
186 see http://nath323.sourceforge.net/.
187
188 If you want to compile it as a module, say 'M' here and read
189 Documentation/modules.txt. If unsure, say 'N'.
190
171config IP_NF_QUEUE 191config IP_NF_QUEUE
172 tristate "IP Userspace queueing via NETLINK (OBSOLETE)" 192 tristate "IP Userspace queueing via NETLINK (OBSOLETE)"
173 help 193 help
@@ -303,16 +323,6 @@ config IP_NF_MATCH_HASHLIMIT
303 destination IP' or `500pps from any given source IP' with a single 323 destination IP' or `500pps from any given source IP' with a single
304 IPtables rule. 324 IPtables rule.
305 325
306config IP_NF_MATCH_POLICY
307 tristate "IPsec policy match support"
308 depends on IP_NF_IPTABLES && XFRM
309 help
310 Policy matching allows you to match packets based on the
311 IPsec policy that was used during decapsulation/will
312 be used during encapsulation.
313
314 To compile it as a module, choose M here. If unsure, say N.
315
316# `filter', generic and specific targets 326# `filter', generic and specific targets
317config IP_NF_FILTER 327config IP_NF_FILTER
318 tristate "Packet filtering" 328 tristate "Packet filtering"
@@ -494,6 +504,12 @@ config IP_NF_NAT_PPTP
494 default IP_NF_NAT if IP_NF_PPTP=y 504 default IP_NF_NAT if IP_NF_PPTP=y
495 default m if IP_NF_PPTP=m 505 default m if IP_NF_PPTP=m
496 506
507config IP_NF_NAT_H323
508 tristate
509 depends on IP_NF_IPTABLES!=n && IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
510 default IP_NF_NAT if IP_NF_H323=y
511 default m if IP_NF_H323=m
512
497# mangle + specific targets 513# mangle + specific targets
498config IP_NF_MANGLE 514config IP_NF_MANGLE
499 tristate "Packet mangling" 515 tristate "Packet mangling"
diff --git a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile
index e5c5b3202f02..f2cd9a6c5b91 100644
--- a/net/ipv4/netfilter/Makefile
+++ b/net/ipv4/netfilter/Makefile
@@ -10,6 +10,9 @@ iptable_nat-objs := ip_nat_rule.o ip_nat_standalone.o
10ip_conntrack_pptp-objs := ip_conntrack_helper_pptp.o ip_conntrack_proto_gre.o 10ip_conntrack_pptp-objs := ip_conntrack_helper_pptp.o ip_conntrack_proto_gre.o
11ip_nat_pptp-objs := ip_nat_helper_pptp.o ip_nat_proto_gre.o 11ip_nat_pptp-objs := ip_nat_helper_pptp.o ip_nat_proto_gre.o
12 12
13ip_conntrack_h323-objs := ip_conntrack_helper_h323.o ip_conntrack_helper_h323_asn1.o
14ip_nat_h323-objs := ip_nat_helper_h323.o
15
13# connection tracking 16# connection tracking
14obj-$(CONFIG_IP_NF_CONNTRACK) += ip_conntrack.o 17obj-$(CONFIG_IP_NF_CONNTRACK) += ip_conntrack.o
15obj-$(CONFIG_IP_NF_NAT) += ip_nat.o 18obj-$(CONFIG_IP_NF_NAT) += ip_nat.o
@@ -22,6 +25,7 @@ obj-$(CONFIG_IP_NF_CONNTRACK_NETLINK) += ip_conntrack_netlink.o
22obj-$(CONFIG_IP_NF_CT_PROTO_SCTP) += ip_conntrack_proto_sctp.o 25obj-$(CONFIG_IP_NF_CT_PROTO_SCTP) += ip_conntrack_proto_sctp.o
23 26
24# connection tracking helpers 27# connection tracking helpers
28obj-$(CONFIG_IP_NF_H323) += ip_conntrack_h323.o
25obj-$(CONFIG_IP_NF_PPTP) += ip_conntrack_pptp.o 29obj-$(CONFIG_IP_NF_PPTP) += ip_conntrack_pptp.o
26obj-$(CONFIG_IP_NF_AMANDA) += ip_conntrack_amanda.o 30obj-$(CONFIG_IP_NF_AMANDA) += ip_conntrack_amanda.o
27obj-$(CONFIG_IP_NF_TFTP) += ip_conntrack_tftp.o 31obj-$(CONFIG_IP_NF_TFTP) += ip_conntrack_tftp.o
@@ -30,6 +34,7 @@ obj-$(CONFIG_IP_NF_IRC) += ip_conntrack_irc.o
30obj-$(CONFIG_IP_NF_NETBIOS_NS) += ip_conntrack_netbios_ns.o 34obj-$(CONFIG_IP_NF_NETBIOS_NS) += ip_conntrack_netbios_ns.o
31 35
32# NAT helpers 36# NAT helpers
37obj-$(CONFIG_IP_NF_NAT_H323) += ip_nat_h323.o
33obj-$(CONFIG_IP_NF_NAT_PPTP) += ip_nat_pptp.o 38obj-$(CONFIG_IP_NF_NAT_PPTP) += ip_nat_pptp.o
34obj-$(CONFIG_IP_NF_NAT_AMANDA) += ip_nat_amanda.o 39obj-$(CONFIG_IP_NF_NAT_AMANDA) += ip_nat_amanda.o
35obj-$(CONFIG_IP_NF_NAT_TFTP) += ip_nat_tftp.o 40obj-$(CONFIG_IP_NF_NAT_TFTP) += ip_nat_tftp.o
@@ -57,7 +62,6 @@ obj-$(CONFIG_IP_NF_MATCH_DSCP) += ipt_dscp.o
57obj-$(CONFIG_IP_NF_MATCH_AH_ESP) += ipt_ah.o ipt_esp.o 62obj-$(CONFIG_IP_NF_MATCH_AH_ESP) += ipt_ah.o ipt_esp.o
58obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o 63obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o
59obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o 64obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o
60obj-$(CONFIG_IP_NF_MATCH_POLICY) += ipt_policy.o
61 65
62# targets 66# targets
63obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o 67obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 7d7ab94a7a2e..f7efb3f27bf5 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -22,7 +22,7 @@
22#include <linux/init.h> 22#include <linux/init.h>
23 23
24#include <asm/uaccess.h> 24#include <asm/uaccess.h>
25#include <asm/semaphore.h> 25#include <linux/mutex.h>
26 26
27#include <linux/netfilter/x_tables.h> 27#include <linux/netfilter/x_tables.h>
28#include <linux/netfilter_arp/arp_tables.h> 28#include <linux/netfilter_arp/arp_tables.h>
@@ -208,6 +208,7 @@ static unsigned int arpt_error(struct sk_buff **pskb,
208 const struct net_device *in, 208 const struct net_device *in,
209 const struct net_device *out, 209 const struct net_device *out,
210 unsigned int hooknum, 210 unsigned int hooknum,
211 const struct xt_target *target,
211 const void *targinfo, 212 const void *targinfo,
212 void *userinfo) 213 void *userinfo)
213{ 214{
@@ -300,6 +301,7 @@ unsigned int arpt_do_table(struct sk_buff **pskb,
300 verdict = t->u.kernel.target->target(pskb, 301 verdict = t->u.kernel.target->target(pskb,
301 in, out, 302 in, out,
302 hook, 303 hook,
304 t->u.kernel.target,
303 t->data, 305 t->data,
304 userdata); 306 userdata);
305 307
@@ -480,26 +482,31 @@ static inline int check_entry(struct arpt_entry *e, const char *name, unsigned i
480 } 482 }
481 t->u.kernel.target = target; 483 t->u.kernel.target = target;
482 484
485 ret = xt_check_target(target, NF_ARP, t->u.target_size - sizeof(*t),
486 name, e->comefrom, 0, 0);
487 if (ret)
488 goto err;
489
483 if (t->u.kernel.target == &arpt_standard_target) { 490 if (t->u.kernel.target == &arpt_standard_target) {
484 if (!standard_check(t, size)) { 491 if (!standard_check(t, size)) {
485 ret = -EINVAL; 492 ret = -EINVAL;
486 goto out; 493 goto out;
487 } 494 }
488 } else if (t->u.kernel.target->checkentry 495 } else if (t->u.kernel.target->checkentry
489 && !t->u.kernel.target->checkentry(name, e, t->data, 496 && !t->u.kernel.target->checkentry(name, e, target, t->data,
490 t->u.target_size 497 t->u.target_size
491 - sizeof(*t), 498 - sizeof(*t),
492 e->comefrom)) { 499 e->comefrom)) {
493 module_put(t->u.kernel.target->me);
494 duprintf("arp_tables: check failed for `%s'.\n", 500 duprintf("arp_tables: check failed for `%s'.\n",
495 t->u.kernel.target->name); 501 t->u.kernel.target->name);
496 ret = -EINVAL; 502 ret = -EINVAL;
497 goto out; 503 goto err;
498 } 504 }
499 505
500 (*i)++; 506 (*i)++;
501 return 0; 507 return 0;
502 508err:
509 module_put(t->u.kernel.target->me);
503out: 510out:
504 return ret; 511 return ret;
505} 512}
@@ -555,7 +562,7 @@ static inline int cleanup_entry(struct arpt_entry *e, unsigned int *i)
555 562
556 t = arpt_get_target(e); 563 t = arpt_get_target(e);
557 if (t->u.kernel.target->destroy) 564 if (t->u.kernel.target->destroy)
558 t->u.kernel.target->destroy(t->data, 565 t->u.kernel.target->destroy(t->u.kernel.target, t->data,
559 t->u.target_size - sizeof(*t)); 566 t->u.target_size - sizeof(*t));
560 module_put(t->u.kernel.target->me); 567 module_put(t->u.kernel.target->me);
561 return 0; 568 return 0;
@@ -1138,11 +1145,13 @@ void arpt_unregister_table(struct arpt_table *table)
1138/* The built-in targets: standard (NULL) and error. */ 1145/* The built-in targets: standard (NULL) and error. */
1139static struct arpt_target arpt_standard_target = { 1146static struct arpt_target arpt_standard_target = {
1140 .name = ARPT_STANDARD_TARGET, 1147 .name = ARPT_STANDARD_TARGET,
1148 .targetsize = sizeof(int),
1141}; 1149};
1142 1150
1143static struct arpt_target arpt_error_target = { 1151static struct arpt_target arpt_error_target = {
1144 .name = ARPT_ERROR_TARGET, 1152 .name = ARPT_ERROR_TARGET,
1145 .target = arpt_error, 1153 .target = arpt_error,
1154 .targetsize = ARPT_FUNCTION_MAXNAMELEN,
1146}; 1155};
1147 1156
1148static struct nf_sockopt_ops arpt_sockopts = { 1157static struct nf_sockopt_ops arpt_sockopts = {
diff --git a/net/ipv4/netfilter/arpt_mangle.c b/net/ipv4/netfilter/arpt_mangle.c
index c97650a16a5b..0f2a95350e26 100644
--- a/net/ipv4/netfilter/arpt_mangle.c
+++ b/net/ipv4/netfilter/arpt_mangle.c
@@ -8,9 +8,10 @@ MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
8MODULE_DESCRIPTION("arptables arp payload mangle target"); 8MODULE_DESCRIPTION("arptables arp payload mangle target");
9 9
10static unsigned int 10static unsigned int
11target(struct sk_buff **pskb, const struct net_device *in, 11target(struct sk_buff **pskb,
12 const struct net_device *out, unsigned int hooknum, const void *targinfo, 12 const struct net_device *in, const struct net_device *out,
13 void *userinfo) 13 unsigned int hooknum, const struct xt_target *target,
14 const void *targinfo, void *userinfo)
14{ 15{
15 const struct arpt_mangle *mangle = targinfo; 16 const struct arpt_mangle *mangle = targinfo;
16 struct arphdr *arp; 17 struct arphdr *arp;
@@ -65,8 +66,8 @@ target(struct sk_buff **pskb, const struct net_device *in,
65} 66}
66 67
67static int 68static int
68checkentry(const char *tablename, const void *e, void *targinfo, 69checkentry(const char *tablename, const void *e, const struct xt_target *target,
69 unsigned int targinfosize, unsigned int hook_mask) 70 void *targinfo, unsigned int targinfosize, unsigned int hook_mask)
70{ 71{
71 const struct arpt_mangle *mangle = targinfo; 72 const struct arpt_mangle *mangle = targinfo;
72 73
@@ -80,12 +81,12 @@ checkentry(const char *tablename, const void *e, void *targinfo,
80 return 1; 81 return 1;
81} 82}
82 83
83static struct arpt_target arpt_mangle_reg 84static struct arpt_target arpt_mangle_reg = {
84= { 85 .name = "mangle",
85 .name = "mangle", 86 .target = target,
86 .target = target, 87 .targetsize = sizeof(struct arpt_mangle),
87 .checkentry = checkentry, 88 .checkentry = checkentry,
88 .me = THIS_MODULE, 89 .me = THIS_MODULE,
89}; 90};
90 91
91static int __init init(void) 92static int __init init(void)
diff --git a/net/ipv4/netfilter/ip_conntrack_helper_h323.c b/net/ipv4/netfilter/ip_conntrack_helper_h323.c
new file mode 100644
index 000000000000..20da6730b860
--- /dev/null
+++ b/net/ipv4/netfilter/ip_conntrack_helper_h323.c
@@ -0,0 +1,1731 @@
1/*
2 * H.323 connection tracking helper
3 *
4 * Copyright (c) 2006 Jing Min Zhao <zhaojingmin@users.sourceforge.net>
5 *
6 * This source code is licensed under General Public License version 2.
7 *
8 * Based on the 'brute force' H.323 connection tracking module by
9 * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
10 *
11 * For more information, please see http://nath323.sourceforge.net/
12 *
13 * Changes:
14 * 2006-02-01 - initial version 0.1
15 *
16 * 2006-02-20 - version 0.2
17 * 1. Changed source format to follow kernel conventions
18 * 2. Deleted some unnecessary structures
19 * 3. Minor fixes
20 *
21 * 2006-03-10 - version 0.3
22 * 1. Added support for multiple TPKTs in one packet (suggested by
23 * Patrick McHardy)
24 * 2. Avoid excessive stack usage (based on Patrick McHardy's patch)
25 * 3. Added support for non-linear skb (based on Patrick McHardy's patch)
26 * 4. Fixed missing H.245 module owner (Patrick McHardy)
27 * 5. Avoid long RAS expectation chains (Patrick McHardy)
28 * 6. Fixed incorrect __exit attribute (Patrick McHardy)
29 * 7. Eliminated unnecessary return code
30 * 8. Fixed incorrect use of NAT data from conntrack code (suggested by
31 * Patrick McHardy)
32 * 9. Fixed TTL calculation error in RCF
33 * 10. Added TTL support in RRQ
34 * 11. Better support for separate TPKT header and data
35 *
36 * 2006-03-15 - version 0.4
37 * 1. Added support for T.120 channels
38 * 2. Added parameter gkrouted_only (suggested by Patrick McHardy)
39 * 3. Splitted ASN.1 code and data (suggested by Patrick McHardy)
40 * 4. Sort ASN.1 data to avoid forwarding declarations (suggested by
41 * Patrick McHardy)
42 * 5. Reset next TPKT data length in get_tpkt_data()
43 */
44
45#include <linux/config.h>
46#include <linux/module.h>
47#include <linux/netfilter.h>
48#include <linux/ip.h>
49#include <net/tcp.h>
50#include <linux/netfilter_ipv4/ip_conntrack.h>
51#include <linux/netfilter_ipv4/ip_conntrack_core.h>
52#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
53#include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
54#include <linux/netfilter_ipv4/ip_conntrack_h323.h>
55#include <linux/moduleparam.h>
56
57#include "ip_conntrack_helper_h323_asn1.h"
58
59#if 0
60#define DEBUGP printk
61#else
62#define DEBUGP(format, args...)
63#endif
64
65/* Parameters */
66static int gkrouted_only = 1;
67module_param(gkrouted_only, int, 0600);
68MODULE_PARM_DESC(gkrouted_only, "only accept calls from gatekeeper");
69
70/* Hooks for NAT */
71int (*set_h245_addr_hook) (struct sk_buff ** pskb,
72 unsigned char **data, int dataoff,
73 H245_TransportAddress * addr,
74 u_int32_t ip, u_int16_t port);
75int (*set_h225_addr_hook) (struct sk_buff ** pskb,
76 unsigned char **data, int dataoff,
77 TransportAddress * addr,
78 u_int32_t ip, u_int16_t port);
79int (*set_sig_addr_hook) (struct sk_buff ** pskb,
80 struct ip_conntrack * ct,
81 enum ip_conntrack_info ctinfo,
82 unsigned char **data,
83 TransportAddress * addr, int count);
84int (*set_ras_addr_hook) (struct sk_buff ** pskb,
85 struct ip_conntrack * ct,
86 enum ip_conntrack_info ctinfo,
87 unsigned char **data,
88 TransportAddress * addr, int count);
89int (*nat_rtp_rtcp_hook) (struct sk_buff ** pskb,
90 struct ip_conntrack * ct,
91 enum ip_conntrack_info ctinfo,
92 unsigned char **data, int dataoff,
93 H245_TransportAddress * addr,
94 u_int16_t port, u_int16_t rtp_port,
95 struct ip_conntrack_expect * rtp_exp,
96 struct ip_conntrack_expect * rtcp_exp);
97int (*nat_t120_hook) (struct sk_buff ** pskb,
98 struct ip_conntrack * ct,
99 enum ip_conntrack_info ctinfo,
100 unsigned char **data, int dataoff,
101 H245_TransportAddress * addr, u_int16_t port,
102 struct ip_conntrack_expect * exp);
103int (*nat_h245_hook) (struct sk_buff ** pskb,
104 struct ip_conntrack * ct,
105 enum ip_conntrack_info ctinfo,
106 unsigned char **data, int dataoff,
107 TransportAddress * addr, u_int16_t port,
108 struct ip_conntrack_expect * exp);
109int (*nat_q931_hook) (struct sk_buff ** pskb,
110 struct ip_conntrack * ct,
111 enum ip_conntrack_info ctinfo,
112 unsigned char **data, TransportAddress * addr, int idx,
113 u_int16_t port, struct ip_conntrack_expect * exp);
114
115
116static DEFINE_SPINLOCK(ip_h323_lock);
117static char *h323_buffer;
118
119/****************************************************************************/
120static int get_tpkt_data(struct sk_buff **pskb, struct ip_conntrack *ct,
121 enum ip_conntrack_info ctinfo,
122 unsigned char **data, int *datalen, int *dataoff)
123{
124 struct ip_ct_h323_master *info = &ct->help.ct_h323_info;
125 int dir = CTINFO2DIR(ctinfo);
126 struct tcphdr _tcph, *th;
127 int tcpdatalen;
128 int tcpdataoff;
129 unsigned char *tpkt;
130 int tpktlen;
131 int tpktoff;
132
133 /* Get TCP header */
134 th = skb_header_pointer(*pskb, (*pskb)->nh.iph->ihl * 4,
135 sizeof(_tcph), &_tcph);
136 if (th == NULL)
137 return 0;
138
139 /* Get TCP data offset */
140 tcpdataoff = (*pskb)->nh.iph->ihl * 4 + th->doff * 4;
141
142 /* Get TCP data length */
143 tcpdatalen = (*pskb)->len - tcpdataoff;
144 if (tcpdatalen <= 0) /* No TCP data */
145 goto clear_out;
146
147 if (*data == NULL) { /* first TPKT */
148 /* Get first TPKT pointer */
149 tpkt = skb_header_pointer(*pskb, tcpdataoff, tcpdatalen,
150 h323_buffer);
151 BUG_ON(tpkt == NULL);
152
153 /* Validate TPKT identifier */
154 if (tcpdatalen < 4 || tpkt[0] != 0x03 || tpkt[1] != 0) {
155 /* Netmeeting sends TPKT header and data separately */
156 if (info->tpkt_len[dir] > 0) {
157 DEBUGP("ip_ct_h323: previous packet "
158 "indicated separate TPKT data of %hu "
159 "bytes\n", info->tpkt_len[dir]);
160 if (info->tpkt_len[dir] <= tcpdatalen) {
161 /* Yes, there was a TPKT header
162 * received */
163 *data = tpkt;
164 *datalen = info->tpkt_len[dir];
165 *dataoff = 0;
166 goto out;
167 }
168
169 /* Fragmented TPKT */
170 if (net_ratelimit())
171 printk("ip_ct_h323: "
172 "fragmented TPKT\n");
173 goto clear_out;
174 }
175
176 /* It is not even a TPKT */
177 return 0;
178 }
179 tpktoff = 0;
180 } else { /* Next TPKT */
181 tpktoff = *dataoff + *datalen;
182 tcpdatalen -= tpktoff;
183 if (tcpdatalen <= 4) /* No more TPKT */
184 goto clear_out;
185 tpkt = *data + *datalen;
186
187 /* Validate TPKT identifier */
188 if (tpkt[0] != 0x03 || tpkt[1] != 0)
189 goto clear_out;
190 }
191
192 /* Validate TPKT length */
193 tpktlen = tpkt[2] * 256 + tpkt[3];
194 if (tpktlen > tcpdatalen) {
195 if (tcpdatalen == 4) { /* Separate TPKT header */
196 /* Netmeeting sends TPKT header and data separately */
197 DEBUGP("ip_ct_h323: separate TPKT header indicates "
198 "there will be TPKT data of %hu bytes\n",
199 tpktlen - 4);
200 info->tpkt_len[dir] = tpktlen - 4;
201 return 0;
202 }
203
204 if (net_ratelimit())
205 printk("ip_ct_h323: incomplete TPKT (fragmented?)\n");
206 goto clear_out;
207 }
208
209 /* This is the encapsulated data */
210 *data = tpkt + 4;
211 *datalen = tpktlen - 4;
212 *dataoff = tpktoff + 4;
213
214 out:
215 /* Clear TPKT length */
216 info->tpkt_len[dir] = 0;
217 return 1;
218
219 clear_out:
220 info->tpkt_len[dir] = 0;
221 return 0;
222}
223
224/****************************************************************************/
225int get_h245_addr(unsigned char *data, H245_TransportAddress * addr,
226 u_int32_t * ip, u_int16_t * port)
227{
228 unsigned char *p;
229
230 if (addr->choice != eH245_TransportAddress_unicastAddress ||
231 addr->unicastAddress.choice != eUnicastAddress_iPAddress)
232 return 0;
233
234 p = data + addr->unicastAddress.iPAddress.network;
235 *ip = htonl((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]));
236 *port = (p[4] << 8) | (p[5]);
237
238 return 1;
239}
240
241/****************************************************************************/
242static int expect_rtp_rtcp(struct sk_buff **pskb, struct ip_conntrack *ct,
243 enum ip_conntrack_info ctinfo,
244 unsigned char **data, int dataoff,
245 H245_TransportAddress * addr)
246{
247 int dir = CTINFO2DIR(ctinfo);
248 int ret = 0;
249 u_int32_t ip;
250 u_int16_t port;
251 u_int16_t rtp_port;
252 struct ip_conntrack_expect *rtp_exp;
253 struct ip_conntrack_expect *rtcp_exp;
254
255 /* Read RTP or RTCP address */
256 if (!get_h245_addr(*data, addr, &ip, &port) ||
257 ip != ct->tuplehash[dir].tuple.src.ip || port == 0)
258 return 0;
259
260 /* RTP port is even */
261 rtp_port = port & (~1);
262
263 /* Create expect for RTP */
264 if ((rtp_exp = ip_conntrack_expect_alloc(ct)) == NULL)
265 return -1;
266 rtp_exp->tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
267 rtp_exp->tuple.src.u.udp.port = 0;
268 rtp_exp->tuple.dst.ip = ct->tuplehash[!dir].tuple.dst.ip;
269 rtp_exp->tuple.dst.u.udp.port = htons(rtp_port);
270 rtp_exp->tuple.dst.protonum = IPPROTO_UDP;
271 rtp_exp->mask.src.ip = 0xFFFFFFFF;
272 rtp_exp->mask.src.u.udp.port = 0;
273 rtp_exp->mask.dst.ip = 0xFFFFFFFF;
274 rtp_exp->mask.dst.u.udp.port = 0xFFFF;
275 rtp_exp->mask.dst.protonum = 0xFF;
276 rtp_exp->flags = 0;
277
278 /* Create expect for RTCP */
279 if ((rtcp_exp = ip_conntrack_expect_alloc(ct)) == NULL) {
280 ip_conntrack_expect_put(rtp_exp);
281 return -1;
282 }
283 rtcp_exp->tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
284 rtcp_exp->tuple.src.u.udp.port = 0;
285 rtcp_exp->tuple.dst.ip = ct->tuplehash[!dir].tuple.dst.ip;
286 rtcp_exp->tuple.dst.u.udp.port = htons(rtp_port + 1);
287 rtcp_exp->tuple.dst.protonum = IPPROTO_UDP;
288 rtcp_exp->mask.src.ip = 0xFFFFFFFF;
289 rtcp_exp->mask.src.u.udp.port = 0;
290 rtcp_exp->mask.dst.ip = 0xFFFFFFFF;
291 rtcp_exp->mask.dst.u.udp.port = 0xFFFF;
292 rtcp_exp->mask.dst.protonum = 0xFF;
293 rtcp_exp->flags = 0;
294
295 if (ct->tuplehash[dir].tuple.src.ip !=
296 ct->tuplehash[!dir].tuple.dst.ip && nat_rtp_rtcp_hook) {
297 /* NAT needed */
298 ret = nat_rtp_rtcp_hook(pskb, ct, ctinfo, data, dataoff,
299 addr, port, rtp_port, rtp_exp,
300 rtcp_exp);
301 } else { /* Conntrack only */
302 rtp_exp->expectfn = NULL;
303 rtcp_exp->expectfn = NULL;
304
305 if (ip_conntrack_expect_related(rtp_exp) == 0) {
306 if (ip_conntrack_expect_related(rtcp_exp) == 0) {
307 DEBUGP("ip_ct_h323: expect RTP "
308 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
309 NIPQUAD(rtp_exp->tuple.src.ip),
310 ntohs(rtp_exp->tuple.src.u.udp.port),
311 NIPQUAD(rtp_exp->tuple.dst.ip),
312 ntohs(rtp_exp->tuple.dst.u.udp.port));
313 DEBUGP("ip_ct_h323: expect RTCP "
314 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
315 NIPQUAD(rtcp_exp->tuple.src.ip),
316 ntohs(rtcp_exp->tuple.src.u.udp.port),
317 NIPQUAD(rtcp_exp->tuple.dst.ip),
318 ntohs(rtcp_exp->tuple.dst.u.udp.port));
319 } else {
320 ip_conntrack_unexpect_related(rtp_exp);
321 ret = -1;
322 }
323 } else
324 ret = -1;
325 }
326
327 ip_conntrack_expect_put(rtp_exp);
328 ip_conntrack_expect_put(rtcp_exp);
329
330 return ret;
331}
332
333/****************************************************************************/
334static int expect_t120(struct sk_buff **pskb,
335 struct ip_conntrack *ct,
336 enum ip_conntrack_info ctinfo,
337 unsigned char **data, int dataoff,
338 H245_TransportAddress * addr)
339{
340 int dir = CTINFO2DIR(ctinfo);
341 int ret = 0;
342 u_int32_t ip;
343 u_int16_t port;
344 struct ip_conntrack_expect *exp = NULL;
345
346 /* Read T.120 address */
347 if (!get_h245_addr(*data, addr, &ip, &port) ||
348 ip != ct->tuplehash[dir].tuple.src.ip || port == 0)
349 return 0;
350
351 /* Create expect for T.120 connections */
352 if ((exp = ip_conntrack_expect_alloc(ct)) == NULL)
353 return -1;
354 exp->tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
355 exp->tuple.src.u.tcp.port = 0;
356 exp->tuple.dst.ip = ct->tuplehash[!dir].tuple.dst.ip;
357 exp->tuple.dst.u.tcp.port = htons(port);
358 exp->tuple.dst.protonum = IPPROTO_TCP;
359 exp->mask.src.ip = 0xFFFFFFFF;
360 exp->mask.src.u.tcp.port = 0;
361 exp->mask.dst.ip = 0xFFFFFFFF;
362 exp->mask.dst.u.tcp.port = 0xFFFF;
363 exp->mask.dst.protonum = 0xFF;
364 exp->flags = IP_CT_EXPECT_PERMANENT; /* Accept multiple channels */
365
366 if (ct->tuplehash[dir].tuple.src.ip !=
367 ct->tuplehash[!dir].tuple.dst.ip && nat_t120_hook) {
368 /* NAT needed */
369 ret = nat_t120_hook(pskb, ct, ctinfo, data, dataoff, addr,
370 port, exp);
371 } else { /* Conntrack only */
372 exp->expectfn = NULL;
373 if (ip_conntrack_expect_related(exp) == 0) {
374 DEBUGP("ip_ct_h323: expect T.120 "
375 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
376 NIPQUAD(exp->tuple.src.ip),
377 ntohs(exp->tuple.src.u.tcp.port),
378 NIPQUAD(exp->tuple.dst.ip),
379 ntohs(exp->tuple.dst.u.tcp.port));
380 } else
381 ret = -1;
382 }
383
384 ip_conntrack_expect_put(exp);
385
386 return ret;
387}
388
389/****************************************************************************/
390static int process_h245_channel(struct sk_buff **pskb,
391 struct ip_conntrack *ct,
392 enum ip_conntrack_info ctinfo,
393 unsigned char **data, int dataoff,
394 H2250LogicalChannelParameters * channel)
395{
396 int ret;
397
398 if (channel->options & eH2250LogicalChannelParameters_mediaChannel) {
399 /* RTP */
400 ret = expect_rtp_rtcp(pskb, ct, ctinfo, data, dataoff,
401 &channel->mediaChannel);
402 if (ret < 0)
403 return -1;
404 }
405
406 if (channel->
407 options & eH2250LogicalChannelParameters_mediaControlChannel) {
408 /* RTCP */
409 ret = expect_rtp_rtcp(pskb, ct, ctinfo, data, dataoff,
410 &channel->mediaControlChannel);
411 if (ret < 0)
412 return -1;
413 }
414
415 return 0;
416}
417
418/****************************************************************************/
419static int process_olc(struct sk_buff **pskb, struct ip_conntrack *ct,
420 enum ip_conntrack_info ctinfo,
421 unsigned char **data, int dataoff,
422 OpenLogicalChannel * olc)
423{
424 int ret;
425
426 DEBUGP("ip_ct_h323: OpenLogicalChannel\n");
427
428 if (olc->forwardLogicalChannelParameters.multiplexParameters.choice ==
429 eOpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters)
430 {
431 ret = process_h245_channel(pskb, ct, ctinfo, data, dataoff,
432 &olc->
433 forwardLogicalChannelParameters.
434 multiplexParameters.
435 h2250LogicalChannelParameters);
436 if (ret < 0)
437 return -1;
438 }
439
440 if ((olc->options &
441 eOpenLogicalChannel_reverseLogicalChannelParameters) &&
442 (olc->reverseLogicalChannelParameters.options &
443 eOpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters)
444 && (olc->reverseLogicalChannelParameters.multiplexParameters.
445 choice ==
446 eOpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters))
447 {
448 ret =
449 process_h245_channel(pskb, ct, ctinfo, data, dataoff,
450 &olc->
451 reverseLogicalChannelParameters.
452 multiplexParameters.
453 h2250LogicalChannelParameters);
454 if (ret < 0)
455 return -1;
456 }
457
458 if ((olc->options & eOpenLogicalChannel_separateStack) &&
459 olc->forwardLogicalChannelParameters.dataType.choice ==
460 eDataType_data &&
461 olc->forwardLogicalChannelParameters.dataType.data.application.
462 choice == eDataApplicationCapability_application_t120 &&
463 olc->forwardLogicalChannelParameters.dataType.data.application.
464 t120.choice == eDataProtocolCapability_separateLANStack &&
465 olc->separateStack.networkAddress.choice ==
466 eNetworkAccessParameters_networkAddress_localAreaAddress) {
467 ret = expect_t120(pskb, ct, ctinfo, data, dataoff,
468 &olc->separateStack.networkAddress.
469 localAreaAddress);
470 if (ret < 0)
471 return -1;
472 }
473
474 return 0;
475}
476
477/****************************************************************************/
478static int process_olca(struct sk_buff **pskb, struct ip_conntrack *ct,
479 enum ip_conntrack_info ctinfo,
480 unsigned char **data, int dataoff,
481 OpenLogicalChannelAck * olca)
482{
483 H2250LogicalChannelAckParameters *ack;
484 int ret;
485
486 DEBUGP("ip_ct_h323: OpenLogicalChannelAck\n");
487
488 if ((olca->options &
489 eOpenLogicalChannelAck_reverseLogicalChannelParameters) &&
490 (olca->reverseLogicalChannelParameters.options &
491 eOpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters)
492 && (olca->reverseLogicalChannelParameters.multiplexParameters.
493 choice ==
494 eOpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters))
495 {
496 ret = process_h245_channel(pskb, ct, ctinfo, data, dataoff,
497 &olca->
498 reverseLogicalChannelParameters.
499 multiplexParameters.
500 h2250LogicalChannelParameters);
501 if (ret < 0)
502 return -1;
503 }
504
505 if ((olca->options &
506 eOpenLogicalChannelAck_forwardMultiplexAckParameters) &&
507 (olca->forwardMultiplexAckParameters.choice ==
508 eOpenLogicalChannelAck_forwardMultiplexAckParameters_h2250LogicalChannelAckParameters))
509 {
510 ack = &olca->forwardMultiplexAckParameters.
511 h2250LogicalChannelAckParameters;
512 if (ack->options &
513 eH2250LogicalChannelAckParameters_mediaChannel) {
514 /* RTP */
515 ret = expect_rtp_rtcp(pskb, ct, ctinfo, data, dataoff,
516 &ack->mediaChannel);
517 if (ret < 0)
518 return -1;
519 }
520
521 if (ack->options &
522 eH2250LogicalChannelAckParameters_mediaControlChannel) {
523 /* RTCP */
524 ret = expect_rtp_rtcp(pskb, ct, ctinfo, data, dataoff,
525 &ack->mediaControlChannel);
526 if (ret < 0)
527 return -1;
528 }
529 }
530
531 return 0;
532}
533
534/****************************************************************************/
535static int process_h245(struct sk_buff **pskb, struct ip_conntrack *ct,
536 enum ip_conntrack_info ctinfo,
537 unsigned char **data, int dataoff,
538 MultimediaSystemControlMessage * mscm)
539{
540 switch (mscm->choice) {
541 case eMultimediaSystemControlMessage_request:
542 if (mscm->request.choice ==
543 eRequestMessage_openLogicalChannel) {
544 return process_olc(pskb, ct, ctinfo, data, dataoff,
545 &mscm->request.openLogicalChannel);
546 }
547 DEBUGP("ip_ct_h323: H.245 Request %d\n",
548 mscm->request.choice);
549 break;
550 case eMultimediaSystemControlMessage_response:
551 if (mscm->response.choice ==
552 eResponseMessage_openLogicalChannelAck) {
553 return process_olca(pskb, ct, ctinfo, data, dataoff,
554 &mscm->response.
555 openLogicalChannelAck);
556 }
557 DEBUGP("ip_ct_h323: H.245 Response %d\n",
558 mscm->response.choice);
559 break;
560 default:
561 DEBUGP("ip_ct_h323: H.245 signal %d\n", mscm->choice);
562 break;
563 }
564
565 return 0;
566}
567
568/****************************************************************************/
569static int h245_help(struct sk_buff **pskb, struct ip_conntrack *ct,
570 enum ip_conntrack_info ctinfo)
571{
572 static MultimediaSystemControlMessage mscm;
573 unsigned char *data = NULL;
574 int datalen;
575 int dataoff;
576 int ret;
577
578 /* Until there's been traffic both ways, don't look in packets. */
579 if (ctinfo != IP_CT_ESTABLISHED
580 && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
581 return NF_ACCEPT;
582 }
583 DEBUGP("ip_ct_h245: skblen = %u\n", (*pskb)->len);
584
585 spin_lock_bh(&ip_h323_lock);
586
587 /* Process each TPKT */
588 while (get_tpkt_data(pskb, ct, ctinfo, &data, &datalen, &dataoff)) {
589 DEBUGP("ip_ct_h245: TPKT %u.%u.%u.%u->%u.%u.%u.%u, len=%d\n",
590 NIPQUAD((*pskb)->nh.iph->saddr),
591 NIPQUAD((*pskb)->nh.iph->daddr), datalen);
592
593 /* Decode H.245 signal */
594 ret = DecodeMultimediaSystemControlMessage(data, datalen,
595 &mscm);
596 if (ret < 0) {
597 if (net_ratelimit())
598 printk("ip_ct_h245: decoding error: %s\n",
599 ret == H323_ERROR_BOUND ?
600 "out of bound" : "out of range");
601 /* We don't drop when decoding error */
602 break;
603 }
604
605 /* Process H.245 signal */
606 if (process_h245(pskb, ct, ctinfo, &data, dataoff, &mscm) < 0)
607 goto drop;
608 }
609
610 spin_unlock_bh(&ip_h323_lock);
611 return NF_ACCEPT;
612
613 drop:
614 spin_unlock_bh(&ip_h323_lock);
615 if (net_ratelimit())
616 printk("ip_ct_h245: packet dropped\n");
617 return NF_DROP;
618}
619
620/****************************************************************************/
621static struct ip_conntrack_helper ip_conntrack_helper_h245 = {
622 .name = "H.245",
623 .me = THIS_MODULE,
624 .max_expected = H323_RTP_CHANNEL_MAX * 4 + 2 /* T.120 */ ,
625 .timeout = 240,
626 .tuple = {.dst = {.protonum = IPPROTO_TCP}},
627 .mask = {.src = {.u = {0xFFFF}},
628 .dst = {.protonum = 0xFF}},
629 .help = h245_help
630};
631
632/****************************************************************************/
633void ip_conntrack_h245_expect(struct ip_conntrack *new,
634 struct ip_conntrack_expect *this)
635{
636 write_lock_bh(&ip_conntrack_lock);
637 new->helper = &ip_conntrack_helper_h245;
638 write_unlock_bh(&ip_conntrack_lock);
639}
640
641/****************************************************************************/
642static int get_h225_addr(unsigned char *data, TransportAddress * addr,
643 u_int32_t * ip, u_int16_t * port)
644{
645 unsigned char *p;
646
647 if (addr->choice != eTransportAddress_ipAddress)
648 return 0;
649
650 p = data + addr->ipAddress.ip;
651 *ip = htonl((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]));
652 *port = (p[4] << 8) | (p[5]);
653
654 return 1;
655}
656
657/****************************************************************************/
658static int expect_h245(struct sk_buff **pskb, struct ip_conntrack *ct,
659 enum ip_conntrack_info ctinfo,
660 unsigned char **data, int dataoff,
661 TransportAddress * addr)
662{
663 int dir = CTINFO2DIR(ctinfo);
664 int ret = 0;
665 u_int32_t ip;
666 u_int16_t port;
667 struct ip_conntrack_expect *exp = NULL;
668
669 /* Read h245Address */
670 if (!get_h225_addr(*data, addr, &ip, &port) ||
671 ip != ct->tuplehash[dir].tuple.src.ip || port == 0)
672 return 0;
673
674 /* Create expect for h245 connection */
675 if ((exp = ip_conntrack_expect_alloc(ct)) == NULL)
676 return -1;
677 exp->tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
678 exp->tuple.src.u.tcp.port = 0;
679 exp->tuple.dst.ip = ct->tuplehash[!dir].tuple.dst.ip;
680 exp->tuple.dst.u.tcp.port = htons(port);
681 exp->tuple.dst.protonum = IPPROTO_TCP;
682 exp->mask.src.ip = 0xFFFFFFFF;
683 exp->mask.src.u.tcp.port = 0;
684 exp->mask.dst.ip = 0xFFFFFFFF;
685 exp->mask.dst.u.tcp.port = 0xFFFF;
686 exp->mask.dst.protonum = 0xFF;
687 exp->flags = 0;
688
689 if (ct->tuplehash[dir].tuple.src.ip !=
690 ct->tuplehash[!dir].tuple.dst.ip && nat_h245_hook) {
691 /* NAT needed */
692 ret = nat_h245_hook(pskb, ct, ctinfo, data, dataoff, addr,
693 port, exp);
694 } else { /* Conntrack only */
695 exp->expectfn = ip_conntrack_h245_expect;
696
697 if (ip_conntrack_expect_related(exp) == 0) {
698 DEBUGP("ip_ct_q931: expect H.245 "
699 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
700 NIPQUAD(exp->tuple.src.ip),
701 ntohs(exp->tuple.src.u.tcp.port),
702 NIPQUAD(exp->tuple.dst.ip),
703 ntohs(exp->tuple.dst.u.tcp.port));
704 } else
705 ret = -1;
706 }
707
708 ip_conntrack_expect_put(exp);
709
710 return ret;
711}
712
713/****************************************************************************/
714static int process_setup(struct sk_buff **pskb, struct ip_conntrack *ct,
715 enum ip_conntrack_info ctinfo,
716 unsigned char **data, int dataoff,
717 Setup_UUIE * setup)
718{
719 int dir = CTINFO2DIR(ctinfo);
720 int ret;
721 int i;
722 u_int32_t ip;
723 u_int16_t port;
724
725 DEBUGP("ip_ct_q931: Setup\n");
726
727 if (setup->options & eSetup_UUIE_h245Address) {
728 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
729 &setup->h245Address);
730 if (ret < 0)
731 return -1;
732 }
733
734 if ((setup->options & eSetup_UUIE_destCallSignalAddress) &&
735 (set_h225_addr_hook) &&
736 get_h225_addr(*data, &setup->destCallSignalAddress, &ip, &port) &&
737 ip != ct->tuplehash[!dir].tuple.src.ip) {
738 DEBUGP("ip_ct_q931: set destCallSignalAddress "
739 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
740 NIPQUAD(ip), port,
741 NIPQUAD(ct->tuplehash[!dir].tuple.src.ip),
742 ntohs(ct->tuplehash[!dir].tuple.src.u.tcp.port));
743 ret = set_h225_addr_hook(pskb, data, dataoff,
744 &setup->destCallSignalAddress,
745 ct->tuplehash[!dir].tuple.src.ip,
746 ntohs(ct->tuplehash[!dir].tuple.src.
747 u.tcp.port));
748 if (ret < 0)
749 return -1;
750 }
751
752 if ((setup->options & eSetup_UUIE_sourceCallSignalAddress) &&
753 (set_h225_addr_hook) &&
754 get_h225_addr(*data, &setup->sourceCallSignalAddress, &ip, &port)
755 && ip != ct->tuplehash[!dir].tuple.dst.ip) {
756 DEBUGP("ip_ct_q931: set sourceCallSignalAddress "
757 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
758 NIPQUAD(ip), port,
759 NIPQUAD(ct->tuplehash[!dir].tuple.dst.ip),
760 ntohs(ct->tuplehash[!dir].tuple.dst.u.tcp.port));
761 ret = set_h225_addr_hook(pskb, data, dataoff,
762 &setup->sourceCallSignalAddress,
763 ct->tuplehash[!dir].tuple.dst.ip,
764 ntohs(ct->tuplehash[!dir].tuple.dst.
765 u.tcp.port));
766 if (ret < 0)
767 return -1;
768 }
769
770 if (setup->options & eSetup_UUIE_fastStart) {
771 for (i = 0; i < setup->fastStart.count; i++) {
772 ret = process_olc(pskb, ct, ctinfo, data, dataoff,
773 &setup->fastStart.item[i]);
774 if (ret < 0)
775 return -1;
776 }
777 }
778
779 return 0;
780}
781
782/****************************************************************************/
783static int process_callproceeding(struct sk_buff **pskb,
784 struct ip_conntrack *ct,
785 enum ip_conntrack_info ctinfo,
786 unsigned char **data, int dataoff,
787 CallProceeding_UUIE * callproc)
788{
789 int ret;
790 int i;
791
792 DEBUGP("ip_ct_q931: CallProceeding\n");
793
794 if (callproc->options & eCallProceeding_UUIE_h245Address) {
795 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
796 &callproc->h245Address);
797 if (ret < 0)
798 return -1;
799 }
800
801 if (callproc->options & eCallProceeding_UUIE_fastStart) {
802 for (i = 0; i < callproc->fastStart.count; i++) {
803 ret = process_olc(pskb, ct, ctinfo, data, dataoff,
804 &callproc->fastStart.item[i]);
805 if (ret < 0)
806 return -1;
807 }
808 }
809
810 return 0;
811}
812
813/****************************************************************************/
814static int process_connect(struct sk_buff **pskb, struct ip_conntrack *ct,
815 enum ip_conntrack_info ctinfo,
816 unsigned char **data, int dataoff,
817 Connect_UUIE * connect)
818{
819 int ret;
820 int i;
821
822 DEBUGP("ip_ct_q931: Connect\n");
823
824 if (connect->options & eConnect_UUIE_h245Address) {
825 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
826 &connect->h245Address);
827 if (ret < 0)
828 return -1;
829 }
830
831 if (connect->options & eConnect_UUIE_fastStart) {
832 for (i = 0; i < connect->fastStart.count; i++) {
833 ret = process_olc(pskb, ct, ctinfo, data, dataoff,
834 &connect->fastStart.item[i]);
835 if (ret < 0)
836 return -1;
837 }
838 }
839
840 return 0;
841}
842
843/****************************************************************************/
844static int process_alerting(struct sk_buff **pskb, struct ip_conntrack *ct,
845 enum ip_conntrack_info ctinfo,
846 unsigned char **data, int dataoff,
847 Alerting_UUIE * alert)
848{
849 int ret;
850 int i;
851
852 DEBUGP("ip_ct_q931: Alerting\n");
853
854 if (alert->options & eAlerting_UUIE_h245Address) {
855 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
856 &alert->h245Address);
857 if (ret < 0)
858 return -1;
859 }
860
861 if (alert->options & eAlerting_UUIE_fastStart) {
862 for (i = 0; i < alert->fastStart.count; i++) {
863 ret = process_olc(pskb, ct, ctinfo, data, dataoff,
864 &alert->fastStart.item[i]);
865 if (ret < 0)
866 return -1;
867 }
868 }
869
870 return 0;
871}
872
873/****************************************************************************/
874static int process_information(struct sk_buff **pskb,
875 struct ip_conntrack *ct,
876 enum ip_conntrack_info ctinfo,
877 unsigned char **data, int dataoff,
878 Information_UUIE * info)
879{
880 int ret;
881 int i;
882
883 DEBUGP("ip_ct_q931: Information\n");
884
885 if (info->options & eInformation_UUIE_fastStart) {
886 for (i = 0; i < info->fastStart.count; i++) {
887 ret = process_olc(pskb, ct, ctinfo, data, dataoff,
888 &info->fastStart.item[i]);
889 if (ret < 0)
890 return -1;
891 }
892 }
893
894 return 0;
895}
896
897/****************************************************************************/
898static int process_facility(struct sk_buff **pskb, struct ip_conntrack *ct,
899 enum ip_conntrack_info ctinfo,
900 unsigned char **data, int dataoff,
901 Facility_UUIE * facility)
902{
903 int ret;
904 int i;
905
906 DEBUGP("ip_ct_q931: Facility\n");
907
908 if (facility->options & eFacility_UUIE_h245Address) {
909 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
910 &facility->h245Address);
911 if (ret < 0)
912 return -1;
913 }
914
915 if (facility->options & eFacility_UUIE_fastStart) {
916 for (i = 0; i < facility->fastStart.count; i++) {
917 ret = process_olc(pskb, ct, ctinfo, data, dataoff,
918 &facility->fastStart.item[i]);
919 if (ret < 0)
920 return -1;
921 }
922 }
923
924 return 0;
925}
926
927/****************************************************************************/
928static int process_progress(struct sk_buff **pskb, struct ip_conntrack *ct,
929 enum ip_conntrack_info ctinfo,
930 unsigned char **data, int dataoff,
931 Progress_UUIE * progress)
932{
933 int ret;
934 int i;
935
936 DEBUGP("ip_ct_q931: Progress\n");
937
938 if (progress->options & eProgress_UUIE_h245Address) {
939 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
940 &progress->h245Address);
941 if (ret < 0)
942 return -1;
943 }
944
945 if (progress->options & eProgress_UUIE_fastStart) {
946 for (i = 0; i < progress->fastStart.count; i++) {
947 ret = process_olc(pskb, ct, ctinfo, data, dataoff,
948 &progress->fastStart.item[i]);
949 if (ret < 0)
950 return -1;
951 }
952 }
953
954 return 0;
955}
956
957/****************************************************************************/
958static int process_q931(struct sk_buff **pskb, struct ip_conntrack *ct,
959 enum ip_conntrack_info ctinfo,
960 unsigned char **data, int dataoff, Q931 * q931)
961{
962 H323_UU_PDU *pdu = &q931->UUIE.h323_uu_pdu;
963 int i;
964 int ret = 0;
965
966 switch (pdu->h323_message_body.choice) {
967 case eH323_UU_PDU_h323_message_body_setup:
968 ret = process_setup(pskb, ct, ctinfo, data, dataoff,
969 &pdu->h323_message_body.setup);
970 break;
971 case eH323_UU_PDU_h323_message_body_callProceeding:
972 ret = process_callproceeding(pskb, ct, ctinfo, data, dataoff,
973 &pdu->h323_message_body.
974 callProceeding);
975 break;
976 case eH323_UU_PDU_h323_message_body_connect:
977 ret = process_connect(pskb, ct, ctinfo, data, dataoff,
978 &pdu->h323_message_body.connect);
979 break;
980 case eH323_UU_PDU_h323_message_body_alerting:
981 ret = process_alerting(pskb, ct, ctinfo, data, dataoff,
982 &pdu->h323_message_body.alerting);
983 break;
984 case eH323_UU_PDU_h323_message_body_information:
985 ret = process_information(pskb, ct, ctinfo, data, dataoff,
986 &pdu->h323_message_body.
987 information);
988 break;
989 case eH323_UU_PDU_h323_message_body_facility:
990 ret = process_facility(pskb, ct, ctinfo, data, dataoff,
991 &pdu->h323_message_body.facility);
992 break;
993 case eH323_UU_PDU_h323_message_body_progress:
994 ret = process_progress(pskb, ct, ctinfo, data, dataoff,
995 &pdu->h323_message_body.progress);
996 break;
997 default:
998 DEBUGP("ip_ct_q931: Q.931 signal %d\n",
999 pdu->h323_message_body.choice);
1000 break;
1001 }
1002
1003 if (ret < 0)
1004 return -1;
1005
1006 if (pdu->options & eH323_UU_PDU_h245Control) {
1007 for (i = 0; i < pdu->h245Control.count; i++) {
1008 ret = process_h245(pskb, ct, ctinfo, data, dataoff,
1009 &pdu->h245Control.item[i]);
1010 if (ret < 0)
1011 return -1;
1012 }
1013 }
1014
1015 return 0;
1016}
1017
1018/****************************************************************************/
1019static int q931_help(struct sk_buff **pskb, struct ip_conntrack *ct,
1020 enum ip_conntrack_info ctinfo)
1021{
1022 static Q931 q931;
1023 unsigned char *data = NULL;
1024 int datalen;
1025 int dataoff;
1026 int ret;
1027
1028 /* Until there's been traffic both ways, don't look in packets. */
1029 if (ctinfo != IP_CT_ESTABLISHED
1030 && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
1031 return NF_ACCEPT;
1032 }
1033 DEBUGP("ip_ct_q931: skblen = %u\n", (*pskb)->len);
1034
1035 spin_lock_bh(&ip_h323_lock);
1036
1037 /* Process each TPKT */
1038 while (get_tpkt_data(pskb, ct, ctinfo, &data, &datalen, &dataoff)) {
1039 DEBUGP("ip_ct_q931: TPKT %u.%u.%u.%u->%u.%u.%u.%u, len=%d\n",
1040 NIPQUAD((*pskb)->nh.iph->saddr),
1041 NIPQUAD((*pskb)->nh.iph->daddr), datalen);
1042
1043 /* Decode Q.931 signal */
1044 ret = DecodeQ931(data, datalen, &q931);
1045 if (ret < 0) {
1046 if (net_ratelimit())
1047 printk("ip_ct_q931: decoding error: %s\n",
1048 ret == H323_ERROR_BOUND ?
1049 "out of bound" : "out of range");
1050 /* We don't drop when decoding error */
1051 break;
1052 }
1053
1054 /* Process Q.931 signal */
1055 if (process_q931(pskb, ct, ctinfo, &data, dataoff, &q931) < 0)
1056 goto drop;
1057 }
1058
1059 spin_unlock_bh(&ip_h323_lock);
1060 return NF_ACCEPT;
1061
1062 drop:
1063 spin_unlock_bh(&ip_h323_lock);
1064 if (net_ratelimit())
1065 printk("ip_ct_q931: packet dropped\n");
1066 return NF_DROP;
1067}
1068
1069/****************************************************************************/
1070static struct ip_conntrack_helper ip_conntrack_helper_q931 = {
1071 .name = "Q.931",
1072 .me = THIS_MODULE,
1073 .max_expected = H323_RTP_CHANNEL_MAX * 4 + 4 /* T.120 and H.245 */ ,
1074 .timeout = 240,
1075 .tuple = {.src = {.u = {__constant_htons(Q931_PORT)}},
1076 .dst = {.protonum = IPPROTO_TCP}},
1077 .mask = {.src = {.u = {0xFFFF}},
1078 .dst = {.protonum = 0xFF}},
1079 .help = q931_help
1080};
1081
1082/****************************************************************************/
1083void ip_conntrack_q931_expect(struct ip_conntrack *new,
1084 struct ip_conntrack_expect *this)
1085{
1086 write_lock_bh(&ip_conntrack_lock);
1087 new->helper = &ip_conntrack_helper_q931;
1088 write_unlock_bh(&ip_conntrack_lock);
1089}
1090
1091/****************************************************************************/
1092static unsigned char *get_udp_data(struct sk_buff **pskb, int *datalen)
1093{
1094 struct udphdr _uh, *uh;
1095 int dataoff;
1096
1097 uh = skb_header_pointer(*pskb, (*pskb)->nh.iph->ihl * 4, sizeof(_uh),
1098 &_uh);
1099 if (uh == NULL)
1100 return NULL;
1101 dataoff = (*pskb)->nh.iph->ihl * 4 + sizeof(_uh);
1102 if (dataoff >= (*pskb)->len)
1103 return NULL;
1104 *datalen = (*pskb)->len - dataoff;
1105 return skb_header_pointer(*pskb, dataoff, *datalen, h323_buffer);
1106}
1107
1108/****************************************************************************/
1109static struct ip_conntrack_expect *find_expect(struct ip_conntrack *ct,
1110 u_int32_t ip, u_int16_t port)
1111{
1112 struct ip_conntrack_expect *exp;
1113 struct ip_conntrack_tuple tuple;
1114
1115 tuple.src.ip = 0;
1116 tuple.src.u.tcp.port = 0;
1117 tuple.dst.ip = ip;
1118 tuple.dst.u.tcp.port = htons(port);
1119 tuple.dst.protonum = IPPROTO_TCP;
1120
1121 exp = __ip_conntrack_expect_find(&tuple);
1122 if (exp->master == ct)
1123 return exp;
1124 return NULL;
1125}
1126
1127/****************************************************************************/
1128static int set_expect_timeout(struct ip_conntrack_expect *exp,
1129 unsigned timeout)
1130{
1131 if (!exp || !del_timer(&exp->timeout))
1132 return 0;
1133
1134 exp->timeout.expires = jiffies + timeout * HZ;
1135 add_timer(&exp->timeout);
1136
1137 return 1;
1138}
1139
1140/****************************************************************************/
1141static int expect_q931(struct sk_buff **pskb, struct ip_conntrack *ct,
1142 enum ip_conntrack_info ctinfo,
1143 unsigned char **data,
1144 TransportAddress * addr, int count)
1145{
1146 struct ip_ct_h323_master *info = &ct->help.ct_h323_info;
1147 int dir = CTINFO2DIR(ctinfo);
1148 int ret = 0;
1149 int i;
1150 u_int32_t ip;
1151 u_int16_t port;
1152 struct ip_conntrack_expect *exp;
1153
1154 /* Look for the first related address */
1155 for (i = 0; i < count; i++) {
1156 if (get_h225_addr(*data, &addr[i], &ip, &port) &&
1157 ip == ct->tuplehash[dir].tuple.src.ip && port != 0)
1158 break;
1159 }
1160
1161 if (i >= count) /* Not found */
1162 return 0;
1163
1164 /* Create expect for Q.931 */
1165 if ((exp = ip_conntrack_expect_alloc(ct)) == NULL)
1166 return -1;
1167 exp->tuple.src.ip = gkrouted_only ? /* only accept calls from GK? */
1168 ct->tuplehash[!dir].tuple.src.ip : 0;
1169 exp->tuple.src.u.tcp.port = 0;
1170 exp->tuple.dst.ip = ct->tuplehash[!dir].tuple.dst.ip;
1171 exp->tuple.dst.u.tcp.port = htons(port);
1172 exp->tuple.dst.protonum = IPPROTO_TCP;
1173 exp->mask.src.ip = gkrouted_only ? 0xFFFFFFFF : 0;
1174 exp->mask.src.u.tcp.port = 0;
1175 exp->mask.dst.ip = 0xFFFFFFFF;
1176 exp->mask.dst.u.tcp.port = 0xFFFF;
1177 exp->mask.dst.protonum = 0xFF;
1178 exp->flags = IP_CT_EXPECT_PERMANENT; /* Accept multiple calls */
1179
1180 if (nat_q931_hook) { /* Need NAT */
1181 ret = nat_q931_hook(pskb, ct, ctinfo, data, addr, i,
1182 port, exp);
1183 } else { /* Conntrack only */
1184 exp->expectfn = ip_conntrack_q931_expect;
1185
1186 if (ip_conntrack_expect_related(exp) == 0) {
1187 DEBUGP("ip_ct_ras: expect Q.931 "
1188 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
1189 NIPQUAD(exp->tuple.src.ip),
1190 ntohs(exp->tuple.src.u.tcp.port),
1191 NIPQUAD(exp->tuple.dst.ip),
1192 ntohs(exp->tuple.dst.u.tcp.port));
1193
1194 /* Save port for looking up expect in processing RCF */
1195 info->sig_port[dir] = port;
1196 } else
1197 ret = -1;
1198 }
1199
1200 ip_conntrack_expect_put(exp);
1201
1202 return ret;
1203}
1204
1205/****************************************************************************/
1206static int process_grq(struct sk_buff **pskb, struct ip_conntrack *ct,
1207 enum ip_conntrack_info ctinfo,
1208 unsigned char **data, GatekeeperRequest * grq)
1209{
1210 DEBUGP("ip_ct_ras: GRQ\n");
1211
1212 if (set_ras_addr_hook) /* NATed */
1213 return set_ras_addr_hook(pskb, ct, ctinfo, data,
1214 &grq->rasAddress, 1);
1215 return 0;
1216}
1217
1218/* Declare before using */
1219static void ip_conntrack_ras_expect(struct ip_conntrack *new,
1220 struct ip_conntrack_expect *this);
1221
1222/****************************************************************************/
1223static int process_gcf(struct sk_buff **pskb, struct ip_conntrack *ct,
1224 enum ip_conntrack_info ctinfo,
1225 unsigned char **data, GatekeeperConfirm * gcf)
1226{
1227 int dir = CTINFO2DIR(ctinfo);
1228 int ret = 0;
1229 u_int32_t ip;
1230 u_int16_t port;
1231 struct ip_conntrack_expect *exp;
1232
1233 DEBUGP("ip_ct_ras: GCF\n");
1234
1235 if (!get_h225_addr(*data, &gcf->rasAddress, &ip, &port))
1236 return 0;
1237
1238 /* Registration port is the same as discovery port */
1239 if (ip == ct->tuplehash[dir].tuple.src.ip &&
1240 port == ntohs(ct->tuplehash[dir].tuple.src.u.udp.port))
1241 return 0;
1242
1243 /* Avoid RAS expectation loops. A GCF is never expected. */
1244 if (test_bit(IPS_EXPECTED_BIT, &ct->status))
1245 return 0;
1246
1247 /* Need new expect */
1248 if ((exp = ip_conntrack_expect_alloc(ct)) == NULL)
1249 return -1;
1250 exp->tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
1251 exp->tuple.src.u.tcp.port = 0;
1252 exp->tuple.dst.ip = ip;
1253 exp->tuple.dst.u.tcp.port = htons(port);
1254 exp->tuple.dst.protonum = IPPROTO_UDP;
1255 exp->mask.src.ip = 0xFFFFFFFF;
1256 exp->mask.src.u.tcp.port = 0;
1257 exp->mask.dst.ip = 0xFFFFFFFF;
1258 exp->mask.dst.u.tcp.port = 0xFFFF;
1259 exp->mask.dst.protonum = 0xFF;
1260 exp->flags = 0;
1261 exp->expectfn = ip_conntrack_ras_expect;
1262 if (ip_conntrack_expect_related(exp) == 0) {
1263 DEBUGP("ip_ct_ras: expect RAS "
1264 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
1265 NIPQUAD(exp->tuple.src.ip),
1266 ntohs(exp->tuple.src.u.tcp.port),
1267 NIPQUAD(exp->tuple.dst.ip),
1268 ntohs(exp->tuple.dst.u.tcp.port));
1269 } else
1270 ret = -1;
1271
1272 ip_conntrack_expect_put(exp);
1273
1274 return ret;
1275}
1276
1277/****************************************************************************/
1278static int process_rrq(struct sk_buff **pskb, struct ip_conntrack *ct,
1279 enum ip_conntrack_info ctinfo,
1280 unsigned char **data, RegistrationRequest * rrq)
1281{
1282 struct ip_ct_h323_master *info = &ct->help.ct_h323_info;
1283 int ret;
1284
1285 DEBUGP("ip_ct_ras: RRQ\n");
1286
1287 ret = expect_q931(pskb, ct, ctinfo, data,
1288 rrq->callSignalAddress.item,
1289 rrq->callSignalAddress.count);
1290 if (ret < 0)
1291 return -1;
1292
1293 if (set_ras_addr_hook) {
1294 ret = set_ras_addr_hook(pskb, ct, ctinfo, data,
1295 rrq->rasAddress.item,
1296 rrq->rasAddress.count);
1297 if (ret < 0)
1298 return -1;
1299 }
1300
1301 if (rrq->options & eRegistrationRequest_timeToLive) {
1302 DEBUGP("ip_ct_ras: RRQ TTL = %u seconds\n", rrq->timeToLive);
1303 info->timeout = rrq->timeToLive;
1304 } else
1305 info->timeout = 0;
1306
1307 return 0;
1308}
1309
1310/****************************************************************************/
1311static int process_rcf(struct sk_buff **pskb, struct ip_conntrack *ct,
1312 enum ip_conntrack_info ctinfo,
1313 unsigned char **data, RegistrationConfirm * rcf)
1314{
1315 struct ip_ct_h323_master *info = &ct->help.ct_h323_info;
1316 int dir = CTINFO2DIR(ctinfo);
1317 int ret;
1318 struct ip_conntrack_expect *exp;
1319
1320 DEBUGP("ip_ct_ras: RCF\n");
1321
1322 if (set_sig_addr_hook) {
1323 ret = set_sig_addr_hook(pskb, ct, ctinfo, data,
1324 rcf->callSignalAddress.item,
1325 rcf->callSignalAddress.count);
1326 if (ret < 0)
1327 return -1;
1328 }
1329
1330 if (rcf->options & eRegistrationConfirm_timeToLive) {
1331 DEBUGP("ip_ct_ras: RCF TTL = %u seconds\n", rcf->timeToLive);
1332 info->timeout = rcf->timeToLive;
1333 }
1334
1335 if (info->timeout > 0) {
1336 DEBUGP
1337 ("ip_ct_ras: set RAS connection timeout to %u seconds\n",
1338 info->timeout);
1339 ip_ct_refresh_acct(ct, ctinfo, NULL, info->timeout * HZ);
1340
1341 /* Set expect timeout */
1342 read_lock_bh(&ip_conntrack_lock);
1343 exp = find_expect(ct, ct->tuplehash[dir].tuple.dst.ip,
1344 info->sig_port[!dir]);
1345 if (exp) {
1346 DEBUGP("ip_ct_ras: set Q.931 expect "
1347 "(%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu) "
1348 "timeout to %u seconds\n",
1349 NIPQUAD(exp->tuple.src.ip),
1350 ntohs(exp->tuple.src.u.tcp.port),
1351 NIPQUAD(exp->tuple.dst.ip),
1352 ntohs(exp->tuple.dst.u.tcp.port),
1353 info->timeout);
1354 set_expect_timeout(exp, info->timeout);
1355 }
1356 read_unlock_bh(&ip_conntrack_lock);
1357 }
1358
1359 return 0;
1360}
1361
1362/****************************************************************************/
1363static int process_urq(struct sk_buff **pskb, struct ip_conntrack *ct,
1364 enum ip_conntrack_info ctinfo,
1365 unsigned char **data, UnregistrationRequest * urq)
1366{
1367 struct ip_ct_h323_master *info = &ct->help.ct_h323_info;
1368 int dir = CTINFO2DIR(ctinfo);
1369 int ret;
1370
1371 DEBUGP("ip_ct_ras: URQ\n");
1372
1373 if (set_sig_addr_hook) {
1374 ret = set_sig_addr_hook(pskb, ct, ctinfo, data,
1375 urq->callSignalAddress.item,
1376 urq->callSignalAddress.count);
1377 if (ret < 0)
1378 return -1;
1379 }
1380
1381 /* Clear old expect */
1382 ip_ct_remove_expectations(ct);
1383 info->sig_port[dir] = 0;
1384 info->sig_port[!dir] = 0;
1385
1386 /* Give it 30 seconds for UCF or URJ */
1387 ip_ct_refresh_acct(ct, ctinfo, NULL, 30 * HZ);
1388
1389 return 0;
1390}
1391
1392/****************************************************************************/
1393static int process_arq(struct sk_buff **pskb, struct ip_conntrack *ct,
1394 enum ip_conntrack_info ctinfo,
1395 unsigned char **data, AdmissionRequest * arq)
1396{
1397 struct ip_ct_h323_master *info = &ct->help.ct_h323_info;
1398 int dir = CTINFO2DIR(ctinfo);
1399 u_int32_t ip;
1400 u_int16_t port;
1401
1402 DEBUGP("ip_ct_ras: ARQ\n");
1403
1404 if ((arq->options & eAdmissionRequest_destCallSignalAddress) &&
1405 get_h225_addr(*data, &arq->destCallSignalAddress, &ip, &port) &&
1406 ip == ct->tuplehash[dir].tuple.src.ip &&
1407 port == info->sig_port[dir] && set_h225_addr_hook) {
1408 /* Answering ARQ */
1409 return set_h225_addr_hook(pskb, data, 0,
1410 &arq->destCallSignalAddress,
1411 ct->tuplehash[!dir].tuple.dst.ip,
1412 info->sig_port[!dir]);
1413 }
1414
1415 if ((arq->options & eAdmissionRequest_srcCallSignalAddress) &&
1416 get_h225_addr(*data, &arq->srcCallSignalAddress, &ip, &port) &&
1417 ip == ct->tuplehash[dir].tuple.src.ip && set_h225_addr_hook) {
1418 /* Calling ARQ */
1419 return set_h225_addr_hook(pskb, data, 0,
1420 &arq->srcCallSignalAddress,
1421 ct->tuplehash[!dir].tuple.dst.ip,
1422 port);
1423 }
1424
1425 return 0;
1426}
1427
1428/****************************************************************************/
1429static int process_acf(struct sk_buff **pskb, struct ip_conntrack *ct,
1430 enum ip_conntrack_info ctinfo,
1431 unsigned char **data, AdmissionConfirm * acf)
1432{
1433 int dir = CTINFO2DIR(ctinfo);
1434 int ret = 0;
1435 u_int32_t ip;
1436 u_int16_t port;
1437 struct ip_conntrack_expect *exp;
1438
1439 DEBUGP("ip_ct_ras: ACF\n");
1440
1441 if (!get_h225_addr(*data, &acf->destCallSignalAddress, &ip, &port))
1442 return 0;
1443
1444 if (ip == ct->tuplehash[dir].tuple.dst.ip) { /* Answering ACF */
1445 if (set_sig_addr_hook)
1446 return set_sig_addr_hook(pskb, ct, ctinfo, data,
1447 &acf->destCallSignalAddress,
1448 1);
1449 return 0;
1450 }
1451
1452 /* Need new expect */
1453 if ((exp = ip_conntrack_expect_alloc(ct)) == NULL)
1454 return -1;
1455 exp->tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
1456 exp->tuple.src.u.tcp.port = 0;
1457 exp->tuple.dst.ip = ip;
1458 exp->tuple.dst.u.tcp.port = htons(port);
1459 exp->tuple.dst.protonum = IPPROTO_TCP;
1460 exp->mask.src.ip = 0xFFFFFFFF;
1461 exp->mask.src.u.tcp.port = 0;
1462 exp->mask.dst.ip = 0xFFFFFFFF;
1463 exp->mask.dst.u.tcp.port = 0xFFFF;
1464 exp->mask.dst.protonum = 0xFF;
1465 exp->flags = IP_CT_EXPECT_PERMANENT;
1466 exp->expectfn = ip_conntrack_q931_expect;
1467
1468 if (ip_conntrack_expect_related(exp) == 0) {
1469 DEBUGP("ip_ct_ras: expect Q.931 "
1470 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
1471 NIPQUAD(exp->tuple.src.ip),
1472 ntohs(exp->tuple.src.u.tcp.port),
1473 NIPQUAD(exp->tuple.dst.ip),
1474 ntohs(exp->tuple.dst.u.tcp.port));
1475 } else
1476 ret = -1;
1477
1478 ip_conntrack_expect_put(exp);
1479
1480 return ret;
1481}
1482
1483/****************************************************************************/
1484static int process_lrq(struct sk_buff **pskb, struct ip_conntrack *ct,
1485 enum ip_conntrack_info ctinfo,
1486 unsigned char **data, LocationRequest * lrq)
1487{
1488 DEBUGP("ip_ct_ras: LRQ\n");
1489
1490 if (set_ras_addr_hook)
1491 return set_ras_addr_hook(pskb, ct, ctinfo, data,
1492 &lrq->replyAddress, 1);
1493 return 0;
1494}
1495
1496/****************************************************************************/
1497static int process_lcf(struct sk_buff **pskb, struct ip_conntrack *ct,
1498 enum ip_conntrack_info ctinfo,
1499 unsigned char **data, LocationConfirm * lcf)
1500{
1501 int dir = CTINFO2DIR(ctinfo);
1502 int ret = 0;
1503 u_int32_t ip;
1504 u_int16_t port;
1505 struct ip_conntrack_expect *exp = NULL;
1506
1507 DEBUGP("ip_ct_ras: LCF\n");
1508
1509 if (!get_h225_addr(*data, &lcf->callSignalAddress, &ip, &port))
1510 return 0;
1511
1512 /* Need new expect for call signal */
1513 if ((exp = ip_conntrack_expect_alloc(ct)) == NULL)
1514 return -1;
1515 exp->tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
1516 exp->tuple.src.u.tcp.port = 0;
1517 exp->tuple.dst.ip = ip;
1518 exp->tuple.dst.u.tcp.port = htons(port);
1519 exp->tuple.dst.protonum = IPPROTO_TCP;
1520 exp->mask.src.ip = 0xFFFFFFFF;
1521 exp->mask.src.u.tcp.port = 0;
1522 exp->mask.dst.ip = 0xFFFFFFFF;
1523 exp->mask.dst.u.tcp.port = 0xFFFF;
1524 exp->mask.dst.protonum = 0xFF;
1525 exp->flags = IP_CT_EXPECT_PERMANENT;
1526 exp->expectfn = ip_conntrack_q931_expect;
1527
1528 if (ip_conntrack_expect_related(exp) == 0) {
1529 DEBUGP("ip_ct_ras: expect Q.931 "
1530 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
1531 NIPQUAD(exp->tuple.src.ip),
1532 ntohs(exp->tuple.src.u.tcp.port),
1533 NIPQUAD(exp->tuple.dst.ip),
1534 ntohs(exp->tuple.dst.u.tcp.port));
1535 } else
1536 ret = -1;
1537
1538 ip_conntrack_expect_put(exp);
1539
1540 /* Ignore rasAddress */
1541
1542 return ret;
1543}
1544
1545/****************************************************************************/
1546static int process_irr(struct sk_buff **pskb, struct ip_conntrack *ct,
1547 enum ip_conntrack_info ctinfo,
1548 unsigned char **data, InfoRequestResponse * irr)
1549{
1550 int ret;
1551
1552 DEBUGP("ip_ct_ras: IRR\n");
1553
1554 if (set_ras_addr_hook) {
1555 ret = set_ras_addr_hook(pskb, ct, ctinfo, data,
1556 &irr->rasAddress, 1);
1557 if (ret < 0)
1558 return -1;
1559 }
1560
1561 if (set_sig_addr_hook) {
1562 ret = set_sig_addr_hook(pskb, ct, ctinfo, data,
1563 irr->callSignalAddress.item,
1564 irr->callSignalAddress.count);
1565 if (ret < 0)
1566 return -1;
1567 }
1568
1569 return 0;
1570}
1571
1572/****************************************************************************/
1573static int process_ras(struct sk_buff **pskb, struct ip_conntrack *ct,
1574 enum ip_conntrack_info ctinfo,
1575 unsigned char **data, RasMessage * ras)
1576{
1577 switch (ras->choice) {
1578 case eRasMessage_gatekeeperRequest:
1579 return process_grq(pskb, ct, ctinfo, data,
1580 &ras->gatekeeperRequest);
1581 case eRasMessage_gatekeeperConfirm:
1582 return process_gcf(pskb, ct, ctinfo, data,
1583 &ras->gatekeeperConfirm);
1584 case eRasMessage_registrationRequest:
1585 return process_rrq(pskb, ct, ctinfo, data,
1586 &ras->registrationRequest);
1587 case eRasMessage_registrationConfirm:
1588 return process_rcf(pskb, ct, ctinfo, data,
1589 &ras->registrationConfirm);
1590 case eRasMessage_unregistrationRequest:
1591 return process_urq(pskb, ct, ctinfo, data,
1592 &ras->unregistrationRequest);
1593 case eRasMessage_admissionRequest:
1594 return process_arq(pskb, ct, ctinfo, data,
1595 &ras->admissionRequest);
1596 case eRasMessage_admissionConfirm:
1597 return process_acf(pskb, ct, ctinfo, data,
1598 &ras->admissionConfirm);
1599 case eRasMessage_locationRequest:
1600 return process_lrq(pskb, ct, ctinfo, data,
1601 &ras->locationRequest);
1602 case eRasMessage_locationConfirm:
1603 return process_lcf(pskb, ct, ctinfo, data,
1604 &ras->locationConfirm);
1605 case eRasMessage_infoRequestResponse:
1606 return process_irr(pskb, ct, ctinfo, data,
1607 &ras->infoRequestResponse);
1608 default:
1609 DEBUGP("ip_ct_ras: RAS message %d\n", ras->choice);
1610 break;
1611 }
1612
1613 return 0;
1614}
1615
1616/****************************************************************************/
1617static int ras_help(struct sk_buff **pskb, struct ip_conntrack *ct,
1618 enum ip_conntrack_info ctinfo)
1619{
1620 static RasMessage ras;
1621 unsigned char *data;
1622 int datalen = 0;
1623 int ret;
1624
1625 DEBUGP("ip_ct_ras: skblen = %u\n", (*pskb)->len);
1626
1627 spin_lock_bh(&ip_h323_lock);
1628
1629 /* Get UDP data */
1630 data = get_udp_data(pskb, &datalen);
1631 if (data == NULL)
1632 goto accept;
1633 DEBUGP("ip_ct_ras: RAS message %u.%u.%u.%u->%u.%u.%u.%u, len=%d\n",
1634 NIPQUAD((*pskb)->nh.iph->saddr),
1635 NIPQUAD((*pskb)->nh.iph->daddr), datalen);
1636
1637 /* Decode RAS message */
1638 ret = DecodeRasMessage(data, datalen, &ras);
1639 if (ret < 0) {
1640 if (net_ratelimit())
1641 printk("ip_ct_ras: decoding error: %s\n",
1642 ret == H323_ERROR_BOUND ?
1643 "out of bound" : "out of range");
1644 goto accept;
1645 }
1646
1647 /* Process RAS message */
1648 if (process_ras(pskb, ct, ctinfo, &data, &ras) < 0)
1649 goto drop;
1650
1651 accept:
1652 spin_unlock_bh(&ip_h323_lock);
1653 return NF_ACCEPT;
1654
1655 drop:
1656 spin_unlock_bh(&ip_h323_lock);
1657 if (net_ratelimit())
1658 printk("ip_ct_ras: packet dropped\n");
1659 return NF_DROP;
1660}
1661
1662/****************************************************************************/
1663static struct ip_conntrack_helper ip_conntrack_helper_ras = {
1664 .name = "RAS",
1665 .me = THIS_MODULE,
1666 .max_expected = 32,
1667 .timeout = 240,
1668 .tuple = {.src = {.u = {__constant_htons(RAS_PORT)}},
1669 .dst = {.protonum = IPPROTO_UDP}},
1670 .mask = {.src = {.u = {0xFFFE}},
1671 .dst = {.protonum = 0xFF}},
1672 .help = ras_help,
1673};
1674
1675/****************************************************************************/
1676static void ip_conntrack_ras_expect(struct ip_conntrack *new,
1677 struct ip_conntrack_expect *this)
1678{
1679 write_lock_bh(&ip_conntrack_lock);
1680 new->helper = &ip_conntrack_helper_ras;
1681 write_unlock_bh(&ip_conntrack_lock);
1682}
1683
1684/****************************************************************************/
1685/* Not __exit - called from init() */
1686static void fini(void)
1687{
1688 ip_conntrack_helper_unregister(&ip_conntrack_helper_ras);
1689 ip_conntrack_helper_unregister(&ip_conntrack_helper_q931);
1690 kfree(h323_buffer);
1691 DEBUGP("ip_ct_h323: fini\n");
1692}
1693
1694/****************************************************************************/
1695static int __init init(void)
1696{
1697 int ret;
1698
1699 h323_buffer = kmalloc(65536, GFP_KERNEL);
1700 if (!h323_buffer)
1701 return -ENOMEM;
1702 if ((ret = ip_conntrack_helper_register(&ip_conntrack_helper_q931)) ||
1703 (ret = ip_conntrack_helper_register(&ip_conntrack_helper_ras))) {
1704 fini();
1705 return ret;
1706 }
1707
1708 DEBUGP("ip_ct_h323: init success\n");
1709 return 0;
1710}
1711
1712/****************************************************************************/
1713module_init(init);
1714module_exit(fini);
1715
1716EXPORT_SYMBOL(get_h245_addr);
1717EXPORT_SYMBOL(get_h225_addr);
1718EXPORT_SYMBOL(ip_conntrack_h245_expect);
1719EXPORT_SYMBOL(ip_conntrack_q931_expect);
1720EXPORT_SYMBOL(set_h245_addr_hook);
1721EXPORT_SYMBOL(set_h225_addr_hook);
1722EXPORT_SYMBOL(set_sig_addr_hook);
1723EXPORT_SYMBOL(set_ras_addr_hook);
1724EXPORT_SYMBOL(nat_rtp_rtcp_hook);
1725EXPORT_SYMBOL(nat_t120_hook);
1726EXPORT_SYMBOL(nat_h245_hook);
1727EXPORT_SYMBOL(nat_q931_hook);
1728
1729MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>");
1730MODULE_DESCRIPTION("H.323 connection tracking helper");
1731MODULE_LICENSE("GPL");
diff --git a/net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.c b/net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.c
new file mode 100644
index 000000000000..afa525129b51
--- /dev/null
+++ b/net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.c
@@ -0,0 +1,870 @@
1/****************************************************************************
2 * ip_conntrack_helper_h323_asn1.c - BER and PER decoding library for H.323
3 * conntrack/NAT module.
4 *
5 * Copyright (c) 2006 by Jing Min Zhao <zhaojingmin@hotmail.com>
6 *
7 * This source code is licensed under General Public License version 2.
8 *
9 * See ip_conntrack_helper_h323_asn1.h for details.
10 *
11 ****************************************************************************/
12
13#ifdef __KERNEL__
14#include <linux/kernel.h>
15#else
16#include <stdio.h>
17#endif
18#include "ip_conntrack_helper_h323_asn1.h"
19
20/* Trace Flag */
21#ifndef H323_TRACE
22#define H323_TRACE 0
23#endif
24
25#if H323_TRACE
26#define TAB_SIZE 4
27#define IFTHEN(cond, act) if(cond){act;}
28#ifdef __KERNEL__
29#define PRINT printk
30#else
31#define PRINT printf
32#endif
33#define FNAME(name) name,
34#else
35#define IFTHEN(cond, act)
36#define PRINT(fmt, args...)
37#define FNAME(name)
38#endif
39
40/* ASN.1 Types */
41#define NUL 0
42#define BOOL 1
43#define OID 2
44#define INT 3
45#define ENUM 4
46#define BITSTR 5
47#define NUMSTR 6
48#define NUMDGT 6
49#define TBCDSTR 6
50#define OCTSTR 7
51#define PRTSTR 7
52#define IA5STR 7
53#define GENSTR 7
54#define BMPSTR 8
55#define SEQ 9
56#define SET 9
57#define SEQOF 10
58#define SETOF 10
59#define CHOICE 11
60
61/* Constraint Types */
62#define FIXD 0
63/* #define BITS 1-8 */
64#define BYTE 9
65#define WORD 10
66#define CONS 11
67#define SEMI 12
68#define UNCO 13
69
70/* ASN.1 Type Attributes */
71#define SKIP 0
72#define STOP 1
73#define DECODE 2
74#define EXT 4
75#define OPEN 8
76#define OPT 16
77
78
79/* ASN.1 Field Structure */
80typedef struct field_t {
81#if H323_TRACE
82 char *name;
83#endif
84 unsigned char type;
85 unsigned char sz;
86 unsigned char lb;
87 unsigned char ub;
88 unsigned short attr;
89 unsigned short offset;
90 struct field_t *fields;
91} field_t;
92
93/* Bit Stream */
94typedef struct {
95 unsigned char *buf;
96 unsigned char *beg;
97 unsigned char *end;
98 unsigned char *cur;
99 unsigned bit;
100} bitstr_t;
101
102/* Tool Functions */
103#define INC_BIT(bs) if((++bs->bit)>7){bs->cur++;bs->bit=0;}
104#define INC_BITS(bs,b) if((bs->bit+=b)>7){bs->cur+=bs->bit>>3;bs->bit&=7;}
105#define BYTE_ALIGN(bs) if(bs->bit){bs->cur++;bs->bit=0;}
106#define CHECK_BOUND(bs,n) if(bs->cur+(n)>bs->end)return(H323_ERROR_BOUND)
107static unsigned get_len(bitstr_t * bs);
108static unsigned get_bit(bitstr_t * bs);
109static unsigned get_bits(bitstr_t * bs, unsigned b);
110static unsigned get_bitmap(bitstr_t * bs, unsigned b);
111static unsigned get_uint(bitstr_t * bs, int b);
112
113/* Decoder Functions */
114static int decode_nul(bitstr_t * bs, field_t * f, char *base, int level);
115static int decode_bool(bitstr_t * bs, field_t * f, char *base, int level);
116static int decode_oid(bitstr_t * bs, field_t * f, char *base, int level);
117static int decode_int(bitstr_t * bs, field_t * f, char *base, int level);
118static int decode_enum(bitstr_t * bs, field_t * f, char *base, int level);
119static int decode_bitstr(bitstr_t * bs, field_t * f, char *base, int level);
120static int decode_numstr(bitstr_t * bs, field_t * f, char *base, int level);
121static int decode_octstr(bitstr_t * bs, field_t * f, char *base, int level);
122static int decode_bmpstr(bitstr_t * bs, field_t * f, char *base, int level);
123static int decode_seq(bitstr_t * bs, field_t * f, char *base, int level);
124static int decode_seqof(bitstr_t * bs, field_t * f, char *base, int level);
125static int decode_choice(bitstr_t * bs, field_t * f, char *base, int level);
126
127/* Decoder Functions Vector */
128typedef int (*decoder_t) (bitstr_t *, field_t *, char *, int);
129static decoder_t Decoders[] = {
130 decode_nul,
131 decode_bool,
132 decode_oid,
133 decode_int,
134 decode_enum,
135 decode_bitstr,
136 decode_numstr,
137 decode_octstr,
138 decode_bmpstr,
139 decode_seq,
140 decode_seqof,
141 decode_choice,
142};
143
144/****************************************************************************
145 * H.323 Types
146 ****************************************************************************/
147#include "ip_conntrack_helper_h323_types.c"
148
149/****************************************************************************
150 * Functions
151 ****************************************************************************/
152/* Assume bs is aligned && v < 16384 */
153unsigned get_len(bitstr_t * bs)
154{
155 unsigned v;
156
157 v = *bs->cur++;
158
159 if (v & 0x80) {
160 v &= 0x3f;
161 v <<= 8;
162 v += *bs->cur++;
163 }
164
165 return v;
166}
167
168/****************************************************************************/
169unsigned get_bit(bitstr_t * bs)
170{
171 unsigned b = (*bs->cur) & (0x80 >> bs->bit);
172
173 INC_BIT(bs);
174
175 return b;
176}
177
178/****************************************************************************/
179/* Assume b <= 8 */
180unsigned get_bits(bitstr_t * bs, unsigned b)
181{
182 unsigned v, l;
183
184 v = (*bs->cur) & (0xffU >> bs->bit);
185 l = b + bs->bit;
186
187 if (l < 8) {
188 v >>= 8 - l;
189 bs->bit = l;
190 } else if (l == 8) {
191 bs->cur++;
192 bs->bit = 0;
193 } else { /* l > 8 */
194
195 v <<= 8;
196 v += *(++bs->cur);
197 v >>= 16 - l;
198 bs->bit = l - 8;
199 }
200
201 return v;
202}
203
204/****************************************************************************/
205/* Assume b <= 32 */
206unsigned get_bitmap(bitstr_t * bs, unsigned b)
207{
208 unsigned v, l, shift, bytes;
209
210 if (!b)
211 return 0;
212
213 l = bs->bit + b;
214
215 if (l < 8) {
216 v = (unsigned) (*bs->cur) << (bs->bit + 24);
217 bs->bit = l;
218 } else if (l == 8) {
219 v = (unsigned) (*bs->cur++) << (bs->bit + 24);
220 bs->bit = 0;
221 } else {
222 for (bytes = l >> 3, shift = 24, v = 0; bytes;
223 bytes--, shift -= 8)
224 v |= (unsigned) (*bs->cur++) << shift;
225
226 if (l < 32) {
227 v |= (unsigned) (*bs->cur) << shift;
228 v <<= bs->bit;
229 } else if (l > 32) {
230 v <<= bs->bit;
231 v |= (*bs->cur) >> (8 - bs->bit);
232 }
233
234 bs->bit = l & 0x7;
235 }
236
237 v &= 0xffffffff << (32 - b);
238
239 return v;
240}
241
242/****************************************************************************
243 * Assume bs is aligned and sizeof(unsigned int) == 4
244 ****************************************************************************/
245unsigned get_uint(bitstr_t * bs, int b)
246{
247 unsigned v = 0;
248
249 switch (b) {
250 case 4:
251 v |= *bs->cur++;
252 v <<= 8;
253 case 3:
254 v |= *bs->cur++;
255 v <<= 8;
256 case 2:
257 v |= *bs->cur++;
258 v <<= 8;
259 case 1:
260 v |= *bs->cur++;
261 break;
262 }
263 return v;
264}
265
266/****************************************************************************/
267int decode_nul(bitstr_t * bs, field_t * f, char *base, int level)
268{
269 PRINT("%*.s%s\n", level * TAB_SIZE, " ", f->name);
270
271 return H323_ERROR_NONE;
272}
273
274/****************************************************************************/
275int decode_bool(bitstr_t * bs, field_t * f, char *base, int level)
276{
277 PRINT("%*.s%s\n", level * TAB_SIZE, " ", f->name);
278
279 INC_BIT(bs);
280
281 CHECK_BOUND(bs, 0);
282 return H323_ERROR_NONE;
283}
284
285/****************************************************************************/
286int decode_oid(bitstr_t * bs, field_t * f, char *base, int level)
287{
288 int len;
289
290 PRINT("%*.s%s\n", level * TAB_SIZE, " ", f->name);
291
292 BYTE_ALIGN(bs);
293 CHECK_BOUND(bs, 1);
294 len = *bs->cur++;
295 bs->cur += len;
296
297 CHECK_BOUND(bs, 0);
298 return H323_ERROR_NONE;
299}
300
301/****************************************************************************/
302int decode_int(bitstr_t * bs, field_t * f, char *base, int level)
303{
304 unsigned len;
305
306 PRINT("%*.s%s", level * TAB_SIZE, " ", f->name);
307
308 switch (f->sz) {
309 case BYTE: /* Range == 256 */
310 BYTE_ALIGN(bs);
311 bs->cur++;
312 break;
313 case WORD: /* 257 <= Range <= 64K */
314 BYTE_ALIGN(bs);
315 bs->cur += 2;
316 break;
317 case CONS: /* 64K < Range < 4G */
318 len = get_bits(bs, 2) + 1;
319 BYTE_ALIGN(bs);
320 if (base && (f->attr & DECODE)) { /* timeToLive */
321 unsigned v = get_uint(bs, len) + f->lb;
322 PRINT(" = %u", v);
323 *((unsigned *) (base + f->offset)) = v;
324 }
325 bs->cur += len;
326 break;
327 case UNCO:
328 BYTE_ALIGN(bs);
329 CHECK_BOUND(bs, 2);
330 len = get_len(bs);
331 bs->cur += len;
332 break;
333 default: /* 2 <= Range <= 255 */
334 INC_BITS(bs, f->sz);
335 break;
336 }
337
338 PRINT("\n");
339
340 CHECK_BOUND(bs, 0);
341 return H323_ERROR_NONE;
342}
343
344/****************************************************************************/
345int decode_enum(bitstr_t * bs, field_t * f, char *base, int level)
346{
347 PRINT("%*.s%s\n", level * TAB_SIZE, " ", f->name);
348
349 if ((f->attr & EXT) && get_bit(bs)) {
350 INC_BITS(bs, 7);
351 } else {
352 INC_BITS(bs, f->sz);
353 }
354
355 CHECK_BOUND(bs, 0);
356 return H323_ERROR_NONE;
357}
358
359/****************************************************************************/
360int decode_bitstr(bitstr_t * bs, field_t * f, char *base, int level)
361{
362 unsigned len;
363
364 PRINT("%*.s%s\n", level * TAB_SIZE, " ", f->name);
365
366 BYTE_ALIGN(bs);
367 switch (f->sz) {
368 case FIXD: /* fixed length > 16 */
369 len = f->lb;
370 break;
371 case WORD: /* 2-byte length */
372 CHECK_BOUND(bs, 2);
373 len = (*bs->cur++) << 8;
374 len += (*bs->cur++) + f->lb;
375 break;
376 case SEMI:
377 CHECK_BOUND(bs, 2);
378 len = get_len(bs);
379 break;
380 default:
381 len = 0;
382 break;
383 }
384
385 bs->cur += len >> 3;
386 bs->bit = len & 7;
387
388 CHECK_BOUND(bs, 0);
389 return H323_ERROR_NONE;
390}
391
392/****************************************************************************/
393int decode_numstr(bitstr_t * bs, field_t * f, char *base, int level)
394{
395 unsigned len;
396
397 PRINT("%*.s%s\n", level * TAB_SIZE, " ", f->name);
398
399 /* 2 <= Range <= 255 */
400 len = get_bits(bs, f->sz) + f->lb;
401
402 BYTE_ALIGN(bs);
403 INC_BITS(bs, (len << 2));
404
405 CHECK_BOUND(bs, 0);
406 return H323_ERROR_NONE;
407}
408
409/****************************************************************************/
410int decode_octstr(bitstr_t * bs, field_t * f, char *base, int level)
411{
412 unsigned len;
413
414 PRINT("%*.s%s", level * TAB_SIZE, " ", f->name);
415
416 switch (f->sz) {
417 case FIXD: /* Range == 1 */
418 if (f->lb > 2) {
419 BYTE_ALIGN(bs);
420 if (base && (f->attr & DECODE)) {
421 /* The IP Address */
422 IFTHEN(f->lb == 4,
423 PRINT(" = %d.%d.%d.%d:%d",
424 bs->cur[0], bs->cur[1],
425 bs->cur[2], bs->cur[3],
426 bs->cur[4] * 256 + bs->cur[5]));
427 *((unsigned *) (base + f->offset)) =
428 bs->cur - bs->buf;
429 }
430 }
431 len = f->lb;
432 break;
433 case BYTE: /* Range == 256 */
434 BYTE_ALIGN(bs);
435 CHECK_BOUND(bs, 1);
436 len = (*bs->cur++) + f->lb;
437 break;
438 case SEMI:
439 BYTE_ALIGN(bs);
440 CHECK_BOUND(bs, 2);
441 len = get_len(bs) + f->lb;
442 break;
443 default: /* 2 <= Range <= 255 */
444 len = get_bits(bs, f->sz) + f->lb;
445 BYTE_ALIGN(bs);
446 break;
447 }
448
449 bs->cur += len;
450
451 PRINT("\n");
452
453 CHECK_BOUND(bs, 0);
454 return H323_ERROR_NONE;
455}
456
457/****************************************************************************/
458int decode_bmpstr(bitstr_t * bs, field_t * f, char *base, int level)
459{
460 unsigned len;
461
462 PRINT("%*.s%s\n", level * TAB_SIZE, " ", f->name);
463
464 switch (f->sz) {
465 case BYTE: /* Range == 256 */
466 BYTE_ALIGN(bs);
467 CHECK_BOUND(bs, 1);
468 len = (*bs->cur++) + f->lb;
469 break;
470 default: /* 2 <= Range <= 255 */
471 len = get_bits(bs, f->sz) + f->lb;
472 BYTE_ALIGN(bs);
473 break;
474 }
475
476 bs->cur += len << 1;
477
478 CHECK_BOUND(bs, 0);
479 return H323_ERROR_NONE;
480}
481
482/****************************************************************************/
483int decode_seq(bitstr_t * bs, field_t * f, char *base, int level)
484{
485 unsigned ext, bmp, i, opt, len = 0, bmp2, bmp2_len;
486 int err;
487 field_t *son;
488 unsigned char *beg = NULL;
489
490 PRINT("%*.s%s\n", level * TAB_SIZE, " ", f->name);
491
492 /* Decode? */
493 base = (base && (f->attr & DECODE)) ? base + f->offset : NULL;
494
495 /* Extensible? */
496 ext = (f->attr & EXT) ? get_bit(bs) : 0;
497
498 /* Get fields bitmap */
499 bmp = get_bitmap(bs, f->sz);
500 if (base)
501 *(unsigned *) base = bmp;
502
503 /* Decode the root components */
504 for (i = opt = 0, son = f->fields; i < f->lb; i++, son++) {
505 if (son->attr & STOP) {
506 PRINT("%*.s%s\n", (level + 1) * TAB_SIZE, " ",
507 son->name);
508 return H323_ERROR_STOP;
509 }
510
511 if (son->attr & OPT) { /* Optional component */
512 if (!((0x80000000U >> (opt++)) & bmp)) /* Not exist */
513 continue;
514 }
515
516 /* Decode */
517 if (son->attr & OPEN) { /* Open field */
518 CHECK_BOUND(bs, 2);
519 len = get_len(bs);
520 CHECK_BOUND(bs, len);
521 if (!base) {
522 PRINT("%*.s%s\n", (level + 1) * TAB_SIZE,
523 " ", son->name);
524 bs->cur += len;
525 continue;
526 }
527 beg = bs->cur;
528
529 /* Decode */
530 if ((err = (Decoders[son->type]) (bs, son, base,
531 level + 1)) >
532 H323_ERROR_STOP)
533 return err;
534
535 bs->cur = beg + len;
536 bs->bit = 0;
537 } else if ((err = (Decoders[son->type]) (bs, son, base,
538 level + 1)))
539 return err;
540 }
541
542 /* No extension? */
543 if (!ext)
544 return H323_ERROR_NONE;
545
546 /* Get the extension bitmap */
547 bmp2_len = get_bits(bs, 7) + 1;
548 CHECK_BOUND(bs, (bmp2_len + 7) >> 3);
549 bmp2 = get_bitmap(bs, bmp2_len);
550 bmp |= bmp2 >> f->sz;
551 if (base)
552 *(unsigned *) base = bmp;
553 BYTE_ALIGN(bs);
554
555 /* Decode the extension components */
556 for (opt = 0; opt < bmp2_len; opt++, i++, son++) {
557 if (son->attr & STOP) {
558 PRINT("%*.s%s\n", (level + 1) * TAB_SIZE, " ",
559 son->name);
560 return H323_ERROR_STOP;
561 }
562
563 if (!((0x80000000 >> opt) & bmp2)) /* Not present */
564 continue;
565
566 /* Check Range */
567 if (i >= f->ub) { /* Newer Version? */
568 CHECK_BOUND(bs, 2);
569 len = get_len(bs);
570 CHECK_BOUND(bs, len);
571 bs->cur += len;
572 continue;
573 }
574
575 CHECK_BOUND(bs, 2);
576 len = get_len(bs);
577 CHECK_BOUND(bs, len);
578 if (!base || !(son->attr & DECODE)) {
579 PRINT("%*.s%s\n", (level + 1) * TAB_SIZE, " ",
580 son->name);
581 bs->cur += len;
582 continue;
583 }
584 beg = bs->cur;
585
586 if ((err = (Decoders[son->type]) (bs, son, base,
587 level + 1)) >
588 H323_ERROR_STOP)
589 return err;
590
591 bs->cur = beg + len;
592 bs->bit = 0;
593 }
594 return H323_ERROR_NONE;
595}
596
597/****************************************************************************/
598int decode_seqof(bitstr_t * bs, field_t * f, char *base, int level)
599{
600 unsigned count, effective_count = 0, i, len = 0;
601 int err;
602 field_t *son;
603 unsigned char *beg = NULL;
604
605 PRINT("%*.s%s\n", level * TAB_SIZE, " ", f->name);
606
607 /* Decode? */
608 base = (base && (f->attr & DECODE)) ? base + f->offset : NULL;
609
610 /* Decode item count */
611 switch (f->sz) {
612 case BYTE:
613 BYTE_ALIGN(bs);
614 CHECK_BOUND(bs, 1);
615 count = *bs->cur++;
616 break;
617 case WORD:
618 BYTE_ALIGN(bs);
619 CHECK_BOUND(bs, 2);
620 count = *bs->cur++;
621 count <<= 8;
622 count = *bs->cur++;
623 break;
624 case SEMI:
625 BYTE_ALIGN(bs);
626 CHECK_BOUND(bs, 2);
627 count = get_len(bs);
628 break;
629 default:
630 count = get_bits(bs, f->sz);
631 break;
632 }
633 count += f->lb;
634
635 /* Write Count */
636 if (base) {
637 effective_count = count > f->ub ? f->ub : count;
638 *(unsigned *) base = effective_count;
639 base += sizeof(unsigned);
640 }
641
642 /* Decode nested field */
643 son = f->fields;
644 if (base)
645 base -= son->offset;
646 for (i = 0; i < count; i++) {
647 if (son->attr & OPEN) {
648 BYTE_ALIGN(bs);
649 len = get_len(bs);
650 CHECK_BOUND(bs, len);
651 if (!base || !(son->attr & DECODE)) {
652 PRINT("%*.s%s\n", (level + 1) * TAB_SIZE,
653 " ", son->name);
654 bs->cur += len;
655 continue;
656 }
657 beg = bs->cur;
658
659 if ((err = (Decoders[son->type]) (bs, son,
660 i <
661 effective_count ?
662 base : NULL,
663 level + 1)) >
664 H323_ERROR_STOP)
665 return err;
666
667 bs->cur = beg + len;
668 bs->bit = 0;
669 } else
670 if ((err = (Decoders[son->type]) (bs, son,
671 i < effective_count ?
672 base : NULL,
673 level + 1)))
674 return err;
675
676 if (base)
677 base += son->offset;
678 }
679
680 return H323_ERROR_NONE;
681}
682
683
684/****************************************************************************/
685int decode_choice(bitstr_t * bs, field_t * f, char *base, int level)
686{
687 unsigned type, ext, len = 0;
688 int err;
689 field_t *son;
690 unsigned char *beg = NULL;
691
692 PRINT("%*.s%s\n", level * TAB_SIZE, " ", f->name);
693
694 /* Decode? */
695 base = (base && (f->attr & DECODE)) ? base + f->offset : NULL;
696
697 /* Decode the choice index number */
698 if ((f->attr & EXT) && get_bit(bs)) {
699 ext = 1;
700 type = get_bits(bs, 7) + f->lb;
701 } else {
702 ext = 0;
703 type = get_bits(bs, f->sz);
704 }
705
706 /* Check Range */
707 if (type >= f->ub) { /* Newer version? */
708 BYTE_ALIGN(bs);
709 len = get_len(bs);
710 CHECK_BOUND(bs, len);
711 bs->cur += len;
712 return H323_ERROR_NONE;
713 }
714
715 /* Write Type */
716 if (base)
717 *(unsigned *) base = type;
718
719 /* Transfer to son level */
720 son = &f->fields[type];
721 if (son->attr & STOP) {
722 PRINT("%*.s%s\n", (level + 1) * TAB_SIZE, " ", son->name);
723 return H323_ERROR_STOP;
724 }
725
726 if (ext || (son->attr & OPEN)) {
727 BYTE_ALIGN(bs);
728 len = get_len(bs);
729 CHECK_BOUND(bs, len);
730 if (!base || !(son->attr & DECODE)) {
731 PRINT("%*.s%s\n", (level + 1) * TAB_SIZE, " ",
732 son->name);
733 bs->cur += len;
734 return H323_ERROR_NONE;
735 }
736 beg = bs->cur;
737
738 if ((err = (Decoders[son->type]) (bs, son, base, level + 1)) >
739 H323_ERROR_STOP)
740 return err;
741
742 bs->cur = beg + len;
743 bs->bit = 0;
744 } else if ((err = (Decoders[son->type]) (bs, son, base, level + 1)))
745 return err;
746
747 return H323_ERROR_NONE;
748}
749
750/****************************************************************************/
751int DecodeRasMessage(unsigned char *buf, size_t sz, RasMessage * ras)
752{
753 static field_t ras_message = {
754 FNAME("RasMessage") CHOICE, 5, 24, 32, DECODE | EXT,
755 0, _RasMessage
756 };
757 bitstr_t bs;
758
759 bs.buf = bs.beg = bs.cur = buf;
760 bs.end = buf + sz;
761 bs.bit = 0;
762
763 return decode_choice(&bs, &ras_message, (char *) ras, 0);
764}
765
766/****************************************************************************/
767static int DecodeH323_UserInformation(unsigned char *buf, unsigned char *beg,
768 size_t sz, H323_UserInformation * uuie)
769{
770 static field_t h323_userinformation = {
771 FNAME("H323-UserInformation") SEQ, 1, 2, 2, DECODE | EXT,
772 0, _H323_UserInformation
773 };
774 bitstr_t bs;
775
776 bs.buf = buf;
777 bs.beg = bs.cur = beg;
778 bs.end = beg + sz;
779 bs.bit = 0;
780
781 return decode_seq(&bs, &h323_userinformation, (char *) uuie, 0);
782}
783
784/****************************************************************************/
785int DecodeMultimediaSystemControlMessage(unsigned char *buf, size_t sz,
786 MultimediaSystemControlMessage *
787 mscm)
788{
789 static field_t multimediasystemcontrolmessage = {
790 FNAME("MultimediaSystemControlMessage") CHOICE, 2, 4, 4,
791 DECODE | EXT, 0, _MultimediaSystemControlMessage
792 };
793 bitstr_t bs;
794
795 bs.buf = bs.beg = bs.cur = buf;
796 bs.end = buf + sz;
797 bs.bit = 0;
798
799 return decode_choice(&bs, &multimediasystemcontrolmessage,
800 (char *) mscm, 0);
801}
802
803/****************************************************************************/
804int DecodeQ931(unsigned char *buf, size_t sz, Q931 * q931)
805{
806 unsigned char *p = buf;
807 int len;
808
809 if (!p || sz < 1)
810 return H323_ERROR_BOUND;
811
812 /* Protocol Discriminator */
813 if (*p != 0x08) {
814 PRINT("Unknown Protocol Discriminator\n");
815 return H323_ERROR_RANGE;
816 }
817 p++;
818 sz--;
819
820 /* CallReferenceValue */
821 if (sz < 1)
822 return H323_ERROR_BOUND;
823 len = *p++;
824 sz--;
825 if (sz < len)
826 return H323_ERROR_BOUND;
827 p += len;
828 sz -= len;
829
830 /* Message Type */
831 if (sz < 1)
832 return H323_ERROR_BOUND;
833 q931->MessageType = *p++;
834 PRINT("MessageType = %02X\n", q931->MessageType);
835 if (*p & 0x80) {
836 p++;
837 sz--;
838 }
839
840 /* Decode Information Elements */
841 while (sz > 0) {
842 if (*p == 0x7e) { /* UserUserIE */
843 if (sz < 3)
844 break;
845 p++;
846 len = *p++ << 8;
847 len |= *p++;
848 sz -= 3;
849 if (sz < len)
850 break;
851 p++;
852 len--;
853 return DecodeH323_UserInformation(buf, p, len,
854 &q931->UUIE);
855 }
856 p++;
857 sz--;
858 if (sz < 1)
859 break;
860 len = *p++;
861 if (sz < len)
862 break;
863 p += len;
864 sz -= len;
865 }
866
867 PRINT("Q.931 UUIE not found\n");
868
869 return H323_ERROR_BOUND;
870}
diff --git a/net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.h b/net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.h
new file mode 100644
index 000000000000..0bd828081c0c
--- /dev/null
+++ b/net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.h
@@ -0,0 +1,98 @@
1/****************************************************************************
2 * ip_conntrack_helper_h323_asn1.h - BER and PER decoding library for H.323
3 * conntrack/NAT module.
4 *
5 * Copyright (c) 2006 by Jing Min Zhao <zhaojingmin@hotmail.com>
6 *
7 * This source code is licensed under General Public License version 2.
8 *
9 *
10 * This library is based on H.225 version 4, H.235 version 2 and H.245
11 * version 7. It is extremely optimized to decode only the absolutely
12 * necessary objects in a signal for Linux kernel NAT module use, so don't
13 * expect it to be a full ASN.1 library.
14 *
15 * Features:
16 *
17 * 1. Small. The total size of code plus data is less than 20 KB (IA32).
18 * 2. Fast. Decoding Netmeeting's Setup signal 1 million times on a PIII 866
19 * takes only 3.9 seconds.
20 * 3. No memory allocation. It uses a static object. No need to initialize or
21 * cleanup.
22 * 4. Thread safe.
23 * 5. Support embedded architectures that has no misaligned memory access
24 * support.
25 *
26 * Limitations:
27 *
28 * 1. At most 30 faststart entries. Actually this is limited by ethernet's MTU.
29 * If a Setup signal contains more than 30 faststart, the packet size will
30 * very likely exceed the MTU size, then the TPKT will be fragmented. I
31 * don't know how to handle this in a Netfilter module. Anybody can help?
32 * Although I think 30 is enough for most of the cases.
33 * 2. IPv4 addresses only.
34 *
35 ****************************************************************************/
36
37#ifndef _IP_CONNTRACK_HELPER_H323_ASN1_H_
38#define _IP_CONNTRACK_HELPER_H323_ASN1_H_
39
40/*****************************************************************************
41 * H.323 Types
42 ****************************************************************************/
43#include "ip_conntrack_helper_h323_types.h"
44
45typedef struct {
46 enum {
47 Q931_NationalEscape = 0x00,
48 Q931_Alerting = 0x01,
49 Q931_CallProceeding = 0x02,
50 Q931_Connect = 0x07,
51 Q931_ConnectAck = 0x0F,
52 Q931_Progress = 0x03,
53 Q931_Setup = 0x05,
54 Q931_SetupAck = 0x0D,
55 Q931_Resume = 0x26,
56 Q931_ResumeAck = 0x2E,
57 Q931_ResumeReject = 0x22,
58 Q931_Suspend = 0x25,
59 Q931_SuspendAck = 0x2D,
60 Q931_SuspendReject = 0x21,
61 Q931_UserInformation = 0x20,
62 Q931_Disconnect = 0x45,
63 Q931_Release = 0x4D,
64 Q931_ReleaseComplete = 0x5A,
65 Q931_Restart = 0x46,
66 Q931_RestartAck = 0x4E,
67 Q931_Segment = 0x60,
68 Q931_CongestionCtrl = 0x79,
69 Q931_Information = 0x7B,
70 Q931_Notify = 0x6E,
71 Q931_Status = 0x7D,
72 Q931_StatusEnquiry = 0x75,
73 Q931_Facility = 0x62
74 } MessageType;
75 H323_UserInformation UUIE;
76} Q931;
77
78/*****************************************************************************
79 * Decode Functions Return Codes
80 ****************************************************************************/
81
82#define H323_ERROR_NONE 0 /* Decoded successfully */
83#define H323_ERROR_STOP 1 /* Decoding stopped, not really an error */
84#define H323_ERROR_BOUND -1
85#define H323_ERROR_RANGE -2
86
87
88/*****************************************************************************
89 * Decode Functions
90 ****************************************************************************/
91
92int DecodeRasMessage(unsigned char *buf, size_t sz, RasMessage * ras);
93int DecodeQ931(unsigned char *buf, size_t sz, Q931 * q931);
94int DecodeMultimediaSystemControlMessage(unsigned char *buf, size_t sz,
95 MultimediaSystemControlMessage *
96 mscm);
97
98#endif
diff --git a/net/ipv4/netfilter/ip_conntrack_helper_h323_types.c b/net/ipv4/netfilter/ip_conntrack_helper_h323_types.c
new file mode 100644
index 000000000000..022c47b9f6c9
--- /dev/null
+++ b/net/ipv4/netfilter/ip_conntrack_helper_h323_types.c
@@ -0,0 +1,1926 @@
1/* Generated by Jing Min Zhao's ASN.1 parser, Mar 15 2006
2 *
3 * Copyright (c) 2006 Jing Min Zhao <zhaojingmin@users.sourceforge.net>
4 *
5 * This source code is licensed under General Public License version 2.
6 */
7
8static field_t _TransportAddress_ipAddress[] = { /* SEQUENCE */
9 {FNAME("ip") OCTSTR, FIXD, 4, 0, DECODE,
10 offsetof(TransportAddress_ipAddress, ip), NULL},
11 {FNAME("port") INT, WORD, 0, 0, SKIP, 0, NULL},
12};
13
14static field_t _TransportAddress_ipSourceRoute_route[] = { /* SEQUENCE OF */
15 {FNAME("item") OCTSTR, FIXD, 4, 0, SKIP, 0, NULL},
16};
17
18static field_t _TransportAddress_ipSourceRoute_routing[] = { /* CHOICE */
19 {FNAME("strict") NUL, FIXD, 0, 0, SKIP, 0, NULL},
20 {FNAME("loose") NUL, FIXD, 0, 0, SKIP, 0, NULL},
21};
22
23static field_t _TransportAddress_ipSourceRoute[] = { /* SEQUENCE */
24 {FNAME("ip") OCTSTR, FIXD, 4, 0, SKIP, 0, NULL},
25 {FNAME("port") INT, WORD, 0, 0, SKIP, 0, NULL},
26 {FNAME("route") SEQOF, SEMI, 0, 0, SKIP, 0,
27 _TransportAddress_ipSourceRoute_route},
28 {FNAME("routing") CHOICE, 1, 2, 2, SKIP | EXT, 0,
29 _TransportAddress_ipSourceRoute_routing},
30};
31
32static field_t _TransportAddress_ipxAddress[] = { /* SEQUENCE */
33 {FNAME("node") OCTSTR, FIXD, 6, 0, SKIP, 0, NULL},
34 {FNAME("netnum") OCTSTR, FIXD, 4, 0, SKIP, 0, NULL},
35 {FNAME("port") OCTSTR, FIXD, 2, 0, SKIP, 0, NULL},
36};
37
38static field_t _TransportAddress_ip6Address[] = { /* SEQUENCE */
39 {FNAME("ip") OCTSTR, FIXD, 16, 0, SKIP, 0, NULL},
40 {FNAME("port") INT, WORD, 0, 0, SKIP, 0, NULL},
41};
42
43static field_t _H221NonStandard[] = { /* SEQUENCE */
44 {FNAME("t35CountryCode") INT, BYTE, 0, 0, SKIP, 0, NULL},
45 {FNAME("t35Extension") INT, BYTE, 0, 0, SKIP, 0, NULL},
46 {FNAME("manufacturerCode") INT, WORD, 0, 0, SKIP, 0, NULL},
47};
48
49static field_t _NonStandardIdentifier[] = { /* CHOICE */
50 {FNAME("object") OID, BYTE, 0, 0, SKIP, 0, NULL},
51 {FNAME("h221NonStandard") SEQ, 0, 3, 3, SKIP | EXT, 0,
52 _H221NonStandard},
53};
54
55static field_t _NonStandardParameter[] = { /* SEQUENCE */
56 {FNAME("nonStandardIdentifier") CHOICE, 1, 2, 2, SKIP | EXT, 0,
57 _NonStandardIdentifier},
58 {FNAME("data") OCTSTR, SEMI, 0, 0, SKIP, 0, NULL},
59};
60
61static field_t _TransportAddress[] = { /* CHOICE */
62 {FNAME("ipAddress") SEQ, 0, 2, 2, DECODE,
63 offsetof(TransportAddress, ipAddress), _TransportAddress_ipAddress},
64 {FNAME("ipSourceRoute") SEQ, 0, 4, 4, SKIP | EXT, 0,
65 _TransportAddress_ipSourceRoute},
66 {FNAME("ipxAddress") SEQ, 0, 3, 3, SKIP, 0,
67 _TransportAddress_ipxAddress},
68 {FNAME("ip6Address") SEQ, 0, 2, 2, SKIP | EXT, 0,
69 _TransportAddress_ip6Address},
70 {FNAME("netBios") OCTSTR, FIXD, 16, 0, SKIP, 0, NULL},
71 {FNAME("nsap") OCTSTR, 5, 1, 0, SKIP, 0, NULL},
72 {FNAME("nonStandardAddress") SEQ, 0, 2, 2, SKIP, 0,
73 _NonStandardParameter},
74};
75
76static field_t _AliasAddress[] = { /* CHOICE */
77 {FNAME("dialedDigits") NUMDGT, 7, 1, 0, SKIP, 0, NULL},
78 {FNAME("h323-ID") BMPSTR, BYTE, 1, 0, SKIP, 0, NULL},
79 {FNAME("url-ID") IA5STR, WORD, 1, 0, SKIP, 0, NULL},
80 {FNAME("transportID") CHOICE, 3, 7, 7, SKIP | EXT, 0, NULL},
81 {FNAME("email-ID") IA5STR, WORD, 1, 0, SKIP, 0, NULL},
82 {FNAME("partyNumber") CHOICE, 3, 5, 5, SKIP | EXT, 0, NULL},
83 {FNAME("mobileUIM") CHOICE, 1, 2, 2, SKIP | EXT, 0, NULL},
84};
85
86static field_t _Setup_UUIE_sourceAddress[] = { /* SEQUENCE OF */
87 {FNAME("item") CHOICE, 1, 2, 7, SKIP | EXT, 0, _AliasAddress},
88};
89
90static field_t _VendorIdentifier[] = { /* SEQUENCE */
91 {FNAME("vendor") SEQ, 0, 3, 3, SKIP | EXT, 0, _H221NonStandard},
92 {FNAME("productId") OCTSTR, BYTE, 1, 0, SKIP | OPT, 0, NULL},
93 {FNAME("versionId") OCTSTR, BYTE, 1, 0, SKIP | OPT, 0, NULL},
94};
95
96static field_t _GatekeeperInfo[] = { /* SEQUENCE */
97 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
98 _NonStandardParameter},
99};
100
101static field_t _H310Caps[] = { /* SEQUENCE */
102 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
103 _NonStandardParameter},
104 {FNAME("dataRatesSupported") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
105 {FNAME("supportedPrefixes") SEQOF, SEMI, 0, 0, SKIP, 0, NULL},
106};
107
108static field_t _H320Caps[] = { /* SEQUENCE */
109 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
110 _NonStandardParameter},
111 {FNAME("dataRatesSupported") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
112 {FNAME("supportedPrefixes") SEQOF, SEMI, 0, 0, SKIP, 0, NULL},
113};
114
115static field_t _H321Caps[] = { /* SEQUENCE */
116 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
117 _NonStandardParameter},
118 {FNAME("dataRatesSupported") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
119 {FNAME("supportedPrefixes") SEQOF, SEMI, 0, 0, SKIP, 0, NULL},
120};
121
122static field_t _H322Caps[] = { /* SEQUENCE */
123 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
124 _NonStandardParameter},
125 {FNAME("dataRatesSupported") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
126 {FNAME("supportedPrefixes") SEQOF, SEMI, 0, 0, SKIP, 0, NULL},
127};
128
129static field_t _H323Caps[] = { /* SEQUENCE */
130 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
131 _NonStandardParameter},
132 {FNAME("dataRatesSupported") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
133 {FNAME("supportedPrefixes") SEQOF, SEMI, 0, 0, SKIP, 0, NULL},
134};
135
136static field_t _H324Caps[] = { /* SEQUENCE */
137 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
138 _NonStandardParameter},
139 {FNAME("dataRatesSupported") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
140 {FNAME("supportedPrefixes") SEQOF, SEMI, 0, 0, SKIP, 0, NULL},
141};
142
143static field_t _VoiceCaps[] = { /* SEQUENCE */
144 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
145 _NonStandardParameter},
146 {FNAME("dataRatesSupported") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
147 {FNAME("supportedPrefixes") SEQOF, SEMI, 0, 0, SKIP, 0, NULL},
148};
149
150static field_t _T120OnlyCaps[] = { /* SEQUENCE */
151 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
152 _NonStandardParameter},
153 {FNAME("dataRatesSupported") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
154 {FNAME("supportedPrefixes") SEQOF, SEMI, 0, 0, SKIP, 0, NULL},
155};
156
157static field_t _SupportedProtocols[] = { /* CHOICE */
158 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP, 0,
159 _NonStandardParameter},
160 {FNAME("h310") SEQ, 1, 1, 3, SKIP | EXT, 0, _H310Caps},
161 {FNAME("h320") SEQ, 1, 1, 3, SKIP | EXT, 0, _H320Caps},
162 {FNAME("h321") SEQ, 1, 1, 3, SKIP | EXT, 0, _H321Caps},
163 {FNAME("h322") SEQ, 1, 1, 3, SKIP | EXT, 0, _H322Caps},
164 {FNAME("h323") SEQ, 1, 1, 3, SKIP | EXT, 0, _H323Caps},
165 {FNAME("h324") SEQ, 1, 1, 3, SKIP | EXT, 0, _H324Caps},
166 {FNAME("voice") SEQ, 1, 1, 3, SKIP | EXT, 0, _VoiceCaps},
167 {FNAME("t120-only") SEQ, 1, 1, 3, SKIP | EXT, 0, _T120OnlyCaps},
168 {FNAME("nonStandardProtocol") SEQ, 2, 3, 3, SKIP | EXT, 0, NULL},
169 {FNAME("t38FaxAnnexbOnly") SEQ, 2, 5, 5, SKIP | EXT, 0, NULL},
170};
171
172static field_t _GatewayInfo_protocol[] = { /* SEQUENCE OF */
173 {FNAME("item") CHOICE, 4, 9, 11, SKIP | EXT, 0, _SupportedProtocols},
174};
175
176static field_t _GatewayInfo[] = { /* SEQUENCE */
177 {FNAME("protocol") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
178 _GatewayInfo_protocol},
179 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
180 _NonStandardParameter},
181};
182
183static field_t _McuInfo[] = { /* SEQUENCE */
184 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
185 _NonStandardParameter},
186 {FNAME("protocol") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
187};
188
189static field_t _TerminalInfo[] = { /* SEQUENCE */
190 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
191 _NonStandardParameter},
192};
193
194static field_t _EndpointType[] = { /* SEQUENCE */
195 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
196 _NonStandardParameter},
197 {FNAME("vendor") SEQ, 2, 3, 3, SKIP | EXT | OPT, 0,
198 _VendorIdentifier},
199 {FNAME("gatekeeper") SEQ, 1, 1, 1, SKIP | EXT | OPT, 0,
200 _GatekeeperInfo},
201 {FNAME("gateway") SEQ, 2, 2, 2, SKIP | EXT | OPT, 0, _GatewayInfo},
202 {FNAME("mcu") SEQ, 1, 1, 2, SKIP | EXT | OPT, 0, _McuInfo},
203 {FNAME("terminal") SEQ, 1, 1, 1, SKIP | EXT | OPT, 0, _TerminalInfo},
204 {FNAME("mc") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
205 {FNAME("undefinedNode") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
206 {FNAME("set") BITSTR, FIXD, 32, 0, SKIP | OPT, 0, NULL},
207 {FNAME("supportedTunnelledProtocols") SEQOF, SEMI, 0, 0, SKIP | OPT,
208 0, NULL},
209};
210
211static field_t _Setup_UUIE_destinationAddress[] = { /* SEQUENCE OF */
212 {FNAME("item") CHOICE, 1, 2, 7, SKIP | EXT, 0, _AliasAddress},
213};
214
215static field_t _Setup_UUIE_destExtraCallInfo[] = { /* SEQUENCE OF */
216 {FNAME("item") CHOICE, 1, 2, 7, SKIP | EXT, 0, _AliasAddress},
217};
218
219static field_t _Setup_UUIE_destExtraCRV[] = { /* SEQUENCE OF */
220 {FNAME("item") INT, WORD, 0, 0, SKIP, 0, NULL},
221};
222
223static field_t _Setup_UUIE_conferenceGoal[] = { /* CHOICE */
224 {FNAME("create") NUL, FIXD, 0, 0, SKIP, 0, NULL},
225 {FNAME("join") NUL, FIXD, 0, 0, SKIP, 0, NULL},
226 {FNAME("invite") NUL, FIXD, 0, 0, SKIP, 0, NULL},
227 {FNAME("capability-negotiation") NUL, FIXD, 0, 0, SKIP, 0, NULL},
228 {FNAME("callIndependentSupplementaryService") NUL, FIXD, 0, 0, SKIP,
229 0, NULL},
230};
231
232static field_t _Q954Details[] = { /* SEQUENCE */
233 {FNAME("conferenceCalling") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
234 {FNAME("threePartyService") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
235};
236
237static field_t _QseriesOptions[] = { /* SEQUENCE */
238 {FNAME("q932Full") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
239 {FNAME("q951Full") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
240 {FNAME("q952Full") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
241 {FNAME("q953Full") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
242 {FNAME("q955Full") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
243 {FNAME("q956Full") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
244 {FNAME("q957Full") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
245 {FNAME("q954Info") SEQ, 0, 2, 2, SKIP | EXT, 0, _Q954Details},
246};
247
248static field_t _CallType[] = { /* CHOICE */
249 {FNAME("pointToPoint") NUL, FIXD, 0, 0, SKIP, 0, NULL},
250 {FNAME("oneToN") NUL, FIXD, 0, 0, SKIP, 0, NULL},
251 {FNAME("nToOne") NUL, FIXD, 0, 0, SKIP, 0, NULL},
252 {FNAME("nToN") NUL, FIXD, 0, 0, SKIP, 0, NULL},
253};
254
255static field_t _H245_NonStandardIdentifier_h221NonStandard[] = { /* SEQUENCE */
256 {FNAME("t35CountryCode") INT, BYTE, 0, 0, SKIP, 0, NULL},
257 {FNAME("t35Extension") INT, BYTE, 0, 0, SKIP, 0, NULL},
258 {FNAME("manufacturerCode") INT, WORD, 0, 0, SKIP, 0, NULL},
259};
260
261static field_t _H245_NonStandardIdentifier[] = { /* CHOICE */
262 {FNAME("object") OID, BYTE, 0, 0, SKIP, 0, NULL},
263 {FNAME("h221NonStandard") SEQ, 0, 3, 3, SKIP, 0,
264 _H245_NonStandardIdentifier_h221NonStandard},
265};
266
267static field_t _H245_NonStandardParameter[] = { /* SEQUENCE */
268 {FNAME("nonStandardIdentifier") CHOICE, 1, 2, 2, SKIP, 0,
269 _H245_NonStandardIdentifier},
270 {FNAME("data") OCTSTR, SEMI, 0, 0, SKIP, 0, NULL},
271};
272
273static field_t _H261VideoCapability[] = { /* SEQUENCE */
274 {FNAME("qcifMPI") INT, 2, 1, 0, SKIP | OPT, 0, NULL},
275 {FNAME("cifMPI") INT, 2, 1, 0, SKIP | OPT, 0, NULL},
276 {FNAME("temporalSpatialTradeOffCapability") BOOL, FIXD, 0, 0, SKIP, 0,
277 NULL},
278 {FNAME("maxBitRate") INT, WORD, 1, 0, SKIP, 0, NULL},
279 {FNAME("stillImageTransmission") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
280 {FNAME("videoBadMBsCap") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
281};
282
283static field_t _H262VideoCapability[] = { /* SEQUENCE */
284 {FNAME("profileAndLevel-SPatML") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
285 {FNAME("profileAndLevel-MPatLL") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
286 {FNAME("profileAndLevel-MPatML") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
287 {FNAME("profileAndLevel-MPatH-14") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
288 {FNAME("profileAndLevel-MPatHL") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
289 {FNAME("profileAndLevel-SNRatLL") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
290 {FNAME("profileAndLevel-SNRatML") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
291 {FNAME("profileAndLevel-SpatialatH-14") BOOL, FIXD, 0, 0, SKIP, 0,
292 NULL},
293 {FNAME("profileAndLevel-HPatML") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
294 {FNAME("profileAndLevel-HPatH-14") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
295 {FNAME("profileAndLevel-HPatHL") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
296 {FNAME("videoBitRate") INT, CONS, 0, 0, SKIP | OPT, 0, NULL},
297 {FNAME("vbvBufferSize") INT, CONS, 0, 0, SKIP | OPT, 0, NULL},
298 {FNAME("samplesPerLine") INT, WORD, 0, 0, SKIP | OPT, 0, NULL},
299 {FNAME("linesPerFrame") INT, WORD, 0, 0, SKIP | OPT, 0, NULL},
300 {FNAME("framesPerSecond") INT, 4, 0, 0, SKIP | OPT, 0, NULL},
301 {FNAME("luminanceSampleRate") INT, CONS, 0, 0, SKIP | OPT, 0, NULL},
302 {FNAME("videoBadMBsCap") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
303};
304
305static field_t _H263VideoCapability[] = { /* SEQUENCE */
306 {FNAME("sqcifMPI") INT, 5, 1, 0, SKIP | OPT, 0, NULL},
307 {FNAME("qcifMPI") INT, 5, 1, 0, SKIP | OPT, 0, NULL},
308 {FNAME("cifMPI") INT, 5, 1, 0, SKIP | OPT, 0, NULL},
309 {FNAME("cif4MPI") INT, 5, 1, 0, SKIP | OPT, 0, NULL},
310 {FNAME("cif16MPI") INT, 5, 1, 0, SKIP | OPT, 0, NULL},
311 {FNAME("maxBitRate") INT, CONS, 1, 0, SKIP, 0, NULL},
312 {FNAME("unrestrictedVector") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
313 {FNAME("arithmeticCoding") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
314 {FNAME("advancedPrediction") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
315 {FNAME("pbFrames") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
316 {FNAME("temporalSpatialTradeOffCapability") BOOL, FIXD, 0, 0, SKIP, 0,
317 NULL},
318 {FNAME("hrd-B") INT, CONS, 0, 0, SKIP | OPT, 0, NULL},
319 {FNAME("bppMaxKb") INT, WORD, 0, 0, SKIP | OPT, 0, NULL},
320 {FNAME("slowSqcifMPI") INT, WORD, 1, 0, SKIP | OPT, 0, NULL},
321 {FNAME("slowQcifMPI") INT, WORD, 1, 0, SKIP | OPT, 0, NULL},
322 {FNAME("slowCifMPI") INT, WORD, 1, 0, SKIP | OPT, 0, NULL},
323 {FNAME("slowCif4MPI") INT, WORD, 1, 0, SKIP | OPT, 0, NULL},
324 {FNAME("slowCif16MPI") INT, WORD, 1, 0, SKIP | OPT, 0, NULL},
325 {FNAME("errorCompensation") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
326 {FNAME("enhancementLayerInfo") SEQ, 3, 4, 4, SKIP | EXT | OPT, 0,
327 NULL},
328 {FNAME("h263Options") SEQ, 5, 29, 31, SKIP | EXT | OPT, 0, NULL},
329};
330
331static field_t _IS11172VideoCapability[] = { /* SEQUENCE */
332 {FNAME("constrainedBitstream") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
333 {FNAME("videoBitRate") INT, CONS, 0, 0, SKIP | OPT, 0, NULL},
334 {FNAME("vbvBufferSize") INT, CONS, 0, 0, SKIP | OPT, 0, NULL},
335 {FNAME("samplesPerLine") INT, WORD, 0, 0, SKIP | OPT, 0, NULL},
336 {FNAME("linesPerFrame") INT, WORD, 0, 0, SKIP | OPT, 0, NULL},
337 {FNAME("pictureRate") INT, 4, 0, 0, SKIP | OPT, 0, NULL},
338 {FNAME("luminanceSampleRate") INT, CONS, 0, 0, SKIP | OPT, 0, NULL},
339 {FNAME("videoBadMBsCap") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
340};
341
342static field_t _VideoCapability[] = { /* CHOICE */
343 {FNAME("nonStandard") SEQ, 0, 2, 2, SKIP, 0,
344 _H245_NonStandardParameter},
345 {FNAME("h261VideoCapability") SEQ, 2, 5, 6, SKIP | EXT, 0,
346 _H261VideoCapability},
347 {FNAME("h262VideoCapability") SEQ, 6, 17, 18, SKIP | EXT, 0,
348 _H262VideoCapability},
349 {FNAME("h263VideoCapability") SEQ, 7, 13, 21, SKIP | EXT, 0,
350 _H263VideoCapability},
351 {FNAME("is11172VideoCapability") SEQ, 6, 7, 8, SKIP | EXT, 0,
352 _IS11172VideoCapability},
353 {FNAME("genericVideoCapability") SEQ, 5, 6, 6, SKIP | EXT, 0, NULL},
354};
355
356static field_t _AudioCapability_g7231[] = { /* SEQUENCE */
357 {FNAME("maxAl-sduAudioFrames") INT, BYTE, 1, 0, SKIP, 0, NULL},
358 {FNAME("silenceSuppression") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
359};
360
361static field_t _IS11172AudioCapability[] = { /* SEQUENCE */
362 {FNAME("audioLayer1") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
363 {FNAME("audioLayer2") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
364 {FNAME("audioLayer3") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
365 {FNAME("audioSampling32k") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
366 {FNAME("audioSampling44k1") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
367 {FNAME("audioSampling48k") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
368 {FNAME("singleChannel") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
369 {FNAME("twoChannels") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
370 {FNAME("bitRate") INT, WORD, 1, 0, SKIP, 0, NULL},
371};
372
373static field_t _IS13818AudioCapability[] = { /* SEQUENCE */
374 {FNAME("audioLayer1") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
375 {FNAME("audioLayer2") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
376 {FNAME("audioLayer3") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
377 {FNAME("audioSampling16k") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
378 {FNAME("audioSampling22k05") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
379 {FNAME("audioSampling24k") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
380 {FNAME("audioSampling32k") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
381 {FNAME("audioSampling44k1") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
382 {FNAME("audioSampling48k") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
383 {FNAME("singleChannel") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
384 {FNAME("twoChannels") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
385 {FNAME("threeChannels2-1") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
386 {FNAME("threeChannels3-0") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
387 {FNAME("fourChannels2-0-2-0") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
388 {FNAME("fourChannels2-2") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
389 {FNAME("fourChannels3-1") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
390 {FNAME("fiveChannels3-0-2-0") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
391 {FNAME("fiveChannels3-2") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
392 {FNAME("lowFrequencyEnhancement") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
393 {FNAME("multilingual") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
394 {FNAME("bitRate") INT, WORD, 1, 0, SKIP, 0, NULL},
395};
396
397static field_t _AudioCapability[] = { /* CHOICE */
398 {FNAME("nonStandard") SEQ, 0, 2, 2, SKIP, 0,
399 _H245_NonStandardParameter},
400 {FNAME("g711Alaw64k") INT, BYTE, 1, 0, SKIP, 0, NULL},
401 {FNAME("g711Alaw56k") INT, BYTE, 1, 0, SKIP, 0, NULL},
402 {FNAME("g711Ulaw64k") INT, BYTE, 1, 0, SKIP, 0, NULL},
403 {FNAME("g711Ulaw56k") INT, BYTE, 1, 0, SKIP, 0, NULL},
404 {FNAME("g722-64k") INT, BYTE, 1, 0, SKIP, 0, NULL},
405 {FNAME("g722-56k") INT, BYTE, 1, 0, SKIP, 0, NULL},
406 {FNAME("g722-48k") INT, BYTE, 1, 0, SKIP, 0, NULL},
407 {FNAME("g7231") SEQ, 0, 2, 2, SKIP, 0, _AudioCapability_g7231},
408 {FNAME("g728") INT, BYTE, 1, 0, SKIP, 0, NULL},
409 {FNAME("g729") INT, BYTE, 1, 0, SKIP, 0, NULL},
410 {FNAME("g729AnnexA") INT, BYTE, 1, 0, SKIP, 0, NULL},
411 {FNAME("is11172AudioCapability") SEQ, 0, 9, 9, SKIP | EXT, 0,
412 _IS11172AudioCapability},
413 {FNAME("is13818AudioCapability") SEQ, 0, 21, 21, SKIP | EXT, 0,
414 _IS13818AudioCapability},
415 {FNAME("g729wAnnexB") INT, BYTE, 1, 0, SKIP, 0, NULL},
416 {FNAME("g729AnnexAwAnnexB") INT, BYTE, 1, 0, SKIP, 0, NULL},
417 {FNAME("g7231AnnexCCapability") SEQ, 1, 3, 3, SKIP | EXT, 0, NULL},
418 {FNAME("gsmFullRate") SEQ, 0, 3, 3, SKIP | EXT, 0, NULL},
419 {FNAME("gsmHalfRate") SEQ, 0, 3, 3, SKIP | EXT, 0, NULL},
420 {FNAME("gsmEnhancedFullRate") SEQ, 0, 3, 3, SKIP | EXT, 0, NULL},
421 {FNAME("genericAudioCapability") SEQ, 5, 6, 6, SKIP | EXT, 0, NULL},
422 {FNAME("g729Extensions") SEQ, 1, 8, 8, SKIP | EXT, 0, NULL},
423};
424
425static field_t _DataProtocolCapability[] = { /* CHOICE */
426 {FNAME("nonStandard") SEQ, 0, 2, 2, SKIP, 0,
427 _H245_NonStandardParameter},
428 {FNAME("v14buffered") NUL, FIXD, 0, 0, SKIP, 0, NULL},
429 {FNAME("v42lapm") NUL, FIXD, 0, 0, SKIP, 0, NULL},
430 {FNAME("hdlcFrameTunnelling") NUL, FIXD, 0, 0, SKIP, 0, NULL},
431 {FNAME("h310SeparateVCStack") NUL, FIXD, 0, 0, SKIP, 0, NULL},
432 {FNAME("h310SingleVCStack") NUL, FIXD, 0, 0, SKIP, 0, NULL},
433 {FNAME("transparent") NUL, FIXD, 0, 0, SKIP, 0, NULL},
434 {FNAME("segmentationAndReassembly") NUL, FIXD, 0, 0, SKIP, 0, NULL},
435 {FNAME("hdlcFrameTunnelingwSAR") NUL, FIXD, 0, 0, SKIP, 0, NULL},
436 {FNAME("v120") NUL, FIXD, 0, 0, SKIP, 0, NULL},
437 {FNAME("separateLANStack") NUL, FIXD, 0, 0, SKIP, 0, NULL},
438 {FNAME("v76wCompression") CHOICE, 2, 3, 3, SKIP | EXT, 0, NULL},
439 {FNAME("tcp") NUL, FIXD, 0, 0, SKIP, 0, NULL},
440 {FNAME("udp") NUL, FIXD, 0, 0, SKIP, 0, NULL},
441};
442
443static field_t _T84Profile_t84Restricted[] = { /* SEQUENCE */
444 {FNAME("qcif") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
445 {FNAME("cif") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
446 {FNAME("ccir601Seq") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
447 {FNAME("ccir601Prog") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
448 {FNAME("hdtvSeq") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
449 {FNAME("hdtvProg") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
450 {FNAME("g3FacsMH200x100") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
451 {FNAME("g3FacsMH200x200") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
452 {FNAME("g4FacsMMR200x100") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
453 {FNAME("g4FacsMMR200x200") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
454 {FNAME("jbig200x200Seq") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
455 {FNAME("jbig200x200Prog") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
456 {FNAME("jbig300x300Seq") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
457 {FNAME("jbig300x300Prog") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
458 {FNAME("digPhotoLow") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
459 {FNAME("digPhotoMedSeq") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
460 {FNAME("digPhotoMedProg") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
461 {FNAME("digPhotoHighSeq") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
462 {FNAME("digPhotoHighProg") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
463};
464
465static field_t _T84Profile[] = { /* CHOICE */
466 {FNAME("t84Unrestricted") NUL, FIXD, 0, 0, SKIP, 0, NULL},
467 {FNAME("t84Restricted") SEQ, 0, 19, 19, SKIP | EXT, 0,
468 _T84Profile_t84Restricted},
469};
470
471static field_t _DataApplicationCapability_application_t84[] = { /* SEQUENCE */
472 {FNAME("t84Protocol") CHOICE, 3, 7, 14, SKIP | EXT, 0,
473 _DataProtocolCapability},
474 {FNAME("t84Profile") CHOICE, 1, 2, 2, SKIP, 0, _T84Profile},
475};
476
477static field_t _DataApplicationCapability_application_nlpid[] = { /* SEQUENCE */
478 {FNAME("nlpidProtocol") CHOICE, 3, 7, 14, SKIP | EXT, 0,
479 _DataProtocolCapability},
480 {FNAME("nlpidData") OCTSTR, SEMI, 0, 0, SKIP, 0, NULL},
481};
482
483static field_t _DataApplicationCapability_application[] = { /* CHOICE */
484 {FNAME("nonStandard") SEQ, 0, 2, 2, SKIP, 0,
485 _H245_NonStandardParameter},
486 {FNAME("t120") CHOICE, 3, 7, 14, DECODE | EXT,
487 offsetof(DataApplicationCapability_application, t120),
488 _DataProtocolCapability},
489 {FNAME("dsm-cc") CHOICE, 3, 7, 14, SKIP | EXT, 0,
490 _DataProtocolCapability},
491 {FNAME("userData") CHOICE, 3, 7, 14, SKIP | EXT, 0,
492 _DataProtocolCapability},
493 {FNAME("t84") SEQ, 0, 2, 2, SKIP, 0,
494 _DataApplicationCapability_application_t84},
495 {FNAME("t434") CHOICE, 3, 7, 14, SKIP | EXT, 0,
496 _DataProtocolCapability},
497 {FNAME("h224") CHOICE, 3, 7, 14, SKIP | EXT, 0,
498 _DataProtocolCapability},
499 {FNAME("nlpid") SEQ, 0, 2, 2, SKIP, 0,
500 _DataApplicationCapability_application_nlpid},
501 {FNAME("dsvdControl") NUL, FIXD, 0, 0, SKIP, 0, NULL},
502 {FNAME("h222DataPartitioning") CHOICE, 3, 7, 14, SKIP | EXT, 0,
503 _DataProtocolCapability},
504 {FNAME("t30fax") CHOICE, 3, 7, 14, SKIP | EXT, 0, NULL},
505 {FNAME("t140") CHOICE, 3, 7, 14, SKIP | EXT, 0, NULL},
506 {FNAME("t38fax") SEQ, 0, 2, 2, SKIP, 0, NULL},
507 {FNAME("genericDataCapability") SEQ, 5, 6, 6, SKIP | EXT, 0, NULL},
508};
509
510static field_t _DataApplicationCapability[] = { /* SEQUENCE */
511 {FNAME("application") CHOICE, 4, 10, 14, DECODE | EXT,
512 offsetof(DataApplicationCapability, application),
513 _DataApplicationCapability_application},
514 {FNAME("maxBitRate") INT, CONS, 0, 0, SKIP, 0, NULL},
515};
516
517static field_t _EncryptionMode[] = { /* CHOICE */
518 {FNAME("nonStandard") SEQ, 0, 2, 2, SKIP, 0,
519 _H245_NonStandardParameter},
520 {FNAME("h233Encryption") NUL, FIXD, 0, 0, SKIP, 0, NULL},
521};
522
523static field_t _DataType[] = { /* CHOICE */
524 {FNAME("nonStandard") SEQ, 0, 2, 2, SKIP, 0,
525 _H245_NonStandardParameter},
526 {FNAME("nullData") NUL, FIXD, 0, 0, SKIP, 0, NULL},
527 {FNAME("videoData") CHOICE, 3, 5, 6, SKIP | EXT, 0, _VideoCapability},
528 {FNAME("audioData") CHOICE, 4, 14, 22, SKIP | EXT, 0,
529 _AudioCapability},
530 {FNAME("data") SEQ, 0, 2, 2, DECODE | EXT, offsetof(DataType, data),
531 _DataApplicationCapability},
532 {FNAME("encryptionData") CHOICE, 1, 2, 2, SKIP | EXT, 0,
533 _EncryptionMode},
534 {FNAME("h235Control") SEQ, 0, 2, 2, SKIP, 0, NULL},
535 {FNAME("h235Media") SEQ, 0, 2, 2, SKIP | EXT, 0, NULL},
536 {FNAME("multiplexedStream") SEQ, 0, 2, 2, SKIP | EXT, 0, NULL},
537};
538
539static field_t _H222LogicalChannelParameters[] = { /* SEQUENCE */
540 {FNAME("resourceID") INT, WORD, 0, 0, SKIP, 0, NULL},
541 {FNAME("subChannelID") INT, WORD, 0, 0, SKIP, 0, NULL},
542 {FNAME("pcr-pid") INT, WORD, 0, 0, SKIP | OPT, 0, NULL},
543 {FNAME("programDescriptors") OCTSTR, SEMI, 0, 0, SKIP | OPT, 0, NULL},
544 {FNAME("streamDescriptors") OCTSTR, SEMI, 0, 0, SKIP | OPT, 0, NULL},
545};
546
547static field_t _H223LogicalChannelParameters_adaptationLayerType_al3[] = { /* SEQUENCE */
548 {FNAME("controlFieldOctets") INT, 2, 0, 0, SKIP, 0, NULL},
549 {FNAME("sendBufferSize") INT, CONS, 0, 0, SKIP, 0, NULL},
550};
551
552static field_t _H223LogicalChannelParameters_adaptationLayerType[] = { /* CHOICE */
553 {FNAME("nonStandard") SEQ, 0, 2, 2, SKIP, 0,
554 _H245_NonStandardParameter},
555 {FNAME("al1Framed") NUL, FIXD, 0, 0, SKIP, 0, NULL},
556 {FNAME("al1NotFramed") NUL, FIXD, 0, 0, SKIP, 0, NULL},
557 {FNAME("al2WithoutSequenceNumbers") NUL, FIXD, 0, 0, SKIP, 0, NULL},
558 {FNAME("al2WithSequenceNumbers") NUL, FIXD, 0, 0, SKIP, 0, NULL},
559 {FNAME("al3") SEQ, 0, 2, 2, SKIP, 0,
560 _H223LogicalChannelParameters_adaptationLayerType_al3},
561 {FNAME("al1M") SEQ, 0, 7, 8, SKIP | EXT, 0, NULL},
562 {FNAME("al2M") SEQ, 0, 2, 2, SKIP | EXT, 0, NULL},
563 {FNAME("al3M") SEQ, 0, 5, 6, SKIP | EXT, 0, NULL},
564};
565
566static field_t _H223LogicalChannelParameters[] = { /* SEQUENCE */
567 {FNAME("adaptationLayerType") CHOICE, 3, 6, 9, SKIP | EXT, 0,
568 _H223LogicalChannelParameters_adaptationLayerType},
569 {FNAME("segmentableFlag") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
570};
571
572static field_t _CRCLength[] = { /* CHOICE */
573 {FNAME("crc8bit") NUL, FIXD, 0, 0, SKIP, 0, NULL},
574 {FNAME("crc16bit") NUL, FIXD, 0, 0, SKIP, 0, NULL},
575 {FNAME("crc32bit") NUL, FIXD, 0, 0, SKIP, 0, NULL},
576};
577
578static field_t _V76HDLCParameters[] = { /* SEQUENCE */
579 {FNAME("crcLength") CHOICE, 2, 3, 3, SKIP | EXT, 0, _CRCLength},
580 {FNAME("n401") INT, WORD, 1, 0, SKIP, 0, NULL},
581 {FNAME("loopbackTestProcedure") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
582};
583
584static field_t _V76LogicalChannelParameters_suspendResume[] = { /* CHOICE */
585 {FNAME("noSuspendResume") NUL, FIXD, 0, 0, SKIP, 0, NULL},
586 {FNAME("suspendResumewAddress") NUL, FIXD, 0, 0, SKIP, 0, NULL},
587 {FNAME("suspendResumewoAddress") NUL, FIXD, 0, 0, SKIP, 0, NULL},
588};
589
590static field_t _V76LogicalChannelParameters_mode_eRM_recovery[] = { /* CHOICE */
591 {FNAME("rej") NUL, FIXD, 0, 0, SKIP, 0, NULL},
592 {FNAME("sREJ") NUL, FIXD, 0, 0, SKIP, 0, NULL},
593 {FNAME("mSREJ") NUL, FIXD, 0, 0, SKIP, 0, NULL},
594};
595
596static field_t _V76LogicalChannelParameters_mode_eRM[] = { /* SEQUENCE */
597 {FNAME("windowSize") INT, 7, 1, 0, SKIP, 0, NULL},
598 {FNAME("recovery") CHOICE, 2, 3, 3, SKIP | EXT, 0,
599 _V76LogicalChannelParameters_mode_eRM_recovery},
600};
601
602static field_t _V76LogicalChannelParameters_mode[] = { /* CHOICE */
603 {FNAME("eRM") SEQ, 0, 2, 2, SKIP | EXT, 0,
604 _V76LogicalChannelParameters_mode_eRM},
605 {FNAME("uNERM") NUL, FIXD, 0, 0, SKIP, 0, NULL},
606};
607
608static field_t _V75Parameters[] = { /* SEQUENCE */
609 {FNAME("audioHeaderPresent") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
610};
611
612static field_t _V76LogicalChannelParameters[] = { /* SEQUENCE */
613 {FNAME("hdlcParameters") SEQ, 0, 3, 3, SKIP | EXT, 0,
614 _V76HDLCParameters},
615 {FNAME("suspendResume") CHOICE, 2, 3, 3, SKIP | EXT, 0,
616 _V76LogicalChannelParameters_suspendResume},
617 {FNAME("uIH") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
618 {FNAME("mode") CHOICE, 1, 2, 2, SKIP | EXT, 0,
619 _V76LogicalChannelParameters_mode},
620 {FNAME("v75Parameters") SEQ, 0, 1, 1, SKIP | EXT, 0, _V75Parameters},
621};
622
623static field_t _H2250LogicalChannelParameters_nonStandard[] = { /* SEQUENCE OF */
624 {FNAME("item") SEQ, 0, 2, 2, SKIP, 0, _H245_NonStandardParameter},
625};
626
627static field_t _UnicastAddress_iPAddress[] = { /* SEQUENCE */
628 {FNAME("network") OCTSTR, FIXD, 4, 0, DECODE,
629 offsetof(UnicastAddress_iPAddress, network), NULL},
630 {FNAME("tsapIdentifier") INT, WORD, 0, 0, SKIP, 0, NULL},
631};
632
633static field_t _UnicastAddress_iPXAddress[] = { /* SEQUENCE */
634 {FNAME("node") OCTSTR, FIXD, 6, 0, SKIP, 0, NULL},
635 {FNAME("netnum") OCTSTR, FIXD, 4, 0, SKIP, 0, NULL},
636 {FNAME("tsapIdentifier") OCTSTR, FIXD, 2, 0, SKIP, 0, NULL},
637};
638
639static field_t _UnicastAddress_iP6Address[] = { /* SEQUENCE */
640 {FNAME("network") OCTSTR, FIXD, 16, 0, SKIP, 0, NULL},
641 {FNAME("tsapIdentifier") INT, WORD, 0, 0, SKIP, 0, NULL},
642};
643
644static field_t _UnicastAddress_iPSourceRouteAddress_routing[] = { /* CHOICE */
645 {FNAME("strict") NUL, FIXD, 0, 0, SKIP, 0, NULL},
646 {FNAME("loose") NUL, FIXD, 0, 0, SKIP, 0, NULL},
647};
648
649static field_t _UnicastAddress_iPSourceRouteAddress_route[] = { /* SEQUENCE OF */
650 {FNAME("item") OCTSTR, FIXD, 4, 0, SKIP, 0, NULL},
651};
652
653static field_t _UnicastAddress_iPSourceRouteAddress[] = { /* SEQUENCE */
654 {FNAME("routing") CHOICE, 1, 2, 2, SKIP, 0,
655 _UnicastAddress_iPSourceRouteAddress_routing},
656 {FNAME("network") OCTSTR, FIXD, 4, 0, SKIP, 0, NULL},
657 {FNAME("tsapIdentifier") INT, WORD, 0, 0, SKIP, 0, NULL},
658 {FNAME("route") SEQOF, SEMI, 0, 0, SKIP, 0,
659 _UnicastAddress_iPSourceRouteAddress_route},
660};
661
662static field_t _UnicastAddress[] = { /* CHOICE */
663 {FNAME("iPAddress") SEQ, 0, 2, 2, DECODE | EXT,
664 offsetof(UnicastAddress, iPAddress), _UnicastAddress_iPAddress},
665 {FNAME("iPXAddress") SEQ, 0, 3, 3, SKIP | EXT, 0,
666 _UnicastAddress_iPXAddress},
667 {FNAME("iP6Address") SEQ, 0, 2, 2, SKIP | EXT, 0,
668 _UnicastAddress_iP6Address},
669 {FNAME("netBios") OCTSTR, FIXD, 16, 0, SKIP, 0, NULL},
670 {FNAME("iPSourceRouteAddress") SEQ, 0, 4, 4, SKIP | EXT, 0,
671 _UnicastAddress_iPSourceRouteAddress},
672 {FNAME("nsap") OCTSTR, 5, 1, 0, SKIP, 0, NULL},
673 {FNAME("nonStandardAddress") SEQ, 0, 2, 2, SKIP, 0, NULL},
674};
675
676static field_t _MulticastAddress_iPAddress[] = { /* SEQUENCE */
677 {FNAME("network") OCTSTR, FIXD, 4, 0, SKIP, 0, NULL},
678 {FNAME("tsapIdentifier") INT, WORD, 0, 0, SKIP, 0, NULL},
679};
680
681static field_t _MulticastAddress_iP6Address[] = { /* SEQUENCE */
682 {FNAME("network") OCTSTR, FIXD, 16, 0, SKIP, 0, NULL},
683 {FNAME("tsapIdentifier") INT, WORD, 0, 0, SKIP, 0, NULL},
684};
685
686static field_t _MulticastAddress[] = { /* CHOICE */
687 {FNAME("iPAddress") SEQ, 0, 2, 2, SKIP | EXT, 0,
688 _MulticastAddress_iPAddress},
689 {FNAME("iP6Address") SEQ, 0, 2, 2, SKIP | EXT, 0,
690 _MulticastAddress_iP6Address},
691 {FNAME("nsap") OCTSTR, 5, 1, 0, SKIP, 0, NULL},
692 {FNAME("nonStandardAddress") SEQ, 0, 2, 2, SKIP, 0, NULL},
693};
694
695static field_t _H245_TransportAddress[] = { /* CHOICE */
696 {FNAME("unicastAddress") CHOICE, 3, 5, 7, DECODE | EXT,
697 offsetof(H245_TransportAddress, unicastAddress), _UnicastAddress},
698 {FNAME("multicastAddress") CHOICE, 1, 2, 4, SKIP | EXT, 0,
699 _MulticastAddress},
700};
701
702static field_t _H2250LogicalChannelParameters[] = { /* SEQUENCE */
703 {FNAME("nonStandard") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
704 _H2250LogicalChannelParameters_nonStandard},
705 {FNAME("sessionID") INT, BYTE, 0, 0, SKIP, 0, NULL},
706 {FNAME("associatedSessionID") INT, 8, 1, 0, SKIP | OPT, 0, NULL},
707 {FNAME("mediaChannel") CHOICE, 1, 2, 2, DECODE | EXT | OPT,
708 offsetof(H2250LogicalChannelParameters, mediaChannel),
709 _H245_TransportAddress},
710 {FNAME("mediaGuaranteedDelivery") BOOL, FIXD, 0, 0, SKIP | OPT, 0,
711 NULL},
712 {FNAME("mediaControlChannel") CHOICE, 1, 2, 2, DECODE | EXT | OPT,
713 offsetof(H2250LogicalChannelParameters, mediaControlChannel),
714 _H245_TransportAddress},
715 {FNAME("mediaControlGuaranteedDelivery") BOOL, FIXD, 0, 0, STOP | OPT,
716 0, NULL},
717 {FNAME("silenceSuppression") BOOL, FIXD, 0, 0, STOP | OPT, 0, NULL},
718 {FNAME("destination") SEQ, 0, 2, 2, STOP | EXT | OPT, 0, NULL},
719 {FNAME("dynamicRTPPayloadType") INT, 5, 96, 0, STOP | OPT, 0, NULL},
720 {FNAME("mediaPacketization") CHOICE, 0, 1, 2, STOP | EXT | OPT, 0,
721 NULL},
722 {FNAME("transportCapability") SEQ, 3, 3, 3, STOP | EXT | OPT, 0,
723 NULL},
724 {FNAME("redundancyEncoding") SEQ, 1, 2, 2, STOP | EXT | OPT, 0, NULL},
725 {FNAME("source") SEQ, 0, 2, 2, SKIP | EXT | OPT, 0, NULL},
726};
727
728static field_t _OpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters[] = { /* CHOICE */
729 {FNAME("h222LogicalChannelParameters") SEQ, 3, 5, 5, SKIP | EXT, 0,
730 _H222LogicalChannelParameters},
731 {FNAME("h223LogicalChannelParameters") SEQ, 0, 2, 2, SKIP | EXT, 0,
732 _H223LogicalChannelParameters},
733 {FNAME("v76LogicalChannelParameters") SEQ, 0, 5, 5, SKIP | EXT, 0,
734 _V76LogicalChannelParameters},
735 {FNAME("h2250LogicalChannelParameters") SEQ, 10, 11, 14, DECODE | EXT,
736 offsetof
737 (OpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters,
738 h2250LogicalChannelParameters), _H2250LogicalChannelParameters},
739 {FNAME("none") NUL, FIXD, 0, 0, SKIP, 0, NULL},
740};
741
742static field_t _OpenLogicalChannel_forwardLogicalChannelParameters[] = { /* SEQUENCE */
743 {FNAME("portNumber") INT, WORD, 0, 0, SKIP | OPT, 0, NULL},
744 {FNAME("dataType") CHOICE, 3, 6, 9, DECODE | EXT,
745 offsetof(OpenLogicalChannel_forwardLogicalChannelParameters,
746 dataType), _DataType},
747 {FNAME("multiplexParameters") CHOICE, 2, 3, 5, DECODE | EXT,
748 offsetof(OpenLogicalChannel_forwardLogicalChannelParameters,
749 multiplexParameters),
750 _OpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters},
751 {FNAME("forwardLogicalChannelDependency") INT, WORD, 1, 0, SKIP | OPT,
752 0, NULL},
753 {FNAME("replacementFor") INT, WORD, 1, 0, SKIP | OPT, 0, NULL},
754};
755
756static field_t _OpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters[] = { /* CHOICE */
757 {FNAME("h223LogicalChannelParameters") SEQ, 0, 2, 2, SKIP | EXT, 0,
758 _H223LogicalChannelParameters},
759 {FNAME("v76LogicalChannelParameters") SEQ, 0, 5, 5, SKIP | EXT, 0,
760 _V76LogicalChannelParameters},
761 {FNAME("h2250LogicalChannelParameters") SEQ, 10, 11, 14, DECODE | EXT,
762 offsetof
763 (OpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters,
764 h2250LogicalChannelParameters), _H2250LogicalChannelParameters},
765};
766
767static field_t _OpenLogicalChannel_reverseLogicalChannelParameters[] = { /* SEQUENCE */
768 {FNAME("dataType") CHOICE, 3, 6, 9, SKIP | EXT, 0, _DataType},
769 {FNAME("multiplexParameters") CHOICE, 1, 2, 3, DECODE | EXT | OPT,
770 offsetof(OpenLogicalChannel_reverseLogicalChannelParameters,
771 multiplexParameters),
772 _OpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters},
773 {FNAME("reverseLogicalChannelDependency") INT, WORD, 1, 0, SKIP | OPT,
774 0, NULL},
775 {FNAME("replacementFor") INT, WORD, 1, 0, SKIP | OPT, 0, NULL},
776};
777
778static field_t _NetworkAccessParameters_distribution[] = { /* CHOICE */
779 {FNAME("unicast") NUL, FIXD, 0, 0, SKIP, 0, NULL},
780 {FNAME("multicast") NUL, FIXD, 0, 0, SKIP, 0, NULL},
781};
782
783static field_t _Q2931Address_address[] = { /* CHOICE */
784 {FNAME("internationalNumber") NUMSTR, 4, 1, 0, SKIP, 0, NULL},
785 {FNAME("nsapAddress") OCTSTR, 5, 1, 0, SKIP, 0, NULL},
786};
787
788static field_t _Q2931Address[] = { /* SEQUENCE */
789 {FNAME("address") CHOICE, 1, 2, 2, SKIP | EXT, 0,
790 _Q2931Address_address},
791 {FNAME("subaddress") OCTSTR, 5, 1, 0, SKIP | OPT, 0, NULL},
792};
793
794static field_t _NetworkAccessParameters_networkAddress[] = { /* CHOICE */
795 {FNAME("q2931Address") SEQ, 1, 2, 2, SKIP | EXT, 0, _Q2931Address},
796 {FNAME("e164Address") NUMDGT, 7, 1, 0, SKIP, 0, NULL},
797 {FNAME("localAreaAddress") CHOICE, 1, 2, 2, DECODE | EXT,
798 offsetof(NetworkAccessParameters_networkAddress, localAreaAddress),
799 _H245_TransportAddress},
800};
801
802static field_t _NetworkAccessParameters[] = { /* SEQUENCE */
803 {FNAME("distribution") CHOICE, 1, 2, 2, SKIP | EXT | OPT, 0,
804 _NetworkAccessParameters_distribution},
805 {FNAME("networkAddress") CHOICE, 2, 3, 3, DECODE | EXT,
806 offsetof(NetworkAccessParameters, networkAddress),
807 _NetworkAccessParameters_networkAddress},
808 {FNAME("associateConference") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
809 {FNAME("externalReference") OCTSTR, 8, 1, 0, SKIP | OPT, 0, NULL},
810 {FNAME("t120SetupProcedure") CHOICE, 2, 3, 3, SKIP | EXT | OPT, 0,
811 NULL},
812};
813
814static field_t _OpenLogicalChannel[] = { /* SEQUENCE */
815 {FNAME("forwardLogicalChannelNumber") INT, WORD, 1, 0, SKIP, 0, NULL},
816 {FNAME("forwardLogicalChannelParameters") SEQ, 1, 3, 5, DECODE | EXT,
817 offsetof(OpenLogicalChannel, forwardLogicalChannelParameters),
818 _OpenLogicalChannel_forwardLogicalChannelParameters},
819 {FNAME("reverseLogicalChannelParameters") SEQ, 1, 2, 4,
820 DECODE | EXT | OPT, offsetof(OpenLogicalChannel,
821 reverseLogicalChannelParameters),
822 _OpenLogicalChannel_reverseLogicalChannelParameters},
823 {FNAME("separateStack") SEQ, 2, 4, 5, DECODE | EXT | OPT,
824 offsetof(OpenLogicalChannel, separateStack),
825 _NetworkAccessParameters},
826 {FNAME("encryptionSync") SEQ, 2, 4, 4, STOP | EXT | OPT, 0, NULL},
827};
828
829static field_t _Setup_UUIE_fastStart[] = { /* SEQUENCE OF */
830 {FNAME("item") SEQ, 1, 3, 5, DECODE | OPEN | EXT,
831 sizeof(OpenLogicalChannel), _OpenLogicalChannel}
832 ,
833};
834
835static field_t _Setup_UUIE[] = { /* SEQUENCE */
836 {FNAME("protocolIdentifier") OID, BYTE, 0, 0, SKIP, 0, NULL},
837 {FNAME("h245Address") CHOICE, 3, 7, 7, DECODE | EXT | OPT,
838 offsetof(Setup_UUIE, h245Address), _TransportAddress},
839 {FNAME("sourceAddress") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
840 _Setup_UUIE_sourceAddress},
841 {FNAME("sourceInfo") SEQ, 6, 8, 10, SKIP | EXT, 0, _EndpointType},
842 {FNAME("destinationAddress") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
843 _Setup_UUIE_destinationAddress},
844 {FNAME("destCallSignalAddress") CHOICE, 3, 7, 7, DECODE | EXT | OPT,
845 offsetof(Setup_UUIE, destCallSignalAddress), _TransportAddress},
846 {FNAME("destExtraCallInfo") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
847 _Setup_UUIE_destExtraCallInfo},
848 {FNAME("destExtraCRV") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
849 _Setup_UUIE_destExtraCRV},
850 {FNAME("activeMC") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
851 {FNAME("conferenceID") OCTSTR, FIXD, 16, 0, SKIP, 0, NULL},
852 {FNAME("conferenceGoal") CHOICE, 2, 3, 5, SKIP | EXT, 0,
853 _Setup_UUIE_conferenceGoal},
854 {FNAME("callServices") SEQ, 0, 8, 8, SKIP | EXT | OPT, 0,
855 _QseriesOptions},
856 {FNAME("callType") CHOICE, 2, 4, 4, SKIP | EXT, 0, _CallType},
857 {FNAME("sourceCallSignalAddress") CHOICE, 3, 7, 7, DECODE | EXT | OPT,
858 offsetof(Setup_UUIE, sourceCallSignalAddress), _TransportAddress},
859 {FNAME("remoteExtensionAddress") CHOICE, 1, 2, 7, SKIP | EXT | OPT, 0,
860 NULL},
861 {FNAME("callIdentifier") SEQ, 0, 1, 1, SKIP | EXT, 0, NULL},
862 {FNAME("h245SecurityCapability") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
863 NULL},
864 {FNAME("tokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
865 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
866 {FNAME("fastStart") SEQOF, SEMI, 0, 30, DECODE | OPT,
867 offsetof(Setup_UUIE, fastStart), _Setup_UUIE_fastStart},
868 {FNAME("mediaWaitForConnect") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
869 {FNAME("canOverlapSend") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
870 {FNAME("endpointIdentifier") BMPSTR, 7, 1, 0, STOP | OPT, 0, NULL},
871 {FNAME("multipleCalls") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
872 {FNAME("maintainConnection") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
873 {FNAME("connectionParameters") SEQ, 0, 3, 3, SKIP | EXT | OPT, 0,
874 NULL},
875 {FNAME("language") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
876 {FNAME("presentationIndicator") CHOICE, 2, 3, 3, SKIP | EXT | OPT, 0,
877 NULL},
878 {FNAME("screeningIndicator") ENUM, 2, 0, 0, SKIP | EXT | OPT, 0,
879 NULL},
880 {FNAME("serviceControl") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
881 {FNAME("symmetricOperationRequired") NUL, FIXD, 0, 0, SKIP | OPT, 0,
882 NULL},
883 {FNAME("capacity") SEQ, 2, 2, 2, SKIP | EXT | OPT, 0, NULL},
884 {FNAME("circuitInfo") SEQ, 3, 3, 3, SKIP | EXT | OPT, 0, NULL},
885 {FNAME("desiredProtocols") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
886 {FNAME("neededFeatures") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
887 {FNAME("desiredFeatures") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
888 {FNAME("supportedFeatures") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
889 {FNAME("parallelH245Control") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
890 {FNAME("additionalSourceAddresses") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
891 NULL},
892};
893
894static field_t _CallProceeding_UUIE_fastStart[] = { /* SEQUENCE OF */
895 {FNAME("item") SEQ, 1, 3, 5, DECODE | OPEN | EXT,
896 sizeof(OpenLogicalChannel), _OpenLogicalChannel}
897 ,
898};
899
900static field_t _CallProceeding_UUIE[] = { /* SEQUENCE */
901 {FNAME("protocolIdentifier") OID, BYTE, 0, 0, SKIP, 0, NULL},
902 {FNAME("destinationInfo") SEQ, 6, 8, 10, SKIP | EXT, 0,
903 _EndpointType},
904 {FNAME("h245Address") CHOICE, 3, 7, 7, DECODE | EXT | OPT,
905 offsetof(CallProceeding_UUIE, h245Address), _TransportAddress},
906 {FNAME("callIdentifier") SEQ, 0, 1, 1, SKIP | EXT, 0, NULL},
907 {FNAME("h245SecurityMode") CHOICE, 2, 4, 4, SKIP | EXT | OPT, 0,
908 NULL},
909 {FNAME("tokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
910 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
911 {FNAME("fastStart") SEQOF, SEMI, 0, 30, DECODE | OPT,
912 offsetof(CallProceeding_UUIE, fastStart),
913 _CallProceeding_UUIE_fastStart},
914 {FNAME("multipleCalls") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
915 {FNAME("maintainConnection") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
916 {FNAME("fastConnectRefused") NUL, FIXD, 0, 0, SKIP | OPT, 0, NULL},
917 {FNAME("featureSet") SEQ, 3, 4, 4, SKIP | EXT | OPT, 0, NULL},
918};
919
920static field_t _Connect_UUIE_fastStart[] = { /* SEQUENCE OF */
921 {FNAME("item") SEQ, 1, 3, 5, DECODE | OPEN | EXT,
922 sizeof(OpenLogicalChannel), _OpenLogicalChannel}
923 ,
924};
925
926static field_t _Connect_UUIE[] = { /* SEQUENCE */
927 {FNAME("protocolIdentifier") OID, BYTE, 0, 0, SKIP, 0, NULL},
928 {FNAME("h245Address") CHOICE, 3, 7, 7, DECODE | EXT | OPT,
929 offsetof(Connect_UUIE, h245Address), _TransportAddress},
930 {FNAME("destinationInfo") SEQ, 6, 8, 10, SKIP | EXT, 0,
931 _EndpointType},
932 {FNAME("conferenceID") OCTSTR, FIXD, 16, 0, SKIP, 0, NULL},
933 {FNAME("callIdentifier") SEQ, 0, 1, 1, SKIP | EXT, 0, NULL},
934 {FNAME("h245SecurityMode") CHOICE, 2, 4, 4, SKIP | EXT | OPT, 0,
935 NULL},
936 {FNAME("tokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
937 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
938 {FNAME("fastStart") SEQOF, SEMI, 0, 30, DECODE | OPT,
939 offsetof(Connect_UUIE, fastStart), _Connect_UUIE_fastStart},
940 {FNAME("multipleCalls") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
941 {FNAME("maintainConnection") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
942 {FNAME("language") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
943 {FNAME("connectedAddress") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
944 {FNAME("presentationIndicator") CHOICE, 2, 3, 3, SKIP | EXT | OPT, 0,
945 NULL},
946 {FNAME("screeningIndicator") ENUM, 2, 0, 0, SKIP | EXT | OPT, 0,
947 NULL},
948 {FNAME("fastConnectRefused") NUL, FIXD, 0, 0, SKIP | OPT, 0, NULL},
949 {FNAME("serviceControl") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
950 {FNAME("capacity") SEQ, 2, 2, 2, SKIP | EXT | OPT, 0, NULL},
951 {FNAME("featureSet") SEQ, 3, 4, 4, SKIP | EXT | OPT, 0, NULL},
952};
953
954static field_t _Alerting_UUIE_fastStart[] = { /* SEQUENCE OF */
955 {FNAME("item") SEQ, 1, 3, 5, DECODE | OPEN | EXT,
956 sizeof(OpenLogicalChannel), _OpenLogicalChannel}
957 ,
958};
959
960static field_t _Alerting_UUIE[] = { /* SEQUENCE */
961 {FNAME("protocolIdentifier") OID, BYTE, 0, 0, SKIP, 0, NULL},
962 {FNAME("destinationInfo") SEQ, 6, 8, 10, SKIP | EXT, 0,
963 _EndpointType},
964 {FNAME("h245Address") CHOICE, 3, 7, 7, DECODE | EXT | OPT,
965 offsetof(Alerting_UUIE, h245Address), _TransportAddress},
966 {FNAME("callIdentifier") SEQ, 0, 1, 1, SKIP | EXT, 0, NULL},
967 {FNAME("h245SecurityMode") CHOICE, 2, 4, 4, SKIP | EXT | OPT, 0,
968 NULL},
969 {FNAME("tokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
970 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
971 {FNAME("fastStart") SEQOF, SEMI, 0, 30, DECODE | OPT,
972 offsetof(Alerting_UUIE, fastStart), _Alerting_UUIE_fastStart},
973 {FNAME("multipleCalls") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
974 {FNAME("maintainConnection") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
975 {FNAME("alertingAddress") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
976 {FNAME("presentationIndicator") CHOICE, 2, 3, 3, SKIP | EXT | OPT, 0,
977 NULL},
978 {FNAME("screeningIndicator") ENUM, 2, 0, 0, SKIP | EXT | OPT, 0,
979 NULL},
980 {FNAME("fastConnectRefused") NUL, FIXD, 0, 0, SKIP | OPT, 0, NULL},
981 {FNAME("serviceControl") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
982 {FNAME("capacity") SEQ, 2, 2, 2, SKIP | EXT | OPT, 0, NULL},
983 {FNAME("featureSet") SEQ, 3, 4, 4, SKIP | EXT | OPT, 0, NULL},
984};
985
986static field_t _Information_UUIE_fastStart[] = { /* SEQUENCE OF */
987 {FNAME("item") SEQ, 1, 3, 5, DECODE | OPEN | EXT,
988 sizeof(OpenLogicalChannel), _OpenLogicalChannel}
989 ,
990};
991
992static field_t _Information_UUIE[] = { /* SEQUENCE */
993 {FNAME("protocolIdentifier") OID, BYTE, 0, 0, SKIP, 0, NULL},
994 {FNAME("callIdentifier") SEQ, 0, 1, 1, SKIP | EXT, 0, NULL},
995 {FNAME("tokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
996 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
997 {FNAME("fastStart") SEQOF, SEMI, 0, 30, DECODE | OPT,
998 offsetof(Information_UUIE, fastStart), _Information_UUIE_fastStart},
999 {FNAME("fastConnectRefused") NUL, FIXD, 0, 0, SKIP | OPT, 0, NULL},
1000 {FNAME("circuitInfo") SEQ, 3, 3, 3, SKIP | EXT | OPT, 0, NULL},
1001};
1002
1003static field_t _ReleaseCompleteReason[] = { /* CHOICE */
1004 {FNAME("noBandwidth") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1005 {FNAME("gatekeeperResources") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1006 {FNAME("unreachableDestination") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1007 {FNAME("destinationRejection") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1008 {FNAME("invalidRevision") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1009 {FNAME("noPermission") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1010 {FNAME("unreachableGatekeeper") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1011 {FNAME("gatewayResources") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1012 {FNAME("badFormatAddress") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1013 {FNAME("adaptiveBusy") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1014 {FNAME("inConf") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1015 {FNAME("undefinedReason") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1016 {FNAME("facilityCallDeflection") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1017 {FNAME("securityDenied") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1018 {FNAME("calledPartyNotRegistered") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1019 {FNAME("callerNotRegistered") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1020 {FNAME("newConnectionNeeded") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1021 {FNAME("nonStandardReason") SEQ, 0, 2, 2, SKIP, 0, NULL},
1022 {FNAME("replaceWithConferenceInvite") OCTSTR, FIXD, 16, 0, SKIP, 0,
1023 NULL},
1024 {FNAME("genericDataReason") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1025 {FNAME("neededFeatureNotSupported") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1026 {FNAME("tunnelledSignallingRejected") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1027};
1028
1029static field_t _ReleaseComplete_UUIE[] = { /* SEQUENCE */
1030 {FNAME("protocolIdentifier") OID, BYTE, 0, 0, SKIP, 0, NULL},
1031 {FNAME("reason") CHOICE, 4, 12, 22, SKIP | EXT | OPT, 0,
1032 _ReleaseCompleteReason},
1033 {FNAME("callIdentifier") SEQ, 0, 1, 1, SKIP | EXT, 0, NULL},
1034 {FNAME("tokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
1035 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
1036 {FNAME("busyAddress") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
1037 {FNAME("presentationIndicator") CHOICE, 2, 3, 3, SKIP | EXT | OPT, 0,
1038 NULL},
1039 {FNAME("screeningIndicator") ENUM, 2, 0, 0, SKIP | EXT | OPT, 0,
1040 NULL},
1041 {FNAME("capacity") SEQ, 2, 2, 2, SKIP | EXT | OPT, 0, NULL},
1042 {FNAME("serviceControl") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
1043 {FNAME("featureSet") SEQ, 3, 4, 4, SKIP | EXT | OPT, 0, NULL},
1044};
1045
1046static field_t _Facility_UUIE_alternativeAliasAddress[] = { /* SEQUENCE OF */
1047 {FNAME("item") CHOICE, 1, 2, 7, SKIP | EXT, 0, _AliasAddress},
1048};
1049
1050static field_t _FacilityReason[] = { /* CHOICE */
1051 {FNAME("routeCallToGatekeeper") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1052 {FNAME("callForwarded") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1053 {FNAME("routeCallToMC") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1054 {FNAME("undefinedReason") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1055 {FNAME("conferenceListChoice") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1056 {FNAME("startH245") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1057 {FNAME("noH245") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1058 {FNAME("newTokens") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1059 {FNAME("featureSetUpdate") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1060 {FNAME("forwardedElements") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1061 {FNAME("transportedInformation") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1062};
1063
1064static field_t _Facility_UUIE_fastStart[] = { /* SEQUENCE OF */
1065 {FNAME("item") SEQ, 1, 3, 5, DECODE | OPEN | EXT,
1066 sizeof(OpenLogicalChannel), _OpenLogicalChannel}
1067 ,
1068};
1069
1070static field_t _Facility_UUIE[] = { /* SEQUENCE */
1071 {FNAME("protocolIdentifier") OID, BYTE, 0, 0, SKIP, 0, NULL},
1072 {FNAME("alternativeAddress") CHOICE, 3, 7, 7, SKIP | EXT | OPT, 0,
1073 _TransportAddress},
1074 {FNAME("alternativeAliasAddress") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
1075 _Facility_UUIE_alternativeAliasAddress},
1076 {FNAME("conferenceID") OCTSTR, FIXD, 16, 0, SKIP | OPT, 0, NULL},
1077 {FNAME("reason") CHOICE, 2, 4, 11, DECODE | EXT,
1078 offsetof(Facility_UUIE, reason), _FacilityReason},
1079 {FNAME("callIdentifier") SEQ, 0, 1, 1, SKIP | EXT, 0, NULL},
1080 {FNAME("destExtraCallInfo") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
1081 {FNAME("remoteExtensionAddress") CHOICE, 1, 2, 7, SKIP | EXT | OPT, 0,
1082 NULL},
1083 {FNAME("tokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
1084 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
1085 {FNAME("conferences") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
1086 {FNAME("h245Address") CHOICE, 3, 7, 7, DECODE | EXT | OPT,
1087 offsetof(Facility_UUIE, h245Address), _TransportAddress},
1088 {FNAME("fastStart") SEQOF, SEMI, 0, 30, DECODE | OPT,
1089 offsetof(Facility_UUIE, fastStart), _Facility_UUIE_fastStart},
1090 {FNAME("multipleCalls") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
1091 {FNAME("maintainConnection") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
1092 {FNAME("fastConnectRefused") NUL, FIXD, 0, 0, SKIP | OPT, 0, NULL},
1093 {FNAME("serviceControl") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
1094 {FNAME("circuitInfo") SEQ, 3, 3, 3, SKIP | EXT | OPT, 0, NULL},
1095 {FNAME("featureSet") SEQ, 3, 4, 4, SKIP | EXT | OPT, 0, NULL},
1096 {FNAME("destinationInfo") SEQ, 6, 8, 10, SKIP | EXT | OPT, 0, NULL},
1097 {FNAME("h245SecurityMode") CHOICE, 2, 4, 4, SKIP | EXT | OPT, 0,
1098 NULL},
1099};
1100
1101static field_t _CallIdentifier[] = { /* SEQUENCE */
1102 {FNAME("guid") OCTSTR, FIXD, 16, 0, SKIP, 0, NULL},
1103};
1104
1105static field_t _SecurityServiceMode[] = { /* CHOICE */
1106 {FNAME("nonStandard") SEQ, 0, 2, 2, SKIP, 0, _NonStandardParameter},
1107 {FNAME("none") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1108 {FNAME("default") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1109};
1110
1111static field_t _SecurityCapabilities[] = { /* SEQUENCE */
1112 {FNAME("nonStandard") SEQ, 0, 2, 2, SKIP | OPT, 0,
1113 _NonStandardParameter},
1114 {FNAME("encryption") CHOICE, 2, 3, 3, SKIP | EXT, 0,
1115 _SecurityServiceMode},
1116 {FNAME("authenticaton") CHOICE, 2, 3, 3, SKIP | EXT, 0,
1117 _SecurityServiceMode},
1118 {FNAME("integrity") CHOICE, 2, 3, 3, SKIP | EXT, 0,
1119 _SecurityServiceMode},
1120};
1121
1122static field_t _H245Security[] = { /* CHOICE */
1123 {FNAME("nonStandard") SEQ, 0, 2, 2, SKIP, 0, _NonStandardParameter},
1124 {FNAME("noSecurity") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1125 {FNAME("tls") SEQ, 1, 4, 4, SKIP | EXT, 0, _SecurityCapabilities},
1126 {FNAME("ipsec") SEQ, 1, 4, 4, SKIP | EXT, 0, _SecurityCapabilities},
1127};
1128
1129static field_t _DHset[] = { /* SEQUENCE */
1130 {FNAME("halfkey") BITSTR, WORD, 0, 0, SKIP, 0, NULL},
1131 {FNAME("modSize") BITSTR, WORD, 0, 0, SKIP, 0, NULL},
1132 {FNAME("generator") BITSTR, WORD, 0, 0, SKIP, 0, NULL},
1133};
1134
1135static field_t _TypedCertificate[] = { /* SEQUENCE */
1136 {FNAME("type") OID, BYTE, 0, 0, SKIP, 0, NULL},
1137 {FNAME("certificate") OCTSTR, SEMI, 0, 0, SKIP, 0, NULL},
1138};
1139
1140static field_t _H235_NonStandardParameter[] = { /* SEQUENCE */
1141 {FNAME("nonStandardIdentifier") OID, BYTE, 0, 0, SKIP, 0, NULL},
1142 {FNAME("data") OCTSTR, SEMI, 0, 0, SKIP, 0, NULL},
1143};
1144
1145static field_t _ClearToken[] = { /* SEQUENCE */
1146 {FNAME("tokenOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1147 {FNAME("timeStamp") INT, CONS, 1, 0, SKIP | OPT, 0, NULL},
1148 {FNAME("password") BMPSTR, 7, 1, 0, SKIP | OPT, 0, NULL},
1149 {FNAME("dhkey") SEQ, 0, 3, 3, SKIP | EXT | OPT, 0, _DHset},
1150 {FNAME("challenge") OCTSTR, 7, 8, 0, SKIP | OPT, 0, NULL},
1151 {FNAME("random") INT, UNCO, 0, 0, SKIP | OPT, 0, NULL},
1152 {FNAME("certificate") SEQ, 0, 2, 2, SKIP | EXT | OPT, 0,
1153 _TypedCertificate},
1154 {FNAME("generalID") BMPSTR, 7, 1, 0, SKIP | OPT, 0, NULL},
1155 {FNAME("nonStandard") SEQ, 0, 2, 2, SKIP | OPT, 0,
1156 _H235_NonStandardParameter},
1157 {FNAME("eckasdhkey") CHOICE, 1, 2, 2, SKIP | EXT | OPT, 0, NULL},
1158 {FNAME("sendersID") BMPSTR, 7, 1, 0, SKIP | OPT, 0, NULL},
1159};
1160
1161static field_t _Progress_UUIE_tokens[] = { /* SEQUENCE OF */
1162 {FNAME("item") SEQ, 8, 9, 11, SKIP | EXT, 0, _ClearToken},
1163};
1164
1165static field_t _Params[] = { /* SEQUENCE */
1166 {FNAME("ranInt") INT, UNCO, 0, 0, SKIP | OPT, 0, NULL},
1167 {FNAME("iv8") OCTSTR, FIXD, 8, 0, SKIP | OPT, 0, NULL},
1168 {FNAME("iv16") OCTSTR, FIXD, 16, 0, SKIP | OPT, 0, NULL},
1169};
1170
1171static field_t _CryptoH323Token_cryptoEPPwdHash_token[] = { /* SEQUENCE */
1172 {FNAME("algorithmOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1173 {FNAME("paramS") SEQ, 2, 2, 3, SKIP | EXT, 0, _Params},
1174 {FNAME("hash") BITSTR, SEMI, 0, 0, SKIP, 0, NULL},
1175};
1176
1177static field_t _CryptoH323Token_cryptoEPPwdHash[] = { /* SEQUENCE */
1178 {FNAME("alias") CHOICE, 1, 2, 7, SKIP | EXT, 0, _AliasAddress},
1179 {FNAME("timeStamp") INT, CONS, 1, 0, SKIP, 0, NULL},
1180 {FNAME("token") SEQ, 0, 3, 3, SKIP, 0,
1181 _CryptoH323Token_cryptoEPPwdHash_token},
1182};
1183
1184static field_t _CryptoH323Token_cryptoGKPwdHash_token[] = { /* SEQUENCE */
1185 {FNAME("algorithmOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1186 {FNAME("paramS") SEQ, 2, 2, 3, SKIP | EXT, 0, _Params},
1187 {FNAME("hash") BITSTR, SEMI, 0, 0, SKIP, 0, NULL},
1188};
1189
1190static field_t _CryptoH323Token_cryptoGKPwdHash[] = { /* SEQUENCE */
1191 {FNAME("gatekeeperId") BMPSTR, 7, 1, 0, SKIP, 0, NULL},
1192 {FNAME("timeStamp") INT, CONS, 1, 0, SKIP, 0, NULL},
1193 {FNAME("token") SEQ, 0, 3, 3, SKIP, 0,
1194 _CryptoH323Token_cryptoGKPwdHash_token},
1195};
1196
1197static field_t _CryptoH323Token_cryptoEPPwdEncr[] = { /* SEQUENCE */
1198 {FNAME("algorithmOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1199 {FNAME("paramS") SEQ, 2, 2, 3, SKIP | EXT, 0, _Params},
1200 {FNAME("encryptedData") OCTSTR, SEMI, 0, 0, SKIP, 0, NULL},
1201};
1202
1203static field_t _CryptoH323Token_cryptoGKPwdEncr[] = { /* SEQUENCE */
1204 {FNAME("algorithmOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1205 {FNAME("paramS") SEQ, 2, 2, 3, SKIP | EXT, 0, _Params},
1206 {FNAME("encryptedData") OCTSTR, SEMI, 0, 0, SKIP, 0, NULL},
1207};
1208
1209static field_t _CryptoH323Token_cryptoEPCert[] = { /* SEQUENCE */
1210 {FNAME("toBeSigned") SEQ, 8, 9, 11, SKIP | OPEN | EXT, 0, NULL},
1211 {FNAME("algorithmOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1212 {FNAME("paramS") SEQ, 2, 2, 3, SKIP | EXT, 0, _Params},
1213 {FNAME("signature") BITSTR, SEMI, 0, 0, SKIP, 0, NULL},
1214};
1215
1216static field_t _CryptoH323Token_cryptoGKCert[] = { /* SEQUENCE */
1217 {FNAME("toBeSigned") SEQ, 8, 9, 11, SKIP | OPEN | EXT, 0, NULL},
1218 {FNAME("algorithmOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1219 {FNAME("paramS") SEQ, 2, 2, 3, SKIP | EXT, 0, _Params},
1220 {FNAME("signature") BITSTR, SEMI, 0, 0, SKIP, 0, NULL},
1221};
1222
1223static field_t _CryptoH323Token_cryptoFastStart[] = { /* SEQUENCE */
1224 {FNAME("toBeSigned") SEQ, 8, 9, 11, SKIP | OPEN | EXT, 0, NULL},
1225 {FNAME("algorithmOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1226 {FNAME("paramS") SEQ, 2, 2, 3, SKIP | EXT, 0, _Params},
1227 {FNAME("signature") BITSTR, SEMI, 0, 0, SKIP, 0, NULL},
1228};
1229
1230static field_t _CryptoToken_cryptoEncryptedToken_token[] = { /* SEQUENCE */
1231 {FNAME("algorithmOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1232 {FNAME("paramS") SEQ, 2, 2, 3, SKIP | EXT, 0, _Params},
1233 {FNAME("encryptedData") OCTSTR, SEMI, 0, 0, SKIP, 0, NULL},
1234};
1235
1236static field_t _CryptoToken_cryptoEncryptedToken[] = { /* SEQUENCE */
1237 {FNAME("tokenOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1238 {FNAME("token") SEQ, 0, 3, 3, SKIP, 0,
1239 _CryptoToken_cryptoEncryptedToken_token},
1240};
1241
1242static field_t _CryptoToken_cryptoSignedToken_token[] = { /* SEQUENCE */
1243 {FNAME("toBeSigned") SEQ, 8, 9, 11, SKIP | OPEN | EXT, 0, NULL},
1244 {FNAME("algorithmOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1245 {FNAME("paramS") SEQ, 2, 2, 3, SKIP | EXT, 0, _Params},
1246 {FNAME("signature") BITSTR, SEMI, 0, 0, SKIP, 0, NULL},
1247};
1248
1249static field_t _CryptoToken_cryptoSignedToken[] = { /* SEQUENCE */
1250 {FNAME("tokenOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1251 {FNAME("token") SEQ, 0, 4, 4, SKIP, 0,
1252 _CryptoToken_cryptoSignedToken_token},
1253};
1254
1255static field_t _CryptoToken_cryptoHashedToken_token[] = { /* SEQUENCE */
1256 {FNAME("algorithmOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1257 {FNAME("paramS") SEQ, 2, 2, 3, SKIP | EXT, 0, _Params},
1258 {FNAME("hash") BITSTR, SEMI, 0, 0, SKIP, 0, NULL},
1259};
1260
1261static field_t _CryptoToken_cryptoHashedToken[] = { /* SEQUENCE */
1262 {FNAME("tokenOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1263 {FNAME("hashedVals") SEQ, 8, 9, 11, SKIP | EXT, 0, _ClearToken},
1264 {FNAME("token") SEQ, 0, 3, 3, SKIP, 0,
1265 _CryptoToken_cryptoHashedToken_token},
1266};
1267
1268static field_t _CryptoToken_cryptoPwdEncr[] = { /* SEQUENCE */
1269 {FNAME("algorithmOID") OID, BYTE, 0, 0, SKIP, 0, NULL},
1270 {FNAME("paramS") SEQ, 2, 2, 3, SKIP | EXT, 0, _Params},
1271 {FNAME("encryptedData") OCTSTR, SEMI, 0, 0, SKIP, 0, NULL},
1272};
1273
1274static field_t _CryptoToken[] = { /* CHOICE */
1275 {FNAME("cryptoEncryptedToken") SEQ, 0, 2, 2, SKIP, 0,
1276 _CryptoToken_cryptoEncryptedToken},
1277 {FNAME("cryptoSignedToken") SEQ, 0, 2, 2, SKIP, 0,
1278 _CryptoToken_cryptoSignedToken},
1279 {FNAME("cryptoHashedToken") SEQ, 0, 3, 3, SKIP, 0,
1280 _CryptoToken_cryptoHashedToken},
1281 {FNAME("cryptoPwdEncr") SEQ, 0, 3, 3, SKIP, 0,
1282 _CryptoToken_cryptoPwdEncr},
1283};
1284
1285static field_t _CryptoH323Token[] = { /* CHOICE */
1286 {FNAME("cryptoEPPwdHash") SEQ, 0, 3, 3, SKIP, 0,
1287 _CryptoH323Token_cryptoEPPwdHash},
1288 {FNAME("cryptoGKPwdHash") SEQ, 0, 3, 3, SKIP, 0,
1289 _CryptoH323Token_cryptoGKPwdHash},
1290 {FNAME("cryptoEPPwdEncr") SEQ, 0, 3, 3, SKIP, 0,
1291 _CryptoH323Token_cryptoEPPwdEncr},
1292 {FNAME("cryptoGKPwdEncr") SEQ, 0, 3, 3, SKIP, 0,
1293 _CryptoH323Token_cryptoGKPwdEncr},
1294 {FNAME("cryptoEPCert") SEQ, 0, 4, 4, SKIP, 0,
1295 _CryptoH323Token_cryptoEPCert},
1296 {FNAME("cryptoGKCert") SEQ, 0, 4, 4, SKIP, 0,
1297 _CryptoH323Token_cryptoGKCert},
1298 {FNAME("cryptoFastStart") SEQ, 0, 4, 4, SKIP, 0,
1299 _CryptoH323Token_cryptoFastStart},
1300 {FNAME("nestedcryptoToken") CHOICE, 2, 4, 4, SKIP | EXT, 0,
1301 _CryptoToken},
1302};
1303
1304static field_t _Progress_UUIE_cryptoTokens[] = { /* SEQUENCE OF */
1305 {FNAME("item") CHOICE, 3, 8, 8, SKIP | EXT, 0, _CryptoH323Token},
1306};
1307
1308static field_t _Progress_UUIE_fastStart[] = { /* SEQUENCE OF */
1309 {FNAME("item") SEQ, 1, 3, 5, DECODE | OPEN | EXT,
1310 sizeof(OpenLogicalChannel), _OpenLogicalChannel}
1311 ,
1312};
1313
1314static field_t _Progress_UUIE[] = { /* SEQUENCE */
1315 {FNAME("protocolIdentifier") OID, BYTE, 0, 0, SKIP, 0, NULL},
1316 {FNAME("destinationInfo") SEQ, 6, 8, 10, SKIP | EXT, 0,
1317 _EndpointType},
1318 {FNAME("h245Address") CHOICE, 3, 7, 7, DECODE | EXT | OPT,
1319 offsetof(Progress_UUIE, h245Address), _TransportAddress},
1320 {FNAME("callIdentifier") SEQ, 0, 1, 1, SKIP | EXT, 0,
1321 _CallIdentifier},
1322 {FNAME("h245SecurityMode") CHOICE, 2, 4, 4, SKIP | EXT | OPT, 0,
1323 _H245Security},
1324 {FNAME("tokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
1325 _Progress_UUIE_tokens},
1326 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
1327 _Progress_UUIE_cryptoTokens},
1328 {FNAME("fastStart") SEQOF, SEMI, 0, 30, DECODE | OPT,
1329 offsetof(Progress_UUIE, fastStart), _Progress_UUIE_fastStart},
1330 {FNAME("multipleCalls") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
1331 {FNAME("maintainConnection") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
1332 {FNAME("fastConnectRefused") NUL, FIXD, 0, 0, SKIP | OPT, 0, NULL},
1333};
1334
1335static field_t _H323_UU_PDU_h323_message_body[] = { /* CHOICE */
1336 {FNAME("setup") SEQ, 7, 13, 39, DECODE | EXT,
1337 offsetof(H323_UU_PDU_h323_message_body, setup), _Setup_UUIE},
1338 {FNAME("callProceeding") SEQ, 1, 3, 12, DECODE | EXT,
1339 offsetof(H323_UU_PDU_h323_message_body, callProceeding),
1340 _CallProceeding_UUIE},
1341 {FNAME("connect") SEQ, 1, 4, 19, DECODE | EXT,
1342 offsetof(H323_UU_PDU_h323_message_body, connect), _Connect_UUIE},
1343 {FNAME("alerting") SEQ, 1, 3, 17, DECODE | EXT,
1344 offsetof(H323_UU_PDU_h323_message_body, alerting), _Alerting_UUIE},
1345 {FNAME("information") SEQ, 0, 1, 7, DECODE | EXT,
1346 offsetof(H323_UU_PDU_h323_message_body, information),
1347 _Information_UUIE},
1348 {FNAME("releaseComplete") SEQ, 1, 2, 11, SKIP | EXT, 0,
1349 _ReleaseComplete_UUIE},
1350 {FNAME("facility") SEQ, 3, 5, 21, DECODE | EXT,
1351 offsetof(H323_UU_PDU_h323_message_body, facility), _Facility_UUIE},
1352 {FNAME("progress") SEQ, 5, 8, 11, DECODE | EXT,
1353 offsetof(H323_UU_PDU_h323_message_body, progress), _Progress_UUIE},
1354 {FNAME("empty") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1355 {FNAME("status") SEQ, 2, 4, 4, SKIP | EXT, 0, NULL},
1356 {FNAME("statusInquiry") SEQ, 2, 4, 4, SKIP | EXT, 0, NULL},
1357 {FNAME("setupAcknowledge") SEQ, 2, 4, 4, SKIP | EXT, 0, NULL},
1358 {FNAME("notify") SEQ, 2, 4, 4, SKIP | EXT, 0, NULL},
1359};
1360
1361static field_t _RequestMessage[] = { /* CHOICE */
1362 {FNAME("nonStandard") SEQ, 0, 1, 1, STOP | EXT, 0, NULL},
1363 {FNAME("masterSlaveDetermination") SEQ, 0, 2, 2, STOP | EXT, 0, NULL},
1364 {FNAME("terminalCapabilitySet") SEQ, 3, 5, 5, STOP | EXT, 0, NULL},
1365 {FNAME("openLogicalChannel") SEQ, 1, 3, 5, DECODE | EXT,
1366 offsetof(RequestMessage, openLogicalChannel), _OpenLogicalChannel},
1367 {FNAME("closeLogicalChannel") SEQ, 0, 2, 3, STOP | EXT, 0, NULL},
1368 {FNAME("requestChannelClose") SEQ, 0, 1, 3, STOP | EXT, 0, NULL},
1369 {FNAME("multiplexEntrySend") SEQ, 0, 2, 2, STOP | EXT, 0, NULL},
1370 {FNAME("requestMultiplexEntry") SEQ, 0, 1, 1, STOP | EXT, 0, NULL},
1371 {FNAME("requestMode") SEQ, 0, 2, 2, STOP | EXT, 0, NULL},
1372 {FNAME("roundTripDelayRequest") SEQ, 0, 1, 1, STOP | EXT, 0, NULL},
1373 {FNAME("maintenanceLoopRequest") SEQ, 0, 1, 1, STOP | EXT, 0, NULL},
1374 {FNAME("communicationModeRequest") SEQ, 0, 0, 0, STOP | EXT, 0, NULL},
1375 {FNAME("conferenceRequest") CHOICE, 3, 8, 16, STOP | EXT, 0, NULL},
1376 {FNAME("multilinkRequest") CHOICE, 3, 5, 5, STOP | EXT, 0, NULL},
1377 {FNAME("logicalChannelRateRequest") SEQ, 0, 3, 3, STOP | EXT, 0,
1378 NULL},
1379};
1380
1381static field_t _OpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters[] = { /* CHOICE */
1382 {FNAME("h222LogicalChannelParameters") SEQ, 3, 5, 5, SKIP | EXT, 0,
1383 _H222LogicalChannelParameters},
1384 {FNAME("h2250LogicalChannelParameters") SEQ, 10, 11, 14, DECODE | EXT,
1385 offsetof
1386 (OpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters,
1387 h2250LogicalChannelParameters), _H2250LogicalChannelParameters},
1388};
1389
1390static field_t _OpenLogicalChannelAck_reverseLogicalChannelParameters[] = { /* SEQUENCE */
1391 {FNAME("reverseLogicalChannelNumber") INT, WORD, 1, 0, SKIP, 0, NULL},
1392 {FNAME("portNumber") INT, WORD, 0, 0, SKIP | OPT, 0, NULL},
1393 {FNAME("multiplexParameters") CHOICE, 0, 1, 2, DECODE | EXT | OPT,
1394 offsetof(OpenLogicalChannelAck_reverseLogicalChannelParameters,
1395 multiplexParameters),
1396 _OpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters},
1397 {FNAME("replacementFor") INT, WORD, 1, 0, SKIP | OPT, 0, NULL},
1398};
1399
1400static field_t _H2250LogicalChannelAckParameters_nonStandard[] = { /* SEQUENCE OF */
1401 {FNAME("item") SEQ, 0, 2, 2, SKIP, 0, _H245_NonStandardParameter},
1402};
1403
1404static field_t _H2250LogicalChannelAckParameters[] = { /* SEQUENCE */
1405 {FNAME("nonStandard") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
1406 _H2250LogicalChannelAckParameters_nonStandard},
1407 {FNAME("sessionID") INT, 8, 1, 0, SKIP | OPT, 0, NULL},
1408 {FNAME("mediaChannel") CHOICE, 1, 2, 2, DECODE | EXT | OPT,
1409 offsetof(H2250LogicalChannelAckParameters, mediaChannel),
1410 _H245_TransportAddress},
1411 {FNAME("mediaControlChannel") CHOICE, 1, 2, 2, DECODE | EXT | OPT,
1412 offsetof(H2250LogicalChannelAckParameters, mediaControlChannel),
1413 _H245_TransportAddress},
1414 {FNAME("dynamicRTPPayloadType") INT, 5, 96, 0, SKIP | OPT, 0, NULL},
1415 {FNAME("flowControlToZero") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
1416 {FNAME("portNumber") INT, WORD, 0, 0, SKIP | OPT, 0, NULL},
1417};
1418
1419static field_t _OpenLogicalChannelAck_forwardMultiplexAckParameters[] = { /* CHOICE */
1420 {FNAME("h2250LogicalChannelAckParameters") SEQ, 5, 5, 7, DECODE | EXT,
1421 offsetof(OpenLogicalChannelAck_forwardMultiplexAckParameters,
1422 h2250LogicalChannelAckParameters),
1423 _H2250LogicalChannelAckParameters},
1424};
1425
1426static field_t _OpenLogicalChannelAck[] = { /* SEQUENCE */
1427 {FNAME("forwardLogicalChannelNumber") INT, WORD, 1, 0, SKIP, 0, NULL},
1428 {FNAME("reverseLogicalChannelParameters") SEQ, 2, 3, 4,
1429 DECODE | EXT | OPT, offsetof(OpenLogicalChannelAck,
1430 reverseLogicalChannelParameters),
1431 _OpenLogicalChannelAck_reverseLogicalChannelParameters},
1432 {FNAME("separateStack") SEQ, 2, 4, 5, SKIP | EXT | OPT, 0, NULL},
1433 {FNAME("forwardMultiplexAckParameters") CHOICE, 0, 1, 1,
1434 DECODE | EXT | OPT, offsetof(OpenLogicalChannelAck,
1435 forwardMultiplexAckParameters),
1436 _OpenLogicalChannelAck_forwardMultiplexAckParameters},
1437 {FNAME("encryptionSync") SEQ, 2, 4, 4, STOP | EXT | OPT, 0, NULL},
1438};
1439
1440static field_t _ResponseMessage[] = { /* CHOICE */
1441 {FNAME("nonStandard") SEQ, 0, 1, 1, STOP | EXT, 0, NULL},
1442 {FNAME("masterSlaveDeterminationAck") SEQ, 0, 1, 1, STOP | EXT, 0,
1443 NULL},
1444 {FNAME("masterSlaveDeterminationReject") SEQ, 0, 1, 1, STOP | EXT, 0,
1445 NULL},
1446 {FNAME("terminalCapabilitySetAck") SEQ, 0, 1, 1, STOP | EXT, 0, NULL},
1447 {FNAME("terminalCapabilitySetReject") SEQ, 0, 2, 2, STOP | EXT, 0,
1448 NULL},
1449 {FNAME("openLogicalChannelAck") SEQ, 1, 2, 5, DECODE | EXT,
1450 offsetof(ResponseMessage, openLogicalChannelAck),
1451 _OpenLogicalChannelAck},
1452 {FNAME("openLogicalChannelReject") SEQ, 0, 2, 2, STOP | EXT, 0, NULL},
1453 {FNAME("closeLogicalChannelAck") SEQ, 0, 1, 1, STOP | EXT, 0, NULL},
1454 {FNAME("requestChannelCloseAck") SEQ, 0, 1, 1, STOP | EXT, 0, NULL},
1455 {FNAME("requestChannelCloseReject") SEQ, 0, 2, 2, STOP | EXT, 0,
1456 NULL},
1457 {FNAME("multiplexEntrySendAck") SEQ, 0, 2, 2, STOP | EXT, 0, NULL},
1458 {FNAME("multiplexEntrySendReject") SEQ, 0, 2, 2, STOP | EXT, 0, NULL},
1459 {FNAME("requestMultiplexEntryAck") SEQ, 0, 1, 1, STOP | EXT, 0, NULL},
1460 {FNAME("requestMultiplexEntryReject") SEQ, 0, 2, 2, STOP | EXT, 0,
1461 NULL},
1462 {FNAME("requestModeAck") SEQ, 0, 2, 2, STOP | EXT, 0, NULL},
1463 {FNAME("requestModeReject") SEQ, 0, 2, 2, STOP | EXT, 0, NULL},
1464 {FNAME("roundTripDelayResponse") SEQ, 0, 1, 1, STOP | EXT, 0, NULL},
1465 {FNAME("maintenanceLoopAck") SEQ, 0, 1, 1, STOP | EXT, 0, NULL},
1466 {FNAME("maintenanceLoopReject") SEQ, 0, 2, 2, STOP | EXT, 0, NULL},
1467 {FNAME("communicationModeResponse") CHOICE, 0, 1, 1, STOP | EXT, 0,
1468 NULL},
1469 {FNAME("conferenceResponse") CHOICE, 3, 8, 16, STOP | EXT, 0, NULL},
1470 {FNAME("multilinkResponse") CHOICE, 3, 5, 5, STOP | EXT, 0, NULL},
1471 {FNAME("logicalChannelRateAcknowledge") SEQ, 0, 3, 3, STOP | EXT, 0,
1472 NULL},
1473 {FNAME("logicalChannelRateReject") SEQ, 1, 4, 4, STOP | EXT, 0, NULL},
1474};
1475
1476static field_t _MultimediaSystemControlMessage[] = { /* CHOICE */
1477 {FNAME("request") CHOICE, 4, 11, 15, DECODE | EXT,
1478 offsetof(MultimediaSystemControlMessage, request), _RequestMessage},
1479 {FNAME("response") CHOICE, 5, 19, 24, DECODE | EXT,
1480 offsetof(MultimediaSystemControlMessage, response),
1481 _ResponseMessage},
1482 {FNAME("command") CHOICE, 3, 7, 12, STOP | EXT, 0, NULL},
1483 {FNAME("indication") CHOICE, 4, 14, 23, STOP | EXT, 0, NULL},
1484};
1485
1486static field_t _H323_UU_PDU_h245Control[] = { /* SEQUENCE OF */
1487 {FNAME("item") CHOICE, 2, 4, 4, DECODE | OPEN | EXT,
1488 sizeof(MultimediaSystemControlMessage),
1489 _MultimediaSystemControlMessage}
1490 ,
1491};
1492
1493static field_t _H323_UU_PDU[] = { /* SEQUENCE */
1494 {FNAME("h323-message-body") CHOICE, 3, 7, 13, DECODE | EXT,
1495 offsetof(H323_UU_PDU, h323_message_body),
1496 _H323_UU_PDU_h323_message_body},
1497 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
1498 _NonStandardParameter},
1499 {FNAME("h4501SupplementaryService") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
1500 NULL},
1501 {FNAME("h245Tunneling") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
1502 {FNAME("h245Control") SEQOF, SEMI, 0, 4, DECODE | OPT,
1503 offsetof(H323_UU_PDU, h245Control), _H323_UU_PDU_h245Control},
1504 {FNAME("nonStandardControl") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1505 {FNAME("callLinkage") SEQ, 2, 2, 2, STOP | EXT | OPT, 0, NULL},
1506 {FNAME("tunnelledSignallingMessage") SEQ, 2, 4, 4, STOP | EXT | OPT,
1507 0, NULL},
1508 {FNAME("provisionalRespToH245Tunneling") NUL, FIXD, 0, 0, STOP | OPT,
1509 0, NULL},
1510 {FNAME("stimulusControl") SEQ, 3, 3, 3, STOP | EXT | OPT, 0, NULL},
1511 {FNAME("genericData") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1512};
1513
1514static field_t _H323_UserInformation[] = { /* SEQUENCE */
1515 {FNAME("h323-uu-pdu") SEQ, 1, 2, 11, DECODE | EXT,
1516 offsetof(H323_UserInformation, h323_uu_pdu), _H323_UU_PDU},
1517 {FNAME("user-data") SEQ, 0, 2, 2, STOP | EXT | OPT, 0, NULL},
1518};
1519
1520static field_t _GatekeeperRequest[] = { /* SEQUENCE */
1521 {FNAME("requestSeqNum") INT, WORD, 1, 0, SKIP, 0, NULL},
1522 {FNAME("protocolIdentifier") OID, BYTE, 0, 0, SKIP, 0, NULL},
1523 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
1524 _NonStandardParameter},
1525 {FNAME("rasAddress") CHOICE, 3, 7, 7, DECODE | EXT,
1526 offsetof(GatekeeperRequest, rasAddress), _TransportAddress},
1527 {FNAME("endpointType") SEQ, 6, 8, 10, STOP | EXT, 0, NULL},
1528 {FNAME("gatekeeperIdentifier") BMPSTR, 7, 1, 0, STOP | OPT, 0, NULL},
1529 {FNAME("callServices") SEQ, 0, 8, 8, STOP | EXT | OPT, 0, NULL},
1530 {FNAME("endpointAlias") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1531 {FNAME("alternateEndpoints") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1532 {FNAME("tokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1533 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1534 {FNAME("authenticationCapability") SEQOF, SEMI, 0, 0, STOP | OPT, 0,
1535 NULL},
1536 {FNAME("algorithmOIDs") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1537 {FNAME("integrity") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1538 {FNAME("integrityCheckValue") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1539 {FNAME("supportsAltGK") NUL, FIXD, 0, 0, STOP | OPT, 0, NULL},
1540 {FNAME("featureSet") SEQ, 3, 4, 4, STOP | EXT | OPT, 0, NULL},
1541 {FNAME("genericData") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1542};
1543
1544static field_t _GatekeeperConfirm[] = { /* SEQUENCE */
1545 {FNAME("requestSeqNum") INT, WORD, 1, 0, SKIP, 0, NULL},
1546 {FNAME("protocolIdentifier") OID, BYTE, 0, 0, SKIP, 0, NULL},
1547 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
1548 _NonStandardParameter},
1549 {FNAME("gatekeeperIdentifier") BMPSTR, 7, 1, 0, SKIP | OPT, 0, NULL},
1550 {FNAME("rasAddress") CHOICE, 3, 7, 7, DECODE | EXT,
1551 offsetof(GatekeeperConfirm, rasAddress), _TransportAddress},
1552 {FNAME("alternateGatekeeper") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1553 {FNAME("authenticationMode") CHOICE, 3, 7, 8, STOP | EXT | OPT, 0,
1554 NULL},
1555 {FNAME("tokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1556 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1557 {FNAME("algorithmOID") OID, BYTE, 0, 0, STOP | OPT, 0, NULL},
1558 {FNAME("integrity") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1559 {FNAME("integrityCheckValue") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1560 {FNAME("featureSet") SEQ, 3, 4, 4, STOP | EXT | OPT, 0, NULL},
1561 {FNAME("genericData") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1562};
1563
1564static field_t _RegistrationRequest_callSignalAddress[] = { /* SEQUENCE OF */
1565 {FNAME("item") CHOICE, 3, 7, 7, DECODE | EXT,
1566 sizeof(TransportAddress), _TransportAddress}
1567 ,
1568};
1569
1570static field_t _RegistrationRequest_rasAddress[] = { /* SEQUENCE OF */
1571 {FNAME("item") CHOICE, 3, 7, 7, DECODE | EXT,
1572 sizeof(TransportAddress), _TransportAddress}
1573 ,
1574};
1575
1576static field_t _RegistrationRequest_terminalAlias[] = { /* SEQUENCE OF */
1577 {FNAME("item") CHOICE, 1, 2, 7, SKIP | EXT, 0, _AliasAddress},
1578};
1579
1580static field_t _RegistrationRequest[] = { /* SEQUENCE */
1581 {FNAME("requestSeqNum") INT, WORD, 1, 0, SKIP, 0, NULL},
1582 {FNAME("protocolIdentifier") OID, BYTE, 0, 0, SKIP, 0, NULL},
1583 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
1584 _NonStandardParameter},
1585 {FNAME("discoveryComplete") BOOL, FIXD, 0, 0, SKIP, 0, NULL},
1586 {FNAME("callSignalAddress") SEQOF, SEMI, 0, 10, DECODE,
1587 offsetof(RegistrationRequest, callSignalAddress),
1588 _RegistrationRequest_callSignalAddress},
1589 {FNAME("rasAddress") SEQOF, SEMI, 0, 10, DECODE,
1590 offsetof(RegistrationRequest, rasAddress),
1591 _RegistrationRequest_rasAddress},
1592 {FNAME("terminalType") SEQ, 6, 8, 10, SKIP | EXT, 0, _EndpointType},
1593 {FNAME("terminalAlias") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
1594 _RegistrationRequest_terminalAlias},
1595 {FNAME("gatekeeperIdentifier") BMPSTR, 7, 1, 0, SKIP | OPT, 0, NULL},
1596 {FNAME("endpointVendor") SEQ, 2, 3, 3, SKIP | EXT, 0,
1597 _VendorIdentifier},
1598 {FNAME("alternateEndpoints") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
1599 {FNAME("timeToLive") INT, CONS, 1, 0, DECODE | OPT,
1600 offsetof(RegistrationRequest, timeToLive), NULL},
1601 {FNAME("tokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1602 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1603 {FNAME("integrityCheckValue") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1604 {FNAME("keepAlive") BOOL, FIXD, 0, 0, STOP, 0, NULL},
1605 {FNAME("endpointIdentifier") BMPSTR, 7, 1, 0, STOP | OPT, 0, NULL},
1606 {FNAME("willSupplyUUIEs") BOOL, FIXD, 0, 0, STOP, 0, NULL},
1607 {FNAME("maintainConnection") BOOL, FIXD, 0, 0, STOP, 0, NULL},
1608 {FNAME("alternateTransportAddresses") SEQ, 1, 1, 1, STOP | EXT | OPT,
1609 0, NULL},
1610 {FNAME("additiveRegistration") NUL, FIXD, 0, 0, STOP | OPT, 0, NULL},
1611 {FNAME("terminalAliasPattern") SEQOF, SEMI, 0, 0, STOP | OPT, 0,
1612 NULL},
1613 {FNAME("supportsAltGK") NUL, FIXD, 0, 0, STOP | OPT, 0, NULL},
1614 {FNAME("usageReportingCapability") SEQ, 3, 4, 4, STOP | EXT | OPT, 0,
1615 NULL},
1616 {FNAME("multipleCalls") BOOL, FIXD, 0, 0, STOP | OPT, 0, NULL},
1617 {FNAME("supportedH248Packages") SEQOF, SEMI, 0, 0, STOP | OPT, 0,
1618 NULL},
1619 {FNAME("callCreditCapability") SEQ, 2, 2, 2, STOP | EXT | OPT, 0,
1620 NULL},
1621 {FNAME("capacityReportingCapability") SEQ, 0, 1, 1, STOP | EXT | OPT,
1622 0, NULL},
1623 {FNAME("capacity") SEQ, 2, 2, 2, STOP | EXT | OPT, 0, NULL},
1624 {FNAME("featureSet") SEQ, 3, 4, 4, STOP | EXT | OPT, 0, NULL},
1625 {FNAME("genericData") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1626};
1627
1628static field_t _RegistrationConfirm_callSignalAddress[] = { /* SEQUENCE OF */
1629 {FNAME("item") CHOICE, 3, 7, 7, DECODE | EXT,
1630 sizeof(TransportAddress), _TransportAddress}
1631 ,
1632};
1633
1634static field_t _RegistrationConfirm_terminalAlias[] = { /* SEQUENCE OF */
1635 {FNAME("item") CHOICE, 1, 2, 7, SKIP | EXT, 0, _AliasAddress},
1636};
1637
1638static field_t _RegistrationConfirm[] = { /* SEQUENCE */
1639 {FNAME("requestSeqNum") INT, WORD, 1, 0, SKIP, 0, NULL},
1640 {FNAME("protocolIdentifier") OID, BYTE, 0, 0, SKIP, 0, NULL},
1641 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
1642 _NonStandardParameter},
1643 {FNAME("callSignalAddress") SEQOF, SEMI, 0, 10, DECODE,
1644 offsetof(RegistrationConfirm, callSignalAddress),
1645 _RegistrationConfirm_callSignalAddress},
1646 {FNAME("terminalAlias") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
1647 _RegistrationConfirm_terminalAlias},
1648 {FNAME("gatekeeperIdentifier") BMPSTR, 7, 1, 0, SKIP | OPT, 0, NULL},
1649 {FNAME("endpointIdentifier") BMPSTR, 7, 1, 0, SKIP, 0, NULL},
1650 {FNAME("alternateGatekeeper") SEQOF, SEMI, 0, 0, SKIP | OPT, 0, NULL},
1651 {FNAME("timeToLive") INT, CONS, 1, 0, DECODE | OPT,
1652 offsetof(RegistrationConfirm, timeToLive), NULL},
1653 {FNAME("tokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1654 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1655 {FNAME("integrityCheckValue") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1656 {FNAME("willRespondToIRR") BOOL, FIXD, 0, 0, STOP, 0, NULL},
1657 {FNAME("preGrantedARQ") SEQ, 0, 4, 8, STOP | EXT | OPT, 0, NULL},
1658 {FNAME("maintainConnection") BOOL, FIXD, 0, 0, STOP, 0, NULL},
1659 {FNAME("serviceControl") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1660 {FNAME("supportsAdditiveRegistration") NUL, FIXD, 0, 0, STOP | OPT, 0,
1661 NULL},
1662 {FNAME("terminalAliasPattern") SEQOF, SEMI, 0, 0, STOP | OPT, 0,
1663 NULL},
1664 {FNAME("supportedPrefixes") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1665 {FNAME("usageSpec") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1666 {FNAME("featureServerAlias") CHOICE, 1, 2, 7, STOP | EXT | OPT, 0,
1667 NULL},
1668 {FNAME("capacityReportingSpec") SEQ, 0, 1, 1, STOP | EXT | OPT, 0,
1669 NULL},
1670 {FNAME("featureSet") SEQ, 3, 4, 4, STOP | EXT | OPT, 0, NULL},
1671 {FNAME("genericData") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1672};
1673
1674static field_t _UnregistrationRequest_callSignalAddress[] = { /* SEQUENCE OF */
1675 {FNAME("item") CHOICE, 3, 7, 7, DECODE | EXT,
1676 sizeof(TransportAddress), _TransportAddress}
1677 ,
1678};
1679
1680static field_t _UnregistrationRequest[] = { /* SEQUENCE */
1681 {FNAME("requestSeqNum") INT, WORD, 1, 0, SKIP, 0, NULL},
1682 {FNAME("callSignalAddress") SEQOF, SEMI, 0, 10, DECODE,
1683 offsetof(UnregistrationRequest, callSignalAddress),
1684 _UnregistrationRequest_callSignalAddress},
1685 {FNAME("endpointAlias") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1686 {FNAME("nonStandardData") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1687 {FNAME("endpointIdentifier") BMPSTR, 7, 1, 0, STOP | OPT, 0, NULL},
1688 {FNAME("alternateEndpoints") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1689 {FNAME("gatekeeperIdentifier") BMPSTR, 7, 1, 0, STOP | OPT, 0, NULL},
1690 {FNAME("tokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1691 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1692 {FNAME("integrityCheckValue") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1693 {FNAME("reason") CHOICE, 2, 4, 5, STOP | EXT | OPT, 0, NULL},
1694 {FNAME("endpointAliasPattern") SEQOF, SEMI, 0, 0, STOP | OPT, 0,
1695 NULL},
1696 {FNAME("supportedPrefixes") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1697 {FNAME("alternateGatekeeper") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1698 {FNAME("genericData") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1699};
1700
1701static field_t _CallModel[] = { /* CHOICE */
1702 {FNAME("direct") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1703 {FNAME("gatekeeperRouted") NUL, FIXD, 0, 0, SKIP, 0, NULL},
1704};
1705
1706static field_t _AdmissionRequest_destinationInfo[] = { /* SEQUENCE OF */
1707 {FNAME("item") CHOICE, 1, 2, 7, SKIP | EXT, 0, _AliasAddress},
1708};
1709
1710static field_t _AdmissionRequest_destExtraCallInfo[] = { /* SEQUENCE OF */
1711 {FNAME("item") CHOICE, 1, 2, 7, SKIP | EXT, 0, _AliasAddress},
1712};
1713
1714static field_t _AdmissionRequest_srcInfo[] = { /* SEQUENCE OF */
1715 {FNAME("item") CHOICE, 1, 2, 7, SKIP | EXT, 0, _AliasAddress},
1716};
1717
1718static field_t _AdmissionRequest[] = { /* SEQUENCE */
1719 {FNAME("requestSeqNum") INT, WORD, 1, 0, SKIP, 0, NULL},
1720 {FNAME("callType") CHOICE, 2, 4, 4, SKIP | EXT, 0, _CallType},
1721 {FNAME("callModel") CHOICE, 1, 2, 2, SKIP | EXT | OPT, 0, _CallModel},
1722 {FNAME("endpointIdentifier") BMPSTR, 7, 1, 0, SKIP, 0, NULL},
1723 {FNAME("destinationInfo") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
1724 _AdmissionRequest_destinationInfo},
1725 {FNAME("destCallSignalAddress") CHOICE, 3, 7, 7, DECODE | EXT | OPT,
1726 offsetof(AdmissionRequest, destCallSignalAddress),
1727 _TransportAddress},
1728 {FNAME("destExtraCallInfo") SEQOF, SEMI, 0, 0, SKIP | OPT, 0,
1729 _AdmissionRequest_destExtraCallInfo},
1730 {FNAME("srcInfo") SEQOF, SEMI, 0, 0, SKIP, 0,
1731 _AdmissionRequest_srcInfo},
1732 {FNAME("srcCallSignalAddress") CHOICE, 3, 7, 7, DECODE | EXT | OPT,
1733 offsetof(AdmissionRequest, srcCallSignalAddress), _TransportAddress},
1734 {FNAME("bandWidth") INT, CONS, 0, 0, STOP, 0, NULL},
1735 {FNAME("callReferenceValue") INT, WORD, 0, 0, STOP, 0, NULL},
1736 {FNAME("nonStandardData") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1737 {FNAME("callServices") SEQ, 0, 8, 8, STOP | EXT | OPT, 0, NULL},
1738 {FNAME("conferenceID") OCTSTR, FIXD, 16, 0, STOP, 0, NULL},
1739 {FNAME("activeMC") BOOL, FIXD, 0, 0, STOP, 0, NULL},
1740 {FNAME("answerCall") BOOL, FIXD, 0, 0, STOP, 0, NULL},
1741 {FNAME("canMapAlias") BOOL, FIXD, 0, 0, STOP, 0, NULL},
1742 {FNAME("callIdentifier") SEQ, 0, 1, 1, STOP | EXT, 0, NULL},
1743 {FNAME("srcAlternatives") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1744 {FNAME("destAlternatives") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1745 {FNAME("gatekeeperIdentifier") BMPSTR, 7, 1, 0, STOP | OPT, 0, NULL},
1746 {FNAME("tokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1747 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1748 {FNAME("integrityCheckValue") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1749 {FNAME("transportQOS") CHOICE, 2, 3, 3, STOP | EXT | OPT, 0, NULL},
1750 {FNAME("willSupplyUUIEs") BOOL, FIXD, 0, 0, STOP, 0, NULL},
1751 {FNAME("callLinkage") SEQ, 2, 2, 2, STOP | EXT | OPT, 0, NULL},
1752 {FNAME("gatewayDataRate") SEQ, 2, 3, 3, STOP | EXT | OPT, 0, NULL},
1753 {FNAME("capacity") SEQ, 2, 2, 2, STOP | EXT | OPT, 0, NULL},
1754 {FNAME("circuitInfo") SEQ, 3, 3, 3, STOP | EXT | OPT, 0, NULL},
1755 {FNAME("desiredProtocols") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1756 {FNAME("desiredTunnelledProtocol") SEQ, 1, 2, 2, STOP | EXT | OPT, 0,
1757 NULL},
1758 {FNAME("featureSet") SEQ, 3, 4, 4, STOP | EXT | OPT, 0, NULL},
1759 {FNAME("genericData") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1760};
1761
1762static field_t _AdmissionConfirm[] = { /* SEQUENCE */
1763 {FNAME("requestSeqNum") INT, WORD, 1, 0, SKIP, 0, NULL},
1764 {FNAME("bandWidth") INT, CONS, 0, 0, SKIP, 0, NULL},
1765 {FNAME("callModel") CHOICE, 1, 2, 2, SKIP | EXT, 0, _CallModel},
1766 {FNAME("destCallSignalAddress") CHOICE, 3, 7, 7, DECODE | EXT,
1767 offsetof(AdmissionConfirm, destCallSignalAddress),
1768 _TransportAddress},
1769 {FNAME("irrFrequency") INT, WORD, 1, 0, STOP | OPT, 0, NULL},
1770 {FNAME("nonStandardData") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1771 {FNAME("destinationInfo") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1772 {FNAME("destExtraCallInfo") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1773 {FNAME("destinationType") SEQ, 6, 8, 10, STOP | EXT | OPT, 0, NULL},
1774 {FNAME("remoteExtensionAddress") SEQOF, SEMI, 0, 0, STOP | OPT, 0,
1775 NULL},
1776 {FNAME("alternateEndpoints") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1777 {FNAME("tokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1778 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1779 {FNAME("integrityCheckValue") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1780 {FNAME("transportQOS") CHOICE, 2, 3, 3, STOP | EXT | OPT, 0, NULL},
1781 {FNAME("willRespondToIRR") BOOL, FIXD, 0, 0, STOP, 0, NULL},
1782 {FNAME("uuiesRequested") SEQ, 0, 9, 13, STOP | EXT, 0, NULL},
1783 {FNAME("language") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1784 {FNAME("alternateTransportAddresses") SEQ, 1, 1, 1, STOP | EXT | OPT,
1785 0, NULL},
1786 {FNAME("useSpecifiedTransport") CHOICE, 1, 2, 2, STOP | EXT | OPT, 0,
1787 NULL},
1788 {FNAME("circuitInfo") SEQ, 3, 3, 3, STOP | EXT | OPT, 0, NULL},
1789 {FNAME("usageSpec") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1790 {FNAME("supportedProtocols") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1791 {FNAME("serviceControl") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1792 {FNAME("multipleCalls") BOOL, FIXD, 0, 0, STOP | OPT, 0, NULL},
1793 {FNAME("featureSet") SEQ, 3, 4, 4, STOP | EXT | OPT, 0, NULL},
1794 {FNAME("genericData") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1795};
1796
1797static field_t _LocationRequest_destinationInfo[] = { /* SEQUENCE OF */
1798 {FNAME("item") CHOICE, 1, 2, 7, SKIP | EXT, 0, _AliasAddress},
1799};
1800
1801static field_t _LocationRequest[] = { /* SEQUENCE */
1802 {FNAME("requestSeqNum") INT, WORD, 1, 0, SKIP, 0, NULL},
1803 {FNAME("endpointIdentifier") BMPSTR, 7, 1, 0, SKIP | OPT, 0, NULL},
1804 {FNAME("destinationInfo") SEQOF, SEMI, 0, 0, SKIP, 0,
1805 _LocationRequest_destinationInfo},
1806 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
1807 _NonStandardParameter},
1808 {FNAME("replyAddress") CHOICE, 3, 7, 7, DECODE | EXT,
1809 offsetof(LocationRequest, replyAddress), _TransportAddress},
1810 {FNAME("sourceInfo") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1811 {FNAME("canMapAlias") BOOL, FIXD, 0, 0, STOP, 0, NULL},
1812 {FNAME("gatekeeperIdentifier") BMPSTR, 7, 1, 0, STOP | OPT, 0, NULL},
1813 {FNAME("tokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1814 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1815 {FNAME("integrityCheckValue") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1816 {FNAME("desiredProtocols") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1817 {FNAME("desiredTunnelledProtocol") SEQ, 1, 2, 2, STOP | EXT | OPT, 0,
1818 NULL},
1819 {FNAME("featureSet") SEQ, 3, 4, 4, STOP | EXT | OPT, 0, NULL},
1820 {FNAME("genericData") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1821 {FNAME("hopCount") INT, 8, 1, 0, STOP | OPT, 0, NULL},
1822 {FNAME("circuitInfo") SEQ, 3, 3, 3, STOP | EXT | OPT, 0, NULL},
1823};
1824
1825static field_t _LocationConfirm[] = { /* SEQUENCE */
1826 {FNAME("requestSeqNum") INT, WORD, 1, 0, SKIP, 0, NULL},
1827 {FNAME("callSignalAddress") CHOICE, 3, 7, 7, DECODE | EXT,
1828 offsetof(LocationConfirm, callSignalAddress), _TransportAddress},
1829 {FNAME("rasAddress") CHOICE, 3, 7, 7, DECODE | EXT,
1830 offsetof(LocationConfirm, rasAddress), _TransportAddress},
1831 {FNAME("nonStandardData") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1832 {FNAME("destinationInfo") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1833 {FNAME("destExtraCallInfo") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1834 {FNAME("destinationType") SEQ, 6, 8, 10, STOP | EXT | OPT, 0, NULL},
1835 {FNAME("remoteExtensionAddress") SEQOF, SEMI, 0, 0, STOP | OPT, 0,
1836 NULL},
1837 {FNAME("alternateEndpoints") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1838 {FNAME("tokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1839 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1840 {FNAME("integrityCheckValue") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1841 {FNAME("alternateTransportAddresses") SEQ, 1, 1, 1, STOP | EXT | OPT,
1842 0, NULL},
1843 {FNAME("supportedProtocols") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1844 {FNAME("multipleCalls") BOOL, FIXD, 0, 0, STOP | OPT, 0, NULL},
1845 {FNAME("featureSet") SEQ, 3, 4, 4, STOP | EXT | OPT, 0, NULL},
1846 {FNAME("genericData") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1847 {FNAME("circuitInfo") SEQ, 3, 3, 3, STOP | EXT | OPT, 0, NULL},
1848 {FNAME("serviceControl") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1849};
1850
1851static field_t _InfoRequestResponse_callSignalAddress[] = { /* SEQUENCE OF */
1852 {FNAME("item") CHOICE, 3, 7, 7, DECODE | EXT,
1853 sizeof(TransportAddress), _TransportAddress}
1854 ,
1855};
1856
1857static field_t _InfoRequestResponse[] = { /* SEQUENCE */
1858 {FNAME("nonStandardData") SEQ, 0, 2, 2, SKIP | OPT, 0,
1859 _NonStandardParameter},
1860 {FNAME("requestSeqNum") INT, WORD, 1, 0, SKIP, 0, NULL},
1861 {FNAME("endpointType") SEQ, 6, 8, 10, SKIP | EXT, 0, _EndpointType},
1862 {FNAME("endpointIdentifier") BMPSTR, 7, 1, 0, SKIP, 0, NULL},
1863 {FNAME("rasAddress") CHOICE, 3, 7, 7, DECODE | EXT,
1864 offsetof(InfoRequestResponse, rasAddress), _TransportAddress},
1865 {FNAME("callSignalAddress") SEQOF, SEMI, 0, 10, DECODE,
1866 offsetof(InfoRequestResponse, callSignalAddress),
1867 _InfoRequestResponse_callSignalAddress},
1868 {FNAME("endpointAlias") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1869 {FNAME("perCallInfo") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1870 {FNAME("tokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1871 {FNAME("cryptoTokens") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1872 {FNAME("integrityCheckValue") SEQ, 0, 2, 2, STOP | OPT, 0, NULL},
1873 {FNAME("needResponse") BOOL, FIXD, 0, 0, STOP, 0, NULL},
1874 {FNAME("capacity") SEQ, 2, 2, 2, STOP | EXT | OPT, 0, NULL},
1875 {FNAME("irrStatus") CHOICE, 2, 4, 4, STOP | EXT | OPT, 0, NULL},
1876 {FNAME("unsolicited") BOOL, FIXD, 0, 0, STOP, 0, NULL},
1877 {FNAME("genericData") SEQOF, SEMI, 0, 0, STOP | OPT, 0, NULL},
1878};
1879
1880static field_t _RasMessage[] = { /* CHOICE */
1881 {FNAME("gatekeeperRequest") SEQ, 4, 8, 18, DECODE | EXT,
1882 offsetof(RasMessage, gatekeeperRequest), _GatekeeperRequest},
1883 {FNAME("gatekeeperConfirm") SEQ, 2, 5, 14, DECODE | EXT,
1884 offsetof(RasMessage, gatekeeperConfirm), _GatekeeperConfirm},
1885 {FNAME("gatekeeperReject") SEQ, 2, 5, 11, STOP | EXT, 0, NULL},
1886 {FNAME("registrationRequest") SEQ, 3, 10, 31, DECODE | EXT,
1887 offsetof(RasMessage, registrationRequest), _RegistrationRequest},
1888 {FNAME("registrationConfirm") SEQ, 3, 7, 24, DECODE | EXT,
1889 offsetof(RasMessage, registrationConfirm), _RegistrationConfirm},
1890 {FNAME("registrationReject") SEQ, 2, 5, 11, STOP | EXT, 0, NULL},
1891 {FNAME("unregistrationRequest") SEQ, 3, 5, 15, DECODE | EXT,
1892 offsetof(RasMessage, unregistrationRequest), _UnregistrationRequest},
1893 {FNAME("unregistrationConfirm") SEQ, 1, 2, 6, STOP | EXT, 0, NULL},
1894 {FNAME("unregistrationReject") SEQ, 1, 3, 8, STOP | EXT, 0, NULL},
1895 {FNAME("admissionRequest") SEQ, 7, 16, 34, DECODE | EXT,
1896 offsetof(RasMessage, admissionRequest), _AdmissionRequest},
1897 {FNAME("admissionConfirm") SEQ, 2, 6, 27, DECODE | EXT,
1898 offsetof(RasMessage, admissionConfirm), _AdmissionConfirm},
1899 {FNAME("admissionReject") SEQ, 1, 3, 11, STOP | EXT, 0, NULL},
1900 {FNAME("bandwidthRequest") SEQ, 2, 7, 18, STOP | EXT, 0, NULL},
1901 {FNAME("bandwidthConfirm") SEQ, 1, 3, 8, STOP | EXT, 0, NULL},
1902 {FNAME("bandwidthReject") SEQ, 1, 4, 9, STOP | EXT, 0, NULL},
1903 {FNAME("disengageRequest") SEQ, 1, 6, 19, STOP | EXT, 0, NULL},
1904 {FNAME("disengageConfirm") SEQ, 1, 2, 9, STOP | EXT, 0, NULL},
1905 {FNAME("disengageReject") SEQ, 1, 3, 8, STOP | EXT, 0, NULL},
1906 {FNAME("locationRequest") SEQ, 2, 5, 17, DECODE | EXT,
1907 offsetof(RasMessage, locationRequest), _LocationRequest},
1908 {FNAME("locationConfirm") SEQ, 1, 4, 19, DECODE | EXT,
1909 offsetof(RasMessage, locationConfirm), _LocationConfirm},
1910 {FNAME("locationReject") SEQ, 1, 3, 10, STOP | EXT, 0, NULL},
1911 {FNAME("infoRequest") SEQ, 2, 4, 15, STOP | EXT, 0, NULL},
1912 {FNAME("infoRequestResponse") SEQ, 3, 8, 16, DECODE | EXT,
1913 offsetof(RasMessage, infoRequestResponse), _InfoRequestResponse},
1914 {FNAME("nonStandardMessage") SEQ, 0, 2, 7, STOP | EXT, 0, NULL},
1915 {FNAME("unknownMessageResponse") SEQ, 0, 1, 5, STOP | EXT, 0, NULL},
1916 {FNAME("requestInProgress") SEQ, 4, 6, 6, STOP | EXT, 0, NULL},
1917 {FNAME("resourcesAvailableIndicate") SEQ, 4, 9, 11, STOP | EXT, 0,
1918 NULL},
1919 {FNAME("resourcesAvailableConfirm") SEQ, 4, 6, 7, STOP | EXT, 0,
1920 NULL},
1921 {FNAME("infoRequestAck") SEQ, 4, 5, 5, STOP | EXT, 0, NULL},
1922 {FNAME("infoRequestNak") SEQ, 5, 7, 7, STOP | EXT, 0, NULL},
1923 {FNAME("serviceControlIndication") SEQ, 8, 10, 10, STOP | EXT, 0,
1924 NULL},
1925 {FNAME("serviceControlResponse") SEQ, 7, 8, 8, STOP | EXT, 0, NULL},
1926};
diff --git a/net/ipv4/netfilter/ip_conntrack_helper_h323_types.h b/net/ipv4/netfilter/ip_conntrack_helper_h323_types.h
new file mode 100644
index 000000000000..cc98f7aa5abe
--- /dev/null
+++ b/net/ipv4/netfilter/ip_conntrack_helper_h323_types.h
@@ -0,0 +1,938 @@
1/* Generated by Jing Min Zhao's ASN.1 parser, Mar 15 2006
2 *
3 * Copyright (c) 2006 Jing Min Zhao <zhaojingmin@users.sourceforge.net>
4 *
5 * This source code is licensed under General Public License version 2.
6 */
7
8typedef struct TransportAddress_ipAddress { /* SEQUENCE */
9 int options; /* No use */
10 unsigned ip;
11} TransportAddress_ipAddress;
12
13typedef struct TransportAddress { /* CHOICE */
14 enum {
15 eTransportAddress_ipAddress,
16 eTransportAddress_ipSourceRoute,
17 eTransportAddress_ipxAddress,
18 eTransportAddress_ip6Address,
19 eTransportAddress_netBios,
20 eTransportAddress_nsap,
21 eTransportAddress_nonStandardAddress,
22 } choice;
23 union {
24 TransportAddress_ipAddress ipAddress;
25 };
26} TransportAddress;
27
28typedef struct DataProtocolCapability { /* CHOICE */
29 enum {
30 eDataProtocolCapability_nonStandard,
31 eDataProtocolCapability_v14buffered,
32 eDataProtocolCapability_v42lapm,
33 eDataProtocolCapability_hdlcFrameTunnelling,
34 eDataProtocolCapability_h310SeparateVCStack,
35 eDataProtocolCapability_h310SingleVCStack,
36 eDataProtocolCapability_transparent,
37 eDataProtocolCapability_segmentationAndReassembly,
38 eDataProtocolCapability_hdlcFrameTunnelingwSAR,
39 eDataProtocolCapability_v120,
40 eDataProtocolCapability_separateLANStack,
41 eDataProtocolCapability_v76wCompression,
42 eDataProtocolCapability_tcp,
43 eDataProtocolCapability_udp,
44 } choice;
45} DataProtocolCapability;
46
47typedef struct DataApplicationCapability_application { /* CHOICE */
48 enum {
49 eDataApplicationCapability_application_nonStandard,
50 eDataApplicationCapability_application_t120,
51 eDataApplicationCapability_application_dsm_cc,
52 eDataApplicationCapability_application_userData,
53 eDataApplicationCapability_application_t84,
54 eDataApplicationCapability_application_t434,
55 eDataApplicationCapability_application_h224,
56 eDataApplicationCapability_application_nlpid,
57 eDataApplicationCapability_application_dsvdControl,
58 eDataApplicationCapability_application_h222DataPartitioning,
59 eDataApplicationCapability_application_t30fax,
60 eDataApplicationCapability_application_t140,
61 eDataApplicationCapability_application_t38fax,
62 eDataApplicationCapability_application_genericDataCapability,
63 } choice;
64 union {
65 DataProtocolCapability t120;
66 };
67} DataApplicationCapability_application;
68
69typedef struct DataApplicationCapability { /* SEQUENCE */
70 int options; /* No use */
71 DataApplicationCapability_application application;
72} DataApplicationCapability;
73
74typedef struct DataType { /* CHOICE */
75 enum {
76 eDataType_nonStandard,
77 eDataType_nullData,
78 eDataType_videoData,
79 eDataType_audioData,
80 eDataType_data,
81 eDataType_encryptionData,
82 eDataType_h235Control,
83 eDataType_h235Media,
84 eDataType_multiplexedStream,
85 } choice;
86 union {
87 DataApplicationCapability data;
88 };
89} DataType;
90
91typedef struct UnicastAddress_iPAddress { /* SEQUENCE */
92 int options; /* No use */
93 unsigned network;
94} UnicastAddress_iPAddress;
95
96typedef struct UnicastAddress { /* CHOICE */
97 enum {
98 eUnicastAddress_iPAddress,
99 eUnicastAddress_iPXAddress,
100 eUnicastAddress_iP6Address,
101 eUnicastAddress_netBios,
102 eUnicastAddress_iPSourceRouteAddress,
103 eUnicastAddress_nsap,
104 eUnicastAddress_nonStandardAddress,
105 } choice;
106 union {
107 UnicastAddress_iPAddress iPAddress;
108 };
109} UnicastAddress;
110
111typedef struct H245_TransportAddress { /* CHOICE */
112 enum {
113 eH245_TransportAddress_unicastAddress,
114 eH245_TransportAddress_multicastAddress,
115 } choice;
116 union {
117 UnicastAddress unicastAddress;
118 };
119} H245_TransportAddress;
120
121typedef struct H2250LogicalChannelParameters { /* SEQUENCE */
122 enum {
123 eH2250LogicalChannelParameters_nonStandard = (1 << 31),
124 eH2250LogicalChannelParameters_associatedSessionID =
125 (1 << 30),
126 eH2250LogicalChannelParameters_mediaChannel = (1 << 29),
127 eH2250LogicalChannelParameters_mediaGuaranteedDelivery =
128 (1 << 28),
129 eH2250LogicalChannelParameters_mediaControlChannel =
130 (1 << 27),
131 eH2250LogicalChannelParameters_mediaControlGuaranteedDelivery
132 = (1 << 26),
133 eH2250LogicalChannelParameters_silenceSuppression = (1 << 25),
134 eH2250LogicalChannelParameters_destination = (1 << 24),
135 eH2250LogicalChannelParameters_dynamicRTPPayloadType =
136 (1 << 23),
137 eH2250LogicalChannelParameters_mediaPacketization = (1 << 22),
138 eH2250LogicalChannelParameters_transportCapability =
139 (1 << 21),
140 eH2250LogicalChannelParameters_redundancyEncoding = (1 << 20),
141 eH2250LogicalChannelParameters_source = (1 << 19),
142 } options;
143 H245_TransportAddress mediaChannel;
144 H245_TransportAddress mediaControlChannel;
145} H2250LogicalChannelParameters;
146
147typedef struct OpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters { /* CHOICE */
148 enum {
149 eOpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters_h222LogicalChannelParameters,
150 eOpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters_h223LogicalChannelParameters,
151 eOpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters_v76LogicalChannelParameters,
152 eOpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters,
153 eOpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters_none,
154 } choice;
155 union {
156 H2250LogicalChannelParameters h2250LogicalChannelParameters;
157 };
158} OpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters;
159
160typedef struct OpenLogicalChannel_forwardLogicalChannelParameters { /* SEQUENCE */
161 enum {
162 eOpenLogicalChannel_forwardLogicalChannelParameters_portNumber
163 = (1 << 31),
164 eOpenLogicalChannel_forwardLogicalChannelParameters_forwardLogicalChannelDependency
165 = (1 << 30),
166 eOpenLogicalChannel_forwardLogicalChannelParameters_replacementFor
167 = (1 << 29),
168 } options;
169 DataType dataType;
170 OpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters
171 multiplexParameters;
172} OpenLogicalChannel_forwardLogicalChannelParameters;
173
174typedef struct OpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters { /* CHOICE */
175 enum {
176 eOpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters_h223LogicalChannelParameters,
177 eOpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters_v76LogicalChannelParameters,
178 eOpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters,
179 } choice;
180 union {
181 H2250LogicalChannelParameters h2250LogicalChannelParameters;
182 };
183} OpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters;
184
185typedef struct OpenLogicalChannel_reverseLogicalChannelParameters { /* SEQUENCE */
186 enum {
187 eOpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters
188 = (1 << 31),
189 eOpenLogicalChannel_reverseLogicalChannelParameters_reverseLogicalChannelDependency
190 = (1 << 30),
191 eOpenLogicalChannel_reverseLogicalChannelParameters_replacementFor
192 = (1 << 29),
193 } options;
194 OpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters
195 multiplexParameters;
196} OpenLogicalChannel_reverseLogicalChannelParameters;
197
198typedef struct NetworkAccessParameters_networkAddress { /* CHOICE */
199 enum {
200 eNetworkAccessParameters_networkAddress_q2931Address,
201 eNetworkAccessParameters_networkAddress_e164Address,
202 eNetworkAccessParameters_networkAddress_localAreaAddress,
203 } choice;
204 union {
205 H245_TransportAddress localAreaAddress;
206 };
207} NetworkAccessParameters_networkAddress;
208
209typedef struct NetworkAccessParameters { /* SEQUENCE */
210 enum {
211 eNetworkAccessParameters_distribution = (1 << 31),
212 eNetworkAccessParameters_externalReference = (1 << 30),
213 eNetworkAccessParameters_t120SetupProcedure = (1 << 29),
214 } options;
215 NetworkAccessParameters_networkAddress networkAddress;
216} NetworkAccessParameters;
217
218typedef struct OpenLogicalChannel { /* SEQUENCE */
219 enum {
220 eOpenLogicalChannel_reverseLogicalChannelParameters =
221 (1 << 31),
222 eOpenLogicalChannel_separateStack = (1 << 30),
223 eOpenLogicalChannel_encryptionSync = (1 << 29),
224 } options;
225 OpenLogicalChannel_forwardLogicalChannelParameters
226 forwardLogicalChannelParameters;
227 OpenLogicalChannel_reverseLogicalChannelParameters
228 reverseLogicalChannelParameters;
229 NetworkAccessParameters separateStack;
230} OpenLogicalChannel;
231
232typedef struct Setup_UUIE_fastStart { /* SEQUENCE OF */
233 int count;
234 OpenLogicalChannel item[30];
235} Setup_UUIE_fastStart;
236
237typedef struct Setup_UUIE { /* SEQUENCE */
238 enum {
239 eSetup_UUIE_h245Address = (1 << 31),
240 eSetup_UUIE_sourceAddress = (1 << 30),
241 eSetup_UUIE_destinationAddress = (1 << 29),
242 eSetup_UUIE_destCallSignalAddress = (1 << 28),
243 eSetup_UUIE_destExtraCallInfo = (1 << 27),
244 eSetup_UUIE_destExtraCRV = (1 << 26),
245 eSetup_UUIE_callServices = (1 << 25),
246 eSetup_UUIE_sourceCallSignalAddress = (1 << 24),
247 eSetup_UUIE_remoteExtensionAddress = (1 << 23),
248 eSetup_UUIE_callIdentifier = (1 << 22),
249 eSetup_UUIE_h245SecurityCapability = (1 << 21),
250 eSetup_UUIE_tokens = (1 << 20),
251 eSetup_UUIE_cryptoTokens = (1 << 19),
252 eSetup_UUIE_fastStart = (1 << 18),
253 eSetup_UUIE_mediaWaitForConnect = (1 << 17),
254 eSetup_UUIE_canOverlapSend = (1 << 16),
255 eSetup_UUIE_endpointIdentifier = (1 << 15),
256 eSetup_UUIE_multipleCalls = (1 << 14),
257 eSetup_UUIE_maintainConnection = (1 << 13),
258 eSetup_UUIE_connectionParameters = (1 << 12),
259 eSetup_UUIE_language = (1 << 11),
260 eSetup_UUIE_presentationIndicator = (1 << 10),
261 eSetup_UUIE_screeningIndicator = (1 << 9),
262 eSetup_UUIE_serviceControl = (1 << 8),
263 eSetup_UUIE_symmetricOperationRequired = (1 << 7),
264 eSetup_UUIE_capacity = (1 << 6),
265 eSetup_UUIE_circuitInfo = (1 << 5),
266 eSetup_UUIE_desiredProtocols = (1 << 4),
267 eSetup_UUIE_neededFeatures = (1 << 3),
268 eSetup_UUIE_desiredFeatures = (1 << 2),
269 eSetup_UUIE_supportedFeatures = (1 << 1),
270 eSetup_UUIE_parallelH245Control = (1 << 0),
271 } options;
272 TransportAddress h245Address;
273 TransportAddress destCallSignalAddress;
274 TransportAddress sourceCallSignalAddress;
275 Setup_UUIE_fastStart fastStart;
276} Setup_UUIE;
277
278typedef struct CallProceeding_UUIE_fastStart { /* SEQUENCE OF */
279 int count;
280 OpenLogicalChannel item[30];
281} CallProceeding_UUIE_fastStart;
282
283typedef struct CallProceeding_UUIE { /* SEQUENCE */
284 enum {
285 eCallProceeding_UUIE_h245Address = (1 << 31),
286 eCallProceeding_UUIE_callIdentifier = (1 << 30),
287 eCallProceeding_UUIE_h245SecurityMode = (1 << 29),
288 eCallProceeding_UUIE_tokens = (1 << 28),
289 eCallProceeding_UUIE_cryptoTokens = (1 << 27),
290 eCallProceeding_UUIE_fastStart = (1 << 26),
291 eCallProceeding_UUIE_multipleCalls = (1 << 25),
292 eCallProceeding_UUIE_maintainConnection = (1 << 24),
293 eCallProceeding_UUIE_fastConnectRefused = (1 << 23),
294 eCallProceeding_UUIE_featureSet = (1 << 22),
295 } options;
296 TransportAddress h245Address;
297 CallProceeding_UUIE_fastStart fastStart;
298} CallProceeding_UUIE;
299
300typedef struct Connect_UUIE_fastStart { /* SEQUENCE OF */
301 int count;
302 OpenLogicalChannel item[30];
303} Connect_UUIE_fastStart;
304
305typedef struct Connect_UUIE { /* SEQUENCE */
306 enum {
307 eConnect_UUIE_h245Address = (1 << 31),
308 eConnect_UUIE_callIdentifier = (1 << 30),
309 eConnect_UUIE_h245SecurityMode = (1 << 29),
310 eConnect_UUIE_tokens = (1 << 28),
311 eConnect_UUIE_cryptoTokens = (1 << 27),
312 eConnect_UUIE_fastStart = (1 << 26),
313 eConnect_UUIE_multipleCalls = (1 << 25),
314 eConnect_UUIE_maintainConnection = (1 << 24),
315 eConnect_UUIE_language = (1 << 23),
316 eConnect_UUIE_connectedAddress = (1 << 22),
317 eConnect_UUIE_presentationIndicator = (1 << 21),
318 eConnect_UUIE_screeningIndicator = (1 << 20),
319 eConnect_UUIE_fastConnectRefused = (1 << 19),
320 eConnect_UUIE_serviceControl = (1 << 18),
321 eConnect_UUIE_capacity = (1 << 17),
322 eConnect_UUIE_featureSet = (1 << 16),
323 } options;
324 TransportAddress h245Address;
325 Connect_UUIE_fastStart fastStart;
326} Connect_UUIE;
327
328typedef struct Alerting_UUIE_fastStart { /* SEQUENCE OF */
329 int count;
330 OpenLogicalChannel item[30];
331} Alerting_UUIE_fastStart;
332
333typedef struct Alerting_UUIE { /* SEQUENCE */
334 enum {
335 eAlerting_UUIE_h245Address = (1 << 31),
336 eAlerting_UUIE_callIdentifier = (1 << 30),
337 eAlerting_UUIE_h245SecurityMode = (1 << 29),
338 eAlerting_UUIE_tokens = (1 << 28),
339 eAlerting_UUIE_cryptoTokens = (1 << 27),
340 eAlerting_UUIE_fastStart = (1 << 26),
341 eAlerting_UUIE_multipleCalls = (1 << 25),
342 eAlerting_UUIE_maintainConnection = (1 << 24),
343 eAlerting_UUIE_alertingAddress = (1 << 23),
344 eAlerting_UUIE_presentationIndicator = (1 << 22),
345 eAlerting_UUIE_screeningIndicator = (1 << 21),
346 eAlerting_UUIE_fastConnectRefused = (1 << 20),
347 eAlerting_UUIE_serviceControl = (1 << 19),
348 eAlerting_UUIE_capacity = (1 << 18),
349 eAlerting_UUIE_featureSet = (1 << 17),
350 } options;
351 TransportAddress h245Address;
352 Alerting_UUIE_fastStart fastStart;
353} Alerting_UUIE;
354
355typedef struct Information_UUIE_fastStart { /* SEQUENCE OF */
356 int count;
357 OpenLogicalChannel item[30];
358} Information_UUIE_fastStart;
359
360typedef struct Information_UUIE { /* SEQUENCE */
361 enum {
362 eInformation_UUIE_callIdentifier = (1 << 31),
363 eInformation_UUIE_tokens = (1 << 30),
364 eInformation_UUIE_cryptoTokens = (1 << 29),
365 eInformation_UUIE_fastStart = (1 << 28),
366 eInformation_UUIE_fastConnectRefused = (1 << 27),
367 eInformation_UUIE_circuitInfo = (1 << 26),
368 } options;
369 Information_UUIE_fastStart fastStart;
370} Information_UUIE;
371
372typedef struct FacilityReason { /* CHOICE */
373 enum {
374 eFacilityReason_routeCallToGatekeeper,
375 eFacilityReason_callForwarded,
376 eFacilityReason_routeCallToMC,
377 eFacilityReason_undefinedReason,
378 eFacilityReason_conferenceListChoice,
379 eFacilityReason_startH245,
380 eFacilityReason_noH245,
381 eFacilityReason_newTokens,
382 eFacilityReason_featureSetUpdate,
383 eFacilityReason_forwardedElements,
384 eFacilityReason_transportedInformation,
385 } choice;
386} FacilityReason;
387
388typedef struct Facility_UUIE_fastStart { /* SEQUENCE OF */
389 int count;
390 OpenLogicalChannel item[30];
391} Facility_UUIE_fastStart;
392
393typedef struct Facility_UUIE { /* SEQUENCE */
394 enum {
395 eFacility_UUIE_alternativeAddress = (1 << 31),
396 eFacility_UUIE_alternativeAliasAddress = (1 << 30),
397 eFacility_UUIE_conferenceID = (1 << 29),
398 eFacility_UUIE_callIdentifier = (1 << 28),
399 eFacility_UUIE_destExtraCallInfo = (1 << 27),
400 eFacility_UUIE_remoteExtensionAddress = (1 << 26),
401 eFacility_UUIE_tokens = (1 << 25),
402 eFacility_UUIE_cryptoTokens = (1 << 24),
403 eFacility_UUIE_conferences = (1 << 23),
404 eFacility_UUIE_h245Address = (1 << 22),
405 eFacility_UUIE_fastStart = (1 << 21),
406 eFacility_UUIE_multipleCalls = (1 << 20),
407 eFacility_UUIE_maintainConnection = (1 << 19),
408 eFacility_UUIE_fastConnectRefused = (1 << 18),
409 eFacility_UUIE_serviceControl = (1 << 17),
410 eFacility_UUIE_circuitInfo = (1 << 16),
411 eFacility_UUIE_featureSet = (1 << 15),
412 eFacility_UUIE_destinationInfo = (1 << 14),
413 eFacility_UUIE_h245SecurityMode = (1 << 13),
414 } options;
415 FacilityReason reason;
416 TransportAddress h245Address;
417 Facility_UUIE_fastStart fastStart;
418} Facility_UUIE;
419
420typedef struct Progress_UUIE_fastStart { /* SEQUENCE OF */
421 int count;
422 OpenLogicalChannel item[30];
423} Progress_UUIE_fastStart;
424
425typedef struct Progress_UUIE { /* SEQUENCE */
426 enum {
427 eProgress_UUIE_h245Address = (1 << 31),
428 eProgress_UUIE_h245SecurityMode = (1 << 30),
429 eProgress_UUIE_tokens = (1 << 29),
430 eProgress_UUIE_cryptoTokens = (1 << 28),
431 eProgress_UUIE_fastStart = (1 << 27),
432 eProgress_UUIE_multipleCalls = (1 << 26),
433 eProgress_UUIE_maintainConnection = (1 << 25),
434 eProgress_UUIE_fastConnectRefused = (1 << 24),
435 } options;
436 TransportAddress h245Address;
437 Progress_UUIE_fastStart fastStart;
438} Progress_UUIE;
439
440typedef struct H323_UU_PDU_h323_message_body { /* CHOICE */
441 enum {
442 eH323_UU_PDU_h323_message_body_setup,
443 eH323_UU_PDU_h323_message_body_callProceeding,
444 eH323_UU_PDU_h323_message_body_connect,
445 eH323_UU_PDU_h323_message_body_alerting,
446 eH323_UU_PDU_h323_message_body_information,
447 eH323_UU_PDU_h323_message_body_releaseComplete,
448 eH323_UU_PDU_h323_message_body_facility,
449 eH323_UU_PDU_h323_message_body_progress,
450 eH323_UU_PDU_h323_message_body_empty,
451 eH323_UU_PDU_h323_message_body_status,
452 eH323_UU_PDU_h323_message_body_statusInquiry,
453 eH323_UU_PDU_h323_message_body_setupAcknowledge,
454 eH323_UU_PDU_h323_message_body_notify,
455 } choice;
456 union {
457 Setup_UUIE setup;
458 CallProceeding_UUIE callProceeding;
459 Connect_UUIE connect;
460 Alerting_UUIE alerting;
461 Information_UUIE information;
462 Facility_UUIE facility;
463 Progress_UUIE progress;
464 };
465} H323_UU_PDU_h323_message_body;
466
467typedef struct RequestMessage { /* CHOICE */
468 enum {
469 eRequestMessage_nonStandard,
470 eRequestMessage_masterSlaveDetermination,
471 eRequestMessage_terminalCapabilitySet,
472 eRequestMessage_openLogicalChannel,
473 eRequestMessage_closeLogicalChannel,
474 eRequestMessage_requestChannelClose,
475 eRequestMessage_multiplexEntrySend,
476 eRequestMessage_requestMultiplexEntry,
477 eRequestMessage_requestMode,
478 eRequestMessage_roundTripDelayRequest,
479 eRequestMessage_maintenanceLoopRequest,
480 eRequestMessage_communicationModeRequest,
481 eRequestMessage_conferenceRequest,
482 eRequestMessage_multilinkRequest,
483 eRequestMessage_logicalChannelRateRequest,
484 } choice;
485 union {
486 OpenLogicalChannel openLogicalChannel;
487 };
488} RequestMessage;
489
490typedef struct OpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters { /* CHOICE */
491 enum {
492 eOpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters_h222LogicalChannelParameters,
493 eOpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters,
494 } choice;
495 union {
496 H2250LogicalChannelParameters h2250LogicalChannelParameters;
497 };
498} OpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters;
499
500typedef struct OpenLogicalChannelAck_reverseLogicalChannelParameters { /* SEQUENCE */
501 enum {
502 eOpenLogicalChannelAck_reverseLogicalChannelParameters_portNumber
503 = (1 << 31),
504 eOpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters
505 = (1 << 30),
506 eOpenLogicalChannelAck_reverseLogicalChannelParameters_replacementFor
507 = (1 << 29),
508 } options;
509 OpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters
510 multiplexParameters;
511} OpenLogicalChannelAck_reverseLogicalChannelParameters;
512
513typedef struct H2250LogicalChannelAckParameters { /* SEQUENCE */
514 enum {
515 eH2250LogicalChannelAckParameters_nonStandard = (1 << 31),
516 eH2250LogicalChannelAckParameters_sessionID = (1 << 30),
517 eH2250LogicalChannelAckParameters_mediaChannel = (1 << 29),
518 eH2250LogicalChannelAckParameters_mediaControlChannel =
519 (1 << 28),
520 eH2250LogicalChannelAckParameters_dynamicRTPPayloadType =
521 (1 << 27),
522 eH2250LogicalChannelAckParameters_flowControlToZero =
523 (1 << 26),
524 eH2250LogicalChannelAckParameters_portNumber = (1 << 25),
525 } options;
526 H245_TransportAddress mediaChannel;
527 H245_TransportAddress mediaControlChannel;
528} H2250LogicalChannelAckParameters;
529
530typedef struct OpenLogicalChannelAck_forwardMultiplexAckParameters { /* CHOICE */
531 enum {
532 eOpenLogicalChannelAck_forwardMultiplexAckParameters_h2250LogicalChannelAckParameters,
533 } choice;
534 union {
535 H2250LogicalChannelAckParameters
536 h2250LogicalChannelAckParameters;
537 };
538} OpenLogicalChannelAck_forwardMultiplexAckParameters;
539
540typedef struct OpenLogicalChannelAck { /* SEQUENCE */
541 enum {
542 eOpenLogicalChannelAck_reverseLogicalChannelParameters =
543 (1 << 31),
544 eOpenLogicalChannelAck_separateStack = (1 << 30),
545 eOpenLogicalChannelAck_forwardMultiplexAckParameters =
546 (1 << 29),
547 eOpenLogicalChannelAck_encryptionSync = (1 << 28),
548 } options;
549 OpenLogicalChannelAck_reverseLogicalChannelParameters
550 reverseLogicalChannelParameters;
551 OpenLogicalChannelAck_forwardMultiplexAckParameters
552 forwardMultiplexAckParameters;
553} OpenLogicalChannelAck;
554
555typedef struct ResponseMessage { /* CHOICE */
556 enum {
557 eResponseMessage_nonStandard,
558 eResponseMessage_masterSlaveDeterminationAck,
559 eResponseMessage_masterSlaveDeterminationReject,
560 eResponseMessage_terminalCapabilitySetAck,
561 eResponseMessage_terminalCapabilitySetReject,
562 eResponseMessage_openLogicalChannelAck,
563 eResponseMessage_openLogicalChannelReject,
564 eResponseMessage_closeLogicalChannelAck,
565 eResponseMessage_requestChannelCloseAck,
566 eResponseMessage_requestChannelCloseReject,
567 eResponseMessage_multiplexEntrySendAck,
568 eResponseMessage_multiplexEntrySendReject,
569 eResponseMessage_requestMultiplexEntryAck,
570 eResponseMessage_requestMultiplexEntryReject,
571 eResponseMessage_requestModeAck,
572 eResponseMessage_requestModeReject,
573 eResponseMessage_roundTripDelayResponse,
574 eResponseMessage_maintenanceLoopAck,
575 eResponseMessage_maintenanceLoopReject,
576 eResponseMessage_communicationModeResponse,
577 eResponseMessage_conferenceResponse,
578 eResponseMessage_multilinkResponse,
579 eResponseMessage_logicalChannelRateAcknowledge,
580 eResponseMessage_logicalChannelRateReject,
581 } choice;
582 union {
583 OpenLogicalChannelAck openLogicalChannelAck;
584 };
585} ResponseMessage;
586
587typedef struct MultimediaSystemControlMessage { /* CHOICE */
588 enum {
589 eMultimediaSystemControlMessage_request,
590 eMultimediaSystemControlMessage_response,
591 eMultimediaSystemControlMessage_command,
592 eMultimediaSystemControlMessage_indication,
593 } choice;
594 union {
595 RequestMessage request;
596 ResponseMessage response;
597 };
598} MultimediaSystemControlMessage;
599
600typedef struct H323_UU_PDU_h245Control { /* SEQUENCE OF */
601 int count;
602 MultimediaSystemControlMessage item[4];
603} H323_UU_PDU_h245Control;
604
605typedef struct H323_UU_PDU { /* SEQUENCE */
606 enum {
607 eH323_UU_PDU_nonStandardData = (1 << 31),
608 eH323_UU_PDU_h4501SupplementaryService = (1 << 30),
609 eH323_UU_PDU_h245Tunneling = (1 << 29),
610 eH323_UU_PDU_h245Control = (1 << 28),
611 eH323_UU_PDU_nonStandardControl = (1 << 27),
612 eH323_UU_PDU_callLinkage = (1 << 26),
613 eH323_UU_PDU_tunnelledSignallingMessage = (1 << 25),
614 eH323_UU_PDU_provisionalRespToH245Tunneling = (1 << 24),
615 eH323_UU_PDU_stimulusControl = (1 << 23),
616 eH323_UU_PDU_genericData = (1 << 22),
617 } options;
618 H323_UU_PDU_h323_message_body h323_message_body;
619 H323_UU_PDU_h245Control h245Control;
620} H323_UU_PDU;
621
622typedef struct H323_UserInformation { /* SEQUENCE */
623 enum {
624 eH323_UserInformation_user_data = (1 << 31),
625 } options;
626 H323_UU_PDU h323_uu_pdu;
627} H323_UserInformation;
628
629typedef struct GatekeeperRequest { /* SEQUENCE */
630 enum {
631 eGatekeeperRequest_nonStandardData = (1 << 31),
632 eGatekeeperRequest_gatekeeperIdentifier = (1 << 30),
633 eGatekeeperRequest_callServices = (1 << 29),
634 eGatekeeperRequest_endpointAlias = (1 << 28),
635 eGatekeeperRequest_alternateEndpoints = (1 << 27),
636 eGatekeeperRequest_tokens = (1 << 26),
637 eGatekeeperRequest_cryptoTokens = (1 << 25),
638 eGatekeeperRequest_authenticationCapability = (1 << 24),
639 eGatekeeperRequest_algorithmOIDs = (1 << 23),
640 eGatekeeperRequest_integrity = (1 << 22),
641 eGatekeeperRequest_integrityCheckValue = (1 << 21),
642 eGatekeeperRequest_supportsAltGK = (1 << 20),
643 eGatekeeperRequest_featureSet = (1 << 19),
644 eGatekeeperRequest_genericData = (1 << 18),
645 } options;
646 TransportAddress rasAddress;
647} GatekeeperRequest;
648
649typedef struct GatekeeperConfirm { /* SEQUENCE */
650 enum {
651 eGatekeeperConfirm_nonStandardData = (1 << 31),
652 eGatekeeperConfirm_gatekeeperIdentifier = (1 << 30),
653 eGatekeeperConfirm_alternateGatekeeper = (1 << 29),
654 eGatekeeperConfirm_authenticationMode = (1 << 28),
655 eGatekeeperConfirm_tokens = (1 << 27),
656 eGatekeeperConfirm_cryptoTokens = (1 << 26),
657 eGatekeeperConfirm_algorithmOID = (1 << 25),
658 eGatekeeperConfirm_integrity = (1 << 24),
659 eGatekeeperConfirm_integrityCheckValue = (1 << 23),
660 eGatekeeperConfirm_featureSet = (1 << 22),
661 eGatekeeperConfirm_genericData = (1 << 21),
662 } options;
663 TransportAddress rasAddress;
664} GatekeeperConfirm;
665
666typedef struct RegistrationRequest_callSignalAddress { /* SEQUENCE OF */
667 int count;
668 TransportAddress item[10];
669} RegistrationRequest_callSignalAddress;
670
671typedef struct RegistrationRequest_rasAddress { /* SEQUENCE OF */
672 int count;
673 TransportAddress item[10];
674} RegistrationRequest_rasAddress;
675
676typedef struct RegistrationRequest { /* SEQUENCE */
677 enum {
678 eRegistrationRequest_nonStandardData = (1 << 31),
679 eRegistrationRequest_terminalAlias = (1 << 30),
680 eRegistrationRequest_gatekeeperIdentifier = (1 << 29),
681 eRegistrationRequest_alternateEndpoints = (1 << 28),
682 eRegistrationRequest_timeToLive = (1 << 27),
683 eRegistrationRequest_tokens = (1 << 26),
684 eRegistrationRequest_cryptoTokens = (1 << 25),
685 eRegistrationRequest_integrityCheckValue = (1 << 24),
686 eRegistrationRequest_keepAlive = (1 << 23),
687 eRegistrationRequest_endpointIdentifier = (1 << 22),
688 eRegistrationRequest_willSupplyUUIEs = (1 << 21),
689 eRegistrationRequest_maintainConnection = (1 << 20),
690 eRegistrationRequest_alternateTransportAddresses = (1 << 19),
691 eRegistrationRequest_additiveRegistration = (1 << 18),
692 eRegistrationRequest_terminalAliasPattern = (1 << 17),
693 eRegistrationRequest_supportsAltGK = (1 << 16),
694 eRegistrationRequest_usageReportingCapability = (1 << 15),
695 eRegistrationRequest_multipleCalls = (1 << 14),
696 eRegistrationRequest_supportedH248Packages = (1 << 13),
697 eRegistrationRequest_callCreditCapability = (1 << 12),
698 eRegistrationRequest_capacityReportingCapability = (1 << 11),
699 eRegistrationRequest_capacity = (1 << 10),
700 eRegistrationRequest_featureSet = (1 << 9),
701 eRegistrationRequest_genericData = (1 << 8),
702 } options;
703 RegistrationRequest_callSignalAddress callSignalAddress;
704 RegistrationRequest_rasAddress rasAddress;
705 unsigned timeToLive;
706} RegistrationRequest;
707
708typedef struct RegistrationConfirm_callSignalAddress { /* SEQUENCE OF */
709 int count;
710 TransportAddress item[10];
711} RegistrationConfirm_callSignalAddress;
712
713typedef struct RegistrationConfirm { /* SEQUENCE */
714 enum {
715 eRegistrationConfirm_nonStandardData = (1 << 31),
716 eRegistrationConfirm_terminalAlias = (1 << 30),
717 eRegistrationConfirm_gatekeeperIdentifier = (1 << 29),
718 eRegistrationConfirm_alternateGatekeeper = (1 << 28),
719 eRegistrationConfirm_timeToLive = (1 << 27),
720 eRegistrationConfirm_tokens = (1 << 26),
721 eRegistrationConfirm_cryptoTokens = (1 << 25),
722 eRegistrationConfirm_integrityCheckValue = (1 << 24),
723 eRegistrationConfirm_willRespondToIRR = (1 << 23),
724 eRegistrationConfirm_preGrantedARQ = (1 << 22),
725 eRegistrationConfirm_maintainConnection = (1 << 21),
726 eRegistrationConfirm_serviceControl = (1 << 20),
727 eRegistrationConfirm_supportsAdditiveRegistration = (1 << 19),
728 eRegistrationConfirm_terminalAliasPattern = (1 << 18),
729 eRegistrationConfirm_supportedPrefixes = (1 << 17),
730 eRegistrationConfirm_usageSpec = (1 << 16),
731 eRegistrationConfirm_featureServerAlias = (1 << 15),
732 eRegistrationConfirm_capacityReportingSpec = (1 << 14),
733 eRegistrationConfirm_featureSet = (1 << 13),
734 eRegistrationConfirm_genericData = (1 << 12),
735 } options;
736 RegistrationConfirm_callSignalAddress callSignalAddress;
737 unsigned timeToLive;
738} RegistrationConfirm;
739
740typedef struct UnregistrationRequest_callSignalAddress { /* SEQUENCE OF */
741 int count;
742 TransportAddress item[10];
743} UnregistrationRequest_callSignalAddress;
744
745typedef struct UnregistrationRequest { /* SEQUENCE */
746 enum {
747 eUnregistrationRequest_endpointAlias = (1 << 31),
748 eUnregistrationRequest_nonStandardData = (1 << 30),
749 eUnregistrationRequest_endpointIdentifier = (1 << 29),
750 eUnregistrationRequest_alternateEndpoints = (1 << 28),
751 eUnregistrationRequest_gatekeeperIdentifier = (1 << 27),
752 eUnregistrationRequest_tokens = (1 << 26),
753 eUnregistrationRequest_cryptoTokens = (1 << 25),
754 eUnregistrationRequest_integrityCheckValue = (1 << 24),
755 eUnregistrationRequest_reason = (1 << 23),
756 eUnregistrationRequest_endpointAliasPattern = (1 << 22),
757 eUnregistrationRequest_supportedPrefixes = (1 << 21),
758 eUnregistrationRequest_alternateGatekeeper = (1 << 20),
759 eUnregistrationRequest_genericData = (1 << 19),
760 } options;
761 UnregistrationRequest_callSignalAddress callSignalAddress;
762} UnregistrationRequest;
763
764typedef struct AdmissionRequest { /* SEQUENCE */
765 enum {
766 eAdmissionRequest_callModel = (1 << 31),
767 eAdmissionRequest_destinationInfo = (1 << 30),
768 eAdmissionRequest_destCallSignalAddress = (1 << 29),
769 eAdmissionRequest_destExtraCallInfo = (1 << 28),
770 eAdmissionRequest_srcCallSignalAddress = (1 << 27),
771 eAdmissionRequest_nonStandardData = (1 << 26),
772 eAdmissionRequest_callServices = (1 << 25),
773 eAdmissionRequest_canMapAlias = (1 << 24),
774 eAdmissionRequest_callIdentifier = (1 << 23),
775 eAdmissionRequest_srcAlternatives = (1 << 22),
776 eAdmissionRequest_destAlternatives = (1 << 21),
777 eAdmissionRequest_gatekeeperIdentifier = (1 << 20),
778 eAdmissionRequest_tokens = (1 << 19),
779 eAdmissionRequest_cryptoTokens = (1 << 18),
780 eAdmissionRequest_integrityCheckValue = (1 << 17),
781 eAdmissionRequest_transportQOS = (1 << 16),
782 eAdmissionRequest_willSupplyUUIEs = (1 << 15),
783 eAdmissionRequest_callLinkage = (1 << 14),
784 eAdmissionRequest_gatewayDataRate = (1 << 13),
785 eAdmissionRequest_capacity = (1 << 12),
786 eAdmissionRequest_circuitInfo = (1 << 11),
787 eAdmissionRequest_desiredProtocols = (1 << 10),
788 eAdmissionRequest_desiredTunnelledProtocol = (1 << 9),
789 eAdmissionRequest_featureSet = (1 << 8),
790 eAdmissionRequest_genericData = (1 << 7),
791 } options;
792 TransportAddress destCallSignalAddress;
793 TransportAddress srcCallSignalAddress;
794} AdmissionRequest;
795
796typedef struct AdmissionConfirm { /* SEQUENCE */
797 enum {
798 eAdmissionConfirm_irrFrequency = (1 << 31),
799 eAdmissionConfirm_nonStandardData = (1 << 30),
800 eAdmissionConfirm_destinationInfo = (1 << 29),
801 eAdmissionConfirm_destExtraCallInfo = (1 << 28),
802 eAdmissionConfirm_destinationType = (1 << 27),
803 eAdmissionConfirm_remoteExtensionAddress = (1 << 26),
804 eAdmissionConfirm_alternateEndpoints = (1 << 25),
805 eAdmissionConfirm_tokens = (1 << 24),
806 eAdmissionConfirm_cryptoTokens = (1 << 23),
807 eAdmissionConfirm_integrityCheckValue = (1 << 22),
808 eAdmissionConfirm_transportQOS = (1 << 21),
809 eAdmissionConfirm_willRespondToIRR = (1 << 20),
810 eAdmissionConfirm_uuiesRequested = (1 << 19),
811 eAdmissionConfirm_language = (1 << 18),
812 eAdmissionConfirm_alternateTransportAddresses = (1 << 17),
813 eAdmissionConfirm_useSpecifiedTransport = (1 << 16),
814 eAdmissionConfirm_circuitInfo = (1 << 15),
815 eAdmissionConfirm_usageSpec = (1 << 14),
816 eAdmissionConfirm_supportedProtocols = (1 << 13),
817 eAdmissionConfirm_serviceControl = (1 << 12),
818 eAdmissionConfirm_multipleCalls = (1 << 11),
819 eAdmissionConfirm_featureSet = (1 << 10),
820 eAdmissionConfirm_genericData = (1 << 9),
821 } options;
822 TransportAddress destCallSignalAddress;
823} AdmissionConfirm;
824
825typedef struct LocationRequest { /* SEQUENCE */
826 enum {
827 eLocationRequest_endpointIdentifier = (1 << 31),
828 eLocationRequest_nonStandardData = (1 << 30),
829 eLocationRequest_sourceInfo = (1 << 29),
830 eLocationRequest_canMapAlias = (1 << 28),
831 eLocationRequest_gatekeeperIdentifier = (1 << 27),
832 eLocationRequest_tokens = (1 << 26),
833 eLocationRequest_cryptoTokens = (1 << 25),
834 eLocationRequest_integrityCheckValue = (1 << 24),
835 eLocationRequest_desiredProtocols = (1 << 23),
836 eLocationRequest_desiredTunnelledProtocol = (1 << 22),
837 eLocationRequest_featureSet = (1 << 21),
838 eLocationRequest_genericData = (1 << 20),
839 eLocationRequest_hopCount = (1 << 19),
840 eLocationRequest_circuitInfo = (1 << 18),
841 } options;
842 TransportAddress replyAddress;
843} LocationRequest;
844
845typedef struct LocationConfirm { /* SEQUENCE */
846 enum {
847 eLocationConfirm_nonStandardData = (1 << 31),
848 eLocationConfirm_destinationInfo = (1 << 30),
849 eLocationConfirm_destExtraCallInfo = (1 << 29),
850 eLocationConfirm_destinationType = (1 << 28),
851 eLocationConfirm_remoteExtensionAddress = (1 << 27),
852 eLocationConfirm_alternateEndpoints = (1 << 26),
853 eLocationConfirm_tokens = (1 << 25),
854 eLocationConfirm_cryptoTokens = (1 << 24),
855 eLocationConfirm_integrityCheckValue = (1 << 23),
856 eLocationConfirm_alternateTransportAddresses = (1 << 22),
857 eLocationConfirm_supportedProtocols = (1 << 21),
858 eLocationConfirm_multipleCalls = (1 << 20),
859 eLocationConfirm_featureSet = (1 << 19),
860 eLocationConfirm_genericData = (1 << 18),
861 eLocationConfirm_circuitInfo = (1 << 17),
862 eLocationConfirm_serviceControl = (1 << 16),
863 } options;
864 TransportAddress callSignalAddress;
865 TransportAddress rasAddress;
866} LocationConfirm;
867
868typedef struct InfoRequestResponse_callSignalAddress { /* SEQUENCE OF */
869 int count;
870 TransportAddress item[10];
871} InfoRequestResponse_callSignalAddress;
872
873typedef struct InfoRequestResponse { /* SEQUENCE */
874 enum {
875 eInfoRequestResponse_nonStandardData = (1 << 31),
876 eInfoRequestResponse_endpointAlias = (1 << 30),
877 eInfoRequestResponse_perCallInfo = (1 << 29),
878 eInfoRequestResponse_tokens = (1 << 28),
879 eInfoRequestResponse_cryptoTokens = (1 << 27),
880 eInfoRequestResponse_integrityCheckValue = (1 << 26),
881 eInfoRequestResponse_needResponse = (1 << 25),
882 eInfoRequestResponse_capacity = (1 << 24),
883 eInfoRequestResponse_irrStatus = (1 << 23),
884 eInfoRequestResponse_unsolicited = (1 << 22),
885 eInfoRequestResponse_genericData = (1 << 21),
886 } options;
887 TransportAddress rasAddress;
888 InfoRequestResponse_callSignalAddress callSignalAddress;
889} InfoRequestResponse;
890
891typedef struct RasMessage { /* CHOICE */
892 enum {
893 eRasMessage_gatekeeperRequest,
894 eRasMessage_gatekeeperConfirm,
895 eRasMessage_gatekeeperReject,
896 eRasMessage_registrationRequest,
897 eRasMessage_registrationConfirm,
898 eRasMessage_registrationReject,
899 eRasMessage_unregistrationRequest,
900 eRasMessage_unregistrationConfirm,
901 eRasMessage_unregistrationReject,
902 eRasMessage_admissionRequest,
903 eRasMessage_admissionConfirm,
904 eRasMessage_admissionReject,
905 eRasMessage_bandwidthRequest,
906 eRasMessage_bandwidthConfirm,
907 eRasMessage_bandwidthReject,
908 eRasMessage_disengageRequest,
909 eRasMessage_disengageConfirm,
910 eRasMessage_disengageReject,
911 eRasMessage_locationRequest,
912 eRasMessage_locationConfirm,
913 eRasMessage_locationReject,
914 eRasMessage_infoRequest,
915 eRasMessage_infoRequestResponse,
916 eRasMessage_nonStandardMessage,
917 eRasMessage_unknownMessageResponse,
918 eRasMessage_requestInProgress,
919 eRasMessage_resourcesAvailableIndicate,
920 eRasMessage_resourcesAvailableConfirm,
921 eRasMessage_infoRequestAck,
922 eRasMessage_infoRequestNak,
923 eRasMessage_serviceControlIndication,
924 eRasMessage_serviceControlResponse,
925 } choice;
926 union {
927 GatekeeperRequest gatekeeperRequest;
928 GatekeeperConfirm gatekeeperConfirm;
929 RegistrationRequest registrationRequest;
930 RegistrationConfirm registrationConfirm;
931 UnregistrationRequest unregistrationRequest;
932 AdmissionRequest admissionRequest;
933 AdmissionConfirm admissionConfirm;
934 LocationRequest locationRequest;
935 LocationConfirm locationConfirm;
936 InfoRequestResponse infoRequestResponse;
937 };
938} RasMessage;
diff --git a/net/ipv4/netfilter/ip_conntrack_netlink.c b/net/ipv4/netfilter/ip_conntrack_netlink.c
index e0b5926c76f9..5ce2e3fc2c7f 100644
--- a/net/ipv4/netfilter/ip_conntrack_netlink.c
+++ b/net/ipv4/netfilter/ip_conntrack_netlink.c
@@ -327,9 +327,10 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
327 group = NFNLGRP_CONNTRACK_UPDATE; 327 group = NFNLGRP_CONNTRACK_UPDATE;
328 } else 328 } else
329 return NOTIFY_DONE; 329 return NOTIFY_DONE;
330 330
331 /* FIXME: Check if there are any listeners before, don't hurt performance */ 331 if (!nfnetlink_has_listeners(group))
332 332 return NOTIFY_DONE;
333
333 skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC); 334 skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
334 if (!skb) 335 if (!skb)
335 return NOTIFY_DONE; 336 return NOTIFY_DONE;
diff --git a/net/ipv4/netfilter/ip_nat_helper_h323.c b/net/ipv4/netfilter/ip_nat_helper_h323.c
new file mode 100644
index 000000000000..a0bc883928c0
--- /dev/null
+++ b/net/ipv4/netfilter/ip_nat_helper_h323.c
@@ -0,0 +1,605 @@
1/*
2 * H.323 extension for NAT alteration.
3 *
4 * Copyright (c) 2006 Jing Min Zhao <zhaojingmin@users.sourceforge.net>
5 *
6 * This source code is licensed under General Public License version 2.
7 *
8 * Based on the 'brute force' H.323 NAT module by
9 * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
10 *
11 * Changes:
12 * 2006-02-01 - initial version 0.1
13 *
14 * 2006-02-20 - version 0.2
15 * 1. Changed source format to follow kernel conventions
16 * 2. Deleted some unnecessary structures
17 * 3. Minor fixes
18 *
19 * 2006-03-10 - version 0.3
20 * 1. Added support for multiple TPKTs in one packet (suggested by
21 * Patrick McHardy)
22 * 2. Added support for non-linear skb (based on Patrick McHardy's patch)
23 * 3. Eliminated unnecessary return code
24 *
25 * 2006-03-15 - version 0.4
26 * 1. Added support for T.120 channels
27 * 2. Added parameter gkrouted_only (suggested by Patrick McHardy)
28 */
29
30#include <linux/module.h>
31#include <linux/netfilter_ipv4.h>
32#include <linux/netfilter.h>
33#include <linux/ip.h>
34#include <linux/tcp.h>
35#include <linux/moduleparam.h>
36#include <net/tcp.h>
37#include <linux/netfilter_ipv4/ip_nat.h>
38#include <linux/netfilter_ipv4/ip_nat_helper.h>
39#include <linux/netfilter_ipv4/ip_nat_rule.h>
40#include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
41#include <linux/netfilter_ipv4/ip_conntrack_h323.h>
42#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
43
44#include "ip_conntrack_helper_h323_asn1.h"
45
46#if 0
47#define DEBUGP printk
48#else
49#define DEBUGP(format, args...)
50#endif
51
52extern int get_h245_addr(unsigned char *data, H245_TransportAddress * addr,
53 u_int32_t * ip, u_int16_t * port);
54extern int get_h225_addr(unsigned char *data, TransportAddress * addr,
55 u_int32_t * ip, u_int16_t * port);
56extern void ip_conntrack_h245_expect(struct ip_conntrack *new,
57 struct ip_conntrack_expect *this);
58extern void ip_conntrack_q931_expect(struct ip_conntrack *new,
59 struct ip_conntrack_expect *this);
60extern int (*set_h245_addr_hook) (struct sk_buff ** pskb,
61 unsigned char **data, int dataoff,
62 H245_TransportAddress * addr,
63 u_int32_t ip, u_int16_t port);
64extern int (*set_h225_addr_hook) (struct sk_buff ** pskb,
65 unsigned char **data, int dataoff,
66 TransportAddress * addr,
67 u_int32_t ip, u_int16_t port);
68extern int (*set_sig_addr_hook) (struct sk_buff ** pskb,
69 struct ip_conntrack * ct,
70 enum ip_conntrack_info ctinfo,
71 unsigned char **data,
72 TransportAddress * addr, int count);
73extern int (*set_ras_addr_hook) (struct sk_buff ** pskb,
74 struct ip_conntrack * ct,
75 enum ip_conntrack_info ctinfo,
76 unsigned char **data,
77 TransportAddress * addr, int count);
78extern int (*nat_rtp_rtcp_hook) (struct sk_buff ** pskb,
79 struct ip_conntrack * ct,
80 enum ip_conntrack_info ctinfo,
81 unsigned char **data, int dataoff,
82 H245_TransportAddress * addr,
83 u_int16_t port, u_int16_t rtp_port,
84 struct ip_conntrack_expect * rtp_exp,
85 struct ip_conntrack_expect * rtcp_exp);
86extern int (*nat_t120_hook) (struct sk_buff ** pskb, struct ip_conntrack * ct,
87 enum ip_conntrack_info ctinfo,
88 unsigned char **data, int dataoff,
89 H245_TransportAddress * addr, u_int16_t port,
90 struct ip_conntrack_expect * exp);
91extern int (*nat_h245_hook) (struct sk_buff ** pskb, struct ip_conntrack * ct,
92 enum ip_conntrack_info ctinfo,
93 unsigned char **data, int dataoff,
94 TransportAddress * addr, u_int16_t port,
95 struct ip_conntrack_expect * exp);
96extern int (*nat_q931_hook) (struct sk_buff ** pskb, struct ip_conntrack * ct,
97 enum ip_conntrack_info ctinfo,
98 unsigned char **data, TransportAddress * addr,
99 int idx, u_int16_t port,
100 struct ip_conntrack_expect * exp);
101
102
103/****************************************************************************/
104static int set_addr(struct sk_buff **pskb,
105 unsigned char **data, int dataoff,
106 unsigned int addroff, u_int32_t ip, u_int16_t port)
107{
108 enum ip_conntrack_info ctinfo;
109 struct ip_conntrack *ct = ip_conntrack_get(*pskb, &ctinfo);
110 struct {
111 u_int32_t ip;
112 u_int16_t port;
113 } __attribute__ ((__packed__)) buf;
114 struct tcphdr _tcph, *th;
115
116 buf.ip = ip;
117 buf.port = htons(port);
118 addroff += dataoff;
119
120 if ((*pskb)->nh.iph->protocol == IPPROTO_TCP) {
121 if (!ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
122 addroff, sizeof(buf),
123 (char *) &buf, sizeof(buf))) {
124 if (net_ratelimit())
125 printk("ip_nat_h323: ip_nat_mangle_tcp_packet"
126 " error\n");
127 return -1;
128 }
129
130 /* Relocate data pointer */
131 th = skb_header_pointer(*pskb, (*pskb)->nh.iph->ihl * 4,
132 sizeof(_tcph), &_tcph);
133 if (th == NULL)
134 return -1;
135 *data = (*pskb)->data + (*pskb)->nh.iph->ihl * 4 +
136 th->doff * 4 + dataoff;
137 } else {
138 if (!ip_nat_mangle_udp_packet(pskb, ct, ctinfo,
139 addroff, sizeof(buf),
140 (char *) &buf, sizeof(buf))) {
141 if (net_ratelimit())
142 printk("ip_nat_h323: ip_nat_mangle_udp_packet"
143 " error\n");
144 return -1;
145 }
146 /* ip_nat_mangle_udp_packet uses skb_make_writable() to copy
147 * or pull everything in a linear buffer, so we can safely
148 * use the skb pointers now */
149 *data = (*pskb)->data + (*pskb)->nh.iph->ihl * 4 +
150 sizeof(struct udphdr);
151 }
152
153 return 0;
154}
155
156/****************************************************************************/
157static int set_h225_addr(struct sk_buff **pskb,
158 unsigned char **data, int dataoff,
159 TransportAddress * addr,
160 u_int32_t ip, u_int16_t port)
161{
162 return set_addr(pskb, data, dataoff, addr->ipAddress.ip, ip, port);
163}
164
165/****************************************************************************/
166static int set_h245_addr(struct sk_buff **pskb,
167 unsigned char **data, int dataoff,
168 H245_TransportAddress * addr,
169 u_int32_t ip, u_int16_t port)
170{
171 return set_addr(pskb, data, dataoff,
172 addr->unicastAddress.iPAddress.network, ip, port);
173}
174
175/****************************************************************************/
176static int set_sig_addr(struct sk_buff **pskb, struct ip_conntrack *ct,
177 enum ip_conntrack_info ctinfo,
178 unsigned char **data,
179 TransportAddress * addr, int count)
180{
181 struct ip_ct_h323_master *info = &ct->help.ct_h323_info;
182 int dir = CTINFO2DIR(ctinfo);
183 int i;
184 u_int32_t ip;
185 u_int16_t port;
186
187 for (i = 0; i < count; i++) {
188 if (get_h225_addr(*data, &addr[i], &ip, &port)) {
189 if (ip == ct->tuplehash[dir].tuple.src.ip &&
190 port == info->sig_port[dir]) {
191 /* GW->GK */
192
193 /* Fix for Gnomemeeting */
194 if (i > 0 &&
195 get_h225_addr(*data, &addr[0],
196 &ip, &port) &&
197 (ntohl(ip) & 0xff000000) == 0x7f000000)
198 i = 0;
199
200 DEBUGP
201 ("ip_nat_ras: set signal address "
202 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
203 NIPQUAD(ip), port,
204 NIPQUAD(ct->tuplehash[!dir].tuple.dst.
205 ip), info->sig_port[!dir]);
206 return set_h225_addr(pskb, data, 0, &addr[i],
207 ct->tuplehash[!dir].
208 tuple.dst.ip,
209 info->sig_port[!dir]);
210 } else if (ip == ct->tuplehash[dir].tuple.dst.ip &&
211 port == info->sig_port[dir]) {
212 /* GK->GW */
213 DEBUGP
214 ("ip_nat_ras: set signal address "
215 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
216 NIPQUAD(ip), port,
217 NIPQUAD(ct->tuplehash[!dir].tuple.src.
218 ip), info->sig_port[!dir]);
219 return set_h225_addr(pskb, data, 0, &addr[i],
220 ct->tuplehash[!dir].
221 tuple.src.ip,
222 info->sig_port[!dir]);
223 }
224 }
225 }
226
227 return 0;
228}
229
230/****************************************************************************/
231static int set_ras_addr(struct sk_buff **pskb, struct ip_conntrack *ct,
232 enum ip_conntrack_info ctinfo,
233 unsigned char **data,
234 TransportAddress * addr, int count)
235{
236 int dir = CTINFO2DIR(ctinfo);
237 int i;
238 u_int32_t ip;
239 u_int16_t port;
240
241 for (i = 0; i < count; i++) {
242 if (get_h225_addr(*data, &addr[i], &ip, &port) &&
243 ip == ct->tuplehash[dir].tuple.src.ip &&
244 port == ntohs(ct->tuplehash[dir].tuple.src.u.udp.port)) {
245 DEBUGP("ip_nat_ras: set rasAddress "
246 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
247 NIPQUAD(ip), port,
248 NIPQUAD(ct->tuplehash[!dir].tuple.dst.ip),
249 ntohs(ct->tuplehash[!dir].tuple.dst.u.udp.
250 port));
251 return set_h225_addr(pskb, data, 0, &addr[i],
252 ct->tuplehash[!dir].tuple.dst.ip,
253 ntohs(ct->tuplehash[!dir].tuple.
254 dst.u.udp.port));
255 }
256 }
257
258 return 0;
259}
260
261/****************************************************************************/
262static int nat_rtp_rtcp(struct sk_buff **pskb, struct ip_conntrack *ct,
263 enum ip_conntrack_info ctinfo,
264 unsigned char **data, int dataoff,
265 H245_TransportAddress * addr,
266 u_int16_t port, u_int16_t rtp_port,
267 struct ip_conntrack_expect *rtp_exp,
268 struct ip_conntrack_expect *rtcp_exp)
269{
270 struct ip_ct_h323_master *info = &ct->help.ct_h323_info;
271 int dir = CTINFO2DIR(ctinfo);
272 int i;
273 u_int16_t nated_port;
274
275 /* Set expectations for NAT */
276 rtp_exp->saved_proto.udp.port = rtp_exp->tuple.dst.u.udp.port;
277 rtp_exp->expectfn = ip_nat_follow_master;
278 rtp_exp->dir = !dir;
279 rtcp_exp->saved_proto.udp.port = rtcp_exp->tuple.dst.u.udp.port;
280 rtcp_exp->expectfn = ip_nat_follow_master;
281 rtcp_exp->dir = !dir;
282
283 /* Lookup existing expects */
284 for (i = 0; i < H323_RTP_CHANNEL_MAX; i++) {
285 if (info->rtp_port[i][dir] == rtp_port) {
286 /* Expected */
287
288 /* Use allocated ports first. This will refresh
289 * the expects */
290 rtp_exp->tuple.dst.u.udp.port =
291 htons(info->rtp_port[i][dir]);
292 rtcp_exp->tuple.dst.u.udp.port =
293 htons(info->rtp_port[i][dir] + 1);
294 break;
295 } else if (info->rtp_port[i][dir] == 0) {
296 /* Not expected */
297 break;
298 }
299 }
300
301 /* Run out of expectations */
302 if (i >= H323_RTP_CHANNEL_MAX) {
303 if (net_ratelimit())
304 printk("ip_nat_h323: out of expectations\n");
305 return 0;
306 }
307
308 /* Try to get a pair of ports. */
309 for (nated_port = ntohs(rtp_exp->tuple.dst.u.udp.port);
310 nated_port != 0; nated_port += 2) {
311 rtp_exp->tuple.dst.u.udp.port = htons(nated_port);
312 if (ip_conntrack_expect_related(rtp_exp) == 0) {
313 rtcp_exp->tuple.dst.u.udp.port =
314 htons(nated_port + 1);
315 if (ip_conntrack_expect_related(rtcp_exp) == 0)
316 break;
317 ip_conntrack_unexpect_related(rtp_exp);
318 }
319 }
320
321 if (nated_port == 0) { /* No port available */
322 if (net_ratelimit())
323 printk("ip_nat_h323: out of RTP ports\n");
324 return 0;
325 }
326
327 /* Modify signal */
328 if (set_h245_addr(pskb, data, dataoff, addr,
329 ct->tuplehash[!dir].tuple.dst.ip,
330 (port & 1) ? nated_port + 1 : nated_port) == 0) {
331 /* Save ports */
332 info->rtp_port[i][dir] = rtp_port;
333 info->rtp_port[i][!dir] = nated_port;
334 } else {
335 ip_conntrack_unexpect_related(rtp_exp);
336 ip_conntrack_unexpect_related(rtcp_exp);
337 return -1;
338 }
339
340 /* Success */
341 DEBUGP("ip_nat_h323: expect RTP %u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
342 NIPQUAD(rtp_exp->tuple.src.ip),
343 ntohs(rtp_exp->tuple.src.u.udp.port),
344 NIPQUAD(rtp_exp->tuple.dst.ip),
345 ntohs(rtp_exp->tuple.dst.u.udp.port));
346 DEBUGP("ip_nat_h323: expect RTCP %u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
347 NIPQUAD(rtcp_exp->tuple.src.ip),
348 ntohs(rtcp_exp->tuple.src.u.udp.port),
349 NIPQUAD(rtcp_exp->tuple.dst.ip),
350 ntohs(rtcp_exp->tuple.dst.u.udp.port));
351
352 return 0;
353}
354
355/****************************************************************************/
356static int nat_t120(struct sk_buff **pskb, struct ip_conntrack *ct,
357 enum ip_conntrack_info ctinfo,
358 unsigned char **data, int dataoff,
359 H245_TransportAddress * addr, u_int16_t port,
360 struct ip_conntrack_expect *exp)
361{
362 int dir = CTINFO2DIR(ctinfo);
363 u_int16_t nated_port = port;
364
365 /* Set expectations for NAT */
366 exp->saved_proto.tcp.port = exp->tuple.dst.u.tcp.port;
367 exp->expectfn = ip_nat_follow_master;
368 exp->dir = !dir;
369
370 /* Try to get same port: if not, try to change it. */
371 for (; nated_port != 0; nated_port++) {
372 exp->tuple.dst.u.tcp.port = htons(nated_port);
373 if (ip_conntrack_expect_related(exp) == 0)
374 break;
375 }
376
377 if (nated_port == 0) { /* No port available */
378 if (net_ratelimit())
379 printk("ip_nat_h323: out of TCP ports\n");
380 return 0;
381 }
382
383 /* Modify signal */
384 if (set_h245_addr(pskb, data, dataoff, addr,
385 ct->tuplehash[!dir].tuple.dst.ip, nated_port) < 0) {
386 ip_conntrack_unexpect_related(exp);
387 return -1;
388 }
389
390 DEBUGP("ip_nat_h323: expect T.120 %u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
391 NIPQUAD(exp->tuple.src.ip), ntohs(exp->tuple.src.u.tcp.port),
392 NIPQUAD(exp->tuple.dst.ip), ntohs(exp->tuple.dst.u.tcp.port));
393
394 return 0;
395}
396
397/****************************************************************************
398 * This conntrack expect function replaces ip_conntrack_h245_expect()
399 * which was set by ip_conntrack_helper_h323.c. It calls both
400 * ip_nat_follow_master() and ip_conntrack_h245_expect()
401 ****************************************************************************/
402static void ip_nat_h245_expect(struct ip_conntrack *new,
403 struct ip_conntrack_expect *this)
404{
405 ip_nat_follow_master(new, this);
406 ip_conntrack_h245_expect(new, this);
407}
408
409/****************************************************************************/
410static int nat_h245(struct sk_buff **pskb, struct ip_conntrack *ct,
411 enum ip_conntrack_info ctinfo,
412 unsigned char **data, int dataoff,
413 TransportAddress * addr, u_int16_t port,
414 struct ip_conntrack_expect *exp)
415{
416 struct ip_ct_h323_master *info = &ct->help.ct_h323_info;
417 int dir = CTINFO2DIR(ctinfo);
418 u_int16_t nated_port = port;
419
420 /* Set expectations for NAT */
421 exp->saved_proto.tcp.port = exp->tuple.dst.u.tcp.port;
422 exp->expectfn = ip_nat_h245_expect;
423 exp->dir = !dir;
424
425 /* Check existing expects */
426 if (info->sig_port[dir] == port)
427 nated_port = info->sig_port[!dir];
428
429 /* Try to get same port: if not, try to change it. */
430 for (; nated_port != 0; nated_port++) {
431 exp->tuple.dst.u.tcp.port = htons(nated_port);
432 if (ip_conntrack_expect_related(exp) == 0)
433 break;
434 }
435
436 if (nated_port == 0) { /* No port available */
437 if (net_ratelimit())
438 printk("ip_nat_q931: out of TCP ports\n");
439 return 0;
440 }
441
442 /* Modify signal */
443 if (set_h225_addr(pskb, data, dataoff, addr,
444 ct->tuplehash[!dir].tuple.dst.ip,
445 nated_port) == 0) {
446 /* Save ports */
447 info->sig_port[dir] = port;
448 info->sig_port[!dir] = nated_port;
449 } else {
450 ip_conntrack_unexpect_related(exp);
451 return -1;
452 }
453
454 DEBUGP("ip_nat_q931: expect H.245 %u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
455 NIPQUAD(exp->tuple.src.ip), ntohs(exp->tuple.src.u.tcp.port),
456 NIPQUAD(exp->tuple.dst.ip), ntohs(exp->tuple.dst.u.tcp.port));
457
458 return 0;
459}
460
461/****************************************************************************
462 * This conntrack expect function replaces ip_conntrack_q931_expect()
463 * which was set by ip_conntrack_helper_h323.c.
464 ****************************************************************************/
465static void ip_nat_q931_expect(struct ip_conntrack *new,
466 struct ip_conntrack_expect *this)
467{
468 struct ip_nat_range range;
469
470 if (this->tuple.src.ip != 0) { /* Only accept calls from GK */
471 ip_nat_follow_master(new, this);
472 goto out;
473 }
474
475 /* This must be a fresh one. */
476 BUG_ON(new->status & IPS_NAT_DONE_MASK);
477
478 /* Change src to where master sends to */
479 range.flags = IP_NAT_RANGE_MAP_IPS;
480 range.min_ip = range.max_ip = new->tuplehash[!this->dir].tuple.src.ip;
481
482 /* hook doesn't matter, but it has to do source manip */
483 ip_nat_setup_info(new, &range, NF_IP_POST_ROUTING);
484
485 /* For DST manip, map port here to where it's expected. */
486 range.flags = (IP_NAT_RANGE_MAP_IPS | IP_NAT_RANGE_PROTO_SPECIFIED);
487 range.min = range.max = this->saved_proto;
488 range.min_ip = range.max_ip =
489 new->master->tuplehash[!this->dir].tuple.src.ip;
490
491 /* hook doesn't matter, but it has to do destination manip */
492 ip_nat_setup_info(new, &range, NF_IP_PRE_ROUTING);
493
494 out:
495 ip_conntrack_q931_expect(new, this);
496}
497
498/****************************************************************************/
499static int nat_q931(struct sk_buff **pskb, struct ip_conntrack *ct,
500 enum ip_conntrack_info ctinfo,
501 unsigned char **data, TransportAddress * addr, int idx,
502 u_int16_t port, struct ip_conntrack_expect *exp)
503{
504 struct ip_ct_h323_master *info = &ct->help.ct_h323_info;
505 int dir = CTINFO2DIR(ctinfo);
506 u_int16_t nated_port = port;
507 u_int32_t ip;
508
509 /* Set expectations for NAT */
510 exp->saved_proto.tcp.port = exp->tuple.dst.u.tcp.port;
511 exp->expectfn = ip_nat_q931_expect;
512 exp->dir = !dir;
513
514 /* Check existing expects */
515 if (info->sig_port[dir] == port)
516 nated_port = info->sig_port[!dir];
517
518 /* Try to get same port: if not, try to change it. */
519 for (; nated_port != 0; nated_port++) {
520 exp->tuple.dst.u.tcp.port = htons(nated_port);
521 if (ip_conntrack_expect_related(exp) == 0)
522 break;
523 }
524
525 if (nated_port == 0) { /* No port available */
526 if (net_ratelimit())
527 printk("ip_nat_ras: out of TCP ports\n");
528 return 0;
529 }
530
531 /* Modify signal */
532 if (set_h225_addr(pskb, data, 0, &addr[idx],
533 ct->tuplehash[!dir].tuple.dst.ip,
534 nated_port) == 0) {
535 /* Save ports */
536 info->sig_port[dir] = port;
537 info->sig_port[!dir] = nated_port;
538
539 /* Fix for Gnomemeeting */
540 if (idx > 0 &&
541 get_h225_addr(*data, &addr[0], &ip, &port) &&
542 (ntohl(ip) & 0xff000000) == 0x7f000000) {
543 set_h225_addr_hook(pskb, data, 0, &addr[0],
544 ct->tuplehash[!dir].tuple.dst.ip,
545 info->sig_port[!dir]);
546 }
547 } else {
548 ip_conntrack_unexpect_related(exp);
549 return -1;
550 }
551
552 /* Success */
553 DEBUGP("ip_nat_ras: expect Q.931 %u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
554 NIPQUAD(exp->tuple.src.ip), ntohs(exp->tuple.src.u.tcp.port),
555 NIPQUAD(exp->tuple.dst.ip), ntohs(exp->tuple.dst.u.tcp.port));
556
557 return 0;
558}
559
560/****************************************************************************/
561static int __init init(void)
562{
563 BUG_ON(set_h245_addr_hook != NULL);
564 BUG_ON(set_h225_addr_hook != NULL);
565 BUG_ON(set_sig_addr_hook != NULL);
566 BUG_ON(set_ras_addr_hook != NULL);
567 BUG_ON(nat_rtp_rtcp_hook != NULL);
568 BUG_ON(nat_t120_hook != NULL);
569 BUG_ON(nat_h245_hook != NULL);
570 BUG_ON(nat_q931_hook != NULL);
571
572 set_h245_addr_hook = set_h245_addr;
573 set_h225_addr_hook = set_h225_addr;
574 set_sig_addr_hook = set_sig_addr;
575 set_ras_addr_hook = set_ras_addr;
576 nat_rtp_rtcp_hook = nat_rtp_rtcp;
577 nat_t120_hook = nat_t120;
578 nat_h245_hook = nat_h245;
579 nat_q931_hook = nat_q931;
580
581 DEBUGP("ip_nat_h323: init success\n");
582 return 0;
583}
584
585/****************************************************************************/
586static void __exit fini(void)
587{
588 set_h245_addr_hook = NULL;
589 set_h225_addr_hook = NULL;
590 set_sig_addr_hook = NULL;
591 set_ras_addr_hook = NULL;
592 nat_rtp_rtcp_hook = NULL;
593 nat_t120_hook = NULL;
594 nat_h245_hook = NULL;
595 nat_q931_hook = NULL;
596 synchronize_net();
597}
598
599/****************************************************************************/
600module_init(init);
601module_exit(fini);
602
603MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>");
604MODULE_DESCRIPTION("H.323 NAT helper");
605MODULE_LICENSE("GPL");
diff --git a/net/ipv4/netfilter/ip_nat_helper_pptp.c b/net/ipv4/netfilter/ip_nat_helper_pptp.c
index ac004895781a..b9c016c063b8 100644
--- a/net/ipv4/netfilter/ip_nat_helper_pptp.c
+++ b/net/ipv4/netfilter/ip_nat_helper_pptp.c
@@ -52,6 +52,8 @@
52 52
53#define IP_NAT_PPTP_VERSION "3.0" 53#define IP_NAT_PPTP_VERSION "3.0"
54 54
55#define REQ_CID(req, off) (*(u_int16_t *)((char *)(req) + (off)))
56
55MODULE_LICENSE("GPL"); 57MODULE_LICENSE("GPL");
56MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>"); 58MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
57MODULE_DESCRIPTION("Netfilter NAT helper module for PPTP"); 59MODULE_DESCRIPTION("Netfilter NAT helper module for PPTP");
@@ -198,7 +200,7 @@ pptp_outbound_pkt(struct sk_buff **pskb,
198 /* only OUT_CALL_REQUEST, IN_CALL_REPLY, CALL_CLEAR_REQUEST pass 200 /* only OUT_CALL_REQUEST, IN_CALL_REPLY, CALL_CLEAR_REQUEST pass
199 * down to here */ 201 * down to here */
200 DEBUGP("altering call id from 0x%04x to 0x%04x\n", 202 DEBUGP("altering call id from 0x%04x to 0x%04x\n",
201 ntohs(*(u_int16_t *)pptpReq + cid_off), ntohs(new_callid)); 203 ntohs(REQ_CID(pptpReq, cid_off)), ntohs(new_callid));
202 204
203 /* mangle packet */ 205 /* mangle packet */
204 if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, 206 if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
@@ -342,7 +344,7 @@ pptp_inbound_pkt(struct sk_buff **pskb,
342 344
343 /* mangle packet */ 345 /* mangle packet */
344 DEBUGP("altering peer call id from 0x%04x to 0x%04x\n", 346 DEBUGP("altering peer call id from 0x%04x to 0x%04x\n",
345 ntohs(*(u_int16_t *)pptpReq + pcid_off), ntohs(new_pcid)); 347 ntohs(REQ_CID(pptpReq, pcid_off)), ntohs(new_pcid));
346 348
347 if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, 349 if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
348 pcid_off + sizeof(struct pptp_pkt_hdr) + 350 pcid_off + sizeof(struct pptp_pkt_hdr) +
@@ -353,7 +355,7 @@ pptp_inbound_pkt(struct sk_buff **pskb,
353 355
354 if (new_cid) { 356 if (new_cid) {
355 DEBUGP("altering call id from 0x%04x to 0x%04x\n", 357 DEBUGP("altering call id from 0x%04x to 0x%04x\n",
356 ntohs(*(u_int16_t *)pptpReq + cid_off), ntohs(new_cid)); 358 ntohs(REQ_CID(pptpReq, cid_off)), ntohs(new_cid));
357 if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, 359 if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
358 cid_off + sizeof(struct pptp_pkt_hdr) + 360 cid_off + sizeof(struct pptp_pkt_hdr) +
359 sizeof(struct PptpControlHeader), 361 sizeof(struct PptpControlHeader),
diff --git a/net/ipv4/netfilter/ip_nat_rule.c b/net/ipv4/netfilter/ip_nat_rule.c
index 1de86282d232..efba8c4e42e0 100644
--- a/net/ipv4/netfilter/ip_nat_rule.c
+++ b/net/ipv4/netfilter/ip_nat_rule.c
@@ -103,6 +103,7 @@ static unsigned int ipt_snat_target(struct sk_buff **pskb,
103 const struct net_device *in, 103 const struct net_device *in,
104 const struct net_device *out, 104 const struct net_device *out,
105 unsigned int hooknum, 105 unsigned int hooknum,
106 const struct ipt_target *target,
106 const void *targinfo, 107 const void *targinfo,
107 void *userinfo) 108 void *userinfo)
108{ 109{
@@ -145,6 +146,7 @@ static unsigned int ipt_dnat_target(struct sk_buff **pskb,
145 const struct net_device *in, 146 const struct net_device *in,
146 const struct net_device *out, 147 const struct net_device *out,
147 unsigned int hooknum, 148 unsigned int hooknum,
149 const struct ipt_target *target,
148 const void *targinfo, 150 const void *targinfo,
149 void *userinfo) 151 void *userinfo)
150{ 152{
@@ -170,6 +172,7 @@ static unsigned int ipt_dnat_target(struct sk_buff **pskb,
170 172
171static int ipt_snat_checkentry(const char *tablename, 173static int ipt_snat_checkentry(const char *tablename,
172 const void *entry, 174 const void *entry,
175 const struct ipt_target *target,
173 void *targinfo, 176 void *targinfo,
174 unsigned int targinfosize, 177 unsigned int targinfosize,
175 unsigned int hook_mask) 178 unsigned int hook_mask)
@@ -181,28 +184,12 @@ static int ipt_snat_checkentry(const char *tablename,
181 printk("SNAT: multiple ranges no longer supported\n"); 184 printk("SNAT: multiple ranges no longer supported\n");
182 return 0; 185 return 0;
183 } 186 }
184
185 if (targinfosize != IPT_ALIGN(sizeof(struct ip_nat_multi_range_compat))) {
186 DEBUGP("SNAT: Target size %u wrong for %u ranges\n",
187 targinfosize, mr->rangesize);
188 return 0;
189 }
190
191 /* Only allow these for NAT. */
192 if (strcmp(tablename, "nat") != 0) {
193 DEBUGP("SNAT: wrong table %s\n", tablename);
194 return 0;
195 }
196
197 if (hook_mask & ~(1 << NF_IP_POST_ROUTING)) {
198 DEBUGP("SNAT: hook mask 0x%x bad\n", hook_mask);
199 return 0;
200 }
201 return 1; 187 return 1;
202} 188}
203 189
204static int ipt_dnat_checkentry(const char *tablename, 190static int ipt_dnat_checkentry(const char *tablename,
205 const void *entry, 191 const void *entry,
192 const struct ipt_target *target,
206 void *targinfo, 193 void *targinfo,
207 unsigned int targinfosize, 194 unsigned int targinfosize,
208 unsigned int hook_mask) 195 unsigned int hook_mask)
@@ -214,24 +201,6 @@ static int ipt_dnat_checkentry(const char *tablename,
214 printk("DNAT: multiple ranges no longer supported\n"); 201 printk("DNAT: multiple ranges no longer supported\n");
215 return 0; 202 return 0;
216 } 203 }
217
218 if (targinfosize != IPT_ALIGN(sizeof(struct ip_nat_multi_range_compat))) {
219 DEBUGP("DNAT: Target size %u wrong for %u ranges\n",
220 targinfosize, mr->rangesize);
221 return 0;
222 }
223
224 /* Only allow these for NAT. */
225 if (strcmp(tablename, "nat") != 0) {
226 DEBUGP("DNAT: wrong table %s\n", tablename);
227 return 0;
228 }
229
230 if (hook_mask & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_OUT))) {
231 DEBUGP("DNAT: hook mask 0x%x bad\n", hook_mask);
232 return 0;
233 }
234
235 return 1; 204 return 1;
236} 205}
237 206
@@ -299,12 +268,18 @@ int ip_nat_rule_find(struct sk_buff **pskb,
299static struct ipt_target ipt_snat_reg = { 268static struct ipt_target ipt_snat_reg = {
300 .name = "SNAT", 269 .name = "SNAT",
301 .target = ipt_snat_target, 270 .target = ipt_snat_target,
271 .targetsize = sizeof(struct ip_nat_multi_range_compat),
272 .table = "nat",
273 .hooks = 1 << NF_IP_POST_ROUTING,
302 .checkentry = ipt_snat_checkentry, 274 .checkentry = ipt_snat_checkentry,
303}; 275};
304 276
305static struct ipt_target ipt_dnat_reg = { 277static struct ipt_target ipt_dnat_reg = {
306 .name = "DNAT", 278 .name = "DNAT",
307 .target = ipt_dnat_target, 279 .target = ipt_dnat_target,
280 .targetsize = sizeof(struct ip_nat_multi_range_compat),
281 .table = "nat",
282 .hooks = 1 << NF_IP_PRE_ROUTING,
308 .checkentry = ipt_dnat_checkentry, 283 .checkentry = ipt_dnat_checkentry,
309}; 284};
310 285
diff --git a/net/ipv4/netfilter/ip_nat_snmp_basic.c b/net/ipv4/netfilter/ip_nat_snmp_basic.c
index 4f95d477805c..f029da2a60ee 100644
--- a/net/ipv4/netfilter/ip_nat_snmp_basic.c
+++ b/net/ipv4/netfilter/ip_nat_snmp_basic.c
@@ -250,6 +250,7 @@ static unsigned char asn1_header_decode(struct asn1_ctx *ctx,
250 if (!asn1_id_decode(ctx, cls, con, tag)) 250 if (!asn1_id_decode(ctx, cls, con, tag))
251 return 0; 251 return 0;
252 252
253 def = len = 0;
253 if (!asn1_length_decode(ctx, &def, &len)) 254 if (!asn1_length_decode(ctx, &def, &len))
254 return 0; 255 return 0;
255 256
@@ -669,7 +670,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
669 unsigned char *eoc, *end, *p; 670 unsigned char *eoc, *end, *p;
670 unsigned long *lp, *id; 671 unsigned long *lp, *id;
671 unsigned long ul; 672 unsigned long ul;
672 long l; 673 long l;
673 674
674 *obj = NULL; 675 *obj = NULL;
675 id = NULL; 676 id = NULL;
@@ -699,11 +700,13 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
699 return 0; 700 return 0;
700 } 701 }
701 702
703 type = 0;
702 if (!snmp_tag_cls2syntax(tag, cls, &type)) { 704 if (!snmp_tag_cls2syntax(tag, cls, &type)) {
703 kfree(id); 705 kfree(id);
704 return 0; 706 return 0;
705 } 707 }
706 708
709 l = 0;
707 switch (type) { 710 switch (type) {
708 case SNMP_INTEGER: 711 case SNMP_INTEGER:
709 len = sizeof(long); 712 len = sizeof(long);
diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c
index 08f80e2ea2aa..1655866c55b9 100644
--- a/net/ipv4/netfilter/ip_queue.c
+++ b/net/ipv4/netfilter/ip_queue.c
@@ -35,6 +35,7 @@
35#include <linux/sysctl.h> 35#include <linux/sysctl.h>
36#include <linux/proc_fs.h> 36#include <linux/proc_fs.h>
37#include <linux/security.h> 37#include <linux/security.h>
38#include <linux/mutex.h>
38#include <net/sock.h> 39#include <net/sock.h>
39#include <net/route.h> 40#include <net/route.h>
40 41
@@ -61,7 +62,7 @@ static unsigned int queue_dropped = 0;
61static unsigned int queue_user_dropped = 0; 62static unsigned int queue_user_dropped = 0;
62static struct sock *ipqnl; 63static struct sock *ipqnl;
63static LIST_HEAD(queue_list); 64static LIST_HEAD(queue_list);
64static DECLARE_MUTEX(ipqnl_sem); 65static DEFINE_MUTEX(ipqnl_mutex);
65 66
66static void 67static void
67ipq_issue_verdict(struct ipq_queue_entry *entry, int verdict) 68ipq_issue_verdict(struct ipq_queue_entry *entry, int verdict)
@@ -539,7 +540,7 @@ ipq_rcv_sk(struct sock *sk, int len)
539 struct sk_buff *skb; 540 struct sk_buff *skb;
540 unsigned int qlen; 541 unsigned int qlen;
541 542
542 down(&ipqnl_sem); 543 mutex_lock(&ipqnl_mutex);
543 544
544 for (qlen = skb_queue_len(&sk->sk_receive_queue); qlen; qlen--) { 545 for (qlen = skb_queue_len(&sk->sk_receive_queue); qlen; qlen--) {
545 skb = skb_dequeue(&sk->sk_receive_queue); 546 skb = skb_dequeue(&sk->sk_receive_queue);
@@ -547,7 +548,7 @@ ipq_rcv_sk(struct sock *sk, int len)
547 kfree_skb(skb); 548 kfree_skb(skb);
548 } 549 }
549 550
550 up(&ipqnl_sem); 551 mutex_unlock(&ipqnl_mutex);
551} 552}
552 553
553static int 554static int
@@ -708,8 +709,8 @@ cleanup_sysctl:
708 709
709cleanup_ipqnl: 710cleanup_ipqnl:
710 sock_release(ipqnl->sk_socket); 711 sock_release(ipqnl->sk_socket);
711 down(&ipqnl_sem); 712 mutex_lock(&ipqnl_mutex);
712 up(&ipqnl_sem); 713 mutex_unlock(&ipqnl_mutex);
713 714
714cleanup_netlink_notifier: 715cleanup_netlink_notifier:
715 netlink_unregister_notifier(&ipq_nl_notifier); 716 netlink_unregister_notifier(&ipq_nl_notifier);
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 16f47c675fef..39705f9bc154 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -25,7 +25,7 @@
25#include <linux/icmp.h> 25#include <linux/icmp.h>
26#include <net/ip.h> 26#include <net/ip.h>
27#include <asm/uaccess.h> 27#include <asm/uaccess.h>
28#include <asm/semaphore.h> 28#include <linux/mutex.h>
29#include <linux/proc_fs.h> 29#include <linux/proc_fs.h>
30#include <linux/err.h> 30#include <linux/err.h>
31#include <linux/cpumask.h> 31#include <linux/cpumask.h>
@@ -179,6 +179,7 @@ ipt_error(struct sk_buff **pskb,
179 const struct net_device *in, 179 const struct net_device *in,
180 const struct net_device *out, 180 const struct net_device *out,
181 unsigned int hooknum, 181 unsigned int hooknum,
182 const struct xt_target *target,
182 const void *targinfo, 183 const void *targinfo,
183 void *userinfo) 184 void *userinfo)
184{ 185{
@@ -197,8 +198,8 @@ int do_match(struct ipt_entry_match *m,
197 int *hotdrop) 198 int *hotdrop)
198{ 199{
199 /* Stop iteration if it doesn't match */ 200 /* Stop iteration if it doesn't match */
200 if (!m->u.kernel.match->match(skb, in, out, m->data, offset, 201 if (!m->u.kernel.match->match(skb, in, out, m->u.kernel.match, m->data,
201 skb->nh.iph->ihl*4, hotdrop)) 202 offset, skb->nh.iph->ihl*4, hotdrop))
202 return 1; 203 return 1;
203 else 204 else
204 return 0; 205 return 0;
@@ -305,6 +306,7 @@ ipt_do_table(struct sk_buff **pskb,
305 verdict = t->u.kernel.target->target(pskb, 306 verdict = t->u.kernel.target->target(pskb,
306 in, out, 307 in, out,
307 hook, 308 hook,
309 t->u.kernel.target,
308 t->data, 310 t->data,
309 userdata); 311 userdata);
310 312
@@ -464,7 +466,7 @@ cleanup_match(struct ipt_entry_match *m, unsigned int *i)
464 return 1; 466 return 1;
465 467
466 if (m->u.kernel.match->destroy) 468 if (m->u.kernel.match->destroy)
467 m->u.kernel.match->destroy(m->data, 469 m->u.kernel.match->destroy(m->u.kernel.match, m->data,
468 m->u.match_size - sizeof(*m)); 470 m->u.match_size - sizeof(*m));
469 module_put(m->u.kernel.match->me); 471 module_put(m->u.kernel.match->me);
470 return 0; 472 return 0;
@@ -477,21 +479,12 @@ standard_check(const struct ipt_entry_target *t,
477 struct ipt_standard_target *targ = (void *)t; 479 struct ipt_standard_target *targ = (void *)t;
478 480
479 /* Check standard info. */ 481 /* Check standard info. */
480 if (t->u.target_size
481 != IPT_ALIGN(sizeof(struct ipt_standard_target))) {
482 duprintf("standard_check: target size %u != %u\n",
483 t->u.target_size,
484 IPT_ALIGN(sizeof(struct ipt_standard_target)));
485 return 0;
486 }
487
488 if (targ->verdict >= 0 482 if (targ->verdict >= 0
489 && targ->verdict > max_offset - sizeof(struct ipt_entry)) { 483 && targ->verdict > max_offset - sizeof(struct ipt_entry)) {
490 duprintf("ipt_standard_check: bad verdict (%i)\n", 484 duprintf("ipt_standard_check: bad verdict (%i)\n",
491 targ->verdict); 485 targ->verdict);
492 return 0; 486 return 0;
493 } 487 }
494
495 if (targ->verdict < -NF_MAX_VERDICT - 1) { 488 if (targ->verdict < -NF_MAX_VERDICT - 1) {
496 duprintf("ipt_standard_check: bad negative verdict (%i)\n", 489 duprintf("ipt_standard_check: bad negative verdict (%i)\n",
497 targ->verdict); 490 targ->verdict);
@@ -508,6 +501,7 @@ check_match(struct ipt_entry_match *m,
508 unsigned int *i) 501 unsigned int *i)
509{ 502{
510 struct ipt_match *match; 503 struct ipt_match *match;
504 int ret;
511 505
512 match = try_then_request_module(xt_find_match(AF_INET, m->u.user.name, 506 match = try_then_request_module(xt_find_match(AF_INET, m->u.user.name,
513 m->u.user.revision), 507 m->u.user.revision),
@@ -518,18 +512,27 @@ check_match(struct ipt_entry_match *m,
518 } 512 }
519 m->u.kernel.match = match; 513 m->u.kernel.match = match;
520 514
515 ret = xt_check_match(match, AF_INET, m->u.match_size - sizeof(*m),
516 name, hookmask, ip->proto,
517 ip->invflags & IPT_INV_PROTO);
518 if (ret)
519 goto err;
520
521 if (m->u.kernel.match->checkentry 521 if (m->u.kernel.match->checkentry
522 && !m->u.kernel.match->checkentry(name, ip, m->data, 522 && !m->u.kernel.match->checkentry(name, ip, match, m->data,
523 m->u.match_size - sizeof(*m), 523 m->u.match_size - sizeof(*m),
524 hookmask)) { 524 hookmask)) {
525 module_put(m->u.kernel.match->me);
526 duprintf("ip_tables: check failed for `%s'.\n", 525 duprintf("ip_tables: check failed for `%s'.\n",
527 m->u.kernel.match->name); 526 m->u.kernel.match->name);
528 return -EINVAL; 527 ret = -EINVAL;
528 goto err;
529 } 529 }
530 530
531 (*i)++; 531 (*i)++;
532 return 0; 532 return 0;
533err:
534 module_put(m->u.kernel.match->me);
535 return ret;
533} 536}
534 537
535static struct ipt_target ipt_standard_target; 538static struct ipt_target ipt_standard_target;
@@ -565,26 +568,32 @@ check_entry(struct ipt_entry *e, const char *name, unsigned int size,
565 } 568 }
566 t->u.kernel.target = target; 569 t->u.kernel.target = target;
567 570
571 ret = xt_check_target(target, AF_INET, t->u.target_size - sizeof(*t),
572 name, e->comefrom, e->ip.proto,
573 e->ip.invflags & IPT_INV_PROTO);
574 if (ret)
575 goto err;
576
568 if (t->u.kernel.target == &ipt_standard_target) { 577 if (t->u.kernel.target == &ipt_standard_target) {
569 if (!standard_check(t, size)) { 578 if (!standard_check(t, size)) {
570 ret = -EINVAL; 579 ret = -EINVAL;
571 goto cleanup_matches; 580 goto cleanup_matches;
572 } 581 }
573 } else if (t->u.kernel.target->checkentry 582 } else if (t->u.kernel.target->checkentry
574 && !t->u.kernel.target->checkentry(name, e, t->data, 583 && !t->u.kernel.target->checkentry(name, e, target, t->data,
575 t->u.target_size 584 t->u.target_size
576 - sizeof(*t), 585 - sizeof(*t),
577 e->comefrom)) { 586 e->comefrom)) {
578 module_put(t->u.kernel.target->me);
579 duprintf("ip_tables: check failed for `%s'.\n", 587 duprintf("ip_tables: check failed for `%s'.\n",
580 t->u.kernel.target->name); 588 t->u.kernel.target->name);
581 ret = -EINVAL; 589 ret = -EINVAL;
582 goto cleanup_matches; 590 goto err;
583 } 591 }
584 592
585 (*i)++; 593 (*i)++;
586 return 0; 594 return 0;
587 595 err:
596 module_put(t->u.kernel.target->me);
588 cleanup_matches: 597 cleanup_matches:
589 IPT_MATCH_ITERATE(e, cleanup_match, &j); 598 IPT_MATCH_ITERATE(e, cleanup_match, &j);
590 return ret; 599 return ret;
@@ -645,7 +654,7 @@ cleanup_entry(struct ipt_entry *e, unsigned int *i)
645 IPT_MATCH_ITERATE(e, cleanup_match, NULL); 654 IPT_MATCH_ITERATE(e, cleanup_match, NULL);
646 t = ipt_get_target(e); 655 t = ipt_get_target(e);
647 if (t->u.kernel.target->destroy) 656 if (t->u.kernel.target->destroy)
648 t->u.kernel.target->destroy(t->data, 657 t->u.kernel.target->destroy(t->u.kernel.target, t->data,
649 t->u.target_size - sizeof(*t)); 658 t->u.target_size - sizeof(*t));
650 module_put(t->u.kernel.target->me); 659 module_put(t->u.kernel.target->me);
651 return 0; 660 return 0;
@@ -1277,6 +1286,7 @@ static int
1277icmp_match(const struct sk_buff *skb, 1286icmp_match(const struct sk_buff *skb,
1278 const struct net_device *in, 1287 const struct net_device *in,
1279 const struct net_device *out, 1288 const struct net_device *out,
1289 const struct xt_match *match,
1280 const void *matchinfo, 1290 const void *matchinfo,
1281 int offset, 1291 int offset,
1282 unsigned int protoff, 1292 unsigned int protoff,
@@ -1310,28 +1320,27 @@ icmp_match(const struct sk_buff *skb,
1310static int 1320static int
1311icmp_checkentry(const char *tablename, 1321icmp_checkentry(const char *tablename,
1312 const void *info, 1322 const void *info,
1323 const struct xt_match *match,
1313 void *matchinfo, 1324 void *matchinfo,
1314 unsigned int matchsize, 1325 unsigned int matchsize,
1315 unsigned int hook_mask) 1326 unsigned int hook_mask)
1316{ 1327{
1317 const struct ipt_ip *ip = info;
1318 const struct ipt_icmp *icmpinfo = matchinfo; 1328 const struct ipt_icmp *icmpinfo = matchinfo;
1319 1329
1320 /* Must specify proto == ICMP, and no unknown invflags */ 1330 /* Must specify no unknown invflags */
1321 return ip->proto == IPPROTO_ICMP 1331 return !(icmpinfo->invflags & ~IPT_ICMP_INV);
1322 && !(ip->invflags & IPT_INV_PROTO)
1323 && matchsize == IPT_ALIGN(sizeof(struct ipt_icmp))
1324 && !(icmpinfo->invflags & ~IPT_ICMP_INV);
1325} 1332}
1326 1333
1327/* The built-in targets: standard (NULL) and error. */ 1334/* The built-in targets: standard (NULL) and error. */
1328static struct ipt_target ipt_standard_target = { 1335static struct ipt_target ipt_standard_target = {
1329 .name = IPT_STANDARD_TARGET, 1336 .name = IPT_STANDARD_TARGET,
1337 .targetsize = sizeof(int),
1330}; 1338};
1331 1339
1332static struct ipt_target ipt_error_target = { 1340static struct ipt_target ipt_error_target = {
1333 .name = IPT_ERROR_TARGET, 1341 .name = IPT_ERROR_TARGET,
1334 .target = ipt_error, 1342 .target = ipt_error,
1343 .targetsize = IPT_FUNCTION_MAXNAMELEN,
1335}; 1344};
1336 1345
1337static struct nf_sockopt_ops ipt_sockopts = { 1346static struct nf_sockopt_ops ipt_sockopts = {
@@ -1346,8 +1355,10 @@ static struct nf_sockopt_ops ipt_sockopts = {
1346 1355
1347static struct ipt_match icmp_matchstruct = { 1356static struct ipt_match icmp_matchstruct = {
1348 .name = "icmp", 1357 .name = "icmp",
1349 .match = &icmp_match, 1358 .match = icmp_match,
1350 .checkentry = &icmp_checkentry, 1359 .matchsize = sizeof(struct ipt_icmp),
1360 .proto = IPPROTO_ICMP,
1361 .checkentry = icmp_checkentry,
1351}; 1362};
1352 1363
1353static int __init init(void) 1364static int __init init(void)
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index d9bc971f03af..61e11edcd6af 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -311,6 +311,7 @@ target(struct sk_buff **pskb,
311 const struct net_device *in, 311 const struct net_device *in,
312 const struct net_device *out, 312 const struct net_device *out,
313 unsigned int hooknum, 313 unsigned int hooknum,
314 const struct xt_target *target,
314 const void *targinfo, 315 const void *targinfo,
315 void *userinfo) 316 void *userinfo)
316{ 317{
@@ -380,6 +381,7 @@ target(struct sk_buff **pskb,
380static int 381static int
381checkentry(const char *tablename, 382checkentry(const char *tablename,
382 const void *e_void, 383 const void *e_void,
384 const struct xt_target *target,
383 void *targinfo, 385 void *targinfo,
384 unsigned int targinfosize, 386 unsigned int targinfosize,
385 unsigned int hook_mask) 387 unsigned int hook_mask)
@@ -389,13 +391,6 @@ checkentry(const char *tablename,
389 391
390 struct clusterip_config *config; 392 struct clusterip_config *config;
391 393
392 if (targinfosize != IPT_ALIGN(sizeof(struct ipt_clusterip_tgt_info))) {
393 printk(KERN_WARNING "CLUSTERIP: targinfosize %u != %Zu\n",
394 targinfosize,
395 IPT_ALIGN(sizeof(struct ipt_clusterip_tgt_info)));
396 return 0;
397 }
398
399 if (cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP && 394 if (cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP &&
400 cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT && 395 cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT &&
401 cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT_DPT) { 396 cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT_DPT) {
@@ -465,9 +460,10 @@ checkentry(const char *tablename,
465} 460}
466 461
467/* drop reference count of cluster config when rule is deleted */ 462/* drop reference count of cluster config when rule is deleted */
468static void destroy(void *matchinfo, unsigned int matchinfosize) 463static void destroy(const struct xt_target *target, void *targinfo,
464 unsigned int targinfosize)
469{ 465{
470 struct ipt_clusterip_tgt_info *cipinfo = matchinfo; 466 struct ipt_clusterip_tgt_info *cipinfo = targinfo;
471 467
472 /* if no more entries are referencing the config, remove it 468 /* if no more entries are referencing the config, remove it
473 * from the list and destroy the proc entry */ 469 * from the list and destroy the proc entry */
@@ -476,12 +472,13 @@ static void destroy(void *matchinfo, unsigned int matchinfosize)
476 clusterip_config_put(cipinfo->config); 472 clusterip_config_put(cipinfo->config);
477} 473}
478 474
479static struct ipt_target clusterip_tgt = { 475static struct ipt_target clusterip_tgt = {
480 .name = "CLUSTERIP", 476 .name = "CLUSTERIP",
481 .target = &target, 477 .target = target,
482 .checkentry = &checkentry, 478 .targetsize = sizeof(struct ipt_clusterip_tgt_info),
483 .destroy = &destroy, 479 .checkentry = checkentry,
484 .me = THIS_MODULE 480 .destroy = destroy,
481 .me = THIS_MODULE
485}; 482};
486 483
487 484
diff --git a/net/ipv4/netfilter/ipt_DSCP.c b/net/ipv4/netfilter/ipt_DSCP.c
index 898cdf79ce18..cfb0b90e598a 100644
--- a/net/ipv4/netfilter/ipt_DSCP.c
+++ b/net/ipv4/netfilter/ipt_DSCP.c
@@ -29,6 +29,7 @@ target(struct sk_buff **pskb,
29 const struct net_device *in, 29 const struct net_device *in,
30 const struct net_device *out, 30 const struct net_device *out,
31 unsigned int hooknum, 31 unsigned int hooknum,
32 const struct xt_target *target,
32 const void *targinfo, 33 const void *targinfo,
33 void *userinfo) 34 void *userinfo)
34{ 35{
@@ -58,35 +59,25 @@ target(struct sk_buff **pskb,
58static int 59static int
59checkentry(const char *tablename, 60checkentry(const char *tablename,
60 const void *e_void, 61 const void *e_void,
62 const struct xt_target *target,
61 void *targinfo, 63 void *targinfo,
62 unsigned int targinfosize, 64 unsigned int targinfosize,
63 unsigned int hook_mask) 65 unsigned int hook_mask)
64{ 66{
65 const u_int8_t dscp = ((struct ipt_DSCP_info *)targinfo)->dscp; 67 const u_int8_t dscp = ((struct ipt_DSCP_info *)targinfo)->dscp;
66 68
67 if (targinfosize != IPT_ALIGN(sizeof(struct ipt_DSCP_info))) {
68 printk(KERN_WARNING "DSCP: targinfosize %u != %Zu\n",
69 targinfosize,
70 IPT_ALIGN(sizeof(struct ipt_DSCP_info)));
71 return 0;
72 }
73
74 if (strcmp(tablename, "mangle") != 0) {
75 printk(KERN_WARNING "DSCP: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
76 return 0;
77 }
78
79 if ((dscp > IPT_DSCP_MAX)) { 69 if ((dscp > IPT_DSCP_MAX)) {
80 printk(KERN_WARNING "DSCP: dscp %x out of range\n", dscp); 70 printk(KERN_WARNING "DSCP: dscp %x out of range\n", dscp);
81 return 0; 71 return 0;
82 } 72 }
83
84 return 1; 73 return 1;
85} 74}
86 75
87static struct ipt_target ipt_dscp_reg = { 76static struct ipt_target ipt_dscp_reg = {
88 .name = "DSCP", 77 .name = "DSCP",
89 .target = target, 78 .target = target,
79 .targetsize = sizeof(struct ipt_DSCP_info),
80 .table = "mangle",
90 .checkentry = checkentry, 81 .checkentry = checkentry,
91 .me = THIS_MODULE, 82 .me = THIS_MODULE,
92}; 83};
diff --git a/net/ipv4/netfilter/ipt_ECN.c b/net/ipv4/netfilter/ipt_ECN.c
index 706445426a6d..b9b80f90c84e 100644
--- a/net/ipv4/netfilter/ipt_ECN.c
+++ b/net/ipv4/netfilter/ipt_ECN.c
@@ -94,6 +94,7 @@ target(struct sk_buff **pskb,
94 const struct net_device *in, 94 const struct net_device *in,
95 const struct net_device *out, 95 const struct net_device *out,
96 unsigned int hooknum, 96 unsigned int hooknum,
97 const struct xt_target *target,
97 const void *targinfo, 98 const void *targinfo,
98 void *userinfo) 99 void *userinfo)
99{ 100{
@@ -114,6 +115,7 @@ target(struct sk_buff **pskb,
114static int 115static int
115checkentry(const char *tablename, 116checkentry(const char *tablename,
116 const void *e_void, 117 const void *e_void,
118 const struct xt_target *target,
117 void *targinfo, 119 void *targinfo,
118 unsigned int targinfosize, 120 unsigned int targinfosize,
119 unsigned int hook_mask) 121 unsigned int hook_mask)
@@ -121,18 +123,6 @@ checkentry(const char *tablename,
121 const struct ipt_ECN_info *einfo = (struct ipt_ECN_info *)targinfo; 123 const struct ipt_ECN_info *einfo = (struct ipt_ECN_info *)targinfo;
122 const struct ipt_entry *e = e_void; 124 const struct ipt_entry *e = e_void;
123 125
124 if (targinfosize != IPT_ALIGN(sizeof(struct ipt_ECN_info))) {
125 printk(KERN_WARNING "ECN: targinfosize %u != %Zu\n",
126 targinfosize,
127 IPT_ALIGN(sizeof(struct ipt_ECN_info)));
128 return 0;
129 }
130
131 if (strcmp(tablename, "mangle") != 0) {
132 printk(KERN_WARNING "ECN: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
133 return 0;
134 }
135
136 if (einfo->operation & IPT_ECN_OP_MASK) { 126 if (einfo->operation & IPT_ECN_OP_MASK) {
137 printk(KERN_WARNING "ECN: unsupported ECN operation %x\n", 127 printk(KERN_WARNING "ECN: unsupported ECN operation %x\n",
138 einfo->operation); 128 einfo->operation);
@@ -143,20 +133,20 @@ checkentry(const char *tablename,
143 einfo->ip_ect); 133 einfo->ip_ect);
144 return 0; 134 return 0;
145 } 135 }
146
147 if ((einfo->operation & (IPT_ECN_OP_SET_ECE|IPT_ECN_OP_SET_CWR)) 136 if ((einfo->operation & (IPT_ECN_OP_SET_ECE|IPT_ECN_OP_SET_CWR))
148 && (e->ip.proto != IPPROTO_TCP || (e->ip.invflags & IPT_INV_PROTO))) { 137 && (e->ip.proto != IPPROTO_TCP || (e->ip.invflags & IPT_INV_PROTO))) {
149 printk(KERN_WARNING "ECN: cannot use TCP operations on a " 138 printk(KERN_WARNING "ECN: cannot use TCP operations on a "
150 "non-tcp rule\n"); 139 "non-tcp rule\n");
151 return 0; 140 return 0;
152 } 141 }
153
154 return 1; 142 return 1;
155} 143}
156 144
157static struct ipt_target ipt_ecn_reg = { 145static struct ipt_target ipt_ecn_reg = {
158 .name = "ECN", 146 .name = "ECN",
159 .target = target, 147 .target = target,
148 .targetsize = sizeof(struct ipt_ECN_info),
149 .table = "mangle",
160 .checkentry = checkentry, 150 .checkentry = checkentry,
161 .me = THIS_MODULE, 151 .me = THIS_MODULE,
162}; 152};
diff --git a/net/ipv4/netfilter/ipt_LOG.c b/net/ipv4/netfilter/ipt_LOG.c
index cc27545ff97f..750d3221b280 100644
--- a/net/ipv4/netfilter/ipt_LOG.c
+++ b/net/ipv4/netfilter/ipt_LOG.c
@@ -415,6 +415,7 @@ ipt_log_target(struct sk_buff **pskb,
415 const struct net_device *in, 415 const struct net_device *in,
416 const struct net_device *out, 416 const struct net_device *out,
417 unsigned int hooknum, 417 unsigned int hooknum,
418 const struct xt_target *target,
418 const void *targinfo, 419 const void *targinfo,
419 void *userinfo) 420 void *userinfo)
420{ 421{
@@ -437,35 +438,29 @@ ipt_log_target(struct sk_buff **pskb,
437 438
438static int ipt_log_checkentry(const char *tablename, 439static int ipt_log_checkentry(const char *tablename,
439 const void *e, 440 const void *e,
441 const struct xt_target *target,
440 void *targinfo, 442 void *targinfo,
441 unsigned int targinfosize, 443 unsigned int targinfosize,
442 unsigned int hook_mask) 444 unsigned int hook_mask)
443{ 445{
444 const struct ipt_log_info *loginfo = targinfo; 446 const struct ipt_log_info *loginfo = targinfo;
445 447
446 if (targinfosize != IPT_ALIGN(sizeof(struct ipt_log_info))) {
447 DEBUGP("LOG: targinfosize %u != %u\n",
448 targinfosize, IPT_ALIGN(sizeof(struct ipt_log_info)));
449 return 0;
450 }
451
452 if (loginfo->level >= 8) { 448 if (loginfo->level >= 8) {
453 DEBUGP("LOG: level %u >= 8\n", loginfo->level); 449 DEBUGP("LOG: level %u >= 8\n", loginfo->level);
454 return 0; 450 return 0;
455 } 451 }
456
457 if (loginfo->prefix[sizeof(loginfo->prefix)-1] != '\0') { 452 if (loginfo->prefix[sizeof(loginfo->prefix)-1] != '\0') {
458 DEBUGP("LOG: prefix term %i\n", 453 DEBUGP("LOG: prefix term %i\n",
459 loginfo->prefix[sizeof(loginfo->prefix)-1]); 454 loginfo->prefix[sizeof(loginfo->prefix)-1]);
460 return 0; 455 return 0;
461 } 456 }
462
463 return 1; 457 return 1;
464} 458}
465 459
466static struct ipt_target ipt_log_reg = { 460static struct ipt_target ipt_log_reg = {
467 .name = "LOG", 461 .name = "LOG",
468 .target = ipt_log_target, 462 .target = ipt_log_target,
463 .targetsize = sizeof(struct ipt_log_info),
469 .checkentry = ipt_log_checkentry, 464 .checkentry = ipt_log_checkentry,
470 .me = THIS_MODULE, 465 .me = THIS_MODULE,
471}; 466};
diff --git a/net/ipv4/netfilter/ipt_MASQUERADE.c b/net/ipv4/netfilter/ipt_MASQUERADE.c
index 12c56d3343ca..e0c321c3bae5 100644
--- a/net/ipv4/netfilter/ipt_MASQUERADE.c
+++ b/net/ipv4/netfilter/ipt_MASQUERADE.c
@@ -41,25 +41,13 @@ static DEFINE_RWLOCK(masq_lock);
41static int 41static int
42masquerade_check(const char *tablename, 42masquerade_check(const char *tablename,
43 const void *e, 43 const void *e,
44 const struct xt_target *target,
44 void *targinfo, 45 void *targinfo,
45 unsigned int targinfosize, 46 unsigned int targinfosize,
46 unsigned int hook_mask) 47 unsigned int hook_mask)
47{ 48{
48 const struct ip_nat_multi_range_compat *mr = targinfo; 49 const struct ip_nat_multi_range_compat *mr = targinfo;
49 50
50 if (strcmp(tablename, "nat") != 0) {
51 DEBUGP("masquerade_check: bad table `%s'.\n", tablename);
52 return 0;
53 }
54 if (targinfosize != IPT_ALIGN(sizeof(*mr))) {
55 DEBUGP("masquerade_check: size %u != %u.\n",
56 targinfosize, sizeof(*mr));
57 return 0;
58 }
59 if (hook_mask & ~(1 << NF_IP_POST_ROUTING)) {
60 DEBUGP("masquerade_check: bad hooks %x.\n", hook_mask);
61 return 0;
62 }
63 if (mr->range[0].flags & IP_NAT_RANGE_MAP_IPS) { 51 if (mr->range[0].flags & IP_NAT_RANGE_MAP_IPS) {
64 DEBUGP("masquerade_check: bad MAP_IPS.\n"); 52 DEBUGP("masquerade_check: bad MAP_IPS.\n");
65 return 0; 53 return 0;
@@ -76,6 +64,7 @@ masquerade_target(struct sk_buff **pskb,
76 const struct net_device *in, 64 const struct net_device *in,
77 const struct net_device *out, 65 const struct net_device *out,
78 unsigned int hooknum, 66 unsigned int hooknum,
67 const struct xt_target *target,
79 const void *targinfo, 68 const void *targinfo,
80 void *userinfo) 69 void *userinfo)
81{ 70{
@@ -179,6 +168,9 @@ static struct notifier_block masq_inet_notifier = {
179static struct ipt_target masquerade = { 168static struct ipt_target masquerade = {
180 .name = "MASQUERADE", 169 .name = "MASQUERADE",
181 .target = masquerade_target, 170 .target = masquerade_target,
171 .targetsize = sizeof(struct ip_nat_multi_range_compat),
172 .table = "nat",
173 .hooks = 1 << NF_IP_POST_ROUTING,
182 .checkentry = masquerade_check, 174 .checkentry = masquerade_check,
183 .me = THIS_MODULE, 175 .me = THIS_MODULE,
184}; 176};
diff --git a/net/ipv4/netfilter/ipt_NETMAP.c b/net/ipv4/netfilter/ipt_NETMAP.c
index b074467fe67b..fba181c2a426 100644
--- a/net/ipv4/netfilter/ipt_NETMAP.c
+++ b/net/ipv4/netfilter/ipt_NETMAP.c
@@ -32,25 +32,13 @@ MODULE_DESCRIPTION("iptables 1:1 NAT mapping of IP networks target");
32static int 32static int
33check(const char *tablename, 33check(const char *tablename,
34 const void *e, 34 const void *e,
35 const struct xt_target *target,
35 void *targinfo, 36 void *targinfo,
36 unsigned int targinfosize, 37 unsigned int targinfosize,
37 unsigned int hook_mask) 38 unsigned int hook_mask)
38{ 39{
39 const struct ip_nat_multi_range_compat *mr = targinfo; 40 const struct ip_nat_multi_range_compat *mr = targinfo;
40 41
41 if (strcmp(tablename, "nat") != 0) {
42 DEBUGP(MODULENAME":check: bad table `%s'.\n", tablename);
43 return 0;
44 }
45 if (targinfosize != IPT_ALIGN(sizeof(*mr))) {
46 DEBUGP(MODULENAME":check: size %u.\n", targinfosize);
47 return 0;
48 }
49 if (hook_mask & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_POST_ROUTING) |
50 (1 << NF_IP_LOCAL_OUT))) {
51 DEBUGP(MODULENAME":check: bad hooks %x.\n", hook_mask);
52 return 0;
53 }
54 if (!(mr->range[0].flags & IP_NAT_RANGE_MAP_IPS)) { 42 if (!(mr->range[0].flags & IP_NAT_RANGE_MAP_IPS)) {
55 DEBUGP(MODULENAME":check: bad MAP_IPS.\n"); 43 DEBUGP(MODULENAME":check: bad MAP_IPS.\n");
56 return 0; 44 return 0;
@@ -67,6 +55,7 @@ target(struct sk_buff **pskb,
67 const struct net_device *in, 55 const struct net_device *in,
68 const struct net_device *out, 56 const struct net_device *out,
69 unsigned int hooknum, 57 unsigned int hooknum,
58 const struct xt_target *target,
70 const void *targinfo, 59 const void *targinfo,
71 void *userinfo) 60 void *userinfo)
72{ 61{
@@ -101,6 +90,10 @@ target(struct sk_buff **pskb,
101static struct ipt_target target_module = { 90static struct ipt_target target_module = {
102 .name = MODULENAME, 91 .name = MODULENAME,
103 .target = target, 92 .target = target,
93 .targetsize = sizeof(struct ip_nat_multi_range_compat),
94 .table = "nat",
95 .hooks = (1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_POST_ROUTING) |
96 (1 << NF_IP_LOCAL_OUT),
104 .checkentry = check, 97 .checkentry = check,
105 .me = THIS_MODULE 98 .me = THIS_MODULE
106}; 99};
diff --git a/net/ipv4/netfilter/ipt_REDIRECT.c b/net/ipv4/netfilter/ipt_REDIRECT.c
index 140be51f2f01..be3da7c4b871 100644
--- a/net/ipv4/netfilter/ipt_REDIRECT.c
+++ b/net/ipv4/netfilter/ipt_REDIRECT.c
@@ -34,24 +34,13 @@ MODULE_DESCRIPTION("iptables REDIRECT target module");
34static int 34static int
35redirect_check(const char *tablename, 35redirect_check(const char *tablename,
36 const void *e, 36 const void *e,
37 const struct xt_target *target,
37 void *targinfo, 38 void *targinfo,
38 unsigned int targinfosize, 39 unsigned int targinfosize,
39 unsigned int hook_mask) 40 unsigned int hook_mask)
40{ 41{
41 const struct ip_nat_multi_range_compat *mr = targinfo; 42 const struct ip_nat_multi_range_compat *mr = targinfo;
42 43
43 if (strcmp(tablename, "nat") != 0) {
44 DEBUGP("redirect_check: bad table `%s'.\n", table);
45 return 0;
46 }
47 if (targinfosize != IPT_ALIGN(sizeof(*mr))) {
48 DEBUGP("redirect_check: size %u.\n", targinfosize);
49 return 0;
50 }
51 if (hook_mask & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_OUT))) {
52 DEBUGP("redirect_check: bad hooks %x.\n", hook_mask);
53 return 0;
54 }
55 if (mr->range[0].flags & IP_NAT_RANGE_MAP_IPS) { 44 if (mr->range[0].flags & IP_NAT_RANGE_MAP_IPS) {
56 DEBUGP("redirect_check: bad MAP_IPS.\n"); 45 DEBUGP("redirect_check: bad MAP_IPS.\n");
57 return 0; 46 return 0;
@@ -68,6 +57,7 @@ redirect_target(struct sk_buff **pskb,
68 const struct net_device *in, 57 const struct net_device *in,
69 const struct net_device *out, 58 const struct net_device *out,
70 unsigned int hooknum, 59 unsigned int hooknum,
60 const struct xt_target *target,
71 const void *targinfo, 61 const void *targinfo,
72 void *userinfo) 62 void *userinfo)
73{ 63{
@@ -115,6 +105,9 @@ redirect_target(struct sk_buff **pskb,
115static struct ipt_target redirect_reg = { 105static struct ipt_target redirect_reg = {
116 .name = "REDIRECT", 106 .name = "REDIRECT",
117 .target = redirect_target, 107 .target = redirect_target,
108 .targetsize = sizeof(struct ip_nat_multi_range_compat),
109 .table = "nat",
110 .hooks = (1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_OUT),
118 .checkentry = redirect_check, 111 .checkentry = redirect_check,
119 .me = THIS_MODULE, 112 .me = THIS_MODULE,
120}; 113};
diff --git a/net/ipv4/netfilter/ipt_REJECT.c b/net/ipv4/netfilter/ipt_REJECT.c
index 3eb47aae78c5..9d3b3579f27c 100644
--- a/net/ipv4/netfilter/ipt_REJECT.c
+++ b/net/ipv4/netfilter/ipt_REJECT.c
@@ -154,10 +154,6 @@ static void send_reset(struct sk_buff *oldskb, int hook)
154 /* This packet will not be the same as the other: clear nf fields */ 154 /* This packet will not be the same as the other: clear nf fields */
155 nf_reset(nskb); 155 nf_reset(nskb);
156 nskb->nfmark = 0; 156 nskb->nfmark = 0;
157#ifdef CONFIG_BRIDGE_NETFILTER
158 nf_bridge_put(nskb->nf_bridge);
159 nskb->nf_bridge = NULL;
160#endif
161 157
162 tcph = (struct tcphdr *)((u_int32_t*)nskb->nh.iph + nskb->nh.iph->ihl); 158 tcph = (struct tcphdr *)((u_int32_t*)nskb->nh.iph + nskb->nh.iph->ihl);
163 159
@@ -236,6 +232,7 @@ static unsigned int reject(struct sk_buff **pskb,
236 const struct net_device *in, 232 const struct net_device *in,
237 const struct net_device *out, 233 const struct net_device *out,
238 unsigned int hooknum, 234 unsigned int hooknum,
235 const struct xt_target *target,
239 const void *targinfo, 236 const void *targinfo,
240 void *userinfo) 237 void *userinfo)
241{ 238{
@@ -283,6 +280,7 @@ static unsigned int reject(struct sk_buff **pskb,
283 280
284static int check(const char *tablename, 281static int check(const char *tablename,
285 const void *e_void, 282 const void *e_void,
283 const struct xt_target *target,
286 void *targinfo, 284 void *targinfo,
287 unsigned int targinfosize, 285 unsigned int targinfosize,
288 unsigned int hook_mask) 286 unsigned int hook_mask)
@@ -290,23 +288,6 @@ static int check(const char *tablename,
290 const struct ipt_reject_info *rejinfo = targinfo; 288 const struct ipt_reject_info *rejinfo = targinfo;
291 const struct ipt_entry *e = e_void; 289 const struct ipt_entry *e = e_void;
292 290
293 if (targinfosize != IPT_ALIGN(sizeof(struct ipt_reject_info))) {
294 DEBUGP("REJECT: targinfosize %u != 0\n", targinfosize);
295 return 0;
296 }
297
298 /* Only allow these for packet filtering. */
299 if (strcmp(tablename, "filter") != 0) {
300 DEBUGP("REJECT: bad table `%s'.\n", tablename);
301 return 0;
302 }
303 if ((hook_mask & ~((1 << NF_IP_LOCAL_IN)
304 | (1 << NF_IP_FORWARD)
305 | (1 << NF_IP_LOCAL_OUT))) != 0) {
306 DEBUGP("REJECT: bad hook mask %X\n", hook_mask);
307 return 0;
308 }
309
310 if (rejinfo->with == IPT_ICMP_ECHOREPLY) { 291 if (rejinfo->with == IPT_ICMP_ECHOREPLY) {
311 printk("REJECT: ECHOREPLY no longer supported.\n"); 292 printk("REJECT: ECHOREPLY no longer supported.\n");
312 return 0; 293 return 0;
@@ -318,13 +299,16 @@ static int check(const char *tablename,
318 return 0; 299 return 0;
319 } 300 }
320 } 301 }
321
322 return 1; 302 return 1;
323} 303}
324 304
325static struct ipt_target ipt_reject_reg = { 305static struct ipt_target ipt_reject_reg = {
326 .name = "REJECT", 306 .name = "REJECT",
327 .target = reject, 307 .target = reject,
308 .targetsize = sizeof(struct ipt_reject_info),
309 .table = "filter",
310 .hooks = (1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD) |
311 (1 << NF_IP_LOCAL_OUT),
328 .checkentry = check, 312 .checkentry = check,
329 .me = THIS_MODULE, 313 .me = THIS_MODULE,
330}; 314};
diff --git a/net/ipv4/netfilter/ipt_SAME.c b/net/ipv4/netfilter/ipt_SAME.c
index a22de59bba0e..7e2ebc9d945e 100644
--- a/net/ipv4/netfilter/ipt_SAME.c
+++ b/net/ipv4/netfilter/ipt_SAME.c
@@ -50,6 +50,7 @@ MODULE_DESCRIPTION("iptables special SNAT module for consistent sourceip");
50static int 50static int
51same_check(const char *tablename, 51same_check(const char *tablename,
52 const void *e, 52 const void *e,
53 const struct xt_target *target,
53 void *targinfo, 54 void *targinfo,
54 unsigned int targinfosize, 55 unsigned int targinfosize,
55 unsigned int hook_mask) 56 unsigned int hook_mask)
@@ -59,18 +60,6 @@ same_check(const char *tablename,
59 60
60 mr->ipnum = 0; 61 mr->ipnum = 0;
61 62
62 if (strcmp(tablename, "nat") != 0) {
63 DEBUGP("same_check: bad table `%s'.\n", tablename);
64 return 0;
65 }
66 if (targinfosize != IPT_ALIGN(sizeof(*mr))) {
67 DEBUGP("same_check: size %u.\n", targinfosize);
68 return 0;
69 }
70 if (hook_mask & ~(1 << NF_IP_PRE_ROUTING | 1 << NF_IP_POST_ROUTING)) {
71 DEBUGP("same_check: bad hooks %x.\n", hook_mask);
72 return 0;
73 }
74 if (mr->rangesize < 1) { 63 if (mr->rangesize < 1) {
75 DEBUGP("same_check: need at least one dest range.\n"); 64 DEBUGP("same_check: need at least one dest range.\n");
76 return 0; 65 return 0;
@@ -127,7 +116,7 @@ same_check(const char *tablename,
127} 116}
128 117
129static void 118static void
130same_destroy(void *targinfo, 119same_destroy(const struct xt_target *target, void *targinfo,
131 unsigned int targinfosize) 120 unsigned int targinfosize)
132{ 121{
133 struct ipt_same_info *mr = targinfo; 122 struct ipt_same_info *mr = targinfo;
@@ -143,6 +132,7 @@ same_target(struct sk_buff **pskb,
143 const struct net_device *in, 132 const struct net_device *in,
144 const struct net_device *out, 133 const struct net_device *out,
145 unsigned int hooknum, 134 unsigned int hooknum,
135 const struct xt_target *target,
146 const void *targinfo, 136 const void *targinfo,
147 void *userinfo) 137 void *userinfo)
148{ 138{
@@ -191,6 +181,9 @@ same_target(struct sk_buff **pskb,
191static struct ipt_target same_reg = { 181static struct ipt_target same_reg = {
192 .name = "SAME", 182 .name = "SAME",
193 .target = same_target, 183 .target = same_target,
184 .targetsize = sizeof(struct ipt_same_info),
185 .table = "nat",
186 .hooks = (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_POST_ROUTING),
194 .checkentry = same_check, 187 .checkentry = same_check,
195 .destroy = same_destroy, 188 .destroy = same_destroy,
196 .me = THIS_MODULE, 189 .me = THIS_MODULE,
diff --git a/net/ipv4/netfilter/ipt_TCPMSS.c b/net/ipv4/netfilter/ipt_TCPMSS.c
index c122841e182c..c4fc50ec2ddb 100644
--- a/net/ipv4/netfilter/ipt_TCPMSS.c
+++ b/net/ipv4/netfilter/ipt_TCPMSS.c
@@ -48,6 +48,7 @@ ipt_tcpmss_target(struct sk_buff **pskb,
48 const struct net_device *in, 48 const struct net_device *in,
49 const struct net_device *out, 49 const struct net_device *out,
50 unsigned int hooknum, 50 unsigned int hooknum,
51 const struct xt_target *target,
51 const void *targinfo, 52 const void *targinfo,
52 void *userinfo) 53 void *userinfo)
53{ 54{
@@ -211,6 +212,7 @@ static inline int find_syn_match(const struct ipt_entry_match *m)
211static int 212static int
212ipt_tcpmss_checkentry(const char *tablename, 213ipt_tcpmss_checkentry(const char *tablename,
213 const void *e_void, 214 const void *e_void,
215 const struct xt_target *target,
214 void *targinfo, 216 void *targinfo,
215 unsigned int targinfosize, 217 unsigned int targinfosize,
216 unsigned int hook_mask) 218 unsigned int hook_mask)
@@ -218,13 +220,6 @@ ipt_tcpmss_checkentry(const char *tablename,
218 const struct ipt_tcpmss_info *tcpmssinfo = targinfo; 220 const struct ipt_tcpmss_info *tcpmssinfo = targinfo;
219 const struct ipt_entry *e = e_void; 221 const struct ipt_entry *e = e_void;
220 222
221 if (targinfosize != IPT_ALIGN(sizeof(struct ipt_tcpmss_info))) {
222 DEBUGP("ipt_tcpmss_checkentry: targinfosize %u != %u\n",
223 targinfosize, IPT_ALIGN(sizeof(struct ipt_tcpmss_info)));
224 return 0;
225 }
226
227
228 if((tcpmssinfo->mss == IPT_TCPMSS_CLAMP_PMTU) && 223 if((tcpmssinfo->mss == IPT_TCPMSS_CLAMP_PMTU) &&
229 ((hook_mask & ~((1 << NF_IP_FORWARD) 224 ((hook_mask & ~((1 << NF_IP_FORWARD)
230 | (1 << NF_IP_LOCAL_OUT) 225 | (1 << NF_IP_LOCAL_OUT)
@@ -233,11 +228,8 @@ ipt_tcpmss_checkentry(const char *tablename,
233 return 0; 228 return 0;
234 } 229 }
235 230
236 if (e->ip.proto == IPPROTO_TCP 231 if (IPT_MATCH_ITERATE(e, find_syn_match))
237 && !(e->ip.invflags & IPT_INV_PROTO)
238 && IPT_MATCH_ITERATE(e, find_syn_match))
239 return 1; 232 return 1;
240
241 printk("TCPMSS: Only works on TCP SYN packets\n"); 233 printk("TCPMSS: Only works on TCP SYN packets\n");
242 return 0; 234 return 0;
243} 235}
@@ -245,6 +237,8 @@ ipt_tcpmss_checkentry(const char *tablename,
245static struct ipt_target ipt_tcpmss_reg = { 237static struct ipt_target ipt_tcpmss_reg = {
246 .name = "TCPMSS", 238 .name = "TCPMSS",
247 .target = ipt_tcpmss_target, 239 .target = ipt_tcpmss_target,
240 .targetsize = sizeof(struct ipt_tcpmss_info),
241 .proto = IPPROTO_TCP,
248 .checkentry = ipt_tcpmss_checkentry, 242 .checkentry = ipt_tcpmss_checkentry,
249 .me = THIS_MODULE, 243 .me = THIS_MODULE,
250}; 244};
diff --git a/net/ipv4/netfilter/ipt_TOS.c b/net/ipv4/netfilter/ipt_TOS.c
index 3a44a56db239..9aa7817657f0 100644
--- a/net/ipv4/netfilter/ipt_TOS.c
+++ b/net/ipv4/netfilter/ipt_TOS.c
@@ -25,6 +25,7 @@ target(struct sk_buff **pskb,
25 const struct net_device *in, 25 const struct net_device *in,
26 const struct net_device *out, 26 const struct net_device *out,
27 unsigned int hooknum, 27 unsigned int hooknum,
28 const struct xt_target *target,
28 const void *targinfo, 29 const void *targinfo,
29 void *userinfo) 30 void *userinfo)
30{ 31{
@@ -53,24 +54,13 @@ target(struct sk_buff **pskb,
53static int 54static int
54checkentry(const char *tablename, 55checkentry(const char *tablename,
55 const void *e_void, 56 const void *e_void,
57 const struct xt_target *target,
56 void *targinfo, 58 void *targinfo,
57 unsigned int targinfosize, 59 unsigned int targinfosize,
58 unsigned int hook_mask) 60 unsigned int hook_mask)
59{ 61{
60 const u_int8_t tos = ((struct ipt_tos_target_info *)targinfo)->tos; 62 const u_int8_t tos = ((struct ipt_tos_target_info *)targinfo)->tos;
61 63
62 if (targinfosize != IPT_ALIGN(sizeof(struct ipt_tos_target_info))) {
63 printk(KERN_WARNING "TOS: targinfosize %u != %Zu\n",
64 targinfosize,
65 IPT_ALIGN(sizeof(struct ipt_tos_target_info)));
66 return 0;
67 }
68
69 if (strcmp(tablename, "mangle") != 0) {
70 printk(KERN_WARNING "TOS: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
71 return 0;
72 }
73
74 if (tos != IPTOS_LOWDELAY 64 if (tos != IPTOS_LOWDELAY
75 && tos != IPTOS_THROUGHPUT 65 && tos != IPTOS_THROUGHPUT
76 && tos != IPTOS_RELIABILITY 66 && tos != IPTOS_RELIABILITY
@@ -79,13 +69,14 @@ checkentry(const char *tablename,
79 printk(KERN_WARNING "TOS: bad tos value %#x\n", tos); 69 printk(KERN_WARNING "TOS: bad tos value %#x\n", tos);
80 return 0; 70 return 0;
81 } 71 }
82
83 return 1; 72 return 1;
84} 73}
85 74
86static struct ipt_target ipt_tos_reg = { 75static struct ipt_target ipt_tos_reg = {
87 .name = "TOS", 76 .name = "TOS",
88 .target = target, 77 .target = target,
78 .targetsize = sizeof(struct ipt_tos_target_info),
79 .table = "mangle",
89 .checkentry = checkentry, 80 .checkentry = checkentry,
90 .me = THIS_MODULE, 81 .me = THIS_MODULE,
91}; 82};
diff --git a/net/ipv4/netfilter/ipt_TTL.c b/net/ipv4/netfilter/ipt_TTL.c
index b769eb231970..5009a003d578 100644
--- a/net/ipv4/netfilter/ipt_TTL.c
+++ b/net/ipv4/netfilter/ipt_TTL.c
@@ -20,9 +20,10 @@ MODULE_DESCRIPTION("IP tables TTL modification module");
20MODULE_LICENSE("GPL"); 20MODULE_LICENSE("GPL");
21 21
22static unsigned int 22static unsigned int
23ipt_ttl_target(struct sk_buff **pskb, const struct net_device *in, 23ipt_ttl_target(struct sk_buff **pskb,
24 const struct net_device *out, unsigned int hooknum, 24 const struct net_device *in, const struct net_device *out,
25 const void *targinfo, void *userinfo) 25 unsigned int hooknum, const struct xt_target *target,
26 const void *targinfo, void *userinfo)
26{ 27{
27 struct iphdr *iph; 28 struct iphdr *iph;
28 const struct ipt_TTL_info *info = targinfo; 29 const struct ipt_TTL_info *info = targinfo;
@@ -67,40 +68,28 @@ ipt_ttl_target(struct sk_buff **pskb, const struct net_device *in,
67 68
68static int ipt_ttl_checkentry(const char *tablename, 69static int ipt_ttl_checkentry(const char *tablename,
69 const void *e, 70 const void *e,
71 const struct xt_target *target,
70 void *targinfo, 72 void *targinfo,
71 unsigned int targinfosize, 73 unsigned int targinfosize,
72 unsigned int hook_mask) 74 unsigned int hook_mask)
73{ 75{
74 struct ipt_TTL_info *info = targinfo; 76 struct ipt_TTL_info *info = targinfo;
75 77
76 if (targinfosize != IPT_ALIGN(sizeof(struct ipt_TTL_info))) {
77 printk(KERN_WARNING "ipt_TTL: targinfosize %u != %Zu\n",
78 targinfosize,
79 IPT_ALIGN(sizeof(struct ipt_TTL_info)));
80 return 0;
81 }
82
83 if (strcmp(tablename, "mangle")) {
84 printk(KERN_WARNING "ipt_TTL: can only be called from "
85 "\"mangle\" table, not \"%s\"\n", tablename);
86 return 0;
87 }
88
89 if (info->mode > IPT_TTL_MAXMODE) { 78 if (info->mode > IPT_TTL_MAXMODE) {
90 printk(KERN_WARNING "ipt_TTL: invalid or unknown Mode %u\n", 79 printk(KERN_WARNING "ipt_TTL: invalid or unknown Mode %u\n",
91 info->mode); 80 info->mode);
92 return 0; 81 return 0;
93 } 82 }
94
95 if ((info->mode != IPT_TTL_SET) && (info->ttl == 0)) 83 if ((info->mode != IPT_TTL_SET) && (info->ttl == 0))
96 return 0; 84 return 0;
97
98 return 1; 85 return 1;
99} 86}
100 87
101static struct ipt_target ipt_TTL = { 88static struct ipt_target ipt_TTL = {
102 .name = "TTL", 89 .name = "TTL",
103 .target = ipt_ttl_target, 90 .target = ipt_ttl_target,
91 .targetsize = sizeof(struct ipt_TTL_info),
92 .table = "mangle",
104 .checkentry = ipt_ttl_checkentry, 93 .checkentry = ipt_ttl_checkentry,
105 .me = THIS_MODULE, 94 .me = THIS_MODULE,
106}; 95};
diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
index 180a9ea57b69..a82a32ed0e2f 100644
--- a/net/ipv4/netfilter/ipt_ULOG.c
+++ b/net/ipv4/netfilter/ipt_ULOG.c
@@ -303,6 +303,7 @@ static unsigned int ipt_ulog_target(struct sk_buff **pskb,
303 const struct net_device *in, 303 const struct net_device *in,
304 const struct net_device *out, 304 const struct net_device *out,
305 unsigned int hooknum, 305 unsigned int hooknum,
306 const struct xt_target *target,
306 const void *targinfo, void *userinfo) 307 const void *targinfo, void *userinfo)
307{ 308{
308 struct ipt_ulog_info *loginfo = (struct ipt_ulog_info *) targinfo; 309 struct ipt_ulog_info *loginfo = (struct ipt_ulog_info *) targinfo;
@@ -339,42 +340,37 @@ static void ipt_logfn(unsigned int pf,
339 340
340static int ipt_ulog_checkentry(const char *tablename, 341static int ipt_ulog_checkentry(const char *tablename,
341 const void *e, 342 const void *e,
343 const struct xt_target *target,
342 void *targinfo, 344 void *targinfo,
343 unsigned int targinfosize, 345 unsigned int targinfosize,
344 unsigned int hookmask) 346 unsigned int hookmask)
345{ 347{
346 struct ipt_ulog_info *loginfo = (struct ipt_ulog_info *) targinfo; 348 struct ipt_ulog_info *loginfo = (struct ipt_ulog_info *) targinfo;
347 349
348 if (targinfosize != IPT_ALIGN(sizeof(struct ipt_ulog_info))) {
349 DEBUGP("ipt_ULOG: targinfosize %u != 0\n", targinfosize);
350 return 0;
351 }
352
353 if (loginfo->prefix[sizeof(loginfo->prefix) - 1] != '\0') { 350 if (loginfo->prefix[sizeof(loginfo->prefix) - 1] != '\0') {
354 DEBUGP("ipt_ULOG: prefix term %i\n", 351 DEBUGP("ipt_ULOG: prefix term %i\n",
355 loginfo->prefix[sizeof(loginfo->prefix) - 1]); 352 loginfo->prefix[sizeof(loginfo->prefix) - 1]);
356 return 0; 353 return 0;
357 } 354 }
358
359 if (loginfo->qthreshold > ULOG_MAX_QLEN) { 355 if (loginfo->qthreshold > ULOG_MAX_QLEN) {
360 DEBUGP("ipt_ULOG: queue threshold %i > MAX_QLEN\n", 356 DEBUGP("ipt_ULOG: queue threshold %i > MAX_QLEN\n",
361 loginfo->qthreshold); 357 loginfo->qthreshold);
362 return 0; 358 return 0;
363 } 359 }
364
365 return 1; 360 return 1;
366} 361}
367 362
368static struct ipt_target ipt_ulog_reg = { 363static struct ipt_target ipt_ulog_reg = {
369 .name = "ULOG", 364 .name = "ULOG",
370 .target = ipt_ulog_target, 365 .target = ipt_ulog_target,
366 .targetsize = sizeof(struct ipt_ulog_info),
371 .checkentry = ipt_ulog_checkentry, 367 .checkentry = ipt_ulog_checkentry,
372 .me = THIS_MODULE, 368 .me = THIS_MODULE,
373}; 369};
374 370
375static struct nf_logger ipt_ulog_logger = { 371static struct nf_logger ipt_ulog_logger = {
376 .name = "ipt_ULOG", 372 .name = "ipt_ULOG",
377 .logfn = &ipt_logfn, 373 .logfn = ipt_logfn,
378 .me = THIS_MODULE, 374 .me = THIS_MODULE,
379}; 375};
380 376
diff --git a/net/ipv4/netfilter/ipt_addrtype.c b/net/ipv4/netfilter/ipt_addrtype.c
index d6b83a976518..5fdf85d0efcf 100644
--- a/net/ipv4/netfilter/ipt_addrtype.c
+++ b/net/ipv4/netfilter/ipt_addrtype.c
@@ -27,8 +27,9 @@ static inline int match_type(u_int32_t addr, u_int16_t mask)
27 return !!(mask & (1 << inet_addr_type(addr))); 27 return !!(mask & (1 << inet_addr_type(addr)));
28} 28}
29 29
30static int match(const struct sk_buff *skb, const struct net_device *in, 30static int match(const struct sk_buff *skb,
31 const struct net_device *out, const void *matchinfo, 31 const struct net_device *in, const struct net_device *out,
32 const struct xt_match *match, const void *matchinfo,
32 int offset, unsigned int protoff, int *hotdrop) 33 int offset, unsigned int protoff, int *hotdrop)
33{ 34{
34 const struct ipt_addrtype_info *info = matchinfo; 35 const struct ipt_addrtype_info *info = matchinfo;
@@ -43,23 +44,10 @@ static int match(const struct sk_buff *skb, const struct net_device *in,
43 return ret; 44 return ret;
44} 45}
45 46
46static int checkentry(const char *tablename, const void *ip,
47 void *matchinfo, unsigned int matchsize,
48 unsigned int hook_mask)
49{
50 if (matchsize != IPT_ALIGN(sizeof(struct ipt_addrtype_info))) {
51 printk(KERN_ERR "ipt_addrtype: invalid size (%u != %Zu)\n",
52 matchsize, IPT_ALIGN(sizeof(struct ipt_addrtype_info)));
53 return 0;
54 }
55
56 return 1;
57}
58
59static struct ipt_match addrtype_match = { 47static struct ipt_match addrtype_match = {
60 .name = "addrtype", 48 .name = "addrtype",
61 .match = match, 49 .match = match,
62 .checkentry = checkentry, 50 .matchsize = sizeof(struct ipt_addrtype_info),
63 .me = THIS_MODULE 51 .me = THIS_MODULE
64}; 52};
65 53
diff --git a/net/ipv4/netfilter/ipt_ah.c b/net/ipv4/netfilter/ipt_ah.c
index 144adfec13cc..35a21fb1f8e0 100644
--- a/net/ipv4/netfilter/ipt_ah.c
+++ b/net/ipv4/netfilter/ipt_ah.c
@@ -39,6 +39,7 @@ static int
39match(const struct sk_buff *skb, 39match(const struct sk_buff *skb,
40 const struct net_device *in, 40 const struct net_device *in,
41 const struct net_device *out, 41 const struct net_device *out,
42 const struct xt_match *match,
42 const void *matchinfo, 43 const void *matchinfo,
43 int offset, 44 int offset,
44 unsigned int protoff, 45 unsigned int protoff,
@@ -71,37 +72,27 @@ match(const struct sk_buff *skb,
71static int 72static int
72checkentry(const char *tablename, 73checkentry(const char *tablename,
73 const void *ip_void, 74 const void *ip_void,
75 const struct xt_match *match,
74 void *matchinfo, 76 void *matchinfo,
75 unsigned int matchinfosize, 77 unsigned int matchinfosize,
76 unsigned int hook_mask) 78 unsigned int hook_mask)
77{ 79{
78 const struct ipt_ah *ahinfo = matchinfo; 80 const struct ipt_ah *ahinfo = matchinfo;
79 const struct ipt_ip *ip = ip_void;
80 81
81 /* Must specify proto == AH, and no unknown invflags */ 82 /* Must specify no unknown invflags */
82 if (ip->proto != IPPROTO_AH || (ip->invflags & IPT_INV_PROTO)) {
83 duprintf("ipt_ah: Protocol %u != %u\n", ip->proto,
84 IPPROTO_AH);
85 return 0;
86 }
87 if (matchinfosize != IPT_ALIGN(sizeof(struct ipt_ah))) {
88 duprintf("ipt_ah: matchsize %u != %u\n",
89 matchinfosize, IPT_ALIGN(sizeof(struct ipt_ah)));
90 return 0;
91 }
92 if (ahinfo->invflags & ~IPT_AH_INV_MASK) { 83 if (ahinfo->invflags & ~IPT_AH_INV_MASK) {
93 duprintf("ipt_ah: unknown flags %X\n", 84 duprintf("ipt_ah: unknown flags %X\n", ahinfo->invflags);
94 ahinfo->invflags);
95 return 0; 85 return 0;
96 } 86 }
97
98 return 1; 87 return 1;
99} 88}
100 89
101static struct ipt_match ah_match = { 90static struct ipt_match ah_match = {
102 .name = "ah", 91 .name = "ah",
103 .match = &match, 92 .match = match,
104 .checkentry = &checkentry, 93 .matchsize = sizeof(struct ipt_ah),
94 .proto = IPPROTO_AH,
95 .checkentry = checkentry,
105 .me = THIS_MODULE, 96 .me = THIS_MODULE,
106}; 97};
107 98
diff --git a/net/ipv4/netfilter/ipt_dscp.c b/net/ipv4/netfilter/ipt_dscp.c
index 92063b4f8602..11963c385dea 100644
--- a/net/ipv4/netfilter/ipt_dscp.c
+++ b/net/ipv4/netfilter/ipt_dscp.c
@@ -19,8 +19,9 @@ MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
19MODULE_DESCRIPTION("iptables DSCP matching module"); 19MODULE_DESCRIPTION("iptables DSCP matching module");
20MODULE_LICENSE("GPL"); 20MODULE_LICENSE("GPL");
21 21
22static int match(const struct sk_buff *skb, const struct net_device *in, 22static int match(const struct sk_buff *skb,
23 const struct net_device *out, const void *matchinfo, 23 const struct net_device *in, const struct net_device *out,
24 const struct xt_match *match, const void *matchinfo,
24 int offset, unsigned int protoff, int *hotdrop) 25 int offset, unsigned int protoff, int *hotdrop)
25{ 26{
26 const struct ipt_dscp_info *info = matchinfo; 27 const struct ipt_dscp_info *info = matchinfo;
@@ -31,20 +32,10 @@ static int match(const struct sk_buff *skb, const struct net_device *in,
31 return ((iph->tos&IPT_DSCP_MASK) == sh_dscp) ^ info->invert; 32 return ((iph->tos&IPT_DSCP_MASK) == sh_dscp) ^ info->invert;
32} 33}
33 34
34static int checkentry(const char *tablename, const void *ip,
35 void *matchinfo, unsigned int matchsize,
36 unsigned int hook_mask)
37{
38 if (matchsize != IPT_ALIGN(sizeof(struct ipt_dscp_info)))
39 return 0;
40
41 return 1;
42}
43
44static struct ipt_match dscp_match = { 35static struct ipt_match dscp_match = {
45 .name = "dscp", 36 .name = "dscp",
46 .match = &match, 37 .match = match,
47 .checkentry = &checkentry, 38 .matchsize = sizeof(struct ipt_dscp_info),
48 .me = THIS_MODULE, 39 .me = THIS_MODULE,
49}; 40};
50 41
diff --git a/net/ipv4/netfilter/ipt_ecn.c b/net/ipv4/netfilter/ipt_ecn.c
index e68b0c7981f0..d7e29f6a38d8 100644
--- a/net/ipv4/netfilter/ipt_ecn.c
+++ b/net/ipv4/netfilter/ipt_ecn.c
@@ -65,8 +65,9 @@ static inline int match_tcp(const struct sk_buff *skb,
65 return 1; 65 return 1;
66} 66}
67 67
68static int match(const struct sk_buff *skb, const struct net_device *in, 68static int match(const struct sk_buff *skb,
69 const struct net_device *out, const void *matchinfo, 69 const struct net_device *in, const struct net_device *out,
70 const struct xt_match *match, const void *matchinfo,
70 int offset, unsigned int protoff, int *hotdrop) 71 int offset, unsigned int protoff, int *hotdrop)
71{ 72{
72 const struct ipt_ecn_info *info = matchinfo; 73 const struct ipt_ecn_info *info = matchinfo;
@@ -86,15 +87,13 @@ static int match(const struct sk_buff *skb, const struct net_device *in,
86} 87}
87 88
88static int checkentry(const char *tablename, const void *ip_void, 89static int checkentry(const char *tablename, const void *ip_void,
90 const struct xt_match *match,
89 void *matchinfo, unsigned int matchsize, 91 void *matchinfo, unsigned int matchsize,
90 unsigned int hook_mask) 92 unsigned int hook_mask)
91{ 93{
92 const struct ipt_ecn_info *info = matchinfo; 94 const struct ipt_ecn_info *info = matchinfo;
93 const struct ipt_ip *ip = ip_void; 95 const struct ipt_ip *ip = ip_void;
94 96
95 if (matchsize != IPT_ALIGN(sizeof(struct ipt_ecn_info)))
96 return 0;
97
98 if (info->operation & IPT_ECN_OP_MATCH_MASK) 97 if (info->operation & IPT_ECN_OP_MATCH_MASK)
99 return 0; 98 return 0;
100 99
@@ -113,8 +112,9 @@ static int checkentry(const char *tablename, const void *ip_void,
113 112
114static struct ipt_match ecn_match = { 113static struct ipt_match ecn_match = {
115 .name = "ecn", 114 .name = "ecn",
116 .match = &match, 115 .match = match,
117 .checkentry = &checkentry, 116 .matchsize = sizeof(struct ipt_ecn_info),
117 .checkentry = checkentry,
118 .me = THIS_MODULE, 118 .me = THIS_MODULE,
119}; 119};
120 120
diff --git a/net/ipv4/netfilter/ipt_esp.c b/net/ipv4/netfilter/ipt_esp.c
index 9de191a8162d..af0d5ec79cb5 100644
--- a/net/ipv4/netfilter/ipt_esp.c
+++ b/net/ipv4/netfilter/ipt_esp.c
@@ -40,6 +40,7 @@ static int
40match(const struct sk_buff *skb, 40match(const struct sk_buff *skb,
41 const struct net_device *in, 41 const struct net_device *in,
42 const struct net_device *out, 42 const struct net_device *out,
43 const struct xt_match *match,
43 const void *matchinfo, 44 const void *matchinfo,
44 int offset, 45 int offset,
45 unsigned int protoff, 46 unsigned int protoff,
@@ -72,37 +73,27 @@ match(const struct sk_buff *skb,
72static int 73static int
73checkentry(const char *tablename, 74checkentry(const char *tablename,
74 const void *ip_void, 75 const void *ip_void,
76 const struct xt_match *match,
75 void *matchinfo, 77 void *matchinfo,
76 unsigned int matchinfosize, 78 unsigned int matchinfosize,
77 unsigned int hook_mask) 79 unsigned int hook_mask)
78{ 80{
79 const struct ipt_esp *espinfo = matchinfo; 81 const struct ipt_esp *espinfo = matchinfo;
80 const struct ipt_ip *ip = ip_void;
81 82
82 /* Must specify proto == ESP, and no unknown invflags */ 83 /* Must specify no unknown invflags */
83 if (ip->proto != IPPROTO_ESP || (ip->invflags & IPT_INV_PROTO)) {
84 duprintf("ipt_esp: Protocol %u != %u\n", ip->proto,
85 IPPROTO_ESP);
86 return 0;
87 }
88 if (matchinfosize != IPT_ALIGN(sizeof(struct ipt_esp))) {
89 duprintf("ipt_esp: matchsize %u != %u\n",
90 matchinfosize, IPT_ALIGN(sizeof(struct ipt_esp)));
91 return 0;
92 }
93 if (espinfo->invflags & ~IPT_ESP_INV_MASK) { 84 if (espinfo->invflags & ~IPT_ESP_INV_MASK) {
94 duprintf("ipt_esp: unknown flags %X\n", 85 duprintf("ipt_esp: unknown flags %X\n", espinfo->invflags);
95 espinfo->invflags);
96 return 0; 86 return 0;
97 } 87 }
98
99 return 1; 88 return 1;
100} 89}
101 90
102static struct ipt_match esp_match = { 91static struct ipt_match esp_match = {
103 .name = "esp", 92 .name = "esp",
104 .match = &match, 93 .match = match,
105 .checkentry = &checkentry, 94 .matchsize = sizeof(struct ipt_esp),
95 .proto = IPPROTO_ESP,
96 .checkentry = checkentry,
106 .me = THIS_MODULE, 97 .me = THIS_MODULE,
107}; 98};
108 99
diff --git a/net/ipv4/netfilter/ipt_hashlimit.c b/net/ipv4/netfilter/ipt_hashlimit.c
index 4fe48c1bd5f3..dc1521c5aa81 100644
--- a/net/ipv4/netfilter/ipt_hashlimit.c
+++ b/net/ipv4/netfilter/ipt_hashlimit.c
@@ -427,6 +427,7 @@ static int
427hashlimit_match(const struct sk_buff *skb, 427hashlimit_match(const struct sk_buff *skb,
428 const struct net_device *in, 428 const struct net_device *in,
429 const struct net_device *out, 429 const struct net_device *out,
430 const struct xt_match *match,
430 const void *matchinfo, 431 const void *matchinfo,
431 int offset, 432 int offset,
432 unsigned int protoff, 433 unsigned int protoff,
@@ -506,15 +507,13 @@ hashlimit_match(const struct sk_buff *skb,
506static int 507static int
507hashlimit_checkentry(const char *tablename, 508hashlimit_checkentry(const char *tablename,
508 const void *inf, 509 const void *inf,
510 const struct xt_match *match,
509 void *matchinfo, 511 void *matchinfo,
510 unsigned int matchsize, 512 unsigned int matchsize,
511 unsigned int hook_mask) 513 unsigned int hook_mask)
512{ 514{
513 struct ipt_hashlimit_info *r = matchinfo; 515 struct ipt_hashlimit_info *r = matchinfo;
514 516
515 if (matchsize != IPT_ALIGN(sizeof(struct ipt_hashlimit_info)))
516 return 0;
517
518 /* Check for overflow. */ 517 /* Check for overflow. */
519 if (r->cfg.burst == 0 518 if (r->cfg.burst == 0
520 || user2credits(r->cfg.avg * r->cfg.burst) < 519 || user2credits(r->cfg.avg * r->cfg.burst) <
@@ -558,19 +557,21 @@ hashlimit_checkentry(const char *tablename,
558} 557}
559 558
560static void 559static void
561hashlimit_destroy(void *matchinfo, unsigned int matchsize) 560hashlimit_destroy(const struct xt_match *match, void *matchinfo,
561 unsigned int matchsize)
562{ 562{
563 struct ipt_hashlimit_info *r = (struct ipt_hashlimit_info *) matchinfo; 563 struct ipt_hashlimit_info *r = (struct ipt_hashlimit_info *) matchinfo;
564 564
565 htable_put(r->hinfo); 565 htable_put(r->hinfo);
566} 566}
567 567
568static struct ipt_match ipt_hashlimit = { 568static struct ipt_match ipt_hashlimit = {
569 .name = "hashlimit", 569 .name = "hashlimit",
570 .match = hashlimit_match, 570 .match = hashlimit_match,
571 .checkentry = hashlimit_checkentry, 571 .matchsize = sizeof(struct ipt_hashlimit_info),
572 .destroy = hashlimit_destroy, 572 .checkentry = hashlimit_checkentry,
573 .me = THIS_MODULE 573 .destroy = hashlimit_destroy,
574 .me = THIS_MODULE
574}; 575};
575 576
576/* PROC stuff */ 577/* PROC stuff */
diff --git a/net/ipv4/netfilter/ipt_iprange.c b/net/ipv4/netfilter/ipt_iprange.c
index 13fb16fb7892..ae70112f5e06 100644
--- a/net/ipv4/netfilter/ipt_iprange.c
+++ b/net/ipv4/netfilter/ipt_iprange.c
@@ -27,6 +27,7 @@ static int
27match(const struct sk_buff *skb, 27match(const struct sk_buff *skb,
28 const struct net_device *in, 28 const struct net_device *in,
29 const struct net_device *out, 29 const struct net_device *out,
30 const struct xt_match *match,
30 const void *matchinfo, 31 const void *matchinfo,
31 int offset, unsigned int protoff, int *hotdrop) 32 int offset, unsigned int protoff, int *hotdrop)
32{ 33{
@@ -62,27 +63,12 @@ match(const struct sk_buff *skb,
62 return 1; 63 return 1;
63} 64}
64 65
65static int check(const char *tablename, 66static struct ipt_match iprange_match = {
66 const void *inf, 67 .name = "iprange",
67 void *matchinfo, 68 .match = match,
68 unsigned int matchsize, 69 .matchsize = sizeof(struct ipt_iprange_info),
69 unsigned int hook_mask) 70 .destroy = NULL,
70{ 71 .me = THIS_MODULE
71 /* verify size */
72 if (matchsize != IPT_ALIGN(sizeof(struct ipt_iprange_info)))
73 return 0;
74
75 return 1;
76}
77
78static struct ipt_match iprange_match =
79{
80 .list = { NULL, NULL },
81 .name = "iprange",
82 .match = &match,
83 .checkentry = &check,
84 .destroy = NULL,
85 .me = THIS_MODULE
86}; 72};
87 73
88static int __init init(void) 74static int __init init(void)
diff --git a/net/ipv4/netfilter/ipt_multiport.c b/net/ipv4/netfilter/ipt_multiport.c
index 2d52326553f1..bd07f7c53872 100644
--- a/net/ipv4/netfilter/ipt_multiport.c
+++ b/net/ipv4/netfilter/ipt_multiport.c
@@ -95,6 +95,7 @@ static int
95match(const struct sk_buff *skb, 95match(const struct sk_buff *skb,
96 const struct net_device *in, 96 const struct net_device *in,
97 const struct net_device *out, 97 const struct net_device *out,
98 const struct xt_match *match,
98 const void *matchinfo, 99 const void *matchinfo,
99 int offset, 100 int offset,
100 unsigned int protoff, 101 unsigned int protoff,
@@ -127,6 +128,7 @@ static int
127match_v1(const struct sk_buff *skb, 128match_v1(const struct sk_buff *skb,
128 const struct net_device *in, 129 const struct net_device *in,
129 const struct net_device *out, 130 const struct net_device *out,
131 const struct xt_match *match,
130 const void *matchinfo, 132 const void *matchinfo,
131 int offset, 133 int offset,
132 unsigned int protoff, 134 unsigned int protoff,
@@ -153,40 +155,19 @@ match_v1(const struct sk_buff *skb,
153 return ports_match_v1(multiinfo, ntohs(pptr[0]), ntohs(pptr[1])); 155 return ports_match_v1(multiinfo, ntohs(pptr[0]), ntohs(pptr[1]));
154} 156}
155 157
156/* Called when user tries to insert an entry of this type. */
157static int
158checkentry(const char *tablename,
159 const void *ip,
160 void *matchinfo,
161 unsigned int matchsize,
162 unsigned int hook_mask)
163{
164 return (matchsize == IPT_ALIGN(sizeof(struct ipt_multiport)));
165}
166
167static int
168checkentry_v1(const char *tablename,
169 const void *ip,
170 void *matchinfo,
171 unsigned int matchsize,
172 unsigned int hook_mask)
173{
174 return (matchsize == IPT_ALIGN(sizeof(struct ipt_multiport_v1)));
175}
176
177static struct ipt_match multiport_match = { 158static struct ipt_match multiport_match = {
178 .name = "multiport", 159 .name = "multiport",
179 .revision = 0, 160 .revision = 0,
180 .match = &match, 161 .match = match,
181 .checkentry = &checkentry, 162 .matchsize = sizeof(struct ipt_multiport),
182 .me = THIS_MODULE, 163 .me = THIS_MODULE,
183}; 164};
184 165
185static struct ipt_match multiport_match_v1 = { 166static struct ipt_match multiport_match_v1 = {
186 .name = "multiport", 167 .name = "multiport",
187 .revision = 1, 168 .revision = 1,
188 .match = &match_v1, 169 .match = match_v1,
189 .checkentry = &checkentry_v1, 170 .matchsize = sizeof(struct ipt_multiport_v1),
190 .me = THIS_MODULE, 171 .me = THIS_MODULE,
191}; 172};
192 173
diff --git a/net/ipv4/netfilter/ipt_owner.c b/net/ipv4/netfilter/ipt_owner.c
index 4843d0c9734f..3900428771f3 100644
--- a/net/ipv4/netfilter/ipt_owner.c
+++ b/net/ipv4/netfilter/ipt_owner.c
@@ -25,6 +25,7 @@ static int
25match(const struct sk_buff *skb, 25match(const struct sk_buff *skb,
26 const struct net_device *in, 26 const struct net_device *in,
27 const struct net_device *out, 27 const struct net_device *out,
28 const struct xt_match *match,
28 const void *matchinfo, 29 const void *matchinfo,
29 int offset, 30 int offset,
30 unsigned int protoff, 31 unsigned int protoff,
@@ -53,37 +54,27 @@ match(const struct sk_buff *skb,
53static int 54static int
54checkentry(const char *tablename, 55checkentry(const char *tablename,
55 const void *ip, 56 const void *ip,
57 const struct xt_match *match,
56 void *matchinfo, 58 void *matchinfo,
57 unsigned int matchsize, 59 unsigned int matchsize,
58 unsigned int hook_mask) 60 unsigned int hook_mask)
59{ 61{
60 const struct ipt_owner_info *info = matchinfo; 62 const struct ipt_owner_info *info = matchinfo;
61 63
62 if (hook_mask
63 & ~((1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING))) {
64 printk("ipt_owner: only valid for LOCAL_OUT or POST_ROUTING.\n");
65 return 0;
66 }
67
68 if (matchsize != IPT_ALIGN(sizeof(struct ipt_owner_info))) {
69 printk("Matchsize %u != %Zu\n", matchsize,
70 IPT_ALIGN(sizeof(struct ipt_owner_info)));
71 return 0;
72 }
73
74 if (info->match & (IPT_OWNER_PID|IPT_OWNER_SID|IPT_OWNER_COMM)) { 64 if (info->match & (IPT_OWNER_PID|IPT_OWNER_SID|IPT_OWNER_COMM)) {
75 printk("ipt_owner: pid, sid and command matching " 65 printk("ipt_owner: pid, sid and command matching "
76 "not supported anymore\n"); 66 "not supported anymore\n");
77 return 0; 67 return 0;
78 } 68 }
79
80 return 1; 69 return 1;
81} 70}
82 71
83static struct ipt_match owner_match = { 72static struct ipt_match owner_match = {
84 .name = "owner", 73 .name = "owner",
85 .match = &match, 74 .match = match,
86 .checkentry = &checkentry, 75 .matchsize = sizeof(struct ipt_owner_info),
76 .hooks = (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING),
77 .checkentry = checkentry,
87 .me = THIS_MODULE, 78 .me = THIS_MODULE,
88}; 79};
89 80
diff --git a/net/ipv4/netfilter/ipt_policy.c b/net/ipv4/netfilter/ipt_policy.c
deleted file mode 100644
index 5a7a265280f9..000000000000
--- a/net/ipv4/netfilter/ipt_policy.c
+++ /dev/null
@@ -1,176 +0,0 @@
1/* IP tables module for matching IPsec policy
2 *
3 * Copyright (c) 2004,2005 Patrick McHardy, <kaber@trash.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/kernel.h>
11#include <linux/config.h>
12#include <linux/module.h>
13#include <linux/skbuff.h>
14#include <linux/init.h>
15#include <net/xfrm.h>
16
17#include <linux/netfilter_ipv4.h>
18#include <linux/netfilter_ipv4/ip_tables.h>
19#include <linux/netfilter_ipv4/ipt_policy.h>
20
21MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
22MODULE_DESCRIPTION("IPtables IPsec policy matching module");
23MODULE_LICENSE("GPL");
24
25
26static inline int
27match_xfrm_state(struct xfrm_state *x, const struct ipt_policy_elem *e)
28{
29#define MATCH_ADDR(x,y,z) (!e->match.x || \
30 ((e->x.a4.s_addr == (e->y.a4.s_addr & (z))) \
31 ^ e->invert.x))
32#define MATCH(x,y) (!e->match.x || ((e->x == (y)) ^ e->invert.x))
33
34 return MATCH_ADDR(saddr, smask, x->props.saddr.a4) &&
35 MATCH_ADDR(daddr, dmask, x->id.daddr.a4) &&
36 MATCH(proto, x->id.proto) &&
37 MATCH(mode, x->props.mode) &&
38 MATCH(spi, x->id.spi) &&
39 MATCH(reqid, x->props.reqid);
40}
41
42static int
43match_policy_in(const struct sk_buff *skb, const struct ipt_policy_info *info)
44{
45 const struct ipt_policy_elem *e;
46 struct sec_path *sp = skb->sp;
47 int strict = info->flags & IPT_POLICY_MATCH_STRICT;
48 int i, pos;
49
50 if (sp == NULL)
51 return -1;
52 if (strict && info->len != sp->len)
53 return 0;
54
55 for (i = sp->len - 1; i >= 0; i--) {
56 pos = strict ? i - sp->len + 1 : 0;
57 if (pos >= info->len)
58 return 0;
59 e = &info->pol[pos];
60
61 if (match_xfrm_state(sp->x[i].xvec, e)) {
62 if (!strict)
63 return 1;
64 } else if (strict)
65 return 0;
66 }
67
68 return strict ? 1 : 0;
69}
70
71static int
72match_policy_out(const struct sk_buff *skb, const struct ipt_policy_info *info)
73{
74 const struct ipt_policy_elem *e;
75 struct dst_entry *dst = skb->dst;
76 int strict = info->flags & IPT_POLICY_MATCH_STRICT;
77 int i, pos;
78
79 if (dst->xfrm == NULL)
80 return -1;
81
82 for (i = 0; dst && dst->xfrm; dst = dst->child, i++) {
83 pos = strict ? i : 0;
84 if (pos >= info->len)
85 return 0;
86 e = &info->pol[pos];
87
88 if (match_xfrm_state(dst->xfrm, e)) {
89 if (!strict)
90 return 1;
91 } else if (strict)
92 return 0;
93 }
94
95 return strict ? i == info->len : 0;
96}
97
98static int match(const struct sk_buff *skb,
99 const struct net_device *in,
100 const struct net_device *out,
101 const void *matchinfo,
102 int offset,
103 unsigned int protoff,
104 int *hotdrop)
105{
106 const struct ipt_policy_info *info = matchinfo;
107 int ret;
108
109 if (info->flags & IPT_POLICY_MATCH_IN)
110 ret = match_policy_in(skb, info);
111 else
112 ret = match_policy_out(skb, info);
113
114 if (ret < 0)
115 ret = info->flags & IPT_POLICY_MATCH_NONE ? 1 : 0;
116 else if (info->flags & IPT_POLICY_MATCH_NONE)
117 ret = 0;
118
119 return ret;
120}
121
122static int checkentry(const char *tablename, const void *ip_void,
123 void *matchinfo, unsigned int matchsize,
124 unsigned int hook_mask)
125{
126 struct ipt_policy_info *info = matchinfo;
127
128 if (matchsize != IPT_ALIGN(sizeof(*info))) {
129 printk(KERN_ERR "ipt_policy: matchsize %u != %zu\n",
130 matchsize, IPT_ALIGN(sizeof(*info)));
131 return 0;
132 }
133 if (!(info->flags & (IPT_POLICY_MATCH_IN|IPT_POLICY_MATCH_OUT))) {
134 printk(KERN_ERR "ipt_policy: neither incoming nor "
135 "outgoing policy selected\n");
136 return 0;
137 }
138 if (hook_mask & (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_LOCAL_IN)
139 && info->flags & IPT_POLICY_MATCH_OUT) {
140 printk(KERN_ERR "ipt_policy: output policy not valid in "
141 "PRE_ROUTING and INPUT\n");
142 return 0;
143 }
144 if (hook_mask & (1 << NF_IP_POST_ROUTING | 1 << NF_IP_LOCAL_OUT)
145 && info->flags & IPT_POLICY_MATCH_IN) {
146 printk(KERN_ERR "ipt_policy: input policy not valid in "
147 "POST_ROUTING and OUTPUT\n");
148 return 0;
149 }
150 if (info->len > IPT_POLICY_MAX_ELEM) {
151 printk(KERN_ERR "ipt_policy: too many policy elements\n");
152 return 0;
153 }
154
155 return 1;
156}
157
158static struct ipt_match policy_match = {
159 .name = "policy",
160 .match = match,
161 .checkentry = checkentry,
162 .me = THIS_MODULE,
163};
164
165static int __init init(void)
166{
167 return ipt_register_match(&policy_match);
168}
169
170static void __exit fini(void)
171{
172 ipt_unregister_match(&policy_match);
173}
174
175module_init(init);
176module_exit(fini);
diff --git a/net/ipv4/netfilter/ipt_recent.c b/net/ipv4/netfilter/ipt_recent.c
index 44611d6d14f5..06792ead1da4 100644
--- a/net/ipv4/netfilter/ipt_recent.c
+++ b/net/ipv4/netfilter/ipt_recent.c
@@ -102,6 +102,7 @@ static int
102match(const struct sk_buff *skb, 102match(const struct sk_buff *skb,
103 const struct net_device *in, 103 const struct net_device *in,
104 const struct net_device *out, 104 const struct net_device *out,
105 const struct xt_match *match,
105 const void *matchinfo, 106 const void *matchinfo,
106 int offset, 107 int offset,
107 unsigned int protoff, 108 unsigned int protoff,
@@ -318,7 +319,7 @@ static int ip_recent_ctrl(struct file *file, const char __user *input, unsigned
318 skb->nh.iph->daddr = 0; 319 skb->nh.iph->daddr = 0;
319 /* Clear ttl since we have no way of knowing it */ 320 /* Clear ttl since we have no way of knowing it */
320 skb->nh.iph->ttl = 0; 321 skb->nh.iph->ttl = 0;
321 match(skb,NULL,NULL,info,0,0,NULL); 322 match(skb,NULL,NULL,NULL,info,0,0,NULL);
322 323
323 kfree(skb->nh.iph); 324 kfree(skb->nh.iph);
324out_free_skb: 325out_free_skb:
@@ -356,6 +357,7 @@ static int
356match(const struct sk_buff *skb, 357match(const struct sk_buff *skb,
357 const struct net_device *in, 358 const struct net_device *in,
358 const struct net_device *out, 359 const struct net_device *out,
360 const struct xt_match *match,
359 const void *matchinfo, 361 const void *matchinfo,
360 int offset, 362 int offset,
361 unsigned int protoff, 363 unsigned int protoff,
@@ -657,6 +659,7 @@ match(const struct sk_buff *skb,
657static int 659static int
658checkentry(const char *tablename, 660checkentry(const char *tablename,
659 const void *ip, 661 const void *ip,
662 const struct xt_match *match,
660 void *matchinfo, 663 void *matchinfo,
661 unsigned int matchsize, 664 unsigned int matchsize,
662 unsigned int hook_mask) 665 unsigned int hook_mask)
@@ -670,8 +673,6 @@ checkentry(const char *tablename,
670 if(debug) printk(KERN_INFO RECENT_NAME ": checkentry() entered.\n"); 673 if(debug) printk(KERN_INFO RECENT_NAME ": checkentry() entered.\n");
671#endif 674#endif
672 675
673 if (matchsize != IPT_ALIGN(sizeof(struct ipt_recent_info))) return 0;
674
675 /* seconds and hit_count only valid for CHECK/UPDATE */ 676 /* seconds and hit_count only valid for CHECK/UPDATE */
676 if(info->check_set & IPT_RECENT_SET) { flag++; if(info->seconds || info->hit_count) return 0; } 677 if(info->check_set & IPT_RECENT_SET) { flag++; if(info->seconds || info->hit_count) return 0; }
677 if(info->check_set & IPT_RECENT_REMOVE) { flag++; if(info->seconds || info->hit_count) return 0; } 678 if(info->check_set & IPT_RECENT_REMOVE) { flag++; if(info->seconds || info->hit_count) return 0; }
@@ -871,7 +872,7 @@ checkentry(const char *tablename,
871 * up its memory. 872 * up its memory.
872 */ 873 */
873static void 874static void
874destroy(void *matchinfo, unsigned int matchsize) 875destroy(const struct xt_match *match, void *matchinfo, unsigned int matchsize)
875{ 876{
876 const struct ipt_recent_info *info = matchinfo; 877 const struct ipt_recent_info *info = matchinfo;
877 struct recent_ip_tables *curr_table, *last_table; 878 struct recent_ip_tables *curr_table, *last_table;
@@ -951,12 +952,13 @@ destroy(void *matchinfo, unsigned int matchsize)
951/* This is the structure we pass to ipt_register to register our 952/* This is the structure we pass to ipt_register to register our
952 * module with iptables. 953 * module with iptables.
953 */ 954 */
954static struct ipt_match recent_match = { 955static struct ipt_match recent_match = {
955 .name = "recent", 956 .name = "recent",
956 .match = &match, 957 .match = match,
957 .checkentry = &checkentry, 958 .matchsize = sizeof(struct ipt_recent_info),
958 .destroy = &destroy, 959 .checkentry = checkentry,
959 .me = THIS_MODULE 960 .destroy = destroy,
961 .me = THIS_MODULE
960}; 962};
961 963
962/* Kernel module initialization. */ 964/* Kernel module initialization. */
diff --git a/net/ipv4/netfilter/ipt_tos.c b/net/ipv4/netfilter/ipt_tos.c
index 9ab765e126f2..e404e92ddd01 100644
--- a/net/ipv4/netfilter/ipt_tos.c
+++ b/net/ipv4/netfilter/ipt_tos.c
@@ -21,6 +21,7 @@ static int
21match(const struct sk_buff *skb, 21match(const struct sk_buff *skb,
22 const struct net_device *in, 22 const struct net_device *in,
23 const struct net_device *out, 23 const struct net_device *out,
24 const struct xt_match *match,
24 const void *matchinfo, 25 const void *matchinfo,
25 int offset, 26 int offset,
26 unsigned int protoff, 27 unsigned int protoff,
@@ -31,23 +32,10 @@ match(const struct sk_buff *skb,
31 return (skb->nh.iph->tos == info->tos) ^ info->invert; 32 return (skb->nh.iph->tos == info->tos) ^ info->invert;
32} 33}
33 34
34static int
35checkentry(const char *tablename,
36 const void *ip,
37 void *matchinfo,
38 unsigned int matchsize,
39 unsigned int hook_mask)
40{
41 if (matchsize != IPT_ALIGN(sizeof(struct ipt_tos_info)))
42 return 0;
43
44 return 1;
45}
46
47static struct ipt_match tos_match = { 35static struct ipt_match tos_match = {
48 .name = "tos", 36 .name = "tos",
49 .match = &match, 37 .match = match,
50 .checkentry = &checkentry, 38 .matchsize = sizeof(struct ipt_tos_info),
51 .me = THIS_MODULE, 39 .me = THIS_MODULE,
52}; 40};
53 41
diff --git a/net/ipv4/netfilter/ipt_ttl.c b/net/ipv4/netfilter/ipt_ttl.c
index 82da53f430ab..ae7ce4d8d90e 100644
--- a/net/ipv4/netfilter/ipt_ttl.c
+++ b/net/ipv4/netfilter/ipt_ttl.c
@@ -19,8 +19,9 @@ MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
19MODULE_DESCRIPTION("IP tables TTL matching module"); 19MODULE_DESCRIPTION("IP tables TTL matching module");
20MODULE_LICENSE("GPL"); 20MODULE_LICENSE("GPL");
21 21
22static int match(const struct sk_buff *skb, const struct net_device *in, 22static int match(const struct sk_buff *skb,
23 const struct net_device *out, const void *matchinfo, 23 const struct net_device *in, const struct net_device *out,
24 const struct xt_match *match, const void *matchinfo,
24 int offset, unsigned int protoff, int *hotdrop) 25 int offset, unsigned int protoff, int *hotdrop)
25{ 26{
26 const struct ipt_ttl_info *info = matchinfo; 27 const struct ipt_ttl_info *info = matchinfo;
@@ -47,20 +48,10 @@ static int match(const struct sk_buff *skb, const struct net_device *in,
47 return 0; 48 return 0;
48} 49}
49 50
50static int checkentry(const char *tablename, const void *ip,
51 void *matchinfo, unsigned int matchsize,
52 unsigned int hook_mask)
53{
54 if (matchsize != IPT_ALIGN(sizeof(struct ipt_ttl_info)))
55 return 0;
56
57 return 1;
58}
59
60static struct ipt_match ttl_match = { 51static struct ipt_match ttl_match = {
61 .name = "ttl", 52 .name = "ttl",
62 .match = &match, 53 .match = match,
63 .checkentry = &checkentry, 54 .matchsize = sizeof(struct ipt_ttl_info),
64 .me = THIS_MODULE, 55 .me = THIS_MODULE,
65}; 56};
66 57
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
index 6c8624a54933..cb9c661f3f33 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
@@ -141,19 +141,21 @@ static unsigned int ipv4_conntrack_help(unsigned int hooknum,
141{ 141{
142 struct nf_conn *ct; 142 struct nf_conn *ct;
143 enum ip_conntrack_info ctinfo; 143 enum ip_conntrack_info ctinfo;
144 struct nf_conn_help *help;
144 145
145 /* This is where we call the helper: as the packet goes out. */ 146 /* This is where we call the helper: as the packet goes out. */
146 ct = nf_ct_get(*pskb, &ctinfo); 147 ct = nf_ct_get(*pskb, &ctinfo);
147 if (ct && ct->helper) { 148 if (!ct)
148 unsigned int ret; 149 return NF_ACCEPT;
149 ret = ct->helper->help(pskb, 150
150 (*pskb)->nh.raw - (*pskb)->data 151 help = nfct_help(ct);
151 + (*pskb)->nh.iph->ihl*4, 152 if (!help || !help->helper)
152 ct, ctinfo); 153 return NF_ACCEPT;
153 if (ret != NF_ACCEPT) 154
154 return ret; 155 return help->helper->help(pskb,
155 } 156 (*pskb)->nh.raw - (*pskb)->data
156 return NF_ACCEPT; 157 + (*pskb)->nh.iph->ihl*4,
158 ct, ctinfo);
157} 159}
158 160
159static unsigned int ipv4_conntrack_defrag(unsigned int hooknum, 161static unsigned int ipv4_conntrack_defrag(unsigned int hooknum,
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index f29a12da5109..fc2562415555 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -660,12 +660,9 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
660out: return ret; 660out: return ret;
661} 661}
662 662
663static int raw_setsockopt(struct sock *sk, int level, int optname, 663static int do_raw_setsockopt(struct sock *sk, int level, int optname,
664 char __user *optval, int optlen) 664 char __user *optval, int optlen)
665{ 665{
666 if (level != SOL_RAW)
667 return ip_setsockopt(sk, level, optname, optval, optlen);
668
669 if (optname == ICMP_FILTER) { 666 if (optname == ICMP_FILTER) {
670 if (inet_sk(sk)->num != IPPROTO_ICMP) 667 if (inet_sk(sk)->num != IPPROTO_ICMP)
671 return -EOPNOTSUPP; 668 return -EOPNOTSUPP;
@@ -675,12 +672,27 @@ static int raw_setsockopt(struct sock *sk, int level, int optname,
675 return -ENOPROTOOPT; 672 return -ENOPROTOOPT;
676} 673}
677 674
678static int raw_getsockopt(struct sock *sk, int level, int optname, 675static int raw_setsockopt(struct sock *sk, int level, int optname,
679 char __user *optval, int __user *optlen) 676 char __user *optval, int optlen)
680{ 677{
681 if (level != SOL_RAW) 678 if (level != SOL_RAW)
682 return ip_getsockopt(sk, level, optname, optval, optlen); 679 return ip_setsockopt(sk, level, optname, optval, optlen);
680 return do_raw_setsockopt(sk, level, optname, optval, optlen);
681}
683 682
683#ifdef CONFIG_COMPAT
684static int compat_raw_setsockopt(struct sock *sk, int level, int optname,
685 char __user *optval, int optlen)
686{
687 if (level != SOL_RAW)
688 return compat_ip_setsockopt(sk, level, optname, optval, optlen);
689 return do_raw_setsockopt(sk, level, optname, optval, optlen);
690}
691#endif
692
693static int do_raw_getsockopt(struct sock *sk, int level, int optname,
694 char __user *optval, int __user *optlen)
695{
684 if (optname == ICMP_FILTER) { 696 if (optname == ICMP_FILTER) {
685 if (inet_sk(sk)->num != IPPROTO_ICMP) 697 if (inet_sk(sk)->num != IPPROTO_ICMP)
686 return -EOPNOTSUPP; 698 return -EOPNOTSUPP;
@@ -690,6 +702,24 @@ static int raw_getsockopt(struct sock *sk, int level, int optname,
690 return -ENOPROTOOPT; 702 return -ENOPROTOOPT;
691} 703}
692 704
705static int raw_getsockopt(struct sock *sk, int level, int optname,
706 char __user *optval, int __user *optlen)
707{
708 if (level != SOL_RAW)
709 return ip_getsockopt(sk, level, optname, optval, optlen);
710 return do_raw_getsockopt(sk, level, optname, optval, optlen);
711}
712
713#ifdef CONFIG_COMPAT
714static int compat_raw_getsockopt(struct sock *sk, int level, int optname,
715 char __user *optval, int __user *optlen)
716{
717 if (level != SOL_RAW)
718 return compat_ip_getsockopt(sk, level, optname, optval, optlen);
719 return do_raw_getsockopt(sk, level, optname, optval, optlen);
720}
721#endif
722
693static int raw_ioctl(struct sock *sk, int cmd, unsigned long arg) 723static int raw_ioctl(struct sock *sk, int cmd, unsigned long arg)
694{ 724{
695 switch (cmd) { 725 switch (cmd) {
@@ -719,22 +749,26 @@ static int raw_ioctl(struct sock *sk, int cmd, unsigned long arg)
719} 749}
720 750
721struct proto raw_prot = { 751struct proto raw_prot = {
722 .name = "RAW", 752 .name = "RAW",
723 .owner = THIS_MODULE, 753 .owner = THIS_MODULE,
724 .close = raw_close, 754 .close = raw_close,
725 .connect = ip4_datagram_connect, 755 .connect = ip4_datagram_connect,
726 .disconnect = udp_disconnect, 756 .disconnect = udp_disconnect,
727 .ioctl = raw_ioctl, 757 .ioctl = raw_ioctl,
728 .init = raw_init, 758 .init = raw_init,
729 .setsockopt = raw_setsockopt, 759 .setsockopt = raw_setsockopt,
730 .getsockopt = raw_getsockopt, 760 .getsockopt = raw_getsockopt,
731 .sendmsg = raw_sendmsg, 761 .sendmsg = raw_sendmsg,
732 .recvmsg = raw_recvmsg, 762 .recvmsg = raw_recvmsg,
733 .bind = raw_bind, 763 .bind = raw_bind,
734 .backlog_rcv = raw_rcv_skb, 764 .backlog_rcv = raw_rcv_skb,
735 .hash = raw_v4_hash, 765 .hash = raw_v4_hash,
736 .unhash = raw_v4_unhash, 766 .unhash = raw_v4_unhash,
737 .obj_size = sizeof(struct raw_sock), 767 .obj_size = sizeof(struct raw_sock),
768#ifdef CONFIG_COMPAT
769 .compat_setsockopt = compat_raw_setsockopt,
770 .compat_getsockopt = compat_raw_getsockopt,
771#endif
738}; 772};
739 773
740#ifdef CONFIG_PROC_FS 774#ifdef CONFIG_PROC_FS
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 16984d4a8a06..6b6c3adfcf00 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -664,7 +664,30 @@ ctl_table ipv4_table[] = {
664 .mode = 0644, 664 .mode = 0644,
665 .proc_handler = &proc_dointvec, 665 .proc_handler = &proc_dointvec,
666 }, 666 },
667 667 {
668 .ctl_name = NET_TCP_MTU_PROBING,
669 .procname = "tcp_mtu_probing",
670 .data = &sysctl_tcp_mtu_probing,
671 .maxlen = sizeof(int),
672 .mode = 0644,
673 .proc_handler = &proc_dointvec,
674 },
675 {
676 .ctl_name = NET_TCP_BASE_MSS,
677 .procname = "tcp_base_mss",
678 .data = &sysctl_tcp_base_mss,
679 .maxlen = sizeof(int),
680 .mode = 0644,
681 .proc_handler = &proc_dointvec,
682 },
683 {
684 .ctl_name = NET_IPV4_TCP_WORKAROUND_SIGNED_WINDOWS,
685 .procname = "tcp_workaround_signed_windows",
686 .data = &sysctl_tcp_workaround_signed_windows,
687 .maxlen = sizeof(int),
688 .mode = 0644,
689 .proc_handler = &proc_dointvec
690 },
668 { .ctl_name = 0 } 691 { .ctl_name = 0 }
669}; 692};
670 693
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 00aa80e93243..4b0272c92d66 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1687,18 +1687,14 @@ int tcp_disconnect(struct sock *sk, int flags)
1687/* 1687/*
1688 * Socket option code for TCP. 1688 * Socket option code for TCP.
1689 */ 1689 */
1690int tcp_setsockopt(struct sock *sk, int level, int optname, char __user *optval, 1690static int do_tcp_setsockopt(struct sock *sk, int level,
1691 int optlen) 1691 int optname, char __user *optval, int optlen)
1692{ 1692{
1693 struct tcp_sock *tp = tcp_sk(sk); 1693 struct tcp_sock *tp = tcp_sk(sk);
1694 struct inet_connection_sock *icsk = inet_csk(sk); 1694 struct inet_connection_sock *icsk = inet_csk(sk);
1695 int val; 1695 int val;
1696 int err = 0; 1696 int err = 0;
1697 1697
1698 if (level != SOL_TCP)
1699 return icsk->icsk_af_ops->setsockopt(sk, level, optname,
1700 optval, optlen);
1701
1702 /* This is a string value all the others are int's */ 1698 /* This is a string value all the others are int's */
1703 if (optname == TCP_CONGESTION) { 1699 if (optname == TCP_CONGESTION) {
1704 char name[TCP_CA_NAME_MAX]; 1700 char name[TCP_CA_NAME_MAX];
@@ -1871,6 +1867,30 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char __user *optval,
1871 return err; 1867 return err;
1872} 1868}
1873 1869
1870int tcp_setsockopt(struct sock *sk, int level, int optname, char __user *optval,
1871 int optlen)
1872{
1873 struct inet_connection_sock *icsk = inet_csk(sk);
1874
1875 if (level != SOL_TCP)
1876 return icsk->icsk_af_ops->setsockopt(sk, level, optname,
1877 optval, optlen);
1878 return do_tcp_setsockopt(sk, level, optname, optval, optlen);
1879}
1880
1881#ifdef CONFIG_COMPAT
1882int compat_tcp_setsockopt(struct sock *sk, int level, int optname,
1883 char __user *optval, int optlen)
1884{
1885 if (level != SOL_TCP)
1886 return inet_csk_compat_setsockopt(sk, level, optname,
1887 optval, optlen);
1888 return do_tcp_setsockopt(sk, level, optname, optval, optlen);
1889}
1890
1891EXPORT_SYMBOL(compat_tcp_setsockopt);
1892#endif
1893
1874/* Return information about state of tcp endpoint in API format. */ 1894/* Return information about state of tcp endpoint in API format. */
1875void tcp_get_info(struct sock *sk, struct tcp_info *info) 1895void tcp_get_info(struct sock *sk, struct tcp_info *info)
1876{ 1896{
@@ -1931,17 +1951,13 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
1931 1951
1932EXPORT_SYMBOL_GPL(tcp_get_info); 1952EXPORT_SYMBOL_GPL(tcp_get_info);
1933 1953
1934int tcp_getsockopt(struct sock *sk, int level, int optname, char __user *optval, 1954static int do_tcp_getsockopt(struct sock *sk, int level,
1935 int __user *optlen) 1955 int optname, char __user *optval, int __user *optlen)
1936{ 1956{
1937 struct inet_connection_sock *icsk = inet_csk(sk); 1957 struct inet_connection_sock *icsk = inet_csk(sk);
1938 struct tcp_sock *tp = tcp_sk(sk); 1958 struct tcp_sock *tp = tcp_sk(sk);
1939 int val, len; 1959 int val, len;
1940 1960
1941 if (level != SOL_TCP)
1942 return icsk->icsk_af_ops->getsockopt(sk, level, optname,
1943 optval, optlen);
1944
1945 if (get_user(len, optlen)) 1961 if (get_user(len, optlen))
1946 return -EFAULT; 1962 return -EFAULT;
1947 1963
@@ -2025,6 +2041,29 @@ int tcp_getsockopt(struct sock *sk, int level, int optname, char __user *optval,
2025 return 0; 2041 return 0;
2026} 2042}
2027 2043
2044int tcp_getsockopt(struct sock *sk, int level, int optname, char __user *optval,
2045 int __user *optlen)
2046{
2047 struct inet_connection_sock *icsk = inet_csk(sk);
2048
2049 if (level != SOL_TCP)
2050 return icsk->icsk_af_ops->getsockopt(sk, level, optname,
2051 optval, optlen);
2052 return do_tcp_getsockopt(sk, level, optname, optval, optlen);
2053}
2054
2055#ifdef CONFIG_COMPAT
2056int compat_tcp_getsockopt(struct sock *sk, int level, int optname,
2057 char __user *optval, int __user *optlen)
2058{
2059 if (level != SOL_TCP)
2060 return inet_csk_compat_getsockopt(sk, level, optname,
2061 optval, optlen);
2062 return do_tcp_getsockopt(sk, level, optname, optval, optlen);
2063}
2064
2065EXPORT_SYMBOL(compat_tcp_getsockopt);
2066#endif
2028 2067
2029extern void __skb_cb_too_small_for_tcp(int, int); 2068extern void __skb_cb_too_small_for_tcp(int, int);
2030extern struct tcp_congestion_ops tcp_reno; 2069extern struct tcp_congestion_ops tcp_reno;
diff --git a/net/ipv4/tcp_htcp.c b/net/ipv4/tcp_htcp.c
index 128de4d7c0b7..1b2ff53f98ed 100644
--- a/net/ipv4/tcp_htcp.c
+++ b/net/ipv4/tcp_htcp.c
@@ -27,12 +27,12 @@ struct htcp {
27 u16 alpha; /* Fixed point arith, << 7 */ 27 u16 alpha; /* Fixed point arith, << 7 */
28 u8 beta; /* Fixed point arith, << 7 */ 28 u8 beta; /* Fixed point arith, << 7 */
29 u8 modeswitch; /* Delay modeswitch until we had at least one congestion event */ 29 u8 modeswitch; /* Delay modeswitch until we had at least one congestion event */
30 u8 ccount; /* Number of RTTs since last congestion event */ 30 u32 last_cong; /* Time since last congestion event end */
31 u8 undo_ccount; 31 u32 undo_last_cong;
32 u16 packetcount; 32 u16 pkts_acked;
33 u32 packetcount;
33 u32 minRTT; 34 u32 minRTT;
34 u32 maxRTT; 35 u32 maxRTT;
35 u32 snd_cwnd_cnt2;
36 36
37 u32 undo_maxRTT; 37 u32 undo_maxRTT;
38 u32 undo_old_maxB; 38 u32 undo_old_maxB;
@@ -45,21 +45,30 @@ struct htcp {
45 u32 lasttime; 45 u32 lasttime;
46}; 46};
47 47
48static inline u32 htcp_cong_time(struct htcp *ca)
49{
50 return jiffies - ca->last_cong;
51}
52
53static inline u32 htcp_ccount(struct htcp *ca)
54{
55 return htcp_cong_time(ca)/ca->minRTT;
56}
57
48static inline void htcp_reset(struct htcp *ca) 58static inline void htcp_reset(struct htcp *ca)
49{ 59{
50 ca->undo_ccount = ca->ccount; 60 ca->undo_last_cong = ca->last_cong;
51 ca->undo_maxRTT = ca->maxRTT; 61 ca->undo_maxRTT = ca->maxRTT;
52 ca->undo_old_maxB = ca->old_maxB; 62 ca->undo_old_maxB = ca->old_maxB;
53 63
54 ca->ccount = 0; 64 ca->last_cong = jiffies;
55 ca->snd_cwnd_cnt2 = 0;
56} 65}
57 66
58static u32 htcp_cwnd_undo(struct sock *sk) 67static u32 htcp_cwnd_undo(struct sock *sk)
59{ 68{
60 const struct tcp_sock *tp = tcp_sk(sk); 69 const struct tcp_sock *tp = tcp_sk(sk);
61 struct htcp *ca = inet_csk_ca(sk); 70 struct htcp *ca = inet_csk_ca(sk);
62 ca->ccount = ca->undo_ccount; 71 ca->last_cong = ca->undo_last_cong;
63 ca->maxRTT = ca->undo_maxRTT; 72 ca->maxRTT = ca->undo_maxRTT;
64 ca->old_maxB = ca->undo_old_maxB; 73 ca->old_maxB = ca->undo_old_maxB;
65 return max(tp->snd_cwnd, (tp->snd_ssthresh<<7)/ca->beta); 74 return max(tp->snd_cwnd, (tp->snd_ssthresh<<7)/ca->beta);
@@ -77,10 +86,10 @@ static inline void measure_rtt(struct sock *sk)
77 ca->minRTT = srtt; 86 ca->minRTT = srtt;
78 87
79 /* max RTT */ 88 /* max RTT */
80 if (icsk->icsk_ca_state == TCP_CA_Open && tp->snd_ssthresh < 0xFFFF && ca->ccount > 3) { 89 if (icsk->icsk_ca_state == TCP_CA_Open && tp->snd_ssthresh < 0xFFFF && htcp_ccount(ca) > 3) {
81 if (ca->maxRTT < ca->minRTT) 90 if (ca->maxRTT < ca->minRTT)
82 ca->maxRTT = ca->minRTT; 91 ca->maxRTT = ca->minRTT;
83 if (ca->maxRTT < srtt && srtt <= ca->maxRTT+HZ/50) 92 if (ca->maxRTT < srtt && srtt <= ca->maxRTT+msecs_to_jiffies(20))
84 ca->maxRTT = srtt; 93 ca->maxRTT = srtt;
85 } 94 }
86} 95}
@@ -92,6 +101,12 @@ static void measure_achieved_throughput(struct sock *sk, u32 pkts_acked)
92 struct htcp *ca = inet_csk_ca(sk); 101 struct htcp *ca = inet_csk_ca(sk);
93 u32 now = tcp_time_stamp; 102 u32 now = tcp_time_stamp;
94 103
104 if (icsk->icsk_ca_state == TCP_CA_Open)
105 ca->pkts_acked = pkts_acked;
106
107 if (!use_bandwidth_switch)
108 return;
109
95 /* achieved throughput calculations */ 110 /* achieved throughput calculations */
96 if (icsk->icsk_ca_state != TCP_CA_Open && 111 if (icsk->icsk_ca_state != TCP_CA_Open &&
97 icsk->icsk_ca_state != TCP_CA_Disorder) { 112 icsk->icsk_ca_state != TCP_CA_Disorder) {
@@ -106,7 +121,7 @@ static void measure_achieved_throughput(struct sock *sk, u32 pkts_acked)
106 && now - ca->lasttime >= ca->minRTT 121 && now - ca->lasttime >= ca->minRTT
107 && ca->minRTT > 0) { 122 && ca->minRTT > 0) {
108 __u32 cur_Bi = ca->packetcount*HZ/(now - ca->lasttime); 123 __u32 cur_Bi = ca->packetcount*HZ/(now - ca->lasttime);
109 if (ca->ccount <= 3) { 124 if (htcp_ccount(ca) <= 3) {
110 /* just after backoff */ 125 /* just after backoff */
111 ca->minB = ca->maxB = ca->Bi = cur_Bi; 126 ca->minB = ca->maxB = ca->Bi = cur_Bi;
112 } else { 127 } else {
@@ -135,7 +150,7 @@ static inline void htcp_beta_update(struct htcp *ca, u32 minRTT, u32 maxRTT)
135 } 150 }
136 } 151 }
137 152
138 if (ca->modeswitch && minRTT > max(HZ/100, 1) && maxRTT) { 153 if (ca->modeswitch && minRTT > msecs_to_jiffies(10) && maxRTT) {
139 ca->beta = (minRTT<<7)/maxRTT; 154 ca->beta = (minRTT<<7)/maxRTT;
140 if (ca->beta < BETA_MIN) 155 if (ca->beta < BETA_MIN)
141 ca->beta = BETA_MIN; 156 ca->beta = BETA_MIN;
@@ -151,7 +166,7 @@ static inline void htcp_alpha_update(struct htcp *ca)
151{ 166{
152 u32 minRTT = ca->minRTT; 167 u32 minRTT = ca->minRTT;
153 u32 factor = 1; 168 u32 factor = 1;
154 u32 diff = ca->ccount * minRTT; /* time since last backoff */ 169 u32 diff = htcp_cong_time(ca);
155 170
156 if (diff > HZ) { 171 if (diff > HZ) {
157 diff -= HZ; 172 diff -= HZ;
@@ -216,21 +231,18 @@ static void htcp_cong_avoid(struct sock *sk, u32 ack, u32 rtt,
216 231
217 measure_rtt(sk); 232 measure_rtt(sk);
218 233
219 /* keep track of number of round-trip times since last backoff event */
220 if (ca->snd_cwnd_cnt2++ > tp->snd_cwnd) {
221 ca->ccount++;
222 ca->snd_cwnd_cnt2 = 0;
223 htcp_alpha_update(ca);
224 }
225
226 /* In dangerous area, increase slowly. 234 /* In dangerous area, increase slowly.
227 * In theory this is tp->snd_cwnd += alpha / tp->snd_cwnd 235 * In theory this is tp->snd_cwnd += alpha / tp->snd_cwnd
228 */ 236 */
229 if ((tp->snd_cwnd_cnt++ * ca->alpha)>>7 >= tp->snd_cwnd) { 237 if ((tp->snd_cwnd_cnt * ca->alpha)>>7 >= tp->snd_cwnd) {
230 if (tp->snd_cwnd < tp->snd_cwnd_clamp) 238 if (tp->snd_cwnd < tp->snd_cwnd_clamp)
231 tp->snd_cwnd++; 239 tp->snd_cwnd++;
232 tp->snd_cwnd_cnt = 0; 240 tp->snd_cwnd_cnt = 0;
233 } 241 htcp_alpha_update(ca);
242 } else
243 tp->snd_cwnd_cnt += ca->pkts_acked;
244
245 ca->pkts_acked = 1;
234 } 246 }
235} 247}
236 248
@@ -249,11 +261,19 @@ static void htcp_init(struct sock *sk)
249 memset(ca, 0, sizeof(struct htcp)); 261 memset(ca, 0, sizeof(struct htcp));
250 ca->alpha = ALPHA_BASE; 262 ca->alpha = ALPHA_BASE;
251 ca->beta = BETA_MIN; 263 ca->beta = BETA_MIN;
264 ca->pkts_acked = 1;
265 ca->last_cong = jiffies;
252} 266}
253 267
254static void htcp_state(struct sock *sk, u8 new_state) 268static void htcp_state(struct sock *sk, u8 new_state)
255{ 269{
256 switch (new_state) { 270 switch (new_state) {
271 case TCP_CA_Open:
272 {
273 struct htcp *ca = inet_csk_ca(sk);
274 ca->last_cong = jiffies;
275 }
276 break;
257 case TCP_CA_CWR: 277 case TCP_CA_CWR:
258 case TCP_CA_Recovery: 278 case TCP_CA_Recovery:
259 case TCP_CA_Loss: 279 case TCP_CA_Loss:
@@ -278,8 +298,6 @@ static int __init htcp_register(void)
278{ 298{
279 BUG_ON(sizeof(struct htcp) > ICSK_CA_PRIV_SIZE); 299 BUG_ON(sizeof(struct htcp) > ICSK_CA_PRIV_SIZE);
280 BUILD_BUG_ON(BETA_MIN >= BETA_MAX); 300 BUILD_BUG_ON(BETA_MIN >= BETA_MAX);
281 if (!use_bandwidth_switch)
282 htcp.pkts_acked = NULL;
283 return tcp_register_congestion_control(&htcp); 301 return tcp_register_congestion_control(&htcp);
284} 302}
285 303
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index e9a54ae7d690..195d83584558 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -1891,6 +1891,34 @@ static void tcp_try_to_open(struct sock *sk, struct tcp_sock *tp, int flag)
1891 } 1891 }
1892} 1892}
1893 1893
1894static void tcp_mtup_probe_failed(struct sock *sk)
1895{
1896 struct inet_connection_sock *icsk = inet_csk(sk);
1897
1898 icsk->icsk_mtup.search_high = icsk->icsk_mtup.probe_size - 1;
1899 icsk->icsk_mtup.probe_size = 0;
1900}
1901
1902static void tcp_mtup_probe_success(struct sock *sk, struct sk_buff *skb)
1903{
1904 struct tcp_sock *tp = tcp_sk(sk);
1905 struct inet_connection_sock *icsk = inet_csk(sk);
1906
1907 /* FIXME: breaks with very large cwnd */
1908 tp->prior_ssthresh = tcp_current_ssthresh(sk);
1909 tp->snd_cwnd = tp->snd_cwnd *
1910 tcp_mss_to_mtu(sk, tp->mss_cache) /
1911 icsk->icsk_mtup.probe_size;
1912 tp->snd_cwnd_cnt = 0;
1913 tp->snd_cwnd_stamp = tcp_time_stamp;
1914 tp->rcv_ssthresh = tcp_current_ssthresh(sk);
1915
1916 icsk->icsk_mtup.search_low = icsk->icsk_mtup.probe_size;
1917 icsk->icsk_mtup.probe_size = 0;
1918 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
1919}
1920
1921
1894/* Process an event, which can update packets-in-flight not trivially. 1922/* Process an event, which can update packets-in-flight not trivially.
1895 * Main goal of this function is to calculate new estimate for left_out, 1923 * Main goal of this function is to calculate new estimate for left_out,
1896 * taking into account both packets sitting in receiver's buffer and 1924 * taking into account both packets sitting in receiver's buffer and
@@ -2023,6 +2051,17 @@ tcp_fastretrans_alert(struct sock *sk, u32 prior_snd_una,
2023 return; 2051 return;
2024 } 2052 }
2025 2053
2054 /* MTU probe failure: don't reduce cwnd */
2055 if (icsk->icsk_ca_state < TCP_CA_CWR &&
2056 icsk->icsk_mtup.probe_size &&
2057 tp->snd_una == tp->mtu_probe.probe_seq_start) {
2058 tcp_mtup_probe_failed(sk);
2059 /* Restores the reduction we did in tcp_mtup_probe() */
2060 tp->snd_cwnd++;
2061 tcp_simple_retransmit(sk);
2062 return;
2063 }
2064
2026 /* Otherwise enter Recovery state */ 2065 /* Otherwise enter Recovery state */
2027 2066
2028 if (IsReno(tp)) 2067 if (IsReno(tp))
@@ -2243,6 +2282,13 @@ static int tcp_clean_rtx_queue(struct sock *sk, __s32 *seq_rtt_p)
2243 tp->retrans_stamp = 0; 2282 tp->retrans_stamp = 0;
2244 } 2283 }
2245 2284
2285 /* MTU probing checks */
2286 if (icsk->icsk_mtup.probe_size) {
2287 if (!after(tp->mtu_probe.probe_seq_end, TCP_SKB_CB(skb)->end_seq)) {
2288 tcp_mtup_probe_success(sk, skb);
2289 }
2290 }
2291
2246 if (sacked) { 2292 if (sacked) {
2247 if (sacked & TCPCB_RETRANS) { 2293 if (sacked & TCPCB_RETRANS) {
2248 if(sacked & TCPCB_SACKED_RETRANS) 2294 if(sacked & TCPCB_SACKED_RETRANS)
@@ -4101,6 +4147,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
4101 if (tp->rx_opt.sack_ok && sysctl_tcp_fack) 4147 if (tp->rx_opt.sack_ok && sysctl_tcp_fack)
4102 tp->rx_opt.sack_ok |= 2; 4148 tp->rx_opt.sack_ok |= 2;
4103 4149
4150 tcp_mtup_init(sk);
4104 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); 4151 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
4105 tcp_initialize_rcv_mss(sk); 4152 tcp_initialize_rcv_mss(sk);
4106 4153
@@ -4211,6 +4258,7 @@ discard:
4211 if (tp->ecn_flags&TCP_ECN_OK) 4258 if (tp->ecn_flags&TCP_ECN_OK)
4212 sock_set_flag(sk, SOCK_NO_LARGESEND); 4259 sock_set_flag(sk, SOCK_NO_LARGESEND);
4213 4260
4261 tcp_mtup_init(sk);
4214 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); 4262 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
4215 tcp_initialize_rcv_mss(sk); 4263 tcp_initialize_rcv_mss(sk);
4216 4264
@@ -4399,6 +4447,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
4399 */ 4447 */
4400 tp->lsndtime = tcp_time_stamp; 4448 tp->lsndtime = tcp_time_stamp;
4401 4449
4450 tcp_mtup_init(sk);
4402 tcp_initialize_rcv_mss(sk); 4451 tcp_initialize_rcv_mss(sk);
4403 tcp_init_buffer_space(sk); 4452 tcp_init_buffer_space(sk);
4404 tcp_fast_path_on(tp); 4453 tcp_fast_path_on(tp);
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 233bdf259965..9e85c0416109 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -900,6 +900,7 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
900 inet_csk(newsk)->icsk_ext_hdr_len = newinet->opt->optlen; 900 inet_csk(newsk)->icsk_ext_hdr_len = newinet->opt->optlen;
901 newinet->id = newtp->write_seq ^ jiffies; 901 newinet->id = newtp->write_seq ^ jiffies;
902 902
903 tcp_mtup_init(newsk);
903 tcp_sync_mss(newsk, dst_mtu(dst)); 904 tcp_sync_mss(newsk, dst_mtu(dst));
904 newtp->advmss = dst_metric(dst, RTAX_ADVMSS); 905 newtp->advmss = dst_metric(dst, RTAX_ADVMSS);
905 tcp_initialize_rcv_mss(newsk); 906 tcp_initialize_rcv_mss(newsk);
@@ -1216,17 +1217,21 @@ int tcp_v4_tw_remember_stamp(struct inet_timewait_sock *tw)
1216} 1217}
1217 1218
1218struct inet_connection_sock_af_ops ipv4_specific = { 1219struct inet_connection_sock_af_ops ipv4_specific = {
1219 .queue_xmit = ip_queue_xmit, 1220 .queue_xmit = ip_queue_xmit,
1220 .send_check = tcp_v4_send_check, 1221 .send_check = tcp_v4_send_check,
1221 .rebuild_header = inet_sk_rebuild_header, 1222 .rebuild_header = inet_sk_rebuild_header,
1222 .conn_request = tcp_v4_conn_request, 1223 .conn_request = tcp_v4_conn_request,
1223 .syn_recv_sock = tcp_v4_syn_recv_sock, 1224 .syn_recv_sock = tcp_v4_syn_recv_sock,
1224 .remember_stamp = tcp_v4_remember_stamp, 1225 .remember_stamp = tcp_v4_remember_stamp,
1225 .net_header_len = sizeof(struct iphdr), 1226 .net_header_len = sizeof(struct iphdr),
1226 .setsockopt = ip_setsockopt, 1227 .setsockopt = ip_setsockopt,
1227 .getsockopt = ip_getsockopt, 1228 .getsockopt = ip_getsockopt,
1228 .addr2sockaddr = inet_csk_addr2sockaddr, 1229 .addr2sockaddr = inet_csk_addr2sockaddr,
1229 .sockaddr_len = sizeof(struct sockaddr_in), 1230 .sockaddr_len = sizeof(struct sockaddr_in),
1231#ifdef CONFIG_COMPAT
1232 .compat_setsockopt = compat_ip_setsockopt,
1233 .compat_getsockopt = compat_ip_getsockopt,
1234#endif
1230}; 1235};
1231 1236
1232/* NOTE: A lot of things set to zero explicitly by call to 1237/* NOTE: A lot of things set to zero explicitly by call to
@@ -1825,23 +1830,16 @@ struct proto tcp_prot = {
1825 .obj_size = sizeof(struct tcp_sock), 1830 .obj_size = sizeof(struct tcp_sock),
1826 .twsk_prot = &tcp_timewait_sock_ops, 1831 .twsk_prot = &tcp_timewait_sock_ops,
1827 .rsk_prot = &tcp_request_sock_ops, 1832 .rsk_prot = &tcp_request_sock_ops,
1833#ifdef CONFIG_COMPAT
1834 .compat_setsockopt = compat_tcp_setsockopt,
1835 .compat_getsockopt = compat_tcp_getsockopt,
1836#endif
1828}; 1837};
1829 1838
1830
1831
1832void __init tcp_v4_init(struct net_proto_family *ops) 1839void __init tcp_v4_init(struct net_proto_family *ops)
1833{ 1840{
1834 int err = sock_create_kern(PF_INET, SOCK_RAW, IPPROTO_TCP, &tcp_socket); 1841 if (inet_csk_ctl_sock_create(&tcp_socket, PF_INET, SOCK_RAW, IPPROTO_TCP) < 0)
1835 if (err < 0)
1836 panic("Failed to create the TCP control socket.\n"); 1842 panic("Failed to create the TCP control socket.\n");
1837 tcp_socket->sk->sk_allocation = GFP_ATOMIC;
1838 inet_sk(tcp_socket->sk)->uc_ttl = -1;
1839
1840 /* Unhash it so that IP input processing does not even
1841 * see it, we do not wish this socket to see incoming
1842 * packets.
1843 */
1844 tcp_socket->sk->sk_prot->unhash(tcp_socket->sk);
1845} 1843}
1846 1844
1847EXPORT_SYMBOL(ipv4_specific); 1845EXPORT_SYMBOL(ipv4_specific);
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 9f498a6c8895..9d79546d384e 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -45,12 +45,23 @@
45/* People can turn this off for buggy TCP's found in printers etc. */ 45/* People can turn this off for buggy TCP's found in printers etc. */
46int sysctl_tcp_retrans_collapse = 1; 46int sysctl_tcp_retrans_collapse = 1;
47 47
48/* People can turn this on to work with those rare, broken TCPs that
49 * interpret the window field as a signed quantity.
50 */
51int sysctl_tcp_workaround_signed_windows = 0;
52
48/* This limits the percentage of the congestion window which we 53/* This limits the percentage of the congestion window which we
49 * will allow a single TSO frame to consume. Building TSO frames 54 * will allow a single TSO frame to consume. Building TSO frames
50 * which are too large can cause TCP streams to be bursty. 55 * which are too large can cause TCP streams to be bursty.
51 */ 56 */
52int sysctl_tcp_tso_win_divisor = 3; 57int sysctl_tcp_tso_win_divisor = 3;
53 58
59int sysctl_tcp_mtu_probing = 0;
60int sysctl_tcp_base_mss = 512;
61
62EXPORT_SYMBOL(sysctl_tcp_mtu_probing);
63EXPORT_SYMBOL(sysctl_tcp_base_mss);
64
54static void update_send_head(struct sock *sk, struct tcp_sock *tp, 65static void update_send_head(struct sock *sk, struct tcp_sock *tp,
55 struct sk_buff *skb) 66 struct sk_buff *skb)
56{ 67{
@@ -171,12 +182,18 @@ void tcp_select_initial_window(int __space, __u32 mss,
171 space = (space / mss) * mss; 182 space = (space / mss) * mss;
172 183
173 /* NOTE: offering an initial window larger than 32767 184 /* NOTE: offering an initial window larger than 32767
174 * will break some buggy TCP stacks. We try to be nice. 185 * will break some buggy TCP stacks. If the admin tells us
175 * If we are not window scaling, then this truncates 186 * it is likely we could be speaking with such a buggy stack
176 * our initial window offering to 32k. There should also 187 * we will truncate our initial window offering to 32K-1
177 * be a sysctl option to stop being nice. 188 * unless the remote has sent us a window scaling option,
189 * which we interpret as a sign the remote TCP is not
190 * misinterpreting the window field as a signed quantity.
178 */ 191 */
179 (*rcv_wnd) = min(space, MAX_TCP_WINDOW); 192 if (sysctl_tcp_workaround_signed_windows)
193 (*rcv_wnd) = min(space, MAX_TCP_WINDOW);
194 else
195 (*rcv_wnd) = space;
196
180 (*rcv_wscale) = 0; 197 (*rcv_wscale) = 0;
181 if (wscale_ok) { 198 if (wscale_ok) {
182 /* Set window scaling on max possible window 199 /* Set window scaling on max possible window
@@ -235,7 +252,7 @@ static u16 tcp_select_window(struct sock *sk)
235 /* Make sure we do not exceed the maximum possible 252 /* Make sure we do not exceed the maximum possible
236 * scaled window. 253 * scaled window.
237 */ 254 */
238 if (!tp->rx_opt.rcv_wscale) 255 if (!tp->rx_opt.rcv_wscale && sysctl_tcp_workaround_signed_windows)
239 new_win = min(new_win, MAX_TCP_WINDOW); 256 new_win = min(new_win, MAX_TCP_WINDOW);
240 else 257 else
241 new_win = min(new_win, (65535U << tp->rx_opt.rcv_wscale)); 258 new_win = min(new_win, (65535U << tp->rx_opt.rcv_wscale));
@@ -681,6 +698,62 @@ int tcp_trim_head(struct sock *sk, struct sk_buff *skb, u32 len)
681 return 0; 698 return 0;
682} 699}
683 700
701/* Not accounting for SACKs here. */
702int tcp_mtu_to_mss(struct sock *sk, int pmtu)
703{
704 struct tcp_sock *tp = tcp_sk(sk);
705 struct inet_connection_sock *icsk = inet_csk(sk);
706 int mss_now;
707
708 /* Calculate base mss without TCP options:
709 It is MMS_S - sizeof(tcphdr) of rfc1122
710 */
711 mss_now = pmtu - icsk->icsk_af_ops->net_header_len - sizeof(struct tcphdr);
712
713 /* Clamp it (mss_clamp does not include tcp options) */
714 if (mss_now > tp->rx_opt.mss_clamp)
715 mss_now = tp->rx_opt.mss_clamp;
716
717 /* Now subtract optional transport overhead */
718 mss_now -= icsk->icsk_ext_hdr_len;
719
720 /* Then reserve room for full set of TCP options and 8 bytes of data */
721 if (mss_now < 48)
722 mss_now = 48;
723
724 /* Now subtract TCP options size, not including SACKs */
725 mss_now -= tp->tcp_header_len - sizeof(struct tcphdr);
726
727 return mss_now;
728}
729
730/* Inverse of above */
731int tcp_mss_to_mtu(struct sock *sk, int mss)
732{
733 struct tcp_sock *tp = tcp_sk(sk);
734 struct inet_connection_sock *icsk = inet_csk(sk);
735 int mtu;
736
737 mtu = mss +
738 tp->tcp_header_len +
739 icsk->icsk_ext_hdr_len +
740 icsk->icsk_af_ops->net_header_len;
741
742 return mtu;
743}
744
745void tcp_mtup_init(struct sock *sk)
746{
747 struct tcp_sock *tp = tcp_sk(sk);
748 struct inet_connection_sock *icsk = inet_csk(sk);
749
750 icsk->icsk_mtup.enabled = sysctl_tcp_mtu_probing > 1;
751 icsk->icsk_mtup.search_high = tp->rx_opt.mss_clamp + sizeof(struct tcphdr) +
752 icsk->icsk_af_ops->net_header_len;
753 icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, sysctl_tcp_base_mss);
754 icsk->icsk_mtup.probe_size = 0;
755}
756
684/* This function synchronize snd mss to current pmtu/exthdr set. 757/* This function synchronize snd mss to current pmtu/exthdr set.
685 758
686 tp->rx_opt.user_mss is mss set by user by TCP_MAXSEG. It does NOT counts 759 tp->rx_opt.user_mss is mss set by user by TCP_MAXSEG. It does NOT counts
@@ -708,25 +781,12 @@ unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu)
708{ 781{
709 struct tcp_sock *tp = tcp_sk(sk); 782 struct tcp_sock *tp = tcp_sk(sk);
710 struct inet_connection_sock *icsk = inet_csk(sk); 783 struct inet_connection_sock *icsk = inet_csk(sk);
711 /* Calculate base mss without TCP options: 784 int mss_now;
712 It is MMS_S - sizeof(tcphdr) of rfc1122
713 */
714 int mss_now = (pmtu - icsk->icsk_af_ops->net_header_len -
715 sizeof(struct tcphdr));
716
717 /* Clamp it (mss_clamp does not include tcp options) */
718 if (mss_now > tp->rx_opt.mss_clamp)
719 mss_now = tp->rx_opt.mss_clamp;
720
721 /* Now subtract optional transport overhead */
722 mss_now -= icsk->icsk_ext_hdr_len;
723 785
724 /* Then reserve room for full set of TCP options and 8 bytes of data */ 786 if (icsk->icsk_mtup.search_high > pmtu)
725 if (mss_now < 48) 787 icsk->icsk_mtup.search_high = pmtu;
726 mss_now = 48;
727 788
728 /* Now subtract TCP options size, not including SACKs */ 789 mss_now = tcp_mtu_to_mss(sk, pmtu);
729 mss_now -= tp->tcp_header_len - sizeof(struct tcphdr);
730 790
731 /* Bound mss with half of window */ 791 /* Bound mss with half of window */
732 if (tp->max_window && mss_now > (tp->max_window>>1)) 792 if (tp->max_window && mss_now > (tp->max_window>>1))
@@ -734,6 +794,8 @@ unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu)
734 794
735 /* And store cached results */ 795 /* And store cached results */
736 icsk->icsk_pmtu_cookie = pmtu; 796 icsk->icsk_pmtu_cookie = pmtu;
797 if (icsk->icsk_mtup.enabled)
798 mss_now = min(mss_now, tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_low));
737 tp->mss_cache = mss_now; 799 tp->mss_cache = mss_now;
738 800
739 return mss_now; 801 return mss_now;
@@ -1063,6 +1125,140 @@ static int tcp_tso_should_defer(struct sock *sk, struct tcp_sock *tp, struct sk_
1063 return 1; 1125 return 1;
1064} 1126}
1065 1127
1128/* Create a new MTU probe if we are ready.
1129 * Returns 0 if we should wait to probe (no cwnd available),
1130 * 1 if a probe was sent,
1131 * -1 otherwise */
1132static int tcp_mtu_probe(struct sock *sk)
1133{
1134 struct tcp_sock *tp = tcp_sk(sk);
1135 struct inet_connection_sock *icsk = inet_csk(sk);
1136 struct sk_buff *skb, *nskb, *next;
1137 int len;
1138 int probe_size;
1139 unsigned int pif;
1140 int copy;
1141 int mss_now;
1142
1143 /* Not currently probing/verifying,
1144 * not in recovery,
1145 * have enough cwnd, and
1146 * not SACKing (the variable headers throw things off) */
1147 if (!icsk->icsk_mtup.enabled ||
1148 icsk->icsk_mtup.probe_size ||
1149 inet_csk(sk)->icsk_ca_state != TCP_CA_Open ||
1150 tp->snd_cwnd < 11 ||
1151 tp->rx_opt.eff_sacks)
1152 return -1;
1153
1154 /* Very simple search strategy: just double the MSS. */
1155 mss_now = tcp_current_mss(sk, 0);
1156 probe_size = 2*tp->mss_cache;
1157 if (probe_size > tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_high)) {
1158 /* TODO: set timer for probe_converge_event */
1159 return -1;
1160 }
1161
1162 /* Have enough data in the send queue to probe? */
1163 len = 0;
1164 if ((skb = sk->sk_send_head) == NULL)
1165 return -1;
1166 while ((len += skb->len) < probe_size && !tcp_skb_is_last(sk, skb))
1167 skb = skb->next;
1168 if (len < probe_size)
1169 return -1;
1170
1171 /* Receive window check. */
1172 if (after(TCP_SKB_CB(skb)->seq + probe_size, tp->snd_una + tp->snd_wnd)) {
1173 if (tp->snd_wnd < probe_size)
1174 return -1;
1175 else
1176 return 0;
1177 }
1178
1179 /* Do we need to wait to drain cwnd? */
1180 pif = tcp_packets_in_flight(tp);
1181 if (pif + 2 > tp->snd_cwnd) {
1182 /* With no packets in flight, don't stall. */
1183 if (pif == 0)
1184 return -1;
1185 else
1186 return 0;
1187 }
1188
1189 /* We're allowed to probe. Build it now. */
1190 if ((nskb = sk_stream_alloc_skb(sk, probe_size, GFP_ATOMIC)) == NULL)
1191 return -1;
1192 sk_charge_skb(sk, nskb);
1193
1194 skb = sk->sk_send_head;
1195 __skb_insert(nskb, skb->prev, skb, &sk->sk_write_queue);
1196 sk->sk_send_head = nskb;
1197
1198 TCP_SKB_CB(nskb)->seq = TCP_SKB_CB(skb)->seq;
1199 TCP_SKB_CB(nskb)->end_seq = TCP_SKB_CB(skb)->seq + probe_size;
1200 TCP_SKB_CB(nskb)->flags = TCPCB_FLAG_ACK;
1201 TCP_SKB_CB(nskb)->sacked = 0;
1202 nskb->csum = 0;
1203 if (skb->ip_summed == CHECKSUM_HW)
1204 nskb->ip_summed = CHECKSUM_HW;
1205
1206 len = 0;
1207 while (len < probe_size) {
1208 next = skb->next;
1209
1210 copy = min_t(int, skb->len, probe_size - len);
1211 if (nskb->ip_summed)
1212 skb_copy_bits(skb, 0, skb_put(nskb, copy), copy);
1213 else
1214 nskb->csum = skb_copy_and_csum_bits(skb, 0,
1215 skb_put(nskb, copy), copy, nskb->csum);
1216
1217 if (skb->len <= copy) {
1218 /* We've eaten all the data from this skb.
1219 * Throw it away. */
1220 TCP_SKB_CB(nskb)->flags |= TCP_SKB_CB(skb)->flags;
1221 __skb_unlink(skb, &sk->sk_write_queue);
1222 sk_stream_free_skb(sk, skb);
1223 } else {
1224 TCP_SKB_CB(nskb)->flags |= TCP_SKB_CB(skb)->flags &
1225 ~(TCPCB_FLAG_FIN|TCPCB_FLAG_PSH);
1226 if (!skb_shinfo(skb)->nr_frags) {
1227 skb_pull(skb, copy);
1228 if (skb->ip_summed != CHECKSUM_HW)
1229 skb->csum = csum_partial(skb->data, skb->len, 0);
1230 } else {
1231 __pskb_trim_head(skb, copy);
1232 tcp_set_skb_tso_segs(sk, skb, mss_now);
1233 }
1234 TCP_SKB_CB(skb)->seq += copy;
1235 }
1236
1237 len += copy;
1238 skb = next;
1239 }
1240 tcp_init_tso_segs(sk, nskb, nskb->len);
1241
1242 /* We're ready to send. If this fails, the probe will
1243 * be resegmented into mss-sized pieces by tcp_write_xmit(). */
1244 TCP_SKB_CB(nskb)->when = tcp_time_stamp;
1245 if (!tcp_transmit_skb(sk, nskb, 1, GFP_ATOMIC)) {
1246 /* Decrement cwnd here because we are sending
1247 * effectively two packets. */
1248 tp->snd_cwnd--;
1249 update_send_head(sk, tp, nskb);
1250
1251 icsk->icsk_mtup.probe_size = tcp_mss_to_mtu(sk, nskb->len);
1252 tp->mtu_probe.probe_seq_start = TCP_SKB_CB(nskb)->seq;
1253 tp->mtu_probe.probe_seq_end = TCP_SKB_CB(nskb)->end_seq;
1254
1255 return 1;
1256 }
1257
1258 return -1;
1259}
1260
1261
1066/* This routine writes packets to the network. It advances the 1262/* This routine writes packets to the network. It advances the
1067 * send_head. This happens as incoming acks open up the remote 1263 * send_head. This happens as incoming acks open up the remote
1068 * window for us. 1264 * window for us.
@@ -1076,6 +1272,7 @@ static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle)
1076 struct sk_buff *skb; 1272 struct sk_buff *skb;
1077 unsigned int tso_segs, sent_pkts; 1273 unsigned int tso_segs, sent_pkts;
1078 int cwnd_quota; 1274 int cwnd_quota;
1275 int result;
1079 1276
1080 /* If we are closed, the bytes will have to remain here. 1277 /* If we are closed, the bytes will have to remain here.
1081 * In time closedown will finish, we empty the write queue and all 1278 * In time closedown will finish, we empty the write queue and all
@@ -1085,6 +1282,14 @@ static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle)
1085 return 0; 1282 return 0;
1086 1283
1087 sent_pkts = 0; 1284 sent_pkts = 0;
1285
1286 /* Do MTU probing. */
1287 if ((result = tcp_mtu_probe(sk)) == 0) {
1288 return 0;
1289 } else if (result > 0) {
1290 sent_pkts = 1;
1291 }
1292
1088 while ((skb = sk->sk_send_head)) { 1293 while ((skb = sk->sk_send_head)) {
1089 unsigned int limit; 1294 unsigned int limit;
1090 1295
@@ -1455,9 +1660,15 @@ void tcp_simple_retransmit(struct sock *sk)
1455int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb) 1660int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
1456{ 1661{
1457 struct tcp_sock *tp = tcp_sk(sk); 1662 struct tcp_sock *tp = tcp_sk(sk);
1663 struct inet_connection_sock *icsk = inet_csk(sk);
1458 unsigned int cur_mss = tcp_current_mss(sk, 0); 1664 unsigned int cur_mss = tcp_current_mss(sk, 0);
1459 int err; 1665 int err;
1460 1666
1667 /* Inconslusive MTU probe */
1668 if (icsk->icsk_mtup.probe_size) {
1669 icsk->icsk_mtup.probe_size = 0;
1670 }
1671
1461 /* Do not sent more than we queued. 1/4 is reserved for possible 1672 /* Do not sent more than we queued. 1/4 is reserved for possible
1462 * copying overhead: fragmentation, tunneling, mangling etc. 1673 * copying overhead: fragmentation, tunneling, mangling etc.
1463 */ 1674 */
@@ -1883,6 +2094,7 @@ static void tcp_connect_init(struct sock *sk)
1883 if (tp->rx_opt.user_mss) 2094 if (tp->rx_opt.user_mss)
1884 tp->rx_opt.mss_clamp = tp->rx_opt.user_mss; 2095 tp->rx_opt.mss_clamp = tp->rx_opt.user_mss;
1885 tp->max_window = 0; 2096 tp->max_window = 0;
2097 tcp_mtup_init(sk);
1886 tcp_sync_mss(sk, dst_mtu(dst)); 2098 tcp_sync_mss(sk, dst_mtu(dst));
1887 2099
1888 if (!tp->window_clamp) 2100 if (!tp->window_clamp)
@@ -2180,3 +2392,4 @@ EXPORT_SYMBOL(tcp_make_synack);
2180EXPORT_SYMBOL(tcp_simple_retransmit); 2392EXPORT_SYMBOL(tcp_simple_retransmit);
2181EXPORT_SYMBOL(tcp_sync_mss); 2393EXPORT_SYMBOL(tcp_sync_mss);
2182EXPORT_SYMBOL(sysctl_tcp_tso_win_divisor); 2394EXPORT_SYMBOL(sysctl_tcp_tso_win_divisor);
2395EXPORT_SYMBOL(tcp_mtup_init);
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index e1880959614a..7c1bde3cd6cb 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -119,8 +119,10 @@ static int tcp_orphan_retries(struct sock *sk, int alive)
119/* A write timeout has occurred. Process the after effects. */ 119/* A write timeout has occurred. Process the after effects. */
120static int tcp_write_timeout(struct sock *sk) 120static int tcp_write_timeout(struct sock *sk)
121{ 121{
122 const struct inet_connection_sock *icsk = inet_csk(sk); 122 struct inet_connection_sock *icsk = inet_csk(sk);
123 struct tcp_sock *tp = tcp_sk(sk);
123 int retry_until; 124 int retry_until;
125 int mss;
124 126
125 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) { 127 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
126 if (icsk->icsk_retransmits) 128 if (icsk->icsk_retransmits)
@@ -128,25 +130,19 @@ static int tcp_write_timeout(struct sock *sk)
128 retry_until = icsk->icsk_syn_retries ? : sysctl_tcp_syn_retries; 130 retry_until = icsk->icsk_syn_retries ? : sysctl_tcp_syn_retries;
129 } else { 131 } else {
130 if (icsk->icsk_retransmits >= sysctl_tcp_retries1) { 132 if (icsk->icsk_retransmits >= sysctl_tcp_retries1) {
131 /* NOTE. draft-ietf-tcpimpl-pmtud-01.txt requires pmtu black 133 /* Black hole detection */
132 hole detection. :-( 134 if (sysctl_tcp_mtu_probing) {
133 135 if (!icsk->icsk_mtup.enabled) {
134 It is place to make it. It is not made. I do not want 136 icsk->icsk_mtup.enabled = 1;
135 to make it. It is disgusting. It does not work in any 137 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
136 case. Let me to cite the same draft, which requires for 138 } else {
137 us to implement this: 139 mss = min(sysctl_tcp_base_mss,
138 140 tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_low)/2);
139 "The one security concern raised by this memo is that ICMP black holes 141 mss = max(mss, 68 - tp->tcp_header_len);
140 are often caused by over-zealous security administrators who block 142 icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, mss);
141 all ICMP messages. It is vitally important that those who design and 143 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
142 deploy security systems understand the impact of strict filtering on 144 }
143 upper-layer protocols. The safest web site in the world is worthless 145 }
144 if most TCP implementations cannot transfer data from it. It would
145 be far nicer to have all of the black holes fixed rather than fixing
146 all of the TCP implementations."
147
148 Golden words :-).
149 */
150 146
151 dst_negative_advice(&sk->sk_dst_cache); 147 dst_negative_advice(&sk->sk_dst_cache);
152 } 148 }
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 00840474a449..3f93292b0ad8 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1207,16 +1207,13 @@ static int udp_destroy_sock(struct sock *sk)
1207/* 1207/*
1208 * Socket option code for UDP 1208 * Socket option code for UDP
1209 */ 1209 */
1210static int udp_setsockopt(struct sock *sk, int level, int optname, 1210static int do_udp_setsockopt(struct sock *sk, int level, int optname,
1211 char __user *optval, int optlen) 1211 char __user *optval, int optlen)
1212{ 1212{
1213 struct udp_sock *up = udp_sk(sk); 1213 struct udp_sock *up = udp_sk(sk);
1214 int val; 1214 int val;
1215 int err = 0; 1215 int err = 0;
1216 1216
1217 if (level != SOL_UDP)
1218 return ip_setsockopt(sk, level, optname, optval, optlen);
1219
1220 if(optlen<sizeof(int)) 1217 if(optlen<sizeof(int))
1221 return -EINVAL; 1218 return -EINVAL;
1222 1219
@@ -1256,15 +1253,30 @@ static int udp_setsockopt(struct sock *sk, int level, int optname,
1256 return err; 1253 return err;
1257} 1254}
1258 1255
1259static int udp_getsockopt(struct sock *sk, int level, int optname, 1256static int udp_setsockopt(struct sock *sk, int level, int optname,
1257 char __user *optval, int optlen)
1258{
1259 if (level != SOL_UDP)
1260 return ip_setsockopt(sk, level, optname, optval, optlen);
1261 return do_udp_setsockopt(sk, level, optname, optval, optlen);
1262}
1263
1264#ifdef CONFIG_COMPAT
1265static int compat_udp_setsockopt(struct sock *sk, int level, int optname,
1266 char __user *optval, int optlen)
1267{
1268 if (level != SOL_UDP)
1269 return compat_ip_setsockopt(sk, level, optname, optval, optlen);
1270 return do_udp_setsockopt(sk, level, optname, optval, optlen);
1271}
1272#endif
1273
1274static int do_udp_getsockopt(struct sock *sk, int level, int optname,
1260 char __user *optval, int __user *optlen) 1275 char __user *optval, int __user *optlen)
1261{ 1276{
1262 struct udp_sock *up = udp_sk(sk); 1277 struct udp_sock *up = udp_sk(sk);
1263 int val, len; 1278 int val, len;
1264 1279
1265 if (level != SOL_UDP)
1266 return ip_getsockopt(sk, level, optname, optval, optlen);
1267
1268 if(get_user(len,optlen)) 1280 if(get_user(len,optlen))
1269 return -EFAULT; 1281 return -EFAULT;
1270 1282
@@ -1293,6 +1305,23 @@ static int udp_getsockopt(struct sock *sk, int level, int optname,
1293 return 0; 1305 return 0;
1294} 1306}
1295 1307
1308static int udp_getsockopt(struct sock *sk, int level, int optname,
1309 char __user *optval, int __user *optlen)
1310{
1311 if (level != SOL_UDP)
1312 return ip_getsockopt(sk, level, optname, optval, optlen);
1313 return do_udp_getsockopt(sk, level, optname, optval, optlen);
1314}
1315
1316#ifdef CONFIG_COMPAT
1317static int compat_udp_getsockopt(struct sock *sk, int level, int optname,
1318 char __user *optval, int __user *optlen)
1319{
1320 if (level != SOL_UDP)
1321 return compat_ip_getsockopt(sk, level, optname, optval, optlen);
1322 return do_udp_getsockopt(sk, level, optname, optval, optlen);
1323}
1324#endif
1296/** 1325/**
1297 * udp_poll - wait for a UDP event. 1326 * udp_poll - wait for a UDP event.
1298 * @file - file struct 1327 * @file - file struct
@@ -1341,23 +1370,27 @@ unsigned int udp_poll(struct file *file, struct socket *sock, poll_table *wait)
1341} 1370}
1342 1371
1343struct proto udp_prot = { 1372struct proto udp_prot = {
1344 .name = "UDP", 1373 .name = "UDP",
1345 .owner = THIS_MODULE, 1374 .owner = THIS_MODULE,
1346 .close = udp_close, 1375 .close = udp_close,
1347 .connect = ip4_datagram_connect, 1376 .connect = ip4_datagram_connect,
1348 .disconnect = udp_disconnect, 1377 .disconnect = udp_disconnect,
1349 .ioctl = udp_ioctl, 1378 .ioctl = udp_ioctl,
1350 .destroy = udp_destroy_sock, 1379 .destroy = udp_destroy_sock,
1351 .setsockopt = udp_setsockopt, 1380 .setsockopt = udp_setsockopt,
1352 .getsockopt = udp_getsockopt, 1381 .getsockopt = udp_getsockopt,
1353 .sendmsg = udp_sendmsg, 1382 .sendmsg = udp_sendmsg,
1354 .recvmsg = udp_recvmsg, 1383 .recvmsg = udp_recvmsg,
1355 .sendpage = udp_sendpage, 1384 .sendpage = udp_sendpage,
1356 .backlog_rcv = udp_queue_rcv_skb, 1385 .backlog_rcv = udp_queue_rcv_skb,
1357 .hash = udp_v4_hash, 1386 .hash = udp_v4_hash,
1358 .unhash = udp_v4_unhash, 1387 .unhash = udp_v4_unhash,
1359 .get_port = udp_v4_get_port, 1388 .get_port = udp_v4_get_port,
1360 .obj_size = sizeof(struct udp_sock), 1389 .obj_size = sizeof(struct udp_sock),
1390#ifdef CONFIG_COMPAT
1391 .compat_setsockopt = compat_udp_setsockopt,
1392 .compat_getsockopt = compat_udp_getsockopt,
1393#endif
1361}; 1394};
1362 1395
1363/* ------------------------------------------------------------------------ */ 1396/* ------------------------------------------------------------------------ */
diff --git a/net/ipv4/xfrm4_tunnel.c b/net/ipv4/xfrm4_tunnel.c
index afbb0d4cc305..b08d56b117f8 100644
--- a/net/ipv4/xfrm4_tunnel.c
+++ b/net/ipv4/xfrm4_tunnel.c
@@ -5,6 +5,7 @@
5 5
6#include <linux/skbuff.h> 6#include <linux/skbuff.h>
7#include <linux/module.h> 7#include <linux/module.h>
8#include <linux/mutex.h>
8#include <net/xfrm.h> 9#include <net/xfrm.h>
9#include <net/ip.h> 10#include <net/ip.h>
10#include <net/protocol.h> 11#include <net/protocol.h>
@@ -26,19 +27,19 @@ static int ipip_xfrm_rcv(struct xfrm_state *x, struct xfrm_decap_state *decap, s
26} 27}
27 28
28static struct xfrm_tunnel *ipip_handler; 29static struct xfrm_tunnel *ipip_handler;
29static DECLARE_MUTEX(xfrm4_tunnel_sem); 30static DEFINE_MUTEX(xfrm4_tunnel_mutex);
30 31
31int xfrm4_tunnel_register(struct xfrm_tunnel *handler) 32int xfrm4_tunnel_register(struct xfrm_tunnel *handler)
32{ 33{
33 int ret; 34 int ret;
34 35
35 down(&xfrm4_tunnel_sem); 36 mutex_lock(&xfrm4_tunnel_mutex);
36 ret = 0; 37 ret = 0;
37 if (ipip_handler != NULL) 38 if (ipip_handler != NULL)
38 ret = -EINVAL; 39 ret = -EINVAL;
39 if (!ret) 40 if (!ret)
40 ipip_handler = handler; 41 ipip_handler = handler;
41 up(&xfrm4_tunnel_sem); 42 mutex_unlock(&xfrm4_tunnel_mutex);
42 43
43 return ret; 44 return ret;
44} 45}
@@ -49,13 +50,13 @@ int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler)
49{ 50{
50 int ret; 51 int ret;
51 52
52 down(&xfrm4_tunnel_sem); 53 mutex_lock(&xfrm4_tunnel_mutex);
53 ret = 0; 54 ret = 0;
54 if (ipip_handler != handler) 55 if (ipip_handler != handler)
55 ret = -EINVAL; 56 ret = -EINVAL;
56 if (!ret) 57 if (!ret)
57 ipip_handler = NULL; 58 ipip_handler = NULL;
58 up(&xfrm4_tunnel_sem); 59 mutex_unlock(&xfrm4_tunnel_mutex);
59 60
60 synchronize_net(); 61 synchronize_net();
61 62
diff --git a/net/ipv6/Kconfig b/net/ipv6/Kconfig
index ab7a9124f985..e6f83b6a2b76 100644
--- a/net/ipv6/Kconfig
+++ b/net/ipv6/Kconfig
@@ -6,8 +6,6 @@
6config IPV6 6config IPV6
7 tristate "The IPv6 protocol" 7 tristate "The IPv6 protocol"
8 default m 8 default m
9 select CRYPTO if IPV6_PRIVACY
10 select CRYPTO_MD5 if IPV6_PRIVACY
11 ---help--- 9 ---help---
12 This is complemental support for the IP version 6. 10 This is complemental support for the IP version 6.
13 You will still be able to do traditional IPv4 networking as well. 11 You will still be able to do traditional IPv4 networking as well.
@@ -22,7 +20,7 @@ config IPV6
22 module will be called ipv6. 20 module will be called ipv6.
23 21
24config IPV6_PRIVACY 22config IPV6_PRIVACY
25 bool "IPv6: Privacy Extensions (RFC 3041) support" 23 bool "IPv6: Privacy Extensions support"
26 depends on IPV6 24 depends on IPV6
27 ---help--- 25 ---help---
28 Privacy Extensions for Stateless Address Autoconfiguration in IPv6 26 Privacy Extensions for Stateless Address Autoconfiguration in IPv6
@@ -30,6 +28,9 @@ config IPV6_PRIVACY
30 pseudo-random global-scope unicast address(es) will assigned to 28 pseudo-random global-scope unicast address(es) will assigned to
31 your interface(s). 29 your interface(s).
32 30
31 We use our standard pseudo random algorithm to generate randomized
32 interface identifier, instead of one described in RFC 3041.
33
33 By default, kernel do not generate temporary addresses. 34 By default, kernel do not generate temporary addresses.
34 To use temporary addresses, do 35 To use temporary addresses, do
35 36
@@ -37,6 +38,25 @@ config IPV6_PRIVACY
37 38
38 See <file:Documentation/networking/ip-sysctl.txt> for details. 39 See <file:Documentation/networking/ip-sysctl.txt> for details.
39 40
41config IPV6_ROUTER_PREF
42 bool "IPv6: Router Preference (RFC 4191) support"
43 depends on IPV6
44 ---help---
45 Router Preference is an optional extension to the Router
46 Advertisement message to improve the ability of hosts
47 to pick more appropriate router, especially when the hosts
48 is placed in a multi-homed network.
49
50 If unsure, say N.
51
52config IPV6_ROUTE_INFO
53 bool "IPv6: Route Information (RFC 4191) support (EXPERIMENTAL)"
54 depends on IPV6_ROUTER_PREF && EXPERIMENTAL
55 ---help---
56 This is experimental support of Route Information.
57
58 If unsure, say N.
59
40config INET6_AH 60config INET6_AH
41 tristate "IPv6: AH transformation" 61 tristate "IPv6: AH transformation"
42 depends on IPV6 62 depends on IPV6
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 19727d941962..01c62a0d3742 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -78,8 +78,6 @@
78 78
79#ifdef CONFIG_IPV6_PRIVACY 79#ifdef CONFIG_IPV6_PRIVACY
80#include <linux/random.h> 80#include <linux/random.h>
81#include <linux/crypto.h>
82#include <linux/scatterlist.h>
83#endif 81#endif
84 82
85#include <asm/uaccess.h> 83#include <asm/uaccess.h>
@@ -110,8 +108,6 @@ static int __ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpad
110static void ipv6_regen_rndid(unsigned long data); 108static void ipv6_regen_rndid(unsigned long data);
111 109
112static int desync_factor = MAX_DESYNC_FACTOR * HZ; 110static int desync_factor = MAX_DESYNC_FACTOR * HZ;
113static struct crypto_tfm *md5_tfm;
114static DEFINE_SPINLOCK(md5_tfm_lock);
115#endif 111#endif
116 112
117static int ipv6_count_addresses(struct inet6_dev *idev); 113static int ipv6_count_addresses(struct inet6_dev *idev);
@@ -169,6 +165,15 @@ struct ipv6_devconf ipv6_devconf = {
169 .max_desync_factor = MAX_DESYNC_FACTOR, 165 .max_desync_factor = MAX_DESYNC_FACTOR,
170#endif 166#endif
171 .max_addresses = IPV6_MAX_ADDRESSES, 167 .max_addresses = IPV6_MAX_ADDRESSES,
168 .accept_ra_defrtr = 1,
169 .accept_ra_pinfo = 1,
170#ifdef CONFIG_IPV6_ROUTER_PREF
171 .accept_ra_rtr_pref = 1,
172 .rtr_probe_interval = 60 * HZ,
173#ifdef CONFIG_IPV6_ROUTE_INFO
174 .accept_ra_rt_info_max_plen = 0,
175#endif
176#endif
172}; 177};
173 178
174static struct ipv6_devconf ipv6_devconf_dflt = { 179static struct ipv6_devconf ipv6_devconf_dflt = {
@@ -190,6 +195,15 @@ static struct ipv6_devconf ipv6_devconf_dflt = {
190 .max_desync_factor = MAX_DESYNC_FACTOR, 195 .max_desync_factor = MAX_DESYNC_FACTOR,
191#endif 196#endif
192 .max_addresses = IPV6_MAX_ADDRESSES, 197 .max_addresses = IPV6_MAX_ADDRESSES,
198 .accept_ra_defrtr = 1,
199 .accept_ra_pinfo = 1,
200#ifdef CONFIG_IPV6_ROUTER_PREF
201 .accept_ra_rtr_pref = 1,
202 .rtr_probe_interval = 60 * HZ,
203#ifdef CONFIG_IPV6_ROUTE_INFO
204 .accept_ra_rt_info_max_plen = 0,
205#endif
206#endif
193}; 207};
194 208
195/* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */ 209/* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */
@@ -327,86 +341,83 @@ static struct inet6_dev * ipv6_add_dev(struct net_device *dev)
327 if (dev->mtu < IPV6_MIN_MTU) 341 if (dev->mtu < IPV6_MIN_MTU)
328 return NULL; 342 return NULL;
329 343
330 ndev = kmalloc(sizeof(struct inet6_dev), GFP_KERNEL); 344 ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL);
331 345
332 if (ndev) { 346 if (ndev == NULL)
333 memset(ndev, 0, sizeof(struct inet6_dev)); 347 return NULL;
334 348
335 rwlock_init(&ndev->lock); 349 rwlock_init(&ndev->lock);
336 ndev->dev = dev; 350 ndev->dev = dev;
337 memcpy(&ndev->cnf, &ipv6_devconf_dflt, sizeof(ndev->cnf)); 351 memcpy(&ndev->cnf, &ipv6_devconf_dflt, sizeof(ndev->cnf));
338 ndev->cnf.mtu6 = dev->mtu; 352 ndev->cnf.mtu6 = dev->mtu;
339 ndev->cnf.sysctl = NULL; 353 ndev->cnf.sysctl = NULL;
340 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl); 354 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl);
341 if (ndev->nd_parms == NULL) { 355 if (ndev->nd_parms == NULL) {
342 kfree(ndev); 356 kfree(ndev);
343 return NULL; 357 return NULL;
344 } 358 }
345 /* We refer to the device */ 359 /* We refer to the device */
346 dev_hold(dev); 360 dev_hold(dev);
347
348 if (snmp6_alloc_dev(ndev) < 0) {
349 ADBG((KERN_WARNING
350 "%s(): cannot allocate memory for statistics; dev=%s.\n",
351 __FUNCTION__, dev->name));
352 neigh_parms_release(&nd_tbl, ndev->nd_parms);
353 ndev->dead = 1;
354 in6_dev_finish_destroy(ndev);
355 return NULL;
356 }
357 361
358 if (snmp6_register_dev(ndev) < 0) { 362 if (snmp6_alloc_dev(ndev) < 0) {
359 ADBG((KERN_WARNING 363 ADBG((KERN_WARNING
360 "%s(): cannot create /proc/net/dev_snmp6/%s\n", 364 "%s(): cannot allocate memory for statistics; dev=%s.\n",
361 __FUNCTION__, dev->name)); 365 __FUNCTION__, dev->name));
362 neigh_parms_release(&nd_tbl, ndev->nd_parms); 366 neigh_parms_release(&nd_tbl, ndev->nd_parms);
363 ndev->dead = 1; 367 ndev->dead = 1;
364 in6_dev_finish_destroy(ndev); 368 in6_dev_finish_destroy(ndev);
365 return NULL; 369 return NULL;
366 } 370 }
367 371
368 /* One reference from device. We must do this before 372 if (snmp6_register_dev(ndev) < 0) {
369 * we invoke __ipv6_regen_rndid(). 373 ADBG((KERN_WARNING
370 */ 374 "%s(): cannot create /proc/net/dev_snmp6/%s\n",
371 in6_dev_hold(ndev); 375 __FUNCTION__, dev->name));
376 neigh_parms_release(&nd_tbl, ndev->nd_parms);
377 ndev->dead = 1;
378 in6_dev_finish_destroy(ndev);
379 return NULL;
380 }
381
382 /* One reference from device. We must do this before
383 * we invoke __ipv6_regen_rndid().
384 */
385 in6_dev_hold(ndev);
372 386
373#ifdef CONFIG_IPV6_PRIVACY 387#ifdef CONFIG_IPV6_PRIVACY
374 get_random_bytes(ndev->rndid, sizeof(ndev->rndid)); 388 init_timer(&ndev->regen_timer);
375 get_random_bytes(ndev->entropy, sizeof(ndev->entropy)); 389 ndev->regen_timer.function = ipv6_regen_rndid;
376 init_timer(&ndev->regen_timer); 390 ndev->regen_timer.data = (unsigned long) ndev;
377 ndev->regen_timer.function = ipv6_regen_rndid; 391 if ((dev->flags&IFF_LOOPBACK) ||
378 ndev->regen_timer.data = (unsigned long) ndev; 392 dev->type == ARPHRD_TUNNEL ||
379 if ((dev->flags&IFF_LOOPBACK) || 393 dev->type == ARPHRD_NONE ||
380 dev->type == ARPHRD_TUNNEL || 394 dev->type == ARPHRD_SIT) {
381 dev->type == ARPHRD_NONE || 395 printk(KERN_INFO
382 dev->type == ARPHRD_SIT) { 396 "%s: Disabled Privacy Extensions\n",
383 printk(KERN_INFO 397 dev->name);
384 "%s: Disabled Privacy Extensions\n", 398 ndev->cnf.use_tempaddr = -1;
385 dev->name); 399 } else {
386 ndev->cnf.use_tempaddr = -1; 400 in6_dev_hold(ndev);
387 } else { 401 ipv6_regen_rndid((unsigned long) ndev);
388 in6_dev_hold(ndev); 402 }
389 ipv6_regen_rndid((unsigned long) ndev);
390 }
391#endif 403#endif
392 404
393 if (netif_carrier_ok(dev)) 405 if (netif_carrier_ok(dev))
394 ndev->if_flags |= IF_READY; 406 ndev->if_flags |= IF_READY;
395 407
396 write_lock_bh(&addrconf_lock); 408 write_lock_bh(&addrconf_lock);
397 dev->ip6_ptr = ndev; 409 dev->ip6_ptr = ndev;
398 write_unlock_bh(&addrconf_lock); 410 write_unlock_bh(&addrconf_lock);
399 411
400 ipv6_mc_init_dev(ndev); 412 ipv6_mc_init_dev(ndev);
401 ndev->tstamp = jiffies; 413 ndev->tstamp = jiffies;
402#ifdef CONFIG_SYSCTL 414#ifdef CONFIG_SYSCTL
403 neigh_sysctl_register(dev, ndev->nd_parms, NET_IPV6, 415 neigh_sysctl_register(dev, ndev->nd_parms, NET_IPV6,
404 NET_IPV6_NEIGH, "ipv6", 416 NET_IPV6_NEIGH, "ipv6",
405 &ndisc_ifinfo_sysctl_change, 417 &ndisc_ifinfo_sysctl_change,
406 NULL); 418 NULL);
407 addrconf_sysctl_register(ndev, &ndev->cnf); 419 addrconf_sysctl_register(ndev, &ndev->cnf);
408#endif 420#endif
409 }
410 return ndev; 421 return ndev;
411} 422}
412 423
@@ -524,7 +535,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen,
524 goto out; 535 goto out;
525 } 536 }
526 537
527 ifa = kmalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC); 538 ifa = kzalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC);
528 539
529 if (ifa == NULL) { 540 if (ifa == NULL) {
530 ADBG(("ipv6_add_addr: malloc failed\n")); 541 ADBG(("ipv6_add_addr: malloc failed\n"));
@@ -538,7 +549,6 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen,
538 goto out; 549 goto out;
539 } 550 }
540 551
541 memset(ifa, 0, sizeof(struct inet6_ifaddr));
542 ipv6_addr_copy(&ifa->addr, addr); 552 ipv6_addr_copy(&ifa->addr, addr);
543 553
544 spin_lock_init(&ifa->lock); 554 spin_lock_init(&ifa->lock);
@@ -1305,52 +1315,67 @@ static void addrconf_leave_anycast(struct inet6_ifaddr *ifp)
1305 __ipv6_dev_ac_dec(ifp->idev, &addr); 1315 __ipv6_dev_ac_dec(ifp->idev, &addr);
1306} 1316}
1307 1317
1318static int addrconf_ifid_eui48(u8 *eui, struct net_device *dev)
1319{
1320 if (dev->addr_len != ETH_ALEN)
1321 return -1;
1322 memcpy(eui, dev->dev_addr, 3);
1323 memcpy(eui + 5, dev->dev_addr + 3, 3);
1324
1325 /*
1326 * The zSeries OSA network cards can be shared among various
1327 * OS instances, but the OSA cards have only one MAC address.
1328 * This leads to duplicate address conflicts in conjunction
1329 * with IPv6 if more than one instance uses the same card.
1330 *
1331 * The driver for these cards can deliver a unique 16-bit
1332 * identifier for each instance sharing the same card. It is
1333 * placed instead of 0xFFFE in the interface identifier. The
1334 * "u" bit of the interface identifier is not inverted in this
1335 * case. Hence the resulting interface identifier has local
1336 * scope according to RFC2373.
1337 */
1338 if (dev->dev_id) {
1339 eui[3] = (dev->dev_id >> 8) & 0xFF;
1340 eui[4] = dev->dev_id & 0xFF;
1341 } else {
1342 eui[3] = 0xFF;
1343 eui[4] = 0xFE;
1344 eui[0] ^= 2;
1345 }
1346 return 0;
1347}
1348
1349static int addrconf_ifid_arcnet(u8 *eui, struct net_device *dev)
1350{
1351 /* XXX: inherit EUI-64 from other interface -- yoshfuji */
1352 if (dev->addr_len != ARCNET_ALEN)
1353 return -1;
1354 memset(eui, 0, 7);
1355 eui[7] = *(u8*)dev->dev_addr;
1356 return 0;
1357}
1358
1359static int addrconf_ifid_infiniband(u8 *eui, struct net_device *dev)
1360{
1361 if (dev->addr_len != INFINIBAND_ALEN)
1362 return -1;
1363 memcpy(eui, dev->dev_addr + 12, 8);
1364 eui[0] |= 2;
1365 return 0;
1366}
1367
1308static int ipv6_generate_eui64(u8 *eui, struct net_device *dev) 1368static int ipv6_generate_eui64(u8 *eui, struct net_device *dev)
1309{ 1369{
1310 switch (dev->type) { 1370 switch (dev->type) {
1311 case ARPHRD_ETHER: 1371 case ARPHRD_ETHER:
1312 case ARPHRD_FDDI: 1372 case ARPHRD_FDDI:
1313 case ARPHRD_IEEE802_TR: 1373 case ARPHRD_IEEE802_TR:
1314 if (dev->addr_len != ETH_ALEN) 1374 return addrconf_ifid_eui48(eui, dev);
1315 return -1;
1316 memcpy(eui, dev->dev_addr, 3);
1317 memcpy(eui + 5, dev->dev_addr + 3, 3);
1318
1319 /*
1320 * The zSeries OSA network cards can be shared among various
1321 * OS instances, but the OSA cards have only one MAC address.
1322 * This leads to duplicate address conflicts in conjunction
1323 * with IPv6 if more than one instance uses the same card.
1324 *
1325 * The driver for these cards can deliver a unique 16-bit
1326 * identifier for each instance sharing the same card. It is
1327 * placed instead of 0xFFFE in the interface identifier. The
1328 * "u" bit of the interface identifier is not inverted in this
1329 * case. Hence the resulting interface identifier has local
1330 * scope according to RFC2373.
1331 */
1332 if (dev->dev_id) {
1333 eui[3] = (dev->dev_id >> 8) & 0xFF;
1334 eui[4] = dev->dev_id & 0xFF;
1335 } else {
1336 eui[3] = 0xFF;
1337 eui[4] = 0xFE;
1338 eui[0] ^= 2;
1339 }
1340 return 0;
1341 case ARPHRD_ARCNET: 1375 case ARPHRD_ARCNET:
1342 /* XXX: inherit EUI-64 from other interface -- yoshfuji */ 1376 return addrconf_ifid_arcnet(eui, dev);
1343 if (dev->addr_len != ARCNET_ALEN)
1344 return -1;
1345 memset(eui, 0, 7);
1346 eui[7] = *(u8*)dev->dev_addr;
1347 return 0;
1348 case ARPHRD_INFINIBAND: 1377 case ARPHRD_INFINIBAND:
1349 if (dev->addr_len != INFINIBAND_ALEN) 1378 return addrconf_ifid_infiniband(eui, dev);
1350 return -1;
1351 memcpy(eui, dev->dev_addr + 12, 8);
1352 eui[0] |= 2;
1353 return 0;
1354 } 1379 }
1355 return -1; 1380 return -1;
1356} 1381}
@@ -1376,34 +1401,9 @@ static int ipv6_inherit_eui64(u8 *eui, struct inet6_dev *idev)
1376/* (re)generation of randomized interface identifier (RFC 3041 3.2, 3.5) */ 1401/* (re)generation of randomized interface identifier (RFC 3041 3.2, 3.5) */
1377static int __ipv6_regen_rndid(struct inet6_dev *idev) 1402static int __ipv6_regen_rndid(struct inet6_dev *idev)
1378{ 1403{
1379 struct net_device *dev;
1380 struct scatterlist sg[2];
1381
1382 sg_set_buf(&sg[0], idev->entropy, 8);
1383 sg_set_buf(&sg[1], idev->work_eui64, 8);
1384
1385 dev = idev->dev;
1386
1387 if (ipv6_generate_eui64(idev->work_eui64, dev)) {
1388 printk(KERN_INFO
1389 "__ipv6_regen_rndid(idev=%p): cannot get EUI64 identifier; use random bytes.\n",
1390 idev);
1391 get_random_bytes(idev->work_eui64, sizeof(idev->work_eui64));
1392 }
1393regen: 1404regen:
1394 spin_lock(&md5_tfm_lock); 1405 get_random_bytes(idev->rndid, sizeof(idev->rndid));
1395 if (unlikely(md5_tfm == NULL)) {
1396 spin_unlock(&md5_tfm_lock);
1397 return -1;
1398 }
1399 crypto_digest_init(md5_tfm);
1400 crypto_digest_update(md5_tfm, sg, 2);
1401 crypto_digest_final(md5_tfm, idev->work_digest);
1402 spin_unlock(&md5_tfm_lock);
1403
1404 memcpy(idev->rndid, &idev->work_digest[0], 8);
1405 idev->rndid[0] &= ~0x02; 1406 idev->rndid[0] &= ~0x02;
1406 memcpy(idev->entropy, &idev->work_digest[8], 8);
1407 1407
1408 /* 1408 /*
1409 * <draft-ietf-ipngwg-temp-addresses-v2-00.txt>: 1409 * <draft-ietf-ipngwg-temp-addresses-v2-00.txt>:
@@ -2143,7 +2143,6 @@ static void addrconf_ip6_tnl_config(struct net_device *dev)
2143 return; 2143 return;
2144 } 2144 }
2145 ip6_tnl_add_linklocal(idev); 2145 ip6_tnl_add_linklocal(idev);
2146 addrconf_add_mroute(dev);
2147} 2146}
2148 2147
2149static int addrconf_notify(struct notifier_block *this, unsigned long event, 2148static int addrconf_notify(struct notifier_block *this, unsigned long event,
@@ -2668,11 +2667,10 @@ static int if6_seq_open(struct inode *inode, struct file *file)
2668{ 2667{
2669 struct seq_file *seq; 2668 struct seq_file *seq;
2670 int rc = -ENOMEM; 2669 int rc = -ENOMEM;
2671 struct if6_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL); 2670 struct if6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
2672 2671
2673 if (!s) 2672 if (!s)
2674 goto out; 2673 goto out;
2675 memset(s, 0, sizeof(*s));
2676 2674
2677 rc = seq_open(file, &if6_seq_ops); 2675 rc = seq_open(file, &if6_seq_ops);
2678 if (rc) 2676 if (rc)
@@ -3133,6 +3131,15 @@ static void inline ipv6_store_devconf(struct ipv6_devconf *cnf,
3133 array[DEVCONF_MAX_DESYNC_FACTOR] = cnf->max_desync_factor; 3131 array[DEVCONF_MAX_DESYNC_FACTOR] = cnf->max_desync_factor;
3134#endif 3132#endif
3135 array[DEVCONF_MAX_ADDRESSES] = cnf->max_addresses; 3133 array[DEVCONF_MAX_ADDRESSES] = cnf->max_addresses;
3134 array[DEVCONF_ACCEPT_RA_DEFRTR] = cnf->accept_ra_defrtr;
3135 array[DEVCONF_ACCEPT_RA_PINFO] = cnf->accept_ra_pinfo;
3136#ifdef CONFIG_IPV6_ROUTER_PREF
3137 array[DEVCONF_ACCEPT_RA_RTR_PREF] = cnf->accept_ra_rtr_pref;
3138 array[DEVCONF_RTR_PROBE_INTERVAL] = cnf->rtr_probe_interval;
3139#ifdef CONFIV_IPV6_ROUTE_INFO
3140 array[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN] = cnf->accept_ra_rt_info_max_plen;
3141#endif
3142#endif
3136} 3143}
3137 3144
3138static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev, 3145static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,
@@ -3586,6 +3593,51 @@ static struct addrconf_sysctl_table
3586 .proc_handler = &proc_dointvec, 3593 .proc_handler = &proc_dointvec,
3587 }, 3594 },
3588 { 3595 {
3596 .ctl_name = NET_IPV6_ACCEPT_RA_DEFRTR,
3597 .procname = "accept_ra_defrtr",
3598 .data = &ipv6_devconf.accept_ra_defrtr,
3599 .maxlen = sizeof(int),
3600 .mode = 0644,
3601 .proc_handler = &proc_dointvec,
3602 },
3603 {
3604 .ctl_name = NET_IPV6_ACCEPT_RA_PINFO,
3605 .procname = "accept_ra_pinfo",
3606 .data = &ipv6_devconf.accept_ra_pinfo,
3607 .maxlen = sizeof(int),
3608 .mode = 0644,
3609 .proc_handler = &proc_dointvec,
3610 },
3611#ifdef CONFIG_IPV6_ROUTER_PREF
3612 {
3613 .ctl_name = NET_IPV6_ACCEPT_RA_RTR_PREF,
3614 .procname = "accept_ra_rtr_pref",
3615 .data = &ipv6_devconf.accept_ra_rtr_pref,
3616 .maxlen = sizeof(int),
3617 .mode = 0644,
3618 .proc_handler = &proc_dointvec,
3619 },
3620 {
3621 .ctl_name = NET_IPV6_RTR_PROBE_INTERVAL,
3622 .procname = "router_probe_interval",
3623 .data = &ipv6_devconf.rtr_probe_interval,
3624 .maxlen = sizeof(int),
3625 .mode = 0644,
3626 .proc_handler = &proc_dointvec_jiffies,
3627 .strategy = &sysctl_jiffies,
3628 },
3629#ifdef CONFIV_IPV6_ROUTE_INFO
3630 {
3631 .ctl_name = NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN,
3632 .procname = "accept_ra_rt_info_max_plen",
3633 .data = &ipv6_devconf.accept_ra_rt_info_max_plen,
3634 .maxlen = sizeof(int),
3635 .mode = 0644,
3636 .proc_handler = &proc_dointvec,
3637 },
3638#endif
3639#endif
3640 {
3589 .ctl_name = 0, /* sentinel */ 3641 .ctl_name = 0, /* sentinel */
3590 } 3642 }
3591 }, 3643 },
@@ -3760,13 +3812,6 @@ int __init addrconf_init(void)
3760 3812
3761 register_netdevice_notifier(&ipv6_dev_notf); 3813 register_netdevice_notifier(&ipv6_dev_notf);
3762 3814
3763#ifdef CONFIG_IPV6_PRIVACY
3764 md5_tfm = crypto_alloc_tfm("md5", 0);
3765 if (unlikely(md5_tfm == NULL))
3766 printk(KERN_WARNING
3767 "failed to load transform for md5\n");
3768#endif
3769
3770 addrconf_verify(0); 3815 addrconf_verify(0);
3771 rtnetlink_links[PF_INET6] = inet6_rtnetlink_table; 3816 rtnetlink_links[PF_INET6] = inet6_rtnetlink_table;
3772#ifdef CONFIG_SYSCTL 3817#ifdef CONFIG_SYSCTL
@@ -3829,11 +3874,6 @@ void __exit addrconf_cleanup(void)
3829 3874
3830 rtnl_unlock(); 3875 rtnl_unlock();
3831 3876
3832#ifdef CONFIG_IPV6_PRIVACY
3833 crypto_free_tfm(md5_tfm);
3834 md5_tfm = NULL;
3835#endif
3836
3837#ifdef CONFIG_PROC_FS 3877#ifdef CONFIG_PROC_FS
3838 proc_net_remove("if_inet6"); 3878 proc_net_remove("if_inet6");
3839#endif 3879#endif
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 6c9711ac1c03..e19457fe4f6e 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -456,45 +456,53 @@ int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
456} 456}
457 457
458const struct proto_ops inet6_stream_ops = { 458const struct proto_ops inet6_stream_ops = {
459 .family = PF_INET6, 459 .family = PF_INET6,
460 .owner = THIS_MODULE, 460 .owner = THIS_MODULE,
461 .release = inet6_release, 461 .release = inet6_release,
462 .bind = inet6_bind, 462 .bind = inet6_bind,
463 .connect = inet_stream_connect, /* ok */ 463 .connect = inet_stream_connect, /* ok */
464 .socketpair = sock_no_socketpair, /* a do nothing */ 464 .socketpair = sock_no_socketpair, /* a do nothing */
465 .accept = inet_accept, /* ok */ 465 .accept = inet_accept, /* ok */
466 .getname = inet6_getname, 466 .getname = inet6_getname,
467 .poll = tcp_poll, /* ok */ 467 .poll = tcp_poll, /* ok */
468 .ioctl = inet6_ioctl, /* must change */ 468 .ioctl = inet6_ioctl, /* must change */
469 .listen = inet_listen, /* ok */ 469 .listen = inet_listen, /* ok */
470 .shutdown = inet_shutdown, /* ok */ 470 .shutdown = inet_shutdown, /* ok */
471 .setsockopt = sock_common_setsockopt, /* ok */ 471 .setsockopt = sock_common_setsockopt, /* ok */
472 .getsockopt = sock_common_getsockopt, /* ok */ 472 .getsockopt = sock_common_getsockopt, /* ok */
473 .sendmsg = inet_sendmsg, /* ok */ 473 .sendmsg = inet_sendmsg, /* ok */
474 .recvmsg = sock_common_recvmsg, /* ok */ 474 .recvmsg = sock_common_recvmsg, /* ok */
475 .mmap = sock_no_mmap, 475 .mmap = sock_no_mmap,
476 .sendpage = tcp_sendpage 476 .sendpage = tcp_sendpage,
477#ifdef CONFIG_COMPAT
478 .compat_setsockopt = compat_sock_common_setsockopt,
479 .compat_getsockopt = compat_sock_common_getsockopt,
480#endif
477}; 481};
478 482
479const struct proto_ops inet6_dgram_ops = { 483const struct proto_ops inet6_dgram_ops = {
480 .family = PF_INET6, 484 .family = PF_INET6,
481 .owner = THIS_MODULE, 485 .owner = THIS_MODULE,
482 .release = inet6_release, 486 .release = inet6_release,
483 .bind = inet6_bind, 487 .bind = inet6_bind,
484 .connect = inet_dgram_connect, /* ok */ 488 .connect = inet_dgram_connect, /* ok */
485 .socketpair = sock_no_socketpair, /* a do nothing */ 489 .socketpair = sock_no_socketpair, /* a do nothing */
486 .accept = sock_no_accept, /* a do nothing */ 490 .accept = sock_no_accept, /* a do nothing */
487 .getname = inet6_getname, 491 .getname = inet6_getname,
488 .poll = udp_poll, /* ok */ 492 .poll = udp_poll, /* ok */
489 .ioctl = inet6_ioctl, /* must change */ 493 .ioctl = inet6_ioctl, /* must change */
490 .listen = sock_no_listen, /* ok */ 494 .listen = sock_no_listen, /* ok */
491 .shutdown = inet_shutdown, /* ok */ 495 .shutdown = inet_shutdown, /* ok */
492 .setsockopt = sock_common_setsockopt, /* ok */ 496 .setsockopt = sock_common_setsockopt, /* ok */
493 .getsockopt = sock_common_getsockopt, /* ok */ 497 .getsockopt = sock_common_getsockopt, /* ok */
494 .sendmsg = inet_sendmsg, /* ok */ 498 .sendmsg = inet_sendmsg, /* ok */
495 .recvmsg = sock_common_recvmsg, /* ok */ 499 .recvmsg = sock_common_recvmsg, /* ok */
496 .mmap = sock_no_mmap, 500 .mmap = sock_no_mmap,
497 .sendpage = sock_no_sendpage, 501 .sendpage = sock_no_sendpage,
502#ifdef CONFIG_COMPAT
503 .compat_setsockopt = compat_sock_common_setsockopt,
504 .compat_getsockopt = compat_sock_common_getsockopt,
505#endif
498}; 506};
499 507
500static struct net_proto_family inet6_family_ops = { 508static struct net_proto_family inet6_family_ops = {
@@ -505,24 +513,28 @@ static struct net_proto_family inet6_family_ops = {
505 513
506/* Same as inet6_dgram_ops, sans udp_poll. */ 514/* Same as inet6_dgram_ops, sans udp_poll. */
507static const struct proto_ops inet6_sockraw_ops = { 515static const struct proto_ops inet6_sockraw_ops = {
508 .family = PF_INET6, 516 .family = PF_INET6,
509 .owner = THIS_MODULE, 517 .owner = THIS_MODULE,
510 .release = inet6_release, 518 .release = inet6_release,
511 .bind = inet6_bind, 519 .bind = inet6_bind,
512 .connect = inet_dgram_connect, /* ok */ 520 .connect = inet_dgram_connect, /* ok */
513 .socketpair = sock_no_socketpair, /* a do nothing */ 521 .socketpair = sock_no_socketpair, /* a do nothing */
514 .accept = sock_no_accept, /* a do nothing */ 522 .accept = sock_no_accept, /* a do nothing */
515 .getname = inet6_getname, 523 .getname = inet6_getname,
516 .poll = datagram_poll, /* ok */ 524 .poll = datagram_poll, /* ok */
517 .ioctl = inet6_ioctl, /* must change */ 525 .ioctl = inet6_ioctl, /* must change */
518 .listen = sock_no_listen, /* ok */ 526 .listen = sock_no_listen, /* ok */
519 .shutdown = inet_shutdown, /* ok */ 527 .shutdown = inet_shutdown, /* ok */
520 .setsockopt = sock_common_setsockopt, /* ok */ 528 .setsockopt = sock_common_setsockopt, /* ok */
521 .getsockopt = sock_common_getsockopt, /* ok */ 529 .getsockopt = sock_common_getsockopt, /* ok */
522 .sendmsg = inet_sendmsg, /* ok */ 530 .sendmsg = inet_sendmsg, /* ok */
523 .recvmsg = sock_common_recvmsg, /* ok */ 531 .recvmsg = sock_common_recvmsg, /* ok */
524 .mmap = sock_no_mmap, 532 .mmap = sock_no_mmap,
525 .sendpage = sock_no_sendpage, 533 .sendpage = sock_no_sendpage,
534#ifdef CONFIG_COMPAT
535 .compat_setsockopt = compat_sock_common_setsockopt,
536 .compat_getsockopt = compat_sock_common_getsockopt,
537#endif
526}; 538};
527 539
528static struct inet_protosw rawv6_protosw = { 540static struct inet_protosw rawv6_protosw = {
diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
index 84963749ab77..cf58251df4b3 100644
--- a/net/ipv6/ah6.c
+++ b/net/ipv6/ah6.c
@@ -213,6 +213,7 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
213 ah->reserved = 0; 213 ah->reserved = 0;
214 ah->spi = x->id.spi; 214 ah->spi = x->id.spi;
215 ah->seq_no = htonl(++x->replay.oseq); 215 ah->seq_no = htonl(++x->replay.oseq);
216 xfrm_aevent_doreplay(x);
216 ahp->icv(ahp, skb, ah->auth_data); 217 ahp->icv(ahp, skb, ah->auth_data);
217 218
218 err = 0; 219 err = 0;
@@ -353,12 +354,10 @@ static int ah6_init_state(struct xfrm_state *x)
353 if (x->encap) 354 if (x->encap)
354 goto error; 355 goto error;
355 356
356 ahp = kmalloc(sizeof(*ahp), GFP_KERNEL); 357 ahp = kzalloc(sizeof(*ahp), GFP_KERNEL);
357 if (ahp == NULL) 358 if (ahp == NULL)
358 return -ENOMEM; 359 return -ENOMEM;
359 360
360 memset(ahp, 0, sizeof(*ahp));
361
362 ahp->key = x->aalg->alg_key; 361 ahp->key = x->aalg->alg_key;
363 ahp->key_len = (x->aalg->alg_key_len+7)/8; 362 ahp->key_len = (x->aalg->alg_key_len+7)/8;
364 ahp->tfm = crypto_alloc_tfm(x->aalg->alg_name, 0); 363 ahp->tfm = crypto_alloc_tfm(x->aalg->alg_name, 0);
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index 840a33d33296..39ec528923f6 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -308,7 +308,7 @@ int ipv6_dev_ac_inc(struct net_device *dev, struct in6_addr *addr)
308 * not found: create a new one. 308 * not found: create a new one.
309 */ 309 */
310 310
311 aca = kmalloc(sizeof(struct ifacaddr6), GFP_ATOMIC); 311 aca = kzalloc(sizeof(struct ifacaddr6), GFP_ATOMIC);
312 312
313 if (aca == NULL) { 313 if (aca == NULL) {
314 err = -ENOMEM; 314 err = -ENOMEM;
@@ -322,8 +322,6 @@ int ipv6_dev_ac_inc(struct net_device *dev, struct in6_addr *addr)
322 goto out; 322 goto out;
323 } 323 }
324 324
325 memset(aca, 0, sizeof(struct ifacaddr6));
326
327 ipv6_addr_copy(&aca->aca_addr, addr); 325 ipv6_addr_copy(&aca->aca_addr, addr);
328 aca->aca_idev = idev; 326 aca->aca_idev = idev;
329 aca->aca_rt = rt; 327 aca->aca_rt = rt;
@@ -550,7 +548,7 @@ static int ac6_seq_open(struct inode *inode, struct file *file)
550{ 548{
551 struct seq_file *seq; 549 struct seq_file *seq;
552 int rc = -ENOMEM; 550 int rc = -ENOMEM;
553 struct ac6_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL); 551 struct ac6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
554 552
555 if (!s) 553 if (!s)
556 goto out; 554 goto out;
@@ -561,7 +559,6 @@ static int ac6_seq_open(struct inode *inode, struct file *file)
561 559
562 seq = file->private_data; 560 seq = file->private_data;
563 seq->private = s; 561 seq->private = s;
564 memset(s, 0, sizeof(*s));
565out: 562out:
566 return rc; 563 return rc;
567out_kfree: 564out_kfree:
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index 7b5b94f13902..3dcaac7a0972 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -94,6 +94,7 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
94 94
95 esph->spi = x->id.spi; 95 esph->spi = x->id.spi;
96 esph->seq_no = htonl(++x->replay.oseq); 96 esph->seq_no = htonl(++x->replay.oseq);
97 xfrm_aevent_doreplay(x);
97 98
98 if (esp->conf.ivlen) 99 if (esp->conf.ivlen)
99 crypto_cipher_set_iv(tfm, esp->conf.ivec, crypto_tfm_alg_ivsize(tfm)); 100 crypto_cipher_set_iv(tfm, esp->conf.ivec, crypto_tfm_alg_ivsize(tfm));
@@ -304,12 +305,10 @@ static int esp6_init_state(struct xfrm_state *x)
304 if (x->encap) 305 if (x->encap)
305 goto error; 306 goto error;
306 307
307 esp = kmalloc(sizeof(*esp), GFP_KERNEL); 308 esp = kzalloc(sizeof(*esp), GFP_KERNEL);
308 if (esp == NULL) 309 if (esp == NULL)
309 return -ENOMEM; 310 return -ENOMEM;
310 311
311 memset(esp, 0, sizeof(*esp));
312
313 if (x->aalg) { 312 if (x->aalg) {
314 struct xfrm_algo_desc *aalg_desc; 313 struct xfrm_algo_desc *aalg_desc;
315 314
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 1bf6d9a769e6..2cb6149349bf 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -1105,7 +1105,6 @@ static int fib6_age(struct rt6_info *rt, void *arg)
1105 if (rt->rt6i_flags&RTF_EXPIRES && rt->rt6i_expires) { 1105 if (rt->rt6i_flags&RTF_EXPIRES && rt->rt6i_expires) {
1106 if (time_after(now, rt->rt6i_expires)) { 1106 if (time_after(now, rt->rt6i_expires)) {
1107 RT6_TRACE("expiring %p\n", rt); 1107 RT6_TRACE("expiring %p\n", rt);
1108 rt6_reset_dflt_pointer(rt);
1109 return -1; 1108 return -1;
1110 } 1109 }
1111 gc_args.more++; 1110 gc_args.more++;
diff --git a/net/ipv6/ip6_flowlabel.c b/net/ipv6/ip6_flowlabel.c
index 69cbe8a66d02..f9ca63912fbf 100644
--- a/net/ipv6/ip6_flowlabel.c
+++ b/net/ipv6/ip6_flowlabel.c
@@ -287,10 +287,9 @@ fl_create(struct in6_flowlabel_req *freq, char __user *optval, int optlen, int *
287 int err; 287 int err;
288 288
289 err = -ENOMEM; 289 err = -ENOMEM;
290 fl = kmalloc(sizeof(*fl), GFP_KERNEL); 290 fl = kzalloc(sizeof(*fl), GFP_KERNEL);
291 if (fl == NULL) 291 if (fl == NULL)
292 goto done; 292 goto done;
293 memset(fl, 0, sizeof(*fl));
294 293
295 olen = optlen - CMSG_ALIGN(sizeof(*freq)); 294 olen = optlen - CMSG_ALIGN(sizeof(*freq));
296 if (olen > 0) { 295 if (olen > 0) {
@@ -663,7 +662,7 @@ static int ip6fl_seq_open(struct inode *inode, struct file *file)
663{ 662{
664 struct seq_file *seq; 663 struct seq_file *seq;
665 int rc = -ENOMEM; 664 int rc = -ENOMEM;
666 struct ip6fl_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL); 665 struct ip6fl_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
667 666
668 if (!s) 667 if (!s)
669 goto out; 668 goto out;
@@ -674,7 +673,6 @@ static int ip6fl_seq_open(struct inode *inode, struct file *file)
674 673
675 seq = file->private_data; 674 seq = file->private_data;
676 seq->private = s; 675 seq->private = s;
677 memset(s, 0, sizeof(*s));
678out: 676out:
679 return rc; 677 return rc;
680out_kfree: 678out_kfree:
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 5bf70b1442ea..4fbc40b13f19 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -733,28 +733,29 @@ int ip6_dst_lookup(struct sock *sk, struct dst_entry **dst, struct flowi *fl)
733 if (*dst) { 733 if (*dst) {
734 struct rt6_info *rt = (struct rt6_info*)*dst; 734 struct rt6_info *rt = (struct rt6_info*)*dst;
735 735
736 /* Yes, checking route validity in not connected 736 /* Yes, checking route validity in not connected
737 case is not very simple. Take into account, 737 * case is not very simple. Take into account,
738 that we do not support routing by source, TOS, 738 * that we do not support routing by source, TOS,
739 and MSG_DONTROUTE --ANK (980726) 739 * and MSG_DONTROUTE --ANK (980726)
740 740 *
741 1. If route was host route, check that 741 * 1. If route was host route, check that
742 cached destination is current. 742 * cached destination is current.
743 If it is network route, we still may 743 * If it is network route, we still may
744 check its validity using saved pointer 744 * check its validity using saved pointer
745 to the last used address: daddr_cache. 745 * to the last used address: daddr_cache.
746 We do not want to save whole address now, 746 * We do not want to save whole address now,
747 (because main consumer of this service 747 * (because main consumer of this service
748 is tcp, which has not this problem), 748 * is tcp, which has not this problem),
749 so that the last trick works only on connected 749 * so that the last trick works only on connected
750 sockets. 750 * sockets.
751 2. oif also should be the same. 751 * 2. oif also should be the same.
752 */ 752 */
753
754 if (((rt->rt6i_dst.plen != 128 || 753 if (((rt->rt6i_dst.plen != 128 ||
755 !ipv6_addr_equal(&fl->fl6_dst, &rt->rt6i_dst.addr)) 754 !ipv6_addr_equal(&fl->fl6_dst,
755 &rt->rt6i_dst.addr))
756 && (np->daddr_cache == NULL || 756 && (np->daddr_cache == NULL ||
757 !ipv6_addr_equal(&fl->fl6_dst, np->daddr_cache))) 757 !ipv6_addr_equal(&fl->fl6_dst,
758 np->daddr_cache)))
758 || (fl->oif && fl->oif != (*dst)->dev->ifindex)) { 759 || (fl->oif && fl->oif != (*dst)->dev->ifindex)) {
759 dst_release(*dst); 760 dst_release(*dst);
760 *dst = NULL; 761 *dst = NULL;
@@ -889,7 +890,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
889 np->cork.hop_limit = hlimit; 890 np->cork.hop_limit = hlimit;
890 np->cork.tclass = tclass; 891 np->cork.tclass = tclass;
891 mtu = dst_mtu(rt->u.dst.path); 892 mtu = dst_mtu(rt->u.dst.path);
892 if (np && np->frag_size < mtu) { 893 if (np->frag_size < mtu) {
893 if (np->frag_size) 894 if (np->frag_size)
894 mtu = np->frag_size; 895 mtu = np->frag_size;
895 } 896 }
diff --git a/net/ipv6/ipcomp6.c b/net/ipv6/ipcomp6.c
index d511a884dad0..028b636687ec 100644
--- a/net/ipv6/ipcomp6.c
+++ b/net/ipv6/ipcomp6.c
@@ -50,6 +50,7 @@
50#include <net/protocol.h> 50#include <net/protocol.h>
51#include <linux/ipv6.h> 51#include <linux/ipv6.h>
52#include <linux/icmpv6.h> 52#include <linux/icmpv6.h>
53#include <linux/mutex.h>
53 54
54struct ipcomp6_tfms { 55struct ipcomp6_tfms {
55 struct list_head list; 56 struct list_head list;
@@ -57,7 +58,7 @@ struct ipcomp6_tfms {
57 int users; 58 int users;
58}; 59};
59 60
60static DECLARE_MUTEX(ipcomp6_resource_sem); 61static DEFINE_MUTEX(ipcomp6_resource_mutex);
61static void **ipcomp6_scratches; 62static void **ipcomp6_scratches;
62static int ipcomp6_scratch_users; 63static int ipcomp6_scratch_users;
63static LIST_HEAD(ipcomp6_tfms_list); 64static LIST_HEAD(ipcomp6_tfms_list);
@@ -286,8 +287,8 @@ static void ipcomp6_free_scratches(void)
286 287
287 for_each_cpu(i) { 288 for_each_cpu(i) {
288 void *scratch = *per_cpu_ptr(scratches, i); 289 void *scratch = *per_cpu_ptr(scratches, i);
289 if (scratch) 290
290 vfree(scratch); 291 vfree(scratch);
291 } 292 }
292 293
293 free_percpu(scratches); 294 free_percpu(scratches);
@@ -405,9 +406,9 @@ static void ipcomp6_destroy(struct xfrm_state *x)
405 if (!ipcd) 406 if (!ipcd)
406 return; 407 return;
407 xfrm_state_delete_tunnel(x); 408 xfrm_state_delete_tunnel(x);
408 down(&ipcomp6_resource_sem); 409 mutex_lock(&ipcomp6_resource_mutex);
409 ipcomp6_free_data(ipcd); 410 ipcomp6_free_data(ipcd);
410 up(&ipcomp6_resource_sem); 411 mutex_unlock(&ipcomp6_resource_mutex);
411 kfree(ipcd); 412 kfree(ipcd);
412 413
413 xfrm6_tunnel_free_spi((xfrm_address_t *)&x->props.saddr); 414 xfrm6_tunnel_free_spi((xfrm_address_t *)&x->props.saddr);
@@ -427,23 +428,22 @@ static int ipcomp6_init_state(struct xfrm_state *x)
427 goto out; 428 goto out;
428 429
429 err = -ENOMEM; 430 err = -ENOMEM;
430 ipcd = kmalloc(sizeof(*ipcd), GFP_KERNEL); 431 ipcd = kzalloc(sizeof(*ipcd), GFP_KERNEL);
431 if (!ipcd) 432 if (!ipcd)
432 goto out; 433 goto out;
433 434
434 memset(ipcd, 0, sizeof(*ipcd));
435 x->props.header_len = 0; 435 x->props.header_len = 0;
436 if (x->props.mode) 436 if (x->props.mode)
437 x->props.header_len += sizeof(struct ipv6hdr); 437 x->props.header_len += sizeof(struct ipv6hdr);
438 438
439 down(&ipcomp6_resource_sem); 439 mutex_lock(&ipcomp6_resource_mutex);
440 if (!ipcomp6_alloc_scratches()) 440 if (!ipcomp6_alloc_scratches())
441 goto error; 441 goto error;
442 442
443 ipcd->tfms = ipcomp6_alloc_tfms(x->calg->alg_name); 443 ipcd->tfms = ipcomp6_alloc_tfms(x->calg->alg_name);
444 if (!ipcd->tfms) 444 if (!ipcd->tfms)
445 goto error; 445 goto error;
446 up(&ipcomp6_resource_sem); 446 mutex_unlock(&ipcomp6_resource_mutex);
447 447
448 if (x->props.mode) { 448 if (x->props.mode) {
449 err = ipcomp6_tunnel_attach(x); 449 err = ipcomp6_tunnel_attach(x);
@@ -459,10 +459,10 @@ static int ipcomp6_init_state(struct xfrm_state *x)
459out: 459out:
460 return err; 460 return err;
461error_tunnel: 461error_tunnel:
462 down(&ipcomp6_resource_sem); 462 mutex_lock(&ipcomp6_resource_mutex);
463error: 463error:
464 ipcomp6_free_data(ipcd); 464 ipcomp6_free_data(ipcd);
465 up(&ipcomp6_resource_sem); 465 mutex_unlock(&ipcomp6_resource_mutex);
466 kfree(ipcd); 466 kfree(ipcd);
467 467
468 goto out; 468 goto out;
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index f7142ba519ab..602feec47738 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -109,19 +109,13 @@ int ip6_ra_control(struct sock *sk, int sel, void (*destructor)(struct sock *))
109 return 0; 109 return 0;
110} 110}
111 111
112int ipv6_setsockopt(struct sock *sk, int level, int optname, 112static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
113 char __user *optval, int optlen) 113 char __user *optval, int optlen)
114{ 114{
115 struct ipv6_pinfo *np = inet6_sk(sk); 115 struct ipv6_pinfo *np = inet6_sk(sk);
116 int val, valbool; 116 int val, valbool;
117 int retv = -ENOPROTOOPT; 117 int retv = -ENOPROTOOPT;
118 118
119 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
120 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
121
122 if(level!=SOL_IPV6)
123 goto out;
124
125 if (optval == NULL) 119 if (optval == NULL)
126 val=0; 120 val=0;
127 else if (get_user(val, (int __user *) optval)) 121 else if (get_user(val, (int __user *) optval))
@@ -613,17 +607,9 @@ done:
613 retv = xfrm_user_policy(sk, optname, optval, optlen); 607 retv = xfrm_user_policy(sk, optname, optval, optlen);
614 break; 608 break;
615 609
616#ifdef CONFIG_NETFILTER
617 default:
618 retv = nf_setsockopt(sk, PF_INET6, optname, optval,
619 optlen);
620 break;
621#endif
622
623 } 610 }
624 release_sock(sk); 611 release_sock(sk);
625 612
626out:
627 return retv; 613 return retv;
628 614
629e_inval: 615e_inval:
@@ -631,6 +617,65 @@ e_inval:
631 return -EINVAL; 617 return -EINVAL;
632} 618}
633 619
620int ipv6_setsockopt(struct sock *sk, int level, int optname,
621 char __user *optval, int optlen)
622{
623 int err;
624
625 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
626 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
627
628 if (level != SOL_IPV6)
629 return -ENOPROTOOPT;
630
631 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
632#ifdef CONFIG_NETFILTER
633 /* we need to exclude all possible ENOPROTOOPTs except default case */
634 if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
635 optname != IPV6_XFRM_POLICY) {
636 lock_sock(sk);
637 err = nf_setsockopt(sk, PF_INET6, optname, optval,
638 optlen);
639 release_sock(sk);
640 }
641#endif
642 return err;
643}
644
645
646#ifdef CONFIG_COMPAT
647int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,
648 char __user *optval, int optlen)
649{
650 int err;
651
652 if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
653 if (udp_prot.compat_setsockopt != NULL)
654 return udp_prot.compat_setsockopt(sk, level, optname,
655 optval, optlen);
656 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
657 }
658
659 if (level != SOL_IPV6)
660 return -ENOPROTOOPT;
661
662 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
663#ifdef CONFIG_NETFILTER
664 /* we need to exclude all possible ENOPROTOOPTs except default case */
665 if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
666 optname != IPV6_XFRM_POLICY) {
667 lock_sock(sk);
668 err = compat_nf_setsockopt(sk, PF_INET6, optname,
669 optval, optlen);
670 release_sock(sk);
671 }
672#endif
673 return err;
674}
675
676EXPORT_SYMBOL(compat_ipv6_setsockopt);
677#endif
678
634static int ipv6_getsockopt_sticky(struct sock *sk, struct ipv6_opt_hdr *hdr, 679static int ipv6_getsockopt_sticky(struct sock *sk, struct ipv6_opt_hdr *hdr,
635 char __user *optval, int len) 680 char __user *optval, int len)
636{ 681{
@@ -642,17 +687,13 @@ static int ipv6_getsockopt_sticky(struct sock *sk, struct ipv6_opt_hdr *hdr,
642 return len; 687 return len;
643} 688}
644 689
645int ipv6_getsockopt(struct sock *sk, int level, int optname, 690static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
646 char __user *optval, int __user *optlen) 691 char __user *optval, int __user *optlen)
647{ 692{
648 struct ipv6_pinfo *np = inet6_sk(sk); 693 struct ipv6_pinfo *np = inet6_sk(sk);
649 int len; 694 int len;
650 int val; 695 int val;
651 696
652 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
653 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
654 if(level!=SOL_IPV6)
655 return -ENOPROTOOPT;
656 if (get_user(len, optlen)) 697 if (get_user(len, optlen))
657 return -EFAULT; 698 return -EFAULT;
658 switch (optname) { 699 switch (optname) {
@@ -842,17 +883,7 @@ int ipv6_getsockopt(struct sock *sk, int level, int optname,
842 break; 883 break;
843 884
844 default: 885 default:
845#ifdef CONFIG_NETFILTER
846 lock_sock(sk);
847 val = nf_getsockopt(sk, PF_INET6, optname, optval,
848 &len);
849 release_sock(sk);
850 if (val >= 0)
851 val = put_user(len, optlen);
852 return val;
853#else
854 return -EINVAL; 886 return -EINVAL;
855#endif
856 } 887 }
857 len = min_t(unsigned int, sizeof(int), len); 888 len = min_t(unsigned int, sizeof(int), len);
858 if(put_user(len, optlen)) 889 if(put_user(len, optlen))
@@ -862,6 +893,78 @@ int ipv6_getsockopt(struct sock *sk, int level, int optname,
862 return 0; 893 return 0;
863} 894}
864 895
896int ipv6_getsockopt(struct sock *sk, int level, int optname,
897 char __user *optval, int __user *optlen)
898{
899 int err;
900
901 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
902 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
903
904 if(level != SOL_IPV6)
905 return -ENOPROTOOPT;
906
907 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
908#ifdef CONFIG_NETFILTER
909 /* we need to exclude all possible EINVALs except default case */
910 if (err == -ENOPROTOOPT && optname != IPV6_ADDRFORM &&
911 optname != MCAST_MSFILTER) {
912 int len;
913
914 if (get_user(len, optlen))
915 return -EFAULT;
916
917 lock_sock(sk);
918 err = nf_getsockopt(sk, PF_INET6, optname, optval,
919 &len);
920 release_sock(sk);
921 if (err >= 0)
922 err = put_user(len, optlen);
923 }
924#endif
925 return err;
926}
927
928#ifdef CONFIG_COMPAT
929int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
930 char __user *optval, int __user *optlen)
931{
932 int err;
933
934 if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
935 if (udp_prot.compat_getsockopt != NULL)
936 return udp_prot.compat_getsockopt(sk, level, optname,
937 optval, optlen);
938 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
939 }
940
941 if (level != SOL_IPV6)
942 return -ENOPROTOOPT;
943
944 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
945#ifdef CONFIG_NETFILTER
946 /* we need to exclude all possible EINVALs except default case */
947 if (err == -ENOPROTOOPT && optname != IPV6_ADDRFORM &&
948 optname != MCAST_MSFILTER) {
949 int len;
950
951 if (get_user(len, optlen))
952 return -EFAULT;
953
954 lock_sock(sk);
955 err = compat_nf_getsockopt(sk, PF_INET6,
956 optname, optval, &len);
957 release_sock(sk);
958 if (err >= 0)
959 err = put_user(len, optlen);
960 }
961#endif
962 return err;
963}
964
965EXPORT_SYMBOL(compat_ipv6_getsockopt);
966#endif
967
865void __init ipv6_packet_init(void) 968void __init ipv6_packet_init(void)
866{ 969{
867 dev_add_pack(&ipv6_packet_type); 970 dev_add_pack(&ipv6_packet_type);
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index 807c021d64a2..6e871afbb2c7 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -767,10 +767,10 @@ static void mld_add_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im)
767 * for deleted items allows change reports to use common code with 767 * for deleted items allows change reports to use common code with
768 * non-deleted or query-response MCA's. 768 * non-deleted or query-response MCA's.
769 */ 769 */
770 pmc = kmalloc(sizeof(*pmc), GFP_ATOMIC); 770 pmc = kzalloc(sizeof(*pmc), GFP_ATOMIC);
771 if (!pmc) 771 if (!pmc)
772 return; 772 return;
773 memset(pmc, 0, sizeof(*pmc)); 773
774 spin_lock_bh(&im->mca_lock); 774 spin_lock_bh(&im->mca_lock);
775 spin_lock_init(&pmc->mca_lock); 775 spin_lock_init(&pmc->mca_lock);
776 pmc->idev = im->idev; 776 pmc->idev = im->idev;
@@ -893,7 +893,7 @@ int ipv6_dev_mc_inc(struct net_device *dev, struct in6_addr *addr)
893 * not found: create a new one. 893 * not found: create a new one.
894 */ 894 */
895 895
896 mc = kmalloc(sizeof(struct ifmcaddr6), GFP_ATOMIC); 896 mc = kzalloc(sizeof(struct ifmcaddr6), GFP_ATOMIC);
897 897
898 if (mc == NULL) { 898 if (mc == NULL) {
899 write_unlock_bh(&idev->lock); 899 write_unlock_bh(&idev->lock);
@@ -901,7 +901,6 @@ int ipv6_dev_mc_inc(struct net_device *dev, struct in6_addr *addr)
901 return -ENOMEM; 901 return -ENOMEM;
902 } 902 }
903 903
904 memset(mc, 0, sizeof(struct ifmcaddr6));
905 init_timer(&mc->mca_timer); 904 init_timer(&mc->mca_timer);
906 mc->mca_timer.function = igmp6_timer_handler; 905 mc->mca_timer.function = igmp6_timer_handler;
907 mc->mca_timer.data = (unsigned long) mc; 906 mc->mca_timer.data = (unsigned long) mc;
@@ -1934,10 +1933,10 @@ static int ip6_mc_add1_src(struct ifmcaddr6 *pmc, int sfmode,
1934 psf_prev = psf; 1933 psf_prev = psf;
1935 } 1934 }
1936 if (!psf) { 1935 if (!psf) {
1937 psf = kmalloc(sizeof(*psf), GFP_ATOMIC); 1936 psf = kzalloc(sizeof(*psf), GFP_ATOMIC);
1938 if (!psf) 1937 if (!psf)
1939 return -ENOBUFS; 1938 return -ENOBUFS;
1940 memset(psf, 0, sizeof(*psf)); 1939
1941 psf->sf_addr = *psfsrc; 1940 psf->sf_addr = *psfsrc;
1942 if (psf_prev) { 1941 if (psf_prev) {
1943 psf_prev->sf_next = psf; 1942 psf_prev->sf_next = psf;
@@ -2431,7 +2430,7 @@ static int igmp6_mc_seq_open(struct inode *inode, struct file *file)
2431{ 2430{
2432 struct seq_file *seq; 2431 struct seq_file *seq;
2433 int rc = -ENOMEM; 2432 int rc = -ENOMEM;
2434 struct igmp6_mc_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL); 2433 struct igmp6_mc_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
2435 2434
2436 if (!s) 2435 if (!s)
2437 goto out; 2436 goto out;
@@ -2442,7 +2441,6 @@ static int igmp6_mc_seq_open(struct inode *inode, struct file *file)
2442 2441
2443 seq = file->private_data; 2442 seq = file->private_data;
2444 seq->private = s; 2443 seq->private = s;
2445 memset(s, 0, sizeof(*s));
2446out: 2444out:
2447 return rc; 2445 return rc;
2448out_kfree: 2446out_kfree:
@@ -2606,7 +2604,7 @@ static int igmp6_mcf_seq_open(struct inode *inode, struct file *file)
2606{ 2604{
2607 struct seq_file *seq; 2605 struct seq_file *seq;
2608 int rc = -ENOMEM; 2606 int rc = -ENOMEM;
2609 struct igmp6_mcf_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL); 2607 struct igmp6_mcf_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
2610 2608
2611 if (!s) 2609 if (!s)
2612 goto out; 2610 goto out;
@@ -2617,7 +2615,6 @@ static int igmp6_mcf_seq_open(struct inode *inode, struct file *file)
2617 2615
2618 seq = file->private_data; 2616 seq = file->private_data;
2619 seq->private = s; 2617 seq->private = s;
2620 memset(s, 0, sizeof(*s));
2621out: 2618out:
2622 return rc; 2619 return rc;
2623out_kfree: 2620out_kfree:
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index cb8856b1d951..dfa20d3be9b6 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -156,7 +156,11 @@ struct neigh_table nd_tbl = {
156 156
157/* ND options */ 157/* ND options */
158struct ndisc_options { 158struct ndisc_options {
159 struct nd_opt_hdr *nd_opt_array[__ND_OPT_MAX]; 159 struct nd_opt_hdr *nd_opt_array[__ND_OPT_ARRAY_MAX];
160#ifdef CONFIG_IPV6_ROUTE_INFO
161 struct nd_opt_hdr *nd_opts_ri;
162 struct nd_opt_hdr *nd_opts_ri_end;
163#endif
160}; 164};
161 165
162#define nd_opts_src_lladdr nd_opt_array[ND_OPT_SOURCE_LL_ADDR] 166#define nd_opts_src_lladdr nd_opt_array[ND_OPT_SOURCE_LL_ADDR]
@@ -255,6 +259,13 @@ static struct ndisc_options *ndisc_parse_options(u8 *opt, int opt_len,
255 if (ndopts->nd_opt_array[nd_opt->nd_opt_type] == 0) 259 if (ndopts->nd_opt_array[nd_opt->nd_opt_type] == 0)
256 ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt; 260 ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt;
257 break; 261 break;
262#ifdef CONFIG_IPV6_ROUTE_INFO
263 case ND_OPT_ROUTE_INFO:
264 ndopts->nd_opts_ri_end = nd_opt;
265 if (!ndopts->nd_opts_ri)
266 ndopts->nd_opts_ri = nd_opt;
267 break;
268#endif
258 default: 269 default:
259 /* 270 /*
260 * Unknown options must be silently ignored, 271 * Unknown options must be silently ignored,
@@ -1019,10 +1030,11 @@ static void ndisc_router_discovery(struct sk_buff *skb)
1019 struct ra_msg *ra_msg = (struct ra_msg *) skb->h.raw; 1030 struct ra_msg *ra_msg = (struct ra_msg *) skb->h.raw;
1020 struct neighbour *neigh = NULL; 1031 struct neighbour *neigh = NULL;
1021 struct inet6_dev *in6_dev; 1032 struct inet6_dev *in6_dev;
1022 struct rt6_info *rt; 1033 struct rt6_info *rt = NULL;
1023 int lifetime; 1034 int lifetime;
1024 struct ndisc_options ndopts; 1035 struct ndisc_options ndopts;
1025 int optlen; 1036 int optlen;
1037 unsigned int pref = 0;
1026 1038
1027 __u8 * opt = (__u8 *)(ra_msg + 1); 1039 __u8 * opt = (__u8 *)(ra_msg + 1);
1028 1040
@@ -1081,8 +1093,19 @@ static void ndisc_router_discovery(struct sk_buff *skb)
1081 (ra_msg->icmph.icmp6_addrconf_other ? 1093 (ra_msg->icmph.icmp6_addrconf_other ?
1082 IF_RA_OTHERCONF : 0); 1094 IF_RA_OTHERCONF : 0);
1083 1095
1096 if (!in6_dev->cnf.accept_ra_defrtr)
1097 goto skip_defrtr;
1098
1084 lifetime = ntohs(ra_msg->icmph.icmp6_rt_lifetime); 1099 lifetime = ntohs(ra_msg->icmph.icmp6_rt_lifetime);
1085 1100
1101#ifdef CONFIG_IPV6_ROUTER_PREF
1102 pref = ra_msg->icmph.icmp6_router_pref;
1103 /* 10b is handled as if it were 00b (medium) */
1104 if (pref == ICMPV6_ROUTER_PREF_INVALID ||
1105 in6_dev->cnf.accept_ra_rtr_pref)
1106 pref = ICMPV6_ROUTER_PREF_MEDIUM;
1107#endif
1108
1086 rt = rt6_get_dflt_router(&skb->nh.ipv6h->saddr, skb->dev); 1109 rt = rt6_get_dflt_router(&skb->nh.ipv6h->saddr, skb->dev);
1087 1110
1088 if (rt) 1111 if (rt)
@@ -1098,7 +1121,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
1098 ND_PRINTK3(KERN_DEBUG 1121 ND_PRINTK3(KERN_DEBUG
1099 "ICMPv6 RA: adding default router.\n"); 1122 "ICMPv6 RA: adding default router.\n");
1100 1123
1101 rt = rt6_add_dflt_router(&skb->nh.ipv6h->saddr, skb->dev); 1124 rt = rt6_add_dflt_router(&skb->nh.ipv6h->saddr, skb->dev, pref);
1102 if (rt == NULL) { 1125 if (rt == NULL) {
1103 ND_PRINTK0(KERN_ERR 1126 ND_PRINTK0(KERN_ERR
1104 "ICMPv6 RA: %s() failed to add default route.\n", 1127 "ICMPv6 RA: %s() failed to add default route.\n",
@@ -1117,6 +1140,8 @@ static void ndisc_router_discovery(struct sk_buff *skb)
1117 return; 1140 return;
1118 } 1141 }
1119 neigh->flags |= NTF_ROUTER; 1142 neigh->flags |= NTF_ROUTER;
1143 } else if (rt) {
1144 rt->rt6i_flags |= (rt->rt6i_flags & ~RTF_PREF_MASK) | RTF_PREF(pref);
1120 } 1145 }
1121 1146
1122 if (rt) 1147 if (rt)
@@ -1128,6 +1153,8 @@ static void ndisc_router_discovery(struct sk_buff *skb)
1128 rt->u.dst.metrics[RTAX_HOPLIMIT-1] = ra_msg->icmph.icmp6_hop_limit; 1153 rt->u.dst.metrics[RTAX_HOPLIMIT-1] = ra_msg->icmph.icmp6_hop_limit;
1129 } 1154 }
1130 1155
1156skip_defrtr:
1157
1131 /* 1158 /*
1132 * Update Reachable Time and Retrans Timer 1159 * Update Reachable Time and Retrans Timer
1133 */ 1160 */
@@ -1186,7 +1213,21 @@ static void ndisc_router_discovery(struct sk_buff *skb)
1186 NEIGH_UPDATE_F_ISROUTER); 1213 NEIGH_UPDATE_F_ISROUTER);
1187 } 1214 }
1188 1215
1189 if (ndopts.nd_opts_pi) { 1216#ifdef CONFIG_IPV6_ROUTE_INFO
1217 if (in6_dev->cnf.accept_ra_rtr_pref && ndopts.nd_opts_ri) {
1218 struct nd_opt_hdr *p;
1219 for (p = ndopts.nd_opts_ri;
1220 p;
1221 p = ndisc_next_option(p, ndopts.nd_opts_ri_end)) {
1222 if (((struct route_info *)p)->prefix_len > in6_dev->cnf.accept_ra_rt_info_max_plen)
1223 continue;
1224 rt6_route_rcv(skb->dev, (u8*)p, (p->nd_opt_len) << 3,
1225 &skb->nh.ipv6h->saddr);
1226 }
1227 }
1228#endif
1229
1230 if (in6_dev->cnf.accept_ra_pinfo && ndopts.nd_opts_pi) {
1190 struct nd_opt_hdr *p; 1231 struct nd_opt_hdr *p;
1191 for (p = ndopts.nd_opts_pi; 1232 for (p = ndopts.nd_opts_pi;
1192 p; 1233 p;
diff --git a/net/ipv6/netfilter/Kconfig b/net/ipv6/netfilter/Kconfig
index 2d6f8ecbc27b..98f78759f1ab 100644
--- a/net/ipv6/netfilter/Kconfig
+++ b/net/ipv6/netfilter/Kconfig
@@ -133,16 +133,6 @@ config IP6_NF_MATCH_EUI64
133 133
134 To compile it as a module, choose M here. If unsure, say N. 134 To compile it as a module, choose M here. If unsure, say N.
135 135
136config IP6_NF_MATCH_POLICY
137 tristate "IPsec policy match support"
138 depends on IP6_NF_IPTABLES && XFRM
139 help
140 Policy matching allows you to match packets based on the
141 IPsec policy that was used during decapsulation/will
142 be used during encapsulation.
143
144 To compile it as a module, choose M here. If unsure, say N.
145
146# The targets 136# The targets
147config IP6_NF_FILTER 137config IP6_NF_FILTER
148 tristate "Packet filtering" 138 tristate "Packet filtering"
diff --git a/net/ipv6/netfilter/Makefile b/net/ipv6/netfilter/Makefile
index db6073c94163..8436a1a1731f 100644
--- a/net/ipv6/netfilter/Makefile
+++ b/net/ipv6/netfilter/Makefile
@@ -9,7 +9,6 @@ obj-$(CONFIG_IP6_NF_MATCH_OPTS) += ip6t_hbh.o ip6t_dst.o
9obj-$(CONFIG_IP6_NF_MATCH_IPV6HEADER) += ip6t_ipv6header.o 9obj-$(CONFIG_IP6_NF_MATCH_IPV6HEADER) += ip6t_ipv6header.o
10obj-$(CONFIG_IP6_NF_MATCH_FRAG) += ip6t_frag.o 10obj-$(CONFIG_IP6_NF_MATCH_FRAG) += ip6t_frag.o
11obj-$(CONFIG_IP6_NF_MATCH_AHESP) += ip6t_esp.o ip6t_ah.o 11obj-$(CONFIG_IP6_NF_MATCH_AHESP) += ip6t_esp.o ip6t_ah.o
12obj-$(CONFIG_IP6_NF_MATCH_POLICY) += ip6t_policy.o
13obj-$(CONFIG_IP6_NF_MATCH_EUI64) += ip6t_eui64.o 12obj-$(CONFIG_IP6_NF_MATCH_EUI64) += ip6t_eui64.o
14obj-$(CONFIG_IP6_NF_MATCH_MULTIPORT) += ip6t_multiport.o 13obj-$(CONFIG_IP6_NF_MATCH_MULTIPORT) += ip6t_multiport.o
15obj-$(CONFIG_IP6_NF_MATCH_OWNER) += ip6t_owner.o 14obj-$(CONFIG_IP6_NF_MATCH_OWNER) += ip6t_owner.o
diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c
index af0635084df8..344eab3b5da8 100644
--- a/net/ipv6/netfilter/ip6_queue.c
+++ b/net/ipv6/netfilter/ip6_queue.c
@@ -35,6 +35,7 @@
35#include <linux/spinlock.h> 35#include <linux/spinlock.h>
36#include <linux/sysctl.h> 36#include <linux/sysctl.h>
37#include <linux/proc_fs.h> 37#include <linux/proc_fs.h>
38#include <linux/mutex.h>
38#include <net/sock.h> 39#include <net/sock.h>
39#include <net/ipv6.h> 40#include <net/ipv6.h>
40#include <net/ip6_route.h> 41#include <net/ip6_route.h>
@@ -65,7 +66,7 @@ static unsigned int queue_dropped = 0;
65static unsigned int queue_user_dropped = 0; 66static unsigned int queue_user_dropped = 0;
66static struct sock *ipqnl; 67static struct sock *ipqnl;
67static LIST_HEAD(queue_list); 68static LIST_HEAD(queue_list);
68static DECLARE_MUTEX(ipqnl_sem); 69static DEFINE_MUTEX(ipqnl_mutex);
69 70
70static void 71static void
71ipq_issue_verdict(struct ipq_queue_entry *entry, int verdict) 72ipq_issue_verdict(struct ipq_queue_entry *entry, int verdict)
@@ -537,7 +538,7 @@ ipq_rcv_sk(struct sock *sk, int len)
537 struct sk_buff *skb; 538 struct sk_buff *skb;
538 unsigned int qlen; 539 unsigned int qlen;
539 540
540 down(&ipqnl_sem); 541 mutex_lock(&ipqnl_mutex);
541 542
542 for (qlen = skb_queue_len(&sk->sk_receive_queue); qlen; qlen--) { 543 for (qlen = skb_queue_len(&sk->sk_receive_queue); qlen; qlen--) {
543 skb = skb_dequeue(&sk->sk_receive_queue); 544 skb = skb_dequeue(&sk->sk_receive_queue);
@@ -545,7 +546,7 @@ ipq_rcv_sk(struct sock *sk, int len)
545 kfree_skb(skb); 546 kfree_skb(skb);
546 } 547 }
547 548
548 up(&ipqnl_sem); 549 mutex_unlock(&ipqnl_mutex);
549} 550}
550 551
551static int 552static int
@@ -704,8 +705,8 @@ cleanup_sysctl:
704 705
705cleanup_ipqnl: 706cleanup_ipqnl:
706 sock_release(ipqnl->sk_socket); 707 sock_release(ipqnl->sk_socket);
707 down(&ipqnl_sem); 708 mutex_lock(&ipqnl_mutex);
708 up(&ipqnl_sem); 709 mutex_unlock(&ipqnl_mutex);
709 710
710cleanup_netlink_notifier: 711cleanup_netlink_notifier:
711 netlink_unregister_notifier(&ipq_nl_notifier); 712 netlink_unregister_notifier(&ipq_nl_notifier);
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index 74ff56c322f4..5a2063bda676 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -29,7 +29,7 @@
29#include <linux/icmpv6.h> 29#include <linux/icmpv6.h>
30#include <net/ipv6.h> 30#include <net/ipv6.h>
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32#include <asm/semaphore.h> 32#include <linux/mutex.h>
33#include <linux/proc_fs.h> 33#include <linux/proc_fs.h>
34#include <linux/cpumask.h> 34#include <linux/cpumask.h>
35 35
@@ -94,19 +94,6 @@ do { \
94#define up(x) do { printk("UP:%u:" #x "\n", __LINE__); up(x); } while(0) 94#define up(x) do { printk("UP:%u:" #x "\n", __LINE__); up(x); } while(0)
95#endif 95#endif
96 96
97int
98ip6_masked_addrcmp(const struct in6_addr *addr1, const struct in6_addr *mask,
99 const struct in6_addr *addr2)
100{
101 int i;
102 for( i = 0; i < 16; i++){
103 if((addr1->s6_addr[i] & mask->s6_addr[i]) !=
104 (addr2->s6_addr[i] & mask->s6_addr[i]))
105 return 1;
106 }
107 return 0;
108}
109
110/* Check for an extension */ 97/* Check for an extension */
111int 98int
112ip6t_ext_hdr(u8 nexthdr) 99ip6t_ext_hdr(u8 nexthdr)
@@ -135,10 +122,10 @@ ip6_packet_match(const struct sk_buff *skb,
135 122
136#define FWINV(bool,invflg) ((bool) ^ !!(ip6info->invflags & invflg)) 123#define FWINV(bool,invflg) ((bool) ^ !!(ip6info->invflags & invflg))
137 124
138 if (FWINV(ip6_masked_addrcmp(&ipv6->saddr, &ip6info->smsk, 125 if (FWINV(ipv6_masked_addr_cmp(&ipv6->saddr, &ip6info->smsk,
139 &ip6info->src), IP6T_INV_SRCIP) 126 &ip6info->src), IP6T_INV_SRCIP)
140 || FWINV(ip6_masked_addrcmp(&ipv6->daddr, &ip6info->dmsk, 127 || FWINV(ipv6_masked_addr_cmp(&ipv6->daddr, &ip6info->dmsk,
141 &ip6info->dst), IP6T_INV_DSTIP)) { 128 &ip6info->dst), IP6T_INV_DSTIP)) {
142 dprintf("Source or dest mismatch.\n"); 129 dprintf("Source or dest mismatch.\n");
143/* 130/*
144 dprintf("SRC: %u. Mask: %u. Target: %u.%s\n", ip->saddr, 131 dprintf("SRC: %u. Mask: %u. Target: %u.%s\n", ip->saddr,
@@ -232,6 +219,7 @@ ip6t_error(struct sk_buff **pskb,
232 const struct net_device *in, 219 const struct net_device *in,
233 const struct net_device *out, 220 const struct net_device *out,
234 unsigned int hooknum, 221 unsigned int hooknum,
222 const struct xt_target *target,
235 const void *targinfo, 223 const void *targinfo,
236 void *userinfo) 224 void *userinfo)
237{ 225{
@@ -251,7 +239,7 @@ int do_match(struct ip6t_entry_match *m,
251 int *hotdrop) 239 int *hotdrop)
252{ 240{
253 /* Stop iteration if it doesn't match */ 241 /* Stop iteration if it doesn't match */
254 if (!m->u.kernel.match->match(skb, in, out, m->data, 242 if (!m->u.kernel.match->match(skb, in, out, m->u.kernel.match, m->data,
255 offset, protoff, hotdrop)) 243 offset, protoff, hotdrop))
256 return 1; 244 return 1;
257 else 245 else
@@ -373,6 +361,7 @@ ip6t_do_table(struct sk_buff **pskb,
373 verdict = t->u.kernel.target->target(pskb, 361 verdict = t->u.kernel.target->target(pskb,
374 in, out, 362 in, out,
375 hook, 363 hook,
364 t->u.kernel.target,
376 t->data, 365 t->data,
377 userdata); 366 userdata);
378 367
@@ -531,7 +520,7 @@ cleanup_match(struct ip6t_entry_match *m, unsigned int *i)
531 return 1; 520 return 1;
532 521
533 if (m->u.kernel.match->destroy) 522 if (m->u.kernel.match->destroy)
534 m->u.kernel.match->destroy(m->data, 523 m->u.kernel.match->destroy(m->u.kernel.match, m->data,
535 m->u.match_size - sizeof(*m)); 524 m->u.match_size - sizeof(*m));
536 module_put(m->u.kernel.match->me); 525 module_put(m->u.kernel.match->me);
537 return 0; 526 return 0;
@@ -544,21 +533,12 @@ standard_check(const struct ip6t_entry_target *t,
544 struct ip6t_standard_target *targ = (void *)t; 533 struct ip6t_standard_target *targ = (void *)t;
545 534
546 /* Check standard info. */ 535 /* Check standard info. */
547 if (t->u.target_size
548 != IP6T_ALIGN(sizeof(struct ip6t_standard_target))) {
549 duprintf("standard_check: target size %u != %u\n",
550 t->u.target_size,
551 IP6T_ALIGN(sizeof(struct ip6t_standard_target)));
552 return 0;
553 }
554
555 if (targ->verdict >= 0 536 if (targ->verdict >= 0
556 && targ->verdict > max_offset - sizeof(struct ip6t_entry)) { 537 && targ->verdict > max_offset - sizeof(struct ip6t_entry)) {
557 duprintf("ip6t_standard_check: bad verdict (%i)\n", 538 duprintf("ip6t_standard_check: bad verdict (%i)\n",
558 targ->verdict); 539 targ->verdict);
559 return 0; 540 return 0;
560 } 541 }
561
562 if (targ->verdict < -NF_MAX_VERDICT - 1) { 542 if (targ->verdict < -NF_MAX_VERDICT - 1) {
563 duprintf("ip6t_standard_check: bad negative verdict (%i)\n", 543 duprintf("ip6t_standard_check: bad negative verdict (%i)\n",
564 targ->verdict); 544 targ->verdict);
@@ -575,6 +555,7 @@ check_match(struct ip6t_entry_match *m,
575 unsigned int *i) 555 unsigned int *i)
576{ 556{
577 struct ip6t_match *match; 557 struct ip6t_match *match;
558 int ret;
578 559
579 match = try_then_request_module(xt_find_match(AF_INET6, m->u.user.name, 560 match = try_then_request_module(xt_find_match(AF_INET6, m->u.user.name,
580 m->u.user.revision), 561 m->u.user.revision),
@@ -585,18 +566,27 @@ check_match(struct ip6t_entry_match *m,
585 } 566 }
586 m->u.kernel.match = match; 567 m->u.kernel.match = match;
587 568
569 ret = xt_check_match(match, AF_INET6, m->u.match_size - sizeof(*m),
570 name, hookmask, ipv6->proto,
571 ipv6->invflags & IP6T_INV_PROTO);
572 if (ret)
573 goto err;
574
588 if (m->u.kernel.match->checkentry 575 if (m->u.kernel.match->checkentry
589 && !m->u.kernel.match->checkentry(name, ipv6, m->data, 576 && !m->u.kernel.match->checkentry(name, ipv6, match, m->data,
590 m->u.match_size - sizeof(*m), 577 m->u.match_size - sizeof(*m),
591 hookmask)) { 578 hookmask)) {
592 module_put(m->u.kernel.match->me);
593 duprintf("ip_tables: check failed for `%s'.\n", 579 duprintf("ip_tables: check failed for `%s'.\n",
594 m->u.kernel.match->name); 580 m->u.kernel.match->name);
595 return -EINVAL; 581 ret = -EINVAL;
582 goto err;
596 } 583 }
597 584
598 (*i)++; 585 (*i)++;
599 return 0; 586 return 0;
587err:
588 module_put(m->u.kernel.match->me);
589 return ret;
600} 590}
601 591
602static struct ip6t_target ip6t_standard_target; 592static struct ip6t_target ip6t_standard_target;
@@ -632,26 +622,32 @@ check_entry(struct ip6t_entry *e, const char *name, unsigned int size,
632 } 622 }
633 t->u.kernel.target = target; 623 t->u.kernel.target = target;
634 624
625 ret = xt_check_target(target, AF_INET6, t->u.target_size - sizeof(*t),
626 name, e->comefrom, e->ipv6.proto,
627 e->ipv6.invflags & IP6T_INV_PROTO);
628 if (ret)
629 goto err;
630
635 if (t->u.kernel.target == &ip6t_standard_target) { 631 if (t->u.kernel.target == &ip6t_standard_target) {
636 if (!standard_check(t, size)) { 632 if (!standard_check(t, size)) {
637 ret = -EINVAL; 633 ret = -EINVAL;
638 goto cleanup_matches; 634 goto cleanup_matches;
639 } 635 }
640 } else if (t->u.kernel.target->checkentry 636 } else if (t->u.kernel.target->checkentry
641 && !t->u.kernel.target->checkentry(name, e, t->data, 637 && !t->u.kernel.target->checkentry(name, e, target, t->data,
642 t->u.target_size 638 t->u.target_size
643 - sizeof(*t), 639 - sizeof(*t),
644 e->comefrom)) { 640 e->comefrom)) {
645 module_put(t->u.kernel.target->me);
646 duprintf("ip_tables: check failed for `%s'.\n", 641 duprintf("ip_tables: check failed for `%s'.\n",
647 t->u.kernel.target->name); 642 t->u.kernel.target->name);
648 ret = -EINVAL; 643 ret = -EINVAL;
649 goto cleanup_matches; 644 goto err;
650 } 645 }
651 646
652 (*i)++; 647 (*i)++;
653 return 0; 648 return 0;
654 649 err:
650 module_put(t->u.kernel.target->me);
655 cleanup_matches: 651 cleanup_matches:
656 IP6T_MATCH_ITERATE(e, cleanup_match, &j); 652 IP6T_MATCH_ITERATE(e, cleanup_match, &j);
657 return ret; 653 return ret;
@@ -712,7 +708,7 @@ cleanup_entry(struct ip6t_entry *e, unsigned int *i)
712 IP6T_MATCH_ITERATE(e, cleanup_match, NULL); 708 IP6T_MATCH_ITERATE(e, cleanup_match, NULL);
713 t = ip6t_get_target(e); 709 t = ip6t_get_target(e);
714 if (t->u.kernel.target->destroy) 710 if (t->u.kernel.target->destroy)
715 t->u.kernel.target->destroy(t->data, 711 t->u.kernel.target->destroy(t->u.kernel.target, t->data,
716 t->u.target_size - sizeof(*t)); 712 t->u.target_size - sizeof(*t));
717 module_put(t->u.kernel.target->me); 713 module_put(t->u.kernel.target->me);
718 return 0; 714 return 0;
@@ -1333,6 +1329,7 @@ static int
1333icmp6_match(const struct sk_buff *skb, 1329icmp6_match(const struct sk_buff *skb,
1334 const struct net_device *in, 1330 const struct net_device *in,
1335 const struct net_device *out, 1331 const struct net_device *out,
1332 const struct xt_match *match,
1336 const void *matchinfo, 1333 const void *matchinfo,
1337 int offset, 1334 int offset,
1338 unsigned int protoff, 1335 unsigned int protoff,
@@ -1365,28 +1362,27 @@ icmp6_match(const struct sk_buff *skb,
1365static int 1362static int
1366icmp6_checkentry(const char *tablename, 1363icmp6_checkentry(const char *tablename,
1367 const void *entry, 1364 const void *entry,
1365 const struct xt_match *match,
1368 void *matchinfo, 1366 void *matchinfo,
1369 unsigned int matchsize, 1367 unsigned int matchsize,
1370 unsigned int hook_mask) 1368 unsigned int hook_mask)
1371{ 1369{
1372 const struct ip6t_ip6 *ipv6 = entry;
1373 const struct ip6t_icmp *icmpinfo = matchinfo; 1370 const struct ip6t_icmp *icmpinfo = matchinfo;
1374 1371
1375 /* Must specify proto == ICMP, and no unknown invflags */ 1372 /* Must specify no unknown invflags */
1376 return ipv6->proto == IPPROTO_ICMPV6 1373 return !(icmpinfo->invflags & ~IP6T_ICMP_INV);
1377 && !(ipv6->invflags & IP6T_INV_PROTO)
1378 && matchsize == IP6T_ALIGN(sizeof(struct ip6t_icmp))
1379 && !(icmpinfo->invflags & ~IP6T_ICMP_INV);
1380} 1374}
1381 1375
1382/* The built-in targets: standard (NULL) and error. */ 1376/* The built-in targets: standard (NULL) and error. */
1383static struct ip6t_target ip6t_standard_target = { 1377static struct ip6t_target ip6t_standard_target = {
1384 .name = IP6T_STANDARD_TARGET, 1378 .name = IP6T_STANDARD_TARGET,
1379 .targetsize = sizeof(int),
1385}; 1380};
1386 1381
1387static struct ip6t_target ip6t_error_target = { 1382static struct ip6t_target ip6t_error_target = {
1388 .name = IP6T_ERROR_TARGET, 1383 .name = IP6T_ERROR_TARGET,
1389 .target = ip6t_error, 1384 .target = ip6t_error,
1385 .targetsize = IP6T_FUNCTION_MAXNAMELEN,
1390}; 1386};
1391 1387
1392static struct nf_sockopt_ops ip6t_sockopts = { 1388static struct nf_sockopt_ops ip6t_sockopts = {
@@ -1402,7 +1398,9 @@ static struct nf_sockopt_ops ip6t_sockopts = {
1402static struct ip6t_match icmp6_matchstruct = { 1398static struct ip6t_match icmp6_matchstruct = {
1403 .name = "icmp6", 1399 .name = "icmp6",
1404 .match = &icmp6_match, 1400 .match = &icmp6_match,
1405 .checkentry = &icmp6_checkentry, 1401 .matchsize = sizeof(struct ip6t_icmp),
1402 .checkentry = icmp6_checkentry,
1403 .proto = IPPROTO_ICMPV6,
1406}; 1404};
1407 1405
1408static int __init init(void) 1406static int __init init(void)
@@ -1515,7 +1513,6 @@ EXPORT_SYMBOL(ip6t_unregister_table);
1515EXPORT_SYMBOL(ip6t_do_table); 1513EXPORT_SYMBOL(ip6t_do_table);
1516EXPORT_SYMBOL(ip6t_ext_hdr); 1514EXPORT_SYMBOL(ip6t_ext_hdr);
1517EXPORT_SYMBOL(ipv6_find_hdr); 1515EXPORT_SYMBOL(ipv6_find_hdr);
1518EXPORT_SYMBOL(ip6_masked_addrcmp);
1519 1516
1520module_init(init); 1517module_init(init);
1521module_exit(fini); 1518module_exit(fini);
diff --git a/net/ipv6/netfilter/ip6t_HL.c b/net/ipv6/netfilter/ip6t_HL.c
index 306200c35057..da14c6d86bcc 100644
--- a/net/ipv6/netfilter/ip6t_HL.c
+++ b/net/ipv6/netfilter/ip6t_HL.c
@@ -21,6 +21,7 @@ static unsigned int ip6t_hl_target(struct sk_buff **pskb,
21 const struct net_device *in, 21 const struct net_device *in,
22 const struct net_device *out, 22 const struct net_device *out,
23 unsigned int hooknum, 23 unsigned int hooknum,
24 const struct xt_target *target,
24 const void *targinfo, void *userinfo) 25 const void *targinfo, void *userinfo)
25{ 26{
26 struct ipv6hdr *ip6h; 27 struct ipv6hdr *ip6h;
@@ -63,43 +64,31 @@ static unsigned int ip6t_hl_target(struct sk_buff **pskb,
63 64
64static int ip6t_hl_checkentry(const char *tablename, 65static int ip6t_hl_checkentry(const char *tablename,
65 const void *entry, 66 const void *entry,
67 const struct xt_target *target,
66 void *targinfo, 68 void *targinfo,
67 unsigned int targinfosize, 69 unsigned int targinfosize,
68 unsigned int hook_mask) 70 unsigned int hook_mask)
69{ 71{
70 struct ip6t_HL_info *info = targinfo; 72 struct ip6t_HL_info *info = targinfo;
71 73
72 if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_HL_info))) {
73 printk(KERN_WARNING "ip6t_HL: targinfosize %u != %Zu\n",
74 targinfosize,
75 IP6T_ALIGN(sizeof(struct ip6t_HL_info)));
76 return 0;
77 }
78
79 if (strcmp(tablename, "mangle")) {
80 printk(KERN_WARNING "ip6t_HL: can only be called from "
81 "\"mangle\" table, not \"%s\"\n", tablename);
82 return 0;
83 }
84
85 if (info->mode > IP6T_HL_MAXMODE) { 74 if (info->mode > IP6T_HL_MAXMODE) {
86 printk(KERN_WARNING "ip6t_HL: invalid or unknown Mode %u\n", 75 printk(KERN_WARNING "ip6t_HL: invalid or unknown Mode %u\n",
87 info->mode); 76 info->mode);
88 return 0; 77 return 0;
89 } 78 }
90
91 if ((info->mode != IP6T_HL_SET) && (info->hop_limit == 0)) { 79 if ((info->mode != IP6T_HL_SET) && (info->hop_limit == 0)) {
92 printk(KERN_WARNING "ip6t_HL: increment/decrement doesn't " 80 printk(KERN_WARNING "ip6t_HL: increment/decrement doesn't "
93 "make sense with value 0\n"); 81 "make sense with value 0\n");
94 return 0; 82 return 0;
95 } 83 }
96
97 return 1; 84 return 1;
98} 85}
99 86
100static struct ip6t_target ip6t_HL = { 87static struct ip6t_target ip6t_HL = {
101 .name = "HL", 88 .name = "HL",
102 .target = ip6t_hl_target, 89 .target = ip6t_hl_target,
90 .targetsize = sizeof(struct ip6t_HL_info),
91 .table = "mangle",
103 .checkentry = ip6t_hl_checkentry, 92 .checkentry = ip6t_hl_checkentry,
104 .me = THIS_MODULE 93 .me = THIS_MODULE
105}; 94};
diff --git a/net/ipv6/netfilter/ip6t_LOG.c b/net/ipv6/netfilter/ip6t_LOG.c
index 6b930efa9fb9..07c6bcbe4c5f 100644
--- a/net/ipv6/netfilter/ip6t_LOG.c
+++ b/net/ipv6/netfilter/ip6t_LOG.c
@@ -426,6 +426,7 @@ ip6t_log_target(struct sk_buff **pskb,
426 const struct net_device *in, 426 const struct net_device *in,
427 const struct net_device *out, 427 const struct net_device *out,
428 unsigned int hooknum, 428 unsigned int hooknum,
429 const struct xt_target *target,
429 const void *targinfo, 430 const void *targinfo,
430 void *userinfo) 431 void *userinfo)
431{ 432{
@@ -449,35 +450,29 @@ ip6t_log_target(struct sk_buff **pskb,
449 450
450static int ip6t_log_checkentry(const char *tablename, 451static int ip6t_log_checkentry(const char *tablename,
451 const void *entry, 452 const void *entry,
453 const struct xt_target *target,
452 void *targinfo, 454 void *targinfo,
453 unsigned int targinfosize, 455 unsigned int targinfosize,
454 unsigned int hook_mask) 456 unsigned int hook_mask)
455{ 457{
456 const struct ip6t_log_info *loginfo = targinfo; 458 const struct ip6t_log_info *loginfo = targinfo;
457 459
458 if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_log_info))) {
459 DEBUGP("LOG: targinfosize %u != %u\n",
460 targinfosize, IP6T_ALIGN(sizeof(struct ip6t_log_info)));
461 return 0;
462 }
463
464 if (loginfo->level >= 8) { 460 if (loginfo->level >= 8) {
465 DEBUGP("LOG: level %u >= 8\n", loginfo->level); 461 DEBUGP("LOG: level %u >= 8\n", loginfo->level);
466 return 0; 462 return 0;
467 } 463 }
468
469 if (loginfo->prefix[sizeof(loginfo->prefix)-1] != '\0') { 464 if (loginfo->prefix[sizeof(loginfo->prefix)-1] != '\0') {
470 DEBUGP("LOG: prefix term %i\n", 465 DEBUGP("LOG: prefix term %i\n",
471 loginfo->prefix[sizeof(loginfo->prefix)-1]); 466 loginfo->prefix[sizeof(loginfo->prefix)-1]);
472 return 0; 467 return 0;
473 } 468 }
474
475 return 1; 469 return 1;
476} 470}
477 471
478static struct ip6t_target ip6t_log_reg = { 472static struct ip6t_target ip6t_log_reg = {
479 .name = "LOG", 473 .name = "LOG",
480 .target = ip6t_log_target, 474 .target = ip6t_log_target,
475 .targetsize = sizeof(struct ip6t_log_info),
481 .checkentry = ip6t_log_checkentry, 476 .checkentry = ip6t_log_checkentry,
482 .me = THIS_MODULE, 477 .me = THIS_MODULE,
483}; 478};
diff --git a/net/ipv6/netfilter/ip6t_REJECT.c b/net/ipv6/netfilter/ip6t_REJECT.c
index 0e6d1d4bbd5c..ddfa38575fe2 100644
--- a/net/ipv6/netfilter/ip6t_REJECT.c
+++ b/net/ipv6/netfilter/ip6t_REJECT.c
@@ -179,6 +179,7 @@ static unsigned int reject6_target(struct sk_buff **pskb,
179 const struct net_device *in, 179 const struct net_device *in,
180 const struct net_device *out, 180 const struct net_device *out,
181 unsigned int hooknum, 181 unsigned int hooknum,
182 const struct xt_target *target,
182 const void *targinfo, 183 const void *targinfo,
183 void *userinfo) 184 void *userinfo)
184{ 185{
@@ -221,6 +222,7 @@ static unsigned int reject6_target(struct sk_buff **pskb,
221 222
222static int check(const char *tablename, 223static int check(const char *tablename,
223 const void *entry, 224 const void *entry,
225 const struct xt_target *target,
224 void *targinfo, 226 void *targinfo,
225 unsigned int targinfosize, 227 unsigned int targinfosize,
226 unsigned int hook_mask) 228 unsigned int hook_mask)
@@ -228,24 +230,6 @@ static int check(const char *tablename,
228 const struct ip6t_reject_info *rejinfo = targinfo; 230 const struct ip6t_reject_info *rejinfo = targinfo;
229 const struct ip6t_entry *e = entry; 231 const struct ip6t_entry *e = entry;
230 232
231 if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_reject_info))) {
232 DEBUGP("ip6t_REJECT: targinfosize %u != 0\n", targinfosize);
233 return 0;
234 }
235
236 /* Only allow these for packet filtering. */
237 if (strcmp(tablename, "filter") != 0) {
238 DEBUGP("ip6t_REJECT: bad table `%s'.\n", tablename);
239 return 0;
240 }
241
242 if ((hook_mask & ~((1 << NF_IP6_LOCAL_IN)
243 | (1 << NF_IP6_FORWARD)
244 | (1 << NF_IP6_LOCAL_OUT))) != 0) {
245 DEBUGP("ip6t_REJECT: bad hook mask %X\n", hook_mask);
246 return 0;
247 }
248
249 if (rejinfo->with == IP6T_ICMP6_ECHOREPLY) { 233 if (rejinfo->with == IP6T_ICMP6_ECHOREPLY) {
250 printk("ip6t_REJECT: ECHOREPLY is not supported.\n"); 234 printk("ip6t_REJECT: ECHOREPLY is not supported.\n");
251 return 0; 235 return 0;
@@ -257,13 +241,16 @@ static int check(const char *tablename,
257 return 0; 241 return 0;
258 } 242 }
259 } 243 }
260
261 return 1; 244 return 1;
262} 245}
263 246
264static struct ip6t_target ip6t_reject_reg = { 247static struct ip6t_target ip6t_reject_reg = {
265 .name = "REJECT", 248 .name = "REJECT",
266 .target = reject6_target, 249 .target = reject6_target,
250 .targetsize = sizeof(struct ip6t_reject_info),
251 .table = "filter",
252 .hooks = (1 << NF_IP6_LOCAL_IN) | (1 << NF_IP6_FORWARD) |
253 (1 << NF_IP6_LOCAL_OUT),
267 .checkentry = check, 254 .checkentry = check,
268 .me = THIS_MODULE 255 .me = THIS_MODULE
269}; 256};
diff --git a/net/ipv6/netfilter/ip6t_ah.c b/net/ipv6/netfilter/ip6t_ah.c
index 219a30365dff..178f6fb1e53d 100644
--- a/net/ipv6/netfilter/ip6t_ah.c
+++ b/net/ipv6/netfilter/ip6t_ah.c
@@ -44,6 +44,7 @@ static int
44match(const struct sk_buff *skb, 44match(const struct sk_buff *skb,
45 const struct net_device *in, 45 const struct net_device *in,
46 const struct net_device *out, 46 const struct net_device *out,
47 const struct xt_match *match,
47 const void *matchinfo, 48 const void *matchinfo,
48 int offset, 49 int offset,
49 unsigned int protoff, 50 unsigned int protoff,
@@ -99,17 +100,13 @@ match(const struct sk_buff *skb,
99static int 100static int
100checkentry(const char *tablename, 101checkentry(const char *tablename,
101 const void *entry, 102 const void *entry,
103 const struct xt_match *match,
102 void *matchinfo, 104 void *matchinfo,
103 unsigned int matchinfosize, 105 unsigned int matchinfosize,
104 unsigned int hook_mask) 106 unsigned int hook_mask)
105{ 107{
106 const struct ip6t_ah *ahinfo = matchinfo; 108 const struct ip6t_ah *ahinfo = matchinfo;
107 109
108 if (matchinfosize != IP6T_ALIGN(sizeof(struct ip6t_ah))) {
109 DEBUGP("ip6t_ah: matchsize %u != %u\n",
110 matchinfosize, IP6T_ALIGN(sizeof(struct ip6t_ah)));
111 return 0;
112 }
113 if (ahinfo->invflags & ~IP6T_AH_INV_MASK) { 110 if (ahinfo->invflags & ~IP6T_AH_INV_MASK) {
114 DEBUGP("ip6t_ah: unknown flags %X\n", ahinfo->invflags); 111 DEBUGP("ip6t_ah: unknown flags %X\n", ahinfo->invflags);
115 return 0; 112 return 0;
@@ -119,8 +116,9 @@ checkentry(const char *tablename,
119 116
120static struct ip6t_match ah_match = { 117static struct ip6t_match ah_match = {
121 .name = "ah", 118 .name = "ah",
122 .match = &match, 119 .match = match,
123 .checkentry = &checkentry, 120 .matchsize = sizeof(struct ip6t_ah),
121 .checkentry = checkentry,
124 .me = THIS_MODULE, 122 .me = THIS_MODULE,
125}; 123};
126 124
diff --git a/net/ipv6/netfilter/ip6t_dst.c b/net/ipv6/netfilter/ip6t_dst.c
index b4c153a53500..e97a70226987 100644
--- a/net/ipv6/netfilter/ip6t_dst.c
+++ b/net/ipv6/netfilter/ip6t_dst.c
@@ -55,6 +55,7 @@ static int
55match(const struct sk_buff *skb, 55match(const struct sk_buff *skb,
56 const struct net_device *in, 56 const struct net_device *in,
57 const struct net_device *out, 57 const struct net_device *out,
58 const struct xt_match *match,
58 const void *matchinfo, 59 const void *matchinfo,
59 int offset, 60 int offset,
60 unsigned int protoff, 61 unsigned int protoff,
@@ -179,22 +180,17 @@ match(const struct sk_buff *skb,
179static int 180static int
180checkentry(const char *tablename, 181checkentry(const char *tablename,
181 const void *info, 182 const void *info,
183 const struct xt_match *match,
182 void *matchinfo, 184 void *matchinfo,
183 unsigned int matchinfosize, 185 unsigned int matchinfosize,
184 unsigned int hook_mask) 186 unsigned int hook_mask)
185{ 187{
186 const struct ip6t_opts *optsinfo = matchinfo; 188 const struct ip6t_opts *optsinfo = matchinfo;
187 189
188 if (matchinfosize != IP6T_ALIGN(sizeof(struct ip6t_opts))) {
189 DEBUGP("ip6t_opts: matchsize %u != %u\n",
190 matchinfosize, IP6T_ALIGN(sizeof(struct ip6t_opts)));
191 return 0;
192 }
193 if (optsinfo->invflags & ~IP6T_OPTS_INV_MASK) { 190 if (optsinfo->invflags & ~IP6T_OPTS_INV_MASK) {
194 DEBUGP("ip6t_opts: unknown flags %X\n", optsinfo->invflags); 191 DEBUGP("ip6t_opts: unknown flags %X\n", optsinfo->invflags);
195 return 0; 192 return 0;
196 } 193 }
197
198 return 1; 194 return 1;
199} 195}
200 196
@@ -204,8 +200,9 @@ static struct ip6t_match opts_match = {
204#else 200#else
205 .name = "dst", 201 .name = "dst",
206#endif 202#endif
207 .match = &match, 203 .match = match,
208 .checkentry = &checkentry, 204 .matchsize = sizeof(struct ip6t_opts),
205 .checkentry = checkentry,
209 .me = THIS_MODULE, 206 .me = THIS_MODULE,
210}; 207};
211 208
diff --git a/net/ipv6/netfilter/ip6t_esp.c b/net/ipv6/netfilter/ip6t_esp.c
index 724285df8711..540b8bfd5055 100644
--- a/net/ipv6/netfilter/ip6t_esp.c
+++ b/net/ipv6/netfilter/ip6t_esp.c
@@ -44,6 +44,7 @@ static int
44match(const struct sk_buff *skb, 44match(const struct sk_buff *skb,
45 const struct net_device *in, 45 const struct net_device *in,
46 const struct net_device *out, 46 const struct net_device *out,
47 const struct xt_match *match,
47 const void *matchinfo, 48 const void *matchinfo,
48 int offset, 49 int offset,
49 unsigned int protoff, 50 unsigned int protoff,
@@ -77,17 +78,13 @@ match(const struct sk_buff *skb,
77static int 78static int
78checkentry(const char *tablename, 79checkentry(const char *tablename,
79 const void *ip, 80 const void *ip,
81 const struct xt_match *match,
80 void *matchinfo, 82 void *matchinfo,
81 unsigned int matchinfosize, 83 unsigned int matchinfosize,
82 unsigned int hook_mask) 84 unsigned int hook_mask)
83{ 85{
84 const struct ip6t_esp *espinfo = matchinfo; 86 const struct ip6t_esp *espinfo = matchinfo;
85 87
86 if (matchinfosize != IP6T_ALIGN(sizeof(struct ip6t_esp))) {
87 DEBUGP("ip6t_esp: matchsize %u != %u\n",
88 matchinfosize, IP6T_ALIGN(sizeof(struct ip6t_esp)));
89 return 0;
90 }
91 if (espinfo->invflags & ~IP6T_ESP_INV_MASK) { 88 if (espinfo->invflags & ~IP6T_ESP_INV_MASK) {
92 DEBUGP("ip6t_esp: unknown flags %X\n", 89 DEBUGP("ip6t_esp: unknown flags %X\n",
93 espinfo->invflags); 90 espinfo->invflags);
@@ -98,8 +95,9 @@ checkentry(const char *tablename,
98 95
99static struct ip6t_match esp_match = { 96static struct ip6t_match esp_match = {
100 .name = "esp", 97 .name = "esp",
101 .match = &match, 98 .match = match,
102 .checkentry = &checkentry, 99 .matchsize = sizeof(struct ip6t_esp),
100 .checkentry = checkentry,
103 .me = THIS_MODULE, 101 .me = THIS_MODULE,
104}; 102};
105 103
diff --git a/net/ipv6/netfilter/ip6t_eui64.c b/net/ipv6/netfilter/ip6t_eui64.c
index 27396ac0b9ed..d4b0bad52830 100644
--- a/net/ipv6/netfilter/ip6t_eui64.c
+++ b/net/ipv6/netfilter/ip6t_eui64.c
@@ -22,6 +22,7 @@ static int
22match(const struct sk_buff *skb, 22match(const struct sk_buff *skb,
23 const struct net_device *in, 23 const struct net_device *in,
24 const struct net_device *out, 24 const struct net_device *out,
25 const struct xt_match *match,
25 const void *matchinfo, 26 const void *matchinfo,
26 int offset, 27 int offset,
27 unsigned int protoff, 28 unsigned int protoff,
@@ -60,30 +61,12 @@ match(const struct sk_buff *skb,
60 return 0; 61 return 0;
61} 62}
62 63
63static int
64ip6t_eui64_checkentry(const char *tablename,
65 const void *ip,
66 void *matchinfo,
67 unsigned int matchsize,
68 unsigned int hook_mask)
69{
70 if (hook_mask
71 & ~((1 << NF_IP6_PRE_ROUTING) | (1 << NF_IP6_LOCAL_IN) |
72 (1 << NF_IP6_FORWARD))) {
73 printk("ip6t_eui64: only valid for PRE_ROUTING, LOCAL_IN or FORWARD.\n");
74 return 0;
75 }
76
77 if (matchsize != IP6T_ALIGN(sizeof(int)))
78 return 0;
79
80 return 1;
81}
82
83static struct ip6t_match eui64_match = { 64static struct ip6t_match eui64_match = {
84 .name = "eui64", 65 .name = "eui64",
85 .match = &match, 66 .match = match,
86 .checkentry = &ip6t_eui64_checkentry, 67 .matchsize = sizeof(int),
68 .hooks = (1 << NF_IP6_PRE_ROUTING) | (1 << NF_IP6_LOCAL_IN) |
69 (1 << NF_IP6_FORWARD),
87 .me = THIS_MODULE, 70 .me = THIS_MODULE,
88}; 71};
89 72
diff --git a/net/ipv6/netfilter/ip6t_frag.c b/net/ipv6/netfilter/ip6t_frag.c
index 4c14125a0e26..4c41e14823d5 100644
--- a/net/ipv6/netfilter/ip6t_frag.c
+++ b/net/ipv6/netfilter/ip6t_frag.c
@@ -43,6 +43,7 @@ static int
43match(const struct sk_buff *skb, 43match(const struct sk_buff *skb,
44 const struct net_device *in, 44 const struct net_device *in,
45 const struct net_device *out, 45 const struct net_device *out,
46 const struct xt_match *match,
46 const void *matchinfo, 47 const void *matchinfo,
47 int offset, 48 int offset,
48 unsigned int protoff, 49 unsigned int protoff,
@@ -116,29 +117,25 @@ match(const struct sk_buff *skb,
116static int 117static int
117checkentry(const char *tablename, 118checkentry(const char *tablename,
118 const void *ip, 119 const void *ip,
120 const struct xt_match *match,
119 void *matchinfo, 121 void *matchinfo,
120 unsigned int matchinfosize, 122 unsigned int matchinfosize,
121 unsigned int hook_mask) 123 unsigned int hook_mask)
122{ 124{
123 const struct ip6t_frag *fraginfo = matchinfo; 125 const struct ip6t_frag *fraginfo = matchinfo;
124 126
125 if (matchinfosize != IP6T_ALIGN(sizeof(struct ip6t_frag))) {
126 DEBUGP("ip6t_frag: matchsize %u != %u\n",
127 matchinfosize, IP6T_ALIGN(sizeof(struct ip6t_frag)));
128 return 0;
129 }
130 if (fraginfo->invflags & ~IP6T_FRAG_INV_MASK) { 127 if (fraginfo->invflags & ~IP6T_FRAG_INV_MASK) {
131 DEBUGP("ip6t_frag: unknown flags %X\n", fraginfo->invflags); 128 DEBUGP("ip6t_frag: unknown flags %X\n", fraginfo->invflags);
132 return 0; 129 return 0;
133 } 130 }
134
135 return 1; 131 return 1;
136} 132}
137 133
138static struct ip6t_match frag_match = { 134static struct ip6t_match frag_match = {
139 .name = "frag", 135 .name = "frag",
140 .match = &match, 136 .match = match,
141 .checkentry = &checkentry, 137 .matchsize = sizeof(struct ip6t_frag),
138 .checkentry = checkentry,
142 .me = THIS_MODULE, 139 .me = THIS_MODULE,
143}; 140};
144 141
diff --git a/net/ipv6/netfilter/ip6t_hbh.c b/net/ipv6/netfilter/ip6t_hbh.c
index 37a8474a7e0c..b4a1fdfe6abc 100644
--- a/net/ipv6/netfilter/ip6t_hbh.c
+++ b/net/ipv6/netfilter/ip6t_hbh.c
@@ -55,6 +55,7 @@ static int
55match(const struct sk_buff *skb, 55match(const struct sk_buff *skb,
56 const struct net_device *in, 56 const struct net_device *in,
57 const struct net_device *out, 57 const struct net_device *out,
58 const struct xt_match *match,
58 const void *matchinfo, 59 const void *matchinfo,
59 int offset, 60 int offset,
60 unsigned int protoff, 61 unsigned int protoff,
@@ -179,22 +180,17 @@ match(const struct sk_buff *skb,
179static int 180static int
180checkentry(const char *tablename, 181checkentry(const char *tablename,
181 const void *entry, 182 const void *entry,
183 const struct xt_match *match,
182 void *matchinfo, 184 void *matchinfo,
183 unsigned int matchinfosize, 185 unsigned int matchinfosize,
184 unsigned int hook_mask) 186 unsigned int hook_mask)
185{ 187{
186 const struct ip6t_opts *optsinfo = matchinfo; 188 const struct ip6t_opts *optsinfo = matchinfo;
187 189
188 if (matchinfosize != IP6T_ALIGN(sizeof(struct ip6t_opts))) {
189 DEBUGP("ip6t_opts: matchsize %u != %u\n",
190 matchinfosize, IP6T_ALIGN(sizeof(struct ip6t_opts)));
191 return 0;
192 }
193 if (optsinfo->invflags & ~IP6T_OPTS_INV_MASK) { 190 if (optsinfo->invflags & ~IP6T_OPTS_INV_MASK) {
194 DEBUGP("ip6t_opts: unknown flags %X\n", optsinfo->invflags); 191 DEBUGP("ip6t_opts: unknown flags %X\n", optsinfo->invflags);
195 return 0; 192 return 0;
196 } 193 }
197
198 return 1; 194 return 1;
199} 195}
200 196
@@ -204,8 +200,9 @@ static struct ip6t_match opts_match = {
204#else 200#else
205 .name = "dst", 201 .name = "dst",
206#endif 202#endif
207 .match = &match, 203 .match = match,
208 .checkentry = &checkentry, 204 .matchsize = sizeof(struct ip6t_opts),
205 .checkentry = checkentry,
209 .me = THIS_MODULE, 206 .me = THIS_MODULE,
210}; 207};
211 208
diff --git a/net/ipv6/netfilter/ip6t_hl.c b/net/ipv6/netfilter/ip6t_hl.c
index c5d9079f2d9d..374055733b26 100644
--- a/net/ipv6/netfilter/ip6t_hl.c
+++ b/net/ipv6/netfilter/ip6t_hl.c
@@ -18,10 +18,10 @@ MODULE_AUTHOR("Maciej Soltysiak <solt@dns.toxicfilms.tv>");
18MODULE_DESCRIPTION("IP tables Hop Limit matching module"); 18MODULE_DESCRIPTION("IP tables Hop Limit matching module");
19MODULE_LICENSE("GPL"); 19MODULE_LICENSE("GPL");
20 20
21static int match(const struct sk_buff *skb, const struct net_device *in, 21static int match(const struct sk_buff *skb,
22 const struct net_device *out, const void *matchinfo, 22 const struct net_device *in, const struct net_device *out,
23 int offset, unsigned int protoff, 23 const struct xt_match *match, const void *matchinfo,
24 int *hotdrop) 24 int offset, unsigned int protoff, int *hotdrop)
25{ 25{
26 const struct ip6t_hl_info *info = matchinfo; 26 const struct ip6t_hl_info *info = matchinfo;
27 const struct ipv6hdr *ip6h = skb->nh.ipv6h; 27 const struct ipv6hdr *ip6h = skb->nh.ipv6h;
@@ -48,20 +48,10 @@ static int match(const struct sk_buff *skb, const struct net_device *in,
48 return 0; 48 return 0;
49} 49}
50 50
51static int checkentry(const char *tablename, const void *entry,
52 void *matchinfo, unsigned int matchsize,
53 unsigned int hook_mask)
54{
55 if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_hl_info)))
56 return 0;
57
58 return 1;
59}
60
61static struct ip6t_match hl_match = { 51static struct ip6t_match hl_match = {
62 .name = "hl", 52 .name = "hl",
63 .match = &match, 53 .match = match,
64 .checkentry = &checkentry, 54 .matchsize = sizeof(struct ip6t_hl_info),
65 .me = THIS_MODULE, 55 .me = THIS_MODULE,
66}; 56};
67 57
diff --git a/net/ipv6/netfilter/ip6t_ipv6header.c b/net/ipv6/netfilter/ip6t_ipv6header.c
index 83ad6b272f7e..9375eeb1369f 100644
--- a/net/ipv6/netfilter/ip6t_ipv6header.c
+++ b/net/ipv6/netfilter/ip6t_ipv6header.c
@@ -29,6 +29,7 @@ static int
29ipv6header_match(const struct sk_buff *skb, 29ipv6header_match(const struct sk_buff *skb,
30 const struct net_device *in, 30 const struct net_device *in,
31 const struct net_device *out, 31 const struct net_device *out,
32 const struct xt_match *match,
32 const void *matchinfo, 33 const void *matchinfo,
33 int offset, 34 int offset,
34 unsigned int protoff, 35 unsigned int protoff,
@@ -125,17 +126,13 @@ ipv6header_match(const struct sk_buff *skb,
125static int 126static int
126ipv6header_checkentry(const char *tablename, 127ipv6header_checkentry(const char *tablename,
127 const void *ip, 128 const void *ip,
129 const struct xt_match *match,
128 void *matchinfo, 130 void *matchinfo,
129 unsigned int matchsize, 131 unsigned int matchsize,
130 unsigned int hook_mask) 132 unsigned int hook_mask)
131{ 133{
132 const struct ip6t_ipv6header_info *info = matchinfo; 134 const struct ip6t_ipv6header_info *info = matchinfo;
133 135
134 /* Check for obvious errors */
135 /* This match is valid in all hooks! */
136 if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_ipv6header_info)))
137 return 0;
138
139 /* invflags is 0 or 0xff in hard mode */ 136 /* invflags is 0 or 0xff in hard mode */
140 if ((!info->modeflag) && info->invflags != 0x00 && 137 if ((!info->modeflag) && info->invflags != 0x00 &&
141 info->invflags != 0xFF) 138 info->invflags != 0xFF)
@@ -147,6 +144,7 @@ ipv6header_checkentry(const char *tablename,
147static struct ip6t_match ip6t_ipv6header_match = { 144static struct ip6t_match ip6t_ipv6header_match = {
148 .name = "ipv6header", 145 .name = "ipv6header",
149 .match = &ipv6header_match, 146 .match = &ipv6header_match,
147 .matchsize = sizeof(struct ip6t_ipv6header_info),
150 .checkentry = &ipv6header_checkentry, 148 .checkentry = &ipv6header_checkentry,
151 .destroy = NULL, 149 .destroy = NULL,
152 .me = THIS_MODULE, 150 .me = THIS_MODULE,
diff --git a/net/ipv6/netfilter/ip6t_multiport.c b/net/ipv6/netfilter/ip6t_multiport.c
index 49f7829dfbc2..752b65d21c72 100644
--- a/net/ipv6/netfilter/ip6t_multiport.c
+++ b/net/ipv6/netfilter/ip6t_multiport.c
@@ -51,6 +51,7 @@ static int
51match(const struct sk_buff *skb, 51match(const struct sk_buff *skb,
52 const struct net_device *in, 52 const struct net_device *in,
53 const struct net_device *out, 53 const struct net_device *out,
54 const struct xt_match *match,
54 const void *matchinfo, 55 const void *matchinfo,
55 int offset, 56 int offset,
56 unsigned int protoff, 57 unsigned int protoff,
@@ -85,6 +86,7 @@ match(const struct sk_buff *skb,
85static int 86static int
86checkentry(const char *tablename, 87checkentry(const char *tablename,
87 const void *info, 88 const void *info,
89 const struct xt_match *match,
88 void *matchinfo, 90 void *matchinfo,
89 unsigned int matchsize, 91 unsigned int matchsize,
90 unsigned int hook_mask) 92 unsigned int hook_mask)
@@ -92,13 +94,9 @@ checkentry(const char *tablename,
92 const struct ip6t_ip6 *ip = info; 94 const struct ip6t_ip6 *ip = info;
93 const struct ip6t_multiport *multiinfo = matchinfo; 95 const struct ip6t_multiport *multiinfo = matchinfo;
94 96
95 if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_multiport)))
96 return 0;
97
98 /* Must specify proto == TCP/UDP, no unknown flags or bad count */ 97 /* Must specify proto == TCP/UDP, no unknown flags or bad count */
99 return (ip->proto == IPPROTO_TCP || ip->proto == IPPROTO_UDP) 98 return (ip->proto == IPPROTO_TCP || ip->proto == IPPROTO_UDP)
100 && !(ip->invflags & IP6T_INV_PROTO) 99 && !(ip->invflags & IP6T_INV_PROTO)
101 && matchsize == IP6T_ALIGN(sizeof(struct ip6t_multiport))
102 && (multiinfo->flags == IP6T_MULTIPORT_SOURCE 100 && (multiinfo->flags == IP6T_MULTIPORT_SOURCE
103 || multiinfo->flags == IP6T_MULTIPORT_DESTINATION 101 || multiinfo->flags == IP6T_MULTIPORT_DESTINATION
104 || multiinfo->flags == IP6T_MULTIPORT_EITHER) 102 || multiinfo->flags == IP6T_MULTIPORT_EITHER)
@@ -107,8 +105,9 @@ checkentry(const char *tablename,
107 105
108static struct ip6t_match multiport_match = { 106static struct ip6t_match multiport_match = {
109 .name = "multiport", 107 .name = "multiport",
110 .match = &match, 108 .match = match,
111 .checkentry = &checkentry, 109 .matchsize = sizeof(struct ip6t_multiport),
110 .checkentry = checkentry,
112 .me = THIS_MODULE, 111 .me = THIS_MODULE,
113}; 112};
114 113
diff --git a/net/ipv6/netfilter/ip6t_owner.c b/net/ipv6/netfilter/ip6t_owner.c
index 8c8a4c7ec934..e2cee3bcdef9 100644
--- a/net/ipv6/netfilter/ip6t_owner.c
+++ b/net/ipv6/netfilter/ip6t_owner.c
@@ -26,6 +26,7 @@ static int
26match(const struct sk_buff *skb, 26match(const struct sk_buff *skb,
27 const struct net_device *in, 27 const struct net_device *in,
28 const struct net_device *out, 28 const struct net_device *out,
29 const struct xt_match *match,
29 const void *matchinfo, 30 const void *matchinfo,
30 int offset, 31 int offset,
31 unsigned int protoff, 32 unsigned int protoff,
@@ -54,34 +55,27 @@ match(const struct sk_buff *skb,
54static int 55static int
55checkentry(const char *tablename, 56checkentry(const char *tablename,
56 const void *ip, 57 const void *ip,
58 const struct xt_match *match,
57 void *matchinfo, 59 void *matchinfo,
58 unsigned int matchsize, 60 unsigned int matchsize,
59 unsigned int hook_mask) 61 unsigned int hook_mask)
60{ 62{
61 const struct ip6t_owner_info *info = matchinfo; 63 const struct ip6t_owner_info *info = matchinfo;
62 64
63 if (hook_mask
64 & ~((1 << NF_IP6_LOCAL_OUT) | (1 << NF_IP6_POST_ROUTING))) {
65 printk("ip6t_owner: only valid for LOCAL_OUT or POST_ROUTING.\n");
66 return 0;
67 }
68
69 if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_owner_info)))
70 return 0;
71
72 if (info->match & (IP6T_OWNER_PID | IP6T_OWNER_SID)) { 65 if (info->match & (IP6T_OWNER_PID | IP6T_OWNER_SID)) {
73 printk("ipt_owner: pid and sid matching " 66 printk("ipt_owner: pid and sid matching "
74 "not supported anymore\n"); 67 "not supported anymore\n");
75 return 0; 68 return 0;
76 } 69 }
77
78 return 1; 70 return 1;
79} 71}
80 72
81static struct ip6t_match owner_match = { 73static struct ip6t_match owner_match = {
82 .name = "owner", 74 .name = "owner",
83 .match = &match, 75 .match = match,
84 .checkentry = &checkentry, 76 .matchsize = sizeof(struct ip6t_owner_info),
77 .hooks = (1 << NF_IP6_LOCAL_OUT) | (1 << NF_IP6_POST_ROUTING),
78 .checkentry = checkentry,
85 .me = THIS_MODULE, 79 .me = THIS_MODULE,
86}; 80};
87 81
diff --git a/net/ipv6/netfilter/ip6t_policy.c b/net/ipv6/netfilter/ip6t_policy.c
deleted file mode 100644
index 3d39ec924041..000000000000
--- a/net/ipv6/netfilter/ip6t_policy.c
+++ /dev/null
@@ -1,176 +0,0 @@
1/* IP tables module for matching IPsec policy
2 *
3 * Copyright (c) 2004,2005 Patrick McHardy, <kaber@trash.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/kernel.h>
11#include <linux/config.h>
12#include <linux/module.h>
13#include <linux/skbuff.h>
14#include <linux/init.h>
15#include <net/xfrm.h>
16
17#include <linux/netfilter_ipv6.h>
18#include <linux/netfilter_ipv6/ip6_tables.h>
19#include <linux/netfilter_ipv6/ip6t_policy.h>
20
21MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
22MODULE_DESCRIPTION("IPtables IPsec policy matching module");
23MODULE_LICENSE("GPL");
24
25
26static inline int
27match_xfrm_state(struct xfrm_state *x, const struct ip6t_policy_elem *e)
28{
29#define MATCH_ADDR(x,y,z) (!e->match.x || \
30 ((!ip6_masked_addrcmp(&e->x.a6, &e->y.a6, z)) \
31 ^ e->invert.x))
32#define MATCH(x,y) (!e->match.x || ((e->x == (y)) ^ e->invert.x))
33
34 return MATCH_ADDR(saddr, smask, (struct in6_addr *)&x->props.saddr.a6) &&
35 MATCH_ADDR(daddr, dmask, (struct in6_addr *)&x->id.daddr.a6) &&
36 MATCH(proto, x->id.proto) &&
37 MATCH(mode, x->props.mode) &&
38 MATCH(spi, x->id.spi) &&
39 MATCH(reqid, x->props.reqid);
40}
41
42static int
43match_policy_in(const struct sk_buff *skb, const struct ip6t_policy_info *info)
44{
45 const struct ip6t_policy_elem *e;
46 struct sec_path *sp = skb->sp;
47 int strict = info->flags & IP6T_POLICY_MATCH_STRICT;
48 int i, pos;
49
50 if (sp == NULL)
51 return -1;
52 if (strict && info->len != sp->len)
53 return 0;
54
55 for (i = sp->len - 1; i >= 0; i--) {
56 pos = strict ? i - sp->len + 1 : 0;
57 if (pos >= info->len)
58 return 0;
59 e = &info->pol[pos];
60
61 if (match_xfrm_state(sp->x[i].xvec, e)) {
62 if (!strict)
63 return 1;
64 } else if (strict)
65 return 0;
66 }
67
68 return strict ? 1 : 0;
69}
70
71static int
72match_policy_out(const struct sk_buff *skb, const struct ip6t_policy_info *info)
73{
74 const struct ip6t_policy_elem *e;
75 struct dst_entry *dst = skb->dst;
76 int strict = info->flags & IP6T_POLICY_MATCH_STRICT;
77 int i, pos;
78
79 if (dst->xfrm == NULL)
80 return -1;
81
82 for (i = 0; dst && dst->xfrm; dst = dst->child, i++) {
83 pos = strict ? i : 0;
84 if (pos >= info->len)
85 return 0;
86 e = &info->pol[pos];
87
88 if (match_xfrm_state(dst->xfrm, e)) {
89 if (!strict)
90 return 1;
91 } else if (strict)
92 return 0;
93 }
94
95 return strict ? i == info->len : 0;
96}
97
98static int match(const struct sk_buff *skb,
99 const struct net_device *in,
100 const struct net_device *out,
101 const void *matchinfo,
102 int offset,
103 unsigned int protoff,
104 int *hotdrop)
105{
106 const struct ip6t_policy_info *info = matchinfo;
107 int ret;
108
109 if (info->flags & IP6T_POLICY_MATCH_IN)
110 ret = match_policy_in(skb, info);
111 else
112 ret = match_policy_out(skb, info);
113
114 if (ret < 0)
115 ret = info->flags & IP6T_POLICY_MATCH_NONE ? 1 : 0;
116 else if (info->flags & IP6T_POLICY_MATCH_NONE)
117 ret = 0;
118
119 return ret;
120}
121
122static int checkentry(const char *tablename, const void *ip_void,
123 void *matchinfo, unsigned int matchsize,
124 unsigned int hook_mask)
125{
126 struct ip6t_policy_info *info = matchinfo;
127
128 if (matchsize != IP6T_ALIGN(sizeof(*info))) {
129 printk(KERN_ERR "ip6t_policy: matchsize %u != %zu\n",
130 matchsize, IP6T_ALIGN(sizeof(*info)));
131 return 0;
132 }
133 if (!(info->flags & (IP6T_POLICY_MATCH_IN|IP6T_POLICY_MATCH_OUT))) {
134 printk(KERN_ERR "ip6t_policy: neither incoming nor "
135 "outgoing policy selected\n");
136 return 0;
137 }
138 if (hook_mask & (1 << NF_IP6_PRE_ROUTING | 1 << NF_IP6_LOCAL_IN)
139 && info->flags & IP6T_POLICY_MATCH_OUT) {
140 printk(KERN_ERR "ip6t_policy: output policy not valid in "
141 "PRE_ROUTING and INPUT\n");
142 return 0;
143 }
144 if (hook_mask & (1 << NF_IP6_POST_ROUTING | 1 << NF_IP6_LOCAL_OUT)
145 && info->flags & IP6T_POLICY_MATCH_IN) {
146 printk(KERN_ERR "ip6t_policy: input policy not valid in "
147 "POST_ROUTING and OUTPUT\n");
148 return 0;
149 }
150 if (info->len > IP6T_POLICY_MAX_ELEM) {
151 printk(KERN_ERR "ip6t_policy: too many policy elements\n");
152 return 0;
153 }
154
155 return 1;
156}
157
158static struct ip6t_match policy_match = {
159 .name = "policy",
160 .match = match,
161 .checkentry = checkentry,
162 .me = THIS_MODULE,
163};
164
165static int __init init(void)
166{
167 return ip6t_register_match(&policy_match);
168}
169
170static void __exit fini(void)
171{
172 ip6t_unregister_match(&policy_match);
173}
174
175module_init(init);
176module_exit(fini);
diff --git a/net/ipv6/netfilter/ip6t_rt.c b/net/ipv6/netfilter/ip6t_rt.c
index 8f82476dc89e..4c6b55bb225b 100644
--- a/net/ipv6/netfilter/ip6t_rt.c
+++ b/net/ipv6/netfilter/ip6t_rt.c
@@ -45,6 +45,7 @@ static int
45match(const struct sk_buff *skb, 45match(const struct sk_buff *skb,
46 const struct net_device *in, 46 const struct net_device *in,
47 const struct net_device *out, 47 const struct net_device *out,
48 const struct xt_match *match,
48 const void *matchinfo, 49 const void *matchinfo,
49 int offset, 50 int offset,
50 unsigned int protoff, 51 unsigned int protoff,
@@ -194,17 +195,13 @@ match(const struct sk_buff *skb,
194static int 195static int
195checkentry(const char *tablename, 196checkentry(const char *tablename,
196 const void *entry, 197 const void *entry,
198 const struct xt_match *match,
197 void *matchinfo, 199 void *matchinfo,
198 unsigned int matchinfosize, 200 unsigned int matchinfosize,
199 unsigned int hook_mask) 201 unsigned int hook_mask)
200{ 202{
201 const struct ip6t_rt *rtinfo = matchinfo; 203 const struct ip6t_rt *rtinfo = matchinfo;
202 204
203 if (matchinfosize != IP6T_ALIGN(sizeof(struct ip6t_rt))) {
204 DEBUGP("ip6t_rt: matchsize %u != %u\n",
205 matchinfosize, IP6T_ALIGN(sizeof(struct ip6t_rt)));
206 return 0;
207 }
208 if (rtinfo->invflags & ~IP6T_RT_INV_MASK) { 205 if (rtinfo->invflags & ~IP6T_RT_INV_MASK) {
209 DEBUGP("ip6t_rt: unknown flags %X\n", rtinfo->invflags); 206 DEBUGP("ip6t_rt: unknown flags %X\n", rtinfo->invflags);
210 return 0; 207 return 0;
@@ -222,8 +219,9 @@ checkentry(const char *tablename,
222 219
223static struct ip6t_match rt_match = { 220static struct ip6t_match rt_match = {
224 .name = "rt", 221 .name = "rt",
225 .match = &match, 222 .match = match,
226 .checkentry = &checkentry, 223 .matchsize = sizeof(struct ip6t_rt),
224 .checkentry = checkentry,
227 .me = THIS_MODULE, 225 .me = THIS_MODULE,
228}; 226};
229 227
diff --git a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
index ac702a29dd16..ac35f9526368 100644
--- a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
+++ b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
@@ -179,31 +179,36 @@ static unsigned int ipv6_confirm(unsigned int hooknum,
179 int (*okfn)(struct sk_buff *)) 179 int (*okfn)(struct sk_buff *))
180{ 180{
181 struct nf_conn *ct; 181 struct nf_conn *ct;
182 struct nf_conn_help *help;
182 enum ip_conntrack_info ctinfo; 183 enum ip_conntrack_info ctinfo;
184 unsigned int ret, protoff;
185 unsigned int extoff = (u8*)((*pskb)->nh.ipv6h + 1)
186 - (*pskb)->data;
187 unsigned char pnum = (*pskb)->nh.ipv6h->nexthdr;
188
183 189
184 /* This is where we call the helper: as the packet goes out. */ 190 /* This is where we call the helper: as the packet goes out. */
185 ct = nf_ct_get(*pskb, &ctinfo); 191 ct = nf_ct_get(*pskb, &ctinfo);
186 if (ct && ct->helper) { 192 if (!ct)
187 unsigned int ret, protoff; 193 goto out;
188 unsigned int extoff = (u8*)((*pskb)->nh.ipv6h + 1)
189 - (*pskb)->data;
190 unsigned char pnum = (*pskb)->nh.ipv6h->nexthdr;
191
192 protoff = nf_ct_ipv6_skip_exthdr(*pskb, extoff, &pnum,
193 (*pskb)->len - extoff);
194 if (protoff < 0 || protoff > (*pskb)->len ||
195 pnum == NEXTHDR_FRAGMENT) {
196 DEBUGP("proto header not found\n");
197 return NF_ACCEPT;
198 }
199 194
200 ret = ct->helper->help(pskb, protoff, ct, ctinfo); 195 help = nfct_help(ct);
201 if (ret != NF_ACCEPT) 196 if (!help || !help->helper)
202 return ret; 197 goto out;
198
199 protoff = nf_ct_ipv6_skip_exthdr(*pskb, extoff, &pnum,
200 (*pskb)->len - extoff);
201 if (protoff < 0 || protoff > (*pskb)->len ||
202 pnum == NEXTHDR_FRAGMENT) {
203 DEBUGP("proto header not found\n");
204 return NF_ACCEPT;
203 } 205 }
204 206
207 ret = help->helper->help(pskb, protoff, ct, ctinfo);
208 if (ret != NF_ACCEPT)
209 return ret;
210out:
205 /* We've seen it coming out the other side: confirm it */ 211 /* We've seen it coming out the other side: confirm it */
206
207 return nf_conntrack_confirm(pskb); 212 return nf_conntrack_confirm(pskb);
208} 213}
209 214
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
index 84ef9a13108d..3e319035f82d 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -313,8 +313,8 @@ static struct nf_ct_frag6_queue *nf_ct_frag6_intern(unsigned int hash,
313#ifdef CONFIG_SMP 313#ifdef CONFIG_SMP
314 hlist_for_each_entry(fq, n, &nf_ct_frag6_hash[hash], list) { 314 hlist_for_each_entry(fq, n, &nf_ct_frag6_hash[hash], list) {
315 if (fq->id == fq_in->id && 315 if (fq->id == fq_in->id &&
316 !ipv6_addr_cmp(&fq_in->saddr, &fq->saddr) && 316 ipv6_addr_equal(&fq_in->saddr, &fq->saddr) &&
317 !ipv6_addr_cmp(&fq_in->daddr, &fq->daddr)) { 317 ipv6_addr_equal(&fq_in->daddr, &fq->daddr)) {
318 atomic_inc(&fq->refcnt); 318 atomic_inc(&fq->refcnt);
319 write_unlock(&nf_ct_frag6_lock); 319 write_unlock(&nf_ct_frag6_lock);
320 fq_in->last_in |= COMPLETE; 320 fq_in->last_in |= COMPLETE;
@@ -376,8 +376,8 @@ fq_find(u32 id, struct in6_addr *src, struct in6_addr *dst)
376 read_lock(&nf_ct_frag6_lock); 376 read_lock(&nf_ct_frag6_lock);
377 hlist_for_each_entry(fq, n, &nf_ct_frag6_hash[hash], list) { 377 hlist_for_each_entry(fq, n, &nf_ct_frag6_hash[hash], list) {
378 if (fq->id == id && 378 if (fq->id == id &&
379 !ipv6_addr_cmp(src, &fq->saddr) && 379 ipv6_addr_equal(src, &fq->saddr) &&
380 !ipv6_addr_cmp(dst, &fq->daddr)) { 380 ipv6_addr_equal(dst, &fq->daddr)) {
381 atomic_inc(&fq->refcnt); 381 atomic_inc(&fq->refcnt);
382 read_unlock(&nf_ct_frag6_lock); 382 read_unlock(&nf_ct_frag6_lock);
383 return fq; 383 return fq;
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index ae20a0ec9bd8..fa1ce0ae123e 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -859,29 +859,12 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
859} 859}
860 860
861 861
862static int rawv6_setsockopt(struct sock *sk, int level, int optname, 862static int do_rawv6_setsockopt(struct sock *sk, int level, int optname,
863 char __user *optval, int optlen) 863 char __user *optval, int optlen)
864{ 864{
865 struct raw6_sock *rp = raw6_sk(sk); 865 struct raw6_sock *rp = raw6_sk(sk);
866 int val; 866 int val;
867 867
868 switch(level) {
869 case SOL_RAW:
870 break;
871
872 case SOL_ICMPV6:
873 if (inet_sk(sk)->num != IPPROTO_ICMPV6)
874 return -EOPNOTSUPP;
875 return rawv6_seticmpfilter(sk, level, optname, optval,
876 optlen);
877 case SOL_IPV6:
878 if (optname == IPV6_CHECKSUM)
879 break;
880 default:
881 return ipv6_setsockopt(sk, level, optname, optval,
882 optlen);
883 };
884
885 if (get_user(val, (int __user *)optval)) 868 if (get_user(val, (int __user *)optval))
886 return -EFAULT; 869 return -EFAULT;
887 870
@@ -906,12 +889,9 @@ static int rawv6_setsockopt(struct sock *sk, int level, int optname,
906 } 889 }
907} 890}
908 891
909static int rawv6_getsockopt(struct sock *sk, int level, int optname, 892static int rawv6_setsockopt(struct sock *sk, int level, int optname,
910 char __user *optval, int __user *optlen) 893 char __user *optval, int optlen)
911{ 894{
912 struct raw6_sock *rp = raw6_sk(sk);
913 int val, len;
914
915 switch(level) { 895 switch(level) {
916 case SOL_RAW: 896 case SOL_RAW:
917 break; 897 break;
@@ -919,15 +899,45 @@ static int rawv6_getsockopt(struct sock *sk, int level, int optname,
919 case SOL_ICMPV6: 899 case SOL_ICMPV6:
920 if (inet_sk(sk)->num != IPPROTO_ICMPV6) 900 if (inet_sk(sk)->num != IPPROTO_ICMPV6)
921 return -EOPNOTSUPP; 901 return -EOPNOTSUPP;
922 return rawv6_geticmpfilter(sk, level, optname, optval, 902 return rawv6_seticmpfilter(sk, level, optname, optval,
923 optlen); 903 optlen);
924 case SOL_IPV6: 904 case SOL_IPV6:
925 if (optname == IPV6_CHECKSUM) 905 if (optname == IPV6_CHECKSUM)
926 break; 906 break;
927 default: 907 default:
928 return ipv6_getsockopt(sk, level, optname, optval, 908 return ipv6_setsockopt(sk, level, optname, optval,
929 optlen); 909 optlen);
930 }; 910 };
911 return do_rawv6_setsockopt(sk, level, optname, optval, optlen);
912}
913
914#ifdef CONFIG_COMPAT
915static int compat_rawv6_setsockopt(struct sock *sk, int level, int optname,
916 char __user *optval, int optlen)
917{
918 switch (level) {
919 case SOL_RAW:
920 break;
921 case SOL_ICMPV6:
922 if (inet_sk(sk)->num != IPPROTO_ICMPV6)
923 return -EOPNOTSUPP;
924 return rawv6_seticmpfilter(sk, level, optname, optval, optlen);
925 case SOL_IPV6:
926 if (optname == IPV6_CHECKSUM)
927 break;
928 default:
929 return compat_ipv6_setsockopt(sk, level, optname,
930 optval, optlen);
931 };
932 return do_rawv6_setsockopt(sk, level, optname, optval, optlen);
933}
934#endif
935
936static int do_rawv6_getsockopt(struct sock *sk, int level, int optname,
937 char __user *optval, int __user *optlen)
938{
939 struct raw6_sock *rp = raw6_sk(sk);
940 int val, len;
931 941
932 if (get_user(len,optlen)) 942 if (get_user(len,optlen))
933 return -EFAULT; 943 return -EFAULT;
@@ -953,6 +963,50 @@ static int rawv6_getsockopt(struct sock *sk, int level, int optname,
953 return 0; 963 return 0;
954} 964}
955 965
966static int rawv6_getsockopt(struct sock *sk, int level, int optname,
967 char __user *optval, int __user *optlen)
968{
969 switch(level) {
970 case SOL_RAW:
971 break;
972
973 case SOL_ICMPV6:
974 if (inet_sk(sk)->num != IPPROTO_ICMPV6)
975 return -EOPNOTSUPP;
976 return rawv6_geticmpfilter(sk, level, optname, optval,
977 optlen);
978 case SOL_IPV6:
979 if (optname == IPV6_CHECKSUM)
980 break;
981 default:
982 return ipv6_getsockopt(sk, level, optname, optval,
983 optlen);
984 };
985 return do_rawv6_getsockopt(sk, level, optname, optval, optlen);
986}
987
988#ifdef CONFIG_COMPAT
989static int compat_rawv6_getsockopt(struct sock *sk, int level, int optname,
990 char __user *optval, int __user *optlen)
991{
992 switch (level) {
993 case SOL_RAW:
994 break;
995 case SOL_ICMPV6:
996 if (inet_sk(sk)->num != IPPROTO_ICMPV6)
997 return -EOPNOTSUPP;
998 return rawv6_geticmpfilter(sk, level, optname, optval, optlen);
999 case SOL_IPV6:
1000 if (optname == IPV6_CHECKSUM)
1001 break;
1002 default:
1003 return compat_ipv6_getsockopt(sk, level, optname,
1004 optval, optlen);
1005 };
1006 return do_rawv6_getsockopt(sk, level, optname, optval, optlen);
1007}
1008#endif
1009
956static int rawv6_ioctl(struct sock *sk, int cmd, unsigned long arg) 1010static int rawv6_ioctl(struct sock *sk, int cmd, unsigned long arg)
957{ 1011{
958 switch(cmd) { 1012 switch(cmd) {
@@ -998,23 +1052,27 @@ static int rawv6_init_sk(struct sock *sk)
998} 1052}
999 1053
1000struct proto rawv6_prot = { 1054struct proto rawv6_prot = {
1001 .name = "RAWv6", 1055 .name = "RAWv6",
1002 .owner = THIS_MODULE, 1056 .owner = THIS_MODULE,
1003 .close = rawv6_close, 1057 .close = rawv6_close,
1004 .connect = ip6_datagram_connect, 1058 .connect = ip6_datagram_connect,
1005 .disconnect = udp_disconnect, 1059 .disconnect = udp_disconnect,
1006 .ioctl = rawv6_ioctl, 1060 .ioctl = rawv6_ioctl,
1007 .init = rawv6_init_sk, 1061 .init = rawv6_init_sk,
1008 .destroy = inet6_destroy_sock, 1062 .destroy = inet6_destroy_sock,
1009 .setsockopt = rawv6_setsockopt, 1063 .setsockopt = rawv6_setsockopt,
1010 .getsockopt = rawv6_getsockopt, 1064 .getsockopt = rawv6_getsockopt,
1011 .sendmsg = rawv6_sendmsg, 1065 .sendmsg = rawv6_sendmsg,
1012 .recvmsg = rawv6_recvmsg, 1066 .recvmsg = rawv6_recvmsg,
1013 .bind = rawv6_bind, 1067 .bind = rawv6_bind,
1014 .backlog_rcv = rawv6_rcv_skb, 1068 .backlog_rcv = rawv6_rcv_skb,
1015 .hash = raw_v6_hash, 1069 .hash = raw_v6_hash,
1016 .unhash = raw_v6_unhash, 1070 .unhash = raw_v6_unhash,
1017 .obj_size = sizeof(struct raw6_sock), 1071 .obj_size = sizeof(struct raw6_sock),
1072#ifdef CONFIG_COMPAT
1073 .compat_setsockopt = compat_rawv6_setsockopt,
1074 .compat_getsockopt = compat_rawv6_getsockopt,
1075#endif
1018}; 1076};
1019 1077
1020#ifdef CONFIG_PROC_FS 1078#ifdef CONFIG_PROC_FS
@@ -1140,7 +1198,7 @@ static int raw6_seq_open(struct inode *inode, struct file *file)
1140{ 1198{
1141 struct seq_file *seq; 1199 struct seq_file *seq;
1142 int rc = -ENOMEM; 1200 int rc = -ENOMEM;
1143 struct raw6_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL); 1201 struct raw6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
1144 if (!s) 1202 if (!s)
1145 goto out; 1203 goto out;
1146 rc = seq_open(file, &raw6_seq_ops); 1204 rc = seq_open(file, &raw6_seq_ops);
@@ -1148,7 +1206,6 @@ static int raw6_seq_open(struct inode *inode, struct file *file)
1148 goto out_kfree; 1206 goto out_kfree;
1149 seq = file->private_data; 1207 seq = file->private_data;
1150 seq->private = s; 1208 seq->private = s;
1151 memset(s, 0, sizeof(*s));
1152out: 1209out:
1153 return rc; 1210 return rc;
1154out_kfree: 1211out_kfree:
diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
index 15e1456b3f18..b67a45fb93e9 100644
--- a/net/ipv6/reassembly.c
+++ b/net/ipv6/reassembly.c
@@ -203,7 +203,7 @@ static inline void frag_free_queue(struct frag_queue *fq, int *work)
203 203
204static inline struct frag_queue *frag_alloc_queue(void) 204static inline struct frag_queue *frag_alloc_queue(void)
205{ 205{
206 struct frag_queue *fq = kmalloc(sizeof(struct frag_queue), GFP_ATOMIC); 206 struct frag_queue *fq = kzalloc(sizeof(struct frag_queue), GFP_ATOMIC);
207 207
208 if(!fq) 208 if(!fq)
209 return NULL; 209 return NULL;
@@ -288,6 +288,7 @@ static void ip6_evictor(void)
288static void ip6_frag_expire(unsigned long data) 288static void ip6_frag_expire(unsigned long data)
289{ 289{
290 struct frag_queue *fq = (struct frag_queue *) data; 290 struct frag_queue *fq = (struct frag_queue *) data;
291 struct net_device *dev;
291 292
292 spin_lock(&fq->lock); 293 spin_lock(&fq->lock);
293 294
@@ -299,22 +300,22 @@ static void ip6_frag_expire(unsigned long data)
299 IP6_INC_STATS_BH(IPSTATS_MIB_REASMTIMEOUT); 300 IP6_INC_STATS_BH(IPSTATS_MIB_REASMTIMEOUT);
300 IP6_INC_STATS_BH(IPSTATS_MIB_REASMFAILS); 301 IP6_INC_STATS_BH(IPSTATS_MIB_REASMFAILS);
301 302
302 /* Send error only if the first segment arrived. */ 303 /* Don't send error if the first segment did not arrive. */
303 if (fq->last_in&FIRST_IN && fq->fragments) { 304 if (!(fq->last_in&FIRST_IN) || !fq->fragments)
304 struct net_device *dev = dev_get_by_index(fq->iif); 305 goto out;
305 306
306 /* 307 dev = dev_get_by_index(fq->iif);
307 But use as source device on which LAST ARRIVED 308 if (!dev)
308 segment was received. And do not use fq->dev 309 goto out;
309 pointer directly, device might already disappeared. 310
310 */ 311 /*
311 if (dev) { 312 But use as source device on which LAST ARRIVED
312 fq->fragments->dev = dev; 313 segment was received. And do not use fq->dev
313 icmpv6_send(fq->fragments, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0, 314 pointer directly, device might already disappeared.
314 dev); 315 */
315 dev_put(dev); 316 fq->fragments->dev = dev;
316 } 317 icmpv6_send(fq->fragments, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0, dev);
317 } 318 dev_put(dev);
318out: 319out:
319 spin_unlock(&fq->lock); 320 spin_unlock(&fq->lock);
320 fq_put(fq, NULL); 321 fq_put(fq, NULL);
@@ -368,8 +369,6 @@ ip6_frag_create(unsigned int hash, u32 id, struct in6_addr *src, struct in6_addr
368 if ((fq = frag_alloc_queue()) == NULL) 369 if ((fq = frag_alloc_queue()) == NULL)
369 goto oom; 370 goto oom;
370 371
371 memset(fq, 0, sizeof(struct frag_queue));
372
373 fq->id = id; 372 fq->id = id;
374 ipv6_addr_copy(&fq->saddr, src); 373 ipv6_addr_copy(&fq->saddr, src);
375 ipv6_addr_copy(&fq->daddr, dst); 374 ipv6_addr_copy(&fq->daddr, dst);
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index e0d3ad02ffb5..79078747a646 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -72,6 +72,10 @@
72#define RT6_TRACE(x...) do { ; } while (0) 72#define RT6_TRACE(x...) do { ; } while (0)
73#endif 73#endif
74 74
75#define CLONE_OFFLINK_ROUTE 0
76
77#define RT6_SELECT_F_IFACE 0x1
78#define RT6_SELECT_F_REACHABLE 0x2
75 79
76static int ip6_rt_max_size = 4096; 80static int ip6_rt_max_size = 4096;
77static int ip6_rt_gc_min_interval = HZ / 2; 81static int ip6_rt_gc_min_interval = HZ / 2;
@@ -94,6 +98,14 @@ static int ip6_pkt_discard_out(struct sk_buff *skb);
94static void ip6_link_failure(struct sk_buff *skb); 98static void ip6_link_failure(struct sk_buff *skb);
95static void ip6_rt_update_pmtu(struct dst_entry *dst, u32 mtu); 99static void ip6_rt_update_pmtu(struct dst_entry *dst, u32 mtu);
96 100
101#ifdef CONFIG_IPV6_ROUTE_INFO
102static struct rt6_info *rt6_add_route_info(struct in6_addr *prefix, int prefixlen,
103 struct in6_addr *gwaddr, int ifindex,
104 unsigned pref);
105static struct rt6_info *rt6_get_route_info(struct in6_addr *prefix, int prefixlen,
106 struct in6_addr *gwaddr, int ifindex);
107#endif
108
97static struct dst_ops ip6_dst_ops = { 109static struct dst_ops ip6_dst_ops = {
98 .family = AF_INET6, 110 .family = AF_INET6,
99 .protocol = __constant_htons(ETH_P_IPV6), 111 .protocol = __constant_htons(ETH_P_IPV6),
@@ -214,150 +226,211 @@ static __inline__ struct rt6_info *rt6_device_match(struct rt6_info *rt,
214 return rt; 226 return rt;
215} 227}
216 228
229#ifdef CONFIG_IPV6_ROUTER_PREF
230static void rt6_probe(struct rt6_info *rt)
231{
232 struct neighbour *neigh = rt ? rt->rt6i_nexthop : NULL;
233 /*
234 * Okay, this does not seem to be appropriate
235 * for now, however, we need to check if it
236 * is really so; aka Router Reachability Probing.
237 *
238 * Router Reachability Probe MUST be rate-limited
239 * to no more than one per minute.
240 */
241 if (!neigh || (neigh->nud_state & NUD_VALID))
242 return;
243 read_lock_bh(&neigh->lock);
244 if (!(neigh->nud_state & NUD_VALID) &&
245 time_after(jiffies, neigh->updated + rt->rt6i_idev->cnf.rtr_probe_interval)) {
246 struct in6_addr mcaddr;
247 struct in6_addr *target;
248
249 neigh->updated = jiffies;
250 read_unlock_bh(&neigh->lock);
251
252 target = (struct in6_addr *)&neigh->primary_key;
253 addrconf_addr_solict_mult(target, &mcaddr);
254 ndisc_send_ns(rt->rt6i_dev, NULL, target, &mcaddr, NULL);
255 } else
256 read_unlock_bh(&neigh->lock);
257}
258#else
259static inline void rt6_probe(struct rt6_info *rt)
260{
261 return;
262}
263#endif
264
217/* 265/*
218 * pointer to the last default router chosen. BH is disabled locally. 266 * Default Router Selection (RFC 2461 6.3.6)
219 */ 267 */
220static struct rt6_info *rt6_dflt_pointer; 268static int inline rt6_check_dev(struct rt6_info *rt, int oif)
221static DEFINE_SPINLOCK(rt6_dflt_lock); 269{
270 struct net_device *dev = rt->rt6i_dev;
271 if (!oif || dev->ifindex == oif)
272 return 2;
273 if ((dev->flags & IFF_LOOPBACK) &&
274 rt->rt6i_idev && rt->rt6i_idev->dev->ifindex == oif)
275 return 1;
276 return 0;
277}
222 278
223void rt6_reset_dflt_pointer(struct rt6_info *rt) 279static int inline rt6_check_neigh(struct rt6_info *rt)
224{ 280{
225 spin_lock_bh(&rt6_dflt_lock); 281 struct neighbour *neigh = rt->rt6i_nexthop;
226 if (rt == NULL || rt == rt6_dflt_pointer) { 282 int m = 0;
227 RT6_TRACE("reset default router: %p->NULL\n", rt6_dflt_pointer); 283 if (neigh) {
228 rt6_dflt_pointer = NULL; 284 read_lock_bh(&neigh->lock);
285 if (neigh->nud_state & NUD_VALID)
286 m = 1;
287 read_unlock_bh(&neigh->lock);
229 } 288 }
230 spin_unlock_bh(&rt6_dflt_lock); 289 return m;
231} 290}
232 291
233/* Default Router Selection (RFC 2461 6.3.6) */ 292static int rt6_score_route(struct rt6_info *rt, int oif,
234static struct rt6_info *rt6_best_dflt(struct rt6_info *rt, int oif) 293 int strict)
235{ 294{
236 struct rt6_info *match = NULL; 295 int m = rt6_check_dev(rt, oif);
237 struct rt6_info *sprt; 296 if (!m && (strict & RT6_SELECT_F_IFACE))
238 int mpri = 0; 297 return -1;
239 298#ifdef CONFIG_IPV6_ROUTER_PREF
240 for (sprt = rt; sprt; sprt = sprt->u.next) { 299 m |= IPV6_DECODE_PREF(IPV6_EXTRACT_PREF(rt->rt6i_flags)) << 2;
241 struct neighbour *neigh; 300#endif
242 int m = 0; 301 if (rt6_check_neigh(rt))
243 302 m |= 16;
244 if (!oif || 303 else if (strict & RT6_SELECT_F_REACHABLE)
245 (sprt->rt6i_dev && 304 return -1;
246 sprt->rt6i_dev->ifindex == oif)) 305 return m;
247 m += 8; 306}
248 307
249 if (rt6_check_expired(sprt)) 308static struct rt6_info *rt6_select(struct rt6_info **head, int oif,
250 continue; 309 int strict)
310{
311 struct rt6_info *match = NULL, *last = NULL;
312 struct rt6_info *rt, *rt0 = *head;
313 u32 metric;
314 int mpri = -1;
251 315
252 if (sprt == rt6_dflt_pointer) 316 RT6_TRACE("%s(head=%p(*head=%p), oif=%d)\n",
253 m += 4; 317 __FUNCTION__, head, head ? *head : NULL, oif);
254 318
255 if ((neigh = sprt->rt6i_nexthop) != NULL) { 319 for (rt = rt0, metric = rt0->rt6i_metric;
256 read_lock_bh(&neigh->lock); 320 rt && rt->rt6i_metric == metric;
257 switch (neigh->nud_state) { 321 rt = rt->u.next) {
258 case NUD_REACHABLE: 322 int m;
259 m += 3;
260 break;
261 323
262 case NUD_STALE: 324 if (rt6_check_expired(rt))
263 case NUD_DELAY: 325 continue;
264 case NUD_PROBE:
265 m += 2;
266 break;
267 326
268 case NUD_NOARP: 327 last = rt;
269 case NUD_PERMANENT:
270 m += 1;
271 break;
272 328
273 case NUD_INCOMPLETE: 329 m = rt6_score_route(rt, oif, strict);
274 default: 330 if (m < 0)
275 read_unlock_bh(&neigh->lock);
276 continue;
277 }
278 read_unlock_bh(&neigh->lock);
279 } else {
280 continue; 331 continue;
281 }
282 332
283 if (m > mpri || m >= 12) { 333 if (m > mpri) {
284 match = sprt; 334 rt6_probe(match);
335 match = rt;
285 mpri = m; 336 mpri = m;
286 if (m >= 12) { 337 } else {
287 /* we choose the last default router if it 338 rt6_probe(rt);
288 * is in (probably) reachable state.
289 * If route changed, we should do pmtu
290 * discovery. --yoshfuji
291 */
292 break;
293 }
294 } 339 }
295 } 340 }
296 341
297 spin_lock(&rt6_dflt_lock); 342 if (!match &&
298 if (!match) { 343 (strict & RT6_SELECT_F_REACHABLE) &&
299 /* 344 last && last != rt0) {
300 * No default routers are known to be reachable. 345 /* no entries matched; do round-robin */
301 * SHOULD round robin 346 *head = rt0->u.next;
302 */ 347 rt0->u.next = last->u.next;
303 if (rt6_dflt_pointer) { 348 last->u.next = rt0;
304 for (sprt = rt6_dflt_pointer->u.next;
305 sprt; sprt = sprt->u.next) {
306 if (sprt->u.dst.obsolete <= 0 &&
307 sprt->u.dst.error == 0 &&
308 !rt6_check_expired(sprt)) {
309 match = sprt;
310 break;
311 }
312 }
313 for (sprt = rt;
314 !match && sprt;
315 sprt = sprt->u.next) {
316 if (sprt->u.dst.obsolete <= 0 &&
317 sprt->u.dst.error == 0 &&
318 !rt6_check_expired(sprt)) {
319 match = sprt;
320 break;
321 }
322 if (sprt == rt6_dflt_pointer)
323 break;
324 }
325 }
326 } 349 }
327 350
328 if (match) { 351 RT6_TRACE("%s() => %p, score=%d\n",
329 if (rt6_dflt_pointer != match) 352 __FUNCTION__, match, mpri);
330 RT6_TRACE("changed default router: %p->%p\n", 353
331 rt6_dflt_pointer, match); 354 return (match ? match : &ip6_null_entry);
332 rt6_dflt_pointer = match; 355}
356
357#ifdef CONFIG_IPV6_ROUTE_INFO
358int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
359 struct in6_addr *gwaddr)
360{
361 struct route_info *rinfo = (struct route_info *) opt;
362 struct in6_addr prefix_buf, *prefix;
363 unsigned int pref;
364 u32 lifetime;
365 struct rt6_info *rt;
366
367 if (len < sizeof(struct route_info)) {
368 return -EINVAL;
333 } 369 }
334 spin_unlock(&rt6_dflt_lock);
335 370
336 if (!match) { 371 /* Sanity check for prefix_len and length */
337 /* 372 if (rinfo->length > 3) {
338 * Last Resort: if no default routers found, 373 return -EINVAL;
339 * use addrconf default route. 374 } else if (rinfo->prefix_len > 128) {
340 * We don't record this route. 375 return -EINVAL;
341 */ 376 } else if (rinfo->prefix_len > 64) {
342 for (sprt = ip6_routing_table.leaf; 377 if (rinfo->length < 2) {
343 sprt; sprt = sprt->u.next) { 378 return -EINVAL;
344 if (!rt6_check_expired(sprt) &&
345 (sprt->rt6i_flags & RTF_DEFAULT) &&
346 (!oif ||
347 (sprt->rt6i_dev &&
348 sprt->rt6i_dev->ifindex == oif))) {
349 match = sprt;
350 break;
351 }
352 } 379 }
353 if (!match) { 380 } else if (rinfo->prefix_len > 0) {
354 /* no default route. give up. */ 381 if (rinfo->length < 1) {
355 match = &ip6_null_entry; 382 return -EINVAL;
356 } 383 }
357 } 384 }
358 385
359 return match; 386 pref = rinfo->route_pref;
387 if (pref == ICMPV6_ROUTER_PREF_INVALID)
388 pref = ICMPV6_ROUTER_PREF_MEDIUM;
389
390 lifetime = htonl(rinfo->lifetime);
391 if (lifetime == 0xffffffff) {
392 /* infinity */
393 } else if (lifetime > 0x7fffffff/HZ) {
394 /* Avoid arithmetic overflow */
395 lifetime = 0x7fffffff/HZ - 1;
396 }
397
398 if (rinfo->length == 3)
399 prefix = (struct in6_addr *)rinfo->prefix;
400 else {
401 /* this function is safe */
402 ipv6_addr_prefix(&prefix_buf,
403 (struct in6_addr *)rinfo->prefix,
404 rinfo->prefix_len);
405 prefix = &prefix_buf;
406 }
407
408 rt = rt6_get_route_info(prefix, rinfo->prefix_len, gwaddr, dev->ifindex);
409
410 if (rt && !lifetime) {
411 ip6_del_rt(rt, NULL, NULL, NULL);
412 rt = NULL;
413 }
414
415 if (!rt && lifetime)
416 rt = rt6_add_route_info(prefix, rinfo->prefix_len, gwaddr, dev->ifindex,
417 pref);
418 else if (rt)
419 rt->rt6i_flags = RTF_ROUTEINFO |
420 (rt->rt6i_flags & ~RTF_PREF_MASK) | RTF_PREF(pref);
421
422 if (rt) {
423 if (lifetime == 0xffffffff) {
424 rt->rt6i_flags &= ~RTF_EXPIRES;
425 } else {
426 rt->rt6i_expires = jiffies + HZ * lifetime;
427 rt->rt6i_flags |= RTF_EXPIRES;
428 }
429 dst_release(&rt->u.dst);
430 }
431 return 0;
360} 432}
433#endif
361 434
362struct rt6_info *rt6_lookup(struct in6_addr *daddr, struct in6_addr *saddr, 435struct rt6_info *rt6_lookup(struct in6_addr *daddr, struct in6_addr *saddr,
363 int oif, int strict) 436 int oif, int strict)
@@ -397,14 +470,9 @@ int ip6_ins_rt(struct rt6_info *rt, struct nlmsghdr *nlh,
397 return err; 470 return err;
398} 471}
399 472
400/* No rt6_lock! If COW failed, the function returns dead route entry 473static struct rt6_info *rt6_alloc_cow(struct rt6_info *ort, struct in6_addr *daddr,
401 with dst->error set to errno value. 474 struct in6_addr *saddr)
402 */
403
404static struct rt6_info *rt6_cow(struct rt6_info *ort, struct in6_addr *daddr,
405 struct in6_addr *saddr, struct netlink_skb_parms *req)
406{ 475{
407 int err;
408 struct rt6_info *rt; 476 struct rt6_info *rt;
409 477
410 /* 478 /*
@@ -435,25 +503,30 @@ static struct rt6_info *rt6_cow(struct rt6_info *ort, struct in6_addr *daddr,
435 503
436 rt->rt6i_nexthop = ndisc_get_neigh(rt->rt6i_dev, &rt->rt6i_gateway); 504 rt->rt6i_nexthop = ndisc_get_neigh(rt->rt6i_dev, &rt->rt6i_gateway);
437 505
438 dst_hold(&rt->u.dst); 506 }
439
440 err = ip6_ins_rt(rt, NULL, NULL, req);
441 if (err == 0)
442 return rt;
443 507
444 rt->u.dst.error = err; 508 return rt;
509}
445 510
446 return rt; 511static struct rt6_info *rt6_alloc_clone(struct rt6_info *ort, struct in6_addr *daddr)
512{
513 struct rt6_info *rt = ip6_rt_copy(ort);
514 if (rt) {
515 ipv6_addr_copy(&rt->rt6i_dst.addr, daddr);
516 rt->rt6i_dst.plen = 128;
517 rt->rt6i_flags |= RTF_CACHE;
518 if (rt->rt6i_flags & RTF_REJECT)
519 rt->u.dst.error = ort->u.dst.error;
520 rt->u.dst.flags |= DST_HOST;
521 rt->rt6i_nexthop = neigh_clone(ort->rt6i_nexthop);
447 } 522 }
448 dst_hold(&ip6_null_entry.u.dst); 523 return rt;
449 return &ip6_null_entry;
450} 524}
451 525
452#define BACKTRACK() \ 526#define BACKTRACK() \
453if (rt == &ip6_null_entry && strict) { \ 527if (rt == &ip6_null_entry) { \
454 while ((fn = fn->parent) != NULL) { \ 528 while ((fn = fn->parent) != NULL) { \
455 if (fn->fn_flags & RTN_ROOT) { \ 529 if (fn->fn_flags & RTN_ROOT) { \
456 dst_hold(&rt->u.dst); \
457 goto out; \ 530 goto out; \
458 } \ 531 } \
459 if (fn->fn_flags & RTN_RTINFO) \ 532 if (fn->fn_flags & RTN_RTINFO) \
@@ -465,115 +538,138 @@ if (rt == &ip6_null_entry && strict) { \
465void ip6_route_input(struct sk_buff *skb) 538void ip6_route_input(struct sk_buff *skb)
466{ 539{
467 struct fib6_node *fn; 540 struct fib6_node *fn;
468 struct rt6_info *rt; 541 struct rt6_info *rt, *nrt;
469 int strict; 542 int strict;
470 int attempts = 3; 543 int attempts = 3;
544 int err;
545 int reachable = RT6_SELECT_F_REACHABLE;
471 546
472 strict = ipv6_addr_type(&skb->nh.ipv6h->daddr) & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL); 547 strict = ipv6_addr_type(&skb->nh.ipv6h->daddr) & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL) ? RT6_SELECT_F_IFACE : 0;
473 548
474relookup: 549relookup:
475 read_lock_bh(&rt6_lock); 550 read_lock_bh(&rt6_lock);
476 551
552restart_2:
477 fn = fib6_lookup(&ip6_routing_table, &skb->nh.ipv6h->daddr, 553 fn = fib6_lookup(&ip6_routing_table, &skb->nh.ipv6h->daddr,
478 &skb->nh.ipv6h->saddr); 554 &skb->nh.ipv6h->saddr);
479 555
480restart: 556restart:
481 rt = fn->leaf; 557 rt = rt6_select(&fn->leaf, skb->dev->ifindex, strict | reachable);
482
483 if ((rt->rt6i_flags & RTF_CACHE)) {
484 rt = rt6_device_match(rt, skb->dev->ifindex, strict);
485 BACKTRACK();
486 dst_hold(&rt->u.dst);
487 goto out;
488 }
489
490 rt = rt6_device_match(rt, skb->dev->ifindex, strict);
491 BACKTRACK(); 558 BACKTRACK();
559 if (rt == &ip6_null_entry ||
560 rt->rt6i_flags & RTF_CACHE)
561 goto out;
492 562
493 if (!rt->rt6i_nexthop && !(rt->rt6i_flags & RTF_NONEXTHOP)) { 563 dst_hold(&rt->u.dst);
494 struct rt6_info *nrt; 564 read_unlock_bh(&rt6_lock);
495 dst_hold(&rt->u.dst);
496 read_unlock_bh(&rt6_lock);
497 565
498 nrt = rt6_cow(rt, &skb->nh.ipv6h->daddr, 566 if (!rt->rt6i_nexthop && !(rt->rt6i_flags & RTF_NONEXTHOP))
499 &skb->nh.ipv6h->saddr, 567 nrt = rt6_alloc_cow(rt, &skb->nh.ipv6h->daddr, &skb->nh.ipv6h->saddr);
500 &NETLINK_CB(skb)); 568 else {
569#if CLONE_OFFLINK_ROUTE
570 nrt = rt6_alloc_clone(rt, &skb->nh.ipv6h->daddr);
571#else
572 goto out2;
573#endif
574 }
501 575
502 dst_release(&rt->u.dst); 576 dst_release(&rt->u.dst);
503 rt = nrt; 577 rt = nrt ? : &ip6_null_entry;
504 578
505 if (rt->u.dst.error != -EEXIST || --attempts <= 0) 579 dst_hold(&rt->u.dst);
580 if (nrt) {
581 err = ip6_ins_rt(nrt, NULL, NULL, &NETLINK_CB(skb));
582 if (!err)
506 goto out2; 583 goto out2;
507
508 /* Race condition! In the gap, when rt6_lock was
509 released someone could insert this route. Relookup.
510 */
511 dst_release(&rt->u.dst);
512 goto relookup;
513 } 584 }
514 dst_hold(&rt->u.dst); 585
586 if (--attempts <= 0)
587 goto out2;
588
589 /*
590 * Race condition! In the gap, when rt6_lock was
591 * released someone could insert this route. Relookup.
592 */
593 dst_release(&rt->u.dst);
594 goto relookup;
515 595
516out: 596out:
597 if (reachable) {
598 reachable = 0;
599 goto restart_2;
600 }
601 dst_hold(&rt->u.dst);
517 read_unlock_bh(&rt6_lock); 602 read_unlock_bh(&rt6_lock);
518out2: 603out2:
519 rt->u.dst.lastuse = jiffies; 604 rt->u.dst.lastuse = jiffies;
520 rt->u.dst.__use++; 605 rt->u.dst.__use++;
521 skb->dst = (struct dst_entry *) rt; 606 skb->dst = (struct dst_entry *) rt;
607 return;
522} 608}
523 609
524struct dst_entry * ip6_route_output(struct sock *sk, struct flowi *fl) 610struct dst_entry * ip6_route_output(struct sock *sk, struct flowi *fl)
525{ 611{
526 struct fib6_node *fn; 612 struct fib6_node *fn;
527 struct rt6_info *rt; 613 struct rt6_info *rt, *nrt;
528 int strict; 614 int strict;
529 int attempts = 3; 615 int attempts = 3;
616 int err;
617 int reachable = RT6_SELECT_F_REACHABLE;
530 618
531 strict = ipv6_addr_type(&fl->fl6_dst) & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL); 619 strict = ipv6_addr_type(&fl->fl6_dst) & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL) ? RT6_SELECT_F_IFACE : 0;
532 620
533relookup: 621relookup:
534 read_lock_bh(&rt6_lock); 622 read_lock_bh(&rt6_lock);
535 623
624restart_2:
536 fn = fib6_lookup(&ip6_routing_table, &fl->fl6_dst, &fl->fl6_src); 625 fn = fib6_lookup(&ip6_routing_table, &fl->fl6_dst, &fl->fl6_src);
537 626
538restart: 627restart:
539 rt = fn->leaf; 628 rt = rt6_select(&fn->leaf, fl->oif, strict | reachable);
540 629 BACKTRACK();
541 if ((rt->rt6i_flags & RTF_CACHE)) { 630 if (rt == &ip6_null_entry ||
542 rt = rt6_device_match(rt, fl->oif, strict); 631 rt->rt6i_flags & RTF_CACHE)
543 BACKTRACK();
544 dst_hold(&rt->u.dst);
545 goto out; 632 goto out;
546 }
547 if (rt->rt6i_flags & RTF_DEFAULT) {
548 if (rt->rt6i_metric >= IP6_RT_PRIO_ADDRCONF)
549 rt = rt6_best_dflt(rt, fl->oif);
550 } else {
551 rt = rt6_device_match(rt, fl->oif, strict);
552 BACKTRACK();
553 }
554 633
555 if (!rt->rt6i_nexthop && !(rt->rt6i_flags & RTF_NONEXTHOP)) { 634 dst_hold(&rt->u.dst);
556 struct rt6_info *nrt; 635 read_unlock_bh(&rt6_lock);
557 dst_hold(&rt->u.dst);
558 read_unlock_bh(&rt6_lock);
559 636
560 nrt = rt6_cow(rt, &fl->fl6_dst, &fl->fl6_src, NULL); 637 if (!rt->rt6i_nexthop && !(rt->rt6i_flags & RTF_NONEXTHOP))
638 nrt = rt6_alloc_cow(rt, &fl->fl6_dst, &fl->fl6_src);
639 else {
640#if CLONE_OFFLINK_ROUTE
641 nrt = rt6_alloc_clone(rt, &fl->fl6_dst);
642#else
643 goto out2;
644#endif
645 }
561 646
562 dst_release(&rt->u.dst); 647 dst_release(&rt->u.dst);
563 rt = nrt; 648 rt = nrt ? : &ip6_null_entry;
564 649
565 if (rt->u.dst.error != -EEXIST || --attempts <= 0) 650 dst_hold(&rt->u.dst);
651 if (nrt) {
652 err = ip6_ins_rt(nrt, NULL, NULL, NULL);
653 if (!err)
566 goto out2; 654 goto out2;
567
568 /* Race condition! In the gap, when rt6_lock was
569 released someone could insert this route. Relookup.
570 */
571 dst_release(&rt->u.dst);
572 goto relookup;
573 } 655 }
574 dst_hold(&rt->u.dst); 656
657 if (--attempts <= 0)
658 goto out2;
659
660 /*
661 * Race condition! In the gap, when rt6_lock was
662 * released someone could insert this route. Relookup.
663 */
664 dst_release(&rt->u.dst);
665 goto relookup;
575 666
576out: 667out:
668 if (reachable) {
669 reachable = 0;
670 goto restart_2;
671 }
672 dst_hold(&rt->u.dst);
577 read_unlock_bh(&rt6_lock); 673 read_unlock_bh(&rt6_lock);
578out2: 674out2:
579 rt->u.dst.lastuse = jiffies; 675 rt->u.dst.lastuse = jiffies;
@@ -999,8 +1095,6 @@ int ip6_del_rt(struct rt6_info *rt, struct nlmsghdr *nlh, void *_rtattr, struct
999 1095
1000 write_lock_bh(&rt6_lock); 1096 write_lock_bh(&rt6_lock);
1001 1097
1002 rt6_reset_dflt_pointer(NULL);
1003
1004 err = fib6_del(rt, nlh, _rtattr, req); 1098 err = fib6_del(rt, nlh, _rtattr, req);
1005 dst_release(&rt->u.dst); 1099 dst_release(&rt->u.dst);
1006 1100
@@ -1050,59 +1144,63 @@ static int ip6_route_del(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh, void *_r
1050void rt6_redirect(struct in6_addr *dest, struct in6_addr *saddr, 1144void rt6_redirect(struct in6_addr *dest, struct in6_addr *saddr,
1051 struct neighbour *neigh, u8 *lladdr, int on_link) 1145 struct neighbour *neigh, u8 *lladdr, int on_link)
1052{ 1146{
1053 struct rt6_info *rt, *nrt; 1147 struct rt6_info *rt, *nrt = NULL;
1054 1148 int strict;
1055 /* Locate old route to this destination. */ 1149 struct fib6_node *fn;
1056 rt = rt6_lookup(dest, NULL, neigh->dev->ifindex, 1);
1057
1058 if (rt == NULL)
1059 return;
1060
1061 if (neigh->dev != rt->rt6i_dev)
1062 goto out;
1063 1150
1064 /* 1151 /*
1065 * Current route is on-link; redirect is always invalid. 1152 * Get the "current" route for this destination and
1066 * 1153 * check if the redirect has come from approriate router.
1067 * Seems, previous statement is not true. It could 1154 *
1068 * be node, which looks for us as on-link (f.e. proxy ndisc) 1155 * RFC 2461 specifies that redirects should only be
1069 * But then router serving it might decide, that we should 1156 * accepted if they come from the nexthop to the target.
1070 * know truth 8)8) --ANK (980726). 1157 * Due to the way the routes are chosen, this notion
1158 * is a bit fuzzy and one might need to check all possible
1159 * routes.
1071 */ 1160 */
1072 if (!(rt->rt6i_flags&RTF_GATEWAY)) 1161 strict = ipv6_addr_type(dest) & (IPV6_ADDR_MULTICAST | IPV6_ADDR_LINKLOCAL);
1073 goto out;
1074 1162
1075 /* 1163 read_lock_bh(&rt6_lock);
1076 * RFC 2461 specifies that redirects should only be 1164 fn = fib6_lookup(&ip6_routing_table, dest, NULL);
1077 * accepted if they come from the nexthop to the target. 1165restart:
1078 * Due to the way default routers are chosen, this notion 1166 for (rt = fn->leaf; rt; rt = rt->u.next) {
1079 * is a bit fuzzy and one might need to check all default 1167 /*
1080 * routers. 1168 * Current route is on-link; redirect is always invalid.
1081 */ 1169 *
1082 if (!ipv6_addr_equal(saddr, &rt->rt6i_gateway)) { 1170 * Seems, previous statement is not true. It could
1083 if (rt->rt6i_flags & RTF_DEFAULT) { 1171 * be node, which looks for us as on-link (f.e. proxy ndisc)
1084 struct rt6_info *rt1; 1172 * But then router serving it might decide, that we should
1085 1173 * know truth 8)8) --ANK (980726).
1086 read_lock(&rt6_lock); 1174 */
1087 for (rt1 = ip6_routing_table.leaf; rt1; rt1 = rt1->u.next) { 1175 if (rt6_check_expired(rt))
1088 if (ipv6_addr_equal(saddr, &rt1->rt6i_gateway)) { 1176 continue;
1089 dst_hold(&rt1->u.dst); 1177 if (!(rt->rt6i_flags & RTF_GATEWAY))
1090 dst_release(&rt->u.dst); 1178 continue;
1091 read_unlock(&rt6_lock); 1179 if (neigh->dev != rt->rt6i_dev)
1092 rt = rt1; 1180 continue;
1093 goto source_ok; 1181 if (!ipv6_addr_equal(saddr, &rt->rt6i_gateway))
1094 } 1182 continue;
1095 } 1183 break;
1096 read_unlock(&rt6_lock); 1184 }
1185 if (rt)
1186 dst_hold(&rt->u.dst);
1187 else if (strict) {
1188 while ((fn = fn->parent) != NULL) {
1189 if (fn->fn_flags & RTN_ROOT)
1190 break;
1191 if (fn->fn_flags & RTN_RTINFO)
1192 goto restart;
1097 } 1193 }
1194 }
1195 read_unlock_bh(&rt6_lock);
1196
1197 if (!rt) {
1098 if (net_ratelimit()) 1198 if (net_ratelimit())
1099 printk(KERN_DEBUG "rt6_redirect: source isn't a valid nexthop " 1199 printk(KERN_DEBUG "rt6_redirect: source isn't a valid nexthop "
1100 "for redirect target\n"); 1200 "for redirect target\n");
1101 goto out; 1201 return;
1102 } 1202 }
1103 1203
1104source_ok:
1105
1106 /* 1204 /*
1107 * We have finally decided to accept it. 1205 * We have finally decided to accept it.
1108 */ 1206 */
@@ -1210,38 +1308,27 @@ void rt6_pmtu_discovery(struct in6_addr *daddr, struct in6_addr *saddr,
1210 1. It is connected route. Action: COW 1308 1. It is connected route. Action: COW
1211 2. It is gatewayed route or NONEXTHOP route. Action: clone it. 1309 2. It is gatewayed route or NONEXTHOP route. Action: clone it.
1212 */ 1310 */
1213 if (!rt->rt6i_nexthop && !(rt->rt6i_flags & RTF_NONEXTHOP)) { 1311 if (!rt->rt6i_nexthop && !(rt->rt6i_flags & RTF_NONEXTHOP))
1214 nrt = rt6_cow(rt, daddr, saddr, NULL); 1312 nrt = rt6_alloc_cow(rt, daddr, saddr);
1215 if (!nrt->u.dst.error) { 1313 else
1216 nrt->u.dst.metrics[RTAX_MTU-1] = pmtu; 1314 nrt = rt6_alloc_clone(rt, daddr);
1217 if (allfrag) 1315
1218 nrt->u.dst.metrics[RTAX_FEATURES-1] |= RTAX_FEATURE_ALLFRAG; 1316 if (nrt) {
1219 /* According to RFC 1981, detecting PMTU increase shouldn't be
1220 happened within 5 mins, the recommended timer is 10 mins.
1221 Here this route expiration time is set to ip6_rt_mtu_expires
1222 which is 10 mins. After 10 mins the decreased pmtu is expired
1223 and detecting PMTU increase will be automatically happened.
1224 */
1225 dst_set_expires(&nrt->u.dst, ip6_rt_mtu_expires);
1226 nrt->rt6i_flags |= RTF_DYNAMIC|RTF_EXPIRES;
1227 }
1228 dst_release(&nrt->u.dst);
1229 } else {
1230 nrt = ip6_rt_copy(rt);
1231 if (nrt == NULL)
1232 goto out;
1233 ipv6_addr_copy(&nrt->rt6i_dst.addr, daddr);
1234 nrt->rt6i_dst.plen = 128;
1235 nrt->u.dst.flags |= DST_HOST;
1236 nrt->rt6i_nexthop = neigh_clone(rt->rt6i_nexthop);
1237 dst_set_expires(&nrt->u.dst, ip6_rt_mtu_expires);
1238 nrt->rt6i_flags |= RTF_DYNAMIC|RTF_CACHE|RTF_EXPIRES;
1239 nrt->u.dst.metrics[RTAX_MTU-1] = pmtu; 1317 nrt->u.dst.metrics[RTAX_MTU-1] = pmtu;
1240 if (allfrag) 1318 if (allfrag)
1241 nrt->u.dst.metrics[RTAX_FEATURES-1] |= RTAX_FEATURE_ALLFRAG; 1319 nrt->u.dst.metrics[RTAX_FEATURES-1] |= RTAX_FEATURE_ALLFRAG;
1320
1321 /* According to RFC 1981, detecting PMTU increase shouldn't be
1322 * happened within 5 mins, the recommended timer is 10 mins.
1323 * Here this route expiration time is set to ip6_rt_mtu_expires
1324 * which is 10 mins. After 10 mins the decreased pmtu is expired
1325 * and detecting PMTU increase will be automatically happened.
1326 */
1327 dst_set_expires(&nrt->u.dst, ip6_rt_mtu_expires);
1328 nrt->rt6i_flags |= RTF_DYNAMIC|RTF_EXPIRES;
1329
1242 ip6_ins_rt(nrt, NULL, NULL, NULL); 1330 ip6_ins_rt(nrt, NULL, NULL, NULL);
1243 } 1331 }
1244
1245out: 1332out:
1246 dst_release(&rt->u.dst); 1333 dst_release(&rt->u.dst);
1247} 1334}
@@ -1280,6 +1367,57 @@ static struct rt6_info * ip6_rt_copy(struct rt6_info *ort)
1280 return rt; 1367 return rt;
1281} 1368}
1282 1369
1370#ifdef CONFIG_IPV6_ROUTE_INFO
1371static struct rt6_info *rt6_get_route_info(struct in6_addr *prefix, int prefixlen,
1372 struct in6_addr *gwaddr, int ifindex)
1373{
1374 struct fib6_node *fn;
1375 struct rt6_info *rt = NULL;
1376
1377 write_lock_bh(&rt6_lock);
1378 fn = fib6_locate(&ip6_routing_table, prefix ,prefixlen, NULL, 0);
1379 if (!fn)
1380 goto out;
1381
1382 for (rt = fn->leaf; rt; rt = rt->u.next) {
1383 if (rt->rt6i_dev->ifindex != ifindex)
1384 continue;
1385 if ((rt->rt6i_flags & (RTF_ROUTEINFO|RTF_GATEWAY)) != (RTF_ROUTEINFO|RTF_GATEWAY))
1386 continue;
1387 if (!ipv6_addr_equal(&rt->rt6i_gateway, gwaddr))
1388 continue;
1389 dst_hold(&rt->u.dst);
1390 break;
1391 }
1392out:
1393 write_unlock_bh(&rt6_lock);
1394 return rt;
1395}
1396
1397static struct rt6_info *rt6_add_route_info(struct in6_addr *prefix, int prefixlen,
1398 struct in6_addr *gwaddr, int ifindex,
1399 unsigned pref)
1400{
1401 struct in6_rtmsg rtmsg;
1402
1403 memset(&rtmsg, 0, sizeof(rtmsg));
1404 rtmsg.rtmsg_type = RTMSG_NEWROUTE;
1405 ipv6_addr_copy(&rtmsg.rtmsg_dst, prefix);
1406 rtmsg.rtmsg_dst_len = prefixlen;
1407 ipv6_addr_copy(&rtmsg.rtmsg_gateway, gwaddr);
1408 rtmsg.rtmsg_metric = 1024;
1409 rtmsg.rtmsg_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_ROUTEINFO | RTF_UP | RTF_PREF(pref);
1410 /* We should treat it as a default route if prefix length is 0. */
1411 if (!prefixlen)
1412 rtmsg.rtmsg_flags |= RTF_DEFAULT;
1413 rtmsg.rtmsg_ifindex = ifindex;
1414
1415 ip6_route_add(&rtmsg, NULL, NULL, NULL);
1416
1417 return rt6_get_route_info(prefix, prefixlen, gwaddr, ifindex);
1418}
1419#endif
1420
1283struct rt6_info *rt6_get_dflt_router(struct in6_addr *addr, struct net_device *dev) 1421struct rt6_info *rt6_get_dflt_router(struct in6_addr *addr, struct net_device *dev)
1284{ 1422{
1285 struct rt6_info *rt; 1423 struct rt6_info *rt;
@@ -1290,6 +1428,7 @@ struct rt6_info *rt6_get_dflt_router(struct in6_addr *addr, struct net_device *d
1290 write_lock_bh(&rt6_lock); 1428 write_lock_bh(&rt6_lock);
1291 for (rt = fn->leaf; rt; rt=rt->u.next) { 1429 for (rt = fn->leaf; rt; rt=rt->u.next) {
1292 if (dev == rt->rt6i_dev && 1430 if (dev == rt->rt6i_dev &&
1431 ((rt->rt6i_flags & (RTF_ADDRCONF | RTF_DEFAULT)) == (RTF_ADDRCONF | RTF_DEFAULT)) &&
1293 ipv6_addr_equal(&rt->rt6i_gateway, addr)) 1432 ipv6_addr_equal(&rt->rt6i_gateway, addr))
1294 break; 1433 break;
1295 } 1434 }
@@ -1300,7 +1439,8 @@ struct rt6_info *rt6_get_dflt_router(struct in6_addr *addr, struct net_device *d
1300} 1439}
1301 1440
1302struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr, 1441struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr,
1303 struct net_device *dev) 1442 struct net_device *dev,
1443 unsigned int pref)
1304{ 1444{
1305 struct in6_rtmsg rtmsg; 1445 struct in6_rtmsg rtmsg;
1306 1446
@@ -1308,7 +1448,8 @@ struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr,
1308 rtmsg.rtmsg_type = RTMSG_NEWROUTE; 1448 rtmsg.rtmsg_type = RTMSG_NEWROUTE;
1309 ipv6_addr_copy(&rtmsg.rtmsg_gateway, gwaddr); 1449 ipv6_addr_copy(&rtmsg.rtmsg_gateway, gwaddr);
1310 rtmsg.rtmsg_metric = 1024; 1450 rtmsg.rtmsg_metric = 1024;
1311 rtmsg.rtmsg_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_DEFAULT | RTF_UP | RTF_EXPIRES; 1451 rtmsg.rtmsg_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_DEFAULT | RTF_UP | RTF_EXPIRES |
1452 RTF_PREF(pref);
1312 1453
1313 rtmsg.rtmsg_ifindex = dev->ifindex; 1454 rtmsg.rtmsg_ifindex = dev->ifindex;
1314 1455
@@ -1326,8 +1467,6 @@ restart:
1326 if (rt->rt6i_flags & (RTF_DEFAULT | RTF_ADDRCONF)) { 1467 if (rt->rt6i_flags & (RTF_DEFAULT | RTF_ADDRCONF)) {
1327 dst_hold(&rt->u.dst); 1468 dst_hold(&rt->u.dst);
1328 1469
1329 rt6_reset_dflt_pointer(NULL);
1330
1331 read_unlock_bh(&rt6_lock); 1470 read_unlock_bh(&rt6_lock);
1332 1471
1333 ip6_del_rt(rt, NULL, NULL, NULL); 1472 ip6_del_rt(rt, NULL, NULL, NULL);
@@ -1738,11 +1877,10 @@ int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
1738 /* 1877 /*
1739 * 2. allocate and initialize walker. 1878 * 2. allocate and initialize walker.
1740 */ 1879 */
1741 w = kmalloc(sizeof(*w), GFP_ATOMIC); 1880 w = kzalloc(sizeof(*w), GFP_ATOMIC);
1742 if (w == NULL) 1881 if (w == NULL)
1743 return -ENOMEM; 1882 return -ENOMEM;
1744 RT6_TRACE("dump<%p", w); 1883 RT6_TRACE("dump<%p", w);
1745 memset(w, 0, sizeof(*w));
1746 w->root = &ip6_routing_table; 1884 w->root = &ip6_routing_table;
1747 w->func = fib6_dump_node; 1885 w->func = fib6_dump_node;
1748 w->args = &arg; 1886 w->args = &arg;
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index ca9cf6853755..301eee726b0f 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -987,6 +987,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
987 inet_csk(newsk)->icsk_ext_hdr_len = (newnp->opt->opt_nflen + 987 inet_csk(newsk)->icsk_ext_hdr_len = (newnp->opt->opt_nflen +
988 newnp->opt->opt_flen); 988 newnp->opt->opt_flen);
989 989
990 tcp_mtup_init(newsk);
990 tcp_sync_mss(newsk, dst_mtu(dst)); 991 tcp_sync_mss(newsk, dst_mtu(dst));
991 newtp->advmss = dst_metric(dst, RTAX_ADVMSS); 992 newtp->advmss = dst_metric(dst, RTAX_ADVMSS);
992 tcp_initialize_rcv_mss(newsk); 993 tcp_initialize_rcv_mss(newsk);
@@ -1297,18 +1298,21 @@ static int tcp_v6_remember_stamp(struct sock *sk)
1297} 1298}
1298 1299
1299static struct inet_connection_sock_af_ops ipv6_specific = { 1300static struct inet_connection_sock_af_ops ipv6_specific = {
1300 .queue_xmit = inet6_csk_xmit, 1301 .queue_xmit = inet6_csk_xmit,
1301 .send_check = tcp_v6_send_check, 1302 .send_check = tcp_v6_send_check,
1302 .rebuild_header = inet6_sk_rebuild_header, 1303 .rebuild_header = inet6_sk_rebuild_header,
1303 .conn_request = tcp_v6_conn_request, 1304 .conn_request = tcp_v6_conn_request,
1304 .syn_recv_sock = tcp_v6_syn_recv_sock, 1305 .syn_recv_sock = tcp_v6_syn_recv_sock,
1305 .remember_stamp = tcp_v6_remember_stamp, 1306 .remember_stamp = tcp_v6_remember_stamp,
1306 .net_header_len = sizeof(struct ipv6hdr), 1307 .net_header_len = sizeof(struct ipv6hdr),
1307 1308 .setsockopt = ipv6_setsockopt,
1308 .setsockopt = ipv6_setsockopt, 1309 .getsockopt = ipv6_getsockopt,
1309 .getsockopt = ipv6_getsockopt, 1310 .addr2sockaddr = inet6_csk_addr2sockaddr,
1310 .addr2sockaddr = inet6_csk_addr2sockaddr, 1311 .sockaddr_len = sizeof(struct sockaddr_in6),
1311 .sockaddr_len = sizeof(struct sockaddr_in6) 1312#ifdef CONFIG_COMPAT
1313 .compat_setsockopt = compat_ipv6_setsockopt,
1314 .compat_getsockopt = compat_ipv6_getsockopt,
1315#endif
1312}; 1316};
1313 1317
1314/* 1318/*
@@ -1316,22 +1320,23 @@ static struct inet_connection_sock_af_ops ipv6_specific = {
1316 */ 1320 */
1317 1321
1318static struct inet_connection_sock_af_ops ipv6_mapped = { 1322static struct inet_connection_sock_af_ops ipv6_mapped = {
1319 .queue_xmit = ip_queue_xmit, 1323 .queue_xmit = ip_queue_xmit,
1320 .send_check = tcp_v4_send_check, 1324 .send_check = tcp_v4_send_check,
1321 .rebuild_header = inet_sk_rebuild_header, 1325 .rebuild_header = inet_sk_rebuild_header,
1322 .conn_request = tcp_v6_conn_request, 1326 .conn_request = tcp_v6_conn_request,
1323 .syn_recv_sock = tcp_v6_syn_recv_sock, 1327 .syn_recv_sock = tcp_v6_syn_recv_sock,
1324 .remember_stamp = tcp_v4_remember_stamp, 1328 .remember_stamp = tcp_v4_remember_stamp,
1325 .net_header_len = sizeof(struct iphdr), 1329 .net_header_len = sizeof(struct iphdr),
1326 1330 .setsockopt = ipv6_setsockopt,
1327 .setsockopt = ipv6_setsockopt, 1331 .getsockopt = ipv6_getsockopt,
1328 .getsockopt = ipv6_getsockopt, 1332 .addr2sockaddr = inet6_csk_addr2sockaddr,
1329 .addr2sockaddr = inet6_csk_addr2sockaddr, 1333 .sockaddr_len = sizeof(struct sockaddr_in6),
1330 .sockaddr_len = sizeof(struct sockaddr_in6) 1334#ifdef CONFIG_COMPAT
1335 .compat_setsockopt = compat_ipv6_setsockopt,
1336 .compat_getsockopt = compat_ipv6_getsockopt,
1337#endif
1331}; 1338};
1332 1339
1333
1334
1335/* NOTE: A lot of things set to zero explicitly by call to 1340/* NOTE: A lot of things set to zero explicitly by call to
1336 * sk_alloc() so need not be done here. 1341 * sk_alloc() so need not be done here.
1337 */ 1342 */
@@ -1583,6 +1588,10 @@ struct proto tcpv6_prot = {
1583 .obj_size = sizeof(struct tcp6_sock), 1588 .obj_size = sizeof(struct tcp6_sock),
1584 .twsk_prot = &tcp6_timewait_sock_ops, 1589 .twsk_prot = &tcp6_timewait_sock_ops,
1585 .rsk_prot = &tcp6_request_sock_ops, 1590 .rsk_prot = &tcp6_request_sock_ops,
1591#ifdef CONFIG_COMPAT
1592 .compat_setsockopt = compat_tcp_setsockopt,
1593 .compat_getsockopt = compat_tcp_getsockopt,
1594#endif
1586}; 1595};
1587 1596
1588static struct inet6_protocol tcpv6_protocol = { 1597static struct inet6_protocol tcpv6_protocol = {
@@ -1604,21 +1613,12 @@ static struct inet_protosw tcpv6_protosw = {
1604 1613
1605void __init tcpv6_init(void) 1614void __init tcpv6_init(void)
1606{ 1615{
1607 int err;
1608
1609 /* register inet6 protocol */ 1616 /* register inet6 protocol */
1610 if (inet6_add_protocol(&tcpv6_protocol, IPPROTO_TCP) < 0) 1617 if (inet6_add_protocol(&tcpv6_protocol, IPPROTO_TCP) < 0)
1611 printk(KERN_ERR "tcpv6_init: Could not register protocol\n"); 1618 printk(KERN_ERR "tcpv6_init: Could not register protocol\n");
1612 inet6_register_protosw(&tcpv6_protosw); 1619 inet6_register_protosw(&tcpv6_protosw);
1613 1620
1614 err = sock_create_kern(PF_INET6, SOCK_RAW, IPPROTO_TCP, &tcp6_socket); 1621 if (inet_csk_ctl_sock_create(&tcp6_socket, PF_INET6, SOCK_RAW,
1615 if (err < 0) 1622 IPPROTO_TCP) < 0)
1616 panic("Failed to create the TCPv6 control socket.\n"); 1623 panic("Failed to create the TCPv6 control socket.\n");
1617 tcp6_socket->sk->sk_allocation = GFP_ATOMIC;
1618
1619 /* Unhash it so that IP input processing does not even
1620 * see it, we do not wish this socket to see incoming
1621 * packets.
1622 */
1623 tcp6_socket->sk->sk_prot->unhash(tcp6_socket->sk);
1624} 1624}
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index c47648892c04..8d3432a70f3a 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -880,16 +880,13 @@ static int udpv6_destroy_sock(struct sock *sk)
880/* 880/*
881 * Socket option code for UDP 881 * Socket option code for UDP
882 */ 882 */
883static int udpv6_setsockopt(struct sock *sk, int level, int optname, 883static int do_udpv6_setsockopt(struct sock *sk, int level, int optname,
884 char __user *optval, int optlen) 884 char __user *optval, int optlen)
885{ 885{
886 struct udp_sock *up = udp_sk(sk); 886 struct udp_sock *up = udp_sk(sk);
887 int val; 887 int val;
888 int err = 0; 888 int err = 0;
889 889
890 if (level != SOL_UDP)
891 return ipv6_setsockopt(sk, level, optname, optval, optlen);
892
893 if(optlen<sizeof(int)) 890 if(optlen<sizeof(int))
894 return -EINVAL; 891 return -EINVAL;
895 892
@@ -927,15 +924,31 @@ static int udpv6_setsockopt(struct sock *sk, int level, int optname,
927 return err; 924 return err;
928} 925}
929 926
930static int udpv6_getsockopt(struct sock *sk, int level, int optname, 927static int udpv6_setsockopt(struct sock *sk, int level, int optname,
928 char __user *optval, int optlen)
929{
930 if (level != SOL_UDP)
931 return ipv6_setsockopt(sk, level, optname, optval, optlen);
932 return do_udpv6_setsockopt(sk, level, optname, optval, optlen);
933}
934
935#ifdef CONFIG_COMPAT
936static int compat_udpv6_setsockopt(struct sock *sk, int level, int optname,
937 char __user *optval, int optlen)
938{
939 if (level != SOL_UDP)
940 return compat_ipv6_setsockopt(sk, level, optname,
941 optval, optlen);
942 return do_udpv6_setsockopt(sk, level, optname, optval, optlen);
943}
944#endif
945
946static int do_udpv6_getsockopt(struct sock *sk, int level, int optname,
931 char __user *optval, int __user *optlen) 947 char __user *optval, int __user *optlen)
932{ 948{
933 struct udp_sock *up = udp_sk(sk); 949 struct udp_sock *up = udp_sk(sk);
934 int val, len; 950 int val, len;
935 951
936 if (level != SOL_UDP)
937 return ipv6_getsockopt(sk, level, optname, optval, optlen);
938
939 if(get_user(len,optlen)) 952 if(get_user(len,optlen))
940 return -EFAULT; 953 return -EFAULT;
941 954
@@ -964,6 +977,25 @@ static int udpv6_getsockopt(struct sock *sk, int level, int optname,
964 return 0; 977 return 0;
965} 978}
966 979
980static int udpv6_getsockopt(struct sock *sk, int level, int optname,
981 char __user *optval, int __user *optlen)
982{
983 if (level != SOL_UDP)
984 return ipv6_getsockopt(sk, level, optname, optval, optlen);
985 return do_udpv6_getsockopt(sk, level, optname, optval, optlen);
986}
987
988#ifdef CONFIG_COMPAT
989static int compat_udpv6_getsockopt(struct sock *sk, int level, int optname,
990 char __user *optval, int __user *optlen)
991{
992 if (level != SOL_UDP)
993 return compat_ipv6_getsockopt(sk, level, optname,
994 optval, optlen);
995 return do_udpv6_getsockopt(sk, level, optname, optval, optlen);
996}
997#endif
998
967static struct inet6_protocol udpv6_protocol = { 999static struct inet6_protocol udpv6_protocol = {
968 .handler = udpv6_rcv, 1000 .handler = udpv6_rcv,
969 .err_handler = udpv6_err, 1001 .err_handler = udpv6_err,
@@ -1037,22 +1069,26 @@ void udp6_proc_exit(void) {
1037/* ------------------------------------------------------------------------ */ 1069/* ------------------------------------------------------------------------ */
1038 1070
1039struct proto udpv6_prot = { 1071struct proto udpv6_prot = {
1040 .name = "UDPv6", 1072 .name = "UDPv6",
1041 .owner = THIS_MODULE, 1073 .owner = THIS_MODULE,
1042 .close = udpv6_close, 1074 .close = udpv6_close,
1043 .connect = ip6_datagram_connect, 1075 .connect = ip6_datagram_connect,
1044 .disconnect = udp_disconnect, 1076 .disconnect = udp_disconnect,
1045 .ioctl = udp_ioctl, 1077 .ioctl = udp_ioctl,
1046 .destroy = udpv6_destroy_sock, 1078 .destroy = udpv6_destroy_sock,
1047 .setsockopt = udpv6_setsockopt, 1079 .setsockopt = udpv6_setsockopt,
1048 .getsockopt = udpv6_getsockopt, 1080 .getsockopt = udpv6_getsockopt,
1049 .sendmsg = udpv6_sendmsg, 1081 .sendmsg = udpv6_sendmsg,
1050 .recvmsg = udpv6_recvmsg, 1082 .recvmsg = udpv6_recvmsg,
1051 .backlog_rcv = udpv6_queue_rcv_skb, 1083 .backlog_rcv = udpv6_queue_rcv_skb,
1052 .hash = udp_v6_hash, 1084 .hash = udp_v6_hash,
1053 .unhash = udp_v6_unhash, 1085 .unhash = udp_v6_unhash,
1054 .get_port = udp_v6_get_port, 1086 .get_port = udp_v6_get_port,
1055 .obj_size = sizeof(struct udp6_sock), 1087 .obj_size = sizeof(struct udp6_sock),
1088#ifdef CONFIG_COMPAT
1089 .compat_setsockopt = compat_udpv6_setsockopt,
1090 .compat_getsockopt = compat_udpv6_getsockopt,
1091#endif
1056}; 1092};
1057 1093
1058static struct inet_protosw udpv6_protosw = { 1094static struct inet_protosw udpv6_protosw = {
diff --git a/net/ipv6/xfrm6_tunnel.c b/net/ipv6/xfrm6_tunnel.c
index 8cfc58b96fc2..08f9abbdf1d7 100644
--- a/net/ipv6/xfrm6_tunnel.c
+++ b/net/ipv6/xfrm6_tunnel.c
@@ -31,6 +31,7 @@
31#include <net/protocol.h> 31#include <net/protocol.h>
32#include <linux/ipv6.h> 32#include <linux/ipv6.h>
33#include <linux/icmpv6.h> 33#include <linux/icmpv6.h>
34#include <linux/mutex.h>
34 35
35#ifdef CONFIG_IPV6_XFRM6_TUNNEL_DEBUG 36#ifdef CONFIG_IPV6_XFRM6_TUNNEL_DEBUG
36# define X6TDEBUG 3 37# define X6TDEBUG 3
@@ -357,19 +358,19 @@ static int xfrm6_tunnel_input(struct xfrm_state *x, struct xfrm_decap_state *dec
357} 358}
358 359
359static struct xfrm6_tunnel *xfrm6_tunnel_handler; 360static struct xfrm6_tunnel *xfrm6_tunnel_handler;
360static DECLARE_MUTEX(xfrm6_tunnel_sem); 361static DEFINE_MUTEX(xfrm6_tunnel_mutex);
361 362
362int xfrm6_tunnel_register(struct xfrm6_tunnel *handler) 363int xfrm6_tunnel_register(struct xfrm6_tunnel *handler)
363{ 364{
364 int ret; 365 int ret;
365 366
366 down(&xfrm6_tunnel_sem); 367 mutex_lock(&xfrm6_tunnel_mutex);
367 ret = 0; 368 ret = 0;
368 if (xfrm6_tunnel_handler != NULL) 369 if (xfrm6_tunnel_handler != NULL)
369 ret = -EINVAL; 370 ret = -EINVAL;
370 if (!ret) 371 if (!ret)
371 xfrm6_tunnel_handler = handler; 372 xfrm6_tunnel_handler = handler;
372 up(&xfrm6_tunnel_sem); 373 mutex_unlock(&xfrm6_tunnel_mutex);
373 374
374 return ret; 375 return ret;
375} 376}
@@ -380,13 +381,13 @@ int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler)
380{ 381{
381 int ret; 382 int ret;
382 383
383 down(&xfrm6_tunnel_sem); 384 mutex_lock(&xfrm6_tunnel_mutex);
384 ret = 0; 385 ret = 0;
385 if (xfrm6_tunnel_handler != handler) 386 if (xfrm6_tunnel_handler != handler)
386 ret = -EINVAL; 387 ret = -EINVAL;
387 if (!ret) 388 if (!ret)
388 xfrm6_tunnel_handler = NULL; 389 xfrm6_tunnel_handler = NULL;
389 up(&xfrm6_tunnel_sem); 390 mutex_unlock(&xfrm6_tunnel_mutex);
390 391
391 synchronize_net(); 392 synchronize_net();
392 393
diff --git a/net/key/af_key.c b/net/key/af_key.c
index b2d4d1dd2116..859582275cab 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -2651,6 +2651,8 @@ static int pfkey_send_notify(struct xfrm_state *x, struct km_event *c)
2651 return key_notify_sa(x, c); 2651 return key_notify_sa(x, c);
2652 case XFRM_MSG_FLUSHSA: 2652 case XFRM_MSG_FLUSHSA:
2653 return key_notify_sa_flush(c); 2653 return key_notify_sa_flush(c);
2654 case XFRM_MSG_NEWAE: /* not yet supported */
2655 break;
2654 default: 2656 default:
2655 printk("pfkey: Unknown SA event %d\n", c->event); 2657 printk("pfkey: Unknown SA event %d\n", c->event);
2656 break; 2658 break;
@@ -3078,9 +3080,9 @@ static int pfkey_sendmsg(struct kiocb *kiocb,
3078 if (!hdr) 3080 if (!hdr)
3079 goto out; 3081 goto out;
3080 3082
3081 down(&xfrm_cfg_sem); 3083 mutex_lock(&xfrm_cfg_mutex);
3082 err = pfkey_process(sk, skb, hdr); 3084 err = pfkey_process(sk, skb, hdr);
3083 up(&xfrm_cfg_sem); 3085 mutex_unlock(&xfrm_cfg_mutex);
3084 3086
3085out: 3087out:
3086 if (err && hdr && pfkey_error(hdr, err, sk) == 0) 3088 if (err && hdr && pfkey_error(hdr, err, sk) == 0)
diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index 8171c53bc0ed..5a04db745c8d 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -54,7 +54,7 @@ static int llc_ui_wait_for_busy_core(struct sock *sk, long timeout);
54 * 54 *
55 * Return the next unused link number for a given sap. 55 * Return the next unused link number for a given sap.
56 */ 56 */
57static __inline__ u16 llc_ui_next_link_no(int sap) 57static inline u16 llc_ui_next_link_no(int sap)
58{ 58{
59 return llc_ui_sap_link_no_max[sap]++; 59 return llc_ui_sap_link_no_max[sap]++;
60} 60}
@@ -65,7 +65,7 @@ static __inline__ u16 llc_ui_next_link_no(int sap)
65 * 65 *
66 * Given an ARP header type return the corresponding ethernet protocol. 66 * Given an ARP header type return the corresponding ethernet protocol.
67 */ 67 */
68static __inline__ u16 llc_proto_type(u16 arphrd) 68static inline u16 llc_proto_type(u16 arphrd)
69{ 69{
70 return arphrd == ARPHRD_IEEE802_TR ? 70 return arphrd == ARPHRD_IEEE802_TR ?
71 htons(ETH_P_TR_802_2) : htons(ETH_P_802_2); 71 htons(ETH_P_TR_802_2) : htons(ETH_P_802_2);
@@ -75,7 +75,7 @@ static __inline__ u16 llc_proto_type(u16 arphrd)
75 * llc_ui_addr_null - determines if a address structure is null 75 * llc_ui_addr_null - determines if a address structure is null
76 * @addr: Address to test if null. 76 * @addr: Address to test if null.
77 */ 77 */
78static __inline__ u8 llc_ui_addr_null(struct sockaddr_llc *addr) 78static inline u8 llc_ui_addr_null(struct sockaddr_llc *addr)
79{ 79{
80 return !memcmp(addr, &llc_ui_addrnull, sizeof(*addr)); 80 return !memcmp(addr, &llc_ui_addrnull, sizeof(*addr));
81} 81}
@@ -89,8 +89,7 @@ static __inline__ u8 llc_ui_addr_null(struct sockaddr_llc *addr)
89 * operation the user would like to perform and the type of socket. 89 * operation the user would like to perform and the type of socket.
90 * Returns the correct llc header length. 90 * Returns the correct llc header length.
91 */ 91 */
92static __inline__ u8 llc_ui_header_len(struct sock *sk, 92static inline u8 llc_ui_header_len(struct sock *sk, struct sockaddr_llc *addr)
93 struct sockaddr_llc *addr)
94{ 93{
95 u8 rc = LLC_PDU_LEN_U; 94 u8 rc = LLC_PDU_LEN_U;
96 95
@@ -138,7 +137,7 @@ static void llc_ui_sk_init(struct socket *sock, struct sock *sk)
138} 137}
139 138
140static struct proto llc_proto = { 139static struct proto llc_proto = {
141 .name = "DDP", 140 .name = "LLC",
142 .owner = THIS_MODULE, 141 .owner = THIS_MODULE,
143 .obj_size = sizeof(struct llc_sock), 142 .obj_size = sizeof(struct llc_sock),
144}; 143};
@@ -188,8 +187,10 @@ static int llc_ui_release(struct socket *sock)
188 llc->laddr.lsap, llc->daddr.lsap); 187 llc->laddr.lsap, llc->daddr.lsap);
189 if (!llc_send_disc(sk)) 188 if (!llc_send_disc(sk))
190 llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo); 189 llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo);
191 if (!sock_flag(sk, SOCK_ZAPPED)) 190 if (!sock_flag(sk, SOCK_ZAPPED)) {
191 llc_sap_put(llc->sap);
192 llc_sap_remove_socket(llc->sap, sk); 192 llc_sap_remove_socket(llc->sap, sk);
193 }
193 release_sock(sk); 194 release_sock(sk);
194 if (llc->dev) 195 if (llc->dev)
195 dev_put(llc->dev); 196 dev_put(llc->dev);
diff --git a/net/llc/llc_c_ac.c b/net/llc/llc_c_ac.c
index 8169f24ed33e..860140caa6e0 100644
--- a/net/llc/llc_c_ac.c
+++ b/net/llc/llc_c_ac.c
@@ -27,7 +27,6 @@
27#include <net/llc_pdu.h> 27#include <net/llc_pdu.h>
28#include <net/llc.h> 28#include <net/llc.h>
29 29
30#include "llc_output.h"
31 30
32static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb); 31static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb);
33static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb); 32static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb);
diff --git a/net/llc/llc_core.c b/net/llc/llc_core.c
index ab0fcd32fd84..bd242a49514a 100644
--- a/net/llc/llc_core.c
+++ b/net/llc/llc_core.c
@@ -127,7 +127,6 @@ struct llc_sap *llc_sap_open(unsigned char lsap,
127 goto out; 127 goto out;
128 sap->laddr.lsap = lsap; 128 sap->laddr.lsap = lsap;
129 sap->rcv_func = func; 129 sap->rcv_func = func;
130 llc_sap_hold(sap);
131 llc_add_sap(sap); 130 llc_add_sap(sap);
132out: 131out:
133 write_unlock_bh(&llc_sap_list_lock); 132 write_unlock_bh(&llc_sap_list_lock);
diff --git a/net/llc/llc_output.c b/net/llc/llc_output.c
index b4d55b6abb67..b4e668e0e12c 100644
--- a/net/llc/llc_output.c
+++ b/net/llc/llc_output.c
@@ -30,7 +30,8 @@
30 * Fills MAC header fields, depending on MAC type. Returns 0, If MAC type 30 * Fills MAC header fields, depending on MAC type. Returns 0, If MAC type
31 * is a valid type and initialization completes correctly 1, otherwise. 31 * is a valid type and initialization completes correctly 1, otherwise.
32 */ 32 */
33int llc_mac_hdr_init(struct sk_buff *skb, unsigned char *sa, unsigned char *da) 33int llc_mac_hdr_init(struct sk_buff *skb,
34 const unsigned char *sa, const unsigned char *da)
34{ 35{
35 int rc = 0; 36 int rc = 0;
36 37
diff --git a/net/llc/llc_output.h b/net/llc/llc_output.h
deleted file mode 100644
index 179edf753f00..000000000000
--- a/net/llc/llc_output.h
+++ /dev/null
@@ -1,20 +0,0 @@
1#ifndef LLC_OUTPUT_H
2#define LLC_OUTPUT_H
3/*
4 * Copyright (c) 1997 by Procom Technology, Inc.
5 * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
6 *
7 * This program can be redistributed or modified under the terms of the
8 * GNU General Public License version 2 as published by the Free Software
9 * Foundation.
10 * This program is distributed without any warranty or implied warranty
11 * of merchantability or fitness for a particular purpose.
12 *
13 * See the GNU General Public License version 2 for more details.
14 */
15
16struct sk_buff;
17
18int llc_mac_hdr_init(struct sk_buff *skb, unsigned char *sa, unsigned char *da);
19
20#endif /* LLC_OUTPUT_H */
diff --git a/net/llc/llc_s_ac.c b/net/llc/llc_s_ac.c
index bb3580fb8cfe..ac3d93b210d2 100644
--- a/net/llc/llc_s_ac.c
+++ b/net/llc/llc_s_ac.c
@@ -24,7 +24,7 @@
24#include <net/llc_s_ac.h> 24#include <net/llc_s_ac.h>
25#include <net/llc_s_ev.h> 25#include <net/llc_s_ev.h>
26#include <net/llc_sap.h> 26#include <net/llc_sap.h>
27#include "llc_output.h" 27
28 28
29/** 29/**
30 * llc_sap_action_unit_data_ind - forward UI PDU to network layer 30 * llc_sap_action_unit_data_ind - forward UI PDU to network layer
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index a8e5544da93e..174027809148 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -279,6 +279,16 @@ config NETFILTER_XT_MATCH_MARK
279 279
280 To compile it as a module, choose M here. If unsure, say N. 280 To compile it as a module, choose M here. If unsure, say N.
281 281
282config NETFILTER_XT_MATCH_POLICY
283 tristate 'IPsec "policy" match support'
284 depends on NETFILTER_XTABLES && XFRM
285 help
286 Policy matching allows you to match packets based on the
287 IPsec policy that was used during decapsulation/will
288 be used during encapsulation.
289
290 To compile it as a module, choose M here. If unsure, say N.
291
282config NETFILTER_XT_MATCH_PHYSDEV 292config NETFILTER_XT_MATCH_PHYSDEV
283 tristate '"physdev" match support' 293 tristate '"physdev" match support'
284 depends on NETFILTER_XTABLES && BRIDGE_NETFILTER 294 depends on NETFILTER_XTABLES && BRIDGE_NETFILTER
diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
index 746172ebc91b..9558727f5e79 100644
--- a/net/netfilter/Makefile
+++ b/net/netfilter/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_LENGTH) += xt_length.o
40obj-$(CONFIG_NETFILTER_XT_MATCH_LIMIT) += xt_limit.o 40obj-$(CONFIG_NETFILTER_XT_MATCH_LIMIT) += xt_limit.o
41obj-$(CONFIG_NETFILTER_XT_MATCH_MAC) += xt_mac.o 41obj-$(CONFIG_NETFILTER_XT_MATCH_MAC) += xt_mac.o
42obj-$(CONFIG_NETFILTER_XT_MATCH_MARK) += xt_mark.o 42obj-$(CONFIG_NETFILTER_XT_MATCH_MARK) += xt_mark.o
43obj-$(CONFIG_NETFILTER_XT_MATCH_POLICY) += xt_policy.o
43obj-$(CONFIG_NETFILTER_XT_MATCH_PKTTYPE) += xt_pkttype.o 44obj-$(CONFIG_NETFILTER_XT_MATCH_PKTTYPE) += xt_pkttype.o
44obj-$(CONFIG_NETFILTER_XT_MATCH_REALM) += xt_realm.o 45obj-$(CONFIG_NETFILTER_XT_MATCH_REALM) += xt_realm.o
45obj-$(CONFIG_NETFILTER_XT_MATCH_SCTP) += xt_sctp.o 46obj-$(CONFIG_NETFILTER_XT_MATCH_SCTP) += xt_sctp.o
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index d622ddf08bb0..f6498234e264 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -3,7 +3,7 @@
3 extension. */ 3 extension. */
4 4
5/* (C) 1999-2001 Paul `Rusty' Russell 5/* (C) 1999-2001 Paul `Rusty' Russell
6 * (C) 2002-2005 Netfilter Core Team <coreteam@netfilter.org> 6 * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org>
7 * (C) 2003,2004 USAGI/WIDE Project <http://www.linux-ipv6.org> 7 * (C) 2003,2004 USAGI/WIDE Project <http://www.linux-ipv6.org>
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
@@ -20,6 +20,9 @@
20 * - generalize L3 protocol denendent part. 20 * - generalize L3 protocol denendent part.
21 * 23 Mar 2004: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp> 21 * 23 Mar 2004: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
22 * - add support various size of conntrack structures. 22 * - add support various size of conntrack structures.
23 * 26 Jan 2006: Harald Welte <laforge@netfilter.org>
24 * - restructure nf_conn (introduce nf_conn_help)
25 * - redesign 'features' how they were originally intended
23 * 26 *
24 * Derived from net/ipv4/netfilter/ip_conntrack_core.c 27 * Derived from net/ipv4/netfilter/ip_conntrack_core.c
25 */ 28 */
@@ -55,7 +58,7 @@
55#include <net/netfilter/nf_conntrack_core.h> 58#include <net/netfilter/nf_conntrack_core.h>
56#include <linux/netfilter_ipv4/listhelp.h> 59#include <linux/netfilter_ipv4/listhelp.h>
57 60
58#define NF_CONNTRACK_VERSION "0.4.1" 61#define NF_CONNTRACK_VERSION "0.5.0"
59 62
60#if 0 63#if 0
61#define DEBUGP printk 64#define DEBUGP printk
@@ -182,7 +185,7 @@ static struct {
182DEFINE_RWLOCK(nf_ct_cache_lock); 185DEFINE_RWLOCK(nf_ct_cache_lock);
183 186
184/* This avoids calling kmem_cache_create() with same name simultaneously */ 187/* This avoids calling kmem_cache_create() with same name simultaneously */
185DECLARE_MUTEX(nf_ct_cache_mutex); 188static DEFINE_MUTEX(nf_ct_cache_mutex);
186 189
187extern struct nf_conntrack_protocol nf_conntrack_generic_protocol; 190extern struct nf_conntrack_protocol nf_conntrack_generic_protocol;
188struct nf_conntrack_protocol * 191struct nf_conntrack_protocol *
@@ -259,21 +262,8 @@ static inline u_int32_t hash_conntrack(const struct nf_conntrack_tuple *tuple)
259 nf_conntrack_hash_rnd); 262 nf_conntrack_hash_rnd);
260} 263}
261 264
262/* Initialize "struct nf_conn" which has spaces for helper */
263static int
264init_conntrack_for_helper(struct nf_conn *conntrack, u_int32_t features)
265{
266
267 conntrack->help = (union nf_conntrack_help *)
268 (((unsigned long)conntrack->data
269 + (__alignof__(union nf_conntrack_help) - 1))
270 & (~((unsigned long)(__alignof__(union nf_conntrack_help) -1))));
271 return 0;
272}
273
274int nf_conntrack_register_cache(u_int32_t features, const char *name, 265int nf_conntrack_register_cache(u_int32_t features, const char *name,
275 size_t size, 266 size_t size)
276 int (*init)(struct nf_conn *, u_int32_t))
277{ 267{
278 int ret = 0; 268 int ret = 0;
279 char *cache_name; 269 char *cache_name;
@@ -288,7 +278,7 @@ int nf_conntrack_register_cache(u_int32_t features, const char *name,
288 return -EINVAL; 278 return -EINVAL;
289 } 279 }
290 280
291 down(&nf_ct_cache_mutex); 281 mutex_lock(&nf_ct_cache_mutex);
292 282
293 write_lock_bh(&nf_ct_cache_lock); 283 write_lock_bh(&nf_ct_cache_lock);
294 /* e.g: multiple helpers are loaded */ 284 /* e.g: multiple helpers are loaded */
@@ -296,8 +286,7 @@ int nf_conntrack_register_cache(u_int32_t features, const char *name,
296 DEBUGP("nf_conntrack_register_cache: already resisterd.\n"); 286 DEBUGP("nf_conntrack_register_cache: already resisterd.\n");
297 if ((!strncmp(nf_ct_cache[features].name, name, 287 if ((!strncmp(nf_ct_cache[features].name, name,
298 NF_CT_FEATURES_NAMELEN)) 288 NF_CT_FEATURES_NAMELEN))
299 && nf_ct_cache[features].size == size 289 && nf_ct_cache[features].size == size) {
300 && nf_ct_cache[features].init_conntrack == init) {
301 DEBUGP("nf_conntrack_register_cache: reusing.\n"); 290 DEBUGP("nf_conntrack_register_cache: reusing.\n");
302 nf_ct_cache[features].use++; 291 nf_ct_cache[features].use++;
303 ret = 0; 292 ret = 0;
@@ -305,7 +294,7 @@ int nf_conntrack_register_cache(u_int32_t features, const char *name,
305 ret = -EBUSY; 294 ret = -EBUSY;
306 295
307 write_unlock_bh(&nf_ct_cache_lock); 296 write_unlock_bh(&nf_ct_cache_lock);
308 up(&nf_ct_cache_mutex); 297 mutex_unlock(&nf_ct_cache_mutex);
309 return ret; 298 return ret;
310 } 299 }
311 write_unlock_bh(&nf_ct_cache_lock); 300 write_unlock_bh(&nf_ct_cache_lock);
@@ -340,7 +329,6 @@ int nf_conntrack_register_cache(u_int32_t features, const char *name,
340 write_lock_bh(&nf_ct_cache_lock); 329 write_lock_bh(&nf_ct_cache_lock);
341 nf_ct_cache[features].use = 1; 330 nf_ct_cache[features].use = 1;
342 nf_ct_cache[features].size = size; 331 nf_ct_cache[features].size = size;
343 nf_ct_cache[features].init_conntrack = init;
344 nf_ct_cache[features].cachep = cachep; 332 nf_ct_cache[features].cachep = cachep;
345 nf_ct_cache[features].name = cache_name; 333 nf_ct_cache[features].name = cache_name;
346 write_unlock_bh(&nf_ct_cache_lock); 334 write_unlock_bh(&nf_ct_cache_lock);
@@ -350,7 +338,7 @@ int nf_conntrack_register_cache(u_int32_t features, const char *name,
350out_free_name: 338out_free_name:
351 kfree(cache_name); 339 kfree(cache_name);
352out_up_mutex: 340out_up_mutex:
353 up(&nf_ct_cache_mutex); 341 mutex_unlock(&nf_ct_cache_mutex);
354 return ret; 342 return ret;
355} 343}
356 344
@@ -365,19 +353,18 @@ void nf_conntrack_unregister_cache(u_int32_t features)
365 * slab cache. 353 * slab cache.
366 */ 354 */
367 DEBUGP("nf_conntrack_unregister_cache: 0x%04x\n", features); 355 DEBUGP("nf_conntrack_unregister_cache: 0x%04x\n", features);
368 down(&nf_ct_cache_mutex); 356 mutex_lock(&nf_ct_cache_mutex);
369 357
370 write_lock_bh(&nf_ct_cache_lock); 358 write_lock_bh(&nf_ct_cache_lock);
371 if (--nf_ct_cache[features].use > 0) { 359 if (--nf_ct_cache[features].use > 0) {
372 write_unlock_bh(&nf_ct_cache_lock); 360 write_unlock_bh(&nf_ct_cache_lock);
373 up(&nf_ct_cache_mutex); 361 mutex_unlock(&nf_ct_cache_mutex);
374 return; 362 return;
375 } 363 }
376 cachep = nf_ct_cache[features].cachep; 364 cachep = nf_ct_cache[features].cachep;
377 name = nf_ct_cache[features].name; 365 name = nf_ct_cache[features].name;
378 nf_ct_cache[features].cachep = NULL; 366 nf_ct_cache[features].cachep = NULL;
379 nf_ct_cache[features].name = NULL; 367 nf_ct_cache[features].name = NULL;
380 nf_ct_cache[features].init_conntrack = NULL;
381 nf_ct_cache[features].size = 0; 368 nf_ct_cache[features].size = 0;
382 write_unlock_bh(&nf_ct_cache_lock); 369 write_unlock_bh(&nf_ct_cache_lock);
383 370
@@ -386,7 +373,7 @@ void nf_conntrack_unregister_cache(u_int32_t features)
386 kmem_cache_destroy(cachep); 373 kmem_cache_destroy(cachep);
387 kfree(name); 374 kfree(name);
388 375
389 up(&nf_ct_cache_mutex); 376 mutex_unlock(&nf_ct_cache_mutex);
390} 377}
391 378
392int 379int
@@ -432,11 +419,15 @@ nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse,
432/* nf_conntrack_expect helper functions */ 419/* nf_conntrack_expect helper functions */
433void nf_ct_unlink_expect(struct nf_conntrack_expect *exp) 420void nf_ct_unlink_expect(struct nf_conntrack_expect *exp)
434{ 421{
422 struct nf_conn_help *master_help = nfct_help(exp->master);
423
424 NF_CT_ASSERT(master_help);
435 ASSERT_WRITE_LOCK(&nf_conntrack_lock); 425 ASSERT_WRITE_LOCK(&nf_conntrack_lock);
436 NF_CT_ASSERT(!timer_pending(&exp->timeout)); 426 NF_CT_ASSERT(!timer_pending(&exp->timeout));
427
437 list_del(&exp->list); 428 list_del(&exp->list);
438 NF_CT_STAT_INC(expect_delete); 429 NF_CT_STAT_INC(expect_delete);
439 exp->master->expecting--; 430 master_help->expecting--;
440 nf_conntrack_expect_put(exp); 431 nf_conntrack_expect_put(exp);
441} 432}
442 433
@@ -508,9 +499,10 @@ find_expectation(const struct nf_conntrack_tuple *tuple)
508void nf_ct_remove_expectations(struct nf_conn *ct) 499void nf_ct_remove_expectations(struct nf_conn *ct)
509{ 500{
510 struct nf_conntrack_expect *i, *tmp; 501 struct nf_conntrack_expect *i, *tmp;
502 struct nf_conn_help *help = nfct_help(ct);
511 503
512 /* Optimization: most connection never expect any others. */ 504 /* Optimization: most connection never expect any others. */
513 if (ct->expecting == 0) 505 if (!help || help->expecting == 0)
514 return; 506 return;
515 507
516 list_for_each_entry_safe(i, tmp, &nf_conntrack_expect_list, list) { 508 list_for_each_entry_safe(i, tmp, &nf_conntrack_expect_list, list) {
@@ -713,6 +705,7 @@ __nf_conntrack_confirm(struct sk_buff **pskb)
713 conntrack_tuple_cmp, 705 conntrack_tuple_cmp,
714 struct nf_conntrack_tuple_hash *, 706 struct nf_conntrack_tuple_hash *,
715 &ct->tuplehash[IP_CT_DIR_REPLY].tuple, NULL)) { 707 &ct->tuplehash[IP_CT_DIR_REPLY].tuple, NULL)) {
708 struct nf_conn_help *help;
716 /* Remove from unconfirmed list */ 709 /* Remove from unconfirmed list */
717 list_del(&ct->tuplehash[IP_CT_DIR_ORIGINAL].list); 710 list_del(&ct->tuplehash[IP_CT_DIR_ORIGINAL].list);
718 711
@@ -726,7 +719,8 @@ __nf_conntrack_confirm(struct sk_buff **pskb)
726 set_bit(IPS_CONFIRMED_BIT, &ct->status); 719 set_bit(IPS_CONFIRMED_BIT, &ct->status);
727 NF_CT_STAT_INC(insert); 720 NF_CT_STAT_INC(insert);
728 write_unlock_bh(&nf_conntrack_lock); 721 write_unlock_bh(&nf_conntrack_lock);
729 if (ct->helper) 722 help = nfct_help(ct);
723 if (help && help->helper)
730 nf_conntrack_event_cache(IPCT_HELPER, *pskb); 724 nf_conntrack_event_cache(IPCT_HELPER, *pskb);
731#ifdef CONFIG_NF_NAT_NEEDED 725#ifdef CONFIG_NF_NAT_NEEDED
732 if (test_bit(IPS_SRC_NAT_DONE_BIT, &ct->status) || 726 if (test_bit(IPS_SRC_NAT_DONE_BIT, &ct->status) ||
@@ -842,8 +836,9 @@ __nf_conntrack_alloc(const struct nf_conntrack_tuple *orig,
842{ 836{
843 struct nf_conn *conntrack = NULL; 837 struct nf_conn *conntrack = NULL;
844 u_int32_t features = 0; 838 u_int32_t features = 0;
839 struct nf_conntrack_helper *helper;
845 840
846 if (!nf_conntrack_hash_rnd_initted) { 841 if (unlikely(!nf_conntrack_hash_rnd_initted)) {
847 get_random_bytes(&nf_conntrack_hash_rnd, 4); 842 get_random_bytes(&nf_conntrack_hash_rnd, 4);
848 nf_conntrack_hash_rnd_initted = 1; 843 nf_conntrack_hash_rnd_initted = 1;
849 } 844 }
@@ -863,8 +858,11 @@ __nf_conntrack_alloc(const struct nf_conntrack_tuple *orig,
863 858
864 /* find features needed by this conntrack. */ 859 /* find features needed by this conntrack. */
865 features = l3proto->get_features(orig); 860 features = l3proto->get_features(orig);
861
862 /* FIXME: protect helper list per RCU */
866 read_lock_bh(&nf_conntrack_lock); 863 read_lock_bh(&nf_conntrack_lock);
867 if (__nf_ct_helper_find(repl) != NULL) 864 helper = __nf_ct_helper_find(repl);
865 if (helper)
868 features |= NF_CT_F_HELP; 866 features |= NF_CT_F_HELP;
869 read_unlock_bh(&nf_conntrack_lock); 867 read_unlock_bh(&nf_conntrack_lock);
870 868
@@ -872,7 +870,7 @@ __nf_conntrack_alloc(const struct nf_conntrack_tuple *orig,
872 870
873 read_lock_bh(&nf_ct_cache_lock); 871 read_lock_bh(&nf_ct_cache_lock);
874 872
875 if (!nf_ct_cache[features].use) { 873 if (unlikely(!nf_ct_cache[features].use)) {
876 DEBUGP("nf_conntrack_alloc: not supported features = 0x%x\n", 874 DEBUGP("nf_conntrack_alloc: not supported features = 0x%x\n",
877 features); 875 features);
878 goto out; 876 goto out;
@@ -886,12 +884,10 @@ __nf_conntrack_alloc(const struct nf_conntrack_tuple *orig,
886 884
887 memset(conntrack, 0, nf_ct_cache[features].size); 885 memset(conntrack, 0, nf_ct_cache[features].size);
888 conntrack->features = features; 886 conntrack->features = features;
889 if (nf_ct_cache[features].init_conntrack && 887 if (helper) {
890 nf_ct_cache[features].init_conntrack(conntrack, features) < 0) { 888 struct nf_conn_help *help = nfct_help(conntrack);
891 DEBUGP("nf_conntrack_alloc: failed to init\n"); 889 NF_CT_ASSERT(help);
892 kmem_cache_free(nf_ct_cache[features].cachep, conntrack); 890 help->helper = helper;
893 conntrack = NULL;
894 goto out;
895 } 891 }
896 892
897 atomic_set(&conntrack->ct_general.use, 1); 893 atomic_set(&conntrack->ct_general.use, 1);
@@ -972,11 +968,8 @@ init_conntrack(const struct nf_conntrack_tuple *tuple,
972#endif 968#endif
973 nf_conntrack_get(&conntrack->master->ct_general); 969 nf_conntrack_get(&conntrack->master->ct_general);
974 NF_CT_STAT_INC(expect_new); 970 NF_CT_STAT_INC(expect_new);
975 } else { 971 } else
976 conntrack->helper = __nf_ct_helper_find(&repl_tuple);
977
978 NF_CT_STAT_INC(new); 972 NF_CT_STAT_INC(new);
979 }
980 973
981 /* Overload tuple linked list to put us in unconfirmed list. */ 974 /* Overload tuple linked list to put us in unconfirmed list. */
982 list_add(&conntrack->tuplehash[IP_CT_DIR_ORIGINAL].list, &unconfirmed); 975 list_add(&conntrack->tuplehash[IP_CT_DIR_ORIGINAL].list, &unconfirmed);
@@ -1206,14 +1199,16 @@ void nf_conntrack_expect_put(struct nf_conntrack_expect *exp)
1206 1199
1207static void nf_conntrack_expect_insert(struct nf_conntrack_expect *exp) 1200static void nf_conntrack_expect_insert(struct nf_conntrack_expect *exp)
1208{ 1201{
1202 struct nf_conn_help *master_help = nfct_help(exp->master);
1203
1209 atomic_inc(&exp->use); 1204 atomic_inc(&exp->use);
1210 exp->master->expecting++; 1205 master_help->expecting++;
1211 list_add(&exp->list, &nf_conntrack_expect_list); 1206 list_add(&exp->list, &nf_conntrack_expect_list);
1212 1207
1213 init_timer(&exp->timeout); 1208 init_timer(&exp->timeout);
1214 exp->timeout.data = (unsigned long)exp; 1209 exp->timeout.data = (unsigned long)exp;
1215 exp->timeout.function = expectation_timed_out; 1210 exp->timeout.function = expectation_timed_out;
1216 exp->timeout.expires = jiffies + exp->master->helper->timeout * HZ; 1211 exp->timeout.expires = jiffies + master_help->helper->timeout * HZ;
1217 add_timer(&exp->timeout); 1212 add_timer(&exp->timeout);
1218 1213
1219 exp->id = ++nf_conntrack_expect_next_id; 1214 exp->id = ++nf_conntrack_expect_next_id;
@@ -1239,10 +1234,12 @@ static void evict_oldest_expect(struct nf_conn *master)
1239 1234
1240static inline int refresh_timer(struct nf_conntrack_expect *i) 1235static inline int refresh_timer(struct nf_conntrack_expect *i)
1241{ 1236{
1237 struct nf_conn_help *master_help = nfct_help(i->master);
1238
1242 if (!del_timer(&i->timeout)) 1239 if (!del_timer(&i->timeout))
1243 return 0; 1240 return 0;
1244 1241
1245 i->timeout.expires = jiffies + i->master->helper->timeout*HZ; 1242 i->timeout.expires = jiffies + master_help->helper->timeout*HZ;
1246 add_timer(&i->timeout); 1243 add_timer(&i->timeout);
1247 return 1; 1244 return 1;
1248} 1245}
@@ -1251,8 +1248,11 @@ int nf_conntrack_expect_related(struct nf_conntrack_expect *expect)
1251{ 1248{
1252 struct nf_conntrack_expect *i; 1249 struct nf_conntrack_expect *i;
1253 struct nf_conn *master = expect->master; 1250 struct nf_conn *master = expect->master;
1251 struct nf_conn_help *master_help = nfct_help(master);
1254 int ret; 1252 int ret;
1255 1253
1254 NF_CT_ASSERT(master_help);
1255
1256 DEBUGP("nf_conntrack_expect_related %p\n", related_to); 1256 DEBUGP("nf_conntrack_expect_related %p\n", related_to);
1257 DEBUGP("tuple: "); NF_CT_DUMP_TUPLE(&expect->tuple); 1257 DEBUGP("tuple: "); NF_CT_DUMP_TUPLE(&expect->tuple);
1258 DEBUGP("mask: "); NF_CT_DUMP_TUPLE(&expect->mask); 1258 DEBUGP("mask: "); NF_CT_DUMP_TUPLE(&expect->mask);
@@ -1271,8 +1271,8 @@ int nf_conntrack_expect_related(struct nf_conntrack_expect *expect)
1271 } 1271 }
1272 } 1272 }
1273 /* Will be over limit? */ 1273 /* Will be over limit? */
1274 if (master->helper->max_expected && 1274 if (master_help->helper->max_expected &&
1275 master->expecting >= master->helper->max_expected) 1275 master_help->expecting >= master_help->helper->max_expected)
1276 evict_oldest_expect(master); 1276 evict_oldest_expect(master);
1277 1277
1278 nf_conntrack_expect_insert(expect); 1278 nf_conntrack_expect_insert(expect);
@@ -1283,24 +1283,6 @@ out:
1283 return ret; 1283 return ret;
1284} 1284}
1285 1285
1286/* Alter reply tuple (maybe alter helper). This is for NAT, and is
1287 implicitly racy: see __nf_conntrack_confirm */
1288void nf_conntrack_alter_reply(struct nf_conn *conntrack,
1289 const struct nf_conntrack_tuple *newreply)
1290{
1291 write_lock_bh(&nf_conntrack_lock);
1292 /* Should be unconfirmed, so not in hash table yet */
1293 NF_CT_ASSERT(!nf_ct_is_confirmed(conntrack));
1294
1295 DEBUGP("Altering reply tuple of %p to ", conntrack);
1296 NF_CT_DUMP_TUPLE(newreply);
1297
1298 conntrack->tuplehash[IP_CT_DIR_REPLY].tuple = *newreply;
1299 if (!conntrack->master && conntrack->expecting == 0)
1300 conntrack->helper = __nf_ct_helper_find(newreply);
1301 write_unlock_bh(&nf_conntrack_lock);
1302}
1303
1304int nf_conntrack_helper_register(struct nf_conntrack_helper *me) 1286int nf_conntrack_helper_register(struct nf_conntrack_helper *me)
1305{ 1287{
1306 int ret; 1288 int ret;
@@ -1308,9 +1290,8 @@ int nf_conntrack_helper_register(struct nf_conntrack_helper *me)
1308 1290
1309 ret = nf_conntrack_register_cache(NF_CT_F_HELP, "nf_conntrack:help", 1291 ret = nf_conntrack_register_cache(NF_CT_F_HELP, "nf_conntrack:help",
1310 sizeof(struct nf_conn) 1292 sizeof(struct nf_conn)
1311 + sizeof(union nf_conntrack_help) 1293 + sizeof(struct nf_conn_help)
1312 + __alignof__(union nf_conntrack_help), 1294 + __alignof__(struct nf_conn_help));
1313 init_conntrack_for_helper);
1314 if (ret < 0) { 1295 if (ret < 0) {
1315 printk(KERN_ERR "nf_conntrack_helper_reigster: Unable to create slab cache for conntracks\n"); 1296 printk(KERN_ERR "nf_conntrack_helper_reigster: Unable to create slab cache for conntracks\n");
1316 return ret; 1297 return ret;
@@ -1338,9 +1319,12 @@ __nf_conntrack_helper_find_byname(const char *name)
1338static inline int unhelp(struct nf_conntrack_tuple_hash *i, 1319static inline int unhelp(struct nf_conntrack_tuple_hash *i,
1339 const struct nf_conntrack_helper *me) 1320 const struct nf_conntrack_helper *me)
1340{ 1321{
1341 if (nf_ct_tuplehash_to_ctrack(i)->helper == me) { 1322 struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(i);
1342 nf_conntrack_event(IPCT_HELPER, nf_ct_tuplehash_to_ctrack(i)); 1323 struct nf_conn_help *help = nfct_help(ct);
1343 nf_ct_tuplehash_to_ctrack(i)->helper = NULL; 1324
1325 if (help && help->helper == me) {
1326 nf_conntrack_event(IPCT_HELPER, ct);
1327 help->helper = NULL;
1344 } 1328 }
1345 return 0; 1329 return 0;
1346} 1330}
@@ -1356,7 +1340,8 @@ void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me)
1356 1340
1357 /* Get rid of expectations */ 1341 /* Get rid of expectations */
1358 list_for_each_entry_safe(exp, tmp, &nf_conntrack_expect_list, list) { 1342 list_for_each_entry_safe(exp, tmp, &nf_conntrack_expect_list, list) {
1359 if (exp->master->helper == me && del_timer(&exp->timeout)) { 1343 struct nf_conn_help *help = nfct_help(exp->master);
1344 if (help->helper == me && del_timer(&exp->timeout)) {
1360 nf_ct_unlink_expect(exp); 1345 nf_ct_unlink_expect(exp);
1361 nf_conntrack_expect_put(exp); 1346 nf_conntrack_expect_put(exp);
1362 } 1347 }
@@ -1423,6 +1408,8 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,
1423 1408
1424#include <linux/netfilter/nfnetlink.h> 1409#include <linux/netfilter/nfnetlink.h>
1425#include <linux/netfilter/nfnetlink_conntrack.h> 1410#include <linux/netfilter/nfnetlink_conntrack.h>
1411#include <linux/mutex.h>
1412
1426 1413
1427/* Generic function for tcp/udp/sctp/dccp and alike. This needs to be 1414/* Generic function for tcp/udp/sctp/dccp and alike. This needs to be
1428 * in ip_conntrack_core, since we don't want the protocols to autoload 1415 * in ip_conntrack_core, since we don't want the protocols to autoload
@@ -1697,7 +1684,7 @@ int __init nf_conntrack_init(void)
1697 } 1684 }
1698 1685
1699 ret = nf_conntrack_register_cache(NF_CT_F_BASIC, "nf_conntrack:basic", 1686 ret = nf_conntrack_register_cache(NF_CT_F_BASIC, "nf_conntrack:basic",
1700 sizeof(struct nf_conn), NULL); 1687 sizeof(struct nf_conn));
1701 if (ret < 0) { 1688 if (ret < 0) {
1702 printk(KERN_ERR "Unable to create nf_conn slab cache\n"); 1689 printk(KERN_ERR "Unable to create nf_conn slab cache\n");
1703 goto err_free_hash; 1690 goto err_free_hash;
diff --git a/net/netfilter/nf_conntrack_ftp.c b/net/netfilter/nf_conntrack_ftp.c
index 6f210f399762..cd191b0d4ac7 100644
--- a/net/netfilter/nf_conntrack_ftp.c
+++ b/net/netfilter/nf_conntrack_ftp.c
@@ -440,7 +440,7 @@ static int help(struct sk_buff **pskb,
440 u32 seq; 440 u32 seq;
441 int dir = CTINFO2DIR(ctinfo); 441 int dir = CTINFO2DIR(ctinfo);
442 unsigned int matchlen, matchoff; 442 unsigned int matchlen, matchoff;
443 struct ip_ct_ftp_master *ct_ftp_info = &ct->help->ct_ftp_info; 443 struct ip_ct_ftp_master *ct_ftp_info = &nfct_help(ct)->help.ct_ftp_info;
444 struct nf_conntrack_expect *exp; 444 struct nf_conntrack_expect *exp;
445 struct nf_conntrack_man cmd = {}; 445 struct nf_conntrack_man cmd = {};
446 446
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 9ff3463037e1..5eadf009bb15 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -2,7 +2,7 @@
2 * protocol helpers and general trouble making from userspace. 2 * protocol helpers and general trouble making from userspace.
3 * 3 *
4 * (C) 2001 by Jay Schulist <jschlst@samba.org> 4 * (C) 2001 by Jay Schulist <jschlst@samba.org>
5 * (C) 2002-2005 by Harald Welte <laforge@gnumonks.org> 5 * (C) 2002-2006 by Harald Welte <laforge@gnumonks.org>
6 * (C) 2003 by Patrick Mchardy <kaber@trash.net> 6 * (C) 2003 by Patrick Mchardy <kaber@trash.net>
7 * (C) 2005 by Pablo Neira Ayuso <pablo@eurodev.net> 7 * (C) 2005 by Pablo Neira Ayuso <pablo@eurodev.net>
8 * 8 *
@@ -44,7 +44,7 @@
44 44
45MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
46 46
47static char __initdata version[] = "0.92"; 47static char __initdata version[] = "0.93";
48 48
49#if 0 49#if 0
50#define DEBUGP printk 50#define DEBUGP printk
@@ -165,15 +165,16 @@ static inline int
165ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct nf_conn *ct) 165ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct nf_conn *ct)
166{ 166{
167 struct nfattr *nest_helper; 167 struct nfattr *nest_helper;
168 const struct nf_conn_help *help = nfct_help(ct);
168 169
169 if (!ct->helper) 170 if (!help || !help->helper)
170 return 0; 171 return 0;
171 172
172 nest_helper = NFA_NEST(skb, CTA_HELP); 173 nest_helper = NFA_NEST(skb, CTA_HELP);
173 NFA_PUT(skb, CTA_HELP_NAME, strlen(ct->helper->name), ct->helper->name); 174 NFA_PUT(skb, CTA_HELP_NAME, strlen(help->helper->name), help->helper->name);
174 175
175 if (ct->helper->to_nfattr) 176 if (help->helper->to_nfattr)
176 ct->helper->to_nfattr(skb, ct); 177 help->helper->to_nfattr(skb, ct);
177 178
178 NFA_NEST_END(skb, nest_helper); 179 NFA_NEST_END(skb, nest_helper);
179 180
@@ -337,9 +338,10 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
337 group = NFNLGRP_CONNTRACK_UPDATE; 338 group = NFNLGRP_CONNTRACK_UPDATE;
338 } else 339 } else
339 return NOTIFY_DONE; 340 return NOTIFY_DONE;
340 341
341 /* FIXME: Check if there are any listeners before, don't hurt performance */ 342 if (!nfnetlink_has_listeners(group))
342 343 return NOTIFY_DONE;
344
343 skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC); 345 skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
344 if (!skb) 346 if (!skb)
345 return NOTIFY_DONE; 347 return NOTIFY_DONE;
@@ -903,11 +905,17 @@ static inline int
903ctnetlink_change_helper(struct nf_conn *ct, struct nfattr *cda[]) 905ctnetlink_change_helper(struct nf_conn *ct, struct nfattr *cda[])
904{ 906{
905 struct nf_conntrack_helper *helper; 907 struct nf_conntrack_helper *helper;
908 struct nf_conn_help *help = nfct_help(ct);
906 char *helpname; 909 char *helpname;
907 int err; 910 int err;
908 911
909 DEBUGP("entered %s\n", __FUNCTION__); 912 DEBUGP("entered %s\n", __FUNCTION__);
910 913
914 if (!help) {
915 /* FIXME: we need to reallocate and rehash */
916 return -EBUSY;
917 }
918
911 /* don't change helper of sibling connections */ 919 /* don't change helper of sibling connections */
912 if (ct->master) 920 if (ct->master)
913 return -EINVAL; 921 return -EINVAL;
@@ -924,18 +932,18 @@ ctnetlink_change_helper(struct nf_conn *ct, struct nfattr *cda[])
924 return -EINVAL; 932 return -EINVAL;
925 } 933 }
926 934
927 if (ct->helper) { 935 if (help->helper) {
928 if (!helper) { 936 if (!helper) {
929 /* we had a helper before ... */ 937 /* we had a helper before ... */
930 nf_ct_remove_expectations(ct); 938 nf_ct_remove_expectations(ct);
931 ct->helper = NULL; 939 help->helper = NULL;
932 } else { 940 } else {
933 /* need to zero data of old helper */ 941 /* need to zero data of old helper */
934 memset(&ct->help, 0, sizeof(ct->help)); 942 memset(&help->help, 0, sizeof(help->help));
935 } 943 }
936 } 944 }
937 945
938 ct->helper = helper; 946 help->helper = helper;
939 947
940 return 0; 948 return 0;
941} 949}
@@ -1050,14 +1058,9 @@ ctnetlink_create_conntrack(struct nfattr *cda[],
1050 ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1])); 1058 ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
1051#endif 1059#endif
1052 1060
1053 ct->helper = nf_ct_helper_find_get(rtuple);
1054
1055 add_timer(&ct->timeout); 1061 add_timer(&ct->timeout);
1056 nf_conntrack_hash_insert(ct); 1062 nf_conntrack_hash_insert(ct);
1057 1063
1058 if (ct->helper)
1059 nf_ct_helper_put(ct->helper);
1060
1061 DEBUGP("conntrack with id %u inserted\n", ct->id); 1064 DEBUGP("conntrack with id %u inserted\n", ct->id);
1062 return 0; 1065 return 0;
1063 1066
@@ -1417,7 +1420,8 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
1417 } 1420 }
1418 list_for_each_entry_safe(exp, tmp, &nf_conntrack_expect_list, 1421 list_for_each_entry_safe(exp, tmp, &nf_conntrack_expect_list,
1419 list) { 1422 list) {
1420 if (exp->master->helper == h 1423 struct nf_conn_help *m_help = nfct_help(exp->master);
1424 if (m_help->helper == h
1421 && del_timer(&exp->timeout)) { 1425 && del_timer(&exp->timeout)) {
1422 nf_ct_unlink_expect(exp); 1426 nf_ct_unlink_expect(exp);
1423 nf_conntrack_expect_put(exp); 1427 nf_conntrack_expect_put(exp);
@@ -1452,6 +1456,7 @@ ctnetlink_create_expect(struct nfattr *cda[], u_int8_t u3)
1452 struct nf_conntrack_tuple_hash *h = NULL; 1456 struct nf_conntrack_tuple_hash *h = NULL;
1453 struct nf_conntrack_expect *exp; 1457 struct nf_conntrack_expect *exp;
1454 struct nf_conn *ct; 1458 struct nf_conn *ct;
1459 struct nf_conn_help *help;
1455 int err = 0; 1460 int err = 0;
1456 1461
1457 DEBUGP("entered %s\n", __FUNCTION__); 1462 DEBUGP("entered %s\n", __FUNCTION__);
@@ -1472,8 +1477,9 @@ ctnetlink_create_expect(struct nfattr *cda[], u_int8_t u3)
1472 if (!h) 1477 if (!h)
1473 return -ENOENT; 1478 return -ENOENT;
1474 ct = nf_ct_tuplehash_to_ctrack(h); 1479 ct = nf_ct_tuplehash_to_ctrack(h);
1480 help = nfct_help(ct);
1475 1481
1476 if (!ct->helper) { 1482 if (!help || !help->helper) {
1477 /* such conntrack hasn't got any helper, abort */ 1483 /* such conntrack hasn't got any helper, abort */
1478 err = -EINVAL; 1484 err = -EINVAL;
1479 goto out; 1485 goto out;
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index 617599aeeead..290d5a0c559b 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -839,7 +839,6 @@ EXPORT_SYMBOL(nf_conntrack_l3proto_unregister);
839EXPORT_SYMBOL(nf_conntrack_protocol_register); 839EXPORT_SYMBOL(nf_conntrack_protocol_register);
840EXPORT_SYMBOL(nf_conntrack_protocol_unregister); 840EXPORT_SYMBOL(nf_conntrack_protocol_unregister);
841EXPORT_SYMBOL(nf_ct_invert_tuplepr); 841EXPORT_SYMBOL(nf_ct_invert_tuplepr);
842EXPORT_SYMBOL(nf_conntrack_alter_reply);
843EXPORT_SYMBOL(nf_conntrack_destroyed); 842EXPORT_SYMBOL(nf_conntrack_destroyed);
844EXPORT_SYMBOL(need_conntrack); 843EXPORT_SYMBOL(need_conntrack);
845EXPORT_SYMBOL(nf_conntrack_helper_register); 844EXPORT_SYMBOL(nf_conntrack_helper_register);
diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
index 61a833a9caa6..0a63d7dac7be 100644
--- a/net/netfilter/nf_sockopt.c
+++ b/net/netfilter/nf_sockopt.c
@@ -4,6 +4,7 @@
4#include <linux/module.h> 4#include <linux/module.h>
5#include <linux/skbuff.h> 5#include <linux/skbuff.h>
6#include <linux/netfilter.h> 6#include <linux/netfilter.h>
7#include <linux/mutex.h>
7#include <net/sock.h> 8#include <net/sock.h>
8 9
9#include "nf_internals.h" 10#include "nf_internals.h"
@@ -11,7 +12,7 @@
11/* Sockopts only registered and called from user context, so 12/* Sockopts only registered and called from user context, so
12 net locking would be overkill. Also, [gs]etsockopt calls may 13 net locking would be overkill. Also, [gs]etsockopt calls may
13 sleep. */ 14 sleep. */
14static DECLARE_MUTEX(nf_sockopt_mutex); 15static DEFINE_MUTEX(nf_sockopt_mutex);
15static LIST_HEAD(nf_sockopts); 16static LIST_HEAD(nf_sockopts);
16 17
17/* Do exclusive ranges overlap? */ 18/* Do exclusive ranges overlap? */
@@ -26,7 +27,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
26 struct list_head *i; 27 struct list_head *i;
27 int ret = 0; 28 int ret = 0;
28 29
29 if (down_interruptible(&nf_sockopt_mutex) != 0) 30 if (mutex_lock_interruptible(&nf_sockopt_mutex) != 0)
30 return -EINTR; 31 return -EINTR;
31 32
32 list_for_each(i, &nf_sockopts) { 33 list_for_each(i, &nf_sockopts) {
@@ -48,7 +49,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
48 49
49 list_add(&reg->list, &nf_sockopts); 50 list_add(&reg->list, &nf_sockopts);
50out: 51out:
51 up(&nf_sockopt_mutex); 52 mutex_unlock(&nf_sockopt_mutex);
52 return ret; 53 return ret;
53} 54}
54EXPORT_SYMBOL(nf_register_sockopt); 55EXPORT_SYMBOL(nf_register_sockopt);
@@ -57,18 +58,18 @@ void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
57{ 58{
58 /* No point being interruptible: we're probably in cleanup_module() */ 59 /* No point being interruptible: we're probably in cleanup_module() */
59 restart: 60 restart:
60 down(&nf_sockopt_mutex); 61 mutex_lock(&nf_sockopt_mutex);
61 if (reg->use != 0) { 62 if (reg->use != 0) {
62 /* To be woken by nf_sockopt call... */ 63 /* To be woken by nf_sockopt call... */
63 /* FIXME: Stuart Young's name appears gratuitously. */ 64 /* FIXME: Stuart Young's name appears gratuitously. */
64 set_current_state(TASK_UNINTERRUPTIBLE); 65 set_current_state(TASK_UNINTERRUPTIBLE);
65 reg->cleanup_task = current; 66 reg->cleanup_task = current;
66 up(&nf_sockopt_mutex); 67 mutex_unlock(&nf_sockopt_mutex);
67 schedule(); 68 schedule();
68 goto restart; 69 goto restart;
69 } 70 }
70 list_del(&reg->list); 71 list_del(&reg->list);
71 up(&nf_sockopt_mutex); 72 mutex_unlock(&nf_sockopt_mutex);
72} 73}
73EXPORT_SYMBOL(nf_unregister_sockopt); 74EXPORT_SYMBOL(nf_unregister_sockopt);
74 75
@@ -80,7 +81,7 @@ static int nf_sockopt(struct sock *sk, int pf, int val,
80 struct nf_sockopt_ops *ops; 81 struct nf_sockopt_ops *ops;
81 int ret; 82 int ret;
82 83
83 if (down_interruptible(&nf_sockopt_mutex) != 0) 84 if (mutex_lock_interruptible(&nf_sockopt_mutex) != 0)
84 return -EINTR; 85 return -EINTR;
85 86
86 list_for_each(i, &nf_sockopts) { 87 list_for_each(i, &nf_sockopts) {
@@ -90,7 +91,7 @@ static int nf_sockopt(struct sock *sk, int pf, int val,
90 if (val >= ops->get_optmin 91 if (val >= ops->get_optmin
91 && val < ops->get_optmax) { 92 && val < ops->get_optmax) {
92 ops->use++; 93 ops->use++;
93 up(&nf_sockopt_mutex); 94 mutex_unlock(&nf_sockopt_mutex);
94 ret = ops->get(sk, val, opt, len); 95 ret = ops->get(sk, val, opt, len);
95 goto out; 96 goto out;
96 } 97 }
@@ -98,22 +99,22 @@ static int nf_sockopt(struct sock *sk, int pf, int val,
98 if (val >= ops->set_optmin 99 if (val >= ops->set_optmin
99 && val < ops->set_optmax) { 100 && val < ops->set_optmax) {
100 ops->use++; 101 ops->use++;
101 up(&nf_sockopt_mutex); 102 mutex_unlock(&nf_sockopt_mutex);
102 ret = ops->set(sk, val, opt, *len); 103 ret = ops->set(sk, val, opt, *len);
103 goto out; 104 goto out;
104 } 105 }
105 } 106 }
106 } 107 }
107 } 108 }
108 up(&nf_sockopt_mutex); 109 mutex_unlock(&nf_sockopt_mutex);
109 return -ENOPROTOOPT; 110 return -ENOPROTOOPT;
110 111
111 out: 112 out:
112 down(&nf_sockopt_mutex); 113 mutex_lock(&nf_sockopt_mutex);
113 ops->use--; 114 ops->use--;
114 if (ops->cleanup_task) 115 if (ops->cleanup_task)
115 wake_up_process(ops->cleanup_task); 116 wake_up_process(ops->cleanup_task);
116 up(&nf_sockopt_mutex); 117 mutex_unlock(&nf_sockopt_mutex);
117 return ret; 118 return ret;
118} 119}
119 120
@@ -130,3 +131,72 @@ int nf_getsockopt(struct sock *sk, int pf, int val, char __user *opt, int *len)
130} 131}
131EXPORT_SYMBOL(nf_getsockopt); 132EXPORT_SYMBOL(nf_getsockopt);
132 133
134#ifdef CONFIG_COMPAT
135static int compat_nf_sockopt(struct sock *sk, int pf, int val,
136 char __user *opt, int *len, int get)
137{
138 struct list_head *i;
139 struct nf_sockopt_ops *ops;
140 int ret;
141
142 if (mutex_lock_interruptible(&nf_sockopt_mutex) != 0)
143 return -EINTR;
144
145 list_for_each(i, &nf_sockopts) {
146 ops = (struct nf_sockopt_ops *)i;
147 if (ops->pf == pf) {
148 if (get) {
149 if (val >= ops->get_optmin
150 && val < ops->get_optmax) {
151 ops->use++;
152 mutex_unlock(&nf_sockopt_mutex);
153 if (ops->compat_get)
154 ret = ops->compat_get(sk,
155 val, opt, len);
156 else
157 ret = ops->get(sk,
158 val, opt, len);
159 goto out;
160 }
161 } else {
162 if (val >= ops->set_optmin
163 && val < ops->set_optmax) {
164 ops->use++;
165 mutex_unlock(&nf_sockopt_mutex);
166 if (ops->compat_set)
167 ret = ops->compat_set(sk,
168 val, opt, *len);
169 else
170 ret = ops->set(sk,
171 val, opt, *len);
172 goto out;
173 }
174 }
175 }
176 }
177 mutex_unlock(&nf_sockopt_mutex);
178 return -ENOPROTOOPT;
179
180 out:
181 mutex_lock(&nf_sockopt_mutex);
182 ops->use--;
183 if (ops->cleanup_task)
184 wake_up_process(ops->cleanup_task);
185 mutex_unlock(&nf_sockopt_mutex);
186 return ret;
187}
188
189int compat_nf_setsockopt(struct sock *sk, int pf,
190 int val, char __user *opt, int len)
191{
192 return compat_nf_sockopt(sk, pf, val, opt, &len, 0);
193}
194EXPORT_SYMBOL(compat_nf_setsockopt);
195
196int compat_nf_getsockopt(struct sock *sk, int pf,
197 int val, char __user *opt, int *len)
198{
199 return compat_nf_sockopt(sk, pf, val, opt, len, 1);
200}
201EXPORT_SYMBOL(compat_nf_getsockopt);
202#endif
diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
index f6063e8f0050..b88e82a1a987 100644
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -191,6 +191,12 @@ nfnetlink_check_attributes(struct nfnetlink_subsystem *subsys,
191 return 0; 191 return 0;
192} 192}
193 193
194int nfnetlink_has_listeners(unsigned int group)
195{
196 return netlink_has_listeners(nfnl, group);
197}
198EXPORT_SYMBOL_GPL(nfnetlink_has_listeners);
199
194int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, int echo) 200int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, int echo)
195{ 201{
196 gfp_t allocation = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL; 202 gfp_t allocation = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index 3b3c781b40c0..54cbbaa712dc 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -11,6 +11,10 @@
11 * it under the terms of the GNU General Public License version 2 as 11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. 12 * published by the Free Software Foundation.
13 * 13 *
14 * 2006-01-26 Harald Welte <laforge@netfilter.org>
15 * - Add optional local and global sequence number to detect lost
16 * events from userspace
17 *
14 */ 18 */
15#include <linux/module.h> 19#include <linux/module.h>
16#include <linux/skbuff.h> 20#include <linux/skbuff.h>
@@ -68,11 +72,14 @@ struct nfulnl_instance {
68 unsigned int nlbufsiz; /* netlink buffer allocation size */ 72 unsigned int nlbufsiz; /* netlink buffer allocation size */
69 unsigned int qthreshold; /* threshold of the queue */ 73 unsigned int qthreshold; /* threshold of the queue */
70 u_int32_t copy_range; 74 u_int32_t copy_range;
75 u_int32_t seq; /* instance-local sequential counter */
71 u_int16_t group_num; /* number of this queue */ 76 u_int16_t group_num; /* number of this queue */
77 u_int16_t flags;
72 u_int8_t copy_mode; 78 u_int8_t copy_mode;
73}; 79};
74 80
75static DEFINE_RWLOCK(instances_lock); 81static DEFINE_RWLOCK(instances_lock);
82static atomic_t global_seq;
76 83
77#define INSTANCE_BUCKETS 16 84#define INSTANCE_BUCKETS 16
78static struct hlist_head instance_table[INSTANCE_BUCKETS]; 85static struct hlist_head instance_table[INSTANCE_BUCKETS];
@@ -310,6 +317,16 @@ nfulnl_set_qthresh(struct nfulnl_instance *inst, u_int32_t qthresh)
310 return 0; 317 return 0;
311} 318}
312 319
320static int
321nfulnl_set_flags(struct nfulnl_instance *inst, u_int16_t flags)
322{
323 spin_lock_bh(&inst->lock);
324 inst->flags = ntohs(flags);
325 spin_unlock_bh(&inst->lock);
326
327 return 0;
328}
329
313static struct sk_buff *nfulnl_alloc_skb(unsigned int inst_size, 330static struct sk_buff *nfulnl_alloc_skb(unsigned int inst_size,
314 unsigned int pkt_size) 331 unsigned int pkt_size)
315{ 332{
@@ -377,6 +394,8 @@ static void nfulnl_timer(unsigned long data)
377 spin_unlock_bh(&inst->lock); 394 spin_unlock_bh(&inst->lock);
378} 395}
379 396
397/* This is an inline function, we don't really care about a long
398 * list of arguments */
380static inline int 399static inline int
381__build_packet_message(struct nfulnl_instance *inst, 400__build_packet_message(struct nfulnl_instance *inst,
382 const struct sk_buff *skb, 401 const struct sk_buff *skb,
@@ -515,6 +534,17 @@ __build_packet_message(struct nfulnl_instance *inst,
515 read_unlock_bh(&skb->sk->sk_callback_lock); 534 read_unlock_bh(&skb->sk->sk_callback_lock);
516 } 535 }
517 536
537 /* local sequence number */
538 if (inst->flags & NFULNL_CFG_F_SEQ) {
539 tmp_uint = htonl(inst->seq++);
540 NFA_PUT(inst->skb, NFULA_SEQ, sizeof(tmp_uint), &tmp_uint);
541 }
542 /* global sequence number */
543 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) {
544 tmp_uint = atomic_inc_return(&global_seq);
545 NFA_PUT(inst->skb, NFULA_SEQ_GLOBAL, sizeof(tmp_uint), &tmp_uint);
546 }
547
518 if (data_len) { 548 if (data_len) {
519 struct nfattr *nfa; 549 struct nfattr *nfa;
520 int size = NFA_LENGTH(data_len); 550 int size = NFA_LENGTH(data_len);
@@ -607,6 +637,11 @@ nfulnl_log_packet(unsigned int pf,
607 637
608 spin_lock_bh(&inst->lock); 638 spin_lock_bh(&inst->lock);
609 639
640 if (inst->flags & NFULNL_CFG_F_SEQ)
641 size += NFA_SPACE(sizeof(u_int32_t));
642 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
643 size += NFA_SPACE(sizeof(u_int32_t));
644
610 qthreshold = inst->qthreshold; 645 qthreshold = inst->qthreshold;
611 /* per-rule qthreshold overrides per-instance */ 646 /* per-rule qthreshold overrides per-instance */
612 if (qthreshold > li->u.ulog.qthreshold) 647 if (qthreshold > li->u.ulog.qthreshold)
@@ -736,10 +771,14 @@ static const int nfula_min[NFULA_MAX] = {
736 [NFULA_TIMESTAMP-1] = sizeof(struct nfulnl_msg_packet_timestamp), 771 [NFULA_TIMESTAMP-1] = sizeof(struct nfulnl_msg_packet_timestamp),
737 [NFULA_IFINDEX_INDEV-1] = sizeof(u_int32_t), 772 [NFULA_IFINDEX_INDEV-1] = sizeof(u_int32_t),
738 [NFULA_IFINDEX_OUTDEV-1]= sizeof(u_int32_t), 773 [NFULA_IFINDEX_OUTDEV-1]= sizeof(u_int32_t),
774 [NFULA_IFINDEX_PHYSINDEV-1] = sizeof(u_int32_t),
775 [NFULA_IFINDEX_PHYSOUTDEV-1] = sizeof(u_int32_t),
739 [NFULA_HWADDR-1] = sizeof(struct nfulnl_msg_packet_hw), 776 [NFULA_HWADDR-1] = sizeof(struct nfulnl_msg_packet_hw),
740 [NFULA_PAYLOAD-1] = 0, 777 [NFULA_PAYLOAD-1] = 0,
741 [NFULA_PREFIX-1] = 0, 778 [NFULA_PREFIX-1] = 0,
742 [NFULA_UID-1] = sizeof(u_int32_t), 779 [NFULA_UID-1] = sizeof(u_int32_t),
780 [NFULA_SEQ-1] = sizeof(u_int32_t),
781 [NFULA_SEQ_GLOBAL-1] = sizeof(u_int32_t),
743}; 782};
744 783
745static const int nfula_cfg_min[NFULA_CFG_MAX] = { 784static const int nfula_cfg_min[NFULA_CFG_MAX] = {
@@ -748,6 +787,7 @@ static const int nfula_cfg_min[NFULA_CFG_MAX] = {
748 [NFULA_CFG_TIMEOUT-1] = sizeof(u_int32_t), 787 [NFULA_CFG_TIMEOUT-1] = sizeof(u_int32_t),
749 [NFULA_CFG_QTHRESH-1] = sizeof(u_int32_t), 788 [NFULA_CFG_QTHRESH-1] = sizeof(u_int32_t),
750 [NFULA_CFG_NLBUFSIZ-1] = sizeof(u_int32_t), 789 [NFULA_CFG_NLBUFSIZ-1] = sizeof(u_int32_t),
790 [NFULA_CFG_FLAGS-1] = sizeof(u_int16_t),
751}; 791};
752 792
753static int 793static int
@@ -859,6 +899,12 @@ nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
859 nfulnl_set_qthresh(inst, ntohl(qthresh)); 899 nfulnl_set_qthresh(inst, ntohl(qthresh));
860 } 900 }
861 901
902 if (nfula[NFULA_CFG_FLAGS-1]) {
903 u_int16_t flags =
904 *(u_int16_t *)NFA_DATA(nfula[NFULA_CFG_FLAGS-1]);
905 nfulnl_set_flags(inst, ntohl(flags));
906 }
907
862out_put: 908out_put:
863 instance_put(inst); 909 instance_put(inst);
864 return ret; 910 return ret;
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index d7817afc6b96..750b92829766 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -52,6 +52,12 @@ enum {
52 MATCH, 52 MATCH,
53}; 53};
54 54
55static const char *xt_prefix[NPROTO] = {
56 [AF_INET] = "ip",
57 [AF_INET6] = "ip6",
58 [NF_ARP] = "arp",
59};
60
55/* Registration hooks for targets. */ 61/* Registration hooks for targets. */
56int 62int
57xt_register_target(int af, struct xt_target *target) 63xt_register_target(int af, struct xt_target *target)
@@ -158,18 +164,12 @@ struct xt_target *xt_find_target(int af, const char *name, u8 revision)
158} 164}
159EXPORT_SYMBOL(xt_find_target); 165EXPORT_SYMBOL(xt_find_target);
160 166
161static const char *xt_prefix[NPROTO] = {
162 [AF_INET] = "ipt_%s",
163 [AF_INET6] = "ip6t_%s",
164 [NF_ARP] = "arpt_%s",
165};
166
167struct xt_target *xt_request_find_target(int af, const char *name, u8 revision) 167struct xt_target *xt_request_find_target(int af, const char *name, u8 revision)
168{ 168{
169 struct xt_target *target; 169 struct xt_target *target;
170 170
171 target = try_then_request_module(xt_find_target(af, name, revision), 171 target = try_then_request_module(xt_find_target(af, name, revision),
172 xt_prefix[af], name); 172 "%st_%s", xt_prefix[af], name);
173 if (IS_ERR(target) || !target) 173 if (IS_ERR(target) || !target)
174 return NULL; 174 return NULL;
175 return target; 175 return target;
@@ -237,6 +237,64 @@ int xt_find_revision(int af, const char *name, u8 revision, int target,
237} 237}
238EXPORT_SYMBOL_GPL(xt_find_revision); 238EXPORT_SYMBOL_GPL(xt_find_revision);
239 239
240int xt_check_match(const struct xt_match *match, unsigned short family,
241 unsigned int size, const char *table, unsigned int hook_mask,
242 unsigned short proto, int inv_proto)
243{
244 if (XT_ALIGN(match->matchsize) != size) {
245 printk("%s_tables: %s match: invalid size %Zu != %u\n",
246 xt_prefix[family], match->name,
247 XT_ALIGN(match->matchsize), size);
248 return -EINVAL;
249 }
250 if (match->table && strcmp(match->table, table)) {
251 printk("%s_tables: %s match: only valid in %s table, not %s\n",
252 xt_prefix[family], match->name, match->table, table);
253 return -EINVAL;
254 }
255 if (match->hooks && (hook_mask & ~match->hooks) != 0) {
256 printk("%s_tables: %s match: bad hook_mask %u\n",
257 xt_prefix[family], match->name, hook_mask);
258 return -EINVAL;
259 }
260 if (match->proto && (match->proto != proto || inv_proto)) {
261 printk("%s_tables: %s match: only valid for protocol %u\n",
262 xt_prefix[family], match->name, match->proto);
263 return -EINVAL;
264 }
265 return 0;
266}
267EXPORT_SYMBOL_GPL(xt_check_match);
268
269int xt_check_target(const struct xt_target *target, unsigned short family,
270 unsigned int size, const char *table, unsigned int hook_mask,
271 unsigned short proto, int inv_proto)
272{
273 if (XT_ALIGN(target->targetsize) != size) {
274 printk("%s_tables: %s target: invalid size %Zu != %u\n",
275 xt_prefix[family], target->name,
276 XT_ALIGN(target->targetsize), size);
277 return -EINVAL;
278 }
279 if (target->table && strcmp(target->table, table)) {
280 printk("%s_tables: %s target: only valid in %s table, not %s\n",
281 xt_prefix[family], target->name, target->table, table);
282 return -EINVAL;
283 }
284 if (target->hooks && (hook_mask & ~target->hooks) != 0) {
285 printk("%s_tables: %s target: bad hook_mask %u\n",
286 xt_prefix[family], target->name, hook_mask);
287 return -EINVAL;
288 }
289 if (target->proto && (target->proto != proto || inv_proto)) {
290 printk("%s_tables: %s target: only valid for protocol %u\n",
291 xt_prefix[family], target->name, target->proto);
292 return -EINVAL;
293 }
294 return 0;
295}
296EXPORT_SYMBOL_GPL(xt_check_target);
297
240struct xt_table_info *xt_alloc_table_info(unsigned int size) 298struct xt_table_info *xt_alloc_table_info(unsigned int size)
241{ 299{
242 struct xt_table_info *newinfo; 300 struct xt_table_info *newinfo;
diff --git a/net/netfilter/xt_CLASSIFY.c b/net/netfilter/xt_CLASSIFY.c
index 78ee266a12ee..3224ed87d4c7 100644
--- a/net/netfilter/xt_CLASSIFY.c
+++ b/net/netfilter/xt_CLASSIFY.c
@@ -28,6 +28,7 @@ target(struct sk_buff **pskb,
28 const struct net_device *in, 28 const struct net_device *in,
29 const struct net_device *out, 29 const struct net_device *out,
30 unsigned int hooknum, 30 unsigned int hooknum,
31 const struct xt_target *target,
31 const void *targinfo, 32 const void *targinfo,
32 void *userinfo) 33 void *userinfo)
33{ 34{
@@ -39,47 +40,22 @@ target(struct sk_buff **pskb,
39 return XT_CONTINUE; 40 return XT_CONTINUE;
40} 41}
41 42
42static int
43checkentry(const char *tablename,
44 const void *e,
45 void *targinfo,
46 unsigned int targinfosize,
47 unsigned int hook_mask)
48{
49 if (targinfosize != XT_ALIGN(sizeof(struct xt_classify_target_info))){
50 printk(KERN_ERR "CLASSIFY: invalid size (%u != %Zu).\n",
51 targinfosize,
52 XT_ALIGN(sizeof(struct xt_classify_target_info)));
53 return 0;
54 }
55
56 if (hook_mask & ~((1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_FORWARD) |
57 (1 << NF_IP_POST_ROUTING))) {
58 printk(KERN_ERR "CLASSIFY: only valid in LOCAL_OUT, FORWARD "
59 "and POST_ROUTING.\n");
60 return 0;
61 }
62
63 if (strcmp(tablename, "mangle") != 0) {
64 printk(KERN_ERR "CLASSIFY: can only be called from "
65 "\"mangle\" table, not \"%s\".\n",
66 tablename);
67 return 0;
68 }
69
70 return 1;
71}
72
73static struct xt_target classify_reg = { 43static struct xt_target classify_reg = {
74 .name = "CLASSIFY", 44 .name = "CLASSIFY",
75 .target = target, 45 .target = target,
76 .checkentry = checkentry, 46 .targetsize = sizeof(struct xt_classify_target_info),
47 .table = "mangle",
48 .hooks = (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_FORWARD) |
49 (1 << NF_IP_POST_ROUTING),
77 .me = THIS_MODULE, 50 .me = THIS_MODULE,
78}; 51};
79static struct xt_target classify6_reg = { 52static struct xt_target classify6_reg = {
80 .name = "CLASSIFY", 53 .name = "CLASSIFY",
81 .target = target, 54 .target = target,
82 .checkentry = checkentry, 55 .targetsize = sizeof(struct xt_classify_target_info),
56 .table = "mangle",
57 .hooks = (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_FORWARD) |
58 (1 << NF_IP_POST_ROUTING),
83 .me = THIS_MODULE, 59 .me = THIS_MODULE,
84}; 60};
85 61
diff --git a/net/netfilter/xt_CONNMARK.c b/net/netfilter/xt_CONNMARK.c
index 22506e376be5..df2486a3efd5 100644
--- a/net/netfilter/xt_CONNMARK.c
+++ b/net/netfilter/xt_CONNMARK.c
@@ -37,6 +37,7 @@ target(struct sk_buff **pskb,
37 const struct net_device *in, 37 const struct net_device *in,
38 const struct net_device *out, 38 const struct net_device *out,
39 unsigned int hooknum, 39 unsigned int hooknum,
40 const struct xt_target *target,
40 const void *targinfo, 41 const void *targinfo,
41 void *userinfo) 42 void *userinfo)
42{ 43{
@@ -74,17 +75,12 @@ target(struct sk_buff **pskb,
74static int 75static int
75checkentry(const char *tablename, 76checkentry(const char *tablename,
76 const void *entry, 77 const void *entry,
78 const struct xt_target *target,
77 void *targinfo, 79 void *targinfo,
78 unsigned int targinfosize, 80 unsigned int targinfosize,
79 unsigned int hook_mask) 81 unsigned int hook_mask)
80{ 82{
81 struct xt_connmark_target_info *matchinfo = targinfo; 83 struct xt_connmark_target_info *matchinfo = targinfo;
82 if (targinfosize != XT_ALIGN(sizeof(struct xt_connmark_target_info))) {
83 printk(KERN_WARNING "CONNMARK: targinfosize %u != %Zu\n",
84 targinfosize,
85 XT_ALIGN(sizeof(struct xt_connmark_target_info)));
86 return 0;
87 }
88 84
89 if (matchinfo->mode == XT_CONNMARK_RESTORE) { 85 if (matchinfo->mode == XT_CONNMARK_RESTORE) {
90 if (strcmp(tablename, "mangle") != 0) { 86 if (strcmp(tablename, "mangle") != 0) {
@@ -102,16 +98,19 @@ checkentry(const char *tablename,
102} 98}
103 99
104static struct xt_target connmark_reg = { 100static struct xt_target connmark_reg = {
105 .name = "CONNMARK", 101 .name = "CONNMARK",
106 .target = &target, 102 .target = target,
107 .checkentry = &checkentry, 103 .targetsize = sizeof(struct xt_connmark_target_info),
108 .me = THIS_MODULE 104 .checkentry = checkentry,
105 .me = THIS_MODULE
109}; 106};
107
110static struct xt_target connmark6_reg = { 108static struct xt_target connmark6_reg = {
111 .name = "CONNMARK", 109 .name = "CONNMARK",
112 .target = &target, 110 .target = target,
113 .checkentry = &checkentry, 111 .targetsize = sizeof(struct xt_connmark_target_info),
114 .me = THIS_MODULE 112 .checkentry = checkentry,
113 .me = THIS_MODULE
115}; 114};
116 115
117static int __init init(void) 116static int __init init(void)
diff --git a/net/netfilter/xt_MARK.c b/net/netfilter/xt_MARK.c
index 0c11ee9550f3..dcb5266efae0 100644
--- a/net/netfilter/xt_MARK.c
+++ b/net/netfilter/xt_MARK.c
@@ -26,6 +26,7 @@ target_v0(struct sk_buff **pskb,
26 const struct net_device *in, 26 const struct net_device *in,
27 const struct net_device *out, 27 const struct net_device *out,
28 unsigned int hooknum, 28 unsigned int hooknum,
29 const struct xt_target *target,
29 const void *targinfo, 30 const void *targinfo,
30 void *userinfo) 31 void *userinfo)
31{ 32{
@@ -42,6 +43,7 @@ target_v1(struct sk_buff **pskb,
42 const struct net_device *in, 43 const struct net_device *in,
43 const struct net_device *out, 44 const struct net_device *out,
44 unsigned int hooknum, 45 unsigned int hooknum,
46 const struct xt_target *target,
45 const void *targinfo, 47 const void *targinfo,
46 void *userinfo) 48 void *userinfo)
47{ 49{
@@ -72,53 +74,30 @@ target_v1(struct sk_buff **pskb,
72static int 74static int
73checkentry_v0(const char *tablename, 75checkentry_v0(const char *tablename,
74 const void *entry, 76 const void *entry,
77 const struct xt_target *target,
75 void *targinfo, 78 void *targinfo,
76 unsigned int targinfosize, 79 unsigned int targinfosize,
77 unsigned int hook_mask) 80 unsigned int hook_mask)
78{ 81{
79 struct xt_mark_target_info *markinfo = targinfo; 82 struct xt_mark_target_info *markinfo = targinfo;
80 83
81 if (targinfosize != XT_ALIGN(sizeof(struct xt_mark_target_info))) {
82 printk(KERN_WARNING "MARK: targinfosize %u != %Zu\n",
83 targinfosize,
84 XT_ALIGN(sizeof(struct xt_mark_target_info)));
85 return 0;
86 }
87
88 if (strcmp(tablename, "mangle") != 0) {
89 printk(KERN_WARNING "MARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
90 return 0;
91 }
92
93 if (markinfo->mark > 0xffffffff) { 84 if (markinfo->mark > 0xffffffff) {
94 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n"); 85 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
95 return 0; 86 return 0;
96 } 87 }
97
98 return 1; 88 return 1;
99} 89}
100 90
101static int 91static int
102checkentry_v1(const char *tablename, 92checkentry_v1(const char *tablename,
103 const void *entry, 93 const void *entry,
94 const struct xt_target *target,
104 void *targinfo, 95 void *targinfo,
105 unsigned int targinfosize, 96 unsigned int targinfosize,
106 unsigned int hook_mask) 97 unsigned int hook_mask)
107{ 98{
108 struct xt_mark_target_info_v1 *markinfo = targinfo; 99 struct xt_mark_target_info_v1 *markinfo = targinfo;
109 100
110 if (targinfosize != XT_ALIGN(sizeof(struct xt_mark_target_info_v1))){
111 printk(KERN_WARNING "MARK: targinfosize %u != %Zu\n",
112 targinfosize,
113 XT_ALIGN(sizeof(struct xt_mark_target_info_v1)));
114 return 0;
115 }
116
117 if (strcmp(tablename, "mangle") != 0) {
118 printk(KERN_WARNING "MARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
119 return 0;
120 }
121
122 if (markinfo->mode != XT_MARK_SET 101 if (markinfo->mode != XT_MARK_SET
123 && markinfo->mode != XT_MARK_AND 102 && markinfo->mode != XT_MARK_AND
124 && markinfo->mode != XT_MARK_OR) { 103 && markinfo->mode != XT_MARK_OR) {
@@ -126,18 +105,18 @@ checkentry_v1(const char *tablename,
126 markinfo->mode); 105 markinfo->mode);
127 return 0; 106 return 0;
128 } 107 }
129
130 if (markinfo->mark > 0xffffffff) { 108 if (markinfo->mark > 0xffffffff) {
131 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n"); 109 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
132 return 0; 110 return 0;
133 } 111 }
134
135 return 1; 112 return 1;
136} 113}
137 114
138static struct xt_target ipt_mark_reg_v0 = { 115static struct xt_target ipt_mark_reg_v0 = {
139 .name = "MARK", 116 .name = "MARK",
140 .target = target_v0, 117 .target = target_v0,
118 .targetsize = sizeof(struct xt_mark_target_info),
119 .table = "mangle",
141 .checkentry = checkentry_v0, 120 .checkentry = checkentry_v0,
142 .me = THIS_MODULE, 121 .me = THIS_MODULE,
143 .revision = 0, 122 .revision = 0,
@@ -146,6 +125,8 @@ static struct xt_target ipt_mark_reg_v0 = {
146static struct xt_target ipt_mark_reg_v1 = { 125static struct xt_target ipt_mark_reg_v1 = {
147 .name = "MARK", 126 .name = "MARK",
148 .target = target_v1, 127 .target = target_v1,
128 .targetsize = sizeof(struct xt_mark_target_info_v1),
129 .table = "mangle",
149 .checkentry = checkentry_v1, 130 .checkentry = checkentry_v1,
150 .me = THIS_MODULE, 131 .me = THIS_MODULE,
151 .revision = 1, 132 .revision = 1,
@@ -154,6 +135,8 @@ static struct xt_target ipt_mark_reg_v1 = {
154static struct xt_target ip6t_mark_reg_v0 = { 135static struct xt_target ip6t_mark_reg_v0 = {
155 .name = "MARK", 136 .name = "MARK",
156 .target = target_v0, 137 .target = target_v0,
138 .targetsize = sizeof(struct xt_mark_target_info),
139 .table = "mangle",
157 .checkentry = checkentry_v0, 140 .checkentry = checkentry_v0,
158 .me = THIS_MODULE, 141 .me = THIS_MODULE,
159 .revision = 0, 142 .revision = 0,
diff --git a/net/netfilter/xt_NFQUEUE.c b/net/netfilter/xt_NFQUEUE.c
index 8b76b6f8d1e4..39a963edf16b 100644
--- a/net/netfilter/xt_NFQUEUE.c
+++ b/net/netfilter/xt_NFQUEUE.c
@@ -28,6 +28,7 @@ target(struct sk_buff **pskb,
28 const struct net_device *in, 28 const struct net_device *in,
29 const struct net_device *out, 29 const struct net_device *out,
30 unsigned int hooknum, 30 unsigned int hooknum,
31 const struct xt_target *target,
31 const void *targinfo, 32 const void *targinfo,
32 void *userinfo) 33 void *userinfo)
33{ 34{
@@ -36,41 +37,24 @@ target(struct sk_buff **pskb,
36 return NF_QUEUE_NR(tinfo->queuenum); 37 return NF_QUEUE_NR(tinfo->queuenum);
37} 38}
38 39
39static int
40checkentry(const char *tablename,
41 const void *entry,
42 void *targinfo,
43 unsigned int targinfosize,
44 unsigned int hook_mask)
45{
46 if (targinfosize != XT_ALIGN(sizeof(struct xt_NFQ_info))) {
47 printk(KERN_WARNING "NFQUEUE: targinfosize %u != %Zu\n",
48 targinfosize,
49 XT_ALIGN(sizeof(struct xt_NFQ_info)));
50 return 0;
51 }
52
53 return 1;
54}
55
56static struct xt_target ipt_NFQ_reg = { 40static struct xt_target ipt_NFQ_reg = {
57 .name = "NFQUEUE", 41 .name = "NFQUEUE",
58 .target = target, 42 .target = target,
59 .checkentry = checkentry, 43 .targetsize = sizeof(struct xt_NFQ_info),
60 .me = THIS_MODULE, 44 .me = THIS_MODULE,
61}; 45};
62 46
63static struct xt_target ip6t_NFQ_reg = { 47static struct xt_target ip6t_NFQ_reg = {
64 .name = "NFQUEUE", 48 .name = "NFQUEUE",
65 .target = target, 49 .target = target,
66 .checkentry = checkentry, 50 .targetsize = sizeof(struct xt_NFQ_info),
67 .me = THIS_MODULE, 51 .me = THIS_MODULE,
68}; 52};
69 53
70static struct xt_target arpt_NFQ_reg = { 54static struct xt_target arpt_NFQ_reg = {
71 .name = "NFQUEUE", 55 .name = "NFQUEUE",
72 .target = target, 56 .target = target,
73 .checkentry = checkentry, 57 .targetsize = sizeof(struct xt_NFQ_info),
74 .me = THIS_MODULE, 58 .me = THIS_MODULE,
75}; 59};
76 60
diff --git a/net/netfilter/xt_NOTRACK.c b/net/netfilter/xt_NOTRACK.c
index 24d477afa939..b8634e3f6169 100644
--- a/net/netfilter/xt_NOTRACK.c
+++ b/net/netfilter/xt_NOTRACK.c
@@ -15,6 +15,7 @@ target(struct sk_buff **pskb,
15 const struct net_device *in, 15 const struct net_device *in,
16 const struct net_device *out, 16 const struct net_device *out,
17 unsigned int hooknum, 17 unsigned int hooknum,
18 const struct xt_target *target,
18 const void *targinfo, 19 const void *targinfo,
19 void *userinfo) 20 void *userinfo)
20{ 21{
@@ -33,38 +34,20 @@ target(struct sk_buff **pskb,
33 return XT_CONTINUE; 34 return XT_CONTINUE;
34} 35}
35 36
36static int 37static struct xt_target notrack_reg = {
37checkentry(const char *tablename, 38 .name = "NOTRACK",
38 const void *entry, 39 .target = target,
39 void *targinfo, 40 .targetsize = 0,
40 unsigned int targinfosize, 41 .table = "raw",
41 unsigned int hook_mask) 42 .me = THIS_MODULE,
42{
43 if (targinfosize != 0) {
44 printk(KERN_WARNING "NOTRACK: targinfosize %u != 0\n",
45 targinfosize);
46 return 0;
47 }
48
49 if (strcmp(tablename, "raw") != 0) {
50 printk(KERN_WARNING "NOTRACK: can only be called from \"raw\" table, not \"%s\"\n", tablename);
51 return 0;
52 }
53
54 return 1;
55}
56
57static struct xt_target notrack_reg = {
58 .name = "NOTRACK",
59 .target = target,
60 .checkentry = checkentry,
61 .me = THIS_MODULE,
62}; 43};
63static struct xt_target notrack6_reg = { 44
64 .name = "NOTRACK", 45static struct xt_target notrack6_reg = {
65 .target = target, 46 .name = "NOTRACK",
66 .checkentry = checkentry, 47 .target = target,
67 .me = THIS_MODULE, 48 .targetsize = 0,
49 .table = "raw",
50 .me = THIS_MODULE,
68}; 51};
69 52
70static int __init init(void) 53static int __init init(void)
diff --git a/net/netfilter/xt_comment.c b/net/netfilter/xt_comment.c
index 4ba6fd65c6e9..03d9d741231c 100644
--- a/net/netfilter/xt_comment.c
+++ b/net/netfilter/xt_comment.c
@@ -19,6 +19,7 @@ static int
19match(const struct sk_buff *skb, 19match(const struct sk_buff *skb,
20 const struct net_device *in, 20 const struct net_device *in,
21 const struct net_device *out, 21 const struct net_device *out,
22 const struct xt_match *match,
22 const void *matchinfo, 23 const void *matchinfo,
23 int offset, 24 int offset,
24 unsigned int protooff, 25 unsigned int protooff,
@@ -28,30 +29,17 @@ match(const struct sk_buff *skb,
28 return 1; 29 return 1;
29} 30}
30 31
31static int
32checkentry(const char *tablename,
33 const void *ip,
34 void *matchinfo,
35 unsigned int matchsize,
36 unsigned int hook_mask)
37{
38 /* Check the size */
39 if (matchsize != XT_ALIGN(sizeof(struct xt_comment_info)))
40 return 0;
41 return 1;
42}
43
44static struct xt_match comment_match = { 32static struct xt_match comment_match = {
45 .name = "comment", 33 .name = "comment",
46 .match = match, 34 .match = match,
47 .checkentry = checkentry, 35 .matchsize = sizeof(struct xt_comment_info),
48 .me = THIS_MODULE 36 .me = THIS_MODULE
49}; 37};
50 38
51static struct xt_match comment6_match = { 39static struct xt_match comment6_match = {
52 .name = "comment", 40 .name = "comment",
53 .match = match, 41 .match = match,
54 .checkentry = checkentry, 42 .matchsize = sizeof(struct xt_comment_info),
55 .me = THIS_MODULE 43 .me = THIS_MODULE
56}; 44};
57 45
diff --git a/net/netfilter/xt_connbytes.c b/net/netfilter/xt_connbytes.c
index 150d2a4b0f71..f34ecb9485c7 100644
--- a/net/netfilter/xt_connbytes.c
+++ b/net/netfilter/xt_connbytes.c
@@ -44,6 +44,7 @@ static int
44match(const struct sk_buff *skb, 44match(const struct sk_buff *skb,
45 const struct net_device *in, 45 const struct net_device *in,
46 const struct net_device *out, 46 const struct net_device *out,
47 const struct xt_match *match,
47 const void *matchinfo, 48 const void *matchinfo,
48 int offset, 49 int offset,
49 unsigned int protoff, 50 unsigned int protoff,
@@ -122,15 +123,13 @@ match(const struct sk_buff *skb,
122 123
123static int check(const char *tablename, 124static int check(const char *tablename,
124 const void *ip, 125 const void *ip,
126 const struct xt_match *match,
125 void *matchinfo, 127 void *matchinfo,
126 unsigned int matchsize, 128 unsigned int matchsize,
127 unsigned int hook_mask) 129 unsigned int hook_mask)
128{ 130{
129 const struct xt_connbytes_info *sinfo = matchinfo; 131 const struct xt_connbytes_info *sinfo = matchinfo;
130 132
131 if (matchsize != XT_ALIGN(sizeof(struct xt_connbytes_info)))
132 return 0;
133
134 if (sinfo->what != XT_CONNBYTES_PKTS && 133 if (sinfo->what != XT_CONNBYTES_PKTS &&
135 sinfo->what != XT_CONNBYTES_BYTES && 134 sinfo->what != XT_CONNBYTES_BYTES &&
136 sinfo->what != XT_CONNBYTES_AVGPKT) 135 sinfo->what != XT_CONNBYTES_AVGPKT)
@@ -146,14 +145,16 @@ static int check(const char *tablename,
146 145
147static struct xt_match connbytes_match = { 146static struct xt_match connbytes_match = {
148 .name = "connbytes", 147 .name = "connbytes",
149 .match = &match, 148 .match = match,
150 .checkentry = &check, 149 .checkentry = check,
150 .matchsize = sizeof(struct xt_connbytes_info),
151 .me = THIS_MODULE 151 .me = THIS_MODULE
152}; 152};
153static struct xt_match connbytes6_match = { 153static struct xt_match connbytes6_match = {
154 .name = "connbytes", 154 .name = "connbytes",
155 .match = &match, 155 .match = match,
156 .checkentry = &check, 156 .checkentry = check,
157 .matchsize = sizeof(struct xt_connbytes_info),
157 .me = THIS_MODULE 158 .me = THIS_MODULE
158}; 159};
159 160
diff --git a/net/netfilter/xt_connmark.c b/net/netfilter/xt_connmark.c
index d06e925032da..51822471e919 100644
--- a/net/netfilter/xt_connmark.c
+++ b/net/netfilter/xt_connmark.c
@@ -35,6 +35,7 @@ static int
35match(const struct sk_buff *skb, 35match(const struct sk_buff *skb,
36 const struct net_device *in, 36 const struct net_device *in,
37 const struct net_device *out, 37 const struct net_device *out,
38 const struct xt_match *match,
38 const void *matchinfo, 39 const void *matchinfo,
39 int offset, 40 int offset,
40 unsigned int protoff, 41 unsigned int protoff,
@@ -52,37 +53,36 @@ match(const struct sk_buff *skb,
52static int 53static int
53checkentry(const char *tablename, 54checkentry(const char *tablename,
54 const void *ip, 55 const void *ip,
56 const struct xt_match *match,
55 void *matchinfo, 57 void *matchinfo,
56 unsigned int matchsize, 58 unsigned int matchsize,
57 unsigned int hook_mask) 59 unsigned int hook_mask)
58{ 60{
59 struct xt_connmark_info *cm = 61 struct xt_connmark_info *cm = (struct xt_connmark_info *)matchinfo;
60 (struct xt_connmark_info *)matchinfo;
61 if (matchsize != XT_ALIGN(sizeof(struct xt_connmark_info)))
62 return 0;
63 62
64 if (cm->mark > 0xffffffff || cm->mask > 0xffffffff) { 63 if (cm->mark > 0xffffffff || cm->mask > 0xffffffff) {
65 printk(KERN_WARNING "connmark: only support 32bit mark\n"); 64 printk(KERN_WARNING "connmark: only support 32bit mark\n");
66 return 0; 65 return 0;
67 } 66 }
68
69 return 1; 67 return 1;
70} 68}
71 69
72static struct xt_match connmark_match = { 70static struct xt_match connmark_match = {
73 .name = "connmark", 71 .name = "connmark",
74 .match = &match, 72 .match = match,
75 .checkentry = &checkentry, 73 .matchsize = sizeof(struct xt_connmark_info),
76 .me = THIS_MODULE 74 .checkentry = checkentry,
75 .me = THIS_MODULE
77}; 76};
77
78static struct xt_match connmark6_match = { 78static struct xt_match connmark6_match = {
79 .name = "connmark", 79 .name = "connmark",
80 .match = &match, 80 .match = match,
81 .checkentry = &checkentry, 81 .matchsize = sizeof(struct xt_connmark_info),
82 .me = THIS_MODULE 82 .checkentry = checkentry,
83 .me = THIS_MODULE
83}; 84};
84 85
85
86static int __init init(void) 86static int __init init(void)
87{ 87{
88 int ret; 88 int ret;
diff --git a/net/netfilter/xt_conntrack.c b/net/netfilter/xt_conntrack.c
index ffdebc95eb95..39fc29496e00 100644
--- a/net/netfilter/xt_conntrack.c
+++ b/net/netfilter/xt_conntrack.c
@@ -32,6 +32,7 @@ static int
32match(const struct sk_buff *skb, 32match(const struct sk_buff *skb,
33 const struct net_device *in, 33 const struct net_device *in,
34 const struct net_device *out, 34 const struct net_device *out,
35 const struct xt_match *match,
35 const void *matchinfo, 36 const void *matchinfo,
36 int offset, 37 int offset,
37 unsigned int protoff, 38 unsigned int protoff,
@@ -118,6 +119,7 @@ static int
118match(const struct sk_buff *skb, 119match(const struct sk_buff *skb,
119 const struct net_device *in, 120 const struct net_device *in,
120 const struct net_device *out, 121 const struct net_device *out,
122 const struct xt_match *match,
121 const void *matchinfo, 123 const void *matchinfo,
122 int offset, 124 int offset,
123 unsigned int protoff, 125 unsigned int protoff,
@@ -201,22 +203,10 @@ match(const struct sk_buff *skb,
201 203
202#endif /* CONFIG_NF_IP_CONNTRACK */ 204#endif /* CONFIG_NF_IP_CONNTRACK */
203 205
204static int check(const char *tablename,
205 const void *ip,
206 void *matchinfo,
207 unsigned int matchsize,
208 unsigned int hook_mask)
209{
210 if (matchsize != XT_ALIGN(sizeof(struct xt_conntrack_info)))
211 return 0;
212
213 return 1;
214}
215
216static struct xt_match conntrack_match = { 206static struct xt_match conntrack_match = {
217 .name = "conntrack", 207 .name = "conntrack",
218 .match = &match, 208 .match = match,
219 .checkentry = &check, 209 .matchsize = sizeof(struct xt_conntrack_info),
220 .me = THIS_MODULE, 210 .me = THIS_MODULE,
221}; 211};
222 212
diff --git a/net/netfilter/xt_dccp.c b/net/netfilter/xt_dccp.c
index 779f42fc9524..db6b70cdc770 100644
--- a/net/netfilter/xt_dccp.c
+++ b/net/netfilter/xt_dccp.c
@@ -95,6 +95,7 @@ static int
95match(const struct sk_buff *skb, 95match(const struct sk_buff *skb,
96 const struct net_device *in, 96 const struct net_device *in,
97 const struct net_device *out, 97 const struct net_device *out,
98 const struct xt_match *match,
98 const void *matchinfo, 99 const void *matchinfo,
99 int offset, 100 int offset,
100 unsigned int protoff, 101 unsigned int protoff,
@@ -129,56 +130,34 @@ match(const struct sk_buff *skb,
129static int 130static int
130checkentry(const char *tablename, 131checkentry(const char *tablename,
131 const void *inf, 132 const void *inf,
133 const struct xt_match *match,
132 void *matchinfo, 134 void *matchinfo,
133 unsigned int matchsize, 135 unsigned int matchsize,
134 unsigned int hook_mask) 136 unsigned int hook_mask)
135{ 137{
136 const struct ipt_ip *ip = inf; 138 const struct xt_dccp_info *info = matchinfo;
137 const struct xt_dccp_info *info;
138 139
139 info = (const struct xt_dccp_info *)matchinfo; 140 return !(info->flags & ~XT_DCCP_VALID_FLAGS)
140
141 return ip->proto == IPPROTO_DCCP
142 && !(ip->invflags & XT_INV_PROTO)
143 && matchsize == XT_ALIGN(sizeof(struct xt_dccp_info))
144 && !(info->flags & ~XT_DCCP_VALID_FLAGS)
145 && !(info->invflags & ~XT_DCCP_VALID_FLAGS)
146 && !(info->invflags & ~info->flags);
147}
148
149static int
150checkentry6(const char *tablename,
151 const void *inf,
152 void *matchinfo,
153 unsigned int matchsize,
154 unsigned int hook_mask)
155{
156 const struct ip6t_ip6 *ip = inf;
157 const struct xt_dccp_info *info;
158
159 info = (const struct xt_dccp_info *)matchinfo;
160
161 return ip->proto == IPPROTO_DCCP
162 && !(ip->invflags & XT_INV_PROTO)
163 && matchsize == XT_ALIGN(sizeof(struct xt_dccp_info))
164 && !(info->flags & ~XT_DCCP_VALID_FLAGS)
165 && !(info->invflags & ~XT_DCCP_VALID_FLAGS) 141 && !(info->invflags & ~XT_DCCP_VALID_FLAGS)
166 && !(info->invflags & ~info->flags); 142 && !(info->invflags & ~info->flags);
167} 143}
168 144
169
170static struct xt_match dccp_match = 145static struct xt_match dccp_match =
171{ 146{
172 .name = "dccp", 147 .name = "dccp",
173 .match = &match, 148 .match = match,
174 .checkentry = &checkentry, 149 .matchsize = sizeof(struct xt_dccp_info),
150 .proto = IPPROTO_DCCP,
151 .checkentry = checkentry,
175 .me = THIS_MODULE, 152 .me = THIS_MODULE,
176}; 153};
177static struct xt_match dccp6_match = 154static struct xt_match dccp6_match =
178{ 155{
179 .name = "dccp", 156 .name = "dccp",
180 .match = &match, 157 .match = match,
181 .checkentry = &checkentry6, 158 .matchsize = sizeof(struct xt_dccp_info),
159 .proto = IPPROTO_DCCP,
160 .checkentry = checkentry,
182 .me = THIS_MODULE, 161 .me = THIS_MODULE,
183}; 162};
184 163
diff --git a/net/netfilter/xt_helper.c b/net/netfilter/xt_helper.c
index 38b6715e1db4..ef8e54d40c92 100644
--- a/net/netfilter/xt_helper.c
+++ b/net/netfilter/xt_helper.c
@@ -42,6 +42,7 @@ static int
42match(const struct sk_buff *skb, 42match(const struct sk_buff *skb,
43 const struct net_device *in, 43 const struct net_device *in,
44 const struct net_device *out, 44 const struct net_device *out,
45 const struct xt_match *match,
45 const void *matchinfo, 46 const void *matchinfo,
46 int offset, 47 int offset,
47 unsigned int protoff, 48 unsigned int protoff,
@@ -89,6 +90,7 @@ static int
89match(const struct sk_buff *skb, 90match(const struct sk_buff *skb,
90 const struct net_device *in, 91 const struct net_device *in,
91 const struct net_device *out, 92 const struct net_device *out,
93 const struct xt_match *match,
92 const void *matchinfo, 94 const void *matchinfo,
93 int offset, 95 int offset,
94 unsigned int protoff, 96 unsigned int protoff,
@@ -96,6 +98,7 @@ match(const struct sk_buff *skb,
96{ 98{
97 const struct xt_helper_info *info = matchinfo; 99 const struct xt_helper_info *info = matchinfo;
98 struct nf_conn *ct; 100 struct nf_conn *ct;
101 struct nf_conn_help *master_help;
99 enum ip_conntrack_info ctinfo; 102 enum ip_conntrack_info ctinfo;
100 int ret = info->invert; 103 int ret = info->invert;
101 104
@@ -111,7 +114,8 @@ match(const struct sk_buff *skb,
111 } 114 }
112 115
113 read_lock_bh(&nf_conntrack_lock); 116 read_lock_bh(&nf_conntrack_lock);
114 if (!ct->master->helper) { 117 master_help = nfct_help(ct->master);
118 if (!master_help || !master_help->helper) {
115 DEBUGP("xt_helper: master ct %p has no helper\n", 119 DEBUGP("xt_helper: master ct %p has no helper\n",
116 exp->expectant); 120 exp->expectant);
117 goto out_unlock; 121 goto out_unlock;
@@ -123,8 +127,8 @@ match(const struct sk_buff *skb,
123 if (info->name[0] == '\0') 127 if (info->name[0] == '\0')
124 ret ^= 1; 128 ret ^= 1;
125 else 129 else
126 ret ^= !strncmp(ct->master->helper->name, info->name, 130 ret ^= !strncmp(master_help->helper->name, info->name,
127 strlen(ct->master->helper->name)); 131 strlen(master_help->helper->name));
128out_unlock: 132out_unlock:
129 read_unlock_bh(&nf_conntrack_lock); 133 read_unlock_bh(&nf_conntrack_lock);
130 return ret; 134 return ret;
@@ -133,6 +137,7 @@ out_unlock:
133 137
134static int check(const char *tablename, 138static int check(const char *tablename,
135 const void *inf, 139 const void *inf,
140 const struct xt_match *match,
136 void *matchinfo, 141 void *matchinfo,
137 unsigned int matchsize, 142 unsigned int matchsize,
138 unsigned int hook_mask) 143 unsigned int hook_mask)
@@ -140,24 +145,21 @@ static int check(const char *tablename,
140 struct xt_helper_info *info = matchinfo; 145 struct xt_helper_info *info = matchinfo;
141 146
142 info->name[29] = '\0'; 147 info->name[29] = '\0';
143
144 /* verify size */
145 if (matchsize != XT_ALIGN(sizeof(struct xt_helper_info)))
146 return 0;
147
148 return 1; 148 return 1;
149} 149}
150 150
151static struct xt_match helper_match = { 151static struct xt_match helper_match = {
152 .name = "helper", 152 .name = "helper",
153 .match = &match, 153 .match = match,
154 .checkentry = &check, 154 .matchsize = sizeof(struct xt_helper_info),
155 .checkentry = check,
155 .me = THIS_MODULE, 156 .me = THIS_MODULE,
156}; 157};
157static struct xt_match helper6_match = { 158static struct xt_match helper6_match = {
158 .name = "helper", 159 .name = "helper",
159 .match = &match, 160 .match = match,
160 .checkentry = &check, 161 .matchsize = sizeof(struct xt_helper_info),
162 .checkentry = check,
161 .me = THIS_MODULE, 163 .me = THIS_MODULE,
162}; 164};
163 165
diff --git a/net/netfilter/xt_length.c b/net/netfilter/xt_length.c
index 39c8faea63de..b9e60f041a64 100644
--- a/net/netfilter/xt_length.c
+++ b/net/netfilter/xt_length.c
@@ -24,6 +24,7 @@ static int
24match(const struct sk_buff *skb, 24match(const struct sk_buff *skb,
25 const struct net_device *in, 25 const struct net_device *in,
26 const struct net_device *out, 26 const struct net_device *out,
27 const struct xt_match *match,
27 const void *matchinfo, 28 const void *matchinfo,
28 int offset, 29 int offset,
29 unsigned int protoff, 30 unsigned int protoff,
@@ -39,6 +40,7 @@ static int
39match6(const struct sk_buff *skb, 40match6(const struct sk_buff *skb,
40 const struct net_device *in, 41 const struct net_device *in,
41 const struct net_device *out, 42 const struct net_device *out,
43 const struct xt_match *match,
42 const void *matchinfo, 44 const void *matchinfo,
43 int offset, 45 int offset,
44 unsigned int protoff, 46 unsigned int protoff,
@@ -50,29 +52,17 @@ match6(const struct sk_buff *skb,
50 return (pktlen >= info->min && pktlen <= info->max) ^ info->invert; 52 return (pktlen >= info->min && pktlen <= info->max) ^ info->invert;
51} 53}
52 54
53static int
54checkentry(const char *tablename,
55 const void *ip,
56 void *matchinfo,
57 unsigned int matchsize,
58 unsigned int hook_mask)
59{
60 if (matchsize != XT_ALIGN(sizeof(struct xt_length_info)))
61 return 0;
62
63 return 1;
64}
65
66static struct xt_match length_match = { 55static struct xt_match length_match = {
67 .name = "length", 56 .name = "length",
68 .match = &match, 57 .match = match,
69 .checkentry = &checkentry, 58 .matchsize = sizeof(struct xt_length_info),
70 .me = THIS_MODULE, 59 .me = THIS_MODULE,
71}; 60};
61
72static struct xt_match length6_match = { 62static struct xt_match length6_match = {
73 .name = "length", 63 .name = "length",
74 .match = &match6, 64 .match = match6,
75 .checkentry = &checkentry, 65 .matchsize = sizeof(struct xt_length_info),
76 .me = THIS_MODULE, 66 .me = THIS_MODULE,
77}; 67};
78 68
diff --git a/net/netfilter/xt_limit.c b/net/netfilter/xt_limit.c
index 15e40506bc3a..3049e6f8889e 100644
--- a/net/netfilter/xt_limit.c
+++ b/net/netfilter/xt_limit.c
@@ -68,6 +68,7 @@ static int
68ipt_limit_match(const struct sk_buff *skb, 68ipt_limit_match(const struct sk_buff *skb,
69 const struct net_device *in, 69 const struct net_device *in,
70 const struct net_device *out, 70 const struct net_device *out,
71 const struct xt_match *match,
71 const void *matchinfo, 72 const void *matchinfo,
72 int offset, 73 int offset,
73 unsigned int protoff, 74 unsigned int protoff,
@@ -107,15 +108,13 @@ user2credits(u_int32_t user)
107static int 108static int
108ipt_limit_checkentry(const char *tablename, 109ipt_limit_checkentry(const char *tablename,
109 const void *inf, 110 const void *inf,
111 const struct xt_match *match,
110 void *matchinfo, 112 void *matchinfo,
111 unsigned int matchsize, 113 unsigned int matchsize,
112 unsigned int hook_mask) 114 unsigned int hook_mask)
113{ 115{
114 struct xt_rateinfo *r = matchinfo; 116 struct xt_rateinfo *r = matchinfo;
115 117
116 if (matchsize != XT_ALIGN(sizeof(struct xt_rateinfo)))
117 return 0;
118
119 /* Check for overflow. */ 118 /* Check for overflow. */
120 if (r->burst == 0 119 if (r->burst == 0
121 || user2credits(r->avg * r->burst) < user2credits(r->avg)) { 120 || user2credits(r->avg * r->burst) < user2credits(r->avg)) {
@@ -140,12 +139,14 @@ ipt_limit_checkentry(const char *tablename,
140static struct xt_match ipt_limit_reg = { 139static struct xt_match ipt_limit_reg = {
141 .name = "limit", 140 .name = "limit",
142 .match = ipt_limit_match, 141 .match = ipt_limit_match,
142 .matchsize = sizeof(struct xt_rateinfo),
143 .checkentry = ipt_limit_checkentry, 143 .checkentry = ipt_limit_checkentry,
144 .me = THIS_MODULE, 144 .me = THIS_MODULE,
145}; 145};
146static struct xt_match limit6_reg = { 146static struct xt_match limit6_reg = {
147 .name = "limit", 147 .name = "limit",
148 .match = ipt_limit_match, 148 .match = ipt_limit_match,
149 .matchsize = sizeof(struct xt_rateinfo),
149 .checkentry = ipt_limit_checkentry, 150 .checkentry = ipt_limit_checkentry,
150 .me = THIS_MODULE, 151 .me = THIS_MODULE,
151}; 152};
diff --git a/net/netfilter/xt_mac.c b/net/netfilter/xt_mac.c
index 0461dcb5fc7a..b4559a46dce8 100644
--- a/net/netfilter/xt_mac.c
+++ b/net/netfilter/xt_mac.c
@@ -27,6 +27,7 @@ static int
27match(const struct sk_buff *skb, 27match(const struct sk_buff *skb,
28 const struct net_device *in, 28 const struct net_device *in,
29 const struct net_device *out, 29 const struct net_device *out,
30 const struct xt_match *match,
30 const void *matchinfo, 31 const void *matchinfo,
31 int offset, 32 int offset,
32 unsigned int protoff, 33 unsigned int protoff,
@@ -42,37 +43,20 @@ match(const struct sk_buff *skb,
42 ^ info->invert)); 43 ^ info->invert));
43} 44}
44 45
45static int
46ipt_mac_checkentry(const char *tablename,
47 const void *inf,
48 void *matchinfo,
49 unsigned int matchsize,
50 unsigned int hook_mask)
51{
52 /* FORWARD isn't always valid, but it's nice to be able to do --RR */
53 if (hook_mask
54 & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_IN)
55 | (1 << NF_IP_FORWARD))) {
56 printk("xt_mac: only valid for PRE_ROUTING, LOCAL_IN or FORWARD.\n");
57 return 0;
58 }
59
60 if (matchsize != XT_ALIGN(sizeof(struct xt_mac_info)))
61 return 0;
62
63 return 1;
64}
65
66static struct xt_match mac_match = { 46static struct xt_match mac_match = {
67 .name = "mac", 47 .name = "mac",
68 .match = &match, 48 .match = match,
69 .checkentry = &ipt_mac_checkentry, 49 .matchsize = sizeof(struct xt_mac_info),
50 .hooks = (1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_IN) |
51 (1 << NF_IP_FORWARD),
70 .me = THIS_MODULE, 52 .me = THIS_MODULE,
71}; 53};
72static struct xt_match mac6_match = { 54static struct xt_match mac6_match = {
73 .name = "mac", 55 .name = "mac",
74 .match = &match, 56 .match = match,
75 .checkentry = &ipt_mac_checkentry, 57 .matchsize = sizeof(struct xt_mac_info),
58 .hooks = (1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_IN) |
59 (1 << NF_IP_FORWARD),
76 .me = THIS_MODULE, 60 .me = THIS_MODULE,
77}; 61};
78 62
diff --git a/net/netfilter/xt_mark.c b/net/netfilter/xt_mark.c
index 2a0ac62b72c8..c1a8f0f587f0 100644
--- a/net/netfilter/xt_mark.c
+++ b/net/netfilter/xt_mark.c
@@ -23,6 +23,7 @@ static int
23match(const struct sk_buff *skb, 23match(const struct sk_buff *skb,
24 const struct net_device *in, 24 const struct net_device *in,
25 const struct net_device *out, 25 const struct net_device *out,
26 const struct xt_match *match,
26 const void *matchinfo, 27 const void *matchinfo,
27 int offset, 28 int offset,
28 unsigned int protoff, 29 unsigned int protoff,
@@ -36,34 +37,33 @@ match(const struct sk_buff *skb,
36static int 37static int
37checkentry(const char *tablename, 38checkentry(const char *tablename,
38 const void *entry, 39 const void *entry,
40 const struct xt_match *match,
39 void *matchinfo, 41 void *matchinfo,
40 unsigned int matchsize, 42 unsigned int matchsize,
41 unsigned int hook_mask) 43 unsigned int hook_mask)
42{ 44{
43 struct xt_mark_info *minfo = (struct xt_mark_info *) matchinfo; 45 struct xt_mark_info *minfo = (struct xt_mark_info *) matchinfo;
44 46
45 if (matchsize != XT_ALIGN(sizeof(struct xt_mark_info)))
46 return 0;
47
48 if (minfo->mark > 0xffffffff || minfo->mask > 0xffffffff) { 47 if (minfo->mark > 0xffffffff || minfo->mask > 0xffffffff) {
49 printk(KERN_WARNING "mark: only supports 32bit mark\n"); 48 printk(KERN_WARNING "mark: only supports 32bit mark\n");
50 return 0; 49 return 0;
51 } 50 }
52
53 return 1; 51 return 1;
54} 52}
55 53
56static struct xt_match mark_match = { 54static struct xt_match mark_match = {
57 .name = "mark", 55 .name = "mark",
58 .match = &match, 56 .match = match,
59 .checkentry = &checkentry, 57 .matchsize = sizeof(struct xt_mark_info),
58 .checkentry = checkentry,
60 .me = THIS_MODULE, 59 .me = THIS_MODULE,
61}; 60};
62 61
63static struct xt_match mark6_match = { 62static struct xt_match mark6_match = {
64 .name = "mark", 63 .name = "mark",
65 .match = &match, 64 .match = match,
66 .checkentry = &checkentry, 65 .matchsize = sizeof(struct xt_mark_info),
66 .checkentry = checkentry,
67 .me = THIS_MODULE, 67 .me = THIS_MODULE,
68}; 68};
69 69
diff --git a/net/netfilter/xt_physdev.c b/net/netfilter/xt_physdev.c
index 19bb57c14dfe..f788e8e76254 100644
--- a/net/netfilter/xt_physdev.c
+++ b/net/netfilter/xt_physdev.c
@@ -26,6 +26,7 @@ static int
26match(const struct sk_buff *skb, 26match(const struct sk_buff *skb,
27 const struct net_device *in, 27 const struct net_device *in,
28 const struct net_device *out, 28 const struct net_device *out,
29 const struct xt_match *match,
29 const void *matchinfo, 30 const void *matchinfo,
30 int offset, 31 int offset,
31 unsigned int protoff, 32 unsigned int protoff,
@@ -102,14 +103,13 @@ match_outdev:
102static int 103static int
103checkentry(const char *tablename, 104checkentry(const char *tablename,
104 const void *ip, 105 const void *ip,
106 const struct xt_match *match,
105 void *matchinfo, 107 void *matchinfo,
106 unsigned int matchsize, 108 unsigned int matchsize,
107 unsigned int hook_mask) 109 unsigned int hook_mask)
108{ 110{
109 const struct xt_physdev_info *info = matchinfo; 111 const struct xt_physdev_info *info = matchinfo;
110 112
111 if (matchsize != XT_ALIGN(sizeof(struct xt_physdev_info)))
112 return 0;
113 if (!(info->bitmask & XT_PHYSDEV_OP_MASK) || 113 if (!(info->bitmask & XT_PHYSDEV_OP_MASK) ||
114 info->bitmask & ~XT_PHYSDEV_OP_MASK) 114 info->bitmask & ~XT_PHYSDEV_OP_MASK)
115 return 0; 115 return 0;
@@ -118,15 +118,17 @@ checkentry(const char *tablename,
118 118
119static struct xt_match physdev_match = { 119static struct xt_match physdev_match = {
120 .name = "physdev", 120 .name = "physdev",
121 .match = &match, 121 .match = match,
122 .checkentry = &checkentry, 122 .matchsize = sizeof(struct xt_physdev_info),
123 .checkentry = checkentry,
123 .me = THIS_MODULE, 124 .me = THIS_MODULE,
124}; 125};
125 126
126static struct xt_match physdev6_match = { 127static struct xt_match physdev6_match = {
127 .name = "physdev", 128 .name = "physdev",
128 .match = &match, 129 .match = match,
129 .checkentry = &checkentry, 130 .matchsize = sizeof(struct xt_physdev_info),
131 .checkentry = checkentry,
130 .me = THIS_MODULE, 132 .me = THIS_MODULE,
131}; 133};
132 134
diff --git a/net/netfilter/xt_pkttype.c b/net/netfilter/xt_pkttype.c
index ab1b2630f97d..f38638dfd139 100644
--- a/net/netfilter/xt_pkttype.c
+++ b/net/netfilter/xt_pkttype.c
@@ -22,6 +22,7 @@ MODULE_ALIAS("ip6t_pkttype");
22static int match(const struct sk_buff *skb, 22static int match(const struct sk_buff *skb,
23 const struct net_device *in, 23 const struct net_device *in,
24 const struct net_device *out, 24 const struct net_device *out,
25 const struct xt_match *match,
25 const void *matchinfo, 26 const void *matchinfo,
26 int offset, 27 int offset,
27 unsigned int protoff, 28 unsigned int protoff,
@@ -32,32 +33,20 @@ static int match(const struct sk_buff *skb,
32 return (skb->pkt_type == info->pkttype) ^ info->invert; 33 return (skb->pkt_type == info->pkttype) ^ info->invert;
33} 34}
34 35
35static int checkentry(const char *tablename,
36 const void *ip,
37 void *matchinfo,
38 unsigned int matchsize,
39 unsigned int hook_mask)
40{
41 if (matchsize != XT_ALIGN(sizeof(struct xt_pkttype_info)))
42 return 0;
43
44 return 1;
45}
46
47static struct xt_match pkttype_match = { 36static struct xt_match pkttype_match = {
48 .name = "pkttype", 37 .name = "pkttype",
49 .match = &match, 38 .match = match,
50 .checkentry = &checkentry, 39 .matchsize = sizeof(struct xt_pkttype_info),
51 .me = THIS_MODULE, 40 .me = THIS_MODULE,
52}; 41};
42
53static struct xt_match pkttype6_match = { 43static struct xt_match pkttype6_match = {
54 .name = "pkttype", 44 .name = "pkttype",
55 .match = &match, 45 .match = match,
56 .checkentry = &checkentry, 46 .matchsize = sizeof(struct xt_pkttype_info),
57 .me = THIS_MODULE, 47 .me = THIS_MODULE,
58}; 48};
59 49
60
61static int __init init(void) 50static int __init init(void)
62{ 51{
63 int ret; 52 int ret;
diff --git a/net/netfilter/xt_policy.c b/net/netfilter/xt_policy.c
new file mode 100644
index 000000000000..1ec22082f04d
--- /dev/null
+++ b/net/netfilter/xt_policy.c
@@ -0,0 +1,209 @@
1/* IP tables module for matching IPsec policy
2 *
3 * Copyright (c) 2004,2005 Patrick McHardy, <kaber@trash.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/kernel.h>
11#include <linux/config.h>
12#include <linux/module.h>
13#include <linux/skbuff.h>
14#include <linux/init.h>
15#include <net/xfrm.h>
16
17#include <linux/netfilter/xt_policy.h>
18#include <linux/netfilter/x_tables.h>
19
20MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
21MODULE_DESCRIPTION("Xtables IPsec policy matching module");
22MODULE_LICENSE("GPL");
23
24static inline int
25xt_addr_cmp(const union xt_policy_addr *a1, const union xt_policy_addr *m,
26 const union xt_policy_addr *a2, unsigned short family)
27{
28 switch (family) {
29 case AF_INET:
30 return (a1->a4.s_addr ^ a2->a4.s_addr) & m->a4.s_addr;
31 case AF_INET6:
32 return ipv6_masked_addr_cmp(&a1->a6, &m->a6, &a2->a6);
33 }
34 return 0;
35}
36
37static inline int
38match_xfrm_state(struct xfrm_state *x, const struct xt_policy_elem *e,
39 unsigned short family)
40{
41#define MATCH_ADDR(x,y,z) (!e->match.x || \
42 (xt_addr_cmp(&e->x, &e->y, z, family) \
43 ^ e->invert.x))
44#define MATCH(x,y) (!e->match.x || ((e->x == (y)) ^ e->invert.x))
45
46 return MATCH_ADDR(saddr, smask, (union xt_policy_addr *)&x->props.saddr) &&
47 MATCH_ADDR(daddr, dmask, (union xt_policy_addr *)&x->id.daddr.a4) &&
48 MATCH(proto, x->id.proto) &&
49 MATCH(mode, x->props.mode) &&
50 MATCH(spi, x->id.spi) &&
51 MATCH(reqid, x->props.reqid);
52}
53
54static int
55match_policy_in(const struct sk_buff *skb, const struct xt_policy_info *info,
56 unsigned short family)
57{
58 const struct xt_policy_elem *e;
59 struct sec_path *sp = skb->sp;
60 int strict = info->flags & XT_POLICY_MATCH_STRICT;
61 int i, pos;
62
63 if (sp == NULL)
64 return -1;
65 if (strict && info->len != sp->len)
66 return 0;
67
68 for (i = sp->len - 1; i >= 0; i--) {
69 pos = strict ? i - sp->len + 1 : 0;
70 if (pos >= info->len)
71 return 0;
72 e = &info->pol[pos];
73
74 if (match_xfrm_state(sp->x[i].xvec, e, family)) {
75 if (!strict)
76 return 1;
77 } else if (strict)
78 return 0;
79 }
80
81 return strict ? 1 : 0;
82}
83
84static int
85match_policy_out(const struct sk_buff *skb, const struct xt_policy_info *info,
86 unsigned short family)
87{
88 const struct xt_policy_elem *e;
89 struct dst_entry *dst = skb->dst;
90 int strict = info->flags & XT_POLICY_MATCH_STRICT;
91 int i, pos;
92
93 if (dst->xfrm == NULL)
94 return -1;
95
96 for (i = 0; dst && dst->xfrm; dst = dst->child, i++) {
97 pos = strict ? i : 0;
98 if (pos >= info->len)
99 return 0;
100 e = &info->pol[pos];
101
102 if (match_xfrm_state(dst->xfrm, e, family)) {
103 if (!strict)
104 return 1;
105 } else if (strict)
106 return 0;
107 }
108
109 return strict ? i == info->len : 0;
110}
111
112static int match(const struct sk_buff *skb,
113 const struct net_device *in,
114 const struct net_device *out,
115 const struct xt_match *match,
116 const void *matchinfo,
117 int offset,
118 unsigned int protoff,
119 int *hotdrop)
120{
121 const struct xt_policy_info *info = matchinfo;
122 int ret;
123
124 if (info->flags & XT_POLICY_MATCH_IN)
125 ret = match_policy_in(skb, info, match->family);
126 else
127 ret = match_policy_out(skb, info, match->family);
128
129 if (ret < 0)
130 ret = info->flags & XT_POLICY_MATCH_NONE ? 1 : 0;
131 else if (info->flags & XT_POLICY_MATCH_NONE)
132 ret = 0;
133
134 return ret;
135}
136
137static int checkentry(const char *tablename, const void *ip_void,
138 const struct xt_match *match,
139 void *matchinfo, unsigned int matchsize,
140 unsigned int hook_mask)
141{
142 struct xt_policy_info *info = matchinfo;
143
144 if (!(info->flags & (XT_POLICY_MATCH_IN|XT_POLICY_MATCH_OUT))) {
145 printk(KERN_ERR "xt_policy: neither incoming nor "
146 "outgoing policy selected\n");
147 return 0;
148 }
149 /* hook values are equal for IPv4 and IPv6 */
150 if (hook_mask & (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_LOCAL_IN)
151 && info->flags & XT_POLICY_MATCH_OUT) {
152 printk(KERN_ERR "xt_policy: output policy not valid in "
153 "PRE_ROUTING and INPUT\n");
154 return 0;
155 }
156 if (hook_mask & (1 << NF_IP_POST_ROUTING | 1 << NF_IP_LOCAL_OUT)
157 && info->flags & XT_POLICY_MATCH_IN) {
158 printk(KERN_ERR "xt_policy: input policy not valid in "
159 "POST_ROUTING and OUTPUT\n");
160 return 0;
161 }
162 if (info->len > XT_POLICY_MAX_ELEM) {
163 printk(KERN_ERR "xt_policy: too many policy elements\n");
164 return 0;
165 }
166 return 1;
167}
168
169static struct xt_match policy_match = {
170 .name = "policy",
171 .family = AF_INET,
172 .match = match,
173 .matchsize = sizeof(struct xt_policy_info),
174 .checkentry = checkentry,
175 .me = THIS_MODULE,
176};
177
178static struct xt_match policy6_match = {
179 .name = "policy",
180 .family = AF_INET6,
181 .match = match,
182 .matchsize = sizeof(struct xt_policy_info),
183 .checkentry = checkentry,
184 .me = THIS_MODULE,
185};
186
187static int __init init(void)
188{
189 int ret;
190
191 ret = xt_register_match(AF_INET, &policy_match);
192 if (ret)
193 return ret;
194 ret = xt_register_match(AF_INET6, &policy6_match);
195 if (ret)
196 xt_unregister_match(AF_INET, &policy_match);
197 return ret;
198}
199
200static void __exit fini(void)
201{
202 xt_unregister_match(AF_INET6, &policy6_match);
203 xt_unregister_match(AF_INET, &policy_match);
204}
205
206module_init(init);
207module_exit(fini);
208MODULE_ALIAS("ipt_policy");
209MODULE_ALIAS("ip6t_policy");
diff --git a/net/netfilter/xt_realm.c b/net/netfilter/xt_realm.c
index 2b7e1781d34d..57815a07db67 100644
--- a/net/netfilter/xt_realm.c
+++ b/net/netfilter/xt_realm.c
@@ -27,6 +27,7 @@ static int
27match(const struct sk_buff *skb, 27match(const struct sk_buff *skb,
28 const struct net_device *in, 28 const struct net_device *in,
29 const struct net_device *out, 29 const struct net_device *out,
30 const struct xt_match *match,
30 const void *matchinfo, 31 const void *matchinfo,
31 int offset, 32 int offset,
32 unsigned int protoff, 33 unsigned int protoff,
@@ -38,30 +39,12 @@ match(const struct sk_buff *skb,
38 return (info->id == (dst->tclassid & info->mask)) ^ info->invert; 39 return (info->id == (dst->tclassid & info->mask)) ^ info->invert;
39} 40}
40 41
41static int check(const char *tablename,
42 const void *ip,
43 void *matchinfo,
44 unsigned int matchsize,
45 unsigned int hook_mask)
46{
47 if (hook_mask
48 & ~((1 << NF_IP_POST_ROUTING) | (1 << NF_IP_FORWARD) |
49 (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_LOCAL_IN))) {
50 printk("xt_realm: only valid for POST_ROUTING, LOCAL_OUT, "
51 "LOCAL_IN or FORWARD.\n");
52 return 0;
53 }
54 if (matchsize != XT_ALIGN(sizeof(struct xt_realm_info))) {
55 printk("xt_realm: invalid matchsize.\n");
56 return 0;
57 }
58 return 1;
59}
60
61static struct xt_match realm_match = { 42static struct xt_match realm_match = {
62 .name = "realm", 43 .name = "realm",
63 .match = match, 44 .match = match,
64 .checkentry = check, 45 .matchsize = sizeof(struct xt_realm_info),
46 .hooks = (1 << NF_IP_POST_ROUTING) | (1 << NF_IP_FORWARD) |
47 (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_LOCAL_IN),
65 .me = THIS_MODULE 48 .me = THIS_MODULE
66}; 49};
67 50
diff --git a/net/netfilter/xt_sctp.c b/net/netfilter/xt_sctp.c
index 10fbfc5ba758..f5d698ba03ca 100644
--- a/net/netfilter/xt_sctp.c
+++ b/net/netfilter/xt_sctp.c
@@ -123,6 +123,7 @@ static int
123match(const struct sk_buff *skb, 123match(const struct sk_buff *skb,
124 const struct net_device *in, 124 const struct net_device *in,
125 const struct net_device *out, 125 const struct net_device *out,
126 const struct xt_match *match,
126 const void *matchinfo, 127 const void *matchinfo,
127 int offset, 128 int offset,
128 unsigned int protoff, 129 unsigned int protoff,
@@ -162,19 +163,14 @@ match(const struct sk_buff *skb,
162static int 163static int
163checkentry(const char *tablename, 164checkentry(const char *tablename,
164 const void *inf, 165 const void *inf,
166 const struct xt_match *match,
165 void *matchinfo, 167 void *matchinfo,
166 unsigned int matchsize, 168 unsigned int matchsize,
167 unsigned int hook_mask) 169 unsigned int hook_mask)
168{ 170{
169 const struct xt_sctp_info *info; 171 const struct xt_sctp_info *info = matchinfo;
170 const struct ipt_ip *ip = inf;
171
172 info = (const struct xt_sctp_info *)matchinfo;
173 172
174 return ip->proto == IPPROTO_SCTP 173 return !(info->flags & ~XT_SCTP_VALID_FLAGS)
175 && !(ip->invflags & XT_INV_PROTO)
176 && matchsize == XT_ALIGN(sizeof(struct xt_sctp_info))
177 && !(info->flags & ~XT_SCTP_VALID_FLAGS)
178 && !(info->invflags & ~XT_SCTP_VALID_FLAGS) 174 && !(info->invflags & ~XT_SCTP_VALID_FLAGS)
179 && !(info->invflags & ~info->flags) 175 && !(info->invflags & ~info->flags)
180 && ((!(info->flags & XT_SCTP_CHUNK_TYPES)) || 176 && ((!(info->flags & XT_SCTP_CHUNK_TYPES)) ||
@@ -184,47 +180,23 @@ checkentry(const char *tablename,
184 | SCTP_CHUNK_MATCH_ONLY))); 180 | SCTP_CHUNK_MATCH_ONLY)));
185} 181}
186 182
187static int 183static struct xt_match sctp_match = {
188checkentry6(const char *tablename, 184 .name = "sctp",
189 const void *inf, 185 .match = match,
190 void *matchinfo, 186 .matchsize = sizeof(struct xt_sctp_info),
191 unsigned int matchsize, 187 .proto = IPPROTO_SCTP,
192 unsigned int hook_mask) 188 .checkentry = checkentry,
193{ 189 .me = THIS_MODULE
194 const struct xt_sctp_info *info;
195 const struct ip6t_ip6 *ip = inf;
196
197 info = (const struct xt_sctp_info *)matchinfo;
198
199 return ip->proto == IPPROTO_SCTP
200 && !(ip->invflags & XT_INV_PROTO)
201 && matchsize == XT_ALIGN(sizeof(struct xt_sctp_info))
202 && !(info->flags & ~XT_SCTP_VALID_FLAGS)
203 && !(info->invflags & ~XT_SCTP_VALID_FLAGS)
204 && !(info->invflags & ~info->flags)
205 && ((!(info->flags & XT_SCTP_CHUNK_TYPES)) ||
206 (info->chunk_match_type &
207 (SCTP_CHUNK_MATCH_ALL
208 | SCTP_CHUNK_MATCH_ANY
209 | SCTP_CHUNK_MATCH_ONLY)));
210}
211
212
213static struct xt_match sctp_match =
214{
215 .name = "sctp",
216 .match = &match,
217 .checkentry = &checkentry,
218 .me = THIS_MODULE
219};
220static struct xt_match sctp6_match =
221{
222 .name = "sctp",
223 .match = &match,
224 .checkentry = &checkentry6,
225 .me = THIS_MODULE
226}; 190};
227 191
192static struct xt_match sctp6_match = {
193 .name = "sctp",
194 .match = match,
195 .matchsize = sizeof(struct xt_sctp_info),
196 .proto = IPPROTO_SCTP,
197 .checkentry = checkentry,
198 .me = THIS_MODULE
199};
228 200
229static int __init init(void) 201static int __init init(void)
230{ 202{
diff --git a/net/netfilter/xt_state.c b/net/netfilter/xt_state.c
index 39ce808d40ef..b8ec00cd51fc 100644
--- a/net/netfilter/xt_state.c
+++ b/net/netfilter/xt_state.c
@@ -24,6 +24,7 @@ static int
24match(const struct sk_buff *skb, 24match(const struct sk_buff *skb,
25 const struct net_device *in, 25 const struct net_device *in,
26 const struct net_device *out, 26 const struct net_device *out,
27 const struct xt_match *match,
27 const void *matchinfo, 28 const void *matchinfo,
28 int offset, 29 int offset,
29 unsigned int protoff, 30 unsigned int protoff,
@@ -43,29 +44,17 @@ match(const struct sk_buff *skb,
43 return (sinfo->statemask & statebit); 44 return (sinfo->statemask & statebit);
44} 45}
45 46
46static int check(const char *tablename,
47 const void *ip,
48 void *matchinfo,
49 unsigned int matchsize,
50 unsigned int hook_mask)
51{
52 if (matchsize != XT_ALIGN(sizeof(struct xt_state_info)))
53 return 0;
54
55 return 1;
56}
57
58static struct xt_match state_match = { 47static struct xt_match state_match = {
59 .name = "state", 48 .name = "state",
60 .match = &match, 49 .match = match,
61 .checkentry = &check, 50 .matchsize = sizeof(struct xt_state_info),
62 .me = THIS_MODULE, 51 .me = THIS_MODULE,
63}; 52};
64 53
65static struct xt_match state6_match = { 54static struct xt_match state6_match = {
66 .name = "state", 55 .name = "state",
67 .match = &match, 56 .match = match,
68 .checkentry = &check, 57 .matchsize = sizeof(struct xt_state_info),
69 .me = THIS_MODULE, 58 .me = THIS_MODULE,
70}; 59};
71 60
diff --git a/net/netfilter/xt_string.c b/net/netfilter/xt_string.c
index 7c7d5c8807d6..fccbad6a7f40 100644
--- a/net/netfilter/xt_string.c
+++ b/net/netfilter/xt_string.c
@@ -24,6 +24,7 @@ MODULE_ALIAS("ip6t_string");
24static int match(const struct sk_buff *skb, 24static int match(const struct sk_buff *skb,
25 const struct net_device *in, 25 const struct net_device *in,
26 const struct net_device *out, 26 const struct net_device *out,
27 const struct xt_match *match,
27 const void *matchinfo, 28 const void *matchinfo,
28 int offset, 29 int offset,
29 unsigned int protoff, 30 unsigned int protoff,
@@ -43,6 +44,7 @@ static int match(const struct sk_buff *skb,
43 44
44static int checkentry(const char *tablename, 45static int checkentry(const char *tablename,
45 const void *ip, 46 const void *ip,
47 const struct xt_match *match,
46 void *matchinfo, 48 void *matchinfo,
47 unsigned int matchsize, 49 unsigned int matchsize,
48 unsigned int hook_mask) 50 unsigned int hook_mask)
@@ -50,9 +52,6 @@ static int checkentry(const char *tablename,
50 struct xt_string_info *conf = matchinfo; 52 struct xt_string_info *conf = matchinfo;
51 struct ts_config *ts_conf; 53 struct ts_config *ts_conf;
52 54
53 if (matchsize != XT_ALIGN(sizeof(struct xt_string_info)))
54 return 0;
55
56 /* Damn, can't handle this case properly with iptables... */ 55 /* Damn, can't handle this case properly with iptables... */
57 if (conf->from_offset > conf->to_offset) 56 if (conf->from_offset > conf->to_offset)
58 return 0; 57 return 0;
@@ -67,7 +66,8 @@ static int checkentry(const char *tablename,
67 return 1; 66 return 1;
68} 67}
69 68
70static void destroy(void *matchinfo, unsigned int matchsize) 69static void destroy(const struct xt_match *match, void *matchinfo,
70 unsigned int matchsize)
71{ 71{
72 textsearch_destroy(STRING_TEXT_PRIV(matchinfo)->config); 72 textsearch_destroy(STRING_TEXT_PRIV(matchinfo)->config);
73} 73}
@@ -75,6 +75,7 @@ static void destroy(void *matchinfo, unsigned int matchsize)
75static struct xt_match string_match = { 75static struct xt_match string_match = {
76 .name = "string", 76 .name = "string",
77 .match = match, 77 .match = match,
78 .matchsize = sizeof(struct xt_string_info),
78 .checkentry = checkentry, 79 .checkentry = checkentry,
79 .destroy = destroy, 80 .destroy = destroy,
80 .me = THIS_MODULE 81 .me = THIS_MODULE
@@ -82,6 +83,7 @@ static struct xt_match string_match = {
82static struct xt_match string6_match = { 83static struct xt_match string6_match = {
83 .name = "string", 84 .name = "string",
84 .match = match, 85 .match = match,
86 .matchsize = sizeof(struct xt_string_info),
85 .checkentry = checkentry, 87 .checkentry = checkentry,
86 .destroy = destroy, 88 .destroy = destroy,
87 .me = THIS_MODULE 89 .me = THIS_MODULE
diff --git a/net/netfilter/xt_tcpmss.c b/net/netfilter/xt_tcpmss.c
index acf7f533e9f1..4925fc98f4ae 100644
--- a/net/netfilter/xt_tcpmss.c
+++ b/net/netfilter/xt_tcpmss.c
@@ -81,6 +81,7 @@ static int
81match(const struct sk_buff *skb, 81match(const struct sk_buff *skb,
82 const struct net_device *in, 82 const struct net_device *in,
83 const struct net_device *out, 83 const struct net_device *out,
84 const struct xt_match *match,
84 const void *matchinfo, 85 const void *matchinfo,
85 int offset, 86 int offset,
86 unsigned int protoff, 87 unsigned int protoff,
@@ -92,58 +93,19 @@ match(const struct sk_buff *skb,
92 info->invert, hotdrop); 93 info->invert, hotdrop);
93} 94}
94 95
95static int
96checkentry(const char *tablename,
97 const void *ipinfo,
98 void *matchinfo,
99 unsigned int matchsize,
100 unsigned int hook_mask)
101{
102 const struct ipt_ip *ip = ipinfo;
103 if (matchsize != XT_ALIGN(sizeof(struct xt_tcpmss_match_info)))
104 return 0;
105
106 /* Must specify -p tcp */
107 if (ip->proto != IPPROTO_TCP || (ip->invflags & IPT_INV_PROTO)) {
108 printk("tcpmss: Only works on TCP packets\n");
109 return 0;
110 }
111
112 return 1;
113}
114
115static int
116checkentry6(const char *tablename,
117 const void *ipinfo,
118 void *matchinfo,
119 unsigned int matchsize,
120 unsigned int hook_mask)
121{
122 const struct ip6t_ip6 *ip = ipinfo;
123
124 if (matchsize != XT_ALIGN(sizeof(struct xt_tcpmss_match_info)))
125 return 0;
126
127 /* Must specify -p tcp */
128 if (ip->proto != IPPROTO_TCP || (ip->invflags & XT_INV_PROTO)) {
129 printk("tcpmss: Only works on TCP packets\n");
130 return 0;
131 }
132
133 return 1;
134}
135
136static struct xt_match tcpmss_match = { 96static struct xt_match tcpmss_match = {
137 .name = "tcpmss", 97 .name = "tcpmss",
138 .match = &match, 98 .match = match,
139 .checkentry = &checkentry, 99 .matchsize = sizeof(struct xt_tcpmss_match_info),
100 .proto = IPPROTO_TCP,
140 .me = THIS_MODULE, 101 .me = THIS_MODULE,
141}; 102};
142 103
143static struct xt_match tcpmss6_match = { 104static struct xt_match tcpmss6_match = {
144 .name = "tcpmss", 105 .name = "tcpmss",
145 .match = &match, 106 .match = match,
146 .checkentry = &checkentry6, 107 .matchsize = sizeof(struct xt_tcpmss_match_info),
108 .proto = IPPROTO_TCP,
147 .me = THIS_MODULE, 109 .me = THIS_MODULE,
148}; 110};
149 111
diff --git a/net/netfilter/xt_tcpudp.c b/net/netfilter/xt_tcpudp.c
index 669c8113cc60..b5cd0dd4e41f 100644
--- a/net/netfilter/xt_tcpudp.c
+++ b/net/netfilter/xt_tcpudp.c
@@ -74,6 +74,7 @@ static int
74tcp_match(const struct sk_buff *skb, 74tcp_match(const struct sk_buff *skb,
75 const struct net_device *in, 75 const struct net_device *in,
76 const struct net_device *out, 76 const struct net_device *out,
77 const struct xt_match *match,
77 const void *matchinfo, 78 const void *matchinfo,
78 int offset, 79 int offset,
79 unsigned int protoff, 80 unsigned int protoff,
@@ -138,43 +139,22 @@ tcp_match(const struct sk_buff *skb,
138static int 139static int
139tcp_checkentry(const char *tablename, 140tcp_checkentry(const char *tablename,
140 const void *info, 141 const void *info,
142 const struct xt_match *match,
141 void *matchinfo, 143 void *matchinfo,
142 unsigned int matchsize, 144 unsigned int matchsize,
143 unsigned int hook_mask) 145 unsigned int hook_mask)
144{ 146{
145 const struct ipt_ip *ip = info;
146 const struct xt_tcp *tcpinfo = matchinfo; 147 const struct xt_tcp *tcpinfo = matchinfo;
147 148
148 /* Must specify proto == TCP, and no unknown invflags */ 149 /* Must specify no unknown invflags */
149 return ip->proto == IPPROTO_TCP 150 return !(tcpinfo->invflags & ~XT_TCP_INV_MASK);
150 && !(ip->invflags & XT_INV_PROTO)
151 && matchsize == XT_ALIGN(sizeof(struct xt_tcp))
152 && !(tcpinfo->invflags & ~XT_TCP_INV_MASK);
153} 151}
154 152
155/* Called when user tries to insert an entry of this type. */
156static int
157tcp6_checkentry(const char *tablename,
158 const void *entry,
159 void *matchinfo,
160 unsigned int matchsize,
161 unsigned int hook_mask)
162{
163 const struct ip6t_ip6 *ipv6 = entry;
164 const struct xt_tcp *tcpinfo = matchinfo;
165
166 /* Must specify proto == TCP, and no unknown invflags */
167 return ipv6->proto == IPPROTO_TCP
168 && !(ipv6->invflags & XT_INV_PROTO)
169 && matchsize == XT_ALIGN(sizeof(struct xt_tcp))
170 && !(tcpinfo->invflags & ~XT_TCP_INV_MASK);
171}
172
173
174static int 153static int
175udp_match(const struct sk_buff *skb, 154udp_match(const struct sk_buff *skb,
176 const struct net_device *in, 155 const struct net_device *in,
177 const struct net_device *out, 156 const struct net_device *out,
157 const struct xt_match *match,
178 const void *matchinfo, 158 const void *matchinfo,
179 int offset, 159 int offset,
180 unsigned int protoff, 160 unsigned int protoff,
@@ -208,87 +188,49 @@ udp_match(const struct sk_buff *skb,
208static int 188static int
209udp_checkentry(const char *tablename, 189udp_checkentry(const char *tablename,
210 const void *info, 190 const void *info,
191 const struct xt_match *match,
211 void *matchinfo, 192 void *matchinfo,
212 unsigned int matchinfosize, 193 unsigned int matchsize,
213 unsigned int hook_mask)
214{
215 const struct ipt_ip *ip = info;
216 const struct xt_udp *udpinfo = matchinfo;
217
218 /* Must specify proto == UDP, and no unknown invflags */
219 if (ip->proto != IPPROTO_UDP || (ip->invflags & XT_INV_PROTO)) {
220 duprintf("ipt_udp: Protocol %u != %u\n", ip->proto,
221 IPPROTO_UDP);
222 return 0;
223 }
224 if (matchinfosize != XT_ALIGN(sizeof(struct xt_udp))) {
225 duprintf("ipt_udp: matchsize %u != %u\n",
226 matchinfosize, XT_ALIGN(sizeof(struct xt_udp)));
227 return 0;
228 }
229 if (udpinfo->invflags & ~XT_UDP_INV_MASK) {
230 duprintf("ipt_udp: unknown flags %X\n",
231 udpinfo->invflags);
232 return 0;
233 }
234
235 return 1;
236}
237
238/* Called when user tries to insert an entry of this type. */
239static int
240udp6_checkentry(const char *tablename,
241 const void *entry,
242 void *matchinfo,
243 unsigned int matchinfosize,
244 unsigned int hook_mask) 194 unsigned int hook_mask)
245{ 195{
246 const struct ip6t_ip6 *ipv6 = entry; 196 const struct xt_tcp *udpinfo = matchinfo;
247 const struct xt_udp *udpinfo = matchinfo;
248 197
249 /* Must specify proto == UDP, and no unknown invflags */ 198 /* Must specify no unknown invflags */
250 if (ipv6->proto != IPPROTO_UDP || (ipv6->invflags & XT_INV_PROTO)) { 199 return !(udpinfo->invflags & ~XT_UDP_INV_MASK);
251 duprintf("ip6t_udp: Protocol %u != %u\n", ipv6->proto,
252 IPPROTO_UDP);
253 return 0;
254 }
255 if (matchinfosize != XT_ALIGN(sizeof(struct xt_udp))) {
256 duprintf("ip6t_udp: matchsize %u != %u\n",
257 matchinfosize, XT_ALIGN(sizeof(struct xt_udp)));
258 return 0;
259 }
260 if (udpinfo->invflags & ~XT_UDP_INV_MASK) {
261 duprintf("ip6t_udp: unknown flags %X\n",
262 udpinfo->invflags);
263 return 0;
264 }
265
266 return 1;
267} 200}
268 201
269static struct xt_match tcp_matchstruct = { 202static struct xt_match tcp_matchstruct = {
270 .name = "tcp", 203 .name = "tcp",
271 .match = &tcp_match, 204 .match = tcp_match,
272 .checkentry = &tcp_checkentry, 205 .matchsize = sizeof(struct xt_tcp),
206 .proto = IPPROTO_TCP,
207 .checkentry = tcp_checkentry,
273 .me = THIS_MODULE, 208 .me = THIS_MODULE,
274}; 209};
210
275static struct xt_match tcp6_matchstruct = { 211static struct xt_match tcp6_matchstruct = {
276 .name = "tcp", 212 .name = "tcp",
277 .match = &tcp_match, 213 .match = tcp_match,
278 .checkentry = &tcp6_checkentry, 214 .matchsize = sizeof(struct xt_tcp),
215 .proto = IPPROTO_TCP,
216 .checkentry = tcp_checkentry,
279 .me = THIS_MODULE, 217 .me = THIS_MODULE,
280}; 218};
281 219
282static struct xt_match udp_matchstruct = { 220static struct xt_match udp_matchstruct = {
283 .name = "udp", 221 .name = "udp",
284 .match = &udp_match, 222 .match = udp_match,
285 .checkentry = &udp_checkentry, 223 .matchsize = sizeof(struct xt_udp),
224 .proto = IPPROTO_UDP,
225 .checkentry = udp_checkentry,
286 .me = THIS_MODULE, 226 .me = THIS_MODULE,
287}; 227};
288static struct xt_match udp6_matchstruct = { 228static struct xt_match udp6_matchstruct = {
289 .name = "udp", 229 .name = "udp",
290 .match = &udp_match, 230 .match = udp_match,
291 .checkentry = &udp6_checkentry, 231 .matchsize = sizeof(struct xt_udp),
232 .proto = IPPROTO_UDP,
233 .checkentry = udp_checkentry,
292 .me = THIS_MODULE, 234 .me = THIS_MODULE,
293}; 235};
294 236
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 59dc7d140600..d00a9034cb5f 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -106,6 +106,7 @@ struct nl_pid_hash {
106struct netlink_table { 106struct netlink_table {
107 struct nl_pid_hash hash; 107 struct nl_pid_hash hash;
108 struct hlist_head mc_list; 108 struct hlist_head mc_list;
109 unsigned long *listeners;
109 unsigned int nl_nonroot; 110 unsigned int nl_nonroot;
110 unsigned int groups; 111 unsigned int groups;
111 struct module *module; 112 struct module *module;
@@ -296,6 +297,24 @@ static inline int nl_pid_hash_dilute(struct nl_pid_hash *hash, int len)
296 297
297static const struct proto_ops netlink_ops; 298static const struct proto_ops netlink_ops;
298 299
300static void
301netlink_update_listeners(struct sock *sk)
302{
303 struct netlink_table *tbl = &nl_table[sk->sk_protocol];
304 struct hlist_node *node;
305 unsigned long mask;
306 unsigned int i;
307
308 for (i = 0; i < NLGRPSZ(tbl->groups)/sizeof(unsigned long); i++) {
309 mask = 0;
310 sk_for_each_bound(sk, node, &tbl->mc_list)
311 mask |= nlk_sk(sk)->groups[i];
312 tbl->listeners[i] = mask;
313 }
314 /* this function is only called with the netlink table "grabbed", which
315 * makes sure updates are visible before bind or setsockopt return. */
316}
317
299static int netlink_insert(struct sock *sk, u32 pid) 318static int netlink_insert(struct sock *sk, u32 pid)
300{ 319{
301 struct nl_pid_hash *hash = &nl_table[sk->sk_protocol].hash; 320 struct nl_pid_hash *hash = &nl_table[sk->sk_protocol].hash;
@@ -456,12 +475,14 @@ static int netlink_release(struct socket *sock)
456 if (nlk->module) 475 if (nlk->module)
457 module_put(nlk->module); 476 module_put(nlk->module);
458 477
478 netlink_table_grab();
459 if (nlk->flags & NETLINK_KERNEL_SOCKET) { 479 if (nlk->flags & NETLINK_KERNEL_SOCKET) {
460 netlink_table_grab(); 480 kfree(nl_table[sk->sk_protocol].listeners);
461 nl_table[sk->sk_protocol].module = NULL; 481 nl_table[sk->sk_protocol].module = NULL;
462 nl_table[sk->sk_protocol].registered = 0; 482 nl_table[sk->sk_protocol].registered = 0;
463 netlink_table_ungrab(); 483 } else if (nlk->subscriptions)
464 } 484 netlink_update_listeners(sk);
485 netlink_table_ungrab();
465 486
466 kfree(nlk->groups); 487 kfree(nlk->groups);
467 nlk->groups = NULL; 488 nlk->groups = NULL;
@@ -589,6 +610,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, int addr_len
589 hweight32(nladdr->nl_groups) - 610 hweight32(nladdr->nl_groups) -
590 hweight32(nlk->groups[0])); 611 hweight32(nlk->groups[0]));
591 nlk->groups[0] = (nlk->groups[0] & ~0xffffffffUL) | nladdr->nl_groups; 612 nlk->groups[0] = (nlk->groups[0] & ~0xffffffffUL) | nladdr->nl_groups;
613 netlink_update_listeners(sk);
592 netlink_table_ungrab(); 614 netlink_table_ungrab();
593 615
594 return 0; 616 return 0;
@@ -807,6 +829,17 @@ retry:
807 return netlink_sendskb(sk, skb, ssk->sk_protocol); 829 return netlink_sendskb(sk, skb, ssk->sk_protocol);
808} 830}
809 831
832int netlink_has_listeners(struct sock *sk, unsigned int group)
833{
834 int res = 0;
835
836 BUG_ON(!(nlk_sk(sk)->flags & NETLINK_KERNEL_SOCKET));
837 if (group - 1 < nl_table[sk->sk_protocol].groups)
838 res = test_bit(group - 1, nl_table[sk->sk_protocol].listeners);
839 return res;
840}
841EXPORT_SYMBOL_GPL(netlink_has_listeners);
842
810static __inline__ int netlink_broadcast_deliver(struct sock *sk, struct sk_buff *skb) 843static __inline__ int netlink_broadcast_deliver(struct sock *sk, struct sk_buff *skb)
811{ 844{
812 struct netlink_sock *nlk = nlk_sk(sk); 845 struct netlink_sock *nlk = nlk_sk(sk);
@@ -1011,6 +1044,7 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname,
1011 else 1044 else
1012 __clear_bit(val - 1, nlk->groups); 1045 __clear_bit(val - 1, nlk->groups);
1013 netlink_update_subscriptions(sk, subscriptions); 1046 netlink_update_subscriptions(sk, subscriptions);
1047 netlink_update_listeners(sk);
1014 netlink_table_ungrab(); 1048 netlink_table_ungrab();
1015 err = 0; 1049 err = 0;
1016 break; 1050 break;
@@ -1237,6 +1271,7 @@ netlink_kernel_create(int unit, unsigned int groups,
1237 struct socket *sock; 1271 struct socket *sock;
1238 struct sock *sk; 1272 struct sock *sk;
1239 struct netlink_sock *nlk; 1273 struct netlink_sock *nlk;
1274 unsigned long *listeners = NULL;
1240 1275
1241 if (!nl_table) 1276 if (!nl_table)
1242 return NULL; 1277 return NULL;
@@ -1250,6 +1285,13 @@ netlink_kernel_create(int unit, unsigned int groups,
1250 if (__netlink_create(sock, unit) < 0) 1285 if (__netlink_create(sock, unit) < 0)
1251 goto out_sock_release; 1286 goto out_sock_release;
1252 1287
1288 if (groups < 32)
1289 groups = 32;
1290
1291 listeners = kzalloc(NLGRPSZ(groups), GFP_KERNEL);
1292 if (!listeners)
1293 goto out_sock_release;
1294
1253 sk = sock->sk; 1295 sk = sock->sk;
1254 sk->sk_data_ready = netlink_data_ready; 1296 sk->sk_data_ready = netlink_data_ready;
1255 if (input) 1297 if (input)
@@ -1262,7 +1304,8 @@ netlink_kernel_create(int unit, unsigned int groups,
1262 nlk->flags |= NETLINK_KERNEL_SOCKET; 1304 nlk->flags |= NETLINK_KERNEL_SOCKET;
1263 1305
1264 netlink_table_grab(); 1306 netlink_table_grab();
1265 nl_table[unit].groups = groups < 32 ? 32 : groups; 1307 nl_table[unit].groups = groups;
1308 nl_table[unit].listeners = listeners;
1266 nl_table[unit].module = module; 1309 nl_table[unit].module = module;
1267 nl_table[unit].registered = 1; 1310 nl_table[unit].registered = 1;
1268 netlink_table_ungrab(); 1311 netlink_table_ungrab();
@@ -1270,6 +1313,7 @@ netlink_kernel_create(int unit, unsigned int groups,
1270 return sk; 1313 return sk;
1271 1314
1272out_sock_release: 1315out_sock_release:
1316 kfree(listeners);
1273 sock_release(sock); 1317 sock_release(sock);
1274 return NULL; 1318 return NULL;
1275} 1319}
diff --git a/net/sched/Kconfig b/net/sched/Kconfig
index 778b1e5a4b50..13eeee582886 100644
--- a/net/sched/Kconfig
+++ b/net/sched/Kconfig
@@ -434,7 +434,6 @@ config NET_EMATCH_TEXT
434 434
435config NET_CLS_ACT 435config NET_CLS_ACT
436 bool "Actions" 436 bool "Actions"
437 depends on EXPERIMENTAL
438 select NET_ESTIMATOR 437 select NET_ESTIMATOR
439 ---help--- 438 ---help---
440 Say Y here if you want to use traffic control actions. Actions 439 Say Y here if you want to use traffic control actions. Actions
diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c
index 39a22a3ffe78..6056d20ef429 100644
--- a/net/sched/act_ipt.c
+++ b/net/sched/act_ipt.c
@@ -70,7 +70,8 @@ ipt_init_target(struct ipt_entry_target *t, char *table, unsigned int hook)
70 t->u.kernel.target = target; 70 t->u.kernel.target = target;
71 71
72 if (t->u.kernel.target->checkentry 72 if (t->u.kernel.target->checkentry
73 && !t->u.kernel.target->checkentry(table, NULL, t->data, 73 && !t->u.kernel.target->checkentry(table, NULL,
74 t->u.kernel.target, t->data,
74 t->u.target_size - sizeof(*t), 75 t->u.target_size - sizeof(*t),
75 hook)) { 76 hook)) {
76 DPRINTK("ipt_init_target: check failed for `%s'.\n", 77 DPRINTK("ipt_init_target: check failed for `%s'.\n",
@@ -86,7 +87,7 @@ static void
86ipt_destroy_target(struct ipt_entry_target *t) 87ipt_destroy_target(struct ipt_entry_target *t)
87{ 88{
88 if (t->u.kernel.target->destroy) 89 if (t->u.kernel.target->destroy)
89 t->u.kernel.target->destroy(t->data, 90 t->u.kernel.target->destroy(t->u.kernel.target, t->data,
90 t->u.target_size - sizeof(*t)); 91 t->u.target_size - sizeof(*t));
91 module_put(t->u.kernel.target->me); 92 module_put(t->u.kernel.target->me);
92} 93}
@@ -224,8 +225,9 @@ tcf_ipt(struct sk_buff *skb, struct tc_action *a, struct tcf_result *res)
224 /* iptables targets take a double skb pointer in case the skb 225 /* iptables targets take a double skb pointer in case the skb
225 * needs to be replaced. We don't own the skb, so this must not 226 * needs to be replaced. We don't own the skb, so this must not
226 * happen. The pskb_expand_head above should make sure of this */ 227 * happen. The pskb_expand_head above should make sure of this */
227 ret = p->t->u.kernel.target->target(&skb, skb->dev, NULL, 228 ret = p->t->u.kernel.target->target(&skb, skb->dev, NULL, p->hook,
228 p->hook, p->t->data, NULL); 229 p->t->u.kernel.target, p->t->data,
230 NULL);
229 switch (ret) { 231 switch (ret) {
230 case NF_ACCEPT: 232 case NF_ACCEPT:
231 result = TC_ACT_OK; 233 result = TC_ACT_OK;
diff --git a/net/sched/sch_atm.c b/net/sched/sch_atm.c
index 93ebce40acac..ac7cb60d1e25 100644
--- a/net/sched/sch_atm.c
+++ b/net/sched/sch_atm.c
@@ -638,6 +638,7 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
638 sch,p,flow,skb,tcm); 638 sch,p,flow,skb,tcm);
639 if (!find_flow(p,flow)) return -EINVAL; 639 if (!find_flow(p,flow)) return -EINVAL;
640 tcm->tcm_handle = flow->classid; 640 tcm->tcm_handle = flow->classid;
641 tcm->tcm_info = flow->q->handle;
641 rta = (struct rtattr *) b; 642 rta = (struct rtattr *) b;
642 RTA_PUT(skb,TCA_OPTIONS,0,NULL); 643 RTA_PUT(skb,TCA_OPTIONS,0,NULL);
643 RTA_PUT(skb,TCA_ATM_HDR,flow->hdr_len,flow->hdr); 644 RTA_PUT(skb,TCA_ATM_HDR,flow->hdr_len,flow->hdr);
diff --git a/net/sched/sch_dsmark.c b/net/sched/sch_dsmark.c
index 13e0e7b3856b..f6320ca70493 100644
--- a/net/sched/sch_dsmark.c
+++ b/net/sched/sch_dsmark.c
@@ -438,6 +438,7 @@ static int dsmark_dump_class(struct Qdisc *sch, unsigned long cl,
438 return -EINVAL; 438 return -EINVAL;
439 439
440 tcm->tcm_handle = TC_H_MAKE(TC_H_MAJ(sch->handle), cl-1); 440 tcm->tcm_handle = TC_H_MAKE(TC_H_MAJ(sch->handle), cl-1);
441 tcm->tcm_info = p->q->handle;
441 442
442 opts = RTA_NEST(skb, TCA_OPTIONS); 443 opts = RTA_NEST(skb, TCA_OPTIONS);
443 RTA_PUT_U8(skb,TCA_DSMARK_MASK, p->mask[cl-1]); 444 RTA_PUT_U8(skb,TCA_DSMARK_MASK, p->mask[cl-1]);
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index 99ceb91f0150..31eb83717c26 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -234,7 +234,7 @@ static void dev_watchdog_down(struct net_device *dev)
234{ 234{
235 spin_lock_bh(&dev->xmit_lock); 235 spin_lock_bh(&dev->xmit_lock);
236 if (del_timer(&dev->watchdog_timer)) 236 if (del_timer(&dev->watchdog_timer))
237 __dev_put(dev); 237 dev_put(dev);
238 spin_unlock_bh(&dev->xmit_lock); 238 spin_unlock_bh(&dev->xmit_lock);
239} 239}
240 240
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index ba5283204837..7228d30512c7 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -252,9 +252,9 @@ static int netem_requeue(struct sk_buff *skb, struct Qdisc *sch)
252static unsigned int netem_drop(struct Qdisc* sch) 252static unsigned int netem_drop(struct Qdisc* sch)
253{ 253{
254 struct netem_sched_data *q = qdisc_priv(sch); 254 struct netem_sched_data *q = qdisc_priv(sch);
255 unsigned int len; 255 unsigned int len = 0;
256 256
257 if ((len = q->qdisc->ops->drop(q->qdisc)) != 0) { 257 if (q->qdisc->ops->drop && (len = q->qdisc->ops->drop(q->qdisc)) != 0) {
258 sch->q.qlen--; 258 sch->q.qlen--;
259 sch->qstats.drops++; 259 sch->qstats.drops++;
260 } 260 }
diff --git a/net/sched/sch_prio.c b/net/sched/sch_prio.c
index 1641db33a994..3395ca7bcadf 100644
--- a/net/sched/sch_prio.c
+++ b/net/sched/sch_prio.c
@@ -165,7 +165,7 @@ static unsigned int prio_drop(struct Qdisc* sch)
165 165
166 for (prio = q->bands-1; prio >= 0; prio--) { 166 for (prio = q->bands-1; prio >= 0; prio--) {
167 qdisc = q->queues[prio]; 167 qdisc = q->queues[prio];
168 if ((len = qdisc->ops->drop(qdisc)) != 0) { 168 if (qdisc->ops->drop && (len = qdisc->ops->drop(qdisc)) != 0) {
169 sch->q.qlen--; 169 sch->q.qlen--;
170 return len; 170 return len;
171 } 171 }
diff --git a/net/sched/sch_red.c b/net/sched/sch_red.c
index dccfa44c2d71..2be563cba72b 100644
--- a/net/sched/sch_red.c
+++ b/net/sched/sch_red.c
@@ -44,6 +44,7 @@ struct red_sched_data
44 unsigned char flags; 44 unsigned char flags;
45 struct red_parms parms; 45 struct red_parms parms;
46 struct red_stats stats; 46 struct red_stats stats;
47 struct Qdisc *qdisc;
47}; 48};
48 49
49static inline int red_use_ecn(struct red_sched_data *q) 50static inline int red_use_ecn(struct red_sched_data *q)
@@ -59,8 +60,10 @@ static inline int red_use_harddrop(struct red_sched_data *q)
59static int red_enqueue(struct sk_buff *skb, struct Qdisc* sch) 60static int red_enqueue(struct sk_buff *skb, struct Qdisc* sch)
60{ 61{
61 struct red_sched_data *q = qdisc_priv(sch); 62 struct red_sched_data *q = qdisc_priv(sch);
63 struct Qdisc *child = q->qdisc;
64 int ret;
62 65
63 q->parms.qavg = red_calc_qavg(&q->parms, sch->qstats.backlog); 66 q->parms.qavg = red_calc_qavg(&q->parms, child->qstats.backlog);
64 67
65 if (red_is_idling(&q->parms)) 68 if (red_is_idling(&q->parms))
66 red_end_of_idle_period(&q->parms); 69 red_end_of_idle_period(&q->parms);
@@ -91,11 +94,16 @@ static int red_enqueue(struct sk_buff *skb, struct Qdisc* sch)
91 break; 94 break;
92 } 95 }
93 96
94 if (sch->qstats.backlog + skb->len <= q->limit) 97 ret = child->enqueue(skb, child);
95 return qdisc_enqueue_tail(skb, sch); 98 if (likely(ret == NET_XMIT_SUCCESS)) {
96 99 sch->bstats.bytes += skb->len;
97 q->stats.pdrop++; 100 sch->bstats.packets++;
98 return qdisc_drop(skb, sch); 101 sch->q.qlen++;
102 } else {
103 q->stats.pdrop++;
104 sch->qstats.drops++;
105 }
106 return ret;
99 107
100congestion_drop: 108congestion_drop:
101 qdisc_drop(skb, sch); 109 qdisc_drop(skb, sch);
@@ -105,21 +113,30 @@ congestion_drop:
105static int red_requeue(struct sk_buff *skb, struct Qdisc* sch) 113static int red_requeue(struct sk_buff *skb, struct Qdisc* sch)
106{ 114{
107 struct red_sched_data *q = qdisc_priv(sch); 115 struct red_sched_data *q = qdisc_priv(sch);
116 struct Qdisc *child = q->qdisc;
117 int ret;
108 118
109 if (red_is_idling(&q->parms)) 119 if (red_is_idling(&q->parms))
110 red_end_of_idle_period(&q->parms); 120 red_end_of_idle_period(&q->parms);
111 121
112 return qdisc_requeue(skb, sch); 122 ret = child->ops->requeue(skb, child);
123 if (likely(ret == NET_XMIT_SUCCESS)) {
124 sch->qstats.requeues++;
125 sch->q.qlen++;
126 }
127 return ret;
113} 128}
114 129
115static struct sk_buff * red_dequeue(struct Qdisc* sch) 130static struct sk_buff * red_dequeue(struct Qdisc* sch)
116{ 131{
117 struct sk_buff *skb; 132 struct sk_buff *skb;
118 struct red_sched_data *q = qdisc_priv(sch); 133 struct red_sched_data *q = qdisc_priv(sch);
134 struct Qdisc *child = q->qdisc;
119 135
120 skb = qdisc_dequeue_head(sch); 136 skb = child->dequeue(child);
121 137 if (skb)
122 if (skb == NULL && !red_is_idling(&q->parms)) 138 sch->q.qlen--;
139 else if (!red_is_idling(&q->parms))
123 red_start_of_idle_period(&q->parms); 140 red_start_of_idle_period(&q->parms);
124 141
125 return skb; 142 return skb;
@@ -127,14 +144,14 @@ static struct sk_buff * red_dequeue(struct Qdisc* sch)
127 144
128static unsigned int red_drop(struct Qdisc* sch) 145static unsigned int red_drop(struct Qdisc* sch)
129{ 146{
130 struct sk_buff *skb;
131 struct red_sched_data *q = qdisc_priv(sch); 147 struct red_sched_data *q = qdisc_priv(sch);
148 struct Qdisc *child = q->qdisc;
149 unsigned int len;
132 150
133 skb = qdisc_dequeue_tail(sch); 151 if (child->ops->drop && (len = child->ops->drop(child)) > 0) {
134 if (skb) {
135 unsigned int len = skb->len;
136 q->stats.other++; 152 q->stats.other++;
137 qdisc_drop(skb, sch); 153 sch->qstats.drops++;
154 sch->q.qlen--;
138 return len; 155 return len;
139 } 156 }
140 157
@@ -148,15 +165,48 @@ static void red_reset(struct Qdisc* sch)
148{ 165{
149 struct red_sched_data *q = qdisc_priv(sch); 166 struct red_sched_data *q = qdisc_priv(sch);
150 167
151 qdisc_reset_queue(sch); 168 qdisc_reset(q->qdisc);
169 sch->q.qlen = 0;
152 red_restart(&q->parms); 170 red_restart(&q->parms);
153} 171}
154 172
173static void red_destroy(struct Qdisc *sch)
174{
175 struct red_sched_data *q = qdisc_priv(sch);
176 qdisc_destroy(q->qdisc);
177}
178
179static struct Qdisc *red_create_dflt(struct net_device *dev, u32 limit)
180{
181 struct Qdisc *q = qdisc_create_dflt(dev, &bfifo_qdisc_ops);
182 struct rtattr *rta;
183 int ret;
184
185 if (q) {
186 rta = kmalloc(RTA_LENGTH(sizeof(struct tc_fifo_qopt)),
187 GFP_KERNEL);
188 if (rta) {
189 rta->rta_type = RTM_NEWQDISC;
190 rta->rta_len = RTA_LENGTH(sizeof(struct tc_fifo_qopt));
191 ((struct tc_fifo_qopt *)RTA_DATA(rta))->limit = limit;
192
193 ret = q->ops->change(q, rta);
194 kfree(rta);
195
196 if (ret == 0)
197 return q;
198 }
199 qdisc_destroy(q);
200 }
201 return NULL;
202}
203
155static int red_change(struct Qdisc *sch, struct rtattr *opt) 204static int red_change(struct Qdisc *sch, struct rtattr *opt)
156{ 205{
157 struct red_sched_data *q = qdisc_priv(sch); 206 struct red_sched_data *q = qdisc_priv(sch);
158 struct rtattr *tb[TCA_RED_MAX]; 207 struct rtattr *tb[TCA_RED_MAX];
159 struct tc_red_qopt *ctl; 208 struct tc_red_qopt *ctl;
209 struct Qdisc *child = NULL;
160 210
161 if (opt == NULL || rtattr_parse_nested(tb, TCA_RED_MAX, opt)) 211 if (opt == NULL || rtattr_parse_nested(tb, TCA_RED_MAX, opt))
162 return -EINVAL; 212 return -EINVAL;
@@ -169,9 +219,17 @@ static int red_change(struct Qdisc *sch, struct rtattr *opt)
169 219
170 ctl = RTA_DATA(tb[TCA_RED_PARMS-1]); 220 ctl = RTA_DATA(tb[TCA_RED_PARMS-1]);
171 221
222 if (ctl->limit > 0) {
223 child = red_create_dflt(sch->dev, ctl->limit);
224 if (child == NULL)
225 return -ENOMEM;
226 }
227
172 sch_tree_lock(sch); 228 sch_tree_lock(sch);
173 q->flags = ctl->flags; 229 q->flags = ctl->flags;
174 q->limit = ctl->limit; 230 q->limit = ctl->limit;
231 if (child)
232 qdisc_destroy(xchg(&q->qdisc, child));
175 233
176 red_set_parms(&q->parms, ctl->qth_min, ctl->qth_max, ctl->Wlog, 234 red_set_parms(&q->parms, ctl->qth_min, ctl->qth_max, ctl->Wlog,
177 ctl->Plog, ctl->Scell_log, 235 ctl->Plog, ctl->Scell_log,
@@ -186,6 +244,9 @@ static int red_change(struct Qdisc *sch, struct rtattr *opt)
186 244
187static int red_init(struct Qdisc* sch, struct rtattr *opt) 245static int red_init(struct Qdisc* sch, struct rtattr *opt)
188{ 246{
247 struct red_sched_data *q = qdisc_priv(sch);
248
249 q->qdisc = &noop_qdisc;
189 return red_change(sch, opt); 250 return red_change(sch, opt);
190} 251}
191 252
@@ -224,15 +285,101 @@ static int red_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
224 return gnet_stats_copy_app(d, &st, sizeof(st)); 285 return gnet_stats_copy_app(d, &st, sizeof(st));
225} 286}
226 287
288static int red_dump_class(struct Qdisc *sch, unsigned long cl,
289 struct sk_buff *skb, struct tcmsg *tcm)
290{
291 struct red_sched_data *q = qdisc_priv(sch);
292
293 if (cl != 1)
294 return -ENOENT;
295 tcm->tcm_handle |= TC_H_MIN(1);
296 tcm->tcm_info = q->qdisc->handle;
297 return 0;
298}
299
300static int red_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
301 struct Qdisc **old)
302{
303 struct red_sched_data *q = qdisc_priv(sch);
304
305 if (new == NULL)
306 new = &noop_qdisc;
307
308 sch_tree_lock(sch);
309 *old = xchg(&q->qdisc, new);
310 qdisc_reset(*old);
311 sch->q.qlen = 0;
312 sch_tree_unlock(sch);
313 return 0;
314}
315
316static struct Qdisc *red_leaf(struct Qdisc *sch, unsigned long arg)
317{
318 struct red_sched_data *q = qdisc_priv(sch);
319 return q->qdisc;
320}
321
322static unsigned long red_get(struct Qdisc *sch, u32 classid)
323{
324 return 1;
325}
326
327static void red_put(struct Qdisc *sch, unsigned long arg)
328{
329 return;
330}
331
332static int red_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
333 struct rtattr **tca, unsigned long *arg)
334{
335 return -ENOSYS;
336}
337
338static int red_delete(struct Qdisc *sch, unsigned long cl)
339{
340 return -ENOSYS;
341}
342
343static void red_walk(struct Qdisc *sch, struct qdisc_walker *walker)
344{
345 if (!walker->stop) {
346 if (walker->count >= walker->skip)
347 if (walker->fn(sch, 1, walker) < 0) {
348 walker->stop = 1;
349 return;
350 }
351 walker->count++;
352 }
353}
354
355static struct tcf_proto **red_find_tcf(struct Qdisc *sch, unsigned long cl)
356{
357 return NULL;
358}
359
360static struct Qdisc_class_ops red_class_ops = {
361 .graft = red_graft,
362 .leaf = red_leaf,
363 .get = red_get,
364 .put = red_put,
365 .change = red_change_class,
366 .delete = red_delete,
367 .walk = red_walk,
368 .tcf_chain = red_find_tcf,
369 .dump = red_dump_class,
370};
371
227static struct Qdisc_ops red_qdisc_ops = { 372static struct Qdisc_ops red_qdisc_ops = {
228 .id = "red", 373 .id = "red",
229 .priv_size = sizeof(struct red_sched_data), 374 .priv_size = sizeof(struct red_sched_data),
375 .cl_ops = &red_class_ops,
230 .enqueue = red_enqueue, 376 .enqueue = red_enqueue,
231 .dequeue = red_dequeue, 377 .dequeue = red_dequeue,
232 .requeue = red_requeue, 378 .requeue = red_requeue,
233 .drop = red_drop, 379 .drop = red_drop,
234 .init = red_init, 380 .init = red_init,
235 .reset = red_reset, 381 .reset = red_reset,
382 .destroy = red_destroy,
236 .change = red_change, 383 .change = red_change,
237 .dump = red_dump, 384 .dump = red_dump,
238 .dump_stats = red_dump_stats, 385 .dump_stats = red_dump_stats,
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c
index 86d8da0cbd02..e057768f68b4 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -232,6 +232,7 @@ static unsigned int sfq_drop(struct Qdisc *sch)
232 sfq_dec(q, x); 232 sfq_dec(q, x);
233 sch->q.qlen--; 233 sch->q.qlen--;
234 sch->qstats.drops++; 234 sch->qstats.drops++;
235 sch->qstats.backlog -= len;
235 return len; 236 return len;
236 } 237 }
237 238
@@ -248,6 +249,7 @@ static unsigned int sfq_drop(struct Qdisc *sch)
248 sch->q.qlen--; 249 sch->q.qlen--;
249 q->ht[q->hash[d]] = SFQ_DEPTH; 250 q->ht[q->hash[d]] = SFQ_DEPTH;
250 sch->qstats.drops++; 251 sch->qstats.drops++;
252 sch->qstats.backlog -= len;
251 return len; 253 return len;
252 } 254 }
253 255
@@ -266,6 +268,7 @@ sfq_enqueue(struct sk_buff *skb, struct Qdisc* sch)
266 q->ht[hash] = x = q->dep[SFQ_DEPTH].next; 268 q->ht[hash] = x = q->dep[SFQ_DEPTH].next;
267 q->hash[x] = hash; 269 q->hash[x] = hash;
268 } 270 }
271 sch->qstats.backlog += skb->len;
269 __skb_queue_tail(&q->qs[x], skb); 272 __skb_queue_tail(&q->qs[x], skb);
270 sfq_inc(q, x); 273 sfq_inc(q, x);
271 if (q->qs[x].qlen == 1) { /* The flow is new */ 274 if (q->qs[x].qlen == 1) { /* The flow is new */
@@ -301,6 +304,7 @@ sfq_requeue(struct sk_buff *skb, struct Qdisc* sch)
301 q->ht[hash] = x = q->dep[SFQ_DEPTH].next; 304 q->ht[hash] = x = q->dep[SFQ_DEPTH].next;
302 q->hash[x] = hash; 305 q->hash[x] = hash;
303 } 306 }
307 sch->qstats.backlog += skb->len;
304 __skb_queue_head(&q->qs[x], skb); 308 __skb_queue_head(&q->qs[x], skb);
305 sfq_inc(q, x); 309 sfq_inc(q, x);
306 if (q->qs[x].qlen == 1) { /* The flow is new */ 310 if (q->qs[x].qlen == 1) { /* The flow is new */
@@ -344,6 +348,7 @@ sfq_dequeue(struct Qdisc* sch)
344 skb = __skb_dequeue(&q->qs[a]); 348 skb = __skb_dequeue(&q->qs[a]);
345 sfq_dec(q, a); 349 sfq_dec(q, a);
346 sch->q.qlen--; 350 sch->q.qlen--;
351 sch->qstats.backlog -= skb->len;
347 352
348 /* Is the slot empty? */ 353 /* Is the slot empty? */
349 if (q->qs[a].qlen == 0) { 354 if (q->qs[a].qlen == 0) {
diff --git a/net/sched/sch_tbf.c b/net/sched/sch_tbf.c
index cb9711ea8c6c..d8e03c74ca76 100644
--- a/net/sched/sch_tbf.c
+++ b/net/sched/sch_tbf.c
@@ -177,9 +177,9 @@ static int tbf_requeue(struct sk_buff *skb, struct Qdisc* sch)
177static unsigned int tbf_drop(struct Qdisc* sch) 177static unsigned int tbf_drop(struct Qdisc* sch)
178{ 178{
179 struct tbf_sched_data *q = qdisc_priv(sch); 179 struct tbf_sched_data *q = qdisc_priv(sch);
180 unsigned int len; 180 unsigned int len = 0;
181 181
182 if ((len = q->qdisc->ops->drop(q->qdisc)) != 0) { 182 if (q->qdisc->ops->drop && (len = q->qdisc->ops->drop(q->qdisc)) != 0) {
183 sch->q.qlen--; 183 sch->q.qlen--;
184 sch->qstats.drops++; 184 sch->qstats.drops++;
185 } 185 }
@@ -341,13 +341,14 @@ static int tbf_change(struct Qdisc* sch, struct rtattr *opt)
341 if (max_size < 0) 341 if (max_size < 0)
342 goto done; 342 goto done;
343 343
344 if (q->qdisc == &noop_qdisc) { 344 if (qopt->limit > 0) {
345 if ((child = tbf_create_dflt_qdisc(sch->dev, qopt->limit)) == NULL) 345 if ((child = tbf_create_dflt_qdisc(sch->dev, qopt->limit)) == NULL)
346 goto done; 346 goto done;
347 } 347 }
348 348
349 sch_tree_lock(sch); 349 sch_tree_lock(sch);
350 if (child) q->qdisc = child; 350 if (child)
351 qdisc_destroy(xchg(&q->qdisc, child));
351 q->limit = qopt->limit; 352 q->limit = qopt->limit;
352 q->mtu = qopt->mtu; 353 q->mtu = qopt->mtu;
353 q->max_size = max_size; 354 q->max_size = max_size;
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 2e266129a764..c20d282fac06 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -861,23 +861,27 @@ static int sctp_inet6_supported_addrs(const struct sctp_sock *opt,
861} 861}
862 862
863static const struct proto_ops inet6_seqpacket_ops = { 863static const struct proto_ops inet6_seqpacket_ops = {
864 .family = PF_INET6, 864 .family = PF_INET6,
865 .owner = THIS_MODULE, 865 .owner = THIS_MODULE,
866 .release = inet6_release, 866 .release = inet6_release,
867 .bind = inet6_bind, 867 .bind = inet6_bind,
868 .connect = inet_dgram_connect, 868 .connect = inet_dgram_connect,
869 .socketpair = sock_no_socketpair, 869 .socketpair = sock_no_socketpair,
870 .accept = inet_accept, 870 .accept = inet_accept,
871 .getname = inet6_getname, 871 .getname = inet6_getname,
872 .poll = sctp_poll, 872 .poll = sctp_poll,
873 .ioctl = inet6_ioctl, 873 .ioctl = inet6_ioctl,
874 .listen = sctp_inet_listen, 874 .listen = sctp_inet_listen,
875 .shutdown = inet_shutdown, 875 .shutdown = inet_shutdown,
876 .setsockopt = sock_common_setsockopt, 876 .setsockopt = sock_common_setsockopt,
877 .getsockopt = sock_common_getsockopt, 877 .getsockopt = sock_common_getsockopt,
878 .sendmsg = inet_sendmsg, 878 .sendmsg = inet_sendmsg,
879 .recvmsg = sock_common_recvmsg, 879 .recvmsg = sock_common_recvmsg,
880 .mmap = sock_no_mmap, 880 .mmap = sock_no_mmap,
881#ifdef CONFIG_COMPAT
882 .compat_setsockopt = compat_sock_common_setsockopt,
883 .compat_getsockopt = compat_sock_common_getsockopt,
884#endif
881}; 885};
882 886
883static struct inet_protosw sctpv6_seqpacket_protosw = { 887static struct inet_protosw sctpv6_seqpacket_protosw = {
@@ -911,31 +915,35 @@ static struct inet6_protocol sctpv6_protocol = {
911}; 915};
912 916
913static struct sctp_af sctp_ipv6_specific = { 917static struct sctp_af sctp_ipv6_specific = {
914 .sctp_xmit = sctp_v6_xmit, 918 .sa_family = AF_INET6,
915 .setsockopt = ipv6_setsockopt, 919 .sctp_xmit = sctp_v6_xmit,
916 .getsockopt = ipv6_getsockopt, 920 .setsockopt = ipv6_setsockopt,
917 .get_dst = sctp_v6_get_dst, 921 .getsockopt = ipv6_getsockopt,
918 .get_saddr = sctp_v6_get_saddr, 922 .get_dst = sctp_v6_get_dst,
919 .copy_addrlist = sctp_v6_copy_addrlist, 923 .get_saddr = sctp_v6_get_saddr,
920 .from_skb = sctp_v6_from_skb, 924 .copy_addrlist = sctp_v6_copy_addrlist,
921 .from_sk = sctp_v6_from_sk, 925 .from_skb = sctp_v6_from_skb,
922 .to_sk_saddr = sctp_v6_to_sk_saddr, 926 .from_sk = sctp_v6_from_sk,
923 .to_sk_daddr = sctp_v6_to_sk_daddr, 927 .to_sk_saddr = sctp_v6_to_sk_saddr,
924 .from_addr_param = sctp_v6_from_addr_param, 928 .to_sk_daddr = sctp_v6_to_sk_daddr,
925 .to_addr_param = sctp_v6_to_addr_param, 929 .from_addr_param = sctp_v6_from_addr_param,
926 .dst_saddr = sctp_v6_dst_saddr, 930 .to_addr_param = sctp_v6_to_addr_param,
927 .cmp_addr = sctp_v6_cmp_addr, 931 .dst_saddr = sctp_v6_dst_saddr,
928 .scope = sctp_v6_scope, 932 .cmp_addr = sctp_v6_cmp_addr,
929 .addr_valid = sctp_v6_addr_valid, 933 .scope = sctp_v6_scope,
930 .inaddr_any = sctp_v6_inaddr_any, 934 .addr_valid = sctp_v6_addr_valid,
931 .is_any = sctp_v6_is_any, 935 .inaddr_any = sctp_v6_inaddr_any,
932 .available = sctp_v6_available, 936 .is_any = sctp_v6_is_any,
933 .skb_iif = sctp_v6_skb_iif, 937 .available = sctp_v6_available,
934 .is_ce = sctp_v6_is_ce, 938 .skb_iif = sctp_v6_skb_iif,
935 .seq_dump_addr = sctp_v6_seq_dump_addr, 939 .is_ce = sctp_v6_is_ce,
936 .net_header_len = sizeof(struct ipv6hdr), 940 .seq_dump_addr = sctp_v6_seq_dump_addr,
937 .sockaddr_len = sizeof(struct sockaddr_in6), 941 .net_header_len = sizeof(struct ipv6hdr),
938 .sa_family = AF_INET6, 942 .sockaddr_len = sizeof(struct sockaddr_in6),
943#ifdef CONFIG_COMPAT
944 .compat_setsockopt = compat_ipv6_setsockopt,
945 .compat_getsockopt = compat_ipv6_getsockopt,
946#endif
939}; 947};
940 948
941static struct sctp_pf sctp_pf_inet6_specific = { 949static struct sctp_pf sctp_pf_inet6_specific = {
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index de693b43c8ea..2088aa992b7a 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -831,24 +831,28 @@ static struct notifier_block sctp_inetaddr_notifier = {
831 831
832/* Socket operations. */ 832/* Socket operations. */
833static const struct proto_ops inet_seqpacket_ops = { 833static const struct proto_ops inet_seqpacket_ops = {
834 .family = PF_INET, 834 .family = PF_INET,
835 .owner = THIS_MODULE, 835 .owner = THIS_MODULE,
836 .release = inet_release, /* Needs to be wrapped... */ 836 .release = inet_release, /* Needs to be wrapped... */
837 .bind = inet_bind, 837 .bind = inet_bind,
838 .connect = inet_dgram_connect, 838 .connect = inet_dgram_connect,
839 .socketpair = sock_no_socketpair, 839 .socketpair = sock_no_socketpair,
840 .accept = inet_accept, 840 .accept = inet_accept,
841 .getname = inet_getname, /* Semantics are different. */ 841 .getname = inet_getname, /* Semantics are different. */
842 .poll = sctp_poll, 842 .poll = sctp_poll,
843 .ioctl = inet_ioctl, 843 .ioctl = inet_ioctl,
844 .listen = sctp_inet_listen, 844 .listen = sctp_inet_listen,
845 .shutdown = inet_shutdown, /* Looks harmless. */ 845 .shutdown = inet_shutdown, /* Looks harmless. */
846 .setsockopt = sock_common_setsockopt, /* IP_SOL IP_OPTION is a problem. */ 846 .setsockopt = sock_common_setsockopt, /* IP_SOL IP_OPTION is a problem */
847 .getsockopt = sock_common_getsockopt, 847 .getsockopt = sock_common_getsockopt,
848 .sendmsg = inet_sendmsg, 848 .sendmsg = inet_sendmsg,
849 .recvmsg = sock_common_recvmsg, 849 .recvmsg = sock_common_recvmsg,
850 .mmap = sock_no_mmap, 850 .mmap = sock_no_mmap,
851 .sendpage = sock_no_sendpage, 851 .sendpage = sock_no_sendpage,
852#ifdef CONFIG_COMPAT
853 .compat_setsockopt = compat_sock_common_setsockopt,
854 .compat_getsockopt = compat_sock_common_getsockopt,
855#endif
852}; 856};
853 857
854/* Registration with AF_INET family. */ 858/* Registration with AF_INET family. */
@@ -880,31 +884,35 @@ static struct net_protocol sctp_protocol = {
880 884
881/* IPv4 address related functions. */ 885/* IPv4 address related functions. */
882static struct sctp_af sctp_ipv4_specific = { 886static struct sctp_af sctp_ipv4_specific = {
883 .sctp_xmit = sctp_v4_xmit, 887 .sa_family = AF_INET,
884 .setsockopt = ip_setsockopt, 888 .sctp_xmit = sctp_v4_xmit,
885 .getsockopt = ip_getsockopt, 889 .setsockopt = ip_setsockopt,
886 .get_dst = sctp_v4_get_dst, 890 .getsockopt = ip_getsockopt,
887 .get_saddr = sctp_v4_get_saddr, 891 .get_dst = sctp_v4_get_dst,
888 .copy_addrlist = sctp_v4_copy_addrlist, 892 .get_saddr = sctp_v4_get_saddr,
889 .from_skb = sctp_v4_from_skb, 893 .copy_addrlist = sctp_v4_copy_addrlist,
890 .from_sk = sctp_v4_from_sk, 894 .from_skb = sctp_v4_from_skb,
891 .to_sk_saddr = sctp_v4_to_sk_saddr, 895 .from_sk = sctp_v4_from_sk,
892 .to_sk_daddr = sctp_v4_to_sk_daddr, 896 .to_sk_saddr = sctp_v4_to_sk_saddr,
893 .from_addr_param= sctp_v4_from_addr_param, 897 .to_sk_daddr = sctp_v4_to_sk_daddr,
894 .to_addr_param = sctp_v4_to_addr_param, 898 .from_addr_param = sctp_v4_from_addr_param,
895 .dst_saddr = sctp_v4_dst_saddr, 899 .to_addr_param = sctp_v4_to_addr_param,
896 .cmp_addr = sctp_v4_cmp_addr, 900 .dst_saddr = sctp_v4_dst_saddr,
897 .addr_valid = sctp_v4_addr_valid, 901 .cmp_addr = sctp_v4_cmp_addr,
898 .inaddr_any = sctp_v4_inaddr_any, 902 .addr_valid = sctp_v4_addr_valid,
899 .is_any = sctp_v4_is_any, 903 .inaddr_any = sctp_v4_inaddr_any,
900 .available = sctp_v4_available, 904 .is_any = sctp_v4_is_any,
901 .scope = sctp_v4_scope, 905 .available = sctp_v4_available,
902 .skb_iif = sctp_v4_skb_iif, 906 .scope = sctp_v4_scope,
903 .is_ce = sctp_v4_is_ce, 907 .skb_iif = sctp_v4_skb_iif,
904 .seq_dump_addr = sctp_v4_seq_dump_addr, 908 .is_ce = sctp_v4_is_ce,
905 .net_header_len = sizeof(struct iphdr), 909 .seq_dump_addr = sctp_v4_seq_dump_addr,
906 .sockaddr_len = sizeof(struct sockaddr_in), 910 .net_header_len = sizeof(struct iphdr),
907 .sa_family = AF_INET, 911 .sockaddr_len = sizeof(struct sockaddr_in),
912#ifdef CONFIG_COMPAT
913 .compat_setsockopt = compat_ip_setsockopt,
914 .compat_getsockopt = compat_ip_getsockopt,
915#endif
908}; 916};
909 917
910struct sctp_pf *sctp_get_pf_specific(sa_family_t family) { 918struct sctp_pf *sctp_get_pf_specific(sa_family_t family) {
diff --git a/net/socket.c b/net/socket.c
index 7e1bdef8b09e..e3c21d5ec288 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -68,6 +68,7 @@
68#include <linux/netdevice.h> 68#include <linux/netdevice.h>
69#include <linux/proc_fs.h> 69#include <linux/proc_fs.h>
70#include <linux/seq_file.h> 70#include <linux/seq_file.h>
71#include <linux/mutex.h>
71#include <linux/wanrouter.h> 72#include <linux/wanrouter.h>
72#include <linux/if_bridge.h> 73#include <linux/if_bridge.h>
73#include <linux/if_frad.h> 74#include <linux/if_frad.h>
@@ -348,8 +349,8 @@ static struct dentry_operations sockfs_dentry_operations = {
348/* 349/*
349 * Obtains the first available file descriptor and sets it up for use. 350 * Obtains the first available file descriptor and sets it up for use.
350 * 351 *
351 * This function creates file structure and maps it to fd space 352 * These functions create file structures and maps them to fd space
352 * of current process. On success it returns file descriptor 353 * of the current process. On success it returns file descriptor
353 * and file struct implicitly stored in sock->file. 354 * and file struct implicitly stored in sock->file.
354 * Note that another thread may close file descriptor before we return 355 * Note that another thread may close file descriptor before we return
355 * from this function. We use the fact that now we do not refer 356 * from this function. We use the fact that now we do not refer
@@ -362,53 +363,90 @@ static struct dentry_operations sockfs_dentry_operations = {
362 * but we take care of internal coherence yet. 363 * but we take care of internal coherence yet.
363 */ 364 */
364 365
365int sock_map_fd(struct socket *sock) 366static int sock_alloc_fd(struct file **filep)
366{ 367{
367 int fd; 368 int fd;
368 struct qstr this;
369 char name[32];
370
371 /*
372 * Find a file descriptor suitable for return to the user.
373 */
374 369
375 fd = get_unused_fd(); 370 fd = get_unused_fd();
376 if (fd >= 0) { 371 if (likely(fd >= 0)) {
377 struct file *file = get_empty_filp(); 372 struct file *file = get_empty_filp();
378 373
379 if (!file) { 374 *filep = file;
375 if (unlikely(!file)) {
380 put_unused_fd(fd); 376 put_unused_fd(fd);
381 fd = -ENFILE; 377 return -ENFILE;
382 goto out;
383 } 378 }
379 } else
380 *filep = NULL;
381 return fd;
382}
383
384static int sock_attach_fd(struct socket *sock, struct file *file)
385{
386 struct qstr this;
387 char name[32];
388
389 this.len = sprintf(name, "[%lu]", SOCK_INODE(sock)->i_ino);
390 this.name = name;
391 this.hash = SOCK_INODE(sock)->i_ino;
384 392
385 this.len = sprintf(name, "[%lu]", SOCK_INODE(sock)->i_ino); 393 file->f_dentry = d_alloc(sock_mnt->mnt_sb->s_root, &this);
386 this.name = name; 394 if (unlikely(!file->f_dentry))
387 this.hash = SOCK_INODE(sock)->i_ino; 395 return -ENOMEM;
396
397 file->f_dentry->d_op = &sockfs_dentry_operations;
398 d_add(file->f_dentry, SOCK_INODE(sock));
399 file->f_vfsmnt = mntget(sock_mnt);
400 file->f_mapping = file->f_dentry->d_inode->i_mapping;
401
402 sock->file = file;
403 file->f_op = SOCK_INODE(sock)->i_fop = &socket_file_ops;
404 file->f_mode = FMODE_READ | FMODE_WRITE;
405 file->f_flags = O_RDWR;
406 file->f_pos = 0;
407 file->private_data = sock;
408
409 return 0;
410}
388 411
389 file->f_dentry = d_alloc(sock_mnt->mnt_sb->s_root, &this); 412int sock_map_fd(struct socket *sock)
390 if (!file->f_dentry) { 413{
391 put_filp(file); 414 struct file *newfile;
415 int fd = sock_alloc_fd(&newfile);
416
417 if (likely(fd >= 0)) {
418 int err = sock_attach_fd(sock, newfile);
419
420 if (unlikely(err < 0)) {
421 put_filp(newfile);
392 put_unused_fd(fd); 422 put_unused_fd(fd);
393 fd = -ENOMEM; 423 return err;
394 goto out;
395 } 424 }
396 file->f_dentry->d_op = &sockfs_dentry_operations; 425 fd_install(fd, newfile);
397 d_add(file->f_dentry, SOCK_INODE(sock)); 426 }
398 file->f_vfsmnt = mntget(sock_mnt); 427 return fd;
399 file->f_mapping = file->f_dentry->d_inode->i_mapping; 428}
400 429
401 sock->file = file; 430static struct socket *sock_from_file(struct file *file, int *err)
402 file->f_op = SOCK_INODE(sock)->i_fop = &socket_file_ops; 431{
403 file->f_mode = FMODE_READ | FMODE_WRITE; 432 struct inode *inode;
404 file->f_flags = O_RDWR; 433 struct socket *sock;
405 file->f_pos = 0; 434
406 file->private_data = sock; 435 if (file->f_op == &socket_file_ops)
407 fd_install(fd, file); 436 return file->private_data; /* set in sock_map_fd */
437
438 inode = file->f_dentry->d_inode;
439 if (!S_ISSOCK(inode->i_mode)) {
440 *err = -ENOTSOCK;
441 return NULL;
408 } 442 }
409 443
410out: 444 sock = SOCKET_I(inode);
411 return fd; 445 if (sock->file != file) {
446 printk(KERN_ERR "socki_lookup: socket file changed!\n");
447 sock->file = file;
448 }
449 return sock;
412} 450}
413 451
414/** 452/**
@@ -427,31 +465,31 @@ out:
427struct socket *sockfd_lookup(int fd, int *err) 465struct socket *sockfd_lookup(int fd, int *err)
428{ 466{
429 struct file *file; 467 struct file *file;
430 struct inode *inode;
431 struct socket *sock; 468 struct socket *sock;
432 469
433 if (!(file = fget(fd))) 470 if (!(file = fget(fd))) {
434 {
435 *err = -EBADF; 471 *err = -EBADF;
436 return NULL; 472 return NULL;
437 } 473 }
438 474 sock = sock_from_file(file, err);
439 if (file->f_op == &socket_file_ops) 475 if (!sock)
440 return file->private_data; /* set in sock_map_fd */
441
442 inode = file->f_dentry->d_inode;
443 if (!S_ISSOCK(inode->i_mode)) {
444 *err = -ENOTSOCK;
445 fput(file); 476 fput(file);
446 return NULL; 477 return sock;
447 } 478}
448 479
449 sock = SOCKET_I(inode); 480static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
450 if (sock->file != file) { 481{
451 printk(KERN_ERR "socki_lookup: socket file changed!\n"); 482 struct file *file;
452 sock->file = file; 483 struct socket *sock;
484
485 file = fget_light(fd, fput_needed);
486 if (file) {
487 sock = sock_from_file(file, err);
488 if (sock)
489 return sock;
490 fput_light(file, *fput_needed);
453 } 491 }
454 return sock; 492 return NULL;
455} 493}
456 494
457/** 495/**
@@ -789,36 +827,36 @@ static ssize_t sock_aio_write(struct kiocb *iocb, const char __user *ubuf,
789 * with module unload. 827 * with module unload.
790 */ 828 */
791 829
792static DECLARE_MUTEX(br_ioctl_mutex); 830static DEFINE_MUTEX(br_ioctl_mutex);
793static int (*br_ioctl_hook)(unsigned int cmd, void __user *arg) = NULL; 831static int (*br_ioctl_hook)(unsigned int cmd, void __user *arg) = NULL;
794 832
795void brioctl_set(int (*hook)(unsigned int, void __user *)) 833void brioctl_set(int (*hook)(unsigned int, void __user *))
796{ 834{
797 down(&br_ioctl_mutex); 835 mutex_lock(&br_ioctl_mutex);
798 br_ioctl_hook = hook; 836 br_ioctl_hook = hook;
799 up(&br_ioctl_mutex); 837 mutex_unlock(&br_ioctl_mutex);
800} 838}
801EXPORT_SYMBOL(brioctl_set); 839EXPORT_SYMBOL(brioctl_set);
802 840
803static DECLARE_MUTEX(vlan_ioctl_mutex); 841static DEFINE_MUTEX(vlan_ioctl_mutex);
804static int (*vlan_ioctl_hook)(void __user *arg); 842static int (*vlan_ioctl_hook)(void __user *arg);
805 843
806void vlan_ioctl_set(int (*hook)(void __user *)) 844void vlan_ioctl_set(int (*hook)(void __user *))
807{ 845{
808 down(&vlan_ioctl_mutex); 846 mutex_lock(&vlan_ioctl_mutex);
809 vlan_ioctl_hook = hook; 847 vlan_ioctl_hook = hook;
810 up(&vlan_ioctl_mutex); 848 mutex_unlock(&vlan_ioctl_mutex);
811} 849}
812EXPORT_SYMBOL(vlan_ioctl_set); 850EXPORT_SYMBOL(vlan_ioctl_set);
813 851
814static DECLARE_MUTEX(dlci_ioctl_mutex); 852static DEFINE_MUTEX(dlci_ioctl_mutex);
815static int (*dlci_ioctl_hook)(unsigned int, void __user *); 853static int (*dlci_ioctl_hook)(unsigned int, void __user *);
816 854
817void dlci_ioctl_set(int (*hook)(unsigned int, void __user *)) 855void dlci_ioctl_set(int (*hook)(unsigned int, void __user *))
818{ 856{
819 down(&dlci_ioctl_mutex); 857 mutex_lock(&dlci_ioctl_mutex);
820 dlci_ioctl_hook = hook; 858 dlci_ioctl_hook = hook;
821 up(&dlci_ioctl_mutex); 859 mutex_unlock(&dlci_ioctl_mutex);
822} 860}
823EXPORT_SYMBOL(dlci_ioctl_set); 861EXPORT_SYMBOL(dlci_ioctl_set);
824 862
@@ -862,10 +900,10 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
862 if (!br_ioctl_hook) 900 if (!br_ioctl_hook)
863 request_module("bridge"); 901 request_module("bridge");
864 902
865 down(&br_ioctl_mutex); 903 mutex_lock(&br_ioctl_mutex);
866 if (br_ioctl_hook) 904 if (br_ioctl_hook)
867 err = br_ioctl_hook(cmd, argp); 905 err = br_ioctl_hook(cmd, argp);
868 up(&br_ioctl_mutex); 906 mutex_unlock(&br_ioctl_mutex);
869 break; 907 break;
870 case SIOCGIFVLAN: 908 case SIOCGIFVLAN:
871 case SIOCSIFVLAN: 909 case SIOCSIFVLAN:
@@ -873,10 +911,10 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
873 if (!vlan_ioctl_hook) 911 if (!vlan_ioctl_hook)
874 request_module("8021q"); 912 request_module("8021q");
875 913
876 down(&vlan_ioctl_mutex); 914 mutex_lock(&vlan_ioctl_mutex);
877 if (vlan_ioctl_hook) 915 if (vlan_ioctl_hook)
878 err = vlan_ioctl_hook(argp); 916 err = vlan_ioctl_hook(argp);
879 up(&vlan_ioctl_mutex); 917 mutex_unlock(&vlan_ioctl_mutex);
880 break; 918 break;
881 case SIOCGIFDIVERT: 919 case SIOCGIFDIVERT:
882 case SIOCSIFDIVERT: 920 case SIOCSIFDIVERT:
@@ -890,9 +928,9 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
890 request_module("dlci"); 928 request_module("dlci");
891 929
892 if (dlci_ioctl_hook) { 930 if (dlci_ioctl_hook) {
893 down(&dlci_ioctl_mutex); 931 mutex_lock(&dlci_ioctl_mutex);
894 err = dlci_ioctl_hook(cmd, argp); 932 err = dlci_ioctl_hook(cmd, argp);
895 up(&dlci_ioctl_mutex); 933 mutex_unlock(&dlci_ioctl_mutex);
896 } 934 }
897 break; 935 break;
898 default: 936 default:
@@ -1286,19 +1324,17 @@ asmlinkage long sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen)
1286{ 1324{
1287 struct socket *sock; 1325 struct socket *sock;
1288 char address[MAX_SOCK_ADDR]; 1326 char address[MAX_SOCK_ADDR];
1289 int err; 1327 int err, fput_needed;
1290 1328
1291 if((sock = sockfd_lookup(fd,&err))!=NULL) 1329 if((sock = sockfd_lookup_light(fd, &err, &fput_needed))!=NULL)
1292 { 1330 {
1293 if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0) { 1331 if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0) {
1294 err = security_socket_bind(sock, (struct sockaddr *)address, addrlen); 1332 err = security_socket_bind(sock, (struct sockaddr *)address, addrlen);
1295 if (err) { 1333 if (!err)
1296 sockfd_put(sock); 1334 err = sock->ops->bind(sock,
1297 return err; 1335 (struct sockaddr *)address, addrlen);
1298 }
1299 err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);
1300 } 1336 }
1301 sockfd_put(sock); 1337 fput_light(sock->file, fput_needed);
1302 } 1338 }
1303 return err; 1339 return err;
1304} 1340}
@@ -1315,20 +1351,17 @@ int sysctl_somaxconn = SOMAXCONN;
1315asmlinkage long sys_listen(int fd, int backlog) 1351asmlinkage long sys_listen(int fd, int backlog)
1316{ 1352{
1317 struct socket *sock; 1353 struct socket *sock;
1318 int err; 1354 int err, fput_needed;
1319 1355
1320 if ((sock = sockfd_lookup(fd, &err)) != NULL) { 1356 if ((sock = sockfd_lookup_light(fd, &err, &fput_needed)) != NULL) {
1321 if ((unsigned) backlog > sysctl_somaxconn) 1357 if ((unsigned) backlog > sysctl_somaxconn)
1322 backlog = sysctl_somaxconn; 1358 backlog = sysctl_somaxconn;
1323 1359
1324 err = security_socket_listen(sock, backlog); 1360 err = security_socket_listen(sock, backlog);
1325 if (err) { 1361 if (!err)
1326 sockfd_put(sock); 1362 err = sock->ops->listen(sock, backlog);
1327 return err;
1328 }
1329 1363
1330 err=sock->ops->listen(sock, backlog); 1364 fput_light(sock->file, fput_needed);
1331 sockfd_put(sock);
1332 } 1365 }
1333 return err; 1366 return err;
1334} 1367}
@@ -1349,10 +1382,11 @@ asmlinkage long sys_listen(int fd, int backlog)
1349asmlinkage long sys_accept(int fd, struct sockaddr __user *upeer_sockaddr, int __user *upeer_addrlen) 1382asmlinkage long sys_accept(int fd, struct sockaddr __user *upeer_sockaddr, int __user *upeer_addrlen)
1350{ 1383{
1351 struct socket *sock, *newsock; 1384 struct socket *sock, *newsock;
1352 int err, len; 1385 struct file *newfile;
1386 int err, len, newfd, fput_needed;
1353 char address[MAX_SOCK_ADDR]; 1387 char address[MAX_SOCK_ADDR];
1354 1388
1355 sock = sockfd_lookup(fd, &err); 1389 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1356 if (!sock) 1390 if (!sock)
1357 goto out; 1391 goto out;
1358 1392
@@ -1369,35 +1403,48 @@ asmlinkage long sys_accept(int fd, struct sockaddr __user *upeer_sockaddr, int _
1369 */ 1403 */
1370 __module_get(newsock->ops->owner); 1404 __module_get(newsock->ops->owner);
1371 1405
1406 newfd = sock_alloc_fd(&newfile);
1407 if (unlikely(newfd < 0)) {
1408 err = newfd;
1409 goto out_release;
1410 }
1411
1412 err = sock_attach_fd(newsock, newfile);
1413 if (err < 0)
1414 goto out_fd;
1415
1372 err = security_socket_accept(sock, newsock); 1416 err = security_socket_accept(sock, newsock);
1373 if (err) 1417 if (err)
1374 goto out_release; 1418 goto out_fd;
1375 1419
1376 err = sock->ops->accept(sock, newsock, sock->file->f_flags); 1420 err = sock->ops->accept(sock, newsock, sock->file->f_flags);
1377 if (err < 0) 1421 if (err < 0)
1378 goto out_release; 1422 goto out_fd;
1379 1423
1380 if (upeer_sockaddr) { 1424 if (upeer_sockaddr) {
1381 if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) { 1425 if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {
1382 err = -ECONNABORTED; 1426 err = -ECONNABORTED;
1383 goto out_release; 1427 goto out_fd;
1384 } 1428 }
1385 err = move_addr_to_user(address, len, upeer_sockaddr, upeer_addrlen); 1429 err = move_addr_to_user(address, len, upeer_sockaddr, upeer_addrlen);
1386 if (err < 0) 1430 if (err < 0)
1387 goto out_release; 1431 goto out_fd;
1388 } 1432 }
1389 1433
1390 /* File flags are not inherited via accept() unlike another OSes. */ 1434 /* File flags are not inherited via accept() unlike another OSes. */
1391 1435
1392 if ((err = sock_map_fd(newsock)) < 0) 1436 fd_install(newfd, newfile);
1393 goto out_release; 1437 err = newfd;
1394 1438
1395 security_socket_post_accept(sock, newsock); 1439 security_socket_post_accept(sock, newsock);
1396 1440
1397out_put: 1441out_put:
1398 sockfd_put(sock); 1442 fput_light(sock->file, fput_needed);
1399out: 1443out:
1400 return err; 1444 return err;
1445out_fd:
1446 put_filp(newfile);
1447 put_unused_fd(newfd);
1401out_release: 1448out_release:
1402 sock_release(newsock); 1449 sock_release(newsock);
1403 goto out_put; 1450 goto out_put;
@@ -1420,9 +1467,9 @@ asmlinkage long sys_connect(int fd, struct sockaddr __user *uservaddr, int addrl
1420{ 1467{
1421 struct socket *sock; 1468 struct socket *sock;
1422 char address[MAX_SOCK_ADDR]; 1469 char address[MAX_SOCK_ADDR];
1423 int err; 1470 int err, fput_needed;
1424 1471
1425 sock = sockfd_lookup(fd, &err); 1472 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1426 if (!sock) 1473 if (!sock)
1427 goto out; 1474 goto out;
1428 err = move_addr_to_kernel(uservaddr, addrlen, address); 1475 err = move_addr_to_kernel(uservaddr, addrlen, address);
@@ -1436,7 +1483,7 @@ asmlinkage long sys_connect(int fd, struct sockaddr __user *uservaddr, int addrl
1436 err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen, 1483 err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,
1437 sock->file->f_flags); 1484 sock->file->f_flags);
1438out_put: 1485out_put:
1439 sockfd_put(sock); 1486 fput_light(sock->file, fput_needed);
1440out: 1487out:
1441 return err; 1488 return err;
1442} 1489}
@@ -1450,9 +1497,9 @@ asmlinkage long sys_getsockname(int fd, struct sockaddr __user *usockaddr, int _
1450{ 1497{
1451 struct socket *sock; 1498 struct socket *sock;
1452 char address[MAX_SOCK_ADDR]; 1499 char address[MAX_SOCK_ADDR];
1453 int len, err; 1500 int len, err, fput_needed;
1454 1501
1455 sock = sockfd_lookup(fd, &err); 1502 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1456 if (!sock) 1503 if (!sock)
1457 goto out; 1504 goto out;
1458 1505
@@ -1466,7 +1513,7 @@ asmlinkage long sys_getsockname(int fd, struct sockaddr __user *usockaddr, int _
1466 err = move_addr_to_user(address, len, usockaddr, usockaddr_len); 1513 err = move_addr_to_user(address, len, usockaddr, usockaddr_len);
1467 1514
1468out_put: 1515out_put:
1469 sockfd_put(sock); 1516 fput_light(sock->file, fput_needed);
1470out: 1517out:
1471 return err; 1518 return err;
1472} 1519}
@@ -1480,20 +1527,19 @@ asmlinkage long sys_getpeername(int fd, struct sockaddr __user *usockaddr, int _
1480{ 1527{
1481 struct socket *sock; 1528 struct socket *sock;
1482 char address[MAX_SOCK_ADDR]; 1529 char address[MAX_SOCK_ADDR];
1483 int len, err; 1530 int len, err, fput_needed;
1484 1531
1485 if ((sock = sockfd_lookup(fd, &err))!=NULL) 1532 if ((sock = sockfd_lookup_light(fd, &err, &fput_needed)) != NULL) {
1486 {
1487 err = security_socket_getpeername(sock); 1533 err = security_socket_getpeername(sock);
1488 if (err) { 1534 if (err) {
1489 sockfd_put(sock); 1535 fput_light(sock->file, fput_needed);
1490 return err; 1536 return err;
1491 } 1537 }
1492 1538
1493 err = sock->ops->getname(sock, (struct sockaddr *)address, &len, 1); 1539 err = sock->ops->getname(sock, (struct sockaddr *)address, &len, 1);
1494 if (!err) 1540 if (!err)
1495 err=move_addr_to_user(address,len, usockaddr, usockaddr_len); 1541 err=move_addr_to_user(address,len, usockaddr, usockaddr_len);
1496 sockfd_put(sock); 1542 fput_light(sock->file, fput_needed);
1497 } 1543 }
1498 return err; 1544 return err;
1499} 1545}
@@ -1512,10 +1558,16 @@ asmlinkage long sys_sendto(int fd, void __user * buff, size_t len, unsigned flag
1512 int err; 1558 int err;
1513 struct msghdr msg; 1559 struct msghdr msg;
1514 struct iovec iov; 1560 struct iovec iov;
1515 1561 int fput_needed;
1516 sock = sockfd_lookup(fd, &err); 1562 struct file *sock_file;
1563
1564 sock_file = fget_light(fd, &fput_needed);
1565 if (!sock_file)
1566 return -EBADF;
1567
1568 sock = sock_from_file(sock_file, &err);
1517 if (!sock) 1569 if (!sock)
1518 goto out; 1570 goto out_put;
1519 iov.iov_base=buff; 1571 iov.iov_base=buff;
1520 iov.iov_len=len; 1572 iov.iov_len=len;
1521 msg.msg_name=NULL; 1573 msg.msg_name=NULL;
@@ -1524,8 +1576,7 @@ asmlinkage long sys_sendto(int fd, void __user * buff, size_t len, unsigned flag
1524 msg.msg_control=NULL; 1576 msg.msg_control=NULL;
1525 msg.msg_controllen=0; 1577 msg.msg_controllen=0;
1526 msg.msg_namelen=0; 1578 msg.msg_namelen=0;
1527 if(addr) 1579 if (addr) {
1528 {
1529 err = move_addr_to_kernel(addr, addr_len, address); 1580 err = move_addr_to_kernel(addr, addr_len, address);
1530 if (err < 0) 1581 if (err < 0)
1531 goto out_put; 1582 goto out_put;
@@ -1538,8 +1589,7 @@ asmlinkage long sys_sendto(int fd, void __user * buff, size_t len, unsigned flag
1538 err = sock_sendmsg(sock, &msg, len); 1589 err = sock_sendmsg(sock, &msg, len);
1539 1590
1540out_put: 1591out_put:
1541 sockfd_put(sock); 1592 fput_light(sock_file, fput_needed);
1542out:
1543 return err; 1593 return err;
1544} 1594}
1545 1595
@@ -1566,8 +1616,14 @@ asmlinkage long sys_recvfrom(int fd, void __user * ubuf, size_t size, unsigned f
1566 struct msghdr msg; 1616 struct msghdr msg;
1567 char address[MAX_SOCK_ADDR]; 1617 char address[MAX_SOCK_ADDR];
1568 int err,err2; 1618 int err,err2;
1619 struct file *sock_file;
1620 int fput_needed;
1569 1621
1570 sock = sockfd_lookup(fd, &err); 1622 sock_file = fget_light(fd, &fput_needed);
1623 if (!sock_file)
1624 return -EBADF;
1625
1626 sock = sock_from_file(sock_file, &err);
1571 if (!sock) 1627 if (!sock)
1572 goto out; 1628 goto out;
1573 1629
@@ -1589,8 +1645,8 @@ asmlinkage long sys_recvfrom(int fd, void __user * ubuf, size_t size, unsigned f
1589 if(err2<0) 1645 if(err2<0)
1590 err=err2; 1646 err=err2;
1591 } 1647 }
1592 sockfd_put(sock);
1593out: 1648out:
1649 fput_light(sock_file, fput_needed);
1594 return err; 1650 return err;
1595} 1651}
1596 1652
@@ -1610,25 +1666,24 @@ asmlinkage long sys_recv(int fd, void __user * ubuf, size_t size, unsigned flags
1610 1666
1611asmlinkage long sys_setsockopt(int fd, int level, int optname, char __user *optval, int optlen) 1667asmlinkage long sys_setsockopt(int fd, int level, int optname, char __user *optval, int optlen)
1612{ 1668{
1613 int err; 1669 int err, fput_needed;
1614 struct socket *sock; 1670 struct socket *sock;
1615 1671
1616 if (optlen < 0) 1672 if (optlen < 0)
1617 return -EINVAL; 1673 return -EINVAL;
1618 1674
1619 if ((sock = sockfd_lookup(fd, &err))!=NULL) 1675 if ((sock = sockfd_lookup_light(fd, &err, &fput_needed)) != NULL)
1620 { 1676 {
1621 err = security_socket_setsockopt(sock,level,optname); 1677 err = security_socket_setsockopt(sock,level,optname);
1622 if (err) { 1678 if (err)
1623 sockfd_put(sock); 1679 goto out_put;
1624 return err;
1625 }
1626 1680
1627 if (level == SOL_SOCKET) 1681 if (level == SOL_SOCKET)
1628 err=sock_setsockopt(sock,level,optname,optval,optlen); 1682 err=sock_setsockopt(sock,level,optname,optval,optlen);
1629 else 1683 else
1630 err=sock->ops->setsockopt(sock, level, optname, optval, optlen); 1684 err=sock->ops->setsockopt(sock, level, optname, optval, optlen);
1631 sockfd_put(sock); 1685out_put:
1686 fput_light(sock->file, fput_needed);
1632 } 1687 }
1633 return err; 1688 return err;
1634} 1689}
@@ -1640,23 +1695,20 @@ asmlinkage long sys_setsockopt(int fd, int level, int optname, char __user *optv
1640 1695
1641asmlinkage long sys_getsockopt(int fd, int level, int optname, char __user *optval, int __user *optlen) 1696asmlinkage long sys_getsockopt(int fd, int level, int optname, char __user *optval, int __user *optlen)
1642{ 1697{
1643 int err; 1698 int err, fput_needed;
1644 struct socket *sock; 1699 struct socket *sock;
1645 1700
1646 if ((sock = sockfd_lookup(fd, &err))!=NULL) 1701 if ((sock = sockfd_lookup_light(fd, &err, &fput_needed)) != NULL) {
1647 { 1702 err = security_socket_getsockopt(sock, level, optname);
1648 err = security_socket_getsockopt(sock, level, 1703 if (err)
1649 optname); 1704 goto out_put;
1650 if (err) {
1651 sockfd_put(sock);
1652 return err;
1653 }
1654 1705
1655 if (level == SOL_SOCKET) 1706 if (level == SOL_SOCKET)
1656 err=sock_getsockopt(sock,level,optname,optval,optlen); 1707 err=sock_getsockopt(sock,level,optname,optval,optlen);
1657 else 1708 else
1658 err=sock->ops->getsockopt(sock, level, optname, optval, optlen); 1709 err=sock->ops->getsockopt(sock, level, optname, optval, optlen);
1659 sockfd_put(sock); 1710out_put:
1711 fput_light(sock->file, fput_needed);
1660 } 1712 }
1661 return err; 1713 return err;
1662} 1714}
@@ -1668,19 +1720,15 @@ asmlinkage long sys_getsockopt(int fd, int level, int optname, char __user *optv
1668 1720
1669asmlinkage long sys_shutdown(int fd, int how) 1721asmlinkage long sys_shutdown(int fd, int how)
1670{ 1722{
1671 int err; 1723 int err, fput_needed;
1672 struct socket *sock; 1724 struct socket *sock;
1673 1725
1674 if ((sock = sockfd_lookup(fd, &err))!=NULL) 1726 if ((sock = sockfd_lookup_light(fd, &err, &fput_needed))!=NULL)
1675 { 1727 {
1676 err = security_socket_shutdown(sock, how); 1728 err = security_socket_shutdown(sock, how);
1677 if (err) { 1729 if (!err)
1678 sockfd_put(sock); 1730 err = sock->ops->shutdown(sock, how);
1679 return err; 1731 fput_light(sock->file, fput_needed);
1680 }
1681
1682 err=sock->ops->shutdown(sock, how);
1683 sockfd_put(sock);
1684 } 1732 }
1685 return err; 1733 return err;
1686} 1734}
@@ -1709,6 +1757,7 @@ asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags)
1709 unsigned char *ctl_buf = ctl; 1757 unsigned char *ctl_buf = ctl;
1710 struct msghdr msg_sys; 1758 struct msghdr msg_sys;
1711 int err, ctl_len, iov_size, total_len; 1759 int err, ctl_len, iov_size, total_len;
1760 int fput_needed;
1712 1761
1713 err = -EFAULT; 1762 err = -EFAULT;
1714 if (MSG_CMSG_COMPAT & flags) { 1763 if (MSG_CMSG_COMPAT & flags) {
@@ -1717,7 +1766,7 @@ asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags)
1717 } else if (copy_from_user(&msg_sys, msg, sizeof(struct msghdr))) 1766 } else if (copy_from_user(&msg_sys, msg, sizeof(struct msghdr)))
1718 return -EFAULT; 1767 return -EFAULT;
1719 1768
1720 sock = sockfd_lookup(fd, &err); 1769 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1721 if (!sock) 1770 if (!sock)
1722 goto out; 1771 goto out;
1723 1772
@@ -1785,7 +1834,7 @@ out_freeiov:
1785 if (iov != iovstack) 1834 if (iov != iovstack)
1786 sock_kfree_s(sock->sk, iov, iov_size); 1835 sock_kfree_s(sock->sk, iov, iov_size);
1787out_put: 1836out_put:
1788 sockfd_put(sock); 1837 fput_light(sock->file, fput_needed);
1789out: 1838out:
1790 return err; 1839 return err;
1791} 1840}
@@ -1803,6 +1852,7 @@ asmlinkage long sys_recvmsg(int fd, struct msghdr __user *msg, unsigned int flag
1803 struct msghdr msg_sys; 1852 struct msghdr msg_sys;
1804 unsigned long cmsg_ptr; 1853 unsigned long cmsg_ptr;
1805 int err, iov_size, total_len, len; 1854 int err, iov_size, total_len, len;
1855 int fput_needed;
1806 1856
1807 /* kernel mode address */ 1857 /* kernel mode address */
1808 char addr[MAX_SOCK_ADDR]; 1858 char addr[MAX_SOCK_ADDR];
@@ -1818,7 +1868,7 @@ asmlinkage long sys_recvmsg(int fd, struct msghdr __user *msg, unsigned int flag
1818 if (copy_from_user(&msg_sys,msg,sizeof(struct msghdr))) 1868 if (copy_from_user(&msg_sys,msg,sizeof(struct msghdr)))
1819 return -EFAULT; 1869 return -EFAULT;
1820 1870
1821 sock = sockfd_lookup(fd, &err); 1871 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1822 if (!sock) 1872 if (!sock)
1823 goto out; 1873 goto out;
1824 1874
@@ -1885,7 +1935,7 @@ out_freeiov:
1885 if (iov != iovstack) 1935 if (iov != iovstack)
1886 sock_kfree_s(sock->sk, iov, iov_size); 1936 sock_kfree_s(sock->sk, iov, iov_size);
1887out_put: 1937out_put:
1888 sockfd_put(sock); 1938 fput_light(sock->file, fput_needed);
1889out: 1939out:
1890 return err; 1940 return err;
1891} 1941}
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index dcaa0c4453ff..0acccfeeb284 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -26,6 +26,7 @@
26#include <linux/proc_fs.h> 26#include <linux/proc_fs.h>
27#include <linux/net.h> 27#include <linux/net.h>
28#include <linux/workqueue.h> 28#include <linux/workqueue.h>
29#include <linux/mutex.h>
29#include <asm/ioctls.h> 30#include <asm/ioctls.h>
30#include <linux/sunrpc/types.h> 31#include <linux/sunrpc/types.h>
31#include <linux/sunrpc/cache.h> 32#include <linux/sunrpc/cache.h>
@@ -532,7 +533,7 @@ void cache_clean_deferred(void *owner)
532 */ 533 */
533 534
534static DEFINE_SPINLOCK(queue_lock); 535static DEFINE_SPINLOCK(queue_lock);
535static DECLARE_MUTEX(queue_io_sem); 536static DEFINE_MUTEX(queue_io_mutex);
536 537
537struct cache_queue { 538struct cache_queue {
538 struct list_head list; 539 struct list_head list;
@@ -561,7 +562,7 @@ cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos)
561 if (count == 0) 562 if (count == 0)
562 return 0; 563 return 0;
563 564
564 down(&queue_io_sem); /* protect against multiple concurrent 565 mutex_lock(&queue_io_mutex); /* protect against multiple concurrent
565 * readers on this file */ 566 * readers on this file */
566 again: 567 again:
567 spin_lock(&queue_lock); 568 spin_lock(&queue_lock);
@@ -574,7 +575,7 @@ cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos)
574 } 575 }
575 if (rp->q.list.next == &cd->queue) { 576 if (rp->q.list.next == &cd->queue) {
576 spin_unlock(&queue_lock); 577 spin_unlock(&queue_lock);
577 up(&queue_io_sem); 578 mutex_unlock(&queue_io_mutex);
578 BUG_ON(rp->offset); 579 BUG_ON(rp->offset);
579 return 0; 580 return 0;
580 } 581 }
@@ -621,11 +622,11 @@ cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos)
621 } 622 }
622 if (err == -EAGAIN) 623 if (err == -EAGAIN)
623 goto again; 624 goto again;
624 up(&queue_io_sem); 625 mutex_unlock(&queue_io_mutex);
625 return err ? err : count; 626 return err ? err : count;
626} 627}
627 628
628static char write_buf[8192]; /* protected by queue_io_sem */ 629static char write_buf[8192]; /* protected by queue_io_mutex */
629 630
630static ssize_t 631static ssize_t
631cache_write(struct file *filp, const char __user *buf, size_t count, 632cache_write(struct file *filp, const char __user *buf, size_t count,
@@ -639,10 +640,10 @@ cache_write(struct file *filp, const char __user *buf, size_t count,
639 if (count >= sizeof(write_buf)) 640 if (count >= sizeof(write_buf))
640 return -EINVAL; 641 return -EINVAL;
641 642
642 down(&queue_io_sem); 643 mutex_lock(&queue_io_mutex);
643 644
644 if (copy_from_user(write_buf, buf, count)) { 645 if (copy_from_user(write_buf, buf, count)) {
645 up(&queue_io_sem); 646 mutex_unlock(&queue_io_mutex);
646 return -EFAULT; 647 return -EFAULT;
647 } 648 }
648 write_buf[count] = '\0'; 649 write_buf[count] = '\0';
@@ -651,7 +652,7 @@ cache_write(struct file *filp, const char __user *buf, size_t count,
651 else 652 else
652 err = -EINVAL; 653 err = -EINVAL;
653 654
654 up(&queue_io_sem); 655 mutex_unlock(&queue_io_mutex);
655 return err ? err : count; 656 return err ? err : count;
656} 657}
657 658
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index e838d042f7f5..dff07795bd16 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c
@@ -18,6 +18,7 @@
18#include <linux/smp.h> 18#include <linux/smp.h>
19#include <linux/smp_lock.h> 19#include <linux/smp_lock.h>
20#include <linux/spinlock.h> 20#include <linux/spinlock.h>
21#include <linux/mutex.h>
21 22
22#include <linux/sunrpc/clnt.h> 23#include <linux/sunrpc/clnt.h>
23#include <linux/sunrpc/xprt.h> 24#include <linux/sunrpc/xprt.h>
@@ -62,7 +63,7 @@ static LIST_HEAD(all_tasks);
62/* 63/*
63 * rpciod-related stuff 64 * rpciod-related stuff
64 */ 65 */
65static DECLARE_MUTEX(rpciod_sema); 66static DEFINE_MUTEX(rpciod_mutex);
66static unsigned int rpciod_users; 67static unsigned int rpciod_users;
67static struct workqueue_struct *rpciod_workqueue; 68static struct workqueue_struct *rpciod_workqueue;
68 69
@@ -1047,7 +1048,7 @@ rpciod_up(void)
1047 struct workqueue_struct *wq; 1048 struct workqueue_struct *wq;
1048 int error = 0; 1049 int error = 0;
1049 1050
1050 down(&rpciod_sema); 1051 mutex_lock(&rpciod_mutex);
1051 dprintk("rpciod_up: users %d\n", rpciod_users); 1052 dprintk("rpciod_up: users %d\n", rpciod_users);
1052 rpciod_users++; 1053 rpciod_users++;
1053 if (rpciod_workqueue) 1054 if (rpciod_workqueue)
@@ -1070,14 +1071,14 @@ rpciod_up(void)
1070 rpciod_workqueue = wq; 1071 rpciod_workqueue = wq;
1071 error = 0; 1072 error = 0;
1072out: 1073out:
1073 up(&rpciod_sema); 1074 mutex_unlock(&rpciod_mutex);
1074 return error; 1075 return error;
1075} 1076}
1076 1077
1077void 1078void
1078rpciod_down(void) 1079rpciod_down(void)
1079{ 1080{
1080 down(&rpciod_sema); 1081 mutex_lock(&rpciod_mutex);
1081 dprintk("rpciod_down sema %d\n", rpciod_users); 1082 dprintk("rpciod_down sema %d\n", rpciod_users);
1082 if (rpciod_users) { 1083 if (rpciod_users) {
1083 if (--rpciod_users) 1084 if (--rpciod_users)
@@ -1094,7 +1095,7 @@ rpciod_down(void)
1094 destroy_workqueue(rpciod_workqueue); 1095 destroy_workqueue(rpciod_workqueue);
1095 rpciod_workqueue = NULL; 1096 rpciod_workqueue = NULL;
1096 out: 1097 out:
1097 up(&rpciod_sema); 1098 mutex_unlock(&rpciod_mutex);
1098} 1099}
1099 1100
1100#ifdef RPC_DEBUG 1101#ifdef RPC_DEBUG
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 50580620e897..a27905a0ad27 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -1296,13 +1296,13 @@ svc_send(struct svc_rqst *rqstp)
1296 xb->page_len + 1296 xb->page_len +
1297 xb->tail[0].iov_len; 1297 xb->tail[0].iov_len;
1298 1298
1299 /* Grab svsk->sk_sem to serialize outgoing data. */ 1299 /* Grab svsk->sk_mutex to serialize outgoing data. */
1300 down(&svsk->sk_sem); 1300 mutex_lock(&svsk->sk_mutex);
1301 if (test_bit(SK_DEAD, &svsk->sk_flags)) 1301 if (test_bit(SK_DEAD, &svsk->sk_flags))
1302 len = -ENOTCONN; 1302 len = -ENOTCONN;
1303 else 1303 else
1304 len = svsk->sk_sendto(rqstp); 1304 len = svsk->sk_sendto(rqstp);
1305 up(&svsk->sk_sem); 1305 mutex_unlock(&svsk->sk_mutex);
1306 svc_sock_release(rqstp); 1306 svc_sock_release(rqstp);
1307 1307
1308 if (len == -ECONNREFUSED || len == -ENOTCONN || len == -EAGAIN) 1308 if (len == -ECONNREFUSED || len == -ENOTCONN || len == -EAGAIN)
@@ -1351,7 +1351,7 @@ svc_setup_socket(struct svc_serv *serv, struct socket *sock,
1351 svsk->sk_lastrecv = get_seconds(); 1351 svsk->sk_lastrecv = get_seconds();
1352 INIT_LIST_HEAD(&svsk->sk_deferred); 1352 INIT_LIST_HEAD(&svsk->sk_deferred);
1353 INIT_LIST_HEAD(&svsk->sk_ready); 1353 INIT_LIST_HEAD(&svsk->sk_ready);
1354 sema_init(&svsk->sk_sem, 1); 1354 mutex_init(&svsk->sk_mutex);
1355 1355
1356 /* Initialize the socket */ 1356 /* Initialize the socket */
1357 if (sock->type == SOCK_DGRAM) 1357 if (sock->type == SOCK_DGRAM)
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index a7b04f397c12..2c4ecbe50082 100644
--- a/net/tipc/bcast.c
+++ b/net/tipc/bcast.c
@@ -107,22 +107,22 @@ static spinlock_t bc_lock = SPIN_LOCK_UNLOCKED;
107char tipc_bclink_name[] = "multicast-link"; 107char tipc_bclink_name[] = "multicast-link";
108 108
109 109
110static inline u32 buf_seqno(struct sk_buff *buf) 110static u32 buf_seqno(struct sk_buff *buf)
111{ 111{
112 return msg_seqno(buf_msg(buf)); 112 return msg_seqno(buf_msg(buf));
113} 113}
114 114
115static inline u32 bcbuf_acks(struct sk_buff *buf) 115static u32 bcbuf_acks(struct sk_buff *buf)
116{ 116{
117 return (u32)(unsigned long)TIPC_SKB_CB(buf)->handle; 117 return (u32)(unsigned long)TIPC_SKB_CB(buf)->handle;
118} 118}
119 119
120static inline void bcbuf_set_acks(struct sk_buff *buf, u32 acks) 120static void bcbuf_set_acks(struct sk_buff *buf, u32 acks)
121{ 121{
122 TIPC_SKB_CB(buf)->handle = (void *)(unsigned long)acks; 122 TIPC_SKB_CB(buf)->handle = (void *)(unsigned long)acks;
123} 123}
124 124
125static inline void bcbuf_decr_acks(struct sk_buff *buf) 125static void bcbuf_decr_acks(struct sk_buff *buf)
126{ 126{
127 bcbuf_set_acks(buf, bcbuf_acks(buf) - 1); 127 bcbuf_set_acks(buf, bcbuf_acks(buf) - 1);
128} 128}
@@ -134,7 +134,7 @@ static inline void bcbuf_decr_acks(struct sk_buff *buf)
134 * Called with 'node' locked, bc_lock unlocked 134 * Called with 'node' locked, bc_lock unlocked
135 */ 135 */
136 136
137static inline void bclink_set_gap(struct node *n_ptr) 137static void bclink_set_gap(struct node *n_ptr)
138{ 138{
139 struct sk_buff *buf = n_ptr->bclink.deferred_head; 139 struct sk_buff *buf = n_ptr->bclink.deferred_head;
140 140
@@ -154,7 +154,7 @@ static inline void bclink_set_gap(struct node *n_ptr)
154 * distribute NACKs, but tries to use the same spacing (divide by 16). 154 * distribute NACKs, but tries to use the same spacing (divide by 16).
155 */ 155 */
156 156
157static inline int bclink_ack_allowed(u32 n) 157static int bclink_ack_allowed(u32 n)
158{ 158{
159 return((n % TIPC_MIN_LINK_WIN) == tipc_own_tag); 159 return((n % TIPC_MIN_LINK_WIN) == tipc_own_tag);
160} 160}
@@ -271,7 +271,7 @@ static void bclink_send_nack(struct node *n_ptr)
271 msg_set_bcgap_to(msg, n_ptr->bclink.gap_to); 271 msg_set_bcgap_to(msg, n_ptr->bclink.gap_to);
272 msg_set_bcast_tag(msg, tipc_own_tag); 272 msg_set_bcast_tag(msg, tipc_own_tag);
273 273
274 if (tipc_bearer_send(&bcbearer->bearer, buf, 0)) { 274 if (tipc_bearer_send(&bcbearer->bearer, buf, NULL)) {
275 bcl->stats.sent_nacks++; 275 bcl->stats.sent_nacks++;
276 buf_discard(buf); 276 buf_discard(buf);
277 } else { 277 } else {
@@ -314,7 +314,7 @@ void tipc_bclink_check_gap(struct node *n_ptr, u32 last_sent)
314 * Only tipc_net_lock set. 314 * Only tipc_net_lock set.
315 */ 315 */
316 316
317void tipc_bclink_peek_nack(u32 dest, u32 sender_tag, u32 gap_after, u32 gap_to) 317static void tipc_bclink_peek_nack(u32 dest, u32 sender_tag, u32 gap_after, u32 gap_to)
318{ 318{
319 struct node *n_ptr = tipc_node_find(dest); 319 struct node *n_ptr = tipc_node_find(dest);
320 u32 my_after, my_to; 320 u32 my_after, my_to;
@@ -425,9 +425,9 @@ void tipc_bclink_recv_pkt(struct sk_buff *buf)
425 msg_bcgap_to(msg)); 425 msg_bcgap_to(msg));
426 } else { 426 } else {
427 tipc_bclink_peek_nack(msg_destnode(msg), 427 tipc_bclink_peek_nack(msg_destnode(msg),
428 msg_bcast_tag(msg), 428 msg_bcast_tag(msg),
429 msg_bcgap_after(msg), 429 msg_bcgap_after(msg),
430 msg_bcgap_to(msg)); 430 msg_bcgap_to(msg));
431 } 431 }
432 buf_discard(buf); 432 buf_discard(buf);
433 return; 433 return;
@@ -525,16 +525,18 @@ u32 tipc_bclink_acks_missing(struct node *n_ptr)
525 * Returns 0 if packet sent successfully, non-zero if not 525 * Returns 0 if packet sent successfully, non-zero if not
526 */ 526 */
527 527
528int tipc_bcbearer_send(struct sk_buff *buf, 528static int tipc_bcbearer_send(struct sk_buff *buf,
529 struct tipc_bearer *unused1, 529 struct tipc_bearer *unused1,
530 struct tipc_media_addr *unused2) 530 struct tipc_media_addr *unused2)
531{ 531{
532 static int send_count = 0; 532 static int send_count = 0;
533 533
534 struct node_map remains; 534 struct node_map *remains;
535 struct node_map remains_new; 535 struct node_map *remains_new;
536 struct node_map *remains_tmp;
536 int bp_index; 537 int bp_index;
537 int swap_time; 538 int swap_time;
539 int err;
538 540
539 /* Prepare buffer for broadcasting (if first time trying to send it) */ 541 /* Prepare buffer for broadcasting (if first time trying to send it) */
540 542
@@ -555,7 +557,9 @@ int tipc_bcbearer_send(struct sk_buff *buf,
555 557
556 /* Send buffer over bearers until all targets reached */ 558 /* Send buffer over bearers until all targets reached */
557 559
558 remains = tipc_cltr_bcast_nodes; 560 remains = kmalloc(sizeof(struct node_map), GFP_ATOMIC);
561 remains_new = kmalloc(sizeof(struct node_map), GFP_ATOMIC);
562 *remains = tipc_cltr_bcast_nodes;
559 563
560 for (bp_index = 0; bp_index < MAX_BEARERS; bp_index++) { 564 for (bp_index = 0; bp_index < MAX_BEARERS; bp_index++) {
561 struct bearer *p = bcbearer->bpairs[bp_index].primary; 565 struct bearer *p = bcbearer->bpairs[bp_index].primary;
@@ -564,8 +568,8 @@ int tipc_bcbearer_send(struct sk_buff *buf,
564 if (!p) 568 if (!p)
565 break; /* no more bearers to try */ 569 break; /* no more bearers to try */
566 570
567 tipc_nmap_diff(&remains, &p->nodes, &remains_new); 571 tipc_nmap_diff(remains, &p->nodes, remains_new);
568 if (remains_new.count == remains.count) 572 if (remains_new->count == remains->count)
569 continue; /* bearer pair doesn't add anything */ 573 continue; /* bearer pair doesn't add anything */
570 574
571 if (!p->publ.blocked && 575 if (!p->publ.blocked &&
@@ -583,17 +587,27 @@ swap:
583 bcbearer->bpairs[bp_index].primary = s; 587 bcbearer->bpairs[bp_index].primary = s;
584 bcbearer->bpairs[bp_index].secondary = p; 588 bcbearer->bpairs[bp_index].secondary = p;
585update: 589update:
586 if (remains_new.count == 0) 590 if (remains_new->count == 0) {
587 return TIPC_OK; 591 err = TIPC_OK;
592 goto out;
593 }
588 594
595 /* swap map */
596 remains_tmp = remains;
589 remains = remains_new; 597 remains = remains_new;
598 remains_new = remains_tmp;
590 } 599 }
591 600
592 /* Unable to reach all targets */ 601 /* Unable to reach all targets */
593 602
594 bcbearer->bearer.publ.blocked = 1; 603 bcbearer->bearer.publ.blocked = 1;
595 bcl->stats.bearer_congs++; 604 bcl->stats.bearer_congs++;
596 return ~TIPC_OK; 605 err = ~TIPC_OK;
606
607 out:
608 kfree(remains_new);
609 kfree(remains);
610 return err;
597} 611}
598 612
599/** 613/**
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 64dcb0f3a8b2..e213a8e54855 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -45,10 +45,10 @@
45 45
46#define MAX_ADDR_STR 32 46#define MAX_ADDR_STR 32
47 47
48static struct media *media_list = 0; 48static struct media *media_list = NULL;
49static u32 media_count = 0; 49static u32 media_count = 0;
50 50
51struct bearer *tipc_bearers = 0; 51struct bearer *tipc_bearers = NULL;
52 52
53/** 53/**
54 * media_name_valid - validate media name 54 * media_name_valid - validate media name
@@ -79,7 +79,7 @@ static struct media *media_find(const char *name)
79 if (!strcmp(m_ptr->name, name)) 79 if (!strcmp(m_ptr->name, name))
80 return m_ptr; 80 return m_ptr;
81 } 81 }
82 return 0; 82 return NULL;
83} 83}
84 84
85/** 85/**
@@ -287,7 +287,7 @@ static struct bearer *bearer_find(const char *name)
287 if (b_ptr->active && (!strcmp(b_ptr->publ.name, name))) 287 if (b_ptr->active && (!strcmp(b_ptr->publ.name, name)))
288 return b_ptr; 288 return b_ptr;
289 } 289 }
290 return 0; 290 return NULL;
291} 291}
292 292
293/** 293/**
@@ -307,7 +307,7 @@ struct bearer *tipc_bearer_find_interface(const char *if_name)
307 if (!strcmp(b_if_name, if_name)) 307 if (!strcmp(b_if_name, if_name))
308 return b_ptr; 308 return b_ptr;
309 } 309 }
310 return 0; 310 return NULL;
311} 311}
312 312
313/** 313/**
@@ -569,7 +569,7 @@ failed:
569 569
570int tipc_block_bearer(const char *name) 570int tipc_block_bearer(const char *name)
571{ 571{
572 struct bearer *b_ptr = 0; 572 struct bearer *b_ptr = NULL;
573 struct link *l_ptr; 573 struct link *l_ptr;
574 struct link *temp_l_ptr; 574 struct link *temp_l_ptr;
575 575
@@ -666,8 +666,8 @@ int tipc_bearer_init(void)
666 } else { 666 } else {
667 kfree(tipc_bearers); 667 kfree(tipc_bearers);
668 kfree(media_list); 668 kfree(media_list);
669 tipc_bearers = 0; 669 tipc_bearers = NULL;
670 media_list = 0; 670 media_list = NULL;
671 res = -ENOMEM; 671 res = -ENOMEM;
672 } 672 }
673 write_unlock_bh(&tipc_net_lock); 673 write_unlock_bh(&tipc_net_lock);
@@ -691,8 +691,8 @@ void tipc_bearer_stop(void)
691 } 691 }
692 kfree(tipc_bearers); 692 kfree(tipc_bearers);
693 kfree(media_list); 693 kfree(media_list);
694 tipc_bearers = 0; 694 tipc_bearers = NULL;
695 media_list = 0; 695 media_list = NULL;
696 media_count = 0; 696 media_count = 0;
697} 697}
698 698
diff --git a/net/tipc/cluster.c b/net/tipc/cluster.c
index ab974ca19371..1aed81584e96 100644
--- a/net/tipc/cluster.c
+++ b/net/tipc/cluster.c
@@ -44,11 +44,11 @@
44#include "msg.h" 44#include "msg.h"
45#include "bearer.h" 45#include "bearer.h"
46 46
47void tipc_cltr_multicast(struct cluster *c_ptr, struct sk_buff *buf, 47static void tipc_cltr_multicast(struct cluster *c_ptr, struct sk_buff *buf,
48 u32 lower, u32 upper); 48 u32 lower, u32 upper);
49struct sk_buff *tipc_cltr_prepare_routing_msg(u32 data_size, u32 dest); 49static struct sk_buff *tipc_cltr_prepare_routing_msg(u32 data_size, u32 dest);
50 50
51struct node **tipc_local_nodes = 0; 51struct node **tipc_local_nodes = NULL;
52struct node_map tipc_cltr_bcast_nodes = {0,{0,}}; 52struct node_map tipc_cltr_bcast_nodes = {0,{0,}};
53u32 tipc_highest_allowed_slave = 0; 53u32 tipc_highest_allowed_slave = 0;
54 54
@@ -61,7 +61,7 @@ struct cluster *tipc_cltr_create(u32 addr)
61 61
62 c_ptr = (struct cluster *)kmalloc(sizeof(*c_ptr), GFP_ATOMIC); 62 c_ptr = (struct cluster *)kmalloc(sizeof(*c_ptr), GFP_ATOMIC);
63 if (c_ptr == NULL) 63 if (c_ptr == NULL)
64 return 0; 64 return NULL;
65 memset(c_ptr, 0, sizeof(*c_ptr)); 65 memset(c_ptr, 0, sizeof(*c_ptr));
66 66
67 c_ptr->addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0); 67 c_ptr->addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0);
@@ -73,7 +73,7 @@ struct cluster *tipc_cltr_create(u32 addr)
73 c_ptr->nodes = (struct node **)kmalloc(alloc, GFP_ATOMIC); 73 c_ptr->nodes = (struct node **)kmalloc(alloc, GFP_ATOMIC);
74 if (c_ptr->nodes == NULL) { 74 if (c_ptr->nodes == NULL) {
75 kfree(c_ptr); 75 kfree(c_ptr);
76 return 0; 76 return NULL;
77 } 77 }
78 memset(c_ptr->nodes, 0, alloc); 78 memset(c_ptr->nodes, 0, alloc);
79 if (in_own_cluster(addr)) 79 if (in_own_cluster(addr))
@@ -91,7 +91,7 @@ struct cluster *tipc_cltr_create(u32 addr)
91 } 91 }
92 else { 92 else {
93 kfree(c_ptr); 93 kfree(c_ptr);
94 c_ptr = 0; 94 c_ptr = NULL;
95 } 95 }
96 96
97 return c_ptr; 97 return c_ptr;
@@ -204,7 +204,7 @@ struct node *tipc_cltr_select_node(struct cluster *c_ptr, u32 selector)
204 204
205 assert(!in_own_cluster(c_ptr->addr)); 205 assert(!in_own_cluster(c_ptr->addr));
206 if (!c_ptr->highest_node) 206 if (!c_ptr->highest_node)
207 return 0; 207 return NULL;
208 208
209 /* Start entry must be random */ 209 /* Start entry must be random */
210 while (mask > c_ptr->highest_node) { 210 while (mask > c_ptr->highest_node) {
@@ -222,14 +222,14 @@ struct node *tipc_cltr_select_node(struct cluster *c_ptr, u32 selector)
222 if (tipc_node_has_active_links(c_ptr->nodes[n_num])) 222 if (tipc_node_has_active_links(c_ptr->nodes[n_num]))
223 return c_ptr->nodes[n_num]; 223 return c_ptr->nodes[n_num];
224 } 224 }
225 return 0; 225 return NULL;
226} 226}
227 227
228/* 228/*
229 * Routing table management: See description in node.c 229 * Routing table management: See description in node.c
230 */ 230 */
231 231
232struct sk_buff *tipc_cltr_prepare_routing_msg(u32 data_size, u32 dest) 232static struct sk_buff *tipc_cltr_prepare_routing_msg(u32 data_size, u32 dest)
233{ 233{
234 u32 size = INT_H_SIZE + data_size; 234 u32 size = INT_H_SIZE + data_size;
235 struct sk_buff *buf = buf_acquire(size); 235 struct sk_buff *buf = buf_acquire(size);
@@ -495,7 +495,7 @@ void tipc_cltr_remove_as_router(struct cluster *c_ptr, u32 router)
495 * tipc_cltr_multicast - multicast message to local nodes 495 * tipc_cltr_multicast - multicast message to local nodes
496 */ 496 */
497 497
498void tipc_cltr_multicast(struct cluster *c_ptr, struct sk_buff *buf, 498static void tipc_cltr_multicast(struct cluster *c_ptr, struct sk_buff *buf,
499 u32 lower, u32 upper) 499 u32 lower, u32 upper)
500{ 500{
501 struct sk_buff *buf_copy; 501 struct sk_buff *buf_copy;
diff --git a/net/tipc/cluster.h b/net/tipc/cluster.h
index 9963642e1058..1b4cd309495a 100644
--- a/net/tipc/cluster.h
+++ b/net/tipc/cluster.h
@@ -86,7 +86,7 @@ static inline struct cluster *tipc_cltr_find(u32 addr)
86 86
87 if (z_ptr) 87 if (z_ptr)
88 return z_ptr->clusters[1]; 88 return z_ptr->clusters[1];
89 return 0; 89 return NULL;
90} 90}
91 91
92#endif 92#endif
diff --git a/net/tipc/config.c b/net/tipc/config.c
index 3c8e6740e5ae..48b5de2dbe60 100644
--- a/net/tipc/config.c
+++ b/net/tipc/config.c
@@ -683,11 +683,11 @@ int tipc_cfg_init(void)
683 memset(&mng, 0, sizeof(mng)); 683 memset(&mng, 0, sizeof(mng));
684 INIT_LIST_HEAD(&mng.link_subscribers); 684 INIT_LIST_HEAD(&mng.link_subscribers);
685 685
686 res = tipc_attach(&mng.user_ref, 0, 0); 686 res = tipc_attach(&mng.user_ref, NULL, NULL);
687 if (res) 687 if (res)
688 goto failed; 688 goto failed;
689 689
690 res = tipc_createport(mng.user_ref, 0, TIPC_CRITICAL_IMPORTANCE, 690 res = tipc_createport(mng.user_ref, NULL, TIPC_CRITICAL_IMPORTANCE,
691 NULL, NULL, NULL, 691 NULL, NULL, NULL,
692 NULL, cfg_named_msg_event, NULL, 692 NULL, cfg_named_msg_event, NULL,
693 NULL, &mng.port_ref); 693 NULL, &mng.port_ref);
diff --git a/net/tipc/dbg.c b/net/tipc/dbg.c
index 4f4beefa7830..26ef95d5fe38 100644
--- a/net/tipc/dbg.c
+++ b/net/tipc/dbg.c
@@ -81,7 +81,7 @@ void tipc_printbuf_init(struct print_buf *pb, char *raw, u32 sz)
81 81
82 pb->crs = pb->buf = raw; 82 pb->crs = pb->buf = raw;
83 pb->size = sz; 83 pb->size = sz;
84 pb->next = 0; 84 pb->next = NULL;
85 pb->buf[0] = 0; 85 pb->buf[0] = 0;
86 pb->buf[sz-1] = ~0; 86 pb->buf[sz-1] = ~0;
87} 87}
@@ -216,7 +216,7 @@ void tipc_printf(struct print_buf *pb, const char *fmt, ...)
216 } 216 }
217 } 217 }
218 pb_next = pb->next; 218 pb_next = pb->next;
219 pb->next = 0; 219 pb->next = NULL;
220 pb = pb_next; 220 pb = pb_next;
221 } 221 }
222 spin_unlock_bh(&print_lock); 222 spin_unlock_bh(&print_lock);
diff --git a/net/tipc/discover.c b/net/tipc/discover.c
index 53ba4630c10d..92601385e5f5 100644
--- a/net/tipc/discover.c
+++ b/net/tipc/discover.c
@@ -110,10 +110,10 @@ void tipc_disc_link_event(u32 addr, char *name, int up)
110 * @b_ptr: ptr to bearer issuing message 110 * @b_ptr: ptr to bearer issuing message
111 */ 111 */
112 112
113struct sk_buff *tipc_disc_init_msg(u32 type, 113static struct sk_buff *tipc_disc_init_msg(u32 type,
114 u32 req_links, 114 u32 req_links,
115 u32 dest_domain, 115 u32 dest_domain,
116 struct bearer *b_ptr) 116 struct bearer *b_ptr)
117{ 117{
118 struct sk_buff *buf = buf_acquire(DSC_H_SIZE); 118 struct sk_buff *buf = buf_acquire(DSC_H_SIZE);
119 struct tipc_msg *msg; 119 struct tipc_msg *msg;
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c
index 1f8d83b9c8b4..7a252785f727 100644
--- a/net/tipc/eth_media.c
+++ b/net/tipc/eth_media.c
@@ -169,7 +169,7 @@ static int enable_bearer(struct tipc_bearer *tb_ptr)
169 169
170static void disable_bearer(struct tipc_bearer *tb_ptr) 170static void disable_bearer(struct tipc_bearer *tb_ptr)
171{ 171{
172 ((struct eth_bearer *)tb_ptr->usr_handle)->bearer = 0; 172 ((struct eth_bearer *)tb_ptr->usr_handle)->bearer = NULL;
173} 173}
174 174
175/** 175/**
@@ -285,7 +285,7 @@ void tipc_eth_media_stop(void)
285 for (i = 0; i < MAX_ETH_BEARERS ; i++) { 285 for (i = 0; i < MAX_ETH_BEARERS ; i++) {
286 if (eth_bearers[i].bearer) { 286 if (eth_bearers[i].bearer) {
287 eth_bearers[i].bearer->blocked = 1; 287 eth_bearers[i].bearer->blocked = 1;
288 eth_bearers[i].bearer = 0; 288 eth_bearers[i].bearer = NULL;
289 } 289 }
290 if (eth_bearers[i].dev) { 290 if (eth_bearers[i].dev) {
291 dev_remove_pack(&eth_bearers[i].tipc_packet_type); 291 dev_remove_pack(&eth_bearers[i].tipc_packet_type);
diff --git a/net/tipc/link.c b/net/tipc/link.c
index 511872afa459..910b37e5083d 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -157,13 +157,13 @@ static void link_print(struct link *l_ptr, struct print_buf *buf,
157 } \ 157 } \
158} while (0) 158} while (0)
159 159
160static inline void dbg_print_link(struct link *l_ptr, const char *str) 160static void dbg_print_link(struct link *l_ptr, const char *str)
161{ 161{
162 if (DBG_OUTPUT) 162 if (DBG_OUTPUT)
163 link_print(l_ptr, DBG_OUTPUT, str); 163 link_print(l_ptr, DBG_OUTPUT, str);
164} 164}
165 165
166static inline void dbg_print_buf_chain(struct sk_buff *root_buf) 166static void dbg_print_buf_chain(struct sk_buff *root_buf)
167{ 167{
168 if (DBG_OUTPUT) { 168 if (DBG_OUTPUT) {
169 struct sk_buff *buf = root_buf; 169 struct sk_buff *buf = root_buf;
@@ -176,50 +176,50 @@ static inline void dbg_print_buf_chain(struct sk_buff *root_buf)
176} 176}
177 177
178/* 178/*
179 * Simple inlined link routines 179 * Simple link routines
180 */ 180 */
181 181
182static inline unsigned int align(unsigned int i) 182static unsigned int align(unsigned int i)
183{ 183{
184 return (i + 3) & ~3u; 184 return (i + 3) & ~3u;
185} 185}
186 186
187static inline int link_working_working(struct link *l_ptr) 187static int link_working_working(struct link *l_ptr)
188{ 188{
189 return (l_ptr->state == WORKING_WORKING); 189 return (l_ptr->state == WORKING_WORKING);
190} 190}
191 191
192static inline int link_working_unknown(struct link *l_ptr) 192static int link_working_unknown(struct link *l_ptr)
193{ 193{
194 return (l_ptr->state == WORKING_UNKNOWN); 194 return (l_ptr->state == WORKING_UNKNOWN);
195} 195}
196 196
197static inline int link_reset_unknown(struct link *l_ptr) 197static int link_reset_unknown(struct link *l_ptr)
198{ 198{
199 return (l_ptr->state == RESET_UNKNOWN); 199 return (l_ptr->state == RESET_UNKNOWN);
200} 200}
201 201
202static inline int link_reset_reset(struct link *l_ptr) 202static int link_reset_reset(struct link *l_ptr)
203{ 203{
204 return (l_ptr->state == RESET_RESET); 204 return (l_ptr->state == RESET_RESET);
205} 205}
206 206
207static inline int link_blocked(struct link *l_ptr) 207static int link_blocked(struct link *l_ptr)
208{ 208{
209 return (l_ptr->exp_msg_count || l_ptr->blocked); 209 return (l_ptr->exp_msg_count || l_ptr->blocked);
210} 210}
211 211
212static inline int link_congested(struct link *l_ptr) 212static int link_congested(struct link *l_ptr)
213{ 213{
214 return (l_ptr->out_queue_size >= l_ptr->queue_limit[0]); 214 return (l_ptr->out_queue_size >= l_ptr->queue_limit[0]);
215} 215}
216 216
217static inline u32 link_max_pkt(struct link *l_ptr) 217static u32 link_max_pkt(struct link *l_ptr)
218{ 218{
219 return l_ptr->max_pkt; 219 return l_ptr->max_pkt;
220} 220}
221 221
222static inline void link_init_max_pkt(struct link *l_ptr) 222static void link_init_max_pkt(struct link *l_ptr)
223{ 223{
224 u32 max_pkt; 224 u32 max_pkt;
225 225
@@ -236,20 +236,20 @@ static inline void link_init_max_pkt(struct link *l_ptr)
236 l_ptr->max_pkt_probes = 0; 236 l_ptr->max_pkt_probes = 0;
237} 237}
238 238
239static inline u32 link_next_sent(struct link *l_ptr) 239static u32 link_next_sent(struct link *l_ptr)
240{ 240{
241 if (l_ptr->next_out) 241 if (l_ptr->next_out)
242 return msg_seqno(buf_msg(l_ptr->next_out)); 242 return msg_seqno(buf_msg(l_ptr->next_out));
243 return mod(l_ptr->next_out_no); 243 return mod(l_ptr->next_out_no);
244} 244}
245 245
246static inline u32 link_last_sent(struct link *l_ptr) 246static u32 link_last_sent(struct link *l_ptr)
247{ 247{
248 return mod(link_next_sent(l_ptr) - 1); 248 return mod(link_next_sent(l_ptr) - 1);
249} 249}
250 250
251/* 251/*
252 * Simple non-inlined link routines (i.e. referenced outside this file) 252 * Simple non-static link routines (i.e. referenced outside this file)
253 */ 253 */
254 254
255int tipc_link_is_up(struct link *l_ptr) 255int tipc_link_is_up(struct link *l_ptr)
@@ -396,7 +396,7 @@ static void link_timeout(struct link *l_ptr)
396 tipc_node_unlock(l_ptr->owner); 396 tipc_node_unlock(l_ptr->owner);
397} 397}
398 398
399static inline void link_set_timer(struct link *l_ptr, u32 time) 399static void link_set_timer(struct link *l_ptr, u32 time)
400{ 400{
401 k_start_timer(&l_ptr->timer, time); 401 k_start_timer(&l_ptr->timer, time);
402} 402}
@@ -573,7 +573,7 @@ void tipc_link_wakeup_ports(struct link *l_ptr, int all)
573 if (win <= 0) 573 if (win <= 0)
574 break; 574 break;
575 list_del_init(&p_ptr->wait_list); 575 list_del_init(&p_ptr->wait_list);
576 p_ptr->congested_link = 0; 576 p_ptr->congested_link = NULL;
577 assert(p_ptr->wakeup); 577 assert(p_ptr->wakeup);
578 spin_lock_bh(p_ptr->publ.lock); 578 spin_lock_bh(p_ptr->publ.lock);
579 p_ptr->publ.congested = 0; 579 p_ptr->publ.congested = 0;
@@ -1004,9 +1004,9 @@ static int link_bundle_buf(struct link *l_ptr,
1004 return 1; 1004 return 1;
1005} 1005}
1006 1006
1007static inline void link_add_to_outqueue(struct link *l_ptr, 1007static void link_add_to_outqueue(struct link *l_ptr,
1008 struct sk_buff *buf, 1008 struct sk_buff *buf,
1009 struct tipc_msg *msg) 1009 struct tipc_msg *msg)
1010{ 1010{
1011 u32 ack = mod(l_ptr->next_in_no - 1); 1011 u32 ack = mod(l_ptr->next_in_no - 1);
1012 u32 seqno = mod(l_ptr->next_out_no++); 1012 u32 seqno = mod(l_ptr->next_out_no++);
@@ -1156,8 +1156,8 @@ int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector)
1156 * Link is locked. Returns user data length. 1156 * Link is locked. Returns user data length.
1157 */ 1157 */
1158 1158
1159static inline int link_send_buf_fast(struct link *l_ptr, struct sk_buff *buf, 1159static int link_send_buf_fast(struct link *l_ptr, struct sk_buff *buf,
1160 u32 *used_max_pkt) 1160 u32 *used_max_pkt)
1161{ 1161{
1162 struct tipc_msg *msg = buf_msg(buf); 1162 struct tipc_msg *msg = buf_msg(buf);
1163 int res = msg_data_sz(msg); 1163 int res = msg_data_sz(msg);
@@ -1355,7 +1355,7 @@ again:
1355 fragm_crs = 0; 1355 fragm_crs = 0;
1356 fragm_rest = 0; 1356 fragm_rest = 0;
1357 sect_rest = 0; 1357 sect_rest = 0;
1358 sect_crs = 0; 1358 sect_crs = NULL;
1359 curr_sect = -1; 1359 curr_sect = -1;
1360 1360
1361 /* Prepare reusable fragment header: */ 1361 /* Prepare reusable fragment header: */
@@ -1549,7 +1549,7 @@ u32 tipc_link_push_packet(struct link *l_ptr)
1549 msg_dbg(buf_msg(buf), ">DEF-PROT>"); 1549 msg_dbg(buf_msg(buf), ">DEF-PROT>");
1550 l_ptr->unacked_window = 0; 1550 l_ptr->unacked_window = 0;
1551 buf_discard(buf); 1551 buf_discard(buf);
1552 l_ptr->proto_msg_queue = 0; 1552 l_ptr->proto_msg_queue = NULL;
1553 return TIPC_OK; 1553 return TIPC_OK;
1554 } else { 1554 } else {
1555 msg_dbg(buf_msg(buf), "|>DEF-PROT>"); 1555 msg_dbg(buf_msg(buf), "|>DEF-PROT>");
@@ -1860,7 +1860,7 @@ u32 tipc_link_defer_pkt(struct sk_buff **head,
1860 struct sk_buff **tail, 1860 struct sk_buff **tail,
1861 struct sk_buff *buf) 1861 struct sk_buff *buf)
1862{ 1862{
1863 struct sk_buff *prev = 0; 1863 struct sk_buff *prev = NULL;
1864 struct sk_buff *crs = *head; 1864 struct sk_buff *crs = *head;
1865 u32 seq_no = msg_seqno(buf_msg(buf)); 1865 u32 seq_no = msg_seqno(buf_msg(buf));
1866 1866
@@ -1953,7 +1953,7 @@ static void link_handle_out_of_seq_msg(struct link *l_ptr,
1953void tipc_link_send_proto_msg(struct link *l_ptr, u32 msg_typ, int probe_msg, 1953void tipc_link_send_proto_msg(struct link *l_ptr, u32 msg_typ, int probe_msg,
1954 u32 gap, u32 tolerance, u32 priority, u32 ack_mtu) 1954 u32 gap, u32 tolerance, u32 priority, u32 ack_mtu)
1955{ 1955{
1956 struct sk_buff *buf = 0; 1956 struct sk_buff *buf = NULL;
1957 struct tipc_msg *msg = l_ptr->pmsg; 1957 struct tipc_msg *msg = l_ptr->pmsg;
1958 u32 msg_size = sizeof(l_ptr->proto_msg); 1958 u32 msg_size = sizeof(l_ptr->proto_msg);
1959 1959
@@ -2426,7 +2426,7 @@ static int link_recv_changeover_msg(struct link **l_ptr,
2426 } 2426 }
2427 } 2427 }
2428exit: 2428exit:
2429 *buf = 0; 2429 *buf = NULL;
2430 buf_discard(tunnel_buf); 2430 buf_discard(tunnel_buf);
2431 return 0; 2431 return 0;
2432} 2432}
@@ -2539,42 +2539,37 @@ exit:
2539 * pending message. This makes dynamic memory allocation unecessary. 2539 * pending message. This makes dynamic memory allocation unecessary.
2540 */ 2540 */
2541 2541
2542static inline u32 get_long_msg_seqno(struct sk_buff *buf) 2542static void set_long_msg_seqno(struct sk_buff *buf, u32 seqno)
2543{
2544 return msg_seqno(buf_msg(buf));
2545}
2546
2547static inline void set_long_msg_seqno(struct sk_buff *buf, u32 seqno)
2548{ 2543{
2549 msg_set_seqno(buf_msg(buf), seqno); 2544 msg_set_seqno(buf_msg(buf), seqno);
2550} 2545}
2551 2546
2552static inline u32 get_fragm_size(struct sk_buff *buf) 2547static u32 get_fragm_size(struct sk_buff *buf)
2553{ 2548{
2554 return msg_ack(buf_msg(buf)); 2549 return msg_ack(buf_msg(buf));
2555} 2550}
2556 2551
2557static inline void set_fragm_size(struct sk_buff *buf, u32 sz) 2552static void set_fragm_size(struct sk_buff *buf, u32 sz)
2558{ 2553{
2559 msg_set_ack(buf_msg(buf), sz); 2554 msg_set_ack(buf_msg(buf), sz);
2560} 2555}
2561 2556
2562static inline u32 get_expected_frags(struct sk_buff *buf) 2557static u32 get_expected_frags(struct sk_buff *buf)
2563{ 2558{
2564 return msg_bcast_ack(buf_msg(buf)); 2559 return msg_bcast_ack(buf_msg(buf));
2565} 2560}
2566 2561
2567static inline void set_expected_frags(struct sk_buff *buf, u32 exp) 2562static void set_expected_frags(struct sk_buff *buf, u32 exp)
2568{ 2563{
2569 msg_set_bcast_ack(buf_msg(buf), exp); 2564 msg_set_bcast_ack(buf_msg(buf), exp);
2570} 2565}
2571 2566
2572static inline u32 get_timer_cnt(struct sk_buff *buf) 2567static u32 get_timer_cnt(struct sk_buff *buf)
2573{ 2568{
2574 return msg_reroute_cnt(buf_msg(buf)); 2569 return msg_reroute_cnt(buf_msg(buf));
2575} 2570}
2576 2571
2577static inline void incr_timer_cnt(struct sk_buff *buf) 2572static void incr_timer_cnt(struct sk_buff *buf)
2578{ 2573{
2579 msg_incr_reroute_cnt(buf_msg(buf)); 2574 msg_incr_reroute_cnt(buf_msg(buf));
2580} 2575}
@@ -2586,13 +2581,13 @@ static inline void incr_timer_cnt(struct sk_buff *buf)
2586int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb, 2581int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
2587 struct tipc_msg **m) 2582 struct tipc_msg **m)
2588{ 2583{
2589 struct sk_buff *prev = 0; 2584 struct sk_buff *prev = NULL;
2590 struct sk_buff *fbuf = *fb; 2585 struct sk_buff *fbuf = *fb;
2591 struct tipc_msg *fragm = buf_msg(fbuf); 2586 struct tipc_msg *fragm = buf_msg(fbuf);
2592 struct sk_buff *pbuf = *pending; 2587 struct sk_buff *pbuf = *pending;
2593 u32 long_msg_seq_no = msg_long_msgno(fragm); 2588 u32 long_msg_seq_no = msg_long_msgno(fragm);
2594 2589
2595 *fb = 0; 2590 *fb = NULL;
2596 msg_dbg(fragm,"FRG<REC<"); 2591 msg_dbg(fragm,"FRG<REC<");
2597 2592
2598 /* Is there an incomplete message waiting for this fragment? */ 2593 /* Is there an incomplete message waiting for this fragment? */
@@ -2670,8 +2665,8 @@ int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
2670 2665
2671static void link_check_defragm_bufs(struct link *l_ptr) 2666static void link_check_defragm_bufs(struct link *l_ptr)
2672{ 2667{
2673 struct sk_buff *prev = 0; 2668 struct sk_buff *prev = NULL;
2674 struct sk_buff *next = 0; 2669 struct sk_buff *next = NULL;
2675 struct sk_buff *buf = l_ptr->defragm_buf; 2670 struct sk_buff *buf = l_ptr->defragm_buf;
2676 2671
2677 if (!buf) 2672 if (!buf)
@@ -2750,19 +2745,19 @@ static struct link *link_find_link(const char *name, struct node **node)
2750 struct link *l_ptr; 2745 struct link *l_ptr;
2751 2746
2752 if (!link_name_validate(name, &link_name_parts)) 2747 if (!link_name_validate(name, &link_name_parts))
2753 return 0; 2748 return NULL;
2754 2749
2755 b_ptr = tipc_bearer_find_interface(link_name_parts.if_local); 2750 b_ptr = tipc_bearer_find_interface(link_name_parts.if_local);
2756 if (!b_ptr) 2751 if (!b_ptr)
2757 return 0; 2752 return NULL;
2758 2753
2759 *node = tipc_node_find(link_name_parts.addr_peer); 2754 *node = tipc_node_find(link_name_parts.addr_peer);
2760 if (!*node) 2755 if (!*node)
2761 return 0; 2756 return NULL;
2762 2757
2763 l_ptr = (*node)->links[b_ptr->identity]; 2758 l_ptr = (*node)->links[b_ptr->identity];
2764 if (!l_ptr || strcmp(l_ptr->name, name)) 2759 if (!l_ptr || strcmp(l_ptr->name, name))
2765 return 0; 2760 return NULL;
2766 2761
2767 return l_ptr; 2762 return l_ptr;
2768} 2763}
diff --git a/net/tipc/name_distr.c b/net/tipc/name_distr.c
index 830f90999041..953307a9df1d 100644
--- a/net/tipc/name_distr.c
+++ b/net/tipc/name_distr.c
@@ -168,8 +168,8 @@ void tipc_named_withdraw(struct publication *publ)
168void tipc_named_node_up(unsigned long node) 168void tipc_named_node_up(unsigned long node)
169{ 169{
170 struct publication *publ; 170 struct publication *publ;
171 struct distr_item *item = 0; 171 struct distr_item *item = NULL;
172 struct sk_buff *buf = 0; 172 struct sk_buff *buf = NULL;
173 u32 left = 0; 173 u32 left = 0;
174 u32 rest; 174 u32 rest;
175 u32 max_item_buf; 175 u32 max_item_buf;
@@ -200,7 +200,7 @@ void tipc_named_node_up(unsigned long node)
200 "<%u.%u.%u>\n", tipc_zone(node), 200 "<%u.%u.%u>\n", tipc_zone(node),
201 tipc_cluster(node), tipc_node(node)); 201 tipc_cluster(node), tipc_node(node));
202 tipc_link_send(buf, node, node); 202 tipc_link_send(buf, node, node);
203 buf = 0; 203 buf = NULL;
204 } 204 }
205 } 205 }
206exit: 206exit:
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index 3f4b23bd08f7..d129422fc5c2 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -46,7 +46,7 @@
46#include "cluster.h" 46#include "cluster.h"
47#include "bcast.h" 47#include "bcast.h"
48 48
49int tipc_nametbl_size = 1024; /* must be a power of 2 */ 49static int tipc_nametbl_size = 1024; /* must be a power of 2 */
50 50
51/** 51/**
52 * struct sub_seq - container for all published instances of a name sequence 52 * struct sub_seq - container for all published instances of a name sequence
@@ -104,7 +104,7 @@ static atomic_t rsv_publ_ok = ATOMIC_INIT(0);
104rwlock_t tipc_nametbl_lock = RW_LOCK_UNLOCKED; 104rwlock_t tipc_nametbl_lock = RW_LOCK_UNLOCKED;
105 105
106 106
107static inline int hash(int x) 107static int hash(int x)
108{ 108{
109 return(x & (tipc_nametbl_size - 1)); 109 return(x & (tipc_nametbl_size - 1));
110} 110}
@@ -121,7 +121,7 @@ static struct publication *publ_create(u32 type, u32 lower, u32 upper,
121 (struct publication *)kmalloc(sizeof(*publ), GFP_ATOMIC); 121 (struct publication *)kmalloc(sizeof(*publ), GFP_ATOMIC);
122 if (publ == NULL) { 122 if (publ == NULL) {
123 warn("Memory squeeze; failed to create publication\n"); 123 warn("Memory squeeze; failed to create publication\n");
124 return 0; 124 return NULL;
125 } 125 }
126 126
127 memset(publ, 0, sizeof(*publ)); 127 memset(publ, 0, sizeof(*publ));
@@ -142,7 +142,7 @@ static struct publication *publ_create(u32 type, u32 lower, u32 upper,
142 * tipc_subseq_alloc - allocate a specified number of sub-sequence structures 142 * tipc_subseq_alloc - allocate a specified number of sub-sequence structures
143 */ 143 */
144 144
145struct sub_seq *tipc_subseq_alloc(u32 cnt) 145static struct sub_seq *tipc_subseq_alloc(u32 cnt)
146{ 146{
147 u32 sz = cnt * sizeof(struct sub_seq); 147 u32 sz = cnt * sizeof(struct sub_seq);
148 struct sub_seq *sseq = (struct sub_seq *)kmalloc(sz, GFP_ATOMIC); 148 struct sub_seq *sseq = (struct sub_seq *)kmalloc(sz, GFP_ATOMIC);
@@ -158,7 +158,7 @@ struct sub_seq *tipc_subseq_alloc(u32 cnt)
158 * Allocates a single sub-sequence structure and sets it to all 0's. 158 * Allocates a single sub-sequence structure and sets it to all 0's.
159 */ 159 */
160 160
161struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_head) 161static struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_head)
162{ 162{
163 struct name_seq *nseq = 163 struct name_seq *nseq =
164 (struct name_seq *)kmalloc(sizeof(*nseq), GFP_ATOMIC); 164 (struct name_seq *)kmalloc(sizeof(*nseq), GFP_ATOMIC);
@@ -168,7 +168,7 @@ struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_head)
168 warn("Memory squeeze; failed to create name sequence\n"); 168 warn("Memory squeeze; failed to create name sequence\n");
169 kfree(nseq); 169 kfree(nseq);
170 kfree(sseq); 170 kfree(sseq);
171 return 0; 171 return NULL;
172 } 172 }
173 173
174 memset(nseq, 0, sizeof(*nseq)); 174 memset(nseq, 0, sizeof(*nseq));
@@ -190,8 +190,8 @@ struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_head)
190 * Very time-critical, so binary searches through sub-sequence array. 190 * Very time-critical, so binary searches through sub-sequence array.
191 */ 191 */
192 192
193static inline struct sub_seq *nameseq_find_subseq(struct name_seq *nseq, 193static struct sub_seq *nameseq_find_subseq(struct name_seq *nseq,
194 u32 instance) 194 u32 instance)
195{ 195{
196 struct sub_seq *sseqs = nseq->sseqs; 196 struct sub_seq *sseqs = nseq->sseqs;
197 int low = 0; 197 int low = 0;
@@ -207,7 +207,7 @@ static inline struct sub_seq *nameseq_find_subseq(struct name_seq *nseq,
207 else 207 else
208 return &sseqs[mid]; 208 return &sseqs[mid];
209 } 209 }
210 return 0; 210 return NULL;
211} 211}
212 212
213/** 213/**
@@ -243,9 +243,9 @@ static u32 nameseq_locate_subseq(struct name_seq *nseq, u32 instance)
243 * tipc_nameseq_insert_publ - 243 * tipc_nameseq_insert_publ -
244 */ 244 */
245 245
246struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq, 246static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq,
247 u32 type, u32 lower, u32 upper, 247 u32 type, u32 lower, u32 upper,
248 u32 scope, u32 node, u32 port, u32 key) 248 u32 scope, u32 node, u32 port, u32 key)
249{ 249{
250 struct subscription *s; 250 struct subscription *s;
251 struct subscription *st; 251 struct subscription *st;
@@ -263,7 +263,7 @@ struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq,
263 263
264 if ((sseq->lower != lower) || (sseq->upper != upper)) { 264 if ((sseq->lower != lower) || (sseq->upper != upper)) {
265 warn("Overlapping publ <%u,%u,%u>\n", type, lower, upper); 265 warn("Overlapping publ <%u,%u,%u>\n", type, lower, upper);
266 return 0; 266 return NULL;
267 } 267 }
268 } else { 268 } else {
269 u32 inspos; 269 u32 inspos;
@@ -278,7 +278,7 @@ struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq,
278 if ((inspos < nseq->first_free) && 278 if ((inspos < nseq->first_free) &&
279 (upper >= nseq->sseqs[inspos].lower)) { 279 (upper >= nseq->sseqs[inspos].lower)) {
280 warn("Overlapping publ <%u,%u,%u>\n", type, lower, upper); 280 warn("Overlapping publ <%u,%u,%u>\n", type, lower, upper);
281 return 0; 281 return NULL;
282 } 282 }
283 283
284 /* Ensure there is space for new sub-sequence */ 284 /* Ensure there is space for new sub-sequence */
@@ -294,7 +294,7 @@ struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq,
294 nseq->alloc *= 2; 294 nseq->alloc *= 2;
295 } else { 295 } else {
296 warn("Memory squeeze; failed to create sub-sequence\n"); 296 warn("Memory squeeze; failed to create sub-sequence\n");
297 return 0; 297 return NULL;
298 } 298 }
299 } 299 }
300 dbg("Have %u sseqs for type %u\n", nseq->alloc, type); 300 dbg("Have %u sseqs for type %u\n", nseq->alloc, type);
@@ -319,7 +319,7 @@ struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq,
319 319
320 publ = publ_create(type, lower, upper, scope, node, port, key); 320 publ = publ_create(type, lower, upper, scope, node, port, key);
321 if (!publ) 321 if (!publ)
322 return 0; 322 return NULL;
323 dbg("inserting publ %x, node=%x publ->node=%x, subscr->node=%x\n", 323 dbg("inserting publ %x, node=%x publ->node=%x, subscr->node=%x\n",
324 publ, node, publ->node, publ->subscr.node); 324 publ, node, publ->node, publ->subscr.node);
325 325
@@ -369,8 +369,8 @@ struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq,
369 * tipc_nameseq_remove_publ - 369 * tipc_nameseq_remove_publ -
370 */ 370 */
371 371
372struct publication *tipc_nameseq_remove_publ(struct name_seq *nseq, u32 inst, 372static struct publication *tipc_nameseq_remove_publ(struct name_seq *nseq, u32 inst,
373 u32 node, u32 ref, u32 key) 373 u32 node, u32 ref, u32 key)
374{ 374{
375 struct publication *publ; 375 struct publication *publ;
376 struct publication *prev; 376 struct publication *prev;
@@ -394,7 +394,7 @@ struct publication *tipc_nameseq_remove_publ(struct name_seq *nseq, u32 inst,
394 i, &nseq->sseqs[i], nseq->sseqs[i].lower, 394 i, &nseq->sseqs[i], nseq->sseqs[i].lower,
395 nseq->sseqs[i].upper); 395 nseq->sseqs[i].upper);
396 } 396 }
397 return 0; 397 return NULL;
398 } 398 }
399 dbg("nameseq_remove: seq: %x, sseq %x, <%u,%u> key %u\n", 399 dbg("nameseq_remove: seq: %x, sseq %x, <%u,%u> key %u\n",
400 nseq, sseq, nseq->type, inst, key); 400 nseq, sseq, nseq->type, inst, key);
@@ -413,7 +413,7 @@ struct publication *tipc_nameseq_remove_publ(struct name_seq *nseq, u32 inst,
413 prev->zone_list_next = publ->zone_list_next; 413 prev->zone_list_next = publ->zone_list_next;
414 sseq->zone_list = publ->zone_list_next; 414 sseq->zone_list = publ->zone_list_next;
415 } else { 415 } else {
416 sseq->zone_list = 0; 416 sseq->zone_list = NULL;
417 } 417 }
418 418
419 if (in_own_cluster(node)) { 419 if (in_own_cluster(node)) {
@@ -431,7 +431,7 @@ struct publication *tipc_nameseq_remove_publ(struct name_seq *nseq, u32 inst,
431 prev->cluster_list_next = publ->cluster_list_next; 431 prev->cluster_list_next = publ->cluster_list_next;
432 sseq->cluster_list = publ->cluster_list_next; 432 sseq->cluster_list = publ->cluster_list_next;
433 } else { 433 } else {
434 sseq->cluster_list = 0; 434 sseq->cluster_list = NULL;
435 } 435 }
436 } 436 }
437 437
@@ -450,7 +450,7 @@ struct publication *tipc_nameseq_remove_publ(struct name_seq *nseq, u32 inst,
450 prev->node_list_next = publ->node_list_next; 450 prev->node_list_next = publ->node_list_next;
451 sseq->node_list = publ->node_list_next; 451 sseq->node_list = publ->node_list_next;
452 } else { 452 } else {
453 sseq->node_list = 0; 453 sseq->node_list = NULL;
454 } 454 }
455 } 455 }
456 assert(!publ->node || (publ->node == node)); 456 assert(!publ->node || (publ->node == node));
@@ -535,7 +535,7 @@ static struct name_seq *nametbl_find_seq(u32 type)
535 } 535 }
536 } 536 }
537 537
538 return 0; 538 return NULL;
539}; 539};
540 540
541struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper, 541struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper,
@@ -547,7 +547,7 @@ struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper,
547 if (lower > upper) { 547 if (lower > upper) {
548 warn("Failed to publish illegal <%u,%u,%u>\n", 548 warn("Failed to publish illegal <%u,%u,%u>\n",
549 type, lower, upper); 549 type, lower, upper);
550 return 0; 550 return NULL;
551 } 551 }
552 552
553 dbg("Publishing <%u,%u,%u> from %x\n", type, lower, upper, node); 553 dbg("Publishing <%u,%u,%u> from %x\n", type, lower, upper, node);
@@ -556,7 +556,7 @@ struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper,
556 dbg("tipc_nametbl_insert_publ: created %x\n", seq); 556 dbg("tipc_nametbl_insert_publ: created %x\n", seq);
557 } 557 }
558 if (!seq) 558 if (!seq)
559 return 0; 559 return NULL;
560 560
561 assert(seq->type == type); 561 assert(seq->type == type);
562 return tipc_nameseq_insert_publ(seq, type, lower, upper, 562 return tipc_nameseq_insert_publ(seq, type, lower, upper,
@@ -570,7 +570,7 @@ struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower,
570 struct name_seq *seq = nametbl_find_seq(type); 570 struct name_seq *seq = nametbl_find_seq(type);
571 571
572 if (!seq) 572 if (!seq)
573 return 0; 573 return NULL;
574 574
575 dbg("Withdrawing <%u,%u> from %x\n", type, lower, node); 575 dbg("Withdrawing <%u,%u> from %x\n", type, lower, node);
576 publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key); 576 publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key);
@@ -594,7 +594,7 @@ struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower,
594u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *destnode) 594u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *destnode)
595{ 595{
596 struct sub_seq *sseq; 596 struct sub_seq *sseq;
597 struct publication *publ = 0; 597 struct publication *publ = NULL;
598 struct name_seq *seq; 598 struct name_seq *seq;
599 u32 ref; 599 u32 ref;
600 600
@@ -740,12 +740,12 @@ struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper,
740 if (table.local_publ_count >= tipc_max_publications) { 740 if (table.local_publ_count >= tipc_max_publications) {
741 warn("Failed publish: max %u local publication\n", 741 warn("Failed publish: max %u local publication\n",
742 tipc_max_publications); 742 tipc_max_publications);
743 return 0; 743 return NULL;
744 } 744 }
745 if ((type < TIPC_RESERVED_TYPES) && !atomic_read(&rsv_publ_ok)) { 745 if ((type < TIPC_RESERVED_TYPES) && !atomic_read(&rsv_publ_ok)) {
746 warn("Failed to publish reserved name <%u,%u,%u>\n", 746 warn("Failed to publish reserved name <%u,%u,%u>\n",
747 type, lower, upper); 747 type, lower, upper);
748 return 0; 748 return NULL;
749 } 749 }
750 750
751 write_lock_bh(&tipc_nametbl_lock); 751 write_lock_bh(&tipc_nametbl_lock);
@@ -983,6 +983,7 @@ static void nametbl_list(struct print_buf *buf, u32 depth_info,
983 } 983 }
984} 984}
985 985
986#if 0
986void tipc_nametbl_print(struct print_buf *buf, const char *str) 987void tipc_nametbl_print(struct print_buf *buf, const char *str)
987{ 988{
988 tipc_printf(buf, str); 989 tipc_printf(buf, str);
@@ -990,6 +991,7 @@ void tipc_nametbl_print(struct print_buf *buf, const char *str)
990 nametbl_list(buf, 0, 0, 0, 0); 991 nametbl_list(buf, 0, 0, 0, 0);
991 read_unlock_bh(&tipc_nametbl_lock); 992 read_unlock_bh(&tipc_nametbl_lock);
992} 993}
994#endif
993 995
994#define MAX_NAME_TBL_QUERY 32768 996#define MAX_NAME_TBL_QUERY 32768
995 997
@@ -1023,10 +1025,12 @@ struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space)
1023 return buf; 1025 return buf;
1024} 1026}
1025 1027
1028#if 0
1026void tipc_nametbl_dump(void) 1029void tipc_nametbl_dump(void)
1027{ 1030{
1028 nametbl_list(TIPC_CONS, 0, 0, 0, 0); 1031 nametbl_list(TIPC_CONS, 0, 0, 0, 0);
1029} 1032}
1033#endif
1030 1034
1031int tipc_nametbl_init(void) 1035int tipc_nametbl_init(void)
1032{ 1036{
diff --git a/net/tipc/net.c b/net/tipc/net.c
index 074891ad4f09..f7c8223ddf7d 100644
--- a/net/tipc/net.c
+++ b/net/tipc/net.c
@@ -116,7 +116,7 @@
116*/ 116*/
117 117
118rwlock_t tipc_net_lock = RW_LOCK_UNLOCKED; 118rwlock_t tipc_net_lock = RW_LOCK_UNLOCKED;
119struct network tipc_net = { 0 }; 119struct network tipc_net = { NULL };
120 120
121struct node *tipc_net_select_remote_node(u32 addr, u32 ref) 121struct node *tipc_net_select_remote_node(u32 addr, u32 ref)
122{ 122{
@@ -128,13 +128,14 @@ u32 tipc_net_select_router(u32 addr, u32 ref)
128 return tipc_zone_select_router(tipc_net.zones[tipc_zone(addr)], addr, ref); 128 return tipc_zone_select_router(tipc_net.zones[tipc_zone(addr)], addr, ref);
129} 129}
130 130
131 131#if 0
132u32 tipc_net_next_node(u32 a) 132u32 tipc_net_next_node(u32 a)
133{ 133{
134 if (tipc_net.zones[tipc_zone(a)]) 134 if (tipc_net.zones[tipc_zone(a)])
135 return tipc_zone_next_node(a); 135 return tipc_zone_next_node(a);
136 return 0; 136 return 0;
137} 137}
138#endif
138 139
139void tipc_net_remove_as_router(u32 router) 140void tipc_net_remove_as_router(u32 router)
140{ 141{
@@ -181,7 +182,7 @@ static void net_stop(void)
181 tipc_zone_delete(tipc_net.zones[z_num]); 182 tipc_zone_delete(tipc_net.zones[z_num]);
182 } 183 }
183 kfree(tipc_net.zones); 184 kfree(tipc_net.zones);
184 tipc_net.zones = 0; 185 tipc_net.zones = NULL;
185} 186}
186 187
187static void net_route_named_msg(struct sk_buff *buf) 188static void net_route_named_msg(struct sk_buff *buf)
diff --git a/net/tipc/node.c b/net/tipc/node.c
index 6d65010e5fa1..0d5db06e203f 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -155,7 +155,7 @@ static void node_select_active_links(struct node *n_ptr)
155 u32 i; 155 u32 i;
156 u32 highest_prio = 0; 156 u32 highest_prio = 0;
157 157
158 active[0] = active[1] = 0; 158 active[0] = active[1] = NULL;
159 159
160 for (i = 0; i < MAX_BEARERS; i++) { 160 for (i = 0; i < MAX_BEARERS; i++) {
161 struct link *l_ptr = n_ptr->links[i]; 161 struct link *l_ptr = n_ptr->links[i];
@@ -214,7 +214,7 @@ int tipc_node_has_redundant_links(struct node *n_ptr)
214 (n_ptr->active_links[0] != n_ptr->active_links[1])); 214 (n_ptr->active_links[0] != n_ptr->active_links[1]));
215} 215}
216 216
217int tipc_node_has_active_routes(struct node *n_ptr) 217static int tipc_node_has_active_routes(struct node *n_ptr)
218{ 218{
219 return (n_ptr && (n_ptr->last_router >= 0)); 219 return (n_ptr && (n_ptr->last_router >= 0));
220} 220}
@@ -240,7 +240,7 @@ struct node *tipc_node_attach_link(struct link *l_ptr)
240 240
241 err("Attempt to create third link to %s\n", 241 err("Attempt to create third link to %s\n",
242 addr_string_fill(addr_string, n_ptr->addr)); 242 addr_string_fill(addr_string, n_ptr->addr));
243 return 0; 243 return NULL;
244 } 244 }
245 245
246 if (!n_ptr->links[bearer_id]) { 246 if (!n_ptr->links[bearer_id]) {
@@ -253,12 +253,12 @@ struct node *tipc_node_attach_link(struct link *l_ptr)
253 l_ptr->b_ptr->publ.name, 253 l_ptr->b_ptr->publ.name,
254 addr_string_fill(addr_string, l_ptr->addr)); 254 addr_string_fill(addr_string, l_ptr->addr));
255 } 255 }
256 return 0; 256 return NULL;
257} 257}
258 258
259void tipc_node_detach_link(struct node *n_ptr, struct link *l_ptr) 259void tipc_node_detach_link(struct node *n_ptr, struct link *l_ptr)
260{ 260{
261 n_ptr->links[l_ptr->b_ptr->identity] = 0; 261 n_ptr->links[l_ptr->b_ptr->identity] = NULL;
262 tipc_net.zones[tipc_zone(l_ptr->addr)]->links--; 262 tipc_net.zones[tipc_zone(l_ptr->addr)]->links--;
263 n_ptr->link_cnt--; 263 n_ptr->link_cnt--;
264} 264}
@@ -424,7 +424,7 @@ static void node_lost_contact(struct node *n_ptr)
424 424
425 /* Notify subscribers */ 425 /* Notify subscribers */
426 list_for_each_entry_safe(ns, tns, &n_ptr->nsub, nodesub_list) { 426 list_for_each_entry_safe(ns, tns, &n_ptr->nsub, nodesub_list) {
427 ns->node = 0; 427 ns->node = NULL;
428 list_del_init(&ns->nodesub_list); 428 list_del_init(&ns->nodesub_list);
429 tipc_k_signal((Handler)ns->handle_node_down, 429 tipc_k_signal((Handler)ns->handle_node_down,
430 (unsigned long)ns->usr_handle); 430 (unsigned long)ns->usr_handle);
@@ -443,7 +443,7 @@ struct node *tipc_node_select_next_hop(u32 addr, u32 selector)
443 u32 router_addr; 443 u32 router_addr;
444 444
445 if (!tipc_addr_domain_valid(addr)) 445 if (!tipc_addr_domain_valid(addr))
446 return 0; 446 return NULL;
447 447
448 /* Look for direct link to destination processsor */ 448 /* Look for direct link to destination processsor */
449 n_ptr = tipc_node_find(addr); 449 n_ptr = tipc_node_find(addr);
@@ -452,7 +452,7 @@ struct node *tipc_node_select_next_hop(u32 addr, u32 selector)
452 452
453 /* Cluster local system nodes *must* have direct links */ 453 /* Cluster local system nodes *must* have direct links */
454 if (!is_slave(addr) && in_own_cluster(addr)) 454 if (!is_slave(addr) && in_own_cluster(addr))
455 return 0; 455 return NULL;
456 456
457 /* Look for cluster local router with direct link to node */ 457 /* Look for cluster local router with direct link to node */
458 router_addr = tipc_node_select_router(n_ptr, selector); 458 router_addr = tipc_node_select_router(n_ptr, selector);
@@ -462,7 +462,7 @@ struct node *tipc_node_select_next_hop(u32 addr, u32 selector)
462 /* Slave nodes can only be accessed within own cluster via a 462 /* Slave nodes can only be accessed within own cluster via a
463 known router with direct link -- if no router was found,give up */ 463 known router with direct link -- if no router was found,give up */
464 if (is_slave(addr)) 464 if (is_slave(addr))
465 return 0; 465 return NULL;
466 466
467 /* Inter zone/cluster -- find any direct link to remote cluster */ 467 /* Inter zone/cluster -- find any direct link to remote cluster */
468 addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0); 468 addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0);
@@ -475,7 +475,7 @@ struct node *tipc_node_select_next_hop(u32 addr, u32 selector)
475 if (router_addr) 475 if (router_addr)
476 return tipc_node_select(router_addr, selector); 476 return tipc_node_select(router_addr, selector);
477 477
478 return 0; 478 return NULL;
479} 479}
480 480
481/** 481/**
diff --git a/net/tipc/node.h b/net/tipc/node.h
index 29f7ae6992d4..781126e084ae 100644
--- a/net/tipc/node.h
+++ b/net/tipc/node.h
@@ -121,7 +121,7 @@ static inline struct node *tipc_node_find(u32 addr)
121 if (c_ptr) 121 if (c_ptr)
122 return c_ptr->nodes[tipc_node(addr)]; 122 return c_ptr->nodes[tipc_node(addr)];
123 } 123 }
124 return 0; 124 return NULL;
125} 125}
126 126
127static inline struct node *tipc_node_select(u32 addr, u32 selector) 127static inline struct node *tipc_node_select(u32 addr, u32 selector)
diff --git a/net/tipc/node_subscr.c b/net/tipc/node_subscr.c
index afeea121d8be..cff4068cc755 100644
--- a/net/tipc/node_subscr.c
+++ b/net/tipc/node_subscr.c
@@ -47,7 +47,7 @@
47void tipc_nodesub_subscribe(struct node_subscr *node_sub, u32 addr, 47void tipc_nodesub_subscribe(struct node_subscr *node_sub, u32 addr,
48 void *usr_handle, net_ev_handler handle_down) 48 void *usr_handle, net_ev_handler handle_down)
49{ 49{
50 node_sub->node = 0; 50 node_sub->node = NULL;
51 if (addr == tipc_own_addr) 51 if (addr == tipc_own_addr)
52 return; 52 return;
53 if (!tipc_addr_node_valid(addr)) { 53 if (!tipc_addr_node_valid(addr)) {
diff --git a/net/tipc/port.c b/net/tipc/port.c
index 72aae52bfec1..67e96cb1e825 100644
--- a/net/tipc/port.c
+++ b/net/tipc/port.c
@@ -54,8 +54,8 @@
54 54
55#define MAX_REJECT_SIZE 1024 55#define MAX_REJECT_SIZE 1024
56 56
57static struct sk_buff *msg_queue_head = 0; 57static struct sk_buff *msg_queue_head = NULL;
58static struct sk_buff *msg_queue_tail = 0; 58static struct sk_buff *msg_queue_tail = NULL;
59 59
60spinlock_t tipc_port_list_lock = SPIN_LOCK_UNLOCKED; 60spinlock_t tipc_port_list_lock = SPIN_LOCK_UNLOCKED;
61static spinlock_t queue_lock = SPIN_LOCK_UNLOCKED; 61static spinlock_t queue_lock = SPIN_LOCK_UNLOCKED;
@@ -67,27 +67,22 @@ static struct sk_buff* port_build_peer_abort_msg(struct port *,u32 err);
67static void port_timeout(unsigned long ref); 67static void port_timeout(unsigned long ref);
68 68
69 69
70static inline u32 port_peernode(struct port *p_ptr) 70static u32 port_peernode(struct port *p_ptr)
71{ 71{
72 return msg_destnode(&p_ptr->publ.phdr); 72 return msg_destnode(&p_ptr->publ.phdr);
73} 73}
74 74
75static inline u32 port_peerport(struct port *p_ptr) 75static u32 port_peerport(struct port *p_ptr)
76{ 76{
77 return msg_destport(&p_ptr->publ.phdr); 77 return msg_destport(&p_ptr->publ.phdr);
78} 78}
79 79
80static inline u32 port_out_seqno(struct port *p_ptr) 80static u32 port_out_seqno(struct port *p_ptr)
81{ 81{
82 return msg_transp_seqno(&p_ptr->publ.phdr); 82 return msg_transp_seqno(&p_ptr->publ.phdr);
83} 83}
84 84
85static inline void port_set_out_seqno(struct port *p_ptr, u32 seqno) 85static void port_incr_out_seqno(struct port *p_ptr)
86{
87 msg_set_transp_seqno(&p_ptr->publ.phdr,seqno);
88}
89
90static inline void port_incr_out_seqno(struct port *p_ptr)
91{ 86{
92 struct tipc_msg *m = &p_ptr->publ.phdr; 87 struct tipc_msg *m = &p_ptr->publ.phdr;
93 88
@@ -258,11 +253,11 @@ u32 tipc_createport_raw(void *usr_handle,
258 p_ptr->publ.usr_handle = usr_handle; 253 p_ptr->publ.usr_handle = usr_handle;
259 INIT_LIST_HEAD(&p_ptr->wait_list); 254 INIT_LIST_HEAD(&p_ptr->wait_list);
260 INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list); 255 INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list);
261 p_ptr->congested_link = 0; 256 p_ptr->congested_link = NULL;
262 p_ptr->max_pkt = MAX_PKT_DEFAULT; 257 p_ptr->max_pkt = MAX_PKT_DEFAULT;
263 p_ptr->dispatcher = dispatcher; 258 p_ptr->dispatcher = dispatcher;
264 p_ptr->wakeup = wakeup; 259 p_ptr->wakeup = wakeup;
265 p_ptr->user_port = 0; 260 p_ptr->user_port = NULL;
266 k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref); 261 k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref);
267 spin_lock_bh(&tipc_port_list_lock); 262 spin_lock_bh(&tipc_port_list_lock);
268 INIT_LIST_HEAD(&p_ptr->publications); 263 INIT_LIST_HEAD(&p_ptr->publications);
@@ -276,9 +271,9 @@ u32 tipc_createport_raw(void *usr_handle,
276int tipc_deleteport(u32 ref) 271int tipc_deleteport(u32 ref)
277{ 272{
278 struct port *p_ptr; 273 struct port *p_ptr;
279 struct sk_buff *buf = 0; 274 struct sk_buff *buf = NULL;
280 275
281 tipc_withdraw(ref, 0, 0); 276 tipc_withdraw(ref, 0, NULL);
282 p_ptr = tipc_port_lock(ref); 277 p_ptr = tipc_port_lock(ref);
283 if (!p_ptr) 278 if (!p_ptr)
284 return -EINVAL; 279 return -EINVAL;
@@ -329,13 +324,13 @@ void *tipc_get_handle(const u32 ref)
329 324
330 p_ptr = tipc_port_lock(ref); 325 p_ptr = tipc_port_lock(ref);
331 if (!p_ptr) 326 if (!p_ptr)
332 return 0; 327 return NULL;
333 handle = p_ptr->publ.usr_handle; 328 handle = p_ptr->publ.usr_handle;
334 tipc_port_unlock(p_ptr); 329 tipc_port_unlock(p_ptr);
335 return handle; 330 return handle;
336} 331}
337 332
338static inline int port_unreliable(struct port *p_ptr) 333static int port_unreliable(struct port *p_ptr)
339{ 334{
340 return msg_src_droppable(&p_ptr->publ.phdr); 335 return msg_src_droppable(&p_ptr->publ.phdr);
341} 336}
@@ -364,7 +359,7 @@ int tipc_set_portunreliable(u32 ref, unsigned int isunreliable)
364 return TIPC_OK; 359 return TIPC_OK;
365} 360}
366 361
367static inline int port_unreturnable(struct port *p_ptr) 362static int port_unreturnable(struct port *p_ptr)
368{ 363{
369 return msg_dest_droppable(&p_ptr->publ.phdr); 364 return msg_dest_droppable(&p_ptr->publ.phdr);
370} 365}
@@ -475,7 +470,7 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err)
475 470
476 /* send self-abort message when rejecting on a connected port */ 471 /* send self-abort message when rejecting on a connected port */
477 if (msg_connected(msg)) { 472 if (msg_connected(msg)) {
478 struct sk_buff *abuf = 0; 473 struct sk_buff *abuf = NULL;
479 struct port *p_ptr = tipc_port_lock(msg_destport(msg)); 474 struct port *p_ptr = tipc_port_lock(msg_destport(msg));
480 475
481 if (p_ptr) { 476 if (p_ptr) {
@@ -510,7 +505,7 @@ int tipc_port_reject_sections(struct port *p_ptr, struct tipc_msg *hdr,
510static void port_timeout(unsigned long ref) 505static void port_timeout(unsigned long ref)
511{ 506{
512 struct port *p_ptr = tipc_port_lock(ref); 507 struct port *p_ptr = tipc_port_lock(ref);
513 struct sk_buff *buf = 0; 508 struct sk_buff *buf = NULL;
514 509
515 if (!p_ptr || !p_ptr->publ.connected) 510 if (!p_ptr || !p_ptr->publ.connected)
516 return; 511 return;
@@ -540,7 +535,7 @@ static void port_timeout(unsigned long ref)
540static void port_handle_node_down(unsigned long ref) 535static void port_handle_node_down(unsigned long ref)
541{ 536{
542 struct port *p_ptr = tipc_port_lock(ref); 537 struct port *p_ptr = tipc_port_lock(ref);
543 struct sk_buff* buf = 0; 538 struct sk_buff* buf = NULL;
544 539
545 if (!p_ptr) 540 if (!p_ptr)
546 return; 541 return;
@@ -555,7 +550,7 @@ static struct sk_buff *port_build_self_abort_msg(struct port *p_ptr, u32 err)
555 u32 imp = msg_importance(&p_ptr->publ.phdr); 550 u32 imp = msg_importance(&p_ptr->publ.phdr);
556 551
557 if (!p_ptr->publ.connected) 552 if (!p_ptr->publ.connected)
558 return 0; 553 return NULL;
559 if (imp < TIPC_CRITICAL_IMPORTANCE) 554 if (imp < TIPC_CRITICAL_IMPORTANCE)
560 imp++; 555 imp++;
561 return port_build_proto_msg(p_ptr->publ.ref, 556 return port_build_proto_msg(p_ptr->publ.ref,
@@ -575,7 +570,7 @@ static struct sk_buff *port_build_peer_abort_msg(struct port *p_ptr, u32 err)
575 u32 imp = msg_importance(&p_ptr->publ.phdr); 570 u32 imp = msg_importance(&p_ptr->publ.phdr);
576 571
577 if (!p_ptr->publ.connected) 572 if (!p_ptr->publ.connected)
578 return 0; 573 return NULL;
579 if (imp < TIPC_CRITICAL_IMPORTANCE) 574 if (imp < TIPC_CRITICAL_IMPORTANCE)
580 imp++; 575 imp++;
581 return port_build_proto_msg(port_peerport(p_ptr), 576 return port_build_proto_msg(port_peerport(p_ptr),
@@ -594,8 +589,8 @@ void tipc_port_recv_proto_msg(struct sk_buff *buf)
594 struct tipc_msg *msg = buf_msg(buf); 589 struct tipc_msg *msg = buf_msg(buf);
595 struct port *p_ptr = tipc_port_lock(msg_destport(msg)); 590 struct port *p_ptr = tipc_port_lock(msg_destport(msg));
596 u32 err = TIPC_OK; 591 u32 err = TIPC_OK;
597 struct sk_buff *r_buf = 0; 592 struct sk_buff *r_buf = NULL;
598 struct sk_buff *abort_buf = 0; 593 struct sk_buff *abort_buf = NULL;
599 594
600 msg_dbg(msg, "PORT<RECV<:"); 595 msg_dbg(msg, "PORT<RECV<:");
601 596
@@ -804,7 +799,7 @@ static void port_dispatcher_sigh(void *dummy)
804 799
805 spin_lock_bh(&queue_lock); 800 spin_lock_bh(&queue_lock);
806 buf = msg_queue_head; 801 buf = msg_queue_head;
807 msg_queue_head = 0; 802 msg_queue_head = NULL;
808 spin_unlock_bh(&queue_lock); 803 spin_unlock_bh(&queue_lock);
809 804
810 while (buf) { 805 while (buf) {
@@ -991,8 +986,8 @@ static void port_wakeup_sh(unsigned long ref)
991{ 986{
992 struct port *p_ptr; 987 struct port *p_ptr;
993 struct user_port *up_ptr; 988 struct user_port *up_ptr;
994 tipc_continue_event cb = 0; 989 tipc_continue_event cb = NULL;
995 void *uh = 0; 990 void *uh = NULL;
996 991
997 p_ptr = tipc_port_lock(ref); 992 p_ptr = tipc_port_lock(ref);
998 if (p_ptr) { 993 if (p_ptr) {
@@ -1016,7 +1011,7 @@ static void port_wakeup(struct tipc_port *p_ptr)
1016void tipc_acknowledge(u32 ref, u32 ack) 1011void tipc_acknowledge(u32 ref, u32 ack)
1017{ 1012{
1018 struct port *p_ptr; 1013 struct port *p_ptr;
1019 struct sk_buff *buf = 0; 1014 struct sk_buff *buf = NULL;
1020 1015
1021 p_ptr = tipc_port_lock(ref); 1016 p_ptr = tipc_port_lock(ref);
1022 if (!p_ptr) 1017 if (!p_ptr)
@@ -1062,7 +1057,7 @@ int tipc_createport(u32 user_ref,
1062 if (up_ptr == NULL) { 1057 if (up_ptr == NULL) {
1063 return -ENOMEM; 1058 return -ENOMEM;
1064 } 1059 }
1065 ref = tipc_createport_raw(0, port_dispatcher, port_wakeup, importance); 1060 ref = tipc_createport_raw(NULL, port_dispatcher, port_wakeup, importance);
1066 p_ptr = tipc_port_lock(ref); 1061 p_ptr = tipc_port_lock(ref);
1067 if (!p_ptr) { 1062 if (!p_ptr) {
1068 kfree(up_ptr); 1063 kfree(up_ptr);
@@ -1273,7 +1268,7 @@ int tipc_disconnect(u32 ref)
1273int tipc_shutdown(u32 ref) 1268int tipc_shutdown(u32 ref)
1274{ 1269{
1275 struct port *p_ptr; 1270 struct port *p_ptr;
1276 struct sk_buff *buf = 0; 1271 struct sk_buff *buf = NULL;
1277 1272
1278 p_ptr = tipc_port_lock(ref); 1273 p_ptr = tipc_port_lock(ref);
1279 if (!p_ptr) 1274 if (!p_ptr)
diff --git a/net/tipc/ref.c b/net/tipc/ref.c
index 5a13c2defe4a..33bbf5095094 100644
--- a/net/tipc/ref.c
+++ b/net/tipc/ref.c
@@ -61,7 +61,7 @@
61 * because entry 0's reference field has the form XXXX|1--1. 61 * because entry 0's reference field has the form XXXX|1--1.
62 */ 62 */
63 63
64struct ref_table tipc_ref_table = { 0 }; 64struct ref_table tipc_ref_table = { NULL };
65 65
66static rwlock_t ref_table_lock = RW_LOCK_UNLOCKED; 66static rwlock_t ref_table_lock = RW_LOCK_UNLOCKED;
67 67
@@ -86,7 +86,7 @@ int tipc_ref_table_init(u32 requested_size, u32 start)
86 write_lock_bh(&ref_table_lock); 86 write_lock_bh(&ref_table_lock);
87 index_mask = sz - 1; 87 index_mask = sz - 1;
88 for (i = sz - 1; i >= 0; i--) { 88 for (i = sz - 1; i >= 0; i--) {
89 table[i].object = 0; 89 table[i].object = NULL;
90 table[i].lock = SPIN_LOCK_UNLOCKED; 90 table[i].lock = SPIN_LOCK_UNLOCKED;
91 table[i].data.next_plus_upper = (start & ~index_mask) + i - 1; 91 table[i].data.next_plus_upper = (start & ~index_mask) + i - 1;
92 } 92 }
@@ -108,7 +108,7 @@ void tipc_ref_table_stop(void)
108 return; 108 return;
109 109
110 vfree(tipc_ref_table.entries); 110 vfree(tipc_ref_table.entries);
111 tipc_ref_table.entries = 0; 111 tipc_ref_table.entries = NULL;
112} 112}
113 113
114/** 114/**
@@ -173,7 +173,7 @@ void tipc_ref_discard(u32 ref)
173 assert(entry->data.reference == ref); 173 assert(entry->data.reference == ref);
174 174
175 /* mark entry as unused */ 175 /* mark entry as unused */
176 entry->object = 0; 176 entry->object = NULL;
177 if (tipc_ref_table.first_free == 0) 177 if (tipc_ref_table.first_free == 0)
178 tipc_ref_table.first_free = index; 178 tipc_ref_table.first_free = index;
179 else 179 else
diff --git a/net/tipc/ref.h b/net/tipc/ref.h
index 4f8f9f40dcac..6d20006be45b 100644
--- a/net/tipc/ref.h
+++ b/net/tipc/ref.h
@@ -92,7 +92,7 @@ static inline void *tipc_ref_lock(u32 ref)
92 return r->object; 92 return r->object;
93 spin_unlock_bh(&r->lock); 93 spin_unlock_bh(&r->lock);
94 } 94 }
95 return 0; 95 return NULL;
96} 96}
97 97
98/** 98/**
@@ -125,7 +125,7 @@ static inline void *tipc_ref_deref(u32 ref)
125 if (likely(r->data.reference == ref)) 125 if (likely(r->data.reference == ref))
126 return r->object; 126 return r->object;
127 } 127 }
128 return 0; 128 return NULL;
129} 129}
130 130
131#endif 131#endif
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 67253bfcd702..648a734e6044 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -88,7 +88,7 @@ static atomic_t tipc_queue_size = ATOMIC_INIT(0);
88 * with non-socket interfaces. 88 * with non-socket interfaces.
89 * See net.c for description of locking policy. 89 * See net.c for description of locking policy.
90 */ 90 */
91static inline void sock_lock(struct tipc_sock* tsock) 91static void sock_lock(struct tipc_sock* tsock)
92{ 92{
93 spin_lock_bh(tsock->p->lock); 93 spin_lock_bh(tsock->p->lock);
94} 94}
@@ -96,7 +96,7 @@ static inline void sock_lock(struct tipc_sock* tsock)
96/* 96/*
97 * sock_unlock(): Unlock a port/socket pair 97 * sock_unlock(): Unlock a port/socket pair
98 */ 98 */
99static inline void sock_unlock(struct tipc_sock* tsock) 99static void sock_unlock(struct tipc_sock* tsock)
100{ 100{
101 spin_unlock_bh(tsock->p->lock); 101 spin_unlock_bh(tsock->p->lock);
102} 102}
@@ -119,7 +119,7 @@ static inline void sock_unlock(struct tipc_sock* tsock)
119 * Returns pollmask value 119 * Returns pollmask value
120 */ 120 */
121 121
122static inline u32 pollmask(struct socket *sock) 122static u32 pollmask(struct socket *sock)
123{ 123{
124 u32 mask; 124 u32 mask;
125 125
@@ -144,7 +144,7 @@ static inline u32 pollmask(struct socket *sock)
144 * @tsock: TIPC socket 144 * @tsock: TIPC socket
145 */ 145 */
146 146
147static inline void advance_queue(struct tipc_sock *tsock) 147static void advance_queue(struct tipc_sock *tsock)
148{ 148{
149 sock_lock(tsock); 149 sock_lock(tsock);
150 buf_discard(skb_dequeue(&tsock->sk.sk_receive_queue)); 150 buf_discard(skb_dequeue(&tsock->sk.sk_receive_queue));
@@ -178,7 +178,7 @@ static int tipc_create(struct socket *sock, int protocol)
178 if (unlikely(protocol != 0)) 178 if (unlikely(protocol != 0))
179 return -EPROTONOSUPPORT; 179 return -EPROTONOSUPPORT;
180 180
181 ref = tipc_createport_raw(0, &dispatch, &wakeupdispatch, TIPC_LOW_IMPORTANCE); 181 ref = tipc_createport_raw(NULL, &dispatch, &wakeupdispatch, TIPC_LOW_IMPORTANCE);
182 if (unlikely(!ref)) 182 if (unlikely(!ref))
183 return -ENOMEM; 183 return -ENOMEM;
184 184
@@ -265,7 +265,7 @@ static int release(struct socket *sock)
265 sock_lock(tsock); 265 sock_lock(tsock);
266 buf = skb_dequeue(&sk->sk_receive_queue); 266 buf = skb_dequeue(&sk->sk_receive_queue);
267 if (!buf) 267 if (!buf)
268 tsock->p->usr_handle = 0; 268 tsock->p->usr_handle = NULL;
269 sock_unlock(tsock); 269 sock_unlock(tsock);
270 if (!buf) 270 if (!buf)
271 break; 271 break;
@@ -319,7 +319,7 @@ static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len)
319 return -ERESTARTSYS; 319 return -ERESTARTSYS;
320 320
321 if (unlikely(!uaddr_len)) { 321 if (unlikely(!uaddr_len)) {
322 res = tipc_withdraw(tsock->p->ref, 0, 0); 322 res = tipc_withdraw(tsock->p->ref, 0, NULL);
323 goto exit; 323 goto exit;
324 } 324 }
325 325
@@ -412,7 +412,7 @@ static unsigned int poll(struct file *file, struct socket *sock,
412 * Returns 0 if permission is granted, otherwise errno 412 * Returns 0 if permission is granted, otherwise errno
413 */ 413 */
414 414
415static inline int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m) 415static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m)
416{ 416{
417 struct tipc_cfg_msg_hdr hdr; 417 struct tipc_cfg_msg_hdr hdr;
418 418
@@ -695,7 +695,7 @@ static int auto_connect(struct socket *sock, struct tipc_sock *tsock,
695 * Note: Address is not captured if not requested by receiver. 695 * Note: Address is not captured if not requested by receiver.
696 */ 696 */
697 697
698static inline void set_orig_addr(struct msghdr *m, struct tipc_msg *msg) 698static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg)
699{ 699{
700 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)m->msg_name; 700 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)m->msg_name;
701 701
@@ -721,7 +721,7 @@ static inline void set_orig_addr(struct msghdr *m, struct tipc_msg *msg)
721 * Returns 0 if successful, otherwise errno 721 * Returns 0 if successful, otherwise errno
722 */ 722 */
723 723
724static inline int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, 724static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
725 struct tipc_port *tport) 725 struct tipc_port *tport)
726{ 726{
727 u32 anc_data[3]; 727 u32 anc_data[3];
@@ -1226,7 +1226,7 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
1226{ 1226{
1227 struct tipc_sock *tsock = tipc_sk(sock->sk); 1227 struct tipc_sock *tsock = tipc_sk(sock->sk);
1228 struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest; 1228 struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest;
1229 struct msghdr m = {0,}; 1229 struct msghdr m = {NULL,};
1230 struct sk_buff *buf; 1230 struct sk_buff *buf;
1231 struct tipc_msg *msg; 1231 struct tipc_msg *msg;
1232 int res; 1232 int res;
@@ -1251,7 +1251,7 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
1251 /* Send a 'SYN-' to destination */ 1251 /* Send a 'SYN-' to destination */
1252 1252
1253 m.msg_name = dest; 1253 m.msg_name = dest;
1254 if ((res = send_msg(0, sock, &m, 0)) < 0) { 1254 if ((res = send_msg(NULL, sock, &m, 0)) < 0) {
1255 sock->state = SS_DISCONNECTING; 1255 sock->state = SS_DISCONNECTING;
1256 return res; 1256 return res;
1257 } 1257 }
@@ -1367,9 +1367,9 @@ static int accept(struct socket *sock, struct socket *newsock, int flags)
1367 1367
1368 msg_dbg(msg,"<ACC<: "); 1368 msg_dbg(msg,"<ACC<: ");
1369 if (!msg_data_sz(msg)) { 1369 if (!msg_data_sz(msg)) {
1370 struct msghdr m = {0,}; 1370 struct msghdr m = {NULL,};
1371 1371
1372 send_packet(0, newsock, &m, 0); 1372 send_packet(NULL, newsock, &m, 0);
1373 advance_queue(tsock); 1373 advance_queue(tsock);
1374 } else { 1374 } else {
1375 sock_lock(tsock); 1375 sock_lock(tsock);
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
index 5ff38b9f3194..c5f026c7fd38 100644
--- a/net/tipc/subscr.c
+++ b/net/tipc/subscr.c
@@ -86,7 +86,7 @@ static struct top_srv topsrv = { 0 };
86 * Returns converted value 86 * Returns converted value
87 */ 87 */
88 88
89static inline u32 htohl(u32 in, int swap) 89static u32 htohl(u32 in, int swap)
90{ 90{
91 char *c = (char *)&in; 91 char *c = (char *)&in;
92 92
@@ -381,7 +381,7 @@ static void subscr_named_msg_event(void *usr_handle,
381 struct tipc_name_seq const *dest) 381 struct tipc_name_seq const *dest)
382{ 382{
383 struct subscriber *subscriber; 383 struct subscriber *subscriber;
384 struct iovec msg_sect = {0, 0}; 384 struct iovec msg_sect = {NULL, 0};
385 spinlock_t *subscriber_lock; 385 spinlock_t *subscriber_lock;
386 386
387 dbg("subscr_named_msg_event: orig = %x own = %x,\n", 387 dbg("subscr_named_msg_event: orig = %x own = %x,\n",
@@ -413,13 +413,13 @@ static void subscr_named_msg_event(void *usr_handle,
413 tipc_createport(topsrv.user_ref, 413 tipc_createport(topsrv.user_ref,
414 (void *)(unsigned long)subscriber->ref, 414 (void *)(unsigned long)subscriber->ref,
415 importance, 415 importance,
416 0, 416 NULL,
417 0, 417 NULL,
418 subscr_conn_shutdown_event, 418 subscr_conn_shutdown_event,
419 0, 419 NULL,
420 0, 420 NULL,
421 subscr_conn_msg_event, 421 subscr_conn_msg_event,
422 0, 422 NULL,
423 &subscriber->port_ref); 423 &subscriber->port_ref);
424 if (subscriber->port_ref == 0) { 424 if (subscriber->port_ref == 0) {
425 warn("Memory squeeze; failed to create subscription port\n"); 425 warn("Memory squeeze; failed to create subscription port\n");
@@ -461,22 +461,22 @@ int tipc_subscr_start(void)
461 INIT_LIST_HEAD(&topsrv.subscriber_list); 461 INIT_LIST_HEAD(&topsrv.subscriber_list);
462 462
463 spin_lock_bh(&topsrv.lock); 463 spin_lock_bh(&topsrv.lock);
464 res = tipc_attach(&topsrv.user_ref, 0, 0); 464 res = tipc_attach(&topsrv.user_ref, NULL, NULL);
465 if (res) { 465 if (res) {
466 spin_unlock_bh(&topsrv.lock); 466 spin_unlock_bh(&topsrv.lock);
467 return res; 467 return res;
468 } 468 }
469 469
470 res = tipc_createport(topsrv.user_ref, 470 res = tipc_createport(topsrv.user_ref,
471 0, 471 NULL,
472 TIPC_CRITICAL_IMPORTANCE, 472 TIPC_CRITICAL_IMPORTANCE,
473 0, 473 NULL,
474 0, 474 NULL,
475 0, 475 NULL,
476 0, 476 NULL,
477 subscr_named_msg_event, 477 subscr_named_msg_event,
478 0, 478 NULL,
479 0, 479 NULL,
480 &topsrv.setup_port); 480 &topsrv.setup_port);
481 if (res) 481 if (res)
482 goto failed; 482 goto failed;
diff --git a/net/tipc/user_reg.c b/net/tipc/user_reg.c
index 106200d76587..3f3f933976e9 100644
--- a/net/tipc/user_reg.c
+++ b/net/tipc/user_reg.c
@@ -65,7 +65,7 @@ struct tipc_user {
65#define MAX_USERID 64 65#define MAX_USERID 64
66#define USER_LIST_SIZE ((MAX_USERID + 1) * sizeof(struct tipc_user)) 66#define USER_LIST_SIZE ((MAX_USERID + 1) * sizeof(struct tipc_user))
67 67
68static struct tipc_user *users = 0; 68static struct tipc_user *users = NULL;
69static u32 next_free_user = MAX_USERID + 1; 69static u32 next_free_user = MAX_USERID + 1;
70static spinlock_t reg_lock = SPIN_LOCK_UNLOCKED; 70static spinlock_t reg_lock = SPIN_LOCK_UNLOCKED;
71 71
@@ -149,7 +149,7 @@ void tipc_reg_stop(void)
149 reg_callback(&users[id]); 149 reg_callback(&users[id]);
150 } 150 }
151 kfree(users); 151 kfree(users);
152 users = 0; 152 users = NULL;
153} 153}
154 154
155/** 155/**
diff --git a/net/tipc/zone.c b/net/tipc/zone.c
index 7c11f7f83a21..2803e1b4f170 100644
--- a/net/tipc/zone.c
+++ b/net/tipc/zone.c
@@ -44,11 +44,11 @@
44 44
45struct _zone *tipc_zone_create(u32 addr) 45struct _zone *tipc_zone_create(u32 addr)
46{ 46{
47 struct _zone *z_ptr = 0; 47 struct _zone *z_ptr = NULL;
48 u32 z_num; 48 u32 z_num;
49 49
50 if (!tipc_addr_domain_valid(addr)) 50 if (!tipc_addr_domain_valid(addr))
51 return 0; 51 return NULL;
52 52
53 z_ptr = (struct _zone *)kmalloc(sizeof(*z_ptr), GFP_ATOMIC); 53 z_ptr = (struct _zone *)kmalloc(sizeof(*z_ptr), GFP_ATOMIC);
54 if (z_ptr != NULL) { 54 if (z_ptr != NULL) {
@@ -114,10 +114,10 @@ struct node *tipc_zone_select_remote_node(struct _zone *z_ptr, u32 addr, u32 ref
114 u32 c_num; 114 u32 c_num;
115 115
116 if (!z_ptr) 116 if (!z_ptr)
117 return 0; 117 return NULL;
118 c_ptr = z_ptr->clusters[tipc_cluster(addr)]; 118 c_ptr = z_ptr->clusters[tipc_cluster(addr)];
119 if (!c_ptr) 119 if (!c_ptr)
120 return 0; 120 return NULL;
121 n_ptr = tipc_cltr_select_node(c_ptr, ref); 121 n_ptr = tipc_cltr_select_node(c_ptr, ref);
122 if (n_ptr) 122 if (n_ptr)
123 return n_ptr; 123 return n_ptr;
@@ -126,12 +126,12 @@ struct node *tipc_zone_select_remote_node(struct _zone *z_ptr, u32 addr, u32 ref
126 for (c_num = 1; c_num <= tipc_max_clusters; c_num++) { 126 for (c_num = 1; c_num <= tipc_max_clusters; c_num++) {
127 c_ptr = z_ptr->clusters[c_num]; 127 c_ptr = z_ptr->clusters[c_num];
128 if (!c_ptr) 128 if (!c_ptr)
129 return 0; 129 return NULL;
130 n_ptr = tipc_cltr_select_node(c_ptr, ref); 130 n_ptr = tipc_cltr_select_node(c_ptr, ref);
131 if (n_ptr) 131 if (n_ptr)
132 return n_ptr; 132 return n_ptr;
133 } 133 }
134 return 0; 134 return NULL;
135} 135}
136 136
137u32 tipc_zone_select_router(struct _zone *z_ptr, u32 addr, u32 ref) 137u32 tipc_zone_select_router(struct _zone *z_ptr, u32 addr, u32 ref)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index c323cc6a28b0..2b4cc2eea5b3 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -566,7 +566,7 @@ static struct sock * unix_create1(struct socket *sock)
566 u->mnt = NULL; 566 u->mnt = NULL;
567 spin_lock_init(&u->lock); 567 spin_lock_init(&u->lock);
568 atomic_set(&u->inflight, sock ? 0 : -1); 568 atomic_set(&u->inflight, sock ? 0 : -1);
569 init_MUTEX(&u->readsem); /* single task reading lock */ 569 mutex_init(&u->readlock); /* single task reading lock */
570 init_waitqueue_head(&u->peer_wait); 570 init_waitqueue_head(&u->peer_wait);
571 unix_insert_socket(unix_sockets_unbound, sk); 571 unix_insert_socket(unix_sockets_unbound, sk);
572out: 572out:
@@ -623,7 +623,7 @@ static int unix_autobind(struct socket *sock)
623 struct unix_address * addr; 623 struct unix_address * addr;
624 int err; 624 int err;
625 625
626 down(&u->readsem); 626 mutex_lock(&u->readlock);
627 627
628 err = 0; 628 err = 0;
629 if (u->addr) 629 if (u->addr)
@@ -661,7 +661,7 @@ retry:
661 spin_unlock(&unix_table_lock); 661 spin_unlock(&unix_table_lock);
662 err = 0; 662 err = 0;
663 663
664out: up(&u->readsem); 664out: mutex_unlock(&u->readlock);
665 return err; 665 return err;
666} 666}
667 667
@@ -744,7 +744,7 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
744 goto out; 744 goto out;
745 addr_len = err; 745 addr_len = err;
746 746
747 down(&u->readsem); 747 mutex_lock(&u->readlock);
748 748
749 err = -EINVAL; 749 err = -EINVAL;
750 if (u->addr) 750 if (u->addr)
@@ -816,7 +816,7 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
816out_unlock: 816out_unlock:
817 spin_unlock(&unix_table_lock); 817 spin_unlock(&unix_table_lock);
818out_up: 818out_up:
819 up(&u->readsem); 819 mutex_unlock(&u->readlock);
820out: 820out:
821 return err; 821 return err;
822 822
@@ -1427,15 +1427,15 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1427 while(sent < len) 1427 while(sent < len)
1428 { 1428 {
1429 /* 1429 /*
1430 * Optimisation for the fact that under 0.01% of X messages typically 1430 * Optimisation for the fact that under 0.01% of X
1431 * need breaking up. 1431 * messages typically need breaking up.
1432 */ 1432 */
1433 1433
1434 size=len-sent; 1434 size = len-sent;
1435 1435
1436 /* Keep two messages in the pipe so it schedules better */ 1436 /* Keep two messages in the pipe so it schedules better */
1437 if (size > sk->sk_sndbuf / 2 - 64) 1437 if (size > ((sk->sk_sndbuf >> 1) - 64))
1438 size = sk->sk_sndbuf / 2 - 64; 1438 size = (sk->sk_sndbuf >> 1) - 64;
1439 1439
1440 if (size > SKB_MAX_ALLOC) 1440 if (size > SKB_MAX_ALLOC)
1441 size = SKB_MAX_ALLOC; 1441 size = SKB_MAX_ALLOC;
@@ -1545,7 +1545,7 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1545 1545
1546 msg->msg_namelen = 0; 1546 msg->msg_namelen = 0;
1547 1547
1548 down(&u->readsem); 1548 mutex_lock(&u->readlock);
1549 1549
1550 skb = skb_recv_datagram(sk, flags, noblock, &err); 1550 skb = skb_recv_datagram(sk, flags, noblock, &err);
1551 if (!skb) 1551 if (!skb)
@@ -1600,7 +1600,7 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1600out_free: 1600out_free:
1601 skb_free_datagram(sk,skb); 1601 skb_free_datagram(sk,skb);
1602out_unlock: 1602out_unlock:
1603 up(&u->readsem); 1603 mutex_unlock(&u->readlock);
1604out: 1604out:
1605 return err; 1605 return err;
1606} 1606}
@@ -1676,7 +1676,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1676 memset(&tmp_scm, 0, sizeof(tmp_scm)); 1676 memset(&tmp_scm, 0, sizeof(tmp_scm));
1677 } 1677 }
1678 1678
1679 down(&u->readsem); 1679 mutex_lock(&u->readlock);
1680 1680
1681 do 1681 do
1682 { 1682 {
@@ -1700,7 +1700,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1700 err = -EAGAIN; 1700 err = -EAGAIN;
1701 if (!timeo) 1701 if (!timeo)
1702 break; 1702 break;
1703 up(&u->readsem); 1703 mutex_unlock(&u->readlock);
1704 1704
1705 timeo = unix_stream_data_wait(sk, timeo); 1705 timeo = unix_stream_data_wait(sk, timeo);
1706 1706
@@ -1708,7 +1708,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1708 err = sock_intr_errno(timeo); 1708 err = sock_intr_errno(timeo);
1709 goto out; 1709 goto out;
1710 } 1710 }
1711 down(&u->readsem); 1711 mutex_lock(&u->readlock);
1712 continue; 1712 continue;
1713 } 1713 }
1714 1714
@@ -1774,7 +1774,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1774 } 1774 }
1775 } while (size); 1775 } while (size);
1776 1776
1777 up(&u->readsem); 1777 mutex_unlock(&u->readlock);
1778 scm_recv(sock, msg, siocb->scm, flags); 1778 scm_recv(sock, msg, siocb->scm, flags);
1779out: 1779out:
1780 return copied ? : err; 1780 return copied ? : err;
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index 411802bd4d37..746c2f4a5fa6 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -76,6 +76,7 @@
76#include <linux/netdevice.h> 76#include <linux/netdevice.h>
77#include <linux/file.h> 77#include <linux/file.h>
78#include <linux/proc_fs.h> 78#include <linux/proc_fs.h>
79#include <linux/mutex.h>
79 80
80#include <net/sock.h> 81#include <net/sock.h>
81#include <net/af_unix.h> 82#include <net/af_unix.h>
@@ -169,7 +170,7 @@ static void maybe_unmark_and_push(struct sock *x)
169 170
170void unix_gc(void) 171void unix_gc(void)
171{ 172{
172 static DECLARE_MUTEX(unix_gc_sem); 173 static DEFINE_MUTEX(unix_gc_sem);
173 int i; 174 int i;
174 struct sock *s; 175 struct sock *s;
175 struct sk_buff_head hitlist; 176 struct sk_buff_head hitlist;
@@ -179,7 +180,7 @@ void unix_gc(void)
179 * Avoid a recursive GC. 180 * Avoid a recursive GC.
180 */ 181 */
181 182
182 if (down_trylock(&unix_gc_sem)) 183 if (!mutex_trylock(&unix_gc_sem))
183 return; 184 return;
184 185
185 spin_lock(&unix_table_lock); 186 spin_lock(&unix_table_lock);
@@ -308,5 +309,5 @@ void unix_gc(void)
308 */ 309 */
309 310
310 __skb_queue_purge(&hitlist); 311 __skb_queue_purge(&hitlist);
311 up(&unix_gc_sem); 312 mutex_unlock(&unix_gc_sem);
312} 313}
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index ae62054a9fc4..f5eae9febd26 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -26,8 +26,8 @@
26#include <net/xfrm.h> 26#include <net/xfrm.h>
27#include <net/ip.h> 27#include <net/ip.h>
28 28
29DECLARE_MUTEX(xfrm_cfg_sem); 29DEFINE_MUTEX(xfrm_cfg_mutex);
30EXPORT_SYMBOL(xfrm_cfg_sem); 30EXPORT_SYMBOL(xfrm_cfg_mutex);
31 31
32static DEFINE_RWLOCK(xfrm_policy_lock); 32static DEFINE_RWLOCK(xfrm_policy_lock);
33 33
@@ -203,7 +203,7 @@ static void xfrm_policy_timer(unsigned long data)
203 } 203 }
204 204
205 if (warn) 205 if (warn)
206 km_policy_expired(xp, dir, 0); 206 km_policy_expired(xp, dir, 0, 0);
207 if (next != LONG_MAX && 207 if (next != LONG_MAX &&
208 !mod_timer(&xp->timer, jiffies + make_jiffies(next))) 208 !mod_timer(&xp->timer, jiffies + make_jiffies(next)))
209 xfrm_pol_hold(xp); 209 xfrm_pol_hold(xp);
@@ -216,7 +216,7 @@ out:
216expired: 216expired:
217 read_unlock(&xp->lock); 217 read_unlock(&xp->lock);
218 if (!xfrm_policy_delete(xp, dir)) 218 if (!xfrm_policy_delete(xp, dir))
219 km_policy_expired(xp, dir, 1); 219 km_policy_expired(xp, dir, 1, 0);
220 xfrm_pol_put(xp); 220 xfrm_pol_put(xp);
221} 221}
222 222
@@ -621,6 +621,7 @@ int xfrm_policy_delete(struct xfrm_policy *pol, int dir)
621 } 621 }
622 return -ENOENT; 622 return -ENOENT;
623} 623}
624EXPORT_SYMBOL(xfrm_policy_delete);
624 625
625int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol) 626int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol)
626{ 627{
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index c656cbaf35e8..a8e14dc1b04e 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -20,6 +20,15 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <asm/uaccess.h> 21#include <asm/uaccess.h>
22 22
23struct sock *xfrm_nl;
24EXPORT_SYMBOL(xfrm_nl);
25
26u32 sysctl_xfrm_aevent_etime = XFRM_AE_ETIME;
27EXPORT_SYMBOL(sysctl_xfrm_aevent_etime);
28
29u32 sysctl_xfrm_aevent_rseqth = XFRM_AE_SEQT_SIZE;
30EXPORT_SYMBOL(sysctl_xfrm_aevent_rseqth);
31
23/* Each xfrm_state may be linked to two tables: 32/* Each xfrm_state may be linked to two tables:
24 33
25 1. Hash table by (spi,daddr,ah/esp) to find SA by SPI. (input,ctl) 34 1. Hash table by (spi,daddr,ah/esp) to find SA by SPI. (input,ctl)
@@ -50,18 +59,20 @@ static DEFINE_SPINLOCK(xfrm_state_gc_lock);
50 59
51static int xfrm_state_gc_flush_bundles; 60static int xfrm_state_gc_flush_bundles;
52 61
53static int __xfrm_state_delete(struct xfrm_state *x); 62int __xfrm_state_delete(struct xfrm_state *x);
54 63
55static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned short family); 64static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned short family);
56static void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo); 65static void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo);
57 66
58static int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol); 67int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol);
59static void km_state_expired(struct xfrm_state *x, int hard); 68void km_state_expired(struct xfrm_state *x, int hard, u32 pid);
60 69
61static void xfrm_state_gc_destroy(struct xfrm_state *x) 70static void xfrm_state_gc_destroy(struct xfrm_state *x)
62{ 71{
63 if (del_timer(&x->timer)) 72 if (del_timer(&x->timer))
64 BUG(); 73 BUG();
74 if (del_timer(&x->rtimer))
75 BUG();
65 kfree(x->aalg); 76 kfree(x->aalg);
66 kfree(x->ealg); 77 kfree(x->ealg);
67 kfree(x->calg); 78 kfree(x->calg);
@@ -153,7 +164,7 @@ static void xfrm_timer_handler(unsigned long data)
153 164
154 x->km.dying = warn; 165 x->km.dying = warn;
155 if (warn) 166 if (warn)
156 km_state_expired(x, 0); 167 km_state_expired(x, 0, 0);
157resched: 168resched:
158 if (next != LONG_MAX && 169 if (next != LONG_MAX &&
159 !mod_timer(&x->timer, jiffies + make_jiffies(next))) 170 !mod_timer(&x->timer, jiffies + make_jiffies(next)))
@@ -168,13 +179,15 @@ expired:
168 goto resched; 179 goto resched;
169 } 180 }
170 if (!__xfrm_state_delete(x) && x->id.spi) 181 if (!__xfrm_state_delete(x) && x->id.spi)
171 km_state_expired(x, 1); 182 km_state_expired(x, 1, 0);
172 183
173out: 184out:
174 spin_unlock(&x->lock); 185 spin_unlock(&x->lock);
175 xfrm_state_put(x); 186 xfrm_state_put(x);
176} 187}
177 188
189static void xfrm_replay_timer_handler(unsigned long data);
190
178struct xfrm_state *xfrm_state_alloc(void) 191struct xfrm_state *xfrm_state_alloc(void)
179{ 192{
180 struct xfrm_state *x; 193 struct xfrm_state *x;
@@ -190,11 +203,16 @@ struct xfrm_state *xfrm_state_alloc(void)
190 init_timer(&x->timer); 203 init_timer(&x->timer);
191 x->timer.function = xfrm_timer_handler; 204 x->timer.function = xfrm_timer_handler;
192 x->timer.data = (unsigned long)x; 205 x->timer.data = (unsigned long)x;
206 init_timer(&x->rtimer);
207 x->rtimer.function = xfrm_replay_timer_handler;
208 x->rtimer.data = (unsigned long)x;
193 x->curlft.add_time = (unsigned long)xtime.tv_sec; 209 x->curlft.add_time = (unsigned long)xtime.tv_sec;
194 x->lft.soft_byte_limit = XFRM_INF; 210 x->lft.soft_byte_limit = XFRM_INF;
195 x->lft.soft_packet_limit = XFRM_INF; 211 x->lft.soft_packet_limit = XFRM_INF;
196 x->lft.hard_byte_limit = XFRM_INF; 212 x->lft.hard_byte_limit = XFRM_INF;
197 x->lft.hard_packet_limit = XFRM_INF; 213 x->lft.hard_packet_limit = XFRM_INF;
214 x->replay_maxage = 0;
215 x->replay_maxdiff = 0;
198 spin_lock_init(&x->lock); 216 spin_lock_init(&x->lock);
199 } 217 }
200 return x; 218 return x;
@@ -212,7 +230,7 @@ void __xfrm_state_destroy(struct xfrm_state *x)
212} 230}
213EXPORT_SYMBOL(__xfrm_state_destroy); 231EXPORT_SYMBOL(__xfrm_state_destroy);
214 232
215static int __xfrm_state_delete(struct xfrm_state *x) 233int __xfrm_state_delete(struct xfrm_state *x)
216{ 234{
217 int err = -ESRCH; 235 int err = -ESRCH;
218 236
@@ -228,6 +246,8 @@ static int __xfrm_state_delete(struct xfrm_state *x)
228 spin_unlock(&xfrm_state_lock); 246 spin_unlock(&xfrm_state_lock);
229 if (del_timer(&x->timer)) 247 if (del_timer(&x->timer))
230 __xfrm_state_put(x); 248 __xfrm_state_put(x);
249 if (del_timer(&x->rtimer))
250 __xfrm_state_put(x);
231 251
232 /* The number two in this test is the reference 252 /* The number two in this test is the reference
233 * mentioned in the comment below plus the reference 253 * mentioned in the comment below plus the reference
@@ -249,6 +269,7 @@ static int __xfrm_state_delete(struct xfrm_state *x)
249 269
250 return err; 270 return err;
251} 271}
272EXPORT_SYMBOL(__xfrm_state_delete);
252 273
253int xfrm_state_delete(struct xfrm_state *x) 274int xfrm_state_delete(struct xfrm_state *x)
254{ 275{
@@ -426,6 +447,10 @@ static void __xfrm_state_insert(struct xfrm_state *x)
426 if (!mod_timer(&x->timer, jiffies + HZ)) 447 if (!mod_timer(&x->timer, jiffies + HZ))
427 xfrm_state_hold(x); 448 xfrm_state_hold(x);
428 449
450 if (x->replay_maxage &&
451 !mod_timer(&x->rtimer, jiffies + x->replay_maxage))
452 xfrm_state_hold(x);
453
429 wake_up(&km_waitq); 454 wake_up(&km_waitq);
430} 455}
431 456
@@ -580,7 +605,7 @@ int xfrm_state_check_expire(struct xfrm_state *x)
580 (x->curlft.bytes >= x->lft.soft_byte_limit || 605 (x->curlft.bytes >= x->lft.soft_byte_limit ||
581 x->curlft.packets >= x->lft.soft_packet_limit)) { 606 x->curlft.packets >= x->lft.soft_packet_limit)) {
582 x->km.dying = 1; 607 x->km.dying = 1;
583 km_state_expired(x, 0); 608 km_state_expired(x, 0, 0);
584 } 609 }
585 return 0; 610 return 0;
586} 611}
@@ -762,6 +787,61 @@ out:
762} 787}
763EXPORT_SYMBOL(xfrm_state_walk); 788EXPORT_SYMBOL(xfrm_state_walk);
764 789
790
791void xfrm_replay_notify(struct xfrm_state *x, int event)
792{
793 struct km_event c;
794 /* we send notify messages in case
795 * 1. we updated on of the sequence numbers, and the seqno difference
796 * is at least x->replay_maxdiff, in this case we also update the
797 * timeout of our timer function
798 * 2. if x->replay_maxage has elapsed since last update,
799 * and there were changes
800 *
801 * The state structure must be locked!
802 */
803
804 switch (event) {
805 case XFRM_REPLAY_UPDATE:
806 if (x->replay_maxdiff &&
807 (x->replay.seq - x->preplay.seq < x->replay_maxdiff) &&
808 (x->replay.oseq - x->preplay.oseq < x->replay_maxdiff))
809 return;
810
811 break;
812
813 case XFRM_REPLAY_TIMEOUT:
814 if ((x->replay.seq == x->preplay.seq) &&
815 (x->replay.bitmap == x->preplay.bitmap) &&
816 (x->replay.oseq == x->preplay.oseq))
817 return;
818
819 break;
820 }
821
822 memcpy(&x->preplay, &x->replay, sizeof(struct xfrm_replay_state));
823 c.event = XFRM_MSG_NEWAE;
824 c.data.aevent = event;
825 km_state_notify(x, &c);
826
827 if (x->replay_maxage &&
828 !mod_timer(&x->rtimer, jiffies + x->replay_maxage))
829 xfrm_state_hold(x);
830}
831EXPORT_SYMBOL(xfrm_replay_notify);
832
833static void xfrm_replay_timer_handler(unsigned long data)
834{
835 struct xfrm_state *x = (struct xfrm_state*)data;
836
837 spin_lock(&x->lock);
838
839 if (xfrm_aevent_is_on() && x->km.state == XFRM_STATE_VALID)
840 xfrm_replay_notify(x, XFRM_REPLAY_TIMEOUT);
841
842 spin_unlock(&x->lock);
843}
844
765int xfrm_replay_check(struct xfrm_state *x, u32 seq) 845int xfrm_replay_check(struct xfrm_state *x, u32 seq)
766{ 846{
767 u32 diff; 847 u32 diff;
@@ -805,6 +885,9 @@ void xfrm_replay_advance(struct xfrm_state *x, u32 seq)
805 diff = x->replay.seq - seq; 885 diff = x->replay.seq - seq;
806 x->replay.bitmap |= (1U << diff); 886 x->replay.bitmap |= (1U << diff);
807 } 887 }
888
889 if (xfrm_aevent_is_on())
890 xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
808} 891}
809EXPORT_SYMBOL(xfrm_replay_advance); 892EXPORT_SYMBOL(xfrm_replay_advance);
810 893
@@ -835,11 +918,12 @@ void km_state_notify(struct xfrm_state *x, struct km_event *c)
835EXPORT_SYMBOL(km_policy_notify); 918EXPORT_SYMBOL(km_policy_notify);
836EXPORT_SYMBOL(km_state_notify); 919EXPORT_SYMBOL(km_state_notify);
837 920
838static void km_state_expired(struct xfrm_state *x, int hard) 921void km_state_expired(struct xfrm_state *x, int hard, u32 pid)
839{ 922{
840 struct km_event c; 923 struct km_event c;
841 924
842 c.data.hard = hard; 925 c.data.hard = hard;
926 c.pid = pid;
843 c.event = XFRM_MSG_EXPIRE; 927 c.event = XFRM_MSG_EXPIRE;
844 km_state_notify(x, &c); 928 km_state_notify(x, &c);
845 929
@@ -847,11 +931,12 @@ static void km_state_expired(struct xfrm_state *x, int hard)
847 wake_up(&km_waitq); 931 wake_up(&km_waitq);
848} 932}
849 933
934EXPORT_SYMBOL(km_state_expired);
850/* 935/*
851 * We send to all registered managers regardless of failure 936 * We send to all registered managers regardless of failure
852 * We are happy with one success 937 * We are happy with one success
853*/ 938*/
854static int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol) 939int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol)
855{ 940{
856 int err = -EINVAL, acqret; 941 int err = -EINVAL, acqret;
857 struct xfrm_mgr *km; 942 struct xfrm_mgr *km;
@@ -865,6 +950,7 @@ static int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_polic
865 read_unlock(&xfrm_km_lock); 950 read_unlock(&xfrm_km_lock);
866 return err; 951 return err;
867} 952}
953EXPORT_SYMBOL(km_query);
868 954
869int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport) 955int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport)
870{ 956{
@@ -883,17 +969,19 @@ int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport)
883} 969}
884EXPORT_SYMBOL(km_new_mapping); 970EXPORT_SYMBOL(km_new_mapping);
885 971
886void km_policy_expired(struct xfrm_policy *pol, int dir, int hard) 972void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 pid)
887{ 973{
888 struct km_event c; 974 struct km_event c;
889 975
890 c.data.hard = hard; 976 c.data.hard = hard;
977 c.pid = pid;
891 c.event = XFRM_MSG_POLEXPIRE; 978 c.event = XFRM_MSG_POLEXPIRE;
892 km_policy_notify(pol, dir, &c); 979 km_policy_notify(pol, dir, &c);
893 980
894 if (hard) 981 if (hard)
895 wake_up(&km_waitq); 982 wake_up(&km_waitq);
896} 983}
984EXPORT_SYMBOL(km_policy_expired);
897 985
898int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen) 986int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen)
899{ 987{
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 7de17559249a..81d1005830f4 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -28,8 +28,6 @@
28#include <net/netlink.h> 28#include <net/netlink.h>
29#include <asm/uaccess.h> 29#include <asm/uaccess.h>
30 30
31static struct sock *xfrm_nl;
32
33static int verify_one_alg(struct rtattr **xfrma, enum xfrm_attr_type_t type) 31static int verify_one_alg(struct rtattr **xfrma, enum xfrm_attr_type_t type)
34{ 32{
35 struct rtattr *rt = xfrma[type - 1]; 33 struct rtattr *rt = xfrma[type - 1];
@@ -103,9 +101,6 @@ static inline int verify_sec_ctx_len(struct rtattr **xfrma)
103 101
104 uctx = RTA_DATA(rt); 102 uctx = RTA_DATA(rt);
105 103
106 if (uctx->ctx_len > PAGE_SIZE)
107 return -EINVAL;
108
109 len += sizeof(struct xfrm_user_sec_ctx); 104 len += sizeof(struct xfrm_user_sec_ctx);
110 len += uctx->ctx_len; 105 len += uctx->ctx_len;
111 106
@@ -276,6 +271,56 @@ static void copy_from_user_state(struct xfrm_state *x, struct xfrm_usersa_info *
276 x->props.flags = p->flags; 271 x->props.flags = p->flags;
277} 272}
278 273
274/*
275 * someday when pfkey also has support, we could have the code
276 * somehow made shareable and move it to xfrm_state.c - JHS
277 *
278*/
279static int xfrm_update_ae_params(struct xfrm_state *x, struct rtattr **xfrma)
280{
281 int err = - EINVAL;
282 struct rtattr *rp = xfrma[XFRMA_REPLAY_VAL-1];
283 struct rtattr *lt = xfrma[XFRMA_LTIME_VAL-1];
284 struct rtattr *et = xfrma[XFRMA_ETIMER_THRESH-1];
285 struct rtattr *rt = xfrma[XFRMA_REPLAY_THRESH-1];
286
287 if (rp) {
288 struct xfrm_replay_state *replay;
289 if (RTA_PAYLOAD(rp) < sizeof(*replay))
290 goto error;
291 replay = RTA_DATA(rp);
292 memcpy(&x->replay, replay, sizeof(*replay));
293 memcpy(&x->preplay, replay, sizeof(*replay));
294 }
295
296 if (lt) {
297 struct xfrm_lifetime_cur *ltime;
298 if (RTA_PAYLOAD(lt) < sizeof(*ltime))
299 goto error;
300 ltime = RTA_DATA(lt);
301 x->curlft.bytes = ltime->bytes;
302 x->curlft.packets = ltime->packets;
303 x->curlft.add_time = ltime->add_time;
304 x->curlft.use_time = ltime->use_time;
305 }
306
307 if (et) {
308 if (RTA_PAYLOAD(et) < sizeof(u32))
309 goto error;
310 x->replay_maxage = *(u32*)RTA_DATA(et);
311 }
312
313 if (rt) {
314 if (RTA_PAYLOAD(rt) < sizeof(u32))
315 goto error;
316 x->replay_maxdiff = *(u32*)RTA_DATA(rt);
317 }
318
319 return 0;
320error:
321 return err;
322}
323
279static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p, 324static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p,
280 struct rtattr **xfrma, 325 struct rtattr **xfrma,
281 int *errp) 326 int *errp)
@@ -311,6 +356,18 @@ static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p,
311 goto error; 356 goto error;
312 357
313 x->km.seq = p->seq; 358 x->km.seq = p->seq;
359 x->replay_maxdiff = sysctl_xfrm_aevent_rseqth;
360 /* sysctl_xfrm_aevent_etime is in 100ms units */
361 x->replay_maxage = (sysctl_xfrm_aevent_etime*HZ)/XFRM_AE_ETH_M;
362 x->preplay.bitmap = 0;
363 x->preplay.seq = x->replay.seq+x->replay_maxdiff;
364 x->preplay.oseq = x->replay.oseq +x->replay_maxdiff;
365
366 /* override default values from above */
367
368 err = xfrm_update_ae_params(x, (struct rtattr **)xfrma);
369 if (err < 0)
370 goto error;
314 371
315 return x; 372 return x;
316 373
@@ -1025,9 +1082,142 @@ static int xfrm_flush_sa(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma
1025 return 0; 1082 return 0;
1026} 1083}
1027 1084
1028static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma) 1085
1086static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, struct km_event *c)
1087{
1088 struct xfrm_aevent_id *id;
1089 struct nlmsghdr *nlh;
1090 struct xfrm_lifetime_cur ltime;
1091 unsigned char *b = skb->tail;
1092
1093 nlh = NLMSG_PUT(skb, c->pid, c->seq, XFRM_MSG_NEWAE, sizeof(*id));
1094 id = NLMSG_DATA(nlh);
1095 nlh->nlmsg_flags = 0;
1096
1097 id->sa_id.daddr = x->id.daddr;
1098 id->sa_id.spi = x->id.spi;
1099 id->sa_id.family = x->props.family;
1100 id->sa_id.proto = x->id.proto;
1101 id->flags = c->data.aevent;
1102
1103 RTA_PUT(skb, XFRMA_REPLAY_VAL, sizeof(x->replay), &x->replay);
1104
1105 ltime.bytes = x->curlft.bytes;
1106 ltime.packets = x->curlft.packets;
1107 ltime.add_time = x->curlft.add_time;
1108 ltime.use_time = x->curlft.use_time;
1109
1110 RTA_PUT(skb, XFRMA_LTIME_VAL, sizeof(struct xfrm_lifetime_cur), &ltime);
1111
1112 if (id->flags&XFRM_AE_RTHR) {
1113 RTA_PUT(skb,XFRMA_REPLAY_THRESH,sizeof(u32),&x->replay_maxdiff);
1114 }
1115
1116 if (id->flags&XFRM_AE_ETHR) {
1117 u32 etimer = x->replay_maxage*10/HZ;
1118 RTA_PUT(skb,XFRMA_ETIMER_THRESH,sizeof(u32),&etimer);
1119 }
1120
1121 nlh->nlmsg_len = skb->tail - b;
1122 return skb->len;
1123
1124rtattr_failure:
1125nlmsg_failure:
1126 skb_trim(skb, b - skb->data);
1127 return -1;
1128}
1129
1130static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma)
1131{
1132 struct xfrm_state *x;
1133 struct sk_buff *r_skb;
1134 int err;
1135 struct km_event c;
1136 struct xfrm_aevent_id *p = NLMSG_DATA(nlh);
1137 int len = NLMSG_LENGTH(sizeof(struct xfrm_aevent_id));
1138 struct xfrm_usersa_id *id = &p->sa_id;
1139
1140 len += RTA_SPACE(sizeof(struct xfrm_replay_state));
1141 len += RTA_SPACE(sizeof(struct xfrm_lifetime_cur));
1142
1143 if (p->flags&XFRM_AE_RTHR)
1144 len+=RTA_SPACE(sizeof(u32));
1145
1146 if (p->flags&XFRM_AE_ETHR)
1147 len+=RTA_SPACE(sizeof(u32));
1148
1149 r_skb = alloc_skb(len, GFP_ATOMIC);
1150 if (r_skb == NULL)
1151 return -ENOMEM;
1152
1153 x = xfrm_state_lookup(&id->daddr, id->spi, id->proto, id->family);
1154 if (x == NULL) {
1155 kfree(r_skb);
1156 return -ESRCH;
1157 }
1158
1159 /*
1160 * XXX: is this lock really needed - none of the other
1161 * gets lock (the concern is things getting updated
1162 * while we are still reading) - jhs
1163 */
1164 spin_lock_bh(&x->lock);
1165 c.data.aevent = p->flags;
1166 c.seq = nlh->nlmsg_seq;
1167 c.pid = nlh->nlmsg_pid;
1168
1169 if (build_aevent(r_skb, x, &c) < 0)
1170 BUG();
1171 err = netlink_unicast(xfrm_nl, r_skb,
1172 NETLINK_CB(skb).pid, MSG_DONTWAIT);
1173 spin_unlock_bh(&x->lock);
1174 xfrm_state_put(x);
1175 return err;
1176}
1177
1178static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma)
1029{ 1179{
1180 struct xfrm_state *x;
1030 struct km_event c; 1181 struct km_event c;
1182 int err = - EINVAL;
1183 struct xfrm_aevent_id *p = NLMSG_DATA(nlh);
1184 struct rtattr *rp = xfrma[XFRMA_REPLAY_VAL-1];
1185 struct rtattr *lt = xfrma[XFRMA_LTIME_VAL-1];
1186
1187 if (!lt && !rp)
1188 return err;
1189
1190 /* pedantic mode - thou shalt sayeth replaceth */
1191 if (!(nlh->nlmsg_flags&NLM_F_REPLACE))
1192 return err;
1193
1194 x = xfrm_state_lookup(&p->sa_id.daddr, p->sa_id.spi, p->sa_id.proto, p->sa_id.family);
1195 if (x == NULL)
1196 return -ESRCH;
1197
1198 if (x->km.state != XFRM_STATE_VALID)
1199 goto out;
1200
1201 spin_lock_bh(&x->lock);
1202 err = xfrm_update_ae_params(x,(struct rtattr **)xfrma);
1203 spin_unlock_bh(&x->lock);
1204 if (err < 0)
1205 goto out;
1206
1207 c.event = nlh->nlmsg_type;
1208 c.seq = nlh->nlmsg_seq;
1209 c.pid = nlh->nlmsg_pid;
1210 c.data.aevent = XFRM_AE_CU;
1211 km_state_notify(x, &c);
1212 err = 0;
1213out:
1214 xfrm_state_put(x);
1215 return err;
1216}
1217
1218static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma)
1219{
1220struct km_event c;
1031 1221
1032 xfrm_policy_flush(); 1222 xfrm_policy_flush();
1033 c.event = nlh->nlmsg_type; 1223 c.event = nlh->nlmsg_type;
@@ -1037,6 +1227,139 @@ static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh, void **x
1037 return 0; 1227 return 0;
1038} 1228}
1039 1229
1230static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma)
1231{
1232 struct xfrm_policy *xp;
1233 struct xfrm_user_polexpire *up = NLMSG_DATA(nlh);
1234 struct xfrm_userpolicy_info *p = &up->pol;
1235 int err = -ENOENT;
1236
1237 if (p->index)
1238 xp = xfrm_policy_byid(p->dir, p->index, 0);
1239 else {
1240 struct rtattr **rtattrs = (struct rtattr **)xfrma;
1241 struct rtattr *rt = rtattrs[XFRMA_SEC_CTX-1];
1242 struct xfrm_policy tmp;
1243
1244 err = verify_sec_ctx_len(rtattrs);
1245 if (err)
1246 return err;
1247
1248 memset(&tmp, 0, sizeof(struct xfrm_policy));
1249 if (rt) {
1250 struct xfrm_user_sec_ctx *uctx = RTA_DATA(rt);
1251
1252 if ((err = security_xfrm_policy_alloc(&tmp, uctx)))
1253 return err;
1254 }
1255 xp = xfrm_policy_bysel_ctx(p->dir, &p->sel, tmp.security, 0);
1256 security_xfrm_policy_free(&tmp);
1257 }
1258
1259 if (xp == NULL)
1260 return err;
1261 read_lock(&xp->lock);
1262 if (xp->dead) {
1263 read_unlock(&xp->lock);
1264 goto out;
1265 }
1266
1267 read_unlock(&xp->lock);
1268 err = 0;
1269 if (up->hard) {
1270 xfrm_policy_delete(xp, p->dir);
1271 } else {
1272 // reset the timers here?
1273 printk("Dont know what to do with soft policy expire\n");
1274 }
1275 km_policy_expired(xp, p->dir, up->hard, current->pid);
1276
1277out:
1278 xfrm_pol_put(xp);
1279 return err;
1280}
1281
1282static int xfrm_add_sa_expire(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma)
1283{
1284 struct xfrm_state *x;
1285 int err;
1286 struct xfrm_user_expire *ue = NLMSG_DATA(nlh);
1287 struct xfrm_usersa_info *p = &ue->state;
1288
1289 x = xfrm_state_lookup(&p->id.daddr, p->id.spi, p->id.proto, p->family);
1290 err = -ENOENT;
1291
1292 if (x == NULL)
1293 return err;
1294
1295 err = -EINVAL;
1296
1297 spin_lock_bh(&x->lock);
1298 if (x->km.state != XFRM_STATE_VALID)
1299 goto out;
1300 km_state_expired(x, ue->hard, current->pid);
1301
1302 if (ue->hard)
1303 __xfrm_state_delete(x);
1304out:
1305 spin_unlock_bh(&x->lock);
1306 xfrm_state_put(x);
1307 return err;
1308}
1309
1310static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma)
1311{
1312 struct xfrm_policy *xp;
1313 struct xfrm_user_tmpl *ut;
1314 int i;
1315 struct rtattr *rt = xfrma[XFRMA_TMPL-1];
1316
1317 struct xfrm_user_acquire *ua = NLMSG_DATA(nlh);
1318 struct xfrm_state *x = xfrm_state_alloc();
1319 int err = -ENOMEM;
1320
1321 if (!x)
1322 return err;
1323
1324 err = verify_newpolicy_info(&ua->policy);
1325 if (err) {
1326 printk("BAD policy passed\n");
1327 kfree(x);
1328 return err;
1329 }
1330
1331 /* build an XP */
1332 xp = xfrm_policy_construct(&ua->policy, (struct rtattr **) xfrma, &err); if (!xp) {
1333 kfree(x);
1334 return err;
1335 }
1336
1337 memcpy(&x->id, &ua->id, sizeof(ua->id));
1338 memcpy(&x->props.saddr, &ua->saddr, sizeof(ua->saddr));
1339 memcpy(&x->sel, &ua->sel, sizeof(ua->sel));
1340
1341 ut = RTA_DATA(rt);
1342 /* extract the templates and for each call km_key */
1343 for (i = 0; i < xp->xfrm_nr; i++, ut++) {
1344 struct xfrm_tmpl *t = &xp->xfrm_vec[i];
1345 memcpy(&x->id, &t->id, sizeof(x->id));
1346 x->props.mode = t->mode;
1347 x->props.reqid = t->reqid;
1348 x->props.family = ut->family;
1349 t->aalgos = ua->aalgos;
1350 t->ealgos = ua->ealgos;
1351 t->calgos = ua->calgos;
1352 err = km_query(x, t, xp);
1353
1354 }
1355
1356 kfree(x);
1357 kfree(xp);
1358
1359 return 0;
1360}
1361
1362
1040#define XMSGSIZE(type) NLMSG_LENGTH(sizeof(struct type)) 1363#define XMSGSIZE(type) NLMSG_LENGTH(sizeof(struct type))
1041 1364
1042static const int xfrm_msg_min[XFRM_NR_MSGTYPES] = { 1365static const int xfrm_msg_min[XFRM_NR_MSGTYPES] = {
@@ -1054,6 +1377,8 @@ static const int xfrm_msg_min[XFRM_NR_MSGTYPES] = {
1054 [XFRM_MSG_POLEXPIRE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_polexpire), 1377 [XFRM_MSG_POLEXPIRE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_polexpire),
1055 [XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_flush), 1378 [XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_flush),
1056 [XFRM_MSG_FLUSHPOLICY - XFRM_MSG_BASE] = NLMSG_LENGTH(0), 1379 [XFRM_MSG_FLUSHPOLICY - XFRM_MSG_BASE] = NLMSG_LENGTH(0),
1380 [XFRM_MSG_NEWAE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_aevent_id),
1381 [XFRM_MSG_GETAE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_aevent_id),
1057}; 1382};
1058 1383
1059#undef XMSGSIZE 1384#undef XMSGSIZE
@@ -1071,10 +1396,15 @@ static struct xfrm_link {
1071 [XFRM_MSG_GETPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_get_policy, 1396 [XFRM_MSG_GETPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_get_policy,
1072 .dump = xfrm_dump_policy }, 1397 .dump = xfrm_dump_policy },
1073 [XFRM_MSG_ALLOCSPI - XFRM_MSG_BASE] = { .doit = xfrm_alloc_userspi }, 1398 [XFRM_MSG_ALLOCSPI - XFRM_MSG_BASE] = { .doit = xfrm_alloc_userspi },
1399 [XFRM_MSG_ACQUIRE - XFRM_MSG_BASE] = { .doit = xfrm_add_acquire },
1400 [XFRM_MSG_EXPIRE - XFRM_MSG_BASE] = { .doit = xfrm_add_sa_expire },
1074 [XFRM_MSG_UPDPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_add_policy }, 1401 [XFRM_MSG_UPDPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_add_policy },
1075 [XFRM_MSG_UPDSA - XFRM_MSG_BASE] = { .doit = xfrm_add_sa }, 1402 [XFRM_MSG_UPDSA - XFRM_MSG_BASE] = { .doit = xfrm_add_sa },
1403 [XFRM_MSG_POLEXPIRE - XFRM_MSG_BASE] = { .doit = xfrm_add_pol_expire},
1076 [XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = { .doit = xfrm_flush_sa }, 1404 [XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = { .doit = xfrm_flush_sa },
1077 [XFRM_MSG_FLUSHPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_flush_policy }, 1405 [XFRM_MSG_FLUSHPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_flush_policy },
1406 [XFRM_MSG_NEWAE - XFRM_MSG_BASE] = { .doit = xfrm_new_ae },
1407 [XFRM_MSG_GETAE - XFRM_MSG_BASE] = { .doit = xfrm_get_ae },
1078}; 1408};
1079 1409
1080static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp) 1410static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp)
@@ -1156,26 +1486,26 @@ static void xfrm_netlink_rcv(struct sock *sk, int len)
1156 unsigned int qlen = 0; 1486 unsigned int qlen = 0;
1157 1487
1158 do { 1488 do {
1159 down(&xfrm_cfg_sem); 1489 mutex_lock(&xfrm_cfg_mutex);
1160 netlink_run_queue(sk, &qlen, &xfrm_user_rcv_msg); 1490 netlink_run_queue(sk, &qlen, &xfrm_user_rcv_msg);
1161 up(&xfrm_cfg_sem); 1491 mutex_unlock(&xfrm_cfg_mutex);
1162 1492
1163 } while (qlen); 1493 } while (qlen);
1164} 1494}
1165 1495
1166static int build_expire(struct sk_buff *skb, struct xfrm_state *x, int hard) 1496static int build_expire(struct sk_buff *skb, struct xfrm_state *x, struct km_event *c)
1167{ 1497{
1168 struct xfrm_user_expire *ue; 1498 struct xfrm_user_expire *ue;
1169 struct nlmsghdr *nlh; 1499 struct nlmsghdr *nlh;
1170 unsigned char *b = skb->tail; 1500 unsigned char *b = skb->tail;
1171 1501
1172 nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_EXPIRE, 1502 nlh = NLMSG_PUT(skb, c->pid, 0, XFRM_MSG_EXPIRE,
1173 sizeof(*ue)); 1503 sizeof(*ue));
1174 ue = NLMSG_DATA(nlh); 1504 ue = NLMSG_DATA(nlh);
1175 nlh->nlmsg_flags = 0; 1505 nlh->nlmsg_flags = 0;
1176 1506
1177 copy_to_user_state(x, &ue->state); 1507 copy_to_user_state(x, &ue->state);
1178 ue->hard = (hard != 0) ? 1 : 0; 1508 ue->hard = (c->data.hard != 0) ? 1 : 0;
1179 1509
1180 nlh->nlmsg_len = skb->tail - b; 1510 nlh->nlmsg_len = skb->tail - b;
1181 return skb->len; 1511 return skb->len;
@@ -1194,13 +1524,31 @@ static int xfrm_exp_state_notify(struct xfrm_state *x, struct km_event *c)
1194 if (skb == NULL) 1524 if (skb == NULL)
1195 return -ENOMEM; 1525 return -ENOMEM;
1196 1526
1197 if (build_expire(skb, x, c->data.hard) < 0) 1527 if (build_expire(skb, x, c) < 0)
1198 BUG(); 1528 BUG();
1199 1529
1200 NETLINK_CB(skb).dst_group = XFRMNLGRP_EXPIRE; 1530 NETLINK_CB(skb).dst_group = XFRMNLGRP_EXPIRE;
1201 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_EXPIRE, GFP_ATOMIC); 1531 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_EXPIRE, GFP_ATOMIC);
1202} 1532}
1203 1533
1534static int xfrm_aevent_state_notify(struct xfrm_state *x, struct km_event *c)
1535{
1536 struct sk_buff *skb;
1537 int len = NLMSG_LENGTH(sizeof(struct xfrm_aevent_id));
1538
1539 len += RTA_SPACE(sizeof(struct xfrm_replay_state));
1540 len += RTA_SPACE(sizeof(struct xfrm_lifetime_cur));
1541 skb = alloc_skb(len, GFP_ATOMIC);
1542 if (skb == NULL)
1543 return -ENOMEM;
1544
1545 if (build_aevent(skb, x, c) < 0)
1546 BUG();
1547
1548 NETLINK_CB(skb).dst_group = XFRMNLGRP_AEVENTS;
1549 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_AEVENTS, GFP_ATOMIC);
1550}
1551
1204static int xfrm_notify_sa_flush(struct km_event *c) 1552static int xfrm_notify_sa_flush(struct km_event *c)
1205{ 1553{
1206 struct xfrm_usersa_flush *p; 1554 struct xfrm_usersa_flush *p;
@@ -1313,6 +1661,8 @@ static int xfrm_send_state_notify(struct xfrm_state *x, struct km_event *c)
1313 switch (c->event) { 1661 switch (c->event) {
1314 case XFRM_MSG_EXPIRE: 1662 case XFRM_MSG_EXPIRE:
1315 return xfrm_exp_state_notify(x, c); 1663 return xfrm_exp_state_notify(x, c);
1664 case XFRM_MSG_NEWAE:
1665 return xfrm_aevent_state_notify(x, c);
1316 case XFRM_MSG_DELSA: 1666 case XFRM_MSG_DELSA:
1317 case XFRM_MSG_UPDSA: 1667 case XFRM_MSG_UPDSA:
1318 case XFRM_MSG_NEWSA: 1668 case XFRM_MSG_NEWSA:
@@ -1443,13 +1793,14 @@ static struct xfrm_policy *xfrm_compile_policy(u16 family, int opt,
1443} 1793}
1444 1794
1445static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp, 1795static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp,
1446 int dir, int hard) 1796 int dir, struct km_event *c)
1447{ 1797{
1448 struct xfrm_user_polexpire *upe; 1798 struct xfrm_user_polexpire *upe;
1449 struct nlmsghdr *nlh; 1799 struct nlmsghdr *nlh;
1800 int hard = c->data.hard;
1450 unsigned char *b = skb->tail; 1801 unsigned char *b = skb->tail;
1451 1802
1452 nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_POLEXPIRE, sizeof(*upe)); 1803 nlh = NLMSG_PUT(skb, c->pid, 0, XFRM_MSG_POLEXPIRE, sizeof(*upe));
1453 upe = NLMSG_DATA(nlh); 1804 upe = NLMSG_DATA(nlh);
1454 nlh->nlmsg_flags = 0; 1805 nlh->nlmsg_flags = 0;
1455 1806
@@ -1480,7 +1831,7 @@ static int xfrm_exp_policy_notify(struct xfrm_policy *xp, int dir, struct km_eve
1480 if (skb == NULL) 1831 if (skb == NULL)
1481 return -ENOMEM; 1832 return -ENOMEM;
1482 1833
1483 if (build_polexpire(skb, xp, dir, c->data.hard) < 0) 1834 if (build_polexpire(skb, xp, dir, c) < 0)
1484 BUG(); 1835 BUG();
1485 1836
1486 NETLINK_CB(skb).dst_group = XFRMNLGRP_EXPIRE; 1837 NETLINK_CB(skb).dst_group = XFRMNLGRP_EXPIRE;
@@ -1596,12 +1947,15 @@ static struct xfrm_mgr netlink_mgr = {
1596 1947
1597static int __init xfrm_user_init(void) 1948static int __init xfrm_user_init(void)
1598{ 1949{
1950 struct sock *nlsk;
1951
1599 printk(KERN_INFO "Initializing IPsec netlink socket\n"); 1952 printk(KERN_INFO "Initializing IPsec netlink socket\n");
1600 1953
1601 xfrm_nl = netlink_kernel_create(NETLINK_XFRM, XFRMNLGRP_MAX, 1954 nlsk = netlink_kernel_create(NETLINK_XFRM, XFRMNLGRP_MAX,
1602 xfrm_netlink_rcv, THIS_MODULE); 1955 xfrm_netlink_rcv, THIS_MODULE);
1603 if (xfrm_nl == NULL) 1956 if (nlsk == NULL)
1604 return -ENOMEM; 1957 return -ENOMEM;
1958 rcu_assign_pointer(xfrm_nl, nlsk);
1605 1959
1606 xfrm_register_km(&netlink_mgr); 1960 xfrm_register_km(&netlink_mgr);
1607 1961
@@ -1610,11 +1964,16 @@ static int __init xfrm_user_init(void)
1610 1964
1611static void __exit xfrm_user_exit(void) 1965static void __exit xfrm_user_exit(void)
1612{ 1966{
1967 struct sock *nlsk = xfrm_nl;
1968
1613 xfrm_unregister_km(&netlink_mgr); 1969 xfrm_unregister_km(&netlink_mgr);
1614 sock_release(xfrm_nl->sk_socket); 1970 rcu_assign_pointer(xfrm_nl, NULL);
1971 synchronize_rcu();
1972 sock_release(nlsk->sk_socket);
1615} 1973}
1616 1974
1617module_init(xfrm_user_init); 1975module_init(xfrm_user_init);
1618module_exit(xfrm_user_exit); 1976module_exit(xfrm_user_exit);
1619MODULE_LICENSE("GPL"); 1977MODULE_LICENSE("GPL");
1620MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_XFRM); 1978MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_XFRM);
1979
diff --git a/scripts/genksyms/keywords.c_shipped b/scripts/genksyms/keywords.c_shipped
index ee4647805c58..d8153f572e40 100644
--- a/scripts/genksyms/keywords.c_shipped
+++ b/scripts/genksyms/keywords.c_shipped
@@ -52,9 +52,9 @@ is_reserved_hash (register const char *str, register unsigned int len)
52 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 52 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
53 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 53 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
54 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 54 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
55 71, 71, 71, 71, 71, 71, 71, 71, 71, 15, 55 71, 71, 71, 71, 71, 71, 71, 71, 71, 0,
56 71, 71, 71, 71, 71, 71, 15, 71, 71, 71, 56 71, 71, 71, 71, 71, 71, 35, 71, 71, 71,
57 10, 71, 71, 71, 71, 71, 71, 71, 71, 71, 57 5, 71, 71, 71, 71, 71, 71, 71, 71, 71,
58 71, 71, 71, 71, 71, 0, 71, 0, 71, 5, 58 71, 71, 71, 71, 71, 0, 71, 0, 71, 5,
59 5, 0, 10, 20, 71, 25, 71, 71, 20, 0, 59 5, 0, 10, 20, 71, 25, 71, 71, 20, 0,
60 20, 30, 25, 71, 10, 5, 0, 20, 15, 71, 60 20, 30, 25, 71, 10, 5, 0, 20, 15, 71,
@@ -84,9 +84,9 @@ is_reserved_word (register const char *str, register unsigned int len)
84{ 84{
85 enum 85 enum
86 { 86 {
87 TOTAL_KEYWORDS = 41, 87 TOTAL_KEYWORDS = 42,
88 MIN_WORD_LENGTH = 3, 88 MIN_WORD_LENGTH = 3,
89 MAX_WORD_LENGTH = 17, 89 MAX_WORD_LENGTH = 24,
90 MIN_HASH_VALUE = 3, 90 MIN_HASH_VALUE = 3,
91 MAX_HASH_VALUE = 70 91 MAX_HASH_VALUE = 70
92 }; 92 };
@@ -94,104 +94,105 @@ is_reserved_word (register const char *str, register unsigned int len)
94 static const struct resword wordlist[] = 94 static const struct resword wordlist[] =
95 { 95 {
96 {""}, {""}, {""}, 96 {""}, {""}, {""},
97#line 24 "scripts/genksyms/keywords.gperf" 97#line 25 "scripts/genksyms/keywords.gperf"
98 {"asm", ASM_KEYW}, 98 {"asm", ASM_KEYW},
99 {""}, 99 {""},
100#line 7 "scripts/genksyms/keywords.gperf" 100#line 8 "scripts/genksyms/keywords.gperf"
101 {"__asm", ASM_KEYW}, 101 {"__asm", ASM_KEYW},
102 {""}, 102 {""},
103#line 8 "scripts/genksyms/keywords.gperf" 103#line 9 "scripts/genksyms/keywords.gperf"
104 {"__asm__", ASM_KEYW}, 104 {"__asm__", ASM_KEYW},
105 {""}, 105 {""},
106#line 21 "scripts/genksyms/keywords.gperf" 106#line 22 "scripts/genksyms/keywords.gperf"
107 {"_restrict", RESTRICT_KEYW}, 107 {"_restrict", RESTRICT_KEYW},
108#line 50 "scripts/genksyms/keywords.gperf" 108#line 51 "scripts/genksyms/keywords.gperf"
109 {"__typeof__", TYPEOF_KEYW}, 109 {"__typeof__", TYPEOF_KEYW},
110#line 9 "scripts/genksyms/keywords.gperf" 110#line 10 "scripts/genksyms/keywords.gperf"
111 {"__attribute", ATTRIBUTE_KEYW}, 111 {"__attribute", ATTRIBUTE_KEYW},
112#line 11 "scripts/genksyms/keywords.gperf" 112#line 12 "scripts/genksyms/keywords.gperf"
113 {"__const", CONST_KEYW}, 113 {"__const", CONST_KEYW},
114#line 10 "scripts/genksyms/keywords.gperf" 114#line 11 "scripts/genksyms/keywords.gperf"
115 {"__attribute__", ATTRIBUTE_KEYW}, 115 {"__attribute__", ATTRIBUTE_KEYW},
116#line 12 "scripts/genksyms/keywords.gperf" 116#line 13 "scripts/genksyms/keywords.gperf"
117 {"__const__", CONST_KEYW}, 117 {"__const__", CONST_KEYW},
118#line 16 "scripts/genksyms/keywords.gperf" 118#line 17 "scripts/genksyms/keywords.gperf"
119 {"__signed__", SIGNED_KEYW}, 119 {"__signed__", SIGNED_KEYW},
120#line 42 "scripts/genksyms/keywords.gperf" 120#line 43 "scripts/genksyms/keywords.gperf"
121 {"static", STATIC_KEYW}, 121 {"static", STATIC_KEYW},
122 {""}, 122 {""},
123#line 15 "scripts/genksyms/keywords.gperf" 123#line 16 "scripts/genksyms/keywords.gperf"
124 {"__signed", SIGNED_KEYW}, 124 {"__signed", SIGNED_KEYW},
125#line 30 "scripts/genksyms/keywords.gperf" 125#line 31 "scripts/genksyms/keywords.gperf"
126 {"char", CHAR_KEYW}, 126 {"char", CHAR_KEYW},
127 {""}, 127 {""},
128#line 43 "scripts/genksyms/keywords.gperf" 128#line 44 "scripts/genksyms/keywords.gperf"
129 {"struct", STRUCT_KEYW}, 129 {"struct", STRUCT_KEYW},
130#line 22 "scripts/genksyms/keywords.gperf"
131 {"__restrict__", RESTRICT_KEYW},
132#line 23 "scripts/genksyms/keywords.gperf" 130#line 23 "scripts/genksyms/keywords.gperf"
131 {"__restrict__", RESTRICT_KEYW},
132#line 24 "scripts/genksyms/keywords.gperf"
133 {"restrict", RESTRICT_KEYW}, 133 {"restrict", RESTRICT_KEYW},
134#line 33 "scripts/genksyms/keywords.gperf" 134#line 34 "scripts/genksyms/keywords.gperf"
135 {"enum", ENUM_KEYW}, 135 {"enum", ENUM_KEYW},
136#line 17 "scripts/genksyms/keywords.gperf" 136#line 18 "scripts/genksyms/keywords.gperf"
137 {"__volatile", VOLATILE_KEYW}, 137 {"__volatile", VOLATILE_KEYW},
138#line 34 "scripts/genksyms/keywords.gperf" 138#line 35 "scripts/genksyms/keywords.gperf"
139 {"extern", EXTERN_KEYW}, 139 {"extern", EXTERN_KEYW},
140#line 18 "scripts/genksyms/keywords.gperf" 140#line 19 "scripts/genksyms/keywords.gperf"
141 {"__volatile__", VOLATILE_KEYW}, 141 {"__volatile__", VOLATILE_KEYW},
142#line 37 "scripts/genksyms/keywords.gperf" 142#line 38 "scripts/genksyms/keywords.gperf"
143 {"int", INT_KEYW}, 143 {"int", INT_KEYW},
144 {""}, 144#line 7 "scripts/genksyms/keywords.gperf"
145#line 31 "scripts/genksyms/keywords.gperf" 145 {"EXPORT_SYMBOL_GPL_FUTURE", EXPORT_SYMBOL_KEYW},
146 {"const", CONST_KEYW},
147#line 32 "scripts/genksyms/keywords.gperf" 146#line 32 "scripts/genksyms/keywords.gperf"
147 {"const", CONST_KEYW},
148#line 33 "scripts/genksyms/keywords.gperf"
148 {"double", DOUBLE_KEYW}, 149 {"double", DOUBLE_KEYW},
149 {""}, 150 {""},
150#line 13 "scripts/genksyms/keywords.gperf" 151#line 14 "scripts/genksyms/keywords.gperf"
151 {"__inline", INLINE_KEYW}, 152 {"__inline", INLINE_KEYW},
152#line 29 "scripts/genksyms/keywords.gperf" 153#line 30 "scripts/genksyms/keywords.gperf"
153 {"auto", AUTO_KEYW}, 154 {"auto", AUTO_KEYW},
154#line 14 "scripts/genksyms/keywords.gperf" 155#line 15 "scripts/genksyms/keywords.gperf"
155 {"__inline__", INLINE_KEYW}, 156 {"__inline__", INLINE_KEYW},
156#line 41 "scripts/genksyms/keywords.gperf" 157#line 42 "scripts/genksyms/keywords.gperf"
157 {"signed", SIGNED_KEYW}, 158 {"signed", SIGNED_KEYW},
158 {""}, 159 {""},
159#line 46 "scripts/genksyms/keywords.gperf" 160#line 47 "scripts/genksyms/keywords.gperf"
160 {"unsigned", UNSIGNED_KEYW}, 161 {"unsigned", UNSIGNED_KEYW},
161 {""}, 162 {""},
162#line 40 "scripts/genksyms/keywords.gperf" 163#line 41 "scripts/genksyms/keywords.gperf"
163 {"short", SHORT_KEYW}, 164 {"short", SHORT_KEYW},
164#line 49 "scripts/genksyms/keywords.gperf" 165#line 50 "scripts/genksyms/keywords.gperf"
165 {"typeof", TYPEOF_KEYW}, 166 {"typeof", TYPEOF_KEYW},
166#line 44 "scripts/genksyms/keywords.gperf" 167#line 45 "scripts/genksyms/keywords.gperf"
167 {"typedef", TYPEDEF_KEYW}, 168 {"typedef", TYPEDEF_KEYW},
168#line 48 "scripts/genksyms/keywords.gperf" 169#line 49 "scripts/genksyms/keywords.gperf"
169 {"volatile", VOLATILE_KEYW}, 170 {"volatile", VOLATILE_KEYW},
170 {""}, 171 {""},
171#line 35 "scripts/genksyms/keywords.gperf" 172#line 36 "scripts/genksyms/keywords.gperf"
172 {"float", FLOAT_KEYW}, 173 {"float", FLOAT_KEYW},
173 {""}, {""}, 174 {""}, {""},
174#line 39 "scripts/genksyms/keywords.gperf" 175#line 40 "scripts/genksyms/keywords.gperf"
175 {"register", REGISTER_KEYW}, 176 {"register", REGISTER_KEYW},
176#line 47 "scripts/genksyms/keywords.gperf" 177#line 48 "scripts/genksyms/keywords.gperf"
177 {"void", VOID_KEYW}, 178 {"void", VOID_KEYW},
178 {""}, 179 {""},
179#line 36 "scripts/genksyms/keywords.gperf" 180#line 37 "scripts/genksyms/keywords.gperf"
180 {"inline", INLINE_KEYW}, 181 {"inline", INLINE_KEYW},
181 {""}, 182 {""},
182#line 5 "scripts/genksyms/keywords.gperf" 183#line 5 "scripts/genksyms/keywords.gperf"
183 {"EXPORT_SYMBOL", EXPORT_SYMBOL_KEYW}, 184 {"EXPORT_SYMBOL", EXPORT_SYMBOL_KEYW},
184 {""}, 185 {""},
185#line 20 "scripts/genksyms/keywords.gperf" 186#line 21 "scripts/genksyms/keywords.gperf"
186 {"_Bool", BOOL_KEYW}, 187 {"_Bool", BOOL_KEYW},
187 {""}, 188 {""},
188#line 6 "scripts/genksyms/keywords.gperf" 189#line 6 "scripts/genksyms/keywords.gperf"
189 {"EXPORT_SYMBOL_GPL", EXPORT_SYMBOL_KEYW}, 190 {"EXPORT_SYMBOL_GPL", EXPORT_SYMBOL_KEYW},
190 {""}, {""}, {""}, {""}, {""}, {""}, 191 {""}, {""}, {""}, {""}, {""}, {""},
191#line 38 "scripts/genksyms/keywords.gperf" 192#line 39 "scripts/genksyms/keywords.gperf"
192 {"long", LONG_KEYW}, 193 {"long", LONG_KEYW},
193 {""}, {""}, {""}, {""}, {""}, 194 {""}, {""}, {""}, {""}, {""},
194#line 45 "scripts/genksyms/keywords.gperf" 195#line 46 "scripts/genksyms/keywords.gperf"
195 {"union", UNION_KEYW} 196 {"union", UNION_KEYW}
196 }; 197 };
197 198
diff --git a/scripts/genksyms/keywords.gperf b/scripts/genksyms/keywords.gperf
index b6bec765996e..c75e0c8d8f0c 100644
--- a/scripts/genksyms/keywords.gperf
+++ b/scripts/genksyms/keywords.gperf
@@ -4,6 +4,7 @@ struct resword { const char *name; int token; }
4%% 4%%
5EXPORT_SYMBOL, EXPORT_SYMBOL_KEYW 5EXPORT_SYMBOL, EXPORT_SYMBOL_KEYW
6EXPORT_SYMBOL_GPL, EXPORT_SYMBOL_KEYW 6EXPORT_SYMBOL_GPL, EXPORT_SYMBOL_KEYW
7EXPORT_SYMBOL_GPL_FUTURE, EXPORT_SYMBOL_KEYW
7__asm, ASM_KEYW 8__asm, ASM_KEYW
8__asm__, ASM_KEYW 9__asm__, ASM_KEYW
9__attribute, ATTRIBUTE_KEYW 10__attribute, ATTRIBUTE_KEYW
diff --git a/security/dummy.c b/security/dummy.c
index f1a5bd98bf10..a678f094b72d 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -763,8 +763,14 @@ static int dummy_socket_sock_rcv_skb (struct sock *sk, struct sk_buff *skb)
763 return 0; 763 return 0;
764} 764}
765 765
766static int dummy_socket_getpeersec(struct socket *sock, char __user *optval, 766static int dummy_socket_getpeersec_stream(struct socket *sock, char __user *optval,
767 int __user *optlen, unsigned len) 767 int __user *optlen, unsigned len)
768{
769 return -ENOPROTOOPT;
770}
771
772static int dummy_socket_getpeersec_dgram(struct sk_buff *skb, char **secdata,
773 u32 *seclen)
768{ 774{
769 return -ENOPROTOOPT; 775 return -ENOPROTOOPT;
770} 776}
@@ -1002,7 +1008,8 @@ void security_fixup_ops (struct security_operations *ops)
1002 set_to_dummy_if_null(ops, socket_getsockopt); 1008 set_to_dummy_if_null(ops, socket_getsockopt);
1003 set_to_dummy_if_null(ops, socket_shutdown); 1009 set_to_dummy_if_null(ops, socket_shutdown);
1004 set_to_dummy_if_null(ops, socket_sock_rcv_skb); 1010 set_to_dummy_if_null(ops, socket_sock_rcv_skb);
1005 set_to_dummy_if_null(ops, socket_getpeersec); 1011 set_to_dummy_if_null(ops, socket_getpeersec_stream);
1012 set_to_dummy_if_null(ops, socket_getpeersec_dgram);
1006 set_to_dummy_if_null(ops, sk_alloc_security); 1013 set_to_dummy_if_null(ops, sk_alloc_security);
1007 set_to_dummy_if_null(ops, sk_free_security); 1014 set_to_dummy_if_null(ops, sk_free_security);
1008 set_to_dummy_if_null(ops, sk_getsid); 1015 set_to_dummy_if_null(ops, sk_getsid);
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index b65c201e9ff5..5b16196f2823 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3318,24 +3318,38 @@ out:
3318 return err; 3318 return err;
3319} 3319}
3320 3320
3321static int selinux_socket_getpeersec(struct socket *sock, char __user *optval, 3321static int selinux_socket_getpeersec_stream(struct socket *sock, char __user *optval,
3322 int __user *optlen, unsigned len) 3322 int __user *optlen, unsigned len)
3323{ 3323{
3324 int err = 0; 3324 int err = 0;
3325 char *scontext; 3325 char *scontext;
3326 u32 scontext_len; 3326 u32 scontext_len;
3327 struct sk_security_struct *ssec; 3327 struct sk_security_struct *ssec;
3328 struct inode_security_struct *isec; 3328 struct inode_security_struct *isec;
3329 u32 peer_sid = 0;
3329 3330
3330 isec = SOCK_INODE(sock)->i_security; 3331 isec = SOCK_INODE(sock)->i_security;
3331 if (isec->sclass != SECCLASS_UNIX_STREAM_SOCKET) { 3332
3333 /* if UNIX_STREAM check peer_sid, if TCP check dst for labelled sa */
3334 if (isec->sclass == SECCLASS_UNIX_STREAM_SOCKET) {
3335 ssec = sock->sk->sk_security;
3336 peer_sid = ssec->peer_sid;
3337 }
3338 else if (isec->sclass == SECCLASS_TCP_SOCKET) {
3339 peer_sid = selinux_socket_getpeer_stream(sock->sk);
3340
3341 if (peer_sid == SECSID_NULL) {
3342 err = -ENOPROTOOPT;
3343 goto out;
3344 }
3345 }
3346 else {
3332 err = -ENOPROTOOPT; 3347 err = -ENOPROTOOPT;
3333 goto out; 3348 goto out;
3334 } 3349 }
3335 3350
3336 ssec = sock->sk->sk_security; 3351 err = security_sid_to_context(peer_sid, &scontext, &scontext_len);
3337 3352
3338 err = security_sid_to_context(ssec->peer_sid, &scontext, &scontext_len);
3339 if (err) 3353 if (err)
3340 goto out; 3354 goto out;
3341 3355
@@ -3356,6 +3370,23 @@ out:
3356 return err; 3370 return err;
3357} 3371}
3358 3372
3373static int selinux_socket_getpeersec_dgram(struct sk_buff *skb, char **secdata, u32 *seclen)
3374{
3375 int err = 0;
3376 u32 peer_sid = selinux_socket_getpeer_dgram(skb);
3377
3378 if (peer_sid == SECSID_NULL)
3379 return -EINVAL;
3380
3381 err = security_sid_to_context(peer_sid, secdata, seclen);
3382 if (err)
3383 return err;
3384
3385 return 0;
3386}
3387
3388
3389
3359static int selinux_sk_alloc_security(struct sock *sk, int family, gfp_t priority) 3390static int selinux_sk_alloc_security(struct sock *sk, int family, gfp_t priority)
3360{ 3391{
3361 return sk_alloc_security(sk, family, priority); 3392 return sk_alloc_security(sk, family, priority);
@@ -4344,7 +4375,8 @@ static struct security_operations selinux_ops = {
4344 .socket_setsockopt = selinux_socket_setsockopt, 4375 .socket_setsockopt = selinux_socket_setsockopt,
4345 .socket_shutdown = selinux_socket_shutdown, 4376 .socket_shutdown = selinux_socket_shutdown,
4346 .socket_sock_rcv_skb = selinux_socket_sock_rcv_skb, 4377 .socket_sock_rcv_skb = selinux_socket_sock_rcv_skb,
4347 .socket_getpeersec = selinux_socket_getpeersec, 4378 .socket_getpeersec_stream = selinux_socket_getpeersec_stream,
4379 .socket_getpeersec_dgram = selinux_socket_getpeersec_dgram,
4348 .sk_alloc_security = selinux_sk_alloc_security, 4380 .sk_alloc_security = selinux_sk_alloc_security,
4349 .sk_free_security = selinux_sk_free_security, 4381 .sk_free_security = selinux_sk_free_security,
4350 .sk_getsid = selinux_sk_getsid_security, 4382 .sk_getsid = selinux_sk_getsid_security,
diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
index 8e87996c6dd5..c10f1fc41502 100644
--- a/security/selinux/include/xfrm.h
+++ b/security/selinux/include/xfrm.h
@@ -39,6 +39,8 @@ static inline u32 selinux_no_sk_sid(struct flowi *fl)
39#ifdef CONFIG_SECURITY_NETWORK_XFRM 39#ifdef CONFIG_SECURITY_NETWORK_XFRM
40int selinux_xfrm_sock_rcv_skb(u32 sid, struct sk_buff *skb); 40int selinux_xfrm_sock_rcv_skb(u32 sid, struct sk_buff *skb);
41int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb); 41int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb);
42u32 selinux_socket_getpeer_stream(struct sock *sk);
43u32 selinux_socket_getpeer_dgram(struct sk_buff *skb);
42#else 44#else
43static inline int selinux_xfrm_sock_rcv_skb(u32 isec_sid, struct sk_buff *skb) 45static inline int selinux_xfrm_sock_rcv_skb(u32 isec_sid, struct sk_buff *skb)
44{ 46{
@@ -49,6 +51,16 @@ static inline int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb)
49{ 51{
50 return NF_ACCEPT; 52 return NF_ACCEPT;
51} 53}
54
55static inline int selinux_socket_getpeer_stream(struct sock *sk)
56{
57 return SECSID_NULL;
58}
59
60static inline int selinux_socket_getpeer_dgram(struct sk_buff *skb)
61{
62 return SECSID_NULL;
63}
52#endif 64#endif
53 65
54#endif /* _SELINUX_XFRM_H_ */ 66#endif /* _SELINUX_XFRM_H_ */
diff --git a/security/selinux/nlmsgtab.c b/security/selinux/nlmsgtab.c
index 69b9329b2054..85e399259832 100644
--- a/security/selinux/nlmsgtab.c
+++ b/security/selinux/nlmsgtab.c
@@ -88,8 +88,15 @@ static struct nlmsg_perm nlmsg_xfrm_perms[] =
88 { XFRM_MSG_DELPOLICY, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, 88 { XFRM_MSG_DELPOLICY, NETLINK_XFRM_SOCKET__NLMSG_WRITE },
89 { XFRM_MSG_GETPOLICY, NETLINK_XFRM_SOCKET__NLMSG_READ }, 89 { XFRM_MSG_GETPOLICY, NETLINK_XFRM_SOCKET__NLMSG_READ },
90 { XFRM_MSG_ALLOCSPI, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, 90 { XFRM_MSG_ALLOCSPI, NETLINK_XFRM_SOCKET__NLMSG_WRITE },
91 { XFRM_MSG_ACQUIRE, NETLINK_XFRM_SOCKET__NLMSG_WRITE },
92 { XFRM_MSG_EXPIRE, NETLINK_XFRM_SOCKET__NLMSG_WRITE },
91 { XFRM_MSG_UPDPOLICY, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, 93 { XFRM_MSG_UPDPOLICY, NETLINK_XFRM_SOCKET__NLMSG_WRITE },
92 { XFRM_MSG_UPDSA, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, 94 { XFRM_MSG_UPDSA, NETLINK_XFRM_SOCKET__NLMSG_WRITE },
95 { XFRM_MSG_POLEXPIRE, NETLINK_XFRM_SOCKET__NLMSG_WRITE },
96 { XFRM_MSG_FLUSHSA, NETLINK_XFRM_SOCKET__NLMSG_WRITE },
97 { XFRM_MSG_FLUSHPOLICY, NETLINK_XFRM_SOCKET__NLMSG_WRITE },
98 { XFRM_MSG_NEWAE, NETLINK_XFRM_SOCKET__NLMSG_WRITE },
99 { XFRM_MSG_GETAE, NETLINK_XFRM_SOCKET__NLMSG_READ },
93}; 100};
94 101
95static struct nlmsg_perm nlmsg_audit_perms[] = 102static struct nlmsg_perm nlmsg_audit_perms[] =
diff --git a/security/selinux/xfrm.c b/security/selinux/xfrm.c
index b2af7ca496c1..dfab6c886698 100644
--- a/security/selinux/xfrm.c
+++ b/security/selinux/xfrm.c
@@ -225,6 +225,74 @@ void selinux_xfrm_state_free(struct xfrm_state *x)
225} 225}
226 226
227/* 227/*
228 * SELinux internal function to retrieve the context of a connected
229 * (sk->sk_state == TCP_ESTABLISHED) TCP socket based on its security
230 * association used to connect to the remote socket.
231 *
232 * Retrieve via getsockopt SO_PEERSEC.
233 */
234u32 selinux_socket_getpeer_stream(struct sock *sk)
235{
236 struct dst_entry *dst, *dst_test;
237 u32 peer_sid = SECSID_NULL;
238
239 if (sk->sk_state != TCP_ESTABLISHED)
240 goto out;
241
242 dst = sk_dst_get(sk);
243 if (!dst)
244 goto out;
245
246 for (dst_test = dst; dst_test != 0;
247 dst_test = dst_test->child) {
248 struct xfrm_state *x = dst_test->xfrm;
249
250 if (x && selinux_authorizable_xfrm(x)) {
251 struct xfrm_sec_ctx *ctx = x->security;
252 peer_sid = ctx->ctx_sid;
253 break;
254 }
255 }
256 dst_release(dst);
257
258out:
259 return peer_sid;
260}
261
262/*
263 * SELinux internal function to retrieve the context of a UDP packet
264 * based on its security association used to connect to the remote socket.
265 *
266 * Retrieve via setsockopt IP_PASSSEC and recvmsg with control message
267 * type SCM_SECURITY.
268 */
269u32 selinux_socket_getpeer_dgram(struct sk_buff *skb)
270{
271 struct sec_path *sp;
272
273 if (skb == NULL)
274 return SECSID_NULL;
275
276 if (skb->sk->sk_protocol != IPPROTO_UDP)
277 return SECSID_NULL;
278
279 sp = skb->sp;
280 if (sp) {
281 int i;
282
283 for (i = sp->len-1; i >= 0; i--) {
284 struct xfrm_state *x = sp->x[i].xvec;
285 if (selinux_authorizable_xfrm(x)) {
286 struct xfrm_sec_ctx *ctx = x->security;
287 return ctx->ctx_sid;
288 }
289 }
290 }
291
292 return SECSID_NULL;
293}
294
295/*
228 * LSM hook that controls access to unlabelled packets. If 296 * LSM hook that controls access to unlabelled packets. If
229 * a xfrm_state is authorizable (defined by macro) then it was 297 * a xfrm_state is authorizable (defined by macro) then it was
230 * already authorized by the IPSec process. If not, then 298 * already authorized by the IPSec process. If not, then