aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/Changes24
-rw-r--r--Documentation/DocBook/libata.tmpl96
-rw-r--r--Documentation/SubmittingDrivers14
-rw-r--r--Documentation/SubmittingPatches44
-rw-r--r--Documentation/block/ioprio.txt176
-rw-r--r--Documentation/cciss.txt1
-rw-r--r--Documentation/kernel-parameters.txt17
-rw-r--r--Documentation/networking/dmfe.txt82
-rw-r--r--Documentation/pcmcia/devicetable.txt64
-rw-r--r--Documentation/pcmcia/driver-changes.txt51
-rw-r--r--Documentation/serial/driver4
-rw-r--r--Documentation/video4linux/API.html415
-rw-r--r--Documentation/video4linux/CARDLIST.cx888
-rw-r--r--Documentation/video4linux/CARDLIST.saa71346
-rw-r--r--Documentation/video4linux/CARDLIST.tuner3
-rw-r--r--Documentation/video4linux/README.saa71349
-rw-r--r--MAINTAINERS17
-rw-r--r--Makefile4
-rw-r--r--arch/arm/Kconfig5
-rw-r--r--arch/arm/kernel/armksyms.c6
-rw-r--r--arch/arm/kernel/process.c5
-rw-r--r--arch/arm/kernel/setup.c3
-rw-r--r--arch/arm/kernel/smp.c123
-rw-r--r--arch/arm/kernel/time.c10
-rw-r--r--arch/arm/lib/Makefile2
-rw-r--r--arch/arm/lib/longlong.h183
-rw-r--r--arch/arm/lib/udivdi3.c222
-rw-r--r--arch/arm/mach-aaec2000/Makefile.boot1
-rw-r--r--arch/arm/mach-aaec2000/core.c4
-rw-r--r--arch/arm/mach-clps711x/time.c4
-rw-r--r--arch/arm/mach-clps7500/core.c4
-rw-r--r--arch/arm/mach-ebsa110/core.c4
-rw-r--r--arch/arm/mach-epxa10db/time.c4
-rw-r--r--arch/arm/mach-footbridge/dc21285-timer.c2
-rw-r--r--arch/arm/mach-footbridge/isa-timer.c2
-rw-r--r--arch/arm/mach-h720x/cpu-h7201.c4
-rw-r--r--arch/arm/mach-h720x/cpu-h7202.c4
-rw-r--r--arch/arm/mach-imx/time.c4
-rw-r--r--arch/arm/mach-integrator/core.c45
-rw-r--r--arch/arm/mach-iop3xx/iop321-time.c2
-rw-r--r--arch/arm/mach-iop3xx/iop331-time.c2
-rw-r--r--arch/arm/mach-ixp2000/core.c9
-rw-r--r--arch/arm/mach-ixp2000/ixdp2800.c6
-rw-r--r--arch/arm/mach-ixp4xx/common.c4
-rw-r--r--arch/arm/mach-lh7a40x/time.c4
-rw-r--r--arch/arm/mach-omap/pm.c16
-rw-r--r--arch/arm/mach-omap/time.c54
-rw-r--r--arch/arm/mach-omap/usb.c8
-rw-r--r--arch/arm/mach-pxa/time.c4
-rw-r--r--arch/arm/mach-s3c2410/Kconfig5
-rw-r--r--arch/arm/mach-s3c2410/Makefile1
-rw-r--r--arch/arm/mach-s3c2410/devs.c4
-rw-r--r--arch/arm/mach-s3c2410/irq.c7
-rw-r--r--arch/arm/mach-s3c2410/mach-bast.c39
-rw-r--r--arch/arm/mach-s3c2410/mach-vr1000.c8
-rw-r--r--arch/arm/mach-s3c2410/pm-simtec.c65
-rw-r--r--arch/arm/mach-s3c2410/time.c4
-rw-r--r--arch/arm/mach-sa1100/h3600.c2
-rw-r--r--arch/arm/mach-sa1100/time.c4
-rw-r--r--arch/arm/mach-shark/core.c4
-rw-r--r--arch/arm/mach-versatile/core.c65
-rw-r--r--arch/arm/mm/init.c73
-rw-r--r--arch/arm/mm/mm-armv.c89
-rw-r--r--arch/arm/oprofile/Makefile2
-rw-r--r--arch/arm/oprofile/backtrace.c144
-rw-r--r--arch/arm/oprofile/init.c2
-rw-r--r--arch/arm/oprofile/op_arm_model.h2
-rw-r--r--arch/arm/tools/mach-types69
-rw-r--r--arch/arm/vfp/vfp.h15
-rw-r--r--arch/arm/vfp/vfpdouble.c2
-rw-r--r--arch/arm/vfp/vfpmodule.c2
-rw-r--r--arch/arm/vfp/vfpsingle.c14
-rw-r--r--arch/i386/boot/tools/build.c3
-rw-r--r--arch/i386/kernel/acpi/boot.c57
-rw-r--r--arch/i386/kernel/kprobes.c133
-rw-r--r--arch/i386/kernel/process.c29
-rw-r--r--arch/i386/kernel/syscall_table.S2
-rw-r--r--arch/i386/pci/common.c8
-rw-r--r--arch/i386/pci/irq.c51
-rw-r--r--arch/i386/pci/legacy.c2
-rw-r--r--arch/i386/pci/mmconfig.c39
-rw-r--r--arch/i386/pci/numa.c2
-rw-r--r--arch/i386/pci/pci.h1
-rw-r--r--arch/ia64/configs/sn2_defconfig4
-rw-r--r--arch/ia64/configs/tiger_defconfig39
-rw-r--r--arch/ia64/configs/zx1_defconfig166
-rw-r--r--arch/ia64/hp/common/sba_iommu.c4
-rw-r--r--arch/ia64/hp/sim/simserial.c16
-rw-r--r--arch/ia64/kernel/acpi.c30
-rw-r--r--arch/ia64/kernel/entry.S114
-rw-r--r--arch/ia64/kernel/fsys.S147
-rw-r--r--arch/ia64/kernel/gate.S62
-rw-r--r--arch/ia64/kernel/ia64_ksyms.c3
-rw-r--r--arch/ia64/kernel/iosapic.c134
-rw-r--r--arch/ia64/kernel/ivt.S198
-rw-r--r--arch/ia64/kernel/kprobes.c128
-rw-r--r--arch/ia64/kernel/process.c16
-rw-r--r--arch/ia64/kernel/ptrace.c22
-rw-r--r--arch/ia64/kernel/setup.c12
-rw-r--r--arch/ia64/kernel/smp.c3
-rw-r--r--arch/ia64/kernel/vmlinux.lds.S7
-rw-r--r--arch/ia64/pci/pci.c38
-rw-r--r--arch/ia64/sn/kernel/io_init.c2
-rw-r--r--arch/ia64/sn/kernel/iomv.c6
-rw-r--r--arch/ia64/sn/kernel/setup.c43
-rw-r--r--arch/ia64/sn/kernel/sn2/ptc_deadlock.S1
-rw-r--r--arch/ia64/sn/kernel/tiocx.c14
-rw-r--r--arch/ia64/sn/pci/tioca_provider.c8
-rw-r--r--arch/mips/kernel/signal.c2
-rw-r--r--arch/parisc/configs/712_defconfig2
-rw-r--r--arch/parisc/configs/a500_defconfig2
-rw-r--r--arch/parisc/configs/b180_defconfig2
-rw-r--r--arch/parisc/configs/c3000_defconfig2
-rw-r--r--arch/parisc/defconfig2
-rw-r--r--arch/ppc/kernel/misc.S2
-rw-r--r--arch/ppc/kernel/pci.c21
-rw-r--r--arch/ppc/mm/init.c14
-rw-r--r--arch/ppc/platforms/pmac_sleep.S4
-rw-r--r--arch/ppc/platforms/pmac_time.c8
-rw-r--r--arch/ppc/platforms/sandpoint.c1
-rw-r--r--arch/ppc/syslib/open_pic.c26
-rw-r--r--arch/ppc64/kernel/irq.c2
-rw-r--r--arch/ppc64/kernel/kprobes.c125
-rw-r--r--arch/ppc64/kernel/pci.c22
-rw-r--r--arch/ppc64/kernel/ppc_ksyms.c1
-rw-r--r--arch/ppc64/kernel/process.c4
-rw-r--r--arch/ppc64/kernel/time.c1
-rw-r--r--arch/sparc/Kconfig56
-rw-r--r--arch/sparc64/kernel/auxio.c2
-rw-r--r--arch/sparc64/kernel/entry.S116
-rw-r--r--arch/sparc64/kernel/irq.c171
-rw-r--r--arch/sparc64/kernel/semaphore.c12
-rw-r--r--arch/sparc64/kernel/sparc64_ksyms.c1
-rw-r--r--arch/sparc64/kernel/trampoline.S3
-rw-r--r--arch/sparc64/lib/U1memcpy.S103
-rw-r--r--arch/sparc64/lib/VISsave.S15
-rw-r--r--arch/sparc64/lib/atomic.S42
-rw-r--r--arch/sparc64/lib/bitops.S31
-rw-r--r--arch/sparc64/lib/debuglocks.c6
-rw-r--r--arch/sparc64/lib/dec_and_lock.S6
-rw-r--r--arch/sparc64/lib/rwsem.S15
-rw-r--r--arch/sparc64/mm/init.c6
-rw-r--r--arch/sparc64/mm/ultra.S3
-rw-r--r--arch/x86_64/kernel/kprobes.c236
-rw-r--r--arch/x86_64/kernel/process.c29
-rw-r--r--arch/x86_64/pci/mmconfig.c68
-rw-r--r--drivers/acpi/container.c2
-rw-r--r--drivers/acpi/pci_bind.c27
-rw-r--r--drivers/acpi/pci_root.c24
-rw-r--r--drivers/acpi/processor_core.c2
-rw-r--r--drivers/acpi/scan.c126
-rw-r--r--drivers/base/firmware_class.c13
-rw-r--r--drivers/block/as-iosched.c5
-rw-r--r--drivers/block/cciss.c18
-rw-r--r--drivers/block/cfq-iosched.c2081
-rw-r--r--drivers/block/deadline-iosched.c3
-rw-r--r--drivers/block/elevator.c9
-rw-r--r--drivers/block/ll_rw_blk.c206
-rw-r--r--drivers/block/swim3.c10
-rw-r--r--drivers/block/sx8.c7
-rw-r--r--drivers/bluetooth/bluecard_cs.c9
-rw-r--r--drivers/bluetooth/bt3c_cs.c7
-rw-r--r--drivers/bluetooth/btuart_cs.c7
-rw-r--r--drivers/bluetooth/dtl1_cs.c8
-rw-r--r--drivers/char/agp/amd64-agp.c9
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c4
-rw-r--r--drivers/char/misc.c3
-rw-r--r--drivers/char/moxa.c2
-rw-r--r--drivers/char/pcmcia/synclink_cs.c9
-rw-r--r--drivers/char/rio/rio_linux.c4
-rw-r--r--drivers/char/rtc.c16
-rw-r--r--drivers/char/tipar.c2
-rw-r--r--drivers/char/tty_ioctl.c4
-rw-r--r--drivers/char/vt_ioctl.c5
-rw-r--r--drivers/char/watchdog/ixp2000_wdt.c2
-rw-r--r--drivers/char/watchdog/ixp4xx_wdt.c2
-rw-r--r--drivers/firmware/pcdp.c24
-rw-r--r--drivers/firmware/pcdp.h33
-rw-r--r--drivers/i2c/chips/atxp1.c2
-rw-r--r--drivers/ide/Kconfig6
-rw-r--r--drivers/ide/ide-disk.c4
-rw-r--r--drivers/ide/ide-dma.c1
-rw-r--r--drivers/ide/ide-iops.c3
-rw-r--r--drivers/ide/legacy/ide-cs.c35
-rw-r--r--drivers/ide/pci/Makefile1
-rw-r--r--drivers/ide/pci/generic.c73
-rw-r--r--drivers/ide/pci/hpt366.c470
-rw-r--r--drivers/ide/pci/it821x.c812
-rw-r--r--drivers/ide/pci/serverworks.c10
-rw-r--r--drivers/ide/ppc/pmac.c8
-rw-r--r--drivers/ieee1394/ohci1394.c10
-rw-r--r--drivers/infiniband/core/packer.c4
-rw-r--r--drivers/infiniband/core/sa_query.c18
-rw-r--r--drivers/infiniband/hw/mthca/mthca_av.c1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.c531
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.h48
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cq.c101
-rw-r--r--drivers/infiniband/hw/mthca/mthca_dev.h12
-rw-r--r--drivers/infiniband/hw/mthca/mthca_doorbell.h1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_eq.c58
-rw-r--r--drivers/infiniband/hw/mthca/mthca_main.c32
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mcg.c63
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.c10
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mr.c367
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.h14
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c139
-rw-r--r--drivers/input/evdev.c407
-rw-r--r--drivers/input/gameport/Kconfig14
-rw-r--r--drivers/input/gameport/Makefile2
-rw-r--r--drivers/input/gameport/cs461x.c322
-rw-r--r--drivers/input/gameport/gameport.c31
-rw-r--r--drivers/input/gameport/ns558.c12
-rw-r--r--drivers/input/gameport/vortex.c186
-rw-r--r--drivers/input/input.c37
-rw-r--r--drivers/input/joydev.c116
-rw-r--r--drivers/input/joystick/a3d.c2
-rw-r--r--drivers/input/joystick/adi.c4
-rw-r--r--drivers/input/joystick/amijoy.c29
-rw-r--r--drivers/input/joystick/db9.c17
-rw-r--r--drivers/input/joystick/gamecon.c29
-rw-r--r--drivers/input/joystick/gf2k.c2
-rw-r--r--drivers/input/joystick/grip_mp.c2
-rw-r--r--drivers/input/joystick/iforce/iforce-main.c1
-rw-r--r--drivers/input/joystick/iforce/iforce-usb.c1
-rw-r--r--drivers/input/joystick/spaceball.c4
-rw-r--r--drivers/input/joystick/spaceorb.c2
-rw-r--r--drivers/input/joystick/tmdc.c2
-rw-r--r--drivers/input/joystick/turbografx.c35
-rw-r--r--drivers/input/keyboard/atkbd.c6
-rw-r--r--drivers/input/keyboard/corgikbd.c6
-rw-r--r--drivers/input/keyboard/lkkbd.c8
-rw-r--r--drivers/input/keyboard/locomokbd.c28
-rw-r--r--drivers/input/keyboard/maple_keyb.c22
-rw-r--r--drivers/input/misc/uinput.c6
-rw-r--r--drivers/input/mouse/Makefile2
-rw-r--r--drivers/input/mouse/alps.c52
-rw-r--r--drivers/input/mouse/amimouse.c8
-rw-r--r--drivers/input/mouse/inport.c38
-rw-r--r--drivers/input/mouse/lifebook.c134
-rw-r--r--drivers/input/mouse/lifebook.h17
-rw-r--r--drivers/input/mouse/logibm.c17
-rw-r--r--drivers/input/mouse/maplemouse.c75
-rw-r--r--drivers/input/mouse/pc110pad.c21
-rw-r--r--drivers/input/mouse/psmouse-base.c351
-rw-r--r--drivers/input/mouse/psmouse.h4
-rw-r--r--drivers/input/mouse/rpcmouse.c2
-rw-r--r--drivers/input/mouse/vsxxxaa.c4
-rw-r--r--drivers/input/mousedev.c8
-rw-r--r--drivers/input/serio/libps2.c136
-rw-r--r--drivers/input/serio/serio.c89
-rw-r--r--drivers/input/touchscreen/elo.c2
-rw-r--r--drivers/input/touchscreen/h3600_ts_input.c180
-rw-r--r--drivers/input/touchscreen/mk712.c21
-rw-r--r--drivers/isdn/hardware/avm/avm_cs.c9
-rw-r--r--drivers/isdn/hardware/eicon/dadapter.c2
-rw-r--r--drivers/isdn/hisax/avma1_cs.c8
-rw-r--r--drivers/isdn/hisax/elsa_cs.c8
-rw-r--r--drivers/isdn/hisax/hfc4s8s_l1.c8
-rw-r--r--drivers/isdn/hisax/sedlbauer_cs.c13
-rw-r--r--drivers/isdn/hisax/teles_cs.c7
-rw-r--r--drivers/isdn/hysdn/hycapi.c20
-rw-r--r--drivers/isdn/hysdn/hysdn_boot.c4
-rw-r--r--drivers/isdn/hysdn/hysdn_defs.h12
-rw-r--r--drivers/isdn/hysdn/hysdn_init.c2
-rw-r--r--drivers/isdn/hysdn/hysdn_proclog.c4
-rw-r--r--drivers/macintosh/Kconfig42
-rw-r--r--drivers/macintosh/Makefile3
-rw-r--r--drivers/macintosh/adb.c10
-rw-r--r--drivers/macintosh/macserial.c3036
-rw-r--r--drivers/macintosh/macserial.h461
-rw-r--r--drivers/macintosh/via-pmu.c78
-rw-r--r--drivers/md/md.c1
-rw-r--r--drivers/media/video/Kconfig2
-rw-r--r--drivers/media/video/Makefile3
-rw-r--r--drivers/media/video/bttv-driver.c73
-rw-r--r--drivers/media/video/bttvp.h5
-rw-r--r--drivers/media/video/mt20xx.c6
-rw-r--r--drivers/media/video/tda8290.c20
-rw-r--r--drivers/media/video/tda9887.c7
-rw-r--r--drivers/media/video/tea5767.c334
-rw-r--r--drivers/media/video/tuner-core.c163
-rw-r--r--drivers/media/video/tuner-simple.c34
-rw-r--r--drivers/message/fusion/mptfc.c4
-rw-r--r--drivers/message/fusion/mptscsih.c10
-rw-r--r--drivers/message/fusion/mptscsih.h2
-rw-r--r--drivers/message/fusion/mptspi.c4
-rw-r--r--drivers/mtd/maps/Kconfig10
-rw-r--r--drivers/mtd/maps/pcmciamtd.c29
-rw-r--r--drivers/net/3c503.c16
-rw-r--r--drivers/net/3c505.c6
-rw-r--r--drivers/net/3c509.c1
-rw-r--r--drivers/net/3c515.c16
-rw-r--r--drivers/net/3c523.c19
-rw-r--r--drivers/net/3c59x.c6
-rw-r--r--drivers/net/8139cp.c25
-rw-r--r--drivers/net/82596.c14
-rw-r--r--drivers/net/Kconfig8
-rw-r--r--drivers/net/ac3200.c19
-rw-r--r--drivers/net/acenic.c5
-rwxr-xr-xdrivers/net/amd8111e.c8
-rw-r--r--drivers/net/arm/etherh.c16
-rw-r--r--drivers/net/at1700.c4
-rw-r--r--drivers/net/b44.c3
-rw-r--r--drivers/net/bonding/bond_3ad.c3
-rw-r--r--drivers/net/bonding/bond_main.c390
-rw-r--r--drivers/net/bonding/bonding.h12
-rw-r--r--drivers/net/cs89x0.c59
-rw-r--r--drivers/net/cs89x0.h2
-rw-r--r--drivers/net/defxx.c88
-rw-r--r--drivers/net/dl2k.c8
-rw-r--r--drivers/net/dm9000.c4
-rw-r--r--drivers/net/e100.c37
-rw-r--r--drivers/net/e1000/e1000.h4
-rw-r--r--drivers/net/e1000/e1000_ethtool.c131
-rw-r--r--drivers/net/e1000/e1000_hw.c23
-rw-r--r--drivers/net/e1000/e1000_hw.h1
-rw-r--r--drivers/net/e1000/e1000_main.c111
-rw-r--r--drivers/net/e2100.c15
-rw-r--r--drivers/net/eepro.c21
-rw-r--r--drivers/net/eepro100.c8
-rw-r--r--drivers/net/eexpress.c12
-rw-r--r--drivers/net/epic100.c6
-rw-r--r--drivers/net/es3210.c16
-rw-r--r--drivers/net/eth16i.c20
-rw-r--r--drivers/net/ewrk3.c12
-rw-r--r--drivers/net/fealnx.c11
-rw-r--r--drivers/net/forcedeth.c53
-rw-r--r--drivers/net/gianfar.c652
-rw-r--r--drivers/net/gianfar.h363
-rw-r--r--drivers/net/gianfar_ethtool.c277
-rw-r--r--drivers/net/gianfar_phy.c2
-rw-r--r--drivers/net/hamachi.c12
-rw-r--r--drivers/net/hp-plus.c15
-rw-r--r--drivers/net/hp.c17
-rw-r--r--drivers/net/hp100.c44
-rw-r--r--drivers/net/isa-skeleton.c20
-rw-r--r--drivers/net/ixgb/ixgb_main.c5
-rw-r--r--drivers/net/lance.c17
-rw-r--r--drivers/net/lasi_82596.c8
-rw-r--r--drivers/net/lne390.c19
-rw-r--r--drivers/net/myri_code.h1283
-rw-r--r--drivers/net/natsemi.c4
-rw-r--r--drivers/net/ne-h8300.c19
-rw-r--r--drivers/net/ne.c18
-rw-r--r--drivers/net/ne2.c19
-rw-r--r--drivers/net/ns83820.c5
-rw-r--r--drivers/net/pcmcia/3c574_cs.c8
-rw-r--r--drivers/net/pcmcia/3c589_cs.c12
-rw-r--r--drivers/net/pcmcia/axnet_cs.c29
-rw-r--r--drivers/net/pcmcia/com20020_cs.c7
-rw-r--r--drivers/net/pcmcia/fmvj18x_cs.c30
-rw-r--r--drivers/net/pcmcia/ibmtr_cs.c11
-rw-r--r--drivers/net/pcmcia/nmclan_cs.c8
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c213
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c320
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c28
-rw-r--r--drivers/net/pcnet32.c8
-rw-r--r--drivers/net/r8169.c4
-rw-r--r--drivers/net/s2io.c15
-rw-r--r--drivers/net/sb1000.c14
-rw-r--r--drivers/net/sb1250-mac.c4
-rw-r--r--drivers/net/sis900.c11
-rw-r--r--drivers/net/sk98lin/skge.c5
-rw-r--r--drivers/net/skfp/Makefile4
-rw-r--r--drivers/net/skfp/drvfbi.c222
-rw-r--r--drivers/net/skfp/ess.c4
-rw-r--r--drivers/net/skfp/fplustm.c70
-rw-r--r--drivers/net/skfp/h/cmtdef.h7
-rw-r--r--drivers/net/skfp/h/hwmtm.h25
-rw-r--r--drivers/net/skfp/h/osdef1st.h2
-rw-r--r--drivers/net/skfp/hwmtm.c34
-rw-r--r--drivers/net/skfp/lnkstat.c204
-rw-r--r--drivers/net/skfp/pcmplc.c7
-rw-r--r--drivers/net/skfp/pmf.c11
-rw-r--r--drivers/net/skfp/skfddi.c1
-rw-r--r--drivers/net/skfp/smt.c48
-rw-r--r--drivers/net/skfp/smtdef.c5
-rw-r--r--drivers/net/skfp/smtparse.c467
-rw-r--r--drivers/net/skge.c1710
-rw-r--r--drivers/net/skge.h586
-rw-r--r--drivers/net/slip.c7
-rw-r--r--drivers/net/smc-mca.c60
-rw-r--r--drivers/net/smc-mca.h61
-rw-r--r--drivers/net/smc-ultra.c15
-rw-r--r--drivers/net/smc91x.c45
-rw-r--r--drivers/net/smc91x.h13
-rw-r--r--drivers/net/starfire.c6
-rw-r--r--drivers/net/sundance.c6
-rw-r--r--drivers/net/sungem.c5
-rw-r--r--drivers/net/tlan.c3
-rw-r--r--drivers/net/tokenring/3c359.c3
-rw-r--r--drivers/net/tokenring/3c359_microcode.h2
-rw-r--r--drivers/net/tokenring/abyss.c11
-rw-r--r--drivers/net/tokenring/ibmtr.c28
-rw-r--r--drivers/net/tokenring/lanstreamer.c9
-rw-r--r--drivers/net/tokenring/madgemc.c14
-rw-r--r--drivers/net/tokenring/proteon.c11
-rw-r--r--drivers/net/tokenring/skisa.c11
-rw-r--r--drivers/net/tokenring/smctr.c2
-rw-r--r--drivers/net/tokenring/smctr_firmware.h2
-rw-r--r--drivers/net/tokenring/tms380tr.c13
-rw-r--r--drivers/net/tokenring/tmspci.c11
-rw-r--r--drivers/net/tulip/de2104x.c6
-rw-r--r--drivers/net/tulip/dmfe.c23
-rw-r--r--drivers/net/tulip/eeprom.c16
-rw-r--r--drivers/net/tulip/interrupt.c10
-rw-r--r--drivers/net/tulip/media.c3
-rw-r--r--drivers/net/tulip/tulip_core.c50
-rw-r--r--drivers/net/tulip/winbond-840.c9
-rw-r--r--drivers/net/tulip/xircom_tulip_cb.c4
-rw-r--r--drivers/net/typhoon.c4
-rw-r--r--drivers/net/via-rhine.c26
-rw-r--r--drivers/net/via-velocity.c6
-rw-r--r--drivers/net/wan/farsync.c1
-rw-r--r--drivers/net/wan/hdlc_cisco.c2
-rw-r--r--drivers/net/wan/wanxl.c5
-rw-r--r--drivers/net/wd.c18
-rw-r--r--drivers/net/wireless/airo.c12
-rw-r--r--drivers/net/wireless/airo_cs.c10
-rw-r--r--drivers/net/wireless/arlan-main.c26
-rw-r--r--drivers/net/wireless/atmel_cs.c22
-rw-r--r--drivers/net/wireless/netwave_cs.c7
-rw-r--r--drivers/net/wireless/orinoco.c2465
-rw-r--r--drivers/net/wireless/orinoco.h30
-rw-r--r--drivers/net/wireless/orinoco_cs.c51
-rw-r--r--drivers/net/wireless/prism54/isl_38xx.c6
-rw-r--r--drivers/net/wireless/ray_cs.c7
-rw-r--r--drivers/net/wireless/wavelan_cs.c10
-rw-r--r--drivers/net/wireless/wl3501_cs.c7
-rw-r--r--drivers/net/yellowfin.c8
-rw-r--r--drivers/parisc/dino.c1
-rw-r--r--drivers/parisc/lba_pci.c2
-rw-r--r--drivers/parport/parport_cs.c9
-rw-r--r--drivers/pci/bus.c11
-rw-r--r--drivers/pci/hotplug/Makefile4
-rw-r--r--drivers/pci/hotplug/acpiphp.h47
-rw-r--r--drivers/pci/hotplug/acpiphp_core.c9
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c882
-rw-r--r--drivers/pci/hotplug/acpiphp_pci.c449
-rw-r--r--drivers/pci/hotplug/acpiphp_res.c700
-rw-r--r--drivers/pci/hotplug/cpqphp_core.c5
-rw-r--r--drivers/pci/msi.c88
-rw-r--r--drivers/pci/msi.h9
-rw-r--r--drivers/pci/pci-sysfs.c26
-rw-r--r--drivers/pci/probe.c29
-rw-r--r--drivers/pci/proc.c14
-rw-r--r--drivers/pci/remove.c14
-rw-r--r--drivers/pci/setup-bus.c5
-rw-r--r--drivers/pcmcia/Kconfig43
-rw-r--r--drivers/pcmcia/Makefile3
-rw-r--r--drivers/pcmcia/cistpl.c28
-rw-r--r--drivers/pcmcia/cs.c1164
-rw-r--r--drivers/pcmcia/cs_internal.h13
-rw-r--r--drivers/pcmcia/ds.c1255
-rw-r--r--drivers/pcmcia/ds_internal.h21
-rw-r--r--drivers/pcmcia/i82365.c23
-rw-r--r--drivers/pcmcia/pcmcia_compat.c34
-rw-r--r--drivers/pcmcia/pcmcia_ioctl.c786
-rw-r--r--drivers/pcmcia/pcmcia_resource.c998
-rw-r--r--drivers/pcmcia/rsrc_mgr.c11
-rw-r--r--drivers/pcmcia/rsrc_nonstatic.c170
-rw-r--r--drivers/pcmcia/socket_sysfs.c166
-rw-r--r--drivers/pcmcia/yenta_socket.c6
-rw-r--r--drivers/scsi/3w-9xxx.c8
-rw-r--r--drivers/scsi/3w-xxxx.c8
-rw-r--r--drivers/scsi/ahci.c22
-rw-r--r--drivers/scsi/ipr.c10
-rw-r--r--drivers/scsi/libata-core.c6
-rw-r--r--drivers/scsi/libata-scsi.c16
-rw-r--r--drivers/scsi/megaraid.c8
-rw-r--r--drivers/scsi/pcmcia/aha152x_stub.c11
-rw-r--r--drivers/scsi/pcmcia/fdomain_stub.c10
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.c13
-rw-r--r--drivers/scsi/pcmcia/qlogic_stub.c22
-rw-r--r--drivers/scsi/pcmcia/sym53c500_cs.c9
-rw-r--r--drivers/scsi/scsi_lib.c2
-rw-r--r--drivers/serial/68328serial.c17
-rw-r--r--drivers/serial/8250.c58
-rw-r--r--drivers/serial/8250_accent.c47
-rw-r--r--drivers/serial/8250_boca.c61
-rw-r--r--drivers/serial/8250_fourport.c53
-rw-r--r--drivers/serial/8250_hub6.c58
-rw-r--r--drivers/serial/8250_mca.c64
-rw-r--r--drivers/serial/Kconfig77
-rw-r--r--drivers/serial/Makefile5
-rw-r--r--drivers/serial/au1x00_uart.c3
-rw-r--r--drivers/serial/ip22zilog.c13
-rw-r--r--drivers/serial/mpsc.c3
-rw-r--r--drivers/serial/pmac_zilog.c4
-rw-r--r--drivers/serial/pxa.c3
-rw-r--r--drivers/serial/serial_core.c28
-rw-r--r--drivers/serial/serial_cs.c106
-rw-r--r--drivers/serial/serial_txx9.c3
-rw-r--r--drivers/serial/sunsab.c7
-rw-r--r--drivers/serial/sunsu.c3
-rw-r--r--drivers/serial/sunzilog.c13
-rw-r--r--drivers/telephony/ixj_pcmcia.c7
-rw-r--r--drivers/usb/Makefile2
-rw-r--r--drivers/usb/atm/Kconfig50
-rw-r--r--drivers/usb/atm/Makefile7
-rw-r--r--drivers/usb/atm/cxacru.c878
-rw-r--r--drivers/usb/atm/speedtch.c1085
-rw-r--r--drivers/usb/atm/usb_atm.c1188
-rw-r--r--drivers/usb/atm/usb_atm.h176
-rw-r--r--drivers/usb/atm/usbatm.c1230
-rw-r--r--drivers/usb/atm/usbatm.h184
-rw-r--r--drivers/usb/atm/xusbatm.c196
-rw-r--r--drivers/usb/class/cdc-acm.c209
-rw-r--r--drivers/usb/class/cdc-acm.h25
-rw-r--r--drivers/usb/class/usblp.c3
-rw-r--r--drivers/usb/core/devio.c6
-rw-r--r--drivers/usb/core/hcd.c279
-rw-r--r--drivers/usb/core/hcd.h19
-rw-r--r--drivers/usb/core/hub.c19
-rw-r--r--drivers/usb/core/hub.h11
-rw-r--r--drivers/usb/gadget/Kconfig11
-rw-r--r--drivers/usb/gadget/dummy_hcd.c745
-rw-r--r--drivers/usb/gadget/ether.c353
-rw-r--r--drivers/usb/gadget/file_storage.c61
-rw-r--r--drivers/usb/gadget/goku_udc.c28
-rw-r--r--drivers/usb/gadget/inode.c12
-rw-r--r--drivers/usb/gadget/ndis.h14
-rw-r--r--drivers/usb/gadget/net2280.c51
-rw-r--r--drivers/usb/gadget/omap_udc.c301
-rw-r--r--drivers/usb/gadget/omap_udc.h4
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c43
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.h10
-rw-r--r--drivers/usb/gadget/rndis.c515
-rw-r--r--drivers/usb/gadget/rndis.h95
-rw-r--r--drivers/usb/gadget/serial.c36
-rw-r--r--drivers/usb/gadget/zero.c6
-rw-r--r--drivers/usb/host/Kconfig13
-rw-r--r--drivers/usb/host/Makefile1
-rw-r--r--drivers/usb/host/ehci-dbg.c59
-rw-r--r--drivers/usb/host/ehci-hcd.c58
-rw-r--r--drivers/usb/host/ehci-hub.c2
-rw-r--r--drivers/usb/host/ehci-q.c2
-rw-r--r--drivers/usb/host/ehci-sched.c17
-rw-r--r--drivers/usb/host/isp116x-hcd.c1875
-rw-r--r--drivers/usb/host/isp116x.h583
-rw-r--r--drivers/usb/host/ohci-hcd.c58
-rw-r--r--drivers/usb/host/ohci-mem.c1
-rw-r--r--drivers/usb/host/ohci-omap.c4
-rw-r--r--drivers/usb/host/ohci-pci.c13
-rw-r--r--drivers/usb/host/ohci.h2
-rw-r--r--drivers/usb/host/sl811-hcd.c18
-rw-r--r--drivers/usb/host/sl811_cs.c21
-rw-r--r--drivers/usb/host/uhci-debug.c32
-rw-r--r--drivers/usb/host/uhci-hcd.c773
-rw-r--r--drivers/usb/host/uhci-hcd.h59
-rw-r--r--drivers/usb/host/uhci-hub.c83
-rw-r--r--drivers/usb/host/uhci-q.c58
-rw-r--r--drivers/usb/input/Kconfig24
-rw-r--r--drivers/usb/input/Makefile2
-rw-r--r--drivers/usb/input/acecad.c285
-rw-r--r--drivers/usb/input/aiptek.c32
-rw-r--r--drivers/usb/input/ati_remote.c248
-rw-r--r--drivers/usb/input/hid-core.c26
-rw-r--r--drivers/usb/input/hid-debug.h16
-rw-r--r--drivers/usb/input/hid-input.c16
-rw-r--r--drivers/usb/input/hid-lgff.c18
-rw-r--r--drivers/usb/input/hid.h18
-rw-r--r--drivers/usb/input/hiddev.c56
-rw-r--r--drivers/usb/input/itmtouch.c268
-rw-r--r--drivers/usb/input/kbtab.c17
-rw-r--r--drivers/usb/input/mtouchusb.c410
-rw-r--r--drivers/usb/input/powermate.c30
-rw-r--r--drivers/usb/input/touchkitusb.c11
-rw-r--r--drivers/usb/input/usbkbd.c29
-rw-r--r--drivers/usb/input/usbmouse.c31
-rw-r--r--drivers/usb/input/wacom.c398
-rw-r--r--drivers/usb/input/xpad.c75
-rw-r--r--drivers/usb/media/stv680.c8
-rw-r--r--drivers/usb/media/stv680.h5
-rw-r--r--drivers/usb/misc/idmouse.c149
-rw-r--r--drivers/usb/misc/usbtest.c60
-rw-r--r--drivers/usb/net/pegasus.c2
-rw-r--r--drivers/usb/net/pegasus.h2
-rw-r--r--drivers/usb/net/rtl8150.c2
-rw-r--r--drivers/usb/net/usbnet.c2
-rw-r--r--drivers/usb/net/zd1201.c41
-rw-r--r--drivers/usb/net/zd1201.h1
-rw-r--r--drivers/usb/serial/cyberjack.c19
-rw-r--r--drivers/usb/serial/generic.c24
-rw-r--r--drivers/usb/serial/ipaq.c5
-rw-r--r--drivers/usb/serial/ipw.c14
-rw-r--r--drivers/usb/serial/ir-usb.c16
-rw-r--r--drivers/usb/serial/keyspan_pda.c19
-rw-r--r--drivers/usb/serial/omninet.c17
-rw-r--r--drivers/usb/serial/safe_serial.c13
-rw-r--r--drivers/usb/serial/usb-serial.c1
-rw-r--r--drivers/usb/serial/usb-serial.h3
-rw-r--r--drivers/usb/storage/scsiglue.c54
-rw-r--r--drivers/usb/storage/scsiglue.h1
-rw-r--r--drivers/usb/storage/transport.c116
-rw-r--r--drivers/usb/storage/transport.h1
-rw-r--r--drivers/video/aty/aty128fb.c14
-rw-r--r--drivers/video/chipsfb.c176
-rw-r--r--fs/Makefile1
-rw-r--r--fs/aio.c9
-rw-r--r--fs/buffer.c4
-rw-r--r--fs/char_dev.c2
-rw-r--r--fs/ext3/balloc.c135
-rw-r--r--fs/ext3/file.c4
-rw-r--r--fs/ext3/super.c3
-rw-r--r--fs/ioprio.c172
-rw-r--r--fs/nfs/nfs3acl.c14
-rw-r--r--fs/nfsd/vfs.c13
-rw-r--r--fs/reiserfs/ioctl.c6
-rw-r--r--fs/reiserfs/journal.c12
-rw-r--r--fs/reiserfs/super.c2
-rw-r--r--fs/udf/namei.c4
-rw-r--r--include/acpi/acpi_bus.h17
-rw-r--r--include/acpi/acpi_drivers.h1
-rw-r--r--include/asm-alpha/pci.h19
-rw-r--r--include/asm-alpha/serial.h47
-rw-r--r--include/asm-arm/arch-ixp2000/ixdp2x00.h4
-rw-r--r--include/asm-arm/arch-ixp2000/ixdp2x01.h4
-rw-r--r--include/asm-arm/arch-ixp2000/ixp2000-regs.h19
-rw-r--r--include/asm-arm/arch-ixp2000/vmalloc.h2
-rw-r--r--include/asm-arm/arch-ixp4xx/debug-macro.S2
-rw-r--r--include/asm-arm/arch-omap/usb.h9
-rw-r--r--include/asm-arm/arch-pxa/debug-macro.S2
-rw-r--r--include/asm-arm/arch-s3c2410/audio.h49
-rw-r--r--include/asm-arm/hardware/arm_timer.h21
-rw-r--r--include/asm-arm/ide.h2
-rw-r--r--include/asm-arm/io.h2
-rw-r--r--include/asm-arm/mach/time.h2
-rw-r--r--include/asm-arm/pci.h10
-rw-r--r--include/asm-arm/system.h12
-rw-r--r--include/asm-arm/tlbflush.h28
-rw-r--r--include/asm-arm26/serial.h22
-rw-r--r--include/asm-frv/pci.h10
-rw-r--r--include/asm-i386/ide.h12
-rw-r--r--include/asm-i386/pci.h10
-rw-r--r--include/asm-i386/serial.h102
-rw-r--r--include/asm-i386/tlbflush.h12
-rw-r--r--include/asm-i386/unistd.h4
-rw-r--r--include/asm-ia64/iosapic.h12
-rw-r--r--include/asm-ia64/kprobes.h14
-rw-r--r--include/asm-ia64/mmu_context.h3
-rw-r--r--include/asm-ia64/pci.h19
-rw-r--r--include/asm-ia64/sections.h1
-rw-r--r--include/asm-ia64/sn/addrs.h17
-rw-r--r--include/asm-ia64/sn/l1.h1
-rw-r--r--include/asm-ia64/sn/shub_mmr.h346
-rw-r--r--include/asm-ia64/sn/simulator.h13
-rw-r--r--include/asm-ia64/sn/sn2/sn_hwperf.h2
-rw-r--r--include/asm-ia64/sn/sn_sal.h10
-rw-r--r--include/asm-ia64/sn/tioca_provider.h1
-rw-r--r--include/asm-ia64/unistd.h2
-rw-r--r--include/asm-ia64/vga.h5
-rw-r--r--include/asm-m68k/serial.h47
-rw-r--r--include/asm-mips/pci.h10
-rw-r--r--include/asm-mips/serial.h84
-rw-r--r--include/asm-parisc/pci.h19
-rw-r--r--include/asm-parisc/serial.h16
-rw-r--r--include/asm-ppc/open_pic.h6
-rw-r--r--include/asm-ppc/pc_serial.h86
-rw-r--r--include/asm-ppc/pci.h16
-rw-r--r--include/asm-ppc/unistd.h4
-rw-r--r--include/asm-ppc64/byteorder.h10
-rw-r--r--include/asm-ppc64/kprobes.h5
-rw-r--r--include/asm-ppc64/pci.h26
-rw-r--r--include/asm-sh/bigsur/serial.h5
-rw-r--r--include/asm-sh/ec3104/serial.h4
-rw-r--r--include/asm-sh/pci.h10
-rw-r--r--include/asm-sh/serial.h6
-rw-r--r--include/asm-sh64/pci.h10
-rw-r--r--include/asm-sh64/serial.h4
-rw-r--r--include/asm-sparc/pci.h10
-rw-r--r--include/asm-sparc64/auxio.h2
-rw-r--r--include/asm-sparc64/floppy.h16
-rw-r--r--include/asm-sparc64/irq.h7
-rw-r--r--include/asm-sparc64/pci.h19
-rw-r--r--include/asm-sparc64/rwsem.h3
-rw-r--r--include/asm-sparc64/spinlock.h29
-rw-r--r--include/asm-sparc64/spitfire.h1
-rw-r--r--include/asm-v850/pci.h10
-rw-r--r--include/asm-x86_64/pci.h10
-rw-r--r--include/asm-x86_64/serial.h102
-rw-r--r--include/asm-x86_64/tlbflush.h12
-rw-r--r--include/asm-x86_64/unistd.h6
-rw-r--r--include/linux/acpi.h19
-rw-r--r--include/linux/atalk.h2
-rw-r--r--include/linux/bio.h14
-rw-r--r--include/linux/blkdev.h26
-rw-r--r--include/linux/byteorder/swabb.h17
-rw-r--r--include/linux/cciss_ioctl.h1
-rw-r--r--include/linux/elevator.h8
-rw-r--r--include/linux/etherdevice.h3
-rw-r--r--include/linux/fs.h19
-rw-r--r--include/linux/i2c-dev.h1
-rw-r--r--include/linux/if_bonding.h7
-rw-r--r--include/linux/in6.h2
-rw-r--r--include/linux/init_task.h2
-rw-r--r--include/linux/input.h4
-rw-r--r--include/linux/ioprio.h88
-rw-r--r--include/linux/irq.h5
-rw-r--r--include/linux/joystick.h33
-rw-r--r--include/linux/kprobes.h30
-rw-r--r--include/linux/libps2.h1
-rw-r--r--include/linux/mod_devicetable.h46
-rw-r--r--include/linux/netlink.h1
-rw-r--r--include/linux/pci.h33
-rw-r--r--include/linux/pci_ids.h9
-rw-r--r--include/linux/pkt_cls.h1
-rw-r--r--include/linux/pkt_sched.h9
-rw-r--r--include/linux/pmu.h6
-rw-r--r--include/linux/rtnetlink.h10
-rw-r--r--include/linux/sched.h6
-rw-r--r--include/linux/seccomp.h10
-rw-r--r--include/linux/serial_8250.h1
-rw-r--r--include/linux/serio.h6
-rw-r--r--include/linux/sysctl.h1
-rw-r--r--include/linux/usb_ch9.h189
-rw-r--r--include/linux/usb_gadget.h2
-rw-r--r--include/linux/usb_isp116x.h47
-rw-r--r--include/linux/videodev2.h2
-rw-r--r--include/linux/writeback.h8
-rw-r--r--include/linux/xattr_acl.h50
-rw-r--r--include/media/tuner.h20
-rw-r--r--include/net/ieee80211.h856
-rw-r--r--include/net/ipv6.h1
-rw-r--r--include/net/sctp/constants.h18
-rw-r--r--include/net/sctp/structs.h4
-rw-r--r--include/pcmcia/ciscode.h2
-rw-r--r--include/pcmcia/cs.h2
-rw-r--r--include/pcmcia/device_id.h249
-rw-r--r--include/pcmcia/ds.h9
-rw-r--r--include/pcmcia/ss.h34
-rw-r--r--init/main.c7
-rw-r--r--kernel/exit.c2
-rw-r--r--kernel/fork.c5
-rw-r--r--kernel/irq/autoprobe.c9
-rw-r--r--kernel/irq/handle.c2
-rw-r--r--kernel/irq/spurious.c113
-rw-r--r--kernel/itimer.c8
-rw-r--r--kernel/kexec.c10
-rw-r--r--kernel/kprobes.c170
-rw-r--r--kernel/sched.c17
-rw-r--r--mm/page-writeback.c2
-rw-r--r--mm/page_alloc.c3
-rw-r--r--mm/vmscan.c2
-rw-r--r--net/bridge/br_netfilter.c2
-rw-r--r--net/bridge/netfilter/ebt_log.c6
-rw-r--r--net/core/neighbour.c6
-rw-r--r--net/core/pktgen.c29
-rw-r--r--net/core/rtnetlink.c2
-rw-r--r--net/core/wireless.c1
-rw-r--r--net/ethernet/eth.c7
-rw-r--r--net/ipv4/Kconfig3
-rw-r--r--net/ipv4/fib_trie.c56
-rw-r--r--net/ipv4/ip_input.c6
-rw-r--r--net/ipv4/ip_output.c8
-rw-r--r--net/ipv4/ipconfig.c4
-rw-r--r--net/ipv4/ipmr.c10
-rw-r--r--net/ipv4/ipvs/ip_vs_conn.c25
-rw-r--r--net/ipv4/ipvs/ip_vs_ctl.c8
-rw-r--r--net/ipv4/ipvs/ip_vs_sync.c4
-rw-r--r--net/ipv4/netfilter/ipt_CLUSTERIP.c7
-rw-r--r--net/ipv4/route.c9
-rw-r--r--net/ipv6/addrconf.c19
-rw-r--r--net/ipv6/ip6_flowlabel.c1
-rw-r--r--net/netlink/af_netlink.c11
-rw-r--r--net/sched/act_api.c10
-rw-r--r--net/sched/cls_api.c2
-rw-r--r--net/sched/cls_rsvp.h1
-rw-r--r--net/sched/sch_api.c2
-rw-r--r--net/sched/sch_cbq.c3
-rw-r--r--net/sctp/endpointola.c13
-rw-r--r--net/sctp/protocol.c5
-rw-r--r--net/sctp/sysctl.c13
-rw-r--r--net/sctp/transport.c1
-rw-r--r--scripts/mod/file2alias.c39
-rw-r--r--sound/oss/Kconfig2
-rw-r--r--sound/oss/dmasound/dmasound_awacs.c14
-rw-r--r--sound/oss/es1370.c88
-rw-r--r--sound/oss/es1371.c95
-rw-r--r--sound/oss/esssolo1.c26
-rw-r--r--sound/oss/mad16.c30
-rw-r--r--sound/oss/sonicvibes.c25
-rw-r--r--sound/oss/trident.c37
-rw-r--r--sound/oss/via82cxxx_audio.c5
-rw-r--r--sound/pci/cs4281.c5
-rw-r--r--sound/pcmcia/pdaudiocf/pdaudiocf.c9
-rw-r--r--sound/pcmcia/vx/vxpocket.c20
-rw-r--r--sound/ppc/awacs.c8
-rw-r--r--sound/ppc/daca.c6
-rw-r--r--sound/ppc/pmac.c11
-rw-r--r--sound/ppc/pmac.h2
-rw-r--r--sound/ppc/tumbler.c4
793 files changed, 30990 insertions, 24874 deletions
diff --git a/Documentation/Changes b/Documentation/Changes
index b37600754762..afebdbcd553a 100644
--- a/Documentation/Changes
+++ b/Documentation/Changes
@@ -44,9 +44,9 @@ running, the suggested command should tell you.
44 44
45Again, keep in mind that this list assumes you are already 45Again, keep in mind that this list assumes you are already
46functionally running a Linux 2.4 kernel. Also, not all tools are 46functionally running a Linux 2.4 kernel. Also, not all tools are
47necessary on all systems; obviously, if you don't have any PCMCIA (PC 47necessary on all systems; obviously, if you don't have any ISDN
48Card) hardware, for example, you probably needn't concern yourself 48hardware, for example, you probably needn't concern yourself with
49with pcmcia-cs. 49isdn4k-utils.
50 50
51o Gnu C 2.95.3 # gcc --version 51o Gnu C 2.95.3 # gcc --version
52o Gnu make 3.79.1 # make --version 52o Gnu make 3.79.1 # make --version
@@ -57,6 +57,7 @@ o e2fsprogs 1.29 # tune2fs
57o jfsutils 1.1.3 # fsck.jfs -V 57o jfsutils 1.1.3 # fsck.jfs -V
58o reiserfsprogs 3.6.3 # reiserfsck -V 2>&1|grep reiserfsprogs 58o reiserfsprogs 3.6.3 # reiserfsck -V 2>&1|grep reiserfsprogs
59o xfsprogs 2.6.0 # xfs_db -V 59o xfsprogs 2.6.0 # xfs_db -V
60o pcmciautils 001
60o pcmcia-cs 3.1.21 # cardmgr -V 61o pcmcia-cs 3.1.21 # cardmgr -V
61o quota-tools 3.09 # quota -V 62o quota-tools 3.09 # quota -V
62o PPP 2.4.0 # pppd --version 63o PPP 2.4.0 # pppd --version
@@ -186,13 +187,20 @@ architecture independent and any version from 2.0.0 onward should
186work correctly with this version of the XFS kernel code (2.6.0 or 187work correctly with this version of the XFS kernel code (2.6.0 or
187later is recommended, due to some significant improvements). 188later is recommended, due to some significant improvements).
188 189
190PCMCIAutils
191-----------
192
193PCMCIAutils replaces pcmcia-cs (see below). It properly sets up
194PCMCIA sockets at system startup and loads the appropriate modules
195for 16-bit PCMCIA devices if the kernel is modularized and the hotplug
196subsystem is used.
189 197
190Pcmcia-cs 198Pcmcia-cs
191--------- 199---------
192 200
193PCMCIA (PC Card) support is now partially implemented in the main 201PCMCIA (PC Card) support is now partially implemented in the main
194kernel source. Pay attention when you recompile your kernel ;-). 202kernel source. The "pcmciautils" package (see above) replaces pcmcia-cs
195Also, be sure to upgrade to the latest pcmcia-cs release. 203for newest kernels.
196 204
197Quota-tools 205Quota-tools
198----------- 206-----------
@@ -349,9 +357,13 @@ Xfsprogs
349-------- 357--------
350o <ftp://oss.sgi.com/projects/xfs/download/> 358o <ftp://oss.sgi.com/projects/xfs/download/>
351 359
360Pcmciautils
361-----------
362o <ftp://ftp.kernel.org/pub/linux/utils/kernel/pcmcia/>
363
352Pcmcia-cs 364Pcmcia-cs
353--------- 365---------
354o <ftp://pcmcia-cs.sourceforge.net/pub/pcmcia-cs/pcmcia-cs-3.1.21.tar.gz> 366o <http://pcmcia-cs.sourceforge.net/>
355 367
356Quota-tools 368Quota-tools
357---------- 369----------
diff --git a/Documentation/DocBook/libata.tmpl b/Documentation/DocBook/libata.tmpl
index 6df1dfd18b65..375ae760dc1e 100644
--- a/Documentation/DocBook/libata.tmpl
+++ b/Documentation/DocBook/libata.tmpl
@@ -84,6 +84,14 @@ void (*port_disable) (struct ata_port *);
84 Called from ata_bus_probe() and ata_bus_reset() error paths, 84 Called from ata_bus_probe() and ata_bus_reset() error paths,
85 as well as when unregistering from the SCSI module (rmmod, hot 85 as well as when unregistering from the SCSI module (rmmod, hot
86 unplug). 86 unplug).
87 This function should do whatever needs to be done to take the
88 port out of use. In most cases, ata_port_disable() can be used
89 as this hook.
90 </para>
91 <para>
92 Called from ata_bus_probe() on a failed probe.
93 Called from ata_bus_reset() on a failed bus reset.
94 Called from ata_scsi_release().
87 </para> 95 </para>
88 96
89 </sect2> 97 </sect2>
@@ -98,6 +106,13 @@ void (*dev_config) (struct ata_port *, struct ata_device *);
98 found. Typically used to apply device-specific fixups prior to 106 found. Typically used to apply device-specific fixups prior to
99 issue of SET FEATURES - XFER MODE, and prior to operation. 107 issue of SET FEATURES - XFER MODE, and prior to operation.
100 </para> 108 </para>
109 <para>
110 Called by ata_device_add() after ata_dev_identify() determines
111 a device is present.
112 </para>
113 <para>
114 This entry may be specified as NULL in ata_port_operations.
115 </para>
101 116
102 </sect2> 117 </sect2>
103 118
@@ -135,6 +150,8 @@ void (*tf_read) (struct ata_port *ap, struct ata_taskfile *tf);
135 registers / DMA buffers. ->tf_read() is called to read the 150 registers / DMA buffers. ->tf_read() is called to read the
136 hardware registers / DMA buffers, to obtain the current set of 151 hardware registers / DMA buffers, to obtain the current set of
137 taskfile register values. 152 taskfile register values.
153 Most drivers for taskfile-based hardware (PIO or MMIO) use
154 ata_tf_load() and ata_tf_read() for these hooks.
138 </para> 155 </para>
139 156
140 </sect2> 157 </sect2>
@@ -147,6 +164,8 @@ void (*exec_command)(struct ata_port *ap, struct ata_taskfile *tf);
147 <para> 164 <para>
148 causes an ATA command, previously loaded with 165 causes an ATA command, previously loaded with
149 ->tf_load(), to be initiated in hardware. 166 ->tf_load(), to be initiated in hardware.
167 Most drivers for taskfile-based hardware use ata_exec_command()
168 for this hook.
150 </para> 169 </para>
151 170
152 </sect2> 171 </sect2>
@@ -161,6 +180,10 @@ Allow low-level driver to filter ATA PACKET commands, returning a status
161indicating whether or not it is OK to use DMA for the supplied PACKET 180indicating whether or not it is OK to use DMA for the supplied PACKET
162command. 181command.
163 </para> 182 </para>
183 <para>
184 This hook may be specified as NULL, in which case libata will
185 assume that atapi dma can be supported.
186 </para>
164 187
165 </sect2> 188 </sect2>
166 189
@@ -175,6 +198,14 @@ u8 (*check_err)(struct ata_port *ap);
175 Reads the Status/AltStatus/Error ATA shadow register from 198 Reads the Status/AltStatus/Error ATA shadow register from
176 hardware. On some hardware, reading the Status register has 199 hardware. On some hardware, reading the Status register has
177 the side effect of clearing the interrupt condition. 200 the side effect of clearing the interrupt condition.
201 Most drivers for taskfile-based hardware use
202 ata_check_status() for this hook.
203 </para>
204 <para>
205 Note that because this is called from ata_device_add(), at
206 least a dummy function that clears device interrupts must be
207 provided for all drivers, even if the controller doesn't
208 actually have a taskfile status register.
178 </para> 209 </para>
179 210
180 </sect2> 211 </sect2>
@@ -188,7 +219,13 @@ void (*dev_select)(struct ata_port *ap, unsigned int device);
188 Issues the low-level hardware command(s) that causes one of N 219 Issues the low-level hardware command(s) that causes one of N
189 hardware devices to be considered 'selected' (active and 220 hardware devices to be considered 'selected' (active and
190 available for use) on the ATA bus. This generally has no 221 available for use) on the ATA bus. This generally has no
191meaning on FIS-based devices. 222 meaning on FIS-based devices.
223 </para>
224 <para>
225 Most drivers for taskfile-based hardware use
226 ata_std_dev_select() for this hook. Controllers which do not
227 support second drives on a port (such as SATA contollers) will
228 use ata_noop_dev_select().
192 </para> 229 </para>
193 230
194 </sect2> 231 </sect2>
@@ -204,6 +241,8 @@ void (*phy_reset) (struct ata_port *ap);
204 for device presence (PATA and SATA), typically a soft reset 241 for device presence (PATA and SATA), typically a soft reset
205 (SRST) will be performed. Drivers typically use the helper 242 (SRST) will be performed. Drivers typically use the helper
206 functions ata_bus_reset() or sata_phy_reset() for this hook. 243 functions ata_bus_reset() or sata_phy_reset() for this hook.
244 Many SATA drivers use sata_phy_reset() or call it from within
245 their own phy_reset() functions.
207 </para> 246 </para>
208 247
209 </sect2> 248 </sect2>
@@ -227,6 +266,25 @@ PCI IDE DMA Status register.
227These hooks are typically either no-ops, or simply not implemented, in 266These hooks are typically either no-ops, or simply not implemented, in
228FIS-based drivers. 267FIS-based drivers.
229 </para> 268 </para>
269 <para>
270Most legacy IDE drivers use ata_bmdma_setup() for the bmdma_setup()
271hook. ata_bmdma_setup() will write the pointer to the PRD table to
272the IDE PRD Table Address register, enable DMA in the DMA Command
273register, and call exec_command() to begin the transfer.
274 </para>
275 <para>
276Most legacy IDE drivers use ata_bmdma_start() for the bmdma_start()
277hook. ata_bmdma_start() will write the ATA_DMA_START flag to the DMA
278Command register.
279 </para>
280 <para>
281Many legacy IDE drivers use ata_bmdma_stop() for the bmdma_stop()
282hook. ata_bmdma_stop() clears the ATA_DMA_START flag in the DMA
283command register.
284 </para>
285 <para>
286Many legacy IDE drivers use ata_bmdma_status() as the bmdma_status() hook.
287 </para>
230 288
231 </sect2> 289 </sect2>
232 290
@@ -250,6 +308,10 @@ int (*qc_issue) (struct ata_queued_cmd *qc);
250 helper function ata_qc_issue_prot() for taskfile protocol-based 308 helper function ata_qc_issue_prot() for taskfile protocol-based
251 dispatch. More advanced drivers implement their own ->qc_issue. 309 dispatch. More advanced drivers implement their own ->qc_issue.
252 </para> 310 </para>
311 <para>
312 ata_qc_issue_prot() calls ->tf_load(), ->bmdma_setup(), and
313 ->bmdma_start() as necessary to initiate a transfer.
314 </para>
253 315
254 </sect2> 316 </sect2>
255 317
@@ -279,6 +341,21 @@ void (*irq_clear) (struct ata_port *);
279 before the interrupt handler is registered, to be sure hardware 341 before the interrupt handler is registered, to be sure hardware
280 is quiet. 342 is quiet.
281 </para> 343 </para>
344 <para>
345 The second argument, dev_instance, should be cast to a pointer
346 to struct ata_host_set.
347 </para>
348 <para>
349 Most legacy IDE drivers use ata_interrupt() for the
350 irq_handler hook, which scans all ports in the host_set,
351 determines which queued command was active (if any), and calls
352 ata_host_intr(ap,qc).
353 </para>
354 <para>
355 Most legacy IDE drivers use ata_bmdma_irq_clear() for the
356 irq_clear() hook, which simply clears the interrupt and error
357 flags in the DMA status register.
358 </para>
282 359
283 </sect2> 360 </sect2>
284 361
@@ -292,6 +369,7 @@ void (*scr_write) (struct ata_port *ap, unsigned int sc_reg,
292 <para> 369 <para>
293 Read and write standard SATA phy registers. Currently only used 370 Read and write standard SATA phy registers. Currently only used
294 if ->phy_reset hook called the sata_phy_reset() helper function. 371 if ->phy_reset hook called the sata_phy_reset() helper function.
372 sc_reg is one of SCR_STATUS, SCR_CONTROL, SCR_ERROR, or SCR_ACTIVE.
295 </para> 373 </para>
296 374
297 </sect2> 375 </sect2>
@@ -307,17 +385,29 @@ void (*host_stop) (struct ata_host_set *host_set);
307 ->port_start() is called just after the data structures for each 385 ->port_start() is called just after the data structures for each
308 port are initialized. Typically this is used to alloc per-port 386 port are initialized. Typically this is used to alloc per-port
309 DMA buffers / tables / rings, enable DMA engines, and similar 387 DMA buffers / tables / rings, enable DMA engines, and similar
310 tasks. 388 tasks. Some drivers also use this entry point as a chance to
389 allocate driver-private memory for ap->private_data.
390 </para>
391 <para>
392 Many drivers use ata_port_start() as this hook or call
393 it from their own port_start() hooks. ata_port_start()
394 allocates space for a legacy IDE PRD table and returns.
311 </para> 395 </para>
312 <para> 396 <para>
313 ->port_stop() is called after ->host_stop(). It's sole function 397 ->port_stop() is called after ->host_stop(). It's sole function
314 is to release DMA/memory resources, now that they are no longer 398 is to release DMA/memory resources, now that they are no longer
315 actively being used. 399 actively being used. Many drivers also free driver-private
400 data from port at this time.
401 </para>
402 <para>
403 Many drivers use ata_port_stop() as this hook, which frees the
404 PRD table.
316 </para> 405 </para>
317 <para> 406 <para>
318 ->host_stop() is called after all ->port_stop() calls 407 ->host_stop() is called after all ->port_stop() calls
319have completed. The hook must finalize hardware shutdown, release DMA 408have completed. The hook must finalize hardware shutdown, release DMA
320and other resources, etc. 409and other resources, etc.
410 This hook may be specified as NULL, in which case it is not called.
321 </para> 411 </para>
322 412
323 </sect2> 413 </sect2>
diff --git a/Documentation/SubmittingDrivers b/Documentation/SubmittingDrivers
index de3b252e717d..c3cca924e94b 100644
--- a/Documentation/SubmittingDrivers
+++ b/Documentation/SubmittingDrivers
@@ -13,13 +13,14 @@ Allocating Device Numbers
13------------------------- 13-------------------------
14 14
15Major and minor numbers for block and character devices are allocated 15Major and minor numbers for block and character devices are allocated
16by the Linux assigned name and number authority (currently better 16by the Linux assigned name and number authority (currently this is
17known as H Peter Anvin). The site is http://www.lanana.org/. This 17Torben Mathiasen). The site is http://www.lanana.org/. This
18also deals with allocating numbers for devices that are not going to 18also deals with allocating numbers for devices that are not going to
19be submitted to the mainstream kernel. 19be submitted to the mainstream kernel.
20See Documentation/devices.txt for more information on this.
20 21
21If you don't use assigned numbers then when you device is submitted it will 22If you don't use assigned numbers then when your device is submitted it will
22get given an assigned number even if that is different from values you may 23be given an assigned number even if that is different from values you may
23have shipped to customers before. 24have shipped to customers before.
24 25
25Who To Submit Drivers To 26Who To Submit Drivers To
@@ -32,7 +33,8 @@ Linux 2.2:
32 If the code area has a general maintainer then please submit it to 33 If the code area has a general maintainer then please submit it to
33 the maintainer listed in MAINTAINERS in the kernel file. If the 34 the maintainer listed in MAINTAINERS in the kernel file. If the
34 maintainer does not respond or you cannot find the appropriate 35 maintainer does not respond or you cannot find the appropriate
35 maintainer then please contact Alan Cox <alan@lxorguk.ukuu.org.uk> 36 maintainer then please contact the 2.2 kernel maintainer:
37 Marc-Christian Petersen <m.c.p@wolk-project.de>.
36 38
37Linux 2.4: 39Linux 2.4:
38 The same rules apply as 2.2. The final contact point for Linux 2.4 40 The same rules apply as 2.2. The final contact point for Linux 2.4
@@ -48,7 +50,7 @@ What Criteria Determine Acceptance
48 50
49Licensing: The code must be released to us under the 51Licensing: The code must be released to us under the
50 GNU General Public License. We don't insist on any kind 52 GNU General Public License. We don't insist on any kind
51 of exclusively GPL licensing, and if you wish the driver 53 of exclusive GPL licensing, and if you wish the driver
52 to be useful to other communities such as BSD you may well 54 to be useful to other communities such as BSD you may well
53 wish to release under multiple licenses. 55 wish to release under multiple licenses.
54 56
diff --git a/Documentation/SubmittingPatches b/Documentation/SubmittingPatches
index 4d1f41b84ebc..6761a7b241a5 100644
--- a/Documentation/SubmittingPatches
+++ b/Documentation/SubmittingPatches
@@ -35,7 +35,7 @@ not in any lower subdirectory.
35 35
36To create a patch for a single file, it is often sufficient to do: 36To create a patch for a single file, it is often sufficient to do:
37 37
38 SRCTREE= linux-2.4 38 SRCTREE= linux-2.6
39 MYFILE= drivers/net/mydriver.c 39 MYFILE= drivers/net/mydriver.c
40 40
41 cd $SRCTREE 41 cd $SRCTREE
@@ -48,17 +48,18 @@ To create a patch for multiple files, you should unpack a "vanilla",
48or unmodified kernel source tree, and generate a diff against your 48or unmodified kernel source tree, and generate a diff against your
49own source tree. For example: 49own source tree. For example:
50 50
51 MYSRC= /devel/linux-2.4 51 MYSRC= /devel/linux-2.6
52 52
53 tar xvfz linux-2.4.0-test11.tar.gz 53 tar xvfz linux-2.6.12.tar.gz
54 mv linux linux-vanilla 54 mv linux-2.6.12 linux-2.6.12-vanilla
55 wget http://www.moses.uklinux.net/patches/dontdiff 55 diff -uprN -X linux-2.6.12-vanilla/Documentation/dontdiff \
56 diff -uprN -X dontdiff linux-vanilla $MYSRC > /tmp/patch 56 linux-2.6.12-vanilla $MYSRC > /tmp/patch
57 rm -f dontdiff
58 57
59"dontdiff" is a list of files which are generated by the kernel during 58"dontdiff" is a list of files which are generated by the kernel during
60the build process, and should be ignored in any diff(1)-generated 59the build process, and should be ignored in any diff(1)-generated
61patch. dontdiff is maintained by Tigran Aivazian <tigran@veritas.com> 60patch. The "dontdiff" file is included in the kernel tree in
612.6.12 and later. For earlier kernel versions, you can get it
62from <http://www.xenotime.net/linux/doc/dontdiff>.
62 63
63Make sure your patch does not include any extra files which do not 64Make sure your patch does not include any extra files which do not
64belong in a patch submission. Make sure to review your patch -after- 65belong in a patch submission. Make sure to review your patch -after-
@@ -66,18 +67,20 @@ generated it with diff(1), to ensure accuracy.
66 67
67If your changes produce a lot of deltas, you may want to look into 68If your changes produce a lot of deltas, you may want to look into
68splitting them into individual patches which modify things in 69splitting them into individual patches which modify things in
69logical stages, this will facilitate easier reviewing by other 70logical stages. This will facilitate easier reviewing by other
70kernel developers, very important if you want your patch accepted. 71kernel developers, very important if you want your patch accepted.
71There are a number of scripts which can aid in this; 72There are a number of scripts which can aid in this:
72 73
73Quilt: 74Quilt:
74http://savannah.nongnu.org/projects/quilt 75http://savannah.nongnu.org/projects/quilt
75 76
76Randy Dunlap's patch scripts: 77Randy Dunlap's patch scripts:
77http://developer.osdl.org/rddunlap/scripts/patching-scripts.tgz 78http://www.xenotime.net/linux/scripts/patching-scripts-002.tar.gz
78 79
79Andrew Morton's patch scripts: 80Andrew Morton's patch scripts:
80http://www.zip.com.au/~akpm/linux/patches/patch-scripts-0.16 81http://www.zip.com.au/~akpm/linux/patches/patch-scripts-0.20
82
83
81 84
822) Describe your changes. 852) Describe your changes.
83 86
@@ -163,6 +166,8 @@ patches. Trivial patches must qualify for one of the following rules:
163 since people copy, as long as it's trivial) 166 since people copy, as long as it's trivial)
164 Any fix by the author/maintainer of the file. (ie. patch monkey 167 Any fix by the author/maintainer of the file. (ie. patch monkey
165 in re-transmission mode) 168 in re-transmission mode)
169URL: <http://www.kernel.org/pub/linux/kernel/people/rusty/trivial/>
170
166 171
167 172
168 173
@@ -291,6 +296,17 @@ now, but you can do this to mark internal company procedures or just
291point out some special detail about the sign-off. 296point out some special detail about the sign-off.
292 297
293 298
299
30012) More references for submitting patches
301
302Andrew Morton, "The perfect patch" (tpp).
303 <http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt>
304
305Jeff Garzik, "Linux kernel patch submission format."
306 <http://linux.yyz.us/patch-format.html>
307
308
309
294----------------------------------- 310-----------------------------------
295SECTION 2 - HINTS, TIPS, AND TRICKS 311SECTION 2 - HINTS, TIPS, AND TRICKS
296----------------------------------- 312-----------------------------------
@@ -359,7 +375,5 @@ and 'extern __inline__'.
3594) Don't over-design. 3754) Don't over-design.
360 376
361Don't try to anticipate nebulous future cases which may or may not 377Don't try to anticipate nebulous future cases which may or may not
362be useful: "Make it as simple as you can, and no simpler" 378be useful: "Make it as simple as you can, and no simpler."
363
364
365 379
diff --git a/Documentation/block/ioprio.txt b/Documentation/block/ioprio.txt
new file mode 100644
index 000000000000..96ccf681075e
--- /dev/null
+++ b/Documentation/block/ioprio.txt
@@ -0,0 +1,176 @@
1Block io priorities
2===================
3
4
5Intro
6-----
7
8With the introduction of cfq v3 (aka cfq-ts or time sliced cfq), basic io
9priorities is supported for reads on files. This enables users to io nice
10processes or process groups, similar to what has been possible to cpu
11scheduling for ages. This document mainly details the current possibilites
12with cfq, other io schedulers do not support io priorities so far.
13
14Scheduling classes
15------------------
16
17CFQ implements three generic scheduling classes that determine how io is
18served for a process.
19
20IOPRIO_CLASS_RT: This is the realtime io class. This scheduling class is given
21higher priority than any other in the system, processes from this class are
22given first access to the disk every time. Thus it needs to be used with some
23care, one io RT process can starve the entire system. Within the RT class,
24there are 8 levels of class data that determine exactly how much time this
25process needs the disk for on each service. In the future this might change
26to be more directly mappable to performance, by passing in a wanted data
27rate instead.
28
29IOPRIO_CLASS_BE: This is the best-effort scheduling class, which is the default
30for any process that hasn't set a specific io priority. The class data
31determines how much io bandwidth the process will get, it's directly mappable
32to the cpu nice levels just more coarsely implemented. 0 is the highest
33BE prio level, 7 is the lowest. The mapping between cpu nice level and io
34nice level is determined as: io_nice = (cpu_nice + 20) / 5.
35
36IOPRIO_CLASS_IDLE: This is the idle scheduling class, processes running at this
37level only get io time when no one else needs the disk. The idle class has no
38class data, since it doesn't really apply here.
39
40Tools
41-----
42
43See below for a sample ionice tool. Usage:
44
45# ionice -c<class> -n<level> -p<pid>
46
47If pid isn't given, the current process is assumed. IO priority settings
48are inherited on fork, so you can use ionice to start the process at a given
49level:
50
51# ionice -c2 -n0 /bin/ls
52
53will run ls at the best-effort scheduling class at the highest priority.
54For a running process, you can give the pid instead:
55
56# ionice -c1 -n2 -p100
57
58will change pid 100 to run at the realtime scheduling class, at priority 2.
59
60---> snip ionice.c tool <---
61
62#include <stdio.h>
63#include <stdlib.h>
64#include <errno.h>
65#include <getopt.h>
66#include <unistd.h>
67#include <sys/ptrace.h>
68#include <asm/unistd.h>
69
70extern int sys_ioprio_set(int, int, int);
71extern int sys_ioprio_get(int, int);
72
73#if defined(__i386__)
74#define __NR_ioprio_set 289
75#define __NR_ioprio_get 290
76#elif defined(__ppc__)
77#define __NR_ioprio_set 273
78#define __NR_ioprio_get 274
79#elif defined(__x86_64__)
80#define __NR_ioprio_set 251
81#define __NR_ioprio_get 252
82#elif defined(__ia64__)
83#define __NR_ioprio_set 1274
84#define __NR_ioprio_get 1275
85#else
86#error "Unsupported arch"
87#endif
88
89_syscall3(int, ioprio_set, int, which, int, who, int, ioprio);
90_syscall2(int, ioprio_get, int, which, int, who);
91
92enum {
93 IOPRIO_CLASS_NONE,
94 IOPRIO_CLASS_RT,
95 IOPRIO_CLASS_BE,
96 IOPRIO_CLASS_IDLE,
97};
98
99enum {
100 IOPRIO_WHO_PROCESS = 1,
101 IOPRIO_WHO_PGRP,
102 IOPRIO_WHO_USER,
103};
104
105#define IOPRIO_CLASS_SHIFT 13
106
107const char *to_prio[] = { "none", "realtime", "best-effort", "idle", };
108
109int main(int argc, char *argv[])
110{
111 int ioprio = 4, set = 0, ioprio_class = IOPRIO_CLASS_BE;
112 int c, pid = 0;
113
114 while ((c = getopt(argc, argv, "+n:c:p:")) != EOF) {
115 switch (c) {
116 case 'n':
117 ioprio = strtol(optarg, NULL, 10);
118 set = 1;
119 break;
120 case 'c':
121 ioprio_class = strtol(optarg, NULL, 10);
122 set = 1;
123 break;
124 case 'p':
125 pid = strtol(optarg, NULL, 10);
126 break;
127 }
128 }
129
130 switch (ioprio_class) {
131 case IOPRIO_CLASS_NONE:
132 ioprio_class = IOPRIO_CLASS_BE;
133 break;
134 case IOPRIO_CLASS_RT:
135 case IOPRIO_CLASS_BE:
136 break;
137 case IOPRIO_CLASS_IDLE:
138 ioprio = 7;
139 break;
140 default:
141 printf("bad prio class %d\n", ioprio_class);
142 return 1;
143 }
144
145 if (!set) {
146 if (!pid && argv[optind])
147 pid = strtol(argv[optind], NULL, 10);
148
149 ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid);
150
151 printf("pid=%d, %d\n", pid, ioprio);
152
153 if (ioprio == -1)
154 perror("ioprio_get");
155 else {
156 ioprio_class = ioprio >> IOPRIO_CLASS_SHIFT;
157 ioprio = ioprio & 0xff;
158 printf("%s: prio %d\n", to_prio[ioprio_class], ioprio);
159 }
160 } else {
161 if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << IOPRIO_CLASS_SHIFT) == -1) {
162 perror("ioprio_set");
163 return 1;
164 }
165
166 if (argv[optind])
167 execvp(argv[optind], &argv[optind]);
168 }
169
170 return 0;
171}
172
173---> snip ionice.c tool <---
174
175
176March 11 2005, Jens Axboe <axboe@suse.de>
diff --git a/Documentation/cciss.txt b/Documentation/cciss.txt
index d599beb9df8a..c8f9a73111da 100644
--- a/Documentation/cciss.txt
+++ b/Documentation/cciss.txt
@@ -17,6 +17,7 @@ This driver is known to work with the following cards:
17 * SA P600 17 * SA P600
18 * SA P800 18 * SA P800
19 * SA E400 19 * SA E400
20 * SA E300
20 21
21If nodes are not already created in the /dev/cciss directory, run as root: 22If nodes are not already created in the /dev/cciss directory, run as root:
22 23
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index f44bb5567c5b..4ec75c06bca4 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -622,6 +622,17 @@ running once the system is up.
622 ips= [HW,SCSI] Adaptec / IBM ServeRAID controller 622 ips= [HW,SCSI] Adaptec / IBM ServeRAID controller
623 See header of drivers/scsi/ips.c. 623 See header of drivers/scsi/ips.c.
624 624
625 irqfixup [HW]
626 When an interrupt is not handled search all handlers
627 for it. Intended to get systems with badly broken
628 firmware running.
629
630 irqpoll [HW]
631 When an interrupt is not handled search all handlers
632 for it. Also check all handlers each timer
633 interrupt. Intended to get systems with badly broken
634 firmware running.
635
625 isapnp= [ISAPNP] 636 isapnp= [ISAPNP]
626 Format: <RDP>, <reset>, <pci_scan>, <verbosity> 637 Format: <RDP>, <reset>, <pci_scan>, <verbosity>
627 638
@@ -1030,6 +1041,10 @@ running once the system is up.
1030 irqmask=0xMMMM [IA-32] Set a bit mask of IRQs allowed to be assigned 1041 irqmask=0xMMMM [IA-32] Set a bit mask of IRQs allowed to be assigned
1031 automatically to PCI devices. You can make the kernel 1042 automatically to PCI devices. You can make the kernel
1032 exclude IRQs of your ISA cards this way. 1043 exclude IRQs of your ISA cards this way.
1044 pirqaddr=0xAAAAA [IA-32] Specify the physical address
1045 of the PIRQ table (normally generated
1046 by the BIOS) if it is outside the
1047 F0000h-100000h range.
1033 lastbus=N [IA-32] Scan all buses till bus #N. Can be useful 1048 lastbus=N [IA-32] Scan all buses till bus #N. Can be useful
1034 if the kernel is unable to find your secondary buses 1049 if the kernel is unable to find your secondary buses
1035 and you want to tell it explicitly which ones they are. 1050 and you want to tell it explicitly which ones they are.
@@ -1115,7 +1130,7 @@ running once the system is up.
1115 See Documentation/ramdisk.txt. 1130 See Documentation/ramdisk.txt.
1116 1131
1117 psmouse.proto= [HW,MOUSE] Highest PS2 mouse protocol extension to 1132 psmouse.proto= [HW,MOUSE] Highest PS2 mouse protocol extension to
1118 probe for (bare|imps|exps). 1133 probe for (bare|imps|exps|lifebook|any).
1119 psmouse.rate= [HW,MOUSE] Set desired mouse report rate, in reports 1134 psmouse.rate= [HW,MOUSE] Set desired mouse report rate, in reports
1120 per second. 1135 per second.
1121 psmouse.resetafter= 1136 psmouse.resetafter=
diff --git a/Documentation/networking/dmfe.txt b/Documentation/networking/dmfe.txt
index c0e8398674ef..046363552d09 100644
--- a/Documentation/networking/dmfe.txt
+++ b/Documentation/networking/dmfe.txt
@@ -1,59 +1,65 @@
1 dmfe.c: Version 1.28 01/18/2000 1Davicom DM9102(A)/DM9132/DM9801 fast ethernet driver for Linux.
2 2
3 A Davicom DM9102(A)/DM9132/DM9801 fast ethernet driver for Linux. 3This program is free software; you can redistribute it and/or
4 Copyright (C) 1997 Sten Wang 4modify it under the terms of the GNU General Public License
5as published by the Free Software Foundation; either version 2
6of the License, or (at your option) any later version.
5 7
6 This program is free software; you can redistribute it and/or 8This program is distributed in the hope that it will be useful,
7 modify it under the terms of the GNU General Public License 9but WITHOUT ANY WARRANTY; without even the implied warranty of
8 as published by the Free Software Foundation; either version 2 10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 of the License, or (at your option) any later version. 11GNU General Public License for more details.
10 12
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 13
14This driver provides kernel support for Davicom DM9102(A)/DM9132/DM9801 ethernet cards ( CNET
1510/100 ethernet cards uses Davicom chipset too, so this driver supports CNET cards too ).If you
16didn't compile this driver as a module, it will automatically load itself on boot and print a
17line similar to :
16 18
17 A. Compiler command: 19 dmfe: Davicom DM9xxx net driver, version 1.36.4 (2002-01-17)
18 20
19 A-1: For normal single or multiple processor kernel 21If you compiled this driver as a module, you have to load it on boot.You can load it with command :
20 "gcc -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall
21 -Wstrict-prototypes -O6 -c dmfe.c"
22 22
23 A-2: For single or multiple processor with kernel module version function 23 insmod dmfe
24 "gcc -DMODULE -DMODVERSIONS -D__KERNEL__ -I/usr/src/linux/net/inet
25 -Wall -Wstrict-prototypes -O6 -c dmfe.c"
26 24
25This way it will autodetect the device mode.This is the suggested way to load the module.Or you can pass
26a mode= setting to module while loading, like :
27 27
28 B. The following steps teach you how to activate a DM9102 board: 28 insmod dmfe mode=0 # Force 10M Half Duplex
29 insmod dmfe mode=1 # Force 100M Half Duplex
30 insmod dmfe mode=4 # Force 10M Full Duplex
31 insmod dmfe mode=5 # Force 100M Full Duplex
29 32
30 1. Used the upper compiler command to compile dmfe.c 33Next you should configure your network interface with a command similar to :
31 34
32 2. Insert dmfe module into kernel 35 ifconfig eth0 172.22.3.18
33 "insmod dmfe" ;;Auto Detection Mode (Suggest) 36 ^^^^^^^^^^^
34 "insmod dmfe mode=0" ;;Force 10M Half Duplex 37 Your IP Adress
35 "insmod dmfe mode=1" ;;Force 100M Half Duplex
36 "insmod dmfe mode=4" ;;Force 10M Full Duplex
37 "insmod dmfe mode=5" ;;Force 100M Full Duplex
38 38
39 3. Config a dm9102 network interface 39Then you may have to modify the default routing table with command :
40 "ifconfig eth0 172.22.3.18"
41 ^^^^^^^^^^^ Your IP address
42 40
43 4. Activate the IP routing table. For some distributions, it is not 41 route add default eth0
44 necessary. You can type "route" to check.
45 42
46 "route add default eth0"
47 43
44Now your ethernet card should be up and running.
48 45
49 5. Well done. Your DM9102 adapter is now activated.
50 46
47TODO:
51 48
52 C. Object files description: 49Implement pci_driver::suspend() and pci_driver::resume() power management methods.
53 1. dmfe_rh61.o: For Redhat 6.1 50Check on 64 bit boxes.
51Check and fix on big endian boxes.
52Test and make sure PCI latency is now correct for all cases.
54 53
55 If you can make sure your kernel version, you can rename
56 to dmfe.o and directly use it without re-compiling.
57 54
55Authors:
58 56
59 Author: Sten Wang, 886-3-5798797-8517, E-mail: sten_wang@davicom.com.tw 57Sten Wang <sten_wang@davicom.com.tw > : Original Author
58Tobias Ringstrom <tori@unhappy.mine.nu> : Current Maintainer
59
60Contributors:
61
62Marcelo Tosatti <marcelo@conectiva.com.br>
63Alan Cox <alan@redhat.com>
64Jeff Garzik <jgarzik@pobox.com>
65Vojtech Pavlik <vojtech@suse.cz>
diff --git a/Documentation/pcmcia/devicetable.txt b/Documentation/pcmcia/devicetable.txt
new file mode 100644
index 000000000000..045511acafc9
--- /dev/null
+++ b/Documentation/pcmcia/devicetable.txt
@@ -0,0 +1,64 @@
1Matching of PCMCIA devices to drivers is done using one or more of the
2following criteria:
3
4- manufactor ID
5- card ID
6- product ID strings _and_ hashes of these strings
7- function ID
8- device function (actual and pseudo)
9
10You should use the helpers in include/pcmcia/device_id.h for generating the
11struct pcmcia_device_id[] entries which match devices to drivers.
12
13If you want to match product ID strings, you also need to pass the crc32
14hashes of the string to the macro, e.g. if you want to match the product ID
15string 1, you need to use
16
17PCMCIA_DEVICE_PROD_ID1("some_string", 0x(hash_of_some_string)),
18
19If the hash is incorrect, the kernel will inform you about this in "dmesg"
20upon module initialization, and tell you of the correct hash.
21
22You can determine the hash of the product ID strings by running
23"pcmcia-modalias %n.%m" [%n being replaced with the socket number and %m being
24replaced with the device function] from pcmciautils. It generates a string
25in the following form:
26pcmcia:m0149cC1ABf06pfn00fn00pa725B842DpbF1EFEE84pc0877B627pd00000000
27
28The hex value after "pa" is the hash of product ID string 1, after "pb" for
29string 2 and so on.
30
31Alternatively, you can use this small tool to determine the crc32 hash.
32simply pass the string you want to evaluate as argument to this program,
33e.g.
34$ ./crc32hash "Dual Speed"
35
36-------------------------------------------------------------------------
37/* crc32hash.c - derived from linux/lib/crc32.c, GNU GPL v2 */
38#include <string.h>
39#include <stdio.h>
40#include <ctype.h>
41#include <stdlib.h>
42
43unsigned int crc32(unsigned char const *p, unsigned int len)
44{
45 int i;
46 unsigned int crc = 0;
47 while (len--) {
48 crc ^= *p++;
49 for (i = 0; i < 8; i++)
50 crc = (crc >> 1) ^ ((crc & 1) ? 0xedb88320 : 0);
51 }
52 return crc;
53}
54
55int main(int argc, char **argv) {
56 unsigned int result;
57 if (argc != 2) {
58 printf("no string passed as argument\n");
59 return -1;
60 }
61 result = crc32(argv[1], strlen(argv[1]));
62 printf("0x%x\n", result);
63 return 0;
64}
diff --git a/Documentation/pcmcia/driver-changes.txt b/Documentation/pcmcia/driver-changes.txt
new file mode 100644
index 000000000000..9c315ab48a02
--- /dev/null
+++ b/Documentation/pcmcia/driver-changes.txt
@@ -0,0 +1,51 @@
1This file details changes in 2.6 which affect PCMCIA card driver authors:
2
3* in-kernel device<->driver matching
4 PCMCIA devices and their correct drivers can now be matched in
5 kernelspace. See 'devicetable.txt' for details.
6
7* Device model integration (as of 2.6.11)
8 A struct pcmcia_device is registered with the device model core,
9 and can be used (e.g. for SET_NETDEV_DEV) by using
10 handle_to_dev(client_handle_t * handle).
11
12* Convert internal I/O port addresses to unsigned long (as of 2.6.11)
13 ioaddr_t should be replaced by kio_addr_t in PCMCIA card drivers.
14
15* irq_mask and irq_list parameters (as of 2.6.11)
16 The irq_mask and irq_list parameters should no longer be used in
17 PCMCIA card drivers. Instead, it is the job of the PCMCIA core to
18 determine which IRQ should be used. Therefore, link->irq.IRQInfo2
19 is ignored.
20
21* client->PendingEvents is gone (as of 2.6.11)
22 client->PendingEvents is no longer available.
23
24* client->Attributes are gone (as of 2.6.11)
25 client->Attributes is unused, therefore it is removed from all
26 PCMCIA card drivers
27
28* core functions no longer available (as of 2.6.11)
29 The following functions have been removed from the kernel source
30 because they are unused by all in-kernel drivers, and no external
31 driver was reported to rely on them:
32 pcmcia_get_first_region()
33 pcmcia_get_next_region()
34 pcmcia_modify_window()
35 pcmcia_set_event_mask()
36 pcmcia_get_first_window()
37 pcmcia_get_next_window()
38
39* device list iteration upon module removal (as of 2.6.10)
40 It is no longer necessary to iterate on the driver's internal
41 client list and call the ->detach() function upon module removal.
42
43* Resource management. (as of 2.6.8)
44 Although the PCMCIA subsystem will allocate resources for cards,
45 it no longer marks these resources busy. This means that driver
46 authors are now responsible for claiming your resources as per
47 other drivers in Linux. You should use request_region() to mark
48 your IO regions in-use, and request_mem_region() to mark your
49 memory regions in-use. The name argument should be a pointer to
50 your driver name. Eg, for pcnet_cs, name should point to the
51 string "pcnet_cs".
diff --git a/Documentation/serial/driver b/Documentation/serial/driver
index e9c0178cd202..ac7eabbf662a 100644
--- a/Documentation/serial/driver
+++ b/Documentation/serial/driver
@@ -107,8 +107,8 @@ hardware.
107 indicate that the signal is permanently active. If RI is 107 indicate that the signal is permanently active. If RI is
108 not available, the signal should not be indicated as active. 108 not available, the signal should not be indicated as active.
109 109
110 Locking: none. 110 Locking: port->lock taken.
111 Interrupts: caller dependent. 111 Interrupts: locally disabled.
112 This call must not sleep 112 This call must not sleep
113 113
114 stop_tx(port,tty_stop) 114 stop_tx(port,tty_stop)
diff --git a/Documentation/video4linux/API.html b/Documentation/video4linux/API.html
index 4b3d8f640a4a..441407b12a9f 100644
--- a/Documentation/video4linux/API.html
+++ b/Documentation/video4linux/API.html
@@ -1,399 +1,16 @@
1<HTML><HEAD> 1<TITLE>V4L API</TITLE>
2<TITLE>Video4Linux Kernel API Reference v0.1:19990430</TITLE> 2<H1>Video For Linux APIs</H1>
3</HEAD> 3<table border=0>
4<! Revision History: > 4<tr>
5<! 4/30/1999 - Fred Gleason (fredg@wava.com)> 5<td>
6<! Documented extensions for the Radio Data System (RDS) extensions > 6<A HREF=http://www.linuxtv.org/downloads/video4linux/API/V4L1_API.html>
7<BODY bgcolor="#ffffff"> 7V4L original API</a>
8<H3>Devices</H3> 8</td><td>
9Video4Linux provides the following sets of device files. These live on the 9Obsoleted by V4L2 API
10character device formerly known as "/dev/bttv". /dev/bttv should be a 10</td></tr><tr><td>
11symlink to /dev/video0 for most people. 11<A HREF=http://www.linuxtv.org/downloads/video4linux/API/V4L2_API.html>
12<P> 12V4L2 API</a>
13<TABLE> 13</td><td>
14<TR><TH>Device Name</TH><TH>Minor Range</TH><TH>Function</TH> 14Should be used for new projects
15<TR><TD>/dev/video</TD><TD>0-63</TD><TD>Video Capture Interface</TD> 15</td></tr>
16<TR><TD>/dev/radio</TD><TD>64-127</TD><TD>AM/FM Radio Devices</TD> 16</table>
17<TR><TD>/dev/vtx</TD><TD>192-223</TD><TD>Teletext Interface Chips</TD>
18<TR><TD>/dev/vbi</TD><TD>224-239</TD><TD>Raw VBI Data (Intercast/teletext)</TD>
19</TABLE>
20<P>
21Video4Linux programs open and scan the devices to find what they are looking
22for. Capability queries define what each interface supports. The
23described API is only defined for video capture cards. The relevant subset
24applies to radio cards. Teletext interfaces talk the existing VTX API.
25<P>
26<H3>Capability Query Ioctl</H3>
27The <B>VIDIOCGCAP</B> ioctl call is used to obtain the capability
28information for a video device. The <b>struct video_capability</b> object
29passed to the ioctl is completed and returned. It contains the following
30information
31<P>
32<TABLE>
33<TR><TD><b>name[32]</b><TD>Canonical name for this interface</TD>
34<TR><TD><b>type</b><TD>Type of interface</TD>
35<TR><TD><b>channels</b><TD>Number of radio/tv channels if appropriate</TD>
36<TR><TD><b>audios</b><TD>Number of audio devices if appropriate</TD>
37<TR><TD><b>maxwidth</b><TD>Maximum capture width in pixels</TD>
38<TR><TD><b>maxheight</b><TD>Maximum capture height in pixels</TD>
39<TR><TD><b>minwidth</b><TD>Minimum capture width in pixels</TD>
40<TR><TD><b>minheight</b><TD>Minimum capture height in pixels</TD>
41</TABLE>
42<P>
43The type field lists the capability flags for the device. These are
44as follows
45<P>
46<TABLE>
47<TR><TH>Name</TH><TH>Description</TH>
48<TR><TD><b>VID_TYPE_CAPTURE</b><TD>Can capture to memory</TD>
49<TR><TD><b>VID_TYPE_TUNER</b><TD>Has a tuner of some form</TD>
50<TR><TD><b>VID_TYPE_TELETEXT</b><TD>Has teletext capability</TD>
51<TR><TD><b>VID_TYPE_OVERLAY</b><TD>Can overlay its image onto the frame buffer</TD>
52<TR><TD><b>VID_TYPE_CHROMAKEY</b><TD>Overlay is Chromakeyed</TD>
53<TR><TD><b>VID_TYPE_CLIPPING</b><TD>Overlay clipping is supported</TD>
54<TR><TD><b>VID_TYPE_FRAMERAM</b><TD>Overlay overwrites frame buffer memory</TD>
55<TR><TD><b>VID_TYPE_SCALES</b><TD>The hardware supports image scaling</TD>
56<TR><TD><b>VID_TYPE_MONOCHROME</b><TD>Image capture is grey scale only</TD>
57<TR><TD><b>VID_TYPE_SUBCAPTURE</b><TD>Capture can be of only part of the image</TD>
58</TABLE>
59<P>
60The minimum and maximum sizes listed for a capture device do not imply all
61that all height/width ratios or sizes within the range are possible. A
62request to set a size will be honoured by the largest available capture
63size whose capture is no large than the requested rectangle in either
64direction. For example the quickcam has 3 fixed settings.
65<P>
66<H3>Frame Buffer</H3>
67Capture cards that drop data directly onto the frame buffer must be told the
68base address of the frame buffer, its size and organisation. This is a
69privileged ioctl and one that eventually X itself should set.
70<P>
71The <b>VIDIOCSFBUF</b> ioctl sets the frame buffer parameters for a capture
72card. If the card does not do direct writes to the frame buffer then this
73ioctl will be unsupported. The <b>VIDIOCGFBUF</b> ioctl returns the
74currently used parameters. The structure used in both cases is a
75<b>struct video_buffer</b>.
76<P>
77<TABLE>
78<TR><TD><b>void *base</b></TD><TD>Base physical address of the buffer</TD>
79<TR><TD><b>int height</b></TD><TD>Height of the frame buffer</TD>
80<TR><TD><b>int width</b></TD><TD>Width of the frame buffer</TD>
81<TR><TD><b>int depth</b></TD><TD>Depth of the frame buffer</TD>
82<TR><TD><b>int bytesperline</b></TD><TD>Number of bytes of memory between the start of two adjacent lines</TD>
83</TABLE>
84<P>
85Note that these values reflect the physical layout of the frame buffer.
86The visible area may be smaller. In fact under XFree86 this is commonly the
87case. XFree86 DGA can provide the parameters required to set up this ioctl.
88Setting the base address to NULL indicates there is no physical frame buffer
89access.
90<P>
91<H3>Capture Windows</H3>
92The capture area is described by a <b>struct video_window</b>. This defines
93a capture area and the clipping information if relevant. The
94<b>VIDIOCGWIN</b> ioctl recovers the current settings and the
95<b>VIDIOCSWIN</b> sets new values. A successful call to <b>VIDIOCSWIN</b>
96indicates that a suitable set of parameters have been chosen. They do not
97indicate that exactly what was requested was granted. The program should
98call <b>VIDIOCGWIN</b> to check if the nearest match was suitable. The
99<b>struct video_window</b> contains the following fields.
100<P>
101<TABLE>
102<TR><TD><b>x</b><TD>The X co-ordinate specified in X windows format.</TD>
103<TR><TD><b>y</b><TD>The Y co-ordinate specified in X windows format.</TD>
104<TR><TD><b>width</b><TD>The width of the image capture.</TD>
105<TR><TD><b>height</b><TD>The height of the image capture.</TD>
106<TR><TD><b>chromakey</b><TD>A host order RGB32 value for the chroma key.</TD>
107<TR><TD><b>flags</b><TD>Additional capture flags.</TD>
108<TR><TD><b>clips</b><TD>A list of clipping rectangles. <em>(Set only)</em></TD>
109<TR><TD><b>clipcount</b><TD>The number of clipping rectangles. <em>(Set only)</em></TD>
110</TABLE>
111<P>
112Clipping rectangles are passed as an array. Each clip consists of the following
113fields available to the user.
114<P>
115<TABLE>
116<TR><TD><b>x</b></TD><TD>X co-ordinate of rectangle to skip</TD>
117<TR><TD><b>y</b></TD><TD>Y co-ordinate of rectangle to skip</TD>
118<TR><TD><b>width</b></TD><TD>Width of rectangle to skip</TD>
119<TR><TD><b>height</b></TD><TD>Height of rectangle to skip</TD>
120</TABLE>
121<P>
122Merely setting the window does not enable capturing. Overlay capturing
123(i.e. PCI-PCI transfer to the frame buffer of the video card)
124is activated by passing the <b>VIDIOCCAPTURE</b> ioctl a value of 1, and
125disabled by passing it a value of 0.
126<P>
127Some capture devices can capture a subfield of the image they actually see.
128This is indicated when VIDEO_TYPE_SUBCAPTURE is defined.
129The video_capture describes the time and special subfields to capture.
130The video_capture structure contains the following fields.
131<P>
132<TABLE>
133<TR><TD><b>x</b></TD><TD>X co-ordinate of source rectangle to grab</TD>
134<TR><TD><b>y</b></TD><TD>Y co-ordinate of source rectangle to grab</TD>
135<TR><TD><b>width</b></TD><TD>Width of source rectangle to grab</TD>
136<TR><TD><b>height</b></TD><TD>Height of source rectangle to grab</TD>
137<TR><TD><b>decimation</b></TD><TD>Decimation to apply</TD>
138<TR><TD><b>flags</b></TD><TD>Flag settings for grabbing</TD>
139</TABLE>
140The available flags are
141<P>
142<TABLE>
143<TR><TH>Name</TH><TH>Description</TH>
144<TR><TD><b>VIDEO_CAPTURE_ODD</b><TD>Capture only odd frames</TD>
145<TR><TD><b>VIDEO_CAPTURE_EVEN</b><TD>Capture only even frames</TD>
146</TABLE>
147<P>
148<H3>Video Sources</H3>
149Each video4linux video or audio device captures from one or more
150source <b>channels</b>. Each channel can be queries with the
151<b>VDIOCGCHAN</b> ioctl call. Before invoking this function the caller
152must set the channel field to the channel that is being queried. On return
153the <b>struct video_channel</b> is filled in with information about the
154nature of the channel itself.
155<P>
156The <b>VIDIOCSCHAN</b> ioctl takes an integer argument and switches the
157capture to this input. It is not defined whether parameters such as colour
158settings or tuning are maintained across a channel switch. The caller should
159maintain settings as desired for each channel. (This is reasonable as
160different video inputs may have different properties).
161<P>
162The <b>struct video_channel</b> consists of the following
163<P>
164<TABLE>
165<TR><TD><b>channel</b></TD><TD>The channel number</TD>
166<TR><TD><b>name</b></TD><TD>The input name - preferably reflecting the label
167on the card input itself</TD>
168<TR><TD><b>tuners</b></TD><TD>Number of tuners for this input</TD>
169<TR><TD><b>flags</b></TD><TD>Properties the tuner has</TD>
170<TR><TD><b>type</b></TD><TD>Input type (if known)</TD>
171<TR><TD><b>norm</b><TD>The norm for this channel</TD>
172</TABLE>
173<P>
174The flags defined are
175<P>
176<TABLE>
177<TR><TD><b>VIDEO_VC_TUNER</b><TD>Channel has tuners.</TD>
178<TR><TD><b>VIDEO_VC_AUDIO</b><TD>Channel has audio.</TD>
179<TR><TD><b>VIDEO_VC_NORM</b><TD>Channel has norm setting.</TD>
180</TABLE>
181<P>
182The types defined are
183<P>
184<TABLE>
185<TR><TD><b>VIDEO_TYPE_TV</b><TD>The input is a TV input.</TD>
186<TR><TD><b>VIDEO_TYPE_CAMERA</b><TD>The input is a camera.</TD>
187</TABLE>
188<P>
189<H3>Image Properties</H3>
190The image properties of the picture can be queried with the <b>VIDIOCGPICT</b>
191ioctl which fills in a <b>struct video_picture</b>. The <b>VIDIOCSPICT</b>
192ioctl allows values to be changed. All values except for the palette type
193are scaled between 0-65535.
194<P>
195The <b>struct video_picture</b> consists of the following fields
196<P>
197<TABLE>
198<TR><TD><b>brightness</b><TD>Picture brightness</TD>
199<TR><TD><b>hue</b><TD>Picture hue (colour only)</TD>
200<TR><TD><b>colour</b><TD>Picture colour (colour only)</TD>
201<TR><TD><b>contrast</b><TD>Picture contrast</TD>
202<TR><TD><b>whiteness</b><TD>The whiteness (greyscale only)</TD>
203<TR><TD><b>depth</b><TD>The capture depth (may need to match the frame buffer depth)</TD>
204<TR><TD><b>palette</b><TD>Reports the palette that should be used for this image</TD>
205</TABLE>
206<P>
207The following palettes are defined
208<P>
209<TABLE>
210<TR><TD><b>VIDEO_PALETTE_GREY</b><TD>Linear intensity grey scale (255 is brightest).</TD>
211<TR><TD><b>VIDEO_PALETTE_HI240</b><TD>The BT848 8bit colour cube.</TD>
212<TR><TD><b>VIDEO_PALETTE_RGB565</b><TD>RGB565 packed into 16 bit words.</TD>
213<TR><TD><b>VIDEO_PALETTE_RGB555</b><TD>RGV555 packed into 16 bit words, top bit undefined.</TD>
214<TR><TD><b>VIDEO_PALETTE_RGB24</b><TD>RGB888 packed into 24bit words.</TD>
215<TR><TD><b>VIDEO_PALETTE_RGB32</b><TD>RGB888 packed into the low 3 bytes of 32bit words. The top 8bits are undefined.</TD>
216<TR><TD><b>VIDEO_PALETTE_YUV422</b><TD>Video style YUV422 - 8bits packed 4bits Y 2bits U 2bits V</TD>
217<TR><TD><b>VIDEO_PALETTE_YUYV</b><TD>Describe me</TD>
218<TR><TD><b>VIDEO_PALETTE_UYVY</b><TD>Describe me</TD>
219<TR><TD><b>VIDEO_PALETTE_YUV420</b><TD>YUV420 capture</TD>
220<TR><TD><b>VIDEO_PALETTE_YUV411</b><TD>YUV411 capture</TD>
221<TR><TD><b>VIDEO_PALETTE_RAW</b><TD>RAW capture (BT848)</TD>
222<TR><TD><b>VIDEO_PALETTE_YUV422P</b><TD>YUV 4:2:2 Planar</TD>
223<TR><TD><b>VIDEO_PALETTE_YUV411P</b><TD>YUV 4:1:1 Planar</TD>
224</TABLE>
225<P>
226<H3>Tuning</H3>
227Each video input channel can have one or more tuners associated with it. Many
228devices will not have tuners. TV cards and radio cards will have one or more
229tuners attached.
230<P>
231Tuners are described by a <b>struct video_tuner</b> which can be obtained by
232the <b>VIDIOCGTUNER</b> ioctl. Fill in the tuner number in the structure
233then pass the structure to the ioctl to have the data filled in. The
234tuner can be switched using <b>VIDIOCSTUNER</b> which takes an integer argument
235giving the tuner to use. A struct tuner has the following fields
236<P>
237<TABLE>
238<TR><TD><b>tuner</b><TD>Number of the tuner</TD>
239<TR><TD><b>name</b><TD>Canonical name for this tuner (eg FM/AM/TV)</TD>
240<TR><TD><b>rangelow</b><TD>Lowest tunable frequency</TD>
241<TR><TD><b>rangehigh</b><TD>Highest tunable frequency</TD>
242<TR><TD><b>flags</b><TD>Flags describing the tuner</TD>
243<TR><TD><b>mode</b><TD>The video signal mode if relevant</TD>
244<TR><TD><b>signal</b><TD>Signal strength if known - between 0-65535</TD>
245</TABLE>
246<P>
247The following flags exist
248<P>
249<TABLE>
250<TR><TD><b>VIDEO_TUNER_PAL</b><TD>PAL tuning is supported</TD>
251<TR><TD><b>VIDEO_TUNER_NTSC</b><TD>NTSC tuning is supported</TD>
252<TR><TD><b>VIDEO_TUNER_SECAM</b><TD>SECAM tuning is supported</TD>
253<TR><TD><b>VIDEO_TUNER_LOW</b><TD>Frequency is in a lower range</TD>
254<TR><TD><b>VIDEO_TUNER_NORM</b><TD>The norm for this tuner is settable</TD>
255<TR><TD><b>VIDEO_TUNER_STEREO_ON</b><TD>The tuner is seeing stereo audio</TD>
256<TR><TD><b>VIDEO_TUNER_RDS_ON</b><TD>The tuner is seeing a RDS datastream</TD>
257<TR><TD><b>VIDEO_TUNER_MBS_ON</b><TD>The tuner is seeing a MBS datastream</TD>
258</TABLE>
259<P>
260The following modes are defined
261<P>
262<TABLE>
263<TR><TD><b>VIDEO_MODE_PAL</b><TD>The tuner is in PAL mode</TD>
264<TR><TD><b>VIDEO_MODE_NTSC</b><TD>The tuner is in NTSC mode</TD>
265<TR><TD><b>VIDEO_MODE_SECAM</b><TD>The tuner is in SECAM mode</TD>
266<TR><TD><b>VIDEO_MODE_AUTO</b><TD>The tuner auto switches, or mode does not apply</TD>
267</TABLE>
268<P>
269Tuning frequencies are an unsigned 32bit value in 1/16th MHz or if the
270<b>VIDEO_TUNER_LOW</b> flag is set they are in 1/16th KHz. The current
271frequency is obtained as an unsigned long via the <b>VIDIOCGFREQ</b> ioctl and
272set by the <b>VIDIOCSFREQ</b> ioctl.
273<P>
274<H3>Audio</H3>
275TV and Radio devices have one or more audio inputs that may be selected.
276The audio properties are queried by passing a <b>struct video_audio</b> to <b>VIDIOCGAUDIO</b> ioctl. The
277<b>VIDIOCSAUDIO</b> ioctl sets audio properties.
278<P>
279The structure contains the following fields
280<P>
281<TABLE>
282<TR><TD><b>audio</b><TD>The channel number</TD>
283<TR><TD><b>volume</b><TD>The volume level</TD>
284<TR><TD><b>bass</b><TD>The bass level</TD>
285<TR><TD><b>treble</b><TD>The treble level</TD>
286<TR><TD><b>flags</b><TD>Flags describing the audio channel</TD>
287<TR><TD><b>name</b><TD>Canonical name for the audio input</TD>
288<TR><TD><b>mode</b><TD>The mode the audio input is in</TD>
289<TR><TD><b>balance</b><TD>The left/right balance</TD>
290<TR><TD><b>step</b><TD>Actual step used by the hardware</TD>
291</TABLE>
292<P>
293The following flags are defined
294<P>
295<TABLE>
296<TR><TD><b>VIDEO_AUDIO_MUTE</b><TD>The audio is muted</TD>
297<TR><TD><b>VIDEO_AUDIO_MUTABLE</b><TD>Audio muting is supported</TD>
298<TR><TD><b>VIDEO_AUDIO_VOLUME</b><TD>The volume is controllable</TD>
299<TR><TD><b>VIDEO_AUDIO_BASS</b><TD>The bass is controllable</TD>
300<TR><TD><b>VIDEO_AUDIO_TREBLE</b><TD>The treble is controllable</TD>
301<TR><TD><b>VIDEO_AUDIO_BALANCE</b><TD>The balance is controllable</TD>
302</TABLE>
303<P>
304The following decoding modes are defined
305<P>
306<TABLE>
307<TR><TD><b>VIDEO_SOUND_MONO</b><TD>Mono signal</TD>
308<TR><TD><b>VIDEO_SOUND_STEREO</b><TD>Stereo signal (NICAM for TV)</TD>
309<TR><TD><b>VIDEO_SOUND_LANG1</b><TD>European TV alternate language 1</TD>
310<TR><TD><b>VIDEO_SOUND_LANG2</b><TD>European TV alternate language 2</TD>
311</TABLE>
312<P>
313<H3>Reading Images</H3>
314Each call to the <b>read</b> syscall returns the next available image
315from the device. It is up to the caller to set format and size (using
316the VIDIOCSPICT and VIDIOCSWIN ioctls) and then to pass a suitable
317size buffer and length to the function. Not all devices will support
318read operations.
319<P>
320A second way to handle image capture is via the mmap interface if supported.
321To use the mmap interface a user first sets the desired image size and depth
322properties. Next the VIDIOCGMBUF ioctl is issued. This reports the size
323of buffer to mmap and the offset within the buffer for each frame. The
324number of frames supported is device dependent and may only be one.
325<P>
326The video_mbuf structure contains the following fields
327<P>
328<TABLE>
329<TR><TD><b>size</b><TD>The number of bytes to map</TD>
330<TR><TD><b>frames</b><TD>The number of frames</TD>
331<TR><TD><b>offsets</b><TD>The offset of each frame</TD>
332</TABLE>
333<P>
334Once the mmap has been made the VIDIOCMCAPTURE ioctl starts the
335capture to a frame using the format and image size specified in the
336video_mmap (which should match or be below the initial query size).
337When the VIDIOCMCAPTURE ioctl returns the frame is <em>not</em>
338captured yet, the driver just instructed the hardware to start the
339capture. The application has to use the VIDIOCSYNC ioctl to wait
340until the capture of a frame is finished. VIDIOCSYNC takes the frame
341number you want to wait for as argument.
342<p>
343It is allowed to call VIDIOCMCAPTURE multiple times (with different
344frame numbers in video_mmap->frame of course) and thus have multiple
345outstanding capture requests. A simple way do to double-buffering
346using this feature looks like this:
347<pre>
348/* setup everything */
349VIDIOCMCAPTURE(0)
350while (whatever) {
351 VIDIOCMCAPTURE(1)
352 VIDIOCSYNC(0)
353 /* process frame 0 while the hardware captures frame 1 */
354 VIDIOCMCAPTURE(0)
355 VIDIOCSYNC(1)
356 /* process frame 1 while the hardware captures frame 0 */
357}
358</pre>
359Note that you are <em>not</em> limited to only two frames. The API
360allows up to 32 frames, the VIDIOCGMBUF ioctl returns the number of
361frames the driver granted. Thus it is possible to build deeper queues
362to avoid loosing frames on load peaks.
363<p>
364While capturing to memory the driver will make a "best effort" attempt
365to capture to screen as well if requested. This normally means all
366frames that "miss" memory mapped capture will go to the display.
367<P>
368A final ioctl exists to allow a device to obtain related devices if a
369driver has multiple components (for example video0 may not be associated
370with vbi0 which would cause an intercast display program to make a bad
371mistake). The VIDIOCGUNIT ioctl reports the unit numbers of the associated
372devices if any exist. The video_unit structure has the following fields.
373<P>
374<TABLE>
375<TR><TD><b>video</b><TD>Video capture device</TD>
376<TR><TD><b>vbi</b><TD>VBI capture device</TD>
377<TR><TD><b>radio</b><TD>Radio device</TD>
378<TR><TD><b>audio</b><TD>Audio mixer</TD>
379<TR><TD><b>teletext</b><TD>Teletext device</TD>
380</TABLE>
381<P>
382<H3>RDS Datastreams</H3>
383For radio devices that support it, it is possible to receive Radio Data
384System (RDS) data by means of a read() on the device. The data is packed in
385groups of three, as follows:
386<TABLE>
387<TR><TD>First Octet</TD><TD>Least Significant Byte of RDS Block</TD></TR>
388<TR><TD>Second Octet</TD><TD>Most Significant Byte of RDS Block
389<TR><TD>Third Octet</TD><TD>Bit 7:</TD><TD>Error bit. Indicates that
390an uncorrectable error occurred during reception of this block.</TD></TR>
391<TR><TD>&nbsp;</TD><TD>Bit 6:</TD><TD>Corrected bit. Indicates that
392an error was corrected for this data block.</TD></TR>
393<TR><TD>&nbsp;</TD><TD>Bits 5-3:</TD><TD>Received Offset. Indicates the
394offset received by the sync system.</TD></TR>
395<TR><TD>&nbsp;</TD><TD>Bits 2-0:</TD><TD>Offset Name. Indicates the
396offset applied to this data.</TD></TR>
397</TABLE>
398</BODY>
399</HTML>
diff --git a/Documentation/video4linux/CARDLIST.cx88 b/Documentation/video4linux/CARDLIST.cx88
index 216f705495cc..4377aa11f567 100644
--- a/Documentation/video4linux/CARDLIST.cx88
+++ b/Documentation/video4linux/CARDLIST.cx88
@@ -13,17 +13,17 @@ card=11 - Prolink PlayTV PVR
13card=12 - ASUS PVR-416 13card=12 - ASUS PVR-416
14card=13 - MSI TV-@nywhere 14card=13 - MSI TV-@nywhere
15card=14 - KWorld/VStream XPert DVB-T 15card=14 - KWorld/VStream XPert DVB-T
16card=15 - DVICO FusionHDTV DVB-T1 16card=15 - DViCO FusionHDTV DVB-T1
17card=16 - KWorld LTV883RF 17card=16 - KWorld LTV883RF
18card=17 - DViCO - FusionHDTV 3 Gold 18card=17 - DViCO FusionHDTV 3 Gold-Q
19card=18 - Hauppauge Nova-T DVB-T 19card=18 - Hauppauge Nova-T DVB-T
20card=19 - Conexant DVB-T reference design 20card=19 - Conexant DVB-T reference design
21card=20 - Provideo PV259 21card=20 - Provideo PV259
22card=21 - DVICO FusionHDTV DVB-T Plus 22card=21 - DViCO FusionHDTV DVB-T Plus
23card=22 - digitalnow DNTV Live! DVB-T 23card=22 - digitalnow DNTV Live! DVB-T
24card=23 - pcHDTV HD3000 HDTV 24card=23 - pcHDTV HD3000 HDTV
25card=24 - Hauppauge WinTV 28xxx (Roslyn) models 25card=24 - Hauppauge WinTV 28xxx (Roslyn) models
26card=25 - Digital-Logic MICROSPACE Entertainment Center (MEC) 26card=25 - Digital-Logic MICROSPACE Entertainment Center (MEC)
27card=26 - IODATA GV/BCTV7E 27card=26 - IODATA GV/BCTV7E
28card=27 - PixelView PlayTV Ultra Pro (Stereo) 28card=27 - PixelView PlayTV Ultra Pro (Stereo)
29card=28 - DViCO - FusionHDTV 3 Gold-T 29card=28 - DViCO FusionHDTV 3 Gold-T
diff --git a/Documentation/video4linux/CARDLIST.saa7134 b/Documentation/video4linux/CARDLIST.saa7134
index d5ed95d28500..735e8ba02d9f 100644
--- a/Documentation/video4linux/CARDLIST.saa7134
+++ b/Documentation/video4linux/CARDLIST.saa7134
@@ -54,3 +54,9 @@
54 55 -> LifeView FlyDVB-T DUO [5168:0306] 54 55 -> LifeView FlyDVB-T DUO [5168:0306]
55 56 -> Avermedia AVerTV 307 [1461:a70a] 55 56 -> Avermedia AVerTV 307 [1461:a70a]
56 57 -> Avermedia AVerTV GO 007 FM [1461:f31f] 56 57 -> Avermedia AVerTV GO 007 FM [1461:f31f]
57 58 -> ADS Tech Instant TV (saa7135) [1421:0350,1421:0370]
58 59 -> Kworld/Tevion V-Stream Xpert TV PVR7134
59 60 -> Typhoon DVB-T Duo Digital/Analog Cardbus
60 61 -> Philips TOUGH DVB-T reference design
61 62 -> Compro VideoMate TV Gold+II
62 63 -> Kworld Xpert TV PVR7134
diff --git a/Documentation/video4linux/CARDLIST.tuner b/Documentation/video4linux/CARDLIST.tuner
index aeb8df8ce890..e78020f68b2e 100644
--- a/Documentation/video4linux/CARDLIST.tuner
+++ b/Documentation/video4linux/CARDLIST.tuner
@@ -59,3 +59,6 @@ tuner=57 - Philips FQ1236A MK4
59tuner=58 - Ymec TVision TVF-8531MF 59tuner=58 - Ymec TVision TVF-8531MF
60tuner=59 - Ymec TVision TVF-5533MF 60tuner=59 - Ymec TVision TVF-5533MF
61tuner=60 - Thomson DDT 7611 (ATSC/NTSC) 61tuner=60 - Thomson DDT 7611 (ATSC/NTSC)
62tuner=61 - Tena TNF9533-D/IF
63tuner=62 - Philips TEA5767HN FM Radio
64tuner=63 - Philips FMD1216ME MK3 Hybrid Tuner
diff --git a/Documentation/video4linux/README.saa7134 b/Documentation/video4linux/README.saa7134
index 1a446c65365e..1f788e498eff 100644
--- a/Documentation/video4linux/README.saa7134
+++ b/Documentation/video4linux/README.saa7134
@@ -57,6 +57,15 @@ Cards can use either of these two crystals (xtal):
57 - 24.576MHz -> .audio_clock=0x200000 57 - 24.576MHz -> .audio_clock=0x200000
58(xtal * .audio_clock = 51539600) 58(xtal * .audio_clock = 51539600)
59 59
60Some details about 30/34/35:
61
62 - saa7130 - low-price chip, doesn't have mute, that is why all those
63 cards should have .mute field defined in their tuner structure.
64
65 - saa7134 - usual chip
66
67 - saa7133/35 - saa7135 is probably a marketing decision, since all those
68 chips identifies itself as 33 on pci.
60 69
61Credits 70Credits
62======= 71=======
diff --git a/MAINTAINERS b/MAINTAINERS
index a0b0d595d17c..19a9a1c53037 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -512,11 +512,11 @@ W: http://linuxppc64.org
512S: Supported 512S: Supported
513 513
514BTTV VIDEO4LINUX DRIVER 514BTTV VIDEO4LINUX DRIVER
515P: Gerd Knorr 515P: Mauro Carvalho Chehab
516M: kraxel@bytesex.org 516M: mchehab@brturbo.com.br
517L: video4linux-list@redhat.com 517L: video4linux-list@redhat.com
518W: http://bytesex.org/bttv/ 518W: http://linuxtv.org
519S: Orphan 519S: Maintained
520 520
521BUSLOGIC SCSI DRIVER 521BUSLOGIC SCSI DRIVER
522P: Leonard N. Zubkoff 522P: Leonard N. Zubkoff
@@ -1149,7 +1149,7 @@ S: Maintained
1149 1149
1150INFINIBAND SUBSYSTEM 1150INFINIBAND SUBSYSTEM
1151P: Roland Dreier 1151P: Roland Dreier
1152M: roland@topspin.com 1152M: rolandd@cisco.com
1153P: Sean Hefty 1153P: Sean Hefty
1154M: mshefty@ichips.intel.com 1154M: mshefty@ichips.intel.com
1155P: Hal Rosenstock 1155P: Hal Rosenstock
@@ -2625,10 +2625,11 @@ W: http://rio500.sourceforge.net
2625S: Maintained 2625S: Maintained
2626 2626
2627VIDEO FOR LINUX 2627VIDEO FOR LINUX
2628P: Gerd Knorr 2628P: Mauro Carvalho Chehab
2629M: kraxel@bytesex.org 2629M: mchehab@brturbo.com.br
2630L: video4linux-list@redhat.com 2630L: video4linux-list@redhat.com
2631S: Orphan 2631W: http://linuxtv.org
2632S: Maintained
2632 2633
2633W1 DALLAS'S 1-WIRE BUS 2634W1 DALLAS'S 1-WIRE BUS
2634P: Evgeniy Polyakov 2635P: Evgeniy Polyakov
diff --git a/Makefile b/Makefile
index 1fdace757e15..77aab7bdde01 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 2 1VERSION = 2
2PATCHLEVEL = 6 2PATCHLEVEL = 6
3SUBLEVEL = 12 3SUBLEVEL = 13
4EXTRAVERSION = 4EXTRAVERSION =-rc1
5NAME=Woozy Numbat 5NAME=Woozy Numbat
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index c8d94dcd8ef7..620f2ca94ed2 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -361,6 +361,11 @@ config NO_IDLE_HZ
361 Alternatively, if you want dynamic tick automatically enabled 361 Alternatively, if you want dynamic tick automatically enabled
362 during boot, pass "dyntick=enable" via the kernel command string. 362 during boot, pass "dyntick=enable" via the kernel command string.
363 363
364 Please note that dynamic tick may affect the accuracy of
365 timekeeping on some platforms depending on the implementation.
366 Currently at least OMAP platform is known to have accurate
367 timekeeping with dynamic tick.
368
364config ARCH_DISCONTIGMEM_ENABLE 369config ARCH_DISCONTIGMEM_ENABLE
365 bool 370 bool
366 default (ARCH_LH7A40X && !LH7A40X_CONTIGMEM) 371 default (ARCH_LH7A40X && !LH7A40X_CONTIGMEM)
diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
index 4c38bd8bc298..b713c44c6fb4 100644
--- a/arch/arm/kernel/armksyms.c
+++ b/arch/arm/kernel/armksyms.c
@@ -30,9 +30,6 @@ extern void __lshrdi3(void);
30extern void __modsi3(void); 30extern void __modsi3(void);
31extern void __muldi3(void); 31extern void __muldi3(void);
32extern void __ucmpdi2(void); 32extern void __ucmpdi2(void);
33extern void __udivdi3(void);
34extern void __umoddi3(void);
35extern void __udivmoddi4(void);
36extern void __udivsi3(void); 33extern void __udivsi3(void);
37extern void __umodsi3(void); 34extern void __umodsi3(void);
38extern void __do_div64(void); 35extern void __do_div64(void);
@@ -134,9 +131,6 @@ EXPORT_SYMBOL(__lshrdi3);
134EXPORT_SYMBOL(__modsi3); 131EXPORT_SYMBOL(__modsi3);
135EXPORT_SYMBOL(__muldi3); 132EXPORT_SYMBOL(__muldi3);
136EXPORT_SYMBOL(__ucmpdi2); 133EXPORT_SYMBOL(__ucmpdi2);
137EXPORT_SYMBOL(__udivdi3);
138EXPORT_SYMBOL(__umoddi3);
139EXPORT_SYMBOL(__udivmoddi4);
140EXPORT_SYMBOL(__udivsi3); 134EXPORT_SYMBOL(__udivsi3);
141EXPORT_SYMBOL(__umodsi3); 135EXPORT_SYMBOL(__umodsi3);
142EXPORT_SYMBOL(__do_div64); 136EXPORT_SYMBOL(__do_div64);
diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index 8f146a4b4752..bbea636ff687 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -32,6 +32,7 @@
32#include <asm/leds.h> 32#include <asm/leds.h>
33#include <asm/processor.h> 33#include <asm/processor.h>
34#include <asm/uaccess.h> 34#include <asm/uaccess.h>
35#include <asm/mach/time.h>
35 36
36extern const char *processor_modes[]; 37extern const char *processor_modes[];
37extern void setup_mm_for_reboot(char mode); 38extern void setup_mm_for_reboot(char mode);
@@ -85,8 +86,10 @@ EXPORT_SYMBOL(pm_power_off);
85void default_idle(void) 86void default_idle(void)
86{ 87{
87 local_irq_disable(); 88 local_irq_disable();
88 if (!need_resched() && !hlt_counter) 89 if (!need_resched() && !hlt_counter) {
90 timer_dyn_reprogram();
89 arch_idle(); 91 arch_idle();
92 }
90 local_irq_enable(); 93 local_irq_enable();
91} 94}
92 95
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index 8cf733daa800..35b7273cfdb4 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -359,7 +359,8 @@ void cpu_init(void)
359 "I" (offsetof(struct stack, abt[0])), 359 "I" (offsetof(struct stack, abt[0])),
360 "I" (PSR_F_BIT | PSR_I_BIT | UND_MODE), 360 "I" (PSR_F_BIT | PSR_I_BIT | UND_MODE),
361 "I" (offsetof(struct stack, und[0])), 361 "I" (offsetof(struct stack, und[0])),
362 "I" (PSR_F_BIT | PSR_I_BIT | SVC_MODE)); 362 "I" (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
363 : "r14");
363} 364}
364 365
365static struct machine_desc * __init setup_machine(unsigned int nr) 366static struct machine_desc * __init setup_machine(unsigned int nr)
diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index 34892758f098..a931409c8fe4 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -502,3 +502,126 @@ int __init setup_profiling_timer(unsigned int multiplier)
502{ 502{
503 return -EINVAL; 503 return -EINVAL;
504} 504}
505
506static int
507on_each_cpu_mask(void (*func)(void *), void *info, int retry, int wait,
508 cpumask_t mask)
509{
510 int ret = 0;
511
512 preempt_disable();
513
514 ret = smp_call_function_on_cpu(func, info, retry, wait, mask);
515 if (cpu_isset(smp_processor_id(), mask))
516 func(info);
517
518 preempt_enable();
519
520 return ret;
521}
522
523/**********************************************************************/
524
525/*
526 * TLB operations
527 */
528struct tlb_args {
529 struct vm_area_struct *ta_vma;
530 unsigned long ta_start;
531 unsigned long ta_end;
532};
533
534static inline void ipi_flush_tlb_all(void *ignored)
535{
536 local_flush_tlb_all();
537}
538
539static inline void ipi_flush_tlb_mm(void *arg)
540{
541 struct mm_struct *mm = (struct mm_struct *)arg;
542
543 local_flush_tlb_mm(mm);
544}
545
546static inline void ipi_flush_tlb_page(void *arg)
547{
548 struct tlb_args *ta = (struct tlb_args *)arg;
549
550 local_flush_tlb_page(ta->ta_vma, ta->ta_start);
551}
552
553static inline void ipi_flush_tlb_kernel_page(void *arg)
554{
555 struct tlb_args *ta = (struct tlb_args *)arg;
556
557 local_flush_tlb_kernel_page(ta->ta_start);
558}
559
560static inline void ipi_flush_tlb_range(void *arg)
561{
562 struct tlb_args *ta = (struct tlb_args *)arg;
563
564 local_flush_tlb_range(ta->ta_vma, ta->ta_start, ta->ta_end);
565}
566
567static inline void ipi_flush_tlb_kernel_range(void *arg)
568{
569 struct tlb_args *ta = (struct tlb_args *)arg;
570
571 local_flush_tlb_kernel_range(ta->ta_start, ta->ta_end);
572}
573
574void flush_tlb_all(void)
575{
576 on_each_cpu(ipi_flush_tlb_all, NULL, 1, 1);
577}
578
579void flush_tlb_mm(struct mm_struct *mm)
580{
581 cpumask_t mask = mm->cpu_vm_mask;
582
583 on_each_cpu_mask(ipi_flush_tlb_mm, mm, 1, 1, mask);
584}
585
586void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
587{
588 cpumask_t mask = vma->vm_mm->cpu_vm_mask;
589 struct tlb_args ta;
590
591 ta.ta_vma = vma;
592 ta.ta_start = uaddr;
593
594 on_each_cpu_mask(ipi_flush_tlb_page, &ta, 1, 1, mask);
595}
596
597void flush_tlb_kernel_page(unsigned long kaddr)
598{
599 struct tlb_args ta;
600
601 ta.ta_start = kaddr;
602
603 on_each_cpu(ipi_flush_tlb_kernel_page, &ta, 1, 1);
604}
605
606void flush_tlb_range(struct vm_area_struct *vma,
607 unsigned long start, unsigned long end)
608{
609 cpumask_t mask = vma->vm_mm->cpu_vm_mask;
610 struct tlb_args ta;
611
612 ta.ta_vma = vma;
613 ta.ta_start = start;
614 ta.ta_end = end;
615
616 on_each_cpu_mask(ipi_flush_tlb_range, &ta, 1, 1, mask);
617}
618
619void flush_tlb_kernel_range(unsigned long start, unsigned long end)
620{
621 struct tlb_args ta;
622
623 ta.ta_start = start;
624 ta.ta_end = end;
625
626 on_each_cpu(ipi_flush_tlb_kernel_range, &ta, 1, 1);
627}
diff --git a/arch/arm/kernel/time.c b/arch/arm/kernel/time.c
index 06054c9ba074..1b7fcd50c3e2 100644
--- a/arch/arm/kernel/time.c
+++ b/arch/arm/kernel/time.c
@@ -424,15 +424,19 @@ static int timer_dyn_tick_disable(void)
424 return ret; 424 return ret;
425} 425}
426 426
427/*
428 * Reprogram the system timer for at least the calculated time interval.
429 * This function should be called from the idle thread with IRQs disabled,
430 * immediately before sleeping.
431 */
427void timer_dyn_reprogram(void) 432void timer_dyn_reprogram(void)
428{ 433{
429 struct dyn_tick_timer *dyn_tick = system_timer->dyn_tick; 434 struct dyn_tick_timer *dyn_tick = system_timer->dyn_tick;
430 unsigned long flags;
431 435
432 write_seqlock_irqsave(&xtime_lock, flags); 436 write_seqlock(&xtime_lock);
433 if (dyn_tick->state & DYN_TICK_ENABLED) 437 if (dyn_tick->state & DYN_TICK_ENABLED)
434 dyn_tick->reprogram(next_timer_interrupt() - jiffies); 438 dyn_tick->reprogram(next_timer_interrupt() - jiffies);
435 write_sequnlock_irqrestore(&xtime_lock, flags); 439 write_sequnlock(&xtime_lock);
436} 440}
437 441
438static ssize_t timer_show_dyn_tick(struct sys_device *dev, char *buf) 442static ssize_t timer_show_dyn_tick(struct sys_device *dev, char *buf)
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index c0e65833ffc4..8725d63e4219 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -11,7 +11,7 @@ lib-y := backtrace.o changebit.o csumipv6.o csumpartial.o \
11 strnlen_user.o strchr.o strrchr.o testchangebit.o \ 11 strnlen_user.o strchr.o strrchr.o testchangebit.o \
12 testclearbit.o testsetbit.o uaccess.o getuser.o \ 12 testclearbit.o testsetbit.o uaccess.o getuser.o \
13 putuser.o ashldi3.o ashrdi3.o lshrdi3.o muldi3.o \ 13 putuser.o ashldi3.o ashrdi3.o lshrdi3.o muldi3.o \
14 ucmpdi2.o udivdi3.o lib1funcs.o div64.o \ 14 ucmpdi2.o lib1funcs.o div64.o \
15 io-readsb.o io-writesb.o io-readsl.o io-writesl.o 15 io-readsb.o io-writesb.o io-readsl.o io-writesl.o
16 16
17ifeq ($(CONFIG_CPU_32v3),y) 17ifeq ($(CONFIG_CPU_32v3),y)
diff --git a/arch/arm/lib/longlong.h b/arch/arm/lib/longlong.h
deleted file mode 100644
index 90ae647e4d76..000000000000
--- a/arch/arm/lib/longlong.h
+++ /dev/null
@@ -1,183 +0,0 @@
1/* longlong.h -- based on code from gcc-2.95.3
2
3 definitions for mixed size 32/64 bit arithmetic.
4 Copyright (C) 1991, 92, 94, 95, 96, 1997, 1998 Free Software Foundation, Inc.
5
6 This definition file is free software; you can redistribute it
7 and/or modify it under the terms of the GNU General Public
8 License as published by the Free Software Foundation; either
9 version 2, or (at your option) any later version.
10
11 This definition file is distributed in the hope that it will be
12 useful, but WITHOUT ANY WARRANTY; without even the implied
13 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the 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., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21/* Borrowed from GCC 2.95.3, I Molton 29/07/01 */
22
23#ifndef SI_TYPE_SIZE
24#define SI_TYPE_SIZE 32
25#endif
26
27#define __BITS4 (SI_TYPE_SIZE / 4)
28#define __ll_B (1L << (SI_TYPE_SIZE / 2))
29#define __ll_lowpart(t) ((u32) (t) % __ll_B)
30#define __ll_highpart(t) ((u32) (t) / __ll_B)
31
32/* Define auxiliary asm macros.
33
34 1) umul_ppmm(high_prod, low_prod, multipler, multiplicand)
35 multiplies two u32 integers MULTIPLER and MULTIPLICAND,
36 and generates a two-part u32 product in HIGH_PROD and
37 LOW_PROD.
38
39 2) __umulsidi3(a,b) multiplies two u32 integers A and B,
40 and returns a u64 product. This is just a variant of umul_ppmm.
41
42 3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
43 denominator) divides a two-word unsigned integer, composed by the
44 integers HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and
45 places the quotient in QUOTIENT and the remainder in REMAINDER.
46 HIGH_NUMERATOR must be less than DENOMINATOR for correct operation.
47 If, in addition, the most significant bit of DENOMINATOR must be 1,
48 then the pre-processor symbol UDIV_NEEDS_NORMALIZATION is defined to 1.
49
50 4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
51 denominator). Like udiv_qrnnd but the numbers are signed. The
52 quotient is rounded towards 0.
53
54 5) count_leading_zeros(count, x) counts the number of zero-bits from
55 the msb to the first non-zero bit. This is the number of steps X
56 needs to be shifted left to set the msb. Undefined for X == 0.
57
58 6) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
59 high_addend_2, low_addend_2) adds two two-word unsigned integers,
60 composed by HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and
61 LOW_ADDEND_2 respectively. The result is placed in HIGH_SUM and
62 LOW_SUM. Overflow (i.e. carry out) is not stored anywhere, and is
63 lost.
64
65 7) sub_ddmmss(high_difference, low_difference, high_minuend,
66 low_minuend, high_subtrahend, low_subtrahend) subtracts two
67 two-word unsigned integers, composed by HIGH_MINUEND_1 and
68 LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and LOW_SUBTRAHEND_2
69 respectively. The result is placed in HIGH_DIFFERENCE and
70 LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere,
71 and is lost.
72
73 If any of these macros are left undefined for a particular CPU,
74 C macros are used. */
75
76#if defined (__arm__)
77#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
78 __asm__ ("adds %1, %4, %5 \n\
79 adc %0, %2, %3" \
80 : "=r" ((u32) (sh)), \
81 "=&r" ((u32) (sl)) \
82 : "%r" ((u32) (ah)), \
83 "rI" ((u32) (bh)), \
84 "%r" ((u32) (al)), \
85 "rI" ((u32) (bl)))
86#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
87 __asm__ ("subs %1, %4, %5 \n\
88 sbc %0, %2, %3" \
89 : "=r" ((u32) (sh)), \
90 "=&r" ((u32) (sl)) \
91 : "r" ((u32) (ah)), \
92 "rI" ((u32) (bh)), \
93 "r" ((u32) (al)), \
94 "rI" ((u32) (bl)))
95#define umul_ppmm(xh, xl, a, b) \
96{register u32 __t0, __t1, __t2; \
97 __asm__ ("%@ Inlined umul_ppmm \n\
98 mov %2, %5, lsr #16 \n\
99 mov %0, %6, lsr #16 \n\
100 bic %3, %5, %2, lsl #16 \n\
101 bic %4, %6, %0, lsl #16 \n\
102 mul %1, %3, %4 \n\
103 mul %4, %2, %4 \n\
104 mul %3, %0, %3 \n\
105 mul %0, %2, %0 \n\
106 adds %3, %4, %3 \n\
107 addcs %0, %0, #65536 \n\
108 adds %1, %1, %3, lsl #16 \n\
109 adc %0, %0, %3, lsr #16" \
110 : "=&r" ((u32) (xh)), \
111 "=r" ((u32) (xl)), \
112 "=&r" (__t0), "=&r" (__t1), "=r" (__t2) \
113 : "r" ((u32) (a)), \
114 "r" ((u32) (b)));}
115#define UMUL_TIME 20
116#define UDIV_TIME 100
117#endif /* __arm__ */
118
119#define __umulsidi3(u, v) \
120 ({DIunion __w; \
121 umul_ppmm (__w.s.high, __w.s.low, u, v); \
122 __w.ll; })
123
124#define __udiv_qrnnd_c(q, r, n1, n0, d) \
125 do { \
126 u32 __d1, __d0, __q1, __q0; \
127 u32 __r1, __r0, __m; \
128 __d1 = __ll_highpart (d); \
129 __d0 = __ll_lowpart (d); \
130 \
131 __r1 = (n1) % __d1; \
132 __q1 = (n1) / __d1; \
133 __m = (u32) __q1 * __d0; \
134 __r1 = __r1 * __ll_B | __ll_highpart (n0); \
135 if (__r1 < __m) \
136 { \
137 __q1--, __r1 += (d); \
138 if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
139 if (__r1 < __m) \
140 __q1--, __r1 += (d); \
141 } \
142 __r1 -= __m; \
143 \
144 __r0 = __r1 % __d1; \
145 __q0 = __r1 / __d1; \
146 __m = (u32) __q0 * __d0; \
147 __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
148 if (__r0 < __m) \
149 { \
150 __q0--, __r0 += (d); \
151 if (__r0 >= (d)) \
152 if (__r0 < __m) \
153 __q0--, __r0 += (d); \
154 } \
155 __r0 -= __m; \
156 \
157 (q) = (u32) __q1 * __ll_B | __q0; \
158 (r) = __r0; \
159 } while (0)
160
161#define UDIV_NEEDS_NORMALIZATION 1
162#define udiv_qrnnd __udiv_qrnnd_c
163
164#define count_leading_zeros(count, x) \
165 do { \
166 u32 __xr = (x); \
167 u32 __a; \
168 \
169 if (SI_TYPE_SIZE <= 32) \
170 { \
171 __a = __xr < ((u32)1<<2*__BITS4) \
172 ? (__xr < ((u32)1<<__BITS4) ? 0 : __BITS4) \
173 : (__xr < ((u32)1<<3*__BITS4) ? 2*__BITS4 : 3*__BITS4); \
174 } \
175 else \
176 { \
177 for (__a = SI_TYPE_SIZE - 8; __a > 0; __a -= 8) \
178 if (((__xr >> __a) & 0xff) != 0) \
179 break; \
180 } \
181 \
182 (count) = SI_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
183 } while (0)
diff --git a/arch/arm/lib/udivdi3.c b/arch/arm/lib/udivdi3.c
deleted file mode 100644
index e343be4c6642..000000000000
--- a/arch/arm/lib/udivdi3.c
+++ /dev/null
@@ -1,222 +0,0 @@
1/* More subroutines needed by GCC output code on some machines. */
2/* Compile this one with gcc. */
3/* Copyright (C) 1989, 92-98, 1999 Free Software Foundation, Inc.
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22/* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License.
28 */
29/* support functions required by the kernel. based on code from gcc-2.95.3 */
30/* I Molton 29/07/01 */
31
32#include "gcclib.h"
33#include "longlong.h"
34
35static const u8 __clz_tab[] = {
36 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
37 5, 5, 5, 5, 5, 5, 5, 5,
38 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
39 6, 6, 6, 6, 6, 6, 6, 6,
40 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
41 7, 7, 7, 7, 7, 7, 7, 7,
42 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
43 7, 7, 7, 7, 7, 7, 7, 7,
44 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
45 8, 8, 8, 8, 8, 8, 8, 8,
46 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
47 8, 8, 8, 8, 8, 8, 8, 8,
48 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
49 8, 8, 8, 8, 8, 8, 8, 8,
50 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
51 8, 8, 8, 8, 8, 8, 8, 8,
52};
53
54u64 __udivmoddi4(u64 n, u64 d, u64 * rp)
55{
56 DIunion ww;
57 DIunion nn, dd;
58 DIunion rr;
59 u32 d0, d1, n0, n1, n2;
60 u32 q0, q1;
61 u32 b, bm;
62
63 nn.ll = n;
64 dd.ll = d;
65
66 d0 = dd.s.low;
67 d1 = dd.s.high;
68 n0 = nn.s.low;
69 n1 = nn.s.high;
70
71 if (d1 == 0) {
72 if (d0 > n1) {
73 /* 0q = nn / 0D */
74
75 count_leading_zeros(bm, d0);
76
77 if (bm != 0) {
78 /* Normalize, i.e. make the most significant bit of the
79 denominator set. */
80
81 d0 = d0 << bm;
82 n1 = (n1 << bm) | (n0 >> (SI_TYPE_SIZE - bm));
83 n0 = n0 << bm;
84 }
85
86 udiv_qrnnd(q0, n0, n1, n0, d0);
87 q1 = 0;
88
89 /* Remainder in n0 >> bm. */
90 } else {
91 /* qq = NN / 0d */
92
93 if (d0 == 0)
94 d0 = 1 / d0; /* Divide intentionally by zero. */
95
96 count_leading_zeros(bm, d0);
97
98 if (bm == 0) {
99 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
100 conclude (the most significant bit of n1 is set) /\ (the
101 leading quotient digit q1 = 1).
102
103 This special case is necessary, not an optimization.
104 (Shifts counts of SI_TYPE_SIZE are undefined.) */
105
106 n1 -= d0;
107 q1 = 1;
108 } else {
109 /* Normalize. */
110
111 b = SI_TYPE_SIZE - bm;
112
113 d0 = d0 << bm;
114 n2 = n1 >> b;
115 n1 = (n1 << bm) | (n0 >> b);
116 n0 = n0 << bm;
117
118 udiv_qrnnd(q1, n1, n2, n1, d0);
119 }
120
121 /* n1 != d0... */
122
123 udiv_qrnnd(q0, n0, n1, n0, d0);
124
125 /* Remainder in n0 >> bm. */
126 }
127
128 if (rp != 0) {
129 rr.s.low = n0 >> bm;
130 rr.s.high = 0;
131 *rp = rr.ll;
132 }
133 } else {
134 if (d1 > n1) {
135 /* 00 = nn / DD */
136
137 q0 = 0;
138 q1 = 0;
139
140 /* Remainder in n1n0. */
141 if (rp != 0) {
142 rr.s.low = n0;
143 rr.s.high = n1;
144 *rp = rr.ll;
145 }
146 } else {
147 /* 0q = NN / dd */
148
149 count_leading_zeros(bm, d1);
150 if (bm == 0) {
151 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
152 conclude (the most significant bit of n1 is set) /\ (the
153 quotient digit q0 = 0 or 1).
154
155 This special case is necessary, not an optimization. */
156
157 /* The condition on the next line takes advantage of that
158 n1 >= d1 (true due to program flow). */
159 if (n1 > d1 || n0 >= d0) {
160 q0 = 1;
161 sub_ddmmss(n1, n0, n1, n0, d1, d0);
162 } else
163 q0 = 0;
164
165 q1 = 0;
166
167 if (rp != 0) {
168 rr.s.low = n0;
169 rr.s.high = n1;
170 *rp = rr.ll;
171 }
172 } else {
173 u32 m1, m0;
174 /* Normalize. */
175
176 b = SI_TYPE_SIZE - bm;
177
178 d1 = (d1 << bm) | (d0 >> b);
179 d0 = d0 << bm;
180 n2 = n1 >> b;
181 n1 = (n1 << bm) | (n0 >> b);
182 n0 = n0 << bm;
183
184 udiv_qrnnd(q0, n1, n2, n1, d1);
185 umul_ppmm(m1, m0, q0, d0);
186
187 if (m1 > n1 || (m1 == n1 && m0 > n0)) {
188 q0--;
189 sub_ddmmss(m1, m0, m1, m0, d1, d0);
190 }
191
192 q1 = 0;
193
194 /* Remainder in (n1n0 - m1m0) >> bm. */
195 if (rp != 0) {
196 sub_ddmmss(n1, n0, n1, n0, m1, m0);
197 rr.s.low = (n1 << b) | (n0 >> bm);
198 rr.s.high = n1 >> bm;
199 *rp = rr.ll;
200 }
201 }
202 }
203 }
204
205 ww.s.low = q0;
206 ww.s.high = q1;
207 return ww.ll;
208}
209
210u64 __udivdi3(u64 n, u64 d)
211{
212 return __udivmoddi4(n, d, (u64 *) 0);
213}
214
215u64 __umoddi3(u64 u, u64 v)
216{
217 u64 w;
218
219 (void)__udivmoddi4(u, v, &w);
220
221 return w;
222}
diff --git a/arch/arm/mach-aaec2000/Makefile.boot b/arch/arm/mach-aaec2000/Makefile.boot
new file mode 100644
index 000000000000..8f5a8b7c53c7
--- /dev/null
+++ b/arch/arm/mach-aaec2000/Makefile.boot
@@ -0,0 +1 @@
zreladdr-y := 0xf0008000
diff --git a/arch/arm/mach-aaec2000/core.c b/arch/arm/mach-aaec2000/core.c
index fc145b3768fa..aece0cd4f0a3 100644
--- a/arch/arm/mach-aaec2000/core.c
+++ b/arch/arm/mach-aaec2000/core.c
@@ -128,8 +128,8 @@ aaec2000_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
128 128
129static struct irqaction aaec2000_timer_irq = { 129static struct irqaction aaec2000_timer_irq = {
130 .name = "AAEC-2000 Timer Tick", 130 .name = "AAEC-2000 Timer Tick",
131 .flags = SA_INTERRUPT, 131 .flags = SA_INTERRUPT | SA_TIMER,
132 .handler = aaec2000_timer_interrupt 132 .handler = aaec2000_timer_interrupt,
133}; 133};
134 134
135static void __init aaec2000_timer_init(void) 135static void __init aaec2000_timer_init(void)
diff --git a/arch/arm/mach-clps711x/time.c b/arch/arm/mach-clps711x/time.c
index 383d4e0c6e35..1a23f0dcd4b8 100644
--- a/arch/arm/mach-clps711x/time.c
+++ b/arch/arm/mach-clps711x/time.c
@@ -57,8 +57,8 @@ p720t_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
57 57
58static struct irqaction clps711x_timer_irq = { 58static struct irqaction clps711x_timer_irq = {
59 .name = "CLPS711x Timer Tick", 59 .name = "CLPS711x Timer Tick",
60 .flags = SA_INTERRUPT, 60 .flags = SA_INTERRUPT | SA_TIMER,
61 .handler = p720t_timer_interrupt 61 .handler = p720t_timer_interrupt,
62}; 62};
63 63
64static void __init clps711x_timer_init(void) 64static void __init clps711x_timer_init(void)
diff --git a/arch/arm/mach-clps7500/core.c b/arch/arm/mach-clps7500/core.c
index 0bc7da488612..90e85f434f6f 100644
--- a/arch/arm/mach-clps7500/core.c
+++ b/arch/arm/mach-clps7500/core.c
@@ -298,8 +298,8 @@ clps7500_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
298 298
299static struct irqaction clps7500_timer_irq = { 299static struct irqaction clps7500_timer_irq = {
300 .name = "CLPS7500 Timer Tick", 300 .name = "CLPS7500 Timer Tick",
301 .flags = SA_INTERRUPT, 301 .flags = SA_INTERRUPT | SA_TIMER,
302 .handler = clps7500_timer_interrupt 302 .handler = clps7500_timer_interrupt,
303}; 303};
304 304
305/* 305/*
diff --git a/arch/arm/mach-ebsa110/core.c b/arch/arm/mach-ebsa110/core.c
index ef362d44949d..86ffdbb5626e 100644
--- a/arch/arm/mach-ebsa110/core.c
+++ b/arch/arm/mach-ebsa110/core.c
@@ -173,8 +173,8 @@ ebsa110_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
173 173
174static struct irqaction ebsa110_timer_irq = { 174static struct irqaction ebsa110_timer_irq = {
175 .name = "EBSA110 Timer Tick", 175 .name = "EBSA110 Timer Tick",
176 .flags = SA_INTERRUPT, 176 .flags = SA_INTERRUPT | SA_TIMER,
177 .handler = ebsa110_timer_interrupt 177 .handler = ebsa110_timer_interrupt,
178}; 178};
179 179
180/* 180/*
diff --git a/arch/arm/mach-epxa10db/time.c b/arch/arm/mach-epxa10db/time.c
index 1b991f3cc3c6..4b1084dde8dd 100644
--- a/arch/arm/mach-epxa10db/time.c
+++ b/arch/arm/mach-epxa10db/time.c
@@ -56,8 +56,8 @@ epxa10db_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
56 56
57static struct irqaction epxa10db_timer_irq = { 57static struct irqaction epxa10db_timer_irq = {
58 .name = "Excalibur Timer Tick", 58 .name = "Excalibur Timer Tick",
59 .flags = SA_INTERRUPT, 59 .flags = SA_INTERRUPT | SA_TIMER,
60 .handler = epxa10db_timer_interrupt 60 .handler = epxa10db_timer_interrupt,
61}; 61};
62 62
63/* 63/*
diff --git a/arch/arm/mach-footbridge/dc21285-timer.c b/arch/arm/mach-footbridge/dc21285-timer.c
index da5b9b7623ca..14a62d6008fe 100644
--- a/arch/arm/mach-footbridge/dc21285-timer.c
+++ b/arch/arm/mach-footbridge/dc21285-timer.c
@@ -43,7 +43,7 @@ timer1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
43static struct irqaction footbridge_timer_irq = { 43static struct irqaction footbridge_timer_irq = {
44 .name = "Timer1 timer tick", 44 .name = "Timer1 timer tick",
45 .handler = timer1_interrupt, 45 .handler = timer1_interrupt,
46 .flags = SA_INTERRUPT, 46 .flags = SA_INTERRUPT | SA_TIMER,
47}; 47};
48 48
49/* 49/*
diff --git a/arch/arm/mach-footbridge/isa-timer.c b/arch/arm/mach-footbridge/isa-timer.c
index a4fefa0bb5a1..c1d74f7ab669 100644
--- a/arch/arm/mach-footbridge/isa-timer.c
+++ b/arch/arm/mach-footbridge/isa-timer.c
@@ -72,7 +72,7 @@ isa_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
72static struct irqaction isa_timer_irq = { 72static struct irqaction isa_timer_irq = {
73 .name = "ISA timer tick", 73 .name = "ISA timer tick",
74 .handler = isa_timer_interrupt, 74 .handler = isa_timer_interrupt,
75 .flags = SA_INTERRUPT, 75 .flags = SA_INTERRUPT | SA_TIMER,
76}; 76};
77 77
78static void __init isa_timer_init(void) 78static void __init isa_timer_init(void)
diff --git a/arch/arm/mach-h720x/cpu-h7201.c b/arch/arm/mach-h720x/cpu-h7201.c
index 743656881ed6..af9e4a5d5ea7 100644
--- a/arch/arm/mach-h720x/cpu-h7201.c
+++ b/arch/arm/mach-h720x/cpu-h7201.c
@@ -41,8 +41,8 @@ h7201_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
41 41
42static struct irqaction h7201_timer_irq = { 42static struct irqaction h7201_timer_irq = {
43 .name = "h7201 Timer Tick", 43 .name = "h7201 Timer Tick",
44 .flags = SA_INTERRUPT, 44 .flags = SA_INTERRUPT | SA_TIMER,
45 .handler = h7201_timer_interrupt 45 .handler = h7201_timer_interrupt,
46}; 46};
47 47
48/* 48/*
diff --git a/arch/arm/mach-h720x/cpu-h7202.c b/arch/arm/mach-h720x/cpu-h7202.c
index 21b8fb6122cd..593b6a2a30e1 100644
--- a/arch/arm/mach-h720x/cpu-h7202.c
+++ b/arch/arm/mach-h720x/cpu-h7202.c
@@ -171,8 +171,8 @@ static struct irqchip h7202_timerx_chip = {
171 171
172static struct irqaction h7202_timer_irq = { 172static struct irqaction h7202_timer_irq = {
173 .name = "h7202 Timer Tick", 173 .name = "h7202 Timer Tick",
174 .flags = SA_INTERRUPT, 174 .flags = SA_INTERRUPT | SA_TIMER,
175 .handler = h7202_timer_interrupt 175 .handler = h7202_timer_interrupt,
176}; 176};
177 177
178/* 178/*
diff --git a/arch/arm/mach-imx/time.c b/arch/arm/mach-imx/time.c
index 11f1e56c36bc..ea805bfa5e54 100644
--- a/arch/arm/mach-imx/time.c
+++ b/arch/arm/mach-imx/time.c
@@ -72,8 +72,8 @@ imx_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
72 72
73static struct irqaction imx_timer_irq = { 73static struct irqaction imx_timer_irq = {
74 .name = "i.MX Timer Tick", 74 .name = "i.MX Timer Tick",
75 .flags = SA_INTERRUPT, 75 .flags = SA_INTERRUPT | SA_TIMER,
76 .handler = imx_timer_interrupt 76 .handler = imx_timer_interrupt,
77}; 77};
78 78
79/* 79/*
diff --git a/arch/arm/mach-integrator/core.c b/arch/arm/mach-integrator/core.c
index bd1e5e3c9d34..dacbf504dae2 100644
--- a/arch/arm/mach-integrator/core.c
+++ b/arch/arm/mach-integrator/core.c
@@ -20,6 +20,7 @@
20#include <asm/irq.h> 20#include <asm/irq.h>
21#include <asm/io.h> 21#include <asm/io.h>
22#include <asm/hardware/amba.h> 22#include <asm/hardware/amba.h>
23#include <asm/hardware/arm_timer.h>
23#include <asm/arch/cm.h> 24#include <asm/arch/cm.h>
24#include <asm/system.h> 25#include <asm/system.h>
25#include <asm/leds.h> 26#include <asm/leds.h>
@@ -156,16 +157,6 @@ EXPORT_SYMBOL(cm_control);
156#define TICKS2USECS(x) ((x) / TICKS_PER_uSEC) 157#define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
157#endif 158#endif
158 159
159/*
160 * What does it look like?
161 */
162typedef struct TimerStruct {
163 unsigned long TimerLoad;
164 unsigned long TimerValue;
165 unsigned long TimerControl;
166 unsigned long TimerClear;
167} TimerStruct_t;
168
169static unsigned long timer_reload; 160static unsigned long timer_reload;
170 161
171/* 162/*
@@ -174,7 +165,6 @@ static unsigned long timer_reload;
174 */ 165 */
175unsigned long integrator_gettimeoffset(void) 166unsigned long integrator_gettimeoffset(void)
176{ 167{
177 volatile TimerStruct_t *timer1 = (TimerStruct_t *)TIMER1_VA_BASE;
178 unsigned long ticks1, ticks2, status; 168 unsigned long ticks1, ticks2, status;
179 169
180 /* 170 /*
@@ -183,11 +173,11 @@ unsigned long integrator_gettimeoffset(void)
183 * an interrupt. We get around this by ensuring that the 173 * an interrupt. We get around this by ensuring that the
184 * counter has not reloaded between our two reads. 174 * counter has not reloaded between our two reads.
185 */ 175 */
186 ticks2 = timer1->TimerValue & 0xffff; 176 ticks2 = readl(TIMER1_VA_BASE + TIMER_VALUE) & 0xffff;
187 do { 177 do {
188 ticks1 = ticks2; 178 ticks1 = ticks2;
189 status = __raw_readl(VA_IC_BASE + IRQ_RAW_STATUS); 179 status = __raw_readl(VA_IC_BASE + IRQ_RAW_STATUS);
190 ticks2 = timer1->TimerValue & 0xffff; 180 ticks2 = readl(TIMER1_VA_BASE + TIMER_VALUE) & 0xffff;
191 } while (ticks2 > ticks1); 181 } while (ticks2 > ticks1);
192 182
193 /* 183 /*
@@ -213,14 +203,12 @@ unsigned long integrator_gettimeoffset(void)
213static irqreturn_t 203static irqreturn_t
214integrator_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs) 204integrator_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
215{ 205{
216 volatile TimerStruct_t *timer1 = (volatile TimerStruct_t *)TIMER1_VA_BASE;
217
218 write_seqlock(&xtime_lock); 206 write_seqlock(&xtime_lock);
219 207
220 /* 208 /*
221 * clear the interrupt 209 * clear the interrupt
222 */ 210 */
223 timer1->TimerClear = 1; 211 writel(1, TIMER1_VA_BASE + TIMER_INTCLR);
224 212
225 /* 213 /*
226 * the clock tick routines are only processed on the 214 * the clock tick routines are only processed on the
@@ -247,8 +235,8 @@ integrator_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
247 235
248static struct irqaction integrator_timer_irq = { 236static struct irqaction integrator_timer_irq = {
249 .name = "Integrator Timer Tick", 237 .name = "Integrator Timer Tick",
250 .flags = SA_INTERRUPT, 238 .flags = SA_INTERRUPT | SA_TIMER,
251 .handler = integrator_timer_interrupt 239 .handler = integrator_timer_interrupt,
252}; 240};
253 241
254/* 242/*
@@ -256,32 +244,29 @@ static struct irqaction integrator_timer_irq = {
256 */ 244 */
257void __init integrator_time_init(unsigned long reload, unsigned int ctrl) 245void __init integrator_time_init(unsigned long reload, unsigned int ctrl)
258{ 246{
259 volatile TimerStruct_t *timer0 = (volatile TimerStruct_t *)TIMER0_VA_BASE; 247 unsigned int timer_ctrl = TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC;
260 volatile TimerStruct_t *timer1 = (volatile TimerStruct_t *)TIMER1_VA_BASE;
261 volatile TimerStruct_t *timer2 = (volatile TimerStruct_t *)TIMER2_VA_BASE;
262 unsigned int timer_ctrl = 0x80 | 0x40; /* periodic */
263 248
264 timer_reload = reload; 249 timer_reload = reload;
265 timer_ctrl |= ctrl; 250 timer_ctrl |= ctrl;
266 251
267 if (timer_reload > 0x100000) { 252 if (timer_reload > 0x100000) {
268 timer_reload >>= 8; 253 timer_reload >>= 8;
269 timer_ctrl |= 0x08; /* /256 */ 254 timer_ctrl |= TIMER_CTRL_DIV256;
270 } else if (timer_reload > 0x010000) { 255 } else if (timer_reload > 0x010000) {
271 timer_reload >>= 4; 256 timer_reload >>= 4;
272 timer_ctrl |= 0x04; /* /16 */ 257 timer_ctrl |= TIMER_CTRL_DIV16;
273 } 258 }
274 259
275 /* 260 /*
276 * Initialise to a known state (all timers off) 261 * Initialise to a known state (all timers off)
277 */ 262 */
278 timer0->TimerControl = 0; 263 writel(0, TIMER0_VA_BASE + TIMER_CTRL);
279 timer1->TimerControl = 0; 264 writel(0, TIMER1_VA_BASE + TIMER_CTRL);
280 timer2->TimerControl = 0; 265 writel(0, TIMER2_VA_BASE + TIMER_CTRL);
281 266
282 timer1->TimerLoad = timer_reload; 267 writel(timer_reload, TIMER1_VA_BASE + TIMER_LOAD);
283 timer1->TimerValue = timer_reload; 268 writel(timer_reload, TIMER1_VA_BASE + TIMER_VALUE);
284 timer1->TimerControl = timer_ctrl; 269 writel(timer_ctrl, TIMER1_VA_BASE + TIMER_CTRL);
285 270
286 /* 271 /*
287 * Make irqs happen for the system timer 272 * Make irqs happen for the system timer
diff --git a/arch/arm/mach-iop3xx/iop321-time.c b/arch/arm/mach-iop3xx/iop321-time.c
index 9b7dd64d1b8f..d53af1669502 100644
--- a/arch/arm/mach-iop3xx/iop321-time.c
+++ b/arch/arm/mach-iop3xx/iop321-time.c
@@ -86,7 +86,7 @@ iop321_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
86static struct irqaction iop321_timer_irq = { 86static struct irqaction iop321_timer_irq = {
87 .name = "IOP321 Timer Tick", 87 .name = "IOP321 Timer Tick",
88 .handler = iop321_timer_interrupt, 88 .handler = iop321_timer_interrupt,
89 .flags = SA_INTERRUPT 89 .flags = SA_INTERRUPT | SA_TIMER,
90}; 90};
91 91
92static void __init iop321_timer_init(void) 92static void __init iop321_timer_init(void)
diff --git a/arch/arm/mach-iop3xx/iop331-time.c b/arch/arm/mach-iop3xx/iop331-time.c
index e01696769263..1a6d9d661e4b 100644
--- a/arch/arm/mach-iop3xx/iop331-time.c
+++ b/arch/arm/mach-iop3xx/iop331-time.c
@@ -83,7 +83,7 @@ iop331_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
83static struct irqaction iop331_timer_irq = { 83static struct irqaction iop331_timer_irq = {
84 .name = "IOP331 Timer Tick", 84 .name = "IOP331 Timer Tick",
85 .handler = iop331_timer_interrupt, 85 .handler = iop331_timer_interrupt,
86 .flags = SA_INTERRUPT 86 .flags = SA_INTERRUPT | SA_TIMER,
87}; 87};
88 88
89static void __init iop331_timer_init(void) 89static void __init iop331_timer_init(void)
diff --git a/arch/arm/mach-ixp2000/core.c b/arch/arm/mach-ixp2000/core.c
index 0ee34acb8d7b..4b9d841e04c1 100644
--- a/arch/arm/mach-ixp2000/core.c
+++ b/arch/arm/mach-ixp2000/core.c
@@ -103,6 +103,11 @@ static struct map_desc ixp2000_io_desc[] __initdata = {
103 .length = IXP2000_PCI_CSR_SIZE, 103 .length = IXP2000_PCI_CSR_SIZE,
104 .type = MT_DEVICE 104 .type = MT_DEVICE
105 }, { 105 }, {
106 .virtual = IXP2000_MSF_VIRT_BASE,
107 .physical = IXP2000_MSF_PHYS_BASE,
108 .length = IXP2000_MSF_SIZE,
109 .type = MT_DEVICE
110 }, {
106 .virtual = IXP2000_PCI_IO_VIRT_BASE, 111 .virtual = IXP2000_PCI_IO_VIRT_BASE,
107 .physical = IXP2000_PCI_IO_PHYS_BASE, 112 .physical = IXP2000_PCI_IO_PHYS_BASE,
108 .length = IXP2000_PCI_IO_SIZE, 113 .length = IXP2000_PCI_IO_SIZE,
@@ -194,8 +199,8 @@ static int ixp2000_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
194 199
195static struct irqaction ixp2000_timer_irq = { 200static struct irqaction ixp2000_timer_irq = {
196 .name = "IXP2000 Timer Tick", 201 .name = "IXP2000 Timer Tick",
197 .flags = SA_INTERRUPT, 202 .flags = SA_INTERRUPT | SA_TIMER,
198 .handler = ixp2000_timer_interrupt 203 .handler = ixp2000_timer_interrupt,
199}; 204};
200 205
201void __init ixp2000_init_time(unsigned long tick_rate) 206void __init ixp2000_init_time(unsigned long tick_rate)
diff --git a/arch/arm/mach-ixp2000/ixdp2800.c b/arch/arm/mach-ixp2000/ixdp2800.c
index aec13c7108a9..468a4bbfb724 100644
--- a/arch/arm/mach-ixp2000/ixdp2800.c
+++ b/arch/arm/mach-ixp2000/ixdp2800.c
@@ -42,12 +42,6 @@
42#include <asm/mach/flash.h> 42#include <asm/mach/flash.h>
43#include <asm/mach/arch.h> 43#include <asm/mach/arch.h>
44 44
45
46void ixdp2400_init_irq(void)
47{
48 ixdp2x00_init_irq(IXDP2800_CPLD_INT_STAT, IXDP2800_CPLD_INT_MASK, IXDP2400_NR_IRQS);
49}
50
51/************************************************************************* 45/*************************************************************************
52 * IXDP2800 timer tick 46 * IXDP2800 timer tick
53 *************************************************************************/ 47 *************************************************************************/
diff --git a/arch/arm/mach-ixp4xx/common.c b/arch/arm/mach-ixp4xx/common.c
index f39e8408488f..04490a9f8f6e 100644
--- a/arch/arm/mach-ixp4xx/common.c
+++ b/arch/arm/mach-ixp4xx/common.c
@@ -298,8 +298,8 @@ static irqreturn_t ixp4xx_timer_interrupt(int irq, void *dev_id, struct pt_regs
298 298
299static struct irqaction ixp4xx_timer_irq = { 299static struct irqaction ixp4xx_timer_irq = {
300 .name = "IXP4xx Timer Tick", 300 .name = "IXP4xx Timer Tick",
301 .flags = SA_INTERRUPT, 301 .flags = SA_INTERRUPT | SA_TIMER,
302 .handler = ixp4xx_timer_interrupt 302 .handler = ixp4xx_timer_interrupt,
303}; 303};
304 304
305static void __init ixp4xx_timer_init(void) 305static void __init ixp4xx_timer_init(void)
diff --git a/arch/arm/mach-lh7a40x/time.c b/arch/arm/mach-lh7a40x/time.c
index 51e1c814b400..be377e331f25 100644
--- a/arch/arm/mach-lh7a40x/time.c
+++ b/arch/arm/mach-lh7a40x/time.c
@@ -53,8 +53,8 @@ lh7a40x_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
53 53
54static struct irqaction lh7a40x_timer_irq = { 54static struct irqaction lh7a40x_timer_irq = {
55 .name = "LHA740x Timer Tick", 55 .name = "LHA740x Timer Tick",
56 .flags = SA_INTERRUPT, 56 .flags = SA_INTERRUPT | SA_TIMER,
57 .handler = lh7a40x_timer_interrupt 57 .handler = lh7a40x_timer_interrupt,
58}; 58};
59 59
60static void __init lh7a40x_timer_init(void) 60static void __init lh7a40x_timer_init(void)
diff --git a/arch/arm/mach-omap/pm.c b/arch/arm/mach-omap/pm.c
index 00fac155df2a..6b03ccdc1e92 100644
--- a/arch/arm/mach-omap/pm.c
+++ b/arch/arm/mach-omap/pm.c
@@ -41,7 +41,9 @@
41#include <linux/pm.h> 41#include <linux/pm.h>
42 42
43#include <asm/io.h> 43#include <asm/io.h>
44#include <asm/mach/time.h>
44#include <asm/mach-types.h> 45#include <asm/mach-types.h>
46
45#include <asm/arch/omap16xx.h> 47#include <asm/arch/omap16xx.h>
46#include <asm/arch/pm.h> 48#include <asm/arch/pm.h>
47#include <asm/arch/mux.h> 49#include <asm/arch/mux.h>
@@ -80,13 +82,13 @@ void omap_pm_idle(void)
80 return; 82 return;
81 } 83 }
82 mask32 = omap_readl(ARM_SYSST); 84 mask32 = omap_readl(ARM_SYSST);
83 local_fiq_enable();
84 local_irq_enable();
85 85
86#if defined(CONFIG_OMAP_32K_TIMER) && defined(CONFIG_NO_IDLE_HZ) 86 /*
87 /* Override timer to use VST for the next cycle */ 87 * Since an interrupt may set up a timer, we don't want to
88 omap_32k_timer_next_vst_interrupt(); 88 * reprogram the hardware timer with interrupts enabled.
89#endif 89 * Re-enable interrupts only after returning from idle.
90 */
91 timer_dyn_reprogram();
90 92
91 if ((mask32 & DSP_IDLE) == 0) { 93 if ((mask32 & DSP_IDLE) == 0) {
92 __asm__ volatile ("mcr p15, 0, r0, c7, c0, 4"); 94 __asm__ volatile ("mcr p15, 0, r0, c7, c0, 4");
@@ -102,6 +104,8 @@ void omap_pm_idle(void)
102 104
103 func_ptr(); 105 func_ptr();
104 } 106 }
107 local_fiq_enable();
108 local_irq_enable();
105} 109}
106 110
107/* 111/*
diff --git a/arch/arm/mach-omap/time.c b/arch/arm/mach-omap/time.c
index 4205fdcb632c..dd34e9f4c413 100644
--- a/arch/arm/mach-omap/time.c
+++ b/arch/arm/mach-omap/time.c
@@ -4,7 +4,7 @@
4 * OMAP Timers 4 * OMAP Timers
5 * 5 *
6 * Copyright (C) 2004 Nokia Corporation 6 * Copyright (C) 2004 Nokia Corporation
7 * Partial timer rewrite and additional VST timer support by 7 * Partial timer rewrite and additional dynamic tick timer support by
8 * Tony Lindgen <tony@atomide.com> and 8 * Tony Lindgen <tony@atomide.com> and
9 * Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com> 9 * Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
10 * 10 *
@@ -188,8 +188,8 @@ static irqreturn_t omap_mpu_timer_interrupt(int irq, void *dev_id,
188 188
189static struct irqaction omap_mpu_timer_irq = { 189static struct irqaction omap_mpu_timer_irq = {
190 .name = "mpu timer", 190 .name = "mpu timer",
191 .flags = SA_INTERRUPT, 191 .flags = SA_INTERRUPT | SA_TIMER,
192 .handler = omap_mpu_timer_interrupt 192 .handler = omap_mpu_timer_interrupt,
193}; 193};
194 194
195static unsigned long omap_mpu_timer1_overflows; 195static unsigned long omap_mpu_timer1_overflows;
@@ -203,7 +203,7 @@ static irqreturn_t omap_mpu_timer1_interrupt(int irq, void *dev_id,
203static struct irqaction omap_mpu_timer1_irq = { 203static struct irqaction omap_mpu_timer1_irq = {
204 .name = "mpu timer1 overflow", 204 .name = "mpu timer1 overflow",
205 .flags = SA_INTERRUPT, 205 .flags = SA_INTERRUPT,
206 .handler = omap_mpu_timer1_interrupt 206 .handler = omap_mpu_timer1_interrupt,
207}; 207};
208 208
209static __init void omap_init_mpu_timer(void) 209static __init void omap_init_mpu_timer(void)
@@ -261,7 +261,6 @@ unsigned long long sched_clock(void)
261 * so with HZ = 100, TVR = 327.68. 261 * so with HZ = 100, TVR = 327.68.
262 */ 262 */
263#define OMAP_32K_TIMER_TICK_PERIOD ((32768 / HZ) - 1) 263#define OMAP_32K_TIMER_TICK_PERIOD ((32768 / HZ) - 1)
264#define MAX_SKIP_JIFFIES 25
265#define TIMER_32K_SYNCHRONIZED 0xfffbc410 264#define TIMER_32K_SYNCHRONIZED 0xfffbc410
266 265
267#define JIFFIES_TO_HW_TICKS(nr_jiffies, clock_rate) \ 266#define JIFFIES_TO_HW_TICKS(nr_jiffies, clock_rate) \
@@ -347,14 +346,55 @@ static irqreturn_t omap_32k_timer_interrupt(int irq, void *dev_id,
347 return IRQ_HANDLED; 346 return IRQ_HANDLED;
348} 347}
349 348
349#ifdef CONFIG_NO_IDLE_HZ
350/*
351 * Programs the next timer interrupt needed. Called when dynamic tick is
352 * enabled, and to reprogram the ticks to skip from pm_idle. Note that
353 * we can keep the timer continuous, and don't need to set it to run in
354 * one-shot mode. This is because the timer will get reprogrammed again
355 * after next interrupt.
356 */
357void omap_32k_timer_reprogram(unsigned long next_tick)
358{
359 omap_32k_timer_start(JIFFIES_TO_HW_TICKS(next_tick, 32768) + 1);
360}
361
362static struct irqaction omap_32k_timer_irq;
363extern struct timer_update_handler timer_update;
364
365static int omap_32k_timer_enable_dyn_tick(void)
366{
367 /* No need to reprogram timer, just use the next interrupt */
368 return 0;
369}
370
371static int omap_32k_timer_disable_dyn_tick(void)
372{
373 omap_32k_timer_start(OMAP_32K_TIMER_TICK_PERIOD);
374 return 0;
375}
376
377static struct dyn_tick_timer omap_dyn_tick_timer = {
378 .enable = omap_32k_timer_enable_dyn_tick,
379 .disable = omap_32k_timer_disable_dyn_tick,
380 .reprogram = omap_32k_timer_reprogram,
381 .handler = omap_32k_timer_interrupt,
382};
383#endif /* CONFIG_NO_IDLE_HZ */
384
350static struct irqaction omap_32k_timer_irq = { 385static struct irqaction omap_32k_timer_irq = {
351 .name = "32KHz timer", 386 .name = "32KHz timer",
352 .flags = SA_INTERRUPT, 387 .flags = SA_INTERRUPT | SA_TIMER,
353 .handler = omap_32k_timer_interrupt 388 .handler = omap_32k_timer_interrupt,
354}; 389};
355 390
356static __init void omap_init_32k_timer(void) 391static __init void omap_init_32k_timer(void)
357{ 392{
393
394#ifdef CONFIG_NO_IDLE_HZ
395 omap_timer.dyn_tick = &omap_dyn_tick_timer;
396#endif
397
358 setup_irq(INT_OS_TIMER, &omap_32k_timer_irq); 398 setup_irq(INT_OS_TIMER, &omap_32k_timer_irq);
359 omap_timer.offset = omap_32k_timer_gettimeoffset; 399 omap_timer.offset = omap_32k_timer_gettimeoffset;
360 omap_32k_last_tick = omap_32k_sync_timer_read(); 400 omap_32k_last_tick = omap_32k_sync_timer_read();
diff --git a/arch/arm/mach-omap/usb.c b/arch/arm/mach-omap/usb.c
index 6e805d451d0e..7f37857b1a28 100644
--- a/arch/arm/mach-omap/usb.c
+++ b/arch/arm/mach-omap/usb.c
@@ -288,8 +288,8 @@ static void usb_release(struct device *dev)
288static struct resource udc_resources[] = { 288static struct resource udc_resources[] = {
289 /* order is significant! */ 289 /* order is significant! */
290 { /* registers */ 290 { /* registers */
291 .start = IO_ADDRESS(UDC_BASE), 291 .start = UDC_BASE,
292 .end = IO_ADDRESS(UDC_BASE + 0xff), 292 .end = UDC_BASE + 0xff,
293 .flags = IORESOURCE_MEM, 293 .flags = IORESOURCE_MEM,
294 }, { /* general IRQ */ 294 }, { /* general IRQ */
295 .start = IH2_BASE + 20, 295 .start = IH2_BASE + 20,
@@ -355,8 +355,8 @@ static struct platform_device ohci_device = {
355static struct resource otg_resources[] = { 355static struct resource otg_resources[] = {
356 /* order is significant! */ 356 /* order is significant! */
357 { 357 {
358 .start = IO_ADDRESS(OTG_BASE), 358 .start = OTG_BASE,
359 .end = IO_ADDRESS(OTG_BASE + 0xff), 359 .end = OTG_BASE + 0xff,
360 .flags = IORESOURCE_MEM, 360 .flags = IORESOURCE_MEM,
361 }, { 361 }, {
362 .start = IH2_BASE + 8, 362 .start = IH2_BASE + 8,
diff --git a/arch/arm/mach-pxa/time.c b/arch/arm/mach-pxa/time.c
index 473fb6173f72..6e5202154f91 100644
--- a/arch/arm/mach-pxa/time.c
+++ b/arch/arm/mach-pxa/time.c
@@ -105,8 +105,8 @@ pxa_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
105 105
106static struct irqaction pxa_timer_irq = { 106static struct irqaction pxa_timer_irq = {
107 .name = "PXA Timer Tick", 107 .name = "PXA Timer Tick",
108 .flags = SA_INTERRUPT, 108 .flags = SA_INTERRUPT | SA_TIMER,
109 .handler = pxa_timer_interrupt 109 .handler = pxa_timer_interrupt,
110}; 110};
111 111
112static void __init pxa_timer_init(void) 112static void __init pxa_timer_init(void)
diff --git a/arch/arm/mach-s3c2410/Kconfig b/arch/arm/mach-s3c2410/Kconfig
index 534df0c6c770..d4d03d0daaec 100644
--- a/arch/arm/mach-s3c2410/Kconfig
+++ b/arch/arm/mach-s3c2410/Kconfig
@@ -154,6 +154,11 @@ config S3C2410_PM_CHECK_CHUNKSIZE
154 the CRC data block will take more memory, but wil identify any 154 the CRC data block will take more memory, but wil identify any
155 faults with better precision. 155 faults with better precision.
156 156
157config PM_SIMTEC
158 bool
159 depends on PM && (ARCH_BAST || MACH_VR1000)
160 default y
161
157config S3C2410_LOWLEVEL_UART_PORT 162config S3C2410_LOWLEVEL_UART_PORT
158 int "S3C2410 UART to use for low-level messages" 163 int "S3C2410 UART to use for low-level messages"
159 default 0 164 default 0
diff --git a/arch/arm/mach-s3c2410/Makefile b/arch/arm/mach-s3c2410/Makefile
index 7c379aad5d62..f99b689e4392 100644
--- a/arch/arm/mach-s3c2410/Makefile
+++ b/arch/arm/mach-s3c2410/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_S3C2410_DMA) += dma.o
18# Power Management support 18# Power Management support
19 19
20obj-$(CONFIG_PM) += pm.o sleep.o 20obj-$(CONFIG_PM) += pm.o sleep.o
21obj-$(CONFIG_PM_SIMTEC) += pm-simtec.o
21 22
22# S3C2440 support 23# S3C2440 support
23 24
diff --git a/arch/arm/mach-s3c2410/devs.c b/arch/arm/mach-s3c2410/devs.c
index 64792f678668..4664bd11adc1 100644
--- a/arch/arm/mach-s3c2410/devs.c
+++ b/arch/arm/mach-s3c2410/devs.c
@@ -96,8 +96,8 @@ struct platform_device s3c_device_lcd = {
96 .num_resources = ARRAY_SIZE(s3c_lcd_resource), 96 .num_resources = ARRAY_SIZE(s3c_lcd_resource),
97 .resource = s3c_lcd_resource, 97 .resource = s3c_lcd_resource,
98 .dev = { 98 .dev = {
99 .dma_mask = &s3c_device_lcd_dmamask, 99 .dma_mask = &s3c_device_lcd_dmamask,
100 .coherent_dma_mask = 0xffffffffUL 100 .coherent_dma_mask = 0xffffffffUL
101 } 101 }
102}; 102};
103 103
diff --git a/arch/arm/mach-s3c2410/irq.c b/arch/arm/mach-s3c2410/irq.c
index b668c48f4399..cf9f46d88061 100644
--- a/arch/arm/mach-s3c2410/irq.c
+++ b/arch/arm/mach-s3c2410/irq.c
@@ -40,8 +40,11 @@
40 * 04-Nov-2004 Ben Dooks 40 * 04-Nov-2004 Ben Dooks
41 * Fix standard IRQ wake for EINT0..4 and RTC 41 * Fix standard IRQ wake for EINT0..4 and RTC
42 * 42 *
43 * 22-Feb-2004 Ben Dooks 43 * 22-Feb-2005 Ben Dooks
44 * Fixed edge-triggering on ADC IRQ 44 * Fixed edge-triggering on ADC IRQ
45 *
46 * 28-Jun-2005 Ben Dooks
47 * Mark IRQ_LCD valid
45*/ 48*/
46 49
47#include <linux/init.h> 50#include <linux/init.h>
@@ -366,7 +369,6 @@ static struct irqchip s3c_irq_eint0t4 = {
366#define INTMSK_UART1 (1UL << (IRQ_UART1 - IRQ_EINT0)) 369#define INTMSK_UART1 (1UL << (IRQ_UART1 - IRQ_EINT0))
367#define INTMSK_UART2 (1UL << (IRQ_UART2 - IRQ_EINT0)) 370#define INTMSK_UART2 (1UL << (IRQ_UART2 - IRQ_EINT0))
368#define INTMSK_ADCPARENT (1UL << (IRQ_ADCPARENT - IRQ_EINT0)) 371#define INTMSK_ADCPARENT (1UL << (IRQ_ADCPARENT - IRQ_EINT0))
369#define INTMSK_LCD (1UL << (IRQ_LCD - IRQ_EINT0))
370 372
371static inline void 373static inline void
372s3c_irqsub_mask(unsigned int irqno, unsigned int parentbit, 374s3c_irqsub_mask(unsigned int irqno, unsigned int parentbit,
@@ -716,7 +718,6 @@ void __init s3c24xx_init_irq(void)
716 case IRQ_UART0: 718 case IRQ_UART0:
717 case IRQ_UART1: 719 case IRQ_UART1:
718 case IRQ_UART2: 720 case IRQ_UART2:
719 case IRQ_LCD:
720 case IRQ_ADCPARENT: 721 case IRQ_ADCPARENT:
721 set_irq_chip(irqno, &s3c_irq_level_chip); 722 set_irq_chip(irqno, &s3c_irq_level_chip);
722 set_irq_handler(irqno, do_level_IRQ); 723 set_irq_handler(irqno, do_level_IRQ);
diff --git a/arch/arm/mach-s3c2410/mach-bast.c b/arch/arm/mach-s3c2410/mach-bast.c
index f3e970039b65..549bcb1f32c0 100644
--- a/arch/arm/mach-s3c2410/mach-bast.c
+++ b/arch/arm/mach-s3c2410/mach-bast.c
@@ -27,6 +27,7 @@
27 * 10-Mar-2005 LCVR Changed S3C2410_VA to S3C24XX_VA 27 * 10-Mar-2005 LCVR Changed S3C2410_VA to S3C24XX_VA
28 * 14-Mar-2006 BJD Updated for __iomem changes 28 * 14-Mar-2006 BJD Updated for __iomem changes
29 * 22-Jun-2006 BJD Added DM9000 platform information 29 * 22-Jun-2006 BJD Added DM9000 platform information
30 * 28-Jun-2006 BJD Moved pm functionality out to common code
30*/ 31*/
31 32
32#include <linux/kernel.h> 33#include <linux/kernel.h>
@@ -67,7 +68,6 @@
67#include "devs.h" 68#include "devs.h"
68#include "cpu.h" 69#include "cpu.h"
69#include "usb-simtec.h" 70#include "usb-simtec.h"
70#include "pm.h"
71 71
72#define COPYRIGHT ", (c) 2004-2005 Simtec Electronics" 72#define COPYRIGHT ", (c) 2004-2005 Simtec Electronics"
73 73
@@ -405,44 +405,13 @@ void __init bast_map_io(void)
405 usb_simtec_init(); 405 usb_simtec_init();
406} 406}
407 407
408void __init bast_init_irq(void)
409{
410 s3c24xx_init_irq();
411}
412
413#ifdef CONFIG_PM
414
415/* bast_init_machine
416 *
417 * enable the power management functions for the EB2410ITX
418*/
419
420static __init void bast_init_machine(void)
421{
422 unsigned long gstatus4;
423
424 printk(KERN_INFO "BAST Power Manangement" COPYRIGHT "\n");
425
426 gstatus4 = (__raw_readl(S3C2410_BANKCON7) & 0x3) << 30;
427 gstatus4 |= (__raw_readl(S3C2410_BANKCON6) & 0x3) << 28;
428 gstatus4 |= (__raw_readl(S3C2410_BANKSIZE) & S3C2410_BANKSIZE_MASK);
429
430 __raw_writel(gstatus4, S3C2410_GSTATUS4);
431
432 s3c2410_pm_init();
433}
434
435#else
436#define bast_init_machine NULL
437#endif
438
439 408
440MACHINE_START(BAST, "Simtec-BAST") 409MACHINE_START(BAST, "Simtec-BAST")
441 MAINTAINER("Ben Dooks <ben@simtec.co.uk>") 410 MAINTAINER("Ben Dooks <ben@simtec.co.uk>")
442 BOOT_MEM(S3C2410_SDRAM_PA, S3C2410_PA_UART, (u32)S3C24XX_VA_UART) 411 BOOT_MEM(S3C2410_SDRAM_PA, S3C2410_PA_UART, (u32)S3C24XX_VA_UART)
443 BOOT_PARAMS(S3C2410_SDRAM_PA + 0x100) 412 BOOT_PARAMS(S3C2410_SDRAM_PA + 0x100)
444 MAPIO(bast_map_io) 413
445 INITIRQ(bast_init_irq) 414 .map_io = bast_map_io,
446 .init_machine = bast_init_machine, 415 .init_irq = s3c24xx_init_irq,
447 .timer = &s3c24xx_timer, 416 .timer = &s3c24xx_timer,
448MACHINE_END 417MACHINE_END
diff --git a/arch/arm/mach-s3c2410/mach-vr1000.c b/arch/arm/mach-s3c2410/mach-vr1000.c
index 76be074944a0..1db2855e3e56 100644
--- a/arch/arm/mach-s3c2410/mach-vr1000.c
+++ b/arch/arm/mach-s3c2410/mach-vr1000.c
@@ -371,16 +371,12 @@ void __init vr1000_map_io(void)
371 usb_simtec_init(); 371 usb_simtec_init();
372} 372}
373 373
374void __init vr1000_init_irq(void)
375{
376 s3c24xx_init_irq();
377}
378 374
379MACHINE_START(VR1000, "Thorcom-VR1000") 375MACHINE_START(VR1000, "Thorcom-VR1000")
380 MAINTAINER("Ben Dooks <ben@simtec.co.uk>") 376 MAINTAINER("Ben Dooks <ben@simtec.co.uk>")
381 BOOT_MEM(S3C2410_SDRAM_PA, S3C2410_PA_UART, (u32)S3C24XX_VA_UART) 377 BOOT_MEM(S3C2410_SDRAM_PA, S3C2410_PA_UART, (u32)S3C24XX_VA_UART)
382 BOOT_PARAMS(S3C2410_SDRAM_PA + 0x100) 378 BOOT_PARAMS(S3C2410_SDRAM_PA + 0x100)
383 MAPIO(vr1000_map_io) 379 .map_io = vr1000_map_io,
384 INITIRQ(vr1000_init_irq) 380 .init_irq = s3c24xx_init_irq,
385 .timer = &s3c24xx_timer, 381 .timer = &s3c24xx_timer,
386MACHINE_END 382MACHINE_END
diff --git a/arch/arm/mach-s3c2410/pm-simtec.c b/arch/arm/mach-s3c2410/pm-simtec.c
new file mode 100644
index 000000000000..2cb798832223
--- /dev/null
+++ b/arch/arm/mach-s3c2410/pm-simtec.c
@@ -0,0 +1,65 @@
1/* linux/arch/arm/mach-s3c2410/pm-simtec.c
2 *
3 * Copyright (c) 2004 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * http://armlinux.simtec.co.uk/
7 *
8 * Power Management helpers for Simtec S3C24XX implementations
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 version 2 as
12 * published by the Free Software Foundation.
13*/
14
15#include <linux/kernel.h>
16#include <linux/types.h>
17#include <linux/interrupt.h>
18#include <linux/list.h>
19#include <linux/timer.h>
20#include <linux/init.h>
21#include <linux/device.h>
22
23#include <asm/mach/arch.h>
24#include <asm/mach/map.h>
25
26#include <asm/hardware.h>
27#include <asm/io.h>
28
29#include <asm/arch/map.h>
30#include <asm/arch/regs-serial.h>
31#include <asm/arch/regs-gpio.h>
32#include <asm/arch/regs-mem.h>
33
34#include <asm/mach-types.h>
35
36#include "pm.h"
37
38#define COPYRIGHT ", (c) 2005 Simtec Electronics"
39
40/* pm_simtec_init
41 *
42 * enable the power management functions
43*/
44
45static __init int pm_simtec_init(void)
46{
47 unsigned long gstatus4;
48
49 /* check which machine we are running on */
50
51 if (!machine_is_bast() && !machine_is_vr1000())
52 return 0;
53
54 printk(KERN_INFO "Simtec Board Power Manangement" COPYRIGHT "\n");
55
56 gstatus4 = (__raw_readl(S3C2410_BANKCON7) & 0x3) << 30;
57 gstatus4 |= (__raw_readl(S3C2410_BANKCON6) & 0x3) << 28;
58 gstatus4 |= (__raw_readl(S3C2410_BANKSIZE) & S3C2410_BANKSIZE_MASK);
59
60 __raw_writel(gstatus4, S3C2410_GSTATUS4);
61
62 return s3c2410_pm_init();
63}
64
65arch_initcall(pm_simtec_init);
diff --git a/arch/arm/mach-s3c2410/time.c b/arch/arm/mach-s3c2410/time.c
index 179f0e031af4..765a3a9ae032 100644
--- a/arch/arm/mach-s3c2410/time.c
+++ b/arch/arm/mach-s3c2410/time.c
@@ -137,8 +137,8 @@ s3c2410_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
137 137
138static struct irqaction s3c2410_timer_irq = { 138static struct irqaction s3c2410_timer_irq = {
139 .name = "S3C2410 Timer Tick", 139 .name = "S3C2410 Timer Tick",
140 .flags = SA_INTERRUPT, 140 .flags = SA_INTERRUPT | SA_TIMER,
141 .handler = s3c2410_timer_interrupt 141 .handler = s3c2410_timer_interrupt,
142}; 142};
143 143
144/* 144/*
diff --git a/arch/arm/mach-sa1100/h3600.c b/arch/arm/mach-sa1100/h3600.c
index 84c86543501a..65dbe991426d 100644
--- a/arch/arm/mach-sa1100/h3600.c
+++ b/arch/arm/mach-sa1100/h3600.c
@@ -727,7 +727,7 @@ static void h3800_IRQ_demux(unsigned int irq, struct irqdesc *desc, struct pt_re
727static struct irqaction h3800_irq = { 727static struct irqaction h3800_irq = {
728 .name = "h3800_asic", 728 .name = "h3800_asic",
729 .handler = h3800_IRQ_demux, 729 .handler = h3800_IRQ_demux,
730 .flags = SA_INTERRUPT, 730 .flags = SA_INTERRUPT | SA_TIMER,
731}; 731};
732 732
733u32 kpio_int_shadow = 0; 733u32 kpio_int_shadow = 0;
diff --git a/arch/arm/mach-sa1100/time.c b/arch/arm/mach-sa1100/time.c
index 19b0c0fd6377..0eeb3616ffea 100644
--- a/arch/arm/mach-sa1100/time.c
+++ b/arch/arm/mach-sa1100/time.c
@@ -99,8 +99,8 @@ sa1100_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
99 99
100static struct irqaction sa1100_timer_irq = { 100static struct irqaction sa1100_timer_irq = {
101 .name = "SA11xx Timer Tick", 101 .name = "SA11xx Timer Tick",
102 .flags = SA_INTERRUPT, 102 .flags = SA_INTERRUPT | SA_TIMER,
103 .handler = sa1100_timer_interrupt 103 .handler = sa1100_timer_interrupt,
104}; 104};
105 105
106static void __init sa1100_timer_init(void) 106static void __init sa1100_timer_init(void)
diff --git a/arch/arm/mach-shark/core.c b/arch/arm/mach-shark/core.c
index a9bc5d0dbd85..aa0e2f6e02f6 100644
--- a/arch/arm/mach-shark/core.c
+++ b/arch/arm/mach-shark/core.c
@@ -84,8 +84,8 @@ shark_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
84 84
85static struct irqaction shark_timer_irq = { 85static struct irqaction shark_timer_irq = {
86 .name = "Shark Timer Tick", 86 .name = "Shark Timer Tick",
87 .flags = SA_INTERRUPT, 87 .flags = SA_INTERRUPT | SA_TIMER,
88 .handler = shark_timer_interrupt 88 .handler = shark_timer_interrupt,
89}; 89};
90 90
91/* 91/*
diff --git a/arch/arm/mach-versatile/core.c b/arch/arm/mach-versatile/core.c
index 6a7cbea5e098..f01c0f8a2bb3 100644
--- a/arch/arm/mach-versatile/core.c
+++ b/arch/arm/mach-versatile/core.c
@@ -33,6 +33,7 @@
33#include <asm/mach-types.h> 33#include <asm/mach-types.h>
34#include <asm/hardware/amba.h> 34#include <asm/hardware/amba.h>
35#include <asm/hardware/amba_clcd.h> 35#include <asm/hardware/amba_clcd.h>
36#include <asm/hardware/arm_timer.h>
36#include <asm/hardware/icst307.h> 37#include <asm/hardware/icst307.h>
37 38
38#include <asm/mach/arch.h> 39#include <asm/mach/arch.h>
@@ -788,38 +789,25 @@ void __init versatile_init(void)
788 */ 789 */
789#define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10) 790#define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
790#if TIMER_INTERVAL >= 0x100000 791#if TIMER_INTERVAL >= 0x100000
791#define TIMER_RELOAD (TIMER_INTERVAL >> 8) /* Divide by 256 */ 792#define TIMER_RELOAD (TIMER_INTERVAL >> 8)
792#define TIMER_CTRL 0x88 /* Enable, Clock / 256 */ 793#define TIMER_DIVISOR (TIMER_CTRL_DIV256)
793#define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC) 794#define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
794#elif TIMER_INTERVAL >= 0x10000 795#elif TIMER_INTERVAL >= 0x10000
795#define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */ 796#define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
796#define TIMER_CTRL 0x84 /* Enable, Clock / 16 */ 797#define TIMER_DIVISOR (TIMER_CTRL_DIV16)
797#define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC) 798#define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
798#else 799#else
799#define TIMER_RELOAD (TIMER_INTERVAL) 800#define TIMER_RELOAD (TIMER_INTERVAL)
800#define TIMER_CTRL 0x80 /* Enable */ 801#define TIMER_DIVISOR (TIMER_CTRL_DIV1)
801#define TICKS2USECS(x) ((x) / TICKS_PER_uSEC) 802#define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
802#endif 803#endif
803 804
804#define TIMER_CTRL_IE (1 << 5) /* Interrupt Enable */
805
806/*
807 * What does it look like?
808 */
809typedef struct TimerStruct {
810 unsigned long TimerLoad;
811 unsigned long TimerValue;
812 unsigned long TimerControl;
813 unsigned long TimerClear;
814} TimerStruct_t;
815
816/* 805/*
817 * Returns number of ms since last clock interrupt. Note that interrupts 806 * Returns number of ms since last clock interrupt. Note that interrupts
818 * will have been disabled by do_gettimeoffset() 807 * will have been disabled by do_gettimeoffset()
819 */ 808 */
820static unsigned long versatile_gettimeoffset(void) 809static unsigned long versatile_gettimeoffset(void)
821{ 810{
822 volatile TimerStruct_t *timer0 = (TimerStruct_t *)TIMER0_VA_BASE;
823 unsigned long ticks1, ticks2, status; 811 unsigned long ticks1, ticks2, status;
824 812
825 /* 813 /*
@@ -828,11 +816,11 @@ static unsigned long versatile_gettimeoffset(void)
828 * an interrupt. We get around this by ensuring that the 816 * an interrupt. We get around this by ensuring that the
829 * counter has not reloaded between our two reads. 817 * counter has not reloaded between our two reads.
830 */ 818 */
831 ticks2 = timer0->TimerValue & 0xffff; 819 ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
832 do { 820 do {
833 ticks1 = ticks2; 821 ticks1 = ticks2;
834 status = __raw_readl(VA_IC_BASE + VIC_IRQ_RAW_STATUS); 822 status = __raw_readl(VA_IC_BASE + VIC_IRQ_RAW_STATUS);
835 ticks2 = timer0->TimerValue & 0xffff; 823 ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
836 } while (ticks2 > ticks1); 824 } while (ticks2 > ticks1);
837 825
838 /* 826 /*
@@ -859,12 +847,10 @@ static unsigned long versatile_gettimeoffset(void)
859 */ 847 */
860static irqreturn_t versatile_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs) 848static irqreturn_t versatile_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
861{ 849{
862 volatile TimerStruct_t *timer0 = (volatile TimerStruct_t *)TIMER0_VA_BASE;
863
864 write_seqlock(&xtime_lock); 850 write_seqlock(&xtime_lock);
865 851
866 // ...clear the interrupt 852 // ...clear the interrupt
867 timer0->TimerClear = 1; 853 writel(1, TIMER0_VA_BASE + TIMER_INTCLR);
868 854
869 timer_tick(regs); 855 timer_tick(regs);
870 856
@@ -875,8 +861,8 @@ static irqreturn_t versatile_timer_interrupt(int irq, void *dev_id, struct pt_re
875 861
876static struct irqaction versatile_timer_irq = { 862static struct irqaction versatile_timer_irq = {
877 .name = "Versatile Timer Tick", 863 .name = "Versatile Timer Tick",
878 .flags = SA_INTERRUPT, 864 .flags = SA_INTERRUPT | SA_TIMER,
879 .handler = versatile_timer_interrupt 865 .handler = versatile_timer_interrupt,
880}; 866};
881 867
882/* 868/*
@@ -884,31 +870,32 @@ static struct irqaction versatile_timer_irq = {
884 */ 870 */
885static void __init versatile_timer_init(void) 871static void __init versatile_timer_init(void)
886{ 872{
887 volatile TimerStruct_t *timer0 = (volatile TimerStruct_t *)TIMER0_VA_BASE; 873 u32 val;
888 volatile TimerStruct_t *timer1 = (volatile TimerStruct_t *)TIMER1_VA_BASE;
889 volatile TimerStruct_t *timer2 = (volatile TimerStruct_t *)TIMER2_VA_BASE;
890 volatile TimerStruct_t *timer3 = (volatile TimerStruct_t *)TIMER3_VA_BASE;
891 874
892 /* 875 /*
893 * set clock frequency: 876 * set clock frequency:
894 * VERSATILE_REFCLK is 32KHz 877 * VERSATILE_REFCLK is 32KHz
895 * VERSATILE_TIMCLK is 1MHz 878 * VERSATILE_TIMCLK is 1MHz
896 */ 879 */
897 *(volatile unsigned int *)IO_ADDRESS(VERSATILE_SCTL_BASE) |= 880 val = readl(IO_ADDRESS(VERSATILE_SCTL_BASE));
898 ((VERSATILE_TIMCLK << VERSATILE_TIMER1_EnSel) | (VERSATILE_TIMCLK << VERSATILE_TIMER2_EnSel) | 881 writel((VERSATILE_TIMCLK << VERSATILE_TIMER1_EnSel) |
899 (VERSATILE_TIMCLK << VERSATILE_TIMER3_EnSel) | (VERSATILE_TIMCLK << VERSATILE_TIMER4_EnSel)); 882 (VERSATILE_TIMCLK << VERSATILE_TIMER2_EnSel) |
883 (VERSATILE_TIMCLK << VERSATILE_TIMER3_EnSel) |
884 (VERSATILE_TIMCLK << VERSATILE_TIMER4_EnSel) | val,
885 IO_ADDRESS(VERSATILE_SCTL_BASE));
900 886
901 /* 887 /*
902 * Initialise to a known state (all timers off) 888 * Initialise to a known state (all timers off)
903 */ 889 */
904 timer0->TimerControl = 0; 890 writel(0, TIMER0_VA_BASE + TIMER_CTRL);
905 timer1->TimerControl = 0; 891 writel(0, TIMER1_VA_BASE + TIMER_CTRL);
906 timer2->TimerControl = 0; 892 writel(0, TIMER2_VA_BASE + TIMER_CTRL);
907 timer3->TimerControl = 0; 893 writel(0, TIMER3_VA_BASE + TIMER_CTRL);
908 894
909 timer0->TimerLoad = TIMER_RELOAD; 895 writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_LOAD);
910 timer0->TimerValue = TIMER_RELOAD; 896 writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_VALUE);
911 timer0->TimerControl = TIMER_CTRL | 0x40 | TIMER_CTRL_IE; /* periodic + IE */ 897 writel(TIMER_DIVISOR | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC |
898 TIMER_CTRL_IE, TIMER0_VA_BASE + TIMER_CTRL);
912 899
913 /* 900 /*
914 * Make irqs happen for the system timer 901 * Make irqs happen for the system timer
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index c08710b1ff02..edffa47a4b2a 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -437,7 +437,7 @@ void __init paging_init(struct meminfo *mi, struct machine_desc *mdesc)
437 memtable_init(mi); 437 memtable_init(mi);
438 if (mdesc->map_io) 438 if (mdesc->map_io)
439 mdesc->map_io(); 439 mdesc->map_io();
440 flush_tlb_all(); 440 local_flush_tlb_all();
441 441
442 /* 442 /*
443 * initialise the zones within each node 443 * initialise the zones within each node
@@ -522,6 +522,69 @@ static inline void free_area(unsigned long addr, unsigned long end, char *s)
522 printk(KERN_INFO "Freeing %s memory: %dK\n", s, size); 522 printk(KERN_INFO "Freeing %s memory: %dK\n", s, size);
523} 523}
524 524
525static inline void
526free_memmap(int node, unsigned long start_pfn, unsigned long end_pfn)
527{
528 struct page *start_pg, *end_pg;
529 unsigned long pg, pgend;
530
531 /*
532 * Convert start_pfn/end_pfn to a struct page pointer.
533 */
534 start_pg = pfn_to_page(start_pfn);
535 end_pg = pfn_to_page(end_pfn);
536
537 /*
538 * Convert to physical addresses, and
539 * round start upwards and end downwards.
540 */
541 pg = PAGE_ALIGN(__pa(start_pg));
542 pgend = __pa(end_pg) & PAGE_MASK;
543
544 /*
545 * If there are free pages between these,
546 * free the section of the memmap array.
547 */
548 if (pg < pgend)
549 free_bootmem_node(NODE_DATA(node), pg, pgend - pg);
550}
551
552/*
553 * The mem_map array can get very big. Free the unused area of the memory map.
554 */
555static void __init free_unused_memmap_node(int node, struct meminfo *mi)
556{
557 unsigned long bank_start, prev_bank_end = 0;
558 unsigned int i;
559
560 /*
561 * [FIXME] This relies on each bank being in address order. This
562 * may not be the case, especially if the user has provided the
563 * information on the command line.
564 */
565 for (i = 0; i < mi->nr_banks; i++) {
566 if (mi->bank[i].size == 0 || mi->bank[i].node != node)
567 continue;
568
569 bank_start = mi->bank[i].start >> PAGE_SHIFT;
570 if (bank_start < prev_bank_end) {
571 printk(KERN_ERR "MEM: unordered memory banks. "
572 "Not freeing memmap.\n");
573 break;
574 }
575
576 /*
577 * If we had a previous bank, and there is a space
578 * between the current bank and the previous, free it.
579 */
580 if (prev_bank_end && prev_bank_end != bank_start)
581 free_memmap(node, prev_bank_end, bank_start);
582
583 prev_bank_end = (mi->bank[i].start +
584 mi->bank[i].size) >> PAGE_SHIFT;
585 }
586}
587
525/* 588/*
526 * mem_init() marks the free areas in the mem_map and tells us how much 589 * mem_init() marks the free areas in the mem_map and tells us how much
527 * memory is free. This is done after various parts of the system have 590 * memory is free. This is done after various parts of the system have
@@ -540,16 +603,12 @@ void __init mem_init(void)
540 max_mapnr = virt_to_page(high_memory) - mem_map; 603 max_mapnr = virt_to_page(high_memory) - mem_map;
541#endif 604#endif
542 605
543 /*
544 * We may have non-contiguous memory.
545 */
546 if (meminfo.nr_banks != 1)
547 create_memmap_holes(&meminfo);
548
549 /* this will put all unused low memory onto the freelists */ 606 /* this will put all unused low memory onto the freelists */
550 for_each_online_node(node) { 607 for_each_online_node(node) {
551 pg_data_t *pgdat = NODE_DATA(node); 608 pg_data_t *pgdat = NODE_DATA(node);
552 609
610 free_unused_memmap_node(node, &meminfo);
611
553 if (pgdat->node_spanned_pages != 0) 612 if (pgdat->node_spanned_pages != 0)
554 totalram_pages += free_all_bootmem_node(pgdat); 613 totalram_pages += free_all_bootmem_node(pgdat);
555 } 614 }
diff --git a/arch/arm/mm/mm-armv.c b/arch/arm/mm/mm-armv.c
index 2c2b93d77d43..c3bd503b43a2 100644
--- a/arch/arm/mm/mm-armv.c
+++ b/arch/arm/mm/mm-armv.c
@@ -169,7 +169,14 @@ pgd_t *get_pgd_slow(struct mm_struct *mm)
169 169
170 memzero(new_pgd, FIRST_KERNEL_PGD_NR * sizeof(pgd_t)); 170 memzero(new_pgd, FIRST_KERNEL_PGD_NR * sizeof(pgd_t));
171 171
172 /*
173 * Copy over the kernel and IO PGD entries
174 */
172 init_pgd = pgd_offset_k(0); 175 init_pgd = pgd_offset_k(0);
176 memcpy(new_pgd + FIRST_KERNEL_PGD_NR, init_pgd + FIRST_KERNEL_PGD_NR,
177 (PTRS_PER_PGD - FIRST_KERNEL_PGD_NR) * sizeof(pgd_t));
178
179 clean_dcache_area(new_pgd, PTRS_PER_PGD * sizeof(pgd_t));
173 180
174 if (!vectors_high()) { 181 if (!vectors_high()) {
175 /* 182 /*
@@ -198,14 +205,6 @@ pgd_t *get_pgd_slow(struct mm_struct *mm)
198 spin_unlock(&mm->page_table_lock); 205 spin_unlock(&mm->page_table_lock);
199 } 206 }
200 207
201 /*
202 * Copy over the kernel and IO PGD entries
203 */
204 memcpy(new_pgd + FIRST_KERNEL_PGD_NR, init_pgd + FIRST_KERNEL_PGD_NR,
205 (PTRS_PER_PGD - FIRST_KERNEL_PGD_NR) * sizeof(pgd_t));
206
207 clean_dcache_area(new_pgd, PTRS_PER_PGD * sizeof(pgd_t));
208
209 return new_pgd; 208 return new_pgd;
210 209
211no_pte: 210no_pte:
@@ -683,7 +682,7 @@ void __init memtable_init(struct meminfo *mi)
683 } 682 }
684 683
685 flush_cache_all(); 684 flush_cache_all();
686 flush_tlb_all(); 685 local_flush_tlb_all();
687 686
688 top_pmd = pmd_off_k(0xffff0000); 687 top_pmd = pmd_off_k(0xffff0000);
689} 688}
@@ -698,75 +697,3 @@ void __init iotable_init(struct map_desc *io_desc, int nr)
698 for (i = 0; i < nr; i++) 697 for (i = 0; i < nr; i++)
699 create_mapping(io_desc + i); 698 create_mapping(io_desc + i);
700} 699}
701
702static inline void
703free_memmap(int node, unsigned long start_pfn, unsigned long end_pfn)
704{
705 struct page *start_pg, *end_pg;
706 unsigned long pg, pgend;
707
708 /*
709 * Convert start_pfn/end_pfn to a struct page pointer.
710 */
711 start_pg = pfn_to_page(start_pfn);
712 end_pg = pfn_to_page(end_pfn);
713
714 /*
715 * Convert to physical addresses, and
716 * round start upwards and end downwards.
717 */
718 pg = PAGE_ALIGN(__pa(start_pg));
719 pgend = __pa(end_pg) & PAGE_MASK;
720
721 /*
722 * If there are free pages between these,
723 * free the section of the memmap array.
724 */
725 if (pg < pgend)
726 free_bootmem_node(NODE_DATA(node), pg, pgend - pg);
727}
728
729static inline void free_unused_memmap_node(int node, struct meminfo *mi)
730{
731 unsigned long bank_start, prev_bank_end = 0;
732 unsigned int i;
733
734 /*
735 * [FIXME] This relies on each bank being in address order. This
736 * may not be the case, especially if the user has provided the
737 * information on the command line.
738 */
739 for (i = 0; i < mi->nr_banks; i++) {
740 if (mi->bank[i].size == 0 || mi->bank[i].node != node)
741 continue;
742
743 bank_start = mi->bank[i].start >> PAGE_SHIFT;
744 if (bank_start < prev_bank_end) {
745 printk(KERN_ERR "MEM: unordered memory banks. "
746 "Not freeing memmap.\n");
747 break;
748 }
749
750 /*
751 * If we had a previous bank, and there is a space
752 * between the current bank and the previous, free it.
753 */
754 if (prev_bank_end && prev_bank_end != bank_start)
755 free_memmap(node, prev_bank_end, bank_start);
756
757 prev_bank_end = PAGE_ALIGN(mi->bank[i].start +
758 mi->bank[i].size) >> PAGE_SHIFT;
759 }
760}
761
762/*
763 * The mem_map array can get very big. Free
764 * the unused area of the memory map.
765 */
766void __init create_memmap_holes(struct meminfo *mi)
767{
768 int node;
769
770 for_each_online_node(node)
771 free_unused_memmap_node(node, mi);
772}
diff --git a/arch/arm/oprofile/Makefile b/arch/arm/oprofile/Makefile
index ba1a6e9f2b28..8ffb523e6c77 100644
--- a/arch/arm/oprofile/Makefile
+++ b/arch/arm/oprofile/Makefile
@@ -6,6 +6,6 @@ DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \
6 oprofilefs.o oprofile_stats.o \ 6 oprofilefs.o oprofile_stats.o \
7 timer_int.o ) 7 timer_int.o )
8 8
9oprofile-y := $(DRIVER_OBJS) init.o 9oprofile-y := $(DRIVER_OBJS) init.o backtrace.o
10oprofile-$(CONFIG_CPU_XSCALE) += common.o op_model_xscale.o 10oprofile-$(CONFIG_CPU_XSCALE) += common.o op_model_xscale.o
11 11
diff --git a/arch/arm/oprofile/backtrace.c b/arch/arm/oprofile/backtrace.c
new file mode 100644
index 000000000000..ec58d3e2eb8b
--- /dev/null
+++ b/arch/arm/oprofile/backtrace.c
@@ -0,0 +1,144 @@
1/*
2 * Arm specific backtracing code for oprofile
3 *
4 * Copyright 2005 Openedhand Ltd.
5 *
6 * Author: Richard Purdie <rpurdie@openedhand.com>
7 *
8 * Based on i386 oprofile backtrace code by John Levon, David Smith
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 version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15
16#include <linux/oprofile.h>
17#include <linux/sched.h>
18#include <linux/mm.h>
19#include <asm/ptrace.h>
20#include <asm/uaccess.h>
21
22
23/*
24 * The registers we're interested in are at the end of the variable
25 * length saved register structure. The fp points at the end of this
26 * structure so the address of this struct is:
27 * (struct frame_tail *)(xxx->fp)-1
28 */
29struct frame_tail {
30 struct frame_tail *fp;
31 unsigned long sp;
32 unsigned long lr;
33} __attribute__((packed));
34
35
36#ifdef CONFIG_FRAME_POINTER
37static struct frame_tail* kernel_backtrace(struct frame_tail *tail)
38{
39 oprofile_add_trace(tail->lr);
40
41 /* frame pointers should strictly progress back up the stack
42 * (towards higher addresses) */
43 if (tail >= tail->fp)
44 return NULL;
45
46 return tail->fp-1;
47}
48#endif
49
50static struct frame_tail* user_backtrace(struct frame_tail *tail)
51{
52 struct frame_tail buftail;
53
54 /* hardware pte might not be valid due to dirty/accessed bit emulation
55 * so we use copy_from_user and benefit from exception fixups */
56 if (copy_from_user(&buftail, tail, sizeof(struct frame_tail)))
57 return NULL;
58
59 oprofile_add_trace(buftail.lr);
60
61 /* frame pointers should strictly progress back up the stack
62 * (towards higher addresses) */
63 if (tail >= buftail.fp)
64 return NULL;
65
66 return buftail.fp-1;
67}
68
69/* Compare two addresses and see if they're on the same page */
70#define CMP_ADDR_EQUAL(x,y,offset) ((((unsigned long) x) >> PAGE_SHIFT) \
71 == ((((unsigned long) y) + offset) >> PAGE_SHIFT))
72
73/* check that the page(s) containing the frame tail are present */
74static int pages_present(struct frame_tail *tail)
75{
76 struct mm_struct * mm = current->mm;
77
78 if (!check_user_page_readable(mm, (unsigned long)tail))
79 return 0;
80
81 if (CMP_ADDR_EQUAL(tail, tail, 8))
82 return 1;
83
84 if (!check_user_page_readable(mm, ((unsigned long)tail) + 8))
85 return 0;
86
87 return 1;
88}
89
90/*
91 * | | /\ Higher addresses
92 * | |
93 * --------------- stack base (address of current_thread_info)
94 * | thread info |
95 * . .
96 * | stack |
97 * --------------- saved regs->ARM_fp value if valid (frame_tail address)
98 * . .
99 * --------------- struct pt_regs stored on stack (struct pt_regs *)
100 * | |
101 * . .
102 * | |
103 * --------------- %esp
104 * | |
105 * | | \/ Lower addresses
106 *
107 * Thus, &pt_regs <-> stack base restricts the valid(ish) fp values
108 */
109static int valid_kernel_stack(struct frame_tail *tail, struct pt_regs *regs)
110{
111 unsigned long tailaddr = (unsigned long)tail;
112 unsigned long stack = (unsigned long)regs;
113 unsigned long stack_base = (stack & ~(THREAD_SIZE - 1)) + THREAD_SIZE;
114
115 return (tailaddr > stack) && (tailaddr < stack_base);
116}
117
118void arm_backtrace(struct pt_regs const *regs, unsigned int depth)
119{
120 struct frame_tail *tail;
121 unsigned long last_address = 0;
122
123 tail = ((struct frame_tail *) regs->ARM_fp) - 1;
124
125 if (!user_mode(regs)) {
126
127#ifdef CONFIG_FRAME_POINTER
128 while (depth-- && tail && valid_kernel_stack(tail, regs)) {
129 tail = kernel_backtrace(tail);
130 }
131#endif
132 return;
133 }
134
135 while (depth-- && tail && !((unsigned long) tail & 3)) {
136 if ((!CMP_ADDR_EQUAL(last_address, tail, 0)
137 || !CMP_ADDR_EQUAL(last_address, tail, 8))
138 && !pages_present(tail))
139 return;
140 last_address = (unsigned long) tail;
141 tail = user_backtrace(tail);
142 }
143}
144
diff --git a/arch/arm/oprofile/init.c b/arch/arm/oprofile/init.c
index cce3d3015eb7..d315a3a86c86 100644
--- a/arch/arm/oprofile/init.c
+++ b/arch/arm/oprofile/init.c
@@ -20,6 +20,8 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
20 ret = pmu_init(ops, &op_xscale_spec); 20 ret = pmu_init(ops, &op_xscale_spec);
21#endif 21#endif
22 22
23 ops->backtrace = arm_backtrace;
24
23 return ret; 25 return ret;
24} 26}
25 27
diff --git a/arch/arm/oprofile/op_arm_model.h b/arch/arm/oprofile/op_arm_model.h
index 2d4caf4781ad..2148d07484b7 100644
--- a/arch/arm/oprofile/op_arm_model.h
+++ b/arch/arm/oprofile/op_arm_model.h
@@ -24,6 +24,8 @@ struct op_arm_model_spec {
24extern struct op_arm_model_spec op_xscale_spec; 24extern struct op_arm_model_spec op_xscale_spec;
25#endif 25#endif
26 26
27extern void arm_backtrace(struct pt_regs * const regs, unsigned int depth);
28
27extern int __init pmu_init(struct oprofile_operations *ops, struct op_arm_model_spec *spec); 29extern int __init pmu_init(struct oprofile_operations *ops, struct op_arm_model_spec *spec);
28extern void pmu_exit(void); 30extern void pmu_exit(void);
29#endif /* OP_ARM_MODEL_H */ 31#endif /* OP_ARM_MODEL_H */
diff --git a/arch/arm/tools/mach-types b/arch/arm/tools/mach-types
index 30c1dfbb052f..6d3a79e5fef8 100644
--- a/arch/arm/tools/mach-types
+++ b/arch/arm/tools/mach-types
@@ -6,7 +6,7 @@
6# To add an entry into this database, please see Documentation/arm/README, 6# To add an entry into this database, please see Documentation/arm/README,
7# or contact rmk@arm.linux.org.uk 7# or contact rmk@arm.linux.org.uk
8# 8#
9# Last update: Thu Mar 24 14:34:50 2005 9# Last update: Thu Jun 23 20:19:33 2005
10# 10#
11# machine_is_xxx CONFIG_xxxx MACH_TYPE_xxx number 11# machine_is_xxx CONFIG_xxxx MACH_TYPE_xxx number
12# 12#
@@ -243,7 +243,7 @@ yoho ARCH_YOHO YOHO 231
243jasper ARCH_JASPER JASPER 232 243jasper ARCH_JASPER JASPER 232
244dsc25 ARCH_DSC25 DSC25 233 244dsc25 ARCH_DSC25 DSC25 233
245omap_innovator MACH_OMAP_INNOVATOR OMAP_INNOVATOR 234 245omap_innovator MACH_OMAP_INNOVATOR OMAP_INNOVATOR 234
246ramses ARCH_RAMSES RAMSES 235 246mnci ARCH_RAMSES RAMSES 235
247s28x ARCH_S28X S28X 236 247s28x ARCH_S28X S28X 236
248mport3 ARCH_MPORT3 MPORT3 237 248mport3 ARCH_MPORT3 MPORT3 237
249pxa_eagle250 ARCH_PXA_EAGLE250 PXA_EAGLE250 238 249pxa_eagle250 ARCH_PXA_EAGLE250 PXA_EAGLE250 238
@@ -323,7 +323,7 @@ nimbra29x ARCH_NIMBRA29X NIMBRA29X 311
323nimbra210 ARCH_NIMBRA210 NIMBRA210 312 323nimbra210 ARCH_NIMBRA210 NIMBRA210 312
324hhp_d95xx ARCH_HHP_D95XX HHP_D95XX 313 324hhp_d95xx ARCH_HHP_D95XX HHP_D95XX 313
325labarm ARCH_LABARM LABARM 314 325labarm ARCH_LABARM LABARM 314
326m825xx ARCH_M825XX M825XX 315 326comcerto ARCH_M825XX M825XX 315
327m7100 SA1100_M7100 M7100 316 327m7100 SA1100_M7100 M7100 316
328nipc2 ARCH_NIPC2 NIPC2 317 328nipc2 ARCH_NIPC2 NIPC2 317
329fu7202 ARCH_FU7202 FU7202 318 329fu7202 ARCH_FU7202 FU7202 318
@@ -724,3 +724,66 @@ lpc22xx MACH_LPC22XX LPC22XX 715
724omap_comet3 MACH_COMET3 COMET3 716 724omap_comet3 MACH_COMET3 COMET3 716
725omap_comet4 MACH_COMET4 COMET4 717 725omap_comet4 MACH_COMET4 COMET4 717
726csb625 MACH_CSB625 CSB625 718 726csb625 MACH_CSB625 CSB625 718
727fortunet2 MACH_FORTUNET2 FORTUNET2 719
728s5h2200 MACH_S5H2200 S5H2200 720
729optorm920 MACH_OPTORM920 OPTORM920 721
730adsbitsyxb MACH_ADSBITSYXB ADSBITSYXB 722
731adssphere MACH_ADSSPHERE ADSSPHERE 723
732adsportal MACH_ADSPORTAL ADSPORTAL 724
733ln2410sbc MACH_LN2410SBC LN2410SBC 725
734cb3rufc MACH_CB3RUFC CB3RUFC 726
735mp2usb MACH_MP2USB MP2USB 727
736ntnp425c MACH_NTNP425C NTNP425C 728
737colibri MACH_COLIBRI COLIBRI 729
738pcm7220 MACH_PCM7220 PCM7220 730
739gateway7001 MACH_GATEWAY7001 GATEWAY7001 731
740pcm027 MACH_PCM027 PCM027 732
741cmpxa MACH_CMPXA CMPXA 733
742anubis MACH_ANUBIS ANUBIS 734
743ite8152 MACH_ITE8152 ITE8152 735
744lpc3xxx MACH_LPC3XXX LPC3XXX 736
745puppeteer MACH_PUPPETEER PUPPETEER 737
746vt001 MACH_MACH_VADATECH MACH_VADATECH 738
747e570 MACH_E570 E570 739
748x50 MACH_X50 X50 740
749recon MACH_RECON RECON 741
750xboardgp8 MACH_XBOARDGP8 XBOARDGP8 742
751fpic2 MACH_FPIC2 FPIC2 743
752akita MACH_AKITA AKITA 744
753a81 MACH_A81 A81 745
754svm_sc25x MACH_SVM_SC25X SVM_SC25X 746
755vt020 MACH_VADATECH020 VADATECH020 747
756tli MACH_TLI TLI 748
757edb9315lc MACH_EDB9315LC EDB9315LC 749
758passec MACH_PASSEC PASSEC 750
759ds_tiger MACH_DS_TIGER DS_TIGER 751
760e310 MACH_E310 E310 752
761e330 MACH_E330 E330 753
762rt3000 MACH_RT3000 RT3000 754
763nokia770 MACH_NOKIA770 NOKIA770 755
764pnx0106 MACH_PNX0106 PNX0106 756
765hx21xx MACH_HX21XX HX21XX 757
766faraday MACH_FARADAY FARADAY 758
767sbc9312 MACH_SBC9312 SBC9312 759
768batman MACH_BATMAN BATMAN 760
769jpd201 MACH_JPD201 JPD201 761
770mipsa MACH_MIPSA MIPSA 762
771kacom MACH_KACOM KACOM 763
772swarcocpu MACH_SWARCOCPU SWARCOCPU 764
773swarcodsl MACH_SWARCODSL SWARCODSL 765
774blueangel MACH_BLUEANGEL BLUEANGEL 766
775hairygrama MACH_HAIRYGRAMA HAIRYGRAMA 767
776banff MACH_BANFF BANFF 768
777carmeva MACH_CARMEVA CARMEVA 769
778sam255 MACH_SAM255 SAM255 770
779ppm10 MACH_PPM10 PPM10 771
780edb9315a MACH_EDB9315A EDB9315A 772
781sunset MACH_SUNSET SUNSET 773
782stargate2 MACH_STARGATE2 STARGATE2 774
783intelmote2 MACH_INTELMOTE2 INTELMOTE2 775
784trizeps4 MACH_TRIZEPS4 TRIZEPS4 776
785mainstone2 MACH_MAINSTONE2 MAINSTONE2 777
786ez_ixp42x MACH_EZ_IXP42X EZ_IXP42X 778
787tapwave_zodiac MACH_TAPWAVE_ZODIAC TAPWAVE_ZODIAC 779
788universalmeter MACH_UNIVERSALMETER UNIVERSALMETER 780
789hicoarm9 MACH_HICOARM9 HICOARM9 781
diff --git a/arch/arm/vfp/vfp.h b/arch/arm/vfp/vfp.h
index 55a02bc994a3..4b97950984e9 100644
--- a/arch/arm/vfp/vfp.h
+++ b/arch/arm/vfp/vfp.h
@@ -117,7 +117,13 @@ static inline u64 vfp_estimate_div128to64(u64 nh, u64 nl, u64 m)
117 if (nh >= m) 117 if (nh >= m)
118 return ~0ULL; 118 return ~0ULL;
119 mh = m >> 32; 119 mh = m >> 32;
120 z = (mh << 32 <= nh) ? 0xffffffff00000000ULL : (nh / mh) << 32; 120 if (mh << 32 <= nh) {
121 z = 0xffffffff00000000ULL;
122 } else {
123 z = nh;
124 do_div(z, mh);
125 z <<= 32;
126 }
121 mul64to128(&termh, &terml, m, z); 127 mul64to128(&termh, &terml, m, z);
122 sub128(&remh, &reml, nh, nl, termh, terml); 128 sub128(&remh, &reml, nh, nl, termh, terml);
123 ml = m << 32; 129 ml = m << 32;
@@ -126,7 +132,12 @@ static inline u64 vfp_estimate_div128to64(u64 nh, u64 nl, u64 m)
126 add128(&remh, &reml, remh, reml, mh, ml); 132 add128(&remh, &reml, remh, reml, mh, ml);
127 } 133 }
128 remh = (remh << 32) | (reml >> 32); 134 remh = (remh << 32) | (reml >> 32);
129 z |= (mh << 32 <= remh) ? 0xffffffff : remh / mh; 135 if (mh << 32 <= remh) {
136 z |= 0xffffffff;
137 } else {
138 do_div(remh, mh);
139 z |= remh;
140 }
130 return z; 141 return z;
131} 142}
132 143
diff --git a/arch/arm/vfp/vfpdouble.c b/arch/arm/vfp/vfpdouble.c
index fa3053e84db5..b801cd66b6ea 100644
--- a/arch/arm/vfp/vfpdouble.c
+++ b/arch/arm/vfp/vfpdouble.c
@@ -32,6 +32,8 @@
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/bitops.h> 34#include <linux/bitops.h>
35
36#include <asm/div64.h>
35#include <asm/ptrace.h> 37#include <asm/ptrace.h>
36#include <asm/vfp.h> 38#include <asm/vfp.h>
37 39
diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c
index 3aeedd2afc70..22f3da4e0829 100644
--- a/arch/arm/vfp/vfpmodule.c
+++ b/arch/arm/vfp/vfpmodule.c
@@ -89,7 +89,7 @@ void vfp_raise_sigfpe(unsigned int sicode, struct pt_regs *regs)
89 current->thread.error_code = 0; 89 current->thread.error_code = 0;
90 current->thread.trap_no = 6; 90 current->thread.trap_no = 6;
91 91
92 force_sig_info(SIGFPE, &info, current); 92 send_sig_info(SIGFPE, &info, current);
93} 93}
94 94
95static void vfp_panic(char *reason) 95static void vfp_panic(char *reason)
diff --git a/arch/arm/vfp/vfpsingle.c b/arch/arm/vfp/vfpsingle.c
index 6849fe35cb2e..14dd696ddeb1 100644
--- a/arch/arm/vfp/vfpsingle.c
+++ b/arch/arm/vfp/vfpsingle.c
@@ -32,6 +32,8 @@
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/bitops.h> 34#include <linux/bitops.h>
35
36#include <asm/div64.h>
35#include <asm/ptrace.h> 37#include <asm/ptrace.h>
36#include <asm/vfp.h> 38#include <asm/vfp.h>
37 39
@@ -303,7 +305,11 @@ u32 vfp_estimate_sqrt_significand(u32 exponent, u32 significand)
303 if (z <= a) 305 if (z <= a)
304 return (s32)a >> 1; 306 return (s32)a >> 1;
305 } 307 }
306 return (u32)(((u64)a << 31) / z) + (z >> 1); 308 {
309 u64 v = (u64)a << 31;
310 do_div(v, z);
311 return v + (z >> 1);
312 }
307} 313}
308 314
309static u32 vfp_single_fsqrt(int sd, int unused, s32 m, u32 fpscr) 315static u32 vfp_single_fsqrt(int sd, int unused, s32 m, u32 fpscr)
@@ -1107,7 +1113,11 @@ static u32 vfp_single_fdiv(int sd, int sn, s32 m, u32 fpscr)
1107 vsn.significand >>= 1; 1113 vsn.significand >>= 1;
1108 vsd.exponent++; 1114 vsd.exponent++;
1109 } 1115 }
1110 vsd.significand = ((u64)vsn.significand << 32) / vsm.significand; 1116 {
1117 u64 significand = (u64)vsn.significand << 32;
1118 do_div(significand, vsm.significand);
1119 vsd.significand = significand;
1120 }
1111 if ((vsd.significand & 0x3f) == 0) 1121 if ((vsd.significand & 0x3f) == 0)
1112 vsd.significand |= ((u64)vsm.significand * vsd.significand != (u64)vsn.significand << 32); 1122 vsd.significand |= ((u64)vsm.significand * vsd.significand != (u64)vsn.significand << 32);
1113 1123
diff --git a/arch/i386/boot/tools/build.c b/arch/i386/boot/tools/build.c
index 4a17956512e1..6835f6d47c31 100644
--- a/arch/i386/boot/tools/build.c
+++ b/arch/i386/boot/tools/build.c
@@ -70,7 +70,8 @@ void usage(void)
70 70
71int main(int argc, char ** argv) 71int main(int argc, char ** argv)
72{ 72{
73 unsigned int i, c, sz, setup_sectors; 73 unsigned int i, sz, setup_sectors;
74 int c;
74 u32 sys_size; 75 u32 sys_size;
75 byte major_root, minor_root; 76 byte major_root, minor_root;
76 struct stat sb; 77 struct stat sb;
diff --git a/arch/i386/kernel/acpi/boot.c b/arch/i386/kernel/acpi/boot.c
index 9f63ae0f404b..b7808a89d945 100644
--- a/arch/i386/kernel/acpi/boot.c
+++ b/arch/i386/kernel/acpi/boot.c
@@ -159,9 +159,15 @@ char *__acpi_map_table(unsigned long phys, unsigned long size)
159#endif 159#endif
160 160
161#ifdef CONFIG_PCI_MMCONFIG 161#ifdef CONFIG_PCI_MMCONFIG
162static int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size) 162/* The physical address of the MMCONFIG aperture. Set from ACPI tables. */
163struct acpi_table_mcfg_config *pci_mmcfg_config;
164int pci_mmcfg_config_num;
165
166int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size)
163{ 167{
164 struct acpi_table_mcfg *mcfg; 168 struct acpi_table_mcfg *mcfg;
169 unsigned long i;
170 int config_size;
165 171
166 if (!phys_addr || !size) 172 if (!phys_addr || !size)
167 return -EINVAL; 173 return -EINVAL;
@@ -172,18 +178,38 @@ static int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size)
172 return -ENODEV; 178 return -ENODEV;
173 } 179 }
174 180
175 if (mcfg->base_reserved) { 181 /* how many config structures do we have */
176 printk(KERN_ERR PREFIX "MMCONFIG not in low 4GB of memory\n"); 182 pci_mmcfg_config_num = 0;
183 i = size - sizeof(struct acpi_table_mcfg);
184 while (i >= sizeof(struct acpi_table_mcfg_config)) {
185 ++pci_mmcfg_config_num;
186 i -= sizeof(struct acpi_table_mcfg_config);
187 };
188 if (pci_mmcfg_config_num == 0) {
189 printk(KERN_ERR PREFIX "MMCONFIG has no entries\n");
177 return -ENODEV; 190 return -ENODEV;
178 } 191 }
179 192
180 pci_mmcfg_base_addr = mcfg->base_address; 193 config_size = pci_mmcfg_config_num * sizeof(*pci_mmcfg_config);
194 pci_mmcfg_config = kmalloc(config_size, GFP_KERNEL);
195 if (!pci_mmcfg_config) {
196 printk(KERN_WARNING PREFIX
197 "No memory for MCFG config tables\n");
198 return -ENOMEM;
199 }
200
201 memcpy(pci_mmcfg_config, &mcfg->config, config_size);
202 for (i = 0; i < pci_mmcfg_config_num; ++i) {
203 if (mcfg->config[i].base_reserved) {
204 printk(KERN_ERR PREFIX
205 "MMCONFIG not in low 4GB of memory\n");
206 return -ENODEV;
207 }
208 }
181 209
182 return 0; 210 return 0;
183} 211}
184#else 212#endif /* CONFIG_PCI_MMCONFIG */
185#define acpi_parse_mcfg NULL
186#endif /* !CONFIG_PCI_MMCONFIG */
187 213
188#ifdef CONFIG_X86_LOCAL_APIC 214#ifdef CONFIG_X86_LOCAL_APIC
189static int __init 215static int __init
@@ -507,6 +533,22 @@ acpi_unmap_lsapic(int cpu)
507EXPORT_SYMBOL(acpi_unmap_lsapic); 533EXPORT_SYMBOL(acpi_unmap_lsapic);
508#endif /* CONFIG_ACPI_HOTPLUG_CPU */ 534#endif /* CONFIG_ACPI_HOTPLUG_CPU */
509 535
536int
537acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
538{
539 /* TBD */
540 return -EINVAL;
541}
542EXPORT_SYMBOL(acpi_register_ioapic);
543
544int
545acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
546{
547 /* TBD */
548 return -EINVAL;
549}
550EXPORT_SYMBOL(acpi_unregister_ioapic);
551
510static unsigned long __init 552static unsigned long __init
511acpi_scan_rsdp ( 553acpi_scan_rsdp (
512 unsigned long start, 554 unsigned long start,
@@ -1123,7 +1165,6 @@ int __init acpi_boot_init(void)
1123 acpi_process_madt(); 1165 acpi_process_madt();
1124 1166
1125 acpi_table_parse(ACPI_HPET, acpi_parse_hpet); 1167 acpi_table_parse(ACPI_HPET, acpi_parse_hpet);
1126 acpi_table_parse(ACPI_MCFG, acpi_parse_mcfg);
1127 1168
1128 return 0; 1169 return 0;
1129} 1170}
diff --git a/arch/i386/kernel/kprobes.c b/arch/i386/kernel/kprobes.c
index 3762f6b35ab2..fc8b17521761 100644
--- a/arch/i386/kernel/kprobes.c
+++ b/arch/i386/kernel/kprobes.c
@@ -127,48 +127,23 @@ static inline void prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
127 regs->eip = (unsigned long)&p->ainsn.insn; 127 regs->eip = (unsigned long)&p->ainsn.insn;
128} 128}
129 129
130struct task_struct *arch_get_kprobe_task(void *ptr)
131{
132 return ((struct thread_info *) (((unsigned long) ptr) &
133 (~(THREAD_SIZE -1))))->task;
134}
135
136void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs) 130void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs)
137{ 131{
138 unsigned long *sara = (unsigned long *)&regs->esp; 132 unsigned long *sara = (unsigned long *)&regs->esp;
139 struct kretprobe_instance *ri; 133 struct kretprobe_instance *ri;
140 static void *orig_ret_addr; 134
135 if ((ri = get_free_rp_inst(rp)) != NULL) {
136 ri->rp = rp;
137 ri->task = current;
138 ri->ret_addr = (kprobe_opcode_t *) *sara;
141 139
142 /*
143 * Save the return address when the return probe hits
144 * the first time, and use it to populate the (krprobe
145 * instance)->ret_addr for subsequent return probes at
146 * the same addrress since stack address would have
147 * the kretprobe_trampoline by then.
148 */
149 if (((void*) *sara) != kretprobe_trampoline)
150 orig_ret_addr = (void*) *sara;
151
152 if ((ri = get_free_rp_inst(rp)) != NULL) {
153 ri->rp = rp;
154 ri->stack_addr = sara;
155 ri->ret_addr = orig_ret_addr;
156 add_rp_inst(ri);
157 /* Replace the return addr with trampoline addr */ 140 /* Replace the return addr with trampoline addr */
158 *sara = (unsigned long) &kretprobe_trampoline; 141 *sara = (unsigned long) &kretprobe_trampoline;
159 } else {
160 rp->nmissed++;
161 }
162}
163 142
164void arch_kprobe_flush_task(struct task_struct *tk) 143 add_rp_inst(ri);
165{ 144 } else {
166 struct kretprobe_instance *ri; 145 rp->nmissed++;
167 while ((ri = get_rp_inst_tsk(tk)) != NULL) { 146 }
168 *((unsigned long *)(ri->stack_addr)) =
169 (unsigned long) ri->ret_addr;
170 recycle_rp_inst(ri);
171 }
172} 147}
173 148
174/* 149/*
@@ -286,36 +261,59 @@ no_kprobe:
286 */ 261 */
287int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs) 262int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
288{ 263{
289 struct task_struct *tsk; 264 struct kretprobe_instance *ri = NULL;
290 struct kretprobe_instance *ri; 265 struct hlist_head *head;
291 struct hlist_head *head; 266 struct hlist_node *node, *tmp;
292 struct hlist_node *node; 267 unsigned long orig_ret_address = 0;
293 unsigned long *sara = ((unsigned long *) &regs->esp) - 1; 268 unsigned long trampoline_address =(unsigned long)&kretprobe_trampoline;
294
295 tsk = arch_get_kprobe_task(sara);
296 head = kretprobe_inst_table_head(tsk);
297
298 hlist_for_each_entry(ri, node, head, hlist) {
299 if (ri->stack_addr == sara && ri->rp) {
300 if (ri->rp->handler)
301 ri->rp->handler(ri, regs);
302 }
303 }
304 return 0;
305}
306 269
307void trampoline_post_handler(struct kprobe *p, struct pt_regs *regs, 270 head = kretprobe_inst_table_head(current);
308 unsigned long flags)
309{
310 struct kretprobe_instance *ri;
311 /* RA already popped */
312 unsigned long *sara = ((unsigned long *)&regs->esp) - 1;
313 271
314 while ((ri = get_rp_inst(sara))) { 272 /*
315 regs->eip = (unsigned long)ri->ret_addr; 273 * It is possible to have multiple instances associated with a given
274 * task either because an multiple functions in the call path
275 * have a return probe installed on them, and/or more then one return
276 * return probe was registered for a target function.
277 *
278 * We can handle this because:
279 * - instances are always inserted at the head of the list
280 * - when multiple return probes are registered for the same
281 * function, the first instance's ret_addr will point to the
282 * real return address, and all the rest will point to
283 * kretprobe_trampoline
284 */
285 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
286 if (ri->task != current)
287 /* another task is sharing our hash bucket */
288 continue;
289
290 if (ri->rp && ri->rp->handler)
291 ri->rp->handler(ri, regs);
292
293 orig_ret_address = (unsigned long)ri->ret_addr;
316 recycle_rp_inst(ri); 294 recycle_rp_inst(ri);
295
296 if (orig_ret_address != trampoline_address)
297 /*
298 * This is the real return address. Any other
299 * instances associated with this task are for
300 * other calls deeper on the call stack
301 */
302 break;
317 } 303 }
318 regs->eflags &= ~TF_MASK; 304
305 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
306 regs->eip = orig_ret_address;
307
308 unlock_kprobes();
309 preempt_enable_no_resched();
310
311 /*
312 * By returning a non-zero value, we are telling
313 * kprobe_handler() that we have handled unlocking
314 * and re-enabling preemption.
315 */
316 return 1;
319} 317}
320 318
321/* 319/*
@@ -403,8 +401,7 @@ static inline int post_kprobe_handler(struct pt_regs *regs)
403 current_kprobe->post_handler(current_kprobe, regs, 0); 401 current_kprobe->post_handler(current_kprobe, regs, 0);
404 } 402 }
405 403
406 if (current_kprobe->post_handler != trampoline_post_handler) 404 resume_execution(current_kprobe, regs);
407 resume_execution(current_kprobe, regs);
408 regs->eflags |= kprobe_saved_eflags; 405 regs->eflags |= kprobe_saved_eflags;
409 406
410 /*Restore back the original saved kprobes variables and continue. */ 407 /*Restore back the original saved kprobes variables and continue. */
@@ -534,3 +531,13 @@ int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
534 } 531 }
535 return 0; 532 return 0;
536} 533}
534
535static struct kprobe trampoline_p = {
536 .addr = (kprobe_opcode_t *) &kretprobe_trampoline,
537 .pre_handler = trampoline_probe_handler
538};
539
540int __init arch_init(void)
541{
542 return register_kprobe(&trampoline_p);
543}
diff --git a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c
index 5f8cfa6b7940..ba243a4cc119 100644
--- a/arch/i386/kernel/process.c
+++ b/arch/i386/kernel/process.c
@@ -617,6 +617,33 @@ handle_io_bitmap(struct thread_struct *next, struct tss_struct *tss)
617} 617}
618 618
619/* 619/*
620 * This function selects if the context switch from prev to next
621 * has to tweak the TSC disable bit in the cr4.
622 */
623static inline void disable_tsc(struct task_struct *prev_p,
624 struct task_struct *next_p)
625{
626 struct thread_info *prev, *next;
627
628 /*
629 * gcc should eliminate the ->thread_info dereference if
630 * has_secure_computing returns 0 at compile time (SECCOMP=n).
631 */
632 prev = prev_p->thread_info;
633 next = next_p->thread_info;
634
635 if (has_secure_computing(prev) || has_secure_computing(next)) {
636 /* slow path here */
637 if (has_secure_computing(prev) &&
638 !has_secure_computing(next)) {
639 write_cr4(read_cr4() & ~X86_CR4_TSD);
640 } else if (!has_secure_computing(prev) &&
641 has_secure_computing(next))
642 write_cr4(read_cr4() | X86_CR4_TSD);
643 }
644}
645
646/*
620 * switch_to(x,yn) should switch tasks from x to y. 647 * switch_to(x,yn) should switch tasks from x to y.
621 * 648 *
622 * We fsave/fwait so that an exception goes off at the right time 649 * We fsave/fwait so that an exception goes off at the right time
@@ -695,6 +722,8 @@ struct task_struct fastcall * __switch_to(struct task_struct *prev_p, struct tas
695 if (unlikely(prev->io_bitmap_ptr || next->io_bitmap_ptr)) 722 if (unlikely(prev->io_bitmap_ptr || next->io_bitmap_ptr))
696 handle_io_bitmap(next, tss); 723 handle_io_bitmap(next, tss);
697 724
725 disable_tsc(prev_p, next_p);
726
698 return prev_p; 727 return prev_p;
699} 728}
700 729
diff --git a/arch/i386/kernel/syscall_table.S b/arch/i386/kernel/syscall_table.S
index 442a6e937b19..3db9a04aec6e 100644
--- a/arch/i386/kernel/syscall_table.S
+++ b/arch/i386/kernel/syscall_table.S
@@ -289,3 +289,5 @@ ENTRY(sys_call_table)
289 .long sys_add_key 289 .long sys_add_key
290 .long sys_request_key 290 .long sys_request_key
291 .long sys_keyctl 291 .long sys_keyctl
292 .long sys_ioprio_set
293 .long sys_ioprio_get /* 290 */
diff --git a/arch/i386/pci/common.c b/arch/i386/pci/common.c
index 720975e1af50..87325263cd4f 100644
--- a/arch/i386/pci/common.c
+++ b/arch/i386/pci/common.c
@@ -25,7 +25,8 @@ unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
25 25
26int pci_routeirq; 26int pci_routeirq;
27int pcibios_last_bus = -1; 27int pcibios_last_bus = -1;
28struct pci_bus *pci_root_bus = NULL; 28unsigned long pirq_table_addr;
29struct pci_bus *pci_root_bus;
29struct pci_raw_ops *raw_pci_ops; 30struct pci_raw_ops *raw_pci_ops;
30 31
31static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value) 32static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
@@ -133,7 +134,7 @@ struct pci_bus * __devinit pcibios_scan_root(int busnum)
133 134
134 printk("PCI: Probing PCI hardware (bus %02x)\n", busnum); 135 printk("PCI: Probing PCI hardware (bus %02x)\n", busnum);
135 136
136 return pci_scan_bus(busnum, &pci_root_ops, NULL); 137 return pci_scan_bus_parented(NULL, busnum, &pci_root_ops, NULL);
137} 138}
138 139
139extern u8 pci_cache_line_size; 140extern u8 pci_cache_line_size;
@@ -188,6 +189,9 @@ char * __devinit pcibios_setup(char *str)
188 } else if (!strcmp(str, "biosirq")) { 189 } else if (!strcmp(str, "biosirq")) {
189 pci_probe |= PCI_BIOS_IRQ_SCAN; 190 pci_probe |= PCI_BIOS_IRQ_SCAN;
190 return NULL; 191 return NULL;
192 } else if (!strncmp(str, "pirqaddr=", 9)) {
193 pirq_table_addr = simple_strtoul(str+9, NULL, 0);
194 return NULL;
191 } 195 }
192#endif 196#endif
193#ifdef CONFIG_PCI_DIRECT 197#ifdef CONFIG_PCI_DIRECT
diff --git a/arch/i386/pci/irq.c b/arch/i386/pci/irq.c
index 83458f81e661..78ca1ecbb907 100644
--- a/arch/i386/pci/irq.c
+++ b/arch/i386/pci/irq.c
@@ -58,6 +58,35 @@ struct irq_router_handler {
58int (*pcibios_enable_irq)(struct pci_dev *dev) = NULL; 58int (*pcibios_enable_irq)(struct pci_dev *dev) = NULL;
59 59
60/* 60/*
61 * Check passed address for the PCI IRQ Routing Table signature
62 * and perform checksum verification.
63 */
64
65static inline struct irq_routing_table * pirq_check_routing_table(u8 *addr)
66{
67 struct irq_routing_table *rt;
68 int i;
69 u8 sum;
70
71 rt = (struct irq_routing_table *) addr;
72 if (rt->signature != PIRQ_SIGNATURE ||
73 rt->version != PIRQ_VERSION ||
74 rt->size % 16 ||
75 rt->size < sizeof(struct irq_routing_table))
76 return NULL;
77 sum = 0;
78 for (i=0; i < rt->size; i++)
79 sum += addr[i];
80 if (!sum) {
81 DBG("PCI: Interrupt Routing Table found at 0x%p\n", rt);
82 return rt;
83 }
84 return NULL;
85}
86
87
88
89/*
61 * Search 0xf0000 -- 0xfffff for the PCI IRQ Routing Table. 90 * Search 0xf0000 -- 0xfffff for the PCI IRQ Routing Table.
62 */ 91 */
63 92
@@ -65,23 +94,17 @@ static struct irq_routing_table * __init pirq_find_routing_table(void)
65{ 94{
66 u8 *addr; 95 u8 *addr;
67 struct irq_routing_table *rt; 96 struct irq_routing_table *rt;
68 int i;
69 u8 sum;
70 97
98 if (pirq_table_addr) {
99 rt = pirq_check_routing_table((u8 *) __va(pirq_table_addr));
100 if (rt)
101 return rt;
102 printk(KERN_WARNING "PCI: PIRQ table NOT found at pirqaddr\n");
103 }
71 for(addr = (u8 *) __va(0xf0000); addr < (u8 *) __va(0x100000); addr += 16) { 104 for(addr = (u8 *) __va(0xf0000); addr < (u8 *) __va(0x100000); addr += 16) {
72 rt = (struct irq_routing_table *) addr; 105 rt = pirq_check_routing_table(addr);
73 if (rt->signature != PIRQ_SIGNATURE || 106 if (rt)
74 rt->version != PIRQ_VERSION ||
75 rt->size % 16 ||
76 rt->size < sizeof(struct irq_routing_table))
77 continue;
78 sum = 0;
79 for(i=0; i<rt->size; i++)
80 sum += addr[i];
81 if (!sum) {
82 DBG("PCI: Interrupt Routing Table found at 0x%p\n", rt);
83 return rt; 107 return rt;
84 }
85 } 108 }
86 return NULL; 109 return NULL;
87} 110}
diff --git a/arch/i386/pci/legacy.c b/arch/i386/pci/legacy.c
index 1492e3753869..149a9588c256 100644
--- a/arch/i386/pci/legacy.c
+++ b/arch/i386/pci/legacy.c
@@ -45,6 +45,8 @@ static int __init pci_legacy_init(void)
45 45
46 printk("PCI: Probing PCI hardware\n"); 46 printk("PCI: Probing PCI hardware\n");
47 pci_root_bus = pcibios_scan_root(0); 47 pci_root_bus = pcibios_scan_root(0);
48 if (pci_root_bus)
49 pci_bus_add_devices(pci_root_bus);
48 50
49 pcibios_fixup_peer_bridges(); 51 pcibios_fixup_peer_bridges();
50 52
diff --git a/arch/i386/pci/mmconfig.c b/arch/i386/pci/mmconfig.c
index 021a50aa51f4..60f0e7a1162a 100644
--- a/arch/i386/pci/mmconfig.c
+++ b/arch/i386/pci/mmconfig.c
@@ -11,11 +11,9 @@
11 11
12#include <linux/pci.h> 12#include <linux/pci.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/acpi.h>
14#include "pci.h" 15#include "pci.h"
15 16
16/* The physical address of the MMCONFIG aperture. Set from ACPI tables. */
17u32 pci_mmcfg_base_addr;
18
19#define mmcfg_virt_addr ((void __iomem *) fix_to_virt(FIX_PCIE_MCFG)) 17#define mmcfg_virt_addr ((void __iomem *) fix_to_virt(FIX_PCIE_MCFG))
20 18
21/* The base address of the last MMCONFIG device accessed */ 19/* The base address of the last MMCONFIG device accessed */
@@ -24,10 +22,31 @@ static u32 mmcfg_last_accessed_device;
24/* 22/*
25 * Functions for accessing PCI configuration space with MMCONFIG accesses 23 * Functions for accessing PCI configuration space with MMCONFIG accesses
26 */ 24 */
25static u32 get_base_addr(unsigned int seg, int bus)
26{
27 int cfg_num = -1;
28 struct acpi_table_mcfg_config *cfg;
29
30 while (1) {
31 ++cfg_num;
32 if (cfg_num >= pci_mmcfg_config_num) {
33 /* something bad is going on, no cfg table is found. */
34 /* so we fall back to the old way we used to do this */
35 /* and just rely on the first entry to be correct. */
36 return pci_mmcfg_config[0].base_address;
37 }
38 cfg = &pci_mmcfg_config[cfg_num];
39 if (cfg->pci_segment_group_number != seg)
40 continue;
41 if ((cfg->start_bus_number <= bus) &&
42 (cfg->end_bus_number >= bus))
43 return cfg->base_address;
44 }
45}
27 46
28static inline void pci_exp_set_dev_base(int bus, int devfn) 47static inline void pci_exp_set_dev_base(unsigned int seg, int bus, int devfn)
29{ 48{
30 u32 dev_base = pci_mmcfg_base_addr | (bus << 20) | (devfn << 12); 49 u32 dev_base = get_base_addr(seg, bus) | (bus << 20) | (devfn << 12);
31 if (dev_base != mmcfg_last_accessed_device) { 50 if (dev_base != mmcfg_last_accessed_device) {
32 mmcfg_last_accessed_device = dev_base; 51 mmcfg_last_accessed_device = dev_base;
33 set_fixmap_nocache(FIX_PCIE_MCFG, dev_base); 52 set_fixmap_nocache(FIX_PCIE_MCFG, dev_base);
@@ -44,7 +63,7 @@ static int pci_mmcfg_read(unsigned int seg, unsigned int bus,
44 63
45 spin_lock_irqsave(&pci_config_lock, flags); 64 spin_lock_irqsave(&pci_config_lock, flags);
46 65
47 pci_exp_set_dev_base(bus, devfn); 66 pci_exp_set_dev_base(seg, bus, devfn);
48 67
49 switch (len) { 68 switch (len) {
50 case 1: 69 case 1:
@@ -73,7 +92,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
73 92
74 spin_lock_irqsave(&pci_config_lock, flags); 93 spin_lock_irqsave(&pci_config_lock, flags);
75 94
76 pci_exp_set_dev_base(bus, devfn); 95 pci_exp_set_dev_base(seg, bus, devfn);
77 96
78 switch (len) { 97 switch (len) {
79 case 1: 98 case 1:
@@ -101,7 +120,11 @@ static int __init pci_mmcfg_init(void)
101{ 120{
102 if ((pci_probe & PCI_PROBE_MMCONF) == 0) 121 if ((pci_probe & PCI_PROBE_MMCONF) == 0)
103 goto out; 122 goto out;
104 if (!pci_mmcfg_base_addr) 123
124 acpi_table_parse(ACPI_MCFG, acpi_parse_mcfg);
125 if ((pci_mmcfg_config_num == 0) ||
126 (pci_mmcfg_config == NULL) ||
127 (pci_mmcfg_config[0].base_address == 0))
105 goto out; 128 goto out;
106 129
107 /* Kludge for now. Don't use mmconfig on AMD systems because 130 /* Kludge for now. Don't use mmconfig on AMD systems because
diff --git a/arch/i386/pci/numa.c b/arch/i386/pci/numa.c
index 9e3695461899..adbe17a38f6f 100644
--- a/arch/i386/pci/numa.c
+++ b/arch/i386/pci/numa.c
@@ -115,6 +115,8 @@ static int __init pci_numa_init(void)
115 return 0; 115 return 0;
116 116
117 pci_root_bus = pcibios_scan_root(0); 117 pci_root_bus = pcibios_scan_root(0);
118 if (pci_root_bus)
119 pci_bus_add_devices(pci_root_bus);
118 if (num_online_nodes() > 1) 120 if (num_online_nodes() > 1)
119 for_each_online_node(quad) { 121 for_each_online_node(quad) {
120 if (quad == 0) 122 if (quad == 0)
diff --git a/arch/i386/pci/pci.h b/arch/i386/pci/pci.h
index a8fc80ca69f3..a80f0f55ff51 100644
--- a/arch/i386/pci/pci.h
+++ b/arch/i386/pci/pci.h
@@ -27,6 +27,7 @@
27#define PCI_ASSIGN_ALL_BUSSES 0x4000 27#define PCI_ASSIGN_ALL_BUSSES 0x4000
28 28
29extern unsigned int pci_probe; 29extern unsigned int pci_probe;
30extern unsigned long pirq_table_addr;
30 31
31/* pci-i386.c */ 32/* pci-i386.c */
32 33
diff --git a/arch/ia64/configs/sn2_defconfig b/arch/ia64/configs/sn2_defconfig
index 487d2e36b0a6..c05613980300 100644
--- a/arch/ia64/configs/sn2_defconfig
+++ b/arch/ia64/configs/sn2_defconfig
@@ -99,7 +99,7 @@ CONFIG_ACPI_DEALLOCATE_IRQ=y
99# Firmware Drivers 99# Firmware Drivers
100# 100#
101CONFIG_EFI_VARS=y 101CONFIG_EFI_VARS=y
102# CONFIG_EFI_PCDP is not set 102CONFIG_EFI_PCDP=y
103CONFIG_BINFMT_ELF=y 103CONFIG_BINFMT_ELF=y
104# CONFIG_BINFMT_MISC is not set 104# CONFIG_BINFMT_MISC is not set
105 105
@@ -650,7 +650,7 @@ CONFIG_MMTIMER=y
650# 650#
651# Console display driver support 651# Console display driver support
652# 652#
653# CONFIG_VGA_CONSOLE is not set 653CONFIG_VGA_CONSOLE=y
654CONFIG_DUMMY_CONSOLE=y 654CONFIG_DUMMY_CONSOLE=y
655 655
656# 656#
diff --git a/arch/ia64/configs/tiger_defconfig b/arch/ia64/configs/tiger_defconfig
index 47f45341ac62..73454eee26f1 100644
--- a/arch/ia64/configs/tiger_defconfig
+++ b/arch/ia64/configs/tiger_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.12-20050621 3# Linux kernel version: 2.6.13-rc1-20050629
4# Tue Jun 21 14:03:24 2005 4# Wed Jun 29 15:28:12 2005
5# 5#
6 6
7# 7#
@@ -80,18 +80,29 @@ CONFIG_MCKINLEY=y
80# CONFIG_IA64_PAGE_SIZE_8KB is not set 80# CONFIG_IA64_PAGE_SIZE_8KB is not set
81CONFIG_IA64_PAGE_SIZE_16KB=y 81CONFIG_IA64_PAGE_SIZE_16KB=y
82# CONFIG_IA64_PAGE_SIZE_64KB is not set 82# CONFIG_IA64_PAGE_SIZE_64KB is not set
83# CONFIG_HZ_100 is not set
84CONFIG_HZ_250=y
85# CONFIG_HZ_1000 is not set
86CONFIG_HZ=250
83CONFIG_IA64_L1_CACHE_SHIFT=7 87CONFIG_IA64_L1_CACHE_SHIFT=7
84# CONFIG_NUMA is not set 88# CONFIG_NUMA is not set
85CONFIG_VIRTUAL_MEM_MAP=y 89CONFIG_VIRTUAL_MEM_MAP=y
86CONFIG_HOLES_IN_ZONE=y 90CONFIG_HOLES_IN_ZONE=y
87CONFIG_IA64_CYCLONE=y 91CONFIG_IA64_CYCLONE=y
88CONFIG_IOSAPIC=y 92CONFIG_IOSAPIC=y
93# CONFIG_IA64_SGI_SN_XP is not set
89CONFIG_FORCE_MAX_ZONEORDER=18 94CONFIG_FORCE_MAX_ZONEORDER=18
90CONFIG_SMP=y 95CONFIG_SMP=y
91CONFIG_NR_CPUS=4 96CONFIG_NR_CPUS=4
92CONFIG_HOTPLUG_CPU=y 97CONFIG_HOTPLUG_CPU=y
93# CONFIG_SCHED_SMT is not set 98# CONFIG_SCHED_SMT is not set
94# CONFIG_PREEMPT is not set 99# CONFIG_PREEMPT is not set
100CONFIG_SELECT_MEMORY_MODEL=y
101CONFIG_FLATMEM_MANUAL=y
102# CONFIG_DISCONTIGMEM_MANUAL is not set
103# CONFIG_SPARSEMEM_MANUAL is not set
104CONFIG_FLATMEM=y
105CONFIG_FLAT_NODE_MEM_MAP=y
95CONFIG_HAVE_DEC_LOCK=y 106CONFIG_HAVE_DEC_LOCK=y
96CONFIG_IA32_SUPPORT=y 107CONFIG_IA32_SUPPORT=y
97CONFIG_COMPAT=y 108CONFIG_COMPAT=y
@@ -257,6 +268,7 @@ CONFIG_BLK_DEV_CMD64X=y
257# CONFIG_BLK_DEV_HPT366 is not set 268# CONFIG_BLK_DEV_HPT366 is not set
258# CONFIG_BLK_DEV_SC1200 is not set 269# CONFIG_BLK_DEV_SC1200 is not set
259CONFIG_BLK_DEV_PIIX=y 270CONFIG_BLK_DEV_PIIX=y
271# CONFIG_BLK_DEV_IT821X is not set
260# CONFIG_BLK_DEV_NS87415 is not set 272# CONFIG_BLK_DEV_NS87415 is not set
261# CONFIG_BLK_DEV_PDC202XX_OLD is not set 273# CONFIG_BLK_DEV_PDC202XX_OLD is not set
262# CONFIG_BLK_DEV_PDC202XX_NEW is not set 274# CONFIG_BLK_DEV_PDC202XX_NEW is not set
@@ -395,6 +407,7 @@ CONFIG_UNIX=y
395CONFIG_INET=y 407CONFIG_INET=y
396CONFIG_IP_MULTICAST=y 408CONFIG_IP_MULTICAST=y
397# CONFIG_IP_ADVANCED_ROUTER is not set 409# CONFIG_IP_ADVANCED_ROUTER is not set
410CONFIG_IP_FIB_HASH=y
398# CONFIG_IP_PNP is not set 411# CONFIG_IP_PNP is not set
399# CONFIG_NET_IPIP is not set 412# CONFIG_NET_IPIP is not set
400# CONFIG_NET_IPGRE is not set 413# CONFIG_NET_IPGRE is not set
@@ -407,6 +420,8 @@ CONFIG_SYN_COOKIES=y
407# CONFIG_INET_TUNNEL is not set 420# CONFIG_INET_TUNNEL is not set
408CONFIG_IP_TCPDIAG=y 421CONFIG_IP_TCPDIAG=y
409# CONFIG_IP_TCPDIAG_IPV6 is not set 422# CONFIG_IP_TCPDIAG_IPV6 is not set
423# CONFIG_TCP_CONG_ADVANCED is not set
424CONFIG_TCP_CONG_BIC=y
410# CONFIG_IPV6 is not set 425# CONFIG_IPV6 is not set
411# CONFIG_NETFILTER is not set 426# CONFIG_NETFILTER is not set
412 427
@@ -598,9 +613,7 @@ CONFIG_GAMEPORT=m
598# CONFIG_GAMEPORT_NS558 is not set 613# CONFIG_GAMEPORT_NS558 is not set
599# CONFIG_GAMEPORT_L4 is not set 614# CONFIG_GAMEPORT_L4 is not set
600# CONFIG_GAMEPORT_EMU10K1 is not set 615# CONFIG_GAMEPORT_EMU10K1 is not set
601# CONFIG_GAMEPORT_VORTEX is not set
602# CONFIG_GAMEPORT_FM801 is not set 616# CONFIG_GAMEPORT_FM801 is not set
603# CONFIG_GAMEPORT_CS461X is not set
604 617
605# 618#
606# Character devices 619# Character devices
@@ -629,7 +642,6 @@ CONFIG_SERIAL_8250_NR_UARTS=6
629CONFIG_SERIAL_8250_EXTENDED=y 642CONFIG_SERIAL_8250_EXTENDED=y
630CONFIG_SERIAL_8250_SHARE_IRQ=y 643CONFIG_SERIAL_8250_SHARE_IRQ=y
631# CONFIG_SERIAL_8250_DETECT_IRQ is not set 644# CONFIG_SERIAL_8250_DETECT_IRQ is not set
632# CONFIG_SERIAL_8250_MULTIPORT is not set
633# CONFIG_SERIAL_8250_RSA is not set 645# CONFIG_SERIAL_8250_RSA is not set
634 646
635# 647#
@@ -743,6 +755,7 @@ CONFIG_USB_DEVICEFS=y
743CONFIG_USB_EHCI_HCD=m 755CONFIG_USB_EHCI_HCD=m
744# CONFIG_USB_EHCI_SPLIT_ISO is not set 756# CONFIG_USB_EHCI_SPLIT_ISO is not set
745# CONFIG_USB_EHCI_ROOT_HUB_TT is not set 757# CONFIG_USB_EHCI_ROOT_HUB_TT is not set
758# CONFIG_USB_ISP116X_HCD is not set
746CONFIG_USB_OHCI_HCD=m 759CONFIG_USB_OHCI_HCD=m
747# CONFIG_USB_OHCI_BIG_ENDIAN is not set 760# CONFIG_USB_OHCI_BIG_ENDIAN is not set
748CONFIG_USB_OHCI_LITTLE_ENDIAN=y 761CONFIG_USB_OHCI_LITTLE_ENDIAN=y
@@ -779,9 +792,11 @@ CONFIG_USB_HIDINPUT=y
779# CONFIG_USB_HIDDEV is not set 792# CONFIG_USB_HIDDEV is not set
780# CONFIG_USB_AIPTEK is not set 793# CONFIG_USB_AIPTEK is not set
781# CONFIG_USB_WACOM is not set 794# CONFIG_USB_WACOM is not set
795# CONFIG_USB_ACECAD is not set
782# CONFIG_USB_KBTAB is not set 796# CONFIG_USB_KBTAB is not set
783# CONFIG_USB_POWERMATE is not set 797# CONFIG_USB_POWERMATE is not set
784# CONFIG_USB_MTOUCH is not set 798# CONFIG_USB_MTOUCH is not set
799# CONFIG_USB_ITMTOUCH is not set
785# CONFIG_USB_EGALAX is not set 800# CONFIG_USB_EGALAX is not set
786# CONFIG_USB_XPAD is not set 801# CONFIG_USB_XPAD is not set
787# CONFIG_USB_ATI_REMOTE is not set 802# CONFIG_USB_ATI_REMOTE is not set
@@ -838,7 +853,7 @@ CONFIG_USB_HIDINPUT=y
838# CONFIG_USB_TEST is not set 853# CONFIG_USB_TEST is not set
839 854
840# 855#
841# USB ATM/DSL drivers 856# USB DSL modem support
842# 857#
843 858
844# 859#
@@ -857,12 +872,17 @@ CONFIG_USB_HIDINPUT=y
857# CONFIG_INFINIBAND is not set 872# CONFIG_INFINIBAND is not set
858 873
859# 874#
875# SN Devices
876#
877
878#
860# File systems 879# File systems
861# 880#
862CONFIG_EXT2_FS=y 881CONFIG_EXT2_FS=y
863CONFIG_EXT2_FS_XATTR=y 882CONFIG_EXT2_FS_XATTR=y
864CONFIG_EXT2_FS_POSIX_ACL=y 883CONFIG_EXT2_FS_POSIX_ACL=y
865CONFIG_EXT2_FS_SECURITY=y 884CONFIG_EXT2_FS_SECURITY=y
885# CONFIG_EXT2_FS_XIP is not set
866CONFIG_EXT3_FS=y 886CONFIG_EXT3_FS=y
867CONFIG_EXT3_FS_XATTR=y 887CONFIG_EXT3_FS_XATTR=y
868CONFIG_EXT3_FS_POSIX_ACL=y 888CONFIG_EXT3_FS_POSIX_ACL=y
@@ -922,7 +942,6 @@ CONFIG_NTFS_FS=m
922CONFIG_PROC_FS=y 942CONFIG_PROC_FS=y
923CONFIG_PROC_KCORE=y 943CONFIG_PROC_KCORE=y
924CONFIG_SYSFS=y 944CONFIG_SYSFS=y
925# CONFIG_DEVFS_FS is not set
926# CONFIG_DEVPTS_FS_XATTR is not set 945# CONFIG_DEVPTS_FS_XATTR is not set
927CONFIG_TMPFS=y 946CONFIG_TMPFS=y
928CONFIG_TMPFS_XATTR=y 947CONFIG_TMPFS_XATTR=y
@@ -953,15 +972,18 @@ CONFIG_RAMFS=y
953# 972#
954CONFIG_NFS_FS=m 973CONFIG_NFS_FS=m
955CONFIG_NFS_V3=y 974CONFIG_NFS_V3=y
975# CONFIG_NFS_V3_ACL is not set
956CONFIG_NFS_V4=y 976CONFIG_NFS_V4=y
957CONFIG_NFS_DIRECTIO=y 977CONFIG_NFS_DIRECTIO=y
958CONFIG_NFSD=m 978CONFIG_NFSD=m
959CONFIG_NFSD_V3=y 979CONFIG_NFSD_V3=y
980# CONFIG_NFSD_V3_ACL is not set
960CONFIG_NFSD_V4=y 981CONFIG_NFSD_V4=y
961CONFIG_NFSD_TCP=y 982CONFIG_NFSD_TCP=y
962CONFIG_LOCKD=m 983CONFIG_LOCKD=m
963CONFIG_LOCKD_V4=y 984CONFIG_LOCKD_V4=y
964CONFIG_EXPORTFS=y 985CONFIG_EXPORTFS=y
986CONFIG_NFS_COMMON=y
965CONFIG_SUNRPC=m 987CONFIG_SUNRPC=m
966CONFIG_SUNRPC_GSS=m 988CONFIG_SUNRPC_GSS=m
967CONFIG_RPCSEC_GSS_KRB5=m 989CONFIG_RPCSEC_GSS_KRB5=m
@@ -1069,6 +1091,7 @@ CONFIG_LOG_BUF_SHIFT=20
1069# CONFIG_DEBUG_KOBJECT is not set 1091# CONFIG_DEBUG_KOBJECT is not set
1070# CONFIG_DEBUG_INFO is not set 1092# CONFIG_DEBUG_INFO is not set
1071# CONFIG_DEBUG_FS is not set 1093# CONFIG_DEBUG_FS is not set
1094# CONFIG_KPROBES is not set
1072CONFIG_IA64_GRANULE_16MB=y 1095CONFIG_IA64_GRANULE_16MB=y
1073# CONFIG_IA64_GRANULE_64MB is not set 1096# CONFIG_IA64_GRANULE_64MB is not set
1074# CONFIG_IA64_PRINT_HAZARDS is not set 1097# CONFIG_IA64_PRINT_HAZARDS is not set
@@ -1090,7 +1113,7 @@ CONFIG_CRYPTO=y
1090# CONFIG_CRYPTO_HMAC is not set 1113# CONFIG_CRYPTO_HMAC is not set
1091# CONFIG_CRYPTO_NULL is not set 1114# CONFIG_CRYPTO_NULL is not set
1092# CONFIG_CRYPTO_MD4 is not set 1115# CONFIG_CRYPTO_MD4 is not set
1093CONFIG_CRYPTO_MD5=m 1116CONFIG_CRYPTO_MD5=y
1094# CONFIG_CRYPTO_SHA1 is not set 1117# CONFIG_CRYPTO_SHA1 is not set
1095# CONFIG_CRYPTO_SHA256 is not set 1118# CONFIG_CRYPTO_SHA256 is not set
1096# CONFIG_CRYPTO_SHA512 is not set 1119# CONFIG_CRYPTO_SHA512 is not set
diff --git a/arch/ia64/configs/zx1_defconfig b/arch/ia64/configs/zx1_defconfig
index 21d6f9bab5e9..b7755e4436d2 100644
--- a/arch/ia64/configs/zx1_defconfig
+++ b/arch/ia64/configs/zx1_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.10 3# Linux kernel version: 2.6.13-rc1-20050629
4# Wed Dec 29 09:05:48 2004 4# Wed Jun 29 15:31:11 2005
5# 5#
6 6
7# 7#
@@ -12,6 +12,7 @@ CONFIG_EXPERIMENTAL=y
12CONFIG_BROKEN=y 12CONFIG_BROKEN=y
13CONFIG_BROKEN_ON_SMP=y 13CONFIG_BROKEN_ON_SMP=y
14CONFIG_LOCK_KERNEL=y 14CONFIG_LOCK_KERNEL=y
15CONFIG_INIT_ENV_ARG_LIMIT=32
15 16
16# 17#
17# General setup 18# General setup
@@ -24,23 +25,26 @@ CONFIG_BSD_PROCESS_ACCT=y
24# CONFIG_BSD_PROCESS_ACCT_V3 is not set 25# CONFIG_BSD_PROCESS_ACCT_V3 is not set
25CONFIG_SYSCTL=y 26CONFIG_SYSCTL=y
26# CONFIG_AUDIT is not set 27# CONFIG_AUDIT is not set
27CONFIG_LOG_BUF_SHIFT=17
28CONFIG_HOTPLUG=y 28CONFIG_HOTPLUG=y
29CONFIG_KOBJECT_UEVENT=y 29CONFIG_KOBJECT_UEVENT=y
30# CONFIG_IKCONFIG is not set 30# CONFIG_IKCONFIG is not set
31# CONFIG_CPUSETS is not set
31# CONFIG_EMBEDDED is not set 32# CONFIG_EMBEDDED is not set
32CONFIG_KALLSYMS=y 33CONFIG_KALLSYMS=y
33# CONFIG_KALLSYMS_ALL is not set 34# CONFIG_KALLSYMS_ALL is not set
34# CONFIG_KALLSYMS_EXTRA_PASS is not set 35# CONFIG_KALLSYMS_EXTRA_PASS is not set
36CONFIG_PRINTK=y
37CONFIG_BUG=y
38CONFIG_BASE_FULL=y
35CONFIG_FUTEX=y 39CONFIG_FUTEX=y
36CONFIG_EPOLL=y 40CONFIG_EPOLL=y
37# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
38CONFIG_SHMEM=y 41CONFIG_SHMEM=y
39CONFIG_CC_ALIGN_FUNCTIONS=0 42CONFIG_CC_ALIGN_FUNCTIONS=0
40CONFIG_CC_ALIGN_LABELS=0 43CONFIG_CC_ALIGN_LABELS=0
41CONFIG_CC_ALIGN_LOOPS=0 44CONFIG_CC_ALIGN_LOOPS=0
42CONFIG_CC_ALIGN_JUMPS=0 45CONFIG_CC_ALIGN_JUMPS=0
43# CONFIG_TINY_SHMEM is not set 46# CONFIG_TINY_SHMEM is not set
47CONFIG_BASE_SMALL=0
44 48
45# 49#
46# Loadable module support 50# Loadable module support
@@ -59,12 +63,15 @@ CONFIG_IA64=y
59CONFIG_64BIT=y 63CONFIG_64BIT=y
60CONFIG_MMU=y 64CONFIG_MMU=y
61CONFIG_RWSEM_XCHGADD_ALGORITHM=y 65CONFIG_RWSEM_XCHGADD_ALGORITHM=y
66CONFIG_GENERIC_CALIBRATE_DELAY=y
62CONFIG_TIME_INTERPOLATION=y 67CONFIG_TIME_INTERPOLATION=y
63CONFIG_EFI=y 68CONFIG_EFI=y
64CONFIG_GENERIC_IOMAP=y 69CONFIG_GENERIC_IOMAP=y
70CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
65# CONFIG_IA64_GENERIC is not set 71# CONFIG_IA64_GENERIC is not set
66# CONFIG_IA64_DIG is not set 72# CONFIG_IA64_DIG is not set
67CONFIG_IA64_HP_ZX1=y 73CONFIG_IA64_HP_ZX1=y
74# CONFIG_IA64_HP_ZX1_SWIOTLB is not set
68# CONFIG_IA64_SGI_SN2 is not set 75# CONFIG_IA64_SGI_SN2 is not set
69# CONFIG_IA64_HP_SIM is not set 76# CONFIG_IA64_HP_SIM is not set
70# CONFIG_ITANIUM is not set 77# CONFIG_ITANIUM is not set
@@ -73,22 +80,36 @@ CONFIG_MCKINLEY=y
73# CONFIG_IA64_PAGE_SIZE_8KB is not set 80# CONFIG_IA64_PAGE_SIZE_8KB is not set
74CONFIG_IA64_PAGE_SIZE_16KB=y 81CONFIG_IA64_PAGE_SIZE_16KB=y
75# CONFIG_IA64_PAGE_SIZE_64KB is not set 82# CONFIG_IA64_PAGE_SIZE_64KB is not set
83# CONFIG_HZ_100 is not set
84CONFIG_HZ_250=y
85# CONFIG_HZ_1000 is not set
86CONFIG_HZ=250
76CONFIG_IA64_L1_CACHE_SHIFT=7 87CONFIG_IA64_L1_CACHE_SHIFT=7
77# CONFIG_NUMA is not set 88# CONFIG_NUMA is not set
78CONFIG_VIRTUAL_MEM_MAP=y 89CONFIG_VIRTUAL_MEM_MAP=y
90CONFIG_HOLES_IN_ZONE=y
79# CONFIG_IA64_CYCLONE is not set 91# CONFIG_IA64_CYCLONE is not set
80CONFIG_IOSAPIC=y 92CONFIG_IOSAPIC=y
93# CONFIG_IA64_SGI_SN_XP is not set
81CONFIG_FORCE_MAX_ZONEORDER=18 94CONFIG_FORCE_MAX_ZONEORDER=18
82CONFIG_SMP=y 95CONFIG_SMP=y
83CONFIG_NR_CPUS=16 96CONFIG_NR_CPUS=16
84# CONFIG_HOTPLUG_CPU is not set 97# CONFIG_HOTPLUG_CPU is not set
98# CONFIG_SCHED_SMT is not set
85# CONFIG_PREEMPT is not set 99# CONFIG_PREEMPT is not set
100CONFIG_SELECT_MEMORY_MODEL=y
101CONFIG_FLATMEM_MANUAL=y
102# CONFIG_DISCONTIGMEM_MANUAL is not set
103# CONFIG_SPARSEMEM_MANUAL is not set
104CONFIG_FLATMEM=y
105CONFIG_FLAT_NODE_MEM_MAP=y
86CONFIG_HAVE_DEC_LOCK=y 106CONFIG_HAVE_DEC_LOCK=y
87CONFIG_IA32_SUPPORT=y 107CONFIG_IA32_SUPPORT=y
88CONFIG_COMPAT=y 108CONFIG_COMPAT=y
89CONFIG_IA64_MCA_RECOVERY=y 109CONFIG_IA64_MCA_RECOVERY=y
90CONFIG_PERFMON=y 110CONFIG_PERFMON=y
91CONFIG_IA64_PALINFO=y 111CONFIG_IA64_PALINFO=y
112CONFIG_ACPI_DEALLOCATE_IRQ=y
92 113
93# 114#
94# Firmware Drivers 115# Firmware Drivers
@@ -120,6 +141,7 @@ CONFIG_ACPI_BUS=y
120CONFIG_ACPI_POWER=y 141CONFIG_ACPI_POWER=y
121CONFIG_ACPI_PCI=y 142CONFIG_ACPI_PCI=y
122CONFIG_ACPI_SYSTEM=y 143CONFIG_ACPI_SYSTEM=y
144# CONFIG_ACPI_CONTAINER is not set
123 145
124# 146#
125# Bus options (PCI, PCMCIA) 147# Bus options (PCI, PCMCIA)
@@ -129,6 +151,7 @@ CONFIG_PCI_DOMAINS=y
129# CONFIG_PCI_MSI is not set 151# CONFIG_PCI_MSI is not set
130CONFIG_PCI_LEGACY_PROC=y 152CONFIG_PCI_LEGACY_PROC=y
131CONFIG_PCI_NAMES=y 153CONFIG_PCI_NAMES=y
154# CONFIG_PCI_DEBUG is not set
132 155
133# 156#
134# PCI Hotplug Support 157# PCI Hotplug Support
@@ -138,7 +161,6 @@ CONFIG_HOTPLUG_PCI=y
138CONFIG_HOTPLUG_PCI_ACPI=y 161CONFIG_HOTPLUG_PCI_ACPI=y
139# CONFIG_HOTPLUG_PCI_ACPI_IBM is not set 162# CONFIG_HOTPLUG_PCI_ACPI_IBM is not set
140# CONFIG_HOTPLUG_PCI_CPCI is not set 163# CONFIG_HOTPLUG_PCI_CPCI is not set
141# CONFIG_HOTPLUG_PCI_PCIE is not set
142# CONFIG_HOTPLUG_PCI_SHPC is not set 164# CONFIG_HOTPLUG_PCI_SHPC is not set
143 165
144# 166#
@@ -147,10 +169,6 @@ CONFIG_HOTPLUG_PCI_ACPI=y
147# CONFIG_PCCARD is not set 169# CONFIG_PCCARD is not set
148 170
149# 171#
150# PC-card bridges
151#
152
153#
154# Device Drivers 172# Device Drivers
155# 173#
156 174
@@ -184,6 +202,7 @@ CONFIG_PREVENT_FIRMWARE_BUILD=y
184# CONFIG_BLK_CPQ_CISS_DA is not set 202# CONFIG_BLK_CPQ_CISS_DA is not set
185# CONFIG_BLK_DEV_DAC960 is not set 203# CONFIG_BLK_DEV_DAC960 is not set
186# CONFIG_BLK_DEV_UMEM is not set 204# CONFIG_BLK_DEV_UMEM is not set
205# CONFIG_BLK_DEV_COW_COMMON is not set
187CONFIG_BLK_DEV_LOOP=y 206CONFIG_BLK_DEV_LOOP=y
188# CONFIG_BLK_DEV_CRYPTOLOOP is not set 207# CONFIG_BLK_DEV_CRYPTOLOOP is not set
189# CONFIG_BLK_DEV_NBD is not set 208# CONFIG_BLK_DEV_NBD is not set
@@ -203,6 +222,7 @@ CONFIG_IOSCHED_NOOP=y
203CONFIG_IOSCHED_AS=y 222CONFIG_IOSCHED_AS=y
204CONFIG_IOSCHED_DEADLINE=y 223CONFIG_IOSCHED_DEADLINE=y
205CONFIG_IOSCHED_CFQ=y 224CONFIG_IOSCHED_CFQ=y
225# CONFIG_ATA_OVER_ETH is not set
206 226
207# 227#
208# ATA/ATAPI/MFM/RLL support 228# ATA/ATAPI/MFM/RLL support
@@ -246,6 +266,7 @@ CONFIG_BLK_DEV_CMD64X=y
246# CONFIG_BLK_DEV_HPT366 is not set 266# CONFIG_BLK_DEV_HPT366 is not set
247# CONFIG_BLK_DEV_SC1200 is not set 267# CONFIG_BLK_DEV_SC1200 is not set
248# CONFIG_BLK_DEV_PIIX is not set 268# CONFIG_BLK_DEV_PIIX is not set
269# CONFIG_BLK_DEV_IT821X is not set
249# CONFIG_BLK_DEV_NS87415 is not set 270# CONFIG_BLK_DEV_NS87415 is not set
250# CONFIG_BLK_DEV_PDC202XX_OLD is not set 271# CONFIG_BLK_DEV_PDC202XX_OLD is not set
251# CONFIG_BLK_DEV_PDC202XX_NEW is not set 272# CONFIG_BLK_DEV_PDC202XX_NEW is not set
@@ -275,6 +296,7 @@ CONFIG_CHR_DEV_OSST=y
275CONFIG_BLK_DEV_SR=y 296CONFIG_BLK_DEV_SR=y
276CONFIG_BLK_DEV_SR_VENDOR=y 297CONFIG_BLK_DEV_SR_VENDOR=y
277CONFIG_CHR_DEV_SG=y 298CONFIG_CHR_DEV_SG=y
299# CONFIG_CHR_DEV_SCH is not set
278 300
279# 301#
280# Some SCSI devices (e.g. CD jukebox) support multiple LUNs 302# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
@@ -288,6 +310,7 @@ CONFIG_SCSI_LOGGING=y
288# 310#
289CONFIG_SCSI_SPI_ATTRS=y 311CONFIG_SCSI_SPI_ATTRS=y
290# CONFIG_SCSI_FC_ATTRS is not set 312# CONFIG_SCSI_FC_ATTRS is not set
313# CONFIG_SCSI_ISCSI_ATTRS is not set
291 314
292# 315#
293# SCSI low-level drivers 316# SCSI low-level drivers
@@ -303,13 +326,10 @@ CONFIG_SCSI_SPI_ATTRS=y
303# CONFIG_MEGARAID_NEWGEN is not set 326# CONFIG_MEGARAID_NEWGEN is not set
304# CONFIG_MEGARAID_LEGACY is not set 327# CONFIG_MEGARAID_LEGACY is not set
305# CONFIG_SCSI_SATA is not set 328# CONFIG_SCSI_SATA is not set
306# CONFIG_SCSI_BUSLOGIC is not set
307# CONFIG_SCSI_CPQFCTS is not set 329# CONFIG_SCSI_CPQFCTS is not set
308# CONFIG_SCSI_DMX3191D is not set 330# CONFIG_SCSI_DMX3191D is not set
309# CONFIG_SCSI_EATA is not set
310# CONFIG_SCSI_EATA_PIO is not set 331# CONFIG_SCSI_EATA_PIO is not set
311# CONFIG_SCSI_FUTURE_DOMAIN is not set 332# CONFIG_SCSI_FUTURE_DOMAIN is not set
312# CONFIG_SCSI_GDTH is not set
313# CONFIG_SCSI_IPS is not set 333# CONFIG_SCSI_IPS is not set
314# CONFIG_SCSI_INITIO is not set 334# CONFIG_SCSI_INITIO is not set
315# CONFIG_SCSI_INIA100 is not set 335# CONFIG_SCSI_INIA100 is not set
@@ -319,8 +339,6 @@ CONFIG_SCSI_SYM53C8XX_DEFAULT_TAGS=16
319CONFIG_SCSI_SYM53C8XX_MAX_TAGS=64 339CONFIG_SCSI_SYM53C8XX_MAX_TAGS=64
320# CONFIG_SCSI_SYM53C8XX_IOMAPPED is not set 340# CONFIG_SCSI_SYM53C8XX_IOMAPPED is not set
321# CONFIG_SCSI_IPR is not set 341# CONFIG_SCSI_IPR is not set
322# CONFIG_SCSI_PCI2000 is not set
323# CONFIG_SCSI_PCI2220I is not set
324# CONFIG_SCSI_QLOGIC_ISP is not set 342# CONFIG_SCSI_QLOGIC_ISP is not set
325# CONFIG_SCSI_QLOGIC_FC is not set 343# CONFIG_SCSI_QLOGIC_FC is not set
326CONFIG_SCSI_QLOGIC_1280=y 344CONFIG_SCSI_QLOGIC_1280=y
@@ -331,7 +349,7 @@ CONFIG_SCSI_QLA2XXX=y
331# CONFIG_SCSI_QLA2300 is not set 349# CONFIG_SCSI_QLA2300 is not set
332# CONFIG_SCSI_QLA2322 is not set 350# CONFIG_SCSI_QLA2322 is not set
333# CONFIG_SCSI_QLA6312 is not set 351# CONFIG_SCSI_QLA6312 is not set
334# CONFIG_SCSI_QLA6322 is not set 352# CONFIG_SCSI_LPFC is not set
335# CONFIG_SCSI_DC395x is not set 353# CONFIG_SCSI_DC395x is not set
336# CONFIG_SCSI_DC390T is not set 354# CONFIG_SCSI_DC390T is not set
337# CONFIG_SCSI_DEBUG is not set 355# CONFIG_SCSI_DEBUG is not set
@@ -344,9 +362,9 @@ CONFIG_SCSI_QLA2XXX=y
344# 362#
345# Fusion MPT device support 363# Fusion MPT device support
346# 364#
347CONFIG_FUSION=y 365# CONFIG_FUSION is not set
348CONFIG_FUSION_MAX_SGE=40 366# CONFIG_FUSION_SPI is not set
349# CONFIG_FUSION_CTL is not set 367# CONFIG_FUSION_FC is not set
350 368
351# 369#
352# IEEE 1394 (FireWire) support 370# IEEE 1394 (FireWire) support
@@ -368,12 +386,12 @@ CONFIG_NET=y
368# 386#
369CONFIG_PACKET=y 387CONFIG_PACKET=y
370# CONFIG_PACKET_MMAP is not set 388# CONFIG_PACKET_MMAP is not set
371# CONFIG_NETLINK_DEV is not set
372CONFIG_UNIX=y 389CONFIG_UNIX=y
373# CONFIG_NET_KEY is not set 390# CONFIG_NET_KEY is not set
374CONFIG_INET=y 391CONFIG_INET=y
375CONFIG_IP_MULTICAST=y 392CONFIG_IP_MULTICAST=y
376# CONFIG_IP_ADVANCED_ROUTER is not set 393# CONFIG_IP_ADVANCED_ROUTER is not set
394CONFIG_IP_FIB_HASH=y
377# CONFIG_IP_PNP is not set 395# CONFIG_IP_PNP is not set
378# CONFIG_NET_IPIP is not set 396# CONFIG_NET_IPIP is not set
379# CONFIG_NET_IPGRE is not set 397# CONFIG_NET_IPGRE is not set
@@ -386,6 +404,8 @@ CONFIG_IP_MULTICAST=y
386# CONFIG_INET_TUNNEL is not set 404# CONFIG_INET_TUNNEL is not set
387# CONFIG_IP_TCPDIAG is not set 405# CONFIG_IP_TCPDIAG is not set
388# CONFIG_IP_TCPDIAG_IPV6 is not set 406# CONFIG_IP_TCPDIAG_IPV6 is not set
407# CONFIG_TCP_CONG_ADVANCED is not set
408CONFIG_TCP_CONG_BIC=y
389 409
390# 410#
391# IP: Virtual Server Configuration 411# IP: Virtual Server Configuration
@@ -405,8 +425,6 @@ CONFIG_NETFILTER=y
405CONFIG_IP_NF_ARPTABLES=y 425CONFIG_IP_NF_ARPTABLES=y
406# CONFIG_IP_NF_ARPFILTER is not set 426# CONFIG_IP_NF_ARPFILTER is not set
407# CONFIG_IP_NF_ARP_MANGLE is not set 427# CONFIG_IP_NF_ARP_MANGLE is not set
408# CONFIG_IP_NF_COMPAT_IPCHAINS is not set
409# CONFIG_IP_NF_COMPAT_IPFWADM is not set
410 428
411# 429#
412# SCTP Configuration (EXPERIMENTAL) 430# SCTP Configuration (EXPERIMENTAL)
@@ -483,7 +501,6 @@ CONFIG_NET_PCI=y
483# CONFIG_DGRS is not set 501# CONFIG_DGRS is not set
484# CONFIG_EEPRO100 is not set 502# CONFIG_EEPRO100 is not set
485CONFIG_E100=y 503CONFIG_E100=y
486# CONFIG_E100_NAPI is not set
487# CONFIG_FEALNX is not set 504# CONFIG_FEALNX is not set
488# CONFIG_NATSEMI is not set 505# CONFIG_NATSEMI is not set
489# CONFIG_NE2K_PCI is not set 506# CONFIG_NE2K_PCI is not set
@@ -505,9 +522,11 @@ CONFIG_E1000=y
505# CONFIG_HAMACHI is not set 522# CONFIG_HAMACHI is not set
506# CONFIG_YELLOWFIN is not set 523# CONFIG_YELLOWFIN is not set
507# CONFIG_R8169 is not set 524# CONFIG_R8169 is not set
525# CONFIG_SKGE is not set
508# CONFIG_SK98LIN is not set 526# CONFIG_SK98LIN is not set
509# CONFIG_VIA_VELOCITY is not set 527# CONFIG_VIA_VELOCITY is not set
510CONFIG_TIGON3=y 528CONFIG_TIGON3=y
529# CONFIG_BNX2 is not set
511 530
512# 531#
513# Ethernet (10000 Mbit) 532# Ethernet (10000 Mbit)
@@ -565,18 +584,6 @@ CONFIG_INPUT_EVDEV=y
565# CONFIG_INPUT_EVBUG is not set 584# CONFIG_INPUT_EVBUG is not set
566 585
567# 586#
568# Input I/O drivers
569#
570# CONFIG_GAMEPORT is not set
571CONFIG_SOUND_GAMEPORT=y
572CONFIG_SERIO=y
573# CONFIG_SERIO_I8042 is not set
574# CONFIG_SERIO_SERPORT is not set
575# CONFIG_SERIO_CT82C710 is not set
576# CONFIG_SERIO_PCIPS2 is not set
577# CONFIG_SERIO_RAW is not set
578
579#
580# Input Device Drivers 587# Input Device Drivers
581# 588#
582# CONFIG_INPUT_KEYBOARD is not set 589# CONFIG_INPUT_KEYBOARD is not set
@@ -586,6 +593,16 @@ CONFIG_SERIO=y
586# CONFIG_INPUT_MISC is not set 593# CONFIG_INPUT_MISC is not set
587 594
588# 595#
596# Hardware I/O ports
597#
598CONFIG_SERIO=y
599# CONFIG_SERIO_I8042 is not set
600# CONFIG_SERIO_SERPORT is not set
601# CONFIG_SERIO_PCIPS2 is not set
602# CONFIG_SERIO_RAW is not set
603# CONFIG_GAMEPORT is not set
604
605#
589# Character devices 606# Character devices
590# 607#
591CONFIG_VT=y 608CONFIG_VT=y
@@ -603,7 +620,6 @@ CONFIG_SERIAL_8250_NR_UARTS=8
603CONFIG_SERIAL_8250_EXTENDED=y 620CONFIG_SERIAL_8250_EXTENDED=y
604CONFIG_SERIAL_8250_SHARE_IRQ=y 621CONFIG_SERIAL_8250_SHARE_IRQ=y
605# CONFIG_SERIAL_8250_DETECT_IRQ is not set 622# CONFIG_SERIAL_8250_DETECT_IRQ is not set
606# CONFIG_SERIAL_8250_MULTIPORT is not set
607# CONFIG_SERIAL_8250_RSA is not set 623# CONFIG_SERIAL_8250_RSA is not set
608 624
609# 625#
@@ -611,6 +627,7 @@ CONFIG_SERIAL_8250_SHARE_IRQ=y
611# 627#
612CONFIG_SERIAL_CORE=y 628CONFIG_SERIAL_CORE=y
613CONFIG_SERIAL_CORE_CONSOLE=y 629CONFIG_SERIAL_CORE_CONSOLE=y
630# CONFIG_SERIAL_JSM is not set
614CONFIG_UNIX98_PTYS=y 631CONFIG_UNIX98_PTYS=y
615CONFIG_LEGACY_PTYS=y 632CONFIG_LEGACY_PTYS=y
616CONFIG_LEGACY_PTY_COUNT=256 633CONFIG_LEGACY_PTY_COUNT=256
@@ -644,6 +661,12 @@ CONFIG_DRM_RADEON=y
644# CONFIG_DRM_SIS is not set 661# CONFIG_DRM_SIS is not set
645# CONFIG_RAW_DRIVER is not set 662# CONFIG_RAW_DRIVER is not set
646# CONFIG_HPET is not set 663# CONFIG_HPET is not set
664# CONFIG_HANGCHECK_TIMER is not set
665
666#
667# TPM devices
668#
669# CONFIG_TCG_TPM is not set
647 670
648# 671#
649# I2C support 672# I2C support
@@ -668,6 +691,7 @@ CONFIG_I2C_ALGOPCF=y
668# CONFIG_I2C_AMD8111 is not set 691# CONFIG_I2C_AMD8111 is not set
669# CONFIG_I2C_I801 is not set 692# CONFIG_I2C_I801 is not set
670# CONFIG_I2C_I810 is not set 693# CONFIG_I2C_I810 is not set
694# CONFIG_I2C_PIIX4 is not set
671# CONFIG_I2C_ISA is not set 695# CONFIG_I2C_ISA is not set
672# CONFIG_I2C_NFORCE2 is not set 696# CONFIG_I2C_NFORCE2 is not set
673# CONFIG_I2C_PARPORT_LIGHT is not set 697# CONFIG_I2C_PARPORT_LIGHT is not set
@@ -691,10 +715,14 @@ CONFIG_I2C_ALGOPCF=y
691# CONFIG_SENSORS_ADM1025 is not set 715# CONFIG_SENSORS_ADM1025 is not set
692# CONFIG_SENSORS_ADM1026 is not set 716# CONFIG_SENSORS_ADM1026 is not set
693# CONFIG_SENSORS_ADM1031 is not set 717# CONFIG_SENSORS_ADM1031 is not set
718# CONFIG_SENSORS_ADM9240 is not set
694# CONFIG_SENSORS_ASB100 is not set 719# CONFIG_SENSORS_ASB100 is not set
720# CONFIG_SENSORS_ATXP1 is not set
695# CONFIG_SENSORS_DS1621 is not set 721# CONFIG_SENSORS_DS1621 is not set
696# CONFIG_SENSORS_FSCHER is not set 722# CONFIG_SENSORS_FSCHER is not set
723# CONFIG_SENSORS_FSCPOS is not set
697# CONFIG_SENSORS_GL518SM is not set 724# CONFIG_SENSORS_GL518SM is not set
725# CONFIG_SENSORS_GL520SM is not set
698# CONFIG_SENSORS_IT87 is not set 726# CONFIG_SENSORS_IT87 is not set
699# CONFIG_SENSORS_LM63 is not set 727# CONFIG_SENSORS_LM63 is not set
700# CONFIG_SENSORS_LM75 is not set 728# CONFIG_SENSORS_LM75 is not set
@@ -705,21 +733,29 @@ CONFIG_I2C_ALGOPCF=y
705# CONFIG_SENSORS_LM85 is not set 733# CONFIG_SENSORS_LM85 is not set
706# CONFIG_SENSORS_LM87 is not set 734# CONFIG_SENSORS_LM87 is not set
707# CONFIG_SENSORS_LM90 is not set 735# CONFIG_SENSORS_LM90 is not set
736# CONFIG_SENSORS_LM92 is not set
708# CONFIG_SENSORS_MAX1619 is not set 737# CONFIG_SENSORS_MAX1619 is not set
709# CONFIG_SENSORS_PC87360 is not set 738# CONFIG_SENSORS_PC87360 is not set
739# CONFIG_SENSORS_SMSC47B397 is not set
740# CONFIG_SENSORS_SIS5595 is not set
710# CONFIG_SENSORS_SMSC47M1 is not set 741# CONFIG_SENSORS_SMSC47M1 is not set
711# CONFIG_SENSORS_VIA686A is not set 742# CONFIG_SENSORS_VIA686A is not set
712# CONFIG_SENSORS_W83781D is not set 743# CONFIG_SENSORS_W83781D is not set
713# CONFIG_SENSORS_W83L785TS is not set 744# CONFIG_SENSORS_W83L785TS is not set
714# CONFIG_SENSORS_W83627HF is not set 745# CONFIG_SENSORS_W83627HF is not set
746# CONFIG_SENSORS_W83627EHF is not set
715 747
716# 748#
717# Other I2C Chip support 749# Other I2C Chip support
718# 750#
751# CONFIG_SENSORS_DS1337 is not set
752# CONFIG_SENSORS_DS1374 is not set
719# CONFIG_SENSORS_EEPROM is not set 753# CONFIG_SENSORS_EEPROM is not set
720# CONFIG_SENSORS_PCF8574 is not set 754# CONFIG_SENSORS_PCF8574 is not set
755# CONFIG_SENSORS_PCA9539 is not set
721# CONFIG_SENSORS_PCF8591 is not set 756# CONFIG_SENSORS_PCF8591 is not set
722# CONFIG_SENSORS_RTC8564 is not set 757# CONFIG_SENSORS_RTC8564 is not set
758# CONFIG_SENSORS_MAX6875 is not set
723# CONFIG_I2C_DEBUG_CORE is not set 759# CONFIG_I2C_DEBUG_CORE is not set
724# CONFIG_I2C_DEBUG_ALGO is not set 760# CONFIG_I2C_DEBUG_ALGO is not set
725# CONFIG_I2C_DEBUG_BUS is not set 761# CONFIG_I2C_DEBUG_BUS is not set
@@ -746,6 +782,7 @@ CONFIG_VIDEO_DEV=y
746# 782#
747# Video Adapters 783# Video Adapters
748# 784#
785# CONFIG_TUNER_MULTI_I2C is not set
749# CONFIG_VIDEO_BT848 is not set 786# CONFIG_VIDEO_BT848 is not set
750# CONFIG_VIDEO_CPIA is not set 787# CONFIG_VIDEO_CPIA is not set
751# CONFIG_VIDEO_SAA5246A is not set 788# CONFIG_VIDEO_SAA5246A is not set
@@ -778,6 +815,11 @@ CONFIG_VIDEO_DEV=y
778# Graphics support 815# Graphics support
779# 816#
780CONFIG_FB=y 817CONFIG_FB=y
818CONFIG_FB_CFB_FILLRECT=y
819CONFIG_FB_CFB_COPYAREA=y
820CONFIG_FB_CFB_IMAGEBLIT=y
821CONFIG_FB_SOFT_CURSOR=y
822# CONFIG_FB_MACMODES is not set
781CONFIG_FB_MODE_HELPERS=y 823CONFIG_FB_MODE_HELPERS=y
782# CONFIG_FB_TILEBLITTING is not set 824# CONFIG_FB_TILEBLITTING is not set
783# CONFIG_FB_CIRRUS is not set 825# CONFIG_FB_CIRRUS is not set
@@ -785,6 +827,7 @@ CONFIG_FB_MODE_HELPERS=y
785# CONFIG_FB_CYBER2000 is not set 827# CONFIG_FB_CYBER2000 is not set
786# CONFIG_FB_ASILIANT is not set 828# CONFIG_FB_ASILIANT is not set
787# CONFIG_FB_IMSTT is not set 829# CONFIG_FB_IMSTT is not set
830# CONFIG_FB_NVIDIA is not set
788# CONFIG_FB_RIVA is not set 831# CONFIG_FB_RIVA is not set
789# CONFIG_FB_MATROX is not set 832# CONFIG_FB_MATROX is not set
790# CONFIG_FB_RADEON_OLD is not set 833# CONFIG_FB_RADEON_OLD is not set
@@ -801,6 +844,7 @@ CONFIG_FB_RADEON_DEBUG=y
801# CONFIG_FB_VOODOO1 is not set 844# CONFIG_FB_VOODOO1 is not set
802# CONFIG_FB_TRIDENT is not set 845# CONFIG_FB_TRIDENT is not set
803# CONFIG_FB_PM3 is not set 846# CONFIG_FB_PM3 is not set
847# CONFIG_FB_S1D13XXX is not set
804# CONFIG_FB_VIRTUAL is not set 848# CONFIG_FB_VIRTUAL is not set
805 849
806# 850#
@@ -820,6 +864,7 @@ CONFIG_LOGO=y
820# CONFIG_LOGO_LINUX_MONO is not set 864# CONFIG_LOGO_LINUX_MONO is not set
821# CONFIG_LOGO_LINUX_VGA16 is not set 865# CONFIG_LOGO_LINUX_VGA16 is not set
822CONFIG_LOGO_LINUX_CLUT224=y 866CONFIG_LOGO_LINUX_CLUT224=y
867# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
823 868
824# 869#
825# Sound 870# Sound
@@ -869,6 +914,8 @@ CONFIG_SND_AC97_CODEC=y
869# CONFIG_SND_CS46XX is not set 914# CONFIG_SND_CS46XX is not set
870# CONFIG_SND_CS4281 is not set 915# CONFIG_SND_CS4281 is not set
871# CONFIG_SND_EMU10K1 is not set 916# CONFIG_SND_EMU10K1 is not set
917# CONFIG_SND_EMU10K1X is not set
918# CONFIG_SND_CA0106 is not set
872# CONFIG_SND_KORG1212 is not set 919# CONFIG_SND_KORG1212 is not set
873# CONFIG_SND_MIXART is not set 920# CONFIG_SND_MIXART is not set
874# CONFIG_SND_NM256 is not set 921# CONFIG_SND_NM256 is not set
@@ -876,6 +923,7 @@ CONFIG_SND_AC97_CODEC=y
876# CONFIG_SND_RME96 is not set 923# CONFIG_SND_RME96 is not set
877# CONFIG_SND_RME9652 is not set 924# CONFIG_SND_RME9652 is not set
878# CONFIG_SND_HDSP is not set 925# CONFIG_SND_HDSP is not set
926# CONFIG_SND_HDSPM is not set
879# CONFIG_SND_TRIDENT is not set 927# CONFIG_SND_TRIDENT is not set
880# CONFIG_SND_YMFPCI is not set 928# CONFIG_SND_YMFPCI is not set
881# CONFIG_SND_ALS4000 is not set 929# CONFIG_SND_ALS4000 is not set
@@ -893,13 +941,14 @@ CONFIG_SND_FM801_TEA575X=y
893# CONFIG_SND_INTEL8X0M is not set 941# CONFIG_SND_INTEL8X0M is not set
894# CONFIG_SND_SONICVIBES is not set 942# CONFIG_SND_SONICVIBES is not set
895# CONFIG_SND_VIA82XX is not set 943# CONFIG_SND_VIA82XX is not set
944# CONFIG_SND_VIA82XX_MODEM is not set
896# CONFIG_SND_VX222 is not set 945# CONFIG_SND_VX222 is not set
946# CONFIG_SND_HDA_INTEL is not set
897 947
898# 948#
899# USB devices 949# USB devices
900# 950#
901# CONFIG_SND_USB_AUDIO is not set 951# CONFIG_SND_USB_AUDIO is not set
902# CONFIG_SND_USB_USX2Y is not set
903 952
904# 953#
905# Open Sound System 954# Open Sound System
@@ -909,6 +958,8 @@ CONFIG_SND_FM801_TEA575X=y
909# 958#
910# USB support 959# USB support
911# 960#
961CONFIG_USB_ARCH_HAS_HCD=y
962CONFIG_USB_ARCH_HAS_OHCI=y
912CONFIG_USB=y 963CONFIG_USB=y
913# CONFIG_USB_DEBUG is not set 964# CONFIG_USB_DEBUG is not set
914 965
@@ -920,8 +971,6 @@ CONFIG_USB_BANDWIDTH=y
920# CONFIG_USB_DYNAMIC_MINORS is not set 971# CONFIG_USB_DYNAMIC_MINORS is not set
921# CONFIG_USB_SUSPEND is not set 972# CONFIG_USB_SUSPEND is not set
922# CONFIG_USB_OTG is not set 973# CONFIG_USB_OTG is not set
923CONFIG_USB_ARCH_HAS_HCD=y
924CONFIG_USB_ARCH_HAS_OHCI=y
925 974
926# 975#
927# USB Host Controller Drivers 976# USB Host Controller Drivers
@@ -929,7 +978,10 @@ CONFIG_USB_ARCH_HAS_OHCI=y
929CONFIG_USB_EHCI_HCD=y 978CONFIG_USB_EHCI_HCD=y
930# CONFIG_USB_EHCI_SPLIT_ISO is not set 979# CONFIG_USB_EHCI_SPLIT_ISO is not set
931# CONFIG_USB_EHCI_ROOT_HUB_TT is not set 980# CONFIG_USB_EHCI_ROOT_HUB_TT is not set
981# CONFIG_USB_ISP116X_HCD is not set
932CONFIG_USB_OHCI_HCD=y 982CONFIG_USB_OHCI_HCD=y
983# CONFIG_USB_OHCI_BIG_ENDIAN is not set
984CONFIG_USB_OHCI_LITTLE_ENDIAN=y
933CONFIG_USB_UHCI_HCD=y 985CONFIG_USB_UHCI_HCD=y
934# CONFIG_USB_SL811_HCD is not set 986# CONFIG_USB_SL811_HCD is not set
935 987
@@ -947,12 +999,11 @@ CONFIG_USB_UHCI_HCD=y
947# 999#
948CONFIG_USB_STORAGE=y 1000CONFIG_USB_STORAGE=y
949# CONFIG_USB_STORAGE_DEBUG is not set 1001# CONFIG_USB_STORAGE_DEBUG is not set
950# CONFIG_USB_STORAGE_RW_DETECT is not set
951# CONFIG_USB_STORAGE_DATAFAB is not set 1002# CONFIG_USB_STORAGE_DATAFAB is not set
952# CONFIG_USB_STORAGE_FREECOM is not set 1003# CONFIG_USB_STORAGE_FREECOM is not set
953# CONFIG_USB_STORAGE_ISD200 is not set 1004# CONFIG_USB_STORAGE_ISD200 is not set
954# CONFIG_USB_STORAGE_DPCM is not set 1005# CONFIG_USB_STORAGE_DPCM is not set
955# CONFIG_USB_STORAGE_HP8200e is not set 1006# CONFIG_USB_STORAGE_USBAT is not set
956# CONFIG_USB_STORAGE_SDDR09 is not set 1007# CONFIG_USB_STORAGE_SDDR09 is not set
957# CONFIG_USB_STORAGE_SDDR55 is not set 1008# CONFIG_USB_STORAGE_SDDR55 is not set
958# CONFIG_USB_STORAGE_JUMPSHOT is not set 1009# CONFIG_USB_STORAGE_JUMPSHOT is not set
@@ -966,9 +1017,11 @@ CONFIG_USB_HIDINPUT=y
966CONFIG_USB_HIDDEV=y 1017CONFIG_USB_HIDDEV=y
967# CONFIG_USB_AIPTEK is not set 1018# CONFIG_USB_AIPTEK is not set
968# CONFIG_USB_WACOM is not set 1019# CONFIG_USB_WACOM is not set
1020# CONFIG_USB_ACECAD is not set
969# CONFIG_USB_KBTAB is not set 1021# CONFIG_USB_KBTAB is not set
970# CONFIG_USB_POWERMATE is not set 1022# CONFIG_USB_POWERMATE is not set
971# CONFIG_USB_MTOUCH is not set 1023# CONFIG_USB_MTOUCH is not set
1024# CONFIG_USB_ITMTOUCH is not set
972# CONFIG_USB_EGALAX is not set 1025# CONFIG_USB_EGALAX is not set
973# CONFIG_USB_XPAD is not set 1026# CONFIG_USB_XPAD is not set
974# CONFIG_USB_ATI_REMOTE is not set 1027# CONFIG_USB_ATI_REMOTE is not set
@@ -978,7 +1031,6 @@ CONFIG_USB_HIDDEV=y
978# 1031#
979# CONFIG_USB_MDC800 is not set 1032# CONFIG_USB_MDC800 is not set
980# CONFIG_USB_MICROTEK is not set 1033# CONFIG_USB_MICROTEK is not set
981# CONFIG_USB_HPUSBSCSI is not set
982 1034
983# 1035#
984# USB Multimedia devices 1036# USB Multimedia devices
@@ -992,6 +1044,7 @@ CONFIG_USB_HIDDEV=y
992# CONFIG_USB_SE401 is not set 1044# CONFIG_USB_SE401 is not set
993# CONFIG_USB_SN9C102 is not set 1045# CONFIG_USB_SN9C102 is not set
994# CONFIG_USB_STV680 is not set 1046# CONFIG_USB_STV680 is not set
1047# CONFIG_USB_PWC is not set
995 1048
996# 1049#
997# USB Network Adapters 1050# USB Network Adapters
@@ -1001,6 +1054,7 @@ CONFIG_USB_HIDDEV=y
1001# CONFIG_USB_PEGASUS is not set 1054# CONFIG_USB_PEGASUS is not set
1002# CONFIG_USB_RTL8150 is not set 1055# CONFIG_USB_RTL8150 is not set
1003# CONFIG_USB_USBNET is not set 1056# CONFIG_USB_USBNET is not set
1057CONFIG_USB_MON=y
1004 1058
1005# 1059#
1006# USB port drivers 1060# USB port drivers
@@ -1016,7 +1070,6 @@ CONFIG_USB_HIDDEV=y
1016# 1070#
1017# CONFIG_USB_EMI62 is not set 1071# CONFIG_USB_EMI62 is not set
1018# CONFIG_USB_EMI26 is not set 1072# CONFIG_USB_EMI26 is not set
1019# CONFIG_USB_TIGL is not set
1020# CONFIG_USB_AUERSWALD is not set 1073# CONFIG_USB_AUERSWALD is not set
1021# CONFIG_USB_RIO500 is not set 1074# CONFIG_USB_RIO500 is not set
1022# CONFIG_USB_LEGOTOWER is not set 1075# CONFIG_USB_LEGOTOWER is not set
@@ -1025,9 +1078,11 @@ CONFIG_USB_HIDDEV=y
1025# CONFIG_USB_CYTHERM is not set 1078# CONFIG_USB_CYTHERM is not set
1026# CONFIG_USB_PHIDGETKIT is not set 1079# CONFIG_USB_PHIDGETKIT is not set
1027# CONFIG_USB_PHIDGETSERVO is not set 1080# CONFIG_USB_PHIDGETSERVO is not set
1081# CONFIG_USB_IDMOUSE is not set
1082# CONFIG_USB_SISUSBVGA is not set
1028 1083
1029# 1084#
1030# USB ATM/DSL drivers 1085# USB DSL modem support
1031# 1086#
1032 1087
1033# 1088#
@@ -1041,12 +1096,22 @@ CONFIG_USB_HIDDEV=y
1041# CONFIG_MMC is not set 1096# CONFIG_MMC is not set
1042 1097
1043# 1098#
1099# InfiniBand support
1100#
1101# CONFIG_INFINIBAND is not set
1102
1103#
1104# SN Devices
1105#
1106
1107#
1044# File systems 1108# File systems
1045# 1109#
1046CONFIG_EXT2_FS=y 1110CONFIG_EXT2_FS=y
1047CONFIG_EXT2_FS_XATTR=y 1111CONFIG_EXT2_FS_XATTR=y
1048# CONFIG_EXT2_FS_POSIX_ACL is not set 1112# CONFIG_EXT2_FS_POSIX_ACL is not set
1049# CONFIG_EXT2_FS_SECURITY is not set 1113# CONFIG_EXT2_FS_SECURITY is not set
1114# CONFIG_EXT2_FS_XIP is not set
1050CONFIG_EXT3_FS=y 1115CONFIG_EXT3_FS=y
1051CONFIG_EXT3_FS_XATTR=y 1116CONFIG_EXT3_FS_XATTR=y
1052# CONFIG_EXT3_FS_POSIX_ACL is not set 1117# CONFIG_EXT3_FS_POSIX_ACL is not set
@@ -1056,6 +1121,10 @@ CONFIG_JBD=y
1056CONFIG_FS_MBCACHE=y 1121CONFIG_FS_MBCACHE=y
1057# CONFIG_REISERFS_FS is not set 1122# CONFIG_REISERFS_FS is not set
1058# CONFIG_JFS_FS is not set 1123# CONFIG_JFS_FS is not set
1124
1125#
1126# XFS support
1127#
1059# CONFIG_XFS_FS is not set 1128# CONFIG_XFS_FS is not set
1060# CONFIG_MINIX_FS is not set 1129# CONFIG_MINIX_FS is not set
1061# CONFIG_ROMFS_FS is not set 1130# CONFIG_ROMFS_FS is not set
@@ -1089,7 +1158,6 @@ CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
1089CONFIG_PROC_FS=y 1158CONFIG_PROC_FS=y
1090CONFIG_PROC_KCORE=y 1159CONFIG_PROC_KCORE=y
1091CONFIG_SYSFS=y 1160CONFIG_SYSFS=y
1092# CONFIG_DEVFS_FS is not set
1093# CONFIG_DEVPTS_FS_XATTR is not set 1161# CONFIG_DEVPTS_FS_XATTR is not set
1094CONFIG_TMPFS=y 1162CONFIG_TMPFS=y
1095CONFIG_TMPFS_XATTR=y 1163CONFIG_TMPFS_XATTR=y
@@ -1120,15 +1188,18 @@ CONFIG_RAMFS=y
1120# 1188#
1121CONFIG_NFS_FS=y 1189CONFIG_NFS_FS=y
1122CONFIG_NFS_V3=y 1190CONFIG_NFS_V3=y
1191# CONFIG_NFS_V3_ACL is not set
1123CONFIG_NFS_V4=y 1192CONFIG_NFS_V4=y
1124# CONFIG_NFS_DIRECTIO is not set 1193# CONFIG_NFS_DIRECTIO is not set
1125CONFIG_NFSD=y 1194CONFIG_NFSD=y
1126CONFIG_NFSD_V3=y 1195CONFIG_NFSD_V3=y
1196# CONFIG_NFSD_V3_ACL is not set
1127# CONFIG_NFSD_V4 is not set 1197# CONFIG_NFSD_V4 is not set
1128# CONFIG_NFSD_TCP is not set 1198# CONFIG_NFSD_TCP is not set
1129CONFIG_LOCKD=y 1199CONFIG_LOCKD=y
1130CONFIG_LOCKD_V4=y 1200CONFIG_LOCKD_V4=y
1131CONFIG_EXPORTFS=y 1201CONFIG_EXPORTFS=y
1202CONFIG_NFS_COMMON=y
1132CONFIG_SUNRPC=y 1203CONFIG_SUNRPC=y
1133CONFIG_SUNRPC_GSS=y 1204CONFIG_SUNRPC_GSS=y
1134CONFIG_RPCSEC_GSS_KRB5=y 1205CONFIG_RPCSEC_GSS_KRB5=y
@@ -1209,6 +1280,8 @@ CONFIG_NLS_UTF8=y
1209# CONFIG_CRC_CCITT is not set 1280# CONFIG_CRC_CCITT is not set
1210CONFIG_CRC32=y 1281CONFIG_CRC32=y
1211# CONFIG_LIBCRC32C is not set 1282# CONFIG_LIBCRC32C is not set
1283CONFIG_GENERIC_HARDIRQS=y
1284CONFIG_GENERIC_IRQ_PROBE=y
1212 1285
1213# 1286#
1214# Profiling support 1287# Profiling support
@@ -1218,14 +1291,18 @@ CONFIG_CRC32=y
1218# 1291#
1219# Kernel hacking 1292# Kernel hacking
1220# 1293#
1294# CONFIG_PRINTK_TIME is not set
1221CONFIG_DEBUG_KERNEL=y 1295CONFIG_DEBUG_KERNEL=y
1222CONFIG_MAGIC_SYSRQ=y 1296CONFIG_MAGIC_SYSRQ=y
1297CONFIG_LOG_BUF_SHIFT=17
1223# CONFIG_SCHEDSTATS is not set 1298# CONFIG_SCHEDSTATS is not set
1224# CONFIG_DEBUG_SLAB is not set 1299# CONFIG_DEBUG_SLAB is not set
1225# CONFIG_DEBUG_SPINLOCK is not set 1300# CONFIG_DEBUG_SPINLOCK is not set
1226# CONFIG_DEBUG_SPINLOCK_SLEEP is not set 1301# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
1227# CONFIG_DEBUG_KOBJECT is not set 1302# CONFIG_DEBUG_KOBJECT is not set
1228# CONFIG_DEBUG_INFO is not set 1303# CONFIG_DEBUG_INFO is not set
1304# CONFIG_DEBUG_FS is not set
1305CONFIG_KPROBES=y
1229CONFIG_IA64_GRANULE_16MB=y 1306CONFIG_IA64_GRANULE_16MB=y
1230# CONFIG_IA64_GRANULE_64MB is not set 1307# CONFIG_IA64_GRANULE_64MB is not set
1231CONFIG_IA64_PRINT_HAZARDS=y 1308CONFIG_IA64_PRINT_HAZARDS=y
@@ -1252,6 +1329,7 @@ CONFIG_CRYPTO_MD5=y
1252# CONFIG_CRYPTO_SHA256 is not set 1329# CONFIG_CRYPTO_SHA256 is not set
1253# CONFIG_CRYPTO_SHA512 is not set 1330# CONFIG_CRYPTO_SHA512 is not set
1254# CONFIG_CRYPTO_WP512 is not set 1331# CONFIG_CRYPTO_WP512 is not set
1332# CONFIG_CRYPTO_TGR192 is not set
1255CONFIG_CRYPTO_DES=y 1333CONFIG_CRYPTO_DES=y
1256# CONFIG_CRYPTO_BLOWFISH is not set 1334# CONFIG_CRYPTO_BLOWFISH is not set
1257# CONFIG_CRYPTO_TWOFISH is not set 1335# CONFIG_CRYPTO_TWOFISH is not set
diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c
index b8db6e3e5e81..11957598a8b9 100644
--- a/arch/ia64/hp/common/sba_iommu.c
+++ b/arch/ia64/hp/common/sba_iommu.c
@@ -156,10 +156,13 @@
156*/ 156*/
157#define DELAYED_RESOURCE_CNT 64 157#define DELAYED_RESOURCE_CNT 64
158 158
159#define PCI_DEVICE_ID_HP_SX2000_IOC 0x12ec
160
159#define ZX1_IOC_ID ((PCI_DEVICE_ID_HP_ZX1_IOC << 16) | PCI_VENDOR_ID_HP) 161#define ZX1_IOC_ID ((PCI_DEVICE_ID_HP_ZX1_IOC << 16) | PCI_VENDOR_ID_HP)
160#define ZX2_IOC_ID ((PCI_DEVICE_ID_HP_ZX2_IOC << 16) | PCI_VENDOR_ID_HP) 162#define ZX2_IOC_ID ((PCI_DEVICE_ID_HP_ZX2_IOC << 16) | PCI_VENDOR_ID_HP)
161#define REO_IOC_ID ((PCI_DEVICE_ID_HP_REO_IOC << 16) | PCI_VENDOR_ID_HP) 163#define REO_IOC_ID ((PCI_DEVICE_ID_HP_REO_IOC << 16) | PCI_VENDOR_ID_HP)
162#define SX1000_IOC_ID ((PCI_DEVICE_ID_HP_SX1000_IOC << 16) | PCI_VENDOR_ID_HP) 164#define SX1000_IOC_ID ((PCI_DEVICE_ID_HP_SX1000_IOC << 16) | PCI_VENDOR_ID_HP)
165#define SX2000_IOC_ID ((PCI_DEVICE_ID_HP_SX2000_IOC << 16) | PCI_VENDOR_ID_HP)
163 166
164#define ZX1_IOC_OFFSET 0x1000 /* ACPI reports SBA, we want IOC */ 167#define ZX1_IOC_OFFSET 0x1000 /* ACPI reports SBA, we want IOC */
165 168
@@ -1726,6 +1729,7 @@ static struct ioc_iommu ioc_iommu_info[] __initdata = {
1726 { ZX1_IOC_ID, "zx1", ioc_zx1_init }, 1729 { ZX1_IOC_ID, "zx1", ioc_zx1_init },
1727 { ZX2_IOC_ID, "zx2", NULL }, 1730 { ZX2_IOC_ID, "zx2", NULL },
1728 { SX1000_IOC_ID, "sx1000", NULL }, 1731 { SX1000_IOC_ID, "sx1000", NULL },
1732 { SX2000_IOC_ID, "sx2000", NULL },
1729}; 1733};
1730 1734
1731static struct ioc * __init 1735static struct ioc * __init
diff --git a/arch/ia64/hp/sim/simserial.c b/arch/ia64/hp/sim/simserial.c
index 786e70718ce4..7a8ae0f4b387 100644
--- a/arch/ia64/hp/sim/simserial.c
+++ b/arch/ia64/hp/sim/simserial.c
@@ -30,6 +30,7 @@
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/serial.h> 31#include <linux/serial.h>
32#include <linux/serialP.h> 32#include <linux/serialP.h>
33#include <linux/sysrq.h>
33 34
34#include <asm/irq.h> 35#include <asm/irq.h>
35#include <asm/hw_irq.h> 36#include <asm/hw_irq.h>
@@ -149,12 +150,17 @@ static void receive_chars(struct tty_struct *tty, struct pt_regs *regs)
149 seen_esc = 2; 150 seen_esc = 2;
150 continue; 151 continue;
151 } else if ( seen_esc == 2 ) { 152 } else if ( seen_esc == 2 ) {
152 if ( ch == 'P' ) show_state(); /* F1 key */ 153 if ( ch == 'P' ) /* F1 */
153#ifdef CONFIG_KDB 154 show_state();
154 if ( ch == 'S' ) 155#ifdef CONFIG_MAGIC_SYSRQ
155 kdb(KDB_REASON_KEYBOARD, 0, (kdb_eframe_t) regs); 156 if ( ch == 'S' ) { /* F4 */
157 do
158 ch = ia64_ssc(0, 0, 0, 0,
159 SSC_GETCHAR);
160 while (!ch);
161 handle_sysrq(ch, regs, NULL);
162 }
156#endif 163#endif
157
158 seen_esc = 0; 164 seen_esc = 0;
159 continue; 165 continue;
160 } 166 }
diff --git a/arch/ia64/kernel/acpi.c b/arch/ia64/kernel/acpi.c
index 72dfd9e7de0f..cda06f88c66e 100644
--- a/arch/ia64/kernel/acpi.c
+++ b/arch/ia64/kernel/acpi.c
@@ -236,9 +236,7 @@ acpi_parse_iosapic (acpi_table_entry_header *header, const unsigned long end)
236 if (BAD_MADT_ENTRY(iosapic, end)) 236 if (BAD_MADT_ENTRY(iosapic, end))
237 return -EINVAL; 237 return -EINVAL;
238 238
239 iosapic_init(iosapic->address, iosapic->global_irq_base); 239 return iosapic_init(iosapic->address, iosapic->global_irq_base);
240
241 return 0;
242} 240}
243 241
244 242
@@ -772,7 +770,7 @@ EXPORT_SYMBOL(acpi_unmap_lsapic);
772 770
773 771
774#ifdef CONFIG_ACPI_NUMA 772#ifdef CONFIG_ACPI_NUMA
775acpi_status __init 773acpi_status __devinit
776acpi_map_iosapic (acpi_handle handle, u32 depth, void *context, void **ret) 774acpi_map_iosapic (acpi_handle handle, u32 depth, void *context, void **ret)
777{ 775{
778 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; 776 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
@@ -825,4 +823,28 @@ acpi_map_iosapic (acpi_handle handle, u32 depth, void *context, void **ret)
825 return AE_OK; 823 return AE_OK;
826} 824}
827#endif /* CONFIG_NUMA */ 825#endif /* CONFIG_NUMA */
826
827int
828acpi_register_ioapic (acpi_handle handle, u64 phys_addr, u32 gsi_base)
829{
830 int err;
831
832 if ((err = iosapic_init(phys_addr, gsi_base)))
833 return err;
834
835#if CONFIG_ACPI_NUMA
836 acpi_map_iosapic(handle, 0, NULL, NULL);
837#endif /* CONFIG_ACPI_NUMA */
838
839 return 0;
840}
841EXPORT_SYMBOL(acpi_register_ioapic);
842
843int
844acpi_unregister_ioapic (acpi_handle handle, u32 gsi_base)
845{
846 return iosapic_remove(gsi_base);
847}
848EXPORT_SYMBOL(acpi_unregister_ioapic);
849
828#endif /* CONFIG_ACPI_BOOT */ 850#endif /* CONFIG_ACPI_BOOT */
diff --git a/arch/ia64/kernel/entry.S b/arch/ia64/kernel/entry.S
index b1d5d3d5276c..69f88d561d62 100644
--- a/arch/ia64/kernel/entry.S
+++ b/arch/ia64/kernel/entry.S
@@ -470,18 +470,6 @@ ENTRY(load_switch_stack)
470 br.cond.sptk.many b7 470 br.cond.sptk.many b7
471END(load_switch_stack) 471END(load_switch_stack)
472 472
473GLOBAL_ENTRY(__ia64_syscall)
474 .regstk 6,0,0,0
475 mov r15=in5 // put syscall number in place
476 break __BREAK_SYSCALL
477 movl r2=errno
478 cmp.eq p6,p7=-1,r10
479 ;;
480(p6) st4 [r2]=r8
481(p6) mov r8=-1
482 br.ret.sptk.many rp
483END(__ia64_syscall)
484
485GLOBAL_ENTRY(execve) 473GLOBAL_ENTRY(execve)
486 mov r15=__NR_execve // put syscall number in place 474 mov r15=__NR_execve // put syscall number in place
487 break __BREAK_SYSCALL 475 break __BREAK_SYSCALL
@@ -637,7 +625,7 @@ END(ia64_ret_from_syscall)
637 * r8-r11: restored (syscall return value(s)) 625 * r8-r11: restored (syscall return value(s))
638 * r12: restored (user-level stack pointer) 626 * r12: restored (user-level stack pointer)
639 * r13: restored (user-level thread pointer) 627 * r13: restored (user-level thread pointer)
640 * r14: cleared 628 * r14: set to __kernel_syscall_via_epc
641 * r15: restored (syscall #) 629 * r15: restored (syscall #)
642 * r16-r17: cleared 630 * r16-r17: cleared
643 * r18: user-level b6 631 * r18: user-level b6
@@ -658,7 +646,7 @@ END(ia64_ret_from_syscall)
658 * pr: restored (user-level pr) 646 * pr: restored (user-level pr)
659 * b0: restored (user-level rp) 647 * b0: restored (user-level rp)
660 * b6: restored 648 * b6: restored
661 * b7: cleared 649 * b7: set to __kernel_syscall_via_epc
662 * ar.unat: restored (user-level ar.unat) 650 * ar.unat: restored (user-level ar.unat)
663 * ar.pfs: restored (user-level ar.pfs) 651 * ar.pfs: restored (user-level ar.pfs)
664 * ar.rsc: restored (user-level ar.rsc) 652 * ar.rsc: restored (user-level ar.rsc)
@@ -704,72 +692,79 @@ ENTRY(ia64_leave_syscall)
704 ;; 692 ;;
705(p6) ld4 r31=[r18] // load current_thread_info()->flags 693(p6) ld4 r31=[r18] // load current_thread_info()->flags
706 ld8 r19=[r2],PT(B6)-PT(LOADRS) // load ar.rsc value for "loadrs" 694 ld8 r19=[r2],PT(B6)-PT(LOADRS) // load ar.rsc value for "loadrs"
707 mov b7=r0 // clear b7 695 nop.i 0
708 ;; 696 ;;
709 ld8 r23=[r3],PT(R11)-PT(AR_BSPSTORE) // load ar.bspstore (may be garbage) 697 mov r16=ar.bsp // M2 get existing backing store pointer
710 ld8 r18=[r2],PT(R9)-PT(B6) // load b6 698 ld8 r18=[r2],PT(R9)-PT(B6) // load b6
711(p6) and r15=TIF_WORK_MASK,r31 // any work other than TIF_SYSCALL_TRACE? 699(p6) and r15=TIF_WORK_MASK,r31 // any work other than TIF_SYSCALL_TRACE?
712 ;; 700 ;;
713 mov r16=ar.bsp // M2 get existing backing store pointer 701 ld8 r23=[r3],PT(R11)-PT(AR_BSPSTORE) // load ar.bspstore (may be garbage)
714(p6) cmp4.ne.unc p6,p0=r15, r0 // any special work pending? 702(p6) cmp4.ne.unc p6,p0=r15, r0 // any special work pending?
715(p6) br.cond.spnt .work_pending_syscall 703(p6) br.cond.spnt .work_pending_syscall
716 ;; 704 ;;
717 // start restoring the state saved on the kernel stack (struct pt_regs): 705 // start restoring the state saved on the kernel stack (struct pt_regs):
718 ld8 r9=[r2],PT(CR_IPSR)-PT(R9) 706 ld8 r9=[r2],PT(CR_IPSR)-PT(R9)
719 ld8 r11=[r3],PT(CR_IIP)-PT(R11) 707 ld8 r11=[r3],PT(CR_IIP)-PT(R11)
720 mov f6=f0 // clear f6 708(pNonSys) break 0 // bug check: we shouldn't be here if pNonSys is TRUE!
721 ;; 709 ;;
722 invala // M0|1 invalidate ALAT 710 invala // M0|1 invalidate ALAT
723 rsm psr.i | psr.ic // M2 initiate turning off of interrupt and interruption collection 711 rsm psr.i | psr.ic // M2 turn off interrupts and interruption collection
724 mov f9=f0 // clear f9 712 cmp.eq p9,p0=r0,r0 // A set p9 to indicate that we should restore cr.ifs
725 713
726 ld8 r29=[r2],16 // load cr.ipsr 714 ld8 r29=[r2],16 // M0|1 load cr.ipsr
727 ld8 r28=[r3],16 // load cr.iip 715 ld8 r28=[r3],16 // M0|1 load cr.iip
728 mov f8=f0 // clear f8 716 mov r22=r0 // A clear r22
729 ;; 717 ;;
730 ld8 r30=[r2],16 // M0|1 load cr.ifs 718 ld8 r30=[r2],16 // M0|1 load cr.ifs
731 ld8 r25=[r3],16 // M0|1 load ar.unat 719 ld8 r25=[r3],16 // M0|1 load ar.unat
732 cmp.eq p9,p0=r0,r0 // set p9 to indicate that we should restore cr.ifs 720(pUStk) add r14=IA64_TASK_THREAD_ON_USTACK_OFFSET,r13
733 ;; 721 ;;
734 ld8 r26=[r2],PT(B0)-PT(AR_PFS) // M0|1 load ar.pfs 722 ld8 r26=[r2],PT(B0)-PT(AR_PFS) // M0|1 load ar.pfs
735(pKStk) mov r22=psr // M2 read PSR now that interrupts are disabled 723(pKStk) mov r22=psr // M2 read PSR now that interrupts are disabled
736 mov f10=f0 // clear f10 724 nop 0
737 ;; 725 ;;
738 ld8 r21=[r2],PT(AR_RNAT)-PT(B0) // load b0 726 ld8 r21=[r2],PT(AR_RNAT)-PT(B0) // M0|1 load b0
739 ld8 r27=[r3],PT(PR)-PT(AR_RSC) // load ar.rsc 727 ld8 r27=[r3],PT(PR)-PT(AR_RSC) // M0|1 load ar.rsc
740 mov f11=f0 // clear f11 728 mov f6=f0 // F clear f6
741 ;; 729 ;;
742 ld8 r24=[r2],PT(AR_FPSR)-PT(AR_RNAT) // load ar.rnat (may be garbage) 730 ld8 r24=[r2],PT(AR_FPSR)-PT(AR_RNAT) // M0|1 load ar.rnat (may be garbage)
743 ld8 r31=[r3],PT(R1)-PT(PR) // load predicates 731 ld8 r31=[r3],PT(R1)-PT(PR) // M0|1 load predicates
744(pUStk) add r14=IA64_TASK_THREAD_ON_USTACK_OFFSET,r13 732 mov f7=f0 // F clear f7
745 ;; 733 ;;
746 ld8 r20=[r2],PT(R12)-PT(AR_FPSR) // load ar.fpsr 734 ld8 r20=[r2],PT(R12)-PT(AR_FPSR) // M0|1 load ar.fpsr
747 ld8.fill r1=[r3],16 // load r1 735 ld8.fill r1=[r3],16 // M0|1 load r1
748(pUStk) mov r17=1 736(pUStk) mov r17=1 // A
749 ;; 737 ;;
750 srlz.d // M0 ensure interruption collection is off 738(pUStk) st1 [r14]=r17 // M2|3
751 ld8.fill r13=[r3],16 739 ld8.fill r13=[r3],16 // M0|1
752 mov f7=f0 // clear f7 740 mov f8=f0 // F clear f8
753 ;; 741 ;;
754 ld8.fill r12=[r2] // restore r12 (sp) 742 ld8.fill r12=[r2] // M0|1 restore r12 (sp)
755 mov.m ar.ssd=r0 // M2 clear ar.ssd 743 ld8.fill r15=[r3] // M0|1 restore r15
756 mov r22=r0 // clear r22 744 mov b6=r18 // I0 restore b6
757 745
758 ld8.fill r15=[r3] // restore r15 746 addl r17=THIS_CPU(ia64_phys_stacked_size_p8),r0 // A
759(pUStk) st1 [r14]=r17 747 mov f9=f0 // F clear f9
760 addl r3=THIS_CPU(ia64_phys_stacked_size_p8),r0 748(pKStk) br.cond.dpnt.many skip_rbs_switch // B
749
750 srlz.d // M0 ensure interruption collection is off (for cover)
751 shr.u r18=r19,16 // I0|1 get byte size of existing "dirty" partition
752 cover // B add current frame into dirty partition & set cr.ifs
761 ;; 753 ;;
762(pUStk) ld4 r17=[r3] // r17 = cpu_data->phys_stacked_size_p8 754(pUStk) ld4 r17=[r17] // M0|1 r17 = cpu_data->phys_stacked_size_p8
763 mov.m ar.csd=r0 // M2 clear ar.csd 755 mov r19=ar.bsp // M2 get new backing store pointer
764 mov b6=r18 // I0 restore b6 756 mov f10=f0 // F clear f10
757
758 nop.m 0
759 movl r14=__kernel_syscall_via_epc // X
765 ;; 760 ;;
766 mov r14=r0 // clear r14 761 mov.m ar.csd=r0 // M2 clear ar.csd
767 shr.u r18=r19,16 // I0|1 get byte size of existing "dirty" partition 762 mov.m ar.ccv=r0 // M2 clear ar.ccv
768(pKStk) br.cond.dpnt.many skip_rbs_switch 763 mov b7=r14 // I0 clear b7 (hint with __kernel_syscall_via_epc)
769 764
770 mov.m ar.ccv=r0 // clear ar.ccv 765 mov.m ar.ssd=r0 // M2 clear ar.ssd
771(pNonSys) br.cond.dpnt.many dont_preserve_current_frame 766 mov f11=f0 // F clear f11
772 br.cond.sptk.many rbs_switch 767 br.cond.sptk.many rbs_switch // B
773END(ia64_leave_syscall) 768END(ia64_leave_syscall)
774 769
775#ifdef CONFIG_IA32_SUPPORT 770#ifdef CONFIG_IA32_SUPPORT
@@ -885,7 +880,7 @@ GLOBAL_ENTRY(ia64_leave_kernel)
885 ldf.fill f7=[r2],PT(F11)-PT(F7) 880 ldf.fill f7=[r2],PT(F11)-PT(F7)
886 ldf.fill f8=[r3],32 881 ldf.fill f8=[r3],32
887 ;; 882 ;;
888 srlz.i // ensure interruption collection is off 883 srlz.d // ensure that inter. collection is off (VHPT is don't care, since text is pinned)
889 mov ar.ccv=r15 884 mov ar.ccv=r15
890 ;; 885 ;;
891 ldf.fill f11=[r2] 886 ldf.fill f11=[r2]
@@ -945,11 +940,10 @@ GLOBAL_ENTRY(ia64_leave_kernel)
945 * NOTE: alloc, loadrs, and cover can't be predicated. 940 * NOTE: alloc, loadrs, and cover can't be predicated.
946 */ 941 */
947(pNonSys) br.cond.dpnt dont_preserve_current_frame 942(pNonSys) br.cond.dpnt dont_preserve_current_frame
948
949rbs_switch:
950 cover // add current frame into dirty partition and set cr.ifs 943 cover // add current frame into dirty partition and set cr.ifs
951 ;; 944 ;;
952 mov r19=ar.bsp // get new backing store pointer 945 mov r19=ar.bsp // get new backing store pointer
946rbs_switch:
953 sub r16=r16,r18 // krbs = old bsp - size of dirty partition 947 sub r16=r16,r18 // krbs = old bsp - size of dirty partition
954 cmp.ne p9,p0=r0,r0 // clear p9 to skip restore of cr.ifs 948 cmp.ne p9,p0=r0,r0 // clear p9 to skip restore of cr.ifs
955 ;; 949 ;;
@@ -1024,14 +1018,14 @@ rse_clear_invalid:
1024 mov loc5=0 1018 mov loc5=0
1025 mov loc6=0 1019 mov loc6=0
1026 mov loc7=0 1020 mov loc7=0
1027(pRecurse) br.call.sptk.few b0=rse_clear_invalid 1021(pRecurse) br.call.dptk.few b0=rse_clear_invalid
1028 ;; 1022 ;;
1029 mov loc8=0 1023 mov loc8=0
1030 mov loc9=0 1024 mov loc9=0
1031 cmp.ne pReturn,p0=r0,in1 // if recursion count != 0, we need to do a br.ret 1025 cmp.ne pReturn,p0=r0,in1 // if recursion count != 0, we need to do a br.ret
1032 mov loc10=0 1026 mov loc10=0
1033 mov loc11=0 1027 mov loc11=0
1034(pReturn) br.ret.sptk.many b0 1028(pReturn) br.ret.dptk.many b0
1035#endif /* !CONFIG_ITANIUM */ 1029#endif /* !CONFIG_ITANIUM */
1036# undef pRecurse 1030# undef pRecurse
1037# undef pReturn 1031# undef pReturn
@@ -1577,8 +1571,8 @@ sys_call_table:
1577 data8 sys_add_key 1571 data8 sys_add_key
1578 data8 sys_request_key 1572 data8 sys_request_key
1579 data8 sys_keyctl 1573 data8 sys_keyctl
1580 data8 sys_ni_syscall 1574 data8 sys_ioprio_set
1581 data8 sys_ni_syscall // 1275 1575 data8 sys_ioprio_get // 1275
1582 data8 sys_set_zone_reclaim 1576 data8 sys_set_zone_reclaim
1583 data8 sys_ni_syscall 1577 data8 sys_ni_syscall
1584 data8 sys_ni_syscall 1578 data8 sys_ni_syscall
diff --git a/arch/ia64/kernel/fsys.S b/arch/ia64/kernel/fsys.S
index 962b6c4e32b5..7d7684a369d3 100644
--- a/arch/ia64/kernel/fsys.S
+++ b/arch/ia64/kernel/fsys.S
@@ -531,93 +531,114 @@ GLOBAL_ENTRY(fsys_bubble_down)
531 .altrp b6 531 .altrp b6
532 .body 532 .body
533 /* 533 /*
534 * We get here for syscalls that don't have a lightweight handler. For those, we 534 * We get here for syscalls that don't have a lightweight
535 * need to bubble down into the kernel and that requires setting up a minimal 535 * handler. For those, we need to bubble down into the kernel
536 * pt_regs structure, and initializing the CPU state more or less as if an 536 * and that requires setting up a minimal pt_regs structure,
537 * interruption had occurred. To make syscall-restarts work, we setup pt_regs 537 * and initializing the CPU state more or less as if an
538 * such that cr_iip points to the second instruction in syscall_via_break. 538 * interruption had occurred. To make syscall-restarts work,
539 * Decrementing the IP hence will restart the syscall via break and not 539 * we setup pt_regs such that cr_iip points to the second
540 * decrementing IP will return us to the caller, as usual. Note that we preserve 540 * instruction in syscall_via_break. Decrementing the IP
541 * the value of psr.pp rather than initializing it from dcr.pp. This makes it 541 * hence will restart the syscall via break and not
542 * possible to distinguish fsyscall execution from other privileged execution. 542 * decrementing IP will return us to the caller, as usual.
543 * Note that we preserve the value of psr.pp rather than
544 * initializing it from dcr.pp. This makes it possible to
545 * distinguish fsyscall execution from other privileged
546 * execution.
543 * 547 *
544 * On entry: 548 * On entry:
545 * - normal fsyscall handler register usage, except that we also have: 549 * - normal fsyscall handler register usage, except
550 * that we also have:
546 * - r18: address of syscall entry point 551 * - r18: address of syscall entry point
547 * - r21: ar.fpsr 552 * - r21: ar.fpsr
548 * - r26: ar.pfs 553 * - r26: ar.pfs
549 * - r27: ar.rsc 554 * - r27: ar.rsc
550 * - r29: psr 555 * - r29: psr
556 *
557 * We used to clear some PSR bits here but that requires slow
558 * serialization. Fortuntely, that isn't really necessary.
559 * The rationale is as follows: we used to clear bits
560 * ~PSR_PRESERVED_BITS in PSR.L. Since
561 * PSR_PRESERVED_BITS==PSR.{UP,MFL,MFH,PK,DT,PP,SP,RT,IC}, we
562 * ended up clearing PSR.{BE,AC,I,DFL,DFH,DI,DB,SI,TB}.
563 * However,
564 *
565 * PSR.BE : already is turned off in __kernel_syscall_via_epc()
566 * PSR.AC : don't care (kernel normally turns PSR.AC on)
567 * PSR.I : already turned off by the time fsys_bubble_down gets
568 * invoked
569 * PSR.DFL: always 0 (kernel never turns it on)
570 * PSR.DFH: don't care --- kernel never touches f32-f127 on its own
571 * initiative
572 * PSR.DI : always 0 (kernel never turns it on)
573 * PSR.SI : always 0 (kernel never turns it on)
574 * PSR.DB : don't care --- kernel never enables kernel-level
575 * breakpoints
576 * PSR.TB : must be 0 already; if it wasn't zero on entry to
577 * __kernel_syscall_via_epc, the branch to fsys_bubble_down
578 * will trigger a taken branch; the taken-trap-handler then
579 * converts the syscall into a break-based system-call.
551 */ 580 */
552# define PSR_PRESERVED_BITS (IA64_PSR_UP | IA64_PSR_MFL | IA64_PSR_MFH | IA64_PSR_PK \
553 | IA64_PSR_DT | IA64_PSR_PP | IA64_PSR_SP | IA64_PSR_RT \
554 | IA64_PSR_IC)
555 /* 581 /*
556 * Reading psr.l gives us only bits 0-31, psr.it, and psr.mc. The rest we have 582 * Reading psr.l gives us only bits 0-31, psr.it, and psr.mc.
557 * to synthesize. 583 * The rest we have to synthesize.
558 */ 584 */
559# define PSR_ONE_BITS ((3 << IA64_PSR_CPL0_BIT) | (0x1 << IA64_PSR_RI_BIT) \ 585# define PSR_ONE_BITS ((3 << IA64_PSR_CPL0_BIT) \
586 | (0x1 << IA64_PSR_RI_BIT) \
560 | IA64_PSR_BN | IA64_PSR_I) 587 | IA64_PSR_BN | IA64_PSR_I)
561 588
562 invala 589 invala // M0|1
563 movl r8=PSR_ONE_BITS 590 movl r14=ia64_ret_from_syscall // X
564 591
565 mov r25=ar.unat // save ar.unat (5 cyc) 592 nop.m 0
566 movl r9=PSR_PRESERVED_BITS 593 movl r28=__kernel_syscall_via_break // X create cr.iip
594 ;;
567 595
568 mov ar.rsc=0 // set enforced lazy mode, pl 0, little-endian, loadrs=0 596 mov r2=r16 // A get task addr to addl-addressable register
569 movl r28=__kernel_syscall_via_break 597 adds r16=IA64_TASK_THREAD_ON_USTACK_OFFSET,r16 // A
598 mov r31=pr // I0 save pr (2 cyc)
570 ;; 599 ;;
571 mov r23=ar.bspstore // save ar.bspstore (12 cyc) 600 st1 [r16]=r0 // M2|3 clear current->thread.on_ustack flag
572 mov r31=pr // save pr (2 cyc) 601 addl r22=IA64_RBS_OFFSET,r2 // A compute base of RBS
573 mov r20=r1 // save caller's gp in r20 602 add r3=TI_FLAGS+IA64_TASK_SIZE,r2 // A
574 ;; 603 ;;
575 mov r2=r16 // copy current task addr to addl-addressable register 604 ld4 r3=[r3] // M0|1 r3 = current_thread_info()->flags
576 and r9=r9,r29 605 lfetch.fault.excl.nt1 [r22] // M0|1 prefetch register backing-store
577 mov r19=b6 // save b6 (2 cyc) 606 nop.i 0
578 ;; 607 ;;
579 mov psr.l=r9 // slam the door (17 cyc to srlz.i) 608 mov ar.rsc=0 // M2 set enforced lazy mode, pl 0, LE, loadrs=0
580 or r29=r8,r29 // construct cr.ipsr value to save 609 nop.m 0
581 addl r22=IA64_RBS_OFFSET,r2 // compute base of RBS 610 nop.i 0
582 ;; 611 ;;
583 // GAS reports a spurious RAW hazard on the read of ar.rnat because it thinks 612 mov r23=ar.bspstore // M2 (12 cyc) save ar.bspstore
584 // we may be reading ar.itc after writing to psr.l. Avoid that message with 613 mov.m r24=ar.rnat // M2 (5 cyc) read ar.rnat (dual-issues!)
585 // this directive: 614 nop.i 0
586 dv_serialize_data
587 mov.m r24=ar.rnat // read ar.rnat (5 cyc lat)
588 lfetch.fault.excl.nt1 [r22]
589 adds r16=IA64_TASK_THREAD_ON_USTACK_OFFSET,r2
590
591 // ensure previous insn group is issued before we stall for srlz.i:
592 ;; 615 ;;
593 srlz.i // ensure new psr.l has been established 616 mov ar.bspstore=r22 // M2 (6 cyc) switch to kernel RBS
594 ///////////////////////////////////////////////////////////////////////////// 617 movl r8=PSR_ONE_BITS // X
595 ////////// from this point on, execution is not interruptible anymore
596 /////////////////////////////////////////////////////////////////////////////
597 addl r1=IA64_STK_OFFSET-IA64_PT_REGS_SIZE,r2 // compute base of memory stack
598 cmp.ne pKStk,pUStk=r0,r0 // set pKStk <- 0, pUStk <- 1
599 ;; 618 ;;
600 st1 [r16]=r0 // clear current->thread.on_ustack flag 619 mov r25=ar.unat // M2 (5 cyc) save ar.unat
601 mov ar.bspstore=r22 // switch to kernel RBS 620 mov r19=b6 // I0 save b6 (2 cyc)
602 mov b6=r18 // copy syscall entry-point to b6 (7 cyc) 621 mov r20=r1 // A save caller's gp in r20
603 add r3=TI_FLAGS+IA64_TASK_SIZE,r2
604 ;; 622 ;;
605 ld4 r3=[r3] // r2 = current_thread_info()->flags 623 or r29=r8,r29 // A construct cr.ipsr value to save
606 mov r18=ar.bsp // save (kernel) ar.bsp (12 cyc) 624 mov b6=r18 // I0 copy syscall entry-point to b6 (7 cyc)
607 mov ar.rsc=0x3 // set eager mode, pl 0, little-endian, loadrs=0 625 addl r1=IA64_STK_OFFSET-IA64_PT_REGS_SIZE,r2 // A compute base of memory stack
608 br.call.sptk.many b7=ia64_syscall_setup 626
609 ;; 627 mov r18=ar.bsp // M2 save (kernel) ar.bsp (12 cyc)
610 ssm psr.i 628 cmp.ne pKStk,pUStk=r0,r0 // A set pKStk <- 0, pUStk <- 1
611 movl r2=ia64_ret_from_syscall 629 br.call.sptk.many b7=ia64_syscall_setup // B
612 ;; 630 ;;
613 mov rp=r2 // set the real return addr 631 mov ar.rsc=0x3 // M2 set eager mode, pl 0, LE, loadrs=0
614 and r3=_TIF_SYSCALL_TRACEAUDIT,r3 632 mov rp=r14 // I0 set the real return addr
633 and r3=_TIF_SYSCALL_TRACEAUDIT,r3 // A
615 ;; 634 ;;
616 cmp.eq p8,p0=r3,r0 635 ssm psr.i // M2 we're on kernel stacks now, reenable irqs
636 cmp.eq p8,p0=r3,r0 // A
637(p10) br.cond.spnt.many ia64_ret_from_syscall // B return if bad call-frame or r15 is a NaT
617 638
618(p10) br.cond.spnt.many ia64_ret_from_syscall // p10==true means out registers are more than 8 639 nop.m 0
619(p8) br.call.sptk.many b6=b6 // ignore this return addr 640(p8) br.call.sptk.many b6=b6 // B (ignore return address)
620 br.cond.sptk ia64_trace_syscall 641 br.cond.spnt ia64_trace_syscall // B
621END(fsys_bubble_down) 642END(fsys_bubble_down)
622 643
623 .rodata 644 .rodata
diff --git a/arch/ia64/kernel/gate.S b/arch/ia64/kernel/gate.S
index facf75acdc85..86948ce63e43 100644
--- a/arch/ia64/kernel/gate.S
+++ b/arch/ia64/kernel/gate.S
@@ -72,38 +72,40 @@ GLOBAL_ENTRY(__kernel_syscall_via_epc)
72 * bundle get executed. The remaining code must be safe even if 72 * bundle get executed. The remaining code must be safe even if
73 * they do not get executed. 73 * they do not get executed.
74 */ 74 */
75 adds r17=-1024,r15 75 adds r17=-1024,r15 // A
76 mov r10=0 // default to successful syscall execution 76 mov r10=0 // A default to successful syscall execution
77 epc 77 epc // B causes split-issue
78} 78}
79 ;; 79 ;;
80 rsm psr.be // note: on McKinley "rsm psr.be/srlz.d" is slightly faster than "rum psr.be" 80 rsm psr.be | psr.i // M2 (5 cyc to srlz.d)
81 LOAD_FSYSCALL_TABLE(r14) 81 LOAD_FSYSCALL_TABLE(r14) // X
82
83 mov r16=IA64_KR(CURRENT) // 12 cycle read latency
84 tnat.nz p10,p9=r15
85 mov r19=NR_syscalls-1
86 ;; 82 ;;
87 shladd r18=r17,3,r14 83 mov r16=IA64_KR(CURRENT) // M2 (12 cyc)
88 84 shladd r18=r17,3,r14 // A
89 srlz.d 85 mov r19=NR_syscalls-1 // A
90 cmp.ne p8,p0=r0,r0 // p8 <- FALSE 86 ;;
91 /* Note: if r17 is a NaT, p6 will be set to zero. */ 87 lfetch [r18] // M0|1
92 cmp.geu p6,p7=r19,r17 // (syscall > 0 && syscall < 1024+NR_syscalls)? 88 mov r29=psr // M2 (12 cyc)
93 ;; 89 // If r17 is a NaT, p6 will be zero
94(p6) ld8 r18=[r18] 90 cmp.geu p6,p7=r19,r17 // A (sysnr > 0 && sysnr < 1024+NR_syscalls)?
95 mov r21=ar.fpsr 91 ;;
96 add r14=-8,r14 // r14 <- addr of fsys_bubble_down entry 92 mov r21=ar.fpsr // M2 (12 cyc)
97 ;; 93 tnat.nz p10,p9=r15 // I0
98(p6) mov b7=r18 94 mov.i r26=ar.pfs // I0 (would stall anyhow due to srlz.d...)
99(p6) tbit.z p8,p0=r18,0 95 ;;
100(p8) br.dptk.many b7 96 srlz.d // M0 (forces split-issue) ensure PSR.BE==0
101 97(p6) ld8 r18=[r18] // M0|1
102(p6) rsm psr.i 98 nop.i 0
103 mov r27=ar.rsc 99 ;;
104 mov r26=ar.pfs 100 nop.m 0
101(p6) tbit.z.unc p8,p0=r18,0 // I0 (dual-issues with "mov b7=r18"!)
102 nop.i 0
105 ;; 103 ;;
106 mov r29=psr // read psr (12 cyc load latency) 104(p8) ssm psr.i
105(p6) mov b7=r18 // I0
106(p8) br.dptk.many b7 // B
107
108 mov r27=ar.rsc // M2 (12 cyc)
107/* 109/*
108 * brl.cond doesn't work as intended because the linker would convert this branch 110 * brl.cond doesn't work as intended because the linker would convert this branch
109 * into a branch to a PLT. Perhaps there will be a way to avoid this with some 111 * into a branch to a PLT. Perhaps there will be a way to avoid this with some
@@ -111,6 +113,8 @@ GLOBAL_ENTRY(__kernel_syscall_via_epc)
111 * instead. 113 * instead.
112 */ 114 */
113#ifdef CONFIG_ITANIUM 115#ifdef CONFIG_ITANIUM
116(p6) add r14=-8,r14 // r14 <- addr of fsys_bubble_down entry
117 ;;
114(p6) ld8 r14=[r14] // r14 <- fsys_bubble_down 118(p6) ld8 r14=[r14] // r14 <- fsys_bubble_down
115 ;; 119 ;;
116(p6) mov b7=r14 120(p6) mov b7=r14
@@ -118,7 +122,7 @@ GLOBAL_ENTRY(__kernel_syscall_via_epc)
118#else 122#else
119 BRL_COND_FSYS_BUBBLE_DOWN(p6) 123 BRL_COND_FSYS_BUBBLE_DOWN(p6)
120#endif 124#endif
121 125 ssm psr.i
122 mov r10=-1 126 mov r10=-1
123(p10) mov r8=EINVAL 127(p10) mov r8=EINVAL
124(p9) mov r8=ENOSYS 128(p9) mov r8=ENOSYS
diff --git a/arch/ia64/kernel/ia64_ksyms.c b/arch/ia64/kernel/ia64_ksyms.c
index 7bbf019c9867..01572814abe4 100644
--- a/arch/ia64/kernel/ia64_ksyms.c
+++ b/arch/ia64/kernel/ia64_ksyms.c
@@ -58,9 +58,6 @@ EXPORT_SYMBOL(__strlen_user);
58EXPORT_SYMBOL(__strncpy_from_user); 58EXPORT_SYMBOL(__strncpy_from_user);
59EXPORT_SYMBOL(__strnlen_user); 59EXPORT_SYMBOL(__strnlen_user);
60 60
61#include <asm/unistd.h>
62EXPORT_SYMBOL(__ia64_syscall);
63
64/* from arch/ia64/lib */ 61/* from arch/ia64/lib */
65extern void __divsi3(void); 62extern void __divsi3(void);
66extern void __udivsi3(void); 63extern void __udivsi3(void);
diff --git a/arch/ia64/kernel/iosapic.c b/arch/ia64/kernel/iosapic.c
index 88b014381df5..c170be095ccd 100644
--- a/arch/ia64/kernel/iosapic.c
+++ b/arch/ia64/kernel/iosapic.c
@@ -129,14 +129,13 @@ static struct iosapic {
129 char __iomem *addr; /* base address of IOSAPIC */ 129 char __iomem *addr; /* base address of IOSAPIC */
130 unsigned int gsi_base; /* first GSI assigned to this IOSAPIC */ 130 unsigned int gsi_base; /* first GSI assigned to this IOSAPIC */
131 unsigned short num_rte; /* number of RTE in this IOSAPIC */ 131 unsigned short num_rte; /* number of RTE in this IOSAPIC */
132 int rtes_inuse; /* # of RTEs in use on this IOSAPIC */
132#ifdef CONFIG_NUMA 133#ifdef CONFIG_NUMA
133 unsigned short node; /* numa node association via pxm */ 134 unsigned short node; /* numa node association via pxm */
134#endif 135#endif
135} iosapic_lists[NR_IOSAPICS]; 136} iosapic_lists[NR_IOSAPICS];
136 137
137static int num_iosapic; 138static unsigned char pcat_compat __devinitdata; /* 8259 compatibility flag */
138
139static unsigned char pcat_compat __initdata; /* 8259 compatibility flag */
140 139
141static int iosapic_kmalloc_ok; 140static int iosapic_kmalloc_ok;
142static LIST_HEAD(free_rte_list); 141static LIST_HEAD(free_rte_list);
@@ -149,7 +148,7 @@ find_iosapic (unsigned int gsi)
149{ 148{
150 int i; 149 int i;
151 150
152 for (i = 0; i < num_iosapic; i++) { 151 for (i = 0; i < NR_IOSAPICS; i++) {
153 if ((unsigned) (gsi - iosapic_lists[i].gsi_base) < iosapic_lists[i].num_rte) 152 if ((unsigned) (gsi - iosapic_lists[i].gsi_base) < iosapic_lists[i].num_rte)
154 return i; 153 return i;
155 } 154 }
@@ -598,6 +597,7 @@ register_intr (unsigned int gsi, int vector, unsigned char delivery,
598 rte->refcnt++; 597 rte->refcnt++;
599 list_add_tail(&rte->rte_list, &iosapic_intr_info[vector].rtes); 598 list_add_tail(&rte->rte_list, &iosapic_intr_info[vector].rtes);
600 iosapic_intr_info[vector].count++; 599 iosapic_intr_info[vector].count++;
600 iosapic_lists[index].rtes_inuse++;
601 } 601 }
602 else if (vector_is_shared(vector)) { 602 else if (vector_is_shared(vector)) {
603 struct iosapic_intr_info *info = &iosapic_intr_info[vector]; 603 struct iosapic_intr_info *info = &iosapic_intr_info[vector];
@@ -778,7 +778,7 @@ void
778iosapic_unregister_intr (unsigned int gsi) 778iosapic_unregister_intr (unsigned int gsi)
779{ 779{
780 unsigned long flags; 780 unsigned long flags;
781 int irq, vector; 781 int irq, vector, index;
782 irq_desc_t *idesc; 782 irq_desc_t *idesc;
783 u32 low32; 783 u32 low32;
784 unsigned long trigger, polarity; 784 unsigned long trigger, polarity;
@@ -819,6 +819,9 @@ iosapic_unregister_intr (unsigned int gsi)
819 list_del(&rte->rte_list); 819 list_del(&rte->rte_list);
820 iosapic_intr_info[vector].count--; 820 iosapic_intr_info[vector].count--;
821 iosapic_free_rte(rte); 821 iosapic_free_rte(rte);
822 index = find_iosapic(gsi);
823 iosapic_lists[index].rtes_inuse--;
824 WARN_ON(iosapic_lists[index].rtes_inuse < 0);
822 825
823 trigger = iosapic_intr_info[vector].trigger; 826 trigger = iosapic_intr_info[vector].trigger;
824 polarity = iosapic_intr_info[vector].polarity; 827 polarity = iosapic_intr_info[vector].polarity;
@@ -952,30 +955,86 @@ iosapic_system_init (int system_pcat_compat)
952 } 955 }
953} 956}
954 957
955void __init 958static inline int
959iosapic_alloc (void)
960{
961 int index;
962
963 for (index = 0; index < NR_IOSAPICS; index++)
964 if (!iosapic_lists[index].addr)
965 return index;
966
967 printk(KERN_WARNING "%s: failed to allocate iosapic\n", __FUNCTION__);
968 return -1;
969}
970
971static inline void
972iosapic_free (int index)
973{
974 memset(&iosapic_lists[index], 0, sizeof(iosapic_lists[0]));
975}
976
977static inline int
978iosapic_check_gsi_range (unsigned int gsi_base, unsigned int ver)
979{
980 int index;
981 unsigned int gsi_end, base, end;
982
983 /* check gsi range */
984 gsi_end = gsi_base + ((ver >> 16) & 0xff);
985 for (index = 0; index < NR_IOSAPICS; index++) {
986 if (!iosapic_lists[index].addr)
987 continue;
988
989 base = iosapic_lists[index].gsi_base;
990 end = base + iosapic_lists[index].num_rte - 1;
991
992 if (gsi_base < base && gsi_end < base)
993 continue;/* OK */
994
995 if (gsi_base > end && gsi_end > end)
996 continue; /* OK */
997
998 return -EBUSY;
999 }
1000 return 0;
1001}
1002
1003int __devinit
956iosapic_init (unsigned long phys_addr, unsigned int gsi_base) 1004iosapic_init (unsigned long phys_addr, unsigned int gsi_base)
957{ 1005{
958 int num_rte; 1006 int num_rte, err, index;
959 unsigned int isa_irq, ver; 1007 unsigned int isa_irq, ver;
960 char __iomem *addr; 1008 char __iomem *addr;
1009 unsigned long flags;
1010
1011 spin_lock_irqsave(&iosapic_lock, flags);
1012 {
1013 addr = ioremap(phys_addr, 0);
1014 ver = iosapic_version(addr);
961 1015
962 addr = ioremap(phys_addr, 0); 1016 if ((err = iosapic_check_gsi_range(gsi_base, ver))) {
963 ver = iosapic_version(addr); 1017 iounmap(addr);
1018 spin_unlock_irqrestore(&iosapic_lock, flags);
1019 return err;
1020 }
964 1021
965 /* 1022 /*
966 * The MAX_REDIR register holds the highest input pin 1023 * The MAX_REDIR register holds the highest input pin
967 * number (starting from 0). 1024 * number (starting from 0).
968 * We add 1 so that we can use it for number of pins (= RTEs) 1025 * We add 1 so that we can use it for number of pins (= RTEs)
969 */ 1026 */
970 num_rte = ((ver >> 16) & 0xff) + 1; 1027 num_rte = ((ver >> 16) & 0xff) + 1;
971 1028
972 iosapic_lists[num_iosapic].addr = addr; 1029 index = iosapic_alloc();
973 iosapic_lists[num_iosapic].gsi_base = gsi_base; 1030 iosapic_lists[index].addr = addr;
974 iosapic_lists[num_iosapic].num_rte = num_rte; 1031 iosapic_lists[index].gsi_base = gsi_base;
1032 iosapic_lists[index].num_rte = num_rte;
975#ifdef CONFIG_NUMA 1033#ifdef CONFIG_NUMA
976 iosapic_lists[num_iosapic].node = MAX_NUMNODES; 1034 iosapic_lists[index].node = MAX_NUMNODES;
977#endif 1035#endif
978 num_iosapic++; 1036 }
1037 spin_unlock_irqrestore(&iosapic_lock, flags);
979 1038
980 if ((gsi_base == 0) && pcat_compat) { 1039 if ((gsi_base == 0) && pcat_compat) {
981 /* 1040 /*
@@ -986,10 +1045,43 @@ iosapic_init (unsigned long phys_addr, unsigned int gsi_base)
986 for (isa_irq = 0; isa_irq < 16; ++isa_irq) 1045 for (isa_irq = 0; isa_irq < 16; ++isa_irq)
987 iosapic_override_isa_irq(isa_irq, isa_irq, IOSAPIC_POL_HIGH, IOSAPIC_EDGE); 1046 iosapic_override_isa_irq(isa_irq, isa_irq, IOSAPIC_POL_HIGH, IOSAPIC_EDGE);
988 } 1047 }
1048 return 0;
1049}
1050
1051#ifdef CONFIG_HOTPLUG
1052int
1053iosapic_remove (unsigned int gsi_base)
1054{
1055 int index, err = 0;
1056 unsigned long flags;
1057
1058 spin_lock_irqsave(&iosapic_lock, flags);
1059 {
1060 index = find_iosapic(gsi_base);
1061 if (index < 0) {
1062 printk(KERN_WARNING "%s: No IOSAPIC for GSI base %u\n",
1063 __FUNCTION__, gsi_base);
1064 goto out;
1065 }
1066
1067 if (iosapic_lists[index].rtes_inuse) {
1068 err = -EBUSY;
1069 printk(KERN_WARNING "%s: IOSAPIC for GSI base %u is busy\n",
1070 __FUNCTION__, gsi_base);
1071 goto out;
1072 }
1073
1074 iounmap(iosapic_lists[index].addr);
1075 iosapic_free(index);
1076 }
1077 out:
1078 spin_unlock_irqrestore(&iosapic_lock, flags);
1079 return err;
989} 1080}
1081#endif /* CONFIG_HOTPLUG */
990 1082
991#ifdef CONFIG_NUMA 1083#ifdef CONFIG_NUMA
992void __init 1084void __devinit
993map_iosapic_to_node(unsigned int gsi_base, int node) 1085map_iosapic_to_node(unsigned int gsi_base, int node)
994{ 1086{
995 int index; 1087 int index;
diff --git a/arch/ia64/kernel/ivt.S b/arch/ia64/kernel/ivt.S
index 2bc085a73e30..3bb3a13c4047 100644
--- a/arch/ia64/kernel/ivt.S
+++ b/arch/ia64/kernel/ivt.S
@@ -1,7 +1,7 @@
1/* 1/*
2 * arch/ia64/kernel/ivt.S 2 * arch/ia64/kernel/ivt.S
3 * 3 *
4 * Copyright (C) 1998-2001, 2003 Hewlett-Packard Co 4 * Copyright (C) 1998-2001, 2003, 2005 Hewlett-Packard Co
5 * Stephane Eranian <eranian@hpl.hp.com> 5 * Stephane Eranian <eranian@hpl.hp.com>
6 * David Mosberger <davidm@hpl.hp.com> 6 * David Mosberger <davidm@hpl.hp.com>
7 * Copyright (C) 2000, 2002-2003 Intel Co 7 * Copyright (C) 2000, 2002-2003 Intel Co
@@ -692,82 +692,118 @@ ENTRY(break_fault)
692 * to prevent leaking bits from kernel to user level. 692 * to prevent leaking bits from kernel to user level.
693 */ 693 */
694 DBG_FAULT(11) 694 DBG_FAULT(11)
695 mov r16=IA64_KR(CURRENT) // r16 = current task; 12 cycle read lat. 695 mov.m r16=IA64_KR(CURRENT) // M2 r16 <- current task (12 cyc)
696 mov r17=cr.iim 696 mov r29=cr.ipsr // M2 (12 cyc)
697 mov r18=__IA64_BREAK_SYSCALL 697 mov r31=pr // I0 (2 cyc)
698 mov r21=ar.fpsr 698
699 mov r29=cr.ipsr 699 mov r17=cr.iim // M2 (2 cyc)
700 mov r19=b6 700 mov.m r27=ar.rsc // M2 (12 cyc)
701 mov r25=ar.unat 701 mov r18=__IA64_BREAK_SYSCALL // A
702 mov r27=ar.rsc 702
703 mov r26=ar.pfs 703 mov.m ar.rsc=0 // M2
704 mov r28=cr.iip 704 mov.m r21=ar.fpsr // M2 (12 cyc)
705 mov r31=pr // prepare to save predicates 705 mov r19=b6 // I0 (2 cyc)
706 mov r20=r1 706 ;;
707 ;; 707 mov.m r23=ar.bspstore // M2 (12 cyc)
708 mov.m r24=ar.rnat // M2 (5 cyc)
709 mov.i r26=ar.pfs // I0 (2 cyc)
710
711 invala // M0|1
712 nop.m 0 // M
713 mov r20=r1 // A save r1
714
715 nop.m 0
716 movl r30=sys_call_table // X
717
718 mov r28=cr.iip // M2 (2 cyc)
719 cmp.eq p0,p7=r18,r17 // I0 is this a system call?
720(p7) br.cond.spnt non_syscall // B no ->
721 //
722 // From this point on, we are definitely on the syscall-path
723 // and we can use (non-banked) scratch registers.
724 //
725///////////////////////////////////////////////////////////////////////
726 mov r1=r16 // A move task-pointer to "addl"-addressable reg
727 mov r2=r16 // A setup r2 for ia64_syscall_setup
728 add r9=TI_FLAGS+IA64_TASK_SIZE,r16 // A r9 = &current_thread_info()->flags
729
708 adds r16=IA64_TASK_THREAD_ON_USTACK_OFFSET,r16 730 adds r16=IA64_TASK_THREAD_ON_USTACK_OFFSET,r16
709 cmp.eq p0,p7=r18,r17 // is this a system call? (p7 <- false, if so) 731 adds r15=-1024,r15 // A subtract 1024 from syscall number
710(p7) br.cond.spnt non_syscall 732 mov r3=NR_syscalls - 1
711 ;; 733 ;;
712 ld1 r17=[r16] // load current->thread.on_ustack flag 734 ld1.bias r17=[r16] // M0|1 r17 = current->thread.on_ustack flag
713 st1 [r16]=r0 // clear current->thread.on_ustack flag 735 ld4 r9=[r9] // M0|1 r9 = current_thread_info()->flags
714 add r1=-IA64_TASK_THREAD_ON_USTACK_OFFSET,r16 // set r1 for MINSTATE_START_SAVE_MIN_VIRT 736 extr.u r8=r29,41,2 // I0 extract ei field from cr.ipsr
737
738 shladd r30=r15,3,r30 // A r30 = sys_call_table + 8*(syscall-1024)
739 addl r22=IA64_RBS_OFFSET,r1 // A compute base of RBS
740 cmp.leu p6,p7=r15,r3 // A syscall number in range?
715 ;; 741 ;;
716 invala
717 742
718 /* adjust return address so we skip over the break instruction: */ 743 lfetch.fault.excl.nt1 [r22] // M0|1 prefetch RBS
744(p6) ld8 r30=[r30] // M0|1 load address of syscall entry point
745 tnat.nz.or p7,p0=r15 // I0 is syscall nr a NaT?
719 746
720 extr.u r8=r29,41,2 // extract ei field from cr.ipsr 747 mov.m ar.bspstore=r22 // M2 switch to kernel RBS
721 ;; 748 cmp.eq p8,p9=2,r8 // A isr.ei==2?
722 cmp.eq p6,p7=2,r8 // isr.ei==2?
723 mov r2=r1 // setup r2 for ia64_syscall_setup
724 ;;
725(p6) mov r8=0 // clear ei to 0
726(p6) adds r28=16,r28 // switch cr.iip to next bundle cr.ipsr.ei wrapped
727(p7) adds r8=1,r8 // increment ei to next slot
728 ;;
729 cmp.eq pKStk,pUStk=r0,r17 // are we in kernel mode already?
730 dep r29=r8,r29,41,2 // insert new ei into cr.ipsr
731 ;; 749 ;;
732 750
733 // switch from user to kernel RBS: 751(p8) mov r8=0 // A clear ei to 0
734 MINSTATE_START_SAVE_MIN_VIRT 752(p7) movl r30=sys_ni_syscall // X
735 br.call.sptk.many b7=ia64_syscall_setup
736 ;;
737 MINSTATE_END_SAVE_MIN_VIRT // switch to bank 1
738 ssm psr.ic | PSR_DEFAULT_BITS
739 ;;
740 srlz.i // guarantee that interruption collection is on
741 mov r3=NR_syscalls - 1
742 ;;
743(p15) ssm psr.i // restore psr.i
744 // p10==true means out registers are more than 8 or r15's Nat is true
745(p10) br.cond.spnt.many ia64_ret_from_syscall
746 ;;
747 movl r16=sys_call_table
748 753
749 adds r15=-1024,r15 // r15 contains the syscall number---subtract 1024 754(p8) adds r28=16,r28 // A switch cr.iip to next bundle
750 movl r2=ia64_ret_from_syscall 755(p9) adds r8=1,r8 // A increment ei to next slot
751 ;; 756 nop.i 0
752 shladd r20=r15,3,r16 // r20 = sys_call_table + 8*(syscall-1024)
753 cmp.leu p6,p7=r15,r3 // (syscall > 0 && syscall < 1024 + NR_syscalls) ?
754 mov rp=r2 // set the real return addr
755 ;; 757 ;;
756(p6) ld8 r20=[r20] // load address of syscall entry point
757(p7) movl r20=sys_ni_syscall
758 758
759 add r2=TI_FLAGS+IA64_TASK_SIZE,r13 759 mov.m r25=ar.unat // M2 (5 cyc)
760 ;; 760 dep r29=r8,r29,41,2 // I0 insert new ei into cr.ipsr
761 ld4 r2=[r2] // r2 = current_thread_info()->flags 761 adds r15=1024,r15 // A restore original syscall number
762 ;; 762 //
763 and r2=_TIF_SYSCALL_TRACEAUDIT,r2 // mask trace or audit 763 // If any of the above loads miss in L1D, we'll stall here until
764 // the data arrives.
765 //
766///////////////////////////////////////////////////////////////////////
767 st1 [r16]=r0 // M2|3 clear current->thread.on_ustack flag
768 mov b6=r30 // I0 setup syscall handler branch reg early
769 cmp.eq pKStk,pUStk=r0,r17 // A were we on kernel stacks already?
770
771 and r9=_TIF_SYSCALL_TRACEAUDIT,r9 // A mask trace or audit
772 mov r18=ar.bsp // M2 (12 cyc)
773(pKStk) br.cond.spnt .break_fixup // B we're already in kernel-mode -- fix up RBS
774 ;;
775.back_from_break_fixup:
776(pUStk) addl r1=IA64_STK_OFFSET-IA64_PT_REGS_SIZE,r1 // A compute base of memory stack
777 cmp.eq p14,p0=r9,r0 // A are syscalls being traced/audited?
778 br.call.sptk.many b7=ia64_syscall_setup // B
7791:
780 mov ar.rsc=0x3 // M2 set eager mode, pl 0, LE, loadrs=0
781 nop 0
782 bsw.1 // B (6 cyc) regs are saved, switch to bank 1
764 ;; 783 ;;
765 cmp.eq p8,p0=r2,r0 784
766 mov b6=r20 785 ssm psr.ic | PSR_DEFAULT_BITS // M2 now it's safe to re-enable intr.-collection
786 movl r3=ia64_ret_from_syscall // X
767 ;; 787 ;;
768(p8) br.call.sptk.many b6=b6 // ignore this return addr 788
769 br.cond.sptk ia64_trace_syscall 789 srlz.i // M0 ensure interruption collection is on
790 mov rp=r3 // I0 set the real return addr
791(p10) br.cond.spnt.many ia64_ret_from_syscall // B return if bad call-frame or r15 is a NaT
792
793(p15) ssm psr.i // M2 restore psr.i
794(p14) br.call.sptk.many b6=b6 // B invoke syscall-handker (ignore return addr)
795 br.cond.spnt.many ia64_trace_syscall // B do syscall-tracing thingamagic
770 // NOT REACHED 796 // NOT REACHED
797///////////////////////////////////////////////////////////////////////
798 // On entry, we optimistically assumed that we're coming from user-space.
799 // For the rare cases where a system-call is done from within the kernel,
800 // we fix things up at this point:
801.break_fixup:
802 add r1=-IA64_PT_REGS_SIZE,sp // A allocate space for pt_regs structure
803 mov ar.rnat=r24 // M2 restore kernel's AR.RNAT
804 ;;
805 mov ar.bspstore=r23 // M2 restore kernel's AR.BSPSTORE
806 br.cond.sptk .back_from_break_fixup
771END(break_fault) 807END(break_fault)
772 808
773 .org ia64_ivt+0x3000 809 .org ia64_ivt+0x3000
@@ -842,8 +878,6 @@ END(interrupt)
842 * - r31: saved pr 878 * - r31: saved pr
843 * - b0: original contents (to be saved) 879 * - b0: original contents (to be saved)
844 * On exit: 880 * On exit:
845 * - executing on bank 1 registers
846 * - psr.ic enabled, interrupts restored
847 * - p10: TRUE if syscall is invoked with more than 8 out 881 * - p10: TRUE if syscall is invoked with more than 8 out
848 * registers or r15's Nat is true 882 * registers or r15's Nat is true
849 * - r1: kernel's gp 883 * - r1: kernel's gp
@@ -851,8 +885,11 @@ END(interrupt)
851 * - r8: -EINVAL if p10 is true 885 * - r8: -EINVAL if p10 is true
852 * - r12: points to kernel stack 886 * - r12: points to kernel stack
853 * - r13: points to current task 887 * - r13: points to current task
888 * - r14: preserved (same as on entry)
889 * - p13: preserved
854 * - p15: TRUE if interrupts need to be re-enabled 890 * - p15: TRUE if interrupts need to be re-enabled
855 * - ar.fpsr: set to kernel settings 891 * - ar.fpsr: set to kernel settings
892 * - b6: preserved (same as on entry)
856 */ 893 */
857GLOBAL_ENTRY(ia64_syscall_setup) 894GLOBAL_ENTRY(ia64_syscall_setup)
858#if PT(B6) != 0 895#if PT(B6) != 0
@@ -920,10 +957,10 @@ GLOBAL_ENTRY(ia64_syscall_setup)
920(p13) mov in5=-1 957(p13) mov in5=-1
921 ;; 958 ;;
922 st8 [r16]=r21,PT(R8)-PT(AR_FPSR) // save ar.fpsr 959 st8 [r16]=r21,PT(R8)-PT(AR_FPSR) // save ar.fpsr
923 tnat.nz p14,p0=in6 960 tnat.nz p13,p0=in6
924 cmp.lt p10,p9=r11,r8 // frame size can't be more than local+8 961 cmp.lt p10,p9=r11,r8 // frame size can't be more than local+8
925 ;; 962 ;;
926 stf8 [r16]=f1 // ensure pt_regs.r8 != 0 (see handle_syscall_error) 963 mov r8=1
927(p9) tnat.nz p10,p0=r15 964(p9) tnat.nz p10,p0=r15
928 adds r12=-16,r1 // switch to kernel memory stack (with 16 bytes of scratch) 965 adds r12=-16,r1 // switch to kernel memory stack (with 16 bytes of scratch)
929 966
@@ -934,9 +971,9 @@ GLOBAL_ENTRY(ia64_syscall_setup)
934 mov r13=r2 // establish `current' 971 mov r13=r2 // establish `current'
935 movl r1=__gp // establish kernel global pointer 972 movl r1=__gp // establish kernel global pointer
936 ;; 973 ;;
937(p14) mov in6=-1 974 st8 [r16]=r8 // ensure pt_regs.r8 != 0 (see handle_syscall_error)
975(p13) mov in6=-1
938(p8) mov in7=-1 976(p8) mov in7=-1
939 nop.i 0
940 977
941 cmp.eq pSys,pNonSys=r0,r0 // set pSys=1, pNonSys=0 978 cmp.eq pSys,pNonSys=r0,r0 // set pSys=1, pNonSys=0
942 movl r17=FPSR_DEFAULT 979 movl r17=FPSR_DEFAULT
@@ -1007,6 +1044,8 @@ END(dispatch_illegal_op_fault)
1007 FAULT(17) 1044 FAULT(17)
1008 1045
1009ENTRY(non_syscall) 1046ENTRY(non_syscall)
1047 mov ar.rsc=r27 // restore ar.rsc before SAVE_MIN_WITH_COVER
1048 ;;
1010 SAVE_MIN_WITH_COVER 1049 SAVE_MIN_WITH_COVER
1011 1050
1012 // There is no particular reason for this code to be here, other than that 1051 // There is no particular reason for this code to be here, other than that
@@ -1204,6 +1243,25 @@ END(disabled_fp_reg)
1204// 0x5600 Entry 26 (size 16 bundles) Nat Consumption (11,23,37,50) 1243// 0x5600 Entry 26 (size 16 bundles) Nat Consumption (11,23,37,50)
1205ENTRY(nat_consumption) 1244ENTRY(nat_consumption)
1206 DBG_FAULT(26) 1245 DBG_FAULT(26)
1246
1247 mov r16=cr.ipsr
1248 mov r17=cr.isr
1249 mov r31=pr // save PR
1250 ;;
1251 and r18=0xf,r17 // r18 = cr.ipsr.code{3:0}
1252 tbit.z p6,p0=r17,IA64_ISR_NA_BIT
1253 ;;
1254 cmp.ne.or p6,p0=IA64_ISR_CODE_LFETCH,r18
1255 dep r16=-1,r16,IA64_PSR_ED_BIT,1
1256(p6) br.cond.spnt 1f // branch if (cr.ispr.na == 0 || cr.ipsr.code{3:0} != LFETCH)
1257 ;;
1258 mov cr.ipsr=r16 // set cr.ipsr.na
1259 mov pr=r31,-1
1260 ;;
1261 rfi
1262
12631: mov pr=r31,-1
1264 ;;
1207 FAULT(26) 1265 FAULT(26)
1208END(nat_consumption) 1266END(nat_consumption)
1209 1267
diff --git a/arch/ia64/kernel/kprobes.c b/arch/ia64/kernel/kprobes.c
index 5978823d5c63..3aa3167edbec 100644
--- a/arch/ia64/kernel/kprobes.c
+++ b/arch/ia64/kernel/kprobes.c
@@ -34,6 +34,7 @@
34 34
35#include <asm/pgtable.h> 35#include <asm/pgtable.h>
36#include <asm/kdebug.h> 36#include <asm/kdebug.h>
37#include <asm/sections.h>
37 38
38extern void jprobe_inst_return(void); 39extern void jprobe_inst_return(void);
39 40
@@ -263,13 +264,33 @@ static inline void get_kprobe_inst(bundle_t *bundle, uint slot,
263 } 264 }
264} 265}
265 266
267/* Returns non-zero if the addr is in the Interrupt Vector Table */
268static inline int in_ivt_functions(unsigned long addr)
269{
270 return (addr >= (unsigned long)__start_ivt_text
271 && addr < (unsigned long)__end_ivt_text);
272}
273
266static int valid_kprobe_addr(int template, int slot, unsigned long addr) 274static int valid_kprobe_addr(int template, int slot, unsigned long addr)
267{ 275{
268 if ((slot > 2) || ((bundle_encoding[template][1] == L) && slot > 1)) { 276 if ((slot > 2) || ((bundle_encoding[template][1] == L) && slot > 1)) {
269 printk(KERN_WARNING "Attempting to insert unaligned kprobe at 0x%lx\n", 277 printk(KERN_WARNING "Attempting to insert unaligned kprobe "
270 addr); 278 "at 0x%lx\n", addr);
271 return -EINVAL; 279 return -EINVAL;
272 } 280 }
281
282 if (in_ivt_functions(addr)) {
283 printk(KERN_WARNING "Kprobes can't be inserted inside "
284 "IVT functions at 0x%lx\n", addr);
285 return -EINVAL;
286 }
287
288 if (slot == 1 && bundle_encoding[template][1] != L) {
289 printk(KERN_WARNING "Inserting kprobes on slot #1 "
290 "is not supported\n");
291 return -EINVAL;
292 }
293
273 return 0; 294 return 0;
274} 295}
275 296
@@ -290,6 +311,94 @@ static inline void set_current_kprobe(struct kprobe *p)
290 current_kprobe = p; 311 current_kprobe = p;
291} 312}
292 313
314static void kretprobe_trampoline(void)
315{
316}
317
318/*
319 * At this point the target function has been tricked into
320 * returning into our trampoline. Lookup the associated instance
321 * and then:
322 * - call the handler function
323 * - cleanup by marking the instance as unused
324 * - long jump back to the original return address
325 */
326int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
327{
328 struct kretprobe_instance *ri = NULL;
329 struct hlist_head *head;
330 struct hlist_node *node, *tmp;
331 unsigned long orig_ret_address = 0;
332 unsigned long trampoline_address =
333 ((struct fnptr *)kretprobe_trampoline)->ip;
334
335 head = kretprobe_inst_table_head(current);
336
337 /*
338 * It is possible to have multiple instances associated with a given
339 * task either because an multiple functions in the call path
340 * have a return probe installed on them, and/or more then one return
341 * return probe was registered for a target function.
342 *
343 * We can handle this because:
344 * - instances are always inserted at the head of the list
345 * - when multiple return probes are registered for the same
346 * function, the first instance's ret_addr will point to the
347 * real return address, and all the rest will point to
348 * kretprobe_trampoline
349 */
350 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
351 if (ri->task != current)
352 /* another task is sharing our hash bucket */
353 continue;
354
355 if (ri->rp && ri->rp->handler)
356 ri->rp->handler(ri, regs);
357
358 orig_ret_address = (unsigned long)ri->ret_addr;
359 recycle_rp_inst(ri);
360
361 if (orig_ret_address != trampoline_address)
362 /*
363 * This is the real return address. Any other
364 * instances associated with this task are for
365 * other calls deeper on the call stack
366 */
367 break;
368 }
369
370 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
371 regs->cr_iip = orig_ret_address;
372
373 unlock_kprobes();
374 preempt_enable_no_resched();
375
376 /*
377 * By returning a non-zero value, we are telling
378 * kprobe_handler() that we have handled unlocking
379 * and re-enabling preemption.
380 */
381 return 1;
382}
383
384void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs)
385{
386 struct kretprobe_instance *ri;
387
388 if ((ri = get_free_rp_inst(rp)) != NULL) {
389 ri->rp = rp;
390 ri->task = current;
391 ri->ret_addr = (kprobe_opcode_t *)regs->b0;
392
393 /* Replace the return addr with trampoline addr */
394 regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip;
395
396 add_rp_inst(ri);
397 } else {
398 rp->nmissed++;
399 }
400}
401
293int arch_prepare_kprobe(struct kprobe *p) 402int arch_prepare_kprobe(struct kprobe *p)
294{ 403{
295 unsigned long addr = (unsigned long) p->addr; 404 unsigned long addr = (unsigned long) p->addr;
@@ -492,8 +601,8 @@ static int pre_kprobes_handler(struct die_args *args)
492 if (p->pre_handler && p->pre_handler(p, regs)) 601 if (p->pre_handler && p->pre_handler(p, regs))
493 /* 602 /*
494 * Our pre-handler is specifically requesting that we just 603 * Our pre-handler is specifically requesting that we just
495 * do a return. This is handling the case where the 604 * do a return. This is used for both the jprobe pre-handler
496 * pre-handler is really our special jprobe pre-handler. 605 * and the kretprobe trampoline
497 */ 606 */
498 return 1; 607 return 1;
499 608
@@ -599,3 +708,14 @@ int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
599 *regs = jprobe_saved_regs; 708 *regs = jprobe_saved_regs;
600 return 1; 709 return 1;
601} 710}
711
712static struct kprobe trampoline_p = {
713 .pre_handler = trampoline_probe_handler
714};
715
716int __init arch_init(void)
717{
718 trampoline_p.addr =
719 (kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip;
720 return register_kprobe(&trampoline_p);
721}
diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index ebb71f3d6d19..6e35bff05d59 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -27,6 +27,7 @@
27#include <linux/efi.h> 27#include <linux/efi.h>
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/kprobes.h>
30 31
31#include <asm/cpu.h> 32#include <asm/cpu.h>
32#include <asm/delay.h> 33#include <asm/delay.h>
@@ -707,6 +708,13 @@ kernel_thread_helper (int (*fn)(void *), void *arg)
707void 708void
708flush_thread (void) 709flush_thread (void)
709{ 710{
711 /*
712 * Remove function-return probe instances associated with this task
713 * and put them back on the free list. Do not insert an exit probe for
714 * this function, it will be disabled by kprobe_flush_task if you do.
715 */
716 kprobe_flush_task(current);
717
710 /* drop floating-point and debug-register state if it exists: */ 718 /* drop floating-point and debug-register state if it exists: */
711 current->thread.flags &= ~(IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID); 719 current->thread.flags &= ~(IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID);
712 ia64_drop_fpu(current); 720 ia64_drop_fpu(current);
@@ -721,6 +729,14 @@ flush_thread (void)
721void 729void
722exit_thread (void) 730exit_thread (void)
723{ 731{
732
733 /*
734 * Remove function-return probe instances associated with this task
735 * and put them back on the free list. Do not insert an exit probe for
736 * this function, it will be disabled by kprobe_flush_task if you do.
737 */
738 kprobe_flush_task(current);
739
724 ia64_drop_fpu(current); 740 ia64_drop_fpu(current);
725#ifdef CONFIG_PERFMON 741#ifdef CONFIG_PERFMON
726 /* if needed, stop monitoring and flush state to perfmon context */ 742 /* if needed, stop monitoring and flush state to perfmon context */
diff --git a/arch/ia64/kernel/ptrace.c b/arch/ia64/kernel/ptrace.c
index 6d57aebad485..bbb8bc7c0552 100644
--- a/arch/ia64/kernel/ptrace.c
+++ b/arch/ia64/kernel/ptrace.c
@@ -725,12 +725,32 @@ convert_to_non_syscall (struct task_struct *child, struct pt_regs *pt,
725 break; 725 break;
726 } 726 }
727 727
728 /*
729 * Note: at the time of this call, the target task is blocked
730 * in notify_resume_user() and by clearling PRED_LEAVE_SYSCALL
731 * (aka, "pLvSys") we redirect execution from
732 * .work_pending_syscall_end to .work_processed_kernel.
733 */
728 unw_get_pr(&prev_info, &pr); 734 unw_get_pr(&prev_info, &pr);
729 pr &= ~(1UL << PRED_SYSCALL); 735 pr &= ~((1UL << PRED_SYSCALL) | (1UL << PRED_LEAVE_SYSCALL));
730 pr |= (1UL << PRED_NON_SYSCALL); 736 pr |= (1UL << PRED_NON_SYSCALL);
731 unw_set_pr(&prev_info, pr); 737 unw_set_pr(&prev_info, pr);
732 738
733 pt->cr_ifs = (1UL << 63) | cfm; 739 pt->cr_ifs = (1UL << 63) | cfm;
740 /*
741 * Clear the memory that is NOT written on syscall-entry to
742 * ensure we do not leak kernel-state to user when execution
743 * resumes.
744 */
745 pt->r2 = 0;
746 pt->r3 = 0;
747 pt->r14 = 0;
748 memset(&pt->r16, 0, 16*8); /* clear r16-r31 */
749 memset(&pt->f6, 0, 6*16); /* clear f6-f11 */
750 pt->b7 = 0;
751 pt->ar_ccv = 0;
752 pt->ar_csd = 0;
753 pt->ar_ssd = 0;
734} 754}
735 755
736static int 756static int
diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c
index d14692e0920a..2693e1522d7c 100644
--- a/arch/ia64/kernel/setup.c
+++ b/arch/ia64/kernel/setup.c
@@ -72,6 +72,8 @@ DEFINE_PER_CPU(unsigned long, ia64_phys_stacked_size_p8);
72unsigned long ia64_cycles_per_usec; 72unsigned long ia64_cycles_per_usec;
73struct ia64_boot_param *ia64_boot_param; 73struct ia64_boot_param *ia64_boot_param;
74struct screen_info screen_info; 74struct screen_info screen_info;
75unsigned long vga_console_iobase;
76unsigned long vga_console_membase;
75 77
76unsigned long ia64_max_cacheline_size; 78unsigned long ia64_max_cacheline_size;
77unsigned long ia64_iobase; /* virtual address for I/O accesses */ 79unsigned long ia64_iobase; /* virtual address for I/O accesses */
@@ -273,23 +275,25 @@ io_port_init (void)
273static inline int __init 275static inline int __init
274early_console_setup (char *cmdline) 276early_console_setup (char *cmdline)
275{ 277{
278 int earlycons = 0;
279
276#ifdef CONFIG_SERIAL_SGI_L1_CONSOLE 280#ifdef CONFIG_SERIAL_SGI_L1_CONSOLE
277 { 281 {
278 extern int sn_serial_console_early_setup(void); 282 extern int sn_serial_console_early_setup(void);
279 if (!sn_serial_console_early_setup()) 283 if (!sn_serial_console_early_setup())
280 return 0; 284 earlycons++;
281 } 285 }
282#endif 286#endif
283#ifdef CONFIG_EFI_PCDP 287#ifdef CONFIG_EFI_PCDP
284 if (!efi_setup_pcdp_console(cmdline)) 288 if (!efi_setup_pcdp_console(cmdline))
285 return 0; 289 earlycons++;
286#endif 290#endif
287#ifdef CONFIG_SERIAL_8250_CONSOLE 291#ifdef CONFIG_SERIAL_8250_CONSOLE
288 if (!early_serial_console_init(cmdline)) 292 if (!early_serial_console_init(cmdline))
289 return 0; 293 earlycons++;
290#endif 294#endif
291 295
292 return -1; 296 return (earlycons) ? 0 : -1;
293} 297}
294 298
295static inline void 299static inline void
diff --git a/arch/ia64/kernel/smp.c b/arch/ia64/kernel/smp.c
index b49d4ddaab93..0166a9847095 100644
--- a/arch/ia64/kernel/smp.c
+++ b/arch/ia64/kernel/smp.c
@@ -231,13 +231,16 @@ smp_flush_tlb_all (void)
231void 231void
232smp_flush_tlb_mm (struct mm_struct *mm) 232smp_flush_tlb_mm (struct mm_struct *mm)
233{ 233{
234 preempt_disable();
234 /* this happens for the common case of a single-threaded fork(): */ 235 /* this happens for the common case of a single-threaded fork(): */
235 if (likely(mm == current->active_mm && atomic_read(&mm->mm_users) == 1)) 236 if (likely(mm == current->active_mm && atomic_read(&mm->mm_users) == 1))
236 { 237 {
237 local_finish_flush_tlb_mm(mm); 238 local_finish_flush_tlb_mm(mm);
239 preempt_enable();
238 return; 240 return;
239 } 241 }
240 242
243 preempt_enable();
241 /* 244 /*
242 * We could optimize this further by using mm->cpu_vm_mask to track which CPUs 245 * We could optimize this further by using mm->cpu_vm_mask to track which CPUs
243 * have been running in the address space. It's not clear that this is worth the 246 * have been running in the address space. It's not clear that this is worth the
diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
index b9f0db4c1b04..a676e79e0681 100644
--- a/arch/ia64/kernel/vmlinux.lds.S
+++ b/arch/ia64/kernel/vmlinux.lds.S
@@ -8,6 +8,11 @@
8#define LOAD_OFFSET (KERNEL_START - KERNEL_TR_PAGE_SIZE) 8#define LOAD_OFFSET (KERNEL_START - KERNEL_TR_PAGE_SIZE)
9#include <asm-generic/vmlinux.lds.h> 9#include <asm-generic/vmlinux.lds.h>
10 10
11#define IVT_TEXT \
12 VMLINUX_SYMBOL(__start_ivt_text) = .; \
13 *(.text.ivt) \
14 VMLINUX_SYMBOL(__end_ivt_text) = .;
15
11OUTPUT_FORMAT("elf64-ia64-little") 16OUTPUT_FORMAT("elf64-ia64-little")
12OUTPUT_ARCH(ia64) 17OUTPUT_ARCH(ia64)
13ENTRY(phys_start) 18ENTRY(phys_start)
@@ -39,7 +44,7 @@ SECTIONS
39 44
40 .text : AT(ADDR(.text) - LOAD_OFFSET) 45 .text : AT(ADDR(.text) - LOAD_OFFSET)
41 { 46 {
42 *(.text.ivt) 47 IVT_TEXT
43 *(.text) 48 *(.text)
44 SCHED_TEXT 49 SCHED_TEXT
45 LOCK_TEXT 50 LOCK_TEXT
diff --git a/arch/ia64/pci/pci.c b/arch/ia64/pci/pci.c
index e3fc4edea113..720a861f88be 100644
--- a/arch/ia64/pci/pci.c
+++ b/arch/ia64/pci/pci.c
@@ -312,7 +312,7 @@ pci_acpi_scan_root(struct acpi_device *device, int domain, int bus)
312 acpi_walk_resources(device->handle, METHOD_NAME__CRS, add_window, 312 acpi_walk_resources(device->handle, METHOD_NAME__CRS, add_window,
313 &info); 313 &info);
314 314
315 pbus = pci_scan_bus(bus, &pci_root_ops, controller); 315 pbus = pci_scan_bus_parented(NULL, bus, &pci_root_ops, controller);
316 if (pbus) 316 if (pbus)
317 pcibios_setup_root_windows(pbus, controller); 317 pcibios_setup_root_windows(pbus, controller);
318 318
@@ -373,6 +373,25 @@ void pcibios_bus_to_resource(struct pci_dev *dev,
373 res->end = region->end + offset; 373 res->end = region->end + offset;
374} 374}
375 375
376static int __devinit is_valid_resource(struct pci_dev *dev, int idx)
377{
378 unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM;
379 struct resource *devr = &dev->resource[idx];
380
381 if (!dev->bus)
382 return 0;
383 for (i=0; i<PCI_BUS_NUM_RESOURCES; i++) {
384 struct resource *busr = dev->bus->resource[i];
385
386 if (!busr || ((busr->flags ^ devr->flags) & type_mask))
387 continue;
388 if ((devr->start) && (devr->start >= busr->start) &&
389 (devr->end <= busr->end))
390 return 1;
391 }
392 return 0;
393}
394
376static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev) 395static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev)
377{ 396{
378 struct pci_bus_region region; 397 struct pci_bus_region region;
@@ -386,7 +405,8 @@ static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev)
386 region.start = dev->resource[i].start; 405 region.start = dev->resource[i].start;
387 region.end = dev->resource[i].end; 406 region.end = dev->resource[i].end;
388 pcibios_bus_to_resource(dev, &dev->resource[i], &region); 407 pcibios_bus_to_resource(dev, &dev->resource[i], &region);
389 pci_claim_resource(dev, i); 408 if ((is_valid_resource(dev, i)))
409 pci_claim_resource(dev, i);
390 } 410 }
391} 411}
392 412
@@ -398,6 +418,10 @@ pcibios_fixup_bus (struct pci_bus *b)
398{ 418{
399 struct pci_dev *dev; 419 struct pci_dev *dev;
400 420
421 if (b->self) {
422 pci_read_bridge_bases(b);
423 pcibios_fixup_device_resources(b->self);
424 }
401 list_for_each_entry(dev, &b->devices, bus_list) 425 list_for_each_entry(dev, &b->devices, bus_list)
402 pcibios_fixup_device_resources(dev); 426 pcibios_fixup_device_resources(dev);
403 427
@@ -418,18 +442,24 @@ pcibios_enable_resources (struct pci_dev *dev, int mask)
418 u16 cmd, old_cmd; 442 u16 cmd, old_cmd;
419 int idx; 443 int idx;
420 struct resource *r; 444 struct resource *r;
445 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
421 446
422 if (!dev) 447 if (!dev)
423 return -EINVAL; 448 return -EINVAL;
424 449
425 pci_read_config_word(dev, PCI_COMMAND, &cmd); 450 pci_read_config_word(dev, PCI_COMMAND, &cmd);
426 old_cmd = cmd; 451 old_cmd = cmd;
427 for (idx=0; idx<6; idx++) { 452 for (idx=0; idx<PCI_NUM_RESOURCES; idx++) {
428 /* Only set up the desired resources. */ 453 /* Only set up the desired resources. */
429 if (!(mask & (1 << idx))) 454 if (!(mask & (1 << idx)))
430 continue; 455 continue;
431 456
432 r = &dev->resource[idx]; 457 r = &dev->resource[idx];
458 if (!(r->flags & type_mask))
459 continue;
460 if ((idx == PCI_ROM_RESOURCE) &&
461 (!(r->flags & IORESOURCE_ROM_ENABLE)))
462 continue;
433 if (!r->start && r->end) { 463 if (!r->start && r->end) {
434 printk(KERN_ERR 464 printk(KERN_ERR
435 "PCI: Device %s not available because of resource collisions\n", 465 "PCI: Device %s not available because of resource collisions\n",
@@ -441,8 +471,6 @@ pcibios_enable_resources (struct pci_dev *dev, int mask)
441 if (r->flags & IORESOURCE_MEM) 471 if (r->flags & IORESOURCE_MEM)
442 cmd |= PCI_COMMAND_MEMORY; 472 cmd |= PCI_COMMAND_MEMORY;
443 } 473 }
444 if (dev->resource[PCI_ROM_RESOURCE].start)
445 cmd |= PCI_COMMAND_MEMORY;
446 if (cmd != old_cmd) { 474 if (cmd != old_cmd) {
447 printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd); 475 printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd);
448 pci_write_config_word(dev, PCI_COMMAND, cmd); 476 pci_write_config_word(dev, PCI_COMMAND, cmd);
diff --git a/arch/ia64/sn/kernel/io_init.c b/arch/ia64/sn/kernel/io_init.c
index 9e07f5463f21..783eb4323847 100644
--- a/arch/ia64/sn/kernel/io_init.c
+++ b/arch/ia64/sn/kernel/io_init.c
@@ -384,7 +384,7 @@ static int __init sn_pci_init(void)
384 extern void register_sn_procfs(void); 384 extern void register_sn_procfs(void);
385#endif 385#endif
386 386
387 if (!ia64_platform_is("sn2") || IS_RUNNING_ON_SIMULATOR()) 387 if (!ia64_platform_is("sn2") || IS_RUNNING_ON_FAKE_PROM())
388 return 0; 388 return 0;
389 389
390 /* 390 /*
diff --git a/arch/ia64/sn/kernel/iomv.c b/arch/ia64/sn/kernel/iomv.c
index fec6d8b8237b..7ce3cdad627b 100644
--- a/arch/ia64/sn/kernel/iomv.c
+++ b/arch/ia64/sn/kernel/iomv.c
@@ -9,12 +9,16 @@
9#include <linux/module.h> 9#include <linux/module.h>
10#include <asm/io.h> 10#include <asm/io.h>
11#include <asm/delay.h> 11#include <asm/delay.h>
12#include <asm/vga.h>
12#include <asm/sn/nodepda.h> 13#include <asm/sn/nodepda.h>
13#include <asm/sn/simulator.h> 14#include <asm/sn/simulator.h>
14#include <asm/sn/pda.h> 15#include <asm/sn/pda.h>
15#include <asm/sn/sn_cpuid.h> 16#include <asm/sn/sn_cpuid.h>
16#include <asm/sn/shub_mmr.h> 17#include <asm/sn/shub_mmr.h>
17 18
19#define IS_LEGACY_VGA_IOPORT(p) \
20 (((p) >= 0x3b0 && (p) <= 0x3bb) || ((p) >= 0x3c0 && (p) <= 0x3df))
21
18/** 22/**
19 * sn_io_addr - convert an in/out port to an i/o address 23 * sn_io_addr - convert an in/out port to an i/o address
20 * @port: port to convert 24 * @port: port to convert
@@ -26,6 +30,8 @@
26void *sn_io_addr(unsigned long port) 30void *sn_io_addr(unsigned long port)
27{ 31{
28 if (!IS_RUNNING_ON_SIMULATOR()) { 32 if (!IS_RUNNING_ON_SIMULATOR()) {
33 if (IS_LEGACY_VGA_IOPORT(port))
34 port += vga_console_iobase;
29 /* On sn2, legacy I/O ports don't point at anything */ 35 /* On sn2, legacy I/O ports don't point at anything */
30 if (port < (64 * 1024)) 36 if (port < (64 * 1024))
31 return NULL; 37 return NULL;
diff --git a/arch/ia64/sn/kernel/setup.c b/arch/ia64/sn/kernel/setup.c
index 44bfc7f318cb..22e10d282c7f 100644
--- a/arch/ia64/sn/kernel/setup.c
+++ b/arch/ia64/sn/kernel/setup.c
@@ -36,6 +36,7 @@
36#include <asm/machvec.h> 36#include <asm/machvec.h>
37#include <asm/system.h> 37#include <asm/system.h>
38#include <asm/processor.h> 38#include <asm/processor.h>
39#include <asm/vga.h>
39#include <asm/sn/arch.h> 40#include <asm/sn/arch.h>
40#include <asm/sn/addrs.h> 41#include <asm/sn/addrs.h>
41#include <asm/sn/pda.h> 42#include <asm/sn/pda.h>
@@ -95,6 +96,7 @@ u8 sn_coherency_id;
95EXPORT_SYMBOL(sn_coherency_id); 96EXPORT_SYMBOL(sn_coherency_id);
96u8 sn_region_size; 97u8 sn_region_size;
97EXPORT_SYMBOL(sn_region_size); 98EXPORT_SYMBOL(sn_region_size);
99int sn_prom_type; /* 0=hardware, 1=medusa/realprom, 2=medusa/fakeprom */
98 100
99short physical_node_map[MAX_PHYSNODE_ID]; 101short physical_node_map[MAX_PHYSNODE_ID];
100 102
@@ -273,14 +275,17 @@ void __init sn_setup(char **cmdline_p)
273 275
274 ia64_sn_plat_set_error_handling_features(); 276 ia64_sn_plat_set_error_handling_features();
275 277
278#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
276 /* 279 /*
277 * If the generic code has enabled vga console support - lets 280 * If there was a primary vga adapter identified through the
278 * get rid of it again. This is a kludge for the fact that ACPI 281 * EFI PCDP table, make it the preferred console. Otherwise
279 * currtently has no way of informing us if legacy VGA is available 282 * zero out conswitchp.
280 * or not.
281 */ 283 */
282#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE) 284
283 if (conswitchp == &vga_con) { 285 if (vga_console_membase) {
286 /* usable vga ... make tty0 the preferred default console */
287 add_preferred_console("tty", 0, NULL);
288 } else {
284 printk(KERN_DEBUG "SGI: Disabling VGA console\n"); 289 printk(KERN_DEBUG "SGI: Disabling VGA console\n");
285#ifdef CONFIG_DUMMY_CONSOLE 290#ifdef CONFIG_DUMMY_CONSOLE
286 conswitchp = &dummy_con; 291 conswitchp = &dummy_con;
@@ -350,7 +355,7 @@ void __init sn_setup(char **cmdline_p)
350 355
351 ia64_mark_idle = &snidle; 356 ia64_mark_idle = &snidle;
352 357
353 /* 358 /*
354 * For the bootcpu, we do this here. All other cpus will make the 359 * For the bootcpu, we do this here. All other cpus will make the
355 * call as part of cpu_init in slave cpu initialization. 360 * call as part of cpu_init in slave cpu initialization.
356 */ 361 */
@@ -397,7 +402,7 @@ static void __init sn_init_pdas(char **cmdline_p)
397 nodepdaindr[cnode] = 402 nodepdaindr[cnode] =
398 alloc_bootmem_node(NODE_DATA(cnode), sizeof(nodepda_t)); 403 alloc_bootmem_node(NODE_DATA(cnode), sizeof(nodepda_t));
399 memset(nodepdaindr[cnode], 0, sizeof(nodepda_t)); 404 memset(nodepdaindr[cnode], 0, sizeof(nodepda_t));
400 memset(nodepdaindr[cnode]->phys_cpuid, -1, 405 memset(nodepdaindr[cnode]->phys_cpuid, -1,
401 sizeof(nodepdaindr[cnode]->phys_cpuid)); 406 sizeof(nodepdaindr[cnode]->phys_cpuid));
402 } 407 }
403 408
@@ -427,7 +432,7 @@ static void __init sn_init_pdas(char **cmdline_p)
427 } 432 }
428 433
429 /* 434 /*
430 * Initialize the per node hubdev. This includes IO Nodes and 435 * Initialize the per node hubdev. This includes IO Nodes and
431 * headless/memless nodes. 436 * headless/memless nodes.
432 */ 437 */
433 for (cnode = 0; cnode < numionodes; cnode++) { 438 for (cnode = 0; cnode < numionodes; cnode++) {
@@ -455,6 +460,14 @@ void __init sn_cpu_init(void)
455 int i; 460 int i;
456 static int wars_have_been_checked; 461 static int wars_have_been_checked;
457 462
463 if (smp_processor_id() == 0 && IS_MEDUSA()) {
464 if (ia64_sn_is_fake_prom())
465 sn_prom_type = 2;
466 else
467 sn_prom_type = 1;
468 printk("Running on medusa with %s PROM\n", (sn_prom_type == 1) ? "real" : "fake");
469 }
470
458 memset(pda, 0, sizeof(pda)); 471 memset(pda, 0, sizeof(pda));
459 if (ia64_sn_get_sn_info(0, &sn_hub_info->shub2, &sn_hub_info->nasid_bitmask, &sn_hub_info->nasid_shift, 472 if (ia64_sn_get_sn_info(0, &sn_hub_info->shub2, &sn_hub_info->nasid_bitmask, &sn_hub_info->nasid_shift,
460 &sn_system_size, &sn_sharing_domain_size, &sn_partition_id, 473 &sn_system_size, &sn_sharing_domain_size, &sn_partition_id,
@@ -520,7 +533,7 @@ void __init sn_cpu_init(void)
520 */ 533 */
521 { 534 {
522 u64 pio1[] = {SH1_PIO_WRITE_STATUS_0, 0, SH1_PIO_WRITE_STATUS_1, 0}; 535 u64 pio1[] = {SH1_PIO_WRITE_STATUS_0, 0, SH1_PIO_WRITE_STATUS_1, 0};
523 u64 pio2[] = {SH2_PIO_WRITE_STATUS_0, SH2_PIO_WRITE_STATUS_1, 536 u64 pio2[] = {SH2_PIO_WRITE_STATUS_0, SH2_PIO_WRITE_STATUS_1,
524 SH2_PIO_WRITE_STATUS_2, SH2_PIO_WRITE_STATUS_3}; 537 SH2_PIO_WRITE_STATUS_2, SH2_PIO_WRITE_STATUS_3};
525 u64 *pio; 538 u64 *pio;
526 pio = is_shub1() ? pio1 : pio2; 539 pio = is_shub1() ? pio1 : pio2;
@@ -552,6 +565,10 @@ static void __init scan_for_ionodes(void)
552 int nasid = 0; 565 int nasid = 0;
553 lboard_t *brd; 566 lboard_t *brd;
554 567
568 /* fakeprom does not support klgraph */
569 if (IS_RUNNING_ON_FAKE_PROM())
570 return;
571
555 /* Setup ionodes with memory */ 572 /* Setup ionodes with memory */
556 for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid += 2) { 573 for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid += 2) {
557 char *klgraph_header; 574 char *klgraph_header;
@@ -563,8 +580,6 @@ static void __init scan_for_ionodes(void)
563 cnodeid = -1; 580 cnodeid = -1;
564 klgraph_header = __va(ia64_sn_get_klconfig_addr(nasid)); 581 klgraph_header = __va(ia64_sn_get_klconfig_addr(nasid));
565 if (!klgraph_header) { 582 if (!klgraph_header) {
566 if (IS_RUNNING_ON_SIMULATOR())
567 continue;
568 BUG(); /* All nodes must have klconfig tables! */ 583 BUG(); /* All nodes must have klconfig tables! */
569 } 584 }
570 cnodeid = nasid_to_cnodeid(nasid); 585 cnodeid = nasid_to_cnodeid(nasid);
@@ -630,8 +645,8 @@ int
630nasid_slice_to_cpuid(int nasid, int slice) 645nasid_slice_to_cpuid(int nasid, int slice)
631{ 646{
632 long cpu; 647 long cpu;
633 648
634 for (cpu=0; cpu < NR_CPUS; cpu++) 649 for (cpu=0; cpu < NR_CPUS; cpu++)
635 if (cpuid_to_nasid(cpu) == nasid && 650 if (cpuid_to_nasid(cpu) == nasid &&
636 cpuid_to_slice(cpu) == slice) 651 cpuid_to_slice(cpu) == slice)
637 return cpu; 652 return cpu;
diff --git a/arch/ia64/sn/kernel/sn2/ptc_deadlock.S b/arch/ia64/sn/kernel/sn2/ptc_deadlock.S
index 7947312801ec..96cb71d15682 100644
--- a/arch/ia64/sn/kernel/sn2/ptc_deadlock.S
+++ b/arch/ia64/sn/kernel/sn2/ptc_deadlock.S
@@ -6,6 +6,7 @@
6 * Copyright (C) 2000-2004 Silicon Graphics, Inc. All rights reserved. 6 * Copyright (C) 2000-2004 Silicon Graphics, Inc. All rights reserved.
7 */ 7 */
8 8
9#include <asm/types.h>
9#include <asm/sn/shub_mmr.h> 10#include <asm/sn/shub_mmr.h>
10 11
11#define DEADLOCKBIT SH_PIO_WRITE_STATUS_WRITE_DEADLOCK_SHFT 12#define DEADLOCKBIT SH_PIO_WRITE_STATUS_WRITE_DEADLOCK_SHFT
diff --git a/arch/ia64/sn/kernel/tiocx.c b/arch/ia64/sn/kernel/tiocx.c
index a087b274847e..8716f4d5314b 100644
--- a/arch/ia64/sn/kernel/tiocx.c
+++ b/arch/ia64/sn/kernel/tiocx.c
@@ -204,8 +204,8 @@ cx_device_register(nasid_t nasid, int part_num, int mfg_num,
204 cx_dev->dev.parent = NULL; 204 cx_dev->dev.parent = NULL;
205 cx_dev->dev.bus = &tiocx_bus_type; 205 cx_dev->dev.bus = &tiocx_bus_type;
206 cx_dev->dev.release = tiocx_bus_release; 206 cx_dev->dev.release = tiocx_bus_release;
207 snprintf(cx_dev->dev.bus_id, BUS_ID_SIZE, "%d.0x%x", 207 snprintf(cx_dev->dev.bus_id, BUS_ID_SIZE, "%d",
208 cx_dev->cx_id.nasid, cx_dev->cx_id.part_num); 208 cx_dev->cx_id.nasid);
209 device_register(&cx_dev->dev); 209 device_register(&cx_dev->dev);
210 get_device(&cx_dev->dev); 210 get_device(&cx_dev->dev);
211 211
@@ -236,7 +236,6 @@ int cx_device_unregister(struct cx_dev *cx_dev)
236 */ 236 */
237static int cx_device_reload(struct cx_dev *cx_dev) 237static int cx_device_reload(struct cx_dev *cx_dev)
238{ 238{
239 device_remove_file(&cx_dev->dev, &dev_attr_cxdev_control);
240 cx_device_unregister(cx_dev); 239 cx_device_unregister(cx_dev);
241 return cx_device_register(cx_dev->cx_id.nasid, cx_dev->cx_id.part_num, 240 return cx_device_register(cx_dev->cx_id.nasid, cx_dev->cx_id.part_num,
242 cx_dev->cx_id.mfg_num, cx_dev->hubdev); 241 cx_dev->cx_id.mfg_num, cx_dev->hubdev);
@@ -383,6 +382,7 @@ static int is_fpga_brick(int nasid)
383 switch (tiocx_btchar_get(nasid)) { 382 switch (tiocx_btchar_get(nasid)) {
384 case L1_BRICKTYPE_SA: 383 case L1_BRICKTYPE_SA:
385 case L1_BRICKTYPE_ATHENA: 384 case L1_BRICKTYPE_ATHENA:
385 case L1_BRICKTYPE_DAYTONA:
386 return 1; 386 return 1;
387 } 387 }
388 return 0; 388 return 0;
@@ -409,7 +409,7 @@ static int tiocx_reload(struct cx_dev *cx_dev)
409 uint64_t cx_id; 409 uint64_t cx_id;
410 410
411 cx_id = 411 cx_id =
412 *(volatile int32_t *)(TIO_SWIN_BASE(nasid, TIOCX_CORELET) + 412 *(volatile uint64_t *)(TIO_SWIN_BASE(nasid, TIOCX_CORELET) +
413 WIDGET_ID); 413 WIDGET_ID);
414 part_num = XWIDGET_PART_NUM(cx_id); 414 part_num = XWIDGET_PART_NUM(cx_id);
415 mfg_num = XWIDGET_MFG_NUM(cx_id); 415 mfg_num = XWIDGET_MFG_NUM(cx_id);
@@ -458,6 +458,10 @@ static ssize_t store_cxdev_control(struct device *dev, struct device_attribute *
458 458
459 switch (n) { 459 switch (n) {
460 case 1: 460 case 1:
461 tio_corelet_reset(cx_dev->cx_id.nasid, TIOCX_CORELET);
462 tiocx_reload(cx_dev);
463 break;
464 case 2:
461 tiocx_reload(cx_dev); 465 tiocx_reload(cx_dev);
462 break; 466 break;
463 case 3: 467 case 3:
@@ -537,7 +541,7 @@ static void __exit tiocx_exit(void)
537 bus_unregister(&tiocx_bus_type); 541 bus_unregister(&tiocx_bus_type);
538} 542}
539 543
540module_init(tiocx_init); 544subsys_initcall(tiocx_init);
541module_exit(tiocx_exit); 545module_exit(tiocx_exit);
542 546
543/************************************************************************ 547/************************************************************************
diff --git a/arch/ia64/sn/pci/tioca_provider.c b/arch/ia64/sn/pci/tioca_provider.c
index 8dae9eb45456..05aa8c2fe9bb 100644
--- a/arch/ia64/sn/pci/tioca_provider.c
+++ b/arch/ia64/sn/pci/tioca_provider.c
@@ -336,7 +336,7 @@ tioca_dma_d48(struct pci_dev *pdev, uint64_t paddr)
336 if (!ct_addr) 336 if (!ct_addr)
337 return 0; 337 return 0;
338 338
339 bus_addr = (dma_addr_t) (ct_addr & 0xffffffffffff); 339 bus_addr = (dma_addr_t) (ct_addr & 0xffffffffffffUL);
340 node_upper = ct_addr >> 48; 340 node_upper = ct_addr >> 48;
341 341
342 if (node_upper > 64) { 342 if (node_upper > 64) {
@@ -464,7 +464,7 @@ map_return:
464 * For mappings created using the direct modes (64 or 48) there are no 464 * For mappings created using the direct modes (64 or 48) there are no
465 * resources to release. 465 * resources to release.
466 */ 466 */
467void 467static void
468tioca_dma_unmap(struct pci_dev *pdev, dma_addr_t bus_addr, int dir) 468tioca_dma_unmap(struct pci_dev *pdev, dma_addr_t bus_addr, int dir)
469{ 469{
470 int i, entry; 470 int i, entry;
@@ -514,7 +514,7 @@ tioca_dma_unmap(struct pci_dev *pdev, dma_addr_t bus_addr, int dir)
514 * The mapping mode used is based on the devices dma_mask. As a last resort 514 * The mapping mode used is based on the devices dma_mask. As a last resort
515 * use the GART mapped mode. 515 * use the GART mapped mode.
516 */ 516 */
517uint64_t 517static uint64_t
518tioca_dma_map(struct pci_dev *pdev, uint64_t paddr, size_t byte_count) 518tioca_dma_map(struct pci_dev *pdev, uint64_t paddr, size_t byte_count)
519{ 519{
520 uint64_t mapaddr; 520 uint64_t mapaddr;
@@ -580,7 +580,7 @@ tioca_error_intr_handler(int irq, void *arg, struct pt_regs *pt)
580 * On successful setup, returns the kernel version of tioca_common back to 580 * On successful setup, returns the kernel version of tioca_common back to
581 * the caller. 581 * the caller.
582 */ 582 */
583void * 583static void *
584tioca_bus_fixup(struct pcibus_bussoft *prom_bussoft) 584tioca_bus_fixup(struct pcibus_bussoft *prom_bussoft)
585{ 585{
586 struct tioca_common *tioca_common; 586 struct tioca_common *tioca_common;
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 508026ae5842..65ee15396ffd 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -457,7 +457,7 @@ static int do_signal(sigset_t *oldset, struct pt_regs *regs)
457 if (!user_mode(regs)) 457 if (!user_mode(regs))
458 return 1; 458 return 1;
459 459
460 if (try_to_freeze(0)) 460 if (try_to_freeze())
461 goto no_signal; 461 goto no_signal;
462 462
463 if (!oldset) 463 if (!oldset)
diff --git a/arch/parisc/configs/712_defconfig b/arch/parisc/configs/712_defconfig
index 872085dea8a8..6efaa9293eef 100644
--- a/arch/parisc/configs/712_defconfig
+++ b/arch/parisc/configs/712_defconfig
@@ -506,7 +506,7 @@ CONFIG_HW_CONSOLE=y
506# 506#
507CONFIG_SERIAL_8250=y 507CONFIG_SERIAL_8250=y
508CONFIG_SERIAL_8250_CONSOLE=y 508CONFIG_SERIAL_8250_CONSOLE=y
509CONFIG_SERIAL_8250_NR_UARTS=8 509CONFIG_SERIAL_8250_NR_UARTS=17
510CONFIG_SERIAL_8250_EXTENDED=y 510CONFIG_SERIAL_8250_EXTENDED=y
511CONFIG_SERIAL_8250_MANY_PORTS=y 511CONFIG_SERIAL_8250_MANY_PORTS=y
512CONFIG_SERIAL_8250_SHARE_IRQ=y 512CONFIG_SERIAL_8250_SHARE_IRQ=y
diff --git a/arch/parisc/configs/a500_defconfig b/arch/parisc/configs/a500_defconfig
index d28ebfa1070d..30fc03ed0cfb 100644
--- a/arch/parisc/configs/a500_defconfig
+++ b/arch/parisc/configs/a500_defconfig
@@ -662,7 +662,7 @@ CONFIG_HW_CONSOLE=y
662CONFIG_SERIAL_8250=y 662CONFIG_SERIAL_8250=y
663CONFIG_SERIAL_8250_CONSOLE=y 663CONFIG_SERIAL_8250_CONSOLE=y
664CONFIG_SERIAL_8250_CS=m 664CONFIG_SERIAL_8250_CS=m
665CONFIG_SERIAL_8250_NR_UARTS=8 665CONFIG_SERIAL_8250_NR_UARTS=17
666CONFIG_SERIAL_8250_EXTENDED=y 666CONFIG_SERIAL_8250_EXTENDED=y
667CONFIG_SERIAL_8250_MANY_PORTS=y 667CONFIG_SERIAL_8250_MANY_PORTS=y
668CONFIG_SERIAL_8250_SHARE_IRQ=y 668CONFIG_SERIAL_8250_SHARE_IRQ=y
diff --git a/arch/parisc/configs/b180_defconfig b/arch/parisc/configs/b180_defconfig
index 1700d7aec686..46c9511f3229 100644
--- a/arch/parisc/configs/b180_defconfig
+++ b/arch/parisc/configs/b180_defconfig
@@ -514,7 +514,7 @@ CONFIG_HW_CONSOLE=y
514# 514#
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=13
518CONFIG_SERIAL_8250_EXTENDED=y 518CONFIG_SERIAL_8250_EXTENDED=y
519CONFIG_SERIAL_8250_MANY_PORTS=y 519CONFIG_SERIAL_8250_MANY_PORTS=y
520CONFIG_SERIAL_8250_SHARE_IRQ=y 520CONFIG_SERIAL_8250_SHARE_IRQ=y
diff --git a/arch/parisc/configs/c3000_defconfig b/arch/parisc/configs/c3000_defconfig
index b27980161c31..67aca6ccc9b0 100644
--- a/arch/parisc/configs/c3000_defconfig
+++ b/arch/parisc/configs/c3000_defconfig
@@ -661,7 +661,7 @@ CONFIG_HW_CONSOLE=y
661# 661#
662CONFIG_SERIAL_8250=y 662CONFIG_SERIAL_8250=y
663CONFIG_SERIAL_8250_CONSOLE=y 663CONFIG_SERIAL_8250_CONSOLE=y
664CONFIG_SERIAL_8250_NR_UARTS=4 664CONFIG_SERIAL_8250_NR_UARTS=13
665CONFIG_SERIAL_8250_EXTENDED=y 665CONFIG_SERIAL_8250_EXTENDED=y
666CONFIG_SERIAL_8250_MANY_PORTS=y 666CONFIG_SERIAL_8250_MANY_PORTS=y
667CONFIG_SERIAL_8250_SHARE_IRQ=y 667CONFIG_SERIAL_8250_SHARE_IRQ=y
diff --git a/arch/parisc/defconfig b/arch/parisc/defconfig
index ebd6301aa599..fdae21c503d7 100644
--- a/arch/parisc/defconfig
+++ b/arch/parisc/defconfig
@@ -517,7 +517,7 @@ CONFIG_HW_CONSOLE=y
517# 517#
518CONFIG_SERIAL_8250=y 518CONFIG_SERIAL_8250=y
519CONFIG_SERIAL_8250_CONSOLE=y 519CONFIG_SERIAL_8250_CONSOLE=y
520CONFIG_SERIAL_8250_NR_UARTS=4 520CONFIG_SERIAL_8250_NR_UARTS=13
521CONFIG_SERIAL_8250_EXTENDED=y 521CONFIG_SERIAL_8250_EXTENDED=y
522CONFIG_SERIAL_8250_MANY_PORTS=y 522CONFIG_SERIAL_8250_MANY_PORTS=y
523CONFIG_SERIAL_8250_SHARE_IRQ=y 523CONFIG_SERIAL_8250_SHARE_IRQ=y
diff --git a/arch/ppc/kernel/misc.S b/arch/ppc/kernel/misc.S
index b6a63a49a232..191a8def3bdb 100644
--- a/arch/ppc/kernel/misc.S
+++ b/arch/ppc/kernel/misc.S
@@ -1449,3 +1449,5 @@ _GLOBAL(sys_call_table)
1449 .long sys_request_key /* 270 */ 1449 .long sys_request_key /* 270 */
1450 .long sys_keyctl 1450 .long sys_keyctl
1451 .long sys_waitid 1451 .long sys_waitid
1452 .long sys_ioprio_set
1453 .long sys_ioprio_get
diff --git a/arch/ppc/kernel/pci.c b/arch/ppc/kernel/pci.c
index 6d7b92d72458..70cfb6ffd877 100644
--- a/arch/ppc/kernel/pci.c
+++ b/arch/ppc/kernel/pci.c
@@ -1495,7 +1495,7 @@ static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
1495 *offset += hose->pci_mem_offset; 1495 *offset += hose->pci_mem_offset;
1496 res_bit = IORESOURCE_MEM; 1496 res_bit = IORESOURCE_MEM;
1497 } else { 1497 } else {
1498 io_offset = (unsigned long)hose->io_base_virt; 1498 io_offset = hose->io_base_virt - ___IO_BASE;
1499 *offset += io_offset; 1499 *offset += io_offset;
1500 res_bit = IORESOURCE_IO; 1500 res_bit = IORESOURCE_IO;
1501 } 1501 }
@@ -1522,7 +1522,7 @@ static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
1522 1522
1523 /* found it! construct the final physical address */ 1523 /* found it! construct the final physical address */
1524 if (mmap_state == pci_mmap_io) 1524 if (mmap_state == pci_mmap_io)
1525 *offset += hose->io_base_phys - _IO_BASE; 1525 *offset += hose->io_base_phys - io_offset;
1526 return rp; 1526 return rp;
1527 } 1527 }
1528 1528
@@ -1739,6 +1739,23 @@ long sys_pciconfig_iobase(long which, unsigned long bus, unsigned long devfn)
1739 return result; 1739 return result;
1740} 1740}
1741 1741
1742void pci_resource_to_user(const struct pci_dev *dev, int bar,
1743 const struct resource *rsrc,
1744 u64 *start, u64 *end)
1745{
1746 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
1747 unsigned long offset = 0;
1748
1749 if (hose == NULL)
1750 return;
1751
1752 if (rsrc->flags & IORESOURCE_IO)
1753 offset = ___IO_BASE - hose->io_base_virt + hose->io_base_phys;
1754
1755 *start = rsrc->start + offset;
1756 *end = rsrc->end + offset;
1757}
1758
1742void __init 1759void __init
1743pci_init_resource(struct resource *res, unsigned long start, unsigned long end, 1760pci_init_resource(struct resource *res, unsigned long start, unsigned long end,
1744 int flags, char *name) 1761 int flags, char *name)
diff --git a/arch/ppc/mm/init.c b/arch/ppc/mm/init.c
index 334ef4150d92..6164a2b34733 100644
--- a/arch/ppc/mm/init.c
+++ b/arch/ppc/mm/init.c
@@ -606,9 +606,19 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
606 struct page *page = pfn_to_page(pfn); 606 struct page *page = pfn_to_page(pfn);
607 if (!PageReserved(page) 607 if (!PageReserved(page)
608 && !test_bit(PG_arch_1, &page->flags)) { 608 && !test_bit(PG_arch_1, &page->flags)) {
609 if (vma->vm_mm == current->active_mm) 609 if (vma->vm_mm == current->active_mm) {
610#ifdef CONFIG_8xx
611 /* On 8xx, cache control instructions (particularly
612 * "dcbst" from flush_dcache_icache) fault as write
613 * operation if there is an unpopulated TLB entry
614 * for the address in question. To workaround that,
615 * we invalidate the TLB here, thus avoiding dcbst
616 * misbehaviour.
617 */
618 _tlbie(address);
619#endif
610 __flush_dcache_icache((void *) address); 620 __flush_dcache_icache((void *) address);
611 else 621 } else
612 flush_dcache_icache_page(page); 622 flush_dcache_icache_page(page);
613 set_bit(PG_arch_1, &page->flags); 623 set_bit(PG_arch_1, &page->flags);
614 } 624 }
diff --git a/arch/ppc/platforms/pmac_sleep.S b/arch/ppc/platforms/pmac_sleep.S
index f459ade1bd63..016a74649155 100644
--- a/arch/ppc/platforms/pmac_sleep.S
+++ b/arch/ppc/platforms/pmac_sleep.S
@@ -46,7 +46,7 @@
46 .section .text 46 .section .text
47 .align 5 47 .align 5
48 48
49#if defined(CONFIG_PMAC_PBOOK) || defined(CONFIG_CPU_FREQ_PMAC) 49#if defined(CONFIG_PM) || defined(CONFIG_CPU_FREQ_PMAC)
50 50
51/* This gets called by via-pmu.c late during the sleep process. 51/* This gets called by via-pmu.c late during the sleep process.
52 * The PMU was already send the sleep command and will shut us down 52 * The PMU was already send the sleep command and will shut us down
@@ -382,7 +382,7 @@ turn_on_mmu:
382 isync 382 isync
383 rfi 383 rfi
384 384
385#endif /* defined(CONFIG_PMAC_PBOOK) || defined(CONFIG_CPU_FREQ) */ 385#endif /* defined(CONFIG_PM) || defined(CONFIG_CPU_FREQ) */
386 386
387 .section .data 387 .section .data
388 .balign L1_CACHE_LINE_SIZE 388 .balign L1_CACHE_LINE_SIZE
diff --git a/arch/ppc/platforms/pmac_time.c b/arch/ppc/platforms/pmac_time.c
index de60ccc7db9f..778ce4fec368 100644
--- a/arch/ppc/platforms/pmac_time.c
+++ b/arch/ppc/platforms/pmac_time.c
@@ -206,7 +206,7 @@ via_calibrate_decr(void)
206 return 1; 206 return 1;
207} 207}
208 208
209#ifdef CONFIG_PMAC_PBOOK 209#ifdef CONFIG_PM
210/* 210/*
211 * Reset the time after a sleep. 211 * Reset the time after a sleep.
212 */ 212 */
@@ -238,7 +238,7 @@ time_sleep_notify(struct pmu_sleep_notifier *self, int when)
238static struct pmu_sleep_notifier time_sleep_notifier __pmacdata = { 238static struct pmu_sleep_notifier time_sleep_notifier __pmacdata = {
239 time_sleep_notify, SLEEP_LEVEL_MISC, 239 time_sleep_notify, SLEEP_LEVEL_MISC,
240}; 240};
241#endif /* CONFIG_PMAC_PBOOK */ 241#endif /* CONFIG_PM */
242 242
243/* 243/*
244 * Query the OF and get the decr frequency. 244 * Query the OF and get the decr frequency.
@@ -251,9 +251,9 @@ pmac_calibrate_decr(void)
251 struct device_node *cpu; 251 struct device_node *cpu;
252 unsigned int freq, *fp; 252 unsigned int freq, *fp;
253 253
254#ifdef CONFIG_PMAC_PBOOK 254#ifdef CONFIG_PM
255 pmu_register_sleep_notifier(&time_sleep_notifier); 255 pmu_register_sleep_notifier(&time_sleep_notifier);
256#endif /* CONFIG_PMAC_PBOOK */ 256#endif /* CONFIG_PM */
257 257
258 /* We assume MacRISC2 machines have correct device-tree 258 /* We assume MacRISC2 machines have correct device-tree
259 * calibration. That's better since the VIA itself seems 259 * calibration. That's better since the VIA itself seems
diff --git a/arch/ppc/platforms/sandpoint.c b/arch/ppc/platforms/sandpoint.c
index 70e58f43f2b8..8b149c2fc54f 100644
--- a/arch/ppc/platforms/sandpoint.c
+++ b/arch/ppc/platforms/sandpoint.c
@@ -324,6 +324,7 @@ sandpoint_setup_arch(void)
324 pdata[1].irq = 0; 324 pdata[1].irq = 0;
325 pdata[1].mapbase = 0; 325 pdata[1].mapbase = 0;
326 } 326 }
327 }
327 328
328 printk(KERN_INFO "Motorola SPS Sandpoint Test Platform\n"); 329 printk(KERN_INFO "Motorola SPS Sandpoint Test Platform\n");
329 printk(KERN_INFO "Port by MontaVista Software, Inc. (source@mvista.com)\n"); 330 printk(KERN_INFO "Port by MontaVista Software, Inc. (source@mvista.com)\n");
diff --git a/arch/ppc/syslib/open_pic.c b/arch/ppc/syslib/open_pic.c
index b45d8268bf93..ad39b86ca92c 100644
--- a/arch/ppc/syslib/open_pic.c
+++ b/arch/ppc/syslib/open_pic.c
@@ -370,8 +370,9 @@ void __init openpic_init(int offset)
370 /* Initialize IPI interrupts */ 370 /* Initialize IPI interrupts */
371 if ( ppc_md.progress ) ppc_md.progress("openpic: ipi",0x3bb); 371 if ( ppc_md.progress ) ppc_md.progress("openpic: ipi",0x3bb);
372 for (i = 0; i < OPENPIC_NUM_IPI; i++) { 372 for (i = 0; i < OPENPIC_NUM_IPI; i++) {
373 /* Disabled, Priority 10..13 */ 373 /* Disabled, increased priorities 10..13 */
374 openpic_initipi(i, 10+i, OPENPIC_VEC_IPI+i+offset); 374 openpic_initipi(i, OPENPIC_PRIORITY_IPI_BASE+i,
375 OPENPIC_VEC_IPI+i+offset);
375 /* IPIs are per-CPU */ 376 /* IPIs are per-CPU */
376 irq_desc[OPENPIC_VEC_IPI+i+offset].status |= IRQ_PER_CPU; 377 irq_desc[OPENPIC_VEC_IPI+i+offset].status |= IRQ_PER_CPU;
377 irq_desc[OPENPIC_VEC_IPI+i+offset].handler = &open_pic_ipi; 378 irq_desc[OPENPIC_VEC_IPI+i+offset].handler = &open_pic_ipi;
@@ -399,8 +400,9 @@ void __init openpic_init(int offset)
399 if (sense & IRQ_SENSE_MASK) 400 if (sense & IRQ_SENSE_MASK)
400 irq_desc[i+offset].status = IRQ_LEVEL; 401 irq_desc[i+offset].status = IRQ_LEVEL;
401 402
402 /* Enabled, Priority 8 */ 403 /* Enabled, Default priority */
403 openpic_initirq(i, 8, i+offset, (sense & IRQ_POLARITY_MASK), 404 openpic_initirq(i, OPENPIC_PRIORITY_DEFAULT, i+offset,
405 (sense & IRQ_POLARITY_MASK),
404 (sense & IRQ_SENSE_MASK)); 406 (sense & IRQ_SENSE_MASK));
405 /* Processor 0 */ 407 /* Processor 0 */
406 openpic_mapirq(i, CPU_MASK_CPU0, CPU_MASK_NONE); 408 openpic_mapirq(i, CPU_MASK_CPU0, CPU_MASK_NONE);
@@ -656,6 +658,18 @@ static void __init openpic_maptimer(u_int timer, cpumask_t cpumask)
656} 658}
657 659
658/* 660/*
661 * Change the priority of an interrupt
662 */
663void __init
664openpic_set_irq_priority(u_int irq, u_int pri)
665{
666 check_arg_irq(irq);
667 openpic_safe_writefield(&ISR[irq - open_pic_irq_offset]->Vector_Priority,
668 OPENPIC_PRIORITY_MASK,
669 pri << OPENPIC_PRIORITY_SHIFT);
670}
671
672/*
659 * Initalize the interrupt source which will generate an NMI. 673 * Initalize the interrupt source which will generate an NMI.
660 * This raises the interrupt's priority from 8 to 9. 674 * This raises the interrupt's priority from 8 to 9.
661 * 675 *
@@ -665,9 +679,7 @@ void __init
665openpic_init_nmi_irq(u_int irq) 679openpic_init_nmi_irq(u_int irq)
666{ 680{
667 check_arg_irq(irq); 681 check_arg_irq(irq);
668 openpic_safe_writefield(&ISR[irq - open_pic_irq_offset]->Vector_Priority, 682 openpic_set_irq_priority(irq, OPENPIC_PRIORITY_NMI);
669 OPENPIC_PRIORITY_MASK,
670 9 << OPENPIC_PRIORITY_SHIFT);
671} 683}
672 684
673/* 685/*
diff --git a/arch/ppc64/kernel/irq.c b/arch/ppc64/kernel/irq.c
index 3defc8c33adf..ffe300611f00 100644
--- a/arch/ppc64/kernel/irq.c
+++ b/arch/ppc64/kernel/irq.c
@@ -245,7 +245,7 @@ void ppc_irq_dispatch_handler(struct pt_regs *regs, int irq)
245 245
246 spin_lock(&desc->lock); 246 spin_lock(&desc->lock);
247 if (!noirqdebug) 247 if (!noirqdebug)
248 note_interrupt(irq, desc, action_ret); 248 note_interrupt(irq, desc, action_ret, regs);
249 if (likely(!(desc->status & IRQ_PENDING))) 249 if (likely(!(desc->status & IRQ_PENDING)))
250 break; 250 break;
251 desc->status &= ~IRQ_PENDING; 251 desc->status &= ~IRQ_PENDING;
diff --git a/arch/ppc64/kernel/kprobes.c b/arch/ppc64/kernel/kprobes.c
index 782ce3efa2c1..1d2ff6d6b0b3 100644
--- a/arch/ppc64/kernel/kprobes.c
+++ b/arch/ppc64/kernel/kprobes.c
@@ -36,6 +36,8 @@
36#include <asm/kdebug.h> 36#include <asm/kdebug.h>
37#include <asm/sstep.h> 37#include <asm/sstep.h>
38 38
39static DECLARE_MUTEX(kprobe_mutex);
40
39static struct kprobe *current_kprobe; 41static struct kprobe *current_kprobe;
40static unsigned long kprobe_status, kprobe_saved_msr; 42static unsigned long kprobe_status, kprobe_saved_msr;
41static struct kprobe *kprobe_prev; 43static struct kprobe *kprobe_prev;
@@ -54,6 +56,15 @@ int arch_prepare_kprobe(struct kprobe *p)
54 printk("Cannot register a kprobe on rfid or mtmsrd\n"); 56 printk("Cannot register a kprobe on rfid or mtmsrd\n");
55 ret = -EINVAL; 57 ret = -EINVAL;
56 } 58 }
59
60 /* insn must be on a special executable page on ppc64 */
61 if (!ret) {
62 up(&kprobe_mutex);
63 p->ainsn.insn = get_insn_slot();
64 down(&kprobe_mutex);
65 if (!p->ainsn.insn)
66 ret = -ENOMEM;
67 }
57 return ret; 68 return ret;
58} 69}
59 70
@@ -79,16 +90,22 @@ void arch_disarm_kprobe(struct kprobe *p)
79 90
80void arch_remove_kprobe(struct kprobe *p) 91void arch_remove_kprobe(struct kprobe *p)
81{ 92{
93 up(&kprobe_mutex);
94 free_insn_slot(p->ainsn.insn);
95 down(&kprobe_mutex);
82} 96}
83 97
84static inline void prepare_singlestep(struct kprobe *p, struct pt_regs *regs) 98static inline void prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
85{ 99{
100 kprobe_opcode_t insn = *p->ainsn.insn;
101
86 regs->msr |= MSR_SE; 102 regs->msr |= MSR_SE;
87 /*single step inline if it a breakpoint instruction*/ 103
88 if (p->opcode == BREAKPOINT_INSTRUCTION) 104 /* single step inline if it is a trap variant */
105 if (IS_TW(insn) || IS_TD(insn) || IS_TWI(insn) || IS_TDI(insn))
89 regs->nip = (unsigned long)p->addr; 106 regs->nip = (unsigned long)p->addr;
90 else 107 else
91 regs->nip = (unsigned long)&p->ainsn.insn; 108 regs->nip = (unsigned long)p->ainsn.insn;
92} 109}
93 110
94static inline void save_previous_kprobe(void) 111static inline void save_previous_kprobe(void)
@@ -105,6 +122,23 @@ static inline void restore_previous_kprobe(void)
105 kprobe_saved_msr = kprobe_saved_msr_prev; 122 kprobe_saved_msr = kprobe_saved_msr_prev;
106} 123}
107 124
125void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs)
126{
127 struct kretprobe_instance *ri;
128
129 if ((ri = get_free_rp_inst(rp)) != NULL) {
130 ri->rp = rp;
131 ri->task = current;
132 ri->ret_addr = (kprobe_opcode_t *)regs->link;
133
134 /* Replace the return addr with trampoline addr */
135 regs->link = (unsigned long)kretprobe_trampoline;
136 add_rp_inst(ri);
137 } else {
138 rp->nmissed++;
139 }
140}
141
108static inline int kprobe_handler(struct pt_regs *regs) 142static inline int kprobe_handler(struct pt_regs *regs)
109{ 143{
110 struct kprobe *p; 144 struct kprobe *p;
@@ -195,6 +229,78 @@ no_kprobe:
195} 229}
196 230
197/* 231/*
232 * Function return probe trampoline:
233 * - init_kprobes() establishes a probepoint here
234 * - When the probed function returns, this probe
235 * causes the handlers to fire
236 */
237void kretprobe_trampoline_holder(void)
238{
239 asm volatile(".global kretprobe_trampoline\n"
240 "kretprobe_trampoline:\n"
241 "nop\n");
242}
243
244/*
245 * Called when the probe at kretprobe trampoline is hit
246 */
247int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
248{
249 struct kretprobe_instance *ri = NULL;
250 struct hlist_head *head;
251 struct hlist_node *node, *tmp;
252 unsigned long orig_ret_address = 0;
253 unsigned long trampoline_address =(unsigned long)&kretprobe_trampoline;
254
255 head = kretprobe_inst_table_head(current);
256
257 /*
258 * It is possible to have multiple instances associated with a given
259 * task either because an multiple functions in the call path
260 * have a return probe installed on them, and/or more then one return
261 * return probe was registered for a target function.
262 *
263 * We can handle this because:
264 * - instances are always inserted at the head of the list
265 * - when multiple return probes are registered for the same
266 * function, the first instance's ret_addr will point to the
267 * real return address, and all the rest will point to
268 * kretprobe_trampoline
269 */
270 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
271 if (ri->task != current)
272 /* another task is sharing our hash bucket */
273 continue;
274
275 if (ri->rp && ri->rp->handler)
276 ri->rp->handler(ri, regs);
277
278 orig_ret_address = (unsigned long)ri->ret_addr;
279 recycle_rp_inst(ri);
280
281 if (orig_ret_address != trampoline_address)
282 /*
283 * This is the real return address. Any other
284 * instances associated with this task are for
285 * other calls deeper on the call stack
286 */
287 break;
288 }
289
290 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
291 regs->nip = orig_ret_address;
292
293 unlock_kprobes();
294
295 /*
296 * By returning a non-zero value, we are telling
297 * kprobe_handler() that we have handled unlocking
298 * and re-enabling preemption.
299 */
300 return 1;
301}
302
303/*
198 * Called after single-stepping. p->addr is the address of the 304 * Called after single-stepping. p->addr is the address of the
199 * instruction whose first byte has been replaced by the "breakpoint" 305 * instruction whose first byte has been replaced by the "breakpoint"
200 * instruction. To avoid the SMP problems that can occur when we 306 * instruction. To avoid the SMP problems that can occur when we
@@ -205,9 +311,10 @@ no_kprobe:
205static void resume_execution(struct kprobe *p, struct pt_regs *regs) 311static void resume_execution(struct kprobe *p, struct pt_regs *regs)
206{ 312{
207 int ret; 313 int ret;
314 unsigned int insn = *p->ainsn.insn;
208 315
209 regs->nip = (unsigned long)p->addr; 316 regs->nip = (unsigned long)p->addr;
210 ret = emulate_step(regs, p->ainsn.insn[0]); 317 ret = emulate_step(regs, insn);
211 if (ret == 0) 318 if (ret == 0)
212 regs->nip = (unsigned long)p->addr + 4; 319 regs->nip = (unsigned long)p->addr + 4;
213} 320}
@@ -331,3 +438,13 @@ int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
331 memcpy(regs, &jprobe_saved_regs, sizeof(struct pt_regs)); 438 memcpy(regs, &jprobe_saved_regs, sizeof(struct pt_regs));
332 return 1; 439 return 1;
333} 440}
441
442static struct kprobe trampoline_p = {
443 .addr = (kprobe_opcode_t *) &kretprobe_trampoline,
444 .pre_handler = trampoline_probe_handler
445};
446
447int __init arch_init(void)
448{
449 return register_kprobe(&trampoline_p);
450}
diff --git a/arch/ppc64/kernel/pci.c b/arch/ppc64/kernel/pci.c
index 580676f87d23..ae6f579d3fa0 100644
--- a/arch/ppc64/kernel/pci.c
+++ b/arch/ppc64/kernel/pci.c
@@ -351,7 +351,7 @@ static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
351 *offset += hose->pci_mem_offset; 351 *offset += hose->pci_mem_offset;
352 res_bit = IORESOURCE_MEM; 352 res_bit = IORESOURCE_MEM;
353 } else { 353 } else {
354 io_offset = (unsigned long)hose->io_base_virt; 354 io_offset = (unsigned long)hose->io_base_virt - pci_io_base;
355 *offset += io_offset; 355 *offset += io_offset;
356 res_bit = IORESOURCE_IO; 356 res_bit = IORESOURCE_IO;
357 } 357 }
@@ -378,7 +378,7 @@ static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
378 378
379 /* found it! construct the final physical address */ 379 /* found it! construct the final physical address */
380 if (mmap_state == pci_mmap_io) 380 if (mmap_state == pci_mmap_io)
381 *offset += hose->io_base_phys - io_offset; 381 *offset += hose->io_base_phys - io_offset;
382 return rp; 382 return rp;
383 } 383 }
384 384
@@ -944,4 +944,22 @@ int pci_read_irq_line(struct pci_dev *pci_dev)
944} 944}
945EXPORT_SYMBOL(pci_read_irq_line); 945EXPORT_SYMBOL(pci_read_irq_line);
946 946
947void pci_resource_to_user(const struct pci_dev *dev, int bar,
948 const struct resource *rsrc,
949 u64 *start, u64 *end)
950{
951 struct pci_controller *hose = pci_bus_to_host(dev->bus);
952 unsigned long offset = 0;
953
954 if (hose == NULL)
955 return;
956
957 if (rsrc->flags & IORESOURCE_IO)
958 offset = pci_io_base - (unsigned long)hose->io_base_virt +
959 hose->io_base_phys;
960
961 *start = rsrc->start + offset;
962 *end = rsrc->end + offset;
963}
964
947#endif /* CONFIG_PPC_MULTIPLATFORM */ 965#endif /* CONFIG_PPC_MULTIPLATFORM */
diff --git a/arch/ppc64/kernel/ppc_ksyms.c b/arch/ppc64/kernel/ppc_ksyms.c
index b230a63fe4c8..705742f4eec6 100644
--- a/arch/ppc64/kernel/ppc_ksyms.c
+++ b/arch/ppc64/kernel/ppc_ksyms.c
@@ -75,6 +75,7 @@ EXPORT_SYMBOL(giveup_fpu);
75EXPORT_SYMBOL(giveup_altivec); 75EXPORT_SYMBOL(giveup_altivec);
76#endif 76#endif
77EXPORT_SYMBOL(__flush_icache_range); 77EXPORT_SYMBOL(__flush_icache_range);
78EXPORT_SYMBOL(flush_dcache_range);
78 79
79#ifdef CONFIG_SMP 80#ifdef CONFIG_SMP
80#ifdef CONFIG_PPC_ISERIES 81#ifdef CONFIG_PPC_ISERIES
diff --git a/arch/ppc64/kernel/process.c b/arch/ppc64/kernel/process.c
index aba89554d89d..f7cae05e40fb 100644
--- a/arch/ppc64/kernel/process.c
+++ b/arch/ppc64/kernel/process.c
@@ -36,6 +36,7 @@
36#include <linux/kallsyms.h> 36#include <linux/kallsyms.h>
37#include <linux/interrupt.h> 37#include <linux/interrupt.h>
38#include <linux/utsname.h> 38#include <linux/utsname.h>
39#include <linux/kprobes.h>
39 40
40#include <asm/pgtable.h> 41#include <asm/pgtable.h>
41#include <asm/uaccess.h> 42#include <asm/uaccess.h>
@@ -307,6 +308,8 @@ void show_regs(struct pt_regs * regs)
307 308
308void exit_thread(void) 309void exit_thread(void)
309{ 310{
311 kprobe_flush_task(current);
312
310#ifndef CONFIG_SMP 313#ifndef CONFIG_SMP
311 if (last_task_used_math == current) 314 if (last_task_used_math == current)
312 last_task_used_math = NULL; 315 last_task_used_math = NULL;
@@ -321,6 +324,7 @@ void flush_thread(void)
321{ 324{
322 struct thread_info *t = current_thread_info(); 325 struct thread_info *t = current_thread_info();
323 326
327 kprobe_flush_task(current);
324 if (t->flags & _TIF_ABI_PENDING) 328 if (t->flags & _TIF_ABI_PENDING)
325 t->flags ^= (_TIF_ABI_PENDING | _TIF_32BIT); 329 t->flags ^= (_TIF_ABI_PENDING | _TIF_32BIT);
326 330
diff --git a/arch/ppc64/kernel/time.c b/arch/ppc64/kernel/time.c
index 2348a75e050d..2a532db9138a 100644
--- a/arch/ppc64/kernel/time.c
+++ b/arch/ppc64/kernel/time.c
@@ -91,6 +91,7 @@ unsigned long tb_to_xs;
91unsigned tb_to_us; 91unsigned tb_to_us;
92unsigned long processor_freq; 92unsigned long processor_freq;
93DEFINE_SPINLOCK(rtc_lock); 93DEFINE_SPINLOCK(rtc_lock);
94EXPORT_SYMBOL_GPL(rtc_lock);
94 95
95unsigned long tb_to_ns_scale; 96unsigned long tb_to_ns_scale;
96unsigned long tb_to_ns_shift; 97unsigned long tb_to_ns_shift;
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 262e13d086fe..7a117ef473c5 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -270,66 +270,10 @@ endmenu
270 270
271source "drivers/Kconfig" 271source "drivers/Kconfig"
272 272
273config PRINTER
274 tristate "Parallel printer support"
275 depends on PARPORT
276 ---help---
277 If you intend to attach a printer to the parallel port of your Linux
278 box (as opposed to using a serial printer; if the connector at the
279 printer has 9 or 25 holes ["female"], then it's serial), say Y.
280 Also read the Printing-HOWTO, available from
281 <http://www.tldp.org/docs.html#howto>.
282
283 It is possible to share one parallel port among several devices
284 (e.g. printer and ZIP drive) and it is safe to compile the
285 corresponding drivers into the kernel. If you want to compile this
286 driver as a module however, choose M here and read
287 <file:Documentation/parport.txt>. The module will be called lp.
288
289 If you have several parallel ports, you can specify which ports to
290 use with the "lp" kernel command line option. (Try "man bootparam"
291 or see the documentation of your boot loader (silo) about how to pass
292 options to the kernel at boot time.) The syntax of the "lp" command
293 line option can be found in <file:drivers/char/lp.c>.
294
295 If you have more than 8 printers, you need to increase the LP_NO
296 macro in lp.c and the PARPORT_MAX macro in parport.h.
297
298source "mm/Kconfig"
299
300endmenu
301
302source "drivers/base/Kconfig"
303
304source "drivers/video/Kconfig"
305
306source "drivers/mtd/Kconfig"
307
308source "drivers/serial/Kconfig"
309
310if !SUN4 273if !SUN4
311source "drivers/sbus/char/Kconfig" 274source "drivers/sbus/char/Kconfig"
312endif 275endif
313 276
314source "drivers/block/Kconfig"
315
316# Don't frighten a common SBus user
317if PCI
318
319source "drivers/ide/Kconfig"
320
321endif
322
323source "drivers/isdn/Kconfig"
324
325source "drivers/scsi/Kconfig"
326
327source "drivers/fc4/Kconfig"
328
329source "drivers/md/Kconfig"
330
331source "net/Kconfig"
332
333# This one must be before the filesystem configs. -DaveM 277# This one must be before the filesystem configs. -DaveM
334 278
335menu "Unix98 PTY support" 279menu "Unix98 PTY support"
diff --git a/arch/sparc64/kernel/auxio.c b/arch/sparc64/kernel/auxio.c
index a0716ccc2f4a..8852c20c8d99 100644
--- a/arch/sparc64/kernel/auxio.c
+++ b/arch/sparc64/kernel/auxio.c
@@ -16,7 +16,7 @@
16#include <asm/ebus.h> 16#include <asm/ebus.h>
17#include <asm/auxio.h> 17#include <asm/auxio.h>
18 18
19/* This cannot be static, as it is referenced in entry.S */ 19/* This cannot be static, as it is referenced in irq.c */
20void __iomem *auxio_register = NULL; 20void __iomem *auxio_register = NULL;
21 21
22enum auxio_type { 22enum auxio_type {
diff --git a/arch/sparc64/kernel/entry.S b/arch/sparc64/kernel/entry.S
index a47f2d0b1a29..eee516a71c14 100644
--- a/arch/sparc64/kernel/entry.S
+++ b/arch/sparc64/kernel/entry.S
@@ -271,8 +271,9 @@ cplus_fptrap_insn_1:
271 fmuld %f0, %f2, %f26 271 fmuld %f0, %f2, %f26
272 faddd %f0, %f2, %f28 272 faddd %f0, %f2, %f28
273 fmuld %f0, %f2, %f30 273 fmuld %f0, %f2, %f30
274 membar #Sync
274 b,pt %xcc, fpdis_exit 275 b,pt %xcc, fpdis_exit
275 membar #Sync 276 nop
2762: andcc %g5, FPRS_DU, %g0 2772: andcc %g5, FPRS_DU, %g0
277 bne,pt %icc, 3f 278 bne,pt %icc, 3f
278 fzero %f32 279 fzero %f32
@@ -301,8 +302,9 @@ cplus_fptrap_insn_2:
301 fmuld %f32, %f34, %f58 302 fmuld %f32, %f34, %f58
302 faddd %f32, %f34, %f60 303 faddd %f32, %f34, %f60
303 fmuld %f32, %f34, %f62 304 fmuld %f32, %f34, %f62
305 membar #Sync
304 ba,pt %xcc, fpdis_exit 306 ba,pt %xcc, fpdis_exit
305 membar #Sync 307 nop
3063: mov SECONDARY_CONTEXT, %g3 3083: mov SECONDARY_CONTEXT, %g3
307 add %g6, TI_FPREGS, %g1 309 add %g6, TI_FPREGS, %g1
308 ldxa [%g3] ASI_DMMU, %g5 310 ldxa [%g3] ASI_DMMU, %g5
@@ -699,116 +701,6 @@ utrap_ill:
699 ba,pt %xcc, rtrap 701 ba,pt %xcc, rtrap
700 clr %l6 702 clr %l6
701 703
702#ifdef CONFIG_BLK_DEV_FD
703 .globl floppy_hardint
704floppy_hardint:
705 wr %g0, (1 << 11), %clear_softint
706 sethi %hi(doing_pdma), %g1
707 ld [%g1 + %lo(doing_pdma)], %g2
708 brz,pn %g2, floppy_dosoftint
709 sethi %hi(fdc_status), %g3
710 ldx [%g3 + %lo(fdc_status)], %g3
711 sethi %hi(pdma_vaddr), %g5
712 ldx [%g5 + %lo(pdma_vaddr)], %g4
713 sethi %hi(pdma_size), %g5
714 ldx [%g5 + %lo(pdma_size)], %g5
715
716next_byte:
717 lduba [%g3] ASI_PHYS_BYPASS_EC_E, %g7
718 andcc %g7, 0x80, %g0
719 be,pn %icc, floppy_fifo_emptied
720 andcc %g7, 0x20, %g0
721 be,pn %icc, floppy_overrun
722 andcc %g7, 0x40, %g0
723 be,pn %icc, floppy_write
724 sub %g5, 1, %g5
725
726 inc %g3
727 lduba [%g3] ASI_PHYS_BYPASS_EC_E, %g7
728 dec %g3
729 orcc %g0, %g5, %g0
730 stb %g7, [%g4]
731 bne,pn %xcc, next_byte
732 add %g4, 1, %g4
733
734 b,pt %xcc, floppy_tdone
735 nop
736
737floppy_write:
738 ldub [%g4], %g7
739 orcc %g0, %g5, %g0
740 inc %g3
741 stba %g7, [%g3] ASI_PHYS_BYPASS_EC_E
742 dec %g3
743 bne,pn %xcc, next_byte
744 add %g4, 1, %g4
745
746floppy_tdone:
747 sethi %hi(pdma_vaddr), %g1
748 stx %g4, [%g1 + %lo(pdma_vaddr)]
749 sethi %hi(pdma_size), %g1
750 stx %g5, [%g1 + %lo(pdma_size)]
751 sethi %hi(auxio_register), %g1
752 ldx [%g1 + %lo(auxio_register)], %g7
753 lduba [%g7] ASI_PHYS_BYPASS_EC_E, %g5
754 or %g5, AUXIO_AUX1_FTCNT, %g5
755/* andn %g5, AUXIO_AUX1_MASK, %g5 */
756 stba %g5, [%g7] ASI_PHYS_BYPASS_EC_E
757 andn %g5, AUXIO_AUX1_FTCNT, %g5
758/* andn %g5, AUXIO_AUX1_MASK, %g5 */
759
760 nop; nop; nop; nop; nop; nop;
761 nop; nop; nop; nop; nop; nop;
762
763 stba %g5, [%g7] ASI_PHYS_BYPASS_EC_E
764 sethi %hi(doing_pdma), %g1
765 b,pt %xcc, floppy_dosoftint
766 st %g0, [%g1 + %lo(doing_pdma)]
767
768floppy_fifo_emptied:
769 sethi %hi(pdma_vaddr), %g1
770 stx %g4, [%g1 + %lo(pdma_vaddr)]
771 sethi %hi(pdma_size), %g1
772 stx %g5, [%g1 + %lo(pdma_size)]
773 sethi %hi(irq_action), %g1
774 or %g1, %lo(irq_action), %g1
775 ldx [%g1 + (11 << 3)], %g3 ! irqaction[floppy_irq]
776 ldx [%g3 + 0x08], %g4 ! action->flags>>48==ino
777 sethi %hi(ivector_table), %g3
778 srlx %g4, 48, %g4
779 or %g3, %lo(ivector_table), %g3
780 sllx %g4, 5, %g4
781 ldx [%g3 + %g4], %g4 ! &ivector_table[ino]
782 ldx [%g4 + 0x10], %g4 ! bucket->iclr
783 stwa %g0, [%g4] ASI_PHYS_BYPASS_EC_E ! ICLR_IDLE
784 membar #Sync ! probably not needed...
785 retry
786
787floppy_overrun:
788 sethi %hi(pdma_vaddr), %g1
789 stx %g4, [%g1 + %lo(pdma_vaddr)]
790 sethi %hi(pdma_size), %g1
791 stx %g5, [%g1 + %lo(pdma_size)]
792 sethi %hi(doing_pdma), %g1
793 st %g0, [%g1 + %lo(doing_pdma)]
794
795floppy_dosoftint:
796 rdpr %pil, %g2
797 wrpr %g0, 15, %pil
798 sethi %hi(109f), %g7
799 b,pt %xcc, etrap_irq
800109: or %g7, %lo(109b), %g7
801
802 mov 11, %o0
803 mov 0, %o1
804 call sparc_floppy_irq
805 add %sp, PTREGS_OFF, %o2
806
807 b,pt %xcc, rtrap_irq
808 nop
809
810#endif /* CONFIG_BLK_DEV_FD */
811
812 /* XXX Here is stuff we still need to write... -DaveM XXX */ 704 /* XXX Here is stuff we still need to write... -DaveM XXX */
813 .globl netbsd_syscall 705 .globl netbsd_syscall
814netbsd_syscall: 706netbsd_syscall:
diff --git a/arch/sparc64/kernel/irq.c b/arch/sparc64/kernel/irq.c
index 4dcb8af94090..424712577307 100644
--- a/arch/sparc64/kernel/irq.c
+++ b/arch/sparc64/kernel/irq.c
@@ -37,6 +37,7 @@
37#include <asm/uaccess.h> 37#include <asm/uaccess.h>
38#include <asm/cache.h> 38#include <asm/cache.h>
39#include <asm/cpudata.h> 39#include <asm/cpudata.h>
40#include <asm/auxio.h>
40 41
41#ifdef CONFIG_SMP 42#ifdef CONFIG_SMP
42static void distribute_irqs(void); 43static void distribute_irqs(void);
@@ -834,137 +835,65 @@ void handler_irq(int irq, struct pt_regs *regs)
834} 835}
835 836
836#ifdef CONFIG_BLK_DEV_FD 837#ifdef CONFIG_BLK_DEV_FD
837extern void floppy_interrupt(int irq, void *dev_cookie, struct pt_regs *regs); 838extern irqreturn_t floppy_interrupt(int, void *, struct pt_regs *);;
838 839
839void sparc_floppy_irq(int irq, void *dev_cookie, struct pt_regs *regs) 840/* XXX No easy way to include asm/floppy.h XXX */
840{ 841extern unsigned char *pdma_vaddr;
841 struct irqaction *action = *(irq + irq_action); 842extern unsigned long pdma_size;
842 struct ino_bucket *bucket; 843extern volatile int doing_pdma;
843 int cpu = smp_processor_id(); 844extern unsigned long fdc_status;
844
845 irq_enter();
846 kstat_this_cpu.irqs[irq]++;
847
848 *(irq_work(cpu, irq)) = 0;
849 bucket = get_ino_in_irqaction(action) + ivector_table;
850
851 bucket->flags |= IBF_INPROGRESS;
852
853 floppy_interrupt(irq, dev_cookie, regs);
854 upa_writel(ICLR_IDLE, bucket->iclr);
855
856 bucket->flags &= ~IBF_INPROGRESS;
857
858 irq_exit();
859}
860#endif
861
862/* The following assumes that the branch lies before the place we
863 * are branching to. This is the case for a trap vector...
864 * You have been warned.
865 */
866#define SPARC_BRANCH(dest_addr, inst_addr) \
867 (0x10800000 | ((((dest_addr)-(inst_addr))>>2)&0x3fffff))
868
869#define SPARC_NOP (0x01000000)
870 845
871static void install_fast_irq(unsigned int cpu_irq, 846irqreturn_t sparc_floppy_irq(int irq, void *dev_cookie, struct pt_regs *regs)
872 irqreturn_t (*handler)(int, void *, struct pt_regs *))
873{ 847{
874 extern unsigned long sparc64_ttable_tl0; 848 if (likely(doing_pdma)) {
875 unsigned long ttent = (unsigned long) &sparc64_ttable_tl0; 849 void __iomem *stat = (void __iomem *) fdc_status;
876 unsigned int *insns; 850 unsigned char *vaddr = pdma_vaddr;
877 851 unsigned long size = pdma_size;
878 ttent += 0x820; 852 u8 val;
879 ttent += (cpu_irq - 1) << 5; 853
880 insns = (unsigned int *) ttent; 854 while (size) {
881 insns[0] = SPARC_BRANCH(((unsigned long) handler), 855 val = readb(stat);
882 ((unsigned long)&insns[0])); 856 if (unlikely(!(val & 0x80))) {
883 insns[1] = SPARC_NOP; 857 pdma_vaddr = vaddr;
884 __asm__ __volatile__("membar #StoreStore; flush %0" : : "r" (ttent)); 858 pdma_size = size;
885} 859 return IRQ_HANDLED;
886 860 }
887int request_fast_irq(unsigned int irq, 861 if (unlikely(!(val & 0x20))) {
888 irqreturn_t (*handler)(int, void *, struct pt_regs *), 862 pdma_vaddr = vaddr;
889 unsigned long irqflags, const char *name, void *dev_id) 863 pdma_size = size;
890{ 864 doing_pdma = 0;
891 struct irqaction *action; 865 goto main_interrupt;
892 struct ino_bucket *bucket = __bucket(irq); 866 }
893 unsigned long flags; 867 if (val & 0x40) {
894 868 /* read */
895 /* No pil0 dummy buckets allowed here. */ 869 *vaddr++ = readb(stat + 1);
896 if (bucket < &ivector_table[0] || 870 } else {
897 bucket >= &ivector_table[NUM_IVECS]) { 871 unsigned char data = *vaddr++;
898 unsigned int *caller;
899
900 __asm__ __volatile__("mov %%i7, %0" : "=r" (caller));
901 printk(KERN_CRIT "request_fast_irq: Old style IRQ registry attempt "
902 "from %p, irq %08x.\n", caller, irq);
903 return -EINVAL;
904 }
905
906 if (!handler)
907 return -EINVAL;
908 872
909 if ((bucket->pil == 0) || (bucket->pil == 14)) { 873 /* write */
910 printk("request_fast_irq: Trying to register shared IRQ 0 or 14.\n"); 874 writeb(data, stat + 1);
911 return -EBUSY; 875 }
912 } 876 size--;
877 }
913 878
914 spin_lock_irqsave(&irq_action_lock, flags); 879 pdma_vaddr = vaddr;
880 pdma_size = size;
915 881
916 action = *(bucket->pil + irq_action); 882 /* Send Terminal Count pulse to floppy controller. */
917 if (action) { 883 val = readb(auxio_register);
918 if (action->flags & SA_SHIRQ) 884 val |= AUXIO_AUX1_FTCNT;
919 panic("Trying to register fast irq when already shared.\n"); 885 writeb(val, auxio_register);
920 if (irqflags & SA_SHIRQ) 886 val &= AUXIO_AUX1_FTCNT;
921 panic("Trying to register fast irq as shared.\n"); 887 writeb(val, auxio_register);
922 printk("request_fast_irq: Trying to register yet already owned.\n");
923 spin_unlock_irqrestore(&irq_action_lock, flags);
924 return -EBUSY;
925 }
926 888
927 /* 889 doing_pdma = 0;
928 * We do not check for SA_SAMPLE_RANDOM in this path. Neither do we
929 * support smp intr affinity in this path.
930 */
931 if (irqflags & SA_STATIC_ALLOC) {
932 if (static_irq_count < MAX_STATIC_ALLOC)
933 action = &static_irqaction[static_irq_count++];
934 else
935 printk("Request for IRQ%d (%s) SA_STATIC_ALLOC failed "
936 "using kmalloc\n", bucket->pil, name);
937 }
938 if (action == NULL)
939 action = (struct irqaction *)kmalloc(sizeof(struct irqaction),
940 GFP_ATOMIC);
941 if (!action) {
942 spin_unlock_irqrestore(&irq_action_lock, flags);
943 return -ENOMEM;
944 } 890 }
945 install_fast_irq(bucket->pil, handler);
946 891
947 bucket->irq_info = action; 892main_interrupt:
948 bucket->flags |= IBF_ACTIVE; 893 return floppy_interrupt(irq, dev_cookie, regs);
949
950 action->handler = handler;
951 action->flags = irqflags;
952 action->dev_id = NULL;
953 action->name = name;
954 action->next = NULL;
955 put_ino_in_irqaction(action, irq);
956 put_smpaff_in_irqaction(action, CPU_MASK_NONE);
957
958 *(bucket->pil + irq_action) = action;
959 enable_irq(irq);
960
961 spin_unlock_irqrestore(&irq_action_lock, flags);
962
963#ifdef CONFIG_SMP
964 distribute_irqs();
965#endif
966 return 0;
967} 894}
895EXPORT_SYMBOL(sparc_floppy_irq);
896#endif
968 897
969/* We really don't need these at all on the Sparc. We only have 898/* We really don't need these at all on the Sparc. We only have
970 * stubs here because they are exported to modules. 899 * stubs here because they are exported to modules.
diff --git a/arch/sparc64/kernel/semaphore.c b/arch/sparc64/kernel/semaphore.c
index 63496c43fe17..a809e63f03ef 100644
--- a/arch/sparc64/kernel/semaphore.c
+++ b/arch/sparc64/kernel/semaphore.c
@@ -32,8 +32,9 @@ static __inline__ int __sem_update_count(struct semaphore *sem, int incr)
32" add %1, %4, %1\n" 32" add %1, %4, %1\n"
33" cas [%3], %0, %1\n" 33" cas [%3], %0, %1\n"
34" cmp %0, %1\n" 34" cmp %0, %1\n"
35" membar #StoreLoad | #StoreStore\n"
35" bne,pn %%icc, 1b\n" 36" bne,pn %%icc, 1b\n"
36" membar #StoreLoad | #StoreStore\n" 37" nop\n"
37 : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count) 38 : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count)
38 : "r" (&sem->count), "r" (incr), "m" (sem->count) 39 : "r" (&sem->count), "r" (incr), "m" (sem->count)
39 : "cc"); 40 : "cc");
@@ -71,8 +72,9 @@ void up(struct semaphore *sem)
71" cmp %%g1, %%g7\n" 72" cmp %%g1, %%g7\n"
72" bne,pn %%icc, 1b\n" 73" bne,pn %%icc, 1b\n"
73" addcc %%g7, 1, %%g0\n" 74" addcc %%g7, 1, %%g0\n"
75" membar #StoreLoad | #StoreStore\n"
74" ble,pn %%icc, 3f\n" 76" ble,pn %%icc, 3f\n"
75" membar #StoreLoad | #StoreStore\n" 77" nop\n"
76"2:\n" 78"2:\n"
77" .subsection 2\n" 79" .subsection 2\n"
78"3: mov %0, %%g1\n" 80"3: mov %0, %%g1\n"
@@ -128,8 +130,9 @@ void __sched down(struct semaphore *sem)
128" cmp %%g1, %%g7\n" 130" cmp %%g1, %%g7\n"
129" bne,pn %%icc, 1b\n" 131" bne,pn %%icc, 1b\n"
130" cmp %%g7, 1\n" 132" cmp %%g7, 1\n"
133" membar #StoreLoad | #StoreStore\n"
131" bl,pn %%icc, 3f\n" 134" bl,pn %%icc, 3f\n"
132" membar #StoreLoad | #StoreStore\n" 135" nop\n"
133"2:\n" 136"2:\n"
134" .subsection 2\n" 137" .subsection 2\n"
135"3: mov %0, %%g1\n" 138"3: mov %0, %%g1\n"
@@ -233,8 +236,9 @@ int __sched down_interruptible(struct semaphore *sem)
233" cmp %%g1, %%g7\n" 236" cmp %%g1, %%g7\n"
234" bne,pn %%icc, 1b\n" 237" bne,pn %%icc, 1b\n"
235" cmp %%g7, 1\n" 238" cmp %%g7, 1\n"
239" membar #StoreLoad | #StoreStore\n"
236" bl,pn %%icc, 3f\n" 240" bl,pn %%icc, 3f\n"
237" membar #StoreLoad | #StoreStore\n" 241" nop\n"
238"2:\n" 242"2:\n"
239" .subsection 2\n" 243" .subsection 2\n"
240"3: mov %2, %%g1\n" 244"3: mov %2, %%g1\n"
diff --git a/arch/sparc64/kernel/sparc64_ksyms.c b/arch/sparc64/kernel/sparc64_ksyms.c
index e78cc53594fa..56cd96f4a5cd 100644
--- a/arch/sparc64/kernel/sparc64_ksyms.c
+++ b/arch/sparc64/kernel/sparc64_ksyms.c
@@ -227,7 +227,6 @@ EXPORT_SYMBOL(__flush_dcache_range);
227 227
228EXPORT_SYMBOL(mostek_lock); 228EXPORT_SYMBOL(mostek_lock);
229EXPORT_SYMBOL(mstk48t02_regs); 229EXPORT_SYMBOL(mstk48t02_regs);
230EXPORT_SYMBOL(request_fast_irq);
231#ifdef CONFIG_SUN_AUXIO 230#ifdef CONFIG_SUN_AUXIO
232EXPORT_SYMBOL(auxio_set_led); 231EXPORT_SYMBOL(auxio_set_led);
233EXPORT_SYMBOL(auxio_set_lte); 232EXPORT_SYMBOL(auxio_set_lte);
diff --git a/arch/sparc64/kernel/trampoline.S b/arch/sparc64/kernel/trampoline.S
index 2c8f9344b4ee..3a145fc39cf2 100644
--- a/arch/sparc64/kernel/trampoline.S
+++ b/arch/sparc64/kernel/trampoline.S
@@ -98,8 +98,9 @@ startup_continue:
98 98
99 sethi %hi(prom_entry_lock), %g2 99 sethi %hi(prom_entry_lock), %g2
1001: ldstub [%g2 + %lo(prom_entry_lock)], %g1 1001: ldstub [%g2 + %lo(prom_entry_lock)], %g1
101 membar #StoreLoad | #StoreStore
101 brnz,pn %g1, 1b 102 brnz,pn %g1, 1b
102 membar #StoreLoad | #StoreStore 103 nop
103 104
104 sethi %hi(p1275buf), %g2 105 sethi %hi(p1275buf), %g2
105 or %g2, %lo(p1275buf), %g2 106 or %g2, %lo(p1275buf), %g2
diff --git a/arch/sparc64/lib/U1memcpy.S b/arch/sparc64/lib/U1memcpy.S
index da9b520c7189..bafd2fc07acb 100644
--- a/arch/sparc64/lib/U1memcpy.S
+++ b/arch/sparc64/lib/U1memcpy.S
@@ -87,14 +87,17 @@
87#define LOOP_CHUNK3(src, dest, len, branch_dest) \ 87#define LOOP_CHUNK3(src, dest, len, branch_dest) \
88 MAIN_LOOP_CHUNK(src, dest, f32, f48, len, branch_dest) 88 MAIN_LOOP_CHUNK(src, dest, f32, f48, len, branch_dest)
89 89
90#define DO_SYNC membar #Sync;
90#define STORE_SYNC(dest, fsrc) \ 91#define STORE_SYNC(dest, fsrc) \
91 EX_ST(STORE_BLK(%fsrc, %dest)); \ 92 EX_ST(STORE_BLK(%fsrc, %dest)); \
92 add %dest, 0x40, %dest; 93 add %dest, 0x40, %dest; \
94 DO_SYNC
93 95
94#define STORE_JUMP(dest, fsrc, target) \ 96#define STORE_JUMP(dest, fsrc, target) \
95 EX_ST(STORE_BLK(%fsrc, %dest)); \ 97 EX_ST(STORE_BLK(%fsrc, %dest)); \
96 add %dest, 0x40, %dest; \ 98 add %dest, 0x40, %dest; \
97 ba,pt %xcc, target; 99 ba,pt %xcc, target; \
100 nop;
98 101
99#define FINISH_VISCHUNK(dest, f0, f1, left) \ 102#define FINISH_VISCHUNK(dest, f0, f1, left) \
100 subcc %left, 8, %left;\ 103 subcc %left, 8, %left;\
@@ -239,17 +242,17 @@ FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
239 ba,pt %xcc, 1b+4 242 ba,pt %xcc, 1b+4
240 faligndata %f0, %f2, %f48 243 faligndata %f0, %f2, %f48
2411: FREG_FROB(f16,f18,f20,f22,f24,f26,f28,f30,f32) 2441: FREG_FROB(f16,f18,f20,f22,f24,f26,f28,f30,f32)
242 STORE_SYNC(o0, f48) membar #Sync 245 STORE_SYNC(o0, f48)
243 FREG_FROB(f32,f34,f36,f38,f40,f42,f44,f46,f0) 246 FREG_FROB(f32,f34,f36,f38,f40,f42,f44,f46,f0)
244 STORE_JUMP(o0, f48, 40f) membar #Sync 247 STORE_JUMP(o0, f48, 40f)
2452: FREG_FROB(f32,f34,f36,f38,f40,f42,f44,f46,f0) 2482: FREG_FROB(f32,f34,f36,f38,f40,f42,f44,f46,f0)
246 STORE_SYNC(o0, f48) membar #Sync 249 STORE_SYNC(o0, f48)
247 FREG_FROB(f0, f2, f4, f6, f8, f10,f12,f14,f16) 250 FREG_FROB(f0, f2, f4, f6, f8, f10,f12,f14,f16)
248 STORE_JUMP(o0, f48, 48f) membar #Sync 251 STORE_JUMP(o0, f48, 48f)
2493: FREG_FROB(f0, f2, f4, f6, f8, f10,f12,f14,f16) 2523: FREG_FROB(f0, f2, f4, f6, f8, f10,f12,f14,f16)
250 STORE_SYNC(o0, f48) membar #Sync 253 STORE_SYNC(o0, f48)
251 FREG_FROB(f16,f18,f20,f22,f24,f26,f28,f30,f32) 254 FREG_FROB(f16,f18,f20,f22,f24,f26,f28,f30,f32)
252 STORE_JUMP(o0, f48, 56f) membar #Sync 255 STORE_JUMP(o0, f48, 56f)
253 256
2541: FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18) 2571: FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18)
255 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f) 258 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
@@ -260,17 +263,17 @@ FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
260 ba,pt %xcc, 1b+4 263 ba,pt %xcc, 1b+4
261 faligndata %f2, %f4, %f48 264 faligndata %f2, %f4, %f48
2621: FREG_FROB(f18,f20,f22,f24,f26,f28,f30,f32,f34) 2651: FREG_FROB(f18,f20,f22,f24,f26,f28,f30,f32,f34)
263 STORE_SYNC(o0, f48) membar #Sync 266 STORE_SYNC(o0, f48)
264 FREG_FROB(f34,f36,f38,f40,f42,f44,f46,f0, f2) 267 FREG_FROB(f34,f36,f38,f40,f42,f44,f46,f0, f2)
265 STORE_JUMP(o0, f48, 41f) membar #Sync 268 STORE_JUMP(o0, f48, 41f)
2662: FREG_FROB(f34,f36,f38,f40,f42,f44,f46,f0, f2) 2692: FREG_FROB(f34,f36,f38,f40,f42,f44,f46,f0, f2)
267 STORE_SYNC(o0, f48) membar #Sync 270 STORE_SYNC(o0, f48)
268 FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18) 271 FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18)
269 STORE_JUMP(o0, f48, 49f) membar #Sync 272 STORE_JUMP(o0, f48, 49f)
2703: FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18) 2733: FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18)
271 STORE_SYNC(o0, f48) membar #Sync 274 STORE_SYNC(o0, f48)
272 FREG_FROB(f18,f20,f22,f24,f26,f28,f30,f32,f34) 275 FREG_FROB(f18,f20,f22,f24,f26,f28,f30,f32,f34)
273 STORE_JUMP(o0, f48, 57f) membar #Sync 276 STORE_JUMP(o0, f48, 57f)
274 277
2751: FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20) 2781: FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20)
276 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f) 279 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
@@ -281,17 +284,17 @@ FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
281 ba,pt %xcc, 1b+4 284 ba,pt %xcc, 1b+4
282 faligndata %f4, %f6, %f48 285 faligndata %f4, %f6, %f48
2831: FREG_FROB(f20,f22,f24,f26,f28,f30,f32,f34,f36) 2861: FREG_FROB(f20,f22,f24,f26,f28,f30,f32,f34,f36)
284 STORE_SYNC(o0, f48) membar #Sync 287 STORE_SYNC(o0, f48)
285 FREG_FROB(f36,f38,f40,f42,f44,f46,f0, f2, f4) 288 FREG_FROB(f36,f38,f40,f42,f44,f46,f0, f2, f4)
286 STORE_JUMP(o0, f48, 42f) membar #Sync 289 STORE_JUMP(o0, f48, 42f)
2872: FREG_FROB(f36,f38,f40,f42,f44,f46,f0, f2, f4) 2902: FREG_FROB(f36,f38,f40,f42,f44,f46,f0, f2, f4)
288 STORE_SYNC(o0, f48) membar #Sync 291 STORE_SYNC(o0, f48)
289 FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20) 292 FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20)
290 STORE_JUMP(o0, f48, 50f) membar #Sync 293 STORE_JUMP(o0, f48, 50f)
2913: FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20) 2943: FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20)
292 STORE_SYNC(o0, f48) membar #Sync 295 STORE_SYNC(o0, f48)
293 FREG_FROB(f20,f22,f24,f26,f28,f30,f32,f34,f36) 296 FREG_FROB(f20,f22,f24,f26,f28,f30,f32,f34,f36)
294 STORE_JUMP(o0, f48, 58f) membar #Sync 297 STORE_JUMP(o0, f48, 58f)
295 298
2961: FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22) 2991: FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22)
297 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f) 300 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
@@ -302,17 +305,17 @@ FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
302 ba,pt %xcc, 1b+4 305 ba,pt %xcc, 1b+4
303 faligndata %f6, %f8, %f48 306 faligndata %f6, %f8, %f48
3041: FREG_FROB(f22,f24,f26,f28,f30,f32,f34,f36,f38) 3071: FREG_FROB(f22,f24,f26,f28,f30,f32,f34,f36,f38)
305 STORE_SYNC(o0, f48) membar #Sync 308 STORE_SYNC(o0, f48)
306 FREG_FROB(f38,f40,f42,f44,f46,f0, f2, f4, f6) 309 FREG_FROB(f38,f40,f42,f44,f46,f0, f2, f4, f6)
307 STORE_JUMP(o0, f48, 43f) membar #Sync 310 STORE_JUMP(o0, f48, 43f)
3082: FREG_FROB(f38,f40,f42,f44,f46,f0, f2, f4, f6) 3112: FREG_FROB(f38,f40,f42,f44,f46,f0, f2, f4, f6)
309 STORE_SYNC(o0, f48) membar #Sync 312 STORE_SYNC(o0, f48)
310 FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22) 313 FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22)
311 STORE_JUMP(o0, f48, 51f) membar #Sync 314 STORE_JUMP(o0, f48, 51f)
3123: FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22) 3153: FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22)
313 STORE_SYNC(o0, f48) membar #Sync 316 STORE_SYNC(o0, f48)
314 FREG_FROB(f22,f24,f26,f28,f30,f32,f34,f36,f38) 317 FREG_FROB(f22,f24,f26,f28,f30,f32,f34,f36,f38)
315 STORE_JUMP(o0, f48, 59f) membar #Sync 318 STORE_JUMP(o0, f48, 59f)
316 319
3171: FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24) 3201: FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24)
318 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f) 321 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
@@ -323,17 +326,17 @@ FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
323 ba,pt %xcc, 1b+4 326 ba,pt %xcc, 1b+4
324 faligndata %f8, %f10, %f48 327 faligndata %f8, %f10, %f48
3251: FREG_FROB(f24,f26,f28,f30,f32,f34,f36,f38,f40) 3281: FREG_FROB(f24,f26,f28,f30,f32,f34,f36,f38,f40)
326 STORE_SYNC(o0, f48) membar #Sync 329 STORE_SYNC(o0, f48)
327 FREG_FROB(f40,f42,f44,f46,f0, f2, f4, f6, f8) 330 FREG_FROB(f40,f42,f44,f46,f0, f2, f4, f6, f8)
328 STORE_JUMP(o0, f48, 44f) membar #Sync 331 STORE_JUMP(o0, f48, 44f)
3292: FREG_FROB(f40,f42,f44,f46,f0, f2, f4, f6, f8) 3322: FREG_FROB(f40,f42,f44,f46,f0, f2, f4, f6, f8)
330 STORE_SYNC(o0, f48) membar #Sync 333 STORE_SYNC(o0, f48)
331 FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24) 334 FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24)
332 STORE_JUMP(o0, f48, 52f) membar #Sync 335 STORE_JUMP(o0, f48, 52f)
3333: FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24) 3363: FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24)
334 STORE_SYNC(o0, f48) membar #Sync 337 STORE_SYNC(o0, f48)
335 FREG_FROB(f24,f26,f28,f30,f32,f34,f36,f38,f40) 338 FREG_FROB(f24,f26,f28,f30,f32,f34,f36,f38,f40)
336 STORE_JUMP(o0, f48, 60f) membar #Sync 339 STORE_JUMP(o0, f48, 60f)
337 340
3381: FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26) 3411: FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26)
339 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f) 342 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
@@ -344,17 +347,17 @@ FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
344 ba,pt %xcc, 1b+4 347 ba,pt %xcc, 1b+4
345 faligndata %f10, %f12, %f48 348 faligndata %f10, %f12, %f48
3461: FREG_FROB(f26,f28,f30,f32,f34,f36,f38,f40,f42) 3491: FREG_FROB(f26,f28,f30,f32,f34,f36,f38,f40,f42)
347 STORE_SYNC(o0, f48) membar #Sync 350 STORE_SYNC(o0, f48)
348 FREG_FROB(f42,f44,f46,f0, f2, f4, f6, f8, f10) 351 FREG_FROB(f42,f44,f46,f0, f2, f4, f6, f8, f10)
349 STORE_JUMP(o0, f48, 45f) membar #Sync 352 STORE_JUMP(o0, f48, 45f)
3502: FREG_FROB(f42,f44,f46,f0, f2, f4, f6, f8, f10) 3532: FREG_FROB(f42,f44,f46,f0, f2, f4, f6, f8, f10)
351 STORE_SYNC(o0, f48) membar #Sync 354 STORE_SYNC(o0, f48)
352 FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26) 355 FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26)
353 STORE_JUMP(o0, f48, 53f) membar #Sync 356 STORE_JUMP(o0, f48, 53f)
3543: FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26) 3573: FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26)
355 STORE_SYNC(o0, f48) membar #Sync 358 STORE_SYNC(o0, f48)
356 FREG_FROB(f26,f28,f30,f32,f34,f36,f38,f40,f42) 359 FREG_FROB(f26,f28,f30,f32,f34,f36,f38,f40,f42)
357 STORE_JUMP(o0, f48, 61f) membar #Sync 360 STORE_JUMP(o0, f48, 61f)
358 361
3591: FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28) 3621: FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28)
360 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f) 363 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
@@ -365,17 +368,17 @@ FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
365 ba,pt %xcc, 1b+4 368 ba,pt %xcc, 1b+4
366 faligndata %f12, %f14, %f48 369 faligndata %f12, %f14, %f48
3671: FREG_FROB(f28,f30,f32,f34,f36,f38,f40,f42,f44) 3701: FREG_FROB(f28,f30,f32,f34,f36,f38,f40,f42,f44)
368 STORE_SYNC(o0, f48) membar #Sync 371 STORE_SYNC(o0, f48)
369 FREG_FROB(f44,f46,f0, f2, f4, f6, f8, f10,f12) 372 FREG_FROB(f44,f46,f0, f2, f4, f6, f8, f10,f12)
370 STORE_JUMP(o0, f48, 46f) membar #Sync 373 STORE_JUMP(o0, f48, 46f)
3712: FREG_FROB(f44,f46,f0, f2, f4, f6, f8, f10,f12) 3742: FREG_FROB(f44,f46,f0, f2, f4, f6, f8, f10,f12)
372 STORE_SYNC(o0, f48) membar #Sync 375 STORE_SYNC(o0, f48)
373 FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28) 376 FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28)
374 STORE_JUMP(o0, f48, 54f) membar #Sync 377 STORE_JUMP(o0, f48, 54f)
3753: FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28) 3783: FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28)
376 STORE_SYNC(o0, f48) membar #Sync 379 STORE_SYNC(o0, f48)
377 FREG_FROB(f28,f30,f32,f34,f36,f38,f40,f42,f44) 380 FREG_FROB(f28,f30,f32,f34,f36,f38,f40,f42,f44)
378 STORE_JUMP(o0, f48, 62f) membar #Sync 381 STORE_JUMP(o0, f48, 62f)
379 382
3801: FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30) 3831: FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30)
381 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f) 384 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
@@ -386,17 +389,17 @@ FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
386 ba,pt %xcc, 1b+4 389 ba,pt %xcc, 1b+4
387 faligndata %f14, %f16, %f48 390 faligndata %f14, %f16, %f48
3881: FREG_FROB(f30,f32,f34,f36,f38,f40,f42,f44,f46) 3911: FREG_FROB(f30,f32,f34,f36,f38,f40,f42,f44,f46)
389 STORE_SYNC(o0, f48) membar #Sync 392 STORE_SYNC(o0, f48)
390 FREG_FROB(f46,f0, f2, f4, f6, f8, f10,f12,f14) 393 FREG_FROB(f46,f0, f2, f4, f6, f8, f10,f12,f14)
391 STORE_JUMP(o0, f48, 47f) membar #Sync 394 STORE_JUMP(o0, f48, 47f)
3922: FREG_FROB(f46,f0, f2, f4, f6, f8, f10,f12,f14) 3952: FREG_FROB(f46,f0, f2, f4, f6, f8, f10,f12,f14)
393 STORE_SYNC(o0, f48) membar #Sync 396 STORE_SYNC(o0, f48)
394 FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30) 397 FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30)
395 STORE_JUMP(o0, f48, 55f) membar #Sync 398 STORE_JUMP(o0, f48, 55f)
3963: FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30) 3993: FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30)
397 STORE_SYNC(o0, f48) membar #Sync 400 STORE_SYNC(o0, f48)
398 FREG_FROB(f30,f32,f34,f36,f38,f40,f42,f44,f46) 401 FREG_FROB(f30,f32,f34,f36,f38,f40,f42,f44,f46)
399 STORE_JUMP(o0, f48, 63f) membar #Sync 402 STORE_JUMP(o0, f48, 63f)
400 403
40140: FINISH_VISCHUNK(o0, f0, f2, g3) 40440: FINISH_VISCHUNK(o0, f0, f2, g3)
40241: FINISH_VISCHUNK(o0, f2, f4, g3) 40541: FINISH_VISCHUNK(o0, f2, f4, g3)
diff --git a/arch/sparc64/lib/VISsave.S b/arch/sparc64/lib/VISsave.S
index 65e328d600a8..4e18989bd602 100644
--- a/arch/sparc64/lib/VISsave.S
+++ b/arch/sparc64/lib/VISsave.S
@@ -72,7 +72,11 @@ vis1: ldub [%g6 + TI_FPSAVED], %g3
72 72
73 stda %f48, [%g3 + %g1] ASI_BLK_P 73 stda %f48, [%g3 + %g1] ASI_BLK_P
745: membar #Sync 745: membar #Sync
75 jmpl %g7 + %g0, %g0 75 ba,pt %xcc, 80f
76 nop
77
78 .align 32
7980: jmpl %g7 + %g0, %g0
76 nop 80 nop
77 81
786: ldub [%g3 + TI_FPSAVED], %o5 826: ldub [%g3 + TI_FPSAVED], %o5
@@ -87,8 +91,11 @@ vis1: ldub [%g6 + TI_FPSAVED], %g3
87 stda %f32, [%g2 + %g1] ASI_BLK_P 91 stda %f32, [%g2 + %g1] ASI_BLK_P
88 stda %f48, [%g3 + %g1] ASI_BLK_P 92 stda %f48, [%g3 + %g1] ASI_BLK_P
89 membar #Sync 93 membar #Sync
90 jmpl %g7 + %g0, %g0 94 ba,pt %xcc, 80f
95 nop
91 96
97 .align 32
9880: jmpl %g7 + %g0, %g0
92 nop 99 nop
93 100
94 .align 32 101 .align 32
@@ -126,6 +133,10 @@ VISenterhalf:
126 stda %f0, [%g2 + %g1] ASI_BLK_P 133 stda %f0, [%g2 + %g1] ASI_BLK_P
127 stda %f16, [%g3 + %g1] ASI_BLK_P 134 stda %f16, [%g3 + %g1] ASI_BLK_P
128 membar #Sync 135 membar #Sync
136 ba,pt %xcc, 4f
137 nop
138
139 .align 32
1294: and %o5, FPRS_DU, %o5 1404: and %o5, FPRS_DU, %o5
130 jmpl %g7 + %g0, %g0 141 jmpl %g7 + %g0, %g0
131 wr %o5, FPRS_FEF, %fprs 142 wr %o5, FPRS_FEF, %fprs
diff --git a/arch/sparc64/lib/atomic.S b/arch/sparc64/lib/atomic.S
index e528b8d1a3e6..faf87c31598b 100644
--- a/arch/sparc64/lib/atomic.S
+++ b/arch/sparc64/lib/atomic.S
@@ -7,18 +7,6 @@
7#include <linux/config.h> 7#include <linux/config.h>
8#include <asm/asi.h> 8#include <asm/asi.h>
9 9
10 /* On SMP we need to use memory barriers to ensure
11 * correct memory operation ordering, nop these out
12 * for uniprocessor.
13 */
14#ifdef CONFIG_SMP
15#define ATOMIC_PRE_BARRIER membar #StoreLoad | #LoadLoad
16#define ATOMIC_POST_BARRIER membar #StoreLoad | #StoreStore
17#else
18#define ATOMIC_PRE_BARRIER nop
19#define ATOMIC_POST_BARRIER nop
20#endif
21
22 .text 10 .text
23 11
24 /* Two versions of the atomic routines, one that 12 /* Two versions of the atomic routines, one that
@@ -52,6 +40,24 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
52 nop 40 nop
53 .size atomic_sub, .-atomic_sub 41 .size atomic_sub, .-atomic_sub
54 42
43 /* On SMP we need to use memory barriers to ensure
44 * correct memory operation ordering, nop these out
45 * for uniprocessor.
46 */
47#ifdef CONFIG_SMP
48
49#define ATOMIC_PRE_BARRIER membar #StoreLoad | #LoadLoad;
50#define ATOMIC_POST_BARRIER \
51 ba,pt %xcc, 80b; \
52 membar #StoreLoad | #StoreStore
53
5480: retl
55 nop
56#else
57#define ATOMIC_PRE_BARRIER
58#define ATOMIC_POST_BARRIER
59#endif
60
55 .globl atomic_add_ret 61 .globl atomic_add_ret
56 .type atomic_add_ret,#function 62 .type atomic_add_ret,#function
57atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */ 63atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
@@ -62,9 +68,10 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
62 cmp %g1, %g7 68 cmp %g1, %g7
63 bne,pn %icc, 1b 69 bne,pn %icc, 1b
64 add %g7, %o0, %g7 70 add %g7, %o0, %g7
71 sra %g7, 0, %o0
65 ATOMIC_POST_BARRIER 72 ATOMIC_POST_BARRIER
66 retl 73 retl
67 sra %g7, 0, %o0 74 nop
68 .size atomic_add_ret, .-atomic_add_ret 75 .size atomic_add_ret, .-atomic_add_ret
69 76
70 .globl atomic_sub_ret 77 .globl atomic_sub_ret
@@ -77,9 +84,10 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
77 cmp %g1, %g7 84 cmp %g1, %g7
78 bne,pn %icc, 1b 85 bne,pn %icc, 1b
79 sub %g7, %o0, %g7 86 sub %g7, %o0, %g7
87 sra %g7, 0, %o0
80 ATOMIC_POST_BARRIER 88 ATOMIC_POST_BARRIER
81 retl 89 retl
82 sra %g7, 0, %o0 90 nop
83 .size atomic_sub_ret, .-atomic_sub_ret 91 .size atomic_sub_ret, .-atomic_sub_ret
84 92
85 .globl atomic64_add 93 .globl atomic64_add
@@ -118,9 +126,10 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
118 cmp %g1, %g7 126 cmp %g1, %g7
119 bne,pn %xcc, 1b 127 bne,pn %xcc, 1b
120 add %g7, %o0, %g7 128 add %g7, %o0, %g7
129 mov %g7, %o0
121 ATOMIC_POST_BARRIER 130 ATOMIC_POST_BARRIER
122 retl 131 retl
123 mov %g7, %o0 132 nop
124 .size atomic64_add_ret, .-atomic64_add_ret 133 .size atomic64_add_ret, .-atomic64_add_ret
125 134
126 .globl atomic64_sub_ret 135 .globl atomic64_sub_ret
@@ -133,7 +142,8 @@ atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
133 cmp %g1, %g7 142 cmp %g1, %g7
134 bne,pn %xcc, 1b 143 bne,pn %xcc, 1b
135 sub %g7, %o0, %g7 144 sub %g7, %o0, %g7
145 mov %g7, %o0
136 ATOMIC_POST_BARRIER 146 ATOMIC_POST_BARRIER
137 retl 147 retl
138 mov %g7, %o0 148 nop
139 .size atomic64_sub_ret, .-atomic64_sub_ret 149 .size atomic64_sub_ret, .-atomic64_sub_ret
diff --git a/arch/sparc64/lib/bitops.S b/arch/sparc64/lib/bitops.S
index 886dcd2b376a..31afbfe6c1e8 100644
--- a/arch/sparc64/lib/bitops.S
+++ b/arch/sparc64/lib/bitops.S
@@ -7,20 +7,26 @@
7#include <linux/config.h> 7#include <linux/config.h>
8#include <asm/asi.h> 8#include <asm/asi.h>
9 9
10 .text
11
10 /* On SMP we need to use memory barriers to ensure 12 /* On SMP we need to use memory barriers to ensure
11 * correct memory operation ordering, nop these out 13 * correct memory operation ordering, nop these out
12 * for uniprocessor. 14 * for uniprocessor.
13 */ 15 */
16
14#ifdef CONFIG_SMP 17#ifdef CONFIG_SMP
15#define BITOP_PRE_BARRIER membar #StoreLoad | #LoadLoad 18#define BITOP_PRE_BARRIER membar #StoreLoad | #LoadLoad
16#define BITOP_POST_BARRIER membar #StoreLoad | #StoreStore 19#define BITOP_POST_BARRIER \
20 ba,pt %xcc, 80b; \
21 membar #StoreLoad | #StoreStore
22
2380: retl
24 nop
17#else 25#else
18#define BITOP_PRE_BARRIER nop 26#define BITOP_PRE_BARRIER
19#define BITOP_POST_BARRIER nop 27#define BITOP_POST_BARRIER
20#endif 28#endif
21 29
22 .text
23
24 .globl test_and_set_bit 30 .globl test_and_set_bit
25 .type test_and_set_bit,#function 31 .type test_and_set_bit,#function
26test_and_set_bit: /* %o0=nr, %o1=addr */ 32test_and_set_bit: /* %o0=nr, %o1=addr */
@@ -37,10 +43,11 @@ test_and_set_bit: /* %o0=nr, %o1=addr */
37 cmp %g7, %g1 43 cmp %g7, %g1
38 bne,pn %xcc, 1b 44 bne,pn %xcc, 1b
39 and %g7, %o2, %g2 45 and %g7, %o2, %g2
40 BITOP_POST_BARRIER
41 clr %o0 46 clr %o0
47 movrne %g2, 1, %o0
48 BITOP_POST_BARRIER
42 retl 49 retl
43 movrne %g2, 1, %o0 50 nop
44 .size test_and_set_bit, .-test_and_set_bit 51 .size test_and_set_bit, .-test_and_set_bit
45 52
46 .globl test_and_clear_bit 53 .globl test_and_clear_bit
@@ -59,10 +66,11 @@ test_and_clear_bit: /* %o0=nr, %o1=addr */
59 cmp %g7, %g1 66 cmp %g7, %g1
60 bne,pn %xcc, 1b 67 bne,pn %xcc, 1b
61 and %g7, %o2, %g2 68 and %g7, %o2, %g2
62 BITOP_POST_BARRIER
63 clr %o0 69 clr %o0
70 movrne %g2, 1, %o0
71 BITOP_POST_BARRIER
64 retl 72 retl
65 movrne %g2, 1, %o0 73 nop
66 .size test_and_clear_bit, .-test_and_clear_bit 74 .size test_and_clear_bit, .-test_and_clear_bit
67 75
68 .globl test_and_change_bit 76 .globl test_and_change_bit
@@ -81,10 +89,11 @@ test_and_change_bit: /* %o0=nr, %o1=addr */
81 cmp %g7, %g1 89 cmp %g7, %g1
82 bne,pn %xcc, 1b 90 bne,pn %xcc, 1b
83 and %g7, %o2, %g2 91 and %g7, %o2, %g2
84 BITOP_POST_BARRIER
85 clr %o0 92 clr %o0
93 movrne %g2, 1, %o0
94 BITOP_POST_BARRIER
86 retl 95 retl
87 movrne %g2, 1, %o0 96 nop
88 .size test_and_change_bit, .-test_and_change_bit 97 .size test_and_change_bit, .-test_and_change_bit
89 98
90 .globl set_bit 99 .globl set_bit
diff --git a/arch/sparc64/lib/debuglocks.c b/arch/sparc64/lib/debuglocks.c
index c421e0c65325..f03344cf784e 100644
--- a/arch/sparc64/lib/debuglocks.c
+++ b/arch/sparc64/lib/debuglocks.c
@@ -252,8 +252,9 @@ wlock_again:
252" andn %%g1, %%g3, %%g7\n" 252" andn %%g1, %%g3, %%g7\n"
253" casx [%0], %%g1, %%g7\n" 253" casx [%0], %%g1, %%g7\n"
254" cmp %%g1, %%g7\n" 254" cmp %%g1, %%g7\n"
255" membar #StoreLoad | #StoreStore\n"
255" bne,pn %%xcc, 1b\n" 256" bne,pn %%xcc, 1b\n"
256" membar #StoreLoad | #StoreStore" 257" nop"
257 : /* no outputs */ 258 : /* no outputs */
258 : "r" (&(rw->lock)) 259 : "r" (&(rw->lock))
259 : "g3", "g1", "g7", "cc", "memory"); 260 : "g3", "g1", "g7", "cc", "memory");
@@ -351,8 +352,9 @@ int _do_write_trylock (rwlock_t *rw, char *str)
351" andn %%g1, %%g3, %%g7\n" 352" andn %%g1, %%g3, %%g7\n"
352" casx [%0], %%g1, %%g7\n" 353" casx [%0], %%g1, %%g7\n"
353" cmp %%g1, %%g7\n" 354" cmp %%g1, %%g7\n"
355" membar #StoreLoad | #StoreStore\n"
354" bne,pn %%xcc, 1b\n" 356" bne,pn %%xcc, 1b\n"
355" membar #StoreLoad | #StoreStore" 357" nop"
356 : /* no outputs */ 358 : /* no outputs */
357 : "r" (&(rw->lock)) 359 : "r" (&(rw->lock))
358 : "g3", "g1", "g7", "cc", "memory"); 360 : "g3", "g1", "g7", "cc", "memory");
diff --git a/arch/sparc64/lib/dec_and_lock.S b/arch/sparc64/lib/dec_and_lock.S
index 7e6fdaebedba..8ee288dd0afc 100644
--- a/arch/sparc64/lib/dec_and_lock.S
+++ b/arch/sparc64/lib/dec_and_lock.S
@@ -48,8 +48,9 @@ start_to_zero:
48#endif 48#endif
49to_zero: 49to_zero:
50 ldstub [%o1], %g3 50 ldstub [%o1], %g3
51 membar #StoreLoad | #StoreStore
51 brnz,pn %g3, spin_on_lock 52 brnz,pn %g3, spin_on_lock
52 membar #StoreLoad | #StoreStore 53 nop
53loop2: cas [%o0], %g2, %g7 /* ASSERT(g7 == 0) */ 54loop2: cas [%o0], %g2, %g7 /* ASSERT(g7 == 0) */
54 cmp %g2, %g7 55 cmp %g2, %g7
55 56
@@ -71,8 +72,9 @@ loop2: cas [%o0], %g2, %g7 /* ASSERT(g7 == 0) */
71 nop 72 nop
72spin_on_lock: 73spin_on_lock:
73 ldub [%o1], %g3 74 ldub [%o1], %g3
75 membar #LoadLoad
74 brnz,pt %g3, spin_on_lock 76 brnz,pt %g3, spin_on_lock
75 membar #LoadLoad 77 nop
76 ba,pt %xcc, to_zero 78 ba,pt %xcc, to_zero
77 nop 79 nop
78 nop 80 nop
diff --git a/arch/sparc64/lib/rwsem.S b/arch/sparc64/lib/rwsem.S
index 174ff7b9164c..75f0e6b951d6 100644
--- a/arch/sparc64/lib/rwsem.S
+++ b/arch/sparc64/lib/rwsem.S
@@ -17,8 +17,9 @@ __down_read:
17 bne,pn %icc, 1b 17 bne,pn %icc, 1b
18 add %g7, 1, %g7 18 add %g7, 1, %g7
19 cmp %g7, 0 19 cmp %g7, 0
20 membar #StoreLoad | #StoreStore
20 bl,pn %icc, 3f 21 bl,pn %icc, 3f
21 membar #StoreLoad | #StoreStore 22 nop
222: 232:
23 retl 24 retl
24 nop 25 nop
@@ -57,8 +58,9 @@ __down_write:
57 cmp %g3, %g7 58 cmp %g3, %g7
58 bne,pn %icc, 1b 59 bne,pn %icc, 1b
59 cmp %g7, 0 60 cmp %g7, 0
61 membar #StoreLoad | #StoreStore
60 bne,pn %icc, 3f 62 bne,pn %icc, 3f
61 membar #StoreLoad | #StoreStore 63 nop
622: retl 642: retl
63 nop 65 nop
643: 663:
@@ -97,8 +99,9 @@ __up_read:
97 cmp %g1, %g7 99 cmp %g1, %g7
98 bne,pn %icc, 1b 100 bne,pn %icc, 1b
99 cmp %g7, 0 101 cmp %g7, 0
102 membar #StoreLoad | #StoreStore
100 bl,pn %icc, 3f 103 bl,pn %icc, 3f
101 membar #StoreLoad | #StoreStore 104 nop
1022: retl 1052: retl
103 nop 106 nop
1043: sethi %hi(RWSEM_ACTIVE_MASK), %g1 1073: sethi %hi(RWSEM_ACTIVE_MASK), %g1
@@ -126,8 +129,9 @@ __up_write:
126 bne,pn %icc, 1b 129 bne,pn %icc, 1b
127 sub %g7, %g1, %g7 130 sub %g7, %g1, %g7
128 cmp %g7, 0 131 cmp %g7, 0
132 membar #StoreLoad | #StoreStore
129 bl,pn %icc, 3f 133 bl,pn %icc, 3f
130 membar #StoreLoad | #StoreStore 134 nop
1312: 1352:
132 retl 136 retl
133 nop 137 nop
@@ -151,8 +155,9 @@ __downgrade_write:
151 bne,pn %icc, 1b 155 bne,pn %icc, 1b
152 sub %g7, %g1, %g7 156 sub %g7, %g1, %g7
153 cmp %g7, 0 157 cmp %g7, 0
158 membar #StoreLoad | #StoreStore
154 bl,pn %icc, 3f 159 bl,pn %icc, 3f
155 membar #StoreLoad | #StoreStore 160 nop
1562: 1612:
157 retl 162 retl
158 nop 163 nop
diff --git a/arch/sparc64/mm/init.c b/arch/sparc64/mm/init.c
index 9c5222075da9..8fc413cb6acd 100644
--- a/arch/sparc64/mm/init.c
+++ b/arch/sparc64/mm/init.c
@@ -136,8 +136,9 @@ static __inline__ void set_dcache_dirty(struct page *page, int this_cpu)
136 "or %%g1, %0, %%g1\n\t" 136 "or %%g1, %0, %%g1\n\t"
137 "casx [%2], %%g7, %%g1\n\t" 137 "casx [%2], %%g7, %%g1\n\t"
138 "cmp %%g7, %%g1\n\t" 138 "cmp %%g7, %%g1\n\t"
139 "membar #StoreLoad | #StoreStore\n\t"
139 "bne,pn %%xcc, 1b\n\t" 140 "bne,pn %%xcc, 1b\n\t"
140 " membar #StoreLoad | #StoreStore" 141 " nop"
141 : /* no outputs */ 142 : /* no outputs */
142 : "r" (mask), "r" (non_cpu_bits), "r" (&page->flags) 143 : "r" (mask), "r" (non_cpu_bits), "r" (&page->flags)
143 : "g1", "g7"); 144 : "g1", "g7");
@@ -157,8 +158,9 @@ static __inline__ void clear_dcache_dirty_cpu(struct page *page, unsigned long c
157 " andn %%g7, %1, %%g1\n\t" 158 " andn %%g7, %1, %%g1\n\t"
158 "casx [%2], %%g7, %%g1\n\t" 159 "casx [%2], %%g7, %%g1\n\t"
159 "cmp %%g7, %%g1\n\t" 160 "cmp %%g7, %%g1\n\t"
161 "membar #StoreLoad | #StoreStore\n\t"
160 "bne,pn %%xcc, 1b\n\t" 162 "bne,pn %%xcc, 1b\n\t"
161 " membar #StoreLoad | #StoreStore\n" 163 " nop\n"
162 "2:" 164 "2:"
163 : /* no outputs */ 165 : /* no outputs */
164 : "r" (cpu), "r" (mask), "r" (&page->flags), 166 : "r" (cpu), "r" (mask), "r" (&page->flags),
diff --git a/arch/sparc64/mm/ultra.S b/arch/sparc64/mm/ultra.S
index 7a0934321010..7a2431d3abc7 100644
--- a/arch/sparc64/mm/ultra.S
+++ b/arch/sparc64/mm/ultra.S
@@ -266,8 +266,9 @@ __cheetah_flush_tlb_pending: /* 22 insns */
266 andn %o3, 1, %o3 266 andn %o3, 1, %o3
267 stxa %g0, [%o3] ASI_IMMU_DEMAP 267 stxa %g0, [%o3] ASI_IMMU_DEMAP
2682: stxa %g0, [%o3] ASI_DMMU_DEMAP 2682: stxa %g0, [%o3] ASI_DMMU_DEMAP
269 membar #Sync
269 brnz,pt %o1, 1b 270 brnz,pt %o1, 1b
270 membar #Sync 271 nop
271 stxa %g2, [%o4] ASI_DMMU 272 stxa %g2, [%o4] ASI_DMMU
272 flush %g6 273 flush %g6
273 wrpr %g0, 0, %tl 274 wrpr %g0, 0, %tl
diff --git a/arch/x86_64/kernel/kprobes.c b/arch/x86_64/kernel/kprobes.c
index 4e680f87a75f..acd2a778ebe6 100644
--- a/arch/x86_64/kernel/kprobes.c
+++ b/arch/x86_64/kernel/kprobes.c
@@ -38,7 +38,7 @@
38#include <linux/string.h> 38#include <linux/string.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/preempt.h> 40#include <linux/preempt.h>
41#include <linux/moduleloader.h> 41
42#include <asm/cacheflush.h> 42#include <asm/cacheflush.h>
43#include <asm/pgtable.h> 43#include <asm/pgtable.h>
44#include <asm/kdebug.h> 44#include <asm/kdebug.h>
@@ -51,8 +51,6 @@ static struct kprobe *kprobe_prev;
51static unsigned long kprobe_status_prev, kprobe_old_rflags_prev, kprobe_saved_rflags_prev; 51static unsigned long kprobe_status_prev, kprobe_old_rflags_prev, kprobe_saved_rflags_prev;
52static struct pt_regs jprobe_saved_regs; 52static struct pt_regs jprobe_saved_regs;
53static long *jprobe_saved_rsp; 53static long *jprobe_saved_rsp;
54static kprobe_opcode_t *get_insn_slot(void);
55static void free_insn_slot(kprobe_opcode_t *slot);
56void jprobe_return_end(void); 54void jprobe_return_end(void);
57 55
58/* copy of the kernel stack at the probe fire time */ 56/* copy of the kernel stack at the probe fire time */
@@ -274,48 +272,23 @@ static void prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
274 regs->rip = (unsigned long)p->ainsn.insn; 272 regs->rip = (unsigned long)p->ainsn.insn;
275} 273}
276 274
277struct task_struct *arch_get_kprobe_task(void *ptr)
278{
279 return ((struct thread_info *) (((unsigned long) ptr) &
280 (~(THREAD_SIZE -1))))->task;
281}
282
283void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs) 275void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs)
284{ 276{
285 unsigned long *sara = (unsigned long *)regs->rsp; 277 unsigned long *sara = (unsigned long *)regs->rsp;
286 struct kretprobe_instance *ri; 278 struct kretprobe_instance *ri;
287 static void *orig_ret_addr; 279
280 if ((ri = get_free_rp_inst(rp)) != NULL) {
281 ri->rp = rp;
282 ri->task = current;
283 ri->ret_addr = (kprobe_opcode_t *) *sara;
288 284
289 /*
290 * Save the return address when the return probe hits
291 * the first time, and use it to populate the (krprobe
292 * instance)->ret_addr for subsequent return probes at
293 * the same addrress since stack address would have
294 * the kretprobe_trampoline by then.
295 */
296 if (((void*) *sara) != kretprobe_trampoline)
297 orig_ret_addr = (void*) *sara;
298
299 if ((ri = get_free_rp_inst(rp)) != NULL) {
300 ri->rp = rp;
301 ri->stack_addr = sara;
302 ri->ret_addr = orig_ret_addr;
303 add_rp_inst(ri);
304 /* Replace the return addr with trampoline addr */ 285 /* Replace the return addr with trampoline addr */
305 *sara = (unsigned long) &kretprobe_trampoline; 286 *sara = (unsigned long) &kretprobe_trampoline;
306 } else {
307 rp->nmissed++;
308 }
309}
310 287
311void arch_kprobe_flush_task(struct task_struct *tk) 288 add_rp_inst(ri);
312{ 289 } else {
313 struct kretprobe_instance *ri; 290 rp->nmissed++;
314 while ((ri = get_rp_inst_tsk(tk)) != NULL) { 291 }
315 *((unsigned long *)(ri->stack_addr)) =
316 (unsigned long) ri->ret_addr;
317 recycle_rp_inst(ri);
318 }
319} 292}
320 293
321/* 294/*
@@ -428,36 +401,59 @@ no_kprobe:
428 */ 401 */
429int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs) 402int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
430{ 403{
431 struct task_struct *tsk; 404 struct kretprobe_instance *ri = NULL;
432 struct kretprobe_instance *ri; 405 struct hlist_head *head;
433 struct hlist_head *head; 406 struct hlist_node *node, *tmp;
434 struct hlist_node *node; 407 unsigned long orig_ret_address = 0;
435 unsigned long *sara = (unsigned long *)regs->rsp - 1; 408 unsigned long trampoline_address =(unsigned long)&kretprobe_trampoline;
436
437 tsk = arch_get_kprobe_task(sara);
438 head = kretprobe_inst_table_head(tsk);
439
440 hlist_for_each_entry(ri, node, head, hlist) {
441 if (ri->stack_addr == sara && ri->rp) {
442 if (ri->rp->handler)
443 ri->rp->handler(ri, regs);
444 }
445 }
446 return 0;
447}
448 409
449void trampoline_post_handler(struct kprobe *p, struct pt_regs *regs, 410 head = kretprobe_inst_table_head(current);
450 unsigned long flags)
451{
452 struct kretprobe_instance *ri;
453 /* RA already popped */
454 unsigned long *sara = ((unsigned long *)regs->rsp) - 1;
455 411
456 while ((ri = get_rp_inst(sara))) { 412 /*
457 regs->rip = (unsigned long)ri->ret_addr; 413 * It is possible to have multiple instances associated with a given
414 * task either because an multiple functions in the call path
415 * have a return probe installed on them, and/or more then one return
416 * return probe was registered for a target function.
417 *
418 * We can handle this because:
419 * - instances are always inserted at the head of the list
420 * - when multiple return probes are registered for the same
421 * function, the first instance's ret_addr will point to the
422 * real return address, and all the rest will point to
423 * kretprobe_trampoline
424 */
425 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
426 if (ri->task != current)
427 /* another task is sharing our hash bucket */
428 continue;
429
430 if (ri->rp && ri->rp->handler)
431 ri->rp->handler(ri, regs);
432
433 orig_ret_address = (unsigned long)ri->ret_addr;
458 recycle_rp_inst(ri); 434 recycle_rp_inst(ri);
435
436 if (orig_ret_address != trampoline_address)
437 /*
438 * This is the real return address. Any other
439 * instances associated with this task are for
440 * other calls deeper on the call stack
441 */
442 break;
459 } 443 }
460 regs->eflags &= ~TF_MASK; 444
445 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
446 regs->rip = orig_ret_address;
447
448 unlock_kprobes();
449 preempt_enable_no_resched();
450
451 /*
452 * By returning a non-zero value, we are telling
453 * kprobe_handler() that we have handled unlocking
454 * and re-enabling preemption.
455 */
456 return 1;
461} 457}
462 458
463/* 459/*
@@ -550,8 +546,7 @@ int post_kprobe_handler(struct pt_regs *regs)
550 current_kprobe->post_handler(current_kprobe, regs, 0); 546 current_kprobe->post_handler(current_kprobe, regs, 0);
551 } 547 }
552 548
553 if (current_kprobe->post_handler != trampoline_post_handler) 549 resume_execution(current_kprobe, regs);
554 resume_execution(current_kprobe, regs);
555 regs->eflags |= kprobe_saved_rflags; 550 regs->eflags |= kprobe_saved_rflags;
556 551
557 /* Restore the original saved kprobes variables and continue. */ 552 /* Restore the original saved kprobes variables and continue. */
@@ -682,111 +677,12 @@ int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
682 return 0; 677 return 0;
683} 678}
684 679
685/* 680static struct kprobe trampoline_p = {
686 * kprobe->ainsn.insn points to the copy of the instruction to be single-stepped. 681 .addr = (kprobe_opcode_t *) &kretprobe_trampoline,
687 * By default on x86_64, pages we get from kmalloc or vmalloc are not 682 .pre_handler = trampoline_probe_handler
688 * executable. Single-stepping an instruction on such a page yields an
689 * oops. So instead of storing the instruction copies in their respective
690 * kprobe objects, we allocate a page, map it executable, and store all the
691 * instruction copies there. (We can allocate additional pages if somebody
692 * inserts a huge number of probes.) Each page can hold up to INSNS_PER_PAGE
693 * instruction slots, each of which is MAX_INSN_SIZE*sizeof(kprobe_opcode_t)
694 * bytes.
695 */
696#define INSNS_PER_PAGE (PAGE_SIZE/(MAX_INSN_SIZE*sizeof(kprobe_opcode_t)))
697struct kprobe_insn_page {
698 struct hlist_node hlist;
699 kprobe_opcode_t *insns; /* page of instruction slots */
700 char slot_used[INSNS_PER_PAGE];
701 int nused;
702}; 683};
703 684
704static struct hlist_head kprobe_insn_pages; 685int __init arch_init(void)
705
706/**
707 * get_insn_slot() - Find a slot on an executable page for an instruction.
708 * We allocate an executable page if there's no room on existing ones.
709 */
710static kprobe_opcode_t *get_insn_slot(void)
711{
712 struct kprobe_insn_page *kip;
713 struct hlist_node *pos;
714
715 hlist_for_each(pos, &kprobe_insn_pages) {
716 kip = hlist_entry(pos, struct kprobe_insn_page, hlist);
717 if (kip->nused < INSNS_PER_PAGE) {
718 int i;
719 for (i = 0; i < INSNS_PER_PAGE; i++) {
720 if (!kip->slot_used[i]) {
721 kip->slot_used[i] = 1;
722 kip->nused++;
723 return kip->insns + (i*MAX_INSN_SIZE);
724 }
725 }
726 /* Surprise! No unused slots. Fix kip->nused. */
727 kip->nused = INSNS_PER_PAGE;
728 }
729 }
730
731 /* All out of space. Need to allocate a new page. Use slot 0.*/
732 kip = kmalloc(sizeof(struct kprobe_insn_page), GFP_KERNEL);
733 if (!kip) {
734 return NULL;
735 }
736
737 /*
738 * For the %rip-relative displacement fixups to be doable, we
739 * need our instruction copy to be within +/- 2GB of any data it
740 * might access via %rip. That is, within 2GB of where the
741 * kernel image and loaded module images reside. So we allocate
742 * a page in the module loading area.
743 */
744 kip->insns = module_alloc(PAGE_SIZE);
745 if (!kip->insns) {
746 kfree(kip);
747 return NULL;
748 }
749 INIT_HLIST_NODE(&kip->hlist);
750 hlist_add_head(&kip->hlist, &kprobe_insn_pages);
751 memset(kip->slot_used, 0, INSNS_PER_PAGE);
752 kip->slot_used[0] = 1;
753 kip->nused = 1;
754 return kip->insns;
755}
756
757/**
758 * free_insn_slot() - Free instruction slot obtained from get_insn_slot().
759 */
760static void free_insn_slot(kprobe_opcode_t *slot)
761{ 686{
762 struct kprobe_insn_page *kip; 687 return register_kprobe(&trampoline_p);
763 struct hlist_node *pos;
764
765 hlist_for_each(pos, &kprobe_insn_pages) {
766 kip = hlist_entry(pos, struct kprobe_insn_page, hlist);
767 if (kip->insns <= slot
768 && slot < kip->insns+(INSNS_PER_PAGE*MAX_INSN_SIZE)) {
769 int i = (slot - kip->insns) / MAX_INSN_SIZE;
770 kip->slot_used[i] = 0;
771 kip->nused--;
772 if (kip->nused == 0) {
773 /*
774 * Page is no longer in use. Free it unless
775 * it's the last one. We keep the last one
776 * so as not to have to set it up again the
777 * next time somebody inserts a probe.
778 */
779 hlist_del(&kip->hlist);
780 if (hlist_empty(&kprobe_insn_pages)) {
781 INIT_HLIST_NODE(&kip->hlist);
782 hlist_add_head(&kip->hlist,
783 &kprobe_insn_pages);
784 } else {
785 module_free(NULL, kip->insns);
786 kfree(kip);
787 }
788 }
789 return;
790 }
791 }
792} 688}
diff --git a/arch/x86_64/kernel/process.c b/arch/x86_64/kernel/process.c
index 1d91271796e5..7577f9d7a75d 100644
--- a/arch/x86_64/kernel/process.c
+++ b/arch/x86_64/kernel/process.c
@@ -482,6 +482,33 @@ out:
482} 482}
483 483
484/* 484/*
485 * This function selects if the context switch from prev to next
486 * has to tweak the TSC disable bit in the cr4.
487 */
488static inline void disable_tsc(struct task_struct *prev_p,
489 struct task_struct *next_p)
490{
491 struct thread_info *prev, *next;
492
493 /*
494 * gcc should eliminate the ->thread_info dereference if
495 * has_secure_computing returns 0 at compile time (SECCOMP=n).
496 */
497 prev = prev_p->thread_info;
498 next = next_p->thread_info;
499
500 if (has_secure_computing(prev) || has_secure_computing(next)) {
501 /* slow path here */
502 if (has_secure_computing(prev) &&
503 !has_secure_computing(next)) {
504 write_cr4(read_cr4() & ~X86_CR4_TSD);
505 } else if (!has_secure_computing(prev) &&
506 has_secure_computing(next))
507 write_cr4(read_cr4() | X86_CR4_TSD);
508 }
509}
510
511/*
485 * This special macro can be used to load a debugging register 512 * This special macro can be used to load a debugging register
486 */ 513 */
487#define loaddebug(thread,r) set_debug(thread->debugreg ## r, r) 514#define loaddebug(thread,r) set_debug(thread->debugreg ## r, r)
@@ -599,6 +626,8 @@ struct task_struct *__switch_to(struct task_struct *prev_p, struct task_struct *
599 } 626 }
600 } 627 }
601 628
629 disable_tsc(prev_p, next_p);
630
602 return prev_p; 631 return prev_p;
603} 632}
604 633
diff --git a/arch/x86_64/pci/mmconfig.c b/arch/x86_64/pci/mmconfig.c
index b693c232fd07..657e88aa0902 100644
--- a/arch/x86_64/pci/mmconfig.c
+++ b/arch/x86_64/pci/mmconfig.c
@@ -7,25 +7,50 @@
7 7
8#include <linux/pci.h> 8#include <linux/pci.h>
9#include <linux/init.h> 9#include <linux/init.h>
10#include <linux/acpi.h>
10#include "pci.h" 11#include "pci.h"
11 12
12#define MMCONFIG_APER_SIZE (256*1024*1024) 13#define MMCONFIG_APER_SIZE (256*1024*1024)
13 14
14/* The physical address of the MMCONFIG aperture. Set from ACPI tables. */
15u32 pci_mmcfg_base_addr;
16
17/* Static virtual mapping of the MMCONFIG aperture */ 15/* Static virtual mapping of the MMCONFIG aperture */
18char *pci_mmcfg_virt; 16struct mmcfg_virt {
17 struct acpi_table_mcfg_config *cfg;
18 char *virt;
19};
20static struct mmcfg_virt *pci_mmcfg_virt;
19 21
20static inline char *pci_dev_base(unsigned int bus, unsigned int devfn) 22static char *get_virt(unsigned int seg, int bus)
21{ 23{
22 return pci_mmcfg_virt + ((bus << 20) | (devfn << 12)); 24 int cfg_num = -1;
25 struct acpi_table_mcfg_config *cfg;
26
27 while (1) {
28 ++cfg_num;
29 if (cfg_num >= pci_mmcfg_config_num) {
30 /* something bad is going on, no cfg table is found. */
31 /* so we fall back to the old way we used to do this */
32 /* and just rely on the first entry to be correct. */
33 return pci_mmcfg_virt[0].virt;
34 }
35 cfg = pci_mmcfg_virt[cfg_num].cfg;
36 if (cfg->pci_segment_group_number != seg)
37 continue;
38 if ((cfg->start_bus_number <= bus) &&
39 (cfg->end_bus_number >= bus))
40 return pci_mmcfg_virt[cfg_num].virt;
41 }
42}
43
44static inline char *pci_dev_base(unsigned int seg, unsigned int bus, unsigned int devfn)
45{
46
47 return get_virt(seg, bus) + ((bus << 20) | (devfn << 12));
23} 48}
24 49
25static int pci_mmcfg_read(unsigned int seg, unsigned int bus, 50static int pci_mmcfg_read(unsigned int seg, unsigned int bus,
26 unsigned int devfn, int reg, int len, u32 *value) 51 unsigned int devfn, int reg, int len, u32 *value)
27{ 52{
28 char *addr = pci_dev_base(bus, devfn); 53 char *addr = pci_dev_base(seg, bus, devfn);
29 54
30 if (unlikely(!value || (bus > 255) || (devfn > 255) || (reg > 4095))) 55 if (unlikely(!value || (bus > 255) || (devfn > 255) || (reg > 4095)))
31 return -EINVAL; 56 return -EINVAL;
@@ -48,7 +73,7 @@ static int pci_mmcfg_read(unsigned int seg, unsigned int bus,
48static int pci_mmcfg_write(unsigned int seg, unsigned int bus, 73static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
49 unsigned int devfn, int reg, int len, u32 value) 74 unsigned int devfn, int reg, int len, u32 value)
50{ 75{
51 char *addr = pci_dev_base(bus,devfn); 76 char *addr = pci_dev_base(seg, bus, devfn);
52 77
53 if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095))) 78 if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095)))
54 return -EINVAL; 79 return -EINVAL;
@@ -75,9 +100,15 @@ static struct pci_raw_ops pci_mmcfg = {
75 100
76static int __init pci_mmcfg_init(void) 101static int __init pci_mmcfg_init(void)
77{ 102{
103 int i;
104
78 if ((pci_probe & PCI_PROBE_MMCONF) == 0) 105 if ((pci_probe & PCI_PROBE_MMCONF) == 0)
79 return 0; 106 return 0;
80 if (!pci_mmcfg_base_addr) 107
108 acpi_table_parse(ACPI_MCFG, acpi_parse_mcfg);
109 if ((pci_mmcfg_config_num == 0) ||
110 (pci_mmcfg_config == NULL) ||
111 (pci_mmcfg_config[0].base_address == 0))
81 return 0; 112 return 0;
82 113
83 /* Kludge for now. Don't use mmconfig on AMD systems because 114 /* Kludge for now. Don't use mmconfig on AMD systems because
@@ -88,13 +119,22 @@ static int __init pci_mmcfg_init(void)
88 return 0; 119 return 0;
89 120
90 /* RED-PEN i386 doesn't do _nocache right now */ 121 /* RED-PEN i386 doesn't do _nocache right now */
91 pci_mmcfg_virt = ioremap_nocache(pci_mmcfg_base_addr, MMCONFIG_APER_SIZE); 122 pci_mmcfg_virt = kmalloc(sizeof(*pci_mmcfg_virt) * pci_mmcfg_config_num, GFP_KERNEL);
92 if (!pci_mmcfg_virt) { 123 if (pci_mmcfg_virt == NULL) {
93 printk("PCI: Cannot map mmconfig aperture\n"); 124 printk("PCI: Can not allocate memory for mmconfig structures\n");
94 return 0; 125 return 0;
95 } 126 }
127 for (i = 0; i < pci_mmcfg_config_num; ++i) {
128 pci_mmcfg_virt[i].cfg = &pci_mmcfg_config[i];
129 pci_mmcfg_virt[i].virt = ioremap_nocache(pci_mmcfg_config[i].base_address, MMCONFIG_APER_SIZE);
130 if (!pci_mmcfg_virt[i].virt) {
131 printk("PCI: Cannot map mmconfig aperture for segment %d\n",
132 pci_mmcfg_config[i].pci_segment_group_number);
133 return 0;
134 }
135 printk(KERN_INFO "PCI: Using MMCONFIG at %x\n", pci_mmcfg_config[i].base_address);
136 }
96 137
97 printk(KERN_INFO "PCI: Using MMCONFIG at %x\n", pci_mmcfg_base_addr);
98 raw_pci_ops = &pci_mmcfg; 138 raw_pci_ops = &pci_mmcfg;
99 pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF; 139 pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
100 140
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 5a0adbf8bc04..97013ddfa202 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -153,7 +153,7 @@ container_device_add(struct acpi_device **device, acpi_handle handle)
153 return_VALUE(-ENODEV); 153 return_VALUE(-ENODEV);
154 } 154 }
155 155
156 result = acpi_bus_scan(*device); 156 result = acpi_bus_start(*device);
157 157
158 return_VALUE(result); 158 return_VALUE(result);
159} 159}
diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c
index 5d19b39e9e2b..5148f3c10b5c 100644
--- a/drivers/acpi/pci_bind.c
+++ b/drivers/acpi/pci_bind.c
@@ -61,15 +61,14 @@ acpi_pci_data_handler (
61 61
62 62
63/** 63/**
64 * acpi_os_get_pci_id 64 * acpi_get_pci_id
65 * ------------------ 65 * ------------------
66 * This function is used by the ACPI Interpreter (a.k.a. Core Subsystem) 66 * This function is used by the ACPI Interpreter (a.k.a. Core Subsystem)
67 * to resolve PCI information for ACPI-PCI devices defined in the namespace. 67 * to resolve PCI information for ACPI-PCI devices defined in the namespace.
68 * This typically occurs when resolving PCI operation region information. 68 * This typically occurs when resolving PCI operation region information.
69 */ 69 */
70#ifdef ACPI_FUTURE_USAGE
71acpi_status 70acpi_status
72acpi_os_get_pci_id ( 71acpi_get_pci_id (
73 acpi_handle handle, 72 acpi_handle handle,
74 struct acpi_pci_id *id) 73 struct acpi_pci_id *id)
75{ 74{
@@ -78,7 +77,7 @@ acpi_os_get_pci_id (
78 struct acpi_device *device = NULL; 77 struct acpi_device *device = NULL;
79 struct acpi_pci_data *data = NULL; 78 struct acpi_pci_data *data = NULL;
80 79
81 ACPI_FUNCTION_TRACE("acpi_os_get_pci_id"); 80 ACPI_FUNCTION_TRACE("acpi_get_pci_id");
82 81
83 if (!id) 82 if (!id)
84 return_ACPI_STATUS(AE_BAD_PARAMETER); 83 return_ACPI_STATUS(AE_BAD_PARAMETER);
@@ -92,7 +91,7 @@ acpi_os_get_pci_id (
92 } 91 }
93 92
94 status = acpi_get_data(handle, acpi_pci_data_handler, (void**) &data); 93 status = acpi_get_data(handle, acpi_pci_data_handler, (void**) &data);
95 if (ACPI_FAILURE(status) || !data || !data->dev) { 94 if (ACPI_FAILURE(status) || !data) {
96 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 95 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
97 "Invalid ACPI-PCI context for device %s\n", 96 "Invalid ACPI-PCI context for device %s\n",
98 acpi_device_bid(device))); 97 acpi_device_bid(device)));
@@ -115,7 +114,7 @@ acpi_os_get_pci_id (
115 114
116 return_ACPI_STATUS(AE_OK); 115 return_ACPI_STATUS(AE_OK);
117} 116}
118#endif /* ACPI_FUTURE_USAGE */ 117EXPORT_SYMBOL(acpi_get_pci_id);
119 118
120 119
121int 120int
@@ -129,6 +128,8 @@ acpi_pci_bind (
129 char *pathname = NULL; 128 char *pathname = NULL;
130 struct acpi_buffer buffer = {0, NULL}; 129 struct acpi_buffer buffer = {0, NULL};
131 acpi_handle handle = NULL; 130 acpi_handle handle = NULL;
131 struct pci_dev *dev;
132 struct pci_bus *bus;
132 133
133 ACPI_FUNCTION_TRACE("acpi_pci_bind"); 134 ACPI_FUNCTION_TRACE("acpi_pci_bind");
134 135
@@ -193,8 +194,20 @@ acpi_pci_bind (
193 * Locate matching device in PCI namespace. If it doesn't exist 194 * Locate matching device in PCI namespace. If it doesn't exist
194 * this typically means that the device isn't currently inserted 195 * this typically means that the device isn't currently inserted
195 * (e.g. docking station, port replicator, etc.). 196 * (e.g. docking station, port replicator, etc.).
197 * We cannot simply search the global pci device list, since
198 * PCI devices are added to the global pci list when the root
199 * bridge start ops are run, which may not have happened yet.
196 */ 200 */
197 data->dev = pci_find_slot(data->id.bus, PCI_DEVFN(data->id.device, data->id.function)); 201 bus = pci_find_bus(data->id.segment, data->id.bus);
202 if (bus) {
203 list_for_each_entry(dev, &bus->devices, bus_list) {
204 if (dev->devfn == PCI_DEVFN(data->id.device,
205 data->id.function)) {
206 data->dev = dev;
207 break;
208 }
209 }
210 }
198 if (!data->dev) { 211 if (!data->dev) {
199 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 212 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
200 "Device %02x:%02x:%02x.%02x not present in PCI namespace\n", 213 "Device %02x:%02x:%02x.%02x not present in PCI namespace\n",
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 7e6b8e3b2ed4..5d2f77fcd50c 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -46,6 +46,7 @@ ACPI_MODULE_NAME ("pci_root")
46 46
47static int acpi_pci_root_add (struct acpi_device *device); 47static int acpi_pci_root_add (struct acpi_device *device);
48static int acpi_pci_root_remove (struct acpi_device *device, int type); 48static int acpi_pci_root_remove (struct acpi_device *device, int type);
49static int acpi_pci_root_start (struct acpi_device *device);
49 50
50static struct acpi_driver acpi_pci_root_driver = { 51static struct acpi_driver acpi_pci_root_driver = {
51 .name = ACPI_PCI_ROOT_DRIVER_NAME, 52 .name = ACPI_PCI_ROOT_DRIVER_NAME,
@@ -54,6 +55,7 @@ static struct acpi_driver acpi_pci_root_driver = {
54 .ops = { 55 .ops = {
55 .add = acpi_pci_root_add, 56 .add = acpi_pci_root_add,
56 .remove = acpi_pci_root_remove, 57 .remove = acpi_pci_root_remove,
58 .start = acpi_pci_root_start,
57 }, 59 },
58}; 60};
59 61
@@ -169,6 +171,7 @@ acpi_pci_root_add (
169 if (!root) 171 if (!root)
170 return_VALUE(-ENOMEM); 172 return_VALUE(-ENOMEM);
171 memset(root, 0, sizeof(struct acpi_pci_root)); 173 memset(root, 0, sizeof(struct acpi_pci_root));
174 INIT_LIST_HEAD(&root->node);
172 175
173 root->handle = device->handle; 176 root->handle = device->handle;
174 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME); 177 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
@@ -298,12 +301,31 @@ acpi_pci_root_add (
298 root->id.bus); 301 root->id.bus);
299 302
300end: 303end:
301 if (result) 304 if (result) {
305 if (!list_empty(&root->node))
306 list_del(&root->node);
302 kfree(root); 307 kfree(root);
308 }
303 309
304 return_VALUE(result); 310 return_VALUE(result);
305} 311}
306 312
313static int
314acpi_pci_root_start (
315 struct acpi_device *device)
316{
317 struct acpi_pci_root *root;
318
319 ACPI_FUNCTION_TRACE("acpi_pci_root_start");
320
321 list_for_each_entry(root, &acpi_pci_roots, node) {
322 if (root->handle == device->handle) {
323 pci_bus_add_devices(root->bus);
324 return_VALUE(0);
325 }
326 }
327 return_VALUE(-ENODEV);
328}
307 329
308static int 330static int
309acpi_pci_root_remove ( 331acpi_pci_root_remove (
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index f4778747e889..76156ac91bd3 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -723,7 +723,7 @@ int acpi_processor_device_add(
723 return_VALUE(-ENODEV); 723 return_VALUE(-ENODEV);
724 } 724 }
725 725
726 acpi_bus_scan(*device); 726 acpi_bus_start(*device);
727 727
728 pr = acpi_driver_data(*device); 728 pr = acpi_driver_data(*device);
729 if (!pr) 729 if (!pr)
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index e85885593280..337d49b5564b 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -553,20 +553,29 @@ acpi_bus_driver_init (
553 * upon possible configuration and currently allocated resources. 553 * upon possible configuration and currently allocated resources.
554 */ 554 */
555 555
556 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Driver successfully bound to device\n"));
557 return_VALUE(0);
558}
559
560int
561acpi_start_single_object (
562 struct acpi_device *device)
563{
564 int result = 0;
565 struct acpi_driver *driver;
566
567 ACPI_FUNCTION_TRACE("acpi_start_single_object");
568
569 if (!(driver = device->driver))
570 return_VALUE(0);
571
556 if (driver->ops.start) { 572 if (driver->ops.start) {
557 result = driver->ops.start(device); 573 result = driver->ops.start(device);
558 if (result && driver->ops.remove) 574 if (result && driver->ops.remove)
559 driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL); 575 driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
560 return_VALUE(result);
561 } 576 }
562 577
563 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Driver successfully bound to device\n")); 578 return_VALUE(result);
564
565 if (driver->ops.scan) {
566 driver->ops.scan(device);
567 }
568
569 return_VALUE(0);
570} 579}
571 580
572static int acpi_driver_attach(struct acpi_driver * drv) 581static int acpi_driver_attach(struct acpi_driver * drv)
@@ -586,6 +595,7 @@ static int acpi_driver_attach(struct acpi_driver * drv)
586 595
587 if (!acpi_bus_match(dev, drv)) { 596 if (!acpi_bus_match(dev, drv)) {
588 if (!acpi_bus_driver_init(dev, drv)) { 597 if (!acpi_bus_driver_init(dev, drv)) {
598 acpi_start_single_object(dev);
589 atomic_inc(&drv->references); 599 atomic_inc(&drv->references);
590 count++; 600 count++;
591 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n", 601 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n",
@@ -1009,8 +1019,8 @@ acpi_bus_remove (
1009} 1019}
1010 1020
1011 1021
1012int 1022static int
1013acpi_bus_add ( 1023acpi_add_single_object (
1014 struct acpi_device **child, 1024 struct acpi_device **child,
1015 struct acpi_device *parent, 1025 struct acpi_device *parent,
1016 acpi_handle handle, 1026 acpi_handle handle,
@@ -1019,7 +1029,7 @@ acpi_bus_add (
1019 int result = 0; 1029 int result = 0;
1020 struct acpi_device *device = NULL; 1030 struct acpi_device *device = NULL;
1021 1031
1022 ACPI_FUNCTION_TRACE("acpi_bus_add"); 1032 ACPI_FUNCTION_TRACE("acpi_add_single_object");
1023 1033
1024 if (!child) 1034 if (!child)
1025 return_VALUE(-EINVAL); 1035 return_VALUE(-EINVAL);
@@ -1140,7 +1150,7 @@ acpi_bus_add (
1140 * 1150 *
1141 * TBD: Assumes LDM provides driver hot-plug capability. 1151 * TBD: Assumes LDM provides driver hot-plug capability.
1142 */ 1152 */
1143 acpi_bus_find_driver(device); 1153 result = acpi_bus_find_driver(device);
1144 1154
1145end: 1155end:
1146 if (!result) 1156 if (!result)
@@ -1153,10 +1163,10 @@ end:
1153 1163
1154 return_VALUE(result); 1164 return_VALUE(result);
1155} 1165}
1156EXPORT_SYMBOL(acpi_bus_add);
1157 1166
1158 1167
1159int acpi_bus_scan (struct acpi_device *start) 1168static int acpi_bus_scan (struct acpi_device *start,
1169 struct acpi_bus_ops *ops)
1160{ 1170{
1161 acpi_status status = AE_OK; 1171 acpi_status status = AE_OK;
1162 struct acpi_device *parent = NULL; 1172 struct acpi_device *parent = NULL;
@@ -1229,9 +1239,20 @@ int acpi_bus_scan (struct acpi_device *start)
1229 continue; 1239 continue;
1230 } 1240 }
1231 1241
1232 status = acpi_bus_add(&child, parent, chandle, type); 1242 if (ops->acpi_op_add)
1233 if (ACPI_FAILURE(status)) 1243 status = acpi_add_single_object(&child, parent,
1234 continue; 1244 chandle, type);
1245 else
1246 status = acpi_bus_get_device(chandle, &child);
1247
1248 if (ACPI_FAILURE(status))
1249 continue;
1250
1251 if (ops->acpi_op_start) {
1252 status = acpi_start_single_object(child);
1253 if (ACPI_FAILURE(status))
1254 continue;
1255 }
1235 1256
1236 /* 1257 /*
1237 * If the device is present, enabled, and functioning then 1258 * If the device is present, enabled, and functioning then
@@ -1257,8 +1278,50 @@ int acpi_bus_scan (struct acpi_device *start)
1257 1278
1258 return_VALUE(0); 1279 return_VALUE(0);
1259} 1280}
1260EXPORT_SYMBOL(acpi_bus_scan);
1261 1281
1282int
1283acpi_bus_add (
1284 struct acpi_device **child,
1285 struct acpi_device *parent,
1286 acpi_handle handle,
1287 int type)
1288{
1289 int result;
1290 struct acpi_bus_ops ops;
1291
1292 ACPI_FUNCTION_TRACE("acpi_bus_add");
1293
1294 result = acpi_add_single_object(child, parent, handle, type);
1295 if (!result) {
1296 memset(&ops, 0, sizeof(ops));
1297 ops.acpi_op_add = 1;
1298 result = acpi_bus_scan(*child, &ops);
1299 }
1300 return_VALUE(result);
1301}
1302EXPORT_SYMBOL(acpi_bus_add);
1303
1304int
1305acpi_bus_start (
1306 struct acpi_device *device)
1307{
1308 int result;
1309 struct acpi_bus_ops ops;
1310
1311 ACPI_FUNCTION_TRACE("acpi_bus_start");
1312
1313 if (!device)
1314 return_VALUE(-EINVAL);
1315
1316 result = acpi_start_single_object(device);
1317 if (!result) {
1318 memset(&ops, 0, sizeof(ops));
1319 ops.acpi_op_start = 1;
1320 result = acpi_bus_scan(device, &ops);
1321 }
1322 return_VALUE(result);
1323}
1324EXPORT_SYMBOL(acpi_bus_start);
1262 1325
1263static int 1326static int
1264acpi_bus_trim(struct acpi_device *start, 1327acpi_bus_trim(struct acpi_device *start,
@@ -1331,13 +1394,19 @@ acpi_bus_scan_fixed (
1331 /* 1394 /*
1332 * Enumerate all fixed-feature devices. 1395 * Enumerate all fixed-feature devices.
1333 */ 1396 */
1334 if (acpi_fadt.pwr_button == 0) 1397 if (acpi_fadt.pwr_button == 0) {
1335 result = acpi_bus_add(&device, acpi_root, 1398 result = acpi_add_single_object(&device, acpi_root,
1336 NULL, ACPI_BUS_TYPE_POWER_BUTTON); 1399 NULL, ACPI_BUS_TYPE_POWER_BUTTON);
1400 if (!result)
1401 result = acpi_start_single_object(device);
1402 }
1337 1403
1338 if (acpi_fadt.sleep_button == 0) 1404 if (acpi_fadt.sleep_button == 0) {
1339 result = acpi_bus_add(&device, acpi_root, 1405 result = acpi_add_single_object(&device, acpi_root,
1340 NULL, ACPI_BUS_TYPE_SLEEP_BUTTON); 1406 NULL, ACPI_BUS_TYPE_SLEEP_BUTTON);
1407 if (!result)
1408 result = acpi_start_single_object(device);
1409 }
1341 1410
1342 return_VALUE(result); 1411 return_VALUE(result);
1343} 1412}
@@ -1346,6 +1415,7 @@ acpi_bus_scan_fixed (
1346static int __init acpi_scan_init(void) 1415static int __init acpi_scan_init(void)
1347{ 1416{
1348 int result; 1417 int result;
1418 struct acpi_bus_ops ops;
1349 1419
1350 ACPI_FUNCTION_TRACE("acpi_scan_init"); 1420 ACPI_FUNCTION_TRACE("acpi_scan_init");
1351 1421
@@ -1357,17 +1427,23 @@ static int __init acpi_scan_init(void)
1357 /* 1427 /*
1358 * Create the root device in the bus's device tree 1428 * Create the root device in the bus's device tree
1359 */ 1429 */
1360 result = acpi_bus_add(&acpi_root, NULL, ACPI_ROOT_OBJECT, 1430 result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT,
1361 ACPI_BUS_TYPE_SYSTEM); 1431 ACPI_BUS_TYPE_SYSTEM);
1362 if (result) 1432 if (result)
1363 goto Done; 1433 goto Done;
1364 1434
1435 result = acpi_start_single_object(acpi_root);
1436
1365 /* 1437 /*
1366 * Enumerate devices in the ACPI namespace. 1438 * Enumerate devices in the ACPI namespace.
1367 */ 1439 */
1368 result = acpi_bus_scan_fixed(acpi_root); 1440 result = acpi_bus_scan_fixed(acpi_root);
1369 if (!result) 1441 if (!result) {
1370 result = acpi_bus_scan(acpi_root); 1442 memset(&ops, 0, sizeof(ops));
1443 ops.acpi_op_add = 1;
1444 ops.acpi_op_start = 1;
1445 result = acpi_bus_scan(acpi_root, &ops);
1446 }
1371 1447
1372 if (result) 1448 if (result)
1373 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL); 1449 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 97fe13f7f07c..652281402c92 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -74,6 +74,8 @@ static ssize_t
74firmware_timeout_store(struct class *class, const char *buf, size_t count) 74firmware_timeout_store(struct class *class, const char *buf, size_t count)
75{ 75{
76 loading_timeout = simple_strtol(buf, NULL, 10); 76 loading_timeout = simple_strtol(buf, NULL, 10);
77 if (loading_timeout < 0)
78 loading_timeout = 0;
77 return count; 79 return count;
78} 80}
79 81
@@ -138,6 +140,10 @@ firmware_loading_store(struct class_device *class_dev,
138 switch (loading) { 140 switch (loading) {
139 case 1: 141 case 1:
140 down(&fw_lock); 142 down(&fw_lock);
143 if (!fw_priv->fw) {
144 up(&fw_lock);
145 break;
146 }
141 vfree(fw_priv->fw->data); 147 vfree(fw_priv->fw->data);
142 fw_priv->fw->data = NULL; 148 fw_priv->fw->data = NULL;
143 fw_priv->fw->size = 0; 149 fw_priv->fw->size = 0;
@@ -178,7 +184,7 @@ firmware_data_read(struct kobject *kobj,
178 184
179 down(&fw_lock); 185 down(&fw_lock);
180 fw = fw_priv->fw; 186 fw = fw_priv->fw;
181 if (test_bit(FW_STATUS_DONE, &fw_priv->status)) { 187 if (!fw || test_bit(FW_STATUS_DONE, &fw_priv->status)) {
182 ret_count = -ENODEV; 188 ret_count = -ENODEV;
183 goto out; 189 goto out;
184 } 190 }
@@ -238,9 +244,10 @@ firmware_data_write(struct kobject *kobj,
238 244
239 if (!capable(CAP_SYS_RAWIO)) 245 if (!capable(CAP_SYS_RAWIO))
240 return -EPERM; 246 return -EPERM;
247
241 down(&fw_lock); 248 down(&fw_lock);
242 fw = fw_priv->fw; 249 fw = fw_priv->fw;
243 if (test_bit(FW_STATUS_DONE, &fw_priv->status)) { 250 if (!fw || test_bit(FW_STATUS_DONE, &fw_priv->status)) {
244 retval = -ENODEV; 251 retval = -ENODEV;
245 goto out; 252 goto out;
246 } 253 }
@@ -418,7 +425,7 @@ request_firmware(const struct firmware **firmware_p, const char *name,
418 425
419 fw_priv = class_get_devdata(class_dev); 426 fw_priv = class_get_devdata(class_dev);
420 427
421 if (loading_timeout) { 428 if (loading_timeout > 0) {
422 fw_priv->timeout.expires = jiffies + loading_timeout * HZ; 429 fw_priv->timeout.expires = jiffies + loading_timeout * HZ;
423 add_timer(&fw_priv->timeout); 430 add_timer(&fw_priv->timeout);
424 } 431 }
diff --git a/drivers/block/as-iosched.c b/drivers/block/as-iosched.c
index 3410b4d294b9..91aeb678135d 100644
--- a/drivers/block/as-iosched.c
+++ b/drivers/block/as-iosched.c
@@ -1806,7 +1806,8 @@ static void as_put_request(request_queue_t *q, struct request *rq)
1806 rq->elevator_private = NULL; 1806 rq->elevator_private = NULL;
1807} 1807}
1808 1808
1809static int as_set_request(request_queue_t *q, struct request *rq, int gfp_mask) 1809static int as_set_request(request_queue_t *q, struct request *rq,
1810 struct bio *bio, int gfp_mask)
1810{ 1811{
1811 struct as_data *ad = q->elevator->elevator_data; 1812 struct as_data *ad = q->elevator->elevator_data;
1812 struct as_rq *arq = mempool_alloc(ad->arq_pool, gfp_mask); 1813 struct as_rq *arq = mempool_alloc(ad->arq_pool, gfp_mask);
@@ -1827,7 +1828,7 @@ static int as_set_request(request_queue_t *q, struct request *rq, int gfp_mask)
1827 return 1; 1828 return 1;
1828} 1829}
1829 1830
1830static int as_may_queue(request_queue_t *q, int rw) 1831static int as_may_queue(request_queue_t *q, int rw, struct bio *bio)
1831{ 1832{
1832 int ret = ELV_MQUEUE_MAY; 1833 int ret = ELV_MQUEUE_MAY;
1833 struct as_data *ad = q->elevator->elevator_data; 1834 struct as_data *ad = q->elevator->elevator_data;
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index abde27027c06..3e9fb6e4a52a 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Disk Array driver for HP SA 5xxx and 6xxx Controllers 2 * Disk Array driver for HP SA 5xxx and 6xxx Controllers
3 * Copyright 2000, 2002 Hewlett-Packard Development Company, L.P. 3 * Copyright 2000, 2005 Hewlett-Packard Development Company, L.P.
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -54,7 +54,7 @@
54MODULE_AUTHOR("Hewlett-Packard Company"); 54MODULE_AUTHOR("Hewlett-Packard Company");
55MODULE_DESCRIPTION("Driver for HP Controller SA5xxx SA6xxx version 2.6.6"); 55MODULE_DESCRIPTION("Driver for HP Controller SA5xxx SA6xxx version 2.6.6");
56MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400" 56MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400"
57 " SA6i P600 P800 E400"); 57 " SA6i P600 P800 E400 E300");
58MODULE_LICENSE("GPL"); 58MODULE_LICENSE("GPL");
59 59
60#include "cciss_cmd.h" 60#include "cciss_cmd.h"
@@ -85,8 +85,10 @@ static const struct pci_device_id cciss_pci_device_id[] = {
85 0x103C, 0x3225, 0, 0, 0}, 85 0x103C, 0x3225, 0, 0, 0},
86 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSB, 86 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSB,
87 0x103c, 0x3223, 0, 0, 0}, 87 0x103c, 0x3223, 0, 0, 0},
88 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSB, 88 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC,
89 0x103c, 0x3231, 0, 0, 0}, 89 0x103c, 0x3231, 0, 0, 0},
90 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC,
91 0x103c, 0x3233, 0, 0, 0},
90 {0,} 92 {0,}
91}; 93};
92MODULE_DEVICE_TABLE(pci, cciss_pci_device_id); 94MODULE_DEVICE_TABLE(pci, cciss_pci_device_id);
@@ -110,6 +112,7 @@ static struct board_type products[] = {
110 { 0x3225103C, "Smart Array P600", &SA5_access}, 112 { 0x3225103C, "Smart Array P600", &SA5_access},
111 { 0x3223103C, "Smart Array P800", &SA5_access}, 113 { 0x3223103C, "Smart Array P800", &SA5_access},
112 { 0x3231103C, "Smart Array E400", &SA5_access}, 114 { 0x3231103C, "Smart Array E400", &SA5_access},
115 { 0x3233103C, "Smart Array E300", &SA5_access},
113}; 116};
114 117
115/* How long to wait (in millesconds) for board to go into simple mode */ 118/* How long to wait (in millesconds) for board to go into simple mode */
@@ -635,6 +638,7 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
635 cciss_pci_info_struct pciinfo; 638 cciss_pci_info_struct pciinfo;
636 639
637 if (!arg) return -EINVAL; 640 if (!arg) return -EINVAL;
641 pciinfo.domain = pci_domain_nr(host->pdev->bus);
638 pciinfo.bus = host->pdev->bus->number; 642 pciinfo.bus = host->pdev->bus->number;
639 pciinfo.dev_fn = host->pdev->devfn; 643 pciinfo.dev_fn = host->pdev->devfn;
640 pciinfo.board_id = host->board_id; 644 pciinfo.board_id = host->board_id;
@@ -782,18 +786,10 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
782 786
783 case CCISS_GETLUNINFO: { 787 case CCISS_GETLUNINFO: {
784 LogvolInfo_struct luninfo; 788 LogvolInfo_struct luninfo;
785 int i;
786 789
787 luninfo.LunID = drv->LunID; 790 luninfo.LunID = drv->LunID;
788 luninfo.num_opens = drv->usage_count; 791 luninfo.num_opens = drv->usage_count;
789 luninfo.num_parts = 0; 792 luninfo.num_parts = 0;
790 /* count partitions 1 to 15 with sizes > 0 */
791 for (i = 0; i < MAX_PART - 1; i++) {
792 if (!disk->part[i])
793 continue;
794 if (disk->part[i]->nr_sects != 0)
795 luninfo.num_parts++;
796 }
797 if (copy_to_user(argp, &luninfo, 793 if (copy_to_user(argp, &luninfo,
798 sizeof(LogvolInfo_struct))) 794 sizeof(LogvolInfo_struct)))
799 return -EFAULT; 795 return -EFAULT;
diff --git a/drivers/block/cfq-iosched.c b/drivers/block/cfq-iosched.c
index 3ac47dde64da..de5746e38af9 100644
--- a/drivers/block/cfq-iosched.c
+++ b/drivers/block/cfq-iosched.c
@@ -21,22 +21,34 @@
21#include <linux/hash.h> 21#include <linux/hash.h>
22#include <linux/rbtree.h> 22#include <linux/rbtree.h>
23#include <linux/mempool.h> 23#include <linux/mempool.h>
24 24#include <linux/ioprio.h>
25static unsigned long max_elapsed_crq; 25#include <linux/writeback.h>
26static unsigned long max_elapsed_dispatch;
27 26
28/* 27/*
29 * tunables 28 * tunables
30 */ 29 */
31static int cfq_quantum = 4; /* max queue in one round of service */ 30static int cfq_quantum = 4; /* max queue in one round of service */
32static int cfq_queued = 8; /* minimum rq allocate limit per-queue*/ 31static int cfq_queued = 8; /* minimum rq allocate limit per-queue*/
33static int cfq_service = HZ; /* period over which service is avg */ 32static int cfq_fifo_expire[2] = { HZ / 4, HZ / 8 };
34static int cfq_fifo_expire_r = HZ / 2; /* fifo timeout for sync requests */
35static int cfq_fifo_expire_w = 5 * HZ; /* fifo timeout for async requests */
36static int cfq_fifo_rate = HZ / 8; /* fifo expiry rate */
37static int cfq_back_max = 16 * 1024; /* maximum backwards seek, in KiB */ 33static int cfq_back_max = 16 * 1024; /* maximum backwards seek, in KiB */
38static int cfq_back_penalty = 2; /* penalty of a backwards seek */ 34static int cfq_back_penalty = 2; /* penalty of a backwards seek */
39 35
36static int cfq_slice_sync = HZ / 10;
37static int cfq_slice_async = HZ / 25;
38static int cfq_slice_async_rq = 2;
39static int cfq_slice_idle = HZ / 100;
40
41#define CFQ_IDLE_GRACE (HZ / 10)
42#define CFQ_SLICE_SCALE (5)
43
44#define CFQ_KEY_ASYNC (0)
45#define CFQ_KEY_ANY (0xffff)
46
47/*
48 * disable queueing at the driver/hardware level
49 */
50static int cfq_max_depth = 1;
51
40/* 52/*
41 * for the hash of cfqq inside the cfqd 53 * for the hash of cfqq inside the cfqd
42 */ 54 */
@@ -55,6 +67,7 @@ static int cfq_back_penalty = 2; /* penalty of a backwards seek */
55#define list_entry_hash(ptr) hlist_entry((ptr), struct cfq_rq, hash) 67#define list_entry_hash(ptr) hlist_entry((ptr), struct cfq_rq, hash)
56 68
57#define list_entry_cfqq(ptr) list_entry((ptr), struct cfq_queue, cfq_list) 69#define list_entry_cfqq(ptr) list_entry((ptr), struct cfq_queue, cfq_list)
70#define list_entry_fifo(ptr) list_entry((ptr), struct request, queuelist)
58 71
59#define RQ_DATA(rq) (rq)->elevator_private 72#define RQ_DATA(rq) (rq)->elevator_private
60 73
@@ -75,78 +88,110 @@ static int cfq_back_penalty = 2; /* penalty of a backwards seek */
75#define rb_entry_crq(node) rb_entry((node), struct cfq_rq, rb_node) 88#define rb_entry_crq(node) rb_entry((node), struct cfq_rq, rb_node)
76#define rq_rb_key(rq) (rq)->sector 89#define rq_rb_key(rq) (rq)->sector
77 90
78/*
79 * threshold for switching off non-tag accounting
80 */
81#define CFQ_MAX_TAG (4)
82
83/*
84 * sort key types and names
85 */
86enum {
87 CFQ_KEY_PGID,
88 CFQ_KEY_TGID,
89 CFQ_KEY_UID,
90 CFQ_KEY_GID,
91 CFQ_KEY_LAST,
92};
93
94static char *cfq_key_types[] = { "pgid", "tgid", "uid", "gid", NULL };
95
96static kmem_cache_t *crq_pool; 91static kmem_cache_t *crq_pool;
97static kmem_cache_t *cfq_pool; 92static kmem_cache_t *cfq_pool;
98static kmem_cache_t *cfq_ioc_pool; 93static kmem_cache_t *cfq_ioc_pool;
99 94
95#define CFQ_PRIO_LISTS IOPRIO_BE_NR
96#define cfq_class_idle(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_IDLE)
97#define cfq_class_be(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_BE)
98#define cfq_class_rt(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_RT)
99
100#define ASYNC (0)
101#define SYNC (1)
102
103#define cfq_cfqq_dispatched(cfqq) \
104 ((cfqq)->on_dispatch[ASYNC] + (cfqq)->on_dispatch[SYNC])
105
106#define cfq_cfqq_class_sync(cfqq) ((cfqq)->key != CFQ_KEY_ASYNC)
107
108#define cfq_cfqq_sync(cfqq) \
109 (cfq_cfqq_class_sync(cfqq) || (cfqq)->on_dispatch[SYNC])
110
111/*
112 * Per block device queue structure
113 */
100struct cfq_data { 114struct cfq_data {
101 struct list_head rr_list; 115 atomic_t ref;
116 request_queue_t *queue;
117
118 /*
119 * rr list of queues with requests and the count of them
120 */
121 struct list_head rr_list[CFQ_PRIO_LISTS];
122 struct list_head busy_rr;
123 struct list_head cur_rr;
124 struct list_head idle_rr;
125 unsigned int busy_queues;
126
127 /*
128 * non-ordered list of empty cfqq's
129 */
102 struct list_head empty_list; 130 struct list_head empty_list;
103 131
132 /*
133 * cfqq lookup hash
134 */
104 struct hlist_head *cfq_hash; 135 struct hlist_head *cfq_hash;
105 struct hlist_head *crq_hash;
106 136
107 /* queues on rr_list (ie they have pending requests */ 137 /*
108 unsigned int busy_queues; 138 * global crq hash for all queues
139 */
140 struct hlist_head *crq_hash;
109 141
110 unsigned int max_queued; 142 unsigned int max_queued;
111 143
112 atomic_t ref; 144 mempool_t *crq_pool;
113 145
114 int key_type; 146 int rq_in_driver;
115 147
116 mempool_t *crq_pool; 148 /*
149 * schedule slice state info
150 */
151 /*
152 * idle window management
153 */
154 struct timer_list idle_slice_timer;
155 struct work_struct unplug_work;
117 156
118 request_queue_t *queue; 157 struct cfq_queue *active_queue;
158 struct cfq_io_context *active_cic;
159 int cur_prio, cur_end_prio;
160 unsigned int dispatch_slice;
161
162 struct timer_list idle_class_timer;
119 163
120 sector_t last_sector; 164 sector_t last_sector;
165 unsigned long last_end_request;
121 166
122 int rq_in_driver; 167 unsigned int rq_starved;
123 168
124 /* 169 /*
125 * tunables, see top of file 170 * tunables, see top of file
126 */ 171 */
127 unsigned int cfq_quantum; 172 unsigned int cfq_quantum;
128 unsigned int cfq_queued; 173 unsigned int cfq_queued;
129 unsigned int cfq_fifo_expire_r; 174 unsigned int cfq_fifo_expire[2];
130 unsigned int cfq_fifo_expire_w;
131 unsigned int cfq_fifo_batch_expire;
132 unsigned int cfq_back_penalty; 175 unsigned int cfq_back_penalty;
133 unsigned int cfq_back_max; 176 unsigned int cfq_back_max;
134 unsigned int find_best_crq; 177 unsigned int cfq_slice[2];
135 178 unsigned int cfq_slice_async_rq;
136 unsigned int cfq_tagged; 179 unsigned int cfq_slice_idle;
180 unsigned int cfq_max_depth;
137}; 181};
138 182
183/*
184 * Per process-grouping structure
185 */
139struct cfq_queue { 186struct cfq_queue {
140 /* reference count */ 187 /* reference count */
141 atomic_t ref; 188 atomic_t ref;
142 /* parent cfq_data */ 189 /* parent cfq_data */
143 struct cfq_data *cfqd; 190 struct cfq_data *cfqd;
144 /* hash of mergeable requests */ 191 /* cfqq lookup hash */
145 struct hlist_node cfq_hash; 192 struct hlist_node cfq_hash;
146 /* hash key */ 193 /* hash key */
147 unsigned long key; 194 unsigned int key;
148 /* whether queue is on rr (or empty) list */
149 int on_rr;
150 /* on either rr or empty list of cfqd */ 195 /* on either rr or empty list of cfqd */
151 struct list_head cfq_list; 196 struct list_head cfq_list;
152 /* sorted list of pending requests */ 197 /* sorted list of pending requests */
@@ -158,21 +203,22 @@ struct cfq_queue {
158 /* currently allocated requests */ 203 /* currently allocated requests */
159 int allocated[2]; 204 int allocated[2];
160 /* fifo list of requests in sort_list */ 205 /* fifo list of requests in sort_list */
161 struct list_head fifo[2]; 206 struct list_head fifo;
162 /* last time fifo expired */
163 unsigned long last_fifo_expire;
164 207
165 int key_type; 208 unsigned long slice_start;
209 unsigned long slice_end;
210 unsigned long slice_left;
211 unsigned long service_last;
166 212
167 unsigned long service_start; 213 /* number of requests that are on the dispatch list */
168 unsigned long service_used; 214 int on_dispatch[2];
169 215
170 unsigned int max_rate; 216 /* io prio of this group */
217 unsigned short ioprio, org_ioprio;
218 unsigned short ioprio_class, org_ioprio_class;
171 219
172 /* number of requests that have been handed to the driver */ 220 /* various state flags, see below */
173 int in_flight; 221 unsigned int flags;
174 /* number of currently allocated requests */
175 int alloc_limit[2];
176}; 222};
177 223
178struct cfq_rq { 224struct cfq_rq {
@@ -184,42 +230,78 @@ struct cfq_rq {
184 struct cfq_queue *cfq_queue; 230 struct cfq_queue *cfq_queue;
185 struct cfq_io_context *io_context; 231 struct cfq_io_context *io_context;
186 232
187 unsigned long service_start; 233 unsigned int crq_flags;
188 unsigned long queue_start; 234};
235
236enum cfqq_state_flags {
237 CFQ_CFQQ_FLAG_on_rr = 0,
238 CFQ_CFQQ_FLAG_wait_request,
239 CFQ_CFQQ_FLAG_must_alloc,
240 CFQ_CFQQ_FLAG_must_alloc_slice,
241 CFQ_CFQQ_FLAG_must_dispatch,
242 CFQ_CFQQ_FLAG_fifo_expire,
243 CFQ_CFQQ_FLAG_idle_window,
244 CFQ_CFQQ_FLAG_prio_changed,
245 CFQ_CFQQ_FLAG_expired,
246};
189 247
190 unsigned int in_flight : 1; 248#define CFQ_CFQQ_FNS(name) \
191 unsigned int accounted : 1; 249static inline void cfq_mark_cfqq_##name(struct cfq_queue *cfqq) \
192 unsigned int is_sync : 1; 250{ \
193 unsigned int is_write : 1; 251 cfqq->flags |= (1 << CFQ_CFQQ_FLAG_##name); \
252} \
253static inline void cfq_clear_cfqq_##name(struct cfq_queue *cfqq) \
254{ \
255 cfqq->flags &= ~(1 << CFQ_CFQQ_FLAG_##name); \
256} \
257static inline int cfq_cfqq_##name(const struct cfq_queue *cfqq) \
258{ \
259 return (cfqq->flags & (1 << CFQ_CFQQ_FLAG_##name)) != 0; \
260}
261
262CFQ_CFQQ_FNS(on_rr);
263CFQ_CFQQ_FNS(wait_request);
264CFQ_CFQQ_FNS(must_alloc);
265CFQ_CFQQ_FNS(must_alloc_slice);
266CFQ_CFQQ_FNS(must_dispatch);
267CFQ_CFQQ_FNS(fifo_expire);
268CFQ_CFQQ_FNS(idle_window);
269CFQ_CFQQ_FNS(prio_changed);
270CFQ_CFQQ_FNS(expired);
271#undef CFQ_CFQQ_FNS
272
273enum cfq_rq_state_flags {
274 CFQ_CRQ_FLAG_in_flight = 0,
275 CFQ_CRQ_FLAG_in_driver,
276 CFQ_CRQ_FLAG_is_sync,
277 CFQ_CRQ_FLAG_requeued,
194}; 278};
195 279
196static struct cfq_queue *cfq_find_cfq_hash(struct cfq_data *, unsigned long); 280#define CFQ_CRQ_FNS(name) \
281static inline void cfq_mark_crq_##name(struct cfq_rq *crq) \
282{ \
283 crq->crq_flags |= (1 << CFQ_CRQ_FLAG_##name); \
284} \
285static inline void cfq_clear_crq_##name(struct cfq_rq *crq) \
286{ \
287 crq->crq_flags &= ~(1 << CFQ_CRQ_FLAG_##name); \
288} \
289static inline int cfq_crq_##name(const struct cfq_rq *crq) \
290{ \
291 return (crq->crq_flags & (1 << CFQ_CRQ_FLAG_##name)) != 0; \
292}
293
294CFQ_CRQ_FNS(in_flight);
295CFQ_CRQ_FNS(in_driver);
296CFQ_CRQ_FNS(is_sync);
297CFQ_CRQ_FNS(requeued);
298#undef CFQ_CRQ_FNS
299
300static struct cfq_queue *cfq_find_cfq_hash(struct cfq_data *, unsigned int, unsigned short);
197static void cfq_dispatch_sort(request_queue_t *, struct cfq_rq *); 301static void cfq_dispatch_sort(request_queue_t *, struct cfq_rq *);
198static void cfq_update_next_crq(struct cfq_rq *);
199static void cfq_put_cfqd(struct cfq_data *cfqd); 302static void cfq_put_cfqd(struct cfq_data *cfqd);
200 303
201/* 304#define process_sync(tsk) ((tsk)->flags & PF_SYNCWRITE)
202 * what the fairness is based on (ie how processes are grouped and
203 * differentiated)
204 */
205static inline unsigned long
206cfq_hash_key(struct cfq_data *cfqd, struct task_struct *tsk)
207{
208 /*
209 * optimize this so that ->key_type is the offset into the struct
210 */
211 switch (cfqd->key_type) {
212 case CFQ_KEY_PGID:
213 return process_group(tsk);
214 default:
215 case CFQ_KEY_TGID:
216 return tsk->tgid;
217 case CFQ_KEY_UID:
218 return tsk->uid;
219 case CFQ_KEY_GID:
220 return tsk->gid;
221 }
222}
223 305
224/* 306/*
225 * lots of deadline iosched dupes, can be abstracted later... 307 * lots of deadline iosched dupes, can be abstracted later...
@@ -235,16 +317,12 @@ static void cfq_remove_merge_hints(request_queue_t *q, struct cfq_rq *crq)
235 317
236 if (q->last_merge == crq->request) 318 if (q->last_merge == crq->request)
237 q->last_merge = NULL; 319 q->last_merge = NULL;
238
239 cfq_update_next_crq(crq);
240} 320}
241 321
242static inline void cfq_add_crq_hash(struct cfq_data *cfqd, struct cfq_rq *crq) 322static inline void cfq_add_crq_hash(struct cfq_data *cfqd, struct cfq_rq *crq)
243{ 323{
244 const int hash_idx = CFQ_MHASH_FN(rq_hash_key(crq->request)); 324 const int hash_idx = CFQ_MHASH_FN(rq_hash_key(crq->request));
245 325
246 BUG_ON(!hlist_unhashed(&crq->hash));
247
248 hlist_add_head(&crq->hash, &cfqd->crq_hash[hash_idx]); 326 hlist_add_head(&crq->hash, &cfqd->crq_hash[hash_idx]);
249} 327}
250 328
@@ -257,8 +335,6 @@ static struct request *cfq_find_rq_hash(struct cfq_data *cfqd, sector_t offset)
257 struct cfq_rq *crq = list_entry_hash(entry); 335 struct cfq_rq *crq = list_entry_hash(entry);
258 struct request *__rq = crq->request; 336 struct request *__rq = crq->request;
259 337
260 BUG_ON(hlist_unhashed(&crq->hash));
261
262 if (!rq_mergeable(__rq)) { 338 if (!rq_mergeable(__rq)) {
263 cfq_del_crq_hash(crq); 339 cfq_del_crq_hash(crq);
264 continue; 340 continue;
@@ -271,6 +347,28 @@ static struct request *cfq_find_rq_hash(struct cfq_data *cfqd, sector_t offset)
271 return NULL; 347 return NULL;
272} 348}
273 349
350static inline int cfq_pending_requests(struct cfq_data *cfqd)
351{
352 return !list_empty(&cfqd->queue->queue_head) || cfqd->busy_queues;
353}
354
355/*
356 * scheduler run of queue, if there are requests pending and no one in the
357 * driver that will restart queueing
358 */
359static inline void cfq_schedule_dispatch(struct cfq_data *cfqd)
360{
361 if (!cfqd->rq_in_driver && cfq_pending_requests(cfqd))
362 kblockd_schedule_work(&cfqd->unplug_work);
363}
364
365static int cfq_queue_empty(request_queue_t *q)
366{
367 struct cfq_data *cfqd = q->elevator->elevator_data;
368
369 return !cfq_pending_requests(cfqd);
370}
371
274/* 372/*
275 * Lifted from AS - choose which of crq1 and crq2 that is best served now. 373 * Lifted from AS - choose which of crq1 and crq2 that is best served now.
276 * We choose the request that is closest to the head right now. Distance 374 * We choose the request that is closest to the head right now. Distance
@@ -287,36 +385,16 @@ cfq_choose_req(struct cfq_data *cfqd, struct cfq_rq *crq1, struct cfq_rq *crq2)
287 return crq2; 385 return crq2;
288 if (crq2 == NULL) 386 if (crq2 == NULL)
289 return crq1; 387 return crq1;
388 if (cfq_crq_requeued(crq1))
389 return crq1;
390 if (cfq_crq_requeued(crq2))
391 return crq2;
290 392
291 s1 = crq1->request->sector; 393 s1 = crq1->request->sector;
292 s2 = crq2->request->sector; 394 s2 = crq2->request->sector;
293 395
294 last = cfqd->last_sector; 396 last = cfqd->last_sector;
295 397
296#if 0
297 if (!list_empty(&cfqd->queue->queue_head)) {
298 struct list_head *entry = &cfqd->queue->queue_head;
299 unsigned long distance = ~0UL;
300 struct request *rq;
301
302 while ((entry = entry->prev) != &cfqd->queue->queue_head) {
303 rq = list_entry_rq(entry);
304
305 if (blk_barrier_rq(rq))
306 break;
307
308 if (distance < abs(s1 - rq->sector + rq->nr_sectors)) {
309 distance = abs(s1 - rq->sector +rq->nr_sectors);
310 last = rq->sector + rq->nr_sectors;
311 }
312 if (distance < abs(s2 - rq->sector + rq->nr_sectors)) {
313 distance = abs(s2 - rq->sector +rq->nr_sectors);
314 last = rq->sector + rq->nr_sectors;
315 }
316 }
317 }
318#endif
319
320 /* 398 /*
321 * by definition, 1KiB is 2 sectors 399 * by definition, 1KiB is 2 sectors
322 */ 400 */
@@ -377,11 +455,14 @@ cfq_find_next_crq(struct cfq_data *cfqd, struct cfq_queue *cfqq,
377 struct cfq_rq *crq_next = NULL, *crq_prev = NULL; 455 struct cfq_rq *crq_next = NULL, *crq_prev = NULL;
378 struct rb_node *rbnext, *rbprev; 456 struct rb_node *rbnext, *rbprev;
379 457
380 if (!ON_RB(&last->rb_node)) 458 rbnext = NULL;
381 return NULL; 459 if (ON_RB(&last->rb_node))
382 460 rbnext = rb_next(&last->rb_node);
383 if ((rbnext = rb_next(&last->rb_node)) == NULL) 461 if (!rbnext) {
384 rbnext = rb_first(&cfqq->sort_list); 462 rbnext = rb_first(&cfqq->sort_list);
463 if (rbnext == &last->rb_node)
464 rbnext = NULL;
465 }
385 466
386 rbprev = rb_prev(&last->rb_node); 467 rbprev = rb_prev(&last->rb_node);
387 468
@@ -401,67 +482,53 @@ static void cfq_update_next_crq(struct cfq_rq *crq)
401 cfqq->next_crq = cfq_find_next_crq(cfqq->cfqd, cfqq, crq); 482 cfqq->next_crq = cfq_find_next_crq(cfqq->cfqd, cfqq, crq);
402} 483}
403 484
404static int cfq_check_sort_rr_list(struct cfq_queue *cfqq) 485static void cfq_resort_rr_list(struct cfq_queue *cfqq, int preempted)
405{ 486{
406 struct list_head *head = &cfqq->cfqd->rr_list; 487 struct cfq_data *cfqd = cfqq->cfqd;
407 struct list_head *next, *prev; 488 struct list_head *list, *entry;
408
409 /*
410 * list might still be ordered
411 */
412 next = cfqq->cfq_list.next;
413 if (next != head) {
414 struct cfq_queue *cnext = list_entry_cfqq(next);
415 489
416 if (cfqq->service_used > cnext->service_used) 490 BUG_ON(!cfq_cfqq_on_rr(cfqq));
417 return 1;
418 }
419 491
420 prev = cfqq->cfq_list.prev; 492 list_del(&cfqq->cfq_list);
421 if (prev != head) {
422 struct cfq_queue *cprev = list_entry_cfqq(prev);
423 493
424 if (cfqq->service_used < cprev->service_used) 494 if (cfq_class_rt(cfqq))
425 return 1; 495 list = &cfqd->cur_rr;
496 else if (cfq_class_idle(cfqq))
497 list = &cfqd->idle_rr;
498 else {
499 /*
500 * if cfqq has requests in flight, don't allow it to be
501 * found in cfq_set_active_queue before it has finished them.
502 * this is done to increase fairness between a process that
503 * has lots of io pending vs one that only generates one
504 * sporadically or synchronously
505 */
506 if (cfq_cfqq_dispatched(cfqq))
507 list = &cfqd->busy_rr;
508 else
509 list = &cfqd->rr_list[cfqq->ioprio];
426 } 510 }
427 511
428 return 0; 512 /*
429} 513 * if queue was preempted, just add to front to be fair. busy_rr
430 514 * isn't sorted.
431static void cfq_sort_rr_list(struct cfq_queue *cfqq, int new_queue) 515 */
432{ 516 if (preempted || list == &cfqd->busy_rr) {
433 struct list_head *entry = &cfqq->cfqd->rr_list; 517 list_add(&cfqq->cfq_list, list);
434
435 if (!cfqq->on_rr)
436 return;
437 if (!new_queue && !cfq_check_sort_rr_list(cfqq))
438 return; 518 return;
439 519 }
440 list_del(&cfqq->cfq_list);
441 520
442 /* 521 /*
443 * sort by our mean service_used, sub-sort by in-flight requests 522 * sort by when queue was last serviced
444 */ 523 */
445 while ((entry = entry->prev) != &cfqq->cfqd->rr_list) { 524 entry = list;
525 while ((entry = entry->prev) != list) {
446 struct cfq_queue *__cfqq = list_entry_cfqq(entry); 526 struct cfq_queue *__cfqq = list_entry_cfqq(entry);
447 527
448 if (cfqq->service_used > __cfqq->service_used) 528 if (!__cfqq->service_last)
529 break;
530 if (time_before(__cfqq->service_last, cfqq->service_last))
449 break; 531 break;
450 else if (cfqq->service_used == __cfqq->service_used) {
451 struct list_head *prv;
452
453 while ((prv = entry->prev) != &cfqq->cfqd->rr_list) {
454 __cfqq = list_entry_cfqq(prv);
455
456 WARN_ON(__cfqq->service_used > cfqq->service_used);
457 if (cfqq->service_used != __cfqq->service_used)
458 break;
459 if (cfqq->in_flight > __cfqq->in_flight)
460 break;
461
462 entry = prv;
463 }
464 }
465 } 532 }
466 533
467 list_add(&cfqq->cfq_list, entry); 534 list_add(&cfqq->cfq_list, entry);
@@ -469,28 +536,24 @@ static void cfq_sort_rr_list(struct cfq_queue *cfqq, int new_queue)
469 536
470/* 537/*
471 * add to busy list of queues for service, trying to be fair in ordering 538 * add to busy list of queues for service, trying to be fair in ordering
472 * the pending list according to requests serviced 539 * the pending list according to last request service
473 */ 540 */
474static inline void 541static inline void
475cfq_add_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq) 542cfq_add_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq, int requeue)
476{ 543{
477 /* 544 BUG_ON(cfq_cfqq_on_rr(cfqq));
478 * it's currently on the empty list 545 cfq_mark_cfqq_on_rr(cfqq);
479 */
480 cfqq->on_rr = 1;
481 cfqd->busy_queues++; 546 cfqd->busy_queues++;
482 547
483 if (time_after(jiffies, cfqq->service_start + cfq_service)) 548 cfq_resort_rr_list(cfqq, requeue);
484 cfqq->service_used >>= 3;
485
486 cfq_sort_rr_list(cfqq, 1);
487} 549}
488 550
489static inline void 551static inline void
490cfq_del_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq) 552cfq_del_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq)
491{ 553{
554 BUG_ON(!cfq_cfqq_on_rr(cfqq));
555 cfq_clear_cfqq_on_rr(cfqq);
492 list_move(&cfqq->cfq_list, &cfqd->empty_list); 556 list_move(&cfqq->cfq_list, &cfqd->empty_list);
493 cfqq->on_rr = 0;
494 557
495 BUG_ON(!cfqd->busy_queues); 558 BUG_ON(!cfqd->busy_queues);
496 cfqd->busy_queues--; 559 cfqd->busy_queues--;
@@ -505,16 +568,17 @@ static inline void cfq_del_crq_rb(struct cfq_rq *crq)
505 568
506 if (ON_RB(&crq->rb_node)) { 569 if (ON_RB(&crq->rb_node)) {
507 struct cfq_data *cfqd = cfqq->cfqd; 570 struct cfq_data *cfqd = cfqq->cfqd;
571 const int sync = cfq_crq_is_sync(crq);
508 572
509 BUG_ON(!cfqq->queued[crq->is_sync]); 573 BUG_ON(!cfqq->queued[sync]);
574 cfqq->queued[sync]--;
510 575
511 cfq_update_next_crq(crq); 576 cfq_update_next_crq(crq);
512 577
513 cfqq->queued[crq->is_sync]--;
514 rb_erase(&crq->rb_node, &cfqq->sort_list); 578 rb_erase(&crq->rb_node, &cfqq->sort_list);
515 RB_CLEAR_COLOR(&crq->rb_node); 579 RB_CLEAR_COLOR(&crq->rb_node);
516 580
517 if (RB_EMPTY(&cfqq->sort_list) && cfqq->on_rr) 581 if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY(&cfqq->sort_list))
518 cfq_del_cfqq_rr(cfqd, cfqq); 582 cfq_del_cfqq_rr(cfqd, cfqq);
519 } 583 }
520} 584}
@@ -550,7 +614,7 @@ static void cfq_add_crq_rb(struct cfq_rq *crq)
550 struct cfq_rq *__alias; 614 struct cfq_rq *__alias;
551 615
552 crq->rb_key = rq_rb_key(rq); 616 crq->rb_key = rq_rb_key(rq);
553 cfqq->queued[crq->is_sync]++; 617 cfqq->queued[cfq_crq_is_sync(crq)]++;
554 618
555 /* 619 /*
556 * looks a little odd, but the first insert might return an alias. 620 * looks a little odd, but the first insert might return an alias.
@@ -561,8 +625,8 @@ static void cfq_add_crq_rb(struct cfq_rq *crq)
561 625
562 rb_insert_color(&crq->rb_node, &cfqq->sort_list); 626 rb_insert_color(&crq->rb_node, &cfqq->sort_list);
563 627
564 if (!cfqq->on_rr) 628 if (!cfq_cfqq_on_rr(cfqq))
565 cfq_add_cfqq_rr(cfqd, cfqq); 629 cfq_add_cfqq_rr(cfqd, cfqq, cfq_crq_requeued(crq));
566 630
567 /* 631 /*
568 * check if this request is a better next-serve candidate 632 * check if this request is a better next-serve candidate
@@ -575,17 +639,16 @@ cfq_reposition_crq_rb(struct cfq_queue *cfqq, struct cfq_rq *crq)
575{ 639{
576 if (ON_RB(&crq->rb_node)) { 640 if (ON_RB(&crq->rb_node)) {
577 rb_erase(&crq->rb_node, &cfqq->sort_list); 641 rb_erase(&crq->rb_node, &cfqq->sort_list);
578 cfqq->queued[crq->is_sync]--; 642 cfqq->queued[cfq_crq_is_sync(crq)]--;
579 } 643 }
580 644
581 cfq_add_crq_rb(crq); 645 cfq_add_crq_rb(crq);
582} 646}
583 647
584static struct request * 648static struct request *cfq_find_rq_rb(struct cfq_data *cfqd, sector_t sector)
585cfq_find_rq_rb(struct cfq_data *cfqd, sector_t sector) 649
586{ 650{
587 const unsigned long key = cfq_hash_key(cfqd, current); 651 struct cfq_queue *cfqq = cfq_find_cfq_hash(cfqd, current->pid, CFQ_KEY_ANY);
588 struct cfq_queue *cfqq = cfq_find_cfq_hash(cfqd, key);
589 struct rb_node *n; 652 struct rb_node *n;
590 653
591 if (!cfqq) 654 if (!cfqq)
@@ -609,20 +672,25 @@ out:
609 672
610static void cfq_deactivate_request(request_queue_t *q, struct request *rq) 673static void cfq_deactivate_request(request_queue_t *q, struct request *rq)
611{ 674{
675 struct cfq_data *cfqd = q->elevator->elevator_data;
612 struct cfq_rq *crq = RQ_DATA(rq); 676 struct cfq_rq *crq = RQ_DATA(rq);
613 677
614 if (crq) { 678 if (crq) {
615 struct cfq_queue *cfqq = crq->cfq_queue; 679 struct cfq_queue *cfqq = crq->cfq_queue;
616 680
617 if (cfqq->cfqd->cfq_tagged) { 681 if (cfq_crq_in_driver(crq)) {
618 cfqq->service_used--; 682 cfq_clear_crq_in_driver(crq);
619 cfq_sort_rr_list(cfqq, 0); 683 WARN_ON(!cfqd->rq_in_driver);
684 cfqd->rq_in_driver--;
620 } 685 }
686 if (cfq_crq_in_flight(crq)) {
687 const int sync = cfq_crq_is_sync(crq);
621 688
622 if (crq->accounted) { 689 cfq_clear_crq_in_flight(crq);
623 crq->accounted = 0; 690 WARN_ON(!cfqq->on_dispatch[sync]);
624 cfqq->cfqd->rq_in_driver--; 691 cfqq->on_dispatch[sync]--;
625 } 692 }
693 cfq_mark_crq_requeued(crq);
626 } 694 }
627} 695}
628 696
@@ -640,11 +708,10 @@ static void cfq_remove_request(request_queue_t *q, struct request *rq)
640 struct cfq_rq *crq = RQ_DATA(rq); 708 struct cfq_rq *crq = RQ_DATA(rq);
641 709
642 if (crq) { 710 if (crq) {
643 cfq_remove_merge_hints(q, crq);
644 list_del_init(&rq->queuelist); 711 list_del_init(&rq->queuelist);
712 cfq_del_crq_rb(crq);
713 cfq_remove_merge_hints(q, crq);
645 714
646 if (crq->cfq_queue)
647 cfq_del_crq_rb(crq);
648 } 715 }
649} 716}
650 717
@@ -662,21 +729,15 @@ cfq_merge(request_queue_t *q, struct request **req, struct bio *bio)
662 } 729 }
663 730
664 __rq = cfq_find_rq_hash(cfqd, bio->bi_sector); 731 __rq = cfq_find_rq_hash(cfqd, bio->bi_sector);
665 if (__rq) { 732 if (__rq && elv_rq_merge_ok(__rq, bio)) {
666 BUG_ON(__rq->sector + __rq->nr_sectors != bio->bi_sector); 733 ret = ELEVATOR_BACK_MERGE;
667 734 goto out;
668 if (elv_rq_merge_ok(__rq, bio)) {
669 ret = ELEVATOR_BACK_MERGE;
670 goto out;
671 }
672 } 735 }
673 736
674 __rq = cfq_find_rq_rb(cfqd, bio->bi_sector + bio_sectors(bio)); 737 __rq = cfq_find_rq_rb(cfqd, bio->bi_sector + bio_sectors(bio));
675 if (__rq) { 738 if (__rq && elv_rq_merge_ok(__rq, bio)) {
676 if (elv_rq_merge_ok(__rq, bio)) { 739 ret = ELEVATOR_FRONT_MERGE;
677 ret = ELEVATOR_FRONT_MERGE; 740 goto out;
678 goto out;
679 }
680 } 741 }
681 742
682 return ELEVATOR_NO_MERGE; 743 return ELEVATOR_NO_MERGE;
@@ -709,20 +770,220 @@ static void
709cfq_merged_requests(request_queue_t *q, struct request *rq, 770cfq_merged_requests(request_queue_t *q, struct request *rq,
710 struct request *next) 771 struct request *next)
711{ 772{
712 struct cfq_rq *crq = RQ_DATA(rq);
713 struct cfq_rq *cnext = RQ_DATA(next);
714
715 cfq_merged_request(q, rq); 773 cfq_merged_request(q, rq);
716 774
717 if (!list_empty(&rq->queuelist) && !list_empty(&next->queuelist)) { 775 /*
718 if (time_before(cnext->queue_start, crq->queue_start)) { 776 * reposition in fifo if next is older than rq
719 list_move(&rq->queuelist, &next->queuelist); 777 */
720 crq->queue_start = cnext->queue_start; 778 if (!list_empty(&rq->queuelist) && !list_empty(&next->queuelist) &&
779 time_before(next->start_time, rq->start_time))
780 list_move(&rq->queuelist, &next->queuelist);
781
782 cfq_remove_request(q, next);
783}
784
785static inline void
786__cfq_set_active_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq)
787{
788 if (cfqq) {
789 /*
790 * stop potential idle class queues waiting service
791 */
792 del_timer(&cfqd->idle_class_timer);
793
794 cfqq->slice_start = jiffies;
795 cfqq->slice_end = 0;
796 cfqq->slice_left = 0;
797 cfq_clear_cfqq_must_alloc_slice(cfqq);
798 cfq_clear_cfqq_fifo_expire(cfqq);
799 cfq_clear_cfqq_expired(cfqq);
800 }
801
802 cfqd->active_queue = cfqq;
803}
804
805/*
806 * 0
807 * 0,1
808 * 0,1,2
809 * 0,1,2,3
810 * 0,1,2,3,4
811 * 0,1,2,3,4,5
812 * 0,1,2,3,4,5,6
813 * 0,1,2,3,4,5,6,7
814 */
815static int cfq_get_next_prio_level(struct cfq_data *cfqd)
816{
817 int prio, wrap;
818
819 prio = -1;
820 wrap = 0;
821 do {
822 int p;
823
824 for (p = cfqd->cur_prio; p <= cfqd->cur_end_prio; p++) {
825 if (!list_empty(&cfqd->rr_list[p])) {
826 prio = p;
827 break;
828 }
829 }
830
831 if (prio != -1)
832 break;
833 cfqd->cur_prio = 0;
834 if (++cfqd->cur_end_prio == CFQ_PRIO_LISTS) {
835 cfqd->cur_end_prio = 0;
836 if (wrap)
837 break;
838 wrap = 1;
721 } 839 }
840 } while (1);
841
842 if (unlikely(prio == -1))
843 return -1;
844
845 BUG_ON(prio >= CFQ_PRIO_LISTS);
846
847 list_splice_init(&cfqd->rr_list[prio], &cfqd->cur_rr);
848
849 cfqd->cur_prio = prio + 1;
850 if (cfqd->cur_prio > cfqd->cur_end_prio) {
851 cfqd->cur_end_prio = cfqd->cur_prio;
852 cfqd->cur_prio = 0;
853 }
854 if (cfqd->cur_end_prio == CFQ_PRIO_LISTS) {
855 cfqd->cur_prio = 0;
856 cfqd->cur_end_prio = 0;
722 } 857 }
723 858
724 cfq_update_next_crq(cnext); 859 return prio;
725 cfq_remove_request(q, next); 860}
861
862static struct cfq_queue *cfq_set_active_queue(struct cfq_data *cfqd)
863{
864 struct cfq_queue *cfqq;
865
866 /*
867 * if current queue is expired but not done with its requests yet,
868 * wait for that to happen
869 */
870 if ((cfqq = cfqd->active_queue) != NULL) {
871 if (cfq_cfqq_expired(cfqq) && cfq_cfqq_dispatched(cfqq))
872 return NULL;
873 }
874
875 /*
876 * if current list is non-empty, grab first entry. if it is empty,
877 * get next prio level and grab first entry then if any are spliced
878 */
879 if (!list_empty(&cfqd->cur_rr) || cfq_get_next_prio_level(cfqd) != -1)
880 cfqq = list_entry_cfqq(cfqd->cur_rr.next);
881
882 /*
883 * if we have idle queues and no rt or be queues had pending
884 * requests, either allow immediate service if the grace period
885 * has passed or arm the idle grace timer
886 */
887 if (!cfqq && !list_empty(&cfqd->idle_rr)) {
888 unsigned long end = cfqd->last_end_request + CFQ_IDLE_GRACE;
889
890 if (time_after_eq(jiffies, end))
891 cfqq = list_entry_cfqq(cfqd->idle_rr.next);
892 else
893 mod_timer(&cfqd->idle_class_timer, end);
894 }
895
896 __cfq_set_active_queue(cfqd, cfqq);
897 return cfqq;
898}
899
900/*
901 * current cfqq expired its slice (or was too idle), select new one
902 */
903static void
904__cfq_slice_expired(struct cfq_data *cfqd, struct cfq_queue *cfqq,
905 int preempted)
906{
907 unsigned long now = jiffies;
908
909 if (cfq_cfqq_wait_request(cfqq))
910 del_timer(&cfqd->idle_slice_timer);
911
912 if (!preempted && !cfq_cfqq_dispatched(cfqq))
913 cfqq->service_last = now;
914
915 cfq_clear_cfqq_must_dispatch(cfqq);
916 cfq_clear_cfqq_wait_request(cfqq);
917
918 /*
919 * store what was left of this slice, if the queue idled out
920 * or was preempted
921 */
922 if (time_after(now, cfqq->slice_end))
923 cfqq->slice_left = now - cfqq->slice_end;
924 else
925 cfqq->slice_left = 0;
926
927 if (cfq_cfqq_on_rr(cfqq))
928 cfq_resort_rr_list(cfqq, preempted);
929
930 if (cfqq == cfqd->active_queue)
931 cfqd->active_queue = NULL;
932
933 if (cfqd->active_cic) {
934 put_io_context(cfqd->active_cic->ioc);
935 cfqd->active_cic = NULL;
936 }
937
938 cfqd->dispatch_slice = 0;
939}
940
941static inline void cfq_slice_expired(struct cfq_data *cfqd, int preempted)
942{
943 struct cfq_queue *cfqq = cfqd->active_queue;
944
945 if (cfqq) {
946 /*
947 * use deferred expiry, if there are requests in progress as
948 * not to disturb the slice of the next queue
949 */
950 if (cfq_cfqq_dispatched(cfqq))
951 cfq_mark_cfqq_expired(cfqq);
952 else
953 __cfq_slice_expired(cfqd, cfqq, preempted);
954 }
955}
956
957static int cfq_arm_slice_timer(struct cfq_data *cfqd, struct cfq_queue *cfqq)
958
959{
960 WARN_ON(!RB_EMPTY(&cfqq->sort_list));
961 WARN_ON(cfqq != cfqd->active_queue);
962
963 /*
964 * idle is disabled, either manually or by past process history
965 */
966 if (!cfqd->cfq_slice_idle)
967 return 0;
968 if (!cfq_cfqq_idle_window(cfqq))
969 return 0;
970 /*
971 * task has exited, don't wait
972 */
973 if (cfqd->active_cic && !cfqd->active_cic->ioc->task)
974 return 0;
975
976 cfq_mark_cfqq_must_dispatch(cfqq);
977 cfq_mark_cfqq_wait_request(cfqq);
978
979 if (!timer_pending(&cfqd->idle_slice_timer)) {
980 unsigned long slice_left = min(cfqq->slice_end - 1, (unsigned long) cfqd->cfq_slice_idle);
981
982 cfqd->idle_slice_timer.expires = jiffies + slice_left;
983 add_timer(&cfqd->idle_slice_timer);
984 }
985
986 return 1;
726} 987}
727 988
728/* 989/*
@@ -738,31 +999,40 @@ static void cfq_dispatch_sort(request_queue_t *q, struct cfq_rq *crq)
738 struct request *__rq; 999 struct request *__rq;
739 sector_t last; 1000 sector_t last;
740 1001
741 cfq_del_crq_rb(crq);
742 cfq_remove_merge_hints(q, crq);
743 list_del(&crq->request->queuelist); 1002 list_del(&crq->request->queuelist);
744 1003
745 last = cfqd->last_sector; 1004 last = cfqd->last_sector;
746 while ((entry = entry->prev) != head) { 1005 list_for_each_entry_reverse(__rq, head, queuelist) {
747 __rq = list_entry_rq(entry); 1006 struct cfq_rq *__crq = RQ_DATA(__rq);
748 1007
749 if (blk_barrier_rq(crq->request)) 1008 if (blk_barrier_rq(__rq))
750 break; 1009 break;
751 if (!blk_fs_request(crq->request)) 1010 if (!blk_fs_request(__rq))
1011 break;
1012 if (cfq_crq_requeued(__crq))
752 break; 1013 break;
753 1014
754 if (crq->request->sector > __rq->sector) 1015 if (__rq->sector <= crq->request->sector)
755 break; 1016 break;
756 if (__rq->sector > last && crq->request->sector < last) { 1017 if (__rq->sector > last && crq->request->sector < last) {
757 last = crq->request->sector; 1018 last = crq->request->sector + crq->request->nr_sectors;
758 break; 1019 break;
759 } 1020 }
1021 entry = &__rq->queuelist;
760 } 1022 }
761 1023
762 cfqd->last_sector = last; 1024 cfqd->last_sector = last;
763 crq->in_flight = 1; 1025
764 cfqq->in_flight++; 1026 cfqq->next_crq = cfq_find_next_crq(cfqd, cfqq, crq);
765 list_add(&crq->request->queuelist, entry); 1027
1028 cfq_del_crq_rb(crq);
1029 cfq_remove_merge_hints(q, crq);
1030
1031 cfq_mark_crq_in_flight(crq);
1032 cfq_clear_crq_requeued(crq);
1033
1034 cfqq->on_dispatch[cfq_crq_is_sync(crq)]++;
1035 list_add_tail(&crq->request->queuelist, entry);
766} 1036}
767 1037
768/* 1038/*
@@ -771,173 +1041,225 @@ static void cfq_dispatch_sort(request_queue_t *q, struct cfq_rq *crq)
771static inline struct cfq_rq *cfq_check_fifo(struct cfq_queue *cfqq) 1041static inline struct cfq_rq *cfq_check_fifo(struct cfq_queue *cfqq)
772{ 1042{
773 struct cfq_data *cfqd = cfqq->cfqd; 1043 struct cfq_data *cfqd = cfqq->cfqd;
774 const int reads = !list_empty(&cfqq->fifo[0]); 1044 struct request *rq;
775 const int writes = !list_empty(&cfqq->fifo[1]);
776 unsigned long now = jiffies;
777 struct cfq_rq *crq; 1045 struct cfq_rq *crq;
778 1046
779 if (time_before(now, cfqq->last_fifo_expire + cfqd->cfq_fifo_batch_expire)) 1047 if (cfq_cfqq_fifo_expire(cfqq))
780 return NULL; 1048 return NULL;
781 1049
782 crq = RQ_DATA(list_entry(cfqq->fifo[0].next, struct request, queuelist)); 1050 if (!list_empty(&cfqq->fifo)) {
783 if (reads && time_after(now, crq->queue_start + cfqd->cfq_fifo_expire_r)) { 1051 int fifo = cfq_cfqq_class_sync(cfqq);
784 cfqq->last_fifo_expire = now;
785 return crq;
786 }
787 1052
788 crq = RQ_DATA(list_entry(cfqq->fifo[1].next, struct request, queuelist)); 1053 crq = RQ_DATA(list_entry_fifo(cfqq->fifo.next));
789 if (writes && time_after(now, crq->queue_start + cfqd->cfq_fifo_expire_w)) { 1054 rq = crq->request;
790 cfqq->last_fifo_expire = now; 1055 if (time_after(jiffies, rq->start_time + cfqd->cfq_fifo_expire[fifo])) {
791 return crq; 1056 cfq_mark_cfqq_fifo_expire(cfqq);
1057 return crq;
1058 }
792 } 1059 }
793 1060
794 return NULL; 1061 return NULL;
795} 1062}
796 1063
797/* 1064/*
798 * dispatch a single request from given queue 1065 * Scale schedule slice based on io priority. Use the sync time slice only
1066 * if a queue is marked sync and has sync io queued. A sync queue with async
1067 * io only, should not get full sync slice length.
799 */ 1068 */
1069static inline int
1070cfq_prio_to_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1071{
1072 const int base_slice = cfqd->cfq_slice[cfq_cfqq_sync(cfqq)];
1073
1074 WARN_ON(cfqq->ioprio >= IOPRIO_BE_NR);
1075
1076 return base_slice + (base_slice/CFQ_SLICE_SCALE * (4 - cfqq->ioprio));
1077}
1078
800static inline void 1079static inline void
801cfq_dispatch_request(request_queue_t *q, struct cfq_data *cfqd, 1080cfq_set_prio_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
802 struct cfq_queue *cfqq)
803{ 1081{
804 struct cfq_rq *crq; 1082 cfqq->slice_end = cfq_prio_to_slice(cfqd, cfqq) + jiffies;
1083}
1084
1085static inline int
1086cfq_prio_to_maxrq(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1087{
1088 const int base_rq = cfqd->cfq_slice_async_rq;
1089
1090 WARN_ON(cfqq->ioprio >= IOPRIO_BE_NR);
1091
1092 return 2 * (base_rq + base_rq * (CFQ_PRIO_LISTS - 1 - cfqq->ioprio));
1093}
1094
1095/*
1096 * get next queue for service
1097 */
1098static struct cfq_queue *cfq_select_queue(struct cfq_data *cfqd, int force)
1099{
1100 unsigned long now = jiffies;
1101 struct cfq_queue *cfqq;
1102
1103 cfqq = cfqd->active_queue;
1104 if (!cfqq)
1105 goto new_queue;
1106
1107 if (cfq_cfqq_expired(cfqq))
1108 goto new_queue;
805 1109
806 /* 1110 /*
807 * follow expired path, else get first next available 1111 * slice has expired
808 */ 1112 */
809 if ((crq = cfq_check_fifo(cfqq)) == NULL) { 1113 if (!cfq_cfqq_must_dispatch(cfqq) && time_after(now, cfqq->slice_end))
810 if (cfqd->find_best_crq) 1114 goto expire;
811 crq = cfqq->next_crq;
812 else
813 crq = rb_entry_crq(rb_first(&cfqq->sort_list));
814 }
815
816 cfqd->last_sector = crq->request->sector + crq->request->nr_sectors;
817 1115
818 /* 1116 /*
819 * finally, insert request into driver list 1117 * if queue has requests, dispatch one. if not, check if
1118 * enough slice is left to wait for one
820 */ 1119 */
821 cfq_dispatch_sort(q, crq); 1120 if (!RB_EMPTY(&cfqq->sort_list))
1121 goto keep_queue;
1122 else if (!force && cfq_cfqq_class_sync(cfqq) &&
1123 time_before(now, cfqq->slice_end)) {
1124 if (cfq_arm_slice_timer(cfqd, cfqq))
1125 return NULL;
1126 }
1127
1128expire:
1129 cfq_slice_expired(cfqd, 0);
1130new_queue:
1131 cfqq = cfq_set_active_queue(cfqd);
1132keep_queue:
1133 return cfqq;
822} 1134}
823 1135
824static int cfq_dispatch_requests(request_queue_t *q, int max_dispatch) 1136static int
1137__cfq_dispatch_requests(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1138 int max_dispatch)
825{ 1139{
826 struct cfq_data *cfqd = q->elevator->elevator_data; 1140 int dispatched = 0;
827 struct cfq_queue *cfqq;
828 struct list_head *entry, *tmp;
829 int queued, busy_queues, first_round;
830 1141
831 if (list_empty(&cfqd->rr_list)) 1142 BUG_ON(RB_EMPTY(&cfqq->sort_list));
832 return 0;
833 1143
834 queued = 0; 1144 do {
835 first_round = 1; 1145 struct cfq_rq *crq;
836restart:
837 busy_queues = 0;
838 list_for_each_safe(entry, tmp, &cfqd->rr_list) {
839 cfqq = list_entry_cfqq(entry);
840 1146
841 BUG_ON(RB_EMPTY(&cfqq->sort_list)); 1147 /*
1148 * follow expired path, else get first next available
1149 */
1150 if ((crq = cfq_check_fifo(cfqq)) == NULL)
1151 crq = cfqq->next_crq;
842 1152
843 /* 1153 /*
844 * first round of queueing, only select from queues that 1154 * finally, insert request into driver dispatch list
845 * don't already have io in-flight
846 */ 1155 */
847 if (first_round && cfqq->in_flight) 1156 cfq_dispatch_sort(cfqd->queue, crq);
848 continue;
849 1157
850 cfq_dispatch_request(q, cfqd, cfqq); 1158 cfqd->dispatch_slice++;
1159 dispatched++;
851 1160
852 if (!RB_EMPTY(&cfqq->sort_list)) 1161 if (!cfqd->active_cic) {
853 busy_queues++; 1162 atomic_inc(&crq->io_context->ioc->refcount);
1163 cfqd->active_cic = crq->io_context;
1164 }
854 1165
855 queued++; 1166 if (RB_EMPTY(&cfqq->sort_list))
856 } 1167 break;
1168
1169 } while (dispatched < max_dispatch);
1170
1171 /*
1172 * if slice end isn't set yet, set it. if at least one request was
1173 * sync, use the sync time slice value
1174 */
1175 if (!cfqq->slice_end)
1176 cfq_set_prio_slice(cfqd, cfqq);
1177
1178 /*
1179 * expire an async queue immediately if it has used up its slice. idle
1180 * queue always expire after 1 dispatch round.
1181 */
1182 if ((!cfq_cfqq_sync(cfqq) &&
1183 cfqd->dispatch_slice >= cfq_prio_to_maxrq(cfqd, cfqq)) ||
1184 cfq_class_idle(cfqq))
1185 cfq_slice_expired(cfqd, 0);
1186
1187 return dispatched;
1188}
1189
1190static int
1191cfq_dispatch_requests(request_queue_t *q, int max_dispatch, int force)
1192{
1193 struct cfq_data *cfqd = q->elevator->elevator_data;
1194 struct cfq_queue *cfqq;
1195
1196 if (!cfqd->busy_queues)
1197 return 0;
1198
1199 cfqq = cfq_select_queue(cfqd, force);
1200 if (cfqq) {
1201 cfq_clear_cfqq_must_dispatch(cfqq);
1202 cfq_clear_cfqq_wait_request(cfqq);
1203 del_timer(&cfqd->idle_slice_timer);
857 1204
858 if ((queued < max_dispatch) && (busy_queues || first_round)) { 1205 if (cfq_class_idle(cfqq))
859 first_round = 0; 1206 max_dispatch = 1;
860 goto restart; 1207
1208 return __cfq_dispatch_requests(cfqd, cfqq, max_dispatch);
861 } 1209 }
862 1210
863 return queued; 1211 return 0;
864} 1212}
865 1213
866static inline void cfq_account_dispatch(struct cfq_rq *crq) 1214static inline void cfq_account_dispatch(struct cfq_rq *crq)
867{ 1215{
868 struct cfq_queue *cfqq = crq->cfq_queue; 1216 struct cfq_queue *cfqq = crq->cfq_queue;
869 struct cfq_data *cfqd = cfqq->cfqd; 1217 struct cfq_data *cfqd = cfqq->cfqd;
870 unsigned long now, elapsed;
871 1218
872 if (!blk_fs_request(crq->request)) 1219 if (unlikely(!blk_fs_request(crq->request)))
873 return; 1220 return;
874 1221
875 /* 1222 /*
876 * accounted bit is necessary since some drivers will call 1223 * accounted bit is necessary since some drivers will call
877 * elv_next_request() many times for the same request (eg ide) 1224 * elv_next_request() many times for the same request (eg ide)
878 */ 1225 */
879 if (crq->accounted) 1226 if (cfq_crq_in_driver(crq))
880 return; 1227 return;
881 1228
882 now = jiffies; 1229 cfq_mark_crq_in_driver(crq);
883 if (cfqq->service_start == ~0UL) 1230 cfqd->rq_in_driver++;
884 cfqq->service_start = now;
885
886 /*
887 * on drives with tagged command queueing, command turn-around time
888 * doesn't necessarily reflect the time spent processing this very
889 * command inside the drive. so do the accounting differently there,
890 * by just sorting on the number of requests
891 */
892 if (cfqd->cfq_tagged) {
893 if (time_after(now, cfqq->service_start + cfq_service)) {
894 cfqq->service_start = now;
895 cfqq->service_used /= 10;
896 }
897
898 cfqq->service_used++;
899 cfq_sort_rr_list(cfqq, 0);
900 }
901
902 elapsed = now - crq->queue_start;
903 if (elapsed > max_elapsed_dispatch)
904 max_elapsed_dispatch = elapsed;
905
906 crq->accounted = 1;
907 crq->service_start = now;
908
909 if (++cfqd->rq_in_driver >= CFQ_MAX_TAG && !cfqd->cfq_tagged) {
910 cfqq->cfqd->cfq_tagged = 1;
911 printk("cfq: depth %d reached, tagging now on\n", CFQ_MAX_TAG);
912 }
913} 1231}
914 1232
915static inline void 1233static inline void
916cfq_account_completion(struct cfq_queue *cfqq, struct cfq_rq *crq) 1234cfq_account_completion(struct cfq_queue *cfqq, struct cfq_rq *crq)
917{ 1235{
918 struct cfq_data *cfqd = cfqq->cfqd; 1236 struct cfq_data *cfqd = cfqq->cfqd;
1237 unsigned long now;
919 1238
920 if (!crq->accounted) 1239 if (!cfq_crq_in_driver(crq))
921 return; 1240 return;
922 1241
1242 now = jiffies;
1243
923 WARN_ON(!cfqd->rq_in_driver); 1244 WARN_ON(!cfqd->rq_in_driver);
924 cfqd->rq_in_driver--; 1245 cfqd->rq_in_driver--;
925 1246
926 if (!cfqd->cfq_tagged) { 1247 if (!cfq_class_idle(cfqq))
927 unsigned long now = jiffies; 1248 cfqd->last_end_request = now;
928 unsigned long duration = now - crq->service_start;
929 1249
930 if (time_after(now, cfqq->service_start + cfq_service)) { 1250 if (!cfq_cfqq_dispatched(cfqq)) {
931 cfqq->service_start = now; 1251 if (cfq_cfqq_on_rr(cfqq)) {
932 cfqq->service_used >>= 3; 1252 cfqq->service_last = now;
1253 cfq_resort_rr_list(cfqq, 0);
1254 }
1255 if (cfq_cfqq_expired(cfqq)) {
1256 __cfq_slice_expired(cfqd, cfqq, 0);
1257 cfq_schedule_dispatch(cfqd);
933 } 1258 }
934
935 cfqq->service_used += duration;
936 cfq_sort_rr_list(cfqq, 0);
937
938 if (duration > max_elapsed_crq)
939 max_elapsed_crq = duration;
940 } 1259 }
1260
1261 if (cfq_crq_is_sync(crq))
1262 crq->io_context->last_end_request = now;
941} 1263}
942 1264
943static struct request *cfq_next_request(request_queue_t *q) 1265static struct request *cfq_next_request(request_queue_t *q)
@@ -950,7 +1272,18 @@ static struct request *cfq_next_request(request_queue_t *q)
950dispatch: 1272dispatch:
951 rq = list_entry_rq(q->queue_head.next); 1273 rq = list_entry_rq(q->queue_head.next);
952 1274
953 if ((crq = RQ_DATA(rq)) != NULL) { 1275 crq = RQ_DATA(rq);
1276 if (crq) {
1277 struct cfq_queue *cfqq = crq->cfq_queue;
1278
1279 /*
1280 * if idle window is disabled, allow queue buildup
1281 */
1282 if (!cfq_crq_in_driver(crq) &&
1283 !cfq_cfqq_idle_window(cfqq) &&
1284 cfqd->rq_in_driver >= cfqd->cfq_max_depth)
1285 return NULL;
1286
954 cfq_remove_merge_hints(q, crq); 1287 cfq_remove_merge_hints(q, crq);
955 cfq_account_dispatch(crq); 1288 cfq_account_dispatch(crq);
956 } 1289 }
@@ -958,7 +1291,7 @@ dispatch:
958 return rq; 1291 return rq;
959 } 1292 }
960 1293
961 if (cfq_dispatch_requests(q, cfqd->cfq_quantum)) 1294 if (cfq_dispatch_requests(q, cfqd->cfq_quantum, 0))
962 goto dispatch; 1295 goto dispatch;
963 1296
964 return NULL; 1297 return NULL;
@@ -972,13 +1305,21 @@ dispatch:
972 */ 1305 */
973static void cfq_put_queue(struct cfq_queue *cfqq) 1306static void cfq_put_queue(struct cfq_queue *cfqq)
974{ 1307{
975 BUG_ON(!atomic_read(&cfqq->ref)); 1308 struct cfq_data *cfqd = cfqq->cfqd;
1309
1310 BUG_ON(atomic_read(&cfqq->ref) <= 0);
976 1311
977 if (!atomic_dec_and_test(&cfqq->ref)) 1312 if (!atomic_dec_and_test(&cfqq->ref))
978 return; 1313 return;
979 1314
980 BUG_ON(rb_first(&cfqq->sort_list)); 1315 BUG_ON(rb_first(&cfqq->sort_list));
981 BUG_ON(cfqq->on_rr); 1316 BUG_ON(cfqq->allocated[READ] + cfqq->allocated[WRITE]);
1317 BUG_ON(cfq_cfqq_on_rr(cfqq));
1318
1319 if (unlikely(cfqd->active_queue == cfqq)) {
1320 __cfq_slice_expired(cfqd, cfqq, 0);
1321 cfq_schedule_dispatch(cfqd);
1322 }
982 1323
983 cfq_put_cfqd(cfqq->cfqd); 1324 cfq_put_cfqd(cfqq->cfqd);
984 1325
@@ -991,15 +1332,17 @@ static void cfq_put_queue(struct cfq_queue *cfqq)
991} 1332}
992 1333
993static inline struct cfq_queue * 1334static inline struct cfq_queue *
994__cfq_find_cfq_hash(struct cfq_data *cfqd, unsigned long key, const int hashval) 1335__cfq_find_cfq_hash(struct cfq_data *cfqd, unsigned int key, unsigned int prio,
1336 const int hashval)
995{ 1337{
996 struct hlist_head *hash_list = &cfqd->cfq_hash[hashval]; 1338 struct hlist_head *hash_list = &cfqd->cfq_hash[hashval];
997 struct hlist_node *entry, *next; 1339 struct hlist_node *entry, *next;
998 1340
999 hlist_for_each_safe(entry, next, hash_list) { 1341 hlist_for_each_safe(entry, next, hash_list) {
1000 struct cfq_queue *__cfqq = list_entry_qhash(entry); 1342 struct cfq_queue *__cfqq = list_entry_qhash(entry);
1343 const unsigned short __p = IOPRIO_PRIO_VALUE(__cfqq->ioprio_class, __cfqq->ioprio);
1001 1344
1002 if (__cfqq->key == key) 1345 if (__cfqq->key == key && (__p == prio || prio == CFQ_KEY_ANY))
1003 return __cfqq; 1346 return __cfqq;
1004 } 1347 }
1005 1348
@@ -1007,94 +1350,220 @@ __cfq_find_cfq_hash(struct cfq_data *cfqd, unsigned long key, const int hashval)
1007} 1350}
1008 1351
1009static struct cfq_queue * 1352static struct cfq_queue *
1010cfq_find_cfq_hash(struct cfq_data *cfqd, unsigned long key) 1353cfq_find_cfq_hash(struct cfq_data *cfqd, unsigned int key, unsigned short prio)
1011{ 1354{
1012 return __cfq_find_cfq_hash(cfqd, key, hash_long(key, CFQ_QHASH_SHIFT)); 1355 return __cfq_find_cfq_hash(cfqd, key, prio, hash_long(key, CFQ_QHASH_SHIFT));
1013} 1356}
1014 1357
1015static inline void 1358static void cfq_free_io_context(struct cfq_io_context *cic)
1016cfq_rehash_cfqq(struct cfq_data *cfqd, struct cfq_queue **cfqq,
1017 struct cfq_io_context *cic)
1018{ 1359{
1019 unsigned long hashkey = cfq_hash_key(cfqd, current); 1360 struct cfq_io_context *__cic;
1020 unsigned long hashval = hash_long(hashkey, CFQ_QHASH_SHIFT); 1361 struct list_head *entry, *next;
1021 struct cfq_queue *__cfqq;
1022 unsigned long flags;
1023
1024 spin_lock_irqsave(cfqd->queue->queue_lock, flags);
1025 1362
1026 hlist_del(&(*cfqq)->cfq_hash); 1363 list_for_each_safe(entry, next, &cic->list) {
1027 1364 __cic = list_entry(entry, struct cfq_io_context, list);
1028 __cfqq = __cfq_find_cfq_hash(cfqd, hashkey, hashval); 1365 kmem_cache_free(cfq_ioc_pool, __cic);
1029 if (!__cfqq || __cfqq == *cfqq) {
1030 __cfqq = *cfqq;
1031 hlist_add_head(&__cfqq->cfq_hash, &cfqd->cfq_hash[hashval]);
1032 __cfqq->key_type = cfqd->key_type;
1033 } else {
1034 atomic_inc(&__cfqq->ref);
1035 cic->cfqq = __cfqq;
1036 cfq_put_queue(*cfqq);
1037 *cfqq = __cfqq;
1038 } 1366 }
1039 1367
1040 cic->cfqq = __cfqq; 1368 kmem_cache_free(cfq_ioc_pool, cic);
1041 spin_unlock_irqrestore(cfqd->queue->queue_lock, flags);
1042} 1369}
1043 1370
1044static void cfq_free_io_context(struct cfq_io_context *cic) 1371/*
1372 * Called with interrupts disabled
1373 */
1374static void cfq_exit_single_io_context(struct cfq_io_context *cic)
1045{ 1375{
1046 kmem_cache_free(cfq_ioc_pool, cic); 1376 struct cfq_data *cfqd = cic->cfqq->cfqd;
1377 request_queue_t *q = cfqd->queue;
1378
1379 WARN_ON(!irqs_disabled());
1380
1381 spin_lock(q->queue_lock);
1382
1383 if (unlikely(cic->cfqq == cfqd->active_queue)) {
1384 __cfq_slice_expired(cfqd, cic->cfqq, 0);
1385 cfq_schedule_dispatch(cfqd);
1386 }
1387
1388 cfq_put_queue(cic->cfqq);
1389 cic->cfqq = NULL;
1390 spin_unlock(q->queue_lock);
1047} 1391}
1048 1392
1049/* 1393/*
1050 * locking hierarchy is: io_context lock -> queue locks 1394 * Another task may update the task cic list, if it is doing a queue lookup
1395 * on its behalf. cfq_cic_lock excludes such concurrent updates
1051 */ 1396 */
1052static void cfq_exit_io_context(struct cfq_io_context *cic) 1397static void cfq_exit_io_context(struct cfq_io_context *cic)
1053{ 1398{
1054 struct cfq_queue *cfqq = cic->cfqq; 1399 struct cfq_io_context *__cic;
1055 struct list_head *entry = &cic->list; 1400 struct list_head *entry;
1056 request_queue_t *q;
1057 unsigned long flags; 1401 unsigned long flags;
1058 1402
1403 local_irq_save(flags);
1404
1059 /* 1405 /*
1060 * put the reference this task is holding to the various queues 1406 * put the reference this task is holding to the various queues
1061 */ 1407 */
1062 spin_lock_irqsave(&cic->ioc->lock, flags); 1408 list_for_each(entry, &cic->list) {
1063 while ((entry = cic->list.next) != &cic->list) {
1064 struct cfq_io_context *__cic;
1065
1066 __cic = list_entry(entry, struct cfq_io_context, list); 1409 __cic = list_entry(entry, struct cfq_io_context, list);
1067 list_del(entry); 1410 cfq_exit_single_io_context(__cic);
1068
1069 q = __cic->cfqq->cfqd->queue;
1070 spin_lock(q->queue_lock);
1071 cfq_put_queue(__cic->cfqq);
1072 spin_unlock(q->queue_lock);
1073 } 1411 }
1074 1412
1075 q = cfqq->cfqd->queue; 1413 cfq_exit_single_io_context(cic);
1076 spin_lock(q->queue_lock); 1414 local_irq_restore(flags);
1077 cfq_put_queue(cfqq);
1078 spin_unlock(q->queue_lock);
1079
1080 cic->cfqq = NULL;
1081 spin_unlock_irqrestore(&cic->ioc->lock, flags);
1082} 1415}
1083 1416
1084static struct cfq_io_context *cfq_alloc_io_context(int gfp_flags) 1417static struct cfq_io_context *
1418cfq_alloc_io_context(struct cfq_data *cfqd, int gfp_mask)
1085{ 1419{
1086 struct cfq_io_context *cic = kmem_cache_alloc(cfq_ioc_pool, gfp_flags); 1420 struct cfq_io_context *cic = kmem_cache_alloc(cfq_ioc_pool, gfp_mask);
1087 1421
1088 if (cic) { 1422 if (cic) {
1089 cic->dtor = cfq_free_io_context;
1090 cic->exit = cfq_exit_io_context;
1091 INIT_LIST_HEAD(&cic->list); 1423 INIT_LIST_HEAD(&cic->list);
1092 cic->cfqq = NULL; 1424 cic->cfqq = NULL;
1425 cic->key = NULL;
1426 cic->last_end_request = jiffies;
1427 cic->ttime_total = 0;
1428 cic->ttime_samples = 0;
1429 cic->ttime_mean = 0;
1430 cic->dtor = cfq_free_io_context;
1431 cic->exit = cfq_exit_io_context;
1093 } 1432 }
1094 1433
1095 return cic; 1434 return cic;
1096} 1435}
1097 1436
1437static void cfq_init_prio_data(struct cfq_queue *cfqq)
1438{
1439 struct task_struct *tsk = current;
1440 int ioprio_class;
1441
1442 if (!cfq_cfqq_prio_changed(cfqq))
1443 return;
1444
1445 ioprio_class = IOPRIO_PRIO_CLASS(tsk->ioprio);
1446 switch (ioprio_class) {
1447 default:
1448 printk(KERN_ERR "cfq: bad prio %x\n", ioprio_class);
1449 case IOPRIO_CLASS_NONE:
1450 /*
1451 * no prio set, place us in the middle of the BE classes
1452 */
1453 cfqq->ioprio = task_nice_ioprio(tsk);
1454 cfqq->ioprio_class = IOPRIO_CLASS_BE;
1455 break;
1456 case IOPRIO_CLASS_RT:
1457 cfqq->ioprio = task_ioprio(tsk);
1458 cfqq->ioprio_class = IOPRIO_CLASS_RT;
1459 break;
1460 case IOPRIO_CLASS_BE:
1461 cfqq->ioprio = task_ioprio(tsk);
1462 cfqq->ioprio_class = IOPRIO_CLASS_BE;
1463 break;
1464 case IOPRIO_CLASS_IDLE:
1465 cfqq->ioprio_class = IOPRIO_CLASS_IDLE;
1466 cfqq->ioprio = 7;
1467 cfq_clear_cfqq_idle_window(cfqq);
1468 break;
1469 }
1470
1471 /*
1472 * keep track of original prio settings in case we have to temporarily
1473 * elevate the priority of this queue
1474 */
1475 cfqq->org_ioprio = cfqq->ioprio;
1476 cfqq->org_ioprio_class = cfqq->ioprio_class;
1477
1478 if (cfq_cfqq_on_rr(cfqq))
1479 cfq_resort_rr_list(cfqq, 0);
1480
1481 cfq_clear_cfqq_prio_changed(cfqq);
1482}
1483
1484static inline void changed_ioprio(struct cfq_queue *cfqq)
1485{
1486 if (cfqq) {
1487 struct cfq_data *cfqd = cfqq->cfqd;
1488
1489 spin_lock(cfqd->queue->queue_lock);
1490 cfq_mark_cfqq_prio_changed(cfqq);
1491 cfq_init_prio_data(cfqq);
1492 spin_unlock(cfqd->queue->queue_lock);
1493 }
1494}
1495
1496/*
1497 * callback from sys_ioprio_set, irqs are disabled
1498 */
1499static int cfq_ioc_set_ioprio(struct io_context *ioc, unsigned int ioprio)
1500{
1501 struct cfq_io_context *cic = ioc->cic;
1502
1503 changed_ioprio(cic->cfqq);
1504
1505 list_for_each_entry(cic, &cic->list, list)
1506 changed_ioprio(cic->cfqq);
1507
1508 return 0;
1509}
1510
1511static struct cfq_queue *
1512cfq_get_queue(struct cfq_data *cfqd, unsigned int key, unsigned short ioprio,
1513 int gfp_mask)
1514{
1515 const int hashval = hash_long(key, CFQ_QHASH_SHIFT);
1516 struct cfq_queue *cfqq, *new_cfqq = NULL;
1517
1518retry:
1519 cfqq = __cfq_find_cfq_hash(cfqd, key, ioprio, hashval);
1520
1521 if (!cfqq) {
1522 if (new_cfqq) {
1523 cfqq = new_cfqq;
1524 new_cfqq = NULL;
1525 } else if (gfp_mask & __GFP_WAIT) {
1526 spin_unlock_irq(cfqd->queue->queue_lock);
1527 new_cfqq = kmem_cache_alloc(cfq_pool, gfp_mask);
1528 spin_lock_irq(cfqd->queue->queue_lock);
1529 goto retry;
1530 } else {
1531 cfqq = kmem_cache_alloc(cfq_pool, gfp_mask);
1532 if (!cfqq)
1533 goto out;
1534 }
1535
1536 memset(cfqq, 0, sizeof(*cfqq));
1537
1538 INIT_HLIST_NODE(&cfqq->cfq_hash);
1539 INIT_LIST_HEAD(&cfqq->cfq_list);
1540 RB_CLEAR_ROOT(&cfqq->sort_list);
1541 INIT_LIST_HEAD(&cfqq->fifo);
1542
1543 cfqq->key = key;
1544 hlist_add_head(&cfqq->cfq_hash, &cfqd->cfq_hash[hashval]);
1545 atomic_set(&cfqq->ref, 0);
1546 cfqq->cfqd = cfqd;
1547 atomic_inc(&cfqd->ref);
1548 cfqq->service_last = 0;
1549 /*
1550 * set ->slice_left to allow preemption for a new process
1551 */
1552 cfqq->slice_left = 2 * cfqd->cfq_slice_idle;
1553 cfq_mark_cfqq_idle_window(cfqq);
1554 cfq_mark_cfqq_prio_changed(cfqq);
1555 cfq_init_prio_data(cfqq);
1556 }
1557
1558 if (new_cfqq)
1559 kmem_cache_free(cfq_pool, new_cfqq);
1560
1561 atomic_inc(&cfqq->ref);
1562out:
1563 WARN_ON((gfp_mask & __GFP_WAIT) && !cfqq);
1564 return cfqq;
1565}
1566
1098/* 1567/*
1099 * Setup general io context and cfq io context. There can be several cfq 1568 * Setup general io context and cfq io context. There can be several cfq
1100 * io contexts per general io context, if this process is doing io to more 1569 * io contexts per general io context, if this process is doing io to more
@@ -1102,39 +1571,39 @@ static struct cfq_io_context *cfq_alloc_io_context(int gfp_flags)
1102 * cfqq, so we don't need to worry about it disappearing 1571 * cfqq, so we don't need to worry about it disappearing
1103 */ 1572 */
1104static struct cfq_io_context * 1573static struct cfq_io_context *
1105cfq_get_io_context(struct cfq_queue **cfqq, int gfp_flags) 1574cfq_get_io_context(struct cfq_data *cfqd, pid_t pid, int gfp_mask)
1106{ 1575{
1107 struct cfq_data *cfqd = (*cfqq)->cfqd; 1576 struct io_context *ioc = NULL;
1108 struct cfq_queue *__cfqq = *cfqq;
1109 struct cfq_io_context *cic; 1577 struct cfq_io_context *cic;
1110 struct io_context *ioc;
1111 1578
1112 might_sleep_if(gfp_flags & __GFP_WAIT); 1579 might_sleep_if(gfp_mask & __GFP_WAIT);
1113 1580
1114 ioc = get_io_context(gfp_flags); 1581 ioc = get_io_context(gfp_mask);
1115 if (!ioc) 1582 if (!ioc)
1116 return NULL; 1583 return NULL;
1117 1584
1118 if ((cic = ioc->cic) == NULL) { 1585 if ((cic = ioc->cic) == NULL) {
1119 cic = cfq_alloc_io_context(gfp_flags); 1586 cic = cfq_alloc_io_context(cfqd, gfp_mask);
1120 1587
1121 if (cic == NULL) 1588 if (cic == NULL)
1122 goto err; 1589 goto err;
1123 1590
1591 /*
1592 * manually increment generic io_context usage count, it
1593 * cannot go away since we are already holding one ref to it
1594 */
1124 ioc->cic = cic; 1595 ioc->cic = cic;
1596 ioc->set_ioprio = cfq_ioc_set_ioprio;
1125 cic->ioc = ioc; 1597 cic->ioc = ioc;
1126 cic->cfqq = __cfqq; 1598 cic->key = cfqd;
1127 atomic_inc(&__cfqq->ref); 1599 atomic_inc(&cfqd->ref);
1128 } else { 1600 } else {
1129 struct cfq_io_context *__cic; 1601 struct cfq_io_context *__cic;
1130 unsigned long flags;
1131 1602
1132 /* 1603 /*
1133 * since the first cic on the list is actually the head 1604 * the first cic on the list is actually the head itself
1134 * itself, need to check this here or we'll duplicate an
1135 * cic per ioc for no reason
1136 */ 1605 */
1137 if (cic->cfqq == __cfqq) 1606 if (cic->key == cfqd)
1138 goto out; 1607 goto out;
1139 1608
1140 /* 1609 /*
@@ -1142,152 +1611,250 @@ cfq_get_io_context(struct cfq_queue **cfqq, int gfp_flags)
1142 * should be ok here, the list will usually not be more than 1611 * should be ok here, the list will usually not be more than
1143 * 1 or a few entries long 1612 * 1 or a few entries long
1144 */ 1613 */
1145 spin_lock_irqsave(&ioc->lock, flags);
1146 list_for_each_entry(__cic, &cic->list, list) { 1614 list_for_each_entry(__cic, &cic->list, list) {
1147 /* 1615 /*
1148 * this process is already holding a reference to 1616 * this process is already holding a reference to
1149 * this queue, so no need to get one more 1617 * this queue, so no need to get one more
1150 */ 1618 */
1151 if (__cic->cfqq == __cfqq) { 1619 if (__cic->key == cfqd) {
1152 cic = __cic; 1620 cic = __cic;
1153 spin_unlock_irqrestore(&ioc->lock, flags);
1154 goto out; 1621 goto out;
1155 } 1622 }
1156 } 1623 }
1157 spin_unlock_irqrestore(&ioc->lock, flags);
1158 1624
1159 /* 1625 /*
1160 * nope, process doesn't have a cic assoicated with this 1626 * nope, process doesn't have a cic assoicated with this
1161 * cfqq yet. get a new one and add to list 1627 * cfqq yet. get a new one and add to list
1162 */ 1628 */
1163 __cic = cfq_alloc_io_context(gfp_flags); 1629 __cic = cfq_alloc_io_context(cfqd, gfp_mask);
1164 if (__cic == NULL) 1630 if (__cic == NULL)
1165 goto err; 1631 goto err;
1166 1632
1167 __cic->ioc = ioc; 1633 __cic->ioc = ioc;
1168 __cic->cfqq = __cfqq; 1634 __cic->key = cfqd;
1169 atomic_inc(&__cfqq->ref); 1635 atomic_inc(&cfqd->ref);
1170 spin_lock_irqsave(&ioc->lock, flags);
1171 list_add(&__cic->list, &cic->list); 1636 list_add(&__cic->list, &cic->list);
1172 spin_unlock_irqrestore(&ioc->lock, flags);
1173
1174 cic = __cic; 1637 cic = __cic;
1175 *cfqq = __cfqq;
1176 } 1638 }
1177 1639
1178out: 1640out:
1179 /*
1180 * if key_type has been changed on the fly, we lazily rehash
1181 * each queue at lookup time
1182 */
1183 if ((*cfqq)->key_type != cfqd->key_type)
1184 cfq_rehash_cfqq(cfqd, cfqq, cic);
1185
1186 return cic; 1641 return cic;
1187err: 1642err:
1188 put_io_context(ioc); 1643 put_io_context(ioc);
1189 return NULL; 1644 return NULL;
1190} 1645}
1191 1646
1192static struct cfq_queue * 1647static void
1193__cfq_get_queue(struct cfq_data *cfqd, unsigned long key, int gfp_mask) 1648cfq_update_io_thinktime(struct cfq_data *cfqd, struct cfq_io_context *cic)
1194{ 1649{
1195 const int hashval = hash_long(key, CFQ_QHASH_SHIFT); 1650 unsigned long elapsed, ttime;
1196 struct cfq_queue *cfqq, *new_cfqq = NULL;
1197
1198retry:
1199 cfqq = __cfq_find_cfq_hash(cfqd, key, hashval);
1200 1651
1201 if (!cfqq) { 1652 /*
1202 if (new_cfqq) { 1653 * if this context already has stuff queued, thinktime is from
1203 cfqq = new_cfqq; 1654 * last queue not last end
1204 new_cfqq = NULL; 1655 */
1205 } else { 1656#if 0
1206 spin_unlock_irq(cfqd->queue->queue_lock); 1657 if (time_after(cic->last_end_request, cic->last_queue))
1207 new_cfqq = kmem_cache_alloc(cfq_pool, gfp_mask); 1658 elapsed = jiffies - cic->last_end_request;
1208 spin_lock_irq(cfqd->queue->queue_lock); 1659 else
1660 elapsed = jiffies - cic->last_queue;
1661#else
1662 elapsed = jiffies - cic->last_end_request;
1663#endif
1209 1664
1210 if (!new_cfqq && !(gfp_mask & __GFP_WAIT)) 1665 ttime = min(elapsed, 2UL * cfqd->cfq_slice_idle);
1211 goto out;
1212 1666
1213 goto retry; 1667 cic->ttime_samples = (7*cic->ttime_samples + 256) / 8;
1214 } 1668 cic->ttime_total = (7*cic->ttime_total + 256*ttime) / 8;
1669 cic->ttime_mean = (cic->ttime_total + 128) / cic->ttime_samples;
1670}
1215 1671
1216 memset(cfqq, 0, sizeof(*cfqq)); 1672#define sample_valid(samples) ((samples) > 80)
1217 1673
1218 INIT_HLIST_NODE(&cfqq->cfq_hash); 1674/*
1219 INIT_LIST_HEAD(&cfqq->cfq_list); 1675 * Disable idle window if the process thinks too long or seeks so much that
1220 RB_CLEAR_ROOT(&cfqq->sort_list); 1676 * it doesn't matter
1221 INIT_LIST_HEAD(&cfqq->fifo[0]); 1677 */
1222 INIT_LIST_HEAD(&cfqq->fifo[1]); 1678static void
1679cfq_update_idle_window(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1680 struct cfq_io_context *cic)
1681{
1682 int enable_idle = cfq_cfqq_idle_window(cfqq);
1223 1683
1224 cfqq->key = key; 1684 if (!cic->ioc->task || !cfqd->cfq_slice_idle)
1225 hlist_add_head(&cfqq->cfq_hash, &cfqd->cfq_hash[hashval]); 1685 enable_idle = 0;
1226 atomic_set(&cfqq->ref, 0); 1686 else if (sample_valid(cic->ttime_samples)) {
1227 cfqq->cfqd = cfqd; 1687 if (cic->ttime_mean > cfqd->cfq_slice_idle)
1228 atomic_inc(&cfqd->ref); 1688 enable_idle = 0;
1229 cfqq->key_type = cfqd->key_type; 1689 else
1230 cfqq->service_start = ~0UL; 1690 enable_idle = 1;
1231 } 1691 }
1232 1692
1233 if (new_cfqq) 1693 if (enable_idle)
1234 kmem_cache_free(cfq_pool, new_cfqq); 1694 cfq_mark_cfqq_idle_window(cfqq);
1695 else
1696 cfq_clear_cfqq_idle_window(cfqq);
1697}
1235 1698
1236 atomic_inc(&cfqq->ref); 1699
1237out: 1700/*
1238 WARN_ON((gfp_mask & __GFP_WAIT) && !cfqq); 1701 * Check if new_cfqq should preempt the currently active queue. Return 0 for
1239 return cfqq; 1702 * no or if we aren't sure, a 1 will cause a preempt.
1703 */
1704static int
1705cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq,
1706 struct cfq_rq *crq)
1707{
1708 struct cfq_queue *cfqq = cfqd->active_queue;
1709
1710 if (cfq_class_idle(new_cfqq))
1711 return 0;
1712
1713 if (!cfqq)
1714 return 1;
1715
1716 if (cfq_class_idle(cfqq))
1717 return 1;
1718 if (!cfq_cfqq_wait_request(new_cfqq))
1719 return 0;
1720 /*
1721 * if it doesn't have slice left, forget it
1722 */
1723 if (new_cfqq->slice_left < cfqd->cfq_slice_idle)
1724 return 0;
1725 if (cfq_crq_is_sync(crq) && !cfq_cfqq_sync(cfqq))
1726 return 1;
1727
1728 return 0;
1729}
1730
1731/*
1732 * cfqq preempts the active queue. if we allowed preempt with no slice left,
1733 * let it have half of its nominal slice.
1734 */
1735static void cfq_preempt_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1736{
1737 struct cfq_queue *__cfqq, *next;
1738
1739 list_for_each_entry_safe(__cfqq, next, &cfqd->cur_rr, cfq_list)
1740 cfq_resort_rr_list(__cfqq, 1);
1741
1742 if (!cfqq->slice_left)
1743 cfqq->slice_left = cfq_prio_to_slice(cfqd, cfqq) / 2;
1744
1745 cfqq->slice_end = cfqq->slice_left + jiffies;
1746 __cfq_slice_expired(cfqd, cfqq, 1);
1747 __cfq_set_active_queue(cfqd, cfqq);
1240} 1748}
1241 1749
1242static void cfq_enqueue(struct cfq_data *cfqd, struct cfq_rq *crq) 1750/*
1751 * should really be a ll_rw_blk.c helper
1752 */
1753static void cfq_start_queueing(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1754{
1755 request_queue_t *q = cfqd->queue;
1756
1757 if (!blk_queue_plugged(q))
1758 q->request_fn(q);
1759 else
1760 __generic_unplug_device(q);
1761}
1762
1763/*
1764 * Called when a new fs request (crq) is added (to cfqq). Check if there's
1765 * something we should do about it
1766 */
1767static void
1768cfq_crq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1769 struct cfq_rq *crq)
1243{ 1770{
1244 crq->is_sync = 0; 1771 const int sync = cfq_crq_is_sync(crq);
1245 if (rq_data_dir(crq->request) == READ || current->flags & PF_SYNCWRITE) 1772
1246 crq->is_sync = 1; 1773 cfqq->next_crq = cfq_choose_req(cfqd, cfqq->next_crq, crq);
1774
1775 if (sync) {
1776 struct cfq_io_context *cic = crq->io_context;
1777
1778 cfq_update_io_thinktime(cfqd, cic);
1779 cfq_update_idle_window(cfqd, cfqq, cic);
1780
1781 cic->last_queue = jiffies;
1782 }
1783
1784 if (cfqq == cfqd->active_queue) {
1785 /*
1786 * if we are waiting for a request for this queue, let it rip
1787 * immediately and flag that we must not expire this queue
1788 * just now
1789 */
1790 if (cfq_cfqq_wait_request(cfqq)) {
1791 cfq_mark_cfqq_must_dispatch(cfqq);
1792 del_timer(&cfqd->idle_slice_timer);
1793 cfq_start_queueing(cfqd, cfqq);
1794 }
1795 } else if (cfq_should_preempt(cfqd, cfqq, crq)) {
1796 /*
1797 * not the active queue - expire current slice if it is
1798 * idle and has expired it's mean thinktime or this new queue
1799 * has some old slice time left and is of higher priority
1800 */
1801 cfq_preempt_queue(cfqd, cfqq);
1802 cfq_mark_cfqq_must_dispatch(cfqq);
1803 cfq_start_queueing(cfqd, cfqq);
1804 }
1805}
1806
1807static void cfq_enqueue(struct cfq_data *cfqd, struct request *rq)
1808{
1809 struct cfq_rq *crq = RQ_DATA(rq);
1810 struct cfq_queue *cfqq = crq->cfq_queue;
1811
1812 cfq_init_prio_data(cfqq);
1247 1813
1248 cfq_add_crq_rb(crq); 1814 cfq_add_crq_rb(crq);
1249 crq->queue_start = jiffies;
1250 1815
1251 list_add_tail(&crq->request->queuelist, &crq->cfq_queue->fifo[crq->is_sync]); 1816 list_add_tail(&rq->queuelist, &cfqq->fifo);
1817
1818 if (rq_mergeable(rq)) {
1819 cfq_add_crq_hash(cfqd, crq);
1820
1821 if (!cfqd->queue->last_merge)
1822 cfqd->queue->last_merge = rq;
1823 }
1824
1825 cfq_crq_enqueued(cfqd, cfqq, crq);
1252} 1826}
1253 1827
1254static void 1828static void
1255cfq_insert_request(request_queue_t *q, struct request *rq, int where) 1829cfq_insert_request(request_queue_t *q, struct request *rq, int where)
1256{ 1830{
1257 struct cfq_data *cfqd = q->elevator->elevator_data; 1831 struct cfq_data *cfqd = q->elevator->elevator_data;
1258 struct cfq_rq *crq = RQ_DATA(rq);
1259 1832
1260 switch (where) { 1833 switch (where) {
1261 case ELEVATOR_INSERT_BACK: 1834 case ELEVATOR_INSERT_BACK:
1262 while (cfq_dispatch_requests(q, cfqd->cfq_quantum)) 1835 while (cfq_dispatch_requests(q, INT_MAX, 1))
1263 ; 1836 ;
1264 list_add_tail(&rq->queuelist, &q->queue_head); 1837 list_add_tail(&rq->queuelist, &q->queue_head);
1838 /*
1839 * If we were idling with pending requests on
1840 * inactive cfqqs, force dispatching will
1841 * remove the idle timer and the queue won't
1842 * be kicked by __make_request() afterward.
1843 * Kick it here.
1844 */
1845 cfq_schedule_dispatch(cfqd);
1265 break; 1846 break;
1266 case ELEVATOR_INSERT_FRONT: 1847 case ELEVATOR_INSERT_FRONT:
1267 list_add(&rq->queuelist, &q->queue_head); 1848 list_add(&rq->queuelist, &q->queue_head);
1268 break; 1849 break;
1269 case ELEVATOR_INSERT_SORT: 1850 case ELEVATOR_INSERT_SORT:
1270 BUG_ON(!blk_fs_request(rq)); 1851 BUG_ON(!blk_fs_request(rq));
1271 cfq_enqueue(cfqd, crq); 1852 cfq_enqueue(cfqd, rq);
1272 break; 1853 break;
1273 default: 1854 default:
1274 printk("%s: bad insert point %d\n", __FUNCTION__,where); 1855 printk("%s: bad insert point %d\n", __FUNCTION__,where);
1275 return; 1856 return;
1276 } 1857 }
1277
1278 if (rq_mergeable(rq)) {
1279 cfq_add_crq_hash(cfqd, crq);
1280
1281 if (!q->last_merge)
1282 q->last_merge = rq;
1283 }
1284}
1285
1286static int cfq_queue_empty(request_queue_t *q)
1287{
1288 struct cfq_data *cfqd = q->elevator->elevator_data;
1289
1290 return list_empty(&q->queue_head) && list_empty(&cfqd->rr_list);
1291} 1858}
1292 1859
1293static void cfq_completed_request(request_queue_t *q, struct request *rq) 1860static void cfq_completed_request(request_queue_t *q, struct request *rq)
@@ -1300,9 +1867,11 @@ static void cfq_completed_request(request_queue_t *q, struct request *rq)
1300 1867
1301 cfqq = crq->cfq_queue; 1868 cfqq = crq->cfq_queue;
1302 1869
1303 if (crq->in_flight) { 1870 if (cfq_crq_in_flight(crq)) {
1304 WARN_ON(!cfqq->in_flight); 1871 const int sync = cfq_crq_is_sync(crq);
1305 cfqq->in_flight--; 1872
1873 WARN_ON(!cfqq->on_dispatch[sync]);
1874 cfqq->on_dispatch[sync]--;
1306 } 1875 }
1307 1876
1308 cfq_account_completion(cfqq, crq); 1877 cfq_account_completion(cfqq, crq);
@@ -1332,51 +1901,136 @@ cfq_latter_request(request_queue_t *q, struct request *rq)
1332 return NULL; 1901 return NULL;
1333} 1902}
1334 1903
1335static int cfq_may_queue(request_queue_t *q, int rw) 1904/*
1905 * we temporarily boost lower priority queues if they are holding fs exclusive
1906 * resources. they are boosted to normal prio (CLASS_BE/4)
1907 */
1908static void cfq_prio_boost(struct cfq_queue *cfqq)
1336{ 1909{
1337 struct cfq_data *cfqd = q->elevator->elevator_data; 1910 const int ioprio_class = cfqq->ioprio_class;
1338 struct cfq_queue *cfqq; 1911 const int ioprio = cfqq->ioprio;
1339 int ret = ELV_MQUEUE_MAY;
1340 1912
1341 if (current->flags & PF_MEMALLOC) 1913 if (has_fs_excl()) {
1342 return ELV_MQUEUE_MAY; 1914 /*
1915 * boost idle prio on transactions that would lock out other
1916 * users of the filesystem
1917 */
1918 if (cfq_class_idle(cfqq))
1919 cfqq->ioprio_class = IOPRIO_CLASS_BE;
1920 if (cfqq->ioprio > IOPRIO_NORM)
1921 cfqq->ioprio = IOPRIO_NORM;
1922 } else {
1923 /*
1924 * check if we need to unboost the queue
1925 */
1926 if (cfqq->ioprio_class != cfqq->org_ioprio_class)
1927 cfqq->ioprio_class = cfqq->org_ioprio_class;
1928 if (cfqq->ioprio != cfqq->org_ioprio)
1929 cfqq->ioprio = cfqq->org_ioprio;
1930 }
1343 1931
1344 cfqq = cfq_find_cfq_hash(cfqd, cfq_hash_key(cfqd, current)); 1932 /*
1345 if (cfqq) { 1933 * refile between round-robin lists if we moved the priority class
1346 int limit = cfqd->max_queued; 1934 */
1935 if ((ioprio_class != cfqq->ioprio_class || ioprio != cfqq->ioprio) &&
1936 cfq_cfqq_on_rr(cfqq))
1937 cfq_resort_rr_list(cfqq, 0);
1938}
1347 1939
1348 if (cfqq->allocated[rw] < cfqd->cfq_queued) 1940static inline pid_t cfq_queue_pid(struct task_struct *task, int rw)
1349 return ELV_MQUEUE_MUST; 1941{
1942 if (rw == READ || process_sync(task))
1943 return task->pid;
1350 1944
1351 if (cfqd->busy_queues) 1945 return CFQ_KEY_ASYNC;
1352 limit = q->nr_requests / cfqd->busy_queues; 1946}
1353 1947
1354 if (limit < cfqd->cfq_queued) 1948static inline int
1355 limit = cfqd->cfq_queued; 1949__cfq_may_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1356 else if (limit > cfqd->max_queued) 1950 struct task_struct *task, int rw)
1357 limit = cfqd->max_queued; 1951{
1952#if 1
1953 if ((cfq_cfqq_wait_request(cfqq) || cfq_cfqq_must_alloc(cfqq)) &&
1954 !cfq_cfqq_must_alloc_slice(cfqq)) {
1955 cfq_mark_cfqq_must_alloc_slice(cfqq);
1956 return ELV_MQUEUE_MUST;
1957 }
1358 1958
1359 if (cfqq->allocated[rw] >= limit) { 1959 return ELV_MQUEUE_MAY;
1360 if (limit > cfqq->alloc_limit[rw]) 1960#else
1361 cfqq->alloc_limit[rw] = limit; 1961 if (!cfqq || task->flags & PF_MEMALLOC)
1962 return ELV_MQUEUE_MAY;
1963 if (!cfqq->allocated[rw] || cfq_cfqq_must_alloc(cfqq)) {
1964 if (cfq_cfqq_wait_request(cfqq))
1965 return ELV_MQUEUE_MUST;
1362 1966
1363 ret = ELV_MQUEUE_NO; 1967 /*
1968 * only allow 1 ELV_MQUEUE_MUST per slice, otherwise we
1969 * can quickly flood the queue with writes from a single task
1970 */
1971 if (rw == READ || !cfq_cfqq_must_alloc_slice(cfqq)) {
1972 cfq_mark_cfqq_must_alloc_slice(cfqq);
1973 return ELV_MQUEUE_MUST;
1364 } 1974 }
1975
1976 return ELV_MQUEUE_MAY;
1365 } 1977 }
1978 if (cfq_class_idle(cfqq))
1979 return ELV_MQUEUE_NO;
1980 if (cfqq->allocated[rw] >= cfqd->max_queued) {
1981 struct io_context *ioc = get_io_context(GFP_ATOMIC);
1982 int ret = ELV_MQUEUE_NO;
1366 1983
1367 return ret; 1984 if (ioc && ioc->nr_batch_requests)
1985 ret = ELV_MQUEUE_MAY;
1986
1987 put_io_context(ioc);
1988 return ret;
1989 }
1990
1991 return ELV_MQUEUE_MAY;
1992#endif
1993}
1994
1995static int cfq_may_queue(request_queue_t *q, int rw, struct bio *bio)
1996{
1997 struct cfq_data *cfqd = q->elevator->elevator_data;
1998 struct task_struct *tsk = current;
1999 struct cfq_queue *cfqq;
2000
2001 /*
2002 * don't force setup of a queue from here, as a call to may_queue
2003 * does not necessarily imply that a request actually will be queued.
2004 * so just lookup a possibly existing queue, or return 'may queue'
2005 * if that fails
2006 */
2007 cfqq = cfq_find_cfq_hash(cfqd, cfq_queue_pid(tsk, rw), tsk->ioprio);
2008 if (cfqq) {
2009 cfq_init_prio_data(cfqq);
2010 cfq_prio_boost(cfqq);
2011
2012 return __cfq_may_queue(cfqd, cfqq, tsk, rw);
2013 }
2014
2015 return ELV_MQUEUE_MAY;
1368} 2016}
1369 2017
1370static void cfq_check_waiters(request_queue_t *q, struct cfq_queue *cfqq) 2018static void cfq_check_waiters(request_queue_t *q, struct cfq_queue *cfqq)
1371{ 2019{
2020 struct cfq_data *cfqd = q->elevator->elevator_data;
1372 struct request_list *rl = &q->rq; 2021 struct request_list *rl = &q->rq;
1373 const int write = waitqueue_active(&rl->wait[WRITE]);
1374 const int read = waitqueue_active(&rl->wait[READ]);
1375 2022
1376 if (read && cfqq->allocated[READ] < cfqq->alloc_limit[READ]) 2023 if (cfqq->allocated[READ] <= cfqd->max_queued || cfqd->rq_starved) {
1377 wake_up(&rl->wait[READ]); 2024 smp_mb();
1378 if (write && cfqq->allocated[WRITE] < cfqq->alloc_limit[WRITE]) 2025 if (waitqueue_active(&rl->wait[READ]))
1379 wake_up(&rl->wait[WRITE]); 2026 wake_up(&rl->wait[READ]);
2027 }
2028
2029 if (cfqq->allocated[WRITE] <= cfqd->max_queued || cfqd->rq_starved) {
2030 smp_mb();
2031 if (waitqueue_active(&rl->wait[WRITE]))
2032 wake_up(&rl->wait[WRITE]);
2033 }
1380} 2034}
1381 2035
1382/* 2036/*
@@ -1389,69 +2043,61 @@ static void cfq_put_request(request_queue_t *q, struct request *rq)
1389 2043
1390 if (crq) { 2044 if (crq) {
1391 struct cfq_queue *cfqq = crq->cfq_queue; 2045 struct cfq_queue *cfqq = crq->cfq_queue;
2046 const int rw = rq_data_dir(rq);
1392 2047
1393 BUG_ON(q->last_merge == rq); 2048 BUG_ON(!cfqq->allocated[rw]);
1394 BUG_ON(!hlist_unhashed(&crq->hash)); 2049 cfqq->allocated[rw]--;
1395 2050
1396 if (crq->io_context) 2051 put_io_context(crq->io_context->ioc);
1397 put_io_context(crq->io_context->ioc);
1398
1399 BUG_ON(!cfqq->allocated[crq->is_write]);
1400 cfqq->allocated[crq->is_write]--;
1401 2052
1402 mempool_free(crq, cfqd->crq_pool); 2053 mempool_free(crq, cfqd->crq_pool);
1403 rq->elevator_private = NULL; 2054 rq->elevator_private = NULL;
1404 2055
1405 smp_mb();
1406 cfq_check_waiters(q, cfqq); 2056 cfq_check_waiters(q, cfqq);
1407 cfq_put_queue(cfqq); 2057 cfq_put_queue(cfqq);
1408 } 2058 }
1409} 2059}
1410 2060
1411/* 2061/*
1412 * Allocate cfq data structures associated with this request. A queue and 2062 * Allocate cfq data structures associated with this request.
1413 */ 2063 */
1414static int cfq_set_request(request_queue_t *q, struct request *rq, int gfp_mask) 2064static int
2065cfq_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
2066 int gfp_mask)
1415{ 2067{
1416 struct cfq_data *cfqd = q->elevator->elevator_data; 2068 struct cfq_data *cfqd = q->elevator->elevator_data;
2069 struct task_struct *tsk = current;
1417 struct cfq_io_context *cic; 2070 struct cfq_io_context *cic;
1418 const int rw = rq_data_dir(rq); 2071 const int rw = rq_data_dir(rq);
1419 struct cfq_queue *cfqq, *saved_cfqq; 2072 pid_t key = cfq_queue_pid(tsk, rw);
2073 struct cfq_queue *cfqq;
1420 struct cfq_rq *crq; 2074 struct cfq_rq *crq;
1421 unsigned long flags; 2075 unsigned long flags;
1422 2076
1423 might_sleep_if(gfp_mask & __GFP_WAIT); 2077 might_sleep_if(gfp_mask & __GFP_WAIT);
1424 2078
2079 cic = cfq_get_io_context(cfqd, key, gfp_mask);
2080
1425 spin_lock_irqsave(q->queue_lock, flags); 2081 spin_lock_irqsave(q->queue_lock, flags);
1426 2082
1427 cfqq = __cfq_get_queue(cfqd, cfq_hash_key(cfqd, current), gfp_mask); 2083 if (!cic)
1428 if (!cfqq) 2084 goto queue_fail;
1429 goto out_lock; 2085
2086 if (!cic->cfqq) {
2087 cfqq = cfq_get_queue(cfqd, key, tsk->ioprio, gfp_mask);
2088 if (!cfqq)
2089 goto queue_fail;
1430 2090
1431repeat: 2091 cic->cfqq = cfqq;
1432 if (cfqq->allocated[rw] >= cfqd->max_queued) 2092 } else
1433 goto out_lock; 2093 cfqq = cic->cfqq;
1434 2094
1435 cfqq->allocated[rw]++; 2095 cfqq->allocated[rw]++;
2096 cfq_clear_cfqq_must_alloc(cfqq);
2097 cfqd->rq_starved = 0;
2098 atomic_inc(&cfqq->ref);
1436 spin_unlock_irqrestore(q->queue_lock, flags); 2099 spin_unlock_irqrestore(q->queue_lock, flags);
1437 2100
1438 /*
1439 * if hashing type has changed, the cfq_queue might change here.
1440 */
1441 saved_cfqq = cfqq;
1442 cic = cfq_get_io_context(&cfqq, gfp_mask);
1443 if (!cic)
1444 goto err;
1445
1446 /*
1447 * repeat allocation checks on queue change
1448 */
1449 if (unlikely(saved_cfqq != cfqq)) {
1450 spin_lock_irqsave(q->queue_lock, flags);
1451 saved_cfqq->allocated[rw]--;
1452 goto repeat;
1453 }
1454
1455 crq = mempool_alloc(cfqd->crq_pool, gfp_mask); 2101 crq = mempool_alloc(cfqd->crq_pool, gfp_mask);
1456 if (crq) { 2102 if (crq) {
1457 RB_CLEAR(&crq->rb_node); 2103 RB_CLEAR(&crq->rb_node);
@@ -1460,24 +2106,141 @@ repeat:
1460 INIT_HLIST_NODE(&crq->hash); 2106 INIT_HLIST_NODE(&crq->hash);
1461 crq->cfq_queue = cfqq; 2107 crq->cfq_queue = cfqq;
1462 crq->io_context = cic; 2108 crq->io_context = cic;
1463 crq->service_start = crq->queue_start = 0; 2109 cfq_clear_crq_in_flight(crq);
1464 crq->in_flight = crq->accounted = crq->is_sync = 0; 2110 cfq_clear_crq_in_driver(crq);
1465 crq->is_write = rw; 2111 cfq_clear_crq_requeued(crq);
2112
2113 if (rw == READ || process_sync(tsk))
2114 cfq_mark_crq_is_sync(crq);
2115 else
2116 cfq_clear_crq_is_sync(crq);
2117
1466 rq->elevator_private = crq; 2118 rq->elevator_private = crq;
1467 cfqq->alloc_limit[rw] = 0;
1468 return 0; 2119 return 0;
1469 } 2120 }
1470 2121
1471 put_io_context(cic->ioc);
1472err:
1473 spin_lock_irqsave(q->queue_lock, flags); 2122 spin_lock_irqsave(q->queue_lock, flags);
1474 cfqq->allocated[rw]--; 2123 cfqq->allocated[rw]--;
2124 if (!(cfqq->allocated[0] + cfqq->allocated[1]))
2125 cfq_mark_cfqq_must_alloc(cfqq);
1475 cfq_put_queue(cfqq); 2126 cfq_put_queue(cfqq);
1476out_lock: 2127queue_fail:
2128 if (cic)
2129 put_io_context(cic->ioc);
2130 /*
2131 * mark us rq allocation starved. we need to kickstart the process
2132 * ourselves if there are no pending requests that can do it for us.
2133 * that would be an extremely rare OOM situation
2134 */
2135 cfqd->rq_starved = 1;
2136 cfq_schedule_dispatch(cfqd);
1477 spin_unlock_irqrestore(q->queue_lock, flags); 2137 spin_unlock_irqrestore(q->queue_lock, flags);
1478 return 1; 2138 return 1;
1479} 2139}
1480 2140
2141static void cfq_kick_queue(void *data)
2142{
2143 request_queue_t *q = data;
2144 struct cfq_data *cfqd = q->elevator->elevator_data;
2145 unsigned long flags;
2146
2147 spin_lock_irqsave(q->queue_lock, flags);
2148
2149 if (cfqd->rq_starved) {
2150 struct request_list *rl = &q->rq;
2151
2152 /*
2153 * we aren't guaranteed to get a request after this, but we
2154 * have to be opportunistic
2155 */
2156 smp_mb();
2157 if (waitqueue_active(&rl->wait[READ]))
2158 wake_up(&rl->wait[READ]);
2159 if (waitqueue_active(&rl->wait[WRITE]))
2160 wake_up(&rl->wait[WRITE]);
2161 }
2162
2163 blk_remove_plug(q);
2164 q->request_fn(q);
2165 spin_unlock_irqrestore(q->queue_lock, flags);
2166}
2167
2168/*
2169 * Timer running if the active_queue is currently idling inside its time slice
2170 */
2171static void cfq_idle_slice_timer(unsigned long data)
2172{
2173 struct cfq_data *cfqd = (struct cfq_data *) data;
2174 struct cfq_queue *cfqq;
2175 unsigned long flags;
2176
2177 spin_lock_irqsave(cfqd->queue->queue_lock, flags);
2178
2179 if ((cfqq = cfqd->active_queue) != NULL) {
2180 unsigned long now = jiffies;
2181
2182 /*
2183 * expired
2184 */
2185 if (time_after(now, cfqq->slice_end))
2186 goto expire;
2187
2188 /*
2189 * only expire and reinvoke request handler, if there are
2190 * other queues with pending requests
2191 */
2192 if (!cfq_pending_requests(cfqd)) {
2193 cfqd->idle_slice_timer.expires = min(now + cfqd->cfq_slice_idle, cfqq->slice_end);
2194 add_timer(&cfqd->idle_slice_timer);
2195 goto out_cont;
2196 }
2197
2198 /*
2199 * not expired and it has a request pending, let it dispatch
2200 */
2201 if (!RB_EMPTY(&cfqq->sort_list)) {
2202 cfq_mark_cfqq_must_dispatch(cfqq);
2203 goto out_kick;
2204 }
2205 }
2206expire:
2207 cfq_slice_expired(cfqd, 0);
2208out_kick:
2209 cfq_schedule_dispatch(cfqd);
2210out_cont:
2211 spin_unlock_irqrestore(cfqd->queue->queue_lock, flags);
2212}
2213
2214/*
2215 * Timer running if an idle class queue is waiting for service
2216 */
2217static void cfq_idle_class_timer(unsigned long data)
2218{
2219 struct cfq_data *cfqd = (struct cfq_data *) data;
2220 unsigned long flags, end;
2221
2222 spin_lock_irqsave(cfqd->queue->queue_lock, flags);
2223
2224 /*
2225 * race with a non-idle queue, reset timer
2226 */
2227 end = cfqd->last_end_request + CFQ_IDLE_GRACE;
2228 if (!time_after_eq(jiffies, end)) {
2229 cfqd->idle_class_timer.expires = end;
2230 add_timer(&cfqd->idle_class_timer);
2231 } else
2232 cfq_schedule_dispatch(cfqd);
2233
2234 spin_unlock_irqrestore(cfqd->queue->queue_lock, flags);
2235}
2236
2237static void cfq_shutdown_timer_wq(struct cfq_data *cfqd)
2238{
2239 del_timer_sync(&cfqd->idle_slice_timer);
2240 del_timer_sync(&cfqd->idle_class_timer);
2241 blk_sync_queue(cfqd->queue);
2242}
2243
1481static void cfq_put_cfqd(struct cfq_data *cfqd) 2244static void cfq_put_cfqd(struct cfq_data *cfqd)
1482{ 2245{
1483 request_queue_t *q = cfqd->queue; 2246 request_queue_t *q = cfqd->queue;
@@ -1487,6 +2250,9 @@ static void cfq_put_cfqd(struct cfq_data *cfqd)
1487 2250
1488 blk_put_queue(q); 2251 blk_put_queue(q);
1489 2252
2253 cfq_shutdown_timer_wq(cfqd);
2254 q->elevator->elevator_data = NULL;
2255
1490 mempool_destroy(cfqd->crq_pool); 2256 mempool_destroy(cfqd->crq_pool);
1491 kfree(cfqd->crq_hash); 2257 kfree(cfqd->crq_hash);
1492 kfree(cfqd->cfq_hash); 2258 kfree(cfqd->cfq_hash);
@@ -1495,7 +2261,10 @@ static void cfq_put_cfqd(struct cfq_data *cfqd)
1495 2261
1496static void cfq_exit_queue(elevator_t *e) 2262static void cfq_exit_queue(elevator_t *e)
1497{ 2263{
1498 cfq_put_cfqd(e->elevator_data); 2264 struct cfq_data *cfqd = e->elevator_data;
2265
2266 cfq_shutdown_timer_wq(cfqd);
2267 cfq_put_cfqd(cfqd);
1499} 2268}
1500 2269
1501static int cfq_init_queue(request_queue_t *q, elevator_t *e) 2270static int cfq_init_queue(request_queue_t *q, elevator_t *e)
@@ -1508,7 +2277,13 @@ static int cfq_init_queue(request_queue_t *q, elevator_t *e)
1508 return -ENOMEM; 2277 return -ENOMEM;
1509 2278
1510 memset(cfqd, 0, sizeof(*cfqd)); 2279 memset(cfqd, 0, sizeof(*cfqd));
1511 INIT_LIST_HEAD(&cfqd->rr_list); 2280
2281 for (i = 0; i < CFQ_PRIO_LISTS; i++)
2282 INIT_LIST_HEAD(&cfqd->rr_list[i]);
2283
2284 INIT_LIST_HEAD(&cfqd->busy_rr);
2285 INIT_LIST_HEAD(&cfqd->cur_rr);
2286 INIT_LIST_HEAD(&cfqd->idle_rr);
1512 INIT_LIST_HEAD(&cfqd->empty_list); 2287 INIT_LIST_HEAD(&cfqd->empty_list);
1513 2288
1514 cfqd->crq_hash = kmalloc(sizeof(struct hlist_head) * CFQ_MHASH_ENTRIES, GFP_KERNEL); 2289 cfqd->crq_hash = kmalloc(sizeof(struct hlist_head) * CFQ_MHASH_ENTRIES, GFP_KERNEL);
@@ -1533,24 +2308,32 @@ static int cfq_init_queue(request_queue_t *q, elevator_t *e)
1533 cfqd->queue = q; 2308 cfqd->queue = q;
1534 atomic_inc(&q->refcnt); 2309 atomic_inc(&q->refcnt);
1535 2310
1536 /* 2311 cfqd->max_queued = q->nr_requests / 4;
1537 * just set it to some high value, we want anyone to be able to queue
1538 * some requests. fairness is handled differently
1539 */
1540 q->nr_requests = 1024;
1541 cfqd->max_queued = q->nr_requests / 16;
1542 q->nr_batching = cfq_queued; 2312 q->nr_batching = cfq_queued;
1543 cfqd->key_type = CFQ_KEY_TGID; 2313
1544 cfqd->find_best_crq = 1; 2314 init_timer(&cfqd->idle_slice_timer);
2315 cfqd->idle_slice_timer.function = cfq_idle_slice_timer;
2316 cfqd->idle_slice_timer.data = (unsigned long) cfqd;
2317
2318 init_timer(&cfqd->idle_class_timer);
2319 cfqd->idle_class_timer.function = cfq_idle_class_timer;
2320 cfqd->idle_class_timer.data = (unsigned long) cfqd;
2321
2322 INIT_WORK(&cfqd->unplug_work, cfq_kick_queue, q);
2323
1545 atomic_set(&cfqd->ref, 1); 2324 atomic_set(&cfqd->ref, 1);
1546 2325
1547 cfqd->cfq_queued = cfq_queued; 2326 cfqd->cfq_queued = cfq_queued;
1548 cfqd->cfq_quantum = cfq_quantum; 2327 cfqd->cfq_quantum = cfq_quantum;
1549 cfqd->cfq_fifo_expire_r = cfq_fifo_expire_r; 2328 cfqd->cfq_fifo_expire[0] = cfq_fifo_expire[0];
1550 cfqd->cfq_fifo_expire_w = cfq_fifo_expire_w; 2329 cfqd->cfq_fifo_expire[1] = cfq_fifo_expire[1];
1551 cfqd->cfq_fifo_batch_expire = cfq_fifo_rate;
1552 cfqd->cfq_back_max = cfq_back_max; 2330 cfqd->cfq_back_max = cfq_back_max;
1553 cfqd->cfq_back_penalty = cfq_back_penalty; 2331 cfqd->cfq_back_penalty = cfq_back_penalty;
2332 cfqd->cfq_slice[0] = cfq_slice_async;
2333 cfqd->cfq_slice[1] = cfq_slice_sync;
2334 cfqd->cfq_slice_async_rq = cfq_slice_async_rq;
2335 cfqd->cfq_slice_idle = cfq_slice_idle;
2336 cfqd->cfq_max_depth = cfq_max_depth;
1554 2337
1555 return 0; 2338 return 0;
1556out_crqpool: 2339out_crqpool:
@@ -1595,7 +2378,6 @@ fail:
1595 return -ENOMEM; 2378 return -ENOMEM;
1596} 2379}
1597 2380
1598
1599/* 2381/*
1600 * sysfs parts below --> 2382 * sysfs parts below -->
1601 */ 2383 */
@@ -1620,45 +2402,6 @@ cfq_var_store(unsigned int *var, const char *page, size_t count)
1620 return count; 2402 return count;
1621} 2403}
1622 2404
1623static ssize_t
1624cfq_clear_elapsed(struct cfq_data *cfqd, const char *page, size_t count)
1625{
1626 max_elapsed_dispatch = max_elapsed_crq = 0;
1627 return count;
1628}
1629
1630static ssize_t
1631cfq_set_key_type(struct cfq_data *cfqd, const char *page, size_t count)
1632{
1633 spin_lock_irq(cfqd->queue->queue_lock);
1634 if (!strncmp(page, "pgid", 4))
1635 cfqd->key_type = CFQ_KEY_PGID;
1636 else if (!strncmp(page, "tgid", 4))
1637 cfqd->key_type = CFQ_KEY_TGID;
1638 else if (!strncmp(page, "uid", 3))
1639 cfqd->key_type = CFQ_KEY_UID;
1640 else if (!strncmp(page, "gid", 3))
1641 cfqd->key_type = CFQ_KEY_GID;
1642 spin_unlock_irq(cfqd->queue->queue_lock);
1643 return count;
1644}
1645
1646static ssize_t
1647cfq_read_key_type(struct cfq_data *cfqd, char *page)
1648{
1649 ssize_t len = 0;
1650 int i;
1651
1652 for (i = CFQ_KEY_PGID; i < CFQ_KEY_LAST; i++) {
1653 if (cfqd->key_type == i)
1654 len += sprintf(page+len, "[%s] ", cfq_key_types[i]);
1655 else
1656 len += sprintf(page+len, "%s ", cfq_key_types[i]);
1657 }
1658 len += sprintf(page+len, "\n");
1659 return len;
1660}
1661
1662#define SHOW_FUNCTION(__FUNC, __VAR, __CONV) \ 2405#define SHOW_FUNCTION(__FUNC, __VAR, __CONV) \
1663static ssize_t __FUNC(struct cfq_data *cfqd, char *page) \ 2406static ssize_t __FUNC(struct cfq_data *cfqd, char *page) \
1664{ \ 2407{ \
@@ -1669,12 +2412,15 @@ static ssize_t __FUNC(struct cfq_data *cfqd, char *page) \
1669} 2412}
1670SHOW_FUNCTION(cfq_quantum_show, cfqd->cfq_quantum, 0); 2413SHOW_FUNCTION(cfq_quantum_show, cfqd->cfq_quantum, 0);
1671SHOW_FUNCTION(cfq_queued_show, cfqd->cfq_queued, 0); 2414SHOW_FUNCTION(cfq_queued_show, cfqd->cfq_queued, 0);
1672SHOW_FUNCTION(cfq_fifo_expire_r_show, cfqd->cfq_fifo_expire_r, 1); 2415SHOW_FUNCTION(cfq_fifo_expire_sync_show, cfqd->cfq_fifo_expire[1], 1);
1673SHOW_FUNCTION(cfq_fifo_expire_w_show, cfqd->cfq_fifo_expire_w, 1); 2416SHOW_FUNCTION(cfq_fifo_expire_async_show, cfqd->cfq_fifo_expire[0], 1);
1674SHOW_FUNCTION(cfq_fifo_batch_expire_show, cfqd->cfq_fifo_batch_expire, 1);
1675SHOW_FUNCTION(cfq_find_best_show, cfqd->find_best_crq, 0);
1676SHOW_FUNCTION(cfq_back_max_show, cfqd->cfq_back_max, 0); 2417SHOW_FUNCTION(cfq_back_max_show, cfqd->cfq_back_max, 0);
1677SHOW_FUNCTION(cfq_back_penalty_show, cfqd->cfq_back_penalty, 0); 2418SHOW_FUNCTION(cfq_back_penalty_show, cfqd->cfq_back_penalty, 0);
2419SHOW_FUNCTION(cfq_slice_idle_show, cfqd->cfq_slice_idle, 1);
2420SHOW_FUNCTION(cfq_slice_sync_show, cfqd->cfq_slice[1], 1);
2421SHOW_FUNCTION(cfq_slice_async_show, cfqd->cfq_slice[0], 1);
2422SHOW_FUNCTION(cfq_slice_async_rq_show, cfqd->cfq_slice_async_rq, 0);
2423SHOW_FUNCTION(cfq_max_depth_show, cfqd->cfq_max_depth, 0);
1678#undef SHOW_FUNCTION 2424#undef SHOW_FUNCTION
1679 2425
1680#define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, __CONV) \ 2426#define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, __CONV) \
@@ -1694,12 +2440,15 @@ static ssize_t __FUNC(struct cfq_data *cfqd, const char *page, size_t count) \
1694} 2440}
1695STORE_FUNCTION(cfq_quantum_store, &cfqd->cfq_quantum, 1, UINT_MAX, 0); 2441STORE_FUNCTION(cfq_quantum_store, &cfqd->cfq_quantum, 1, UINT_MAX, 0);
1696STORE_FUNCTION(cfq_queued_store, &cfqd->cfq_queued, 1, UINT_MAX, 0); 2442STORE_FUNCTION(cfq_queued_store, &cfqd->cfq_queued, 1, UINT_MAX, 0);
1697STORE_FUNCTION(cfq_fifo_expire_r_store, &cfqd->cfq_fifo_expire_r, 1, UINT_MAX, 1); 2443STORE_FUNCTION(cfq_fifo_expire_sync_store, &cfqd->cfq_fifo_expire[1], 1, UINT_MAX, 1);
1698STORE_FUNCTION(cfq_fifo_expire_w_store, &cfqd->cfq_fifo_expire_w, 1, UINT_MAX, 1); 2444STORE_FUNCTION(cfq_fifo_expire_async_store, &cfqd->cfq_fifo_expire[0], 1, UINT_MAX, 1);
1699STORE_FUNCTION(cfq_fifo_batch_expire_store, &cfqd->cfq_fifo_batch_expire, 0, UINT_MAX, 1);
1700STORE_FUNCTION(cfq_find_best_store, &cfqd->find_best_crq, 0, 1, 0);
1701STORE_FUNCTION(cfq_back_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0); 2445STORE_FUNCTION(cfq_back_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0);
1702STORE_FUNCTION(cfq_back_penalty_store, &cfqd->cfq_back_penalty, 1, UINT_MAX, 0); 2446STORE_FUNCTION(cfq_back_penalty_store, &cfqd->cfq_back_penalty, 1, UINT_MAX, 0);
2447STORE_FUNCTION(cfq_slice_idle_store, &cfqd->cfq_slice_idle, 0, UINT_MAX, 1);
2448STORE_FUNCTION(cfq_slice_sync_store, &cfqd->cfq_slice[1], 1, UINT_MAX, 1);
2449STORE_FUNCTION(cfq_slice_async_store, &cfqd->cfq_slice[0], 1, UINT_MAX, 1);
2450STORE_FUNCTION(cfq_slice_async_rq_store, &cfqd->cfq_slice_async_rq, 1, UINT_MAX, 0);
2451STORE_FUNCTION(cfq_max_depth_store, &cfqd->cfq_max_depth, 1, UINT_MAX, 0);
1703#undef STORE_FUNCTION 2452#undef STORE_FUNCTION
1704 2453
1705static struct cfq_fs_entry cfq_quantum_entry = { 2454static struct cfq_fs_entry cfq_quantum_entry = {
@@ -1712,25 +2461,15 @@ static struct cfq_fs_entry cfq_queued_entry = {
1712 .show = cfq_queued_show, 2461 .show = cfq_queued_show,
1713 .store = cfq_queued_store, 2462 .store = cfq_queued_store,
1714}; 2463};
1715static struct cfq_fs_entry cfq_fifo_expire_r_entry = { 2464static struct cfq_fs_entry cfq_fifo_expire_sync_entry = {
1716 .attr = {.name = "fifo_expire_sync", .mode = S_IRUGO | S_IWUSR }, 2465 .attr = {.name = "fifo_expire_sync", .mode = S_IRUGO | S_IWUSR },
1717 .show = cfq_fifo_expire_r_show, 2466 .show = cfq_fifo_expire_sync_show,
1718 .store = cfq_fifo_expire_r_store, 2467 .store = cfq_fifo_expire_sync_store,
1719}; 2468};
1720static struct cfq_fs_entry cfq_fifo_expire_w_entry = { 2469static struct cfq_fs_entry cfq_fifo_expire_async_entry = {
1721 .attr = {.name = "fifo_expire_async", .mode = S_IRUGO | S_IWUSR }, 2470 .attr = {.name = "fifo_expire_async", .mode = S_IRUGO | S_IWUSR },
1722 .show = cfq_fifo_expire_w_show, 2471 .show = cfq_fifo_expire_async_show,
1723 .store = cfq_fifo_expire_w_store, 2472 .store = cfq_fifo_expire_async_store,
1724};
1725static struct cfq_fs_entry cfq_fifo_batch_expire_entry = {
1726 .attr = {.name = "fifo_batch_expire", .mode = S_IRUGO | S_IWUSR },
1727 .show = cfq_fifo_batch_expire_show,
1728 .store = cfq_fifo_batch_expire_store,
1729};
1730static struct cfq_fs_entry cfq_find_best_entry = {
1731 .attr = {.name = "find_best_crq", .mode = S_IRUGO | S_IWUSR },
1732 .show = cfq_find_best_show,
1733 .store = cfq_find_best_store,
1734}; 2473};
1735static struct cfq_fs_entry cfq_back_max_entry = { 2474static struct cfq_fs_entry cfq_back_max_entry = {
1736 .attr = {.name = "back_seek_max", .mode = S_IRUGO | S_IWUSR }, 2475 .attr = {.name = "back_seek_max", .mode = S_IRUGO | S_IWUSR },
@@ -1742,27 +2481,44 @@ static struct cfq_fs_entry cfq_back_penalty_entry = {
1742 .show = cfq_back_penalty_show, 2481 .show = cfq_back_penalty_show,
1743 .store = cfq_back_penalty_store, 2482 .store = cfq_back_penalty_store,
1744}; 2483};
1745static struct cfq_fs_entry cfq_clear_elapsed_entry = { 2484static struct cfq_fs_entry cfq_slice_sync_entry = {
1746 .attr = {.name = "clear_elapsed", .mode = S_IWUSR }, 2485 .attr = {.name = "slice_sync", .mode = S_IRUGO | S_IWUSR },
1747 .store = cfq_clear_elapsed, 2486 .show = cfq_slice_sync_show,
2487 .store = cfq_slice_sync_store,
2488};
2489static struct cfq_fs_entry cfq_slice_async_entry = {
2490 .attr = {.name = "slice_async", .mode = S_IRUGO | S_IWUSR },
2491 .show = cfq_slice_async_show,
2492 .store = cfq_slice_async_store,
1748}; 2493};
1749static struct cfq_fs_entry cfq_key_type_entry = { 2494static struct cfq_fs_entry cfq_slice_async_rq_entry = {
1750 .attr = {.name = "key_type", .mode = S_IRUGO | S_IWUSR }, 2495 .attr = {.name = "slice_async_rq", .mode = S_IRUGO | S_IWUSR },
1751 .show = cfq_read_key_type, 2496 .show = cfq_slice_async_rq_show,
1752 .store = cfq_set_key_type, 2497 .store = cfq_slice_async_rq_store,
2498};
2499static struct cfq_fs_entry cfq_slice_idle_entry = {
2500 .attr = {.name = "slice_idle", .mode = S_IRUGO | S_IWUSR },
2501 .show = cfq_slice_idle_show,
2502 .store = cfq_slice_idle_store,
2503};
2504static struct cfq_fs_entry cfq_max_depth_entry = {
2505 .attr = {.name = "max_depth", .mode = S_IRUGO | S_IWUSR },
2506 .show = cfq_max_depth_show,
2507 .store = cfq_max_depth_store,
1753}; 2508};
1754 2509
1755static struct attribute *default_attrs[] = { 2510static struct attribute *default_attrs[] = {
1756 &cfq_quantum_entry.attr, 2511 &cfq_quantum_entry.attr,
1757 &cfq_queued_entry.attr, 2512 &cfq_queued_entry.attr,
1758 &cfq_fifo_expire_r_entry.attr, 2513 &cfq_fifo_expire_sync_entry.attr,
1759 &cfq_fifo_expire_w_entry.attr, 2514 &cfq_fifo_expire_async_entry.attr,
1760 &cfq_fifo_batch_expire_entry.attr,
1761 &cfq_key_type_entry.attr,
1762 &cfq_find_best_entry.attr,
1763 &cfq_back_max_entry.attr, 2515 &cfq_back_max_entry.attr,
1764 &cfq_back_penalty_entry.attr, 2516 &cfq_back_penalty_entry.attr,
1765 &cfq_clear_elapsed_entry.attr, 2517 &cfq_slice_sync_entry.attr,
2518 &cfq_slice_async_entry.attr,
2519 &cfq_slice_async_rq_entry.attr,
2520 &cfq_slice_idle_entry.attr,
2521 &cfq_max_depth_entry.attr,
1766 NULL, 2522 NULL,
1767}; 2523};
1768 2524
@@ -1832,21 +2588,46 @@ static int __init cfq_init(void)
1832{ 2588{
1833 int ret; 2589 int ret;
1834 2590
2591 /*
2592 * could be 0 on HZ < 1000 setups
2593 */
2594 if (!cfq_slice_async)
2595 cfq_slice_async = 1;
2596 if (!cfq_slice_idle)
2597 cfq_slice_idle = 1;
2598
1835 if (cfq_slab_setup()) 2599 if (cfq_slab_setup())
1836 return -ENOMEM; 2600 return -ENOMEM;
1837 2601
1838 ret = elv_register(&iosched_cfq); 2602 ret = elv_register(&iosched_cfq);
1839 if (!ret) { 2603 if (ret)
1840 __module_get(THIS_MODULE); 2604 cfq_slab_kill();
1841 return 0;
1842 }
1843 2605
1844 cfq_slab_kill();
1845 return ret; 2606 return ret;
1846} 2607}
1847 2608
1848static void __exit cfq_exit(void) 2609static void __exit cfq_exit(void)
1849{ 2610{
2611 struct task_struct *g, *p;
2612 unsigned long flags;
2613
2614 read_lock_irqsave(&tasklist_lock, flags);
2615
2616 /*
2617 * iterate each process in the system, removing our io_context
2618 */
2619 do_each_thread(g, p) {
2620 struct io_context *ioc = p->io_context;
2621
2622 if (ioc && ioc->cic) {
2623 ioc->cic->exit(ioc->cic);
2624 cfq_free_io_context(ioc->cic);
2625 ioc->cic = NULL;
2626 }
2627 } while_each_thread(g, p);
2628
2629 read_unlock_irqrestore(&tasklist_lock, flags);
2630
1850 cfq_slab_kill(); 2631 cfq_slab_kill();
1851 elv_unregister(&iosched_cfq); 2632 elv_unregister(&iosched_cfq);
1852} 2633}
diff --git a/drivers/block/deadline-iosched.c b/drivers/block/deadline-iosched.c
index 4bc2fea73273..ff5201e02153 100644
--- a/drivers/block/deadline-iosched.c
+++ b/drivers/block/deadline-iosched.c
@@ -760,7 +760,8 @@ static void deadline_put_request(request_queue_t *q, struct request *rq)
760} 760}
761 761
762static int 762static int
763deadline_set_request(request_queue_t *q, struct request *rq, int gfp_mask) 763deadline_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
764 int gfp_mask)
764{ 765{
765 struct deadline_data *dd = q->elevator->elevator_data; 766 struct deadline_data *dd = q->elevator->elevator_data;
766 struct deadline_rq *drq; 767 struct deadline_rq *drq;
diff --git a/drivers/block/elevator.c b/drivers/block/elevator.c
index f831f08f839c..98f0126a2deb 100644
--- a/drivers/block/elevator.c
+++ b/drivers/block/elevator.c
@@ -486,12 +486,13 @@ struct request *elv_former_request(request_queue_t *q, struct request *rq)
486 return NULL; 486 return NULL;
487} 487}
488 488
489int elv_set_request(request_queue_t *q, struct request *rq, int gfp_mask) 489int elv_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
490 int gfp_mask)
490{ 491{
491 elevator_t *e = q->elevator; 492 elevator_t *e = q->elevator;
492 493
493 if (e->ops->elevator_set_req_fn) 494 if (e->ops->elevator_set_req_fn)
494 return e->ops->elevator_set_req_fn(q, rq, gfp_mask); 495 return e->ops->elevator_set_req_fn(q, rq, bio, gfp_mask);
495 496
496 rq->elevator_private = NULL; 497 rq->elevator_private = NULL;
497 return 0; 498 return 0;
@@ -505,12 +506,12 @@ void elv_put_request(request_queue_t *q, struct request *rq)
505 e->ops->elevator_put_req_fn(q, rq); 506 e->ops->elevator_put_req_fn(q, rq);
506} 507}
507 508
508int elv_may_queue(request_queue_t *q, int rw) 509int elv_may_queue(request_queue_t *q, int rw, struct bio *bio)
509{ 510{
510 elevator_t *e = q->elevator; 511 elevator_t *e = q->elevator;
511 512
512 if (e->ops->elevator_may_queue_fn) 513 if (e->ops->elevator_may_queue_fn)
513 return e->ops->elevator_may_queue_fn(q, rw); 514 return e->ops->elevator_may_queue_fn(q, rw, bio);
514 515
515 return ELV_MQUEUE_MAY; 516 return ELV_MQUEUE_MAY;
516} 517}
diff --git a/drivers/block/ll_rw_blk.c b/drivers/block/ll_rw_blk.c
index 60e64091de1b..692a5fced76e 100644
--- a/drivers/block/ll_rw_blk.c
+++ b/drivers/block/ll_rw_blk.c
@@ -276,6 +276,7 @@ static inline void rq_init(request_queue_t *q, struct request *rq)
276 rq->errors = 0; 276 rq->errors = 0;
277 rq->rq_status = RQ_ACTIVE; 277 rq->rq_status = RQ_ACTIVE;
278 rq->bio = rq->biotail = NULL; 278 rq->bio = rq->biotail = NULL;
279 rq->ioprio = 0;
279 rq->buffer = NULL; 280 rq->buffer = NULL;
280 rq->ref_count = 1; 281 rq->ref_count = 1;
281 rq->q = q; 282 rq->q = q;
@@ -1442,11 +1443,7 @@ void __generic_unplug_device(request_queue_t *q)
1442 if (!blk_remove_plug(q)) 1443 if (!blk_remove_plug(q))
1443 return; 1444 return;
1444 1445
1445 /* 1446 q->request_fn(q);
1446 * was plugged, fire request_fn if queue has stuff to do
1447 */
1448 if (elv_next_request(q))
1449 q->request_fn(q);
1450} 1447}
1451EXPORT_SYMBOL(__generic_unplug_device); 1448EXPORT_SYMBOL(__generic_unplug_device);
1452 1449
@@ -1776,8 +1773,8 @@ static inline void blk_free_request(request_queue_t *q, struct request *rq)
1776 mempool_free(rq, q->rq.rq_pool); 1773 mempool_free(rq, q->rq.rq_pool);
1777} 1774}
1778 1775
1779static inline struct request *blk_alloc_request(request_queue_t *q, int rw, 1776static inline struct request *
1780 int gfp_mask) 1777blk_alloc_request(request_queue_t *q, int rw, struct bio *bio, int gfp_mask)
1781{ 1778{
1782 struct request *rq = mempool_alloc(q->rq.rq_pool, gfp_mask); 1779 struct request *rq = mempool_alloc(q->rq.rq_pool, gfp_mask);
1783 1780
@@ -1790,7 +1787,7 @@ static inline struct request *blk_alloc_request(request_queue_t *q, int rw,
1790 */ 1787 */
1791 rq->flags = rw; 1788 rq->flags = rw;
1792 1789
1793 if (!elv_set_request(q, rq, gfp_mask)) 1790 if (!elv_set_request(q, rq, bio, gfp_mask))
1794 return rq; 1791 return rq;
1795 1792
1796 mempool_free(rq, q->rq.rq_pool); 1793 mempool_free(rq, q->rq.rq_pool);
@@ -1870,18 +1867,20 @@ static void freed_request(request_queue_t *q, int rw)
1870 1867
1871#define blkdev_free_rq(list) list_entry((list)->next, struct request, queuelist) 1868#define blkdev_free_rq(list) list_entry((list)->next, struct request, queuelist)
1872/* 1869/*
1873 * Get a free request, queue_lock must not be held 1870 * Get a free request, queue_lock must be held.
1871 * Returns NULL on failure, with queue_lock held.
1872 * Returns !NULL on success, with queue_lock *not held*.
1874 */ 1873 */
1875static struct request *get_request(request_queue_t *q, int rw, int gfp_mask) 1874static struct request *get_request(request_queue_t *q, int rw, struct bio *bio,
1875 int gfp_mask)
1876{ 1876{
1877 struct request *rq = NULL; 1877 struct request *rq = NULL;
1878 struct request_list *rl = &q->rq; 1878 struct request_list *rl = &q->rq;
1879 struct io_context *ioc = get_io_context(gfp_mask); 1879 struct io_context *ioc = current_io_context(GFP_ATOMIC);
1880 1880
1881 if (unlikely(test_bit(QUEUE_FLAG_DRAIN, &q->queue_flags))) 1881 if (unlikely(test_bit(QUEUE_FLAG_DRAIN, &q->queue_flags)))
1882 goto out; 1882 goto out;
1883 1883
1884 spin_lock_irq(q->queue_lock);
1885 if (rl->count[rw]+1 >= q->nr_requests) { 1884 if (rl->count[rw]+1 >= q->nr_requests) {
1886 /* 1885 /*
1887 * The queue will fill after this allocation, so set it as 1886 * The queue will fill after this allocation, so set it as
@@ -1895,7 +1894,7 @@ static struct request *get_request(request_queue_t *q, int rw, int gfp_mask)
1895 } 1894 }
1896 } 1895 }
1897 1896
1898 switch (elv_may_queue(q, rw)) { 1897 switch (elv_may_queue(q, rw, bio)) {
1899 case ELV_MQUEUE_NO: 1898 case ELV_MQUEUE_NO:
1900 goto rq_starved; 1899 goto rq_starved;
1901 case ELV_MQUEUE_MAY: 1900 case ELV_MQUEUE_MAY:
@@ -1909,18 +1908,25 @@ static struct request *get_request(request_queue_t *q, int rw, int gfp_mask)
1909 * The queue is full and the allocating process is not a 1908 * The queue is full and the allocating process is not a
1910 * "batcher", and not exempted by the IO scheduler 1909 * "batcher", and not exempted by the IO scheduler
1911 */ 1910 */
1912 spin_unlock_irq(q->queue_lock);
1913 goto out; 1911 goto out;
1914 } 1912 }
1915 1913
1916get_rq: 1914get_rq:
1915 /*
1916 * Only allow batching queuers to allocate up to 50% over the defined
1917 * limit of requests, otherwise we could have thousands of requests
1918 * allocated with any setting of ->nr_requests
1919 */
1920 if (rl->count[rw] >= (3 * q->nr_requests / 2))
1921 goto out;
1922
1917 rl->count[rw]++; 1923 rl->count[rw]++;
1918 rl->starved[rw] = 0; 1924 rl->starved[rw] = 0;
1919 if (rl->count[rw] >= queue_congestion_on_threshold(q)) 1925 if (rl->count[rw] >= queue_congestion_on_threshold(q))
1920 set_queue_congested(q, rw); 1926 set_queue_congested(q, rw);
1921 spin_unlock_irq(q->queue_lock); 1927 spin_unlock_irq(q->queue_lock);
1922 1928
1923 rq = blk_alloc_request(q, rw, gfp_mask); 1929 rq = blk_alloc_request(q, rw, bio, gfp_mask);
1924 if (!rq) { 1930 if (!rq) {
1925 /* 1931 /*
1926 * Allocation failed presumably due to memory. Undo anything 1932 * Allocation failed presumably due to memory. Undo anything
@@ -1943,7 +1949,6 @@ rq_starved:
1943 if (unlikely(rl->count[rw] == 0)) 1949 if (unlikely(rl->count[rw] == 0))
1944 rl->starved[rw] = 1; 1950 rl->starved[rw] = 1;
1945 1951
1946 spin_unlock_irq(q->queue_lock);
1947 goto out; 1952 goto out;
1948 } 1953 }
1949 1954
@@ -1953,31 +1958,35 @@ rq_starved:
1953 rq_init(q, rq); 1958 rq_init(q, rq);
1954 rq->rl = rl; 1959 rq->rl = rl;
1955out: 1960out:
1956 put_io_context(ioc);
1957 return rq; 1961 return rq;
1958} 1962}
1959 1963
1960/* 1964/*
1961 * No available requests for this queue, unplug the device and wait for some 1965 * No available requests for this queue, unplug the device and wait for some
1962 * requests to become available. 1966 * requests to become available.
1967 *
1968 * Called with q->queue_lock held, and returns with it unlocked.
1963 */ 1969 */
1964static struct request *get_request_wait(request_queue_t *q, int rw) 1970static struct request *get_request_wait(request_queue_t *q, int rw,
1971 struct bio *bio)
1965{ 1972{
1966 DEFINE_WAIT(wait);
1967 struct request *rq; 1973 struct request *rq;
1968 1974
1969 do { 1975 rq = get_request(q, rw, bio, GFP_NOIO);
1976 while (!rq) {
1977 DEFINE_WAIT(wait);
1970 struct request_list *rl = &q->rq; 1978 struct request_list *rl = &q->rq;
1971 1979
1972 prepare_to_wait_exclusive(&rl->wait[rw], &wait, 1980 prepare_to_wait_exclusive(&rl->wait[rw], &wait,
1973 TASK_UNINTERRUPTIBLE); 1981 TASK_UNINTERRUPTIBLE);
1974 1982
1975 rq = get_request(q, rw, GFP_NOIO); 1983 rq = get_request(q, rw, bio, GFP_NOIO);
1976 1984
1977 if (!rq) { 1985 if (!rq) {
1978 struct io_context *ioc; 1986 struct io_context *ioc;
1979 1987
1980 generic_unplug_device(q); 1988 __generic_unplug_device(q);
1989 spin_unlock_irq(q->queue_lock);
1981 io_schedule(); 1990 io_schedule();
1982 1991
1983 /* 1992 /*
@@ -1986,12 +1995,13 @@ static struct request *get_request_wait(request_queue_t *q, int rw)
1986 * up to a big batch of them for a small period time. 1995 * up to a big batch of them for a small period time.
1987 * See ioc_batching, ioc_set_batching 1996 * See ioc_batching, ioc_set_batching
1988 */ 1997 */
1989 ioc = get_io_context(GFP_NOIO); 1998 ioc = current_io_context(GFP_NOIO);
1990 ioc_set_batching(q, ioc); 1999 ioc_set_batching(q, ioc);
1991 put_io_context(ioc); 2000
2001 spin_lock_irq(q->queue_lock);
1992 } 2002 }
1993 finish_wait(&rl->wait[rw], &wait); 2003 finish_wait(&rl->wait[rw], &wait);
1994 } while (!rq); 2004 }
1995 2005
1996 return rq; 2006 return rq;
1997} 2007}
@@ -2002,14 +2012,18 @@ struct request *blk_get_request(request_queue_t *q, int rw, int gfp_mask)
2002 2012
2003 BUG_ON(rw != READ && rw != WRITE); 2013 BUG_ON(rw != READ && rw != WRITE);
2004 2014
2005 if (gfp_mask & __GFP_WAIT) 2015 spin_lock_irq(q->queue_lock);
2006 rq = get_request_wait(q, rw); 2016 if (gfp_mask & __GFP_WAIT) {
2007 else 2017 rq = get_request_wait(q, rw, NULL);
2008 rq = get_request(q, rw, gfp_mask); 2018 } else {
2019 rq = get_request(q, rw, NULL, gfp_mask);
2020 if (!rq)
2021 spin_unlock_irq(q->queue_lock);
2022 }
2023 /* q->queue_lock is unlocked at this point */
2009 2024
2010 return rq; 2025 return rq;
2011} 2026}
2012
2013EXPORT_SYMBOL(blk_get_request); 2027EXPORT_SYMBOL(blk_get_request);
2014 2028
2015/** 2029/**
@@ -2333,7 +2347,6 @@ static void __blk_put_request(request_queue_t *q, struct request *req)
2333 return; 2347 return;
2334 2348
2335 req->rq_status = RQ_INACTIVE; 2349 req->rq_status = RQ_INACTIVE;
2336 req->q = NULL;
2337 req->rl = NULL; 2350 req->rl = NULL;
2338 2351
2339 /* 2352 /*
@@ -2462,6 +2475,8 @@ static int attempt_merge(request_queue_t *q, struct request *req,
2462 req->rq_disk->in_flight--; 2475 req->rq_disk->in_flight--;
2463 } 2476 }
2464 2477
2478 req->ioprio = ioprio_best(req->ioprio, next->ioprio);
2479
2465 __blk_put_request(q, next); 2480 __blk_put_request(q, next);
2466 return 1; 2481 return 1;
2467} 2482}
@@ -2512,13 +2527,15 @@ EXPORT_SYMBOL(blk_attempt_remerge);
2512 2527
2513static int __make_request(request_queue_t *q, struct bio *bio) 2528static int __make_request(request_queue_t *q, struct bio *bio)
2514{ 2529{
2515 struct request *req, *freereq = NULL; 2530 struct request *req;
2516 int el_ret, rw, nr_sectors, cur_nr_sectors, barrier, err, sync; 2531 int el_ret, rw, nr_sectors, cur_nr_sectors, barrier, err, sync;
2532 unsigned short prio;
2517 sector_t sector; 2533 sector_t sector;
2518 2534
2519 sector = bio->bi_sector; 2535 sector = bio->bi_sector;
2520 nr_sectors = bio_sectors(bio); 2536 nr_sectors = bio_sectors(bio);
2521 cur_nr_sectors = bio_cur_sectors(bio); 2537 cur_nr_sectors = bio_cur_sectors(bio);
2538 prio = bio_prio(bio);
2522 2539
2523 rw = bio_data_dir(bio); 2540 rw = bio_data_dir(bio);
2524 sync = bio_sync(bio); 2541 sync = bio_sync(bio);
@@ -2538,14 +2555,9 @@ static int __make_request(request_queue_t *q, struct bio *bio)
2538 goto end_io; 2555 goto end_io;
2539 } 2556 }
2540 2557
2541again:
2542 spin_lock_irq(q->queue_lock); 2558 spin_lock_irq(q->queue_lock);
2543 2559
2544 if (elv_queue_empty(q)) { 2560 if (unlikely(barrier) || elv_queue_empty(q))
2545 blk_plug_device(q);
2546 goto get_rq;
2547 }
2548 if (barrier)
2549 goto get_rq; 2561 goto get_rq;
2550 2562
2551 el_ret = elv_merge(q, &req, bio); 2563 el_ret = elv_merge(q, &req, bio);
@@ -2559,6 +2571,7 @@ again:
2559 req->biotail->bi_next = bio; 2571 req->biotail->bi_next = bio;
2560 req->biotail = bio; 2572 req->biotail = bio;
2561 req->nr_sectors = req->hard_nr_sectors += nr_sectors; 2573 req->nr_sectors = req->hard_nr_sectors += nr_sectors;
2574 req->ioprio = ioprio_best(req->ioprio, prio);
2562 drive_stat_acct(req, nr_sectors, 0); 2575 drive_stat_acct(req, nr_sectors, 0);
2563 if (!attempt_back_merge(q, req)) 2576 if (!attempt_back_merge(q, req))
2564 elv_merged_request(q, req); 2577 elv_merged_request(q, req);
@@ -2583,45 +2596,30 @@ again:
2583 req->hard_cur_sectors = cur_nr_sectors; 2596 req->hard_cur_sectors = cur_nr_sectors;
2584 req->sector = req->hard_sector = sector; 2597 req->sector = req->hard_sector = sector;
2585 req->nr_sectors = req->hard_nr_sectors += nr_sectors; 2598 req->nr_sectors = req->hard_nr_sectors += nr_sectors;
2599 req->ioprio = ioprio_best(req->ioprio, prio);
2586 drive_stat_acct(req, nr_sectors, 0); 2600 drive_stat_acct(req, nr_sectors, 0);
2587 if (!attempt_front_merge(q, req)) 2601 if (!attempt_front_merge(q, req))
2588 elv_merged_request(q, req); 2602 elv_merged_request(q, req);
2589 goto out; 2603 goto out;
2590 2604
2591 /* 2605 /* ELV_NO_MERGE: elevator says don't/can't merge. */
2592 * elevator says don't/can't merge. get new request
2593 */
2594 case ELEVATOR_NO_MERGE:
2595 break;
2596
2597 default: 2606 default:
2598 printk("elevator returned crap (%d)\n", el_ret); 2607 ;
2599 BUG();
2600 } 2608 }
2601 2609
2610get_rq:
2602 /* 2611 /*
2603 * Grab a free request from the freelist - if that is empty, check 2612 * Grab a free request. This is might sleep but can not fail.
2604 * if we are doing read ahead and abort instead of blocking for 2613 * Returns with the queue unlocked.
2605 * a free slot. 2614 */
2615 req = get_request_wait(q, rw, bio);
2616
2617 /*
2618 * After dropping the lock and possibly sleeping here, our request
2619 * may now be mergeable after it had proven unmergeable (above).
2620 * We don't worry about that case for efficiency. It won't happen
2621 * often, and the elevators are able to handle it.
2606 */ 2622 */
2607get_rq:
2608 if (freereq) {
2609 req = freereq;
2610 freereq = NULL;
2611 } else {
2612 spin_unlock_irq(q->queue_lock);
2613 if ((freereq = get_request(q, rw, GFP_ATOMIC)) == NULL) {
2614 /*
2615 * READA bit set
2616 */
2617 err = -EWOULDBLOCK;
2618 if (bio_rw_ahead(bio))
2619 goto end_io;
2620
2621 freereq = get_request_wait(q, rw);
2622 }
2623 goto again;
2624 }
2625 2623
2626 req->flags |= REQ_CMD; 2624 req->flags |= REQ_CMD;
2627 2625
@@ -2646,13 +2644,15 @@ get_rq:
2646 req->buffer = bio_data(bio); /* see ->buffer comment above */ 2644 req->buffer = bio_data(bio); /* see ->buffer comment above */
2647 req->waiting = NULL; 2645 req->waiting = NULL;
2648 req->bio = req->biotail = bio; 2646 req->bio = req->biotail = bio;
2647 req->ioprio = prio;
2649 req->rq_disk = bio->bi_bdev->bd_disk; 2648 req->rq_disk = bio->bi_bdev->bd_disk;
2650 req->start_time = jiffies; 2649 req->start_time = jiffies;
2651 2650
2651 spin_lock_irq(q->queue_lock);
2652 if (elv_queue_empty(q))
2653 blk_plug_device(q);
2652 add_request(q, req); 2654 add_request(q, req);
2653out: 2655out:
2654 if (freereq)
2655 __blk_put_request(q, freereq);
2656 if (sync) 2656 if (sync)
2657 __generic_unplug_device(q); 2657 __generic_unplug_device(q);
2658 2658
@@ -2674,7 +2674,7 @@ static inline void blk_partition_remap(struct bio *bio)
2674 if (bdev != bdev->bd_contains) { 2674 if (bdev != bdev->bd_contains) {
2675 struct hd_struct *p = bdev->bd_part; 2675 struct hd_struct *p = bdev->bd_part;
2676 2676
2677 switch (bio->bi_rw) { 2677 switch (bio_data_dir(bio)) {
2678 case READ: 2678 case READ:
2679 p->read_sectors += bio_sectors(bio); 2679 p->read_sectors += bio_sectors(bio);
2680 p->reads++; 2680 p->reads++;
@@ -2693,6 +2693,7 @@ void blk_finish_queue_drain(request_queue_t *q)
2693{ 2693{
2694 struct request_list *rl = &q->rq; 2694 struct request_list *rl = &q->rq;
2695 struct request *rq; 2695 struct request *rq;
2696 int requeued = 0;
2696 2697
2697 spin_lock_irq(q->queue_lock); 2698 spin_lock_irq(q->queue_lock);
2698 clear_bit(QUEUE_FLAG_DRAIN, &q->queue_flags); 2699 clear_bit(QUEUE_FLAG_DRAIN, &q->queue_flags);
@@ -2701,9 +2702,13 @@ void blk_finish_queue_drain(request_queue_t *q)
2701 rq = list_entry_rq(q->drain_list.next); 2702 rq = list_entry_rq(q->drain_list.next);
2702 2703
2703 list_del_init(&rq->queuelist); 2704 list_del_init(&rq->queuelist);
2704 __elv_add_request(q, rq, ELEVATOR_INSERT_BACK, 1); 2705 elv_requeue_request(q, rq);
2706 requeued++;
2705 } 2707 }
2706 2708
2709 if (requeued)
2710 q->request_fn(q);
2711
2707 spin_unlock_irq(q->queue_lock); 2712 spin_unlock_irq(q->queue_lock);
2708 2713
2709 wake_up(&rl->wait[0]); 2714 wake_up(&rl->wait[0]);
@@ -2900,7 +2905,7 @@ void submit_bio(int rw, struct bio *bio)
2900 2905
2901 BIO_BUG_ON(!bio->bi_size); 2906 BIO_BUG_ON(!bio->bi_size);
2902 BIO_BUG_ON(!bio->bi_io_vec); 2907 BIO_BUG_ON(!bio->bi_io_vec);
2903 bio->bi_rw = rw; 2908 bio->bi_rw |= rw;
2904 if (rw & WRITE) 2909 if (rw & WRITE)
2905 mod_page_state(pgpgout, count); 2910 mod_page_state(pgpgout, count);
2906 else 2911 else
@@ -3257,8 +3262,11 @@ void exit_io_context(void)
3257 struct io_context *ioc; 3262 struct io_context *ioc;
3258 3263
3259 local_irq_save(flags); 3264 local_irq_save(flags);
3265 task_lock(current);
3260 ioc = current->io_context; 3266 ioc = current->io_context;
3261 current->io_context = NULL; 3267 current->io_context = NULL;
3268 ioc->task = NULL;
3269 task_unlock(current);
3262 local_irq_restore(flags); 3270 local_irq_restore(flags);
3263 3271
3264 if (ioc->aic && ioc->aic->exit) 3272 if (ioc->aic && ioc->aic->exit)
@@ -3271,53 +3279,49 @@ void exit_io_context(void)
3271 3279
3272/* 3280/*
3273 * If the current task has no IO context then create one and initialise it. 3281 * If the current task has no IO context then create one and initialise it.
3274 * If it does have a context, take a ref on it. 3282 * Otherwise, return its existing IO context.
3275 * 3283 *
3276 * This is always called in the context of the task which submitted the I/O. 3284 * This returned IO context doesn't have a specifically elevated refcount,
3277 * But weird things happen, so we disable local interrupts to ensure exclusive 3285 * but since the current task itself holds a reference, the context can be
3278 * access to *current. 3286 * used in general code, so long as it stays within `current` context.
3279 */ 3287 */
3280struct io_context *get_io_context(int gfp_flags) 3288struct io_context *current_io_context(int gfp_flags)
3281{ 3289{
3282 struct task_struct *tsk = current; 3290 struct task_struct *tsk = current;
3283 unsigned long flags;
3284 struct io_context *ret; 3291 struct io_context *ret;
3285 3292
3286 local_irq_save(flags);
3287 ret = tsk->io_context; 3293 ret = tsk->io_context;
3288 if (ret) 3294 if (likely(ret))
3289 goto out; 3295 return ret;
3290
3291 local_irq_restore(flags);
3292 3296
3293 ret = kmem_cache_alloc(iocontext_cachep, gfp_flags); 3297 ret = kmem_cache_alloc(iocontext_cachep, gfp_flags);
3294 if (ret) { 3298 if (ret) {
3295 atomic_set(&ret->refcount, 1); 3299 atomic_set(&ret->refcount, 1);
3296 ret->pid = tsk->pid; 3300 ret->task = current;
3301 ret->set_ioprio = NULL;
3297 ret->last_waited = jiffies; /* doesn't matter... */ 3302 ret->last_waited = jiffies; /* doesn't matter... */
3298 ret->nr_batch_requests = 0; /* because this is 0 */ 3303 ret->nr_batch_requests = 0; /* because this is 0 */
3299 ret->aic = NULL; 3304 ret->aic = NULL;
3300 ret->cic = NULL; 3305 ret->cic = NULL;
3301 spin_lock_init(&ret->lock); 3306 tsk->io_context = ret;
3302 3307 }
3303 local_irq_save(flags);
3304 3308
3305 /* 3309 return ret;
3306 * very unlikely, someone raced with us in setting up the task 3310}
3307 * io context. free new context and just grab a reference. 3311EXPORT_SYMBOL(current_io_context);
3308 */
3309 if (!tsk->io_context)
3310 tsk->io_context = ret;
3311 else {
3312 kmem_cache_free(iocontext_cachep, ret);
3313 ret = tsk->io_context;
3314 }
3315 3312
3316out: 3313/*
3314 * If the current task has no IO context then create one and initialise it.
3315 * If it does have a context, take a ref on it.
3316 *
3317 * This is always called in the context of the task which submitted the I/O.
3318 */
3319struct io_context *get_io_context(int gfp_flags)
3320{
3321 struct io_context *ret;
3322 ret = current_io_context(gfp_flags);
3323 if (likely(ret))
3317 atomic_inc(&ret->refcount); 3324 atomic_inc(&ret->refcount);
3318 local_irq_restore(flags);
3319 }
3320
3321 return ret; 3325 return ret;
3322} 3326}
3323EXPORT_SYMBOL(get_io_context); 3327EXPORT_SYMBOL(get_io_context);
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index 5b09cf154ac7..e5f7494c00ee 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -253,7 +253,7 @@ static int floppy_revalidate(struct gendisk *disk);
253static int swim3_add_device(struct device_node *swims); 253static int swim3_add_device(struct device_node *swims);
254int swim3_init(void); 254int swim3_init(void);
255 255
256#ifndef CONFIG_PMAC_PBOOK 256#ifndef CONFIG_PMAC_MEDIABAY
257#define check_media_bay(which, what) 1 257#define check_media_bay(which, what) 1
258#endif 258#endif
259 259
@@ -297,9 +297,11 @@ static void do_fd_request(request_queue_t * q)
297 int i; 297 int i;
298 for(i=0;i<floppy_count;i++) 298 for(i=0;i<floppy_count;i++)
299 { 299 {
300#ifdef CONFIG_PMAC_MEDIABAY
300 if (floppy_states[i].media_bay && 301 if (floppy_states[i].media_bay &&
301 check_media_bay(floppy_states[i].media_bay, MB_FD)) 302 check_media_bay(floppy_states[i].media_bay, MB_FD))
302 continue; 303 continue;
304#endif /* CONFIG_PMAC_MEDIABAY */
303 start_request(&floppy_states[i]); 305 start_request(&floppy_states[i]);
304 } 306 }
305 sti(); 307 sti();
@@ -856,8 +858,10 @@ static int floppy_ioctl(struct inode *inode, struct file *filp,
856 if ((cmd & 0x80) && !capable(CAP_SYS_ADMIN)) 858 if ((cmd & 0x80) && !capable(CAP_SYS_ADMIN))
857 return -EPERM; 859 return -EPERM;
858 860
861#ifdef CONFIG_PMAC_MEDIABAY
859 if (fs->media_bay && check_media_bay(fs->media_bay, MB_FD)) 862 if (fs->media_bay && check_media_bay(fs->media_bay, MB_FD))
860 return -ENXIO; 863 return -ENXIO;
864#endif
861 865
862 switch (cmd) { 866 switch (cmd) {
863 case FDEJECT: 867 case FDEJECT:
@@ -881,8 +885,10 @@ static int floppy_open(struct inode *inode, struct file *filp)
881 int n, err = 0; 885 int n, err = 0;
882 886
883 if (fs->ref_count == 0) { 887 if (fs->ref_count == 0) {
888#ifdef CONFIG_PMAC_MEDIABAY
884 if (fs->media_bay && check_media_bay(fs->media_bay, MB_FD)) 889 if (fs->media_bay && check_media_bay(fs->media_bay, MB_FD))
885 return -ENXIO; 890 return -ENXIO;
891#endif
886 out_8(&sw->setup, S_IBM_DRIVE | S_FCLK_DIV2); 892 out_8(&sw->setup, S_IBM_DRIVE | S_FCLK_DIV2);
887 out_8(&sw->control_bic, 0xff); 893 out_8(&sw->control_bic, 0xff);
888 out_8(&sw->mode, 0x95); 894 out_8(&sw->mode, 0x95);
@@ -967,8 +973,10 @@ static int floppy_revalidate(struct gendisk *disk)
967 struct swim3 __iomem *sw; 973 struct swim3 __iomem *sw;
968 int ret, n; 974 int ret, n;
969 975
976#ifdef CONFIG_PMAC_MEDIABAY
970 if (fs->media_bay && check_media_bay(fs->media_bay, MB_FD)) 977 if (fs->media_bay && check_media_bay(fs->media_bay, MB_FD))
971 return -ENXIO; 978 return -ENXIO;
979#endif
972 980
973 sw = fs->swim3; 981 sw = fs->swim3;
974 grab_drive(fs, revalidating, 0); 982 grab_drive(fs, revalidating, 0);
diff --git a/drivers/block/sx8.c b/drivers/block/sx8.c
index 5ed3a6379452..9db0a9e3e59c 100644
--- a/drivers/block/sx8.c
+++ b/drivers/block/sx8.c
@@ -26,6 +26,7 @@
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/time.h> 27#include <linux/time.h>
28#include <linux/hdreg.h> 28#include <linux/hdreg.h>
29#include <linux/dma-mapping.h>
29#include <asm/io.h> 30#include <asm/io.h>
30#include <asm/semaphore.h> 31#include <asm/semaphore.h>
31#include <asm/uaccess.h> 32#include <asm/uaccess.h>
@@ -1582,9 +1583,9 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1582 goto err_out; 1583 goto err_out;
1583 1584
1584#if IF_64BIT_DMA_IS_POSSIBLE /* grrrr... */ 1585#if IF_64BIT_DMA_IS_POSSIBLE /* grrrr... */
1585 rc = pci_set_dma_mask(pdev, 0xffffffffffffffffULL); 1586 rc = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
1586 if (!rc) { 1587 if (!rc) {
1587 rc = pci_set_consistent_dma_mask(pdev, 0xffffffffffffffffULL); 1588 rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
1588 if (rc) { 1589 if (rc) {
1589 printk(KERN_ERR DRV_NAME "(%s): consistent DMA mask failure\n", 1590 printk(KERN_ERR DRV_NAME "(%s): consistent DMA mask failure\n",
1590 pci_name(pdev)); 1591 pci_name(pdev));
@@ -1593,7 +1594,7 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1593 pci_dac = 1; 1594 pci_dac = 1;
1594 } else { 1595 } else {
1595#endif 1596#endif
1596 rc = pci_set_dma_mask(pdev, 0xffffffffULL); 1597 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
1597 if (rc) { 1598 if (rc) {
1598 printk(KERN_ERR DRV_NAME "(%s): DMA mask failure\n", 1599 printk(KERN_ERR DRV_NAME "(%s): DMA mask failure\n",
1599 pci_name(pdev)); 1600 pci_name(pdev));
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
index e481cc411b5d..5ef9adb9fe73 100644
--- a/drivers/bluetooth/bluecard_cs.c
+++ b/drivers/bluetooth/bluecard_cs.c
@@ -1089,6 +1089,14 @@ static int bluecard_event(event_t event, int priority, event_callback_args_t *ar
1089 return 0; 1089 return 0;
1090} 1090}
1091 1091
1092static struct pcmcia_device_id bluecard_ids[] = {
1093 PCMCIA_DEVICE_PROD_ID12("BlueCard", "LSE041", 0xbaf16fbf, 0x657cc15e),
1094 PCMCIA_DEVICE_PROD_ID12("BTCFCARD", "LSE139", 0xe3987764, 0x2524b59c),
1095 PCMCIA_DEVICE_PROD_ID12("WSS", "LSE039", 0x0a0736ec, 0x24e6dfab),
1096 PCMCIA_DEVICE_NULL
1097};
1098MODULE_DEVICE_TABLE(pcmcia, bluecard_ids);
1099
1092static struct pcmcia_driver bluecard_driver = { 1100static struct pcmcia_driver bluecard_driver = {
1093 .owner = THIS_MODULE, 1101 .owner = THIS_MODULE,
1094 .drv = { 1102 .drv = {
@@ -1096,6 +1104,7 @@ static struct pcmcia_driver bluecard_driver = {
1096 }, 1104 },
1097 .attach = bluecard_attach, 1105 .attach = bluecard_attach,
1098 .detach = bluecard_detach, 1106 .detach = bluecard_detach,
1107 .id_table = bluecard_ids,
1099}; 1108};
1100 1109
1101static int __init init_bluecard_cs(void) 1110static int __init init_bluecard_cs(void)
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index f71e5c76963d..9013cd759afb 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -935,6 +935,12 @@ static int bt3c_event(event_t event, int priority, event_callback_args_t *args)
935 return 0; 935 return 0;
936} 936}
937 937
938static struct pcmcia_device_id bt3c_ids[] = {
939 PCMCIA_DEVICE_PROD_ID13("3COM", "Bluetooth PC Card", 0xefce0a31, 0xd4ce9b02),
940 PCMCIA_DEVICE_NULL
941};
942MODULE_DEVICE_TABLE(pcmcia, bt3c_ids);
943
938static struct pcmcia_driver bt3c_driver = { 944static struct pcmcia_driver bt3c_driver = {
939 .owner = THIS_MODULE, 945 .owner = THIS_MODULE,
940 .drv = { 946 .drv = {
@@ -942,6 +948,7 @@ static struct pcmcia_driver bt3c_driver = {
942 }, 948 },
943 .attach = bt3c_attach, 949 .attach = bt3c_attach,
944 .detach = bt3c_detach, 950 .detach = bt3c_detach,
951 .id_table = bt3c_ids,
945}; 952};
946 953
947static int __init init_bt3c_cs(void) 954static int __init init_bt3c_cs(void)
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c
index ad8d972444a5..c479484a1f7f 100644
--- a/drivers/bluetooth/btuart_cs.c
+++ b/drivers/bluetooth/btuart_cs.c
@@ -855,6 +855,12 @@ static int btuart_event(event_t event, int priority, event_callback_args_t *args
855 return 0; 855 return 0;
856} 856}
857 857
858static struct pcmcia_device_id btuart_ids[] = {
859 /* don't use this driver. Use serial_cs + hci_uart instead */
860 PCMCIA_DEVICE_NULL
861};
862MODULE_DEVICE_TABLE(pcmcia, btuart_ids);
863
858static struct pcmcia_driver btuart_driver = { 864static struct pcmcia_driver btuart_driver = {
859 .owner = THIS_MODULE, 865 .owner = THIS_MODULE,
860 .drv = { 866 .drv = {
@@ -862,6 +868,7 @@ static struct pcmcia_driver btuart_driver = {
862 }, 868 },
863 .attach = btuart_attach, 869 .attach = btuart_attach,
864 .detach = btuart_detach, 870 .detach = btuart_detach,
871 .id_table = btuart_ids,
865}; 872};
866 873
867static int __init init_btuart_cs(void) 874static int __init init_btuart_cs(void)
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index fe954e5d9a1d..bb12f7daeb91 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -807,6 +807,13 @@ static int dtl1_event(event_t event, int priority, event_callback_args_t *args)
807 return 0; 807 return 0;
808} 808}
809 809
810static struct pcmcia_device_id dtl1_ids[] = {
811 PCMCIA_DEVICE_PROD_ID12("Nokia Mobile Phones", "DTL-1", 0xe1bfdd64, 0xe168480d),
812 PCMCIA_DEVICE_PROD_ID12("Socket", "CF", 0xb38bcc2e, 0x44ebf863),
813 PCMCIA_DEVICE_NULL
814};
815MODULE_DEVICE_TABLE(pcmcia, dtl1_ids);
816
810static struct pcmcia_driver dtl1_driver = { 817static struct pcmcia_driver dtl1_driver = {
811 .owner = THIS_MODULE, 818 .owner = THIS_MODULE,
812 .drv = { 819 .drv = {
@@ -814,6 +821,7 @@ static struct pcmcia_driver dtl1_driver = {
814 }, 821 },
815 .attach = dtl1_attach, 822 .attach = dtl1_attach,
816 .detach = dtl1_detach, 823 .detach = dtl1_detach,
824 .id_table = dtl1_ids,
817}; 825};
818 826
819static int __init init_dtl1_cs(void) 827static int __init init_dtl1_cs(void)
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 1407945a5892..59f589d733f9 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -686,6 +686,15 @@ static struct pci_device_id agp_amd64_pci_table[] = {
686 .subvendor = PCI_ANY_ID, 686 .subvendor = PCI_ANY_ID,
687 .subdevice = PCI_ANY_ID, 687 .subdevice = PCI_ANY_ID,
688 }, 688 },
689 /* SIS 760 */
690 {
691 .class = (PCI_CLASS_BRIDGE_HOST << 8),
692 .class_mask = ~0,
693 .vendor = PCI_VENDOR_ID_SI,
694 .device = PCI_DEVICE_ID_SI_760,
695 .subvendor = PCI_ANY_ID,
696 .subdevice = PCI_ANY_ID,
697 },
689 { } 698 { }
690}; 699};
691 700
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 1813d0d198f1..e16c13fe698d 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -1088,8 +1088,8 @@ static inline int i_ipmi_request(ipmi_user_t user,
1088 long seqid; 1088 long seqid;
1089 int broadcast = 0; 1089 int broadcast = 0;
1090 1090
1091 if (addr->channel > IPMI_NUM_CHANNELS) { 1091 if (addr->channel >= IPMI_MAX_CHANNELS) {
1092 spin_lock_irqsave(&intf->counter_lock, flags); 1092 spin_lock_irqsave(&intf->counter_lock, flags);
1093 intf->sent_invalid_commands++; 1093 intf->sent_invalid_commands++;
1094 spin_unlock_irqrestore(&intf->counter_lock, flags); 1094 spin_unlock_irqrestore(&intf->counter_lock, flags);
1095 rv = -EINVAL; 1095 rv = -EINVAL;
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 31cf84d69026..931efd58f87a 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -309,9 +309,6 @@ static int __init misc_init(void)
309#ifdef CONFIG_BVME6000 309#ifdef CONFIG_BVME6000
310 rtc_DP8570A_init(); 310 rtc_DP8570A_init();
311#endif 311#endif
312#ifdef CONFIG_PMAC_PBOOK
313 pmu_device_init();
314#endif
315 if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) { 312 if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) {
316 printk("unable to get major %d for misc devices\n", 313 printk("unable to get major %d for misc devices\n",
317 MISC_MAJOR); 314 MISC_MAJOR);
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 7c24fbe831f8..95f7046ff059 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -451,7 +451,7 @@ static int __init moxa_init(void)
451 int n = (sizeof(moxa_pcibrds) / sizeof(moxa_pcibrds[0])) - 1; 451 int n = (sizeof(moxa_pcibrds) / sizeof(moxa_pcibrds[0])) - 1;
452 i = 0; 452 i = 0;
453 while (i < n) { 453 while (i < n) {
454 while ((p = pci_find_device(moxa_pcibrds[i].vendor, moxa_pcibrds[i].device, p))!=NULL) 454 while ((p = pci_get_device(moxa_pcibrds[i].vendor, moxa_pcibrds[i].device, p))!=NULL)
455 { 455 {
456 if (pci_enable_device(p)) 456 if (pci_enable_device(p))
457 continue; 457 continue;
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 1c8d866a49dc..8f36b1758eb6 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -581,7 +581,7 @@ static dev_link_t *mgslpc_attach(void)
581 581
582 /* Interrupt setup */ 582 /* Interrupt setup */
583 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 583 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
584 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID; 584 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
585 link->irq.Handler = NULL; 585 link->irq.Handler = NULL;
586 586
587 link->conf.Attributes = 0; 587 link->conf.Attributes = 0;
@@ -3081,6 +3081,12 @@ void mgslpc_remove_device(MGSLPC_INFO *remove_info)
3081 } 3081 }
3082} 3082}
3083 3083
3084static struct pcmcia_device_id mgslpc_ids[] = {
3085 PCMCIA_DEVICE_MANF_CARD(0x02c5, 0x0050),
3086 PCMCIA_DEVICE_NULL
3087};
3088MODULE_DEVICE_TABLE(pcmcia, mgslpc_ids);
3089
3084static struct pcmcia_driver mgslpc_driver = { 3090static struct pcmcia_driver mgslpc_driver = {
3085 .owner = THIS_MODULE, 3091 .owner = THIS_MODULE,
3086 .drv = { 3092 .drv = {
@@ -3088,6 +3094,7 @@ static struct pcmcia_driver mgslpc_driver = {
3088 }, 3094 },
3089 .attach = mgslpc_attach, 3095 .attach = mgslpc_attach,
3090 .detach = mgslpc_detach, 3096 .detach = mgslpc_detach,
3097 .id_table = mgslpc_ids,
3091}; 3098};
3092 3099
3093static struct tty_operations mgslpc_ops = { 3100static struct tty_operations mgslpc_ops = {
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index 7db3370f4972..d7d484024e2b 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -1095,7 +1095,7 @@ static int __init rio_init(void)
1095 1095
1096#ifdef CONFIG_PCI 1096#ifdef CONFIG_PCI
1097 /* First look for the JET devices: */ 1097 /* First look for the JET devices: */
1098 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX, 1098 while ((pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
1099 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, 1099 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
1100 pdev))) { 1100 pdev))) {
1101 if (pci_enable_device(pdev)) continue; 1101 if (pci_enable_device(pdev)) continue;
@@ -1169,7 +1169,7 @@ static int __init rio_init(void)
1169 */ 1169 */
1170 1170
1171 /* Then look for the older RIO/PCI devices: */ 1171 /* Then look for the older RIO/PCI devices: */
1172 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX, 1172 while ((pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
1173 PCI_DEVICE_ID_SPECIALIX_RIO, 1173 PCI_DEVICE_ID_SPECIALIX_RIO,
1174 pdev))) { 1174 pdev))) {
1175 if (pci_enable_device(pdev)) continue; 1175 if (pci_enable_device(pdev)) continue;
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index ff4f09804865..d8f9e94ae475 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -78,6 +78,7 @@
78#include <linux/sysctl.h> 78#include <linux/sysctl.h>
79#include <linux/wait.h> 79#include <linux/wait.h>
80#include <linux/bcd.h> 80#include <linux/bcd.h>
81#include <linux/delay.h>
81 82
82#include <asm/current.h> 83#include <asm/current.h>
83#include <asm/uaccess.h> 84#include <asm/uaccess.h>
@@ -894,7 +895,6 @@ static int __init rtc_init(void)
894 struct proc_dir_entry *ent; 895 struct proc_dir_entry *ent;
895#if defined(__alpha__) || defined(__mips__) 896#if defined(__alpha__) || defined(__mips__)
896 unsigned int year, ctrl; 897 unsigned int year, ctrl;
897 unsigned long uip_watchdog;
898 char *guess = NULL; 898 char *guess = NULL;
899#endif 899#endif
900#ifdef __sparc__ 900#ifdef __sparc__
@@ -1000,12 +1000,8 @@ no_irq:
1000 /* Each operating system on an Alpha uses its own epoch. 1000 /* Each operating system on an Alpha uses its own epoch.
1001 Let's try to guess which one we are using now. */ 1001 Let's try to guess which one we are using now. */
1002 1002
1003 uip_watchdog = jiffies;
1004 if (rtc_is_updating() != 0) 1003 if (rtc_is_updating() != 0)
1005 while (jiffies - uip_watchdog < 2*HZ/100) { 1004 msleep(20);
1006 barrier();
1007 cpu_relax();
1008 }
1009 1005
1010 spin_lock_irq(&rtc_lock); 1006 spin_lock_irq(&rtc_lock);
1011 year = CMOS_READ(RTC_YEAR); 1007 year = CMOS_READ(RTC_YEAR);
@@ -1213,7 +1209,6 @@ static int rtc_proc_open(struct inode *inode, struct file *file)
1213 1209
1214void rtc_get_rtc_time(struct rtc_time *rtc_tm) 1210void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1215{ 1211{
1216 unsigned long uip_watchdog = jiffies;
1217 unsigned char ctrl; 1212 unsigned char ctrl;
1218#ifdef CONFIG_MACH_DECSTATION 1213#ifdef CONFIG_MACH_DECSTATION
1219 unsigned int real_year; 1214 unsigned int real_year;
@@ -1221,7 +1216,7 @@ void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1221 1216
1222 /* 1217 /*
1223 * read RTC once any update in progress is done. The update 1218 * read RTC once any update in progress is done. The update
1224 * can take just over 2ms. We wait 10 to 20ms. There is no need to 1219 * can take just over 2ms. We wait 20ms. There is no need to
1225 * to poll-wait (up to 1s - eeccch) for the falling edge of RTC_UIP. 1220 * to poll-wait (up to 1s - eeccch) for the falling edge of RTC_UIP.
1226 * If you need to know *exactly* when a second has started, enable 1221 * If you need to know *exactly* when a second has started, enable
1227 * periodic update complete interrupts, (via ioctl) and then 1222 * periodic update complete interrupts, (via ioctl) and then
@@ -1230,10 +1225,7 @@ void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1230 */ 1225 */
1231 1226
1232 if (rtc_is_updating() != 0) 1227 if (rtc_is_updating() != 0)
1233 while (jiffies - uip_watchdog < 2*HZ/100) { 1228 msleep(20);
1234 barrier();
1235 cpu_relax();
1236 }
1237 1229
1238 /* 1230 /*
1239 * Only the values that we read from the RTC are set. We leave 1231 * Only the values that we read from the RTC are set. We leave
diff --git a/drivers/char/tipar.c b/drivers/char/tipar.c
index 659335d80ee7..ec78d2f161f7 100644
--- a/drivers/char/tipar.c
+++ b/drivers/char/tipar.c
@@ -396,7 +396,7 @@ static struct file_operations tipar_fops = {
396static int __init 396static int __init
397tipar_setup(char *str) 397tipar_setup(char *str)
398{ 398{
399 int ints[2]; 399 int ints[3];
400 400
401 str = get_options(str, ARRAY_SIZE(ints), ints); 401 str = get_options(str, ARRAY_SIZE(ints), ints);
402 402
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index 58597993954f..f19cf9d7792d 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -476,11 +476,11 @@ int n_tty_ioctl(struct tty_struct * tty, struct file * file,
476 ld = tty_ldisc_ref(tty); 476 ld = tty_ldisc_ref(tty);
477 switch (arg) { 477 switch (arg) {
478 case TCIFLUSH: 478 case TCIFLUSH:
479 if (ld->flush_buffer) 479 if (ld && ld->flush_buffer)
480 ld->flush_buffer(tty); 480 ld->flush_buffer(tty);
481 break; 481 break;
482 case TCIOFLUSH: 482 case TCIOFLUSH:
483 if (ld->flush_buffer) 483 if (ld && ld->flush_buffer)
484 ld->flush_buffer(tty); 484 ld->flush_buffer(tty);
485 /* fall through */ 485 /* fall through */
486 case TCOFLUSH: 486 case TCOFLUSH:
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index 8971484b956b..1d44f69e1fda 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -25,6 +25,7 @@
25#include <linux/fs.h> 25#include <linux/fs.h>
26#include <linux/console.h> 26#include <linux/console.h>
27#include <linux/signal.h> 27#include <linux/signal.h>
28#include <linux/timex.h>
28 29
29#include <asm/io.h> 30#include <asm/io.h>
30#include <asm/uaccess.h> 31#include <asm/uaccess.h>
@@ -386,7 +387,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
386 if (!perm) 387 if (!perm)
387 return -EPERM; 388 return -EPERM;
388 if (arg) 389 if (arg)
389 arg = 1193182 / arg; 390 arg = CLOCK_TICK_RATE / arg;
390 kd_mksound(arg, 0); 391 kd_mksound(arg, 0);
391 return 0; 392 return 0;
392 393
@@ -403,7 +404,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
403 ticks = HZ * ((arg >> 16) & 0xffff) / 1000; 404 ticks = HZ * ((arg >> 16) & 0xffff) / 1000;
404 count = ticks ? (arg & 0xffff) : 0; 405 count = ticks ? (arg & 0xffff) : 0;
405 if (count) 406 if (count)
406 count = 1193182 / count; 407 count = CLOCK_TICK_RATE / count;
407 kd_mksound(count, ticks); 408 kd_mksound(count, ticks);
408 return 0; 409 return 0;
409 } 410 }
diff --git a/drivers/char/watchdog/ixp2000_wdt.c b/drivers/char/watchdog/ixp2000_wdt.c
index 4e98c215e5b1..4b039516cc86 100644
--- a/drivers/char/watchdog/ixp2000_wdt.c
+++ b/drivers/char/watchdog/ixp2000_wdt.c
@@ -162,7 +162,7 @@ ixp2000_wdt_release(struct inode *inode, struct file *file)
162 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status)) { 162 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status)) {
163 wdt_disable(); 163 wdt_disable();
164 } else { 164 } else {
165 printk(KERN_CRIT "WATCHDOG: Device closed unexpectdly - " 165 printk(KERN_CRIT "WATCHDOG: Device closed unexpectedly - "
166 "timer will not stop\n"); 166 "timer will not stop\n");
167 } 167 }
168 168
diff --git a/drivers/char/watchdog/ixp4xx_wdt.c b/drivers/char/watchdog/ixp4xx_wdt.c
index 82396e06c8a8..83df369113a4 100644
--- a/drivers/char/watchdog/ixp4xx_wdt.c
+++ b/drivers/char/watchdog/ixp4xx_wdt.c
@@ -156,7 +156,7 @@ ixp4xx_wdt_release(struct inode *inode, struct file *file)
156 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status)) { 156 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status)) {
157 wdt_disable(); 157 wdt_disable();
158 } else { 158 } else {
159 printk(KERN_CRIT "WATCHDOG: Device closed unexpectdly - " 159 printk(KERN_CRIT "WATCHDOG: Device closed unexpectedly - "
160 "timer will not stop\n"); 160 "timer will not stop\n");
161 } 161 }
162 162
diff --git a/drivers/firmware/pcdp.c b/drivers/firmware/pcdp.c
index 839b44a7e08b..53c95c0bbf46 100644
--- a/drivers/firmware/pcdp.c
+++ b/drivers/firmware/pcdp.c
@@ -16,6 +16,7 @@
16#include <linux/console.h> 16#include <linux/console.h>
17#include <linux/efi.h> 17#include <linux/efi.h>
18#include <linux/serial.h> 18#include <linux/serial.h>
19#include <asm/vga.h>
19#include "pcdp.h" 20#include "pcdp.h"
20 21
21static int __init 22static int __init
@@ -40,10 +41,27 @@ setup_serial_console(struct pcdp_uart *uart)
40} 41}
41 42
42static int __init 43static int __init
43setup_vga_console(struct pcdp_vga *vga) 44setup_vga_console(struct pcdp_device *dev)
44{ 45{
45#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE) 46#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
46 if (efi_mem_type(0xA0000) == EFI_CONVENTIONAL_MEMORY) { 47 u8 *if_ptr;
48
49 if_ptr = ((u8 *)dev + sizeof(struct pcdp_device));
50 if (if_ptr[0] == PCDP_IF_PCI) {
51 struct pcdp_if_pci if_pci;
52
53 /* struct copy since ifptr might not be correctly aligned */
54
55 memcpy(&if_pci, if_ptr, sizeof(if_pci));
56
57 if (if_pci.trans & PCDP_PCI_TRANS_IOPORT)
58 vga_console_iobase = if_pci.ioport_tra;
59
60 if (if_pci.trans & PCDP_PCI_TRANS_MMIO)
61 vga_console_membase = if_pci.mmio_tra;
62 }
63
64 if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) {
47 printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n"); 65 printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n");
48 return -ENODEV; 66 return -ENODEV;
49 } 67 }
@@ -95,7 +113,7 @@ efi_setup_pcdp_console(char *cmdline)
95 dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) { 113 dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) {
96 if (dev->flags & PCDP_PRIMARY_CONSOLE) { 114 if (dev->flags & PCDP_PRIMARY_CONSOLE) {
97 if (dev->type == PCDP_CONSOLE_VGA) { 115 if (dev->type == PCDP_CONSOLE_VGA) {
98 return setup_vga_console((struct pcdp_vga *) dev); 116 return setup_vga_console(dev);
99 } 117 }
100 } 118 }
101 } 119 }
diff --git a/drivers/firmware/pcdp.h b/drivers/firmware/pcdp.h
index 1dc7c88b7b4d..e72cc47de33b 100644
--- a/drivers/firmware/pcdp.h
+++ b/drivers/firmware/pcdp.h
@@ -52,11 +52,34 @@ struct pcdp_uart {
52 u32 clock_rate; 52 u32 clock_rate;
53 u8 pci_prog_intfc; 53 u8 pci_prog_intfc;
54 u8 flags; 54 u8 flags;
55}; 55} __attribute__((packed));
56
57#define PCDP_IF_PCI 1
58
59/* pcdp_if_pci.trans */
60#define PCDP_PCI_TRANS_IOPORT 0x02
61#define PCDP_PCI_TRANS_MMIO 0x01
62
63struct pcdp_if_pci {
64 u8 interconnect;
65 u8 reserved;
66 u16 length;
67 u8 segment;
68 u8 bus;
69 u8 dev;
70 u8 fun;
71 u16 dev_id;
72 u16 vendor_id;
73 u32 acpi_interrupt;
74 u64 mmio_tra;
75 u64 ioport_tra;
76 u8 flags;
77 u8 trans;
78} __attribute__((packed));
56 79
57struct pcdp_vga { 80struct pcdp_vga {
58 u8 count; /* address space descriptors */ 81 u8 count; /* address space descriptors */
59}; 82} __attribute__((packed));
60 83
61/* pcdp_device.flags */ 84/* pcdp_device.flags */
62#define PCDP_PRIMARY_CONSOLE 1 85#define PCDP_PRIMARY_CONSOLE 1
@@ -66,7 +89,9 @@ struct pcdp_device {
66 u8 flags; 89 u8 flags;
67 u16 length; 90 u16 length;
68 u16 efi_index; 91 u16 efi_index;
69}; 92 /* next data is pcdp_if_pci or pcdp_if_acpi (not yet supported) */
93 /* next data is device specific type (currently only pcdp_vga) */
94} __attribute__((packed));
70 95
71struct pcdp { 96struct pcdp {
72 u8 signature[4]; 97 u8 signature[4];
@@ -81,4 +106,4 @@ struct pcdp {
81 u32 num_uarts; 106 u32 num_uarts;
82 struct pcdp_uart uart[0]; /* actual size is num_uarts */ 107 struct pcdp_uart uart[0]; /* actual size is num_uarts */
83 /* remainder of table is pcdp_device structures */ 108 /* remainder of table is pcdp_device structures */
84}; 109} __attribute__((packed));
diff --git a/drivers/i2c/chips/atxp1.c b/drivers/i2c/chips/atxp1.c
index 5c6597aa2c7f..0bcf82b4c07b 100644
--- a/drivers/i2c/chips/atxp1.c
+++ b/drivers/i2c/chips/atxp1.c
@@ -144,7 +144,7 @@ static ssize_t atxp1_storevcore(struct device *dev, struct device_attribute *att
144 if (vid == cvid) 144 if (vid == cvid)
145 return count; 145 return count;
146 146
147 dev_info(dev, "Setting VCore to %d mV (0x%02x)\n", vcore, vid); 147 dev_dbg(dev, "Setting VCore to %d mV (0x%02x)\n", vcore, vid);
148 148
149 /* Write every 25 mV step to increase stability */ 149 /* Write every 25 mV step to increase stability */
150 if (cvid > vid) { 150 if (cvid > vid) {
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 0273f124a4f7..5f33df47aa74 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -606,6 +606,12 @@ config BLK_DEV_IT8172
606 <http://www.ite.com.tw/ia/brief_it8172bsp.htm>; picture of the 606 <http://www.ite.com.tw/ia/brief_it8172bsp.htm>; picture of the
607 board at <http://www.mvista.com/partners/semiconductor/ite.html>. 607 board at <http://www.mvista.com/partners/semiconductor/ite.html>.
608 608
609config BLK_DEV_IT821X
610 tristate "IT821X IDE support"
611 help
612 This driver adds support for the ITE 8211 IDE controller and the
613 IT 8212 IDE RAID controller in both RAID and pass-through mode.
614
609config BLK_DEV_NS87415 615config BLK_DEV_NS87415
610 tristate "NS87415 chipset support" 616 tristate "NS87415 chipset support"
611 help 617 help
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index d6f934886b04..f9c1acb4ed6a 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -119,6 +119,10 @@ static int lba_capacity_is_ok (struct hd_driveid *id)
119{ 119{
120 unsigned long lba_sects, chs_sects, head, tail; 120 unsigned long lba_sects, chs_sects, head, tail;
121 121
122 /* No non-LBA info .. so valid! */
123 if (id->cyls == 0)
124 return 1;
125
122 /* 126 /*
123 * The ATA spec tells large drives to return 127 * The ATA spec tells large drives to return
124 * C/H/S = 16383/16/63 independent of their size. 128 * C/H/S = 16383/16/63 independent of their size.
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 2d2eefb610dd..1e1531334c25 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -132,7 +132,6 @@ static const struct drive_list_entry drive_blacklist [] = {
132 { "SAMSUNG CD-ROM SC-148C", "ALL" }, 132 { "SAMSUNG CD-ROM SC-148C", "ALL" },
133 { "SAMSUNG CD-ROM SC", "ALL" }, 133 { "SAMSUNG CD-ROM SC", "ALL" },
134 { "SanDisk SDP3B-64" , "ALL" }, 134 { "SanDisk SDP3B-64" , "ALL" },
135 { "SAMSUNG CD-ROM SN-124", "ALL" },
136 { "ATAPI CD-ROM DRIVE 40X MAXIMUM", "ALL" }, 135 { "ATAPI CD-ROM DRIVE 40X MAXIMUM", "ALL" },
137 { "_NEC DV5800A", "ALL" }, 136 { "_NEC DV5800A", "ALL" },
138 { NULL , NULL } 137 { NULL , NULL }
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 53024942a7eb..b443b04a4c5a 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -1181,7 +1181,8 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1181 pre_reset(drive); 1181 pre_reset(drive);
1182 SELECT_DRIVE(drive); 1182 SELECT_DRIVE(drive);
1183 udelay (20); 1183 udelay (20);
1184 hwif->OUTB(WIN_SRST, IDE_COMMAND_REG); 1184 hwif->OUTBSYNC(drive, WIN_SRST, IDE_COMMAND_REG);
1185 ndelay(400);
1185 hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE; 1186 hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE;
1186 hwgroup->polling = 1; 1187 hwgroup->polling = 1;
1187 __ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL); 1188 __ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL);
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index e20327e54b1a..978d27d6452d 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -457,6 +457,40 @@ int ide_event(event_t event, int priority,
457 return 0; 457 return 0;
458} /* ide_event */ 458} /* ide_event */
459 459
460static struct pcmcia_device_id ide_ids[] = {
461 PCMCIA_DEVICE_FUNC_ID(4),
462 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
463 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
464 PCMCIA_DEVICE_MANF_CARD(0x2080, 0x0001),
465 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401),
466 PCMCIA_DEVICE_PROD_ID123("Caravelle", "PSC-IDE ", "PSC000", 0x8c36137c, 0xd0693ab8, 0x2768a9f0),
467 PCMCIA_DEVICE_PROD_ID123("CDROM", "IDE", "MCD-601p", 0x1b9179ca, 0xede88951, 0x0d902f74),
468 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "IDE CARD", "F1", 0x281f1c5d, 0x1907960c, 0xf7fde8b9),
469 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "CD-ROM", 0x78f308dc, 0x66536591),
470 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "PnPIDE", 0x78f308dc, 0x0c694728),
471 PCMCIA_DEVICE_PROD_ID12("CNF CD-M", "CD-ROM", 0x7d93b852, 0x66536591),
472 PCMCIA_DEVICE_PROD_ID12("Creative Technology Ltd.", "PCMCIA CD-ROM Interface Card", 0xff8c8a45, 0xfe8020c4),
473 PCMCIA_DEVICE_PROD_ID12("Digital Equipment Corporation.", "Digital Mobile Media CD-ROM", 0x17692a66, 0xef1dcbde),
474 PCMCIA_DEVICE_PROD_ID12("EXP", "CD", 0x6f58c983, 0xaae5994f),
475 PCMCIA_DEVICE_PROD_ID12("EXP ", "CD-ROM", 0x0a5c52fd, 0x66536591),
476 PCMCIA_DEVICE_PROD_ID12("EXP ", "PnPIDE", 0x0a5c52fd, 0x0c694728),
477 PCMCIA_DEVICE_PROD_ID12("FREECOM", "PCCARD-IDE", 0x5714cbf7, 0x48e0ab8e),
478 PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753),
479 PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2 ", 0x547e66dc, 0x8671043b),
480 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149),
481 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674),
482 PCMCIA_DEVICE_PROD_ID12("LOOKMEET", "CBIDE2 ", 0xe37be2b5, 0x8671043b),
483 PCMCIA_DEVICE_PROD_ID12(" ", "NinjaATA-", 0x3b6e20c8, 0xebe0bd79),
484 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "CD-ROM", 0x281f1c5d, 0x66536591),
485 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "PnPIDE", 0x281f1c5d, 0x0c694728),
486 PCMCIA_DEVICE_PROD_ID12("SHUTTLE TECHNOLOGY LTD.", "PCCARD-IDE/ATAPI Adapter", 0x4a3f0ba0, 0x322560e1),
487 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "MK2001MPL", 0xb4585a1a, 0x3489e003),
488 PCMCIA_DEVICE_PROD_ID12("WIT", "IDE16", 0x244e5994, 0x3e232852),
489 PCMCIA_DEVICE_PROD_ID1("STI Flash", 0xe4a13209),
490 PCMCIA_DEVICE_NULL,
491};
492MODULE_DEVICE_TABLE(pcmcia, ide_ids);
493
460static struct pcmcia_driver ide_cs_driver = { 494static struct pcmcia_driver ide_cs_driver = {
461 .owner = THIS_MODULE, 495 .owner = THIS_MODULE,
462 .drv = { 496 .drv = {
@@ -464,6 +498,7 @@ static struct pcmcia_driver ide_cs_driver = {
464 }, 498 },
465 .attach = ide_attach, 499 .attach = ide_attach,
466 .detach = ide_detach, 500 .detach = ide_detach,
501 .id_table = ide_ids,
467}; 502};
468 503
469static int __init init_ide_cs(void) 504static int __init init_ide_cs(void)
diff --git a/drivers/ide/pci/Makefile b/drivers/ide/pci/Makefile
index 55e6e553e497..af46226c1796 100644
--- a/drivers/ide/pci/Makefile
+++ b/drivers/ide/pci/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_BLK_DEV_HPT34X) += hpt34x.o
12obj-$(CONFIG_BLK_DEV_HPT366) += hpt366.o 12obj-$(CONFIG_BLK_DEV_HPT366) += hpt366.o
13#obj-$(CONFIG_BLK_DEV_HPT37X) += hpt37x.o 13#obj-$(CONFIG_BLK_DEV_HPT37X) += hpt37x.o
14obj-$(CONFIG_BLK_DEV_IT8172) += it8172.o 14obj-$(CONFIG_BLK_DEV_IT8172) += it8172.o
15obj-$(CONFIG_BLK_DEV_IT821X) += it821x.o
15obj-$(CONFIG_BLK_DEV_NS87415) += ns87415.o 16obj-$(CONFIG_BLK_DEV_NS87415) += ns87415.o
16obj-$(CONFIG_BLK_DEV_OPTI621) += opti621.o 17obj-$(CONFIG_BLK_DEV_OPTI621) += opti621.o
17obj-$(CONFIG_BLK_DEV_PDC202XX_OLD) += pdc202xx_old.o 18obj-$(CONFIG_BLK_DEV_PDC202XX_OLD) += pdc202xx_old.o
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index 4565cc311ff3..da46577380f3 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -39,6 +39,17 @@
39 39
40#include <asm/io.h> 40#include <asm/io.h>
41 41
42static int ide_generic_all; /* Set to claim all devices */
43
44static int __init ide_generic_all_on(char *unused)
45{
46 ide_generic_all = 1;
47 printk(KERN_INFO "IDE generic will claim all unknown PCI IDE storage controllers.\n");
48 return 1;
49}
50
51__setup("all-generic-ide", ide_generic_all_on);
52
42static void __devinit init_hwif_generic (ide_hwif_t *hwif) 53static void __devinit init_hwif_generic (ide_hwif_t *hwif)
43{ 54{
44 switch(hwif->pci_dev->device) { 55 switch(hwif->pci_dev->device) {
@@ -78,79 +89,85 @@ static void __devinit init_hwif_generic (ide_hwif_t *hwif)
78 89
79static ide_pci_device_t generic_chipsets[] __devinitdata = { 90static ide_pci_device_t generic_chipsets[] __devinitdata = {
80 { /* 0 */ 91 { /* 0 */
92 .name = "Unknown",
93 .init_hwif = init_hwif_generic,
94 .channels = 2,
95 .autodma = AUTODMA,
96 .bootable = ON_BOARD,
97 },{ /* 1 */
81 .name = "NS87410", 98 .name = "NS87410",
82 .init_hwif = init_hwif_generic, 99 .init_hwif = init_hwif_generic,
83 .channels = 2, 100 .channels = 2,
84 .autodma = AUTODMA, 101 .autodma = AUTODMA,
85 .enablebits = {{0x43,0x08,0x08}, {0x47,0x08,0x08}}, 102 .enablebits = {{0x43,0x08,0x08}, {0x47,0x08,0x08}},
86 .bootable = ON_BOARD, 103 .bootable = ON_BOARD,
87 },{ /* 1 */ 104 },{ /* 2 */
88 .name = "SAMURAI", 105 .name = "SAMURAI",
89 .init_hwif = init_hwif_generic, 106 .init_hwif = init_hwif_generic,
90 .channels = 2, 107 .channels = 2,
91 .autodma = AUTODMA, 108 .autodma = AUTODMA,
92 .bootable = ON_BOARD, 109 .bootable = ON_BOARD,
93 },{ /* 2 */ 110 },{ /* 3 */
94 .name = "HT6565", 111 .name = "HT6565",
95 .init_hwif = init_hwif_generic, 112 .init_hwif = init_hwif_generic,
96 .channels = 2, 113 .channels = 2,
97 .autodma = AUTODMA, 114 .autodma = AUTODMA,
98 .bootable = ON_BOARD, 115 .bootable = ON_BOARD,
99 },{ /* 3 */ 116 },{ /* 4 */
100 .name = "UM8673F", 117 .name = "UM8673F",
101 .init_hwif = init_hwif_generic, 118 .init_hwif = init_hwif_generic,
102 .channels = 2, 119 .channels = 2,
103 .autodma = NODMA, 120 .autodma = NODMA,
104 .bootable = ON_BOARD, 121 .bootable = ON_BOARD,
105 },{ /* 4 */ 122 },{ /* 5 */
106 .name = "UM8886A", 123 .name = "UM8886A",
107 .init_hwif = init_hwif_generic, 124 .init_hwif = init_hwif_generic,
108 .channels = 2, 125 .channels = 2,
109 .autodma = NODMA, 126 .autodma = NODMA,
110 .bootable = ON_BOARD, 127 .bootable = ON_BOARD,
111 },{ /* 5 */ 128 },{ /* 6 */
112 .name = "UM8886BF", 129 .name = "UM8886BF",
113 .init_hwif = init_hwif_generic, 130 .init_hwif = init_hwif_generic,
114 .channels = 2, 131 .channels = 2,
115 .autodma = NODMA, 132 .autodma = NODMA,
116 .bootable = ON_BOARD, 133 .bootable = ON_BOARD,
117 },{ /* 6 */ 134 },{ /* 7 */
118 .name = "HINT_IDE", 135 .name = "HINT_IDE",
119 .init_hwif = init_hwif_generic, 136 .init_hwif = init_hwif_generic,
120 .channels = 2, 137 .channels = 2,
121 .autodma = AUTODMA, 138 .autodma = AUTODMA,
122 .bootable = ON_BOARD, 139 .bootable = ON_BOARD,
123 },{ /* 7 */ 140 },{ /* 8 */
124 .name = "VIA_IDE", 141 .name = "VIA_IDE",
125 .init_hwif = init_hwif_generic, 142 .init_hwif = init_hwif_generic,
126 .channels = 2, 143 .channels = 2,
127 .autodma = NOAUTODMA, 144 .autodma = NOAUTODMA,
128 .bootable = ON_BOARD, 145 .bootable = ON_BOARD,
129 },{ /* 8 */ 146 },{ /* 9 */
130 .name = "OPTI621V", 147 .name = "OPTI621V",
131 .init_hwif = init_hwif_generic, 148 .init_hwif = init_hwif_generic,
132 .channels = 2, 149 .channels = 2,
133 .autodma = NOAUTODMA, 150 .autodma = NOAUTODMA,
134 .bootable = ON_BOARD, 151 .bootable = ON_BOARD,
135 },{ /* 9 */ 152 },{ /* 10 */
136 .name = "VIA8237SATA", 153 .name = "VIA8237SATA",
137 .init_hwif = init_hwif_generic, 154 .init_hwif = init_hwif_generic,
138 .channels = 2, 155 .channels = 2,
139 .autodma = AUTODMA, 156 .autodma = AUTODMA,
140 .bootable = OFF_BOARD, 157 .bootable = OFF_BOARD,
141 },{ /* 10 */ 158 },{ /* 11 */
142 .name = "Piccolo0102", 159 .name = "Piccolo0102",
143 .init_hwif = init_hwif_generic, 160 .init_hwif = init_hwif_generic,
144 .channels = 2, 161 .channels = 2,
145 .autodma = NOAUTODMA, 162 .autodma = NOAUTODMA,
146 .bootable = ON_BOARD, 163 .bootable = ON_BOARD,
147 },{ /* 11 */ 164 },{ /* 12 */
148 .name = "Piccolo0103", 165 .name = "Piccolo0103",
149 .init_hwif = init_hwif_generic, 166 .init_hwif = init_hwif_generic,
150 .channels = 2, 167 .channels = 2,
151 .autodma = NOAUTODMA, 168 .autodma = NOAUTODMA,
152 .bootable = ON_BOARD, 169 .bootable = ON_BOARD,
153 },{ /* 12 */ 170 },{ /* 13 */
154 .name = "Piccolo0105", 171 .name = "Piccolo0105",
155 .init_hwif = init_hwif_generic, 172 .init_hwif = init_hwif_generic,
156 .channels = 2, 173 .channels = 2,
@@ -174,6 +191,10 @@ static int __devinit generic_init_one(struct pci_dev *dev, const struct pci_devi
174 u16 command; 191 u16 command;
175 int ret = -ENODEV; 192 int ret = -ENODEV;
176 193
194 /* Don't use the generic entry unless instructed to do so */
195 if (id->driver_data == 0 && ide_generic_all == 0)
196 goto out;
197
177 if (dev->vendor == PCI_VENDOR_ID_UMC && 198 if (dev->vendor == PCI_VENDOR_ID_UMC &&
178 dev->device == PCI_DEVICE_ID_UMC_UM8886A && 199 dev->device == PCI_DEVICE_ID_UMC_UM8886A &&
179 (!(PCI_FUNC(dev->devfn) & 1))) 200 (!(PCI_FUNC(dev->devfn) & 1)))
@@ -195,21 +216,23 @@ out:
195} 216}
196 217
197static struct pci_device_id generic_pci_tbl[] = { 218static struct pci_device_id generic_pci_tbl[] = {
198 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 219 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
199 { PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, 220 { PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
200 { PCI_VENDOR_ID_HOLTEK, PCI_DEVICE_ID_HOLTEK_6565, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2}, 221 { PCI_VENDOR_ID_HOLTEK, PCI_DEVICE_ID_HOLTEK_6565, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
201 { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8673F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3}, 222 { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8673F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
202 { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4}, 223 { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
203 { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886BF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5}, 224 { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886BF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6},
204 { PCI_VENDOR_ID_HINT, PCI_DEVICE_ID_HINT_VXPROII_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6}, 225 { PCI_VENDOR_ID_HINT, PCI_DEVICE_ID_HINT_VXPROII_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7},
205 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C561, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7}, 226 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C561, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8},
206 { PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C558, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8}, 227 { PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C558, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9},
207#ifdef CONFIG_BLK_DEV_IDE_SATA 228#ifdef CONFIG_BLK_DEV_IDE_SATA
208 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237_SATA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9}, 229 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237_SATA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10},
209#endif 230#endif
210 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10}, 231 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11},
211 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11}, 232 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12},
212 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12}, 233 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13},
234 /* Must come last. If you add entries adjust this table appropriately and the init_one code */
235 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 0},
213 { 0, }, 236 { 0, },
214}; 237};
215MODULE_DEVICE_TABLE(pci, generic_pci_tbl); 238MODULE_DEVICE_TABLE(pci, generic_pci_tbl);
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index c8ee0b8c0292..7b64db10d1b0 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -10,6 +10,11 @@
10 * donation of an ABit BP6 mainboard, processor, and memory acellerated 10 * donation of an ABit BP6 mainboard, processor, and memory acellerated
11 * development and support. 11 * development and support.
12 * 12 *
13 *
14 * Highpoint have their own driver (source except for the raid part)
15 * available from http://www.highpoint-tech.com/hpt3xx-opensource-v131.tgz
16 * This may be useful to anyone wanting to work on the mainstream hpt IDE.
17 *
13 * Note that final HPT370 support was done by force extraction of GPL. 18 * Note that final HPT370 support was done by force extraction of GPL.
14 * 19 *
15 * - add function for getting/setting power status of drive 20 * - add function for getting/setting power status of drive
@@ -446,44 +451,29 @@ static struct chipset_bus_clock_list_entry sixty_six_base_hpt374[] = {
446#define F_LOW_PCI_50 0x2d 451#define F_LOW_PCI_50 0x2d
447#define F_LOW_PCI_66 0x42 452#define F_LOW_PCI_66 0x42
448 453
449/* FIXME: compare with driver's code before removing */ 454/*
450#if 0 455 * Hold all the highpoint quirks and revision information in one
451 if (hpt_minimum_revision(dev, 3)) { 456 * place.
452 u8 cbl; 457 */
453 cbl = inb(iobase + 0x7b);
454 outb(cbl | 1, iobase + 0x7b);
455 outb(cbl & ~1, iobase + 0x7b);
456 cbl = inb(iobase + 0x7a);
457 p += sprintf(p, "Cable: ATA-%d"
458 " ATA-%d\n",
459 (cbl & 0x02) ? 33 : 66,
460 (cbl & 0x01) ? 33 : 66);
461 p += sprintf(p, "\n");
462 }
463 {
464 u8 c2, c3;
465 /* older revs don't have these registers mapped
466 * into io space */
467 pci_read_config_byte(dev, 0x43, &c0);
468 pci_read_config_byte(dev, 0x47, &c1);
469 pci_read_config_byte(dev, 0x4b, &c2);
470 pci_read_config_byte(dev, 0x4f, &c3);
471
472 p += sprintf(p, "Mode: %s %s"
473 " %s %s\n",
474 (c0 & 0x10) ? "UDMA" : (c0 & 0x20) ? "DMA " :
475 (c0 & 0x80) ? "PIO " : "off ",
476 (c1 & 0x10) ? "UDMA" : (c1 & 0x20) ? "DMA " :
477 (c1 & 0x80) ? "PIO " : "off ",
478 (c2 & 0x10) ? "UDMA" : (c2 & 0x20) ? "DMA " :
479 (c2 & 0x80) ? "PIO " : "off ",
480 (c3 & 0x10) ? "UDMA" : (c3 & 0x20) ? "DMA " :
481 (c3 & 0x80) ? "PIO " : "off ");
482 }
483 }
484#endif
485 458
486static u32 hpt_revision (struct pci_dev *dev) 459struct hpt_info
460{
461 u8 max_mode; /* Speeds allowed */
462 int revision; /* Chipset revision */
463 int flags; /* Chipset properties */
464#define PLL_MODE 1
465#define IS_372N 2
466 /* Speed table */
467 struct chipset_bus_clock_list_entry *speed;
468};
469
470/*
471 * This wants fixing so that we do everything not by classrev
472 * (which breaks on the newest chips) but by creating an
473 * enumeration of chip variants and using that
474 */
475
476static __devinit u32 hpt_revision (struct pci_dev *dev)
487{ 477{
488 u32 class_rev; 478 u32 class_rev;
489 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev); 479 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
@@ -507,37 +497,33 @@ static u32 hpt_revision (struct pci_dev *dev)
507 return class_rev; 497 return class_rev;
508} 498}
509 499
510static u32 hpt_minimum_revision (struct pci_dev *dev, int revision)
511{
512 unsigned int class_rev = hpt_revision(dev);
513 revision--;
514 return ((int) (class_rev > revision) ? 1 : 0);
515}
516
517static int check_in_drive_lists(ide_drive_t *drive, const char **list); 500static int check_in_drive_lists(ide_drive_t *drive, const char **list);
518 501
519static u8 hpt3xx_ratemask (ide_drive_t *drive) 502static u8 hpt3xx_ratemask (ide_drive_t *drive)
520{ 503{
521 struct pci_dev *dev = HWIF(drive)->pci_dev; 504 ide_hwif_t *hwif = drive->hwif;
505 struct hpt_info *info = ide_get_hwifdata(hwif);
522 u8 mode = 0; 506 u8 mode = 0;
523 507
524 if (hpt_minimum_revision(dev, 8)) { /* HPT374 */ 508 /* FIXME: TODO - move this to set info->mode once at boot */
509
510 if (info->revision >= 8) { /* HPT374 */
525 mode = (HPT374_ALLOW_ATA133_6) ? 4 : 3; 511 mode = (HPT374_ALLOW_ATA133_6) ? 4 : 3;
526 } else if (hpt_minimum_revision(dev, 7)) { /* HPT371 */ 512 } else if (info->revision >= 7) { /* HPT371 */
527 mode = (HPT371_ALLOW_ATA133_6) ? 4 : 3; 513 mode = (HPT371_ALLOW_ATA133_6) ? 4 : 3;
528 } else if (hpt_minimum_revision(dev, 6)) { /* HPT302 */ 514 } else if (info->revision >= 6) { /* HPT302 */
529 mode = (HPT302_ALLOW_ATA133_6) ? 4 : 3; 515 mode = (HPT302_ALLOW_ATA133_6) ? 4 : 3;
530 } else if (hpt_minimum_revision(dev, 5)) { /* HPT372 */ 516 } else if (info->revision >= 5) { /* HPT372 */
531 mode = (HPT372_ALLOW_ATA133_6) ? 4 : 3; 517 mode = (HPT372_ALLOW_ATA133_6) ? 4 : 3;
532 } else if (hpt_minimum_revision(dev, 4)) { /* HPT370A */ 518 } else if (info->revision >= 4) { /* HPT370A */
533 mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2; 519 mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2;
534 } else if (hpt_minimum_revision(dev, 3)) { /* HPT370 */ 520 } else if (info->revision >= 3) { /* HPT370 */
535 mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2; 521 mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2;
536 mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : mode; 522 mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : mode;
537 } else { /* HPT366 and HPT368 */ 523 } else { /* HPT366 and HPT368 */
538 mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : 2; 524 mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : 2;
539 } 525 }
540 if (!eighty_ninty_three(drive) && (mode)) 526 if (!eighty_ninty_three(drive) && mode)
541 mode = min(mode, (u8)1); 527 mode = min(mode, (u8)1);
542 return mode; 528 return mode;
543} 529}
@@ -549,7 +535,8 @@ static u8 hpt3xx_ratemask (ide_drive_t *drive)
549 535
550static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed) 536static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed)
551{ 537{
552 struct pci_dev *dev = HWIF(drive)->pci_dev; 538 ide_hwif_t *hwif = drive->hwif;
539 struct hpt_info *info = ide_get_hwifdata(hwif);
553 u8 mode = hpt3xx_ratemask(drive); 540 u8 mode = hpt3xx_ratemask(drive);
554 541
555 if (drive->media != ide_disk) 542 if (drive->media != ide_disk)
@@ -561,7 +548,7 @@ static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed)
561 break; 548 break;
562 case 0x03: 549 case 0x03:
563 speed = min(speed, (u8)XFER_UDMA_5); 550 speed = min(speed, (u8)XFER_UDMA_5);
564 if (hpt_minimum_revision(dev, 5)) 551 if (info->revision >= 5)
565 break; 552 break;
566 if (check_in_drive_lists(drive, bad_ata100_5)) 553 if (check_in_drive_lists(drive, bad_ata100_5))
567 speed = min(speed, (u8)XFER_UDMA_4); 554 speed = min(speed, (u8)XFER_UDMA_4);
@@ -571,7 +558,7 @@ static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed)
571 /* 558 /*
572 * CHECK ME, Does this need to be set to 5 ?? 559 * CHECK ME, Does this need to be set to 5 ??
573 */ 560 */
574 if (hpt_minimum_revision(dev, 3)) 561 if (info->revision >= 3)
575 break; 562 break;
576 if ((check_in_drive_lists(drive, bad_ata66_4)) || 563 if ((check_in_drive_lists(drive, bad_ata66_4)) ||
577 (!(HPT366_ALLOW_ATA66_4))) 564 (!(HPT366_ALLOW_ATA66_4)))
@@ -585,7 +572,7 @@ static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed)
585 /* 572 /*
586 * CHECK ME, Does this need to be set to 5 ?? 573 * CHECK ME, Does this need to be set to 5 ??
587 */ 574 */
588 if (hpt_minimum_revision(dev, 3)) 575 if (info->revision >= 3)
589 break; 576 break;
590 if (check_in_drive_lists(drive, bad_ata33)) 577 if (check_in_drive_lists(drive, bad_ata33))
591 speed = min(speed, (u8)XFER_MW_DMA_2); 578 speed = min(speed, (u8)XFER_MW_DMA_2);
@@ -624,11 +611,12 @@ static unsigned int pci_bus_clock_list (u8 speed, struct chipset_bus_clock_list_
624 611
625static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed) 612static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
626{ 613{
627 struct pci_dev *dev = HWIF(drive)->pci_dev; 614 ide_hwif_t *hwif = drive->hwif;
615 struct pci_dev *dev = hwif->pci_dev;
616 struct hpt_info *info = ide_get_hwifdata(hwif);
628 u8 speed = hpt3xx_ratefilter(drive, xferspeed); 617 u8 speed = hpt3xx_ratefilter(drive, xferspeed);
629// u8 speed = ide_rate_filter(hpt3xx_ratemask(drive), xferspeed);
630 u8 regtime = (drive->select.b.unit & 0x01) ? 0x44 : 0x40; 618 u8 regtime = (drive->select.b.unit & 0x01) ? 0x44 : 0x40;
631 u8 regfast = (HWIF(drive)->channel) ? 0x55 : 0x51; 619 u8 regfast = (hwif->channel) ? 0x55 : 0x51;
632 u8 drive_fast = 0; 620 u8 drive_fast = 0;
633 u32 reg1 = 0, reg2 = 0; 621 u32 reg1 = 0, reg2 = 0;
634 622
@@ -636,16 +624,11 @@ static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
636 * Disable the "fast interrupt" prediction. 624 * Disable the "fast interrupt" prediction.
637 */ 625 */
638 pci_read_config_byte(dev, regfast, &drive_fast); 626 pci_read_config_byte(dev, regfast, &drive_fast);
639#if 0
640 if (drive_fast & 0x02)
641 pci_write_config_byte(dev, regfast, drive_fast & ~0x20);
642#else
643 if (drive_fast & 0x80) 627 if (drive_fast & 0x80)
644 pci_write_config_byte(dev, regfast, drive_fast & ~0x80); 628 pci_write_config_byte(dev, regfast, drive_fast & ~0x80);
645#endif
646 629
647 reg2 = pci_bus_clock_list(speed, 630 reg2 = pci_bus_clock_list(speed, info->speed);
648 (struct chipset_bus_clock_list_entry *) pci_get_drvdata(dev)); 631
649 /* 632 /*
650 * Disable on-chip PIO FIFO/buffer 633 * Disable on-chip PIO FIFO/buffer
651 * (to avoid problems handling I/O errors later) 634 * (to avoid problems handling I/O errors later)
@@ -665,10 +648,11 @@ static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
665 648
666static int hpt370_tune_chipset(ide_drive_t *drive, u8 xferspeed) 649static int hpt370_tune_chipset(ide_drive_t *drive, u8 xferspeed)
667{ 650{
668 struct pci_dev *dev = HWIF(drive)->pci_dev; 651 ide_hwif_t *hwif = drive->hwif;
652 struct pci_dev *dev = hwif->pci_dev;
653 struct hpt_info *info = ide_get_hwifdata(hwif);
669 u8 speed = hpt3xx_ratefilter(drive, xferspeed); 654 u8 speed = hpt3xx_ratefilter(drive, xferspeed);
670// u8 speed = ide_rate_filter(hpt3xx_ratemask(drive), xferspeed); 655 u8 regfast = (drive->hwif->channel) ? 0x55 : 0x51;
671 u8 regfast = (HWIF(drive)->channel) ? 0x55 : 0x51;
672 u8 drive_pci = 0x40 + (drive->dn * 4); 656 u8 drive_pci = 0x40 + (drive->dn * 4);
673 u8 new_fast = 0, drive_fast = 0; 657 u8 new_fast = 0, drive_fast = 0;
674 u32 list_conf = 0, drive_conf = 0; 658 u32 list_conf = 0, drive_conf = 0;
@@ -693,17 +677,13 @@ static int hpt370_tune_chipset(ide_drive_t *drive, u8 xferspeed)
693 if (new_fast != drive_fast) 677 if (new_fast != drive_fast)
694 pci_write_config_byte(dev, regfast, new_fast); 678 pci_write_config_byte(dev, regfast, new_fast);
695 679
696 list_conf = pci_bus_clock_list(speed, 680 list_conf = pci_bus_clock_list(speed, info->speed);
697 (struct chipset_bus_clock_list_entry *)
698 pci_get_drvdata(dev));
699 681
700 pci_read_config_dword(dev, drive_pci, &drive_conf); 682 pci_read_config_dword(dev, drive_pci, &drive_conf);
701 list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask); 683 list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask);
702 684
703 if (speed < XFER_MW_DMA_0) { 685 if (speed < XFER_MW_DMA_0)
704 list_conf &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */ 686 list_conf &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */
705 }
706
707 pci_write_config_dword(dev, drive_pci, list_conf); 687 pci_write_config_dword(dev, drive_pci, list_conf);
708 688
709 return ide_config_drive_speed(drive, speed); 689 return ide_config_drive_speed(drive, speed);
@@ -711,10 +691,11 @@ static int hpt370_tune_chipset(ide_drive_t *drive, u8 xferspeed)
711 691
712static int hpt372_tune_chipset(ide_drive_t *drive, u8 xferspeed) 692static int hpt372_tune_chipset(ide_drive_t *drive, u8 xferspeed)
713{ 693{
714 struct pci_dev *dev = HWIF(drive)->pci_dev; 694 ide_hwif_t *hwif = drive->hwif;
695 struct pci_dev *dev = hwif->pci_dev;
696 struct hpt_info *info = ide_get_hwifdata(hwif);
715 u8 speed = hpt3xx_ratefilter(drive, xferspeed); 697 u8 speed = hpt3xx_ratefilter(drive, xferspeed);
716// u8 speed = ide_rate_filter(hpt3xx_ratemask(drive), xferspeed); 698 u8 regfast = (drive->hwif->channel) ? 0x55 : 0x51;
717 u8 regfast = (HWIF(drive)->channel) ? 0x55 : 0x51;
718 u8 drive_fast = 0, drive_pci = 0x40 + (drive->dn * 4); 699 u8 drive_fast = 0, drive_pci = 0x40 + (drive->dn * 4);
719 u32 list_conf = 0, drive_conf = 0; 700 u32 list_conf = 0, drive_conf = 0;
720 u32 conf_mask = (speed >= XFER_MW_DMA_0) ? 0xc0000000 : 0x30070000; 701 u32 conf_mask = (speed >= XFER_MW_DMA_0) ? 0xc0000000 : 0x30070000;
@@ -726,10 +707,8 @@ static int hpt372_tune_chipset(ide_drive_t *drive, u8 xferspeed)
726 pci_read_config_byte(dev, regfast, &drive_fast); 707 pci_read_config_byte(dev, regfast, &drive_fast);
727 drive_fast &= ~0x07; 708 drive_fast &= ~0x07;
728 pci_write_config_byte(dev, regfast, drive_fast); 709 pci_write_config_byte(dev, regfast, drive_fast);
729 710
730 list_conf = pci_bus_clock_list(speed, 711 list_conf = pci_bus_clock_list(speed, info->speed);
731 (struct chipset_bus_clock_list_entry *)
732 pci_get_drvdata(dev));
733 pci_read_config_dword(dev, drive_pci, &drive_conf); 712 pci_read_config_dword(dev, drive_pci, &drive_conf);
734 list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask); 713 list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask);
735 if (speed < XFER_MW_DMA_0) 714 if (speed < XFER_MW_DMA_0)
@@ -741,19 +720,14 @@ static int hpt372_tune_chipset(ide_drive_t *drive, u8 xferspeed)
741 720
742static int hpt3xx_tune_chipset (ide_drive_t *drive, u8 speed) 721static int hpt3xx_tune_chipset (ide_drive_t *drive, u8 speed)
743{ 722{
744 struct pci_dev *dev = HWIF(drive)->pci_dev; 723 ide_hwif_t *hwif = drive->hwif;
724 struct hpt_info *info = ide_get_hwifdata(hwif);
745 725
746 if (hpt_minimum_revision(dev, 8)) 726 if (info->revision >= 8)
747 return hpt372_tune_chipset(drive, speed); /* not a typo */ 727 return hpt372_tune_chipset(drive, speed); /* not a typo */
748#if 0 728 else if (info->revision >= 5)
749 else if (hpt_minimum_revision(dev, 7))
750 hpt371_tune_chipset(drive, speed);
751 else if (hpt_minimum_revision(dev, 6))
752 hpt302_tune_chipset(drive, speed);
753#endif
754 else if (hpt_minimum_revision(dev, 5))
755 return hpt372_tune_chipset(drive, speed); 729 return hpt372_tune_chipset(drive, speed);
756 else if (hpt_minimum_revision(dev, 3)) 730 else if (info->revision >= 3)
757 return hpt370_tune_chipset(drive, speed); 731 return hpt370_tune_chipset(drive, speed);
758 else /* hpt368: hpt_minimum_revision(dev, 2) */ 732 else /* hpt368: hpt_minimum_revision(dev, 2) */
759 return hpt36x_tune_chipset(drive, speed); 733 return hpt36x_tune_chipset(drive, speed);
@@ -779,8 +753,14 @@ static void hpt3xx_tune_drive (ide_drive_t *drive, u8 pio)
779static int config_chipset_for_dma (ide_drive_t *drive) 753static int config_chipset_for_dma (ide_drive_t *drive)
780{ 754{
781 u8 speed = ide_dma_speed(drive, hpt3xx_ratemask(drive)); 755 u8 speed = ide_dma_speed(drive, hpt3xx_ratemask(drive));
756 ide_hwif_t *hwif = drive->hwif;
757 struct hpt_info *info = ide_get_hwifdata(hwif);
782 758
783 if (!(speed)) 759 if (!speed)
760 return 0;
761
762 /* If we don't have any timings we can't do a lot */
763 if (info->speed == NULL)
784 return 0; 764 return 0;
785 765
786 (void) hpt3xx_tune_chipset(drive, speed); 766 (void) hpt3xx_tune_chipset(drive, speed);
@@ -794,7 +774,7 @@ static int hpt3xx_quirkproc (ide_drive_t *drive)
794 774
795static void hpt3xx_intrproc (ide_drive_t *drive) 775static void hpt3xx_intrproc (ide_drive_t *drive)
796{ 776{
797 ide_hwif_t *hwif = HWIF(drive); 777 ide_hwif_t *hwif = drive->hwif;
798 778
799 if (drive->quirk_list) 779 if (drive->quirk_list)
800 return; 780 return;
@@ -804,24 +784,26 @@ static void hpt3xx_intrproc (ide_drive_t *drive)
804 784
805static void hpt3xx_maskproc (ide_drive_t *drive, int mask) 785static void hpt3xx_maskproc (ide_drive_t *drive, int mask)
806{ 786{
807 struct pci_dev *dev = HWIF(drive)->pci_dev; 787 ide_hwif_t *hwif = drive->hwif;
788 struct hpt_info *info = ide_get_hwifdata(hwif);
789 struct pci_dev *dev = hwif->pci_dev;
808 790
809 if (drive->quirk_list) { 791 if (drive->quirk_list) {
810 if (hpt_minimum_revision(dev,3)) { 792 if (info->revision >= 3) {
811 u8 reg5a = 0; 793 u8 reg5a = 0;
812 pci_read_config_byte(dev, 0x5a, &reg5a); 794 pci_read_config_byte(dev, 0x5a, &reg5a);
813 if (((reg5a & 0x10) >> 4) != mask) 795 if (((reg5a & 0x10) >> 4) != mask)
814 pci_write_config_byte(dev, 0x5a, mask ? (reg5a | 0x10) : (reg5a & ~0x10)); 796 pci_write_config_byte(dev, 0x5a, mask ? (reg5a | 0x10) : (reg5a & ~0x10));
815 } else { 797 } else {
816 if (mask) { 798 if (mask) {
817 disable_irq(HWIF(drive)->irq); 799 disable_irq(hwif->irq);
818 } else { 800 } else {
819 enable_irq(HWIF(drive)->irq); 801 enable_irq(hwif->irq);
820 } 802 }
821 } 803 }
822 } else { 804 } else {
823 if (IDE_CONTROL_REG) 805 if (IDE_CONTROL_REG)
824 HWIF(drive)->OUTB(mask ? (drive->ctl | 2) : 806 hwif->OUTB(mask ? (drive->ctl | 2) :
825 (drive->ctl & ~2), 807 (drive->ctl & ~2),
826 IDE_CONTROL_REG); 808 IDE_CONTROL_REG);
827 } 809 }
@@ -829,12 +811,12 @@ static void hpt3xx_maskproc (ide_drive_t *drive, int mask)
829 811
830static int hpt366_config_drive_xfer_rate (ide_drive_t *drive) 812static int hpt366_config_drive_xfer_rate (ide_drive_t *drive)
831{ 813{
832 ide_hwif_t *hwif = HWIF(drive); 814 ide_hwif_t *hwif = drive->hwif;
833 struct hd_driveid *id = drive->id; 815 struct hd_driveid *id = drive->id;
834 816
835 drive->init_speed = 0; 817 drive->init_speed = 0;
836 818
837 if (id && (id->capability & 1) && drive->autodma) { 819 if ((id->capability & 1) && drive->autodma) {
838 820
839 if (ide_use_dma(drive)) { 821 if (ide_use_dma(drive)) {
840 if (config_chipset_for_dma(drive)) 822 if (config_chipset_for_dma(drive))
@@ -868,15 +850,6 @@ static int hpt366_ide_dma_lostirq (ide_drive_t *drive)
868 drive->name, __FUNCTION__, reg50h, reg52h, reg5ah); 850 drive->name, __FUNCTION__, reg50h, reg52h, reg5ah);
869 if (reg5ah & 0x10) 851 if (reg5ah & 0x10)
870 pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10); 852 pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10);
871#if 0
872 /* how about we flush and reset, mmmkay? */
873 pci_write_config_byte(dev, 0x51, 0x1F);
874 /* fall through to a reset */
875 case dma_start:
876 case ide_dma_end:
877 /* reset the chips state over and over.. */
878 pci_write_config_byte(dev, 0x51, 0x13);
879#endif
880 return __ide_dma_lostirq(drive); 853 return __ide_dma_lostirq(drive);
881} 854}
882 855
@@ -919,7 +892,7 @@ static void hpt370_lostirq_timeout (ide_drive_t *drive)
919 u8 dma_stat = 0, dma_cmd = 0; 892 u8 dma_stat = 0, dma_cmd = 0;
920 893
921 pci_read_config_byte(HWIF(drive)->pci_dev, reginfo, &bfifo); 894 pci_read_config_byte(HWIF(drive)->pci_dev, reginfo, &bfifo);
922 printk("%s: %d bytes in FIFO\n", drive->name, bfifo); 895 printk(KERN_DEBUG "%s: %d bytes in FIFO\n", drive->name, bfifo);
923 hpt370_clear_engine(drive); 896 hpt370_clear_engine(drive);
924 /* get dma command mode */ 897 /* get dma command mode */
925 dma_cmd = hwif->INB(hwif->dma_command); 898 dma_cmd = hwif->INB(hwif->dma_command);
@@ -1047,15 +1020,6 @@ static void hpt372n_rw_disk(ide_drive_t *drive, struct request *rq)
1047 1020
1048static void hpt3xx_reset (ide_drive_t *drive) 1021static void hpt3xx_reset (ide_drive_t *drive)
1049{ 1022{
1050#if 0
1051 unsigned long high_16 = pci_resource_start(HWIF(drive)->pci_dev, 4);
1052 u8 reset = (HWIF(drive)->channel) ? 0x80 : 0x40;
1053 u8 reg59h = 0;
1054
1055 pci_read_config_byte(HWIF(drive)->pci_dev, 0x59, &reg59h);
1056 pci_write_config_byte(HWIF(drive)->pci_dev, 0x59, reg59h|reset);
1057 pci_write_config_byte(HWIF(drive)->pci_dev, 0x59, reg59h);
1058#endif
1059} 1023}
1060 1024
1061static int hpt3xx_tristate (ide_drive_t * drive, int state) 1025static int hpt3xx_tristate (ide_drive_t * drive, int state)
@@ -1065,8 +1029,6 @@ static int hpt3xx_tristate (ide_drive_t * drive, int state)
1065 u8 reg59h = 0, reset = (hwif->channel) ? 0x80 : 0x40; 1029 u8 reg59h = 0, reset = (hwif->channel) ? 0x80 : 0x40;
1066 u8 regXXh = 0, state_reg= (hwif->channel) ? 0x57 : 0x53; 1030 u8 regXXh = 0, state_reg= (hwif->channel) ? 0x57 : 0x53;
1067 1031
1068// hwif->bus_state = state;
1069
1070 pci_read_config_byte(dev, 0x59, &reg59h); 1032 pci_read_config_byte(dev, 0x59, &reg59h);
1071 pci_read_config_byte(dev, state_reg, &regXXh); 1033 pci_read_config_byte(dev, state_reg, &regXXh);
1072 1034
@@ -1093,7 +1055,7 @@ static int hpt3xx_tristate (ide_drive_t * drive, int state)
1093#define TRISTATE_BIT 0x8000 1055#define TRISTATE_BIT 0x8000
1094static int hpt370_busproc(ide_drive_t * drive, int state) 1056static int hpt370_busproc(ide_drive_t * drive, int state)
1095{ 1057{
1096 ide_hwif_t *hwif = HWIF(drive); 1058 ide_hwif_t *hwif = drive->hwif;
1097 struct pci_dev *dev = hwif->pci_dev; 1059 struct pci_dev *dev = hwif->pci_dev;
1098 u8 tristate = 0, resetmask = 0, bus_reg = 0; 1060 u8 tristate = 0, resetmask = 0, bus_reg = 0;
1099 u16 tri_reg; 1061 u16 tri_reg;
@@ -1148,33 +1110,44 @@ static int hpt370_busproc(ide_drive_t * drive, int state)
1148 return 0; 1110 return 0;
1149} 1111}
1150 1112
1151static int __devinit init_hpt37x(struct pci_dev *dev) 1113static void __devinit hpt366_clocking(ide_hwif_t *hwif)
1152{ 1114{
1115 u32 reg1 = 0;
1116 struct hpt_info *info = ide_get_hwifdata(hwif);
1117
1118 pci_read_config_dword(hwif->pci_dev, 0x40, &reg1);
1119
1120 /* detect bus speed by looking at control reg timing: */
1121 switch((reg1 >> 8) & 7) {
1122 case 5:
1123 info->speed = forty_base_hpt366;
1124 break;
1125 case 9:
1126 info->speed = twenty_five_base_hpt366;
1127 break;
1128 case 7:
1129 default:
1130 info->speed = thirty_three_base_hpt366;
1131 break;
1132 }
1133}
1134
1135static void __devinit hpt37x_clocking(ide_hwif_t *hwif)
1136{
1137 struct hpt_info *info = ide_get_hwifdata(hwif);
1138 struct pci_dev *dev = hwif->pci_dev;
1153 int adjust, i; 1139 int adjust, i;
1154 u16 freq; 1140 u16 freq;
1155 u32 pll; 1141 u32 pll;
1156 u8 reg5bh; 1142 u8 reg5bh;
1157 u8 reg5ah = 0;
1158 unsigned long dmabase = pci_resource_start(dev, 4);
1159 u8 did, rid;
1160 int is_372n = 0;
1161 1143
1162 pci_read_config_byte(dev, 0x5a, &reg5ah);
1163 /* interrupt force enable */
1164 pci_write_config_byte(dev, 0x5a, (reg5ah & ~0x10));
1165
1166 if(dmabase)
1167 {
1168 did = inb(dmabase + 0x22);
1169 rid = inb(dmabase + 0x28);
1170
1171 if((did == 4 && rid == 6) || (did == 5 && rid > 1))
1172 is_372n = 1;
1173 }
1174
1175 /* 1144 /*
1176 * default to pci clock. make sure MA15/16 are set to output 1145 * default to pci clock. make sure MA15/16 are set to output
1177 * to prevent drives having problems with 40-pin cables. 1146 * to prevent drives having problems with 40-pin cables. Needed
1147 * for some drives such as IBM-DTLA which will not enter ready
1148 * state on reset when PDIAG is a input.
1149 *
1150 * ToDo: should we set 0x21 when using PLL mode ?
1178 */ 1151 */
1179 pci_write_config_byte(dev, 0x5b, 0x23); 1152 pci_write_config_byte(dev, 0x5b, 0x23);
1180 1153
@@ -1197,9 +1170,7 @@ static int __devinit init_hpt37x(struct pci_dev *dev)
1197 * Currently we always set up the PLL for the 372N 1170 * Currently we always set up the PLL for the 372N
1198 */ 1171 */
1199 1172
1200 pci_set_drvdata(dev, NULL); 1173 if(info->flags & IS_372N)
1201
1202 if(is_372n)
1203 { 1174 {
1204 printk(KERN_INFO "hpt: HPT372N detected, using 372N timing.\n"); 1175 printk(KERN_INFO "hpt: HPT372N detected, using 372N timing.\n");
1205 if(freq < 0x55) 1176 if(freq < 0x55)
@@ -1227,39 +1198,38 @@ static int __devinit init_hpt37x(struct pci_dev *dev)
1227 pll = F_LOW_PCI_66; 1198 pll = F_LOW_PCI_66;
1228 1199
1229 if (pll == F_LOW_PCI_33) { 1200 if (pll == F_LOW_PCI_33) {
1230 if (hpt_minimum_revision(dev,8)) 1201 if (info->revision >= 8)
1231 pci_set_drvdata(dev, (void *) thirty_three_base_hpt374); 1202 info->speed = thirty_three_base_hpt374;
1232 else if (hpt_minimum_revision(dev,5)) 1203 else if (info->revision >= 5)
1233 pci_set_drvdata(dev, (void *) thirty_three_base_hpt372); 1204 info->speed = thirty_three_base_hpt372;
1234 else if (hpt_minimum_revision(dev,4)) 1205 else if (info->revision >= 4)
1235 pci_set_drvdata(dev, (void *) thirty_three_base_hpt370a); 1206 info->speed = thirty_three_base_hpt370a;
1236 else 1207 else
1237 pci_set_drvdata(dev, (void *) thirty_three_base_hpt370); 1208 info->speed = thirty_three_base_hpt370;
1238 printk("HPT37X: using 33MHz PCI clock\n"); 1209 printk(KERN_DEBUG "HPT37X: using 33MHz PCI clock\n");
1239 } else if (pll == F_LOW_PCI_40) { 1210 } else if (pll == F_LOW_PCI_40) {
1240 /* Unsupported */ 1211 /* Unsupported */
1241 } else if (pll == F_LOW_PCI_50) { 1212 } else if (pll == F_LOW_PCI_50) {
1242 if (hpt_minimum_revision(dev,8)) 1213 if (info->revision >= 8)
1243 pci_set_drvdata(dev, (void *) fifty_base_hpt370a); 1214 info->speed = fifty_base_hpt370a;
1244 else if (hpt_minimum_revision(dev,5)) 1215 else if (info->revision >= 5)
1245 pci_set_drvdata(dev, (void *) fifty_base_hpt372); 1216 info->speed = fifty_base_hpt372;
1246 else if (hpt_minimum_revision(dev,4)) 1217 else if (info->revision >= 4)
1247 pci_set_drvdata(dev, (void *) fifty_base_hpt370a); 1218 info->speed = fifty_base_hpt370a;
1248 else 1219 else
1249 pci_set_drvdata(dev, (void *) fifty_base_hpt370a); 1220 info->speed = fifty_base_hpt370a;
1250 printk("HPT37X: using 50MHz PCI clock\n"); 1221 printk(KERN_DEBUG "HPT37X: using 50MHz PCI clock\n");
1251 } else { 1222 } else {
1252 if (hpt_minimum_revision(dev,8)) 1223 if (info->revision >= 8) {
1253 {
1254 printk(KERN_ERR "HPT37x: 66MHz timings are not supported.\n"); 1224 printk(KERN_ERR "HPT37x: 66MHz timings are not supported.\n");
1255 } 1225 }
1256 else if (hpt_minimum_revision(dev,5)) 1226 else if (info->revision >= 5)
1257 pci_set_drvdata(dev, (void *) sixty_six_base_hpt372); 1227 info->speed = sixty_six_base_hpt372;
1258 else if (hpt_minimum_revision(dev,4)) 1228 else if (info->revision >= 4)
1259 pci_set_drvdata(dev, (void *) sixty_six_base_hpt370a); 1229 info->speed = sixty_six_base_hpt370a;
1260 else 1230 else
1261 pci_set_drvdata(dev, (void *) sixty_six_base_hpt370); 1231 info->speed = sixty_six_base_hpt370;
1262 printk("HPT37X: using 66MHz PCI clock\n"); 1232 printk(KERN_DEBUG "HPT37X: using 66MHz PCI clock\n");
1263 } 1233 }
1264 } 1234 }
1265 1235
@@ -1269,11 +1239,19 @@ static int __devinit init_hpt37x(struct pci_dev *dev)
1269 * result in slow reads when using a 33MHz PCI clock. we also 1239 * result in slow reads when using a 33MHz PCI clock. we also
1270 * don't like to use the PLL because it will cause glitches 1240 * don't like to use the PLL because it will cause glitches
1271 * on PRST/SRST when the HPT state engine gets reset. 1241 * on PRST/SRST when the HPT state engine gets reset.
1242 *
1243 * ToDo: Use 66MHz PLL when ATA133 devices are present on a
1244 * 372 device so we can get ATA133 support
1272 */ 1245 */
1273 if (pci_get_drvdata(dev)) 1246 if (info->speed)
1274 goto init_hpt37X_done; 1247 goto init_hpt37X_done;
1248
1249 info->flags |= PLL_MODE;
1275 1250
1276 /* 1251 /*
1252 * FIXME: make this work correctly, esp with 372N as per
1253 * reference driver code.
1254 *
1277 * adjust PLL based upon PCI clock, enable it, and wait for 1255 * adjust PLL based upon PCI clock, enable it, and wait for
1278 * stabilization. 1256 * stabilization.
1279 */ 1257 */
@@ -1298,14 +1276,14 @@ static int __devinit init_hpt37x(struct pci_dev *dev)
1298 pci_write_config_dword(dev, 0x5c, 1276 pci_write_config_dword(dev, 0x5c,
1299 pll & ~0x100); 1277 pll & ~0x100);
1300 pci_write_config_byte(dev, 0x5b, 0x21); 1278 pci_write_config_byte(dev, 0x5b, 0x21);
1301 if (hpt_minimum_revision(dev,8)) 1279 if (info->revision >= 8)
1302 pci_set_drvdata(dev, (void *) fifty_base_hpt370a); 1280 info->speed = fifty_base_hpt370a;
1303 else if (hpt_minimum_revision(dev,5)) 1281 else if (info->revision >= 5)
1304 pci_set_drvdata(dev, (void *) fifty_base_hpt372); 1282 info->speed = fifty_base_hpt372;
1305 else if (hpt_minimum_revision(dev,4)) 1283 else if (info->revision >= 4)
1306 pci_set_drvdata(dev, (void *) fifty_base_hpt370a); 1284 info->speed = fifty_base_hpt370a;
1307 else 1285 else
1308 pci_set_drvdata(dev, (void *) fifty_base_hpt370a); 1286 info->speed = fifty_base_hpt370a;
1309 printk("HPT37X: using 50MHz internal PLL\n"); 1287 printk("HPT37X: using 50MHz internal PLL\n");
1310 goto init_hpt37X_done; 1288 goto init_hpt37X_done;
1311 } 1289 }
@@ -1318,10 +1296,22 @@ pll_recal:
1318 } 1296 }
1319 1297
1320init_hpt37X_done: 1298init_hpt37X_done:
1299 if (!info->speed)
1300 printk(KERN_ERR "HPT37X%s: unknown bus timing [%d %d].\n",
1301 (info->flags & IS_372N)?"N":"", pll, freq);
1321 /* reset state engine */ 1302 /* reset state engine */
1322 pci_write_config_byte(dev, 0x50, 0x37); 1303 pci_write_config_byte(dev, 0x50, 0x37);
1323 pci_write_config_byte(dev, 0x54, 0x37); 1304 pci_write_config_byte(dev, 0x54, 0x37);
1324 udelay(100); 1305 udelay(100);
1306}
1307
1308static int __devinit init_hpt37x(struct pci_dev *dev)
1309{
1310 u8 reg5ah;
1311
1312 pci_read_config_byte(dev, 0x5a, &reg5ah);
1313 /* interrupt force enable */
1314 pci_write_config_byte(dev, 0x5a, (reg5ah & ~0x10));
1325 return 0; 1315 return 0;
1326} 1316}
1327 1317
@@ -1338,59 +1328,27 @@ static int __devinit init_hpt366(struct pci_dev *dev)
1338 pci_write_config_byte(dev, 0x51, drive_fast & ~0x80); 1328 pci_write_config_byte(dev, 0x51, drive_fast & ~0x80);
1339 pci_read_config_dword(dev, 0x40, &reg1); 1329 pci_read_config_dword(dev, 0x40, &reg1);
1340 1330
1341 /* detect bus speed by looking at control reg timing: */
1342 switch((reg1 >> 8) & 7) {
1343 case 5:
1344 pci_set_drvdata(dev, (void *) forty_base_hpt366);
1345 break;
1346 case 9:
1347 pci_set_drvdata(dev, (void *) twenty_five_base_hpt366);
1348 break;
1349 case 7:
1350 default:
1351 pci_set_drvdata(dev, (void *) thirty_three_base_hpt366);
1352 break;
1353 }
1354
1355 if (!pci_get_drvdata(dev))
1356 {
1357 printk(KERN_ERR "hpt366: unknown bus timing.\n");
1358 pci_set_drvdata(dev, NULL);
1359 }
1360 return 0; 1331 return 0;
1361} 1332}
1362 1333
1363static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name) 1334static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name)
1364{ 1335{
1365 int ret = 0; 1336 int ret = 0;
1366 u8 test = 0; 1337 /* FIXME: Not portable */
1367
1368 if (dev->resource[PCI_ROM_RESOURCE].start) 1338 if (dev->resource[PCI_ROM_RESOURCE].start)
1369 pci_write_config_byte(dev, PCI_ROM_ADDRESS, 1339 pci_write_config_byte(dev, PCI_ROM_ADDRESS,
1370 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); 1340 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
1371 1341
1372 pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &test); 1342 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
1373 if (test != (L1_CACHE_BYTES / 4)) 1343 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
1374 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 1344 pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
1375 (L1_CACHE_BYTES / 4)); 1345 pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
1376
1377 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &test);
1378 if (test != 0x78)
1379 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
1380 1346
1381 pci_read_config_byte(dev, PCI_MIN_GNT, &test); 1347 if (hpt_revision(dev) >= 3)
1382 if (test != 0x08)
1383 pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
1384
1385 pci_read_config_byte(dev, PCI_MAX_LAT, &test);
1386 if (test != 0x08)
1387 pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
1388
1389 if (hpt_minimum_revision(dev, 3)) {
1390 ret = init_hpt37x(dev); 1348 ret = init_hpt37x(dev);
1391 } else { 1349 else
1392 ret =init_hpt366(dev); 1350 ret = init_hpt366(dev);
1393 } 1351
1394 if (ret) 1352 if (ret)
1395 return ret; 1353 return ret;
1396 1354
@@ -1400,27 +1358,16 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1400static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) 1358static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1401{ 1359{
1402 struct pci_dev *dev = hwif->pci_dev; 1360 struct pci_dev *dev = hwif->pci_dev;
1361 struct hpt_info *info = ide_get_hwifdata(hwif);
1403 u8 ata66 = 0, regmask = (hwif->channel) ? 0x01 : 0x02; 1362 u8 ata66 = 0, regmask = (hwif->channel) ? 0x01 : 0x02;
1404 u8 did, rid;
1405 unsigned long dmabase = hwif->dma_base;
1406 int is_372n = 0;
1407 1363
1408 if(dmabase)
1409 {
1410 did = inb(dmabase + 0x22);
1411 rid = inb(dmabase + 0x28);
1412
1413 if((did == 4 && rid == 6) || (did == 5 && rid > 1))
1414 is_372n = 1;
1415 }
1416
1417 hwif->tuneproc = &hpt3xx_tune_drive; 1364 hwif->tuneproc = &hpt3xx_tune_drive;
1418 hwif->speedproc = &hpt3xx_tune_chipset; 1365 hwif->speedproc = &hpt3xx_tune_chipset;
1419 hwif->quirkproc = &hpt3xx_quirkproc; 1366 hwif->quirkproc = &hpt3xx_quirkproc;
1420 hwif->intrproc = &hpt3xx_intrproc; 1367 hwif->intrproc = &hpt3xx_intrproc;
1421 hwif->maskproc = &hpt3xx_maskproc; 1368 hwif->maskproc = &hpt3xx_maskproc;
1422 1369
1423 if(is_372n) 1370 if(info->flags & IS_372N)
1424 hwif->rw_disk = &hpt372n_rw_disk; 1371 hwif->rw_disk = &hpt372n_rw_disk;
1425 1372
1426 /* 1373 /*
@@ -1428,7 +1375,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1428 * address lines to access an external eeprom. To read valid 1375 * address lines to access an external eeprom. To read valid
1429 * cable detect state the pins must be enabled as inputs. 1376 * cable detect state the pins must be enabled as inputs.
1430 */ 1377 */
1431 if (hpt_minimum_revision(dev, 8) && PCI_FUNC(dev->devfn) & 1) { 1378 if (info->revision >= 8 && (PCI_FUNC(dev->devfn) & 1)) {
1432 /* 1379 /*
1433 * HPT374 PCI function 1 1380 * HPT374 PCI function 1
1434 * - set bit 15 of reg 0x52 to enable TCBLID as input 1381 * - set bit 15 of reg 0x52 to enable TCBLID as input
@@ -1443,7 +1390,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1443 pci_read_config_byte(dev, 0x5a, &ata66); 1390 pci_read_config_byte(dev, 0x5a, &ata66);
1444 pci_write_config_word(dev, 0x52, mcr3); 1391 pci_write_config_word(dev, 0x52, mcr3);
1445 pci_write_config_word(dev, 0x56, mcr6); 1392 pci_write_config_word(dev, 0x56, mcr6);
1446 } else if (hpt_minimum_revision(dev, 3)) { 1393 } else if (info->revision >= 3) {
1447 /* 1394 /*
1448 * HPT370/372 and 374 pcifn 0 1395 * HPT370/372 and 374 pcifn 0
1449 * - clear bit 0 of 0x5b to enable P/SCBLID as inputs 1396 * - clear bit 0 of 0x5b to enable P/SCBLID as inputs
@@ -1470,7 +1417,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1470 hwif->serialized = hwif->mate->serialized = 1; 1417 hwif->serialized = hwif->mate->serialized = 1;
1471#endif 1418#endif
1472 1419
1473 if (hpt_minimum_revision(dev,3)) { 1420 if (info->revision >= 3) {
1474 u8 reg5ah = 0; 1421 u8 reg5ah = 0;
1475 pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10); 1422 pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10);
1476 /* 1423 /*
@@ -1480,8 +1427,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1480 */ 1427 */
1481 hwif->resetproc = &hpt3xx_reset; 1428 hwif->resetproc = &hpt3xx_reset;
1482 hwif->busproc = &hpt370_busproc; 1429 hwif->busproc = &hpt370_busproc;
1483// hwif->drives[0].autotune = hwif->drives[1].autotune = 1; 1430 } else if (info->revision >= 2) {
1484 } else if (hpt_minimum_revision(dev,2)) {
1485 hwif->resetproc = &hpt3xx_reset; 1431 hwif->resetproc = &hpt3xx_reset;
1486 hwif->busproc = &hpt3xx_tristate; 1432 hwif->busproc = &hpt3xx_tristate;
1487 } else { 1433 } else {
@@ -1502,18 +1448,18 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1502 hwif->udma_four = ((ata66 & regmask) ? 0 : 1); 1448 hwif->udma_four = ((ata66 & regmask) ? 0 : 1);
1503 hwif->ide_dma_check = &hpt366_config_drive_xfer_rate; 1449 hwif->ide_dma_check = &hpt366_config_drive_xfer_rate;
1504 1450
1505 if (hpt_minimum_revision(dev,8)) { 1451 if (info->revision >= 8) {
1506 hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq; 1452 hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;
1507 hwif->ide_dma_end = &hpt374_ide_dma_end; 1453 hwif->ide_dma_end = &hpt374_ide_dma_end;
1508 } else if (hpt_minimum_revision(dev,5)) { 1454 } else if (info->revision >= 5) {
1509 hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq; 1455 hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;
1510 hwif->ide_dma_end = &hpt374_ide_dma_end; 1456 hwif->ide_dma_end = &hpt374_ide_dma_end;
1511 } else if (hpt_minimum_revision(dev,3)) { 1457 } else if (info->revision >= 3) {
1512 hwif->dma_start = &hpt370_ide_dma_start; 1458 hwif->dma_start = &hpt370_ide_dma_start;
1513 hwif->ide_dma_end = &hpt370_ide_dma_end; 1459 hwif->ide_dma_end = &hpt370_ide_dma_end;
1514 hwif->ide_dma_timeout = &hpt370_ide_dma_timeout; 1460 hwif->ide_dma_timeout = &hpt370_ide_dma_timeout;
1515 hwif->ide_dma_lostirq = &hpt370_ide_dma_lostirq; 1461 hwif->ide_dma_lostirq = &hpt370_ide_dma_lostirq;
1516 } else if (hpt_minimum_revision(dev,2)) 1462 } else if (info->revision >= 2)
1517 hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq; 1463 hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq;
1518 else 1464 else
1519 hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq; 1465 hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq;
@@ -1526,6 +1472,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1526 1472
1527static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase) 1473static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
1528{ 1474{
1475 struct hpt_info *info = ide_get_hwifdata(hwif);
1529 u8 masterdma = 0, slavedma = 0; 1476 u8 masterdma = 0, slavedma = 0;
1530 u8 dma_new = 0, dma_old = 0; 1477 u8 dma_new = 0, dma_old = 0;
1531 u8 primary = hwif->channel ? 0x4b : 0x43; 1478 u8 primary = hwif->channel ? 0x4b : 0x43;
@@ -1535,8 +1482,7 @@ static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
1535 if (!dmabase) 1482 if (!dmabase)
1536 return; 1483 return;
1537 1484
1538 if(pci_get_drvdata(hwif->pci_dev) == NULL) 1485 if(info->speed == NULL) {
1539 {
1540 printk(KERN_WARNING "hpt: no known IDE timings, disabling DMA.\n"); 1486 printk(KERN_WARNING "hpt: no known IDE timings, disabling DMA.\n");
1541 return; 1487 return;
1542 } 1488 }
@@ -1559,6 +1505,40 @@ static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
1559 ide_setup_dma(hwif, dmabase, 8); 1505 ide_setup_dma(hwif, dmabase, 8);
1560} 1506}
1561 1507
1508/*
1509 * We "borrow" this hook in order to set the data structures
1510 * up early enough before dma or init_hwif calls are made.
1511 */
1512
1513static void __devinit init_iops_hpt366(ide_hwif_t *hwif)
1514{
1515 struct hpt_info *info = kmalloc(sizeof(struct hpt_info), GFP_KERNEL);
1516 unsigned long dmabase = pci_resource_start(hwif->pci_dev, 4);
1517 u8 did, rid;
1518
1519 if(info == NULL) {
1520 printk(KERN_WARNING "hpt366: out of memory.\n");
1521 return;
1522 }
1523 memset(info, 0, sizeof(struct hpt_info));
1524 ide_set_hwifdata(hwif, info);
1525
1526 if(dmabase) {
1527 did = inb(dmabase + 0x22);
1528 rid = inb(dmabase + 0x28);
1529
1530 if((did == 4 && rid == 6) || (did == 5 && rid > 1))
1531 info->flags |= IS_372N;
1532 }
1533
1534 info->revision = hpt_revision(hwif->pci_dev);
1535
1536 if (info->revision >= 3)
1537 hpt37x_clocking(hwif);
1538 else
1539 hpt366_clocking(hwif);
1540}
1541
1562static int __devinit init_setup_hpt374(struct pci_dev *dev, ide_pci_device_t *d) 1542static int __devinit init_setup_hpt374(struct pci_dev *dev, ide_pci_device_t *d)
1563{ 1543{
1564 struct pci_dev *findev = NULL; 1544 struct pci_dev *findev = NULL;
@@ -1646,6 +1626,7 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1646 .name = "HPT366", 1626 .name = "HPT366",
1647 .init_setup = init_setup_hpt366, 1627 .init_setup = init_setup_hpt366,
1648 .init_chipset = init_chipset_hpt366, 1628 .init_chipset = init_chipset_hpt366,
1629 .init_iops = init_iops_hpt366,
1649 .init_hwif = init_hwif_hpt366, 1630 .init_hwif = init_hwif_hpt366,
1650 .init_dma = init_dma_hpt366, 1631 .init_dma = init_dma_hpt366,
1651 .channels = 2, 1632 .channels = 2,
@@ -1656,6 +1637,7 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1656 .name = "HPT372A", 1637 .name = "HPT372A",
1657 .init_setup = init_setup_hpt37x, 1638 .init_setup = init_setup_hpt37x,
1658 .init_chipset = init_chipset_hpt366, 1639 .init_chipset = init_chipset_hpt366,
1640 .init_iops = init_iops_hpt366,
1659 .init_hwif = init_hwif_hpt366, 1641 .init_hwif = init_hwif_hpt366,
1660 .init_dma = init_dma_hpt366, 1642 .init_dma = init_dma_hpt366,
1661 .channels = 2, 1643 .channels = 2,
@@ -1665,6 +1647,7 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1665 .name = "HPT302", 1647 .name = "HPT302",
1666 .init_setup = init_setup_hpt37x, 1648 .init_setup = init_setup_hpt37x,
1667 .init_chipset = init_chipset_hpt366, 1649 .init_chipset = init_chipset_hpt366,
1650 .init_iops = init_iops_hpt366,
1668 .init_hwif = init_hwif_hpt366, 1651 .init_hwif = init_hwif_hpt366,
1669 .init_dma = init_dma_hpt366, 1652 .init_dma = init_dma_hpt366,
1670 .channels = 2, 1653 .channels = 2,
@@ -1674,6 +1657,7 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1674 .name = "HPT371", 1657 .name = "HPT371",
1675 .init_setup = init_setup_hpt37x, 1658 .init_setup = init_setup_hpt37x,
1676 .init_chipset = init_chipset_hpt366, 1659 .init_chipset = init_chipset_hpt366,
1660 .init_iops = init_iops_hpt366,
1677 .init_hwif = init_hwif_hpt366, 1661 .init_hwif = init_hwif_hpt366,
1678 .init_dma = init_dma_hpt366, 1662 .init_dma = init_dma_hpt366,
1679 .channels = 2, 1663 .channels = 2,
@@ -1683,6 +1667,7 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1683 .name = "HPT374", 1667 .name = "HPT374",
1684 .init_setup = init_setup_hpt374, 1668 .init_setup = init_setup_hpt374,
1685 .init_chipset = init_chipset_hpt366, 1669 .init_chipset = init_chipset_hpt366,
1670 .init_iops = init_iops_hpt366,
1686 .init_hwif = init_hwif_hpt366, 1671 .init_hwif = init_hwif_hpt366,
1687 .init_dma = init_dma_hpt366, 1672 .init_dma = init_dma_hpt366,
1688 .channels = 2, /* 4 */ 1673 .channels = 2, /* 4 */
@@ -1692,6 +1677,7 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1692 .name = "HPT372N", 1677 .name = "HPT372N",
1693 .init_setup = init_setup_hpt37x, 1678 .init_setup = init_setup_hpt37x,
1694 .init_chipset = init_chipset_hpt366, 1679 .init_chipset = init_chipset_hpt366,
1680 .init_iops = init_iops_hpt366,
1695 .init_hwif = init_hwif_hpt366, 1681 .init_hwif = init_hwif_hpt366,
1696 .init_dma = init_dma_hpt366, 1682 .init_dma = init_dma_hpt366,
1697 .channels = 2, /* 4 */ 1683 .channels = 2, /* 4 */
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
new file mode 100644
index 000000000000..e440036e651f
--- /dev/null
+++ b/drivers/ide/pci/it821x.c
@@ -0,0 +1,812 @@
1
2/*
3 * linux/drivers/ide/pci/it821x.c Version 0.09 December 2004
4 *
5 * Copyright (C) 2004 Red Hat <alan@redhat.com>
6 *
7 * May be copied or modified under the terms of the GNU General Public License
8 * Based in part on the ITE vendor provided SCSI driver.
9 *
10 * Documentation available from
11 * http://www.ite.com.tw/pc/IT8212F_V04.pdf
12 * Some other documents are NDA.
13 *
14 * The ITE8212 isn't exactly a standard IDE controller. It has two
15 * modes. In pass through mode then it is an IDE controller. In its smart
16 * mode its actually quite a capable hardware raid controller disguised
17 * as an IDE controller. Smart mode only understands DMA read/write and
18 * identify, none of the fancier commands apply. The IT8211 is identical
19 * in other respects but lacks the raid mode.
20 *
21 * Errata:
22 * o Rev 0x10 also requires master/slave hold the same DMA timings and
23 * cannot do ATAPI MWDMA.
24 * o The identify data for raid volumes lacks CHS info (technically ok)
25 * but also fails to set the LBA28 and other bits. We fix these in
26 * the IDE probe quirk code.
27 * o If you write LBA48 sized I/O's (ie > 256 sector) in smart mode
28 * raid then the controller firmware dies
29 * o Smart mode without RAID doesn't clear all the necessary identify
30 * bits to reduce the command set to the one used
31 *
32 * This has a few impacts on the driver
33 * - In pass through mode we do all the work you would expect
34 * - In smart mode the clocking set up is done by the controller generally
35 * but we must watch the other limits and filter.
36 * - There are a few extra vendor commands that actually talk to the
37 * controller but only work PIO with no IRQ.
38 *
39 * Vendor areas of the identify block in smart mode are used for the
40 * timing and policy set up. Each HDD in raid mode also has a serial
41 * block on the disk. The hardware extra commands are get/set chip status,
42 * rebuild, get rebuild status.
43 *
44 * In Linux the driver supports pass through mode as if the device was
45 * just another IDE controller. If the smart mode is running then
46 * volumes are managed by the controller firmware and each IDE "disk"
47 * is a raid volume. Even more cute - the controller can do automated
48 * hotplug and rebuild.
49 *
50 * The pass through controller itself is a little demented. It has a
51 * flaw that it has a single set of PIO/MWDMA timings per channel so
52 * non UDMA devices restrict each others performance. It also has a
53 * single clock source per channel so mixed UDMA100/133 performance
54 * isn't perfect and we have to pick a clock. Thankfully none of this
55 * matters in smart mode. ATAPI DMA is not currently supported.
56 *
57 * It seems the smart mode is a win for RAID1/RAID10 but otherwise not.
58 *
59 * TODO
60 * - ATAPI UDMA is ok but not MWDMA it seems
61 * - RAID configuration ioctls
62 * - Move to libata once it grows up
63 */
64
65#include <linux/config.h>
66#include <linux/types.h>
67#include <linux/module.h>
68#include <linux/pci.h>
69#include <linux/delay.h>
70#include <linux/hdreg.h>
71#include <linux/ide.h>
72#include <linux/init.h>
73
74#include <asm/io.h>
75
76struct it821x_dev
77{
78 unsigned int smart:1, /* Are we in smart raid mode */
79 timing10:1; /* Rev 0x10 */
80 u8 clock_mode; /* 0, ATA_50 or ATA_66 */
81 u8 want[2][2]; /* Mode/Pri log for master slave */
82 /* We need these for switching the clock when DMA goes on/off
83 The high byte is the 66Mhz timing */
84 u16 pio[2]; /* Cached PIO values */
85 u16 mwdma[2]; /* Cached MWDMA values */
86 u16 udma[2]; /* Cached UDMA values (per drive) */
87};
88
89#define ATA_66 0
90#define ATA_50 1
91#define ATA_ANY 2
92
93#define UDMA_OFF 0
94#define MWDMA_OFF 0
95
96/*
97 * We allow users to force the card into non raid mode without
98 * flashing the alternative BIOS. This is also neccessary right now
99 * for embedded platforms that cannot run a PC BIOS but are using this
100 * device.
101 */
102
103static int it8212_noraid;
104
105/**
106 * it821x_program - program the PIO/MWDMA registers
107 * @drive: drive to tune
108 *
109 * Program the PIO/MWDMA timing for this channel according to the
110 * current clock.
111 */
112
113static void it821x_program(ide_drive_t *drive, u16 timing)
114{
115 ide_hwif_t *hwif = drive->hwif;
116 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
117 int channel = hwif->channel;
118 u8 conf;
119
120 /* Program PIO/MWDMA timing bits */
121 if(itdev->clock_mode == ATA_66)
122 conf = timing >> 8;
123 else
124 conf = timing & 0xFF;
125 pci_write_config_byte(hwif->pci_dev, 0x54 + 4 * channel, conf);
126}
127
128/**
129 * it821x_program_udma - program the UDMA registers
130 * @drive: drive to tune
131 *
132 * Program the UDMA timing for this drive according to the
133 * current clock.
134 */
135
136static void it821x_program_udma(ide_drive_t *drive, u16 timing)
137{
138 ide_hwif_t *hwif = drive->hwif;
139 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
140 int channel = hwif->channel;
141 int unit = drive->select.b.unit;
142 u8 conf;
143
144 /* Program UDMA timing bits */
145 if(itdev->clock_mode == ATA_66)
146 conf = timing >> 8;
147 else
148 conf = timing & 0xFF;
149 if(itdev->timing10 == 0)
150 pci_write_config_byte(hwif->pci_dev, 0x56 + 4 * channel + unit, conf);
151 else {
152 pci_write_config_byte(hwif->pci_dev, 0x56 + 4 * channel, conf);
153 pci_write_config_byte(hwif->pci_dev, 0x56 + 4 * channel + 1, conf);
154 }
155}
156
157
158/**
159 * it821x_clock_strategy
160 * @hwif: hardware interface
161 *
162 * Select between the 50 and 66Mhz base clocks to get the best
163 * results for this interface.
164 */
165
166static void it821x_clock_strategy(ide_drive_t *drive)
167{
168 ide_hwif_t *hwif = drive->hwif;
169 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
170
171 u8 unit = drive->select.b.unit;
172 ide_drive_t *pair = &hwif->drives[1-unit];
173
174 int clock, altclock;
175 u8 v;
176 int sel = 0;
177
178 if(itdev->want[0][0] > itdev->want[1][0]) {
179 clock = itdev->want[0][1];
180 altclock = itdev->want[1][1];
181 } else {
182 clock = itdev->want[1][1];
183 altclock = itdev->want[0][1];
184 }
185
186 /* Master doesn't care does the slave ? */
187 if(clock == ATA_ANY)
188 clock = altclock;
189
190 /* Nobody cares - keep the same clock */
191 if(clock == ATA_ANY)
192 return;
193 /* No change */
194 if(clock == itdev->clock_mode)
195 return;
196
197 /* Load this into the controller ? */
198 if(clock == ATA_66)
199 itdev->clock_mode = ATA_66;
200 else {
201 itdev->clock_mode = ATA_50;
202 sel = 1;
203 }
204 pci_read_config_byte(hwif->pci_dev, 0x50, &v);
205 v &= ~(1 << (1 + hwif->channel));
206 v |= sel << (1 + hwif->channel);
207 pci_write_config_byte(hwif->pci_dev, 0x50, v);
208
209 /*
210 * Reprogram the UDMA/PIO of the pair drive for the switch
211 * MWDMA will be dealt with by the dma switcher
212 */
213 if(pair && itdev->udma[1-unit] != UDMA_OFF) {
214 it821x_program_udma(pair, itdev->udma[1-unit]);
215 it821x_program(pair, itdev->pio[1-unit]);
216 }
217 /*
218 * Reprogram the UDMA/PIO of our drive for the switch.
219 * MWDMA will be dealt with by the dma switcher
220 */
221 if(itdev->udma[unit] != UDMA_OFF) {
222 it821x_program_udma(drive, itdev->udma[unit]);
223 it821x_program(drive, itdev->pio[unit]);
224 }
225}
226
227/**
228 * it821x_ratemask - Compute available modes
229 * @drive: IDE drive
230 *
231 * Compute the available speeds for the devices on the interface. This
232 * is all modes to ATA133 clipped by drive cable setup.
233 */
234
235static u8 it821x_ratemask (ide_drive_t *drive)
236{
237 u8 mode = 4;
238 if (!eighty_ninty_three(drive))
239 mode = min(mode, (u8)1);
240 return mode;
241}
242
243/**
244 * it821x_tuneproc - tune a drive
245 * @drive: drive to tune
246 * @mode_wanted: the target operating mode
247 *
248 * Load the timing settings for this device mode into the
249 * controller. By the time we are called the mode has been
250 * modified as neccessary to handle the absence of seperate
251 * master/slave timers for MWDMA/PIO.
252 *
253 * This code is only used in pass through mode.
254 */
255
256static void it821x_tuneproc (ide_drive_t *drive, byte mode_wanted)
257{
258 ide_hwif_t *hwif = drive->hwif;
259 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
260 int unit = drive->select.b.unit;
261
262 /* Spec says 89 ref driver uses 88 */
263 static u16 pio[] = { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 };
264 static u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY };
265
266 if(itdev->smart)
267 return;
268
269 /* We prefer 66Mhz clock for PIO 0-3, don't care for PIO4 */
270 itdev->want[unit][1] = pio_want[mode_wanted];
271 itdev->want[unit][0] = 1; /* PIO is lowest priority */
272 itdev->pio[unit] = pio[mode_wanted];
273 it821x_clock_strategy(drive);
274 it821x_program(drive, itdev->pio[unit]);
275}
276
277/**
278 * it821x_tune_mwdma - tune a channel for MWDMA
279 * @drive: drive to set up
280 * @mode_wanted: the target operating mode
281 *
282 * Load the timing settings for this device mode into the
283 * controller when doing MWDMA in pass through mode. The caller
284 * must manage the whole lack of per device MWDMA/PIO timings and
285 * the shared MWDMA/PIO timing register.
286 */
287
288static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
289{
290 ide_hwif_t *hwif = drive->hwif;
291 struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif);
292 int unit = drive->select.b.unit;
293 int channel = hwif->channel;
294 u8 conf;
295
296 static u16 dma[] = { 0x8866, 0x3222, 0x3121 };
297 static u8 mwdma_want[] = { ATA_ANY, ATA_66, ATA_ANY };
298
299 itdev->want[unit][1] = mwdma_want[mode_wanted];
300 itdev->want[unit][0] = 2; /* MWDMA is low priority */
301 itdev->mwdma[unit] = dma[mode_wanted];
302 itdev->udma[unit] = UDMA_OFF;
303
304 /* UDMA bits off - Revision 0x10 do them in pairs */
305 pci_read_config_byte(hwif->pci_dev, 0x50, &conf);
306 if(itdev->timing10)
307 conf |= channel ? 0x60: 0x18;
308 else
309 conf |= 1 << (3 + 2 * channel + unit);
310 pci_write_config_byte(hwif->pci_dev, 0x50, conf);
311
312 it821x_clock_strategy(drive);
313 /* FIXME: do we need to program this ? */
314 /* it821x_program(drive, itdev->mwdma[unit]); */
315}
316
317/**
318 * it821x_tune_udma - tune a channel for UDMA
319 * @drive: drive to set up
320 * @mode_wanted: the target operating mode
321 *
322 * Load the timing settings for this device mode into the
323 * controller when doing UDMA modes in pass through.
324 */
325
326static void it821x_tune_udma (ide_drive_t *drive, byte mode_wanted)
327{
328 ide_hwif_t *hwif = drive->hwif;
329 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
330 int unit = drive->select.b.unit;
331 int channel = hwif->channel;
332 u8 conf;
333
334 static u16 udma[] = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 };
335 static u8 udma_want[] = { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 };
336
337 itdev->want[unit][1] = udma_want[mode_wanted];
338 itdev->want[unit][0] = 3; /* UDMA is high priority */
339 itdev->mwdma[unit] = MWDMA_OFF;
340 itdev->udma[unit] = udma[mode_wanted];
341 if(mode_wanted >= 5)
342 itdev->udma[unit] |= 0x8080; /* UDMA 5/6 select on */
343
344 /* UDMA on. Again revision 0x10 must do the pair */
345 pci_read_config_byte(hwif->pci_dev, 0x50, &conf);
346 if(itdev->timing10)
347 conf &= channel ? 0x9F: 0xE7;
348 else
349 conf &= ~ (1 << (3 + 2 * channel + unit));
350 pci_write_config_byte(hwif->pci_dev, 0x50, conf);
351
352 it821x_clock_strategy(drive);
353 it821x_program_udma(drive, itdev->udma[unit]);
354
355}
356
357/**
358 * config_it821x_chipset_for_pio - set drive timings
359 * @drive: drive to tune
360 * @speed we want
361 *
362 * Compute the best pio mode we can for a given device. We must
363 * pick a speed that does not cause problems with the other device
364 * on the cable.
365 */
366
367static void config_it821x_chipset_for_pio (ide_drive_t *drive, byte set_speed)
368{
369 u8 unit = drive->select.b.unit;
370 ide_hwif_t *hwif = drive->hwif;
371 ide_drive_t *pair = &hwif->drives[1-unit];
372 u8 speed = 0, set_pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
373 u8 pair_pio;
374
375 /* We have to deal with this mess in pairs */
376 if(pair != NULL) {
377 pair_pio = ide_get_best_pio_mode(pair, 255, 5, NULL);
378 /* Trim PIO to the slowest of the master/slave */
379 if(pair_pio < set_pio)
380 set_pio = pair_pio;
381 }
382 it821x_tuneproc(drive, set_pio);
383 speed = XFER_PIO_0 + set_pio;
384 /* XXX - We trim to the lowest of the pair so the other drive
385 will always be fine at this point until we do hotplug passthru */
386
387 if (set_speed)
388 (void) ide_config_drive_speed(drive, speed);
389}
390
391/**
392 * it821x_dma_read - DMA hook
393 * @drive: drive for DMA
394 *
395 * The IT821x has a single timing register for MWDMA and for PIO
396 * operations. As we flip back and forth we have to reload the
397 * clock. In addition the rev 0x10 device only works if the same
398 * timing value is loaded into the master and slave UDMA clock
399 * so we must also reload that.
400 *
401 * FIXME: we could figure out in advance if we need to do reloads
402 */
403
404static void it821x_dma_start(ide_drive_t *drive)
405{
406 ide_hwif_t *hwif = drive->hwif;
407 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
408 int unit = drive->select.b.unit;
409 if(itdev->mwdma[unit] != MWDMA_OFF)
410 it821x_program(drive, itdev->mwdma[unit]);
411 else if(itdev->udma[unit] != UDMA_OFF && itdev->timing10)
412 it821x_program_udma(drive, itdev->udma[unit]);
413 ide_dma_start(drive);
414}
415
416/**
417 * it821x_dma_write - DMA hook
418 * @drive: drive for DMA stop
419 *
420 * The IT821x has a single timing register for MWDMA and for PIO
421 * operations. As we flip back and forth we have to reload the
422 * clock.
423 */
424
425static int it821x_dma_end(ide_drive_t *drive)
426{
427 ide_hwif_t *hwif = drive->hwif;
428 int unit = drive->select.b.unit;
429 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
430 int ret = __ide_dma_end(drive);
431 if(itdev->mwdma[unit] != MWDMA_OFF)
432 it821x_program(drive, itdev->pio[unit]);
433 return ret;
434}
435
436
437/**
438 * it821x_tune_chipset - set controller timings
439 * @drive: Drive to set up
440 * @xferspeed: speed we want to achieve
441 *
442 * Tune the ITE chipset for the desired mode. If we can't achieve
443 * the desired mode then tune for a lower one, but ultimately
444 * make the thing work.
445 */
446
447static int it821x_tune_chipset (ide_drive_t *drive, byte xferspeed)
448{
449
450 ide_hwif_t *hwif = drive->hwif;
451 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
452 u8 speed = ide_rate_filter(it821x_ratemask(drive), xferspeed);
453
454 if(!itdev->smart) {
455 switch(speed) {
456 case XFER_PIO_4:
457 case XFER_PIO_3:
458 case XFER_PIO_2:
459 case XFER_PIO_1:
460 case XFER_PIO_0:
461 it821x_tuneproc(drive, (speed - XFER_PIO_0));
462 break;
463 /* MWDMA tuning is really hard because our MWDMA and PIO
464 timings are kept in the same place. We can switch in the
465 host dma on/off callbacks */
466 case XFER_MW_DMA_2:
467 case XFER_MW_DMA_1:
468 case XFER_MW_DMA_0:
469 it821x_tune_mwdma(drive, (speed - XFER_MW_DMA_0));
470 break;
471 case XFER_UDMA_6:
472 case XFER_UDMA_5:
473 case XFER_UDMA_4:
474 case XFER_UDMA_3:
475 case XFER_UDMA_2:
476 case XFER_UDMA_1:
477 case XFER_UDMA_0:
478 it821x_tune_udma(drive, (speed - XFER_UDMA_0));
479 break;
480 default:
481 return 1;
482 }
483 }
484 /*
485 * In smart mode the clocking is done by the host controller
486 * snooping the mode we picked. The rest of it is not our problem
487 */
488 return ide_config_drive_speed(drive, speed);
489}
490
491/**
492 * config_chipset_for_dma - configure for DMA
493 * @drive: drive to configure
494 *
495 * Called by the IDE layer when it wants the timings set up.
496 */
497
498static int config_chipset_for_dma (ide_drive_t *drive)
499{
500 u8 speed = ide_dma_speed(drive, it821x_ratemask(drive));
501
502 config_it821x_chipset_for_pio(drive, !speed);
503 it821x_tune_chipset(drive, speed);
504 return ide_dma_enable(drive);
505}
506
507/**
508 * it821x_configure_drive_for_dma - set up for DMA transfers
509 * @drive: drive we are going to set up
510 *
511 * Set up the drive for DMA, tune the controller and drive as
512 * required. If the drive isn't suitable for DMA or we hit
513 * other problems then we will drop down to PIO and set up
514 * PIO appropriately
515 */
516
517static int it821x_config_drive_for_dma (ide_drive_t *drive)
518{
519 ide_hwif_t *hwif = drive->hwif;
520
521 if (ide_use_dma(drive)) {
522 if (config_chipset_for_dma(drive))
523 return hwif->ide_dma_on(drive);
524 }
525 config_it821x_chipset_for_pio(drive, 1);
526 return hwif->ide_dma_off_quietly(drive);
527}
528
529/**
530 * ata66_it821x - check for 80 pin cable
531 * @hwif: interface to check
532 *
533 * Check for the presence of an ATA66 capable cable on the
534 * interface. Problematic as it seems some cards don't have
535 * the needed logic onboard.
536 */
537
538static unsigned int __devinit ata66_it821x(ide_hwif_t *hwif)
539{
540 /* The reference driver also only does disk side */
541 return 1;
542}
543
544/**
545 * it821x_fixup - post init callback
546 * @hwif: interface
547 *
548 * This callback is run after the drives have been probed but
549 * before anything gets attached. It allows drivers to do any
550 * final tuning that is needed, or fixups to work around bugs.
551 */
552
553static void __devinit it821x_fixups(ide_hwif_t *hwif)
554{
555 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
556 int i;
557
558 if(!itdev->smart) {
559 /*
560 * If we are in pass through mode then not much
561 * needs to be done, but we do bother to clear the
562 * IRQ mask as we may well be in PIO (eg rev 0x10)
563 * for now and we know unmasking is safe on this chipset.
564 */
565 for (i = 0; i < 2; i++) {
566 ide_drive_t *drive = &hwif->drives[i];
567 if(drive->present)
568 drive->unmask = 1;
569 }
570 return;
571 }
572 /*
573 * Perform fixups on smart mode. We need to "lose" some
574 * capabilities the firmware lacks but does not filter, and
575 * also patch up some capability bits that it forgets to set
576 * in RAID mode.
577 */
578
579 for(i = 0; i < 2; i++) {
580 ide_drive_t *drive = &hwif->drives[i];
581 struct hd_driveid *id;
582 u16 *idbits;
583
584 if(!drive->present)
585 continue;
586 id = drive->id;
587 idbits = (u16 *)drive->id;
588
589 /* Check for RAID v native */
590 if(strstr(id->model, "Integrated Technology Express")) {
591 /* In raid mode the ident block is slightly buggy
592 We need to set the bits so that the IDE layer knows
593 LBA28. LBA48 and DMA ar valid */
594 id->capability |= 3; /* LBA28, DMA */
595 id->command_set_2 |= 0x0400; /* LBA48 valid */
596 id->cfs_enable_2 |= 0x0400; /* LBA48 on */
597 /* Reporting logic */
598 printk(KERN_INFO "%s: IT8212 %sRAID %d volume",
599 drive->name,
600 idbits[147] ? "Bootable ":"",
601 idbits[129]);
602 if(idbits[129] != 1)
603 printk("(%dK stripe)", idbits[146]);
604 printk(".\n");
605 /* Now the core code will have wrongly decided no DMA
606 so we need to fix this */
607 hwif->ide_dma_off_quietly(drive);
608#ifdef CONFIG_IDEDMA_ONLYDISK
609 if (drive->media == ide_disk)
610#endif
611 hwif->ide_dma_check(drive);
612 } else {
613 /* Non RAID volume. Fixups to stop the core code
614 doing unsupported things */
615 id->field_valid &= 1;
616 id->queue_depth = 0;
617 id->command_set_1 = 0;
618 id->command_set_2 &= 0xC400;
619 id->cfsse &= 0xC000;
620 id->cfs_enable_1 = 0;
621 id->cfs_enable_2 &= 0xC400;
622 id->csf_default &= 0xC000;
623 id->word127 = 0;
624 id->dlf = 0;
625 id->csfo = 0;
626 id->cfa_power = 0;
627 printk(KERN_INFO "%s: Performing identify fixups.\n",
628 drive->name);
629 }
630 }
631
632}
633
634/**
635 * init_hwif_it821x - set up hwif structs
636 * @hwif: interface to set up
637 *
638 * We do the basic set up of the interface structure. The IT8212
639 * requires several custom handlers so we override the default
640 * ide DMA handlers appropriately
641 */
642
643static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
644{
645 struct it821x_dev *idev = kmalloc(sizeof(struct it821x_dev), GFP_KERNEL);
646 u8 conf;
647
648 if(idev == NULL) {
649 printk(KERN_ERR "it821x: out of memory, falling back to legacy behaviour.\n");
650 goto fallback;
651 }
652 memset(idev, 0, sizeof(struct it821x_dev));
653 ide_set_hwifdata(hwif, idev);
654
655 pci_read_config_byte(hwif->pci_dev, 0x50, &conf);
656 if(conf & 1) {
657 idev->smart = 1;
658 hwif->atapi_dma = 0;
659 /* Long I/O's although allowed in LBA48 space cause the
660 onboard firmware to enter the twighlight zone */
661 hwif->rqsize = 256;
662 }
663
664 /* Pull the current clocks from 0x50 also */
665 if (conf & (1 << (1 + hwif->channel)))
666 idev->clock_mode = ATA_50;
667 else
668 idev->clock_mode = ATA_66;
669
670 idev->want[0][1] = ATA_ANY;
671 idev->want[1][1] = ATA_ANY;
672
673 /*
674 * Not in the docs but according to the reference driver
675 * this is neccessary.
676 */
677
678 pci_read_config_byte(hwif->pci_dev, 0x08, &conf);
679 if(conf == 0x10) {
680 idev->timing10 = 1;
681 hwif->atapi_dma = 0;
682 if(!idev->smart)
683 printk(KERN_WARNING "it821x: Revision 0x10, workarounds activated.\n");
684 }
685
686 hwif->speedproc = &it821x_tune_chipset;
687 hwif->tuneproc = &it821x_tuneproc;
688
689 /* MWDMA/PIO clock switching for pass through mode */
690 if(!idev->smart) {
691 hwif->dma_start = &it821x_dma_start;
692 hwif->ide_dma_end = &it821x_dma_end;
693 }
694
695 hwif->drives[0].autotune = 1;
696 hwif->drives[1].autotune = 1;
697
698 if (!hwif->dma_base)
699 goto fallback;
700
701 hwif->ultra_mask = 0x7f;
702 hwif->mwdma_mask = 0x07;
703 hwif->swdma_mask = 0x07;
704
705 hwif->ide_dma_check = &it821x_config_drive_for_dma;
706 if (!(hwif->udma_four))
707 hwif->udma_four = ata66_it821x(hwif);
708
709 /*
710 * The BIOS often doesn't set up DMA on this controller
711 * so we always do it.
712 */
713
714 hwif->autodma = 1;
715 hwif->drives[0].autodma = hwif->autodma;
716 hwif->drives[1].autodma = hwif->autodma;
717 return;
718fallback:
719 hwif->autodma = 0;
720 return;
721}
722
723static void __devinit it8212_disable_raid(struct pci_dev *dev)
724{
725 /* Reset local CPU, and set BIOS not ready */
726 pci_write_config_byte(dev, 0x5E, 0x01);
727
728 /* Set to bypass mode, and reset PCI bus */
729 pci_write_config_byte(dev, 0x50, 0x00);
730 pci_write_config_word(dev, PCI_COMMAND,
731 PCI_COMMAND_PARITY | PCI_COMMAND_IO |
732 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
733 pci_write_config_word(dev, 0x40, 0xA0F3);
734
735 pci_write_config_dword(dev,0x4C, 0x02040204);
736 pci_write_config_byte(dev, 0x42, 0x36);
737 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0);
738}
739
740static unsigned int __devinit init_chipset_it821x(struct pci_dev *dev, const char *name)
741{
742 u8 conf;
743 static char *mode[2] = { "pass through", "smart" };
744
745 /* Force the card into bypass mode if so requested */
746 if (it8212_noraid) {
747 printk(KERN_INFO "it8212: forcing bypass mode.\n");
748 it8212_disable_raid(dev);
749 }
750 pci_read_config_byte(dev, 0x50, &conf);
751 printk(KERN_INFO "it821x: controller in %s mode.\n", mode[conf & 1]);
752 return 0;
753}
754
755
756#define DECLARE_ITE_DEV(name_str) \
757 { \
758 .name = name_str, \
759 .init_chipset = init_chipset_it821x, \
760 .init_hwif = init_hwif_it821x, \
761 .channels = 2, \
762 .autodma = AUTODMA, \
763 .bootable = ON_BOARD, \
764 .fixup = it821x_fixups \
765 }
766
767static ide_pci_device_t it821x_chipsets[] __devinitdata = {
768 /* 0 */ DECLARE_ITE_DEV("IT8212"),
769};
770
771/**
772 * it821x_init_one - pci layer discovery entry
773 * @dev: PCI device
774 * @id: ident table entry
775 *
776 * Called by the PCI code when it finds an ITE821x controller.
777 * We then use the IDE PCI generic helper to do most of the work.
778 */
779
780static int __devinit it821x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
781{
782 ide_setup_pci_device(dev, &it821x_chipsets[id->driver_data]);
783 return 0;
784}
785
786static struct pci_device_id it821x_pci_tbl[] = {
787 { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
788 { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8212, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
789 { 0, },
790};
791
792MODULE_DEVICE_TABLE(pci, it821x_pci_tbl);
793
794static struct pci_driver driver = {
795 .name = "ITE821x IDE",
796 .id_table = it821x_pci_tbl,
797 .probe = it821x_init_one,
798};
799
800static int __init it821x_ide_init(void)
801{
802 return ide_pci_register_driver(&driver);
803}
804
805module_init(it821x_ide_init);
806
807module_param_named(noraid, it8212_noraid, int, S_IRUGO);
808MODULE_PARM_DESC(it8212_noraid, "Force card into bypass mode");
809
810MODULE_AUTHOR("Alan Cox");
811MODULE_DESCRIPTION("PCI driver module for the ITE 821x");
812MODULE_LICENSE("GPL");
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index 82a1103b2413..c6f5fa4b4ca6 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -442,7 +442,7 @@ static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const cha
442 return (dev->irq) ? dev->irq : 0; 442 return (dev->irq) ? dev->irq : 0;
443} 443}
444 444
445static unsigned int __init ata66_svwks_svwks (ide_hwif_t *hwif) 445static unsigned int __devinit ata66_svwks_svwks (ide_hwif_t *hwif)
446{ 446{
447 return 1; 447 return 1;
448} 448}
@@ -454,7 +454,7 @@ static unsigned int __init ata66_svwks_svwks (ide_hwif_t *hwif)
454 * Bit 14 clear = primary IDE channel does not have 80-pin cable. 454 * Bit 14 clear = primary IDE channel does not have 80-pin cable.
455 * Bit 14 set = primary IDE channel has 80-pin cable. 455 * Bit 14 set = primary IDE channel has 80-pin cable.
456 */ 456 */
457static unsigned int __init ata66_svwks_dell (ide_hwif_t *hwif) 457static unsigned int __devinit ata66_svwks_dell (ide_hwif_t *hwif)
458{ 458{
459 struct pci_dev *dev = hwif->pci_dev; 459 struct pci_dev *dev = hwif->pci_dev;
460 if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL && 460 if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
@@ -472,7 +472,7 @@ static unsigned int __init ata66_svwks_dell (ide_hwif_t *hwif)
472 * 472 *
473 * WARNING: this only works on Alpine hardware! 473 * WARNING: this only works on Alpine hardware!
474 */ 474 */
475static unsigned int __init ata66_svwks_cobalt (ide_hwif_t *hwif) 475static unsigned int __devinit ata66_svwks_cobalt (ide_hwif_t *hwif)
476{ 476{
477 struct pci_dev *dev = hwif->pci_dev; 477 struct pci_dev *dev = hwif->pci_dev;
478 if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN && 478 if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN &&
@@ -483,7 +483,7 @@ static unsigned int __init ata66_svwks_cobalt (ide_hwif_t *hwif)
483 return 0; 483 return 0;
484} 484}
485 485
486static unsigned int __init ata66_svwks (ide_hwif_t *hwif) 486static unsigned int __devinit ata66_svwks (ide_hwif_t *hwif)
487{ 487{
488 struct pci_dev *dev = hwif->pci_dev; 488 struct pci_dev *dev = hwif->pci_dev;
489 489
@@ -573,7 +573,7 @@ static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d)
573 return ide_setup_pci_device(dev, d); 573 return ide_setup_pci_device(dev, d);
574} 574}
575 575
576static int __init init_setup_csb6 (struct pci_dev *dev, ide_pci_device_t *d) 576static int __devinit init_setup_csb6 (struct pci_dev *dev, ide_pci_device_t *d)
577{ 577{
578 if (!(PCI_FUNC(dev->devfn) & 1)) { 578 if (!(PCI_FUNC(dev->devfn) & 1)) {
579 d->bootable = NEVER_BOARD; 579 d->bootable = NEVER_BOARD;
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index 569f16767442..818380b5fd27 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -1324,9 +1324,9 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1324 /* XXX FIXME: Media bay stuff need re-organizing */ 1324 /* XXX FIXME: Media bay stuff need re-organizing */
1325 if (np->parent && np->parent->name 1325 if (np->parent && np->parent->name
1326 && strcasecmp(np->parent->name, "media-bay") == 0) { 1326 && strcasecmp(np->parent->name, "media-bay") == 0) {
1327#ifdef CONFIG_PMAC_PBOOK 1327#ifdef CONFIG_PMAC_MEDIABAY
1328 media_bay_set_ide_infos(np->parent, pmif->regbase, pmif->irq, hwif->index); 1328 media_bay_set_ide_infos(np->parent, pmif->regbase, pmif->irq, hwif->index);
1329#endif /* CONFIG_PMAC_PBOOK */ 1329#endif /* CONFIG_PMAC_MEDIABAY */
1330 pmif->mediabay = 1; 1330 pmif->mediabay = 1;
1331 if (!bidp) 1331 if (!bidp)
1332 pmif->aapl_bus_id = 1; 1332 pmif->aapl_bus_id = 1;
@@ -1382,10 +1382,10 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1382 hwif->index, model_name[pmif->kind], pmif->aapl_bus_id, 1382 hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
1383 pmif->mediabay ? " (mediabay)" : "", hwif->irq); 1383 pmif->mediabay ? " (mediabay)" : "", hwif->irq);
1384 1384
1385#ifdef CONFIG_PMAC_PBOOK 1385#ifdef CONFIG_PMAC_MEDIABAY
1386 if (pmif->mediabay && check_media_bay_by_base(pmif->regbase, MB_CD) == 0) 1386 if (pmif->mediabay && check_media_bay_by_base(pmif->regbase, MB_CD) == 0)
1387 hwif->noprobe = 0; 1387 hwif->noprobe = 0;
1388#endif /* CONFIG_PMAC_PBOOK */ 1388#endif /* CONFIG_PMAC_MEDIABAY */
1389 1389
1390 hwif->sg_max_nents = MAX_DCMDS; 1390 hwif->sg_max_nents = MAX_DCMDS;
1391 1391
diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
index 36e25ac823dc..b3d3d22fde64 100644
--- a/drivers/ieee1394/ohci1394.c
+++ b/drivers/ieee1394/ohci1394.c
@@ -3538,8 +3538,8 @@ static void ohci1394_pci_remove(struct pci_dev *pdev)
3538 3538
3539static int ohci1394_pci_resume (struct pci_dev *pdev) 3539static int ohci1394_pci_resume (struct pci_dev *pdev)
3540{ 3540{
3541#ifdef CONFIG_PMAC_PBOOK 3541#ifdef CONFIG_PPC_PMAC
3542 { 3542 if (_machine == _MACH_Pmac) {
3543 struct device_node *of_node; 3543 struct device_node *of_node;
3544 3544
3545 /* Re-enable 1394 */ 3545 /* Re-enable 1394 */
@@ -3547,7 +3547,7 @@ static int ohci1394_pci_resume (struct pci_dev *pdev)
3547 if (of_node) 3547 if (of_node)
3548 pmac_call_feature (PMAC_FTR_1394_ENABLE, of_node, 0, 1); 3548 pmac_call_feature (PMAC_FTR_1394_ENABLE, of_node, 0, 1);
3549 } 3549 }
3550#endif 3550#endif /* CONFIG_PPC_PMAC */
3551 3551
3552 pci_enable_device(pdev); 3552 pci_enable_device(pdev);
3553 3553
@@ -3557,8 +3557,8 @@ static int ohci1394_pci_resume (struct pci_dev *pdev)
3557 3557
3558static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) 3558static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state)
3559{ 3559{
3560#ifdef CONFIG_PMAC_PBOOK 3560#ifdef CONFIG_PPC_PMAC
3561 { 3561 if (_machine == _MACH_Pmac) {
3562 struct device_node *of_node; 3562 struct device_node *of_node;
3563 3563
3564 /* Disable 1394 */ 3564 /* Disable 1394 */
diff --git a/drivers/infiniband/core/packer.c b/drivers/infiniband/core/packer.c
index 5f15feffeae2..eb5ff54c10d7 100644
--- a/drivers/infiniband/core/packer.c
+++ b/drivers/infiniband/core/packer.c
@@ -96,7 +96,7 @@ void ib_pack(const struct ib_field *desc,
96 else 96 else
97 val = 0; 97 val = 0;
98 98
99 mask = cpu_to_be64(((1ull << desc[i].size_bits) - 1) << shift); 99 mask = cpu_to_be64((~0ull >> (64 - desc[i].size_bits)) << shift);
100 addr = (__be64 *) ((__be32 *) buf + desc[i].offset_words); 100 addr = (__be64 *) ((__be32 *) buf + desc[i].offset_words);
101 *addr = (*addr & ~mask) | (cpu_to_be64(val) & mask); 101 *addr = (*addr & ~mask) | (cpu_to_be64(val) & mask);
102 } else { 102 } else {
@@ -176,7 +176,7 @@ void ib_unpack(const struct ib_field *desc,
176 __be64 *addr; 176 __be64 *addr;
177 177
178 shift = 64 - desc[i].offset_bits - desc[i].size_bits; 178 shift = 64 - desc[i].offset_bits - desc[i].size_bits;
179 mask = ((1ull << desc[i].size_bits) - 1) << shift; 179 mask = (~0ull >> (64 - desc[i].size_bits)) << shift;
180 addr = (__be64 *) buf + desc[i].offset_words; 180 addr = (__be64 *) buf + desc[i].offset_words;
181 val = (be64_to_cpup(addr) & mask) >> shift; 181 val = (be64_to_cpup(addr) & mask) >> shift;
182 value_write(desc[i].struct_offset_bytes, 182 value_write(desc[i].struct_offset_bytes,
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index 276e1a53010d..5a08e81fa827 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -507,7 +507,13 @@ retry:
507 spin_unlock_irqrestore(&idr_lock, flags); 507 spin_unlock_irqrestore(&idr_lock, flags);
508 } 508 }
509 509
510 return ret; 510 /*
511 * It's not safe to dereference query any more, because the
512 * send may already have completed and freed the query in
513 * another context. So use wr.wr_id, which has a copy of the
514 * query's id.
515 */
516 return ret ? ret : wr.wr_id;
511} 517}
512 518
513static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query, 519static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query,
@@ -598,14 +604,15 @@ int ib_sa_path_rec_get(struct ib_device *device, u8 port_num,
598 rec, query->sa_query.mad->data); 604 rec, query->sa_query.mad->data);
599 605
600 *sa_query = &query->sa_query; 606 *sa_query = &query->sa_query;
607
601 ret = send_mad(&query->sa_query, timeout_ms); 608 ret = send_mad(&query->sa_query, timeout_ms);
602 if (ret) { 609 if (ret < 0) {
603 *sa_query = NULL; 610 *sa_query = NULL;
604 kfree(query->sa_query.mad); 611 kfree(query->sa_query.mad);
605 kfree(query); 612 kfree(query);
606 } 613 }
607 614
608 return ret ? ret : query->sa_query.id; 615 return ret;
609} 616}
610EXPORT_SYMBOL(ib_sa_path_rec_get); 617EXPORT_SYMBOL(ib_sa_path_rec_get);
611 618
@@ -674,14 +681,15 @@ int ib_sa_mcmember_rec_query(struct ib_device *device, u8 port_num,
674 rec, query->sa_query.mad->data); 681 rec, query->sa_query.mad->data);
675 682
676 *sa_query = &query->sa_query; 683 *sa_query = &query->sa_query;
684
677 ret = send_mad(&query->sa_query, timeout_ms); 685 ret = send_mad(&query->sa_query, timeout_ms);
678 if (ret) { 686 if (ret < 0) {
679 *sa_query = NULL; 687 *sa_query = NULL;
680 kfree(query->sa_query.mad); 688 kfree(query->sa_query.mad);
681 kfree(query); 689 kfree(query);
682 } 690 }
683 691
684 return ret ? ret : query->sa_query.id; 692 return ret;
685} 693}
686EXPORT_SYMBOL(ib_sa_mcmember_rec_query); 694EXPORT_SYMBOL(ib_sa_mcmember_rec_query);
687 695
diff --git a/drivers/infiniband/hw/mthca/mthca_av.c b/drivers/infiniband/hw/mthca/mthca_av.c
index 085baf393ca4..d58dcbe66488 100644
--- a/drivers/infiniband/hw/mthca/mthca_av.c
+++ b/drivers/infiniband/hw/mthca/mthca_av.c
@@ -1,5 +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 Sun Microsystems, Inc. All rights reserved.
3 * 4 *
4 * 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
5 * 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
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
index cd9ed958d92f..1557a522d831 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
@@ -431,6 +431,36 @@ static int mthca_cmd_imm(struct mthca_dev *dev,
431 timeout, status); 431 timeout, status);
432} 432}
433 433
434int mthca_cmd_init(struct mthca_dev *dev)
435{
436 sema_init(&dev->cmd.hcr_sem, 1);
437 sema_init(&dev->cmd.poll_sem, 1);
438 dev->cmd.use_events = 0;
439
440 dev->hcr = ioremap(pci_resource_start(dev->pdev, 0) + MTHCA_HCR_BASE,
441 MTHCA_HCR_SIZE);
442 if (!dev->hcr) {
443 mthca_err(dev, "Couldn't map command register.");
444 return -ENOMEM;
445 }
446
447 dev->cmd.pool = pci_pool_create("mthca_cmd", dev->pdev,
448 MTHCA_MAILBOX_SIZE,
449 MTHCA_MAILBOX_SIZE, 0);
450 if (!dev->cmd.pool) {
451 iounmap(dev->hcr);
452 return -ENOMEM;
453 }
454
455 return 0;
456}
457
458void mthca_cmd_cleanup(struct mthca_dev *dev)
459{
460 pci_pool_destroy(dev->cmd.pool);
461 iounmap(dev->hcr);
462}
463
434/* 464/*
435 * Switch to using events to issue FW commands (should be called after 465 * Switch to using events to issue FW commands (should be called after
436 * event queue to command events has been initialized). 466 * event queue to command events has been initialized).
@@ -489,6 +519,33 @@ void mthca_cmd_use_polling(struct mthca_dev *dev)
489 up(&dev->cmd.poll_sem); 519 up(&dev->cmd.poll_sem);
490} 520}
491 521
522struct mthca_mailbox *mthca_alloc_mailbox(struct mthca_dev *dev,
523 unsigned int gfp_mask)
524{
525 struct mthca_mailbox *mailbox;
526
527 mailbox = kmalloc(sizeof *mailbox, gfp_mask);
528 if (!mailbox)
529 return ERR_PTR(-ENOMEM);
530
531 mailbox->buf = pci_pool_alloc(dev->cmd.pool, gfp_mask, &mailbox->dma);
532 if (!mailbox->buf) {
533 kfree(mailbox);
534 return ERR_PTR(-ENOMEM);
535 }
536
537 return mailbox;
538}
539
540void mthca_free_mailbox(struct mthca_dev *dev, struct mthca_mailbox *mailbox)
541{
542 if (!mailbox)
543 return;
544
545 pci_pool_free(dev->cmd.pool, mailbox->buf, mailbox->dma);
546 kfree(mailbox);
547}
548
492int mthca_SYS_EN(struct mthca_dev *dev, u8 *status) 549int mthca_SYS_EN(struct mthca_dev *dev, u8 *status)
493{ 550{
494 u64 out; 551 u64 out;
@@ -513,20 +570,20 @@ int mthca_SYS_DIS(struct mthca_dev *dev, u8 *status)
513static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm, 570static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm,
514 u64 virt, u8 *status) 571 u64 virt, u8 *status)
515{ 572{
516 u32 *inbox; 573 struct mthca_mailbox *mailbox;
517 dma_addr_t indma;
518 struct mthca_icm_iter iter; 574 struct mthca_icm_iter iter;
575 __be64 *pages;
519 int lg; 576 int lg;
520 int nent = 0; 577 int nent = 0;
521 int i; 578 int i;
522 int err = 0; 579 int err = 0;
523 int ts = 0, tc = 0; 580 int ts = 0, tc = 0;
524 581
525 inbox = pci_alloc_consistent(dev->pdev, PAGE_SIZE, &indma); 582 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
526 if (!inbox) 583 if (IS_ERR(mailbox))
527 return -ENOMEM; 584 return PTR_ERR(mailbox);
528 585 memset(mailbox->buf, 0, MTHCA_MAILBOX_SIZE);
529 memset(inbox, 0, PAGE_SIZE); 586 pages = mailbox->buf;
530 587
531 for (mthca_icm_first(icm, &iter); 588 for (mthca_icm_first(icm, &iter);
532 !mthca_icm_last(&iter); 589 !mthca_icm_last(&iter);
@@ -546,19 +603,17 @@ static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm,
546 } 603 }
547 for (i = 0; i < mthca_icm_size(&iter) / (1 << lg); ++i, ++nent) { 604 for (i = 0; i < mthca_icm_size(&iter) / (1 << lg); ++i, ++nent) {
548 if (virt != -1) { 605 if (virt != -1) {
549 *((__be64 *) (inbox + nent * 4)) = 606 pages[nent * 2] = cpu_to_be64(virt);
550 cpu_to_be64(virt);
551 virt += 1 << lg; 607 virt += 1 << lg;
552 } 608 }
553 609
554 *((__be64 *) (inbox + nent * 4 + 2)) = 610 pages[nent * 2 + 1] = cpu_to_be64((mthca_icm_addr(&iter) +
555 cpu_to_be64((mthca_icm_addr(&iter) + 611 (i << lg)) | (lg - 12));
556 (i << lg)) | (lg - 12));
557 ts += 1 << (lg - 10); 612 ts += 1 << (lg - 10);
558 ++tc; 613 ++tc;
559 614
560 if (nent == PAGE_SIZE / 16) { 615 if (nent == MTHCA_MAILBOX_SIZE / 16) {
561 err = mthca_cmd(dev, indma, nent, 0, op, 616 err = mthca_cmd(dev, mailbox->dma, nent, 0, op,
562 CMD_TIME_CLASS_B, status); 617 CMD_TIME_CLASS_B, status);
563 if (err || *status) 618 if (err || *status)
564 goto out; 619 goto out;
@@ -568,7 +623,7 @@ static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm,
568 } 623 }
569 624
570 if (nent) 625 if (nent)
571 err = mthca_cmd(dev, indma, nent, 0, op, 626 err = mthca_cmd(dev, mailbox->dma, nent, 0, op,
572 CMD_TIME_CLASS_B, status); 627 CMD_TIME_CLASS_B, status);
573 628
574 switch (op) { 629 switch (op) {
@@ -585,7 +640,7 @@ static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm,
585 } 640 }
586 641
587out: 642out:
588 pci_free_consistent(dev->pdev, PAGE_SIZE, inbox, indma); 643 mthca_free_mailbox(dev, mailbox);
589 return err; 644 return err;
590} 645}
591 646
@@ -606,8 +661,8 @@ int mthca_RUN_FW(struct mthca_dev *dev, u8 *status)
606 661
607int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status) 662int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
608{ 663{
664 struct mthca_mailbox *mailbox;
609 u32 *outbox; 665 u32 *outbox;
610 dma_addr_t outdma;
611 int err = 0; 666 int err = 0;
612 u8 lg; 667 u8 lg;
613 668
@@ -625,12 +680,12 @@ int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
625#define QUERY_FW_EQ_ARM_BASE_OFFSET 0x40 680#define QUERY_FW_EQ_ARM_BASE_OFFSET 0x40
626#define QUERY_FW_EQ_SET_CI_BASE_OFFSET 0x48 681#define QUERY_FW_EQ_SET_CI_BASE_OFFSET 0x48
627 682
628 outbox = pci_alloc_consistent(dev->pdev, QUERY_FW_OUT_SIZE, &outdma); 683 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
629 if (!outbox) { 684 if (IS_ERR(mailbox))
630 return -ENOMEM; 685 return PTR_ERR(mailbox);
631 } 686 outbox = mailbox->buf;
632 687
633 err = mthca_cmd_box(dev, 0, outdma, 0, 0, CMD_QUERY_FW, 688 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_FW,
634 CMD_TIME_CLASS_A, status); 689 CMD_TIME_CLASS_A, status);
635 690
636 if (err) 691 if (err)
@@ -681,15 +736,15 @@ int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
681 } 736 }
682 737
683out: 738out:
684 pci_free_consistent(dev->pdev, QUERY_FW_OUT_SIZE, outbox, outdma); 739 mthca_free_mailbox(dev, mailbox);
685 return err; 740 return err;
686} 741}
687 742
688int mthca_ENABLE_LAM(struct mthca_dev *dev, u8 *status) 743int mthca_ENABLE_LAM(struct mthca_dev *dev, u8 *status)
689{ 744{
745 struct mthca_mailbox *mailbox;
690 u8 info; 746 u8 info;
691 u32 *outbox; 747 u32 *outbox;
692 dma_addr_t outdma;
693 int err = 0; 748 int err = 0;
694 749
695#define ENABLE_LAM_OUT_SIZE 0x100 750#define ENABLE_LAM_OUT_SIZE 0x100
@@ -700,11 +755,12 @@ int mthca_ENABLE_LAM(struct mthca_dev *dev, u8 *status)
700#define ENABLE_LAM_INFO_HIDDEN_FLAG (1 << 4) 755#define ENABLE_LAM_INFO_HIDDEN_FLAG (1 << 4)
701#define ENABLE_LAM_INFO_ECC_MASK 0x3 756#define ENABLE_LAM_INFO_ECC_MASK 0x3
702 757
703 outbox = pci_alloc_consistent(dev->pdev, ENABLE_LAM_OUT_SIZE, &outdma); 758 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
704 if (!outbox) 759 if (IS_ERR(mailbox))
705 return -ENOMEM; 760 return PTR_ERR(mailbox);
761 outbox = mailbox->buf;
706 762
707 err = mthca_cmd_box(dev, 0, outdma, 0, 0, CMD_ENABLE_LAM, 763 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_ENABLE_LAM,
708 CMD_TIME_CLASS_C, status); 764 CMD_TIME_CLASS_C, status);
709 765
710 if (err) 766 if (err)
@@ -733,7 +789,7 @@ int mthca_ENABLE_LAM(struct mthca_dev *dev, u8 *status)
733 (unsigned long long) dev->ddr_end); 789 (unsigned long long) dev->ddr_end);
734 790
735out: 791out:
736 pci_free_consistent(dev->pdev, ENABLE_LAM_OUT_SIZE, outbox, outdma); 792 mthca_free_mailbox(dev, mailbox);
737 return err; 793 return err;
738} 794}
739 795
@@ -744,9 +800,9 @@ int mthca_DISABLE_LAM(struct mthca_dev *dev, u8 *status)
744 800
745int mthca_QUERY_DDR(struct mthca_dev *dev, u8 *status) 801int mthca_QUERY_DDR(struct mthca_dev *dev, u8 *status)
746{ 802{
803 struct mthca_mailbox *mailbox;
747 u8 info; 804 u8 info;
748 u32 *outbox; 805 u32 *outbox;
749 dma_addr_t outdma;
750 int err = 0; 806 int err = 0;
751 807
752#define QUERY_DDR_OUT_SIZE 0x100 808#define QUERY_DDR_OUT_SIZE 0x100
@@ -757,11 +813,12 @@ int mthca_QUERY_DDR(struct mthca_dev *dev, u8 *status)
757#define QUERY_DDR_INFO_HIDDEN_FLAG (1 << 4) 813#define QUERY_DDR_INFO_HIDDEN_FLAG (1 << 4)
758#define QUERY_DDR_INFO_ECC_MASK 0x3 814#define QUERY_DDR_INFO_ECC_MASK 0x3
759 815
760 outbox = pci_alloc_consistent(dev->pdev, QUERY_DDR_OUT_SIZE, &outdma); 816 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
761 if (!outbox) 817 if (IS_ERR(mailbox))
762 return -ENOMEM; 818 return PTR_ERR(mailbox);
819 outbox = mailbox->buf;
763 820
764 err = mthca_cmd_box(dev, 0, outdma, 0, 0, CMD_QUERY_DDR, 821 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_DDR,
765 CMD_TIME_CLASS_A, status); 822 CMD_TIME_CLASS_A, status);
766 823
767 if (err) 824 if (err)
@@ -787,15 +844,15 @@ int mthca_QUERY_DDR(struct mthca_dev *dev, u8 *status)
787 (unsigned long long) dev->ddr_end); 844 (unsigned long long) dev->ddr_end);
788 845
789out: 846out:
790 pci_free_consistent(dev->pdev, QUERY_DDR_OUT_SIZE, outbox, outdma); 847 mthca_free_mailbox(dev, mailbox);
791 return err; 848 return err;
792} 849}
793 850
794int mthca_QUERY_DEV_LIM(struct mthca_dev *dev, 851int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
795 struct mthca_dev_lim *dev_lim, u8 *status) 852 struct mthca_dev_lim *dev_lim, u8 *status)
796{ 853{
854 struct mthca_mailbox *mailbox;
797 u32 *outbox; 855 u32 *outbox;
798 dma_addr_t outdma;
799 u8 field; 856 u8 field;
800 u16 size; 857 u16 size;
801 int err; 858 int err;
@@ -860,11 +917,12 @@ int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
860#define QUERY_DEV_LIM_LAMR_OFFSET 0x9f 917#define QUERY_DEV_LIM_LAMR_OFFSET 0x9f
861#define QUERY_DEV_LIM_MAX_ICM_SZ_OFFSET 0xa0 918#define QUERY_DEV_LIM_MAX_ICM_SZ_OFFSET 0xa0
862 919
863 outbox = pci_alloc_consistent(dev->pdev, QUERY_DEV_LIM_OUT_SIZE, &outdma); 920 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
864 if (!outbox) 921 if (IS_ERR(mailbox))
865 return -ENOMEM; 922 return PTR_ERR(mailbox);
923 outbox = mailbox->buf;
866 924
867 err = mthca_cmd_box(dev, 0, outdma, 0, 0, CMD_QUERY_DEV_LIM, 925 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_DEV_LIM,
868 CMD_TIME_CLASS_A, status); 926 CMD_TIME_CLASS_A, status);
869 927
870 if (err) 928 if (err)
@@ -1020,15 +1078,15 @@ int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
1020 } 1078 }
1021 1079
1022out: 1080out:
1023 pci_free_consistent(dev->pdev, QUERY_DEV_LIM_OUT_SIZE, outbox, outdma); 1081 mthca_free_mailbox(dev, mailbox);
1024 return err; 1082 return err;
1025} 1083}
1026 1084
1027int mthca_QUERY_ADAPTER(struct mthca_dev *dev, 1085int mthca_QUERY_ADAPTER(struct mthca_dev *dev,
1028 struct mthca_adapter *adapter, u8 *status) 1086 struct mthca_adapter *adapter, u8 *status)
1029{ 1087{
1088 struct mthca_mailbox *mailbox;
1030 u32 *outbox; 1089 u32 *outbox;
1031 dma_addr_t outdma;
1032 int err; 1090 int err;
1033 1091
1034#define QUERY_ADAPTER_OUT_SIZE 0x100 1092#define QUERY_ADAPTER_OUT_SIZE 0x100
@@ -1037,23 +1095,24 @@ int mthca_QUERY_ADAPTER(struct mthca_dev *dev,
1037#define QUERY_ADAPTER_REVISION_ID_OFFSET 0x08 1095#define QUERY_ADAPTER_REVISION_ID_OFFSET 0x08
1038#define QUERY_ADAPTER_INTA_PIN_OFFSET 0x10 1096#define QUERY_ADAPTER_INTA_PIN_OFFSET 0x10
1039 1097
1040 outbox = pci_alloc_consistent(dev->pdev, QUERY_ADAPTER_OUT_SIZE, &outdma); 1098 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1041 if (!outbox) 1099 if (IS_ERR(mailbox))
1042 return -ENOMEM; 1100 return PTR_ERR(mailbox);
1101 outbox = mailbox->buf;
1043 1102
1044 err = mthca_cmd_box(dev, 0, outdma, 0, 0, CMD_QUERY_ADAPTER, 1103 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_ADAPTER,
1045 CMD_TIME_CLASS_A, status); 1104 CMD_TIME_CLASS_A, status);
1046 1105
1047 if (err) 1106 if (err)
1048 goto out; 1107 goto out;
1049 1108
1050 MTHCA_GET(adapter->vendor_id, outbox, QUERY_ADAPTER_VENDOR_ID_OFFSET); 1109 MTHCA_GET(adapter->vendor_id, outbox, QUERY_ADAPTER_VENDOR_ID_OFFSET);
1051 MTHCA_GET(adapter->device_id, outbox, QUERY_ADAPTER_DEVICE_ID_OFFSET); 1110 MTHCA_GET(adapter->device_id, outbox, QUERY_ADAPTER_DEVICE_ID_OFFSET);
1052 MTHCA_GET(adapter->revision_id, outbox, QUERY_ADAPTER_REVISION_ID_OFFSET); 1111 MTHCA_GET(adapter->revision_id, outbox, QUERY_ADAPTER_REVISION_ID_OFFSET);
1053 MTHCA_GET(adapter->inta_pin, outbox, QUERY_ADAPTER_INTA_PIN_OFFSET); 1112 MTHCA_GET(adapter->inta_pin, outbox, QUERY_ADAPTER_INTA_PIN_OFFSET);
1054 1113
1055out: 1114out:
1056 pci_free_consistent(dev->pdev, QUERY_DEV_LIM_OUT_SIZE, outbox, outdma); 1115 mthca_free_mailbox(dev, mailbox);
1057 return err; 1116 return err;
1058} 1117}
1059 1118
@@ -1061,8 +1120,8 @@ int mthca_INIT_HCA(struct mthca_dev *dev,
1061 struct mthca_init_hca_param *param, 1120 struct mthca_init_hca_param *param,
1062 u8 *status) 1121 u8 *status)
1063{ 1122{
1123 struct mthca_mailbox *mailbox;
1064 u32 *inbox; 1124 u32 *inbox;
1065 dma_addr_t indma;
1066 int err; 1125 int err;
1067 1126
1068#define INIT_HCA_IN_SIZE 0x200 1127#define INIT_HCA_IN_SIZE 0x200
@@ -1102,9 +1161,10 @@ int mthca_INIT_HCA(struct mthca_dev *dev,
1102#define INIT_HCA_UAR_SCATCH_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x10) 1161#define INIT_HCA_UAR_SCATCH_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x10)
1103#define INIT_HCA_UAR_CTX_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x18) 1162#define INIT_HCA_UAR_CTX_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x18)
1104 1163
1105 inbox = pci_alloc_consistent(dev->pdev, INIT_HCA_IN_SIZE, &indma); 1164 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1106 if (!inbox) 1165 if (IS_ERR(mailbox))
1107 return -ENOMEM; 1166 return PTR_ERR(mailbox);
1167 inbox = mailbox->buf;
1108 1168
1109 memset(inbox, 0, INIT_HCA_IN_SIZE); 1169 memset(inbox, 0, INIT_HCA_IN_SIZE);
1110 1170
@@ -1167,10 +1227,9 @@ int mthca_INIT_HCA(struct mthca_dev *dev,
1167 MTHCA_PUT(inbox, param->uarc_base, INIT_HCA_UAR_CTX_BASE_OFFSET); 1227 MTHCA_PUT(inbox, param->uarc_base, INIT_HCA_UAR_CTX_BASE_OFFSET);
1168 } 1228 }
1169 1229
1170 err = mthca_cmd(dev, indma, 0, 0, CMD_INIT_HCA, 1230 err = mthca_cmd(dev, mailbox->dma, 0, 0, CMD_INIT_HCA, HZ, status);
1171 HZ, status);
1172 1231
1173 pci_free_consistent(dev->pdev, INIT_HCA_IN_SIZE, inbox, indma); 1232 mthca_free_mailbox(dev, mailbox);
1174 return err; 1233 return err;
1175} 1234}
1176 1235
@@ -1178,8 +1237,8 @@ int mthca_INIT_IB(struct mthca_dev *dev,
1178 struct mthca_init_ib_param *param, 1237 struct mthca_init_ib_param *param,
1179 int port, u8 *status) 1238 int port, u8 *status)
1180{ 1239{
1240 struct mthca_mailbox *mailbox;
1181 u32 *inbox; 1241 u32 *inbox;
1182 dma_addr_t indma;
1183 int err; 1242 int err;
1184 u32 flags; 1243 u32 flags;
1185 1244
@@ -1199,9 +1258,10 @@ int mthca_INIT_IB(struct mthca_dev *dev,
1199#define INIT_IB_NODE_GUID_OFFSET 0x18 1258#define INIT_IB_NODE_GUID_OFFSET 0x18
1200#define INIT_IB_SI_GUID_OFFSET 0x20 1259#define INIT_IB_SI_GUID_OFFSET 0x20
1201 1260
1202 inbox = pci_alloc_consistent(dev->pdev, INIT_IB_IN_SIZE, &indma); 1261 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1203 if (!inbox) 1262 if (IS_ERR(mailbox))
1204 return -ENOMEM; 1263 return PTR_ERR(mailbox);
1264 inbox = mailbox->buf;
1205 1265
1206 memset(inbox, 0, INIT_IB_IN_SIZE); 1266 memset(inbox, 0, INIT_IB_IN_SIZE);
1207 1267
@@ -1221,10 +1281,10 @@ int mthca_INIT_IB(struct mthca_dev *dev,
1221 MTHCA_PUT(inbox, param->node_guid, INIT_IB_NODE_GUID_OFFSET); 1281 MTHCA_PUT(inbox, param->node_guid, INIT_IB_NODE_GUID_OFFSET);
1222 MTHCA_PUT(inbox, param->si_guid, INIT_IB_SI_GUID_OFFSET); 1282 MTHCA_PUT(inbox, param->si_guid, INIT_IB_SI_GUID_OFFSET);
1223 1283
1224 err = mthca_cmd(dev, indma, port, 0, CMD_INIT_IB, 1284 err = mthca_cmd(dev, mailbox->dma, port, 0, CMD_INIT_IB,
1225 CMD_TIME_CLASS_A, status); 1285 CMD_TIME_CLASS_A, status);
1226 1286
1227 pci_free_consistent(dev->pdev, INIT_HCA_IN_SIZE, inbox, indma); 1287 mthca_free_mailbox(dev, mailbox);
1228 return err; 1288 return err;
1229} 1289}
1230 1290
@@ -1241,8 +1301,8 @@ int mthca_CLOSE_HCA(struct mthca_dev *dev, int panic, u8 *status)
1241int mthca_SET_IB(struct mthca_dev *dev, struct mthca_set_ib_param *param, 1301int mthca_SET_IB(struct mthca_dev *dev, struct mthca_set_ib_param *param,
1242 int port, u8 *status) 1302 int port, u8 *status)
1243{ 1303{
1304 struct mthca_mailbox *mailbox;
1244 u32 *inbox; 1305 u32 *inbox;
1245 dma_addr_t indma;
1246 int err; 1306 int err;
1247 u32 flags = 0; 1307 u32 flags = 0;
1248 1308
@@ -1253,9 +1313,10 @@ int mthca_SET_IB(struct mthca_dev *dev, struct mthca_set_ib_param *param,
1253#define SET_IB_CAP_MASK_OFFSET 0x04 1313#define SET_IB_CAP_MASK_OFFSET 0x04
1254#define SET_IB_SI_GUID_OFFSET 0x08 1314#define SET_IB_SI_GUID_OFFSET 0x08
1255 1315
1256 inbox = pci_alloc_consistent(dev->pdev, SET_IB_IN_SIZE, &indma); 1316 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1257 if (!inbox) 1317 if (IS_ERR(mailbox))
1258 return -ENOMEM; 1318 return PTR_ERR(mailbox);
1319 inbox = mailbox->buf;
1259 1320
1260 memset(inbox, 0, SET_IB_IN_SIZE); 1321 memset(inbox, 0, SET_IB_IN_SIZE);
1261 1322
@@ -1266,10 +1327,10 @@ int mthca_SET_IB(struct mthca_dev *dev, struct mthca_set_ib_param *param,
1266 MTHCA_PUT(inbox, param->cap_mask, SET_IB_CAP_MASK_OFFSET); 1327 MTHCA_PUT(inbox, param->cap_mask, SET_IB_CAP_MASK_OFFSET);
1267 MTHCA_PUT(inbox, param->si_guid, SET_IB_SI_GUID_OFFSET); 1328 MTHCA_PUT(inbox, param->si_guid, SET_IB_SI_GUID_OFFSET);
1268 1329
1269 err = mthca_cmd(dev, indma, port, 0, CMD_SET_IB, 1330 err = mthca_cmd(dev, mailbox->dma, port, 0, CMD_SET_IB,
1270 CMD_TIME_CLASS_B, status); 1331 CMD_TIME_CLASS_B, status);
1271 1332
1272 pci_free_consistent(dev->pdev, INIT_HCA_IN_SIZE, inbox, indma); 1333 mthca_free_mailbox(dev, mailbox);
1273 return err; 1334 return err;
1274} 1335}
1275 1336
@@ -1280,20 +1341,22 @@ int mthca_MAP_ICM(struct mthca_dev *dev, struct mthca_icm *icm, u64 virt, u8 *st
1280 1341
1281int mthca_MAP_ICM_page(struct mthca_dev *dev, u64 dma_addr, u64 virt, u8 *status) 1342int mthca_MAP_ICM_page(struct mthca_dev *dev, u64 dma_addr, u64 virt, u8 *status)
1282{ 1343{
1344 struct mthca_mailbox *mailbox;
1283 u64 *inbox; 1345 u64 *inbox;
1284 dma_addr_t indma;
1285 int err; 1346 int err;
1286 1347
1287 inbox = pci_alloc_consistent(dev->pdev, 16, &indma); 1348 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1288 if (!inbox) 1349 if (IS_ERR(mailbox))
1289 return -ENOMEM; 1350 return PTR_ERR(mailbox);
1351 inbox = mailbox->buf;
1290 1352
1291 inbox[0] = cpu_to_be64(virt); 1353 inbox[0] = cpu_to_be64(virt);
1292 inbox[1] = cpu_to_be64(dma_addr); 1354 inbox[1] = cpu_to_be64(dma_addr);
1293 1355
1294 err = mthca_cmd(dev, indma, 1, 0, CMD_MAP_ICM, CMD_TIME_CLASS_B, status); 1356 err = mthca_cmd(dev, mailbox->dma, 1, 0, CMD_MAP_ICM,
1357 CMD_TIME_CLASS_B, status);
1295 1358
1296 pci_free_consistent(dev->pdev, 16, inbox, indma); 1359 mthca_free_mailbox(dev, mailbox);
1297 1360
1298 if (!err) 1361 if (!err)
1299 mthca_dbg(dev, "Mapped page at %llx to %llx for ICM.\n", 1362 mthca_dbg(dev, "Mapped page at %llx to %llx for ICM.\n",
@@ -1338,69 +1401,26 @@ int mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages,
1338 return 0; 1401 return 0;
1339} 1402}
1340 1403
1341int mthca_SW2HW_MPT(struct mthca_dev *dev, void *mpt_entry, 1404int mthca_SW2HW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1342 int mpt_index, u8 *status) 1405 int mpt_index, u8 *status)
1343{ 1406{
1344 dma_addr_t indma; 1407 return mthca_cmd(dev, mailbox->dma, mpt_index, 0, CMD_SW2HW_MPT,
1345 int err; 1408 CMD_TIME_CLASS_B, status);
1346
1347 indma = pci_map_single(dev->pdev, mpt_entry,
1348 MTHCA_MPT_ENTRY_SIZE,
1349 PCI_DMA_TODEVICE);
1350 if (pci_dma_mapping_error(indma))
1351 return -ENOMEM;
1352
1353 err = mthca_cmd(dev, indma, mpt_index, 0, CMD_SW2HW_MPT,
1354 CMD_TIME_CLASS_B, status);
1355
1356 pci_unmap_single(dev->pdev, indma,
1357 MTHCA_MPT_ENTRY_SIZE, PCI_DMA_TODEVICE);
1358 return err;
1359} 1409}
1360 1410
1361int mthca_HW2SW_MPT(struct mthca_dev *dev, void *mpt_entry, 1411int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1362 int mpt_index, u8 *status) 1412 int mpt_index, u8 *status)
1363{ 1413{
1364 dma_addr_t outdma = 0; 1414 return mthca_cmd_box(dev, 0, mailbox ? mailbox->dma : 0, mpt_index,
1365 int err; 1415 !mailbox, CMD_HW2SW_MPT,
1366 1416 CMD_TIME_CLASS_B, status);
1367 if (mpt_entry) {
1368 outdma = pci_map_single(dev->pdev, mpt_entry,
1369 MTHCA_MPT_ENTRY_SIZE,
1370 PCI_DMA_FROMDEVICE);
1371 if (pci_dma_mapping_error(outdma))
1372 return -ENOMEM;
1373 }
1374
1375 err = mthca_cmd_box(dev, 0, outdma, mpt_index, !mpt_entry,
1376 CMD_HW2SW_MPT,
1377 CMD_TIME_CLASS_B, status);
1378
1379 if (mpt_entry)
1380 pci_unmap_single(dev->pdev, outdma,
1381 MTHCA_MPT_ENTRY_SIZE,
1382 PCI_DMA_FROMDEVICE);
1383 return err;
1384} 1417}
1385 1418
1386int mthca_WRITE_MTT(struct mthca_dev *dev, u64 *mtt_entry, 1419int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1387 int num_mtt, u8 *status) 1420 int num_mtt, u8 *status)
1388{ 1421{
1389 dma_addr_t indma; 1422 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
1390 int err; 1423 CMD_TIME_CLASS_B, status);
1391
1392 indma = pci_map_single(dev->pdev, mtt_entry,
1393 (num_mtt + 2) * 8,
1394 PCI_DMA_TODEVICE);
1395 if (pci_dma_mapping_error(indma))
1396 return -ENOMEM;
1397
1398 err = mthca_cmd(dev, indma, num_mtt, 0, CMD_WRITE_MTT,
1399 CMD_TIME_CLASS_B, status);
1400
1401 pci_unmap_single(dev->pdev, indma,
1402 (num_mtt + 2) * 8, PCI_DMA_TODEVICE);
1403 return err;
1404} 1424}
1405 1425
1406int mthca_SYNC_TPT(struct mthca_dev *dev, u8 *status) 1426int mthca_SYNC_TPT(struct mthca_dev *dev, u8 *status)
@@ -1418,92 +1438,38 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
1418 0, CMD_MAP_EQ, CMD_TIME_CLASS_B, status); 1438 0, CMD_MAP_EQ, CMD_TIME_CLASS_B, status);
1419} 1439}
1420 1440
1421int mthca_SW2HW_EQ(struct mthca_dev *dev, void *eq_context, 1441int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1422 int eq_num, u8 *status) 1442 int eq_num, u8 *status)
1423{ 1443{
1424 dma_addr_t indma; 1444 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
1425 int err; 1445 CMD_TIME_CLASS_A, status);
1426
1427 indma = pci_map_single(dev->pdev, eq_context,
1428 MTHCA_EQ_CONTEXT_SIZE,
1429 PCI_DMA_TODEVICE);
1430 if (pci_dma_mapping_error(indma))
1431 return -ENOMEM;
1432
1433 err = mthca_cmd(dev, indma, eq_num, 0, CMD_SW2HW_EQ,
1434 CMD_TIME_CLASS_A, status);
1435
1436 pci_unmap_single(dev->pdev, indma,
1437 MTHCA_EQ_CONTEXT_SIZE, PCI_DMA_TODEVICE);
1438 return err;
1439} 1446}
1440 1447
1441int mthca_HW2SW_EQ(struct mthca_dev *dev, void *eq_context, 1448int mthca_HW2SW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1442 int eq_num, u8 *status) 1449 int eq_num, u8 *status)
1443{ 1450{
1444 dma_addr_t outdma = 0; 1451 return mthca_cmd_box(dev, 0, mailbox->dma, eq_num, 0,
1445 int err; 1452 CMD_HW2SW_EQ,
1446 1453 CMD_TIME_CLASS_A, status);
1447 outdma = pci_map_single(dev->pdev, eq_context,
1448 MTHCA_EQ_CONTEXT_SIZE,
1449 PCI_DMA_FROMDEVICE);
1450 if (pci_dma_mapping_error(outdma))
1451 return -ENOMEM;
1452
1453 err = mthca_cmd_box(dev, 0, outdma, eq_num, 0,
1454 CMD_HW2SW_EQ,
1455 CMD_TIME_CLASS_A, status);
1456
1457 pci_unmap_single(dev->pdev, outdma,
1458 MTHCA_EQ_CONTEXT_SIZE,
1459 PCI_DMA_FROMDEVICE);
1460 return err;
1461} 1454}
1462 1455
1463int mthca_SW2HW_CQ(struct mthca_dev *dev, void *cq_context, 1456int mthca_SW2HW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1464 int cq_num, u8 *status) 1457 int cq_num, u8 *status)
1465{ 1458{
1466 dma_addr_t indma; 1459 return mthca_cmd(dev, mailbox->dma, cq_num, 0, CMD_SW2HW_CQ,
1467 int err;
1468
1469 indma = pci_map_single(dev->pdev, cq_context,
1470 MTHCA_CQ_CONTEXT_SIZE,
1471 PCI_DMA_TODEVICE);
1472 if (pci_dma_mapping_error(indma))
1473 return -ENOMEM;
1474
1475 err = mthca_cmd(dev, indma, cq_num, 0, CMD_SW2HW_CQ,
1476 CMD_TIME_CLASS_A, status); 1460 CMD_TIME_CLASS_A, status);
1477
1478 pci_unmap_single(dev->pdev, indma,
1479 MTHCA_CQ_CONTEXT_SIZE, PCI_DMA_TODEVICE);
1480 return err;
1481} 1461}
1482 1462
1483int mthca_HW2SW_CQ(struct mthca_dev *dev, void *cq_context, 1463int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1484 int cq_num, u8 *status) 1464 int cq_num, u8 *status)
1485{ 1465{
1486 dma_addr_t outdma = 0; 1466 return mthca_cmd_box(dev, 0, mailbox->dma, cq_num, 0,
1487 int err; 1467 CMD_HW2SW_CQ,
1488 1468 CMD_TIME_CLASS_A, status);
1489 outdma = pci_map_single(dev->pdev, cq_context,
1490 MTHCA_CQ_CONTEXT_SIZE,
1491 PCI_DMA_FROMDEVICE);
1492 if (pci_dma_mapping_error(outdma))
1493 return -ENOMEM;
1494
1495 err = mthca_cmd_box(dev, 0, outdma, cq_num, 0,
1496 CMD_HW2SW_CQ,
1497 CMD_TIME_CLASS_A, status);
1498
1499 pci_unmap_single(dev->pdev, outdma,
1500 MTHCA_CQ_CONTEXT_SIZE,
1501 PCI_DMA_FROMDEVICE);
1502 return err;
1503} 1469}
1504 1470
1505int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num, 1471int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,
1506 int is_ee, void *qp_context, u32 optmask, 1472 int is_ee, struct mthca_mailbox *mailbox, u32 optmask,
1507 u8 *status) 1473 u8 *status)
1508{ 1474{
1509 static const u16 op[] = { 1475 static const u16 op[] = {
@@ -1520,36 +1486,34 @@ int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,
1520 [MTHCA_TRANS_ANY2RST] = CMD_ERR2RST_QPEE 1486 [MTHCA_TRANS_ANY2RST] = CMD_ERR2RST_QPEE
1521 }; 1487 };
1522 u8 op_mod = 0; 1488 u8 op_mod = 0;
1523 1489 int my_mailbox = 0;
1524 dma_addr_t indma;
1525 int err; 1490 int err;
1526 1491
1527 if (trans < 0 || trans >= ARRAY_SIZE(op)) 1492 if (trans < 0 || trans >= ARRAY_SIZE(op))
1528 return -EINVAL; 1493 return -EINVAL;
1529 1494
1530 if (trans == MTHCA_TRANS_ANY2RST) { 1495 if (trans == MTHCA_TRANS_ANY2RST) {
1531 indma = 0;
1532 op_mod = 3; /* don't write outbox, any->reset */ 1496 op_mod = 3; /* don't write outbox, any->reset */
1533 1497
1534 /* For debugging */ 1498 /* For debugging */
1535 qp_context = pci_alloc_consistent(dev->pdev, MTHCA_QP_CONTEXT_SIZE, 1499 if (!mailbox) {
1536 &indma); 1500 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1537 op_mod = 2; /* write outbox, any->reset */ 1501 if (!IS_ERR(mailbox)) {
1502 my_mailbox = 1;
1503 op_mod = 2; /* write outbox, any->reset */
1504 } else
1505 mailbox = NULL;
1506 }
1538 } else { 1507 } else {
1539 indma = pci_map_single(dev->pdev, qp_context,
1540 MTHCA_QP_CONTEXT_SIZE,
1541 PCI_DMA_TODEVICE);
1542 if (pci_dma_mapping_error(indma))
1543 return -ENOMEM;
1544
1545 if (0) { 1508 if (0) {
1546 int i; 1509 int i;
1547 mthca_dbg(dev, "Dumping QP context:\n"); 1510 mthca_dbg(dev, "Dumping QP context:\n");
1548 printk(" opt param mask: %08x\n", be32_to_cpup(qp_context)); 1511 printk(" opt param mask: %08x\n", be32_to_cpup(mailbox->buf));
1549 for (i = 0; i < 0x100 / 4; ++i) { 1512 for (i = 0; i < 0x100 / 4; ++i) {
1550 if (i % 8 == 0) 1513 if (i % 8 == 0)
1551 printk(" [%02x] ", i * 4); 1514 printk(" [%02x] ", i * 4);
1552 printk(" %08x", be32_to_cpu(((u32 *) qp_context)[i + 2])); 1515 printk(" %08x",
1516 be32_to_cpu(((u32 *) mailbox->buf)[i + 2]));
1553 if ((i + 1) % 8 == 0) 1517 if ((i + 1) % 8 == 0)
1554 printk("\n"); 1518 printk("\n");
1555 } 1519 }
@@ -1557,55 +1521,39 @@ int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,
1557 } 1521 }
1558 1522
1559 if (trans == MTHCA_TRANS_ANY2RST) { 1523 if (trans == MTHCA_TRANS_ANY2RST) {
1560 err = mthca_cmd_box(dev, 0, indma, (!!is_ee << 24) | num, 1524 err = mthca_cmd_box(dev, 0, mailbox ? mailbox->dma : 0,
1561 op_mod, op[trans], CMD_TIME_CLASS_C, status); 1525 (!!is_ee << 24) | num, op_mod,
1526 op[trans], CMD_TIME_CLASS_C, status);
1562 1527
1563 if (0) { 1528 if (0 && mailbox) {
1564 int i; 1529 int i;
1565 mthca_dbg(dev, "Dumping QP context:\n"); 1530 mthca_dbg(dev, "Dumping QP context:\n");
1566 printk(" %08x\n", be32_to_cpup(qp_context)); 1531 printk(" %08x\n", be32_to_cpup(mailbox->buf));
1567 for (i = 0; i < 0x100 / 4; ++i) { 1532 for (i = 0; i < 0x100 / 4; ++i) {
1568 if (i % 8 == 0) 1533 if (i % 8 == 0)
1569 printk("[%02x] ", i * 4); 1534 printk("[%02x] ", i * 4);
1570 printk(" %08x", be32_to_cpu(((u32 *) qp_context)[i + 2])); 1535 printk(" %08x",
1536 be32_to_cpu(((u32 *) mailbox->buf)[i + 2]));
1571 if ((i + 1) % 8 == 0) 1537 if ((i + 1) % 8 == 0)
1572 printk("\n"); 1538 printk("\n");
1573 } 1539 }
1574 } 1540 }
1575 1541
1576 } else 1542 } else
1577 err = mthca_cmd(dev, indma, (!!is_ee << 24) | num, 1543 err = mthca_cmd(dev, mailbox->dma, (!!is_ee << 24) | num,
1578 op_mod, op[trans], CMD_TIME_CLASS_C, status); 1544 op_mod, op[trans], CMD_TIME_CLASS_C, status);
1579 1545
1580 if (trans != MTHCA_TRANS_ANY2RST) 1546 if (my_mailbox)
1581 pci_unmap_single(dev->pdev, indma, 1547 mthca_free_mailbox(dev, mailbox);
1582 MTHCA_QP_CONTEXT_SIZE, PCI_DMA_TODEVICE); 1548
1583 else
1584 pci_free_consistent(dev->pdev, MTHCA_QP_CONTEXT_SIZE,
1585 qp_context, indma);
1586 return err; 1549 return err;
1587} 1550}
1588 1551
1589int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee, 1552int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee,
1590 void *qp_context, u8 *status) 1553 struct mthca_mailbox *mailbox, u8 *status)
1591{ 1554{
1592 dma_addr_t outdma = 0; 1555 return mthca_cmd_box(dev, 0, mailbox->dma, (!!is_ee << 24) | num, 0,
1593 int err; 1556 CMD_QUERY_QPEE, CMD_TIME_CLASS_A, status);
1594
1595 outdma = pci_map_single(dev->pdev, qp_context,
1596 MTHCA_QP_CONTEXT_SIZE,
1597 PCI_DMA_FROMDEVICE);
1598 if (pci_dma_mapping_error(outdma))
1599 return -ENOMEM;
1600
1601 err = mthca_cmd_box(dev, 0, outdma, (!!is_ee << 24) | num, 0,
1602 CMD_QUERY_QPEE,
1603 CMD_TIME_CLASS_A, status);
1604
1605 pci_unmap_single(dev->pdev, outdma,
1606 MTHCA_QP_CONTEXT_SIZE,
1607 PCI_DMA_FROMDEVICE);
1608 return err;
1609} 1557}
1610 1558
1611int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn, 1559int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn,
@@ -1635,11 +1583,11 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn,
1635} 1583}
1636 1584
1637int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey, 1585int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
1638 int port, struct ib_wc* in_wc, struct ib_grh* in_grh, 1586 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
1639 void *in_mad, void *response_mad, u8 *status) 1587 void *in_mad, void *response_mad, u8 *status)
1640{ 1588{
1641 void *box; 1589 struct mthca_mailbox *inmailbox, *outmailbox;
1642 dma_addr_t dma; 1590 void *inbox;
1643 int err; 1591 int err;
1644 u32 in_modifier = port; 1592 u32 in_modifier = port;
1645 u8 op_modifier = 0; 1593 u8 op_modifier = 0;
@@ -1653,11 +1601,18 @@ int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
1653#define MAD_IFC_PKEY_OFFSET 0x10e 1601#define MAD_IFC_PKEY_OFFSET 0x10e
1654#define MAD_IFC_GRH_OFFSET 0x140 1602#define MAD_IFC_GRH_OFFSET 0x140
1655 1603
1656 box = pci_alloc_consistent(dev->pdev, MAD_IFC_BOX_SIZE, &dma); 1604 inmailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1657 if (!box) 1605 if (IS_ERR(inmailbox))
1658 return -ENOMEM; 1606 return PTR_ERR(inmailbox);
1607 inbox = inmailbox->buf;
1659 1608
1660 memcpy(box, in_mad, 256); 1609 outmailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1610 if (IS_ERR(outmailbox)) {
1611 mthca_free_mailbox(dev, inmailbox);
1612 return PTR_ERR(outmailbox);
1613 }
1614
1615 memcpy(inbox, in_mad, 256);
1661 1616
1662 /* 1617 /*
1663 * Key check traps can't be generated unless we have in_wc to 1618 * Key check traps can't be generated unless we have in_wc to
@@ -1671,97 +1626,65 @@ int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
1671 if (in_wc) { 1626 if (in_wc) {
1672 u8 val; 1627 u8 val;
1673 1628
1674 memset(box + 256, 0, 256); 1629 memset(inbox + 256, 0, 256);
1675 1630
1676 MTHCA_PUT(box, in_wc->qp_num, MAD_IFC_MY_QPN_OFFSET); 1631 MTHCA_PUT(inbox, in_wc->qp_num, MAD_IFC_MY_QPN_OFFSET);
1677 MTHCA_PUT(box, in_wc->src_qp, MAD_IFC_RQPN_OFFSET); 1632 MTHCA_PUT(inbox, in_wc->src_qp, MAD_IFC_RQPN_OFFSET);
1678 1633
1679 val = in_wc->sl << 4; 1634 val = in_wc->sl << 4;
1680 MTHCA_PUT(box, val, MAD_IFC_SL_OFFSET); 1635 MTHCA_PUT(inbox, val, MAD_IFC_SL_OFFSET);
1681 1636
1682 val = in_wc->dlid_path_bits | 1637 val = in_wc->dlid_path_bits |
1683 (in_wc->wc_flags & IB_WC_GRH ? 0x80 : 0); 1638 (in_wc->wc_flags & IB_WC_GRH ? 0x80 : 0);
1684 MTHCA_PUT(box, val, MAD_IFC_GRH_OFFSET); 1639 MTHCA_PUT(inbox, val, MAD_IFC_GRH_OFFSET);
1685 1640
1686 MTHCA_PUT(box, in_wc->slid, MAD_IFC_RLID_OFFSET); 1641 MTHCA_PUT(inbox, in_wc->slid, MAD_IFC_RLID_OFFSET);
1687 MTHCA_PUT(box, in_wc->pkey_index, MAD_IFC_PKEY_OFFSET); 1642 MTHCA_PUT(inbox, in_wc->pkey_index, MAD_IFC_PKEY_OFFSET);
1688 1643
1689 if (in_grh) 1644 if (in_grh)
1690 memcpy((u8 *) box + MAD_IFC_GRH_OFFSET, in_grh, 40); 1645 memcpy(inbox + MAD_IFC_GRH_OFFSET, in_grh, 40);
1691 1646
1692 op_modifier |= 0x10; 1647 op_modifier |= 0x10;
1693 1648
1694 in_modifier |= in_wc->slid << 16; 1649 in_modifier |= in_wc->slid << 16;
1695 } 1650 }
1696 1651
1697 err = mthca_cmd_box(dev, dma, dma + 512, in_modifier, op_modifier, 1652 err = mthca_cmd_box(dev, inmailbox->dma, outmailbox->dma,
1653 in_modifier, op_modifier,
1698 CMD_MAD_IFC, CMD_TIME_CLASS_C, status); 1654 CMD_MAD_IFC, CMD_TIME_CLASS_C, status);
1699 1655
1700 if (!err && !*status) 1656 if (!err && !*status)
1701 memcpy(response_mad, box + 512, 256); 1657 memcpy(response_mad, outmailbox->buf, 256);
1702 1658
1703 pci_free_consistent(dev->pdev, MAD_IFC_BOX_SIZE, box, dma); 1659 mthca_free_mailbox(dev, inmailbox);
1660 mthca_free_mailbox(dev, outmailbox);
1704 return err; 1661 return err;
1705} 1662}
1706 1663
1707int mthca_READ_MGM(struct mthca_dev *dev, int index, void *mgm, 1664int mthca_READ_MGM(struct mthca_dev *dev, int index,
1708 u8 *status) 1665 struct mthca_mailbox *mailbox, u8 *status)
1709{ 1666{
1710 dma_addr_t outdma = 0; 1667 return mthca_cmd_box(dev, 0, mailbox->dma, index, 0,
1711 int err; 1668 CMD_READ_MGM, CMD_TIME_CLASS_A, status);
1712
1713 outdma = pci_map_single(dev->pdev, mgm,
1714 MTHCA_MGM_ENTRY_SIZE,
1715 PCI_DMA_FROMDEVICE);
1716 if (pci_dma_mapping_error(outdma))
1717 return -ENOMEM;
1718
1719 err = mthca_cmd_box(dev, 0, outdma, index, 0,
1720 CMD_READ_MGM,
1721 CMD_TIME_CLASS_A, status);
1722
1723 pci_unmap_single(dev->pdev, outdma,
1724 MTHCA_MGM_ENTRY_SIZE,
1725 PCI_DMA_FROMDEVICE);
1726 return err;
1727} 1669}
1728 1670
1729int mthca_WRITE_MGM(struct mthca_dev *dev, int index, void *mgm, 1671int mthca_WRITE_MGM(struct mthca_dev *dev, int index,
1730 u8 *status) 1672 struct mthca_mailbox *mailbox, u8 *status)
1731{ 1673{
1732 dma_addr_t indma; 1674 return mthca_cmd(dev, mailbox->dma, index, 0, CMD_WRITE_MGM,
1733 int err; 1675 CMD_TIME_CLASS_A, status);
1734
1735 indma = pci_map_single(dev->pdev, mgm,
1736 MTHCA_MGM_ENTRY_SIZE,
1737 PCI_DMA_TODEVICE);
1738 if (pci_dma_mapping_error(indma))
1739 return -ENOMEM;
1740
1741 err = mthca_cmd(dev, indma, index, 0, CMD_WRITE_MGM,
1742 CMD_TIME_CLASS_A, status);
1743
1744 pci_unmap_single(dev->pdev, indma,
1745 MTHCA_MGM_ENTRY_SIZE, PCI_DMA_TODEVICE);
1746 return err;
1747} 1676}
1748 1677
1749int mthca_MGID_HASH(struct mthca_dev *dev, void *gid, u16 *hash, 1678int mthca_MGID_HASH(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1750 u8 *status) 1679 u16 *hash, u8 *status)
1751{ 1680{
1752 dma_addr_t indma;
1753 u64 imm; 1681 u64 imm;
1754 int err; 1682 int err;
1755 1683
1756 indma = pci_map_single(dev->pdev, gid, 16, PCI_DMA_TODEVICE); 1684 err = mthca_cmd_imm(dev, mailbox->dma, &imm, 0, 0, CMD_MGID_HASH,
1757 if (pci_dma_mapping_error(indma))
1758 return -ENOMEM;
1759
1760 err = mthca_cmd_imm(dev, indma, &imm, 0, 0, CMD_MGID_HASH,
1761 CMD_TIME_CLASS_A, status); 1685 CMD_TIME_CLASS_A, status);
1762 *hash = imm;
1763 1686
1764 pci_unmap_single(dev->pdev, indma, 16, PCI_DMA_TODEVICE); 1687 *hash = imm;
1765 return err; 1688 return err;
1766} 1689}
1767 1690
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.h b/drivers/infiniband/hw/mthca/mthca_cmd.h
index adf039b3c540..ed517f175dd6 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.h
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.h
@@ -37,8 +37,7 @@
37 37
38#include <ib_verbs.h> 38#include <ib_verbs.h>
39 39
40#define MTHCA_CMD_MAILBOX_ALIGN 16UL 40#define MTHCA_MAILBOX_SIZE 4096
41#define MTHCA_CMD_MAILBOX_EXTRA (MTHCA_CMD_MAILBOX_ALIGN - 1)
42 41
43enum { 42enum {
44 /* command completed successfully: */ 43 /* command completed successfully: */
@@ -112,6 +111,11 @@ enum {
112 DEV_LIM_FLAG_UD_MULTI = 1 << 21, 111 DEV_LIM_FLAG_UD_MULTI = 1 << 21,
113}; 112};
114 113
114struct mthca_mailbox {
115 dma_addr_t dma;
116 void *buf;
117};
118
115struct mthca_dev_lim { 119struct mthca_dev_lim {
116 int max_srq_sz; 120 int max_srq_sz;
117 int max_qp_sz; 121 int max_qp_sz;
@@ -235,11 +239,17 @@ struct mthca_set_ib_param {
235 u32 cap_mask; 239 u32 cap_mask;
236}; 240};
237 241
242int mthca_cmd_init(struct mthca_dev *dev);
243void mthca_cmd_cleanup(struct mthca_dev *dev);
238int mthca_cmd_use_events(struct mthca_dev *dev); 244int mthca_cmd_use_events(struct mthca_dev *dev);
239void mthca_cmd_use_polling(struct mthca_dev *dev); 245void mthca_cmd_use_polling(struct mthca_dev *dev);
240void mthca_cmd_event(struct mthca_dev *dev, u16 token, 246void mthca_cmd_event(struct mthca_dev *dev, u16 token,
241 u8 status, u64 out_param); 247 u8 status, u64 out_param);
242 248
249struct mthca_mailbox *mthca_alloc_mailbox(struct mthca_dev *dev,
250 unsigned int gfp_mask);
251void mthca_free_mailbox(struct mthca_dev *dev, struct mthca_mailbox *mailbox);
252
243int mthca_SYS_EN(struct mthca_dev *dev, u8 *status); 253int mthca_SYS_EN(struct mthca_dev *dev, u8 *status);
244int mthca_SYS_DIS(struct mthca_dev *dev, u8 *status); 254int mthca_SYS_DIS(struct mthca_dev *dev, u8 *status);
245int mthca_MAP_FA(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status); 255int mthca_MAP_FA(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status);
@@ -270,41 +280,39 @@ int mthca_MAP_ICM_AUX(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status);
270int mthca_UNMAP_ICM_AUX(struct mthca_dev *dev, u8 *status); 280int mthca_UNMAP_ICM_AUX(struct mthca_dev *dev, u8 *status);
271int mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages, 281int mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages,
272 u8 *status); 282 u8 *status);
273int mthca_SW2HW_MPT(struct mthca_dev *dev, void *mpt_entry, 283int mthca_SW2HW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
274 int mpt_index, u8 *status); 284 int mpt_index, u8 *status);
275int mthca_HW2SW_MPT(struct mthca_dev *dev, void *mpt_entry, 285int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
276 int mpt_index, u8 *status); 286 int mpt_index, u8 *status);
277int mthca_WRITE_MTT(struct mthca_dev *dev, u64 *mtt_entry, 287int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
278 int num_mtt, u8 *status); 288 int num_mtt, u8 *status);
279int mthca_SYNC_TPT(struct mthca_dev *dev, u8 *status); 289int mthca_SYNC_TPT(struct mthca_dev *dev, u8 *status);
280int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap, 290int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
281 int eq_num, u8 *status); 291 int eq_num, u8 *status);
282int mthca_SW2HW_EQ(struct mthca_dev *dev, void *eq_context, 292int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
283 int eq_num, u8 *status); 293 int eq_num, u8 *status);
284int mthca_HW2SW_EQ(struct mthca_dev *dev, void *eq_context, 294int mthca_HW2SW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
285 int eq_num, u8 *status); 295 int eq_num, u8 *status);
286int mthca_SW2HW_CQ(struct mthca_dev *dev, void *cq_context, 296int mthca_SW2HW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
287 int cq_num, u8 *status); 297 int cq_num, u8 *status);
288int mthca_HW2SW_CQ(struct mthca_dev *dev, void *cq_context, 298int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
289 int cq_num, u8 *status); 299 int cq_num, u8 *status);
290int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num, 300int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,
291 int is_ee, void *qp_context, u32 optmask, 301 int is_ee, struct mthca_mailbox *mailbox, u32 optmask,
292 u8 *status); 302 u8 *status);
293int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee, 303int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee,
294 void *qp_context, u8 *status); 304 struct mthca_mailbox *mailbox, u8 *status);
295int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn, 305int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn,
296 u8 *status); 306 u8 *status);
297int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey, 307int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
298 int port, struct ib_wc* in_wc, struct ib_grh* in_grh, 308 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
299 void *in_mad, void *response_mad, u8 *status); 309 void *in_mad, void *response_mad, u8 *status);
300int mthca_READ_MGM(struct mthca_dev *dev, int index, void *mgm, 310int mthca_READ_MGM(struct mthca_dev *dev, int index,
301 u8 *status); 311 struct mthca_mailbox *mailbox, u8 *status);
302int mthca_WRITE_MGM(struct mthca_dev *dev, int index, void *mgm, 312int mthca_WRITE_MGM(struct mthca_dev *dev, int index,
303 u8 *status); 313 struct mthca_mailbox *mailbox, u8 *status);
304int mthca_MGID_HASH(struct mthca_dev *dev, void *gid, u16 *hash, 314int mthca_MGID_HASH(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
305 u8 *status); 315 u16 *hash, u8 *status);
306int mthca_NOP(struct mthca_dev *dev, u8 *status); 316int mthca_NOP(struct mthca_dev *dev, u8 *status);
307 317
308#define MAILBOX_ALIGN(x) ((void *) ALIGN((unsigned long) (x), MTHCA_CMD_MAILBOX_ALIGN))
309
310#endif /* MTHCA_CMD_H */ 318#endif /* MTHCA_CMD_H */
diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
index 2bf347b84c31..766e9031ec45 100644
--- a/drivers/infiniband/hw/mthca/mthca_cq.c
+++ b/drivers/infiniband/hw/mthca/mthca_cq.c
@@ -1,5 +1,6 @@
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 * 4 *
4 * 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
5 * 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
@@ -171,6 +172,17 @@ static inline void set_cqe_hw(struct mthca_cqe *cqe)
171 cqe->owner = MTHCA_CQ_ENTRY_OWNER_HW; 172 cqe->owner = MTHCA_CQ_ENTRY_OWNER_HW;
172} 173}
173 174
175static void dump_cqe(struct mthca_dev *dev, void *cqe_ptr)
176{
177 __be32 *cqe = cqe_ptr;
178
179 (void) cqe; /* avoid warning if mthca_dbg compiled away... */
180 mthca_dbg(dev, "CQE contents %08x %08x %08x %08x %08x %08x %08x %08x\n",
181 be32_to_cpu(cqe[0]), be32_to_cpu(cqe[1]), be32_to_cpu(cqe[2]),
182 be32_to_cpu(cqe[3]), be32_to_cpu(cqe[4]), be32_to_cpu(cqe[5]),
183 be32_to_cpu(cqe[6]), be32_to_cpu(cqe[7]));
184}
185
174/* 186/*
175 * incr is ignored in native Arbel (mem-free) mode, so cq->cons_index 187 * incr is ignored in native Arbel (mem-free) mode, so cq->cons_index
176 * should be correct before calling update_cons_index(). 188 * should be correct before calling update_cons_index().
@@ -280,16 +292,12 @@ static int handle_error_cqe(struct mthca_dev *dev, struct mthca_cq *cq,
280 int dbd; 292 int dbd;
281 u32 new_wqe; 293 u32 new_wqe;
282 294
283 if (1 && cqe->syndrome != SYNDROME_WR_FLUSH_ERR) { 295 if (cqe->syndrome == SYNDROME_LOCAL_QP_OP_ERR) {
284 int j; 296 mthca_dbg(dev, "local QP operation err "
285 297 "(QPN %06x, WQE @ %08x, CQN %06x, index %d)\n",
286 mthca_dbg(dev, "%x/%d: error CQE -> QPN %06x, WQE @ %08x\n", 298 be32_to_cpu(cqe->my_qpn), be32_to_cpu(cqe->wqe),
287 cq->cqn, cq->cons_index, be32_to_cpu(cqe->my_qpn), 299 cq->cqn, cq->cons_index);
288 be32_to_cpu(cqe->wqe)); 300 dump_cqe(dev, cqe);
289
290 for (j = 0; j < 8; ++j)
291 printk(KERN_DEBUG " [%2x] %08x\n",
292 j * 4, be32_to_cpu(((u32 *) cqe)[j]));
293 } 301 }
294 302
295 /* 303 /*
@@ -377,15 +385,6 @@ static int handle_error_cqe(struct mthca_dev *dev, struct mthca_cq *cq,
377 return 0; 385 return 0;
378} 386}
379 387
380static void dump_cqe(struct mthca_cqe *cqe)
381{
382 int j;
383
384 for (j = 0; j < 8; ++j)
385 printk(KERN_DEBUG " [%2x] %08x\n",
386 j * 4, be32_to_cpu(((u32 *) cqe)[j]));
387}
388
389static inline int mthca_poll_one(struct mthca_dev *dev, 388static inline int mthca_poll_one(struct mthca_dev *dev,
390 struct mthca_cq *cq, 389 struct mthca_cq *cq,
391 struct mthca_qp **cur_qp, 390 struct mthca_qp **cur_qp,
@@ -414,8 +413,7 @@ static inline int mthca_poll_one(struct mthca_dev *dev,
414 mthca_dbg(dev, "%x/%d: CQE -> QPN %06x, WQE @ %08x\n", 413 mthca_dbg(dev, "%x/%d: CQE -> QPN %06x, WQE @ %08x\n",
415 cq->cqn, cq->cons_index, be32_to_cpu(cqe->my_qpn), 414 cq->cqn, cq->cons_index, be32_to_cpu(cqe->my_qpn),
416 be32_to_cpu(cqe->wqe)); 415 be32_to_cpu(cqe->wqe));
417 416 dump_cqe(dev, cqe);
418 dump_cqe(cqe);
419 } 417 }
420 418
421 is_error = (cqe->opcode & MTHCA_ERROR_CQE_OPCODE_MASK) == 419 is_error = (cqe->opcode & MTHCA_ERROR_CQE_OPCODE_MASK) ==
@@ -638,19 +636,19 @@ static void mthca_free_cq_buf(struct mthca_dev *dev, struct mthca_cq *cq)
638 int size; 636 int size;
639 637
640 if (cq->is_direct) 638 if (cq->is_direct)
641 pci_free_consistent(dev->pdev, 639 dma_free_coherent(&dev->pdev->dev,
642 (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE, 640 (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE,
643 cq->queue.direct.buf, 641 cq->queue.direct.buf,
644 pci_unmap_addr(&cq->queue.direct, 642 pci_unmap_addr(&cq->queue.direct,
645 mapping)); 643 mapping));
646 else { 644 else {
647 size = (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE; 645 size = (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE;
648 for (i = 0; i < (size + PAGE_SIZE - 1) / PAGE_SIZE; ++i) 646 for (i = 0; i < (size + PAGE_SIZE - 1) / PAGE_SIZE; ++i)
649 if (cq->queue.page_list[i].buf) 647 if (cq->queue.page_list[i].buf)
650 pci_free_consistent(dev->pdev, PAGE_SIZE, 648 dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
651 cq->queue.page_list[i].buf, 649 cq->queue.page_list[i].buf,
652 pci_unmap_addr(&cq->queue.page_list[i], 650 pci_unmap_addr(&cq->queue.page_list[i],
653 mapping)); 651 mapping));
654 652
655 kfree(cq->queue.page_list); 653 kfree(cq->queue.page_list);
656 } 654 }
@@ -670,8 +668,8 @@ static int mthca_alloc_cq_buf(struct mthca_dev *dev, int size,
670 npages = 1; 668 npages = 1;
671 shift = get_order(size) + PAGE_SHIFT; 669 shift = get_order(size) + PAGE_SHIFT;
672 670
673 cq->queue.direct.buf = pci_alloc_consistent(dev->pdev, 671 cq->queue.direct.buf = dma_alloc_coherent(&dev->pdev->dev,
674 size, &t); 672 size, &t, GFP_KERNEL);
675 if (!cq->queue.direct.buf) 673 if (!cq->queue.direct.buf)
676 return -ENOMEM; 674 return -ENOMEM;
677 675
@@ -709,7 +707,8 @@ static int mthca_alloc_cq_buf(struct mthca_dev *dev, int size,
709 707
710 for (i = 0; i < npages; ++i) { 708 for (i = 0; i < npages; ++i) {
711 cq->queue.page_list[i].buf = 709 cq->queue.page_list[i].buf =
712 pci_alloc_consistent(dev->pdev, PAGE_SIZE, &t); 710 dma_alloc_coherent(&dev->pdev->dev, PAGE_SIZE,
711 &t, GFP_KERNEL);
713 if (!cq->queue.page_list[i].buf) 712 if (!cq->queue.page_list[i].buf)
714 goto err_free; 713 goto err_free;
715 714
@@ -746,7 +745,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
746 struct mthca_cq *cq) 745 struct mthca_cq *cq)
747{ 746{
748 int size = nent * MTHCA_CQ_ENTRY_SIZE; 747 int size = nent * MTHCA_CQ_ENTRY_SIZE;
749 void *mailbox = NULL; 748 struct mthca_mailbox *mailbox;
750 struct mthca_cq_context *cq_context; 749 struct mthca_cq_context *cq_context;
751 int err = -ENOMEM; 750 int err = -ENOMEM;
752 u8 status; 751 u8 status;
@@ -780,12 +779,11 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
780 goto err_out_ci; 779 goto err_out_ci;
781 } 780 }
782 781
783 mailbox = kmalloc(sizeof (struct mthca_cq_context) + MTHCA_CMD_MAILBOX_EXTRA, 782 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
784 GFP_KERNEL); 783 if (IS_ERR(mailbox))
785 if (!mailbox) 784 goto err_out_arm;
786 goto err_out_mailbox;
787 785
788 cq_context = MAILBOX_ALIGN(mailbox); 786 cq_context = mailbox->buf;
789 787
790 err = mthca_alloc_cq_buf(dev, size, cq); 788 err = mthca_alloc_cq_buf(dev, size, cq);
791 if (err) 789 if (err)
@@ -816,7 +814,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
816 cq_context->state_db = cpu_to_be32(cq->arm_db_index); 814 cq_context->state_db = cpu_to_be32(cq->arm_db_index);
817 } 815 }
818 816
819 err = mthca_SW2HW_CQ(dev, cq_context, cq->cqn, &status); 817 err = mthca_SW2HW_CQ(dev, mailbox, cq->cqn, &status);
820 if (err) { 818 if (err) {
821 mthca_warn(dev, "SW2HW_CQ failed (%d)\n", err); 819 mthca_warn(dev, "SW2HW_CQ failed (%d)\n", err);
822 goto err_out_free_mr; 820 goto err_out_free_mr;
@@ -840,7 +838,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
840 838
841 cq->cons_index = 0; 839 cq->cons_index = 0;
842 840
843 kfree(mailbox); 841 mthca_free_mailbox(dev, mailbox);
844 842
845 return 0; 843 return 0;
846 844
@@ -849,8 +847,9 @@ err_out_free_mr:
849 mthca_free_cq_buf(dev, cq); 847 mthca_free_cq_buf(dev, cq);
850 848
851err_out_mailbox: 849err_out_mailbox:
852 kfree(mailbox); 850 mthca_free_mailbox(dev, mailbox);
853 851
852err_out_arm:
854 if (mthca_is_memfree(dev)) 853 if (mthca_is_memfree(dev))
855 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index); 854 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index);
856 855
@@ -870,28 +869,26 @@ err_out:
870void mthca_free_cq(struct mthca_dev *dev, 869void mthca_free_cq(struct mthca_dev *dev,
871 struct mthca_cq *cq) 870 struct mthca_cq *cq)
872{ 871{
873 void *mailbox; 872 struct mthca_mailbox *mailbox;
874 int err; 873 int err;
875 u8 status; 874 u8 status;
876 875
877 might_sleep(); 876 might_sleep();
878 877
879 mailbox = kmalloc(sizeof (struct mthca_cq_context) + MTHCA_CMD_MAILBOX_EXTRA, 878 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
880 GFP_KERNEL); 879 if (IS_ERR(mailbox)) {
881 if (!mailbox) {
882 mthca_warn(dev, "No memory for mailbox to free CQ.\n"); 880 mthca_warn(dev, "No memory for mailbox to free CQ.\n");
883 return; 881 return;
884 } 882 }
885 883
886 err = mthca_HW2SW_CQ(dev, MAILBOX_ALIGN(mailbox), cq->cqn, &status); 884 err = mthca_HW2SW_CQ(dev, mailbox, cq->cqn, &status);
887 if (err) 885 if (err)
888 mthca_warn(dev, "HW2SW_CQ failed (%d)\n", err); 886 mthca_warn(dev, "HW2SW_CQ failed (%d)\n", err);
889 else if (status) 887 else if (status)
890 mthca_warn(dev, "HW2SW_CQ returned status 0x%02x\n", 888 mthca_warn(dev, "HW2SW_CQ returned status 0x%02x\n", status);
891 status);
892 889
893 if (0) { 890 if (0) {
894 u32 *ctx = MAILBOX_ALIGN(mailbox); 891 u32 *ctx = mailbox->buf;
895 int j; 892 int j;
896 893
897 printk(KERN_ERR "context for CQN %x (cons index %x, next sw %d)\n", 894 printk(KERN_ERR "context for CQN %x (cons index %x, next sw %d)\n",
@@ -919,11 +916,11 @@ void mthca_free_cq(struct mthca_dev *dev,
919 if (mthca_is_memfree(dev)) { 916 if (mthca_is_memfree(dev)) {
920 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index); 917 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index);
921 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_SET_CI, cq->set_ci_db_index); 918 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_SET_CI, cq->set_ci_db_index);
922 mthca_table_put(dev, dev->cq_table.table, cq->cqn);
923 } 919 }
924 920
921 mthca_table_put(dev, dev->cq_table.table, cq->cqn);
925 mthca_free(&dev->cq_table.alloc, cq->cqn); 922 mthca_free(&dev->cq_table.alloc, cq->cqn);
926 kfree(mailbox); 923 mthca_free_mailbox(dev, mailbox);
927} 924}
928 925
929int __devinit mthca_init_cq_table(struct mthca_dev *dev) 926int __devinit mthca_init_cq_table(struct mthca_dev *dev)
diff --git a/drivers/infiniband/hw/mthca/mthca_dev.h b/drivers/infiniband/hw/mthca/mthca_dev.h
index e3d79e267dc9..4127f09dc5ec 100644
--- a/drivers/infiniband/hw/mthca/mthca_dev.h
+++ b/drivers/infiniband/hw/mthca/mthca_dev.h
@@ -1,5 +1,6 @@
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 * 4 *
4 * 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
5 * 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
@@ -46,8 +47,8 @@
46 47
47#define DRV_NAME "ib_mthca" 48#define DRV_NAME "ib_mthca"
48#define PFX DRV_NAME ": " 49#define PFX DRV_NAME ": "
49#define DRV_VERSION "0.06-pre" 50#define DRV_VERSION "0.06"
50#define DRV_RELDATE "November 8, 2004" 51#define DRV_RELDATE "June 23, 2005"
51 52
52enum { 53enum {
53 MTHCA_FLAG_DDR_HIDDEN = 1 << 1, 54 MTHCA_FLAG_DDR_HIDDEN = 1 << 1,
@@ -98,6 +99,7 @@ enum {
98}; 99};
99 100
100struct mthca_cmd { 101struct mthca_cmd {
102 struct pci_pool *pool;
101 int use_events; 103 int use_events;
102 struct semaphore hcr_sem; 104 struct semaphore hcr_sem;
103 struct semaphore poll_sem; 105 struct semaphore poll_sem;
@@ -379,6 +381,12 @@ void mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar);
379int mthca_pd_alloc(struct mthca_dev *dev, struct mthca_pd *pd); 381int mthca_pd_alloc(struct mthca_dev *dev, struct mthca_pd *pd);
380void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd); 382void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd);
381 383
384struct mthca_mtt *mthca_alloc_mtt(struct mthca_dev *dev, int size);
385void mthca_free_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt);
386int mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt,
387 int start_index, u64 *buffer_list, int list_len);
388int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
389 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr);
382int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd, 390int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
383 u32 access, struct mthca_mr *mr); 391 u32 access, struct mthca_mr *mr);
384int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd, 392int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
diff --git a/drivers/infiniband/hw/mthca/mthca_doorbell.h b/drivers/infiniband/hw/mthca/mthca_doorbell.h
index 821039a49049..535fad7710fb 100644
--- a/drivers/infiniband/hw/mthca/mthca_doorbell.h
+++ b/drivers/infiniband/hw/mthca/mthca_doorbell.h
@@ -1,5 +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 Sun Microsystems, Inc. All rights reserved.
3 * 4 *
4 * 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
5 * 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
diff --git a/drivers/infiniband/hw/mthca/mthca_eq.c b/drivers/infiniband/hw/mthca/mthca_eq.c
index f46d615d396f..cbcf2b4722e4 100644
--- a/drivers/infiniband/hw/mthca/mthca_eq.c
+++ b/drivers/infiniband/hw/mthca/mthca_eq.c
@@ -469,7 +469,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
469 PAGE_SIZE; 469 PAGE_SIZE;
470 u64 *dma_list = NULL; 470 u64 *dma_list = NULL;
471 dma_addr_t t; 471 dma_addr_t t;
472 void *mailbox = NULL; 472 struct mthca_mailbox *mailbox;
473 struct mthca_eq_context *eq_context; 473 struct mthca_eq_context *eq_context;
474 int err = -ENOMEM; 474 int err = -ENOMEM;
475 int i; 475 int i;
@@ -494,17 +494,16 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
494 if (!dma_list) 494 if (!dma_list)
495 goto err_out_free; 495 goto err_out_free;
496 496
497 mailbox = kmalloc(sizeof *eq_context + MTHCA_CMD_MAILBOX_EXTRA, 497 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
498 GFP_KERNEL); 498 if (IS_ERR(mailbox))
499 if (!mailbox)
500 goto err_out_free; 499 goto err_out_free;
501 eq_context = MAILBOX_ALIGN(mailbox); 500 eq_context = mailbox->buf;
502 501
503 for (i = 0; i < npages; ++i) { 502 for (i = 0; i < npages; ++i) {
504 eq->page_list[i].buf = pci_alloc_consistent(dev->pdev, 503 eq->page_list[i].buf = dma_alloc_coherent(&dev->pdev->dev,
505 PAGE_SIZE, &t); 504 PAGE_SIZE, &t, GFP_KERNEL);
506 if (!eq->page_list[i].buf) 505 if (!eq->page_list[i].buf)
507 goto err_out_free; 506 goto err_out_free_pages;
508 507
509 dma_list[i] = t; 508 dma_list[i] = t;
510 pci_unmap_addr_set(&eq->page_list[i], mapping, t); 509 pci_unmap_addr_set(&eq->page_list[i], mapping, t);
@@ -517,7 +516,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
517 516
518 eq->eqn = mthca_alloc(&dev->eq_table.alloc); 517 eq->eqn = mthca_alloc(&dev->eq_table.alloc);
519 if (eq->eqn == -1) 518 if (eq->eqn == -1)
520 goto err_out_free; 519 goto err_out_free_pages;
521 520
522 err = mthca_mr_alloc_phys(dev, dev->driver_pd.pd_num, 521 err = mthca_mr_alloc_phys(dev, dev->driver_pd.pd_num,
523 dma_list, PAGE_SHIFT, npages, 522 dma_list, PAGE_SHIFT, npages,
@@ -548,7 +547,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
548 eq_context->intr = intr; 547 eq_context->intr = intr;
549 eq_context->lkey = cpu_to_be32(eq->mr.ibmr.lkey); 548 eq_context->lkey = cpu_to_be32(eq->mr.ibmr.lkey);
550 549
551 err = mthca_SW2HW_EQ(dev, eq_context, eq->eqn, &status); 550 err = mthca_SW2HW_EQ(dev, mailbox, eq->eqn, &status);
552 if (err) { 551 if (err) {
553 mthca_warn(dev, "SW2HW_EQ failed (%d)\n", err); 552 mthca_warn(dev, "SW2HW_EQ failed (%d)\n", err);
554 goto err_out_free_mr; 553 goto err_out_free_mr;
@@ -561,7 +560,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
561 } 560 }
562 561
563 kfree(dma_list); 562 kfree(dma_list);
564 kfree(mailbox); 563 mthca_free_mailbox(dev, mailbox);
565 564
566 eq->eqn_mask = swab32(1 << eq->eqn); 565 eq->eqn_mask = swab32(1 << eq->eqn);
567 eq->cons_index = 0; 566 eq->cons_index = 0;
@@ -579,17 +578,19 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
579 err_out_free_eq: 578 err_out_free_eq:
580 mthca_free(&dev->eq_table.alloc, eq->eqn); 579 mthca_free(&dev->eq_table.alloc, eq->eqn);
581 580
582 err_out_free: 581 err_out_free_pages:
583 for (i = 0; i < npages; ++i) 582 for (i = 0; i < npages; ++i)
584 if (eq->page_list[i].buf) 583 if (eq->page_list[i].buf)
585 pci_free_consistent(dev->pdev, PAGE_SIZE, 584 dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
586 eq->page_list[i].buf, 585 eq->page_list[i].buf,
587 pci_unmap_addr(&eq->page_list[i], 586 pci_unmap_addr(&eq->page_list[i],
588 mapping)); 587 mapping));
588
589 mthca_free_mailbox(dev, mailbox);
589 590
591 err_out_free:
590 kfree(eq->page_list); 592 kfree(eq->page_list);
591 kfree(dma_list); 593 kfree(dma_list);
592 kfree(mailbox);
593 594
594 err_out: 595 err_out:
595 return err; 596 return err;
@@ -598,25 +599,22 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
598static void mthca_free_eq(struct mthca_dev *dev, 599static void mthca_free_eq(struct mthca_dev *dev,
599 struct mthca_eq *eq) 600 struct mthca_eq *eq)
600{ 601{
601 void *mailbox = NULL; 602 struct mthca_mailbox *mailbox;
602 int err; 603 int err;
603 u8 status; 604 u8 status;
604 int npages = (eq->nent * MTHCA_EQ_ENTRY_SIZE + PAGE_SIZE - 1) / 605 int npages = (eq->nent * MTHCA_EQ_ENTRY_SIZE + PAGE_SIZE - 1) /
605 PAGE_SIZE; 606 PAGE_SIZE;
606 int i; 607 int i;
607 608
608 mailbox = kmalloc(sizeof (struct mthca_eq_context) + MTHCA_CMD_MAILBOX_EXTRA, 609 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
609 GFP_KERNEL); 610 if (IS_ERR(mailbox))
610 if (!mailbox)
611 return; 611 return;
612 612
613 err = mthca_HW2SW_EQ(dev, MAILBOX_ALIGN(mailbox), 613 err = mthca_HW2SW_EQ(dev, mailbox, eq->eqn, &status);
614 eq->eqn, &status);
615 if (err) 614 if (err)
616 mthca_warn(dev, "HW2SW_EQ failed (%d)\n", err); 615 mthca_warn(dev, "HW2SW_EQ failed (%d)\n", err);
617 if (status) 616 if (status)
618 mthca_warn(dev, "HW2SW_EQ returned status 0x%02x\n", 617 mthca_warn(dev, "HW2SW_EQ returned status 0x%02x\n", status);
619 status);
620 618
621 dev->eq_table.arm_mask &= ~eq->eqn_mask; 619 dev->eq_table.arm_mask &= ~eq->eqn_mask;
622 620
@@ -625,7 +623,7 @@ static void mthca_free_eq(struct mthca_dev *dev,
625 for (i = 0; i < sizeof (struct mthca_eq_context) / 4; ++i) { 623 for (i = 0; i < sizeof (struct mthca_eq_context) / 4; ++i) {
626 if (i % 4 == 0) 624 if (i % 4 == 0)
627 printk("[%02x] ", i * 4); 625 printk("[%02x] ", i * 4);
628 printk(" %08x", be32_to_cpup(MAILBOX_ALIGN(mailbox) + i * 4)); 626 printk(" %08x", be32_to_cpup(mailbox->buf + i * 4));
629 if ((i + 1) % 4 == 0) 627 if ((i + 1) % 4 == 0)
630 printk("\n"); 628 printk("\n");
631 } 629 }
@@ -638,7 +636,7 @@ static void mthca_free_eq(struct mthca_dev *dev,
638 pci_unmap_addr(&eq->page_list[i], mapping)); 636 pci_unmap_addr(&eq->page_list[i], mapping));
639 637
640 kfree(eq->page_list); 638 kfree(eq->page_list);
641 kfree(mailbox); 639 mthca_free_mailbox(dev, mailbox);
642} 640}
643 641
644static void mthca_free_irqs(struct mthca_dev *dev) 642static void mthca_free_irqs(struct mthca_dev *dev)
@@ -709,8 +707,7 @@ static int __devinit mthca_map_eq_regs(struct mthca_dev *dev)
709 if (mthca_map_reg(dev, ((pci_resource_len(dev->pdev, 0) - 1) & 707 if (mthca_map_reg(dev, ((pci_resource_len(dev->pdev, 0) - 1) &
710 dev->fw.arbel.eq_arm_base) + 4, 4, 708 dev->fw.arbel.eq_arm_base) + 4, 4,
711 &dev->eq_regs.arbel.eq_arm)) { 709 &dev->eq_regs.arbel.eq_arm)) {
712 mthca_err(dev, "Couldn't map interrupt clear register, " 710 mthca_err(dev, "Couldn't map EQ arm register, aborting.\n");
713 "aborting.\n");
714 mthca_unmap_reg(dev, (pci_resource_len(dev->pdev, 0) - 1) & 711 mthca_unmap_reg(dev, (pci_resource_len(dev->pdev, 0) - 1) &
715 dev->fw.arbel.clr_int_base, MTHCA_CLR_INT_SIZE, 712 dev->fw.arbel.clr_int_base, MTHCA_CLR_INT_SIZE,
716 dev->clr_base); 713 dev->clr_base);
@@ -721,8 +718,7 @@ static int __devinit mthca_map_eq_regs(struct mthca_dev *dev)
721 dev->fw.arbel.eq_set_ci_base, 718 dev->fw.arbel.eq_set_ci_base,
722 MTHCA_EQ_SET_CI_SIZE, 719 MTHCA_EQ_SET_CI_SIZE,
723 &dev->eq_regs.arbel.eq_set_ci_base)) { 720 &dev->eq_regs.arbel.eq_set_ci_base)) {
724 mthca_err(dev, "Couldn't map interrupt clear register, " 721 mthca_err(dev, "Couldn't map EQ CI register, aborting.\n");
725 "aborting.\n");
726 mthca_unmap_reg(dev, ((pci_resource_len(dev->pdev, 0) - 1) & 722 mthca_unmap_reg(dev, ((pci_resource_len(dev->pdev, 0) - 1) &
727 dev->fw.arbel.eq_arm_base) + 4, 4, 723 dev->fw.arbel.eq_arm_base) + 4, 4,
728 dev->eq_regs.arbel.eq_arm); 724 dev->eq_regs.arbel.eq_arm);
diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
index d40590356df8..09519b604c08 100644
--- a/drivers/infiniband/hw/mthca/mthca_main.c
+++ b/drivers/infiniband/hw/mthca/mthca_main.c
@@ -1,5 +1,6 @@
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 * 4 *
4 * 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
5 * 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
@@ -69,7 +70,7 @@ MODULE_PARM_DESC(msi, "attempt to use MSI if nonzero");
69#endif /* CONFIG_PCI_MSI */ 70#endif /* CONFIG_PCI_MSI */
70 71
71static const char mthca_version[] __devinitdata = 72static const char mthca_version[] __devinitdata =
72 "ib_mthca: Mellanox InfiniBand HCA driver v" 73 DRV_NAME ": Mellanox InfiniBand HCA driver v"
73 DRV_VERSION " (" DRV_RELDATE ")\n"; 74 DRV_VERSION " (" DRV_RELDATE ")\n";
74 75
75static struct mthca_profile default_profile = { 76static struct mthca_profile default_profile = {
@@ -927,13 +928,13 @@ static int __devinit mthca_init_one(struct pci_dev *pdev,
927 */ 928 */
928 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) || 929 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
929 pci_resource_len(pdev, 0) != 1 << 20) { 930 pci_resource_len(pdev, 0) != 1 << 20) {
930 dev_err(&pdev->dev, "Missing DCS, aborting."); 931 dev_err(&pdev->dev, "Missing DCS, aborting.\n");
931 err = -ENODEV; 932 err = -ENODEV;
932 goto err_disable_pdev; 933 goto err_disable_pdev;
933 } 934 }
934 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM) || 935 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM) ||
935 pci_resource_len(pdev, 2) != 1 << 23) { 936 pci_resource_len(pdev, 2) != 1 << 23) {
936 dev_err(&pdev->dev, "Missing UAR, aborting."); 937 dev_err(&pdev->dev, "Missing UAR, aborting.\n");
937 err = -ENODEV; 938 err = -ENODEV;
938 goto err_disable_pdev; 939 goto err_disable_pdev;
939 } 940 }
@@ -1004,25 +1005,18 @@ static int __devinit mthca_init_one(struct pci_dev *pdev,
1004 !pci_enable_msi(pdev)) 1005 !pci_enable_msi(pdev))
1005 mdev->mthca_flags |= MTHCA_FLAG_MSI; 1006 mdev->mthca_flags |= MTHCA_FLAG_MSI;
1006 1007
1007 sema_init(&mdev->cmd.hcr_sem, 1); 1008 if (mthca_cmd_init(mdev)) {
1008 sema_init(&mdev->cmd.poll_sem, 1); 1009 mthca_err(mdev, "Failed to init command interface, aborting.\n");
1009 mdev->cmd.use_events = 0;
1010
1011 mdev->hcr = ioremap(pci_resource_start(pdev, 0) + MTHCA_HCR_BASE, MTHCA_HCR_SIZE);
1012 if (!mdev->hcr) {
1013 mthca_err(mdev, "Couldn't map command register, "
1014 "aborting.\n");
1015 err = -ENOMEM;
1016 goto err_free_dev; 1010 goto err_free_dev;
1017 } 1011 }
1018 1012
1019 err = mthca_tune_pci(mdev); 1013 err = mthca_tune_pci(mdev);
1020 if (err) 1014 if (err)
1021 goto err_iounmap; 1015 goto err_cmd;
1022 1016
1023 err = mthca_init_hca(mdev); 1017 err = mthca_init_hca(mdev);
1024 if (err) 1018 if (err)
1025 goto err_iounmap; 1019 goto err_cmd;
1026 1020
1027 if (mdev->fw_ver < mthca_hca_table[id->driver_data].latest_fw) { 1021 if (mdev->fw_ver < mthca_hca_table[id->driver_data].latest_fw) {
1028 mthca_warn(mdev, "HCA FW version %x.%x.%x is old (%x.%x.%x is current).\n", 1022 mthca_warn(mdev, "HCA FW version %x.%x.%x is old (%x.%x.%x is current).\n",
@@ -1070,8 +1064,8 @@ err_cleanup:
1070err_close: 1064err_close:
1071 mthca_close_hca(mdev); 1065 mthca_close_hca(mdev);
1072 1066
1073err_iounmap: 1067err_cmd:
1074 iounmap(mdev->hcr); 1068 mthca_cmd_cleanup(mdev);
1075 1069
1076err_free_dev: 1070err_free_dev:
1077 if (mdev->mthca_flags & MTHCA_FLAG_MSI_X) 1071 if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
@@ -1118,10 +1112,8 @@ static void __devexit mthca_remove_one(struct pci_dev *pdev)
1118 iounmap(mdev->kar); 1112 iounmap(mdev->kar);
1119 mthca_uar_free(mdev, &mdev->driver_uar); 1113 mthca_uar_free(mdev, &mdev->driver_uar);
1120 mthca_cleanup_uar_table(mdev); 1114 mthca_cleanup_uar_table(mdev);
1121
1122 mthca_close_hca(mdev); 1115 mthca_close_hca(mdev);
1123 1116 mthca_cmd_cleanup(mdev);
1124 iounmap(mdev->hcr);
1125 1117
1126 if (mdev->mthca_flags & MTHCA_FLAG_MSI_X) 1118 if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
1127 pci_disable_msix(pdev); 1119 pci_disable_msix(pdev);
@@ -1163,7 +1155,7 @@ static struct pci_device_id mthca_pci_table[] = {
1163MODULE_DEVICE_TABLE(pci, mthca_pci_table); 1155MODULE_DEVICE_TABLE(pci, mthca_pci_table);
1164 1156
1165static struct pci_driver mthca_driver = { 1157static struct pci_driver mthca_driver = {
1166 .name = "ib_mthca", 1158 .name = DRV_NAME,
1167 .id_table = mthca_pci_table, 1159 .id_table = mthca_pci_table,
1168 .probe = mthca_init_one, 1160 .probe = mthca_init_one,
1169 .remove = __devexit_p(mthca_remove_one) 1161 .remove = __devexit_p(mthca_remove_one)
diff --git a/drivers/infiniband/hw/mthca/mthca_mcg.c b/drivers/infiniband/hw/mthca/mthca_mcg.c
index 70a6553a588e..5be7d949dbf6 100644
--- a/drivers/infiniband/hw/mthca/mthca_mcg.c
+++ b/drivers/infiniband/hw/mthca/mthca_mcg.c
@@ -66,22 +66,23 @@ static const u8 zero_gid[16]; /* automatically initialized to 0 */
66 * entry in hash chain and *mgm holds end of hash chain. 66 * entry in hash chain and *mgm holds end of hash chain.
67 */ 67 */
68static int find_mgm(struct mthca_dev *dev, 68static int find_mgm(struct mthca_dev *dev,
69 u8 *gid, struct mthca_mgm *mgm, 69 u8 *gid, struct mthca_mailbox *mgm_mailbox,
70 u16 *hash, int *prev, int *index) 70 u16 *hash, int *prev, int *index)
71{ 71{
72 void *mailbox; 72 struct mthca_mailbox *mailbox;
73 struct mthca_mgm *mgm = mgm_mailbox->buf;
73 u8 *mgid; 74 u8 *mgid;
74 int err; 75 int err;
75 u8 status; 76 u8 status;
76 77
77 mailbox = kmalloc(16 + MTHCA_CMD_MAILBOX_EXTRA, GFP_KERNEL); 78 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
78 if (!mailbox) 79 if (IS_ERR(mailbox))
79 return -ENOMEM; 80 return -ENOMEM;
80 mgid = MAILBOX_ALIGN(mailbox); 81 mgid = mailbox->buf;
81 82
82 memcpy(mgid, gid, 16); 83 memcpy(mgid, gid, 16);
83 84
84 err = mthca_MGID_HASH(dev, mgid, hash, &status); 85 err = mthca_MGID_HASH(dev, mailbox, hash, &status);
85 if (err) 86 if (err)
86 goto out; 87 goto out;
87 if (status) { 88 if (status) {
@@ -103,7 +104,7 @@ static int find_mgm(struct mthca_dev *dev,
103 *prev = -1; 104 *prev = -1;
104 105
105 do { 106 do {
106 err = mthca_READ_MGM(dev, *index, mgm, &status); 107 err = mthca_READ_MGM(dev, *index, mgm_mailbox, &status);
107 if (err) 108 if (err)
108 goto out; 109 goto out;
109 if (status) { 110 if (status) {
@@ -129,14 +130,14 @@ static int find_mgm(struct mthca_dev *dev,
129 *index = -1; 130 *index = -1;
130 131
131 out: 132 out:
132 kfree(mailbox); 133 mthca_free_mailbox(dev, mailbox);
133 return err; 134 return err;
134} 135}
135 136
136int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) 137int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
137{ 138{
138 struct mthca_dev *dev = to_mdev(ibqp->device); 139 struct mthca_dev *dev = to_mdev(ibqp->device);
139 void *mailbox; 140 struct mthca_mailbox *mailbox;
140 struct mthca_mgm *mgm; 141 struct mthca_mgm *mgm;
141 u16 hash; 142 u16 hash;
142 int index, prev; 143 int index, prev;
@@ -145,15 +146,15 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
145 int err; 146 int err;
146 u8 status; 147 u8 status;
147 148
148 mailbox = kmalloc(sizeof *mgm + MTHCA_CMD_MAILBOX_EXTRA, GFP_KERNEL); 149 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
149 if (!mailbox) 150 if (IS_ERR(mailbox))
150 return -ENOMEM; 151 return PTR_ERR(mailbox);
151 mgm = MAILBOX_ALIGN(mailbox); 152 mgm = mailbox->buf;
152 153
153 if (down_interruptible(&dev->mcg_table.sem)) 154 if (down_interruptible(&dev->mcg_table.sem))
154 return -EINTR; 155 return -EINTR;
155 156
156 err = find_mgm(dev, gid->raw, mgm, &hash, &prev, &index); 157 err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index);
157 if (err) 158 if (err)
158 goto out; 159 goto out;
159 160
@@ -170,7 +171,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
170 goto out; 171 goto out;
171 } 172 }
172 173
173 err = mthca_READ_MGM(dev, index, mgm, &status); 174 err = mthca_READ_MGM(dev, index, mailbox, &status);
174 if (err) 175 if (err)
175 goto out; 176 goto out;
176 if (status) { 177 if (status) {
@@ -195,7 +196,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
195 goto out; 196 goto out;
196 } 197 }
197 198
198 err = mthca_WRITE_MGM(dev, index, mgm, &status); 199 err = mthca_WRITE_MGM(dev, index, mailbox, &status);
199 if (err) 200 if (err)
200 goto out; 201 goto out;
201 if (status) { 202 if (status) {
@@ -206,7 +207,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
206 if (!link) 207 if (!link)
207 goto out; 208 goto out;
208 209
209 err = mthca_READ_MGM(dev, prev, mgm, &status); 210 err = mthca_READ_MGM(dev, prev, mailbox, &status);
210 if (err) 211 if (err)
211 goto out; 212 goto out;
212 if (status) { 213 if (status) {
@@ -217,7 +218,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
217 218
218 mgm->next_gid_index = cpu_to_be32(index << 5); 219 mgm->next_gid_index = cpu_to_be32(index << 5);
219 220
220 err = mthca_WRITE_MGM(dev, prev, mgm, &status); 221 err = mthca_WRITE_MGM(dev, prev, mailbox, &status);
221 if (err) 222 if (err)
222 goto out; 223 goto out;
223 if (status) { 224 if (status) {
@@ -227,14 +228,14 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
227 228
228 out: 229 out:
229 up(&dev->mcg_table.sem); 230 up(&dev->mcg_table.sem);
230 kfree(mailbox); 231 mthca_free_mailbox(dev, mailbox);
231 return err; 232 return err;
232} 233}
233 234
234int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) 235int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
235{ 236{
236 struct mthca_dev *dev = to_mdev(ibqp->device); 237 struct mthca_dev *dev = to_mdev(ibqp->device);
237 void *mailbox; 238 struct mthca_mailbox *mailbox;
238 struct mthca_mgm *mgm; 239 struct mthca_mgm *mgm;
239 u16 hash; 240 u16 hash;
240 int prev, index; 241 int prev, index;
@@ -242,15 +243,15 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
242 int err; 243 int err;
243 u8 status; 244 u8 status;
244 245
245 mailbox = kmalloc(sizeof *mgm + MTHCA_CMD_MAILBOX_EXTRA, GFP_KERNEL); 246 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
246 if (!mailbox) 247 if (IS_ERR(mailbox))
247 return -ENOMEM; 248 return PTR_ERR(mailbox);
248 mgm = MAILBOX_ALIGN(mailbox); 249 mgm = mailbox->buf;
249 250
250 if (down_interruptible(&dev->mcg_table.sem)) 251 if (down_interruptible(&dev->mcg_table.sem))
251 return -EINTR; 252 return -EINTR;
252 253
253 err = find_mgm(dev, gid->raw, mgm, &hash, &prev, &index); 254 err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index);
254 if (err) 255 if (err)
255 goto out; 256 goto out;
256 257
@@ -285,7 +286,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
285 mgm->qp[loc] = mgm->qp[i - 1]; 286 mgm->qp[loc] = mgm->qp[i - 1];
286 mgm->qp[i - 1] = 0; 287 mgm->qp[i - 1] = 0;
287 288
288 err = mthca_WRITE_MGM(dev, index, mgm, &status); 289 err = mthca_WRITE_MGM(dev, index, mailbox, &status);
289 if (err) 290 if (err)
290 goto out; 291 goto out;
291 if (status) { 292 if (status) {
@@ -304,7 +305,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
304 if (be32_to_cpu(mgm->next_gid_index) >> 5) { 305 if (be32_to_cpu(mgm->next_gid_index) >> 5) {
305 err = mthca_READ_MGM(dev, 306 err = mthca_READ_MGM(dev,
306 be32_to_cpu(mgm->next_gid_index) >> 5, 307 be32_to_cpu(mgm->next_gid_index) >> 5,
307 mgm, &status); 308 mailbox, &status);
308 if (err) 309 if (err)
309 goto out; 310 goto out;
310 if (status) { 311 if (status) {
@@ -316,7 +317,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
316 } else 317 } else
317 memset(mgm->gid, 0, 16); 318 memset(mgm->gid, 0, 16);
318 319
319 err = mthca_WRITE_MGM(dev, index, mgm, &status); 320 err = mthca_WRITE_MGM(dev, index, mailbox, &status);
320 if (err) 321 if (err)
321 goto out; 322 goto out;
322 if (status) { 323 if (status) {
@@ -327,7 +328,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
327 } else { 328 } else {
328 /* Remove entry from AMGM */ 329 /* Remove entry from AMGM */
329 index = be32_to_cpu(mgm->next_gid_index) >> 5; 330 index = be32_to_cpu(mgm->next_gid_index) >> 5;
330 err = mthca_READ_MGM(dev, prev, mgm, &status); 331 err = mthca_READ_MGM(dev, prev, mailbox, &status);
331 if (err) 332 if (err)
332 goto out; 333 goto out;
333 if (status) { 334 if (status) {
@@ -338,7 +339,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
338 339
339 mgm->next_gid_index = cpu_to_be32(index << 5); 340 mgm->next_gid_index = cpu_to_be32(index << 5);
340 341
341 err = mthca_WRITE_MGM(dev, prev, mgm, &status); 342 err = mthca_WRITE_MGM(dev, prev, mailbox, &status);
342 if (err) 343 if (err)
343 goto out; 344 goto out;
344 if (status) { 345 if (status) {
@@ -350,7 +351,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
350 351
351 out: 352 out:
352 up(&dev->mcg_table.sem); 353 up(&dev->mcg_table.sem);
353 kfree(mailbox); 354 mthca_free_mailbox(dev, mailbox);
354 return err; 355 return err;
355} 356}
356 357
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
index 637b30e35592..6d3b05dd9e3f 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.c
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
@@ -179,9 +179,14 @@ out:
179 179
180void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int obj) 180void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int obj)
181{ 181{
182 int i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE; 182 int i;
183 u8 status; 183 u8 status;
184 184
185 if (!mthca_is_memfree(dev))
186 return;
187
188 i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE;
189
185 down(&table->mutex); 190 down(&table->mutex);
186 191
187 if (--table->icm[i]->refcount == 0) { 192 if (--table->icm[i]->refcount == 0) {
@@ -256,6 +261,9 @@ void mthca_table_put_range(struct mthca_dev *dev, struct mthca_icm_table *table,
256{ 261{
257 int i; 262 int i;
258 263
264 if (!mthca_is_memfree(dev))
265 return;
266
259 for (i = start; i <= end; i += MTHCA_TABLE_CHUNK_SIZE / table->obj_size) 267 for (i = start; i <= end; i += MTHCA_TABLE_CHUNK_SIZE / table->obj_size)
260 mthca_table_put(dev, table, i); 268 mthca_table_put(dev, table, i);
261} 269}
diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
index 8960fc2306be..cbe50feaf680 100644
--- a/drivers/infiniband/hw/mthca/mthca_mr.c
+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
@@ -40,6 +40,12 @@
40#include "mthca_cmd.h" 40#include "mthca_cmd.h"
41#include "mthca_memfree.h" 41#include "mthca_memfree.h"
42 42
43struct mthca_mtt {
44 struct mthca_buddy *buddy;
45 int order;
46 u32 first_seg;
47};
48
43/* 49/*
44 * Must be packed because mtt_seg is 64 bits but only aligned to 32 bits. 50 * Must be packed because mtt_seg is 64 bits but only aligned to 32 bits.
45 */ 51 */
@@ -173,8 +179,8 @@ static void __devexit mthca_buddy_cleanup(struct mthca_buddy *buddy)
173 kfree(buddy->bits); 179 kfree(buddy->bits);
174} 180}
175 181
176static u32 mthca_alloc_mtt(struct mthca_dev *dev, int order, 182static u32 mthca_alloc_mtt_range(struct mthca_dev *dev, int order,
177 struct mthca_buddy *buddy) 183 struct mthca_buddy *buddy)
178{ 184{
179 u32 seg = mthca_buddy_alloc(buddy, order); 185 u32 seg = mthca_buddy_alloc(buddy, order);
180 186
@@ -191,14 +197,102 @@ static u32 mthca_alloc_mtt(struct mthca_dev *dev, int order,
191 return seg; 197 return seg;
192} 198}
193 199
194static void mthca_free_mtt(struct mthca_dev *dev, u32 seg, int order, 200static struct mthca_mtt *__mthca_alloc_mtt(struct mthca_dev *dev, int size,
195 struct mthca_buddy* buddy) 201 struct mthca_buddy *buddy)
196{ 202{
197 mthca_buddy_free(buddy, seg, order); 203 struct mthca_mtt *mtt;
204 int i;
198 205
199 if (mthca_is_memfree(dev)) 206 if (size <= 0)
200 mthca_table_put_range(dev, dev->mr_table.mtt_table, seg, 207 return ERR_PTR(-EINVAL);
201 seg + (1 << order) - 1); 208
209 mtt = kmalloc(sizeof *mtt, GFP_KERNEL);
210 if (!mtt)
211 return ERR_PTR(-ENOMEM);
212
213 mtt->buddy = buddy;
214 mtt->order = 0;
215 for (i = MTHCA_MTT_SEG_SIZE / 8; i < size; i <<= 1)
216 ++mtt->order;
217
218 mtt->first_seg = mthca_alloc_mtt_range(dev, mtt->order, buddy);
219 if (mtt->first_seg == -1) {
220 kfree(mtt);
221 return ERR_PTR(-ENOMEM);
222 }
223
224 return mtt;
225}
226
227struct mthca_mtt *mthca_alloc_mtt(struct mthca_dev *dev, int size)
228{
229 return __mthca_alloc_mtt(dev, size, &dev->mr_table.mtt_buddy);
230}
231
232void mthca_free_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt)
233{
234 if (!mtt)
235 return;
236
237 mthca_buddy_free(mtt->buddy, mtt->first_seg, mtt->order);
238
239 mthca_table_put_range(dev, dev->mr_table.mtt_table,
240 mtt->first_seg,
241 mtt->first_seg + (1 << mtt->order) - 1);
242
243 kfree(mtt);
244}
245
246int mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt,
247 int start_index, u64 *buffer_list, int list_len)
248{
249 struct mthca_mailbox *mailbox;
250 u64 *mtt_entry;
251 int err = 0;
252 u8 status;
253 int i;
254
255 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
256 if (IS_ERR(mailbox))
257 return PTR_ERR(mailbox);
258 mtt_entry = mailbox->buf;
259
260 while (list_len > 0) {
261 mtt_entry[0] = cpu_to_be64(dev->mr_table.mtt_base +
262 mtt->first_seg * MTHCA_MTT_SEG_SIZE +
263 start_index * 8);
264 mtt_entry[1] = 0;
265 for (i = 0; i < list_len && i < MTHCA_MAILBOX_SIZE / 8 - 2; ++i)
266 mtt_entry[i + 2] = cpu_to_be64(buffer_list[i] |
267 MTHCA_MTT_FLAG_PRESENT);
268
269 /*
270 * If we have an odd number of entries to write, add
271 * one more dummy entry for firmware efficiency.
272 */
273 if (i & 1)
274 mtt_entry[i + 2] = 0;
275
276 err = mthca_WRITE_MTT(dev, mailbox, (i + 1) & ~1, &status);
277 if (err) {
278 mthca_warn(dev, "WRITE_MTT failed (%d)\n", err);
279 goto out;
280 }
281 if (status) {
282 mthca_warn(dev, "WRITE_MTT returned status 0x%02x\n",
283 status);
284 err = -EINVAL;
285 goto out;
286 }
287
288 list_len -= i;
289 start_index += i;
290 buffer_list += i;
291 }
292
293out:
294 mthca_free_mailbox(dev, mailbox);
295 return err;
202} 296}
203 297
204static inline u32 tavor_hw_index_to_key(u32 ind) 298static inline u32 tavor_hw_index_to_key(u32 ind)
@@ -237,91 +331,18 @@ static inline u32 key_to_hw_index(struct mthca_dev *dev, u32 key)
237 return tavor_key_to_hw_index(key); 331 return tavor_key_to_hw_index(key);
238} 332}
239 333
240int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd, 334int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
241 u32 access, struct mthca_mr *mr) 335 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
242{ 336{
243 void *mailbox = NULL; 337 struct mthca_mailbox *mailbox;
244 struct mthca_mpt_entry *mpt_entry; 338 struct mthca_mpt_entry *mpt_entry;
245 u32 key; 339 u32 key;
340 int i;
246 int err; 341 int err;
247 u8 status; 342 u8 status;
248 343
249 might_sleep(); 344 might_sleep();
250 345
251 mr->order = -1;
252 key = mthca_alloc(&dev->mr_table.mpt_alloc);
253 if (key == -1)
254 return -ENOMEM;
255 mr->ibmr.rkey = mr->ibmr.lkey = hw_index_to_key(dev, key);
256
257 if (mthca_is_memfree(dev)) {
258 err = mthca_table_get(dev, dev->mr_table.mpt_table, key);
259 if (err)
260 goto err_out_mpt_free;
261 }
262
263 mailbox = kmalloc(sizeof *mpt_entry + MTHCA_CMD_MAILBOX_EXTRA,
264 GFP_KERNEL);
265 if (!mailbox) {
266 err = -ENOMEM;
267 goto err_out_table;
268 }
269 mpt_entry = MAILBOX_ALIGN(mailbox);
270
271 mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS |
272 MTHCA_MPT_FLAG_MIO |
273 MTHCA_MPT_FLAG_PHYSICAL |
274 MTHCA_MPT_FLAG_REGION |
275 access);
276 mpt_entry->page_size = 0;
277 mpt_entry->key = cpu_to_be32(key);
278 mpt_entry->pd = cpu_to_be32(pd);
279 mpt_entry->start = 0;
280 mpt_entry->length = ~0ULL;
281
282 memset(&mpt_entry->lkey, 0,
283 sizeof *mpt_entry - offsetof(struct mthca_mpt_entry, lkey));
284
285 err = mthca_SW2HW_MPT(dev, mpt_entry,
286 key & (dev->limits.num_mpts - 1),
287 &status);
288 if (err) {
289 mthca_warn(dev, "SW2HW_MPT failed (%d)\n", err);
290 goto err_out_table;
291 } else if (status) {
292 mthca_warn(dev, "SW2HW_MPT returned status 0x%02x\n",
293 status);
294 err = -EINVAL;
295 goto err_out_table;
296 }
297
298 kfree(mailbox);
299 return err;
300
301err_out_table:
302 if (mthca_is_memfree(dev))
303 mthca_table_put(dev, dev->mr_table.mpt_table, key);
304
305err_out_mpt_free:
306 mthca_free(&dev->mr_table.mpt_alloc, key);
307 kfree(mailbox);
308 return err;
309}
310
311int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
312 u64 *buffer_list, int buffer_size_shift,
313 int list_len, u64 iova, u64 total_size,
314 u32 access, struct mthca_mr *mr)
315{
316 void *mailbox;
317 u64 *mtt_entry;
318 struct mthca_mpt_entry *mpt_entry;
319 u32 key;
320 int err = -ENOMEM;
321 u8 status;
322 int i;
323
324 might_sleep();
325 WARN_ON(buffer_size_shift >= 32); 346 WARN_ON(buffer_size_shift >= 32);
326 347
327 key = mthca_alloc(&dev->mr_table.mpt_alloc); 348 key = mthca_alloc(&dev->mr_table.mpt_alloc);
@@ -335,75 +356,33 @@ int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
335 goto err_out_mpt_free; 356 goto err_out_mpt_free;
336 } 357 }
337 358
338 for (i = MTHCA_MTT_SEG_SIZE / 8, mr->order = 0; 359 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
339 i < list_len; 360 if (IS_ERR(mailbox)) {
340 i <<= 1, ++mr->order) 361 err = PTR_ERR(mailbox);
341 ; /* nothing */
342
343 mr->first_seg = mthca_alloc_mtt(dev, mr->order,
344 &dev->mr_table.mtt_buddy);
345 if (mr->first_seg == -1)
346 goto err_out_table; 362 goto err_out_table;
347
348 /*
349 * If list_len is odd, we add one more dummy entry for
350 * firmware efficiency.
351 */
352 mailbox = kmalloc(max(sizeof *mpt_entry,
353 (size_t) 8 * (list_len + (list_len & 1) + 2)) +
354 MTHCA_CMD_MAILBOX_EXTRA,
355 GFP_KERNEL);
356 if (!mailbox)
357 goto err_out_free_mtt;
358
359 mtt_entry = MAILBOX_ALIGN(mailbox);
360
361 mtt_entry[0] = cpu_to_be64(dev->mr_table.mtt_base +
362 mr->first_seg * MTHCA_MTT_SEG_SIZE);
363 mtt_entry[1] = 0;
364 for (i = 0; i < list_len; ++i)
365 mtt_entry[i + 2] = cpu_to_be64(buffer_list[i] |
366 MTHCA_MTT_FLAG_PRESENT);
367 if (list_len & 1) {
368 mtt_entry[i + 2] = 0;
369 ++list_len;
370 }
371
372 if (0) {
373 mthca_dbg(dev, "Dumping MPT entry\n");
374 for (i = 0; i < list_len + 2; ++i)
375 printk(KERN_ERR "[%2d] %016llx\n",
376 i, (unsigned long long) be64_to_cpu(mtt_entry[i]));
377 }
378
379 err = mthca_WRITE_MTT(dev, mtt_entry, list_len, &status);
380 if (err) {
381 mthca_warn(dev, "WRITE_MTT failed (%d)\n", err);
382 goto err_out_mailbox_free;
383 }
384 if (status) {
385 mthca_warn(dev, "WRITE_MTT returned status 0x%02x\n",
386 status);
387 err = -EINVAL;
388 goto err_out_mailbox_free;
389 } 363 }
390 364 mpt_entry = mailbox->buf;
391 mpt_entry = MAILBOX_ALIGN(mailbox);
392 365
393 mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS | 366 mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS |
394 MTHCA_MPT_FLAG_MIO | 367 MTHCA_MPT_FLAG_MIO |
395 MTHCA_MPT_FLAG_REGION | 368 MTHCA_MPT_FLAG_REGION |
396 access); 369 access);
370 if (!mr->mtt)
371 mpt_entry->flags |= cpu_to_be32(MTHCA_MPT_FLAG_PHYSICAL);
397 372
398 mpt_entry->page_size = cpu_to_be32(buffer_size_shift - 12); 373 mpt_entry->page_size = cpu_to_be32(buffer_size_shift - 12);
399 mpt_entry->key = cpu_to_be32(key); 374 mpt_entry->key = cpu_to_be32(key);
400 mpt_entry->pd = cpu_to_be32(pd); 375 mpt_entry->pd = cpu_to_be32(pd);
401 mpt_entry->start = cpu_to_be64(iova); 376 mpt_entry->start = cpu_to_be64(iova);
402 mpt_entry->length = cpu_to_be64(total_size); 377 mpt_entry->length = cpu_to_be64(total_size);
378
403 memset(&mpt_entry->lkey, 0, 379 memset(&mpt_entry->lkey, 0,
404 sizeof *mpt_entry - offsetof(struct mthca_mpt_entry, lkey)); 380 sizeof *mpt_entry - offsetof(struct mthca_mpt_entry, lkey));
405 mpt_entry->mtt_seg = cpu_to_be64(dev->mr_table.mtt_base + 381
406 mr->first_seg * MTHCA_MTT_SEG_SIZE); 382 if (mr->mtt)
383 mpt_entry->mtt_seg =
384 cpu_to_be64(dev->mr_table.mtt_base +
385 mr->mtt->first_seg * MTHCA_MTT_SEG_SIZE);
407 386
408 if (0) { 387 if (0) {
409 mthca_dbg(dev, "Dumping MPT entry %08x:\n", mr->ibmr.lkey); 388 mthca_dbg(dev, "Dumping MPT entry %08x:\n", mr->ibmr.lkey);
@@ -416,45 +395,70 @@ int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
416 } 395 }
417 } 396 }
418 397
419 err = mthca_SW2HW_MPT(dev, mpt_entry, 398 err = mthca_SW2HW_MPT(dev, mailbox,
420 key & (dev->limits.num_mpts - 1), 399 key & (dev->limits.num_mpts - 1),
421 &status); 400 &status);
422 if (err) 401 if (err) {
423 mthca_warn(dev, "SW2HW_MPT failed (%d)\n", err); 402 mthca_warn(dev, "SW2HW_MPT failed (%d)\n", err);
424 else if (status) { 403 goto err_out_mailbox;
404 } else if (status) {
425 mthca_warn(dev, "SW2HW_MPT returned status 0x%02x\n", 405 mthca_warn(dev, "SW2HW_MPT returned status 0x%02x\n",
426 status); 406 status);
427 err = -EINVAL; 407 err = -EINVAL;
408 goto err_out_mailbox;
428 } 409 }
429 410
430 kfree(mailbox); 411 mthca_free_mailbox(dev, mailbox);
431 return err; 412 return err;
432 413
433err_out_mailbox_free: 414err_out_mailbox:
434 kfree(mailbox); 415 mthca_free_mailbox(dev, mailbox);
435
436err_out_free_mtt:
437 mthca_free_mtt(dev, mr->first_seg, mr->order, &dev->mr_table.mtt_buddy);
438 416
439err_out_table: 417err_out_table:
440 if (mthca_is_memfree(dev)) 418 mthca_table_put(dev, dev->mr_table.mpt_table, key);
441 mthca_table_put(dev, dev->mr_table.mpt_table, key);
442 419
443err_out_mpt_free: 420err_out_mpt_free:
444 mthca_free(&dev->mr_table.mpt_alloc, key); 421 mthca_free(&dev->mr_table.mpt_alloc, key);
445 return err; 422 return err;
446} 423}
447 424
448/* Free mr or fmr */ 425int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
449static void mthca_free_region(struct mthca_dev *dev, u32 lkey, int order, 426 u32 access, struct mthca_mr *mr)
450 u32 first_seg, struct mthca_buddy *buddy)
451{ 427{
452 if (order >= 0) 428 mr->mtt = NULL;
453 mthca_free_mtt(dev, first_seg, order, buddy); 429 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
430}
454 431
455 if (mthca_is_memfree(dev)) 432int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
456 mthca_table_put(dev, dev->mr_table.mpt_table, 433 u64 *buffer_list, int buffer_size_shift,
457 arbel_key_to_hw_index(lkey)); 434 int list_len, u64 iova, u64 total_size,
435 u32 access, struct mthca_mr *mr)
436{
437 int err;
438
439 mr->mtt = mthca_alloc_mtt(dev, list_len);
440 if (IS_ERR(mr->mtt))
441 return PTR_ERR(mr->mtt);
442
443 err = mthca_write_mtt(dev, mr->mtt, 0, buffer_list, list_len);
444 if (err) {
445 mthca_free_mtt(dev, mr->mtt);
446 return err;
447 }
448
449 err = mthca_mr_alloc(dev, pd, buffer_size_shift, iova,
450 total_size, access, mr);
451 if (err)
452 mthca_free_mtt(dev, mr->mtt);
453
454 return err;
455}
456
457/* Free mr or fmr */
458static void mthca_free_region(struct mthca_dev *dev, u32 lkey)
459{
460 mthca_table_put(dev, dev->mr_table.mpt_table,
461 arbel_key_to_hw_index(lkey));
458 462
459 mthca_free(&dev->mr_table.mpt_alloc, key_to_hw_index(dev, lkey)); 463 mthca_free(&dev->mr_table.mpt_alloc, key_to_hw_index(dev, lkey));
460} 464}
@@ -476,15 +480,15 @@ void mthca_free_mr(struct mthca_dev *dev, struct mthca_mr *mr)
476 mthca_warn(dev, "HW2SW_MPT returned status 0x%02x\n", 480 mthca_warn(dev, "HW2SW_MPT returned status 0x%02x\n",
477 status); 481 status);
478 482
479 mthca_free_region(dev, mr->ibmr.lkey, mr->order, mr->first_seg, 483 mthca_free_region(dev, mr->ibmr.lkey);
480 &dev->mr_table.mtt_buddy); 484 mthca_free_mtt(dev, mr->mtt);
481} 485}
482 486
483int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd, 487int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
484 u32 access, struct mthca_fmr *mr) 488 u32 access, struct mthca_fmr *mr)
485{ 489{
486 struct mthca_mpt_entry *mpt_entry; 490 struct mthca_mpt_entry *mpt_entry;
487 void *mailbox; 491 struct mthca_mailbox *mailbox;
488 u64 mtt_seg; 492 u64 mtt_seg;
489 u32 key, idx; 493 u32 key, idx;
490 u8 status; 494 u8 status;
@@ -522,31 +526,24 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
522 mr->mem.tavor.mpt = dev->mr_table.tavor_fmr.mpt_base + 526 mr->mem.tavor.mpt = dev->mr_table.tavor_fmr.mpt_base +
523 sizeof *(mr->mem.tavor.mpt) * idx; 527 sizeof *(mr->mem.tavor.mpt) * idx;
524 528
525 for (i = MTHCA_MTT_SEG_SIZE / 8, mr->order = 0; 529 mr->mtt = __mthca_alloc_mtt(dev, list_len, dev->mr_table.fmr_mtt_buddy);
526 i < list_len; 530 if (IS_ERR(mr->mtt))
527 i <<= 1, ++mr->order)
528 ; /* nothing */
529
530 mr->first_seg = mthca_alloc_mtt(dev, mr->order,
531 dev->mr_table.fmr_mtt_buddy);
532 if (mr->first_seg == -1)
533 goto err_out_table; 531 goto err_out_table;
534 532
535 mtt_seg = mr->first_seg * MTHCA_MTT_SEG_SIZE; 533 mtt_seg = mr->mtt->first_seg * MTHCA_MTT_SEG_SIZE;
536 534
537 if (mthca_is_memfree(dev)) { 535 if (mthca_is_memfree(dev)) {
538 mr->mem.arbel.mtts = mthca_table_find(dev->mr_table.mtt_table, 536 mr->mem.arbel.mtts = mthca_table_find(dev->mr_table.mtt_table,
539 mr->first_seg); 537 mr->mtt->first_seg);
540 BUG_ON(!mr->mem.arbel.mtts); 538 BUG_ON(!mr->mem.arbel.mtts);
541 } else 539 } else
542 mr->mem.tavor.mtts = dev->mr_table.tavor_fmr.mtt_base + mtt_seg; 540 mr->mem.tavor.mtts = dev->mr_table.tavor_fmr.mtt_base + mtt_seg;
543 541
544 mailbox = kmalloc(sizeof *mpt_entry + MTHCA_CMD_MAILBOX_EXTRA, 542 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
545 GFP_KERNEL); 543 if (IS_ERR(mailbox))
546 if (!mailbox)
547 goto err_out_free_mtt; 544 goto err_out_free_mtt;
548 545
549 mpt_entry = MAILBOX_ALIGN(mailbox); 546 mpt_entry = mailbox->buf;
550 547
551 mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS | 548 mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS |
552 MTHCA_MPT_FLAG_MIO | 549 MTHCA_MPT_FLAG_MIO |
@@ -571,7 +568,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
571 } 568 }
572 } 569 }
573 570
574 err = mthca_SW2HW_MPT(dev, mpt_entry, 571 err = mthca_SW2HW_MPT(dev, mailbox,
575 key & (dev->limits.num_mpts - 1), 572 key & (dev->limits.num_mpts - 1),
576 &status); 573 &status);
577 if (err) { 574 if (err) {
@@ -585,19 +582,17 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
585 goto err_out_mailbox_free; 582 goto err_out_mailbox_free;
586 } 583 }
587 584
588 kfree(mailbox); 585 mthca_free_mailbox(dev, mailbox);
589 return 0; 586 return 0;
590 587
591err_out_mailbox_free: 588err_out_mailbox_free:
592 kfree(mailbox); 589 mthca_free_mailbox(dev, mailbox);
593 590
594err_out_free_mtt: 591err_out_free_mtt:
595 mthca_free_mtt(dev, mr->first_seg, mr->order, 592 mthca_free_mtt(dev, mr->mtt);
596 dev->mr_table.fmr_mtt_buddy);
597 593
598err_out_table: 594err_out_table:
599 if (mthca_is_memfree(dev)) 595 mthca_table_put(dev, dev->mr_table.mpt_table, key);
600 mthca_table_put(dev, dev->mr_table.mpt_table, key);
601 596
602err_out_mpt_free: 597err_out_mpt_free:
603 mthca_free(&dev->mr_table.mpt_alloc, mr->ibmr.lkey); 598 mthca_free(&dev->mr_table.mpt_alloc, mr->ibmr.lkey);
@@ -609,8 +604,9 @@ int mthca_free_fmr(struct mthca_dev *dev, struct mthca_fmr *fmr)
609 if (fmr->maps) 604 if (fmr->maps)
610 return -EBUSY; 605 return -EBUSY;
611 606
612 mthca_free_region(dev, fmr->ibmr.lkey, fmr->order, fmr->first_seg, 607 mthca_free_region(dev, fmr->ibmr.lkey);
613 dev->mr_table.fmr_mtt_buddy); 608 mthca_free_mtt(dev, fmr->mtt);
609
614 return 0; 610 return 0;
615} 611}
616 612
@@ -826,7 +822,8 @@ int __devinit mthca_init_mr_table(struct mthca_dev *dev)
826 if (dev->limits.reserved_mtts) { 822 if (dev->limits.reserved_mtts) {
827 i = fls(dev->limits.reserved_mtts - 1); 823 i = fls(dev->limits.reserved_mtts - 1);
828 824
829 if (mthca_alloc_mtt(dev, i, dev->mr_table.fmr_mtt_buddy) == -1) { 825 if (mthca_alloc_mtt_range(dev, i,
826 dev->mr_table.fmr_mtt_buddy) == -1) {
830 mthca_warn(dev, "MTT table of order %d is too small.\n", 827 mthca_warn(dev, "MTT table of order %d is too small.\n",
831 dev->mr_table.fmr_mtt_buddy->max_order); 828 dev->mr_table.fmr_mtt_buddy->max_order);
832 err = -ENOMEM; 829 err = -ENOMEM;
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
index 159f4e6c312d..0b5adfd91597 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -1,5 +1,6 @@
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 * 4 *
4 * 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
5 * 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
@@ -52,7 +53,7 @@ static int mthca_query_device(struct ib_device *ibdev,
52 if (!in_mad || !out_mad) 53 if (!in_mad || !out_mad)
53 goto out; 54 goto out;
54 55
55 memset(props, 0, sizeof props); 56 memset(props, 0, sizeof *props);
56 57
57 props->fw_ver = mdev->fw_ver; 58 props->fw_ver = mdev->fw_ver;
58 59
@@ -558,6 +559,7 @@ static struct ib_mr *mthca_reg_phys_mr(struct ib_pd *pd,
558 convert_access(acc), mr); 559 convert_access(acc), mr);
559 560
560 if (err) { 561 if (err) {
562 kfree(page_list);
561 kfree(mr); 563 kfree(mr);
562 return ERR_PTR(err); 564 return ERR_PTR(err);
563 } 565 }
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.h b/drivers/infiniband/hw/mthca/mthca_provider.h
index 619710f95a87..4d976cccb1a8 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.h
+++ b/drivers/infiniband/hw/mthca/mthca_provider.h
@@ -54,18 +54,18 @@ struct mthca_uar {
54 int index; 54 int index;
55}; 55};
56 56
57struct mthca_mtt;
58
57struct mthca_mr { 59struct mthca_mr {
58 struct ib_mr ibmr; 60 struct ib_mr ibmr;
59 int order; 61 struct mthca_mtt *mtt;
60 u32 first_seg;
61}; 62};
62 63
63struct mthca_fmr { 64struct mthca_fmr {
64 struct ib_fmr ibmr; 65 struct ib_fmr ibmr;
65 struct ib_fmr_attr attr; 66 struct ib_fmr_attr attr;
66 int order; 67 struct mthca_mtt *mtt;
67 u32 first_seg; 68 int maps;
68 int maps;
69 union { 69 union {
70 struct { 70 struct {
71 struct mthca_mpt_entry __iomem *mpt; 71 struct mthca_mpt_entry __iomem *mpt;
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index ca73bab11a02..163a8ef4186f 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -357,6 +357,9 @@ static const struct {
357 [UD] = (IB_QP_PKEY_INDEX | 357 [UD] = (IB_QP_PKEY_INDEX |
358 IB_QP_PORT | 358 IB_QP_PORT |
359 IB_QP_QKEY), 359 IB_QP_QKEY),
360 [UC] = (IB_QP_PKEY_INDEX |
361 IB_QP_PORT |
362 IB_QP_ACCESS_FLAGS),
360 [RC] = (IB_QP_PKEY_INDEX | 363 [RC] = (IB_QP_PKEY_INDEX |
361 IB_QP_PORT | 364 IB_QP_PORT |
362 IB_QP_ACCESS_FLAGS), 365 IB_QP_ACCESS_FLAGS),
@@ -378,6 +381,9 @@ static const struct {
378 [UD] = (IB_QP_PKEY_INDEX | 381 [UD] = (IB_QP_PKEY_INDEX |
379 IB_QP_PORT | 382 IB_QP_PORT |
380 IB_QP_QKEY), 383 IB_QP_QKEY),
384 [UC] = (IB_QP_PKEY_INDEX |
385 IB_QP_PORT |
386 IB_QP_ACCESS_FLAGS),
381 [RC] = (IB_QP_PKEY_INDEX | 387 [RC] = (IB_QP_PKEY_INDEX |
382 IB_QP_PORT | 388 IB_QP_PORT |
383 IB_QP_ACCESS_FLAGS), 389 IB_QP_ACCESS_FLAGS),
@@ -388,6 +394,11 @@ static const struct {
388 [IB_QPS_RTR] = { 394 [IB_QPS_RTR] = {
389 .trans = MTHCA_TRANS_INIT2RTR, 395 .trans = MTHCA_TRANS_INIT2RTR,
390 .req_param = { 396 .req_param = {
397 [UC] = (IB_QP_AV |
398 IB_QP_PATH_MTU |
399 IB_QP_DEST_QPN |
400 IB_QP_RQ_PSN |
401 IB_QP_MAX_DEST_RD_ATOMIC),
391 [RC] = (IB_QP_AV | 402 [RC] = (IB_QP_AV |
392 IB_QP_PATH_MTU | 403 IB_QP_PATH_MTU |
393 IB_QP_DEST_QPN | 404 IB_QP_DEST_QPN |
@@ -398,6 +409,9 @@ static const struct {
398 .opt_param = { 409 .opt_param = {
399 [UD] = (IB_QP_PKEY_INDEX | 410 [UD] = (IB_QP_PKEY_INDEX |
400 IB_QP_QKEY), 411 IB_QP_QKEY),
412 [UC] = (IB_QP_ALT_PATH |
413 IB_QP_ACCESS_FLAGS |
414 IB_QP_PKEY_INDEX),
401 [RC] = (IB_QP_ALT_PATH | 415 [RC] = (IB_QP_ALT_PATH |
402 IB_QP_ACCESS_FLAGS | 416 IB_QP_ACCESS_FLAGS |
403 IB_QP_PKEY_INDEX), 417 IB_QP_PKEY_INDEX),
@@ -413,6 +427,8 @@ static const struct {
413 .trans = MTHCA_TRANS_RTR2RTS, 427 .trans = MTHCA_TRANS_RTR2RTS,
414 .req_param = { 428 .req_param = {
415 [UD] = IB_QP_SQ_PSN, 429 [UD] = IB_QP_SQ_PSN,
430 [UC] = (IB_QP_SQ_PSN |
431 IB_QP_MAX_QP_RD_ATOMIC),
416 [RC] = (IB_QP_TIMEOUT | 432 [RC] = (IB_QP_TIMEOUT |
417 IB_QP_RETRY_CNT | 433 IB_QP_RETRY_CNT |
418 IB_QP_RNR_RETRY | 434 IB_QP_RNR_RETRY |
@@ -423,6 +439,11 @@ static const struct {
423 .opt_param = { 439 .opt_param = {
424 [UD] = (IB_QP_CUR_STATE | 440 [UD] = (IB_QP_CUR_STATE |
425 IB_QP_QKEY), 441 IB_QP_QKEY),
442 [UC] = (IB_QP_CUR_STATE |
443 IB_QP_ALT_PATH |
444 IB_QP_ACCESS_FLAGS |
445 IB_QP_PKEY_INDEX |
446 IB_QP_PATH_MIG_STATE),
426 [RC] = (IB_QP_CUR_STATE | 447 [RC] = (IB_QP_CUR_STATE |
427 IB_QP_ALT_PATH | 448 IB_QP_ALT_PATH |
428 IB_QP_ACCESS_FLAGS | 449 IB_QP_ACCESS_FLAGS |
@@ -442,6 +463,9 @@ static const struct {
442 .opt_param = { 463 .opt_param = {
443 [UD] = (IB_QP_CUR_STATE | 464 [UD] = (IB_QP_CUR_STATE |
444 IB_QP_QKEY), 465 IB_QP_QKEY),
466 [UC] = (IB_QP_ACCESS_FLAGS |
467 IB_QP_ALT_PATH |
468 IB_QP_PATH_MIG_STATE),
445 [RC] = (IB_QP_ACCESS_FLAGS | 469 [RC] = (IB_QP_ACCESS_FLAGS |
446 IB_QP_ALT_PATH | 470 IB_QP_ALT_PATH |
447 IB_QP_PATH_MIG_STATE | 471 IB_QP_PATH_MIG_STATE |
@@ -462,6 +486,10 @@ static const struct {
462 .opt_param = { 486 .opt_param = {
463 [UD] = (IB_QP_CUR_STATE | 487 [UD] = (IB_QP_CUR_STATE |
464 IB_QP_QKEY), 488 IB_QP_QKEY),
489 [UC] = (IB_QP_CUR_STATE |
490 IB_QP_ALT_PATH |
491 IB_QP_ACCESS_FLAGS |
492 IB_QP_PATH_MIG_STATE),
465 [RC] = (IB_QP_CUR_STATE | 493 [RC] = (IB_QP_CUR_STATE |
466 IB_QP_ALT_PATH | 494 IB_QP_ALT_PATH |
467 IB_QP_ACCESS_FLAGS | 495 IB_QP_ACCESS_FLAGS |
@@ -476,6 +504,14 @@ static const struct {
476 .opt_param = { 504 .opt_param = {
477 [UD] = (IB_QP_PKEY_INDEX | 505 [UD] = (IB_QP_PKEY_INDEX |
478 IB_QP_QKEY), 506 IB_QP_QKEY),
507 [UC] = (IB_QP_AV |
508 IB_QP_MAX_QP_RD_ATOMIC |
509 IB_QP_MAX_DEST_RD_ATOMIC |
510 IB_QP_CUR_STATE |
511 IB_QP_ALT_PATH |
512 IB_QP_ACCESS_FLAGS |
513 IB_QP_PKEY_INDEX |
514 IB_QP_PATH_MIG_STATE),
479 [RC] = (IB_QP_AV | 515 [RC] = (IB_QP_AV |
480 IB_QP_TIMEOUT | 516 IB_QP_TIMEOUT |
481 IB_QP_RETRY_CNT | 517 IB_QP_RETRY_CNT |
@@ -501,6 +537,7 @@ static const struct {
501 .opt_param = { 537 .opt_param = {
502 [UD] = (IB_QP_CUR_STATE | 538 [UD] = (IB_QP_CUR_STATE |
503 IB_QP_QKEY), 539 IB_QP_QKEY),
540 [UC] = (IB_QP_CUR_STATE),
504 [RC] = (IB_QP_CUR_STATE | 541 [RC] = (IB_QP_CUR_STATE |
505 IB_QP_MIN_RNR_TIMER), 542 IB_QP_MIN_RNR_TIMER),
506 [MLX] = (IB_QP_CUR_STATE | 543 [MLX] = (IB_QP_CUR_STATE |
@@ -552,7 +589,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
552 struct mthca_dev *dev = to_mdev(ibqp->device); 589 struct mthca_dev *dev = to_mdev(ibqp->device);
553 struct mthca_qp *qp = to_mqp(ibqp); 590 struct mthca_qp *qp = to_mqp(ibqp);
554 enum ib_qp_state cur_state, new_state; 591 enum ib_qp_state cur_state, new_state;
555 void *mailbox = NULL; 592 struct mthca_mailbox *mailbox;
556 struct mthca_qp_param *qp_param; 593 struct mthca_qp_param *qp_param;
557 struct mthca_qp_context *qp_context; 594 struct mthca_qp_context *qp_context;
558 u32 req_param, opt_param; 595 u32 req_param, opt_param;
@@ -609,10 +646,10 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
609 return -EINVAL; 646 return -EINVAL;
610 } 647 }
611 648
612 mailbox = kmalloc(sizeof (*qp_param) + MTHCA_CMD_MAILBOX_EXTRA, GFP_KERNEL); 649 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
613 if (!mailbox) 650 if (IS_ERR(mailbox))
614 return -ENOMEM; 651 return PTR_ERR(mailbox);
615 qp_param = MAILBOX_ALIGN(mailbox); 652 qp_param = mailbox->buf;
616 qp_context = &qp_param->context; 653 qp_context = &qp_param->context;
617 memset(qp_param, 0, sizeof *qp_param); 654 memset(qp_param, 0, sizeof *qp_param);
618 655
@@ -683,7 +720,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
683 if (attr_mask & IB_QP_AV) { 720 if (attr_mask & IB_QP_AV) {
684 qp_context->pri_path.g_mylmc = attr->ah_attr.src_path_bits & 0x7f; 721 qp_context->pri_path.g_mylmc = attr->ah_attr.src_path_bits & 0x7f;
685 qp_context->pri_path.rlid = cpu_to_be16(attr->ah_attr.dlid); 722 qp_context->pri_path.rlid = cpu_to_be16(attr->ah_attr.dlid);
686 qp_context->pri_path.static_rate = (!!attr->ah_attr.static_rate) << 3; 723 qp_context->pri_path.static_rate = !!attr->ah_attr.static_rate;
687 if (attr->ah_attr.ah_flags & IB_AH_GRH) { 724 if (attr->ah_attr.ah_flags & IB_AH_GRH) {
688 qp_context->pri_path.g_mylmc |= 1 << 7; 725 qp_context->pri_path.g_mylmc |= 1 << 7;
689 qp_context->pri_path.mgid_index = attr->ah_attr.grh.sgid_index; 726 qp_context->pri_path.mgid_index = attr->ah_attr.grh.sgid_index;
@@ -724,9 +761,9 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
724 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RETRY_COUNT); 761 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RETRY_COUNT);
725 } 762 }
726 763
727 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) { 764 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) {
728 qp_context->params1 |= cpu_to_be32(min(attr->max_dest_rd_atomic ? 765 qp_context->params1 |= cpu_to_be32(min(attr->max_rd_atomic ?
729 ffs(attr->max_dest_rd_atomic) - 1 : 0, 766 ffs(attr->max_rd_atomic) - 1 : 0,
730 7) << 21); 767 7) << 21);
731 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_SRA_MAX); 768 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_SRA_MAX);
732 } 769 }
@@ -764,10 +801,10 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
764 qp->atomic_rd_en = attr->qp_access_flags; 801 qp->atomic_rd_en = attr->qp_access_flags;
765 } 802 }
766 803
767 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) { 804 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) {
768 u8 rra_max; 805 u8 rra_max;
769 806
770 if (qp->resp_depth && !attr->max_rd_atomic) { 807 if (qp->resp_depth && !attr->max_dest_rd_atomic) {
771 /* 808 /*
772 * Lowering our responder resources to zero. 809 * Lowering our responder resources to zero.
773 * Turn off RDMA/atomics as responder. 810 * Turn off RDMA/atomics as responder.
@@ -778,7 +815,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
778 MTHCA_QP_OPTPAR_RAE); 815 MTHCA_QP_OPTPAR_RAE);
779 } 816 }
780 817
781 if (!qp->resp_depth && attr->max_rd_atomic) { 818 if (!qp->resp_depth && attr->max_dest_rd_atomic) {
782 /* 819 /*
783 * Increasing our responder resources from 820 * Increasing our responder resources from
784 * zero. Turn on RDMA/atomics as appropriate. 821 * zero. Turn on RDMA/atomics as appropriate.
@@ -799,7 +836,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
799 } 836 }
800 837
801 for (rra_max = 0; 838 for (rra_max = 0;
802 1 << rra_max < attr->max_rd_atomic && 839 1 << rra_max < attr->max_dest_rd_atomic &&
803 rra_max < dev->qp_table.rdb_shift; 840 rra_max < dev->qp_table.rdb_shift;
804 ++rra_max) 841 ++rra_max)
805 ; /* nothing */ 842 ; /* nothing */
@@ -807,7 +844,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
807 qp_context->params2 |= cpu_to_be32(rra_max << 21); 844 qp_context->params2 |= cpu_to_be32(rra_max << 21);
808 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RRA_MAX); 845 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RRA_MAX);
809 846
810 qp->resp_depth = attr->max_rd_atomic; 847 qp->resp_depth = attr->max_dest_rd_atomic;
811 } 848 }
812 849
813 qp_context->params2 |= cpu_to_be32(MTHCA_QP_BIT_RSC); 850 qp_context->params2 |= cpu_to_be32(MTHCA_QP_BIT_RSC);
@@ -835,7 +872,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
835 } 872 }
836 873
837 err = mthca_MODIFY_QP(dev, state_table[cur_state][new_state].trans, 874 err = mthca_MODIFY_QP(dev, state_table[cur_state][new_state].trans,
838 qp->qpn, 0, qp_param, 0, &status); 875 qp->qpn, 0, mailbox, 0, &status);
839 if (status) { 876 if (status) {
840 mthca_warn(dev, "modify QP %d returned status %02x.\n", 877 mthca_warn(dev, "modify QP %d returned status %02x.\n",
841 state_table[cur_state][new_state].trans, status); 878 state_table[cur_state][new_state].trans, status);
@@ -845,7 +882,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
845 if (!err) 882 if (!err)
846 qp->state = new_state; 883 qp->state = new_state;
847 884
848 kfree(mailbox); 885 mthca_free_mailbox(dev, mailbox);
849 886
850 if (is_sqp(dev, qp)) 887 if (is_sqp(dev, qp))
851 store_attrs(to_msqp(qp), attr, attr_mask); 888 store_attrs(to_msqp(qp), attr, attr_mask);
@@ -934,7 +971,8 @@ static int mthca_alloc_wqe_buf(struct mthca_dev *dev,
934 mthca_dbg(dev, "Creating direct QP of size %d (shift %d)\n", 971 mthca_dbg(dev, "Creating direct QP of size %d (shift %d)\n",
935 size, shift); 972 size, shift);
936 973
937 qp->queue.direct.buf = pci_alloc_consistent(dev->pdev, size, &t); 974 qp->queue.direct.buf = dma_alloc_coherent(&dev->pdev->dev, size,
975 &t, GFP_KERNEL);
938 if (!qp->queue.direct.buf) 976 if (!qp->queue.direct.buf)
939 goto err_out; 977 goto err_out;
940 978
@@ -973,7 +1011,8 @@ static int mthca_alloc_wqe_buf(struct mthca_dev *dev,
973 1011
974 for (i = 0; i < npages; ++i) { 1012 for (i = 0; i < npages; ++i) {
975 qp->queue.page_list[i].buf = 1013 qp->queue.page_list[i].buf =
976 pci_alloc_consistent(dev->pdev, PAGE_SIZE, &t); 1014 dma_alloc_coherent(&dev->pdev->dev, PAGE_SIZE,
1015 &t, GFP_KERNEL);
977 if (!qp->queue.page_list[i].buf) 1016 if (!qp->queue.page_list[i].buf)
978 goto err_out_free; 1017 goto err_out_free;
979 1018
@@ -996,16 +1035,15 @@ static int mthca_alloc_wqe_buf(struct mthca_dev *dev,
996 1035
997 err_out_free: 1036 err_out_free:
998 if (qp->is_direct) { 1037 if (qp->is_direct) {
999 pci_free_consistent(dev->pdev, size, 1038 dma_free_coherent(&dev->pdev->dev, size, qp->queue.direct.buf,
1000 qp->queue.direct.buf, 1039 pci_unmap_addr(&qp->queue.direct, mapping));
1001 pci_unmap_addr(&qp->queue.direct, mapping));
1002 } else 1040 } else
1003 for (i = 0; i < npages; ++i) { 1041 for (i = 0; i < npages; ++i) {
1004 if (qp->queue.page_list[i].buf) 1042 if (qp->queue.page_list[i].buf)
1005 pci_free_consistent(dev->pdev, PAGE_SIZE, 1043 dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
1006 qp->queue.page_list[i].buf, 1044 qp->queue.page_list[i].buf,
1007 pci_unmap_addr(&qp->queue.page_list[i], 1045 pci_unmap_addr(&qp->queue.page_list[i],
1008 mapping)); 1046 mapping));
1009 1047
1010 } 1048 }
1011 1049
@@ -1073,11 +1111,12 @@ static void mthca_free_memfree(struct mthca_dev *dev,
1073 if (mthca_is_memfree(dev)) { 1111 if (mthca_is_memfree(dev)) {
1074 mthca_free_db(dev, MTHCA_DB_TYPE_SQ, qp->sq.db_index); 1112 mthca_free_db(dev, MTHCA_DB_TYPE_SQ, qp->sq.db_index);
1075 mthca_free_db(dev, MTHCA_DB_TYPE_RQ, qp->rq.db_index); 1113 mthca_free_db(dev, MTHCA_DB_TYPE_RQ, qp->rq.db_index);
1076 mthca_table_put(dev, dev->qp_table.rdb_table,
1077 qp->qpn << dev->qp_table.rdb_shift);
1078 mthca_table_put(dev, dev->qp_table.eqp_table, qp->qpn);
1079 mthca_table_put(dev, dev->qp_table.qp_table, qp->qpn);
1080 } 1114 }
1115
1116 mthca_table_put(dev, dev->qp_table.rdb_table,
1117 qp->qpn << dev->qp_table.rdb_shift);
1118 mthca_table_put(dev, dev->qp_table.eqp_table, qp->qpn);
1119 mthca_table_put(dev, dev->qp_table.qp_table, qp->qpn);
1081} 1120}
1082 1121
1083static void mthca_wq_init(struct mthca_wq* wq) 1122static void mthca_wq_init(struct mthca_wq* wq)
@@ -1529,6 +1568,26 @@ int mthca_tavor_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1529 1568
1530 break; 1569 break;
1531 1570
1571 case UC:
1572 switch (wr->opcode) {
1573 case IB_WR_RDMA_WRITE:
1574 case IB_WR_RDMA_WRITE_WITH_IMM:
1575 ((struct mthca_raddr_seg *) wqe)->raddr =
1576 cpu_to_be64(wr->wr.rdma.remote_addr);
1577 ((struct mthca_raddr_seg *) wqe)->rkey =
1578 cpu_to_be32(wr->wr.rdma.rkey);
1579 ((struct mthca_raddr_seg *) wqe)->reserved = 0;
1580 wqe += sizeof (struct mthca_raddr_seg);
1581 size += sizeof (struct mthca_raddr_seg) / 16;
1582 break;
1583
1584 default:
1585 /* No extra segments required for sends */
1586 break;
1587 }
1588
1589 break;
1590
1532 case UD: 1591 case UD:
1533 ((struct mthca_tavor_ud_seg *) wqe)->lkey = 1592 ((struct mthca_tavor_ud_seg *) wqe)->lkey =
1534 cpu_to_be32(to_mah(wr->wr.ud.ah)->key); 1593 cpu_to_be32(to_mah(wr->wr.ud.ah)->key);
@@ -1814,9 +1873,29 @@ int mthca_arbel_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1814 sizeof (struct mthca_atomic_seg); 1873 sizeof (struct mthca_atomic_seg);
1815 break; 1874 break;
1816 1875
1876 case IB_WR_RDMA_READ:
1877 case IB_WR_RDMA_WRITE:
1878 case IB_WR_RDMA_WRITE_WITH_IMM:
1879 ((struct mthca_raddr_seg *) wqe)->raddr =
1880 cpu_to_be64(wr->wr.rdma.remote_addr);
1881 ((struct mthca_raddr_seg *) wqe)->rkey =
1882 cpu_to_be32(wr->wr.rdma.rkey);
1883 ((struct mthca_raddr_seg *) wqe)->reserved = 0;
1884 wqe += sizeof (struct mthca_raddr_seg);
1885 size += sizeof (struct mthca_raddr_seg) / 16;
1886 break;
1887
1888 default:
1889 /* No extra segments required for sends */
1890 break;
1891 }
1892
1893 break;
1894
1895 case UC:
1896 switch (wr->opcode) {
1817 case IB_WR_RDMA_WRITE: 1897 case IB_WR_RDMA_WRITE:
1818 case IB_WR_RDMA_WRITE_WITH_IMM: 1898 case IB_WR_RDMA_WRITE_WITH_IMM:
1819 case IB_WR_RDMA_READ:
1820 ((struct mthca_raddr_seg *) wqe)->raddr = 1899 ((struct mthca_raddr_seg *) wqe)->raddr =
1821 cpu_to_be64(wr->wr.rdma.remote_addr); 1900 cpu_to_be64(wr->wr.rdma.remote_addr);
1822 ((struct mthca_raddr_seg *) wqe)->rkey = 1901 ((struct mthca_raddr_seg *) wqe)->rkey =
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 556264b43425..374f404e81da 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -21,6 +21,7 @@
21#include <linux/smp_lock.h> 21#include <linux/smp_lock.h>
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/devfs_fs_kernel.h> 23#include <linux/devfs_fs_kernel.h>
24#include <linux/compat.h>
24 25
25struct evdev { 26struct evdev {
26 int exist; 27 int exist;
@@ -145,6 +146,41 @@ static int evdev_open(struct inode * inode, struct file * file)
145 return 0; 146 return 0;
146} 147}
147 148
149#ifdef CONFIG_COMPAT
150struct input_event_compat {
151 struct compat_timeval time;
152 __u16 type;
153 __u16 code;
154 __s32 value;
155};
156
157#ifdef CONFIG_X86_64
158# define COMPAT_TEST test_thread_flag(TIF_IA32)
159#elif defined(CONFIG_IA64)
160# define COMPAT_TEST IS_IA32_PROCESS(ia64_task_regs(current))
161#elif defined(CONFIG_ARCH_S390)
162# define COMPAT_TEST test_thread_flag(TIF_31BIT)
163#else
164# define COMPAT_TEST test_thread_flag(TIF_32BIT)
165#endif
166
167static ssize_t evdev_write_compat(struct file * file, const char __user * buffer, size_t count, loff_t *ppos)
168{
169 struct evdev_list *list = file->private_data;
170 struct input_event_compat event;
171 int retval = 0;
172
173 while (retval < count) {
174 if (copy_from_user(&event, buffer + retval, sizeof(struct input_event_compat)))
175 return -EFAULT;
176 input_event(list->evdev->handle.dev, event.type, event.code, event.value);
177 retval += sizeof(struct input_event_compat);
178 }
179
180 return retval;
181}
182#endif
183
148static ssize_t evdev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) 184static ssize_t evdev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos)
149{ 185{
150 struct evdev_list *list = file->private_data; 186 struct evdev_list *list = file->private_data;
@@ -153,6 +189,11 @@ static ssize_t evdev_write(struct file * file, const char __user * buffer, size_
153 189
154 if (!list->evdev->exist) return -ENODEV; 190 if (!list->evdev->exist) return -ENODEV;
155 191
192#ifdef CONFIG_COMPAT
193 if (COMPAT_TEST)
194 return evdev_write_compat(file, buffer, count, ppos);
195#endif
196
156 while (retval < count) { 197 while (retval < count) {
157 198
158 if (copy_from_user(&event, buffer + retval, sizeof(struct input_event))) 199 if (copy_from_user(&event, buffer + retval, sizeof(struct input_event)))
@@ -164,11 +205,56 @@ static ssize_t evdev_write(struct file * file, const char __user * buffer, size_
164 return retval; 205 return retval;
165} 206}
166 207
208#ifdef CONFIG_COMPAT
209static ssize_t evdev_read_compat(struct file * file, char __user * buffer, size_t count, loff_t *ppos)
210{
211 struct evdev_list *list = file->private_data;
212 int retval;
213
214 if (count < sizeof(struct input_event_compat))
215 return -EINVAL;
216
217 if (list->head == list->tail && list->evdev->exist && (file->f_flags & O_NONBLOCK))
218 return -EAGAIN;
219
220 retval = wait_event_interruptible(list->evdev->wait,
221 list->head != list->tail || (!list->evdev->exist));
222
223 if (retval)
224 return retval;
225
226 if (!list->evdev->exist)
227 return -ENODEV;
228
229 while (list->head != list->tail && retval + sizeof(struct input_event_compat) <= count) {
230 struct input_event *event = (struct input_event *) list->buffer + list->tail;
231 struct input_event_compat event_compat;
232 event_compat.time.tv_sec = event->time.tv_sec;
233 event_compat.time.tv_usec = event->time.tv_usec;
234 event_compat.type = event->type;
235 event_compat.code = event->code;
236 event_compat.value = event->value;
237
238 if (copy_to_user(buffer + retval, &event_compat,
239 sizeof(struct input_event_compat))) return -EFAULT;
240 list->tail = (list->tail + 1) & (EVDEV_BUFFER_SIZE - 1);
241 retval += sizeof(struct input_event_compat);
242 }
243
244 return retval;
245}
246#endif
247
167static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos) 248static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos)
168{ 249{
169 struct evdev_list *list = file->private_data; 250 struct evdev_list *list = file->private_data;
170 int retval; 251 int retval;
171 252
253#ifdef CONFIG_COMPAT
254 if (COMPAT_TEST)
255 return evdev_read_compat(file, buffer, count, ppos);
256#endif
257
172 if (count < sizeof(struct input_event)) 258 if (count < sizeof(struct input_event))
173 return -EINVAL; 259 return -EINVAL;
174 260
@@ -186,7 +272,7 @@ static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count
186 272
187 while (list->head != list->tail && retval + sizeof(struct input_event) <= count) { 273 while (list->head != list->tail && retval + sizeof(struct input_event) <= count) {
188 if (copy_to_user(buffer + retval, list->buffer + list->tail, 274 if (copy_to_user(buffer + retval, list->buffer + list->tail,
189 sizeof(struct input_event))) return -EFAULT; 275 sizeof(struct input_event))) return -EFAULT;
190 list->tail = (list->tail + 1) & (EVDEV_BUFFER_SIZE - 1); 276 list->tail = (list->tail + 1) & (EVDEV_BUFFER_SIZE - 1);
191 retval += sizeof(struct input_event); 277 retval += sizeof(struct input_event);
192 } 278 }
@@ -203,7 +289,7 @@ static unsigned int evdev_poll(struct file *file, poll_table *wait)
203 (list->evdev->exist ? 0 : (POLLHUP | POLLERR)); 289 (list->evdev->exist ? 0 : (POLLHUP | POLLERR));
204} 290}
205 291
206static int evdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 292static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
207{ 293{
208 struct evdev_list *list = file->private_data; 294 struct evdev_list *list = file->private_data;
209 struct evdev *evdev = list->evdev; 295 struct evdev *evdev = list->evdev;
@@ -285,109 +371,267 @@ static int evdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
285 371
286 default: 372 default:
287 373
288 if (_IOC_TYPE(cmd) != 'E' || _IOC_DIR(cmd) != _IOC_READ) 374 if (_IOC_TYPE(cmd) != 'E')
289 return -EINVAL; 375 return -EINVAL;
290 376
291 if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0,0))) { 377 if (_IOC_DIR(cmd) == _IOC_READ) {
292 378
293 long *bits; 379 if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0,0))) {
294 int len; 380
295 381 long *bits;
296 switch (_IOC_NR(cmd) & EV_MAX) { 382 int len;
297 case 0: bits = dev->evbit; len = EV_MAX; break; 383
298 case EV_KEY: bits = dev->keybit; len = KEY_MAX; break; 384 switch (_IOC_NR(cmd) & EV_MAX) {
299 case EV_REL: bits = dev->relbit; len = REL_MAX; break; 385 case 0: bits = dev->evbit; len = EV_MAX; break;
300 case EV_ABS: bits = dev->absbit; len = ABS_MAX; break; 386 case EV_KEY: bits = dev->keybit; len = KEY_MAX; break;
301 case EV_MSC: bits = dev->mscbit; len = MSC_MAX; break; 387 case EV_REL: bits = dev->relbit; len = REL_MAX; break;
302 case EV_LED: bits = dev->ledbit; len = LED_MAX; break; 388 case EV_ABS: bits = dev->absbit; len = ABS_MAX; break;
303 case EV_SND: bits = dev->sndbit; len = SND_MAX; break; 389 case EV_MSC: bits = dev->mscbit; len = MSC_MAX; break;
304 case EV_FF: bits = dev->ffbit; len = FF_MAX; break; 390 case EV_LED: bits = dev->ledbit; len = LED_MAX; break;
305 default: return -EINVAL; 391 case EV_SND: bits = dev->sndbit; len = SND_MAX; break;
392 case EV_FF: bits = dev->ffbit; len = FF_MAX; break;
393 default: return -EINVAL;
394 }
395 len = NBITS(len) * sizeof(long);
396 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
397 return copy_to_user(p, bits, len) ? -EFAULT : len;
306 } 398 }
307 len = NBITS(len) * sizeof(long);
308 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
309 return copy_to_user(p, bits, len) ? -EFAULT : len;
310 }
311 399
312 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0))) { 400 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0))) {
313 int len; 401 int len;
314 len = NBITS(KEY_MAX) * sizeof(long); 402 len = NBITS(KEY_MAX) * sizeof(long);
315 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); 403 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
316 return copy_to_user(p, dev->key, len) ? -EFAULT : len; 404 return copy_to_user(p, dev->key, len) ? -EFAULT : len;
317 } 405 }
318 406
319 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0))) { 407 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0))) {
320 int len; 408 int len;
321 len = NBITS(LED_MAX) * sizeof(long); 409 len = NBITS(LED_MAX) * sizeof(long);
322 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); 410 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
323 return copy_to_user(p, dev->led, len) ? -EFAULT : len; 411 return copy_to_user(p, dev->led, len) ? -EFAULT : len;
324 } 412 }
325 413
326 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0))) { 414 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0))) {
327 int len; 415 int len;
328 len = NBITS(SND_MAX) * sizeof(long); 416 len = NBITS(SND_MAX) * sizeof(long);
329 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); 417 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
330 return copy_to_user(p, dev->snd, len) ? -EFAULT : len; 418 return copy_to_user(p, dev->snd, len) ? -EFAULT : len;
331 } 419 }
332 420
333 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) { 421 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) {
334 int len; 422 int len;
335 if (!dev->name) return -ENOENT; 423 if (!dev->name) return -ENOENT;
336 len = strlen(dev->name) + 1; 424 len = strlen(dev->name) + 1;
337 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); 425 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
338 return copy_to_user(p, dev->name, len) ? -EFAULT : len; 426 return copy_to_user(p, dev->name, len) ? -EFAULT : len;
339 } 427 }
428
429 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) {
430 int len;
431 if (!dev->phys) return -ENOENT;
432 len = strlen(dev->phys) + 1;
433 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
434 return copy_to_user(p, dev->phys, len) ? -EFAULT : len;
435 }
436
437 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) {
438 int len;
439 if (!dev->uniq) return -ENOENT;
440 len = strlen(dev->uniq) + 1;
441 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
442 return copy_to_user(p, dev->uniq, len) ? -EFAULT : len;
443 }
444
445 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) {
446
447 int t = _IOC_NR(cmd) & ABS_MAX;
448
449 abs.value = dev->abs[t];
450 abs.minimum = dev->absmin[t];
451 abs.maximum = dev->absmax[t];
452 abs.fuzz = dev->absfuzz[t];
453 abs.flat = dev->absflat[t];
454
455 if (copy_to_user(p, &abs, sizeof(struct input_absinfo)))
456 return -EFAULT;
457
458 return 0;
459 }
340 460
341 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) {
342 int len;
343 if (!dev->phys) return -ENOENT;
344 len = strlen(dev->phys) + 1;
345 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
346 return copy_to_user(p, dev->phys, len) ? -EFAULT : len;
347 } 461 }
348 462
349 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) { 463 if (_IOC_DIR(cmd) == _IOC_WRITE) {
350 int len; 464
351 if (!dev->uniq) return -ENOENT; 465 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) {
352 len = strlen(dev->uniq) + 1; 466
353 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); 467 int t = _IOC_NR(cmd) & ABS_MAX;
354 return copy_to_user(p, dev->uniq, len) ? -EFAULT : len; 468
469 if (copy_from_user(&abs, p, sizeof(struct input_absinfo)))
470 return -EFAULT;
471
472 dev->abs[t] = abs.value;
473 dev->absmin[t] = abs.minimum;
474 dev->absmax[t] = abs.maximum;
475 dev->absfuzz[t] = abs.fuzz;
476 dev->absflat[t] = abs.flat;
477
478 return 0;
479 }
355 } 480 }
481 }
482 return -EINVAL;
483}
356 484
357 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) { 485#ifdef CONFIG_COMPAT
486
487#define BITS_PER_LONG_COMPAT (sizeof(compat_long_t) * 8)
488#define NBITS_COMPAT(x) ((((x)-1)/BITS_PER_LONG_COMPAT)+1)
489#define OFF_COMPAT(x) ((x)%BITS_PER_LONG_COMPAT)
490#define BIT_COMPAT(x) (1UL<<OFF_COMPAT(x))
491#define LONG_COMPAT(x) ((x)/BITS_PER_LONG_COMPAT)
492#define test_bit_compat(bit, array) ((array[LONG_COMPAT(bit)] >> OFF_COMPAT(bit)) & 1)
493
494#ifdef __BIG_ENDIAN
495#define bit_to_user(bit, max) \
496do { \
497 int i; \
498 int len = NBITS_COMPAT((max)) * sizeof(compat_long_t); \
499 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); \
500 for (i = 0; i < len / sizeof(compat_long_t); i++) \
501 if (copy_to_user((compat_long_t*) p + i, \
502 (compat_long_t*) (bit) + i + 1 - ((i % 2) << 1), \
503 sizeof(compat_long_t))) \
504 return -EFAULT; \
505 return len; \
506} while (0)
507#else
508#define bit_to_user(bit, max) \
509do { \
510 int len = NBITS_COMPAT((max)) * sizeof(compat_long_t); \
511 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); \
512 return copy_to_user(p, (bit), len) ? -EFAULT : len; \
513} while (0)
514#endif
515
516static long evdev_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
517{
518 struct evdev_list *list = file->private_data;
519 struct evdev *evdev = list->evdev;
520 struct input_dev *dev = evdev->handle.dev;
521 struct input_absinfo abs;
522 void __user *p = compat_ptr(arg);
358 523
359 int t = _IOC_NR(cmd) & ABS_MAX; 524 if (!evdev->exist) return -ENODEV;
360 525
361 abs.value = dev->abs[t]; 526 switch (cmd) {
362 abs.minimum = dev->absmin[t];
363 abs.maximum = dev->absmax[t];
364 abs.fuzz = dev->absfuzz[t];
365 abs.flat = dev->absflat[t];
366 527
367 if (copy_to_user(p, &abs, sizeof(struct input_absinfo))) 528 case EVIOCGVERSION:
368 return -EFAULT; 529 case EVIOCGID:
530 case EVIOCGKEYCODE:
531 case EVIOCSKEYCODE:
532 case EVIOCSFF:
533 case EVIOCRMFF:
534 case EVIOCGEFFECTS:
535 case EVIOCGRAB:
536 return evdev_ioctl(file, cmd, (unsigned long) p);
369 537
370 return 0; 538 default:
539
540 if (_IOC_TYPE(cmd) != 'E')
541 return -EINVAL;
542
543 if (_IOC_DIR(cmd) == _IOC_READ) {
544
545 if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0,0))) {
546 long *bits;
547 int max;
548
549 switch (_IOC_NR(cmd) & EV_MAX) {
550 case 0: bits = dev->evbit; max = EV_MAX; break;
551 case EV_KEY: bits = dev->keybit; max = KEY_MAX; break;
552 case EV_REL: bits = dev->relbit; max = REL_MAX; break;
553 case EV_ABS: bits = dev->absbit; max = ABS_MAX; break;
554 case EV_MSC: bits = dev->mscbit; max = MSC_MAX; break;
555 case EV_LED: bits = dev->ledbit; max = LED_MAX; break;
556 case EV_SND: bits = dev->sndbit; max = SND_MAX; break;
557 case EV_FF: bits = dev->ffbit; max = FF_MAX; break;
558 default: return -EINVAL;
559 }
560 bit_to_user(bits, max);
561 }
562
563 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0)))
564 bit_to_user(dev->key, KEY_MAX);
565
566 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0)))
567 bit_to_user(dev->led, LED_MAX);
568
569 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0)))
570 bit_to_user(dev->snd, SND_MAX);
571
572 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) {
573 int len;
574 if (!dev->name) return -ENOENT;
575 len = strlen(dev->name) + 1;
576 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
577 return copy_to_user(p, dev->name, len) ? -EFAULT : len;
578 }
579
580 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) {
581 int len;
582 if (!dev->phys) return -ENOENT;
583 len = strlen(dev->phys) + 1;
584 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
585 return copy_to_user(p, dev->phys, len) ? -EFAULT : len;
586 }
587
588 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) {
589 int len;
590 if (!dev->uniq) return -ENOENT;
591 len = strlen(dev->uniq) + 1;
592 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
593 return copy_to_user(p, dev->uniq, len) ? -EFAULT : len;
594 }
595
596 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) {
597
598 int t = _IOC_NR(cmd) & ABS_MAX;
599
600 abs.value = dev->abs[t];
601 abs.minimum = dev->absmin[t];
602 abs.maximum = dev->absmax[t];
603 abs.fuzz = dev->absfuzz[t];
604 abs.flat = dev->absflat[t];
605
606 if (copy_to_user(p, &abs, sizeof(struct input_absinfo)))
607 return -EFAULT;
608
609 return 0;
610 }
371 } 611 }
372 612
373 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) { 613 if (_IOC_DIR(cmd) == _IOC_WRITE) {
374 614
375 int t = _IOC_NR(cmd) & ABS_MAX; 615 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) {
376 616
377 if (copy_from_user(&abs, p, sizeof(struct input_absinfo))) 617 int t = _IOC_NR(cmd) & ABS_MAX;
378 return -EFAULT;
379 618
380 dev->abs[t] = abs.value; 619 if (copy_from_user(&abs, p, sizeof(struct input_absinfo)))
381 dev->absmin[t] = abs.minimum; 620 return -EFAULT;
382 dev->absmax[t] = abs.maximum;
383 dev->absfuzz[t] = abs.fuzz;
384 dev->absflat[t] = abs.flat;
385 621
386 return 0; 622 dev->abs[t] = abs.value;
623 dev->absmin[t] = abs.minimum;
624 dev->absmax[t] = abs.maximum;
625 dev->absfuzz[t] = abs.fuzz;
626 dev->absflat[t] = abs.flat;
627
628 return 0;
629 }
387 } 630 }
388 } 631 }
389 return -EINVAL; 632 return -EINVAL;
390} 633}
634#endif
391 635
392static struct file_operations evdev_fops = { 636static struct file_operations evdev_fops = {
393 .owner = THIS_MODULE, 637 .owner = THIS_MODULE,
@@ -396,7 +640,10 @@ static struct file_operations evdev_fops = {
396 .poll = evdev_poll, 640 .poll = evdev_poll,
397 .open = evdev_open, 641 .open = evdev_open,
398 .release = evdev_release, 642 .release = evdev_release,
399 .ioctl = evdev_ioctl, 643 .unlocked_ioctl = evdev_ioctl,
644#ifdef CONFIG_COMPAT
645 .compat_ioctl = evdev_ioctl_compat,
646#endif
400 .fasync = evdev_fasync, 647 .fasync = evdev_fasync,
401 .flush = evdev_flush 648 .flush = evdev_flush
402}; 649};
diff --git a/drivers/input/gameport/Kconfig b/drivers/input/gameport/Kconfig
index 1d93f5092904..7524bd7d8b8f 100644
--- a/drivers/input/gameport/Kconfig
+++ b/drivers/input/gameport/Kconfig
@@ -49,22 +49,8 @@ config GAMEPORT_EMU10K1
49 To compile this driver as a module, choose M here: the 49 To compile this driver as a module, choose M here: the
50 module will be called emu10k1-gp. 50 module will be called emu10k1-gp.
51 51
52config GAMEPORT_VORTEX
53 tristate "Aureal Vortex, Vortex 2 gameport support"
54 depends on PCI
55 help
56 Say Y here if you have an Aureal Vortex 1 or 2 card and want
57 to use its gameport.
58
59 To compile this driver as a module, choose M here: the
60 module will be called vortex.
61
62config GAMEPORT_FM801 52config GAMEPORT_FM801
63 tristate "ForteMedia FM801 gameport support" 53 tristate "ForteMedia FM801 gameport support"
64 depends on PCI 54 depends on PCI
65 55
66config GAMEPORT_CS461X
67 tristate "Crystal SoundFusion gameport support"
68 depends on PCI
69
70endif 56endif
diff --git a/drivers/input/gameport/Makefile b/drivers/input/gameport/Makefile
index 5367b4267adf..b6f6097bd8c4 100644
--- a/drivers/input/gameport/Makefile
+++ b/drivers/input/gameport/Makefile
@@ -5,9 +5,7 @@
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7obj-$(CONFIG_GAMEPORT) += gameport.o 7obj-$(CONFIG_GAMEPORT) += gameport.o
8obj-$(CONFIG_GAMEPORT_CS461X) += cs461x.o
9obj-$(CONFIG_GAMEPORT_EMU10K1) += emu10k1-gp.o 8obj-$(CONFIG_GAMEPORT_EMU10K1) += emu10k1-gp.o
10obj-$(CONFIG_GAMEPORT_FM801) += fm801-gp.o 9obj-$(CONFIG_GAMEPORT_FM801) += fm801-gp.o
11obj-$(CONFIG_GAMEPORT_L4) += lightning.o 10obj-$(CONFIG_GAMEPORT_L4) += lightning.o
12obj-$(CONFIG_GAMEPORT_NS558) += ns558.o 11obj-$(CONFIG_GAMEPORT_NS558) += ns558.o
13obj-$(CONFIG_GAMEPORT_VORTEX) += vortex.o
diff --git a/drivers/input/gameport/cs461x.c b/drivers/input/gameport/cs461x.c
deleted file mode 100644
index d4013ff98623..000000000000
--- a/drivers/input/gameport/cs461x.c
+++ /dev/null
@@ -1,322 +0,0 @@
1/*
2 The all defines and part of code (such as cs461x_*) are
3 contributed from ALSA 0.5.8 sources.
4 See http://www.alsa-project.org/ for sources
5
6 Tested on Linux 686 2.4.0-test9, ALSA 0.5.8a and CS4610
7*/
8
9#include <asm/io.h>
10
11#include <linux/module.h>
12#include <linux/ioport.h>
13#include <linux/config.h>
14#include <linux/init.h>
15#include <linux/gameport.h>
16#include <linux/slab.h>
17#include <linux/pci.h>
18
19MODULE_AUTHOR("Victor Krapivin");
20MODULE_LICENSE("GPL");
21
22/*
23 These options are experimental
24
25#define CS461X_FULL_MAP
26*/
27
28
29#ifndef PCI_VENDOR_ID_CIRRUS
30#define PCI_VENDOR_ID_CIRRUS 0x1013
31#endif
32#ifndef PCI_DEVICE_ID_CIRRUS_4610
33#define PCI_DEVICE_ID_CIRRUS_4610 0x6001
34#endif
35#ifndef PCI_DEVICE_ID_CIRRUS_4612
36#define PCI_DEVICE_ID_CIRRUS_4612 0x6003
37#endif
38#ifndef PCI_DEVICE_ID_CIRRUS_4615
39#define PCI_DEVICE_ID_CIRRUS_4615 0x6004
40#endif
41
42/* Registers */
43
44#define BA0_JSPT 0x00000480
45#define BA0_JSCTL 0x00000484
46#define BA0_JSC1 0x00000488
47#define BA0_JSC2 0x0000048C
48#define BA0_JSIO 0x000004A0
49
50/* Bits for JSPT */
51
52#define JSPT_CAX 0x00000001
53#define JSPT_CAY 0x00000002
54#define JSPT_CBX 0x00000004
55#define JSPT_CBY 0x00000008
56#define JSPT_BA1 0x00000010
57#define JSPT_BA2 0x00000020
58#define JSPT_BB1 0x00000040
59#define JSPT_BB2 0x00000080
60
61/* Bits for JSCTL */
62
63#define JSCTL_SP_MASK 0x00000003
64#define JSCTL_SP_SLOW 0x00000000
65#define JSCTL_SP_MEDIUM_SLOW 0x00000001
66#define JSCTL_SP_MEDIUM_FAST 0x00000002
67#define JSCTL_SP_FAST 0x00000003
68#define JSCTL_ARE 0x00000004
69
70/* Data register pairs masks */
71
72#define JSC1_Y1V_MASK 0x0000FFFF
73#define JSC1_X1V_MASK 0xFFFF0000
74#define JSC1_Y1V_SHIFT 0
75#define JSC1_X1V_SHIFT 16
76#define JSC2_Y2V_MASK 0x0000FFFF
77#define JSC2_X2V_MASK 0xFFFF0000
78#define JSC2_Y2V_SHIFT 0
79#define JSC2_X2V_SHIFT 16
80
81/* JS GPIO */
82
83#define JSIO_DAX 0x00000001
84#define JSIO_DAY 0x00000002
85#define JSIO_DBX 0x00000004
86#define JSIO_DBY 0x00000008
87#define JSIO_AXOE 0x00000010
88#define JSIO_AYOE 0x00000020
89#define JSIO_BXOE 0x00000040
90#define JSIO_BYOE 0x00000080
91
92/*
93 The card initialization code is obfuscated; the module cs461x
94 need to be loaded after ALSA modules initialized and something
95 played on the CS 4610 chip (see sources for details of CS4610
96 initialization code from ALSA)
97*/
98
99/* Card specific definitions */
100
101#define CS461X_BA0_SIZE 0x2000
102#define CS461X_BA1_DATA0_SIZE 0x3000
103#define CS461X_BA1_DATA1_SIZE 0x3800
104#define CS461X_BA1_PRG_SIZE 0x7000
105#define CS461X_BA1_REG_SIZE 0x0100
106
107#define BA1_SP_DMEM0 0x00000000
108#define BA1_SP_DMEM1 0x00010000
109#define BA1_SP_PMEM 0x00020000
110#define BA1_SP_REG 0x00030000
111
112#define BA1_DWORD_SIZE (13 * 1024 + 512)
113#define BA1_MEMORY_COUNT 3
114
115/*
116 Only one CS461x card is still suppoted; the code requires
117 redesign to avoid this limitatuion.
118*/
119
120static unsigned long ba0_addr;
121static unsigned int __iomem *ba0;
122
123#ifdef CS461X_FULL_MAP
124static unsigned long ba1_addr;
125static union ba1_t {
126 struct {
127 unsigned int __iomem *data0;
128 unsigned int __iomem *data1;
129 unsigned int __iomem *pmem;
130 unsigned int __iomem *reg;
131 } name;
132 unsigned int __iomem *idx[4];
133} ba1;
134
135static void cs461x_poke(unsigned long reg, unsigned int val)
136{
137 writel(val, &ba1.idx[(reg >> 16) & 3][(reg >> 2) & 0x3fff]);
138}
139
140static unsigned int cs461x_peek(unsigned long reg)
141{
142 return readl(&ba1.idx[(reg >> 16) & 3][(reg >> 2) & 0x3fff]);
143}
144
145#endif
146
147static void cs461x_pokeBA0(unsigned long reg, unsigned int val)
148{
149 writel(val, &ba0[reg >> 2]);
150}
151
152static unsigned int cs461x_peekBA0(unsigned long reg)
153{
154 return readl(&ba0[reg >> 2]);
155}
156
157static int cs461x_free(struct pci_dev *pdev)
158{
159 struct gameport *port = pci_get_drvdata(pdev);
160
161 if (port)
162 gameport_unregister_port(port);
163
164 if (ba0) iounmap(ba0);
165#ifdef CS461X_FULL_MAP
166 if (ba1.name.data0) iounmap(ba1.name.data0);
167 if (ba1.name.data1) iounmap(ba1.name.data1);
168 if (ba1.name.pmem) iounmap(ba1.name.pmem);
169 if (ba1.name.reg) iounmap(ba1.name.reg);
170#endif
171 return 0;
172}
173
174static void cs461x_gameport_trigger(struct gameport *gameport)
175{
176 cs461x_pokeBA0(BA0_JSPT, 0xFF); //outb(gameport->io, 0xFF);
177}
178
179static unsigned char cs461x_gameport_read(struct gameport *gameport)
180{
181 return cs461x_peekBA0(BA0_JSPT); //inb(gameport->io);
182}
183
184static int cs461x_gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
185{
186 unsigned js1, js2, jst;
187
188 js1 = cs461x_peekBA0(BA0_JSC1);
189 js2 = cs461x_peekBA0(BA0_JSC2);
190 jst = cs461x_peekBA0(BA0_JSPT);
191
192 *buttons = (~jst >> 4) & 0x0F;
193
194 axes[0] = ((js1 & JSC1_Y1V_MASK) >> JSC1_Y1V_SHIFT) & 0xFFFF;
195 axes[1] = ((js1 & JSC1_X1V_MASK) >> JSC1_X1V_SHIFT) & 0xFFFF;
196 axes[2] = ((js2 & JSC2_Y2V_MASK) >> JSC2_Y2V_SHIFT) & 0xFFFF;
197 axes[3] = ((js2 & JSC2_X2V_MASK) >> JSC2_X2V_SHIFT) & 0xFFFF;
198
199 for(jst=0;jst<4;++jst)
200 if(axes[jst]==0xFFFF) axes[jst] = -1;
201 return 0;
202}
203
204static int cs461x_gameport_open(struct gameport *gameport, int mode)
205{
206 switch (mode) {
207 case GAMEPORT_MODE_COOKED:
208 case GAMEPORT_MODE_RAW:
209 return 0;
210 default:
211 return -1;
212 }
213 return 0;
214}
215
216static struct pci_device_id cs461x_pci_tbl[] = {
217 { PCI_VENDOR_ID_CIRRUS, 0x6001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Cirrus CS4610 */
218 { PCI_VENDOR_ID_CIRRUS, 0x6003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Cirrus CS4612 */
219 { PCI_VENDOR_ID_CIRRUS, 0x6005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Cirrus CS4615 */
220 { 0, }
221};
222MODULE_DEVICE_TABLE(pci, cs461x_pci_tbl);
223
224static int __devinit cs461x_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
225{
226 int rc;
227 struct gameport* port;
228
229 rc = pci_enable_device(pdev);
230 if (rc) {
231 printk(KERN_ERR "cs461x: Cannot enable PCI gameport (bus %d, devfn %d) error=%d\n",
232 pdev->bus->number, pdev->devfn, rc);
233 return rc;
234 }
235
236 ba0_addr = pci_resource_start(pdev, 0);
237#ifdef CS461X_FULL_MAP
238 ba1_addr = pci_resource_start(pdev, 1);
239#endif
240 if (ba0_addr == 0 || ba0_addr == ~0
241#ifdef CS461X_FULL_MAP
242 || ba1_addr == 0 || ba1_addr == ~0
243#endif
244 ) {
245 printk(KERN_ERR "cs461x: wrong address - ba0 = 0x%lx\n", ba0_addr);
246#ifdef CS461X_FULL_MAP
247 printk(KERN_ERR "cs461x: wrong address - ba1 = 0x%lx\n", ba1_addr);
248#endif
249 cs461x_free(pdev);
250 return -ENOMEM;
251 }
252
253 ba0 = ioremap(ba0_addr, CS461X_BA0_SIZE);
254#ifdef CS461X_FULL_MAP
255 ba1.name.data0 = ioremap(ba1_addr + BA1_SP_DMEM0, CS461X_BA1_DATA0_SIZE);
256 ba1.name.data1 = ioremap(ba1_addr + BA1_SP_DMEM1, CS461X_BA1_DATA1_SIZE);
257 ba1.name.pmem = ioremap(ba1_addr + BA1_SP_PMEM, CS461X_BA1_PRG_SIZE);
258 ba1.name.reg = ioremap(ba1_addr + BA1_SP_REG, CS461X_BA1_REG_SIZE);
259
260 if (ba0 == NULL || ba1.name.data0 == NULL ||
261 ba1.name.data1 == NULL || ba1.name.pmem == NULL ||
262 ba1.name.reg == NULL) {
263 cs461x_free(pdev);
264 return -ENOMEM;
265 }
266#else
267 if (ba0 == NULL) {
268 cs461x_free(pdev);
269 return -ENOMEM;
270 }
271#endif
272
273 if (!(port = gameport_allocate_port())) {
274 printk(KERN_ERR "cs461x: Memory allocation failed\n");
275 cs461x_free(pdev);
276 return -ENOMEM;
277 }
278
279 pci_set_drvdata(pdev, port);
280
281 port->open = cs461x_gameport_open;
282 port->trigger = cs461x_gameport_trigger;
283 port->read = cs461x_gameport_read;
284 port->cooked_read = cs461x_gameport_cooked_read;
285
286 gameport_set_name(port, "CS416x");
287 gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
288 port->dev.parent = &pdev->dev;
289
290 cs461x_pokeBA0(BA0_JSIO, 0xFF); // ?
291 cs461x_pokeBA0(BA0_JSCTL, JSCTL_SP_MEDIUM_SLOW);
292
293 gameport_register_port(port);
294
295 return 0;
296}
297
298static void __devexit cs461x_pci_remove(struct pci_dev *pdev)
299{
300 cs461x_free(pdev);
301}
302
303static struct pci_driver cs461x_pci_driver = {
304 .name = "CS461x_gameport",
305 .id_table = cs461x_pci_tbl,
306 .probe = cs461x_pci_probe,
307 .remove = __devexit_p(cs461x_pci_remove),
308};
309
310static int __init cs461x_init(void)
311{
312 return pci_register_driver(&cs461x_pci_driver);
313}
314
315static void __exit cs461x_exit(void)
316{
317 pci_unregister_driver(&cs461x_pci_driver);
318}
319
320module_init(cs461x_init);
321module_exit(cs461x_exit);
322
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
index c77a82e46055..3e72c9b1461e 100644
--- a/drivers/input/gameport/gameport.c
+++ b/drivers/input/gameport/gameport.c
@@ -17,11 +17,10 @@
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/gameport.h> 18#include <linux/gameport.h>
19#include <linux/wait.h> 19#include <linux/wait.h>
20#include <linux/completion.h>
21#include <linux/sched.h> 20#include <linux/sched.h>
22#include <linux/smp_lock.h>
23#include <linux/slab.h> 21#include <linux/slab.h>
24#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/kthread.h>
25 24
26/*#include <asm/io.h>*/ 25/*#include <asm/io.h>*/
27 26
@@ -238,8 +237,7 @@ struct gameport_event {
238static DEFINE_SPINLOCK(gameport_event_lock); /* protects gameport_event_list */ 237static DEFINE_SPINLOCK(gameport_event_lock); /* protects gameport_event_list */
239static LIST_HEAD(gameport_event_list); 238static LIST_HEAD(gameport_event_list);
240static DECLARE_WAIT_QUEUE_HEAD(gameport_wait); 239static DECLARE_WAIT_QUEUE_HEAD(gameport_wait);
241static DECLARE_COMPLETION(gameport_exited); 240static struct task_struct *gameport_task;
242static int gameport_pid;
243 241
244static void gameport_queue_event(void *object, struct module *owner, 242static void gameport_queue_event(void *object, struct module *owner,
245 enum gameport_event_type event_type) 243 enum gameport_event_type event_type)
@@ -250,12 +248,12 @@ static void gameport_queue_event(void *object, struct module *owner,
250 spin_lock_irqsave(&gameport_event_lock, flags); 248 spin_lock_irqsave(&gameport_event_lock, flags);
251 249
252 /* 250 /*
253 * Scan event list for the other events for the same gameport port, 251 * Scan event list for the other events for the same gameport port,
254 * starting with the most recent one. If event is the same we 252 * starting with the most recent one. If event is the same we
255 * do not need add new one. If event is of different type we 253 * do not need add new one. If event is of different type we
256 * need to add this event and should not look further because 254 * need to add this event and should not look further because
257 * we need to preseve sequence of distinct events. 255 * we need to preseve sequence of distinct events.
258 */ 256 */
259 list_for_each_entry_reverse(event, &gameport_event_list, node) { 257 list_for_each_entry_reverse(event, &gameport_event_list, node) {
260 if (event->object == object) { 258 if (event->object == object) {
261 if (event->type == event_type) 259 if (event->type == event_type)
@@ -432,20 +430,15 @@ static struct gameport *gameport_get_pending_child(struct gameport *parent)
432 430
433static int gameport_thread(void *nothing) 431static int gameport_thread(void *nothing)
434{ 432{
435 lock_kernel();
436 daemonize("kgameportd");
437 allow_signal(SIGTERM);
438
439 do { 433 do {
440 gameport_handle_events(); 434 gameport_handle_events();
441 wait_event_interruptible(gameport_wait, !list_empty(&gameport_event_list)); 435 wait_event_interruptible(gameport_wait,
436 kthread_should_stop() || !list_empty(&gameport_event_list));
442 try_to_freeze(); 437 try_to_freeze();
443 } while (!signal_pending(current)); 438 } while (!kthread_should_stop());
444 439
445 printk(KERN_DEBUG "gameport: kgameportd exiting\n"); 440 printk(KERN_DEBUG "gameport: kgameportd exiting\n");
446 441 return 0;
447 unlock_kernel();
448 complete_and_exit(&gameport_exited, 0);
449} 442}
450 443
451 444
@@ -773,9 +766,10 @@ void gameport_close(struct gameport *gameport)
773 766
774static int __init gameport_init(void) 767static int __init gameport_init(void)
775{ 768{
776 if (!(gameport_pid = kernel_thread(gameport_thread, NULL, CLONE_KERNEL))) { 769 gameport_task = kthread_run(gameport_thread, NULL, "kgameportd");
770 if (IS_ERR(gameport_task)) {
777 printk(KERN_ERR "gameport: Failed to start kgameportd\n"); 771 printk(KERN_ERR "gameport: Failed to start kgameportd\n");
778 return -1; 772 return PTR_ERR(gameport_task);
779 } 773 }
780 774
781 gameport_bus.dev_attrs = gameport_device_attrs; 775 gameport_bus.dev_attrs = gameport_device_attrs;
@@ -789,8 +783,7 @@ static int __init gameport_init(void)
789static void __exit gameport_exit(void) 783static void __exit gameport_exit(void)
790{ 784{
791 bus_unregister(&gameport_bus); 785 bus_unregister(&gameport_bus);
792 kill_proc(gameport_pid, SIGTERM, 1); 786 kthread_stop(gameport_task);
793 wait_for_completion(&gameport_exited);
794} 787}
795 788
796module_init(gameport_init); 789module_init(gameport_init);
diff --git a/drivers/input/gameport/ns558.c b/drivers/input/gameport/ns558.c
index 7c5c6318eeb9..1ab5f2dc8a2a 100644
--- a/drivers/input/gameport/ns558.c
+++ b/drivers/input/gameport/ns558.c
@@ -258,18 +258,18 @@ static int __init ns558_init(void)
258{ 258{
259 int i = 0; 259 int i = 0;
260 260
261 if (pnp_register_driver(&ns558_pnp_driver) >= 0)
262 pnp_registered = 1;
263
261/* 264/*
262 * Probe ISA ports first so that PnP gets to choose free port addresses 265 * Probe ISA ports after PnP, so that PnP ports that are already
263 * not occupied by the ISA ports. 266 * enabled get detected as PnP. This may be suboptimal in multi-device
267 * configurations, but saves hassle with simple setups.
264 */ 268 */
265 269
266 while (ns558_isa_portlist[i]) 270 while (ns558_isa_portlist[i])
267 ns558_isa_probe(ns558_isa_portlist[i++]); 271 ns558_isa_probe(ns558_isa_portlist[i++]);
268 272
269 if (pnp_register_driver(&ns558_pnp_driver) >= 0)
270 pnp_registered = 1;
271
272
273 return (list_empty(&ns558_list) && !pnp_registered) ? -ENODEV : 0; 273 return (list_empty(&ns558_list) && !pnp_registered) ? -ENODEV : 0;
274} 274}
275 275
diff --git a/drivers/input/gameport/vortex.c b/drivers/input/gameport/vortex.c
deleted file mode 100644
index 36b0309c8bf6..000000000000
--- a/drivers/input/gameport/vortex.c
+++ /dev/null
@@ -1,186 +0,0 @@
1/*
2 * $Id: vortex.c,v 1.5 2002/07/01 15:39:30 vojtech Exp $
3 *
4 * Copyright (c) 2000-2001 Vojtech Pavlik
5 *
6 * Based on the work of:
7 * Raymond Ingles
8 */
9
10/*
11 * Trident 4DWave and Aureal Vortex gameport driver for Linux
12 */
13
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 * Should you need to contact me, the author, you can do so either by
30 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
31 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
32 */
33
34#include <asm/io.h>
35#include <linux/delay.h>
36#include <linux/errno.h>
37#include <linux/ioport.h>
38#include <linux/kernel.h>
39#include <linux/module.h>
40#include <linux/pci.h>
41#include <linux/init.h>
42#include <linux/slab.h>
43#include <linux/delay.h>
44#include <linux/gameport.h>
45
46MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
47MODULE_DESCRIPTION("Aureal Vortex and Vortex2 gameport driver");
48MODULE_LICENSE("GPL");
49
50#define VORTEX_GCR 0x0c /* Gameport control register */
51#define VORTEX_LEG 0x08 /* Legacy port location */
52#define VORTEX_AXD 0x10 /* Axes start */
53#define VORTEX_DATA_WAIT 20 /* 20 ms */
54
55struct vortex {
56 struct gameport *gameport;
57 struct pci_dev *dev;
58 unsigned char __iomem *base;
59 unsigned char __iomem *io;
60};
61
62static unsigned char vortex_read(struct gameport *gameport)
63{
64 struct vortex *vortex = gameport->port_data;
65 return readb(vortex->io + VORTEX_LEG);
66}
67
68static void vortex_trigger(struct gameport *gameport)
69{
70 struct vortex *vortex = gameport->port_data;
71 writeb(0xff, vortex->io + VORTEX_LEG);
72}
73
74static int vortex_cooked_read(struct gameport *gameport, int *axes, int *buttons)
75{
76 struct vortex *vortex = gameport->port_data;
77 int i;
78
79 *buttons = (~readb(vortex->base + VORTEX_LEG) >> 4) & 0xf;
80
81 for (i = 0; i < 4; i++) {
82 axes[i] = readw(vortex->io + VORTEX_AXD + i * sizeof(u32));
83 if (axes[i] == 0x1fff) axes[i] = -1;
84 }
85
86 return 0;
87}
88
89static int vortex_open(struct gameport *gameport, int mode)
90{
91 struct vortex *vortex = gameport->port_data;
92
93 switch (mode) {
94 case GAMEPORT_MODE_COOKED:
95 writeb(0x40, vortex->io + VORTEX_GCR);
96 msleep(VORTEX_DATA_WAIT);
97 return 0;
98 case GAMEPORT_MODE_RAW:
99 writeb(0x00, vortex->io + VORTEX_GCR);
100 return 0;
101 default:
102 return -1;
103 }
104
105 return 0;
106}
107
108static int __devinit vortex_probe(struct pci_dev *dev, const struct pci_device_id *id)
109{
110 struct vortex *vortex;
111 struct gameport *port;
112 int i;
113
114 vortex = kcalloc(1, sizeof(struct vortex), GFP_KERNEL);
115 port = gameport_allocate_port();
116 if (!vortex || !port) {
117 printk(KERN_ERR "vortex: Memory allocation failed.\n");
118 kfree(vortex);
119 gameport_free_port(port);
120 return -ENOMEM;
121 }
122
123 for (i = 0; i < 6; i++)
124 if (~pci_resource_flags(dev, i) & IORESOURCE_IO)
125 break;
126
127 pci_enable_device(dev);
128
129 vortex->dev = dev;
130 vortex->gameport = port;
131 vortex->base = ioremap(pci_resource_start(vortex->dev, i),
132 pci_resource_len(vortex->dev, i));
133 vortex->io = vortex->base + id->driver_data;
134
135 pci_set_drvdata(dev, vortex);
136
137 port->port_data = vortex;
138 port->fuzz = 64;
139
140 gameport_set_name(port, "AU88x0");
141 gameport_set_phys(port, "pci%s/gameport0", pci_name(dev));
142 port->dev.parent = &dev->dev;
143 port->read = vortex_read;
144 port->trigger = vortex_trigger;
145 port->cooked_read = vortex_cooked_read;
146 port->open = vortex_open;
147
148 gameport_register_port(port);
149
150 return 0;
151}
152
153static void __devexit vortex_remove(struct pci_dev *dev)
154{
155 struct vortex *vortex = pci_get_drvdata(dev);
156
157 gameport_unregister_port(vortex->gameport);
158 iounmap(vortex->base);
159 kfree(vortex);
160}
161
162static struct pci_device_id vortex_id_table[] = {
163 { 0x12eb, 0x0001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x11000 },
164 { 0x12eb, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x28800 },
165 { 0 }
166};
167
168static struct pci_driver vortex_driver = {
169 .name = "vortex_gameport",
170 .id_table = vortex_id_table,
171 .probe = vortex_probe,
172 .remove = __devexit_p(vortex_remove),
173};
174
175static int __init vortex_init(void)
176{
177 return pci_register_driver(&vortex_driver);
178}
179
180static void __exit vortex_exit(void)
181{
182 pci_unregister_driver(&vortex_driver);
183}
184
185module_init(vortex_init);
186module_exit(vortex_exit);
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 83c77c990dda..7c4b4d37b3e6 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -219,10 +219,24 @@ void input_release_device(struct input_handle *handle)
219 219
220int input_open_device(struct input_handle *handle) 220int input_open_device(struct input_handle *handle)
221{ 221{
222 struct input_dev *dev = handle->dev;
223 int err;
224
225 err = down_interruptible(&dev->sem);
226 if (err)
227 return err;
228
222 handle->open++; 229 handle->open++;
223 if (handle->dev->open) 230
224 return handle->dev->open(handle->dev); 231 if (!dev->users++ && dev->open)
225 return 0; 232 err = dev->open(dev);
233
234 if (err)
235 handle->open--;
236
237 up(&dev->sem);
238
239 return err;
226} 240}
227 241
228int input_flush_device(struct input_handle* handle, struct file* file) 242int input_flush_device(struct input_handle* handle, struct file* file)
@@ -235,10 +249,17 @@ int input_flush_device(struct input_handle* handle, struct file* file)
235 249
236void input_close_device(struct input_handle *handle) 250void input_close_device(struct input_handle *handle)
237{ 251{
252 struct input_dev *dev = handle->dev;
253
238 input_release_device(handle); 254 input_release_device(handle);
239 if (handle->dev->close) 255
240 handle->dev->close(handle->dev); 256 down(&dev->sem);
257
258 if (!--dev->users && dev->close)
259 dev->close(dev);
241 handle->open--; 260 handle->open--;
261
262 up(&dev->sem);
242} 263}
243 264
244static void input_link_handle(struct input_handle *handle) 265static void input_link_handle(struct input_handle *handle)
@@ -415,6 +436,8 @@ void input_register_device(struct input_dev *dev)
415 436
416 set_bit(EV_SYN, dev->evbit); 437 set_bit(EV_SYN, dev->evbit);
417 438
439 init_MUTEX(&dev->sem);
440
418 /* 441 /*
419 * If delay and period are pre-set by the driver, then autorepeating 442 * If delay and period are pre-set by the driver, then autorepeating
420 * is handled by the driver itself and we don't do it in input.c. 443 * is handled by the driver itself and we don't do it in input.c.
@@ -674,6 +697,8 @@ static int input_handlers_read(char *buf, char **start, off_t pos, int count, in
674 return (count > cnt) ? cnt : count; 697 return (count > cnt) ? cnt : count;
675} 698}
676 699
700static struct file_operations input_fileops;
701
677static int __init input_proc_init(void) 702static int __init input_proc_init(void)
678{ 703{
679 struct proc_dir_entry *entry; 704 struct proc_dir_entry *entry;
@@ -688,6 +713,8 @@ static int __init input_proc_init(void)
688 return -ENOMEM; 713 return -ENOMEM;
689 } 714 }
690 entry->owner = THIS_MODULE; 715 entry->owner = THIS_MODULE;
716 input_fileops = *entry->proc_fops;
717 entry->proc_fops = &input_fileops;
691 entry->proc_fops->poll = input_devices_poll; 718 entry->proc_fops->poll = input_devices_poll;
692 entry = create_proc_read_entry("handlers", 0, proc_bus_input_dir, input_handlers_read, NULL); 719 entry = create_proc_read_entry("handlers", 0, proc_bus_input_dir, input_handlers_read, NULL);
693 if (entry == NULL) { 720 if (entry == NULL) {
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index 39775fc380c7..ff8e1bbd0e13 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -285,48 +285,33 @@ static unsigned int joydev_poll(struct file *file, poll_table *wait)
285 (POLLIN | POLLRDNORM) : 0) | (list->joydev->exist ? 0 : (POLLHUP | POLLERR)); 285 (POLLIN | POLLRDNORM) : 0) | (list->joydev->exist ? 0 : (POLLHUP | POLLERR));
286} 286}
287 287
288static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 288static int joydev_ioctl_common(struct joydev *joydev, unsigned int cmd, void __user *argp)
289{ 289{
290 struct joydev_list *list = file->private_data;
291 struct joydev *joydev = list->joydev;
292 struct input_dev *dev = joydev->handle.dev; 290 struct input_dev *dev = joydev->handle.dev;
293 void __user *argp = (void __user *)arg;
294 int i, j; 291 int i, j;
295 292
296 if (!joydev->exist) return -ENODEV;
297
298 switch (cmd) { 293 switch (cmd) {
299 294
300 case JS_SET_CAL: 295 case JS_SET_CAL:
301 return copy_from_user(&joydev->glue.JS_CORR, argp, 296 return copy_from_user(&joydev->glue.JS_CORR, argp,
302 sizeof(struct JS_DATA_TYPE)) ? -EFAULT : 0; 297 sizeof(joydev->glue.JS_CORR)) ? -EFAULT : 0;
303 case JS_GET_CAL: 298 case JS_GET_CAL:
304 return copy_to_user(argp, &joydev->glue.JS_CORR, 299 return copy_to_user(argp, &joydev->glue.JS_CORR,
305 sizeof(struct JS_DATA_TYPE)) ? -EFAULT : 0; 300 sizeof(joydev->glue.JS_CORR)) ? -EFAULT : 0;
306 case JS_SET_TIMEOUT: 301 case JS_SET_TIMEOUT:
307 return get_user(joydev->glue.JS_TIMEOUT, (int __user *) arg); 302 return get_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp);
308 case JS_GET_TIMEOUT: 303 case JS_GET_TIMEOUT:
309 return put_user(joydev->glue.JS_TIMEOUT, (int __user *) arg); 304 return put_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp);
310 case JS_SET_TIMELIMIT:
311 return get_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
312 case JS_GET_TIMELIMIT:
313 return put_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
314 case JS_SET_ALL:
315 return copy_from_user(&joydev->glue, argp,
316 sizeof(struct JS_DATA_SAVE_TYPE)) ? -EFAULT : 0;
317 case JS_GET_ALL:
318 return copy_to_user(argp, &joydev->glue,
319 sizeof(struct JS_DATA_SAVE_TYPE)) ? -EFAULT : 0;
320 305
321 case JSIOCGVERSION: 306 case JSIOCGVERSION:
322 return put_user(JS_VERSION, (__u32 __user *) arg); 307 return put_user(JS_VERSION, (__u32 __user *) argp);
323 case JSIOCGAXES: 308 case JSIOCGAXES:
324 return put_user(joydev->nabs, (__u8 __user *) arg); 309 return put_user(joydev->nabs, (__u8 __user *) argp);
325 case JSIOCGBUTTONS: 310 case JSIOCGBUTTONS:
326 return put_user(joydev->nkey, (__u8 __user *) arg); 311 return put_user(joydev->nkey, (__u8 __user *) argp);
327 case JSIOCSCORR: 312 case JSIOCSCORR:
328 if (copy_from_user(joydev->corr, argp, 313 if (copy_from_user(joydev->corr, argp,
329 sizeof(struct js_corr) * joydev->nabs)) 314 sizeof(joydev->corr[0]) * joydev->nabs))
330 return -EFAULT; 315 return -EFAULT;
331 for (i = 0; i < joydev->nabs; i++) { 316 for (i = 0; i < joydev->nabs; i++) {
332 j = joydev->abspam[i]; 317 j = joydev->abspam[i];
@@ -335,7 +320,7 @@ static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
335 return 0; 320 return 0;
336 case JSIOCGCORR: 321 case JSIOCGCORR:
337 return copy_to_user(argp, joydev->corr, 322 return copy_to_user(argp, joydev->corr,
338 sizeof(struct js_corr) * joydev->nabs) ? -EFAULT : 0; 323 sizeof(joydev->corr[0]) * joydev->nabs) ? -EFAULT : 0;
339 case JSIOCSAXMAP: 324 case JSIOCSAXMAP:
340 if (copy_from_user(joydev->abspam, argp, sizeof(__u8) * (ABS_MAX + 1))) 325 if (copy_from_user(joydev->abspam, argp, sizeof(__u8) * (ABS_MAX + 1)))
341 return -EFAULT; 326 return -EFAULT;
@@ -371,6 +356,84 @@ static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
371 return -EINVAL; 356 return -EINVAL;
372} 357}
373 358
359#ifdef CONFIG_COMPAT
360static long joydev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
361{
362 struct joydev_list *list = file->private_data;
363 struct joydev *joydev = list->joydev;
364 void __user *argp = (void __user *)arg;
365 s32 tmp32;
366 struct JS_DATA_SAVE_TYPE_32 ds32;
367 int err;
368
369 if (!joydev->exist) return -ENODEV;
370 switch(cmd) {
371 case JS_SET_TIMELIMIT:
372 err = get_user(tmp32, (s32 __user *) arg);
373 if (err == 0)
374 joydev->glue.JS_TIMELIMIT = tmp32;
375 break;
376 case JS_GET_TIMELIMIT:
377 tmp32 = joydev->glue.JS_TIMELIMIT;
378 err = put_user(tmp32, (s32 __user *) arg);
379 break;
380
381 case JS_SET_ALL:
382 err = copy_from_user(&ds32, argp,
383 sizeof(ds32)) ? -EFAULT : 0;
384 if (err == 0) {
385 joydev->glue.JS_TIMEOUT = ds32.JS_TIMEOUT;
386 joydev->glue.BUSY = ds32.BUSY;
387 joydev->glue.JS_EXPIRETIME = ds32.JS_EXPIRETIME;
388 joydev->glue.JS_TIMELIMIT = ds32.JS_TIMELIMIT;
389 joydev->glue.JS_SAVE = ds32.JS_SAVE;
390 joydev->glue.JS_CORR = ds32.JS_CORR;
391 }
392 break;
393
394 case JS_GET_ALL:
395 ds32.JS_TIMEOUT = joydev->glue.JS_TIMEOUT;
396 ds32.BUSY = joydev->glue.BUSY;
397 ds32.JS_EXPIRETIME = joydev->glue.JS_EXPIRETIME;
398 ds32.JS_TIMELIMIT = joydev->glue.JS_TIMELIMIT;
399 ds32.JS_SAVE = joydev->glue.JS_SAVE;
400 ds32.JS_CORR = joydev->glue.JS_CORR;
401
402 err = copy_to_user(argp, &ds32,
403 sizeof(ds32)) ? -EFAULT : 0;
404 break;
405
406 default:
407 err = joydev_ioctl_common(joydev, cmd, argp);
408 }
409 return err;
410}
411#endif /* CONFIG_COMPAT */
412
413static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
414{
415 struct joydev_list *list = file->private_data;
416 struct joydev *joydev = list->joydev;
417 void __user *argp = (void __user *)arg;
418
419 if (!joydev->exist) return -ENODEV;
420
421 switch(cmd) {
422 case JS_SET_TIMELIMIT:
423 return get_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
424 case JS_GET_TIMELIMIT:
425 return put_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
426 case JS_SET_ALL:
427 return copy_from_user(&joydev->glue, argp,
428 sizeof(joydev->glue)) ? -EFAULT : 0;
429 case JS_GET_ALL:
430 return copy_to_user(argp, &joydev->glue,
431 sizeof(joydev->glue)) ? -EFAULT : 0;
432 default:
433 return joydev_ioctl_common(joydev, cmd, argp);
434 }
435}
436
374static struct file_operations joydev_fops = { 437static struct file_operations joydev_fops = {
375 .owner = THIS_MODULE, 438 .owner = THIS_MODULE,
376 .read = joydev_read, 439 .read = joydev_read,
@@ -379,6 +442,9 @@ static struct file_operations joydev_fops = {
379 .open = joydev_open, 442 .open = joydev_open,
380 .release = joydev_release, 443 .release = joydev_release,
381 .ioctl = joydev_ioctl, 444 .ioctl = joydev_ioctl,
445#ifdef CONFIG_COMPAT
446 .compat_ioctl = joydev_compat_ioctl,
447#endif
382 .fasync = joydev_fasync, 448 .fasync = joydev_fasync,
383}; 449};
384 450
diff --git a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c
index ad39fe4bf35f..bf34f75b9467 100644
--- a/drivers/input/joystick/a3d.c
+++ b/drivers/input/joystick/a3d.c
@@ -185,7 +185,7 @@ static void a3d_poll(struct gameport *gameport)
185 a3d->reads++; 185 a3d->reads++;
186 if (a3d_read_packet(a3d->gameport, a3d->length, data) != a3d->length || 186 if (a3d_read_packet(a3d->gameport, a3d->length, data) != a3d->length ||
187 data[0] != a3d->mode || a3d_csum(data, a3d->length)) 187 data[0] != a3d->mode || a3d_csum(data, a3d->length))
188 a3d->bads++; 188 a3d->bads++;
189 else 189 else
190 a3d_read(a3d, data); 190 a3d_read(a3d, data);
191} 191}
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 83f6dafc1716..265962956c63 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -82,7 +82,7 @@ static char adi_cm2_abs[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ };
82static char adi_wmf_abs[] = { ABS_WHEEL, ABS_GAS, ABS_BRAKE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y }; 82static char adi_wmf_abs[] = { ABS_WHEEL, ABS_GAS, ABS_BRAKE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y };
83 83
84static short adi_wmgpe_key[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START, BTN_MODE, BTN_SELECT }; 84static short adi_wmgpe_key[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START, BTN_MODE, BTN_SELECT };
85static short adi_wmi_key[] = { BTN_TRIGGER, BTN_TOP, BTN_THUMB, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_BASE3, BTN_BASE4, BTN_EXTRA }; 85static short adi_wmi_key[] = { BTN_TRIGGER, BTN_TOP, BTN_THUMB, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_BASE3, BTN_BASE4, BTN_EXTRA };
86static short adi_wmed3d_key[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2 }; 86static short adi_wmed3d_key[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2 };
87static short adi_cm2_key[] = { BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 }; 87static short adi_cm2_key[] = { BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 };
88 88
@@ -183,7 +183,7 @@ static void adi_move_bits(struct adi_port *port, int length)
183 int i; 183 int i;
184 struct adi *adi = port->adi; 184 struct adi *adi = port->adi;
185 185
186 adi[0].idx = adi[1].idx = 0; 186 adi[0].idx = adi[1].idx = 0;
187 187
188 if (adi[0].ret <= 0 || adi[1].ret <= 0) return; 188 if (adi[0].ret <= 0 || adi[1].ret <= 0) return;
189 if (adi[0].data[0] & 0x20 || ~adi[1].data[0] & 0x20) return; 189 if (adi[0].data[0] & 0x20 || ~adi[1].data[0] & 0x20) return;
diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index cf36ca9b92f3..033456bb9fe0 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -51,7 +51,8 @@ MODULE_PARM_DESC(map, "Map of attached joysticks in form of <a>,<b> (default is
51 51
52__obsolete_setup("amijoy="); 52__obsolete_setup("amijoy=");
53 53
54static int amijoy_used[2] = { 0, 0 }; 54static int amijoy_used;
55static DECLARE_MUTEX(amijoy_sem);
55static struct input_dev amijoy_dev[2]; 56static struct input_dev amijoy_dev[2];
56static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" }; 57static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" };
57 58
@@ -84,26 +85,30 @@ static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp)
84 85
85static int amijoy_open(struct input_dev *dev) 86static int amijoy_open(struct input_dev *dev)
86{ 87{
87 int *used = dev->private; 88 int err;
88 89
89 if ((*used)++) 90 err = down_interruptible(&amijoy_sem);
90 return 0; 91 if (err)
92 return err;
91 93
92 if (request_irq(IRQ_AMIGA_VERTB, amijoy_interrupt, 0, "amijoy", amijoy_interrupt)) { 94 if (!amijoy_used && request_irq(IRQ_AMIGA_VERTB, amijoy_interrupt, 0, "amijoy", amijoy_interrupt)) {
93 (*used)--;
94 printk(KERN_ERR "amijoy.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB); 95 printk(KERN_ERR "amijoy.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
95 return -EBUSY; 96 err = -EBUSY;
97 goto out;
96 } 98 }
97 99
98 return 0; 100 amijoy_used++;
101out:
102 up(&amijoy_sem);
103 return err;
99} 104}
100 105
101static void amijoy_close(struct input_dev *dev) 106static void amijoy_close(struct input_dev *dev)
102{ 107{
103 int *used = dev->private; 108 down(&amijoysem);
104 109 if (!--amijoy_used)
105 if (!--(*used))
106 free_irq(IRQ_AMIGA_VERTB, amijoy_interrupt); 110 free_irq(IRQ_AMIGA_VERTB, amijoy_interrupt);
111 up(&amijoy_sem);
107} 112}
108 113
109static int __init amijoy_init(void) 114static int __init amijoy_init(void)
@@ -138,8 +143,6 @@ static int __init amijoy_init(void)
138 amijoy_dev[i].id.product = 0x0003; 143 amijoy_dev[i].id.product = 0x0003;
139 amijoy_dev[i].id.version = 0x0100; 144 amijoy_dev[i].id.version = 0x0100;
140 145
141 amijoy_dev[i].private = amijoy_used + i;
142
143 input_register_device(amijoy_dev + i); 146 input_register_device(amijoy_dev + i);
144 printk(KERN_INFO "input: %s at joy%ddat\n", amijoy_name, i); 147 printk(KERN_INFO "input: %s at joy%ddat\n", amijoy_name, i);
145 } 148 }
diff --git a/drivers/input/joystick/db9.c b/drivers/input/joystick/db9.c
index cfdd3acf06a1..fbd3eed07f90 100644
--- a/drivers/input/joystick/db9.c
+++ b/drivers/input/joystick/db9.c
@@ -87,7 +87,7 @@ __obsolete_setup("db9_3=");
87#define DB9_NORMAL 0x0a 87#define DB9_NORMAL 0x0a
88#define DB9_NOSELECT 0x08 88#define DB9_NOSELECT 0x08
89 89
90#define DB9_MAX_DEVICES 2 90#define DB9_MAX_DEVICES 2
91 91
92#define DB9_GENESIS6_DELAY 14 92#define DB9_GENESIS6_DELAY 14
93#define DB9_REFRESH_TIME HZ/100 93#define DB9_REFRESH_TIME HZ/100
@@ -98,6 +98,7 @@ struct db9 {
98 struct pardevice *pd; 98 struct pardevice *pd;
99 int mode; 99 int mode;
100 int used; 100 int used;
101 struct semaphore sem;
101 char phys[2][32]; 102 char phys[2][32];
102}; 103};
103 104
@@ -503,6 +504,11 @@ static int db9_open(struct input_dev *dev)
503{ 504{
504 struct db9 *db9 = dev->private; 505 struct db9 *db9 = dev->private;
505 struct parport *port = db9->pd->port; 506 struct parport *port = db9->pd->port;
507 int err;
508
509 err = down_interruptible(&db9->sem);
510 if (err)
511 return err;
506 512
507 if (!db9->used++) { 513 if (!db9->used++) {
508 parport_claim(db9->pd); 514 parport_claim(db9->pd);
@@ -514,6 +520,7 @@ static int db9_open(struct input_dev *dev)
514 mod_timer(&db9->timer, jiffies + DB9_REFRESH_TIME); 520 mod_timer(&db9->timer, jiffies + DB9_REFRESH_TIME);
515 } 521 }
516 522
523 up(&db9->sem);
517 return 0; 524 return 0;
518} 525}
519 526
@@ -522,12 +529,14 @@ static void db9_close(struct input_dev *dev)
522 struct db9 *db9 = dev->private; 529 struct db9 *db9 = dev->private;
523 struct parport *port = db9->pd->port; 530 struct parport *port = db9->pd->port;
524 531
532 down(&db9->sem);
525 if (!--db9->used) { 533 if (!--db9->used) {
526 del_timer(&db9->timer); 534 del_timer_sync(&db9->timer);
527 parport_write_control(port, 0x00); 535 parport_write_control(port, 0x00);
528 parport_data_forward(port); 536 parport_data_forward(port);
529 parport_release(db9->pd); 537 parport_release(db9->pd);
530 } 538 }
539 up(&db9->sem);
531} 540}
532 541
533static struct db9 __init *db9_probe(int *config, int nargs) 542static struct db9 __init *db9_probe(int *config, int nargs)
@@ -563,12 +572,12 @@ static struct db9 __init *db9_probe(int *config, int nargs)
563 } 572 }
564 } 573 }
565 574
566 if (!(db9 = kmalloc(sizeof(struct db9), GFP_KERNEL))) { 575 if (!(db9 = kcalloc(1, sizeof(struct db9), GFP_KERNEL))) {
567 parport_put_port(pp); 576 parport_put_port(pp);
568 return NULL; 577 return NULL;
569 } 578 }
570 memset(db9, 0, sizeof(struct db9));
571 579
580 init_MUTEX(&db9->sem);
572 db9->mode = config[1]; 581 db9->mode = config[1];
573 init_timer(&db9->timer); 582 init_timer(&db9->timer);
574 db9->timer.data = (long) db9; 583 db9->timer.data = (long) db9;
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c
index 8732f52bdd08..95bbdd302aad 100644
--- a/drivers/input/joystick/gamecon.c
+++ b/drivers/input/joystick/gamecon.c
@@ -1,12 +1,12 @@
1/* 1/*
2 * NES, SNES, N64, MultiSystem, PSX gamepad driver for Linux 2 * NES, SNES, N64, MultiSystem, PSX gamepad driver for Linux
3 * 3 *
4 * Copyright (c) 1999-2004 Vojtech Pavlik <vojtech@suse.cz> 4 * Copyright (c) 1999-2004 Vojtech Pavlik <vojtech@suse.cz>
5 * Copyright (c) 2004 Peter Nelson <rufus-kernel@hackish.org> 5 * Copyright (c) 2004 Peter Nelson <rufus-kernel@hackish.org>
6 * 6 *
7 * Based on the work of: 7 * Based on the work of:
8 * Andree Borrmann John Dahlstrom 8 * Andree Borrmann John Dahlstrom
9 * David Kuder Nathan Hand 9 * David Kuder Nathan Hand
10 */ 10 */
11 11
12/* 12/*
@@ -81,6 +81,7 @@ struct gc {
81 struct timer_list timer; 81 struct timer_list timer;
82 unsigned char pads[GC_MAX + 1]; 82 unsigned char pads[GC_MAX + 1];
83 int used; 83 int used;
84 struct semaphore sem;
84 char phys[5][32]; 85 char phys[5][32];
85}; 86};
86 87
@@ -433,7 +434,7 @@ static void gc_timer(unsigned long private)
433 gc_psx_read_packet(gc, data_psx, data); 434 gc_psx_read_packet(gc, data_psx, data);
434 435
435 for (i = 0; i < 5; i++) { 436 for (i = 0; i < 5; i++) {
436 switch (data[i]) { 437 switch (data[i]) {
437 438
438 case GC_PSX_RUMBLE: 439 case GC_PSX_RUMBLE:
439 440
@@ -503,22 +504,33 @@ static void gc_timer(unsigned long private)
503static int gc_open(struct input_dev *dev) 504static int gc_open(struct input_dev *dev)
504{ 505{
505 struct gc *gc = dev->private; 506 struct gc *gc = dev->private;
507 int err;
508
509 err = down_interruptible(&gc->sem);
510 if (err)
511 return err;
512
506 if (!gc->used++) { 513 if (!gc->used++) {
507 parport_claim(gc->pd); 514 parport_claim(gc->pd);
508 parport_write_control(gc->pd->port, 0x04); 515 parport_write_control(gc->pd->port, 0x04);
509 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME); 516 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME);
510 } 517 }
518
519 up(&gc->sem);
511 return 0; 520 return 0;
512} 521}
513 522
514static void gc_close(struct input_dev *dev) 523static void gc_close(struct input_dev *dev)
515{ 524{
516 struct gc *gc = dev->private; 525 struct gc *gc = dev->private;
526
527 down(&gc->sem);
517 if (!--gc->used) { 528 if (!--gc->used) {
518 del_timer(&gc->timer); 529 del_timer_sync(&gc->timer);
519 parport_write_control(gc->pd->port, 0x00); 530 parport_write_control(gc->pd->port, 0x00);
520 parport_release(gc->pd); 531 parport_release(gc->pd);
521 } 532 }
533 up(&gc->sem);
522} 534}
523 535
524static struct gc __init *gc_probe(int *config, int nargs) 536static struct gc __init *gc_probe(int *config, int nargs)
@@ -542,11 +554,12 @@ static struct gc __init *gc_probe(int *config, int nargs)
542 return NULL; 554 return NULL;
543 } 555 }
544 556
545 if (!(gc = kmalloc(sizeof(struct gc), GFP_KERNEL))) { 557 if (!(gc = kcalloc(1, sizeof(struct gc), GFP_KERNEL))) {
546 parport_put_port(pp); 558 parport_put_port(pp);
547 return NULL; 559 return NULL;
548 } 560 }
549 memset(gc, 0, sizeof(struct gc)); 561
562 init_MUTEX(&gc->sem);
550 563
551 gc->pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); 564 gc->pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
552 565
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index ad13f09a4e71..7d969420066c 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -329,7 +329,7 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
329 329
330 for (i = 0; i < gf2k_axes[gf2k->id]; i++) { 330 for (i = 0; i < gf2k_axes[gf2k->id]; i++) {
331 gf2k->dev.absmax[gf2k_abs[i]] = (i < 2) ? gf2k->dev.abs[gf2k_abs[i]] * 2 - 32 : 331 gf2k->dev.absmax[gf2k_abs[i]] = (i < 2) ? gf2k->dev.abs[gf2k_abs[i]] * 2 - 32 :
332 gf2k->dev.abs[gf2k_abs[0]] + gf2k->dev.abs[gf2k_abs[1]] - 32; 332 gf2k->dev.abs[gf2k_abs[0]] + gf2k->dev.abs[gf2k_abs[1]] - 32;
333 gf2k->dev.absmin[gf2k_abs[i]] = 32; 333 gf2k->dev.absmin[gf2k_abs[i]] = 32;
334 gf2k->dev.absfuzz[gf2k_abs[i]] = 8; 334 gf2k->dev.absfuzz[gf2k_abs[i]] = 8;
335 gf2k->dev.absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0; 335 gf2k->dev.absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0;
diff --git a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c
index 42e5005d621f..0da7bd133ccf 100644
--- a/drivers/input/joystick/grip_mp.c
+++ b/drivers/input/joystick/grip_mp.c
@@ -171,7 +171,7 @@ static int mp_io(struct gameport* gameport, int sendflags, int sendcode, u32 *pa
171 *packet = 0; 171 *packet = 0;
172 raw_data = gameport_read(gameport); 172 raw_data = gameport_read(gameport);
173 if (raw_data & 1) 173 if (raw_data & 1)
174 return IO_RETRY; 174 return IO_RETRY;
175 175
176 for (i = 0; i < 64; i++) { 176 for (i = 0; i < 64; i++) {
177 raw_data = gameport_read(gameport); 177 raw_data = gameport_read(gameport);
diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c
index 028f3513629a..e31b7b93fde2 100644
--- a/drivers/input/joystick/iforce/iforce-main.c
+++ b/drivers/input/joystick/iforce/iforce-main.c
@@ -78,6 +78,7 @@ static struct iforce_device iforce_device[] = {
78 { 0x061c, 0xc0a4, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce }, //? 78 { 0x061c, 0xc0a4, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce }, //?
79 { 0x06f8, 0x0001, "Guillemot Race Leader Force Feedback", btn_wheel, abs_wheel, ff_iforce }, //? 79 { 0x06f8, 0x0001, "Guillemot Race Leader Force Feedback", btn_wheel, abs_wheel, ff_iforce }, //?
80 { 0x06f8, 0x0004, "Guillemot Force Feedback Racing Wheel", btn_wheel, abs_wheel, ff_iforce }, //? 80 { 0x06f8, 0x0004, "Guillemot Force Feedback Racing Wheel", btn_wheel, abs_wheel, ff_iforce }, //?
81 { 0x06f8, 0x0004, "Gullemot Jet Leader 3D", btn_joystick, abs_joystick, ff_iforce }, //?
81 { 0x0000, 0x0000, "Unknown I-Force Device [%04x:%04x]", btn_joystick, abs_joystick, ff_iforce } 82 { 0x0000, 0x0000, "Unknown I-Force Device [%04x:%04x]", btn_joystick, abs_joystick, ff_iforce }
82}; 83};
83 84
diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c
index 617c0b0e5a39..6369a24684fe 100644
--- a/drivers/input/joystick/iforce/iforce-usb.c
+++ b/drivers/input/joystick/iforce/iforce-usb.c
@@ -229,6 +229,7 @@ static struct usb_device_id iforce_usb_ids [] = {
229 { USB_DEVICE(0x061c, 0xc0a4) }, /* ACT LABS Force RS */ 229 { USB_DEVICE(0x061c, 0xc0a4) }, /* ACT LABS Force RS */
230 { USB_DEVICE(0x06f8, 0x0001) }, /* Guillemot Race Leader Force Feedback */ 230 { USB_DEVICE(0x06f8, 0x0001) }, /* Guillemot Race Leader Force Feedback */
231 { USB_DEVICE(0x06f8, 0x0004) }, /* Guillemot Force Feedback Racing Wheel */ 231 { USB_DEVICE(0x06f8, 0x0004) }, /* Guillemot Force Feedback Racing Wheel */
232 { USB_DEVICE(0x06f8, 0xa302) }, /* Guillemot Jet Leader 3D */
232 { } /* Terminating entry */ 233 { } /* Terminating entry */
233}; 234};
234 235
diff --git a/drivers/input/joystick/spaceball.c b/drivers/input/joystick/spaceball.c
index ec0a2a64d49c..a436f2220856 100644
--- a/drivers/input/joystick/spaceball.c
+++ b/drivers/input/joystick/spaceball.c
@@ -4,8 +4,8 @@
4 * Copyright (c) 1999-2001 Vojtech Pavlik 4 * Copyright (c) 1999-2001 Vojtech Pavlik
5 * 5 *
6 * Based on the work of: 6 * Based on the work of:
7 * David Thompson 7 * David Thompson
8 * Joseph Krahn 8 * Joseph Krahn
9 */ 9 */
10 10
11/* 11/*
diff --git a/drivers/input/joystick/spaceorb.c b/drivers/input/joystick/spaceorb.c
index 874367bfab08..01fd2e4791ae 100644
--- a/drivers/input/joystick/spaceorb.c
+++ b/drivers/input/joystick/spaceorb.c
@@ -4,7 +4,7 @@
4 * Copyright (c) 1999-2001 Vojtech Pavlik 4 * Copyright (c) 1999-2001 Vojtech Pavlik
5 * 5 *
6 * Based on the work of: 6 * Based on the work of:
7 * David Thompson 7 * David Thompson
8 */ 8 */
9 9
10/* 10/*
diff --git a/drivers/input/joystick/tmdc.c b/drivers/input/joystick/tmdc.c
index aaee52ceb920..9eb9954cac6e 100644
--- a/drivers/input/joystick/tmdc.c
+++ b/drivers/input/joystick/tmdc.c
@@ -79,7 +79,7 @@ static short tmdc_btn_pad[TMDC_BTN] =
79 { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_START, BTN_SELECT, BTN_TL, BTN_TR }; 79 { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_START, BTN_SELECT, BTN_TL, BTN_TR };
80static short tmdc_btn_joy[TMDC_BTN] = 80static short tmdc_btn_joy[TMDC_BTN] =
81 { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_THUMB2, BTN_PINKIE, 81 { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_THUMB2, BTN_PINKIE,
82 BTN_BASE3, BTN_BASE4, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z }; 82 BTN_BASE3, BTN_BASE4, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z };
83static short tmdc_btn_fm[TMDC_BTN] = 83static short tmdc_btn_fm[TMDC_BTN] =
84 { BTN_TRIGGER, BTN_C, BTN_B, BTN_A, BTN_THUMB, BTN_X, BTN_Y, BTN_Z, BTN_TOP, BTN_TOP2 }; 84 { BTN_TRIGGER, BTN_C, BTN_B, BTN_A, BTN_THUMB, BTN_X, BTN_Y, BTN_Z, BTN_TOP, BTN_TOP2 };
85static short tmdc_btn_at[TMDC_BTN] = 85static short tmdc_btn_at[TMDC_BTN] =
diff --git a/drivers/input/joystick/turbografx.c b/drivers/input/joystick/turbografx.c
index dd88b9cb49fa..28100d461cb7 100644
--- a/drivers/input/joystick/turbografx.c
+++ b/drivers/input/joystick/turbografx.c
@@ -84,6 +84,7 @@ static struct tgfx {
84 char phys[7][32]; 84 char phys[7][32];
85 int sticks; 85 int sticks;
86 int used; 86 int used;
87 struct semaphore sem;
87} *tgfx_base[3]; 88} *tgfx_base[3];
88 89
89/* 90/*
@@ -99,7 +100,7 @@ static void tgfx_timer(unsigned long private)
99 for (i = 0; i < 7; i++) 100 for (i = 0; i < 7; i++)
100 if (tgfx->sticks & (1 << i)) { 101 if (tgfx->sticks & (1 << i)) {
101 102
102 dev = tgfx->dev + i; 103 dev = tgfx->dev + i;
103 104
104 parport_write_data(tgfx->pd->port, ~(1 << i)); 105 parport_write_data(tgfx->pd->port, ~(1 << i));
105 data1 = parport_read_status(tgfx->pd->port) ^ 0x7f; 106 data1 = parport_read_status(tgfx->pd->port) ^ 0x7f;
@@ -122,23 +123,34 @@ static void tgfx_timer(unsigned long private)
122 123
123static int tgfx_open(struct input_dev *dev) 124static int tgfx_open(struct input_dev *dev)
124{ 125{
125 struct tgfx *tgfx = dev->private; 126 struct tgfx *tgfx = dev->private;
126 if (!tgfx->used++) { 127 int err;
128
129 err = down_interruptible(&tgfx->sem);
130 if (err)
131 return err;
132
133 if (!tgfx->used++) {
127 parport_claim(tgfx->pd); 134 parport_claim(tgfx->pd);
128 parport_write_control(tgfx->pd->port, 0x04); 135 parport_write_control(tgfx->pd->port, 0x04);
129 mod_timer(&tgfx->timer, jiffies + TGFX_REFRESH_TIME); 136 mod_timer(&tgfx->timer, jiffies + TGFX_REFRESH_TIME);
130 } 137 }
131 return 0; 138
139 up(&tgfx->sem);
140 return 0;
132} 141}
133 142
134static void tgfx_close(struct input_dev *dev) 143static void tgfx_close(struct input_dev *dev)
135{ 144{
136 struct tgfx *tgfx = dev->private; 145 struct tgfx *tgfx = dev->private;
137 if (!--tgfx->used) { 146
138 del_timer(&tgfx->timer); 147 down(&tgfx->sem);
148 if (!--tgfx->used) {
149 del_timer_sync(&tgfx->timer);
139 parport_write_control(tgfx->pd->port, 0x00); 150 parport_write_control(tgfx->pd->port, 0x00);
140 parport_release(tgfx->pd); 151 parport_release(tgfx->pd);
141 } 152 }
153 up(&tgfx->sem);
142} 154}
143 155
144/* 156/*
@@ -166,11 +178,12 @@ static struct tgfx __init *tgfx_probe(int *config, int nargs)
166 return NULL; 178 return NULL;
167 } 179 }
168 180
169 if (!(tgfx = kmalloc(sizeof(struct tgfx), GFP_KERNEL))) { 181 if (!(tgfx = kcalloc(1, sizeof(struct tgfx), GFP_KERNEL))) {
170 parport_put_port(pp); 182 parport_put_port(pp);
171 return NULL; 183 return NULL;
172 } 184 }
173 memset(tgfx, 0, sizeof(struct tgfx)); 185
186 init_MUTEX(&tgfx->sem);
174 187
175 tgfx->pd = parport_register_device(pp, "turbografx", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); 188 tgfx->pd = parport_register_device(pp, "turbografx", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
176 189
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index 82fad9a23ace..4d4985b59abf 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -227,7 +227,7 @@ static ssize_t atkbd_do_set_##_name(struct device *d, struct device_attribute *a
227{ \ 227{ \
228 return atkbd_attr_set_helper(d, b, s, atkbd_set_##_name); \ 228 return atkbd_attr_set_helper(d, b, s, atkbd_set_##_name); \
229} \ 229} \
230static struct device_attribute atkbd_attr_##_name = \ 230static struct device_attribute atkbd_attr_##_name = \
231 __ATTR(_name, S_IWUSR | S_IRUGO, atkbd_do_show_##_name, atkbd_do_set_##_name); 231 __ATTR(_name, S_IWUSR | S_IRUGO, atkbd_do_show_##_name, atkbd_do_set_##_name);
232 232
233ATKBD_DEFINE_ATTR(extra); 233ATKBD_DEFINE_ATTR(extra);
@@ -388,7 +388,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
388 value = atkbd->release ? 0 : 388 value = atkbd->release ? 0 :
389 (1 + (!atkbd->softrepeat && test_bit(atkbd->keycode[code], atkbd->dev.key))); 389 (1 + (!atkbd->softrepeat && test_bit(atkbd->keycode[code], atkbd->dev.key)));
390 390
391 switch (value) { /* Workaround Toshiba laptop multiple keypress */ 391 switch (value) { /* Workaround Toshiba laptop multiple keypress */
392 case 0: 392 case 0:
393 atkbd->last = 0; 393 atkbd->last = 0;
394 break; 394 break;
@@ -894,7 +894,7 @@ static int atkbd_reconnect(struct serio *serio)
894 if (atkbd->write) { 894 if (atkbd->write) {
895 param[0] = (test_bit(LED_SCROLLL, atkbd->dev.led) ? 1 : 0) 895 param[0] = (test_bit(LED_SCROLLL, atkbd->dev.led) ? 1 : 0)
896 | (test_bit(LED_NUML, atkbd->dev.led) ? 2 : 0) 896 | (test_bit(LED_NUML, atkbd->dev.led) ? 2 : 0)
897 | (test_bit(LED_CAPSL, atkbd->dev.led) ? 4 : 0); 897 | (test_bit(LED_CAPSL, atkbd->dev.led) ? 4 : 0);
898 898
899 if (atkbd_probe(atkbd)) 899 if (atkbd_probe(atkbd))
900 return -1; 900 return -1;
diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c
index 0f1220a0ceb5..a8551711e8d6 100644
--- a/drivers/input/keyboard/corgikbd.c
+++ b/drivers/input/keyboard/corgikbd.c
@@ -39,6 +39,7 @@
39#define CORGI_KEY_CALENDER KEY_F1 39#define CORGI_KEY_CALENDER KEY_F1
40#define CORGI_KEY_ADDRESS KEY_F2 40#define CORGI_KEY_ADDRESS KEY_F2
41#define CORGI_KEY_FN KEY_F3 41#define CORGI_KEY_FN KEY_F3
42#define CORGI_KEY_CANCEL KEY_F4
42#define CORGI_KEY_OFF KEY_SUSPEND 43#define CORGI_KEY_OFF KEY_SUSPEND
43#define CORGI_KEY_EXOK KEY_F5 44#define CORGI_KEY_EXOK KEY_F5
44#define CORGI_KEY_EXCANCEL KEY_F6 45#define CORGI_KEY_EXCANCEL KEY_F6
@@ -46,6 +47,7 @@
46#define CORGI_KEY_EXJOGUP KEY_F8 47#define CORGI_KEY_EXJOGUP KEY_F8
47#define CORGI_KEY_JAP1 KEY_LEFTCTRL 48#define CORGI_KEY_JAP1 KEY_LEFTCTRL
48#define CORGI_KEY_JAP2 KEY_LEFTALT 49#define CORGI_KEY_JAP2 KEY_LEFTALT
50#define CORGI_KEY_MAIL KEY_F10
49#define CORGI_KEY_OK KEY_F11 51#define CORGI_KEY_OK KEY_F11
50#define CORGI_KEY_MENU KEY_F12 52#define CORGI_KEY_MENU KEY_F12
51#define CORGI_HINGE_0 KEY_KP0 53#define CORGI_HINGE_0 KEY_KP0
@@ -59,8 +61,8 @@ static unsigned char corgikbd_keycode[NR_SCANCODES] = {
59 KEY_TAB, KEY_Q, KEY_E, KEY_T, KEY_G, KEY_U, KEY_J, KEY_K, 0, 0, 0, 0, 0, 0, 0, 0, /* 33-48 */ 61 KEY_TAB, KEY_Q, KEY_E, KEY_T, KEY_G, KEY_U, KEY_J, KEY_K, 0, 0, 0, 0, 0, 0, 0, 0, /* 33-48 */
60 CORGI_KEY_CALENDER, KEY_W, KEY_S, KEY_F, KEY_V, KEY_H, KEY_M, KEY_L, 0, KEY_RIGHTSHIFT, 0, 0, 0, 0, 0, 0, /* 49-64 */ 62 CORGI_KEY_CALENDER, KEY_W, KEY_S, KEY_F, KEY_V, KEY_H, KEY_M, KEY_L, 0, KEY_RIGHTSHIFT, 0, 0, 0, 0, 0, 0, /* 49-64 */
61 CORGI_KEY_ADDRESS, KEY_A, KEY_D, KEY_C, KEY_B, KEY_N, KEY_DOT, 0, KEY_ENTER, 0, KEY_LEFTSHIFT, 0, 0, 0, 0, 0, /* 65-80 */ 63 CORGI_KEY_ADDRESS, KEY_A, KEY_D, KEY_C, KEY_B, KEY_N, KEY_DOT, 0, KEY_ENTER, 0, KEY_LEFTSHIFT, 0, 0, 0, 0, 0, /* 65-80 */
62 KEY_MAIL, KEY_Z, KEY_X, KEY_MINUS, KEY_SPACE, KEY_COMMA, 0, KEY_UP, 0, 0, 0, CORGI_KEY_FN, 0, 0, 0, 0, /* 81-96 */ 64 CORGI_KEY_MAIL, KEY_Z, KEY_X, KEY_MINUS, KEY_SPACE, KEY_COMMA, 0, KEY_UP, 0, 0, 0, CORGI_KEY_FN, 0, 0, 0, 0, /* 81-96 */
63 KEY_SYSRQ, CORGI_KEY_JAP1, CORGI_KEY_JAP2, KEY_CANCEL, CORGI_KEY_OK, CORGI_KEY_MENU, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0, 0, 0, 0, /* 97-112 */ 65 KEY_SYSRQ, CORGI_KEY_JAP1, CORGI_KEY_JAP2, CORGI_KEY_CANCEL, CORGI_KEY_OK, CORGI_KEY_MENU, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0, 0, 0, 0, /* 97-112 */
64 CORGI_KEY_OFF, CORGI_KEY_EXOK, CORGI_KEY_EXCANCEL, CORGI_KEY_EXJOGDOWN, CORGI_KEY_EXJOGUP, 0, 0, 0, 0, 0, 0, 0, /* 113-124 */ 66 CORGI_KEY_OFF, CORGI_KEY_EXOK, CORGI_KEY_EXCANCEL, CORGI_KEY_EXJOGDOWN, CORGI_KEY_EXJOGUP, 0, 0, 0, 0, 0, 0, 0, /* 113-124 */
65 CORGI_HINGE_0, CORGI_HINGE_1, CORGI_HINGE_2 /* 125-127 */ 67 CORGI_HINGE_0, CORGI_HINGE_1, CORGI_HINGE_2 /* 125-127 */
66}; 68};
diff --git a/drivers/input/keyboard/lkkbd.c b/drivers/input/keyboard/lkkbd.c
index 2694ff2b5beb..098963c7cdd6 100644
--- a/drivers/input/keyboard/lkkbd.c
+++ b/drivers/input/keyboard/lkkbd.c
@@ -15,10 +15,10 @@
15 * information given below, I will _not_ be liable! 15 * information given below, I will _not_ be liable!
16 * 16 *
17 * RJ10 pinout: To DE9: Or DB25: 17 * RJ10 pinout: To DE9: Or DB25:
18 * 1 - RxD <----> Pin 3 (TxD) <-> Pin 2 (TxD) 18 * 1 - RxD <----> Pin 3 (TxD) <-> Pin 2 (TxD)
19 * 2 - GND <----> Pin 5 (GND) <-> Pin 7 (GND) 19 * 2 - GND <----> Pin 5 (GND) <-> Pin 7 (GND)
20 * 4 - TxD <----> Pin 2 (RxD) <-> Pin 3 (RxD) 20 * 4 - TxD <----> Pin 2 (RxD) <-> Pin 3 (RxD)
21 * 3 - +12V (from HDD drive connector), DON'T connect to DE9 or DB25!!! 21 * 3 - +12V (from HDD drive connector), DON'T connect to DE9 or DB25!!!
22 * 22 *
23 * Pin numbers for DE9 and DB25 are noted on the plug (quite small:). For 23 * Pin numbers for DE9 and DB25 are noted on the plug (quite small:). For
24 * RJ10, it's like this: 24 * RJ10, it's like this:
diff --git a/drivers/input/keyboard/locomokbd.c b/drivers/input/keyboard/locomokbd.c
index d3e9dd6a13cd..8935290256b3 100644
--- a/drivers/input/keyboard/locomokbd.c
+++ b/drivers/input/keyboard/locomokbd.c
@@ -42,7 +42,7 @@ MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
42MODULE_DESCRIPTION("LoCoMo keyboard driver"); 42MODULE_DESCRIPTION("LoCoMo keyboard driver");
43MODULE_LICENSE("GPL"); 43MODULE_LICENSE("GPL");
44 44
45#define LOCOMOKBD_NUMKEYS 128 45#define LOCOMOKBD_NUMKEYS 128
46 46
47#define KEY_ACTIVITY KEY_F16 47#define KEY_ACTIVITY KEY_F16
48#define KEY_CONTACT KEY_F18 48#define KEY_CONTACT KEY_F18
@@ -61,7 +61,7 @@ static unsigned char locomokbd_keycode[LOCOMOKBD_NUMKEYS] = {
61 KEY_G, KEY_F, KEY_X, KEY_S, 0, 0, 0, 0, 0, 0, /* 90 - 99 */ 61 KEY_G, KEY_F, KEY_X, KEY_S, 0, 0, 0, 0, 0, 0, /* 90 - 99 */
62 0, 0, KEY_DOT, 0, KEY_COMMA, KEY_N, KEY_B, KEY_C, KEY_Z, KEY_A, /* 100 - 109 */ 62 0, 0, KEY_DOT, 0, KEY_COMMA, KEY_N, KEY_B, KEY_C, KEY_Z, KEY_A, /* 100 - 109 */
63 KEY_LEFTSHIFT, KEY_TAB, KEY_LEFTCTRL, 0, 0, 0, 0, 0, 0, 0, /* 110 - 119 */ 63 KEY_LEFTSHIFT, KEY_TAB, KEY_LEFTCTRL, 0, 0, 0, 0, 0, 0, 0, /* 110 - 119 */
64 KEY_M, KEY_SPACE, KEY_V, KEY_APOSTROPHE, KEY_SLASH, 0, 0, 0 /* 120 - 128 */ 64 KEY_M, KEY_SPACE, KEY_V, KEY_APOSTROPHE, KEY_SLASH, 0, 0, 0 /* 120 - 128 */
65}; 65};
66 66
67#define KB_ROWS 16 67#define KB_ROWS 16
@@ -82,7 +82,7 @@ struct locomokbd {
82 struct locomo_dev *ldev; 82 struct locomo_dev *ldev;
83 unsigned long base; 83 unsigned long base;
84 spinlock_t lock; 84 spinlock_t lock;
85 85
86 struct timer_list timer; 86 struct timer_list timer;
87}; 87};
88 88
@@ -95,7 +95,7 @@ static inline void locomokbd_charge_all(unsigned long membase)
95static inline void locomokbd_activate_all(unsigned long membase) 95static inline void locomokbd_activate_all(unsigned long membase)
96{ 96{
97 unsigned long r; 97 unsigned long r;
98 98
99 locomo_writel(0, membase + LOCOMO_KSC); 99 locomo_writel(0, membase + LOCOMO_KSC);
100 r = locomo_readl(membase + LOCOMO_KIC); 100 r = locomo_readl(membase + LOCOMO_KIC);
101 r &= 0xFEFF; 101 r &= 0xFEFF;
@@ -127,7 +127,7 @@ static inline void locomokbd_reset_col(unsigned long membase, int col)
127 */ 127 */
128 128
129/* Scan the hardware keyboard and push any changes up through the input layer */ 129/* Scan the hardware keyboard and push any changes up through the input layer */
130static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *regs) 130static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *regs)
131{ 131{
132 unsigned int row, col, rowd, scancode; 132 unsigned int row, col, rowd, scancode;
133 unsigned long flags; 133 unsigned long flags;
@@ -138,7 +138,7 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *
138 138
139 if (regs) 139 if (regs)
140 input_regs(&locomokbd->input, regs); 140 input_regs(&locomokbd->input, regs);
141 141
142 locomokbd_charge_all(membase); 142 locomokbd_charge_all(membase);
143 143
144 num_pressed = 0; 144 num_pressed = 0;
@@ -146,9 +146,9 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *
146 146
147 locomokbd_activate_col(membase, col); 147 locomokbd_activate_col(membase, col);
148 udelay(KB_DELAY); 148 udelay(KB_DELAY);
149 149
150 rowd = ~locomo_readl(membase + LOCOMO_KIB); 150 rowd = ~locomo_readl(membase + LOCOMO_KIB);
151 for (row = 0; row < KB_ROWS; row++ ) { 151 for (row = 0; row < KB_ROWS; row++) {
152 scancode = SCANCODE(col, row); 152 scancode = SCANCODE(col, row);
153 if (rowd & KB_ROWMASK(row)) { 153 if (rowd & KB_ROWMASK(row)) {
154 num_pressed += 1; 154 num_pressed += 1;
@@ -170,7 +170,7 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *
170 spin_unlock_irqrestore(&locomokbd->lock, flags); 170 spin_unlock_irqrestore(&locomokbd->lock, flags);
171} 171}
172 172
173/* 173/*
174 * LoCoMo keyboard interrupt handler. 174 * LoCoMo keyboard interrupt handler.
175 */ 175 */
176static irqreturn_t locomokbd_interrupt(int irq, void *dev_id, struct pt_regs *regs) 176static irqreturn_t locomokbd_interrupt(int irq, void *dev_id, struct pt_regs *regs)
@@ -205,8 +205,8 @@ static int locomokbd_probe(struct locomo_dev *dev)
205 memset(locomokbd, 0, sizeof(struct locomokbd)); 205 memset(locomokbd, 0, sizeof(struct locomokbd));
206 206
207 /* try and claim memory region */ 207 /* try and claim memory region */
208 if (!request_mem_region((unsigned long) dev->mapbase, 208 if (!request_mem_region((unsigned long) dev->mapbase,
209 dev->length, 209 dev->length,
210 LOCOMO_DRIVER_NAME(dev))) { 210 LOCOMO_DRIVER_NAME(dev))) {
211 ret = -EBUSY; 211 ret = -EBUSY;
212 printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n"); 212 printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n");
@@ -225,7 +225,7 @@ static int locomokbd_probe(struct locomo_dev *dev)
225 locomokbd->timer.data = (unsigned long) locomokbd; 225 locomokbd->timer.data = (unsigned long) locomokbd;
226 226
227 locomokbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 227 locomokbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
228 228
229 init_input_dev(&locomokbd->input); 229 init_input_dev(&locomokbd->input);
230 locomokbd->input.keycode = locomokbd->keycode; 230 locomokbd->input.keycode = locomokbd->keycode;
231 locomokbd->input.keycodesize = sizeof(unsigned char); 231 locomokbd->input.keycodesize = sizeof(unsigned char);
@@ -271,11 +271,11 @@ free:
271static int locomokbd_remove(struct locomo_dev *dev) 271static int locomokbd_remove(struct locomo_dev *dev)
272{ 272{
273 struct locomokbd *locomokbd = locomo_get_drvdata(dev); 273 struct locomokbd *locomokbd = locomo_get_drvdata(dev);
274 274
275 free_irq(dev->irq[0], locomokbd); 275 free_irq(dev->irq[0], locomokbd);
276 276
277 del_timer_sync(&locomokbd->timer); 277 del_timer_sync(&locomokbd->timer);
278 278
279 input_unregister_device(&locomokbd->input); 279 input_unregister_device(&locomokbd->input);
280 locomo_set_drvdata(dev, NULL); 280 locomo_set_drvdata(dev, NULL);
281 281
diff --git a/drivers/input/keyboard/maple_keyb.c b/drivers/input/keyboard/maple_keyb.c
index 859ed771ee0a..eecbde294f1f 100644
--- a/drivers/input/keyboard/maple_keyb.c
+++ b/drivers/input/keyboard/maple_keyb.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * $Id: maple_keyb.c,v 1.4 2004/03/22 01:18:15 lethal Exp $ 2 * $Id: maple_keyb.c,v 1.4 2004/03/22 01:18:15 lethal Exp $
3 * SEGA Dreamcast keyboard driver 3 * SEGA Dreamcast keyboard driver
4 * Based on drivers/usb/usbkbd.c 4 * Based on drivers/usb/usbkbd.c
5 */ 5 */
6 6
@@ -40,7 +40,6 @@ struct dc_kbd {
40 struct input_dev dev; 40 struct input_dev dev;
41 unsigned char new[8]; 41 unsigned char new[8];
42 unsigned char old[8]; 42 unsigned char old[8];
43 int open;
44}; 43};
45 44
46 45
@@ -95,22 +94,6 @@ static void dc_kbd_callback(struct mapleq *mq)
95 } 94 }
96} 95}
97 96
98
99static int dc_kbd_open(struct input_dev *dev)
100{
101 struct dc_kbd *kbd = dev->private;
102 kbd->open++;
103 return 0;
104}
105
106
107static void dc_kbd_close(struct input_dev *dev)
108{
109 struct dc_kbd *kbd = dev->private;
110 kbd->open--;
111}
112
113
114static int dc_kbd_connect(struct maple_device *dev) 97static int dc_kbd_connect(struct maple_device *dev)
115{ 98{
116 int i; 99 int i;
@@ -133,9 +116,6 @@ static int dc_kbd_connect(struct maple_device *dev)
133 clear_bit(0, kbd->dev.keybit); 116 clear_bit(0, kbd->dev.keybit);
134 117
135 kbd->dev.private = kbd; 118 kbd->dev.private = kbd;
136 kbd->dev.open = dc_kbd_open;
137 kbd->dev.close = dc_kbd_close;
138 kbd->dev.event = NULL;
139 119
140 kbd->dev.name = dev->product_name; 120 kbd->dev.name = dev->product_name;
141 kbd->dev.id.bustype = BUS_MAPLE; 121 kbd->dev.id.bustype = BUS_MAPLE;
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 158c8e845ff9..98710997aaaa 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -298,9 +298,11 @@ static int uinput_alloc_device(struct file *file, const char __user *buffer, siz
298 /* check if absmin/absmax/absfuzz/absflat are filled as 298 /* check if absmin/absmax/absfuzz/absflat are filled as
299 * told in Documentation/input/input-programming.txt */ 299 * told in Documentation/input/input-programming.txt */
300 if (test_bit(EV_ABS, dev->evbit)) { 300 if (test_bit(EV_ABS, dev->evbit)) {
301 retval = uinput_validate_absbits(dev); 301 int err = uinput_validate_absbits(dev);
302 if (retval < 0) 302 if (err < 0) {
303 retval = err;
303 kfree(dev->name); 304 kfree(dev->name);
305 }
304 } 306 }
305 307
306exit: 308exit:
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index a7864195806a..c4909b49337d 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -15,4 +15,4 @@ obj-$(CONFIG_MOUSE_SERIAL) += sermouse.o
15obj-$(CONFIG_MOUSE_HIL) += hil_ptr.o 15obj-$(CONFIG_MOUSE_HIL) += hil_ptr.o
16obj-$(CONFIG_MOUSE_VSXXXAA) += vsxxxaa.o 16obj-$(CONFIG_MOUSE_VSXXXAA) += vsxxxaa.o
17 17
18psmouse-objs := psmouse-base.o alps.o logips2pp.o synaptics.o 18psmouse-objs := psmouse-base.o alps.o logips2pp.o synaptics.o lifebook.o
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 7bf4be733e9a..a12e98158a75 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -30,10 +30,11 @@
30 30
31#define ALPS_DUALPOINT 0x01 31#define ALPS_DUALPOINT 0x01
32#define ALPS_WHEEL 0x02 32#define ALPS_WHEEL 0x02
33#define ALPS_FW_BK 0x04 33#define ALPS_FW_BK_1 0x04
34#define ALPS_4BTN 0x08 34#define ALPS_4BTN 0x08
35#define ALPS_OLDPROTO 0x10 35#define ALPS_OLDPROTO 0x10
36#define ALPS_PASS 0x20 36#define ALPS_PASS 0x20
37#define ALPS_FW_BK_2 0x40
37 38
38static struct alps_model_info alps_model_data[] = { 39static struct alps_model_info alps_model_data[] = {
39 { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */ 40 { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */
@@ -43,11 +44,11 @@ static struct alps_model_info alps_model_data[] = {
43 { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, 44 { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
44 { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, 0 }, 45 { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, 0 },
45 { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */ 46 { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
46 { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK }, /* NEC Versa L320 */ 47 { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
47 { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 }, 48 { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 },
48 { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS }, /* Dell Latitude D800 */ 49 { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS }, /* Dell Latitude D800 */
49 { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, 50 { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
50 { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, 51 { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
51 { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */ 52 { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
52 { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, 53 { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
53 { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */ 54 { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
@@ -61,11 +62,11 @@ static struct alps_model_info alps_model_data[] = {
61 62
62/* 63/*
63 * ALPS abolute Mode - new format 64 * ALPS abolute Mode - new format
64 * 65 *
65 * byte 0: 1 ? ? ? 1 ? ? ? 66 * byte 0: 1 ? ? ? 1 ? ? ?
66 * byte 1: 0 x6 x5 x4 x3 x2 x1 x0 67 * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
67 * byte 2: 0 x10 x9 x8 x7 ? fin ges 68 * byte 2: 0 x10 x9 x8 x7 ? fin ges
68 * byte 3: 0 y9 y8 y7 1 M R L 69 * byte 3: 0 y9 y8 y7 1 M R L
69 * byte 4: 0 y6 y5 y4 y3 y2 y1 y0 70 * byte 4: 0 y6 y5 y4 y3 y2 y1 y0
70 * byte 5: 0 z6 z5 z4 z3 z2 z1 z0 71 * byte 5: 0 z6 z5 z4 z3 z2 z1 z0
71 * 72 *
@@ -81,11 +82,12 @@ static void alps_process_packet(struct psmouse *psmouse, struct pt_regs *regs)
81 struct input_dev *dev = &psmouse->dev; 82 struct input_dev *dev = &psmouse->dev;
82 struct input_dev *dev2 = &priv->dev2; 83 struct input_dev *dev2 = &priv->dev2;
83 int x, y, z, ges, fin, left, right, middle; 84 int x, y, z, ges, fin, left, right, middle;
85 int back = 0, forward = 0;
84 86
85 input_regs(dev, regs); 87 input_regs(dev, regs);
86 88
87 if ((packet[0] & 0xc8) == 0x08) { /* 3-byte PS/2 packet */ 89 if ((packet[0] & 0xc8) == 0x08) { /* 3-byte PS/2 packet */
88 input_report_key(dev2, BTN_LEFT, packet[0] & 1); 90 input_report_key(dev2, BTN_LEFT, packet[0] & 1);
89 input_report_key(dev2, BTN_RIGHT, packet[0] & 2); 91 input_report_key(dev2, BTN_RIGHT, packet[0] & 2);
90 input_report_key(dev2, BTN_MIDDLE, packet[0] & 4); 92 input_report_key(dev2, BTN_MIDDLE, packet[0] & 4);
91 input_report_rel(dev2, REL_X, 93 input_report_rel(dev2, REL_X,
@@ -112,6 +114,18 @@ static void alps_process_packet(struct psmouse *psmouse, struct pt_regs *regs)
112 z = packet[5]; 114 z = packet[5];
113 } 115 }
114 116
117 if (priv->i->flags & ALPS_FW_BK_1) {
118 back = packet[2] & 4;
119 forward = packet[0] & 0x10;
120 }
121
122 if (priv->i->flags & ALPS_FW_BK_2) {
123 back = packet[3] & 4;
124 forward = packet[2] & 4;
125 if ((middle = forward && back))
126 forward = back = 0;
127 }
128
115 ges = packet[2] & 1; 129 ges = packet[2] & 1;
116 fin = packet[2] & 2; 130 fin = packet[2] & 2;
117 131
@@ -155,13 +169,12 @@ static void alps_process_packet(struct psmouse *psmouse, struct pt_regs *regs)
155 input_report_abs(dev, ABS_PRESSURE, z); 169 input_report_abs(dev, ABS_PRESSURE, z);
156 input_report_key(dev, BTN_TOOL_FINGER, z > 0); 170 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
157 171
158
159 if (priv->i->flags & ALPS_WHEEL) 172 if (priv->i->flags & ALPS_WHEEL)
160 input_report_rel(dev, REL_WHEEL, ((packet[0] >> 4) & 0x07) | ((packet[2] >> 2) & 0x08)); 173 input_report_rel(dev, REL_WHEEL, ((packet[0] >> 4) & 0x07) | ((packet[2] >> 2) & 0x08));
161 174
162 if (priv->i->flags & ALPS_FW_BK) { 175 if (priv->i->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
163 input_report_key(dev, BTN_FORWARD, packet[0] & 0x10); 176 input_report_key(dev, BTN_FORWARD, forward);
164 input_report_key(dev, BTN_BACK, packet[2] & 0x04); 177 input_report_key(dev, BTN_BACK, back);
165 } 178 }
166 179
167 input_sync(dev); 180 input_sync(dev);
@@ -257,7 +270,6 @@ static struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *vers
257static int alps_passthrough_mode(struct psmouse *psmouse, int enable) 270static int alps_passthrough_mode(struct psmouse *psmouse, int enable)
258{ 271{
259 struct ps2dev *ps2dev = &psmouse->ps2dev; 272 struct ps2dev *ps2dev = &psmouse->ps2dev;
260 unsigned char param[3];
261 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11; 273 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
262 274
263 if (ps2_command(ps2dev, NULL, cmd) || 275 if (ps2_command(ps2dev, NULL, cmd) ||
@@ -267,7 +279,7 @@ static int alps_passthrough_mode(struct psmouse *psmouse, int enable)
267 return -1; 279 return -1;
268 280
269 /* we may get 3 more bytes, just ignore them */ 281 /* we may get 3 more bytes, just ignore them */
270 ps2_command(ps2dev, param, 0x0300); 282 ps2_drain(ps2dev, 3, 100);
271 283
272 return 0; 284 return 0;
273} 285}
@@ -425,7 +437,7 @@ int alps_init(struct psmouse *psmouse)
425 psmouse->dev.relbit[LONG(REL_WHEEL)] |= BIT(REL_WHEEL); 437 psmouse->dev.relbit[LONG(REL_WHEEL)] |= BIT(REL_WHEEL);
426 } 438 }
427 439
428 if (priv->i->flags & ALPS_FW_BK) { 440 if (priv->i->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
429 psmouse->dev.keybit[LONG(BTN_FORWARD)] |= BIT(BTN_FORWARD); 441 psmouse->dev.keybit[LONG(BTN_FORWARD)] |= BIT(BTN_FORWARD);
430 psmouse->dev.keybit[LONG(BTN_BACK)] |= BIT(BTN_BACK); 442 psmouse->dev.keybit[LONG(BTN_BACK)] |= BIT(BTN_BACK);
431 } 443 }
@@ -436,8 +448,8 @@ int alps_init(struct psmouse *psmouse)
436 priv->dev2.id.bustype = BUS_I8042; 448 priv->dev2.id.bustype = BUS_I8042;
437 priv->dev2.id.vendor = 0x0002; 449 priv->dev2.id.vendor = 0x0002;
438 priv->dev2.id.product = PSMOUSE_ALPS; 450 priv->dev2.id.product = PSMOUSE_ALPS;
439 priv->dev2.id.version = 0x0000; 451 priv->dev2.id.version = 0x0000;
440 452
441 priv->dev2.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 453 priv->dev2.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
442 priv->dev2.relbit[LONG(REL_X)] |= BIT(REL_X) | BIT(REL_Y); 454 priv->dev2.relbit[LONG(REL_X)] |= BIT(REL_X) | BIT(REL_Y);
443 priv->dev2.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 455 priv->dev2.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
@@ -461,17 +473,15 @@ init_fail:
461int alps_detect(struct psmouse *psmouse, int set_properties) 473int alps_detect(struct psmouse *psmouse, int set_properties)
462{ 474{
463 int version; 475 int version;
464 struct alps_model_info *model; 476 struct alps_model_info *model;
465 477
466 if (!(model = alps_get_model(psmouse, &version))) 478 if (!(model = alps_get_model(psmouse, &version)))
467 return -1; 479 return -1;
468 480
469 if (set_properties) { 481 if (set_properties) {
470 psmouse->vendor = "ALPS"; 482 psmouse->vendor = "ALPS";
471 if (model->flags & ALPS_DUALPOINT) 483 psmouse->name = model->flags & ALPS_DUALPOINT ?
472 psmouse->name = "DualPoint TouchPad"; 484 "DualPoint TouchPad" : "GlidePoint";
473 else
474 psmouse->name = "GlidePoint";
475 psmouse->model = version; 485 psmouse->model = version;
476 } 486 }
477 return 0; 487 return 0;
diff --git a/drivers/input/mouse/amimouse.c b/drivers/input/mouse/amimouse.c
index 7baa09cca7c5..e994849efb8f 100644
--- a/drivers/input/mouse/amimouse.c
+++ b/drivers/input/mouse/amimouse.c
@@ -33,7 +33,6 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
33MODULE_DESCRIPTION("Amiga mouse driver"); 33MODULE_DESCRIPTION("Amiga mouse driver");
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
35 35
36static int amimouse_used = 0;
37static int amimouse_lastx, amimouse_lasty; 36static int amimouse_lastx, amimouse_lasty;
38static struct input_dev amimouse_dev; 37static struct input_dev amimouse_dev;
39 38
@@ -81,16 +80,12 @@ static int amimouse_open(struct input_dev *dev)
81{ 80{
82 unsigned short joy0dat; 81 unsigned short joy0dat;
83 82
84 if (amimouse_used++)
85 return 0;
86
87 joy0dat = custom.joy0dat; 83 joy0dat = custom.joy0dat;
88 84
89 amimouse_lastx = joy0dat & 0xff; 85 amimouse_lastx = joy0dat & 0xff;
90 amimouse_lasty = joy0dat >> 8; 86 amimouse_lasty = joy0dat >> 8;
91 87
92 if (request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse", amimouse_interrupt)) { 88 if (request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse", amimouse_interrupt)) {
93 amimouse_used--;
94 printk(KERN_ERR "amimouse.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB); 89 printk(KERN_ERR "amimouse.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
95 return -EBUSY; 90 return -EBUSY;
96 } 91 }
@@ -100,8 +95,7 @@ static int amimouse_open(struct input_dev *dev)
100 95
101static void amimouse_close(struct input_dev *dev) 96static void amimouse_close(struct input_dev *dev)
102{ 97{
103 if (!--amimouse_used) 98 free_irq(IRQ_AMIGA_VERTB, amimouse_interrupt);
104 free_irq(IRQ_AMIGA_VERTB, amimouse_interrupt);
105} 99}
106 100
107static int __init amimouse_init(void) 101static int __init amimouse_init(void)
diff --git a/drivers/input/mouse/inport.c b/drivers/input/mouse/inport.c
index ca4e96886627..1f62c0134010 100644
--- a/drivers/input/mouse/inport.c
+++ b/drivers/input/mouse/inport.c
@@ -17,18 +17,18 @@
17/* 17/*
18 * This program is free software; you can redistribute it and/or modify 18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by 19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or 20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version. 21 * (at your option) any later version.
22 * 22 *
23 * This program is distributed in the hope that it will be useful, 23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details. 26 * GNU General Public License for more details.
27 * 27 *
28 * You should have received a copy of the GNU General Public License 28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software 29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 * 31 *
32 * Should you need to contact me, the author, you can do so either by 32 * Should you need to contact me, the author, you can do so either by
33 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: 33 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
34 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 34 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
@@ -87,29 +87,23 @@ MODULE_PARM_DESC(irq, "IRQ number (5=default)");
87 87
88__obsolete_setup("inport_irq="); 88__obsolete_setup("inport_irq=");
89 89
90static int inport_used;
91
92static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs); 90static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs);
93 91
94static int inport_open(struct input_dev *dev) 92static int inport_open(struct input_dev *dev)
95{ 93{
96 if (!inport_used++) { 94 if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL))
97 if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL)) 95 return -EBUSY;
98 return -EBUSY; 96 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
99 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 97 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
100 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
101 }
102 98
103 return 0; 99 return 0;
104} 100}
105 101
106static void inport_close(struct input_dev *dev) 102static void inport_close(struct input_dev *dev)
107{ 103{
108 if (!--inport_used) { 104 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
109 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 105 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
110 outb(INPORT_MODE_BASE, INPORT_DATA_PORT); 106 free_irq(inport_irq, NULL);
111 free_irq(inport_irq, NULL);
112 }
113} 107}
114 108
115static struct input_dev inport_dev = { 109static struct input_dev inport_dev = {
@@ -120,11 +114,11 @@ static struct input_dev inport_dev = {
120 .close = inport_close, 114 .close = inport_close,
121 .name = INPORT_NAME, 115 .name = INPORT_NAME,
122 .phys = "isa023c/input0", 116 .phys = "isa023c/input0",
123 .id = { 117 .id = {
124 .bustype = BUS_ISA, 118 .bustype = BUS_ISA,
125 .vendor = INPORT_VENDOR, 119 .vendor = INPORT_VENDOR,
126 .product = 0x0001, 120 .product = 0x0001,
127 .version = 0x0100, 121 .version = 0x0100,
128 }, 122 },
129}; 123};
130 124
diff --git a/drivers/input/mouse/lifebook.c b/drivers/input/mouse/lifebook.c
new file mode 100644
index 000000000000..bd9df9b28325
--- /dev/null
+++ b/drivers/input/mouse/lifebook.c
@@ -0,0 +1,134 @@
1/*
2 * Fujitsu B-series Lifebook PS/2 TouchScreen driver
3 *
4 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
5 * Copyright (c) 2005 Kenan Esau <kenan.esau@conan.de>
6 *
7 * TouchScreen detection, absolute mode setting and packet layout is taken from
8 * Harald Hoyer's description of the device.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 */
14
15#include <linux/input.h>
16#include <linux/serio.h>
17#include <linux/libps2.h>
18#include <linux/dmi.h>
19
20#include "psmouse.h"
21#include "lifebook.h"
22
23static struct dmi_system_id lifebook_dmi_table[] = {
24 {
25 .ident = "Lifebook B",
26 .matches = {
27 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"),
28 },
29 },
30 { }
31};
32
33
34static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
35{
36 unsigned char *packet = psmouse->packet;
37 struct input_dev *dev = &psmouse->dev;
38
39 if (psmouse->pktcnt != 3)
40 return PSMOUSE_GOOD_DATA;
41
42 input_regs(dev, regs);
43
44 /* calculate X and Y */
45 if ((packet[0] & 0x08) == 0x00) {
46 input_report_abs(dev, ABS_X,
47 (packet[1] | ((packet[0] & 0x30) << 4)));
48 input_report_abs(dev, ABS_Y,
49 1024 - (packet[2] | ((packet[0] & 0xC0) << 2)));
50 } else {
51 input_report_rel(dev, REL_X,
52 ((packet[0] & 0x10) ? packet[1] - 256 : packet[1]));
53 input_report_rel(dev, REL_Y,
54 -(int)((packet[0] & 0x20) ? packet[2] - 256 : packet[2]));
55 }
56
57 input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
58 input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
59 input_report_key(dev, BTN_TOUCH, packet[0] & 0x04);
60
61 input_sync(dev);
62
63 return PSMOUSE_FULL_PACKET;
64}
65
66static int lifebook_absolute_mode(struct psmouse *psmouse)
67{
68 struct ps2dev *ps2dev = &psmouse->ps2dev;
69 unsigned char param;
70
71 if (psmouse_reset(psmouse))
72 return -1;
73
74 /*
75 Enable absolute output -- ps2_command fails always but if
76 you leave this call out the touchsreen will never send
77 absolute coordinates
78 */
79 param = 0x07;
80 ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
81
82 return 0;
83}
84
85static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
86{
87 unsigned char params[] = { 0, 1, 2, 2, 3 };
88
89 if (resolution == 0 || resolution > 400)
90 resolution = 400;
91
92 ps2_command(&psmouse->ps2dev, &params[resolution / 100], PSMOUSE_CMD_SETRES);
93 psmouse->resolution = 50 << params[resolution / 100];
94}
95
96static void lifebook_disconnect(struct psmouse *psmouse)
97{
98 psmouse_reset(psmouse);
99}
100
101int lifebook_detect(struct psmouse *psmouse, int set_properties)
102{
103 if (!dmi_check_system(lifebook_dmi_table))
104 return -1;
105
106 if (set_properties) {
107 psmouse->vendor = "Fujitsu";
108 psmouse->name = "Lifebook TouchScreen";
109 }
110
111 return 0;
112}
113
114int lifebook_init(struct psmouse *psmouse)
115{
116 if (lifebook_absolute_mode(psmouse))
117 return -1;
118
119 psmouse->dev.evbit[0] = BIT(EV_ABS) | BIT(EV_KEY) | BIT(EV_REL);
120 psmouse->dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
121 psmouse->dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
122 psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
123 input_set_abs_params(&psmouse->dev, ABS_X, 0, 1024, 0, 0);
124 input_set_abs_params(&psmouse->dev, ABS_Y, 0, 1024, 0, 0);
125
126 psmouse->protocol_handler = lifebook_process_byte;
127 psmouse->set_resolution = lifebook_set_resolution;
128 psmouse->disconnect = lifebook_disconnect;
129 psmouse->reconnect = lifebook_absolute_mode;
130 psmouse->pktsize = 3;
131
132 return 0;
133}
134
diff --git a/drivers/input/mouse/lifebook.h b/drivers/input/mouse/lifebook.h
new file mode 100644
index 000000000000..be1c0943825d
--- /dev/null
+++ b/drivers/input/mouse/lifebook.h
@@ -0,0 +1,17 @@
1/*
2 * Fujitsu B-series Lifebook PS/2 TouchScreen driver
3 *
4 * Copyright (c) 2005 Vojtech Pavlik
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10
11#ifndef _LIFEBOOK_H
12#define _LIFEBOOK_H
13
14int lifebook_detect(struct psmouse *psmouse, int set_properties);
15int lifebook_init(struct psmouse *psmouse);
16
17#endif
diff --git a/drivers/input/mouse/logibm.c b/drivers/input/mouse/logibm.c
index 77eb83e87f61..8b5243167227 100644
--- a/drivers/input/mouse/logibm.c
+++ b/drivers/input/mouse/logibm.c
@@ -18,18 +18,18 @@
18/* 18/*
19 * This program is free software; you can redistribute it and/or modify 19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by 20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or 21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version. 22 * (at your option) any later version.
23 * 23 *
24 * This program is distributed in the hope that it will be useful, 24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details. 27 * GNU General Public License for more details.
28 * 28 *
29 * You should have received a copy of the GNU General Public License 29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software 30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 * 32 *
33 * Should you need to contact me, the author, you can do so either by 33 * Should you need to contact me, the author, you can do so either by
34 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: 34 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
35 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 35 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
@@ -77,16 +77,11 @@ MODULE_PARM_DESC(irq, "IRQ number (5=default)");
77 77
78__obsolete_setup("logibm_irq="); 78__obsolete_setup("logibm_irq=");
79 79
80static int logibm_used = 0;
81
82static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs); 80static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs);
83 81
84static int logibm_open(struct input_dev *dev) 82static int logibm_open(struct input_dev *dev)
85{ 83{
86 if (logibm_used++)
87 return 0;
88 if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) { 84 if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) {
89 logibm_used--;
90 printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq); 85 printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq);
91 return -EBUSY; 86 return -EBUSY;
92 } 87 }
@@ -96,8 +91,6 @@ static int logibm_open(struct input_dev *dev)
96 91
97static void logibm_close(struct input_dev *dev) 92static void logibm_close(struct input_dev *dev)
98{ 93{
99 if (--logibm_used)
100 return;
101 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT); 94 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
102 free_irq(logibm_irq, NULL); 95 free_irq(logibm_irq, NULL);
103} 96}
@@ -167,7 +160,7 @@ static int __init logibm_init(void)
167 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT); 160 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
168 161
169 input_register_device(&logibm_dev); 162 input_register_device(&logibm_dev);
170 163
171 printk(KERN_INFO "input: Logitech bus mouse at %#x irq %d\n", LOGIBM_BASE, logibm_irq); 164 printk(KERN_INFO "input: Logitech bus mouse at %#x irq %d\n", LOGIBM_BASE, logibm_irq);
172 165
173 return 0; 166 return 0;
diff --git a/drivers/input/mouse/maplemouse.c b/drivers/input/mouse/maplemouse.c
index 12dc0ef5020f..e90c60cbbf05 100644
--- a/drivers/input/mouse/maplemouse.c
+++ b/drivers/input/mouse/maplemouse.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * $Id: maplemouse.c,v 1.2 2004/03/22 01:18:15 lethal Exp $ 2 * $Id: maplemouse.c,v 1.2 2004/03/22 01:18:15 lethal Exp $
3 * SEGA Dreamcast mouse driver 3 * SEGA Dreamcast mouse driver
4 * Based on drivers/usb/usbmouse.c 4 * Based on drivers/usb/usbmouse.c
5 */ 5 */
6 6
@@ -15,80 +15,51 @@
15MODULE_AUTHOR("YAEGASHI Takeshi <t@keshi.org>"); 15MODULE_AUTHOR("YAEGASHI Takeshi <t@keshi.org>");
16MODULE_DESCRIPTION("SEGA Dreamcast mouse driver"); 16MODULE_DESCRIPTION("SEGA Dreamcast mouse driver");
17 17
18struct dc_mouse {
19 struct input_dev dev;
20 int open;
21};
22
23
24static void dc_mouse_callback(struct mapleq *mq) 18static void dc_mouse_callback(struct mapleq *mq)
25{ 19{
26 int buttons, relx, rely, relz; 20 int buttons, relx, rely, relz;
27 struct maple_device *mapledev = mq->dev; 21 struct maple_device *mapledev = mq->dev;
28 struct dc_mouse *mouse = mapledev->private_data; 22 struct input_dev *dev = mapledev->private_data;
29 struct input_dev *dev = &mouse->dev;
30 unsigned char *res = mq->recvbuf; 23 unsigned char *res = mq->recvbuf;
31 24
32 buttons = ~res[8]; 25 buttons = ~res[8];
33 relx=*(unsigned short *)(res+12)-512; 26 relx = *(unsigned short *)(res + 12) - 512;
34 rely=*(unsigned short *)(res+14)-512; 27 rely = *(unsigned short *)(res + 14) - 512;
35 relz=*(unsigned short *)(res+16)-512; 28 relz = *(unsigned short *)(res + 16) - 512;
36 29
37 input_report_key(dev, BTN_LEFT, buttons&4); 30 input_report_key(dev, BTN_LEFT, buttons & 4);
38 input_report_key(dev, BTN_MIDDLE, buttons&9); 31 input_report_key(dev, BTN_MIDDLE, buttons & 9);
39 input_report_key(dev, BTN_RIGHT, buttons&2); 32 input_report_key(dev, BTN_RIGHT, buttons & 2);
40 input_report_rel(dev, REL_X, relx); 33 input_report_rel(dev, REL_X, relx);
41 input_report_rel(dev, REL_Y, rely); 34 input_report_rel(dev, REL_Y, rely);
42 input_report_rel(dev, REL_WHEEL, relz); 35 input_report_rel(dev, REL_WHEEL, relz);
43 input_sync(dev); 36 input_sync(dev);
44} 37}
45 38
46
47static int dc_mouse_open(struct input_dev *dev)
48{
49 struct dc_mouse *mouse = dev->private;
50 mouse->open++;
51 return 0;
52}
53
54
55static void dc_mouse_close(struct input_dev *dev)
56{
57 struct dc_mouse *mouse = dev->private;
58 mouse->open--;
59}
60
61
62static int dc_mouse_connect(struct maple_device *dev) 39static int dc_mouse_connect(struct maple_device *dev)
63{ 40{
64 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]); 41 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
65 struct dc_mouse *mouse; 42 struct input_dev *input_dev;
66 43
67 if (!(mouse = kmalloc(sizeof(struct dc_mouse), GFP_KERNEL))) 44 if (!(input_dev = kmalloc(sizeof(struct input_dev), GFP_KERNEL)))
68 return -1; 45 return -1;
69 memset(mouse, 0, sizeof(struct dc_mouse));
70
71 dev->private_data = mouse;
72 46
73 mouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 47 dev->private_data = input_dev;
74 mouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
75 mouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL);
76 48
77 init_input_dev(&mouse->dev); 49 memset(input_dev, 0, sizeof(struct dc_mouse));
50 init_input_dev(input_dev);
51 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
52 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
53 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL);
78 54
79 mouse->dev.private = mouse; 55 input_dev->name = dev->product_name;
80 mouse->dev.open = dc_mouse_open; 56 input_dev->id.bustype = BUS_MAPLE;
81 mouse->dev.close = dc_mouse_close;
82 mouse->dev.event = NULL;
83 57
84 mouse->dev.name = dev->product_name; 58 input_register_device(input_dev);
85 mouse->dev.id.bustype = BUS_MAPLE;
86
87 input_register_device(&mouse->dev);
88 59
89 maple_getcond_callback(dev, dc_mouse_callback, 1, MAPLE_FUNC_MOUSE); 60 maple_getcond_callback(dev, dc_mouse_callback, 1, MAPLE_FUNC_MOUSE);
90 61
91 printk(KERN_INFO "input: mouse(0x%lx): %s\n", data, mouse->dev.name); 62 printk(KERN_INFO "input: mouse(0x%lx): %s\n", data, input_dev->name);
92 63
93 return 0; 64 return 0;
94} 65}
@@ -96,10 +67,10 @@ static int dc_mouse_connect(struct maple_device *dev)
96 67
97static void dc_mouse_disconnect(struct maple_device *dev) 68static void dc_mouse_disconnect(struct maple_device *dev)
98{ 69{
99 struct dc_mouse *mouse = dev->private_data; 70 struct input_dev *input_dev = dev->private_data;
100 71
101 input_unregister_device(&mouse->dev); 72 input_unregister_device(input_dev);
102 kfree(mouse); 73 kfree(input_dev);
103} 74}
104 75
105 76
diff --git a/drivers/input/mouse/pc110pad.c b/drivers/input/mouse/pc110pad.c
index 0c74918fe254..93393d5c0078 100644
--- a/drivers/input/mouse/pc110pad.c
+++ b/drivers/input/mouse/pc110pad.c
@@ -4,7 +4,7 @@
4 * Copyright (c) 2000-2001 Vojtech Pavlik 4 * Copyright (c) 2000-2001 Vojtech Pavlik
5 * 5 *
6 * Based on the work of: 6 * Based on the work of:
7 * Alan Cox Robin O'Leary 7 * Alan Cox Robin O'Leary
8 */ 8 */
9 9
10/* 10/*
@@ -56,7 +56,6 @@ static int pc110pad_io = 0x15e0;
56static struct input_dev pc110pad_dev; 56static struct input_dev pc110pad_dev;
57static int pc110pad_data[3]; 57static int pc110pad_data[3];
58static int pc110pad_count; 58static int pc110pad_count;
59static int pc110pad_used;
60 59
61static char *pc110pad_name = "IBM PC110 TouchPad"; 60static char *pc110pad_name = "IBM PC110 TouchPad";
62static char *pc110pad_phys = "isa15e0/input0"; 61static char *pc110pad_phys = "isa15e0/input0";
@@ -74,7 +73,7 @@ static irqreturn_t pc110pad_interrupt(int irq, void *ptr, struct pt_regs *regs)
74 73
75 if (pc110pad_count < 3) 74 if (pc110pad_count < 3)
76 return IRQ_HANDLED; 75 return IRQ_HANDLED;
77 76
78 input_regs(&pc110pad_dev, regs); 77 input_regs(&pc110pad_dev, regs);
79 input_report_key(&pc110pad_dev, BTN_TOUCH, 78 input_report_key(&pc110pad_dev, BTN_TOUCH,
80 pc110pad_data[0] & 0x01); 79 pc110pad_data[0] & 0x01);
@@ -90,15 +89,11 @@ static irqreturn_t pc110pad_interrupt(int irq, void *ptr, struct pt_regs *regs)
90 89
91static void pc110pad_close(struct input_dev *dev) 90static void pc110pad_close(struct input_dev *dev)
92{ 91{
93 if (!--pc110pad_used) 92 outb(PC110PAD_OFF, pc110pad_io + 2);
94 outb(PC110PAD_OFF, pc110pad_io + 2);
95} 93}
96 94
97static int pc110pad_open(struct input_dev *dev) 95static int pc110pad_open(struct input_dev *dev)
98{ 96{
99 if (pc110pad_used++)
100 return 0;
101
102 pc110pad_interrupt(0,NULL,NULL); 97 pc110pad_interrupt(0,NULL,NULL);
103 pc110pad_interrupt(0,NULL,NULL); 98 pc110pad_interrupt(0,NULL,NULL);
104 pc110pad_interrupt(0,NULL,NULL); 99 pc110pad_interrupt(0,NULL,NULL);
@@ -145,7 +140,7 @@ static int __init pc110pad_init(void)
145 140
146 pc110pad_dev.absmax[ABS_X] = 0x1ff; 141 pc110pad_dev.absmax[ABS_X] = 0x1ff;
147 pc110pad_dev.absmax[ABS_Y] = 0x0ff; 142 pc110pad_dev.absmax[ABS_Y] = 0x0ff;
148 143
149 pc110pad_dev.open = pc110pad_open; 144 pc110pad_dev.open = pc110pad_open;
150 pc110pad_dev.close = pc110pad_close; 145 pc110pad_dev.close = pc110pad_close;
151 146
@@ -156,17 +151,17 @@ static int __init pc110pad_init(void)
156 pc110pad_dev.id.product = 0x0001; 151 pc110pad_dev.id.product = 0x0001;
157 pc110pad_dev.id.version = 0x0100; 152 pc110pad_dev.id.version = 0x0100;
158 153
159 input_register_device(&pc110pad_dev); 154 input_register_device(&pc110pad_dev);
160 155
161 printk(KERN_INFO "input: %s at %#x irq %d\n", 156 printk(KERN_INFO "input: %s at %#x irq %d\n",
162 pc110pad_name, pc110pad_io, pc110pad_irq); 157 pc110pad_name, pc110pad_io, pc110pad_irq);
163 158
164 return 0; 159 return 0;
165} 160}
166 161
167static void __exit pc110pad_exit(void) 162static void __exit pc110pad_exit(void)
168{ 163{
169 input_unregister_device(&pc110pad_dev); 164 input_unregister_device(&pc110pad_dev);
170 165
171 outb(PC110PAD_OFF, pc110pad_io + 2); 166 outb(PC110PAD_OFF, pc110pad_io + 2);
172 167
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 019034b21a0b..19785a6c5abd 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -24,6 +24,7 @@
24#include "synaptics.h" 24#include "synaptics.h"
25#include "logips2pp.h" 25#include "logips2pp.h"
26#include "alps.h" 26#include "alps.h"
27#include "lifebook.h"
27 28
28#define DRIVER_DESC "PS/2 mouse driver" 29#define DRIVER_DESC "PS/2 mouse driver"
29 30
@@ -31,10 +32,9 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
31MODULE_DESCRIPTION(DRIVER_DESC); 32MODULE_DESCRIPTION(DRIVER_DESC);
32MODULE_LICENSE("GPL"); 33MODULE_LICENSE("GPL");
33 34
34static unsigned int psmouse_max_proto = -1U; 35static unsigned int psmouse_max_proto = PSMOUSE_AUTO;
35static int psmouse_set_maxproto(const char *val, struct kernel_param *kp); 36static int psmouse_set_maxproto(const char *val, struct kernel_param *kp);
36static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp); 37static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp);
37static char *psmouse_proto_abbrev[] = { NULL, "bare", NULL, NULL, NULL, "imps", "exps", NULL, NULL, NULL };
38#define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int) 38#define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int)
39#define param_set_proto_abbrev psmouse_set_maxproto 39#define param_set_proto_abbrev psmouse_set_maxproto
40#define param_get_proto_abbrev psmouse_get_maxproto 40#define param_get_proto_abbrev psmouse_get_maxproto
@@ -57,6 +57,7 @@ static unsigned int psmouse_resetafter;
57module_param_named(resetafter, psmouse_resetafter, uint, 0644); 57module_param_named(resetafter, psmouse_resetafter, uint, 0644);
58MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never)."); 58MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never).");
59 59
60PSMOUSE_DEFINE_ATTR(protocol);
60PSMOUSE_DEFINE_ATTR(rate); 61PSMOUSE_DEFINE_ATTR(rate);
61PSMOUSE_DEFINE_ATTR(resolution); 62PSMOUSE_DEFINE_ATTR(resolution);
62PSMOUSE_DEFINE_ATTR(resetafter); 63PSMOUSE_DEFINE_ATTR(resetafter);
@@ -67,7 +68,23 @@ __obsolete_setup("psmouse_smartscroll=");
67__obsolete_setup("psmouse_resetafter="); 68__obsolete_setup("psmouse_resetafter=");
68__obsolete_setup("psmouse_rate="); 69__obsolete_setup("psmouse_rate=");
69 70
70static char *psmouse_protocols[] = { "None", "PS/2", "PS2++", "ThinkPS/2", "GenPS/2", "ImPS/2", "ImExPS/2", "SynPS/2", "AlpsPS/2" }; 71/*
72 * psmouse_sem protects all operations changing state of mouse
73 * (connecting, disconnecting, changing rate or resolution via
74 * sysfs). We could use a per-device semaphore but since there
75 * rarely more than one PS/2 mouse connected and since semaphore
76 * is taken in "slow" paths it is not worth it.
77 */
78static DECLARE_MUTEX(psmouse_sem);
79
80struct psmouse_protocol {
81 enum psmouse_type type;
82 char *name;
83 char *alias;
84 int maxproto;
85 int (*detect)(struct psmouse *, int);
86 int (*init)(struct psmouse *);
87};
71 88
72/* 89/*
73 * psmouse_process_byte() analyzes the PS/2 data stream and reports 90 * psmouse_process_byte() analyzes the PS/2 data stream and reports
@@ -407,12 +424,15 @@ static int thinking_detect(struct psmouse *psmouse, int set_properties)
407 */ 424 */
408static int ps2bare_detect(struct psmouse *psmouse, int set_properties) 425static int ps2bare_detect(struct psmouse *psmouse, int set_properties)
409{ 426{
410 if (!psmouse->vendor) psmouse->vendor = "Generic"; 427 if (set_properties) {
411 if (!psmouse->name) psmouse->name = "Mouse"; 428 if (!psmouse->vendor) psmouse->vendor = "Generic";
429 if (!psmouse->name) psmouse->name = "Mouse";
430 }
412 431
413 return 0; 432 return 0;
414} 433}
415 434
435
416/* 436/*
417 * psmouse_extensions() probes for any extensions to the basic PS/2 protocol 437 * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
418 * the mouse may have. 438 * the mouse may have.
@@ -424,6 +444,17 @@ static int psmouse_extensions(struct psmouse *psmouse,
424 int synaptics_hardware = 0; 444 int synaptics_hardware = 0;
425 445
426/* 446/*
447 * We always check for lifebook because it does not disturb mouse
448 * (it only checks DMI information).
449 */
450 if (lifebook_detect(psmouse, set_properties) == 0) {
451 if (max_proto > PSMOUSE_IMEX) {
452 if (!set_properties || lifebook_init(psmouse) == 0)
453 return PSMOUSE_LIFEBOOK;
454 }
455 }
456
457/*
427 * Try Kensington ThinkingMouse (we try first, because synaptics probe 458 * Try Kensington ThinkingMouse (we try first, because synaptics probe
428 * upsets the thinkingmouse). 459 * upsets the thinkingmouse).
429 */ 460 */
@@ -506,6 +537,103 @@ static int psmouse_extensions(struct psmouse *psmouse,
506 return PSMOUSE_PS2; 537 return PSMOUSE_PS2;
507} 538}
508 539
540static struct psmouse_protocol psmouse_protocols[] = {
541 {
542 .type = PSMOUSE_PS2,
543 .name = "PS/2",
544 .alias = "bare",
545 .maxproto = 1,
546 .detect = ps2bare_detect,
547 },
548 {
549 .type = PSMOUSE_PS2PP,
550 .name = "PS2++",
551 .alias = "logitech",
552 .detect = ps2pp_init,
553 },
554 {
555 .type = PSMOUSE_THINKPS,
556 .name = "ThinkPS/2",
557 .alias = "thinkps",
558 .detect = thinking_detect,
559 },
560 {
561 .type = PSMOUSE_GENPS,
562 .name = "GenPS/2",
563 .alias = "genius",
564 .detect = genius_detect,
565 },
566 {
567 .type = PSMOUSE_IMPS,
568 .name = "ImPS/2",
569 .alias = "imps",
570 .maxproto = 1,
571 .detect = intellimouse_detect,
572 },
573 {
574 .type = PSMOUSE_IMEX,
575 .name = "ImExPS/2",
576 .alias = "exps",
577 .maxproto = 1,
578 .detect = im_explorer_detect,
579 },
580 {
581 .type = PSMOUSE_SYNAPTICS,
582 .name = "SynPS/2",
583 .alias = "synaptics",
584 .detect = synaptics_detect,
585 .init = synaptics_init,
586 },
587 {
588 .type = PSMOUSE_ALPS,
589 .name = "AlpsPS/2",
590 .alias = "alps",
591 .detect = alps_detect,
592 .init = alps_init,
593 },
594 {
595 .type = PSMOUSE_LIFEBOOK,
596 .name = "LBPS/2",
597 .alias = "lifebook",
598 .init = lifebook_init,
599 },
600 {
601 .type = PSMOUSE_AUTO,
602 .name = "auto",
603 .alias = "any",
604 .maxproto = 1,
605 },
606};
607
608static struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type)
609{
610 int i;
611
612 for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++)
613 if (psmouse_protocols[i].type == type)
614 return &psmouse_protocols[i];
615
616 WARN_ON(1);
617 return &psmouse_protocols[0];
618}
619
620static struct psmouse_protocol *psmouse_protocol_by_name(const char *name, size_t len)
621{
622 struct psmouse_protocol *p;
623 int i;
624
625 for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++) {
626 p = &psmouse_protocols[i];
627
628 if ((strlen(p->name) == len && !strncmp(p->name, name, len)) ||
629 (strlen(p->alias) == len && !strncmp(p->alias, name, len)))
630 return &psmouse_protocols[i];
631 }
632
633 return NULL;
634}
635
636
509/* 637/*
510 * psmouse_probe() probes for a PS/2 mouse. 638 * psmouse_probe() probes for a PS/2 mouse.
511 */ 639 */
@@ -653,30 +781,84 @@ static void psmouse_cleanup(struct serio *serio)
653 781
654static void psmouse_disconnect(struct serio *serio) 782static void psmouse_disconnect(struct serio *serio)
655{ 783{
656 struct psmouse *psmouse, *parent; 784 struct psmouse *psmouse, *parent = NULL;
657 785
786 psmouse = serio_get_drvdata(serio);
787
788 device_remove_file(&serio->dev, &psmouse_attr_protocol);
658 device_remove_file(&serio->dev, &psmouse_attr_rate); 789 device_remove_file(&serio->dev, &psmouse_attr_rate);
659 device_remove_file(&serio->dev, &psmouse_attr_resolution); 790 device_remove_file(&serio->dev, &psmouse_attr_resolution);
660 device_remove_file(&serio->dev, &psmouse_attr_resetafter); 791 device_remove_file(&serio->dev, &psmouse_attr_resetafter);
661 792
662 psmouse = serio_get_drvdata(serio); 793 down(&psmouse_sem);
794
663 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 795 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
664 796
665 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { 797 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
666 parent = serio_get_drvdata(serio->parent); 798 parent = serio_get_drvdata(serio->parent);
667 if (parent->pt_deactivate) 799 psmouse_deactivate(parent);
668 parent->pt_deactivate(parent);
669 } 800 }
670 801
671 if (psmouse->disconnect) 802 if (psmouse->disconnect)
672 psmouse->disconnect(psmouse); 803 psmouse->disconnect(psmouse);
673 804
805 if (parent && parent->pt_deactivate)
806 parent->pt_deactivate(parent);
807
674 psmouse_set_state(psmouse, PSMOUSE_IGNORE); 808 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
675 809
676 input_unregister_device(&psmouse->dev); 810 input_unregister_device(&psmouse->dev);
677 serio_close(serio); 811 serio_close(serio);
678 serio_set_drvdata(serio, NULL); 812 serio_set_drvdata(serio, NULL);
679 kfree(psmouse); 813 kfree(psmouse);
814
815 if (parent)
816 psmouse_activate(parent);
817
818 up(&psmouse_sem);
819}
820
821static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_protocol *proto)
822{
823 memset(&psmouse->dev, 0, sizeof(struct input_dev));
824
825 init_input_dev(&psmouse->dev);
826
827 psmouse->dev.private = psmouse;
828 psmouse->dev.dev = &psmouse->ps2dev.serio->dev;
829
830 psmouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
831 psmouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
832 psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
833
834 psmouse->set_rate = psmouse_set_rate;
835 psmouse->set_resolution = psmouse_set_resolution;
836 psmouse->protocol_handler = psmouse_process_byte;
837 psmouse->pktsize = 3;
838
839 if (proto && (proto->detect || proto->init)) {
840 if (proto->detect && proto->detect(psmouse, 1) < 0)
841 return -1;
842
843 if (proto->init && proto->init(psmouse) < 0)
844 return -1;
845
846 psmouse->type = proto->type;
847 }
848 else
849 psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1);
850
851 sprintf(psmouse->devname, "%s %s %s",
852 psmouse_protocol_by_type(psmouse->type)->name, psmouse->vendor, psmouse->name);
853
854 psmouse->dev.name = psmouse->devname;
855 psmouse->dev.phys = psmouse->phys;
856 psmouse->dev.id.bustype = BUS_I8042;
857 psmouse->dev.id.vendor = 0x0002;
858 psmouse->dev.id.product = psmouse->type;
859 psmouse->dev.id.version = psmouse->model;
860
861 return 0;
680} 862}
681 863
682/* 864/*
@@ -688,6 +870,8 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
688 struct psmouse *psmouse, *parent = NULL; 870 struct psmouse *psmouse, *parent = NULL;
689 int retval; 871 int retval;
690 872
873 down(&psmouse_sem);
874
691 /* 875 /*
692 * If this is a pass-through port deactivate parent so the device 876 * If this is a pass-through port deactivate parent so the device
693 * connected to this port can be successfully identified 877 * connected to this port can be successfully identified
@@ -697,20 +881,14 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
697 psmouse_deactivate(parent); 881 psmouse_deactivate(parent);
698 } 882 }
699 883
700 if (!(psmouse = kmalloc(sizeof(struct psmouse), GFP_KERNEL))) { 884 if (!(psmouse = kcalloc(1, sizeof(struct psmouse), GFP_KERNEL))) {
701 retval = -ENOMEM; 885 retval = -ENOMEM;
702 goto out; 886 goto out;
703 } 887 }
704 888
705 memset(psmouse, 0, sizeof(struct psmouse));
706
707 ps2_init(&psmouse->ps2dev, serio); 889 ps2_init(&psmouse->ps2dev, serio);
708 sprintf(psmouse->phys, "%s/input0", serio->phys); 890 sprintf(psmouse->phys, "%s/input0", serio->phys);
709 psmouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 891
710 psmouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
711 psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
712 psmouse->dev.private = psmouse;
713 psmouse->dev.dev = &serio->dev;
714 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); 892 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
715 893
716 serio_set_drvdata(serio, psmouse); 894 serio_set_drvdata(serio, psmouse);
@@ -734,25 +912,10 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
734 psmouse->resolution = psmouse_resolution; 912 psmouse->resolution = psmouse_resolution;
735 psmouse->resetafter = psmouse_resetafter; 913 psmouse->resetafter = psmouse_resetafter;
736 psmouse->smartscroll = psmouse_smartscroll; 914 psmouse->smartscroll = psmouse_smartscroll;
737 psmouse->set_rate = psmouse_set_rate;
738 psmouse->set_resolution = psmouse_set_resolution;
739 psmouse->protocol_handler = psmouse_process_byte;
740 psmouse->pktsize = 3;
741 915
742 psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1); 916 psmouse_switch_protocol(psmouse, NULL);
743
744 sprintf(psmouse->devname, "%s %s %s",
745 psmouse_protocols[psmouse->type], psmouse->vendor, psmouse->name);
746
747 psmouse->dev.name = psmouse->devname;
748 psmouse->dev.phys = psmouse->phys;
749 psmouse->dev.id.bustype = BUS_I8042;
750 psmouse->dev.id.vendor = 0x0002;
751 psmouse->dev.id.product = psmouse->type;
752 psmouse->dev.id.version = psmouse->model;
753 917
754 input_register_device(&psmouse->dev); 918 input_register_device(&psmouse->dev);
755
756 printk(KERN_INFO "input: %s on %s\n", psmouse->devname, serio->phys); 919 printk(KERN_INFO "input: %s on %s\n", psmouse->devname, serio->phys);
757 920
758 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 921 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
@@ -762,6 +925,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
762 if (parent && parent->pt_activate) 925 if (parent && parent->pt_activate)
763 parent->pt_activate(parent); 926 parent->pt_activate(parent);
764 927
928 device_create_file(&serio->dev, &psmouse_attr_protocol);
765 device_create_file(&serio->dev, &psmouse_attr_rate); 929 device_create_file(&serio->dev, &psmouse_attr_rate);
766 device_create_file(&serio->dev, &psmouse_attr_resolution); 930 device_create_file(&serio->dev, &psmouse_attr_resolution);
767 device_create_file(&serio->dev, &psmouse_attr_resetafter); 931 device_create_file(&serio->dev, &psmouse_attr_resetafter);
@@ -771,10 +935,11 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
771 retval = 0; 935 retval = 0;
772 936
773out: 937out:
774 /* If this is a pass-through port the parent awaits to be activated */ 938 /* If this is a pass-through port the parent needs to be re-activated */
775 if (parent) 939 if (parent)
776 psmouse_activate(parent); 940 psmouse_activate(parent);
777 941
942 up(&psmouse_sem);
778 return retval; 943 return retval;
779} 944}
780 945
@@ -791,6 +956,8 @@ static int psmouse_reconnect(struct serio *serio)
791 return -1; 956 return -1;
792 } 957 }
793 958
959 down(&psmouse_sem);
960
794 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { 961 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
795 parent = serio_get_drvdata(serio->parent); 962 parent = serio_get_drvdata(serio->parent);
796 psmouse_deactivate(parent); 963 psmouse_deactivate(parent);
@@ -823,6 +990,7 @@ out:
823 if (parent) 990 if (parent)
824 psmouse_activate(parent); 991 psmouse_activate(parent);
825 992
993 up(&psmouse_sem);
826 return rc; 994 return rc;
827} 995}
828 996
@@ -893,26 +1061,109 @@ ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t coun
893 1061
894 if (serio->drv != &psmouse_drv) { 1062 if (serio->drv != &psmouse_drv) {
895 retval = -ENODEV; 1063 retval = -ENODEV;
896 goto out; 1064 goto out_unpin;
1065 }
1066
1067 retval = down_interruptible(&psmouse_sem);
1068 if (retval)
1069 goto out_unpin;
1070
1071 if (psmouse->state == PSMOUSE_IGNORE) {
1072 retval = -ENODEV;
1073 goto out_up;
897 } 1074 }
898 1075
899 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { 1076 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
900 parent = serio_get_drvdata(serio->parent); 1077 parent = serio_get_drvdata(serio->parent);
901 psmouse_deactivate(parent); 1078 psmouse_deactivate(parent);
902 } 1079 }
1080
903 psmouse_deactivate(psmouse); 1081 psmouse_deactivate(psmouse);
904 1082
905 retval = handler(psmouse, buf, count); 1083 retval = handler(psmouse, buf, count);
906 1084
907 psmouse_activate(psmouse); 1085 if (retval != -ENODEV)
1086 psmouse_activate(psmouse);
1087
908 if (parent) 1088 if (parent)
909 psmouse_activate(parent); 1089 psmouse_activate(parent);
910 1090
911out: 1091 out_up:
1092 up(&psmouse_sem);
1093 out_unpin:
912 serio_unpin_driver(serio); 1094 serio_unpin_driver(serio);
913 return retval; 1095 return retval;
914} 1096}
915 1097
1098static ssize_t psmouse_attr_show_protocol(struct psmouse *psmouse, char *buf)
1099{
1100 return sprintf(buf, "%s\n", psmouse_protocol_by_type(psmouse->type)->name);
1101}
1102
1103static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, const char *buf, size_t count)
1104{
1105 struct serio *serio = psmouse->ps2dev.serio;
1106 struct psmouse *parent = NULL;
1107 struct psmouse_protocol *proto;
1108 int retry = 0;
1109
1110 if (!(proto = psmouse_protocol_by_name(buf, count)))
1111 return -EINVAL;
1112
1113 if (psmouse->type == proto->type)
1114 return count;
1115
1116 while (serio->child) {
1117 if (++retry > 3) {
1118 printk(KERN_WARNING "psmouse: failed to destroy child port, protocol change aborted.\n");
1119 return -EIO;
1120 }
1121
1122 up(&psmouse_sem);
1123 serio_unpin_driver(serio);
1124 serio_unregister_child_port(serio);
1125 serio_pin_driver_uninterruptible(serio);
1126 down(&psmouse_sem);
1127
1128 if (serio->drv != &psmouse_drv)
1129 return -ENODEV;
1130
1131 if (psmouse->type == proto->type)
1132 return count; /* switched by other thread */
1133 }
1134
1135 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1136 parent = serio_get_drvdata(serio->parent);
1137 if (parent->pt_deactivate)
1138 parent->pt_deactivate(parent);
1139 }
1140
1141 if (psmouse->disconnect)
1142 psmouse->disconnect(psmouse);
1143
1144 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1145 input_unregister_device(&psmouse->dev);
1146
1147 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
1148
1149 if (psmouse_switch_protocol(psmouse, proto) < 0) {
1150 psmouse_reset(psmouse);
1151 /* default to PSMOUSE_PS2 */
1152 psmouse_switch_protocol(psmouse, &psmouse_protocols[0]);
1153 }
1154
1155 psmouse_initialize(psmouse);
1156 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1157
1158 input_register_device(&psmouse->dev);
1159 printk(KERN_INFO "input: %s on %s\n", psmouse->devname, serio->phys);
1160
1161 if (parent && parent->pt_activate)
1162 parent->pt_activate(parent);
1163
1164 return count;
1165}
1166
916static ssize_t psmouse_attr_show_rate(struct psmouse *psmouse, char *buf) 1167static ssize_t psmouse_attr_show_rate(struct psmouse *psmouse, char *buf)
917{ 1168{
918 return sprintf(buf, "%d\n", psmouse->rate); 1169 return sprintf(buf, "%d\n", psmouse->rate);
@@ -969,34 +1220,26 @@ static ssize_t psmouse_attr_set_resetafter(struct psmouse *psmouse, const char *
969 1220
970static int psmouse_set_maxproto(const char *val, struct kernel_param *kp) 1221static int psmouse_set_maxproto(const char *val, struct kernel_param *kp)
971{ 1222{
972 int i; 1223 struct psmouse_protocol *proto;
973 1224
974 if (!val) 1225 if (!val)
975 return -EINVAL; 1226 return -EINVAL;
976 1227
977 if (!strncmp(val, "any", 3)) { 1228 proto = psmouse_protocol_by_name(val, strlen(val));
978 *((unsigned int *)kp->arg) = -1U;
979 return 0;
980 }
981 1229
982 for (i = 0; i < ARRAY_SIZE(psmouse_proto_abbrev); i++) { 1230 if (!proto || !proto->maxproto)
983 if (!psmouse_proto_abbrev[i]) 1231 return -EINVAL;
984 continue;
985 1232
986 if (!strncmp(val, psmouse_proto_abbrev[i], strlen(psmouse_proto_abbrev[i]))) { 1233 *((unsigned int *)kp->arg) = proto->type;
987 *((unsigned int *)kp->arg) = i;
988 return 0;
989 }
990 }
991 1234
992 return -EINVAL; \ 1235 return 0; \
993} 1236}
994 1237
995static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp) 1238static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp)
996{ 1239{
997 return sprintf(buffer, "%s\n", 1240 int type = *((unsigned int *)kp->arg);
998 psmouse_max_proto < ARRAY_SIZE(psmouse_proto_abbrev) ? 1241
999 psmouse_proto_abbrev[psmouse_max_proto] : "any"); 1242 return sprintf(buffer, "%s\n", psmouse_protocol_by_type(type)->name);
1000} 1243}
1001 1244
1002static int __init psmouse_init(void) 1245static int __init psmouse_init(void)
diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
index 79e17a0c4664..86691cf43433 100644
--- a/drivers/input/mouse/psmouse.h
+++ b/drivers/input/mouse/psmouse.h
@@ -77,6 +77,8 @@ enum psmouse_type {
77 PSMOUSE_IMEX, 77 PSMOUSE_IMEX,
78 PSMOUSE_SYNAPTICS, 78 PSMOUSE_SYNAPTICS,
79 PSMOUSE_ALPS, 79 PSMOUSE_ALPS,
80 PSMOUSE_LIFEBOOK,
81 PSMOUSE_AUTO /* This one should always be last */
80}; 82};
81 83
82int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command); 84int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command);
@@ -99,7 +101,7 @@ static ssize_t psmouse_do_set_##_name(struct device *d, struct device_attribute
99{ \ 101{ \
100 return psmouse_attr_set_helper(d, b, s, psmouse_attr_set_##_name); \ 102 return psmouse_attr_set_helper(d, b, s, psmouse_attr_set_##_name); \
101} \ 103} \
102static struct device_attribute psmouse_attr_##_name = \ 104static struct device_attribute psmouse_attr_##_name = \
103 __ATTR(_name, S_IWUSR | S_IRUGO, \ 105 __ATTR(_name, S_IWUSR | S_IRUGO, \
104 psmouse_do_show_##_name, psmouse_do_set_##_name); 106 psmouse_do_show_##_name, psmouse_do_set_##_name);
105 107
diff --git a/drivers/input/mouse/rpcmouse.c b/drivers/input/mouse/rpcmouse.c
index 7280f68afcee..8fe1212b8fd7 100644
--- a/drivers/input/mouse/rpcmouse.c
+++ b/drivers/input/mouse/rpcmouse.c
@@ -59,7 +59,7 @@ static irqreturn_t rpcmouse_irq(int irq, void *dev_id, struct pt_regs *regs)
59 b = (short) (__raw_readl(0xe0310000) ^ 0x70); 59 b = (short) (__raw_readl(0xe0310000) ^ 0x70);
60 60
61 dx = x - rpcmouse_lastx; 61 dx = x - rpcmouse_lastx;
62 dy = y - rpcmouse_lasty; 62 dy = y - rpcmouse_lasty;
63 63
64 rpcmouse_lastx = x; 64 rpcmouse_lastx = x;
65 rpcmouse_lasty = y; 65 rpcmouse_lasty = y;
diff --git a/drivers/input/mouse/vsxxxaa.c b/drivers/input/mouse/vsxxxaa.c
index b2cb101c8110..f024be9b44d2 100644
--- a/drivers/input/mouse/vsxxxaa.c
+++ b/drivers/input/mouse/vsxxxaa.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for DEC VSXXX-AA mouse (hockey-puck mouse, ball or two rollers) 2 * Driver for DEC VSXXX-AA mouse (hockey-puck mouse, ball or two rollers)
3 * DEC VSXXX-GA mouse (rectangular mouse, with ball) 3 * DEC VSXXX-GA mouse (rectangular mouse, with ball)
4 * DEC VSXXX-AB tablet (digitizer with hair cross or stylus) 4 * DEC VSXXX-AB tablet (digitizer with hair cross or stylus)
5 * 5 *
6 * Copyright (C) 2003-2004 by Jan-Benedict Glaw <jbglaw@lug-owl.de> 6 * Copyright (C) 2003-2004 by Jan-Benedict Glaw <jbglaw@lug-owl.de>
7 * 7 *
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index 062848ac7e6b..c6194a9dd174 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -220,6 +220,7 @@ static void mousedev_notify_readers(struct mousedev *mousedev, struct mousedev_h
220 struct mousedev_list *list; 220 struct mousedev_list *list;
221 struct mousedev_motion *p; 221 struct mousedev_motion *p;
222 unsigned long flags; 222 unsigned long flags;
223 int wake_readers = 0;
223 224
224 list_for_each_entry(list, &mousedev->list, node) { 225 list_for_each_entry(list, &mousedev->list, node) {
225 spin_lock_irqsave(&list->packet_lock, flags); 226 spin_lock_irqsave(&list->packet_lock, flags);
@@ -255,11 +256,14 @@ static void mousedev_notify_readers(struct mousedev *mousedev, struct mousedev_h
255 256
256 spin_unlock_irqrestore(&list->packet_lock, flags); 257 spin_unlock_irqrestore(&list->packet_lock, flags);
257 258
258 if (list->ready) 259 if (list->ready) {
259 kill_fasync(&list->fasync, SIGIO, POLL_IN); 260 kill_fasync(&list->fasync, SIGIO, POLL_IN);
261 wake_readers = 1;
262 }
260 } 263 }
261 264
262 wake_up_interruptible(&mousedev->wait); 265 if (wake_readers)
266 wake_up_interruptible(&mousedev->wait);
263} 267}
264 268
265static void mousedev_touchpad_touch(struct mousedev *mousedev, int value) 269static void mousedev_touchpad_touch(struct mousedev *mousedev, int value)
diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c
index c978657068c5..d4c990f7c85e 100644
--- a/drivers/input/serio/libps2.c
+++ b/drivers/input/serio/libps2.c
@@ -29,6 +29,7 @@ MODULE_LICENSE("GPL");
29 29
30EXPORT_SYMBOL(ps2_init); 30EXPORT_SYMBOL(ps2_init);
31EXPORT_SYMBOL(ps2_sendbyte); 31EXPORT_SYMBOL(ps2_sendbyte);
32EXPORT_SYMBOL(ps2_drain);
32EXPORT_SYMBOL(ps2_command); 33EXPORT_SYMBOL(ps2_command);
33EXPORT_SYMBOL(ps2_schedule_command); 34EXPORT_SYMBOL(ps2_schedule_command);
34EXPORT_SYMBOL(ps2_handle_ack); 35EXPORT_SYMBOL(ps2_handle_ack);
@@ -45,11 +46,11 @@ struct ps2work {
45 46
46 47
47/* 48/*
48 * ps2_sendbyte() sends a byte to the mouse, and waits for acknowledge. 49 * ps2_sendbyte() sends a byte to the device and waits for acknowledge.
49 * It doesn't handle retransmission, though it could - because when there would 50 * It doesn't handle retransmission, though it could - because if there
50 * be need for retransmissions, the mouse has to be replaced anyway. 51 * is a need for retransmissions device has to be replaced anyway.
51 * 52 *
52 * ps2_sendbyte() can only be called from a process context 53 * ps2_sendbyte() can only be called from a process context.
53 */ 54 */
54 55
55int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout) 56int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout)
@@ -72,6 +73,91 @@ int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout)
72} 73}
73 74
74/* 75/*
76 * ps2_drain() waits for device to transmit requested number of bytes
77 * and discards them.
78 */
79
80void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout)
81{
82 if (maxbytes > sizeof(ps2dev->cmdbuf)) {
83 WARN_ON(1);
84 maxbytes = sizeof(ps2dev->cmdbuf);
85 }
86
87 down(&ps2dev->cmd_sem);
88
89 serio_pause_rx(ps2dev->serio);
90 ps2dev->flags = PS2_FLAG_CMD;
91 ps2dev->cmdcnt = maxbytes;
92 serio_continue_rx(ps2dev->serio);
93
94 wait_event_timeout(ps2dev->wait,
95 !(ps2dev->flags & PS2_FLAG_CMD),
96 msecs_to_jiffies(timeout));
97 up(&ps2dev->cmd_sem);
98}
99
100/*
101 * ps2_is_keyboard_id() checks received ID byte against the list of
102 * known keyboard IDs.
103 */
104
105static inline int ps2_is_keyboard_id(char id_byte)
106{
107 static char keyboard_ids[] = {
108 0xab, /* Regular keyboards */
109 0xac, /* NCD Sun keyboard */
110 0x2b, /* Trust keyboard, translated */
111 0x5d, /* Trust keyboard */
112 0x60, /* NMB SGI keyboard, translated */
113 0x47, /* NMB SGI keyboard */
114 };
115
116 return memchr(keyboard_ids, id_byte, sizeof(keyboard_ids)) != NULL;
117}
118
119/*
120 * ps2_adjust_timeout() is called after receiving 1st byte of command
121 * response and tries to reduce remaining timeout to speed up command
122 * completion.
123 */
124
125static int ps2_adjust_timeout(struct ps2dev *ps2dev, int command, int timeout)
126{
127 switch (command) {
128 case PS2_CMD_RESET_BAT:
129 /*
130 * Device has sent the first response byte after
131 * reset command, reset is thus done, so we can
132 * shorten the timeout.
133 * The next byte will come soon (keyboard) or not
134 * at all (mouse).
135 */
136 if (timeout > msecs_to_jiffies(100))
137 timeout = msecs_to_jiffies(100);
138 break;
139
140 case PS2_CMD_GETID:
141 /*
142 * If device behind the port is not a keyboard there
143 * won't be 2nd byte of ID response.
144 */
145 if (!ps2_is_keyboard_id(ps2dev->cmdbuf[1])) {
146 serio_pause_rx(ps2dev->serio);
147 ps2dev->flags = ps2dev->cmdcnt = 0;
148 serio_continue_rx(ps2dev->serio);
149 timeout = 0;
150 }
151 break;
152
153 default:
154 break;
155 }
156
157 return timeout;
158}
159
160/*
75 * ps2_command() sends a command and its parameters to the mouse, 161 * ps2_command() sends a command and its parameters to the mouse,
76 * then waits for the response and puts it in the param array. 162 * then waits for the response and puts it in the param array.
77 * 163 *
@@ -86,6 +172,11 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
86 int rc = -1; 172 int rc = -1;
87 int i; 173 int i;
88 174
175 if (receive > sizeof(ps2dev->cmdbuf)) {
176 WARN_ON(1);
177 return -1;
178 }
179
89 down(&ps2dev->cmd_sem); 180 down(&ps2dev->cmd_sem);
90 181
91 serio_pause_rx(ps2dev->serio); 182 serio_pause_rx(ps2dev->serio);
@@ -101,10 +192,9 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
101 * ACKing the reset command, and so it can take a long 192 * ACKing the reset command, and so it can take a long
102 * time before the ACK arrrives. 193 * time before the ACK arrrives.
103 */ 194 */
104 if (command & 0xff) 195 if (ps2_sendbyte(ps2dev, command & 0xff,
105 if (ps2_sendbyte(ps2dev, command & 0xff, 196 command == PS2_CMD_RESET_BAT ? 1000 : 200))
106 command == PS2_CMD_RESET_BAT ? 1000 : 200)) 197 goto out;
107 goto out;
108 198
109 for (i = 0; i < send; i++) 199 for (i = 0; i < send; i++)
110 if (ps2_sendbyte(ps2dev, param[i], 200)) 200 if (ps2_sendbyte(ps2dev, param[i], 200))
@@ -120,33 +210,7 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
120 210
121 if (ps2dev->cmdcnt && timeout > 0) { 211 if (ps2dev->cmdcnt && timeout > 0) {
122 212
123 if (command == PS2_CMD_RESET_BAT && timeout > msecs_to_jiffies(100)) { 213 timeout = ps2_adjust_timeout(ps2dev, command, timeout);
124 /*
125 * Device has sent the first response byte
126 * after a reset command, reset is thus done,
127 * shorten the timeout. The next byte will come
128 * soon (keyboard) or not at all (mouse).
129 */
130 timeout = msecs_to_jiffies(100);
131 }
132
133 if (command == PS2_CMD_GETID &&
134 ps2dev->cmdbuf[receive - 1] != 0xab && /* Regular keyboards */
135 ps2dev->cmdbuf[receive - 1] != 0xac && /* NCD Sun keyboard */
136 ps2dev->cmdbuf[receive - 1] != 0x2b && /* Trust keyboard, translated */
137 ps2dev->cmdbuf[receive - 1] != 0x5d && /* Trust keyboard */
138 ps2dev->cmdbuf[receive - 1] != 0x60 && /* NMB SGI keyboard, translated */
139 ps2dev->cmdbuf[receive - 1] != 0x47) { /* NMB SGI keyboard */
140 /*
141 * Device behind the port is not a keyboard
142 * so we don't need to wait for the 2nd byte
143 * of ID response.
144 */
145 serio_pause_rx(ps2dev->serio);
146 ps2dev->flags = ps2dev->cmdcnt = 0;
147 serio_continue_rx(ps2dev->serio);
148 }
149
150 wait_event_timeout(ps2dev->wait, 214 wait_event_timeout(ps2dev->wait,
151 !(ps2dev->flags & PS2_FLAG_CMD), timeout); 215 !(ps2dev->flags & PS2_FLAG_CMD), timeout);
152 } 216 }
@@ -160,7 +224,7 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
160 224
161 rc = 0; 225 rc = 0;
162 226
163out: 227 out:
164 serio_pause_rx(ps2dev->serio); 228 serio_pause_rx(ps2dev->serio);
165 ps2dev->flags = 0; 229 ps2dev->flags = 0;
166 serio_continue_rx(ps2dev->serio); 230 serio_continue_rx(ps2dev->serio);
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index 341824c48529..f367695e69b5 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -31,10 +31,9 @@
31#include <linux/serio.h> 31#include <linux/serio.h>
32#include <linux/errno.h> 32#include <linux/errno.h>
33#include <linux/wait.h> 33#include <linux/wait.h>
34#include <linux/completion.h>
35#include <linux/sched.h> 34#include <linux/sched.h>
36#include <linux/smp_lock.h>
37#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/kthread.h>
38 37
39MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 38MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
40MODULE_DESCRIPTION("Serio abstraction core"); 39MODULE_DESCRIPTION("Serio abstraction core");
@@ -43,6 +42,7 @@ MODULE_LICENSE("GPL");
43EXPORT_SYMBOL(serio_interrupt); 42EXPORT_SYMBOL(serio_interrupt);
44EXPORT_SYMBOL(__serio_register_port); 43EXPORT_SYMBOL(__serio_register_port);
45EXPORT_SYMBOL(serio_unregister_port); 44EXPORT_SYMBOL(serio_unregister_port);
45EXPORT_SYMBOL(serio_unregister_child_port);
46EXPORT_SYMBOL(__serio_unregister_port_delayed); 46EXPORT_SYMBOL(__serio_unregister_port_delayed);
47EXPORT_SYMBOL(__serio_register_driver); 47EXPORT_SYMBOL(__serio_register_driver);
48EXPORT_SYMBOL(serio_unregister_driver); 48EXPORT_SYMBOL(serio_unregister_driver);
@@ -68,6 +68,37 @@ static void serio_destroy_port(struct serio *serio);
68static void serio_reconnect_port(struct serio *serio); 68static void serio_reconnect_port(struct serio *serio);
69static void serio_disconnect_port(struct serio *serio); 69static void serio_disconnect_port(struct serio *serio);
70 70
71static int serio_connect_driver(struct serio *serio, struct serio_driver *drv)
72{
73 int retval;
74
75 down(&serio->drv_sem);
76 retval = drv->connect(serio, drv);
77 up(&serio->drv_sem);
78
79 return retval;
80}
81
82static int serio_reconnect_driver(struct serio *serio)
83{
84 int retval = -1;
85
86 down(&serio->drv_sem);
87 if (serio->drv && serio->drv->reconnect)
88 retval = serio->drv->reconnect(serio);
89 up(&serio->drv_sem);
90
91 return retval;
92}
93
94static void serio_disconnect_driver(struct serio *serio)
95{
96 down(&serio->drv_sem);
97 if (serio->drv)
98 serio->drv->disconnect(serio);
99 up(&serio->drv_sem);
100}
101
71static int serio_match_port(const struct serio_device_id *ids, struct serio *serio) 102static int serio_match_port(const struct serio_device_id *ids, struct serio *serio)
72{ 103{
73 while (ids->type || ids->proto) { 104 while (ids->type || ids->proto) {
@@ -91,7 +122,7 @@ static void serio_bind_driver(struct serio *serio, struct serio_driver *drv)
91 122
92 if (serio_match_port(drv->id_table, serio)) { 123 if (serio_match_port(drv->id_table, serio)) {
93 serio->dev.driver = &drv->driver; 124 serio->dev.driver = &drv->driver;
94 if (drv->connect(serio, drv)) { 125 if (serio_connect_driver(serio, drv)) {
95 serio->dev.driver = NULL; 126 serio->dev.driver = NULL;
96 goto out; 127 goto out;
97 } 128 }
@@ -138,8 +169,7 @@ struct serio_event {
138static DEFINE_SPINLOCK(serio_event_lock); /* protects serio_event_list */ 169static DEFINE_SPINLOCK(serio_event_lock); /* protects serio_event_list */
139static LIST_HEAD(serio_event_list); 170static LIST_HEAD(serio_event_list);
140static DECLARE_WAIT_QUEUE_HEAD(serio_wait); 171static DECLARE_WAIT_QUEUE_HEAD(serio_wait);
141static DECLARE_COMPLETION(serio_exited); 172static struct task_struct *serio_task;
142static int serio_pid;
143 173
144static void serio_queue_event(void *object, struct module *owner, 174static void serio_queue_event(void *object, struct module *owner,
145 enum serio_event_type event_type) 175 enum serio_event_type event_type)
@@ -150,12 +180,12 @@ static void serio_queue_event(void *object, struct module *owner,
150 spin_lock_irqsave(&serio_event_lock, flags); 180 spin_lock_irqsave(&serio_event_lock, flags);
151 181
152 /* 182 /*
153 * Scan event list for the other events for the same serio port, 183 * Scan event list for the other events for the same serio port,
154 * starting with the most recent one. If event is the same we 184 * starting with the most recent one. If event is the same we
155 * do not need add new one. If event is of different type we 185 * do not need add new one. If event is of different type we
156 * need to add this event and should not look further because 186 * need to add this event and should not look further because
157 * we need to preseve sequence of distinct events. 187 * we need to preseve sequence of distinct events.
158 */ 188 */
159 list_for_each_entry_reverse(event, &serio_event_list, node) { 189 list_for_each_entry_reverse(event, &serio_event_list, node) {
160 if (event->object == object) { 190 if (event->object == object) {
161 if (event->type == event_type) 191 if (event->type == event_type)
@@ -337,20 +367,15 @@ static struct serio *serio_get_pending_child(struct serio *parent)
337 367
338static int serio_thread(void *nothing) 368static int serio_thread(void *nothing)
339{ 369{
340 lock_kernel();
341 daemonize("kseriod");
342 allow_signal(SIGTERM);
343
344 do { 370 do {
345 serio_handle_events(); 371 serio_handle_events();
346 wait_event_interruptible(serio_wait, !list_empty(&serio_event_list)); 372 wait_event_interruptible(serio_wait,
373 kthread_should_stop() || !list_empty(&serio_event_list));
347 try_to_freeze(); 374 try_to_freeze();
348 } while (!signal_pending(current)); 375 } while (!kthread_should_stop());
349 376
350 printk(KERN_DEBUG "serio: kseriod exiting\n"); 377 printk(KERN_DEBUG "serio: kseriod exiting\n");
351 378 return 0;
352 unlock_kernel();
353 complete_and_exit(&serio_exited, 0);
354} 379}
355 380
356 381
@@ -557,7 +582,7 @@ static void serio_destroy_port(struct serio *serio)
557static void serio_reconnect_port(struct serio *serio) 582static void serio_reconnect_port(struct serio *serio)
558{ 583{
559 do { 584 do {
560 if (!serio->drv || !serio->drv->reconnect || serio->drv->reconnect(serio)) { 585 if (serio_reconnect_driver(serio)) {
561 serio_disconnect_port(serio); 586 serio_disconnect_port(serio);
562 serio_find_driver(serio); 587 serio_find_driver(serio);
563 /* Ok, old children are now gone, we are done */ 588 /* Ok, old children are now gone, we are done */
@@ -630,6 +655,19 @@ void serio_unregister_port(struct serio *serio)
630} 655}
631 656
632/* 657/*
658 * Safely unregisters child port if one is present.
659 */
660void serio_unregister_child_port(struct serio *serio)
661{
662 down(&serio_sem);
663 if (serio->child) {
664 serio_disconnect_port(serio->child);
665 serio_destroy_port(serio->child);
666 }
667 up(&serio_sem);
668}
669
670/*
633 * Submits register request to kseriod for subsequent execution. 671 * Submits register request to kseriod for subsequent execution.
634 * Can be used when it is not obvious whether the serio_sem is 672 * Can be used when it is not obvious whether the serio_sem is
635 * taken or not and when delayed execution is feasible. 673 * taken or not and when delayed execution is feasible.
@@ -686,15 +724,14 @@ static int serio_driver_probe(struct device *dev)
686 struct serio *serio = to_serio_port(dev); 724 struct serio *serio = to_serio_port(dev);
687 struct serio_driver *drv = to_serio_driver(dev->driver); 725 struct serio_driver *drv = to_serio_driver(dev->driver);
688 726
689 return drv->connect(serio, drv); 727 return serio_connect_driver(serio, drv);
690} 728}
691 729
692static int serio_driver_remove(struct device *dev) 730static int serio_driver_remove(struct device *dev)
693{ 731{
694 struct serio *serio = to_serio_port(dev); 732 struct serio *serio = to_serio_port(dev);
695 struct serio_driver *drv = to_serio_driver(dev->driver);
696 733
697 drv->disconnect(serio); 734 serio_disconnect_driver(serio);
698 return 0; 735 return 0;
699} 736}
700 737
@@ -730,11 +767,9 @@ start_over:
730 767
731static void serio_set_drv(struct serio *serio, struct serio_driver *drv) 768static void serio_set_drv(struct serio *serio, struct serio_driver *drv)
732{ 769{
733 down(&serio->drv_sem);
734 serio_pause_rx(serio); 770 serio_pause_rx(serio);
735 serio->drv = drv; 771 serio->drv = drv;
736 serio_continue_rx(serio); 772 serio_continue_rx(serio);
737 up(&serio->drv_sem);
738} 773}
739 774
740static int serio_bus_match(struct device *dev, struct device_driver *drv) 775static int serio_bus_match(struct device *dev, struct device_driver *drv)
@@ -794,7 +829,7 @@ static int serio_resume(struct device *dev)
794{ 829{
795 struct serio *serio = to_serio_port(dev); 830 struct serio *serio = to_serio_port(dev);
796 831
797 if (!serio->drv || !serio->drv->reconnect || serio->drv->reconnect(serio)) { 832 if (serio_reconnect_driver(serio)) {
798 /* 833 /*
799 * Driver re-probing can take a while, so better let kseriod 834 * Driver re-probing can take a while, so better let kseriod
800 * deal with it. 835 * deal with it.
@@ -848,9 +883,10 @@ irqreturn_t serio_interrupt(struct serio *serio,
848 883
849static int __init serio_init(void) 884static int __init serio_init(void)
850{ 885{
851 if (!(serio_pid = kernel_thread(serio_thread, NULL, CLONE_KERNEL))) { 886 serio_task = kthread_run(serio_thread, NULL, "kseriod");
887 if (IS_ERR(serio_task)) {
852 printk(KERN_ERR "serio: Failed to start kseriod\n"); 888 printk(KERN_ERR "serio: Failed to start kseriod\n");
853 return -1; 889 return PTR_ERR(serio_task);
854 } 890 }
855 891
856 serio_bus.dev_attrs = serio_device_attrs; 892 serio_bus.dev_attrs = serio_device_attrs;
@@ -866,8 +902,7 @@ static int __init serio_init(void)
866static void __exit serio_exit(void) 902static void __exit serio_exit(void)
867{ 903{
868 bus_unregister(&serio_bus); 904 bus_unregister(&serio_bus);
869 kill_proc(serio_pid, SIGTERM, 1); 905 kthread_stop(serio_task);
870 wait_for_completion(&serio_exited);
871} 906}
872 907
873module_init(serio_init); 908module_init(serio_init);
diff --git a/drivers/input/touchscreen/elo.c b/drivers/input/touchscreen/elo.c
index 546ce599334e..3cdc9cab688d 100644
--- a/drivers/input/touchscreen/elo.c
+++ b/drivers/input/touchscreen/elo.c
@@ -226,7 +226,7 @@ static int elo_connect(struct serio *serio, struct serio_driver *drv)
226 input_set_abs_params(&elo->dev, ABS_Y, 96, 4000, 0, 0); 226 input_set_abs_params(&elo->dev, ABS_Y, 96, 4000, 0, 0);
227 input_set_abs_params(&elo->dev, ABS_PRESSURE, 0, 255, 0, 0); 227 input_set_abs_params(&elo->dev, ABS_PRESSURE, 0, 255, 0, 0);
228 break; 228 break;
229 229
230 case 1: /* 6-byte protocol */ 230 case 1: /* 6-byte protocol */
231 input_set_abs_params(&elo->dev, ABS_PRESSURE, 0, 15, 0, 0); 231 input_set_abs_params(&elo->dev, ABS_PRESSURE, 0, 15, 0, 0);
232 232
diff --git a/drivers/input/touchscreen/h3600_ts_input.c b/drivers/input/touchscreen/h3600_ts_input.c
index acb9137a0226..bcfa1e36f957 100644
--- a/drivers/input/touchscreen/h3600_ts_input.c
+++ b/drivers/input/touchscreen/h3600_ts_input.c
@@ -89,9 +89,9 @@ MODULE_LICENSE("GPL");
89#define H3600_SCANCODE_Q 4 /* 4 -> Q button */ 89#define H3600_SCANCODE_Q 4 /* 4 -> Q button */
90#define H3600_SCANCODE_START 5 /* 5 -> start menu */ 90#define H3600_SCANCODE_START 5 /* 5 -> start menu */
91#define H3600_SCANCODE_UP 6 /* 6 -> up */ 91#define H3600_SCANCODE_UP 6 /* 6 -> up */
92#define H3600_SCANCODE_RIGHT 7 /* 7 -> right */ 92#define H3600_SCANCODE_RIGHT 7 /* 7 -> right */
93#define H3600_SCANCODE_LEFT 8 /* 8 -> left */ 93#define H3600_SCANCODE_LEFT 8 /* 8 -> left */
94#define H3600_SCANCODE_DOWN 9 /* 9 -> down */ 94#define H3600_SCANCODE_DOWN 9 /* 9 -> down */
95 95
96static char *h3600_name = "H3600 TouchScreen"; 96static char *h3600_name = "H3600 TouchScreen";
97 97
@@ -113,7 +113,7 @@ struct h3600_dev {
113 113
114static irqreturn_t action_button_handler(int irq, void *dev_id, struct pt_regs *regs) 114static irqreturn_t action_button_handler(int irq, void *dev_id, struct pt_regs *regs)
115{ 115{
116 int down = (GPLR & GPIO_BITSY_ACTION_BUTTON) ? 0 : 1; 116 int down = (GPLR & GPIO_BITSY_ACTION_BUTTON) ? 0 : 1;
117 struct input_dev *dev = (struct input_dev *) dev_id; 117 struct input_dev *dev = (struct input_dev *) dev_id;
118 118
119 input_regs(dev, regs); 119 input_regs(dev, regs);
@@ -125,7 +125,7 @@ static irqreturn_t action_button_handler(int irq, void *dev_id, struct pt_regs *
125 125
126static irqreturn_t npower_button_handler(int irq, void *dev_id, struct pt_regs *regs) 126static irqreturn_t npower_button_handler(int irq, void *dev_id, struct pt_regs *regs)
127{ 127{
128 int down = (GPLR & GPIO_BITSY_NPOWER_BUTTON) ? 0 : 1; 128 int down = (GPLR & GPIO_BITSY_NPOWER_BUTTON) ? 0 : 1;
129 struct input_dev *dev = (struct input_dev *) dev_id; 129 struct input_dev *dev = (struct input_dev *) dev_id;
130 130
131 /* 131 /*
@@ -145,8 +145,8 @@ static irqreturn_t npower_button_handler(int irq, void *dev_id, struct pt_regs *
145static int flite_brightness = 25; 145static int flite_brightness = 25;
146 146
147enum flite_pwr { 147enum flite_pwr {
148 FLITE_PWR_OFF = 0, 148 FLITE_PWR_OFF = 0,
149 FLITE_PWR_ON = 1 149 FLITE_PWR_ON = 1
150}; 150};
151 151
152/* 152/*
@@ -157,9 +157,9 @@ unsigned int h3600_flite_power(struct input_dev *dev, enum flite_pwr pwr)
157 struct h3600_dev *ts = dev->private; 157 struct h3600_dev *ts = dev->private;
158 158
159 /* Must be in this order */ 159 /* Must be in this order */
160 ts->serio->write(ts->serio, 1); 160 ts->serio->write(ts->serio, 1);
161 ts->serio->write(ts->serio, pwr); 161 ts->serio->write(ts->serio, pwr);
162 ts->serio->write(ts->serio, brightness); 162 ts->serio->write(ts->serio, brightness);
163 return 0; 163 return 0;
164} 164}
165 165
@@ -169,26 +169,26 @@ static int h3600ts_pm_callback(struct pm_dev *pm_dev, pm_request_t req,
169{ 169{
170 struct input_dev *dev = (struct input_dev *) data; 170 struct input_dev *dev = (struct input_dev *) data;
171 171
172 switch (req) { 172 switch (req) {
173 case PM_SUSPEND: /* enter D1-D3 */ 173 case PM_SUSPEND: /* enter D1-D3 */
174 suspended = 1; 174 suspended = 1;
175 h3600_flite_power(dev, FLITE_PWR_OFF); 175 h3600_flite_power(dev, FLITE_PWR_OFF);
176 break; 176 break;
177 case PM_BLANK: 177 case PM_BLANK:
178 if (!suspended) 178 if (!suspended)
179 h3600_flite_power(dev, FLITE_PWR_OFF); 179 h3600_flite_power(dev, FLITE_PWR_OFF);
180 break; 180 break;
181 case PM_RESUME: /* enter D0 */ 181 case PM_RESUME: /* enter D0 */
182 /* same as unblank */ 182 /* same as unblank */
183 case PM_UNBLANK: 183 case PM_UNBLANK:
184 if (suspended) { 184 if (suspended) {
185 //initSerial(); 185 //initSerial();
186 suspended = 0; 186 suspended = 0;
187 } 187 }
188 h3600_flite_power(dev, FLITE_PWR_ON); 188 h3600_flite_power(dev, FLITE_PWR_ON);
189 break; 189 break;
190 } 190 }
191 return 0; 191 return 0;
192} 192}
193#endif 193#endif
194 194
@@ -199,25 +199,25 @@ static int h3600ts_pm_callback(struct pm_dev *pm_dev, pm_request_t req,
199 */ 199 */
200static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs) 200static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs)
201{ 201{
202 struct input_dev *dev = &ts->dev; 202 struct input_dev *dev = &ts->dev;
203 static int touched = 0; 203 static int touched = 0;
204 int key, down = 0; 204 int key, down = 0;
205 205
206 input_regs(dev, regs); 206 input_regs(dev, regs);
207 207
208 switch (ts->event) { 208 switch (ts->event) {
209 /* 209 /*
210 Buttons - returned as a single byte 210 Buttons - returned as a single byte
211 7 6 5 4 3 2 1 0 211 7 6 5 4 3 2 1 0
212 S x x x N N N N 212 S x x x N N N N
213 213
214 S switch state ( 0=pressed 1=released) 214 S switch state ( 0=pressed 1=released)
215 x Unused. 215 x Unused.
216 NNNN switch number 0-15 216 NNNN switch number 0-15
217 217
218 Note: This is true for non interrupt generated key events. 218 Note: This is true for non interrupt generated key events.
219 */ 219 */
220 case KEYBD_ID: 220 case KEYBD_ID:
221 down = (ts->buf[0] & 0x80) ? 0 : 1; 221 down = (ts->buf[0] & 0x80) ? 0 : 1;
222 222
223 switch (ts->buf[0] & 0x7f) { 223 switch (ts->buf[0] & 0x7f) {
@@ -229,40 +229,40 @@ static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs)
229 break; 229 break;
230 case H3600_SCANCODE_CONTACTS: 230 case H3600_SCANCODE_CONTACTS:
231 key = KEY_PROG2; 231 key = KEY_PROG2;
232 break; 232 break;
233 case H3600_SCANCODE_Q: 233 case H3600_SCANCODE_Q:
234 key = KEY_Q; 234 key = KEY_Q;
235 break; 235 break;
236 case H3600_SCANCODE_START: 236 case H3600_SCANCODE_START:
237 key = KEY_PROG3; 237 key = KEY_PROG3;
238 break; 238 break;
239 case H3600_SCANCODE_UP: 239 case H3600_SCANCODE_UP:
240 key = KEY_UP; 240 key = KEY_UP;
241 break; 241 break;
242 case H3600_SCANCODE_RIGHT: 242 case H3600_SCANCODE_RIGHT:
243 key = KEY_RIGHT; 243 key = KEY_RIGHT;
244 break; 244 break;
245 case H3600_SCANCODE_LEFT: 245 case H3600_SCANCODE_LEFT:
246 key = KEY_LEFT; 246 key = KEY_LEFT;
247 break; 247 break;
248 case H3600_SCANCODE_DOWN: 248 case H3600_SCANCODE_DOWN:
249 key = KEY_DOWN; 249 key = KEY_DOWN;
250 break; 250 break;
251 default: 251 default:
252 key = 0; 252 key = 0;
253 } 253 }
254 if (key) 254 if (key)
255 input_report_key(dev, key, down); 255 input_report_key(dev, key, down);
256 break; 256 break;
257 /* 257 /*
258 * Native touchscreen event data is formatted as shown below:- 258 * Native touchscreen event data is formatted as shown below:-
259 * 259 *
260 * +-------+-------+-------+-------+ 260 * +-------+-------+-------+-------+
261 * | Xmsb | Xlsb | Ymsb | Ylsb | 261 * | Xmsb | Xlsb | Ymsb | Ylsb |
262 * +-------+-------+-------+-------+ 262 * +-------+-------+-------+-------+
263 * byte 0 1 2 3 263 * byte 0 1 2 3
264 */ 264 */
265 case TOUCHS_ID: 265 case TOUCHS_ID:
266 if (!touched) { 266 if (!touched) {
267 input_report_key(dev, BTN_TOUCH, 1); 267 input_report_key(dev, BTN_TOUCH, 1);
268 touched = 1; 268 touched = 1;
@@ -272,19 +272,19 @@ static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs)
272 unsigned short x, y; 272 unsigned short x, y;
273 273
274 x = ts->buf[0]; x <<= 8; x += ts->buf[1]; 274 x = ts->buf[0]; x <<= 8; x += ts->buf[1];
275 y = ts->buf[2]; y <<= 8; y += ts->buf[3]; 275 y = ts->buf[2]; y <<= 8; y += ts->buf[3];
276 276
277 input_report_abs(dev, ABS_X, x); 277 input_report_abs(dev, ABS_X, x);
278 input_report_abs(dev, ABS_Y, y); 278 input_report_abs(dev, ABS_Y, y);
279 } else { 279 } else {
280 input_report_key(dev, BTN_TOUCH, 0); 280 input_report_key(dev, BTN_TOUCH, 0);
281 touched = 0; 281 touched = 0;
282 } 282 }
283 break; 283 break;
284 default: 284 default:
285 /* Send a non input event elsewhere */ 285 /* Send a non input event elsewhere */
286 break; 286 break;
287 } 287 }
288 288
289 input_sync(dev); 289 input_sync(dev);
290} 290}
@@ -293,7 +293,7 @@ static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs)
293 * h3600ts_event() handles events from the input module. 293 * h3600ts_event() handles events from the input module.
294 */ 294 */
295static int h3600ts_event(struct input_dev *dev, unsigned int type, 295static int h3600ts_event(struct input_dev *dev, unsigned int type,
296 unsigned int code, int value) 296 unsigned int code, int value)
297{ 297{
298 struct h3600_dev *ts = dev->private; 298 struct h3600_dev *ts = dev->private;
299 299
@@ -332,41 +332,41 @@ static int state;
332static irqreturn_t h3600ts_interrupt(struct serio *serio, unsigned char data, 332static irqreturn_t h3600ts_interrupt(struct serio *serio, unsigned char data,
333 unsigned int flags, struct pt_regs *regs) 333 unsigned int flags, struct pt_regs *regs)
334{ 334{
335 struct h3600_dev *ts = serio_get_drvdata(serio); 335 struct h3600_dev *ts = serio_get_drvdata(serio);
336 336
337 /* 337 /*
338 * We have a new frame coming in. 338 * We have a new frame coming in.
339 */ 339 */
340 switch (state) { 340 switch (state) {
341 case STATE_SOF: 341 case STATE_SOF:
342 if (data == CHAR_SOF) 342 if (data == CHAR_SOF)
343 state = STATE_ID; 343 state = STATE_ID;
344 break; 344 break;
345 case STATE_ID: 345 case STATE_ID:
346 ts->event = (data & 0xf0) >> 4; 346 ts->event = (data & 0xf0) >> 4;
347 ts->len = (data & 0xf); 347 ts->len = (data & 0xf);
348 ts->idx = 0; 348 ts->idx = 0;
349 if (ts->event >= MAX_ID) { 349 if (ts->event >= MAX_ID) {
350 state = STATE_SOF; 350 state = STATE_SOF;
351 break; 351 break;
352 } 352 }
353 ts->chksum = data; 353 ts->chksum = data;
354 state = (ts->len > 0) ? STATE_DATA : STATE_EOF; 354 state = (ts->len > 0) ? STATE_DATA : STATE_EOF;
355 break; 355 break;
356 case STATE_DATA: 356 case STATE_DATA:
357 ts->chksum += data; 357 ts->chksum += data;
358 ts->buf[ts->idx]= data; 358 ts->buf[ts->idx]= data;
359 if(++ts->idx == ts->len) 359 if (++ts->idx == ts->len)
360 state = STATE_EOF; 360 state = STATE_EOF;
361 break; 361 break;
362 case STATE_EOF: 362 case STATE_EOF:
363 state = STATE_SOF; 363 state = STATE_SOF;
364 if (data == CHAR_EOF || data == ts->chksum) 364 if (data == CHAR_EOF || data == ts->chksum)
365 h3600ts_process_packet(ts, regs); 365 h3600ts_process_packet(ts, regs);
366 break; 366 break;
367 default: 367 default:
368 printk("Error3\n"); 368 printk("Error3\n");
369 break; 369 break;
370 } 370 }
371 371
372 return IRQ_HANDLED; 372 return IRQ_HANDLED;
@@ -390,10 +390,10 @@ static int h3600ts_connect(struct serio *serio, struct serio_driver *drv)
390 init_input_dev(&ts->dev); 390 init_input_dev(&ts->dev);
391 391
392 /* Device specific stuff */ 392 /* Device specific stuff */
393 set_GPIO_IRQ_edge(GPIO_BITSY_ACTION_BUTTON, GPIO_BOTH_EDGES); 393 set_GPIO_IRQ_edge(GPIO_BITSY_ACTION_BUTTON, GPIO_BOTH_EDGES);
394 set_GPIO_IRQ_edge(GPIO_BITSY_NPOWER_BUTTON, GPIO_RISING_EDGE); 394 set_GPIO_IRQ_edge(GPIO_BITSY_NPOWER_BUTTON, GPIO_RISING_EDGE);
395 395
396 if (request_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, action_button_handler, 396 if (request_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, action_button_handler,
397 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM, 397 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM,
398 "h3600_action", &ts->dev)) { 398 "h3600_action", &ts->dev)) {
399 printk(KERN_ERR "h3600ts.c: Could not allocate Action Button IRQ!\n"); 399 printk(KERN_ERR "h3600ts.c: Could not allocate Action Button IRQ!\n");
@@ -401,7 +401,7 @@ static int h3600ts_connect(struct serio *serio, struct serio_driver *drv)
401 return -EBUSY; 401 return -EBUSY;
402 } 402 }
403 403
404 if (request_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, npower_button_handler, 404 if (request_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, npower_button_handler,
405 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM, 405 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM,
406 "h3600_suspend", &ts->dev)) { 406 "h3600_suspend", &ts->dev)) {
407 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, &ts->dev); 407 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, &ts->dev);
@@ -433,7 +433,7 @@ static int h3600ts_connect(struct serio *serio, struct serio_driver *drv)
433 433
434 sprintf(ts->phys, "%s/input0", serio->phys); 434 sprintf(ts->phys, "%s/input0", serio->phys);
435 435
436 ts->dev.event = h3600ts_event; 436 ts->dev.event = h3600ts_event;
437 ts->dev.private = ts; 437 ts->dev.private = ts;
438 ts->dev.name = h3600_name; 438 ts->dev.name = h3600_name;
439 ts->dev.phys = ts->phys; 439 ts->dev.phys = ts->phys;
@@ -446,8 +446,8 @@ static int h3600ts_connect(struct serio *serio, struct serio_driver *drv)
446 446
447 err = serio_open(serio, drv); 447 err = serio_open(serio, drv);
448 if (err) { 448 if (err) {
449 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, ts); 449 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, ts);
450 free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, ts); 450 free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, ts);
451 serio_set_drvdata(serio, NULL); 451 serio_set_drvdata(serio, NULL);
452 kfree(ts); 452 kfree(ts);
453 return err; 453 return err;
diff --git a/drivers/input/touchscreen/mk712.c b/drivers/input/touchscreen/mk712.c
index 2d14a57a05e5..afaaebe5225b 100644
--- a/drivers/input/touchscreen/mk712.c
+++ b/drivers/input/touchscreen/mk712.c
@@ -17,7 +17,7 @@
17 * found in Gateway AOL Connected Touchpad computers. 17 * found in Gateway AOL Connected Touchpad computers.
18 * 18 *
19 * Documentation for ICS MK712 can be found at: 19 * Documentation for ICS MK712 can be found at:
20 * http://www.icst.com/pdf/mk712.pdf 20 * http://www.icst.com/pdf/mk712.pdf
21 */ 21 */
22 22
23/* 23/*
@@ -77,7 +77,6 @@ MODULE_PARM_DESC(irq, "IRQ of MK712 touchscreen controller");
77#define MK712_READ_ONE_POINT 0x20 77#define MK712_READ_ONE_POINT 0x20
78#define MK712_POWERUP 0x40 78#define MK712_POWERUP 0x40
79 79
80static int mk712_used = 0;
81static struct input_dev mk712_dev; 80static struct input_dev mk712_dev;
82static DEFINE_SPINLOCK(mk712_lock); 81static DEFINE_SPINLOCK(mk712_lock);
83 82
@@ -130,17 +129,14 @@ static int mk712_open(struct input_dev *dev)
130 129
131 spin_lock_irqsave(&mk712_lock, flags); 130 spin_lock_irqsave(&mk712_lock, flags);
132 131
133 if (!mk712_used++) { 132 outb(0, mk712_io + MK712_CONTROL); /* Reset */
134 133
135 outb(0, mk712_io + MK712_CONTROL); /* Reset */ 134 outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE |
135 MK712_INT_ON_CHANGE_IN_TOUCH_STATUS |
136 MK712_ENABLE_PERIODIC_CONVERSIONS |
137 MK712_POWERUP, mk712_io + MK712_CONTROL);
136 138
137 outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE | 139 outb(10, mk712_io + MK712_RATE); /* 187 points per second */
138 MK712_INT_ON_CHANGE_IN_TOUCH_STATUS |
139 MK712_ENABLE_PERIODIC_CONVERSIONS |
140 MK712_POWERUP, mk712_io + MK712_CONTROL);
141
142 outb(10, mk712_io + MK712_RATE); /* 187 points per second */
143 }
144 140
145 spin_unlock_irqrestore(&mk712_lock, flags); 141 spin_unlock_irqrestore(&mk712_lock, flags);
146 142
@@ -153,8 +149,7 @@ static void mk712_close(struct input_dev *dev)
153 149
154 spin_lock_irqsave(&mk712_lock, flags); 150 spin_lock_irqsave(&mk712_lock, flags);
155 151
156 if (!--mk712_used) 152 outb(0, mk712_io + MK712_CONTROL);
157 outb(0, mk712_io + MK712_CONTROL);
158 153
159 spin_unlock_irqrestore(&mk712_lock, flags); 154 spin_unlock_irqrestore(&mk712_lock, flags);
160} 155}
diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c
index dc00c85e3e35..ee750e9456dd 100644
--- a/drivers/isdn/hardware/avm/avm_cs.c
+++ b/drivers/isdn/hardware/avm/avm_cs.c
@@ -486,6 +486,14 @@ static int avmcs_event(event_t event, int priority,
486 return 0; 486 return 0;
487} /* avmcs_event */ 487} /* avmcs_event */
488 488
489static struct pcmcia_device_id avmcs_ids[] = {
490 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335),
491 PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M1", 0x95d42008, 0x81e10430),
492 PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M2", 0x95d42008, 0x18e8558a),
493 PCMCIA_DEVICE_NULL
494};
495MODULE_DEVICE_TABLE(pcmcia, avmcs_ids);
496
489static struct pcmcia_driver avmcs_driver = { 497static struct pcmcia_driver avmcs_driver = {
490 .owner = THIS_MODULE, 498 .owner = THIS_MODULE,
491 .drv = { 499 .drv = {
@@ -493,6 +501,7 @@ static struct pcmcia_driver avmcs_driver = {
493 }, 501 },
494 .attach = avmcs_attach, 502 .attach = avmcs_attach,
495 .detach = avmcs_detach, 503 .detach = avmcs_detach,
504 .id_table = avmcs_ids,
496}; 505};
497 506
498static int __init avmcs_init(void) 507static int __init avmcs_init(void)
diff --git a/drivers/isdn/hardware/eicon/dadapter.c b/drivers/isdn/hardware/eicon/dadapter.c
index 6e548a222ef1..89497890158d 100644
--- a/drivers/isdn/hardware/eicon/dadapter.c
+++ b/drivers/isdn/hardware/eicon/dadapter.c
@@ -44,7 +44,7 @@ static didd_adapter_change_notification_t\
44 Array to held adapter information 44 Array to held adapter information
45 -------------------------------------------------------------------------- */ 45 -------------------------------------------------------------------------- */
46static DESCRIPTOR HandleTable[NEW_MAX_DESCRIPTORS]; 46static DESCRIPTOR HandleTable[NEW_MAX_DESCRIPTORS];
47dword Adapters = 0; /* Number of adapters */ 47static dword Adapters = 0; /* Number of adapters */
48/* -------------------------------------------------------------------------- 48/* --------------------------------------------------------------------------
49 Shadow IDI_DIMAINT 49 Shadow IDI_DIMAINT
50 and 'shadow' debug stuff 50 and 'shadow' debug stuff
diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c
index 663a0bf703b7..67c60e04a37b 100644
--- a/drivers/isdn/hisax/avma1_cs.c
+++ b/drivers/isdn/hisax/avma1_cs.c
@@ -501,6 +501,13 @@ static int avma1cs_event(event_t event, int priority,
501 return 0; 501 return 0;
502} /* avma1cs_event */ 502} /* avma1cs_event */
503 503
504static struct pcmcia_device_id avma1cs_ids[] = {
505 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
506 PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b),
507 PCMCIA_DEVICE_NULL
508};
509MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids);
510
504static struct pcmcia_driver avma1cs_driver = { 511static struct pcmcia_driver avma1cs_driver = {
505 .owner = THIS_MODULE, 512 .owner = THIS_MODULE,
506 .drv = { 513 .drv = {
@@ -508,6 +515,7 @@ static struct pcmcia_driver avma1cs_driver = {
508 }, 515 },
509 .attach = avma1cs_attach, 516 .attach = avma1cs_attach,
510 .detach = avma1cs_detach, 517 .detach = avma1cs_detach,
518 .id_table = avma1cs_ids,
511}; 519};
512 520
513/*====================================================================*/ 521/*====================================================================*/
diff --git a/drivers/isdn/hisax/elsa_cs.c b/drivers/isdn/hisax/elsa_cs.c
index bfc013225f46..9146be547044 100644
--- a/drivers/isdn/hisax/elsa_cs.c
+++ b/drivers/isdn/hisax/elsa_cs.c
@@ -508,6 +508,13 @@ static int elsa_cs_event(event_t event, int priority,
508 return 0; 508 return 0;
509} /* elsa_cs_event */ 509} /* elsa_cs_event */
510 510
511static struct pcmcia_device_id elsa_ids[] = {
512 PCMCIA_DEVICE_PROD_ID12("ELSA AG (Aachen, Germany)", "MicroLink ISDN/MC ", 0x983de2c4, 0x333ba257),
513 PCMCIA_DEVICE_PROD_ID12("ELSA GmbH, Aachen", "MicroLink ISDN/MC ", 0x639e5718, 0x333ba257),
514 PCMCIA_DEVICE_NULL
515};
516MODULE_DEVICE_TABLE(pcmcia, elsa_ids);
517
511static struct pcmcia_driver elsa_cs_driver = { 518static struct pcmcia_driver elsa_cs_driver = {
512 .owner = THIS_MODULE, 519 .owner = THIS_MODULE,
513 .drv = { 520 .drv = {
@@ -515,6 +522,7 @@ static struct pcmcia_driver elsa_cs_driver = {
515 }, 522 },
516 .attach = elsa_cs_attach, 523 .attach = elsa_cs_attach,
517 .detach = elsa_cs_detach, 524 .detach = elsa_cs_detach,
525 .id_table = elsa_ids,
518}; 526};
519 527
520static int __init init_elsa_cs(void) 528static int __init init_elsa_cs(void)
diff --git a/drivers/isdn/hisax/hfc4s8s_l1.c b/drivers/isdn/hisax/hfc4s8s_l1.c
index 6e7e060716b7..7333377ab31d 100644
--- a/drivers/isdn/hisax/hfc4s8s_l1.c
+++ b/drivers/isdn/hisax/hfc4s8s_l1.c
@@ -312,7 +312,7 @@ wait_busy(hfc4s8s_hw * a)
312/* function to read critical counter registers that */ 312/* function to read critical counter registers that */
313/* may be udpated by the chip during read */ 313/* may be udpated by the chip during read */
314/******************************************************/ 314/******************************************************/
315static volatile u_char 315static u_char
316Read_hfc8_stable(hfc4s8s_hw * hw, int reg) 316Read_hfc8_stable(hfc4s8s_hw * hw, int reg)
317{ 317{
318 u_char ref8; 318 u_char ref8;
@@ -324,7 +324,7 @@ Read_hfc8_stable(hfc4s8s_hw * hw, int reg)
324 return in8; 324 return in8;
325} 325}
326 326
327static volatile int 327static int
328Read_hfc16_stable(hfc4s8s_hw * hw, int reg) 328Read_hfc16_stable(hfc4s8s_hw * hw, int reg)
329{ 329{
330 int ref16; 330 int ref16;
@@ -1465,7 +1465,7 @@ hfc_hardware_enable(hfc4s8s_hw * hw, int enable, int nt_mode)
1465/******************************************/ 1465/******************************************/
1466/* disable memory mapped ports / io ports */ 1466/* disable memory mapped ports / io ports */
1467/******************************************/ 1467/******************************************/
1468void 1468static void
1469release_pci_ports(hfc4s8s_hw * hw) 1469release_pci_ports(hfc4s8s_hw * hw)
1470{ 1470{
1471 pci_write_config_word(hw->pdev, PCI_COMMAND, 0); 1471 pci_write_config_word(hw->pdev, PCI_COMMAND, 0);
@@ -1481,7 +1481,7 @@ release_pci_ports(hfc4s8s_hw * hw)
1481/*****************************************/ 1481/*****************************************/
1482/* enable memory mapped ports / io ports */ 1482/* enable memory mapped ports / io ports */
1483/*****************************************/ 1483/*****************************************/
1484void 1484static void
1485enable_pci_ports(hfc4s8s_hw * hw) 1485enable_pci_ports(hfc4s8s_hw * hw)
1486{ 1486{
1487#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 1487#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM
diff --git a/drivers/isdn/hisax/sedlbauer_cs.c b/drivers/isdn/hisax/sedlbauer_cs.c
index 449651241477..058147a69576 100644
--- a/drivers/isdn/hisax/sedlbauer_cs.c
+++ b/drivers/isdn/hisax/sedlbauer_cs.c
@@ -616,6 +616,18 @@ static int sedlbauer_event(event_t event, int priority,
616 return 0; 616 return 0;
617} /* sedlbauer_event */ 617} /* sedlbauer_event */
618 618
619static struct pcmcia_device_id sedlbauer_ids[] = {
620 PCMCIA_DEVICE_PROD_ID1234("SEDLBAUER", "speed star II", "V 3.1", "(c) 93 - 98 cb ", 0x81fb79f5, 0xf3612e1d, 0x6b95c78a, 0x50d4149c),
621 PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D67", 0x81fb79f5, 0xe4e9bc12, 0x397b7e90),
622 PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D98", 0x81fb79f5, 0xe4e9bc12, 0x2e5c7fce),
623 PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (C) 93-94 VK", 0x81fb79f5, 0xe4e9bc12, 0x8db143fe),
624 PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (c) 93-95 VK", 0x81fb79f5, 0xe4e9bc12, 0xb391ab4c),
625 PCMCIA_DEVICE_PROD_ID12("HST High Soft Tech GmbH", "Saphir II B", 0xd79e0b84, 0x21d083ae),
626/* PCMCIA_DEVICE_PROD_ID1234("SEDLBAUER", 0x81fb79f5), */ /* too generic*/
627 PCMCIA_DEVICE_NULL
628};
629MODULE_DEVICE_TABLE(pcmcia, sedlbauer_ids);
630
619static struct pcmcia_driver sedlbauer_driver = { 631static struct pcmcia_driver sedlbauer_driver = {
620 .owner = THIS_MODULE, 632 .owner = THIS_MODULE,
621 .drv = { 633 .drv = {
@@ -623,6 +635,7 @@ static struct pcmcia_driver sedlbauer_driver = {
623 }, 635 },
624 .attach = sedlbauer_attach, 636 .attach = sedlbauer_attach,
625 .detach = sedlbauer_detach, 637 .detach = sedlbauer_detach,
638 .id_table = sedlbauer_ids,
626}; 639};
627 640
628static int __init init_sedlbauer_cs(void) 641static int __init init_sedlbauer_cs(void)
diff --git a/drivers/isdn/hisax/teles_cs.c b/drivers/isdn/hisax/teles_cs.c
index 63e8e20c17a8..107376ff5b9b 100644
--- a/drivers/isdn/hisax/teles_cs.c
+++ b/drivers/isdn/hisax/teles_cs.c
@@ -489,6 +489,12 @@ static int teles_cs_event(event_t event, int priority,
489 return 0; 489 return 0;
490} /* teles_cs_event */ 490} /* teles_cs_event */
491 491
492static struct pcmcia_device_id teles_ids[] = {
493 PCMCIA_DEVICE_PROD_ID12("TELES", "S0/PC", 0x67b50eae, 0xe9e70119),
494 PCMCIA_DEVICE_NULL,
495};
496MODULE_DEVICE_TABLE(pcmcia, teles_ids);
497
492static struct pcmcia_driver teles_cs_driver = { 498static struct pcmcia_driver teles_cs_driver = {
493 .owner = THIS_MODULE, 499 .owner = THIS_MODULE,
494 .drv = { 500 .drv = {
@@ -496,6 +502,7 @@ static struct pcmcia_driver teles_cs_driver = {
496 }, 502 },
497 .attach = teles_attach, 503 .attach = teles_attach,
498 .detach = teles_detach, 504 .detach = teles_detach,
505 .id_table = teles_ids,
499}; 506};
500 507
501static int __init init_teles_cs(void) 508static int __init init_teles_cs(void)
diff --git a/drivers/isdn/hysdn/hycapi.c b/drivers/isdn/hysdn/hycapi.c
index 8ee25b2ccce1..1fd3d4e5f284 100644
--- a/drivers/isdn/hysdn/hycapi.c
+++ b/drivers/isdn/hysdn/hycapi.c
@@ -42,6 +42,8 @@ typedef struct _hycapi_appl {
42 42
43static hycapi_appl hycapi_applications[CAPI_MAXAPPL]; 43static hycapi_appl hycapi_applications[CAPI_MAXAPPL];
44 44
45static u16 hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb);
46
45static inline int _hycapi_appCheck(int app_id, int ctrl_no) 47static inline int _hycapi_appCheck(int app_id, int ctrl_no)
46{ 48{
47 if((ctrl_no <= 0) || (ctrl_no > CAPI_MAXCONTR) || (app_id <= 0) || 49 if((ctrl_no <= 0) || (ctrl_no > CAPI_MAXCONTR) || (app_id <= 0) ||
@@ -57,7 +59,7 @@ static inline int _hycapi_appCheck(int app_id, int ctrl_no)
57Kernel-Capi callback reset_ctr 59Kernel-Capi callback reset_ctr
58******************************/ 60******************************/
59 61
60void 62static void
61hycapi_reset_ctr(struct capi_ctr *ctrl) 63hycapi_reset_ctr(struct capi_ctr *ctrl)
62{ 64{
63 hycapictrl_info *cinfo = ctrl->driverdata; 65 hycapictrl_info *cinfo = ctrl->driverdata;
@@ -73,7 +75,7 @@ hycapi_reset_ctr(struct capi_ctr *ctrl)
73Kernel-Capi callback remove_ctr 75Kernel-Capi callback remove_ctr
74******************************/ 76******************************/
75 77
76void 78static void
77hycapi_remove_ctr(struct capi_ctr *ctrl) 79hycapi_remove_ctr(struct capi_ctr *ctrl)
78{ 80{
79 int i; 81 int i;
@@ -215,7 +217,7 @@ Error-checking is done for CAPI-compliance.
215The application is recorded in the internal list. 217The application is recorded in the internal list.
216*************************************************************/ 218*************************************************************/
217 219
218void 220static void
219hycapi_register_appl(struct capi_ctr *ctrl, __u16 appl, 221hycapi_register_appl(struct capi_ctr *ctrl, __u16 appl,
220 capi_register_params *rp) 222 capi_register_params *rp)
221{ 223{
@@ -291,7 +293,7 @@ Release the application from the internal list an remove it's
291registration at controller-level 293registration at controller-level
292******************************************************************/ 294******************************************************************/
293 295
294void 296static void
295hycapi_release_appl(struct capi_ctr *ctrl, __u16 appl) 297hycapi_release_appl(struct capi_ctr *ctrl, __u16 appl)
296{ 298{
297 int chk; 299 int chk;
@@ -364,7 +366,7 @@ firmware-releases that do not check the MsgLen-Indication!
364 366
365***************************************************************/ 367***************************************************************/
366 368
367u16 hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb) 369static u16 hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb)
368{ 370{
369 __u16 appl_id; 371 __u16 appl_id;
370 int _len, _len2; 372 int _len, _len2;
@@ -437,8 +439,8 @@ Informations provided in the /proc/capi-entries.
437 439
438*********************************************************************/ 440*********************************************************************/
439 441
440int hycapi_read_proc(char *page, char **start, off_t off, 442static int hycapi_read_proc(char *page, char **start, off_t off,
441 int count, int *eof, struct capi_ctr *ctrl) 443 int count, int *eof, struct capi_ctr *ctrl)
442{ 444{
443 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata); 445 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
444 hysdn_card *card = cinfo->card; 446 hysdn_card *card = cinfo->card;
@@ -485,7 +487,7 @@ on capi-interface registration.
485 487
486**************************************************************/ 488**************************************************************/
487 489
488int hycapi_load_firmware(struct capi_ctr *ctrl, capiloaddata *data) 490static int hycapi_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
489{ 491{
490#ifdef HYCAPI_PRINTFNAMES 492#ifdef HYCAPI_PRINTFNAMES
491 printk(KERN_NOTICE "hycapi_load_firmware\n"); 493 printk(KERN_NOTICE "hycapi_load_firmware\n");
@@ -494,7 +496,7 @@ int hycapi_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
494} 496}
495 497
496 498
497char *hycapi_procinfo(struct capi_ctr *ctrl) 499static char *hycapi_procinfo(struct capi_ctr *ctrl)
498{ 500{
499 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata); 501 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
500#ifdef HYCAPI_PRINTFNAMES 502#ifdef HYCAPI_PRINTFNAMES
diff --git a/drivers/isdn/hysdn/hysdn_boot.c b/drivers/isdn/hysdn/hysdn_boot.c
index 6c04281e57b8..7bfba196f315 100644
--- a/drivers/isdn/hysdn/hysdn_boot.c
+++ b/drivers/isdn/hysdn/hysdn_boot.c
@@ -53,7 +53,7 @@ struct boot_data {
53/* to be called at start of POF file reading, */ 53/* to be called at start of POF file reading, */
54/* before starting any decryption on any POF record. */ 54/* before starting any decryption on any POF record. */
55/*****************************************************/ 55/*****************************************************/
56void 56static void
57StartDecryption(struct boot_data *boot) 57StartDecryption(struct boot_data *boot)
58{ 58{
59 boot->Cryptor = CRYPT_STARTTERM; 59 boot->Cryptor = CRYPT_STARTTERM;
@@ -66,7 +66,7 @@ StartDecryption(struct boot_data *boot)
66/* to HI and LO boot loader and (all) seq tags, because */ 66/* to HI and LO boot loader and (all) seq tags, because */
67/* global Cryptor is started for whole POF. */ 67/* global Cryptor is started for whole POF. */
68/***************************************************************/ 68/***************************************************************/
69void 69static void
70DecryptBuf(struct boot_data *boot, int cnt) 70DecryptBuf(struct boot_data *boot, int cnt)
71{ 71{
72 uchar *bufp = boot->buf.BootBuf; 72 uchar *bufp = boot->buf.BootBuf;
diff --git a/drivers/isdn/hysdn/hysdn_defs.h b/drivers/isdn/hysdn/hysdn_defs.h
index 4cee26e558ee..432f6f99089e 100644
--- a/drivers/isdn/hysdn/hysdn_defs.h
+++ b/drivers/isdn/hysdn/hysdn_defs.h
@@ -227,7 +227,6 @@ typedef struct hycapictrl_info hycapictrl_info;
227/*****************/ 227/*****************/
228/* exported vars */ 228/* exported vars */
229/*****************/ 229/*****************/
230extern int cardmax; /* number of found cards */
231extern hysdn_card *card_root; /* pointer to first card */ 230extern hysdn_card *card_root; /* pointer to first card */
232 231
233 232
@@ -244,7 +243,6 @@ extern void hysdn_procconf_release(void); /* deinit proc config filesys */
244/* hysdn_proclog.c */ 243/* hysdn_proclog.c */
245extern int hysdn_proclog_init(hysdn_card *); /* init proc log entry */ 244extern int hysdn_proclog_init(hysdn_card *); /* init proc log entry */
246extern void hysdn_proclog_release(hysdn_card *); /* deinit proc log entry */ 245extern void hysdn_proclog_release(hysdn_card *); /* deinit proc log entry */
247extern void put_log_buffer(hysdn_card *, char *); /* output log data */
248extern void hysdn_addlog(hysdn_card *, char *,...); /* output data to log */ 246extern void hysdn_addlog(hysdn_card *, char *,...); /* output data to log */
249extern void hysdn_card_errlog(hysdn_card *, tErrLogEntry *, int); /* output card log */ 247extern void hysdn_card_errlog(hysdn_card *, tErrLogEntry *, int); /* output card log */
250 248
@@ -278,16 +276,6 @@ extern unsigned int hycapi_enable;
278extern int hycapi_capi_create(hysdn_card *); /* create a new capi device */ 276extern int hycapi_capi_create(hysdn_card *); /* create a new capi device */
279extern int hycapi_capi_release(hysdn_card *); /* delete the device */ 277extern int hycapi_capi_release(hysdn_card *); /* delete the device */
280extern int hycapi_capi_stop(hysdn_card *card); /* suspend */ 278extern int hycapi_capi_stop(hysdn_card *card); /* suspend */
281extern int hycapi_load_firmware(struct capi_ctr *, capiloaddata *);
282extern void hycapi_reset_ctr(struct capi_ctr *);
283extern void hycapi_remove_ctr(struct capi_ctr *);
284extern void hycapi_register_appl(struct capi_ctr *, __u16 appl,
285 capi_register_params *);
286extern void hycapi_release_appl(struct capi_ctr *, __u16 appl);
287extern u16 hycapi_send_message(struct capi_ctr *, struct sk_buff *skb);
288extern char *hycapi_procinfo(struct capi_ctr *);
289extern int hycapi_read_proc(char *page, char **start, off_t off,
290 int count, int *eof, struct capi_ctr *card);
291extern void hycapi_rx_capipkt(hysdn_card * card, uchar * buf, word len); 279extern void hycapi_rx_capipkt(hysdn_card * card, uchar * buf, word len);
292extern void hycapi_tx_capiack(hysdn_card * card); 280extern void hycapi_tx_capiack(hysdn_card * card);
293extern struct sk_buff *hycapi_tx_capiget(hysdn_card *card); 281extern struct sk_buff *hycapi_tx_capiget(hysdn_card *card);
diff --git a/drivers/isdn/hysdn/hysdn_init.c b/drivers/isdn/hysdn/hysdn_init.c
index 5cac2bf5f4b0..12c8137b5161 100644
--- a/drivers/isdn/hysdn/hysdn_init.c
+++ b/drivers/isdn/hysdn/hysdn_init.c
@@ -34,7 +34,7 @@ MODULE_AUTHOR("Werner Cornelius");
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
35 35
36static char *hysdn_init_revision = "$Revision: 1.6.6.6 $"; 36static char *hysdn_init_revision = "$Revision: 1.6.6.6 $";
37int cardmax; /* number of found cards */ 37static int cardmax; /* number of found cards */
38hysdn_card *card_root = NULL; /* pointer to first card */ 38hysdn_card *card_root = NULL; /* pointer to first card */
39 39
40/**********************************************/ 40/**********************************************/
diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c
index 8ef2b7c952a6..4d57011c5737 100644
--- a/drivers/isdn/hysdn/hysdn_proclog.c
+++ b/drivers/isdn/hysdn/hysdn_proclog.c
@@ -22,6 +22,8 @@
22/* the proc subdir for the interface is defined in the procconf module */ 22/* the proc subdir for the interface is defined in the procconf module */
23extern struct proc_dir_entry *hysdn_proc_entry; 23extern struct proc_dir_entry *hysdn_proc_entry;
24 24
25static void put_log_buffer(hysdn_card * card, char *cp);
26
25/*************************************************/ 27/*************************************************/
26/* structure keeping ascii log for device output */ 28/* structure keeping ascii log for device output */
27/*************************************************/ 29/*************************************************/
@@ -93,7 +95,7 @@ hysdn_addlog(hysdn_card * card, char *fmt,...)
93/* opened for read got the contents. */ 95/* opened for read got the contents. */
94/* Flushes buffers not longer in use. */ 96/* Flushes buffers not longer in use. */
95/********************************************/ 97/********************************************/
96void 98static void
97put_log_buffer(hysdn_card * card, char *cp) 99put_log_buffer(hysdn_card * card, char *cp)
98{ 100{
99 struct log_data *ib; 101 struct log_data *ib;
diff --git a/drivers/macintosh/Kconfig b/drivers/macintosh/Kconfig
index 8a7117a08cf0..91691a6c004e 100644
--- a/drivers/macintosh/Kconfig
+++ b/drivers/macintosh/Kconfig
@@ -86,33 +86,18 @@ config PMAC_SMU
86 on the "SMU" system control chip which replaces the old PMU. 86 on the "SMU" system control chip which replaces the old PMU.
87 If you don't know, say Y. 87 If you don't know, say Y.
88 88
89config PMAC_PBOOK
90 bool "Power management support for PowerBooks"
91 depends on ADB_PMU
92 ---help---
93 This provides support for putting a PowerBook to sleep; it also
94 enables media bay support. Power management works on the
95 PB2400/3400/3500, Wallstreet, Lombard, and Bronze PowerBook G3 and
96 the Titanium Powerbook G4, as well as the iBooks. You should get
97 the power management daemon, pmud, to make it work and you must have
98 the /dev/pmu device (see the pmud README).
99
100 Get pmud from <ftp://ftp.samba.org/pub/ppclinux/pmud/>.
101
102 If you have a PowerBook, you should say Y here.
103
104 You may also want to compile the dma sound driver as a module and
105 have it autoloaded. The act of removing the module shuts down the
106 sound hardware for more power savings.
107
108config PM
109 bool
110 depends on PPC_PMAC && ADB_PMU && PMAC_PBOOK
111 default y
112
113config PMAC_APM_EMU 89config PMAC_APM_EMU
114 tristate "APM emulation" 90 tristate "APM emulation"
115 depends on PMAC_PBOOK 91 depends on PPC_PMAC && PPC32 && PM
92
93config PMAC_MEDIABAY
94 bool "Support PowerBook hotswap media bay"
95 depends on PPC_PMAC && PPC32
96 help
97 This option adds support for older PowerBook's hotswap media bay
98 that can contains batteries, floppy drives, or IDE devices. PCI
99 devices are not fully supported in the bay as I never had one to
100 try with
116 101
117# made a separate option since backlight may end up beeing used 102# made a separate option since backlight may end up beeing used
118# on non-powerbook machines (but only on PMU based ones AFAIK) 103# on non-powerbook machines (but only on PMU based ones AFAIK)
@@ -126,13 +111,6 @@ config PMAC_BACKLIGHT
126 events; also, the PowerBook button device will be enabled so you can 111 events; also, the PowerBook button device will be enabled so you can
127 change the screen brightness. 112 change the screen brightness.
128 113
129config MAC_SERIAL
130 tristate "Support for PowerMac serial ports (OBSOLETE DRIVER)"
131 depends on PPC_PMAC && BROKEN
132 help
133 This driver is obsolete. Use CONFIG_SERIAL_PMACZILOG in
134 "Character devices --> Serial drivers --> PowerMac z85c30" option.
135
136config ADB_MACIO 114config ADB_MACIO
137 bool "Include MacIO (CHRP) ADB driver" 115 bool "Include MacIO (CHRP) ADB driver"
138 depends on ADB && PPC_CHRP && !PPC_PMAC64 116 depends on ADB && PPC_CHRP && !PPC_PMAC64
diff --git a/drivers/macintosh/Makefile b/drivers/macintosh/Makefile
index c3a4705a8295..f5ae171dbfef 100644
--- a/drivers/macintosh/Makefile
+++ b/drivers/macintosh/Makefile
@@ -6,8 +6,7 @@
6 6
7obj-$(CONFIG_PPC_PMAC) += macio_asic.o 7obj-$(CONFIG_PPC_PMAC) += macio_asic.o
8 8
9obj-$(CONFIG_PMAC_PBOOK) += mediabay.o 9obj-$(CONFIG_PMAC_MEDIABAY) += mediabay.o
10obj-$(CONFIG_MAC_SERIAL) += macserial.o
11obj-$(CONFIG_MAC_EMUMOUSEBTN) += mac_hid.o 10obj-$(CONFIG_MAC_EMUMOUSEBTN) += mac_hid.o
12obj-$(CONFIG_INPUT_ADBHID) += adbhid.o 11obj-$(CONFIG_INPUT_ADBHID) += adbhid.o
13obj-$(CONFIG_ANSLCD) += ans-lcd.o 12obj-$(CONFIG_ANSLCD) += ans-lcd.o
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index 493e2afa191c..c0dc1e3fa58b 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -90,7 +90,7 @@ static int sleepy_trackpad;
90static int autopoll_devs; 90static int autopoll_devs;
91int __adb_probe_sync; 91int __adb_probe_sync;
92 92
93#ifdef CONFIG_PMAC_PBOOK 93#ifdef CONFIG_PM
94static int adb_notify_sleep(struct pmu_sleep_notifier *self, int when); 94static int adb_notify_sleep(struct pmu_sleep_notifier *self, int when);
95static struct pmu_sleep_notifier adb_sleep_notifier = { 95static struct pmu_sleep_notifier adb_sleep_notifier = {
96 adb_notify_sleep, 96 adb_notify_sleep,
@@ -320,9 +320,9 @@ int __init adb_init(void)
320 printk(KERN_WARNING "Warning: no ADB interface detected\n"); 320 printk(KERN_WARNING "Warning: no ADB interface detected\n");
321 adb_controller = NULL; 321 adb_controller = NULL;
322 } else { 322 } else {
323#ifdef CONFIG_PMAC_PBOOK 323#ifdef CONFIG_PM
324 pmu_register_sleep_notifier(&adb_sleep_notifier); 324 pmu_register_sleep_notifier(&adb_sleep_notifier);
325#endif /* CONFIG_PMAC_PBOOK */ 325#endif /* CONFIG_PM */
326#ifdef CONFIG_PPC 326#ifdef CONFIG_PPC
327 if (machine_is_compatible("AAPL,PowerBook1998") || 327 if (machine_is_compatible("AAPL,PowerBook1998") ||
328 machine_is_compatible("PowerBook1,1")) 328 machine_is_compatible("PowerBook1,1"))
@@ -337,7 +337,7 @@ int __init adb_init(void)
337 337
338__initcall(adb_init); 338__initcall(adb_init);
339 339
340#ifdef CONFIG_PMAC_PBOOK 340#ifdef CONFIG_PM
341/* 341/*
342 * notify clients before sleep and reset bus afterwards 342 * notify clients before sleep and reset bus afterwards
343 */ 343 */
@@ -378,7 +378,7 @@ adb_notify_sleep(struct pmu_sleep_notifier *self, int when)
378 } 378 }
379 return PBOOK_SLEEP_OK; 379 return PBOOK_SLEEP_OK;
380} 380}
381#endif /* CONFIG_PMAC_PBOOK */ 381#endif /* CONFIG_PM */
382 382
383static int 383static int
384do_adb_reset_bus(void) 384do_adb_reset_bus(void)
diff --git a/drivers/macintosh/macserial.c b/drivers/macintosh/macserial.c
deleted file mode 100644
index 0be3ac6cc169..000000000000
--- a/drivers/macintosh/macserial.c
+++ /dev/null
@@ -1,3036 +0,0 @@
1/*
2 * macserial.c: Serial port driver for Power Macintoshes.
3 *
4 * Derived from drivers/sbus/char/sunserial.c by Paul Mackerras.
5 *
6 * Copyright (C) 1996 Paul Mackerras (Paul.Mackerras@cs.anu.edu.au)
7 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
8 *
9 * Receive DMA code by Takashi Oe <toe@unlserve.unl.edu>.
10 *
11 * $Id: macserial.c,v 1.24.2.4 1999/10/19 04:36:42 paulus Exp $
12 */
13
14#include <linux/config.h>
15#include <linux/errno.h>
16#include <linux/module.h>
17#include <linux/signal.h>
18#include <linux/sched.h>
19#include <linux/timer.h>
20#include <linux/interrupt.h>
21#include <linux/workqueue.h>
22#include <linux/tty.h>
23#include <linux/tty_flip.h>
24#include <linux/major.h>
25#include <linux/string.h>
26#include <linux/fcntl.h>
27#include <linux/mm.h>
28#include <linux/kernel.h>
29#include <linux/delay.h>
30#include <linux/init.h>
31#ifdef CONFIG_SERIAL_CONSOLE
32#include <linux/console.h>
33#endif
34#include <linux/slab.h>
35#include <linux/bitops.h>
36
37#include <asm/sections.h>
38#include <asm/io.h>
39#include <asm/pgtable.h>
40#include <asm/irq.h>
41#include <asm/prom.h>
42#include <asm/system.h>
43#include <asm/segment.h>
44#include <asm/machdep.h>
45#include <asm/pmac_feature.h>
46#include <linux/adb.h>
47#include <linux/pmu.h>
48#ifdef CONFIG_KGDB
49#include <asm/kgdb.h>
50#endif
51#include <asm/dbdma.h>
52
53#include "macserial.h"
54
55#ifdef CONFIG_PMAC_PBOOK
56static int serial_notify_sleep(struct pmu_sleep_notifier *self, int when);
57static struct pmu_sleep_notifier serial_sleep_notifier = {
58 serial_notify_sleep,
59 SLEEP_LEVEL_MISC,
60};
61#endif
62
63#define SUPPORT_SERIAL_DMA
64#define MACSERIAL_VERSION "2.0"
65
66/*
67 * It would be nice to dynamically allocate everything that
68 * depends on NUM_SERIAL, so we could support any number of
69 * Z8530s, but for now...
70 */
71#define NUM_SERIAL 2 /* Max number of ZS chips supported */
72#define NUM_CHANNELS (NUM_SERIAL * 2) /* 2 channels per chip */
73
74/* On PowerMacs, the hardware takes care of the SCC recovery time,
75 but we need the eieio to make sure that the accesses occur
76 in the order we want. */
77#define RECOVERY_DELAY eieio()
78
79static struct tty_driver *serial_driver;
80
81struct mac_zschannel zs_channels[NUM_CHANNELS];
82
83struct mac_serial zs_soft[NUM_CHANNELS];
84int zs_channels_found;
85struct mac_serial *zs_chain; /* list of all channels */
86
87struct tty_struct zs_ttys[NUM_CHANNELS];
88
89static int is_powerbook;
90
91#ifdef CONFIG_SERIAL_CONSOLE
92static struct console sercons;
93#endif
94
95#ifdef CONFIG_KGDB
96struct mac_zschannel *zs_kgdbchan;
97static unsigned char scc_inittab[] = {
98 9, 0x80, /* reset A side (CHRA) */
99 13, 0, /* set baud rate divisor */
100 12, 1,
101 14, 1, /* baud rate gen enable, src=rtxc (BRENABL) */
102 11, 0x50, /* clocks = br gen (RCBR | TCBR) */
103 5, 0x6a, /* tx 8 bits, assert RTS (Tx8 | TxENAB | RTS) */
104 4, 0x44, /* x16 clock, 1 stop (SB1 | X16CLK)*/
105 3, 0xc1, /* rx enable, 8 bits (RxENABLE | Rx8)*/
106};
107#endif
108#define ZS_CLOCK 3686400 /* Z8530 RTxC input clock rate */
109
110/* serial subtype definitions */
111#define SERIAL_TYPE_NORMAL 1
112
113/* number of characters left in xmit buffer before we ask for more */
114#define WAKEUP_CHARS 256
115
116/*
117 * Debugging.
118 */
119#undef SERIAL_DEBUG_INTR
120#undef SERIAL_DEBUG_OPEN
121#undef SERIAL_DEBUG_FLOW
122#undef SERIAL_DEBUG_POWER
123#undef SERIAL_DEBUG_THROTTLE
124#undef SERIAL_DEBUG_STOP
125#undef SERIAL_DEBUG_BAUDS
126
127#define RS_STROBE_TIME 10
128#define RS_ISR_PASS_LIMIT 256
129
130#define _INLINE_ inline
131
132#ifdef SERIAL_DEBUG_OPEN
133#define OPNDBG(fmt, arg...) printk(KERN_DEBUG fmt , ## arg)
134#else
135#define OPNDBG(fmt, arg...) do { } while (0)
136#endif
137#ifdef SERIAL_DEBUG_POWER
138#define PWRDBG(fmt, arg...) printk(KERN_DEBUG fmt , ## arg)
139#else
140#define PWRDBG(fmt, arg...) do { } while (0)
141#endif
142#ifdef SERIAL_DEBUG_BAUDS
143#define BAUDBG(fmt, arg...) printk(fmt , ## arg)
144#else
145#define BAUDBG(fmt, arg...) do { } while (0)
146#endif
147
148static void probe_sccs(void);
149static void change_speed(struct mac_serial *info, struct termios *old);
150static void rs_wait_until_sent(struct tty_struct *tty, int timeout);
151static int set_scc_power(struct mac_serial * info, int state);
152static int setup_scc(struct mac_serial * info);
153static void dbdma_reset(volatile struct dbdma_regs *dma);
154static void dbdma_flush(volatile struct dbdma_regs *dma);
155static irqreturn_t rs_txdma_irq(int irq, void *dev_id, struct pt_regs *regs);
156static irqreturn_t rs_rxdma_irq(int irq, void *dev_id, struct pt_regs *regs);
157static void dma_init(struct mac_serial * info);
158static void rxdma_start(struct mac_serial * info, int curr);
159static void rxdma_to_tty(struct mac_serial * info);
160
161/*
162 * tmp_buf is used as a temporary buffer by serial_write. We need to
163 * lock it in case the copy_from_user blocks while swapping in a page,
164 * and some other program tries to do a serial write at the same time.
165 * Since the lock will only come under contention when the system is
166 * swapping and available memory is low, it makes sense to share one
167 * buffer across all the serial ports, since it significantly saves
168 * memory if large numbers of serial ports are open.
169 */
170static unsigned char *tmp_buf;
171static DECLARE_MUTEX(tmp_buf_sem);
172
173
174static inline int __pmac
175serial_paranoia_check(struct mac_serial *info,
176 char *name, const char *routine)
177{
178#ifdef SERIAL_PARANOIA_CHECK
179 static const char badmagic[] = KERN_WARNING
180 "Warning: bad magic number for serial struct %s in %s\n";
181 static const char badinfo[] = KERN_WARNING
182 "Warning: null mac_serial for %s in %s\n";
183
184 if (!info) {
185 printk(badinfo, name, routine);
186 return 1;
187 }
188 if (info->magic != SERIAL_MAGIC) {
189 printk(badmagic, name, routine);
190 return 1;
191 }
192#endif
193 return 0;
194}
195
196/*
197 * Reading and writing Z8530 registers.
198 */
199static inline unsigned char __pmac read_zsreg(struct mac_zschannel *channel,
200 unsigned char reg)
201{
202 unsigned char retval;
203 unsigned long flags;
204
205 /*
206 * We have to make this atomic.
207 */
208 spin_lock_irqsave(&channel->lock, flags);
209 if (reg != 0) {
210 *channel->control = reg;
211 RECOVERY_DELAY;
212 }
213 retval = *channel->control;
214 RECOVERY_DELAY;
215 spin_unlock_irqrestore(&channel->lock, flags);
216 return retval;
217}
218
219static inline void __pmac write_zsreg(struct mac_zschannel *channel,
220 unsigned char reg, unsigned char value)
221{
222 unsigned long flags;
223
224 spin_lock_irqsave(&channel->lock, flags);
225 if (reg != 0) {
226 *channel->control = reg;
227 RECOVERY_DELAY;
228 }
229 *channel->control = value;
230 RECOVERY_DELAY;
231 spin_unlock_irqrestore(&channel->lock, flags);
232 return;
233}
234
235static inline unsigned char __pmac read_zsdata(struct mac_zschannel *channel)
236{
237 unsigned char retval;
238
239 retval = *channel->data;
240 RECOVERY_DELAY;
241 return retval;
242}
243
244static inline void write_zsdata(struct mac_zschannel *channel,
245 unsigned char value)
246{
247 *channel->data = value;
248 RECOVERY_DELAY;
249 return;
250}
251
252static inline void load_zsregs(struct mac_zschannel *channel,
253 unsigned char *regs)
254{
255 ZS_CLEARERR(channel);
256 ZS_CLEARFIFO(channel);
257 /* Load 'em up */
258 write_zsreg(channel, R4, regs[R4]);
259 write_zsreg(channel, R10, regs[R10]);
260 write_zsreg(channel, R3, regs[R3] & ~RxENABLE);
261 write_zsreg(channel, R5, regs[R5] & ~TxENAB);
262 write_zsreg(channel, R1, regs[R1]);
263 write_zsreg(channel, R9, regs[R9]);
264 write_zsreg(channel, R11, regs[R11]);
265 write_zsreg(channel, R12, regs[R12]);
266 write_zsreg(channel, R13, regs[R13]);
267 write_zsreg(channel, R14, regs[R14]);
268 write_zsreg(channel, R15, regs[R15]);
269 write_zsreg(channel, R3, regs[R3]);
270 write_zsreg(channel, R5, regs[R5]);
271 return;
272}
273
274/* Sets or clears DTR/RTS on the requested line */
275static inline void zs_rtsdtr(struct mac_serial *ss, int set)
276{
277 if (set)
278 ss->curregs[5] |= (RTS | DTR);
279 else
280 ss->curregs[5] &= ~(RTS | DTR);
281 write_zsreg(ss->zs_channel, 5, ss->curregs[5]);
282 return;
283}
284
285/* Utility routines for the Zilog */
286static inline int get_zsbaud(struct mac_serial *ss)
287{
288 struct mac_zschannel *channel = ss->zs_channel;
289 int brg;
290
291 if ((ss->curregs[R11] & TCBR) == 0) {
292 /* higher rates don't use the baud rate generator */
293 return (ss->curregs[R4] & X32CLK)? ZS_CLOCK/32: ZS_CLOCK/16;
294 }
295 /* The baud rate is split up between two 8-bit registers in
296 * what is termed 'BRG time constant' format in my docs for
297 * the chip, it is a function of the clk rate the chip is
298 * receiving which happens to be constant.
299 */
300 brg = (read_zsreg(channel, 13) << 8);
301 brg |= read_zsreg(channel, 12);
302 return BRG_TO_BPS(brg, (ZS_CLOCK/(ss->clk_divisor)));
303}
304
305/* On receive, this clears errors and the receiver interrupts */
306static inline void rs_recv_clear(struct mac_zschannel *zsc)
307{
308 write_zsreg(zsc, 0, ERR_RES);
309 write_zsreg(zsc, 0, RES_H_IUS); /* XXX this is unnecessary */
310}
311
312/*
313 * Reset a Descriptor-Based DMA channel.
314 */
315static void dbdma_reset(volatile struct dbdma_regs *dma)
316{
317 int i;
318
319 out_le32(&dma->control, (WAKE|FLUSH|PAUSE|RUN) << 16);
320
321 /*
322 * Yes this looks peculiar, but apparently it needs to be this
323 * way on some machines. (We need to make sure the DBDMA
324 * engine has actually got the write above and responded
325 * to it. - paulus)
326 */
327 for (i = 200; i > 0; --i)
328 if (ld_le32(&dma->status) & RUN)
329 udelay(1);
330}
331
332/*
333 * Tells a DBDMA channel to stop and write any buffered data
334 * it might have to memory.
335 */
336static _INLINE_ void dbdma_flush(volatile struct dbdma_regs *dma)
337{
338 int i = 0;
339
340 out_le32(&dma->control, (FLUSH << 16) | FLUSH);
341 while (((in_le32(&dma->status) & FLUSH) != 0) && (i++ < 100))
342 udelay(1);
343}
344
345/*
346 * ----------------------------------------------------------------------
347 *
348 * Here starts the interrupt handling routines. All of the following
349 * subroutines are declared as inline and are folded into
350 * rs_interrupt(). They were separated out for readability's sake.
351 *
352 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
353 * -----------------------------------------------------------------------
354 */
355
356/*
357 * This routine is used by the interrupt handler to schedule
358 * processing in the software interrupt portion of the driver.
359 */
360static _INLINE_ void rs_sched_event(struct mac_serial *info,
361 int event)
362{
363 info->event |= 1 << event;
364 schedule_work(&info->tqueue);
365}
366
367/* Work out the flag value for a z8530 status value. */
368static _INLINE_ int stat_to_flag(int stat)
369{
370 int flag;
371
372 if (stat & Rx_OVR) {
373 flag = TTY_OVERRUN;
374 } else if (stat & FRM_ERR) {
375 flag = TTY_FRAME;
376 } else if (stat & PAR_ERR) {
377 flag = TTY_PARITY;
378 } else
379 flag = 0;
380 return flag;
381}
382
383static _INLINE_ void receive_chars(struct mac_serial *info,
384 struct pt_regs *regs)
385{
386 struct tty_struct *tty = info->tty;
387 unsigned char ch, stat, flag;
388
389 while ((read_zsreg(info->zs_channel, 0) & Rx_CH_AV) != 0) {
390
391 stat = read_zsreg(info->zs_channel, R1);
392 ch = read_zsdata(info->zs_channel);
393
394#ifdef CONFIG_KGDB
395 if (info->kgdb_channel) {
396 if (ch == 0x03 || ch == '$')
397 breakpoint();
398 if (stat & (Rx_OVR|FRM_ERR|PAR_ERR))
399 write_zsreg(info->zs_channel, 0, ERR_RES);
400 return;
401 }
402#endif
403 if (!tty)
404 continue;
405 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
406 tty_flip_buffer_push(tty);
407
408 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
409 static int flip_buf_ovf;
410 if (++flip_buf_ovf <= 1)
411 printk(KERN_WARNING "FB. overflow: %d\n",
412 flip_buf_ovf);
413 break;
414 }
415 tty->flip.count++;
416 {
417 static int flip_max_cnt;
418 if (flip_max_cnt < tty->flip.count)
419 flip_max_cnt = tty->flip.count;
420 }
421 flag = stat_to_flag(stat);
422 if (flag)
423 /* reset the error indication */
424 write_zsreg(info->zs_channel, 0, ERR_RES);
425 *tty->flip.flag_buf_ptr++ = flag;
426 *tty->flip.char_buf_ptr++ = ch;
427 }
428 if (tty)
429 tty_flip_buffer_push(tty);
430}
431
432static void transmit_chars(struct mac_serial *info)
433{
434 if ((read_zsreg(info->zs_channel, 0) & Tx_BUF_EMP) == 0)
435 return;
436 info->tx_active = 0;
437
438 if (info->x_char && !info->power_wait) {
439 /* Send next char */
440 write_zsdata(info->zs_channel, info->x_char);
441 info->x_char = 0;
442 info->tx_active = 1;
443 return;
444 }
445
446 if ((info->xmit_cnt <= 0) || info->tty->stopped || info->tx_stopped
447 || info->power_wait) {
448 write_zsreg(info->zs_channel, 0, RES_Tx_P);
449 return;
450 }
451
452 /* Send char */
453 write_zsdata(info->zs_channel, info->xmit_buf[info->xmit_tail++]);
454 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
455 info->xmit_cnt--;
456 info->tx_active = 1;
457
458 if (info->xmit_cnt < WAKEUP_CHARS)
459 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
460}
461
462static void powerup_done(unsigned long data)
463{
464 struct mac_serial *info = (struct mac_serial *) data;
465 unsigned long flags;
466
467 spin_lock_irqsave(&info->lock, flags);
468 info->power_wait = 0;
469 transmit_chars(info);
470 spin_unlock_irqrestore(&info->lock, flags);
471}
472
473static _INLINE_ void status_handle(struct mac_serial *info)
474{
475 unsigned char status;
476
477 /* Get status from Read Register 0 */
478 status = read_zsreg(info->zs_channel, 0);
479
480 /* Check for DCD transitions */
481 if (((status ^ info->read_reg_zero) & DCD) != 0
482 && info->tty && !C_CLOCAL(info->tty)) {
483 if (status & DCD) {
484 wake_up_interruptible(&info->open_wait);
485 } else {
486 if (info->tty)
487 tty_hangup(info->tty);
488 }
489 }
490
491 /* Check for CTS transitions */
492 if (info->tty && C_CRTSCTS(info->tty)) {
493 /*
494 * For some reason, on the Power Macintosh,
495 * it seems that the CTS bit is 1 when CTS is
496 * *negated* and 0 when it is asserted.
497 * The DCD bit doesn't seem to be inverted
498 * like this.
499 */
500 if ((status & CTS) == 0) {
501 if (info->tx_stopped) {
502#ifdef SERIAL_DEBUG_FLOW
503 printk(KERN_DEBUG "CTS up\n");
504#endif
505 info->tx_stopped = 0;
506 if (!info->tx_active)
507 transmit_chars(info);
508 }
509 } else {
510#ifdef SERIAL_DEBUG_FLOW
511 printk(KERN_DEBUG "CTS down\n");
512#endif
513 info->tx_stopped = 1;
514 }
515 }
516
517 /* Clear status condition... */
518 write_zsreg(info->zs_channel, 0, RES_EXT_INT);
519 info->read_reg_zero = status;
520}
521
522static _INLINE_ void receive_special_dma(struct mac_serial *info)
523{
524 unsigned char stat, flag;
525 volatile struct dbdma_regs *rd = &info->rx->dma;
526 int where = RX_BUF_SIZE;
527
528 spin_lock(&info->rx_dma_lock);
529 if ((ld_le32(&rd->status) & ACTIVE) != 0)
530 dbdma_flush(rd);
531 if (in_le32(&rd->cmdptr)
532 == virt_to_bus(info->rx_cmds[info->rx_cbuf] + 1))
533 where -= in_le16(&info->rx->res_count);
534 where--;
535
536 stat = read_zsreg(info->zs_channel, R1);
537
538 flag = stat_to_flag(stat);
539 if (flag) {
540 info->rx_flag_buf[info->rx_cbuf][where] = flag;
541 /* reset the error indication */
542 write_zsreg(info->zs_channel, 0, ERR_RES);
543 }
544
545 spin_unlock(&info->rx_dma_lock);
546}
547
548/*
549 * This is the serial driver's generic interrupt routine
550 */
551static irqreturn_t rs_interrupt(int irq, void *dev_id, struct pt_regs * regs)
552{
553 struct mac_serial *info = (struct mac_serial *) dev_id;
554 unsigned char zs_intreg;
555 int shift;
556 unsigned long flags;
557 int handled = 0;
558
559 if (!(info->flags & ZILOG_INITIALIZED)) {
560 printk(KERN_WARNING "rs_interrupt: irq %d, port not "
561 "initialized\n", irq);
562 disable_irq(irq);
563 return IRQ_NONE;
564 }
565
566 /* NOTE: The read register 3, which holds the irq status,
567 * does so for both channels on each chip. Although
568 * the status value itself must be read from the A
569 * channel and is only valid when read from channel A.
570 * Yes... broken hardware...
571 */
572#define CHAN_IRQMASK (CHBRxIP | CHBTxIP | CHBEXT)
573
574 if (info->zs_chan_a == info->zs_channel)
575 shift = 3; /* Channel A */
576 else
577 shift = 0; /* Channel B */
578
579 spin_lock_irqsave(&info->lock, flags);
580 for (;;) {
581 zs_intreg = read_zsreg(info->zs_chan_a, 3) >> shift;
582#ifdef SERIAL_DEBUG_INTR
583 printk(KERN_DEBUG "rs_interrupt: irq %d, zs_intreg 0x%x\n",
584 irq, (int)zs_intreg);
585#endif
586
587 if ((zs_intreg & CHAN_IRQMASK) == 0)
588 break;
589 handled = 1;
590
591 if (zs_intreg & CHBRxIP) {
592 /* If we are doing DMA, we only ask for interrupts
593 on characters with errors or special conditions. */
594 if (info->dma_initted)
595 receive_special_dma(info);
596 else
597 receive_chars(info, regs);
598 }
599 if (zs_intreg & CHBTxIP)
600 transmit_chars(info);
601 if (zs_intreg & CHBEXT)
602 status_handle(info);
603 }
604 spin_unlock_irqrestore(&info->lock, flags);
605 return IRQ_RETVAL(handled);
606}
607
608/* Transmit DMA interrupt - not used at present */
609static irqreturn_t rs_txdma_irq(int irq, void *dev_id, struct pt_regs *regs)
610{
611 return IRQ_HANDLED;
612}
613
614/*
615 * Receive DMA interrupt.
616 */
617static irqreturn_t rs_rxdma_irq(int irq, void *dev_id, struct pt_regs *regs)
618{
619 struct mac_serial *info = (struct mac_serial *) dev_id;
620 volatile struct dbdma_cmd *cd;
621
622 if (!info->dma_initted)
623 return IRQ_NONE;
624 spin_lock(&info->rx_dma_lock);
625 /* First, confirm that this interrupt is, indeed, coming */
626 /* from Rx DMA */
627 cd = info->rx_cmds[info->rx_cbuf] + 2;
628 if ((in_le16(&cd->xfer_status) & (RUN | ACTIVE)) != (RUN | ACTIVE)) {
629 spin_unlock(&info->rx_dma_lock);
630 return IRQ_NONE;
631 }
632 if (info->rx_fbuf != RX_NO_FBUF) {
633 info->rx_cbuf = info->rx_fbuf;
634 if (++info->rx_fbuf == info->rx_nbuf)
635 info->rx_fbuf = 0;
636 if (info->rx_fbuf == info->rx_ubuf)
637 info->rx_fbuf = RX_NO_FBUF;
638 }
639 spin_unlock(&info->rx_dma_lock);
640 return IRQ_HANDLED;
641}
642
643/*
644 * -------------------------------------------------------------------
645 * Here ends the serial interrupt routines.
646 * -------------------------------------------------------------------
647 */
648
649/*
650 * ------------------------------------------------------------
651 * rs_stop() and rs_start()
652 *
653 * This routines are called before setting or resetting tty->stopped.
654 * ------------------------------------------------------------
655 */
656static void rs_stop(struct tty_struct *tty)
657{
658 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
659
660#ifdef SERIAL_DEBUG_STOP
661 printk(KERN_DEBUG "rs_stop %ld....\n",
662 tty->ldisc.chars_in_buffer(tty));
663#endif
664
665 if (serial_paranoia_check(info, tty->name, "rs_stop"))
666 return;
667
668#if 0
669 spin_lock_irqsave(&info->lock, flags);
670 if (info->curregs[5] & TxENAB) {
671 info->curregs[5] &= ~TxENAB;
672 info->pendregs[5] &= ~TxENAB;
673 write_zsreg(info->zs_channel, 5, info->curregs[5]);
674 }
675 spin_unlock_irqrestore(&info->lock, flags);
676#endif
677}
678
679static void rs_start(struct tty_struct *tty)
680{
681 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
682 unsigned long flags;
683
684#ifdef SERIAL_DEBUG_STOP
685 printk(KERN_DEBUG "rs_start %ld....\n",
686 tty->ldisc.chars_in_buffer(tty));
687#endif
688
689 if (serial_paranoia_check(info, tty->name, "rs_start"))
690 return;
691
692 spin_lock_irqsave(&info->lock, flags);
693#if 0
694 if (info->xmit_cnt && info->xmit_buf && !(info->curregs[5] & TxENAB)) {
695 info->curregs[5] |= TxENAB;
696 info->pendregs[5] = info->curregs[5];
697 write_zsreg(info->zs_channel, 5, info->curregs[5]);
698 }
699#else
700 if (info->xmit_cnt && info->xmit_buf && !info->tx_active) {
701 transmit_chars(info);
702 }
703#endif
704 spin_unlock_irqrestore(&info->lock, flags);
705}
706
707static void do_softint(void *private_)
708{
709 struct mac_serial *info = (struct mac_serial *) private_;
710 struct tty_struct *tty;
711
712 tty = info->tty;
713 if (!tty)
714 return;
715
716 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event))
717 tty_wakeup(tty);
718}
719
720static int startup(struct mac_serial * info)
721{
722 int delay;
723
724 OPNDBG("startup() (ttyS%d, irq %d)\n", info->line, info->irq);
725
726 if (info->flags & ZILOG_INITIALIZED) {
727 OPNDBG(" -> already inited\n");
728 return 0;
729 }
730
731 if (!info->xmit_buf) {
732 info->xmit_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
733 if (!info->xmit_buf)
734 return -ENOMEM;
735 }
736
737 OPNDBG("starting up ttyS%d (irq %d)...\n", info->line, info->irq);
738
739 delay = set_scc_power(info, 1);
740
741 setup_scc(info);
742
743 if (delay) {
744 unsigned long flags;
745
746 /* delay is in ms */
747 spin_lock_irqsave(&info->lock, flags);
748 info->power_wait = 1;
749 mod_timer(&info->powerup_timer,
750 jiffies + (delay * HZ + 999) / 1000);
751 spin_unlock_irqrestore(&info->lock, flags);
752 }
753
754 OPNDBG("enabling IRQ on ttyS%d (irq %d)...\n", info->line, info->irq);
755
756 info->flags |= ZILOG_INITIALIZED;
757 enable_irq(info->irq);
758 if (info->dma_initted) {
759 enable_irq(info->rx_dma_irq);
760 }
761
762 return 0;
763}
764
765static _INLINE_ void rxdma_start(struct mac_serial * info, int curr)
766{
767 volatile struct dbdma_regs *rd = &info->rx->dma;
768 volatile struct dbdma_cmd *cd = info->rx_cmds[curr];
769
770//printk(KERN_DEBUG "SCC: rxdma_start\n");
771
772 st_le32(&rd->cmdptr, virt_to_bus(cd));
773 out_le32(&rd->control, (RUN << 16) | RUN);
774}
775
776static void rxdma_to_tty(struct mac_serial *info)
777{
778 struct tty_struct *tty = info->tty;
779 volatile struct dbdma_regs *rd = &info->rx->dma;
780 unsigned long flags;
781 int residue, available, space, do_queue;
782
783 if (!tty)
784 return;
785
786 do_queue = 0;
787 spin_lock_irqsave(&info->rx_dma_lock, flags);
788more:
789 space = TTY_FLIPBUF_SIZE - tty->flip.count;
790 if (!space) {
791 do_queue++;
792 goto out;
793 }
794 residue = 0;
795 if (info->rx_ubuf == info->rx_cbuf) {
796 if ((ld_le32(&rd->status) & ACTIVE) != 0) {
797 dbdma_flush(rd);
798 if (in_le32(&rd->cmdptr)
799 == virt_to_bus(info->rx_cmds[info->rx_cbuf]+1))
800 residue = in_le16(&info->rx->res_count);
801 }
802 }
803 available = RX_BUF_SIZE - residue - info->rx_done_bytes;
804 if (available > space)
805 available = space;
806 if (available) {
807 memcpy(tty->flip.char_buf_ptr,
808 info->rx_char_buf[info->rx_ubuf] + info->rx_done_bytes,
809 available);
810 memcpy(tty->flip.flag_buf_ptr,
811 info->rx_flag_buf[info->rx_ubuf] + info->rx_done_bytes,
812 available);
813 tty->flip.char_buf_ptr += available;
814 tty->flip.count += available;
815 tty->flip.flag_buf_ptr += available;
816 memset(info->rx_flag_buf[info->rx_ubuf] + info->rx_done_bytes,
817 0, available);
818 info->rx_done_bytes += available;
819 do_queue++;
820 }
821 if (info->rx_done_bytes == RX_BUF_SIZE) {
822 volatile struct dbdma_cmd *cd = info->rx_cmds[info->rx_ubuf];
823
824 if (info->rx_ubuf == info->rx_cbuf)
825 goto out;
826 /* mark rx_char_buf[rx_ubuf] free */
827 st_le16(&cd->command, DBDMA_NOP);
828 cd++;
829 st_le32(&cd->cmd_dep, 0);
830 st_le32((unsigned int *)&cd->res_count, 0);
831 cd++;
832 st_le16(&cd->xfer_status, 0);
833
834 if (info->rx_fbuf == RX_NO_FBUF) {
835 info->rx_fbuf = info->rx_ubuf;
836 if (!(ld_le32(&rd->status) & ACTIVE)) {
837 dbdma_reset(&info->rx->dma);
838 rxdma_start(info, info->rx_ubuf);
839 info->rx_cbuf = info->rx_ubuf;
840 }
841 }
842 info->rx_done_bytes = 0;
843 if (++info->rx_ubuf == info->rx_nbuf)
844 info->rx_ubuf = 0;
845 if (info->rx_fbuf == info->rx_ubuf)
846 info->rx_fbuf = RX_NO_FBUF;
847 goto more;
848 }
849out:
850 spin_unlock_irqrestore(&info->rx_dma_lock, flags);
851 if (do_queue)
852 tty_flip_buffer_push(tty);
853}
854
855static void poll_rxdma(unsigned long private_)
856{
857 struct mac_serial *info = (struct mac_serial *) private_;
858 unsigned long flags;
859
860 rxdma_to_tty(info);
861 spin_lock_irqsave(&info->rx_dma_lock, flags);
862 mod_timer(&info->poll_dma_timer, RX_DMA_TIMER);
863 spin_unlock_irqrestore(&info->rx_dma_lock, flags);
864}
865
866static void dma_init(struct mac_serial * info)
867{
868 int i, size;
869 volatile struct dbdma_cmd *cd;
870 unsigned char *p;
871
872 info->rx_nbuf = 8;
873
874 /* various mem set up */
875 size = sizeof(struct dbdma_cmd) * (3 * info->rx_nbuf + 2)
876 + (RX_BUF_SIZE * 2 + sizeof(*info->rx_cmds)
877 + sizeof(*info->rx_char_buf) + sizeof(*info->rx_flag_buf))
878 * info->rx_nbuf;
879 info->dma_priv = kmalloc(size, GFP_KERNEL | GFP_DMA);
880 if (info->dma_priv == NULL)
881 return;
882 memset(info->dma_priv, 0, size);
883
884 info->rx_cmds = (volatile struct dbdma_cmd **)info->dma_priv;
885 info->rx_char_buf = (unsigned char **) (info->rx_cmds + info->rx_nbuf);
886 info->rx_flag_buf = info->rx_char_buf + info->rx_nbuf;
887 p = (unsigned char *) (info->rx_flag_buf + info->rx_nbuf);
888 for (i = 0; i < info->rx_nbuf; i++, p += RX_BUF_SIZE)
889 info->rx_char_buf[i] = p;
890 for (i = 0; i < info->rx_nbuf; i++, p += RX_BUF_SIZE)
891 info->rx_flag_buf[i] = p;
892
893 /* a bit of DMA programming */
894 cd = info->rx_cmds[0] = (volatile struct dbdma_cmd *) DBDMA_ALIGN(p);
895 st_le16(&cd->command, DBDMA_NOP);
896 cd++;
897 st_le16(&cd->req_count, RX_BUF_SIZE);
898 st_le16(&cd->command, INPUT_MORE);
899 st_le32(&cd->phy_addr, virt_to_bus(info->rx_char_buf[0]));
900 cd++;
901 st_le16(&cd->req_count, 4);
902 st_le16(&cd->command, STORE_WORD | INTR_ALWAYS);
903 st_le32(&cd->phy_addr, virt_to_bus(cd-2));
904 st_le32(&cd->cmd_dep, DBDMA_STOP);
905 for (i = 1; i < info->rx_nbuf; i++) {
906 info->rx_cmds[i] = ++cd;
907 st_le16(&cd->command, DBDMA_NOP);
908 cd++;
909 st_le16(&cd->req_count, RX_BUF_SIZE);
910 st_le16(&cd->command, INPUT_MORE);
911 st_le32(&cd->phy_addr, virt_to_bus(info->rx_char_buf[i]));
912 cd++;
913 st_le16(&cd->req_count, 4);
914 st_le16(&cd->command, STORE_WORD | INTR_ALWAYS);
915 st_le32(&cd->phy_addr, virt_to_bus(cd-2));
916 st_le32(&cd->cmd_dep, DBDMA_STOP);
917 }
918 cd++;
919 st_le16(&cd->command, DBDMA_NOP | BR_ALWAYS);
920 st_le32(&cd->cmd_dep, virt_to_bus(info->rx_cmds[0]));
921
922 /* setup DMA to our liking */
923 dbdma_reset(&info->rx->dma);
924 st_le32(&info->rx->dma.intr_sel, 0x10001);
925 st_le32(&info->rx->dma.br_sel, 0x10001);
926 out_le32(&info->rx->dma.wait_sel, 0x10001);
927
928 /* set various flags */
929 info->rx_ubuf = 0;
930 info->rx_cbuf = 0;
931 info->rx_fbuf = info->rx_ubuf + 1;
932 if (info->rx_fbuf == info->rx_nbuf)
933 info->rx_fbuf = RX_NO_FBUF;
934 info->rx_done_bytes = 0;
935
936 /* setup polling */
937 init_timer(&info->poll_dma_timer);
938 info->poll_dma_timer.function = (void *)&poll_rxdma;
939 info->poll_dma_timer.data = (unsigned long)info;
940
941 info->dma_initted = 1;
942}
943
944/*
945 * FixZeroBug....Works around a bug in the SCC receving channel.
946 * Taken from Darwin code, 15 Sept. 2000 -DanM
947 *
948 * The following sequence prevents a problem that is seen with O'Hare ASICs
949 * (most versions -- also with some Heathrow and Hydra ASICs) where a zero
950 * at the input to the receiver becomes 'stuck' and locks up the receiver.
951 * This problem can occur as a result of a zero bit at the receiver input
952 * coincident with any of the following events:
953 *
954 * The SCC is initialized (hardware or software).
955 * A framing error is detected.
956 * The clocking option changes from synchronous or X1 asynchronous
957 * clocking to X16, X32, or X64 asynchronous clocking.
958 * The decoding mode is changed among NRZ, NRZI, FM0, or FM1.
959 *
960 * This workaround attempts to recover from the lockup condition by placing
961 * the SCC in synchronous loopback mode with a fast clock before programming
962 * any of the asynchronous modes.
963 */
964static void fix_zero_bug_scc(struct mac_serial * info)
965{
966 write_zsreg(info->zs_channel, 9,
967 (info->zs_channel == info->zs_chan_a? CHRA: CHRB));
968 udelay(10);
969 write_zsreg(info->zs_channel, 9,
970 ((info->zs_channel == info->zs_chan_a? CHRA: CHRB) | NV));
971
972 write_zsreg(info->zs_channel, 4, (X1CLK | EXTSYNC));
973
974 /* I think this is wrong....but, I just copying code....
975 */
976 write_zsreg(info->zs_channel, 3, (8 & ~RxENABLE));
977
978 write_zsreg(info->zs_channel, 5, (8 & ~TxENAB));
979 write_zsreg(info->zs_channel, 9, NV); /* Didn't we already do this? */
980 write_zsreg(info->zs_channel, 11, (RCBR | TCBR));
981 write_zsreg(info->zs_channel, 12, 0);
982 write_zsreg(info->zs_channel, 13, 0);
983 write_zsreg(info->zs_channel, 14, (LOOPBAK | SSBR));
984 write_zsreg(info->zs_channel, 14, (LOOPBAK | SSBR | BRENABL));
985 write_zsreg(info->zs_channel, 3, (8 | RxENABLE));
986 write_zsreg(info->zs_channel, 0, RES_EXT_INT);
987 write_zsreg(info->zs_channel, 0, RES_EXT_INT); /* to kill some time */
988
989 /* The channel should be OK now, but it is probably receiving
990 * loopback garbage.
991 * Switch to asynchronous mode, disable the receiver,
992 * and discard everything in the receive buffer.
993 */
994 write_zsreg(info->zs_channel, 9, NV);
995 write_zsreg(info->zs_channel, 4, PAR_ENA);
996 write_zsreg(info->zs_channel, 3, (8 & ~RxENABLE));
997
998 while (read_zsreg(info->zs_channel, 0) & Rx_CH_AV) {
999 (void)read_zsreg(info->zs_channel, 8);
1000 write_zsreg(info->zs_channel, 0, RES_EXT_INT);
1001 write_zsreg(info->zs_channel, 0, ERR_RES);
1002 }
1003}
1004
1005static int setup_scc(struct mac_serial * info)
1006{
1007 unsigned long flags;
1008
1009 OPNDBG("setting up ttyS%d SCC...\n", info->line);
1010
1011 spin_lock_irqsave(&info->lock, flags);
1012
1013 /* Nice buggy HW ... */
1014 fix_zero_bug_scc(info);
1015
1016 /*
1017 * Reset the chip.
1018 */
1019 write_zsreg(info->zs_channel, 9,
1020 (info->zs_channel == info->zs_chan_a? CHRA: CHRB));
1021 udelay(10);
1022 write_zsreg(info->zs_channel, 9, 0);
1023
1024 /*
1025 * Clear the receive FIFO.
1026 */
1027 ZS_CLEARFIFO(info->zs_channel);
1028 info->xmit_fifo_size = 1;
1029
1030 /*
1031 * Reset DMAs
1032 */
1033 if (info->has_dma)
1034 dma_init(info);
1035
1036 /*
1037 * Clear the interrupt registers.
1038 */
1039 write_zsreg(info->zs_channel, 0, ERR_RES);
1040 write_zsreg(info->zs_channel, 0, RES_H_IUS);
1041
1042 /*
1043 * Turn on RTS and DTR.
1044 */
1045 if (!info->is_irda)
1046 zs_rtsdtr(info, 1);
1047
1048 /*
1049 * Finally, enable sequencing and interrupts
1050 */
1051 if (!info->dma_initted) {
1052 /* interrupt on ext/status changes, all received chars,
1053 transmit ready */
1054 info->curregs[1] = (info->curregs[1] & ~0x18)
1055 | (EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB);
1056 } else {
1057 /* interrupt on ext/status changes, W/Req pin is
1058 receive DMA request */
1059 info->curregs[1] = (info->curregs[1] & ~(0x18 | TxINT_ENAB))
1060 | (EXT_INT_ENAB | WT_RDY_RT | WT_FN_RDYFN);
1061 write_zsreg(info->zs_channel, 1, info->curregs[1]);
1062 /* enable W/Req pin */
1063 info->curregs[1] |= WT_RDY_ENAB;
1064 write_zsreg(info->zs_channel, 1, info->curregs[1]);
1065 /* enable interrupts on transmit ready and receive errors */
1066 info->curregs[1] |= INT_ERR_Rx | TxINT_ENAB;
1067 }
1068 info->pendregs[1] = info->curregs[1];
1069 info->curregs[3] |= (RxENABLE | Rx8);
1070 info->pendregs[3] = info->curregs[3];
1071 info->curregs[5] |= (TxENAB | Tx8);
1072 info->pendregs[5] = info->curregs[5];
1073 info->curregs[9] |= (NV | MIE);
1074 info->pendregs[9] = info->curregs[9];
1075 write_zsreg(info->zs_channel, 3, info->curregs[3]);
1076 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1077 write_zsreg(info->zs_channel, 9, info->curregs[9]);
1078
1079 if (info->tty)
1080 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1081 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1082
1083 spin_unlock_irqrestore(&info->lock, flags);
1084
1085 /*
1086 * Set the speed of the serial port
1087 */
1088 change_speed(info, 0);
1089
1090 /* Save the current value of RR0 */
1091 info->read_reg_zero = read_zsreg(info->zs_channel, 0);
1092
1093 if (info->dma_initted) {
1094 spin_lock_irqsave(&info->rx_dma_lock, flags);
1095 rxdma_start(info, 0);
1096 info->poll_dma_timer.expires = RX_DMA_TIMER;
1097 add_timer(&info->poll_dma_timer);
1098 spin_unlock_irqrestore(&info->rx_dma_lock, flags);
1099 }
1100
1101 return 0;
1102}
1103
1104/*
1105 * This routine will shutdown a serial port; interrupts are disabled, and
1106 * DTR is dropped if the hangup on close termio flag is on.
1107 */
1108static void shutdown(struct mac_serial * info)
1109{
1110 OPNDBG("Shutting down serial port %d (irq %d)....\n", info->line,
1111 info->irq);
1112
1113 if (!(info->flags & ZILOG_INITIALIZED)) {
1114 OPNDBG("(already shutdown)\n");
1115 return;
1116 }
1117
1118 if (info->has_dma) {
1119 del_timer(&info->poll_dma_timer);
1120 dbdma_reset(info->tx_dma);
1121 dbdma_reset(&info->rx->dma);
1122 disable_irq(info->tx_dma_irq);
1123 disable_irq(info->rx_dma_irq);
1124 }
1125 disable_irq(info->irq);
1126
1127 info->pendregs[1] = info->curregs[1] = 0;
1128 write_zsreg(info->zs_channel, 1, 0); /* no interrupts */
1129
1130 info->curregs[3] &= ~RxENABLE;
1131 info->pendregs[3] = info->curregs[3];
1132 write_zsreg(info->zs_channel, 3, info->curregs[3]);
1133
1134 info->curregs[5] &= ~TxENAB;
1135 if (!info->tty || C_HUPCL(info->tty))
1136 info->curregs[5] &= ~DTR;
1137 info->pendregs[5] = info->curregs[5];
1138 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1139
1140 if (info->tty)
1141 set_bit(TTY_IO_ERROR, &info->tty->flags);
1142
1143 set_scc_power(info, 0);
1144
1145 if (info->xmit_buf) {
1146 free_page((unsigned long) info->xmit_buf);
1147 info->xmit_buf = 0;
1148 }
1149
1150 if (info->has_dma && info->dma_priv) {
1151 kfree(info->dma_priv);
1152 info->dma_priv = NULL;
1153 info->dma_initted = 0;
1154 }
1155
1156 memset(info->curregs, 0, sizeof(info->curregs));
1157 memset(info->pendregs, 0, sizeof(info->pendregs));
1158
1159 info->flags &= ~ZILOG_INITIALIZED;
1160}
1161
1162/*
1163 * Turn power on or off to the SCC and associated stuff
1164 * (port drivers, modem, IR port, etc.)
1165 * Returns the number of milliseconds we should wait before
1166 * trying to use the port.
1167 */
1168static int set_scc_power(struct mac_serial * info, int state)
1169{
1170 int delay = 0;
1171
1172 if (state) {
1173 PWRDBG("ttyS%d: powering up hardware\n", info->line);
1174 pmac_call_feature(
1175 PMAC_FTR_SCC_ENABLE,
1176 info->dev_node, info->port_type, 1);
1177 if (info->is_internal_modem) {
1178 pmac_call_feature(
1179 PMAC_FTR_MODEM_ENABLE,
1180 info->dev_node, 0, 1);
1181 delay = 2500; /* wait for 2.5s before using */
1182 } else if (info->is_irda)
1183 mdelay(50); /* Do better here once the problems
1184 * with blocking have been ironed out
1185 */
1186 } else {
1187 /* TODO: Make that depend on a timer, don't power down
1188 * immediately
1189 */
1190 PWRDBG("ttyS%d: shutting down hardware\n", info->line);
1191 if (info->is_internal_modem) {
1192 PWRDBG("ttyS%d: shutting down modem\n", info->line);
1193 pmac_call_feature(
1194 PMAC_FTR_MODEM_ENABLE,
1195 info->dev_node, 0, 0);
1196 }
1197 pmac_call_feature(
1198 PMAC_FTR_SCC_ENABLE,
1199 info->dev_node, info->port_type, 0);
1200 }
1201 return delay;
1202}
1203
1204static void irda_rts_pulses(struct mac_serial *info, int w)
1205{
1206 udelay(w);
1207 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB);
1208 udelay(2);
1209 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB | RTS);
1210 udelay(8);
1211 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB);
1212 udelay(4);
1213 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB | RTS);
1214}
1215
1216/*
1217 * Set the irda codec on the imac to the specified baud rate.
1218 */
1219static void irda_setup(struct mac_serial *info)
1220{
1221 int code, speed, t;
1222
1223 speed = info->tty->termios->c_cflag & CBAUD;
1224 if (speed < B2400 || speed > B115200)
1225 return;
1226 code = 0x4d + B115200 - speed;
1227
1228 /* disable serial interrupts and receive DMA */
1229 write_zsreg(info->zs_channel, 1, info->curregs[1] & ~0x9f);
1230
1231 /* wait for transmitter to drain */
1232 t = 10000;
1233 while ((read_zsreg(info->zs_channel, 0) & Tx_BUF_EMP) == 0
1234 || (read_zsreg(info->zs_channel, 1) & ALL_SNT) == 0) {
1235 if (--t <= 0) {
1236 printk(KERN_ERR "transmitter didn't drain\n");
1237 return;
1238 }
1239 udelay(10);
1240 }
1241 udelay(100);
1242
1243 /* set to 8 bits, no parity, 19200 baud, RTS on, DTR off */
1244 write_zsreg(info->zs_channel, 4, X16CLK | SB1);
1245 write_zsreg(info->zs_channel, 11, TCBR | RCBR);
1246 t = BPS_TO_BRG(19200, ZS_CLOCK/16);
1247 write_zsreg(info->zs_channel, 12, t);
1248 write_zsreg(info->zs_channel, 13, t >> 8);
1249 write_zsreg(info->zs_channel, 14, BRENABL);
1250 write_zsreg(info->zs_channel, 3, Rx8 | RxENABLE);
1251 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB | RTS);
1252
1253 /* set TxD low for ~104us and pulse RTS */
1254 udelay(1000);
1255 write_zsdata(info->zs_channel, 0xfe);
1256 irda_rts_pulses(info, 150);
1257 irda_rts_pulses(info, 180);
1258 irda_rts_pulses(info, 50);
1259 udelay(100);
1260
1261 /* assert DTR, wait 30ms, talk to the chip */
1262 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB | RTS | DTR);
1263 mdelay(30);
1264 while (read_zsreg(info->zs_channel, 0) & Rx_CH_AV)
1265 read_zsdata(info->zs_channel);
1266
1267 write_zsdata(info->zs_channel, 1);
1268 t = 1000;
1269 while ((read_zsreg(info->zs_channel, 0) & Rx_CH_AV) == 0) {
1270 if (--t <= 0) {
1271 printk(KERN_ERR "irda_setup timed out on 1st byte\n");
1272 goto out;
1273 }
1274 udelay(10);
1275 }
1276 t = read_zsdata(info->zs_channel);
1277 if (t != 4)
1278 printk(KERN_ERR "irda_setup 1st byte = %x\n", t);
1279
1280 write_zsdata(info->zs_channel, code);
1281 t = 1000;
1282 while ((read_zsreg(info->zs_channel, 0) & Rx_CH_AV) == 0) {
1283 if (--t <= 0) {
1284 printk(KERN_ERR "irda_setup timed out on 2nd byte\n");
1285 goto out;
1286 }
1287 udelay(10);
1288 }
1289 t = read_zsdata(info->zs_channel);
1290 if (t != code)
1291 printk(KERN_ERR "irda_setup 2nd byte = %x (%x)\n", t, code);
1292
1293 /* Drop DTR again and do some more RTS pulses */
1294 out:
1295 udelay(100);
1296 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB | RTS);
1297 irda_rts_pulses(info, 80);
1298
1299 /* We should be right to go now. We assume that load_zsregs
1300 will get called soon to load up the correct baud rate etc. */
1301 info->curregs[5] = (info->curregs[5] | RTS) & ~DTR;
1302 info->pendregs[5] = info->curregs[5];
1303}
1304
1305/*
1306 * This routine is called to set the UART divisor registers to match
1307 * the specified baud rate for a serial port.
1308 */
1309static void change_speed(struct mac_serial *info, struct termios *old_termios)
1310{
1311 unsigned cflag;
1312 int bits;
1313 int brg, baud;
1314 unsigned long flags;
1315
1316 if (!info->tty || !info->tty->termios)
1317 return;
1318
1319 cflag = info->tty->termios->c_cflag;
1320 baud = tty_get_baud_rate(info->tty);
1321 if (baud == 0) {
1322 if (old_termios) {
1323 info->tty->termios->c_cflag &= ~CBAUD;
1324 info->tty->termios->c_cflag |= (old_termios->c_cflag & CBAUD);
1325 cflag = info->tty->termios->c_cflag;
1326 baud = tty_get_baud_rate(info->tty);
1327 }
1328 else
1329 baud = info->zs_baud;
1330 }
1331 if (baud > 230400)
1332 baud = 230400;
1333 else if (baud == 0)
1334 baud = 38400;
1335
1336 spin_lock_irqsave(&info->lock, flags);
1337 info->zs_baud = baud;
1338 info->clk_divisor = 16;
1339
1340 BAUDBG(KERN_DEBUG "set speed to %d bds, ", baud);
1341
1342 switch (baud) {
1343 case ZS_CLOCK/16: /* 230400 */
1344 info->curregs[4] = X16CLK;
1345 info->curregs[11] = 0;
1346 break;
1347 case ZS_CLOCK/32: /* 115200 */
1348 info->curregs[4] = X32CLK;
1349 info->curregs[11] = 0;
1350 break;
1351 default:
1352 info->curregs[4] = X16CLK;
1353 info->curregs[11] = TCBR | RCBR;
1354 brg = BPS_TO_BRG(baud, ZS_CLOCK/info->clk_divisor);
1355 info->curregs[12] = (brg & 255);
1356 info->curregs[13] = ((brg >> 8) & 255);
1357 info->curregs[14] = BRENABL;
1358 }
1359
1360 /* byte size and parity */
1361 info->curregs[3] &= ~RxNBITS_MASK;
1362 info->curregs[5] &= ~TxNBITS_MASK;
1363 switch (cflag & CSIZE) {
1364 case CS5:
1365 info->curregs[3] |= Rx5;
1366 info->curregs[5] |= Tx5;
1367 BAUDBG("5 bits, ");
1368 bits = 7;
1369 break;
1370 case CS6:
1371 info->curregs[3] |= Rx6;
1372 info->curregs[5] |= Tx6;
1373 BAUDBG("6 bits, ");
1374 bits = 8;
1375 break;
1376 case CS7:
1377 info->curregs[3] |= Rx7;
1378 info->curregs[5] |= Tx7;
1379 BAUDBG("7 bits, ");
1380 bits = 9;
1381 break;
1382 case CS8:
1383 default: /* defaults to 8 bits */
1384 info->curregs[3] |= Rx8;
1385 info->curregs[5] |= Tx8;
1386 BAUDBG("8 bits, ");
1387 bits = 10;
1388 break;
1389 }
1390 info->pendregs[3] = info->curregs[3];
1391 info->pendregs[5] = info->curregs[5];
1392
1393 info->curregs[4] &= ~(SB_MASK | PAR_ENA | PAR_EVEN);
1394 if (cflag & CSTOPB) {
1395 info->curregs[4] |= SB2;
1396 bits++;
1397 BAUDBG("2 stop, ");
1398 } else {
1399 info->curregs[4] |= SB1;
1400 BAUDBG("1 stop, ");
1401 }
1402 if (cflag & PARENB) {
1403 bits++;
1404 info->curregs[4] |= PAR_ENA;
1405 BAUDBG("parity, ");
1406 }
1407 if (!(cflag & PARODD)) {
1408 info->curregs[4] |= PAR_EVEN;
1409 }
1410 info->pendregs[4] = info->curregs[4];
1411
1412 if (!(cflag & CLOCAL)) {
1413 if (!(info->curregs[15] & DCDIE))
1414 info->read_reg_zero = read_zsreg(info->zs_channel, 0);
1415 info->curregs[15] |= DCDIE;
1416 } else
1417 info->curregs[15] &= ~DCDIE;
1418 if (cflag & CRTSCTS) {
1419 info->curregs[15] |= CTSIE;
1420 if ((read_zsreg(info->zs_channel, 0) & CTS) != 0)
1421 info->tx_stopped = 1;
1422 } else {
1423 info->curregs[15] &= ~CTSIE;
1424 info->tx_stopped = 0;
1425 }
1426 info->pendregs[15] = info->curregs[15];
1427
1428 /* Calc timeout value. This is pretty broken with high baud rates with HZ=100.
1429 This code would love a larger HZ and a >1 fifo size, but this is not
1430 a priority. The resulting value must be >HZ/2
1431 */
1432 info->timeout = ((info->xmit_fifo_size*HZ*bits) / baud);
1433 info->timeout += HZ/50+1; /* Add .02 seconds of slop */
1434
1435 BAUDBG("timeout=%d/%ds, base:%d\n", (int)info->timeout, (int)HZ,
1436 (int)info->baud_base);
1437
1438 /* set the irda codec to the right rate */
1439 if (info->is_irda)
1440 irda_setup(info);
1441
1442 /* Load up the new values */
1443 load_zsregs(info->zs_channel, info->curregs);
1444
1445 spin_unlock_irqrestore(&info->lock, flags);
1446}
1447
1448static void rs_flush_chars(struct tty_struct *tty)
1449{
1450 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1451 unsigned long flags;
1452
1453 if (serial_paranoia_check(info, tty->name, "rs_flush_chars"))
1454 return;
1455
1456 spin_lock_irqsave(&info->lock, flags);
1457 if (!(info->xmit_cnt <= 0 || tty->stopped || info->tx_stopped ||
1458 !info->xmit_buf))
1459 /* Enable transmitter */
1460 transmit_chars(info);
1461 spin_unlock_irqrestore(&info->lock, flags);
1462}
1463
1464static int rs_write(struct tty_struct * tty,
1465 const unsigned char *buf, int count)
1466{
1467 int c, ret = 0;
1468 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1469 unsigned long flags;
1470
1471 if (serial_paranoia_check(info, tty->name, "rs_write"))
1472 return 0;
1473
1474 if (!tty || !info->xmit_buf || !tmp_buf)
1475 return 0;
1476
1477 while (1) {
1478 spin_lock_irqsave(&info->lock, flags);
1479 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1480 SERIAL_XMIT_SIZE - info->xmit_head));
1481 if (c <= 0) {
1482 spin_unlock_irqrestore(&info->lock, flags);
1483 break;
1484 }
1485 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1486 info->xmit_head = ((info->xmit_head + c) &
1487 (SERIAL_XMIT_SIZE-1));
1488 info->xmit_cnt += c;
1489 spin_unlock_irqrestore(&info->lock, flags);
1490 buf += c;
1491 count -= c;
1492 ret += c;
1493 }
1494 spin_lock_irqsave(&info->lock, flags);
1495 if (info->xmit_cnt && !tty->stopped && !info->tx_stopped
1496 && !info->tx_active)
1497 transmit_chars(info);
1498 spin_unlock_irqrestore(&info->lock, flags);
1499 return ret;
1500}
1501
1502static int rs_write_room(struct tty_struct *tty)
1503{
1504 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1505 int ret;
1506
1507 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
1508 return 0;
1509 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1510 if (ret < 0)
1511 ret = 0;
1512 return ret;
1513}
1514
1515static int rs_chars_in_buffer(struct tty_struct *tty)
1516{
1517 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1518
1519 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
1520 return 0;
1521 return info->xmit_cnt;
1522}
1523
1524static void rs_flush_buffer(struct tty_struct *tty)
1525{
1526 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1527 unsigned long flags;
1528
1529 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
1530 return;
1531 spin_lock_irqsave(&info->lock, flags);
1532 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1533 spin_unlock_irqrestore(&info->lock, flags);
1534 tty_wakeup(tty);
1535}
1536
1537/*
1538 * ------------------------------------------------------------
1539 * rs_throttle()
1540 *
1541 * This routine is called by the upper-layer tty layer to signal that
1542 * incoming characters should be throttled.
1543 * ------------------------------------------------------------
1544 */
1545static void rs_throttle(struct tty_struct * tty)
1546{
1547 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1548 unsigned long flags;
1549#ifdef SERIAL_DEBUG_THROTTLE
1550 printk(KERN_DEBUG "throttle %ld....\n",tty->ldisc.chars_in_buffer(tty));
1551#endif
1552
1553 if (serial_paranoia_check(info, tty->name, "rs_throttle"))
1554 return;
1555
1556 if (I_IXOFF(tty)) {
1557 spin_lock_irqsave(&info->lock, flags);
1558 info->x_char = STOP_CHAR(tty);
1559 if (!info->tx_active)
1560 transmit_chars(info);
1561 spin_unlock_irqrestore(&info->lock, flags);
1562 }
1563
1564 if (C_CRTSCTS(tty)) {
1565 /*
1566 * Here we want to turn off the RTS line. On Macintoshes,
1567 * the external serial ports using a DIN-8 or DIN-9
1568 * connector only have the DTR line (which is usually
1569 * wired to both RTS and DTR on an external modem in
1570 * the cable). RTS doesn't go out to the serial port
1571 * socket, it acts as an output enable for the transmit
1572 * data line. So in this case we don't drop RTS.
1573 *
1574 * Macs with internal modems generally do have both RTS
1575 * and DTR wired to the modem, so in that case we do
1576 * drop RTS.
1577 */
1578 if (info->is_internal_modem) {
1579 spin_lock_irqsave(&info->lock, flags);
1580 info->curregs[5] &= ~RTS;
1581 info->pendregs[5] &= ~RTS;
1582 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1583 spin_unlock_irqrestore(&info->lock, flags);
1584 }
1585 }
1586
1587#ifdef CDTRCTS
1588 if (tty->termios->c_cflag & CDTRCTS) {
1589 spin_lock_irqsave(&info->lock, flags);
1590 info->curregs[5] &= ~DTR;
1591 info->pendregs[5] &= ~DTR;
1592 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1593 spin_unlock_irqrestore(&info->lock, flags);
1594 }
1595#endif /* CDTRCTS */
1596}
1597
1598static void rs_unthrottle(struct tty_struct * tty)
1599{
1600 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1601 unsigned long flags;
1602#ifdef SERIAL_DEBUG_THROTTLE
1603 printk(KERN_DEBUG "unthrottle %s: %d....\n",
1604 tty->ldisc.chars_in_buffer(tty));
1605#endif
1606
1607 if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
1608 return;
1609
1610 if (I_IXOFF(tty)) {
1611 spin_lock_irqsave(&info->lock, flags);
1612 if (info->x_char)
1613 info->x_char = 0;
1614 else {
1615 info->x_char = START_CHAR(tty);
1616 if (!info->tx_active)
1617 transmit_chars(info);
1618 }
1619 spin_unlock_irqrestore(&info->lock, flags);
1620 }
1621
1622 if (C_CRTSCTS(tty) && info->is_internal_modem) {
1623 /* Assert RTS line */
1624 spin_lock_irqsave(&info->lock, flags);
1625 info->curregs[5] |= RTS;
1626 info->pendregs[5] |= RTS;
1627 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1628 spin_unlock_irqrestore(&info->lock, flags);
1629 }
1630
1631#ifdef CDTRCTS
1632 if (tty->termios->c_cflag & CDTRCTS) {
1633 /* Assert DTR line */
1634 spin_lock_irqsave(&info->lock, flags);
1635 info->curregs[5] |= DTR;
1636 info->pendregs[5] |= DTR;
1637 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1638 spin_unlock_irqrestore(&info->lock, flags);
1639 }
1640#endif
1641}
1642
1643/*
1644 * ------------------------------------------------------------
1645 * rs_ioctl() and friends
1646 * ------------------------------------------------------------
1647 */
1648
1649static int get_serial_info(struct mac_serial * info,
1650 struct serial_struct __user * retinfo)
1651{
1652 struct serial_struct tmp;
1653
1654 if (!retinfo)
1655 return -EFAULT;
1656 memset(&tmp, 0, sizeof(tmp));
1657 tmp.type = info->type;
1658 tmp.line = info->line;
1659 tmp.port = info->port;
1660 tmp.irq = info->irq;
1661 tmp.flags = info->flags;
1662 tmp.baud_base = info->baud_base;
1663 tmp.close_delay = info->close_delay;
1664 tmp.closing_wait = info->closing_wait;
1665 tmp.custom_divisor = info->custom_divisor;
1666 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
1667 return -EFAULT;
1668 return 0;
1669}
1670
1671static int set_serial_info(struct mac_serial * info,
1672 struct serial_struct __user * new_info)
1673{
1674 struct serial_struct new_serial;
1675 struct mac_serial old_info;
1676 int retval = 0;
1677
1678 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
1679 return -EFAULT;
1680 old_info = *info;
1681
1682 if (!capable(CAP_SYS_ADMIN)) {
1683 if ((new_serial.baud_base != info->baud_base) ||
1684 (new_serial.type != info->type) ||
1685 (new_serial.close_delay != info->close_delay) ||
1686 ((new_serial.flags & ~ZILOG_USR_MASK) !=
1687 (info->flags & ~ZILOG_USR_MASK)))
1688 return -EPERM;
1689 info->flags = ((info->flags & ~ZILOG_USR_MASK) |
1690 (new_serial.flags & ZILOG_USR_MASK));
1691 info->custom_divisor = new_serial.custom_divisor;
1692 goto check_and_exit;
1693 }
1694
1695 if (info->count > 1)
1696 return -EBUSY;
1697
1698 /*
1699 * OK, past this point, all the error checking has been done.
1700 * At this point, we start making changes.....
1701 */
1702
1703 info->baud_base = new_serial.baud_base;
1704 info->flags = ((info->flags & ~ZILOG_FLAGS) |
1705 (new_serial.flags & ZILOG_FLAGS));
1706 info->type = new_serial.type;
1707 info->close_delay = new_serial.close_delay;
1708 info->closing_wait = new_serial.closing_wait;
1709
1710check_and_exit:
1711 if (info->flags & ZILOG_INITIALIZED)
1712 retval = setup_scc(info);
1713 return retval;
1714}
1715
1716/*
1717 * get_lsr_info - get line status register info
1718 *
1719 * Purpose: Let user call ioctl() to get info when the UART physically
1720 * is emptied. On bus types like RS485, the transmitter must
1721 * release the bus after transmitting. This must be done when
1722 * the transmit shift register is empty, not be done when the
1723 * transmit holding register is empty. This functionality
1724 * allows an RS485 driver to be written in user space.
1725 */
1726static int get_lsr_info(struct mac_serial * info, unsigned int *value)
1727{
1728 unsigned char status;
1729 unsigned long flags;
1730
1731 spin_lock_irqsave(&info->lock, flags);
1732 status = read_zsreg(info->zs_channel, 0);
1733 spin_unlock_irqrestore(&info->lock, flags);
1734 status = (status & Tx_BUF_EMP)? TIOCSER_TEMT: 0;
1735 return put_user(status,value);
1736}
1737
1738static int rs_tiocmget(struct tty_struct *tty, struct file *file)
1739{
1740 struct mac_serial * info = (struct mac_serial *)tty->driver_data;
1741 unsigned char control, status;
1742 unsigned long flags;
1743
1744#ifdef CONFIG_KGDB
1745 if (info->kgdb_channel)
1746 return -ENODEV;
1747#endif
1748 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
1749 return -ENODEV;
1750
1751 if (tty->flags & (1 << TTY_IO_ERROR))
1752 return -EIO;
1753
1754 spin_lock_irqsave(&info->lock, flags);
1755 control = info->curregs[5];
1756 status = read_zsreg(info->zs_channel, 0);
1757 spin_unlock_irqrestore(&info->lock, flags);
1758 return ((control & RTS) ? TIOCM_RTS: 0)
1759 | ((control & DTR) ? TIOCM_DTR: 0)
1760 | ((status & DCD) ? TIOCM_CAR: 0)
1761 | ((status & CTS) ? 0: TIOCM_CTS);
1762}
1763
1764static int rs_tiocmset(struct tty_struct *tty, struct file *file,
1765 unsigned int set, unsigned int clear)
1766{
1767 struct mac_serial * info = (struct mac_serial *)tty->driver_data;
1768 unsigned int arg, bits;
1769 unsigned long flags;
1770
1771#ifdef CONFIG_KGDB
1772 if (info->kgdb_channel)
1773 return -ENODEV;
1774#endif
1775 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
1776 return -ENODEV;
1777
1778 if (tty->flags & (1 << TTY_IO_ERROR))
1779 return -EIO;
1780
1781 spin_lock_irqsave(&info->lock, flags);
1782 if (set & TIOCM_RTS)
1783 info->curregs[5] |= RTS;
1784 if (set & TIOCM_DTR)
1785 info->curregs[5] |= DTR;
1786 if (clear & TIOCM_RTS)
1787 info->curregs[5] &= ~RTS;
1788 if (clear & TIOCM_DTR)
1789 info->curregs[5] &= ~DTR;
1790
1791 info->pendregs[5] = info->curregs[5];
1792 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1793 spin_unlock_irqrestore(&info->lock, flags);
1794 return 0;
1795}
1796
1797/*
1798 * rs_break - turn transmit break condition on/off
1799 */
1800static void rs_break(struct tty_struct *tty, int break_state)
1801{
1802 struct mac_serial *info = (struct mac_serial *) tty->driver_data;
1803 unsigned long flags;
1804
1805 if (serial_paranoia_check(info, tty->name, "rs_break"))
1806 return;
1807
1808 spin_lock_irqsave(&info->lock, flags);
1809 if (break_state == -1)
1810 info->curregs[5] |= SND_BRK;
1811 else
1812 info->curregs[5] &= ~SND_BRK;
1813 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1814 spin_unlock_irqrestore(&info->lock, flags);
1815}
1816
1817static int rs_ioctl(struct tty_struct *tty, struct file * file,
1818 unsigned int cmd, unsigned long arg)
1819{
1820 struct mac_serial * info = (struct mac_serial *)tty->driver_data;
1821
1822#ifdef CONFIG_KGDB
1823 if (info->kgdb_channel)
1824 return -ENODEV;
1825#endif
1826 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
1827 return -ENODEV;
1828
1829 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1830 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT)) {
1831 if (tty->flags & (1 << TTY_IO_ERROR))
1832 return -EIO;
1833 }
1834
1835 switch (cmd) {
1836 case TIOCGSERIAL:
1837 return get_serial_info(info,
1838 (struct serial_struct __user *) arg);
1839 case TIOCSSERIAL:
1840 return set_serial_info(info,
1841 (struct serial_struct __user *) arg);
1842 case TIOCSERGETLSR: /* Get line status register */
1843 return get_lsr_info(info, (unsigned int *) arg);
1844
1845 case TIOCSERGSTRUCT:
1846 if (copy_to_user((struct mac_serial __user *) arg,
1847 info, sizeof(struct mac_serial)))
1848 return -EFAULT;
1849 return 0;
1850
1851 default:
1852 return -ENOIOCTLCMD;
1853 }
1854 return 0;
1855}
1856
1857static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
1858{
1859 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1860 int was_stopped;
1861
1862 if (tty->termios->c_cflag == old_termios->c_cflag)
1863 return;
1864 was_stopped = info->tx_stopped;
1865
1866 change_speed(info, old_termios);
1867
1868 if (was_stopped && !info->tx_stopped) {
1869 tty->hw_stopped = 0;
1870 rs_start(tty);
1871 }
1872}
1873
1874/*
1875 * ------------------------------------------------------------
1876 * rs_close()
1877 *
1878 * This routine is called when the serial port gets closed.
1879 * Wait for the last remaining data to be sent.
1880 * ------------------------------------------------------------
1881 */
1882static void rs_close(struct tty_struct *tty, struct file * filp)
1883{
1884 struct mac_serial * info = (struct mac_serial *)tty->driver_data;
1885 unsigned long flags;
1886
1887 if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
1888 return;
1889
1890 spin_lock_irqsave(&info->lock, flags);
1891
1892 if (tty_hung_up_p(filp)) {
1893 spin_unlock_irqrestore(&info->lock, flags);
1894 return;
1895 }
1896
1897 OPNDBG("rs_close ttyS%d, count = %d\n", info->line, info->count);
1898 if ((tty->count == 1) && (info->count != 1)) {
1899 /*
1900 * Uh, oh. tty->count is 1, which means that the tty
1901 * structure will be freed. Info->count should always
1902 * be one in these conditions. If it's greater than
1903 * one, we've got real problems, since it means the
1904 * serial port won't be shutdown.
1905 */
1906 printk(KERN_ERR "rs_close: bad serial port count; tty->count "
1907 "is 1, info->count is %d\n", info->count);
1908 info->count = 1;
1909 }
1910 if (--info->count < 0) {
1911 printk(KERN_ERR "rs_close: bad serial port count for "
1912 "ttyS%d: %d\n", info->line, info->count);
1913 info->count = 0;
1914 }
1915 if (info->count) {
1916 spin_unlock_irqrestore(&info->lock, flags);
1917 return;
1918 }
1919 info->flags |= ZILOG_CLOSING;
1920 /*
1921 * Now we wait for the transmit buffer to clear; and we notify
1922 * the line discipline to only process XON/XOFF characters.
1923 */
1924 OPNDBG("waiting end of Tx... (timeout:%d)\n", info->closing_wait);
1925 tty->closing = 1;
1926 if (info->closing_wait != ZILOG_CLOSING_WAIT_NONE) {
1927 spin_unlock_irqrestore(&info->lock, flags);
1928 tty_wait_until_sent(tty, info->closing_wait);
1929 spin_lock_irqsave(&info->lock, flags);
1930 }
1931
1932 /*
1933 * At this point we stop accepting input. To do this, we
1934 * disable the receiver and receive interrupts.
1935 */
1936 info->curregs[3] &= ~RxENABLE;
1937 info->pendregs[3] = info->curregs[3];
1938 write_zsreg(info->zs_channel, 3, info->curregs[3]);
1939 info->curregs[1] &= ~(0x18); /* disable any rx ints */
1940 info->pendregs[1] = info->curregs[1];
1941 write_zsreg(info->zs_channel, 1, info->curregs[1]);
1942 ZS_CLEARFIFO(info->zs_channel);
1943 if (info->flags & ZILOG_INITIALIZED) {
1944 /*
1945 * Before we drop DTR, make sure the SCC transmitter
1946 * has completely drained.
1947 */
1948 OPNDBG("waiting end of Rx...\n");
1949 spin_unlock_irqrestore(&info->lock, flags);
1950 rs_wait_until_sent(tty, info->timeout);
1951 spin_lock_irqsave(&info->lock, flags);
1952 }
1953
1954 shutdown(info);
1955 /* restore flags now since shutdown() will have disabled this port's
1956 specific irqs */
1957 spin_unlock_irqrestore(&info->lock, flags);
1958
1959 if (tty->driver->flush_buffer)
1960 tty->driver->flush_buffer(tty);
1961 tty_ldisc_flush(tty);
1962 tty->closing = 0;
1963 info->event = 0;
1964 info->tty = 0;
1965
1966 if (info->blocked_open) {
1967 if (info->close_delay) {
1968 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1969 }
1970 wake_up_interruptible(&info->open_wait);
1971 }
1972 info->flags &= ~(ZILOG_NORMAL_ACTIVE|ZILOG_CLOSING);
1973 wake_up_interruptible(&info->close_wait);
1974}
1975
1976/*
1977 * rs_wait_until_sent() --- wait until the transmitter is empty
1978 */
1979static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1980{
1981 struct mac_serial *info = (struct mac_serial *) tty->driver_data;
1982 unsigned long orig_jiffies, char_time;
1983
1984 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
1985 return;
1986
1987/* printk("rs_wait_until_sent, timeout:%d, tty_stopped:%d, tx_stopped:%d\n",
1988 timeout, tty->stopped, info->tx_stopped);
1989*/
1990 orig_jiffies = jiffies;
1991 /*
1992 * Set the check interval to be 1/5 of the estimated time to
1993 * send a single character, and make it at least 1. The check
1994 * interval should also be less than the timeout.
1995 */
1996 if (info->timeout <= HZ/50) {
1997 printk(KERN_INFO "macserial: invalid info->timeout=%d\n",
1998 info->timeout);
1999 info->timeout = HZ/50+1;
2000 }
2001
2002 char_time = (info->timeout - HZ/50) / info->xmit_fifo_size;
2003 char_time = char_time / 5;
2004 if (char_time > HZ) {
2005 printk(KERN_WARNING "macserial: char_time %ld >HZ !!!\n",
2006 char_time);
2007 char_time = 1;
2008 } else if (char_time == 0)
2009 char_time = 1;
2010 if (timeout)
2011 char_time = min_t(unsigned long, char_time, timeout);
2012 while ((read_zsreg(info->zs_channel, 1) & ALL_SNT) == 0) {
2013 msleep_interruptible(jiffies_to_msecs(char_time));
2014 if (signal_pending(current))
2015 break;
2016 if (timeout && time_after(jiffies, orig_jiffies + timeout))
2017 break;
2018 }
2019 current->state = TASK_RUNNING;
2020}
2021
2022/*
2023 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
2024 */
2025static void rs_hangup(struct tty_struct *tty)
2026{
2027 struct mac_serial * info = (struct mac_serial *)tty->driver_data;
2028
2029 if (serial_paranoia_check(info, tty->name, "rs_hangup"))
2030 return;
2031
2032 rs_flush_buffer(tty);
2033 shutdown(info);
2034 info->event = 0;
2035 info->count = 0;
2036 info->flags &= ~ZILOG_NORMAL_ACTIVE;
2037 info->tty = 0;
2038 wake_up_interruptible(&info->open_wait);
2039}
2040
2041/*
2042 * ------------------------------------------------------------
2043 * rs_open() and friends
2044 * ------------------------------------------------------------
2045 */
2046static int block_til_ready(struct tty_struct *tty, struct file * filp,
2047 struct mac_serial *info)
2048{
2049 DECLARE_WAITQUEUE(wait,current);
2050 int retval;
2051 int do_clocal = 0;
2052
2053 /*
2054 * If the device is in the middle of being closed, then block
2055 * until it's done, and then try again.
2056 */
2057 if (info->flags & ZILOG_CLOSING) {
2058 interruptible_sleep_on(&info->close_wait);
2059 return -EAGAIN;
2060 }
2061
2062 /*
2063 * If non-blocking mode is set, or the port is not enabled,
2064 * then make the check up front and then exit.
2065 */
2066 if ((filp->f_flags & O_NONBLOCK) ||
2067 (tty->flags & (1 << TTY_IO_ERROR))) {
2068 info->flags |= ZILOG_NORMAL_ACTIVE;
2069 return 0;
2070 }
2071
2072 if (tty->termios->c_cflag & CLOCAL)
2073 do_clocal = 1;
2074
2075 /*
2076 * Block waiting for the carrier detect and the line to become
2077 * free (i.e., not in use by the callout). While we are in
2078 * this loop, info->count is dropped by one, so that
2079 * rs_close() knows when to free things. We restore it upon
2080 * exit, either normal or abnormal.
2081 */
2082 retval = 0;
2083 add_wait_queue(&info->open_wait, &wait);
2084 OPNDBG("block_til_ready before block: ttyS%d, count = %d\n",
2085 info->line, info->count);
2086 spin_lock_irq(&info->lock);
2087 if (!tty_hung_up_p(filp))
2088 info->count--;
2089 spin_unlock_irq(&info->lock);
2090 info->blocked_open++;
2091 while (1) {
2092 spin_lock_irq(&info->lock);
2093 if ((tty->termios->c_cflag & CBAUD) &&
2094 !info->is_irda)
2095 zs_rtsdtr(info, 1);
2096 spin_unlock_irq(&info->lock);
2097 set_current_state(TASK_INTERRUPTIBLE);
2098 if (tty_hung_up_p(filp) ||
2099 !(info->flags & ZILOG_INITIALIZED)) {
2100 retval = -EAGAIN;
2101 break;
2102 }
2103 if (!(info->flags & ZILOG_CLOSING) &&
2104 (do_clocal || (read_zsreg(info->zs_channel, 0) & DCD)))
2105 break;
2106 if (signal_pending(current)) {
2107 retval = -ERESTARTSYS;
2108 break;
2109 }
2110 OPNDBG("block_til_ready blocking: ttyS%d, count = %d\n",
2111 info->line, info->count);
2112 schedule();
2113 }
2114 current->state = TASK_RUNNING;
2115 remove_wait_queue(&info->open_wait, &wait);
2116 if (!tty_hung_up_p(filp))
2117 info->count++;
2118 info->blocked_open--;
2119 OPNDBG("block_til_ready after blocking: ttyS%d, count = %d\n",
2120 info->line, info->count);
2121 if (retval)
2122 return retval;
2123 info->flags |= ZILOG_NORMAL_ACTIVE;
2124 return 0;
2125}
2126
2127/*
2128 * This routine is called whenever a serial port is opened. It
2129 * enables interrupts for a serial port, linking in its ZILOG structure into
2130 * the IRQ chain. It also performs the serial-specific
2131 * initialization for the tty structure.
2132 */
2133static int rs_open(struct tty_struct *tty, struct file * filp)
2134{
2135 struct mac_serial *info;
2136 int retval, line;
2137 unsigned long page;
2138
2139 line = tty->index;
2140 if ((line < 0) || (line >= zs_channels_found)) {
2141 return -ENODEV;
2142 }
2143 info = zs_soft + line;
2144
2145#ifdef CONFIG_KGDB
2146 if (info->kgdb_channel) {
2147 return -ENODEV;
2148 }
2149#endif
2150 if (serial_paranoia_check(info, tty->name, "rs_open"))
2151 return -ENODEV;
2152 OPNDBG("rs_open %s, count = %d, tty=%p\n", tty->name,
2153 info->count, tty);
2154
2155 info->count++;
2156 tty->driver_data = info;
2157 info->tty = tty;
2158
2159 if (!tmp_buf) {
2160 page = get_zeroed_page(GFP_KERNEL);
2161 if (!page)
2162 return -ENOMEM;
2163 if (tmp_buf)
2164 free_page(page);
2165 else
2166 tmp_buf = (unsigned char *) page;
2167 }
2168
2169 /*
2170 * If the port is the middle of closing, bail out now
2171 */
2172 if (tty_hung_up_p(filp) ||
2173 (info->flags & ZILOG_CLOSING)) {
2174 if (info->flags & ZILOG_CLOSING)
2175 interruptible_sleep_on(&info->close_wait);
2176 return -EAGAIN;
2177 }
2178
2179 /*
2180 * Start up serial port
2181 */
2182
2183 retval = startup(info);
2184 if (retval)
2185 return retval;
2186
2187 retval = block_til_ready(tty, filp, info);
2188 if (retval) {
2189 OPNDBG("rs_open returning after block_til_ready with %d\n",
2190 retval);
2191 return retval;
2192 }
2193
2194#ifdef CONFIG_SERIAL_CONSOLE
2195 if (sercons.cflag && sercons.index == line) {
2196 tty->termios->c_cflag = sercons.cflag;
2197 sercons.cflag = 0;
2198 change_speed(info, 0);
2199 }
2200#endif
2201
2202 OPNDBG("rs_open %s successful...\n", tty->name);
2203 return 0;
2204}
2205
2206/* Finally, routines used to initialize the serial driver. */
2207
2208static void show_serial_version(void)
2209{
2210 printk(KERN_INFO "PowerMac Z8530 serial driver version " MACSERIAL_VERSION "\n");
2211}
2212
2213/*
2214 * Initialize one channel, both the mac_serial and mac_zschannel
2215 * structs. We use the dev_node field of the mac_serial struct.
2216 */
2217static int
2218chan_init(struct mac_serial *zss, struct mac_zschannel *zs_chan,
2219 struct mac_zschannel *zs_chan_a)
2220{
2221 struct device_node *ch = zss->dev_node;
2222 char *conn;
2223 int len;
2224 struct slot_names_prop {
2225 int count;
2226 char name[1];
2227 } *slots;
2228
2229 zss->irq = ch->intrs[0].line;
2230 zss->has_dma = 0;
2231#if !defined(CONFIG_KGDB) && defined(SUPPORT_SERIAL_DMA)
2232 if (ch->n_addrs >= 3 && ch->n_intrs == 3)
2233 zss->has_dma = 1;
2234#endif
2235 zss->dma_initted = 0;
2236
2237 zs_chan->control = (volatile unsigned char *)
2238 ioremap(ch->addrs[0].address, 0x1000);
2239 zs_chan->data = zs_chan->control + 0x10;
2240 spin_lock_init(&zs_chan->lock);
2241 zs_chan->parent = zss;
2242 zss->zs_channel = zs_chan;
2243 zss->zs_chan_a = zs_chan_a;
2244
2245 /* setup misc varariables */
2246 zss->kgdb_channel = 0;
2247
2248 /* For now, we assume you either have a slot-names property
2249 * with "Modem" in it, or your channel is compatible with
2250 * "cobalt". Might need additional fixups
2251 */
2252 zss->is_internal_modem = device_is_compatible(ch, "cobalt");
2253 conn = get_property(ch, "AAPL,connector", &len);
2254 zss->is_irda = conn && (strcmp(conn, "infrared") == 0);
2255 zss->port_type = PMAC_SCC_ASYNC;
2256 /* 1999 Powerbook G3 has slot-names property instead */
2257 slots = (struct slot_names_prop *)get_property(ch, "slot-names", &len);
2258 if (slots && slots->count > 0) {
2259 if (strcmp(slots->name, "IrDA") == 0)
2260 zss->is_irda = 1;
2261 else if (strcmp(slots->name, "Modem") == 0)
2262 zss->is_internal_modem = 1;
2263 }
2264 if (zss->is_irda)
2265 zss->port_type = PMAC_SCC_IRDA;
2266 if (zss->is_internal_modem) {
2267 struct device_node* i2c_modem = find_devices("i2c-modem");
2268 if (i2c_modem) {
2269 char* mid = get_property(i2c_modem, "modem-id", NULL);
2270 if (mid) switch(*mid) {
2271 case 0x04 :
2272 case 0x05 :
2273 case 0x07 :
2274 case 0x08 :
2275 case 0x0b :
2276 case 0x0c :
2277 zss->port_type = PMAC_SCC_I2S1;
2278 }
2279 printk(KERN_INFO "macserial: i2c-modem detected, id: %d\n",
2280 mid ? (*mid) : 0);
2281 } else {
2282 printk(KERN_INFO "macserial: serial modem detected\n");
2283 }
2284 }
2285
2286 while (zss->has_dma) {
2287 zss->dma_priv = NULL;
2288 /* it seems that the last two addresses are the
2289 DMA controllers */
2290 zss->tx_dma = (volatile struct dbdma_regs *)
2291 ioremap(ch->addrs[ch->n_addrs - 2].address, 0x100);
2292 zss->rx = (volatile struct mac_dma *)
2293 ioremap(ch->addrs[ch->n_addrs - 1].address, 0x100);
2294 zss->tx_dma_irq = ch->intrs[1].line;
2295 zss->rx_dma_irq = ch->intrs[2].line;
2296 spin_lock_init(&zss->rx_dma_lock);
2297 break;
2298 }
2299
2300 init_timer(&zss->powerup_timer);
2301 zss->powerup_timer.function = powerup_done;
2302 zss->powerup_timer.data = (unsigned long) zss;
2303 return 0;
2304}
2305
2306/*
2307 * /proc fs routines. TODO: Add status lines & error stats
2308 */
2309static inline int
2310line_info(char *buf, struct mac_serial *info)
2311{
2312 int ret=0;
2313 unsigned char* connector;
2314 int lenp;
2315
2316 ret += sprintf(buf, "%d: port:0x%X irq:%d", info->line, info->port, info->irq);
2317
2318 connector = get_property(info->dev_node, "AAPL,connector", &lenp);
2319 if (connector)
2320 ret+=sprintf(buf+ret," con:%s ", connector);
2321 if (info->is_internal_modem) {
2322 if (!connector)
2323 ret+=sprintf(buf+ret," con:");
2324 ret+=sprintf(buf+ret,"%s", " (internal modem)");
2325 }
2326 if (info->is_irda) {
2327 if (!connector)
2328 ret+=sprintf(buf+ret," con:");
2329 ret+=sprintf(buf+ret,"%s", " (IrDA)");
2330 }
2331 ret+=sprintf(buf+ret,"\n");
2332
2333 return ret;
2334}
2335
2336int macserial_read_proc(char *page, char **start, off_t off, int count,
2337 int *eof, void *data)
2338{
2339 int l, len = 0;
2340 off_t begin = 0;
2341 struct mac_serial *info;
2342
2343 len += sprintf(page, "serinfo:1.0 driver:" MACSERIAL_VERSION "\n");
2344 for (info = zs_chain; info && len < 4000; info = info->zs_next) {
2345 l = line_info(page + len, info);
2346 len += l;
2347 if (len+begin > off+count)
2348 goto done;
2349 if (len+begin < off) {
2350 begin += len;
2351 len = 0;
2352 }
2353 }
2354 *eof = 1;
2355done:
2356 if (off >= len+begin)
2357 return 0;
2358 *start = page + (off-begin);
2359 return ((count < begin+len-off) ? count : begin+len-off);
2360}
2361
2362/* Ask the PROM how many Z8530s we have and initialize their zs_channels */
2363static void
2364probe_sccs(void)
2365{
2366 struct device_node *dev, *ch;
2367 struct mac_serial **pp;
2368 int n, chip, nchan;
2369 struct mac_zschannel *zs_chan;
2370 int chan_a_index;
2371
2372 n = 0;
2373 pp = &zs_chain;
2374 zs_chan = zs_channels;
2375 for (dev = find_devices("escc"); dev != 0; dev = dev->next) {
2376 nchan = 0;
2377 chip = n;
2378 if (n >= NUM_CHANNELS) {
2379 printk(KERN_WARNING "Sorry, can't use %s: no more "
2380 "channels\n", dev->full_name);
2381 continue;
2382 }
2383 chan_a_index = 0;
2384 for (ch = dev->child; ch != 0; ch = ch->sibling) {
2385 if (nchan >= 2) {
2386 printk(KERN_WARNING "SCC: Only 2 channels per "
2387 "chip are supported\n");
2388 break;
2389 }
2390 if (ch->n_addrs < 1 || (ch ->n_intrs < 1)) {
2391 printk("Can't use %s: %d addrs %d intrs\n",
2392 ch->full_name, ch->n_addrs, ch->n_intrs);
2393 continue;
2394 }
2395
2396 /* The channel with the higher address
2397 will be the A side. */
2398 if (nchan > 0 &&
2399 ch->addrs[0].address
2400 > zs_soft[n-1].dev_node->addrs[0].address)
2401 chan_a_index = 1;
2402
2403 /* minimal initialization for now */
2404 zs_soft[n].dev_node = ch;
2405 *pp = &zs_soft[n];
2406 pp = &zs_soft[n].zs_next;
2407 ++nchan;
2408 ++n;
2409 }
2410 if (nchan == 0)
2411 continue;
2412
2413 /* set up A side */
2414 if (chan_init(&zs_soft[chip + chan_a_index], zs_chan, zs_chan))
2415 continue;
2416 ++zs_chan;
2417
2418 /* set up B side, if it exists */
2419 if (nchan > 1)
2420 if (chan_init(&zs_soft[chip + 1 - chan_a_index],
2421 zs_chan, zs_chan - 1))
2422 continue;
2423 ++zs_chan;
2424 }
2425 *pp = 0;
2426
2427 zs_channels_found = n;
2428#ifdef CONFIG_PMAC_PBOOK
2429 if (n)
2430 pmu_register_sleep_notifier(&serial_sleep_notifier);
2431#endif /* CONFIG_PMAC_PBOOK */
2432}
2433
2434static struct tty_operations serial_ops = {
2435 .open = rs_open,
2436 .close = rs_close,
2437 .write = rs_write,
2438 .flush_chars = rs_flush_chars,
2439 .write_room = rs_write_room,
2440 .chars_in_buffer = rs_chars_in_buffer,
2441 .flush_buffer = rs_flush_buffer,
2442 .ioctl = rs_ioctl,
2443 .throttle = rs_throttle,
2444 .unthrottle = rs_unthrottle,
2445 .set_termios = rs_set_termios,
2446 .stop = rs_stop,
2447 .start = rs_start,
2448 .hangup = rs_hangup,
2449 .break_ctl = rs_break,
2450 .wait_until_sent = rs_wait_until_sent,
2451 .read_proc = macserial_read_proc,
2452 .tiocmget = rs_tiocmget,
2453 .tiocmset = rs_tiocmset,
2454};
2455
2456static int macserial_init(void)
2457{
2458 int channel, i;
2459 struct mac_serial *info;
2460
2461 /* Find out how many Z8530 SCCs we have */
2462 if (zs_chain == 0)
2463 probe_sccs();
2464
2465 serial_driver = alloc_tty_driver(zs_channels_found);
2466 if (!serial_driver)
2467 return -ENOMEM;
2468
2469 /* XXX assume it's a powerbook if we have a via-pmu
2470 *
2471 * This is OK for core99 machines as well.
2472 */
2473 is_powerbook = find_devices("via-pmu") != 0;
2474
2475 /* Register the interrupt handler for each one
2476 * We also request the OF resources here as probe_sccs()
2477 * might be called too early for that
2478 */
2479 for (i = 0; i < zs_channels_found; ++i) {
2480 struct device_node* ch = zs_soft[i].dev_node;
2481 if (!request_OF_resource(ch, 0, NULL)) {
2482 printk(KERN_ERR "macserial: can't request IO resource !\n");
2483 put_tty_driver(serial_driver);
2484 return -ENODEV;
2485 }
2486 if (zs_soft[i].has_dma) {
2487 if (!request_OF_resource(ch, ch->n_addrs - 2, " (tx dma)")) {
2488 printk(KERN_ERR "macserial: can't request TX DMA resource !\n");
2489 zs_soft[i].has_dma = 0;
2490 goto no_dma;
2491 }
2492 if (!request_OF_resource(ch, ch->n_addrs - 1, " (rx dma)")) {
2493 release_OF_resource(ch, ch->n_addrs - 2);
2494 printk(KERN_ERR "macserial: can't request RX DMA resource !\n");
2495 zs_soft[i].has_dma = 0;
2496 goto no_dma;
2497 }
2498 if (request_irq(zs_soft[i].tx_dma_irq, rs_txdma_irq, 0,
2499 "SCC-txdma", &zs_soft[i]))
2500 printk(KERN_ERR "macserial: can't get irq %d\n",
2501 zs_soft[i].tx_dma_irq);
2502 disable_irq(zs_soft[i].tx_dma_irq);
2503 if (request_irq(zs_soft[i].rx_dma_irq, rs_rxdma_irq, 0,
2504 "SCC-rxdma", &zs_soft[i]))
2505 printk(KERN_ERR "macserial: can't get irq %d\n",
2506 zs_soft[i].rx_dma_irq);
2507 disable_irq(zs_soft[i].rx_dma_irq);
2508 }
2509no_dma:
2510 if (request_irq(zs_soft[i].irq, rs_interrupt, 0,
2511 "SCC", &zs_soft[i]))
2512 printk(KERN_ERR "macserial: can't get irq %d\n",
2513 zs_soft[i].irq);
2514 disable_irq(zs_soft[i].irq);
2515 }
2516
2517 show_serial_version();
2518
2519 /* Initialize the tty_driver structure */
2520 /* Not all of this is exactly right for us. */
2521
2522 serial_driver->owner = THIS_MODULE;
2523 serial_driver->driver_name = "macserial";
2524 serial_driver->devfs_name = "tts/";
2525 serial_driver->name = "ttyS";
2526 serial_driver->major = TTY_MAJOR;
2527 serial_driver->minor_start = 64;
2528 serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2529 serial_driver->subtype = SERIAL_TYPE_NORMAL;
2530 serial_driver->init_termios = tty_std_termios;
2531 serial_driver->init_termios.c_cflag =
2532 B38400 | CS8 | CREAD | HUPCL | CLOCAL;
2533 serial_driver->flags = TTY_DRIVER_REAL_RAW;
2534 tty_set_operations(serial_driver, &serial_ops);
2535
2536 if (tty_register_driver(serial_driver))
2537 printk(KERN_ERR "Error: couldn't register serial driver\n");
2538
2539 for (channel = 0; channel < zs_channels_found; ++channel) {
2540#ifdef CONFIG_KGDB
2541 if (zs_soft[channel].kgdb_channel) {
2542 kgdb_interruptible(1);
2543 continue;
2544 }
2545#endif
2546 zs_soft[channel].clk_divisor = 16;
2547/* -- we are not sure the SCC is powered ON at this point
2548 zs_soft[channel].zs_baud = get_zsbaud(&zs_soft[channel]);
2549*/
2550 zs_soft[channel].zs_baud = 38400;
2551
2552 /* If console serial line, then enable interrupts. */
2553 if (zs_soft[channel].is_cons) {
2554 printk(KERN_INFO "macserial: console line, enabling "
2555 "interrupt %d\n", zs_soft[channel].irq);
2556 panic("macserial: console not supported yet !");
2557 write_zsreg(zs_soft[channel].zs_channel, R1,
2558 (EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB));
2559 write_zsreg(zs_soft[channel].zs_channel, R9,
2560 (NV | MIE));
2561 }
2562 }
2563
2564 for (info = zs_chain, i = 0; info; info = info->zs_next, i++)
2565 {
2566 unsigned char* connector;
2567 int lenp;
2568
2569#ifdef CONFIG_KGDB
2570 if (info->kgdb_channel) {
2571 continue;
2572 }
2573#endif
2574 info->magic = SERIAL_MAGIC;
2575 info->port = (int) info->zs_channel->control;
2576 info->line = i;
2577 info->tty = 0;
2578 info->custom_divisor = 16;
2579 info->timeout = 0;
2580 info->close_delay = 50;
2581 info->closing_wait = 3000;
2582 info->x_char = 0;
2583 info->event = 0;
2584 info->count = 0;
2585 info->blocked_open = 0;
2586 INIT_WORK(&info->tqueue, do_softint, info);
2587 spin_lock_init(&info->lock);
2588 init_waitqueue_head(&info->open_wait);
2589 init_waitqueue_head(&info->close_wait);
2590 info->timeout = HZ;
2591 printk(KERN_INFO "tty%02d at 0x%08x (irq = %d)", info->line,
2592 info->port, info->irq);
2593 printk(" is a Z8530 ESCC");
2594 connector = get_property(info->dev_node, "AAPL,connector", &lenp);
2595 if (connector)
2596 printk(", port = %s", connector);
2597 if (info->is_internal_modem)
2598 printk(" (internal modem)");
2599 if (info->is_irda)
2600 printk(" (IrDA)");
2601 printk("\n");
2602 }
2603 tmp_buf = 0;
2604
2605 return 0;
2606}
2607
2608void macserial_cleanup(void)
2609{
2610 int i;
2611 unsigned long flags;
2612 struct mac_serial *info;
2613
2614 for (info = zs_chain, i = 0; info; info = info->zs_next, i++)
2615 set_scc_power(info, 0);
2616 spin_lock_irqsave(&info->lock, flags);
2617 for (i = 0; i < zs_channels_found; ++i) {
2618 free_irq(zs_soft[i].irq, &zs_soft[i]);
2619 if (zs_soft[i].has_dma) {
2620 free_irq(zs_soft[i].tx_dma_irq, &zs_soft[i]);
2621 free_irq(zs_soft[i].rx_dma_irq, &zs_soft[i]);
2622 }
2623 release_OF_resource(zs_soft[i].dev_node, 0);
2624 if (zs_soft[i].has_dma) {
2625 struct device_node* ch = zs_soft[i].dev_node;
2626 release_OF_resource(ch, ch->n_addrs - 2);
2627 release_OF_resource(ch, ch->n_addrs - 1);
2628 }
2629 }
2630 spin_unlock_irqrestore(&info->lock, flags);
2631 tty_unregister_driver(serial_driver);
2632 put_tty_driver(serial_driver);
2633
2634 if (tmp_buf) {
2635 free_page((unsigned long) tmp_buf);
2636 tmp_buf = 0;
2637 }
2638
2639#ifdef CONFIG_PMAC_PBOOK
2640 if (zs_channels_found)
2641 pmu_unregister_sleep_notifier(&serial_sleep_notifier);
2642#endif /* CONFIG_PMAC_PBOOK */
2643}
2644
2645module_init(macserial_init);
2646module_exit(macserial_cleanup);
2647MODULE_LICENSE("GPL");
2648
2649#if 0
2650/*
2651 * register_serial and unregister_serial allows for serial ports to be
2652 * configured at run-time, to support PCMCIA modems.
2653 */
2654/* PowerMac: Unused at this time, just here to make things link. */
2655int register_serial(struct serial_struct *req)
2656{
2657 return -1;
2658}
2659
2660void unregister_serial(int line)
2661{
2662 return;
2663}
2664#endif
2665
2666/*
2667 * ------------------------------------------------------------
2668 * Serial console driver
2669 * ------------------------------------------------------------
2670 */
2671#ifdef CONFIG_SERIAL_CONSOLE
2672
2673/*
2674 * Print a string to the serial port trying not to disturb
2675 * any possible real use of the port...
2676 */
2677static void serial_console_write(struct console *co, const char *s,
2678 unsigned count)
2679{
2680 struct mac_serial *info = zs_soft + co->index;
2681 int i;
2682
2683 /* Turn of interrupts and enable the transmitter. */
2684 write_zsreg(info->zs_channel, R1, info->curregs[1] & ~TxINT_ENAB);
2685 write_zsreg(info->zs_channel, R5, info->curregs[5] | TxENAB | RTS | DTR);
2686
2687 for (i=0; i<count; i++) {
2688 /* Wait for the transmit buffer to empty. */
2689 while ((read_zsreg(info->zs_channel, 0) & Tx_BUF_EMP) == 0) {
2690 eieio();
2691 }
2692
2693 write_zsdata(info->zs_channel, s[i]);
2694 if (s[i] == 10) {
2695 while ((read_zsreg(info->zs_channel, 0) & Tx_BUF_EMP)
2696 == 0)
2697 eieio();
2698
2699 write_zsdata(info->zs_channel, 13);
2700 }
2701 }
2702
2703 /* Restore the values in the registers. */
2704 write_zsreg(info->zs_channel, R1, info->curregs[1]);
2705 /* Don't disable the transmitter. */
2706}
2707
2708static struct tty_driver *serial_driver;
2709
2710static struct tty_driver *serial_console_device(struct console *c, int *index)
2711{
2712 *index = c->index;
2713 return serial_driver;
2714}
2715
2716/*
2717 * Setup initial baud/bits/parity. We do two things here:
2718 * - construct a cflag setting for the first rs_open()
2719 * - initialize the serial port
2720 * Return non-zero if we didn't find a serial port.
2721 */
2722static int __init serial_console_setup(struct console *co, char *options)
2723{
2724 struct mac_serial *info;
2725 int baud = 38400;
2726 int bits = 8;
2727 int parity = 'n';
2728 int cflag = CREAD | HUPCL | CLOCAL;
2729 int brg;
2730 char *s;
2731 long flags;
2732
2733 /* Find out how many Z8530 SCCs we have */
2734 if (zs_chain == 0)
2735 probe_sccs();
2736
2737 if (zs_chain == 0)
2738 return -1;
2739
2740 /* Do we have the device asked for? */
2741 if (co->index >= zs_channels_found)
2742 return -1;
2743 info = zs_soft + co->index;
2744
2745 set_scc_power(info, 1);
2746
2747 /* Reset the channel */
2748 write_zsreg(info->zs_channel, R9, CHRA);
2749
2750 if (options) {
2751 baud = simple_strtoul(options, NULL, 10);
2752 s = options;
2753 while(*s >= '0' && *s <= '9')
2754 s++;
2755 if (*s)
2756 parity = *s++;
2757 if (*s)
2758 bits = *s - '0';
2759 }
2760
2761 /*
2762 * Now construct a cflag setting.
2763 */
2764 switch(baud) {
2765 case 1200:
2766 cflag |= B1200;
2767 break;
2768 case 2400:
2769 cflag |= B2400;
2770 break;
2771 case 4800:
2772 cflag |= B4800;
2773 break;
2774 case 9600:
2775 cflag |= B9600;
2776 break;
2777 case 19200:
2778 cflag |= B19200;
2779 break;
2780 case 57600:
2781 cflag |= B57600;
2782 break;
2783 case 115200:
2784 cflag |= B115200;
2785 break;
2786 case 38400:
2787 default:
2788 cflag |= B38400;
2789 break;
2790 }
2791 switch(bits) {
2792 case 7:
2793 cflag |= CS7;
2794 break;
2795 default:
2796 case 8:
2797 cflag |= CS8;
2798 break;
2799 }
2800 switch(parity) {
2801 case 'o': case 'O':
2802 cflag |= PARENB | PARODD;
2803 break;
2804 case 'e': case 'E':
2805 cflag |= PARENB;
2806 break;
2807 }
2808 co->cflag = cflag;
2809
2810 spin_lock_irqsave(&info->lock, flags);
2811 memset(info->curregs, 0, sizeof(info->curregs));
2812
2813 info->zs_baud = baud;
2814 info->clk_divisor = 16;
2815 switch (info->zs_baud) {
2816 case ZS_CLOCK/16: /* 230400 */
2817 info->curregs[4] = X16CLK;
2818 info->curregs[11] = 0;
2819 break;
2820 case ZS_CLOCK/32: /* 115200 */
2821 info->curregs[4] = X32CLK;
2822 info->curregs[11] = 0;
2823 break;
2824 default:
2825 info->curregs[4] = X16CLK;
2826 info->curregs[11] = TCBR | RCBR;
2827 brg = BPS_TO_BRG(info->zs_baud, ZS_CLOCK/info->clk_divisor);
2828 info->curregs[12] = (brg & 255);
2829 info->curregs[13] = ((brg >> 8) & 255);
2830 info->curregs[14] = BRENABL;
2831 }
2832
2833 /* byte size and parity */
2834 info->curregs[3] &= ~RxNBITS_MASK;
2835 info->curregs[5] &= ~TxNBITS_MASK;
2836 switch (cflag & CSIZE) {
2837 case CS5:
2838 info->curregs[3] |= Rx5;
2839 info->curregs[5] |= Tx5;
2840 break;
2841 case CS6:
2842 info->curregs[3] |= Rx6;
2843 info->curregs[5] |= Tx6;
2844 break;
2845 case CS7:
2846 info->curregs[3] |= Rx7;
2847 info->curregs[5] |= Tx7;
2848 break;
2849 case CS8:
2850 default: /* defaults to 8 bits */
2851 info->curregs[3] |= Rx8;
2852 info->curregs[5] |= Tx8;
2853 break;
2854 }
2855 info->curregs[5] |= TxENAB | RTS | DTR;
2856 info->pendregs[3] = info->curregs[3];
2857 info->pendregs[5] = info->curregs[5];
2858
2859 info->curregs[4] &= ~(SB_MASK | PAR_ENA | PAR_EVEN);
2860 if (cflag & CSTOPB) {
2861 info->curregs[4] |= SB2;
2862 } else {
2863 info->curregs[4] |= SB1;
2864 }
2865 if (cflag & PARENB) {
2866 info->curregs[4] |= PAR_ENA;
2867 if (!(cflag & PARODD)) {
2868 info->curregs[4] |= PAR_EVEN;
2869 }
2870 }
2871 info->pendregs[4] = info->curregs[4];
2872
2873 if (!(cflag & CLOCAL)) {
2874 if (!(info->curregs[15] & DCDIE))
2875 info->read_reg_zero = read_zsreg(info->zs_channel, 0);
2876 info->curregs[15] |= DCDIE;
2877 } else
2878 info->curregs[15] &= ~DCDIE;
2879 if (cflag & CRTSCTS) {
2880 info->curregs[15] |= CTSIE;
2881 if ((read_zsreg(info->zs_channel, 0) & CTS) != 0)
2882 info->tx_stopped = 1;
2883 } else {
2884 info->curregs[15] &= ~CTSIE;
2885 info->tx_stopped = 0;
2886 }
2887 info->pendregs[15] = info->curregs[15];
2888
2889 /* Load up the new values */
2890 load_zsregs(info->zs_channel, info->curregs);
2891
2892 spin_unlock_irqrestore(&info->lock, flags);
2893
2894 return 0;
2895}
2896
2897static struct console sercons = {
2898 .name = "ttyS",
2899 .write = serial_console_write,
2900 .device = serial_console_device,
2901 .setup = serial_console_setup,
2902 .flags = CON_PRINTBUFFER,
2903 .index = -1,
2904};
2905
2906/*
2907 * Register console.
2908 */
2909static void __init mac_scc_console_init(void)
2910{
2911 register_console(&sercons);
2912}
2913console_initcall(mac_scc_console_init);
2914
2915#endif /* ifdef CONFIG_SERIAL_CONSOLE */
2916
2917#ifdef CONFIG_KGDB
2918/* These are for receiving and sending characters under the kgdb
2919 * source level kernel debugger.
2920 */
2921void putDebugChar(char kgdb_char)
2922{
2923 struct mac_zschannel *chan = zs_kgdbchan;
2924 while ((read_zsreg(chan, 0) & Tx_BUF_EMP) == 0)
2925 udelay(5);
2926 write_zsdata(chan, kgdb_char);
2927}
2928
2929char getDebugChar(void)
2930{
2931 struct mac_zschannel *chan = zs_kgdbchan;
2932 while((read_zsreg(chan, 0) & Rx_CH_AV) == 0)
2933 eieio(); /*barrier();*/
2934 return read_zsdata(chan);
2935}
2936
2937void kgdb_interruptible(int yes)
2938{
2939 struct mac_zschannel *chan = zs_kgdbchan;
2940 int one, nine;
2941 nine = read_zsreg(chan, 9);
2942 if (yes == 1) {
2943 one = EXT_INT_ENAB|INT_ALL_Rx;
2944 nine |= MIE;
2945 printk("turning serial ints on\n");
2946 } else {
2947 one = RxINT_DISAB;
2948 nine &= ~MIE;
2949 printk("turning serial ints off\n");
2950 }
2951 write_zsreg(chan, 1, one);
2952 write_zsreg(chan, 9, nine);
2953}
2954
2955/* This sets up the serial port we're using, and turns on
2956 * interrupts for that channel, so kgdb is usable once we're done.
2957 */
2958static inline void kgdb_chaninit(struct mac_zschannel *ms, int intson, int bps)
2959{
2960 int brg;
2961 int i, x;
2962 volatile char *sccc = ms->control;
2963 brg = BPS_TO_BRG(bps, ZS_CLOCK/16);
2964 printk("setting bps on kgdb line to %d [brg=%x]\n", bps, brg);
2965 for (i = 20000; i != 0; --i) {
2966 x = *sccc; eieio();
2967 }
2968 for (i = 0; i < sizeof(scc_inittab); ++i) {
2969 write_zsreg(ms, scc_inittab[i], scc_inittab[i+1]);
2970 i++;
2971 }
2972}
2973
2974/* This is called at boot time to prime the kgdb serial debugging
2975 * serial line. The 'tty_num' argument is 0 for /dev/ttya and 1
2976 * for /dev/ttyb which is determined in setup_arch() from the
2977 * boot command line flags.
2978 * XXX at the moment probably only channel A will work
2979 */
2980void __init zs_kgdb_hook(int tty_num)
2981{
2982 /* Find out how many Z8530 SCCs we have */
2983 if (zs_chain == 0)
2984 probe_sccs();
2985
2986 set_scc_power(&zs_soft[tty_num], 1);
2987
2988 zs_kgdbchan = zs_soft[tty_num].zs_channel;
2989 zs_soft[tty_num].change_needed = 0;
2990 zs_soft[tty_num].clk_divisor = 16;
2991 zs_soft[tty_num].zs_baud = 38400;
2992 zs_soft[tty_num].kgdb_channel = 1; /* This runs kgdb */
2993
2994 /* Turn on transmitter/receiver at 8-bits/char */
2995 kgdb_chaninit(zs_soft[tty_num].zs_channel, 1, 38400);
2996 printk("KGDB: on channel %d initialized\n", tty_num);
2997 set_debug_traps(); /* init stub */
2998}
2999#endif /* ifdef CONFIG_KGDB */
3000
3001#ifdef CONFIG_PMAC_PBOOK
3002/*
3003 * notify clients before sleep and reset bus afterwards
3004 */
3005int
3006serial_notify_sleep(struct pmu_sleep_notifier *self, int when)
3007{
3008 int i;
3009
3010 switch (when) {
3011 case PBOOK_SLEEP_REQUEST:
3012 case PBOOK_SLEEP_REJECT:
3013 break;
3014
3015 case PBOOK_SLEEP_NOW:
3016 for (i=0; i<zs_channels_found; i++) {
3017 struct mac_serial *info = &zs_soft[i];
3018 if (info->flags & ZILOG_INITIALIZED) {
3019 shutdown(info);
3020 info->flags |= ZILOG_SLEEPING;
3021 }
3022 }
3023 break;
3024 case PBOOK_WAKE:
3025 for (i=0; i<zs_channels_found; i++) {
3026 struct mac_serial *info = &zs_soft[i];
3027 if (info->flags & ZILOG_SLEEPING) {
3028 info->flags &= ~ZILOG_SLEEPING;
3029 startup(info);
3030 }
3031 }
3032 break;
3033 }
3034 return PBOOK_SLEEP_OK;
3035}
3036#endif /* CONFIG_PMAC_PBOOK */
diff --git a/drivers/macintosh/macserial.h b/drivers/macintosh/macserial.h
deleted file mode 100644
index bade11a7a5c3..000000000000
--- a/drivers/macintosh/macserial.h
+++ /dev/null
@@ -1,461 +0,0 @@
1/*
2 * macserial.h: Definitions for the Macintosh Z8530 serial driver.
3 *
4 * Adapted from drivers/sbus/char/sunserial.h by Paul Mackerras.
5 *
6 * Copyright (C) 1996 Paul Mackerras (Paul.Mackerras@cs.anu.edu.au)
7 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
8 */
9#ifndef _MACSERIAL_H
10#define _MACSERIAL_H
11
12#include <linux/spinlock.h>
13
14#define NUM_ZSREGS 16
15
16struct serial_struct {
17 int type;
18 int line;
19 int port;
20 int irq;
21 int flags;
22 int xmit_fifo_size;
23 int custom_divisor;
24 int baud_base;
25 unsigned short close_delay;
26 char reserved_char[2];
27 int hub6;
28 unsigned short closing_wait; /* time to wait before closing */
29 unsigned short closing_wait2; /* no longer used... */
30 int reserved[4];
31};
32
33/*
34 * For the close wait times, 0 means wait forever for serial port to
35 * flush its output. 65535 means don't wait at all.
36 */
37#define ZILOG_CLOSING_WAIT_INF 0
38#define ZILOG_CLOSING_WAIT_NONE 65535
39
40/*
41 * Definitions for ZILOG_struct (and serial_struct) flags field
42 */
43#define ZILOG_HUP_NOTIFY 0x0001 /* Notify getty on hangups and closes
44 * on the callout port */
45#define ZILOG_FOURPORT 0x0002 /* Set OU1, OUT2 per AST Fourport settings */
46#define ZILOG_SAK 0x0004 /* Secure Attention Key (Orange book) */
47#define ZILOG_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */
48
49#define ZILOG_SPD_MASK 0x0030
50#define ZILOG_SPD_HI 0x0010 /* Use 56000 instead of 38400 bps */
51
52#define ZILOG_SPD_VHI 0x0020 /* Use 115200 instead of 38400 bps */
53#define ZILOG_SPD_CUST 0x0030 /* Use user-specified divisor */
54
55#define ZILOG_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */
56#define ZILOG_AUTO_IRQ 0x0080 /* Do automatic IRQ during autoconfiguration */
57#define ZILOG_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */
58#define ZILOG_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */
59#define ZILOG_CALLOUT_NOHUP 0x0400 /* Don't do hangups for cua device */
60
61#define ZILOG_FLAGS 0x0FFF /* Possible legal ZILOG flags */
62#define ZILOG_USR_MASK 0x0430 /* Legal flags that non-privileged
63 * users can set or reset */
64
65/* Internal flags used only by kernel/chr_drv/serial.c */
66#define ZILOG_INITIALIZED 0x80000000 /* Serial port was initialized */
67#define ZILOG_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */
68#define ZILOG_NORMAL_ACTIVE 0x20000000 /* Normal device is active */
69#define ZILOG_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */
70#define ZILOG_CLOSING 0x08000000 /* Serial port is closing */
71#define ZILOG_CTS_FLOW 0x04000000 /* Do CTS flow control */
72#define ZILOG_CHECK_CD 0x02000000 /* i.e., CLOCAL */
73#define ZILOG_SLEEPING 0x01000000 /* have shut it down for sleep */
74
75/* Software state per channel */
76
77#ifdef __KERNEL__
78/*
79 * This is our internal structure for each serial port's state.
80 *
81 * Many fields are paralleled by the structure used by the serial_struct
82 * structure.
83 *
84 * For definitions of the flags field, see tty.h
85 */
86
87struct mac_serial;
88
89struct mac_zschannel {
90 volatile unsigned char* control;
91 volatile unsigned char* data;
92 spinlock_t lock;
93 /* Used for debugging */
94 struct mac_serial* parent;
95};
96
97struct mac_dma {
98 volatile struct dbdma_regs dma;
99 volatile unsigned short res_count;
100 volatile unsigned short command;
101 volatile unsigned int buf_addr;
102};
103
104struct mac_serial {
105 struct mac_serial *zs_next; /* For IRQ servicing chain */
106 struct mac_zschannel *zs_channel; /* Channel registers */
107 struct mac_zschannel *zs_chan_a; /* A side registers */
108 unsigned char read_reg_zero;
109 struct device_node* dev_node;
110 spinlock_t lock;
111
112 char soft_carrier; /* Use soft carrier on this channel */
113 char break_abort; /* Is serial console in, so process brk/abrt */
114 char kgdb_channel; /* Kgdb is running on this channel */
115 char is_cons; /* Is this our console. */
116 char is_internal_modem; /* is connected to an internal modem */
117 char is_irda; /* is connected to an IrDA codec */
118 int port_type; /* Port type for pmac_feature */
119 unsigned char tx_active; /* character is being xmitted */
120 unsigned char tx_stopped; /* output is suspended */
121 unsigned char power_wait; /* waiting for power-up delay to expire */
122
123 /* We need to know the current clock divisor
124 * to read the bps rate the chip has currently
125 * loaded.
126 */
127 unsigned char clk_divisor; /* May be 1, 16, 32, or 64 */
128 int zs_baud;
129
130 /* Current write register values */
131 unsigned char curregs[NUM_ZSREGS];
132
133 /* Values we need to set next opportunity */
134 unsigned char pendregs[NUM_ZSREGS];
135
136 char change_needed;
137
138 int magic;
139 int baud_base;
140 int port;
141 int irq;
142 int flags; /* defined in tty.h */
143 int type; /* UART type */
144 struct tty_struct *tty;
145 int read_status_mask;
146 int ignore_status_mask;
147 int timeout;
148 int xmit_fifo_size;
149 int custom_divisor;
150 int x_char; /* xon/xoff character */
151 int close_delay;
152 unsigned short closing_wait;
153 unsigned short closing_wait2;
154 unsigned long event;
155 unsigned long last_active;
156 int line;
157 int count; /* # of fd on device */
158 int blocked_open; /* # of blocked opens */
159 unsigned char *xmit_buf;
160 int xmit_head;
161 int xmit_tail;
162 int xmit_cnt;
163 struct work_struct tqueue;
164 wait_queue_head_t open_wait;
165 wait_queue_head_t close_wait;
166
167 volatile struct dbdma_regs *tx_dma;
168 int tx_dma_irq;
169 volatile struct dbdma_cmd *tx_cmds;
170 volatile struct mac_dma *rx;
171 int rx_dma_irq;
172 volatile struct dbdma_cmd **rx_cmds;
173 unsigned char **rx_char_buf;
174 unsigned char **rx_flag_buf;
175#define RX_BUF_SIZE 256
176 int rx_nbuf;
177 int rx_done_bytes;
178 int rx_ubuf;
179 int rx_fbuf;
180#define RX_NO_FBUF (-1)
181 int rx_cbuf;
182 spinlock_t rx_dma_lock;
183 int has_dma;
184 int dma_initted;
185 void *dma_priv;
186 struct timer_list poll_dma_timer;
187#define RX_DMA_TIMER (jiffies + 10*HZ/1000)
188
189 struct timer_list powerup_timer;
190};
191
192
193#define SERIAL_MAGIC 0x5301
194
195/*
196 * The size of the serial xmit buffer is 1 page, or 4096 bytes
197 */
198#define SERIAL_XMIT_SIZE 4096
199
200/*
201 * Events are used to schedule things to happen at timer-interrupt
202 * time, instead of at rs interrupt time.
203 */
204#define RS_EVENT_WRITE_WAKEUP 0
205
206#endif /* __KERNEL__ */
207
208/* Conversion routines to/from brg time constants from/to bits
209 * per second.
210 */
211#define BRG_TO_BPS(brg, freq) ((freq) / 2 / ((brg) + 2))
212#define BPS_TO_BRG(bps, freq) ((((freq) + (bps)) / (2 * (bps))) - 2)
213
214/* The Zilog register set */
215
216#define FLAG 0x7e
217
218/* Write Register 0 */
219#define R0 0 /* Register selects */
220#define R1 1
221#define R2 2
222#define R3 3
223#define R4 4
224#define R5 5
225#define R6 6
226#define R7 7
227#define R8 8
228#define R9 9
229#define R10 10
230#define R11 11
231#define R12 12
232#define R13 13
233#define R14 14
234#define R15 15
235
236#define NULLCODE 0 /* Null Code */
237#define POINT_HIGH 0x8 /* Select upper half of registers */
238#define RES_EXT_INT 0x10 /* Reset Ext. Status Interrupts */
239#define SEND_ABORT 0x18 /* HDLC Abort */
240#define RES_RxINT_FC 0x20 /* Reset RxINT on First Character */
241#define RES_Tx_P 0x28 /* Reset TxINT Pending */
242#define ERR_RES 0x30 /* Error Reset */
243#define RES_H_IUS 0x38 /* Reset highest IUS */
244
245#define RES_Rx_CRC 0x40 /* Reset Rx CRC Checker */
246#define RES_Tx_CRC 0x80 /* Reset Tx CRC Checker */
247#define RES_EOM_L 0xC0 /* Reset EOM latch */
248
249/* Write Register 1 */
250
251#define EXT_INT_ENAB 0x1 /* Ext Int Enable */
252#define TxINT_ENAB 0x2 /* Tx Int Enable */
253#define PAR_SPEC 0x4 /* Parity is special condition */
254
255#define RxINT_DISAB 0 /* Rx Int Disable */
256#define RxINT_FCERR 0x8 /* Rx Int on First Character Only or Error */
257#define INT_ALL_Rx 0x10 /* Int on all Rx Characters or error */
258#define INT_ERR_Rx 0x18 /* Int on error only */
259
260#define WT_RDY_RT 0x20 /* W/Req reflects recv if 1, xmit if 0 */
261#define WT_FN_RDYFN 0x40 /* W/Req pin is DMA request if 1, wait if 0 */
262#define WT_RDY_ENAB 0x80 /* Enable W/Req pin */
263
264/* Write Register #2 (Interrupt Vector) */
265
266/* Write Register 3 */
267
268#define RxENABLE 0x1 /* Rx Enable */
269#define SYNC_L_INH 0x2 /* Sync Character Load Inhibit */
270#define ADD_SM 0x4 /* Address Search Mode (SDLC) */
271#define RxCRC_ENAB 0x8 /* Rx CRC Enable */
272#define ENT_HM 0x10 /* Enter Hunt Mode */
273#define AUTO_ENAB 0x20 /* Auto Enables */
274#define Rx5 0x0 /* Rx 5 Bits/Character */
275#define Rx7 0x40 /* Rx 7 Bits/Character */
276#define Rx6 0x80 /* Rx 6 Bits/Character */
277#define Rx8 0xc0 /* Rx 8 Bits/Character */
278#define RxNBITS_MASK 0xc0
279
280/* Write Register 4 */
281
282#define PAR_ENA 0x1 /* Parity Enable */
283#define PAR_EVEN 0x2 /* Parity Even/Odd* */
284
285#define SYNC_ENAB 0 /* Sync Modes Enable */
286#define SB1 0x4 /* 1 stop bit/char */
287#define SB15 0x8 /* 1.5 stop bits/char */
288#define SB2 0xc /* 2 stop bits/char */
289#define SB_MASK 0xc
290
291#define MONSYNC 0 /* 8 Bit Sync character */
292#define BISYNC 0x10 /* 16 bit sync character */
293#define SDLC 0x20 /* SDLC Mode (01111110 Sync Flag) */
294#define EXTSYNC 0x30 /* External Sync Mode */
295
296#define X1CLK 0x0 /* x1 clock mode */
297#define X16CLK 0x40 /* x16 clock mode */
298#define X32CLK 0x80 /* x32 clock mode */
299#define X64CLK 0xC0 /* x64 clock mode */
300#define XCLK_MASK 0xC0
301
302/* Write Register 5 */
303
304#define TxCRC_ENAB 0x1 /* Tx CRC Enable */
305#define RTS 0x2 /* RTS */
306#define SDLC_CRC 0x4 /* SDLC/CRC-16 */
307#define TxENAB 0x8 /* Tx Enable */
308#define SND_BRK 0x10 /* Send Break */
309#define Tx5 0x0 /* Tx 5 bits (or less)/character */
310#define Tx7 0x20 /* Tx 7 bits/character */
311#define Tx6 0x40 /* Tx 6 bits/character */
312#define Tx8 0x60 /* Tx 8 bits/character */
313#define TxNBITS_MASK 0x60
314#define DTR 0x80 /* DTR */
315
316/* Write Register 6 (Sync bits 0-7/SDLC Address Field) */
317
318/* Write Register 7 (Sync bits 8-15/SDLC 01111110) */
319
320/* Write Register 7' (Some enhanced feature control) */
321#define ENEXREAD 0x40 /* Enable read of some write registers */
322
323/* Write Register 8 (transmit buffer) */
324
325/* Write Register 9 (Master interrupt control) */
326#define VIS 1 /* Vector Includes Status */
327#define NV 2 /* No Vector */
328#define DLC 4 /* Disable Lower Chain */
329#define MIE 8 /* Master Interrupt Enable */
330#define STATHI 0x10 /* Status high */
331#define NORESET 0 /* No reset on write to R9 */
332#define CHRB 0x40 /* Reset channel B */
333#define CHRA 0x80 /* Reset channel A */
334#define FHWRES 0xc0 /* Force hardware reset */
335
336/* Write Register 10 (misc control bits) */
337#define BIT6 1 /* 6 bit/8bit sync */
338#define LOOPMODE 2 /* SDLC Loop mode */
339#define ABUNDER 4 /* Abort/flag on SDLC xmit underrun */
340#define MARKIDLE 8 /* Mark/flag on idle */
341#define GAOP 0x10 /* Go active on poll */
342#define NRZ 0 /* NRZ mode */
343#define NRZI 0x20 /* NRZI mode */
344#define FM1 0x40 /* FM1 (transition = 1) */
345#define FM0 0x60 /* FM0 (transition = 0) */
346#define CRCPS 0x80 /* CRC Preset I/O */
347
348/* Write Register 11 (Clock Mode control) */
349#define TRxCXT 0 /* TRxC = Xtal output */
350#define TRxCTC 1 /* TRxC = Transmit clock */
351#define TRxCBR 2 /* TRxC = BR Generator Output */
352#define TRxCDP 3 /* TRxC = DPLL output */
353#define TRxCOI 4 /* TRxC O/I */
354#define TCRTxCP 0 /* Transmit clock = RTxC pin */
355#define TCTRxCP 8 /* Transmit clock = TRxC pin */
356#define TCBR 0x10 /* Transmit clock = BR Generator output */
357#define TCDPLL 0x18 /* Transmit clock = DPLL output */
358#define RCRTxCP 0 /* Receive clock = RTxC pin */
359#define RCTRxCP 0x20 /* Receive clock = TRxC pin */
360#define RCBR 0x40 /* Receive clock = BR Generator output */
361#define RCDPLL 0x60 /* Receive clock = DPLL output */
362#define RTxCX 0x80 /* RTxC Xtal/No Xtal */
363
364/* Write Register 12 (lower byte of baud rate generator time constant) */
365
366/* Write Register 13 (upper byte of baud rate generator time constant) */
367
368/* Write Register 14 (Misc control bits) */
369#define BRENABL 1 /* Baud rate generator enable */
370#define BRSRC 2 /* Baud rate generator source */
371#define DTRREQ 4 /* DTR/Request function */
372#define AUTOECHO 8 /* Auto Echo */
373#define LOOPBAK 0x10 /* Local loopback */
374#define SEARCH 0x20 /* Enter search mode */
375#define RMC 0x40 /* Reset missing clock */
376#define DISDPLL 0x60 /* Disable DPLL */
377#define SSBR 0x80 /* Set DPLL source = BR generator */
378#define SSRTxC 0xa0 /* Set DPLL source = RTxC */
379#define SFMM 0xc0 /* Set FM mode */
380#define SNRZI 0xe0 /* Set NRZI mode */
381
382/* Write Register 15 (external/status interrupt control) */
383#define EN85C30 1 /* Enable some 85c30-enhanced registers */
384#define ZCIE 2 /* Zero count IE */
385#define ENSTFIFO 4 /* Enable status FIFO (SDLC) */
386#define DCDIE 8 /* DCD IE */
387#define SYNCIE 0x10 /* Sync/hunt IE */
388#define CTSIE 0x20 /* CTS IE */
389#define TxUIE 0x40 /* Tx Underrun/EOM IE */
390#define BRKIE 0x80 /* Break/Abort IE */
391
392
393/* Read Register 0 */
394#define Rx_CH_AV 0x1 /* Rx Character Available */
395#define ZCOUNT 0x2 /* Zero count */
396#define Tx_BUF_EMP 0x4 /* Tx Buffer empty */
397#define DCD 0x8 /* DCD */
398#define SYNC_HUNT 0x10 /* Sync/hunt */
399#define CTS 0x20 /* CTS */
400#define TxEOM 0x40 /* Tx underrun */
401#define BRK_ABRT 0x80 /* Break/Abort */
402
403/* Read Register 1 */
404#define ALL_SNT 0x1 /* All sent */
405/* Residue Data for 8 Rx bits/char programmed */
406#define RES3 0x8 /* 0/3 */
407#define RES4 0x4 /* 0/4 */
408#define RES5 0xc /* 0/5 */
409#define RES6 0x2 /* 0/6 */
410#define RES7 0xa /* 0/7 */
411#define RES8 0x6 /* 0/8 */
412#define RES18 0xe /* 1/8 */
413#define RES28 0x0 /* 2/8 */
414/* Special Rx Condition Interrupts */
415#define PAR_ERR 0x10 /* Parity error */
416#define Rx_OVR 0x20 /* Rx Overrun Error */
417#define FRM_ERR 0x40 /* CRC/Framing Error */
418#define END_FR 0x80 /* End of Frame (SDLC) */
419
420/* Read Register 2 (channel b only) - Interrupt vector */
421#define CHB_Tx_EMPTY 0x00
422#define CHB_EXT_STAT 0x02
423#define CHB_Rx_AVAIL 0x04
424#define CHB_SPECIAL 0x06
425#define CHA_Tx_EMPTY 0x08
426#define CHA_EXT_STAT 0x0a
427#define CHA_Rx_AVAIL 0x0c
428#define CHA_SPECIAL 0x0e
429#define STATUS_MASK 0x06
430
431/* Read Register 3 (interrupt pending register) ch a only */
432#define CHBEXT 0x1 /* Channel B Ext/Stat IP */
433#define CHBTxIP 0x2 /* Channel B Tx IP */
434#define CHBRxIP 0x4 /* Channel B Rx IP */
435#define CHAEXT 0x8 /* Channel A Ext/Stat IP */
436#define CHATxIP 0x10 /* Channel A Tx IP */
437#define CHARxIP 0x20 /* Channel A Rx IP */
438
439/* Read Register 8 (receive data register) */
440
441/* Read Register 10 (misc status bits) */
442#define ONLOOP 2 /* On loop */
443#define LOOPSEND 0x10 /* Loop sending */
444#define CLK2MIS 0x40 /* Two clocks missing */
445#define CLK1MIS 0x80 /* One clock missing */
446
447/* Read Register 12 (lower byte of baud rate generator constant) */
448
449/* Read Register 13 (upper byte of baud rate generator constant) */
450
451/* Read Register 15 (value of WR 15) */
452
453/* Misc macros */
454#define ZS_CLEARERR(channel) (write_zsreg(channel, 0, ERR_RES))
455#define ZS_CLEARFIFO(channel) do { volatile unsigned char garbage; \
456 garbage = read_zsdata(channel); \
457 garbage = read_zsdata(channel); \
458 garbage = read_zsdata(channel); \
459 } while(0)
460
461#endif /* !(_MACSERIAL_H) */
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index b941ee220997..4a0a0ad2d03c 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -63,6 +63,10 @@
63#include <asm/backlight.h> 63#include <asm/backlight.h>
64#endif 64#endif
65 65
66#ifdef CONFIG_PPC32
67#include <asm/open_pic.h>
68#endif
69
66/* Some compile options */ 70/* Some compile options */
67#undef SUSPEND_USES_PMU 71#undef SUSPEND_USES_PMU
68#define DEBUG_SLEEP 72#define DEBUG_SLEEP
@@ -151,10 +155,10 @@ static spinlock_t pmu_lock;
151static u8 pmu_intr_mask; 155static u8 pmu_intr_mask;
152static int pmu_version; 156static int pmu_version;
153static int drop_interrupts; 157static int drop_interrupts;
154#ifdef CONFIG_PMAC_PBOOK 158#ifdef CONFIG_PM
155static int option_lid_wakeup = 1; 159static int option_lid_wakeup = 1;
156static int sleep_in_progress; 160static int sleep_in_progress;
157#endif /* CONFIG_PMAC_PBOOK */ 161#endif /* CONFIG_PM */
158static unsigned long async_req_locks; 162static unsigned long async_req_locks;
159static unsigned int pmu_irq_stats[11]; 163static unsigned int pmu_irq_stats[11];
160 164
@@ -164,7 +168,6 @@ static struct proc_dir_entry *proc_pmu_irqstats;
164static struct proc_dir_entry *proc_pmu_options; 168static struct proc_dir_entry *proc_pmu_options;
165static int option_server_mode; 169static int option_server_mode;
166 170
167#ifdef CONFIG_PMAC_PBOOK
168int pmu_battery_count; 171int pmu_battery_count;
169int pmu_cur_battery; 172int pmu_cur_battery;
170unsigned int pmu_power_flags; 173unsigned int pmu_power_flags;
@@ -172,7 +175,6 @@ struct pmu_battery_info pmu_batteries[PMU_MAX_BATTERIES];
172static int query_batt_timer = BATTERY_POLLING_COUNT; 175static int query_batt_timer = BATTERY_POLLING_COUNT;
173static struct adb_request batt_req; 176static struct adb_request batt_req;
174static struct proc_dir_entry *proc_pmu_batt[PMU_MAX_BATTERIES]; 177static struct proc_dir_entry *proc_pmu_batt[PMU_MAX_BATTERIES];
175#endif /* CONFIG_PMAC_PBOOK */
176 178
177#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) 179#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
178extern int disable_kernel_backlight; 180extern int disable_kernel_backlight;
@@ -206,11 +208,9 @@ static int proc_get_irqstats(char *page, char **start, off_t off,
206static int pmu_set_backlight_level(int level, void* data); 208static int pmu_set_backlight_level(int level, void* data);
207static int pmu_set_backlight_enable(int on, int level, void* data); 209static int pmu_set_backlight_enable(int on, int level, void* data);
208#endif /* CONFIG_PMAC_BACKLIGHT */ 210#endif /* CONFIG_PMAC_BACKLIGHT */
209#ifdef CONFIG_PMAC_PBOOK
210static void pmu_pass_intr(unsigned char *data, int len); 211static void pmu_pass_intr(unsigned char *data, int len);
211static int proc_get_batt(char *page, char **start, off_t off, 212static int proc_get_batt(char *page, char **start, off_t off,
212 int count, int *eof, void *data); 213 int count, int *eof, void *data);
213#endif /* CONFIG_PMAC_PBOOK */
214static int proc_read_options(char *page, char **start, off_t off, 214static int proc_read_options(char *page, char **start, off_t off,
215 int count, int *eof, void *data); 215 int count, int *eof, void *data);
216static int proc_write_options(struct file *file, const char __user *buffer, 216static int proc_write_options(struct file *file, const char __user *buffer,
@@ -403,8 +403,12 @@ static int __init via_pmu_start(void)
403 403
404 bright_req_1.complete = 1; 404 bright_req_1.complete = 1;
405 bright_req_2.complete = 1; 405 bright_req_2.complete = 1;
406#ifdef CONFIG_PMAC_PBOOK
407 batt_req.complete = 1; 406 batt_req.complete = 1;
407
408#ifdef CONFIG_PPC32
409 if (pmu_kind == PMU_KEYLARGO_BASED)
410 openpic_set_irq_priority(vias->intrs[0].line,
411 OPENPIC_PRIORITY_DEFAULT + 1);
408#endif 412#endif
409 413
410 if (request_irq(vias->intrs[0].line, via_pmu_interrupt, 0, "VIA-PMU", 414 if (request_irq(vias->intrs[0].line, via_pmu_interrupt, 0, "VIA-PMU",
@@ -458,7 +462,7 @@ static int __init via_pmu_dev_init(void)
458 register_backlight_controller(&pmu_backlight_controller, NULL, "pmu"); 462 register_backlight_controller(&pmu_backlight_controller, NULL, "pmu");
459#endif /* CONFIG_PMAC_BACKLIGHT */ 463#endif /* CONFIG_PMAC_BACKLIGHT */
460 464
461#ifdef CONFIG_PMAC_PBOOK 465#ifdef CONFIG_PPC32
462 if (machine_is_compatible("AAPL,3400/2400") || 466 if (machine_is_compatible("AAPL,3400/2400") ||
463 machine_is_compatible("AAPL,3500")) { 467 machine_is_compatible("AAPL,3500")) {
464 int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO, 468 int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO,
@@ -486,20 +490,19 @@ static int __init via_pmu_dev_init(void)
486 pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART; 490 pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART;
487 } 491 }
488 } 492 }
489#endif /* CONFIG_PMAC_PBOOK */ 493#endif /* CONFIG_PPC32 */
494
490 /* Create /proc/pmu */ 495 /* Create /proc/pmu */
491 proc_pmu_root = proc_mkdir("pmu", NULL); 496 proc_pmu_root = proc_mkdir("pmu", NULL);
492 if (proc_pmu_root) { 497 if (proc_pmu_root) {
493#ifdef CONFIG_PMAC_PBOOK 498 long i;
494 int i;
495 499
496 for (i=0; i<pmu_battery_count; i++) { 500 for (i=0; i<pmu_battery_count; i++) {
497 char title[16]; 501 char title[16];
498 sprintf(title, "battery_%d", i); 502 sprintf(title, "battery_%ld", i);
499 proc_pmu_batt[i] = create_proc_read_entry(title, 0, proc_pmu_root, 503 proc_pmu_batt[i] = create_proc_read_entry(title, 0, proc_pmu_root,
500 proc_get_batt, (void *)i); 504 proc_get_batt, (void *)i);
501 } 505 }
502#endif /* CONFIG_PMAC_PBOOK */
503 506
504 proc_pmu_info = create_proc_read_entry("info", 0, proc_pmu_root, 507 proc_pmu_info = create_proc_read_entry("info", 0, proc_pmu_root,
505 proc_get_info, NULL); 508 proc_get_info, NULL);
@@ -619,8 +622,6 @@ static void pmu_set_server_mode(int server_mode)
619 pmu_wait_complete(&req); 622 pmu_wait_complete(&req);
620} 623}
621 624
622#ifdef CONFIG_PMAC_PBOOK
623
624/* This new version of the code for 2400/3400/3500 powerbooks 625/* This new version of the code for 2400/3400/3500 powerbooks
625 * is inspired from the implementation in gkrellm-pmu 626 * is inspired from the implementation in gkrellm-pmu
626 */ 627 */
@@ -803,8 +804,6 @@ query_battery_state(void)
803 2, PMU_SMART_BATTERY_STATE, pmu_cur_battery+1); 804 2, PMU_SMART_BATTERY_STATE, pmu_cur_battery+1);
804} 805}
805 806
806#endif /* CONFIG_PMAC_PBOOK */
807
808static int __pmac 807static int __pmac
809proc_get_info(char *page, char **start, off_t off, 808proc_get_info(char *page, char **start, off_t off,
810 int count, int *eof, void *data) 809 int count, int *eof, void *data)
@@ -813,11 +812,9 @@ proc_get_info(char *page, char **start, off_t off,
813 812
814 p += sprintf(p, "PMU driver version : %d\n", PMU_DRIVER_VERSION); 813 p += sprintf(p, "PMU driver version : %d\n", PMU_DRIVER_VERSION);
815 p += sprintf(p, "PMU firmware version : %02x\n", pmu_version); 814 p += sprintf(p, "PMU firmware version : %02x\n", pmu_version);
816#ifdef CONFIG_PMAC_PBOOK
817 p += sprintf(p, "AC Power : %d\n", 815 p += sprintf(p, "AC Power : %d\n",
818 ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0)); 816 ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0));
819 p += sprintf(p, "Battery count : %d\n", pmu_battery_count); 817 p += sprintf(p, "Battery count : %d\n", pmu_battery_count);
820#endif /* CONFIG_PMAC_PBOOK */
821 818
822 return p - page; 819 return p - page;
823} 820}
@@ -849,12 +846,11 @@ proc_get_irqstats(char *page, char **start, off_t off,
849 return p - page; 846 return p - page;
850} 847}
851 848
852#ifdef CONFIG_PMAC_PBOOK
853static int __pmac 849static int __pmac
854proc_get_batt(char *page, char **start, off_t off, 850proc_get_batt(char *page, char **start, off_t off,
855 int count, int *eof, void *data) 851 int count, int *eof, void *data)
856{ 852{
857 int batnum = (int)data; 853 long batnum = (long)data;
858 char *p = page; 854 char *p = page;
859 855
860 p += sprintf(p, "\n"); 856 p += sprintf(p, "\n");
@@ -873,7 +869,6 @@ proc_get_batt(char *page, char **start, off_t off,
873 869
874 return p - page; 870 return p - page;
875} 871}
876#endif /* CONFIG_PMAC_PBOOK */
877 872
878static int __pmac 873static int __pmac
879proc_read_options(char *page, char **start, off_t off, 874proc_read_options(char *page, char **start, off_t off,
@@ -881,11 +876,11 @@ proc_read_options(char *page, char **start, off_t off,
881{ 876{
882 char *p = page; 877 char *p = page;
883 878
884#ifdef CONFIG_PMAC_PBOOK 879#ifdef CONFIG_PM
885 if (pmu_kind == PMU_KEYLARGO_BASED && 880 if (pmu_kind == PMU_KEYLARGO_BASED &&
886 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) 881 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0)
887 p += sprintf(p, "lid_wakeup=%d\n", option_lid_wakeup); 882 p += sprintf(p, "lid_wakeup=%d\n", option_lid_wakeup);
888#endif /* CONFIG_PMAC_PBOOK */ 883#endif
889 if (pmu_kind == PMU_KEYLARGO_BASED) 884 if (pmu_kind == PMU_KEYLARGO_BASED)
890 p += sprintf(p, "server_mode=%d\n", option_server_mode); 885 p += sprintf(p, "server_mode=%d\n", option_server_mode);
891 886
@@ -922,12 +917,12 @@ proc_write_options(struct file *file, const char __user *buffer,
922 *(val++) = 0; 917 *(val++) = 0;
923 while(*val == ' ') 918 while(*val == ' ')
924 val++; 919 val++;
925#ifdef CONFIG_PMAC_PBOOK 920#ifdef CONFIG_PM
926 if (pmu_kind == PMU_KEYLARGO_BASED && 921 if (pmu_kind == PMU_KEYLARGO_BASED &&
927 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) 922 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0)
928 if (!strcmp(label, "lid_wakeup")) 923 if (!strcmp(label, "lid_wakeup"))
929 option_lid_wakeup = ((*val) == '1'); 924 option_lid_wakeup = ((*val) == '1');
930#endif /* CONFIG_PMAC_PBOOK */ 925#endif
931 if (pmu_kind == PMU_KEYLARGO_BASED && !strcmp(label, "server_mode")) { 926 if (pmu_kind == PMU_KEYLARGO_BASED && !strcmp(label, "server_mode")) {
932 int new_value; 927 int new_value;
933 new_value = ((*val) == '1'); 928 new_value = ((*val) == '1');
@@ -1422,7 +1417,6 @@ next:
1422 } 1417 }
1423 /* Tick interrupt */ 1418 /* Tick interrupt */
1424 else if ((1 << pirq) & PMU_INT_TICK) { 1419 else if ((1 << pirq) & PMU_INT_TICK) {
1425#ifdef CONFIG_PMAC_PBOOK
1426 /* Environement or tick interrupt, query batteries */ 1420 /* Environement or tick interrupt, query batteries */
1427 if (pmu_battery_count) { 1421 if (pmu_battery_count) {
1428 if ((--query_batt_timer) == 0) { 1422 if ((--query_batt_timer) == 0) {
@@ -1437,7 +1431,6 @@ next:
1437 pmu_pass_intr(data, len); 1431 pmu_pass_intr(data, len);
1438 } else { 1432 } else {
1439 pmu_pass_intr(data, len); 1433 pmu_pass_intr(data, len);
1440#endif /* CONFIG_PMAC_PBOOK */
1441 } 1434 }
1442 goto next; 1435 goto next;
1443} 1436}
@@ -2052,7 +2045,7 @@ pmu_i2c_simple_write(int bus, int addr, u8* data, int len)
2052 return -1; 2045 return -1;
2053} 2046}
2054 2047
2055#ifdef CONFIG_PMAC_PBOOK 2048#ifdef CONFIG_PM
2056 2049
2057static LIST_HEAD(sleep_notifiers); 2050static LIST_HEAD(sleep_notifiers);
2058 2051
@@ -2705,6 +2698,8 @@ powerbook_sleep_3400(void)
2705 return 0; 2698 return 0;
2706} 2699}
2707 2700
2701#endif /* CONFIG_PM */
2702
2708/* 2703/*
2709 * Support for /dev/pmu device 2704 * Support for /dev/pmu device
2710 */ 2705 */
@@ -2884,11 +2879,11 @@ static int __pmac
2884pmu_ioctl(struct inode * inode, struct file *filp, 2879pmu_ioctl(struct inode * inode, struct file *filp,
2885 u_int cmd, u_long arg) 2880 u_int cmd, u_long arg)
2886{ 2881{
2887 struct pmu_private *pp = filp->private_data;
2888 __u32 __user *argp = (__u32 __user *)arg; 2882 __u32 __user *argp = (__u32 __user *)arg;
2889 int error; 2883 int error = -EINVAL;
2890 2884
2891 switch (cmd) { 2885 switch (cmd) {
2886#ifdef CONFIG_PM
2892 case PMU_IOC_SLEEP: 2887 case PMU_IOC_SLEEP:
2893 if (!capable(CAP_SYS_ADMIN)) 2888 if (!capable(CAP_SYS_ADMIN))
2894 return -EACCES; 2889 return -EACCES;
@@ -2910,12 +2905,13 @@ pmu_ioctl(struct inode * inode, struct file *filp,
2910 error = -ENOSYS; 2905 error = -ENOSYS;
2911 } 2906 }
2912 sleep_in_progress = 0; 2907 sleep_in_progress = 0;
2913 return error; 2908 break;
2914 case PMU_IOC_CAN_SLEEP: 2909 case PMU_IOC_CAN_SLEEP:
2915 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) < 0) 2910 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) < 0)
2916 return put_user(0, argp); 2911 return put_user(0, argp);
2917 else 2912 else
2918 return put_user(1, argp); 2913 return put_user(1, argp);
2914#endif /* CONFIG_PM */
2919 2915
2920#ifdef CONFIG_PMAC_BACKLIGHT 2916#ifdef CONFIG_PMAC_BACKLIGHT
2921 /* Backlight should have its own device or go via 2917 /* Backlight should have its own device or go via
@@ -2936,11 +2932,13 @@ pmu_ioctl(struct inode * inode, struct file *filp,
2936 error = get_user(value, argp); 2932 error = get_user(value, argp);
2937 if (!error) 2933 if (!error)
2938 error = set_backlight_level(value); 2934 error = set_backlight_level(value);
2939 return error; 2935 break;
2940 } 2936 }
2941#ifdef CONFIG_INPUT_ADBHID 2937#ifdef CONFIG_INPUT_ADBHID
2942 case PMU_IOC_GRAB_BACKLIGHT: { 2938 case PMU_IOC_GRAB_BACKLIGHT: {
2939 struct pmu_private *pp = filp->private_data;
2943 unsigned long flags; 2940 unsigned long flags;
2941
2944 if (pp->backlight_locker) 2942 if (pp->backlight_locker)
2945 return 0; 2943 return 0;
2946 pp->backlight_locker = 1; 2944 pp->backlight_locker = 1;
@@ -2956,7 +2954,7 @@ pmu_ioctl(struct inode * inode, struct file *filp,
2956 case PMU_IOC_HAS_ADB: 2954 case PMU_IOC_HAS_ADB:
2957 return put_user(pmu_has_adb, argp); 2955 return put_user(pmu_has_adb, argp);
2958 } 2956 }
2959 return -EINVAL; 2957 return error;
2960} 2958}
2961 2959
2962static struct file_operations pmu_device_fops __pmacdata = { 2960static struct file_operations pmu_device_fops __pmacdata = {
@@ -2972,14 +2970,16 @@ static struct miscdevice pmu_device __pmacdata = {
2972 PMU_MINOR, "pmu", &pmu_device_fops 2970 PMU_MINOR, "pmu", &pmu_device_fops
2973}; 2971};
2974 2972
2975void pmu_device_init(void) 2973static int pmu_device_init(void)
2976{ 2974{
2977 if (!via) 2975 if (!via)
2978 return; 2976 return 0;
2979 if (misc_register(&pmu_device) < 0) 2977 if (misc_register(&pmu_device) < 0)
2980 printk(KERN_ERR "via-pmu: cannot register misc device.\n"); 2978 printk(KERN_ERR "via-pmu: cannot register misc device.\n");
2979 return 0;
2981} 2980}
2982#endif /* CONFIG_PMAC_PBOOK */ 2981device_initcall(pmu_device_init);
2982
2983 2983
2984#ifdef DEBUG_SLEEP 2984#ifdef DEBUG_SLEEP
2985static inline void __pmac 2985static inline void __pmac
@@ -3147,12 +3147,12 @@ EXPORT_SYMBOL(pmu_i2c_combined_read);
3147EXPORT_SYMBOL(pmu_i2c_stdsub_write); 3147EXPORT_SYMBOL(pmu_i2c_stdsub_write);
3148EXPORT_SYMBOL(pmu_i2c_simple_read); 3148EXPORT_SYMBOL(pmu_i2c_simple_read);
3149EXPORT_SYMBOL(pmu_i2c_simple_write); 3149EXPORT_SYMBOL(pmu_i2c_simple_write);
3150#ifdef CONFIG_PMAC_PBOOK 3150#ifdef CONFIG_PM
3151EXPORT_SYMBOL(pmu_register_sleep_notifier); 3151EXPORT_SYMBOL(pmu_register_sleep_notifier);
3152EXPORT_SYMBOL(pmu_unregister_sleep_notifier); 3152EXPORT_SYMBOL(pmu_unregister_sleep_notifier);
3153EXPORT_SYMBOL(pmu_enable_irled); 3153EXPORT_SYMBOL(pmu_enable_irled);
3154EXPORT_SYMBOL(pmu_battery_count); 3154EXPORT_SYMBOL(pmu_battery_count);
3155EXPORT_SYMBOL(pmu_batteries); 3155EXPORT_SYMBOL(pmu_batteries);
3156EXPORT_SYMBOL(pmu_power_flags); 3156EXPORT_SYMBOL(pmu_power_flags);
3157#endif /* CONFIG_PMAC_PBOOK */ 3157#endif /* CONFIG_PM */
3158 3158
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 3802f7a17f16..4a0c57db2b67 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -338,6 +338,7 @@ static int super_written(struct bio *bio, unsigned int bytes_done, int error)
338 338
339 if (atomic_dec_and_test(&rdev->mddev->pending_writes)) 339 if (atomic_dec_and_test(&rdev->mddev->pending_writes))
340 wake_up(&rdev->mddev->sb_wait); 340 wake_up(&rdev->mddev->sb_wait);
341 bio_put(bio);
341 return 0; 342 return 0;
342} 343}
343 344
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index f9383e7f34ff..1b70f8b0feb9 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -7,7 +7,7 @@ menu "Video For Linux"
7 7
8comment "Video Adapters" 8comment "Video Adapters"
9 9
10config CONFIG_TUNER_MULTI_I2C 10config TUNER_MULTI_I2C
11 bool "Enable support for multiple I2C devices on Video Adapters (EXPERIMENTAL)" 11 bool "Enable support for multiple I2C devices on Video Adapters (EXPERIMENTAL)"
12 depends on VIDEO_DEV && EXPERIMENTAL 12 depends on VIDEO_DEV && EXPERIMENTAL
13 ---help--- 13 ---help---
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 2dc906fdfa55..810e7aac0a53 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -7,8 +7,7 @@ bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \
7zoran-objs := zr36120.o zr36120_i2c.o zr36120_mem.o 7zoran-objs := zr36120.o zr36120_i2c.o zr36120_mem.o
8zr36067-objs := zoran_procfs.o zoran_device.o \ 8zr36067-objs := zoran_procfs.o zoran_device.o \
9 zoran_driver.o zoran_card.o 9 zoran_driver.o zoran_card.o
10tuner-objs := tuner-core.o tuner-simple.o mt20xx.o tda8290.o 10tuner-objs := tuner-core.o tuner-simple.o mt20xx.o tda8290.o tea5767.o
11
12obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o v4l1-compat.o 11obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o v4l1-compat.o
13 12
14obj-$(CONFIG_VIDEO_BT848) += bttv.o msp3400.o tvaudio.o \ 13obj-$(CONFIG_VIDEO_BT848) += bttv.o msp3400.o tvaudio.o \
diff --git a/drivers/media/video/bttv-driver.c b/drivers/media/video/bttv-driver.c
index 290289a99757..7d62b394c509 100644
--- a/drivers/media/video/bttv-driver.c
+++ b/drivers/media/video/bttv-driver.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttv-driver.c,v 1.38 2005/06/10 17:20:24 mchehab Exp $ 2 $Id: bttv-driver.c,v 1.40 2005/06/16 21:38:45 nsh Exp $
3 3
4 bttv - Bt848 frame grabber driver 4 bttv - Bt848 frame grabber driver
5 5
@@ -76,6 +76,9 @@ static unsigned int whitecrush_upper = 0xCF;
76static unsigned int whitecrush_lower = 0x7F; 76static unsigned int whitecrush_lower = 0x7F;
77static unsigned int vcr_hack = 0; 77static unsigned int vcr_hack = 0;
78static unsigned int irq_iswitch = 0; 78static unsigned int irq_iswitch = 0;
79static unsigned int uv_ratio = 50;
80static unsigned int full_luma_range = 0;
81static unsigned int coring = 0;
79 82
80/* API features (turn on/off stuff for testing) */ 83/* API features (turn on/off stuff for testing) */
81static unsigned int v4l2 = 1; 84static unsigned int v4l2 = 1;
@@ -106,6 +109,9 @@ module_param(adc_crush, int, 0444);
106module_param(whitecrush_upper, int, 0444); 109module_param(whitecrush_upper, int, 0444);
107module_param(whitecrush_lower, int, 0444); 110module_param(whitecrush_lower, int, 0444);
108module_param(vcr_hack, int, 0444); 111module_param(vcr_hack, int, 0444);
112module_param(uv_ratio, int, 0444);
113module_param(full_luma_range, int, 0444);
114module_param(coring, int, 0444);
109 115
110module_param_array(radio, int, NULL, 0444); 116module_param_array(radio, int, NULL, 0444);
111 117
@@ -124,6 +130,9 @@ MODULE_PARM_DESC(whitecrush_upper,"sets the white crush upper value, default is
124MODULE_PARM_DESC(whitecrush_lower,"sets the white crush lower value, default is 127"); 130MODULE_PARM_DESC(whitecrush_lower,"sets the white crush lower value, default is 127");
125MODULE_PARM_DESC(vcr_hack,"enables the VCR hack (improves synch on poor VCR tapes), default is 0 (no)"); 131MODULE_PARM_DESC(vcr_hack,"enables the VCR hack (improves synch on poor VCR tapes), default is 0 (no)");
126MODULE_PARM_DESC(irq_iswitch,"switch inputs in irq handler"); 132MODULE_PARM_DESC(irq_iswitch,"switch inputs in irq handler");
133MODULE_PARM_DESC(uv_ratio,"ratio between u and v gains, default is 50");
134MODULE_PARM_DESC(full_luma_range,"use the full luma range, default is 0 (no)");
135MODULE_PARM_DESC(coring,"set the luma coring level, default is 0 (no)");
127 136
128MODULE_DESCRIPTION("bttv - v4l/v4l2 driver module for bt848/878 based cards"); 137MODULE_DESCRIPTION("bttv - v4l/v4l2 driver module for bt848/878 based cards");
129MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr"); 138MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr");
@@ -484,7 +493,10 @@ static const unsigned int BTTV_FORMATS = ARRAY_SIZE(bttv_formats);
484#define V4L2_CID_PRIVATE_VCR_HACK (V4L2_CID_PRIVATE_BASE + 5) 493#define V4L2_CID_PRIVATE_VCR_HACK (V4L2_CID_PRIVATE_BASE + 5)
485#define V4L2_CID_PRIVATE_WHITECRUSH_UPPER (V4L2_CID_PRIVATE_BASE + 6) 494#define V4L2_CID_PRIVATE_WHITECRUSH_UPPER (V4L2_CID_PRIVATE_BASE + 6)
486#define V4L2_CID_PRIVATE_WHITECRUSH_LOWER (V4L2_CID_PRIVATE_BASE + 7) 495#define V4L2_CID_PRIVATE_WHITECRUSH_LOWER (V4L2_CID_PRIVATE_BASE + 7)
487#define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 8) 496#define V4L2_CID_PRIVATE_UV_RATIO (V4L2_CID_PRIVATE_BASE + 8)
497#define V4L2_CID_PRIVATE_FULL_LUMA_RANGE (V4L2_CID_PRIVATE_BASE + 9)
498#define V4L2_CID_PRIVATE_CORING (V4L2_CID_PRIVATE_BASE + 10)
499#define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 11)
488 500
489static const struct v4l2_queryctrl no_ctl = { 501static const struct v4l2_queryctrl no_ctl = {
490 .name = "42", 502 .name = "42",
@@ -618,8 +630,32 @@ static const struct v4l2_queryctrl bttv_ctls[] = {
618 .step = 1, 630 .step = 1,
619 .default_value = 0x7F, 631 .default_value = 0x7F,
620 .type = V4L2_CTRL_TYPE_INTEGER, 632 .type = V4L2_CTRL_TYPE_INTEGER,
633 },{
634 .id = V4L2_CID_PRIVATE_UV_RATIO,
635 .name = "uv ratio",
636 .minimum = 0,
637 .maximum = 100,
638 .step = 1,
639 .default_value = 50,
640 .type = V4L2_CTRL_TYPE_INTEGER,
641 },{
642 .id = V4L2_CID_PRIVATE_FULL_LUMA_RANGE,
643 .name = "full luma range",
644 .minimum = 0,
645 .maximum = 1,
646 .type = V4L2_CTRL_TYPE_BOOLEAN,
647 },{
648 .id = V4L2_CID_PRIVATE_CORING,
649 .name = "coring",
650 .minimum = 0,
651 .maximum = 3,
652 .step = 1,
653 .default_value = 0,
654 .type = V4L2_CTRL_TYPE_INTEGER,
621 } 655 }
622 656
657
658
623}; 659};
624static const int BTTV_CTLS = ARRAY_SIZE(bttv_ctls); 660static const int BTTV_CTLS = ARRAY_SIZE(bttv_ctls);
625 661
@@ -833,8 +869,8 @@ static void bt848_sat(struct bttv *btv, int color)
833 btv->saturation = color; 869 btv->saturation = color;
834 870
835 /* 0-511 for the color */ 871 /* 0-511 for the color */
836 val_u = color >> 7; 872 val_u = ((color * btv->opt_uv_ratio) / 50) >> 7;
837 val_v = ((color>>7)*180L)/254; 873 val_v = (((color * (100 - btv->opt_uv_ratio) / 50) >>7)*180L)/254;
838 hibits = (val_u >> 7) & 2; 874 hibits = (val_u >> 7) & 2;
839 hibits |= (val_v >> 8) & 1; 875 hibits |= (val_v >> 8) & 1;
840 btwrite(val_u & 0xff, BT848_SAT_U_LO); 876 btwrite(val_u & 0xff, BT848_SAT_U_LO);
@@ -1151,6 +1187,15 @@ static int get_control(struct bttv *btv, struct v4l2_control *c)
1151 case V4L2_CID_PRIVATE_WHITECRUSH_LOWER: 1187 case V4L2_CID_PRIVATE_WHITECRUSH_LOWER:
1152 c->value = btv->opt_whitecrush_lower; 1188 c->value = btv->opt_whitecrush_lower;
1153 break; 1189 break;
1190 case V4L2_CID_PRIVATE_UV_RATIO:
1191 c->value = btv->opt_uv_ratio;
1192 break;
1193 case V4L2_CID_PRIVATE_FULL_LUMA_RANGE:
1194 c->value = btv->opt_full_luma_range;
1195 break;
1196 case V4L2_CID_PRIVATE_CORING:
1197 c->value = btv->opt_coring;
1198 break;
1154 default: 1199 default:
1155 return -EINVAL; 1200 return -EINVAL;
1156 } 1201 }
@@ -1247,6 +1292,18 @@ static int set_control(struct bttv *btv, struct v4l2_control *c)
1247 btv->opt_whitecrush_lower = c->value; 1292 btv->opt_whitecrush_lower = c->value;
1248 btwrite(c->value, BT848_WC_DOWN); 1293 btwrite(c->value, BT848_WC_DOWN);
1249 break; 1294 break;
1295 case V4L2_CID_PRIVATE_UV_RATIO:
1296 btv->opt_uv_ratio = c->value;
1297 bt848_sat(btv, btv->saturation);
1298 break;
1299 case V4L2_CID_PRIVATE_FULL_LUMA_RANGE:
1300 btv->opt_full_luma_range = c->value;
1301 btaor((c->value<<7), ~BT848_OFORM_RANGE, BT848_OFORM);
1302 break;
1303 case V4L2_CID_PRIVATE_CORING:
1304 btv->opt_coring = c->value;
1305 btaor((c->value<<5), ~BT848_OFORM_CORE32, BT848_OFORM);
1306 break;
1250 default: 1307 default:
1251 return -EINVAL; 1308 return -EINVAL;
1252 } 1309 }
@@ -3117,11 +3174,6 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
3117 return -EINVAL; 3174 return -EINVAL;
3118 memset(v,0,sizeof(*v)); 3175 memset(v,0,sizeof(*v));
3119 strcpy(v->name, "Radio"); 3176 strcpy(v->name, "Radio");
3120 /* japan: 76.0 MHz - 89.9 MHz
3121 western europe: 87.5 MHz - 108.0 MHz
3122 russia: 65.0 MHz - 108.0 MHz */
3123 v->rangelow=(int)(65*16);
3124 v->rangehigh=(int)(108*16);
3125 bttv_call_i2c_clients(btv,cmd,v); 3177 bttv_call_i2c_clients(btv,cmd,v);
3126 return 0; 3178 return 0;
3127 } 3179 }
@@ -3876,6 +3928,9 @@ static int __devinit bttv_probe(struct pci_dev *dev,
3876 btv->opt_vcr_hack = vcr_hack; 3928 btv->opt_vcr_hack = vcr_hack;
3877 btv->opt_whitecrush_upper = whitecrush_upper; 3929 btv->opt_whitecrush_upper = whitecrush_upper;
3878 btv->opt_whitecrush_lower = whitecrush_lower; 3930 btv->opt_whitecrush_lower = whitecrush_lower;
3931 btv->opt_uv_ratio = uv_ratio;
3932 btv->opt_full_luma_range = full_luma_range;
3933 btv->opt_coring = coring;
3879 3934
3880 /* fill struct bttv with some useful defaults */ 3935 /* fill struct bttv with some useful defaults */
3881 btv->init.btv = btv; 3936 btv->init.btv = btv;
diff --git a/drivers/media/video/bttvp.h b/drivers/media/video/bttvp.h
index 7b6f1e856028..f3293e4a15ad 100644
--- a/drivers/media/video/bttvp.h
+++ b/drivers/media/video/bttvp.h
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttvp.h,v 1.17 2005/02/16 12:14:10 kraxel Exp $ 2 $Id: bttvp.h,v 1.19 2005/06/16 21:38:45 nsh Exp $
3 3
4 bttv - Bt848 frame grabber driver 4 bttv - Bt848 frame grabber driver
5 5
@@ -326,6 +326,9 @@ struct bttv {
326 int opt_vcr_hack; 326 int opt_vcr_hack;
327 int opt_whitecrush_upper; 327 int opt_whitecrush_upper;
328 int opt_whitecrush_lower; 328 int opt_whitecrush_lower;
329 int opt_uv_ratio;
330 int opt_full_luma_range;
331 int opt_coring;
329 332
330 /* radio data/state */ 333 /* radio data/state */
331 int has_radio; 334 int has_radio;
diff --git a/drivers/media/video/mt20xx.c b/drivers/media/video/mt20xx.c
index 95ad17b7f38e..9c005cb128d7 100644
--- a/drivers/media/video/mt20xx.c
+++ b/drivers/media/video/mt20xx.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: mt20xx.c,v 1.4 2005/03/04 09:24:56 kraxel Exp $ 2 * $Id: mt20xx.c,v 1.5 2005/06/16 08:29:49 nsh Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * controls microtune tuners, mt2032 + mt2050 at the moment. 5 * controls microtune tuners, mt2032 + mt2050 at the moment.
@@ -295,8 +295,8 @@ static void mt2032_set_radio_freq(struct i2c_client *c, unsigned int freq)
295 int if2 = t->radio_if2; 295 int if2 = t->radio_if2;
296 296
297 // per Manual for FM tuning: first if center freq. 1085 MHz 297 // per Manual for FM tuning: first if center freq. 1085 MHz
298 mt2032_set_if_freq(c, freq*62500 /* freq*1000*1000/16 */, 298 mt2032_set_if_freq(c, freq * 1000 / 16,
299 1085*1000*1000,if2,if2,if2); 299 1085*1000*1000,if2,if2,if2);
300} 300}
301 301
302// Initalization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001 302// Initalization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001
diff --git a/drivers/media/video/tda8290.c b/drivers/media/video/tda8290.c
index b27cc348d95c..f59d4601cc63 100644
--- a/drivers/media/video/tda8290.c
+++ b/drivers/media/video/tda8290.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tda8290.c,v 1.7 2005/03/07 12:01:51 kraxel Exp $ 2 * $Id: tda8290.c,v 1.11 2005/06/18 06:09:06 nsh Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * controls the philips tda8290+75 tuner chip combo. 5 * controls the philips tda8290+75 tuner chip combo.
@@ -69,7 +69,7 @@ static __u8 get_freq_entry( struct freq_entry* table, __u16 freq)
69static unsigned char i2c_enable_bridge[2] = { 0x21, 0xC0 }; 69static unsigned char i2c_enable_bridge[2] = { 0x21, 0xC0 };
70static unsigned char i2c_disable_bridge[2] = { 0x21, 0x80 }; 70static unsigned char i2c_disable_bridge[2] = { 0x21, 0x80 };
71static unsigned char i2c_init_tda8275[14] = { 0x00, 0x00, 0x00, 0x00, 71static unsigned char i2c_init_tda8275[14] = { 0x00, 0x00, 0x00, 0x00,
72 0x7C, 0x04, 0xA3, 0x3F, 72 0xfC, 0x04, 0xA3, 0x3F,
73 0x2A, 0x04, 0xFF, 0x00, 73 0x2A, 0x04, 0xFF, 0x00,
74 0x00, 0x40 }; 74 0x00, 0x40 };
75static unsigned char i2c_set_VS[2] = { 0x30, 0x6F }; 75static unsigned char i2c_set_VS[2] = { 0x30, 0x6F };
@@ -138,16 +138,24 @@ static int tda8290_tune(struct i2c_client *c)
138 138
139static void set_frequency(struct tuner *t, u16 ifc) 139static void set_frequency(struct tuner *t, u16 ifc)
140{ 140{
141 u32 N = (((t->freq<<3)+ifc)&0x3fffc); 141 u32 freq;
142 u32 N;
142 143
143 N = N >> get_freq_entry(div_table, t->freq); 144 if (t->mode == V4L2_TUNER_RADIO)
145 freq = t->freq / 1000;
146 else
147 freq = t->freq;
148
149 N = (((freq<<3)+ifc)&0x3fffc);
150
151 N = N >> get_freq_entry(div_table, freq);
144 t->i2c_set_freq[0] = 0; 152 t->i2c_set_freq[0] = 0;
145 t->i2c_set_freq[1] = (unsigned char)(N>>8); 153 t->i2c_set_freq[1] = (unsigned char)(N>>8);
146 t->i2c_set_freq[2] = (unsigned char) N; 154 t->i2c_set_freq[2] = (unsigned char) N;
147 t->i2c_set_freq[3] = 0x40; 155 t->i2c_set_freq[3] = 0x40;
148 t->i2c_set_freq[4] = 0x52; 156 t->i2c_set_freq[4] = 0x52;
149 t->i2c_set_freq[5] = get_freq_entry(band_table, t->freq); 157 t->i2c_set_freq[5] = get_freq_entry(band_table, freq);
150 t->i2c_set_freq[6] = get_freq_entry(agc_table, t->freq); 158 t->i2c_set_freq[6] = get_freq_entry(agc_table, freq);
151 t->i2c_set_freq[7] = 0x8f; 159 t->i2c_set_freq[7] = 0x8f;
152} 160}
153 161
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index 39773633cc3c..ee35562f4d1a 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -368,7 +368,7 @@ static int tda9887_set_tvnorm(struct tda9887 *t, char *buf)
368 if (t->radio_mode == V4L2_TUNER_MODE_MONO) 368 if (t->radio_mode == V4L2_TUNER_MODE_MONO)
369 norm = &radio_mono; 369 norm = &radio_mono;
370 else 370 else
371 norm = &radio_stereo; 371 norm = &radio_stereo;
372 } else { 372 } else {
373 for (i = 0; i < ARRAY_SIZE(tvnorms); i++) { 373 for (i = 0; i < ARRAY_SIZE(tvnorms); i++) {
374 if (tvnorms[i].std & t->std) { 374 if (tvnorms[i].std & t->std) {
@@ -566,7 +566,6 @@ static int tda9887_configure(struct tda9887 *t)
566 if (UNSET != t->pinnacle_id) { 566 if (UNSET != t->pinnacle_id) {
567 tda9887_set_pinnacle(t,buf); 567 tda9887_set_pinnacle(t,buf);
568 } 568 }
569
570 tda9887_set_config(t,buf); 569 tda9887_set_config(t,buf);
571 tda9887_set_insmod(t,buf); 570 tda9887_set_insmod(t,buf);
572 571
@@ -615,8 +614,8 @@ static int tda9887_attach(struct i2c_adapter *adap, int addr, int kind)
615 t->pinnacle_id = UNSET; 614 t->pinnacle_id = UNSET;
616 t->radio_mode = V4L2_TUNER_MODE_STEREO; 615 t->radio_mode = V4L2_TUNER_MODE_STEREO;
617 616
618 i2c_set_clientdata(&t->client, t); 617 i2c_set_clientdata(&t->client, t);
619 i2c_attach_client(&t->client); 618 i2c_attach_client(&t->client);
620 619
621 return 0; 620 return 0;
622} 621}
diff --git a/drivers/media/video/tea5767.c b/drivers/media/video/tea5767.c
new file mode 100644
index 000000000000..a29f08f81f63
--- /dev/null
+++ b/drivers/media/video/tea5767.c
@@ -0,0 +1,334 @@
1/*
2 * For Philips TEA5767 FM Chip used on some TV Cards like Prolink Pixelview
3 * I2C address is allways 0xC0.
4 *
5 * $Id: tea5767.c,v 1.11 2005/06/21 15:40:33 mchehab Exp $
6 *
7 * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br)
8 * This code is placed under the terms of the GNU General Public License
9 *
10 * tea5767 autodetection thanks to Torsten Seeboth and Atsushi Nakagawa
11 * from their contributions on DScaler.
12 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/sched.h>
18#include <linux/string.h>
19#include <linux/timer.h>
20#include <linux/delay.h>
21#include <linux/errno.h>
22#include <linux/slab.h>
23#include <linux/videodev.h>
24#include <linux/i2c.h>
25#include <linux/i2c-algo-bit.h>
26
27#include <media/tuner.h>
28
29/* Declared at tuner-core.c */
30extern unsigned int tuner_debug;
31
32#define PREFIX "TEA5767 "
33
34/*****************************************************************************/
35
36/******************************
37 * Write mode register values *
38 ******************************/
39
40/* First register */
41#define TEA5767_MUTE 0x80 /* Mutes output */
42#define TEA5767_SEARCH 0x40 /* Activates station search */
43/* Bits 0-5 for divider MSB */
44
45/* Second register */
46/* Bits 0-7 for divider LSB */
47
48/* Third register */
49
50/* Station search from botton to up */
51#define TEA5767_SEARCH_UP 0x80
52
53/* Searches with ADC output = 10 */
54#define TEA5767_SRCH_HIGH_LVL 0x60
55
56/* Searches with ADC output = 10 */
57#define TEA5767_SRCH_MID_LVL 0x40
58
59/* Searches with ADC output = 5 */
60#define TEA5767_SRCH_LOW_LVL 0x20
61
62/* if on, div=4*(Frf+Fif)/Fref otherwise, div=4*(Frf-Fif)/Freq) */
63#define TEA5767_HIGH_LO_INJECT 0x10
64
65/* Disable stereo */
66#define TEA5767_MONO 0x08
67
68/* Disable right channel and turns to mono */
69#define TEA5767_MUTE_RIGHT 0x04
70
71/* Disable left channel and turns to mono */
72#define TEA5767_MUTE_LEFT 0x02
73
74#define TEA5767_PORT1_HIGH 0x01
75
76/* Forth register */
77#define TEA5767_PORT2_HIGH 0x80
78/* Chips stops working. Only I2C bus remains on */
79#define TEA5767_STDBY 0x40
80
81/* Japan freq (76-108 MHz. If disabled, 87.5-108 MHz */
82#define TEA5767_JAPAN_BAND 0x20
83
84/* Unselected means 32.768 KHz freq as reference. Otherwise Xtal at 13 MHz */
85#define TEA5767_XTAL_32768 0x10
86
87/* Cuts weak signals */
88#define TEA5767_SOFT_MUTE 0x08
89
90/* Activates high cut control */
91#define TEA5767_HIGH_CUT_CTRL 0x04
92
93/* Activates stereo noise control */
94#define TEA5767_ST_NOISE_CTL 0x02
95
96/* If activate PORT 1 indicates SEARCH or else it is used as PORT1 */
97#define TEA5767_SRCH_IND 0x01
98
99/* Fiveth register */
100
101/* By activating, it will use Xtal at 13 MHz as reference for divider */
102#define TEA5767_PLLREF_ENABLE 0x80
103
104/* By activating, deemphasis=50, or else, deemphasis of 50us */
105#define TEA5767_DEEMPH_75 0X40
106
107/*****************************
108 * Read mode register values *
109 *****************************/
110
111/* First register */
112#define TEA5767_READY_FLAG_MASK 0x80
113#define TEA5767_BAND_LIMIT_MASK 0X40
114/* Bits 0-5 for divider MSB after search or preset */
115
116/* Second register */
117/* Bits 0-7 for divider LSB after search or preset */
118
119/* Third register */
120#define TEA5767_STEREO_MASK 0x80
121#define TEA5767_IF_CNTR_MASK 0x7f
122
123/* Four register */
124#define TEA5767_ADC_LEVEL_MASK 0xf0
125
126/* should be 0 */
127#define TEA5767_CHIP_ID_MASK 0x0f
128
129/* Fiveth register */
130/* Reserved for future extensions */
131#define TEA5767_RESERVED_MASK 0xff
132
133/*****************************************************************************/
134
135static void set_tv_freq(struct i2c_client *c, unsigned int freq)
136{
137 struct tuner *t = i2c_get_clientdata(c);
138
139 tuner_warn("This tuner doesn't support TV freq.\n");
140}
141
142static void tea5767_status_dump(unsigned char *buffer)
143{
144 unsigned int div, frq;
145
146 if (TEA5767_READY_FLAG_MASK & buffer[0])
147 printk(PREFIX "Ready Flag ON\n");
148 else
149 printk(PREFIX "Ready Flag OFF\n");
150
151 if (TEA5767_BAND_LIMIT_MASK & buffer[0])
152 printk(PREFIX "Tuner at band limit\n");
153 else
154 printk(PREFIX "Tuner not at band limit\n");
155
156 div=((buffer[0]&0x3f)<<8) | buffer[1];
157
158 switch (TEA5767_HIGH_LO_32768) {
159 case TEA5767_HIGH_LO_13MHz:
160 frq = 1000*(div*50-700-225)/4; /* Freq in KHz */
161 break;
162 case TEA5767_LOW_LO_13MHz:
163 frq = 1000*(div*50+700+225)/4; /* Freq in KHz */
164 break;
165 case TEA5767_LOW_LO_32768:
166 frq = 1000*(div*32768/1000+700+225)/4; /* Freq in KHz */
167 break;
168 case TEA5767_HIGH_LO_32768:
169 default:
170 frq = 1000*(div*32768/1000-700-225)/4; /* Freq in KHz */
171 break;
172 }
173 buffer[0] = (div>>8) & 0x3f;
174 buffer[1] = div & 0xff;
175
176 printk(PREFIX "Frequency %d.%03d KHz (divider = 0x%04x)\n",
177 frq/1000,frq%1000,div);
178
179 if (TEA5767_STEREO_MASK & buffer[2])
180 printk(PREFIX "Stereo\n");
181 else
182 printk(PREFIX "Mono\n");
183
184 printk(PREFIX "IF Counter = %d\n",buffer[2] & TEA5767_IF_CNTR_MASK);
185
186 printk(PREFIX "ADC Level = %d\n",(buffer[3] & TEA5767_ADC_LEVEL_MASK)>>4);
187
188 printk(PREFIX "Chip ID = %d\n",(buffer[3] & TEA5767_CHIP_ID_MASK));
189
190 printk(PREFIX "Reserved = 0x%02x\n",(buffer[4] & TEA5767_RESERVED_MASK));
191}
192
193/* Freq should be specifyed at 62.5 Hz */
194static void set_radio_freq(struct i2c_client *c, unsigned int frq)
195{
196 struct tuner *t = i2c_get_clientdata(c);
197 unsigned char buffer[5];
198 unsigned div;
199 int rc;
200
201 if ( tuner_debug )
202 printk(PREFIX "radio freq counter %d\n",frq);
203
204 /* Rounds freq to next decimal value - for 62.5 KHz step */
205 /* frq = 20*(frq/16)+radio_frq[frq%16]; */
206
207 buffer[2] = TEA5767_PORT1_HIGH;
208 buffer[3] = TEA5767_PORT2_HIGH | TEA5767_HIGH_CUT_CTRL | TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND;
209 buffer[4]=0;
210
211 if (t->audmode == V4L2_TUNER_MODE_MONO) {
212 tuner_dbg("TEA5767 set to mono\n");
213 buffer[2] |= TEA5767_MONO;
214 } else
215 tuner_dbg("TEA5767 set to stereo\n");
216
217 switch (t->type) {
218 case TEA5767_HIGH_LO_13MHz:
219 tuner_dbg("TEA5767 radio HIGH LO inject xtal @ 13 MHz\n");
220 buffer[2] |= TEA5767_HIGH_LO_INJECT;
221 buffer[4] |= TEA5767_PLLREF_ENABLE;
222 div = (frq*4/16+700+225+25)/50;
223 break;
224 case TEA5767_LOW_LO_13MHz:
225 tuner_dbg("TEA5767 radio LOW LO inject xtal @ 13 MHz\n");
226
227 buffer[4] |= TEA5767_PLLREF_ENABLE;
228 div = (frq*4/16-700-225+25)/50;
229 break;
230 case TEA5767_LOW_LO_32768:
231 tuner_dbg("TEA5767 radio LOW LO inject xtal @ 32,768 MHz\n");
232 buffer[3] |= TEA5767_XTAL_32768;
233 /* const 700=4000*175 Khz - to adjust freq to right value */
234 div = (1000*(frq*4/16-700-225)+16384)>>15;
235 break;
236 case TEA5767_HIGH_LO_32768:
237 default:
238 tuner_dbg("TEA5767 radio HIGH LO inject xtal @ 32,768 MHz\n");
239
240 buffer[2] |= TEA5767_HIGH_LO_INJECT;
241 buffer[3] |= TEA5767_XTAL_32768;
242 div = (1000*(frq*4/16+700+225)+16384)>>15;
243 break;
244 }
245 buffer[0] = (div>>8) & 0x3f;
246 buffer[1] = div & 0xff;
247
248 if ( tuner_debug )
249 tea5767_status_dump(buffer);
250
251 if (5 != (rc = i2c_master_send(c,buffer,5)))
252 tuner_warn("i2c i/o error: rc == %d (should be 5)\n",rc);
253}
254
255static int tea5767_signal(struct i2c_client *c)
256{
257 unsigned char buffer[5];
258 int rc;
259 struct tuner *t = i2c_get_clientdata(c);
260
261 memset(buffer,0,sizeof(buffer));
262 if (5 != (rc = i2c_master_recv(c,buffer,5)))
263 tuner_warn ( "i2c i/o error: rc == %d (should be 5)\n",rc);
264
265 return ((buffer[3] & TEA5767_ADC_LEVEL_MASK) <<(13-4));
266}
267
268static int tea5767_stereo(struct i2c_client *c)
269{
270 unsigned char buffer[5];
271 int rc;
272 struct tuner *t = i2c_get_clientdata(c);
273
274 memset(buffer,0,sizeof(buffer));
275 if (5 != (rc = i2c_master_recv(c,buffer,5)))
276 tuner_warn ( "i2c i/o error: rc == %d (should be 5)\n",rc);
277
278 rc = buffer[2] & TEA5767_STEREO_MASK;
279
280 if ( tuner_debug )
281 tuner_dbg("TEA5767 radio ST GET = %02x\n", rc);
282
283 return ( (buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO: 0);
284}
285
286int tea_detection(struct i2c_client *c)
287{
288 unsigned char buffer[5]= { 0xff, 0xff, 0xff, 0xff, 0xff };
289 int rc;
290 struct tuner *t = i2c_get_clientdata(c);
291
292 if (5 != (rc = i2c_master_recv(c,buffer,5))) {
293 tuner_warn ( "it is not a TEA5767. Received %i chars.\n",rc );
294 return EINVAL;
295 }
296
297 /* If all bytes are the same then it's a TV tuner and not a tea5767 chip. */
298 if (buffer[0] == buffer[1] && buffer[0] == buffer[2] &&
299 buffer[0] == buffer[3] && buffer[0] == buffer[4]) {
300 tuner_warn ( "All bytes are equal. It is not a TEA5767\n" );
301 return EINVAL;
302 }
303
304 /* Status bytes:
305 * Byte 4: bit 3:1 : CI (Chip Identification) == 0
306 * bit 0 : internally set to 0
307 * Byte 5: bit 7:0 : == 0
308 */
309
310 if (!((buffer[3] & 0x0f) == 0x00) && (buffer[4] == 0x00)) {
311 tuner_warn ( "Chip ID is not zero. It is not a TEA5767\n" );
312 return EINVAL;
313 }
314 tuner_warn ( "TEA5767 detected.\n" );
315 return 0;
316}
317
318int tea5767_tuner_init(struct i2c_client *c)
319{
320 struct tuner *t = i2c_get_clientdata(c);
321
322 if (tea_detection(c)==EINVAL) return EINVAL;
323
324 tuner_info("type set to %d (%s)\n",
325 t->type, TEA5767_TUNER_NAME);
326 strlcpy(c->name, TEA5767_TUNER_NAME, sizeof(c->name));
327
328 t->tv_freq = set_tv_freq;
329 t->radio_freq = set_radio_freq;
330 t->has_signal = tea5767_signal;
331 t->is_stereo = tea5767_stereo;
332
333 return (0);
334}
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index eaabfc858703..6f6bf4a633fc 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tuner-core.c,v 1.15 2005/06/12 01:36:14 mchehab Exp $ 2 * $Id: tuner-core.c,v 1.29 2005/06/21 15:40:33 mchehab Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * core core, i.e. kernel interfaces, registering and so on 5 * core core, i.e. kernel interfaces, registering and so on
@@ -26,7 +26,6 @@
26/* 26/*
27 * comment line bellow to return to old behavor, where only one I2C device is supported 27 * comment line bellow to return to old behavor, where only one I2C device is supported
28 */ 28 */
29#define CONFIG_TUNER_MULTI_I2C /**/
30 29
31#define UNSET (-1U) 30#define UNSET (-1U)
32 31
@@ -58,9 +57,7 @@ MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
58MODULE_LICENSE("GPL"); 57MODULE_LICENSE("GPL");
59 58
60static int this_adap; 59static int this_adap;
61#ifdef CONFIG_TUNER_MULTI_I2C
62static unsigned short first_tuner, tv_tuner, radio_tuner; 60static unsigned short first_tuner, tv_tuner, radio_tuner;
63#endif
64 61
65static struct i2c_driver driver; 62static struct i2c_driver driver;
66static struct i2c_client client_template; 63static struct i2c_client client_template;
@@ -81,26 +78,9 @@ static void set_tv_freq(struct i2c_client *c, unsigned int freq)
81 return; 78 return;
82 } 79 }
83 if (freq < tv_range[0]*16 || freq > tv_range[1]*16) { 80 if (freq < tv_range[0]*16 || freq > tv_range[1]*16) {
84
85 if (freq >= tv_range[0]*16364 && freq <= tv_range[1]*16384) {
86 /* V4L2_TUNER_CAP_LOW frequency */
87
88 tuner_dbg("V4L2_TUNER_CAP_LOW freq selected for TV. Tuners yet doesn't support converting it to valid freq.\n");
89
90 t->tv_freq(c,freq>>10);
91
92 return;
93 } else {
94 /* FIXME: better do that chip-specific, but
95 right now we don't have that in the config
96 struct and this way is still better than no
97 check at all */
98 tuner_info("TV freq (%d.%02d) out of range (%d-%d)\n", 81 tuner_info("TV freq (%d.%02d) out of range (%d-%d)\n",
99 freq/16,freq%16*100/16,tv_range[0],tv_range[1]); 82 freq/16,freq%16*100/16,tv_range[0],tv_range[1]);
100 return;
101 }
102 } 83 }
103 tuner_dbg("62.5 Khz freq step selected for TV.\n");
104 t->tv_freq(c,freq); 84 t->tv_freq(c,freq);
105} 85}
106 86
@@ -116,31 +96,18 @@ static void set_radio_freq(struct i2c_client *c, unsigned int freq)
116 tuner_info("no radio tuning for this one, sorry.\n"); 96 tuner_info("no radio tuning for this one, sorry.\n");
117 return; 97 return;
118 } 98 }
119 if (freq < radio_range[0]*16 || freq > radio_range[1]*16) { 99 if (freq >= radio_range[0]*16000 && freq <= radio_range[1]*16000) {
120 if (freq >= tv_range[0]*16364 && freq <= tv_range[1]*16384) { 100 if (tuner_debug)
121 /* V4L2_TUNER_CAP_LOW frequency */ 101 tuner_info("radio freq step 62.5Hz (%d.%06d)\n",
122 if (t->type == TUNER_TEA5767) { 102 freq/16000,freq%16000*1000/16);
123 tuner_info("radio freq step 62.5Hz (%d.%06d)\n",(freq>>14),freq%(1<<14)*10000); 103 t->radio_freq(c,freq);
124 t->radio_freq(c,freq>>10); 104 } else {
125 return; 105 tuner_info("radio freq (%d.%02d) out of range (%d-%d)\n",
126 } 106 freq/16,freq%16*100/16,
127 107 radio_range[0],radio_range[1]);
128 tuner_dbg("V4L2_TUNER_CAP_LOW freq selected for Radio. Tuners yet doesn't support converting it to valid freq.\n");
129
130 tuner_info("radio freq (%d.%06d)\n",(freq>>14),freq%(1<<14)*10000);
131
132 t->radio_freq(c,freq>>10);
133 return;
134
135 } else {
136 tuner_info("radio freq (%d.%02d) out of range (%d-%d)\n",
137 freq/16,freq%16*100/16,
138 radio_range[0],radio_range[1]);
139 return;
140 }
141 } 108 }
142 tuner_dbg("62.5 Khz freq step selected for Radio.\n"); 109
143 t->radio_freq(c,freq); 110 return;
144} 111}
145 112
146static void set_freq(struct i2c_client *c, unsigned long freq) 113static void set_freq(struct i2c_client *c, unsigned long freq)
@@ -166,8 +133,8 @@ static void set_freq(struct i2c_client *c, unsigned long freq)
166static void set_type(struct i2c_client *c, unsigned int type) 133static void set_type(struct i2c_client *c, unsigned int type)
167{ 134{
168 struct tuner *t = i2c_get_clientdata(c); 135 struct tuner *t = i2c_get_clientdata(c);
136 unsigned char buffer[4];
169 137
170 tuner_dbg ("I2C addr 0x%02x with type %d\n",c->addr<<1,type);
171 /* sanity check */ 138 /* sanity check */
172 if (type == UNSET || type == TUNER_ABSENT) 139 if (type == UNSET || type == TUNER_ABSENT)
173 return; 140 return;
@@ -179,8 +146,8 @@ static void set_type(struct i2c_client *c, unsigned int type)
179 t->type = type; 146 t->type = type;
180 return; 147 return;
181 } 148 }
182 if (t->initialized) 149 if ((t->initialized) && (t->type == type))
183 /* run only once */ 150 /* run only once except type change Hac 04/05*/
184 return; 151 return;
185 152
186 t->initialized = 1; 153 t->initialized = 1;
@@ -193,25 +160,42 @@ static void set_type(struct i2c_client *c, unsigned int type)
193 case TUNER_PHILIPS_TDA8290: 160 case TUNER_PHILIPS_TDA8290:
194 tda8290_init(c); 161 tda8290_init(c);
195 break; 162 break;
163 case TUNER_TEA5767:
164 if (tea5767_tuner_init(c)==EINVAL) t->type=TUNER_ABSENT;
165 break;
166 case TUNER_PHILIPS_FMD1216ME_MK3:
167 buffer[0] = 0x0b;
168 buffer[1] = 0xdc;
169 buffer[2] = 0x9c;
170 buffer[3] = 0x60;
171 i2c_master_send(c,buffer,4);
172 mdelay(1);
173 buffer[2] = 0x86;
174 buffer[3] = 0x54;
175 i2c_master_send(c,buffer,4);
176 default_tuner_init(c);
177 break;
196 default: 178 default:
179 /* TEA5767 autodetection code */
180 if (tea5767_tuner_init(c)!=EINVAL) {
181 t->type = TUNER_TEA5767;
182 if (first_tuner == 0x60)
183 first_tuner++;
184 break;
185 }
186
197 default_tuner_init(c); 187 default_tuner_init(c);
198 break; 188 break;
199 } 189 }
190 tuner_dbg ("I2C addr 0x%02x with type %d\n",c->addr<<1,type);
200} 191}
201 192
202#ifdef CONFIG_TUNER_MULTI_I2C
203#define CHECK_ADDR(tp,cmd,tun) if (client->addr!=tp) { \ 193#define CHECK_ADDR(tp,cmd,tun) if (client->addr!=tp) { \
204 return 0; } else \ 194 return 0; } else if (tuner_debug) \
205 tuner_info ("Cmd %s accepted to "tun"\n",cmd); 195 tuner_info ("Cmd %s accepted to "tun"\n",cmd);
206#define CHECK_MODE(cmd) if (t->mode == V4L2_TUNER_RADIO) { \ 196#define CHECK_MODE(cmd) if (t->mode == V4L2_TUNER_RADIO) { \
207 CHECK_ADDR(radio_tuner,cmd,"radio") } else \ 197 CHECK_ADDR(radio_tuner,cmd,"radio") } else \
208 { CHECK_ADDR(tv_tuner,cmd,"TV"); } 198 { CHECK_ADDR(tv_tuner,cmd,"TV"); }
209#else
210#define CHECK_ADDR(tp,cmd,tun) tuner_info ("Cmd %s accepted to "tun"\n",cmd);
211#define CHECK_MODE(cmd) tuner_info ("Cmd %s accepted\n",cmd);
212#endif
213
214#ifdef CONFIG_TUNER_MULTI_I2C
215 199
216static void set_addr(struct i2c_client *c, struct tuner_addr *tun_addr) 200static void set_addr(struct i2c_client *c, struct tuner_addr *tun_addr)
217{ 201{
@@ -242,9 +226,6 @@ static void set_addr(struct i2c_client *c, struct tuner_addr *tun_addr)
242 } 226 }
243 set_type(c,tun_addr->type); 227 set_type(c,tun_addr->type);
244} 228}
245#else
246#define set_addr(c,tun_addr) set_type(c,(tun_addr)->type)
247#endif
248 229
249static char pal[] = "-"; 230static char pal[] = "-";
250module_param_string(pal, pal, sizeof(pal), 0644); 231module_param_string(pal, pal, sizeof(pal), 0644);
@@ -284,17 +265,12 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
284{ 265{
285 struct tuner *t; 266 struct tuner *t;
286 267
287#ifndef CONFIG_TUNER_MULTI_I2C
288 if (this_adap > 0)
289 return -1;
290#else
291 /* by default, first I2C card is both tv and radio tuner */ 268 /* by default, first I2C card is both tv and radio tuner */
292 if (this_adap == 0) { 269 if (this_adap == 0) {
293 first_tuner = addr; 270 first_tuner = addr;
294 tv_tuner = addr; 271 tv_tuner = addr;
295 radio_tuner = addr; 272 radio_tuner = addr;
296 } 273 }
297#endif
298 this_adap++; 274 this_adap++;
299 275
300 client_template.adapter = adap; 276 client_template.adapter = adap;
@@ -308,6 +284,7 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
308 i2c_set_clientdata(&t->i2c, t); 284 i2c_set_clientdata(&t->i2c, t);
309 t->type = UNSET; 285 t->type = UNSET;
310 t->radio_if2 = 10700*1000; /* 10.7MHz - FM radio */ 286 t->radio_if2 = 10700*1000; /* 10.7MHz - FM radio */
287 t->audmode = V4L2_TUNER_MODE_STEREO;
311 288
312 i2c_attach_client(&t->i2c); 289 i2c_attach_client(&t->i2c);
313 tuner_info("chip found @ 0x%x (%s)\n", 290 tuner_info("chip found @ 0x%x (%s)\n",
@@ -325,11 +302,9 @@ static int tuner_probe(struct i2c_adapter *adap)
325 } 302 }
326 this_adap = 0; 303 this_adap = 0;
327 304
328#ifdef CONFIG_TUNER_MULTI_I2C
329 first_tuner = 0; 305 first_tuner = 0;
330 tv_tuner = 0; 306 tv_tuner = 0;
331 radio_tuner = 0; 307 radio_tuner = 0;
332#endif
333 308
334 if (adap->class & I2C_CLASS_TV_ANALOG) 309 if (adap->class & I2C_CLASS_TV_ANALOG)
335 return i2c_probe(adap, &addr_data, tuner_attach); 310 return i2c_probe(adap, &addr_data, tuner_attach);
@@ -392,8 +367,7 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
392 t->radio_if2 = 41300 * 1000; 367 t->radio_if2 = 41300 * 1000;
393 break; 368 break;
394 } 369 }
395 break; 370 break;
396
397 /* --- v4l ioctls --- */ 371 /* --- v4l ioctls --- */
398 /* take care: bttv does userspace copying, we'll get a 372 /* take care: bttv does userspace copying, we'll get a
399 kernel pointer here... */ 373 kernel pointer here... */
@@ -440,11 +414,18 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
440 vt->signal = t->has_signal(client); 414 vt->signal = t->has_signal(client);
441 if (t->is_stereo) { 415 if (t->is_stereo) {
442 if (t->is_stereo(client)) 416 if (t->is_stereo(client))
443 vt-> flags |= VIDEO_TUNER_STEREO_ON; 417 vt->flags |= VIDEO_TUNER_STEREO_ON;
444 else 418 else
445 vt-> flags &= 0xffff ^ VIDEO_TUNER_STEREO_ON; 419 vt->flags &= ~VIDEO_TUNER_STEREO_ON;
446 } 420 }
447 vt->flags |= V4L2_TUNER_CAP_LOW; /* Allow freqs at 62.5 Hz */ 421 vt->flags |= V4L2_TUNER_CAP_LOW; /* Allow freqs at 62.5 Hz */
422
423 vt->rangelow = radio_range[0] * 16000;
424 vt->rangehigh = radio_range[1] * 16000;
425
426 } else {
427 vt->rangelow = tv_range[0] * 16;
428 vt->rangehigh = tv_range[1] * 16;
448 } 429 }
449 430
450 return 0; 431 return 0;
@@ -510,20 +491,46 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
510 tuner -> signal = t->has_signal(client); 491 tuner -> signal = t->has_signal(client);
511 if (t->is_stereo) { 492 if (t->is_stereo) {
512 if (t->is_stereo(client)) { 493 if (t->is_stereo(client)) {
513 tuner -> capability |= V4L2_TUNER_CAP_STEREO; 494 tuner -> rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
514 tuner -> rxsubchans |= V4L2_TUNER_SUB_STEREO;
515 } else { 495 } else {
516 tuner -> rxsubchans &= 0xffff ^ V4L2_TUNER_SUB_STEREO; 496 tuner -> rxsubchans = V4L2_TUNER_SUB_MONO;
517 } 497 }
518 } 498 }
499 tuner->capability |= V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
500 tuner->audmode = t->audmode;
501
502 tuner->rangelow = radio_range[0] * 16000;
503 tuner->rangehigh = radio_range[1] * 16000;
504 } else {
505 tuner->rangelow = tv_range[0] * 16;
506 tuner->rangehigh = tv_range[1] * 16;
519 } 507 }
520 /* Wow to deal with V4L2_TUNER_CAP_LOW ? For now, it accepts from low at 62.5KHz step to high at 62.5 Hz */
521 tuner->rangelow = tv_range[0] * 16;
522// tuner->rangehigh = tv_range[1] * 16;
523// tuner->rangelow = tv_range[0] * 16384;
524 tuner->rangehigh = tv_range[1] * 16384;
525 break; 508 break;
526 } 509 }
510 case VIDIOC_S_TUNER: /* Allow changing radio range and audio mode */
511 {
512 struct v4l2_tuner *tuner = arg;
513
514 CHECK_ADDR(radio_tuner,"VIDIOC_S_TUNER","radio");
515 SWITCH_V4L2;
516
517 /* To switch the audio mode, applications initialize the
518 index and audmode fields and the reserved array and
519 call the VIDIOC_S_TUNER ioctl. */
520 /* rxsubchannels: V4L2_TUNER_MODE_MONO, V4L2_TUNER_MODE_STEREO,
521 V4L2_TUNER_MODE_LANG1, V4L2_TUNER_MODE_LANG2,
522 V4L2_TUNER_MODE_SAP */
523
524 if (tuner->audmode == V4L2_TUNER_MODE_MONO)
525 t->audmode = V4L2_TUNER_MODE_MONO;
526 else
527 t->audmode = V4L2_TUNER_MODE_STEREO;
528
529 set_radio_freq(client, t->freq);
530 break;
531 }
532 case TDA9887_SET_CONFIG: /* Nothing to do on tuner-core */
533 break;
527 default: 534 default:
528 tuner_dbg ("Unimplemented IOCTL 0x%08x called to tuner.\n", cmd); 535 tuner_dbg ("Unimplemented IOCTL 0x%08x called to tuner.\n", cmd);
529 /* nothing */ 536 /* nothing */
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index 539f30557317..c39ed6226ee0 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tuner-simple.c,v 1.21 2005/06/10 19:53:26 nsh Exp $ 2 * $Id: tuner-simple.c,v 1.31 2005/06/21 16:02:25 mkrufky Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * controls all those simple 4-control-bytes style tuners. 5 * controls all those simple 4-control-bytes style tuners.
@@ -207,28 +207,27 @@ static struct tunertype tuners[] = {
207 { "LG PAL (TAPE series)", LGINNOTEK, PAL, 207 { "LG PAL (TAPE series)", LGINNOTEK, PAL,
208 16*170.00, 16*450.00, 0x01,0x02,0x08,0xce,623}, 208 16*170.00, 16*450.00, 0x01,0x02,0x08,0xce,623},
209 209
210 { "Philips PAL/SECAM multi (FQ1216AME MK4)", Philips, PAL, 210 { "Philips PAL/SECAM multi (FQ1216AME MK4)", Philips, PAL,
211 16*160.00,16*442.00,0x01,0x02,0x04,0xce,623 }, 211 16*160.00,16*442.00,0x01,0x02,0x04,0xce,623 },
212 { "Philips FQ1236A MK4", Philips, NTSC, 212 { "Philips FQ1236A MK4", Philips, NTSC,
213 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732 }, 213 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732 },
214 214
215 /* Should work for TVF8531MF, TVF8831MF, TVF8731MF */ 215 /* Should work for TVF8531MF, TVF8831MF, TVF8731MF */
216 { "Ymec TVision TVF-8531MF", Philips, NTSC, 216 { "Ymec TVision TVF-8531MF", Philips, NTSC,
217 16*160.00,16*454.00,0xa0,0x90,0x30,0x8e,732}, 217 16*160.00,16*454.00,0xa0,0x90,0x30,0x8e,732},
218 { "Ymec TVision TVF-5533MF", Philips, NTSC, 218 { "Ymec TVision TVF-5533MF", Philips, NTSC,
219 16*160.00,16*454.00,0x01,0x02,0x04,0x8e,732}, 219 16*160.00,16*454.00,0x01,0x02,0x04,0x8e,732},
220
221 { "Thomson DDT 7611 (ATSC/NTSC)", THOMSON, ATSC, 220 { "Thomson DDT 7611 (ATSC/NTSC)", THOMSON, ATSC,
222 16*157.25,16*454.00,0x39,0x3a,0x3c,0x8e,732}, 221 16*157.25,16*454.00,0x39,0x3a,0x3c,0x8e,732},
223 { "Tena TNF9533-D/IF", LGINNOTEK, PAL, 222 /* Should work for TNF9533-D/IF, TNF9533-B/DF */
224 16*160.25, 16*464.25, 0x01,0x02,0x08,0x8e,623}, 223 { "Tena TNF9533-D/IF", Philips, PAL,
224 16*160.25,16*464.25,0x01,0x02,0x04,0x8e,623},
225 225
226 /* 226 /* This entry is for TEA5767 FM radio only chip used on several boards w/TV tuner */
227 * This entry is for TEA5767 FM radio only chip used on several boards
228 * w/TV tuner
229 */
230 { TEA5767_TUNER_NAME, Philips, RADIO, 227 { TEA5767_TUNER_NAME, Philips, RADIO,
231 -1, -1, 0, 0, 0, TEA5767_LOW_LO_32768,0}, 228 -1, -1, 0, 0, 0, TEA5767_LOW_LO_32768,0},
229 { "Philips FMD1216ME MK3 Hybrid Tuner", Philips, PAL,
230 16*160.00,16*442.00,0x51,0x52,0x54,0x86,623 },
232}; 231};
233 232
234unsigned const int tuner_count = ARRAY_SIZE(tuners); 233unsigned const int tuner_count = ARRAY_SIZE(tuners);
@@ -455,24 +454,24 @@ static void default_set_radio_freq(struct i2c_client *c, unsigned int freq)
455 int rc; 454 int rc;
456 455
457 tun=&tuners[t->type]; 456 tun=&tuners[t->type];
458 div = freq + (int)(16*10.7); 457 div = (freq / 1000) + (int)(16*10.7);
459 buffer[2] = tun->config; 458 buffer[2] = tun->config;
460 459
461 switch (t->type) { 460 switch (t->type) {
462 case TUNER_TENA_9533_DI: 461 case TUNER_TENA_9533_DI:
463 case TUNER_YMEC_TVF_5533MF: 462 case TUNER_YMEC_TVF_5533MF:
464
465 /*These values are empirically determinated */ 463 /*These values are empirically determinated */
466 div = (freq*122)/16 - 20; 464 div = (freq * 122) / 16000 - 20;
467 buffer[2] = 0x88; /* could be also 0x80 */ 465 buffer[2] = 0x88; /* could be also 0x80 */
468 buffer[3] = 0x19; /* could be also 0x10, 0x18, 0x99 */ 466 buffer[3] = 0x19; /* could be also 0x10, 0x18, 0x99 */
469 break; 467 break;
470 case TUNER_PHILIPS_FM1216ME_MK3: 468 case TUNER_PHILIPS_FM1216ME_MK3:
471 case TUNER_PHILIPS_FM1236_MK3: 469 case TUNER_PHILIPS_FM1236_MK3:
470 case TUNER_PHILIPS_FMD1216ME_MK3:
472 buffer[3] = 0x19; 471 buffer[3] = 0x19;
473 break; 472 break;
474 case TUNER_PHILIPS_FM1256_IH3: 473 case TUNER_PHILIPS_FM1256_IH3:
475 div = (20 * freq)/16 + 333 * 2; 474 div = (20 * freq) / 16000 + 333 * 2;
476 buffer[2] = 0x80; 475 buffer[2] = 0x80;
477 buffer[3] = 0x19; 476 buffer[3] = 0x19;
478 break; 477 break;
@@ -505,6 +504,7 @@ int default_tuner_init(struct i2c_client *c)
505 t->radio_freq = default_set_radio_freq; 504 t->radio_freq = default_set_radio_freq;
506 t->has_signal = tuner_signal; 505 t->has_signal = tuner_signal;
507 t->is_stereo = tuner_stereo; 506 t->is_stereo = tuner_stereo;
507
508 return 0; 508 return 0;
509} 509}
510 510
diff --git a/drivers/message/fusion/mptfc.c b/drivers/message/fusion/mptfc.c
index d8d65397e06e..353deb25e397 100644
--- a/drivers/message/fusion/mptfc.c
+++ b/drivers/message/fusion/mptfc.c
@@ -364,9 +364,7 @@ static struct pci_driver mptfc_driver = {
364 .id_table = mptfc_pci_table, 364 .id_table = mptfc_pci_table,
365 .probe = mptfc_probe, 365 .probe = mptfc_probe,
366 .remove = __devexit_p(mptscsih_remove), 366 .remove = __devexit_p(mptscsih_remove),
367 .driver = { 367 .shutdown = mptscsih_shutdown,
368 .shutdown = mptscsih_shutdown,
369 },
370#ifdef CONFIG_PM 368#ifdef CONFIG_PM
371 .suspend = mptscsih_suspend, 369 .suspend = mptscsih_suspend,
372 .resume = mptscsih_resume, 370 .resume = mptscsih_resume,
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index a0078ae5b9b8..4f973a49be4c 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -170,7 +170,7 @@ static void mptscsih_fillbuf(char *buffer, int size, int index, int width);
170#endif 170#endif
171 171
172void mptscsih_remove(struct pci_dev *); 172void mptscsih_remove(struct pci_dev *);
173void mptscsih_shutdown(struct device *); 173void mptscsih_shutdown(struct pci_dev *);
174#ifdef CONFIG_PM 174#ifdef CONFIG_PM
175int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state); 175int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state);
176int mptscsih_resume(struct pci_dev *pdev); 176int mptscsih_resume(struct pci_dev *pdev);
@@ -988,7 +988,7 @@ mptscsih_remove(struct pci_dev *pdev)
988#endif 988#endif
989#endif 989#endif
990 990
991 mptscsih_shutdown(&pdev->dev); 991 mptscsih_shutdown(pdev);
992 992
993 sz1=0; 993 sz1=0;
994 994
@@ -1026,9 +1026,9 @@ mptscsih_remove(struct pci_dev *pdev)
1026 * 1026 *
1027 */ 1027 */
1028void 1028void
1029mptscsih_shutdown(struct device * dev) 1029mptscsih_shutdown(struct pci_dev *pdev)
1030{ 1030{
1031 MPT_ADAPTER *ioc = pci_get_drvdata(to_pci_dev(dev)); 1031 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1032 struct Scsi_Host *host = ioc->sh; 1032 struct Scsi_Host *host = ioc->sh;
1033 MPT_SCSI_HOST *hd; 1033 MPT_SCSI_HOST *hd;
1034 1034
@@ -1054,7 +1054,7 @@ mptscsih_shutdown(struct device * dev)
1054int 1054int
1055mptscsih_suspend(struct pci_dev *pdev, pm_message_t state) 1055mptscsih_suspend(struct pci_dev *pdev, pm_message_t state)
1056{ 1056{
1057 mptscsih_shutdown(&pdev->dev); 1057 mptscsih_shutdown(pdev);
1058 return mpt_suspend(pdev,state); 1058 return mpt_suspend(pdev,state);
1059} 1059}
1060 1060
diff --git a/drivers/message/fusion/mptscsih.h b/drivers/message/fusion/mptscsih.h
index d73aec33e16a..5ea89bf0df19 100644
--- a/drivers/message/fusion/mptscsih.h
+++ b/drivers/message/fusion/mptscsih.h
@@ -82,7 +82,7 @@
82#endif 82#endif
83 83
84extern void mptscsih_remove(struct pci_dev *); 84extern void mptscsih_remove(struct pci_dev *);
85extern void mptscsih_shutdown(struct device *); 85extern void mptscsih_shutdown(struct pci_dev *);
86#ifdef CONFIG_PM 86#ifdef CONFIG_PM
87extern int mptscsih_suspend(struct pci_dev *pdev, u32 state); 87extern int mptscsih_suspend(struct pci_dev *pdev, u32 state);
88extern int mptscsih_resume(struct pci_dev *pdev); 88extern int mptscsih_resume(struct pci_dev *pdev);
diff --git a/drivers/message/fusion/mptspi.c b/drivers/message/fusion/mptspi.c
index 5f9a61b85b3b..e0c0ee5bc966 100644
--- a/drivers/message/fusion/mptspi.c
+++ b/drivers/message/fusion/mptspi.c
@@ -419,9 +419,7 @@ static struct pci_driver mptspi_driver = {
419 .id_table = mptspi_pci_table, 419 .id_table = mptspi_pci_table,
420 .probe = mptspi_probe, 420 .probe = mptspi_probe,
421 .remove = __devexit_p(mptscsih_remove), 421 .remove = __devexit_p(mptscsih_remove),
422 .driver = { 422 .shutdown = mptscsih_shutdown,
423 .shutdown = mptscsih_shutdown,
424 },
425#ifdef CONFIG_PM 423#ifdef CONFIG_PM
426 .suspend = mptscsih_suspend, 424 .suspend = mptscsih_suspend,
427 .resume = mptscsih_resume, 425 .resume = mptscsih_resume,
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 8480057eadb4..2bea2e0b06f2 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -607,6 +607,16 @@ config MTD_PCMCIA
607 cards are usually around 4-16MiB in size. This does not include 607 cards are usually around 4-16MiB in size. This does not include
608 Compact Flash cards which are treated as IDE devices. 608 Compact Flash cards which are treated as IDE devices.
609 609
610config MTD_PCMCIA_ANONYMOUS
611 bool "Use PCMCIA MTD drivers for anonymous PCMCIA cards"
612 depends on MTD_PCMCIA
613 default N
614 help
615 If this option is enabled, PCMCIA cards which do not report
616 anything about themselves are assumed to be MTD cards.
617
618 If unsure, say N.
619
610config MTD_UCLINUX 620config MTD_UCLINUX
611 tristate "Generic uClinux RAM/ROM filesystem support" 621 tristate "Generic uClinux RAM/ROM filesystem support"
612 depends on MTD_PARTITIONS && !MMU 622 depends on MTD_PARTITIONS && !MMU
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index e37b4c1976e5..c2655a817e3d 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -818,6 +818,32 @@ static dev_link_t *pcmciamtd_attach(void)
818 return link; 818 return link;
819} 819}
820 820
821static struct pcmcia_device_id pcmciamtd_ids[] = {
822 PCMCIA_DEVICE_FUNC_ID(1),
823 PCMCIA_DEVICE_PROD_ID123("IO DATA", "PCS-2M", "2MB SRAM", 0x547e66dc, 0x1fed36cd, 0x36eadd21),
824 PCMCIA_DEVICE_PROD_ID12("IBM", "2MB SRAM", 0xb569a6e5, 0x36eadd21),
825 PCMCIA_DEVICE_PROD_ID12("IBM", "4MB FLASH", 0xb569a6e5, 0x8bc54d2a),
826 PCMCIA_DEVICE_PROD_ID12("IBM", "8MB FLASH", 0xb569a6e5, 0x6df1be3e),
827 PCMCIA_DEVICE_PROD_ID12("Intel", "S2E20SW", 0x816cc815, 0xd14c9dcf),
828 PCMCIA_DEVICE_PROD_ID12("Intel", "S2E8 SW", 0x816cc815, 0xa2d7dedb),
829 PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-02 ", 0x40ade711, 0x145cea5c),
830 PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-04 ", 0x40ade711, 0x42064dda),
831 PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-20 ", 0x40ade711, 0x25ee5cb0),
832 PCMCIA_DEVICE_PROD_ID12("intel", "VALUE SERIES 100 ", 0x40ade711, 0xdf8506d8),
833 PCMCIA_DEVICE_PROD_ID12("KINGMAX TECHNOLOGY INC.", "SRAM 256K Bytes", 0x54d0c69c, 0xad12c29c),
834 PCMCIA_DEVICE_PROD_ID12("Maxtor", "MAXFL MobileMax Flash Memory Card", 0xb68968c8, 0x2dfb47b0),
835 PCMCIA_DEVICE_PROD_ID12("SEIKO EPSON", "WWB101EN20", 0xf9876baf, 0xad0b207b),
836 PCMCIA_DEVICE_PROD_ID12("SEIKO EPSON", "WWB513EN20", 0xf9876baf, 0xe8d884ad),
837 PCMCIA_DEVICE_PROD_ID12("Starfish, Inc.", "REX-3000", 0x05ddca47, 0xe7d67bca),
838 PCMCIA_DEVICE_PROD_ID12("Starfish, Inc.", "REX-4100", 0x05ddca47, 0x7bc32944),
839 /* the following was commented out in pcmcia-cs-3.2.7 */
840 /* PCMCIA_DEVICE_PROD_ID12("RATOC Systems,Inc.", "SmartMedia ADAPTER PC Card", 0xf4a2fefe, 0x5885b2ae), */
841#ifdef CONFIG_MTD_PCMCIA_ANONYMOUS
842 { .match_flags = PCMCIA_DEV_ID_MATCH_ANONYMOUS, },
843#endif
844 PCMCIA_DEVICE_NULL
845};
846MODULE_DEVICE_TABLE(pcmcia, pcmciamtd_ids);
821 847
822static struct pcmcia_driver pcmciamtd_driver = { 848static struct pcmcia_driver pcmciamtd_driver = {
823 .drv = { 849 .drv = {
@@ -825,7 +851,8 @@ static struct pcmcia_driver pcmciamtd_driver = {
825 }, 851 },
826 .attach = pcmciamtd_attach, 852 .attach = pcmciamtd_attach,
827 .detach = pcmciamtd_detach, 853 .detach = pcmciamtd_detach,
828 .owner = THIS_MODULE 854 .owner = THIS_MODULE,
855 .id_table = pcmciamtd_ids,
829}; 856};
830 857
831 858
diff --git a/drivers/net/3c503.c b/drivers/net/3c503.c
index 29dfd47f41d2..5c5eebdb6914 100644
--- a/drivers/net/3c503.c
+++ b/drivers/net/3c503.c
@@ -171,12 +171,7 @@ struct net_device * __init el2_probe(int unit)
171 err = do_el2_probe(dev); 171 err = do_el2_probe(dev);
172 if (err) 172 if (err)
173 goto out; 173 goto out;
174 err = register_netdev(dev);
175 if (err)
176 goto out1;
177 return dev; 174 return dev;
178out1:
179 cleanup_card(dev);
180out: 175out:
181 free_netdev(dev); 176 free_netdev(dev);
182 return ERR_PTR(err); 177 return ERR_PTR(err);
@@ -356,6 +351,10 @@ el2_probe1(struct net_device *dev, int ioaddr)
356 dev->poll_controller = ei_poll; 351 dev->poll_controller = ei_poll;
357#endif 352#endif
358 353
354 retval = register_netdev(dev);
355 if (retval)
356 goto out1;
357
359 if (dev->mem_start) 358 if (dev->mem_start)
360 printk("%s: %s - %dkB RAM, 8kB shared mem window at %#6lx-%#6lx.\n", 359 printk("%s: %s - %dkB RAM, 8kB shared mem window at %#6lx-%#6lx.\n",
361 dev->name, ei_status.name, (wordlength+1)<<3, 360 dev->name, ei_status.name, (wordlength+1)<<3,
@@ -715,11 +714,8 @@ init_module(void)
715 dev->base_addr = io[this_dev]; 714 dev->base_addr = io[this_dev];
716 dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */ 715 dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */
717 if (do_el2_probe(dev) == 0) { 716 if (do_el2_probe(dev) == 0) {
718 if (register_netdev(dev) == 0) { 717 dev_el2[found++] = dev;
719 dev_el2[found++] = dev; 718 continue;
720 continue;
721 }
722 cleanup_card(dev);
723 } 719 }
724 free_netdev(dev); 720 free_netdev(dev);
725 printk(KERN_WARNING "3c503.c: No 3c503 card found (i/o = 0x%x).\n", io[this_dev]); 721 printk(KERN_WARNING "3c503.c: No 3c503 card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/3c505.c b/drivers/net/3c505.c
index 76fa8cc24085..ad17f17e8e7a 100644
--- a/drivers/net/3c505.c
+++ b/drivers/net/3c505.c
@@ -1317,8 +1317,7 @@ static int __init elp_sense(struct net_device *dev)
1317 if (orig_HSR & DIR) { 1317 if (orig_HSR & DIR) {
1318 /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */ 1318 /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */
1319 outb(0, dev->base_addr + PORT_CONTROL); 1319 outb(0, dev->base_addr + PORT_CONTROL);
1320 set_current_state(TASK_UNINTERRUPTIBLE); 1320 msleep(300);
1321 schedule_timeout(30*HZ/100);
1322 if (inb_status(addr) & DIR) { 1321 if (inb_status(addr) & DIR) {
1323 if (elp_debug > 0) 1322 if (elp_debug > 0)
1324 printk(notfound_msg, 2); 1323 printk(notfound_msg, 2);
@@ -1327,8 +1326,7 @@ static int __init elp_sense(struct net_device *dev)
1327 } else { 1326 } else {
1328 /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */ 1327 /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */
1329 outb(DIR, dev->base_addr + PORT_CONTROL); 1328 outb(DIR, dev->base_addr + PORT_CONTROL);
1330 set_current_state(TASK_UNINTERRUPTIBLE); 1329 msleep(300);
1331 schedule_timeout(30*HZ/100);
1332 if (!(inb_status(addr) & DIR)) { 1330 if (!(inb_status(addr) & DIR)) {
1333 if (elp_debug > 0) 1331 if (elp_debug > 0)
1334 printk(notfound_msg, 3); 1332 printk(notfound_msg, 3);
diff --git a/drivers/net/3c509.c b/drivers/net/3c509.c
index e843109d4f62..977935a3d898 100644
--- a/drivers/net/3c509.c
+++ b/drivers/net/3c509.c
@@ -217,6 +217,7 @@ static void el3_poll_controller(struct net_device *dev);
217static struct eisa_device_id el3_eisa_ids[] = { 217static struct eisa_device_id el3_eisa_ids[] = {
218 { "TCM5092" }, 218 { "TCM5092" },
219 { "TCM5093" }, 219 { "TCM5093" },
220 { "TCM5095" },
220 { "" } 221 { "" }
221}; 222};
222 223
diff --git a/drivers/net/3c515.c b/drivers/net/3c515.c
index c4cf4fcd1344..91d1c4c24d9b 100644
--- a/drivers/net/3c515.c
+++ b/drivers/net/3c515.c
@@ -365,7 +365,7 @@ static int nopnp;
365#endif /* __ISAPNP__ */ 365#endif /* __ISAPNP__ */
366 366
367static struct net_device *corkscrew_scan(int unit); 367static struct net_device *corkscrew_scan(int unit);
368static void corkscrew_setup(struct net_device *dev, int ioaddr, 368static int corkscrew_setup(struct net_device *dev, int ioaddr,
369 struct pnp_dev *idev, int card_number); 369 struct pnp_dev *idev, int card_number);
370static int corkscrew_open(struct net_device *dev); 370static int corkscrew_open(struct net_device *dev);
371static void corkscrew_timer(unsigned long arg); 371static void corkscrew_timer(unsigned long arg);
@@ -539,10 +539,9 @@ static struct net_device *corkscrew_scan(int unit)
539 printk(KERN_INFO "3c515 Resource configuration register %#4.4x, DCR %4.4x.\n", 539 printk(KERN_INFO "3c515 Resource configuration register %#4.4x, DCR %4.4x.\n",
540 inl(ioaddr + 0x2002), inw(ioaddr + 0x2000)); 540 inl(ioaddr + 0x2002), inw(ioaddr + 0x2000));
541 /* irq = inw(ioaddr + 0x2002) & 15; */ /* Use the irq from isapnp */ 541 /* irq = inw(ioaddr + 0x2002) & 15; */ /* Use the irq from isapnp */
542 corkscrew_setup(dev, ioaddr, idev, cards_found++);
543 SET_NETDEV_DEV(dev, &idev->dev); 542 SET_NETDEV_DEV(dev, &idev->dev);
544 pnp_cards++; 543 pnp_cards++;
545 err = register_netdev(dev); 544 err = corkscrew_setup(dev, ioaddr, idev, cards_found++);
546 if (!err) 545 if (!err)
547 return dev; 546 return dev;
548 cleanup_card(dev); 547 cleanup_card(dev);
@@ -558,8 +557,7 @@ no_pnp:
558 557
559 printk(KERN_INFO "3c515 Resource configuration register %#4.4x, DCR %4.4x.\n", 558 printk(KERN_INFO "3c515 Resource configuration register %#4.4x, DCR %4.4x.\n",
560 inl(ioaddr + 0x2002), inw(ioaddr + 0x2000)); 559 inl(ioaddr + 0x2002), inw(ioaddr + 0x2000));
561 corkscrew_setup(dev, ioaddr, NULL, cards_found++); 560 err = corkscrew_setup(dev, ioaddr, NULL, cards_found++);
562 err = register_netdev(dev);
563 if (!err) 561 if (!err)
564 return dev; 562 return dev;
565 cleanup_card(dev); 563 cleanup_card(dev);
@@ -568,7 +566,7 @@ no_pnp:
568 return NULL; 566 return NULL;
569} 567}
570 568
571static void corkscrew_setup(struct net_device *dev, int ioaddr, 569static int corkscrew_setup(struct net_device *dev, int ioaddr,
572 struct pnp_dev *idev, int card_number) 570 struct pnp_dev *idev, int card_number)
573{ 571{
574 struct corkscrew_private *vp = netdev_priv(dev); 572 struct corkscrew_private *vp = netdev_priv(dev);
@@ -691,6 +689,8 @@ static void corkscrew_setup(struct net_device *dev, int ioaddr,
691 dev->get_stats = &corkscrew_get_stats; 689 dev->get_stats = &corkscrew_get_stats;
692 dev->set_multicast_list = &set_rx_mode; 690 dev->set_multicast_list = &set_rx_mode;
693 dev->ethtool_ops = &netdev_ethtool_ops; 691 dev->ethtool_ops = &netdev_ethtool_ops;
692
693 return register_netdev(dev);
694} 694}
695 695
696 696
@@ -822,7 +822,7 @@ static int corkscrew_open(struct net_device *dev)
822 break; /* Bad news! */ 822 break; /* Bad news! */
823 skb->dev = dev; /* Mark as being used by this device. */ 823 skb->dev = dev; /* Mark as being used by this device. */
824 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 824 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
825 vp->rx_ring[i].addr = isa_virt_to_bus(skb->tail); 825 vp->rx_ring[i].addr = isa_virt_to_bus(skb->data);
826 } 826 }
827 vp->rx_ring[i - 1].next = isa_virt_to_bus(&vp->rx_ring[0]); /* Wrap the ring. */ 827 vp->rx_ring[i - 1].next = isa_virt_to_bus(&vp->rx_ring[0]); /* Wrap the ring. */
828 outl(isa_virt_to_bus(&vp->rx_ring[0]), ioaddr + UpListPtr); 828 outl(isa_virt_to_bus(&vp->rx_ring[0]), ioaddr + UpListPtr);
@@ -1406,7 +1406,7 @@ static int boomerang_rx(struct net_device *dev)
1406 break; /* Bad news! */ 1406 break; /* Bad news! */
1407 skb->dev = dev; /* Mark as being used by this device. */ 1407 skb->dev = dev; /* Mark as being used by this device. */
1408 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 1408 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1409 vp->rx_ring[entry].addr = isa_virt_to_bus(skb->tail); 1409 vp->rx_ring[entry].addr = isa_virt_to_bus(skb->data);
1410 vp->rx_skbuff[entry] = skb; 1410 vp->rx_skbuff[entry] = skb;
1411 } 1411 }
1412 vp->rx_ring[entry].status = 0; /* Clear complete bit. */ 1412 vp->rx_ring[entry].status = 0; /* Clear complete bit. */
diff --git a/drivers/net/3c523.c b/drivers/net/3c523.c
index 8f6b2fa13e28..9e1fe2e0478c 100644
--- a/drivers/net/3c523.c
+++ b/drivers/net/3c523.c
@@ -572,6 +572,10 @@ static int __init do_elmc_probe(struct net_device *dev)
572 dev->flags&=~IFF_MULTICAST; /* Multicast doesn't work */ 572 dev->flags&=~IFF_MULTICAST; /* Multicast doesn't work */
573#endif 573#endif
574 574
575 retval = register_netdev(dev);
576 if (retval)
577 goto err_out;
578
575 return 0; 579 return 0;
576err_out: 580err_out:
577 mca_set_adapter_procfn(slot, NULL, NULL); 581 mca_set_adapter_procfn(slot, NULL, NULL);
@@ -600,12 +604,7 @@ struct net_device * __init elmc_probe(int unit)
600 err = do_elmc_probe(dev); 604 err = do_elmc_probe(dev);
601 if (err) 605 if (err)
602 goto out; 606 goto out;
603 err = register_netdev(dev);
604 if (err)
605 goto out1;
606 return dev; 607 return dev;
607out1:
608 cleanup_card(dev);
609out: 608out:
610 free_netdev(dev); 609 free_netdev(dev);
611 return ERR_PTR(err); 610 return ERR_PTR(err);
@@ -1275,6 +1274,7 @@ module_param_array(irq, int, NULL, 0);
1275module_param_array(io, int, NULL, 0); 1274module_param_array(io, int, NULL, 0);
1276MODULE_PARM_DESC(io, "EtherLink/MC I/O base address(es)"); 1275MODULE_PARM_DESC(io, "EtherLink/MC I/O base address(es)");
1277MODULE_PARM_DESC(irq, "EtherLink/MC IRQ number(s)"); 1276MODULE_PARM_DESC(irq, "EtherLink/MC IRQ number(s)");
1277MODULE_LICENSE("GPL");
1278 1278
1279int init_module(void) 1279int init_module(void)
1280{ 1280{
@@ -1288,12 +1288,9 @@ int init_module(void)
1288 dev->irq=irq[this_dev]; 1288 dev->irq=irq[this_dev];
1289 dev->base_addr=io[this_dev]; 1289 dev->base_addr=io[this_dev];
1290 if (do_elmc_probe(dev) == 0) { 1290 if (do_elmc_probe(dev) == 0) {
1291 if (register_netdev(dev) == 0) { 1291 dev_elmc[this_dev] = dev;
1292 dev_elmc[this_dev] = dev; 1292 found++;
1293 found++; 1293 continue;
1294 continue;
1295 }
1296 cleanup_card(dev);
1297 } 1294 }
1298 free_netdev(dev); 1295 free_netdev(dev);
1299 if (io[this_dev]==0) 1296 if (io[this_dev]==0)
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index 80ec9aa575bb..07746b95fd83 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -1802,7 +1802,7 @@ vortex_open(struct net_device *dev)
1802 break; /* Bad news! */ 1802 break; /* Bad news! */
1803 skb->dev = dev; /* Mark as being used by this device. */ 1803 skb->dev = dev; /* Mark as being used by this device. */
1804 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 1804 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1805 vp->rx_ring[i].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->tail, PKT_BUF_SZ, PCI_DMA_FROMDEVICE)); 1805 vp->rx_ring[i].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->data, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
1806 } 1806 }
1807 if (i != RX_RING_SIZE) { 1807 if (i != RX_RING_SIZE) {
1808 int j; 1808 int j;
@@ -2632,7 +2632,7 @@ boomerang_rx(struct net_device *dev)
2632 pci_dma_sync_single_for_cpu(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 2632 pci_dma_sync_single_for_cpu(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
2633 /* 'skb_put()' points to the start of sk_buff data area. */ 2633 /* 'skb_put()' points to the start of sk_buff data area. */
2634 memcpy(skb_put(skb, pkt_len), 2634 memcpy(skb_put(skb, pkt_len),
2635 vp->rx_skbuff[entry]->tail, 2635 vp->rx_skbuff[entry]->data,
2636 pkt_len); 2636 pkt_len);
2637 pci_dma_sync_single_for_device(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 2637 pci_dma_sync_single_for_device(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
2638 vp->rx_copy++; 2638 vp->rx_copy++;
@@ -2678,7 +2678,7 @@ boomerang_rx(struct net_device *dev)
2678 } 2678 }
2679 skb->dev = dev; /* Mark as being used by this device. */ 2679 skb->dev = dev; /* Mark as being used by this device. */
2680 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 2680 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
2681 vp->rx_ring[entry].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->tail, PKT_BUF_SZ, PCI_DMA_FROMDEVICE)); 2681 vp->rx_ring[entry].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->data, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
2682 vp->rx_skbuff[entry] = skb; 2682 vp->rx_skbuff[entry] = skb;
2683 } 2683 }
2684 vp->rx_ring[entry].status = 0; /* Clear complete bit. */ 2684 vp->rx_ring[entry].status = 0; /* Clear complete bit. */
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index 72cdf19e1be1..7b293f01c9ed 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -61,6 +61,7 @@
61#include <linux/etherdevice.h> 61#include <linux/etherdevice.h>
62#include <linux/init.h> 62#include <linux/init.h>
63#include <linux/pci.h> 63#include <linux/pci.h>
64#include <linux/dma-mapping.h>
64#include <linux/delay.h> 65#include <linux/delay.h>
65#include <linux/ethtool.h> 66#include <linux/ethtool.h>
66#include <linux/mii.h> 67#include <linux/mii.h>
@@ -595,7 +596,7 @@ rx_status_loop:
595 596
596 mapping = 597 mapping =
597 cp->rx_skb[rx_tail].mapping = 598 cp->rx_skb[rx_tail].mapping =
598 pci_map_single(cp->pdev, new_skb->tail, 599 pci_map_single(cp->pdev, new_skb->data,
599 buflen, PCI_DMA_FROMDEVICE); 600 buflen, PCI_DMA_FROMDEVICE);
600 cp->rx_skb[rx_tail].skb = new_skb; 601 cp->rx_skb[rx_tail].skb = new_skb;
601 602
@@ -1100,7 +1101,7 @@ static int cp_refill_rx (struct cp_private *cp)
1100 skb_reserve(skb, RX_OFFSET); 1101 skb_reserve(skb, RX_OFFSET);
1101 1102
1102 cp->rx_skb[i].mapping = pci_map_single(cp->pdev, 1103 cp->rx_skb[i].mapping = pci_map_single(cp->pdev,
1103 skb->tail, cp->rx_buf_sz, PCI_DMA_FROMDEVICE); 1104 skb->data, cp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1104 cp->rx_skb[i].skb = skb; 1105 cp->rx_skb[i].skb = skb;
1105 1106
1106 cp->rx_ring[i].opts2 = 0; 1107 cp->rx_ring[i].opts2 = 0;
@@ -1515,22 +1516,22 @@ static void cp_get_ethtool_stats (struct net_device *dev,
1515 struct ethtool_stats *estats, u64 *tmp_stats) 1516 struct ethtool_stats *estats, u64 *tmp_stats)
1516{ 1517{
1517 struct cp_private *cp = netdev_priv(dev); 1518 struct cp_private *cp = netdev_priv(dev);
1518 unsigned int work = 100;
1519 int i; 1519 int i;
1520 1520
1521 memset(cp->nic_stats, 0, sizeof(struct cp_dma_stats));
1522
1521 /* begin NIC statistics dump */ 1523 /* begin NIC statistics dump */
1522 cpw32(StatsAddr + 4, (cp->nic_stats_dma >> 16) >> 16); 1524 cpw32(StatsAddr + 4, (cp->nic_stats_dma >> 16) >> 16);
1523 cpw32(StatsAddr, (cp->nic_stats_dma & 0xffffffff) | DumpStats); 1525 cpw32(StatsAddr, (cp->nic_stats_dma & 0xffffffff) | DumpStats);
1524 cpr32(StatsAddr); 1526 cpr32(StatsAddr);
1525 1527
1526 while (work-- > 0) { 1528 for (i = 0; i < 1000; i++) {
1527 if ((cpr32(StatsAddr) & DumpStats) == 0) 1529 if ((cpr32(StatsAddr) & DumpStats) == 0)
1528 break; 1530 break;
1529 cpu_relax(); 1531 udelay(10);
1530 } 1532 }
1531 1533 cpw32(StatsAddr, 0);
1532 if (cpr32(StatsAddr) & DumpStats) 1534 cpw32(StatsAddr + 4, 0);
1533 return /* -EIO */;
1534 1535
1535 i = 0; 1536 i = 0;
1536 tmp_stats[i++] = le64_to_cpu(cp->nic_stats->tx_ok); 1537 tmp_stats[i++] = le64_to_cpu(cp->nic_stats->tx_ok);
@@ -1732,19 +1733,19 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1732 1733
1733 /* Configure DMA attributes. */ 1734 /* Configure DMA attributes. */
1734 if ((sizeof(dma_addr_t) > 4) && 1735 if ((sizeof(dma_addr_t) > 4) &&
1735 !pci_set_consistent_dma_mask(pdev, 0xffffffffffffffffULL) && 1736 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) &&
1736 !pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) { 1737 !pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
1737 pci_using_dac = 1; 1738 pci_using_dac = 1;
1738 } else { 1739 } else {
1739 pci_using_dac = 0; 1740 pci_using_dac = 0;
1740 1741
1741 rc = pci_set_dma_mask(pdev, 0xffffffffULL); 1742 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
1742 if (rc) { 1743 if (rc) {
1743 printk(KERN_ERR PFX "No usable DMA configuration, " 1744 printk(KERN_ERR PFX "No usable DMA configuration, "
1744 "aborting.\n"); 1745 "aborting.\n");
1745 goto err_out_res; 1746 goto err_out_res;
1746 } 1747 }
1747 rc = pci_set_consistent_dma_mask(pdev, 0xffffffffULL); 1748 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
1748 if (rc) { 1749 if (rc) {
1749 printk(KERN_ERR PFX "No usable consistent DMA configuration, " 1750 printk(KERN_ERR PFX "No usable consistent DMA configuration, "
1750 "aborting.\n"); 1751 "aborting.\n");
diff --git a/drivers/net/82596.c b/drivers/net/82596.c
index 65f97b1dc581..13b745b39667 100644
--- a/drivers/net/82596.c
+++ b/drivers/net/82596.c
@@ -546,11 +546,11 @@ static inline void init_rx_bufs(struct net_device *dev)
546 rbd->b_next = WSWAPrbd(virt_to_bus(rbd+1)); 546 rbd->b_next = WSWAPrbd(virt_to_bus(rbd+1));
547 rbd->b_addr = WSWAPrbd(virt_to_bus(rbd)); 547 rbd->b_addr = WSWAPrbd(virt_to_bus(rbd));
548 rbd->skb = skb; 548 rbd->skb = skb;
549 rbd->v_data = skb->tail; 549 rbd->v_data = skb->data;
550 rbd->b_data = WSWAPchar(virt_to_bus(skb->tail)); 550 rbd->b_data = WSWAPchar(virt_to_bus(skb->data));
551 rbd->size = PKT_BUF_SZ; 551 rbd->size = PKT_BUF_SZ;
552#ifdef __mc68000__ 552#ifdef __mc68000__
553 cache_clear(virt_to_phys(skb->tail), PKT_BUF_SZ); 553 cache_clear(virt_to_phys(skb->data), PKT_BUF_SZ);
554#endif 554#endif
555 } 555 }
556 lp->rbd_head = lp->rbds; 556 lp->rbd_head = lp->rbds;
@@ -816,10 +816,10 @@ static inline int i596_rx(struct net_device *dev)
816 rx_in_place = 1; 816 rx_in_place = 1;
817 rbd->skb = newskb; 817 rbd->skb = newskb;
818 newskb->dev = dev; 818 newskb->dev = dev;
819 rbd->v_data = newskb->tail; 819 rbd->v_data = newskb->data;
820 rbd->b_data = WSWAPchar(virt_to_bus(newskb->tail)); 820 rbd->b_data = WSWAPchar(virt_to_bus(newskb->data));
821#ifdef __mc68000__ 821#ifdef __mc68000__
822 cache_clear(virt_to_phys(newskb->tail), PKT_BUF_SZ); 822 cache_clear(virt_to_phys(newskb->data), PKT_BUF_SZ);
823#endif 823#endif
824 } 824 }
825 else 825 else
@@ -840,7 +840,7 @@ memory_squeeze:
840 skb->protocol=eth_type_trans(skb,dev); 840 skb->protocol=eth_type_trans(skb,dev);
841 skb->len = pkt_len; 841 skb->len = pkt_len;
842#ifdef __mc68000__ 842#ifdef __mc68000__
843 cache_clear(virt_to_phys(rbd->skb->tail), 843 cache_clear(virt_to_phys(rbd->skb->data),
844 pkt_len); 844 pkt_len);
845#endif 845#endif
846 netif_rx(skb); 846 netif_rx(skb);
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index fa9f76c953dd..2b55687f6ee9 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -1320,7 +1320,7 @@ config FORCEDETH
1320 1320
1321config CS89x0 1321config CS89x0
1322 tristate "CS89x0 support" 1322 tristate "CS89x0 support"
1323 depends on NET_PCI && (ISA || ARCH_IXDP2X01) 1323 depends on (NET_PCI && (ISA || ARCH_IXDP2X01)) || ARCH_PNX0105
1324 ---help--- 1324 ---help---
1325 Support for CS89x0 chipset based Ethernet cards. If you have a 1325 Support for CS89x0 chipset based Ethernet cards. If you have a
1326 network (Ethernet) card of this type, say Y and read the 1326 network (Ethernet) card of this type, say Y and read the
@@ -1488,14 +1488,14 @@ config 8139CP
1488 will be called 8139cp. This is recommended. 1488 will be called 8139cp. This is recommended.
1489 1489
1490config 8139TOO 1490config 8139TOO
1491 tristate "RealTek RTL-8139 PCI Fast Ethernet Adapter support" 1491 tristate "RealTek RTL-8129/8130/8139 PCI Fast Ethernet Adapter support"
1492 depends on NET_PCI && PCI 1492 depends on NET_PCI && PCI
1493 select CRC32 1493 select CRC32
1494 select MII 1494 select MII
1495 ---help--- 1495 ---help---
1496 This is a driver for the Fast Ethernet PCI network cards based on 1496 This is a driver for the Fast Ethernet PCI network cards based on
1497 the RTL8139 chips. If you have one of those, say Y and read 1497 the RTL 8129/8130/8139 chips. If you have one of those, say Y and
1498 the Ethernet-HOWTO <http://www.tldp.org/docs.html#howto>. 1498 read the Ethernet-HOWTO <http://www.tldp.org/docs.html#howto>.
1499 1499
1500 To compile this driver as a module, choose M here: the module 1500 To compile this driver as a module, choose M here: the module
1501 will be called 8139too. This is recommended. 1501 will be called 8139too. This is recommended.
diff --git a/drivers/net/ac3200.c b/drivers/net/ac3200.c
index 24fba36b5c1d..91791ba37769 100644
--- a/drivers/net/ac3200.c
+++ b/drivers/net/ac3200.c
@@ -146,12 +146,7 @@ struct net_device * __init ac3200_probe(int unit)
146 err = do_ac3200_probe(dev); 146 err = do_ac3200_probe(dev);
147 if (err) 147 if (err)
148 goto out; 148 goto out;
149 err = register_netdev(dev);
150 if (err)
151 goto out1;
152 return dev; 149 return dev;
153out1:
154 cleanup_card(dev);
155out: 150out:
156 free_netdev(dev); 151 free_netdev(dev);
157 return ERR_PTR(err); 152 return ERR_PTR(err);
@@ -273,7 +268,14 @@ static int __init ac_probe1(int ioaddr, struct net_device *dev)
273 dev->poll_controller = ei_poll; 268 dev->poll_controller = ei_poll;
274#endif 269#endif
275 NS8390_init(dev, 0); 270 NS8390_init(dev, 0);
271
272 retval = register_netdev(dev);
273 if (retval)
274 goto out2;
276 return 0; 275 return 0;
276out2:
277 if (ei_status.reg0)
278 iounmap((void *)dev->mem_start);
277out1: 279out1:
278 free_irq(dev->irq, dev); 280 free_irq(dev->irq, dev);
279out: 281out:
@@ -392,11 +394,8 @@ init_module(void)
392 dev->base_addr = io[this_dev]; 394 dev->base_addr = io[this_dev];
393 dev->mem_start = mem[this_dev]; /* Currently ignored by driver */ 395 dev->mem_start = mem[this_dev]; /* Currently ignored by driver */
394 if (do_ac3200_probe(dev) == 0) { 396 if (do_ac3200_probe(dev) == 0) {
395 if (register_netdev(dev) == 0) { 397 dev_ac32[found++] = dev;
396 dev_ac32[found++] = dev; 398 continue;
397 continue;
398 }
399 cleanup_card(dev);
400 } 399 }
401 free_netdev(dev); 400 free_netdev(dev);
402 printk(KERN_WARNING "ac3200.c: No ac3200 card found (i/o = 0x%x).\n", io[this_dev]); 401 printk(KERN_WARNING "ac3200.c: No ac3200 card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/acenic.c b/drivers/net/acenic.c
index 6eea3a8accb7..dbecc6bf7851 100644
--- a/drivers/net/acenic.c
+++ b/drivers/net/acenic.c
@@ -58,6 +58,7 @@
58#include <linux/errno.h> 58#include <linux/errno.h>
59#include <linux/ioport.h> 59#include <linux/ioport.h>
60#include <linux/pci.h> 60#include <linux/pci.h>
61#include <linux/dma-mapping.h>
61#include <linux/kernel.h> 62#include <linux/kernel.h>
62#include <linux/netdevice.h> 63#include <linux/netdevice.h>
63#include <linux/etherdevice.h> 64#include <linux/etherdevice.h>
@@ -1167,9 +1168,9 @@ static int __devinit ace_init(struct net_device *dev)
1167 /* 1168 /*
1168 * Configure DMA attributes. 1169 * Configure DMA attributes.
1169 */ 1170 */
1170 if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) { 1171 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
1171 ap->pci_using_dac = 1; 1172 ap->pci_using_dac = 1;
1172 } else if (!pci_set_dma_mask(pdev, 0xffffffffULL)) { 1173 } else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
1173 ap->pci_using_dac = 0; 1174 ap->pci_using_dac = 0;
1174 } else { 1175 } else {
1175 ecode = -ENODEV; 1176 ecode = -ENODEV;
diff --git a/drivers/net/amd8111e.c b/drivers/net/amd8111e.c
index b7dd7260cafb..8618012df06a 100755
--- a/drivers/net/amd8111e.c
+++ b/drivers/net/amd8111e.c
@@ -87,6 +87,7 @@ Revision History:
87#include <linux/if_vlan.h> 87#include <linux/if_vlan.h>
88#include <linux/ctype.h> 88#include <linux/ctype.h>
89#include <linux/crc32.h> 89#include <linux/crc32.h>
90#include <linux/dma-mapping.h>
90 91
91#include <asm/system.h> 92#include <asm/system.h>
92#include <asm/io.h> 93#include <asm/io.h>
@@ -2006,12 +2007,11 @@ static int __devinit amd8111e_probe_one(struct pci_dev *pdev,
2006 } 2007 }
2007 2008
2008 /* Initialize DMA */ 2009 /* Initialize DMA */
2009 if(!pci_dma_supported(pdev, 0xffffffff)){ 2010 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) < 0) {
2010 printk(KERN_ERR "amd8111e: DMA not supported," 2011 printk(KERN_ERR "amd8111e: DMA not supported,"
2011 "exiting.\n"); 2012 "exiting.\n");
2012 goto err_free_reg; 2013 goto err_free_reg;
2013 } else 2014 }
2014 pdev->dma_mask = 0xffffffff;
2015 2015
2016 reg_addr = pci_resource_start(pdev, 0); 2016 reg_addr = pci_resource_start(pdev, 0);
2017 reg_len = pci_resource_len(pdev, 0); 2017 reg_len = pci_resource_len(pdev, 0);
diff --git a/drivers/net/arm/etherh.c b/drivers/net/arm/etherh.c
index 2e28c201dcc0..942a2819576c 100644
--- a/drivers/net/arm/etherh.c
+++ b/drivers/net/arm/etherh.c
@@ -68,7 +68,6 @@ struct etherh_priv {
68 void __iomem *dma_base; 68 void __iomem *dma_base;
69 unsigned int id; 69 unsigned int id;
70 void __iomem *ctrl_port; 70 void __iomem *ctrl_port;
71 void __iomem *base;
72 unsigned char ctrl; 71 unsigned char ctrl;
73 u32 supported; 72 u32 supported;
74}; 73};
@@ -178,7 +177,7 @@ etherh_setif(struct net_device *dev)
178 switch (etherh_priv(dev)->id) { 177 switch (etherh_priv(dev)->id) {
179 case PROD_I3_ETHERLAN600: 178 case PROD_I3_ETHERLAN600:
180 case PROD_I3_ETHERLAN600A: 179 case PROD_I3_ETHERLAN600A:
181 addr = etherh_priv(dev)->base + EN0_RCNTHI; 180 addr = (void *)dev->base_addr + EN0_RCNTHI;
182 181
183 switch (dev->if_port) { 182 switch (dev->if_port) {
184 case IF_PORT_10BASE2: 183 case IF_PORT_10BASE2:
@@ -219,7 +218,7 @@ etherh_getifstat(struct net_device *dev)
219 switch (etherh_priv(dev)->id) { 218 switch (etherh_priv(dev)->id) {
220 case PROD_I3_ETHERLAN600: 219 case PROD_I3_ETHERLAN600:
221 case PROD_I3_ETHERLAN600A: 220 case PROD_I3_ETHERLAN600A:
222 addr = etherh_priv(dev)->base + EN0_RCNTHI; 221 addr = (void *)dev->base_addr + EN0_RCNTHI;
223 switch (dev->if_port) { 222 switch (dev->if_port) {
224 case IF_PORT_10BASE2: 223 case IF_PORT_10BASE2:
225 stat = 1; 224 stat = 1;
@@ -282,7 +281,7 @@ static void
282etherh_reset(struct net_device *dev) 281etherh_reset(struct net_device *dev)
283{ 282{
284 struct ei_device *ei_local = netdev_priv(dev); 283 struct ei_device *ei_local = netdev_priv(dev);
285 void __iomem *addr = etherh_priv(dev)->base; 284 void __iomem *addr = (void *)dev->base_addr;
286 285
287 writeb(E8390_NODMA+E8390_PAGE0+E8390_STOP, addr); 286 writeb(E8390_NODMA+E8390_PAGE0+E8390_STOP, addr);
288 287
@@ -328,7 +327,7 @@ etherh_block_output (struct net_device *dev, int count, const unsigned char *buf
328 327
329 ei_local->dmaing = 1; 328 ei_local->dmaing = 1;
330 329
331 addr = etherh_priv(dev)->base; 330 addr = (void *)dev->base_addr;
332 dma_base = etherh_priv(dev)->dma_base; 331 dma_base = etherh_priv(dev)->dma_base;
333 332
334 count = (count + 1) & ~1; 333 count = (count + 1) & ~1;
@@ -388,7 +387,7 @@ etherh_block_input (struct net_device *dev, int count, struct sk_buff *skb, int
388 387
389 ei_local->dmaing = 1; 388 ei_local->dmaing = 1;
390 389
391 addr = etherh_priv(dev)->base; 390 addr = (void *)dev->base_addr;
392 dma_base = etherh_priv(dev)->dma_base; 391 dma_base = etherh_priv(dev)->dma_base;
393 392
394 buf = skb->data; 393 buf = skb->data;
@@ -428,7 +427,7 @@ etherh_get_header (struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_p
428 427
429 ei_local->dmaing = 1; 428 ei_local->dmaing = 1;
430 429
431 addr = etherh_priv(dev)->base; 430 addr = (void *)dev->base_addr;
432 dma_base = etherh_priv(dev)->dma_base; 431 dma_base = etherh_priv(dev)->dma_base;
433 432
434 writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD); 433 writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
@@ -697,8 +696,7 @@ etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
697 eh->ctrl_port = eh->ioc_fast; 696 eh->ctrl_port = eh->ioc_fast;
698 } 697 }
699 698
700 eh->base = eh->memc + data->ns8390_offset; 699 dev->base_addr = (unsigned long)eh->memc + data->ns8390_offset;
701 dev->base_addr = (unsigned long)eh->base;
702 eh->dma_base = eh->memc + data->dataport_offset; 700 eh->dma_base = eh->memc + data->dataport_offset;
703 eh->ctrl_port += data->ctrlport_offset; 701 eh->ctrl_port += data->ctrlport_offset;
704 702
diff --git a/drivers/net/at1700.c b/drivers/net/at1700.c
index b8ab2b6355eb..e613cc289749 100644
--- a/drivers/net/at1700.c
+++ b/drivers/net/at1700.c
@@ -34,10 +34,6 @@
34 only is it difficult to detect, it also moves around in I/O space in 34 only is it difficult to detect, it also moves around in I/O space in
35 response to inb()s from other device probes! 35 response to inb()s from other device probes!
36*/ 36*/
37/*
38 99/03/03 Allied Telesis RE1000 Plus support by T.Hagawa
39 99/12/30 port to 2.3.35 by K.Takai
40*/
41 37
42#include <linux/config.h> 38#include <linux/config.h>
43#include <linux/errno.h> 39#include <linux/errno.h>
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index 3fe8ba992c38..f1bd45e3da31 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -1285,6 +1285,9 @@ static int b44_open(struct net_device *dev)
1285 b44_init_hw(bp); 1285 b44_init_hw(bp);
1286 bp->flags |= B44_FLAG_INIT_COMPLETE; 1286 bp->flags |= B44_FLAG_INIT_COMPLETE;
1287 1287
1288 netif_carrier_off(dev);
1289 b44_check_phy(bp);
1290
1288 spin_unlock_irq(&bp->lock); 1291 spin_unlock_irq(&bp->lock);
1289 1292
1290 init_timer(&bp->timer); 1293 init_timer(&bp->timer);
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index 6233c4ffb805..a2e8dda5afac 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -2346,7 +2346,6 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
2346{ 2346{
2347 struct slave *slave, *start_at; 2347 struct slave *slave, *start_at;
2348 struct bonding *bond = dev->priv; 2348 struct bonding *bond = dev->priv;
2349 struct ethhdr *data = (struct ethhdr *)skb->data;
2350 int slave_agg_no; 2349 int slave_agg_no;
2351 int slaves_in_agg; 2350 int slaves_in_agg;
2352 int agg_id; 2351 int agg_id;
@@ -2377,7 +2376,7 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
2377 goto out; 2376 goto out;
2378 } 2377 }
2379 2378
2380 slave_agg_no = (data->h_dest[5]^bond->dev->dev_addr[5]) % slaves_in_agg; 2379 slave_agg_no = bond->xmit_hash_policy(skb, dev, slaves_in_agg);
2381 2380
2382 bond_for_each_slave(bond, slave, i) { 2381 bond_for_each_slave(bond, slave, i) {
2383 struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator; 2382 struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator;
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 269a5e407349..2c930da90a85 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -475,7 +475,18 @@
475 * Solution is to move call to dev_remove_pack outside of the 475 * Solution is to move call to dev_remove_pack outside of the
476 * spinlock. 476 * spinlock.
477 * Set version to 2.6.1. 477 * Set version to 2.6.1.
478 * 478 * 2005/06/05 - Jay Vosburgh <fubar@us.ibm.com>
479 * - Support for generating gratuitous ARPs in active-backup mode.
480 * Includes support for VLAN tagging all bonding-generated ARPs
481 * as needed. Set version to 2.6.2.
482 * 2005/06/08 - Jason Gabler <jygabler at lbl dot gov>
483 * - alternate hashing policy support for mode 2
484 * * Added kernel parameter "xmit_hash_policy" to allow the selection
485 * of different hashing policies for mode 2. The original mode 2
486 * policy is the default, now found in xmit_hash_policy_layer2().
487 * * Added xmit_hash_policy_layer34()
488 * - Modified by Jay Vosburgh <fubar@us.ibm.com> to also support mode 4.
489 * Set version to 2.6.3.
479 */ 490 */
480 491
481//#define BONDING_DEBUG 1 492//#define BONDING_DEBUG 1
@@ -490,7 +501,10 @@
490#include <linux/ptrace.h> 501#include <linux/ptrace.h>
491#include <linux/ioport.h> 502#include <linux/ioport.h>
492#include <linux/in.h> 503#include <linux/in.h>
504#include <net/ip.h>
493#include <linux/ip.h> 505#include <linux/ip.h>
506#include <linux/tcp.h>
507#include <linux/udp.h>
494#include <linux/slab.h> 508#include <linux/slab.h>
495#include <linux/string.h> 509#include <linux/string.h>
496#include <linux/init.h> 510#include <linux/init.h>
@@ -519,6 +533,7 @@
519#include <linux/ethtool.h> 533#include <linux/ethtool.h>
520#include <linux/if_vlan.h> 534#include <linux/if_vlan.h>
521#include <linux/if_bonding.h> 535#include <linux/if_bonding.h>
536#include <net/route.h>
522#include "bonding.h" 537#include "bonding.h"
523#include "bond_3ad.h" 538#include "bond_3ad.h"
524#include "bond_alb.h" 539#include "bond_alb.h"
@@ -537,6 +552,7 @@ static int use_carrier = 1;
537static char *mode = NULL; 552static char *mode = NULL;
538static char *primary = NULL; 553static char *primary = NULL;
539static char *lacp_rate = NULL; 554static char *lacp_rate = NULL;
555static char *xmit_hash_policy = NULL;
540static int arp_interval = BOND_LINK_ARP_INTERV; 556static int arp_interval = BOND_LINK_ARP_INTERV;
541static char *arp_ip_target[BOND_MAX_ARP_TARGETS] = { NULL, }; 557static char *arp_ip_target[BOND_MAX_ARP_TARGETS] = { NULL, };
542 558
@@ -556,6 +572,8 @@ module_param(primary, charp, 0);
556MODULE_PARM_DESC(primary, "Primary network device to use"); 572MODULE_PARM_DESC(primary, "Primary network device to use");
557module_param(lacp_rate, charp, 0); 573module_param(lacp_rate, charp, 0);
558MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner (slow/fast)"); 574MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner (slow/fast)");
575module_param(xmit_hash_policy, charp, 0);
576MODULE_PARM_DESC(xmit_hash_policy, "XOR hashing method : 0 for layer 2 (default), 1 for layer 3+4");
559module_param(arp_interval, int, 0); 577module_param(arp_interval, int, 0);
560MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds"); 578MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds");
561module_param_array(arp_ip_target, charp, NULL, 0); 579module_param_array(arp_ip_target, charp, NULL, 0);
@@ -574,8 +592,8 @@ static struct proc_dir_entry *bond_proc_dir = NULL;
574 592
575static u32 arp_target[BOND_MAX_ARP_TARGETS] = { 0, } ; 593static u32 arp_target[BOND_MAX_ARP_TARGETS] = { 0, } ;
576static int arp_ip_count = 0; 594static int arp_ip_count = 0;
577static u32 my_ip = 0;
578static int bond_mode = BOND_MODE_ROUNDROBIN; 595static int bond_mode = BOND_MODE_ROUNDROBIN;
596static int xmit_hashtype= BOND_XMIT_POLICY_LAYER2;
579static int lacp_fast = 0; 597static int lacp_fast = 0;
580static int app_abi_ver = 0; 598static int app_abi_ver = 0;
581static int orig_app_abi_ver = -1; /* This is used to save the first ABI version 599static int orig_app_abi_ver = -1; /* This is used to save the first ABI version
@@ -585,7 +603,6 @@ static int orig_app_abi_ver = -1; /* This is used to save the first ABI version
585 * command comes from an application using 603 * command comes from an application using
586 * another ABI version. 604 * another ABI version.
587 */ 605 */
588
589struct bond_parm_tbl { 606struct bond_parm_tbl {
590 char *modename; 607 char *modename;
591 int mode; 608 int mode;
@@ -608,9 +625,16 @@ static struct bond_parm_tbl bond_mode_tbl[] = {
608{ NULL, -1}, 625{ NULL, -1},
609}; 626};
610 627
628static struct bond_parm_tbl xmit_hashtype_tbl[] = {
629{ "layer2", BOND_XMIT_POLICY_LAYER2},
630{ "layer3+4", BOND_XMIT_POLICY_LAYER34},
631{ NULL, -1},
632};
633
611/*-------------------------- Forward declarations ---------------------------*/ 634/*-------------------------- Forward declarations ---------------------------*/
612 635
613static inline void bond_set_mode_ops(struct net_device *bond_dev, int mode); 636static inline void bond_set_mode_ops(struct bonding *bond, int mode);
637static void bond_send_gratuitous_arp(struct bonding *bond);
614 638
615/*---------------------------- General routines -----------------------------*/ 639/*---------------------------- General routines -----------------------------*/
616 640
@@ -659,6 +683,7 @@ static int bond_add_vlan(struct bonding *bond, unsigned short vlan_id)
659 683
660 INIT_LIST_HEAD(&vlan->vlan_list); 684 INIT_LIST_HEAD(&vlan->vlan_list);
661 vlan->vlan_id = vlan_id; 685 vlan->vlan_id = vlan_id;
686 vlan->vlan_ip = 0;
662 687
663 write_lock_bh(&bond->lock); 688 write_lock_bh(&bond->lock);
664 689
@@ -1468,16 +1493,6 @@ static void bond_change_active_slave(struct bonding *bond, struct slave *new_act
1468 } 1493 }
1469 } 1494 }
1470 1495
1471 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
1472 if (old_active) {
1473 bond_set_slave_inactive_flags(old_active);
1474 }
1475
1476 if (new_active) {
1477 bond_set_slave_active_flags(new_active);
1478 }
1479 }
1480
1481 if (USES_PRIMARY(bond->params.mode)) { 1496 if (USES_PRIMARY(bond->params.mode)) {
1482 bond_mc_swap(bond, new_active, old_active); 1497 bond_mc_swap(bond, new_active, old_active);
1483 } 1498 }
@@ -1488,6 +1503,17 @@ static void bond_change_active_slave(struct bonding *bond, struct slave *new_act
1488 } else { 1503 } else {
1489 bond->curr_active_slave = new_active; 1504 bond->curr_active_slave = new_active;
1490 } 1505 }
1506
1507 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
1508 if (old_active) {
1509 bond_set_slave_inactive_flags(old_active);
1510 }
1511
1512 if (new_active) {
1513 bond_set_slave_active_flags(new_active);
1514 }
1515 bond_send_gratuitous_arp(bond);
1516 }
1491} 1517}
1492 1518
1493/** 1519/**
@@ -2694,15 +2720,180 @@ out:
2694 read_unlock(&bond->lock); 2720 read_unlock(&bond->lock);
2695} 2721}
2696 2722
2723
2724static u32 bond_glean_dev_ip(struct net_device *dev)
2725{
2726 struct in_device *idev;
2727 struct in_ifaddr *ifa;
2728 u32 addr = 0;
2729
2730 if (!dev)
2731 return 0;
2732
2733 rcu_read_lock();
2734 idev = __in_dev_get(dev);
2735 if (!idev)
2736 goto out;
2737
2738 ifa = idev->ifa_list;
2739 if (!ifa)
2740 goto out;
2741
2742 addr = ifa->ifa_local;
2743out:
2744 rcu_read_unlock();
2745 return addr;
2746}
2747
2748static int bond_has_ip(struct bonding *bond)
2749{
2750 struct vlan_entry *vlan, *vlan_next;
2751
2752 if (bond->master_ip)
2753 return 1;
2754
2755 if (list_empty(&bond->vlan_list))
2756 return 0;
2757
2758 list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
2759 vlan_list) {
2760 if (vlan->vlan_ip)
2761 return 1;
2762 }
2763
2764 return 0;
2765}
2766
2767/*
2768 * We go to the (large) trouble of VLAN tagging ARP frames because
2769 * switches in VLAN mode (especially if ports are configured as
2770 * "native" to a VLAN) might not pass non-tagged frames.
2771 */
2772static void bond_arp_send(struct net_device *slave_dev, int arp_op, u32 dest_ip, u32 src_ip, unsigned short vlan_id)
2773{
2774 struct sk_buff *skb;
2775
2776 dprintk("arp %d on slave %s: dst %x src %x vid %d\n", arp_op,
2777 slave_dev->name, dest_ip, src_ip, vlan_id);
2778
2779 skb = arp_create(arp_op, ETH_P_ARP, dest_ip, slave_dev, src_ip,
2780 NULL, slave_dev->dev_addr, NULL);
2781
2782 if (!skb) {
2783 printk(KERN_ERR DRV_NAME ": ARP packet allocation failed\n");
2784 return;
2785 }
2786 if (vlan_id) {
2787 skb = vlan_put_tag(skb, vlan_id);
2788 if (!skb) {
2789 printk(KERN_ERR DRV_NAME ": failed to insert VLAN tag\n");
2790 return;
2791 }
2792 }
2793 arp_xmit(skb);
2794}
2795
2796
2697static void bond_arp_send_all(struct bonding *bond, struct slave *slave) 2797static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
2698{ 2798{
2699 int i; 2799 int i, vlan_id, rv;
2700 u32 *targets = bond->params.arp_targets; 2800 u32 *targets = bond->params.arp_targets;
2801 struct vlan_entry *vlan, *vlan_next;
2802 struct net_device *vlan_dev;
2803 struct flowi fl;
2804 struct rtable *rt;
2701 2805
2702 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) { 2806 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) {
2703 arp_send(ARPOP_REQUEST, ETH_P_ARP, targets[i], slave->dev, 2807 dprintk("basa: target %x\n", targets[i]);
2704 my_ip, NULL, slave->dev->dev_addr, 2808 if (list_empty(&bond->vlan_list)) {
2705 NULL); 2809 dprintk("basa: empty vlan: arp_send\n");
2810 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2811 bond->master_ip, 0);
2812 continue;
2813 }
2814
2815 /*
2816 * If VLANs are configured, we do a route lookup to
2817 * determine which VLAN interface would be used, so we
2818 * can tag the ARP with the proper VLAN tag.
2819 */
2820 memset(&fl, 0, sizeof(fl));
2821 fl.fl4_dst = targets[i];
2822 fl.fl4_tos = RTO_ONLINK;
2823
2824 rv = ip_route_output_key(&rt, &fl);
2825 if (rv) {
2826 if (net_ratelimit()) {
2827 printk(KERN_WARNING DRV_NAME
2828 ": %s: no route to arp_ip_target %u.%u.%u.%u\n",
2829 bond->dev->name, NIPQUAD(fl.fl4_dst));
2830 }
2831 continue;
2832 }
2833
2834 /*
2835 * This target is not on a VLAN
2836 */
2837 if (rt->u.dst.dev == bond->dev) {
2838 dprintk("basa: rtdev == bond->dev: arp_send\n");
2839 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2840 bond->master_ip, 0);
2841 continue;
2842 }
2843
2844 vlan_id = 0;
2845 list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
2846 vlan_list) {
2847 vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
2848 if (vlan_dev == rt->u.dst.dev) {
2849 vlan_id = vlan->vlan_id;
2850 dprintk("basa: vlan match on %s %d\n",
2851 vlan_dev->name, vlan_id);
2852 break;
2853 }
2854 }
2855
2856 if (vlan_id) {
2857 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2858 vlan->vlan_ip, vlan_id);
2859 continue;
2860 }
2861
2862 if (net_ratelimit()) {
2863 printk(KERN_WARNING DRV_NAME
2864 ": %s: no path to arp_ip_target %u.%u.%u.%u via rt.dev %s\n",
2865 bond->dev->name, NIPQUAD(fl.fl4_dst),
2866 rt->u.dst.dev ? rt->u.dst.dev->name : "NULL");
2867 }
2868 }
2869}
2870
2871/*
2872 * Kick out a gratuitous ARP for an IP on the bonding master plus one
2873 * for each VLAN above us.
2874 */
2875static void bond_send_gratuitous_arp(struct bonding *bond)
2876{
2877 struct slave *slave = bond->curr_active_slave;
2878 struct vlan_entry *vlan;
2879 struct net_device *vlan_dev;
2880
2881 dprintk("bond_send_grat_arp: bond %s slave %s\n", bond->dev->name,
2882 slave ? slave->dev->name : "NULL");
2883 if (!slave)
2884 return;
2885
2886 if (bond->master_ip) {
2887 bond_arp_send(slave->dev, ARPOP_REPLY, bond->master_ip,
2888 bond->master_ip, 0);
2889 }
2890
2891 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
2892 vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
2893 if (vlan->vlan_ip) {
2894 bond_arp_send(slave->dev, ARPOP_REPLY, vlan->vlan_ip,
2895 vlan->vlan_ip, vlan->vlan_id);
2896 }
2706 } 2897 }
2707} 2898}
2708 2899
@@ -2781,7 +2972,7 @@ static void bond_loadbalance_arp_mon(struct net_device *bond_dev)
2781 */ 2972 */
2782 if (((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) || 2973 if (((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) ||
2783 (((jiffies - slave->dev->last_rx) >= (2*delta_in_ticks)) && 2974 (((jiffies - slave->dev->last_rx) >= (2*delta_in_ticks)) &&
2784 my_ip)) { 2975 bond_has_ip(bond))) {
2785 2976
2786 slave->link = BOND_LINK_DOWN; 2977 slave->link = BOND_LINK_DOWN;
2787 slave->state = BOND_STATE_BACKUP; 2978 slave->state = BOND_STATE_BACKUP;
@@ -2920,7 +3111,7 @@ static void bond_activebackup_arp_mon(struct net_device *bond_dev)
2920 if ((slave != bond->curr_active_slave) && 3111 if ((slave != bond->curr_active_slave) &&
2921 (!bond->current_arp_slave) && 3112 (!bond->current_arp_slave) &&
2922 (((jiffies - slave->dev->last_rx) >= 3*delta_in_ticks) && 3113 (((jiffies - slave->dev->last_rx) >= 3*delta_in_ticks) &&
2923 my_ip)) { 3114 bond_has_ip(bond))) {
2924 /* a backup slave has gone down; three times 3115 /* a backup slave has gone down; three times
2925 * the delta allows the current slave to be 3116 * the delta allows the current slave to be
2926 * taken out before the backup slave. 3117 * taken out before the backup slave.
@@ -2966,8 +3157,8 @@ static void bond_activebackup_arp_mon(struct net_device *bond_dev)
2966 * if it is up and needs to take over as the curr_active_slave 3157 * if it is up and needs to take over as the curr_active_slave
2967 */ 3158 */
2968 if ((((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) || 3159 if ((((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) ||
2969 (((jiffies - slave->dev->last_rx) >= (2*delta_in_ticks)) && 3160 (((jiffies - slave->dev->last_rx) >= (2*delta_in_ticks)) &&
2970 my_ip)) && 3161 bond_has_ip(bond))) &&
2971 ((jiffies - slave->jiffies) >= 2*delta_in_ticks)) { 3162 ((jiffies - slave->jiffies) >= 2*delta_in_ticks)) {
2972 3163
2973 slave->link = BOND_LINK_DOWN; 3164 slave->link = BOND_LINK_DOWN;
@@ -3019,7 +3210,7 @@ static void bond_activebackup_arp_mon(struct net_device *bond_dev)
3019 /* the current slave must tx an arp to ensure backup slaves 3210 /* the current slave must tx an arp to ensure backup slaves
3020 * rx traffic 3211 * rx traffic
3021 */ 3212 */
3022 if (slave && my_ip) { 3213 if (slave && bond_has_ip(bond)) {
3023 bond_arp_send_all(bond, slave); 3214 bond_arp_send_all(bond, slave);
3024 } 3215 }
3025 } 3216 }
@@ -3471,10 +3662,67 @@ static int bond_netdev_event(struct notifier_block *this, unsigned long event, v
3471 return NOTIFY_DONE; 3662 return NOTIFY_DONE;
3472} 3663}
3473 3664
3665/*
3666 * bond_inetaddr_event: handle inetaddr notifier chain events.
3667 *
3668 * We keep track of device IPs primarily to use as source addresses in
3669 * ARP monitor probes (rather than spewing out broadcasts all the time).
3670 *
3671 * We track one IP for the main device (if it has one), plus one per VLAN.
3672 */
3673static int bond_inetaddr_event(struct notifier_block *this, unsigned long event, void *ptr)
3674{
3675 struct in_ifaddr *ifa = ptr;
3676 struct net_device *vlan_dev, *event_dev = ifa->ifa_dev->dev;
3677 struct bonding *bond, *bond_next;
3678 struct vlan_entry *vlan, *vlan_next;
3679
3680 list_for_each_entry_safe(bond, bond_next, &bond_dev_list, bond_list) {
3681 if (bond->dev == event_dev) {
3682 switch (event) {
3683 case NETDEV_UP:
3684 bond->master_ip = ifa->ifa_local;
3685 return NOTIFY_OK;
3686 case NETDEV_DOWN:
3687 bond->master_ip = bond_glean_dev_ip(bond->dev);
3688 return NOTIFY_OK;
3689 default:
3690 return NOTIFY_DONE;
3691 }
3692 }
3693
3694 if (list_empty(&bond->vlan_list))
3695 continue;
3696
3697 list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
3698 vlan_list) {
3699 vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
3700 if (vlan_dev == event_dev) {
3701 switch (event) {
3702 case NETDEV_UP:
3703 vlan->vlan_ip = ifa->ifa_local;
3704 return NOTIFY_OK;
3705 case NETDEV_DOWN:
3706 vlan->vlan_ip =
3707 bond_glean_dev_ip(vlan_dev);
3708 return NOTIFY_OK;
3709 default:
3710 return NOTIFY_DONE;
3711 }
3712 }
3713 }
3714 }
3715 return NOTIFY_DONE;
3716}
3717
3474static struct notifier_block bond_netdev_notifier = { 3718static struct notifier_block bond_netdev_notifier = {
3475 .notifier_call = bond_netdev_event, 3719 .notifier_call = bond_netdev_event,
3476}; 3720};
3477 3721
3722static struct notifier_block bond_inetaddr_notifier = {
3723 .notifier_call = bond_inetaddr_event,
3724};
3725
3478/*-------------------------- Packet type handling ---------------------------*/ 3726/*-------------------------- Packet type handling ---------------------------*/
3479 3727
3480/* register to receive lacpdus on a bond */ 3728/* register to receive lacpdus on a bond */
@@ -3496,6 +3744,46 @@ static void bond_unregister_lacpdu(struct bonding *bond)
3496 dev_remove_pack(&(BOND_AD_INFO(bond).ad_pkt_type)); 3744 dev_remove_pack(&(BOND_AD_INFO(bond).ad_pkt_type));
3497} 3745}
3498 3746
3747/*---------------------------- Hashing Policies -----------------------------*/
3748
3749/*
3750 * Hash for the the output device based upon layer 3 and layer 4 data. If
3751 * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is
3752 * altogether not IP, mimic bond_xmit_hash_policy_l2()
3753 */
3754static int bond_xmit_hash_policy_l34(struct sk_buff *skb,
3755 struct net_device *bond_dev, int count)
3756{
3757 struct ethhdr *data = (struct ethhdr *)skb->data;
3758 struct iphdr *iph = skb->nh.iph;
3759 u16 *layer4hdr = (u16 *)((u32 *)iph + iph->ihl);
3760 int layer4_xor = 0;
3761
3762 if (skb->protocol == __constant_htons(ETH_P_IP)) {
3763 if (!(iph->frag_off & __constant_htons(IP_MF|IP_OFFSET)) &&
3764 (iph->protocol == IPPROTO_TCP ||
3765 iph->protocol == IPPROTO_UDP)) {
3766 layer4_xor = htons((*layer4hdr ^ *(layer4hdr + 1)));
3767 }
3768 return (layer4_xor ^
3769 ((ntohl(iph->saddr ^ iph->daddr)) & 0xffff)) % count;
3770
3771 }
3772
3773 return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count;
3774}
3775
3776/*
3777 * Hash for the output device based upon layer 2 data
3778 */
3779static int bond_xmit_hash_policy_l2(struct sk_buff *skb,
3780 struct net_device *bond_dev, int count)
3781{
3782 struct ethhdr *data = (struct ethhdr *)skb->data;
3783
3784 return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count;
3785}
3786
3499/*-------------------------- Device entry points ----------------------------*/ 3787/*-------------------------- Device entry points ----------------------------*/
3500 3788
3501static int bond_open(struct net_device *bond_dev) 3789static int bond_open(struct net_device *bond_dev)
@@ -4060,17 +4348,6 @@ static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_d
4060 struct bonding *bond = bond_dev->priv; 4348 struct bonding *bond = bond_dev->priv;
4061 int res = 1; 4349 int res = 1;
4062 4350
4063 /* if we are sending arp packets, try to at least
4064 identify our own ip address */
4065 if (bond->params.arp_interval && !my_ip &&
4066 (skb->protocol == __constant_htons(ETH_P_ARP))) {
4067 char *the_ip = (char *)skb->data +
4068 sizeof(struct ethhdr) +
4069 sizeof(struct arphdr) +
4070 ETH_ALEN;
4071 memcpy(&my_ip, the_ip, 4);
4072 }
4073
4074 read_lock(&bond->lock); 4351 read_lock(&bond->lock);
4075 read_lock(&bond->curr_slave_lock); 4352 read_lock(&bond->curr_slave_lock);
4076 4353
@@ -4093,14 +4370,13 @@ out:
4093} 4370}
4094 4371
4095/* 4372/*
4096 * in XOR mode, we determine the output device by performing xor on 4373 * In bond_xmit_xor() , we determine the output device by using a pre-
4097 * the source and destination hw adresses. If this device is not 4374 * determined xmit_hash_policy(), If the selected device is not enabled,
4098 * enabled, find the next slave following this xor slave. 4375 * find the next active slave.
4099 */ 4376 */
4100static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev) 4377static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev)
4101{ 4378{
4102 struct bonding *bond = bond_dev->priv; 4379 struct bonding *bond = bond_dev->priv;
4103 struct ethhdr *data = (struct ethhdr *)skb->data;
4104 struct slave *slave, *start_at; 4380 struct slave *slave, *start_at;
4105 int slave_no; 4381 int slave_no;
4106 int i; 4382 int i;
@@ -4112,7 +4388,7 @@ static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev)
4112 goto out; 4388 goto out;
4113 } 4389 }
4114 4390
4115 slave_no = (data->h_dest[5]^bond_dev->dev_addr[5]) % bond->slave_cnt; 4391 slave_no = bond->xmit_hash_policy(skb, bond_dev, bond->slave_cnt);
4116 4392
4117 bond_for_each_slave(bond, slave, i) { 4393 bond_for_each_slave(bond, slave, i) {
4118 slave_no--; 4394 slave_no--;
@@ -4208,8 +4484,10 @@ out:
4208/* 4484/*
4209 * set bond mode specific net device operations 4485 * set bond mode specific net device operations
4210 */ 4486 */
4211static inline void bond_set_mode_ops(struct net_device *bond_dev, int mode) 4487static inline void bond_set_mode_ops(struct bonding *bond, int mode)
4212{ 4488{
4489 struct net_device *bond_dev = bond->dev;
4490
4213 switch (mode) { 4491 switch (mode) {
4214 case BOND_MODE_ROUNDROBIN: 4492 case BOND_MODE_ROUNDROBIN:
4215 bond_dev->hard_start_xmit = bond_xmit_roundrobin; 4493 bond_dev->hard_start_xmit = bond_xmit_roundrobin;
@@ -4219,12 +4497,20 @@ static inline void bond_set_mode_ops(struct net_device *bond_dev, int mode)
4219 break; 4497 break;
4220 case BOND_MODE_XOR: 4498 case BOND_MODE_XOR:
4221 bond_dev->hard_start_xmit = bond_xmit_xor; 4499 bond_dev->hard_start_xmit = bond_xmit_xor;
4500 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34)
4501 bond->xmit_hash_policy = bond_xmit_hash_policy_l34;
4502 else
4503 bond->xmit_hash_policy = bond_xmit_hash_policy_l2;
4222 break; 4504 break;
4223 case BOND_MODE_BROADCAST: 4505 case BOND_MODE_BROADCAST:
4224 bond_dev->hard_start_xmit = bond_xmit_broadcast; 4506 bond_dev->hard_start_xmit = bond_xmit_broadcast;
4225 break; 4507 break;
4226 case BOND_MODE_8023AD: 4508 case BOND_MODE_8023AD:
4227 bond_dev->hard_start_xmit = bond_3ad_xmit_xor; 4509 bond_dev->hard_start_xmit = bond_3ad_xmit_xor;
4510 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34)
4511 bond->xmit_hash_policy = bond_xmit_hash_policy_l34;
4512 else
4513 bond->xmit_hash_policy = bond_xmit_hash_policy_l2;
4228 break; 4514 break;
4229 case BOND_MODE_TLB: 4515 case BOND_MODE_TLB:
4230 case BOND_MODE_ALB: 4516 case BOND_MODE_ALB:
@@ -4273,7 +4559,7 @@ static int __init bond_init(struct net_device *bond_dev, struct bond_params *par
4273 bond_dev->change_mtu = bond_change_mtu; 4559 bond_dev->change_mtu = bond_change_mtu;
4274 bond_dev->set_mac_address = bond_set_mac_address; 4560 bond_dev->set_mac_address = bond_set_mac_address;
4275 4561
4276 bond_set_mode_ops(bond_dev, bond->params.mode); 4562 bond_set_mode_ops(bond, bond->params.mode);
4277 4563
4278 bond_dev->destructor = free_netdev; 4564 bond_dev->destructor = free_netdev;
4279 4565
@@ -4384,6 +4670,25 @@ static int bond_check_params(struct bond_params *params)
4384 } 4670 }
4385 } 4671 }
4386 4672
4673 if (xmit_hash_policy) {
4674 if ((bond_mode != BOND_MODE_XOR) &&
4675 (bond_mode != BOND_MODE_8023AD)) {
4676 printk(KERN_INFO DRV_NAME
4677 ": xor_mode param is irrelevant in mode %s\n",
4678 bond_mode_name(bond_mode));
4679 } else {
4680 xmit_hashtype = bond_parse_parm(xmit_hash_policy,
4681 xmit_hashtype_tbl);
4682 if (xmit_hashtype == -1) {
4683 printk(KERN_ERR DRV_NAME
4684 ": Error: Invalid xmit_hash_policy \"%s\"\n",
4685 xmit_hash_policy == NULL ? "NULL" :
4686 xmit_hash_policy);
4687 return -EINVAL;
4688 }
4689 }
4690 }
4691
4387 if (lacp_rate) { 4692 if (lacp_rate) {
4388 if (bond_mode != BOND_MODE_8023AD) { 4693 if (bond_mode != BOND_MODE_8023AD) {
4389 printk(KERN_INFO DRV_NAME 4694 printk(KERN_INFO DRV_NAME
@@ -4595,6 +4900,7 @@ static int bond_check_params(struct bond_params *params)
4595 4900
4596 /* fill params struct with the proper values */ 4901 /* fill params struct with the proper values */
4597 params->mode = bond_mode; 4902 params->mode = bond_mode;
4903 params->xmit_policy = xmit_hashtype;
4598 params->miimon = miimon; 4904 params->miimon = miimon;
4599 params->arp_interval = arp_interval; 4905 params->arp_interval = arp_interval;
4600 params->updelay = updelay; 4906 params->updelay = updelay;
@@ -4669,6 +4975,7 @@ static int __init bonding_init(void)
4669 4975
4670 rtnl_unlock(); 4976 rtnl_unlock();
4671 register_netdevice_notifier(&bond_netdev_notifier); 4977 register_netdevice_notifier(&bond_netdev_notifier);
4978 register_inetaddr_notifier(&bond_inetaddr_notifier);
4672 4979
4673 return 0; 4980 return 0;
4674 4981
@@ -4684,6 +4991,7 @@ out_err:
4684static void __exit bonding_exit(void) 4991static void __exit bonding_exit(void)
4685{ 4992{
4686 unregister_netdevice_notifier(&bond_netdev_notifier); 4993 unregister_netdevice_notifier(&bond_netdev_notifier);
4994 unregister_inetaddr_notifier(&bond_inetaddr_notifier);
4687 4995
4688 rtnl_lock(); 4996 rtnl_lock();
4689 bond_free_all(); 4997 bond_free_all();
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 8c325308489d..d27f377b3eeb 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -25,6 +25,10 @@
25 * 25 *
26 * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com> 26 * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
27 * - Code cleanup and style changes 27 * - Code cleanup and style changes
28 *
29 * 2005/05/05 - Jason Gabler <jygabler at lbl dot gov>
30 * - added "xmit_policy" kernel parameter for alternate hashing policy
31 * support for mode 2
28 */ 32 */
29 33
30#ifndef _LINUX_BONDING_H 34#ifndef _LINUX_BONDING_H
@@ -36,8 +40,8 @@
36#include "bond_3ad.h" 40#include "bond_3ad.h"
37#include "bond_alb.h" 41#include "bond_alb.h"
38 42
39#define DRV_VERSION "2.6.1" 43#define DRV_VERSION "2.6.3"
40#define DRV_RELDATE "October 29, 2004" 44#define DRV_RELDATE "June 8, 2005"
41#define DRV_NAME "bonding" 45#define DRV_NAME "bonding"
42#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver" 46#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
43 47
@@ -137,6 +141,7 @@
137 141
138struct bond_params { 142struct bond_params {
139 int mode; 143 int mode;
144 int xmit_policy;
140 int miimon; 145 int miimon;
141 int arp_interval; 146 int arp_interval;
142 int use_carrier; 147 int use_carrier;
@@ -149,6 +154,7 @@ struct bond_params {
149 154
150struct vlan_entry { 155struct vlan_entry {
151 struct list_head vlan_list; 156 struct list_head vlan_list;
157 u32 vlan_ip;
152 unsigned short vlan_id; 158 unsigned short vlan_id;
153}; 159};
154 160
@@ -197,6 +203,8 @@ struct bonding {
197#endif /* CONFIG_PROC_FS */ 203#endif /* CONFIG_PROC_FS */
198 struct list_head bond_list; 204 struct list_head bond_list;
199 struct dev_mc_list *mc_list; 205 struct dev_mc_list *mc_list;
206 int (*xmit_hash_policy)(struct sk_buff *, struct net_device *, int);
207 u32 master_ip;
200 u16 flags; 208 u16 flags;
201 struct ad_bond_info ad_info; 209 struct ad_bond_info ad_info;
202 struct alb_bond_info alb_info; 210 struct alb_bond_info alb_info;
diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c
index 5c5f540da26a..b96d6fb1929e 100644
--- a/drivers/net/cs89x0.c
+++ b/drivers/net/cs89x0.c
@@ -174,6 +174,13 @@ static unsigned int cs8900_irq_map[] = {1,0,0,0};
174#include <asm/irq.h> 174#include <asm/irq.h>
175static unsigned int netcard_portlist[] __initdata = {IXDP2X01_CS8900_VIRT_BASE, 0}; 175static unsigned int netcard_portlist[] __initdata = {IXDP2X01_CS8900_VIRT_BASE, 0};
176static unsigned int cs8900_irq_map[] = {IRQ_IXDP2X01_CS8900, 0, 0, 0}; 176static unsigned int cs8900_irq_map[] = {IRQ_IXDP2X01_CS8900, 0, 0, 0};
177#elif defined(CONFIG_ARCH_PNX0105)
178#include <asm/irq.h>
179#include <asm/arch/gpio.h>
180#define CIRRUS_DEFAULT_BASE IO_ADDRESS(EXT_STATIC2_s0_BASE + 0x200000) /* = Physical address 0x48200000 */
181#define CIRRUS_DEFAULT_IRQ VH_INTC_INT_NUM_CASCADED_INTERRUPT_1 /* Event inputs bank 1 - ID 35/bit 3 */
182static unsigned int netcard_portlist[] __initdata = {CIRRUS_DEFAULT_BASE, 0};
183static unsigned int cs8900_irq_map[] = {CIRRUS_DEFAULT_IRQ, 0, 0, 0};
177#else 184#else
178static unsigned int netcard_portlist[] __initdata = 185static unsigned int netcard_portlist[] __initdata =
179 { 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0}; 186 { 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0};
@@ -319,13 +326,7 @@ struct net_device * __init cs89x0_probe(int unit)
319 } 326 }
320 if (err) 327 if (err)
321 goto out; 328 goto out;
322 err = register_netdev(dev);
323 if (err)
324 goto out1;
325 return dev; 329 return dev;
326out1:
327 outw(PP_ChipID, dev->base_addr + ADD_PORT);
328 release_region(dev->base_addr, NETCARD_IO_EXTENT);
329out: 330out:
330 free_netdev(dev); 331 free_netdev(dev);
331 printk(KERN_WARNING "cs89x0: no cs8900 or cs8920 detected. Be sure to disable PnP with SETUP\n"); 332 printk(KERN_WARNING "cs89x0: no cs8900 or cs8920 detected. Be sure to disable PnP with SETUP\n");
@@ -437,6 +438,30 @@ cs89x0_probe1(struct net_device *dev, int ioaddr, int modular)
437#endif 438#endif
438 } 439 }
439 440
441#ifdef CONFIG_ARCH_PNX0105
442 initialize_ebi();
443
444 /* Map GPIO registers for the pins connected to the CS8900a. */
445 if (map_cirrus_gpio() < 0)
446 return -ENODEV;
447
448 reset_cirrus();
449
450 /* Map event-router registers. */
451 if (map_event_router() < 0)
452 return -ENODEV;
453
454 enable_cirrus_irq();
455
456 unmap_cirrus_gpio();
457 unmap_event_router();
458
459 dev->base_addr = ioaddr;
460
461 for (i = 0 ; i < 3 ; i++)
462 readreg(dev, 0);
463#endif
464
440 /* Grab the region so we can find another board if autoIRQ fails. */ 465 /* Grab the region so we can find another board if autoIRQ fails. */
441 /* WTF is going on here? */ 466 /* WTF is going on here? */
442 if (!request_region(ioaddr & ~3, NETCARD_IO_EXTENT, DRV_NAME)) { 467 if (!request_region(ioaddr & ~3, NETCARD_IO_EXTENT, DRV_NAME)) {
@@ -678,7 +703,7 @@ printk("PP_addr=0x%x\n", inw(ioaddr + ADD_PORT));
678 } else { 703 } else {
679 i = lp->isa_config & INT_NO_MASK; 704 i = lp->isa_config & INT_NO_MASK;
680 if (lp->chip_type == CS8900) { 705 if (lp->chip_type == CS8900) {
681#ifdef CONFIG_ARCH_IXDP2X01 706#if defined(CONFIG_ARCH_IXDP2X01) || defined(CONFIG_ARCH_PNX0105)
682 i = cs8900_irq_map[0]; 707 i = cs8900_irq_map[0];
683#else 708#else
684 /* Translate the IRQ using the IRQ mapping table. */ 709 /* Translate the IRQ using the IRQ mapping table. */
@@ -735,7 +760,13 @@ printk("PP_addr=0x%x\n", inw(ioaddr + ADD_PORT));
735 printk("\n"); 760 printk("\n");
736 if (net_debug) 761 if (net_debug)
737 printk("cs89x0_probe1() successful\n"); 762 printk("cs89x0_probe1() successful\n");
763
764 retval = register_netdev(dev);
765 if (retval)
766 goto out3;
738 return 0; 767 return 0;
768out3:
769 outw(PP_ChipID, dev->base_addr + ADD_PORT);
739out2: 770out2:
740 release_region(ioaddr & ~3, NETCARD_IO_EXTENT); 771 release_region(ioaddr & ~3, NETCARD_IO_EXTENT);
741out1: 772out1:
@@ -1145,7 +1176,7 @@ net_open(struct net_device *dev)
1145 int i; 1176 int i;
1146 int ret; 1177 int ret;
1147 1178
1148#ifndef CONFIG_SH_HICOSH4 /* uses irq#1, so this won't work */ 1179#if !defined(CONFIG_SH_HICOSH4) && !defined(CONFIG_ARCH_PNX0105) /* uses irq#1, so this won't work */
1149 if (dev->irq < 2) { 1180 if (dev->irq < 2) {
1150 /* Allow interrupts to be generated by the chip */ 1181 /* Allow interrupts to be generated by the chip */
1151/* Cirrus' release had this: */ 1182/* Cirrus' release had this: */
@@ -1176,7 +1207,7 @@ net_open(struct net_device *dev)
1176 else 1207 else
1177#endif 1208#endif
1178 { 1209 {
1179#ifndef CONFIG_ARCH_IXDP2X01 1210#if !defined(CONFIG_ARCH_IXDP2X01) && !defined(CONFIG_ARCH_PNX0105)
1180 if (((1 << dev->irq) & lp->irq_map) == 0) { 1211 if (((1 << dev->irq) & lp->irq_map) == 0) {
1181 printk(KERN_ERR "%s: IRQ %d is not in our map of allowable IRQs, which is %x\n", 1212 printk(KERN_ERR "%s: IRQ %d is not in our map of allowable IRQs, which is %x\n",
1182 dev->name, dev->irq, lp->irq_map); 1213 dev->name, dev->irq, lp->irq_map);
@@ -1261,6 +1292,9 @@ net_open(struct net_device *dev)
1261 case A_CNF_MEDIA_10B_2: result = lp->adapter_cnf & A_CNF_10B_2; break; 1292 case A_CNF_MEDIA_10B_2: result = lp->adapter_cnf & A_CNF_10B_2; break;
1262 default: result = lp->adapter_cnf & (A_CNF_10B_T | A_CNF_AUI | A_CNF_10B_2); 1293 default: result = lp->adapter_cnf & (A_CNF_10B_T | A_CNF_AUI | A_CNF_10B_2);
1263 } 1294 }
1295#ifdef CONFIG_ARCH_PNX0105
1296 result = A_CNF_10B_T;
1297#endif
1264 if (!result) { 1298 if (!result) {
1265 printk(KERN_ERR "%s: EEPROM is configured for unavailable media\n", dev->name); 1299 printk(KERN_ERR "%s: EEPROM is configured for unavailable media\n", dev->name);
1266 release_irq: 1300 release_irq:
@@ -1831,13 +1865,6 @@ init_module(void)
1831 if (ret) 1865 if (ret)
1832 goto out; 1866 goto out;
1833 1867
1834 if (register_netdev(dev) != 0) {
1835 printk(KERN_ERR "cs89x0.c: No card found at 0x%x\n", io);
1836 ret = -ENXIO;
1837 outw(PP_ChipID, dev->base_addr + ADD_PORT);
1838 release_region(dev->base_addr, NETCARD_IO_EXTENT);
1839 goto out;
1840 }
1841 dev_cs89x0 = dev; 1868 dev_cs89x0 = dev;
1842 return 0; 1869 return 0;
1843out: 1870out:
diff --git a/drivers/net/cs89x0.h b/drivers/net/cs89x0.h
index b0ef7ad2baad..bd3ad8e6cce9 100644
--- a/drivers/net/cs89x0.h
+++ b/drivers/net/cs89x0.h
@@ -16,7 +16,7 @@
16 16
17#include <linux/config.h> 17#include <linux/config.h>
18 18
19#ifdef CONFIG_ARCH_IXDP2X01 19#if defined(CONFIG_ARCH_IXDP2X01) || defined(CONFIG_ARCH_PNX0105)
20/* IXDP2401/IXDP2801 uses dword-aligned register addressing */ 20/* IXDP2401/IXDP2801 uses dword-aligned register addressing */
21#define CS89x0_PORT(reg) ((reg) * 2) 21#define CS89x0_PORT(reg) ((reg) * 2)
22#else 22#else
diff --git a/drivers/net/defxx.c b/drivers/net/defxx.c
index a6aa56598f27..5acd35c312ac 100644
--- a/drivers/net/defxx.c
+++ b/drivers/net/defxx.c
@@ -191,6 +191,7 @@
191 * Feb 2001 davej PCI enable cleanups. 191 * Feb 2001 davej PCI enable cleanups.
192 * 04 Aug 2003 macro Converted to the DMA API. 192 * 04 Aug 2003 macro Converted to the DMA API.
193 * 14 Aug 2004 macro Fix device names reported. 193 * 14 Aug 2004 macro Fix device names reported.
194 * 14 Jun 2005 macro Use irqreturn_t.
194 */ 195 */
195 196
196/* Include files */ 197/* Include files */
@@ -217,8 +218,8 @@
217 218
218/* Version information string should be updated prior to each new release! */ 219/* Version information string should be updated prior to each new release! */
219#define DRV_NAME "defxx" 220#define DRV_NAME "defxx"
220#define DRV_VERSION "v1.07" 221#define DRV_VERSION "v1.08"
221#define DRV_RELDATE "2004/08/14" 222#define DRV_RELDATE "2005/06/14"
222 223
223static char version[] __devinitdata = 224static char version[] __devinitdata =
224 DRV_NAME ": " DRV_VERSION " " DRV_RELDATE 225 DRV_NAME ": " DRV_VERSION " " DRV_RELDATE
@@ -247,7 +248,8 @@ static int dfx_close(struct net_device *dev);
247static void dfx_int_pr_halt_id(DFX_board_t *bp); 248static void dfx_int_pr_halt_id(DFX_board_t *bp);
248static void dfx_int_type_0_process(DFX_board_t *bp); 249static void dfx_int_type_0_process(DFX_board_t *bp);
249static void dfx_int_common(struct net_device *dev); 250static void dfx_int_common(struct net_device *dev);
250static void dfx_interrupt(int irq, void *dev_id, struct pt_regs *regs); 251static irqreturn_t dfx_interrupt(int irq, void *dev_id,
252 struct pt_regs *regs);
251 253
252static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev); 254static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev);
253static void dfx_ctl_set_multicast_list(struct net_device *dev); 255static void dfx_ctl_set_multicast_list(struct net_device *dev);
@@ -437,7 +439,8 @@ static int __devinit dfx_init_one_pci_or_eisa(struct pci_dev *pdev, long ioaddr)
437 } 439 }
438 440
439 SET_MODULE_OWNER(dev); 441 SET_MODULE_OWNER(dev);
440 SET_NETDEV_DEV(dev, &pdev->dev); 442 if (pdev != NULL)
443 SET_NETDEV_DEV(dev, &pdev->dev);
441 444
442 bp = dev->priv; 445 bp = dev->priv;
443 446
@@ -1225,7 +1228,7 @@ static int dfx_open(struct net_device *dev)
1225 1228
1226 /* Register IRQ - support shared interrupts by passing device ptr */ 1229 /* Register IRQ - support shared interrupts by passing device ptr */
1227 1230
1228 ret = request_irq(dev->irq, (void *)dfx_interrupt, SA_SHIRQ, dev->name, dev); 1231 ret = request_irq(dev->irq, dfx_interrupt, SA_SHIRQ, dev->name, dev);
1229 if (ret) { 1232 if (ret) {
1230 printk(KERN_ERR "%s: Requested IRQ %d is busy\n", dev->name, dev->irq); 1233 printk(KERN_ERR "%s: Requested IRQ %d is busy\n", dev->name, dev->irq);
1231 return ret; 1234 return ret;
@@ -1680,13 +1683,13 @@ static void dfx_int_common(struct net_device *dev)
1680 * ================= 1683 * =================
1681 * = dfx_interrupt = 1684 * = dfx_interrupt =
1682 * ================= 1685 * =================
1683 * 1686 *
1684 * Overview: 1687 * Overview:
1685 * Interrupt processing routine 1688 * Interrupt processing routine
1686 * 1689 *
1687 * Returns: 1690 * Returns:
1688 * None 1691 * Whether a valid interrupt was seen.
1689 * 1692 *
1690 * Arguments: 1693 * Arguments:
1691 * irq - interrupt vector 1694 * irq - interrupt vector
1692 * dev_id - pointer to device information 1695 * dev_id - pointer to device information
@@ -1699,7 +1702,8 @@ static void dfx_int_common(struct net_device *dev)
1699 * structure context. 1702 * structure context.
1700 * 1703 *
1701 * Return Codes: 1704 * Return Codes:
1702 * None 1705 * IRQ_HANDLED - an IRQ was handled.
1706 * IRQ_NONE - no IRQ was handled.
1703 * 1707 *
1704 * Assumptions: 1708 * Assumptions:
1705 * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC 1709 * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
@@ -1712,60 +1716,70 @@ static void dfx_int_common(struct net_device *dev)
1712 * Interrupts are disabled, then reenabled at the adapter. 1716 * Interrupts are disabled, then reenabled at the adapter.
1713 */ 1717 */
1714 1718
1715static void dfx_interrupt(int irq, void *dev_id, struct pt_regs *regs) 1719static irqreturn_t dfx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1716 { 1720{
1717 struct net_device *dev = dev_id; 1721 struct net_device *dev = dev_id;
1718 DFX_board_t *bp; /* private board structure pointer */ 1722 DFX_board_t *bp; /* private board structure pointer */
1719 u8 tmp; /* used for disabling/enabling ints */
1720 1723
1721 /* Get board pointer only if device structure is valid */ 1724 /* Get board pointer only if device structure is valid */
1722 1725
1723 bp = dev->priv; 1726 bp = dev->priv;
1724 1727
1725 spin_lock(&bp->lock);
1726
1727 /* See if we're already servicing an interrupt */ 1728 /* See if we're already servicing an interrupt */
1728 1729
1729 /* Service adapter interrupts */ 1730 /* Service adapter interrupts */
1730 1731
1731 if (bp->bus_type == DFX_BUS_TYPE_PCI) 1732 if (bp->bus_type == DFX_BUS_TYPE_PCI) {
1732 { 1733 u32 status;
1733 /* Disable PDQ-PFI interrupts at PFI */
1734 1734
1735 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, PFI_MODE_M_DMA_ENB); 1735 dfx_port_read_long(bp, PFI_K_REG_STATUS, &status);
1736 if (!(status & PFI_STATUS_M_PDQ_INT))
1737 return IRQ_NONE;
1736 1738
1737 /* Call interrupt service routine for this adapter */ 1739 spin_lock(&bp->lock);
1740
1741 /* Disable PDQ-PFI interrupts at PFI */
1742 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
1743 PFI_MODE_M_DMA_ENB);
1738 1744
1745 /* Call interrupt service routine for this adapter */
1739 dfx_int_common(dev); 1746 dfx_int_common(dev);
1740 1747
1741 /* Clear PDQ interrupt status bit and reenable interrupts */ 1748 /* Clear PDQ interrupt status bit and reenable interrupts */
1742 1749 dfx_port_write_long(bp, PFI_K_REG_STATUS,
1743 dfx_port_write_long(bp, PFI_K_REG_STATUS, PFI_STATUS_M_PDQ_INT); 1750 PFI_STATUS_M_PDQ_INT);
1744 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, 1751 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
1745 (PFI_MODE_M_PDQ_INT_ENB + PFI_MODE_M_DMA_ENB)); 1752 (PFI_MODE_M_PDQ_INT_ENB |
1746 } 1753 PFI_MODE_M_DMA_ENB));
1747 else
1748 {
1749 /* Disable interrupts at the ESIC */
1750 1754
1751 dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &tmp); 1755 spin_unlock(&bp->lock);
1752 tmp &= ~PI_CONFIG_STAT_0_M_INT_ENB; 1756 } else {
1753 dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, tmp); 1757 u8 status;
1754 1758
1755 /* Call interrupt service routine for this adapter */ 1759 dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &status);
1760 if (!(status & PI_CONFIG_STAT_0_M_PEND))
1761 return IRQ_NONE;
1756 1762
1763 spin_lock(&bp->lock);
1764
1765 /* Disable interrupts at the ESIC */
1766 status &= ~PI_CONFIG_STAT_0_M_INT_ENB;
1767 dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, status);
1768
1769 /* Call interrupt service routine for this adapter */
1757 dfx_int_common(dev); 1770 dfx_int_common(dev);
1758 1771
1759 /* Reenable interrupts at the ESIC */ 1772 /* Reenable interrupts at the ESIC */
1773 dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &status);
1774 status |= PI_CONFIG_STAT_0_M_INT_ENB;
1775 dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, status);
1760 1776
1761 dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &tmp); 1777 spin_unlock(&bp->lock);
1762 tmp |= PI_CONFIG_STAT_0_M_INT_ENB;
1763 dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, tmp);
1764 }
1765
1766 spin_unlock(&bp->lock);
1767 } 1778 }
1768 1779
1780 return IRQ_HANDLED;
1781}
1782
1769 1783
1770/* 1784/*
1771 * ===================== 1785 * =====================
diff --git a/drivers/net/dl2k.c b/drivers/net/dl2k.c
index aa42b7a27735..430c628279b3 100644
--- a/drivers/net/dl2k.c
+++ b/drivers/net/dl2k.c
@@ -547,7 +547,7 @@ rio_timer (unsigned long data)
547 skb_reserve (skb, 2); 547 skb_reserve (skb, 2);
548 np->rx_ring[entry].fraginfo = 548 np->rx_ring[entry].fraginfo =
549 cpu_to_le64 (pci_map_single 549 cpu_to_le64 (pci_map_single
550 (np->pdev, skb->tail, np->rx_buf_sz, 550 (np->pdev, skb->data, np->rx_buf_sz,
551 PCI_DMA_FROMDEVICE)); 551 PCI_DMA_FROMDEVICE));
552 } 552 }
553 np->rx_ring[entry].fraginfo |= 553 np->rx_ring[entry].fraginfo |=
@@ -618,7 +618,7 @@ alloc_list (struct net_device *dev)
618 /* Rubicon now supports 40 bits of addressing space. */ 618 /* Rubicon now supports 40 bits of addressing space. */
619 np->rx_ring[i].fraginfo = 619 np->rx_ring[i].fraginfo =
620 cpu_to_le64 ( pci_map_single ( 620 cpu_to_le64 ( pci_map_single (
621 np->pdev, skb->tail, np->rx_buf_sz, 621 np->pdev, skb->data, np->rx_buf_sz,
622 PCI_DMA_FROMDEVICE)); 622 PCI_DMA_FROMDEVICE));
623 np->rx_ring[i].fraginfo |= cpu_to_le64 (np->rx_buf_sz) << 48; 623 np->rx_ring[i].fraginfo |= cpu_to_le64 (np->rx_buf_sz) << 48;
624 } 624 }
@@ -906,7 +906,7 @@ receive_packet (struct net_device *dev)
906 /* 16 byte align the IP header */ 906 /* 16 byte align the IP header */
907 skb_reserve (skb, 2); 907 skb_reserve (skb, 2);
908 eth_copy_and_sum (skb, 908 eth_copy_and_sum (skb,
909 np->rx_skbuff[entry]->tail, 909 np->rx_skbuff[entry]->data,
910 pkt_len, 0); 910 pkt_len, 0);
911 skb_put (skb, pkt_len); 911 skb_put (skb, pkt_len);
912 pci_dma_sync_single_for_device(np->pdev, 912 pci_dma_sync_single_for_device(np->pdev,
@@ -950,7 +950,7 @@ receive_packet (struct net_device *dev)
950 skb_reserve (skb, 2); 950 skb_reserve (skb, 2);
951 np->rx_ring[entry].fraginfo = 951 np->rx_ring[entry].fraginfo =
952 cpu_to_le64 (pci_map_single 952 cpu_to_le64 (pci_map_single
953 (np->pdev, skb->tail, np->rx_buf_sz, 953 (np->pdev, skb->data, np->rx_buf_sz,
954 PCI_DMA_FROMDEVICE)); 954 PCI_DMA_FROMDEVICE));
955 } 955 }
956 np->rx_ring[entry].fraginfo |= 956 np->rx_ring[entry].fraginfo |=
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index f4ba0ffb8637..5fddc0ff8878 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -224,7 +224,7 @@ static void dm9000_outblk_32bit(void __iomem *reg, void *data, int count)
224 224
225static void dm9000_inblk_8bit(void __iomem *reg, void *data, int count) 225static void dm9000_inblk_8bit(void __iomem *reg, void *data, int count)
226{ 226{
227 readsb(reg, data, count+1); 227 readsb(reg, data, count);
228} 228}
229 229
230 230
@@ -364,7 +364,7 @@ dm9000_release_board(struct platform_device *pdev, struct board_info *db)
364 } 364 }
365 365
366 if (db->addr_res != NULL) { 366 if (db->addr_res != NULL) {
367 release_resource(db->data_req); 367 release_resource(db->addr_res);
368 kfree(db->addr_req); 368 kfree(db->addr_req);
369 } 369 }
370} 370}
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index 4a47df5a9ff9..d0fa2448761d 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -143,6 +143,7 @@
143#include <linux/delay.h> 143#include <linux/delay.h>
144#include <linux/init.h> 144#include <linux/init.h>
145#include <linux/pci.h> 145#include <linux/pci.h>
146#include <linux/dma-mapping.h>
146#include <linux/netdevice.h> 147#include <linux/netdevice.h>
147#include <linux/etherdevice.h> 148#include <linux/etherdevice.h>
148#include <linux/mii.h> 149#include <linux/mii.h>
@@ -1092,11 +1093,16 @@ static int e100_phy_init(struct nic *nic)
1092 } 1093 }
1093 1094
1094 if((nic->mac >= mac_82550_D102) || ((nic->flags & ich) && 1095 if((nic->mac >= mac_82550_D102) || ((nic->flags & ich) &&
1095 (mdio_read(netdev, nic->mii.phy_id, MII_TPISTATUS) & 0x8000) && 1096 (mdio_read(netdev, nic->mii.phy_id, MII_TPISTATUS) & 0x8000))) {
1096 (nic->eeprom[eeprom_cnfg_mdix] & eeprom_mdix_enabled))) 1097 /* enable/disable MDI/MDI-X auto-switching.
1097 /* enable/disable MDI/MDI-X auto-switching */ 1098 MDI/MDI-X auto-switching is disabled for 82551ER/QM chips */
1098 mdio_write(netdev, nic->mii.phy_id, MII_NCONFIG, 1099 if((nic->mac == mac_82551_E) || (nic->mac == mac_82551_F) ||
1099 nic->mii.force_media ? 0 : NCONFIG_AUTO_SWITCH); 1100 (nic->mac == mac_82551_10) || (nic->mii.force_media) ||
1101 !(nic->eeprom[eeprom_cnfg_mdix] & eeprom_mdix_enabled))
1102 mdio_write(netdev, nic->mii.phy_id, MII_NCONFIG, 0);
1103 else
1104 mdio_write(netdev, nic->mii.phy_id, MII_NCONFIG, NCONFIG_AUTO_SWITCH);
1105 }
1100 1106
1101 return 0; 1107 return 0;
1102} 1108}
@@ -1665,8 +1671,10 @@ static irqreturn_t e100_intr(int irq, void *dev_id, struct pt_regs *regs)
1665 if(stat_ack & stat_ack_rnr) 1671 if(stat_ack & stat_ack_rnr)
1666 nic->ru_running = RU_SUSPENDED; 1672 nic->ru_running = RU_SUSPENDED;
1667 1673
1668 e100_disable_irq(nic); 1674 if(likely(netif_rx_schedule_prep(netdev))) {
1669 netif_rx_schedule(netdev); 1675 e100_disable_irq(nic);
1676 __netif_rx_schedule(netdev);
1677 }
1670 1678
1671 return IRQ_HANDLED; 1679 return IRQ_HANDLED;
1672} 1680}
@@ -2286,7 +2294,7 @@ static int __devinit e100_probe(struct pci_dev *pdev,
2286 goto err_out_disable_pdev; 2294 goto err_out_disable_pdev;
2287 } 2295 }
2288 2296
2289 if((err = pci_set_dma_mask(pdev, 0xFFFFFFFFULL))) { 2297 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
2290 DPRINTK(PROBE, ERR, "No usable DMA configuration, aborting.\n"); 2298 DPRINTK(PROBE, ERR, "No usable DMA configuration, aborting.\n");
2291 goto err_out_free_res; 2299 goto err_out_free_res;
2292 } 2300 }
@@ -2334,11 +2342,11 @@ static int __devinit e100_probe(struct pci_dev *pdev,
2334 goto err_out_iounmap; 2342 goto err_out_iounmap;
2335 } 2343 }
2336 2344
2337 e100_phy_init(nic);
2338
2339 if((err = e100_eeprom_load(nic))) 2345 if((err = e100_eeprom_load(nic)))
2340 goto err_out_free; 2346 goto err_out_free;
2341 2347
2348 e100_phy_init(nic);
2349
2342 memcpy(netdev->dev_addr, nic->eeprom, ETH_ALEN); 2350 memcpy(netdev->dev_addr, nic->eeprom, ETH_ALEN);
2343 if(!is_valid_ether_addr(netdev->dev_addr)) { 2351 if(!is_valid_ether_addr(netdev->dev_addr)) {
2344 DPRINTK(PROBE, ERR, "Invalid MAC address from " 2352 DPRINTK(PROBE, ERR, "Invalid MAC address from "
@@ -2439,9 +2447,8 @@ static int e100_resume(struct pci_dev *pdev)
2439#endif 2447#endif
2440 2448
2441 2449
2442static void e100_shutdown(struct device *dev) 2450static void e100_shutdown(struct pci_dev *pdev)
2443{ 2451{
2444 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
2445 struct net_device *netdev = pci_get_drvdata(pdev); 2452 struct net_device *netdev = pci_get_drvdata(pdev);
2446 struct nic *nic = netdev_priv(netdev); 2453 struct nic *nic = netdev_priv(netdev);
2447 2454
@@ -2462,11 +2469,7 @@ static struct pci_driver e100_driver = {
2462 .suspend = e100_suspend, 2469 .suspend = e100_suspend,
2463 .resume = e100_resume, 2470 .resume = e100_resume,
2464#endif 2471#endif
2465 2472 .shutdown = e100_shutdown,
2466 .driver = {
2467 .shutdown = e100_shutdown,
2468 }
2469
2470}; 2473};
2471 2474
2472static int __init e100_init_module(void) 2475static int __init e100_init_module(void)
diff --git a/drivers/net/e1000/e1000.h b/drivers/net/e1000/e1000.h
index af1e82c5b808..092757bc721f 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -140,7 +140,7 @@ struct e1000_adapter;
140#define E1000_RX_BUFFER_WRITE 16 /* Must be power of 2 */ 140#define E1000_RX_BUFFER_WRITE 16 /* Must be power of 2 */
141 141
142#define AUTO_ALL_MODES 0 142#define AUTO_ALL_MODES 0
143#define E1000_EEPROM_82544_APM 0x0400 143#define E1000_EEPROM_82544_APM 0x0004
144#define E1000_EEPROM_APME 0x0400 144#define E1000_EEPROM_APME 0x0400
145 145
146#ifndef E1000_MASTER_SLAVE 146#ifndef E1000_MASTER_SLAVE
@@ -159,7 +159,7 @@ struct e1000_adapter;
159 * so a DMA handle can be stored along with the buffer */ 159 * so a DMA handle can be stored along with the buffer */
160struct e1000_buffer { 160struct e1000_buffer {
161 struct sk_buff *skb; 161 struct sk_buff *skb;
162 uint64_t dma; 162 dma_addr_t dma;
163 unsigned long time_stamp; 163 unsigned long time_stamp;
164 uint16_t length; 164 uint16_t length;
165 uint16_t next_to_watch; 165 uint16_t next_to_watch;
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index 237247f74df4..f133ff0b0b94 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -105,7 +105,7 @@ static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
105static int 105static int
106e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) 106e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
107{ 107{
108 struct e1000_adapter *adapter = netdev->priv; 108 struct e1000_adapter *adapter = netdev_priv(netdev);
109 struct e1000_hw *hw = &adapter->hw; 109 struct e1000_hw *hw = &adapter->hw;
110 110
111 if(hw->media_type == e1000_media_type_copper) { 111 if(hw->media_type == e1000_media_type_copper) {
@@ -141,9 +141,9 @@ e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
141 SUPPORTED_FIBRE | 141 SUPPORTED_FIBRE |
142 SUPPORTED_Autoneg); 142 SUPPORTED_Autoneg);
143 143
144 ecmd->advertising = (SUPPORTED_1000baseT_Full | 144 ecmd->advertising = (ADVERTISED_1000baseT_Full |
145 SUPPORTED_FIBRE | 145 ADVERTISED_FIBRE |
146 SUPPORTED_Autoneg); 146 ADVERTISED_Autoneg);
147 147
148 ecmd->port = PORT_FIBRE; 148 ecmd->port = PORT_FIBRE;
149 149
@@ -179,13 +179,24 @@ e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
179static int 179static int
180e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) 180e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
181{ 181{
182 struct e1000_adapter *adapter = netdev->priv; 182 struct e1000_adapter *adapter = netdev_priv(netdev);
183 struct e1000_hw *hw = &adapter->hw; 183 struct e1000_hw *hw = &adapter->hw;
184 184
185 if(ecmd->autoneg == AUTONEG_ENABLE) { 185 if(ecmd->autoneg == AUTONEG_ENABLE) {
186 hw->autoneg = 1; 186 hw->autoneg = 1;
187 hw->autoneg_advertised = 0x002F; 187 if(hw->media_type == e1000_media_type_fiber)
188 ecmd->advertising = 0x002F; 188 hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
189 ADVERTISED_FIBRE |
190 ADVERTISED_Autoneg;
191 else
192 hw->autoneg_advertised = ADVERTISED_10baseT_Half |
193 ADVERTISED_10baseT_Full |
194 ADVERTISED_100baseT_Half |
195 ADVERTISED_100baseT_Full |
196 ADVERTISED_1000baseT_Full|
197 ADVERTISED_Autoneg |
198 ADVERTISED_TP;
199 ecmd->advertising = hw->autoneg_advertised;
189 } else 200 } else
190 if(e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) 201 if(e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex))
191 return -EINVAL; 202 return -EINVAL;
@@ -206,7 +217,7 @@ static void
206e1000_get_pauseparam(struct net_device *netdev, 217e1000_get_pauseparam(struct net_device *netdev,
207 struct ethtool_pauseparam *pause) 218 struct ethtool_pauseparam *pause)
208{ 219{
209 struct e1000_adapter *adapter = netdev->priv; 220 struct e1000_adapter *adapter = netdev_priv(netdev);
210 struct e1000_hw *hw = &adapter->hw; 221 struct e1000_hw *hw = &adapter->hw;
211 222
212 pause->autoneg = 223 pause->autoneg =
@@ -226,7 +237,7 @@ static int
226e1000_set_pauseparam(struct net_device *netdev, 237e1000_set_pauseparam(struct net_device *netdev,
227 struct ethtool_pauseparam *pause) 238 struct ethtool_pauseparam *pause)
228{ 239{
229 struct e1000_adapter *adapter = netdev->priv; 240 struct e1000_adapter *adapter = netdev_priv(netdev);
230 struct e1000_hw *hw = &adapter->hw; 241 struct e1000_hw *hw = &adapter->hw;
231 242
232 adapter->fc_autoneg = pause->autoneg; 243 adapter->fc_autoneg = pause->autoneg;
@@ -259,14 +270,14 @@ e1000_set_pauseparam(struct net_device *netdev,
259static uint32_t 270static uint32_t
260e1000_get_rx_csum(struct net_device *netdev) 271e1000_get_rx_csum(struct net_device *netdev)
261{ 272{
262 struct e1000_adapter *adapter = netdev->priv; 273 struct e1000_adapter *adapter = netdev_priv(netdev);
263 return adapter->rx_csum; 274 return adapter->rx_csum;
264} 275}
265 276
266static int 277static int
267e1000_set_rx_csum(struct net_device *netdev, uint32_t data) 278e1000_set_rx_csum(struct net_device *netdev, uint32_t data)
268{ 279{
269 struct e1000_adapter *adapter = netdev->priv; 280 struct e1000_adapter *adapter = netdev_priv(netdev);
270 adapter->rx_csum = data; 281 adapter->rx_csum = data;
271 282
272 if(netif_running(netdev)) { 283 if(netif_running(netdev)) {
@@ -286,7 +297,7 @@ e1000_get_tx_csum(struct net_device *netdev)
286static int 297static int
287e1000_set_tx_csum(struct net_device *netdev, uint32_t data) 298e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
288{ 299{
289 struct e1000_adapter *adapter = netdev->priv; 300 struct e1000_adapter *adapter = netdev_priv(netdev);
290 301
291 if(adapter->hw.mac_type < e1000_82543) { 302 if(adapter->hw.mac_type < e1000_82543) {
292 if (!data) 303 if (!data)
@@ -306,8 +317,8 @@ e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
306static int 317static int
307e1000_set_tso(struct net_device *netdev, uint32_t data) 318e1000_set_tso(struct net_device *netdev, uint32_t data)
308{ 319{
309 struct e1000_adapter *adapter = netdev->priv; 320 struct e1000_adapter *adapter = netdev_priv(netdev);
310 if ((adapter->hw.mac_type < e1000_82544) || 321 if((adapter->hw.mac_type < e1000_82544) ||
311 (adapter->hw.mac_type == e1000_82547)) 322 (adapter->hw.mac_type == e1000_82547))
312 return data ? -EINVAL : 0; 323 return data ? -EINVAL : 0;
313 324
@@ -322,14 +333,14 @@ e1000_set_tso(struct net_device *netdev, uint32_t data)
322static uint32_t 333static uint32_t
323e1000_get_msglevel(struct net_device *netdev) 334e1000_get_msglevel(struct net_device *netdev)
324{ 335{
325 struct e1000_adapter *adapter = netdev->priv; 336 struct e1000_adapter *adapter = netdev_priv(netdev);
326 return adapter->msg_enable; 337 return adapter->msg_enable;
327} 338}
328 339
329static void 340static void
330e1000_set_msglevel(struct net_device *netdev, uint32_t data) 341e1000_set_msglevel(struct net_device *netdev, uint32_t data)
331{ 342{
332 struct e1000_adapter *adapter = netdev->priv; 343 struct e1000_adapter *adapter = netdev_priv(netdev);
333 adapter->msg_enable = data; 344 adapter->msg_enable = data;
334} 345}
335 346
@@ -344,7 +355,7 @@ static void
344e1000_get_regs(struct net_device *netdev, 355e1000_get_regs(struct net_device *netdev,
345 struct ethtool_regs *regs, void *p) 356 struct ethtool_regs *regs, void *p)
346{ 357{
347 struct e1000_adapter *adapter = netdev->priv; 358 struct e1000_adapter *adapter = netdev_priv(netdev);
348 struct e1000_hw *hw = &adapter->hw; 359 struct e1000_hw *hw = &adapter->hw;
349 uint32_t *regs_buff = p; 360 uint32_t *regs_buff = p;
350 uint16_t phy_data; 361 uint16_t phy_data;
@@ -432,7 +443,7 @@ e1000_get_regs(struct net_device *netdev,
432static int 443static int
433e1000_get_eeprom_len(struct net_device *netdev) 444e1000_get_eeprom_len(struct net_device *netdev)
434{ 445{
435 struct e1000_adapter *adapter = netdev->priv; 446 struct e1000_adapter *adapter = netdev_priv(netdev);
436 return adapter->hw.eeprom.word_size * 2; 447 return adapter->hw.eeprom.word_size * 2;
437} 448}
438 449
@@ -440,7 +451,7 @@ static int
440e1000_get_eeprom(struct net_device *netdev, 451e1000_get_eeprom(struct net_device *netdev,
441 struct ethtool_eeprom *eeprom, uint8_t *bytes) 452 struct ethtool_eeprom *eeprom, uint8_t *bytes)
442{ 453{
443 struct e1000_adapter *adapter = netdev->priv; 454 struct e1000_adapter *adapter = netdev_priv(netdev);
444 struct e1000_hw *hw = &adapter->hw; 455 struct e1000_hw *hw = &adapter->hw;
445 uint16_t *eeprom_buff; 456 uint16_t *eeprom_buff;
446 int first_word, last_word; 457 int first_word, last_word;
@@ -486,7 +497,7 @@ static int
486e1000_set_eeprom(struct net_device *netdev, 497e1000_set_eeprom(struct net_device *netdev,
487 struct ethtool_eeprom *eeprom, uint8_t *bytes) 498 struct ethtool_eeprom *eeprom, uint8_t *bytes)
488{ 499{
489 struct e1000_adapter *adapter = netdev->priv; 500 struct e1000_adapter *adapter = netdev_priv(netdev);
490 struct e1000_hw *hw = &adapter->hw; 501 struct e1000_hw *hw = &adapter->hw;
491 uint16_t *eeprom_buff; 502 uint16_t *eeprom_buff;
492 void *ptr; 503 void *ptr;
@@ -547,7 +558,7 @@ static void
547e1000_get_drvinfo(struct net_device *netdev, 558e1000_get_drvinfo(struct net_device *netdev,
548 struct ethtool_drvinfo *drvinfo) 559 struct ethtool_drvinfo *drvinfo)
549{ 560{
550 struct e1000_adapter *adapter = netdev->priv; 561 struct e1000_adapter *adapter = netdev_priv(netdev);
551 562
552 strncpy(drvinfo->driver, e1000_driver_name, 32); 563 strncpy(drvinfo->driver, e1000_driver_name, 32);
553 strncpy(drvinfo->version, e1000_driver_version, 32); 564 strncpy(drvinfo->version, e1000_driver_version, 32);
@@ -563,7 +574,7 @@ static void
563e1000_get_ringparam(struct net_device *netdev, 574e1000_get_ringparam(struct net_device *netdev,
564 struct ethtool_ringparam *ring) 575 struct ethtool_ringparam *ring)
565{ 576{
566 struct e1000_adapter *adapter = netdev->priv; 577 struct e1000_adapter *adapter = netdev_priv(netdev);
567 e1000_mac_type mac_type = adapter->hw.mac_type; 578 e1000_mac_type mac_type = adapter->hw.mac_type;
568 struct e1000_desc_ring *txdr = &adapter->tx_ring; 579 struct e1000_desc_ring *txdr = &adapter->tx_ring;
569 struct e1000_desc_ring *rxdr = &adapter->rx_ring; 580 struct e1000_desc_ring *rxdr = &adapter->rx_ring;
@@ -584,7 +595,7 @@ static int
584e1000_set_ringparam(struct net_device *netdev, 595e1000_set_ringparam(struct net_device *netdev,
585 struct ethtool_ringparam *ring) 596 struct ethtool_ringparam *ring)
586{ 597{
587 struct e1000_adapter *adapter = netdev->priv; 598 struct e1000_adapter *adapter = netdev_priv(netdev);
588 e1000_mac_type mac_type = adapter->hw.mac_type; 599 e1000_mac_type mac_type = adapter->hw.mac_type;
589 struct e1000_desc_ring *txdr = &adapter->tx_ring; 600 struct e1000_desc_ring *txdr = &adapter->tx_ring;
590 struct e1000_desc_ring *rxdr = &adapter->rx_ring; 601 struct e1000_desc_ring *rxdr = &adapter->rx_ring;
@@ -651,6 +662,9 @@ err_setup_rx:
651 E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W)); \ 662 E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W)); \
652 value = E1000_READ_REG(&adapter->hw, R); \ 663 value = E1000_READ_REG(&adapter->hw, R); \
653 if(value != (test[pat] & W & M)) { \ 664 if(value != (test[pat] & W & M)) { \
665 DPRINTK(DRV, ERR, "pattern test reg %04X failed: got " \
666 "0x%08X expected 0x%08X\n", \
667 E1000_##R, value, (test[pat] & W & M)); \
654 *data = (adapter->hw.mac_type < e1000_82543) ? \ 668 *data = (adapter->hw.mac_type < e1000_82543) ? \
655 E1000_82542_##R : E1000_##R; \ 669 E1000_82542_##R : E1000_##R; \
656 return 1; \ 670 return 1; \
@@ -663,7 +677,9 @@ err_setup_rx:
663 uint32_t value; \ 677 uint32_t value; \
664 E1000_WRITE_REG(&adapter->hw, R, W & M); \ 678 E1000_WRITE_REG(&adapter->hw, R, W & M); \
665 value = E1000_READ_REG(&adapter->hw, R); \ 679 value = E1000_READ_REG(&adapter->hw, R); \
666 if ((W & M) != (value & M)) { \ 680 if((W & M) != (value & M)) { \
681 DPRINTK(DRV, ERR, "set/check reg %04X test failed: got 0x%08X "\
682 "expected 0x%08X\n", E1000_##R, (value & M), (W & M)); \
667 *data = (adapter->hw.mac_type < e1000_82543) ? \ 683 *data = (adapter->hw.mac_type < e1000_82543) ? \
668 E1000_82542_##R : E1000_##R; \ 684 E1000_82542_##R : E1000_##R; \
669 return 1; \ 685 return 1; \
@@ -673,18 +689,33 @@ err_setup_rx:
673static int 689static int
674e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data) 690e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
675{ 691{
676 uint32_t value; 692 uint32_t value, before, after;
677 uint32_t i; 693 uint32_t i, toggle;
678 694
679 /* The status register is Read Only, so a write should fail. 695 /* The status register is Read Only, so a write should fail.
680 * Some bits that get toggled are ignored. 696 * Some bits that get toggled are ignored.
681 */ 697 */
682 value = (E1000_READ_REG(&adapter->hw, STATUS) & (0xFFFFF833)); 698 switch (adapter->hw.mac_type) {
683 E1000_WRITE_REG(&adapter->hw, STATUS, (0xFFFFFFFF)); 699 case e1000_82573:
684 if(value != (E1000_READ_REG(&adapter->hw, STATUS) & (0xFFFFF833))) { 700 toggle = 0x7FFFF033;
701 break;
702 default:
703 toggle = 0xFFFFF833;
704 break;
705 }
706
707 before = E1000_READ_REG(&adapter->hw, STATUS);
708 value = (E1000_READ_REG(&adapter->hw, STATUS) & toggle);
709 E1000_WRITE_REG(&adapter->hw, STATUS, toggle);
710 after = E1000_READ_REG(&adapter->hw, STATUS) & toggle;
711 if(value != after) {
712 DPRINTK(DRV, ERR, "failed STATUS register test got: "
713 "0x%08X expected: 0x%08X\n", after, value);
685 *data = 1; 714 *data = 1;
686 return 1; 715 return 1;
687 } 716 }
717 /* restore previous status */
718 E1000_WRITE_REG(&adapter->hw, STATUS, before);
688 719
689 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF); 720 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
690 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF); 721 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
@@ -766,7 +797,7 @@ e1000_test_intr(int irq,
766 struct pt_regs *regs) 797 struct pt_regs *regs)
767{ 798{
768 struct net_device *netdev = (struct net_device *) data; 799 struct net_device *netdev = (struct net_device *) data;
769 struct e1000_adapter *adapter = netdev->priv; 800 struct e1000_adapter *adapter = netdev_priv(netdev);
770 801
771 adapter->test_icr |= E1000_READ_REG(&adapter->hw, ICR); 802 adapter->test_icr |= E1000_READ_REG(&adapter->hw, ICR);
772 803
@@ -1214,6 +1245,7 @@ e1000_set_phy_loopback(struct e1000_adapter *adapter)
1214 case e1000_82541_rev_2: 1245 case e1000_82541_rev_2:
1215 case e1000_82547: 1246 case e1000_82547:
1216 case e1000_82547_rev_2: 1247 case e1000_82547_rev_2:
1248 case e1000_82573:
1217 return e1000_integrated_phy_loopback(adapter); 1249 return e1000_integrated_phy_loopback(adapter);
1218 break; 1250 break;
1219 1251
@@ -1422,7 +1454,7 @@ static void
1422e1000_diag_test(struct net_device *netdev, 1454e1000_diag_test(struct net_device *netdev,
1423 struct ethtool_test *eth_test, uint64_t *data) 1455 struct ethtool_test *eth_test, uint64_t *data)
1424{ 1456{
1425 struct e1000_adapter *adapter = netdev->priv; 1457 struct e1000_adapter *adapter = netdev_priv(netdev);
1426 boolean_t if_running = netif_running(netdev); 1458 boolean_t if_running = netif_running(netdev);
1427 1459
1428 if(eth_test->flags == ETH_TEST_FL_OFFLINE) { 1460 if(eth_test->flags == ETH_TEST_FL_OFFLINE) {
@@ -1482,7 +1514,7 @@ e1000_diag_test(struct net_device *netdev,
1482static void 1514static void
1483e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 1515e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1484{ 1516{
1485 struct e1000_adapter *adapter = netdev->priv; 1517 struct e1000_adapter *adapter = netdev_priv(netdev);
1486 struct e1000_hw *hw = &adapter->hw; 1518 struct e1000_hw *hw = &adapter->hw;
1487 1519
1488 switch(adapter->hw.device_id) { 1520 switch(adapter->hw.device_id) {
@@ -1527,7 +1559,7 @@ e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1527static int 1559static int
1528e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 1560e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1529{ 1561{
1530 struct e1000_adapter *adapter = netdev->priv; 1562 struct e1000_adapter *adapter = netdev_priv(netdev);
1531 struct e1000_hw *hw = &adapter->hw; 1563 struct e1000_hw *hw = &adapter->hw;
1532 1564
1533 switch(adapter->hw.device_id) { 1565 switch(adapter->hw.device_id) {
@@ -1588,22 +1620,31 @@ e1000_led_blink_callback(unsigned long data)
1588static int 1620static int
1589e1000_phys_id(struct net_device *netdev, uint32_t data) 1621e1000_phys_id(struct net_device *netdev, uint32_t data)
1590{ 1622{
1591 struct e1000_adapter *adapter = netdev->priv; 1623 struct e1000_adapter *adapter = netdev_priv(netdev);
1592 1624
1593 if(!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ)) 1625 if(!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
1594 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ); 1626 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
1595 1627
1596 if(!adapter->blink_timer.function) { 1628 if(adapter->hw.mac_type < e1000_82573) {
1597 init_timer(&adapter->blink_timer); 1629 if(!adapter->blink_timer.function) {
1598 adapter->blink_timer.function = e1000_led_blink_callback; 1630 init_timer(&adapter->blink_timer);
1599 adapter->blink_timer.data = (unsigned long) adapter; 1631 adapter->blink_timer.function = e1000_led_blink_callback;
1632 adapter->blink_timer.data = (unsigned long) adapter;
1633 }
1634 e1000_setup_led(&adapter->hw);
1635 mod_timer(&adapter->blink_timer, jiffies);
1636 msleep_interruptible(data * 1000);
1637 del_timer_sync(&adapter->blink_timer);
1638 }
1639 else {
1640 E1000_WRITE_REG(&adapter->hw, LEDCTL, (E1000_LEDCTL_LED2_BLINK_RATE |
1641 E1000_LEDCTL_LED1_BLINK | E1000_LEDCTL_LED2_BLINK |
1642 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED2_MODE_SHIFT) |
1643 (E1000_LEDCTL_MODE_LINK_ACTIVITY << E1000_LEDCTL_LED1_MODE_SHIFT) |
1644 (E1000_LEDCTL_MODE_LED_OFF << E1000_LEDCTL_LED0_MODE_SHIFT)));
1645 msleep_interruptible(data * 1000);
1600 } 1646 }
1601 1647
1602 e1000_setup_led(&adapter->hw);
1603 mod_timer(&adapter->blink_timer, jiffies);
1604
1605 msleep_interruptible(data * 1000);
1606 del_timer_sync(&adapter->blink_timer);
1607 e1000_led_off(&adapter->hw); 1648 e1000_led_off(&adapter->hw);
1608 clear_bit(E1000_LED_ON, &adapter->led_status); 1649 clear_bit(E1000_LED_ON, &adapter->led_status);
1609 e1000_cleanup_led(&adapter->hw); 1650 e1000_cleanup_led(&adapter->hw);
@@ -1614,7 +1655,7 @@ e1000_phys_id(struct net_device *netdev, uint32_t data)
1614static int 1655static int
1615e1000_nway_reset(struct net_device *netdev) 1656e1000_nway_reset(struct net_device *netdev)
1616{ 1657{
1617 struct e1000_adapter *adapter = netdev->priv; 1658 struct e1000_adapter *adapter = netdev_priv(netdev);
1618 if(netif_running(netdev)) { 1659 if(netif_running(netdev)) {
1619 e1000_down(adapter); 1660 e1000_down(adapter);
1620 e1000_up(adapter); 1661 e1000_up(adapter);
@@ -1632,7 +1673,7 @@ static void
1632e1000_get_ethtool_stats(struct net_device *netdev, 1673e1000_get_ethtool_stats(struct net_device *netdev,
1633 struct ethtool_stats *stats, uint64_t *data) 1674 struct ethtool_stats *stats, uint64_t *data)
1634{ 1675{
1635 struct e1000_adapter *adapter = netdev->priv; 1676 struct e1000_adapter *adapter = netdev_priv(netdev);
1636 int i; 1677 int i;
1637 1678
1638 e1000_update_stats(adapter); 1679 e1000_update_stats(adapter);
diff --git a/drivers/net/e1000/e1000_hw.c b/drivers/net/e1000/e1000_hw.c
index 723589b28be5..045f5426ab9a 100644
--- a/drivers/net/e1000/e1000_hw.c
+++ b/drivers/net/e1000/e1000_hw.c
@@ -354,18 +354,27 @@ e1000_set_media_type(struct e1000_hw *hw)
354 hw->media_type = e1000_media_type_internal_serdes; 354 hw->media_type = e1000_media_type_internal_serdes;
355 break; 355 break;
356 default: 356 default:
357 if(hw->mac_type >= e1000_82543) { 357 switch (hw->mac_type) {
358 case e1000_82542_rev2_0:
359 case e1000_82542_rev2_1:
360 hw->media_type = e1000_media_type_fiber;
361 break;
362 case e1000_82573:
363 /* The STATUS_TBIMODE bit is reserved or reused for the this
364 * device.
365 */
366 hw->media_type = e1000_media_type_copper;
367 break;
368 default:
358 status = E1000_READ_REG(hw, STATUS); 369 status = E1000_READ_REG(hw, STATUS);
359 if(status & E1000_STATUS_TBIMODE) { 370 if (status & E1000_STATUS_TBIMODE) {
360 hw->media_type = e1000_media_type_fiber; 371 hw->media_type = e1000_media_type_fiber;
361 /* tbi_compatibility not valid on fiber */ 372 /* tbi_compatibility not valid on fiber */
362 hw->tbi_compatibility_en = FALSE; 373 hw->tbi_compatibility_en = FALSE;
363 } else { 374 } else {
364 hw->media_type = e1000_media_type_copper; 375 hw->media_type = e1000_media_type_copper;
365 } 376 }
366 } else { 377 break;
367 /* This is an 82542 (fiber only) */
368 hw->media_type = e1000_media_type_fiber;
369 } 378 }
370 } 379 }
371} 380}
@@ -1189,9 +1198,9 @@ e1000_copper_link_igp_setup(struct e1000_hw *hw)
1189 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); 1198 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1190 if(ret_val) 1199 if(ret_val)
1191 return ret_val; 1200 return ret_val;
1192 } 1201 }
1193 1202
1194 return E1000_SUCCESS; 1203 return E1000_SUCCESS;
1195} 1204}
1196 1205
1197 1206
diff --git a/drivers/net/e1000/e1000_hw.h b/drivers/net/e1000/e1000_hw.h
index a0263ee96c6b..93e9f8788751 100644
--- a/drivers/net/e1000/e1000_hw.h
+++ b/drivers/net/e1000/e1000_hw.h
@@ -66,6 +66,7 @@ typedef enum {
66 e1000_eeprom_spi, 66 e1000_eeprom_spi,
67 e1000_eeprom_microwire, 67 e1000_eeprom_microwire,
68 e1000_eeprom_flash, 68 e1000_eeprom_flash,
69 e1000_eeprom_none, /* No NVM support */
69 e1000_num_eeprom_types 70 e1000_num_eeprom_types
70} e1000_eeprom_type; 71} e1000_eeprom_type;
71 72
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 137226d98d47..cb7f051a60ad 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -29,6 +29,8 @@
29#include "e1000.h" 29#include "e1000.h"
30 30
31/* Change Log 31/* Change Log
32 * 6.0.58 4/20/05
33 * o Accepted ethtool cleanup patch from Stephen Hemminger
32 * 6.0.44+ 2/15/05 34 * 6.0.44+ 2/15/05
33 * o applied Anton's patch to resolve tx hang in hardware 35 * o applied Anton's patch to resolve tx hang in hardware
34 * o Applied Andrew Mortons patch - e1000 stops working after resume 36 * o Applied Andrew Mortons patch - e1000 stops working after resume
@@ -41,9 +43,9 @@ char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
41#else 43#else
42#define DRIVERNAPI "-NAPI" 44#define DRIVERNAPI "-NAPI"
43#endif 45#endif
44#define DRV_VERSION "6.0.54-k2"DRIVERNAPI 46#define DRV_VERSION "6.0.60-k2"DRIVERNAPI
45char e1000_driver_version[] = DRV_VERSION; 47char e1000_driver_version[] = DRV_VERSION;
46char e1000_copyright[] = "Copyright (c) 1999-2004 Intel Corporation."; 48char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
47 49
48/* e1000_pci_tbl - PCI Device ID Table 50/* e1000_pci_tbl - PCI Device ID Table
49 * 51 *
@@ -517,7 +519,7 @@ e1000_probe(struct pci_dev *pdev,
517 SET_NETDEV_DEV(netdev, &pdev->dev); 519 SET_NETDEV_DEV(netdev, &pdev->dev);
518 520
519 pci_set_drvdata(pdev, netdev); 521 pci_set_drvdata(pdev, netdev);
520 adapter = netdev->priv; 522 adapter = netdev_priv(netdev);
521 adapter->netdev = netdev; 523 adapter->netdev = netdev;
522 adapter->pdev = pdev; 524 adapter->pdev = pdev;
523 adapter->hw.back = adapter; 525 adapter->hw.back = adapter;
@@ -738,7 +740,7 @@ static void __devexit
738e1000_remove(struct pci_dev *pdev) 740e1000_remove(struct pci_dev *pdev)
739{ 741{
740 struct net_device *netdev = pci_get_drvdata(pdev); 742 struct net_device *netdev = pci_get_drvdata(pdev);
741 struct e1000_adapter *adapter = netdev->priv; 743 struct e1000_adapter *adapter = netdev_priv(netdev);
742 uint32_t manc, swsm; 744 uint32_t manc, swsm;
743 745
744 flush_scheduled_work(); 746 flush_scheduled_work();
@@ -871,7 +873,7 @@ e1000_sw_init(struct e1000_adapter *adapter)
871static int 873static int
872e1000_open(struct net_device *netdev) 874e1000_open(struct net_device *netdev)
873{ 875{
874 struct e1000_adapter *adapter = netdev->priv; 876 struct e1000_adapter *adapter = netdev_priv(netdev);
875 int err; 877 int err;
876 878
877 /* allocate transmit descriptors */ 879 /* allocate transmit descriptors */
@@ -919,7 +921,7 @@ err_setup_tx:
919static int 921static int
920e1000_close(struct net_device *netdev) 922e1000_close(struct net_device *netdev)
921{ 923{
922 struct e1000_adapter *adapter = netdev->priv; 924 struct e1000_adapter *adapter = netdev_priv(netdev);
923 925
924 e1000_down(adapter); 926 e1000_down(adapter);
925 927
@@ -1599,7 +1601,7 @@ e1000_leave_82542_rst(struct e1000_adapter *adapter)
1599static int 1601static int
1600e1000_set_mac(struct net_device *netdev, void *p) 1602e1000_set_mac(struct net_device *netdev, void *p)
1601{ 1603{
1602 struct e1000_adapter *adapter = netdev->priv; 1604 struct e1000_adapter *adapter = netdev_priv(netdev);
1603 struct sockaddr *addr = p; 1605 struct sockaddr *addr = p;
1604 1606
1605 if(!is_valid_ether_addr(addr->sa_data)) 1607 if(!is_valid_ether_addr(addr->sa_data))
@@ -1634,7 +1636,7 @@ e1000_set_mac(struct net_device *netdev, void *p)
1634static void 1636static void
1635e1000_set_multi(struct net_device *netdev) 1637e1000_set_multi(struct net_device *netdev)
1636{ 1638{
1637 struct e1000_adapter *adapter = netdev->priv; 1639 struct e1000_adapter *adapter = netdev_priv(netdev);
1638 struct e1000_hw *hw = &adapter->hw; 1640 struct e1000_hw *hw = &adapter->hw;
1639 struct dev_mc_list *mc_ptr; 1641 struct dev_mc_list *mc_ptr;
1640 unsigned long flags; 1642 unsigned long flags;
@@ -2213,7 +2215,7 @@ e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2213static int 2215static int
2214e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) 2216e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2215{ 2217{
2216 struct e1000_adapter *adapter = netdev->priv; 2218 struct e1000_adapter *adapter = netdev_priv(netdev);
2217 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; 2219 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2218 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; 2220 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2219 unsigned int tx_flags = 0; 2221 unsigned int tx_flags = 0;
@@ -2344,7 +2346,7 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2344static void 2346static void
2345e1000_tx_timeout(struct net_device *netdev) 2347e1000_tx_timeout(struct net_device *netdev)
2346{ 2348{
2347 struct e1000_adapter *adapter = netdev->priv; 2349 struct e1000_adapter *adapter = netdev_priv(netdev);
2348 2350
2349 /* Do the reset outside of interrupt context */ 2351 /* Do the reset outside of interrupt context */
2350 schedule_work(&adapter->tx_timeout_task); 2352 schedule_work(&adapter->tx_timeout_task);
@@ -2353,7 +2355,7 @@ e1000_tx_timeout(struct net_device *netdev)
2353static void 2355static void
2354e1000_tx_timeout_task(struct net_device *netdev) 2356e1000_tx_timeout_task(struct net_device *netdev)
2355{ 2357{
2356 struct e1000_adapter *adapter = netdev->priv; 2358 struct e1000_adapter *adapter = netdev_priv(netdev);
2357 2359
2358 e1000_down(adapter); 2360 e1000_down(adapter);
2359 e1000_up(adapter); 2361 e1000_up(adapter);
@@ -2370,7 +2372,7 @@ e1000_tx_timeout_task(struct net_device *netdev)
2370static struct net_device_stats * 2372static struct net_device_stats *
2371e1000_get_stats(struct net_device *netdev) 2373e1000_get_stats(struct net_device *netdev)
2372{ 2374{
2373 struct e1000_adapter *adapter = netdev->priv; 2375 struct e1000_adapter *adapter = netdev_priv(netdev);
2374 2376
2375 e1000_update_stats(adapter); 2377 e1000_update_stats(adapter);
2376 return &adapter->net_stats; 2378 return &adapter->net_stats;
@@ -2387,7 +2389,7 @@ e1000_get_stats(struct net_device *netdev)
2387static int 2389static int
2388e1000_change_mtu(struct net_device *netdev, int new_mtu) 2390e1000_change_mtu(struct net_device *netdev, int new_mtu)
2389{ 2391{
2390 struct e1000_adapter *adapter = netdev->priv; 2392 struct e1000_adapter *adapter = netdev_priv(netdev);
2391 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; 2393 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
2392 2394
2393 if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || 2395 if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
@@ -2598,7 +2600,7 @@ static irqreturn_t
2598e1000_intr(int irq, void *data, struct pt_regs *regs) 2600e1000_intr(int irq, void *data, struct pt_regs *regs)
2599{ 2601{
2600 struct net_device *netdev = data; 2602 struct net_device *netdev = data;
2601 struct e1000_adapter *adapter = netdev->priv; 2603 struct e1000_adapter *adapter = netdev_priv(netdev);
2602 struct e1000_hw *hw = &adapter->hw; 2604 struct e1000_hw *hw = &adapter->hw;
2603 uint32_t icr = E1000_READ_REG(hw, ICR); 2605 uint32_t icr = E1000_READ_REG(hw, ICR);
2604#ifndef CONFIG_E1000_NAPI 2606#ifndef CONFIG_E1000_NAPI
@@ -2661,7 +2663,7 @@ e1000_intr(int irq, void *data, struct pt_regs *regs)
2661static int 2663static int
2662e1000_clean(struct net_device *netdev, int *budget) 2664e1000_clean(struct net_device *netdev, int *budget)
2663{ 2665{
2664 struct e1000_adapter *adapter = netdev->priv; 2666 struct e1000_adapter *adapter = netdev_priv(netdev);
2665 int work_to_do = min(*budget, netdev->quota); 2667 int work_to_do = min(*budget, netdev->quota);
2666 int tx_cleaned; 2668 int tx_cleaned;
2667 int work_done = 0; 2669 int work_done = 0;
@@ -2672,8 +2674,8 @@ e1000_clean(struct net_device *netdev, int *budget)
2672 *budget -= work_done; 2674 *budget -= work_done;
2673 netdev->quota -= work_done; 2675 netdev->quota -= work_done;
2674 2676
2675 /* If no Tx and no Rx work done, exit the polling mode */
2676 if ((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) { 2677 if ((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
2678 /* If no Tx and not enough Rx work done, exit the polling mode */
2677 netif_rx_complete(netdev); 2679 netif_rx_complete(netdev);
2678 e1000_irq_enable(adapter); 2680 e1000_irq_enable(adapter);
2679 return 0; 2681 return 0;
@@ -2769,13 +2771,13 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter)
2769 i = tx_ring->next_to_clean; 2771 i = tx_ring->next_to_clean;
2770 eop = tx_ring->buffer_info[i].next_to_watch; 2772 eop = tx_ring->buffer_info[i].next_to_watch;
2771 eop_desc = E1000_TX_DESC(*tx_ring, eop); 2773 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2772 DPRINTK(TX_ERR, ERR, "Detected Tx Unit Hang\n" 2774 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
2773 " TDH <%x>\n" 2775 " TDH <%x>\n"
2774 " TDT <%x>\n" 2776 " TDT <%x>\n"
2775 " next_to_use <%x>\n" 2777 " next_to_use <%x>\n"
2776 " next_to_clean <%x>\n" 2778 " next_to_clean <%x>\n"
2777 "buffer_info[next_to_clean]\n" 2779 "buffer_info[next_to_clean]\n"
2778 " dma <%llx>\n" 2780 " dma <%zx>\n"
2779 " time_stamp <%lx>\n" 2781 " time_stamp <%lx>\n"
2780 " next_to_watch <%x>\n" 2782 " next_to_watch <%x>\n"
2781 " jiffies <%lx>\n" 2783 " jiffies <%lx>\n"
@@ -2994,7 +2996,7 @@ e1000_clean_rx_irq_ps(struct e1000_adapter *adapter)
2994 2996
2995 i = rx_ring->next_to_clean; 2997 i = rx_ring->next_to_clean;
2996 rx_desc = E1000_RX_DESC_PS(*rx_ring, i); 2998 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
2997 staterr = rx_desc->wb.middle.status_error; 2999 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
2998 3000
2999 while(staterr & E1000_RXD_STAT_DD) { 3001 while(staterr & E1000_RXD_STAT_DD) {
3000 buffer_info = &rx_ring->buffer_info[i]; 3002 buffer_info = &rx_ring->buffer_info[i];
@@ -3065,16 +3067,16 @@ e1000_clean_rx_irq_ps(struct e1000_adapter *adapter)
3065#ifdef CONFIG_E1000_NAPI 3067#ifdef CONFIG_E1000_NAPI
3066 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { 3068 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3067 vlan_hwaccel_receive_skb(skb, adapter->vlgrp, 3069 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3068 le16_to_cpu(rx_desc->wb.middle.vlan & 3070 le16_to_cpu(rx_desc->wb.middle.vlan) &
3069 E1000_RXD_SPC_VLAN_MASK)); 3071 E1000_RXD_SPC_VLAN_MASK);
3070 } else { 3072 } else {
3071 netif_receive_skb(skb); 3073 netif_receive_skb(skb);
3072 } 3074 }
3073#else /* CONFIG_E1000_NAPI */ 3075#else /* CONFIG_E1000_NAPI */
3074 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { 3076 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3075 vlan_hwaccel_rx(skb, adapter->vlgrp, 3077 vlan_hwaccel_rx(skb, adapter->vlgrp,
3076 le16_to_cpu(rx_desc->wb.middle.vlan & 3078 le16_to_cpu(rx_desc->wb.middle.vlan) &
3077 E1000_RXD_SPC_VLAN_MASK)); 3079 E1000_RXD_SPC_VLAN_MASK);
3078 } else { 3080 } else {
3079 netif_rx(skb); 3081 netif_rx(skb);
3080 } 3082 }
@@ -3087,7 +3089,7 @@ next_desc:
3087 if(unlikely(++i == rx_ring->count)) i = 0; 3089 if(unlikely(++i == rx_ring->count)) i = 0;
3088 3090
3089 rx_desc = E1000_RX_DESC_PS(*rx_ring, i); 3091 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3090 staterr = rx_desc->wb.middle.status_error; 3092 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3091 } 3093 }
3092 rx_ring->next_to_clean = i; 3094 rx_ring->next_to_clean = i;
3093 adapter->alloc_rx_buf(adapter); 3095 adapter->alloc_rx_buf(adapter);
@@ -3371,11 +3373,12 @@ e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3371static int 3373static int
3372e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) 3374e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3373{ 3375{
3374 struct e1000_adapter *adapter = netdev->priv; 3376 struct e1000_adapter *adapter = netdev_priv(netdev);
3375 struct mii_ioctl_data *data = if_mii(ifr); 3377 struct mii_ioctl_data *data = if_mii(ifr);
3376 int retval; 3378 int retval;
3377 uint16_t mii_reg; 3379 uint16_t mii_reg;
3378 uint16_t spddplx; 3380 uint16_t spddplx;
3381 unsigned long flags;
3379 3382
3380 if(adapter->hw.media_type != e1000_media_type_copper) 3383 if(adapter->hw.media_type != e1000_media_type_copper)
3381 return -EOPNOTSUPP; 3384 return -EOPNOTSUPP;
@@ -3385,22 +3388,29 @@ e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3385 data->phy_id = adapter->hw.phy_addr; 3388 data->phy_id = adapter->hw.phy_addr;
3386 break; 3389 break;
3387 case SIOCGMIIREG: 3390 case SIOCGMIIREG:
3388 if (!capable(CAP_NET_ADMIN)) 3391 if(!capable(CAP_NET_ADMIN))
3389 return -EPERM; 3392 return -EPERM;
3390 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F, 3393 spin_lock_irqsave(&adapter->stats_lock, flags);
3391 &data->val_out)) 3394 if(e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
3395 &data->val_out)) {
3396 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3392 return -EIO; 3397 return -EIO;
3398 }
3399 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3393 break; 3400 break;
3394 case SIOCSMIIREG: 3401 case SIOCSMIIREG:
3395 if (!capable(CAP_NET_ADMIN)) 3402 if(!capable(CAP_NET_ADMIN))
3396 return -EPERM; 3403 return -EPERM;
3397 if (data->reg_num & ~(0x1F)) 3404 if(data->reg_num & ~(0x1F))
3398 return -EFAULT; 3405 return -EFAULT;
3399 mii_reg = data->val_in; 3406 mii_reg = data->val_in;
3400 if (e1000_write_phy_reg(&adapter->hw, data->reg_num, 3407 spin_lock_irqsave(&adapter->stats_lock, flags);
3401 mii_reg)) 3408 if(e1000_write_phy_reg(&adapter->hw, data->reg_num,
3409 mii_reg)) {
3410 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3402 return -EIO; 3411 return -EIO;
3403 if (adapter->hw.phy_type == e1000_phy_m88) { 3412 }
3413 if(adapter->hw.phy_type == e1000_phy_m88) {
3404 switch (data->reg_num) { 3414 switch (data->reg_num) {
3405 case PHY_CTRL: 3415 case PHY_CTRL:
3406 if(mii_reg & MII_CR_POWER_DOWN) 3416 if(mii_reg & MII_CR_POWER_DOWN)
@@ -3420,8 +3430,12 @@ e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3420 HALF_DUPLEX; 3430 HALF_DUPLEX;
3421 retval = e1000_set_spd_dplx(adapter, 3431 retval = e1000_set_spd_dplx(adapter,
3422 spddplx); 3432 spddplx);
3423 if(retval) 3433 if(retval) {
3434 spin_unlock_irqrestore(
3435 &adapter->stats_lock,
3436 flags);
3424 return retval; 3437 return retval;
3438 }
3425 } 3439 }
3426 if(netif_running(adapter->netdev)) { 3440 if(netif_running(adapter->netdev)) {
3427 e1000_down(adapter); 3441 e1000_down(adapter);
@@ -3431,8 +3445,11 @@ e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3431 break; 3445 break;
3432 case M88E1000_PHY_SPEC_CTRL: 3446 case M88E1000_PHY_SPEC_CTRL:
3433 case M88E1000_EXT_PHY_SPEC_CTRL: 3447 case M88E1000_EXT_PHY_SPEC_CTRL:
3434 if (e1000_phy_reset(&adapter->hw)) 3448 if(e1000_phy_reset(&adapter->hw)) {
3449 spin_unlock_irqrestore(
3450 &adapter->stats_lock, flags);
3435 return -EIO; 3451 return -EIO;
3452 }
3436 break; 3453 break;
3437 } 3454 }
3438 } else { 3455 } else {
@@ -3448,6 +3465,7 @@ e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3448 break; 3465 break;
3449 } 3466 }
3450 } 3467 }
3468 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3451 break; 3469 break;
3452 default: 3470 default:
3453 return -EOPNOTSUPP; 3471 return -EOPNOTSUPP;
@@ -3504,7 +3522,7 @@ e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
3504static void 3522static void
3505e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp) 3523e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
3506{ 3524{
3507 struct e1000_adapter *adapter = netdev->priv; 3525 struct e1000_adapter *adapter = netdev_priv(netdev);
3508 uint32_t ctrl, rctl; 3526 uint32_t ctrl, rctl;
3509 3527
3510 e1000_irq_disable(adapter); 3528 e1000_irq_disable(adapter);
@@ -3544,7 +3562,7 @@ e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
3544static void 3562static void
3545e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid) 3563e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
3546{ 3564{
3547 struct e1000_adapter *adapter = netdev->priv; 3565 struct e1000_adapter *adapter = netdev_priv(netdev);
3548 uint32_t vfta, index; 3566 uint32_t vfta, index;
3549 if((adapter->hw.mng_cookie.status & 3567 if((adapter->hw.mng_cookie.status &
3550 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && 3568 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
@@ -3560,7 +3578,7 @@ e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
3560static void 3578static void
3561e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid) 3579e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
3562{ 3580{
3563 struct e1000_adapter *adapter = netdev->priv; 3581 struct e1000_adapter *adapter = netdev_priv(netdev);
3564 uint32_t vfta, index; 3582 uint32_t vfta, index;
3565 3583
3566 e1000_irq_disable(adapter); 3584 e1000_irq_disable(adapter);
@@ -3601,6 +3619,13 @@ e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
3601{ 3619{
3602 adapter->hw.autoneg = 0; 3620 adapter->hw.autoneg = 0;
3603 3621
3622 /* Fiber NICs only allow 1000 gbps Full duplex */
3623 if((adapter->hw.media_type == e1000_media_type_fiber) &&
3624 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
3625 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
3626 return -EINVAL;
3627 }
3628
3604 switch(spddplx) { 3629 switch(spddplx) {
3605 case SPEED_10 + DUPLEX_HALF: 3630 case SPEED_10 + DUPLEX_HALF:
3606 adapter->hw.forced_speed_duplex = e1000_10_half; 3631 adapter->hw.forced_speed_duplex = e1000_10_half;
@@ -3647,7 +3672,7 @@ static int
3647e1000_suspend(struct pci_dev *pdev, uint32_t state) 3672e1000_suspend(struct pci_dev *pdev, uint32_t state)
3648{ 3673{
3649 struct net_device *netdev = pci_get_drvdata(pdev); 3674 struct net_device *netdev = pci_get_drvdata(pdev);
3650 struct e1000_adapter *adapter = netdev->priv; 3675 struct e1000_adapter *adapter = netdev_priv(netdev);
3651 uint32_t ctrl, ctrl_ext, rctl, manc, status, swsm; 3676 uint32_t ctrl, ctrl_ext, rctl, manc, status, swsm;
3652 uint32_t wufc = adapter->wol; 3677 uint32_t wufc = adapter->wol;
3653 3678
@@ -3740,12 +3765,12 @@ static int
3740e1000_resume(struct pci_dev *pdev) 3765e1000_resume(struct pci_dev *pdev)
3741{ 3766{
3742 struct net_device *netdev = pci_get_drvdata(pdev); 3767 struct net_device *netdev = pci_get_drvdata(pdev);
3743 struct e1000_adapter *adapter = netdev->priv; 3768 struct e1000_adapter *adapter = netdev_priv(netdev);
3744 uint32_t manc, ret, swsm; 3769 uint32_t manc, ret_val, swsm;
3745 3770
3746 pci_set_power_state(pdev, 0); 3771 pci_set_power_state(pdev, 0);
3747 pci_restore_state(pdev); 3772 pci_restore_state(pdev);
3748 ret = pci_enable_device(pdev); 3773 ret_val = pci_enable_device(pdev);
3749 pci_set_master(pdev); 3774 pci_set_master(pdev);
3750 3775
3751 pci_enable_wake(pdev, 3, 0); 3776 pci_enable_wake(pdev, 3, 0);
@@ -3788,7 +3813,7 @@ e1000_resume(struct pci_dev *pdev)
3788static void 3813static void
3789e1000_netpoll(struct net_device *netdev) 3814e1000_netpoll(struct net_device *netdev)
3790{ 3815{
3791 struct e1000_adapter *adapter = netdev->priv; 3816 struct e1000_adapter *adapter = netdev_priv(netdev);
3792 disable_irq(adapter->pdev->irq); 3817 disable_irq(adapter->pdev->irq);
3793 e1000_intr(adapter->pdev->irq, netdev, NULL); 3818 e1000_intr(adapter->pdev->irq, netdev, NULL);
3794 enable_irq(adapter->pdev->irq); 3819 enable_irq(adapter->pdev->irq);
diff --git a/drivers/net/e2100.c b/drivers/net/e2100.c
index 51c9fa260830..f5a4dd7d8564 100644
--- a/drivers/net/e2100.c
+++ b/drivers/net/e2100.c
@@ -162,12 +162,7 @@ struct net_device * __init e2100_probe(int unit)
162 err = do_e2100_probe(dev); 162 err = do_e2100_probe(dev);
163 if (err) 163 if (err)
164 goto out; 164 goto out;
165 err = register_netdev(dev);
166 if (err)
167 goto out1;
168 return dev; 165 return dev;
169out1:
170 cleanup_card(dev);
171out: 166out:
172 free_netdev(dev); 167 free_netdev(dev);
173 return ERR_PTR(err); 168 return ERR_PTR(err);
@@ -286,6 +281,9 @@ static int __init e21_probe1(struct net_device *dev, int ioaddr)
286#endif 281#endif
287 NS8390_init(dev, 0); 282 NS8390_init(dev, 0);
288 283
284 retval = register_netdev(dev);
285 if (retval)
286 goto out;
289 return 0; 287 return 0;
290out: 288out:
291 release_region(ioaddr, E21_IO_EXTENT); 289 release_region(ioaddr, E21_IO_EXTENT);
@@ -453,11 +451,8 @@ init_module(void)
453 dev->mem_start = mem[this_dev]; 451 dev->mem_start = mem[this_dev];
454 dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */ 452 dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */
455 if (do_e2100_probe(dev) == 0) { 453 if (do_e2100_probe(dev) == 0) {
456 if (register_netdev(dev) == 0) { 454 dev_e21[found++] = dev;
457 dev_e21[found++] = dev; 455 continue;
458 continue;
459 }
460 cleanup_card(dev);
461 } 456 }
462 free_netdev(dev); 457 free_netdev(dev);
463 printk(KERN_WARNING "e2100.c: No E2100 card found (i/o = 0x%x).\n", io[this_dev]); 458 printk(KERN_WARNING "e2100.c: No E2100 card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/eepro.c b/drivers/net/eepro.c
index cd2475683027..dcb3028bb60f 100644
--- a/drivers/net/eepro.c
+++ b/drivers/net/eepro.c
@@ -600,12 +600,7 @@ struct net_device * __init eepro_probe(int unit)
600 err = do_eepro_probe(dev); 600 err = do_eepro_probe(dev);
601 if (err) 601 if (err)
602 goto out; 602 goto out;
603 err = register_netdev(dev);
604 if (err)
605 goto out1;
606 return dev; 603 return dev;
607out1:
608 release_region(dev->base_addr, EEPRO_IO_EXTENT);
609out: 604out:
610 free_netdev(dev); 605 free_netdev(dev);
611 return ERR_PTR(err); 606 return ERR_PTR(err);
@@ -758,6 +753,7 @@ static int __init eepro_probe1(struct net_device *dev, int autoprobe)
758 int i; 753 int i;
759 struct eepro_local *lp; 754 struct eepro_local *lp;
760 int ioaddr = dev->base_addr; 755 int ioaddr = dev->base_addr;
756 int err;
761 757
762 /* Grab the region so we can find another board if autoIRQ fails. */ 758 /* Grab the region so we can find another board if autoIRQ fails. */
763 if (!request_region(ioaddr, EEPRO_IO_EXTENT, DRV_NAME)) { 759 if (!request_region(ioaddr, EEPRO_IO_EXTENT, DRV_NAME)) {
@@ -873,10 +869,16 @@ static int __init eepro_probe1(struct net_device *dev, int autoprobe)
873 869
874 /* reset 82595 */ 870 /* reset 82595 */
875 eepro_reset(ioaddr); 871 eepro_reset(ioaddr);
872
873 err = register_netdev(dev);
874 if (err)
875 goto err;
876 return 0; 876 return 0;
877exit: 877exit:
878 err = -ENODEV;
879err:
878 release_region(dev->base_addr, EEPRO_IO_EXTENT); 880 release_region(dev->base_addr, EEPRO_IO_EXTENT);
879 return -ENODEV; 881 return err;
880} 882}
881 883
882/* Open/initialize the board. This is called (in the current kernel) 884/* Open/initialize the board. This is called (in the current kernel)
@@ -1834,11 +1836,8 @@ init_module(void)
1834 dev->irq = irq[i]; 1836 dev->irq = irq[i];
1835 1837
1836 if (do_eepro_probe(dev) == 0) { 1838 if (do_eepro_probe(dev) == 0) {
1837 if (register_netdev(dev) == 0) { 1839 dev_eepro[n_eepro++] = dev;
1838 dev_eepro[n_eepro++] = dev; 1840 continue;
1839 continue;
1840 }
1841 release_region(dev->base_addr, EEPRO_IO_EXTENT);
1842 } 1841 }
1843 free_netdev(dev); 1842 free_netdev(dev);
1844 break; 1843 break;
diff --git a/drivers/net/eepro100.c b/drivers/net/eepro100.c
index 98b3a2fdce90..1795425f512e 100644
--- a/drivers/net/eepro100.c
+++ b/drivers/net/eepro100.c
@@ -1269,7 +1269,7 @@ speedo_init_rx_ring(struct net_device *dev)
1269 if (skb == NULL) 1269 if (skb == NULL)
1270 break; /* OK. Just initially short of Rx bufs. */ 1270 break; /* OK. Just initially short of Rx bufs. */
1271 skb->dev = dev; /* Mark as being used by this device. */ 1271 skb->dev = dev; /* Mark as being used by this device. */
1272 rxf = (struct RxFD *)skb->tail; 1272 rxf = (struct RxFD *)skb->data;
1273 sp->rx_ringp[i] = rxf; 1273 sp->rx_ringp[i] = rxf;
1274 sp->rx_ring_dma[i] = 1274 sp->rx_ring_dma[i] =
1275 pci_map_single(sp->pdev, rxf, 1275 pci_map_single(sp->pdev, rxf,
@@ -1661,7 +1661,7 @@ static inline struct RxFD *speedo_rx_alloc(struct net_device *dev, int entry)
1661 sp->rx_ringp[entry] = NULL; 1661 sp->rx_ringp[entry] = NULL;
1662 return NULL; 1662 return NULL;
1663 } 1663 }
1664 rxf = sp->rx_ringp[entry] = (struct RxFD *)skb->tail; 1664 rxf = sp->rx_ringp[entry] = (struct RxFD *)skb->data;
1665 sp->rx_ring_dma[entry] = 1665 sp->rx_ring_dma[entry] =
1666 pci_map_single(sp->pdev, rxf, 1666 pci_map_single(sp->pdev, rxf,
1667 PKT_BUF_SZ + sizeof(struct RxFD), PCI_DMA_FROMDEVICE); 1667 PKT_BUF_SZ + sizeof(struct RxFD), PCI_DMA_FROMDEVICE);
@@ -1808,10 +1808,10 @@ speedo_rx(struct net_device *dev)
1808 1808
1809#if 1 || USE_IP_CSUM 1809#if 1 || USE_IP_CSUM
1810 /* Packet is in one chunk -- we can copy + cksum. */ 1810 /* Packet is in one chunk -- we can copy + cksum. */
1811 eth_copy_and_sum(skb, sp->rx_skbuff[entry]->tail, pkt_len, 0); 1811 eth_copy_and_sum(skb, sp->rx_skbuff[entry]->data, pkt_len, 0);
1812 skb_put(skb, pkt_len); 1812 skb_put(skb, pkt_len);
1813#else 1813#else
1814 memcpy(skb_put(skb, pkt_len), sp->rx_skbuff[entry]->tail, 1814 memcpy(skb_put(skb, pkt_len), sp->rx_skbuff[entry]->data,
1815 pkt_len); 1815 pkt_len);
1816#endif 1816#endif
1817 pci_dma_sync_single_for_device(sp->pdev, sp->rx_ring_dma[entry], 1817 pci_dma_sync_single_for_device(sp->pdev, sp->rx_ring_dma[entry],
diff --git a/drivers/net/eexpress.c b/drivers/net/eexpress.c
index fc8e7947b334..82bd356e4f3a 100644
--- a/drivers/net/eexpress.c
+++ b/drivers/net/eexpress.c
@@ -436,11 +436,8 @@ struct net_device * __init express_probe(int unit)
436 netdev_boot_setup_check(dev); 436 netdev_boot_setup_check(dev);
437 437
438 err = do_express_probe(dev); 438 err = do_express_probe(dev);
439 if (!err) { 439 if (!err)
440 err = register_netdev(dev); 440 return dev;
441 if (!err)
442 return dev;
443 }
444 free_netdev(dev); 441 free_netdev(dev);
445 return ERR_PTR(err); 442 return ERR_PTR(err);
446} 443}
@@ -1205,7 +1202,8 @@ static int __init eexp_hw_probe(struct net_device *dev, unsigned short ioaddr)
1205 dev->set_multicast_list = &eexp_set_multicast; 1202 dev->set_multicast_list = &eexp_set_multicast;
1206 dev->tx_timeout = eexp_timeout; 1203 dev->tx_timeout = eexp_timeout;
1207 dev->watchdog_timeo = 2*HZ; 1204 dev->watchdog_timeo = 2*HZ;
1208 return 0; 1205
1206 return register_netdev(dev);
1209} 1207}
1210 1208
1211/* 1209/*
@@ -1716,7 +1714,7 @@ int init_module(void)
1716 break; 1714 break;
1717 printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n"); 1715 printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
1718 } 1716 }
1719 if (do_express_probe(dev) == 0 && register_netdev(dev) == 0) { 1717 if (do_express_probe(dev) == 0) {
1720 dev_eexp[this_dev] = dev; 1718 dev_eexp[this_dev] = dev;
1721 found++; 1719 found++;
1722 continue; 1720 continue;
diff --git a/drivers/net/epic100.c b/drivers/net/epic100.c
index 81ebaedaa240..87f522738bfc 100644
--- a/drivers/net/epic100.c
+++ b/drivers/net/epic100.c
@@ -1003,7 +1003,7 @@ static void epic_init_ring(struct net_device *dev)
1003 skb->dev = dev; /* Mark as being used by this device. */ 1003 skb->dev = dev; /* Mark as being used by this device. */
1004 skb_reserve(skb, 2); /* 16 byte align the IP header. */ 1004 skb_reserve(skb, 2); /* 16 byte align the IP header. */
1005 ep->rx_ring[i].bufaddr = pci_map_single(ep->pci_dev, 1005 ep->rx_ring[i].bufaddr = pci_map_single(ep->pci_dev,
1006 skb->tail, ep->rx_buf_sz, PCI_DMA_FROMDEVICE); 1006 skb->data, ep->rx_buf_sz, PCI_DMA_FROMDEVICE);
1007 ep->rx_ring[i].rxstatus = cpu_to_le32(DescOwn); 1007 ep->rx_ring[i].rxstatus = cpu_to_le32(DescOwn);
1008 } 1008 }
1009 ep->dirty_rx = (unsigned int)(i - RX_RING_SIZE); 1009 ep->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
@@ -1274,7 +1274,7 @@ static int epic_rx(struct net_device *dev, int budget)
1274 ep->rx_ring[entry].bufaddr, 1274 ep->rx_ring[entry].bufaddr,
1275 ep->rx_buf_sz, 1275 ep->rx_buf_sz,
1276 PCI_DMA_FROMDEVICE); 1276 PCI_DMA_FROMDEVICE);
1277 eth_copy_and_sum(skb, ep->rx_skbuff[entry]->tail, pkt_len, 0); 1277 eth_copy_and_sum(skb, ep->rx_skbuff[entry]->data, pkt_len, 0);
1278 skb_put(skb, pkt_len); 1278 skb_put(skb, pkt_len);
1279 pci_dma_sync_single_for_device(ep->pci_dev, 1279 pci_dma_sync_single_for_device(ep->pci_dev,
1280 ep->rx_ring[entry].bufaddr, 1280 ep->rx_ring[entry].bufaddr,
@@ -1308,7 +1308,7 @@ static int epic_rx(struct net_device *dev, int budget)
1308 skb->dev = dev; /* Mark as being used by this device. */ 1308 skb->dev = dev; /* Mark as being used by this device. */
1309 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 1309 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1310 ep->rx_ring[entry].bufaddr = pci_map_single(ep->pci_dev, 1310 ep->rx_ring[entry].bufaddr = pci_map_single(ep->pci_dev,
1311 skb->tail, ep->rx_buf_sz, PCI_DMA_FROMDEVICE); 1311 skb->data, ep->rx_buf_sz, PCI_DMA_FROMDEVICE);
1312 work_done++; 1312 work_done++;
1313 } 1313 }
1314 ep->rx_ring[entry].rxstatus = cpu_to_le32(DescOwn); 1314 ep->rx_ring[entry].rxstatus = cpu_to_le32(DescOwn);
diff --git a/drivers/net/es3210.c b/drivers/net/es3210.c
index f1e8150ed2a0..50f8e23bb9e5 100644
--- a/drivers/net/es3210.c
+++ b/drivers/net/es3210.c
@@ -177,12 +177,7 @@ struct net_device * __init es_probe(int unit)
177 err = do_es_probe(dev); 177 err = do_es_probe(dev);
178 if (err) 178 if (err)
179 goto out; 179 goto out;
180 err = register_netdev(dev);
181 if (err)
182 goto out1;
183 return dev; 180 return dev;
184out1:
185 cleanup_card(dev);
186out: 181out:
187 free_netdev(dev); 182 free_netdev(dev);
188 return ERR_PTR(err); 183 return ERR_PTR(err);
@@ -310,6 +305,10 @@ static int __init es_probe1(struct net_device *dev, int ioaddr)
310 dev->poll_controller = ei_poll; 305 dev->poll_controller = ei_poll;
311#endif 306#endif
312 NS8390_init(dev, 0); 307 NS8390_init(dev, 0);
308
309 retval = register_netdev(dev);
310 if (retval)
311 goto out1;
313 return 0; 312 return 0;
314out1: 313out1:
315 free_irq(dev->irq, dev); 314 free_irq(dev->irq, dev);
@@ -445,11 +444,8 @@ init_module(void)
445 dev->base_addr = io[this_dev]; 444 dev->base_addr = io[this_dev];
446 dev->mem_start = mem[this_dev]; 445 dev->mem_start = mem[this_dev];
447 if (do_es_probe(dev) == 0) { 446 if (do_es_probe(dev) == 0) {
448 if (register_netdev(dev) == 0) { 447 dev_es3210[found++] = dev;
449 dev_es3210[found++] = dev; 448 continue;
450 continue;
451 }
452 cleanup_card(dev);
453 } 449 }
454 free_netdev(dev); 450 free_netdev(dev);
455 printk(KERN_WARNING "es3210.c: No es3210 card found (i/o = 0x%x).\n", io[this_dev]); 451 printk(KERN_WARNING "es3210.c: No es3210 card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/eth16i.c b/drivers/net/eth16i.c
index ccae6ba5f7c5..f32a6b3acb2a 100644
--- a/drivers/net/eth16i.c
+++ b/drivers/net/eth16i.c
@@ -473,13 +473,7 @@ struct net_device * __init eth16i_probe(int unit)
473 err = do_eth16i_probe(dev); 473 err = do_eth16i_probe(dev);
474 if (err) 474 if (err)
475 goto out; 475 goto out;
476 err = register_netdev(dev);
477 if (err)
478 goto out1;
479 return dev; 476 return dev;
480out1:
481 free_irq(dev->irq, dev);
482 release_region(dev->base_addr, ETH16I_IO_EXTENT);
483out: 477out:
484 free_netdev(dev); 478 free_netdev(dev);
485 return ERR_PTR(err); 479 return ERR_PTR(err);
@@ -569,7 +563,13 @@ static int __init eth16i_probe1(struct net_device *dev, int ioaddr)
569 dev->tx_timeout = eth16i_timeout; 563 dev->tx_timeout = eth16i_timeout;
570 dev->watchdog_timeo = TX_TIMEOUT; 564 dev->watchdog_timeo = TX_TIMEOUT;
571 spin_lock_init(&lp->lock); 565 spin_lock_init(&lp->lock);
566
567 retval = register_netdev(dev);
568 if (retval)
569 goto out1;
572 return 0; 570 return 0;
571out1:
572 free_irq(dev->irq, dev);
573out: 573out:
574 release_region(ioaddr, ETH16I_IO_EXTENT); 574 release_region(ioaddr, ETH16I_IO_EXTENT);
575 return retval; 575 return retval;
@@ -1462,12 +1462,8 @@ int init_module(void)
1462 } 1462 }
1463 1463
1464 if (do_eth16i_probe(dev) == 0) { 1464 if (do_eth16i_probe(dev) == 0) {
1465 if (register_netdev(dev) == 0) { 1465 dev_eth16i[found++] = dev;
1466 dev_eth16i[found++] = dev; 1466 continue;
1467 continue;
1468 }
1469 free_irq(dev->irq, dev);
1470 release_region(dev->base_addr, ETH16I_IO_EXTENT);
1471 } 1467 }
1472 printk(KERN_WARNING "eth16i.c No Eth16i card found (i/o = 0x%x).\n", 1468 printk(KERN_WARNING "eth16i.c No Eth16i card found (i/o = 0x%x).\n",
1473 io[this_dev]); 1469 io[this_dev]);
diff --git a/drivers/net/ewrk3.c b/drivers/net/ewrk3.c
index dcf969b20be9..b987f9474730 100644
--- a/drivers/net/ewrk3.c
+++ b/drivers/net/ewrk3.c
@@ -1308,15 +1308,9 @@ static int __init eisa_probe(struct net_device *dev, u_long ioaddr)
1308 if (ioaddr < 0x1000) 1308 if (ioaddr < 0x1000)
1309 goto out; 1309 goto out;
1310 1310
1311 if (ioaddr == 0) { /* Autoprobing */ 1311 iobase = ioaddr;
1312 iobase = EISA_SLOT_INC; /* Get the first slot address */ 1312 i = (ioaddr >> 12);
1313 i = 1; 1313 maxSlots = i + 1;
1314 maxSlots = MAX_EISA_SLOTS;
1315 } else { /* Probe a specific location */
1316 iobase = ioaddr;
1317 i = (ioaddr >> 12);
1318 maxSlots = i + 1;
1319 }
1320 1314
1321 for (i = 1; (i < maxSlots) && (dev != NULL); i++, iobase += EISA_SLOT_INC) { 1315 for (i = 1; (i < maxSlots) && (dev != NULL); i++, iobase += EISA_SLOT_INC) {
1322 if (EISA_signature(name, EISA_ID) == 0) { 1316 if (EISA_signature(name, EISA_ID) == 0) {
diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c
index d05e9dd1e140..55dbe9a3fd56 100644
--- a/drivers/net/fealnx.c
+++ b/drivers/net/fealnx.c
@@ -1107,7 +1107,7 @@ static void allocate_rx_buffers(struct net_device *dev)
1107 1107
1108 skb->dev = dev; /* Mark as being used by this device. */ 1108 skb->dev = dev; /* Mark as being used by this device. */
1109 np->lack_rxbuf->skbuff = skb; 1109 np->lack_rxbuf->skbuff = skb;
1110 np->lack_rxbuf->buffer = pci_map_single(np->pci_dev, skb->tail, 1110 np->lack_rxbuf->buffer = pci_map_single(np->pci_dev, skb->data,
1111 np->rx_buf_sz, PCI_DMA_FROMDEVICE); 1111 np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1112 np->lack_rxbuf->status = RXOWN; 1112 np->lack_rxbuf->status = RXOWN;
1113 ++np->really_rx_count; 1113 ++np->really_rx_count;
@@ -1300,7 +1300,7 @@ static void init_ring(struct net_device *dev)
1300 ++np->really_rx_count; 1300 ++np->really_rx_count;
1301 np->rx_ring[i].skbuff = skb; 1301 np->rx_ring[i].skbuff = skb;
1302 skb->dev = dev; /* Mark as being used by this device. */ 1302 skb->dev = dev; /* Mark as being used by this device. */
1303 np->rx_ring[i].buffer = pci_map_single(np->pci_dev, skb->tail, 1303 np->rx_ring[i].buffer = pci_map_single(np->pci_dev, skb->data,
1304 np->rx_buf_sz, PCI_DMA_FROMDEVICE); 1304 np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1305 np->rx_ring[i].status = RXOWN; 1305 np->rx_ring[i].status = RXOWN;
1306 np->rx_ring[i].control |= RXIC; 1306 np->rx_ring[i].control |= RXIC;
@@ -1423,8 +1423,7 @@ static void reset_tx_descriptors(struct net_device *dev)
1423 if (cur->skbuff) { 1423 if (cur->skbuff) {
1424 pci_unmap_single(np->pci_dev, cur->buffer, 1424 pci_unmap_single(np->pci_dev, cur->buffer,
1425 cur->skbuff->len, PCI_DMA_TODEVICE); 1425 cur->skbuff->len, PCI_DMA_TODEVICE);
1426 dev_kfree_skb(cur->skbuff); 1426 dev_kfree_skb_any(cur->skbuff);
1427 /* or dev_kfree_skb_irq(cur->skbuff); ? */
1428 cur->skbuff = NULL; 1427 cur->skbuff = NULL;
1429 } 1428 }
1430 cur->status = 0; 1429 cur->status = 0;
@@ -1738,11 +1737,11 @@ static int netdev_rx(struct net_device *dev)
1738 1737
1739#if ! defined(__alpha__) 1738#if ! defined(__alpha__)
1740 eth_copy_and_sum(skb, 1739 eth_copy_and_sum(skb,
1741 np->cur_rx->skbuff->tail, pkt_len, 0); 1740 np->cur_rx->skbuff->data, pkt_len, 0);
1742 skb_put(skb, pkt_len); 1741 skb_put(skb, pkt_len);
1743#else 1742#else
1744 memcpy(skb_put(skb, pkt_len), 1743 memcpy(skb_put(skb, pkt_len),
1745 np->cur_rx->skbuff->tail, pkt_len); 1744 np->cur_rx->skbuff->data, pkt_len);
1746#endif 1745#endif
1747 pci_dma_sync_single_for_device(np->pci_dev, 1746 pci_dma_sync_single_for_device(np->pci_dev,
1748 np->cur_rx->buffer, 1747 np->cur_rx->buffer,
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index 4ebcd052e150..64f0f697c958 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -82,6 +82,9 @@
82 * 0.31: 14 Nov 2004: ethtool support for getting/setting link 82 * 0.31: 14 Nov 2004: ethtool support for getting/setting link
83 * capabilities. 83 * capabilities.
84 * 0.32: 16 Apr 2005: RX_ERROR4 handling added. 84 * 0.32: 16 Apr 2005: RX_ERROR4 handling added.
85 * 0.33: 16 May 2005: Support for MCP51 added.
86 * 0.34: 18 Jun 2005: Add DEV_NEED_LINKTIMER to all nForce nics.
87 * 0.35: 26 Jun 2005: Support for MCP55 added.
85 * 88 *
86 * Known bugs: 89 * Known bugs:
87 * We suspect that on some hardware no TX done interrupts are generated. 90 * We suspect that on some hardware no TX done interrupts are generated.
@@ -93,7 +96,7 @@
93 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few 96 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few
94 * superfluous timer interrupts from the nic. 97 * superfluous timer interrupts from the nic.
95 */ 98 */
96#define FORCEDETH_VERSION "0.32" 99#define FORCEDETH_VERSION "0.35"
97#define DRV_NAME "forcedeth" 100#define DRV_NAME "forcedeth"
98 101
99#include <linux/module.h> 102#include <linux/module.h>
@@ -2005,7 +2008,9 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
2005 /* handle different descriptor versions */ 2008 /* handle different descriptor versions */
2006 if (pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_1 || 2009 if (pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_1 ||
2007 pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_2 || 2010 pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_2 ||
2008 pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_3) 2011 pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_3 ||
2012 pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_12 ||
2013 pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_13)
2009 np->desc_ver = DESC_VER_1; 2014 np->desc_ver = DESC_VER_1;
2010 else 2015 else
2011 np->desc_ver = DESC_VER_2; 2016 np->desc_ver = DESC_VER_2;
@@ -2215,56 +2220,84 @@ static struct pci_device_id pci_tbl[] = {
2215 .device = PCI_DEVICE_ID_NVIDIA_NVENET_4, 2220 .device = PCI_DEVICE_ID_NVIDIA_NVENET_4,
2216 .subvendor = PCI_ANY_ID, 2221 .subvendor = PCI_ANY_ID,
2217 .subdevice = PCI_ANY_ID, 2222 .subdevice = PCI_ANY_ID,
2218 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2223 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2219 }, 2224 },
2220 { /* nForce3 Ethernet Controller */ 2225 { /* nForce3 Ethernet Controller */
2221 .vendor = PCI_VENDOR_ID_NVIDIA, 2226 .vendor = PCI_VENDOR_ID_NVIDIA,
2222 .device = PCI_DEVICE_ID_NVIDIA_NVENET_5, 2227 .device = PCI_DEVICE_ID_NVIDIA_NVENET_5,
2223 .subvendor = PCI_ANY_ID, 2228 .subvendor = PCI_ANY_ID,
2224 .subdevice = PCI_ANY_ID, 2229 .subdevice = PCI_ANY_ID,
2225 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2230 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2226 }, 2231 },
2227 { /* nForce3 Ethernet Controller */ 2232 { /* nForce3 Ethernet Controller */
2228 .vendor = PCI_VENDOR_ID_NVIDIA, 2233 .vendor = PCI_VENDOR_ID_NVIDIA,
2229 .device = PCI_DEVICE_ID_NVIDIA_NVENET_6, 2234 .device = PCI_DEVICE_ID_NVIDIA_NVENET_6,
2230 .subvendor = PCI_ANY_ID, 2235 .subvendor = PCI_ANY_ID,
2231 .subdevice = PCI_ANY_ID, 2236 .subdevice = PCI_ANY_ID,
2232 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2237 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2233 }, 2238 },
2234 { /* nForce3 Ethernet Controller */ 2239 { /* nForce3 Ethernet Controller */
2235 .vendor = PCI_VENDOR_ID_NVIDIA, 2240 .vendor = PCI_VENDOR_ID_NVIDIA,
2236 .device = PCI_DEVICE_ID_NVIDIA_NVENET_7, 2241 .device = PCI_DEVICE_ID_NVIDIA_NVENET_7,
2237 .subvendor = PCI_ANY_ID, 2242 .subvendor = PCI_ANY_ID,
2238 .subdevice = PCI_ANY_ID, 2243 .subdevice = PCI_ANY_ID,
2239 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2244 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2240 }, 2245 },
2241 { /* CK804 Ethernet Controller */ 2246 { /* CK804 Ethernet Controller */
2242 .vendor = PCI_VENDOR_ID_NVIDIA, 2247 .vendor = PCI_VENDOR_ID_NVIDIA,
2243 .device = PCI_DEVICE_ID_NVIDIA_NVENET_8, 2248 .device = PCI_DEVICE_ID_NVIDIA_NVENET_8,
2244 .subvendor = PCI_ANY_ID, 2249 .subvendor = PCI_ANY_ID,
2245 .subdevice = PCI_ANY_ID, 2250 .subdevice = PCI_ANY_ID,
2246 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2251 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2247 }, 2252 },
2248 { /* CK804 Ethernet Controller */ 2253 { /* CK804 Ethernet Controller */
2249 .vendor = PCI_VENDOR_ID_NVIDIA, 2254 .vendor = PCI_VENDOR_ID_NVIDIA,
2250 .device = PCI_DEVICE_ID_NVIDIA_NVENET_9, 2255 .device = PCI_DEVICE_ID_NVIDIA_NVENET_9,
2251 .subvendor = PCI_ANY_ID, 2256 .subvendor = PCI_ANY_ID,
2252 .subdevice = PCI_ANY_ID, 2257 .subdevice = PCI_ANY_ID,
2253 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2258 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2254 }, 2259 },
2255 { /* MCP04 Ethernet Controller */ 2260 { /* MCP04 Ethernet Controller */
2256 .vendor = PCI_VENDOR_ID_NVIDIA, 2261 .vendor = PCI_VENDOR_ID_NVIDIA,
2257 .device = PCI_DEVICE_ID_NVIDIA_NVENET_10, 2262 .device = PCI_DEVICE_ID_NVIDIA_NVENET_10,
2258 .subvendor = PCI_ANY_ID, 2263 .subvendor = PCI_ANY_ID,
2259 .subdevice = PCI_ANY_ID, 2264 .subdevice = PCI_ANY_ID,
2260 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2265 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2261 }, 2266 },
2262 { /* MCP04 Ethernet Controller */ 2267 { /* MCP04 Ethernet Controller */
2263 .vendor = PCI_VENDOR_ID_NVIDIA, 2268 .vendor = PCI_VENDOR_ID_NVIDIA,
2264 .device = PCI_DEVICE_ID_NVIDIA_NVENET_11, 2269 .device = PCI_DEVICE_ID_NVIDIA_NVENET_11,
2265 .subvendor = PCI_ANY_ID, 2270 .subvendor = PCI_ANY_ID,
2266 .subdevice = PCI_ANY_ID, 2271 .subdevice = PCI_ANY_ID,
2267 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2272 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2273 },
2274 { /* MCP51 Ethernet Controller */
2275 .vendor = PCI_VENDOR_ID_NVIDIA,
2276 .device = PCI_DEVICE_ID_NVIDIA_NVENET_12,
2277 .subvendor = PCI_ANY_ID,
2278 .subdevice = PCI_ANY_ID,
2279 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2280 },
2281 { /* MCP51 Ethernet Controller */
2282 .vendor = PCI_VENDOR_ID_NVIDIA,
2283 .device = PCI_DEVICE_ID_NVIDIA_NVENET_13,
2284 .subvendor = PCI_ANY_ID,
2285 .subdevice = PCI_ANY_ID,
2286 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2287 },
2288 { /* MCP55 Ethernet Controller */
2289 .vendor = PCI_VENDOR_ID_NVIDIA,
2290 .device = PCI_DEVICE_ID_NVIDIA_NVENET_14,
2291 .subvendor = PCI_ANY_ID,
2292 .subdevice = PCI_ANY_ID,
2293 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2294 },
2295 { /* MCP55 Ethernet Controller */
2296 .vendor = PCI_VENDOR_ID_NVIDIA,
2297 .device = PCI_DEVICE_ID_NVIDIA_NVENET_15,
2298 .subvendor = PCI_ANY_ID,
2299 .subdevice = PCI_ANY_ID,
2300 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2268 }, 2301 },
2269 {0,}, 2302 {0,},
2270}; 2303};
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index b43b2b11aacd..6518334b9280 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * drivers/net/gianfar.c 2 * drivers/net/gianfar.c
3 * 3 *
4 * Gianfar Ethernet Driver 4 * Gianfar Ethernet Driver
@@ -22,10 +22,9 @@
22 * B-V +1.62 22 * B-V +1.62
23 * 23 *
24 * Theory of operation 24 * Theory of operation
25 * This driver is designed for the Triple-speed Ethernet 25 * This driver is designed for the non-CPM ethernet controllers
26 * controllers on the Freescale 8540/8560 integrated processors, 26 * on the 85xx and 83xx family of integrated processors
27 * as well as the Fast Ethernet Controller on the 8540. 27 *
28 *
29 * The driver is initialized through platform_device. Structures which 28 * The driver is initialized through platform_device. Structures which
30 * define the configuration needed by the board are defined in a 29 * define the configuration needed by the board are defined in a
31 * board structure in arch/ppc/platforms (though I do not 30 * board structure in arch/ppc/platforms (though I do not
@@ -39,12 +38,12 @@
39 * 38 *
40 * The Gianfar Ethernet Controller uses a ring of buffer 39 * The Gianfar Ethernet Controller uses a ring of buffer
41 * descriptors. The beginning is indicated by a register 40 * descriptors. The beginning is indicated by a register
42 * pointing to the physical address of the start of the ring. 41 * pointing to the physical address of the start of the ring.
43 * The end is determined by a "wrap" bit being set in the 42 * The end is determined by a "wrap" bit being set in the
44 * last descriptor of the ring. 43 * last descriptor of the ring.
45 * 44 *
46 * When a packet is received, the RXF bit in the 45 * When a packet is received, the RXF bit in the
47 * IEVENT register is set, triggering an interrupt when the 46 * IEVENT register is set, triggering an interrupt when the
48 * corresponding bit in the IMASK register is also set (if 47 * corresponding bit in the IMASK register is also set (if
49 * interrupt coalescing is active, then the interrupt may not 48 * interrupt coalescing is active, then the interrupt may not
50 * happen immediately, but will wait until either a set number 49 * happen immediately, but will wait until either a set number
@@ -52,7 +51,7 @@
52 * interrupt handler will signal there is work to be done, and 51 * interrupt handler will signal there is work to be done, and
53 * exit. Without NAPI, the packet(s) will be handled 52 * exit. Without NAPI, the packet(s) will be handled
54 * immediately. Both methods will start at the last known empty 53 * immediately. Both methods will start at the last known empty
55 * descriptor, and process every subsequent descriptor until there 54 * descriptor, and process every subsequent descriptor until there
56 * are none left with data (NAPI will stop after a set number of 55 * are none left with data (NAPI will stop after a set number of
57 * packets to give time to other tasks, but will eventually 56 * packets to give time to other tasks, but will eventually
58 * process all the packets). The data arrives inside a 57 * process all the packets). The data arrives inside a
@@ -83,9 +82,13 @@
83#include <linux/netdevice.h> 82#include <linux/netdevice.h>
84#include <linux/etherdevice.h> 83#include <linux/etherdevice.h>
85#include <linux/skbuff.h> 84#include <linux/skbuff.h>
85#include <linux/if_vlan.h>
86#include <linux/spinlock.h> 86#include <linux/spinlock.h>
87#include <linux/mm.h> 87#include <linux/mm.h>
88#include <linux/device.h> 88#include <linux/device.h>
89#include <linux/ip.h>
90#include <linux/tcp.h>
91#include <linux/udp.h>
89 92
90#include <asm/io.h> 93#include <asm/io.h>
91#include <asm/irq.h> 94#include <asm/irq.h>
@@ -123,7 +126,7 @@ static int gfar_set_mac_address(struct net_device *dev);
123static int gfar_change_mtu(struct net_device *dev, int new_mtu); 126static int gfar_change_mtu(struct net_device *dev, int new_mtu);
124static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs); 127static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs);
125static irqreturn_t gfar_transmit(int irq, void *dev_id, struct pt_regs *regs); 128static irqreturn_t gfar_transmit(int irq, void *dev_id, struct pt_regs *regs);
126irqreturn_t gfar_receive(int irq, void *dev_id, struct pt_regs *regs); 129static irqreturn_t gfar_receive(int irq, void *dev_id, struct pt_regs *regs);
127static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs); 130static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs);
128static irqreturn_t phy_interrupt(int irq, void *dev_id, struct pt_regs *regs); 131static irqreturn_t phy_interrupt(int irq, void *dev_id, struct pt_regs *regs);
129static void gfar_phy_change(void *data); 132static void gfar_phy_change(void *data);
@@ -139,9 +142,12 @@ static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr);
139#ifdef CONFIG_GFAR_NAPI 142#ifdef CONFIG_GFAR_NAPI
140static int gfar_poll(struct net_device *dev, int *budget); 143static int gfar_poll(struct net_device *dev, int *budget);
141#endif 144#endif
142static int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit); 145int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit);
143static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, int length); 146static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, int length);
144static void gfar_phy_startup_timer(unsigned long data); 147static void gfar_phy_startup_timer(unsigned long data);
148static void gfar_vlan_rx_register(struct net_device *netdev,
149 struct vlan_group *grp);
150static void gfar_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
145 151
146extern struct ethtool_ops gfar_ethtool_ops; 152extern struct ethtool_ops gfar_ethtool_ops;
147 153
@@ -149,6 +155,13 @@ MODULE_AUTHOR("Freescale Semiconductor, Inc");
149MODULE_DESCRIPTION("Gianfar Ethernet Driver"); 155MODULE_DESCRIPTION("Gianfar Ethernet Driver");
150MODULE_LICENSE("GPL"); 156MODULE_LICENSE("GPL");
151 157
158int gfar_uses_fcb(struct gfar_private *priv)
159{
160 if (priv->vlan_enable || priv->rx_csum_enable)
161 return 1;
162 else
163 return 0;
164}
152static int gfar_probe(struct device *device) 165static int gfar_probe(struct device *device)
153{ 166{
154 u32 tempval; 167 u32 tempval;
@@ -159,7 +172,6 @@ static int gfar_probe(struct device *device)
159 struct resource *r; 172 struct resource *r;
160 int idx; 173 int idx;
161 int err = 0; 174 int err = 0;
162 int dev_ethtool_ops = 0;
163 175
164 einfo = (struct gianfar_platform_data *) pdev->dev.platform_data; 176 einfo = (struct gianfar_platform_data *) pdev->dev.platform_data;
165 177
@@ -265,15 +277,69 @@ static int gfar_probe(struct device *device)
265 dev->mtu = 1500; 277 dev->mtu = 1500;
266 dev->set_multicast_list = gfar_set_multi; 278 dev->set_multicast_list = gfar_set_multi;
267 279
268 /* Index into the array of possible ethtool 280 dev->ethtool_ops = &gfar_ethtool_ops;
269 * ops to catch all 4 possibilities */ 281
270 if((priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) == 0) 282 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) {
271 dev_ethtool_ops += 1; 283 priv->rx_csum_enable = 1;
284 dev->features |= NETIF_F_IP_CSUM;
285 } else
286 priv->rx_csum_enable = 0;
287
288 priv->vlgrp = NULL;
272 289
273 if((priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE) == 0) 290 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) {
274 dev_ethtool_ops += 2; 291 dev->vlan_rx_register = gfar_vlan_rx_register;
292 dev->vlan_rx_kill_vid = gfar_vlan_rx_kill_vid;
275 293
276 dev->ethtool_ops = gfar_op_array[dev_ethtool_ops]; 294 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
295
296 priv->vlan_enable = 1;
297 }
298
299 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) {
300 priv->extended_hash = 1;
301 priv->hash_width = 9;
302
303 priv->hash_regs[0] = &priv->regs->igaddr0;
304 priv->hash_regs[1] = &priv->regs->igaddr1;
305 priv->hash_regs[2] = &priv->regs->igaddr2;
306 priv->hash_regs[3] = &priv->regs->igaddr3;
307 priv->hash_regs[4] = &priv->regs->igaddr4;
308 priv->hash_regs[5] = &priv->regs->igaddr5;
309 priv->hash_regs[6] = &priv->regs->igaddr6;
310 priv->hash_regs[7] = &priv->regs->igaddr7;
311 priv->hash_regs[8] = &priv->regs->gaddr0;
312 priv->hash_regs[9] = &priv->regs->gaddr1;
313 priv->hash_regs[10] = &priv->regs->gaddr2;
314 priv->hash_regs[11] = &priv->regs->gaddr3;
315 priv->hash_regs[12] = &priv->regs->gaddr4;
316 priv->hash_regs[13] = &priv->regs->gaddr5;
317 priv->hash_regs[14] = &priv->regs->gaddr6;
318 priv->hash_regs[15] = &priv->regs->gaddr7;
319
320 } else {
321 priv->extended_hash = 0;
322 priv->hash_width = 8;
323
324 priv->hash_regs[0] = &priv->regs->gaddr0;
325 priv->hash_regs[1] = &priv->regs->gaddr1;
326 priv->hash_regs[2] = &priv->regs->gaddr2;
327 priv->hash_regs[3] = &priv->regs->gaddr3;
328 priv->hash_regs[4] = &priv->regs->gaddr4;
329 priv->hash_regs[5] = &priv->regs->gaddr5;
330 priv->hash_regs[6] = &priv->regs->gaddr6;
331 priv->hash_regs[7] = &priv->regs->gaddr7;
332 }
333
334 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_PADDING)
335 priv->padding = DEFAULT_PADDING;
336 else
337 priv->padding = 0;
338
339 dev->hard_header_len += priv->padding;
340
341 if (dev->features & NETIF_F_IP_CSUM)
342 dev->hard_header_len += GMAC_FCB_LEN;
277 343
278 priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE; 344 priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE;
279#ifdef CONFIG_GFAR_BUFSTASH 345#ifdef CONFIG_GFAR_BUFSTASH
@@ -289,6 +355,9 @@ static int gfar_probe(struct device *device)
289 priv->rxcount = DEFAULT_RXCOUNT; 355 priv->rxcount = DEFAULT_RXCOUNT;
290 priv->rxtime = DEFAULT_RXTIME; 356 priv->rxtime = DEFAULT_RXTIME;
291 357
358 /* Enable most messages by default */
359 priv->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
360
292 err = register_netdev(dev); 361 err = register_netdev(dev);
293 362
294 if (err) { 363 if (err) {
@@ -360,8 +429,9 @@ static int init_phy(struct net_device *dev)
360 GFP_KERNEL); 429 GFP_KERNEL);
361 430
362 if(NULL == mii_info) { 431 if(NULL == mii_info) {
363 printk(KERN_ERR "%s: Could not allocate mii_info\n", 432 if (netif_msg_ifup(priv))
364 dev->name); 433 printk(KERN_ERR "%s: Could not allocate mii_info\n",
434 dev->name);
365 return -ENOMEM; 435 return -ENOMEM;
366 } 436 }
367 437
@@ -410,7 +480,8 @@ static int init_phy(struct net_device *dev)
410 curphy = get_phy_info(priv->mii_info); 480 curphy = get_phy_info(priv->mii_info);
411 481
412 if (curphy == NULL) { 482 if (curphy == NULL) {
413 printk(KERN_ERR "%s: No PHY found\n", dev->name); 483 if (netif_msg_ifup(priv))
484 printk(KERN_ERR "%s: No PHY found\n", dev->name);
414 err = -1; 485 err = -1;
415 goto no_phy; 486 goto no_phy;
416 } 487 }
@@ -421,7 +492,7 @@ static int init_phy(struct net_device *dev)
421 if(curphy->init) { 492 if(curphy->init) {
422 err = curphy->init(priv->mii_info); 493 err = curphy->init(priv->mii_info);
423 494
424 if (err) 495 if (err)
425 goto phy_init_fail; 496 goto phy_init_fail;
426 } 497 }
427 498
@@ -446,14 +517,14 @@ static void init_registers(struct net_device *dev)
446 gfar_write(&priv->regs->imask, IMASK_INIT_CLEAR); 517 gfar_write(&priv->regs->imask, IMASK_INIT_CLEAR);
447 518
448 /* Init hash registers to zero */ 519 /* Init hash registers to zero */
449 gfar_write(&priv->regs->iaddr0, 0); 520 gfar_write(&priv->regs->igaddr0, 0);
450 gfar_write(&priv->regs->iaddr1, 0); 521 gfar_write(&priv->regs->igaddr1, 0);
451 gfar_write(&priv->regs->iaddr2, 0); 522 gfar_write(&priv->regs->igaddr2, 0);
452 gfar_write(&priv->regs->iaddr3, 0); 523 gfar_write(&priv->regs->igaddr3, 0);
453 gfar_write(&priv->regs->iaddr4, 0); 524 gfar_write(&priv->regs->igaddr4, 0);
454 gfar_write(&priv->regs->iaddr5, 0); 525 gfar_write(&priv->regs->igaddr5, 0);
455 gfar_write(&priv->regs->iaddr6, 0); 526 gfar_write(&priv->regs->igaddr6, 0);
456 gfar_write(&priv->regs->iaddr7, 0); 527 gfar_write(&priv->regs->igaddr7, 0);
457 528
458 gfar_write(&priv->regs->gaddr0, 0); 529 gfar_write(&priv->regs->gaddr0, 0);
459 gfar_write(&priv->regs->gaddr1, 0); 530 gfar_write(&priv->regs->gaddr1, 0);
@@ -464,9 +535,6 @@ static void init_registers(struct net_device *dev)
464 gfar_write(&priv->regs->gaddr6, 0); 535 gfar_write(&priv->regs->gaddr6, 0);
465 gfar_write(&priv->regs->gaddr7, 0); 536 gfar_write(&priv->regs->gaddr7, 0);
466 537
467 /* Zero out rctrl */
468 gfar_write(&priv->regs->rctrl, 0x00000000);
469
470 /* Zero out the rmon mib registers if it has them */ 538 /* Zero out the rmon mib registers if it has them */
471 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) { 539 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
472 memset((void *) &(priv->regs->rmon), 0, 540 memset((void *) &(priv->regs->rmon), 0,
@@ -497,20 +565,14 @@ static void init_registers(struct net_device *dev)
497 gfar_write(&priv->regs->tbipa, TBIPA_VALUE); 565 gfar_write(&priv->regs->tbipa, TBIPA_VALUE);
498} 566}
499 567
500void stop_gfar(struct net_device *dev) 568
569/* Halt the receive and transmit queues */
570void gfar_halt(struct net_device *dev)
501{ 571{
502 struct gfar_private *priv = netdev_priv(dev); 572 struct gfar_private *priv = netdev_priv(dev);
503 struct gfar *regs = priv->regs; 573 struct gfar *regs = priv->regs;
504 unsigned long flags;
505 u32 tempval; 574 u32 tempval;
506 575
507 /* Lock it down */
508 spin_lock_irqsave(&priv->lock, flags);
509
510 /* Tell the kernel the link is down */
511 priv->mii_info->link = 0;
512 adjust_link(dev);
513
514 /* Mask all interrupts */ 576 /* Mask all interrupts */
515 gfar_write(&regs->imask, IMASK_INIT_CLEAR); 577 gfar_write(&regs->imask, IMASK_INIT_CLEAR);
516 578
@@ -533,13 +595,29 @@ void stop_gfar(struct net_device *dev)
533 tempval = gfar_read(&regs->maccfg1); 595 tempval = gfar_read(&regs->maccfg1);
534 tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN); 596 tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN);
535 gfar_write(&regs->maccfg1, tempval); 597 gfar_write(&regs->maccfg1, tempval);
598}
599
600void stop_gfar(struct net_device *dev)
601{
602 struct gfar_private *priv = netdev_priv(dev);
603 struct gfar *regs = priv->regs;
604 unsigned long flags;
605
606 /* Lock it down */
607 spin_lock_irqsave(&priv->lock, flags);
608
609 /* Tell the kernel the link is down */
610 priv->mii_info->link = 0;
611 adjust_link(dev);
612
613 gfar_halt(dev);
536 614
537 if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) { 615 if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) {
538 /* Clear any pending interrupts */ 616 /* Clear any pending interrupts */
539 mii_clear_phy_interrupt(priv->mii_info); 617 mii_clear_phy_interrupt(priv->mii_info);
540 618
541 /* Disable PHY Interrupts */ 619 /* Disable PHY Interrupts */
542 mii_configure_phy_interrupt(priv->mii_info, 620 mii_configure_phy_interrupt(priv->mii_info,
543 MII_INTERRUPT_DISABLED); 621 MII_INTERRUPT_DISABLED);
544 } 622 }
545 623
@@ -566,7 +644,7 @@ void stop_gfar(struct net_device *dev)
566 sizeof(struct txbd8)*priv->tx_ring_size 644 sizeof(struct txbd8)*priv->tx_ring_size
567 + sizeof(struct rxbd8)*priv->rx_ring_size, 645 + sizeof(struct rxbd8)*priv->rx_ring_size,
568 priv->tx_bd_base, 646 priv->tx_bd_base,
569 gfar_read(&regs->tbase)); 647 gfar_read(&regs->tbase0));
570} 648}
571 649
572/* If there are any tx skbs or rx skbs still around, free them. 650/* If there are any tx skbs or rx skbs still around, free them.
@@ -620,6 +698,34 @@ void free_skb_resources(struct gfar_private *priv)
620 } 698 }
621} 699}
622 700
701void gfar_start(struct net_device *dev)
702{
703 struct gfar_private *priv = netdev_priv(dev);
704 struct gfar *regs = priv->regs;
705 u32 tempval;
706
707 /* Enable Rx and Tx in MACCFG1 */
708 tempval = gfar_read(&regs->maccfg1);
709 tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
710 gfar_write(&regs->maccfg1, tempval);
711
712 /* Initialize DMACTRL to have WWR and WOP */
713 tempval = gfar_read(&priv->regs->dmactrl);
714 tempval |= DMACTRL_INIT_SETTINGS;
715 gfar_write(&priv->regs->dmactrl, tempval);
716
717 /* Clear THLT, so that the DMA starts polling now */
718 gfar_write(&regs->tstat, TSTAT_CLEAR_THALT);
719
720 /* Make sure we aren't stopped */
721 tempval = gfar_read(&priv->regs->dmactrl);
722 tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
723 gfar_write(&priv->regs->dmactrl, tempval);
724
725 /* Unmask the interrupts we look for */
726 gfar_write(&regs->imask, IMASK_DEFAULT);
727}
728
623/* Bring the controller up and running */ 729/* Bring the controller up and running */
624int startup_gfar(struct net_device *dev) 730int startup_gfar(struct net_device *dev)
625{ 731{
@@ -630,33 +736,34 @@ int startup_gfar(struct net_device *dev)
630 int i; 736 int i;
631 struct gfar_private *priv = netdev_priv(dev); 737 struct gfar_private *priv = netdev_priv(dev);
632 struct gfar *regs = priv->regs; 738 struct gfar *regs = priv->regs;
633 u32 tempval;
634 int err = 0; 739 int err = 0;
740 u32 rctrl = 0;
635 741
636 gfar_write(&regs->imask, IMASK_INIT_CLEAR); 742 gfar_write(&regs->imask, IMASK_INIT_CLEAR);
637 743
638 /* Allocate memory for the buffer descriptors */ 744 /* Allocate memory for the buffer descriptors */
639 vaddr = (unsigned long) dma_alloc_coherent(NULL, 745 vaddr = (unsigned long) dma_alloc_coherent(NULL,
640 sizeof (struct txbd8) * priv->tx_ring_size + 746 sizeof (struct txbd8) * priv->tx_ring_size +
641 sizeof (struct rxbd8) * priv->rx_ring_size, 747 sizeof (struct rxbd8) * priv->rx_ring_size,
642 &addr, GFP_KERNEL); 748 &addr, GFP_KERNEL);
643 749
644 if (vaddr == 0) { 750 if (vaddr == 0) {
645 printk(KERN_ERR "%s: Could not allocate buffer descriptors!\n", 751 if (netif_msg_ifup(priv))
646 dev->name); 752 printk(KERN_ERR "%s: Could not allocate buffer descriptors!\n",
753 dev->name);
647 return -ENOMEM; 754 return -ENOMEM;
648 } 755 }
649 756
650 priv->tx_bd_base = (struct txbd8 *) vaddr; 757 priv->tx_bd_base = (struct txbd8 *) vaddr;
651 758
652 /* enet DMA only understands physical addresses */ 759 /* enet DMA only understands physical addresses */
653 gfar_write(&regs->tbase, addr); 760 gfar_write(&regs->tbase0, addr);
654 761
655 /* Start the rx descriptor ring where the tx ring leaves off */ 762 /* Start the rx descriptor ring where the tx ring leaves off */
656 addr = addr + sizeof (struct txbd8) * priv->tx_ring_size; 763 addr = addr + sizeof (struct txbd8) * priv->tx_ring_size;
657 vaddr = vaddr + sizeof (struct txbd8) * priv->tx_ring_size; 764 vaddr = vaddr + sizeof (struct txbd8) * priv->tx_ring_size;
658 priv->rx_bd_base = (struct rxbd8 *) vaddr; 765 priv->rx_bd_base = (struct rxbd8 *) vaddr;
659 gfar_write(&regs->rbase, addr); 766 gfar_write(&regs->rbase0, addr);
660 767
661 /* Setup the skbuff rings */ 768 /* Setup the skbuff rings */
662 priv->tx_skbuff = 769 priv->tx_skbuff =
@@ -664,8 +771,9 @@ int startup_gfar(struct net_device *dev)
664 priv->tx_ring_size, GFP_KERNEL); 771 priv->tx_ring_size, GFP_KERNEL);
665 772
666 if (priv->tx_skbuff == NULL) { 773 if (priv->tx_skbuff == NULL) {
667 printk(KERN_ERR "%s: Could not allocate tx_skbuff\n", 774 if (netif_msg_ifup(priv))
668 dev->name); 775 printk(KERN_ERR "%s: Could not allocate tx_skbuff\n",
776 dev->name);
669 err = -ENOMEM; 777 err = -ENOMEM;
670 goto tx_skb_fail; 778 goto tx_skb_fail;
671 } 779 }
@@ -678,8 +786,9 @@ int startup_gfar(struct net_device *dev)
678 priv->rx_ring_size, GFP_KERNEL); 786 priv->rx_ring_size, GFP_KERNEL);
679 787
680 if (priv->rx_skbuff == NULL) { 788 if (priv->rx_skbuff == NULL) {
681 printk(KERN_ERR "%s: Could not allocate rx_skbuff\n", 789 if (netif_msg_ifup(priv))
682 dev->name); 790 printk(KERN_ERR "%s: Could not allocate rx_skbuff\n",
791 dev->name);
683 err = -ENOMEM; 792 err = -ENOMEM;
684 goto rx_skb_fail; 793 goto rx_skb_fail;
685 } 794 }
@@ -726,12 +835,13 @@ int startup_gfar(struct net_device *dev)
726 /* If the device has multiple interrupts, register for 835 /* If the device has multiple interrupts, register for
727 * them. Otherwise, only register for the one */ 836 * them. Otherwise, only register for the one */
728 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) { 837 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
729 /* Install our interrupt handlers for Error, 838 /* Install our interrupt handlers for Error,
730 * Transmit, and Receive */ 839 * Transmit, and Receive */
731 if (request_irq(priv->interruptError, gfar_error, 840 if (request_irq(priv->interruptError, gfar_error,
732 0, "enet_error", dev) < 0) { 841 0, "enet_error", dev) < 0) {
733 printk(KERN_ERR "%s: Can't get IRQ %d\n", 842 if (netif_msg_intr(priv))
734 dev->name, priv->interruptError); 843 printk(KERN_ERR "%s: Can't get IRQ %d\n",
844 dev->name, priv->interruptError);
735 845
736 err = -1; 846 err = -1;
737 goto err_irq_fail; 847 goto err_irq_fail;
@@ -739,8 +849,9 @@ int startup_gfar(struct net_device *dev)
739 849
740 if (request_irq(priv->interruptTransmit, gfar_transmit, 850 if (request_irq(priv->interruptTransmit, gfar_transmit,
741 0, "enet_tx", dev) < 0) { 851 0, "enet_tx", dev) < 0) {
742 printk(KERN_ERR "%s: Can't get IRQ %d\n", 852 if (netif_msg_intr(priv))
743 dev->name, priv->interruptTransmit); 853 printk(KERN_ERR "%s: Can't get IRQ %d\n",
854 dev->name, priv->interruptTransmit);
744 855
745 err = -1; 856 err = -1;
746 857
@@ -749,8 +860,9 @@ int startup_gfar(struct net_device *dev)
749 860
750 if (request_irq(priv->interruptReceive, gfar_receive, 861 if (request_irq(priv->interruptReceive, gfar_receive,
751 0, "enet_rx", dev) < 0) { 862 0, "enet_rx", dev) < 0) {
752 printk(KERN_ERR "%s: Can't get IRQ %d (receive0)\n", 863 if (netif_msg_intr(priv))
753 dev->name, priv->interruptReceive); 864 printk(KERN_ERR "%s: Can't get IRQ %d (receive0)\n",
865 dev->name, priv->interruptReceive);
754 866
755 err = -1; 867 err = -1;
756 goto rx_irq_fail; 868 goto rx_irq_fail;
@@ -758,8 +870,9 @@ int startup_gfar(struct net_device *dev)
758 } else { 870 } else {
759 if (request_irq(priv->interruptTransmit, gfar_interrupt, 871 if (request_irq(priv->interruptTransmit, gfar_interrupt,
760 0, "gfar_interrupt", dev) < 0) { 872 0, "gfar_interrupt", dev) < 0) {
761 printk(KERN_ERR "%s: Can't get IRQ %d\n", 873 if (netif_msg_intr(priv))
762 dev->name, priv->interruptError); 874 printk(KERN_ERR "%s: Can't get IRQ %d\n",
875 dev->name, priv->interruptError);
763 876
764 err = -1; 877 err = -1;
765 goto err_irq_fail; 878 goto err_irq_fail;
@@ -787,28 +900,22 @@ int startup_gfar(struct net_device *dev)
787 else 900 else
788 gfar_write(&regs->rxic, 0); 901 gfar_write(&regs->rxic, 0);
789 902
790 init_waitqueue_head(&priv->rxcleanupq); 903 if (priv->rx_csum_enable)
904 rctrl |= RCTRL_CHECKSUMMING;
791 905
792 /* Enable Rx and Tx in MACCFG1 */ 906 if (priv->extended_hash)
793 tempval = gfar_read(&regs->maccfg1); 907 rctrl |= RCTRL_EXTHASH;
794 tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
795 gfar_write(&regs->maccfg1, tempval);
796 908
797 /* Initialize DMACTRL to have WWR and WOP */ 909 if (priv->vlan_enable)
798 tempval = gfar_read(&priv->regs->dmactrl); 910 rctrl |= RCTRL_VLAN;
799 tempval |= DMACTRL_INIT_SETTINGS;
800 gfar_write(&priv->regs->dmactrl, tempval);
801 911
802 /* Clear THLT, so that the DMA starts polling now */ 912 /* Init rctrl based on our settings */
803 gfar_write(&regs->tstat, TSTAT_CLEAR_THALT); 913 gfar_write(&priv->regs->rctrl, rctrl);
804 914
805 /* Make sure we aren't stopped */ 915 if (dev->features & NETIF_F_IP_CSUM)
806 tempval = gfar_read(&priv->regs->dmactrl); 916 gfar_write(&priv->regs->tctrl, TCTRL_INIT_CSUM);
807 tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
808 gfar_write(&priv->regs->dmactrl, tempval);
809 917
810 /* Unmask the interrupts we look for */ 918 gfar_start(dev);
811 gfar_write(&regs->imask, IMASK_DEFAULT);
812 919
813 return 0; 920 return 0;
814 921
@@ -824,7 +931,7 @@ tx_skb_fail:
824 sizeof(struct txbd8)*priv->tx_ring_size 931 sizeof(struct txbd8)*priv->tx_ring_size
825 + sizeof(struct rxbd8)*priv->rx_ring_size, 932 + sizeof(struct rxbd8)*priv->rx_ring_size,
826 priv->tx_bd_base, 933 priv->tx_bd_base,
827 gfar_read(&regs->tbase)); 934 gfar_read(&regs->tbase0));
828 935
829 if (priv->mii_info->phyinfo->close) 936 if (priv->mii_info->phyinfo->close)
830 priv->mii_info->phyinfo->close(priv->mii_info); 937 priv->mii_info->phyinfo->close(priv->mii_info);
@@ -857,11 +964,62 @@ static int gfar_enet_open(struct net_device *dev)
857 return err; 964 return err;
858} 965}
859 966
967static struct txfcb *gfar_add_fcb(struct sk_buff *skb, struct txbd8 *bdp)
968{
969 struct txfcb *fcb = (struct txfcb *)skb_push (skb, GMAC_FCB_LEN);
970
971 memset(fcb, 0, GMAC_FCB_LEN);
972
973 /* Flag the bd so the controller looks for the FCB */
974 bdp->status |= TXBD_TOE;
975
976 return fcb;
977}
978
979static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb)
980{
981 int len;
982
983 /* If we're here, it's a IP packet with a TCP or UDP
984 * payload. We set it to checksum, using a pseudo-header
985 * we provide
986 */
987 fcb->ip = 1;
988 fcb->tup = 1;
989 fcb->ctu = 1;
990 fcb->nph = 1;
991
992 /* Notify the controller what the protocol is */
993 if (skb->nh.iph->protocol == IPPROTO_UDP)
994 fcb->udp = 1;
995
996 /* l3os is the distance between the start of the
997 * frame (skb->data) and the start of the IP hdr.
998 * l4os is the distance between the start of the
999 * l3 hdr and the l4 hdr */
1000 fcb->l3os = (u16)(skb->nh.raw - skb->data - GMAC_FCB_LEN);
1001 fcb->l4os = (u16)(skb->h.raw - skb->nh.raw);
1002
1003 len = skb->nh.iph->tot_len - fcb->l4os;
1004
1005 /* Provide the pseudoheader csum */
1006 fcb->phcs = ~csum_tcpudp_magic(skb->nh.iph->saddr,
1007 skb->nh.iph->daddr, len,
1008 skb->nh.iph->protocol, 0);
1009}
1010
1011void gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb)
1012{
1013 fcb->vln = 1;
1014 fcb->vlctl = vlan_tx_tag_get(skb);
1015}
1016
860/* This is called by the kernel when a frame is ready for transmission. */ 1017/* This is called by the kernel when a frame is ready for transmission. */
861/* It is pointed to by the dev->hard_start_xmit function pointer */ 1018/* It is pointed to by the dev->hard_start_xmit function pointer */
862static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev) 1019static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
863{ 1020{
864 struct gfar_private *priv = netdev_priv(dev); 1021 struct gfar_private *priv = netdev_priv(dev);
1022 struct txfcb *fcb = NULL;
865 struct txbd8 *txbdp; 1023 struct txbd8 *txbdp;
866 1024
867 /* Update transmit stats */ 1025 /* Update transmit stats */
@@ -876,9 +1034,24 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
876 /* Clear all but the WRAP status flags */ 1034 /* Clear all but the WRAP status flags */
877 txbdp->status &= TXBD_WRAP; 1035 txbdp->status &= TXBD_WRAP;
878 1036
1037 /* Set up checksumming */
1038 if ((dev->features & NETIF_F_IP_CSUM)
1039 && (CHECKSUM_HW == skb->ip_summed)) {
1040 fcb = gfar_add_fcb(skb, txbdp);
1041 gfar_tx_checksum(skb, fcb);
1042 }
1043
1044 if (priv->vlan_enable &&
1045 unlikely(priv->vlgrp && vlan_tx_tag_present(skb))) {
1046 if (NULL == fcb)
1047 fcb = gfar_add_fcb(skb, txbdp);
1048
1049 gfar_tx_vlan(skb, fcb);
1050 }
1051
879 /* Set buffer length and pointer */ 1052 /* Set buffer length and pointer */
880 txbdp->length = skb->len; 1053 txbdp->length = skb->len;
881 txbdp->bufPtr = dma_map_single(NULL, skb->data, 1054 txbdp->bufPtr = dma_map_single(NULL, skb->data,
882 skb->len, DMA_TO_DEVICE); 1055 skb->len, DMA_TO_DEVICE);
883 1056
884 /* Save the skb pointer so we can free it later */ 1057 /* Save the skb pointer so we can free it later */
@@ -972,15 +1145,78 @@ int gfar_set_mac_address(struct net_device *dev)
972} 1145}
973 1146
974 1147
1148/* Enables and disables VLAN insertion/extraction */
1149static void gfar_vlan_rx_register(struct net_device *dev,
1150 struct vlan_group *grp)
1151{
1152 struct gfar_private *priv = netdev_priv(dev);
1153 unsigned long flags;
1154 u32 tempval;
1155
1156 spin_lock_irqsave(&priv->lock, flags);
1157
1158 priv->vlgrp = grp;
1159
1160 if (grp) {
1161 /* Enable VLAN tag insertion */
1162 tempval = gfar_read(&priv->regs->tctrl);
1163 tempval |= TCTRL_VLINS;
1164
1165 gfar_write(&priv->regs->tctrl, tempval);
1166
1167 /* Enable VLAN tag extraction */
1168 tempval = gfar_read(&priv->regs->rctrl);
1169 tempval |= RCTRL_VLEX;
1170 gfar_write(&priv->regs->rctrl, tempval);
1171 } else {
1172 /* Disable VLAN tag insertion */
1173 tempval = gfar_read(&priv->regs->tctrl);
1174 tempval &= ~TCTRL_VLINS;
1175 gfar_write(&priv->regs->tctrl, tempval);
1176
1177 /* Disable VLAN tag extraction */
1178 tempval = gfar_read(&priv->regs->rctrl);
1179 tempval &= ~RCTRL_VLEX;
1180 gfar_write(&priv->regs->rctrl, tempval);
1181 }
1182
1183 spin_unlock_irqrestore(&priv->lock, flags);
1184}
1185
1186
1187static void gfar_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
1188{
1189 struct gfar_private *priv = netdev_priv(dev);
1190 unsigned long flags;
1191
1192 spin_lock_irqsave(&priv->lock, flags);
1193
1194 if (priv->vlgrp)
1195 priv->vlgrp->vlan_devices[vid] = NULL;
1196
1197 spin_unlock_irqrestore(&priv->lock, flags);
1198}
1199
1200
975static int gfar_change_mtu(struct net_device *dev, int new_mtu) 1201static int gfar_change_mtu(struct net_device *dev, int new_mtu)
976{ 1202{
977 int tempsize, tempval; 1203 int tempsize, tempval;
978 struct gfar_private *priv = netdev_priv(dev); 1204 struct gfar_private *priv = netdev_priv(dev);
979 int oldsize = priv->rx_buffer_size; 1205 int oldsize = priv->rx_buffer_size;
980 int frame_size = new_mtu + 18; 1206 int frame_size = new_mtu + ETH_HLEN;
1207
1208 if (priv->vlan_enable)
1209 frame_size += VLAN_ETH_HLEN;
1210
1211 if (gfar_uses_fcb(priv))
1212 frame_size += GMAC_FCB_LEN;
1213
1214 frame_size += priv->padding;
981 1215
982 if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) { 1216 if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) {
983 printk(KERN_ERR "%s: Invalid MTU setting\n", dev->name); 1217 if (netif_msg_drv(priv))
1218 printk(KERN_ERR "%s: Invalid MTU setting\n",
1219 dev->name);
984 return -EINVAL; 1220 return -EINVAL;
985 } 1221 }
986 1222
@@ -1120,7 +1356,7 @@ struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp)
1120 skb->dev = dev; 1356 skb->dev = dev;
1121 1357
1122 bdp->bufPtr = dma_map_single(NULL, skb->data, 1358 bdp->bufPtr = dma_map_single(NULL, skb->data,
1123 priv->rx_buffer_size + RXBUF_ALIGNMENT, 1359 priv->rx_buffer_size + RXBUF_ALIGNMENT,
1124 DMA_FROM_DEVICE); 1360 DMA_FROM_DEVICE);
1125 1361
1126 bdp->length = 0; 1362 bdp->length = 0;
@@ -1190,11 +1426,10 @@ irqreturn_t gfar_receive(int irq, void *dev_id, struct pt_regs *regs)
1190 1426
1191 __netif_rx_schedule(dev); 1427 __netif_rx_schedule(dev);
1192 } else { 1428 } else {
1193#ifdef VERBOSE_GFAR_ERRORS 1429 if (netif_msg_rx_err(priv))
1194 printk(KERN_DEBUG "%s: receive called twice (%x)[%x]\n", 1430 printk(KERN_DEBUG "%s: receive called twice (%x)[%x]\n",
1195 dev->name, gfar_read(&priv->regs->ievent), 1431 dev->name, gfar_read(&priv->regs->ievent),
1196 gfar_read(&priv->regs->imask)); 1432 gfar_read(&priv->regs->imask));
1197#endif
1198 } 1433 }
1199#else 1434#else
1200 1435
@@ -1209,15 +1444,43 @@ irqreturn_t gfar_receive(int irq, void *dev_id, struct pt_regs *regs)
1209 else 1444 else
1210 gfar_write(&priv->regs->rxic, 0); 1445 gfar_write(&priv->regs->rxic, 0);
1211 1446
1212 /* Just in case we need to wake the ring param changer */
1213 priv->rxclean = 1;
1214
1215 spin_unlock(&priv->lock); 1447 spin_unlock(&priv->lock);
1216#endif 1448#endif
1217 1449
1218 return IRQ_HANDLED; 1450 return IRQ_HANDLED;
1219} 1451}
1220 1452
1453static inline int gfar_rx_vlan(struct sk_buff *skb,
1454 struct vlan_group *vlgrp, unsigned short vlctl)
1455{
1456#ifdef CONFIG_GFAR_NAPI
1457 return vlan_hwaccel_receive_skb(skb, vlgrp, vlctl);
1458#else
1459 return vlan_hwaccel_rx(skb, vlgrp, vlctl);
1460#endif
1461}
1462
1463static inline void gfar_rx_checksum(struct sk_buff *skb, struct rxfcb *fcb)
1464{
1465 /* If valid headers were found, and valid sums
1466 * were verified, then we tell the kernel that no
1467 * checksumming is necessary. Otherwise, it is */
1468 if (fcb->cip && !fcb->eip && fcb->ctu && !fcb->etu)
1469 skb->ip_summed = CHECKSUM_UNNECESSARY;
1470 else
1471 skb->ip_summed = CHECKSUM_NONE;
1472}
1473
1474
1475static inline struct rxfcb *gfar_get_fcb(struct sk_buff *skb)
1476{
1477 struct rxfcb *fcb = (struct rxfcb *)skb->data;
1478
1479 /* Remove the FCB from the skb */
1480 skb_pull(skb, GMAC_FCB_LEN);
1481
1482 return fcb;
1483}
1221 1484
1222/* gfar_process_frame() -- handle one incoming packet if skb 1485/* gfar_process_frame() -- handle one incoming packet if skb
1223 * isn't NULL. */ 1486 * isn't NULL. */
@@ -1225,35 +1488,51 @@ static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
1225 int length) 1488 int length)
1226{ 1489{
1227 struct gfar_private *priv = netdev_priv(dev); 1490 struct gfar_private *priv = netdev_priv(dev);
1491 struct rxfcb *fcb = NULL;
1228 1492
1229 if (skb == NULL) { 1493 if (skb == NULL) {
1230#ifdef BRIEF_GFAR_ERRORS 1494 if (netif_msg_rx_err(priv))
1231 printk(KERN_WARNING "%s: Missing skb!!.\n", 1495 printk(KERN_WARNING "%s: Missing skb!!.\n", dev->name);
1232 dev->name);
1233#endif
1234 priv->stats.rx_dropped++; 1496 priv->stats.rx_dropped++;
1235 priv->extra_stats.rx_skbmissing++; 1497 priv->extra_stats.rx_skbmissing++;
1236 } else { 1498 } else {
1499 int ret;
1500
1237 /* Prep the skb for the packet */ 1501 /* Prep the skb for the packet */
1238 skb_put(skb, length); 1502 skb_put(skb, length);
1239 1503
1504 /* Grab the FCB if there is one */
1505 if (gfar_uses_fcb(priv))
1506 fcb = gfar_get_fcb(skb);
1507
1508 /* Remove the padded bytes, if there are any */
1509 if (priv->padding)
1510 skb_pull(skb, priv->padding);
1511
1512 if (priv->rx_csum_enable)
1513 gfar_rx_checksum(skb, fcb);
1514
1240 /* Tell the skb what kind of packet this is */ 1515 /* Tell the skb what kind of packet this is */
1241 skb->protocol = eth_type_trans(skb, dev); 1516 skb->protocol = eth_type_trans(skb, dev);
1242 1517
1243 /* Send the packet up the stack */ 1518 /* Send the packet up the stack */
1244 if (RECEIVE(skb) == NET_RX_DROP) { 1519 if (unlikely(priv->vlgrp && fcb->vln))
1520 ret = gfar_rx_vlan(skb, priv->vlgrp, fcb->vlctl);
1521 else
1522 ret = RECEIVE(skb);
1523
1524 if (NET_RX_DROP == ret)
1245 priv->extra_stats.kernel_dropped++; 1525 priv->extra_stats.kernel_dropped++;
1246 }
1247 } 1526 }
1248 1527
1249 return 0; 1528 return 0;
1250} 1529}
1251 1530
1252/* gfar_clean_rx_ring() -- Processes each frame in the rx ring 1531/* gfar_clean_rx_ring() -- Processes each frame in the rx ring
1253 * until the budget/quota has been reached. Returns the number 1532 * until the budget/quota has been reached. Returns the number
1254 * of frames handled 1533 * of frames handled
1255 */ 1534 */
1256static int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit) 1535int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
1257{ 1536{
1258 struct rxbd8 *bdp; 1537 struct rxbd8 *bdp;
1259 struct sk_buff *skb; 1538 struct sk_buff *skb;
@@ -1355,9 +1634,6 @@ static int gfar_poll(struct net_device *dev, int *budget)
1355 mk_ic_value(priv->rxcount, priv->rxtime)); 1634 mk_ic_value(priv->rxcount, priv->rxtime));
1356 else 1635 else
1357 gfar_write(&priv->regs->rxic, 0); 1636 gfar_write(&priv->regs->rxic, 0);
1358
1359 /* Signal to the ring size changer that it's safe to go */
1360 priv->rxclean = 1;
1361 } 1637 }
1362 1638
1363 return (rx_work_limit < 0) ? 1 : 0; 1639 return (rx_work_limit < 0) ? 1 : 0;
@@ -1393,10 +1669,8 @@ static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1393 if (events & IEVENT_CRL) 1669 if (events & IEVENT_CRL)
1394 priv->stats.tx_aborted_errors++; 1670 priv->stats.tx_aborted_errors++;
1395 if (events & IEVENT_XFUN) { 1671 if (events & IEVENT_XFUN) {
1396#ifdef VERBOSE_GFAR_ERRORS 1672 if (netif_msg_tx_err(priv))
1397 printk(KERN_WARNING "%s: tx underrun. dropped packet\n", 1673 printk(KERN_WARNING "%s: tx underrun. dropped packet\n", dev->name);
1398 dev->name);
1399#endif
1400 priv->stats.tx_dropped++; 1674 priv->stats.tx_dropped++;
1401 priv->extra_stats.tx_underrun++; 1675 priv->extra_stats.tx_underrun++;
1402 1676
@@ -1415,36 +1689,30 @@ static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1415 gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT); 1689 gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
1416#endif 1690#endif
1417 1691
1418#ifdef VERBOSE_GFAR_ERRORS 1692 if (netif_msg_rx_err(priv))
1419 printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n", dev->name, 1693 printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n",
1420 gfar_read(&priv->regs->rstat)); 1694 dev->name,
1421#endif 1695 gfar_read(&priv->regs->rstat));
1422 } 1696 }
1423 if (events & IEVENT_BABR) { 1697 if (events & IEVENT_BABR) {
1424 priv->stats.rx_errors++; 1698 priv->stats.rx_errors++;
1425 priv->extra_stats.rx_babr++; 1699 priv->extra_stats.rx_babr++;
1426 1700
1427#ifdef VERBOSE_GFAR_ERRORS 1701 if (netif_msg_rx_err(priv))
1428 printk(KERN_DEBUG "%s: babbling error\n", dev->name); 1702 printk(KERN_DEBUG "%s: babbling error\n", dev->name);
1429#endif
1430 } 1703 }
1431 if (events & IEVENT_EBERR) { 1704 if (events & IEVENT_EBERR) {
1432 priv->extra_stats.eberr++; 1705 priv->extra_stats.eberr++;
1433#ifdef VERBOSE_GFAR_ERRORS 1706 if (netif_msg_rx_err(priv))
1434 printk(KERN_DEBUG "%s: EBERR\n", dev->name); 1707 printk(KERN_DEBUG "%s: EBERR\n", dev->name);
1435#endif
1436 }
1437 if (events & IEVENT_RXC) {
1438#ifdef VERBOSE_GFAR_ERRORS
1439 printk(KERN_DEBUG "%s: control frame\n", dev->name);
1440#endif
1441 } 1708 }
1709 if ((events & IEVENT_RXC) && (netif_msg_rx_err(priv)))
1710 printk(KERN_DEBUG "%s: control frame\n", dev->name);
1442 1711
1443 if (events & IEVENT_BABT) { 1712 if (events & IEVENT_BABT) {
1444 priv->extra_stats.tx_babt++; 1713 priv->extra_stats.tx_babt++;
1445#ifdef VERBOSE_GFAR_ERRORS 1714 if (netif_msg_rx_err(priv))
1446 printk(KERN_DEBUG "%s: babt error\n", dev->name); 1715 printk(KERN_DEBUG "%s: babt error\n", dev->name);
1447#endif
1448 } 1716 }
1449 1717
1450 return IRQ_HANDLED; 1718 return IRQ_HANDLED;
@@ -1510,7 +1778,7 @@ static void gfar_phy_timer(unsigned long data)
1510 * If, after GFAR_AN_TIMEOUT seconds, it has not 1778 * If, after GFAR_AN_TIMEOUT seconds, it has not
1511 * finished, we switch to forced. 1779 * finished, we switch to forced.
1512 * Either way, once the process has completed, we either 1780 * Either way, once the process has completed, we either
1513 * request the interrupt, or switch the timer over to 1781 * request the interrupt, or switch the timer over to
1514 * using gfar_phy_timer to check status */ 1782 * using gfar_phy_timer to check status */
1515static void gfar_phy_startup_timer(unsigned long data) 1783static void gfar_phy_startup_timer(unsigned long data)
1516{ 1784{
@@ -1535,8 +1803,9 @@ static void gfar_phy_startup_timer(unsigned long data)
1535 1803
1536 /* Forcing failed! Give up */ 1804 /* Forcing failed! Give up */
1537 if(result) { 1805 if(result) {
1538 printk(KERN_ERR "%s: Forcing failed!\n", 1806 if (netif_msg_link(priv))
1539 mii_info->dev->name); 1807 printk(KERN_ERR "%s: Forcing failed!\n",
1808 mii_info->dev->name);
1540 return; 1809 return;
1541 } 1810 }
1542 } 1811 }
@@ -1546,16 +1815,17 @@ static void gfar_phy_startup_timer(unsigned long data)
1546 1815
1547 /* Grab the PHY interrupt, if necessary/possible */ 1816 /* Grab the PHY interrupt, if necessary/possible */
1548 if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) { 1817 if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) {
1549 if (request_irq(priv->einfo->interruptPHY, 1818 if (request_irq(priv->einfo->interruptPHY,
1550 phy_interrupt, 1819 phy_interrupt,
1551 SA_SHIRQ, 1820 SA_SHIRQ,
1552 "phy_interrupt", 1821 "phy_interrupt",
1553 mii_info->dev) < 0) { 1822 mii_info->dev) < 0) {
1554 printk(KERN_ERR "%s: Can't get IRQ %d (PHY)\n", 1823 if (netif_msg_intr(priv))
1555 mii_info->dev->name, 1824 printk(KERN_ERR "%s: Can't get IRQ %d (PHY)\n",
1825 mii_info->dev->name,
1556 priv->einfo->interruptPHY); 1826 priv->einfo->interruptPHY);
1557 } else { 1827 } else {
1558 mii_configure_phy_interrupt(priv->mii_info, 1828 mii_configure_phy_interrupt(priv->mii_info,
1559 MII_INTERRUPT_ENABLED); 1829 MII_INTERRUPT_ENABLED);
1560 return; 1830 return;
1561 } 1831 }
@@ -1592,15 +1862,17 @@ static void adjust_link(struct net_device *dev)
1592 tempval &= ~(MACCFG2_FULL_DUPLEX); 1862 tempval &= ~(MACCFG2_FULL_DUPLEX);
1593 gfar_write(&regs->maccfg2, tempval); 1863 gfar_write(&regs->maccfg2, tempval);
1594 1864
1595 printk(KERN_INFO "%s: Half Duplex\n", 1865 if (netif_msg_link(priv))
1596 dev->name); 1866 printk(KERN_INFO "%s: Half Duplex\n",
1867 dev->name);
1597 } else { 1868 } else {
1598 tempval = gfar_read(&regs->maccfg2); 1869 tempval = gfar_read(&regs->maccfg2);
1599 tempval |= MACCFG2_FULL_DUPLEX; 1870 tempval |= MACCFG2_FULL_DUPLEX;
1600 gfar_write(&regs->maccfg2, tempval); 1871 gfar_write(&regs->maccfg2, tempval);
1601 1872
1602 printk(KERN_INFO "%s: Full Duplex\n", 1873 if (netif_msg_link(priv))
1603 dev->name); 1874 printk(KERN_INFO "%s: Full Duplex\n",
1875 dev->name);
1604 } 1876 }
1605 1877
1606 priv->oldduplex = mii_info->duplex; 1878 priv->oldduplex = mii_info->duplex;
@@ -1622,27 +1894,32 @@ static void adjust_link(struct net_device *dev)
1622 gfar_write(&regs->maccfg2, tempval); 1894 gfar_write(&regs->maccfg2, tempval);
1623 break; 1895 break;
1624 default: 1896 default:
1625 printk(KERN_WARNING 1897 if (netif_msg_link(priv))
1626 "%s: Ack! Speed (%d) is not 10/100/1000!\n", 1898 printk(KERN_WARNING
1627 dev->name, mii_info->speed); 1899 "%s: Ack! Speed (%d) is not 10/100/1000!\n",
1900 dev->name, mii_info->speed);
1628 break; 1901 break;
1629 } 1902 }
1630 1903
1631 printk(KERN_INFO "%s: Speed %dBT\n", dev->name, 1904 if (netif_msg_link(priv))
1632 mii_info->speed); 1905 printk(KERN_INFO "%s: Speed %dBT\n", dev->name,
1906 mii_info->speed);
1633 1907
1634 priv->oldspeed = mii_info->speed; 1908 priv->oldspeed = mii_info->speed;
1635 } 1909 }
1636 1910
1637 if (!priv->oldlink) { 1911 if (!priv->oldlink) {
1638 printk(KERN_INFO "%s: Link is up\n", dev->name); 1912 if (netif_msg_link(priv))
1913 printk(KERN_INFO "%s: Link is up\n", dev->name);
1639 priv->oldlink = 1; 1914 priv->oldlink = 1;
1640 netif_carrier_on(dev); 1915 netif_carrier_on(dev);
1641 netif_schedule(dev); 1916 netif_schedule(dev);
1642 } 1917 }
1643 } else { 1918 } else {
1644 if (priv->oldlink) { 1919 if (priv->oldlink) {
1645 printk(KERN_INFO "%s: Link is down\n", dev->name); 1920 if (netif_msg_link(priv))
1921 printk(KERN_INFO "%s: Link is down\n",
1922 dev->name);
1646 priv->oldlink = 0; 1923 priv->oldlink = 0;
1647 priv->oldspeed = 0; 1924 priv->oldspeed = 0;
1648 priv->oldduplex = -1; 1925 priv->oldduplex = -1;
@@ -1664,8 +1941,9 @@ static void gfar_set_multi(struct net_device *dev)
1664 u32 tempval; 1941 u32 tempval;
1665 1942
1666 if(dev->flags & IFF_PROMISC) { 1943 if(dev->flags & IFF_PROMISC) {
1667 printk(KERN_INFO "%s: Entering promiscuous mode.\n", 1944 if (netif_msg_drv(priv))
1668 dev->name); 1945 printk(KERN_INFO "%s: Entering promiscuous mode.\n",
1946 dev->name);
1669 /* Set RCTRL to PROM */ 1947 /* Set RCTRL to PROM */
1670 tempval = gfar_read(&regs->rctrl); 1948 tempval = gfar_read(&regs->rctrl);
1671 tempval |= RCTRL_PROM; 1949 tempval |= RCTRL_PROM;
@@ -1679,6 +1957,14 @@ static void gfar_set_multi(struct net_device *dev)
1679 1957
1680 if(dev->flags & IFF_ALLMULTI) { 1958 if(dev->flags & IFF_ALLMULTI) {
1681 /* Set the hash to rx all multicast frames */ 1959 /* Set the hash to rx all multicast frames */
1960 gfar_write(&regs->igaddr0, 0xffffffff);
1961 gfar_write(&regs->igaddr1, 0xffffffff);
1962 gfar_write(&regs->igaddr2, 0xffffffff);
1963 gfar_write(&regs->igaddr3, 0xffffffff);
1964 gfar_write(&regs->igaddr4, 0xffffffff);
1965 gfar_write(&regs->igaddr5, 0xffffffff);
1966 gfar_write(&regs->igaddr6, 0xffffffff);
1967 gfar_write(&regs->igaddr7, 0xffffffff);
1682 gfar_write(&regs->gaddr0, 0xffffffff); 1968 gfar_write(&regs->gaddr0, 0xffffffff);
1683 gfar_write(&regs->gaddr1, 0xffffffff); 1969 gfar_write(&regs->gaddr1, 0xffffffff);
1684 gfar_write(&regs->gaddr2, 0xffffffff); 1970 gfar_write(&regs->gaddr2, 0xffffffff);
@@ -1689,6 +1975,14 @@ static void gfar_set_multi(struct net_device *dev)
1689 gfar_write(&regs->gaddr7, 0xffffffff); 1975 gfar_write(&regs->gaddr7, 0xffffffff);
1690 } else { 1976 } else {
1691 /* zero out the hash */ 1977 /* zero out the hash */
1978 gfar_write(&regs->igaddr0, 0x0);
1979 gfar_write(&regs->igaddr1, 0x0);
1980 gfar_write(&regs->igaddr2, 0x0);
1981 gfar_write(&regs->igaddr3, 0x0);
1982 gfar_write(&regs->igaddr4, 0x0);
1983 gfar_write(&regs->igaddr5, 0x0);
1984 gfar_write(&regs->igaddr6, 0x0);
1985 gfar_write(&regs->igaddr7, 0x0);
1692 gfar_write(&regs->gaddr0, 0x0); 1986 gfar_write(&regs->gaddr0, 0x0);
1693 gfar_write(&regs->gaddr1, 0x0); 1987 gfar_write(&regs->gaddr1, 0x0);
1694 gfar_write(&regs->gaddr2, 0x0); 1988 gfar_write(&regs->gaddr2, 0x0);
@@ -1727,16 +2021,15 @@ static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr)
1727{ 2021{
1728 u32 tempval; 2022 u32 tempval;
1729 struct gfar_private *priv = netdev_priv(dev); 2023 struct gfar_private *priv = netdev_priv(dev);
1730 struct gfar *regs = priv->regs;
1731 u32 *hash = &regs->gaddr0;
1732 u32 result = ether_crc(MAC_ADDR_LEN, addr); 2024 u32 result = ether_crc(MAC_ADDR_LEN, addr);
1733 u8 whichreg = ((result >> 29) & 0x7); 2025 int width = priv->hash_width;
1734 u8 whichbit = ((result >> 24) & 0x1f); 2026 u8 whichbit = (result >> (32 - width)) & 0x1f;
2027 u8 whichreg = result >> (32 - width + 5);
1735 u32 value = (1 << (31-whichbit)); 2028 u32 value = (1 << (31-whichbit));
1736 2029
1737 tempval = gfar_read(&hash[whichreg]); 2030 tempval = gfar_read(priv->hash_regs[whichreg]);
1738 tempval |= value; 2031 tempval |= value;
1739 gfar_write(&hash[whichreg], tempval); 2032 gfar_write(priv->hash_regs[whichreg], tempval);
1740 2033
1741 return; 2034 return;
1742} 2035}
@@ -1754,10 +2047,9 @@ static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs)
1754 gfar_write(&priv->regs->ievent, IEVENT_ERR_MASK); 2047 gfar_write(&priv->regs->ievent, IEVENT_ERR_MASK);
1755 2048
1756 /* Hmm... */ 2049 /* Hmm... */
1757#if defined (BRIEF_GFAR_ERRORS) || defined (VERBOSE_GFAR_ERRORS) 2050 if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv))
1758 printk(KERN_DEBUG "%s: error interrupt (ievent=0x%08x imask=0x%08x)\n", 2051 printk(KERN_DEBUG "%s: error interrupt (ievent=0x%08x imask=0x%08x)\n",
1759 dev->name, events, gfar_read(&priv->regs->imask)); 2052 dev->name, events, gfar_read(&priv->regs->imask));
1760#endif
1761 2053
1762 /* Update the error counters */ 2054 /* Update the error counters */
1763 if (events & IEVENT_TXE) { 2055 if (events & IEVENT_TXE) {
@@ -1768,19 +2060,17 @@ static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs)
1768 if (events & IEVENT_CRL) 2060 if (events & IEVENT_CRL)
1769 priv->stats.tx_aborted_errors++; 2061 priv->stats.tx_aborted_errors++;
1770 if (events & IEVENT_XFUN) { 2062 if (events & IEVENT_XFUN) {
1771#ifdef VERBOSE_GFAR_ERRORS 2063 if (netif_msg_tx_err(priv))
1772 printk(KERN_DEBUG "%s: underrun. packet dropped.\n", 2064 printk(KERN_DEBUG "%s: underrun. packet dropped.\n",
1773 dev->name); 2065 dev->name);
1774#endif
1775 priv->stats.tx_dropped++; 2066 priv->stats.tx_dropped++;
1776 priv->extra_stats.tx_underrun++; 2067 priv->extra_stats.tx_underrun++;
1777 2068
1778 /* Reactivate the Tx Queues */ 2069 /* Reactivate the Tx Queues */
1779 gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT); 2070 gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
1780 } 2071 }
1781#ifdef VERBOSE_GFAR_ERRORS 2072 if (netif_msg_tx_err(priv))
1782 printk(KERN_DEBUG "%s: Transmit Error\n", dev->name); 2073 printk(KERN_DEBUG "%s: Transmit Error\n", dev->name);
1783#endif
1784 } 2074 }
1785 if (events & IEVENT_BSY) { 2075 if (events & IEVENT_BSY) {
1786 priv->stats.rx_errors++; 2076 priv->stats.rx_errors++;
@@ -1793,35 +2083,31 @@ static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs)
1793 gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT); 2083 gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
1794#endif 2084#endif
1795 2085
1796#ifdef VERBOSE_GFAR_ERRORS 2086 if (netif_msg_rx_err(priv))
1797 printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n", dev->name, 2087 printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n",
1798 gfar_read(&priv->regs->rstat)); 2088 dev->name,
1799#endif 2089 gfar_read(&priv->regs->rstat));
1800 } 2090 }
1801 if (events & IEVENT_BABR) { 2091 if (events & IEVENT_BABR) {
1802 priv->stats.rx_errors++; 2092 priv->stats.rx_errors++;
1803 priv->extra_stats.rx_babr++; 2093 priv->extra_stats.rx_babr++;
1804 2094
1805#ifdef VERBOSE_GFAR_ERRORS 2095 if (netif_msg_rx_err(priv))
1806 printk(KERN_DEBUG "%s: babbling error\n", dev->name); 2096 printk(KERN_DEBUG "%s: babbling error\n", dev->name);
1807#endif
1808 } 2097 }
1809 if (events & IEVENT_EBERR) { 2098 if (events & IEVENT_EBERR) {
1810 priv->extra_stats.eberr++; 2099 priv->extra_stats.eberr++;
1811#ifdef VERBOSE_GFAR_ERRORS 2100 if (netif_msg_rx_err(priv))
1812 printk(KERN_DEBUG "%s: EBERR\n", dev->name); 2101 printk(KERN_DEBUG "%s: EBERR\n", dev->name);
1813#endif
1814 } 2102 }
1815 if (events & IEVENT_RXC) 2103 if ((events & IEVENT_RXC) && netif_msg_rx_status(priv))
1816#ifdef VERBOSE_GFAR_ERRORS 2104 if (netif_msg_rx_status(priv))
1817 printk(KERN_DEBUG "%s: control frame\n", dev->name); 2105 printk(KERN_DEBUG "%s: control frame\n", dev->name);
1818#endif
1819 2106
1820 if (events & IEVENT_BABT) { 2107 if (events & IEVENT_BABT) {
1821 priv->extra_stats.tx_babt++; 2108 priv->extra_stats.tx_babt++;
1822#ifdef VERBOSE_GFAR_ERRORS 2109 if (netif_msg_tx_err(priv))
1823 printk(KERN_DEBUG "%s: babt error\n", dev->name); 2110 printk(KERN_DEBUG "%s: babt error\n", dev->name);
1824#endif
1825 } 2111 }
1826 return IRQ_HANDLED; 2112 return IRQ_HANDLED;
1827} 2113}
diff --git a/drivers/net/gianfar.h b/drivers/net/gianfar.h
index c2f783a6a9fa..28af087d9fbb 100644
--- a/drivers/net/gianfar.h
+++ b/drivers/net/gianfar.h
@@ -1,4 +1,4 @@
1/* 1/*
2 * drivers/net/gianfar.h 2 * drivers/net/gianfar.h
3 * 3 *
4 * Gianfar Ethernet Driver 4 * Gianfar Ethernet Driver
@@ -53,6 +53,12 @@
53/* The maximum number of packets to be handled in one call of gfar_poll */ 53/* The maximum number of packets to be handled in one call of gfar_poll */
54#define GFAR_DEV_WEIGHT 64 54#define GFAR_DEV_WEIGHT 64
55 55
56/* Length for FCB */
57#define GMAC_FCB_LEN 8
58
59/* Default padding amount */
60#define DEFAULT_PADDING 2
61
56/* Number of bytes to align the rx bufs to */ 62/* Number of bytes to align the rx bufs to */
57#define RXBUF_ALIGNMENT 64 63#define RXBUF_ALIGNMENT 64
58 64
@@ -91,7 +97,7 @@ extern const char gfar_driver_version[];
91#define JUMBO_FRAME_SIZE 9600 97#define JUMBO_FRAME_SIZE 9600
92 98
93/* Latency of interface clock in nanoseconds */ 99/* Latency of interface clock in nanoseconds */
94/* Interface clock latency , in this case, means the 100/* Interface clock latency , in this case, means the
95 * time described by a value of 1 in the interrupt 101 * time described by a value of 1 in the interrupt
96 * coalescing registers' time fields. Since those fields 102 * coalescing registers' time fields. Since those fields
97 * refer to the time it takes for 64 clocks to pass, the 103 * refer to the time it takes for 64 clocks to pass, the
@@ -166,9 +172,28 @@ extern const char gfar_driver_version[];
166 mk_ic_icft(count) | \ 172 mk_ic_icft(count) | \
167 mk_ic_ictt(time)) 173 mk_ic_ictt(time))
168 174
175#define RCTRL_PAL_MASK 0x001f0000
176#define RCTRL_VLEX 0x00002000
177#define RCTRL_FILREN 0x00001000
178#define RCTRL_GHTX 0x00000400
179#define RCTRL_IPCSEN 0x00000200
180#define RCTRL_TUCSEN 0x00000100
181#define RCTRL_PRSDEP_MASK 0x000000c0
182#define RCTRL_PRSDEP_INIT 0x000000c0
169#define RCTRL_PROM 0x00000008 183#define RCTRL_PROM 0x00000008
184#define RCTRL_CHECKSUMMING (RCTRL_IPCSEN \
185 | RCTRL_TUCSEN | RCTRL_PRSDEP_INIT)
186#define RCTRL_EXTHASH (RCTRL_GHTX)
187#define RCTRL_VLAN (RCTRL_PRSDEP_INIT)
188
189
170#define RSTAT_CLEAR_RHALT 0x00800000 190#define RSTAT_CLEAR_RHALT 0x00800000
171 191
192#define TCTRL_IPCSEN 0x00004000
193#define TCTRL_TUCSEN 0x00002000
194#define TCTRL_VLINS 0x00001000
195#define TCTRL_INIT_CSUM (TCTRL_TUCSEN | TCTRL_IPCSEN)
196
172#define IEVENT_INIT_CLEAR 0xffffffff 197#define IEVENT_INIT_CLEAR 0xffffffff
173#define IEVENT_BABR 0x80000000 198#define IEVENT_BABR 0x80000000
174#define IEVENT_RXC 0x40000000 199#define IEVENT_RXC 0x40000000
@@ -187,12 +212,16 @@ extern const char gfar_driver_version[];
187#define IEVENT_RXB0 0x00008000 212#define IEVENT_RXB0 0x00008000
188#define IEVENT_GRSC 0x00000100 213#define IEVENT_GRSC 0x00000100
189#define IEVENT_RXF0 0x00000080 214#define IEVENT_RXF0 0x00000080
215#define IEVENT_FIR 0x00000008
216#define IEVENT_FIQ 0x00000004
217#define IEVENT_DPE 0x00000002
218#define IEVENT_PERR 0x00000001
190#define IEVENT_RX_MASK (IEVENT_RXB0 | IEVENT_RXF0) 219#define IEVENT_RX_MASK (IEVENT_RXB0 | IEVENT_RXF0)
191#define IEVENT_TX_MASK (IEVENT_TXB | IEVENT_TXF) 220#define IEVENT_TX_MASK (IEVENT_TXB | IEVENT_TXF)
192#define IEVENT_ERR_MASK \ 221#define IEVENT_ERR_MASK \
193(IEVENT_RXC | IEVENT_BSY | IEVENT_EBERR | IEVENT_MSRO | \ 222(IEVENT_RXC | IEVENT_BSY | IEVENT_EBERR | IEVENT_MSRO | \
194 IEVENT_BABT | IEVENT_TXC | IEVENT_TXE | IEVENT_LC \ 223 IEVENT_BABT | IEVENT_TXC | IEVENT_TXE | IEVENT_LC \
195 | IEVENT_CRL | IEVENT_XFUN) 224 | IEVENT_CRL | IEVENT_XFUN | IEVENT_DPE | IEVENT_PERR)
196 225
197#define IMASK_INIT_CLEAR 0x00000000 226#define IMASK_INIT_CLEAR 0x00000000
198#define IMASK_BABR 0x80000000 227#define IMASK_BABR 0x80000000
@@ -212,10 +241,15 @@ extern const char gfar_driver_version[];
212#define IMASK_RXB0 0x00008000 241#define IMASK_RXB0 0x00008000
213#define IMASK_GTSC 0x00000100 242#define IMASK_GTSC 0x00000100
214#define IMASK_RXFEN0 0x00000080 243#define IMASK_RXFEN0 0x00000080
244#define IMASK_FIR 0x00000008
245#define IMASK_FIQ 0x00000004
246#define IMASK_DPE 0x00000002
247#define IMASK_PERR 0x00000001
215#define IMASK_RX_DISABLED ~(IMASK_RXFEN0 | IMASK_BSY) 248#define IMASK_RX_DISABLED ~(IMASK_RXFEN0 | IMASK_BSY)
216#define IMASK_DEFAULT (IMASK_TXEEN | IMASK_TXFEN | IMASK_TXBEN | \ 249#define IMASK_DEFAULT (IMASK_TXEEN | IMASK_TXFEN | IMASK_TXBEN | \
217 IMASK_RXFEN0 | IMASK_BSY | IMASK_EBERR | IMASK_BABR | \ 250 IMASK_RXFEN0 | IMASK_BSY | IMASK_EBERR | IMASK_BABR | \
218 IMASK_XFUN | IMASK_RXC | IMASK_BABT) 251 IMASK_XFUN | IMASK_RXC | IMASK_BABT | IMASK_DPE \
252 | IMASK_PERR)
219 253
220 254
221/* Attribute fields */ 255/* Attribute fields */
@@ -254,6 +288,18 @@ extern const char gfar_driver_version[];
254#define TXBD_RETRYLIMIT 0x0040 288#define TXBD_RETRYLIMIT 0x0040
255#define TXBD_RETRYCOUNTMASK 0x003c 289#define TXBD_RETRYCOUNTMASK 0x003c
256#define TXBD_UNDERRUN 0x0002 290#define TXBD_UNDERRUN 0x0002
291#define TXBD_TOE 0x0002
292
293/* Tx FCB param bits */
294#define TXFCB_VLN 0x80
295#define TXFCB_IP 0x40
296#define TXFCB_IP6 0x20
297#define TXFCB_TUP 0x10
298#define TXFCB_UDP 0x08
299#define TXFCB_CIP 0x04
300#define TXFCB_CTU 0x02
301#define TXFCB_NPH 0x01
302#define TXFCB_DEFAULT (TXFCB_IP|TXFCB_TUP|TXFCB_CTU|TXFCB_NPH)
257 303
258/* RxBD status field bits */ 304/* RxBD status field bits */
259#define RXBD_EMPTY 0x8000 305#define RXBD_EMPTY 0x8000
@@ -273,6 +319,18 @@ extern const char gfar_driver_version[];
273#define RXBD_TRUNCATED 0x0001 319#define RXBD_TRUNCATED 0x0001
274#define RXBD_STATS 0x01ff 320#define RXBD_STATS 0x01ff
275 321
322/* Rx FCB status field bits */
323#define RXFCB_VLN 0x8000
324#define RXFCB_IP 0x4000
325#define RXFCB_IP6 0x2000
326#define RXFCB_TUP 0x1000
327#define RXFCB_CIP 0x0800
328#define RXFCB_CTU 0x0400
329#define RXFCB_EIP 0x0200
330#define RXFCB_ETU 0x0100
331#define RXFCB_PERR_MASK 0x000c
332#define RXFCB_PERR_BADL3 0x0008
333
276struct txbd8 334struct txbd8
277{ 335{
278 u16 status; /* Status Fields */ 336 u16 status; /* Status Fields */
@@ -280,6 +338,22 @@ struct txbd8
280 u32 bufPtr; /* Buffer Pointer */ 338 u32 bufPtr; /* Buffer Pointer */
281}; 339};
282 340
341struct txfcb {
342 u8 vln:1,
343 ip:1,
344 ip6:1,
345 tup:1,
346 udp:1,
347 cip:1,
348 ctu:1,
349 nph:1;
350 u8 reserved;
351 u8 l4os; /* Level 4 Header Offset */
352 u8 l3os; /* Level 3 Header Offset */
353 u16 phcs; /* Pseudo-header Checksum */
354 u16 vlctl; /* VLAN control word */
355};
356
283struct rxbd8 357struct rxbd8
284{ 358{
285 u16 status; /* Status Fields */ 359 u16 status; /* Status Fields */
@@ -287,6 +361,21 @@ struct rxbd8
287 u32 bufPtr; /* Buffer Pointer */ 361 u32 bufPtr; /* Buffer Pointer */
288}; 362};
289 363
364struct rxfcb {
365 u16 vln:1,
366 ip:1,
367 ip6:1,
368 tup:1,
369 cip:1,
370 ctu:1,
371 eip:1,
372 etu:1;
373 u8 rq; /* Receive Queue index */
374 u8 pro; /* Layer 4 Protocol */
375 u16 reserved;
376 u16 vlctl; /* VLAN control word */
377};
378
290struct rmon_mib 379struct rmon_mib
291{ 380{
292 u32 tr64; /* 0x.680 - Transmit and Receive 64-byte Frame Counter */ 381 u32 tr64; /* 0x.680 - Transmit and Receive 64-byte Frame Counter */
@@ -371,90 +460,191 @@ struct gfar_stats {
371 460
372 461
373struct gfar { 462struct gfar {
374 u8 res1[16]; 463 u32 tsec_id; /* 0x.000 - Controller ID register */
375 u32 ievent; /* 0x.010 - Interrupt Event Register */ 464 u8 res1[12];
376 u32 imask; /* 0x.014 - Interrupt Mask Register */ 465 u32 ievent; /* 0x.010 - Interrupt Event Register */
377 u32 edis; /* 0x.018 - Error Disabled Register */ 466 u32 imask; /* 0x.014 - Interrupt Mask Register */
467 u32 edis; /* 0x.018 - Error Disabled Register */
378 u8 res2[4]; 468 u8 res2[4];
379 u32 ecntrl; /* 0x.020 - Ethernet Control Register */ 469 u32 ecntrl; /* 0x.020 - Ethernet Control Register */
380 u32 minflr; /* 0x.024 - Minimum Frame Length Register */ 470 u32 minflr; /* 0x.024 - Minimum Frame Length Register */
381 u32 ptv; /* 0x.028 - Pause Time Value Register */ 471 u32 ptv; /* 0x.028 - Pause Time Value Register */
382 u32 dmactrl; /* 0x.02c - DMA Control Register */ 472 u32 dmactrl; /* 0x.02c - DMA Control Register */
383 u32 tbipa; /* 0x.030 - TBI PHY Address Register */ 473 u32 tbipa; /* 0x.030 - TBI PHY Address Register */
384 u8 res3[88]; 474 u8 res3[88];
385 u32 fifo_tx_thr; /* 0x.08c - FIFO transmit threshold register */ 475 u32 fifo_tx_thr; /* 0x.08c - FIFO transmit threshold register */
386 u8 res4[8]; 476 u8 res4[8];
387 u32 fifo_tx_starve; /* 0x.098 - FIFO transmit starve register */ 477 u32 fifo_tx_starve; /* 0x.098 - FIFO transmit starve register */
388 u32 fifo_tx_starve_shutoff; /* 0x.09c - FIFO transmit starve shutoff register */ 478 u32 fifo_tx_starve_shutoff; /* 0x.09c - FIFO transmit starve shutoff register */
389 u8 res5[96]; 479 u8 res5[4];
390 u32 tctrl; /* 0x.100 - Transmit Control Register */ 480 u32 fifo_rx_pause; /* 0x.0a4 - FIFO receive pause threshold register */
391 u32 tstat; /* 0x.104 - Transmit Status Register */ 481 u32 fifo_rx_alarm; /* 0x.0a8 - FIFO receive alarm threshold register */
392 u8 res6[4]; 482 u8 res6[84];
393 u32 tbdlen; /* 0x.10c - Transmit Buffer Descriptor Data Length Register */ 483 u32 tctrl; /* 0x.100 - Transmit Control Register */
394 u32 txic; /* 0x.110 - Transmit Interrupt Coalescing Configuration Register */ 484 u32 tstat; /* 0x.104 - Transmit Status Register */
395 u8 res7[16]; 485 u32 dfvlan; /* 0x.108 - Default VLAN Control word */
396 u32 ctbptr; /* 0x.124 - Current Transmit Buffer Descriptor Pointer Register */ 486 u32 tbdlen; /* 0x.10c - Transmit Buffer Descriptor Data Length Register */
397 u8 res8[92]; 487 u32 txic; /* 0x.110 - Transmit Interrupt Coalescing Configuration Register */
398 u32 tbptr; /* 0x.184 - Transmit Buffer Descriptor Pointer Low Register */ 488 u32 tqueue; /* 0x.114 - Transmit queue control register */
399 u8 res9[124]; 489 u8 res7[40];
400 u32 tbase; /* 0x.204 - Transmit Descriptor Base Address Register */ 490 u32 tr03wt; /* 0x.140 - TxBD Rings 0-3 round-robin weightings */
401 u8 res10[168]; 491 u32 tr47wt; /* 0x.144 - TxBD Rings 4-7 round-robin weightings */
402 u32 ostbd; /* 0x.2b0 - Out-of-Sequence Transmit Buffer Descriptor Register */ 492 u8 res8[52];
403 u32 ostbdp; /* 0x.2b4 - Out-of-Sequence Transmit Data Buffer Pointer Register */ 493 u32 tbdbph; /* 0x.17c - Tx data buffer pointer high */
404 u8 res11[72]; 494 u8 res9a[4];
405 u32 rctrl; /* 0x.300 - Receive Control Register */ 495 u32 tbptr0; /* 0x.184 - TxBD Pointer for ring 0 */
406 u32 rstat; /* 0x.304 - Receive Status Register */ 496 u8 res9b[4];
407 u8 res12[4]; 497 u32 tbptr1; /* 0x.18c - TxBD Pointer for ring 1 */
408 u32 rbdlen; /* 0x.30c - RxBD Data Length Register */ 498 u8 res9c[4];
409 u32 rxic; /* 0x.310 - Receive Interrupt Coalescing Configuration Register */ 499 u32 tbptr2; /* 0x.194 - TxBD Pointer for ring 2 */
410 u8 res13[16]; 500 u8 res9d[4];
411 u32 crbptr; /* 0x.324 - Current Receive Buffer Descriptor Pointer */ 501 u32 tbptr3; /* 0x.19c - TxBD Pointer for ring 3 */
412 u8 res14[24]; 502 u8 res9e[4];
413 u32 mrblr; /* 0x.340 - Maximum Receive Buffer Length Register */ 503 u32 tbptr4; /* 0x.1a4 - TxBD Pointer for ring 4 */
414 u8 res15[64]; 504 u8 res9f[4];
415 u32 rbptr; /* 0x.384 - Receive Buffer Descriptor Pointer */ 505 u32 tbptr5; /* 0x.1ac - TxBD Pointer for ring 5 */
416 u8 res16[124]; 506 u8 res9g[4];
417 u32 rbase; /* 0x.404 - Receive Descriptor Base Address */ 507 u32 tbptr6; /* 0x.1b4 - TxBD Pointer for ring 6 */
418 u8 res17[248]; 508 u8 res9h[4];
419 u32 maccfg1; /* 0x.500 - MAC Configuration 1 Register */ 509 u32 tbptr7; /* 0x.1bc - TxBD Pointer for ring 7 */
420 u32 maccfg2; /* 0x.504 - MAC Configuration 2 Register */ 510 u8 res9[64];
421 u32 ipgifg; /* 0x.508 - Inter Packet Gap/Inter Frame Gap Register */ 511 u32 tbaseh; /* 0x.200 - TxBD base address high */
422 u32 hafdup; /* 0x.50c - Half Duplex Register */ 512 u32 tbase0; /* 0x.204 - TxBD Base Address of ring 0 */
423 u32 maxfrm; /* 0x.510 - Maximum Frame Length Register */ 513 u8 res10a[4];
514 u32 tbase1; /* 0x.20c - TxBD Base Address of ring 1 */
515 u8 res10b[4];
516 u32 tbase2; /* 0x.214 - TxBD Base Address of ring 2 */
517 u8 res10c[4];
518 u32 tbase3; /* 0x.21c - TxBD Base Address of ring 3 */
519 u8 res10d[4];
520 u32 tbase4; /* 0x.224 - TxBD Base Address of ring 4 */
521 u8 res10e[4];
522 u32 tbase5; /* 0x.22c - TxBD Base Address of ring 5 */
523 u8 res10f[4];
524 u32 tbase6; /* 0x.234 - TxBD Base Address of ring 6 */
525 u8 res10g[4];
526 u32 tbase7; /* 0x.23c - TxBD Base Address of ring 7 */
527 u8 res10[192];
528 u32 rctrl; /* 0x.300 - Receive Control Register */
529 u32 rstat; /* 0x.304 - Receive Status Register */
530 u8 res12[8];
531 u32 rxic; /* 0x.310 - Receive Interrupt Coalescing Configuration Register */
532 u32 rqueue; /* 0x.314 - Receive queue control register */
533 u8 res13[24];
534 u32 rbifx; /* 0x.330 - Receive bit field extract control register */
535 u32 rqfar; /* 0x.334 - Receive queue filing table address register */
536 u32 rqfcr; /* 0x.338 - Receive queue filing table control register */
537 u32 rqfpr; /* 0x.33c - Receive queue filing table property register */
538 u32 mrblr; /* 0x.340 - Maximum Receive Buffer Length Register */
539 u8 res14[56];
540 u32 rbdbph; /* 0x.37c - Rx data buffer pointer high */
541 u8 res15a[4];
542 u32 rbptr0; /* 0x.384 - RxBD pointer for ring 0 */
543 u8 res15b[4];
544 u32 rbptr1; /* 0x.38c - RxBD pointer for ring 1 */
545 u8 res15c[4];
546 u32 rbptr2; /* 0x.394 - RxBD pointer for ring 2 */
547 u8 res15d[4];
548 u32 rbptr3; /* 0x.39c - RxBD pointer for ring 3 */
549 u8 res15e[4];
550 u32 rbptr4; /* 0x.3a4 - RxBD pointer for ring 4 */
551 u8 res15f[4];
552 u32 rbptr5; /* 0x.3ac - RxBD pointer for ring 5 */
553 u8 res15g[4];
554 u32 rbptr6; /* 0x.3b4 - RxBD pointer for ring 6 */
555 u8 res15h[4];
556 u32 rbptr7; /* 0x.3bc - RxBD pointer for ring 7 */
557 u8 res16[64];
558 u32 rbaseh; /* 0x.400 - RxBD base address high */
559 u32 rbase0; /* 0x.404 - RxBD base address of ring 0 */
560 u8 res17a[4];
561 u32 rbase1; /* 0x.40c - RxBD base address of ring 1 */
562 u8 res17b[4];
563 u32 rbase2; /* 0x.414 - RxBD base address of ring 2 */
564 u8 res17c[4];
565 u32 rbase3; /* 0x.41c - RxBD base address of ring 3 */
566 u8 res17d[4];
567 u32 rbase4; /* 0x.424 - RxBD base address of ring 4 */
568 u8 res17e[4];
569 u32 rbase5; /* 0x.42c - RxBD base address of ring 5 */
570 u8 res17f[4];
571 u32 rbase6; /* 0x.434 - RxBD base address of ring 6 */
572 u8 res17g[4];
573 u32 rbase7; /* 0x.43c - RxBD base address of ring 7 */
574 u8 res17[192];
575 u32 maccfg1; /* 0x.500 - MAC Configuration 1 Register */
576 u32 maccfg2; /* 0x.504 - MAC Configuration 2 Register */
577 u32 ipgifg; /* 0x.508 - Inter Packet Gap/Inter Frame Gap Register */
578 u32 hafdup; /* 0x.50c - Half Duplex Register */
579 u32 maxfrm; /* 0x.510 - Maximum Frame Length Register */
424 u8 res18[12]; 580 u8 res18[12];
425 u32 miimcfg; /* 0x.520 - MII Management Configuration Register */ 581 u32 miimcfg; /* 0x.520 - MII Management Configuration Register */
426 u32 miimcom; /* 0x.524 - MII Management Command Register */ 582 u32 miimcom; /* 0x.524 - MII Management Command Register */
427 u32 miimadd; /* 0x.528 - MII Management Address Register */ 583 u32 miimadd; /* 0x.528 - MII Management Address Register */
428 u32 miimcon; /* 0x.52c - MII Management Control Register */ 584 u32 miimcon; /* 0x.52c - MII Management Control Register */
429 u32 miimstat; /* 0x.530 - MII Management Status Register */ 585 u32 miimstat; /* 0x.530 - MII Management Status Register */
430 u32 miimind; /* 0x.534 - MII Management Indicator Register */ 586 u32 miimind; /* 0x.534 - MII Management Indicator Register */
431 u8 res19[4]; 587 u8 res19[4];
432 u32 ifstat; /* 0x.53c - Interface Status Register */ 588 u32 ifstat; /* 0x.53c - Interface Status Register */
433 u32 macstnaddr1; /* 0x.540 - Station Address Part 1 Register */ 589 u32 macstnaddr1; /* 0x.540 - Station Address Part 1 Register */
434 u32 macstnaddr2; /* 0x.544 - Station Address Part 2 Register */ 590 u32 macstnaddr2; /* 0x.544 - Station Address Part 2 Register */
435 u8 res20[312]; 591 u32 mac01addr1; /* 0x.548 - MAC exact match address 1, part 1 */
436 struct rmon_mib rmon; 592 u32 mac01addr2; /* 0x.54c - MAC exact match address 1, part 2 */
437 u8 res21[192]; 593 u32 mac02addr1; /* 0x.550 - MAC exact match address 2, part 1 */
438 u32 iaddr0; /* 0x.800 - Indivdual address register 0 */ 594 u32 mac02addr2; /* 0x.554 - MAC exact match address 2, part 2 */
439 u32 iaddr1; /* 0x.804 - Indivdual address register 1 */ 595 u32 mac03addr1; /* 0x.558 - MAC exact match address 3, part 1 */
440 u32 iaddr2; /* 0x.808 - Indivdual address register 2 */ 596 u32 mac03addr2; /* 0x.55c - MAC exact match address 3, part 2 */
441 u32 iaddr3; /* 0x.80c - Indivdual address register 3 */ 597 u32 mac04addr1; /* 0x.560 - MAC exact match address 4, part 1 */
442 u32 iaddr4; /* 0x.810 - Indivdual address register 4 */ 598 u32 mac04addr2; /* 0x.564 - MAC exact match address 4, part 2 */
443 u32 iaddr5; /* 0x.814 - Indivdual address register 5 */ 599 u32 mac05addr1; /* 0x.568 - MAC exact match address 5, part 1 */
444 u32 iaddr6; /* 0x.818 - Indivdual address register 6 */ 600 u32 mac05addr2; /* 0x.56c - MAC exact match address 5, part 2 */
445 u32 iaddr7; /* 0x.81c - Indivdual address register 7 */ 601 u32 mac06addr1; /* 0x.570 - MAC exact match address 6, part 1 */
602 u32 mac06addr2; /* 0x.574 - MAC exact match address 6, part 2 */
603 u32 mac07addr1; /* 0x.578 - MAC exact match address 7, part 1 */
604 u32 mac07addr2; /* 0x.57c - MAC exact match address 7, part 2 */
605 u32 mac08addr1; /* 0x.580 - MAC exact match address 8, part 1 */
606 u32 mac08addr2; /* 0x.584 - MAC exact match address 8, part 2 */
607 u32 mac09addr1; /* 0x.588 - MAC exact match address 9, part 1 */
608 u32 mac09addr2; /* 0x.58c - MAC exact match address 9, part 2 */
609 u32 mac10addr1; /* 0x.590 - MAC exact match address 10, part 1*/
610 u32 mac10addr2; /* 0x.594 - MAC exact match address 10, part 2*/
611 u32 mac11addr1; /* 0x.598 - MAC exact match address 11, part 1*/
612 u32 mac11addr2; /* 0x.59c - MAC exact match address 11, part 2*/
613 u32 mac12addr1; /* 0x.5a0 - MAC exact match address 12, part 1*/
614 u32 mac12addr2; /* 0x.5a4 - MAC exact match address 12, part 2*/
615 u32 mac13addr1; /* 0x.5a8 - MAC exact match address 13, part 1*/
616 u32 mac13addr2; /* 0x.5ac - MAC exact match address 13, part 2*/
617 u32 mac14addr1; /* 0x.5b0 - MAC exact match address 14, part 1*/
618 u32 mac14addr2; /* 0x.5b4 - MAC exact match address 14, part 2*/
619 u32 mac15addr1; /* 0x.5b8 - MAC exact match address 15, part 1*/
620 u32 mac15addr2; /* 0x.5bc - MAC exact match address 15, part 2*/
621 u8 res20[192];
622 struct rmon_mib rmon; /* 0x.680-0x.73c */
623 u32 rrej; /* 0x.740 - Receive filer rejected packet counter */
624 u8 res21[188];
625 u32 igaddr0; /* 0x.800 - Indivdual/Group address register 0*/
626 u32 igaddr1; /* 0x.804 - Indivdual/Group address register 1*/
627 u32 igaddr2; /* 0x.808 - Indivdual/Group address register 2*/
628 u32 igaddr3; /* 0x.80c - Indivdual/Group address register 3*/
629 u32 igaddr4; /* 0x.810 - Indivdual/Group address register 4*/
630 u32 igaddr5; /* 0x.814 - Indivdual/Group address register 5*/
631 u32 igaddr6; /* 0x.818 - Indivdual/Group address register 6*/
632 u32 igaddr7; /* 0x.81c - Indivdual/Group address register 7*/
446 u8 res22[96]; 633 u8 res22[96];
447 u32 gaddr0; /* 0x.880 - Global address register 0 */ 634 u32 gaddr0; /* 0x.880 - Group address register 0 */
448 u32 gaddr1; /* 0x.884 - Global address register 1 */ 635 u32 gaddr1; /* 0x.884 - Group address register 1 */
449 u32 gaddr2; /* 0x.888 - Global address register 2 */ 636 u32 gaddr2; /* 0x.888 - Group address register 2 */
450 u32 gaddr3; /* 0x.88c - Global address register 3 */ 637 u32 gaddr3; /* 0x.88c - Group address register 3 */
451 u32 gaddr4; /* 0x.890 - Global address register 4 */ 638 u32 gaddr4; /* 0x.890 - Group address register 4 */
452 u32 gaddr5; /* 0x.894 - Global address register 5 */ 639 u32 gaddr5; /* 0x.894 - Group address register 5 */
453 u32 gaddr6; /* 0x.898 - Global address register 6 */ 640 u32 gaddr6; /* 0x.898 - Group address register 6 */
454 u32 gaddr7; /* 0x.89c - Global address register 7 */ 641 u32 gaddr7; /* 0x.89c - Group address register 7 */
455 u8 res23[856]; 642 u8 res23a[352];
456 u32 attr; /* 0x.bf8 - Attributes Register */ 643 u32 fifocfg; /* 0x.a00 - FIFO interface config register */
457 u32 attreli; /* 0x.bfc - Attributes Extract Length and Extract Index Register */ 644 u8 res23b[252];
645 u8 res23c[248];
646 u32 attr; /* 0x.bf8 - Attributes Register */
647 u32 attreli; /* 0x.bfc - Attributes Extract Length and Extract Index Register */
458 u8 res24[1024]; 648 u8 res24[1024];
459 649
460}; 650};
@@ -496,6 +686,8 @@ struct gfar_private {
496 struct txbd8 *cur_tx; /* Next free ring entry */ 686 struct txbd8 *cur_tx; /* Next free ring entry */
497 struct txbd8 *dirty_tx; /* The Ring entry to be freed. */ 687 struct txbd8 *dirty_tx; /* The Ring entry to be freed. */
498 struct gfar *regs; /* Pointer to the GFAR memory mapped Registers */ 688 struct gfar *regs; /* Pointer to the GFAR memory mapped Registers */
689 u32 *hash_regs[16];
690 int hash_width;
499 struct gfar *phyregs; 691 struct gfar *phyregs;
500 struct work_struct tq; 692 struct work_struct tq;
501 struct timer_list phy_info_timer; 693 struct timer_list phy_info_timer;
@@ -506,9 +698,12 @@ struct gfar_private {
506 unsigned int rx_stash_size; 698 unsigned int rx_stash_size;
507 unsigned int tx_ring_size; 699 unsigned int tx_ring_size;
508 unsigned int rx_ring_size; 700 unsigned int rx_ring_size;
509 wait_queue_head_t rxcleanupq;
510 unsigned int rxclean;
511 701
702 unsigned char vlan_enable:1,
703 rx_csum_enable:1,
704 extended_hash:1;
705 unsigned short padding;
706 struct vlan_group *vlgrp;
512 /* Info structure initialized by board setup code */ 707 /* Info structure initialized by board setup code */
513 unsigned int interruptTransmit; 708 unsigned int interruptTransmit;
514 unsigned int interruptReceive; 709 unsigned int interruptReceive;
@@ -519,6 +714,8 @@ struct gfar_private {
519 int oldspeed; 714 int oldspeed;
520 int oldduplex; 715 int oldduplex;
521 int oldlink; 716 int oldlink;
717
718 uint32_t msg_enable;
522}; 719};
523 720
524extern inline u32 gfar_read(volatile unsigned *addr) 721extern inline u32 gfar_read(volatile unsigned *addr)
diff --git a/drivers/net/gianfar_ethtool.c b/drivers/net/gianfar_ethtool.c
index 28046e9e88ba..a451de629197 100644
--- a/drivers/net/gianfar_ethtool.c
+++ b/drivers/net/gianfar_ethtool.c
@@ -46,16 +46,18 @@
46 46
47extern int startup_gfar(struct net_device *dev); 47extern int startup_gfar(struct net_device *dev);
48extern void stop_gfar(struct net_device *dev); 48extern void stop_gfar(struct net_device *dev);
49extern void gfar_receive(int irq, void *dev_id, struct pt_regs *regs); 49extern void gfar_halt(struct net_device *dev);
50extern void gfar_start(struct net_device *dev);
51extern int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit);
50 52
51void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, 53static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,
52 u64 * buf); 54 u64 * buf);
53void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf); 55static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf);
54int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals); 56static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
55int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals); 57static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
56void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals); 58static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
57int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals); 59static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
58void gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo); 60static void gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo);
59 61
60static char stat_gstrings[][ETH_GSTRING_LEN] = { 62static char stat_gstrings[][ETH_GSTRING_LEN] = {
61 "rx-dropped-by-kernel", 63 "rx-dropped-by-kernel",
@@ -118,57 +120,56 @@ static char stat_gstrings[][ETH_GSTRING_LEN] = {
118 "tx-fragmented-frames", 120 "tx-fragmented-frames",
119}; 121};
120 122
123/* Fill in a buffer with the strings which correspond to the
124 * stats */
125static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf)
126{
127 struct gfar_private *priv = netdev_priv(dev);
128
129 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
130 memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN);
131 else
132 memcpy(buf, stat_gstrings,
133 GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN);
134}
135
121/* Fill in an array of 64-bit statistics from various sources. 136/* Fill in an array of 64-bit statistics from various sources.
122 * This array will be appended to the end of the ethtool_stats 137 * This array will be appended to the end of the ethtool_stats
123 * structure, and returned to user space 138 * structure, and returned to user space
124 */ 139 */
125void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, u64 * buf) 140static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, u64 * buf)
126{ 141{
127 int i; 142 int i;
128 struct gfar_private *priv = netdev_priv(dev); 143 struct gfar_private *priv = netdev_priv(dev);
129 u32 *rmon = (u32 *) & priv->regs->rmon;
130 u64 *extra = (u64 *) & priv->extra_stats; 144 u64 *extra = (u64 *) & priv->extra_stats;
131 struct gfar_stats *stats = (struct gfar_stats *) buf;
132 145
133 for (i = 0; i < GFAR_RMON_LEN; i++) { 146 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
134 stats->rmon[i] = (u64) (rmon[i]); 147 u32 *rmon = (u32 *) & priv->regs->rmon;
135 } 148 struct gfar_stats *stats = (struct gfar_stats *) buf;
136
137 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++) {
138 stats->extra[i] = extra[i];
139 }
140}
141 149
142/* Returns the number of stats (and their corresponding strings) */ 150 for (i = 0; i < GFAR_RMON_LEN; i++)
143int gfar_stats_count(struct net_device *dev) 151 stats->rmon[i] = (u64) (rmon[i]);
144{
145 return GFAR_STATS_LEN;
146}
147 152
148void gfar_gstrings_normon(struct net_device *dev, u32 stringset, u8 * buf) 153 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
149{ 154 stats->extra[i] = extra[i];
150 memcpy(buf, stat_gstrings, GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN); 155 } else
156 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
157 buf[i] = extra[i];
151} 158}
152 159
153void gfar_fill_stats_normon(struct net_device *dev, 160/* Returns the number of stats (and their corresponding strings) */
154 struct ethtool_stats *dummy, u64 * buf) 161static int gfar_stats_count(struct net_device *dev)
155{ 162{
156 int i;
157 struct gfar_private *priv = netdev_priv(dev); 163 struct gfar_private *priv = netdev_priv(dev);
158 u64 *extra = (u64 *) & priv->extra_stats;
159 164
160 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++) { 165 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
161 buf[i] = extra[i]; 166 return GFAR_STATS_LEN;
162 } 167 else
168 return GFAR_EXTRA_STATS_LEN;
163} 169}
164 170
165
166int gfar_stats_count_normon(struct net_device *dev)
167{
168 return GFAR_EXTRA_STATS_LEN;
169}
170/* Fills in the drvinfo structure with some basic info */ 171/* Fills in the drvinfo structure with some basic info */
171void gfar_gdrvinfo(struct net_device *dev, struct 172static void gfar_gdrvinfo(struct net_device *dev, struct
172 ethtool_drvinfo *drvinfo) 173 ethtool_drvinfo *drvinfo)
173{ 174{
174 strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN); 175 strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN);
@@ -182,7 +183,7 @@ void gfar_gdrvinfo(struct net_device *dev, struct
182} 183}
183 184
184/* Return the current settings in the ethtool_cmd structure */ 185/* Return the current settings in the ethtool_cmd structure */
185int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd) 186static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd)
186{ 187{
187 struct gfar_private *priv = netdev_priv(dev); 188 struct gfar_private *priv = netdev_priv(dev);
188 uint gigabit_support = 189 uint gigabit_support =
@@ -216,13 +217,13 @@ int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd)
216} 217}
217 218
218/* Return the length of the register structure */ 219/* Return the length of the register structure */
219int gfar_reglen(struct net_device *dev) 220static int gfar_reglen(struct net_device *dev)
220{ 221{
221 return sizeof (struct gfar); 222 return sizeof (struct gfar);
222} 223}
223 224
224/* Return a dump of the GFAR register space */ 225/* Return a dump of the GFAR register space */
225void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf) 226static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf)
226{ 227{
227 int i; 228 int i;
228 struct gfar_private *priv = netdev_priv(dev); 229 struct gfar_private *priv = netdev_priv(dev);
@@ -233,13 +234,6 @@ void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regb
233 buf[i] = theregs[i]; 234 buf[i] = theregs[i];
234} 235}
235 236
236/* Fill in a buffer with the strings which correspond to the
237 * stats */
238void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf)
239{
240 memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN);
241}
242
243/* Convert microseconds to ethernet clock ticks, which changes 237/* Convert microseconds to ethernet clock ticks, which changes
244 * depending on what speed the controller is running at */ 238 * depending on what speed the controller is running at */
245static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs) 239static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs)
@@ -291,9 +285,12 @@ static unsigned int gfar_ticks2usecs(struct gfar_private *priv, unsigned int tic
291 285
292/* Get the coalescing parameters, and put them in the cvals 286/* Get the coalescing parameters, and put them in the cvals
293 * structure. */ 287 * structure. */
294int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) 288static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
295{ 289{
296 struct gfar_private *priv = netdev_priv(dev); 290 struct gfar_private *priv = netdev_priv(dev);
291
292 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
293 return -EOPNOTSUPP;
297 294
298 cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, priv->rxtime); 295 cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, priv->rxtime);
299 cvals->rx_max_coalesced_frames = priv->rxcount; 296 cvals->rx_max_coalesced_frames = priv->rxcount;
@@ -337,10 +334,13 @@ int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
337 * Both cvals->*_usecs and cvals->*_frames have to be > 0 334 * Both cvals->*_usecs and cvals->*_frames have to be > 0
338 * in order for coalescing to be active 335 * in order for coalescing to be active
339 */ 336 */
340int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) 337static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
341{ 338{
342 struct gfar_private *priv = netdev_priv(dev); 339 struct gfar_private *priv = netdev_priv(dev);
343 340
341 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
342 return -EOPNOTSUPP;
343
344 /* Set up rx coalescing */ 344 /* Set up rx coalescing */
345 if ((cvals->rx_coalesce_usecs == 0) || 345 if ((cvals->rx_coalesce_usecs == 0) ||
346 (cvals->rx_max_coalesced_frames == 0)) 346 (cvals->rx_max_coalesced_frames == 0))
@@ -379,7 +379,7 @@ int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
379/* Fills in rvals with the current ring parameters. Currently, 379/* Fills in rvals with the current ring parameters. Currently,
380 * rx, rx_mini, and rx_jumbo rings are the same size, as mini and 380 * rx, rx_mini, and rx_jumbo rings are the same size, as mini and
381 * jumbo are ignored by the driver */ 381 * jumbo are ignored by the driver */
382void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals) 382static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
383{ 383{
384 struct gfar_private *priv = netdev_priv(dev); 384 struct gfar_private *priv = netdev_priv(dev);
385 385
@@ -401,9 +401,8 @@ void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
401 * necessary so that we don't mess things up while we're in 401 * necessary so that we don't mess things up while we're in
402 * motion. We wait for the ring to be clean before reallocating 402 * motion. We wait for the ring to be clean before reallocating
403 * the rings. */ 403 * the rings. */
404int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals) 404static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
405{ 405{
406 u32 tempval;
407 struct gfar_private *priv = netdev_priv(dev); 406 struct gfar_private *priv = netdev_priv(dev);
408 int err = 0; 407 int err = 0;
409 408
@@ -425,37 +424,54 @@ int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
425 return -EINVAL; 424 return -EINVAL;
426 } 425 }
427 426
428 /* Stop the controller so we don't rx any more frames */ 427 if (dev->flags & IFF_UP) {
429 /* But first, make sure we clear the bits */ 428 unsigned long flags;
430 tempval = gfar_read(&priv->regs->dmactrl);
431 tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
432 gfar_write(&priv->regs->dmactrl, tempval);
433 429
434 tempval = gfar_read(&priv->regs->dmactrl); 430 /* Halt TX and RX, and process the frames which
435 tempval |= (DMACTRL_GRS | DMACTRL_GTS); 431 * have already been received */
436 gfar_write(&priv->regs->dmactrl, tempval); 432 spin_lock_irqsave(&priv->lock, flags);
433 gfar_halt(dev);
434 gfar_clean_rx_ring(dev, priv->rx_ring_size);
435 spin_unlock_irqrestore(&priv->lock, flags);
437 436
438 while (!(gfar_read(&priv->regs->ievent) & (IEVENT_GRSC | IEVENT_GTSC))) 437 /* Now we take down the rings to rebuild them */
439 cpu_relax(); 438 stop_gfar(dev);
439 }
440 440
441 /* Note that rx is not clean right now */ 441 /* Change the size */
442 priv->rxclean = 0; 442 priv->rx_ring_size = rvals->rx_pending;
443 priv->tx_ring_size = rvals->tx_pending;
443 444
444 if (dev->flags & IFF_UP) { 445 /* Rebuild the rings with the new size */
445 /* Tell the driver to process the rest of the frames */ 446 if (dev->flags & IFF_UP)
446 gfar_receive(0, (void *) dev, NULL); 447 err = startup_gfar(dev);
447 448
448 /* Now wait for it to be done */ 449 return err;
449 wait_event_interruptible(priv->rxcleanupq, priv->rxclean); 450}
450 451
451 /* Ok, all packets have been handled. Now we bring it down, 452static int gfar_set_rx_csum(struct net_device *dev, uint32_t data)
452 * change the ring size, and bring it up */ 453{
454 struct gfar_private *priv = netdev_priv(dev);
455 int err = 0;
453 456
457 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
458 return -EOPNOTSUPP;
459
460 if (dev->flags & IFF_UP) {
461 unsigned long flags;
462
463 /* Halt TX and RX, and process the frames which
464 * have already been received */
465 spin_lock_irqsave(&priv->lock, flags);
466 gfar_halt(dev);
467 gfar_clean_rx_ring(dev, priv->rx_ring_size);
468 spin_unlock_irqrestore(&priv->lock, flags);
469
470 /* Now we take down the rings to rebuild them */
454 stop_gfar(dev); 471 stop_gfar(dev);
455 } 472 }
456 473
457 priv->rx_ring_size = rvals->rx_pending; 474 priv->rx_csum_enable = data;
458 priv->tx_ring_size = rvals->tx_pending;
459 475
460 if (dev->flags & IFF_UP) 476 if (dev->flags & IFF_UP)
461 err = startup_gfar(dev); 477 err = startup_gfar(dev);
@@ -463,6 +479,61 @@ int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
463 return err; 479 return err;
464} 480}
465 481
482static uint32_t gfar_get_rx_csum(struct net_device *dev)
483{
484 struct gfar_private *priv = netdev_priv(dev);
485
486 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
487 return 0;
488
489 return priv->rx_csum_enable;
490}
491
492static int gfar_set_tx_csum(struct net_device *dev, uint32_t data)
493{
494 unsigned long flags;
495 struct gfar_private *priv = netdev_priv(dev);
496
497 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
498 return -EOPNOTSUPP;
499
500 spin_lock_irqsave(&priv->lock, flags);
501 gfar_halt(dev);
502
503 if (data)
504 dev->features |= NETIF_F_IP_CSUM;
505 else
506 dev->features &= ~NETIF_F_IP_CSUM;
507
508 gfar_start(dev);
509 spin_unlock_irqrestore(&priv->lock, flags);
510
511 return 0;
512}
513
514static uint32_t gfar_get_tx_csum(struct net_device *dev)
515{
516 struct gfar_private *priv = netdev_priv(dev);
517
518 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
519 return 0;
520
521 return (dev->features & NETIF_F_IP_CSUM) != 0;
522}
523
524static uint32_t gfar_get_msglevel(struct net_device *dev)
525{
526 struct gfar_private *priv = netdev_priv(dev);
527 return priv->msg_enable;
528}
529
530static void gfar_set_msglevel(struct net_device *dev, uint32_t data)
531{
532 struct gfar_private *priv = netdev_priv(dev);
533 priv->msg_enable = data;
534}
535
536
466struct ethtool_ops gfar_ethtool_ops = { 537struct ethtool_ops gfar_ethtool_ops = {
467 .get_settings = gfar_gsettings, 538 .get_settings = gfar_gsettings,
468 .get_drvinfo = gfar_gdrvinfo, 539 .get_drvinfo = gfar_gdrvinfo,
@@ -476,52 +547,10 @@ struct ethtool_ops gfar_ethtool_ops = {
476 .get_strings = gfar_gstrings, 547 .get_strings = gfar_gstrings,
477 .get_stats_count = gfar_stats_count, 548 .get_stats_count = gfar_stats_count,
478 .get_ethtool_stats = gfar_fill_stats, 549 .get_ethtool_stats = gfar_fill_stats,
479}; 550 .get_rx_csum = gfar_get_rx_csum,
480 551 .get_tx_csum = gfar_get_tx_csum,
481struct ethtool_ops gfar_normon_nocoalesce_ethtool_ops = { 552 .set_rx_csum = gfar_set_rx_csum,
482 .get_settings = gfar_gsettings, 553 .set_tx_csum = gfar_set_tx_csum,
483 .get_drvinfo = gfar_gdrvinfo, 554 .get_msglevel = gfar_get_msglevel,
484 .get_regs_len = gfar_reglen, 555 .set_msglevel = gfar_set_msglevel,
485 .get_regs = gfar_get_regs,
486 .get_link = ethtool_op_get_link,
487 .get_ringparam = gfar_gringparam,
488 .set_ringparam = gfar_sringparam,
489 .get_strings = gfar_gstrings_normon,
490 .get_stats_count = gfar_stats_count_normon,
491 .get_ethtool_stats = gfar_fill_stats_normon,
492};
493
494struct ethtool_ops gfar_nocoalesce_ethtool_ops = {
495 .get_settings = gfar_gsettings,
496 .get_drvinfo = gfar_gdrvinfo,
497 .get_regs_len = gfar_reglen,
498 .get_regs = gfar_get_regs,
499 .get_link = ethtool_op_get_link,
500 .get_ringparam = gfar_gringparam,
501 .set_ringparam = gfar_sringparam,
502 .get_strings = gfar_gstrings,
503 .get_stats_count = gfar_stats_count,
504 .get_ethtool_stats = gfar_fill_stats,
505};
506
507struct ethtool_ops gfar_normon_ethtool_ops = {
508 .get_settings = gfar_gsettings,
509 .get_drvinfo = gfar_gdrvinfo,
510 .get_regs_len = gfar_reglen,
511 .get_regs = gfar_get_regs,
512 .get_link = ethtool_op_get_link,
513 .get_coalesce = gfar_gcoalesce,
514 .set_coalesce = gfar_scoalesce,
515 .get_ringparam = gfar_gringparam,
516 .set_ringparam = gfar_sringparam,
517 .get_strings = gfar_gstrings_normon,
518 .get_stats_count = gfar_stats_count_normon,
519 .get_ethtool_stats = gfar_fill_stats_normon,
520};
521
522struct ethtool_ops *gfar_op_array[] = {
523 &gfar_ethtool_ops,
524 &gfar_normon_ethtool_ops,
525 &gfar_nocoalesce_ethtool_ops,
526 &gfar_normon_nocoalesce_ethtool_ops
527}; 556};
diff --git a/drivers/net/gianfar_phy.c b/drivers/net/gianfar_phy.c
index 02b16abc89bd..7c965f268a82 100644
--- a/drivers/net/gianfar_phy.c
+++ b/drivers/net/gianfar_phy.c
@@ -572,7 +572,7 @@ static struct phy_info phy_info_dm9161 = {
572static struct phy_info phy_info_marvell = { 572static struct phy_info phy_info_marvell = {
573 .phy_id = 0x01410c00, 573 .phy_id = 0x01410c00,
574 .phy_id_mask = 0xffffff00, 574 .phy_id_mask = 0xffffff00,
575 .name = "Marvell 88E1101", 575 .name = "Marvell 88E1101/88E1111",
576 .features = MII_GBIT_FEATURES, 576 .features = MII_GBIT_FEATURES,
577 .config_aneg = &marvell_config_aneg, 577 .config_aneg = &marvell_config_aneg,
578 .read_status = &marvell_read_status, 578 .read_status = &marvell_read_status,
diff --git a/drivers/net/hamachi.c b/drivers/net/hamachi.c
index 3d96714ed3cf..d9df1d9a5739 100644
--- a/drivers/net/hamachi.c
+++ b/drivers/net/hamachi.c
@@ -1149,7 +1149,7 @@ static void hamachi_tx_timeout(struct net_device *dev)
1149 skb->dev = dev; /* Mark as being used by this device. */ 1149 skb->dev = dev; /* Mark as being used by this device. */
1150 skb_reserve(skb, 2); /* 16 byte align the IP header. */ 1150 skb_reserve(skb, 2); /* 16 byte align the IP header. */
1151 hmp->rx_ring[i].addr = cpu_to_leXX(pci_map_single(hmp->pci_dev, 1151 hmp->rx_ring[i].addr = cpu_to_leXX(pci_map_single(hmp->pci_dev,
1152 skb->tail, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE)); 1152 skb->data, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE));
1153 hmp->rx_ring[i].status_n_length = cpu_to_le32(DescOwn | 1153 hmp->rx_ring[i].status_n_length = cpu_to_le32(DescOwn |
1154 DescEndPacket | DescIntr | (hmp->rx_buf_sz - 2)); 1154 DescEndPacket | DescIntr | (hmp->rx_buf_sz - 2));
1155 } 1155 }
@@ -1210,7 +1210,7 @@ static void hamachi_init_ring(struct net_device *dev)
1210 skb->dev = dev; /* Mark as being used by this device. */ 1210 skb->dev = dev; /* Mark as being used by this device. */
1211 skb_reserve(skb, 2); /* 16 byte align the IP header. */ 1211 skb_reserve(skb, 2); /* 16 byte align the IP header. */
1212 hmp->rx_ring[i].addr = cpu_to_leXX(pci_map_single(hmp->pci_dev, 1212 hmp->rx_ring[i].addr = cpu_to_leXX(pci_map_single(hmp->pci_dev,
1213 skb->tail, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE)); 1213 skb->data, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE));
1214 /* -2 because it doesn't REALLY have that first 2 bytes -KDU */ 1214 /* -2 because it doesn't REALLY have that first 2 bytes -KDU */
1215 hmp->rx_ring[i].status_n_length = cpu_to_le32(DescOwn | 1215 hmp->rx_ring[i].status_n_length = cpu_to_le32(DescOwn |
1216 DescEndPacket | DescIntr | (hmp->rx_buf_sz -2)); 1216 DescEndPacket | DescIntr | (hmp->rx_buf_sz -2));
@@ -1509,7 +1509,7 @@ static int hamachi_rx(struct net_device *dev)
1509 desc->addr, 1509 desc->addr,
1510 hmp->rx_buf_sz, 1510 hmp->rx_buf_sz,
1511 PCI_DMA_FROMDEVICE); 1511 PCI_DMA_FROMDEVICE);
1512 buf_addr = (u8 *) hmp->rx_skbuff[entry]->tail; 1512 buf_addr = (u8 *) hmp->rx_skbuff[entry]->data;
1513 frame_status = le32_to_cpu(get_unaligned((s32*)&(buf_addr[data_size - 12]))); 1513 frame_status = le32_to_cpu(get_unaligned((s32*)&(buf_addr[data_size - 12])));
1514 if (hamachi_debug > 4) 1514 if (hamachi_debug > 4)
1515 printk(KERN_DEBUG " hamachi_rx() status was %8.8x.\n", 1515 printk(KERN_DEBUG " hamachi_rx() status was %8.8x.\n",
@@ -1678,7 +1678,7 @@ static int hamachi_rx(struct net_device *dev)
1678 skb->dev = dev; /* Mark as being used by this device. */ 1678 skb->dev = dev; /* Mark as being used by this device. */
1679 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 1679 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1680 desc->addr = cpu_to_leXX(pci_map_single(hmp->pci_dev, 1680 desc->addr = cpu_to_leXX(pci_map_single(hmp->pci_dev,
1681 skb->tail, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE)); 1681 skb->data, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE));
1682 } 1682 }
1683 desc->status_n_length = cpu_to_le32(hmp->rx_buf_sz); 1683 desc->status_n_length = cpu_to_le32(hmp->rx_buf_sz);
1684 if (entry >= RX_RING_SIZE-1) 1684 if (entry >= RX_RING_SIZE-1)
@@ -1772,9 +1772,9 @@ static int hamachi_close(struct net_device *dev)
1772 readl(ioaddr + RxCurPtr) == (long)&hmp->rx_ring[i] ? '>' : ' ', 1772 readl(ioaddr + RxCurPtr) == (long)&hmp->rx_ring[i] ? '>' : ' ',
1773 i, hmp->rx_ring[i].status_n_length, hmp->rx_ring[i].addr); 1773 i, hmp->rx_ring[i].status_n_length, hmp->rx_ring[i].addr);
1774 if (hamachi_debug > 6) { 1774 if (hamachi_debug > 6) {
1775 if (*(u8*)hmp->rx_skbuff[i]->tail != 0x69) { 1775 if (*(u8*)hmp->rx_skbuff[i]->data != 0x69) {
1776 u16 *addr = (u16 *) 1776 u16 *addr = (u16 *)
1777 hmp->rx_skbuff[i]->tail; 1777 hmp->rx_skbuff[i]->data;
1778 int j; 1778 int j;
1779 1779
1780 for (j = 0; j < 0x50; j++) 1780 for (j = 0; j < 0x50; j++)
diff --git a/drivers/net/hp-plus.c b/drivers/net/hp-plus.c
index 4834314b676d..0abf5dd08b4c 100644
--- a/drivers/net/hp-plus.c
+++ b/drivers/net/hp-plus.c
@@ -159,12 +159,7 @@ struct net_device * __init hp_plus_probe(int unit)
159 err = do_hpp_probe(dev); 159 err = do_hpp_probe(dev);
160 if (err) 160 if (err)
161 goto out; 161 goto out;
162 err = register_netdev(dev);
163 if (err)
164 goto out1;
165 return dev; 162 return dev;
166out1:
167 cleanup_card(dev);
168out: 163out:
169 free_netdev(dev); 164 free_netdev(dev);
170 return ERR_PTR(err); 165 return ERR_PTR(err);
@@ -271,6 +266,9 @@ static int __init hpp_probe1(struct net_device *dev, int ioaddr)
271 /* Leave the 8390 and HP chip reset. */ 266 /* Leave the 8390 and HP chip reset. */
272 outw(inw(ioaddr + HPP_OPTION) & ~EnableIRQ, ioaddr + HPP_OPTION); 267 outw(inw(ioaddr + HPP_OPTION) & ~EnableIRQ, ioaddr + HPP_OPTION);
273 268
269 retval = register_netdev(dev);
270 if (retval)
271 goto out;
274 return 0; 272 return 0;
275out: 273out:
276 release_region(ioaddr, HP_IO_EXTENT); 274 release_region(ioaddr, HP_IO_EXTENT);
@@ -463,11 +461,8 @@ init_module(void)
463 dev->irq = irq[this_dev]; 461 dev->irq = irq[this_dev];
464 dev->base_addr = io[this_dev]; 462 dev->base_addr = io[this_dev];
465 if (do_hpp_probe(dev) == 0) { 463 if (do_hpp_probe(dev) == 0) {
466 if (register_netdev(dev) == 0) { 464 dev_hpp[found++] = dev;
467 dev_hpp[found++] = dev; 465 continue;
468 continue;
469 }
470 cleanup_card(dev);
471 } 466 }
472 free_netdev(dev); 467 free_netdev(dev);
473 printk(KERN_WARNING "hp-plus.c: No HP-Plus card found (i/o = 0x%x).\n", io[this_dev]); 468 printk(KERN_WARNING "hp-plus.c: No HP-Plus card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/hp.c b/drivers/net/hp.c
index 026888611d6f..59cf841b14ab 100644
--- a/drivers/net/hp.c
+++ b/drivers/net/hp.c
@@ -123,12 +123,7 @@ struct net_device * __init hp_probe(int unit)
123 err = do_hp_probe(dev); 123 err = do_hp_probe(dev);
124 if (err) 124 if (err)
125 goto out; 125 goto out;
126 err = register_netdev(dev);
127 if (err)
128 goto out1;
129 return dev; 126 return dev;
130out1:
131 cleanup_card(dev);
132out: 127out:
133 free_netdev(dev); 128 free_netdev(dev);
134 return ERR_PTR(err); 129 return ERR_PTR(err);
@@ -227,7 +222,12 @@ static int __init hp_probe1(struct net_device *dev, int ioaddr)
227 ei_status.block_output = &hp_block_output; 222 ei_status.block_output = &hp_block_output;
228 hp_init_card(dev); 223 hp_init_card(dev);
229 224
225 retval = register_netdev(dev);
226 if (retval)
227 goto out1;
230 return 0; 228 return 0;
229out1:
230 free_irq(dev->irq, dev);
231out: 231out:
232 release_region(ioaddr, HP_IO_EXTENT); 232 release_region(ioaddr, HP_IO_EXTENT);
233 return retval; 233 return retval;
@@ -432,11 +432,8 @@ init_module(void)
432 dev->irq = irq[this_dev]; 432 dev->irq = irq[this_dev];
433 dev->base_addr = io[this_dev]; 433 dev->base_addr = io[this_dev];
434 if (do_hp_probe(dev) == 0) { 434 if (do_hp_probe(dev) == 0) {
435 if (register_netdev(dev) == 0) { 435 dev_hp[found++] = dev;
436 dev_hp[found++] = dev; 436 continue;
437 continue;
438 }
439 cleanup_card(dev);
440 } 437 }
441 free_netdev(dev); 438 free_netdev(dev);
442 printk(KERN_WARNING "hp.c: No HP card found (i/o = 0x%x).\n", io[this_dev]); 439 printk(KERN_WARNING "hp.c: No HP card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/hp100.c b/drivers/net/hp100.c
index b3a898c5a585..cf0ac6fda1a1 100644
--- a/drivers/net/hp100.c
+++ b/drivers/net/hp100.c
@@ -106,6 +106,7 @@
106#include <linux/interrupt.h> 106#include <linux/interrupt.h>
107#include <linux/eisa.h> 107#include <linux/eisa.h>
108#include <linux/pci.h> 108#include <linux/pci.h>
109#include <linux/dma-mapping.h>
109#include <linux/spinlock.h> 110#include <linux/spinlock.h>
110#include <linux/netdevice.h> 111#include <linux/netdevice.h>
111#include <linux/etherdevice.h> 112#include <linux/etherdevice.h>
@@ -417,12 +418,7 @@ struct net_device * __init hp100_probe(int unit)
417 if (err) 418 if (err)
418 goto out; 419 goto out;
419 420
420 err = register_netdev(dev);
421 if (err)
422 goto out1;
423 return dev; 421 return dev;
424 out1:
425 release_region(dev->base_addr, HP100_REGION_SIZE);
426 out: 422 out:
427 free_netdev(dev); 423 free_netdev(dev);
428 return ERR_PTR(err); 424 return ERR_PTR(err);
@@ -562,7 +558,7 @@ static int __devinit hp100_probe1(struct net_device *dev, int ioaddr,
562 * Also, we can have EISA Busmaster cards (not tested), 558 * Also, we can have EISA Busmaster cards (not tested),
563 * so beware !!! - Jean II */ 559 * so beware !!! - Jean II */
564 if((bus == HP100_BUS_PCI) && 560 if((bus == HP100_BUS_PCI) &&
565 (pci_set_dma_mask(pci_dev, 0xffffffff))) { 561 (pci_set_dma_mask(pci_dev, DMA_32BIT_MASK))) {
566 /* Gracefully fallback to shared memory */ 562 /* Gracefully fallback to shared memory */
567 goto busmasterfail; 563 goto busmasterfail;
568 } 564 }
@@ -776,11 +772,22 @@ static int __devinit hp100_probe1(struct net_device *dev, int ioaddr,
776 printk("Warning! Link down.\n"); 772 printk("Warning! Link down.\n");
777 } 773 }
778 774
775 err = register_netdev(dev);
776 if (err)
777 goto out3;
778
779 return 0; 779 return 0;
780out3:
781 if (local_mode == 1)
782 pci_free_consistent(lp->pci_dev, MAX_RINGSIZE + 0x0f,
783 lp->page_vaddr_algn,
784 virt_to_whatever(dev, lp->page_vaddr_algn));
785 if (mem_ptr_virt)
786 iounmap(mem_ptr_virt);
780out2: 787out2:
781 release_region(ioaddr, HP100_REGION_SIZE); 788 release_region(ioaddr, HP100_REGION_SIZE);
782out1: 789out1:
783 return -ENODEV; 790 return err;
784} 791}
785 792
786/* This procedure puts the card into a stable init state */ 793/* This procedure puts the card into a stable init state */
@@ -2875,18 +2882,12 @@ static int __init hp100_eisa_probe (struct device *gendev)
2875 if (err) 2882 if (err)
2876 goto out1; 2883 goto out1;
2877 2884
2878 err = register_netdev(dev);
2879 if (err)
2880 goto out2;
2881
2882#ifdef HP100_DEBUG 2885#ifdef HP100_DEBUG
2883 printk("hp100: %s: EISA adapter found at 0x%x\n", dev->name, 2886 printk("hp100: %s: EISA adapter found at 0x%x\n", dev->name,
2884 dev->base_addr); 2887 dev->base_addr);
2885#endif 2888#endif
2886 gendev->driver_data = dev; 2889 gendev->driver_data = dev;
2887 return 0; 2890 return 0;
2888 out2:
2889 release_region(dev->base_addr, HP100_REGION_SIZE);
2890 out1: 2891 out1:
2891 free_netdev(dev); 2892 free_netdev(dev);
2892 return err; 2893 return err;
@@ -2951,17 +2952,12 @@ static int __devinit hp100_pci_probe (struct pci_dev *pdev,
2951 err = hp100_probe1(dev, ioaddr, HP100_BUS_PCI, pdev); 2952 err = hp100_probe1(dev, ioaddr, HP100_BUS_PCI, pdev);
2952 if (err) 2953 if (err)
2953 goto out1; 2954 goto out1;
2954 err = register_netdev(dev);
2955 if (err)
2956 goto out2;
2957 2955
2958#ifdef HP100_DEBUG 2956#ifdef HP100_DEBUG
2959 printk("hp100: %s: PCI adapter found at 0x%x\n", dev->name, ioaddr); 2957 printk("hp100: %s: PCI adapter found at 0x%x\n", dev->name, ioaddr);
2960#endif 2958#endif
2961 pci_set_drvdata(pdev, dev); 2959 pci_set_drvdata(pdev, dev);
2962 return 0; 2960 return 0;
2963 out2:
2964 release_region(dev->base_addr, HP100_REGION_SIZE);
2965 out1: 2961 out1:
2966 free_netdev(dev); 2962 free_netdev(dev);
2967 out0: 2963 out0:
@@ -3032,15 +3028,9 @@ static int __init hp100_isa_init(void)
3032 SET_MODULE_OWNER(dev); 3028 SET_MODULE_OWNER(dev);
3033 3029
3034 err = hp100_isa_probe(dev, hp100_port[i]); 3030 err = hp100_isa_probe(dev, hp100_port[i]);
3035 if (!err) { 3031 if (!err)
3036 err = register_netdev(dev); 3032 hp100_devlist[cards++] = dev;
3037 if (!err) 3033 else
3038 hp100_devlist[cards++] = dev;
3039 else
3040 release_region(dev->base_addr, HP100_REGION_SIZE);
3041 }
3042
3043 if (err)
3044 free_netdev(dev); 3034 free_netdev(dev);
3045 } 3035 }
3046 3036
diff --git a/drivers/net/isa-skeleton.c b/drivers/net/isa-skeleton.c
index 50bebb55e9ee..88ae8a04fabc 100644
--- a/drivers/net/isa-skeleton.c
+++ b/drivers/net/isa-skeleton.c
@@ -176,12 +176,7 @@ struct net_device * __init netcard_probe(int unit)
176 err = do_netcard_probe(dev); 176 err = do_netcard_probe(dev);
177 if (err) 177 if (err)
178 goto out; 178 goto out;
179 err = register_netdev(dev);
180 if (err)
181 goto out1;
182 return dev; 179 return dev;
183out1:
184 cleanup_card(dev);
185out: 180out:
186 free_netdev(dev); 181 free_netdev(dev);
187 return ERR_PTR(err); 182 return ERR_PTR(err);
@@ -316,7 +311,15 @@ static int __init netcard_probe1(struct net_device *dev, int ioaddr)
316 311
317 dev->tx_timeout = &net_tx_timeout; 312 dev->tx_timeout = &net_tx_timeout;
318 dev->watchdog_timeo = MY_TX_TIMEOUT; 313 dev->watchdog_timeo = MY_TX_TIMEOUT;
314
315 err = register_netdev(dev);
316 if (err)
317 goto out2;
319 return 0; 318 return 0;
319out2:
320#ifdef jumpered_dma
321 free_dma(dev->dma);
322#endif
320out1: 323out1:
321#ifdef jumpered_interrupts 324#ifdef jumpered_interrupts
322 free_irq(dev->irq, dev); 325 free_irq(dev->irq, dev);
@@ -691,11 +694,8 @@ int init_module(void)
691 dev->dma = dma; 694 dev->dma = dma;
692 dev->mem_start = mem; 695 dev->mem_start = mem;
693 if (do_netcard_probe(dev) == 0) { 696 if (do_netcard_probe(dev) == 0) {
694 if (register_netdev(dev) == 0) 697 this_device = dev;
695 this_device = dev; 698 return 0;
696 return 0;
697 }
698 cleanup_card(dev);
699 } 699 }
700 free_netdev(dev); 700 free_netdev(dev);
701 return -ENXIO; 701 return -ENXIO;
diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
index 35f6a7c271a2..097b90ccf575 100644
--- a/drivers/net/ixgb/ixgb_main.c
+++ b/drivers/net/ixgb/ixgb_main.c
@@ -47,7 +47,9 @@ char ixgb_driver_string[] = "Intel(R) PRO/10GbE Network Driver";
47#else 47#else
48#define DRIVERNAPI "-NAPI" 48#define DRIVERNAPI "-NAPI"
49#endif 49#endif
50char ixgb_driver_version[] = "1.0.95-k2"DRIVERNAPI; 50
51#define DRV_VERSION "1.0.95-k2"DRIVERNAPI
52char ixgb_driver_version[] = DRV_VERSION;
51char ixgb_copyright[] = "Copyright (c) 1999-2005 Intel Corporation."; 53char ixgb_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
52 54
53/* ixgb_pci_tbl - PCI Device ID Table 55/* ixgb_pci_tbl - PCI Device ID Table
@@ -140,6 +142,7 @@ static struct pci_driver ixgb_driver = {
140MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); 142MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
141MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver"); 143MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver");
142MODULE_LICENSE("GPL"); 144MODULE_LICENSE("GPL");
145MODULE_VERSION(DRV_VERSION);
143 146
144/* some defines for controlling descriptor fetches in h/w */ 147/* some defines for controlling descriptor fetches in h/w */
145#define RXDCTL_PTHRESH_DEFAULT 128 /* chip considers prefech below this */ 148#define RXDCTL_PTHRESH_DEFAULT 128 /* chip considers prefech below this */
diff --git a/drivers/net/lance.c b/drivers/net/lance.c
index dec557fb6a99..b4929beb33b2 100644
--- a/drivers/net/lance.c
+++ b/drivers/net/lance.c
@@ -356,11 +356,8 @@ int init_module(void)
356 dev->base_addr = io[this_dev]; 356 dev->base_addr = io[this_dev];
357 dev->dma = dma[this_dev]; 357 dev->dma = dma[this_dev];
358 if (do_lance_probe(dev) == 0) { 358 if (do_lance_probe(dev) == 0) {
359 if (register_netdev(dev) == 0) { 359 dev_lance[found++] = dev;
360 dev_lance[found++] = dev; 360 continue;
361 continue;
362 }
363 cleanup_card(dev);
364 } 361 }
365 free_netdev(dev); 362 free_netdev(dev);
366 break; 363 break;
@@ -448,12 +445,7 @@ struct net_device * __init lance_probe(int unit)
448 err = do_lance_probe(dev); 445 err = do_lance_probe(dev);
449 if (err) 446 if (err)
450 goto out; 447 goto out;
451 err = register_netdev(dev);
452 if (err)
453 goto out1;
454 return dev; 448 return dev;
455out1:
456 cleanup_card(dev);
457out: 449out:
458 free_netdev(dev); 450 free_netdev(dev);
459 return ERR_PTR(err); 451 return ERR_PTR(err);
@@ -724,6 +716,9 @@ static int __init lance_probe1(struct net_device *dev, int ioaddr, int irq, int
724 dev->tx_timeout = lance_tx_timeout; 716 dev->tx_timeout = lance_tx_timeout;
725 dev->watchdog_timeo = TX_TIMEOUT; 717 dev->watchdog_timeo = TX_TIMEOUT;
726 718
719 err = register_netdev(dev);
720 if (err)
721 goto out_dma;
727 return 0; 722 return 0;
728out_dma: 723out_dma:
729 if (dev->dma != 4) 724 if (dev->dma != 4)
@@ -867,7 +862,7 @@ lance_init_ring(struct net_device *dev, int gfp)
867 lp->rx_skbuff[i] = skb; 862 lp->rx_skbuff[i] = skb;
868 if (skb) { 863 if (skb) {
869 skb->dev = dev; 864 skb->dev = dev;
870 rx_buff = skb->tail; 865 rx_buff = skb->data;
871 } else 866 } else
872 rx_buff = kmalloc(PKT_BUF_SZ, GFP_DMA | gfp); 867 rx_buff = kmalloc(PKT_BUF_SZ, GFP_DMA | gfp);
873 if (rx_buff == NULL) 868 if (rx_buff == NULL)
diff --git a/drivers/net/lasi_82596.c b/drivers/net/lasi_82596.c
index 5e263fcba669..41bad07ac1ac 100644
--- a/drivers/net/lasi_82596.c
+++ b/drivers/net/lasi_82596.c
@@ -553,14 +553,14 @@ static inline void init_rx_bufs(struct net_device *dev)
553 if (skb == NULL) 553 if (skb == NULL)
554 panic("%s: alloc_skb() failed", __FILE__); 554 panic("%s: alloc_skb() failed", __FILE__);
555 skb_reserve(skb, 2); 555 skb_reserve(skb, 2);
556 dma_addr = dma_map_single(lp->dev, skb->tail,PKT_BUF_SZ, 556 dma_addr = dma_map_single(lp->dev, skb->data,PKT_BUF_SZ,
557 DMA_FROM_DEVICE); 557 DMA_FROM_DEVICE);
558 skb->dev = dev; 558 skb->dev = dev;
559 rbd->v_next = rbd+1; 559 rbd->v_next = rbd+1;
560 rbd->b_next = WSWAPrbd(virt_to_dma(lp,rbd+1)); 560 rbd->b_next = WSWAPrbd(virt_to_dma(lp,rbd+1));
561 rbd->b_addr = WSWAPrbd(virt_to_dma(lp,rbd)); 561 rbd->b_addr = WSWAPrbd(virt_to_dma(lp,rbd));
562 rbd->skb = skb; 562 rbd->skb = skb;
563 rbd->v_data = skb->tail; 563 rbd->v_data = skb->data;
564 rbd->b_data = WSWAPchar(dma_addr); 564 rbd->b_data = WSWAPchar(dma_addr);
565 rbd->size = PKT_BUF_SZ; 565 rbd->size = PKT_BUF_SZ;
566 } 566 }
@@ -783,8 +783,8 @@ static inline int i596_rx(struct net_device *dev)
783 rx_in_place = 1; 783 rx_in_place = 1;
784 rbd->skb = newskb; 784 rbd->skb = newskb;
785 newskb->dev = dev; 785 newskb->dev = dev;
786 dma_addr = dma_map_single(lp->dev, newskb->tail, PKT_BUF_SZ, DMA_FROM_DEVICE); 786 dma_addr = dma_map_single(lp->dev, newskb->data, PKT_BUF_SZ, DMA_FROM_DEVICE);
787 rbd->v_data = newskb->tail; 787 rbd->v_data = newskb->data;
788 rbd->b_data = WSWAPchar(dma_addr); 788 rbd->b_data = WSWAPchar(dma_addr);
789 CHECK_WBACK_INV(rbd, sizeof(struct i596_rbd)); 789 CHECK_WBACK_INV(rbd, sizeof(struct i596_rbd));
790 } 790 }
diff --git a/drivers/net/lne390.c b/drivers/net/lne390.c
index 179a97c0af69..27f0d8ac4c40 100644
--- a/drivers/net/lne390.c
+++ b/drivers/net/lne390.c
@@ -167,12 +167,7 @@ struct net_device * __init lne390_probe(int unit)
167 err = do_lne390_probe(dev); 167 err = do_lne390_probe(dev);
168 if (err) 168 if (err)
169 goto out; 169 goto out;
170 err = register_netdev(dev);
171 if (err)
172 goto out1;
173 return dev; 170 return dev;
174out1:
175 cleanup_card(dev);
176out: 171out:
177 free_netdev(dev); 172 free_netdev(dev);
178 return ERR_PTR(err); 173 return ERR_PTR(err);
@@ -296,7 +291,14 @@ static int __init lne390_probe1(struct net_device *dev, int ioaddr)
296 dev->poll_controller = ei_poll; 291 dev->poll_controller = ei_poll;
297#endif 292#endif
298 NS8390_init(dev, 0); 293 NS8390_init(dev, 0);
294
295 ret = register_netdev(dev);
296 if (ret)
297 goto unmap;
299 return 0; 298 return 0;
299unmap:
300 if (ei_status.reg0)
301 iounmap((void *)dev->mem_start);
300cleanup: 302cleanup:
301 free_irq(dev->irq, dev); 303 free_irq(dev->irq, dev);
302 return ret; 304 return ret;
@@ -426,11 +428,8 @@ int init_module(void)
426 dev->base_addr = io[this_dev]; 428 dev->base_addr = io[this_dev];
427 dev->mem_start = mem[this_dev]; 429 dev->mem_start = mem[this_dev];
428 if (do_lne390_probe(dev) == 0) { 430 if (do_lne390_probe(dev) == 0) {
429 if (register_netdev(dev) == 0) { 431 dev_lne[found++] = dev;
430 dev_lne[found++] = dev; 432 continue;
431 continue;
432 }
433 cleanup_card(dev);
434 } 433 }
435 free_netdev(dev); 434 free_netdev(dev);
436 printk(KERN_WARNING "lne390.c: No LNE390 card found (i/o = 0x%x).\n", io[this_dev]); 435 printk(KERN_WARNING "lne390.c: No LNE390 card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/myri_code.h b/drivers/net/myri_code.h
index 851eba8a3e00..e9c6e569d1f4 100644
--- a/drivers/net/myri_code.h
+++ b/drivers/net/myri_code.h
@@ -4775,1288 +4775,7 @@ static unsigned char lanai4_code[76256] __initdata = {
4775/* This is the LANai data */ 4775/* This is the LANai data */
4776 4776
4777static unsigned int lanai4_data_off = 0x94F0; /* half-word offset */ 4777static unsigned int lanai4_data_off = 0x94F0; /* half-word offset */
4778static unsigned char lanai4_data[20472] __initdata = { 4778static unsigned char lanai4_data[20472] __initdata;
47790x00,0x00,
47800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x01,
58900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60590x00,0x00, 0x00,0x00, 0x00,0x00, } ;
6060 4779
6061 4780
6062#ifdef SYMBOL_DEFINES_COMPILED 4781#ifdef SYMBOL_DEFINES_COMPILED
diff --git a/drivers/net/natsemi.c b/drivers/net/natsemi.c
index babb59e146ea..9d6d2548c2d3 100644
--- a/drivers/net/natsemi.c
+++ b/drivers/net/natsemi.c
@@ -1926,7 +1926,7 @@ static void refill_rx(struct net_device *dev)
1926 break; /* Better luck next round. */ 1926 break; /* Better luck next round. */
1927 skb->dev = dev; /* Mark as being used by this device. */ 1927 skb->dev = dev; /* Mark as being used by this device. */
1928 np->rx_dma[entry] = pci_map_single(np->pci_dev, 1928 np->rx_dma[entry] = pci_map_single(np->pci_dev,
1929 skb->tail, buflen, PCI_DMA_FROMDEVICE); 1929 skb->data, buflen, PCI_DMA_FROMDEVICE);
1930 np->rx_ring[entry].addr = cpu_to_le32(np->rx_dma[entry]); 1930 np->rx_ring[entry].addr = cpu_to_le32(np->rx_dma[entry]);
1931 } 1931 }
1932 np->rx_ring[entry].cmd_status = cpu_to_le32(np->rx_buf_sz); 1932 np->rx_ring[entry].cmd_status = cpu_to_le32(np->rx_buf_sz);
@@ -2280,7 +2280,7 @@ static void netdev_rx(struct net_device *dev)
2280 buflen, 2280 buflen,
2281 PCI_DMA_FROMDEVICE); 2281 PCI_DMA_FROMDEVICE);
2282 eth_copy_and_sum(skb, 2282 eth_copy_and_sum(skb,
2283 np->rx_skbuff[entry]->tail, pkt_len, 0); 2283 np->rx_skbuff[entry]->data, pkt_len, 0);
2284 skb_put(skb, pkt_len); 2284 skb_put(skb, pkt_len);
2285 pci_dma_sync_single_for_device(np->pci_dev, 2285 pci_dma_sync_single_for_device(np->pci_dev,
2286 np->rx_dma[entry], 2286 np->rx_dma[entry],
diff --git a/drivers/net/ne-h8300.c b/drivers/net/ne-h8300.c
index 84e291e24935..8f40368cf2e9 100644
--- a/drivers/net/ne-h8300.c
+++ b/drivers/net/ne-h8300.c
@@ -180,12 +180,7 @@ struct net_device * __init ne_probe(int unit)
180 err = do_ne_probe(dev); 180 err = do_ne_probe(dev);
181 if (err) 181 if (err)
182 goto out; 182 goto out;
183 err = register_netdev(dev);
184 if (err)
185 goto out1;
186 return dev; 183 return dev;
187out1:
188 cleanup_card(dev);
189out: 184out:
190 free_netdev(dev); 185 free_netdev(dev);
191 return ERR_PTR(err); 186 return ERR_PTR(err);
@@ -325,8 +320,13 @@ static int __init ne_probe1(struct net_device *dev, int ioaddr)
325 dev->poll_controller = ei_poll; 320 dev->poll_controller = ei_poll;
326#endif 321#endif
327 NS8390_init(dev, 0); 322 NS8390_init(dev, 0);
328 return 0;
329 323
324 ret = register_netdev(dev);
325 if (ret)
326 goto out_irq;
327 return 0;
328out_irq:
329 free_irq(dev->irq, dev);
330err_out: 330err_out:
331 release_region(ioaddr, NE_IO_EXTENT); 331 release_region(ioaddr, NE_IO_EXTENT);
332 return ret; 332 return ret;
@@ -633,11 +633,8 @@ int init_module(void)
633 err = init_reg_offset(dev, dev->base_addr); 633 err = init_reg_offset(dev, dev->base_addr);
634 if (!err) { 634 if (!err) {
635 if (do_ne_probe(dev) == 0) { 635 if (do_ne_probe(dev) == 0) {
636 if (register_netdev(dev) == 0) { 636 dev_ne[found++] = dev;
637 dev_ne[found++] = dev; 637 continue;
638 continue;
639 }
640 cleanup_card(dev);
641 } 638 }
642 } 639 }
643 free_netdev(dev); 640 free_netdev(dev);
diff --git a/drivers/net/ne.c b/drivers/net/ne.c
index 496433902ade..6c57096aa2e1 100644
--- a/drivers/net/ne.c
+++ b/drivers/net/ne.c
@@ -229,12 +229,7 @@ struct net_device * __init ne_probe(int unit)
229 err = do_ne_probe(dev); 229 err = do_ne_probe(dev);
230 if (err) 230 if (err)
231 goto out; 231 goto out;
232 err = register_netdev(dev);
233 if (err)
234 goto out1;
235 return dev; 232 return dev;
236out1:
237 cleanup_card(dev);
238out: 233out:
239 free_netdev(dev); 234 free_netdev(dev);
240 return ERR_PTR(err); 235 return ERR_PTR(err);
@@ -534,8 +529,14 @@ static int __init ne_probe1(struct net_device *dev, int ioaddr)
534 dev->poll_controller = ei_poll; 529 dev->poll_controller = ei_poll;
535#endif 530#endif
536 NS8390_init(dev, 0); 531 NS8390_init(dev, 0);
532
533 ret = register_netdev(dev);
534 if (ret)
535 goto out_irq;
537 return 0; 536 return 0;
538 537
538out_irq:
539 free_irq(dev->irq, dev);
539err_out: 540err_out:
540 release_region(ioaddr, NE_IO_EXTENT); 541 release_region(ioaddr, NE_IO_EXTENT);
541 return ret; 542 return ret;
@@ -826,11 +827,8 @@ int init_module(void)
826 dev->mem_end = bad[this_dev]; 827 dev->mem_end = bad[this_dev];
827 dev->base_addr = io[this_dev]; 828 dev->base_addr = io[this_dev];
828 if (do_ne_probe(dev) == 0) { 829 if (do_ne_probe(dev) == 0) {
829 if (register_netdev(dev) == 0) { 830 dev_ne[found++] = dev;
830 dev_ne[found++] = dev; 831 continue;
831 continue;
832 }
833 cleanup_card(dev);
834 } 832 }
835 free_netdev(dev); 833 free_netdev(dev);
836 if (found) 834 if (found)
diff --git a/drivers/net/ne2.c b/drivers/net/ne2.c
index 6ebef27dbfae..6d62ada85de6 100644
--- a/drivers/net/ne2.c
+++ b/drivers/net/ne2.c
@@ -301,12 +301,7 @@ struct net_device * __init ne2_probe(int unit)
301 err = do_ne2_probe(dev); 301 err = do_ne2_probe(dev);
302 if (err) 302 if (err)
303 goto out; 303 goto out;
304 err = register_netdev(dev);
305 if (err)
306 goto out1;
307 return dev; 304 return dev;
308out1:
309 cleanup_card(dev);
310out: 305out:
311 free_netdev(dev); 306 free_netdev(dev);
312 return ERR_PTR(err); 307 return ERR_PTR(err);
@@ -517,7 +512,14 @@ static int __init ne2_probe1(struct net_device *dev, int slot)
517 dev->poll_controller = ei_poll; 512 dev->poll_controller = ei_poll;
518#endif 513#endif
519 NS8390_init(dev, 0); 514 NS8390_init(dev, 0);
515
516 retval = register_netdev(dev);
517 if (retval)
518 goto out1;
520 return 0; 519 return 0;
520out1:
521 mca_set_adapter_procfn( ei_status.priv, NULL, NULL);
522 free_irq(dev->irq, dev);
521out: 523out:
522 release_region(base_addr, NE_IO_EXTENT); 524 release_region(base_addr, NE_IO_EXTENT);
523 return retval; 525 return retval;
@@ -798,11 +800,8 @@ int init_module(void)
798 dev->mem_end = bad[this_dev]; 800 dev->mem_end = bad[this_dev];
799 dev->base_addr = io[this_dev]; 801 dev->base_addr = io[this_dev];
800 if (do_ne2_probe(dev) == 0) { 802 if (do_ne2_probe(dev) == 0) {
801 if (register_netdev(dev) == 0) { 803 dev_ne[found++] = dev;
802 dev_ne[found++] = dev; 804 continue;
803 continue;
804 }
805 cleanup_card(dev);
806 } 805 }
807 free_netdev(dev); 806 free_netdev(dev);
808 break; 807 break;
diff --git a/drivers/net/ns83820.c b/drivers/net/ns83820.c
index c336b46bd332..e64df4d0800b 100644
--- a/drivers/net/ns83820.c
+++ b/drivers/net/ns83820.c
@@ -101,6 +101,7 @@
101#include <linux/moduleparam.h> 101#include <linux/moduleparam.h>
102#include <linux/types.h> 102#include <linux/types.h>
103#include <linux/pci.h> 103#include <linux/pci.h>
104#include <linux/dma-mapping.h>
104#include <linux/netdevice.h> 105#include <linux/netdevice.h>
105#include <linux/etherdevice.h> 106#include <linux/etherdevice.h>
106#include <linux/delay.h> 107#include <linux/delay.h>
@@ -573,7 +574,7 @@ static inline int ns83820_add_rx_skb(struct ns83820 *dev, struct sk_buff *skb)
573 574
574 dev->rx_info.next_empty = (next_empty + 1) % NR_RX_DESC; 575 dev->rx_info.next_empty = (next_empty + 1) % NR_RX_DESC;
575 cmdsts = REAL_RX_BUF_SIZE | CMDSTS_INTR; 576 cmdsts = REAL_RX_BUF_SIZE | CMDSTS_INTR;
576 buf = pci_map_single(dev->pci_dev, skb->tail, 577 buf = pci_map_single(dev->pci_dev, skb->data,
577 REAL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); 578 REAL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
578 build_rx_desc(dev, sg, 0, buf, cmdsts, 0); 579 build_rx_desc(dev, sg, 0, buf, cmdsts, 0);
579 /* update link of previous rx */ 580 /* update link of previous rx */
@@ -603,7 +604,7 @@ static inline int rx_refill(struct net_device *ndev, int gfp)
603 if (unlikely(!skb)) 604 if (unlikely(!skb))
604 break; 605 break;
605 606
606 res = (long)skb->tail & 0xf; 607 res = (long)skb->data & 0xf;
607 res = 0x10 - res; 608 res = 0x10 - res;
608 res &= 0xf; 609 res &= 0xf;
609 skb_reserve(skb, res); 610 skb_reserve(skb, res);
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index c6e8b25f9685..f0fc04bd37c4 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -1286,6 +1286,13 @@ static int el3_close(struct net_device *dev)
1286 return 0; 1286 return 0;
1287} 1287}
1288 1288
1289static struct pcmcia_device_id tc574_ids[] = {
1290 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0574),
1291 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0556, "3CCFEM556.cis"),
1292 PCMCIA_DEVICE_NULL,
1293};
1294MODULE_DEVICE_TABLE(pcmcia, tc574_ids);
1295
1289static struct pcmcia_driver tc574_driver = { 1296static struct pcmcia_driver tc574_driver = {
1290 .owner = THIS_MODULE, 1297 .owner = THIS_MODULE,
1291 .drv = { 1298 .drv = {
@@ -1293,6 +1300,7 @@ static struct pcmcia_driver tc574_driver = {
1293 }, 1300 },
1294 .attach = tc574_attach, 1301 .attach = tc574_attach,
1295 .detach = tc574_detach, 1302 .detach = tc574_detach,
1303 .id_table = tc574_ids,
1296}; 1304};
1297 1305
1298static int __init init_tc574(void) 1306static int __init init_tc574(void)
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
index 89abdda1d343..8fa1b5f0fb68 100644
--- a/drivers/net/pcmcia/3c589_cs.c
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -1057,6 +1057,17 @@ static int el3_close(struct net_device *dev)
1057 return 0; 1057 return 0;
1058} 1058}
1059 1059
1060static struct pcmcia_device_id tc589_ids[] = {
1061 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x0101, 0x0562),
1062 PCMCIA_MFC_DEVICE_PROD_ID1(0, "Motorola MARQUIS", 0xf03e4e77),
1063 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0589),
1064 PCMCIA_DEVICE_PROD_ID12("Farallon", "ENet", 0x58d93fc4, 0x992c2202),
1065 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0035, "3CXEM556.cis"),
1066 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x003d, "3CXEM556.cis"),
1067 PCMCIA_DEVICE_NULL,
1068};
1069MODULE_DEVICE_TABLE(pcmcia, tc589_ids);
1070
1060static struct pcmcia_driver tc589_driver = { 1071static struct pcmcia_driver tc589_driver = {
1061 .owner = THIS_MODULE, 1072 .owner = THIS_MODULE,
1062 .drv = { 1073 .drv = {
@@ -1064,6 +1075,7 @@ static struct pcmcia_driver tc589_driver = {
1064 }, 1075 },
1065 .attach = tc589_attach, 1076 .attach = tc589_attach,
1066 .detach = tc589_detach, 1077 .detach = tc589_detach,
1078 .id_table = tc589_ids,
1067}; 1079};
1068 1080
1069static int __init init_tc589(void) 1081static int __init init_tc589(void)
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
index 853b586e481a..23ce77b1d5b0 100644
--- a/drivers/net/pcmcia/axnet_cs.c
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -850,6 +850,34 @@ static void block_output(struct net_device *dev, int count,
850 outsw(nic_base + AXNET_DATAPORT, buf, count>>1); 850 outsw(nic_base + AXNET_DATAPORT, buf, count>>1);
851} 851}
852 852
853static struct pcmcia_device_id axnet_ids[] = {
854 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x016c, 0x0081),
855 PCMCIA_DEVICE_MANF_CARD(0x018a, 0x0301),
856 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0301),
857 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0303),
858 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0309),
859 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1106),
860 PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab),
861 PCMCIA_DEVICE_PROD_ID124("Fast Ethernet", "16-bit PC Card", "AX88190", 0xb4be14e3, 0x9a12eb6a, 0xab9be5ef),
862 PCMCIA_DEVICE_PROD_ID12("ASIX", "AX88190", 0x0959823b, 0xab9be5ef),
863 PCMCIA_DEVICE_PROD_ID12("Billionton", "LNA-100B", 0x552ab682, 0xbc3b87e1),
864 PCMCIA_DEVICE_PROD_ID12("CHEETAH ETHERCARD", "EN2228", 0x00fa7bc8, 0x00e990cc),
865 PCMCIA_DEVICE_PROD_ID12("CNet", "CNF301", 0xbc477dde, 0x78c5f40b),
866 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FEther PCC-TXD", 0x5261440f, 0x436768c5),
867 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FEtherII PCC-TXD", 0x5261440f, 0x730df72e),
868 PCMCIA_DEVICE_PROD_ID12("Dynalink", "L100C16", 0x55632fd5, 0x66bc2a90),
869 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100 V3)", 0x0733cc81, 0x232019a8),
870 PCMCIA_DEVICE_PROD_ID12("MELCO", "LPC3-TX", 0x481e0094, 0xf91af609),
871 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "100BASE", 0x281f1c5d, 0x7c2add04),
872 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FastEtherCard", 0x281f1c5d, 0x7ef26116),
873 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FEP501", 0x281f1c5d, 0x2e272058),
874 PCMCIA_DEVICE_PROD_ID14("Network Everywhere", "AX88190", 0x820a67b6, 0xab9be5ef),
875 /* this is not specific enough */
876 /* PCMCIA_DEVICE_MANF_CARD(0x021b, 0x0202), */
877 PCMCIA_DEVICE_NULL,
878};
879MODULE_DEVICE_TABLE(pcmcia, axnet_ids);
880
853static struct pcmcia_driver axnet_cs_driver = { 881static struct pcmcia_driver axnet_cs_driver = {
854 .owner = THIS_MODULE, 882 .owner = THIS_MODULE,
855 .drv = { 883 .drv = {
@@ -857,6 +885,7 @@ static struct pcmcia_driver axnet_cs_driver = {
857 }, 885 },
858 .attach = axnet_attach, 886 .attach = axnet_attach,
859 .detach = axnet_detach, 887 .detach = axnet_detach,
888 .id_table = axnet_ids,
860}; 889};
861 890
862static int __init init_axnet_cs(void) 891static int __init init_axnet_cs(void)
diff --git a/drivers/net/pcmcia/com20020_cs.c b/drivers/net/pcmcia/com20020_cs.c
index 4294e1e3f156..68d58cc58d31 100644
--- a/drivers/net/pcmcia/com20020_cs.c
+++ b/drivers/net/pcmcia/com20020_cs.c
@@ -483,7 +483,11 @@ static int com20020_event(event_t event, int priority,
483 return 0; 483 return 0;
484} /* com20020_event */ 484} /* com20020_event */
485 485
486 486static struct pcmcia_device_id com20020_ids[] = {
487 PCMCIA_DEVICE_PROD_ID12("Contemporary Control Systems, Inc.", "PCM20 Arcnet Adapter", 0x59991666, 0x95dfffaf),
488 PCMCIA_DEVICE_NULL
489};
490MODULE_DEVICE_TABLE(pcmcia, com20020_ids);
487 491
488static struct pcmcia_driver com20020_cs_driver = { 492static struct pcmcia_driver com20020_cs_driver = {
489 .owner = THIS_MODULE, 493 .owner = THIS_MODULE,
@@ -492,6 +496,7 @@ static struct pcmcia_driver com20020_cs_driver = {
492 }, 496 },
493 .attach = com20020_attach, 497 .attach = com20020_attach,
494 .detach = com20020_detach, 498 .detach = com20020_detach,
499 .id_table = com20020_ids,
495}; 500};
496 501
497static int __init init_com20020_cs(void) 502static int __init init_com20020_cs(void)
diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c
index 0424865e8094..917adbbf0b5b 100644
--- a/drivers/net/pcmcia/fmvj18x_cs.c
+++ b/drivers/net/pcmcia/fmvj18x_cs.c
@@ -435,7 +435,9 @@ static void fmvj18x_config(dev_link_t *link)
435 pcmcia_get_status(handle, &status); 435 pcmcia_get_status(handle, &status);
436 if (status.CardState & CS_EVENT_3VCARD) 436 if (status.CardState & CS_EVENT_3VCARD)
437 link->conf.Vcc = 33; /* inserted in 3.3V slot */ 437 link->conf.Vcc = 33; /* inserted in 3.3V slot */
438 } else if (le16_to_cpu(buf[1]) == PRODID_TDK_GN3410) { 438 } else if (le16_to_cpu(buf[1]) == PRODID_TDK_GN3410
439 || le16_to_cpu(buf[1]) == PRODID_TDK_NP9610
440 || le16_to_cpu(buf[1]) == PRODID_TDK_MN3200) {
439 /* MultiFunction Card */ 441 /* MultiFunction Card */
440 link->conf.ConfigBase = 0x800; 442 link->conf.ConfigBase = 0x800;
441 link->conf.ConfigIndex = 0x47; 443 link->conf.ConfigIndex = 0x47;
@@ -764,6 +766,31 @@ static int fmvj18x_event(event_t event, int priority,
764 return 0; 766 return 0;
765} /* fmvj18x_event */ 767} /* fmvj18x_event */
766 768
769static struct pcmcia_device_id fmvj18x_ids[] = {
770 PCMCIA_DEVICE_MANF_CARD(0x0004, 0x0004),
771 PCMCIA_DEVICE_PROD_ID12("EAGLE Technology", "NE200 ETHERNET LAN MBH10302 04", 0x528c88c4, 0x74f91e59),
772 PCMCIA_DEVICE_PROD_ID12("Eiger Labs,Inc", "EPX-10BT PC Card Ethernet 10BT", 0x53af556e, 0x877f9922),
773 PCMCIA_DEVICE_PROD_ID12("Eiger labs,Inc.", "EPX-10BT PC Card Ethernet 10BT", 0xf47e6c66, 0x877f9922),
774 PCMCIA_DEVICE_PROD_ID12("FUJITSU", "LAN Card(FMV-J182)", 0x6ee5a3d8, 0x5baf31db),
775 PCMCIA_DEVICE_PROD_ID12("FUJITSU", "MBH10308", 0x6ee5a3d8, 0x3f04875e),
776 PCMCIA_DEVICE_PROD_ID12("FUJITSU TOWA", "LA501", 0xb8451188, 0x12939ba2),
777 PCMCIA_DEVICE_PROD_ID12("HITACHI", "HT-4840-11", 0xf4f43949, 0x773910f4),
778 PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310B Ver1.0 ", 0x8cef4d3a, 0x075fc7b6),
779 PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310 Ver1.0 ", 0x8cef4d3a, 0xbccf43e6),
780 PCMCIA_DEVICE_PROD_ID12("RATOC System Inc.", "10BASE_T CARD R280", 0x85c10e17, 0xd9413666),
781 PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CD02x", 0x1eae9475, 0x8fa0ee70),
782 PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CF010", 0x1eae9475, 0x7683bc9a),
783 PCMCIA_DEVICE_PROD_ID1("CONTEC Co.,Ltd.", 0x58d8fee2),
784 PCMCIA_DEVICE_PROD_ID1("PCMCIA LAN MBH10304 ES", 0x2599f454),
785 PCMCIA_DEVICE_PROD_ID1("PCMCIA MBH10302", 0x8f4005da),
786 PCMCIA_DEVICE_PROD_ID1("UBKK,V2.0", 0x90888080),
787 PCMCIA_PFC_DEVICE_PROD_ID12(0, "TDK", "GlobalNetworker 3410/3412", 0x1eae9475, 0xd9a93bed),
788 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0d0a),
789 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0e0a),
790 PCMCIA_DEVICE_NULL,
791};
792MODULE_DEVICE_TABLE(pcmcia, fmvj18x_ids);
793
767static struct pcmcia_driver fmvj18x_cs_driver = { 794static struct pcmcia_driver fmvj18x_cs_driver = {
768 .owner = THIS_MODULE, 795 .owner = THIS_MODULE,
769 .drv = { 796 .drv = {
@@ -771,6 +798,7 @@ static struct pcmcia_driver fmvj18x_cs_driver = {
771 }, 798 },
772 .attach = fmvj18x_attach, 799 .attach = fmvj18x_attach,
773 .detach = fmvj18x_detach, 800 .detach = fmvj18x_detach,
801 .id_table = fmvj18x_ids,
774}; 802};
775 803
776static int __init init_fmvj18x_cs(void) 804static int __init init_fmvj18x_cs(void)
diff --git a/drivers/net/pcmcia/ibmtr_cs.c b/drivers/net/pcmcia/ibmtr_cs.c
index 3107ccfe8f3d..cf6d073ea558 100644
--- a/drivers/net/pcmcia/ibmtr_cs.c
+++ b/drivers/net/pcmcia/ibmtr_cs.c
@@ -119,9 +119,6 @@ static void ibmtr_detach(dev_link_t *);
119 119
120static dev_link_t *dev_list; 120static dev_link_t *dev_list;
121 121
122extern int ibmtr_probe_card(struct net_device *dev);
123extern irqreturn_t tok_interrupt (int irq, void *dev_id, struct pt_regs *regs);
124
125/*====================================================================*/ 122/*====================================================================*/
126 123
127typedef struct ibmtr_dev_t { 124typedef struct ibmtr_dev_t {
@@ -511,6 +508,13 @@ static void ibmtr_hw_setup(struct net_device *dev, u_int mmiobase)
511 return; 508 return;
512} 509}
513 510
511static struct pcmcia_device_id ibmtr_ids[] = {
512 PCMCIA_DEVICE_PROD_ID12("3Com", "TokenLink Velocity PC Card", 0x41240e5b, 0x82c3734e),
513 PCMCIA_DEVICE_PROD_ID12("IBM", "TOKEN RING", 0xb569a6e5, 0xbf8eed47),
514 PCMCIA_DEVICE_NULL,
515};
516MODULE_DEVICE_TABLE(pcmcia, ibmtr_ids);
517
514static struct pcmcia_driver ibmtr_cs_driver = { 518static struct pcmcia_driver ibmtr_cs_driver = {
515 .owner = THIS_MODULE, 519 .owner = THIS_MODULE,
516 .drv = { 520 .drv = {
@@ -518,6 +522,7 @@ static struct pcmcia_driver ibmtr_cs_driver = {
518 }, 522 },
519 .attach = ibmtr_attach, 523 .attach = ibmtr_attach,
520 .detach = ibmtr_detach, 524 .detach = ibmtr_detach,
525 .id_table = ibmtr_ids,
521}; 526};
522 527
523static int __init init_ibmtr_cs(void) 528static int __init init_ibmtr_cs(void)
diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c
index 4603807fcafb..b86e7253fbfc 100644
--- a/drivers/net/pcmcia/nmclan_cs.c
+++ b/drivers/net/pcmcia/nmclan_cs.c
@@ -1675,6 +1675,13 @@ static void set_multicast_list(struct net_device *dev)
1675 1675
1676} /* set_multicast_list */ 1676} /* set_multicast_list */
1677 1677
1678static struct pcmcia_device_id nmclan_ids[] = {
1679 PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "Ethernet", 0x085a850b, 0x00b2e941),
1680 PCMCIA_DEVICE_PROD_ID12("Portable Add-ons", "Ethernet", 0x0ebf1d60, 0x00b2e941),
1681 PCMCIA_DEVICE_NULL,
1682};
1683MODULE_DEVICE_TABLE(pcmcia, nmclan_ids);
1684
1678static struct pcmcia_driver nmclan_cs_driver = { 1685static struct pcmcia_driver nmclan_cs_driver = {
1679 .owner = THIS_MODULE, 1686 .owner = THIS_MODULE,
1680 .drv = { 1687 .drv = {
@@ -1682,6 +1689,7 @@ static struct pcmcia_driver nmclan_cs_driver = {
1682 }, 1689 },
1683 .attach = nmclan_attach, 1690 .attach = nmclan_attach,
1684 .detach = nmclan_detach, 1691 .detach = nmclan_detach,
1692 .id_table = nmclan_ids,
1685}; 1693};
1686 1694
1687static int __init init_nmclan_cs(void) 1695static int __init init_nmclan_cs(void)
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index 181b6ed55003..855a45d062b1 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -1155,11 +1155,13 @@ static int set_config(struct net_device *dev, struct ifmap *map)
1155static irqreturn_t ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs) 1155static irqreturn_t ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs)
1156{ 1156{
1157 struct net_device *dev = dev_id; 1157 struct net_device *dev = dev_id;
1158 pcnet_dev_t *info = PRIV(dev); 1158 pcnet_dev_t *info;
1159 irqreturn_t ret = ei_interrupt(irq, dev_id, regs); 1159 irqreturn_t ret = ei_interrupt(irq, dev_id, regs);
1160 1160
1161 if (ret == IRQ_HANDLED) 1161 if (ret == IRQ_HANDLED) {
1162 info = PRIV(dev);
1162 info->stale = 0; 1163 info->stale = 0;
1164 }
1163 return ret; 1165 return ret;
1164} 1166}
1165 1167
@@ -1350,7 +1352,7 @@ static void dma_block_input(struct net_device *dev, int count,
1350 if (count & 0x01) 1352 if (count & 0x01)
1351 buf[count-1] = inb(nic_base + PCNET_DATAPORT), xfer_count++; 1353 buf[count-1] = inb(nic_base + PCNET_DATAPORT), xfer_count++;
1352 1354
1353 /* This was for the ALPHA version only, but enough people have 1355 /* This was for the ALPHA version only, but enough people have been
1354 encountering problems that it is still here. */ 1356 encountering problems that it is still here. */
1355#ifdef PCMCIA_DEBUG 1357#ifdef PCMCIA_DEBUG
1356 if (ei_debug > 4) { /* DMA termination address check... */ 1358 if (ei_debug > 4) { /* DMA termination address check... */
@@ -1424,7 +1426,7 @@ static void dma_block_output(struct net_device *dev, int count,
1424 dma_start = jiffies; 1426 dma_start = jiffies;
1425 1427
1426#ifdef PCMCIA_DEBUG 1428#ifdef PCMCIA_DEBUG
1427 /* This was for the ALPHA version only, but enough people have 1429 /* This was for the ALPHA version only, but enough people have been
1428 encountering problems that it is still here. */ 1430 encountering problems that it is still here. */
1429 if (ei_debug > 4) { /* DMA termination address check... */ 1431 if (ei_debug > 4) { /* DMA termination address check... */
1430 int addr, tries = 20; 1432 int addr, tries = 20;
@@ -1635,6 +1637,208 @@ failed:
1635 1637
1636/*====================================================================*/ 1638/*====================================================================*/
1637 1639
1640static struct pcmcia_device_id pcnet_ids[] = {
1641 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0057, 0x0021),
1642 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0104, 0x000a),
1643 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0xea15),
1644 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0143, 0x3341),
1645 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0143, 0xc0ab),
1646 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x021b, 0x0101),
1647 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x08a1, 0xc0ab),
1648 PCMCIA_PFC_DEVICE_PROD_ID12(0, "AnyCom", "Fast Ethernet ", 0x578ba6e7, 0x02d92d1e),
1649 PCMCIA_PFC_DEVICE_PROD_ID12(0, "D-Link", "DME336T", 0x1a424a1c, 0xb23897ff),
1650 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Grey Cell", "GCS3000", 0x2a151fac, 0x48b932ae),
1651 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Linksys", "EtherFast 10&100 + 56K PC Card (PCMLM56)", 0x0733cc81, 0xb3765033),
1652 PCMCIA_PFC_DEVICE_PROD_ID12(0, "LINKSYS", "PCMLM336", 0xf7cb0b07, 0x7a821b58),
1653 PCMCIA_PFC_DEVICE_PROD_ID12(0, "PCMCIAs", "ComboCard", 0xdcfe12d3, 0xcd8906cc),
1654 PCMCIA_PFC_DEVICE_PROD_ID12(0, "PCMCIAs", "LanModem", 0xdcfe12d3, 0xc67c648f),
1655 PCMCIA_MFC_DEVICE_PROD_ID12(0, "IBM", "Home and Away 28.8 PC Card ", 0xb569a6e5, 0x5bd4ff2c),
1656 PCMCIA_MFC_DEVICE_PROD_ID12(0, "IBM", "Home and Away Credit Card Adapter", 0xb569a6e5, 0x4bdf15c3),
1657 PCMCIA_MFC_DEVICE_PROD_ID12(0, "IBM", "w95 Home and Away Credit Card ", 0xb569a6e5, 0xae911c15),
1658 PCMCIA_MFC_DEVICE_PROD_ID123(0, "APEX DATA", "MULTICARD", "ETHERNET-MODEM", 0x11c2da09, 0x7289dc5d, 0xaad95e1f),
1659 PCMCIA_MFC_DEVICE_PROD_ID2(0, "FAX/Modem/Ethernet Combo Card ", 0x1ed59302),
1660 PCMCIA_DEVICE_MANF_CARD(0x0057, 0x1004),
1661 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x000d),
1662 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0075),
1663 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0145),
1664 PCMCIA_DEVICE_MANF_CARD(0x0149, 0x0230),
1665 PCMCIA_DEVICE_MANF_CARD(0x0149, 0x4530),
1666/* PCMCIA_DEVICE_MANF_CARD(0x0149, 0xc1ab), conflict with axnet_cs */
1667 PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0110),
1668 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x2328),
1669 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x8041),
1670 PCMCIA_DEVICE_MANF_CARD(0x0213, 0x2452),
1671/* PCMCIA_DEVICE_MANF_CARD(0x021b, 0x0202), conflict with axnet_cs */
1672 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0300),
1673 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0307),
1674 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030a),
1675 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1103),
1676 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1121),
1677 PCMCIA_DEVICE_PROD_ID12("2408LAN", "Ethernet", 0x352fff7f, 0x00b2e941),
1678 PCMCIA_DEVICE_PROD_ID123("Cardwell", "PCMCIA", "ETHERNET", 0x9533672e, 0x281f1c5d, 0x3ff7175b),
1679 PCMCIA_DEVICE_PROD_ID123("CNet ", "CN30BC", "ETHERNET", 0x9fe55d3d, 0x85601198, 0x3ff7175b),
1680 PCMCIA_DEVICE_PROD_ID123("Digital", "Ethernet", "Adapter", 0x9999ab35, 0x00b2e941, 0x4b0d829e),
1681 PCMCIA_DEVICE_PROD_ID123("Edimax Technology Inc.", "PCMCIA", "Ethernet Card", 0x738a0019, 0x281f1c5d, 0x5e9d92c0),
1682 PCMCIA_DEVICE_PROD_ID123("EFA ", "EFA207", "ETHERNET", 0x3d294be4, 0xeb9aab6c, 0x3ff7175b),
1683 PCMCIA_DEVICE_PROD_ID123("I-O DATA", "PCLA", "ETHERNET", 0x1d55d7ec, 0xe4c64d34, 0x3ff7175b),
1684 PCMCIA_DEVICE_PROD_ID123("IO DATA", "PCLATE", "ETHERNET", 0x547e66dc, 0x6b260753, 0x3ff7175b),
1685 PCMCIA_DEVICE_PROD_ID123("KingMax Technology Inc.", "EN10-T2", "PCMCIA Ethernet Card", 0x932b7189, 0x699e4436, 0x6f6652e0),
1686 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "PCMCIA-ETHERNET-CARD", "UE2216", 0x281f1c5d, 0xd4cd2f20, 0xb87add82),
1687 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "PCMCIA-ETHERNET-CARD", "UE2620", 0x281f1c5d, 0xd4cd2f20, 0x7d3d83a8),
1688 PCMCIA_DEVICE_PROD_ID1("2412LAN", 0x67f236ab),
1689 PCMCIA_DEVICE_PROD_ID12("ACCTON", "EN2212", 0xdfc6b5b2, 0xcb112a11),
1690 PCMCIA_DEVICE_PROD_ID12("ACCTON", "EN2216-PCMCIA-ETHERNET", 0xdfc6b5b2, 0x5542bfff),
1691 PCMCIA_DEVICE_PROD_ID12("Allied Telesis, K.K.", "CentreCOM LA100-PCM-T V2 100/10M LAN PC Card", 0xbb7fbdd7, 0xcd91cc68),
1692 PCMCIA_DEVICE_PROD_ID12("Allied Telesis, K.K.", "CentreCOM LA-PCM", 0xbb7fbdd7, 0x5ba10d49),
1693 PCMCIA_DEVICE_PROD_ID12("Allied Telesis K.K.", "LA100-PCM V2", 0x36634a66, 0xc6d05997),
1694 PCMCIA_DEVICE_PROD_ID12("Allied Telesis, K.K.", "CentreCOM LA-PCM_V2", 0xbb7fBdd7, 0x28e299f8),
1695 PCMCIA_DEVICE_PROD_ID12("Allied Telesis K.K.", "LA-PCM V3", 0x36634a66, 0x62241d96),
1696 PCMCIA_DEVICE_PROD_ID12("AmbiCom", "AMB8010", 0x5070a7f9, 0x82f96e96),
1697 PCMCIA_DEVICE_PROD_ID12("AmbiCom", "AMB8610", 0x5070a7f9, 0x86741224),
1698 PCMCIA_DEVICE_PROD_ID12("AmbiCom Inc", "AMB8002", 0x93b15570, 0x75ec3efb),
1699 PCMCIA_DEVICE_PROD_ID12("AmbiCom Inc", "AMB8002T", 0x93b15570, 0x461c5247),
1700 PCMCIA_DEVICE_PROD_ID12("AmbiCom Inc", "AMB8010", 0x93b15570, 0x82f96e96),
1701 PCMCIA_DEVICE_PROD_ID12("AnyCom", "ECO Ethernet", 0x578ba6e7, 0x0a9888c1),
1702 PCMCIA_DEVICE_PROD_ID12("AnyCom", "ECO Ethernet 10/100", 0x578ba6e7, 0x939fedbd),
1703 PCMCIA_DEVICE_PROD_ID12("AROWANA", "PCMCIA Ethernet LAN Card", 0x313adbc8, 0x08d9f190),
1704 PCMCIA_DEVICE_PROD_ID12("ASANTE", "FriendlyNet PC Card", 0x3a7ade0f, 0x41c64504),
1705 PCMCIA_DEVICE_PROD_ID12("Billionton", "LNT-10TB", 0x552ab682, 0xeeb1ba6a),
1706 PCMCIA_DEVICE_PROD_ID12("CF", "10Base-Ethernet", 0x44ebf863, 0x93ae4d79),
1707 PCMCIA_DEVICE_PROD_ID12("CNet", "CN40BC Ethernet", 0xbc477dde, 0xfba775a7),
1708 PCMCIA_DEVICE_PROD_ID12("COMPU-SHACK", "BASEline PCMCIA 10 MBit Ethernetadapter", 0xfa2e424d, 0xe9190d8a),
1709 PCMCIA_DEVICE_PROD_ID12("COMPU-SHACK", "FASTline PCMCIA 10/100 Fast-Ethernet", 0xfa2e424d, 0x3953d9b9),
1710 PCMCIA_DEVICE_PROD_ID12("CONTEC", "C-NET(PC)C-10L", 0x21cab552, 0xf6f90722),
1711 PCMCIA_DEVICE_PROD_ID12("corega", "FEther PCC-TXF", 0x0a21501a, 0xa51564a2),
1712 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega EtherII PCC-T", 0x5261440f, 0xfa9d85bd),
1713 PCMCIA_DEVICE_PROD_ID12("Corega K.K.", "corega EtherII PCC-TD", 0xd4fdcbd8, 0xc49bd73d),
1714 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega Ether PCC-T", 0x5261440f, 0x6705fcaa),
1715 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FastEther PCC-TX", 0x5261440f, 0x485e85d9),
1716 PCMCIA_DEVICE_PROD_ID12("Corega,K.K.", "Ethernet LAN Card", 0x110d26d9, 0x9fd2f0a2),
1717 PCMCIA_DEVICE_PROD_ID12("corega,K.K.", "Ethernet LAN Card", 0x9791a90e, 0x9fd2f0a2),
1718 PCMCIA_DEVICE_PROD_ID12("CouplerlessPCMCIA", "100BASE", 0xee5af0ad, 0x7c2add04),
1719 PCMCIA_DEVICE_PROD_ID12("CyQ've", "ELA-010", 0x77008979, 0x9d8d445d),
1720 PCMCIA_DEVICE_PROD_ID12("CyQ've", "ELA-110E 10/100M LAN Card", 0x77008979, 0xfd184814),
1721 PCMCIA_DEVICE_PROD_ID12("DataTrek.", "NetCard ", 0x5cd66d9d, 0x84697ce0),
1722 PCMCIA_DEVICE_PROD_ID12("Dayna Communications, Inc.", "CommuniCard E", 0x0c629325, 0xb4e7dbaf),
1723 PCMCIA_DEVICE_PROD_ID12("Digicom", "Palladio LAN 10/100", 0x697403d8, 0xe160b995),
1724 PCMCIA_DEVICE_PROD_ID12("Digicom", "Palladio LAN 10/100 Dongless", 0x697403d8, 0xa6d3b233),
1725 PCMCIA_DEVICE_PROD_ID12("DIGITAL", "DEPCM-XX", 0x69616cb3, 0xe600e76e),
1726 PCMCIA_DEVICE_PROD_ID12("D-Link", "DE-650", 0x1a424a1c, 0xf28c8398),
1727 PCMCIA_DEVICE_PROD_ID12("D-Link", "DE-660", 0x1a424a1c, 0xd9a1d05b),
1728 PCMCIA_DEVICE_PROD_ID12("D-Link", "DFE-650", 0x1a424a1c, 0x0f0073f9),
1729 PCMCIA_DEVICE_PROD_ID12("Dual Speed", "10/100 PC Card", 0x725b842d, 0xf1efee84),
1730 PCMCIA_DEVICE_PROD_ID12("Dual Speed", "10/100 Port Attached PC Card", 0x725b842d, 0x2db1f8e9),
1731 PCMCIA_DEVICE_PROD_ID12("Dynalink", "L10BC", 0x55632fd5, 0xdc65f2b1),
1732 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L10BC", 0x6a26d1cf, 0xdc65f2b1),
1733 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L10C", 0x6a26d1cf, 0xc4f84efb),
1734 PCMCIA_DEVICE_PROD_ID12("E-CARD", "E-CARD", 0x6701da11, 0x6701da11),
1735 PCMCIA_DEVICE_PROD_ID12("EIGER Labs Inc.", "Ethernet 10BaseT card", 0x53c864c6, 0xedd059f6),
1736 PCMCIA_DEVICE_PROD_ID12("EIGER Labs Inc.", "Ethernet Combo card", 0x53c864c6, 0x929c486c),
1737 PCMCIA_DEVICE_PROD_ID12("Ethernet", "Adapter", 0x00b2e941, 0x4b0d829e),
1738 PCMCIA_DEVICE_PROD_ID12("Ethernet Adapter", "E2000 PCMCIA Ethernet", 0x96767301, 0x71fbbc61),
1739 PCMCIA_DEVICE_PROD_ID12("Ethernet PCMCIA adapter", "EP-210", 0x8dd86181, 0xf2b52517),
1740 PCMCIA_DEVICE_PROD_ID12("Fast Ethernet", "Adapter", 0xb4be14e3, 0x4b0d829e),
1741 PCMCIA_DEVICE_PROD_ID12("Grey Cell", "GCS2000", 0x2a151fac, 0xf00555cb),
1742 PCMCIA_DEVICE_PROD_ID12("Grey Cell", "GCS2220", 0x2a151fac, 0xc1b7e327),
1743 PCMCIA_DEVICE_PROD_ID12("GVC", "NIC-2000p", 0x76e171bd, 0x6eb1c947),
1744 PCMCIA_DEVICE_PROD_ID12("IBM Corp.", "Ethernet", 0xe3736c88, 0x00b2e941),
1745 PCMCIA_DEVICE_PROD_ID12("IC-CARD", "IC-CARD", 0x60cb09a6, 0x60cb09a6),
1746 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCETTX", 0x547e66dc, 0x6fc5459b),
1747 PCMCIA_DEVICE_PROD_ID12("iPort", "10/100 Ethernet Card", 0x56c538d2, 0x11b0ffc0),
1748 PCMCIA_DEVICE_PROD_ID12("KANSAI ELECTRIC CO.,LTD", "KLA-PCM/T", 0xb18dc3b4, 0xcc51a956),
1749 PCMCIA_DEVICE_PROD_ID12("KCI", "PE520 PCMCIA Ethernet Adapter", 0xa89b87d3, 0x1eb88e64),
1750 PCMCIA_DEVICE_PROD_ID12("KINGMAX", "EN10T2T", 0x7bcb459a, 0xa5c81fa5),
1751 PCMCIA_DEVICE_PROD_ID12("Kingston", "KNE-PC2", 0x1128e633, 0xce2a89b3),
1752 PCMCIA_DEVICE_PROD_ID12("Kingston Technology Corp.", "EtheRx PC Card Ethernet Adapter", 0x313c7be3, 0x0afb54a2),
1753 PCMCIA_DEVICE_PROD_ID12("Laneed", "LD-10/100CD", 0x1b7827b2, 0xcda71d1c),
1754 PCMCIA_DEVICE_PROD_ID12("Laneed", "LD-CDF", 0x1b7827b2, 0xfec71e40),
1755 PCMCIA_DEVICE_PROD_ID12("Laneed", "LD-CDL/T", 0x1b7827b2, 0x79fba4f7),
1756 PCMCIA_DEVICE_PROD_ID12("Laneed", "LD-CDS", 0x1b7827b2, 0x931afaab),
1757 PCMCIA_DEVICE_PROD_ID12("Linksys", "Combo PCMCIA EthernetCard (EC2T)", 0x0733cc81, 0x32ee8c78),
1758 PCMCIA_DEVICE_PROD_ID12("LINKSYS", "E-CARD", 0xf7cb0b07, 0x6701da11),
1759 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 Integrated PC Card (PCM100)", 0x0733cc81, 0x453c3f9d),
1760 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100)", 0x0733cc81, 0x66c5a389),
1761 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100 V2)", 0x0733cc81, 0x3a3b28e9),
1762 PCMCIA_DEVICE_PROD_ID12("Linksys", "HomeLink Phoneline ", 0x0733cc81, 0x5e07cfa0),
1763 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN100TX", 0x88fcdeda, 0x6d772737),
1764 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN20T", 0x88fcdeda, 0x81090922),
1765 PCMCIA_DEVICE_PROD_ID12("LONGSHINE", "PCMCIA Ethernet Card", 0xf866b0b0, 0x6f6652e0),
1766 PCMCIA_DEVICE_PROD_ID12("MACNICA", "ME1-JEIDA", 0x20841b68, 0xaf8a3578),
1767 PCMCIA_DEVICE_PROD_ID12("Macsense", "MPC-10", 0xd830297f, 0xd265c307),
1768 PCMCIA_DEVICE_PROD_ID12("Matsushita Electric Industrial Co.,LTD.", "CF-VEL211", 0x44445376, 0x8ded41d4),
1769 PCMCIA_DEVICE_PROD_ID12("MAXTECH", "PCN2000", 0x78d64bc0, 0xca0ca4b8),
1770 PCMCIA_DEVICE_PROD_ID12("MELCO", "LPC2-T", 0x481e0094, 0xa2eb0cf3),
1771 PCMCIA_DEVICE_PROD_ID12("MELCO", "LPC2-TX", 0x481e0094, 0x41a6916c),
1772 PCMCIA_DEVICE_PROD_ID12("Microcom C.E.", "Travel Card LAN 10/100", 0x4b91cec7, 0xe70220d6),
1773 PCMCIA_DEVICE_PROD_ID12("Microdyne", "NE4200", 0x2e6da59b, 0x0478e472),
1774 PCMCIA_DEVICE_PROD_ID12("MIDORI ELEC.", "LT-PCMT", 0x648d55c1, 0xbde526c7),
1775 PCMCIA_DEVICE_PROD_ID12("National Semiconductor", "InfoMover 4100", 0x36e1191f, 0x60c229b9),
1776 PCMCIA_DEVICE_PROD_ID12("National Semiconductor", "InfoMover NE4100", 0x36e1191f, 0xa6617ec8),
1777 PCMCIA_DEVICE_PROD_ID12("NEC", "PC-9801N-J12", 0x18df0ba0, 0xbc912d76),
1778 PCMCIA_DEVICE_PROD_ID12("NETGEAR", "FA410TX", 0x9aa79dc3, 0x60e5bc0e),
1779 PCMCIA_DEVICE_PROD_ID12("NETGEAR", "FA411", 0x9aa79dc3, 0x40fad875),
1780 PCMCIA_DEVICE_PROD_ID12("Network Everywhere", "Fast Ethernet 10/100 PC Card", 0x820a67b6, 0x31ed1a5f),
1781 PCMCIA_DEVICE_PROD_ID12("NextCom K.K.", "Next Hawk", 0xaedaec74, 0xad050ef1),
1782 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "10/100Mbps Ethernet Card", 0x281f1c5d, 0x6e41773b),
1783 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Ethernet", 0x281f1c5d, 0x00b2e941),
1784 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "ETHERNET", 0x281f1c5d, 0x3ff7175b),
1785 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Ethernet 10BaseT Card", 0x281f1c5d, 0x4de2f6c8),
1786 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Ethernet Card", 0x281f1c5d, 0x5e9d92c0),
1787 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Ethernet Combo card", 0x281f1c5d, 0x929c486c),
1788 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "ETHERNET V1.0", 0x281f1c5d, 0x4d8817c8),
1789 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FastEthernet", 0x281f1c5d, 0xfe871eeb),
1790 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast-Ethernet", 0x281f1c5d, 0x45f1f3b4),
1791 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FAST ETHERNET CARD", 0x281f1c5d, 0xec5dbca7),
1792 PCMCIA_DEVICE_PROD_ID12("PCMCIA LAN", "Ethernet", 0x7500e246, 0x00b2e941),
1793 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "LNT-10TN", 0x281f1c5d, 0xe707f641),
1794 PCMCIA_DEVICE_PROD_ID12("PCMCIAs", "ComboCard", 0xdcfe12d3, 0xcd8906cc),
1795 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "UE2212", 0x281f1c5d, 0xbf17199b),
1796 PCMCIA_DEVICE_PROD_ID12("PCMCIA", " Ethernet NE2000 Compatible", 0x281f1c5d, 0x42d5d7e1),
1797 PCMCIA_DEVICE_PROD_ID12("PRETEC", "Ethernet CompactLAN 10baseT 3.3V", 0xebf91155, 0x30074c80),
1798 PCMCIA_DEVICE_PROD_ID12("PRETEC", "Ethernet CompactLAN 10BaseT 3.3V", 0xebf91155, 0x7f5a4f50),
1799 PCMCIA_DEVICE_PROD_ID12("Psion Dacom", "Gold Card Ethernet", 0xf5f025c2, 0x3a30e110),
1800 PCMCIA_DEVICE_PROD_ID12("=RELIA==", "Ethernet", 0xcdd0644a, 0x00b2e941),
1801 PCMCIA_DEVICE_PROD_ID12("RP", "1625B Ethernet NE2000 Compatible", 0xe3e66e22, 0xb96150df),
1802 PCMCIA_DEVICE_PROD_ID12("RPTI", "EP400 Ethernet NE2000 Compatible", 0xdc6f88fd, 0x4a7e2ae0),
1803 PCMCIA_DEVICE_PROD_ID12("RPTI", "EP401 Ethernet NE2000 Compatible", 0xdc6f88fd, 0x4bcbd7fd),
1804 PCMCIA_DEVICE_PROD_ID12("RPTI LTD.", "EP400", 0xc53ac515, 0x81e39388),
1805 PCMCIA_DEVICE_PROD_ID12("SCM", "Ethernet Combo card", 0xbdc3b102, 0x929c486c),
1806 PCMCIA_DEVICE_PROD_ID12("Seiko Epson Corp.", "Ethernet", 0x09928730, 0x00b2e941),
1807 PCMCIA_DEVICE_PROD_ID12("SMC", "EZCard-10-PCMCIA", 0xc4f8b18b, 0xfb21d265),
1808 PCMCIA_DEVICE_PROD_ID12("Socket Communications Inc", "Socket EA PCMCIA LAN Adapter Revision D", 0xc70a4760, 0x2ade483e),
1809 PCMCIA_DEVICE_PROD_ID12("Socket Communications Inc", "Socket EA PCMCIA LAN Adapter Revision E", 0xc70a4760, 0x5dd978a8),
1810 PCMCIA_DEVICE_PROD_ID12("TDK", "LAK-CD031 for PCMCIA", 0x1eae9475, 0x0ed386fa),
1811 PCMCIA_DEVICE_PROD_ID12("Telecom Device K.K.", "SuperSocket RE450T", 0x466b05f0, 0x8b74bc4f),
1812 PCMCIA_DEVICE_PROD_ID12("Telecom Device K.K.", "SuperSocket RE550T", 0x466b05f0, 0x33c8db2a),
1813 PCMCIA_DEVICE_PROD_ID13("Hypertec", "EP401", 0x8787bec7, 0xf6e4a31e),
1814 PCMCIA_DEVICE_PROD_ID13("KingMax Technology Inc.", "Ethernet Card", 0x932b7189, 0x5e9d92c0),
1815 PCMCIA_DEVICE_PROD_ID13("LONGSHINE", "EP401", 0xf866b0b0, 0xf6e4a31e),
1816 PCMCIA_DEVICE_PROD_ID13("Xircom", "CFE-10", 0x2e3ee845, 0x22a49f89),
1817 PCMCIA_DEVICE_PROD_ID1("CyQ've 10 Base-T LAN CARD", 0x94faf360),
1818 PCMCIA_DEVICE_PROD_ID1("EP-210 PCMCIA LAN CARD.", 0x8850b4de),
1819 PCMCIA_DEVICE_PROD_ID1("ETHER-C16", 0x06a8514f),
1820 PCMCIA_DEVICE_PROD_ID1("IC-CARD", 0x60cb09a6),
1821 PCMCIA_DEVICE_PROD_ID1("NE2000 Compatible", 0x75b8ad5a),
1822 PCMCIA_DEVICE_PROD_ID2("EN-6200P2", 0xa996d078),
1823 /* too generic! */
1824 /* PCMCIA_DEVICE_PROD_ID12("PCMCIA", "10/100 Ethernet Card", 0x281f1c5d, 0x11b0ffc0), */
1825 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "PCMCIA", "EN2218-LAN/MODEM", 0x281f1c5d, 0x570f348e, "PCMLM28.cis"),
1826 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "PCMCIA", "UE2218-LAN/MODEM", 0x281f1c5d, 0x6fdcacee, "PCMLM28.cis"),
1827 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "Psion Dacom", "Gold Card V34 Ethernet", 0xf5f025c2, 0x338e8155, "PCMLM28.cis"),
1828 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "Psion Dacom", "Gold Card V34 Ethernet GSM", 0xf5f025c2, 0x4ae85d35, "PCMLM28.cis"),
1829 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "LINKSYS", "PCMLM28", 0xf7cb0b07, 0x66881874, "PCMLM28.cis"),
1830 PCMCIA_MFC_DEVICE_CIS_PROD_ID12(0, "DAYNA COMMUNICATIONS", "LAN AND MODEM MULTIFUNCTION", 0x8fdf8f89, 0xdd5ed9e8, "DP83903.cis"),
1831 PCMCIA_MFC_DEVICE_CIS_PROD_ID4(0, "NSC MF LAN/Modem", 0x58fc6056, "DP83903.cis"),
1832 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0175, 0x0000, "DP83903.cis"),
1833 PCMCIA_DEVICE_CIS_MANF_CARD(0xc00f, 0x0002, "LA-PCM.cis"),
1834 PCMCIA_DEVICE_CIS_PROD_ID12("KTI", "PE520 PLUS", 0xad180345, 0x9d58d392, "PE520.cis"),
1835 PCMCIA_DEVICE_CIS_PROD_ID12("NDC", "Ethernet", 0x01c43ae1, 0x00b2e941, "NE2K.cis"),
1836 PCMCIA_DEVICE_CIS_PROD_ID12("PMX ", "PE-200", 0x34f3f1c8, 0x10b59f8c, "PE-200.cis"),
1837 PCMCIA_DEVICE_CIS_PROD_ID12("TAMARACK", "Ethernet", 0xcf434fba, 0x00b2e941, "tamarack.cis"),
1838 PCMCIA_DEVICE_NULL
1839};
1840MODULE_DEVICE_TABLE(pcmcia, pcnet_ids);
1841
1638static struct pcmcia_driver pcnet_driver = { 1842static struct pcmcia_driver pcnet_driver = {
1639 .drv = { 1843 .drv = {
1640 .name = "pcnet_cs", 1844 .name = "pcnet_cs",
@@ -1642,6 +1846,7 @@ static struct pcmcia_driver pcnet_driver = {
1642 .attach = pcnet_attach, 1846 .attach = pcnet_attach,
1643 .detach = pcnet_detach, 1847 .detach = pcnet_detach,
1644 .owner = THIS_MODULE, 1848 .owner = THIS_MODULE,
1849 .id_table = pcnet_ids,
1645}; 1850};
1646 1851
1647static int __init init_pcnet_cs(void) 1852static int __init init_pcnet_cs(void)
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index 85a152173148..bc01c88c6709 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -127,6 +127,12 @@ struct smc_private {
127 int rx_ovrn; 127 int rx_ovrn;
128}; 128};
129 129
130struct smc_cfg_mem {
131 tuple_t tuple;
132 cisparse_t parse;
133 u_char buf[255];
134};
135
130/* Special definitions for Megahertz multifunction cards */ 136/* Special definitions for Megahertz multifunction cards */
131#define MEGAHERTZ_ISR 0x0380 137#define MEGAHERTZ_ISR 0x0380
132 138
@@ -498,14 +504,24 @@ static int mhz_mfc_config(dev_link_t *link)
498{ 504{
499 struct net_device *dev = link->priv; 505 struct net_device *dev = link->priv;
500 struct smc_private *smc = netdev_priv(dev); 506 struct smc_private *smc = netdev_priv(dev);
501 tuple_t tuple; 507 struct smc_cfg_mem *cfg_mem;
502 cisparse_t parse; 508 tuple_t *tuple;
503 u_char buf[255]; 509 cisparse_t *parse;
504 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 510 cistpl_cftable_entry_t *cf;
511 u_char *buf;
505 win_req_t req; 512 win_req_t req;
506 memreq_t mem; 513 memreq_t mem;
507 int i, k; 514 int i, k;
508 515
516 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
517 if (!cfg_mem)
518 return CS_OUT_OF_RESOURCE;
519
520 tuple = &cfg_mem->tuple;
521 parse = &cfg_mem->parse;
522 cf = &parse->cftable_entry;
523 buf = cfg_mem->buf;
524
509 link->conf.Attributes |= CONF_ENABLE_SPKR; 525 link->conf.Attributes |= CONF_ENABLE_SPKR;
510 link->conf.Status = CCSR_AUDIO_ENA; 526 link->conf.Status = CCSR_AUDIO_ENA;
511 link->irq.Attributes = 527 link->irq.Attributes =
@@ -514,12 +530,12 @@ static int mhz_mfc_config(dev_link_t *link)
514 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 530 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
515 link->io.NumPorts2 = 8; 531 link->io.NumPorts2 = 8;
516 532
517 tuple.Attributes = tuple.TupleOffset = 0; 533 tuple->Attributes = tuple->TupleOffset = 0;
518 tuple.TupleData = (cisdata_t *)buf; 534 tuple->TupleData = (cisdata_t *)buf;
519 tuple.TupleDataMax = sizeof(buf); 535 tuple->TupleDataMax = 255;
520 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 536 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
521 537
522 i = first_tuple(link->handle, &tuple, &parse); 538 i = first_tuple(link->handle, tuple, parse);
523 /* The Megahertz combo cards have modem-like CIS entries, so 539 /* The Megahertz combo cards have modem-like CIS entries, so
524 we have to explicitly try a bunch of port combinations. */ 540 we have to explicitly try a bunch of port combinations. */
525 while (i == CS_SUCCESS) { 541 while (i == CS_SUCCESS) {
@@ -532,10 +548,10 @@ static int mhz_mfc_config(dev_link_t *link)
532 if (i == CS_SUCCESS) break; 548 if (i == CS_SUCCESS) break;
533 } 549 }
534 if (i == CS_SUCCESS) break; 550 if (i == CS_SUCCESS) break;
535 i = next_tuple(link->handle, &tuple, &parse); 551 i = next_tuple(link->handle, tuple, parse);
536 } 552 }
537 if (i != CS_SUCCESS) 553 if (i != CS_SUCCESS)
538 return i; 554 goto free_cfg_mem;
539 dev->base_addr = link->io.BasePort1; 555 dev->base_addr = link->io.BasePort1;
540 556
541 /* Allocate a memory window, for accessing the ISR */ 557 /* Allocate a memory window, for accessing the ISR */
@@ -544,7 +560,7 @@ static int mhz_mfc_config(dev_link_t *link)
544 req.AccessSpeed = 0; 560 req.AccessSpeed = 0;
545 i = pcmcia_request_window(&link->handle, &req, &link->win); 561 i = pcmcia_request_window(&link->handle, &req, &link->win);
546 if (i != CS_SUCCESS) 562 if (i != CS_SUCCESS)
547 return i; 563 goto free_cfg_mem;
548 smc->base = ioremap(req.Base, req.Size); 564 smc->base = ioremap(req.Base, req.Size);
549 mem.CardOffset = mem.Page = 0; 565 mem.CardOffset = mem.Page = 0;
550 if (smc->manfid == MANFID_MOTOROLA) 566 if (smc->manfid == MANFID_MOTOROLA)
@@ -556,6 +572,8 @@ static int mhz_mfc_config(dev_link_t *link)
556 && (smc->cardid == PRODID_MEGAHERTZ_EM3288)) 572 && (smc->cardid == PRODID_MEGAHERTZ_EM3288))
557 mhz_3288_power(link); 573 mhz_3288_power(link);
558 574
575free_cfg_mem:
576 kfree(cfg_mem);
559 return i; 577 return i;
560} 578}
561 579
@@ -563,39 +581,61 @@ static int mhz_setup(dev_link_t *link)
563{ 581{
564 client_handle_t handle = link->handle; 582 client_handle_t handle = link->handle;
565 struct net_device *dev = link->priv; 583 struct net_device *dev = link->priv;
566 tuple_t tuple; 584 struct smc_cfg_mem *cfg_mem;
567 cisparse_t parse; 585 tuple_t *tuple;
568 u_char buf[255], *station_addr; 586 cisparse_t *parse;
587 u_char *buf, *station_addr;
588 int rc;
589
590 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
591 if (!cfg_mem)
592 return -1;
593
594 tuple = &cfg_mem->tuple;
595 parse = &cfg_mem->parse;
596 buf = cfg_mem->buf;
569 597
570 tuple.Attributes = tuple.TupleOffset = 0; 598 tuple->Attributes = tuple->TupleOffset = 0;
571 tuple.TupleData = buf; 599 tuple->TupleData = (cisdata_t *)buf;
572 tuple.TupleDataMax = sizeof(buf); 600 tuple->TupleDataMax = 255;
573 601
574 /* Read the station address from the CIS. It is stored as the last 602 /* Read the station address from the CIS. It is stored as the last
575 (fourth) string in the Version 1 Version/ID tuple. */ 603 (fourth) string in the Version 1 Version/ID tuple. */
576 tuple.DesiredTuple = CISTPL_VERS_1; 604 tuple->DesiredTuple = CISTPL_VERS_1;
577 if (first_tuple(handle, &tuple, &parse) != CS_SUCCESS) 605 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
578 return -1; 606 rc = -1;
607 goto free_cfg_mem;
608 }
579 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */ 609 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
580 if (next_tuple(handle, &tuple, &parse) != CS_SUCCESS) 610 if (next_tuple(handle, tuple, parse) != CS_SUCCESS)
581 first_tuple(handle, &tuple, &parse); 611 first_tuple(handle, tuple, parse);
582 if (parse.version_1.ns > 3) { 612 if (parse->version_1.ns > 3) {
583 station_addr = parse.version_1.str + parse.version_1.ofs[3]; 613 station_addr = parse->version_1.str + parse->version_1.ofs[3];
584 if (cvt_ascii_address(dev, station_addr) == 0) 614 if (cvt_ascii_address(dev, station_addr) == 0) {
585 return 0; 615 rc = 0;
616 goto free_cfg_mem;
617 }
586 } 618 }
587 619
588 /* Another possibility: for the EM3288, in a special tuple */ 620 /* Another possibility: for the EM3288, in a special tuple */
589 tuple.DesiredTuple = 0x81; 621 tuple->DesiredTuple = 0x81;
590 if (pcmcia_get_first_tuple(handle, &tuple) != CS_SUCCESS) 622 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) {
591 return -1; 623 rc = -1;
592 if (pcmcia_get_tuple_data(handle, &tuple) != CS_SUCCESS) 624 goto free_cfg_mem;
593 return -1; 625 }
626 if (pcmcia_get_tuple_data(handle, tuple) != CS_SUCCESS) {
627 rc = -1;
628 goto free_cfg_mem;
629 }
594 buf[12] = '\0'; 630 buf[12] = '\0';
595 if (cvt_ascii_address(dev, buf) == 0) 631 if (cvt_ascii_address(dev, buf) == 0) {
596 return 0; 632 rc = 0;
597 633 goto free_cfg_mem;
598 return -1; 634 }
635 rc = -1;
636free_cfg_mem:
637 kfree(cfg_mem);
638 return rc;
599} 639}
600 640
601/*====================================================================== 641/*======================================================================
@@ -665,19 +705,29 @@ static int mot_setup(dev_link_t *link)
665static int smc_config(dev_link_t *link) 705static int smc_config(dev_link_t *link)
666{ 706{
667 struct net_device *dev = link->priv; 707 struct net_device *dev = link->priv;
668 tuple_t tuple; 708 struct smc_cfg_mem *cfg_mem;
669 cisparse_t parse; 709 tuple_t *tuple;
670 u_char buf[255]; 710 cisparse_t *parse;
671 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 711 cistpl_cftable_entry_t *cf;
712 u_char *buf;
672 int i; 713 int i;
673 714
674 tuple.Attributes = tuple.TupleOffset = 0; 715 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
675 tuple.TupleData = (cisdata_t *)buf; 716 if (!cfg_mem)
676 tuple.TupleDataMax = sizeof(buf); 717 return CS_OUT_OF_RESOURCE;
677 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 718
719 tuple = &cfg_mem->tuple;
720 parse = &cfg_mem->parse;
721 cf = &parse->cftable_entry;
722 buf = cfg_mem->buf;
723
724 tuple->Attributes = tuple->TupleOffset = 0;
725 tuple->TupleData = (cisdata_t *)buf;
726 tuple->TupleDataMax = 255;
727 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
678 728
679 link->io.NumPorts1 = 16; 729 link->io.NumPorts1 = 16;
680 i = first_tuple(link->handle, &tuple, &parse); 730 i = first_tuple(link->handle, tuple, parse);
681 while (i != CS_NO_MORE_ITEMS) { 731 while (i != CS_NO_MORE_ITEMS) {
682 if (i == CS_SUCCESS) { 732 if (i == CS_SUCCESS) {
683 link->conf.ConfigIndex = cf->index; 733 link->conf.ConfigIndex = cf->index;
@@ -686,10 +736,12 @@ static int smc_config(dev_link_t *link)
686 i = pcmcia_request_io(link->handle, &link->io); 736 i = pcmcia_request_io(link->handle, &link->io);
687 if (i == CS_SUCCESS) break; 737 if (i == CS_SUCCESS) break;
688 } 738 }
689 i = next_tuple(link->handle, &tuple, &parse); 739 i = next_tuple(link->handle, tuple, parse);
690 } 740 }
691 if (i == CS_SUCCESS) 741 if (i == CS_SUCCESS)
692 dev->base_addr = link->io.BasePort1; 742 dev->base_addr = link->io.BasePort1;
743
744 kfree(cfg_mem);
693 return i; 745 return i;
694} 746}
695 747
@@ -697,41 +749,58 @@ static int smc_setup(dev_link_t *link)
697{ 749{
698 client_handle_t handle = link->handle; 750 client_handle_t handle = link->handle;
699 struct net_device *dev = link->priv; 751 struct net_device *dev = link->priv;
700 tuple_t tuple; 752 struct smc_cfg_mem *cfg_mem;
701 cisparse_t parse; 753 tuple_t *tuple;
754 cisparse_t *parse;
702 cistpl_lan_node_id_t *node_id; 755 cistpl_lan_node_id_t *node_id;
703 u_char buf[255], *station_addr; 756 u_char *buf, *station_addr;
704 int i; 757 int i, rc;
758
759 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
760 if (!cfg_mem)
761 return CS_OUT_OF_RESOURCE;
705 762
706 tuple.Attributes = tuple.TupleOffset = 0; 763 tuple = &cfg_mem->tuple;
707 tuple.TupleData = buf; 764 parse = &cfg_mem->parse;
708 tuple.TupleDataMax = sizeof(buf); 765 buf = cfg_mem->buf;
766
767 tuple->Attributes = tuple->TupleOffset = 0;
768 tuple->TupleData = (cisdata_t *)buf;
769 tuple->TupleDataMax = 255;
709 770
710 /* Check for a LAN function extension tuple */ 771 /* Check for a LAN function extension tuple */
711 tuple.DesiredTuple = CISTPL_FUNCE; 772 tuple->DesiredTuple = CISTPL_FUNCE;
712 i = first_tuple(handle, &tuple, &parse); 773 i = first_tuple(handle, tuple, parse);
713 while (i == CS_SUCCESS) { 774 while (i == CS_SUCCESS) {
714 if (parse.funce.type == CISTPL_FUNCE_LAN_NODE_ID) 775 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID)
715 break; 776 break;
716 i = next_tuple(handle, &tuple, &parse); 777 i = next_tuple(handle, tuple, parse);
717 } 778 }
718 if (i == CS_SUCCESS) { 779 if (i == CS_SUCCESS) {
719 node_id = (cistpl_lan_node_id_t *)parse.funce.data; 780 node_id = (cistpl_lan_node_id_t *)parse->funce.data;
720 if (node_id->nb == 6) { 781 if (node_id->nb == 6) {
721 for (i = 0; i < 6; i++) 782 for (i = 0; i < 6; i++)
722 dev->dev_addr[i] = node_id->id[i]; 783 dev->dev_addr[i] = node_id->id[i];
723 return 0; 784 rc = 0;
785 goto free_cfg_mem;
724 } 786 }
725 } 787 }
726 /* Try the third string in the Version 1 Version/ID tuple. */ 788 /* Try the third string in the Version 1 Version/ID tuple. */
727 tuple.DesiredTuple = CISTPL_VERS_1; 789 tuple->DesiredTuple = CISTPL_VERS_1;
728 if (first_tuple(handle, &tuple, &parse) != CS_SUCCESS) 790 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
729 return -1; 791 rc = -1;
730 station_addr = parse.version_1.str + parse.version_1.ofs[2]; 792 goto free_cfg_mem;
731 if (cvt_ascii_address(dev, station_addr) == 0) 793 }
732 return 0; 794 station_addr = parse->version_1.str + parse->version_1.ofs[2];
795 if (cvt_ascii_address(dev, station_addr) == 0) {
796 rc = 0;
797 goto free_cfg_mem;
798 }
733 799
734 return -1; 800 rc = -1;
801free_cfg_mem:
802 kfree(cfg_mem);
803 return rc;
735} 804}
736 805
737/*====================================================================*/ 806/*====================================================================*/
@@ -773,26 +842,36 @@ static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
773{ 842{
774 client_handle_t handle = link->handle; 843 client_handle_t handle = link->handle;
775 struct net_device *dev = link->priv; 844 struct net_device *dev = link->priv;
776 tuple_t tuple; 845 struct smc_cfg_mem *cfg_mem;
777 u_char buf[255]; 846 tuple_t *tuple;
778 int i; 847 u_char *buf;
848 int i, rc;
849
850 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
851 if (!cfg_mem)
852 return -1;
853
854 tuple = &cfg_mem->tuple;
855 buf = cfg_mem->buf;
779 856
780 tuple.Attributes = TUPLE_RETURN_COMMON; 857 tuple->Attributes = TUPLE_RETURN_COMMON;
781 tuple.TupleData = buf; 858 tuple->TupleData = (cisdata_t *)buf;
782 tuple.TupleDataMax = sizeof(buf); 859 tuple->TupleDataMax = 255;
783 tuple.TupleOffset = 0; 860 tuple->TupleOffset = 0;
784 861
785 /* Read the station address from tuple 0x90, subtuple 0x04 */ 862 /* Read the station address from tuple 0x90, subtuple 0x04 */
786 tuple.DesiredTuple = 0x90; 863 tuple->DesiredTuple = 0x90;
787 i = pcmcia_get_first_tuple(handle, &tuple); 864 i = pcmcia_get_first_tuple(handle, tuple);
788 while (i == CS_SUCCESS) { 865 while (i == CS_SUCCESS) {
789 i = pcmcia_get_tuple_data(handle, &tuple); 866 i = pcmcia_get_tuple_data(handle, tuple);
790 if ((i != CS_SUCCESS) || (buf[0] == 0x04)) 867 if ((i != CS_SUCCESS) || (buf[0] == 0x04))
791 break; 868 break;
792 i = pcmcia_get_next_tuple(handle, &tuple); 869 i = pcmcia_get_next_tuple(handle, tuple);
870 }
871 if (i != CS_SUCCESS) {
872 rc = -1;
873 goto free_cfg_mem;
793 } 874 }
794 if (i != CS_SUCCESS)
795 return -1;
796 for (i = 0; i < 6; i++) 875 for (i = 0; i < 6; i++)
797 dev->dev_addr[i] = buf[i+2]; 876 dev->dev_addr[i] = buf[i+2];
798 877
@@ -814,8 +893,10 @@ static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
814 inw(link->io.BasePort1 + OSITECH_AUI_PWR), 893 inw(link->io.BasePort1 + OSITECH_AUI_PWR),
815 inw(link->io.BasePort1 + OSITECH_RESET_ISR)); 894 inw(link->io.BasePort1 + OSITECH_RESET_ISR));
816 } 895 }
817 896 rc = 0;
818 return 0; 897free_cfg_mem:
898 kfree(cfg_mem);
899 return rc;
819} 900}
820 901
821/*====================================================================== 902/*======================================================================
@@ -887,9 +968,10 @@ static void smc91c92_config(dev_link_t *link)
887 client_handle_t handle = link->handle; 968 client_handle_t handle = link->handle;
888 struct net_device *dev = link->priv; 969 struct net_device *dev = link->priv;
889 struct smc_private *smc = netdev_priv(dev); 970 struct smc_private *smc = netdev_priv(dev);
890 tuple_t tuple; 971 struct smc_cfg_mem *cfg_mem;
891 cisparse_t parse; 972 tuple_t *tuple;
892 u_short buf[32]; 973 cisparse_t *parse;
974 u_char *buf;
893 char *name; 975 char *name;
894 int i, j, rev; 976 int i, j, rev;
895 kio_addr_t ioaddr; 977 kio_addr_t ioaddr;
@@ -897,21 +979,29 @@ static void smc91c92_config(dev_link_t *link)
897 979
898 DEBUG(0, "smc91c92_config(0x%p)\n", link); 980 DEBUG(0, "smc91c92_config(0x%p)\n", link);
899 981
900 tuple.Attributes = tuple.TupleOffset = 0; 982 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
901 tuple.TupleData = (cisdata_t *)buf; 983 if (!cfg_mem)
902 tuple.TupleDataMax = sizeof(buf); 984 goto config_failed;
903 985
904 tuple.DesiredTuple = CISTPL_CONFIG; 986 tuple = &cfg_mem->tuple;
905 i = first_tuple(handle, &tuple, &parse); 987 parse = &cfg_mem->parse;
906 CS_EXIT_TEST(i, ParseTuple, config_failed); 988 buf = cfg_mem->buf;
907 link->conf.ConfigBase = parse.config.base;
908 link->conf.Present = parse.config.rmask[0];
909 989
910 tuple.DesiredTuple = CISTPL_MANFID; 990 tuple->Attributes = tuple->TupleOffset = 0;
911 tuple.Attributes = TUPLE_RETURN_COMMON; 991 tuple->TupleData = (cisdata_t *)buf;
912 if (first_tuple(handle, &tuple, &parse) == CS_SUCCESS) { 992 tuple->TupleDataMax = 64;
913 smc->manfid = parse.manfid.manf; 993
914 smc->cardid = parse.manfid.card; 994 tuple->DesiredTuple = CISTPL_CONFIG;
995 i = first_tuple(handle, tuple, parse);
996 CS_EXIT_TEST(i, ParseTuple, config_failed);
997 link->conf.ConfigBase = parse->config.base;
998 link->conf.Present = parse->config.rmask[0];
999
1000 tuple->DesiredTuple = CISTPL_MANFID;
1001 tuple->Attributes = TUPLE_RETURN_COMMON;
1002 if (first_tuple(handle, tuple, parse) == CS_SUCCESS) {
1003 smc->manfid = parse->manfid.manf;
1004 smc->cardid = parse->manfid.card;
915 } 1005 }
916 1006
917 /* Configure card */ 1007 /* Configure card */
@@ -1046,7 +1136,7 @@ static void smc91c92_config(dev_link_t *link)
1046 printk(KERN_NOTICE " No MII transceivers found!\n"); 1136 printk(KERN_NOTICE " No MII transceivers found!\n");
1047 } 1137 }
1048 } 1138 }
1049 1139 kfree(cfg_mem);
1050 return; 1140 return;
1051 1141
1052config_undo: 1142config_undo:
@@ -1054,6 +1144,7 @@ config_undo:
1054config_failed: /* CS_EXIT_TEST() calls jump to here... */ 1144config_failed: /* CS_EXIT_TEST() calls jump to here... */
1055 smc91c92_release(link); 1145 smc91c92_release(link);
1056 link->state &= ~DEV_CONFIG_PENDING; 1146 link->state &= ~DEV_CONFIG_PENDING;
1147 kfree(cfg_mem);
1057 1148
1058} /* smc91c92_config */ 1149} /* smc91c92_config */
1059 1150
@@ -2236,6 +2327,38 @@ static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
2236 return rc; 2327 return rc;
2237} 2328}
2238 2329
2330static struct pcmcia_device_id smc91c92_ids[] = {
2331 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0109, 0x0501),
2332 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0140, 0x000a),
2333 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
2334 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
2335 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
2336 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
2337 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
2338 PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
2339 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2340 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2341 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020),
2342 PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023),
2343 PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb),
2344 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "Fast Ethernet PCCard", 0x78f308dc, 0xdcea68bc),
2345 PCMCIA_DEVICE_PROD_ID12("dit Co., Ltd.", "PC Card-10/100BTX", 0xe59365c8, 0x6a2161d1),
2346 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L100C", 0x6a26d1cf, 0xc16ce9c5),
2347 PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9),
2348 PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953),
2349 PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a),
2350 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2351 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2352 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc),
2353 PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9),
2354 PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d),
2355 /* These conflict with other cards! */
2356 /* PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0100), */
2357 /* PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab), */
2358 PCMCIA_DEVICE_NULL,
2359};
2360MODULE_DEVICE_TABLE(pcmcia, smc91c92_ids);
2361
2239static struct pcmcia_driver smc91c92_cs_driver = { 2362static struct pcmcia_driver smc91c92_cs_driver = {
2240 .owner = THIS_MODULE, 2363 .owner = THIS_MODULE,
2241 .drv = { 2364 .drv = {
@@ -2243,6 +2366,7 @@ static struct pcmcia_driver smc91c92_cs_driver = {
2243 }, 2366 },
2244 .attach = smc91c92_attach, 2367 .attach = smc91c92_attach,
2245 .detach = smc91c92_detach, 2368 .detach = smc91c92_detach,
2369 .id_table = smc91c92_ids,
2246}; 2370};
2247 2371
2248static int __init init_smc91c92_cs(void) 2372static int __init init_smc91c92_cs(void)
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index 58177d67ea12..0cd225e1595c 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -1983,6 +1983,33 @@ do_stop(struct net_device *dev)
1983 return 0; 1983 return 0;
1984} 1984}
1985 1985
1986static struct pcmcia_device_id xirc2ps_ids[] = {
1987 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0089, 0x110a),
1988 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0138, 0x110a),
1989 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea),
1990 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM33", 0x2e3ee845, 0x80609023),
1991 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
1992 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
1993 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
1994 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Xircom", "CreditCard Ethernet", 0x2e3ee845, 0xc0e778c2),
1995 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a),
1996 PCMCIA_DEVICE_PROD_ID13("Toshiba Information Systems", "TPCENET", 0x1b3b94fe, 0xf381c1a2),
1997 PCMCIA_DEVICE_PROD_ID13("Xircom", "CE3-10/100", 0x2e3ee845, 0x0ec0ac37),
1998 PCMCIA_DEVICE_PROD_ID13("Xircom", "PS-CE2-10", 0x2e3ee845, 0x947d9073),
1999 PCMCIA_DEVICE_PROD_ID13("Xircom", "R2E-100BTX", 0x2e3ee845, 0x2464a6e3),
2000 PCMCIA_DEVICE_PROD_ID13("Xircom", "RE-10", 0x2e3ee845, 0x3e08d609),
2001 PCMCIA_DEVICE_PROD_ID13("Xircom", "XE2000", 0x2e3ee845, 0xf7188e46),
2002 PCMCIA_DEVICE_PROD_ID12("Compaq", "Ethernet LAN Card", 0x54f7c49c, 0x9fd2f0a2),
2003 PCMCIA_DEVICE_PROD_ID12("Compaq", "Netelligent 10/100 PC Card", 0x54f7c49c, 0xefe96769),
2004 PCMCIA_DEVICE_PROD_ID12("Intel", "EtherExpress(TM) PRO/100 PC Card Mobile Adapter16", 0x816cc815, 0x174397db),
2005 PCMCIA_DEVICE_PROD_ID12("Toshiba", "10/100 Ethernet PC Card", 0x44a09d9c, 0xb44deecf),
2006 /* also matches CFE-10 cards! */
2007 /* PCMCIA_DEVICE_MANF_CARD(0x0105, 0x010a), */
2008 PCMCIA_DEVICE_NULL,
2009};
2010MODULE_DEVICE_TABLE(pcmcia, xirc2ps_ids);
2011
2012
1986static struct pcmcia_driver xirc2ps_cs_driver = { 2013static struct pcmcia_driver xirc2ps_cs_driver = {
1987 .owner = THIS_MODULE, 2014 .owner = THIS_MODULE,
1988 .drv = { 2015 .drv = {
@@ -1990,6 +2017,7 @@ static struct pcmcia_driver xirc2ps_cs_driver = {
1990 }, 2017 },
1991 .attach = xirc2ps_attach, 2018 .attach = xirc2ps_attach,
1992 .detach = xirc2ps_detach, 2019 .detach = xirc2ps_detach,
2020 .id_table = xirc2ps_ids,
1993}; 2021};
1994 2022
1995static int __init 2023static int __init
diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
index 13f114876965..113b68099216 100644
--- a/drivers/net/pcnet32.c
+++ b/drivers/net/pcnet32.c
@@ -850,7 +850,7 @@ static int pcnet32_phys_id(struct net_device *dev, u32 data)
850 if ((!data) || (data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ))) 850 if ((!data) || (data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ)))
851 data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ); 851 data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ);
852 852
853 schedule_timeout(data * HZ); 853 msleep_interruptible(data * 1000);
854 del_timer_sync(&lp->blink_timer); 854 del_timer_sync(&lp->blink_timer);
855 855
856 /* Restore the original value of the bcrs */ 856 /* Restore the original value of the bcrs */
@@ -1602,7 +1602,7 @@ pcnet32_init_ring(struct net_device *dev)
1602 1602
1603 rmb(); 1603 rmb();
1604 if (lp->rx_dma_addr[i] == 0) 1604 if (lp->rx_dma_addr[i] == 0)
1605 lp->rx_dma_addr[i] = pci_map_single(lp->pci_dev, rx_skbuff->tail, 1605 lp->rx_dma_addr[i] = pci_map_single(lp->pci_dev, rx_skbuff->data,
1606 PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE); 1606 PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE);
1607 lp->rx_ring[i].base = (u32)le32_to_cpu(lp->rx_dma_addr[i]); 1607 lp->rx_ring[i].base = (u32)le32_to_cpu(lp->rx_dma_addr[i]);
1608 lp->rx_ring[i].buf_length = le16_to_cpu(2-PKT_BUF_SZ); 1608 lp->rx_ring[i].buf_length = le16_to_cpu(2-PKT_BUF_SZ);
@@ -1983,7 +1983,7 @@ pcnet32_rx(struct net_device *dev)
1983 lp->rx_skbuff[entry] = newskb; 1983 lp->rx_skbuff[entry] = newskb;
1984 newskb->dev = dev; 1984 newskb->dev = dev;
1985 lp->rx_dma_addr[entry] = 1985 lp->rx_dma_addr[entry] =
1986 pci_map_single(lp->pci_dev, newskb->tail, 1986 pci_map_single(lp->pci_dev, newskb->data,
1987 PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE); 1987 PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE);
1988 lp->rx_ring[entry].base = le32_to_cpu(lp->rx_dma_addr[entry]); 1988 lp->rx_ring[entry].base = le32_to_cpu(lp->rx_dma_addr[entry]);
1989 rx_in_place = 1; 1989 rx_in_place = 1;
@@ -2020,7 +2020,7 @@ pcnet32_rx(struct net_device *dev)
2020 PKT_BUF_SZ-2, 2020 PKT_BUF_SZ-2,
2021 PCI_DMA_FROMDEVICE); 2021 PCI_DMA_FROMDEVICE);
2022 eth_copy_and_sum(skb, 2022 eth_copy_and_sum(skb,
2023 (unsigned char *)(lp->rx_skbuff[entry]->tail), 2023 (unsigned char *)(lp->rx_skbuff[entry]->data),
2024 pkt_len,0); 2024 pkt_len,0);
2025 pci_dma_sync_single_for_device(lp->pci_dev, 2025 pci_dma_sync_single_for_device(lp->pci_dev,
2026 lp->rx_dma_addr[entry], 2026 lp->rx_dma_addr[entry],
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index ce449fe90e6d..d5afe05cd826 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -1876,7 +1876,7 @@ static int rtl8169_alloc_rx_skb(struct pci_dev *pdev, struct sk_buff **sk_buff,
1876 skb_reserve(skb, NET_IP_ALIGN); 1876 skb_reserve(skb, NET_IP_ALIGN);
1877 *sk_buff = skb; 1877 *sk_buff = skb;
1878 1878
1879 mapping = pci_map_single(pdev, skb->tail, rx_buf_sz, 1879 mapping = pci_map_single(pdev, skb->data, rx_buf_sz,
1880 PCI_DMA_FROMDEVICE); 1880 PCI_DMA_FROMDEVICE);
1881 1881
1882 rtl8169_map_to_asic(desc, mapping, rx_buf_sz); 1882 rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
@@ -2336,7 +2336,7 @@ static inline int rtl8169_try_rx_copy(struct sk_buff **sk_buff, int pkt_size,
2336 skb = dev_alloc_skb(pkt_size + NET_IP_ALIGN); 2336 skb = dev_alloc_skb(pkt_size + NET_IP_ALIGN);
2337 if (skb) { 2337 if (skb) {
2338 skb_reserve(skb, NET_IP_ALIGN); 2338 skb_reserve(skb, NET_IP_ALIGN);
2339 eth_copy_and_sum(skb, sk_buff[0]->tail, pkt_size, 0); 2339 eth_copy_and_sum(skb, sk_buff[0]->data, pkt_size, 0);
2340 *sk_buff = skb; 2340 *sk_buff = skb;
2341 rtl8169_mark_to_asic(desc, rx_buf_sz); 2341 rtl8169_mark_to_asic(desc, rx_buf_sz);
2342 ret = 0; 2342 ret = 0;
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index 9c224eba057d..ea638b162d3f 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -42,6 +42,7 @@
42#include <linux/errno.h> 42#include <linux/errno.h>
43#include <linux/ioport.h> 43#include <linux/ioport.h>
44#include <linux/pci.h> 44#include <linux/pci.h>
45#include <linux/dma-mapping.h>
45#include <linux/kernel.h> 46#include <linux/kernel.h>
46#include <linux/netdevice.h> 47#include <linux/netdevice.h>
47#include <linux/etherdevice.h> 48#include <linux/etherdevice.h>
@@ -1698,11 +1699,9 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
1698#else 1699#else
1699 ba = &nic->ba[ring_no][block_no][off]; 1700 ba = &nic->ba[ring_no][block_no][off];
1700 skb_reserve(skb, BUF0_LEN); 1701 skb_reserve(skb, BUF0_LEN);
1701 tmp = (unsigned long) skb->data; 1702 tmp = ((unsigned long) skb->data & ALIGN_SIZE);
1702 tmp += ALIGN_SIZE; 1703 if (tmp)
1703 tmp &= ~ALIGN_SIZE; 1704 skb_reserve(skb, (ALIGN_SIZE + 1) - tmp);
1704 skb->data = (void *) tmp;
1705 skb->tail = (void *) tmp;
1706 1705
1707 memset(rxdp, 0, sizeof(RxD_t)); 1706 memset(rxdp, 0, sizeof(RxD_t));
1708 rxdp->Buffer2_ptr = pci_map_single 1707 rxdp->Buffer2_ptr = pci_map_single
@@ -4593,19 +4592,19 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
4593 return ret; 4592 return ret;
4594 } 4593 }
4595 4594
4596 if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) { 4595 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
4597 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 64bit DMA\n"); 4596 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 64bit DMA\n");
4598 dma_flag = TRUE; 4597 dma_flag = TRUE;
4599 4598
4600 if (pci_set_consistent_dma_mask 4599 if (pci_set_consistent_dma_mask
4601 (pdev, 0xffffffffffffffffULL)) { 4600 (pdev, DMA_64BIT_MASK)) {
4602 DBG_PRINT(ERR_DBG, 4601 DBG_PRINT(ERR_DBG,
4603 "Unable to obtain 64bit DMA for \ 4602 "Unable to obtain 64bit DMA for \
4604 consistent allocations\n"); 4603 consistent allocations\n");
4605 pci_disable_device(pdev); 4604 pci_disable_device(pdev);
4606 return -ENOMEM; 4605 return -ENOMEM;
4607 } 4606 }
4608 } else if (!pci_set_dma_mask(pdev, 0xffffffffUL)) { 4607 } else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
4609 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 32bit DMA\n"); 4608 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 32bit DMA\n");
4610 } else { 4609 } else {
4611 pci_disable_device(pdev); 4610 pci_disable_device(pdev);
diff --git a/drivers/net/sb1000.c b/drivers/net/sb1000.c
index e15369c8d165..d6388e1533f0 100644
--- a/drivers/net/sb1000.c
+++ b/drivers/net/sb1000.c
@@ -90,7 +90,6 @@ static int sb1000_close(struct net_device *dev);
90 90
91 91
92/* SB1000 hardware routines to be used during open/configuration phases */ 92/* SB1000 hardware routines to be used during open/configuration phases */
93static inline void nicedelay(unsigned long usecs);
94static inline int card_wait_for_busy_clear(const int ioaddr[], 93static inline int card_wait_for_busy_clear(const int ioaddr[],
95 const char* name); 94 const char* name);
96static inline int card_wait_for_ready(const int ioaddr[], const char* name, 95static inline int card_wait_for_ready(const int ioaddr[], const char* name,
@@ -254,13 +253,6 @@ static struct pnp_driver sb1000_driver = {
254 253
255static const int TimeOutJiffies = (875 * HZ) / 100; 254static const int TimeOutJiffies = (875 * HZ) / 100;
256 255
257static inline void nicedelay(unsigned long usecs)
258{
259 current->state = TASK_INTERRUPTIBLE;
260 schedule_timeout(HZ);
261 return;
262}
263
264/* Card Wait For Busy Clear (cannot be used during an interrupt) */ 256/* Card Wait For Busy Clear (cannot be used during an interrupt) */
265static inline int 257static inline int
266card_wait_for_busy_clear(const int ioaddr[], const char* name) 258card_wait_for_busy_clear(const int ioaddr[], const char* name)
@@ -475,7 +467,7 @@ sb1000_reset(const int ioaddr[], const char* name)
475 udelay(1000); 467 udelay(1000);
476 outb(0x0, port); 468 outb(0x0, port);
477 inb(port); 469 inb(port);
478 nicedelay(60000); 470 ssleep(1);
479 outb(0x4, port); 471 outb(0x4, port);
480 inb(port); 472 inb(port);
481 udelay(1000); 473 udelay(1000);
@@ -537,7 +529,7 @@ sb1000_activate(const int ioaddr[], const char* name)
537 const unsigned char Command0[6] = {0x80, 0x11, 0x00, 0x00, 0x00, 0x00}; 529 const unsigned char Command0[6] = {0x80, 0x11, 0x00, 0x00, 0x00, 0x00};
538 const unsigned char Command1[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00}; 530 const unsigned char Command1[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00};
539 531
540 nicedelay(50000); 532 ssleep(1);
541 if ((status = card_send_command(ioaddr, name, Command0, st))) 533 if ((status = card_send_command(ioaddr, name, Command0, st)))
542 return status; 534 return status;
543 if ((status = card_send_command(ioaddr, name, Command1, st))) 535 if ((status = card_send_command(ioaddr, name, Command1, st)))
@@ -944,7 +936,7 @@ sb1000_open(struct net_device *dev)
944 /* initialize sb1000 */ 936 /* initialize sb1000 */
945 if ((status = sb1000_reset(ioaddr, name))) 937 if ((status = sb1000_reset(ioaddr, name)))
946 return status; 938 return status;
947 nicedelay(200000); 939 ssleep(1);
948 if ((status = sb1000_check_CRC(ioaddr, name))) 940 if ((status = sb1000_check_CRC(ioaddr, name)))
949 return status; 941 return status;
950 942
diff --git a/drivers/net/sb1250-mac.c b/drivers/net/sb1250-mac.c
index fd2e7c374906..7abd55a4fb21 100644
--- a/drivers/net/sb1250-mac.c
+++ b/drivers/net/sb1250-mac.c
@@ -963,11 +963,11 @@ static int sbdma_add_rcvbuffer(sbmacdma_t *d,struct sk_buff *sb)
963 /* 963 /*
964 * Do not interrupt per DMA transfer. 964 * Do not interrupt per DMA transfer.
965 */ 965 */
966 dsc->dscr_a = virt_to_phys(sb_new->tail) | 966 dsc->dscr_a = virt_to_phys(sb_new->data) |
967 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) | 967 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) |
968 0; 968 0;
969#else 969#else
970 dsc->dscr_a = virt_to_phys(sb_new->tail) | 970 dsc->dscr_a = virt_to_phys(sb_new->data) |
971 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) | 971 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) |
972 M_DMA_DSCRA_INTERRUPT; 972 M_DMA_DSCRA_INTERRUPT;
973#endif 973#endif
diff --git a/drivers/net/sis900.c b/drivers/net/sis900.c
index 3107aed0fb51..23b713c700b3 100644
--- a/drivers/net/sis900.c
+++ b/drivers/net/sis900.c
@@ -66,6 +66,7 @@
66#include <linux/ethtool.h> 66#include <linux/ethtool.h>
67#include <linux/crc32.h> 67#include <linux/crc32.h>
68#include <linux/bitops.h> 68#include <linux/bitops.h>
69#include <linux/dma-mapping.h>
69 70
70#include <asm/processor.h> /* Processor type for cache alignment. */ 71#include <asm/processor.h> /* Processor type for cache alignment. */
71#include <asm/io.h> 72#include <asm/io.h>
@@ -93,8 +94,6 @@ static int sis900_debug = -1; /* Use SIS900_DEF_MSG as value */
93 94
94/* Time in jiffies before concluding the transmitter is hung. */ 95/* Time in jiffies before concluding the transmitter is hung. */
95#define TX_TIMEOUT (4*HZ) 96#define TX_TIMEOUT (4*HZ)
96/* SiS 900 is capable of 32 bits BM DMA */
97#define SIS900_DMA_MASK 0xffffffff
98 97
99enum { 98enum {
100 SIS_900 = 0, 99 SIS_900 = 0,
@@ -414,7 +413,7 @@ static int __devinit sis900_probe(struct pci_dev *pci_dev,
414 ret = pci_enable_device(pci_dev); 413 ret = pci_enable_device(pci_dev);
415 if(ret) return ret; 414 if(ret) return ret;
416 415
417 i = pci_set_dma_mask(pci_dev, SIS900_DMA_MASK); 416 i = pci_set_dma_mask(pci_dev, DMA_32BIT_MASK);
418 if(i){ 417 if(i){
419 printk(KERN_ERR "sis900.c: architecture does not support" 418 printk(KERN_ERR "sis900.c: architecture does not support"
420 "32bit PCI busmaster DMA\n"); 419 "32bit PCI busmaster DMA\n");
@@ -1155,7 +1154,7 @@ sis900_init_rx_ring(struct net_device *net_dev)
1155 sis_priv->rx_skbuff[i] = skb; 1154 sis_priv->rx_skbuff[i] = skb;
1156 sis_priv->rx_ring[i].cmdsts = RX_BUF_SIZE; 1155 sis_priv->rx_ring[i].cmdsts = RX_BUF_SIZE;
1157 sis_priv->rx_ring[i].bufptr = pci_map_single(sis_priv->pci_dev, 1156 sis_priv->rx_ring[i].bufptr = pci_map_single(sis_priv->pci_dev,
1158 skb->tail, RX_BUF_SIZE, PCI_DMA_FROMDEVICE); 1157 skb->data, RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
1159 } 1158 }
1160 sis_priv->dirty_rx = (unsigned int) (i - NUM_RX_DESC); 1159 sis_priv->dirty_rx = (unsigned int) (i - NUM_RX_DESC);
1161 1160
@@ -1777,7 +1776,7 @@ static int sis900_rx(struct net_device *net_dev)
1777 sis_priv->rx_skbuff[entry] = skb; 1776 sis_priv->rx_skbuff[entry] = skb;
1778 sis_priv->rx_ring[entry].cmdsts = RX_BUF_SIZE; 1777 sis_priv->rx_ring[entry].cmdsts = RX_BUF_SIZE;
1779 sis_priv->rx_ring[entry].bufptr = 1778 sis_priv->rx_ring[entry].bufptr =
1780 pci_map_single(sis_priv->pci_dev, skb->tail, 1779 pci_map_single(sis_priv->pci_dev, skb->data,
1781 RX_BUF_SIZE, PCI_DMA_FROMDEVICE); 1780 RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
1782 sis_priv->dirty_rx++; 1781 sis_priv->dirty_rx++;
1783 } 1782 }
@@ -1810,7 +1809,7 @@ static int sis900_rx(struct net_device *net_dev)
1810 sis_priv->rx_skbuff[entry] = skb; 1809 sis_priv->rx_skbuff[entry] = skb;
1811 sis_priv->rx_ring[entry].cmdsts = RX_BUF_SIZE; 1810 sis_priv->rx_ring[entry].cmdsts = RX_BUF_SIZE;
1812 sis_priv->rx_ring[entry].bufptr = 1811 sis_priv->rx_ring[entry].bufptr =
1813 pci_map_single(sis_priv->pci_dev, skb->tail, 1812 pci_map_single(sis_priv->pci_dev, skb->data,
1814 RX_BUF_SIZE, PCI_DMA_FROMDEVICE); 1813 RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
1815 } 1814 }
1816 } 1815 }
diff --git a/drivers/net/sk98lin/skge.c b/drivers/net/sk98lin/skge.c
index 1ccb2989001c..82570ec44d8e 100644
--- a/drivers/net/sk98lin/skge.c
+++ b/drivers/net/sk98lin/skge.c
@@ -112,6 +112,7 @@
112#include <linux/moduleparam.h> 112#include <linux/moduleparam.h>
113#include <linux/init.h> 113#include <linux/init.h>
114#include <linux/proc_fs.h> 114#include <linux/proc_fs.h>
115#include <linux/dma-mapping.h>
115 116
116#include "h/skdrv1st.h" 117#include "h/skdrv1st.h"
117#include "h/skdrv2nd.h" 118#include "h/skdrv2nd.h"
@@ -4912,8 +4913,8 @@ static int __devinit skge_probe_one(struct pci_dev *pdev,
4912 goto out; 4913 goto out;
4913 4914
4914 /* Configure DMA attributes. */ 4915 /* Configure DMA attributes. */
4915 if (pci_set_dma_mask(pdev, (u64) 0xffffffffffffffffULL) && 4916 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4916 pci_set_dma_mask(pdev, (u64) 0xffffffff)) 4917 pci_set_dma_mask(pdev, DMA_32BIT_MASK))
4917 goto out_disable_device; 4918 goto out_disable_device;
4918 4919
4919 4920
diff --git a/drivers/net/skfp/Makefile b/drivers/net/skfp/Makefile
index 6cfccfb7889f..cb23580fcffa 100644
--- a/drivers/net/skfp/Makefile
+++ b/drivers/net/skfp/Makefile
@@ -6,8 +6,8 @@ obj-$(CONFIG_SKFP) += skfp.o
6 6
7skfp-objs := skfddi.o hwmtm.o fplustm.o smt.o cfm.o \ 7skfp-objs := skfddi.o hwmtm.o fplustm.o smt.o cfm.o \
8 ecm.o pcmplc.o pmf.o queue.o rmt.o \ 8 ecm.o pcmplc.o pmf.o queue.o rmt.o \
9 smtdef.o smtinit.o smttimer.o srf.o lnkstat.o \ 9 smtdef.o smtinit.o smttimer.o srf.o hwt.o \
10 smtparse.o hwt.o drvfbi.o ess.o 10 drvfbi.o ess.o
11 11
12# NOTE: 12# NOTE:
13# Compiling this driver produces some warnings (and some more are 13# Compiling this driver produces some warnings (and some more are
diff --git a/drivers/net/skfp/drvfbi.c b/drivers/net/skfp/drvfbi.c
index 052e841ba187..5b475833f645 100644
--- a/drivers/net/skfp/drvfbi.c
+++ b/drivers/net/skfp/drvfbi.c
@@ -105,8 +105,8 @@ extern int AIX_vpdReadByte() ;
105#endif 105#endif
106 106
107 107
108/* Prototypes of local functions. */ 108/* Prototype of a local function. */
109void smt_stop_watchdog(struct s_smc *smc); 109static void smt_stop_watchdog(struct s_smc *smc);
110 110
111#ifdef MCA 111#ifdef MCA
112static int read_card_id() ; 112static int read_card_id() ;
@@ -631,7 +631,7 @@ void plc_clear_irq(struct s_smc *smc, int p)
631 * LED_Y_OFF just switch yellow LED off 631 * LED_Y_OFF just switch yellow LED off
632 * LED_Y_ON just switch yello LED on 632 * LED_Y_ON just switch yello LED on
633 */ 633 */
634void led_indication(struct s_smc *smc, int led_event) 634static void led_indication(struct s_smc *smc, int led_event)
635{ 635{
636 /* use smc->hw.mac_ring_is_up == TRUE 636 /* use smc->hw.mac_ring_is_up == TRUE
637 * as indication for Ring Operational 637 * as indication for Ring Operational
@@ -764,122 +764,6 @@ void llc_recover_tx(struct s_smc *smc)
764#endif 764#endif
765} 765}
766 766
767/*--------------------------- DMA init ----------------------------*/
768#ifdef ISA
769
770/*
771 * init DMA
772 */
773void init_dma(struct s_smc *smc, int dma)
774{
775 SK_UNUSED(smc) ;
776
777 /*
778 * set cascade mode,
779 * clear mask bit (enable DMA cannal)
780 */
781 if (dma > 3) {
782 outp(0xd6,(dma & 0x03) | 0xc0) ;
783 outp(0xd4, dma & 0x03) ;
784 }
785 else {
786 outp(0x0b,(dma & 0x03) | 0xc0) ;
787 outp(0x0a,dma & 0x03) ;
788 }
789}
790
791/*
792 * disable DMA
793 */
794void dis_dma(struct s_smc *smc, int dma)
795{
796 SK_UNUSED(smc) ;
797
798 /*
799 * set mask bit (disable DMA cannal)
800 */
801 if (dma > 3) {
802 outp(0xd4,(dma & 0x03) | 0x04) ;
803 }
804 else {
805 outp(0x0a,(dma & 0x03) | 0x04) ;
806 }
807}
808
809#endif /* ISA */
810
811#ifdef EISA
812
813/*arrays with io addresses of dma controller length and address registers*/
814static const int cntr[8] = { 0x001,0x003,0x005,0x007,0,0x0c6,0x0ca,0x0ce } ;
815static const int base[8] = { 0x000,0x002,0x004,0x006,0,0x0c4,0x0c8,0x0cc } ;
816static const int page[8] = { 0x087,0x083,0x081,0x082,0,0x08b,0x089,0x08a } ;
817
818void init_dma(struct s_smc *smc, int dma)
819{
820 /*
821 * extended mode register
822 * 32 bit IO
823 * type c
824 * TC output
825 * disable stop
826 */
827
828 /* mode read (write) demand */
829 smc->hw.dma_rmode = (dma & 3) | 0x08 | 0x0 ;
830 smc->hw.dma_wmode = (dma & 3) | 0x04 | 0x0 ;
831
832 /* 32 bit IO's, burst DMA mode (type "C") */
833 smc->hw.dma_emode = (dma & 3) | 0x08 | 0x30 ;
834
835 outp((dma < 4) ? 0x40b : 0x4d6,smc->hw.dma_emode) ;
836
837 /* disable chaining */
838 outp((dma < 4) ? 0x40a : 0x4d4,(dma&3)) ;
839
840 /*load dma controller addresses for fast access during set dma*/
841 smc->hw.dma_base_word_count = cntr[smc->hw.dma];
842 smc->hw.dma_base_address = base[smc->hw.dma];
843 smc->hw.dma_base_address_page = page[smc->hw.dma];
844
845}
846
847void dis_dma(struct s_smc *smc, int dma)
848{
849 SK_UNUSED(smc) ;
850
851 outp((dma < 4) ? 0x0a : 0xd4,(dma&3)|4) ;/* mask bit */
852}
853#endif /* EISA */
854
855#ifdef MCA
856void init_dma(struct s_smc *smc, int dma)
857{
858 SK_UNUSED(smc) ;
859 SK_UNUSED(dma) ;
860}
861
862void dis_dma(struct s_smc *smc, int dma)
863{
864 SK_UNUSED(smc) ;
865 SK_UNUSED(dma) ;
866}
867#endif
868
869#ifdef PCI
870void init_dma(struct s_smc *smc, int dma)
871{
872 SK_UNUSED(smc) ;
873 SK_UNUSED(dma) ;
874}
875
876void dis_dma(struct s_smc *smc, int dma)
877{
878 SK_UNUSED(smc) ;
879 SK_UNUSED(dma) ;
880}
881#endif
882
883#ifdef MULT_OEM 767#ifdef MULT_OEM
884static int is_equal_num(char comp1[], char comp2[], int num) 768static int is_equal_num(char comp1[], char comp2[], int num)
885{ 769{
@@ -1407,7 +1291,7 @@ void smt_start_watchdog(struct s_smc *smc)
1407#endif /* DEBUG */ 1291#endif /* DEBUG */
1408} 1292}
1409 1293
1410void smt_stop_watchdog(struct s_smc *smc) 1294static void smt_stop_watchdog(struct s_smc *smc)
1411{ 1295{
1412 SK_UNUSED(smc) ; /* Make LINT happy. */ 1296 SK_UNUSED(smc) ; /* Make LINT happy. */
1413#ifndef DEBUG 1297#ifndef DEBUG
@@ -1422,104 +1306,6 @@ void smt_stop_watchdog(struct s_smc *smc)
1422} 1306}
1423 1307
1424#ifdef PCI 1308#ifdef PCI
1425static char get_rom_byte(struct s_smc *smc, u_short addr)
1426{
1427 GET_PAGE(addr) ;
1428 return (READ_PROM(ADDR(B2_FDP))) ;
1429}
1430
1431/*
1432 * ROM image defines
1433 */
1434#define ROM_SIG_1 0
1435#define ROM_SIG_2 1
1436#define PCI_DATA_1 0x18
1437#define PCI_DATA_2 0x19
1438
1439/*
1440 * PCI data structure defines
1441 */
1442#define VPD_DATA_1 0x08
1443#define VPD_DATA_2 0x09
1444#define IMAGE_LEN_1 0x10
1445#define IMAGE_LEN_2 0x11
1446#define CODE_TYPE 0x14
1447#define INDICATOR 0x15
1448
1449/*
1450 * BEGIN_MANUAL_ENTRY(mac_drv_vpd_read)
1451 * mac_drv_vpd_read(smc,buf,size,image)
1452 *
1453 * function DOWNCALL (FDDIWARE)
1454 * reads the VPD data of the FPROM and writes it into the
1455 * buffer
1456 *
1457 * para buf points to the buffer for the VPD data
1458 * size size of the VPD data buffer
1459 * image boot image; code type of the boot image
1460 * image = 0 Intel x86, PC-AT compatible
1461 * 1 OPENBOOT standard for PCI
1462 * 2-FF reserved
1463 *
1464 * returns len number of VPD data bytes read form the FPROM
1465 * <0 number of read bytes
1466 * >0 error: data invalid
1467 *
1468 * END_MANUAL_ENTRY
1469 */
1470int mac_drv_vpd_read(struct s_smc *smc, char *buf, int size, char image)
1471{
1472 u_short ibase ;
1473 u_short pci_base ;
1474 u_short vpd ;
1475 int len ;
1476
1477 len = 0 ;
1478 ibase = 0 ;
1479 /*
1480 * as long images defined
1481 */
1482 while (get_rom_byte(smc,ibase+ROM_SIG_1) == 0x55 &&
1483 (u_char) get_rom_byte(smc,ibase+ROM_SIG_2) == 0xaa) {
1484 /*
1485 * get the pointer to the PCI data structure
1486 */
1487 pci_base = ibase + get_rom_byte(smc,ibase+PCI_DATA_1) +
1488 (get_rom_byte(smc,ibase+PCI_DATA_2) << 8) ;
1489
1490 if (image == get_rom_byte(smc,pci_base+CODE_TYPE)) {
1491 /*
1492 * we have the right image, read the VPD data
1493 */
1494 vpd = ibase + get_rom_byte(smc,pci_base+VPD_DATA_1) +
1495 (get_rom_byte(smc,pci_base+VPD_DATA_2) << 8) ;
1496 if (vpd == ibase) {
1497 break ; /* no VPD data */
1498 }
1499 for (len = 0; len < size; len++,buf++,vpd++) {
1500 *buf = get_rom_byte(smc,vpd) ;
1501 }
1502 break ;
1503 }
1504 else {
1505 /*
1506 * try the next image
1507 */
1508 if (get_rom_byte(smc,pci_base+INDICATOR) & 0x80) {
1509 break ; /* this was the last image */
1510 }
1511 ibase = ibase + get_rom_byte(smc,ibase+IMAGE_LEN_1) +
1512 (get_rom_byte(smc,ibase+IMAGE_LEN_2) << 8) ;
1513 }
1514 }
1515
1516 return(len) ;
1517}
1518
1519void mac_drv_pci_fix(struct s_smc *smc, u_long fix_value)
1520{
1521 smc->hw.pci_fix_value = fix_value ;
1522}
1523 1309
1524void mac_do_pci_fix(struct s_smc *smc) 1310void mac_do_pci_fix(struct s_smc *smc)
1525{ 1311{
diff --git a/drivers/net/skfp/ess.c b/drivers/net/skfp/ess.c
index fd39b4b2ef7d..62b01328c496 100644
--- a/drivers/net/skfp/ess.c
+++ b/drivers/net/skfp/ess.c
@@ -102,7 +102,7 @@ void ess_timer_poll(struct s_smc *smc);
102void ess_para_change(struct s_smc *smc); 102void ess_para_change(struct s_smc *smc);
103int ess_raf_received_pack(struct s_smc *smc, SMbuf *mb, struct smt_header *sm, 103int ess_raf_received_pack(struct s_smc *smc, SMbuf *mb, struct smt_header *sm,
104 int fs); 104 int fs);
105int process_bw_alloc(struct s_smc *smc, long int payload, long int overhead); 105static int process_bw_alloc(struct s_smc *smc, long int payload, long int overhead);
106 106
107 107
108/* 108/*
@@ -375,7 +375,7 @@ int ess_raf_received_pack(struct s_smc *smc, SMbuf *mb, struct smt_header *sm,
375 * determines the synchronous bandwidth, set the TSYNC register and the 375 * determines the synchronous bandwidth, set the TSYNC register and the
376 * mib variables SBAPayload, SBAOverhead and fddiMACT-NEG. 376 * mib variables SBAPayload, SBAOverhead and fddiMACT-NEG.
377 */ 377 */
378int process_bw_alloc(struct s_smc *smc, long int payload, long int overhead) 378static int process_bw_alloc(struct s_smc *smc, long int payload, long int overhead)
379{ 379{
380 /* 380 /*
381 * determine the synchronous bandwidth (sync_bw) in bytes per T-NEG, 381 * determine the synchronous bandwidth (sync_bw) in bytes per T-NEG,
diff --git a/drivers/net/skfp/fplustm.c b/drivers/net/skfp/fplustm.c
index 76e78442fc24..a2ed47f1cc70 100644
--- a/drivers/net/skfp/fplustm.c
+++ b/drivers/net/skfp/fplustm.c
@@ -1117,30 +1117,6 @@ void mac_clear_multicast(struct s_smc *smc)
1117/* 1117/*
1118 BEGIN_MANUAL_ENTRY(if,func;others;2) 1118 BEGIN_MANUAL_ENTRY(if,func;others;2)
1119 1119
1120 int mac_set_func_addr(smc,f_addr)
1121 struct s_smc *smc ;
1122 u_long f_addr ;
1123
1124Function DOWNCALL (SMT, fplustm.c)
1125 Set a Token-Ring functional address, the address will
1126 be activated after calling mac_update_multicast()
1127
1128Para f_addr functional bits in non-canonical format
1129
1130Returns 0: always success
1131
1132 END_MANUAL_ENTRY()
1133 */
1134int mac_set_func_addr(struct s_smc *smc, u_long f_addr)
1135{
1136 smc->hw.fp.func_addr = f_addr ;
1137 return(0) ;
1138}
1139
1140
1141/*
1142 BEGIN_MANUAL_ENTRY(if,func;others;2)
1143
1144 int mac_add_multicast(smc,addr,can) 1120 int mac_add_multicast(smc,addr,can)
1145 struct s_smc *smc ; 1121 struct s_smc *smc ;
1146 struct fddi_addr *addr ; 1122 struct fddi_addr *addr ;
@@ -1203,52 +1179,6 @@ int mac_add_multicast(struct s_smc *smc, struct fddi_addr *addr, int can)
1203} 1179}
1204 1180
1205/* 1181/*
1206 BEGIN_MANUAL_ENTRY(if,func;others;2)
1207
1208 void mac_del_multicast(smc,addr,can)
1209 struct s_smc *smc ;
1210 struct fddi_addr *addr ;
1211 int can ;
1212
1213Function DOWNCALL (SMT, fplustm.c)
1214 Delete an entry from the multicast table
1215
1216Para addr pointer to a multicast address
1217 can = 0: the multicast address has the physical format
1218 = 1: the multicast address has the canonical format
1219 | 0x80 permanent
1220
1221 END_MANUAL_ENTRY()
1222 */
1223void mac_del_multicast(struct s_smc *smc, struct fddi_addr *addr, int can)
1224{
1225 SK_LOC_DECL(struct fddi_addr,own) ;
1226 struct s_fpmc *tb ;
1227
1228 if (!(tb = mac_get_mc_table(smc,addr,&own,1,can & ~0x80)))
1229 return ;
1230 /*
1231 * permanent addresses must be deleted with perm bit
1232 * and vice versa
1233 */
1234 if (( tb->perm && (can & 0x80)) ||
1235 (!tb->perm && !(can & 0x80))) {
1236 /*
1237 * delete it
1238 */
1239 if (tb->n) {
1240 tb->n-- ;
1241 if (tb->perm) {
1242 smc->hw.fp.smt_slots_used-- ;
1243 }
1244 else {
1245 smc->hw.fp.os_slots_used-- ;
1246 }
1247 }
1248 }
1249}
1250
1251/*
1252 * mode 1182 * mode
1253 */ 1183 */
1254 1184
diff --git a/drivers/net/skfp/h/cmtdef.h b/drivers/net/skfp/h/cmtdef.h
index 603982debc71..f2f771d8be76 100644
--- a/drivers/net/skfp/h/cmtdef.h
+++ b/drivers/net/skfp/h/cmtdef.h
@@ -507,7 +507,6 @@ void pcm_status_state(struct s_smc *smc, int np, int *type, int *state,
507 int *remote, int *mac); 507 int *remote, int *mac);
508void plc_config_mux(struct s_smc *smc, int mux); 508void plc_config_mux(struct s_smc *smc, int mux);
509void sm_lem_evaluate(struct s_smc *smc); 509void sm_lem_evaluate(struct s_smc *smc);
510void smt_clear_una_dna(struct s_smc *smc);
511void mac_update_counter(struct s_smc *smc); 510void mac_update_counter(struct s_smc *smc);
512void sm_pm_ls_latch(struct s_smc *smc, int phy, int on_off); 511void sm_pm_ls_latch(struct s_smc *smc, int phy, int on_off);
513void sm_ma_control(struct s_smc *smc, int mode); 512void sm_ma_control(struct s_smc *smc, int mode);
@@ -541,11 +540,9 @@ void smt_timer_poll(struct s_smc *smc);
541u_long smt_get_time(void); 540u_long smt_get_time(void);
542u_long smt_get_tid(struct s_smc *smc); 541u_long smt_get_tid(struct s_smc *smc);
543void smt_timer_done(struct s_smc *smc); 542void smt_timer_done(struct s_smc *smc);
544void smt_set_defaults(struct s_smc *smc);
545void smt_fixup_mib(struct s_smc *smc); 543void smt_fixup_mib(struct s_smc *smc);
546void smt_reset_defaults(struct s_smc *smc, int level); 544void smt_reset_defaults(struct s_smc *smc, int level);
547void smt_agent_task(struct s_smc *smc); 545void smt_agent_task(struct s_smc *smc);
548void smt_please_reconnect(struct s_smc *smc, int reconn_time);
549int smt_check_para(struct s_smc *smc, struct smt_header *sm, 546int smt_check_para(struct s_smc *smc, struct smt_header *sm,
550 const u_short list[]); 547 const u_short list[]);
551void driver_get_bia(struct s_smc *smc, struct fddi_addr *bia_addr); 548void driver_get_bia(struct s_smc *smc, struct fddi_addr *bia_addr);
@@ -568,7 +565,6 @@ int pcm_get_s_port(struct s_smc *smc);
568int pcm_rooted_station(struct s_smc *smc); 565int pcm_rooted_station(struct s_smc *smc);
569int cfm_get_mac_input(struct s_smc *smc); 566int cfm_get_mac_input(struct s_smc *smc);
570int cfm_get_mac_output(struct s_smc *smc); 567int cfm_get_mac_output(struct s_smc *smc);
571int port_to_mib(struct s_smc *smc, int p);
572int cem_build_path(struct s_smc *smc, char *to, int path_index); 568int cem_build_path(struct s_smc *smc, char *to, int path_index);
573int sm_mac_get_tx_state(struct s_smc *smc); 569int sm_mac_get_tx_state(struct s_smc *smc);
574char *get_pcmstate(struct s_smc *smc, int np); 570char *get_pcmstate(struct s_smc *smc, int np);
@@ -580,8 +576,6 @@ void smt_send_frame(struct s_smc *smc, SMbuf *mb, int fc, int local);
580void smt_set_timestamp(struct s_smc *smc, u_char *p); 576void smt_set_timestamp(struct s_smc *smc, u_char *p);
581void mac_set_rx_mode(struct s_smc *smc, int mode); 577void mac_set_rx_mode(struct s_smc *smc, int mode);
582int mac_add_multicast(struct s_smc *smc, struct fddi_addr *addr, int can); 578int mac_add_multicast(struct s_smc *smc, struct fddi_addr *addr, int can);
583int mac_set_func_addr(struct s_smc *smc, u_long f_addr);
584void mac_del_multicast(struct s_smc *smc, struct fddi_addr *addr, int can);
585void mac_update_multicast(struct s_smc *smc); 579void mac_update_multicast(struct s_smc *smc);
586void mac_clear_multicast(struct s_smc *smc); 580void mac_clear_multicast(struct s_smc *smc);
587void set_formac_tsync(struct s_smc *smc, long sync_bw); 581void set_formac_tsync(struct s_smc *smc, long sync_bw);
@@ -599,7 +593,6 @@ void plc_irq(struct s_smc *smc, int np, unsigned int cmd);
599int smt_set_mac_opvalues(struct s_smc *smc); 593int smt_set_mac_opvalues(struct s_smc *smc);
600 594
601#ifdef TAG_MODE 595#ifdef TAG_MODE
602void mac_drv_pci_fix(struct s_smc *smc, u_long fix_value);
603void mac_do_pci_fix(struct s_smc *smc); 596void mac_do_pci_fix(struct s_smc *smc);
604void mac_drv_clear_tx_queue(struct s_smc *smc); 597void mac_drv_clear_tx_queue(struct s_smc *smc);
605void mac_drv_repair_descr(struct s_smc *smc); 598void mac_drv_repair_descr(struct s_smc *smc);
diff --git a/drivers/net/skfp/h/hwmtm.h b/drivers/net/skfp/h/hwmtm.h
index 4e360af07d77..1a606d4bfe5e 100644
--- a/drivers/net/skfp/h/hwmtm.h
+++ b/drivers/net/skfp/h/hwmtm.h
@@ -262,31 +262,6 @@ struct os_debug {
262 (smc)->hw.fp.tx_q[queue].tx_curr_put 262 (smc)->hw.fp.tx_q[queue].tx_curr_put
263 263
264/* 264/*
265 * BEGIN_MANUAL_ENTRY(HWM_TX_CHECK)
266 * void HWM_TX_CHECK(smc,frame_status,low_water)
267 *
268 * function MACRO (hardware module, hwmtm.h)
269 * This macro is invoked by the OS-specific before it left it's
270 * driver_send function. This macro calls mac_drv_clear_txd
271 * if the free TxDs of the current transmit queue is equal or
272 * lower than the given low water mark.
273 *
274 * para frame_status status of the frame, see design description
275 * low_water low water mark of free TxD's
276 *
277 * END_MANUAL_ENTRY
278 */
279#ifndef HWM_NO_FLOW_CTL
280#define HWM_TX_CHECK(smc,frame_status,low_water) {\
281 if ((low_water)>=(smc)->hw.fp.tx_q[(frame_status)&QUEUE_A0].tx_free) {\
282 mac_drv_clear_txd(smc) ;\
283 }\
284}
285#else
286#define HWM_TX_CHECK(smc,frame_status,low_water) mac_drv_clear_txd(smc)
287#endif
288
289/*
290 * BEGIN_MANUAL_ENTRY(HWM_GET_RX_FRAG_LEN) 265 * BEGIN_MANUAL_ENTRY(HWM_GET_RX_FRAG_LEN)
291 * int HWM_GET_RX_FRAG_LEN(rxd) 266 * int HWM_GET_RX_FRAG_LEN(rxd)
292 * 267 *
diff --git a/drivers/net/skfp/h/osdef1st.h b/drivers/net/skfp/h/osdef1st.h
index 5359eb53008d..763ca18cbea8 100644
--- a/drivers/net/skfp/h/osdef1st.h
+++ b/drivers/net/skfp/h/osdef1st.h
@@ -20,6 +20,8 @@
20// HWM (HardWare Module) Definitions 20// HWM (HardWare Module) Definitions
21// ----------------------- 21// -----------------------
22 22
23#include <asm/byteorder.h>
24
23#ifdef __LITTLE_ENDIAN 25#ifdef __LITTLE_ENDIAN
24#define LITTLE_ENDIAN 26#define LITTLE_ENDIAN
25#else 27#else
diff --git a/drivers/net/skfp/hwmtm.c b/drivers/net/skfp/hwmtm.c
index 18d429021edb..438f424e6361 100644
--- a/drivers/net/skfp/hwmtm.c
+++ b/drivers/net/skfp/hwmtm.c
@@ -86,6 +86,7 @@ static u_long repair_txd_ring(struct s_smc *smc, struct s_smt_tx_queue *queue);
86static u_long repair_rxd_ring(struct s_smc *smc, struct s_smt_rx_queue *queue); 86static u_long repair_rxd_ring(struct s_smc *smc, struct s_smt_rx_queue *queue);
87static SMbuf* get_llc_rx(struct s_smc *smc); 87static SMbuf* get_llc_rx(struct s_smc *smc);
88static SMbuf* get_txd_mb(struct s_smc *smc); 88static SMbuf* get_txd_mb(struct s_smc *smc);
89static void mac_drv_clear_txd(struct s_smc *smc);
89 90
90/* 91/*
91 ------------------------------------------------------------- 92 -------------------------------------------------------------
@@ -146,7 +147,6 @@ extern int mac_drv_rx_init(struct s_smc *smc, int len, int fc, char *look_ahead,
146*/ 147*/
147void process_receive(struct s_smc *smc); 148void process_receive(struct s_smc *smc);
148void fddi_isr(struct s_smc *smc); 149void fddi_isr(struct s_smc *smc);
149void mac_drv_clear_txd(struct s_smc *smc);
150void smt_free_mbuf(struct s_smc *smc, SMbuf *mb); 150void smt_free_mbuf(struct s_smc *smc, SMbuf *mb);
151void init_driver_fplus(struct s_smc *smc); 151void init_driver_fplus(struct s_smc *smc);
152void mac_drv_rx_mode(struct s_smc *smc, int mode); 152void mac_drv_rx_mode(struct s_smc *smc, int mode);
@@ -158,7 +158,6 @@ void hwm_tx_frag(struct s_smc *smc, char far *virt, u_long phys, int len,
158void hwm_rx_frag(struct s_smc *smc, char far *virt, u_long phys, int len, 158void hwm_rx_frag(struct s_smc *smc, char far *virt, u_long phys, int len,
159 int frame_status); 159 int frame_status);
160 160
161int mac_drv_rx_frag(struct s_smc *smc, void far *virt, int len);
162int mac_drv_init(struct s_smc *smc); 161int mac_drv_init(struct s_smc *smc);
163int hwm_tx_init(struct s_smc *smc, u_char fc, int frag_count, int frame_len, 162int hwm_tx_init(struct s_smc *smc, u_char fc, int frag_count, int frame_len,
164 int frame_status); 163 int frame_status);
@@ -1448,35 +1447,6 @@ void hwm_rx_frag(struct s_smc *smc, char far *virt, u_long phys, int len,
1448 NDD_TRACE("RHfE",r,AIX_REVERSE(r->rxd_rbadr),0) ; 1447 NDD_TRACE("RHfE",r,AIX_REVERSE(r->rxd_rbadr),0) ;
1449} 1448}
1450 1449
1451#ifndef NDIS_OS2
1452/*
1453 * BEGIN_MANUAL_ENTRY(mac_drv_rx_frag)
1454 * int mac_drv_rx_frag(smc,virt,len)
1455 *
1456 * function DOWNCALL (hwmtm.c)
1457 * mac_drv_rx_frag fills the fragment with a part of the frame.
1458 *
1459 * para virt the virtual address of the fragment
1460 * len the length in bytes of the fragment
1461 *
1462 * return 0: success code, no errors possible
1463 *
1464 * END_MANUAL_ENTRY
1465 */
1466int mac_drv_rx_frag(struct s_smc *smc, void far *virt, int len)
1467{
1468 NDD_TRACE("RHSB",virt,len,smc->os.hwm.r.mb_pos) ;
1469
1470 DB_RX("receive from queue: len/virt: = %d/%x",len,virt,4) ;
1471 memcpy((char far *)virt,smc->os.hwm.r.mb_pos,len) ;
1472 smc->os.hwm.r.mb_pos += len ;
1473
1474 NDD_TRACE("RHSE",smc->os.hwm.r.mb_pos,0,0) ;
1475 return(0) ;
1476}
1477#endif
1478
1479
1480/* 1450/*
1481 * BEGINN_MANUAL_ENTRY(mac_drv_clear_rx_queue) 1451 * BEGINN_MANUAL_ENTRY(mac_drv_clear_rx_queue)
1482 * 1452 *
@@ -1978,7 +1948,7 @@ void smt_send_mbuf(struct s_smc *smc, SMbuf *mb, int fc)
1978 * 1948 *
1979 * END_MANUAL_ENTRY 1949 * END_MANUAL_ENTRY
1980 */ 1950 */
1981void mac_drv_clear_txd(struct s_smc *smc) 1951static void mac_drv_clear_txd(struct s_smc *smc)
1982{ 1952{
1983 struct s_smt_tx_queue *queue ; 1953 struct s_smt_tx_queue *queue ;
1984 struct s_smt_fp_txd volatile *t1 ; 1954 struct s_smt_fp_txd volatile *t1 ;
diff --git a/drivers/net/skfp/lnkstat.c b/drivers/net/skfp/lnkstat.c
deleted file mode 100644
index 00a248044f86..000000000000
--- a/drivers/net/skfp/lnkstat.c
+++ /dev/null
@@ -1,204 +0,0 @@
1/******************************************************************************
2 *
3 * (C)Copyright 1998,1999 SysKonnect,
4 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
5 *
6 * See the file "skfddi.c" for further information.
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 * The information in this file is provided "AS IS" without warranty.
14 *
15 ******************************************************************************/
16
17/*
18 IBM FDDI read error log function
19*/
20
21#include "h/types.h"
22#include "h/fddi.h"
23#include "h/smc.h"
24#include "h/lnkstat.h"
25
26#ifndef lint
27static const char ID_sccs[] = "@(#)lnkstat.c 1.8 97/04/11 (C) SK " ;
28#endif
29
30#ifdef sun
31#define _far
32#endif
33
34#define EL_IS_OK(x,l) ((((int)&(((struct s_error_log *)0)->x)) + \
35 sizeof(er->x)) <= l)
36
37/*
38 BEGIN_MANUAL_ENTRY(if,func;others;11)
39
40 u_long smt_get_error_word(smc)
41 struct s_smc *smc ;
42
43Function DOWNCALL (SMT, lnkstat.c)
44 This functions returns the SMT error work for AIX events.
45
46Return smt_error_word These bits are supported:
47
48 SMT_ERL_ALC == [PS/PA].fddiPORTLerFlag
49 SMT_ERL_BLC == [PB].fddiPORTLerFlag
50 SMT_ERL_NCC == fddiMACNotCopiedFlag
51 SMT_ERL_FEC == fddiMACFrameErrorFlag
52
53 END_MANUAL_ENTRY()
54 */
55u_long smt_get_error_word(struct s_smc *smc)
56{
57 u_long st;
58
59 /*
60 * smt error word low
61 */
62 st = 0 ;
63 if (smc->s.sas == SMT_SAS) {
64 if (smc->mib.p[PS].fddiPORTLerFlag)
65 st |= SMT_ERL_ALC ;
66 }
67 else {
68 if (smc->mib.p[PA].fddiPORTLerFlag)
69 st |= SMT_ERL_ALC ;
70 if (smc->mib.p[PB].fddiPORTLerFlag)
71 st |= SMT_ERL_BLC ;
72 }
73 if (smc->mib.m[MAC0].fddiMACNotCopiedFlag)
74 st |= SMT_ERL_NCC ; /* not copied condition */
75 if (smc->mib.m[MAC0].fddiMACFrameErrorFlag)
76 st |= SMT_ERL_FEC ; /* frame error condition */
77
78 return st;
79}
80
81/*
82 BEGIN_MANUAL_ENTRY(if,func;others;11)
83
84 u_long smt_get_event_word(smc)
85 struct s_smc *smc ;
86
87Function DOWNCALL (SMT, lnkstat.c)
88 This functions returns the SMT event work for AIX events.
89
90Return smt_event_word always 0
91
92 END_MANUAL_ENTRY()
93 */
94u_long smt_get_event_word(struct s_smc *smc)
95{
96 return (u_long) 0;
97}
98
99/*
100 BEGIN_MANUAL_ENTRY(if,func;others;11)
101
102 u_long smt_get_port_event_word(smc)
103 struct s_smc *smc ;
104
105Function DOWNCALL (SMT, lnkstat.c)
106 This functions returns the SMT port event work for AIX events.
107
108Return smt_port_event_word always 0
109
110 END_MANUAL_ENTRY()
111 */
112u_long smt_get_port_event_word(struct s_smc *smc)
113{
114 return (u_long) 0;
115}
116
117/*
118 BEGIN_MANUAL_ENTRY(if,func;others;11)
119
120 u_long smt_read_errorlog(smc,p,len)
121 struct s_smc *smc ;
122 char _far *p ;
123 int len ;
124
125Function DOWNCALL (SMT, lnkstat.c)
126 This functions returns the SMT error log field for AIX events.
127
128Para p pointer to the error log field
129 len len of the error log field
130
131Return len used len of the error log field
132
133 END_MANUAL_ENTRY()
134 */
135int smt_read_errorlog(struct s_smc *smc, char _far *p, int len)
136{
137 int i ;
138 int st ;
139 struct s_error_log _far *er ;
140
141 er = (struct s_error_log _far *) p ;
142 if (len > sizeof(struct s_error_log))
143 len = sizeof(struct s_error_log) ;
144 for (i = 0 ; i < len ; i++)
145 *p++ = 0 ;
146 /*
147 * set count
148 */
149 if (EL_IS_OK(set_count_high,len)) {
150 er->set_count_low = (u_short)smc->mib.fddiSMTSetCount.count ;
151 er->set_count_high =
152 (u_short)(smc->mib.fddiSMTSetCount.count >> 16L) ;
153 }
154 /*
155 * aci
156 */
157 if (EL_IS_OK(aci_id_code,len)) {
158 er->aci_id_code = 0 ;
159 }
160 /*
161 * purge counter is missed frames; 16 bits only
162 */
163 if (EL_IS_OK(purge_frame_counter,len)) {
164 if (smc->mib.m[MAC0].fddiMACCopied_Ct > 0xffff)
165 er->purge_frame_counter = 0xffff ;
166 else
167 er->purge_frame_counter =
168 (u_short)smc->mib.m[MAC0].fddiMACCopied_Ct ;
169 }
170 /*
171 * CMT and RMT state machines
172 */
173 if (EL_IS_OK(ecm_state,len))
174 er->ecm_state = smc->mib.fddiSMTECMState ;
175
176 if (EL_IS_OK(pcm_b_state,len)) {
177 if (smc->s.sas == SMT_SAS) {
178 er->pcm_a_state = smc->y[PS].mib->fddiPORTPCMState ;
179 er->pcm_b_state = 0 ;
180 }
181 else {
182 er->pcm_a_state = smc->y[PA].mib->fddiPORTPCMState ;
183 er->pcm_b_state = smc->y[PB].mib->fddiPORTPCMState ;
184 }
185 }
186 if (EL_IS_OK(cfm_state,len))
187 er->cfm_state = smc->mib.fddiSMTCF_State ;
188 if (EL_IS_OK(rmt_state,len))
189 er->rmt_state = smc->mib.m[MAC0].fddiMACRMTState ;
190
191 /*
192 * smt error word low (we only need the low order 16 bits.)
193 */
194
195 st = smt_get_error_word(smc) & 0xffff ;
196
197 if (EL_IS_OK(smt_error_low,len))
198 er->smt_error_low = st ;
199
200 if (EL_IS_OK(ucode_version_level,len))
201 er->ucode_version_level = 0x0101 ;
202 return(len) ;
203}
204
diff --git a/drivers/net/skfp/pcmplc.c b/drivers/net/skfp/pcmplc.c
index 571f055c096b..cd0aa4c151b0 100644
--- a/drivers/net/skfp/pcmplc.c
+++ b/drivers/net/skfp/pcmplc.c
@@ -1861,13 +1861,6 @@ void plc_irq(struct s_smc *smc, int np, unsigned int cmd)
1861#endif 1861#endif
1862} 1862}
1863 1863
1864void pcm_set_lct_short(struct s_smc *smc, int n)
1865{
1866 if (n <= 0 || n > 1000)
1867 return ;
1868 smc->s.lct_short = n ;
1869}
1870
1871#ifdef DEBUG 1864#ifdef DEBUG
1872/* 1865/*
1873 * fill state struct 1866 * fill state struct
diff --git a/drivers/net/skfp/pmf.c b/drivers/net/skfp/pmf.c
index f2b446d8b0bf..efc639c013fd 100644
--- a/drivers/net/skfp/pmf.c
+++ b/drivers/net/skfp/pmf.c
@@ -36,12 +36,13 @@ static int smt_authorize(struct s_smc *smc, struct smt_header *sm);
36static int smt_check_set_count(struct s_smc *smc, struct smt_header *sm); 36static int smt_check_set_count(struct s_smc *smc, struct smt_header *sm);
37static const struct s_p_tab* smt_get_ptab(u_short para); 37static const struct s_p_tab* smt_get_ptab(u_short para);
38static int smt_mib_phys(struct s_smc *smc); 38static int smt_mib_phys(struct s_smc *smc);
39int smt_set_para(struct s_smc *smc, struct smt_para *pa, int index, int local, 39static int smt_set_para(struct s_smc *smc, struct smt_para *pa, int index,
40 int set); 40 int local, int set);
41void smt_add_para(struct s_smc *smc, struct s_pcon *pcon, u_short para, 41void smt_add_para(struct s_smc *smc, struct s_pcon *pcon, u_short para,
42 int index, int local); 42 int index, int local);
43static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req, 43static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req,
44 int set, int local); 44 int set, int local);
45static int port_to_mib(struct s_smc *smc, int p);
45 46
46#define MOFFSS(e) ((int)&(((struct fddi_mib *)0)->e)) 47#define MOFFSS(e) ((int)&(((struct fddi_mib *)0)->e))
47#define MOFFSA(e) ((int) (((struct fddi_mib *)0)->e)) 48#define MOFFSA(e) ((int) (((struct fddi_mib *)0)->e))
@@ -1078,8 +1079,8 @@ wrong_error:
1078/* 1079/*
1079 * set parameter 1080 * set parameter
1080 */ 1081 */
1081int smt_set_para(struct s_smc *smc, struct smt_para *pa, int index, int local, 1082static int smt_set_para(struct s_smc *smc, struct smt_para *pa, int index,
1082 int set) 1083 int local, int set)
1083{ 1084{
1084#define IFSET(x) if (set) (x) 1085#define IFSET(x) if (set) (x)
1085 1086
@@ -1549,7 +1550,7 @@ static int smt_mib_phys(struct s_smc *smc)
1549#endif 1550#endif
1550} 1551}
1551 1552
1552int port_to_mib(struct s_smc *smc, int p) 1553static int port_to_mib(struct s_smc *smc, int p)
1553{ 1554{
1554#ifdef CONCENTRATOR 1555#ifdef CONCENTRATOR
1555 SK_UNUSED(smc) ; 1556 SK_UNUSED(smc) ;
diff --git a/drivers/net/skfp/skfddi.c b/drivers/net/skfp/skfddi.c
index c88aad6edd74..4b5ed2c63177 100644
--- a/drivers/net/skfp/skfddi.c
+++ b/drivers/net/skfp/skfddi.c
@@ -149,7 +149,6 @@ extern void hwm_rx_frag(struct s_smc *smc, char far * virt, u_long phys,
149extern void mac_drv_rx_mode(struct s_smc *smc, int mode); 149extern void mac_drv_rx_mode(struct s_smc *smc, int mode);
150extern void mac_drv_clear_rx_queue(struct s_smc *smc); 150extern void mac_drv_clear_rx_queue(struct s_smc *smc);
151extern void enable_tx_irq(struct s_smc *smc, u_short queue); 151extern void enable_tx_irq(struct s_smc *smc, u_short queue);
152extern void mac_drv_clear_txd(struct s_smc *smc);
153 152
154static struct pci_device_id skfddi_pci_tbl[] = { 153static struct pci_device_id skfddi_pci_tbl[] = {
155 { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, }, 154 { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, },
diff --git a/drivers/net/skfp/smt.c b/drivers/net/skfp/smt.c
index 71935eaf9d4e..f17c05cbe44b 100644
--- a/drivers/net/skfp/smt.c
+++ b/drivers/net/skfp/smt.c
@@ -86,7 +86,7 @@ static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
86static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest, 86static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
87 u_long tid, int local); 87 u_long tid, int local);
88#ifdef LITTLE_ENDIAN 88#ifdef LITTLE_ENDIAN
89static void smt_string_swap(void); 89static void smt_string_swap(char *data, const char *format, int len);
90#endif 90#endif
91static void smt_add_frame_len(SMbuf *mb, int len); 91static void smt_add_frame_len(SMbuf *mb, int len);
92static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una); 92static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una);
@@ -110,7 +110,7 @@ static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount
110static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed, 110static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
111 int len); 111 int len);
112 112
113void smt_clear_una_dna(struct s_smc *smc); 113static void smt_clear_una_dna(struct s_smc *smc);
114static void smt_clear_old_una_dna(struct s_smc *smc); 114static void smt_clear_old_una_dna(struct s_smc *smc);
115#ifdef CONCENTRATOR 115#ifdef CONCENTRATOR
116static int entity_to_index(void); 116static int entity_to_index(void);
@@ -118,7 +118,7 @@ static int entity_to_index(void);
118static void update_dac(struct s_smc *smc, int report); 118static void update_dac(struct s_smc *smc, int report);
119static int div_ratio(u_long upper, u_long lower); 119static int div_ratio(u_long upper, u_long lower);
120#ifdef USE_CAN_ADDR 120#ifdef USE_CAN_ADDR
121void hwm_conv_can(struct s_smc *smc, char *data, int len); 121static void hwm_conv_can(struct s_smc *smc, char *data, int len);
122#else 122#else
123#define hwm_conv_can(smc,data,len) 123#define hwm_conv_can(smc,data,len)
124#endif 124#endif
@@ -216,24 +216,6 @@ void smt_agent_task(struct s_smc *smc)
216 DB_SMT("SMT agent task\n",0,0) ; 216 DB_SMT("SMT agent task\n",0,0) ;
217} 217}
218 218
219void smt_please_reconnect(struct s_smc *smc, int reconn_time)
220/* struct s_smc *smc; Pointer to SMT context */
221/* int reconn_time; Wait for reconnect time in seconds */
222{
223 /*
224 * The please reconnect variable is used as a timer.
225 * It is decremented each time smt_event is called.
226 * This happens every second or when smt_force_irq is called.
227 * Note: smt_force_irq () is called on some packet receives and
228 * when a multicast address is changed. Since nothing
229 * is received during the disconnect and the multicast
230 * address changes can be viewed as not very often and
231 * the timer runs out close to its given value
232 * (reconn_time).
233 */
234 smc->sm.please_reconnect = reconn_time ;
235}
236
237#ifndef SMT_REAL_TOKEN_CT 219#ifndef SMT_REAL_TOKEN_CT
238void smt_emulate_token_ct(struct s_smc *smc, int mac_index) 220void smt_emulate_token_ct(struct s_smc *smc, int mac_index)
239{ 221{
@@ -1574,7 +1556,7 @@ static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long see
1574 * clear DNA and UNA 1556 * clear DNA and UNA
1575 * called from CFM if configuration changes 1557 * called from CFM if configuration changes
1576 */ 1558 */
1577void smt_clear_una_dna(struct s_smc *smc) 1559static void smt_clear_una_dna(struct s_smc *smc)
1578{ 1560{
1579 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ; 1561 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
1580 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ; 1562 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
@@ -2058,30 +2040,10 @@ int smt_action(struct s_smc *smc, int class, int code, int index)
2058} 2040}
2059 2041
2060/* 2042/*
2061 * change tneg
2062 * set T_Req in MIB (Path Attribute)
2063 * calculate new values for MAC
2064 * if change required
2065 * disconnect
2066 * set reconnect
2067 * end
2068 */
2069void smt_change_t_neg(struct s_smc *smc, u_long tneg)
2070{
2071 smc->mib.a[PATH0].fddiPATHMaxT_Req = tneg ;
2072
2073 if (smt_set_mac_opvalues(smc)) {
2074 RS_SET(smc,RS_EVENT) ;
2075 smc->sm.please_reconnect = 1 ;
2076 queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
2077 }
2078}
2079
2080/*
2081 * canonical conversion of <len> bytes beginning form *data 2043 * canonical conversion of <len> bytes beginning form *data
2082 */ 2044 */
2083#ifdef USE_CAN_ADDR 2045#ifdef USE_CAN_ADDR
2084void hwm_conv_can(struct s_smc *smc, char *data, int len) 2046static void hwm_conv_can(struct s_smc *smc, char *data, int len)
2085{ 2047{
2086 int i ; 2048 int i ;
2087 2049
diff --git a/drivers/net/skfp/smtdef.c b/drivers/net/skfp/smtdef.c
index 5a0c8db816d8..4e07ff7073f1 100644
--- a/drivers/net/skfp/smtdef.c
+++ b/drivers/net/skfp/smtdef.c
@@ -76,11 +76,6 @@ void smt_reset_defaults(struct s_smc *smc, int level);
76static void smt_init_mib(struct s_smc *smc, int level); 76static void smt_init_mib(struct s_smc *smc, int level);
77static int set_min_max(int maxflag, u_long mib, u_long limit, u_long *oper); 77static int set_min_max(int maxflag, u_long mib, u_long limit, u_long *oper);
78 78
79void smt_set_defaults(struct s_smc *smc)
80{
81 smt_reset_defaults(smc,0) ;
82}
83
84#define MS2BCLK(x) ((x)*12500L) 79#define MS2BCLK(x) ((x)*12500L)
85#define US2BCLK(x) ((x)*1250L) 80#define US2BCLK(x) ((x)*1250L)
86 81
diff --git a/drivers/net/skfp/smtparse.c b/drivers/net/skfp/smtparse.c
deleted file mode 100644
index d5779e414dbe..000000000000
--- a/drivers/net/skfp/smtparse.c
+++ /dev/null
@@ -1,467 +0,0 @@
1/******************************************************************************
2 *
3 * (C)Copyright 1998,1999 SysKonnect,
4 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
5 *
6 * See the file "skfddi.c" for further information.
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 * The information in this file is provided "AS IS" without warranty.
14 *
15 ******************************************************************************/
16
17
18/*
19 parser for SMT parameters
20*/
21
22#include "h/types.h"
23#include "h/fddi.h"
24#include "h/smc.h"
25#include "h/smt_p.h"
26
27#define KERNEL
28#include "h/smtstate.h"
29
30#ifndef lint
31static const char ID_sccs[] = "@(#)smtparse.c 1.12 98/10/06 (C) SK " ;
32#endif
33
34#ifdef sun
35#define _far
36#endif
37
38/*
39 * convert to BCLK units
40 */
41#define MS2BCLK(x) ((x)*12500L)
42#define US2BCLK(x) ((x/10)*125L)
43
44/*
45 * parameter table
46 */
47static struct s_ptab {
48 char *pt_name ;
49 u_short pt_num ;
50 u_short pt_type ;
51 u_long pt_min ;
52 u_long pt_max ;
53} ptab[] = {
54 { "PMFPASSWD",0, 0 } ,
55 { "USERDATA",1, 0 } ,
56 { "LERCUTOFFA",2, 1, 4, 15 } ,
57 { "LERCUTOFFB",3, 1, 4, 15 } ,
58 { "LERALARMA",4, 1, 4, 15 } ,
59 { "LERALARMB",5, 1, 4, 15 } ,
60 { "TMAX",6, 1, 5, 165 } ,
61 { "TMIN",7, 1, 5, 165 } ,
62 { "TREQ",8, 1, 5, 165 } ,
63 { "TVX",9, 1, 2500, 10000 } ,
64#ifdef ESS
65 { "SBAPAYLOAD",10, 1, 0, 1562 } ,
66 { "SBAOVERHEAD",11, 1, 50, 5000 } ,
67 { "MAXTNEG",12, 1, 5, 165 } ,
68 { "MINSEGMENTSIZE",13, 1, 0, 4478 } ,
69 { "SBACATEGORY",14, 1, 0, 0xffff } ,
70 { "SYNCHTXMODE",15, 0 } ,
71#endif
72#ifdef SBA
73 { "SBACOMMAND",16, 0 } ,
74 { "SBAAVAILABLE",17, 1, 0, 100 } ,
75#endif
76 { NULL }
77} ;
78
79/* Define maximum string size for values and keybuffer */
80#define MAX_VAL 40
81
82/*
83 * local function declarations
84 */
85static u_long parse_num(int type, char _far *value, char *v, u_long mn,
86 u_long mx, int scale);
87static int parse_word(char *buf, char _far *text);
88
89#ifdef SIM
90#define DB_MAIN(a,b,c) printf(a,b,c)
91#else
92#define DB_MAIN(a,b,c)
93#endif
94
95/*
96 * BEGIN_MANUAL_ENTRY()
97 *
98 * int smt_parse_arg(struct s_smc *,char _far *keyword,int type,
99 char _far *value)
100 *
101 * parse SMT parameter
102 * *keyword
103 * pointer to keyword, must be \0, \n or \r terminated
104 * *value pointer to value, either char * or u_long *
105 * if char *
106 * pointer to value, must be \0, \n or \r terminated
107 * if u_long *
108 * contains binary value
109 *
110 * type 0: integer
111 * 1: string
112 * return
113 * 0 parameter parsed ok
114 * != 0 error
115 * NOTE:
116 * function can be called with DS != SS
117 *
118 *
119 * END_MANUAL_ENTRY()
120 */
121int smt_parse_arg(struct s_smc *smc, char _far *keyword, int type,
122 char _far *value)
123{
124 char keybuf[MAX_VAL+1];
125 char valbuf[MAX_VAL+1];
126 char c ;
127 char *p ;
128 char *v ;
129 char *d ;
130 u_long val = 0 ;
131 struct s_ptab *pt ;
132 int st ;
133 int i ;
134
135 /*
136 * parse keyword
137 */
138 if ((st = parse_word(keybuf,keyword)))
139 return(st) ;
140 /*
141 * parse value if given as string
142 */
143 if (type == 1) {
144 if ((st = parse_word(valbuf,value)))
145 return(st) ;
146 }
147 /*
148 * search in table
149 */
150 st = 0 ;
151 for (pt = ptab ; (v = pt->pt_name) ; pt++) {
152 for (p = keybuf ; (c = *p) ; p++,v++) {
153 if (c != *v)
154 break ;
155 }
156 if (!c && !*v)
157 break ;
158 }
159 if (!v)
160 return(-1) ;
161#if 0
162 printf("=>%s<==>%s<=\n",pt->pt_name,valbuf) ;
163#endif
164 /*
165 * set value in MIB
166 */
167 if (pt->pt_type)
168 val = parse_num(type,value,valbuf,pt->pt_min,pt->pt_max,1) ;
169 switch (pt->pt_num) {
170 case 0 :
171 v = valbuf ;
172 d = (char *) smc->mib.fddiPRPMFPasswd ;
173 for (i = 0 ; i < (signed)sizeof(smc->mib.fddiPRPMFPasswd) ; i++)
174 *d++ = *v++ ;
175 DB_MAIN("SET %s = %s\n",pt->pt_name,smc->mib.fddiPRPMFPasswd) ;
176 break ;
177 case 1 :
178 v = valbuf ;
179 d = (char *) smc->mib.fddiSMTUserData ;
180 for (i = 0 ; i < (signed)sizeof(smc->mib.fddiSMTUserData) ; i++)
181 *d++ = *v++ ;
182 DB_MAIN("SET %s = %s\n",pt->pt_name,smc->mib.fddiSMTUserData) ;
183 break ;
184 case 2 :
185 smc->mib.p[PA].fddiPORTLer_Cutoff = (u_char) val ;
186 DB_MAIN("SET %s = %d\n",
187 pt->pt_name,smc->mib.p[PA].fddiPORTLer_Cutoff) ;
188 break ;
189 case 3 :
190 smc->mib.p[PB].fddiPORTLer_Cutoff = (u_char) val ;
191 DB_MAIN("SET %s = %d\n",
192 pt->pt_name,smc->mib.p[PB].fddiPORTLer_Cutoff) ;
193 break ;
194 case 4 :
195 smc->mib.p[PA].fddiPORTLer_Alarm = (u_char) val ;
196 DB_MAIN("SET %s = %d\n",
197 pt->pt_name,smc->mib.p[PA].fddiPORTLer_Alarm) ;
198 break ;
199 case 5 :
200 smc->mib.p[PB].fddiPORTLer_Alarm = (u_char) val ;
201 DB_MAIN("SET %s = %d\n",
202 pt->pt_name,smc->mib.p[PB].fddiPORTLer_Alarm) ;
203 break ;
204 case 6 : /* TMAX */
205 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
206 smc->mib.a[PATH0].fddiPATHT_MaxLowerBound =
207 (u_long) -MS2BCLK((long)val) ;
208 break ;
209 case 7 : /* TMIN */
210 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
211 smc->mib.m[MAC0].fddiMACT_Min =
212 (u_long) -MS2BCLK((long)val) ;
213 break ;
214 case 8 : /* TREQ */
215 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
216 smc->mib.a[PATH0].fddiPATHMaxT_Req =
217 (u_long) -MS2BCLK((long)val) ;
218 break ;
219 case 9 : /* TVX */
220 DB_MAIN("SET %s = %d \n",pt->pt_name,val) ;
221 smc->mib.a[PATH0].fddiPATHTVXLowerBound =
222 (u_long) -US2BCLK((long)val) ;
223 break ;
224#ifdef ESS
225 case 10 : /* SBAPAYLOAD */
226 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
227 if (smc->mib.fddiESSPayload != val) {
228 smc->ess.raf_act_timer_poll = TRUE ;
229 smc->mib.fddiESSPayload = val ;
230 }
231 break ;
232 case 11 : /* SBAOVERHEAD */
233 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
234 smc->mib.fddiESSOverhead = val ;
235 break ;
236 case 12 : /* MAXTNEG */
237 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
238 smc->mib.fddiESSMaxTNeg = (u_long) -MS2BCLK((long)val) ;
239 break ;
240 case 13 : /* MINSEGMENTSIZE */
241 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
242 smc->mib.fddiESSMinSegmentSize = val ;
243 break ;
244 case 14 : /* SBACATEGORY */
245 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
246 smc->mib.fddiESSCategory =
247 (smc->mib.fddiESSCategory & 0xffff) |
248 ((u_long)(val << 16)) ;
249 break ;
250 case 15 : /* SYNCHTXMODE */
251 /* do not use memcmp(valbuf,"ALL",3) because DS != SS */
252 if (valbuf[0] == 'A' && valbuf[1] == 'L' && valbuf[2] == 'L') {
253 smc->mib.fddiESSSynchTxMode = TRUE ;
254 DB_MAIN("SET %s = %s\n",pt->pt_name,valbuf) ;
255 }
256 /* if (!memcmp(valbuf,"SPLIT",5)) { */
257 if (valbuf[0] == 'S' && valbuf[1] == 'P' && valbuf[2] == 'L' &&
258 valbuf[3] == 'I' && valbuf[4] == 'T') {
259 DB_MAIN("SET %s = %s\n",pt->pt_name,valbuf) ;
260 smc->mib.fddiESSSynchTxMode = FALSE ;
261 }
262 break ;
263#endif
264#ifdef SBA
265 case 16 : /* SBACOMMAND */
266 /* if (!memcmp(valbuf,"START",5)) { */
267 if (valbuf[0] == 'S' && valbuf[1] == 'T' && valbuf[2] == 'A' &&
268 valbuf[3] == 'R' && valbuf[4] == 'T') {
269 DB_MAIN("SET %s = %s\n",pt->pt_name,valbuf) ;
270 smc->mib.fddiSBACommand = SB_START ;
271 }
272 /* if (!memcmp(valbuf,"STOP",4)) { */
273 if (valbuf[0] == 'S' && valbuf[1] == 'T' && valbuf[2] == 'O' &&
274 valbuf[3] == 'P') {
275 DB_MAIN("SET %s = %s\n",pt->pt_name,valbuf) ;
276 smc->mib.fddiSBACommand = SB_STOP ;
277 }
278 break ;
279 case 17 : /* SBAAVAILABLE */
280 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
281 smc->mib.fddiSBAAvailable = (u_char) val ;
282 break ;
283#endif
284 }
285 return(0) ;
286}
287
288static int parse_word(char *buf, char _far *text)
289{
290 char c ;
291 char *p ;
292 int p_len ;
293 int quote ;
294 int i ;
295 int ok ;
296
297 /*
298 * skip leading white space
299 */
300 p = buf ;
301 for (i = 0 ; i < MAX_VAL ; i++)
302 *p++ = 0 ;
303 p = buf ;
304 p_len = 0 ;
305 ok = 0 ;
306 while ( (c = *text++) && (c != '\n') && (c != '\r')) {
307 if ((c != ' ') && (c != '\t')) {
308 ok = 1 ;
309 break ;
310 }
311 }
312 if (!ok)
313 return(-1) ;
314 if (c == '"') {
315 quote = 1 ;
316 }
317 else {
318 quote = 0 ;
319 text-- ;
320 }
321 /*
322 * parse valbuf
323 */
324 ok = 0 ;
325 while (!ok && p_len < MAX_VAL-1 && (c = *text++) && (c != '\n')
326 && (c != '\r')) {
327 switch (quote) {
328 case 0 :
329 if ((c == ' ') || (c == '\t') || (c == '=')) {
330 ok = 1 ;
331 break ;
332 }
333 *p++ = c ;
334 p_len++ ;
335 break ;
336 case 2 :
337 *p++ = c ;
338 p_len++ ;
339 quote = 1 ;
340 break ;
341 case 1 :
342 switch (c) {
343 case '"' :
344 ok = 1 ;
345 break ;
346 case '\\' :
347 quote = 2 ;
348 break ;
349 default :
350 *p++ = c ;
351 p_len++ ;
352 }
353 }
354 }
355 *p++ = 0 ;
356 for (p = buf ; (c = *p) ; p++) {
357 if (c >= 'a' && c <= 'z')
358 *p = c + 'A' - 'a' ;
359 }
360 return(0) ;
361}
362
363static u_long parse_num(int type, char _far *value, char *v, u_long mn,
364 u_long mx, int scale)
365{
366 u_long x = 0 ;
367 char c ;
368
369 if (type == 0) { /* integer */
370 u_long _far *l ;
371 u_long u1 ;
372
373 l = (u_long _far *) value ;
374 u1 = *l ;
375 /*
376 * if the value is negative take the lower limit
377 */
378 if ((long)u1 < 0) {
379 if (- ((long)u1) > (long) mx) {
380 u1 = 0 ;
381 }
382 else {
383 u1 = (u_long) - ((long)u1) ;
384 }
385 }
386 x = u1 ;
387 }
388 else { /* string */
389 int sign = 0 ;
390
391 if (*v == '-') {
392 sign = 1 ;
393 }
394 while ((c = *v++) && (c >= '0') && (c <= '9')) {
395 x = x * 10 + c - '0' ;
396 }
397 if (scale == 10) {
398 x *= 10 ;
399 if (c == '.') {
400 if ((c = *v++) && (c >= '0') && (c <= '9')) {
401 x += c - '0' ;
402 }
403 }
404 }
405 if (sign)
406 x = (u_long) - ((long)x) ;
407 }
408 /*
409 * if the value is negative
410 * and the absolute value is outside the limits
411 * take the lower limit
412 * else
413 * take the absoute value
414 */
415 if ((long)x < 0) {
416 if (- ((long)x) > (long) mx) {
417 x = 0 ;
418 }
419 else {
420 x = (u_long) - ((long)x) ;
421 }
422 }
423 if (x < mn)
424 return(mn) ;
425 else if (x > mx)
426 return(mx) ;
427 return(x) ;
428}
429
430#if 0
431struct s_smc SMC ;
432main()
433{
434 char *p ;
435 char *v ;
436 char buf[100] ;
437 int toggle = 0 ;
438
439 while (gets(buf)) {
440 p = buf ;
441 while (*p && ((*p == ' ') || (*p == '\t')))
442 p++ ;
443
444 while (*p && ((*p != ' ') && (*p != '\t')))
445 p++ ;
446
447 v = p ;
448 while (*v && ((*v == ' ') || (*v == '\t')))
449 v++ ;
450 if ((*v >= '0') && (*v <= '9')) {
451 toggle = !toggle ;
452 if (toggle) {
453 u_long l ;
454 l = atol(v) ;
455 smt_parse_arg(&SMC,buf,0,(char _far *)&l) ;
456 }
457 else
458 smt_parse_arg(&SMC,buf,1,(char _far *)p) ;
459 }
460 else {
461 smt_parse_arg(&SMC,buf,1,(char _far *)p) ;
462 }
463 }
464 exit(0) ;
465}
466#endif
467
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index 30e8d589d167..3dbb1cb09ed8 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -7,7 +7,7 @@
7 * of the original driver such as link fail-over and link management because 7 * of the original driver such as link fail-over and link management because
8 * those should be done at higher levels. 8 * those should be done at higher levels.
9 * 9 *
10 * Copyright (C) 2004, Stephen Hemminger <shemminger@osdl.org> 10 * Copyright (C) 2004, 2005 Stephen Hemminger <shemminger@osdl.org>
11 * 11 *
12 * This program is free software; you can redistribute it and/or modify 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 13 * it under the terms of the GNU General Public License as published by
@@ -42,19 +42,20 @@
42#include "skge.h" 42#include "skge.h"
43 43
44#define DRV_NAME "skge" 44#define DRV_NAME "skge"
45#define DRV_VERSION "0.6" 45#define DRV_VERSION "0.7"
46#define PFX DRV_NAME " " 46#define PFX DRV_NAME " "
47 47
48#define DEFAULT_TX_RING_SIZE 128 48#define DEFAULT_TX_RING_SIZE 128
49#define DEFAULT_RX_RING_SIZE 512 49#define DEFAULT_RX_RING_SIZE 512
50#define MAX_TX_RING_SIZE 1024 50#define MAX_TX_RING_SIZE 1024
51#define MAX_RX_RING_SIZE 4096 51#define MAX_RX_RING_SIZE 4096
52#define RX_COPY_THRESHOLD 128
53#define RX_BUF_SIZE 1536
52#define PHY_RETRIES 1000 54#define PHY_RETRIES 1000
53#define ETH_JUMBO_MTU 9000 55#define ETH_JUMBO_MTU 9000
54#define TX_WATCHDOG (5 * HZ) 56#define TX_WATCHDOG (5 * HZ)
55#define NAPI_WEIGHT 64 57#define NAPI_WEIGHT 64
56#define BLINK_HZ (HZ/4) 58#define BLINK_HZ (HZ/4)
57#define LINK_POLL_HZ (HZ/10)
58 59
59MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver"); 60MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver");
60MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>"); 61MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>");
@@ -70,28 +71,17 @@ module_param(debug, int, 0);
70MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); 71MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
71 72
72static const struct pci_device_id skge_id_table[] = { 73static const struct pci_device_id skge_id_table[] = {
73 { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940, 74 { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940) },
74 PCI_ANY_ID, PCI_ANY_ID }, 75 { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940B) },
75 { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940B, 76 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE) },
76 PCI_ANY_ID, PCI_ANY_ID }, 77 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU) },
77 { PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE, 78 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) }, /* SK-9Exx */
78 PCI_ANY_ID, PCI_ANY_ID }, 79 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T), },
79 { PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU, 80 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) },
80 PCI_ANY_ID, PCI_ANY_ID }, 81 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */
81 { PCI_VENDOR_ID_SYSKONNECT, 0x9E00, /* SK-9Exx */ 82 { PCI_DEVICE(PCI_VENDOR_ID_CNET, PCI_DEVICE_ID_CNET_GIGACARD) },
82 PCI_ANY_ID, PCI_ANY_ID }, 83 { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1032) },
83 { PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T, 84 { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1064) },
84 PCI_ANY_ID, PCI_ANY_ID },
85 { PCI_VENDOR_ID_MARVELL, 0x4320, /* Gigabit Ethernet Controller */
86 PCI_ANY_ID, PCI_ANY_ID },
87 { PCI_VENDOR_ID_MARVELL, 0x5005, /* Marvell (11ab), Belkin */
88 PCI_ANY_ID, PCI_ANY_ID },
89 { PCI_VENDOR_ID_CNET, PCI_DEVICE_ID_CNET_GIGACARD,
90 PCI_ANY_ID, PCI_ANY_ID },
91 { PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1032,
92 PCI_ANY_ID, PCI_ANY_ID },
93 { PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1064,
94 PCI_ANY_ID, PCI_ANY_ID },
95 { 0 } 85 { 0 }
96}; 86};
97MODULE_DEVICE_TABLE(pci, skge_id_table); 87MODULE_DEVICE_TABLE(pci, skge_id_table);
@@ -99,19 +89,22 @@ MODULE_DEVICE_TABLE(pci, skge_id_table);
99static int skge_up(struct net_device *dev); 89static int skge_up(struct net_device *dev);
100static int skge_down(struct net_device *dev); 90static int skge_down(struct net_device *dev);
101static void skge_tx_clean(struct skge_port *skge); 91static void skge_tx_clean(struct skge_port *skge);
102static void skge_xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val); 92static void xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val);
103static void skge_gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val); 93static void gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val);
104static void genesis_get_stats(struct skge_port *skge, u64 *data); 94static void genesis_get_stats(struct skge_port *skge, u64 *data);
105static void yukon_get_stats(struct skge_port *skge, u64 *data); 95static void yukon_get_stats(struct skge_port *skge, u64 *data);
106static void yukon_init(struct skge_hw *hw, int port); 96static void yukon_init(struct skge_hw *hw, int port);
107static void yukon_reset(struct skge_hw *hw, int port); 97static void yukon_reset(struct skge_hw *hw, int port);
108static void genesis_mac_init(struct skge_hw *hw, int port); 98static void genesis_mac_init(struct skge_hw *hw, int port);
109static void genesis_reset(struct skge_hw *hw, int port); 99static void genesis_reset(struct skge_hw *hw, int port);
100static void genesis_link_up(struct skge_port *skge);
110 101
102/* Avoid conditionals by using array */
111static const int txqaddr[] = { Q_XA1, Q_XA2 }; 103static const int txqaddr[] = { Q_XA1, Q_XA2 };
112static const int rxqaddr[] = { Q_R1, Q_R2 }; 104static const int rxqaddr[] = { Q_R1, Q_R2 };
113static const u32 rxirqmask[] = { IS_R1_F, IS_R2_F }; 105static const u32 rxirqmask[] = { IS_R1_F, IS_R2_F };
114static 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 };
115 108
116/* Don't need to look at whole 16K. 109/* Don't need to look at whole 16K.
117 * last interesting register is descriptor poll timer. 110 * last interesting register is descriptor poll timer.
@@ -154,7 +147,7 @@ static void skge_get_regs(struct net_device *dev, struct ethtool_regs *regs,
154static int wol_supported(const struct skge_hw *hw) 147static int wol_supported(const struct skge_hw *hw)
155{ 148{
156 return !((hw->chip_id == CHIP_ID_GENESIS || 149 return !((hw->chip_id == CHIP_ID_GENESIS ||
157 (hw->chip_id == CHIP_ID_YUKON && chip_rev(hw) == 0))); 150 (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)));
158} 151}
159 152
160static void skge_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 153static void skge_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
@@ -170,7 +163,7 @@ static int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
170 struct skge_port *skge = netdev_priv(dev); 163 struct skge_port *skge = netdev_priv(dev);
171 struct skge_hw *hw = skge->hw; 164 struct skge_hw *hw = skge->hw;
172 165
173 if(wol->wolopts != WAKE_MAGIC && wol->wolopts != 0) 166 if (wol->wolopts != WAKE_MAGIC && wol->wolopts != 0)
174 return -EOPNOTSUPP; 167 return -EOPNOTSUPP;
175 168
176 if (wol->wolopts == WAKE_MAGIC && !wol_supported(hw)) 169 if (wol->wolopts == WAKE_MAGIC && !wol_supported(hw))
@@ -190,6 +183,36 @@ static int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
190 return 0; 183 return 0;
191} 184}
192 185
186/* Determine supported/adverised modes based on hardware.
187 * Note: ethtoool ADVERTISED_xxx == SUPPORTED_xxx
188 */
189static u32 skge_supported_modes(const struct skge_hw *hw)
190{
191 u32 supported;
192
193 if (iscopper(hw)) {
194 supported = SUPPORTED_10baseT_Half
195 | SUPPORTED_10baseT_Full
196 | SUPPORTED_100baseT_Half
197 | SUPPORTED_100baseT_Full
198 | SUPPORTED_1000baseT_Half
199 | SUPPORTED_1000baseT_Full
200 | SUPPORTED_Autoneg| SUPPORTED_TP;
201
202 if (hw->chip_id == CHIP_ID_GENESIS)
203 supported &= ~(SUPPORTED_10baseT_Half
204 | SUPPORTED_10baseT_Full
205 | SUPPORTED_100baseT_Half
206 | SUPPORTED_100baseT_Full);
207
208 else if (hw->chip_id == CHIP_ID_YUKON)
209 supported &= ~SUPPORTED_1000baseT_Half;
210 } else
211 supported = SUPPORTED_1000baseT_Full | SUPPORTED_FIBRE
212 | SUPPORTED_Autoneg;
213
214 return supported;
215}
193 216
194static int skge_get_settings(struct net_device *dev, 217static int skge_get_settings(struct net_device *dev,
195 struct ethtool_cmd *ecmd) 218 struct ethtool_cmd *ecmd)
@@ -198,38 +221,13 @@ static int skge_get_settings(struct net_device *dev,
198 struct skge_hw *hw = skge->hw; 221 struct skge_hw *hw = skge->hw;
199 222
200 ecmd->transceiver = XCVR_INTERNAL; 223 ecmd->transceiver = XCVR_INTERNAL;
224 ecmd->supported = skge_supported_modes(hw);
201 225
202 if (iscopper(hw)) { 226 if (iscopper(hw)) {
203 if (hw->chip_id == CHIP_ID_GENESIS)
204 ecmd->supported = SUPPORTED_1000baseT_Full
205 | SUPPORTED_1000baseT_Half
206 | SUPPORTED_Autoneg | SUPPORTED_TP;
207 else {
208 ecmd->supported = SUPPORTED_10baseT_Half
209 | SUPPORTED_10baseT_Full
210 | SUPPORTED_100baseT_Half
211 | SUPPORTED_100baseT_Full
212 | SUPPORTED_1000baseT_Half
213 | SUPPORTED_1000baseT_Full
214 | SUPPORTED_Autoneg| SUPPORTED_TP;
215
216 if (hw->chip_id == CHIP_ID_YUKON)
217 ecmd->supported &= ~SUPPORTED_1000baseT_Half;
218
219 else if (hw->chip_id == CHIP_ID_YUKON_FE)
220 ecmd->supported &= ~(SUPPORTED_1000baseT_Half
221 | SUPPORTED_1000baseT_Full);
222 }
223
224 ecmd->port = PORT_TP; 227 ecmd->port = PORT_TP;
225 ecmd->phy_address = hw->phy_addr; 228 ecmd->phy_address = hw->phy_addr;
226 } else { 229 } else
227 ecmd->supported = SUPPORTED_1000baseT_Full
228 | SUPPORTED_FIBRE
229 | SUPPORTED_Autoneg;
230
231 ecmd->port = PORT_FIBRE; 230 ecmd->port = PORT_FIBRE;
232 }
233 231
234 ecmd->advertising = skge->advertising; 232 ecmd->advertising = skge->advertising;
235 ecmd->autoneg = skge->autoneg; 233 ecmd->autoneg = skge->autoneg;
@@ -238,65 +236,57 @@ static int skge_get_settings(struct net_device *dev,
238 return 0; 236 return 0;
239} 237}
240 238
241static u32 skge_modes(const struct skge_hw *hw)
242{
243 u32 modes = ADVERTISED_Autoneg
244 | ADVERTISED_1000baseT_Full | ADVERTISED_1000baseT_Half
245 | ADVERTISED_100baseT_Full | ADVERTISED_100baseT_Half
246 | ADVERTISED_10baseT_Full | ADVERTISED_10baseT_Half;
247
248 if (iscopper(hw)) {
249 modes |= ADVERTISED_TP;
250 switch(hw->chip_id) {
251 case CHIP_ID_GENESIS:
252 modes &= ~(ADVERTISED_100baseT_Full
253 | ADVERTISED_100baseT_Half
254 | ADVERTISED_10baseT_Full
255 | ADVERTISED_10baseT_Half);
256 break;
257
258 case CHIP_ID_YUKON:
259 modes &= ~ADVERTISED_1000baseT_Half;
260 break;
261
262 case CHIP_ID_YUKON_FE:
263 modes &= ~(ADVERTISED_1000baseT_Half|ADVERTISED_1000baseT_Full);
264 break;
265 }
266 } else {
267 modes |= ADVERTISED_FIBRE;
268 modes &= ~ADVERTISED_1000baseT_Half;
269 }
270 return modes;
271}
272
273static int skge_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) 239static int skge_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
274{ 240{
275 struct skge_port *skge = netdev_priv(dev); 241 struct skge_port *skge = netdev_priv(dev);
276 const struct skge_hw *hw = skge->hw; 242 const struct skge_hw *hw = skge->hw;
243 u32 supported = skge_supported_modes(hw);
277 244
278 if (ecmd->autoneg == AUTONEG_ENABLE) { 245 if (ecmd->autoneg == AUTONEG_ENABLE) {
279 if (ecmd->advertising & skge_modes(hw)) 246 ecmd->advertising = supported;
280 return -EINVAL; 247 skge->duplex = -1;
248 skge->speed = -1;
281 } else { 249 } else {
250 u32 setting;
251
282 switch(ecmd->speed) { 252 switch(ecmd->speed) {
283 case SPEED_1000: 253 case SPEED_1000:
284 if (hw->chip_id == CHIP_ID_YUKON_FE) 254 if (ecmd->duplex == DUPLEX_FULL)
255 setting = SUPPORTED_1000baseT_Full;
256 else if (ecmd->duplex == DUPLEX_HALF)
257 setting = SUPPORTED_1000baseT_Half;
258 else
285 return -EINVAL; 259 return -EINVAL;
286 break; 260 break;
287 case SPEED_100: 261 case SPEED_100:
262 if (ecmd->duplex == DUPLEX_FULL)
263 setting = SUPPORTED_100baseT_Full;
264 else if (ecmd->duplex == DUPLEX_HALF)
265 setting = SUPPORTED_100baseT_Half;
266 else
267 return -EINVAL;
268 break;
269
288 case SPEED_10: 270 case SPEED_10:
289 if (iscopper(hw) || hw->chip_id == CHIP_ID_GENESIS) 271 if (ecmd->duplex == DUPLEX_FULL)
272 setting = SUPPORTED_10baseT_Full;
273 else if (ecmd->duplex == DUPLEX_HALF)
274 setting = SUPPORTED_10baseT_Half;
275 else
290 return -EINVAL; 276 return -EINVAL;
291 break; 277 break;
292 default: 278 default:
293 return -EINVAL; 279 return -EINVAL;
294 } 280 }
281
282 if ((setting & supported) == 0)
283 return -EINVAL;
284
285 skge->speed = ecmd->speed;
286 skge->duplex = ecmd->duplex;
295 } 287 }
296 288
297 skge->autoneg = ecmd->autoneg; 289 skge->autoneg = ecmd->autoneg;
298 skge->speed = ecmd->speed;
299 skge->duplex = ecmd->duplex;
300 skge->advertising = ecmd->advertising; 290 skge->advertising = ecmd->advertising;
301 291
302 if (netif_running(dev)) { 292 if (netif_running(dev)) {
@@ -393,7 +383,7 @@ static void skge_get_strings(struct net_device *dev, u32 stringset, u8 *data)
393{ 383{
394 int i; 384 int i;
395 385
396 switch(stringset) { 386 switch (stringset) {
397 case ETH_SS_STATS: 387 case ETH_SS_STATS:
398 for (i = 0; i < ARRAY_SIZE(skge_stats); i++) 388 for (i = 0; i < ARRAY_SIZE(skge_stats); i++)
399 memcpy(data + i * ETH_GSTRING_LEN, 389 memcpy(data + i * ETH_GSTRING_LEN,
@@ -511,14 +501,6 @@ static int skge_set_rx_csum(struct net_device *dev, u32 data)
511 return 0; 501 return 0;
512} 502}
513 503
514/* Only Yukon II supports TSO (not implemented yet) */
515static int skge_set_tso(struct net_device *dev, u32 data)
516{
517 if (data)
518 return -EOPNOTSUPP;
519 return 0;
520}
521
522static void skge_get_pauseparam(struct net_device *dev, 504static void skge_get_pauseparam(struct net_device *dev,
523 struct ethtool_pauseparam *ecmd) 505 struct ethtool_pauseparam *ecmd)
524{ 506{
@@ -540,9 +522,9 @@ static int skge_set_pauseparam(struct net_device *dev,
540 skge->autoneg = ecmd->autoneg; 522 skge->autoneg = ecmd->autoneg;
541 if (ecmd->rx_pause && ecmd->tx_pause) 523 if (ecmd->rx_pause && ecmd->tx_pause)
542 skge->flow_control = FLOW_MODE_SYMMETRIC; 524 skge->flow_control = FLOW_MODE_SYMMETRIC;
543 else if(ecmd->rx_pause && !ecmd->tx_pause) 525 else if (ecmd->rx_pause && !ecmd->tx_pause)
544 skge->flow_control = FLOW_MODE_REM_SEND; 526 skge->flow_control = FLOW_MODE_REM_SEND;
545 else if(!ecmd->rx_pause && ecmd->tx_pause) 527 else if (!ecmd->rx_pause && ecmd->tx_pause)
546 skge->flow_control = FLOW_MODE_LOC_SEND; 528 skge->flow_control = FLOW_MODE_LOC_SEND;
547 else 529 else
548 skge->flow_control = FLOW_MODE_NONE; 530 skge->flow_control = FLOW_MODE_NONE;
@@ -559,8 +541,6 @@ static inline u32 hwkhz(const struct skge_hw *hw)
559{ 541{
560 if (hw->chip_id == CHIP_ID_GENESIS) 542 if (hw->chip_id == CHIP_ID_GENESIS)
561 return 53215; /* or: 53.125 MHz */ 543 return 53215; /* or: 53.125 MHz */
562 else if (hw->chip_id == CHIP_ID_YUKON_EC)
563 return 125000; /* or: 125.000 MHz */
564 else 544 else
565 return 78215; /* or: 78.125 MHz */ 545 return 78215; /* or: 78.125 MHz */
566} 546}
@@ -643,30 +623,18 @@ static int skge_set_coalesce(struct net_device *dev,
643static void skge_led_on(struct skge_hw *hw, int port) 623static void skge_led_on(struct skge_hw *hw, int port)
644{ 624{
645 if (hw->chip_id == CHIP_ID_GENESIS) { 625 if (hw->chip_id == CHIP_ID_GENESIS) {
646 skge_write8(hw, SKGEMAC_REG(port, LNK_LED_REG), LINKLED_ON); 626 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON);
647 skge_write8(hw, B0_LED, LED_STAT_ON); 627 skge_write8(hw, B0_LED, LED_STAT_ON);
648 628
649 skge_write8(hw, SKGEMAC_REG(port, RX_LED_TST), LED_T_ON); 629 skge_write8(hw, SK_REG(port, RX_LED_TST), LED_T_ON);
650 skge_write32(hw, SKGEMAC_REG(port, RX_LED_VAL), 100); 630 skge_write32(hw, SK_REG(port, RX_LED_VAL), 100);
651 skge_write8(hw, SKGEMAC_REG(port, RX_LED_CTRL), LED_START); 631 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
652 632
653 switch (hw->phy_type) { 633 /* For Broadcom Phy only */
654 case SK_PHY_BCOM: 634 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON);
655 skge_xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL,
656 PHY_B_PEC_LED_ON);
657 break;
658 case SK_PHY_LONE:
659 skge_xm_phy_write(hw, port, PHY_LONE_LED_CFG,
660 0x0800);
661 break;
662 default:
663 skge_write8(hw, SKGEMAC_REG(port, TX_LED_TST), LED_T_ON);
664 skge_write32(hw, SKGEMAC_REG(port, TX_LED_VAL), 100);
665 skge_write8(hw, SKGEMAC_REG(port, TX_LED_CTRL), LED_START);
666 }
667 } else { 635 } else {
668 skge_gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0); 636 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
669 skge_gm_phy_write(hw, port, PHY_MARV_LED_OVER, 637 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
670 PHY_M_LED_MO_DUP(MO_LED_ON) | 638 PHY_M_LED_MO_DUP(MO_LED_ON) |
671 PHY_M_LED_MO_10(MO_LED_ON) | 639 PHY_M_LED_MO_10(MO_LED_ON) |
672 PHY_M_LED_MO_100(MO_LED_ON) | 640 PHY_M_LED_MO_100(MO_LED_ON) |
@@ -678,28 +646,17 @@ static void skge_led_on(struct skge_hw *hw, int port)
678static void skge_led_off(struct skge_hw *hw, int port) 646static void skge_led_off(struct skge_hw *hw, int port)
679{ 647{
680 if (hw->chip_id == CHIP_ID_GENESIS) { 648 if (hw->chip_id == CHIP_ID_GENESIS) {
681 skge_write8(hw, SKGEMAC_REG(port, LNK_LED_REG), LINKLED_OFF); 649 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
682 skge_write8(hw, B0_LED, LED_STAT_OFF); 650 skge_write8(hw, B0_LED, LED_STAT_OFF);
683 651
684 skge_write32(hw, SKGEMAC_REG(port, RX_LED_VAL), 0); 652 skge_write32(hw, SK_REG(port, RX_LED_VAL), 0);
685 skge_write8(hw, SKGEMAC_REG(port, RX_LED_CTRL), LED_T_OFF); 653 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF);
686 654
687 switch (hw->phy_type) { 655 /* Broadcom only */
688 case SK_PHY_BCOM: 656 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF);
689 skge_xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL,
690 PHY_B_PEC_LED_OFF);
691 break;
692 case SK_PHY_LONE:
693 skge_xm_phy_write(hw, port, PHY_LONE_LED_CFG,
694 PHY_L_LC_LEDT);
695 break;
696 default:
697 skge_write32(hw, SKGEMAC_REG(port, TX_LED_VAL), 0);
698 skge_write8(hw, SKGEMAC_REG(port, TX_LED_CTRL), LED_T_OFF);
699 }
700 } else { 657 } else {
701 skge_gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0); 658 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
702 skge_gm_phy_write(hw, port, PHY_MARV_LED_OVER, 659 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
703 PHY_M_LED_MO_DUP(MO_LED_OFF) | 660 PHY_M_LED_MO_DUP(MO_LED_OFF) |
704 PHY_M_LED_MO_10(MO_LED_OFF) | 661 PHY_M_LED_MO_10(MO_LED_OFF) |
705 PHY_M_LED_MO_100(MO_LED_OFF) | 662 PHY_M_LED_MO_100(MO_LED_OFF) |
@@ -730,7 +687,7 @@ static int skge_phys_id(struct net_device *dev, u32 data)
730{ 687{
731 struct skge_port *skge = netdev_priv(dev); 688 struct skge_port *skge = netdev_priv(dev);
732 689
733 if(!data || data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ)) 690 if (!data || data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ))
734 data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ); 691 data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ);
735 692
736 /* start blinking */ 693 /* start blinking */
@@ -763,8 +720,6 @@ static struct ethtool_ops skge_ethtool_ops = {
763 .set_pauseparam = skge_set_pauseparam, 720 .set_pauseparam = skge_set_pauseparam,
764 .get_coalesce = skge_get_coalesce, 721 .get_coalesce = skge_get_coalesce,
765 .set_coalesce = skge_set_coalesce, 722 .set_coalesce = skge_set_coalesce,
766 .get_tso = ethtool_op_get_tso,
767 .set_tso = skge_set_tso,
768 .get_sg = ethtool_op_get_sg, 723 .get_sg = ethtool_op_get_sg,
769 .set_sg = skge_set_sg, 724 .set_sg = skge_set_sg,
770 .get_tx_csum = ethtool_op_get_tx_csum, 725 .get_tx_csum = ethtool_op_get_tx_csum,
@@ -793,6 +748,7 @@ static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u64 base)
793 748
794 for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) { 749 for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) {
795 e->desc = d; 750 e->desc = d;
751 e->skb = NULL;
796 if (i == ring->count - 1) { 752 if (i == ring->count - 1) {
797 e->next = ring->start; 753 e->next = ring->start;
798 d->next_offset = base; 754 d->next_offset = base;
@@ -806,24 +762,23 @@ static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u64 base)
806 return 0; 762 return 0;
807} 763}
808 764
809/* Setup buffer for receiving */ 765static struct sk_buff *skge_rx_alloc(struct net_device *dev, unsigned int size)
810static inline int skge_rx_alloc(struct skge_port *skge,
811 struct skge_element *e)
812{ 766{
813 unsigned long bufsize = skge->netdev->mtu + ETH_HLEN; /* VLAN? */ 767 struct sk_buff *skb = dev_alloc_skb(size);
814 struct skge_rx_desc *rd = e->desc;
815 struct sk_buff *skb;
816 u64 map;
817 768
818 skb = dev_alloc_skb(bufsize + NET_IP_ALIGN); 769 if (likely(skb)) {
819 if (unlikely(!skb)) { 770 skb->dev = dev;
820 printk(KERN_DEBUG PFX "%s: out of memory for receive\n", 771 skb_reserve(skb, NET_IP_ALIGN);
821 skge->netdev->name);
822 return -ENOMEM;
823 } 772 }
773 return skb;
774}
824 775
825 skb->dev = skge->netdev; 776/* Allocate and setup a new buffer for receiving */
826 skb_reserve(skb, NET_IP_ALIGN); 777static void skge_rx_setup(struct skge_port *skge, struct skge_element *e,
778 struct sk_buff *skb, unsigned int bufsize)
779{
780 struct skge_rx_desc *rd = e->desc;
781 u64 map;
827 782
828 map = pci_map_single(skge->hw->pdev, skb->data, bufsize, 783 map = pci_map_single(skge->hw->pdev, skb->data, bufsize,
829 PCI_DMA_FROMDEVICE); 784 PCI_DMA_FROMDEVICE);
@@ -841,55 +796,69 @@ static inline int skge_rx_alloc(struct skge_port *skge,
841 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | bufsize; 796 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | bufsize;
842 pci_unmap_addr_set(e, mapaddr, map); 797 pci_unmap_addr_set(e, mapaddr, map);
843 pci_unmap_len_set(e, maplen, bufsize); 798 pci_unmap_len_set(e, maplen, bufsize);
844 return 0;
845} 799}
846 800
847/* Free all unused buffers in receive ring, assumes receiver stopped */ 801/* Resume receiving using existing skb,
802 * Note: DMA address is not changed by chip.
803 * MTU not changed while receiver active.
804 */
805static void skge_rx_reuse(struct skge_element *e, unsigned int size)
806{
807 struct skge_rx_desc *rd = e->desc;
808
809 rd->csum2 = 0;
810 rd->csum2_start = ETH_HLEN;
811
812 wmb();
813
814 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | size;
815}
816
817
818/* Free all buffers in receive ring, assumes receiver stopped */
848static void skge_rx_clean(struct skge_port *skge) 819static void skge_rx_clean(struct skge_port *skge)
849{ 820{
850 struct skge_hw *hw = skge->hw; 821 struct skge_hw *hw = skge->hw;
851 struct skge_ring *ring = &skge->rx_ring; 822 struct skge_ring *ring = &skge->rx_ring;
852 struct skge_element *e; 823 struct skge_element *e;
853 824
854 for (e = ring->to_clean; e != ring->to_use; e = e->next) { 825 e = ring->start;
826 do {
855 struct skge_rx_desc *rd = e->desc; 827 struct skge_rx_desc *rd = e->desc;
856 rd->control = 0; 828 rd->control = 0;
857 829 if (e->skb) {
858 pci_unmap_single(hw->pdev, 830 pci_unmap_single(hw->pdev,
859 pci_unmap_addr(e, mapaddr), 831 pci_unmap_addr(e, mapaddr),
860 pci_unmap_len(e, maplen), 832 pci_unmap_len(e, maplen),
861 PCI_DMA_FROMDEVICE); 833 PCI_DMA_FROMDEVICE);
862 dev_kfree_skb(e->skb); 834 dev_kfree_skb(e->skb);
863 e->skb = NULL; 835 e->skb = NULL;
864 } 836 }
865 ring->to_clean = e; 837 } while ((e = e->next) != ring->start);
866} 838}
867 839
840
868/* Allocate buffers for receive ring 841/* Allocate buffers for receive ring
869 * For receive: to_use is refill location 842 * For receive: to_clean is next received frame.
870 * to_clean is next received frame.
871 *
872 * if (to_use == to_clean)
873 * then ring all frames in ring need buffers
874 * if (to_use->next == to_clean)
875 * then ring all frames in ring have buffers
876 */ 843 */
877static int skge_rx_fill(struct skge_port *skge) 844static int skge_rx_fill(struct skge_port *skge)
878{ 845{
879 struct skge_ring *ring = &skge->rx_ring; 846 struct skge_ring *ring = &skge->rx_ring;
880 struct skge_element *e; 847 struct skge_element *e;
881 int ret = 0; 848 unsigned int bufsize = skge->rx_buf_size;
882 849
883 for (e = ring->to_use; e->next != ring->to_clean; e = e->next) { 850 e = ring->start;
884 if (skge_rx_alloc(skge, e)) { 851 do {
885 ret = 1; 852 struct sk_buff *skb = skge_rx_alloc(skge->netdev, bufsize);
886 break;
887 }
888 853
889 } 854 if (!skb)
890 ring->to_use = e; 855 return -ENOMEM;
856
857 skge_rx_setup(skge, e, skb, bufsize);
858 } while ( (e = e->next) != ring->start);
891 859
892 return ret; 860 ring->to_clean = ring->start;
861 return 0;
893} 862}
894 863
895static void skge_link_up(struct skge_port *skge) 864static void skge_link_up(struct skge_port *skge)
@@ -919,50 +888,50 @@ static void skge_link_down(struct skge_port *skge)
919 printk(KERN_INFO PFX "%s: Link is down.\n", skge->netdev->name); 888 printk(KERN_INFO PFX "%s: Link is down.\n", skge->netdev->name);
920} 889}
921 890
922static u16 skge_xm_phy_read(struct skge_hw *hw, int port, u16 reg) 891static u16 xm_phy_read(struct skge_hw *hw, int port, u16 reg)
923{ 892{
924 int i; 893 int i;
925 u16 v; 894 u16 v;
926 895
927 skge_xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr); 896 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
928 v = skge_xm_read16(hw, port, XM_PHY_DATA); 897 v = xm_read16(hw, port, XM_PHY_DATA);
929 if (hw->phy_type != SK_PHY_XMAC) {
930 for (i = 0; i < PHY_RETRIES; i++) {
931 udelay(1);
932 if (skge_xm_read16(hw, port, XM_MMU_CMD)
933 & XM_MMU_PHY_RDY)
934 goto ready;
935 }
936 898
937 printk(KERN_WARNING PFX "%s: phy read timed out\n", 899 /* Need to wait for external PHY */
938 hw->dev[port]->name); 900 for (i = 0; i < PHY_RETRIES; i++) {
939 return 0; 901 udelay(1);
940 ready: 902 if (xm_read16(hw, port, XM_MMU_CMD)
941 v = skge_xm_read16(hw, port, XM_PHY_DATA); 903 & XM_MMU_PHY_RDY)
904 goto ready;
942 } 905 }
943 906
907 printk(KERN_WARNING PFX "%s: phy read timed out\n",
908 hw->dev[port]->name);
909 return 0;
910 ready:
911 v = xm_read16(hw, port, XM_PHY_DATA);
912
944 return v; 913 return v;
945} 914}
946 915
947static void skge_xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val) 916static void xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
948{ 917{
949 int i; 918 int i;
950 919
951 skge_xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr); 920 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
952 for (i = 0; i < PHY_RETRIES; i++) { 921 for (i = 0; i < PHY_RETRIES; i++) {
953 if (!(skge_xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY)) 922 if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
954 goto ready; 923 goto ready;
955 cpu_relax(); 924 udelay(1);
956 } 925 }
957 printk(KERN_WARNING PFX "%s: phy write failed to come ready\n", 926 printk(KERN_WARNING PFX "%s: phy write failed to come ready\n",
958 hw->dev[port]->name); 927 hw->dev[port]->name);
959 928
960 929
961 ready: 930 ready:
962 skge_xm_write16(hw, port, XM_PHY_DATA, val); 931 xm_write16(hw, port, XM_PHY_DATA, val);
963 for (i = 0; i < PHY_RETRIES; i++) { 932 for (i = 0; i < PHY_RETRIES; i++) {
964 udelay(1); 933 udelay(1);
965 if (!(skge_xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY)) 934 if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
966 return; 935 return;
967 } 936 }
968 printk(KERN_WARNING PFX "%s: phy write timed out\n", 937 printk(KERN_WARNING PFX "%s: phy write timed out\n",
@@ -999,34 +968,112 @@ static void genesis_init(struct skge_hw *hw)
999 968
1000static void genesis_reset(struct skge_hw *hw, int port) 969static void genesis_reset(struct skge_hw *hw, int port)
1001{ 970{
1002 int i; 971 const u8 zero[8] = { 0 };
1003 u64 zero = 0;
1004 972
1005 /* reset the statistics module */ 973 /* reset the statistics module */
1006 skge_xm_write32(hw, port, XM_GP_PORT, XM_GP_RES_STAT); 974 xm_write32(hw, port, XM_GP_PORT, XM_GP_RES_STAT);
1007 skge_xm_write16(hw, port, XM_IMSK, 0xffff); /* disable XMAC IRQs */ 975 xm_write16(hw, port, XM_IMSK, 0xffff); /* disable XMAC IRQs */
1008 skge_xm_write32(hw, port, XM_MODE, 0); /* clear Mode Reg */ 976 xm_write32(hw, port, XM_MODE, 0); /* clear Mode Reg */
1009 skge_xm_write16(hw, port, XM_TX_CMD, 0); /* reset TX CMD Reg */ 977 xm_write16(hw, port, XM_TX_CMD, 0); /* reset TX CMD Reg */
1010 skge_xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */ 978 xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */
1011 979
1012 /* disable all PHY IRQs */ 980 /* disable Broadcom PHY IRQ */
1013 if (hw->phy_type == SK_PHY_BCOM) 981 xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff);
1014 skge_xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff);
1015 982
1016 skge_xm_outhash(hw, port, XM_HSM, (u8 *) &zero); 983 xm_outhash(hw, port, XM_HSM, zero);
1017 for (i = 0; i < 15; i++)
1018 skge_xm_outaddr(hw, port, XM_EXM(i), (u8 *) &zero);
1019 skge_xm_outhash(hw, port, XM_SRC_CHK, (u8 *) &zero);
1020} 984}
1021 985
1022 986
1023static void genesis_mac_init(struct skge_hw *hw, int port) 987/* Convert mode to MII values */
988static const u16 phy_pause_map[] = {
989 [FLOW_MODE_NONE] = 0,
990 [FLOW_MODE_LOC_SEND] = PHY_AN_PAUSE_ASYM,
991 [FLOW_MODE_SYMMETRIC] = PHY_AN_PAUSE_CAP,
992 [FLOW_MODE_REM_SEND] = PHY_AN_PAUSE_CAP | PHY_AN_PAUSE_ASYM,
993};
994
995
996/* Check status of Broadcom phy link */
997static void bcom_check_link(struct skge_hw *hw, int port)
1024{ 998{
1025 struct skge_port *skge = netdev_priv(hw->dev[port]); 999 struct net_device *dev = hw->dev[port];
1000 struct skge_port *skge = netdev_priv(dev);
1001 u16 status;
1002
1003 /* read twice because of latch */
1004 (void) xm_phy_read(hw, port, PHY_BCOM_STAT);
1005 status = xm_phy_read(hw, port, PHY_BCOM_STAT);
1006
1007 pr_debug("bcom_check_link status=0x%x\n", status);
1008
1009 if ((status & PHY_ST_LSYNC) == 0) {
1010 u16 cmd = xm_read16(hw, port, XM_MMU_CMD);
1011 cmd &= ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1012 xm_write16(hw, port, XM_MMU_CMD, cmd);
1013 /* dummy read to ensure writing */
1014 (void) xm_read16(hw, port, XM_MMU_CMD);
1015
1016 if (netif_carrier_ok(dev))
1017 skge_link_down(skge);
1018 } else {
1019 if (skge->autoneg == AUTONEG_ENABLE &&
1020 (status & PHY_ST_AN_OVER)) {
1021 u16 lpa = xm_phy_read(hw, port, PHY_BCOM_AUNE_LP);
1022 u16 aux = xm_phy_read(hw, port, PHY_BCOM_AUX_STAT);
1023
1024 if (lpa & PHY_B_AN_RF) {
1025 printk(KERN_NOTICE PFX "%s: remote fault\n",
1026 dev->name);
1027 return;
1028 }
1029
1030 /* Check Duplex mismatch */
1031 switch(aux & PHY_B_AS_AN_RES_MSK) {
1032 case PHY_B_RES_1000FD:
1033 skge->duplex = DUPLEX_FULL;
1034 break;
1035 case PHY_B_RES_1000HD:
1036 skge->duplex = DUPLEX_HALF;
1037 break;
1038 default:
1039 printk(KERN_NOTICE PFX "%s: duplex mismatch\n",
1040 dev->name);
1041 return;
1042 }
1043
1044
1045 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
1046 switch (aux & PHY_B_AS_PAUSE_MSK) {
1047 case PHY_B_AS_PAUSE_MSK:
1048 skge->flow_control = FLOW_MODE_SYMMETRIC;
1049 break;
1050 case PHY_B_AS_PRR:
1051 skge->flow_control = FLOW_MODE_REM_SEND;
1052 break;
1053 case PHY_B_AS_PRT:
1054 skge->flow_control = FLOW_MODE_LOC_SEND;
1055 break;
1056 default:
1057 skge->flow_control = FLOW_MODE_NONE;
1058 }
1059
1060 skge->speed = SPEED_1000;
1061 }
1062
1063 if (!netif_carrier_ok(dev))
1064 genesis_link_up(skge);
1065 }
1066}
1067
1068/* Broadcom 5400 only supports giagabit! SysKonnect did not put an additional
1069 * Phy on for 100 or 10Mbit operation
1070 */
1071static void bcom_phy_init(struct skge_port *skge, int jumbo)
1072{
1073 struct skge_hw *hw = skge->hw;
1074 int port = skge->port;
1026 int i; 1075 int i;
1027 u32 r; 1076 u16 id1, r, ext, ctl;
1028 u16 id1;
1029 u16 ctrl1, ctrl2, ctrl3, ctrl4, ctrl5;
1030 1077
1031 /* magic workaround patterns for Broadcom */ 1078 /* magic workaround patterns for Broadcom */
1032 static const struct { 1079 static const struct {
@@ -1042,16 +1089,120 @@ static void genesis_mac_init(struct skge_hw *hw, int port)
1042 { 0x17, 0x0013 }, { 0x15, 0x0A04 }, { 0x18, 0x0420 }, 1089 { 0x17, 0x0013 }, { 0x15, 0x0A04 }, { 0x18, 0x0420 },
1043 }; 1090 };
1044 1091
1092 pr_debug("bcom_phy_init\n");
1093
1094 /* read Id from external PHY (all have the same address) */
1095 id1 = xm_phy_read(hw, port, PHY_XMAC_ID1);
1096
1097 /* Optimize MDIO transfer by suppressing preamble. */
1098 r = xm_read16(hw, port, XM_MMU_CMD);
1099 r |= XM_MMU_NO_PRE;
1100 xm_write16(hw, port, XM_MMU_CMD,r);
1101
1102 switch(id1) {
1103 case PHY_BCOM_ID1_C0:
1104 /*
1105 * Workaround BCOM Errata for the C0 type.
1106 * Write magic patterns to reserved registers.
1107 */
1108 for (i = 0; i < ARRAY_SIZE(C0hack); i++)
1109 xm_phy_write(hw, port,
1110 C0hack[i].reg, C0hack[i].val);
1111
1112 break;
1113 case PHY_BCOM_ID1_A1:
1114 /*
1115 * Workaround BCOM Errata for the A1 type.
1116 * Write magic patterns to reserved registers.
1117 */
1118 for (i = 0; i < ARRAY_SIZE(A1hack); i++)
1119 xm_phy_write(hw, port,
1120 A1hack[i].reg, A1hack[i].val);
1121 break;
1122 }
1123
1124 /*
1125 * Workaround BCOM Errata (#10523) for all BCom PHYs.
1126 * Disable Power Management after reset.
1127 */
1128 r = xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL);
1129 r |= PHY_B_AC_DIS_PM;
1130 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, r);
1131
1132 /* Dummy read */
1133 xm_read16(hw, port, XM_ISRC);
1134
1135 ext = PHY_B_PEC_EN_LTR; /* enable tx led */
1136 ctl = PHY_CT_SP1000; /* always 1000mbit */
1137
1138 if (skge->autoneg == AUTONEG_ENABLE) {
1139 /*
1140 * Workaround BCOM Errata #1 for the C5 type.
1141 * 1000Base-T Link Acquisition Failure in Slave Mode
1142 * Set Repeater/DTE bit 10 of the 1000Base-T Control Register
1143 */
1144 u16 adv = PHY_B_1000C_RD;
1145 if (skge->advertising & ADVERTISED_1000baseT_Half)
1146 adv |= PHY_B_1000C_AHD;
1147 if (skge->advertising & ADVERTISED_1000baseT_Full)
1148 adv |= PHY_B_1000C_AFD;
1149 xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, adv);
1150
1151 ctl |= PHY_CT_ANE | PHY_CT_RE_CFG;
1152 } else {
1153 if (skge->duplex == DUPLEX_FULL)
1154 ctl |= PHY_CT_DUP_MD;
1155 /* Force to slave */
1156 xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, PHY_B_1000C_MSE);
1157 }
1158
1159 /* Set autonegotiation pause parameters */
1160 xm_phy_write(hw, port, PHY_BCOM_AUNE_ADV,
1161 phy_pause_map[skge->flow_control] | PHY_AN_CSMA);
1162
1163 /* Handle Jumbo frames */
1164 if (jumbo) {
1165 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1166 PHY_B_AC_TX_TST | PHY_B_AC_LONG_PACK);
1167
1168 ext |= PHY_B_PEC_HIGH_LA;
1169
1170 }
1171
1172 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, ext);
1173 xm_phy_write(hw, port, PHY_BCOM_CTRL, ctl);
1174
1175 /* Use link status change interrrupt */
1176 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
1177
1178 bcom_check_link(hw, port);
1179}
1180
1181static void genesis_mac_init(struct skge_hw *hw, int port)
1182{
1183 struct net_device *dev = hw->dev[port];
1184 struct skge_port *skge = netdev_priv(dev);
1185 int jumbo = hw->dev[port]->mtu > ETH_DATA_LEN;
1186 int i;
1187 u32 r;
1188 const u8 zero[6] = { 0 };
1189
1190 /* Clear MIB counters */
1191 xm_write16(hw, port, XM_STAT_CMD,
1192 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1193 /* Clear two times according to Errata #3 */
1194 xm_write16(hw, port, XM_STAT_CMD,
1195 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1045 1196
1046 /* initialize Rx, Tx and Link LED */ 1197 /* initialize Rx, Tx and Link LED */
1047 skge_write8(hw, SKGEMAC_REG(port, LNK_LED_REG), LINKLED_ON); 1198 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON);
1048 skge_write8(hw, SKGEMAC_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON); 1199 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON);
1049 1200
1050 skge_write8(hw, SKGEMAC_REG(port, RX_LED_CTRL), LED_START); 1201 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
1051 skge_write8(hw, SKGEMAC_REG(port, TX_LED_CTRL), LED_START); 1202 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
1052 1203
1053 /* Unreset the XMAC. */ 1204 /* Unreset the XMAC. */
1054 skge_write16(hw, SKGEMAC_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST); 1205 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
1055 1206
1056 /* 1207 /*
1057 * Perform additional initialization for external PHYs, 1208 * Perform additional initialization for external PHYs,
@@ -1059,67 +1210,56 @@ static void genesis_mac_init(struct skge_hw *hw, int port)
1059 * GMII mode. 1210 * GMII mode.
1060 */ 1211 */
1061 spin_lock_bh(&hw->phy_lock); 1212 spin_lock_bh(&hw->phy_lock);
1062 if (hw->phy_type != SK_PHY_XMAC) { 1213 /* Take external Phy out of reset */
1063 /* Take PHY out of reset. */ 1214 r = skge_read32(hw, B2_GP_IO);
1064 r = skge_read32(hw, B2_GP_IO); 1215 if (port == 0)
1065 if (port == 0) 1216 r |= GP_DIR_0|GP_IO_0;
1066 r |= GP_DIR_0|GP_IO_0; 1217 else
1067 else 1218 r |= GP_DIR_2|GP_IO_2;
1068 r |= GP_DIR_2|GP_IO_2;
1069
1070 skge_write32(hw, B2_GP_IO, r);
1071 skge_read32(hw, B2_GP_IO);
1072
1073 /* Enable GMII mode on the XMAC. */
1074 skge_xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD);
1075
1076 id1 = skge_xm_phy_read(hw, port, PHY_XMAC_ID1);
1077
1078 /* Optimize MDIO transfer by suppressing preamble. */
1079 skge_xm_write16(hw, port, XM_MMU_CMD,
1080 skge_xm_read16(hw, port, XM_MMU_CMD)
1081 | XM_MMU_NO_PRE);
1082
1083 if (id1 == PHY_BCOM_ID1_C0) {
1084 /*
1085 * Workaround BCOM Errata for the C0 type.
1086 * Write magic patterns to reserved registers.
1087 */
1088 for (i = 0; i < ARRAY_SIZE(C0hack); i++)
1089 skge_xm_phy_write(hw, port,
1090 C0hack[i].reg, C0hack[i].val);
1091
1092 } else if (id1 == PHY_BCOM_ID1_A1) {
1093 /*
1094 * Workaround BCOM Errata for the A1 type.
1095 * Write magic patterns to reserved registers.
1096 */
1097 for (i = 0; i < ARRAY_SIZE(A1hack); i++)
1098 skge_xm_phy_write(hw, port,
1099 A1hack[i].reg, A1hack[i].val);
1100 }
1101 1219
1102 /* 1220 skge_write32(hw, B2_GP_IO, r);
1103 * Workaround BCOM Errata (#10523) for all BCom PHYs. 1221 skge_read32(hw, B2_GP_IO);
1104 * Disable Power Management after reset. 1222 spin_unlock_bh(&hw->phy_lock);
1105 */
1106 r = skge_xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL);
1107 skge_xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, r | PHY_B_AC_DIS_PM);
1108 }
1109 1223
1110 /* Dummy read */ 1224 /* Enable GMII interfac */
1111 skge_xm_read16(hw, port, XM_ISRC); 1225 xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD);
1226
1227 bcom_phy_init(skge, jumbo);
1228
1229 /* Set Station Address */
1230 xm_outaddr(hw, port, XM_SA, dev->dev_addr);
1231
1232 /* We don't use match addresses so clear */
1233 for (i = 1; i < 16; i++)
1234 xm_outaddr(hw, port, XM_EXM(i), zero);
1112 1235
1113 r = skge_xm_read32(hw, port, XM_MODE); 1236 /* configure Rx High Water Mark (XM_RX_HI_WM) */
1114 skge_xm_write32(hw, port, XM_MODE, r|XM_MD_CSA); 1237 xm_write16(hw, port, XM_RX_HI_WM, 1450);
1115 1238
1116 /* We don't need the FCS appended to the packet. */ 1239 /* We don't need the FCS appended to the packet. */
1117 r = skge_xm_read16(hw, port, XM_RX_CMD); 1240 r = XM_RX_LENERR_OK | XM_RX_STRIP_FCS;
1118 skge_xm_write16(hw, port, XM_RX_CMD, r | XM_RX_STRIP_FCS); 1241 if (jumbo)
1242 r |= XM_RX_BIG_PK_OK;
1243
1244 if (skge->duplex == DUPLEX_HALF) {
1245 /*
1246 * If in manual half duplex mode the other side might be in
1247 * full duplex mode, so ignore if a carrier extension is not seen
1248 * on frames received
1249 */
1250 r |= XM_RX_DIS_CEXT;
1251 }
1252 xm_write16(hw, port, XM_RX_CMD, r);
1253
1119 1254
1120 /* We want short frames padded to 60 bytes. */ 1255 /* We want short frames padded to 60 bytes. */
1121 r = skge_xm_read16(hw, port, XM_TX_CMD); 1256 xm_write16(hw, port, XM_TX_CMD, XM_TX_AUTO_PAD);
1122 skge_xm_write16(hw, port, XM_TX_CMD, r | XM_TX_AUTO_PAD); 1257
1258 /*
1259 * Bump up the transmit threshold. This helps hold off transmit
1260 * underruns when we're blasting traffic from both ports at once.
1261 */
1262 xm_write16(hw, port, XM_TX_THR, 512);
1123 1263
1124 /* 1264 /*
1125 * Enable the reception of all error frames. This is is 1265 * Enable the reception of all error frames. This is is
@@ -1135,19 +1275,22 @@ static void genesis_mac_init(struct skge_hw *hw, int port)
1135 * case the XMAC will start transfering frames out of the 1275 * case the XMAC will start transfering frames out of the
1136 * RX FIFO as soon as the FIFO threshold is reached. 1276 * RX FIFO as soon as the FIFO threshold is reached.
1137 */ 1277 */
1138 r = skge_xm_read32(hw, port, XM_MODE); 1278 xm_write32(hw, port, XM_MODE, XM_DEF_MODE);
1139 skge_xm_write32(hw, port, XM_MODE,
1140 XM_MD_RX_CRCE|XM_MD_RX_LONG|XM_MD_RX_RUNT|
1141 XM_MD_RX_ERR|XM_MD_RX_IRLE);
1142 1279
1143 skge_xm_outaddr(hw, port, XM_SA, hw->dev[port]->dev_addr);
1144 skge_xm_outaddr(hw, port, XM_EXM(0), hw->dev[port]->dev_addr);
1145 1280
1146 /* 1281 /*
1147 * Bump up the transmit threshold. This helps hold off transmit 1282 * Initialize the Receive Counter Event Mask (XM_RX_EV_MSK)
1148 * underruns when we're blasting traffic from both ports at once. 1283 * - Enable all bits excepting 'Octets Rx OK Low CntOv'
1284 * and 'Octets Rx OK Hi Cnt Ov'.
1149 */ 1285 */
1150 skge_xm_write16(hw, port, XM_TX_THR, 512); 1286 xm_write32(hw, port, XM_RX_EV_MSK, XMR_DEF_MSK);
1287
1288 /*
1289 * Initialize the Transmit Counter Event Mask (XM_TX_EV_MSK)
1290 * - Enable all bits excepting 'Octets Tx OK Low CntOv'
1291 * and 'Octets Tx OK Hi Cnt Ov'.
1292 */
1293 xm_write32(hw, port, XM_TX_EV_MSK, XMT_DEF_MSK);
1151 1294
1152 /* Configure MAC arbiter */ 1295 /* Configure MAC arbiter */
1153 skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR); 1296 skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR);
@@ -1164,137 +1307,30 @@ static void genesis_mac_init(struct skge_hw *hw, int port)
1164 skge_write8(hw, B3_MA_RCINI_TX2, 0); 1307 skge_write8(hw, B3_MA_RCINI_TX2, 0);
1165 1308
1166 /* Configure Rx MAC FIFO */ 1309 /* Configure Rx MAC FIFO */
1167 skge_write8(hw, SKGEMAC_REG(port, RX_MFF_CTRL2), MFF_RST_CLR); 1310 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_CLR);
1168 skge_write16(hw, SKGEMAC_REG(port, RX_MFF_CTRL1), MFF_ENA_TIM_PAT); 1311 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_TIM_PAT);
1169 skge_write8(hw, SKGEMAC_REG(port, RX_MFF_CTRL2), MFF_ENA_OP_MD); 1312 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_ENA_OP_MD);
1170 1313
1171 /* Configure Tx MAC FIFO */ 1314 /* Configure Tx MAC FIFO */
1172 skge_write8(hw, SKGEMAC_REG(port, TX_MFF_CTRL2), MFF_RST_CLR); 1315 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_CLR);
1173 skge_write16(hw, SKGEMAC_REG(port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF); 1316 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF);
1174 skge_write8(hw, SKGEMAC_REG(port, TX_MFF_CTRL2), MFF_ENA_OP_MD); 1317 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_ENA_OP_MD);
1175 1318
1176 if (hw->dev[port]->mtu > ETH_DATA_LEN) { 1319 if (jumbo) {
1177 /* Enable frame flushing if jumbo frames used */ 1320 /* Enable frame flushing if jumbo frames used */
1178 skge_write16(hw, SKGEMAC_REG(port,RX_MFF_CTRL1), MFF_ENA_FLUSH); 1321 skge_write16(hw, SK_REG(port,RX_MFF_CTRL1), MFF_ENA_FLUSH);
1179 } else { 1322 } else {
1180 /* enable timeout timers if normal frames */ 1323 /* enable timeout timers if normal frames */
1181 skge_write16(hw, B3_PA_CTRL, 1324 skge_write16(hw, B3_PA_CTRL,
1182 port == 0 ? PA_ENA_TO_TX1 : PA_ENA_TO_TX2); 1325 (port == 0) ? PA_ENA_TO_TX1 : PA_ENA_TO_TX2);
1183 } 1326 }
1184
1185
1186 r = skge_xm_read16(hw, port, XM_RX_CMD);
1187 if (hw->dev[port]->mtu > ETH_DATA_LEN)
1188 skge_xm_write16(hw, port, XM_RX_CMD, r | XM_RX_BIG_PK_OK);
1189 else
1190 skge_xm_write16(hw, port, XM_RX_CMD, r & ~(XM_RX_BIG_PK_OK));
1191
1192 switch (hw->phy_type) {
1193 case SK_PHY_XMAC:
1194 if (skge->autoneg == AUTONEG_ENABLE) {
1195 ctrl1 = PHY_X_AN_FD | PHY_X_AN_HD;
1196
1197 switch (skge->flow_control) {
1198 case FLOW_MODE_NONE:
1199 ctrl1 |= PHY_X_P_NO_PAUSE;
1200 break;
1201 case FLOW_MODE_LOC_SEND:
1202 ctrl1 |= PHY_X_P_ASYM_MD;
1203 break;
1204 case FLOW_MODE_SYMMETRIC:
1205 ctrl1 |= PHY_X_P_SYM_MD;
1206 break;
1207 case FLOW_MODE_REM_SEND:
1208 ctrl1 |= PHY_X_P_BOTH_MD;
1209 break;
1210 }
1211
1212 skge_xm_phy_write(hw, port, PHY_XMAC_AUNE_ADV, ctrl1);
1213 ctrl2 = PHY_CT_ANE | PHY_CT_RE_CFG;
1214 } else {
1215 ctrl2 = 0;
1216 if (skge->duplex == DUPLEX_FULL)
1217 ctrl2 |= PHY_CT_DUP_MD;
1218 }
1219
1220 skge_xm_phy_write(hw, port, PHY_XMAC_CTRL, ctrl2);
1221 break;
1222
1223 case SK_PHY_BCOM:
1224 ctrl1 = PHY_CT_SP1000;
1225 ctrl2 = 0;
1226 ctrl3 = PHY_SEL_TYPE;
1227 ctrl4 = PHY_B_PEC_EN_LTR;
1228 ctrl5 = PHY_B_AC_TX_TST;
1229
1230 if (skge->autoneg == AUTONEG_ENABLE) {
1231 /*
1232 * Workaround BCOM Errata #1 for the C5 type.
1233 * 1000Base-T Link Acquisition Failure in Slave Mode
1234 * Set Repeater/DTE bit 10 of the 1000Base-T Control Register
1235 */
1236 ctrl2 |= PHY_B_1000C_RD;
1237 if (skge->advertising & ADVERTISED_1000baseT_Half)
1238 ctrl2 |= PHY_B_1000C_AHD;
1239 if (skge->advertising & ADVERTISED_1000baseT_Full)
1240 ctrl2 |= PHY_B_1000C_AFD;
1241
1242 /* Set Flow-control capabilities */
1243 switch (skge->flow_control) {
1244 case FLOW_MODE_NONE:
1245 ctrl3 |= PHY_B_P_NO_PAUSE;
1246 break;
1247 case FLOW_MODE_LOC_SEND:
1248 ctrl3 |= PHY_B_P_ASYM_MD;
1249 break;
1250 case FLOW_MODE_SYMMETRIC:
1251 ctrl3 |= PHY_B_P_SYM_MD;
1252 break;
1253 case FLOW_MODE_REM_SEND:
1254 ctrl3 |= PHY_B_P_BOTH_MD;
1255 break;
1256 }
1257
1258 /* Restart Auto-negotiation */
1259 ctrl1 |= PHY_CT_ANE | PHY_CT_RE_CFG;
1260 } else {
1261 if (skge->duplex == DUPLEX_FULL)
1262 ctrl1 |= PHY_CT_DUP_MD;
1263
1264 ctrl2 |= PHY_B_1000C_MSE; /* set it to Slave */
1265 }
1266
1267 skge_xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, ctrl2);
1268 skge_xm_phy_write(hw, port, PHY_BCOM_AUNE_ADV, ctrl3);
1269
1270 if (skge->netdev->mtu > ETH_DATA_LEN) {
1271 ctrl4 |= PHY_B_PEC_HIGH_LA;
1272 ctrl5 |= PHY_B_AC_LONG_PACK;
1273
1274 skge_xm_phy_write(hw, port,PHY_BCOM_AUX_CTRL, ctrl5);
1275 }
1276
1277 skge_xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, ctrl4);
1278 skge_xm_phy_write(hw, port, PHY_BCOM_CTRL, ctrl1);
1279 break;
1280 }
1281 spin_unlock_bh(&hw->phy_lock);
1282
1283 /* Clear MIB counters */
1284 skge_xm_write16(hw, port, XM_STAT_CMD,
1285 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1286 /* Clear two times according to Errata #3 */
1287 skge_xm_write16(hw, port, XM_STAT_CMD,
1288 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1289
1290 /* Start polling for link status */
1291 mod_timer(&skge->link_check, jiffies + LINK_POLL_HZ);
1292} 1327}
1293 1328
1294static void genesis_stop(struct skge_port *skge) 1329static void genesis_stop(struct skge_port *skge)
1295{ 1330{
1296 struct skge_hw *hw = skge->hw; 1331 struct skge_hw *hw = skge->hw;
1297 int port = skge->port; 1332 int port = skge->port;
1333 u32 reg;
1298 1334
1299 /* Clear Tx packet arbiter timeout IRQ */ 1335 /* Clear Tx packet arbiter timeout IRQ */
1300 skge_write16(hw, B3_PA_CTRL, 1336 skge_write16(hw, B3_PA_CTRL,
@@ -1304,33 +1340,30 @@ static void genesis_stop(struct skge_port *skge)
1304 * If the transfer stucks at the MAC the STOP command will not 1340 * If the transfer stucks at the MAC the STOP command will not
1305 * terminate if we don't flush the XMAC's transmit FIFO ! 1341 * terminate if we don't flush the XMAC's transmit FIFO !
1306 */ 1342 */
1307 skge_xm_write32(hw, port, XM_MODE, 1343 xm_write32(hw, port, XM_MODE,
1308 skge_xm_read32(hw, port, XM_MODE)|XM_MD_FTF); 1344 xm_read32(hw, port, XM_MODE)|XM_MD_FTF);
1309 1345
1310 1346
1311 /* Reset the MAC */ 1347 /* Reset the MAC */
1312 skge_write16(hw, SKGEMAC_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST); 1348 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST);
1313 1349
1314 /* For external PHYs there must be special handling */ 1350 /* For external PHYs there must be special handling */
1315 if (hw->phy_type != SK_PHY_XMAC) { 1351 reg = skge_read32(hw, B2_GP_IO);
1316 u32 reg = skge_read32(hw, B2_GP_IO); 1352 if (port == 0) {
1317 1353 reg |= GP_DIR_0;
1318 if (port == 0) { 1354 reg &= ~GP_IO_0;
1319 reg |= GP_DIR_0; 1355 } else {
1320 reg &= ~GP_IO_0; 1356 reg |= GP_DIR_2;
1321 } else { 1357 reg &= ~GP_IO_2;
1322 reg |= GP_DIR_2;
1323 reg &= ~GP_IO_2;
1324 }
1325 skge_write32(hw, B2_GP_IO, reg);
1326 skge_read32(hw, B2_GP_IO);
1327 } 1358 }
1359 skge_write32(hw, B2_GP_IO, reg);
1360 skge_read32(hw, B2_GP_IO);
1328 1361
1329 skge_xm_write16(hw, port, XM_MMU_CMD, 1362 xm_write16(hw, port, XM_MMU_CMD,
1330 skge_xm_read16(hw, port, XM_MMU_CMD) 1363 xm_read16(hw, port, XM_MMU_CMD)
1331 & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX)); 1364 & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX));
1332 1365
1333 skge_xm_read16(hw, port, XM_MMU_CMD); 1366 xm_read16(hw, port, XM_MMU_CMD);
1334} 1367}
1335 1368
1336 1369
@@ -1341,11 +1374,11 @@ static void genesis_get_stats(struct skge_port *skge, u64 *data)
1341 int i; 1374 int i;
1342 unsigned long timeout = jiffies + HZ; 1375 unsigned long timeout = jiffies + HZ;
1343 1376
1344 skge_xm_write16(hw, port, 1377 xm_write16(hw, port,
1345 XM_STAT_CMD, XM_SC_SNP_TXC | XM_SC_SNP_RXC); 1378 XM_STAT_CMD, XM_SC_SNP_TXC | XM_SC_SNP_RXC);
1346 1379
1347 /* wait for update to complete */ 1380 /* wait for update to complete */
1348 while (skge_xm_read16(hw, port, XM_STAT_CMD) 1381 while (xm_read16(hw, port, XM_STAT_CMD)
1349 & (XM_SC_SNP_TXC | XM_SC_SNP_RXC)) { 1382 & (XM_SC_SNP_TXC | XM_SC_SNP_RXC)) {
1350 if (time_after(jiffies, timeout)) 1383 if (time_after(jiffies, timeout))
1351 break; 1384 break;
@@ -1353,68 +1386,60 @@ static void genesis_get_stats(struct skge_port *skge, u64 *data)
1353 } 1386 }
1354 1387
1355 /* special case for 64 bit octet counter */ 1388 /* special case for 64 bit octet counter */
1356 data[0] = (u64) skge_xm_read32(hw, port, XM_TXO_OK_HI) << 32 1389 data[0] = (u64) xm_read32(hw, port, XM_TXO_OK_HI) << 32
1357 | skge_xm_read32(hw, port, XM_TXO_OK_LO); 1390 | xm_read32(hw, port, XM_TXO_OK_LO);
1358 data[1] = (u64) skge_xm_read32(hw, port, XM_RXO_OK_HI) << 32 1391 data[1] = (u64) xm_read32(hw, port, XM_RXO_OK_HI) << 32
1359 | skge_xm_read32(hw, port, XM_RXO_OK_LO); 1392 | xm_read32(hw, port, XM_RXO_OK_LO);
1360 1393
1361 for (i = 2; i < ARRAY_SIZE(skge_stats); i++) 1394 for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
1362 data[i] = skge_xm_read32(hw, port, skge_stats[i].xmac_offset); 1395 data[i] = xm_read32(hw, port, skge_stats[i].xmac_offset);
1363} 1396}
1364 1397
1365static void genesis_mac_intr(struct skge_hw *hw, int port) 1398static void genesis_mac_intr(struct skge_hw *hw, int port)
1366{ 1399{
1367 struct skge_port *skge = netdev_priv(hw->dev[port]); 1400 struct skge_port *skge = netdev_priv(hw->dev[port]);
1368 u16 status = skge_xm_read16(hw, port, XM_ISRC); 1401 u16 status = xm_read16(hw, port, XM_ISRC);
1369 1402
1370 pr_debug("genesis_intr status %x\n", status); 1403 if (netif_msg_intr(skge))
1371 if (hw->phy_type == SK_PHY_XMAC) { 1404 printk(KERN_DEBUG PFX "%s: mac interrupt status 0x%x\n",
1372 /* LInk down, start polling for state change */ 1405 skge->netdev->name, status);
1373 if (status & XM_IS_INP_ASS) {
1374 skge_xm_write16(hw, port, XM_IMSK,
1375 skge_xm_read16(hw, port, XM_IMSK) | XM_IS_INP_ASS);
1376 mod_timer(&skge->link_check, jiffies + LINK_POLL_HZ);
1377 }
1378 else if (status & XM_IS_AND)
1379 mod_timer(&skge->link_check, jiffies + LINK_POLL_HZ);
1380 }
1381 1406
1382 if (status & XM_IS_TXF_UR) { 1407 if (status & XM_IS_TXF_UR) {
1383 skge_xm_write32(hw, port, XM_MODE, XM_MD_FTF); 1408 xm_write32(hw, port, XM_MODE, XM_MD_FTF);
1384 ++skge->net_stats.tx_fifo_errors; 1409 ++skge->net_stats.tx_fifo_errors;
1385 } 1410 }
1386 if (status & XM_IS_RXF_OV) { 1411 if (status & XM_IS_RXF_OV) {
1387 skge_xm_write32(hw, port, XM_MODE, XM_MD_FRF); 1412 xm_write32(hw, port, XM_MODE, XM_MD_FRF);
1388 ++skge->net_stats.rx_fifo_errors; 1413 ++skge->net_stats.rx_fifo_errors;
1389 } 1414 }
1390} 1415}
1391 1416
1392static void skge_gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val) 1417static void gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
1393{ 1418{
1394 int i; 1419 int i;
1395 1420
1396 skge_gma_write16(hw, port, GM_SMI_DATA, val); 1421 gma_write16(hw, port, GM_SMI_DATA, val);
1397 skge_gma_write16(hw, port, GM_SMI_CTRL, 1422 gma_write16(hw, port, GM_SMI_CTRL,
1398 GM_SMI_CT_PHY_AD(hw->phy_addr) | GM_SMI_CT_REG_AD(reg)); 1423 GM_SMI_CT_PHY_AD(hw->phy_addr) | GM_SMI_CT_REG_AD(reg));
1399 for (i = 0; i < PHY_RETRIES; i++) { 1424 for (i = 0; i < PHY_RETRIES; i++) {
1400 udelay(1); 1425 udelay(1);
1401 1426
1402 if (!(skge_gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY)) 1427 if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY))
1403 break; 1428 break;
1404 } 1429 }
1405} 1430}
1406 1431
1407static u16 skge_gm_phy_read(struct skge_hw *hw, int port, u16 reg) 1432static u16 gm_phy_read(struct skge_hw *hw, int port, u16 reg)
1408{ 1433{
1409 int i; 1434 int i;
1410 1435
1411 skge_gma_write16(hw, port, GM_SMI_CTRL, 1436 gma_write16(hw, port, GM_SMI_CTRL,
1412 GM_SMI_CT_PHY_AD(hw->phy_addr) 1437 GM_SMI_CT_PHY_AD(hw->phy_addr)
1413 | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD); 1438 | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD);
1414 1439
1415 for (i = 0; i < PHY_RETRIES; i++) { 1440 for (i = 0; i < PHY_RETRIES; i++) {
1416 udelay(1); 1441 udelay(1);
1417 if (skge_gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL) 1442 if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL)
1418 goto ready; 1443 goto ready;
1419 } 1444 }
1420 1445
@@ -1422,24 +1447,7 @@ static u16 skge_gm_phy_read(struct skge_hw *hw, int port, u16 reg)
1422 hw->dev[port]->name); 1447 hw->dev[port]->name);
1423 return 0; 1448 return 0;
1424 ready: 1449 ready:
1425 return skge_gma_read16(hw, port, GM_SMI_DATA); 1450 return gma_read16(hw, port, GM_SMI_DATA);
1426}
1427
1428static void genesis_link_down(struct skge_port *skge)
1429{
1430 struct skge_hw *hw = skge->hw;
1431 int port = skge->port;
1432
1433 pr_debug("genesis_link_down\n");
1434
1435 skge_xm_write16(hw, port, XM_MMU_CMD,
1436 skge_xm_read16(hw, port, XM_MMU_CMD)
1437 & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX));
1438
1439 /* dummy read to ensure writing */
1440 (void) skge_xm_read16(hw, port, XM_MMU_CMD);
1441
1442 skge_link_down(skge);
1443} 1451}
1444 1452
1445static void genesis_link_up(struct skge_port *skge) 1453static void genesis_link_up(struct skge_port *skge)
@@ -1450,7 +1458,7 @@ static void genesis_link_up(struct skge_port *skge)
1450 u32 mode, msk; 1458 u32 mode, msk;
1451 1459
1452 pr_debug("genesis_link_up\n"); 1460 pr_debug("genesis_link_up\n");
1453 cmd = skge_xm_read16(hw, port, XM_MMU_CMD); 1461 cmd = xm_read16(hw, port, XM_MMU_CMD);
1454 1462
1455 /* 1463 /*
1456 * enabling pause frame reception is required for 1000BT 1464 * enabling pause frame reception is required for 1000BT
@@ -1458,14 +1466,15 @@ static void genesis_link_up(struct skge_port *skge)
1458 */ 1466 */
1459 if (skge->flow_control == FLOW_MODE_NONE || 1467 if (skge->flow_control == FLOW_MODE_NONE ||
1460 skge->flow_control == FLOW_MODE_LOC_SEND) 1468 skge->flow_control == FLOW_MODE_LOC_SEND)
1469 /* Disable Pause Frame Reception */
1461 cmd |= XM_MMU_IGN_PF; 1470 cmd |= XM_MMU_IGN_PF;
1462 else 1471 else
1463 /* Enable Pause Frame Reception */ 1472 /* Enable Pause Frame Reception */
1464 cmd &= ~XM_MMU_IGN_PF; 1473 cmd &= ~XM_MMU_IGN_PF;
1465 1474
1466 skge_xm_write16(hw, port, XM_MMU_CMD, cmd); 1475 xm_write16(hw, port, XM_MMU_CMD, cmd);
1467 1476
1468 mode = skge_xm_read32(hw, port, XM_MODE); 1477 mode = xm_read32(hw, port, XM_MODE);
1469 if (skge->flow_control == FLOW_MODE_SYMMETRIC || 1478 if (skge->flow_control == FLOW_MODE_SYMMETRIC ||
1470 skge->flow_control == FLOW_MODE_LOC_SEND) { 1479 skge->flow_control == FLOW_MODE_LOC_SEND) {
1471 /* 1480 /*
@@ -1479,10 +1488,10 @@ static void genesis_link_up(struct skge_port *skge)
1479 /* XM_PAUSE_DA = '010000C28001' (default) */ 1488 /* XM_PAUSE_DA = '010000C28001' (default) */
1480 /* XM_MAC_PTIME = 0xffff (maximum) */ 1489 /* XM_MAC_PTIME = 0xffff (maximum) */
1481 /* remember this value is defined in big endian (!) */ 1490 /* remember this value is defined in big endian (!) */
1482 skge_xm_write16(hw, port, XM_MAC_PTIME, 0xffff); 1491 xm_write16(hw, port, XM_MAC_PTIME, 0xffff);
1483 1492
1484 mode |= XM_PAUSE_MODE; 1493 mode |= XM_PAUSE_MODE;
1485 skge_write16(hw, SKGEMAC_REG(port, RX_MFF_CTRL1), MFF_ENA_PAUSE); 1494 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_PAUSE);
1486 } else { 1495 } else {
1487 /* 1496 /*
1488 * disable pause frame generation is required for 1000BT 1497 * disable pause frame generation is required for 1000BT
@@ -1491,125 +1500,68 @@ static void genesis_link_up(struct skge_port *skge)
1491 /* Disable Pause Mode in Mode Register */ 1500 /* Disable Pause Mode in Mode Register */
1492 mode &= ~XM_PAUSE_MODE; 1501 mode &= ~XM_PAUSE_MODE;
1493 1502
1494 skge_write16(hw, SKGEMAC_REG(port, RX_MFF_CTRL1), MFF_DIS_PAUSE); 1503 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_DIS_PAUSE);
1495 } 1504 }
1496 1505
1497 skge_xm_write32(hw, port, XM_MODE, mode); 1506 xm_write32(hw, port, XM_MODE, mode);
1498 1507
1499 msk = XM_DEF_MSK; 1508 msk = XM_DEF_MSK;
1500 if (hw->phy_type != SK_PHY_XMAC) 1509 /* disable GP0 interrupt bit for external Phy */
1501 msk |= XM_IS_INP_ASS; /* disable GP0 interrupt bit */ 1510 msk |= XM_IS_INP_ASS;
1502 1511
1503 skge_xm_write16(hw, port, XM_IMSK, msk); 1512 xm_write16(hw, port, XM_IMSK, msk);
1504 skge_xm_read16(hw, port, XM_ISRC); 1513 xm_read16(hw, port, XM_ISRC);
1505 1514
1506 /* get MMU Command Reg. */ 1515 /* get MMU Command Reg. */
1507 cmd = skge_xm_read16(hw, port, XM_MMU_CMD); 1516 cmd = xm_read16(hw, port, XM_MMU_CMD);
1508 if (hw->phy_type != SK_PHY_XMAC && skge->duplex == DUPLEX_FULL) 1517 if (skge->duplex == DUPLEX_FULL)
1509 cmd |= XM_MMU_GMII_FD; 1518 cmd |= XM_MMU_GMII_FD;
1510 1519
1511 if (hw->phy_type == SK_PHY_BCOM) { 1520 /*
1512 /* 1521 * Workaround BCOM Errata (#10523) for all BCom Phys
1513 * Workaround BCOM Errata (#10523) for all BCom Phys 1522 * Enable Power Management after link up
1514 * Enable Power Management after link up 1523 */
1515 */ 1524 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1516 skge_xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, 1525 xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL)
1517 skge_xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL) 1526 & ~PHY_B_AC_DIS_PM);
1518 & ~PHY_B_AC_DIS_PM); 1527 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
1519 skge_xm_phy_write(hw, port, PHY_BCOM_INT_MASK,
1520 PHY_B_DEF_MSK);
1521 }
1522 1528
1523 /* enable Rx/Tx */ 1529 /* enable Rx/Tx */
1524 skge_xm_write16(hw, port, XM_MMU_CMD, 1530 xm_write16(hw, port, XM_MMU_CMD,
1525 cmd | XM_MMU_ENA_RX | XM_MMU_ENA_TX); 1531 cmd | XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1526 skge_link_up(skge); 1532 skge_link_up(skge);
1527} 1533}
1528 1534
1529 1535
1530static void genesis_bcom_intr(struct skge_port *skge) 1536static inline void bcom_phy_intr(struct skge_port *skge)
1531{ 1537{
1532 struct skge_hw *hw = skge->hw; 1538 struct skge_hw *hw = skge->hw;
1533 int port = skge->port; 1539 int port = skge->port;
1534 u16 stat = skge_xm_phy_read(hw, port, PHY_BCOM_INT_STAT); 1540 u16 isrc;
1541
1542 isrc = xm_phy_read(hw, port, PHY_BCOM_INT_STAT);
1543 if (netif_msg_intr(skge))
1544 printk(KERN_DEBUG PFX "%s: phy interrupt status 0x%x\n",
1545 skge->netdev->name, isrc);
1535 1546
1536 pr_debug("genesis_bcom intr stat=%x\n", stat); 1547 if (isrc & PHY_B_IS_PSE)
1548 printk(KERN_ERR PFX "%s: uncorrectable pair swap error\n",
1549 hw->dev[port]->name);
1537 1550
1538 /* Workaround BCom Errata: 1551 /* Workaround BCom Errata:
1539 * enable and disable loopback mode if "NO HCD" occurs. 1552 * enable and disable loopback mode if "NO HCD" occurs.
1540 */ 1553 */
1541 if (stat & PHY_B_IS_NO_HDCL) { 1554 if (isrc & PHY_B_IS_NO_HDCL) {
1542 u16 ctrl = skge_xm_phy_read(hw, port, PHY_BCOM_CTRL); 1555 u16 ctrl = xm_phy_read(hw, port, PHY_BCOM_CTRL);
1543 skge_xm_phy_write(hw, port, PHY_BCOM_CTRL, 1556 xm_phy_write(hw, port, PHY_BCOM_CTRL,
1544 ctrl | PHY_CT_LOOP); 1557 ctrl | PHY_CT_LOOP);
1545 skge_xm_phy_write(hw, port, PHY_BCOM_CTRL, 1558 xm_phy_write(hw, port, PHY_BCOM_CTRL,
1546 ctrl & ~PHY_CT_LOOP); 1559 ctrl & ~PHY_CT_LOOP);
1547 } 1560 }
1548 1561
1549 stat = skge_xm_phy_read(hw, port, PHY_BCOM_STAT); 1562 if (isrc & (PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE))
1550 if (stat & (PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE)) { 1563 bcom_check_link(hw, port);
1551 u16 aux = skge_xm_phy_read(hw, port, PHY_BCOM_AUX_STAT);
1552 if ( !(aux & PHY_B_AS_LS) && netif_carrier_ok(skge->netdev))
1553 genesis_link_down(skge);
1554
1555 else if (stat & PHY_B_IS_LST_CHANGE) {
1556 if (aux & PHY_B_AS_AN_C) {
1557 switch (aux & PHY_B_AS_AN_RES_MSK) {
1558 case PHY_B_RES_1000FD:
1559 skge->duplex = DUPLEX_FULL;
1560 break;
1561 case PHY_B_RES_1000HD:
1562 skge->duplex = DUPLEX_HALF;
1563 break;
1564 }
1565
1566 switch (aux & PHY_B_AS_PAUSE_MSK) {
1567 case PHY_B_AS_PAUSE_MSK:
1568 skge->flow_control = FLOW_MODE_SYMMETRIC;
1569 break;
1570 case PHY_B_AS_PRR:
1571 skge->flow_control = FLOW_MODE_REM_SEND;
1572 break;
1573 case PHY_B_AS_PRT:
1574 skge->flow_control = FLOW_MODE_LOC_SEND;
1575 break;
1576 default:
1577 skge->flow_control = FLOW_MODE_NONE;
1578 }
1579 skge->speed = SPEED_1000;
1580 }
1581 genesis_link_up(skge);
1582 }
1583 else
1584 mod_timer(&skge->link_check, jiffies + LINK_POLL_HZ);
1585 }
1586}
1587 1564
1588/* Perodic poll of phy status to check for link transistion */
1589static void skge_link_timer(unsigned long __arg)
1590{
1591 struct skge_port *skge = (struct skge_port *) __arg;
1592 struct skge_hw *hw = skge->hw;
1593 int port = skge->port;
1594
1595 if (hw->chip_id != CHIP_ID_GENESIS || !netif_running(skge->netdev))
1596 return;
1597
1598 spin_lock_bh(&hw->phy_lock);
1599 if (hw->phy_type == SK_PHY_BCOM)
1600 genesis_bcom_intr(skge);
1601 else {
1602 int i;
1603 for (i = 0; i < 3; i++)
1604 if (skge_xm_read16(hw, port, XM_ISRC) & XM_IS_INP_ASS)
1605 break;
1606
1607 if (i == 3)
1608 mod_timer(&skge->link_check, jiffies + LINK_POLL_HZ);
1609 else
1610 genesis_link_up(skge);
1611 }
1612 spin_unlock_bh(&hw->phy_lock);
1613} 1565}
1614 1566
1615/* Marvell Phy Initailization */ 1567/* Marvell Phy Initailization */
@@ -1621,31 +1573,27 @@ static void yukon_init(struct skge_hw *hw, int port)
1621 1573
1622 pr_debug("yukon_init\n"); 1574 pr_debug("yukon_init\n");
1623 if (skge->autoneg == AUTONEG_ENABLE) { 1575 if (skge->autoneg == AUTONEG_ENABLE) {
1624 u16 ectrl = skge_gm_phy_read(hw, port, PHY_MARV_EXT_CTRL); 1576 u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
1625 1577
1626 ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK | 1578 ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
1627 PHY_M_EC_MAC_S_MSK); 1579 PHY_M_EC_MAC_S_MSK);
1628 ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ); 1580 ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ);
1629 1581
1630 /* on PHY 88E1111 there is a change for downshift control */ 1582 ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
1631 if (hw->chip_id == CHIP_ID_YUKON_EC)
1632 ectrl |= PHY_M_EC_M_DSC_2(0) | PHY_M_EC_DOWN_S_ENA;
1633 else
1634 ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
1635 1583
1636 skge_gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl); 1584 gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl);
1637 } 1585 }
1638 1586
1639 ctrl = skge_gm_phy_read(hw, port, PHY_MARV_CTRL); 1587 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
1640 if (skge->autoneg == AUTONEG_DISABLE) 1588 if (skge->autoneg == AUTONEG_DISABLE)
1641 ctrl &= ~PHY_CT_ANE; 1589 ctrl &= ~PHY_CT_ANE;
1642 1590
1643 ctrl |= PHY_CT_RESET; 1591 ctrl |= PHY_CT_RESET;
1644 skge_gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); 1592 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
1645 1593
1646 ctrl = 0; 1594 ctrl = 0;
1647 ct1000 = 0; 1595 ct1000 = 0;
1648 adv = PHY_SEL_TYPE; 1596 adv = PHY_AN_CSMA;
1649 1597
1650 if (skge->autoneg == AUTONEG_ENABLE) { 1598 if (skge->autoneg == AUTONEG_ENABLE) {
1651 if (iscopper(hw)) { 1599 if (iscopper(hw)) {
@@ -1661,41 +1609,12 @@ static void yukon_init(struct skge_hw *hw, int port)
1661 adv |= PHY_M_AN_10_FD; 1609 adv |= PHY_M_AN_10_FD;
1662 if (skge->advertising & ADVERTISED_10baseT_Half) 1610 if (skge->advertising & ADVERTISED_10baseT_Half)
1663 adv |= PHY_M_AN_10_HD; 1611 adv |= PHY_M_AN_10_HD;
1664 1612 } else /* special defines for FIBER (88E1011S only) */
1665 /* Set Flow-control capabilities */
1666 switch (skge->flow_control) {
1667 case FLOW_MODE_NONE:
1668 adv |= PHY_B_P_NO_PAUSE;
1669 break;
1670 case FLOW_MODE_LOC_SEND:
1671 adv |= PHY_B_P_ASYM_MD;
1672 break;
1673 case FLOW_MODE_SYMMETRIC:
1674 adv |= PHY_B_P_SYM_MD;
1675 break;
1676 case FLOW_MODE_REM_SEND:
1677 adv |= PHY_B_P_BOTH_MD;
1678 break;
1679 }
1680 } else { /* special defines for FIBER (88E1011S only) */
1681 adv |= PHY_M_AN_1000X_AHD | PHY_M_AN_1000X_AFD; 1613 adv |= PHY_M_AN_1000X_AHD | PHY_M_AN_1000X_AFD;
1682 1614
1683 /* Set Flow-control capabilities */ 1615 /* Set Flow-control capabilities */
1684 switch (skge->flow_control) { 1616 adv |= phy_pause_map[skge->flow_control];
1685 case FLOW_MODE_NONE: 1617
1686 adv |= PHY_M_P_NO_PAUSE_X;
1687 break;
1688 case FLOW_MODE_LOC_SEND:
1689 adv |= PHY_M_P_ASYM_MD_X;
1690 break;
1691 case FLOW_MODE_SYMMETRIC:
1692 adv |= PHY_M_P_SYM_MD_X;
1693 break;
1694 case FLOW_MODE_REM_SEND:
1695 adv |= PHY_M_P_BOTH_MD_X;
1696 break;
1697 }
1698 }
1699 /* Restart Auto-negotiation */ 1618 /* Restart Auto-negotiation */
1700 ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG; 1619 ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG;
1701 } else { 1620 } else {
@@ -1717,36 +1636,23 @@ static void yukon_init(struct skge_hw *hw, int port)
1717 ctrl |= PHY_CT_RESET; 1636 ctrl |= PHY_CT_RESET;
1718 } 1637 }
1719 1638
1720 if (hw->chip_id != CHIP_ID_YUKON_FE) 1639 gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000);
1721 skge_gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000);
1722 1640
1723 skge_gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv); 1641 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv);
1724 skge_gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); 1642 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
1725 1643
1726 /* Setup Phy LED's */ 1644 /* Setup Phy LED's */
1727 ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS); 1645 ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS);
1728 ledover = 0; 1646 ledover = 0;
1729 1647
1730 if (hw->chip_id == CHIP_ID_YUKON_FE) { 1648 ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL;
1731 /* on 88E3082 these bits are at 11..9 (shifted left) */
1732 ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) << 1;
1733
1734 skge_gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR,
1735 ((skge_gm_phy_read(hw, port, PHY_MARV_FE_LED_PAR)
1736
1737 & ~PHY_M_FELP_LED1_MSK)
1738 | PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_ACT_BL)));
1739 } else {
1740 /* set Tx LED (LED_TX) to blink mode on Rx OR Tx activity */
1741 ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL;
1742 1649
1743 /* turn off the Rx LED (LED_RX) */ 1650 /* turn off the Rx LED (LED_RX) */
1744 ledover |= PHY_M_LED_MO_RX(MO_LED_OFF); 1651 ledover |= PHY_M_LED_MO_RX(MO_LED_OFF);
1745 }
1746 1652
1747 /* disable blink mode (LED_DUPLEX) on collisions */ 1653 /* disable blink mode (LED_DUPLEX) on collisions */
1748 ctrl |= PHY_M_LEDC_DP_CTRL; 1654 ctrl |= PHY_M_LEDC_DP_CTRL;
1749 skge_gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl); 1655 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl);
1750 1656
1751 if (skge->autoneg == AUTONEG_DISABLE || skge->speed == SPEED_100) { 1657 if (skge->autoneg == AUTONEG_DISABLE || skge->speed == SPEED_100) {
1752 /* turn on 100 Mbps LED (LED_LINK100) */ 1658 /* turn on 100 Mbps LED (LED_LINK100) */
@@ -1754,25 +1660,25 @@ static void yukon_init(struct skge_hw *hw, int port)
1754 } 1660 }
1755 1661
1756 if (ledover) 1662 if (ledover)
1757 skge_gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover); 1663 gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover);
1758 1664
1759 /* Enable phy interrupt on autonegotiation complete (or link up) */ 1665 /* Enable phy interrupt on autonegotiation complete (or link up) */
1760 if (skge->autoneg == AUTONEG_ENABLE) 1666 if (skge->autoneg == AUTONEG_ENABLE)
1761 skge_gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL); 1667 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL);
1762 else 1668 else
1763 skge_gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); 1669 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
1764} 1670}
1765 1671
1766static void yukon_reset(struct skge_hw *hw, int port) 1672static void yukon_reset(struct skge_hw *hw, int port)
1767{ 1673{
1768 skge_gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);/* disable PHY IRQs */ 1674 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);/* disable PHY IRQs */
1769 skge_gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */ 1675 gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */
1770 skge_gma_write16(hw, port, GM_MC_ADDR_H2, 0); 1676 gma_write16(hw, port, GM_MC_ADDR_H2, 0);
1771 skge_gma_write16(hw, port, GM_MC_ADDR_H3, 0); 1677 gma_write16(hw, port, GM_MC_ADDR_H3, 0);
1772 skge_gma_write16(hw, port, GM_MC_ADDR_H4, 0); 1678 gma_write16(hw, port, GM_MC_ADDR_H4, 0);
1773 1679
1774 skge_gma_write16(hw, port, GM_RX_CTRL, 1680 gma_write16(hw, port, GM_RX_CTRL,
1775 skge_gma_read16(hw, port, GM_RX_CTRL) 1681 gma_read16(hw, port, GM_RX_CTRL)
1776 | GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); 1682 | GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
1777} 1683}
1778 1684
@@ -1785,17 +1691,17 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1785 1691
1786 /* WA code for COMA mode -- set PHY reset */ 1692 /* WA code for COMA mode -- set PHY reset */
1787 if (hw->chip_id == CHIP_ID_YUKON_LITE && 1693 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
1788 chip_rev(hw) == CHIP_REV_YU_LITE_A3) 1694 hw->chip_rev == CHIP_REV_YU_LITE_A3)
1789 skge_write32(hw, B2_GP_IO, 1695 skge_write32(hw, B2_GP_IO,
1790 (skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9)); 1696 (skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9));
1791 1697
1792 /* hard reset */ 1698 /* hard reset */
1793 skge_write32(hw, SKGEMAC_REG(port, GPHY_CTRL), GPC_RST_SET); 1699 skge_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
1794 skge_write32(hw, SKGEMAC_REG(port, GMAC_CTRL), GMC_RST_SET); 1700 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
1795 1701
1796 /* WA code for COMA mode -- clear PHY reset */ 1702 /* WA code for COMA mode -- clear PHY reset */
1797 if (hw->chip_id == CHIP_ID_YUKON_LITE && 1703 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
1798 chip_rev(hw) == CHIP_REV_YU_LITE_A3) 1704 hw->chip_rev == CHIP_REV_YU_LITE_A3)
1799 skge_write32(hw, B2_GP_IO, 1705 skge_write32(hw, B2_GP_IO,
1800 (skge_read32(hw, B2_GP_IO) | GP_DIR_9) 1706 (skge_read32(hw, B2_GP_IO) | GP_DIR_9)
1801 & ~GP_IO_9); 1707 & ~GP_IO_9);
@@ -1806,13 +1712,13 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1806 reg |= iscopper(hw) ? GPC_HWCFG_GMII_COP : GPC_HWCFG_GMII_FIB; 1712 reg |= iscopper(hw) ? GPC_HWCFG_GMII_COP : GPC_HWCFG_GMII_FIB;
1807 1713
1808 /* Clear GMC reset */ 1714 /* Clear GMC reset */
1809 skge_write32(hw, SKGEMAC_REG(port, GPHY_CTRL), reg | GPC_RST_SET); 1715 skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_SET);
1810 skge_write32(hw, SKGEMAC_REG(port, GPHY_CTRL), reg | GPC_RST_CLR); 1716 skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_CLR);
1811 skge_write32(hw, SKGEMAC_REG(port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR); 1717 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR);
1812 if (skge->autoneg == AUTONEG_DISABLE) { 1718 if (skge->autoneg == AUTONEG_DISABLE) {
1813 reg = GM_GPCR_AU_ALL_DIS; 1719 reg = GM_GPCR_AU_ALL_DIS;
1814 skge_gma_write16(hw, port, GM_GP_CTRL, 1720 gma_write16(hw, port, GM_GP_CTRL,
1815 skge_gma_read16(hw, port, GM_GP_CTRL) | reg); 1721 gma_read16(hw, port, GM_GP_CTRL) | reg);
1816 1722
1817 switch (skge->speed) { 1723 switch (skge->speed) {
1818 case SPEED_1000: 1724 case SPEED_1000:
@@ -1828,7 +1734,7 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1828 reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL; 1734 reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL;
1829 switch (skge->flow_control) { 1735 switch (skge->flow_control) {
1830 case FLOW_MODE_NONE: 1736 case FLOW_MODE_NONE:
1831 skge_write32(hw, SKGEMAC_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); 1737 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
1832 reg |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS; 1738 reg |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
1833 break; 1739 break;
1834 case FLOW_MODE_LOC_SEND: 1740 case FLOW_MODE_LOC_SEND:
@@ -1836,7 +1742,7 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1836 reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS; 1742 reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
1837 } 1743 }
1838 1744
1839 skge_gma_write16(hw, port, GM_GP_CTRL, reg); 1745 gma_write16(hw, port, GM_GP_CTRL, reg);
1840 skge_read16(hw, GMAC_IRQ_SRC); 1746 skge_read16(hw, GMAC_IRQ_SRC);
1841 1747
1842 spin_lock_bh(&hw->phy_lock); 1748 spin_lock_bh(&hw->phy_lock);
@@ -1844,25 +1750,25 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1844 spin_unlock_bh(&hw->phy_lock); 1750 spin_unlock_bh(&hw->phy_lock);
1845 1751
1846 /* MIB clear */ 1752 /* MIB clear */
1847 reg = skge_gma_read16(hw, port, GM_PHY_ADDR); 1753 reg = gma_read16(hw, port, GM_PHY_ADDR);
1848 skge_gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR); 1754 gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR);
1849 1755
1850 for (i = 0; i < GM_MIB_CNT_SIZE; i++) 1756 for (i = 0; i < GM_MIB_CNT_SIZE; i++)
1851 skge_gma_read16(hw, port, GM_MIB_CNT_BASE + 8*i); 1757 gma_read16(hw, port, GM_MIB_CNT_BASE + 8*i);
1852 skge_gma_write16(hw, port, GM_PHY_ADDR, reg); 1758 gma_write16(hw, port, GM_PHY_ADDR, reg);
1853 1759
1854 /* transmit control */ 1760 /* transmit control */
1855 skge_gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF)); 1761 gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF));
1856 1762
1857 /* receive control reg: unicast + multicast + no FCS */ 1763 /* receive control reg: unicast + multicast + no FCS */
1858 skge_gma_write16(hw, port, GM_RX_CTRL, 1764 gma_write16(hw, port, GM_RX_CTRL,
1859 GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA); 1765 GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA);
1860 1766
1861 /* transmit flow control */ 1767 /* transmit flow control */
1862 skge_gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff); 1768 gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff);
1863 1769
1864 /* transmit parameter */ 1770 /* transmit parameter */
1865 skge_gma_write16(hw, port, GM_TX_PARAM, 1771 gma_write16(hw, port, GM_TX_PARAM,
1866 TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) | 1772 TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) |
1867 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) | 1773 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) |
1868 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF)); 1774 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF));
@@ -1872,33 +1778,33 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1872 if (hw->dev[port]->mtu > 1500) 1778 if (hw->dev[port]->mtu > 1500)
1873 reg |= GM_SMOD_JUMBO_ENA; 1779 reg |= GM_SMOD_JUMBO_ENA;
1874 1780
1875 skge_gma_write16(hw, port, GM_SERIAL_MODE, reg); 1781 gma_write16(hw, port, GM_SERIAL_MODE, reg);
1876 1782
1877 /* physical address: used for pause frames */ 1783 /* physical address: used for pause frames */
1878 skge_gm_set_addr(hw, port, GM_SRC_ADDR_1L, addr); 1784 gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr);
1879 /* virtual address for data */ 1785 /* virtual address for data */
1880 skge_gm_set_addr(hw, port, GM_SRC_ADDR_2L, addr); 1786 gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr);
1881 1787
1882 /* enable interrupt mask for counter overflows */ 1788 /* enable interrupt mask for counter overflows */
1883 skge_gma_write16(hw, port, GM_TX_IRQ_MSK, 0); 1789 gma_write16(hw, port, GM_TX_IRQ_MSK, 0);
1884 skge_gma_write16(hw, port, GM_RX_IRQ_MSK, 0); 1790 gma_write16(hw, port, GM_RX_IRQ_MSK, 0);
1885 skge_gma_write16(hw, port, GM_TR_IRQ_MSK, 0); 1791 gma_write16(hw, port, GM_TR_IRQ_MSK, 0);
1886 1792
1887 /* Initialize Mac Fifo */ 1793 /* Initialize Mac Fifo */
1888 1794
1889 /* Configure Rx MAC FIFO */ 1795 /* Configure Rx MAC FIFO */
1890 skge_write16(hw, SKGEMAC_REG(port, RX_GMF_FL_MSK), RX_FF_FL_DEF_MSK); 1796 skge_write16(hw, SK_REG(port, RX_GMF_FL_MSK), RX_FF_FL_DEF_MSK);
1891 reg = GMF_OPER_ON | GMF_RX_F_FL_ON; 1797 reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
1892 if (hw->chip_id == CHIP_ID_YUKON_LITE && 1798 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
1893 chip_rev(hw) == CHIP_REV_YU_LITE_A3) 1799 hw->chip_rev == CHIP_REV_YU_LITE_A3)
1894 reg &= ~GMF_RX_F_FL_ON; 1800 reg &= ~GMF_RX_F_FL_ON;
1895 skge_write8(hw, SKGEMAC_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR); 1801 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
1896 skge_write16(hw, SKGEMAC_REG(port, RX_GMF_CTRL_T), reg); 1802 skge_write16(hw, SK_REG(port, RX_GMF_CTRL_T), reg);
1897 skge_write16(hw, SKGEMAC_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF); 1803 skge_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF);
1898 1804
1899 /* Configure Tx MAC FIFO */ 1805 /* Configure Tx MAC FIFO */
1900 skge_write8(hw, SKGEMAC_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR); 1806 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
1901 skge_write16(hw, SKGEMAC_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON); 1807 skge_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
1902} 1808}
1903 1809
1904static void yukon_stop(struct skge_port *skge) 1810static void yukon_stop(struct skge_port *skge)
@@ -1907,19 +1813,19 @@ static void yukon_stop(struct skge_port *skge)
1907 int port = skge->port; 1813 int port = skge->port;
1908 1814
1909 if (hw->chip_id == CHIP_ID_YUKON_LITE && 1815 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
1910 chip_rev(hw) == CHIP_REV_YU_LITE_A3) { 1816 hw->chip_rev == CHIP_REV_YU_LITE_A3) {
1911 skge_write32(hw, B2_GP_IO, 1817 skge_write32(hw, B2_GP_IO,
1912 skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9); 1818 skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9);
1913 } 1819 }
1914 1820
1915 skge_gma_write16(hw, port, GM_GP_CTRL, 1821 gma_write16(hw, port, GM_GP_CTRL,
1916 skge_gma_read16(hw, port, GM_GP_CTRL) 1822 gma_read16(hw, port, GM_GP_CTRL)
1917 & ~(GM_GPCR_RX_ENA|GM_GPCR_RX_ENA)); 1823 & ~(GM_GPCR_RX_ENA|GM_GPCR_RX_ENA));
1918 skge_gma_read16(hw, port, GM_GP_CTRL); 1824 gma_read16(hw, port, GM_GP_CTRL);
1919 1825
1920 /* set GPHY Control reset */ 1826 /* set GPHY Control reset */
1921 skge_gma_write32(hw, port, GPHY_CTRL, GPC_RST_SET); 1827 gma_write32(hw, port, GPHY_CTRL, GPC_RST_SET);
1922 skge_gma_write32(hw, port, GMAC_CTRL, GMC_RST_SET); 1828 gma_write32(hw, port, GMAC_CTRL, GMC_RST_SET);
1923} 1829}
1924 1830
1925static void yukon_get_stats(struct skge_port *skge, u64 *data) 1831static void yukon_get_stats(struct skge_port *skge, u64 *data)
@@ -1928,39 +1834,40 @@ static void yukon_get_stats(struct skge_port *skge, u64 *data)
1928 int port = skge->port; 1834 int port = skge->port;
1929 int i; 1835 int i;
1930 1836
1931 data[0] = (u64) skge_gma_read32(hw, port, GM_TXO_OK_HI) << 32 1837 data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32
1932 | skge_gma_read32(hw, port, GM_TXO_OK_LO); 1838 | gma_read32(hw, port, GM_TXO_OK_LO);
1933 data[1] = (u64) skge_gma_read32(hw, port, GM_RXO_OK_HI) << 32 1839 data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32
1934 | skge_gma_read32(hw, port, GM_RXO_OK_LO); 1840 | gma_read32(hw, port, GM_RXO_OK_LO);
1935 1841
1936 for (i = 2; i < ARRAY_SIZE(skge_stats); i++) 1842 for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
1937 data[i] = skge_gma_read32(hw, port, 1843 data[i] = gma_read32(hw, port,
1938 skge_stats[i].gma_offset); 1844 skge_stats[i].gma_offset);
1939} 1845}
1940 1846
1941static void yukon_mac_intr(struct skge_hw *hw, int port) 1847static void yukon_mac_intr(struct skge_hw *hw, int port)
1942{ 1848{
1943 struct skge_port *skge = netdev_priv(hw->dev[port]); 1849 struct net_device *dev = hw->dev[port];
1944 u8 status = skge_read8(hw, SKGEMAC_REG(port, GMAC_IRQ_SRC)); 1850 struct skge_port *skge = netdev_priv(dev);
1851 u8 status = skge_read8(hw, SK_REG(port, GMAC_IRQ_SRC));
1852
1853 if (netif_msg_intr(skge))
1854 printk(KERN_DEBUG PFX "%s: mac interrupt status 0x%x\n",
1855 dev->name, status);
1945 1856
1946 pr_debug("yukon_intr status %x\n", status);
1947 if (status & GM_IS_RX_FF_OR) { 1857 if (status & GM_IS_RX_FF_OR) {
1948 ++skge->net_stats.rx_fifo_errors; 1858 ++skge->net_stats.rx_fifo_errors;
1949 skge_gma_write8(hw, port, RX_GMF_CTRL_T, GMF_CLI_RX_FO); 1859 gma_write8(hw, port, RX_GMF_CTRL_T, GMF_CLI_RX_FO);
1950 } 1860 }
1951 if (status & GM_IS_TX_FF_UR) { 1861 if (status & GM_IS_TX_FF_UR) {
1952 ++skge->net_stats.tx_fifo_errors; 1862 ++skge->net_stats.tx_fifo_errors;
1953 skge_gma_write8(hw, port, TX_GMF_CTRL_T, GMF_CLI_TX_FU); 1863 gma_write8(hw, port, TX_GMF_CTRL_T, GMF_CLI_TX_FU);
1954 } 1864 }
1955 1865
1956} 1866}
1957 1867
1958static u16 yukon_speed(const struct skge_hw *hw, u16 aux) 1868static u16 yukon_speed(const struct skge_hw *hw, u16 aux)
1959{ 1869{
1960 if (hw->chip_id == CHIP_ID_YUKON_FE) 1870 switch (aux & PHY_M_PS_SPEED_MSK) {
1961 return (aux & PHY_M_PS_SPEED_100) ? SPEED_100 : SPEED_10;
1962
1963 switch(aux & PHY_M_PS_SPEED_MSK) {
1964 case PHY_M_PS_SPEED_1000: 1871 case PHY_M_PS_SPEED_1000:
1965 return SPEED_1000; 1872 return SPEED_1000;
1966 case PHY_M_PS_SPEED_100: 1873 case PHY_M_PS_SPEED_100:
@@ -1981,15 +1888,15 @@ static void yukon_link_up(struct skge_port *skge)
1981 /* Enable Transmit FIFO Underrun */ 1888 /* Enable Transmit FIFO Underrun */
1982 skge_write8(hw, GMAC_IRQ_MSK, GMAC_DEF_MSK); 1889 skge_write8(hw, GMAC_IRQ_MSK, GMAC_DEF_MSK);
1983 1890
1984 reg = skge_gma_read16(hw, port, GM_GP_CTRL); 1891 reg = gma_read16(hw, port, GM_GP_CTRL);
1985 if (skge->duplex == DUPLEX_FULL || skge->autoneg == AUTONEG_ENABLE) 1892 if (skge->duplex == DUPLEX_FULL || skge->autoneg == AUTONEG_ENABLE)
1986 reg |= GM_GPCR_DUP_FULL; 1893 reg |= GM_GPCR_DUP_FULL;
1987 1894
1988 /* enable Rx/Tx */ 1895 /* enable Rx/Tx */
1989 reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA; 1896 reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA;
1990 skge_gma_write16(hw, port, GM_GP_CTRL, reg); 1897 gma_write16(hw, port, GM_GP_CTRL, reg);
1991 1898
1992 skge_gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); 1899 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
1993 skge_link_up(skge); 1900 skge_link_up(skge);
1994} 1901}
1995 1902
@@ -1999,16 +1906,15 @@ static void yukon_link_down(struct skge_port *skge)
1999 int port = skge->port; 1906 int port = skge->port;
2000 1907
2001 pr_debug("yukon_link_down\n"); 1908 pr_debug("yukon_link_down\n");
2002 skge_gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0); 1909 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);
2003 skge_gm_phy_write(hw, port, GM_GP_CTRL, 1910 gm_phy_write(hw, port, GM_GP_CTRL,
2004 skge_gm_phy_read(hw, port, GM_GP_CTRL) 1911 gm_phy_read(hw, port, GM_GP_CTRL)
2005 & ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA)); 1912 & ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA));
2006 1913
2007 if (hw->chip_id != CHIP_ID_YUKON_FE && 1914 if (skge->flow_control == FLOW_MODE_REM_SEND) {
2008 skge->flow_control == FLOW_MODE_REM_SEND) {
2009 /* restore Asymmetric Pause bit */ 1915 /* restore Asymmetric Pause bit */
2010 skge_gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, 1916 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV,
2011 skge_gm_phy_read(hw, port, 1917 gm_phy_read(hw, port,
2012 PHY_MARV_AUNE_ADV) 1918 PHY_MARV_AUNE_ADV)
2013 | PHY_M_AN_ASP); 1919 | PHY_M_AN_ASP);
2014 1920
@@ -2027,20 +1933,21 @@ static void yukon_phy_intr(struct skge_port *skge)
2027 const char *reason = NULL; 1933 const char *reason = NULL;
2028 u16 istatus, phystat; 1934 u16 istatus, phystat;
2029 1935
2030 istatus = skge_gm_phy_read(hw, port, PHY_MARV_INT_STAT); 1936 istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT);
2031 phystat = skge_gm_phy_read(hw, port, PHY_MARV_PHY_STAT); 1937 phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT);
2032 pr_debug("yukon phy intr istat=%x phy_stat=%x\n", istatus, phystat); 1938
1939 if (netif_msg_intr(skge))
1940 printk(KERN_DEBUG PFX "%s: phy interrupt status 0x%x 0x%x\n",
1941 skge->netdev->name, istatus, phystat);
2033 1942
2034 if (istatus & PHY_M_IS_AN_COMPL) { 1943 if (istatus & PHY_M_IS_AN_COMPL) {
2035 if (skge_gm_phy_read(hw, port, PHY_MARV_AUNE_LP) 1944 if (gm_phy_read(hw, port, PHY_MARV_AUNE_LP)
2036 & PHY_M_AN_RF) { 1945 & PHY_M_AN_RF) {
2037 reason = "remote fault"; 1946 reason = "remote fault";
2038 goto failed; 1947 goto failed;
2039 } 1948 }
2040 1949
2041 if (!(hw->chip_id == CHIP_ID_YUKON_FE || hw->chip_id == CHIP_ID_YUKON_EC) 1950 if (gm_phy_read(hw, port, PHY_MARV_1000T_STAT) & PHY_B_1000S_MSF) {
2042 && (skge_gm_phy_read(hw, port, PHY_MARV_1000T_STAT)
2043 & PHY_B_1000S_MSF)) {
2044 reason = "master/slave fault"; 1951 reason = "master/slave fault";
2045 goto failed; 1952 goto failed;
2046 } 1953 }
@@ -2054,10 +1961,6 @@ static void yukon_phy_intr(struct skge_port *skge)
2054 ? DUPLEX_FULL : DUPLEX_HALF; 1961 ? DUPLEX_FULL : DUPLEX_HALF;
2055 skge->speed = yukon_speed(hw, phystat); 1962 skge->speed = yukon_speed(hw, phystat);
2056 1963
2057 /* Tx & Rx Pause Enabled bits are at 9..8 */
2058 if (hw->chip_id == CHIP_ID_YUKON_XL)
2059 phystat >>= 6;
2060
2061 /* We are using IEEE 802.3z/D5.0 Table 37-4 */ 1964 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
2062 switch (phystat & PHY_M_PS_PAUSE_MSK) { 1965 switch (phystat & PHY_M_PS_PAUSE_MSK) {
2063 case PHY_M_PS_PAUSE_MSK: 1966 case PHY_M_PS_PAUSE_MSK:
@@ -2075,9 +1978,9 @@ static void yukon_phy_intr(struct skge_port *skge)
2075 1978
2076 if (skge->flow_control == FLOW_MODE_NONE || 1979 if (skge->flow_control == FLOW_MODE_NONE ||
2077 (skge->speed < SPEED_1000 && skge->duplex == DUPLEX_HALF)) 1980 (skge->speed < SPEED_1000 && skge->duplex == DUPLEX_HALF))
2078 skge_write8(hw, SKGEMAC_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); 1981 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
2079 else 1982 else
2080 skge_write8(hw, SKGEMAC_REG(port, GMAC_CTRL), GMC_PAUSE_ON); 1983 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
2081 yukon_link_up(skge); 1984 yukon_link_up(skge);
2082 return; 1985 return;
2083 } 1986 }
@@ -2161,6 +2064,12 @@ static int skge_up(struct net_device *dev)
2161 if (netif_msg_ifup(skge)) 2064 if (netif_msg_ifup(skge))
2162 printk(KERN_INFO PFX "%s: enabling interface\n", dev->name); 2065 printk(KERN_INFO PFX "%s: enabling interface\n", dev->name);
2163 2066
2067 if (dev->mtu > RX_BUF_SIZE)
2068 skge->rx_buf_size = dev->mtu + ETH_HLEN + NET_IP_ALIGN;
2069 else
2070 skge->rx_buf_size = RX_BUF_SIZE;
2071
2072
2164 rx_size = skge->rx_ring.count * sizeof(struct skge_rx_desc); 2073 rx_size = skge->rx_ring.count * sizeof(struct skge_rx_desc);
2165 tx_size = skge->tx_ring.count * sizeof(struct skge_tx_desc); 2074 tx_size = skge->tx_ring.count * sizeof(struct skge_tx_desc);
2166 skge->mem_size = tx_size + rx_size; 2075 skge->mem_size = tx_size + rx_size;
@@ -2173,7 +2082,8 @@ static int skge_up(struct net_device *dev)
2173 if ((err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma))) 2082 if ((err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma)))
2174 goto free_pci_mem; 2083 goto free_pci_mem;
2175 2084
2176 if (skge_rx_fill(skge)) 2085 err = skge_rx_fill(skge);
2086 if (err)
2177 goto free_rx_ring; 2087 goto free_rx_ring;
2178 2088
2179 if ((err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size, 2089 if ((err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size,
@@ -2182,6 +2092,10 @@ static int skge_up(struct net_device *dev)
2182 2092
2183 skge->tx_avail = skge->tx_ring.count - 1; 2093 skge->tx_avail = skge->tx_ring.count - 1;
2184 2094
2095 /* Enable IRQ from port */
2096 hw->intr_mask |= portirqmask[port];
2097 skge_write32(hw, B0_IMSK, hw->intr_mask);
2098
2185 /* Initialze MAC */ 2099 /* Initialze MAC */
2186 if (hw->chip_id == CHIP_ID_GENESIS) 2100 if (hw->chip_id == CHIP_ID_GENESIS)
2187 genesis_mac_init(hw, port); 2101 genesis_mac_init(hw, port);
@@ -2189,7 +2103,7 @@ static int skge_up(struct net_device *dev)
2189 yukon_mac_init(hw, port); 2103 yukon_mac_init(hw, port);
2190 2104
2191 /* Configure RAMbuffers */ 2105 /* Configure RAMbuffers */
2192 chunk = hw->ram_size / (isdualport(hw) ? 4 : 2); 2106 chunk = hw->ram_size / ((hw->ports + 1)*2);
2193 ram_addr = hw->ram_offset + 2 * chunk * port; 2107 ram_addr = hw->ram_offset + 2 * chunk * port;
2194 2108
2195 skge_ramset(hw, rxqaddr[port], ram_addr, chunk); 2109 skge_ramset(hw, rxqaddr[port], ram_addr, chunk);
@@ -2227,7 +2141,6 @@ static int skge_down(struct net_device *dev)
2227 netif_stop_queue(dev); 2141 netif_stop_queue(dev);
2228 2142
2229 del_timer_sync(&skge->led_blink); 2143 del_timer_sync(&skge->led_blink);
2230 del_timer_sync(&skge->link_check);
2231 2144
2232 /* Stop transmitter */ 2145 /* Stop transmitter */
2233 skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP); 2146 skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP);
@@ -2240,12 +2153,12 @@ static int skge_down(struct net_device *dev)
2240 yukon_stop(skge); 2153 yukon_stop(skge);
2241 2154
2242 /* Disable Force Sync bit and Enable Alloc bit */ 2155 /* Disable Force Sync bit and Enable Alloc bit */
2243 skge_write8(hw, SKGEMAC_REG(port, TXA_CTRL), 2156 skge_write8(hw, SK_REG(port, TXA_CTRL),
2244 TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC); 2157 TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
2245 2158
2246 /* Stop Interval Timer and Limit Counter of Tx Arbiter */ 2159 /* Stop Interval Timer and Limit Counter of Tx Arbiter */
2247 skge_write32(hw, SKGEMAC_REG(port, TXA_ITI_INI), 0L); 2160 skge_write32(hw, SK_REG(port, TXA_ITI_INI), 0L);
2248 skge_write32(hw, SKGEMAC_REG(port, TXA_LIM_INI), 0L); 2161 skge_write32(hw, SK_REG(port, TXA_LIM_INI), 0L);
2249 2162
2250 /* Reset PCI FIFO */ 2163 /* Reset PCI FIFO */
2251 skge_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_SET_RESET); 2164 skge_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_SET_RESET);
@@ -2260,13 +2173,13 @@ static int skge_down(struct net_device *dev)
2260 skge_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_SET_RESET); 2173 skge_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_SET_RESET);
2261 2174
2262 if (hw->chip_id == CHIP_ID_GENESIS) { 2175 if (hw->chip_id == CHIP_ID_GENESIS) {
2263 skge_write8(hw, SKGEMAC_REG(port, TX_MFF_CTRL2), MFF_RST_SET); 2176 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_SET);
2264 skge_write8(hw, SKGEMAC_REG(port, RX_MFF_CTRL2), MFF_RST_SET); 2177 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_SET);
2265 skge_write8(hw, SKGEMAC_REG(port, TX_LED_CTRL), LED_STOP); 2178 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_STOP);
2266 skge_write8(hw, SKGEMAC_REG(port, RX_LED_CTRL), LED_STOP); 2179 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_STOP);
2267 } else { 2180 } else {
2268 skge_write8(hw, SKGEMAC_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); 2181 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
2269 skge_write8(hw, SKGEMAC_REG(port, TX_GMF_CTRL_T), GMF_RST_SET); 2182 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
2270 } 2183 }
2271 2184
2272 /* turn off led's */ 2185 /* turn off led's */
@@ -2299,10 +2212,10 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
2299 2212
2300 local_irq_save(flags); 2213 local_irq_save(flags);
2301 if (!spin_trylock(&skge->tx_lock)) { 2214 if (!spin_trylock(&skge->tx_lock)) {
2302 /* Collision - tell upper layer to requeue */ 2215 /* Collision - tell upper layer to requeue */
2303 local_irq_restore(flags); 2216 local_irq_restore(flags);
2304 return NETDEV_TX_LOCKED; 2217 return NETDEV_TX_LOCKED;
2305 } 2218 }
2306 2219
2307 if (unlikely(skge->tx_avail < skb_shinfo(skb)->nr_frags +1)) { 2220 if (unlikely(skge->tx_avail < skb_shinfo(skb)->nr_frags +1)) {
2308 netif_stop_queue(dev); 2221 netif_stop_queue(dev);
@@ -2333,7 +2246,7 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
2333 * does. Looks like hardware is wrong? 2246 * does. Looks like hardware is wrong?
2334 */ 2247 */
2335 if (ip->protocol == IPPROTO_UDP 2248 if (ip->protocol == IPPROTO_UDP
2336 && chip_rev(hw) == 0 && hw->chip_id == CHIP_ID_YUKON) 2249 && hw->chip_rev == 0 && hw->chip_id == CHIP_ID_YUKON)
2337 control = BMU_TCP_CHECK; 2250 control = BMU_TCP_CHECK;
2338 else 2251 else
2339 control = BMU_UDP_CHECK; 2252 control = BMU_UDP_CHECK;
@@ -2394,6 +2307,7 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
2394 2307
2395static inline void skge_tx_free(struct skge_hw *hw, struct skge_element *e) 2308static inline void skge_tx_free(struct skge_hw *hw, struct skge_element *e)
2396{ 2309{
2310 /* This ring element can be skb or fragment */
2397 if (e->skb) { 2311 if (e->skb) {
2398 pci_unmap_single(hw->pdev, 2312 pci_unmap_single(hw->pdev,
2399 pci_unmap_addr(e, mapaddr), 2313 pci_unmap_addr(e, mapaddr),
@@ -2438,16 +2352,17 @@ static void skge_tx_timeout(struct net_device *dev)
2438static int skge_change_mtu(struct net_device *dev, int new_mtu) 2352static int skge_change_mtu(struct net_device *dev, int new_mtu)
2439{ 2353{
2440 int err = 0; 2354 int err = 0;
2355 int running = netif_running(dev);
2441 2356
2442 if(new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU) 2357 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
2443 return -EINVAL; 2358 return -EINVAL;
2444 2359
2445 dev->mtu = new_mtu;
2446 2360
2447 if (netif_running(dev)) { 2361 if (running)
2448 skge_down(dev); 2362 skge_down(dev);
2363 dev->mtu = new_mtu;
2364 if (running)
2449 skge_up(dev); 2365 skge_up(dev);
2450 }
2451 2366
2452 return err; 2367 return err;
2453} 2368}
@@ -2462,7 +2377,9 @@ static void genesis_set_multicast(struct net_device *dev)
2462 u32 mode; 2377 u32 mode;
2463 u8 filter[8]; 2378 u8 filter[8];
2464 2379
2465 mode = skge_xm_read32(hw, port, XM_MODE); 2380 pr_debug("genesis_set_multicast flags=%x count=%d\n", dev->flags, dev->mc_count);
2381
2382 mode = xm_read32(hw, port, XM_MODE);
2466 mode |= XM_MD_ENA_HASH; 2383 mode |= XM_MD_ENA_HASH;
2467 if (dev->flags & IFF_PROMISC) 2384 if (dev->flags & IFF_PROMISC)
2468 mode |= XM_MD_ENA_PROM; 2385 mode |= XM_MD_ENA_PROM;
@@ -2473,17 +2390,16 @@ static void genesis_set_multicast(struct net_device *dev)
2473 memset(filter, 0xff, sizeof(filter)); 2390 memset(filter, 0xff, sizeof(filter));
2474 else { 2391 else {
2475 memset(filter, 0, sizeof(filter)); 2392 memset(filter, 0, sizeof(filter));
2476 for(i = 0; list && i < count; i++, list = list->next) { 2393 for (i = 0; list && i < count; i++, list = list->next) {
2477 u32 crc = crc32_le(~0, list->dmi_addr, ETH_ALEN); 2394 u32 crc, bit;
2478 u8 bit = 63 - (crc & 63); 2395 crc = ether_crc_le(ETH_ALEN, list->dmi_addr);
2479 2396 bit = ~crc & 0x3f;
2480 filter[bit/8] |= 1 << (bit%8); 2397 filter[bit/8] |= 1 << (bit%8);
2481 } 2398 }
2482 } 2399 }
2483 2400
2484 skge_xm_outhash(hw, port, XM_HSM, filter); 2401 xm_write32(hw, port, XM_MODE, mode);
2485 2402 xm_outhash(hw, port, XM_HSM, filter);
2486 skge_xm_write32(hw, port, XM_MODE, mode);
2487} 2403}
2488 2404
2489static void yukon_set_multicast(struct net_device *dev) 2405static void yukon_set_multicast(struct net_device *dev)
@@ -2497,7 +2413,7 @@ static void yukon_set_multicast(struct net_device *dev)
2497 2413
2498 memset(filter, 0, sizeof(filter)); 2414 memset(filter, 0, sizeof(filter));
2499 2415
2500 reg = skge_gma_read16(hw, port, GM_RX_CTRL); 2416 reg = gma_read16(hw, port, GM_RX_CTRL);
2501 reg |= GM_RXCR_UCF_ENA; 2417 reg |= GM_RXCR_UCF_ENA;
2502 2418
2503 if (dev->flags & IFF_PROMISC) /* promiscious */ 2419 if (dev->flags & IFF_PROMISC) /* promiscious */
@@ -2510,23 +2426,23 @@ static void yukon_set_multicast(struct net_device *dev)
2510 int i; 2426 int i;
2511 reg |= GM_RXCR_MCF_ENA; 2427 reg |= GM_RXCR_MCF_ENA;
2512 2428
2513 for(i = 0; list && i < dev->mc_count; i++, list = list->next) { 2429 for (i = 0; list && i < dev->mc_count; i++, list = list->next) {
2514 u32 bit = ether_crc(ETH_ALEN, list->dmi_addr) & 0x3f; 2430 u32 bit = ether_crc(ETH_ALEN, list->dmi_addr) & 0x3f;
2515 filter[bit/8] |= 1 << (bit%8); 2431 filter[bit/8] |= 1 << (bit%8);
2516 } 2432 }
2517 } 2433 }
2518 2434
2519 2435
2520 skge_gma_write16(hw, port, GM_MC_ADDR_H1, 2436 gma_write16(hw, port, GM_MC_ADDR_H1,
2521 (u16)filter[0] | ((u16)filter[1] << 8)); 2437 (u16)filter[0] | ((u16)filter[1] << 8));
2522 skge_gma_write16(hw, port, GM_MC_ADDR_H2, 2438 gma_write16(hw, port, GM_MC_ADDR_H2,
2523 (u16)filter[2] | ((u16)filter[3] << 8)); 2439 (u16)filter[2] | ((u16)filter[3] << 8));
2524 skge_gma_write16(hw, port, GM_MC_ADDR_H3, 2440 gma_write16(hw, port, GM_MC_ADDR_H3,
2525 (u16)filter[4] | ((u16)filter[5] << 8)); 2441 (u16)filter[4] | ((u16)filter[5] << 8));
2526 skge_gma_write16(hw, port, GM_MC_ADDR_H4, 2442 gma_write16(hw, port, GM_MC_ADDR_H4,
2527 (u16)filter[6] | ((u16)filter[7] << 8)); 2443 (u16)filter[6] | ((u16)filter[7] << 8));
2528 2444
2529 skge_gma_write16(hw, port, GM_RX_CTRL, reg); 2445 gma_write16(hw, port, GM_RX_CTRL, reg);
2530} 2446}
2531 2447
2532static inline int bad_phy_status(const struct skge_hw *hw, u32 status) 2448static inline int bad_phy_status(const struct skge_hw *hw, u32 status)
@@ -2545,28 +2461,76 @@ static void skge_rx_error(struct skge_port *skge, int slot,
2545 printk(KERN_DEBUG PFX "%s: rx err, slot %d control 0x%x status 0x%x\n", 2461 printk(KERN_DEBUG PFX "%s: rx err, slot %d control 0x%x status 0x%x\n",
2546 skge->netdev->name, slot, control, status); 2462 skge->netdev->name, slot, control, status);
2547 2463
2548 if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF) 2464 if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF))
2549 || (control & BMU_BBC) > skge->netdev->mtu + VLAN_ETH_HLEN)
2550 skge->net_stats.rx_length_errors++; 2465 skge->net_stats.rx_length_errors++;
2551 else { 2466 else if (skge->hw->chip_id == CHIP_ID_GENESIS) {
2552 if (skge->hw->chip_id == CHIP_ID_GENESIS) { 2467 if (status & (XMR_FS_RUNT|XMR_FS_LNG_ERR))
2553 if (status & (XMR_FS_RUNT|XMR_FS_LNG_ERR)) 2468 skge->net_stats.rx_length_errors++;
2554 skge->net_stats.rx_length_errors++; 2469 if (status & XMR_FS_FRA_ERR)
2555 if (status & XMR_FS_FRA_ERR) 2470 skge->net_stats.rx_frame_errors++;
2556 skge->net_stats.rx_frame_errors++; 2471 if (status & XMR_FS_FCS_ERR)
2557 if (status & XMR_FS_FCS_ERR) 2472 skge->net_stats.rx_crc_errors++;
2558 skge->net_stats.rx_crc_errors++; 2473 } else {
2559 } else { 2474 if (status & (GMR_FS_LONG_ERR|GMR_FS_UN_SIZE))
2560 if (status & (GMR_FS_LONG_ERR|GMR_FS_UN_SIZE)) 2475 skge->net_stats.rx_length_errors++;
2561 skge->net_stats.rx_length_errors++; 2476 if (status & GMR_FS_FRAGMENT)
2562 if (status & GMR_FS_FRAGMENT) 2477 skge->net_stats.rx_frame_errors++;
2563 skge->net_stats.rx_frame_errors++; 2478 if (status & GMR_FS_CRC_ERR)
2564 if (status & GMR_FS_CRC_ERR) 2479 skge->net_stats.rx_crc_errors++;
2565 skge->net_stats.rx_crc_errors++; 2480 }
2481}
2482
2483/* Get receive buffer from descriptor.
2484 * Handles copy of small buffers and reallocation failures
2485 */
2486static inline struct sk_buff *skge_rx_get(struct skge_port *skge,
2487 struct skge_element *e,
2488 unsigned int len)
2489{
2490 struct sk_buff *nskb, *skb;
2491
2492 if (len < RX_COPY_THRESHOLD) {
2493 nskb = skge_rx_alloc(skge->netdev, len + NET_IP_ALIGN);
2494 if (unlikely(!nskb))
2495 return NULL;
2496
2497 pci_dma_sync_single_for_cpu(skge->hw->pdev,
2498 pci_unmap_addr(e, mapaddr),
2499 len, PCI_DMA_FROMDEVICE);
2500 memcpy(nskb->data, e->skb->data, len);
2501 pci_dma_sync_single_for_device(skge->hw->pdev,
2502 pci_unmap_addr(e, mapaddr),
2503 len, PCI_DMA_FROMDEVICE);
2504
2505 if (skge->rx_csum) {
2506 struct skge_rx_desc *rd = e->desc;
2507 nskb->csum = le16_to_cpu(rd->csum2);
2508 nskb->ip_summed = CHECKSUM_HW;
2566 } 2509 }
2510 skge_rx_reuse(e, skge->rx_buf_size);
2511 return nskb;
2512 } else {
2513 nskb = skge_rx_alloc(skge->netdev, skge->rx_buf_size);
2514 if (unlikely(!nskb))
2515 return NULL;
2516
2517 pci_unmap_single(skge->hw->pdev,
2518 pci_unmap_addr(e, mapaddr),
2519 pci_unmap_len(e, maplen),
2520 PCI_DMA_FROMDEVICE);
2521 skb = e->skb;
2522 if (skge->rx_csum) {
2523 struct skge_rx_desc *rd = e->desc;
2524 skb->csum = le16_to_cpu(rd->csum2);
2525 skb->ip_summed = CHECKSUM_HW;
2526 }
2527
2528 skge_rx_setup(skge, e, nskb, skge->rx_buf_size);
2529 return skb;
2567 } 2530 }
2568} 2531}
2569 2532
2533
2570static int skge_poll(struct net_device *dev, int *budget) 2534static int skge_poll(struct net_device *dev, int *budget)
2571{ 2535{
2572 struct skge_port *skge = netdev_priv(dev); 2536 struct skge_port *skge = netdev_priv(dev);
@@ -2575,13 +2539,12 @@ static int skge_poll(struct net_device *dev, int *budget)
2575 struct skge_element *e; 2539 struct skge_element *e;
2576 unsigned int to_do = min(dev->quota, *budget); 2540 unsigned int to_do = min(dev->quota, *budget);
2577 unsigned int work_done = 0; 2541 unsigned int work_done = 0;
2578 int done;
2579 static const u32 irqmask[] = { IS_PORT_1, IS_PORT_2 };
2580 2542
2581 for (e = ring->to_clean; e != ring->to_use && work_done < to_do; 2543 pr_debug("skge_poll\n");
2582 e = e->next) { 2544
2545 for (e = ring->to_clean; work_done < to_do; e = e->next) {
2583 struct skge_rx_desc *rd = e->desc; 2546 struct skge_rx_desc *rd = e->desc;
2584 struct sk_buff *skb = e->skb; 2547 struct sk_buff *skb;
2585 u32 control, len, status; 2548 u32 control, len, status;
2586 2549
2587 rmb(); 2550 rmb();
@@ -2590,19 +2553,12 @@ static int skge_poll(struct net_device *dev, int *budget)
2590 break; 2553 break;
2591 2554
2592 len = control & BMU_BBC; 2555 len = control & BMU_BBC;
2593 e->skb = NULL;
2594
2595 pci_unmap_single(hw->pdev,
2596 pci_unmap_addr(e, mapaddr),
2597 pci_unmap_len(e, maplen),
2598 PCI_DMA_FROMDEVICE);
2599
2600 status = rd->status; 2556 status = rd->status;
2601 if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF) 2557
2602 || len > dev->mtu + VLAN_ETH_HLEN 2558 if (unlikely((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF)
2603 || bad_phy_status(hw, status)) { 2559 || bad_phy_status(hw, status))) {
2604 skge_rx_error(skge, e - ring->start, control, status); 2560 skge_rx_error(skge, e - ring->start, control, status);
2605 dev_kfree_skb(skb); 2561 skge_rx_reuse(e, skge->rx_buf_size);
2606 continue; 2562 continue;
2607 } 2563 }
2608 2564
@@ -2610,43 +2566,37 @@ static int skge_poll(struct net_device *dev, int *budget)
2610 printk(KERN_DEBUG PFX "%s: rx slot %td status 0x%x len %d\n", 2566 printk(KERN_DEBUG PFX "%s: rx slot %td status 0x%x len %d\n",
2611 dev->name, e - ring->start, rd->status, len); 2567 dev->name, e - ring->start, rd->status, len);
2612 2568
2613 skb_put(skb, len); 2569 skb = skge_rx_get(skge, e, len);
2614 skb->protocol = eth_type_trans(skb, dev); 2570 if (likely(skb)) {
2615 2571 skb_put(skb, len);
2616 if (skge->rx_csum) { 2572 skb->protocol = eth_type_trans(skb, dev);
2617 skb->csum = le16_to_cpu(rd->csum2);
2618 skb->ip_summed = CHECKSUM_HW;
2619 }
2620 2573
2621 dev->last_rx = jiffies; 2574 dev->last_rx = jiffies;
2622 netif_receive_skb(skb); 2575 netif_receive_skb(skb);
2623 2576
2624 ++work_done; 2577 ++work_done;
2578 } else
2579 skge_rx_reuse(e, skge->rx_buf_size);
2625 } 2580 }
2626 ring->to_clean = e; 2581 ring->to_clean = e;
2627 2582
2628 *budget -= work_done;
2629 dev->quota -= work_done;
2630 done = work_done < to_do;
2631
2632 if (skge_rx_fill(skge))
2633 done = 0;
2634
2635 /* restart receiver */ 2583 /* restart receiver */
2636 wmb(); 2584 wmb();
2637 skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), 2585 skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR),
2638 CSR_START | CSR_IRQ_CL_F); 2586 CSR_START | CSR_IRQ_CL_F);
2639 2587
2640 if (done) { 2588 *budget -= work_done;
2641 local_irq_disable(); 2589 dev->quota -= work_done;
2642 hw->intr_mask |= irqmask[skge->port];
2643 /* Order is important since data can get interrupted */
2644 skge_write32(hw, B0_IMSK, hw->intr_mask);
2645 __netif_rx_complete(dev);
2646 local_irq_enable();
2647 }
2648 2590
2649 return !done; 2591 if (work_done >= to_do)
2592 return 1; /* not done */
2593
2594 local_irq_disable();
2595 __netif_rx_complete(dev);
2596 hw->intr_mask |= portirqmask[skge->port];
2597 skge_write32(hw, B0_IMSK, hw->intr_mask);
2598 local_irq_enable();
2599 return 0;
2650} 2600}
2651 2601
2652static inline void skge_tx_intr(struct net_device *dev) 2602static inline void skge_tx_intr(struct net_device *dev)
@@ -2657,7 +2607,7 @@ static inline void skge_tx_intr(struct net_device *dev)
2657 struct skge_element *e; 2607 struct skge_element *e;
2658 2608
2659 spin_lock(&skge->tx_lock); 2609 spin_lock(&skge->tx_lock);
2660 for(e = ring->to_clean; e != ring->to_use; e = e->next) { 2610 for (e = ring->to_clean; e != ring->to_use; e = e->next) {
2661 struct skge_tx_desc *td = e->desc; 2611 struct skge_tx_desc *td = e->desc;
2662 u32 control; 2612 u32 control;
2663 2613
@@ -2690,12 +2640,12 @@ static void skge_mac_parity(struct skge_hw *hw, int port)
2690 : (port == 0 ? "(port A)": "(port B")); 2640 : (port == 0 ? "(port A)": "(port B"));
2691 2641
2692 if (hw->chip_id == CHIP_ID_GENESIS) 2642 if (hw->chip_id == CHIP_ID_GENESIS)
2693 skge_write16(hw, SKGEMAC_REG(port, TX_MFF_CTRL1), 2643 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1),
2694 MFF_CLR_PERR); 2644 MFF_CLR_PERR);
2695 else 2645 else
2696 /* HW-Bug #8: cleared by GMF_CLI_TX_FC instead of GMF_CLI_TX_PE */ 2646 /* HW-Bug #8: cleared by GMF_CLI_TX_FC instead of GMF_CLI_TX_PE */
2697 skge_write8(hw, SKGEMAC_REG(port, TX_GMF_CTRL_T), 2647 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T),
2698 (hw->chip_id == CHIP_ID_YUKON && chip_rev(hw) == 0) 2648 (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)
2699 ? GMF_CLI_TX_FC : GMF_CLI_TX_PE); 2649 ? GMF_CLI_TX_FC : GMF_CLI_TX_PE);
2700} 2650}
2701 2651
@@ -2703,16 +2653,16 @@ static void skge_pci_clear(struct skge_hw *hw)
2703{ 2653{
2704 u16 status; 2654 u16 status;
2705 2655
2706 status = skge_read16(hw, SKGEPCI_REG(PCI_STATUS)); 2656 pci_read_config_word(hw->pdev, PCI_STATUS, &status);
2707 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 2657 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
2708 skge_write16(hw, SKGEPCI_REG(PCI_STATUS), 2658 pci_write_config_word(hw->pdev, PCI_STATUS,
2709 status | PCI_STATUS_ERROR_BITS); 2659 status | PCI_STATUS_ERROR_BITS);
2710 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 2660 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
2711} 2661}
2712 2662
2713static void skge_mac_intr(struct skge_hw *hw, int port) 2663static void skge_mac_intr(struct skge_hw *hw, int port)
2714{ 2664{
2715 if (hw->chip_id == CHIP_ID_GENESIS) 2665 if (hw->chip_id == CHIP_ID_GENESIS)
2716 genesis_mac_intr(hw, port); 2666 genesis_mac_intr(hw, port);
2717 else 2667 else
2718 yukon_mac_intr(hw, port); 2668 yukon_mac_intr(hw, port);
@@ -2726,9 +2676,9 @@ static void skge_error_irq(struct skge_hw *hw)
2726 if (hw->chip_id == CHIP_ID_GENESIS) { 2676 if (hw->chip_id == CHIP_ID_GENESIS) {
2727 /* clear xmac errors */ 2677 /* clear xmac errors */
2728 if (hwstatus & (IS_NO_STAT_M1|IS_NO_TIST_M1)) 2678 if (hwstatus & (IS_NO_STAT_M1|IS_NO_TIST_M1))
2729 skge_write16(hw, SKGEMAC_REG(0, RX_MFF_CTRL1), MFF_CLR_INSTAT); 2679 skge_write16(hw, SK_REG(0, RX_MFF_CTRL1), MFF_CLR_INSTAT);
2730 if (hwstatus & (IS_NO_STAT_M2|IS_NO_TIST_M2)) 2680 if (hwstatus & (IS_NO_STAT_M2|IS_NO_TIST_M2))
2731 skge_write16(hw, SKGEMAC_REG(0, RX_MFF_CTRL2), MFF_CLR_INSTAT); 2681 skge_write16(hw, SK_REG(0, RX_MFF_CTRL2), MFF_CLR_INSTAT);
2732 } else { 2682 } else {
2733 /* Timestamp (unused) overflow */ 2683 /* Timestamp (unused) overflow */
2734 if (hwstatus & IS_IRQ_TIST_OV) 2684 if (hwstatus & IS_IRQ_TIST_OV)
@@ -2803,8 +2753,8 @@ static void skge_extirq(unsigned long data)
2803 2753
2804 if (hw->chip_id != CHIP_ID_GENESIS) 2754 if (hw->chip_id != CHIP_ID_GENESIS)
2805 yukon_phy_intr(skge); 2755 yukon_phy_intr(skge);
2806 else if (hw->phy_type == SK_PHY_BCOM) 2756 else
2807 genesis_bcom_intr(skge); 2757 bcom_phy_intr(skge);
2808 } 2758 }
2809 } 2759 }
2810 spin_unlock(&hw->phy_lock); 2760 spin_unlock(&hw->phy_lock);
@@ -2824,19 +2774,14 @@ static irqreturn_t skge_intr(int irq, void *dev_id, struct pt_regs *regs)
2824 return IRQ_NONE; 2774 return IRQ_NONE;
2825 2775
2826 status &= hw->intr_mask; 2776 status &= hw->intr_mask;
2827 2777 if (status & IS_R1_F) {
2828 if ((status & IS_R1_F) && netif_rx_schedule_prep(hw->dev[0])) {
2829 status &= ~IS_R1_F;
2830 hw->intr_mask &= ~IS_R1_F; 2778 hw->intr_mask &= ~IS_R1_F;
2831 skge_write32(hw, B0_IMSK, hw->intr_mask); 2779 netif_rx_schedule(hw->dev[0]);
2832 __netif_rx_schedule(hw->dev[0]);
2833 } 2780 }
2834 2781
2835 if ((status & IS_R2_F) && netif_rx_schedule_prep(hw->dev[1])) { 2782 if (status & IS_R2_F) {
2836 status &= ~IS_R2_F;
2837 hw->intr_mask &= ~IS_R2_F; 2783 hw->intr_mask &= ~IS_R2_F;
2838 skge_write32(hw, B0_IMSK, hw->intr_mask); 2784 netif_rx_schedule(hw->dev[1]);
2839 __netif_rx_schedule(hw->dev[1]);
2840 } 2785 }
2841 2786
2842 if (status & IS_XA1_F) 2787 if (status & IS_XA1_F)
@@ -2845,9 +2790,27 @@ static irqreturn_t skge_intr(int irq, void *dev_id, struct pt_regs *regs)
2845 if (status & IS_XA2_F) 2790 if (status & IS_XA2_F)
2846 skge_tx_intr(hw->dev[1]); 2791 skge_tx_intr(hw->dev[1]);
2847 2792
2793 if (status & IS_PA_TO_RX1) {
2794 struct skge_port *skge = netdev_priv(hw->dev[0]);
2795 ++skge->net_stats.rx_over_errors;
2796 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX1);
2797 }
2798
2799 if (status & IS_PA_TO_RX2) {
2800 struct skge_port *skge = netdev_priv(hw->dev[1]);
2801 ++skge->net_stats.rx_over_errors;
2802 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX2);
2803 }
2804
2805 if (status & IS_PA_TO_TX1)
2806 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX1);
2807
2808 if (status & IS_PA_TO_TX2)
2809 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX2);
2810
2848 if (status & IS_MAC1) 2811 if (status & IS_MAC1)
2849 skge_mac_intr(hw, 0); 2812 skge_mac_intr(hw, 0);
2850 2813
2851 if (status & IS_MAC2) 2814 if (status & IS_MAC2)
2852 skge_mac_intr(hw, 1); 2815 skge_mac_intr(hw, 1);
2853 2816
@@ -2859,8 +2822,7 @@ static irqreturn_t skge_intr(int irq, void *dev_id, struct pt_regs *regs)
2859 tasklet_schedule(&hw->ext_tasklet); 2822 tasklet_schedule(&hw->ext_tasklet);
2860 } 2823 }
2861 2824
2862 if (status) 2825 skge_write32(hw, B0_IMSK, hw->intr_mask);
2863 skge_write32(hw, B0_IMSK, hw->intr_mask);
2864 2826
2865 return IRQ_HANDLED; 2827 return IRQ_HANDLED;
2866} 2828}
@@ -2904,9 +2866,6 @@ static const struct {
2904 { CHIP_ID_YUKON, "Yukon" }, 2866 { CHIP_ID_YUKON, "Yukon" },
2905 { CHIP_ID_YUKON_LITE, "Yukon-Lite"}, 2867 { CHIP_ID_YUKON_LITE, "Yukon-Lite"},
2906 { CHIP_ID_YUKON_LP, "Yukon-LP"}, 2868 { CHIP_ID_YUKON_LP, "Yukon-LP"},
2907 { CHIP_ID_YUKON_XL, "Yukon-2 XL"},
2908 { CHIP_ID_YUKON_EC, "YUKON-2 EC"},
2909 { CHIP_ID_YUKON_FE, "YUKON-2 FE"},
2910}; 2869};
2911 2870
2912static const char *skge_board_name(const struct skge_hw *hw) 2871static const char *skge_board_name(const struct skge_hw *hw)
@@ -2930,8 +2889,8 @@ static const char *skge_board_name(const struct skge_hw *hw)
2930static int skge_reset(struct skge_hw *hw) 2889static int skge_reset(struct skge_hw *hw)
2931{ 2890{
2932 u16 ctst; 2891 u16 ctst;
2933 u8 t8; 2892 u8 t8, mac_cfg;
2934 int i, ports; 2893 int i;
2935 2894
2936 ctst = skge_read16(hw, B0_CTST); 2895 ctst = skge_read16(hw, B0_CTST);
2937 2896
@@ -2952,12 +2911,9 @@ static int skge_reset(struct skge_hw *hw)
2952 hw->phy_type = skge_read8(hw, B2_E_1) & 0xf; 2911 hw->phy_type = skge_read8(hw, B2_E_1) & 0xf;
2953 hw->pmd_type = skge_read8(hw, B2_PMD_TYP); 2912 hw->pmd_type = skge_read8(hw, B2_PMD_TYP);
2954 2913
2955 switch(hw->chip_id) { 2914 switch (hw->chip_id) {
2956 case CHIP_ID_GENESIS: 2915 case CHIP_ID_GENESIS:
2957 switch (hw->phy_type) { 2916 switch (hw->phy_type) {
2958 case SK_PHY_XMAC:
2959 hw->phy_addr = PHY_ADDR_XMAC;
2960 break;
2961 case SK_PHY_BCOM: 2917 case SK_PHY_BCOM:
2962 hw->phy_addr = PHY_ADDR_BCOM; 2918 hw->phy_addr = PHY_ADDR_BCOM;
2963 break; 2919 break;
@@ -2986,8 +2942,9 @@ static int skge_reset(struct skge_hw *hw)
2986 return -EOPNOTSUPP; 2942 return -EOPNOTSUPP;
2987 } 2943 }
2988 2944
2989 hw->mac_cfg = skge_read8(hw, B2_MAC_CFG); 2945 mac_cfg = skge_read8(hw, B2_MAC_CFG);
2990 ports = isdualport(hw) ? 2 : 1; 2946 hw->ports = (mac_cfg & CFG_SNG_MAC) ? 1 : 2;
2947 hw->chip_rev = (mac_cfg & CFG_CHIP_R_MSK) >> 4;
2991 2948
2992 /* read the adapters RAM size */ 2949 /* read the adapters RAM size */
2993 t8 = skge_read8(hw, B2_E_0); 2950 t8 = skge_read8(hw, B2_E_0);
@@ -3010,9 +2967,9 @@ static int skge_reset(struct skge_hw *hw)
3010 /* switch power to VCC (WA for VAUX problem) */ 2967 /* switch power to VCC (WA for VAUX problem) */
3011 skge_write8(hw, B0_POWER_CTRL, 2968 skge_write8(hw, B0_POWER_CTRL,
3012 PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON); 2969 PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
3013 for (i = 0; i < ports; i++) { 2970 for (i = 0; i < hw->ports; i++) {
3014 skge_write16(hw, SKGEMAC_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET); 2971 skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
3015 skge_write16(hw, SKGEMAC_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR); 2972 skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
3016 } 2973 }
3017 } 2974 }
3018 2975
@@ -3022,8 +2979,8 @@ static int skge_reset(struct skge_hw *hw)
3022 skge_write8(hw, B0_LED, LED_STAT_ON); 2979 skge_write8(hw, B0_LED, LED_STAT_ON);
3023 2980
3024 /* enable the Tx Arbiters */ 2981 /* enable the Tx Arbiters */
3025 for (i = 0; i < ports; i++) 2982 for (i = 0; i < hw->ports; i++)
3026 skge_write8(hw, SKGEMAC_REG(i, TXA_CTRL), TXA_ENA_ARB); 2983 skge_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB);
3027 2984
3028 /* Initialize ram interface */ 2985 /* Initialize ram interface */
3029 skge_write16(hw, B3_RI_CTRL, RI_RST_CLR); 2986 skge_write16(hw, B3_RI_CTRL, RI_RST_CLR);
@@ -3050,16 +3007,14 @@ static int skge_reset(struct skge_hw *hw)
3050 skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, 100)); 3007 skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, 100));
3051 skge_write32(hw, B2_IRQM_CTRL, TIM_START); 3008 skge_write32(hw, B2_IRQM_CTRL, TIM_START);
3052 3009
3053 hw->intr_mask = IS_HW_ERR | IS_EXT_REG | IS_PORT_1; 3010 hw->intr_mask = IS_HW_ERR | IS_EXT_REG;
3054 if (isdualport(hw))
3055 hw->intr_mask |= IS_PORT_2;
3056 skge_write32(hw, B0_IMSK, hw->intr_mask); 3011 skge_write32(hw, B0_IMSK, hw->intr_mask);
3057 3012
3058 if (hw->chip_id != CHIP_ID_GENESIS) 3013 if (hw->chip_id != CHIP_ID_GENESIS)
3059 skge_write8(hw, GMAC_IRQ_MSK, 0); 3014 skge_write8(hw, GMAC_IRQ_MSK, 0);
3060 3015
3061 spin_lock_bh(&hw->phy_lock); 3016 spin_lock_bh(&hw->phy_lock);
3062 for (i = 0; i < ports; i++) { 3017 for (i = 0; i < hw->ports; i++) {
3063 if (hw->chip_id == CHIP_ID_GENESIS) 3018 if (hw->chip_id == CHIP_ID_GENESIS)
3064 genesis_reset(hw, i); 3019 genesis_reset(hw, i);
3065 else 3020 else
@@ -3071,7 +3026,8 @@ static int skge_reset(struct skge_hw *hw)
3071} 3026}
3072 3027
3073/* Initialize network device */ 3028/* Initialize network device */
3074static struct net_device *skge_devinit(struct skge_hw *hw, int port) 3029static struct net_device *skge_devinit(struct skge_hw *hw, int port,
3030 int highmem)
3075{ 3031{
3076 struct skge_port *skge; 3032 struct skge_port *skge;
3077 struct net_device *dev = alloc_etherdev(sizeof(*skge)); 3033 struct net_device *dev = alloc_etherdev(sizeof(*skge));
@@ -3104,6 +3060,8 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port)
3104#endif 3060#endif
3105 dev->irq = hw->pdev->irq; 3061 dev->irq = hw->pdev->irq;
3106 dev->features = NETIF_F_LLTX; 3062 dev->features = NETIF_F_LLTX;
3063 if (highmem)
3064 dev->features |= NETIF_F_HIGHDMA;
3107 3065
3108 skge = netdev_priv(dev); 3066 skge = netdev_priv(dev);
3109 skge->netdev = dev; 3067 skge->netdev = dev;
@@ -3117,7 +3075,7 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port)
3117 skge->flow_control = FLOW_MODE_SYMMETRIC; 3075 skge->flow_control = FLOW_MODE_SYMMETRIC;
3118 skge->duplex = -1; 3076 skge->duplex = -1;
3119 skge->speed = -1; 3077 skge->speed = -1;
3120 skge->advertising = skge_modes(hw); 3078 skge->advertising = skge_supported_modes(hw);
3121 3079
3122 hw->dev[port] = dev; 3080 hw->dev[port] = dev;
3123 3081
@@ -3125,10 +3083,6 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port)
3125 3083
3126 spin_lock_init(&skge->tx_lock); 3084 spin_lock_init(&skge->tx_lock);
3127 3085
3128 init_timer(&skge->link_check);
3129 skge->link_check.function = skge_link_timer;
3130 skge->link_check.data = (unsigned long) skge;
3131
3132 init_timer(&skge->led_blink); 3086 init_timer(&skge->led_blink);
3133 skge->led_blink.function = skge_blink_timer; 3087 skge->led_blink.function = skge_blink_timer;
3134 skge->led_blink.data = (unsigned long) skge; 3088 skge->led_blink.data = (unsigned long) skge;
@@ -3232,14 +3186,11 @@ static int __devinit skge_probe(struct pci_dev *pdev,
3232 3186
3233 printk(KERN_INFO PFX "addr 0x%lx irq %d chip %s rev %d\n", 3187 printk(KERN_INFO PFX "addr 0x%lx irq %d chip %s rev %d\n",
3234 pci_resource_start(pdev, 0), pdev->irq, 3188 pci_resource_start(pdev, 0), pdev->irq,
3235 skge_board_name(hw), chip_rev(hw)); 3189 skge_board_name(hw), hw->chip_rev);
3236 3190
3237 if ((dev = skge_devinit(hw, 0)) == NULL) 3191 if ((dev = skge_devinit(hw, 0, using_dac)) == NULL)
3238 goto err_out_led_off; 3192 goto err_out_led_off;
3239 3193
3240 if (using_dac)
3241 dev->features |= NETIF_F_HIGHDMA;
3242
3243 if ((err = register_netdev(dev))) { 3194 if ((err = register_netdev(dev))) {
3244 printk(KERN_ERR PFX "%s: cannot register net device\n", 3195 printk(KERN_ERR PFX "%s: cannot register net device\n",
3245 pci_name(pdev)); 3196 pci_name(pdev));
@@ -3248,10 +3199,7 @@ static int __devinit skge_probe(struct pci_dev *pdev,
3248 3199
3249 skge_show_addr(dev); 3200 skge_show_addr(dev);
3250 3201
3251 if (isdualport(hw) && (dev1 = skge_devinit(hw, 1))) { 3202 if (hw->ports > 1 && (dev1 = skge_devinit(hw, 1, using_dac))) {
3252 if (using_dac)
3253 dev1->features |= NETIF_F_HIGHDMA;
3254
3255 if (register_netdev(dev1) == 0) 3203 if (register_netdev(dev1) == 0)
3256 skge_show_addr(dev1); 3204 skge_show_addr(dev1);
3257 else { 3205 else {
@@ -3288,7 +3236,7 @@ static void __devexit skge_remove(struct pci_dev *pdev)
3288 struct skge_hw *hw = pci_get_drvdata(pdev); 3236 struct skge_hw *hw = pci_get_drvdata(pdev);
3289 struct net_device *dev0, *dev1; 3237 struct net_device *dev0, *dev1;
3290 3238
3291 if(!hw) 3239 if (!hw)
3292 return; 3240 return;
3293 3241
3294 if ((dev1 = hw->dev[1])) 3242 if ((dev1 = hw->dev[1]))
@@ -3316,7 +3264,7 @@ static int skge_suspend(struct pci_dev *pdev, u32 state)
3316 struct skge_hw *hw = pci_get_drvdata(pdev); 3264 struct skge_hw *hw = pci_get_drvdata(pdev);
3317 int i, wol = 0; 3265 int i, wol = 0;
3318 3266
3319 for(i = 0; i < 2; i++) { 3267 for (i = 0; i < 2; i++) {
3320 struct net_device *dev = hw->dev[i]; 3268 struct net_device *dev = hw->dev[i];
3321 3269
3322 if (dev) { 3270 if (dev) {
@@ -3349,11 +3297,11 @@ static int skge_resume(struct pci_dev *pdev)
3349 3297
3350 skge_reset(hw); 3298 skge_reset(hw);
3351 3299
3352 for(i = 0; i < 2; i++) { 3300 for (i = 0; i < 2; i++) {
3353 struct net_device *dev = hw->dev[i]; 3301 struct net_device *dev = hw->dev[i];
3354 if (dev) { 3302 if (dev) {
3355 netif_device_attach(dev); 3303 netif_device_attach(dev);
3356 if(netif_running(dev)) 3304 if (netif_running(dev))
3357 skge_up(dev); 3305 skge_up(dev);
3358 } 3306 }
3359 } 3307 }
diff --git a/drivers/net/skge.h b/drivers/net/skge.h
index 36c62b68fab4..14d0cc01fb9a 100644
--- a/drivers/net/skge.h
+++ b/drivers/net/skge.h
@@ -7,31 +7,6 @@
7/* PCI config registers */ 7/* PCI config registers */
8#define PCI_DEV_REG1 0x40 8#define PCI_DEV_REG1 0x40
9#define PCI_DEV_REG2 0x44 9#define PCI_DEV_REG2 0x44
10#ifndef PCI_VPD
11#define PCI_VPD 0x50
12#endif
13
14/* PCI_OUR_REG_2 32 bit Our Register 2 */
15enum {
16 PCI_VPD_WR_THR = 0xff<<24, /* Bit 31..24: VPD Write Threshold */
17 PCI_DEV_SEL = 0x7f<<17, /* Bit 23..17: EEPROM Device Select */
18 PCI_VPD_ROM_SZ = 7 <<14, /* Bit 16..14: VPD ROM Size */
19 /* Bit 13..12: reserved */
20 PCI_EN_DUMMY_RD = 1<<3, /* Enable Dummy Read */
21 PCI_REV_DESC = 1<<2, /* Reverse Desc. Bytes */
22 PCI_USEDATA64 = 1<<0, /* Use 64Bit Data bus ext */
23};
24
25/* PCI_VPD_ADR_REG 16 bit VPD Address Register */
26enum {
27 PCI_VPD_FLAG = 1<<15, /* starts VPD rd/wr cycle */
28 PCI_VPD_ADR_MSK =0x7fffL, /* Bit 14.. 0: VPD Address Mask */
29 VPD_RES_ID = 0x82,
30 VPD_RES_READ = 0x90,
31 VPD_RES_WRITE = 0x81,
32 VPD_RES_END = 0x78,
33};
34
35 10
36#define PCI_STATUS_ERROR_BITS (PCI_STATUS_DETECTED_PARITY | \ 11#define PCI_STATUS_ERROR_BITS (PCI_STATUS_DETECTED_PARITY | \
37 PCI_STATUS_SIG_SYSTEM_ERROR | \ 12 PCI_STATUS_SIG_SYSTEM_ERROR | \
@@ -39,7 +14,6 @@ enum {
39 PCI_STATUS_REC_TARGET_ABORT | \ 14 PCI_STATUS_REC_TARGET_ABORT | \
40 PCI_STATUS_PARITY) 15 PCI_STATUS_PARITY)
41 16
42
43enum csr_regs { 17enum csr_regs {
44 B0_RAP = 0x0000, 18 B0_RAP = 0x0000,
45 B0_CTST = 0x0004, 19 B0_CTST = 0x0004,
@@ -229,8 +203,11 @@ enum {
229 IS_XA2_F = 1<<1, /* Q_XA2 End of Frame */ 203 IS_XA2_F = 1<<1, /* Q_XA2 End of Frame */
230 IS_XA2_C = 1<<0, /* Q_XA2 Encoding Error */ 204 IS_XA2_C = 1<<0, /* Q_XA2 Encoding Error */
231 205
232 IS_PORT_1 = IS_XA1_F| IS_R1_F| IS_MAC1, 206 IS_TO_PORT1 = IS_PA_TO_RX1 | IS_PA_TO_TX1,
233 IS_PORT_2 = IS_XA2_F| IS_R2_F| IS_MAC2, 207 IS_TO_PORT2 = IS_PA_TO_RX2 | IS_PA_TO_TX2,
208
209 IS_PORT_1 = IS_XA1_F| IS_R1_F | IS_TO_PORT1 | IS_MAC1,
210 IS_PORT_2 = IS_XA2_F| IS_R2_F | IS_TO_PORT2 | IS_MAC2,
234}; 211};
235 212
236 213
@@ -288,14 +265,6 @@ enum {
288 CHIP_REV_YU_LITE_A3 = 7, /* Chip Rev. for YUKON-Lite A3 */ 265 CHIP_REV_YU_LITE_A3 = 7, /* Chip Rev. for YUKON-Lite A3 */
289}; 266};
290 267
291/* B2_LD_TEST 8 bit EPROM loader test register */
292enum {
293 LD_T_ON = 1<<3, /* Loader Test mode on */
294 LD_T_OFF = 1<<2, /* Loader Test mode off */
295 LD_T_STEP = 1<<1, /* Decrement FPROM addr. Counter */
296 LD_START = 1<<0, /* Start loading FPROM */
297};
298
299/* B2_TI_CTRL 8 bit Timer control */ 268/* B2_TI_CTRL 8 bit Timer control */
300/* B2_IRQM_CTRL 8 bit IRQ Moderation Timer Control */ 269/* B2_IRQM_CTRL 8 bit IRQ Moderation Timer Control */
301enum { 270enum {
@@ -313,16 +282,6 @@ enum {
313 TIM_T_STEP = 1<<0, /* Test step */ 282 TIM_T_STEP = 1<<0, /* Test step */
314}; 283};
315 284
316/* B28_DPT_INI 32 bit Descriptor Poll Timer Init Val */
317/* B28_DPT_VAL 32 bit Descriptor Poll Timer Curr Val */
318/* B28_DPT_CTRL 8 bit Descriptor Poll Timer Ctrl Reg */
319enum {
320 DPT_MSK = 0x00ffffffL, /* Bit 23.. 0: Desc Poll Timer Bits */
321
322 DPT_START = 1<<1, /* Start Descriptor Poll Timer */
323 DPT_STOP = 1<<0, /* Stop Descriptor Poll Timer */
324};
325
326/* B2_GP_IO 32 bit General Purpose I/O Register */ 285/* B2_GP_IO 32 bit General Purpose I/O Register */
327enum { 286enum {
328 GP_DIR_9 = 1<<25, /* IO_9 direct, 0=In/1=Out */ 287 GP_DIR_9 = 1<<25, /* IO_9 direct, 0=In/1=Out */
@@ -348,30 +307,6 @@ enum {
348 GP_IO_0 = 1<<0, /* IO_0 pin */ 307 GP_IO_0 = 1<<0, /* IO_0 pin */
349}; 308};
350 309
351/* Rx/Tx Path related Arbiter Test Registers */
352/* B3_MA_TO_TEST 16 bit MAC Arbiter Timeout Test Reg */
353/* B3_MA_RC_TEST 16 bit MAC Arbiter Recovery Test Reg */
354/* B3_PA_TEST 16 bit Packet Arbiter Test Register */
355/* Bit 15, 11, 7, and 3 are reserved in B3_PA_TEST */
356enum {
357 TX2_T_EV = 1<<15,/* TX2 Timeout/Recv Event occured */
358 TX2_T_ON = 1<<14,/* TX2 Timeout/Recv Timer Test On */
359 TX2_T_OFF = 1<<13,/* TX2 Timeout/Recv Timer Tst Off */
360 TX2_T_STEP = 1<<12,/* TX2 Timeout/Recv Timer Step */
361 TX1_T_EV = 1<<11,/* TX1 Timeout/Recv Event occured */
362 TX1_T_ON = 1<<10,/* TX1 Timeout/Recv Timer Test On */
363 TX1_T_OFF = 1<<9, /* TX1 Timeout/Recv Timer Tst Off */
364 TX1_T_STEP = 1<<8, /* TX1 Timeout/Recv Timer Step */
365 RX2_T_EV = 1<<7, /* RX2 Timeout/Recv Event occured */
366 RX2_T_ON = 1<<6, /* RX2 Timeout/Recv Timer Test On */
367 RX2_T_OFF = 1<<5, /* RX2 Timeout/Recv Timer Tst Off */
368 RX2_T_STEP = 1<<4, /* RX2 Timeout/Recv Timer Step */
369 RX1_T_EV = 1<<3, /* RX1 Timeout/Recv Event occured */
370 RX1_T_ON = 1<<2, /* RX1 Timeout/Recv Timer Test On */
371 RX1_T_OFF = 1<<1, /* RX1 Timeout/Recv Timer Tst Off */
372 RX1_T_STEP = 1<<0, /* RX1 Timeout/Recv Timer Step */
373};
374
375/* Descriptor Bit Definition */ 310/* Descriptor Bit Definition */
376/* TxCtrl Transmit Buffer Control Field */ 311/* TxCtrl Transmit Buffer Control Field */
377/* RxCtrl Receive Buffer Control Field */ 312/* RxCtrl Receive Buffer Control Field */
@@ -428,14 +363,6 @@ enum {
428 RI_RST_SET = 1<<0, /* Set RAM Interface Reset */ 363 RI_RST_SET = 1<<0, /* Set RAM Interface Reset */
429}; 364};
430 365
431/* B3_RI_TEST 8 bit RAM Iface Test Register */
432enum {
433 RI_T_EV = 1<<3, /* Timeout Event occured */
434 RI_T_ON = 1<<2, /* Timeout Timer Test On */
435 RI_T_OFF = 1<<1, /* Timeout Timer Test Off */
436 RI_T_STEP = 1<<0, /* Timeout Timer Step */
437};
438
439/* MAC Arbiter Registers */ 366/* MAC Arbiter Registers */
440/* B3_MA_TO_CTRL 16 bit MAC Arbiter Timeout Ctrl Reg */ 367/* B3_MA_TO_CTRL 16 bit MAC Arbiter Timeout Ctrl Reg */
441enum { 368enum {
@@ -452,19 +379,6 @@ enum {
452#define SK_PKT_TO_MAX 0xffff /* Maximum value */ 379#define SK_PKT_TO_MAX 0xffff /* Maximum value */
453#define SK_RI_TO_53 36 /* RAM interface timeout */ 380#define SK_RI_TO_53 36 /* RAM interface timeout */
454 381
455
456/* B3_MA_RC_CTRL 16 bit MAC Arbiter Recovery Ctrl Reg */
457enum {
458 MA_ENA_REC_TX2 = 1<<7, /* Enable Recovery Timer TX2 */
459 MA_DIS_REC_TX2 = 1<<6, /* Disable Recovery Timer TX2 */
460 MA_ENA_REC_TX1 = 1<<5, /* Enable Recovery Timer TX1 */
461 MA_DIS_REC_TX1 = 1<<4, /* Disable Recovery Timer TX1 */
462 MA_ENA_REC_RX2 = 1<<3, /* Enable Recovery Timer RX2 */
463 MA_DIS_REC_RX2 = 1<<2, /* Disable Recovery Timer RX2 */
464 MA_ENA_REC_RX1 = 1<<1, /* Enable Recovery Timer RX1 */
465 MA_DIS_REC_RX1 = 1<<0, /* Disable Recovery Timer RX1 */
466};
467
468/* Packet Arbiter Registers */ 382/* Packet Arbiter Registers */
469/* B3_PA_CTRL 16 bit Packet Arbiter Ctrl Register */ 383/* B3_PA_CTRL 16 bit Packet Arbiter Ctrl Register */
470enum { 384enum {
@@ -488,7 +402,7 @@ enum {
488 PA_ENA_TO_TX1 | PA_ENA_TO_TX2) 402 PA_ENA_TO_TX1 | PA_ENA_TO_TX2)
489 403
490 404
491/* Transmit Arbiter Registers MAC 1 and 2, use MR_ADDR() to access */ 405/* Transmit Arbiter Registers MAC 1 and 2, use SK_REG() to access */
492/* TXA_ITI_INI 32 bit Tx Arb Interval Timer Init Val */ 406/* TXA_ITI_INI 32 bit Tx Arb Interval Timer Init Val */
493/* TXA_ITI_VAL 32 bit Tx Arb Interval Timer Value */ 407/* TXA_ITI_VAL 32 bit Tx Arb Interval Timer Value */
494/* TXA_LIM_INI 32 bit Tx Arb Limit Counter Init Val */ 408/* TXA_LIM_INI 32 bit Tx Arb Limit Counter Init Val */
@@ -511,7 +425,7 @@ enum {
511/* 425/*
512 * Bank 4 - 5 426 * Bank 4 - 5
513 */ 427 */
514/* Transmit Arbiter Registers MAC 1 and 2, use MR_ADDR() to access */ 428/* Transmit Arbiter Registers MAC 1 and 2, use SK_REG() to access */
515enum { 429enum {
516 TXA_ITI_INI = 0x0200,/* 32 bit Tx Arb Interval Timer Init Val*/ 430 TXA_ITI_INI = 0x0200,/* 32 bit Tx Arb Interval Timer Init Val*/
517 TXA_ITI_VAL = 0x0204,/* 32 bit Tx Arb Interval Timer Value */ 431 TXA_ITI_VAL = 0x0204,/* 32 bit Tx Arb Interval Timer Value */
@@ -537,7 +451,7 @@ enum {
537 451
538/* Queue Register Offsets, use Q_ADDR() to access */ 452/* Queue Register Offsets, use Q_ADDR() to access */
539enum { 453enum {
540 B8_Q_REGS = 0x0400, /* base of Queue registers */ 454 B8_Q_REGS = 0x0400, /* base of Queue registers */
541 Q_D = 0x00, /* 8*32 bit Current Descriptor */ 455 Q_D = 0x00, /* 8*32 bit Current Descriptor */
542 Q_DA_L = 0x20, /* 32 bit Current Descriptor Address Low dWord */ 456 Q_DA_L = 0x20, /* 32 bit Current Descriptor Address Low dWord */
543 Q_DA_H = 0x24, /* 32 bit Current Descriptor Address High dWord */ 457 Q_DA_H = 0x24, /* 32 bit Current Descriptor Address High dWord */
@@ -618,8 +532,7 @@ enum {
618enum { 532enum {
619 PHY_ADDR_XMAC = 0<<8, 533 PHY_ADDR_XMAC = 0<<8,
620 PHY_ADDR_BCOM = 1<<8, 534 PHY_ADDR_BCOM = 1<<8,
621 PHY_ADDR_LONE = 3<<8, 535
622 PHY_ADDR_NAT = 0<<8,
623/* GPHY address (bits 15..11 of SMI control reg) */ 536/* GPHY address (bits 15..11 of SMI control reg) */
624 PHY_ADDR_MARV = 0, 537 PHY_ADDR_MARV = 0,
625}; 538};
@@ -986,7 +899,7 @@ enum {
986 LINKLED_BLINK_OFF = 0x10, 899 LINKLED_BLINK_OFF = 0x10,
987 LINKLED_BLINK_ON = 0x20, 900 LINKLED_BLINK_ON = 0x20,
988}; 901};
989 902
990/* GMAC and GPHY Control Registers (YUKON only) */ 903/* GMAC and GPHY Control Registers (YUKON only) */
991enum { 904enum {
992 GMAC_CTRL = 0x0f00,/* 32 bit GMAC Control Reg */ 905 GMAC_CTRL = 0x0f00,/* 32 bit GMAC Control Reg */
@@ -1151,54 +1064,6 @@ enum {
1151 PHY_MARV_FE_SPEC_2 = 0x1c,/* 16 bit r/w Specific Control Reg. 2 */ 1064 PHY_MARV_FE_SPEC_2 = 0x1c,/* 16 bit r/w Specific Control Reg. 2 */
1152}; 1065};
1153 1066
1154/* Level One-PHY Registers, indirect addressed over XMAC */
1155enum {
1156 PHY_LONE_CTRL = 0x00,/* 16 bit r/w PHY Control Register */
1157 PHY_LONE_STAT = 0x01,/* 16 bit r/o PHY Status Register */
1158 PHY_LONE_ID0 = 0x02,/* 16 bit r/o PHY ID0 Register */
1159 PHY_LONE_ID1 = 0x03,/* 16 bit r/o PHY ID1 Register */
1160 PHY_LONE_AUNE_ADV = 0x04,/* 16 bit r/w Auto-Neg. Advertisement */
1161 PHY_LONE_AUNE_LP = 0x05,/* 16 bit r/o Link Part Ability Reg */
1162 PHY_LONE_AUNE_EXP = 0x06,/* 16 bit r/o Auto-Neg. Expansion Reg */
1163 PHY_LONE_NEPG = 0x07,/* 16 bit r/w Next Page Register */
1164 PHY_LONE_NEPG_LP = 0x08,/* 16 bit r/o Next Page Link Partner */
1165 /* Level One-specific registers */
1166 PHY_LONE_1000T_CTRL = 0x09,/* 16 bit r/w 1000Base-T Control Reg */
1167 PHY_LONE_1000T_STAT = 0x0a,/* 16 bit r/o 1000Base-T Status Reg */
1168 PHY_LONE_EXT_STAT = 0x0f,/* 16 bit r/o Extended Status Reg */
1169 PHY_LONE_PORT_CFG = 0x10,/* 16 bit r/w Port Configuration Reg*/
1170 PHY_LONE_Q_STAT = 0x11,/* 16 bit r/o Quick Status Reg */
1171 PHY_LONE_INT_ENAB = 0x12,/* 16 bit r/w Interrupt Enable Reg */
1172 PHY_LONE_INT_STAT = 0x13,/* 16 bit r/o Interrupt Status Reg */
1173 PHY_LONE_LED_CFG = 0x14,/* 16 bit r/w LED Configuration Reg */
1174 PHY_LONE_PORT_CTRL = 0x15,/* 16 bit r/w Port Control Reg */
1175 PHY_LONE_CIM = 0x16,/* 16 bit r/o CIM Reg */
1176};
1177
1178/* National-PHY Registers, indirect addressed over XMAC */
1179enum {
1180 PHY_NAT_CTRL = 0x00,/* 16 bit r/w PHY Control Register */
1181 PHY_NAT_STAT = 0x01,/* 16 bit r/w PHY Status Register */
1182 PHY_NAT_ID0 = 0x02,/* 16 bit r/o PHY ID0 Register */
1183 PHY_NAT_ID1 = 0x03,/* 16 bit r/o PHY ID1 Register */
1184 PHY_NAT_AUNE_ADV = 0x04,/* 16 bit r/w Auto-Neg. Advertisement */
1185 PHY_NAT_AUNE_LP = 0x05,/* 16 bit r/o Link Partner Ability Reg */
1186 PHY_NAT_AUNE_EXP = 0x06,/* 16 bit r/o Auto-Neg. Expansion Reg */
1187 PHY_NAT_NEPG = 0x07,/* 16 bit r/w Next Page Register */
1188 PHY_NAT_NEPG_LP = 0x08,/* 16 bit r/o Next Page Link Partner Reg */
1189 /* National-specific registers */
1190 PHY_NAT_1000T_CTRL = 0x09,/* 16 bit r/w 1000Base-T Control Reg */
1191 PHY_NAT_1000T_STAT = 0x0a,/* 16 bit r/o 1000Base-T Status Reg */
1192 PHY_NAT_EXT_STAT = 0x0f,/* 16 bit r/o Extended Status Register */
1193 PHY_NAT_EXT_CTRL1 = 0x10,/* 16 bit r/o Extended Control Reg1 */
1194 PHY_NAT_Q_STAT1 = 0x11,/* 16 bit r/o Quick Status Reg1 */
1195 PHY_NAT_10B_OP = 0x12,/* 16 bit r/o 10Base-T Operations Reg */
1196 PHY_NAT_EXT_CTRL2 = 0x13,/* 16 bit r/o Extended Control Reg1 */
1197 PHY_NAT_Q_STAT2 = 0x14,/* 16 bit r/o Quick Status Reg2 */
1198
1199 PHY_NAT_PHY_ADDR = 0x19,/* 16 bit r/o PHY Address Register */
1200};
1201
1202enum { 1067enum {
1203 PHY_CT_RESET = 1<<15, /* Bit 15: (sc) clear all PHY related regs */ 1068 PHY_CT_RESET = 1<<15, /* Bit 15: (sc) clear all PHY related regs */
1204 PHY_CT_LOOP = 1<<14, /* Bit 14: enable Loopback over PHY */ 1069 PHY_CT_LOOP = 1<<14, /* Bit 14: enable Loopback over PHY */
@@ -1253,8 +1118,29 @@ enum {
1253 PHY_MARV_ID1_Y2 = 0x0C91, /* Yukon-2 (PHY 88E1112) */ 1118 PHY_MARV_ID1_Y2 = 0x0C91, /* Yukon-2 (PHY 88E1112) */
1254}; 1119};
1255 1120
1121/* Advertisement register bits */
1256enum { 1122enum {
1257 PHY_AN_NXT_PG = 1<<15, /* Bit 15: Request Next Page */ 1123 PHY_AN_NXT_PG = 1<<15, /* Bit 15: Request Next Page */
1124 PHY_AN_ACK = 1<<14, /* Bit 14: (ro) Acknowledge Received */
1125 PHY_AN_RF = 1<<13, /* Bit 13: Remote Fault Bits */
1126
1127 PHY_AN_PAUSE_ASYM = 1<<11,/* Bit 11: Try for asymmetric */
1128 PHY_AN_PAUSE_CAP = 1<<10, /* Bit 10: Try for pause */
1129 PHY_AN_100BASE4 = 1<<9, /* Bit 9: Try for 100mbps 4k packets */
1130 PHY_AN_100FULL = 1<<8, /* Bit 8: Try for 100mbps full-duplex */
1131 PHY_AN_100HALF = 1<<7, /* Bit 7: Try for 100mbps half-duplex */
1132 PHY_AN_10FULL = 1<<6, /* Bit 6: Try for 10mbps full-duplex */
1133 PHY_AN_10HALF = 1<<5, /* Bit 5: Try for 10mbps half-duplex */
1134 PHY_AN_CSMA = 1<<0, /* Bit 0: Only selector supported */
1135 PHY_AN_SEL = 0x1f, /* Bit 4..0: Selector Field, 00001=Ethernet*/
1136 PHY_AN_FULL = PHY_AN_100FULL | PHY_AN_10FULL | PHY_AN_CSMA,
1137 PHY_AN_ALL = PHY_AN_10HALF | PHY_AN_10FULL |
1138 PHY_AN_100HALF | PHY_AN_100FULL,
1139};
1140
1141/* Xmac Specific */
1142enum {
1143 PHY_X_AN_NXT_PG = 1<<15, /* Bit 15: Request Next Page */
1258 PHY_X_AN_ACK = 1<<14, /* Bit 14: (ro) Acknowledge Received */ 1144 PHY_X_AN_ACK = 1<<14, /* Bit 14: (ro) Acknowledge Received */
1259 PHY_X_AN_RFB = 3<<12,/* Bit 13..12: Remote Fault Bits */ 1145 PHY_X_AN_RFB = 3<<12,/* Bit 13..12: Remote Fault Bits */
1260 1146
@@ -1263,82 +1149,6 @@ enum {
1263 PHY_X_AN_FD = 1<<5, /* Bit 5: Full Duplex */ 1149 PHY_X_AN_FD = 1<<5, /* Bit 5: Full Duplex */
1264}; 1150};
1265 1151
1266enum {
1267 PHY_B_AN_RF = 1<<13, /* Bit 13: Remote Fault */
1268
1269 PHY_B_AN_ASP = 1<<11, /* Bit 11: Asymmetric Pause */
1270 PHY_B_AN_PC = 1<<10, /* Bit 10: Pause Capable */
1271 PHY_B_AN_SEL = 0x1f, /* Bit 4..0: Selector Field, 00001=Ethernet*/
1272};
1273
1274enum {
1275 PHY_L_AN_RF = 1<<13, /* Bit 13: Remote Fault */
1276 /* Bit 12: reserved */
1277 PHY_L_AN_ASP = 1<<11, /* Bit 11: Asymmetric Pause */
1278 PHY_L_AN_PC = 1<<10, /* Bit 10: Pause Capable */
1279
1280 PHY_L_AN_SEL = 0x1f, /* Bit 4..0: Selector Field, 00001=Ethernet*/
1281};
1282
1283/* PHY_NAT_AUNE_ADV 16 bit r/w Auto-Negotiation Advertisement */
1284/* PHY_NAT_AUNE_LP 16 bit r/o Link Partner Ability Reg *****/
1285/* PHY_AN_NXT_PG (see XMAC) Bit 15: Request Next Page */
1286enum {
1287 PHY_N_AN_RF = 1<<13, /* Bit 13: Remote Fault */
1288
1289 PHY_N_AN_100F = 1<<11, /* Bit 11: 100Base-T2 FD Support */
1290 PHY_N_AN_100H = 1<<10, /* Bit 10: 100Base-T2 HD Support */
1291
1292 PHY_N_AN_SEL = 0x1f, /* Bit 4..0: Selector Field, 00001=Ethernet*/
1293};
1294
1295/* field type definition for PHY_x_AN_SEL */
1296enum {
1297 PHY_SEL_TYPE = 1, /* 00001 = Ethernet */
1298};
1299
1300enum {
1301 PHY_ANE_LP_NP = 1<<3, /* Bit 3: Link Partner can Next Page */
1302 PHY_ANE_LOC_NP = 1<<2, /* Bit 2: Local PHY can Next Page */
1303 PHY_ANE_RX_PG = 1<<1, /* Bit 1: Page Received */
1304};
1305
1306enum {
1307 PHY_ANE_PAR_DF = 1<<4, /* Bit 4: Parallel Detection Fault */
1308
1309 PHY_ANE_LP_CAP = 1<<0, /* Bit 0: Link Partner Auto-Neg. Cap. */
1310};
1311
1312enum {
1313 PHY_NP_MORE = 1<<15, /* Bit 15: More, Next Pages to follow */
1314 PHY_NP_ACK1 = 1<<14, /* Bit 14: (ro) Ack1, for receiving a message */
1315 PHY_NP_MSG_VAL = 1<<13, /* Bit 13: Message Page valid */
1316 PHY_NP_ACK2 = 1<<12, /* Bit 12: Ack2, comply with msg content */
1317 PHY_NP_TOG = 1<<11, /* Bit 11: Toggle Bit, ensure sync */
1318 PHY_NP_MSG = 0x07ff, /* Bit 10..0: Message from/to Link Partner */
1319};
1320
1321enum {
1322 PHY_X_EX_FD = 1<<15, /* Bit 15: Device Supports Full Duplex */
1323 PHY_X_EX_HD = 1<<14, /* Bit 14: Device Supports Half Duplex */
1324};
1325
1326enum {
1327 PHY_X_RS_PAUSE = 3<<7,/* Bit 8..7: selected Pause Mode */
1328 PHY_X_RS_HD = 1<<6, /* Bit 6: Half Duplex Mode selected */
1329 PHY_X_RS_FD = 1<<5, /* Bit 5: Full Duplex Mode selected */
1330 PHY_X_RS_ABLMIS = 1<<4, /* Bit 4: duplex or pause cap mismatch */
1331 PHY_X_RS_PAUMIS = 1<<3, /* Bit 3: pause capability mismatch */
1332};
1333
1334/** Remote Fault Bits (PHY_X_AN_RFB) encoding */
1335enum {
1336 X_RFB_OK = 0<<12,/* Bit 13..12 No errors, Link OK */
1337 X_RFB_LF = 1<<12, /* Bit 13..12 Link Failure */
1338 X_RFB_OFF = 2<<12,/* Bit 13..12 Offline */
1339 X_RFB_AN_ERR = 3<<12,/* Bit 13..12 Auto-Negotiation Error */
1340};
1341
1342/* Pause Bits (PHY_X_AN_PAUSE and PHY_X_RS_PAUSE) encoding */ 1152/* Pause Bits (PHY_X_AN_PAUSE and PHY_X_RS_PAUSE) encoding */
1343enum { 1153enum {
1344 PHY_X_P_NO_PAUSE = 0<<7,/* Bit 8..7: no Pause Mode */ 1154 PHY_X_P_NO_PAUSE = 0<<7,/* Bit 8..7: no Pause Mode */
@@ -1418,6 +1228,16 @@ enum {
1418 PHY_B_PES_MLT3_ER = 1<<0, /* Bit 0: MLT3 code Error */ 1228 PHY_B_PES_MLT3_ER = 1<<0, /* Bit 0: MLT3 code Error */
1419}; 1229};
1420 1230
1231/* PHY_BCOM_AUNE_ADV 16 bit r/w Auto-Negotiation Advertisement *****/
1232/* PHY_BCOM_AUNE_LP 16 bit r/o Link Partner Ability Reg *****/
1233enum {
1234 PHY_B_AN_RF = 1<<13, /* Bit 13: Remote Fault */
1235
1236 PHY_B_AN_ASP = 1<<11, /* Bit 11: Asymmetric Pause */
1237 PHY_B_AN_PC = 1<<10, /* Bit 10: Pause Capable */
1238};
1239
1240
1421/***** PHY_BCOM_FC_CTR 16 bit r/w False Carrier Counter *****/ 1241/***** PHY_BCOM_FC_CTR 16 bit r/w False Carrier Counter *****/
1422enum { 1242enum {
1423 PHY_B_FC_CTR = 0xff, /* Bit 7..0: False Carrier Counter */ 1243 PHY_B_FC_CTR = 0xff, /* Bit 7..0: False Carrier Counter */
@@ -1478,7 +1298,9 @@ enum {
1478 PHY_B_IS_LST_CHANGE = 1<<1, /* Bit 1: Link Status Changed */ 1298 PHY_B_IS_LST_CHANGE = 1<<1, /* Bit 1: Link Status Changed */
1479 PHY_B_IS_CRC_ER = 1<<0, /* Bit 0: CRC Error */ 1299 PHY_B_IS_CRC_ER = 1<<0, /* Bit 0: CRC Error */
1480}; 1300};
1481#define PHY_B_DEF_MSK (~(PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE)) 1301#define PHY_B_DEF_MSK \
1302 (~(PHY_B_IS_PSE | PHY_B_IS_AN_PR | PHY_B_IS_DUP_CHANGE | \
1303 PHY_B_IS_LSP_CHANGE | PHY_B_IS_LST_CHANGE))
1482 1304
1483/* Pause Bits (PHY_B_AN_ASP and PHY_B_AN_PC) encoding */ 1305/* Pause Bits (PHY_B_AN_ASP and PHY_B_AN_PC) encoding */
1484enum { 1306enum {
@@ -1495,166 +1317,6 @@ enum {
1495 PHY_B_RES_1000HD = 6<<8,/* Bit 10..8: 1000Base-T Half Dup. */ 1317 PHY_B_RES_1000HD = 6<<8,/* Bit 10..8: 1000Base-T Half Dup. */
1496}; 1318};
1497 1319
1498/*
1499 * Level One-Specific
1500 */
1501/***** PHY_LONE_1000T_CTRL 16 bit r/w 1000Base-T Control Reg *****/
1502enum {
1503 PHY_L_1000C_TEST = 7<<13,/* Bit 15..13: Test Modes */
1504 PHY_L_1000C_MSE = 1<<12, /* Bit 12: Master/Slave Enable */
1505 PHY_L_1000C_MSC = 1<<11, /* Bit 11: M/S Configuration */
1506 PHY_L_1000C_RD = 1<<10, /* Bit 10: Repeater/DTE */
1507 PHY_L_1000C_AFD = 1<<9, /* Bit 9: Advertise Full Duplex */
1508 PHY_L_1000C_AHD = 1<<8, /* Bit 8: Advertise Half Duplex */
1509};
1510
1511/***** PHY_LONE_1000T_STAT 16 bit r/o 1000Base-T Status Reg *****/
1512enum {
1513 PHY_L_1000S_MSF = 1<<15, /* Bit 15: Master/Slave Fault */
1514 PHY_L_1000S_MSR = 1<<14, /* Bit 14: Master/Slave Result */
1515 PHY_L_1000S_LRS = 1<<13, /* Bit 13: Local Receiver Status */
1516 PHY_L_1000S_RRS = 1<<12, /* Bit 12: Remote Receiver Status */
1517 PHY_L_1000S_LP_FD = 1<<11, /* Bit 11: Link Partner can FD */
1518 PHY_L_1000S_LP_HD = 1<<10, /* Bit 10: Link Partner can HD */
1519
1520 PHY_L_1000S_IEC = 0xff, /* Bit 7..0: Idle Error Count */
1521
1522/***** PHY_LONE_EXT_STAT 16 bit r/o Extended Status Register *****/
1523 PHY_L_ES_X_FD_CAP = 1<<15, /* Bit 15: 1000Base-X FD capable */
1524 PHY_L_ES_X_HD_CAP = 1<<14, /* Bit 14: 1000Base-X HD capable */
1525 PHY_L_ES_T_FD_CAP = 1<<13, /* Bit 13: 1000Base-T FD capable */
1526 PHY_L_ES_T_HD_CAP = 1<<12, /* Bit 12: 1000Base-T HD capable */
1527};
1528
1529/***** PHY_LONE_PORT_CFG 16 bit r/w Port Configuration Reg *****/
1530enum {
1531 PHY_L_PC_REP_MODE = 1<<15, /* Bit 15: Repeater Mode */
1532
1533 PHY_L_PC_TX_DIS = 1<<13, /* Bit 13: Tx output Disabled */
1534 PHY_L_PC_BY_SCR = 1<<12, /* Bit 12: Bypass Scrambler */
1535 PHY_L_PC_BY_45 = 1<<11, /* Bit 11: Bypass 4B5B-Decoder */
1536 PHY_L_PC_JAB_DIS = 1<<10, /* Bit 10: Jabber Disabled */
1537 PHY_L_PC_SQE = 1<<9, /* Bit 9: Enable Heartbeat */
1538 PHY_L_PC_TP_LOOP = 1<<8, /* Bit 8: TP Loopback */
1539 PHY_L_PC_SSS = 1<<7, /* Bit 7: Smart Speed Selection */
1540 PHY_L_PC_FIFO_SIZE = 1<<6, /* Bit 6: FIFO Size */
1541 PHY_L_PC_PRE_EN = 1<<5, /* Bit 5: Preamble Enable */
1542 PHY_L_PC_CIM = 1<<4, /* Bit 4: Carrier Integrity Mon */
1543 PHY_L_PC_10_SER = 1<<3, /* Bit 3: Use Serial Output */
1544 PHY_L_PC_ANISOL = 1<<2, /* Bit 2: Unisolate Port */
1545 PHY_L_PC_TEN_BIT = 1<<1, /* Bit 1: 10bit iface mode on */
1546 PHY_L_PC_ALTCLOCK = 1<<0, /* Bit 0: (ro) ALTCLOCK Mode on */
1547};
1548
1549/***** PHY_LONE_Q_STAT 16 bit r/o Quick Status Reg *****/
1550enum {
1551 PHY_L_QS_D_RATE = 3<<14,/* Bit 15..14: Data Rate */
1552 PHY_L_QS_TX_STAT = 1<<13, /* Bit 13: Transmitting */
1553 PHY_L_QS_RX_STAT = 1<<12, /* Bit 12: Receiving */
1554 PHY_L_QS_COL_STAT = 1<<11, /* Bit 11: Collision */
1555 PHY_L_QS_L_STAT = 1<<10, /* Bit 10: Link is up */
1556 PHY_L_QS_DUP_MOD = 1<<9, /* Bit 9: Full/Half Duplex */
1557 PHY_L_QS_AN = 1<<8, /* Bit 8: AutoNeg is On */
1558 PHY_L_QS_AN_C = 1<<7, /* Bit 7: AN is Complete */
1559 PHY_L_QS_LLE = 7<<4,/* Bit 6..4: Line Length Estim. */
1560 PHY_L_QS_PAUSE = 1<<3, /* Bit 3: LP advertised Pause */
1561 PHY_L_QS_AS_PAUSE = 1<<2, /* Bit 2: LP adv. asym. Pause */
1562 PHY_L_QS_ISOLATE = 1<<1, /* Bit 1: CIM Isolated */
1563 PHY_L_QS_EVENT = 1<<0, /* Bit 0: Event has occurred */
1564};
1565
1566/***** PHY_LONE_INT_ENAB 16 bit r/w Interrupt Enable Reg *****/
1567/***** PHY_LONE_INT_STAT 16 bit r/o Interrupt Status Reg *****/
1568enum {
1569 PHY_L_IS_AN_F = 1<<13, /* Bit 13: Auto-Negotiation fault */
1570 PHY_L_IS_CROSS = 1<<11, /* Bit 11: Crossover used */
1571 PHY_L_IS_POL = 1<<10, /* Bit 10: Polarity correct. used */
1572 PHY_L_IS_SS = 1<<9, /* Bit 9: Smart Speed Downgrade */
1573 PHY_L_IS_CFULL = 1<<8, /* Bit 8: Counter Full */
1574 PHY_L_IS_AN_C = 1<<7, /* Bit 7: AutoNeg Complete */
1575 PHY_L_IS_SPEED = 1<<6, /* Bit 6: Speed Changed */
1576 PHY_L_IS_DUP = 1<<5, /* Bit 5: Duplex Changed */
1577 PHY_L_IS_LS = 1<<4, /* Bit 4: Link Status Changed */
1578 PHY_L_IS_ISOL = 1<<3, /* Bit 3: Isolate Occured */
1579 PHY_L_IS_MDINT = 1<<2, /* Bit 2: (ro) STAT: MII Int Pending */
1580 PHY_L_IS_INTEN = 1<<1, /* Bit 1: ENAB: Enable IRQs */
1581 PHY_L_IS_FORCE = 1<<0, /* Bit 0: ENAB: Force Interrupt */
1582};
1583
1584/* int. mask */
1585#define PHY_L_DEF_MSK (PHY_L_IS_LS | PHY_L_IS_ISOL | PHY_L_IS_INTEN)
1586
1587/***** PHY_LONE_LED_CFG 16 bit r/w LED Configuration Reg *****/
1588enum {
1589 PHY_L_LC_LEDC = 3<<14,/* Bit 15..14: Col/Blink/On/Off */
1590 PHY_L_LC_LEDR = 3<<12,/* Bit 13..12: Rx/Blink/On/Off */
1591 PHY_L_LC_LEDT = 3<<10,/* Bit 11..10: Tx/Blink/On/Off */
1592 PHY_L_LC_LEDG = 3<<8,/* Bit 9..8: Giga/Blink/On/Off */
1593 PHY_L_LC_LEDS = 3<<6,/* Bit 7..6: 10-100/Blink/On/Off */
1594 PHY_L_LC_LEDL = 3<<4,/* Bit 5..4: Link/Blink/On/Off */
1595 PHY_L_LC_LEDF = 3<<2,/* Bit 3..2: Duplex/Blink/On/Off */
1596 PHY_L_LC_PSTRECH= 1<<1, /* Bit 1: Strech LED Pulses */
1597 PHY_L_LC_FREQ = 1<<0, /* Bit 0: 30/100 ms */
1598};
1599
1600/***** PHY_LONE_PORT_CTRL 16 bit r/w Port Control Reg *****/
1601enum {
1602 PHY_L_PC_TX_TCLK = 1<<15, /* Bit 15: Enable TX_TCLK */
1603 PHY_L_PC_ALT_NP = 1<<13, /* Bit 14: Alternate Next Page */
1604 PHY_L_PC_GMII_ALT= 1<<12, /* Bit 13: Alternate GMII driver */
1605 PHY_L_PC_TEN_CRS = 1<<10, /* Bit 10: Extend CRS*/
1606};
1607
1608/***** PHY_LONE_CIM 16 bit r/o CIM Reg *****/
1609enum {
1610 PHY_L_CIM_ISOL = 0xff<<8,/* Bit 15..8: Isolate Count */
1611 PHY_L_CIM_FALSE_CAR = 0xff, /* Bit 7..0: False Carrier Count */
1612};
1613
1614/*
1615 * Pause Bits (PHY_L_AN_ASP and PHY_L_AN_PC) encoding
1616 */
1617enum {
1618 PHY_L_P_NO_PAUSE= 0<<10,/* Bit 11..10: no Pause Mode */
1619 PHY_L_P_SYM_MD = 1<<10, /* Bit 11..10: symmetric Pause Mode */
1620 PHY_L_P_ASYM_MD = 2<<10,/* Bit 11..10: asymmetric Pause Mode */
1621 PHY_L_P_BOTH_MD = 3<<10,/* Bit 11..10: both Pause Mode */
1622};
1623
1624/*
1625 * National-Specific
1626 */
1627/***** PHY_NAT_1000T_CTRL 16 bit r/w 1000Base-T Control Reg *****/
1628enum {
1629 PHY_N_1000C_TEST= 7<<13,/* Bit 15..13: Test Modes */
1630 PHY_N_1000C_MSE = 1<<12, /* Bit 12: Master/Slave Enable */
1631 PHY_N_1000C_MSC = 1<<11, /* Bit 11: M/S Configuration */
1632 PHY_N_1000C_RD = 1<<10, /* Bit 10: Repeater/DTE */
1633 PHY_N_1000C_AFD = 1<<9, /* Bit 9: Advertise Full Duplex */
1634 PHY_N_1000C_AHD = 1<<8, /* Bit 8: Advertise Half Duplex */
1635 PHY_N_1000C_APC = 1<<7, /* Bit 7: Asymmetric Pause Cap. */};
1636
1637
1638/***** PHY_NAT_1000T_STAT 16 bit r/o 1000Base-T Status Reg *****/
1639enum {
1640 PHY_N_1000S_MSF = 1<<15, /* Bit 15: Master/Slave Fault */
1641 PHY_N_1000S_MSR = 1<<14, /* Bit 14: Master/Slave Result */
1642 PHY_N_1000S_LRS = 1<<13, /* Bit 13: Local Receiver Status */
1643 PHY_N_1000S_RRS = 1<<12, /* Bit 12: Remote Receiver Status*/
1644 PHY_N_1000S_LP_FD= 1<<11, /* Bit 11: Link Partner can FD */
1645 PHY_N_1000S_LP_HD= 1<<10, /* Bit 10: Link Partner can HD */
1646 PHY_N_1000C_LP_APC= 1<<9, /* Bit 9: LP Asym. Pause Cap. */
1647 PHY_N_1000S_IEC = 0xff, /* Bit 7..0: Idle Error Count */
1648};
1649
1650/***** PHY_NAT_EXT_STAT 16 bit r/o Extended Status Register *****/
1651enum {
1652 PHY_N_ES_X_FD_CAP= 1<<15, /* Bit 15: 1000Base-X FD capable */
1653 PHY_N_ES_X_HD_CAP= 1<<14, /* Bit 14: 1000Base-X HD capable */
1654 PHY_N_ES_T_FD_CAP= 1<<13, /* Bit 13: 1000Base-T FD capable */
1655 PHY_N_ES_T_HD_CAP= 1<<12, /* Bit 12: 1000Base-T HD capable */
1656};
1657
1658/** Marvell-Specific */ 1320/** Marvell-Specific */
1659enum { 1321enum {
1660 PHY_M_AN_NXT_PG = 1<<15, /* Request Next Page */ 1322 PHY_M_AN_NXT_PG = 1<<15, /* Request Next Page */
@@ -1718,7 +1380,7 @@ enum {
1718 PHY_M_PC_EN_DET_PLUS = 3<<8, /* Energy Detect Plus (Mode 2) */ 1380 PHY_M_PC_EN_DET_PLUS = 3<<8, /* Energy Detect Plus (Mode 2) */
1719}; 1381};
1720 1382
1721#define PHY_M_PC_MDI_XMODE(x) (((x)<<5) & PHY_M_PC_MDIX_MSK) 1383#define PHY_M_PC_MDI_XMODE(x) (((x)<<5) & PHY_M_PC_MDIX_MSK)
1722 1384
1723enum { 1385enum {
1724 PHY_M_PC_MAN_MDI = 0, /* 00 = Manual MDI configuration */ 1386 PHY_M_PC_MAN_MDI = 0, /* 00 = Manual MDI configuration */
@@ -2105,7 +1767,7 @@ enum {
2105 GM_GPSR_FC_RX_DIS = 1<<2, /* Bit 2: Rx Flow-Control Mode Disabled */ 1767 GM_GPSR_FC_RX_DIS = 1<<2, /* Bit 2: Rx Flow-Control Mode Disabled */
2106 GM_GPSR_PROM_EN = 1<<1, /* Bit 1: Promiscuous Mode Enabled */ 1768 GM_GPSR_PROM_EN = 1<<1, /* Bit 1: Promiscuous Mode Enabled */
2107}; 1769};
2108 1770
2109/* GM_GP_CTRL 16 bit r/w General Purpose Control Register */ 1771/* GM_GP_CTRL 16 bit r/w General Purpose Control Register */
2110enum { 1772enum {
2111 GM_GPCR_PROM_ENA = 1<<14, /* Bit 14: Enable Promiscuous Mode */ 1773 GM_GPCR_PROM_ENA = 1<<14, /* Bit 14: Enable Promiscuous Mode */
@@ -2127,7 +1789,7 @@ enum {
2127 1789
2128#define GM_GPCR_SPEED_1000 (GM_GPCR_GIGS_ENA | GM_GPCR_SPEED_100) 1790#define GM_GPCR_SPEED_1000 (GM_GPCR_GIGS_ENA | GM_GPCR_SPEED_100)
2129#define GM_GPCR_AU_ALL_DIS (GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_FCT_DIS|GM_GPCR_AU_SPD_DIS) 1791#define GM_GPCR_AU_ALL_DIS (GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_FCT_DIS|GM_GPCR_AU_SPD_DIS)
2130 1792
2131/* GM_TX_CTRL 16 bit r/w Transmit Control Register */ 1793/* GM_TX_CTRL 16 bit r/w Transmit Control Register */
2132enum { 1794enum {
2133 GM_TXCR_FORCE_JAM = 1<<15, /* Bit 15: Force Jam / Flow-Control */ 1795 GM_TXCR_FORCE_JAM = 1<<15, /* Bit 15: Force Jam / Flow-Control */
@@ -2138,7 +1800,7 @@ enum {
2138 1800
2139#define TX_COL_THR(x) (((x)<<10) & GM_TXCR_COL_THR_MSK) 1801#define TX_COL_THR(x) (((x)<<10) & GM_TXCR_COL_THR_MSK)
2140#define TX_COL_DEF 0x04 1802#define TX_COL_DEF 0x04
2141 1803
2142/* GM_RX_CTRL 16 bit r/w Receive Control Register */ 1804/* GM_RX_CTRL 16 bit r/w Receive Control Register */
2143enum { 1805enum {
2144 GM_RXCR_UCF_ENA = 1<<15, /* Bit 15: Enable Unicast filtering */ 1806 GM_RXCR_UCF_ENA = 1<<15, /* Bit 15: Enable Unicast filtering */
@@ -2146,7 +1808,7 @@ enum {
2146 GM_RXCR_CRC_DIS = 1<<13, /* Bit 13: Remove 4-byte CRC */ 1808 GM_RXCR_CRC_DIS = 1<<13, /* Bit 13: Remove 4-byte CRC */
2147 GM_RXCR_PASS_FC = 1<<12, /* Bit 12: Pass FC packets to FIFO */ 1809 GM_RXCR_PASS_FC = 1<<12, /* Bit 12: Pass FC packets to FIFO */
2148}; 1810};
2149 1811
2150/* GM_TX_PARAM 16 bit r/w Transmit Parameter Register */ 1812/* GM_TX_PARAM 16 bit r/w Transmit Parameter Register */
2151enum { 1813enum {
2152 GM_TXPA_JAMLEN_MSK = 0x03<<14, /* Bit 15..14: Jam Length */ 1814 GM_TXPA_JAMLEN_MSK = 0x03<<14, /* Bit 15..14: Jam Length */
@@ -2171,7 +1833,7 @@ enum {
2171 GM_SMOD_JUMBO_ENA = 1<<8, /* Bit 8: Enable Jumbo (Max. Frame Len) */ 1833 GM_SMOD_JUMBO_ENA = 1<<8, /* Bit 8: Enable Jumbo (Max. Frame Len) */
2172 GM_SMOD_IPG_MSK = 0x1f /* Bit 4..0: Inter-Packet Gap (IPG) */ 1834 GM_SMOD_IPG_MSK = 0x1f /* Bit 4..0: Inter-Packet Gap (IPG) */
2173}; 1835};
2174 1836
2175#define DATA_BLIND_VAL(x) (((x)<<11) & GM_SMOD_DATABL_MSK) 1837#define DATA_BLIND_VAL(x) (((x)<<11) & GM_SMOD_DATABL_MSK)
2176#define DATA_BLIND_DEF 0x04 1838#define DATA_BLIND_DEF 0x04
2177 1839
@@ -2186,7 +1848,7 @@ enum {
2186 GM_SMI_CT_RD_VAL = 1<<4, /* Bit 4: Read Valid (Read completed) */ 1848 GM_SMI_CT_RD_VAL = 1<<4, /* Bit 4: Read Valid (Read completed) */
2187 GM_SMI_CT_BUSY = 1<<3, /* Bit 3: Busy (Operation in progress) */ 1849 GM_SMI_CT_BUSY = 1<<3, /* Bit 3: Busy (Operation in progress) */
2188}; 1850};
2189 1851
2190#define GM_SMI_CT_PHY_AD(x) (((x)<<11) & GM_SMI_CT_PHY_A_MSK) 1852#define GM_SMI_CT_PHY_AD(x) (((x)<<11) & GM_SMI_CT_PHY_A_MSK)
2191#define GM_SMI_CT_REG_AD(x) (((x)<<6) & GM_SMI_CT_REG_A_MSK) 1853#define GM_SMI_CT_REG_AD(x) (((x)<<6) & GM_SMI_CT_REG_A_MSK)
2192 1854
@@ -2195,7 +1857,7 @@ enum {
2195 GM_PAR_MIB_CLR = 1<<5, /* Bit 5: Set MIB Clear Counter Mode */ 1857 GM_PAR_MIB_CLR = 1<<5, /* Bit 5: Set MIB Clear Counter Mode */
2196 GM_PAR_MIB_TST = 1<<4, /* Bit 4: MIB Load Counter (Test Mode) */ 1858 GM_PAR_MIB_TST = 1<<4, /* Bit 4: MIB Load Counter (Test Mode) */
2197}; 1859};
2198 1860
2199/* Receive Frame Status Encoding */ 1861/* Receive Frame Status Encoding */
2200enum { 1862enum {
2201 GMR_FS_LEN = 0xffff<<16, /* Bit 31..16: Rx Frame Length */ 1863 GMR_FS_LEN = 0xffff<<16, /* Bit 31..16: Rx Frame Length */
@@ -2217,12 +1879,12 @@ enum {
2217/* 1879/*
2218 * GMR_FS_ANY_ERR (analogous to XMR_FS_ANY_ERR) 1880 * GMR_FS_ANY_ERR (analogous to XMR_FS_ANY_ERR)
2219 */ 1881 */
2220 GMR_FS_ANY_ERR = GMR_FS_CRC_ERR | GMR_FS_LONG_ERR | 1882 GMR_FS_ANY_ERR = GMR_FS_CRC_ERR | GMR_FS_LONG_ERR |
2221 GMR_FS_MII_ERR | GMR_FS_BAD_FC | GMR_FS_GOOD_FC | 1883 GMR_FS_MII_ERR | GMR_FS_BAD_FC | GMR_FS_GOOD_FC |
2222 GMR_FS_JABBER, 1884 GMR_FS_JABBER,
2223/* Rx GMAC FIFO Flush Mask (default) */ 1885/* Rx GMAC FIFO Flush Mask (default) */
2224 RX_FF_FL_DEF_MSK = GMR_FS_CRC_ERR | GMR_FS_RX_FF_OV |GMR_FS_MII_ERR | 1886 RX_FF_FL_DEF_MSK = GMR_FS_CRC_ERR | GMR_FS_RX_FF_OV |GMR_FS_MII_ERR |
2225 GMR_FS_BAD_FC | GMR_FS_GOOD_FC | GMR_FS_UN_SIZE | 1887 GMR_FS_BAD_FC | GMR_FS_GOOD_FC | GMR_FS_UN_SIZE |
2226 GMR_FS_JABBER, 1888 GMR_FS_JABBER,
2227}; 1889};
2228 1890
@@ -2540,10 +2202,6 @@ enum {
2540}; 2202};
2541 2203
2542 2204
2543/* XM_PHY_ADDR 16 bit r/w PHY Address Register */
2544#define XM_PHY_ADDR_SZ 0x1f /* Bit 4..0: PHY Address bits */
2545
2546
2547/* XM_GP_PORT 32 bit r/w General Purpose Port Register */ 2205/* XM_GP_PORT 32 bit r/w General Purpose Port Register */
2548enum { 2206enum {
2549 XM_GP_ANIP = 1<<6, /* Bit 6: (ro) Auto-Neg. in progress */ 2207 XM_GP_ANIP = 1<<6, /* Bit 6: (ro) Auto-Neg. in progress */
@@ -2662,8 +2320,8 @@ enum {
2662}; 2320};
2663 2321
2664#define XM_PAUSE_MODE (XM_MD_SPOE_E | XM_MD_SPOL_I | XM_MD_SPOH_I) 2322#define XM_PAUSE_MODE (XM_MD_SPOE_E | XM_MD_SPOL_I | XM_MD_SPOH_I)
2665#define XM_DEF_MODE (XM_MD_RX_RUNT | XM_MD_RX_IRLE | XM_MD_RX_LONG |\ 2323#define XM_DEF_MODE (XM_MD_RX_RUNT | XM_MD_RX_IRLE | XM_MD_RX_LONG |\
2666 XM_MD_RX_CRCE | XM_MD_RX_ERR | XM_MD_CSA | XM_MD_CAA) 2324 XM_MD_RX_CRCE | XM_MD_RX_ERR | XM_MD_CSA)
2667 2325
2668/* XM_STAT_CMD 16 bit r/w Statistics Command Register */ 2326/* XM_STAT_CMD 16 bit r/w Statistics Command Register */
2669enum { 2327enum {
@@ -2793,28 +2451,20 @@ struct skge_hw {
2793 u32 intr_mask; 2451 u32 intr_mask;
2794 struct net_device *dev[2]; 2452 struct net_device *dev[2];
2795 2453
2796 u8 mac_cfg;
2797 u8 chip_id; 2454 u8 chip_id;
2455 u8 chip_rev;
2798 u8 phy_type; 2456 u8 phy_type;
2799 u8 pmd_type; 2457 u8 pmd_type;
2800 u16 phy_addr; 2458 u16 phy_addr;
2459 u8 ports;
2801 2460
2802 u32 ram_size; 2461 u32 ram_size;
2803 u32 ram_offset; 2462 u32 ram_offset;
2804 2463
2805 struct tasklet_struct ext_tasklet; 2464 struct tasklet_struct ext_tasklet;
2806 spinlock_t phy_lock; 2465 spinlock_t phy_lock;
2807}; 2466};
2808 2467
2809static inline int isdualport(const struct skge_hw *hw)
2810{
2811 return !(hw->mac_cfg & CFG_SNG_MAC);
2812}
2813
2814static inline u8 chip_rev(const struct skge_hw *hw)
2815{
2816 return (hw->mac_cfg & CFG_CHIP_R_MSK) >> 4;
2817}
2818 2468
2819static inline int iscopper(const struct skge_hw *hw) 2469static inline int iscopper(const struct skge_hw *hw)
2820{ 2470{
@@ -2827,7 +2477,7 @@ enum {
2827 FLOW_MODE_REM_SEND = 2, /* Symmetric or just remote */ 2477 FLOW_MODE_REM_SEND = 2, /* Symmetric or just remote */
2828 FLOW_MODE_SYMMETRIC = 3, /* Both stations may send PAUSE */ 2478 FLOW_MODE_SYMMETRIC = 3, /* Both stations may send PAUSE */
2829}; 2479};
2830 2480
2831struct skge_port { 2481struct skge_port {
2832 u32 msg_enable; 2482 u32 msg_enable;
2833 struct skge_hw *hw; 2483 struct skge_hw *hw;
@@ -2853,8 +2503,8 @@ struct skge_port {
2853 void *mem; /* PCI memory for rings */ 2503 void *mem; /* PCI memory for rings */
2854 dma_addr_t dma; 2504 dma_addr_t dma;
2855 unsigned long mem_size; 2505 unsigned long mem_size;
2506 unsigned int rx_buf_size;
2856 2507
2857 struct timer_list link_check;
2858 struct timer_list led_blink; 2508 struct timer_list led_blink;
2859}; 2509};
2860 2510
@@ -2863,7 +2513,6 @@ struct skge_port {
2863static inline u32 skge_read32(const struct skge_hw *hw, int reg) 2513static inline u32 skge_read32(const struct skge_hw *hw, int reg)
2864{ 2514{
2865 return readl(hw->regs + reg); 2515 return readl(hw->regs + reg);
2866
2867} 2516}
2868 2517
2869static inline u16 skge_read16(const struct skge_hw *hw, int reg) 2518static inline u16 skge_read16(const struct skge_hw *hw, int reg)
@@ -2892,114 +2541,87 @@ static inline void skge_write8(const struct skge_hw *hw, int reg, u8 val)
2892} 2541}
2893 2542
2894/* MAC Related Registers inside the device. */ 2543/* MAC Related Registers inside the device. */
2895#define SKGEMAC_REG(port,reg) (((port)<<7)+(reg)) 2544#define SK_REG(port,reg) (((port)<<7)+(reg))
2896 2545#define SK_XMAC_REG(port, reg) \
2897/* PCI config space can be accessed via memory mapped space */
2898#define SKGEPCI_REG(reg) ((reg)+ 0x380)
2899
2900#define SKGEXM_REG(port, reg) \
2901 ((BASE_XMAC_1 + (port) * (BASE_XMAC_2 - BASE_XMAC_1)) | (reg) << 1) 2546 ((BASE_XMAC_1 + (port) * (BASE_XMAC_2 - BASE_XMAC_1)) | (reg) << 1)
2902 2547
2903static inline u32 skge_xm_read32(const struct skge_hw *hw, int port, int reg) 2548static inline u32 xm_read32(const struct skge_hw *hw, int port, int reg)
2904{
2905 return skge_read32(hw, SKGEXM_REG(port,reg));
2906}
2907
2908static inline u16 skge_xm_read16(const struct skge_hw *hw, int port, int reg)
2909{ 2549{
2910 return skge_read16(hw, SKGEXM_REG(port,reg)); 2550 u32 v;
2551 v = skge_read16(hw, SK_XMAC_REG(port, reg));
2552 v |= (u32)skge_read16(hw, SK_XMAC_REG(port, reg+2)) << 16;
2553 return v;
2911} 2554}
2912 2555
2913static inline u8 skge_xm_read8(const struct skge_hw *hw, int port, int reg) 2556static inline u16 xm_read16(const struct skge_hw *hw, int port, int reg)
2914{ 2557{
2915 return skge_read8(hw, SKGEXM_REG(port,reg)); 2558 return skge_read16(hw, SK_XMAC_REG(port,reg));
2916} 2559}
2917 2560
2918static inline void skge_xm_write32(const struct skge_hw *hw, int port, int r, u32 v) 2561static inline void xm_write32(const struct skge_hw *hw, int port, int r, u32 v)
2919{ 2562{
2920 skge_write32(hw, SKGEXM_REG(port,r), v); 2563 skge_write16(hw, SK_XMAC_REG(port,r), v & 0xffff);
2564 skge_write16(hw, SK_XMAC_REG(port,r+2), v >> 16);
2921} 2565}
2922 2566
2923static inline void skge_xm_write16(const struct skge_hw *hw, int port, int r, u16 v) 2567static inline void xm_write16(const struct skge_hw *hw, int port, int r, u16 v)
2924{ 2568{
2925 skge_write16(hw, SKGEXM_REG(port,r), v); 2569 skge_write16(hw, SK_XMAC_REG(port,r), v);
2926} 2570}
2927 2571
2928static inline void skge_xm_write8(const struct skge_hw *hw, int port, int r, u8 v) 2572static inline void xm_outhash(const struct skge_hw *hw, int port, int reg,
2929{
2930 skge_write8(hw, SKGEXM_REG(port,r), v);
2931}
2932
2933static inline void skge_xm_outhash(const struct skge_hw *hw, int port, int reg,
2934 const u8 *hash) 2573 const u8 *hash)
2935{ 2574{
2936 skge_xm_write16(hw, port, reg, 2575 xm_write16(hw, port, reg, (u16)hash[0] | ((u16)hash[1] << 8));
2937 (u16)hash[0] | ((u16)hash[1] << 8)); 2576 xm_write16(hw, port, reg+2, (u16)hash[2] | ((u16)hash[3] << 8));
2938 skge_xm_write16(hw, port, reg+2, 2577 xm_write16(hw, port, reg+4, (u16)hash[4] | ((u16)hash[5] << 8));
2939 (u16)hash[2] | ((u16)hash[3] << 8)); 2578 xm_write16(hw, port, reg+6, (u16)hash[6] | ((u16)hash[7] << 8));
2940 skge_xm_write16(hw, port, reg+4,
2941 (u16)hash[4] | ((u16)hash[5] << 8));
2942 skge_xm_write16(hw, port, reg+6,
2943 (u16)hash[6] | ((u16)hash[7] << 8));
2944} 2579}
2945 2580
2946static inline void skge_xm_outaddr(const struct skge_hw *hw, int port, int reg, 2581static inline void xm_outaddr(const struct skge_hw *hw, int port, int reg,
2947 const u8 *addr) 2582 const u8 *addr)
2948{ 2583{
2949 skge_xm_write16(hw, port, reg, 2584 xm_write16(hw, port, reg, (u16)addr[0] | ((u16)addr[1] << 8));
2950 (u16)addr[0] | ((u16)addr[1] << 8)); 2585 xm_write16(hw, port, reg+2, (u16)addr[2] | ((u16)addr[3] << 8));
2951 skge_xm_write16(hw, port, reg, 2586 xm_write16(hw, port, reg+4, (u16)addr[4] | ((u16)addr[5] << 8));
2952 (u16)addr[2] | ((u16)addr[3] << 8));
2953 skge_xm_write16(hw, port, reg,
2954 (u16)addr[4] | ((u16)addr[5] << 8));
2955} 2587}
2956 2588
2589#define SK_GMAC_REG(port,reg) \
2590 (BASE_GMAC_1 + (port) * (BASE_GMAC_2-BASE_GMAC_1) + (reg))
2957 2591
2958#define SKGEGMA_REG(port,reg) \ 2592static inline u16 gma_read16(const struct skge_hw *hw, int port, int reg)
2959 ((reg) + BASE_GMAC_1 + \
2960 (port) * (BASE_GMAC_2-BASE_GMAC_1))
2961
2962static inline u16 skge_gma_read16(const struct skge_hw *hw, int port, int reg)
2963{ 2593{
2964 return skge_read16(hw, SKGEGMA_REG(port,reg)); 2594 return skge_read16(hw, SK_GMAC_REG(port,reg));
2965} 2595}
2966 2596
2967static inline u32 skge_gma_read32(const struct skge_hw *hw, int port, int reg) 2597static inline u32 gma_read32(const struct skge_hw *hw, int port, int reg)
2968{ 2598{
2969 return (u32) skge_read16(hw, SKGEGMA_REG(port,reg)) 2599 return (u32) skge_read16(hw, SK_GMAC_REG(port,reg))
2970 | ((u32)skge_read16(hw, SKGEGMA_REG(port,reg+4)) << 16); 2600 | ((u32)skge_read16(hw, SK_GMAC_REG(port,reg+4)) << 16);
2971} 2601}
2972 2602
2973static inline u8 skge_gma_read8(const struct skge_hw *hw, int port, int reg) 2603static inline void gma_write16(const struct skge_hw *hw, int port, int r, u16 v)
2974{ 2604{
2975 return skge_read8(hw, SKGEGMA_REG(port,reg)); 2605 skge_write16(hw, SK_GMAC_REG(port,r), v);
2976} 2606}
2977 2607
2978static inline void skge_gma_write16(const struct skge_hw *hw, int port, int r, u16 v) 2608static inline void gma_write32(const struct skge_hw *hw, int port, int r, u32 v)
2979{ 2609{
2980 skge_write16(hw, SKGEGMA_REG(port,r), v); 2610 skge_write16(hw, SK_GMAC_REG(port, r), (u16) v);
2611 skge_write32(hw, SK_GMAC_REG(port, r+4), (u16)(v >> 16));
2981} 2612}
2982 2613
2983static inline void skge_gma_write32(const struct skge_hw *hw, int port, int r, u32 v) 2614static inline void gma_write8(const struct skge_hw *hw, int port, int r, u8 v)
2984{ 2615{
2985 skge_write16(hw, SKGEGMA_REG(port, r), (u16) v); 2616 skge_write8(hw, SK_GMAC_REG(port,r), v);
2986 skge_write32(hw, SKGEGMA_REG(port, r+4), (u16)(v >> 16));
2987} 2617}
2988 2618
2989static inline void skge_gma_write8(const struct skge_hw *hw, int port, int r, u8 v) 2619static inline void gma_set_addr(struct skge_hw *hw, int port, int reg,
2990{
2991 skge_write8(hw, SKGEGMA_REG(port,r), v);
2992}
2993
2994static inline void skge_gm_set_addr(struct skge_hw *hw, int port, int reg,
2995 const u8 *addr) 2620 const u8 *addr)
2996{ 2621{
2997 skge_gma_write16(hw, port, reg, 2622 gma_write16(hw, port, reg, (u16) addr[0] | ((u16) addr[1] << 8));
2998 (u16) addr[0] | ((u16) addr[1] << 8)); 2623 gma_write16(hw, port, reg+4,(u16) addr[2] | ((u16) addr[3] << 8));
2999 skge_gma_write16(hw, port, reg+4, 2624 gma_write16(hw, port, reg+8,(u16) addr[4] | ((u16) addr[5] << 8));
3000 (u16) addr[2] | ((u16) addr[3] << 8));
3001 skge_gma_write16(hw, port, reg+8,
3002 (u16) addr[4] | ((u16) addr[5] << 8));
3003} 2625}
3004 2626
3005#endif 2627#endif
diff --git a/drivers/net/slip.c b/drivers/net/slip.c
index c79e0ad4ba02..404ea4297e32 100644
--- a/drivers/net/slip.c
+++ b/drivers/net/slip.c
@@ -74,6 +74,7 @@
74#include <linux/rtnetlink.h> 74#include <linux/rtnetlink.h>
75#include <linux/if_arp.h> 75#include <linux/if_arp.h>
76#include <linux/if_slip.h> 76#include <linux/if_slip.h>
77#include <linux/delay.h>
77#include <linux/init.h> 78#include <linux/init.h>
78#include "slip.h" 79#include "slip.h"
79#ifdef CONFIG_INET 80#ifdef CONFIG_INET
@@ -1383,10 +1384,8 @@ static void __exit slip_exit(void)
1383 /* First of all: check for active disciplines and hangup them. 1384 /* First of all: check for active disciplines and hangup them.
1384 */ 1385 */
1385 do { 1386 do {
1386 if (busy) { 1387 if (busy)
1387 set_current_state(TASK_INTERRUPTIBLE); 1388 msleep_interruptible(100);
1388 schedule_timeout(HZ / 10);
1389 }
1390 1389
1391 busy = 0; 1390 busy = 0;
1392 for (i = 0; i < slip_maxdev; i++) { 1391 for (i = 0; i < slip_maxdev; i++) {
diff --git a/drivers/net/smc-mca.c b/drivers/net/smc-mca.c
index 990201f42ba0..f00c476064f0 100644
--- a/drivers/net/smc-mca.c
+++ b/drivers/net/smc-mca.c
@@ -49,7 +49,6 @@
49#include <asm/system.h> 49#include <asm/system.h>
50 50
51#include "8390.h" 51#include "8390.h"
52#include "smc-mca.h"
53 52
54#define DRV_NAME "smc-mca" 53#define DRV_NAME "smc-mca"
55 54
@@ -100,6 +99,63 @@ module_param_array(ultra_irq, int, NULL, 0);
100MODULE_PARM_DESC(ultra_io, "SMC Ultra/EtherEZ MCA I/O base address(es)"); 99MODULE_PARM_DESC(ultra_io, "SMC Ultra/EtherEZ MCA I/O base address(es)");
101MODULE_PARM_DESC(ultra_irq, "SMC Ultra/EtherEZ MCA IRQ number(s)"); 100MODULE_PARM_DESC(ultra_irq, "SMC Ultra/EtherEZ MCA IRQ number(s)");
102 101
102static const struct {
103 unsigned int base_addr;
104} addr_table[] = {
105 { 0x0800 },
106 { 0x1800 },
107 { 0x2800 },
108 { 0x3800 },
109 { 0x4800 },
110 { 0x5800 },
111 { 0x6800 },
112 { 0x7800 },
113 { 0x8800 },
114 { 0x9800 },
115 { 0xa800 },
116 { 0xb800 },
117 { 0xc800 },
118 { 0xd800 },
119 { 0xe800 },
120 { 0xf800 }
121};
122
123#define MEM_MASK 64
124
125static const struct {
126 unsigned char mem_index;
127 unsigned long mem_start;
128 unsigned char num_pages;
129} mem_table[] = {
130 { 16, 0x0c0000, 40 },
131 { 18, 0x0c4000, 40 },
132 { 20, 0x0c8000, 40 },
133 { 22, 0x0cc000, 40 },
134 { 24, 0x0d0000, 40 },
135 { 26, 0x0d4000, 40 },
136 { 28, 0x0d8000, 40 },
137 { 30, 0x0dc000, 40 },
138 {144, 0xfc0000, 40 },
139 {148, 0xfc8000, 40 },
140 {154, 0xfd0000, 40 },
141 {156, 0xfd8000, 40 },
142 { 0, 0x0c0000, 20 },
143 { 1, 0x0c2000, 20 },
144 { 2, 0x0c4000, 20 },
145 { 3, 0x0c6000, 20 }
146};
147
148#define IRQ_MASK 243
149static const struct {
150 unsigned char new_irq;
151 unsigned char old_irq;
152} irq_table[] = {
153 { 3, 3 },
154 { 4, 4 },
155 { 10, 10 },
156 { 14, 15 }
157};
158
103static short smc_mca_adapter_ids[] __initdata = { 159static short smc_mca_adapter_ids[] __initdata = {
104 0x61c8, 160 0x61c8,
105 0x61c9, 161 0x61c9,
@@ -126,7 +182,7 @@ static char *smc_mca_adapter_names[] __initdata = {
126 182
127static int ultra_found = 0; 183static int ultra_found = 0;
128 184
129int __init ultramca_probe(struct device *gen_dev) 185static int __init ultramca_probe(struct device *gen_dev)
130{ 186{
131 unsigned short ioaddr; 187 unsigned short ioaddr;
132 struct net_device *dev; 188 struct net_device *dev;
diff --git a/drivers/net/smc-mca.h b/drivers/net/smc-mca.h
deleted file mode 100644
index ac50117a7e84..000000000000
--- a/drivers/net/smc-mca.h
+++ /dev/null
@@ -1,61 +0,0 @@
1/*
2 * djweis weisd3458@uni.edu
3 * most of this file was taken from ps2esdi.h
4 */
5
6struct {
7 unsigned int base_addr;
8} addr_table[] = {
9 { 0x0800 },
10 { 0x1800 },
11 { 0x2800 },
12 { 0x3800 },
13 { 0x4800 },
14 { 0x5800 },
15 { 0x6800 },
16 { 0x7800 },
17 { 0x8800 },
18 { 0x9800 },
19 { 0xa800 },
20 { 0xb800 },
21 { 0xc800 },
22 { 0xd800 },
23 { 0xe800 },
24 { 0xf800 }
25};
26
27#define MEM_MASK 64
28
29struct {
30 unsigned char mem_index;
31 unsigned long mem_start;
32 unsigned char num_pages;
33} mem_table[] = {
34 { 16, 0x0c0000, 40 },
35 { 18, 0x0c4000, 40 },
36 { 20, 0x0c8000, 40 },
37 { 22, 0x0cc000, 40 },
38 { 24, 0x0d0000, 40 },
39 { 26, 0x0d4000, 40 },
40 { 28, 0x0d8000, 40 },
41 { 30, 0x0dc000, 40 },
42 {144, 0xfc0000, 40 },
43 {148, 0xfc8000, 40 },
44 {154, 0xfd0000, 40 },
45 {156, 0xfd8000, 40 },
46 { 0, 0x0c0000, 20 },
47 { 1, 0x0c2000, 20 },
48 { 2, 0x0c4000, 20 },
49 { 3, 0x0c6000, 20 }
50};
51
52#define IRQ_MASK 243
53struct {
54 unsigned char new_irq;
55 unsigned char old_irq;
56} irq_table[] = {
57 { 3, 3 },
58 { 4, 4 },
59 { 10, 10 },
60 { 14, 15 }
61};
diff --git a/drivers/net/smc-ultra.c b/drivers/net/smc-ultra.c
index b564c677c6d2..6d9dae60a697 100644
--- a/drivers/net/smc-ultra.c
+++ b/drivers/net/smc-ultra.c
@@ -194,12 +194,7 @@ struct net_device * __init ultra_probe(int unit)
194 err = do_ultra_probe(dev); 194 err = do_ultra_probe(dev);
195 if (err) 195 if (err)
196 goto out; 196 goto out;
197 err = register_netdev(dev);
198 if (err)
199 goto out1;
200 return dev; 197 return dev;
201out1:
202 cleanup_card(dev);
203out: 198out:
204 free_netdev(dev); 199 free_netdev(dev);
205 return ERR_PTR(err); 200 return ERR_PTR(err);
@@ -325,6 +320,9 @@ static int __init ultra_probe1(struct net_device *dev, int ioaddr)
325#endif 320#endif
326 NS8390_init(dev, 0); 321 NS8390_init(dev, 0);
327 322
323 retval = register_netdev(dev);
324 if (retval)
325 goto out;
328 return 0; 326 return 0;
329out: 327out:
330 release_region(ioaddr, ULTRA_IO_EXTENT); 328 release_region(ioaddr, ULTRA_IO_EXTENT);
@@ -583,11 +581,8 @@ init_module(void)
583 dev->irq = irq[this_dev]; 581 dev->irq = irq[this_dev];
584 dev->base_addr = io[this_dev]; 582 dev->base_addr = io[this_dev];
585 if (do_ultra_probe(dev) == 0) { 583 if (do_ultra_probe(dev) == 0) {
586 if (register_netdev(dev) == 0) { 584 dev_ultra[found++] = dev;
587 dev_ultra[found++] = dev; 585 continue;
588 continue;
589 }
590 cleanup_card(dev);
591 } 586 }
592 free_netdev(dev); 587 free_netdev(dev);
593 printk(KERN_WARNING "smc-ultra.c: No SMC Ultra card found (i/o = 0x%x).\n", io[this_dev]); 588 printk(KERN_WARNING "smc-ultra.c: No SMC Ultra card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/smc91x.c b/drivers/net/smc91x.c
index fd80048f7f7a..1438fdd20826 100644
--- a/drivers/net/smc91x.c
+++ b/drivers/net/smc91x.c
@@ -315,15 +315,25 @@ static void smc_reset(struct net_device *dev)
315 struct smc_local *lp = netdev_priv(dev); 315 struct smc_local *lp = netdev_priv(dev);
316 void __iomem *ioaddr = lp->base; 316 void __iomem *ioaddr = lp->base;
317 unsigned int ctl, cfg; 317 unsigned int ctl, cfg;
318 struct sk_buff *pending_skb;
318 319
319 DBG(2, "%s: %s\n", dev->name, __FUNCTION__); 320 DBG(2, "%s: %s\n", dev->name, __FUNCTION__);
320 321
321 /* Disable all interrupts */ 322 /* Disable all interrupts, block TX tasklet */
322 spin_lock(&lp->lock); 323 spin_lock(&lp->lock);
323 SMC_SELECT_BANK(2); 324 SMC_SELECT_BANK(2);
324 SMC_SET_INT_MASK(0); 325 SMC_SET_INT_MASK(0);
326 pending_skb = lp->pending_tx_skb;
327 lp->pending_tx_skb = NULL;
325 spin_unlock(&lp->lock); 328 spin_unlock(&lp->lock);
326 329
330 /* free any pending tx skb */
331 if (pending_skb) {
332 dev_kfree_skb(pending_skb);
333 lp->stats.tx_errors++;
334 lp->stats.tx_aborted_errors++;
335 }
336
327 /* 337 /*
328 * This resets the registers mostly to defaults, but doesn't 338 * This resets the registers mostly to defaults, but doesn't
329 * affect EEPROM. That seems unnecessary 339 * affect EEPROM. That seems unnecessary
@@ -389,14 +399,6 @@ static void smc_reset(struct net_device *dev)
389 SMC_SELECT_BANK(2); 399 SMC_SELECT_BANK(2);
390 SMC_SET_MMU_CMD(MC_RESET); 400 SMC_SET_MMU_CMD(MC_RESET);
391 SMC_WAIT_MMU_BUSY(); 401 SMC_WAIT_MMU_BUSY();
392
393 /* clear anything saved */
394 if (lp->pending_tx_skb != NULL) {
395 dev_kfree_skb (lp->pending_tx_skb);
396 lp->pending_tx_skb = NULL;
397 lp->stats.tx_errors++;
398 lp->stats.tx_aborted_errors++;
399 }
400} 402}
401 403
402/* 404/*
@@ -440,6 +442,7 @@ static void smc_shutdown(struct net_device *dev)
440{ 442{
441 struct smc_local *lp = netdev_priv(dev); 443 struct smc_local *lp = netdev_priv(dev);
442 void __iomem *ioaddr = lp->base; 444 void __iomem *ioaddr = lp->base;
445 struct sk_buff *pending_skb;
443 446
444 DBG(2, "%s: %s\n", CARDNAME, __FUNCTION__); 447 DBG(2, "%s: %s\n", CARDNAME, __FUNCTION__);
445 448
@@ -447,7 +450,11 @@ static void smc_shutdown(struct net_device *dev)
447 spin_lock(&lp->lock); 450 spin_lock(&lp->lock);
448 SMC_SELECT_BANK(2); 451 SMC_SELECT_BANK(2);
449 SMC_SET_INT_MASK(0); 452 SMC_SET_INT_MASK(0);
453 pending_skb = lp->pending_tx_skb;
454 lp->pending_tx_skb = NULL;
450 spin_unlock(&lp->lock); 455 spin_unlock(&lp->lock);
456 if (pending_skb)
457 dev_kfree_skb(pending_skb);
451 458
452 /* and tell the card to stay away from that nasty outside world */ 459 /* and tell the card to stay away from that nasty outside world */
453 SMC_SELECT_BANK(0); 460 SMC_SELECT_BANK(0);
@@ -627,7 +634,12 @@ static void smc_hardware_send_pkt(unsigned long data)
627 } 634 }
628 635
629 skb = lp->pending_tx_skb; 636 skb = lp->pending_tx_skb;
637 if (unlikely(!skb)) {
638 smc_special_unlock(&lp->lock);
639 return;
640 }
630 lp->pending_tx_skb = NULL; 641 lp->pending_tx_skb = NULL;
642
631 packet_no = SMC_GET_AR(); 643 packet_no = SMC_GET_AR();
632 if (unlikely(packet_no & AR_FAILED)) { 644 if (unlikely(packet_no & AR_FAILED)) {
633 printk("%s: Memory allocation failed.\n", dev->name); 645 printk("%s: Memory allocation failed.\n", dev->name);
@@ -702,7 +714,6 @@ static int smc_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
702 DBG(3, "%s: %s\n", dev->name, __FUNCTION__); 714 DBG(3, "%s: %s\n", dev->name, __FUNCTION__);
703 715
704 BUG_ON(lp->pending_tx_skb != NULL); 716 BUG_ON(lp->pending_tx_skb != NULL);
705 lp->pending_tx_skb = skb;
706 717
707 /* 718 /*
708 * The MMU wants the number of pages to be the number of 256 bytes 719 * The MMU wants the number of pages to be the number of 256 bytes
@@ -718,7 +729,6 @@ static int smc_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
718 numPages = ((skb->len & ~1) + (6 - 1)) >> 8; 729 numPages = ((skb->len & ~1) + (6 - 1)) >> 8;
719 if (unlikely(numPages > 7)) { 730 if (unlikely(numPages > 7)) {
720 printk("%s: Far too big packet error.\n", dev->name); 731 printk("%s: Far too big packet error.\n", dev->name);
721 lp->pending_tx_skb = NULL;
722 lp->stats.tx_errors++; 732 lp->stats.tx_errors++;
723 lp->stats.tx_dropped++; 733 lp->stats.tx_dropped++;
724 dev_kfree_skb(skb); 734 dev_kfree_skb(skb);
@@ -745,6 +755,7 @@ static int smc_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
745 755
746 smc_special_unlock(&lp->lock); 756 smc_special_unlock(&lp->lock);
747 757
758 lp->pending_tx_skb = skb;
748 if (!poll_count) { 759 if (!poll_count) {
749 /* oh well, wait until the chip finds memory later */ 760 /* oh well, wait until the chip finds memory later */
750 netif_stop_queue(dev); 761 netif_stop_queue(dev);
@@ -1062,7 +1073,7 @@ static void smc_phy_powerdown(struct net_device *dev)
1062 above). linkwatch_event() also wants the netlink semaphore. 1073 above). linkwatch_event() also wants the netlink semaphore.
1063 */ 1074 */
1064 while(lp->work_pending) 1075 while(lp->work_pending)
1065 schedule(); 1076 yield();
1066 1077
1067 bmcr = smc_phy_read(dev, phy, MII_BMCR); 1078 bmcr = smc_phy_read(dev, phy, MII_BMCR);
1068 smc_phy_write(dev, phy, MII_BMCR, bmcr | BMCR_PDOWN); 1079 smc_phy_write(dev, phy, MII_BMCR, bmcr | BMCR_PDOWN);
@@ -1606,14 +1617,8 @@ static int smc_close(struct net_device *dev)
1606 1617
1607 /* clear everything */ 1618 /* clear everything */
1608 smc_shutdown(dev); 1619 smc_shutdown(dev);
1609 1620 tasklet_kill(&lp->tx_task);
1610 smc_phy_powerdown(dev); 1621 smc_phy_powerdown(dev);
1611
1612 if (lp->pending_tx_skb) {
1613 dev_kfree_skb(lp->pending_tx_skb);
1614 lp->pending_tx_skb = NULL;
1615 }
1616
1617 return 0; 1622 return 0;
1618} 1623}
1619 1624
@@ -1993,7 +1998,7 @@ static int __init smc_probe(struct net_device *dev, void __iomem *ioaddr)
1993 if (retval) 1998 if (retval)
1994 goto err_out; 1999 goto err_out;
1995 2000
1996 set_irq_type(dev->irq, IRQT_RISING); 2001 set_irq_type(dev->irq, SMC_IRQ_TRIGGER_TYPE);
1997 2002
1998#ifdef SMC_USE_PXA_DMA 2003#ifdef SMC_USE_PXA_DMA
1999 { 2004 {
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index 946528e6b742..7089d86e857a 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -182,6 +182,16 @@ SMC_outw(u16 val, void __iomem *ioaddr, int reg)
182#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l) 182#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
183#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l) 183#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
184 184
185#include <asm/mach-types.h>
186#include <asm/arch/cpu.h>
187
188#define SMC_IRQ_TRIGGER_TYPE (( \
189 machine_is_omap_h2() \
190 || machine_is_omap_h3() \
191 || (machine_is_omap_innovator() && !cpu_is_omap150()) \
192 ) ? IRQT_FALLING : IRQT_RISING)
193
194
185#elif defined(CONFIG_SH_SH4202_MICRODEV) 195#elif defined(CONFIG_SH_SH4202_MICRODEV)
186 196
187#define SMC_CAN_USE_8BIT 0 197#define SMC_CAN_USE_8BIT 0
@@ -300,6 +310,9 @@ static inline void SMC_outsw (unsigned long a, int r, unsigned char* p, int l)
300 310
301#endif 311#endif
302 312
313#ifndef SMC_IRQ_TRIGGER_TYPE
314#define SMC_IRQ_TRIGGER_TYPE IRQT_RISING
315#endif
303 316
304#ifdef SMC_USE_PXA_DMA 317#ifdef SMC_USE_PXA_DMA
305/* 318/*
diff --git a/drivers/net/starfire.c b/drivers/net/starfire.c
index 12e2b6826fa3..88b89dc95c77 100644
--- a/drivers/net/starfire.c
+++ b/drivers/net/starfire.c
@@ -1286,7 +1286,7 @@ static void init_ring(struct net_device *dev)
1286 np->rx_info[i].skb = skb; 1286 np->rx_info[i].skb = skb;
1287 if (skb == NULL) 1287 if (skb == NULL)
1288 break; 1288 break;
1289 np->rx_info[i].mapping = pci_map_single(np->pci_dev, skb->tail, np->rx_buf_sz, PCI_DMA_FROMDEVICE); 1289 np->rx_info[i].mapping = pci_map_single(np->pci_dev, skb->data, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1290 skb->dev = dev; /* Mark as being used by this device. */ 1290 skb->dev = dev; /* Mark as being used by this device. */
1291 /* Grrr, we cannot offset to correctly align the IP header. */ 1291 /* Grrr, we cannot offset to correctly align the IP header. */
1292 np->rx_ring[i].rxaddr = cpu_to_dma(np->rx_info[i].mapping | RxDescValid); 1292 np->rx_ring[i].rxaddr = cpu_to_dma(np->rx_info[i].mapping | RxDescValid);
@@ -1572,7 +1572,7 @@ static int __netdev_rx(struct net_device *dev, int *quota)
1572 pci_dma_sync_single_for_cpu(np->pci_dev, 1572 pci_dma_sync_single_for_cpu(np->pci_dev,
1573 np->rx_info[entry].mapping, 1573 np->rx_info[entry].mapping,
1574 pkt_len, PCI_DMA_FROMDEVICE); 1574 pkt_len, PCI_DMA_FROMDEVICE);
1575 eth_copy_and_sum(skb, np->rx_info[entry].skb->tail, pkt_len, 0); 1575 eth_copy_and_sum(skb, np->rx_info[entry].skb->data, pkt_len, 0);
1576 pci_dma_sync_single_for_device(np->pci_dev, 1576 pci_dma_sync_single_for_device(np->pci_dev,
1577 np->rx_info[entry].mapping, 1577 np->rx_info[entry].mapping,
1578 pkt_len, PCI_DMA_FROMDEVICE); 1578 pkt_len, PCI_DMA_FROMDEVICE);
@@ -1696,7 +1696,7 @@ static void refill_rx_ring(struct net_device *dev)
1696 if (skb == NULL) 1696 if (skb == NULL)
1697 break; /* Better luck next round. */ 1697 break; /* Better luck next round. */
1698 np->rx_info[entry].mapping = 1698 np->rx_info[entry].mapping =
1699 pci_map_single(np->pci_dev, skb->tail, np->rx_buf_sz, PCI_DMA_FROMDEVICE); 1699 pci_map_single(np->pci_dev, skb->data, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1700 skb->dev = dev; /* Mark as being used by this device. */ 1700 skb->dev = dev; /* Mark as being used by this device. */
1701 np->rx_ring[entry].rxaddr = 1701 np->rx_ring[entry].rxaddr =
1702 cpu_to_dma(np->rx_info[entry].mapping | RxDescValid); 1702 cpu_to_dma(np->rx_info[entry].mapping | RxDescValid);
diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
index 08cb7177a175..d500a5771dbc 100644
--- a/drivers/net/sundance.c
+++ b/drivers/net/sundance.c
@@ -1028,7 +1028,7 @@ static void init_ring(struct net_device *dev)
1028 skb->dev = dev; /* Mark as being used by this device. */ 1028 skb->dev = dev; /* Mark as being used by this device. */
1029 skb_reserve(skb, 2); /* 16 byte align the IP header. */ 1029 skb_reserve(skb, 2); /* 16 byte align the IP header. */
1030 np->rx_ring[i].frag[0].addr = cpu_to_le32( 1030 np->rx_ring[i].frag[0].addr = cpu_to_le32(
1031 pci_map_single(np->pci_dev, skb->tail, np->rx_buf_sz, 1031 pci_map_single(np->pci_dev, skb->data, np->rx_buf_sz,
1032 PCI_DMA_FROMDEVICE)); 1032 PCI_DMA_FROMDEVICE));
1033 np->rx_ring[i].frag[0].length = cpu_to_le32(np->rx_buf_sz | LastFrag); 1033 np->rx_ring[i].frag[0].length = cpu_to_le32(np->rx_buf_sz | LastFrag);
1034 } 1034 }
@@ -1341,7 +1341,7 @@ static void rx_poll(unsigned long data)
1341 np->rx_buf_sz, 1341 np->rx_buf_sz,
1342 PCI_DMA_FROMDEVICE); 1342 PCI_DMA_FROMDEVICE);
1343 1343
1344 eth_copy_and_sum(skb, np->rx_skbuff[entry]->tail, pkt_len, 0); 1344 eth_copy_and_sum(skb, np->rx_skbuff[entry]->data, pkt_len, 0);
1345 pci_dma_sync_single_for_device(np->pci_dev, 1345 pci_dma_sync_single_for_device(np->pci_dev,
1346 desc->frag[0].addr, 1346 desc->frag[0].addr,
1347 np->rx_buf_sz, 1347 np->rx_buf_sz,
@@ -1400,7 +1400,7 @@ static void refill_rx (struct net_device *dev)
1400 skb->dev = dev; /* Mark as being used by this device. */ 1400 skb->dev = dev; /* Mark as being used by this device. */
1401 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 1401 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1402 np->rx_ring[entry].frag[0].addr = cpu_to_le32( 1402 np->rx_ring[entry].frag[0].addr = cpu_to_le32(
1403 pci_map_single(np->pci_dev, skb->tail, 1403 pci_map_single(np->pci_dev, skb->data,
1404 np->rx_buf_sz, PCI_DMA_FROMDEVICE)); 1404 np->rx_buf_sz, PCI_DMA_FROMDEVICE));
1405 } 1405 }
1406 /* Perhaps we need not reset this field. */ 1406 /* Perhaps we need not reset this field. */
diff --git a/drivers/net/sungem.c b/drivers/net/sungem.c
index 5cd50fd53c12..1f5655655c40 100644
--- a/drivers/net/sungem.c
+++ b/drivers/net/sungem.c
@@ -44,6 +44,7 @@
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/errno.h> 45#include <linux/errno.h>
46#include <linux/pci.h> 46#include <linux/pci.h>
47#include <linux/dma-mapping.h>
47#include <linux/netdevice.h> 48#include <linux/netdevice.h>
48#include <linux/etherdevice.h> 49#include <linux/etherdevice.h>
49#include <linux/skbuff.h> 50#include <linux/skbuff.h>
@@ -2989,10 +2990,10 @@ static int __devinit gem_init_one(struct pci_dev *pdev,
2989 */ 2990 */
2990 if (pdev->vendor == PCI_VENDOR_ID_SUN && 2991 if (pdev->vendor == PCI_VENDOR_ID_SUN &&
2991 pdev->device == PCI_DEVICE_ID_SUN_GEM && 2992 pdev->device == PCI_DEVICE_ID_SUN_GEM &&
2992 !pci_set_dma_mask(pdev, (u64) 0xffffffffffffffffULL)) { 2993 !pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
2993 pci_using_dac = 1; 2994 pci_using_dac = 1;
2994 } else { 2995 } else {
2995 err = pci_set_dma_mask(pdev, (u64) 0xffffffff); 2996 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
2996 if (err) { 2997 if (err) {
2997 printk(KERN_ERR PFX "No usable DMA configuration, " 2998 printk(KERN_ERR PFX "No usable DMA configuration, "
2998 "aborting.\n"); 2999 "aborting.\n");
diff --git a/drivers/net/tlan.c b/drivers/net/tlan.c
index cf31c0629852..942fae0f2130 100644
--- a/drivers/net/tlan.c
+++ b/drivers/net/tlan.c
@@ -171,6 +171,7 @@
171#include <linux/ioport.h> 171#include <linux/ioport.h>
172#include <linux/eisa.h> 172#include <linux/eisa.h>
173#include <linux/pci.h> 173#include <linux/pci.h>
174#include <linux/dma-mapping.h>
174#include <linux/netdevice.h> 175#include <linux/netdevice.h>
175#include <linux/etherdevice.h> 176#include <linux/etherdevice.h>
176#include <linux/delay.h> 177#include <linux/delay.h>
@@ -566,7 +567,7 @@ static int __devinit TLan_probe1(struct pci_dev *pdev,
566 567
567 priv->adapter = &board_info[ent->driver_data]; 568 priv->adapter = &board_info[ent->driver_data];
568 569
569 rc = pci_set_dma_mask(pdev, 0xFFFFFFFF); 570 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
570 if (rc) { 571 if (rc) {
571 printk(KERN_ERR "TLAN: No suitable PCI mapping available.\n"); 572 printk(KERN_ERR "TLAN: No suitable PCI mapping available.\n");
572 goto err_out_free_dev; 573 goto err_out_free_dev;
diff --git a/drivers/net/tokenring/3c359.c b/drivers/net/tokenring/3c359.c
index 0d1dcf421771..41e0cd8f4786 100644
--- a/drivers/net/tokenring/3c359.c
+++ b/drivers/net/tokenring/3c359.c
@@ -276,7 +276,8 @@ static void xl_ee_write(struct net_device *dev, int ee_addr, u16 ee_value)
276 return ; 276 return ;
277} 277}
278 278
279int __devinit xl_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 279static int __devinit xl_probe(struct pci_dev *pdev,
280 const struct pci_device_id *ent)
280{ 281{
281 struct net_device *dev ; 282 struct net_device *dev ;
282 struct xl_private *xl_priv ; 283 struct xl_private *xl_priv ;
diff --git a/drivers/net/tokenring/3c359_microcode.h b/drivers/net/tokenring/3c359_microcode.h
index 81354afa3d34..0400c029c077 100644
--- a/drivers/net/tokenring/3c359_microcode.h
+++ b/drivers/net/tokenring/3c359_microcode.h
@@ -22,7 +22,7 @@
22 22
23static int mc_size = 24880 ; 23static int mc_size = 24880 ;
24 24
25u8 microcode[] = { 25static const u8 microcode[] = {
26 0xfe,0x3a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 26 0xfe,0x3a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
27,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 27,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
index bd4a2bccf867..87103c400999 100644
--- a/drivers/net/tokenring/abyss.c
+++ b/drivers/net/tokenring/abyss.c
@@ -468,14 +468,3 @@ static void __exit abyss_rmmod (void)
468module_init(abyss_init); 468module_init(abyss_init);
469module_exit(abyss_rmmod); 469module_exit(abyss_rmmod);
470 470
471
472/*
473 * Local variables:
474 * compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c abyss.c"
475 * alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c abyss.c"
476 * c-set-style "K&R"
477 * c-indent-level: 8
478 * c-basic-offset: 8
479 * tab-width: 8
480 * End:
481 */
diff --git a/drivers/net/tokenring/ibmtr.c b/drivers/net/tokenring/ibmtr.c
index 3873917a9c22..e7b001017b9a 100644
--- a/drivers/net/tokenring/ibmtr.c
+++ b/drivers/net/tokenring/ibmtr.c
@@ -151,7 +151,7 @@ static char version[] __initdata =
151 151
152/* this allows displaying full adapter information */ 152/* this allows displaying full adapter information */
153 153
154char *channel_def[] __devinitdata = { "ISA", "MCA", "ISA P&P" }; 154static char *channel_def[] __devinitdata = { "ISA", "MCA", "ISA P&P" };
155 155
156static char pcchannelid[] __devinitdata = { 156static char pcchannelid[] __devinitdata = {
157 0x05, 0x00, 0x04, 0x09, 157 0x05, 0x00, 0x04, 0x09,
@@ -171,7 +171,7 @@ static char mcchannelid[] __devinitdata = {
171 0x03, 0x08, 0x02, 0x00 171 0x03, 0x08, 0x02, 0x00
172}; 172};
173 173
174char __devinit *adapter_def(char type) 174static char __devinit *adapter_def(char type)
175{ 175{
176 switch (type) { 176 switch (type) {
177 case 0xF: return "PC Adapter | PC Adapter II | Adapter/A"; 177 case 0xF: return "PC Adapter | PC Adapter II | Adapter/A";
@@ -184,7 +184,7 @@ char __devinit *adapter_def(char type)
184 184
185#define TRC_INIT 0x01 /* Trace initialization & PROBEs */ 185#define TRC_INIT 0x01 /* Trace initialization & PROBEs */
186#define TRC_INITV 0x02 /* verbose init trace points */ 186#define TRC_INITV 0x02 /* verbose init trace points */
187unsigned char ibmtr_debug_trace = 0; 187static unsigned char ibmtr_debug_trace = 0;
188 188
189static int ibmtr_probe(struct net_device *dev); 189static int ibmtr_probe(struct net_device *dev);
190static int ibmtr_probe1(struct net_device *dev, int ioaddr); 190static int ibmtr_probe1(struct net_device *dev, int ioaddr);
@@ -192,20 +192,20 @@ static unsigned char get_sram_size(struct tok_info *adapt_info);
192static int trdev_init(struct net_device *dev); 192static int trdev_init(struct net_device *dev);
193static int tok_open(struct net_device *dev); 193static int tok_open(struct net_device *dev);
194static int tok_init_card(struct net_device *dev); 194static int tok_init_card(struct net_device *dev);
195void tok_open_adapter(unsigned long dev_addr); 195static void tok_open_adapter(unsigned long dev_addr);
196static void open_sap(unsigned char type, struct net_device *dev); 196static void open_sap(unsigned char type, struct net_device *dev);
197static void tok_set_multicast_list(struct net_device *dev); 197static void tok_set_multicast_list(struct net_device *dev);
198static int tok_send_packet(struct sk_buff *skb, struct net_device *dev); 198static int tok_send_packet(struct sk_buff *skb, struct net_device *dev);
199static int tok_close(struct net_device *dev); 199static int tok_close(struct net_device *dev);
200irqreturn_t tok_interrupt(int irq, void *dev_id, struct pt_regs *regs); 200static irqreturn_t tok_interrupt(int irq, void *dev_id, struct pt_regs *regs);
201static void initial_tok_int(struct net_device *dev); 201static void initial_tok_int(struct net_device *dev);
202static void tr_tx(struct net_device *dev); 202static void tr_tx(struct net_device *dev);
203static void tr_rx(struct net_device *dev); 203static void tr_rx(struct net_device *dev);
204void ibmtr_reset_timer(struct timer_list*tmr,struct net_device *dev); 204static void ibmtr_reset_timer(struct timer_list*tmr,struct net_device *dev);
205static void tok_rerun(unsigned long dev_addr); 205static void tok_rerun(unsigned long dev_addr);
206void ibmtr_readlog(struct net_device *dev); 206static void ibmtr_readlog(struct net_device *dev);
207static struct net_device_stats *tok_get_stats(struct net_device *dev); 207static struct net_device_stats *tok_get_stats(struct net_device *dev);
208int ibmtr_change_mtu(struct net_device *dev, int mtu); 208static int ibmtr_change_mtu(struct net_device *dev, int mtu);
209static void find_turbo_adapters(int *iolist); 209static void find_turbo_adapters(int *iolist);
210 210
211static int ibmtr_portlist[IBMTR_MAX_ADAPTERS+1] __devinitdata = { 211static int ibmtr_portlist[IBMTR_MAX_ADAPTERS+1] __devinitdata = {
@@ -928,7 +928,7 @@ static int tok_open(struct net_device *dev)
928#define DLC_MAX_SAP_OFST 32 928#define DLC_MAX_SAP_OFST 32
929#define DLC_MAX_STA_OFST 33 929#define DLC_MAX_STA_OFST 33
930 930
931void tok_open_adapter(unsigned long dev_addr) 931static void tok_open_adapter(unsigned long dev_addr)
932{ 932{
933 struct net_device *dev = (struct net_device *) dev_addr; 933 struct net_device *dev = (struct net_device *) dev_addr;
934 struct tok_info *ti; 934 struct tok_info *ti;
@@ -1099,7 +1099,7 @@ static void __iomem *map_address(struct tok_info *ti, unsigned index, __u8 *page
1099 return ti->sram_virt + index; 1099 return ti->sram_virt + index;
1100} 1100}
1101 1101
1102void dir_open_adapter (struct net_device *dev) 1102static void dir_open_adapter (struct net_device *dev)
1103{ 1103{
1104 struct tok_info *ti = (struct tok_info *) dev->priv; 1104 struct tok_info *ti = (struct tok_info *) dev->priv;
1105 unsigned char ret_code; 1105 unsigned char ret_code;
@@ -1172,7 +1172,7 @@ void dir_open_adapter (struct net_device *dev)
1172 1172
1173/******************************************************************************/ 1173/******************************************************************************/
1174 1174
1175irqreturn_t tok_interrupt(int irq, void *dev_id, struct pt_regs *regs) 1175static irqreturn_t tok_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1176{ 1176{
1177 unsigned char status; 1177 unsigned char status;
1178 /* unsigned char status_even ; */ 1178 /* unsigned char status_even ; */
@@ -1840,7 +1840,7 @@ static void tr_rx(struct net_device *dev)
1840 1840
1841/*****************************************************************************/ 1841/*****************************************************************************/
1842 1842
1843void ibmtr_reset_timer(struct timer_list *tmr, struct net_device *dev) 1843static void ibmtr_reset_timer(struct timer_list *tmr, struct net_device *dev)
1844{ 1844{
1845 tmr->expires = jiffies + TR_RETRY_INTERVAL; 1845 tmr->expires = jiffies + TR_RETRY_INTERVAL;
1846 tmr->data = (unsigned long) dev; 1846 tmr->data = (unsigned long) dev;
@@ -1872,7 +1872,7 @@ void tok_rerun(unsigned long dev_addr){
1872 1872
1873/*****************************************************************************/ 1873/*****************************************************************************/
1874 1874
1875void ibmtr_readlog(struct net_device *dev) 1875static void ibmtr_readlog(struct net_device *dev)
1876{ 1876{
1877 struct tok_info *ti; 1877 struct tok_info *ti;
1878 1878
@@ -1905,7 +1905,7 @@ static struct net_device_stats *tok_get_stats(struct net_device *dev)
1905 1905
1906/*****************************************************************************/ 1906/*****************************************************************************/
1907 1907
1908int ibmtr_change_mtu(struct net_device *dev, int mtu) 1908static int ibmtr_change_mtu(struct net_device *dev, int mtu)
1909{ 1909{
1910 struct tok_info *ti = (struct tok_info *) dev->priv; 1910 struct tok_info *ti = (struct tok_info *) dev->priv;
1911 1911
diff --git a/drivers/net/tokenring/lanstreamer.c b/drivers/net/tokenring/lanstreamer.c
index 99e0b03b69a8..97712c3c4e07 100644
--- a/drivers/net/tokenring/lanstreamer.c
+++ b/drivers/net/tokenring/lanstreamer.c
@@ -118,6 +118,7 @@
118#include <linux/stddef.h> 118#include <linux/stddef.h>
119#include <linux/init.h> 119#include <linux/init.h>
120#include <linux/pci.h> 120#include <linux/pci.h>
121#include <linux/dma-mapping.h>
121#include <linux/spinlock.h> 122#include <linux/spinlock.h>
122#include <linux/version.h> 123#include <linux/version.h>
123#include <linux/bitops.h> 124#include <linux/bitops.h>
@@ -257,7 +258,7 @@ static int __devinit streamer_init_one(struct pci_dev *pdev,
257#endif 258#endif
258#endif 259#endif
259 260
260 rc = pci_set_dma_mask(pdev, 0xFFFFFFFFULL); 261 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
261 if (rc) { 262 if (rc) {
262 printk(KERN_ERR "%s: No suitable PCI mapping available.\n", 263 printk(KERN_ERR "%s: No suitable PCI mapping available.\n",
263 dev->name); 264 dev->name);
@@ -454,8 +455,7 @@ static int streamer_reset(struct net_device *dev)
454 writew(readw(streamer_mmio + BCTL) | BCTL_SOFTRESET, streamer_mmio + BCTL); 455 writew(readw(streamer_mmio + BCTL) | BCTL_SOFTRESET, streamer_mmio + BCTL);
455 t = jiffies; 456 t = jiffies;
456 /* Hold soft reset bit for a while */ 457 /* Hold soft reset bit for a while */
457 current->state = TASK_UNINTERRUPTIBLE; 458 ssleep(1);
458 schedule_timeout(HZ);
459 459
460 writew(readw(streamer_mmio + BCTL) & ~BCTL_SOFTRESET, 460 writew(readw(streamer_mmio + BCTL) & ~BCTL_SOFTRESET,
461 streamer_mmio + BCTL); 461 streamer_mmio + BCTL);
@@ -511,8 +511,7 @@ static int streamer_reset(struct net_device *dev)
511 writew(SISR_MI, streamer_mmio + SISR_MASK_SUM); 511 writew(SISR_MI, streamer_mmio + SISR_MASK_SUM);
512 512
513 while (!((readw(streamer_mmio + SISR)) & SISR_SRB_REPLY)) { 513 while (!((readw(streamer_mmio + SISR)) & SISR_SRB_REPLY)) {
514 current->state = TASK_INTERRUPTIBLE; 514 msleep_interruptible(100);
515 schedule_timeout(HZ/10);
516 if (jiffies - t > 40 * HZ) { 515 if (jiffies - t > 40 * HZ) {
517 printk(KERN_ERR 516 printk(KERN_ERR
518 "IBM PCI tokenring card not responding\n"); 517 "IBM PCI tokenring card not responding\n");
diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
index cfae2bbf2167..659cbdbef7f3 100644
--- a/drivers/net/tokenring/madgemc.c
+++ b/drivers/net/tokenring/madgemc.c
@@ -625,7 +625,7 @@ static int madgemc_chipset_init(struct net_device *dev)
625/* 625/*
626 * Disable the board, and put back into power-up state. 626 * Disable the board, and put back into power-up state.
627 */ 627 */
628void madgemc_chipset_close(struct net_device *dev) 628static void madgemc_chipset_close(struct net_device *dev)
629{ 629{
630 /* disable interrupts */ 630 /* disable interrupts */
631 madgemc_setint(dev, 0); 631 madgemc_setint(dev, 0);
@@ -786,15 +786,3 @@ module_exit(madgemc_exit);
786 786
787MODULE_LICENSE("GPL"); 787MODULE_LICENSE("GPL");
788 788
789
790/*
791 * Local variables:
792 * compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c madgemc.c"
793 * alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c madgemc.c"
794 * c-set-style "K&R"
795 * c-indent-level: 8
796 * c-basic-offset: 8
797 * tab-width: 8
798 * End:
799 */
800
diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
index 675b063508e3..40ad0fde28af 100644
--- a/drivers/net/tokenring/proteon.c
+++ b/drivers/net/tokenring/proteon.c
@@ -419,14 +419,3 @@ void cleanup_module(void)
419} 419}
420#endif /* MODULE */ 420#endif /* MODULE */
421 421
422
423/*
424 * Local variables:
425 * compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c proteon.c"
426 * alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c proteon.c"
427 * c-set-style "K&R"
428 * c-indent-level: 8
429 * c-basic-offset: 8
430 * tab-width: 8
431 * End:
432 */
diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
index 3fab54a26466..f26796e2d0e5 100644
--- a/drivers/net/tokenring/skisa.c
+++ b/drivers/net/tokenring/skisa.c
@@ -429,14 +429,3 @@ void cleanup_module(void)
429} 429}
430#endif /* MODULE */ 430#endif /* MODULE */
431 431
432
433/*
434 * Local variables:
435 * compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c skisa.c"
436 * alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c skisa.c"
437 * c-set-style "K&R"
438 * c-indent-level: 8
439 * c-basic-offset: 8
440 * tab-width: 8
441 * End:
442 */
diff --git a/drivers/net/tokenring/smctr.c b/drivers/net/tokenring/smctr.c
index 5c8aeacb8318..67d2b596ce22 100644
--- a/drivers/net/tokenring/smctr.c
+++ b/drivers/net/tokenring/smctr.c
@@ -77,7 +77,7 @@ static int ringspeed;
77 77
78/* SMC Name of the Adapter. */ 78/* SMC Name of the Adapter. */
79static char smctr_name[] = "SMC TokenCard"; 79static char smctr_name[] = "SMC TokenCard";
80char *smctr_model = "Unknown"; 80static char *smctr_model = "Unknown";
81 81
82/* Use 0 for production, 1 for verification, 2 for debug, and 82/* Use 0 for production, 1 for verification, 2 for debug, and
83 * 3 for very verbose debug. 83 * 3 for very verbose debug.
diff --git a/drivers/net/tokenring/smctr_firmware.h b/drivers/net/tokenring/smctr_firmware.h
index 53f2cbc817c9..48994b043b7c 100644
--- a/drivers/net/tokenring/smctr_firmware.h
+++ b/drivers/net/tokenring/smctr_firmware.h
@@ -21,7 +21,7 @@
21 21
22#if defined(CONFIG_SMCTR) || defined(CONFIG_SMCTR_MODULE) 22#if defined(CONFIG_SMCTR) || defined(CONFIG_SMCTR_MODULE)
23 23
24unsigned char smctr_code[] = { 24static const unsigned char smctr_code[] = {
25 0x0BC, 0x01D, 0x012, 0x03B, 0x063, 0x0B4, 0x0E9, 0x000, 25 0x0BC, 0x01D, 0x012, 0x03B, 0x063, 0x0B4, 0x0E9, 0x000,
26 0x000, 0x01F, 0x000, 0x001, 0x001, 0x000, 0x002, 0x005, 26 0x000, 0x01F, 0x000, 0x001, 0x001, 0x000, 0x002, 0x005,
27 0x001, 0x000, 0x006, 0x003, 0x001, 0x000, 0x004, 0x009, 27 0x001, 0x000, 0x006, 0x003, 0x001, 0x000, 0x004, 0x009,
diff --git a/drivers/net/tokenring/tms380tr.c b/drivers/net/tokenring/tms380tr.c
index df43b449e429..5e0b0ce98ed7 100644
--- a/drivers/net/tokenring/tms380tr.c
+++ b/drivers/net/tokenring/tms380tr.c
@@ -2379,7 +2379,7 @@ EXPORT_SYMBOL(tmsdev_init);
2379EXPORT_SYMBOL(tmsdev_term); 2379EXPORT_SYMBOL(tmsdev_term);
2380EXPORT_SYMBOL(tms380tr_wait); 2380EXPORT_SYMBOL(tms380tr_wait);
2381 2381
2382struct module *TMS380_module = NULL; 2382static struct module *TMS380_module = NULL;
2383 2383
2384int init_module(void) 2384int init_module(void)
2385{ 2385{
@@ -2397,14 +2397,3 @@ void cleanup_module(void)
2397 2397
2398MODULE_LICENSE("GPL"); 2398MODULE_LICENSE("GPL");
2399 2399
2400
2401/*
2402 * Local variables:
2403 * compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c tms380tr.c"
2404 * alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c tms380tr.c"
2405 * c-set-style "K&R"
2406 * c-indent-level: 8
2407 * c-basic-offset: 8
2408 * tab-width: 8
2409 * End:
2410 */
diff --git a/drivers/net/tokenring/tmspci.c b/drivers/net/tokenring/tmspci.c
index 37ddb5c2bec3..2e18c0a46482 100644
--- a/drivers/net/tokenring/tmspci.c
+++ b/drivers/net/tokenring/tmspci.c
@@ -254,14 +254,3 @@ static void __exit tms_pci_rmmod (void)
254module_init(tms_pci_init); 254module_init(tms_pci_init);
255module_exit(tms_pci_rmmod); 255module_exit(tms_pci_rmmod);
256 256
257
258/*
259 * Local variables:
260 * compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c tmspci.c"
261 * alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c tmspci.c"
262 * c-set-style "K&R"
263 * c-indent-level: 8
264 * c-basic-offset: 8
265 * tab-width: 8
266 * End:
267 */
diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
index dd357dd8c370..fc353e348f9a 100644
--- a/drivers/net/tulip/de2104x.c
+++ b/drivers/net/tulip/de2104x.c
@@ -446,13 +446,13 @@ static void de_rx (struct de_private *de)
446 446
447 mapping = 447 mapping =
448 de->rx_skb[rx_tail].mapping = 448 de->rx_skb[rx_tail].mapping =
449 pci_map_single(de->pdev, copy_skb->tail, 449 pci_map_single(de->pdev, copy_skb->data,
450 buflen, PCI_DMA_FROMDEVICE); 450 buflen, PCI_DMA_FROMDEVICE);
451 de->rx_skb[rx_tail].skb = copy_skb; 451 de->rx_skb[rx_tail].skb = copy_skb;
452 } else { 452 } else {
453 pci_dma_sync_single_for_cpu(de->pdev, mapping, len, PCI_DMA_FROMDEVICE); 453 pci_dma_sync_single_for_cpu(de->pdev, mapping, len, PCI_DMA_FROMDEVICE);
454 skb_reserve(copy_skb, RX_OFFSET); 454 skb_reserve(copy_skb, RX_OFFSET);
455 memcpy(skb_put(copy_skb, len), skb->tail, len); 455 memcpy(skb_put(copy_skb, len), skb->data, len);
456 456
457 pci_dma_sync_single_for_device(de->pdev, mapping, len, PCI_DMA_FROMDEVICE); 457 pci_dma_sync_single_for_device(de->pdev, mapping, len, PCI_DMA_FROMDEVICE);
458 458
@@ -1269,7 +1269,7 @@ static int de_refill_rx (struct de_private *de)
1269 skb->dev = de->dev; 1269 skb->dev = de->dev;
1270 1270
1271 de->rx_skb[i].mapping = pci_map_single(de->pdev, 1271 de->rx_skb[i].mapping = pci_map_single(de->pdev,
1272 skb->tail, de->rx_buf_sz, PCI_DMA_FROMDEVICE); 1272 skb->data, de->rx_buf_sz, PCI_DMA_FROMDEVICE);
1273 de->rx_skb[i].skb = skb; 1273 de->rx_skb[i].skb = skb;
1274 1274
1275 de->rx_ring[i].opts1 = cpu_to_le32(DescOwn); 1275 de->rx_ring[i].opts1 = cpu_to_le32(DescOwn);
diff --git a/drivers/net/tulip/dmfe.c b/drivers/net/tulip/dmfe.c
index e25f33df223e..74e9075d9c48 100644
--- a/drivers/net/tulip/dmfe.c
+++ b/drivers/net/tulip/dmfe.c
@@ -78,6 +78,7 @@
78#include <linux/slab.h> 78#include <linux/slab.h>
79#include <linux/interrupt.h> 79#include <linux/interrupt.h>
80#include <linux/pci.h> 80#include <linux/pci.h>
81#include <linux/dma-mapping.h>
81#include <linux/init.h> 82#include <linux/init.h>
82#include <linux/netdevice.h> 83#include <linux/netdevice.h>
83#include <linux/etherdevice.h> 84#include <linux/etherdevice.h>
@@ -354,7 +355,7 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
354 SET_MODULE_OWNER(dev); 355 SET_MODULE_OWNER(dev);
355 SET_NETDEV_DEV(dev, &pdev->dev); 356 SET_NETDEV_DEV(dev, &pdev->dev);
356 357
357 if (pci_set_dma_mask(pdev, 0xffffffff)) { 358 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
358 printk(KERN_WARNING DRV_NAME ": 32-bit PCI DMA not available.\n"); 359 printk(KERN_WARNING DRV_NAME ": 32-bit PCI DMA not available.\n");
359 err = -ENODEV; 360 err = -ENODEV;
360 goto err_out_free; 361 goto err_out_free;
@@ -743,11 +744,6 @@ static irqreturn_t dmfe_interrupt(int irq, void *dev_id, struct pt_regs *regs)
743 744
744 DMFE_DBUG(0, "dmfe_interrupt()", 0); 745 DMFE_DBUG(0, "dmfe_interrupt()", 0);
745 746
746 if (!dev) {
747 DMFE_DBUG(1, "dmfe_interrupt() without DEVICE arg", 0);
748 return IRQ_NONE;
749 }
750
751 spin_lock_irqsave(&db->lock, flags); 747 spin_lock_irqsave(&db->lock, flags);
752 748
753 /* Got DM910X status */ 749 /* Got DM910X status */
@@ -949,8 +945,8 @@ static void dmfe_rx_packet(struct DEVICE *dev, struct dmfe_board_info * db)
949 945
950 /* Received Packet CRC check need or not */ 946 /* Received Packet CRC check need or not */
951 if ( (db->dm910x_chk_mode & 1) && 947 if ( (db->dm910x_chk_mode & 1) &&
952 (cal_CRC(skb->tail, rxlen, 1) != 948 (cal_CRC(skb->data, rxlen, 1) !=
953 (*(u32 *) (skb->tail+rxlen) ))) { /* FIXME (?) */ 949 (*(u32 *) (skb->data+rxlen) ))) { /* FIXME (?) */
954 /* Found a error received packet */ 950 /* Found a error received packet */
955 dmfe_reuse_skb(db, rxptr->rx_skb_ptr); 951 dmfe_reuse_skb(db, rxptr->rx_skb_ptr);
956 db->dm910x_chk_mode = 3; 952 db->dm910x_chk_mode = 3;
@@ -963,7 +959,7 @@ static void dmfe_rx_packet(struct DEVICE *dev, struct dmfe_board_info * db)
963 /* size less than COPY_SIZE, allocate a rxlen SKB */ 959 /* size less than COPY_SIZE, allocate a rxlen SKB */
964 skb->dev = dev; 960 skb->dev = dev;
965 skb_reserve(skb, 2); /* 16byte align */ 961 skb_reserve(skb, 2); /* 16byte align */
966 memcpy(skb_put(skb, rxlen), rxptr->rx_skb_ptr->tail, rxlen); 962 memcpy(skb_put(skb, rxlen), rxptr->rx_skb_ptr->data, rxlen);
967 dmfe_reuse_skb(db, rxptr->rx_skb_ptr); 963 dmfe_reuse_skb(db, rxptr->rx_skb_ptr);
968 } else { 964 } else {
969 skb->dev = dev; 965 skb->dev = dev;
@@ -1256,7 +1252,7 @@ static void dmfe_reuse_skb(struct dmfe_board_info *db, struct sk_buff * skb)
1256 1252
1257 if (!(rxptr->rdes0 & cpu_to_le32(0x80000000))) { 1253 if (!(rxptr->rdes0 & cpu_to_le32(0x80000000))) {
1258 rxptr->rx_skb_ptr = skb; 1254 rxptr->rx_skb_ptr = skb;
1259 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->tail, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) ); 1255 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->data, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) );
1260 wmb(); 1256 wmb();
1261 rxptr->rdes0 = cpu_to_le32(0x80000000); 1257 rxptr->rdes0 = cpu_to_le32(0x80000000);
1262 db->rx_avail_cnt++; 1258 db->rx_avail_cnt++;
@@ -1467,7 +1463,7 @@ static void allocate_rx_buffer(struct dmfe_board_info *db)
1467 if ( ( skb = dev_alloc_skb(RX_ALLOC_SIZE) ) == NULL ) 1463 if ( ( skb = dev_alloc_skb(RX_ALLOC_SIZE) ) == NULL )
1468 break; 1464 break;
1469 rxptr->rx_skb_ptr = skb; /* FIXME (?) */ 1465 rxptr->rx_skb_ptr = skb; /* FIXME (?) */
1470 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->tail, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) ); 1466 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->data, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) );
1471 wmb(); 1467 wmb();
1472 rxptr->rdes0 = cpu_to_le32(0x80000000); 1468 rxptr->rdes0 = cpu_to_le32(0x80000000);
1473 rxptr = rxptr->next_rx_desc; 1469 rxptr = rxptr->next_rx_desc;
@@ -1806,7 +1802,7 @@ static void dmfe_parse_srom(struct dmfe_board_info * db)
1806 if ( ( (int) srom[18] & 0xff) == SROM_V41_CODE) { 1802 if ( ( (int) srom[18] & 0xff) == SROM_V41_CODE) {
1807 /* SROM V4.01 */ 1803 /* SROM V4.01 */
1808 /* Get NIC support media mode */ 1804 /* Get NIC support media mode */
1809 db->NIC_capability = le16_to_cpup(srom + 34); 1805 db->NIC_capability = le16_to_cpup((__le16 *)srom + 34/2);
1810 db->PHY_reg4 = 0; 1806 db->PHY_reg4 = 0;
1811 for (tmp_reg = 1; tmp_reg < 0x10; tmp_reg <<= 1) { 1807 for (tmp_reg = 1; tmp_reg < 0x10; tmp_reg <<= 1) {
1812 switch( db->NIC_capability & tmp_reg ) { 1808 switch( db->NIC_capability & tmp_reg ) {
@@ -1818,7 +1814,8 @@ static void dmfe_parse_srom(struct dmfe_board_info * db)
1818 } 1814 }
1819 1815
1820 /* Media Mode Force or not check */ 1816 /* Media Mode Force or not check */
1821 dmfe_mode = le32_to_cpup(srom + 34) & le32_to_cpup(srom + 36); 1817 dmfe_mode = le32_to_cpup((__le32 *)srom + 34/4) &
1818 le32_to_cpup((__le32 *)srom + 36/4);
1822 switch(dmfe_mode) { 1819 switch(dmfe_mode) {
1823 case 0x4: dmfe_media_mode = DMFE_100MHF; break; /* 100MHF */ 1820 case 0x4: dmfe_media_mode = DMFE_100MHF; break; /* 100MHF */
1824 case 0x2: dmfe_media_mode = DMFE_10MFD; break; /* 10MFD */ 1821 case 0x2: dmfe_media_mode = DMFE_10MFD; break; /* 10MFD */
diff --git a/drivers/net/tulip/eeprom.c b/drivers/net/tulip/eeprom.c
index ac5bf49ff60f..fbd9ab60b052 100644
--- a/drivers/net/tulip/eeprom.c
+++ b/drivers/net/tulip/eeprom.c
@@ -63,6 +63,22 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
63 */ 63 */
64 { 0x1e00, 0x0000, 0x000b, 0x8f01, 0x0103, 0x0300, 0x0821, 0x000, 0x0001, 0x0000, 0x01e1 } 64 { 0x1e00, 0x0000, 0x000b, 0x8f01, 0x0103, 0x0300, 0x0821, 0x000, 0x0001, 0x0000, 0x01e1 }
65 }, 65 },
66 {"Cobalt Microserver", 0, 0x10, 0xE0, {0x1e00, /* 0 == controller #, 1e == offset */
67 0x0000, /* 0 == high offset, 0 == gap */
68 0x0800, /* Default Autoselect */
69 0x8001, /* 1 leaf, extended type, bogus len */
70 0x0003, /* Type 3 (MII), PHY #0 */
71 0x0400, /* 0 init instr, 4 reset instr */
72 0x0801, /* Set control mode, GP0 output */
73 0x0000, /* Drive GP0 Low (RST is active low) */
74 0x0800, /* control mode, GP0 input (undriven) */
75 0x0000, /* clear control mode */
76 0x7800, /* 100TX FDX + HDX, 10bT FDX + HDX */
77 0x01e0, /* Advertise all above */
78 0x5000, /* FDX all above */
79 0x1800, /* Set fast TTM in 100bt modes */
80 0x0000, /* PHY cannot be unplugged */
81 }},
66 {NULL}}; 82 {NULL}};
67 83
68 84
diff --git a/drivers/net/tulip/interrupt.c b/drivers/net/tulip/interrupt.c
index afb5cda9d8e1..bb3558164a5b 100644
--- a/drivers/net/tulip/interrupt.c
+++ b/drivers/net/tulip/interrupt.c
@@ -78,7 +78,7 @@ int tulip_refill_rx(struct net_device *dev)
78 if (skb == NULL) 78 if (skb == NULL)
79 break; 79 break;
80 80
81 mapping = pci_map_single(tp->pdev, skb->tail, PKT_BUF_SZ, 81 mapping = pci_map_single(tp->pdev, skb->data, PKT_BUF_SZ,
82 PCI_DMA_FROMDEVICE); 82 PCI_DMA_FROMDEVICE);
83 tp->rx_buffers[entry].mapping = mapping; 83 tp->rx_buffers[entry].mapping = mapping;
84 84
@@ -199,12 +199,12 @@ int tulip_poll(struct net_device *dev, int *budget)
199 tp->rx_buffers[entry].mapping, 199 tp->rx_buffers[entry].mapping,
200 pkt_len, PCI_DMA_FROMDEVICE); 200 pkt_len, PCI_DMA_FROMDEVICE);
201#if ! defined(__alpha__) 201#if ! defined(__alpha__)
202 eth_copy_and_sum(skb, tp->rx_buffers[entry].skb->tail, 202 eth_copy_and_sum(skb, tp->rx_buffers[entry].skb->data,
203 pkt_len, 0); 203 pkt_len, 0);
204 skb_put(skb, pkt_len); 204 skb_put(skb, pkt_len);
205#else 205#else
206 memcpy(skb_put(skb, pkt_len), 206 memcpy(skb_put(skb, pkt_len),
207 tp->rx_buffers[entry].skb->tail, 207 tp->rx_buffers[entry].skb->data,
208 pkt_len); 208 pkt_len);
209#endif 209#endif
210 pci_dma_sync_single_for_device(tp->pdev, 210 pci_dma_sync_single_for_device(tp->pdev,
@@ -423,12 +423,12 @@ static int tulip_rx(struct net_device *dev)
423 tp->rx_buffers[entry].mapping, 423 tp->rx_buffers[entry].mapping,
424 pkt_len, PCI_DMA_FROMDEVICE); 424 pkt_len, PCI_DMA_FROMDEVICE);
425#if ! defined(__alpha__) 425#if ! defined(__alpha__)
426 eth_copy_and_sum(skb, tp->rx_buffers[entry].skb->tail, 426 eth_copy_and_sum(skb, tp->rx_buffers[entry].skb->data,
427 pkt_len, 0); 427 pkt_len, 0);
428 skb_put(skb, pkt_len); 428 skb_put(skb, pkt_len);
429#else 429#else
430 memcpy(skb_put(skb, pkt_len), 430 memcpy(skb_put(skb, pkt_len),
431 tp->rx_buffers[entry].skb->tail, 431 tp->rx_buffers[entry].skb->data,
432 pkt_len); 432 pkt_len);
433#endif 433#endif
434 pci_dma_sync_single_for_device(tp->pdev, 434 pci_dma_sync_single_for_device(tp->pdev,
diff --git a/drivers/net/tulip/media.c b/drivers/net/tulip/media.c
index 919c40cd635c..e26c31f944bf 100644
--- a/drivers/net/tulip/media.c
+++ b/drivers/net/tulip/media.c
@@ -400,6 +400,9 @@ void tulip_select_media(struct net_device *dev, int startup)
400 } 400 }
401 401
402 tp->csr6 = new_csr6 | (tp->csr6 & 0xfdff) | (tp->full_duplex ? 0x0200 : 0); 402 tp->csr6 = new_csr6 | (tp->csr6 & 0xfdff) | (tp->full_duplex ? 0x0200 : 0);
403
404 mdelay(1);
405
403 return; 406 return;
404} 407}
405 408
diff --git a/drivers/net/tulip/tulip_core.c b/drivers/net/tulip/tulip_core.c
index e0ae3ed6e578..d45d8f56e5b4 100644
--- a/drivers/net/tulip/tulip_core.c
+++ b/drivers/net/tulip/tulip_core.c
@@ -242,6 +242,7 @@ static struct pci_device_id tulip_pci_tbl[] = {
242 { 0x10b9, 0x5261, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ULI526X }, /* ALi 1563 integrated ethernet */ 242 { 0x10b9, 0x5261, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ULI526X }, /* ALi 1563 integrated ethernet */
243 { 0x10b9, 0x5263, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ULI526X }, /* ALi 1563 integrated ethernet */ 243 { 0x10b9, 0x5263, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ULI526X }, /* ALi 1563 integrated ethernet */
244 { 0x10b7, 0x9300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET }, /* 3Com 3CSOHO100B-TX */ 244 { 0x10b7, 0x9300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET }, /* 3Com 3CSOHO100B-TX */
245 { 0x14ea, 0xab08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET }, /* Planex FNW-3602-TX */
245 { } /* terminate list */ 246 { } /* terminate list */
246}; 247};
247MODULE_DEVICE_TABLE(pci, tulip_pci_tbl); 248MODULE_DEVICE_TABLE(pci, tulip_pci_tbl);
@@ -624,7 +625,7 @@ static void tulip_init_ring(struct net_device *dev)
624 tp->rx_buffers[i].skb = skb; 625 tp->rx_buffers[i].skb = skb;
625 if (skb == NULL) 626 if (skb == NULL)
626 break; 627 break;
627 mapping = pci_map_single(tp->pdev, skb->tail, 628 mapping = pci_map_single(tp->pdev, skb->data,
628 PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 629 PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
629 tp->rx_buffers[i].mapping = mapping; 630 tp->rx_buffers[i].mapping = mapping;
630 skb->dev = dev; /* Mark as being used by this device. */ 631 skb->dev = dev; /* Mark as being used by this device. */
@@ -1514,8 +1515,8 @@ static int __devinit tulip_init_one (struct pci_dev *pdev,
1514 (PCI_SLOT(pdev->devfn) == 12))) { 1515 (PCI_SLOT(pdev->devfn) == 12))) {
1515 /* Cobalt MAC address in first EEPROM locations. */ 1516 /* Cobalt MAC address in first EEPROM locations. */
1516 sa_offset = 0; 1517 sa_offset = 0;
1517 /* No media table either */ 1518 /* Ensure our media table fixup get's applied */
1518 tp->flags &= ~HAS_MEDIA_TABLE; 1519 memcpy(ee_data + 16, ee_data, 8);
1519 } 1520 }
1520#endif 1521#endif
1521#ifdef CONFIG_GSC 1522#ifdef CONFIG_GSC
@@ -1756,11 +1757,19 @@ static int tulip_suspend (struct pci_dev *pdev, pm_message_t state)
1756{ 1757{
1757 struct net_device *dev = pci_get_drvdata(pdev); 1758 struct net_device *dev = pci_get_drvdata(pdev);
1758 1759
1759 if (dev && netif_running (dev) && netif_device_present (dev)) { 1760 if (!dev)
1760 netif_device_detach (dev); 1761 return -EINVAL;
1761 tulip_down (dev); 1762
1762 /* pci_power_off(pdev, -1); */ 1763 if (netif_running(dev))
1763 } 1764 tulip_down(dev);
1765
1766 netif_device_detach(dev);
1767 free_irq(dev->irq, dev);
1768
1769 pci_save_state(pdev);
1770 pci_disable_device(pdev);
1771 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1772
1764 return 0; 1773 return 0;
1765} 1774}
1766 1775
@@ -1768,15 +1777,26 @@ static int tulip_suspend (struct pci_dev *pdev, pm_message_t state)
1768static int tulip_resume(struct pci_dev *pdev) 1777static int tulip_resume(struct pci_dev *pdev)
1769{ 1778{
1770 struct net_device *dev = pci_get_drvdata(pdev); 1779 struct net_device *dev = pci_get_drvdata(pdev);
1780 int retval;
1771 1781
1772 if (dev && netif_running (dev) && !netif_device_present (dev)) { 1782 if (!dev)
1773#if 1 1783 return -EINVAL;
1774 pci_enable_device (pdev); 1784
1775#endif 1785 pci_set_power_state(pdev, PCI_D0);
1776 /* pci_power_on(pdev); */ 1786 pci_restore_state(pdev);
1777 tulip_up (dev); 1787
1778 netif_device_attach (dev); 1788 pci_enable_device(pdev);
1789
1790 if ((retval = request_irq(dev->irq, &tulip_interrupt, SA_SHIRQ, dev->name, dev))) {
1791 printk (KERN_ERR "tulip: request_irq failed in resume\n");
1792 return retval;
1779 } 1793 }
1794
1795 netif_device_attach(dev);
1796
1797 if (netif_running(dev))
1798 tulip_up(dev);
1799
1780 return 0; 1800 return 0;
1781} 1801}
1782 1802
diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
index caff2f590165..5b1af3986abf 100644
--- a/drivers/net/tulip/winbond-840.c
+++ b/drivers/net/tulip/winbond-840.c
@@ -121,6 +121,7 @@ static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
121#include <linux/slab.h> 121#include <linux/slab.h>
122#include <linux/interrupt.h> 122#include <linux/interrupt.h>
123#include <linux/pci.h> 123#include <linux/pci.h>
124#include <linux/dma-mapping.h>
124#include <linux/netdevice.h> 125#include <linux/netdevice.h>
125#include <linux/etherdevice.h> 126#include <linux/etherdevice.h>
126#include <linux/skbuff.h> 127#include <linux/skbuff.h>
@@ -394,7 +395,7 @@ static int __devinit w840_probe1 (struct pci_dev *pdev,
394 395
395 irq = pdev->irq; 396 irq = pdev->irq;
396 397
397 if (pci_set_dma_mask(pdev,0xFFFFffff)) { 398 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
398 printk(KERN_WARNING "Winbond-840: Device %s disabled due to DMA limitations.\n", 399 printk(KERN_WARNING "Winbond-840: Device %s disabled due to DMA limitations.\n",
399 pci_name(pdev)); 400 pci_name(pdev));
400 return -EIO; 401 return -EIO;
@@ -848,7 +849,7 @@ static void init_rxtx_rings(struct net_device *dev)
848 if (skb == NULL) 849 if (skb == NULL)
849 break; 850 break;
850 skb->dev = dev; /* Mark as being used by this device. */ 851 skb->dev = dev; /* Mark as being used by this device. */
851 np->rx_addr[i] = pci_map_single(np->pci_dev,skb->tail, 852 np->rx_addr[i] = pci_map_single(np->pci_dev,skb->data,
852 skb->len,PCI_DMA_FROMDEVICE); 853 skb->len,PCI_DMA_FROMDEVICE);
853 854
854 np->rx_ring[i].buffer1 = np->rx_addr[i]; 855 np->rx_ring[i].buffer1 = np->rx_addr[i];
@@ -1268,7 +1269,7 @@ static int netdev_rx(struct net_device *dev)
1268 pci_dma_sync_single_for_cpu(np->pci_dev,np->rx_addr[entry], 1269 pci_dma_sync_single_for_cpu(np->pci_dev,np->rx_addr[entry],
1269 np->rx_skbuff[entry]->len, 1270 np->rx_skbuff[entry]->len,
1270 PCI_DMA_FROMDEVICE); 1271 PCI_DMA_FROMDEVICE);
1271 eth_copy_and_sum(skb, np->rx_skbuff[entry]->tail, pkt_len, 0); 1272 eth_copy_and_sum(skb, np->rx_skbuff[entry]->data, pkt_len, 0);
1272 skb_put(skb, pkt_len); 1273 skb_put(skb, pkt_len);
1273 pci_dma_sync_single_for_device(np->pci_dev,np->rx_addr[entry], 1274 pci_dma_sync_single_for_device(np->pci_dev,np->rx_addr[entry],
1274 np->rx_skbuff[entry]->len, 1275 np->rx_skbuff[entry]->len,
@@ -1314,7 +1315,7 @@ static int netdev_rx(struct net_device *dev)
1314 break; /* Better luck next round. */ 1315 break; /* Better luck next round. */
1315 skb->dev = dev; /* Mark as being used by this device. */ 1316 skb->dev = dev; /* Mark as being used by this device. */
1316 np->rx_addr[entry] = pci_map_single(np->pci_dev, 1317 np->rx_addr[entry] = pci_map_single(np->pci_dev,
1317 skb->tail, 1318 skb->data,
1318 skb->len, PCI_DMA_FROMDEVICE); 1319 skb->len, PCI_DMA_FROMDEVICE);
1319 np->rx_ring[entry].buffer1 = np->rx_addr[entry]; 1320 np->rx_ring[entry].buffer1 = np->rx_addr[entry];
1320 } 1321 }
diff --git a/drivers/net/tulip/xircom_tulip_cb.c b/drivers/net/tulip/xircom_tulip_cb.c
index b8a9b395c5ea..887d7245fe7b 100644
--- a/drivers/net/tulip/xircom_tulip_cb.c
+++ b/drivers/net/tulip/xircom_tulip_cb.c
@@ -899,7 +899,7 @@ static void xircom_init_ring(struct net_device *dev)
899 break; 899 break;
900 skb->dev = dev; /* Mark as being used by this device. */ 900 skb->dev = dev; /* Mark as being used by this device. */
901 tp->rx_ring[i].status = Rx0DescOwned; /* Owned by Xircom chip */ 901 tp->rx_ring[i].status = Rx0DescOwned; /* Owned by Xircom chip */
902 tp->rx_ring[i].buffer1 = virt_to_bus(skb->tail); 902 tp->rx_ring[i].buffer1 = virt_to_bus(skb->data);
903 } 903 }
904 tp->dirty_rx = (unsigned int)(i - RX_RING_SIZE); 904 tp->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
905 905
@@ -1291,7 +1291,7 @@ xircom_rx(struct net_device *dev)
1291 if (skb == NULL) 1291 if (skb == NULL)
1292 break; 1292 break;
1293 skb->dev = dev; /* Mark as being used by this device. */ 1293 skb->dev = dev; /* Mark as being used by this device. */
1294 tp->rx_ring[entry].buffer1 = virt_to_bus(skb->tail); 1294 tp->rx_ring[entry].buffer1 = virt_to_bus(skb->data);
1295 work_done++; 1295 work_done++;
1296 } 1296 }
1297 tp->rx_ring[entry].status = Rx0DescOwned; 1297 tp->rx_ring[entry].status = Rx0DescOwned;
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index 8f3392989a06..0b5ca2537963 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -1661,7 +1661,7 @@ typhoon_alloc_rx_skb(struct typhoon *tp, u32 idx)
1661#endif 1661#endif
1662 1662
1663 skb->dev = tp->dev; 1663 skb->dev = tp->dev;
1664 dma_addr = pci_map_single(tp->pdev, skb->tail, 1664 dma_addr = pci_map_single(tp->pdev, skb->data,
1665 PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 1665 PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
1666 1666
1667 /* Since no card does 64 bit DAC, the high bits will never 1667 /* Since no card does 64 bit DAC, the high bits will never
@@ -1721,7 +1721,7 @@ typhoon_rx(struct typhoon *tp, struct basic_ring *rxRing, volatile u32 * ready,
1721 pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, 1721 pci_dma_sync_single_for_cpu(tp->pdev, dma_addr,
1722 PKT_BUF_SZ, 1722 PKT_BUF_SZ,
1723 PCI_DMA_FROMDEVICE); 1723 PCI_DMA_FROMDEVICE);
1724 eth_copy_and_sum(new_skb, skb->tail, pkt_len, 0); 1724 eth_copy_and_sum(new_skb, skb->data, pkt_len, 0);
1725 pci_dma_sync_single_for_device(tp->pdev, dma_addr, 1725 pci_dma_sync_single_for_device(tp->pdev, dma_addr,
1726 PKT_BUF_SZ, 1726 PKT_BUF_SZ,
1727 PCI_DMA_FROMDEVICE); 1727 PCI_DMA_FROMDEVICE);
diff --git a/drivers/net/via-rhine.c b/drivers/net/via-rhine.c
index 7b57d552094a..fc7738ffbfff 100644
--- a/drivers/net/via-rhine.c
+++ b/drivers/net/via-rhine.c
@@ -186,6 +186,7 @@ static const int multicast_filter_limit = 32;
186#include <linux/slab.h> 186#include <linux/slab.h>
187#include <linux/interrupt.h> 187#include <linux/interrupt.h>
188#include <linux/pci.h> 188#include <linux/pci.h>
189#include <linux/dma-mapping.h>
189#include <linux/netdevice.h> 190#include <linux/netdevice.h>
190#include <linux/etherdevice.h> 191#include <linux/etherdevice.h>
191#include <linux/skbuff.h> 192#include <linux/skbuff.h>
@@ -506,7 +507,7 @@ static struct net_device_stats *rhine_get_stats(struct net_device *dev);
506static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 507static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
507static struct ethtool_ops netdev_ethtool_ops; 508static struct ethtool_ops netdev_ethtool_ops;
508static int rhine_close(struct net_device *dev); 509static int rhine_close(struct net_device *dev);
509static void rhine_shutdown (struct device *gdev); 510static void rhine_shutdown (struct pci_dev *pdev);
510 511
511#define RHINE_WAIT_FOR(condition) do { \ 512#define RHINE_WAIT_FOR(condition) do { \
512 int i=1024; \ 513 int i=1024; \
@@ -740,7 +741,7 @@ static int __devinit rhine_init_one(struct pci_dev *pdev,
740 goto err_out; 741 goto err_out;
741 742
742 /* this should always be supported */ 743 /* this should always be supported */
743 rc = pci_set_dma_mask(pdev, 0xffffffff); 744 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
744 if (rc) { 745 if (rc) {
745 printk(KERN_ERR "32-bit PCI DMA addresses not supported by " 746 printk(KERN_ERR "32-bit PCI DMA addresses not supported by "
746 "the card!?\n"); 747 "the card!?\n");
@@ -989,7 +990,7 @@ static void alloc_rbufs(struct net_device *dev)
989 skb->dev = dev; /* Mark as being used by this device. */ 990 skb->dev = dev; /* Mark as being used by this device. */
990 991
991 rp->rx_skbuff_dma[i] = 992 rp->rx_skbuff_dma[i] =
992 pci_map_single(rp->pdev, skb->tail, rp->rx_buf_sz, 993 pci_map_single(rp->pdev, skb->data, rp->rx_buf_sz,
993 PCI_DMA_FROMDEVICE); 994 PCI_DMA_FROMDEVICE);
994 995
995 rp->rx_ring[i].addr = cpu_to_le32(rp->rx_skbuff_dma[i]); 996 rp->rx_ring[i].addr = cpu_to_le32(rp->rx_skbuff_dma[i]);
@@ -1397,7 +1398,7 @@ static void rhine_tx(struct net_device *dev)
1397 while (rp->dirty_tx != rp->cur_tx) { 1398 while (rp->dirty_tx != rp->cur_tx) {
1398 txstatus = le32_to_cpu(rp->tx_ring[entry].tx_status); 1399 txstatus = le32_to_cpu(rp->tx_ring[entry].tx_status);
1399 if (debug > 6) 1400 if (debug > 6)
1400 printk(KERN_DEBUG " Tx scavenge %d status %8.8x.\n", 1401 printk(KERN_DEBUG "Tx scavenge %d status %8.8x.\n",
1401 entry, txstatus); 1402 entry, txstatus);
1402 if (txstatus & DescOwn) 1403 if (txstatus & DescOwn)
1403 break; 1404 break;
@@ -1468,7 +1469,7 @@ static void rhine_rx(struct net_device *dev)
1468 int data_size = desc_status >> 16; 1469 int data_size = desc_status >> 16;
1469 1470
1470 if (debug > 4) 1471 if (debug > 4)
1471 printk(KERN_DEBUG " rhine_rx() status is %8.8x.\n", 1472 printk(KERN_DEBUG "rhine_rx() status is %8.8x.\n",
1472 desc_status); 1473 desc_status);
1473 if (--boguscnt < 0) 1474 if (--boguscnt < 0)
1474 break; 1475 break;
@@ -1486,7 +1487,7 @@ static void rhine_rx(struct net_device *dev)
1486 } else if (desc_status & RxErr) { 1487 } else if (desc_status & RxErr) {
1487 /* There was a error. */ 1488 /* There was a error. */
1488 if (debug > 2) 1489 if (debug > 2)
1489 printk(KERN_DEBUG " rhine_rx() Rx " 1490 printk(KERN_DEBUG "rhine_rx() Rx "
1490 "error was %8.8x.\n", 1491 "error was %8.8x.\n",
1491 desc_status); 1492 desc_status);
1492 rp->stats.rx_errors++; 1493 rp->stats.rx_errors++;
@@ -1517,7 +1518,7 @@ static void rhine_rx(struct net_device *dev)
1517 PCI_DMA_FROMDEVICE); 1518 PCI_DMA_FROMDEVICE);
1518 1519
1519 eth_copy_and_sum(skb, 1520 eth_copy_and_sum(skb,
1520 rp->rx_skbuff[entry]->tail, 1521 rp->rx_skbuff[entry]->data,
1521 pkt_len, 0); 1522 pkt_len, 0);
1522 skb_put(skb, pkt_len); 1523 skb_put(skb, pkt_len);
1523 pci_dma_sync_single_for_device(rp->pdev, 1524 pci_dma_sync_single_for_device(rp->pdev,
@@ -1560,7 +1561,7 @@ static void rhine_rx(struct net_device *dev)
1560 break; /* Better luck next round. */ 1561 break; /* Better luck next round. */
1561 skb->dev = dev; /* Mark as being used by this device. */ 1562 skb->dev = dev; /* Mark as being used by this device. */
1562 rp->rx_skbuff_dma[entry] = 1563 rp->rx_skbuff_dma[entry] =
1563 pci_map_single(rp->pdev, skb->tail, 1564 pci_map_single(rp->pdev, skb->data,
1564 rp->rx_buf_sz, 1565 rp->rx_buf_sz,
1565 PCI_DMA_FROMDEVICE); 1566 PCI_DMA_FROMDEVICE);
1566 rp->rx_ring[entry].addr = cpu_to_le32(rp->rx_skbuff_dma[entry]); 1567 rp->rx_ring[entry].addr = cpu_to_le32(rp->rx_skbuff_dma[entry]);
@@ -1894,9 +1895,8 @@ static void __devexit rhine_remove_one(struct pci_dev *pdev)
1894 pci_set_drvdata(pdev, NULL); 1895 pci_set_drvdata(pdev, NULL);
1895} 1896}
1896 1897
1897static void rhine_shutdown (struct device *gendev) 1898static void rhine_shutdown (struct pci_dev *pdev)
1898{ 1899{
1899 struct pci_dev *pdev = to_pci_dev(gendev);
1900 struct net_device *dev = pci_get_drvdata(pdev); 1900 struct net_device *dev = pci_get_drvdata(pdev);
1901 struct rhine_private *rp = netdev_priv(dev); 1901 struct rhine_private *rp = netdev_priv(dev);
1902 void __iomem *ioaddr = rp->base; 1902 void __iomem *ioaddr = rp->base;
@@ -1955,7 +1955,7 @@ static int rhine_suspend(struct pci_dev *pdev, pm_message_t state)
1955 pci_save_state(pdev); 1955 pci_save_state(pdev);
1956 1956
1957 spin_lock_irqsave(&rp->lock, flags); 1957 spin_lock_irqsave(&rp->lock, flags);
1958 rhine_shutdown(&pdev->dev); 1958 rhine_shutdown(pdev);
1959 spin_unlock_irqrestore(&rp->lock, flags); 1959 spin_unlock_irqrestore(&rp->lock, flags);
1960 1960
1961 free_irq(dev->irq, dev); 1961 free_irq(dev->irq, dev);
@@ -2009,9 +2009,7 @@ static struct pci_driver rhine_driver = {
2009 .suspend = rhine_suspend, 2009 .suspend = rhine_suspend,
2010 .resume = rhine_resume, 2010 .resume = rhine_resume,
2011#endif /* CONFIG_PM */ 2011#endif /* CONFIG_PM */
2012 .driver = { 2012 .shutdown = rhine_shutdown,
2013 .shutdown = rhine_shutdown,
2014 }
2015}; 2013};
2016 2014
2017 2015
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index 15e710283493..abc5cee6eedc 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -1335,7 +1335,7 @@ static inline int velocity_rx_copy(struct sk_buff **rx_skb, int pkt_size,
1335 if (vptr->flags & VELOCITY_FLAGS_IP_ALIGN) 1335 if (vptr->flags & VELOCITY_FLAGS_IP_ALIGN)
1336 skb_reserve(new_skb, 2); 1336 skb_reserve(new_skb, 2);
1337 1337
1338 memcpy(new_skb->data, rx_skb[0]->tail, pkt_size); 1338 memcpy(new_skb->data, rx_skb[0]->data, pkt_size);
1339 *rx_skb = new_skb; 1339 *rx_skb = new_skb;
1340 ret = 0; 1340 ret = 0;
1341 } 1341 }
@@ -1456,9 +1456,9 @@ static int velocity_alloc_rx_buf(struct velocity_info *vptr, int idx)
1456 * Do the gymnastics to get the buffer head for data at 1456 * Do the gymnastics to get the buffer head for data at
1457 * 64byte alignment. 1457 * 64byte alignment.
1458 */ 1458 */
1459 skb_reserve(rd_info->skb, (unsigned long) rd_info->skb->tail & 63); 1459 skb_reserve(rd_info->skb, (unsigned long) rd_info->skb->data & 63);
1460 rd_info->skb->dev = vptr->dev; 1460 rd_info->skb->dev = vptr->dev;
1461 rd_info->skb_dma = pci_map_single(vptr->pdev, rd_info->skb->tail, vptr->rx_buf_sz, PCI_DMA_FROMDEVICE); 1461 rd_info->skb_dma = pci_map_single(vptr->pdev, rd_info->skb->data, vptr->rx_buf_sz, PCI_DMA_FROMDEVICE);
1462 1462
1463 /* 1463 /*
1464 * Fill in the descriptor to match 1464 * Fill in the descriptor to match
diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
index 7575b799ce53..7217d44e8854 100644
--- a/drivers/net/wan/farsync.c
+++ b/drivers/net/wan/farsync.c
@@ -981,6 +981,7 @@ fst_issue_cmd(struct fst_port_info *port, unsigned short cmd)
981 /* Wait for any previous command to complete */ 981 /* Wait for any previous command to complete */
982 while (mbval > NAK) { 982 while (mbval > NAK) {
983 spin_unlock_irqrestore(&card->card_lock, flags); 983 spin_unlock_irqrestore(&card->card_lock, flags);
984 set_current_state(TASK_UNINTERRUPTIBLE);
984 schedule_timeout(1); 985 schedule_timeout(1);
985 spin_lock_irqsave(&card->card_lock, flags); 986 spin_lock_irqsave(&card->card_lock, flags);
986 987
diff --git a/drivers/net/wan/hdlc_cisco.c b/drivers/net/wan/hdlc_cisco.c
index c1b6896d7007..87496843681a 100644
--- a/drivers/net/wan/hdlc_cisco.c
+++ b/drivers/net/wan/hdlc_cisco.c
@@ -72,7 +72,7 @@ static void cisco_keepalive_send(struct net_device *dev, u32 type,
72 } 72 }
73 skb_reserve(skb, 4); 73 skb_reserve(skb, 4);
74 cisco_hard_header(skb, dev, CISCO_KEEPALIVE, NULL, NULL, 0); 74 cisco_hard_header(skb, dev, CISCO_KEEPALIVE, NULL, NULL, 0);
75 data = (cisco_packet*)skb->tail; 75 data = (cisco_packet*)skb->data;
76 76
77 data->type = htonl(type); 77 data->type = htonl(type);
78 data->par1 = htonl(par1); 78 data->par1 = htonl(par1);
diff --git a/drivers/net/wan/wanxl.c b/drivers/net/wan/wanxl.c
index 1e7b47704ad9..9c1e10602f2b 100644
--- a/drivers/net/wan/wanxl.c
+++ b/drivers/net/wan/wanxl.c
@@ -26,6 +26,7 @@
26#include <linux/netdevice.h> 26#include <linux/netdevice.h>
27#include <linux/hdlc.h> 27#include <linux/hdlc.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/dma-mapping.h>
29#include <asm/io.h> 30#include <asm/io.h>
30#include <asm/delay.h> 31#include <asm/delay.h>
31 32
@@ -624,8 +625,8 @@ static int __devinit wanxl_pci_init_one(struct pci_dev *pdev,
624 /* FIXME when PCI/DMA subsystems are fixed. 625 /* FIXME when PCI/DMA subsystems are fixed.
625 We set both dma_mask and consistent_dma_mask back to 32 bits 626 We set both dma_mask and consistent_dma_mask back to 32 bits
626 to indicate the card can do 32-bit DMA addressing */ 627 to indicate the card can do 32-bit DMA addressing */
627 if (pci_set_consistent_dma_mask(pdev, 0xFFFFFFFF) || 628 if (pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK) ||
628 pci_set_dma_mask(pdev, 0xFFFFFFFF)) { 629 pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
629 printk(KERN_ERR "wanXL: No usable DMA configuration\n"); 630 printk(KERN_ERR "wanXL: No usable DMA configuration\n");
630 wanxl_pci_remove_one(pdev); 631 wanxl_pci_remove_one(pdev);
631 return -EIO; 632 return -EIO;
diff --git a/drivers/net/wd.c b/drivers/net/wd.c
index 1f05d9bd05e4..b03feae459fc 100644
--- a/drivers/net/wd.c
+++ b/drivers/net/wd.c
@@ -149,12 +149,7 @@ struct net_device * __init wd_probe(int unit)
149 err = do_wd_probe(dev); 149 err = do_wd_probe(dev);
150 if (err) 150 if (err)
151 goto out; 151 goto out;
152 err = register_netdev(dev);
153 if (err)
154 goto out1;
155 return dev; 152 return dev;
156out1:
157 cleanup_card(dev);
158out: 153out:
159 free_netdev(dev); 154 free_netdev(dev);
160 return ERR_PTR(err); 155 return ERR_PTR(err);
@@ -164,6 +159,7 @@ out:
164static int __init wd_probe1(struct net_device *dev, int ioaddr) 159static int __init wd_probe1(struct net_device *dev, int ioaddr)
165{ 160{
166 int i; 161 int i;
162 int err;
167 int checksum = 0; 163 int checksum = 0;
168 int ancient = 0; /* An old card without config registers. */ 164 int ancient = 0; /* An old card without config registers. */
169 int word16 = 0; /* 0 = 8 bit, 1 = 16 bit */ 165 int word16 = 0; /* 0 = 8 bit, 1 = 16 bit */
@@ -356,7 +352,10 @@ static int __init wd_probe1(struct net_device *dev, int ioaddr)
356 outb(inb(ioaddr+4)|0x80, ioaddr+4); 352 outb(inb(ioaddr+4)|0x80, ioaddr+4);
357#endif 353#endif
358 354
359 return 0; 355 err = register_netdev(dev);
356 if (err)
357 free_irq(dev->irq, dev);
358 return err;
360} 359}
361 360
362static int 361static int
@@ -527,11 +526,8 @@ init_module(void)
527 dev->mem_start = mem[this_dev]; 526 dev->mem_start = mem[this_dev];
528 dev->mem_end = mem_end[this_dev]; 527 dev->mem_end = mem_end[this_dev];
529 if (do_wd_probe(dev) == 0) { 528 if (do_wd_probe(dev) == 0) {
530 if (register_netdev(dev) == 0) { 529 dev_wd[found++] = dev;
531 dev_wd[found++] = dev; 530 continue;
532 continue;
533 }
534 cleanup_card(dev);
535 } 531 }
536 free_netdev(dev); 532 free_netdev(dev);
537 printk(KERN_WARNING "wd.c: No wd80x3 card found (i/o = 0x%x).\n", io[this_dev]); 533 printk(KERN_WARNING "wd.c: No wd80x3 card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index d72e0385e4f2..c12648d8192b 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -900,7 +900,7 @@ typedef struct aironet_ioctl {
900 unsigned char __user *data; // d-data 900 unsigned char __user *data; // d-data
901} aironet_ioctl; 901} aironet_ioctl;
902 902
903static char *swversion = "2.1"; 903static char swversion[] = "2.1";
904#endif /* CISCO_EXT */ 904#endif /* CISCO_EXT */
905 905
906#define NUM_MODULES 2 906#define NUM_MODULES 2
@@ -1209,7 +1209,7 @@ struct airo_info {
1209 unsigned char __iomem *pciaux; 1209 unsigned char __iomem *pciaux;
1210 unsigned char *shared; 1210 unsigned char *shared;
1211 dma_addr_t shared_dma; 1211 dma_addr_t shared_dma;
1212 int power; 1212 pm_message_t power;
1213 SsidRid *SSID; 1213 SsidRid *SSID;
1214 APListRid *APList; 1214 APListRid *APList;
1215#define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE 1215#define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
@@ -5499,9 +5499,9 @@ static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state)
5499 cmd.cmd=HOSTSLEEP; 5499 cmd.cmd=HOSTSLEEP;
5500 issuecommand(ai, &cmd, &rsp); 5500 issuecommand(ai, &cmd, &rsp);
5501 5501
5502 pci_enable_wake(pdev, state, 1); 5502 pci_enable_wake(pdev, pci_choose_state(pdev, state), 1);
5503 pci_save_state(pdev); 5503 pci_save_state(pdev);
5504 return pci_set_power_state(pdev, state); 5504 return pci_set_power_state(pdev, pci_choose_state(pdev, state));
5505} 5505}
5506 5506
5507static int airo_pci_resume(struct pci_dev *pdev) 5507static int airo_pci_resume(struct pci_dev *pdev)
@@ -5512,7 +5512,7 @@ static int airo_pci_resume(struct pci_dev *pdev)
5512 5512
5513 pci_set_power_state(pdev, 0); 5513 pci_set_power_state(pdev, 0);
5514 pci_restore_state(pdev); 5514 pci_restore_state(pdev);
5515 pci_enable_wake(pdev, ai->power, 0); 5515 pci_enable_wake(pdev, pci_choose_state(pdev, ai->power), 0);
5516 5516
5517 if (ai->power > 1) { 5517 if (ai->power > 1) {
5518 reset_card(dev, 0); 5518 reset_card(dev, 0);
@@ -5541,7 +5541,7 @@ static int airo_pci_resume(struct pci_dev *pdev)
5541 } 5541 }
5542 writeConfigRid(ai, 0); 5542 writeConfigRid(ai, 0);
5543 enable_MAC(ai, &rsp, 0); 5543 enable_MAC(ai, &rsp, 0);
5544 ai->power = 0; 5544 ai->power = PMSG_ON;
5545 netif_device_attach(dev); 5545 netif_device_attach(dev);
5546 netif_wake_queue(dev); 5546 netif_wake_queue(dev);
5547 enable_interrupts(ai); 5547 enable_interrupts(ai);
diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c
index fbf53af6cda4..f10a9523034a 100644
--- a/drivers/net/wireless/airo_cs.c
+++ b/drivers/net/wireless/airo_cs.c
@@ -559,6 +559,15 @@ static int airo_event(event_t event, int priority,
559 return 0; 559 return 0;
560} /* airo_event */ 560} /* airo_event */
561 561
562static struct pcmcia_device_id airo_ids[] = {
563 PCMCIA_DEVICE_MANF_CARD(0x015f, 0x000a),
564 PCMCIA_DEVICE_MANF_CARD(0x015f, 0x0005),
565 PCMCIA_DEVICE_MANF_CARD(0x015f, 0x0007),
566 PCMCIA_DEVICE_MANF_CARD(0x0105, 0x0007),
567 PCMCIA_DEVICE_NULL,
568};
569MODULE_DEVICE_TABLE(pcmcia, airo_ids);
570
562static struct pcmcia_driver airo_driver = { 571static struct pcmcia_driver airo_driver = {
563 .owner = THIS_MODULE, 572 .owner = THIS_MODULE,
564 .drv = { 573 .drv = {
@@ -566,6 +575,7 @@ static struct pcmcia_driver airo_driver = {
566 }, 575 },
567 .attach = airo_attach, 576 .attach = airo_attach,
568 .detach = airo_detach, 577 .detach = airo_detach,
578 .id_table = airo_ids,
569}; 579};
570 580
571static int airo_cs_init(void) 581static int airo_cs_init(void)
diff --git a/drivers/net/wireless/arlan-main.c b/drivers/net/wireless/arlan-main.c
index 4f304c6e693a..0e1ac338cac1 100644
--- a/drivers/net/wireless/arlan-main.c
+++ b/drivers/net/wireless/arlan-main.c
@@ -33,8 +33,6 @@ static int arlan_EEPROM_bad;
33 33
34#ifdef ARLAN_DEBUGGING 34#ifdef ARLAN_DEBUGGING
35 35
36static int arlan_entry_debug;
37static int arlan_exit_debug;
38static int testMemory = testMemoryUNKNOWN; 36static int testMemory = testMemoryUNKNOWN;
39static int irq = irqUNKNOWN; 37static int irq = irqUNKNOWN;
40static int txScrambled = 1; 38static int txScrambled = 1;
@@ -43,15 +41,13 @@ static int mdebug;
43module_param(irq, int, 0); 41module_param(irq, int, 0);
44module_param(mdebug, int, 0); 42module_param(mdebug, int, 0);
45module_param(testMemory, int, 0); 43module_param(testMemory, int, 0);
46module_param(arlan_entry_debug, int, 0);
47module_param(arlan_exit_debug, int, 0);
48module_param(txScrambled, int, 0); 44module_param(txScrambled, int, 0);
49MODULE_PARM_DESC(irq, "(unused)"); 45MODULE_PARM_DESC(irq, "(unused)");
50MODULE_PARM_DESC(testMemory, "(unused)"); 46MODULE_PARM_DESC(testMemory, "(unused)");
51MODULE_PARM_DESC(mdebug, "Arlan multicast debugging (0-1)"); 47MODULE_PARM_DESC(mdebug, "Arlan multicast debugging (0-1)");
52#endif 48#endif
53 49
54module_param(arlan_debug, int, 0); 50module_param_named(debug, arlan_debug, int, 0);
55module_param(spreadingCode, int, 0); 51module_param(spreadingCode, int, 0);
56module_param(channelNumber, int, 0); 52module_param(channelNumber, int, 0);
57module_param(channelSet, int, 0); 53module_param(channelSet, int, 0);
@@ -63,17 +59,19 @@ module_param(keyStart, int, 0);
63module_param(tx_delay_ms, int, 0); 59module_param(tx_delay_ms, int, 0);
64module_param(retries, int, 0); 60module_param(retries, int, 0);
65module_param(tx_queue_len, int, 0); 61module_param(tx_queue_len, int, 0);
66module_param(arlan_EEPROM_bad, int, 0); 62module_param_named(EEPROM_bad, arlan_EEPROM_bad, int, 0);
67MODULE_PARM_DESC(arlan_debug, "Arlan debug enable (0-1)"); 63MODULE_PARM_DESC(debug, "Arlan debug enable (0-1)");
68MODULE_PARM_DESC(retries, "Arlan maximum packet retransmisions"); 64MODULE_PARM_DESC(retries, "Arlan maximum packet retransmisions");
69#ifdef ARLAN_ENTRY_EXIT_DEBUGGING 65#ifdef ARLAN_ENTRY_EXIT_DEBUGGING
70MODULE_PARM_DESC(arlan_entry_debug, "Arlan driver function entry debugging"); 66static int arlan_entry_debug;
71MODULE_PARM_DESC(arlan_exit_debug, "Arlan driver function exit debugging"); 67static int arlan_exit_debug;
72MODULE_PARM_DESC(arlan_entry_and_exit_debug, "Arlan driver function entry and exit debugging"); 68static int arlan_entry_and_exit_debug;
73#else 69module_param_named(entry_debug, arlan_entry_debug, int, 0);
74MODULE_PARM_DESC(arlan_entry_debug, "(ignored)"); 70module_param_named(exit_debug, arlan_exit_debug, int, 0);
75MODULE_PARM_DESC(arlan_exit_debug, "(ignored)"); 71module_param_named(entry_and_exit_debug, arlan_entry_and_exit_debug, int, 0);
76MODULE_PARM_DESC(arlan_entry_and_exit_debug, "(ignored)"); 72MODULE_PARM_DESC(entry_debug, "Arlan driver function entry debugging");
73MODULE_PARM_DESC(exit_debug, "Arlan driver function exit debugging");
74MODULE_PARM_DESC(entry_and_exit_debug, "Arlan driver function entry and exit debugging");
77#endif 75#endif
78 76
79struct arlan_conf_stru arlan_conf[MAX_ARLANS]; 77struct arlan_conf_stru arlan_conf[MAX_ARLANS];
diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c
index a4ed28d9c783..86379d4998ac 100644
--- a/drivers/net/wireless/atmel_cs.c
+++ b/drivers/net/wireless/atmel_cs.c
@@ -646,6 +646,27 @@ static int atmel_event(event_t event, int priority,
646} /* atmel_event */ 646} /* atmel_event */
647 647
648/*====================================================================*/ 648/*====================================================================*/
649static struct pcmcia_device_id atmel_ids[] = {
650 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0620),
651 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0696),
652 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x3302),
653 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0007),
654 PCMCIA_DEVICE_PROD_ID12("11WAVE", "11WP611AL-E", 0x9eb2da1f, 0xc9a0d3f9),
655 PCMCIA_DEVICE_PROD_ID12("ATMEL", "AT76C502AR", 0xabda4164, 0x41b37e1f),
656 PCMCIA_DEVICE_PROD_ID12("ATMEL", "AT76C504", 0xabda4164, 0x5040670a),
657 PCMCIA_DEVICE_PROD_ID12("ATMEL", "AT76C504A", 0xabda4164, 0xe15ed87f),
658 PCMCIA_DEVICE_PROD_ID12("BT", "Voyager 1020 Laptop Adapter", 0xae49b86a, 0x1e957cd5),
659 PCMCIA_DEVICE_PROD_ID12("CNet", "CNWLC 11Mbps Wireless PC Card V-5", 0xbc477dde, 0x502fae6b),
660 PCMCIA_DEVICE_PROD_ID12("IEEE 802.11b", "Wireless LAN PC Card", 0x5b878724, 0x122f1df6),
661 PCMCIA_DEVICE_PROD_ID12("OEM", "11Mbps Wireless LAN PC Card V-3", 0xfea54c90, 0x1c5b0f68),
662 PCMCIA_DEVICE_PROD_ID12("SMC", "2632W", 0xc4f8b18b, 0x30f38774),
663 PCMCIA_DEVICE_PROD_ID12("SMC", "2632W-V2", 0xc4f8b18b, 0x172d1377),
664 PCMCIA_DEVICE_PROD_ID12("Wireless", "PC", 0xa407ecdd, 0x556e4d7e),
665 PCMCIA_DEVICE_PROD_ID12("WLAN", "802.11b PC CARD", 0x575c516c, 0xb1f6dbc4),
666 PCMCIA_DEVICE_NULL
667};
668MODULE_DEVICE_TABLE(pcmcia, atmel_ids);
669
649static struct pcmcia_driver atmel_driver = { 670static struct pcmcia_driver atmel_driver = {
650 .owner = THIS_MODULE, 671 .owner = THIS_MODULE,
651 .drv = { 672 .drv = {
@@ -653,6 +674,7 @@ static struct pcmcia_driver atmel_driver = {
653 }, 674 },
654 .attach = atmel_attach, 675 .attach = atmel_attach,
655 .detach = atmel_detach, 676 .detach = atmel_detach,
677 .id_table = atmel_ids,
656}; 678};
657 679
658static int atmel_cs_init(void) 680static int atmel_cs_init(void)
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c
index 382241e7edbb..e12bd75b2694 100644
--- a/drivers/net/wireless/netwave_cs.c
+++ b/drivers/net/wireless/netwave_cs.c
@@ -1668,6 +1668,12 @@ static int netwave_close(struct net_device *dev) {
1668 return 0; 1668 return 0;
1669} 1669}
1670 1670
1671static struct pcmcia_device_id netwave_ids[] = {
1672 PCMCIA_DEVICE_PROD_ID12("Xircom", "CreditCard Netwave", 0x2e3ee845, 0x54e28a28),
1673 PCMCIA_DEVICE_NULL,
1674};
1675MODULE_DEVICE_TABLE(pcmcia, netwave_ids);
1676
1671static struct pcmcia_driver netwave_driver = { 1677static struct pcmcia_driver netwave_driver = {
1672 .owner = THIS_MODULE, 1678 .owner = THIS_MODULE,
1673 .drv = { 1679 .drv = {
@@ -1675,6 +1681,7 @@ static struct pcmcia_driver netwave_driver = {
1675 }, 1681 },
1676 .attach = netwave_attach, 1682 .attach = netwave_attach,
1677 .detach = netwave_detach, 1683 .detach = netwave_detach,
1684 .id_table = netwave_ids,
1678}; 1685};
1679 1686
1680static int __init init_netwave_cs(void) 1687static int __init init_netwave_cs(void)
diff --git a/drivers/net/wireless/orinoco.c b/drivers/net/wireless/orinoco.c
index b1078baa1d5e..aabcdc2be05e 100644
--- a/drivers/net/wireless/orinoco.c
+++ b/drivers/net/wireless/orinoco.c
@@ -46,382 +46,9 @@
46 * under either the MPL or the GPL. */ 46 * under either the MPL or the GPL. */
47 47
48/* 48/*
49 * v0.01 -> v0.02 - 21/3/2001 - Jean II
50 * o Allow to use regular ethX device name instead of dldwdX
51 * o Warning on IBSS with ESSID=any for firmware 6.06
52 * o Put proper range.throughput values (optimistic)
53 * o IWSPY support (IOCTL and stat gather in Rx path)
54 * o Allow setting frequency in Ad-Hoc mode
55 * o Disable WEP setting if !has_wep to work on old firmware
56 * o Fix txpower range
57 * o Start adding support for Samsung/Compaq firmware
58 *
59 * v0.02 -> v0.03 - 23/3/2001 - Jean II
60 * o Start adding Symbol support - need to check all that
61 * o Fix Prism2/Symbol WEP to accept 128 bits keys
62 * o Add Symbol WEP (add authentication type)
63 * o Add Prism2/Symbol rate
64 * o Add PM timeout (holdover duration)
65 * o Enable "iwconfig eth0 key off" and friends (toggle flags)
66 * o Enable "iwconfig eth0 power unicast/all" (toggle flags)
67 * o Try with an Intel card. It report firmware 1.01, behave like
68 * an antiquated firmware, however on windows it says 2.00. Yuck !
69 * o Workaround firmware bug in allocate buffer (Intel 1.01)
70 * o Finish external renaming to orinoco...
71 * o Testing with various Wavelan firmwares
72 *
73 * v0.03 -> v0.04 - 30/3/2001 - Jean II
74 * o Update to Wireless 11 -> add retry limit/lifetime support
75 * o Tested with a D-Link DWL 650 card, fill in firmware support
76 * o Warning on Vcc mismatch (D-Link 3.3v card in Lucent 5v only slot)
77 * o Fixed the Prism2 WEP bugs that I introduced in v0.03 :-(
78 * It works on D-Link *only* after a tcpdump. Weird...
79 * And still doesn't work on Intel card. Grrrr...
80 * o Update the mode after a setport3
81 * o Add preamble setting for Symbol cards (not yet enabled)
82 * o Don't complain as much about Symbol cards...
83 *
84 * v0.04 -> v0.04b - 22/4/2001 - David Gibson
85 * o Removed the 'eth' parameter - always use ethXX as the
86 * interface name instead of dldwdXX. The other was racy
87 * anyway.
88 * o Clean up RID definitions in hermes.h, other cleanups
89 *
90 * v0.04b -> v0.04c - 24/4/2001 - Jean II
91 * o Tim Hurley <timster AT seiki.bliztech.com> reported a D-Link card
92 * with vendor 02 and firmware 0.08. Added in the capabilities...
93 * o Tested Lucent firmware 7.28, everything works...
94 *
95 * v0.04c -> v0.05 - 3/5/2001 - Benjamin Herrenschmidt
96 * o Spin-off Pcmcia code. This file is renamed orinoco.c,
97 * and orinoco_cs.c now contains only the Pcmcia specific stuff
98 * o Add Airport driver support on top of orinoco.c (see airport.c)
99 *
100 * v0.05 -> v0.05a - 4/5/2001 - Jean II
101 * o Revert to old Pcmcia code to fix breakage of Ben's changes...
102 *
103 * v0.05a -> v0.05b - 4/5/2001 - Jean II
104 * o add module parameter 'ignore_cis_vcc' for D-Link @ 5V
105 * o D-Link firmware doesn't support multicast. We just print a few
106 * error messages, but otherwise everything works...
107 * o For David : set/getport3 works fine, just upgrade iwpriv...
108 *
109 * v0.05b -> v0.05c - 5/5/2001 - Benjamin Herrenschmidt
110 * o Adapt airport.c to latest changes in orinoco.c
111 * o Remove deferred power enabling code
112 *
113 * v0.05c -> v0.05d - 5/5/2001 - Jean II
114 * o Workaround to SNAP decapsulate frame from Linksys AP
115 * original patch from : Dong Liu <dliu AT research.bell-labs.com>
116 * (note : the memcmp bug was mine - fixed)
117 * o Remove set_retry stuff, no firmware support it (bloat--).
118 *
119 * v0.05d -> v0.06 - 25/5/2001 - Jean II
120 * Original patch from "Hong Lin" <alin AT redhat.com>,
121 * "Ian Kinner" <ikinner AT redhat.com>
122 * and "David Smith" <dsmith AT redhat.com>
123 * o Init of priv->tx_rate_ctrl in firmware specific section.
124 * o Prism2/Symbol rate, upto should be 0xF and not 0x15. Doh !
125 * o Spectrum card always need cor_reset (for every reset)
126 * o Fix cor_reset to not lose bit 7 in the register
127 * o flush_stale_links to remove zombie Pcmcia instances
128 * o Ack previous hermes event before reset
129 * Me (with my little hands)
130 * o Allow orinoco.c to call cor_reset via priv->card_reset_handler
131 * o Add priv->need_card_reset to toggle this feature
132 * o Fix various buglets when setting WEP in Symbol firmware
133 * Now, encryption is fully functional on Symbol cards. Youpi !
134 *
135 * v0.06 -> v0.06b - 25/5/2001 - Jean II
136 * o IBSS on Symbol use port_mode = 4. Please don't ask...
137 *
138 * v0.06b -> v0.06c - 29/5/2001 - Jean II
139 * o Show first spy address in /proc/net/wireless for IBSS mode as well
140 *
141 * v0.06c -> v0.06d - 6/7/2001 - David Gibson
142 * o Change a bunch of KERN_INFO messages to KERN_DEBUG, as per Linus'
143 * wishes to reduce the number of unnecessary messages.
144 * o Removed bogus message on CRC error.
145 * o Merged fixes for v0.08 Prism 2 firmware from William Waghorn
146 * <willwaghorn AT yahoo.co.uk>
147 * o Slight cleanup/re-arrangement of firmware detection code.
148 *
149 * v0.06d -> v0.06e - 1/8/2001 - David Gibson
150 * o Removed some redundant global initializers (orinoco_cs.c).
151 * o Added some module metadata
152 *
153 * v0.06e -> v0.06f - 14/8/2001 - David Gibson
154 * o Wording fix to license
155 * o Added a 'use_alternate_encaps' module parameter for APs which need an
156 * oui of 00:00:00. We really need a better way of handling this, but
157 * the module flag is better than nothing for now.
158 *
159 * v0.06f -> v0.07 - 20/8/2001 - David Gibson
160 * o Removed BAP error retries from hermes_bap_seek(). For Tx we now
161 * let the upper layers handle the retry, we retry explicitly in the
162 * Rx path, but don't make as much noise about it.
163 * o Firmware detection cleanups.
164 *
165 * v0.07 -> v0.07a - 1/10/3001 - Jean II
166 * o Add code to read Symbol firmware revision, inspired by latest code
167 * in Spectrum24 by Lee John Keyser-Allen - Thanks Lee !
168 * o Thanks to Jared Valentine <hidden AT xmission.com> for "providing" me
169 * a 3Com card with a recent firmware, fill out Symbol firmware
170 * capabilities of latest rev (2.20), as well as older Symbol cards.
171 * o Disable Power Management in newer Symbol firmware, the API
172 * has changed (documentation needed).
173 *
174 * v0.07a -> v0.08 - 3/10/2001 - David Gibson
175 * o Fixed a possible buffer overrun found by the Stanford checker (in
176 * dldwd_ioctl_setiwencode()). Can only be called by root anyway, so not
177 * a big problem.
178 * o Turned has_big_wep on for Intersil cards. That's not true for all of
179 * them but we should at least let the capable ones try.
180 * o Wait for BUSY to clear at the beginning of hermes_bap_seek(). I
181 * realized that my assumption that the driver's serialization
182 * would prevent the BAP being busy on entry was possibly false, because
183 * things other than seeks may make the BAP busy.
184 * o Use "alternate" (oui 00:00:00) encapsulation by default.
185 * Setting use_old_encaps will mimic the old behaviour, but I think we
186 * will be able to eliminate this.
187 * o Don't try to make __initdata const (the version string). This can't
188 * work because of the way the __initdata sectioning works.
189 * o Added MODULE_LICENSE tags.
190 * o Support for PLX (transparent PCMCIA->PCI bridge) cards.
191 * o Changed to using the new type-fascist min/max.
192 *
193 * v0.08 -> v0.08a - 9/10/2001 - David Gibson
194 * o Inserted some missing acknowledgements/info into the Changelog.
195 * o Fixed some bugs in the normalization of signal level reporting.
196 * o Fixed bad bug in WEP key handling on Intersil and Symbol firmware,
197 * which led to an instant crash on big-endian machines.
198 *
199 * v0.08a -> v0.08b - 20/11/2001 - David Gibson
200 * o Lots of cleanup and bugfixes in orinoco_plx.c
201 * o Cleanup to handling of Tx rate setting.
202 * o Removed support for old encapsulation method.
203 * o Removed old "dldwd" names.
204 * o Split RID constants into a new file hermes_rid.h
205 * o Renamed RID constants to match linux-wlan-ng and prism2.o
206 * o Bugfixes in hermes.c
207 * o Poke the PLX's INTCSR register, so it actually starts
208 * generating interrupts. These cards might actually work now.
209 * o Update to wireless extensions v12 (Jean II)
210 * o Support for tallies and inquire command (Jean II)
211 * o Airport updates for newer PPC kernels (BenH)
212 *
213 * v0.08b -> v0.09 - 21/12/2001 - David Gibson
214 * o Some new PCI IDs for PLX cards.
215 * o Removed broken attempt to do ALLMULTI reception. Just use
216 * promiscuous mode instead
217 * o Preliminary work for list-AP (Jean II)
218 * o Airport updates from (BenH)
219 * o Eliminated racy hw_ready stuff
220 * o Fixed generation of fake events in irq handler. This should
221 * finally kill the EIO problems (Jean II & dgibson)
222 * o Fixed breakage of bitrate set/get on Agere firmware (Jean II)
223 *
224 * v0.09 -> v0.09a - 2/1/2002 - David Gibson
225 * o Fixed stupid mistake in multicast list handling, triggering
226 * a BUG()
227 *
228 * v0.09a -> v0.09b - 16/1/2002 - David Gibson
229 * o Fixed even stupider mistake in new interrupt handling, which
230 * seriously broke things on big-endian machines.
231 * o Removed a bunch of redundant includes and exports.
232 * o Removed a redundant MOD_{INC,DEC}_USE_COUNT pair in airport.c
233 * o Don't attempt to do hardware level multicast reception on
234 * Intersil firmware, just go promisc instead.
235 * o Typo fixed in hermes_issue_cmd()
236 * o Eliminated WIRELESS_SPY #ifdefs
237 * o Status code reported on Tx exceptions
238 * o Moved netif_wake_queue() from ALLOC interrupts to TX and TXEXC
239 * interrupts, which should fix the timeouts we're seeing.
240 *
241 * v0.09b -> v0.10 - 25 Feb 2002 - David Gibson
242 * o Removed nested structures used for header parsing, so the
243 * driver should now work without hackery on ARM
244 * o Fix for WEP handling on Intersil (Hawk Newton)
245 * o Eliminated the /proc/hermes/ethXX/regs debugging file. It
246 * was never very useful.
247 * o Make Rx errors less noisy.
248 *
249 * v0.10 -> v0.11 - 5 Apr 2002 - David Gibson
250 * o Laid the groundwork in hermes.[ch] for devices which map
251 * into PCI memory space rather than IO space.
252 * o Fixed bug in multicast handling (cleared multicast list when
253 * leaving promiscuous mode).
254 * o Relegated Tx error messages to debug.
255 * o Cleaned up / corrected handling of allocation lengths.
256 * o Set OWNSSID in IBSS mode for WinXP interoperability (jimc).
257 * o Change to using alloc_etherdev() for structure allocations.
258 * o Check for and drop undersized packets.
259 * o Fixed a race in stopping/waking the queue. This should fix
260 * the timeout problems (Pavel Roskin)
261 * o Reverted to netif_wake_queue() on the ALLOC event.
262 * o Fixes for recent Symbol firmwares which lack AP density
263 * (Pavel Roskin).
264 *
265 * v0.11 -> v0.11a - 29 Apr 2002 - David Gibson
266 * o Handle different register spacing, necessary for Prism 2.5
267 * PCI adaptors (Steve Hill).
268 * o Cleaned up initialization of card structures in orinoco_cs
269 * and airport. Removed card->priv field.
270 * o Make response structure optional for hermes_docmd_wait()
271 * Pavel Roskin)
272 * o Added PCI id for Nortel emobility to orinoco_plx.c.
273 * o Cleanup to handling of Symbol's allocation bug. (Pavel Roskin)
274 * o Cleanups to firmware capability detection.
275 * o Arrange for orinoco_pci.c to override firmware detection.
276 * We should be able to support the PCI Intersil cards now.
277 * o Cleanup handling of reset_cor and hard_reset (Pavel Roskin).
278 * o Remove erroneous use of USER_BAP in the TxExc handler (Jouni
279 * Malinen).
280 * o Makefile changes for better integration into David Hinds
281 * pcmcia-cs package.
282 *
283 * v0.11a -> v0.11b - 1 May 2002 - David Gibson
284 * o Better error reporting in orinoco_plx_init_one()
285 * o Fixed multiple bad kfree() bugs introduced by the
286 * alloc_orinocodev() changes.
287 *
288 * v0.11b -> v0.12 - 19 Jun 2002 - David Gibson
289 * o Support changing the MAC address.
290 * o Correct display of Intersil firmware revision numbers.
291 * o Entirely revised locking scheme. Should be both simpler and
292 * better.
293 * o Merged some common code in orinoco_plx, orinoco_pci and
294 * airport by creating orinoco_default_{open,stop,reset}()
295 * which are used as the dev->open, dev->stop, priv->reset
296 * callbacks if none are specified when alloc_orinocodev() is
297 * called.
298 * o Removed orinoco_plx_interrupt() and orinoco_pci_interrupt().
299 * They didn't do anything.
300 *
301 * v0.12 -> v0.12a - 4 Jul 2002 - David Gibson
302 * o Some rearrangement of code.
303 * o Numerous fixups to locking and rest handling, particularly
304 * for PCMCIA.
305 * o This allows open and stop net_device methods to be in
306 * orinoco.c now, rather than in the init modules.
307 * o In orinoco_cs.c link->priv now points to the struct
308 * net_device not to the struct orinoco_private.
309 * o Added a check for undersized SNAP frames, which could cause
310 * crashes.
311 *
312 * v0.12a -> v0.12b - 11 Jul 2002 - David Gibson
313 * o Fix hw->num_init testing code, so num_init is actually
314 * incremented.
315 * o Fix very stupid bug in orinoco_cs which broke compile with
316 * CONFIG_SMP.
317 * o Squashed a warning.
318 *
319 * v0.12b -> v0.12c - 26 Jul 2002 - David Gibson
320 * o Change to C9X style designated initializers.
321 * o Add support for 3Com AirConnect PCI.
322 * o No longer ignore the hard_reset argument to
323 * alloc_orinocodev(). Oops.
324 *
325 * v0.12c -> v0.13beta1 - 13 Sep 2002 - David Gibson
326 * o Revert the broken 0.12* locking scheme and go to a new yet
327 * simpler scheme.
328 * o Do firmware resets only in orinoco_init() and when waking
329 * the card from hard sleep.
330 *
331 * v0.13beta1 -> v0.13 - 27 Sep 2002 - David Gibson
332 * o Re-introduced full resets (via schedule_task()) on Tx
333 * timeout.
334 *
335 * v0.13 -> v0.13a - 30 Sep 2002 - David Gibson
336 * o Minor cleanups to info frame handling. Add basic support
337 * for linkstatus info frames.
338 * o Include required kernel headers in orinoco.h, to avoid
339 * compile problems.
340 *
341 * v0.13a -> v0.13b - 10 Feb 2003 - David Gibson
342 * o Implemented hard reset for Airport cards
343 * o Experimental suspend/resume implementation for orinoco_pci
344 * o Abolished /proc debugging support, replaced with a debugging
345 * iwpriv. Now it's ugly and simple instead of ugly and complex.
346 * o Bugfix in hermes.c if the firmware returned a record length
347 * of 0, we could go clobbering memory.
348 * o Bugfix in orinoco_stop() - it used to fail if hw_unavailable
349 * was set, which was usually true on PCMCIA hot removes.
350 * o Track LINKSTATUS messages, silently drop Tx packets before
351 * we are connected (avoids confusing the firmware), and only
352 * give LINKSTATUS printk()s if the status has changed.
353 *
354 * v0.13b -> v0.13c - 11 Mar 2003 - David Gibson
355 * o Cleanup: use dev instead of priv in various places.
356 * o Bug fix: Don't ReleaseConfiguration on RESET_PHYSICAL event
357 * if we're in the middle of a (driver initiated) hard reset.
358 * o Bug fix: ETH_ZLEN is supposed to include the header
359 * (Dionysus Blazakis & Manish Karir)
360 * o Convert to using workqueues instead of taskqueues (and
361 * backwards compatibility macros for pre 2.5.41 kernels).
362 * o Drop redundant (I think...) MOD_{INC,DEC}_USE_COUNT in
363 * airport.c
364 * o New orinoco_tmd.c init module from Joerg Dorchain for
365 * TMD7160 based PCI to PCMCIA bridges (similar to
366 * orinoco_plx.c).
367 *
368 * v0.13c -> v0.13d - 22 Apr 2003 - David Gibson
369 * o Make hw_unavailable a counter, rather than just a flag, this
370 * is necessary to avoid some races (such as a card being
371 * removed in the middle of orinoco_reset().
372 * o Restore Release/RequestConfiguration in the PCMCIA event handler
373 * when dealing with a driver initiated hard reset. This is
374 * necessary to prevent hangs due to a spurious interrupt while
375 * the reset is in progress.
376 * o Clear the 802.11 header when transmitting, even though we
377 * don't use it. This fixes a long standing bug on some
378 * firmwares, which seem to get confused if that isn't done.
379 * o Be less eager to de-encapsulate SNAP frames, only do so if
380 * the OUI is 00:00:00 or 00:00:f8, leave others alone. The old
381 * behaviour broke CDP (Cisco Discovery Protocol).
382 * o Use dev instead of priv for free_irq() as well as
383 * request_irq() (oops).
384 * o Attempt to reset rather than giving up if we get too many
385 * IRQs.
386 * o Changed semantics of __orinoco_down() so it can be called
387 * safely with hw_unavailable set. It also now clears the
388 * linkstatus (since we're going to have to reassociate).
389 *
390 * v0.13d -> v0.13e - 12 May 2003 - David Gibson
391 * o Support for post-2.5.68 return values from irq handler.
392 * o Fixed bug where underlength packets would be double counted
393 * in the rx_dropped statistics.
394 * o Provided a module parameter to suppress linkstatus messages.
395 *
396 * v0.13e -> v0.14alpha1 - 30 Sep 2003 - David Gibson
397 * o Replaced priv->connected logic with netif_carrier_on/off()
398 * calls.
399 * o Remove has_ibss_any and never set the CREATEIBSS RID when
400 * the ESSID is empty. Too many firmwares break if we do.
401 * o 2.6 merges: Replace pdev->slot_name with pci_name(), remove
402 * __devinitdata from PCI ID tables, use free_netdev().
403 * o Enabled shared-key authentication for Agere firmware (from
404 * Robert J. Moore <Robert.J.Moore AT allanbank.com>
405 * o Move netif_wake_queue() (back) to the Tx completion from the
406 * ALLOC event. This seems to prevent/mitigate the rolling
407 * error -110 problems at least on some Intersil firmwares.
408 * Theoretically reduces performance, but I can't measure it.
409 * Patch from Andrew Tridgell <tridge AT samba.org>
410 *
411 * v0.14alpha1 -> v0.14alpha2 - 20 Oct 2003 - David Gibson
412 * o Correctly turn off shared-key authentication when requested
413 * (bugfix from Robert J. Moore).
414 * o Correct airport sleep interfaces for current 2.6 kernels.
415 * o Add code for key change without disabling/enabling the MAC
416 * port. This is supposed to allow 802.1x to work sanely, but
417 * doesn't seem to yet.
418 *
419 * TODO 49 * TODO
420 * o New wireless extensions API (patch from Moustafa
421 * Youssef, updated by Jim Carter and Pavel Roskin).
422 * o Handle de-encapsulation within network layer, provide 802.11 50 * o Handle de-encapsulation within network layer, provide 802.11
423 * headers (patch from Thomas 'Dent' Mirlacher) 51 * headers (patch from Thomas 'Dent' Mirlacher)
424 * o RF monitor mode support
425 * o Fix possible races in SPY handling. 52 * o Fix possible races in SPY handling.
426 * o Disconnect wireless extensions from fundamental configuration. 53 * o Disconnect wireless extensions from fundamental configuration.
427 * o (maybe) Software WEP support (patch from Stano Meduna). 54 * o (maybe) Software WEP support (patch from Stano Meduna).
@@ -462,7 +89,10 @@
462#include <linux/netdevice.h> 89#include <linux/netdevice.h>
463#include <linux/if_arp.h> 90#include <linux/if_arp.h>
464#include <linux/etherdevice.h> 91#include <linux/etherdevice.h>
92#include <linux/ethtool.h>
465#include <linux/wireless.h> 93#include <linux/wireless.h>
94#include <net/iw_handler.h>
95#include <net/ieee80211.h>
466 96
467#include <asm/uaccess.h> 97#include <asm/uaccess.h>
468#include <asm/io.h> 98#include <asm/io.h>
@@ -496,6 +126,10 @@ static int ignore_disconnect; /* = 0 */
496module_param(ignore_disconnect, int, 0644); 126module_param(ignore_disconnect, int, 0644);
497MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer"); 127MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
498 128
129static int force_monitor; /* = 0 */
130module_param(force_monitor, int, 0644);
131MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
132
499/********************************************************************/ 133/********************************************************************/
500/* Compile time configuration and compatibility stuff */ 134/* Compile time configuration and compatibility stuff */
501/********************************************************************/ 135/********************************************************************/
@@ -511,6 +145,10 @@ MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer
511/* Internal constants */ 145/* Internal constants */
512/********************************************************************/ 146/********************************************************************/
513 147
148/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
149static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
150#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
151
514#define ORINOCO_MIN_MTU 256 152#define ORINOCO_MIN_MTU 256
515#define ORINOCO_MAX_MTU (IEEE802_11_DATA_LEN - ENCAPS_OVERHEAD) 153#define ORINOCO_MAX_MTU (IEEE802_11_DATA_LEN - ENCAPS_OVERHEAD)
516 154
@@ -537,6 +175,11 @@ MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer
537 | HERMES_EV_WTERR | HERMES_EV_INFO \ 175 | HERMES_EV_WTERR | HERMES_EV_INFO \
538 | HERMES_EV_INFDROP ) 176 | HERMES_EV_INFDROP )
539 177
178#define MAX_RID_LEN 1024
179
180static const struct iw_handler_def orinoco_handler_def;
181static struct ethtool_ops orinoco_ethtool_ops;
182
540/********************************************************************/ 183/********************************************************************/
541/* Data tables */ 184/* Data tables */
542/********************************************************************/ 185/********************************************************************/
@@ -571,26 +214,45 @@ static struct {
571/* Data types */ 214/* Data types */
572/********************************************************************/ 215/********************************************************************/
573 216
574struct header_struct { 217/* Used in Event handling.
575 /* 802.3 */ 218 * We avoid nested structres as they break on ARM -- Moustafa */
576 u8 dest[ETH_ALEN]; 219struct hermes_tx_descriptor_802_11 {
577 u8 src[ETH_ALEN]; 220 /* hermes_tx_descriptor */
578 u16 len; 221 u16 status;
579 /* 802.2 */ 222 u16 reserved1;
223 u16 reserved2;
224 u32 sw_support;
225 u8 retry_count;
226 u8 tx_rate;
227 u16 tx_control;
228
229 /* ieee802_11_hdr */
230 u16 frame_ctl;
231 u16 duration_id;
232 u8 addr1[ETH_ALEN];
233 u8 addr2[ETH_ALEN];
234 u8 addr3[ETH_ALEN];
235 u16 seq_ctl;
236 u8 addr4[ETH_ALEN];
237 u16 data_len;
238
239 /* ethhdr */
240 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
241 unsigned char h_source[ETH_ALEN]; /* source ether addr */
242 unsigned short h_proto; /* packet type ID field */
243
244 /* p8022_hdr */
580 u8 dsap; 245 u8 dsap;
581 u8 ssap; 246 u8 ssap;
582 u8 ctrl; 247 u8 ctrl;
583 /* SNAP */
584 u8 oui[3]; 248 u8 oui[3];
249
585 u16 ethertype; 250 u16 ethertype;
586} __attribute__ ((packed)); 251} __attribute__ ((packed));
587 252
588/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */ 253/* Rx frame header except compatibility 802.3 header */
589u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
590
591#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
592
593struct hermes_rx_descriptor { 254struct hermes_rx_descriptor {
255 /* Control */
594 u16 status; 256 u16 status;
595 u32 time; 257 u32 time;
596 u8 silence; 258 u8 silence;
@@ -598,13 +260,24 @@ struct hermes_rx_descriptor {
598 u8 rate; 260 u8 rate;
599 u8 rxflow; 261 u8 rxflow;
600 u32 reserved; 262 u32 reserved;
263
264 /* 802.11 header */
265 u16 frame_ctl;
266 u16 duration_id;
267 u8 addr1[ETH_ALEN];
268 u8 addr2[ETH_ALEN];
269 u8 addr3[ETH_ALEN];
270 u16 seq_ctl;
271 u8 addr4[ETH_ALEN];
272
273 /* Data length */
274 u16 data_len;
601} __attribute__ ((packed)); 275} __attribute__ ((packed));
602 276
603/********************************************************************/ 277/********************************************************************/
604/* Function prototypes */ 278/* Function prototypes */
605/********************************************************************/ 279/********************************************************************/
606 280
607static int orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
608static int __orinoco_program_rids(struct net_device *dev); 281static int __orinoco_program_rids(struct net_device *dev);
609static void __orinoco_set_multicast_list(struct net_device *dev); 282static void __orinoco_set_multicast_list(struct net_device *dev);
610 283
@@ -628,6 +301,10 @@ static inline void set_port_type(struct orinoco_private *priv)
628 priv->createibss = 1; 301 priv->createibss = 1;
629 } 302 }
630 break; 303 break;
304 case IW_MODE_MONITOR:
305 priv->port_type = 3;
306 priv->createibss = 0;
307 break;
631 default: 308 default:
632 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n", 309 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
633 priv->ndev->name); 310 priv->ndev->name);
@@ -814,7 +491,7 @@ static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
814 return 1; 491 return 1;
815 } 492 }
816 493
817 if (! netif_carrier_ok(dev)) { 494 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
818 /* Oops, the firmware hasn't established a connection, 495 /* Oops, the firmware hasn't established a connection,
819 silently drop the packet (this seems to be the 496 silently drop the packet (this seems to be the
820 safest approach). */ 497 safest approach). */
@@ -951,26 +628,55 @@ static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
951 struct orinoco_private *priv = netdev_priv(dev); 628 struct orinoco_private *priv = netdev_priv(dev);
952 struct net_device_stats *stats = &priv->stats; 629 struct net_device_stats *stats = &priv->stats;
953 u16 fid = hermes_read_regn(hw, TXCOMPLFID); 630 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
954 struct hermes_tx_descriptor desc; 631 struct hermes_tx_descriptor_802_11 hdr;
955 int err = 0; 632 int err = 0;
956 633
957 if (fid == DUMMY_FID) 634 if (fid == DUMMY_FID)
958 return; /* Nothing's really happened */ 635 return; /* Nothing's really happened */
959 636
960 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc), fid, 0); 637 /* Read the frame header */
638 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
639 sizeof(struct hermes_tx_descriptor) +
640 sizeof(struct ieee80211_hdr),
641 fid, 0);
642
643 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
644 stats->tx_errors++;
645
961 if (err) { 646 if (err) {
962 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error " 647 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
963 "(FID=%04X error %d)\n", 648 "(FID=%04X error %d)\n",
964 dev->name, fid, err); 649 dev->name, fid, err);
965 } else { 650 return;
966 DEBUG(1, "%s: Tx error, status %d\n",
967 dev->name, le16_to_cpu(desc.status));
968 } 651 }
969 652
970 stats->tx_errors++; 653 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
654 err, fid);
655
656 /* We produce a TXDROP event only for retry or lifetime
657 * exceeded, because that's the only status that really mean
658 * that this particular node went away.
659 * Other errors means that *we* screwed up. - Jean II */
660 hdr.status = le16_to_cpu(hdr.status);
661 if (hdr.status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
662 union iwreq_data wrqu;
663
664 /* Copy 802.11 dest address.
665 * We use the 802.11 header because the frame may
666 * not be 802.3 or may be mangled...
667 * In Ad-Hoc mode, it will be the node address.
668 * In managed mode, it will be most likely the AP addr
669 * User space will figure out how to convert it to
670 * whatever it needs (IP address or else).
671 * - Jean II */
672 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
673 wrqu.addr.sa_family = ARPHRD_ETHER;
674
675 /* Send event to user space */
676 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
677 }
971 678
972 netif_wake_queue(dev); 679 netif_wake_queue(dev);
973 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
974} 680}
975 681
976static void orinoco_tx_timeout(struct net_device *dev) 682static void orinoco_tx_timeout(struct net_device *dev)
@@ -1047,18 +753,127 @@ static void orinoco_stat_gather(struct net_device *dev,
1047 } 753 }
1048} 754}
1049 755
756/*
757 * orinoco_rx_monitor - handle received monitor frames.
758 *
759 * Arguments:
760 * dev network device
761 * rxfid received FID
762 * desc rx descriptor of the frame
763 *
764 * Call context: interrupt
765 */
766static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
767 struct hermes_rx_descriptor *desc)
768{
769 u32 hdrlen = 30; /* return full header by default */
770 u32 datalen = 0;
771 u16 fc;
772 int err;
773 int len;
774 struct sk_buff *skb;
775 struct orinoco_private *priv = netdev_priv(dev);
776 struct net_device_stats *stats = &priv->stats;
777 hermes_t *hw = &priv->hw;
778
779 len = le16_to_cpu(desc->data_len);
780
781 /* Determine the size of the header and the data */
782 fc = le16_to_cpu(desc->frame_ctl);
783 switch (fc & IEEE80211_FCTL_FTYPE) {
784 case IEEE80211_FTYPE_DATA:
785 if ((fc & IEEE80211_FCTL_TODS)
786 && (fc & IEEE80211_FCTL_FROMDS))
787 hdrlen = 30;
788 else
789 hdrlen = 24;
790 datalen = len;
791 break;
792 case IEEE80211_FTYPE_MGMT:
793 hdrlen = 24;
794 datalen = len;
795 break;
796 case IEEE80211_FTYPE_CTL:
797 switch (fc & IEEE80211_FCTL_STYPE) {
798 case IEEE80211_STYPE_PSPOLL:
799 case IEEE80211_STYPE_RTS:
800 case IEEE80211_STYPE_CFEND:
801 case IEEE80211_STYPE_CFENDACK:
802 hdrlen = 16;
803 break;
804 case IEEE80211_STYPE_CTS:
805 case IEEE80211_STYPE_ACK:
806 hdrlen = 10;
807 break;
808 }
809 break;
810 default:
811 /* Unknown frame type */
812 break;
813 }
814
815 /* sanity check the length */
816 if (datalen > IEEE80211_DATA_LEN + 12) {
817 printk(KERN_DEBUG "%s: oversized monitor frame, "
818 "data length = %d\n", dev->name, datalen);
819 err = -EIO;
820 stats->rx_length_errors++;
821 goto update_stats;
822 }
823
824 skb = dev_alloc_skb(hdrlen + datalen);
825 if (!skb) {
826 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
827 dev->name);
828 err = -ENOMEM;
829 goto drop;
830 }
831
832 /* Copy the 802.11 header to the skb */
833 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
834 skb->mac.raw = skb->data;
835
836 /* If any, copy the data from the card to the skb */
837 if (datalen > 0) {
838 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
839 ALIGN(datalen, 2), rxfid,
840 HERMES_802_2_OFFSET);
841 if (err) {
842 printk(KERN_ERR "%s: error %d reading monitor frame\n",
843 dev->name, err);
844 goto drop;
845 }
846 }
847
848 skb->dev = dev;
849 skb->ip_summed = CHECKSUM_NONE;
850 skb->pkt_type = PACKET_OTHERHOST;
851 skb->protocol = __constant_htons(ETH_P_802_2);
852
853 dev->last_rx = jiffies;
854 stats->rx_packets++;
855 stats->rx_bytes += skb->len;
856
857 netif_rx(skb);
858 return;
859
860 drop:
861 dev_kfree_skb_irq(skb);
862 update_stats:
863 stats->rx_errors++;
864 stats->rx_dropped++;
865}
866
1050static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw) 867static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1051{ 868{
1052 struct orinoco_private *priv = netdev_priv(dev); 869 struct orinoco_private *priv = netdev_priv(dev);
1053 struct net_device_stats *stats = &priv->stats; 870 struct net_device_stats *stats = &priv->stats;
1054 struct iw_statistics *wstats = &priv->wstats; 871 struct iw_statistics *wstats = &priv->wstats;
1055 struct sk_buff *skb = NULL; 872 struct sk_buff *skb = NULL;
1056 u16 rxfid, status; 873 u16 rxfid, status, fc;
1057 int length, data_len, data_off; 874 int length;
1058 char *p;
1059 struct hermes_rx_descriptor desc; 875 struct hermes_rx_descriptor desc;
1060 struct header_struct hdr; 876 struct ethhdr *hdr;
1061 struct ethhdr *eh;
1062 int err; 877 int err;
1063 878
1064 rxfid = hermes_read_regn(hw, RXFID); 879 rxfid = hermes_read_regn(hw, RXFID);
@@ -1068,53 +883,46 @@ static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1068 if (err) { 883 if (err) {
1069 printk(KERN_ERR "%s: error %d reading Rx descriptor. " 884 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1070 "Frame dropped.\n", dev->name, err); 885 "Frame dropped.\n", dev->name, err);
1071 stats->rx_errors++; 886 goto update_stats;
1072 goto drop;
1073 } 887 }
1074 888
1075 status = le16_to_cpu(desc.status); 889 status = le16_to_cpu(desc.status);
1076 890
1077 if (status & HERMES_RXSTAT_ERR) { 891 if (status & HERMES_RXSTAT_BADCRC) {
1078 if (status & HERMES_RXSTAT_UNDECRYPTABLE) { 892 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1079 wstats->discard.code++; 893 dev->name);
1080 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n", 894 stats->rx_crc_errors++;
1081 dev->name); 895 goto update_stats;
1082 } else {
1083 stats->rx_crc_errors++;
1084 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", dev->name);
1085 }
1086 stats->rx_errors++;
1087 goto drop;
1088 } 896 }
1089 897
1090 /* For now we ignore the 802.11 header completely, assuming 898 /* Handle frames in monitor mode */
1091 that the card's firmware has handled anything vital */ 899 if (priv->iw_mode == IW_MODE_MONITOR) {
900 orinoco_rx_monitor(dev, rxfid, &desc);
901 return;
902 }
1092 903
1093 err = hermes_bap_pread(hw, IRQ_BAP, &hdr, sizeof(hdr), 904 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1094 rxfid, HERMES_802_3_OFFSET); 905 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1095 if (err) { 906 dev->name);
1096 printk(KERN_ERR "%s: error %d reading frame header. " 907 wstats->discard.code++;
1097 "Frame dropped.\n", dev->name, err); 908 goto update_stats;
1098 stats->rx_errors++;
1099 goto drop;
1100 } 909 }
1101 910
1102 length = ntohs(hdr.len); 911 length = le16_to_cpu(desc.data_len);
1103 912 fc = le16_to_cpu(desc.frame_ctl);
913
1104 /* Sanity checks */ 914 /* Sanity checks */
1105 if (length < 3) { /* No for even an 802.2 LLC header */ 915 if (length < 3) { /* No for even an 802.2 LLC header */
1106 /* At least on Symbol firmware with PCF we get quite a 916 /* At least on Symbol firmware with PCF we get quite a
1107 lot of these legitimately - Poll frames with no 917 lot of these legitimately - Poll frames with no
1108 data. */ 918 data. */
1109 stats->rx_dropped++; 919 return;
1110 goto drop;
1111 } 920 }
1112 if (length > IEEE802_11_DATA_LEN) { 921 if (length > IEEE802_11_DATA_LEN) {
1113 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n", 922 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1114 dev->name, length); 923 dev->name, length);
1115 stats->rx_length_errors++; 924 stats->rx_length_errors++;
1116 stats->rx_errors++; 925 goto update_stats;
1117 goto drop;
1118 } 926 }
1119 927
1120 /* We need space for the packet data itself, plus an ethernet 928 /* We need space for the packet data itself, plus an ethernet
@@ -1126,60 +934,53 @@ static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1126 if (!skb) { 934 if (!skb) {
1127 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n", 935 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1128 dev->name); 936 dev->name);
1129 goto drop; 937 goto update_stats;
1130 } 938 }
1131 939
1132 skb_reserve(skb, 2); /* This way the IP header is aligned */ 940 /* We'll prepend the header, so reserve space for it. The worst
941 case is no decapsulation, when 802.3 header is prepended and
942 nothing is removed. 2 is for aligning the IP header. */
943 skb_reserve(skb, ETH_HLEN + 2);
944
945 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
946 ALIGN(length, 2), rxfid,
947 HERMES_802_2_OFFSET);
948 if (err) {
949 printk(KERN_ERR "%s: error %d reading frame. "
950 "Frame dropped.\n", dev->name, err);
951 goto drop;
952 }
1133 953
1134 /* Handle decapsulation 954 /* Handle decapsulation
1135 * In most cases, the firmware tell us about SNAP frames. 955 * In most cases, the firmware tell us about SNAP frames.
1136 * For some reason, the SNAP frames sent by LinkSys APs 956 * For some reason, the SNAP frames sent by LinkSys APs
1137 * are not properly recognised by most firmwares. 957 * are not properly recognised by most firmwares.
1138 * So, check ourselves */ 958 * So, check ourselves */
1139 if (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) || 959 if (length >= ENCAPS_OVERHEAD &&
1140 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) || 960 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1141 is_ethersnap(&hdr)) { 961 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
962 is_ethersnap(skb->data))) {
1142 /* These indicate a SNAP within 802.2 LLC within 963 /* These indicate a SNAP within 802.2 LLC within
1143 802.11 frame which we'll need to de-encapsulate to 964 802.11 frame which we'll need to de-encapsulate to
1144 the original EthernetII frame. */ 965 the original EthernetII frame. */
1145 966 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
1146 if (length < ENCAPS_OVERHEAD) { /* No room for full LLC+SNAP */
1147 stats->rx_length_errors++;
1148 goto drop;
1149 }
1150
1151 /* Remove SNAP header, reconstruct EthernetII frame */
1152 data_len = length - ENCAPS_OVERHEAD;
1153 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
1154
1155 eh = (struct ethhdr *)skb_put(skb, ETH_HLEN);
1156
1157 memcpy(eh, &hdr, 2 * ETH_ALEN);
1158 eh->h_proto = hdr.ethertype;
1159 } else { 967 } else {
1160 /* All other cases indicate a genuine 802.3 frame. No 968 /* 802.3 frame - prepend 802.3 header as is */
1161 decapsulation needed. We just throw the whole 969 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1162 thing in, and hope the protocol layer can deal with 970 hdr->h_proto = htons(length);
1163 it as 802.3 */
1164 data_len = length;
1165 data_off = HERMES_802_3_OFFSET;
1166 /* FIXME: we re-read from the card data we already read here */
1167 }
1168
1169 p = skb_put(skb, data_len);
1170 err = hermes_bap_pread(hw, IRQ_BAP, p, ALIGN(data_len, 2),
1171 rxfid, data_off);
1172 if (err) {
1173 printk(KERN_ERR "%s: error %d reading frame. "
1174 "Frame dropped.\n", dev->name, err);
1175 stats->rx_errors++;
1176 goto drop;
1177 } 971 }
972 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
973 if (fc & IEEE80211_FCTL_FROMDS)
974 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
975 else
976 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
1178 977
1179 dev->last_rx = jiffies; 978 dev->last_rx = jiffies;
1180 skb->dev = dev; 979 skb->dev = dev;
1181 skb->protocol = eth_type_trans(skb, dev); 980 skb->protocol = eth_type_trans(skb, dev);
1182 skb->ip_summed = CHECKSUM_NONE; 981 skb->ip_summed = CHECKSUM_NONE;
982 if (fc & IEEE80211_FCTL_TODS)
983 skb->pkt_type = PACKET_OTHERHOST;
1183 984
1184 /* Process the wireless stats if needed */ 985 /* Process the wireless stats if needed */
1185 orinoco_stat_gather(dev, skb, &desc); 986 orinoco_stat_gather(dev, skb, &desc);
@@ -1192,11 +993,10 @@ static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1192 return; 993 return;
1193 994
1194 drop: 995 drop:
996 dev_kfree_skb_irq(skb);
997 update_stats:
998 stats->rx_errors++;
1195 stats->rx_dropped++; 999 stats->rx_dropped++;
1196
1197 if (skb)
1198 dev_kfree_skb_irq(skb);
1199 return;
1200} 1000}
1201 1001
1202/********************************************************************/ 1002/********************************************************************/
@@ -1240,6 +1040,99 @@ static void print_linkstatus(struct net_device *dev, u16 status)
1240 dev->name, s, status); 1040 dev->name, s, status);
1241} 1041}
1242 1042
1043/* Search scan results for requested BSSID, join it if found */
1044static void orinoco_join_ap(struct net_device *dev)
1045{
1046 struct orinoco_private *priv = netdev_priv(dev);
1047 struct hermes *hw = &priv->hw;
1048 int err;
1049 unsigned long flags;
1050 struct join_req {
1051 u8 bssid[ETH_ALEN];
1052 u16 channel;
1053 } __attribute__ ((packed)) req;
1054 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1055 struct prism2_scan_apinfo *atom;
1056 int offset = 4;
1057 u8 *buf;
1058 u16 len;
1059
1060 /* Allocate buffer for scan results */
1061 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1062 if (! buf)
1063 return;
1064
1065 if (orinoco_lock(priv, &flags) != 0)
1066 goto out;
1067
1068 /* Sanity checks in case user changed something in the meantime */
1069 if (! priv->bssid_fixed)
1070 goto out;
1071
1072 if (strlen(priv->desired_essid) == 0)
1073 goto out;
1074
1075 /* Read scan results from the firmware */
1076 err = hermes_read_ltv(hw, USER_BAP,
1077 HERMES_RID_SCANRESULTSTABLE,
1078 MAX_SCAN_LEN, &len, buf);
1079 if (err) {
1080 printk(KERN_ERR "%s: Cannot read scan results\n",
1081 dev->name);
1082 goto out;
1083 }
1084
1085 len = HERMES_RECLEN_TO_BYTES(len);
1086
1087 /* Go through the scan results looking for the channel of the AP
1088 * we were requested to join */
1089 for (; offset + atom_len <= len; offset += atom_len) {
1090 atom = (struct prism2_scan_apinfo *) (buf + offset);
1091 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0)
1092 goto found;
1093 }
1094
1095 DEBUG(1, "%s: Requested AP not found in scan results\n",
1096 dev->name);
1097 goto out;
1098
1099 found:
1100 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1101 req.channel = atom->channel; /* both are little-endian */
1102 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1103 &req);
1104 if (err)
1105 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1106
1107 out:
1108 kfree(buf);
1109 orinoco_unlock(priv, &flags);
1110}
1111
1112/* Send new BSSID to userspace */
1113static void orinoco_send_wevents(struct net_device *dev)
1114{
1115 struct orinoco_private *priv = netdev_priv(dev);
1116 struct hermes *hw = &priv->hw;
1117 union iwreq_data wrqu;
1118 int err;
1119 unsigned long flags;
1120
1121 if (orinoco_lock(priv, &flags) != 0)
1122 return;
1123
1124 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1125 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1126 if (err != 0)
1127 return;
1128
1129 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1130
1131 /* Send event to user space */
1132 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1133 orinoco_unlock(priv, &flags);
1134}
1135
1243static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw) 1136static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1244{ 1137{
1245 struct orinoco_private *priv = netdev_priv(dev); 1138 struct orinoco_private *priv = netdev_priv(dev);
@@ -1307,6 +1200,9 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1307 u16 newstatus; 1200 u16 newstatus;
1308 int connected; 1201 int connected;
1309 1202
1203 if (priv->iw_mode == IW_MODE_MONITOR)
1204 break;
1205
1310 if (len != sizeof(linkstatus)) { 1206 if (len != sizeof(linkstatus)) {
1311 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n", 1207 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1312 dev->name, len); 1208 dev->name, len);
@@ -1319,6 +1215,15 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1319 break; 1215 break;
1320 newstatus = le16_to_cpu(linkstatus.linkstatus); 1216 newstatus = le16_to_cpu(linkstatus.linkstatus);
1321 1217
1218 /* Symbol firmware uses "out of range" to signal that
1219 * the hostscan frame can be requested. */
1220 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1221 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1222 priv->has_hostscan && priv->scan_inprogress) {
1223 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1224 break;
1225 }
1226
1322 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED) 1227 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1323 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE) 1228 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1324 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE); 1229 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
@@ -1328,12 +1233,89 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1328 else if (!ignore_disconnect) 1233 else if (!ignore_disconnect)
1329 netif_carrier_off(dev); 1234 netif_carrier_off(dev);
1330 1235
1331 if (newstatus != priv->last_linkstatus) 1236 if (newstatus != priv->last_linkstatus) {
1237 priv->last_linkstatus = newstatus;
1332 print_linkstatus(dev, newstatus); 1238 print_linkstatus(dev, newstatus);
1239 /* The info frame contains only one word which is the
1240 * status (see hermes.h). The status is pretty boring
1241 * in itself, that's why we export the new BSSID...
1242 * Jean II */
1243 schedule_work(&priv->wevent_work);
1244 }
1245 }
1246 break;
1247 case HERMES_INQ_SCAN:
1248 if (!priv->scan_inprogress && priv->bssid_fixed &&
1249 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1250 schedule_work(&priv->join_work);
1251 break;
1252 }
1253 /* fall through */
1254 case HERMES_INQ_HOSTSCAN:
1255 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1256 /* Result of a scanning. Contains information about
1257 * cells in the vicinity - Jean II */
1258 union iwreq_data wrqu;
1259 unsigned char *buf;
1260
1261 /* Sanity check */
1262 if (len > 4096) {
1263 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1264 dev->name, len);
1265 break;
1266 }
1333 1267
1334 priv->last_linkstatus = newstatus; 1268 /* We are a strict producer. If the previous scan results
1269 * have not been consumed, we just have to drop this
1270 * frame. We can't remove the previous results ourselves,
1271 * that would be *very* racy... Jean II */
1272 if (priv->scan_result != NULL) {
1273 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1274 break;
1275 }
1276
1277 /* Allocate buffer for results */
1278 buf = kmalloc(len, GFP_ATOMIC);
1279 if (buf == NULL)
1280 /* No memory, so can't printk()... */
1281 break;
1282
1283 /* Read scan data */
1284 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1285 infofid, sizeof(info));
1286 if (err)
1287 break;
1288
1289#ifdef ORINOCO_DEBUG
1290 {
1291 int i;
1292 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1293 for(i = 1; i < (len * 2); i++)
1294 printk(":%02X", buf[i]);
1295 printk("]\n");
1296 }
1297#endif /* ORINOCO_DEBUG */
1298
1299 /* Allow the clients to access the results */
1300 priv->scan_len = len;
1301 priv->scan_result = buf;
1302
1303 /* Send an empty event to user space.
1304 * We don't send the received data on the event because
1305 * it would require us to do complex transcoding, and
1306 * we want to minimise the work done in the irq handler
1307 * Use a request to extract the data - Jean II */
1308 wrqu.data.length = 0;
1309 wrqu.data.flags = 0;
1310 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1335 } 1311 }
1336 break; 1312 break;
1313 case HERMES_INQ_SEC_STAT_AGERE:
1314 /* Security status (Agere specific) */
1315 /* Ignore this frame for now */
1316 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1317 break;
1318 /* fall through */
1337 default: 1319 default:
1338 printk(KERN_DEBUG "%s: Unknown information frame received: " 1320 printk(KERN_DEBUG "%s: Unknown information frame received: "
1339 "type 0x%04x, length %d\n", dev->name, type, len); 1321 "type 0x%04x, length %d\n", dev->name, type, len);
@@ -1470,6 +1452,36 @@ static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1470 return err; 1452 return err;
1471} 1453}
1472 1454
1455/* Set fixed AP address */
1456static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1457{
1458 int roaming_flag;
1459 int err = 0;
1460 hermes_t *hw = &priv->hw;
1461
1462 switch (priv->firmware_type) {
1463 case FIRMWARE_TYPE_AGERE:
1464 /* not supported */
1465 break;
1466 case FIRMWARE_TYPE_INTERSIL:
1467 if (priv->bssid_fixed)
1468 roaming_flag = 2;
1469 else
1470 roaming_flag = 1;
1471
1472 err = hermes_write_wordrec(hw, USER_BAP,
1473 HERMES_RID_CNFROAMINGMODE,
1474 roaming_flag);
1475 break;
1476 case FIRMWARE_TYPE_SYMBOL:
1477 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1478 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1479 &priv->desired_bssid);
1480 break;
1481 }
1482 return err;
1483}
1484
1473/* Change the WEP keys and/or the current keys. Can be called 1485/* Change the WEP keys and/or the current keys. Can be called
1474 * either from __orinoco_hw_setup_wep() or directly from 1486 * either from __orinoco_hw_setup_wep() or directly from
1475 * orinoco_ioctl_setiwencode(). In the later case the association 1487 * orinoco_ioctl_setiwencode(). In the later case the association
@@ -1655,6 +1667,13 @@ static int __orinoco_program_rids(struct net_device *dev)
1655 } 1667 }
1656 } 1668 }
1657 1669
1670 /* Set the desired BSSID */
1671 err = __orinoco_hw_set_wap(priv);
1672 if (err) {
1673 printk(KERN_ERR "%s: Error %d setting AP address\n",
1674 dev->name, err);
1675 return err;
1676 }
1658 /* Set the desired ESSID */ 1677 /* Set the desired ESSID */
1659 idbuf.len = cpu_to_le16(strlen(priv->desired_essid)); 1678 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1660 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val)); 1679 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
@@ -1793,6 +1812,20 @@ static int __orinoco_program_rids(struct net_device *dev)
1793 } 1812 }
1794 } 1813 }
1795 1814
1815 if (priv->iw_mode == IW_MODE_MONITOR) {
1816 /* Enable monitor mode */
1817 dev->type = ARPHRD_IEEE80211;
1818 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1819 HERMES_TEST_MONITOR, 0, NULL);
1820 } else {
1821 /* Disable monitor mode */
1822 dev->type = ARPHRD_ETHER;
1823 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1824 HERMES_TEST_STOP, 0, NULL);
1825 }
1826 if (err)
1827 return err;
1828
1796 /* Set promiscuity / multicast*/ 1829 /* Set promiscuity / multicast*/
1797 priv->promiscuous = 0; 1830 priv->promiscuous = 0;
1798 priv->mc_count = 0; 1831 priv->mc_count = 0;
@@ -1869,55 +1902,6 @@ __orinoco_set_multicast_list(struct net_device *dev)
1869 dev->flags &= ~IFF_PROMISC; 1902 dev->flags &= ~IFF_PROMISC;
1870} 1903}
1871 1904
1872static int orinoco_reconfigure(struct net_device *dev)
1873{
1874 struct orinoco_private *priv = netdev_priv(dev);
1875 struct hermes *hw = &priv->hw;
1876 unsigned long flags;
1877 int err = 0;
1878
1879 if (priv->broken_disableport) {
1880 schedule_work(&priv->reset_work);
1881 return 0;
1882 }
1883
1884 if (orinoco_lock(priv, &flags) != 0)
1885 return -EBUSY;
1886
1887 err = hermes_disable_port(hw, 0);
1888 if (err) {
1889 printk(KERN_WARNING "%s: Unable to disable port while reconfiguring card\n",
1890 dev->name);
1891 priv->broken_disableport = 1;
1892 goto out;
1893 }
1894
1895 err = __orinoco_program_rids(dev);
1896 if (err) {
1897 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
1898 dev->name);
1899 goto out;
1900 }
1901
1902 err = hermes_enable_port(hw, 0);
1903 if (err) {
1904 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
1905 dev->name);
1906 goto out;
1907 }
1908
1909 out:
1910 if (err) {
1911 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
1912 schedule_work(&priv->reset_work);
1913 err = 0;
1914 }
1915
1916 orinoco_unlock(priv, &flags);
1917 return err;
1918
1919}
1920
1921/* This must be called from user context, without locks held - use 1905/* This must be called from user context, without locks held - use
1922 * schedule_work() */ 1906 * schedule_work() */
1923static void orinoco_reset(struct net_device *dev) 1907static void orinoco_reset(struct net_device *dev)
@@ -1946,6 +1930,11 @@ static void orinoco_reset(struct net_device *dev)
1946 1930
1947 orinoco_unlock(priv, &flags); 1931 orinoco_unlock(priv, &flags);
1948 1932
1933 /* Scanning support: Cleanup of driver struct */
1934 kfree(priv->scan_result);
1935 priv->scan_result = NULL;
1936 priv->scan_inprogress = 0;
1937
1949 if (priv->hard_reset) { 1938 if (priv->hard_reset) {
1950 err = (*priv->hard_reset)(priv); 1939 err = (*priv->hard_reset)(priv);
1951 if (err) { 1940 if (err) {
@@ -2184,6 +2173,8 @@ static int determine_firmware(struct net_device *dev)
2184 priv->has_mwo = (firmver >= 0x60000); 2173 priv->has_mwo = (firmver >= 0x60000);
2185 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */ 2174 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2186 priv->ibss_port = 1; 2175 priv->ibss_port = 1;
2176 priv->has_hostscan = (firmver >= 0x8000a);
2177 priv->broken_monitor = (firmver >= 0x80000);
2187 2178
2188 /* Tested with Agere firmware : 2179 /* Tested with Agere firmware :
2189 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II 2180 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
@@ -2229,6 +2220,8 @@ static int determine_firmware(struct net_device *dev)
2229 priv->ibss_port = 4; 2220 priv->ibss_port = 4;
2230 priv->broken_disableport = (firmver == 0x25013) || 2221 priv->broken_disableport = (firmver == 0x25013) ||
2231 (firmver >= 0x30000 && firmver <= 0x31000); 2222 (firmver >= 0x30000 && firmver <= 0x31000);
2223 priv->has_hostscan = (firmver >= 0x31001) ||
2224 (firmver >= 0x29057 && firmver < 0x30000);
2232 /* Tested with Intel firmware : 0x20015 => Jean II */ 2225 /* Tested with Intel firmware : 0x20015 => Jean II */
2233 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */ 2226 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2234 break; 2227 break;
@@ -2248,6 +2241,7 @@ static int determine_firmware(struct net_device *dev)
2248 priv->has_ibss = (firmver >= 0x000700); /* FIXME */ 2241 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2249 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800); 2242 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2250 priv->has_pm = (firmver >= 0x000700); 2243 priv->has_pm = (firmver >= 0x000700);
2244 priv->has_hostscan = (firmver >= 0x010301);
2251 2245
2252 if (firmver >= 0x000800) 2246 if (firmver >= 0x000800)
2253 priv->ibss_port = 0; 2247 priv->ibss_port = 0;
@@ -2456,8 +2450,9 @@ struct net_device *alloc_orinocodev(int sizeof_card,
2456 dev->tx_timeout = orinoco_tx_timeout; 2450 dev->tx_timeout = orinoco_tx_timeout;
2457 dev->watchdog_timeo = HZ; /* 1 second timeout */ 2451 dev->watchdog_timeo = HZ; /* 1 second timeout */
2458 dev->get_stats = orinoco_get_stats; 2452 dev->get_stats = orinoco_get_stats;
2453 dev->ethtool_ops = &orinoco_ethtool_ops;
2459 dev->get_wireless_stats = orinoco_get_wireless_stats; 2454 dev->get_wireless_stats = orinoco_get_wireless_stats;
2460 dev->do_ioctl = orinoco_ioctl; 2455 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2461 dev->change_mtu = orinoco_change_mtu; 2456 dev->change_mtu = orinoco_change_mtu;
2462 dev->set_multicast_list = orinoco_set_multicast_list; 2457 dev->set_multicast_list = orinoco_set_multicast_list;
2463 /* we use the default eth_mac_addr for setting the MAC addr */ 2458 /* we use the default eth_mac_addr for setting the MAC addr */
@@ -2473,6 +2468,8 @@ struct net_device *alloc_orinocodev(int sizeof_card,
2473 * before anything else touches the 2468 * before anything else touches the
2474 * hardware */ 2469 * hardware */
2475 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev); 2470 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
2471 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
2472 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
2476 2473
2477 netif_carrier_off(dev); 2474 netif_carrier_off(dev);
2478 priv->last_linkstatus = 0xffff; 2475 priv->last_linkstatus = 0xffff;
@@ -2483,6 +2480,9 @@ struct net_device *alloc_orinocodev(int sizeof_card,
2483 2480
2484void free_orinocodev(struct net_device *dev) 2481void free_orinocodev(struct net_device *dev)
2485{ 2482{
2483 struct orinoco_private *priv = netdev_priv(dev);
2484
2485 kfree(priv->scan_result);
2486 free_netdev(dev); 2486 free_netdev(dev);
2487} 2487}
2488 2488
@@ -2490,24 +2490,6 @@ void free_orinocodev(struct net_device *dev)
2490/* Wireless extensions */ 2490/* Wireless extensions */
2491/********************************************************************/ 2491/********************************************************************/
2492 2492
2493static int orinoco_hw_get_bssid(struct orinoco_private *priv,
2494 char buf[ETH_ALEN])
2495{
2496 hermes_t *hw = &priv->hw;
2497 int err = 0;
2498 unsigned long flags;
2499
2500 if (orinoco_lock(priv, &flags) != 0)
2501 return -EBUSY;
2502
2503 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2504 ETH_ALEN, NULL, buf);
2505
2506 orinoco_unlock(priv, &flags);
2507
2508 return err;
2509}
2510
2511static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active, 2493static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2512 char buf[IW_ESSID_MAX_SIZE+1]) 2494 char buf[IW_ESSID_MAX_SIZE+1])
2513{ 2495{
@@ -2633,140 +2615,271 @@ static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2633 return 0; 2615 return 0;
2634} 2616}
2635 2617
2636static int orinoco_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq) 2618static int orinoco_ioctl_getname(struct net_device *dev,
2619 struct iw_request_info *info,
2620 char *name,
2621 char *extra)
2637{ 2622{
2638 struct orinoco_private *priv = netdev_priv(dev); 2623 struct orinoco_private *priv = netdev_priv(dev);
2639 int err = 0;
2640 int mode;
2641 struct iw_range range;
2642 int numrates; 2624 int numrates;
2643 int i, k; 2625 int err;
2626
2627 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2628
2629 if (!err && (numrates > 2))
2630 strcpy(name, "IEEE 802.11b");
2631 else
2632 strcpy(name, "IEEE 802.11-DS");
2633
2634 return 0;
2635}
2636
2637static int orinoco_ioctl_setwap(struct net_device *dev,
2638 struct iw_request_info *info,
2639 struct sockaddr *ap_addr,
2640 char *extra)
2641{
2642 struct orinoco_private *priv = netdev_priv(dev);
2643 int err = -EINPROGRESS; /* Call commit handler */
2644 unsigned long flags; 2644 unsigned long flags;
2645 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2646 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2645 2647
2646 TRACE_ENTER(dev->name); 2648 if (orinoco_lock(priv, &flags) != 0)
2649 return -EBUSY;
2650
2651 /* Enable automatic roaming - no sanity checks are needed */
2652 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2653 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2654 priv->bssid_fixed = 0;
2655 memset(priv->desired_bssid, 0, ETH_ALEN);
2656
2657 /* "off" means keep existing connection */
2658 if (ap_addr->sa_data[0] == 0) {
2659 __orinoco_hw_set_wap(priv);
2660 err = 0;
2661 }
2662 goto out;
2663 }
2664
2665 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2666 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2667 "support manual roaming\n",
2668 dev->name);
2669 err = -EOPNOTSUPP;
2670 goto out;
2671 }
2672
2673 if (priv->iw_mode != IW_MODE_INFRA) {
2674 printk(KERN_WARNING "%s: Manual roaming supported only in "
2675 "managed mode\n", dev->name);
2676 err = -EOPNOTSUPP;
2677 goto out;
2678 }
2679
2680 /* Intersil firmware hangs without Desired ESSID */
2681 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2682 strlen(priv->desired_essid) == 0) {
2683 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2684 "manual roaming\n", dev->name);
2685 err = -EOPNOTSUPP;
2686 goto out;
2687 }
2688
2689 /* Finally, enable manual roaming */
2690 priv->bssid_fixed = 1;
2691 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2692
2693 out:
2694 orinoco_unlock(priv, &flags);
2695 return err;
2696}
2697
2698static int orinoco_ioctl_getwap(struct net_device *dev,
2699 struct iw_request_info *info,
2700 struct sockaddr *ap_addr,
2701 char *extra)
2702{
2703 struct orinoco_private *priv = netdev_priv(dev);
2704
2705 hermes_t *hw = &priv->hw;
2706 int err = 0;
2707 unsigned long flags;
2708
2709 if (orinoco_lock(priv, &flags) != 0)
2710 return -EBUSY;
2711
2712 ap_addr->sa_family = ARPHRD_ETHER;
2713 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2714 ETH_ALEN, NULL, ap_addr->sa_data);
2715
2716 orinoco_unlock(priv, &flags);
2717
2718 return err;
2719}
2647 2720
2648 if (!access_ok(VERIFY_WRITE, rrq->pointer, sizeof(range))) 2721static int orinoco_ioctl_setmode(struct net_device *dev,
2649 return -EFAULT; 2722 struct iw_request_info *info,
2723 u32 *mode,
2724 char *extra)
2725{
2726 struct orinoco_private *priv = netdev_priv(dev);
2727 int err = -EINPROGRESS; /* Call commit handler */
2728 unsigned long flags;
2650 2729
2651 rrq->length = sizeof(range); 2730 if (priv->iw_mode == *mode)
2731 return 0;
2652 2732
2653 if (orinoco_lock(priv, &flags) != 0) 2733 if (orinoco_lock(priv, &flags) != 0)
2654 return -EBUSY; 2734 return -EBUSY;
2655 2735
2656 mode = priv->iw_mode; 2736 switch (*mode) {
2737 case IW_MODE_ADHOC:
2738 if (!priv->has_ibss && !priv->has_port3)
2739 err = -EOPNOTSUPP;
2740 break;
2741
2742 case IW_MODE_INFRA:
2743 break;
2744
2745 case IW_MODE_MONITOR:
2746 if (priv->broken_monitor && !force_monitor) {
2747 printk(KERN_WARNING "%s: Monitor mode support is "
2748 "buggy in this firmware, not enabling\n",
2749 dev->name);
2750 err = -EOPNOTSUPP;
2751 }
2752 break;
2753
2754 default:
2755 err = -EOPNOTSUPP;
2756 break;
2757 }
2758
2759 if (err == -EINPROGRESS) {
2760 priv->iw_mode = *mode;
2761 set_port_type(priv);
2762 }
2763
2657 orinoco_unlock(priv, &flags); 2764 orinoco_unlock(priv, &flags);
2658 2765
2659 memset(&range, 0, sizeof(range)); 2766 return err;
2767}
2768
2769static int orinoco_ioctl_getmode(struct net_device *dev,
2770 struct iw_request_info *info,
2771 u32 *mode,
2772 char *extra)
2773{
2774 struct orinoco_private *priv = netdev_priv(dev);
2775
2776 *mode = priv->iw_mode;
2777 return 0;
2778}
2779
2780static int orinoco_ioctl_getiwrange(struct net_device *dev,
2781 struct iw_request_info *info,
2782 struct iw_point *rrq,
2783 char *extra)
2784{
2785 struct orinoco_private *priv = netdev_priv(dev);
2786 int err = 0;
2787 struct iw_range *range = (struct iw_range *) extra;
2788 int numrates;
2789 int i, k;
2790
2791 TRACE_ENTER(dev->name);
2660 2792
2661 /* Much of this shamelessly taken from wvlan_cs.c. No idea 2793 rrq->length = sizeof(struct iw_range);
2662 * what it all means -dgibson */ 2794 memset(range, 0, sizeof(struct iw_range));
2663 range.we_version_compiled = WIRELESS_EXT;
2664 range.we_version_source = 11;
2665 2795
2666 range.min_nwid = range.max_nwid = 0; /* We don't use nwids */ 2796 range->we_version_compiled = WIRELESS_EXT;
2797 range->we_version_source = 14;
2667 2798
2668 /* Set available channels/frequencies */ 2799 /* Set available channels/frequencies */
2669 range.num_channels = NUM_CHANNELS; 2800 range->num_channels = NUM_CHANNELS;
2670 k = 0; 2801 k = 0;
2671 for (i = 0; i < NUM_CHANNELS; i++) { 2802 for (i = 0; i < NUM_CHANNELS; i++) {
2672 if (priv->channel_mask & (1 << i)) { 2803 if (priv->channel_mask & (1 << i)) {
2673 range.freq[k].i = i + 1; 2804 range->freq[k].i = i + 1;
2674 range.freq[k].m = channel_frequency[i] * 100000; 2805 range->freq[k].m = channel_frequency[i] * 100000;
2675 range.freq[k].e = 1; 2806 range->freq[k].e = 1;
2676 k++; 2807 k++;
2677 } 2808 }
2678 2809
2679 if (k >= IW_MAX_FREQUENCIES) 2810 if (k >= IW_MAX_FREQUENCIES)
2680 break; 2811 break;
2681 } 2812 }
2682 range.num_frequency = k; 2813 range->num_frequency = k;
2814 range->sensitivity = 3;
2683 2815
2684 range.sensitivity = 3; 2816 if (priv->has_wep) {
2817 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2818 range->encoding_size[0] = SMALL_KEY_SIZE;
2819 range->num_encoding_sizes = 1;
2685 2820
2686 if ((mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){ 2821 if (priv->has_big_wep) {
2822 range->encoding_size[1] = LARGE_KEY_SIZE;
2823 range->num_encoding_sizes = 2;
2824 }
2825 }
2826
2827 if ((priv->iw_mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
2687 /* Quality stats meaningless in ad-hoc mode */ 2828 /* Quality stats meaningless in ad-hoc mode */
2688 range.max_qual.qual = 0;
2689 range.max_qual.level = 0;
2690 range.max_qual.noise = 0;
2691 range.avg_qual.qual = 0;
2692 range.avg_qual.level = 0;
2693 range.avg_qual.noise = 0;
2694 } else { 2829 } else {
2695 range.max_qual.qual = 0x8b - 0x2f; 2830 range->max_qual.qual = 0x8b - 0x2f;
2696 range.max_qual.level = 0x2f - 0x95 - 1; 2831 range->max_qual.level = 0x2f - 0x95 - 1;
2697 range.max_qual.noise = 0x2f - 0x95 - 1; 2832 range->max_qual.noise = 0x2f - 0x95 - 1;
2698 /* Need to get better values */ 2833 /* Need to get better values */
2699 range.avg_qual.qual = 0x24; 2834 range->avg_qual.qual = 0x24;
2700 range.avg_qual.level = 0xC2; 2835 range->avg_qual.level = 0xC2;
2701 range.avg_qual.noise = 0x9E; 2836 range->avg_qual.noise = 0x9E;
2702 } 2837 }
2703 2838
2704 err = orinoco_hw_get_bitratelist(priv, &numrates, 2839 err = orinoco_hw_get_bitratelist(priv, &numrates,
2705 range.bitrate, IW_MAX_BITRATES); 2840 range->bitrate, IW_MAX_BITRATES);
2706 if (err) 2841 if (err)
2707 return err; 2842 return err;
2708 range.num_bitrates = numrates; 2843 range->num_bitrates = numrates;
2709 2844
2710 /* Set an indication of the max TCP throughput in bit/s that we can 2845 /* Set an indication of the max TCP throughput in bit/s that we can
2711 * expect using this interface. May be use for QoS stuff... 2846 * expect using this interface. May be use for QoS stuff...
2712 * Jean II */ 2847 * Jean II */
2713 if(numrates > 2) 2848 if (numrates > 2)
2714 range.throughput = 5 * 1000 * 1000; /* ~5 Mb/s */ 2849 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2715 else 2850 else
2716 range.throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */ 2851 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2717 2852
2718 range.min_rts = 0; 2853 range->min_rts = 0;
2719 range.max_rts = 2347; 2854 range->max_rts = 2347;
2720 range.min_frag = 256; 2855 range->min_frag = 256;
2721 range.max_frag = 2346; 2856 range->max_frag = 2346;
2722 2857
2723 if (orinoco_lock(priv, &flags) != 0) 2858 range->min_pmp = 0;
2724 return -EBUSY; 2859 range->max_pmp = 65535000;
2725 if (priv->has_wep) { 2860 range->min_pmt = 0;
2726 range.max_encoding_tokens = ORINOCO_MAX_KEYS; 2861 range->max_pmt = 65535 * 1000; /* ??? */
2727 2862 range->pmp_flags = IW_POWER_PERIOD;
2728 range.encoding_size[0] = SMALL_KEY_SIZE; 2863 range->pmt_flags = IW_POWER_TIMEOUT;
2729 range.num_encoding_sizes = 1; 2864 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2730 2865
2731 if (priv->has_big_wep) { 2866 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2732 range.encoding_size[1] = LARGE_KEY_SIZE; 2867 range->retry_flags = IW_RETRY_LIMIT;
2733 range.num_encoding_sizes = 2; 2868 range->r_time_flags = IW_RETRY_LIFETIME;
2734 } 2869 range->min_retry = 0;
2735 } else { 2870 range->max_retry = 65535; /* ??? */
2736 range.num_encoding_sizes = 0; 2871 range->min_r_time = 0;
2737 range.max_encoding_tokens = 0; 2872 range->max_r_time = 65535 * 1000; /* ??? */
2738 }
2739 orinoco_unlock(priv, &flags);
2740
2741 range.min_pmp = 0;
2742 range.max_pmp = 65535000;
2743 range.min_pmt = 0;
2744 range.max_pmt = 65535 * 1000; /* ??? */
2745 range.pmp_flags = IW_POWER_PERIOD;
2746 range.pmt_flags = IW_POWER_TIMEOUT;
2747 range.pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2748
2749 range.num_txpower = 1;
2750 range.txpower[0] = 15; /* 15dBm */
2751 range.txpower_capa = IW_TXPOW_DBM;
2752
2753 range.retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2754 range.retry_flags = IW_RETRY_LIMIT;
2755 range.r_time_flags = IW_RETRY_LIFETIME;
2756 range.min_retry = 0;
2757 range.max_retry = 65535; /* ??? */
2758 range.min_r_time = 0;
2759 range.max_r_time = 65535 * 1000; /* ??? */
2760
2761 if (copy_to_user(rrq->pointer, &range, sizeof(range)))
2762 return -EFAULT;
2763 2873
2764 TRACE_EXIT(dev->name); 2874 TRACE_EXIT(dev->name);
2765 2875
2766 return 0; 2876 return 0;
2767} 2877}
2768 2878
2769static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq) 2879static int orinoco_ioctl_setiwencode(struct net_device *dev,
2880 struct iw_request_info *info,
2881 struct iw_point *erq,
2882 char *keybuf)
2770{ 2883{
2771 struct orinoco_private *priv = netdev_priv(dev); 2884 struct orinoco_private *priv = netdev_priv(dev);
2772 int index = (erq->flags & IW_ENCODE_INDEX) - 1; 2885 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
@@ -2774,8 +2887,7 @@ static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *er
2774 int enable = priv->wep_on; 2887 int enable = priv->wep_on;
2775 int restricted = priv->wep_restrict; 2888 int restricted = priv->wep_restrict;
2776 u16 xlen = 0; 2889 u16 xlen = 0;
2777 int err = 0; 2890 int err = -EINPROGRESS; /* Call commit handler */
2778 char keybuf[ORINOCO_MAX_KEY_SIZE];
2779 unsigned long flags; 2891 unsigned long flags;
2780 2892
2781 if (! priv->has_wep) 2893 if (! priv->has_wep)
@@ -2788,9 +2900,6 @@ static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *er
2788 2900
2789 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep ) 2901 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2790 return -E2BIG; 2902 return -E2BIG;
2791
2792 if (copy_from_user(keybuf, erq->pointer, erq->length))
2793 return -EFAULT;
2794 } 2903 }
2795 2904
2796 if (orinoco_lock(priv, &flags) != 0) 2905 if (orinoco_lock(priv, &flags) != 0)
@@ -2864,12 +2973,14 @@ static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *er
2864 return err; 2973 return err;
2865} 2974}
2866 2975
2867static int orinoco_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq) 2976static int orinoco_ioctl_getiwencode(struct net_device *dev,
2977 struct iw_request_info *info,
2978 struct iw_point *erq,
2979 char *keybuf)
2868{ 2980{
2869 struct orinoco_private *priv = netdev_priv(dev); 2981 struct orinoco_private *priv = netdev_priv(dev);
2870 int index = (erq->flags & IW_ENCODE_INDEX) - 1; 2982 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2871 u16 xlen = 0; 2983 u16 xlen = 0;
2872 char keybuf[ORINOCO_MAX_KEY_SIZE];
2873 unsigned long flags; 2984 unsigned long flags;
2874 2985
2875 if (! priv->has_wep) 2986 if (! priv->has_wep)
@@ -2898,51 +3009,47 @@ static int orinoco_ioctl_getiwencode(struct net_device *dev, struct iw_point *er
2898 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE); 3009 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
2899 3010
2900 orinoco_unlock(priv, &flags); 3011 orinoco_unlock(priv, &flags);
2901
2902 if (erq->pointer) {
2903 if (copy_to_user(erq->pointer, keybuf, xlen))
2904 return -EFAULT;
2905 }
2906
2907 return 0; 3012 return 0;
2908} 3013}
2909 3014
2910static int orinoco_ioctl_setessid(struct net_device *dev, struct iw_point *erq) 3015static int orinoco_ioctl_setessid(struct net_device *dev,
3016 struct iw_request_info *info,
3017 struct iw_point *erq,
3018 char *essidbuf)
2911{ 3019{
2912 struct orinoco_private *priv = netdev_priv(dev); 3020 struct orinoco_private *priv = netdev_priv(dev);
2913 char essidbuf[IW_ESSID_MAX_SIZE+1];
2914 unsigned long flags; 3021 unsigned long flags;
2915 3022
2916 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it 3023 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
2917 * anyway... - Jean II */ 3024 * anyway... - Jean II */
2918 3025
2919 memset(&essidbuf, 0, sizeof(essidbuf)); 3026 /* Hum... Should not use Wireless Extension constant (may change),
2920 3027 * should use our own... - Jean II */
2921 if (erq->flags) { 3028 if (erq->length > IW_ESSID_MAX_SIZE)
2922 /* iwconfig includes the NUL in the specified length */ 3029 return -E2BIG;
2923 if (erq->length > IW_ESSID_MAX_SIZE+1)
2924 return -E2BIG;
2925
2926 if (copy_from_user(&essidbuf, erq->pointer, erq->length))
2927 return -EFAULT;
2928
2929 essidbuf[IW_ESSID_MAX_SIZE] = '\0';
2930 }
2931 3030
2932 if (orinoco_lock(priv, &flags) != 0) 3031 if (orinoco_lock(priv, &flags) != 0)
2933 return -EBUSY; 3032 return -EBUSY;
2934 3033
2935 memcpy(priv->desired_essid, essidbuf, sizeof(priv->desired_essid)); 3034 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3035 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3036
3037 /* If not ANY, get the new ESSID */
3038 if (erq->flags) {
3039 memcpy(priv->desired_essid, essidbuf, erq->length);
3040 }
2936 3041
2937 orinoco_unlock(priv, &flags); 3042 orinoco_unlock(priv, &flags);
2938 3043
2939 return 0; 3044 return -EINPROGRESS; /* Call commit handler */
2940} 3045}
2941 3046
2942static int orinoco_ioctl_getessid(struct net_device *dev, struct iw_point *erq) 3047static int orinoco_ioctl_getessid(struct net_device *dev,
3048 struct iw_request_info *info,
3049 struct iw_point *erq,
3050 char *essidbuf)
2943{ 3051{
2944 struct orinoco_private *priv = netdev_priv(dev); 3052 struct orinoco_private *priv = netdev_priv(dev);
2945 char essidbuf[IW_ESSID_MAX_SIZE+1];
2946 int active; 3053 int active;
2947 int err = 0; 3054 int err = 0;
2948 unsigned long flags; 3055 unsigned long flags;
@@ -2956,51 +3063,46 @@ static int orinoco_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
2956 } else { 3063 } else {
2957 if (orinoco_lock(priv, &flags) != 0) 3064 if (orinoco_lock(priv, &flags) != 0)
2958 return -EBUSY; 3065 return -EBUSY;
2959 memcpy(essidbuf, priv->desired_essid, sizeof(essidbuf)); 3066 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
2960 orinoco_unlock(priv, &flags); 3067 orinoco_unlock(priv, &flags);
2961 } 3068 }
2962 3069
2963 erq->flags = 1; 3070 erq->flags = 1;
2964 erq->length = strlen(essidbuf) + 1; 3071 erq->length = strlen(essidbuf) + 1;
2965 if (erq->pointer)
2966 if (copy_to_user(erq->pointer, essidbuf, erq->length))
2967 return -EFAULT;
2968 3072
2969 TRACE_EXIT(dev->name); 3073 TRACE_EXIT(dev->name);
2970 3074
2971 return 0; 3075 return 0;
2972} 3076}
2973 3077
2974static int orinoco_ioctl_setnick(struct net_device *dev, struct iw_point *nrq) 3078static int orinoco_ioctl_setnick(struct net_device *dev,
3079 struct iw_request_info *info,
3080 struct iw_point *nrq,
3081 char *nickbuf)
2975{ 3082{
2976 struct orinoco_private *priv = netdev_priv(dev); 3083 struct orinoco_private *priv = netdev_priv(dev);
2977 char nickbuf[IW_ESSID_MAX_SIZE+1];
2978 unsigned long flags; 3084 unsigned long flags;
2979 3085
2980 if (nrq->length > IW_ESSID_MAX_SIZE) 3086 if (nrq->length > IW_ESSID_MAX_SIZE)
2981 return -E2BIG; 3087 return -E2BIG;
2982 3088
2983 memset(nickbuf, 0, sizeof(nickbuf));
2984
2985 if (copy_from_user(nickbuf, nrq->pointer, nrq->length))
2986 return -EFAULT;
2987
2988 nickbuf[nrq->length] = '\0';
2989
2990 if (orinoco_lock(priv, &flags) != 0) 3089 if (orinoco_lock(priv, &flags) != 0)
2991 return -EBUSY; 3090 return -EBUSY;
2992 3091
2993 memcpy(priv->nick, nickbuf, sizeof(priv->nick)); 3092 memset(priv->nick, 0, sizeof(priv->nick));
3093 memcpy(priv->nick, nickbuf, nrq->length);
2994 3094
2995 orinoco_unlock(priv, &flags); 3095 orinoco_unlock(priv, &flags);
2996 3096
2997 return 0; 3097 return -EINPROGRESS; /* Call commit handler */
2998} 3098}
2999 3099
3000static int orinoco_ioctl_getnick(struct net_device *dev, struct iw_point *nrq) 3100static int orinoco_ioctl_getnick(struct net_device *dev,
3101 struct iw_request_info *info,
3102 struct iw_point *nrq,
3103 char *nickbuf)
3001{ 3104{
3002 struct orinoco_private *priv = netdev_priv(dev); 3105 struct orinoco_private *priv = netdev_priv(dev);
3003 char nickbuf[IW_ESSID_MAX_SIZE+1];
3004 unsigned long flags; 3106 unsigned long flags;
3005 3107
3006 if (orinoco_lock(priv, &flags) != 0) 3108 if (orinoco_lock(priv, &flags) != 0)
@@ -3011,23 +3113,22 @@ static int orinoco_ioctl_getnick(struct net_device *dev, struct iw_point *nrq)
3011 3113
3012 nrq->length = strlen(nickbuf)+1; 3114 nrq->length = strlen(nickbuf)+1;
3013 3115
3014 if (copy_to_user(nrq->pointer, nickbuf, sizeof(nickbuf)))
3015 return -EFAULT;
3016
3017 return 0; 3116 return 0;
3018} 3117}
3019 3118
3020static int orinoco_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq) 3119static int orinoco_ioctl_setfreq(struct net_device *dev,
3120 struct iw_request_info *info,
3121 struct iw_freq *frq,
3122 char *extra)
3021{ 3123{
3022 struct orinoco_private *priv = netdev_priv(dev); 3124 struct orinoco_private *priv = netdev_priv(dev);
3023 int chan = -1; 3125 int chan = -1;
3024 unsigned long flags; 3126 unsigned long flags;
3127 int err = -EINPROGRESS; /* Call commit handler */
3025 3128
3026 /* We can only use this in Ad-Hoc demo mode to set the operating 3129 /* In infrastructure mode the AP sets the channel */
3027 * frequency, or in IBSS mode to set the frequency where the IBSS 3130 if (priv->iw_mode == IW_MODE_INFRA)
3028 * will be created - Jean II */ 3131 return -EBUSY;
3029 if (priv->iw_mode != IW_MODE_ADHOC)
3030 return -EOPNOTSUPP;
3031 3132
3032 if ( (frq->e == 0) && (frq->m <= 1000) ) { 3133 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3033 /* Setting by channel number */ 3134 /* Setting by channel number */
@@ -3051,13 +3152,44 @@ static int orinoco_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq)
3051 3152
3052 if (orinoco_lock(priv, &flags) != 0) 3153 if (orinoco_lock(priv, &flags) != 0)
3053 return -EBUSY; 3154 return -EBUSY;
3155
3054 priv->channel = chan; 3156 priv->channel = chan;
3157 if (priv->iw_mode == IW_MODE_MONITOR) {
3158 /* Fast channel change - no commit if successful */
3159 hermes_t *hw = &priv->hw;
3160 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3161 HERMES_TEST_SET_CHANNEL,
3162 chan, NULL);
3163 }
3055 orinoco_unlock(priv, &flags); 3164 orinoco_unlock(priv, &flags);
3056 3165
3166 return err;
3167}
3168
3169static int orinoco_ioctl_getfreq(struct net_device *dev,
3170 struct iw_request_info *info,
3171 struct iw_freq *frq,
3172 char *extra)
3173{
3174 struct orinoco_private *priv = netdev_priv(dev);
3175 int tmp;
3176
3177 /* Locking done in there */
3178 tmp = orinoco_hw_get_freq(priv);
3179 if (tmp < 0) {
3180 return tmp;
3181 }
3182
3183 frq->m = tmp;
3184 frq->e = 1;
3185
3057 return 0; 3186 return 0;
3058} 3187}
3059 3188
3060static int orinoco_ioctl_getsens(struct net_device *dev, struct iw_param *srq) 3189static int orinoco_ioctl_getsens(struct net_device *dev,
3190 struct iw_request_info *info,
3191 struct iw_param *srq,
3192 char *extra)
3061{ 3193{
3062 struct orinoco_private *priv = netdev_priv(dev); 3194 struct orinoco_private *priv = netdev_priv(dev);
3063 hermes_t *hw = &priv->hw; 3195 hermes_t *hw = &priv->hw;
@@ -3083,7 +3215,10 @@ static int orinoco_ioctl_getsens(struct net_device *dev, struct iw_param *srq)
3083 return 0; 3215 return 0;
3084} 3216}
3085 3217
3086static int orinoco_ioctl_setsens(struct net_device *dev, struct iw_param *srq) 3218static int orinoco_ioctl_setsens(struct net_device *dev,
3219 struct iw_request_info *info,
3220 struct iw_param *srq,
3221 char *extra)
3087{ 3222{
3088 struct orinoco_private *priv = netdev_priv(dev); 3223 struct orinoco_private *priv = netdev_priv(dev);
3089 int val = srq->value; 3224 int val = srq->value;
@@ -3100,10 +3235,13 @@ static int orinoco_ioctl_setsens(struct net_device *dev, struct iw_param *srq)
3100 priv->ap_density = val; 3235 priv->ap_density = val;
3101 orinoco_unlock(priv, &flags); 3236 orinoco_unlock(priv, &flags);
3102 3237
3103 return 0; 3238 return -EINPROGRESS; /* Call commit handler */
3104} 3239}
3105 3240
3106static int orinoco_ioctl_setrts(struct net_device *dev, struct iw_param *rrq) 3241static int orinoco_ioctl_setrts(struct net_device *dev,
3242 struct iw_request_info *info,
3243 struct iw_param *rrq,
3244 char *extra)
3107{ 3245{
3108 struct orinoco_private *priv = netdev_priv(dev); 3246 struct orinoco_private *priv = netdev_priv(dev);
3109 int val = rrq->value; 3247 int val = rrq->value;
@@ -3121,13 +3259,30 @@ static int orinoco_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
3121 priv->rts_thresh = val; 3259 priv->rts_thresh = val;
3122 orinoco_unlock(priv, &flags); 3260 orinoco_unlock(priv, &flags);
3123 3261
3262 return -EINPROGRESS; /* Call commit handler */
3263}
3264
3265static int orinoco_ioctl_getrts(struct net_device *dev,
3266 struct iw_request_info *info,
3267 struct iw_param *rrq,
3268 char *extra)
3269{
3270 struct orinoco_private *priv = netdev_priv(dev);
3271
3272 rrq->value = priv->rts_thresh;
3273 rrq->disabled = (rrq->value == 2347);
3274 rrq->fixed = 1;
3275
3124 return 0; 3276 return 0;
3125} 3277}
3126 3278
3127static int orinoco_ioctl_setfrag(struct net_device *dev, struct iw_param *frq) 3279static int orinoco_ioctl_setfrag(struct net_device *dev,
3280 struct iw_request_info *info,
3281 struct iw_param *frq,
3282 char *extra)
3128{ 3283{
3129 struct orinoco_private *priv = netdev_priv(dev); 3284 struct orinoco_private *priv = netdev_priv(dev);
3130 int err = 0; 3285 int err = -EINPROGRESS; /* Call commit handler */
3131 unsigned long flags; 3286 unsigned long flags;
3132 3287
3133 if (orinoco_lock(priv, &flags) != 0) 3288 if (orinoco_lock(priv, &flags) != 0)
@@ -3159,11 +3314,14 @@ static int orinoco_ioctl_setfrag(struct net_device *dev, struct iw_param *frq)
3159 return err; 3314 return err;
3160} 3315}
3161 3316
3162static int orinoco_ioctl_getfrag(struct net_device *dev, struct iw_param *frq) 3317static int orinoco_ioctl_getfrag(struct net_device *dev,
3318 struct iw_request_info *info,
3319 struct iw_param *frq,
3320 char *extra)
3163{ 3321{
3164 struct orinoco_private *priv = netdev_priv(dev); 3322 struct orinoco_private *priv = netdev_priv(dev);
3165 hermes_t *hw = &priv->hw; 3323 hermes_t *hw = &priv->hw;
3166 int err = 0; 3324 int err;
3167 u16 val; 3325 u16 val;
3168 unsigned long flags; 3326 unsigned long flags;
3169 3327
@@ -3196,10 +3354,12 @@ static int orinoco_ioctl_getfrag(struct net_device *dev, struct iw_param *frq)
3196 return err; 3354 return err;
3197} 3355}
3198 3356
3199static int orinoco_ioctl_setrate(struct net_device *dev, struct iw_param *rrq) 3357static int orinoco_ioctl_setrate(struct net_device *dev,
3358 struct iw_request_info *info,
3359 struct iw_param *rrq,
3360 char *extra)
3200{ 3361{
3201 struct orinoco_private *priv = netdev_priv(dev); 3362 struct orinoco_private *priv = netdev_priv(dev);
3202 int err = 0;
3203 int ratemode = -1; 3363 int ratemode = -1;
3204 int bitrate; /* 100s of kilobits */ 3364 int bitrate; /* 100s of kilobits */
3205 int i; 3365 int i;
@@ -3235,10 +3395,13 @@ static int orinoco_ioctl_setrate(struct net_device *dev, struct iw_param *rrq)
3235 priv->bitratemode = ratemode; 3395 priv->bitratemode = ratemode;
3236 orinoco_unlock(priv, &flags); 3396 orinoco_unlock(priv, &flags);
3237 3397
3238 return err; 3398 return -EINPROGRESS;
3239} 3399}
3240 3400
3241static int orinoco_ioctl_getrate(struct net_device *dev, struct iw_param *rrq) 3401static int orinoco_ioctl_getrate(struct net_device *dev,
3402 struct iw_request_info *info,
3403 struct iw_param *rrq,
3404 char *extra)
3242{ 3405{
3243 struct orinoco_private *priv = netdev_priv(dev); 3406 struct orinoco_private *priv = netdev_priv(dev);
3244 hermes_t *hw = &priv->hw; 3407 hermes_t *hw = &priv->hw;
@@ -3303,10 +3466,13 @@ static int orinoco_ioctl_getrate(struct net_device *dev, struct iw_param *rrq)
3303 return err; 3466 return err;
3304} 3467}
3305 3468
3306static int orinoco_ioctl_setpower(struct net_device *dev, struct iw_param *prq) 3469static int orinoco_ioctl_setpower(struct net_device *dev,
3470 struct iw_request_info *info,
3471 struct iw_param *prq,
3472 char *extra)
3307{ 3473{
3308 struct orinoco_private *priv = netdev_priv(dev); 3474 struct orinoco_private *priv = netdev_priv(dev);
3309 int err = 0; 3475 int err = -EINPROGRESS; /* Call commit handler */
3310 unsigned long flags; 3476 unsigned long flags;
3311 3477
3312 if (orinoco_lock(priv, &flags) != 0) 3478 if (orinoco_lock(priv, &flags) != 0)
@@ -3355,7 +3521,10 @@ static int orinoco_ioctl_setpower(struct net_device *dev, struct iw_param *prq)
3355 return err; 3521 return err;
3356} 3522}
3357 3523
3358static int orinoco_ioctl_getpower(struct net_device *dev, struct iw_param *prq) 3524static int orinoco_ioctl_getpower(struct net_device *dev,
3525 struct iw_request_info *info,
3526 struct iw_param *prq,
3527 char *extra)
3359{ 3528{
3360 struct orinoco_private *priv = netdev_priv(dev); 3529 struct orinoco_private *priv = netdev_priv(dev);
3361 hermes_t *hw = &priv->hw; 3530 hermes_t *hw = &priv->hw;
@@ -3403,7 +3572,10 @@ static int orinoco_ioctl_getpower(struct net_device *dev, struct iw_param *prq)
3403 return err; 3572 return err;
3404} 3573}
3405 3574
3406static int orinoco_ioctl_getretry(struct net_device *dev, struct iw_param *rrq) 3575static int orinoco_ioctl_getretry(struct net_device *dev,
3576 struct iw_request_info *info,
3577 struct iw_param *rrq,
3578 char *extra)
3407{ 3579{
3408 struct orinoco_private *priv = netdev_priv(dev); 3580 struct orinoco_private *priv = netdev_priv(dev);
3409 hermes_t *hw = &priv->hw; 3581 hermes_t *hw = &priv->hw;
@@ -3454,10 +3626,38 @@ static int orinoco_ioctl_getretry(struct net_device *dev, struct iw_param *rrq)
3454 return err; 3626 return err;
3455} 3627}
3456 3628
3457static int orinoco_ioctl_setibssport(struct net_device *dev, struct iwreq *wrq) 3629static int orinoco_ioctl_reset(struct net_device *dev,
3630 struct iw_request_info *info,
3631 void *wrqu,
3632 char *extra)
3458{ 3633{
3459 struct orinoco_private *priv = netdev_priv(dev); 3634 struct orinoco_private *priv = netdev_priv(dev);
3460 int val = *( (int *) wrq->u.name ); 3635
3636 if (! capable(CAP_NET_ADMIN))
3637 return -EPERM;
3638
3639 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3640 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3641
3642 /* Firmware reset */
3643 orinoco_reset(dev);
3644 } else {
3645 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3646
3647 schedule_work(&priv->reset_work);
3648 }
3649
3650 return 0;
3651}
3652
3653static int orinoco_ioctl_setibssport(struct net_device *dev,
3654 struct iw_request_info *info,
3655 void *wrqu,
3656 char *extra)
3657
3658{
3659 struct orinoco_private *priv = netdev_priv(dev);
3660 int val = *( (int *) extra );
3461 unsigned long flags; 3661 unsigned long flags;
3462 3662
3463 if (orinoco_lock(priv, &flags) != 0) 3663 if (orinoco_lock(priv, &flags) != 0)
@@ -3469,28 +3669,28 @@ static int orinoco_ioctl_setibssport(struct net_device *dev, struct iwreq *wrq)
3469 set_port_type(priv); 3669 set_port_type(priv);
3470 3670
3471 orinoco_unlock(priv, &flags); 3671 orinoco_unlock(priv, &flags);
3472 return 0; 3672 return -EINPROGRESS; /* Call commit handler */
3473} 3673}
3474 3674
3475static int orinoco_ioctl_getibssport(struct net_device *dev, struct iwreq *wrq) 3675static int orinoco_ioctl_getibssport(struct net_device *dev,
3676 struct iw_request_info *info,
3677 void *wrqu,
3678 char *extra)
3476{ 3679{
3477 struct orinoco_private *priv = netdev_priv(dev); 3680 struct orinoco_private *priv = netdev_priv(dev);
3478 int *val = (int *)wrq->u.name; 3681 int *val = (int *) extra;
3479 unsigned long flags;
3480
3481 if (orinoco_lock(priv, &flags) != 0)
3482 return -EBUSY;
3483 3682
3484 *val = priv->ibss_port; 3683 *val = priv->ibss_port;
3485 orinoco_unlock(priv, &flags);
3486
3487 return 0; 3684 return 0;
3488} 3685}
3489 3686
3490static int orinoco_ioctl_setport3(struct net_device *dev, struct iwreq *wrq) 3687static int orinoco_ioctl_setport3(struct net_device *dev,
3688 struct iw_request_info *info,
3689 void *wrqu,
3690 char *extra)
3491{ 3691{
3492 struct orinoco_private *priv = netdev_priv(dev); 3692 struct orinoco_private *priv = netdev_priv(dev);
3493 int val = *( (int *) wrq->u.name ); 3693 int val = *( (int *) extra );
3494 int err = 0; 3694 int err = 0;
3495 unsigned long flags; 3695 unsigned long flags;
3496 3696
@@ -3519,51 +3719,131 @@ static int orinoco_ioctl_setport3(struct net_device *dev, struct iwreq *wrq)
3519 err = -EINVAL; 3719 err = -EINVAL;
3520 } 3720 }
3521 3721
3522 if (! err) 3722 if (! err) {
3523 /* Actually update the mode we are using */ 3723 /* Actually update the mode we are using */
3524 set_port_type(priv); 3724 set_port_type(priv);
3725 err = -EINPROGRESS;
3726 }
3525 3727
3526 orinoco_unlock(priv, &flags); 3728 orinoco_unlock(priv, &flags);
3527 3729
3528 return err; 3730 return err;
3529} 3731}
3530 3732
3531static int orinoco_ioctl_getport3(struct net_device *dev, struct iwreq *wrq) 3733static int orinoco_ioctl_getport3(struct net_device *dev,
3734 struct iw_request_info *info,
3735 void *wrqu,
3736 char *extra)
3737{
3738 struct orinoco_private *priv = netdev_priv(dev);
3739 int *val = (int *) extra;
3740
3741 *val = priv->prefer_port3;
3742 return 0;
3743}
3744
3745static int orinoco_ioctl_setpreamble(struct net_device *dev,
3746 struct iw_request_info *info,
3747 void *wrqu,
3748 char *extra)
3532{ 3749{
3533 struct orinoco_private *priv = netdev_priv(dev); 3750 struct orinoco_private *priv = netdev_priv(dev);
3534 int *val = (int *)wrq->u.name;
3535 unsigned long flags; 3751 unsigned long flags;
3752 int val;
3753
3754 if (! priv->has_preamble)
3755 return -EOPNOTSUPP;
3756
3757 /* 802.11b has recently defined some short preamble.
3758 * Basically, the Phy header has been reduced in size.
3759 * This increase performance, especially at high rates
3760 * (the preamble is transmitted at 1Mb/s), unfortunately
3761 * this give compatibility troubles... - Jean II */
3762 val = *( (int *) extra );
3536 3763
3537 if (orinoco_lock(priv, &flags) != 0) 3764 if (orinoco_lock(priv, &flags) != 0)
3538 return -EBUSY; 3765 return -EBUSY;
3539 3766
3540 *val = priv->prefer_port3; 3767 if (val)
3768 priv->preamble = 1;
3769 else
3770 priv->preamble = 0;
3771
3541 orinoco_unlock(priv, &flags); 3772 orinoco_unlock(priv, &flags);
3773
3774 return -EINPROGRESS; /* Call commit handler */
3775}
3776
3777static int orinoco_ioctl_getpreamble(struct net_device *dev,
3778 struct iw_request_info *info,
3779 void *wrqu,
3780 char *extra)
3781{
3782 struct orinoco_private *priv = netdev_priv(dev);
3783 int *val = (int *) extra;
3784
3785 if (! priv->has_preamble)
3786 return -EOPNOTSUPP;
3787
3788 *val = priv->preamble;
3542 return 0; 3789 return 0;
3543} 3790}
3544 3791
3792/* ioctl interface to hermes_read_ltv()
3793 * To use with iwpriv, pass the RID as the token argument, e.g.
3794 * iwpriv get_rid [0xfc00]
3795 * At least Wireless Tools 25 is required to use iwpriv.
3796 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3797static int orinoco_ioctl_getrid(struct net_device *dev,
3798 struct iw_request_info *info,
3799 struct iw_point *data,
3800 char *extra)
3801{
3802 struct orinoco_private *priv = netdev_priv(dev);
3803 hermes_t *hw = &priv->hw;
3804 int rid = data->flags;
3805 u16 length;
3806 int err;
3807 unsigned long flags;
3808
3809 /* It's a "get" function, but we don't want users to access the
3810 * WEP key and other raw firmware data */
3811 if (! capable(CAP_NET_ADMIN))
3812 return -EPERM;
3813
3814 if (rid < 0xfc00 || rid > 0xffff)
3815 return -EINVAL;
3816
3817 if (orinoco_lock(priv, &flags) != 0)
3818 return -EBUSY;
3819
3820 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3821 extra);
3822 if (err)
3823 goto out;
3824
3825 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3826 MAX_RID_LEN);
3827
3828 out:
3829 orinoco_unlock(priv, &flags);
3830 return err;
3831}
3832
3545/* Spy is used for link quality/strength measurements in Ad-Hoc mode 3833/* Spy is used for link quality/strength measurements in Ad-Hoc mode
3546 * Jean II */ 3834 * Jean II */
3547static int orinoco_ioctl_setspy(struct net_device *dev, struct iw_point *srq) 3835static int orinoco_ioctl_setspy(struct net_device *dev,
3836 struct iw_request_info *info,
3837 struct iw_point *srq,
3838 char *extra)
3839
3548{ 3840{
3549 struct orinoco_private *priv = netdev_priv(dev); 3841 struct orinoco_private *priv = netdev_priv(dev);
3550 struct sockaddr address[IW_MAX_SPY]; 3842 struct sockaddr *address = (struct sockaddr *) extra;
3551 int number = srq->length; 3843 int number = srq->length;
3552 int i; 3844 int i;
3553 int err = 0;
3554 unsigned long flags; 3845 unsigned long flags;
3555 3846
3556 /* Check the number of addresses */
3557 if (number > IW_MAX_SPY)
3558 return -E2BIG;
3559
3560 /* Get the data in the driver */
3561 if (srq->pointer) {
3562 if (copy_from_user(address, srq->pointer,
3563 sizeof(struct sockaddr) * number))
3564 return -EFAULT;
3565 }
3566
3567 /* Make sure nobody mess with the structure while we do */ 3847 /* Make sure nobody mess with the structure while we do */
3568 if (orinoco_lock(priv, &flags) != 0) 3848 if (orinoco_lock(priv, &flags) != 0)
3569 return -EBUSY; 3849 return -EBUSY;
@@ -3587,14 +3867,17 @@ static int orinoco_ioctl_setspy(struct net_device *dev, struct iw_point *srq)
3587 /* Now, let the others play */ 3867 /* Now, let the others play */
3588 orinoco_unlock(priv, &flags); 3868 orinoco_unlock(priv, &flags);
3589 3869
3590 return err; 3870 /* Do NOT call commit handler */
3871 return 0;
3591} 3872}
3592 3873
3593static int orinoco_ioctl_getspy(struct net_device *dev, struct iw_point *srq) 3874static int orinoco_ioctl_getspy(struct net_device *dev,
3875 struct iw_request_info *info,
3876 struct iw_point *srq,
3877 char *extra)
3594{ 3878{
3595 struct orinoco_private *priv = netdev_priv(dev); 3879 struct orinoco_private *priv = netdev_priv(dev);
3596 struct sockaddr address[IW_MAX_SPY]; 3880 struct sockaddr *address = (struct sockaddr *) extra;
3597 struct iw_quality spy_stat[IW_MAX_SPY];
3598 int number; 3881 int number;
3599 int i; 3882 int i;
3600 unsigned long flags; 3883 unsigned long flags;
@@ -3603,7 +3886,12 @@ static int orinoco_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
3603 return -EBUSY; 3886 return -EBUSY;
3604 3887
3605 number = priv->spy_number; 3888 number = priv->spy_number;
3606 if ((number > 0) && (srq->pointer)) { 3889 /* Create address struct */
3890 for (i = 0; i < number; i++) {
3891 memcpy(address[i].sa_data, priv->spy_address[i], ETH_ALEN);
3892 address[i].sa_family = AF_UNIX;
3893 }
3894 if (number > 0) {
3607 /* Create address struct */ 3895 /* Create address struct */
3608 for (i = 0; i < number; i++) { 3896 for (i = 0; i < number; i++) {
3609 memcpy(address[i].sa_data, priv->spy_address[i], 3897 memcpy(address[i].sa_data, priv->spy_address[i],
@@ -3614,344 +3902,503 @@ static int orinoco_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
3614 /* In theory, we should disable irqs while copying the stats 3902 /* In theory, we should disable irqs while copying the stats
3615 * because the rx path might update it in the middle... 3903 * because the rx path might update it in the middle...
3616 * Bah, who care ? - Jean II */ 3904 * Bah, who care ? - Jean II */
3617 memcpy(&spy_stat, priv->spy_stat, 3905 memcpy(extra + (sizeof(struct sockaddr) * number),
3618 sizeof(struct iw_quality) * IW_MAX_SPY); 3906 priv->spy_stat, sizeof(struct iw_quality) * number);
3619 for (i=0; i < number; i++)
3620 priv->spy_stat[i].updated = 0;
3621 } 3907 }
3908 /* Reset updated flags. */
3909 for (i = 0; i < number; i++)
3910 priv->spy_stat[i].updated = 0;
3622 3911
3623 orinoco_unlock(priv, &flags); 3912 orinoco_unlock(priv, &flags);
3624 3913
3625 /* Push stuff to user space */
3626 srq->length = number; 3914 srq->length = number;
3627 if(copy_to_user(srq->pointer, address,
3628 sizeof(struct sockaddr) * number))
3629 return -EFAULT;
3630 if(copy_to_user(srq->pointer + (sizeof(struct sockaddr)*number),
3631 &spy_stat, sizeof(struct iw_quality) * number))
3632 return -EFAULT;
3633 3915
3634 return 0; 3916 return 0;
3635} 3917}
3636 3918
3637static int 3919/* Trigger a scan (look for other cells in the vicinity */
3638orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 3920static int orinoco_ioctl_setscan(struct net_device *dev,
3921 struct iw_request_info *info,
3922 struct iw_param *srq,
3923 char *extra)
3639{ 3924{
3640 struct orinoco_private *priv = netdev_priv(dev); 3925 struct orinoco_private *priv = netdev_priv(dev);
3641 struct iwreq *wrq = (struct iwreq *)rq; 3926 hermes_t *hw = &priv->hw;
3642 int err = 0; 3927 int err = 0;
3643 int tmp;
3644 int changed = 0;
3645 unsigned long flags; 3928 unsigned long flags;
3646 3929
3647 TRACE_ENTER(dev->name); 3930 /* Note : you may have realised that, as this is a SET operation,
3931 * this is priviledged and therefore a normal user can't
3932 * perform scanning.
3933 * This is not an error, while the device perform scanning,
3934 * traffic doesn't flow, so it's a perfect DoS...
3935 * Jean II */
3648 3936
3649 /* In theory, we could allow most of the the SET stuff to be 3937 if (orinoco_lock(priv, &flags) != 0)
3650 * done. In practice, the lapse of time at startup when the 3938 return -EBUSY;
3651 * card is not ready is very short, so why bother... Note
3652 * that netif_device_present is different from up/down
3653 * (ifconfig), when the device is not yet up, it is usually
3654 * already ready... Jean II */
3655 if (! netif_device_present(dev))
3656 return -ENODEV;
3657 3939
3658 switch (cmd) { 3940 /* Scanning with port 0 disabled would fail */
3659 case SIOCGIWNAME: 3941 if (!netif_running(dev)) {
3660 strcpy(wrq->u.name, "IEEE 802.11-DS"); 3942 err = -ENETDOWN;
3661 break; 3943 goto out;
3662 3944 }
3663 case SIOCGIWAP:
3664 wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
3665 err = orinoco_hw_get_bssid(priv, wrq->u.ap_addr.sa_data);
3666 break;
3667 3945
3668 case SIOCGIWRANGE: 3946 /* In monitor mode, the scan results are always empty.
3669 err = orinoco_ioctl_getiwrange(dev, &wrq->u.data); 3947 * Probe responses are passed to the driver as received
3670 break; 3948 * frames and could be processed in software. */
3949 if (priv->iw_mode == IW_MODE_MONITOR) {
3950 err = -EOPNOTSUPP;
3951 goto out;
3952 }
3671 3953
3672 case SIOCSIWMODE: 3954 /* Note : because we don't lock out the irq handler, the way
3673 if (orinoco_lock(priv, &flags) != 0) 3955 * we access scan variables in priv is critical.
3674 return -EBUSY; 3956 * o scan_inprogress : not touched by irq handler
3675 switch (wrq->u.mode) { 3957 * o scan_mode : not touched by irq handler
3676 case IW_MODE_ADHOC: 3958 * o scan_result : irq is strict producer, non-irq is strict
3677 if (! (priv->has_ibss || priv->has_port3) ) 3959 * consumer.
3678 err = -EINVAL; 3960 * o scan_len : synchronised with scan_result
3679 else { 3961 * Before modifying anything on those variables, please think hard !
3680 priv->iw_mode = IW_MODE_ADHOC; 3962 * Jean II */
3681 changed = 1;
3682 }
3683 break;
3684 3963
3685 case IW_MODE_INFRA: 3964 /* If there is still some left-over scan results, get rid of it */
3686 priv->iw_mode = IW_MODE_INFRA; 3965 if (priv->scan_result != NULL) {
3687 changed = 1; 3966 /* What's likely is that a client did crash or was killed
3688 break; 3967 * between triggering the scan request and reading the
3968 * results, so we need to reset everything.
3969 * Some clients that are too slow may suffer from that...
3970 * Jean II */
3971 kfree(priv->scan_result);
3972 priv->scan_result = NULL;
3973 }
3689 3974
3690 default: 3975 /* Save flags */
3691 err = -EINVAL; 3976 priv->scan_mode = srq->flags;
3692 break;
3693 }
3694 set_port_type(priv);
3695 orinoco_unlock(priv, &flags);
3696 break;
3697 3977
3698 case SIOCGIWMODE: 3978 /* Always trigger scanning, even if it's in progress.
3699 if (orinoco_lock(priv, &flags) != 0) 3979 * This way, if the info frame get lost, we will recover somewhat
3700 return -EBUSY; 3980 * gracefully - Jean II */
3701 wrq->u.mode = priv->iw_mode;
3702 orinoco_unlock(priv, &flags);
3703 break;
3704 3981
3705 case SIOCSIWENCODE: 3982 if (priv->has_hostscan) {
3706 err = orinoco_ioctl_setiwencode(dev, &wrq->u.encoding); 3983 switch (priv->firmware_type) {
3707 if (! err) 3984 case FIRMWARE_TYPE_SYMBOL:
3708 changed = 1; 3985 err = hermes_write_wordrec(hw, USER_BAP,
3986 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3987 HERMES_HOSTSCAN_SYMBOL_ONCE |
3988 HERMES_HOSTSCAN_SYMBOL_BCAST);
3989 break;
3990 case FIRMWARE_TYPE_INTERSIL: {
3991 u16 req[3];
3992
3993 req[0] = cpu_to_le16(0x3fff); /* All channels */
3994 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3995 req[2] = 0; /* Any ESSID */
3996 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3997 HERMES_RID_CNFHOSTSCAN, &req);
3998 }
3709 break; 3999 break;
4000 case FIRMWARE_TYPE_AGERE:
4001 err = hermes_write_wordrec(hw, USER_BAP,
4002 HERMES_RID_CNFSCANSSID_AGERE,
4003 0); /* Any ESSID */
4004 if (err)
4005 break;
3710 4006
3711 case SIOCGIWENCODE: 4007 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3712 if (! capable(CAP_NET_ADMIN)) {
3713 err = -EPERM;
3714 break; 4008 break;
3715 } 4009 }
4010 } else
4011 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3716 4012
3717 err = orinoco_ioctl_getiwencode(dev, &wrq->u.encoding); 4013 /* One more client */
3718 break; 4014 if (! err)
3719 4015 priv->scan_inprogress = 1;
3720 case SIOCSIWESSID:
3721 err = orinoco_ioctl_setessid(dev, &wrq->u.essid);
3722 if (! err)
3723 changed = 1;
3724 break;
3725 4016
3726 case SIOCGIWESSID: 4017 out:
3727 err = orinoco_ioctl_getessid(dev, &wrq->u.essid); 4018 orinoco_unlock(priv, &flags);
3728 break; 4019 return err;
4020}
3729 4021
3730 case SIOCSIWNICKN: 4022/* Translate scan data returned from the card to a card independant
3731 err = orinoco_ioctl_setnick(dev, &wrq->u.data); 4023 * format that the Wireless Tools will understand - Jean II */
3732 if (! err) 4024static inline int orinoco_translate_scan(struct net_device *dev,
3733 changed = 1; 4025 char *buffer,
3734 break; 4026 char *scan,
4027 int scan_len)
4028{
4029 struct orinoco_private *priv = netdev_priv(dev);
4030 int offset; /* In the scan data */
4031 union hermes_scan_info *atom;
4032 int atom_len;
4033 u16 capabilities;
4034 u16 channel;
4035 struct iw_event iwe; /* Temporary buffer */
4036 char * current_ev = buffer;
4037 char * end_buf = buffer + IW_SCAN_MAX_DATA;
3735 4038
3736 case SIOCGIWNICKN: 4039 switch (priv->firmware_type) {
3737 err = orinoco_ioctl_getnick(dev, &wrq->u.data); 4040 case FIRMWARE_TYPE_AGERE:
4041 atom_len = sizeof(struct agere_scan_apinfo);
4042 offset = 0;
3738 break; 4043 break;
3739 4044 case FIRMWARE_TYPE_SYMBOL:
3740 case SIOCGIWFREQ: 4045 /* Lack of documentation necessitates this hack.
3741 tmp = orinoco_hw_get_freq(priv); 4046 * Different firmwares have 68 or 76 byte long atoms.
3742 if (tmp < 0) { 4047 * We try modulo first. If the length divides by both,
3743 err = tmp; 4048 * we check what would be the channel in the second
3744 } else { 4049 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3745 wrq->u.freq.m = tmp; 4050 * Valid channel cannot be 0. */
3746 wrq->u.freq.e = 1; 4051 if (scan_len % 76)
3747 } 4052 atom_len = 68;
4053 else if (scan_len % 68)
4054 atom_len = 76;
4055 else if (scan_len >= 1292 && scan[68] == 0)
4056 atom_len = 76;
4057 else
4058 atom_len = 68;
4059 offset = 0;
3748 break; 4060 break;
3749 4061 case FIRMWARE_TYPE_INTERSIL:
3750 case SIOCSIWFREQ: 4062 offset = 4;
3751 err = orinoco_ioctl_setfreq(dev, &wrq->u.freq); 4063 if (priv->has_hostscan)
3752 if (! err) 4064 atom_len = scan[0] + (scan[1] << 8);
3753 changed = 1; 4065 else
4066 atom_len = offsetof(struct prism2_scan_apinfo, atim);
3754 break; 4067 break;
4068 default:
4069 return 0;
4070 }
3755 4071
3756 case SIOCGIWSENS: 4072 /* Check that we got an whole number of atoms */
3757 err = orinoco_ioctl_getsens(dev, &wrq->u.sens); 4073 if ((scan_len - offset) % atom_len) {
3758 break; 4074 printk(KERN_ERR "%s: Unexpected scan data length %d, "
4075 "atom_len %d, offset %d\n", dev->name, scan_len,
4076 atom_len, offset);
4077 return 0;
4078 }
3759 4079
3760 case SIOCSIWSENS: 4080 /* Read the entries one by one */
3761 err = orinoco_ioctl_setsens(dev, &wrq->u.sens); 4081 for (; offset + atom_len <= scan_len; offset += atom_len) {
3762 if (! err) 4082 /* Get next atom */
3763 changed = 1; 4083 atom = (union hermes_scan_info *) (scan + offset);
3764 break; 4084
4085 /* First entry *MUST* be the AP MAC address */
4086 iwe.cmd = SIOCGIWAP;
4087 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4088 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4089 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4090
4091 /* Other entries will be displayed in the order we give them */
4092
4093 /* Add the ESSID */
4094 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4095 if (iwe.u.data.length > 32)
4096 iwe.u.data.length = 32;
4097 iwe.cmd = SIOCGIWESSID;
4098 iwe.u.data.flags = 1;
4099 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4100
4101 /* Add mode */
4102 iwe.cmd = SIOCGIWMODE;
4103 capabilities = le16_to_cpu(atom->a.capabilities);
4104 if (capabilities & 0x3) {
4105 if (capabilities & 0x1)
4106 iwe.u.mode = IW_MODE_MASTER;
4107 else
4108 iwe.u.mode = IW_MODE_ADHOC;
4109 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4110 }
3765 4111
3766 case SIOCGIWRTS: 4112 channel = atom->s.channel;
3767 wrq->u.rts.value = priv->rts_thresh; 4113 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
3768 wrq->u.rts.disabled = (wrq->u.rts.value == 2347); 4114 /* Add frequency */
3769 wrq->u.rts.fixed = 1; 4115 iwe.cmd = SIOCGIWFREQ;
3770 break; 4116 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4117 iwe.u.freq.e = 1;
4118 current_ev = iwe_stream_add_event(current_ev, end_buf,
4119 &iwe, IW_EV_FREQ_LEN);
4120 }
3771 4121
3772 case SIOCSIWRTS: 4122 /* Add quality statistics */
3773 err = orinoco_ioctl_setrts(dev, &wrq->u.rts); 4123 iwe.cmd = IWEVQUAL;
3774 if (! err) 4124 iwe.u.qual.updated = 0x10; /* no link quality */
3775 changed = 1; 4125 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
3776 break; 4126 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4127 /* Wireless tools prior to 27.pre22 will show link quality
4128 * anyway, so we provide a reasonable value. */
4129 if (iwe.u.qual.level > iwe.u.qual.noise)
4130 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4131 else
4132 iwe.u.qual.qual = 0;
4133 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
3777 4134
3778 case SIOCSIWFRAG: 4135 /* Add encryption capability */
3779 err = orinoco_ioctl_setfrag(dev, &wrq->u.frag); 4136 iwe.cmd = SIOCGIWENCODE;
3780 if (! err) 4137 if (capabilities & 0x10)
3781 changed = 1; 4138 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
3782 break; 4139 else
4140 iwe.u.data.flags = IW_ENCODE_DISABLED;
4141 iwe.u.data.length = 0;
4142 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4143
4144 /* Bit rate is not available in Lucent/Agere firmwares */
4145 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4146 char * current_val = current_ev + IW_EV_LCP_LEN;
4147 int i;
4148 int step;
4149
4150 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4151 step = 2;
4152 else
4153 step = 1;
4154
4155 iwe.cmd = SIOCGIWRATE;
4156 /* Those two flags are ignored... */
4157 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4158 /* Max 10 values */
4159 for (i = 0; i < 10; i += step) {
4160 /* NULL terminated */
4161 if (atom->p.rates[i] == 0x0)
4162 break;
4163 /* Bit rate given in 500 kb/s units (+ 0x80) */
4164 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4165 current_val = iwe_stream_add_value(current_ev, current_val,
4166 end_buf, &iwe,
4167 IW_EV_PARAM_LEN);
4168 }
4169 /* Check if we added any event */
4170 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4171 current_ev = current_val;
4172 }
3783 4173
3784 case SIOCGIWFRAG: 4174 /* The other data in the scan result are not really
3785 err = orinoco_ioctl_getfrag(dev, &wrq->u.frag); 4175 * interesting, so for now drop it - Jean II */
3786 break; 4176 }
4177 return current_ev - buffer;
4178}
3787 4179
3788 case SIOCSIWRATE: 4180/* Return results of a scan */
3789 err = orinoco_ioctl_setrate(dev, &wrq->u.bitrate); 4181static int orinoco_ioctl_getscan(struct net_device *dev,
3790 if (! err) 4182 struct iw_request_info *info,
3791 changed = 1; 4183 struct iw_point *srq,
3792 break; 4184 char *extra)
4185{
4186 struct orinoco_private *priv = netdev_priv(dev);
4187 int err = 0;
4188 unsigned long flags;
3793 4189
3794 case SIOCGIWRATE: 4190 if (orinoco_lock(priv, &flags) != 0)
3795 err = orinoco_ioctl_getrate(dev, &wrq->u.bitrate); 4191 return -EBUSY;
3796 break;
3797 4192
3798 case SIOCSIWPOWER: 4193 /* If no results yet, ask to try again later */
3799 err = orinoco_ioctl_setpower(dev, &wrq->u.power); 4194 if (priv->scan_result == NULL) {
3800 if (! err) 4195 if (priv->scan_inprogress)
3801 changed = 1; 4196 /* Important note : we don't want to block the caller
3802 break; 4197 * until results are ready for various reasons.
4198 * First, managing wait queues is complex and racy.
4199 * Second, we grab some rtnetlink lock before comming
4200 * here (in dev_ioctl()).
4201 * Third, we generate an Wireless Event, so the
4202 * caller can wait itself on that - Jean II */
4203 err = -EAGAIN;
4204 else
4205 /* Client error, no scan results...
4206 * The caller need to restart the scan. */
4207 err = -ENODATA;
4208 } else {
4209 /* We have some results to push back to user space */
4210
4211 /* Translate to WE format */
4212 srq->length = orinoco_translate_scan(dev, extra,
4213 priv->scan_result,
4214 priv->scan_len);
4215
4216 /* Return flags */
4217 srq->flags = (__u16) priv->scan_mode;
4218
4219 /* Results are here, so scan no longer in progress */
4220 priv->scan_inprogress = 0;
4221
4222 /* In any case, Scan results will be cleaned up in the
4223 * reset function and when exiting the driver.
4224 * The person triggering the scanning may never come to
4225 * pick the results, so we need to do it in those places.
4226 * Jean II */
4227
4228#ifdef SCAN_SINGLE_READ
4229 /* If you enable this option, only one client (the first
4230 * one) will be able to read the result (and only one
4231 * time). If there is multiple concurent clients that
4232 * want to read scan results, this behavior is not
4233 * advisable - Jean II */
4234 kfree(priv->scan_result);
4235 priv->scan_result = NULL;
4236#endif /* SCAN_SINGLE_READ */
4237 /* Here, if too much time has elapsed since last scan,
4238 * we may want to clean up scan results... - Jean II */
4239 }
4240
4241 orinoco_unlock(priv, &flags);
4242 return err;
4243}
3803 4244
3804 case SIOCGIWPOWER: 4245/* Commit handler, called after set operations */
3805 err = orinoco_ioctl_getpower(dev, &wrq->u.power); 4246static int orinoco_ioctl_commit(struct net_device *dev,
3806 break; 4247 struct iw_request_info *info,
4248 void *wrqu,
4249 char *extra)
4250{
4251 struct orinoco_private *priv = netdev_priv(dev);
4252 struct hermes *hw = &priv->hw;
4253 unsigned long flags;
4254 int err = 0;
3807 4255
3808 case SIOCGIWTXPOW: 4256 if (!priv->open)
3809 /* The card only supports one tx power, so this is easy */ 4257 return 0;
3810 wrq->u.txpower.value = 15; /* dBm */
3811 wrq->u.txpower.fixed = 1;
3812 wrq->u.txpower.disabled = 0;
3813 wrq->u.txpower.flags = IW_TXPOW_DBM;
3814 break;
3815 4258
3816 case SIOCSIWRETRY: 4259 if (priv->broken_disableport) {
3817 err = -EOPNOTSUPP; 4260 orinoco_reset(dev);
3818 break; 4261 return 0;
4262 }
3819 4263
3820 case SIOCGIWRETRY: 4264 if (orinoco_lock(priv, &flags) != 0)
3821 err = orinoco_ioctl_getretry(dev, &wrq->u.retry); 4265 return err;
3822 break;
3823 4266
3824 case SIOCSIWSPY: 4267 err = hermes_disable_port(hw, 0);
3825 err = orinoco_ioctl_setspy(dev, &wrq->u.data); 4268 if (err) {
3826 break; 4269 printk(KERN_WARNING "%s: Unable to disable port "
4270 "while reconfiguring card\n", dev->name);
4271 priv->broken_disableport = 1;
4272 goto out;
4273 }
3827 4274
3828 case SIOCGIWSPY: 4275 err = __orinoco_program_rids(dev);
3829 err = orinoco_ioctl_getspy(dev, &wrq->u.data); 4276 if (err) {
3830 break; 4277 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4278 dev->name);
4279 goto out;
4280 }
3831 4281
3832 case SIOCGIWPRIV: 4282 err = hermes_enable_port(hw, 0);
3833 if (wrq->u.data.pointer) { 4283 if (err) {
3834 struct iw_priv_args privtab[] = { 4284 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
3835 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" }, 4285 dev->name);
3836 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" }, 4286 goto out;
3837 { SIOCIWFIRSTPRIV + 0x2, 4287 }
3838 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3839 0, "set_port3" },
3840 { SIOCIWFIRSTPRIV + 0x3, 0,
3841 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3842 "get_port3" },
3843 { SIOCIWFIRSTPRIV + 0x4,
3844 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3845 0, "set_preamble" },
3846 { SIOCIWFIRSTPRIV + 0x5, 0,
3847 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3848 "get_preamble" },
3849 { SIOCIWFIRSTPRIV + 0x6,
3850 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3851 0, "set_ibssport" },
3852 { SIOCIWFIRSTPRIV + 0x7, 0,
3853 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3854 "get_ibssport" },
3855 };
3856
3857 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
3858 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
3859 err = -EFAULT;
3860 }
3861 break;
3862
3863 case SIOCIWFIRSTPRIV + 0x0: /* force_reset */
3864 case SIOCIWFIRSTPRIV + 0x1: /* card_reset */
3865 if (! capable(CAP_NET_ADMIN)) {
3866 err = -EPERM;
3867 break;
3868 }
3869
3870 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3871 4288
4289 out:
4290 if (err) {
4291 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
3872 schedule_work(&priv->reset_work); 4292 schedule_work(&priv->reset_work);
3873 break; 4293 err = 0;
3874 4294 }
3875 case SIOCIWFIRSTPRIV + 0x2: /* set_port3 */
3876 if (! capable(CAP_NET_ADMIN)) {
3877 err = -EPERM;
3878 break;
3879 }
3880
3881 err = orinoco_ioctl_setport3(dev, wrq);
3882 if (! err)
3883 changed = 1;
3884 break;
3885 4295
3886 case SIOCIWFIRSTPRIV + 0x3: /* get_port3 */ 4296 orinoco_unlock(priv, &flags);
3887 err = orinoco_ioctl_getport3(dev, wrq); 4297 return err;
3888 break; 4298}
3889 4299
3890 case SIOCIWFIRSTPRIV + 0x4: /* set_preamble */ 4300static const struct iw_priv_args orinoco_privtab[] = {
3891 if (! capable(CAP_NET_ADMIN)) { 4301 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
3892 err = -EPERM; 4302 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
3893 break; 4303 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3894 } 4304 0, "set_port3" },
4305 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4306 "get_port3" },
4307 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4308 0, "set_preamble" },
4309 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4310 "get_preamble" },
4311 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4312 0, "set_ibssport" },
4313 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4314 "get_ibssport" },
4315 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4316 "get_rid" },
4317};
3895 4318
3896 /* 802.11b has recently defined some short preamble.
3897 * Basically, the Phy header has been reduced in size.
3898 * This increase performance, especially at high rates
3899 * (the preamble is transmitted at 1Mb/s), unfortunately
3900 * this give compatibility troubles... - Jean II */
3901 if(priv->has_preamble) {
3902 int val = *( (int *) wrq->u.name );
3903
3904 if (orinoco_lock(priv, &flags) != 0)
3905 return -EBUSY;
3906 if (val)
3907 priv->preamble = 1;
3908 else
3909 priv->preamble = 0;
3910 orinoco_unlock(priv, &flags);
3911 changed = 1;
3912 } else
3913 err = -EOPNOTSUPP;
3914 break;
3915 4319
3916 case SIOCIWFIRSTPRIV + 0x5: /* get_preamble */ 4320/*
3917 if(priv->has_preamble) { 4321 * Structures to export the Wireless Handlers
3918 int *val = (int *)wrq->u.name; 4322 */
3919 4323
3920 if (orinoco_lock(priv, &flags) != 0) 4324static const iw_handler orinoco_handler[] = {
3921 return -EBUSY; 4325 [SIOCSIWCOMMIT-SIOCIWFIRST] (iw_handler) orinoco_ioctl_commit,
3922 *val = priv->preamble; 4326 [SIOCGIWNAME -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getname,
3923 orinoco_unlock(priv, &flags); 4327 [SIOCSIWFREQ -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setfreq,
3924 } else 4328 [SIOCGIWFREQ -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getfreq,
3925 err = -EOPNOTSUPP; 4329 [SIOCSIWMODE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setmode,
3926 break; 4330 [SIOCGIWMODE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getmode,
3927 case SIOCIWFIRSTPRIV + 0x6: /* set_ibssport */ 4331 [SIOCSIWSENS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setsens,
3928 if (! capable(CAP_NET_ADMIN)) { 4332 [SIOCGIWSENS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getsens,
3929 err = -EPERM; 4333 [SIOCGIWRANGE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getiwrange,
3930 break; 4334 [SIOCSIWSPY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setspy,
3931 } 4335 [SIOCGIWSPY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getspy,
4336 [SIOCSIWAP -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setwap,
4337 [SIOCGIWAP -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getwap,
4338 [SIOCSIWSCAN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setscan,
4339 [SIOCGIWSCAN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getscan,
4340 [SIOCSIWESSID -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setessid,
4341 [SIOCGIWESSID -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getessid,
4342 [SIOCSIWNICKN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setnick,
4343 [SIOCGIWNICKN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getnick,
4344 [SIOCSIWRATE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setrate,
4345 [SIOCGIWRATE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getrate,
4346 [SIOCSIWRTS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setrts,
4347 [SIOCGIWRTS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getrts,
4348 [SIOCSIWFRAG -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setfrag,
4349 [SIOCGIWFRAG -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getfrag,
4350 [SIOCGIWRETRY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getretry,
4351 [SIOCSIWENCODE-SIOCIWFIRST] (iw_handler) orinoco_ioctl_setiwencode,
4352 [SIOCGIWENCODE-SIOCIWFIRST] (iw_handler) orinoco_ioctl_getiwencode,
4353 [SIOCSIWPOWER -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setpower,
4354 [SIOCGIWPOWER -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getpower,
4355};
3932 4356
3933 err = orinoco_ioctl_setibssport(dev, wrq);
3934 if (! err)
3935 changed = 1;
3936 break;
3937 4357
3938 case SIOCIWFIRSTPRIV + 0x7: /* get_ibssport */ 4358/*
3939 err = orinoco_ioctl_getibssport(dev, wrq); 4359 Added typecasting since we no longer use iwreq_data -- Moustafa
3940 break; 4360 */
4361static const iw_handler orinoco_private_handler[] = {
4362 [0] (iw_handler) orinoco_ioctl_reset,
4363 [1] (iw_handler) orinoco_ioctl_reset,
4364 [2] (iw_handler) orinoco_ioctl_setport3,
4365 [3] (iw_handler) orinoco_ioctl_getport3,
4366 [4] (iw_handler) orinoco_ioctl_setpreamble,
4367 [5] (iw_handler) orinoco_ioctl_getpreamble,
4368 [6] (iw_handler) orinoco_ioctl_setibssport,
4369 [7] (iw_handler) orinoco_ioctl_getibssport,
4370 [9] (iw_handler) orinoco_ioctl_getrid,
4371};
3941 4372
3942 default: 4373static const struct iw_handler_def orinoco_handler_def = {
3943 err = -EOPNOTSUPP; 4374 .num_standard = ARRAY_SIZE(orinoco_handler),
3944 } 4375 .num_private = ARRAY_SIZE(orinoco_private_handler),
3945 4376 .num_private_args = ARRAY_SIZE(orinoco_privtab),
3946 if (! err && changed && netif_running(dev)) { 4377 .standard = orinoco_handler,
3947 err = orinoco_reconfigure(dev); 4378 .private = orinoco_private_handler,
3948 } 4379 .private_args = orinoco_privtab,
4380};
3949 4381
3950 TRACE_EXIT(dev->name); 4382static void orinoco_get_drvinfo(struct net_device *dev,
4383 struct ethtool_drvinfo *info)
4384{
4385 struct orinoco_private *priv = netdev_priv(dev);
3951 4386
3952 return err; 4387 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4388 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4389 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4390 if (dev->class_dev.dev)
4391 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4392 sizeof(info->bus_info) - 1);
4393 else
4394 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4395 "PCMCIA %p", priv->hw.iobase);
3953} 4396}
3954 4397
4398static struct ethtool_ops orinoco_ethtool_ops = {
4399 .get_drvinfo = orinoco_get_drvinfo,
4400 .get_link = ethtool_op_get_link,
4401};
3955 4402
3956/********************************************************************/ 4403/********************************************************************/
3957/* Debugging */ 4404/* Debugging */
diff --git a/drivers/net/wireless/orinoco.h b/drivers/net/wireless/orinoco.h
index f749b50d1088..2f213a7103fe 100644
--- a/drivers/net/wireless/orinoco.h
+++ b/drivers/net/wireless/orinoco.h
@@ -7,7 +7,7 @@
7#ifndef _ORINOCO_H 7#ifndef _ORINOCO_H
8#define _ORINOCO_H 8#define _ORINOCO_H
9 9
10#define DRIVER_VERSION "0.14alpha2" 10#define DRIVER_VERSION "0.15rc2"
11 11
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/spinlock.h> 13#include <linux/spinlock.h>
@@ -22,6 +22,8 @@
22 22
23#define WIRELESS_SPY // enable iwspy support 23#define WIRELESS_SPY // enable iwspy support
24 24
25#define MAX_SCAN_LEN 4096
26
25#define ORINOCO_MAX_KEY_SIZE 14 27#define ORINOCO_MAX_KEY_SIZE 14
26#define ORINOCO_MAX_KEYS 4 28#define ORINOCO_MAX_KEYS 4
27 29
@@ -30,6 +32,20 @@ struct orinoco_key {
30 char data[ORINOCO_MAX_KEY_SIZE]; 32 char data[ORINOCO_MAX_KEY_SIZE];
31} __attribute__ ((packed)); 33} __attribute__ ((packed));
32 34
35struct header_struct {
36 /* 802.3 */
37 u8 dest[ETH_ALEN];
38 u8 src[ETH_ALEN];
39 u16 len;
40 /* 802.2 */
41 u8 dsap;
42 u8 ssap;
43 u8 ctrl;
44 /* SNAP */
45 u8 oui[3];
46 u16 ethertype;
47} __attribute__ ((packed));
48
33typedef enum { 49typedef enum {
34 FIRMWARE_TYPE_AGERE, 50 FIRMWARE_TYPE_AGERE,
35 FIRMWARE_TYPE_INTERSIL, 51 FIRMWARE_TYPE_INTERSIL,
@@ -48,6 +64,8 @@ struct orinoco_private {
48 /* driver state */ 64 /* driver state */
49 int open; 65 int open;
50 u16 last_linkstatus; 66 u16 last_linkstatus;
67 struct work_struct join_work;
68 struct work_struct wevent_work;
51 69
52 /* Net device stuff */ 70 /* Net device stuff */
53 struct net_device *ndev; 71 struct net_device *ndev;
@@ -74,7 +92,9 @@ struct orinoco_private {
74 unsigned int has_pm:1; 92 unsigned int has_pm:1;
75 unsigned int has_preamble:1; 93 unsigned int has_preamble:1;
76 unsigned int has_sensitivity:1; 94 unsigned int has_sensitivity:1;
95 unsigned int has_hostscan:1;
77 unsigned int broken_disableport:1; 96 unsigned int broken_disableport:1;
97 unsigned int broken_monitor:1;
78 98
79 /* Configuration paramaters */ 99 /* Configuration paramaters */
80 u32 iw_mode; 100 u32 iw_mode;
@@ -84,6 +104,8 @@ struct orinoco_private {
84 int bitratemode; 104 int bitratemode;
85 char nick[IW_ESSID_MAX_SIZE+1]; 105 char nick[IW_ESSID_MAX_SIZE+1];
86 char desired_essid[IW_ESSID_MAX_SIZE+1]; 106 char desired_essid[IW_ESSID_MAX_SIZE+1];
107 char desired_bssid[ETH_ALEN];
108 int bssid_fixed;
87 u16 frag_thresh, mwo_robust; 109 u16 frag_thresh, mwo_robust;
88 u16 channel; 110 u16 channel;
89 u16 ap_density, rts_thresh; 111 u16 ap_density, rts_thresh;
@@ -98,6 +120,12 @@ struct orinoco_private {
98 /* Configuration dependent variables */ 120 /* Configuration dependent variables */
99 int port_type, createibss; 121 int port_type, createibss;
100 int promiscuous, mc_count; 122 int promiscuous, mc_count;
123
124 /* Scanning support */
125 int scan_inprogress; /* Scan pending... */
126 u32 scan_mode; /* Type of scan done */
127 char * scan_result; /* Result of previous scan */
128 int scan_len; /* Lenght of result */
101}; 129};
102 130
103#ifdef ORINOCO_DEBUG 131#ifdef ORINOCO_DEBUG
diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco_cs.c
index 74a8227256aa..597c4586d049 100644
--- a/drivers/net/wireless/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco_cs.c
@@ -608,6 +608,56 @@ static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
608 " (David Gibson <hermes@gibson.dropbear.id.au>, " 608 " (David Gibson <hermes@gibson.dropbear.id.au>, "
609 "Pavel Roskin <proski@gnu.org>, et al)"; 609 "Pavel Roskin <proski@gnu.org>, et al)";
610 610
611static struct pcmcia_device_id orinoco_cs_ids[] = {
612 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
613 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0001),
614 PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002),
615 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002),
616 PCMCIA_DEVICE_MANF_CARD(0x01eb, 0x080a),
617 PCMCIA_DEVICE_MANF_CARD(0x0261, 0x0002),
618 PCMCIA_DEVICE_MANF_CARD(0x0268, 0x0001),
619 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0305),
620 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613),
621 PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002),
622 PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0673),
623 PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002),
624 PCMCIA_DEVICE_MANF_CARD(0x02ac, 0x0002),
625 PCMCIA_DEVICE_MANF_CARD(0x14ea, 0xb001),
626 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300),
627 PCMCIA_DEVICE_MANF_CARD(0x9005, 0x0021),
628 PCMCIA_DEVICE_MANF_CARD(0xc250, 0x0002),
629 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
630 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
631 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
632 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
633 PCMCIA_DEVICE_PROD_ID12("3Com", "3CRWE737A AirConnect Wireless LAN PC Card", 0x41240e5b, 0x56010af3),
634 PCMCIA_DEVICE_PROD_ID123("Instant Wireless ", " Network PC CARD", "Version 01.02", 0x11d901af, 0x6e9bd926, 0x4b74baa0),
635 PCMCIA_DEVICE_PROD_ID12("ACTIONTEC", "PRISM Wireless LAN PC Card", 0x393089da, 0xa71e69d5),
636 PCMCIA_DEVICE_PROD_ID12("Avaya Communication", "Avaya Wireless PC Card", 0xd8a43b78, 0x0d341169),
637 PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-PCM-L11G", 0x2decece3, 0xf57ca4b3),
638 PCMCIA_DEVICE_PROD_ID12("Cabletron", "RoamAbout 802.11 DS", 0x32d445f5, 0xedeffd90),
639 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "Wireless LAN PCC-11", 0x5261440f, 0xa6405584),
640 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "Wireless LAN PCCA-11", 0x5261440f, 0xdf6115f9),
641 PCMCIA_DEVICE_PROD_ID12("D", "Link DRC-650 11Mbps WLAN Card", 0x71b18589, 0xf144e3ac),
642 PCMCIA_DEVICE_PROD_ID12("D", "Link DWL-650 11Mbps WLAN Card", 0x71b18589, 0xb6f1b0ab),
643 PCMCIA_DEVICE_PROD_ID12("ELSA", "AirLancer MC-11", 0x4507a33a, 0xef54f0e3),
644 PCMCIA_DEVICE_PROD_ID12("HyperLink", "Wireless PC Card 11Mbps", 0x56cc3f1a, 0x0bcf220c),
645 PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE", 0x74c5e40d, 0xdb472a18),
646 PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/IEEE", 0x23eb9949, 0xc562e72a),
647 PCMCIA_DEVICE_PROD_ID12("MELCO", "WLI-PCM-L11", 0x481e0094, 0x7360e410),
648 PCMCIA_DEVICE_PROD_ID12("MELCO", "WLI-PCM-L11G", 0x481e0094, 0xf57ca4b3),
649 PCMCIA_DEVICE_PROD_ID12("Microsoft", "Wireless Notebook Adapter MN-520", 0x5961bf85, 0x6eec8c01),
650 PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/IEEE", 0x24358cd4, 0xc562e72a),
651 PCMCIA_DEVICE_PROD_ID12("NETGEAR MA401RA Wireless PC", "Card", 0x0306467f, 0x9762e8f1),
652 PCMCIA_DEVICE_PROD_ID12("PLANEX", "GeoWave/GW-CF110", 0x209f40ab, 0xd9715264),
653 PCMCIA_DEVICE_PROD_ID12("PROXIM", "LAN PC CARD HARMONY 80211B", 0xc6536a5e, 0x090c3cd9),
654 PCMCIA_DEVICE_PROD_ID12("PROXIM", "LAN PCI CARD HARMONY 80211B", 0xc6536a5e, 0x9f494e26),
655 PCMCIA_DEVICE_PROD_ID12("SAMSUNG", "11Mbps WLAN Card", 0x43d74cb4, 0x579bd91b),
656 PCMCIA_DEVICE_PROD_ID1("Symbol Technologies", 0x3f02b4d6),
657 PCMCIA_DEVICE_NULL,
658};
659MODULE_DEVICE_TABLE(pcmcia, orinoco_cs_ids);
660
611static struct pcmcia_driver orinoco_driver = { 661static struct pcmcia_driver orinoco_driver = {
612 .owner = THIS_MODULE, 662 .owner = THIS_MODULE,
613 .drv = { 663 .drv = {
@@ -615,6 +665,7 @@ static struct pcmcia_driver orinoco_driver = {
615 }, 665 },
616 .attach = orinoco_cs_attach, 666 .attach = orinoco_cs_attach,
617 .detach = orinoco_cs_detach, 667 .detach = orinoco_cs_detach,
668 .id_table = orinoco_cs_ids,
618}; 669};
619 670
620static int __init 671static int __init
diff --git a/drivers/net/wireless/prism54/isl_38xx.c b/drivers/net/wireless/prism54/isl_38xx.c
index 4481ec18c5a0..adc7499136dc 100644
--- a/drivers/net/wireless/prism54/isl_38xx.c
+++ b/drivers/net/wireless/prism54/isl_38xx.c
@@ -112,10 +112,10 @@ isl38xx_handle_wakeup(isl38xx_control_block *control_block,
112void 112void
113isl38xx_trigger_device(int asleep, void __iomem *device_base) 113isl38xx_trigger_device(int asleep, void __iomem *device_base)
114{ 114{
115 struct timeval current_time;
116 u32 reg, counter = 0; 115 u32 reg, counter = 0;
117 116
118#if VERBOSE > SHOW_ERROR_MESSAGES 117#if VERBOSE > SHOW_ERROR_MESSAGES
118 struct timeval current_time;
119 DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n"); 119 DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n");
120#endif 120#endif
121 121
@@ -126,11 +126,11 @@ isl38xx_trigger_device(int asleep, void __iomem *device_base)
126 do_gettimeofday(&current_time); 126 do_gettimeofday(&current_time);
127 DEBUG(SHOW_TRACING, "%08li.%08li Device wakeup triggered\n", 127 DEBUG(SHOW_TRACING, "%08li.%08li Device wakeup triggered\n",
128 current_time.tv_sec, (long)current_time.tv_usec); 128 current_time.tv_sec, (long)current_time.tv_usec);
129#endif
130 129
131 DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n", 130 DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
132 current_time.tv_sec, (long)current_time.tv_usec, 131 current_time.tv_sec, (long)current_time.tv_usec,
133 readl(device_base + ISL38XX_CTRL_STAT_REG)); 132 readl(device_base + ISL38XX_CTRL_STAT_REG));
133#endif
134 udelay(ISL38XX_WRITEIO_DELAY); 134 udelay(ISL38XX_WRITEIO_DELAY);
135 135
136 reg = readl(device_base + ISL38XX_INT_IDENT_REG); 136 reg = readl(device_base + ISL38XX_INT_IDENT_REG);
@@ -148,10 +148,12 @@ isl38xx_trigger_device(int asleep, void __iomem *device_base)
148 counter++; 148 counter++;
149 } 149 }
150 150
151#if VERBOSE > SHOW_ERROR_MESSAGES
151 DEBUG(SHOW_TRACING, 152 DEBUG(SHOW_TRACING,
152 "%08li.%08li Device register read %08x\n", 153 "%08li.%08li Device register read %08x\n",
153 current_time.tv_sec, (long)current_time.tv_usec, 154 current_time.tv_sec, (long)current_time.tv_usec,
154 readl(device_base + ISL38XX_CTRL_STAT_REG)); 155 readl(device_base + ISL38XX_CTRL_STAT_REG));
156#endif
155 udelay(ISL38XX_WRITEIO_DELAY); 157 udelay(ISL38XX_WRITEIO_DELAY);
156 158
157#if VERBOSE > SHOW_ERROR_MESSAGES 159#if VERBOSE > SHOW_ERROR_MESSAGES
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 6e5bda56b8f8..31652af52eac 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -2904,6 +2904,12 @@ static int write_int(struct file *file, const char __user *buffer, unsigned long
2904} 2904}
2905#endif 2905#endif
2906 2906
2907static struct pcmcia_device_id ray_ids[] = {
2908 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2909 PCMCIA_DEVICE_NULL,
2910};
2911MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2912
2907static struct pcmcia_driver ray_driver = { 2913static struct pcmcia_driver ray_driver = {
2908 .owner = THIS_MODULE, 2914 .owner = THIS_MODULE,
2909 .drv = { 2915 .drv = {
@@ -2911,6 +2917,7 @@ static struct pcmcia_driver ray_driver = {
2911 }, 2917 },
2912 .attach = ray_attach, 2918 .attach = ray_attach,
2913 .detach = ray_detach, 2919 .detach = ray_detach,
2920 .id_table = ray_ids,
2914}; 2921};
2915 2922
2916static int __init init_ray_cs(void) 2923static int __init init_ray_cs(void)
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c
index ec8329788e49..89532fd92941 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/net/wireless/wavelan_cs.c
@@ -4889,6 +4889,15 @@ wavelan_event(event_t event, /* The event received */
4889 return 0; 4889 return 0;
4890} 4890}
4891 4891
4892static struct pcmcia_device_id wavelan_ids[] = {
4893 PCMCIA_DEVICE_PROD_ID12("AT&T","WaveLAN/PCMCIA", 0xe7c5affd, 0x1bc50975),
4894 PCMCIA_DEVICE_PROD_ID12("Digital", "RoamAbout/DS", 0x9999ab35, 0x00d05e06),
4895 PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/PCMCIA", 0x23eb9949, 0x1bc50975),
4896 PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/PCMCIA", 0x24358cd4, 0x1bc50975),
4897 PCMCIA_DEVICE_NULL,
4898};
4899MODULE_DEVICE_TABLE(pcmcia, wavelan_ids);
4900
4892static struct pcmcia_driver wavelan_driver = { 4901static struct pcmcia_driver wavelan_driver = {
4893 .owner = THIS_MODULE, 4902 .owner = THIS_MODULE,
4894 .drv = { 4903 .drv = {
@@ -4896,6 +4905,7 @@ static struct pcmcia_driver wavelan_driver = {
4896 }, 4905 },
4897 .attach = wavelan_attach, 4906 .attach = wavelan_attach,
4898 .detach = wavelan_detach, 4907 .detach = wavelan_detach,
4908 .id_table = wavelan_ids,
4899}; 4909};
4900 4910
4901static int __init 4911static int __init
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index 1433e5aaf1b4..e3a900482d92 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -2239,6 +2239,12 @@ static int wl3501_event(event_t event, int pri, event_callback_args_t *args)
2239 return 0; 2239 return 0;
2240} 2240}
2241 2241
2242static struct pcmcia_device_id wl3501_ids[] = {
2243 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001),
2244 PCMCIA_DEVICE_NULL
2245};
2246MODULE_DEVICE_TABLE(pcmcia, wl3501_ids);
2247
2242static struct pcmcia_driver wl3501_driver = { 2248static struct pcmcia_driver wl3501_driver = {
2243 .owner = THIS_MODULE, 2249 .owner = THIS_MODULE,
2244 .drv = { 2250 .drv = {
@@ -2246,6 +2252,7 @@ static struct pcmcia_driver wl3501_driver = {
2246 }, 2252 },
2247 .attach = wl3501_attach, 2253 .attach = wl3501_attach,
2248 .detach = wl3501_detach, 2254 .detach = wl3501_detach,
2255 .id_table = wl3501_ids,
2249}; 2256};
2250 2257
2251static int __init wl3501_init_module(void) 2258static int __init wl3501_init_module(void)
diff --git a/drivers/net/yellowfin.c b/drivers/net/yellowfin.c
index 9da925430109..1c2506535f7e 100644
--- a/drivers/net/yellowfin.c
+++ b/drivers/net/yellowfin.c
@@ -786,7 +786,7 @@ static void yellowfin_init_ring(struct net_device *dev)
786 skb->dev = dev; /* Mark as being used by this device. */ 786 skb->dev = dev; /* Mark as being used by this device. */
787 skb_reserve(skb, 2); /* 16 byte align the IP header. */ 787 skb_reserve(skb, 2); /* 16 byte align the IP header. */
788 yp->rx_ring[i].addr = cpu_to_le32(pci_map_single(yp->pci_dev, 788 yp->rx_ring[i].addr = cpu_to_le32(pci_map_single(yp->pci_dev,
789 skb->tail, yp->rx_buf_sz, PCI_DMA_FROMDEVICE)); 789 skb->data, yp->rx_buf_sz, PCI_DMA_FROMDEVICE));
790 } 790 }
791 yp->rx_ring[i-1].dbdma_cmd = cpu_to_le32(CMD_STOP); 791 yp->rx_ring[i-1].dbdma_cmd = cpu_to_le32(CMD_STOP);
792 yp->dirty_rx = (unsigned int)(i - RX_RING_SIZE); 792 yp->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
@@ -1111,7 +1111,7 @@ static int yellowfin_rx(struct net_device *dev)
1111 pci_dma_sync_single_for_cpu(yp->pci_dev, desc->addr, 1111 pci_dma_sync_single_for_cpu(yp->pci_dev, desc->addr,
1112 yp->rx_buf_sz, PCI_DMA_FROMDEVICE); 1112 yp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1113 desc_status = le32_to_cpu(desc->result_status) >> 16; 1113 desc_status = le32_to_cpu(desc->result_status) >> 16;
1114 buf_addr = rx_skb->tail; 1114 buf_addr = rx_skb->data;
1115 data_size = (le32_to_cpu(desc->dbdma_cmd) - 1115 data_size = (le32_to_cpu(desc->dbdma_cmd) -
1116 le32_to_cpu(desc->result_status)) & 0xffff; 1116 le32_to_cpu(desc->result_status)) & 0xffff;
1117 frame_status = le16_to_cpu(get_unaligned((s16*)&(buf_addr[data_size - 2]))); 1117 frame_status = le16_to_cpu(get_unaligned((s16*)&(buf_addr[data_size - 2])));
@@ -1185,7 +1185,7 @@ static int yellowfin_rx(struct net_device *dev)
1185 break; 1185 break;
1186 skb->dev = dev; 1186 skb->dev = dev;
1187 skb_reserve(skb, 2); /* 16 byte align the IP header */ 1187 skb_reserve(skb, 2); /* 16 byte align the IP header */
1188 eth_copy_and_sum(skb, rx_skb->tail, pkt_len, 0); 1188 eth_copy_and_sum(skb, rx_skb->data, pkt_len, 0);
1189 skb_put(skb, pkt_len); 1189 skb_put(skb, pkt_len);
1190 pci_dma_sync_single_for_device(yp->pci_dev, desc->addr, 1190 pci_dma_sync_single_for_device(yp->pci_dev, desc->addr,
1191 yp->rx_buf_sz, 1191 yp->rx_buf_sz,
@@ -1211,7 +1211,7 @@ static int yellowfin_rx(struct net_device *dev)
1211 skb->dev = dev; /* Mark as being used by this device. */ 1211 skb->dev = dev; /* Mark as being used by this device. */
1212 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 1212 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1213 yp->rx_ring[entry].addr = cpu_to_le32(pci_map_single(yp->pci_dev, 1213 yp->rx_ring[entry].addr = cpu_to_le32(pci_map_single(yp->pci_dev,
1214 skb->tail, yp->rx_buf_sz, PCI_DMA_FROMDEVICE)); 1214 skb->data, yp->rx_buf_sz, PCI_DMA_FROMDEVICE));
1215 } 1215 }
1216 yp->rx_ring[entry].dbdma_cmd = cpu_to_le32(CMD_STOP); 1216 yp->rx_ring[entry].dbdma_cmd = cpu_to_le32(CMD_STOP);
1217 yp->rx_ring[entry].result_status = 0; /* Clear complete bit. */ 1217 yp->rx_ring[entry].result_status = 0; /* Clear complete bit. */
diff --git a/drivers/parisc/dino.c b/drivers/parisc/dino.c
index b0d2a73d1d47..2f2dbef2c3b7 100644
--- a/drivers/parisc/dino.c
+++ b/drivers/parisc/dino.c
@@ -993,6 +993,7 @@ dino_driver_callback(struct parisc_device *dev)
993 bus = pci_scan_bus_parented(&dev->dev, dino_current_bus, 993 bus = pci_scan_bus_parented(&dev->dev, dino_current_bus,
994 &dino_cfg_ops, NULL); 994 &dino_cfg_ops, NULL);
995 if(bus) { 995 if(bus) {
996 pci_bus_add_devices(bus);
996 /* This code *depends* on scanning being single threaded 997 /* This code *depends* on scanning being single threaded
997 * if it isn't, this global bus number count will fail 998 * if it isn't, this global bus number count will fail
998 */ 999 */
diff --git a/drivers/parisc/lba_pci.c b/drivers/parisc/lba_pci.c
index dc838804c0dd..7fdd80b7eb47 100644
--- a/drivers/parisc/lba_pci.c
+++ b/drivers/parisc/lba_pci.c
@@ -1570,6 +1570,8 @@ lba_driver_probe(struct parisc_device *dev)
1570 lba_bus = lba_dev->hba.hba_bus = 1570 lba_bus = lba_dev->hba.hba_bus =
1571 pci_scan_bus_parented(&dev->dev, lba_dev->hba.bus_num.start, 1571 pci_scan_bus_parented(&dev->dev, lba_dev->hba.bus_num.start,
1572 cfg_ops, NULL); 1572 cfg_ops, NULL);
1573 if (lba_bus)
1574 pci_bus_add_devices(lba_bus);
1573 1575
1574 /* This is in lieu of calling pci_assign_unassigned_resources() */ 1576 /* This is in lieu of calling pci_assign_unassigned_resources() */
1575 if (is_pdc_pat()) { 1577 if (is_pdc_pat()) {
diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c
index a3fa8185af2a..ff45662c4f7c 100644
--- a/drivers/parport/parport_cs.c
+++ b/drivers/parport/parport_cs.c
@@ -373,6 +373,13 @@ int parport_event(event_t event, int priority,
373 return 0; 373 return 0;
374} /* parport_event */ 374} /* parport_event */
375 375
376static struct pcmcia_device_id parport_ids[] = {
377 PCMCIA_DEVICE_FUNC_ID(3),
378 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0003),
379 PCMCIA_DEVICE_NULL
380};
381MODULE_DEVICE_TABLE(pcmcia, parport_ids);
382
376static struct pcmcia_driver parport_cs_driver = { 383static struct pcmcia_driver parport_cs_driver = {
377 .owner = THIS_MODULE, 384 .owner = THIS_MODULE,
378 .drv = { 385 .drv = {
@@ -380,6 +387,8 @@ static struct pcmcia_driver parport_cs_driver = {
380 }, 387 },
381 .attach = parport_attach, 388 .attach = parport_attach,
382 .detach = parport_detach, 389 .detach = parport_detach,
390 .id_table = parport_ids,
391
383}; 392};
384 393
385static int __init init_parport_cs(void) 394static int __init init_parport_cs(void)
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index dbd33605cc10..fedae89d8f7d 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -121,10 +121,13 @@ void __devinit pci_bus_add_devices(struct pci_bus *bus)
121 * If there is an unattached subordinate bus, attach 121 * If there is an unattached subordinate bus, attach
122 * it and then scan for unattached PCI devices. 122 * it and then scan for unattached PCI devices.
123 */ 123 */
124 if (dev->subordinate && list_empty(&dev->subordinate->node)) { 124 if (dev->subordinate) {
125 spin_lock(&pci_bus_lock); 125 if (list_empty(&dev->subordinate->node)) {
126 list_add_tail(&dev->subordinate->node, &dev->bus->children); 126 spin_lock(&pci_bus_lock);
127 spin_unlock(&pci_bus_lock); 127 list_add_tail(&dev->subordinate->node,
128 &dev->bus->children);
129 spin_unlock(&pci_bus_lock);
130 }
128 pci_bus_add_devices(dev->subordinate); 131 pci_bus_add_devices(dev->subordinate);
129 132
130 sysfs_create_link(&dev->subordinate->class_dev.kobj, &dev->dev.kobj, "bridge"); 133 sysfs_create_link(&dev->subordinate->class_dev.kobj, &dev->dev.kobj, "bridge");
diff --git a/drivers/pci/hotplug/Makefile b/drivers/pci/hotplug/Makefile
index 93c120ddbd39..3e632ff8c717 100644
--- a/drivers/pci/hotplug/Makefile
+++ b/drivers/pci/hotplug/Makefile
@@ -36,9 +36,7 @@ ibmphp-objs := ibmphp_core.o \
36 ibmphp_hpc.o 36 ibmphp_hpc.o
37 37
38acpiphp-objs := acpiphp_core.o \ 38acpiphp-objs := acpiphp_core.o \
39 acpiphp_glue.o \ 39 acpiphp_glue.o
40 acpiphp_pci.o \
41 acpiphp_res.o
42 40
43rpaphp-objs := rpaphp_core.o \ 41rpaphp-objs := rpaphp_core.o \
44 rpaphp_pci.o \ 42 rpaphp_pci.o \
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
index d9499874c8a9..293603e1b7c3 100644
--- a/drivers/pci/hotplug/acpiphp.h
+++ b/drivers/pci/hotplug/acpiphp.h
@@ -7,6 +7,8 @@
7 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com) 7 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
8 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com) 8 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
9 * Copyright (C) 2002,2003 NEC Corporation 9 * Copyright (C) 2002,2003 NEC Corporation
10 * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
11 * Copyright (C) 2003-2005 Hewlett Packard
10 * 12 *
11 * All rights reserved. 13 * All rights reserved.
12 * 14 *
@@ -52,7 +54,6 @@
52 54
53struct acpiphp_bridge; 55struct acpiphp_bridge;
54struct acpiphp_slot; 56struct acpiphp_slot;
55struct pci_resource;
56 57
57/* 58/*
58 * struct slot - slot information for each *physical* slot 59 * struct slot - slot information for each *physical* slot
@@ -65,15 +66,6 @@ struct slot {
65 struct acpiphp_slot *acpi_slot; 66 struct acpiphp_slot *acpi_slot;
66}; 67};
67 68
68/*
69 * struct pci_resource - describes pci resource (mem, pfmem, io, bus)
70 */
71struct pci_resource {
72 struct pci_resource * next;
73 u64 base;
74 u32 length;
75};
76
77/** 69/**
78 * struct hpp_param - ACPI 2.0 _HPP Hot Plug Parameters 70 * struct hpp_param - ACPI 2.0 _HPP Hot Plug Parameters
79 * @cache_line_size in DWORD 71 * @cache_line_size in DWORD
@@ -101,10 +93,6 @@ struct acpiphp_bridge {
101 int type; 93 int type;
102 int nr_slots; 94 int nr_slots;
103 95
104 u8 seg;
105 u8 bus;
106 u8 sub;
107
108 u32 flags; 96 u32 flags;
109 97
110 /* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */ 98 /* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */
@@ -117,12 +105,6 @@ struct acpiphp_bridge {
117 struct hpp_param hpp; 105 struct hpp_param hpp;
118 106
119 spinlock_t res_lock; 107 spinlock_t res_lock;
120
121 /* available resources on this bus */
122 struct pci_resource *mem_head;
123 struct pci_resource *p_mem_head;
124 struct pci_resource *io_head;
125 struct pci_resource *bus_head;
126}; 108};
127 109
128 110
@@ -163,12 +145,6 @@ struct acpiphp_func {
163 145
164 u8 function; /* pci function# */ 146 u8 function; /* pci function# */
165 u32 flags; /* see below */ 147 u32 flags; /* see below */
166
167 /* resources used for this function */
168 struct pci_resource *mem_head;
169 struct pci_resource *p_mem_head;
170 struct pci_resource *io_head;
171 struct pci_resource *bus_head;
172}; 148};
173 149
174/** 150/**
@@ -243,25 +219,6 @@ extern u8 acpiphp_get_latch_status (struct acpiphp_slot *slot);
243extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot); 219extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot);
244extern u32 acpiphp_get_address (struct acpiphp_slot *slot); 220extern u32 acpiphp_get_address (struct acpiphp_slot *slot);
245 221
246/* acpiphp_pci.c */
247extern struct pci_dev *acpiphp_allocate_pcidev (struct pci_bus *pbus, int dev, int fn);
248extern int acpiphp_configure_slot (struct acpiphp_slot *slot);
249extern int acpiphp_configure_function (struct acpiphp_func *func);
250extern void acpiphp_unconfigure_function (struct acpiphp_func *func);
251extern int acpiphp_detect_pci_resource (struct acpiphp_bridge *bridge);
252extern int acpiphp_init_func_resource (struct acpiphp_func *func);
253
254/* acpiphp_res.c */
255extern struct pci_resource *acpiphp_get_io_resource (struct pci_resource **head, u32 size);
256extern struct pci_resource *acpiphp_get_resource (struct pci_resource **head, u32 size);
257extern struct pci_resource *acpiphp_get_resource_with_base (struct pci_resource **head, u64 base, u32 size);
258extern int acpiphp_resource_sort_and_combine (struct pci_resource **head);
259extern struct pci_resource *acpiphp_make_resource (u64 base, u32 length);
260extern void acpiphp_move_resource (struct pci_resource **from, struct pci_resource **to);
261extern void acpiphp_free_resource (struct pci_resource **res);
262extern void acpiphp_dump_resource (struct acpiphp_bridge *bridge); /* debug */
263extern void acpiphp_dump_func_resource (struct acpiphp_func *func); /* debug */
264
265/* variables */ 222/* variables */
266extern int acpiphp_debug; 223extern int acpiphp_debug;
267 224
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
index 4539e61a3dc1..60c4c38047a3 100644
--- a/drivers/pci/hotplug/acpiphp_core.c
+++ b/drivers/pci/hotplug/acpiphp_core.c
@@ -7,6 +7,8 @@
7 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com) 7 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
8 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com) 8 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
9 * Copyright (C) 2002,2003 NEC Corporation 9 * Copyright (C) 2002,2003 NEC Corporation
10 * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
11 * Copyright (C) 2003-2005 Hewlett Packard
10 * 12 *
11 * All rights reserved. 13 * All rights reserved.
12 * 14 *
@@ -53,8 +55,8 @@ int acpiphp_debug;
53static int num_slots; 55static int num_slots;
54static struct acpiphp_attention_info *attention_info; 56static struct acpiphp_attention_info *attention_info;
55 57
56#define DRIVER_VERSION "0.4" 58#define DRIVER_VERSION "0.5"
57#define DRIVER_AUTHOR "Greg Kroah-Hartman <gregkh@us.ibm.com>, Takayoshi Kochi <t-kochi@bq.jp.nec.com>" 59#define DRIVER_AUTHOR "Greg Kroah-Hartman <gregkh@us.ibm.com>, Takayoshi Kochi <t-kochi@bq.jp.nec.com>, Matthew Wilcox <willy@hp.com>"
58#define DRIVER_DESC "ACPI Hot Plug PCI Controller Driver" 60#define DRIVER_DESC "ACPI Hot Plug PCI Controller Driver"
59 61
60MODULE_AUTHOR(DRIVER_AUTHOR); 62MODULE_AUTHOR(DRIVER_AUTHOR);
@@ -281,8 +283,7 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
281/** 283/**
282 * get_address - get pci address of a slot 284 * get_address - get pci address of a slot
283 * @hotplug_slot: slot to get status 285 * @hotplug_slot: slot to get status
284 * @busdev: pointer to struct pci_busdev (seg, bus, dev) 286 * @value: pointer to struct pci_busdev (seg, bus, dev)
285 *
286 */ 287 */
287static int get_address(struct hotplug_slot *hotplug_slot, u32 *value) 288static int get_address(struct hotplug_slot *hotplug_slot, u32 *value)
288{ 289{
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index e7f41294f811..424e7de181ae 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -4,6 +4,10 @@
4 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com) 4 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
5 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com) 5 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
6 * Copyright (C) 2002,2003 NEC Corporation 6 * Copyright (C) 2002,2003 NEC Corporation
7 * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
8 * Copyright (C) 2003-2005 Hewlett Packard
9 * Copyright (C) 2005 Rajesh Shah (rajesh.shah@intel.com)
10 * Copyright (C) 2005 Intel Corporation
7 * 11 *
8 * All rights reserved. 12 * All rights reserved.
9 * 13 *
@@ -26,6 +30,16 @@
26 * 30 *
27 */ 31 */
28 32
33/*
34 * Lifetime rules for pci_dev:
35 * - The one in acpiphp_func has its refcount elevated by pci_get_slot()
36 * when the driver is loaded or when an insertion event occurs. It loses
37 * a refcount when its ejected or the driver unloads.
38 * - The one in acpiphp_bridge has its refcount elevated by pci_get_slot()
39 * when the bridge is scanned and it loses a refcount when the bridge
40 * is removed.
41 */
42
29#include <linux/init.h> 43#include <linux/init.h>
30#include <linux/module.h> 44#include <linux/module.h>
31 45
@@ -178,21 +192,18 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
178 192
179 bridge->nr_slots++; 193 bridge->nr_slots++;
180 194
181 dbg("found ACPI PCI Hotplug slot at PCI %02x:%02x Slot:%d\n", 195 dbg("found ACPI PCI Hotplug slot %d at PCI %04x:%02x:%02x\n",
182 slot->bridge->bus, slot->device, slot->sun); 196 slot->sun, pci_domain_nr(bridge->pci_bus),
197 bridge->pci_bus->number, slot->device);
183 } 198 }
184 199
185 newfunc->slot = slot; 200 newfunc->slot = slot;
186 list_add_tail(&newfunc->sibling, &slot->funcs); 201 list_add_tail(&newfunc->sibling, &slot->funcs);
187 202
188 /* associate corresponding pci_dev */ 203 /* associate corresponding pci_dev */
189 newfunc->pci_dev = pci_find_slot(bridge->bus, 204 newfunc->pci_dev = pci_get_slot(bridge->pci_bus,
190 PCI_DEVFN(device, function)); 205 PCI_DEVFN(device, function));
191 if (newfunc->pci_dev) { 206 if (newfunc->pci_dev) {
192 if (acpiphp_init_func_resource(newfunc) < 0) {
193 kfree(newfunc);
194 return AE_ERROR;
195 }
196 slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON); 207 slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON);
197 } 208 }
198 209
@@ -227,62 +238,6 @@ static int detect_ejectable_slots(acpi_handle *bridge_handle)
227} 238}
228 239
229 240
230/* decode ACPI _CRS data and convert into our internal resource list
231 * TBD: _TRA, etc.
232 */
233static acpi_status
234decode_acpi_resource(struct acpi_resource *resource, void *context)
235{
236 struct acpiphp_bridge *bridge = (struct acpiphp_bridge *) context;
237 struct acpi_resource_address64 address;
238 struct pci_resource *res;
239
240 if (resource->id != ACPI_RSTYPE_ADDRESS16 &&
241 resource->id != ACPI_RSTYPE_ADDRESS32 &&
242 resource->id != ACPI_RSTYPE_ADDRESS64)
243 return AE_OK;
244
245 acpi_resource_to_address64(resource, &address);
246
247 if (address.producer_consumer == ACPI_PRODUCER && address.address_length > 0) {
248 dbg("resource type: %d: 0x%llx - 0x%llx\n", address.resource_type,
249 (unsigned long long)address.min_address_range,
250 (unsigned long long)address.max_address_range);
251 res = acpiphp_make_resource(address.min_address_range,
252 address.address_length);
253 if (!res) {
254 err("out of memory\n");
255 return AE_OK;
256 }
257
258 switch (address.resource_type) {
259 case ACPI_MEMORY_RANGE:
260 if (address.attribute.memory.cache_attribute == ACPI_PREFETCHABLE_MEMORY) {
261 res->next = bridge->p_mem_head;
262 bridge->p_mem_head = res;
263 } else {
264 res->next = bridge->mem_head;
265 bridge->mem_head = res;
266 }
267 break;
268 case ACPI_IO_RANGE:
269 res->next = bridge->io_head;
270 bridge->io_head = res;
271 break;
272 case ACPI_BUS_NUMBER_RANGE:
273 res->next = bridge->bus_head;
274 bridge->bus_head = res;
275 break;
276 default:
277 /* invalid type */
278 kfree(res);
279 break;
280 }
281 }
282
283 return AE_OK;
284}
285
286/* decode ACPI 2.0 _HPP hot plug parameters */ 241/* decode ACPI 2.0 _HPP hot plug parameters */
287static void decode_hpp(struct acpiphp_bridge *bridge) 242static void decode_hpp(struct acpiphp_bridge *bridge)
288{ 243{
@@ -346,34 +301,29 @@ static void init_bridge_misc(struct acpiphp_bridge *bridge)
346 /* decode ACPI 2.0 _HPP (hot plug parameters) */ 301 /* decode ACPI 2.0 _HPP (hot plug parameters) */
347 decode_hpp(bridge); 302 decode_hpp(bridge);
348 303
349 /* subtract all resources already allocated */
350 acpiphp_detect_pci_resource(bridge);
351
352 /* register all slot objects under this bridge */ 304 /* register all slot objects under this bridge */
353 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1, 305 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1,
354 register_slot, bridge, NULL); 306 register_slot, bridge, NULL);
355 307
356 /* install notify handler */ 308 /* install notify handler */
357 status = acpi_install_notify_handler(bridge->handle, 309 if (bridge->type != BRIDGE_TYPE_HOST) {
310 status = acpi_install_notify_handler(bridge->handle,
358 ACPI_SYSTEM_NOTIFY, 311 ACPI_SYSTEM_NOTIFY,
359 handle_hotplug_event_bridge, 312 handle_hotplug_event_bridge,
360 bridge); 313 bridge);
361 314
362 if (ACPI_FAILURE(status)) { 315 if (ACPI_FAILURE(status)) {
363 err("failed to register interrupt notify handler\n"); 316 err("failed to register interrupt notify handler\n");
317 }
364 } 318 }
365 319
366 list_add(&bridge->list, &bridge_list); 320 list_add(&bridge->list, &bridge_list);
367
368 dbg("Bridge resource:\n");
369 acpiphp_dump_resource(bridge);
370} 321}
371 322
372 323
373/* allocate and initialize host bridge data structure */ 324/* allocate and initialize host bridge data structure */
374static void add_host_bridge(acpi_handle *handle, int seg, int bus) 325static void add_host_bridge(acpi_handle *handle, struct pci_bus *pci_bus)
375{ 326{
376 acpi_status status;
377 struct acpiphp_bridge *bridge; 327 struct acpiphp_bridge *bridge;
378 328
379 bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL); 329 bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
@@ -384,52 +334,19 @@ static void add_host_bridge(acpi_handle *handle, int seg, int bus)
384 334
385 bridge->type = BRIDGE_TYPE_HOST; 335 bridge->type = BRIDGE_TYPE_HOST;
386 bridge->handle = handle; 336 bridge->handle = handle;
387 bridge->seg = seg;
388 bridge->bus = bus;
389 337
390 bridge->pci_bus = pci_find_bus(seg, bus); 338 bridge->pci_bus = pci_bus;
391 339
392 spin_lock_init(&bridge->res_lock); 340 spin_lock_init(&bridge->res_lock);
393 341
394 /* to be overridden when we decode _CRS */
395 bridge->sub = bridge->bus;
396
397 /* decode resources */
398
399 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
400 decode_acpi_resource, bridge);
401
402 if (ACPI_FAILURE(status)) {
403 err("failed to decode bridge resources\n");
404 kfree(bridge);
405 return;
406 }
407
408 acpiphp_resource_sort_and_combine(&bridge->io_head);
409 acpiphp_resource_sort_and_combine(&bridge->mem_head);
410 acpiphp_resource_sort_and_combine(&bridge->p_mem_head);
411 acpiphp_resource_sort_and_combine(&bridge->bus_head);
412
413 dbg("ACPI _CRS resource:\n");
414 acpiphp_dump_resource(bridge);
415
416 if (bridge->bus_head) {
417 bridge->bus = bridge->bus_head->base;
418 bridge->sub = bridge->bus_head->base + bridge->bus_head->length - 1;
419 }
420
421 init_bridge_misc(bridge); 342 init_bridge_misc(bridge);
422} 343}
423 344
424 345
425/* allocate and initialize PCI-to-PCI bridge data structure */ 346/* allocate and initialize PCI-to-PCI bridge data structure */
426static void add_p2p_bridge(acpi_handle *handle, int seg, int bus, int dev, int fn) 347static void add_p2p_bridge(acpi_handle *handle, struct pci_dev *pci_dev)
427{ 348{
428 struct acpiphp_bridge *bridge; 349 struct acpiphp_bridge *bridge;
429 u8 tmp8;
430 u16 tmp16;
431 u64 base64, limit64;
432 u32 base, limit, base32u, limit32u;
433 350
434 bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL); 351 bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
435 if (bridge == NULL) { 352 if (bridge == NULL) {
@@ -441,133 +358,22 @@ static void add_p2p_bridge(acpi_handle *handle, int seg, int bus, int dev, int f
441 358
442 bridge->type = BRIDGE_TYPE_P2P; 359 bridge->type = BRIDGE_TYPE_P2P;
443 bridge->handle = handle; 360 bridge->handle = handle;
444 bridge->seg = seg;
445
446 bridge->pci_dev = pci_find_slot(bus, PCI_DEVFN(dev, fn));
447 if (!bridge->pci_dev) {
448 err("Can't get pci_dev\n");
449 kfree(bridge);
450 return;
451 }
452 361
453 bridge->pci_bus = bridge->pci_dev->subordinate; 362 bridge->pci_dev = pci_dev_get(pci_dev);
363 bridge->pci_bus = pci_dev->subordinate;
454 if (!bridge->pci_bus) { 364 if (!bridge->pci_bus) {
455 err("This is not a PCI-to-PCI bridge!\n"); 365 err("This is not a PCI-to-PCI bridge!\n");
456 kfree(bridge); 366 goto err;
457 return;
458 } 367 }
459 368
460 spin_lock_init(&bridge->res_lock); 369 spin_lock_init(&bridge->res_lock);
461 370
462 bridge->bus = bridge->pci_bus->number;
463 bridge->sub = bridge->pci_bus->subordinate;
464
465 /*
466 * decode resources under this P2P bridge
467 */
468
469 /* I/O resources */
470 pci_read_config_byte(bridge->pci_dev, PCI_IO_BASE, &tmp8);
471 base = tmp8;
472 pci_read_config_byte(bridge->pci_dev, PCI_IO_LIMIT, &tmp8);
473 limit = tmp8;
474
475 switch (base & PCI_IO_RANGE_TYPE_MASK) {
476 case PCI_IO_RANGE_TYPE_16:
477 base = (base << 8) & 0xf000;
478 limit = ((limit << 8) & 0xf000) + 0xfff;
479 bridge->io_head = acpiphp_make_resource((u64)base, limit - base + 1);
480 if (!bridge->io_head) {
481 err("out of memory\n");
482 kfree(bridge);
483 return;
484 }
485 dbg("16bit I/O range: %04x-%04x\n",
486 (u32)bridge->io_head->base,
487 (u32)(bridge->io_head->base + bridge->io_head->length - 1));
488 break;
489 case PCI_IO_RANGE_TYPE_32:
490 pci_read_config_word(bridge->pci_dev, PCI_IO_BASE_UPPER16, &tmp16);
491 base = ((u32)tmp16 << 16) | ((base << 8) & 0xf000);
492 pci_read_config_word(bridge->pci_dev, PCI_IO_LIMIT_UPPER16, &tmp16);
493 limit = (((u32)tmp16 << 16) | ((limit << 8) & 0xf000)) + 0xfff;
494 bridge->io_head = acpiphp_make_resource((u64)base, limit - base + 1);
495 if (!bridge->io_head) {
496 err("out of memory\n");
497 kfree(bridge);
498 return;
499 }
500 dbg("32bit I/O range: %08x-%08x\n",
501 (u32)bridge->io_head->base,
502 (u32)(bridge->io_head->base + bridge->io_head->length - 1));
503 break;
504 case 0x0f:
505 dbg("I/O space unsupported\n");
506 break;
507 default:
508 warn("Unknown I/O range type\n");
509 }
510
511 /* Memory resources (mandatory for P2P bridge) */
512 pci_read_config_word(bridge->pci_dev, PCI_MEMORY_BASE, &tmp16);
513 base = (tmp16 & 0xfff0) << 16;
514 pci_read_config_word(bridge->pci_dev, PCI_MEMORY_LIMIT, &tmp16);
515 limit = ((tmp16 & 0xfff0) << 16) | 0xfffff;
516 bridge->mem_head = acpiphp_make_resource((u64)base, limit - base + 1);
517 if (!bridge->mem_head) {
518 err("out of memory\n");
519 kfree(bridge);
520 return;
521 }
522 dbg("32bit Memory range: %08x-%08x\n",
523 (u32)bridge->mem_head->base,
524 (u32)(bridge->mem_head->base + bridge->mem_head->length-1));
525
526 /* Prefetchable Memory resources (optional) */
527 pci_read_config_word(bridge->pci_dev, PCI_PREF_MEMORY_BASE, &tmp16);
528 base = tmp16;
529 pci_read_config_word(bridge->pci_dev, PCI_PREF_MEMORY_LIMIT, &tmp16);
530 limit = tmp16;
531
532 switch (base & PCI_MEMORY_RANGE_TYPE_MASK) {
533 case PCI_PREF_RANGE_TYPE_32:
534 base = (base & 0xfff0) << 16;
535 limit = ((limit & 0xfff0) << 16) | 0xfffff;
536 bridge->p_mem_head = acpiphp_make_resource((u64)base, limit - base + 1);
537 if (!bridge->p_mem_head) {
538 err("out of memory\n");
539 kfree(bridge);
540 return;
541 }
542 dbg("32bit Prefetchable memory range: %08x-%08x\n",
543 (u32)bridge->p_mem_head->base,
544 (u32)(bridge->p_mem_head->base + bridge->p_mem_head->length - 1));
545 break;
546 case PCI_PREF_RANGE_TYPE_64:
547 pci_read_config_dword(bridge->pci_dev, PCI_PREF_BASE_UPPER32, &base32u);
548 pci_read_config_dword(bridge->pci_dev, PCI_PREF_LIMIT_UPPER32, &limit32u);
549 base64 = ((u64)base32u << 32) | ((base & 0xfff0) << 16);
550 limit64 = (((u64)limit32u << 32) | ((limit & 0xfff0) << 16)) + 0xfffff;
551
552 bridge->p_mem_head = acpiphp_make_resource(base64, limit64 - base64 + 1);
553 if (!bridge->p_mem_head) {
554 err("out of memory\n");
555 kfree(bridge);
556 return;
557 }
558 dbg("64bit Prefetchable memory range: %08x%08x-%08x%08x\n",
559 (u32)(bridge->p_mem_head->base >> 32),
560 (u32)(bridge->p_mem_head->base & 0xffffffff),
561 (u32)((bridge->p_mem_head->base + bridge->p_mem_head->length - 1) >> 32),
562 (u32)((bridge->p_mem_head->base + bridge->p_mem_head->length - 1) & 0xffffffff));
563 break;
564 case 0x0f:
565 break;
566 default:
567 warn("Unknown prefetchale memory type\n");
568 }
569
570 init_bridge_misc(bridge); 371 init_bridge_misc(bridge);
372 return;
373 err:
374 pci_dev_put(pci_dev);
375 kfree(bridge);
376 return;
571} 377}
572 378
573 379
@@ -577,14 +383,10 @@ find_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
577{ 383{
578 acpi_status status; 384 acpi_status status;
579 acpi_handle dummy_handle; 385 acpi_handle dummy_handle;
580 unsigned long *segbus = context;
581 unsigned long tmp; 386 unsigned long tmp;
582 int seg, bus, device, function; 387 int device, function;
583 struct pci_dev *dev; 388 struct pci_dev *dev;
584 389 struct pci_bus *pci_bus = context;
585 /* get PCI address */
586 seg = (*segbus >> 8) & 0xff;
587 bus = *segbus & 0xff;
588 390
589 status = acpi_get_handle(handle, "_ADR", &dummy_handle); 391 status = acpi_get_handle(handle, "_ADR", &dummy_handle);
590 if (ACPI_FAILURE(status)) 392 if (ACPI_FAILURE(status))
@@ -599,20 +401,19 @@ find_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
599 device = (tmp >> 16) & 0xffff; 401 device = (tmp >> 16) & 0xffff;
600 function = tmp & 0xffff; 402 function = tmp & 0xffff;
601 403
602 dev = pci_find_slot(bus, PCI_DEVFN(device, function)); 404 dev = pci_get_slot(pci_bus, PCI_DEVFN(device, function));
603 405
604 if (!dev) 406 if (!dev || !dev->subordinate)
605 return AE_OK; 407 goto out;
606
607 if (!dev->subordinate)
608 return AE_OK;
609 408
610 /* check if this bridge has ejectable slots */ 409 /* check if this bridge has ejectable slots */
611 if (detect_ejectable_slots(handle) > 0) { 410 if (detect_ejectable_slots(handle) > 0) {
612 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev)); 411 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev));
613 add_p2p_bridge(handle, seg, bus, device, function); 412 add_p2p_bridge(handle, dev);
614 } 413 }
615 414
415 out:
416 pci_dev_put(dev);
616 return AE_OK; 417 return AE_OK;
617} 418}
618 419
@@ -624,6 +425,7 @@ static int add_bridge(acpi_handle handle)
624 unsigned long tmp; 425 unsigned long tmp;
625 int seg, bus; 426 int seg, bus;
626 acpi_handle dummy_handle; 427 acpi_handle dummy_handle;
428 struct pci_bus *pci_bus;
627 429
628 /* if the bridge doesn't have _STA, we assume it is always there */ 430 /* if the bridge doesn't have _STA, we assume it is always there */
629 status = acpi_get_handle(handle, "_STA", &dummy_handle); 431 status = acpi_get_handle(handle, "_STA", &dummy_handle);
@@ -653,18 +455,22 @@ static int add_bridge(acpi_handle handle)
653 bus = 0; 455 bus = 0;
654 } 456 }
655 457
458 pci_bus = pci_find_bus(seg, bus);
459 if (!pci_bus) {
460 err("Can't find bus %04x:%02x\n", seg, bus);
461 return 0;
462 }
463
656 /* check if this bridge has ejectable slots */ 464 /* check if this bridge has ejectable slots */
657 if (detect_ejectable_slots(handle) > 0) { 465 if (detect_ejectable_slots(handle) > 0) {
658 dbg("found PCI host-bus bridge with hot-pluggable slots\n"); 466 dbg("found PCI host-bus bridge with hot-pluggable slots\n");
659 add_host_bridge(handle, seg, bus); 467 add_host_bridge(handle, pci_bus);
660 return 0; 468 return 0;
661 } 469 }
662 470
663 tmp = seg << 8 | bus;
664
665 /* search P2P bridges under this host bridge */ 471 /* search P2P bridges under this host bridge */
666 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, 472 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
667 find_p2p_bridge, &tmp, NULL); 473 find_p2p_bridge, pci_bus, NULL);
668 474
669 if (ACPI_FAILURE(status)) 475 if (ACPI_FAILURE(status))
670 warn("find_p2p_bridge faied (error code = 0x%x)\n",status); 476 warn("find_p2p_bridge faied (error code = 0x%x)\n",status);
@@ -672,12 +478,205 @@ static int add_bridge(acpi_handle handle)
672 return 0; 478 return 0;
673} 479}
674 480
481static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle)
482{
483 struct list_head *head;
484 list_for_each(head, &bridge_list) {
485 struct acpiphp_bridge *bridge = list_entry(head,
486 struct acpiphp_bridge, list);
487 if (bridge->handle == handle)
488 return bridge;
489 }
490
491 return NULL;
492}
493
494static void cleanup_bridge(struct acpiphp_bridge *bridge)
495{
496 struct list_head *list, *tmp;
497 struct acpiphp_slot *slot;
498 acpi_status status;
499 acpi_handle handle = bridge->handle;
500
501 status = acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
502 handle_hotplug_event_bridge);
503 if (ACPI_FAILURE(status))
504 err("failed to remove notify handler\n");
505
506 slot = bridge->slots;
507 while (slot) {
508 struct acpiphp_slot *next = slot->next;
509 list_for_each_safe (list, tmp, &slot->funcs) {
510 struct acpiphp_func *func;
511 func = list_entry(list, struct acpiphp_func, sibling);
512 status = acpi_remove_notify_handler(func->handle,
513 ACPI_SYSTEM_NOTIFY,
514 handle_hotplug_event_func);
515 if (ACPI_FAILURE(status))
516 err("failed to remove notify handler\n");
517 pci_dev_put(func->pci_dev);
518 list_del(list);
519 kfree(func);
520 }
521 kfree(slot);
522 slot = next;
523 }
524
525 pci_dev_put(bridge->pci_dev);
526 list_del(&bridge->list);
527 kfree(bridge);
528}
529
530static acpi_status
531cleanup_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
532{
533 struct acpiphp_bridge *bridge;
534
535 if (!(bridge = acpiphp_handle_to_bridge(handle)))
536 return AE_OK;
537 cleanup_bridge(bridge);
538 return AE_OK;
539}
675 540
676static void remove_bridge(acpi_handle handle) 541static void remove_bridge(acpi_handle handle)
677{ 542{
678 /* No-op for now .. */ 543 struct acpiphp_bridge *bridge;
544
545 bridge = acpiphp_handle_to_bridge(handle);
546 if (bridge) {
547 cleanup_bridge(bridge);
548 } else {
549 /* clean-up p2p bridges under this host bridge */
550 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
551 (u32)1, cleanup_p2p_bridge, NULL, NULL);
552 }
553}
554
555static struct pci_dev * get_apic_pci_info(acpi_handle handle)
556{
557 struct acpi_pci_id id;
558 struct pci_bus *bus;
559 struct pci_dev *dev;
560
561 if (ACPI_FAILURE(acpi_get_pci_id(handle, &id)))
562 return NULL;
563
564 bus = pci_find_bus(id.segment, id.bus);
565 if (!bus)
566 return NULL;
567
568 dev = pci_get_slot(bus, PCI_DEVFN(id.device, id.function));
569 if (!dev)
570 return NULL;
571
572 if ((dev->class != PCI_CLASS_SYSTEM_PIC_IOAPIC) &&
573 (dev->class != PCI_CLASS_SYSTEM_PIC_IOXAPIC))
574 {
575 pci_dev_put(dev);
576 return NULL;
577 }
578
579 return dev;
580}
581
582static int get_gsi_base(acpi_handle handle, u32 *gsi_base)
583{
584 acpi_status status;
585 int result = -1;
586 unsigned long gsb;
587 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
588 union acpi_object *obj;
589 void *table;
590
591 status = acpi_evaluate_integer(handle, "_GSB", NULL, &gsb);
592 if (ACPI_SUCCESS(status)) {
593 *gsi_base = (u32)gsb;
594 return 0;
595 }
596
597 status = acpi_evaluate_object(handle, "_MAT", NULL, &buffer);
598 if (ACPI_FAILURE(status) || !buffer.length || !buffer.pointer)
599 return -1;
600
601 obj = buffer.pointer;
602 if (obj->type != ACPI_TYPE_BUFFER)
603 goto out;
604
605 table = obj->buffer.pointer;
606 switch (((acpi_table_entry_header *)table)->type) {
607 case ACPI_MADT_IOSAPIC:
608 *gsi_base = ((struct acpi_table_iosapic *)table)->global_irq_base;
609 result = 0;
610 break;
611 case ACPI_MADT_IOAPIC:
612 *gsi_base = ((struct acpi_table_ioapic *)table)->global_irq_base;
613 result = 0;
614 break;
615 default:
616 break;
617 }
618 out:
619 acpi_os_free(buffer.pointer);
620 return result;
621}
622
623static acpi_status
624ioapic_add(acpi_handle handle, u32 lvl, void *context, void **rv)
625{
626 acpi_status status;
627 unsigned long sta;
628 acpi_handle tmp;
629 struct pci_dev *pdev;
630 u32 gsi_base;
631 u64 phys_addr;
632
633 /* Evaluate _STA if present */
634 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
635 if (ACPI_SUCCESS(status) && sta != ACPI_STA_ALL)
636 return AE_CTRL_DEPTH;
637
638 /* Scan only PCI bus scope */
639 status = acpi_get_handle(handle, "_HID", &tmp);
640 if (ACPI_SUCCESS(status))
641 return AE_CTRL_DEPTH;
642
643 if (get_gsi_base(handle, &gsi_base))
644 return AE_OK;
645
646 pdev = get_apic_pci_info(handle);
647 if (!pdev)
648 return AE_OK;
649
650 if (pci_enable_device(pdev)) {
651 pci_dev_put(pdev);
652 return AE_OK;
653 }
654
655 pci_set_master(pdev);
656
657 if (pci_request_region(pdev, 0, "I/O APIC(acpiphp)")) {
658 pci_disable_device(pdev);
659 pci_dev_put(pdev);
660 return AE_OK;
661 }
662
663 phys_addr = pci_resource_start(pdev, 0);
664 if (acpi_register_ioapic(handle, phys_addr, gsi_base)) {
665 pci_release_region(pdev, 0);
666 pci_disable_device(pdev);
667 pci_dev_put(pdev);
668 return AE_OK;
669 }
670
671 return AE_OK;
679} 672}
680 673
674static int acpiphp_configure_ioapics(acpi_handle handle)
675{
676 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
677 ACPI_UINT32_MAX, ioapic_add, NULL, NULL);
678 return 0;
679}
681 680
682static int power_on_slot(struct acpiphp_slot *slot) 681static int power_on_slot(struct acpiphp_slot *slot)
683{ 682{
@@ -719,8 +718,6 @@ static int power_off_slot(struct acpiphp_slot *slot)
719 acpi_status status; 718 acpi_status status;
720 struct acpiphp_func *func; 719 struct acpiphp_func *func;
721 struct list_head *l; 720 struct list_head *l;
722 struct acpi_object_list arg_list;
723 union acpi_object arg;
724 721
725 int retval = 0; 722 int retval = 0;
726 723
@@ -731,7 +728,7 @@ static int power_off_slot(struct acpiphp_slot *slot)
731 list_for_each (l, &slot->funcs) { 728 list_for_each (l, &slot->funcs) {
732 func = list_entry(l, struct acpiphp_func, sibling); 729 func = list_entry(l, struct acpiphp_func, sibling);
733 730
734 if (func->pci_dev && (func->flags & FUNC_HAS_PS3)) { 731 if (func->flags & FUNC_HAS_PS3) {
735 status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL); 732 status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL);
736 if (ACPI_FAILURE(status)) { 733 if (ACPI_FAILURE(status)) {
737 warn("%s: _PS3 failed\n", __FUNCTION__); 734 warn("%s: _PS3 failed\n", __FUNCTION__);
@@ -742,27 +739,6 @@ static int power_off_slot(struct acpiphp_slot *slot)
742 } 739 }
743 } 740 }
744 741
745 list_for_each (l, &slot->funcs) {
746 func = list_entry(l, struct acpiphp_func, sibling);
747
748 /* We don't want to call _EJ0 on non-existing functions. */
749 if (func->pci_dev && (func->flags & FUNC_HAS_EJ0)) {
750 /* _EJ0 method take one argument */
751 arg_list.count = 1;
752 arg_list.pointer = &arg;
753 arg.type = ACPI_TYPE_INTEGER;
754 arg.integer.value = 1;
755
756 status = acpi_evaluate_object(func->handle, "_EJ0", &arg_list, NULL);
757 if (ACPI_FAILURE(status)) {
758 warn("%s: _EJ0 failed\n", __FUNCTION__);
759 retval = -1;
760 goto err_exit;
761 } else
762 break;
763 }
764 }
765
766 /* TBD: evaluate _STA to check if the slot is disabled */ 742 /* TBD: evaluate _STA to check if the slot is disabled */
767 743
768 slot->flags &= (~SLOT_POWEREDON); 744 slot->flags &= (~SLOT_POWEREDON);
@@ -782,70 +758,56 @@ static int power_off_slot(struct acpiphp_slot *slot)
782 */ 758 */
783static int enable_device(struct acpiphp_slot *slot) 759static int enable_device(struct acpiphp_slot *slot)
784{ 760{
785 u8 bus;
786 struct pci_dev *dev; 761 struct pci_dev *dev;
787 struct pci_bus *child; 762 struct pci_bus *bus = slot->bridge->pci_bus;
788 struct list_head *l; 763 struct list_head *l;
789 struct acpiphp_func *func; 764 struct acpiphp_func *func;
790 int retval = 0; 765 int retval = 0;
791 int num; 766 int num, max, pass;
792 767
793 if (slot->flags & SLOT_ENABLED) 768 if (slot->flags & SLOT_ENABLED)
794 goto err_exit; 769 goto err_exit;
795 770
796 /* sanity check: dev should be NULL when hot-plugged in */ 771 /* sanity check: dev should be NULL when hot-plugged in */
797 dev = pci_find_slot(slot->bridge->bus, PCI_DEVFN(slot->device, 0)); 772 dev = pci_get_slot(bus, PCI_DEVFN(slot->device, 0));
798 if (dev) { 773 if (dev) {
799 /* This case shouldn't happen */ 774 /* This case shouldn't happen */
800 err("pci_dev structure already exists.\n"); 775 err("pci_dev structure already exists.\n");
776 pci_dev_put(dev);
801 retval = -1; 777 retval = -1;
802 goto err_exit; 778 goto err_exit;
803 } 779 }
804 780
805 /* allocate resources to device */ 781 num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0));
806 retval = acpiphp_configure_slot(slot); 782 if (num == 0) {
807 if (retval)
808 goto err_exit;
809
810 /* returned `dev' is the *first function* only! */
811 num = pci_scan_slot(slot->bridge->pci_bus, PCI_DEVFN(slot->device, 0));
812 if (num)
813 pci_bus_add_devices(slot->bridge->pci_bus);
814 dev = pci_find_slot(slot->bridge->bus, PCI_DEVFN(slot->device, 0));
815
816 if (!dev) {
817 err("No new device found\n"); 783 err("No new device found\n");
818 retval = -1; 784 retval = -1;
819 goto err_exit; 785 goto err_exit;
820 } 786 }
821 787
822 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { 788 max = bus->secondary;
823 pci_read_config_byte(dev, PCI_SECONDARY_BUS, &bus); 789 for (pass = 0; pass < 2; pass++) {
824 child = (struct pci_bus*) pci_add_new_bus(dev->bus, dev, bus); 790 list_for_each_entry(dev, &bus->devices, bus_list) {
825 pci_do_scan_bus(child); 791 if (PCI_SLOT(dev->devfn) != slot->device)
792 continue;
793 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
794 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
795 max = pci_scan_bridge(bus, dev, max, pass);
796 }
826 } 797 }
827 798
799 pci_bus_assign_resources(bus);
800 pci_bus_add_devices(bus);
801
828 /* associate pci_dev to our representation */ 802 /* associate pci_dev to our representation */
829 list_for_each (l, &slot->funcs) { 803 list_for_each (l, &slot->funcs) {
830 func = list_entry(l, struct acpiphp_func, sibling); 804 func = list_entry(l, struct acpiphp_func, sibling);
831 805 func->pci_dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
832 func->pci_dev = pci_find_slot(slot->bridge->bus,
833 PCI_DEVFN(slot->device,
834 func->function)); 806 func->function));
835 if (!func->pci_dev)
836 continue;
837
838 /* configure device */
839 retval = acpiphp_configure_function(func);
840 if (retval)
841 goto err_exit;
842 } 807 }
843 808
844 slot->flags |= SLOT_ENABLED; 809 slot->flags |= SLOT_ENABLED;
845 810
846 dbg("Available resources:\n");
847 acpiphp_dump_resource(slot->bridge);
848
849 err_exit: 811 err_exit:
850 return retval; 812 return retval;
851} 813}
@@ -866,9 +828,12 @@ static int disable_device(struct acpiphp_slot *slot)
866 828
867 list_for_each (l, &slot->funcs) { 829 list_for_each (l, &slot->funcs) {
868 func = list_entry(l, struct acpiphp_func, sibling); 830 func = list_entry(l, struct acpiphp_func, sibling);
831 if (!func->pci_dev)
832 continue;
869 833
870 if (func->pci_dev) 834 pci_remove_bus_device(func->pci_dev);
871 acpiphp_unconfigure_function(func); 835 pci_dev_put(func->pci_dev);
836 func->pci_dev = NULL;
872 } 837 }
873 838
874 slot->flags &= (~SLOT_ENABLED); 839 slot->flags &= (~SLOT_ENABLED);
@@ -920,6 +885,39 @@ static unsigned int get_slot_status(struct acpiphp_slot *slot)
920} 885}
921 886
922/** 887/**
888 * acpiphp_eject_slot - physically eject the slot
889 */
890static int acpiphp_eject_slot(struct acpiphp_slot *slot)
891{
892 acpi_status status;
893 struct acpiphp_func *func;
894 struct list_head *l;
895 struct acpi_object_list arg_list;
896 union acpi_object arg;
897
898 list_for_each (l, &slot->funcs) {
899 func = list_entry(l, struct acpiphp_func, sibling);
900
901 /* We don't want to call _EJ0 on non-existing functions. */
902 if ((func->flags & FUNC_HAS_EJ0)) {
903 /* _EJ0 method take one argument */
904 arg_list.count = 1;
905 arg_list.pointer = &arg;
906 arg.type = ACPI_TYPE_INTEGER;
907 arg.integer.value = 1;
908
909 status = acpi_evaluate_object(func->handle, "_EJ0", &arg_list, NULL);
910 if (ACPI_FAILURE(status)) {
911 warn("%s: _EJ0 failed\n", __FUNCTION__);
912 return -1;
913 } else
914 break;
915 }
916 }
917 return 0;
918}
919
920/**
923 * acpiphp_check_bridge - re-enumerate devices 921 * acpiphp_check_bridge - re-enumerate devices
924 * 922 *
925 * Iterate over all slots under this bridge and make sure that if a 923 * Iterate over all slots under this bridge and make sure that if a
@@ -942,6 +940,8 @@ static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
942 if (retval) { 940 if (retval) {
943 err("Error occurred in disabling\n"); 941 err("Error occurred in disabling\n");
944 goto err_exit; 942 goto err_exit;
943 } else {
944 acpiphp_eject_slot(slot);
945 } 945 }
946 disabled++; 946 disabled++;
947 } else { 947 } else {
@@ -962,6 +962,144 @@ static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
962 return retval; 962 return retval;
963} 963}
964 964
965static void program_hpp(struct pci_dev *dev, struct acpiphp_bridge *bridge)
966{
967 u16 pci_cmd, pci_bctl;
968 struct pci_dev *cdev;
969
970 /* Program hpp values for this device */
971 if (!(dev->hdr_type == PCI_HEADER_TYPE_NORMAL ||
972 (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE &&
973 (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)))
974 return;
975 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
976 bridge->hpp.cache_line_size);
977 pci_write_config_byte(dev, PCI_LATENCY_TIMER,
978 bridge->hpp.latency_timer);
979 pci_read_config_word(dev, PCI_COMMAND, &pci_cmd);
980 if (bridge->hpp.enable_SERR)
981 pci_cmd |= PCI_COMMAND_SERR;
982 else
983 pci_cmd &= ~PCI_COMMAND_SERR;
984 if (bridge->hpp.enable_PERR)
985 pci_cmd |= PCI_COMMAND_PARITY;
986 else
987 pci_cmd &= ~PCI_COMMAND_PARITY;
988 pci_write_config_word(dev, PCI_COMMAND, pci_cmd);
989
990 /* Program bridge control value and child devices */
991 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
992 pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER,
993 bridge->hpp.latency_timer);
994 pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &pci_bctl);
995 if (bridge->hpp.enable_SERR)
996 pci_bctl |= PCI_BRIDGE_CTL_SERR;
997 else
998 pci_bctl &= ~PCI_BRIDGE_CTL_SERR;
999 if (bridge->hpp.enable_PERR)
1000 pci_bctl |= PCI_BRIDGE_CTL_PARITY;
1001 else
1002 pci_bctl &= ~PCI_BRIDGE_CTL_PARITY;
1003 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, pci_bctl);
1004 if (dev->subordinate) {
1005 list_for_each_entry(cdev, &dev->subordinate->devices,
1006 bus_list)
1007 program_hpp(cdev, bridge);
1008 }
1009 }
1010}
1011
1012static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus)
1013{
1014 struct acpiphp_bridge bridge;
1015 struct pci_dev *dev;
1016
1017 memset(&bridge, 0, sizeof(bridge));
1018 bridge.handle = handle;
1019 decode_hpp(&bridge);
1020 list_for_each_entry(dev, &bus->devices, bus_list)
1021 program_hpp(dev, &bridge);
1022
1023}
1024
1025/*
1026 * Remove devices for which we could not assign resources, call
1027 * arch specific code to fix-up the bus
1028 */
1029static void acpiphp_sanitize_bus(struct pci_bus *bus)
1030{
1031 struct pci_dev *dev;
1032 int i;
1033 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
1034
1035 list_for_each_entry(dev, &bus->devices, bus_list) {
1036 for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {
1037 struct resource *res = &dev->resource[i];
1038 if ((res->flags & type_mask) && !res->start &&
1039 res->end) {
1040 /* Could not assign a required resources
1041 * for this device, remove it */
1042 pci_remove_bus_device(dev);
1043 break;
1044 }
1045 }
1046 }
1047}
1048
1049/* Program resources in newly inserted bridge */
1050static int acpiphp_configure_bridge (acpi_handle handle)
1051{
1052 struct acpi_pci_id pci_id;
1053 struct pci_bus *bus;
1054
1055 if (ACPI_FAILURE(acpi_get_pci_id(handle, &pci_id))) {
1056 err("cannot get PCI domain and bus number for bridge\n");
1057 return -EINVAL;
1058 }
1059 bus = pci_find_bus(pci_id.segment, pci_id.bus);
1060 if (!bus) {
1061 err("cannot find bus %d:%d\n",
1062 pci_id.segment, pci_id.bus);
1063 return -EINVAL;
1064 }
1065
1066 pci_bus_size_bridges(bus);
1067 pci_bus_assign_resources(bus);
1068 acpiphp_sanitize_bus(bus);
1069 acpiphp_set_hpp_values(handle, bus);
1070 pci_enable_bridges(bus);
1071 acpiphp_configure_ioapics(handle);
1072 return 0;
1073}
1074
1075static void handle_bridge_insertion(acpi_handle handle, u32 type)
1076{
1077 struct acpi_device *device, *pdevice;
1078 acpi_handle phandle;
1079
1080 if ((type != ACPI_NOTIFY_BUS_CHECK) &&
1081 (type != ACPI_NOTIFY_DEVICE_CHECK)) {
1082 err("unexpected notification type %d\n", type);
1083 return;
1084 }
1085
1086 acpi_get_parent(handle, &phandle);
1087 if (acpi_bus_get_device(phandle, &pdevice)) {
1088 dbg("no parent device, assuming NULL\n");
1089 pdevice = NULL;
1090 }
1091 if (acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE)) {
1092 err("cannot add bridge to acpi list\n");
1093 return;
1094 }
1095 if (!acpiphp_configure_bridge(handle) &&
1096 !acpi_bus_start(device))
1097 add_bridge(handle);
1098 else
1099 err("cannot configure and start bridge\n");
1100
1101}
1102
965/* 1103/*
966 * ACPI event handlers 1104 * ACPI event handlers
967 */ 1105 */
@@ -982,8 +1120,19 @@ static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *cont
982 char objname[64]; 1120 char objname[64];
983 struct acpi_buffer buffer = { .length = sizeof(objname), 1121 struct acpi_buffer buffer = { .length = sizeof(objname),
984 .pointer = objname }; 1122 .pointer = objname };
1123 struct acpi_device *device;
985 1124
986 bridge = (struct acpiphp_bridge *)context; 1125 if (acpi_bus_get_device(handle, &device)) {
1126 /* This bridge must have just been physically inserted */
1127 handle_bridge_insertion(handle, type);
1128 return;
1129 }
1130
1131 bridge = acpiphp_handle_to_bridge(handle);
1132 if (!bridge) {
1133 err("cannot get bridge info\n");
1134 return;
1135 }
987 1136
988 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); 1137 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
989 1138
@@ -1031,7 +1180,6 @@ static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *cont
1031 } 1180 }
1032} 1181}
1033 1182
1034
1035/** 1183/**
1036 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots) 1184 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
1037 * 1185 *
@@ -1074,7 +1222,8 @@ static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *contex
1074 case ACPI_NOTIFY_EJECT_REQUEST: 1222 case ACPI_NOTIFY_EJECT_REQUEST:
1075 /* request device eject */ 1223 /* request device eject */
1076 dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname); 1224 dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname);
1077 acpiphp_disable_slot(func->slot); 1225 if (!(acpiphp_disable_slot(func->slot)))
1226 acpiphp_eject_slot(func->slot);
1078 break; 1227 break;
1079 1228
1080 default: 1229 default:
@@ -1083,6 +1232,47 @@ static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *contex
1083 } 1232 }
1084} 1233}
1085 1234
1235static int is_root_bridge(acpi_handle handle)
1236{
1237 acpi_status status;
1238 struct acpi_device_info *info;
1239 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
1240 int i;
1241
1242 status = acpi_get_object_info(handle, &buffer);
1243 if (ACPI_SUCCESS(status)) {
1244 info = buffer.pointer;
1245 if ((info->valid & ACPI_VALID_HID) &&
1246 !strcmp(PCI_ROOT_HID_STRING,
1247 info->hardware_id.value)) {
1248 acpi_os_free(buffer.pointer);
1249 return 1;
1250 }
1251 if (info->valid & ACPI_VALID_CID) {
1252 for (i=0; i < info->compatibility_id.count; i++) {
1253 if (!strcmp(PCI_ROOT_HID_STRING,
1254 info->compatibility_id.id[i].value)) {
1255 acpi_os_free(buffer.pointer);
1256 return 1;
1257 }
1258 }
1259 }
1260 }
1261 return 0;
1262}
1263
1264static acpi_status
1265find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
1266{
1267 int *count = (int *)context;
1268
1269 if (is_root_bridge(handle)) {
1270 acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
1271 handle_hotplug_event_bridge, NULL);
1272 (*count)++;
1273 }
1274 return AE_OK ;
1275}
1086 1276
1087static struct acpi_pci_driver acpi_pci_hp_driver = { 1277static struct acpi_pci_driver acpi_pci_hp_driver = {
1088 .add = add_bridge, 1278 .add = add_bridge,
@@ -1095,15 +1285,15 @@ static struct acpi_pci_driver acpi_pci_hp_driver = {
1095 */ 1285 */
1096int __init acpiphp_glue_init(void) 1286int __init acpiphp_glue_init(void)
1097{ 1287{
1098 int num; 1288 int num = 0;
1099
1100 if (list_empty(&pci_root_buses))
1101 return -1;
1102 1289
1103 num = acpi_pci_register_driver(&acpi_pci_hp_driver); 1290 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1291 ACPI_UINT32_MAX, find_root_bridges, &num, NULL);
1104 1292
1105 if (num <= 0) 1293 if (num <= 0)
1106 return -1; 1294 return -1;
1295 else
1296 acpi_pci_register_driver(&acpi_pci_hp_driver);
1107 1297
1108 return 0; 1298 return 0;
1109} 1299}
@@ -1116,46 +1306,6 @@ int __init acpiphp_glue_init(void)
1116 */ 1306 */
1117void __exit acpiphp_glue_exit(void) 1307void __exit acpiphp_glue_exit(void)
1118{ 1308{
1119 struct list_head *l1, *l2, *n1, *n2;
1120 struct acpiphp_bridge *bridge;
1121 struct acpiphp_slot *slot, *next;
1122 struct acpiphp_func *func;
1123 acpi_status status;
1124
1125 list_for_each_safe (l1, n1, &bridge_list) {
1126 bridge = (struct acpiphp_bridge *)l1;
1127 slot = bridge->slots;
1128 while (slot) {
1129 next = slot->next;
1130 list_for_each_safe (l2, n2, &slot->funcs) {
1131 func = list_entry(l2, struct acpiphp_func, sibling);
1132 acpiphp_free_resource(&func->io_head);
1133 acpiphp_free_resource(&func->mem_head);
1134 acpiphp_free_resource(&func->p_mem_head);
1135 acpiphp_free_resource(&func->bus_head);
1136 status = acpi_remove_notify_handler(func->handle,
1137 ACPI_SYSTEM_NOTIFY,
1138 handle_hotplug_event_func);
1139 if (ACPI_FAILURE(status))
1140 err("failed to remove notify handler\n");
1141 kfree(func);
1142 }
1143 kfree(slot);
1144 slot = next;
1145 }
1146 status = acpi_remove_notify_handler(bridge->handle, ACPI_SYSTEM_NOTIFY,
1147 handle_hotplug_event_bridge);
1148 if (ACPI_FAILURE(status))
1149 err("failed to remove notify handler\n");
1150
1151 acpiphp_free_resource(&bridge->io_head);
1152 acpiphp_free_resource(&bridge->mem_head);
1153 acpiphp_free_resource(&bridge->p_mem_head);
1154 acpiphp_free_resource(&bridge->bus_head);
1155
1156 kfree(bridge);
1157 }
1158
1159 acpi_pci_unregister_driver(&acpi_pci_hp_driver); 1309 acpi_pci_unregister_driver(&acpi_pci_hp_driver);
1160} 1310}
1161 1311
@@ -1173,11 +1323,14 @@ int __init acpiphp_get_num_slots(void)
1173 1323
1174 list_for_each (node, &bridge_list) { 1324 list_for_each (node, &bridge_list) {
1175 bridge = (struct acpiphp_bridge *)node; 1325 bridge = (struct acpiphp_bridge *)node;
1176 dbg("Bus%d %dslot(s)\n", bridge->bus, bridge->nr_slots); 1326 dbg("Bus %04x:%02x has %d slot%s\n",
1327 pci_domain_nr(bridge->pci_bus),
1328 bridge->pci_bus->number, bridge->nr_slots,
1329 bridge->nr_slots == 1 ? "" : "s");
1177 num_slots += bridge->nr_slots; 1330 num_slots += bridge->nr_slots;
1178 } 1331 }
1179 1332
1180 dbg("Total %dslots\n", num_slots); 1333 dbg("Total %d slots\n", num_slots);
1181 return num_slots; 1334 return num_slots;
1182} 1335}
1183 1336
@@ -1254,7 +1407,6 @@ int acpiphp_enable_slot(struct acpiphp_slot *slot)
1254 return retval; 1407 return retval;
1255} 1408}
1256 1409
1257
1258/** 1410/**
1259 * acpiphp_disable_slot - power off slot 1411 * acpiphp_disable_slot - power off slot
1260 */ 1412 */
@@ -1274,13 +1426,6 @@ int acpiphp_disable_slot(struct acpiphp_slot *slot)
1274 if (retval) 1426 if (retval)
1275 goto err_exit; 1427 goto err_exit;
1276 1428
1277 acpiphp_resource_sort_and_combine(&slot->bridge->io_head);
1278 acpiphp_resource_sort_and_combine(&slot->bridge->mem_head);
1279 acpiphp_resource_sort_and_combine(&slot->bridge->p_mem_head);
1280 acpiphp_resource_sort_and_combine(&slot->bridge->bus_head);
1281 dbg("Available resources:\n");
1282 acpiphp_dump_resource(slot->bridge);
1283
1284 err_exit: 1429 err_exit:
1285 up(&slot->crit_sect); 1430 up(&slot->crit_sect);
1286 return retval; 1431 return retval;
@@ -1293,11 +1438,7 @@ int acpiphp_disable_slot(struct acpiphp_slot *slot)
1293 */ 1438 */
1294u8 acpiphp_get_power_status(struct acpiphp_slot *slot) 1439u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
1295{ 1440{
1296 unsigned int sta; 1441 return (slot->flags & SLOT_POWEREDON);
1297
1298 sta = get_slot_status(slot);
1299
1300 return (sta & ACPI_STA_ENABLED) ? 1 : 0;
1301} 1442}
1302 1443
1303 1444
@@ -1335,9 +1476,10 @@ u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
1335u32 acpiphp_get_address(struct acpiphp_slot *slot) 1476u32 acpiphp_get_address(struct acpiphp_slot *slot)
1336{ 1477{
1337 u32 address; 1478 u32 address;
1479 struct pci_bus *pci_bus = slot->bridge->pci_bus;
1338 1480
1339 address = ((slot->bridge->seg) << 16) | 1481 address = (pci_domain_nr(pci_bus) << 16) |
1340 ((slot->bridge->bus) << 8) | 1482 (pci_bus->number << 8) |
1341 slot->device; 1483 slot->device;
1342 1484
1343 return address; 1485 return address;
diff --git a/drivers/pci/hotplug/acpiphp_pci.c b/drivers/pci/hotplug/acpiphp_pci.c
deleted file mode 100644
index 54d97c9d1dff..000000000000
--- a/drivers/pci/hotplug/acpiphp_pci.c
+++ /dev/null
@@ -1,449 +0,0 @@
1/*
2 * ACPI PCI HotPlug PCI configuration space management
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001,2002 IBM Corp.
7 * Copyright (C) 2002 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
8 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
9 * Copyright (C) 2002 NEC Corporation
10 *
11 * All rights reserved.
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 (at
16 * your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
21 * NON INFRINGEMENT. See the GNU General Public License for more
22 * 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 * Send feedback to <t-kochi@bq.jp.nec.com>
29 *
30 */
31
32#include <linux/init.h>
33#include <linux/module.h>
34
35#include <linux/kernel.h>
36#include <linux/pci.h>
37#include <linux/acpi.h>
38#include "../pci.h"
39#include "pci_hotplug.h"
40#include "acpiphp.h"
41
42#define MY_NAME "acpiphp_pci"
43
44
45/* allocate mem/pmem/io resource to a new function */
46static int init_config_space (struct acpiphp_func *func)
47{
48 u32 bar, len;
49 u32 address[] = {
50 PCI_BASE_ADDRESS_0,
51 PCI_BASE_ADDRESS_1,
52 PCI_BASE_ADDRESS_2,
53 PCI_BASE_ADDRESS_3,
54 PCI_BASE_ADDRESS_4,
55 PCI_BASE_ADDRESS_5,
56 0
57 };
58 int count;
59 struct acpiphp_bridge *bridge;
60 struct pci_resource *res;
61 struct pci_bus *pbus;
62 int bus, device, function;
63 unsigned int devfn;
64 u16 tmp;
65
66 bridge = func->slot->bridge;
67 pbus = bridge->pci_bus;
68 bus = bridge->bus;
69 device = func->slot->device;
70 function = func->function;
71 devfn = PCI_DEVFN(device, function);
72
73 for (count = 0; address[count]; count++) { /* for 6 BARs */
74 pci_bus_write_config_dword(pbus, devfn,
75 address[count], 0xFFFFFFFF);
76 pci_bus_read_config_dword(pbus, devfn, address[count], &bar);
77
78 if (!bar) /* This BAR is not implemented */
79 continue;
80
81 dbg("Device %02x.%02x BAR %d wants %x\n", device, function, count, bar);
82
83 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
84 /* This is IO */
85
86 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
87 len = len & ~(len - 1);
88
89 dbg("len in IO %x, BAR %d\n", len, count);
90
91 spin_lock(&bridge->res_lock);
92 res = acpiphp_get_io_resource(&bridge->io_head, len);
93 spin_unlock(&bridge->res_lock);
94
95 if (!res) {
96 err("cannot allocate requested io for %02x:%02x.%d len %x\n",
97 bus, device, function, len);
98 return -1;
99 }
100 pci_bus_write_config_dword(pbus, devfn,
101 address[count],
102 (u32)res->base);
103 res->next = func->io_head;
104 func->io_head = res;
105
106 } else {
107 /* This is Memory */
108 if (bar & PCI_BASE_ADDRESS_MEM_PREFETCH) {
109 /* pfmem */
110
111 len = bar & 0xFFFFFFF0;
112 len = ~len + 1;
113
114 dbg("len in PFMEM %x, BAR %d\n", len, count);
115
116 spin_lock(&bridge->res_lock);
117 res = acpiphp_get_resource(&bridge->p_mem_head, len);
118 spin_unlock(&bridge->res_lock);
119
120 if (!res) {
121 err("cannot allocate requested pfmem for %02x:%02x.%d len %x\n",
122 bus, device, function, len);
123 return -1;
124 }
125
126 pci_bus_write_config_dword(pbus, devfn,
127 address[count],
128 (u32)res->base);
129
130 if (bar & PCI_BASE_ADDRESS_MEM_TYPE_64) { /* takes up another dword */
131 dbg("inside the pfmem 64 case, count %d\n", count);
132 count += 1;
133 pci_bus_write_config_dword(pbus, devfn,
134 address[count],
135 (u32)(res->base >> 32));
136 }
137
138 res->next = func->p_mem_head;
139 func->p_mem_head = res;
140
141 } else {
142 /* regular memory */
143
144 len = bar & 0xFFFFFFF0;
145 len = ~len + 1;
146
147 dbg("len in MEM %x, BAR %d\n", len, count);
148
149 spin_lock(&bridge->res_lock);
150 res = acpiphp_get_resource(&bridge->mem_head, len);
151 spin_unlock(&bridge->res_lock);
152
153 if (!res) {
154 err("cannot allocate requested pfmem for %02x:%02x.%d len %x\n",
155 bus, device, function, len);
156 return -1;
157 }
158
159 pci_bus_write_config_dword(pbus, devfn,
160 address[count],
161 (u32)res->base);
162
163 if (bar & PCI_BASE_ADDRESS_MEM_TYPE_64) {
164 /* takes up another dword */
165 dbg("inside mem 64 case, reg. mem, count %d\n", count);
166 count += 1;
167 pci_bus_write_config_dword(pbus, devfn,
168 address[count],
169 (u32)(res->base >> 32));
170 }
171
172 res->next = func->mem_head;
173 func->mem_head = res;
174
175 }
176 }
177 }
178
179 /* disable expansion rom */
180 pci_bus_write_config_dword(pbus, devfn, PCI_ROM_ADDRESS, 0x00000000);
181
182 /* set PCI parameters from _HPP */
183 pci_bus_write_config_byte(pbus, devfn, PCI_CACHE_LINE_SIZE,
184 bridge->hpp.cache_line_size);
185 pci_bus_write_config_byte(pbus, devfn, PCI_LATENCY_TIMER,
186 bridge->hpp.latency_timer);
187
188 pci_bus_read_config_word(pbus, devfn, PCI_COMMAND, &tmp);
189 if (bridge->hpp.enable_SERR)
190 tmp |= PCI_COMMAND_SERR;
191 if (bridge->hpp.enable_PERR)
192 tmp |= PCI_COMMAND_PARITY;
193 pci_bus_write_config_word(pbus, devfn, PCI_COMMAND, tmp);
194
195 return 0;
196}
197
198/* detect_used_resource - subtract resource under dev from bridge */
199static int detect_used_resource (struct acpiphp_bridge *bridge, struct pci_dev *dev)
200{
201 int count;
202
203 dbg("Device %s\n", pci_name(dev));
204
205 for (count = 0; count < DEVICE_COUNT_RESOURCE; count++) {
206 struct pci_resource *res;
207 struct pci_resource **head;
208 unsigned long base = dev->resource[count].start;
209 unsigned long len = dev->resource[count].end - base + 1;
210 unsigned long flags = dev->resource[count].flags;
211
212 if (!flags)
213 continue;
214
215 dbg("BAR[%d] 0x%lx - 0x%lx (0x%lx)\n", count, base,
216 base + len - 1, flags);
217
218 if (flags & IORESOURCE_IO) {
219 head = &bridge->io_head;
220 } else if (flags & IORESOURCE_PREFETCH) {
221 head = &bridge->p_mem_head;
222 } else {
223 head = &bridge->mem_head;
224 }
225
226 spin_lock(&bridge->res_lock);
227 res = acpiphp_get_resource_with_base(head, base, len);
228 spin_unlock(&bridge->res_lock);
229 if (res)
230 kfree(res);
231 }
232
233 return 0;
234}
235
236
237/**
238 * acpiphp_detect_pci_resource - detect resources under bridge
239 * @bridge: detect all resources already used under this bridge
240 *
241 * collect all resources already allocated for all devices under a bridge.
242 */
243int acpiphp_detect_pci_resource (struct acpiphp_bridge *bridge)
244{
245 struct list_head *l;
246 struct pci_dev *dev;
247
248 list_for_each (l, &bridge->pci_bus->devices) {
249 dev = pci_dev_b(l);
250 detect_used_resource(bridge, dev);
251 }
252
253 return 0;
254}
255
256
257/**
258 * acpiphp_init_slot_resource - gather resource usage information of a slot
259 * @slot: ACPI slot object to be checked, should have valid pci_dev member
260 *
261 * TBD: PCI-to-PCI bridge case
262 * use pci_dev->resource[]
263 */
264int acpiphp_init_func_resource (struct acpiphp_func *func)
265{
266 u64 base;
267 u32 bar, len;
268 u32 address[] = {
269 PCI_BASE_ADDRESS_0,
270 PCI_BASE_ADDRESS_1,
271 PCI_BASE_ADDRESS_2,
272 PCI_BASE_ADDRESS_3,
273 PCI_BASE_ADDRESS_4,
274 PCI_BASE_ADDRESS_5,
275 0
276 };
277 int count;
278 struct pci_resource *res;
279 struct pci_dev *dev;
280
281 dev = func->pci_dev;
282 dbg("Hot-pluggable device %s\n", pci_name(dev));
283
284 for (count = 0; address[count]; count++) { /* for 6 BARs */
285 pci_read_config_dword(dev, address[count], &bar);
286
287 if (!bar) /* This BAR is not implemented */
288 continue;
289
290 pci_write_config_dword(dev, address[count], 0xFFFFFFFF);
291 pci_read_config_dword(dev, address[count], &len);
292
293 if (len & PCI_BASE_ADDRESS_SPACE_IO) {
294 /* This is IO */
295 base = bar & 0xFFFFFFFC;
296 len = len & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
297 len = len & ~(len - 1);
298
299 dbg("BAR[%d] %08x - %08x (IO)\n", count, (u32)base, (u32)base + len - 1);
300
301 res = acpiphp_make_resource(base, len);
302 if (!res)
303 goto no_memory;
304
305 res->next = func->io_head;
306 func->io_head = res;
307
308 } else {
309 /* This is Memory */
310 base = bar & 0xFFFFFFF0;
311 if (len & PCI_BASE_ADDRESS_MEM_PREFETCH) {
312 /* pfmem */
313
314 len &= 0xFFFFFFF0;
315 len = ~len + 1;
316
317 if (len & PCI_BASE_ADDRESS_MEM_TYPE_64) { /* takes up another dword */
318 dbg("prefetch mem 64\n");
319 count += 1;
320 }
321 dbg("BAR[%d] %08x - %08x (PMEM)\n", count, (u32)base, (u32)base + len - 1);
322 res = acpiphp_make_resource(base, len);
323 if (!res)
324 goto no_memory;
325
326 res->next = func->p_mem_head;
327 func->p_mem_head = res;
328
329 } else {
330 /* regular memory */
331
332 len &= 0xFFFFFFF0;
333 len = ~len + 1;
334
335 if (len & PCI_BASE_ADDRESS_MEM_TYPE_64) {
336 /* takes up another dword */
337 dbg("mem 64\n");
338 count += 1;
339 }
340 dbg("BAR[%d] %08x - %08x (MEM)\n", count, (u32)base, (u32)base + len - 1);
341 res = acpiphp_make_resource(base, len);
342 if (!res)
343 goto no_memory;
344
345 res->next = func->mem_head;
346 func->mem_head = res;
347
348 }
349 }
350
351 pci_write_config_dword(dev, address[count], bar);
352 }
353#if 1
354 acpiphp_dump_func_resource(func);
355#endif
356
357 return 0;
358
359 no_memory:
360 err("out of memory\n");
361 acpiphp_free_resource(&func->io_head);
362 acpiphp_free_resource(&func->mem_head);
363 acpiphp_free_resource(&func->p_mem_head);
364
365 return -1;
366}
367
368
369/**
370 * acpiphp_configure_slot - allocate PCI resources
371 * @slot: slot to be configured
372 *
373 * initializes a PCI functions on a device inserted
374 * into the slot
375 *
376 */
377int acpiphp_configure_slot (struct acpiphp_slot *slot)
378{
379 struct acpiphp_func *func;
380 struct list_head *l;
381 u8 hdr;
382 u32 dvid;
383 int retval = 0;
384 int is_multi = 0;
385
386 pci_bus_read_config_byte(slot->bridge->pci_bus,
387 PCI_DEVFN(slot->device, 0),
388 PCI_HEADER_TYPE, &hdr);
389
390 if (hdr & 0x80)
391 is_multi = 1;
392
393 list_for_each (l, &slot->funcs) {
394 func = list_entry(l, struct acpiphp_func, sibling);
395 if (is_multi || func->function == 0) {
396 pci_bus_read_config_dword(slot->bridge->pci_bus,
397 PCI_DEVFN(slot->device,
398 func->function),
399 PCI_VENDOR_ID, &dvid);
400 if (dvid != 0xffffffff) {
401 retval = init_config_space(func);
402 if (retval)
403 break;
404 }
405 }
406 }
407
408 return retval;
409}
410
411/**
412 * acpiphp_configure_function - configure PCI function
413 * @func: function to be configured
414 *
415 * initializes a PCI functions on a device inserted
416 * into the slot
417 *
418 */
419int acpiphp_configure_function (struct acpiphp_func *func)
420{
421 /* all handled by the pci core now */
422 return 0;
423}
424
425/**
426 * acpiphp_unconfigure_function - unconfigure PCI function
427 * @func: function to be unconfigured
428 *
429 */
430void acpiphp_unconfigure_function (struct acpiphp_func *func)
431{
432 struct acpiphp_bridge *bridge;
433
434 /* if pci_dev is NULL, ignore it */
435 if (!func->pci_dev)
436 return;
437
438 pci_remove_bus_device(func->pci_dev);
439
440 /* free all resources */
441 bridge = func->slot->bridge;
442
443 spin_lock(&bridge->res_lock);
444 acpiphp_move_resource(&func->io_head, &bridge->io_head);
445 acpiphp_move_resource(&func->mem_head, &bridge->mem_head);
446 acpiphp_move_resource(&func->p_mem_head, &bridge->p_mem_head);
447 acpiphp_move_resource(&func->bus_head, &bridge->bus_head);
448 spin_unlock(&bridge->res_lock);
449}
diff --git a/drivers/pci/hotplug/acpiphp_res.c b/drivers/pci/hotplug/acpiphp_res.c
deleted file mode 100644
index f54b1fa7b75a..000000000000
--- a/drivers/pci/hotplug/acpiphp_res.c
+++ /dev/null
@@ -1,700 +0,0 @@
1/*
2 * ACPI PCI HotPlug Utility functions
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
8 * Copyright (C) 2002 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
9 * Copyright (C) 2002 NEC Corporation
10 *
11 * All rights reserved.
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 (at
16 * your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
21 * NON INFRINGEMENT. See the GNU General Public License for more
22 * 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 * Send feedback to <gregkh@us.ibm.com>, <t-kochi@bq.jp.nec.com>
29 *
30 */
31
32#include <linux/init.h>
33#include <linux/module.h>
34
35#include <linux/kernel.h>
36#include <linux/types.h>
37#include <linux/proc_fs.h>
38#include <linux/sysctl.h>
39#include <linux/pci.h>
40#include <linux/smp.h>
41#include <linux/smp_lock.h>
42
43#include <linux/string.h>
44#include <linux/mm.h>
45#include <linux/errno.h>
46#include <linux/ioport.h>
47#include <linux/slab.h>
48#include <linux/interrupt.h>
49#include <linux/timer.h>
50
51#include <linux/ioctl.h>
52#include <linux/fcntl.h>
53
54#include <linux/list.h>
55
56#include "pci_hotplug.h"
57#include "acpiphp.h"
58
59#define MY_NAME "acpiphp_res"
60
61
62/*
63 * sort_by_size - sort nodes by their length, smallest first
64 */
65static int sort_by_size(struct pci_resource **head)
66{
67 struct pci_resource *current_res;
68 struct pci_resource *next_res;
69 int out_of_order = 1;
70
71 if (!(*head))
72 return 1;
73
74 if (!((*head)->next))
75 return 0;
76
77 while (out_of_order) {
78 out_of_order = 0;
79
80 /* Special case for swapping list head */
81 if (((*head)->next) &&
82 ((*head)->length > (*head)->next->length)) {
83 out_of_order++;
84 current_res = *head;
85 *head = (*head)->next;
86 current_res->next = (*head)->next;
87 (*head)->next = current_res;
88 }
89
90 current_res = *head;
91
92 while (current_res->next && current_res->next->next) {
93 if (current_res->next->length > current_res->next->next->length) {
94 out_of_order++;
95 next_res = current_res->next;
96 current_res->next = current_res->next->next;
97 current_res = current_res->next;
98 next_res->next = current_res->next;
99 current_res->next = next_res;
100 } else
101 current_res = current_res->next;
102 }
103 } /* End of out_of_order loop */
104
105 return 0;
106}
107
108#if 0
109/*
110 * sort_by_max_size - sort nodes by their length, largest first
111 */
112static int sort_by_max_size(struct pci_resource **head)
113{
114 struct pci_resource *current_res;
115 struct pci_resource *next_res;
116 int out_of_order = 1;
117
118 if (!(*head))
119 return 1;
120
121 if (!((*head)->next))
122 return 0;
123
124 while (out_of_order) {
125 out_of_order = 0;
126
127 /* Special case for swapping list head */
128 if (((*head)->next) &&
129 ((*head)->length < (*head)->next->length)) {
130 out_of_order++;
131 current_res = *head;
132 *head = (*head)->next;
133 current_res->next = (*head)->next;
134 (*head)->next = current_res;
135 }
136
137 current_res = *head;
138
139 while (current_res->next && current_res->next->next) {
140 if (current_res->next->length < current_res->next->next->length) {
141 out_of_order++;
142 next_res = current_res->next;
143 current_res->next = current_res->next->next;
144 current_res = current_res->next;
145 next_res->next = current_res->next;
146 current_res->next = next_res;
147 } else
148 current_res = current_res->next;
149 }
150 } /* End of out_of_order loop */
151
152 return 0;
153}
154#endif
155
156/**
157 * get_io_resource - get resource for I/O ports
158 *
159 * this function sorts the resource list by size and then
160 * returns the first node of "size" length that is not in the
161 * ISA aliasing window. If it finds a node larger than "size"
162 * it will split it up.
163 *
164 * size must be a power of two.
165 *
166 * difference from get_resource is handling of ISA aliasing space.
167 *
168 */
169struct pci_resource *acpiphp_get_io_resource (struct pci_resource **head, u32 size)
170{
171 struct pci_resource *prevnode;
172 struct pci_resource *node;
173 struct pci_resource *split_node;
174 u64 temp_qword;
175
176 if (!(*head))
177 return NULL;
178
179 if (acpiphp_resource_sort_and_combine(head))
180 return NULL;
181
182 if (sort_by_size(head))
183 return NULL;
184
185 for (node = *head; node; node = node->next) {
186 if (node->length < size)
187 continue;
188
189 if (node->base & (size - 1)) {
190 /* this one isn't base aligned properly
191 so we'll make a new entry and split it up */
192 temp_qword = (node->base | (size-1)) + 1;
193
194 /* Short circuit if adjusted size is too small */
195 if ((node->length - (temp_qword - node->base)) < size)
196 continue;
197
198 split_node = acpiphp_make_resource(node->base, temp_qword - node->base);
199
200 if (!split_node)
201 return NULL;
202
203 node->base = temp_qword;
204 node->length -= split_node->length;
205
206 /* Put it in the list */
207 split_node->next = node->next;
208 node->next = split_node;
209 } /* End of non-aligned base */
210
211 /* Don't need to check if too small since we already did */
212 if (node->length > size) {
213 /* this one is longer than we need
214 so we'll make a new entry and split it up */
215 split_node = acpiphp_make_resource(node->base + size, node->length - size);
216
217 if (!split_node)
218 return NULL;
219
220 node->length = size;
221
222 /* Put it in the list */
223 split_node->next = node->next;
224 node->next = split_node;
225 } /* End of too big on top end */
226
227 /* For IO make sure it's not in the ISA aliasing space */
228 if ((node->base & 0x300L) && !(node->base & 0xfffff000))
229 continue;
230
231 /* If we got here, then it is the right size
232 Now take it out of the list */
233 if (*head == node) {
234 *head = node->next;
235 } else {
236 prevnode = *head;
237 while (prevnode->next != node)
238 prevnode = prevnode->next;
239
240 prevnode->next = node->next;
241 }
242 node->next = NULL;
243 /* Stop looping */
244 break;
245 }
246
247 return node;
248}
249
250
251#if 0
252/**
253 * get_max_resource - get the largest resource
254 *
255 * Gets the largest node that is at least "size" big from the
256 * list pointed to by head. It aligns the node on top and bottom
257 * to "size" alignment before returning it.
258 */
259static struct pci_resource *acpiphp_get_max_resource (struct pci_resource **head, u32 size)
260{
261 struct pci_resource *max;
262 struct pci_resource *temp;
263 struct pci_resource *split_node;
264 u64 temp_qword;
265
266 if (!(*head))
267 return NULL;
268
269 if (acpiphp_resource_sort_and_combine(head))
270 return NULL;
271
272 if (sort_by_max_size(head))
273 return NULL;
274
275 for (max = *head;max; max = max->next) {
276
277 /* If not big enough we could probably just bail,
278 instead we'll continue to the next. */
279 if (max->length < size)
280 continue;
281
282 if (max->base & (size - 1)) {
283 /* this one isn't base aligned properly
284 so we'll make a new entry and split it up */
285 temp_qword = (max->base | (size-1)) + 1;
286
287 /* Short circuit if adjusted size is too small */
288 if ((max->length - (temp_qword - max->base)) < size)
289 continue;
290
291 split_node = acpiphp_make_resource(max->base, temp_qword - max->base);
292
293 if (!split_node)
294 return NULL;
295
296 max->base = temp_qword;
297 max->length -= split_node->length;
298
299 /* Put it next in the list */
300 split_node->next = max->next;
301 max->next = split_node;
302 }
303
304 if ((max->base + max->length) & (size - 1)) {
305 /* this one isn't end aligned properly at the top
306 so we'll make a new entry and split it up */
307 temp_qword = ((max->base + max->length) & ~(size - 1));
308
309 split_node = acpiphp_make_resource(temp_qword,
310 max->length + max->base - temp_qword);
311
312 if (!split_node)
313 return NULL;
314
315 max->length -= split_node->length;
316
317 /* Put it in the list */
318 split_node->next = max->next;
319 max->next = split_node;
320 }
321
322 /* Make sure it didn't shrink too much when we aligned it */
323 if (max->length < size)
324 continue;
325
326 /* Now take it out of the list */
327 temp = (struct pci_resource*) *head;
328 if (temp == max) {
329 *head = max->next;
330 } else {
331 while (temp && temp->next != max) {
332 temp = temp->next;
333 }
334
335 temp->next = max->next;
336 }
337
338 max->next = NULL;
339 return max;
340 }
341
342 /* If we get here, we couldn't find one */
343 return NULL;
344}
345#endif
346
347/**
348 * get_resource - get resource (mem, pfmem)
349 *
350 * this function sorts the resource list by size and then
351 * returns the first node of "size" length. If it finds a node
352 * larger than "size" it will split it up.
353 *
354 * size must be a power of two.
355 *
356 */
357struct pci_resource *acpiphp_get_resource (struct pci_resource **head, u32 size)
358{
359 struct pci_resource *prevnode;
360 struct pci_resource *node;
361 struct pci_resource *split_node;
362 u64 temp_qword;
363
364 if (!(*head))
365 return NULL;
366
367 if (acpiphp_resource_sort_and_combine(head))
368 return NULL;
369
370 if (sort_by_size(head))
371 return NULL;
372
373 for (node = *head; node; node = node->next) {
374 dbg("%s: req_size =%x node=%p, base=%x, length=%x\n",
375 __FUNCTION__, size, node, (u32)node->base, node->length);
376 if (node->length < size)
377 continue;
378
379 if (node->base & (size - 1)) {
380 dbg("%s: not aligned\n", __FUNCTION__);
381 /* this one isn't base aligned properly
382 so we'll make a new entry and split it up */
383 temp_qword = (node->base | (size-1)) + 1;
384
385 /* Short circuit if adjusted size is too small */
386 if ((node->length - (temp_qword - node->base)) < size)
387 continue;
388
389 split_node = acpiphp_make_resource(node->base, temp_qword - node->base);
390
391 if (!split_node)
392 return NULL;
393
394 node->base = temp_qword;
395 node->length -= split_node->length;
396
397 /* Put it in the list */
398 split_node->next = node->next;
399 node->next = split_node;
400 } /* End of non-aligned base */
401
402 /* Don't need to check if too small since we already did */
403 if (node->length > size) {
404 dbg("%s: too big\n", __FUNCTION__);
405 /* this one is longer than we need
406 so we'll make a new entry and split it up */
407 split_node = acpiphp_make_resource(node->base + size, node->length - size);
408
409 if (!split_node)
410 return NULL;
411
412 node->length = size;
413
414 /* Put it in the list */
415 split_node->next = node->next;
416 node->next = split_node;
417 } /* End of too big on top end */
418
419 dbg("%s: got one!!!\n", __FUNCTION__);
420 /* If we got here, then it is the right size
421 Now take it out of the list */
422 if (*head == node) {
423 *head = node->next;
424 } else {
425 prevnode = *head;
426 while (prevnode->next != node)
427 prevnode = prevnode->next;
428
429 prevnode->next = node->next;
430 }
431 node->next = NULL;
432 /* Stop looping */
433 break;
434 }
435 return node;
436}
437
438/**
439 * get_resource_with_base - get resource with specific base address
440 *
441 * this function
442 * returns the first node of "size" length located at specified base address.
443 * If it finds a node larger than "size" it will split it up.
444 *
445 * size must be a power of two.
446 *
447 */
448struct pci_resource *acpiphp_get_resource_with_base (struct pci_resource **head, u64 base, u32 size)
449{
450 struct pci_resource *prevnode;
451 struct pci_resource *node;
452 struct pci_resource *split_node;
453 u64 temp_qword;
454
455 if (!(*head))
456 return NULL;
457
458 if (acpiphp_resource_sort_and_combine(head))
459 return NULL;
460
461 for (node = *head; node; node = node->next) {
462 dbg(": 1st req_base=%x req_size =%x node=%p, base=%x, length=%x\n",
463 (u32)base, size, node, (u32)node->base, node->length);
464 if (node->base > base)
465 continue;
466
467 if ((node->base + node->length) < (base + size))
468 continue;
469
470 if (node->base < base) {
471 dbg(": split 1\n");
472 /* this one isn't base aligned properly
473 so we'll make a new entry and split it up */
474 temp_qword = base;
475
476 /* Short circuit if adjusted size is too small */
477 if ((node->length - (temp_qword - node->base)) < size)
478 continue;
479
480 split_node = acpiphp_make_resource(node->base, temp_qword - node->base);
481
482 if (!split_node)
483 return NULL;
484
485 node->base = temp_qword;
486 node->length -= split_node->length;
487
488 /* Put it in the list */
489 split_node->next = node->next;
490 node->next = split_node;
491 }
492
493 dbg(": 2nd req_base=%x req_size =%x node=%p, base=%x, length=%x\n",
494 (u32)base, size, node, (u32)node->base, node->length);
495
496 /* Don't need to check if too small since we already did */
497 if (node->length > size) {
498 dbg(": split 2\n");
499 /* this one is longer than we need
500 so we'll make a new entry and split it up */
501 split_node = acpiphp_make_resource(node->base + size, node->length - size);
502
503 if (!split_node)
504 return NULL;
505
506 node->length = size;
507
508 /* Put it in the list */
509 split_node->next = node->next;
510 node->next = split_node;
511 } /* End of too big on top end */
512
513 dbg(": got one!!!\n");
514 /* If we got here, then it is the right size
515 Now take it out of the list */
516 if (*head == node) {
517 *head = node->next;
518 } else {
519 prevnode = *head;
520 while (prevnode->next != node)
521 prevnode = prevnode->next;
522
523 prevnode->next = node->next;
524 }
525 node->next = NULL;
526 /* Stop looping */
527 break;
528 }
529 return node;
530}
531
532
533/**
534 * acpiphp_resource_sort_and_combine
535 *
536 * Sorts all of the nodes in the list in ascending order by
537 * their base addresses. Also does garbage collection by
538 * combining adjacent nodes.
539 *
540 * returns 0 if success
541 */
542int acpiphp_resource_sort_and_combine (struct pci_resource **head)
543{
544 struct pci_resource *node1;
545 struct pci_resource *node2;
546 int out_of_order = 1;
547
548 if (!(*head))
549 return 1;
550
551 dbg("*head->next = %p\n",(*head)->next);
552
553 if (!(*head)->next)
554 return 0; /* only one item on the list, already sorted! */
555
556 dbg("*head->base = 0x%x\n",(u32)(*head)->base);
557 dbg("*head->next->base = 0x%x\n", (u32)(*head)->next->base);
558 while (out_of_order) {
559 out_of_order = 0;
560
561 /* Special case for swapping list head */
562 if (((*head)->next) &&
563 ((*head)->base > (*head)->next->base)) {
564 node1 = *head;
565 (*head) = (*head)->next;
566 node1->next = (*head)->next;
567 (*head)->next = node1;
568 out_of_order++;
569 }
570
571 node1 = (*head);
572
573 while (node1->next && node1->next->next) {
574 if (node1->next->base > node1->next->next->base) {
575 out_of_order++;
576 node2 = node1->next;
577 node1->next = node1->next->next;
578 node1 = node1->next;
579 node2->next = node1->next;
580 node1->next = node2;
581 } else
582 node1 = node1->next;
583 }
584 } /* End of out_of_order loop */
585
586 node1 = *head;
587
588 while (node1 && node1->next) {
589 if ((node1->base + node1->length) == node1->next->base) {
590 /* Combine */
591 dbg("8..\n");
592 node1->length += node1->next->length;
593 node2 = node1->next;
594 node1->next = node1->next->next;
595 kfree(node2);
596 } else
597 node1 = node1->next;
598 }
599
600 return 0;
601}
602
603
604/**
605 * acpiphp_make_resource - make resource structure
606 * @base: base address of a resource
607 * @length: length of a resource
608 */
609struct pci_resource *acpiphp_make_resource (u64 base, u32 length)
610{
611 struct pci_resource *res;
612
613 res = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
614 if (res) {
615 memset(res, 0, sizeof(struct pci_resource));
616 res->base = base;
617 res->length = length;
618 }
619
620 return res;
621}
622
623
624/**
625 * acpiphp_move_resource - move linked resources from one to another
626 * @from: head of linked resource list
627 * @to: head of linked resource list
628 */
629void acpiphp_move_resource (struct pci_resource **from, struct pci_resource **to)
630{
631 struct pci_resource *tmp;
632
633 while (*from) {
634 tmp = (*from)->next;
635 (*from)->next = *to;
636 *to = *from;
637 *from = tmp;
638 }
639
640 /* *from = NULL is guaranteed */
641}
642
643
644/**
645 * acpiphp_free_resource - free all linked resources
646 * @res: head of linked resource list
647 */
648void acpiphp_free_resource (struct pci_resource **res)
649{
650 struct pci_resource *tmp;
651
652 while (*res) {
653 tmp = (*res)->next;
654 kfree(*res);
655 *res = tmp;
656 }
657
658 /* *res = NULL is guaranteed */
659}
660
661
662/* debug support functions; will go away sometime :) */
663static void dump_resource(struct pci_resource *head)
664{
665 struct pci_resource *p;
666 int cnt;
667
668 p = head;
669 cnt = 0;
670
671 while (p) {
672 dbg("[%02d] %08x - %08x\n",
673 cnt++, (u32)p->base, (u32)p->base + p->length - 1);
674 p = p->next;
675 }
676}
677
678void acpiphp_dump_resource(struct acpiphp_bridge *bridge)
679{
680 dbg("I/O resource:\n");
681 dump_resource(bridge->io_head);
682 dbg("MEM resource:\n");
683 dump_resource(bridge->mem_head);
684 dbg("PMEM resource:\n");
685 dump_resource(bridge->p_mem_head);
686 dbg("BUS resource:\n");
687 dump_resource(bridge->bus_head);
688}
689
690void acpiphp_dump_func_resource(struct acpiphp_func *func)
691{
692 dbg("I/O resource:\n");
693 dump_resource(func->io_head);
694 dbg("MEM resource:\n");
695 dump_resource(func->mem_head);
696 dbg("PMEM resource:\n");
697 dump_resource(func->p_mem_head);
698 dbg("BUS resource:\n");
699 dump_resource(func->bus_head);
700}
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index afbccfa5217d..8c6d3987d461 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -60,6 +60,7 @@ static void __iomem *smbios_start;
60static void __iomem *cpqhp_rom_start; 60static void __iomem *cpqhp_rom_start;
61static int power_mode; 61static int power_mode;
62static int debug; 62static int debug;
63static int initialized;
63 64
64#define DRIVER_VERSION "0.9.8" 65#define DRIVER_VERSION "0.9.8"
65#define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>" 66#define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>"
@@ -1271,7 +1272,6 @@ static int one_time_init(void)
1271{ 1272{
1272 int loop; 1273 int loop;
1273 int retval = 0; 1274 int retval = 0;
1274 static int initialized = 0;
1275 1275
1276 if (initialized) 1276 if (initialized)
1277 return 0; 1277 return 0;
@@ -1441,7 +1441,8 @@ static void __exit unload_cpqphpd(void)
1441 } 1441 }
1442 1442
1443 // Stop the notification mechanism 1443 // Stop the notification mechanism
1444 cpqhp_event_stop_thread(); 1444 if (initialized)
1445 cpqhp_event_stop_thread();
1445 1446
1446 //unmap the rom address 1447 //unmap the rom address
1447 if (cpqhp_rom_start) 1448 if (cpqhp_rom_start)
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 30206ac43c44..b5ab9aa6ff7c 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -28,10 +28,10 @@ static struct msi_desc* msi_desc[NR_IRQS] = { [0 ... NR_IRQS-1] = NULL };
28static kmem_cache_t* msi_cachep; 28static kmem_cache_t* msi_cachep;
29 29
30static int pci_msi_enable = 1; 30static int pci_msi_enable = 1;
31static int last_alloc_vector = 0; 31static int last_alloc_vector;
32static int nr_released_vectors = 0; 32static int nr_released_vectors;
33static int nr_reserved_vectors = NR_HP_RESERVED_VECTORS; 33static int nr_reserved_vectors = NR_HP_RESERVED_VECTORS;
34static int nr_msix_devices = 0; 34static int nr_msix_devices;
35 35
36#ifndef CONFIG_X86_IO_APIC 36#ifndef CONFIG_X86_IO_APIC
37int vector_irq[NR_VECTORS] = { [0 ... NR_VECTORS - 1] = -1}; 37int vector_irq[NR_VECTORS] = { [0 ... NR_VECTORS - 1] = -1};
@@ -170,44 +170,30 @@ static unsigned int startup_msi_irq_wo_maskbit(unsigned int vector)
170 return 0; /* never anything pending */ 170 return 0; /* never anything pending */
171} 171}
172 172
173static void release_msi(unsigned int vector); 173static unsigned int startup_msi_irq_w_maskbit(unsigned int vector)
174static void shutdown_msi_irq(unsigned int vector)
175{
176 release_msi(vector);
177}
178
179#define shutdown_msi_irq_wo_maskbit shutdown_msi_irq
180static void enable_msi_irq_wo_maskbit(unsigned int vector) {}
181static void disable_msi_irq_wo_maskbit(unsigned int vector) {}
182static void ack_msi_irq_wo_maskbit(unsigned int vector) {}
183static void end_msi_irq_wo_maskbit(unsigned int vector)
184{ 174{
185 move_msi(vector); 175 startup_msi_irq_wo_maskbit(vector);
186 ack_APIC_irq(); 176 unmask_MSI_irq(vector);
177 return 0; /* never anything pending */
187} 178}
188 179
189static unsigned int startup_msi_irq_w_maskbit(unsigned int vector) 180static void shutdown_msi_irq(unsigned int vector)
190{ 181{
191 struct msi_desc *entry; 182 struct msi_desc *entry;
192 unsigned long flags; 183 unsigned long flags;
193 184
194 spin_lock_irqsave(&msi_lock, flags); 185 spin_lock_irqsave(&msi_lock, flags);
195 entry = msi_desc[vector]; 186 entry = msi_desc[vector];
196 if (!entry || !entry->dev) { 187 if (entry && entry->dev)
197 spin_unlock_irqrestore(&msi_lock, flags); 188 entry->msi_attrib.state = 0; /* Mark it not active */
198 return 0;
199 }
200 entry->msi_attrib.state = 1; /* Mark it active */
201 spin_unlock_irqrestore(&msi_lock, flags); 189 spin_unlock_irqrestore(&msi_lock, flags);
202
203 unmask_MSI_irq(vector);
204 return 0; /* never anything pending */
205} 190}
206 191
207#define shutdown_msi_irq_w_maskbit shutdown_msi_irq 192static void end_msi_irq_wo_maskbit(unsigned int vector)
208#define enable_msi_irq_w_maskbit unmask_MSI_irq 193{
209#define disable_msi_irq_w_maskbit mask_MSI_irq 194 move_msi(vector);
210#define ack_msi_irq_w_maskbit mask_MSI_irq 195 ack_APIC_irq();
196}
211 197
212static void end_msi_irq_w_maskbit(unsigned int vector) 198static void end_msi_irq_w_maskbit(unsigned int vector)
213{ 199{
@@ -216,6 +202,10 @@ static void end_msi_irq_w_maskbit(unsigned int vector)
216 ack_APIC_irq(); 202 ack_APIC_irq();
217} 203}
218 204
205static void do_nothing(unsigned int vector)
206{
207}
208
219/* 209/*
220 * Interrupt Type for MSI-X PCI/PCI-X/PCI-Express Devices, 210 * Interrupt Type for MSI-X PCI/PCI-X/PCI-Express Devices,
221 * which implement the MSI-X Capability Structure. 211 * which implement the MSI-X Capability Structure.
@@ -223,10 +213,10 @@ static void end_msi_irq_w_maskbit(unsigned int vector)
223static struct hw_interrupt_type msix_irq_type = { 213static struct hw_interrupt_type msix_irq_type = {
224 .typename = "PCI-MSI-X", 214 .typename = "PCI-MSI-X",
225 .startup = startup_msi_irq_w_maskbit, 215 .startup = startup_msi_irq_w_maskbit,
226 .shutdown = shutdown_msi_irq_w_maskbit, 216 .shutdown = shutdown_msi_irq,
227 .enable = enable_msi_irq_w_maskbit, 217 .enable = unmask_MSI_irq,
228 .disable = disable_msi_irq_w_maskbit, 218 .disable = mask_MSI_irq,
229 .ack = ack_msi_irq_w_maskbit, 219 .ack = mask_MSI_irq,
230 .end = end_msi_irq_w_maskbit, 220 .end = end_msi_irq_w_maskbit,
231 .set_affinity = set_msi_irq_affinity 221 .set_affinity = set_msi_irq_affinity
232}; 222};
@@ -239,10 +229,10 @@ static struct hw_interrupt_type msix_irq_type = {
239static struct hw_interrupt_type msi_irq_w_maskbit_type = { 229static struct hw_interrupt_type msi_irq_w_maskbit_type = {
240 .typename = "PCI-MSI", 230 .typename = "PCI-MSI",
241 .startup = startup_msi_irq_w_maskbit, 231 .startup = startup_msi_irq_w_maskbit,
242 .shutdown = shutdown_msi_irq_w_maskbit, 232 .shutdown = shutdown_msi_irq,
243 .enable = enable_msi_irq_w_maskbit, 233 .enable = unmask_MSI_irq,
244 .disable = disable_msi_irq_w_maskbit, 234 .disable = mask_MSI_irq,
245 .ack = ack_msi_irq_w_maskbit, 235 .ack = mask_MSI_irq,
246 .end = end_msi_irq_w_maskbit, 236 .end = end_msi_irq_w_maskbit,
247 .set_affinity = set_msi_irq_affinity 237 .set_affinity = set_msi_irq_affinity
248}; 238};
@@ -255,10 +245,10 @@ static struct hw_interrupt_type msi_irq_w_maskbit_type = {
255static struct hw_interrupt_type msi_irq_wo_maskbit_type = { 245static struct hw_interrupt_type msi_irq_wo_maskbit_type = {
256 .typename = "PCI-MSI", 246 .typename = "PCI-MSI",
257 .startup = startup_msi_irq_wo_maskbit, 247 .startup = startup_msi_irq_wo_maskbit,
258 .shutdown = shutdown_msi_irq_wo_maskbit, 248 .shutdown = shutdown_msi_irq,
259 .enable = enable_msi_irq_wo_maskbit, 249 .enable = do_nothing,
260 .disable = disable_msi_irq_wo_maskbit, 250 .disable = do_nothing,
261 .ack = ack_msi_irq_wo_maskbit, 251 .ack = do_nothing,
262 .end = end_msi_irq_wo_maskbit, 252 .end = end_msi_irq_wo_maskbit,
263 .set_affinity = set_msi_irq_affinity 253 .set_affinity = set_msi_irq_affinity
264}; 254};
@@ -407,7 +397,7 @@ static struct msi_desc* alloc_msi_entry(void)
407{ 397{
408 struct msi_desc *entry; 398 struct msi_desc *entry;
409 399
410 entry = (struct msi_desc*) kmem_cache_alloc(msi_cachep, SLAB_KERNEL); 400 entry = kmem_cache_alloc(msi_cachep, SLAB_KERNEL);
411 if (!entry) 401 if (!entry)
412 return NULL; 402 return NULL;
413 403
@@ -796,18 +786,6 @@ void pci_disable_msi(struct pci_dev* dev)
796 } 786 }
797} 787}
798 788
799static void release_msi(unsigned int vector)
800{
801 struct msi_desc *entry;
802 unsigned long flags;
803
804 spin_lock_irqsave(&msi_lock, flags);
805 entry = msi_desc[vector];
806 if (entry && entry->dev)
807 entry->msi_attrib.state = 0; /* Mark it not active */
808 spin_unlock_irqrestore(&msi_lock, flags);
809}
810
811static int msi_free_vector(struct pci_dev* dev, int vector, int reassign) 789static int msi_free_vector(struct pci_dev* dev, int vector, int reassign)
812{ 790{
813 struct msi_desc *entry; 791 struct msi_desc *entry;
@@ -924,7 +902,7 @@ static int reroute_msix_table(int head, struct msix_entry *entries, int *nvec)
924/** 902/**
925 * pci_enable_msix - configure device's MSI-X capability structure 903 * pci_enable_msix - configure device's MSI-X capability structure
926 * @dev: pointer to the pci_dev data structure of MSI-X device function 904 * @dev: pointer to the pci_dev data structure of MSI-X device function
927 * @data: pointer to an array of MSI-X entries 905 * @entries: pointer to an array of MSI-X entries
928 * @nvec: number of MSI-X vectors requested for allocation by device driver 906 * @nvec: number of MSI-X vectors requested for allocation by device driver
929 * 907 *
930 * Setup the MSI-X capability structure of device function with the number 908 * Setup the MSI-X capability structure of device function with the number
diff --git a/drivers/pci/msi.h b/drivers/pci/msi.h
index bef21ae3cbd0..390f1851c0f1 100644
--- a/drivers/pci/msi.h
+++ b/drivers/pci/msi.h
@@ -41,11 +41,11 @@ static inline void move_msi(int vector) {}
41#define PCI_MSIX_FLAGS_BIRMASK (7 << 0) 41#define PCI_MSIX_FLAGS_BIRMASK (7 << 0)
42#define PCI_MSIX_FLAGS_BITMASK (1 << 0) 42#define PCI_MSIX_FLAGS_BITMASK (1 << 0)
43 43
44#define PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET 0
45#define PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET 4
46#define PCI_MSIX_ENTRY_DATA_OFFSET 8
47#define PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET 12
48#define PCI_MSIX_ENTRY_SIZE 16 44#define PCI_MSIX_ENTRY_SIZE 16
45#define PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET 0
46#define PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET 4
47#define PCI_MSIX_ENTRY_DATA_OFFSET 8
48#define PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET 12
49 49
50#define msi_control_reg(base) (base + PCI_MSI_FLAGS) 50#define msi_control_reg(base) (base + PCI_MSI_FLAGS)
51#define msi_lower_address_reg(base) (base + PCI_MSI_ADDRESS_LO) 51#define msi_lower_address_reg(base) (base + PCI_MSI_ADDRESS_LO)
@@ -64,7 +64,6 @@ static inline void move_msi(int vector) {}
64#define msi_enable(control, num) multi_msi_enable(control, num); \ 64#define msi_enable(control, num) multi_msi_enable(control, num); \
65 control |= PCI_MSI_FLAGS_ENABLE 65 control |= PCI_MSI_FLAGS_ENABLE
66 66
67#define msix_control_reg msi_control_reg
68#define msix_table_offset_reg(base) (base + 0x04) 67#define msix_table_offset_reg(base) (base + 0x04)
69#define msix_pba_offset_reg(base) (base + 0x08) 68#define msix_pba_offset_reg(base) (base + 0x08)
70#define msix_enable(control) control |= PCI_MSIX_FLAGS_ENABLE 69#define msix_enable(control) control |= PCI_MSIX_FLAGS_ENABLE
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index a15f94072a6f..cc9d65388e62 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -60,15 +60,18 @@ resource_show(struct device * dev, struct device_attribute *attr, char * buf)
60 char * str = buf; 60 char * str = buf;
61 int i; 61 int i;
62 int max = 7; 62 int max = 7;
63 u64 start, end;
63 64
64 if (pci_dev->subordinate) 65 if (pci_dev->subordinate)
65 max = DEVICE_COUNT_RESOURCE; 66 max = DEVICE_COUNT_RESOURCE;
66 67
67 for (i = 0; i < max; i++) { 68 for (i = 0; i < max; i++) {
68 str += sprintf(str,"0x%016lx 0x%016lx 0x%016lx\n", 69 struct resource *res = &pci_dev->resource[i];
69 pci_resource_start(pci_dev,i), 70 pci_resource_to_user(pci_dev, i, res, &start, &end);
70 pci_resource_end(pci_dev,i), 71 str += sprintf(str,"0x%016llx 0x%016llx 0x%016llx\n",
71 pci_resource_flags(pci_dev,i)); 72 (unsigned long long)start,
73 (unsigned long long)end,
74 (unsigned long long)res->flags);
72 } 75 }
73 return (str - buf); 76 return (str - buf);
74} 77}
@@ -313,8 +316,21 @@ pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
313 struct device, kobj)); 316 struct device, kobj));
314 struct resource *res = (struct resource *)attr->private; 317 struct resource *res = (struct resource *)attr->private;
315 enum pci_mmap_state mmap_type; 318 enum pci_mmap_state mmap_type;
319 u64 start, end;
320 int i;
316 321
317 vma->vm_pgoff += res->start >> PAGE_SHIFT; 322 for (i = 0; i < PCI_ROM_RESOURCE; i++)
323 if (res == &pdev->resource[i])
324 break;
325 if (i >= PCI_ROM_RESOURCE)
326 return -ENODEV;
327
328 /* pci_mmap_page_range() expects the same kind of entry as coming
329 * from /proc/bus/pci/ which is a "user visible" value. If this is
330 * different from the resource itself, arch will do necessary fixup.
331 */
332 pci_resource_to_user(pdev, i, res, &start, &end);
333 vma->vm_pgoff += start >> PAGE_SHIFT;
318 mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io; 334 mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io;
319 335
320 return pci_mmap_page_range(pdev, vma, mmap_type, 0); 336 return pci_mmap_page_range(pdev, vma, mmap_type, 0);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index fd48b201eb53..6a0a82f0508b 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -374,8 +374,11 @@ struct pci_bus * __devinit pci_add_new_bus(struct pci_bus *parent, struct pci_de
374 struct pci_bus *child; 374 struct pci_bus *child;
375 375
376 child = pci_alloc_child_bus(parent, dev, busnr); 376 child = pci_alloc_child_bus(parent, dev, busnr);
377 if (child) 377 if (child) {
378 spin_lock(&pci_bus_lock);
378 list_add_tail(&child->node, &parent->children); 379 list_add_tail(&child->node, &parent->children);
380 spin_unlock(&pci_bus_lock);
381 }
379 return child; 382 return child;
380} 383}
381 384
@@ -411,7 +414,7 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
411{ 414{
412 struct pci_bus *child; 415 struct pci_bus *child;
413 int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS); 416 int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS);
414 u32 buses; 417 u32 buses, i;
415 u16 bctl; 418 u16 bctl;
416 419
417 pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses); 420 pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses);
@@ -447,7 +450,7 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
447 return max; 450 return max;
448 } 451 }
449 452
450 child = pci_alloc_child_bus(bus, dev, busnr); 453 child = pci_add_new_bus(bus, dev, busnr);
451 if (!child) 454 if (!child)
452 return max; 455 return max;
453 child->primary = buses & 0xFF; 456 child->primary = buses & 0xFF;
@@ -470,7 +473,11 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
470 /* Clear errors */ 473 /* Clear errors */
471 pci_write_config_word(dev, PCI_STATUS, 0xffff); 474 pci_write_config_word(dev, PCI_STATUS, 0xffff);
472 475
473 child = pci_alloc_child_bus(bus, dev, ++max); 476 /* Prevent assigning a bus number that already exists.
477 * This can happen when a bridge is hot-plugged */
478 if (pci_find_bus(pci_domain_nr(bus), max+1))
479 return max;
480 child = pci_add_new_bus(bus, dev, ++max);
474 buses = (buses & 0xff000000) 481 buses = (buses & 0xff000000)
475 | ((unsigned int)(child->primary) << 0) 482 | ((unsigned int)(child->primary) << 0)
476 | ((unsigned int)(child->secondary) << 8) 483 | ((unsigned int)(child->secondary) << 8)
@@ -501,7 +508,11 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
501 * as cards with a PCI-to-PCI bridge can be 508 * as cards with a PCI-to-PCI bridge can be
502 * inserted later. 509 * inserted later.
503 */ 510 */
504 max += CARDBUS_RESERVE_BUSNR; 511 for (i=0; i<CARDBUS_RESERVE_BUSNR; i++)
512 if (pci_find_bus(pci_domain_nr(bus),
513 max+i+1))
514 break;
515 max += i;
505 } 516 }
506 /* 517 /*
507 * Set the subordinate bus number to its real value. 518 * Set the subordinate bus number to its real value.
@@ -757,7 +768,9 @@ pci_scan_single_device(struct pci_bus *bus, int devfn)
757 * and the bus list for fixup functions, etc. 768 * and the bus list for fixup functions, etc.
758 */ 769 */
759 INIT_LIST_HEAD(&dev->global_list); 770 INIT_LIST_HEAD(&dev->global_list);
771 spin_lock(&pci_bus_lock);
760 list_add_tail(&dev->bus_list, &bus->devices); 772 list_add_tail(&dev->bus_list, &bus->devices);
773 spin_unlock(&pci_bus_lock);
761 774
762 return dev; 775 return dev;
763} 776}
@@ -878,7 +891,9 @@ struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent, int bus,
878 pr_debug("PCI: Bus %04x:%02x already known\n", pci_domain_nr(b), bus); 891 pr_debug("PCI: Bus %04x:%02x already known\n", pci_domain_nr(b), bus);
879 goto err_out; 892 goto err_out;
880 } 893 }
894 spin_lock(&pci_bus_lock);
881 list_add_tail(&b->node, &pci_root_buses); 895 list_add_tail(&b->node, &pci_root_buses);
896 spin_unlock(&pci_bus_lock);
882 897
883 memset(dev, 0, sizeof(*dev)); 898 memset(dev, 0, sizeof(*dev));
884 dev->parent = parent; 899 dev->parent = parent;
@@ -911,8 +926,6 @@ struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent, int bus,
911 926
912 b->subordinate = pci_scan_child_bus(b); 927 b->subordinate = pci_scan_child_bus(b);
913 928
914 pci_bus_add_devices(b);
915
916 return b; 929 return b;
917 930
918sys_create_link_err: 931sys_create_link_err:
@@ -922,7 +935,9 @@ class_dev_create_file_err:
922class_dev_reg_err: 935class_dev_reg_err:
923 device_unregister(dev); 936 device_unregister(dev);
924dev_reg_err: 937dev_reg_err:
938 spin_lock(&pci_bus_lock);
925 list_del(&b->node); 939 list_del(&b->node);
940 spin_unlock(&pci_bus_lock);
926err_out: 941err_out:
927 kfree(dev); 942 kfree(dev);
928 kfree(b); 943 kfree(b);
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index e68bbfb1e7c3..7988fc8df3fd 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -355,14 +355,20 @@ static int show_device(struct seq_file *m, void *v)
355 dev->device, 355 dev->device,
356 dev->irq); 356 dev->irq);
357 /* Here should be 7 and not PCI_NUM_RESOURCES as we need to preserve compatibility */ 357 /* Here should be 7 and not PCI_NUM_RESOURCES as we need to preserve compatibility */
358 for(i=0; i<7; i++) 358 for (i=0; i<7; i++) {
359 u64 start, end;
360 pci_resource_to_user(dev, i, &dev->resource[i], &start, &end);
359 seq_printf(m, LONG_FORMAT, 361 seq_printf(m, LONG_FORMAT,
360 dev->resource[i].start | 362 ((unsigned long)start) |
361 (dev->resource[i].flags & PCI_REGION_FLAG_MASK)); 363 (dev->resource[i].flags & PCI_REGION_FLAG_MASK));
362 for(i=0; i<7; i++) 364 }
365 for (i=0; i<7; i++) {
366 u64 start, end;
367 pci_resource_to_user(dev, i, &dev->resource[i], &start, &end);
363 seq_printf(m, LONG_FORMAT, 368 seq_printf(m, LONG_FORMAT,
364 dev->resource[i].start < dev->resource[i].end ? 369 dev->resource[i].start < dev->resource[i].end ?
365 dev->resource[i].end - dev->resource[i].start + 1 : 0); 370 (unsigned long)(end - start) + 1 : 0);
371 }
366 seq_putc(m, '\t'); 372 seq_putc(m, '\t');
367 if (drv) 373 if (drv)
368 seq_printf(m, "%s", drv->name); 374 seq_printf(m, "%s", drv->name);
diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
index 96f077f9a659..27a294b6965d 100644
--- a/drivers/pci/remove.c
+++ b/drivers/pci/remove.c
@@ -18,17 +18,21 @@ static void pci_free_resources(struct pci_dev *dev)
18 18
19static void pci_destroy_dev(struct pci_dev *dev) 19static void pci_destroy_dev(struct pci_dev *dev)
20{ 20{
21 pci_proc_detach_device(dev); 21 if (!list_empty(&dev->global_list)) {
22 pci_remove_sysfs_dev_files(dev); 22 pci_proc_detach_device(dev);
23 device_unregister(&dev->dev); 23 pci_remove_sysfs_dev_files(dev);
24 device_unregister(&dev->dev);
25 spin_lock(&pci_bus_lock);
26 list_del(&dev->global_list);
27 dev->global_list.next = dev->global_list.prev = NULL;
28 spin_unlock(&pci_bus_lock);
29 }
24 30
25 /* Remove the device from the device lists, and prevent any further 31 /* Remove the device from the device lists, and prevent any further
26 * list accesses from this device */ 32 * list accesses from this device */
27 spin_lock(&pci_bus_lock); 33 spin_lock(&pci_bus_lock);
28 list_del(&dev->bus_list); 34 list_del(&dev->bus_list);
29 list_del(&dev->global_list);
30 dev->bus_list.next = dev->bus_list.prev = NULL; 35 dev->bus_list.next = dev->bus_list.prev = NULL;
31 dev->global_list.next = dev->global_list.prev = NULL;
32 spin_unlock(&pci_bus_lock); 36 spin_unlock(&pci_bus_lock);
33 37
34 pci_free_resources(dev); 38 pci_free_resources(dev);
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 1ba84be0b4c0..6b628de948af 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -72,7 +72,10 @@ pbus_assign_resources_sorted(struct pci_bus *bus)
72 for (list = head.next; list;) { 72 for (list = head.next; list;) {
73 res = list->res; 73 res = list->res;
74 idx = res - &list->dev->resource[0]; 74 idx = res - &list->dev->resource[0];
75 pci_assign_resource(list->dev, idx); 75 if (pci_assign_resource(list->dev, idx)) {
76 res->start = 0;
77 res->flags = 0;
78 }
76 tmp = list; 79 tmp = list;
77 list = list->next; 80 list = list->next;
78 kfree(tmp); 81 kfree(tmp);
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index 14e4124e1523..52ea34594363 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -14,8 +14,8 @@ config PCCARD
14 Say Y here if you want to attach PCMCIA- or PC-cards to your Linux 14 Say Y here if you want to attach PCMCIA- or PC-cards to your Linux
15 computer. These are credit-card size devices such as network cards, 15 computer. These are credit-card size devices such as network cards,
16 modems or hard drives often used with laptops computers. There are 16 modems or hard drives often used with laptops computers. There are
17 actually two varieties of these cards: the older 16 bit PCMCIA cards 17 actually two varieties of these cards: 16 bit PCMCIA and 32 bit
18 and the newer 32 bit CardBus cards. 18 CardBus cards.
19 19
20 To compile this driver as modules, choose M here: the 20 To compile this driver as modules, choose M here: the
21 module will be called pcmcia_core. 21 module will be called pcmcia_core.
@@ -42,22 +42,51 @@ config PCMCIA_DEBUG
42 42
43config PCMCIA 43config PCMCIA
44 tristate "16-bit PCMCIA support" 44 tristate "16-bit PCMCIA support"
45 select CRC32
45 default y 46 default y
46 ---help--- 47 ---help---
47 This option enables support for 16-bit PCMCIA cards. Most older 48 This option enables support for 16-bit PCMCIA cards. Most older
48 PC-cards are such 16-bit PCMCIA cards, so unless you know you're 49 PC-cards are such 16-bit PCMCIA cards, so unless you know you're
49 only using 32-bit CardBus cards, say Y or M here. 50 only using 32-bit CardBus cards, say Y or M here.
50 51
51 To use 16-bit PCMCIA cards, you will need supporting software from 52 To use 16-bit PCMCIA cards, you will need supporting software in
52 David Hinds' pcmcia-cs package (see the file <file:Documentation/Changes> 53 most cases. (see the file <file:Documentation/Changes> for
53 for location). Please also read the PCMCIA-HOWTO, available from 54 location and details).
54 <http://www.tldp.org/docs.html#howto>.
55 55
56 To compile this driver as modules, choose M here: the 56 To compile this driver as modules, choose M here: the
57 module will be called pcmcia. 57 module will be called pcmcia.
58 58
59 If unsure, say Y. 59 If unsure, say Y.
60 60
61config PCMCIA_LOAD_CIS
62 bool "Load CIS updates from userspace (EXPERIMENTAL)"
63 depends on PCMCIA && EXPERIMENTAL
64 select FW_LOADER
65 default y
66 help
67 Some PCMCIA cards require an updated Card Information Structure (CIS)
68 to be loaded from userspace to work correctly. If you say Y here,
69 and your userspace is arranged correctly, this will be loaded
70 automatically using the in-kernel firmware loader and the hotplug
71 subsystem, instead of relying on cardmgr from pcmcia-cs to do so.
72
73 If unsure, say Y.
74
75config PCMCIA_IOCTL
76 bool
77 depends on PCMCIA
78 default y
79 help
80 If you say Y here, the deprecated ioctl interface to the PCMCIA
81 subsystem will be built. It is needed by cardmgr and cardctl
82 (pcmcia-cs) to function properly.
83
84 If you do not use the new pcmciautils package, and have a
85 yenta, Cirrus PD6729, i82092, i82365 or tcic compatible bridge,
86 you need to say Y here to be able to use 16-bit PCMCIA cards.
87
88 If unsure, say Y.
89
61config CARDBUS 90config CARDBUS
62 bool "32-bit CardBus support" 91 bool "32-bit CardBus support"
63 depends on PCI 92 depends on PCI
@@ -77,8 +106,6 @@ comment "PC-card bridges"
77 106
78config YENTA 107config YENTA
79 tristate "CardBus yenta-compatible bridge support" 108 tristate "CardBus yenta-compatible bridge support"
80 depends on PCI
81#fixme: remove dependendcy on CARDBUS
82 depends on CARDBUS 109 depends on CARDBUS
83 select PCCARD_NONSTATIC 110 select PCCARD_NONSTATIC
84 ---help--- 111 ---help---
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
index 50c29361bc5f..ef694c74dfb7 100644
--- a/drivers/pcmcia/Makefile
+++ b/drivers/pcmcia/Makefile
@@ -10,7 +10,8 @@ pcmcia_core-y += cs.o cistpl.o rsrc_mgr.o socket_sysfs.o
10pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o 10pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o
11obj-$(CONFIG_PCCARD) += pcmcia_core.o 11obj-$(CONFIG_PCCARD) += pcmcia_core.o
12 12
13pcmcia-y += ds.o pcmcia_compat.o 13pcmcia-y += ds.o pcmcia_compat.o pcmcia_resource.o
14pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o
14obj-$(CONFIG_PCMCIA) += pcmcia.o 15obj-$(CONFIG_PCMCIA) += pcmcia.o
15 16
16obj-$(CONFIG_PCCARD_NONSTATIC) += rsrc_nonstatic.o 17obj-$(CONFIG_PCCARD_NONSTATIC) += rsrc_nonstatic.o
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index e29a6ddf2fd7..dd7651ff5b43 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -89,8 +89,10 @@ static void __iomem *
89set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flags) 89set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flags)
90{ 90{
91 pccard_mem_map *mem = &s->cis_mem; 91 pccard_mem_map *mem = &s->cis_mem;
92 int ret;
93
92 if (!(s->features & SS_CAP_STATIC_MAP) && mem->res == NULL) { 94 if (!(s->features & SS_CAP_STATIC_MAP) && mem->res == NULL) {
93 mem->res = find_mem_region(0, s->map_size, s->map_size, 0, s); 95 mem->res = pcmcia_find_mem_region(0, s->map_size, s->map_size, 0, s);
94 if (mem->res == NULL) { 96 if (mem->res == NULL) {
95 printk(KERN_NOTICE "cs: unable to map card memory!\n"); 97 printk(KERN_NOTICE "cs: unable to map card memory!\n");
96 return NULL; 98 return NULL;
@@ -99,7 +101,12 @@ set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flag
99 } 101 }
100 mem->card_start = card_offset; 102 mem->card_start = card_offset;
101 mem->flags = flags; 103 mem->flags = flags;
102 s->ops->set_mem_map(s, mem); 104 ret = s->ops->set_mem_map(s, mem);
105 if (ret) {
106 iounmap(s->cis_virt);
107 return NULL;
108 }
109
103 if (s->features & SS_CAP_STATIC_MAP) { 110 if (s->features & SS_CAP_STATIC_MAP) {
104 if (s->cis_virt) 111 if (s->cis_virt)
105 iounmap(s->cis_virt); 112 iounmap(s->cis_virt);
@@ -119,13 +126,13 @@ set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flag
119#define IS_ATTR 1 126#define IS_ATTR 1
120#define IS_INDIRECT 8 127#define IS_INDIRECT 8
121 128
122int read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, 129int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
123 u_int len, void *ptr) 130 u_int len, void *ptr)
124{ 131{
125 void __iomem *sys, *end; 132 void __iomem *sys, *end;
126 unsigned char *buf = ptr; 133 unsigned char *buf = ptr;
127 134
128 cs_dbg(s, 3, "read_cis_mem(%d, %#x, %u)\n", attr, addr, len); 135 cs_dbg(s, 3, "pcmcia_read_cis_mem(%d, %#x, %u)\n", attr, addr, len);
129 136
130 if (attr & IS_INDIRECT) { 137 if (attr & IS_INDIRECT) {
131 /* Indirect accesses use a bunch of special registers at fixed 138 /* Indirect accesses use a bunch of special registers at fixed
@@ -182,14 +189,16 @@ int read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
182 *(u_char *)(ptr+2), *(u_char *)(ptr+3)); 189 *(u_char *)(ptr+2), *(u_char *)(ptr+3));
183 return 0; 190 return 0;
184} 191}
192EXPORT_SYMBOL(pcmcia_read_cis_mem);
193
185 194
186void write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, 195void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
187 u_int len, void *ptr) 196 u_int len, void *ptr)
188{ 197{
189 void __iomem *sys, *end; 198 void __iomem *sys, *end;
190 unsigned char *buf = ptr; 199 unsigned char *buf = ptr;
191 200
192 cs_dbg(s, 3, "write_cis_mem(%d, %#x, %u)\n", attr, addr, len); 201 cs_dbg(s, 3, "pcmcia_write_cis_mem(%d, %#x, %u)\n", attr, addr, len);
193 202
194 if (attr & IS_INDIRECT) { 203 if (attr & IS_INDIRECT) {
195 /* Indirect accesses use a bunch of special registers at fixed 204 /* Indirect accesses use a bunch of special registers at fixed
@@ -239,6 +248,8 @@ void write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
239 } 248 }
240 } 249 }
241} 250}
251EXPORT_SYMBOL(pcmcia_write_cis_mem);
252
242 253
243/*====================================================================== 254/*======================================================================
244 255
@@ -274,7 +285,7 @@ static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr,
274 ret = read_cb_mem(s, attr, addr, len, ptr); 285 ret = read_cb_mem(s, attr, addr, len, ptr);
275 else 286 else
276#endif 287#endif
277 ret = read_cis_mem(s, attr, addr, len, ptr); 288 ret = pcmcia_read_cis_mem(s, attr, addr, len, ptr);
278 289
279 if (ret == 0) { 290 if (ret == 0) {
280 /* Copy data into the cache */ 291 /* Copy data into the cache */
@@ -348,7 +359,7 @@ int verify_cis_cache(struct pcmcia_socket *s)
348 read_cb_mem(s, cis->attr, cis->addr, len, buf); 359 read_cb_mem(s, cis->attr, cis->addr, len, buf);
349 else 360 else
350#endif 361#endif
351 read_cis_mem(s, cis->attr, cis->addr, len, buf); 362 pcmcia_read_cis_mem(s, cis->attr, cis->addr, len, buf);
352 363
353 if (memcmp(buf, cis->cache, len) != 0) { 364 if (memcmp(buf, cis->cache, len) != 0) {
354 kfree(buf); 365 kfree(buf);
@@ -381,6 +392,7 @@ int pcmcia_replace_cis(struct pcmcia_socket *s, cisdump_t *cis)
381 memcpy(s->fake_cis, cis->Data, cis->Length); 392 memcpy(s->fake_cis, cis->Data, cis->Length);
382 return CS_SUCCESS; 393 return CS_SUCCESS;
383} 394}
395EXPORT_SYMBOL(pcmcia_replace_cis);
384 396
385/*====================================================================== 397/*======================================================================
386 398
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index 48e4f04530d8..e82859d3227a 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -43,36 +43,11 @@
43#include <pcmcia/ds.h> 43#include <pcmcia/ds.h>
44#include "cs_internal.h" 44#include "cs_internal.h"
45 45
46#ifdef CONFIG_PCI
47#define PCI_OPT " [pci]"
48#else
49#define PCI_OPT ""
50#endif
51#ifdef CONFIG_CARDBUS
52#define CB_OPT " [cardbus]"
53#else
54#define CB_OPT ""
55#endif
56#ifdef CONFIG_PM
57#define PM_OPT " [pm]"
58#else
59#define PM_OPT ""
60#endif
61#if !defined(CONFIG_CARDBUS) && !defined(CONFIG_PCI) && !defined(CONFIG_PM)
62#define OPTIONS " none"
63#else
64#define OPTIONS PCI_OPT CB_OPT PM_OPT
65#endif
66
67static const char *release = "Linux Kernel Card Services";
68static const char *options = "options: " OPTIONS;
69
70/*====================================================================*/
71 46
72/* Module parameters */ 47/* Module parameters */
73 48
74MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>"); 49MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
75MODULE_DESCRIPTION("Linux Kernel Card Services\noptions:" OPTIONS); 50MODULE_DESCRIPTION("Linux Kernel Card Services");
76MODULE_LICENSE("GPL"); 51MODULE_LICENSE("GPL");
77 52
78#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444) 53#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444)
@@ -89,9 +64,6 @@ INT_MODULE_PARM(unreset_limit, 30); /* unreset_check's */
89/* Access speed for attribute memory windows */ 64/* Access speed for attribute memory windows */
90INT_MODULE_PARM(cis_speed, 300); /* ns */ 65INT_MODULE_PARM(cis_speed, 300); /* ns */
91 66
92/* Access speed for IO windows */
93INT_MODULE_PARM(io_speed, 0); /* ns */
94
95#ifdef DEBUG 67#ifdef DEBUG
96static int pc_debug; 68static int pc_debug;
97 69
@@ -103,34 +75,26 @@ int cs_debug_level(int level)
103} 75}
104#endif 76#endif
105 77
106/*====================================================================*/
107 78
108socket_state_t dead_socket = { 79socket_state_t dead_socket = {
109 .csc_mask = SS_DETECT, 80 .csc_mask = SS_DETECT,
110}; 81};
82EXPORT_SYMBOL(dead_socket);
111 83
112 84
113/* List of all sockets, protected by a rwsem */ 85/* List of all sockets, protected by a rwsem */
114LIST_HEAD(pcmcia_socket_list); 86LIST_HEAD(pcmcia_socket_list);
115DECLARE_RWSEM(pcmcia_socket_list_rwsem);
116EXPORT_SYMBOL(pcmcia_socket_list); 87EXPORT_SYMBOL(pcmcia_socket_list);
117EXPORT_SYMBOL(pcmcia_socket_list_rwsem);
118
119 88
120#ifdef CONFIG_PCMCIA_PROBE 89DECLARE_RWSEM(pcmcia_socket_list_rwsem);
121/* mask ofIRQs already reserved by other cards, we should avoid using them */ 90EXPORT_SYMBOL(pcmcia_socket_list_rwsem);
122static u8 pcmcia_used_irq[NR_IRQS];
123#endif
124 91
125/*====================================================================
126
127 Low-level PC Card interface drivers need to register with Card
128 Services using these calls.
129
130======================================================================*/
131 92
132/** 93/**
133 * socket drivers are expected to use the following callbacks in their 94 * Low-level PCMCIA socket drivers need to register with the PCCard
95 * core using pcmcia_register_socket.
96 *
97 * socket drivers are expected to use the following callbacks in their
134 * .drv struct: 98 * .drv struct:
135 * - pcmcia_socket_dev_suspend 99 * - pcmcia_socket_dev_suspend
136 * - pcmcia_socket_dev_resume 100 * - pcmcia_socket_dev_resume
@@ -230,8 +194,8 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
230 } 194 }
231 195
232 /* try to obtain a socket number [yes, it gets ugly if we 196 /* try to obtain a socket number [yes, it gets ugly if we
233 * register more than 2^sizeof(unsigned int) pcmcia 197 * register more than 2^sizeof(unsigned int) pcmcia
234 * sockets... but the socket number is deprecated 198 * sockets... but the socket number is deprecated
235 * anyways, so I don't care] */ 199 * anyways, so I don't care] */
236 down_write(&pcmcia_socket_list_rwsem); 200 down_write(&pcmcia_socket_list_rwsem);
237 if (list_empty(&pcmcia_socket_list)) 201 if (list_empty(&pcmcia_socket_list))
@@ -340,54 +304,49 @@ struct pcmcia_socket * pcmcia_get_socket_by_nr(unsigned int nr)
340EXPORT_SYMBOL(pcmcia_get_socket_by_nr); 304EXPORT_SYMBOL(pcmcia_get_socket_by_nr);
341 305
342 306
343/*====================================================================== 307/**
344 308 * socket_setup() and shutdown_socket() are called by the main event
345 socket_setup() and shutdown_socket() are called by the main event 309 * handler when card insertion and removal events are received.
346 handler when card insertion and removal events are received. 310 * socket_setup() turns on socket power and resets the socket, in two stages.
347 socket_setup() turns on socket power and resets the socket, in two stages. 311 * shutdown_socket() unconfigures a socket and turns off socket power.
348 shutdown_socket() unconfigures a socket and turns off socket power. 312 */
349
350======================================================================*/
351
352static void shutdown_socket(struct pcmcia_socket *s) 313static void shutdown_socket(struct pcmcia_socket *s)
353{ 314{
354 cs_dbg(s, 1, "shutdown_socket\n"); 315 cs_dbg(s, 1, "shutdown_socket\n");
355 316
356 /* Blank out the socket state */ 317 /* Blank out the socket state */
357 s->socket = dead_socket; 318 s->socket = dead_socket;
358 s->ops->init(s); 319 s->ops->init(s);
359 s->ops->set_socket(s, &s->socket); 320 s->ops->set_socket(s, &s->socket);
360 s->irq.AssignedIRQ = s->irq.Config = 0; 321 s->irq.AssignedIRQ = s->irq.Config = 0;
361 s->lock_count = 0; 322 s->lock_count = 0;
362 destroy_cis_cache(s); 323 destroy_cis_cache(s);
363#ifdef CONFIG_CARDBUS 324#ifdef CONFIG_CARDBUS
364 cb_free(s); 325 cb_free(s);
365#endif 326#endif
366 s->functions = 0; 327 s->functions = 0;
367 if (s->config) { 328 if (s->config) {
368 kfree(s->config); 329 kfree(s->config);
369 s->config = NULL; 330 s->config = NULL;
370 }
371
372 {
373 int status;
374 s->ops->get_status(s, &status);
375 if (status & SS_POWERON) {
376 printk(KERN_ERR "PCMCIA: socket %p: *** DANGER *** unable to remove socket power\n", s);
377 } 331 }
378 }
379} /* shutdown_socket */
380 332
381/*====================================================================== 333 {
334 int status;
335 s->ops->get_status(s, &status);
336 if (status & SS_POWERON) {
337 printk(KERN_ERR "PCMCIA: socket %p: *** DANGER *** unable to remove socket power\n", s);
338 }
339 }
340} /* shutdown_socket */
382 341
383 The central event handler. Send_event() sends an event to the
384 16-bit subsystem, which then calls the relevant device drivers.
385 Parse_events() interprets the event bits from
386 a card status change report. Do_shutdown() handles the high
387 priority stuff associated with a card removal.
388
389======================================================================*/
390 342
343/**
344 * The central event handler. Send_event() sends an event to the
345 * 16-bit subsystem, which then calls the relevant device drivers.
346 * Parse_events() interprets the event bits from
347 * a card status change report. Do_shutdown() handles the high
348 * priority stuff associated with a card removal.
349 */
391 350
392/* NOTE: send_event needs to be called with skt->sem held. */ 351/* NOTE: send_event needs to be called with skt->sem held. */
393 352
@@ -746,420 +705,9 @@ void pcmcia_parse_events(struct pcmcia_socket *s, u_int events)
746 wake_up(&s->thread_wait); 705 wake_up(&s->thread_wait);
747 } 706 }
748} /* pcmcia_parse_events */ 707} /* pcmcia_parse_events */
708EXPORT_SYMBOL(pcmcia_parse_events);
749 709
750 710
751/*======================================================================
752
753 Special stuff for managing IO windows, because they are scarce.
754
755======================================================================*/
756
757static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
758 ioaddr_t num, u_int lines)
759{
760 int i;
761 kio_addr_t try, align;
762
763 align = (*base) ? (lines ? 1<<lines : 0) : 1;
764 if (align && (align < num)) {
765 if (*base) {
766 cs_dbg(s, 0, "odd IO request: num %#x align %#lx\n",
767 num, align);
768 align = 0;
769 } else
770 while (align && (align < num)) align <<= 1;
771 }
772 if (*base & ~(align-1)) {
773 cs_dbg(s, 0, "odd IO request: base %#x align %#lx\n",
774 *base, align);
775 align = 0;
776 }
777 if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
778 *base = s->io_offset | (*base & 0x0fff);
779 return 0;
780 }
781 /* Check for an already-allocated window that must conflict with
782 what was asked for. It is a hack because it does not catch all
783 potential conflicts, just the most obvious ones. */
784 for (i = 0; i < MAX_IO_WIN; i++)
785 if ((s->io[i].NumPorts != 0) &&
786 ((s->io[i].BasePort & (align-1)) == *base))
787 return 1;
788 for (i = 0; i < MAX_IO_WIN; i++) {
789 if (s->io[i].NumPorts == 0) {
790 s->io[i].res = find_io_region(*base, num, align, s);
791 if (s->io[i].res) {
792 s->io[i].Attributes = attr;
793 s->io[i].BasePort = *base = s->io[i].res->start;
794 s->io[i].NumPorts = s->io[i].InUse = num;
795 break;
796 } else
797 return 1;
798 } else if (s->io[i].Attributes != attr)
799 continue;
800 /* Try to extend top of window */
801 try = s->io[i].BasePort + s->io[i].NumPorts;
802 if ((*base == 0) || (*base == try))
803 if (adjust_io_region(s->io[i].res, s->io[i].res->start,
804 s->io[i].res->end + num, s) == 0) {
805 *base = try;
806 s->io[i].NumPorts += num;
807 s->io[i].InUse += num;
808 break;
809 }
810 /* Try to extend bottom of window */
811 try = s->io[i].BasePort - num;
812 if ((*base == 0) || (*base == try))
813 if (adjust_io_region(s->io[i].res, s->io[i].res->start - num,
814 s->io[i].res->end, s) == 0) {
815 s->io[i].BasePort = *base = try;
816 s->io[i].NumPorts += num;
817 s->io[i].InUse += num;
818 break;
819 }
820 }
821 return (i == MAX_IO_WIN);
822} /* alloc_io_space */
823
824static void release_io_space(struct pcmcia_socket *s, ioaddr_t base,
825 ioaddr_t num)
826{
827 int i;
828
829 for (i = 0; i < MAX_IO_WIN; i++) {
830 if ((s->io[i].BasePort <= base) &&
831 (s->io[i].BasePort+s->io[i].NumPorts >= base+num)) {
832 s->io[i].InUse -= num;
833 /* Free the window if no one else is using it */
834 if (s->io[i].InUse == 0) {
835 s->io[i].NumPorts = 0;
836 release_resource(s->io[i].res);
837 kfree(s->io[i].res);
838 s->io[i].res = NULL;
839 }
840 }
841 }
842}
843
844/*======================================================================
845
846 Access_configuration_register() reads and writes configuration
847 registers in attribute memory. Memory window 0 is reserved for
848 this and the tuple reading services.
849
850======================================================================*/
851
852int pccard_access_configuration_register(struct pcmcia_socket *s,
853 unsigned int function,
854 conf_reg_t *reg)
855{
856 config_t *c;
857 int addr;
858 u_char val;
859
860 if (!s || !s->config)
861 return CS_NO_CARD;
862
863 c = &s->config[function];
864
865 if (c == NULL)
866 return CS_NO_CARD;
867
868 if (!(c->state & CONFIG_LOCKED))
869 return CS_CONFIGURATION_LOCKED;
870
871 addr = (c->ConfigBase + reg->Offset) >> 1;
872
873 switch (reg->Action) {
874 case CS_READ:
875 read_cis_mem(s, 1, addr, 1, &val);
876 reg->Value = val;
877 break;
878 case CS_WRITE:
879 val = reg->Value;
880 write_cis_mem(s, 1, addr, 1, &val);
881 break;
882 default:
883 return CS_BAD_ARGS;
884 break;
885 }
886 return CS_SUCCESS;
887} /* access_configuration_register */
888EXPORT_SYMBOL(pccard_access_configuration_register);
889
890
891/*====================================================================*/
892
893int pccard_get_configuration_info(struct pcmcia_socket *s,
894 unsigned int function,
895 config_info_t *config)
896{
897 config_t *c;
898
899 if (!(s->state & SOCKET_PRESENT))
900 return CS_NO_CARD;
901
902 config->Function = function;
903
904#ifdef CONFIG_CARDBUS
905 if (s->state & SOCKET_CARDBUS) {
906 memset(config, 0, sizeof(config_info_t));
907 config->Vcc = s->socket.Vcc;
908 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
909 config->Option = s->cb_dev->subordinate->number;
910 if (s->state & SOCKET_CARDBUS_CONFIG) {
911 config->Attributes = CONF_VALID_CLIENT;
912 config->IntType = INT_CARDBUS;
913 config->AssignedIRQ = s->irq.AssignedIRQ;
914 if (config->AssignedIRQ)
915 config->Attributes |= CONF_ENABLE_IRQ;
916 config->BasePort1 = s->io[0].BasePort;
917 config->NumPorts1 = s->io[0].NumPorts;
918 }
919 return CS_SUCCESS;
920 }
921#endif
922
923 c = (s->config != NULL) ? &s->config[function] : NULL;
924
925 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
926 config->Attributes = 0;
927 config->Vcc = s->socket.Vcc;
928 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
929 return CS_SUCCESS;
930 }
931
932 /* !!! This is a hack !!! */
933 memcpy(&config->Attributes, &c->Attributes, sizeof(config_t));
934 config->Attributes |= CONF_VALID_CLIENT;
935 config->CardValues = c->CardValues;
936 config->IRQAttributes = c->irq.Attributes;
937 config->AssignedIRQ = s->irq.AssignedIRQ;
938 config->BasePort1 = c->io.BasePort1;
939 config->NumPorts1 = c->io.NumPorts1;
940 config->Attributes1 = c->io.Attributes1;
941 config->BasePort2 = c->io.BasePort2;
942 config->NumPorts2 = c->io.NumPorts2;
943 config->Attributes2 = c->io.Attributes2;
944 config->IOAddrLines = c->io.IOAddrLines;
945
946 return CS_SUCCESS;
947} /* get_configuration_info */
948EXPORT_SYMBOL(pccard_get_configuration_info);
949
950/*======================================================================
951
952 Return information about this version of Card Services.
953
954======================================================================*/
955
956int pcmcia_get_card_services_info(servinfo_t *info)
957{
958 unsigned int socket_count = 0;
959 struct list_head *tmp;
960 info->Signature[0] = 'C';
961 info->Signature[1] = 'S';
962 down_read(&pcmcia_socket_list_rwsem);
963 list_for_each(tmp, &pcmcia_socket_list)
964 socket_count++;
965 up_read(&pcmcia_socket_list_rwsem);
966 info->Count = socket_count;
967 info->Revision = CS_RELEASE_CODE;
968 info->CSLevel = 0x0210;
969 info->VendorString = (char *)release;
970 return CS_SUCCESS;
971} /* get_card_services_info */
972
973
974/*====================================================================*/
975
976int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req)
977{
978 window_t *win;
979 int w;
980
981 if (!s || !(s->state & SOCKET_PRESENT))
982 return CS_NO_CARD;
983 for (w = idx; w < MAX_WIN; w++)
984 if (s->state & SOCKET_WIN_REQ(w)) break;
985 if (w == MAX_WIN)
986 return CS_NO_MORE_ITEMS;
987 win = &s->win[w];
988 req->Base = win->ctl.res->start;
989 req->Size = win->ctl.res->end - win->ctl.res->start + 1;
990 req->AccessSpeed = win->ctl.speed;
991 req->Attributes = 0;
992 if (win->ctl.flags & MAP_ATTRIB)
993 req->Attributes |= WIN_MEMORY_TYPE_AM;
994 if (win->ctl.flags & MAP_ACTIVE)
995 req->Attributes |= WIN_ENABLE;
996 if (win->ctl.flags & MAP_16BIT)
997 req->Attributes |= WIN_DATA_WIDTH_16;
998 if (win->ctl.flags & MAP_USE_WAIT)
999 req->Attributes |= WIN_USE_WAIT;
1000 *handle = win;
1001 return CS_SUCCESS;
1002} /* get_window */
1003EXPORT_SYMBOL(pcmcia_get_window);
1004
1005/*=====================================================================
1006
1007 Return the PCI device associated with a card..
1008
1009======================================================================*/
1010
1011#ifdef CONFIG_CARDBUS
1012
1013struct pci_bus *pcmcia_lookup_bus(struct pcmcia_socket *s)
1014{
1015 if (!s || !(s->state & SOCKET_CARDBUS))
1016 return NULL;
1017
1018 return s->cb_dev->subordinate;
1019}
1020
1021EXPORT_SYMBOL(pcmcia_lookup_bus);
1022
1023#endif
1024
1025/*======================================================================
1026
1027 Get the current socket state bits. We don't support the latched
1028 SocketState yet: I haven't seen any point for it.
1029
1030======================================================================*/
1031
1032int pccard_get_status(struct pcmcia_socket *s, unsigned int function, cs_status_t *status)
1033{
1034 config_t *c;
1035 int val;
1036
1037 s->ops->get_status(s, &val);
1038 status->CardState = status->SocketState = 0;
1039 status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0;
1040 status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0;
1041 status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0;
1042 status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0;
1043 if (s->state & SOCKET_SUSPEND)
1044 status->CardState |= CS_EVENT_PM_SUSPEND;
1045 if (!(s->state & SOCKET_PRESENT))
1046 return CS_NO_CARD;
1047
1048 c = (s->config != NULL) ? &s->config[function] : NULL;
1049 if ((c != NULL) && (c->state & CONFIG_LOCKED) &&
1050 (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
1051 u_char reg;
1052 if (c->Present & PRESENT_PIN_REPLACE) {
1053 read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg);
1054 status->CardState |=
1055 (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
1056 status->CardState |=
1057 (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0;
1058 status->CardState |=
1059 (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0;
1060 status->CardState |=
1061 (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0;
1062 } else {
1063 /* No PRR? Then assume we're always ready */
1064 status->CardState |= CS_EVENT_READY_CHANGE;
1065 }
1066 if (c->Present & PRESENT_EXT_STATUS) {
1067 read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg);
1068 status->CardState |=
1069 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
1070 }
1071 return CS_SUCCESS;
1072 }
1073 status->CardState |=
1074 (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0;
1075 status->CardState |=
1076 (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0;
1077 status->CardState |=
1078 (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0;
1079 status->CardState |=
1080 (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0;
1081 return CS_SUCCESS;
1082} /* get_status */
1083EXPORT_SYMBOL(pccard_get_status);
1084
1085/*======================================================================
1086
1087 Change the card address of an already open memory window.
1088
1089======================================================================*/
1090
1091int pcmcia_get_mem_page(window_handle_t win, memreq_t *req)
1092{
1093 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
1094 return CS_BAD_HANDLE;
1095 req->Page = 0;
1096 req->CardOffset = win->ctl.card_start;
1097 return CS_SUCCESS;
1098} /* get_mem_page */
1099
1100int pcmcia_map_mem_page(window_handle_t win, memreq_t *req)
1101{
1102 struct pcmcia_socket *s;
1103 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
1104 return CS_BAD_HANDLE;
1105 if (req->Page != 0)
1106 return CS_BAD_PAGE;
1107 s = win->sock;
1108 win->ctl.card_start = req->CardOffset;
1109 if (s->ops->set_mem_map(s, &win->ctl) != 0)
1110 return CS_BAD_OFFSET;
1111 return CS_SUCCESS;
1112} /* map_mem_page */
1113
1114/*======================================================================
1115
1116 Modify a locked socket configuration
1117
1118======================================================================*/
1119
1120int pcmcia_modify_configuration(client_handle_t handle,
1121 modconf_t *mod)
1122{
1123 struct pcmcia_socket *s;
1124 config_t *c;
1125
1126 if (CHECK_HANDLE(handle))
1127 return CS_BAD_HANDLE;
1128 s = SOCKET(handle); c = CONFIG(handle);
1129 if (!(s->state & SOCKET_PRESENT))
1130 return CS_NO_CARD;
1131 if (!(c->state & CONFIG_LOCKED))
1132 return CS_CONFIGURATION_LOCKED;
1133
1134 if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
1135 if (mod->Attributes & CONF_ENABLE_IRQ) {
1136 c->Attributes |= CONF_ENABLE_IRQ;
1137 s->socket.io_irq = s->irq.AssignedIRQ;
1138 } else {
1139 c->Attributes &= ~CONF_ENABLE_IRQ;
1140 s->socket.io_irq = 0;
1141 }
1142 s->ops->set_socket(s, &s->socket);
1143 }
1144
1145 if (mod->Attributes & CONF_VCC_CHANGE_VALID)
1146 return CS_BAD_VCC;
1147
1148 /* We only allow changing Vpp1 and Vpp2 to the same value */
1149 if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
1150 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
1151 if (mod->Vpp1 != mod->Vpp2)
1152 return CS_BAD_VPP;
1153 c->Vpp1 = c->Vpp2 = s->socket.Vpp = mod->Vpp1;
1154 if (s->ops->set_socket(s, &s->socket))
1155 return CS_BAD_VPP;
1156 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
1157 (mod->Attributes & CONF_VPP2_CHANGE_VALID))
1158 return CS_BAD_VPP;
1159
1160 return CS_SUCCESS;
1161} /* modify_configuration */
1162
1163/* register pcmcia_callback */ 711/* register pcmcia_callback */
1164int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) 712int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
1165{ 713{
@@ -1188,543 +736,16 @@ int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
1188} 736}
1189EXPORT_SYMBOL(pccard_register_pcmcia); 737EXPORT_SYMBOL(pccard_register_pcmcia);
1190 738
1191/*====================================================================*/
1192 739
1193int pcmcia_release_configuration(client_handle_t handle) 740/* I'm not sure which "reset" function this is supposed to use,
1194{ 741 * but for now, it uses the low-level interface's reset, not the
1195 pccard_io_map io = { 0, 0, 0, 0, 1 }; 742 * CIS register.
1196 struct pcmcia_socket *s; 743 */
1197 int i;
1198
1199 if (CHECK_HANDLE(handle) ||
1200 !(handle->state & CLIENT_CONFIG_LOCKED))
1201 return CS_BAD_HANDLE;
1202 handle->state &= ~CLIENT_CONFIG_LOCKED;
1203 s = SOCKET(handle);
1204
1205#ifdef CONFIG_CARDBUS
1206 if (handle->state & CLIENT_CARDBUS)
1207 return CS_SUCCESS;
1208#endif
1209
1210 if (!(handle->state & CLIENT_STALE)) {
1211 config_t *c = CONFIG(handle);
1212 if (--(s->lock_count) == 0) {
1213 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */
1214 s->socket.Vpp = 0;
1215 s->socket.io_irq = 0;
1216 s->ops->set_socket(s, &s->socket);
1217 }
1218 if (c->state & CONFIG_IO_REQ)
1219 for (i = 0; i < MAX_IO_WIN; i++) {
1220 if (s->io[i].NumPorts == 0)
1221 continue;
1222 s->io[i].Config--;
1223 if (s->io[i].Config != 0)
1224 continue;
1225 io.map = i;
1226 s->ops->set_io_map(s, &io);
1227 }
1228 c->state &= ~CONFIG_LOCKED;
1229 }
1230
1231 return CS_SUCCESS;
1232} /* release_configuration */
1233
1234/*======================================================================
1235
1236 Release_io() releases the I/O ranges allocated by a client. This
1237 may be invoked some time after a card ejection has already dumped
1238 the actual socket configuration, so if the client is "stale", we
1239 don't bother checking the port ranges against the current socket
1240 values.
1241
1242======================================================================*/
1243
1244int pcmcia_release_io(client_handle_t handle, io_req_t *req)
1245{
1246 struct pcmcia_socket *s;
1247
1248 if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IO_REQ))
1249 return CS_BAD_HANDLE;
1250 handle->state &= ~CLIENT_IO_REQ;
1251 s = SOCKET(handle);
1252
1253#ifdef CONFIG_CARDBUS
1254 if (handle->state & CLIENT_CARDBUS)
1255 return CS_SUCCESS;
1256#endif
1257
1258 if (!(handle->state & CLIENT_STALE)) {
1259 config_t *c = CONFIG(handle);
1260 if (c->state & CONFIG_LOCKED)
1261 return CS_CONFIGURATION_LOCKED;
1262 if ((c->io.BasePort1 != req->BasePort1) ||
1263 (c->io.NumPorts1 != req->NumPorts1) ||
1264 (c->io.BasePort2 != req->BasePort2) ||
1265 (c->io.NumPorts2 != req->NumPorts2))
1266 return CS_BAD_ARGS;
1267 c->state &= ~CONFIG_IO_REQ;
1268 }
1269
1270 release_io_space(s, req->BasePort1, req->NumPorts1);
1271 if (req->NumPorts2)
1272 release_io_space(s, req->BasePort2, req->NumPorts2);
1273
1274 return CS_SUCCESS;
1275} /* release_io */
1276
1277/*====================================================================*/
1278
1279int pcmcia_release_irq(client_handle_t handle, irq_req_t *req)
1280{
1281 struct pcmcia_socket *s;
1282 if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IRQ_REQ))
1283 return CS_BAD_HANDLE;
1284 handle->state &= ~CLIENT_IRQ_REQ;
1285 s = SOCKET(handle);
1286
1287 if (!(handle->state & CLIENT_STALE)) {
1288 config_t *c = CONFIG(handle);
1289 if (c->state & CONFIG_LOCKED)
1290 return CS_CONFIGURATION_LOCKED;
1291 if (c->irq.Attributes != req->Attributes)
1292 return CS_BAD_ATTRIBUTE;
1293 if (s->irq.AssignedIRQ != req->AssignedIRQ)
1294 return CS_BAD_IRQ;
1295 if (--s->irq.Config == 0) {
1296 c->state &= ~CONFIG_IRQ_REQ;
1297 s->irq.AssignedIRQ = 0;
1298 }
1299 }
1300
1301 if (req->Attributes & IRQ_HANDLE_PRESENT) {
1302 free_irq(req->AssignedIRQ, req->Instance);
1303 }
1304
1305#ifdef CONFIG_PCMCIA_PROBE
1306 pcmcia_used_irq[req->AssignedIRQ]--;
1307#endif
1308
1309 return CS_SUCCESS;
1310} /* cs_release_irq */
1311
1312/*====================================================================*/
1313
1314int pcmcia_release_window(window_handle_t win)
1315{
1316 struct pcmcia_socket *s;
1317
1318 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
1319 return CS_BAD_HANDLE;
1320 s = win->sock;
1321 if (!(win->handle->state & CLIENT_WIN_REQ(win->index)))
1322 return CS_BAD_HANDLE;
1323
1324 /* Shut down memory window */
1325 win->ctl.flags &= ~MAP_ACTIVE;
1326 s->ops->set_mem_map(s, &win->ctl);
1327 s->state &= ~SOCKET_WIN_REQ(win->index);
1328
1329 /* Release system memory */
1330 if (win->ctl.res) {
1331 release_resource(win->ctl.res);
1332 kfree(win->ctl.res);
1333 win->ctl.res = NULL;
1334 }
1335 win->handle->state &= ~CLIENT_WIN_REQ(win->index);
1336
1337 win->magic = 0;
1338
1339 return CS_SUCCESS;
1340} /* release_window */
1341
1342/*====================================================================*/
1343
1344int pcmcia_request_configuration(client_handle_t handle,
1345 config_req_t *req)
1346{
1347 int i;
1348 u_int base;
1349 struct pcmcia_socket *s;
1350 config_t *c;
1351 pccard_io_map iomap;
1352
1353 if (CHECK_HANDLE(handle))
1354 return CS_BAD_HANDLE;
1355 s = SOCKET(handle);
1356 if (!(s->state & SOCKET_PRESENT))
1357 return CS_NO_CARD;
1358
1359#ifdef CONFIG_CARDBUS
1360 if (handle->state & CLIENT_CARDBUS)
1361 return CS_UNSUPPORTED_MODE;
1362#endif
1363
1364 if (req->IntType & INT_CARDBUS)
1365 return CS_UNSUPPORTED_MODE;
1366 c = CONFIG(handle);
1367 if (c->state & CONFIG_LOCKED)
1368 return CS_CONFIGURATION_LOCKED;
1369
1370 /* Do power control. We don't allow changes in Vcc. */
1371 if (s->socket.Vcc != req->Vcc)
1372 return CS_BAD_VCC;
1373 if (req->Vpp1 != req->Vpp2)
1374 return CS_BAD_VPP;
1375 s->socket.Vpp = req->Vpp1;
1376 if (s->ops->set_socket(s, &s->socket))
1377 return CS_BAD_VPP;
1378
1379 c->Vcc = req->Vcc; c->Vpp1 = c->Vpp2 = req->Vpp1;
1380
1381 /* Pick memory or I/O card, DMA mode, interrupt */
1382 c->IntType = req->IntType;
1383 c->Attributes = req->Attributes;
1384 if (req->IntType & INT_MEMORY_AND_IO)
1385 s->socket.flags |= SS_IOCARD;
1386 if (req->IntType & INT_ZOOMED_VIDEO)
1387 s->socket.flags |= SS_ZVCARD | SS_IOCARD;
1388 if (req->Attributes & CONF_ENABLE_DMA)
1389 s->socket.flags |= SS_DMA_MODE;
1390 if (req->Attributes & CONF_ENABLE_SPKR)
1391 s->socket.flags |= SS_SPKR_ENA;
1392 if (req->Attributes & CONF_ENABLE_IRQ)
1393 s->socket.io_irq = s->irq.AssignedIRQ;
1394 else
1395 s->socket.io_irq = 0;
1396 s->ops->set_socket(s, &s->socket);
1397 s->lock_count++;
1398
1399 /* Set up CIS configuration registers */
1400 base = c->ConfigBase = req->ConfigBase;
1401 c->Present = c->CardValues = req->Present;
1402 if (req->Present & PRESENT_COPY) {
1403 c->Copy = req->Copy;
1404 write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy);
1405 }
1406 if (req->Present & PRESENT_OPTION) {
1407 if (s->functions == 1) {
1408 c->Option = req->ConfigIndex & COR_CONFIG_MASK;
1409 } else {
1410 c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK;
1411 c->Option |= COR_FUNC_ENA|COR_IREQ_ENA;
1412 if (req->Present & PRESENT_IOBASE_0)
1413 c->Option |= COR_ADDR_DECODE;
1414 }
1415 if (c->state & CONFIG_IRQ_REQ)
1416 if (!(c->irq.Attributes & IRQ_FORCED_PULSE))
1417 c->Option |= COR_LEVEL_REQ;
1418 write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option);
1419 mdelay(40);
1420 }
1421 if (req->Present & PRESENT_STATUS) {
1422 c->Status = req->Status;
1423 write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status);
1424 }
1425 if (req->Present & PRESENT_PIN_REPLACE) {
1426 c->Pin = req->Pin;
1427 write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin);
1428 }
1429 if (req->Present & PRESENT_EXT_STATUS) {
1430 c->ExtStatus = req->ExtStatus;
1431 write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus);
1432 }
1433 if (req->Present & PRESENT_IOBASE_0) {
1434 u_char b = c->io.BasePort1 & 0xff;
1435 write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
1436 b = (c->io.BasePort1 >> 8) & 0xff;
1437 write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
1438 }
1439 if (req->Present & PRESENT_IOSIZE) {
1440 u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1;
1441 write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
1442 }
1443
1444 /* Configure I/O windows */
1445 if (c->state & CONFIG_IO_REQ) {
1446 iomap.speed = io_speed;
1447 for (i = 0; i < MAX_IO_WIN; i++)
1448 if (s->io[i].NumPorts != 0) {
1449 iomap.map = i;
1450 iomap.flags = MAP_ACTIVE;
1451 switch (s->io[i].Attributes & IO_DATA_PATH_WIDTH) {
1452 case IO_DATA_PATH_WIDTH_16:
1453 iomap.flags |= MAP_16BIT; break;
1454 case IO_DATA_PATH_WIDTH_AUTO:
1455 iomap.flags |= MAP_AUTOSZ; break;
1456 default:
1457 break;
1458 }
1459 iomap.start = s->io[i].BasePort;
1460 iomap.stop = iomap.start + s->io[i].NumPorts - 1;
1461 s->ops->set_io_map(s, &iomap);
1462 s->io[i].Config++;
1463 }
1464 }
1465
1466 c->state |= CONFIG_LOCKED;
1467 handle->state |= CLIENT_CONFIG_LOCKED;
1468 return CS_SUCCESS;
1469} /* request_configuration */
1470
1471/*======================================================================
1472
1473 Request_io() reserves ranges of port addresses for a socket.
1474 I have not implemented range sharing or alias addressing.
1475
1476======================================================================*/
1477
1478int pcmcia_request_io(client_handle_t handle, io_req_t *req)
1479{
1480 struct pcmcia_socket *s;
1481 config_t *c;
1482
1483 if (CHECK_HANDLE(handle))
1484 return CS_BAD_HANDLE;
1485 s = SOCKET(handle);
1486 if (!(s->state & SOCKET_PRESENT))
1487 return CS_NO_CARD;
1488
1489 if (handle->state & CLIENT_CARDBUS) {
1490#ifdef CONFIG_CARDBUS
1491 handle->state |= CLIENT_IO_REQ;
1492 return CS_SUCCESS;
1493#else
1494 return CS_UNSUPPORTED_FUNCTION;
1495#endif
1496 }
1497
1498 if (!req)
1499 return CS_UNSUPPORTED_MODE;
1500 c = CONFIG(handle);
1501 if (c->state & CONFIG_LOCKED)
1502 return CS_CONFIGURATION_LOCKED;
1503 if (c->state & CONFIG_IO_REQ)
1504 return CS_IN_USE;
1505 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))
1506 return CS_BAD_ATTRIBUTE;
1507 if ((req->NumPorts2 > 0) &&
1508 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)))
1509 return CS_BAD_ATTRIBUTE;
1510
1511 if (alloc_io_space(s, req->Attributes1, &req->BasePort1,
1512 req->NumPorts1, req->IOAddrLines))
1513 return CS_IN_USE;
1514
1515 if (req->NumPorts2) {
1516 if (alloc_io_space(s, req->Attributes2, &req->BasePort2,
1517 req->NumPorts2, req->IOAddrLines)) {
1518 release_io_space(s, req->BasePort1, req->NumPorts1);
1519 return CS_IN_USE;
1520 }
1521 }
1522
1523 c->io = *req;
1524 c->state |= CONFIG_IO_REQ;
1525 handle->state |= CLIENT_IO_REQ;
1526 return CS_SUCCESS;
1527} /* request_io */
1528
1529/*======================================================================
1530
1531 Request_irq() reserves an irq for this client.
1532
1533 Also, since Linux only reserves irq's when they are actually
1534 hooked, we don't guarantee that an irq will still be available
1535 when the configuration is locked. Now that I think about it,
1536 there might be a way to fix this using a dummy handler.
1537
1538======================================================================*/
1539
1540#ifdef CONFIG_PCMCIA_PROBE
1541static irqreturn_t test_action(int cpl, void *dev_id, struct pt_regs *regs)
1542{
1543 return IRQ_NONE;
1544}
1545#endif
1546
1547int pcmcia_request_irq(client_handle_t handle, irq_req_t *req)
1548{
1549 struct pcmcia_socket *s;
1550 config_t *c;
1551 int ret = CS_IN_USE, irq = 0;
1552 struct pcmcia_device *p_dev = handle_to_pdev(handle);
1553
1554 if (CHECK_HANDLE(handle))
1555 return CS_BAD_HANDLE;
1556 s = SOCKET(handle);
1557 if (!(s->state & SOCKET_PRESENT))
1558 return CS_NO_CARD;
1559 c = CONFIG(handle);
1560 if (c->state & CONFIG_LOCKED)
1561 return CS_CONFIGURATION_LOCKED;
1562 if (c->state & CONFIG_IRQ_REQ)
1563 return CS_IN_USE;
1564
1565#ifdef CONFIG_PCMCIA_PROBE
1566 if (s->irq.AssignedIRQ != 0) {
1567 /* If the interrupt is already assigned, it must be the same */
1568 irq = s->irq.AssignedIRQ;
1569 } else {
1570 int try;
1571 u32 mask = s->irq_mask;
1572 void *data = NULL;
1573
1574 for (try = 0; try < 64; try++) {
1575 irq = try % 32;
1576
1577 /* marked as available by driver, and not blocked by userspace? */
1578 if (!((mask >> irq) & 1))
1579 continue;
1580
1581 /* avoid an IRQ which is already used by a PCMCIA card */
1582 if ((try < 32) && pcmcia_used_irq[irq])
1583 continue;
1584
1585 /* register the correct driver, if possible, of check whether
1586 * registering a dummy handle works, i.e. if the IRQ isn't
1587 * marked as used by the kernel resource management core */
1588 ret = request_irq(irq,
1589 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action,
1590 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
1591 (s->functions > 1) ||
1592 (irq == s->pci_irq)) ? SA_SHIRQ : 0,
1593 p_dev->dev.bus_id,
1594 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data);
1595 if (!ret) {
1596 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
1597 free_irq(irq, data);
1598 break;
1599 }
1600 }
1601 }
1602#endif
1603 if (ret) {
1604 if (!s->pci_irq)
1605 return ret;
1606 irq = s->pci_irq;
1607 }
1608
1609 if (ret && req->Attributes & IRQ_HANDLE_PRESENT) {
1610 if (request_irq(irq, req->Handler,
1611 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
1612 (s->functions > 1) ||
1613 (irq == s->pci_irq)) ? SA_SHIRQ : 0,
1614 p_dev->dev.bus_id, req->Instance))
1615 return CS_IN_USE;
1616 }
1617
1618 c->irq.Attributes = req->Attributes;
1619 s->irq.AssignedIRQ = req->AssignedIRQ = irq;
1620 s->irq.Config++;
1621
1622 c->state |= CONFIG_IRQ_REQ;
1623 handle->state |= CLIENT_IRQ_REQ;
1624
1625#ifdef CONFIG_PCMCIA_PROBE
1626 pcmcia_used_irq[irq]++;
1627#endif
1628
1629 return CS_SUCCESS;
1630} /* pcmcia_request_irq */
1631
1632/*======================================================================
1633
1634 Request_window() establishes a mapping between card memory space
1635 and system memory space.
1636
1637======================================================================*/
1638
1639int pcmcia_request_window(client_handle_t *handle, win_req_t *req, window_handle_t *wh)
1640{
1641 struct pcmcia_socket *s;
1642 window_t *win;
1643 u_long align;
1644 int w;
1645
1646 if (CHECK_HANDLE(*handle))
1647 return CS_BAD_HANDLE;
1648 s = (*handle)->Socket;
1649 if (!(s->state & SOCKET_PRESENT))
1650 return CS_NO_CARD;
1651 if (req->Attributes & (WIN_PAGED | WIN_SHARED))
1652 return CS_BAD_ATTRIBUTE;
1653
1654 /* Window size defaults to smallest available */
1655 if (req->Size == 0)
1656 req->Size = s->map_size;
1657 align = (((s->features & SS_CAP_MEM_ALIGN) ||
1658 (req->Attributes & WIN_STRICT_ALIGN)) ?
1659 req->Size : s->map_size);
1660 if (req->Size & (s->map_size-1))
1661 return CS_BAD_SIZE;
1662 if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) ||
1663 (req->Base & (align-1)))
1664 return CS_BAD_BASE;
1665 if (req->Base)
1666 align = 0;
1667
1668 /* Allocate system memory window */
1669 for (w = 0; w < MAX_WIN; w++)
1670 if (!(s->state & SOCKET_WIN_REQ(w))) break;
1671 if (w == MAX_WIN)
1672 return CS_OUT_OF_RESOURCE;
1673
1674 win = &s->win[w];
1675 win->magic = WINDOW_MAGIC;
1676 win->index = w;
1677 win->handle = *handle;
1678 win->sock = s;
1679
1680 if (!(s->features & SS_CAP_STATIC_MAP)) {
1681 win->ctl.res = find_mem_region(req->Base, req->Size, align,
1682 (req->Attributes & WIN_MAP_BELOW_1MB), s);
1683 if (!win->ctl.res)
1684 return CS_IN_USE;
1685 }
1686 (*handle)->state |= CLIENT_WIN_REQ(w);
1687
1688 /* Configure the socket controller */
1689 win->ctl.map = w+1;
1690 win->ctl.flags = 0;
1691 win->ctl.speed = req->AccessSpeed;
1692 if (req->Attributes & WIN_MEMORY_TYPE)
1693 win->ctl.flags |= MAP_ATTRIB;
1694 if (req->Attributes & WIN_ENABLE)
1695 win->ctl.flags |= MAP_ACTIVE;
1696 if (req->Attributes & WIN_DATA_WIDTH_16)
1697 win->ctl.flags |= MAP_16BIT;
1698 if (req->Attributes & WIN_USE_WAIT)
1699 win->ctl.flags |= MAP_USE_WAIT;
1700 win->ctl.card_start = 0;
1701 if (s->ops->set_mem_map(s, &win->ctl) != 0)
1702 return CS_BAD_ARGS;
1703 s->state |= SOCKET_WIN_REQ(w);
1704
1705 /* Return window handle */
1706 if (s->features & SS_CAP_STATIC_MAP) {
1707 req->Base = win->ctl.static_start;
1708 } else {
1709 req->Base = win->ctl.res->start;
1710 }
1711 *wh = win;
1712
1713 return CS_SUCCESS;
1714} /* request_window */
1715
1716/*======================================================================
1717
1718 I'm not sure which "reset" function this is supposed to use,
1719 but for now, it uses the low-level interface's reset, not the
1720 CIS register.
1721
1722======================================================================*/
1723 744
1724int pccard_reset_card(struct pcmcia_socket *skt) 745int pccard_reset_card(struct pcmcia_socket *skt)
1725{ 746{
1726 int ret; 747 int ret;
1727 748
1728 cs_dbg(skt, 1, "resetting socket\n"); 749 cs_dbg(skt, 1, "resetting socket\n");
1729 750
1730 down(&skt->skt_sem); 751 down(&skt->skt_sem);
@@ -1757,17 +778,14 @@ int pccard_reset_card(struct pcmcia_socket *skt)
1757} /* reset_card */ 778} /* reset_card */
1758EXPORT_SYMBOL(pccard_reset_card); 779EXPORT_SYMBOL(pccard_reset_card);
1759 780
1760/*======================================================================
1761
1762 These shut down or wake up a socket. They are sort of user
1763 initiated versions of the APM suspend and resume actions.
1764
1765======================================================================*/
1766 781
782/* These shut down or wake up a socket. They are sort of user
783 * initiated versions of the APM suspend and resume actions.
784 */
1767int pcmcia_suspend_card(struct pcmcia_socket *skt) 785int pcmcia_suspend_card(struct pcmcia_socket *skt)
1768{ 786{
1769 int ret; 787 int ret;
1770 788
1771 cs_dbg(skt, 1, "suspending socket\n"); 789 cs_dbg(skt, 1, "suspending socket\n");
1772 790
1773 down(&skt->skt_sem); 791 down(&skt->skt_sem);
@@ -1786,6 +804,8 @@ int pcmcia_suspend_card(struct pcmcia_socket *skt)
1786 804
1787 return ret; 805 return ret;
1788} /* suspend_card */ 806} /* suspend_card */
807EXPORT_SYMBOL(pcmcia_suspend_card);
808
1789 809
1790int pcmcia_resume_card(struct pcmcia_socket *skt) 810int pcmcia_resume_card(struct pcmcia_socket *skt)
1791{ 811{
@@ -1809,13 +829,10 @@ int pcmcia_resume_card(struct pcmcia_socket *skt)
1809 829
1810 return ret; 830 return ret;
1811} /* resume_card */ 831} /* resume_card */
832EXPORT_SYMBOL(pcmcia_resume_card);
1812 833
1813/*======================================================================
1814
1815 These handle user requests to eject or insert a card.
1816
1817======================================================================*/
1818 834
835/* These handle user requests to eject or insert a card. */
1819int pcmcia_eject_card(struct pcmcia_socket *skt) 836int pcmcia_eject_card(struct pcmcia_socket *skt)
1820{ 837{
1821 int ret; 838 int ret;
@@ -1842,6 +859,8 @@ int pcmcia_eject_card(struct pcmcia_socket *skt)
1842 859
1843 return ret; 860 return ret;
1844} /* eject_card */ 861} /* eject_card */
862EXPORT_SYMBOL(pcmcia_eject_card);
863
1845 864
1846int pcmcia_insert_card(struct pcmcia_socket *skt) 865int pcmcia_insert_card(struct pcmcia_socket *skt)
1847{ 866{
@@ -1865,37 +884,38 @@ int pcmcia_insert_card(struct pcmcia_socket *skt)
1865 884
1866 return ret; 885 return ret;
1867} /* insert_card */ 886} /* insert_card */
887EXPORT_SYMBOL(pcmcia_insert_card);
1868 888
1869/*======================================================================
1870 889
1871 OS-specific module glue goes here 890static int pcmcia_socket_hotplug(struct class_device *dev, char **envp,
1872 891 int num_envp, char *buffer, int buffer_size)
1873======================================================================*/ 892{
1874/* in alpha order */ 893 struct pcmcia_socket *s = container_of(dev, struct pcmcia_socket, dev);
1875EXPORT_SYMBOL(pcmcia_eject_card); 894 int i = 0, length = 0;
1876EXPORT_SYMBOL(pcmcia_get_card_services_info); 895
1877EXPORT_SYMBOL(pcmcia_get_mem_page); 896 if (add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size,
1878EXPORT_SYMBOL(pcmcia_insert_card); 897 &length, "SOCKET_NO=%u", s->sock))
1879EXPORT_SYMBOL(pcmcia_map_mem_page); 898 return -ENOMEM;
1880EXPORT_SYMBOL(pcmcia_modify_configuration); 899
1881EXPORT_SYMBOL(pcmcia_release_configuration); 900 envp[i] = NULL;
1882EXPORT_SYMBOL(pcmcia_release_io); 901
1883EXPORT_SYMBOL(pcmcia_release_irq); 902 return 0;
1884EXPORT_SYMBOL(pcmcia_release_window); 903}
1885EXPORT_SYMBOL(pcmcia_replace_cis); 904
1886EXPORT_SYMBOL(pcmcia_request_configuration); 905
1887EXPORT_SYMBOL(pcmcia_request_io); 906static struct completion pcmcia_unload;
1888EXPORT_SYMBOL(pcmcia_request_irq); 907
1889EXPORT_SYMBOL(pcmcia_request_window); 908static void pcmcia_release_socket_class(struct class *data)
1890EXPORT_SYMBOL(pcmcia_resume_card); 909{
1891EXPORT_SYMBOL(pcmcia_suspend_card); 910 complete(&pcmcia_unload);
911}
1892 912
1893EXPORT_SYMBOL(dead_socket);
1894EXPORT_SYMBOL(pcmcia_parse_events);
1895 913
1896struct class pcmcia_socket_class = { 914struct class pcmcia_socket_class = {
1897 .name = "pcmcia_socket", 915 .name = "pcmcia_socket",
916 .hotplug = pcmcia_socket_hotplug,
1898 .release = pcmcia_release_socket, 917 .release = pcmcia_release_socket,
918 .class_release = pcmcia_release_socket_class,
1899}; 919};
1900EXPORT_SYMBOL(pcmcia_socket_class); 920EXPORT_SYMBOL(pcmcia_socket_class);
1901 921
@@ -1903,9 +923,8 @@ EXPORT_SYMBOL(pcmcia_socket_class);
1903static int __init init_pcmcia_cs(void) 923static int __init init_pcmcia_cs(void)
1904{ 924{
1905 int ret; 925 int ret;
1906 printk(KERN_INFO "%s\n", release);
1907 printk(KERN_INFO " %s\n", options);
1908 926
927 init_completion(&pcmcia_unload);
1909 ret = class_register(&pcmcia_socket_class); 928 ret = class_register(&pcmcia_socket_class);
1910 if (ret) 929 if (ret)
1911 return (ret); 930 return (ret);
@@ -1914,13 +933,12 @@ static int __init init_pcmcia_cs(void)
1914 933
1915static void __exit exit_pcmcia_cs(void) 934static void __exit exit_pcmcia_cs(void)
1916{ 935{
1917 printk(KERN_INFO "unloading Kernel Card Services\n"); 936 class_interface_unregister(&pccard_sysfs_interface);
1918 class_interface_unregister(&pccard_sysfs_interface); 937 class_unregister(&pcmcia_socket_class);
1919 class_unregister(&pcmcia_socket_class); 938
939 wait_for_completion(&pcmcia_unload);
1920} 940}
1921 941
1922subsys_initcall(init_pcmcia_cs); 942subsys_initcall(init_pcmcia_cs);
1923module_exit(exit_pcmcia_cs); 943module_exit(exit_pcmcia_cs);
1924 944
1925/*====================================================================*/
1926
diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h
index 7933a7db49d3..0b4c18edfa49 100644
--- a/drivers/pcmcia/cs_internal.h
+++ b/drivers/pcmcia/cs_internal.h
@@ -123,9 +123,9 @@ void cb_free(struct pcmcia_socket *s);
123int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, void *ptr); 123int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, void *ptr);
124 124
125/* In cistpl.c */ 125/* In cistpl.c */
126int read_cis_mem(struct pcmcia_socket *s, int attr, 126int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr,
127 u_int addr, u_int len, void *ptr); 127 u_int addr, u_int len, void *ptr);
128void write_cis_mem(struct pcmcia_socket *s, int attr, 128void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr,
129 u_int addr, u_int len, void *ptr); 129 u_int addr, u_int len, void *ptr);
130void release_cis_mem(struct pcmcia_socket *s); 130void release_cis_mem(struct pcmcia_socket *s);
131void destroy_cis_cache(struct pcmcia_socket *s); 131void destroy_cis_cache(struct pcmcia_socket *s);
@@ -134,13 +134,12 @@ int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t
134 134
135/* In rsrc_mgr */ 135/* In rsrc_mgr */
136void pcmcia_validate_mem(struct pcmcia_socket *s); 136void pcmcia_validate_mem(struct pcmcia_socket *s);
137struct resource *find_io_region(unsigned long base, int num, unsigned long align, 137struct resource *pcmcia_find_io_region(unsigned long base, int num, unsigned long align,
138 struct pcmcia_socket *s); 138 struct pcmcia_socket *s);
139int adjust_io_region(struct resource *res, unsigned long r_start, 139int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start,
140 unsigned long r_end, struct pcmcia_socket *s); 140 unsigned long r_end, struct pcmcia_socket *s);
141struct resource *find_mem_region(u_long base, u_long num, u_long align, 141struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
142 int low, struct pcmcia_socket *s); 142 int low, struct pcmcia_socket *s);
143int adjust_resource_info(client_handle_t handle, adjust_t *adj);
144void release_resource_db(struct pcmcia_socket *s); 143void release_resource_db(struct pcmcia_socket *s);
145 144
146/* In socket_sysfs.c */ 145/* In socket_sysfs.c */
@@ -159,7 +158,7 @@ int pccard_access_configuration_register(struct pcmcia_socket *s, unsigned int f
159struct pcmcia_callback{ 158struct pcmcia_callback{
160 struct module *owner; 159 struct module *owner;
161 int (*event) (struct pcmcia_socket *s, event_t event, int priority); 160 int (*event) (struct pcmcia_socket *s, event_t event, int priority);
162 int (*resources_done) (struct pcmcia_socket *s); 161 void (*requery) (struct pcmcia_socket *s);
163}; 162};
164 163
165int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c); 164int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 569e55feecfd..cabddd49f6ff 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -10,44 +10,29 @@
10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. 10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
11 * 11 *
12 * (C) 1999 David A. Hinds 12 * (C) 1999 David A. Hinds
13 * (C) 2003 - 2004 Dominik Brodowski 13 * (C) 2003 - 2005 Dominik Brodowski
14 */ 14 */
15 15
16#include <linux/config.h> 16#include <linux/config.h>
17#include <linux/kernel.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/moduleparam.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/major.h>
22#include <linux/string.h>
23#include <linux/errno.h> 20#include <linux/errno.h>
24#include <linux/slab.h>
25#include <linux/mm.h>
26#include <linux/fcntl.h>
27#include <linux/sched.h>
28#include <linux/smp_lock.h>
29#include <linux/timer.h>
30#include <linux/ioctl.h>
31#include <linux/proc_fs.h>
32#include <linux/poll.h>
33#include <linux/pci.h>
34#include <linux/list.h> 21#include <linux/list.h>
35#include <linux/delay.h> 22#include <linux/delay.h>
36#include <linux/kref.h>
37#include <linux/workqueue.h> 23#include <linux/workqueue.h>
38 24#include <linux/crc32.h>
39#include <asm/atomic.h> 25#include <linux/firmware.h>
40 26
41#define IN_CARD_SERVICES 27#define IN_CARD_SERVICES
42#include <pcmcia/version.h>
43#include <pcmcia/cs_types.h> 28#include <pcmcia/cs_types.h>
44#include <pcmcia/cs.h> 29#include <pcmcia/cs.h>
45#include <pcmcia/bulkmem.h>
46#include <pcmcia/cistpl.h> 30#include <pcmcia/cistpl.h>
47#include <pcmcia/ds.h> 31#include <pcmcia/ds.h>
48#include <pcmcia/ss.h> 32#include <pcmcia/ss.h>
49 33
50#include "cs_internal.h" 34#include "cs_internal.h"
35#include "ds_internal.h"
51 36
52/*====================================================================*/ 37/*====================================================================*/
53 38
@@ -70,49 +55,9 @@ module_param_named(pc_debug, ds_pc_debug, int, 0644);
70#define ds_dbg(lvl, fmt, arg...) do { } while (0) 55#define ds_dbg(lvl, fmt, arg...) do { } while (0)
71#endif 56#endif
72 57
73/*====================================================================*/ 58spinlock_t pcmcia_dev_list_lock;
74 59
75/* Device user information */ 60static int unbind_request(struct pcmcia_socket *s);
76#define MAX_EVENTS 32
77#define USER_MAGIC 0x7ea4
78#define CHECK_USER(u) \
79 (((u) == NULL) || ((u)->user_magic != USER_MAGIC))
80typedef struct user_info_t {
81 u_int user_magic;
82 int event_head, event_tail;
83 event_t event[MAX_EVENTS];
84 struct user_info_t *next;
85 struct pcmcia_bus_socket *socket;
86} user_info_t;
87
88/* Socket state information */
89struct pcmcia_bus_socket {
90 struct kref refcount;
91 struct pcmcia_callback callback;
92 int state;
93 user_info_t *user;
94 wait_queue_head_t queue;
95 struct pcmcia_socket *parent;
96
97 /* the PCMCIA devices connected to this socket (normally one, more
98 * for multifunction devices: */
99 struct list_head devices_list;
100 u8 device_count; /* the number of devices, used
101 * only internally and subject
102 * to incorrectness and change */
103};
104static spinlock_t pcmcia_dev_list_lock;
105
106#define DS_SOCKET_PRESENT 0x01
107#define DS_SOCKET_BUSY 0x02
108#define DS_SOCKET_REMOVAL_PENDING 0x10
109#define DS_SOCKET_DEAD 0x80
110
111/*====================================================================*/
112
113static int major_dev = -1;
114
115static int unbind_request(struct pcmcia_bus_socket *s);
116 61
117/*====================================================================*/ 62/*====================================================================*/
118 63
@@ -213,7 +158,7 @@ static const lookup_t service_table[] = {
213}; 158};
214 159
215 160
216int pcmcia_report_error(client_handle_t handle, error_info_t *err) 161static int pcmcia_report_error(client_handle_t handle, error_info_t *err)
217{ 162{
218 int i; 163 int i;
219 char *serv; 164 char *serv;
@@ -243,7 +188,6 @@ int pcmcia_report_error(client_handle_t handle, error_info_t *err)
243 188
244 return CS_SUCCESS; 189 return CS_SUCCESS;
245} /* report_error */ 190} /* report_error */
246EXPORT_SYMBOL(pcmcia_report_error);
247 191
248/* end of code which was in cs.c before */ 192/* end of code which was in cs.c before */
249 193
@@ -256,29 +200,101 @@ void cs_error(client_handle_t handle, int func, int ret)
256} 200}
257EXPORT_SYMBOL(cs_error); 201EXPORT_SYMBOL(cs_error);
258 202
259/*======================================================================*/
260
261static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info);
262static struct pcmcia_bus_socket * get_socket_info_by_nr(unsigned int nr);
263 203
264static void pcmcia_release_bus_socket(struct kref *refcount) 204static void pcmcia_check_driver(struct pcmcia_driver *p_drv)
265{ 205{
266 struct pcmcia_bus_socket *s = container_of(refcount, struct pcmcia_bus_socket, refcount); 206 struct pcmcia_device_id *did = p_drv->id_table;
267 pcmcia_put_socket(s->parent); 207 unsigned int i;
268 kfree(s); 208 u32 hash;
209
210 while (did && did->match_flags) {
211 for (i=0; i<4; i++) {
212 if (!did->prod_id[i])
213 continue;
214
215 hash = crc32(0, did->prod_id[i], strlen(did->prod_id[i]));
216 if (hash == did->prod_id_hash[i])
217 continue;
218
219 printk(KERN_DEBUG "pcmcia: %s: invalid hash for "
220 "product string \"%s\": is 0x%x, should "
221 "be 0x%x\n", p_drv->drv.name, did->prod_id[i],
222 did->prod_id_hash[i], hash);
223 printk(KERN_DEBUG "pcmcia: see "
224 "Documentation/pcmcia/devicetable.txt for "
225 "details\n");
226 }
227 did++;
228 }
229
230 return;
269} 231}
270 232
271static void pcmcia_put_bus_socket(struct pcmcia_bus_socket *s) 233
234#ifdef CONFIG_PCMCIA_LOAD_CIS
235
236/**
237 * pcmcia_load_firmware - load CIS from userspace if device-provided is broken
238 * @dev - the pcmcia device which needs a CIS override
239 * @filename - requested filename in /lib/firmware/cis/
240 *
241 * This uses the in-kernel firmware loading mechanism to use a "fake CIS" if
242 * the one provided by the card is broken. The firmware files reside in
243 * /lib/firmware/cis/ in userspace.
244 */
245static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
272{ 246{
273 kref_put(&s->refcount, pcmcia_release_bus_socket); 247 struct pcmcia_socket *s = dev->socket;
248 const struct firmware *fw;
249 char path[20];
250 int ret=-ENOMEM;
251 cisdump_t *cis;
252
253 if (!filename)
254 return -EINVAL;
255
256 ds_dbg(1, "trying to load firmware %s\n", filename);
257
258 if (strlen(filename) > 14)
259 return -EINVAL;
260
261 snprintf(path, 20, "%s", filename);
262
263 if (request_firmware(&fw, path, &dev->dev) == 0) {
264 if (fw->size >= CISTPL_MAX_CIS_SIZE)
265 goto release;
266
267 cis = kmalloc(sizeof(cisdump_t), GFP_KERNEL);
268 if (!cis)
269 goto release;
270
271 memset(cis, 0, sizeof(cisdump_t));
272
273 cis->Length = fw->size + 1;
274 memcpy(cis->Data, fw->data, fw->size);
275
276 if (!pcmcia_replace_cis(s, cis))
277 ret = 0;
278 }
279 release:
280 release_firmware(fw);
281
282 return (ret);
274} 283}
275 284
276static struct pcmcia_bus_socket *pcmcia_get_bus_socket(struct pcmcia_bus_socket *s) 285#else /* !CONFIG_PCMCIA_LOAD_CIS */
286
287static inline int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
277{ 288{
278 kref_get(&s->refcount); 289 return -ENODEV;
279 return (s);
280} 290}
281 291
292#endif
293
294
295/*======================================================================*/
296
297
282/** 298/**
283 * pcmcia_register_driver - register a PCMCIA driver with the bus core 299 * pcmcia_register_driver - register a PCMCIA driver with the bus core
284 * 300 *
@@ -292,6 +308,8 @@ int pcmcia_register_driver(struct pcmcia_driver *driver)
292 if (!driver) 308 if (!driver)
293 return -EINVAL; 309 return -EINVAL;
294 310
311 pcmcia_check_driver(driver);
312
295 /* initialize common fields */ 313 /* initialize common fields */
296 driver->drv.bus = &pcmcia_bus_type; 314 driver->drv.bus = &pcmcia_bus_type;
297 driver->drv.owner = driver->owner; 315 driver->drv.owner = driver->owner;
@@ -311,42 +329,10 @@ void pcmcia_unregister_driver(struct pcmcia_driver *driver)
311} 329}
312EXPORT_SYMBOL(pcmcia_unregister_driver); 330EXPORT_SYMBOL(pcmcia_unregister_driver);
313 331
314#ifdef CONFIG_PROC_FS
315static struct proc_dir_entry *proc_pccard = NULL;
316
317static int proc_read_drivers_callback(struct device_driver *driver, void *d)
318{
319 char **p = d;
320 struct pcmcia_driver *p_drv = container_of(driver,
321 struct pcmcia_driver, drv);
322
323 *p += sprintf(*p, "%-24.24s 1 %d\n", p_drv->drv.name,
324#ifdef CONFIG_MODULE_UNLOAD
325 (p_drv->owner) ? module_refcount(p_drv->owner) : 1
326#else
327 1
328#endif
329 );
330 d = (void *) p;
331
332 return 0;
333}
334
335static int proc_read_drivers(char *buf, char **start, off_t pos,
336 int count, int *eof, void *data)
337{
338 char *p = buf;
339
340 bus_for_each_drv(&pcmcia_bus_type, NULL,
341 (void *) &p, proc_read_drivers_callback);
342
343 return (p - buf);
344}
345#endif
346 332
347/* pcmcia_device handling */ 333/* pcmcia_device handling */
348 334
349static struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev) 335struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev)
350{ 336{
351 struct device *tmp_dev; 337 struct device *tmp_dev;
352 tmp_dev = get_device(&p_dev->dev); 338 tmp_dev = get_device(&p_dev->dev);
@@ -355,7 +341,7 @@ static struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev)
355 return to_pcmcia_dev(tmp_dev); 341 return to_pcmcia_dev(tmp_dev);
356} 342}
357 343
358static void pcmcia_put_dev(struct pcmcia_device *p_dev) 344void pcmcia_put_dev(struct pcmcia_device *p_dev)
359{ 345{
360 if (p_dev) 346 if (p_dev)
361 put_device(&p_dev->dev); 347 put_device(&p_dev->dev);
@@ -365,7 +351,7 @@ static void pcmcia_release_dev(struct device *dev)
365{ 351{
366 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 352 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
367 ds_dbg(1, "releasing dev %p\n", p_dev); 353 ds_dbg(1, "releasing dev %p\n", p_dev);
368 pcmcia_put_bus_socket(p_dev->socket->pcmcia); 354 pcmcia_put_socket(p_dev->socket);
369 kfree(p_dev); 355 kfree(p_dev);
370} 356}
371 357
@@ -500,34 +486,38 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
500 */ 486 */
501static DECLARE_MUTEX(device_add_lock); 487static DECLARE_MUTEX(device_add_lock);
502 488
503static struct pcmcia_device * pcmcia_device_add(struct pcmcia_bus_socket *s, unsigned int function) 489struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function)
504{ 490{
505 struct pcmcia_device *p_dev; 491 struct pcmcia_device *p_dev;
506 unsigned long flags; 492 unsigned long flags;
507 493
508 s = pcmcia_get_bus_socket(s); 494 s = pcmcia_get_socket(s);
509 if (!s) 495 if (!s)
510 return NULL; 496 return NULL;
511 497
512 down(&device_add_lock); 498 down(&device_add_lock);
513 499
500 /* max of 2 devices per card */
501 if (s->device_count == 2)
502 goto err_put;
503
514 p_dev = kmalloc(sizeof(struct pcmcia_device), GFP_KERNEL); 504 p_dev = kmalloc(sizeof(struct pcmcia_device), GFP_KERNEL);
515 if (!p_dev) 505 if (!p_dev)
516 goto err_put; 506 goto err_put;
517 memset(p_dev, 0, sizeof(struct pcmcia_device)); 507 memset(p_dev, 0, sizeof(struct pcmcia_device));
518 508
519 p_dev->socket = s->parent; 509 p_dev->socket = s;
520 p_dev->device_no = (s->device_count++); 510 p_dev->device_no = (s->device_count++);
521 p_dev->func = function; 511 p_dev->func = function;
522 512
523 p_dev->dev.bus = &pcmcia_bus_type; 513 p_dev->dev.bus = &pcmcia_bus_type;
524 p_dev->dev.parent = s->parent->dev.dev; 514 p_dev->dev.parent = s->dev.dev;
525 p_dev->dev.release = pcmcia_release_dev; 515 p_dev->dev.release = pcmcia_release_dev;
526 sprintf (p_dev->dev.bus_id, "%d.%d", p_dev->socket->sock, p_dev->device_no); 516 sprintf (p_dev->dev.bus_id, "%d.%d", p_dev->socket->sock, p_dev->device_no);
527 517
528 /* compat */ 518 /* compat */
529 p_dev->client.client_magic = CLIENT_MAGIC; 519 p_dev->client.client_magic = CLIENT_MAGIC;
530 p_dev->client.Socket = s->parent; 520 p_dev->client.Socket = s;
531 p_dev->client.Function = function; 521 p_dev->client.Function = function;
532 p_dev->client.state = CLIENT_UNBOUND; 522 p_dev->client.state = CLIENT_UNBOUND;
533 523
@@ -536,6 +526,8 @@ static struct pcmcia_device * pcmcia_device_add(struct pcmcia_bus_socket *s, uns
536 list_add_tail(&p_dev->socket_device_list, &s->devices_list); 526 list_add_tail(&p_dev->socket_device_list, &s->devices_list);
537 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 527 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
538 528
529 pcmcia_device_query(p_dev);
530
539 if (device_register(&p_dev->dev)) { 531 if (device_register(&p_dev->dev)) {
540 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 532 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
541 list_del(&p_dev->socket_device_list); 533 list_del(&p_dev->socket_device_list);
@@ -553,7 +545,7 @@ static struct pcmcia_device * pcmcia_device_add(struct pcmcia_bus_socket *s, uns
553 s->device_count--; 545 s->device_count--;
554 err_put: 546 err_put:
555 up(&device_add_lock); 547 up(&device_add_lock);
556 pcmcia_put_bus_socket(s); 548 pcmcia_put_socket(s);
557 549
558 return NULL; 550 return NULL;
559} 551}
@@ -584,23 +576,252 @@ static int pcmcia_card_add(struct pcmcia_socket *s)
584 /* this doesn't handle multifunction devices on one pcmcia function 576 /* this doesn't handle multifunction devices on one pcmcia function
585 * yet. */ 577 * yet. */
586 for (i=0; i < no_funcs; i++) 578 for (i=0; i < no_funcs; i++)
587 pcmcia_device_add(s->pcmcia, i); 579 pcmcia_device_add(s, i);
588 580
589 return (ret); 581 return (ret);
590} 582}
591 583
592 584
585static void pcmcia_delayed_add_pseudo_device(void *data)
586{
587 struct pcmcia_socket *s = data;
588 pcmcia_device_add(s, 0);
589 s->pcmcia_state.device_add_pending = 0;
590}
591
592static inline void pcmcia_add_pseudo_device(struct pcmcia_socket *s)
593{
594 if (!s->pcmcia_state.device_add_pending) {
595 schedule_work(&s->device_add);
596 s->pcmcia_state.device_add_pending = 1;
597 }
598 return;
599}
600
601static int pcmcia_requery(struct device *dev, void * _data)
602{
603 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
604 if (!p_dev->dev.driver)
605 pcmcia_device_query(p_dev);
606
607 return 0;
608}
609
610static void pcmcia_bus_rescan(struct pcmcia_socket *skt)
611{
612 int no_devices=0;
613 unsigned long flags;
614
615 /* must be called with skt_sem held */
616 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
617 if (list_empty(&skt->devices_list))
618 no_devices=1;
619 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
620
621 /* if no devices were added for this socket yet because of
622 * missing resource information or other trouble, we need to
623 * do this now. */
624 if (no_devices) {
625 int ret = pcmcia_card_add(skt);
626 if (ret)
627 return;
628 }
629
630 /* some device information might have changed because of a CIS
631 * update or because we can finally read it correctly... so
632 * determine it again, overwriting old values if necessary. */
633 bus_for_each_dev(&pcmcia_bus_type, NULL, NULL, pcmcia_requery);
634
635 /* we re-scan all devices, not just the ones connected to this
636 * socket. This does not matter, though. */
637 bus_rescan_devices(&pcmcia_bus_type);
638}
639
640static inline int pcmcia_devmatch(struct pcmcia_device *dev,
641 struct pcmcia_device_id *did)
642{
643 if (did->match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID) {
644 if ((!dev->has_manf_id) || (dev->manf_id != did->manf_id))
645 return 0;
646 }
647
648 if (did->match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID) {
649 if ((!dev->has_card_id) || (dev->card_id != did->card_id))
650 return 0;
651 }
652
653 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION) {
654 if (dev->func != did->function)
655 return 0;
656 }
657
658 if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1) {
659 if (!dev->prod_id[0])
660 return 0;
661 if (strcmp(did->prod_id[0], dev->prod_id[0]))
662 return 0;
663 }
664
665 if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2) {
666 if (!dev->prod_id[1])
667 return 0;
668 if (strcmp(did->prod_id[1], dev->prod_id[1]))
669 return 0;
670 }
671
672 if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3) {
673 if (!dev->prod_id[2])
674 return 0;
675 if (strcmp(did->prod_id[2], dev->prod_id[2]))
676 return 0;
677 }
678
679 if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4) {
680 if (!dev->prod_id[3])
681 return 0;
682 if (strcmp(did->prod_id[3], dev->prod_id[3]))
683 return 0;
684 }
685
686 if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) {
687 /* handle pseudo multifunction devices:
688 * there are at most two pseudo multifunction devices.
689 * if we're matching against the first, schedule a
690 * call which will then check whether there are two
691 * pseudo devices, and if not, add the second one.
692 */
693 if (dev->device_no == 0)
694 pcmcia_add_pseudo_device(dev->socket);
695
696 if (dev->device_no != did->device_no)
697 return 0;
698 }
699
700 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) {
701 if ((!dev->has_func_id) || (dev->func_id != did->func_id))
702 return 0;
703
704 /* if this is a pseudo-multi-function device,
705 * we need explicit matches */
706 if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO)
707 return 0;
708 if (dev->device_no)
709 return 0;
710
711 /* also, FUNC_ID matching needs to be activated by userspace
712 * after it has re-checked that there is no possible module
713 * with a prod_id/manf_id/card_id match.
714 */
715 if (!dev->allow_func_id_match)
716 return 0;
717 }
718
719 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) {
720 if (!dev->socket->fake_cis)
721 pcmcia_load_firmware(dev, did->cisfile);
722
723 if (!dev->socket->fake_cis)
724 return 0;
725 }
726
727 if (did->match_flags & PCMCIA_DEV_ID_MATCH_ANONYMOUS) {
728 int i;
729 for (i=0; i<4; i++)
730 if (dev->prod_id[i])
731 return 0;
732 if (dev->has_manf_id || dev->has_card_id || dev->has_func_id)
733 return 0;
734 }
735
736 dev->dev.driver_data = (void *) did;
737
738 return 1;
739}
740
741
593static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) { 742static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) {
594 struct pcmcia_device * p_dev = to_pcmcia_dev(dev); 743 struct pcmcia_device * p_dev = to_pcmcia_dev(dev);
595 struct pcmcia_driver * p_drv = to_pcmcia_drv(drv); 744 struct pcmcia_driver * p_drv = to_pcmcia_drv(drv);
745 struct pcmcia_device_id *did = p_drv->id_table;
596 746
597 /* matching by cardmgr */ 747 /* matching by cardmgr */
598 if (p_dev->cardmgr == p_drv) 748 if (p_dev->cardmgr == p_drv)
599 return 1; 749 return 1;
600 750
751 while (did && did->match_flags) {
752 if (pcmcia_devmatch(p_dev, did))
753 return 1;
754 did++;
755 }
756
601 return 0; 757 return 0;
602} 758}
603 759
760#ifdef CONFIG_HOTPLUG
761
762static int pcmcia_bus_hotplug(struct device *dev, char **envp, int num_envp,
763 char *buffer, int buffer_size)
764{
765 struct pcmcia_device *p_dev;
766 int i, length = 0;
767 u32 hash[4] = { 0, 0, 0, 0};
768
769 if (!dev)
770 return -ENODEV;
771
772 p_dev = to_pcmcia_dev(dev);
773
774 /* calculate hashes */
775 for (i=0; i<4; i++) {
776 if (!p_dev->prod_id[i])
777 continue;
778 hash[i] = crc32(0, p_dev->prod_id[i], strlen(p_dev->prod_id[i]));
779 }
780
781 i = 0;
782
783 if (add_hotplug_env_var(envp, num_envp, &i,
784 buffer, buffer_size, &length,
785 "SOCKET_NO=%u",
786 p_dev->socket->sock))
787 return -ENOMEM;
788
789 if (add_hotplug_env_var(envp, num_envp, &i,
790 buffer, buffer_size, &length,
791 "DEVICE_NO=%02X",
792 p_dev->device_no))
793 return -ENOMEM;
794
795 if (add_hotplug_env_var(envp, num_envp, &i,
796 buffer, buffer_size, &length,
797 "MODALIAS=pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02X"
798 "pa%08Xpb%08Xpc%08Xpd%08X",
799 p_dev->has_manf_id ? p_dev->manf_id : 0,
800 p_dev->has_card_id ? p_dev->card_id : 0,
801 p_dev->has_func_id ? p_dev->func_id : 0,
802 p_dev->func,
803 p_dev->device_no,
804 hash[0],
805 hash[1],
806 hash[2],
807 hash[3]))
808 return -ENOMEM;
809
810 envp[i] = NULL;
811
812 return 0;
813}
814
815#else
816
817static int pcmcia_bus_hotplug(struct device *dev, char **envp, int num_envp,
818 char *buffer, int buffer_size)
819{
820 return -ENODEV;
821}
822
823#endif
824
604/************************ per-device sysfs output ***************************/ 825/************************ per-device sysfs output ***************************/
605 826
606#define pcmcia_device_attr(field, test, format) \ 827#define pcmcia_device_attr(field, test, format) \
@@ -626,6 +847,43 @@ pcmcia_device_stringattr(prod_id2, prod_id[1]);
626pcmcia_device_stringattr(prod_id3, prod_id[2]); 847pcmcia_device_stringattr(prod_id3, prod_id[2]);
627pcmcia_device_stringattr(prod_id4, prod_id[3]); 848pcmcia_device_stringattr(prod_id4, prod_id[3]);
628 849
850static ssize_t modalias_show(struct device *dev, char *buf)
851{
852 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
853 int i;
854 u32 hash[4] = { 0, 0, 0, 0};
855
856 /* calculate hashes */
857 for (i=0; i<4; i++) {
858 if (!p_dev->prod_id[i])
859 continue;
860 hash[i] = crc32(0,p_dev->prod_id[i],strlen(p_dev->prod_id[i]));
861 }
862 return sprintf(buf, "pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02X"
863 "pa%08Xpb%08Xpc%08Xpd%08X\n",
864 p_dev->has_manf_id ? p_dev->manf_id : 0,
865 p_dev->has_card_id ? p_dev->card_id : 0,
866 p_dev->has_func_id ? p_dev->func_id : 0,
867 p_dev->func, p_dev->device_no,
868 hash[0], hash[1], hash[2], hash[3]);
869}
870
871static ssize_t pcmcia_store_allow_func_id_match(struct device *dev,
872 struct device_attribute *attr, const char *buf, size_t count)
873{
874 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
875 if (!count)
876 return -EINVAL;
877
878 down(&p_dev->socket->skt_sem);
879 p_dev->allow_func_id_match = 1;
880 up(&p_dev->socket->skt_sem);
881
882 bus_rescan_devices(&pcmcia_bus_type);
883
884 return count;
885}
886
629static struct device_attribute pcmcia_dev_attrs[] = { 887static struct device_attribute pcmcia_dev_attrs[] = {
630 __ATTR(function, 0444, func_show, NULL), 888 __ATTR(function, 0444, func_show, NULL),
631 __ATTR_RO(func_id), 889 __ATTR_RO(func_id),
@@ -635,46 +893,14 @@ static struct device_attribute pcmcia_dev_attrs[] = {
635 __ATTR_RO(prod_id2), 893 __ATTR_RO(prod_id2),
636 __ATTR_RO(prod_id3), 894 __ATTR_RO(prod_id3),
637 __ATTR_RO(prod_id4), 895 __ATTR_RO(prod_id4),
896 __ATTR_RO(modalias),
897 __ATTR(allow_func_id_match, 0200, NULL, pcmcia_store_allow_func_id_match),
638 __ATTR_NULL, 898 __ATTR_NULL,
639}; 899};
640 900
641 901
642/*====================================================================== 902/*======================================================================
643 903
644 These manage a ring buffer of events pending for one user process
645
646======================================================================*/
647
648static int queue_empty(user_info_t *user)
649{
650 return (user->event_head == user->event_tail);
651}
652
653static event_t get_queued_event(user_info_t *user)
654{
655 user->event_tail = (user->event_tail+1) % MAX_EVENTS;
656 return user->event[user->event_tail];
657}
658
659static void queue_event(user_info_t *user, event_t event)
660{
661 user->event_head = (user->event_head+1) % MAX_EVENTS;
662 if (user->event_head == user->event_tail)
663 user->event_tail = (user->event_tail+1) % MAX_EVENTS;
664 user->event[user->event_head] = event;
665}
666
667static void handle_event(struct pcmcia_bus_socket *s, event_t event)
668{
669 user_info_t *user;
670 for (user = s->user; user; user = user->next)
671 queue_event(user, event);
672 wake_up_interruptible(&s->queue);
673}
674
675
676/*======================================================================
677
678 The card status event handler. 904 The card status event handler.
679 905
680======================================================================*/ 906======================================================================*/
@@ -706,21 +932,13 @@ static int send_event_callback(struct device *dev, void * _data)
706 932
707static int send_event(struct pcmcia_socket *s, event_t event, int priority) 933static int send_event(struct pcmcia_socket *s, event_t event, int priority)
708{ 934{
709 int ret = 0;
710 struct send_event_data private; 935 struct send_event_data private;
711 struct pcmcia_bus_socket *skt = pcmcia_get_bus_socket(s->pcmcia);
712
713 if (!skt)
714 return 0;
715 936
716 private.skt = s; 937 private.skt = s;
717 private.event = event; 938 private.event = event;
718 private.priority = priority; 939 private.priority = priority;
719 940
720 ret = bus_for_each_dev(&pcmcia_bus_type, NULL, &private, send_event_callback); 941 return bus_for_each_dev(&pcmcia_bus_type, NULL, &private, send_event_callback);
721
722 pcmcia_put_bus_socket(skt);
723 return ret;
724} /* send_event */ 942} /* send_event */
725 943
726 944
@@ -731,25 +949,25 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority)
731 949
732static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) 950static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
733{ 951{
734 struct pcmcia_bus_socket *s = skt->pcmcia; 952 struct pcmcia_socket *s = pcmcia_get_socket(skt);
735 int ret = 0; 953 int ret = 0;
736 954
737 ds_dbg(1, "ds_event(0x%06x, %d, 0x%p)\n", 955 ds_dbg(1, "ds_event(0x%06x, %d, 0x%p)\n",
738 event, priority, s); 956 event, priority, skt);
739 957
740 switch (event) { 958 switch (event) {
741 959
742 case CS_EVENT_CARD_REMOVAL: 960 case CS_EVENT_CARD_REMOVAL:
743 s->state &= ~DS_SOCKET_PRESENT; 961 s->pcmcia_state.present = 0;
744 send_event(skt, event, priority); 962 send_event(skt, event, priority);
745 unbind_request(s); 963 unbind_request(skt);
746 handle_event(s, event); 964 handle_event(skt, event);
747 break; 965 break;
748 966
749 case CS_EVENT_CARD_INSERTION: 967 case CS_EVENT_CARD_INSERTION:
750 s->state |= DS_SOCKET_PRESENT; 968 s->pcmcia_state.present = 1;
751 pcmcia_card_add(skt); 969 pcmcia_card_add(skt);
752 handle_event(s, event); 970 handle_event(skt, event);
753 break; 971 break;
754 972
755 case CS_EVENT_EJECTION_REQUEST: 973 case CS_EVENT_EJECTION_REQUEST:
@@ -757,137 +975,22 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
757 break; 975 break;
758 976
759 default: 977 default:
760 handle_event(s, event); 978 handle_event(skt, event);
761 send_event(skt, event, priority); 979 send_event(skt, event, priority);
762 break; 980 break;
763 } 981 }
764 982
983 pcmcia_put_socket(s);
984
765 return 0; 985 return 0;
766} /* ds_event */ 986} /* ds_event */
767 987
768 988
769/*======================================================================
770
771 bind_request() and bind_device() are merged by now. Register_client()
772 is called right at the end of bind_request(), during the driver's
773 ->attach() call. Individual descriptions:
774
775 bind_request() connects a socket to a particular client driver.
776 It looks up the specified device ID in the list of registered
777 drivers, binds it to the socket, and tries to create an instance
778 of the device. unbind_request() deletes a driver instance.
779
780 Bind_device() associates a device driver with a particular socket.
781 It is normally called by Driver Services after it has identified
782 a newly inserted card. An instance of that driver will then be
783 eligible to register as a client of this socket.
784
785 Register_client() uses the dev_info_t handle to match the
786 caller with a socket. The driver must have already been bound
787 to a socket with bind_device() -- in fact, bind_device()
788 allocates the client structure that will be used.
789
790======================================================================*/
791
792static int bind_request(struct pcmcia_bus_socket *s, bind_info_t *bind_info)
793{
794 struct pcmcia_driver *p_drv;
795 struct pcmcia_device *p_dev;
796 int ret = 0;
797 unsigned long flags;
798
799 s = pcmcia_get_bus_socket(s);
800 if (!s)
801 return -EINVAL;
802
803 ds_dbg(2, "bind_request(%d, '%s')\n", s->parent->sock,
804 (char *)bind_info->dev_info);
805
806 p_drv = get_pcmcia_driver(&bind_info->dev_info);
807 if (!p_drv) {
808 ret = -EINVAL;
809 goto err_put;
810 }
811
812 if (!try_module_get(p_drv->owner)) {
813 ret = -EINVAL;
814 goto err_put_driver;
815 }
816
817 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
818 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
819 if (p_dev->func == bind_info->function) {
820 if ((p_dev->dev.driver == &p_drv->drv)) {
821 if (p_dev->cardmgr) {
822 /* if there's already a device
823 * registered, and it was registered
824 * by userspace before, we need to
825 * return the "instance". */
826 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
827 bind_info->instance = p_dev->instance;
828 ret = -EBUSY;
829 goto err_put_module;
830 } else {
831 /* the correct driver managed to bind
832 * itself magically to the correct
833 * device. */
834 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
835 p_dev->cardmgr = p_drv;
836 ret = 0;
837 goto err_put_module;
838 }
839 } else if (!p_dev->dev.driver) {
840 /* there's already a device available where
841 * no device has been bound to yet. So we don't
842 * need to register a device! */
843 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
844 goto rescan;
845 }
846 }
847 }
848 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
849
850 p_dev = pcmcia_device_add(s, bind_info->function);
851 if (!p_dev) {
852 ret = -EIO;
853 goto err_put_module;
854 }
855
856rescan:
857 p_dev->cardmgr = p_drv;
858
859 pcmcia_device_query(p_dev);
860
861 /*
862 * Prevent this racing with a card insertion.
863 */
864 down(&s->parent->skt_sem);
865 bus_rescan_devices(&pcmcia_bus_type);
866 up(&s->parent->skt_sem);
867
868 /* check whether the driver indeed matched. I don't care if this
869 * is racy or not, because it can only happen on cardmgr access
870 * paths...
871 */
872 if (!(p_dev->dev.driver == &p_drv->drv))
873 p_dev->cardmgr = NULL;
874
875 err_put_module:
876 module_put(p_drv->owner);
877 err_put_driver:
878 put_driver(&p_drv->drv);
879 err_put:
880 pcmcia_put_bus_socket(s);
881
882 return (ret);
883} /* bind_request */
884
885 989
886int pcmcia_register_client(client_handle_t *handle, client_reg_t *req) 990int pcmcia_register_client(client_handle_t *handle, client_reg_t *req)
887{ 991{
888 client_t *client = NULL; 992 client_t *client = NULL;
889 struct pcmcia_socket *s; 993 struct pcmcia_socket *s = NULL;
890 struct pcmcia_bus_socket *skt = NULL;
891 struct pcmcia_device *p_dev = NULL; 994 struct pcmcia_device *p_dev = NULL;
892 995
893 /* Look for unbound client with matching dev_info */ 996 /* Look for unbound client with matching dev_info */
@@ -898,14 +1001,11 @@ int pcmcia_register_client(client_handle_t *handle, client_reg_t *req)
898 if (s->state & SOCKET_CARDBUS) 1001 if (s->state & SOCKET_CARDBUS)
899 continue; 1002 continue;
900 1003
901 skt = s->pcmcia; 1004 s = pcmcia_get_socket(s);
902 if (!skt) 1005 if (!s)
903 continue;
904 skt = pcmcia_get_bus_socket(skt);
905 if (!skt)
906 continue; 1006 continue;
907 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 1007 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
908 list_for_each_entry(p_dev, &skt->devices_list, socket_device_list) { 1008 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
909 struct pcmcia_driver *p_drv; 1009 struct pcmcia_driver *p_drv;
910 p_dev = pcmcia_get_dev(p_dev); 1010 p_dev = pcmcia_get_dev(p_dev);
911 if (!p_dev) 1011 if (!p_dev)
@@ -924,14 +1024,14 @@ int pcmcia_register_client(client_handle_t *handle, client_reg_t *req)
924 pcmcia_put_dev(p_dev); 1024 pcmcia_put_dev(p_dev);
925 } 1025 }
926 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 1026 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
927 pcmcia_put_bus_socket(skt); 1027 pcmcia_put_socket(s);
928 } 1028 }
929 found: 1029 found:
930 up_read(&pcmcia_socket_list_rwsem); 1030 up_read(&pcmcia_socket_list_rwsem);
931 if (!p_dev || !client) 1031 if (!p_dev || !client)
932 return -ENODEV; 1032 return -ENODEV;
933 1033
934 pcmcia_put_bus_socket(skt); /* safe, as we already hold a reference from bind_device */ 1034 pcmcia_put_socket(s); /* safe, as we already hold a reference from bind_device */
935 1035
936 *handle = client; 1036 *handle = client;
937 client->state &= ~CLIENT_UNBOUND; 1037 client->state &= ~CLIENT_UNBOUND;
@@ -978,106 +1078,15 @@ int pcmcia_register_client(client_handle_t *handle, client_reg_t *req)
978EXPORT_SYMBOL(pcmcia_register_client); 1078EXPORT_SYMBOL(pcmcia_register_client);
979 1079
980 1080
981/*====================================================================*/
982
983extern struct pci_bus *pcmcia_lookup_bus(struct pcmcia_socket *s);
984
985static int get_device_info(struct pcmcia_bus_socket *s, bind_info_t *bind_info, int first)
986{
987 dev_node_t *node;
988 struct pcmcia_device *p_dev;
989 unsigned long flags;
990 int ret = 0;
991
992#ifdef CONFIG_CARDBUS
993 /*
994 * Some unbelievably ugly code to associate the PCI cardbus
995 * device and its driver with the PCMCIA "bind" information.
996 */
997 {
998 struct pci_bus *bus;
999
1000 bus = pcmcia_lookup_bus(s->parent);
1001 if (bus) {
1002 struct list_head *list;
1003 struct pci_dev *dev = NULL;
1004
1005 list = bus->devices.next;
1006 while (list != &bus->devices) {
1007 struct pci_dev *pdev = pci_dev_b(list);
1008 list = list->next;
1009
1010 if (first) {
1011 dev = pdev;
1012 break;
1013 }
1014
1015 /* Try to handle "next" here some way? */
1016 }
1017 if (dev && dev->driver) {
1018 strlcpy(bind_info->name, dev->driver->name, DEV_NAME_LEN);
1019 bind_info->major = 0;
1020 bind_info->minor = 0;
1021 bind_info->next = NULL;
1022 return 0;
1023 }
1024 }
1025 }
1026#endif
1027
1028 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
1029 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
1030 if (p_dev->func == bind_info->function) {
1031 p_dev = pcmcia_get_dev(p_dev);
1032 if (!p_dev)
1033 continue;
1034 goto found;
1035 }
1036 }
1037 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
1038 return -ENODEV;
1039
1040 found:
1041 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
1042
1043 if ((!p_dev->instance) ||
1044 (p_dev->instance->state & DEV_CONFIG_PENDING)) {
1045 ret = -EAGAIN;
1046 goto err_put;
1047 }
1048
1049 if (first)
1050 node = p_dev->instance->dev;
1051 else
1052 for (node = p_dev->instance->dev; node; node = node->next)
1053 if (node == bind_info->next)
1054 break;
1055 if (!node) {
1056 ret = -ENODEV;
1057 goto err_put;
1058 }
1059
1060 strlcpy(bind_info->name, node->dev_name, DEV_NAME_LEN);
1061 bind_info->major = node->major;
1062 bind_info->minor = node->minor;
1063 bind_info->next = node->next;
1064
1065 err_put:
1066 pcmcia_put_dev(p_dev);
1067 return (ret);
1068} /* get_device_info */
1069
1070/*====================================================================*/
1071
1072/* unbind _all_ devices attached to a given pcmcia_bus_socket. The 1081/* unbind _all_ devices attached to a given pcmcia_bus_socket. The
1073 * drivers have been called with EVENT_CARD_REMOVAL before. 1082 * drivers have been called with EVENT_CARD_REMOVAL before.
1074 */ 1083 */
1075static int unbind_request(struct pcmcia_bus_socket *s) 1084static int unbind_request(struct pcmcia_socket *s)
1076{ 1085{
1077 struct pcmcia_device *p_dev; 1086 struct pcmcia_device *p_dev;
1078 unsigned long flags; 1087 unsigned long flags;
1079 1088
1080 ds_dbg(2, "unbind_request(%d)\n", s->parent->sock); 1089 ds_dbg(2, "unbind_request(%d)\n", s->sock);
1081 1090
1082 s->device_count = 0; 1091 s->device_count = 0;
1083 1092
@@ -1133,433 +1142,58 @@ int pcmcia_deregister_client(client_handle_t handle)
1133} /* deregister_client */ 1142} /* deregister_client */
1134EXPORT_SYMBOL(pcmcia_deregister_client); 1143EXPORT_SYMBOL(pcmcia_deregister_client);
1135 1144
1136 1145static struct pcmcia_callback pcmcia_bus_callback = {
1137/*====================================================================== 1146 .owner = THIS_MODULE,
1138 1147 .event = ds_event,
1139 The user-mode PC Card device interface 1148 .requery = pcmcia_bus_rescan,
1140
1141======================================================================*/
1142
1143static int ds_open(struct inode *inode, struct file *file)
1144{
1145 socket_t i = iminor(inode);
1146 struct pcmcia_bus_socket *s;
1147 user_info_t *user;
1148
1149 ds_dbg(0, "ds_open(socket %d)\n", i);
1150
1151 s = get_socket_info_by_nr(i);
1152 if (!s)
1153 return -ENODEV;
1154 s = pcmcia_get_bus_socket(s);
1155 if (!s)
1156 return -ENODEV;
1157
1158 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
1159 if (s->state & DS_SOCKET_BUSY) {
1160 pcmcia_put_bus_socket(s);
1161 return -EBUSY;
1162 }
1163 else
1164 s->state |= DS_SOCKET_BUSY;
1165 }
1166
1167 user = kmalloc(sizeof(user_info_t), GFP_KERNEL);
1168 if (!user) {
1169 pcmcia_put_bus_socket(s);
1170 return -ENOMEM;
1171 }
1172 user->event_tail = user->event_head = 0;
1173 user->next = s->user;
1174 user->user_magic = USER_MAGIC;
1175 user->socket = s;
1176 s->user = user;
1177 file->private_data = user;
1178
1179 if (s->state & DS_SOCKET_PRESENT)
1180 queue_event(user, CS_EVENT_CARD_INSERTION);
1181 return 0;
1182} /* ds_open */
1183
1184/*====================================================================*/
1185
1186static int ds_release(struct inode *inode, struct file *file)
1187{
1188 struct pcmcia_bus_socket *s;
1189 user_info_t *user, **link;
1190
1191 ds_dbg(0, "ds_release(socket %d)\n", iminor(inode));
1192
1193 user = file->private_data;
1194 if (CHECK_USER(user))
1195 goto out;
1196
1197 s = user->socket;
1198
1199 /* Unlink user data structure */
1200 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
1201 s->state &= ~DS_SOCKET_BUSY;
1202 }
1203 file->private_data = NULL;
1204 for (link = &s->user; *link; link = &(*link)->next)
1205 if (*link == user) break;
1206 if (link == NULL)
1207 goto out;
1208 *link = user->next;
1209 user->user_magic = 0;
1210 kfree(user);
1211 pcmcia_put_bus_socket(s);
1212out:
1213 return 0;
1214} /* ds_release */
1215
1216/*====================================================================*/
1217
1218static ssize_t ds_read(struct file *file, char __user *buf,
1219 size_t count, loff_t *ppos)
1220{
1221 struct pcmcia_bus_socket *s;
1222 user_info_t *user;
1223 int ret;
1224
1225 ds_dbg(2, "ds_read(socket %d)\n", iminor(file->f_dentry->d_inode));
1226
1227 if (count < 4)
1228 return -EINVAL;
1229
1230 user = file->private_data;
1231 if (CHECK_USER(user))
1232 return -EIO;
1233
1234 s = user->socket;
1235 if (s->state & DS_SOCKET_DEAD)
1236 return -EIO;
1237
1238 ret = wait_event_interruptible(s->queue, !queue_empty(user));
1239 if (ret == 0)
1240 ret = put_user(get_queued_event(user), (int __user *)buf) ? -EFAULT : 4;
1241
1242 return ret;
1243} /* ds_read */
1244
1245/*====================================================================*/
1246
1247static ssize_t ds_write(struct file *file, const char __user *buf,
1248 size_t count, loff_t *ppos)
1249{
1250 ds_dbg(2, "ds_write(socket %d)\n", iminor(file->f_dentry->d_inode));
1251
1252 if (count != 4)
1253 return -EINVAL;
1254 if ((file->f_flags & O_ACCMODE) == O_RDONLY)
1255 return -EBADF;
1256
1257 return -EIO;
1258} /* ds_write */
1259
1260/*====================================================================*/
1261
1262/* No kernel lock - fine */
1263static u_int ds_poll(struct file *file, poll_table *wait)
1264{
1265 struct pcmcia_bus_socket *s;
1266 user_info_t *user;
1267
1268 ds_dbg(2, "ds_poll(socket %d)\n", iminor(file->f_dentry->d_inode));
1269
1270 user = file->private_data;
1271 if (CHECK_USER(user))
1272 return POLLERR;
1273 s = user->socket;
1274 /*
1275 * We don't check for a dead socket here since that
1276 * will send cardmgr into an endless spin.
1277 */
1278 poll_wait(file, &s->queue, wait);
1279 if (!queue_empty(user))
1280 return POLLIN | POLLRDNORM;
1281 return 0;
1282} /* ds_poll */
1283
1284/*====================================================================*/
1285
1286extern int pcmcia_adjust_resource_info(adjust_t *adj);
1287
1288static int ds_ioctl(struct inode * inode, struct file * file,
1289 u_int cmd, u_long arg)
1290{
1291 struct pcmcia_bus_socket *s;
1292 void __user *uarg = (char __user *)arg;
1293 u_int size;
1294 int ret, err;
1295 ds_ioctl_arg_t *buf;
1296 user_info_t *user;
1297
1298 ds_dbg(2, "ds_ioctl(socket %d, %#x, %#lx)\n", iminor(inode), cmd, arg);
1299
1300 user = file->private_data;
1301 if (CHECK_USER(user))
1302 return -EIO;
1303
1304 s = user->socket;
1305 if (s->state & DS_SOCKET_DEAD)
1306 return -EIO;
1307
1308 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
1309 if (size > sizeof(ds_ioctl_arg_t)) return -EINVAL;
1310
1311 /* Permission check */
1312 if (!(cmd & IOC_OUT) && !capable(CAP_SYS_ADMIN))
1313 return -EPERM;
1314
1315 if (cmd & IOC_IN) {
1316 if (!access_ok(VERIFY_READ, uarg, size)) {
1317 ds_dbg(3, "ds_ioctl(): verify_read = %d\n", -EFAULT);
1318 return -EFAULT;
1319 }
1320 }
1321 if (cmd & IOC_OUT) {
1322 if (!access_ok(VERIFY_WRITE, uarg, size)) {
1323 ds_dbg(3, "ds_ioctl(): verify_write = %d\n", -EFAULT);
1324 return -EFAULT;
1325 }
1326 }
1327 buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
1328 if (!buf)
1329 return -ENOMEM;
1330
1331 err = ret = 0;
1332
1333 if (cmd & IOC_IN) __copy_from_user((char *)buf, uarg, size);
1334
1335 switch (cmd) {
1336 case DS_ADJUST_RESOURCE_INFO:
1337 ret = pcmcia_adjust_resource_info(&buf->adjust);
1338 break;
1339 case DS_GET_CARD_SERVICES_INFO:
1340 ret = pcmcia_get_card_services_info(&buf->servinfo);
1341 break;
1342 case DS_GET_CONFIGURATION_INFO:
1343 if (buf->config.Function &&
1344 (buf->config.Function >= s->parent->functions))
1345 ret = CS_BAD_ARGS;
1346 else
1347 ret = pccard_get_configuration_info(s->parent,
1348 buf->config.Function, &buf->config);
1349 break;
1350 case DS_GET_FIRST_TUPLE:
1351 down(&s->parent->skt_sem);
1352 pcmcia_validate_mem(s->parent);
1353 up(&s->parent->skt_sem);
1354 ret = pccard_get_first_tuple(s->parent, BIND_FN_ALL, &buf->tuple);
1355 break;
1356 case DS_GET_NEXT_TUPLE:
1357 ret = pccard_get_next_tuple(s->parent, BIND_FN_ALL, &buf->tuple);
1358 break;
1359 case DS_GET_TUPLE_DATA:
1360 buf->tuple.TupleData = buf->tuple_parse.data;
1361 buf->tuple.TupleDataMax = sizeof(buf->tuple_parse.data);
1362 ret = pccard_get_tuple_data(s->parent, &buf->tuple);
1363 break;
1364 case DS_PARSE_TUPLE:
1365 buf->tuple.TupleData = buf->tuple_parse.data;
1366 ret = pccard_parse_tuple(&buf->tuple, &buf->tuple_parse.parse);
1367 break;
1368 case DS_RESET_CARD:
1369 ret = pccard_reset_card(s->parent);
1370 break;
1371 case DS_GET_STATUS:
1372 if (buf->status.Function &&
1373 (buf->status.Function >= s->parent->functions))
1374 ret = CS_BAD_ARGS;
1375 else
1376 ret = pccard_get_status(s->parent, buf->status.Function, &buf->status);
1377 break;
1378 case DS_VALIDATE_CIS:
1379 down(&s->parent->skt_sem);
1380 pcmcia_validate_mem(s->parent);
1381 up(&s->parent->skt_sem);
1382 ret = pccard_validate_cis(s->parent, BIND_FN_ALL, &buf->cisinfo);
1383 break;
1384 case DS_SUSPEND_CARD:
1385 ret = pcmcia_suspend_card(s->parent);
1386 break;
1387 case DS_RESUME_CARD:
1388 ret = pcmcia_resume_card(s->parent);
1389 break;
1390 case DS_EJECT_CARD:
1391 err = pcmcia_eject_card(s->parent);
1392 break;
1393 case DS_INSERT_CARD:
1394 err = pcmcia_insert_card(s->parent);
1395 break;
1396 case DS_ACCESS_CONFIGURATION_REGISTER:
1397 if ((buf->conf_reg.Action == CS_WRITE) && !capable(CAP_SYS_ADMIN)) {
1398 err = -EPERM;
1399 goto free_out;
1400 }
1401 if (buf->conf_reg.Function &&
1402 (buf->conf_reg.Function >= s->parent->functions))
1403 ret = CS_BAD_ARGS;
1404 else
1405 ret = pccard_access_configuration_register(s->parent,
1406 buf->conf_reg.Function, &buf->conf_reg);
1407 break;
1408 case DS_GET_FIRST_REGION:
1409 case DS_GET_NEXT_REGION:
1410 case DS_BIND_MTD:
1411 if (!capable(CAP_SYS_ADMIN)) {
1412 err = -EPERM;
1413 goto free_out;
1414 } else {
1415 static int printed = 0;
1416 if (!printed) {
1417 printk(KERN_WARNING "2.6. kernels use pcmciamtd instead of memory_cs.c and do not require special\n");
1418 printk(KERN_WARNING "MTD handling any more.\n");
1419 printed++;
1420 }
1421 }
1422 err = -EINVAL;
1423 goto free_out;
1424 break;
1425 case DS_GET_FIRST_WINDOW:
1426 ret = pcmcia_get_window(s->parent, &buf->win_info.handle, 0,
1427 &buf->win_info.window);
1428 break;
1429 case DS_GET_NEXT_WINDOW:
1430 ret = pcmcia_get_window(s->parent, &buf->win_info.handle,
1431 buf->win_info.handle->index + 1, &buf->win_info.window);
1432 break;
1433 case DS_GET_MEM_PAGE:
1434 ret = pcmcia_get_mem_page(buf->win_info.handle,
1435 &buf->win_info.map);
1436 break;
1437 case DS_REPLACE_CIS:
1438 ret = pcmcia_replace_cis(s->parent, &buf->cisdump);
1439 break;
1440 case DS_BIND_REQUEST:
1441 if (!capable(CAP_SYS_ADMIN)) {
1442 err = -EPERM;
1443 goto free_out;
1444 }
1445 err = bind_request(s, &buf->bind_info);
1446 break;
1447 case DS_GET_DEVICE_INFO:
1448 err = get_device_info(s, &buf->bind_info, 1);
1449 break;
1450 case DS_GET_NEXT_DEVICE:
1451 err = get_device_info(s, &buf->bind_info, 0);
1452 break;
1453 case DS_UNBIND_REQUEST:
1454 err = 0;
1455 break;
1456 default:
1457 err = -EINVAL;
1458 }
1459
1460 if ((err == 0) && (ret != CS_SUCCESS)) {
1461 ds_dbg(2, "ds_ioctl: ret = %d\n", ret);
1462 switch (ret) {
1463 case CS_BAD_SOCKET: case CS_NO_CARD:
1464 err = -ENODEV; break;
1465 case CS_BAD_ARGS: case CS_BAD_ATTRIBUTE: case CS_BAD_IRQ:
1466 case CS_BAD_TUPLE:
1467 err = -EINVAL; break;
1468 case CS_IN_USE:
1469 err = -EBUSY; break;
1470 case CS_OUT_OF_RESOURCE:
1471 err = -ENOSPC; break;
1472 case CS_NO_MORE_ITEMS:
1473 err = -ENODATA; break;
1474 case CS_UNSUPPORTED_FUNCTION:
1475 err = -ENOSYS; break;
1476 default:
1477 err = -EIO; break;
1478 }
1479 }
1480
1481 if (cmd & IOC_OUT) {
1482 if (__copy_to_user(uarg, (char *)buf, size))
1483 err = -EFAULT;
1484 }
1485
1486free_out:
1487 kfree(buf);
1488 return err;
1489} /* ds_ioctl */
1490
1491/*====================================================================*/
1492
1493static struct file_operations ds_fops = {
1494 .owner = THIS_MODULE,
1495 .open = ds_open,
1496 .release = ds_release,
1497 .ioctl = ds_ioctl,
1498 .read = ds_read,
1499 .write = ds_write,
1500 .poll = ds_poll,
1501}; 1149};
1502 1150
1503static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev) 1151static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev)
1504{ 1152{
1505 struct pcmcia_socket *socket = class_get_devdata(class_dev); 1153 struct pcmcia_socket *socket = class_get_devdata(class_dev);
1506 struct pcmcia_bus_socket *s;
1507 int ret; 1154 int ret;
1508 1155
1509 s = kmalloc(sizeof(struct pcmcia_bus_socket), GFP_KERNEL); 1156 socket = pcmcia_get_socket(socket);
1510 if(!s) 1157 if (!socket) {
1511 return -ENOMEM;
1512 memset(s, 0, sizeof(struct pcmcia_bus_socket));
1513
1514 /* get reference to parent socket */
1515 s->parent = pcmcia_get_socket(socket);
1516 if (!s->parent) {
1517 printk(KERN_ERR "PCMCIA obtaining reference to socket %p failed\n", socket); 1158 printk(KERN_ERR "PCMCIA obtaining reference to socket %p failed\n", socket);
1518 kfree (s);
1519 return -ENODEV; 1159 return -ENODEV;
1520 } 1160 }
1521 1161
1522 kref_init(&s->refcount);
1523
1524 /* 1162 /*
1525 * Ugly. But we want to wait for the socket threads to have started up. 1163 * Ugly. But we want to wait for the socket threads to have started up.
1526 * We really should let the drivers themselves drive some of this.. 1164 * We really should let the drivers themselves drive some of this..
1527 */ 1165 */
1528 msleep(250); 1166 msleep(250);
1529 1167
1530 init_waitqueue_head(&s->queue); 1168#ifdef CONFIG_PCMCIA_IOCTL
1531 INIT_LIST_HEAD(&s->devices_list); 1169 init_waitqueue_head(&socket->queue);
1532 1170#endif
1533 /* Set up hotline to Card Services */ 1171 INIT_LIST_HEAD(&socket->devices_list);
1534 s->callback.owner = THIS_MODULE; 1172 INIT_WORK(&socket->device_add, pcmcia_delayed_add_pseudo_device, socket);
1535 s->callback.event = &ds_event; 1173 memset(&socket->pcmcia_state, 0, sizeof(u8));
1536 s->callback.resources_done = &pcmcia_card_add; 1174 socket->device_count = 0;
1537 socket->pcmcia = s;
1538 1175
1539 ret = pccard_register_pcmcia(socket, &s->callback); 1176 ret = pccard_register_pcmcia(socket, &pcmcia_bus_callback);
1540 if (ret) { 1177 if (ret) {
1541 printk(KERN_ERR "PCMCIA registration PCCard core failed for socket %p\n", socket); 1178 printk(KERN_ERR "PCMCIA registration PCCard core failed for socket %p\n", socket);
1542 pcmcia_put_bus_socket(s); 1179 pcmcia_put_socket(socket);
1543 socket->pcmcia = NULL;
1544 return (ret); 1180 return (ret);
1545 } 1181 }
1546 1182
1547 return 0; 1183 return 0;
1548} 1184}
1549 1185
1550
1551static void pcmcia_bus_remove_socket(struct class_device *class_dev) 1186static void pcmcia_bus_remove_socket(struct class_device *class_dev)
1552{ 1187{
1553 struct pcmcia_socket *socket = class_get_devdata(class_dev); 1188 struct pcmcia_socket *socket = class_get_devdata(class_dev);
1554 1189
1555 if (!socket || !socket->pcmcia) 1190 if (!socket)
1556 return; 1191 return;
1557 1192
1193 socket->pcmcia_state.dead = 1;
1558 pccard_register_pcmcia(socket, NULL); 1194 pccard_register_pcmcia(socket, NULL);
1559 1195
1560 socket->pcmcia->state |= DS_SOCKET_DEAD; 1196 pcmcia_put_socket(socket);
1561 pcmcia_put_bus_socket(socket->pcmcia);
1562 socket->pcmcia = NULL;
1563 1197
1564 return; 1198 return;
1565} 1199}
@@ -1575,34 +1209,20 @@ static struct class_interface pcmcia_bus_interface = {
1575 1209
1576struct bus_type pcmcia_bus_type = { 1210struct bus_type pcmcia_bus_type = {
1577 .name = "pcmcia", 1211 .name = "pcmcia",
1212 .hotplug = pcmcia_bus_hotplug,
1578 .match = pcmcia_bus_match, 1213 .match = pcmcia_bus_match,
1579 .dev_attrs = pcmcia_dev_attrs, 1214 .dev_attrs = pcmcia_dev_attrs,
1580}; 1215};
1581EXPORT_SYMBOL(pcmcia_bus_type);
1582 1216
1583 1217
1584static int __init init_pcmcia_bus(void) 1218static int __init init_pcmcia_bus(void)
1585{ 1219{
1586 int i;
1587
1588 spin_lock_init(&pcmcia_dev_list_lock); 1220 spin_lock_init(&pcmcia_dev_list_lock);
1589 1221
1590 bus_register(&pcmcia_bus_type); 1222 bus_register(&pcmcia_bus_type);
1591 class_interface_register(&pcmcia_bus_interface); 1223 class_interface_register(&pcmcia_bus_interface);
1592 1224
1593 /* Set up character device for user mode clients */ 1225 pcmcia_setup_ioctl();
1594 i = register_chrdev(0, "pcmcia", &ds_fops);
1595 if (i < 0)
1596 printk(KERN_NOTICE "unable to find a free device # for "
1597 "Driver Services (error=%d)\n", i);
1598 else
1599 major_dev = i;
1600
1601#ifdef CONFIG_PROC_FS
1602 proc_pccard = proc_mkdir("pccard", proc_bus);
1603 if (proc_pccard)
1604 create_proc_read_entry("drivers",0,proc_pccard,proc_read_drivers,NULL);
1605#endif
1606 1226
1607 return 0; 1227 return 0;
1608} 1228}
@@ -1612,48 +1232,13 @@ fs_initcall(init_pcmcia_bus); /* one level after subsys_initcall so that
1612 1232
1613static void __exit exit_pcmcia_bus(void) 1233static void __exit exit_pcmcia_bus(void)
1614{ 1234{
1615 class_interface_unregister(&pcmcia_bus_interface); 1235 pcmcia_cleanup_ioctl();
1616 1236
1617#ifdef CONFIG_PROC_FS 1237 class_interface_unregister(&pcmcia_bus_interface);
1618 if (proc_pccard) {
1619 remove_proc_entry("drivers", proc_pccard);
1620 remove_proc_entry("pccard", proc_bus);
1621 }
1622#endif
1623 if (major_dev != -1)
1624 unregister_chrdev(major_dev, "pcmcia");
1625 1238
1626 bus_unregister(&pcmcia_bus_type); 1239 bus_unregister(&pcmcia_bus_type);
1627} 1240}
1628module_exit(exit_pcmcia_bus); 1241module_exit(exit_pcmcia_bus);
1629 1242
1630 1243
1631
1632/* helpers for backwards-compatible functions */
1633
1634static struct pcmcia_bus_socket * get_socket_info_by_nr(unsigned int nr)
1635{
1636 struct pcmcia_socket * s = pcmcia_get_socket_by_nr(nr);
1637 if (s && s->pcmcia)
1638 return s->pcmcia;
1639 else
1640 return NULL;
1641}
1642
1643/* backwards-compatible accessing of driver --- by name! */
1644
1645static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info)
1646{
1647 struct device_driver *drv;
1648 struct pcmcia_driver *p_drv;
1649
1650 drv = driver_find((char *) dev_info, &pcmcia_bus_type);
1651 if (!drv)
1652 return NULL;
1653
1654 p_drv = container_of(drv, struct pcmcia_driver, drv);
1655
1656 return (p_drv);
1657}
1658
1659MODULE_ALIAS("ds"); 1244MODULE_ALIAS("ds");
diff --git a/drivers/pcmcia/ds_internal.h b/drivers/pcmcia/ds_internal.h
new file mode 100644
index 000000000000..d359bd25a51c
--- /dev/null
+++ b/drivers/pcmcia/ds_internal.h
@@ -0,0 +1,21 @@
1/* ds_internal.h - internal header for 16-bit PCMCIA devices management */
2
3extern spinlock_t pcmcia_dev_list_lock;
4extern struct bus_type pcmcia_bus_type;
5
6extern struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev);
7extern void pcmcia_put_dev(struct pcmcia_device *p_dev);
8
9struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function);
10
11#ifdef CONFIG_PCMCIA_IOCTL
12extern void __init pcmcia_setup_ioctl(void);
13extern void __exit pcmcia_cleanup_ioctl(void);
14extern void handle_event(struct pcmcia_socket *s, event_t event);
15extern int handle_request(struct pcmcia_socket *s, event_t event);
16#else
17static inline void __init pcmcia_setup_ioctl(void) { return; }
18static inline void __init pcmcia_cleanup_ioctl(void) { return; }
19static inline void handle_event(struct pcmcia_socket *s, event_t event) { return; }
20static inline int handle_request(struct pcmcia_socket *s, event_t event) { return CS_SUCCESS; }
21#endif
diff --git a/drivers/pcmcia/i82365.c b/drivers/pcmcia/i82365.c
index 90a335a5d9fa..d72f9a35c8bd 100644
--- a/drivers/pcmcia/i82365.c
+++ b/drivers/pcmcia/i82365.c
@@ -669,11 +669,13 @@ static int __init is_alive(u_short sock)
669 if ((stat & I365_CS_DETECT) && (stat & I365_CS_POWERON) && 669 if ((stat & I365_CS_DETECT) && (stat & I365_CS_POWERON) &&
670 (i365_get(sock, I365_INTCTL) & I365_PC_IOCARD) && 670 (i365_get(sock, I365_INTCTL) & I365_PC_IOCARD) &&
671 (i365_get(sock, I365_ADDRWIN) & I365_ENA_IO(0)) && 671 (i365_get(sock, I365_ADDRWIN) & I365_ENA_IO(0)) &&
672 (check_region(start, stop-start+1) != 0) && 672 ((start & 0xfeef) != 0x02e8)) {
673 ((start & 0xfeef) != 0x02e8)) 673 if (!request_region(start, stop-start+1, "i82365"))
674 return 1; 674 return 1;
675 else 675 release_region(start, stop-start+1);
676 return 0; 676 }
677
678 return 0;
677} 679}
678 680
679/*====================================================================*/ 681/*====================================================================*/
@@ -696,7 +698,13 @@ static void __init add_pcic(int ns, int type)
696 struct i82365_socket *t = &socket[sockets-ns]; 698 struct i82365_socket *t = &socket[sockets-ns];
697 699
698 base = sockets-ns; 700 base = sockets-ns;
699 if (t->ioaddr > 0) request_region(t->ioaddr, 2, "i82365"); 701 if (t->ioaddr > 0) {
702 if (!request_region(t->ioaddr, 2, "i82365")) {
703 printk(KERN_ERR "i82365: IO region conflict at %#lx, not available\n",
704 t->ioaddr);
705 return;
706 }
707 }
700 708
701 if (base == 0) printk("\n"); 709 if (base == 0) printk("\n");
702 printk(KERN_INFO " %s", pcic[type].name); 710 printk(KERN_INFO " %s", pcic[type].name);
@@ -803,7 +811,7 @@ static void __init isa_probe(void)
803 } 811 }
804#endif 812#endif
805 813
806 if (check_region(i365_base, 2) != 0) { 814 if (!request_region(i365_base, 2, "i82365")) {
807 if (sockets == 0) 815 if (sockets == 0)
808 printk("port conflict at %#lx\n", i365_base); 816 printk("port conflict at %#lx\n", i365_base);
809 return; 817 return;
@@ -1441,6 +1449,7 @@ static void __exit exit_i82365(void)
1441 i365_set(i, I365_CSCINT, 0); 1449 i365_set(i, I365_CSCINT, 0);
1442 release_region(socket[i].ioaddr, 2); 1450 release_region(socket[i].ioaddr, 2);
1443 } 1451 }
1452 release_region(i365_base, 2);
1444#ifdef CONFIG_PNP 1453#ifdef CONFIG_PNP
1445 if (i82365_pnpdev) 1454 if (i82365_pnpdev)
1446 pnp_disable_dev(i82365_pnpdev); 1455 pnp_disable_dev(i82365_pnpdev);
diff --git a/drivers/pcmcia/pcmcia_compat.c b/drivers/pcmcia/pcmcia_compat.c
index 68b80084f83f..1cc83317e7e3 100644
--- a/drivers/pcmcia/pcmcia_compat.c
+++ b/drivers/pcmcia/pcmcia_compat.c
@@ -74,19 +74,6 @@ int pcmcia_validate_cis(client_handle_t handle, cisinfo_t *info)
74} 74}
75EXPORT_SYMBOL(pcmcia_validate_cis); 75EXPORT_SYMBOL(pcmcia_validate_cis);
76 76
77int pcmcia_get_configuration_info(client_handle_t handle,
78 config_info_t *config)
79{
80 struct pcmcia_socket *s;
81
82 if ((CHECK_HANDLE(handle)) || !config)
83 return CS_BAD_HANDLE;
84 s = SOCKET(handle);
85 if (!s)
86 return CS_BAD_HANDLE;
87 return pccard_get_configuration_info(s, handle->Function, config);
88}
89EXPORT_SYMBOL(pcmcia_get_configuration_info);
90 77
91int pcmcia_reset_card(client_handle_t handle, client_req_t *req) 78int pcmcia_reset_card(client_handle_t handle, client_req_t *req)
92{ 79{
@@ -102,24 +89,3 @@ int pcmcia_reset_card(client_handle_t handle, client_req_t *req)
102} 89}
103EXPORT_SYMBOL(pcmcia_reset_card); 90EXPORT_SYMBOL(pcmcia_reset_card);
104 91
105int pcmcia_get_status(client_handle_t handle, cs_status_t *status)
106{
107 struct pcmcia_socket *s;
108 if (CHECK_HANDLE(handle))
109 return CS_BAD_HANDLE;
110 s = SOCKET(handle);
111 return pccard_get_status(s, handle->Function, status);
112}
113EXPORT_SYMBOL(pcmcia_get_status);
114
115int pcmcia_access_configuration_register(client_handle_t handle,
116 conf_reg_t *reg)
117{
118 struct pcmcia_socket *s;
119 if (CHECK_HANDLE(handle))
120 return CS_BAD_HANDLE;
121 s = SOCKET(handle);
122 return pccard_access_configuration_register(s, handle->Function, reg);
123}
124EXPORT_SYMBOL(pcmcia_access_configuration_register);
125
diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
new file mode 100644
index 000000000000..b883bc151ed0
--- /dev/null
+++ b/drivers/pcmcia/pcmcia_ioctl.c
@@ -0,0 +1,786 @@
1/*
2 * pcmcia_ioctl.c -- ioctl interface for cardmgr and cardctl
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * The initial developer of the original code is David A. Hinds
9 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
11 *
12 * (C) 1999 David A. Hinds
13 * (C) 2003 - 2004 Dominik Brodowski
14 */
15
16/*
17 * This file will go away soon.
18 */
19
20
21#include <linux/config.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/major.h>
26#include <linux/errno.h>
27#include <linux/ioctl.h>
28#include <linux/proc_fs.h>
29#include <linux/poll.h>
30#include <linux/pci.h>
31#include <linux/workqueue.h>
32
33#define IN_CARD_SERVICES
34#include <pcmcia/version.h>
35#include <pcmcia/cs_types.h>
36#include <pcmcia/cs.h>
37#include <pcmcia/cistpl.h>
38#include <pcmcia/ds.h>
39#include <pcmcia/ss.h>
40
41#include "cs_internal.h"
42#include "ds_internal.h"
43
44static int major_dev = -1;
45
46
47/* Device user information */
48#define MAX_EVENTS 32
49#define USER_MAGIC 0x7ea4
50#define CHECK_USER(u) \
51 (((u) == NULL) || ((u)->user_magic != USER_MAGIC))
52
53typedef struct user_info_t {
54 u_int user_magic;
55 int event_head, event_tail;
56 event_t event[MAX_EVENTS];
57 struct user_info_t *next;
58 struct pcmcia_socket *socket;
59} user_info_t;
60
61
62#ifdef DEBUG
63extern int ds_pc_debug;
64#define cs_socket_name(skt) ((skt)->dev.class_id)
65
66#define ds_dbg(lvl, fmt, arg...) do { \
67 if (ds_pc_debug >= lvl) \
68 printk(KERN_DEBUG "ds: " fmt , ## arg); \
69} while (0)
70#else
71#define ds_dbg(lvl, fmt, arg...) do { } while (0)
72#endif
73
74static const char *release = "Linux Kernel Card Services";
75
76/** pcmcia_get_card_services_info
77 *
78 * Return information about this version of Card Services
79 */
80static int pcmcia_get_card_services_info(servinfo_t *info)
81{
82 unsigned int socket_count = 0;
83 struct list_head *tmp;
84 info->Signature[0] = 'C';
85 info->Signature[1] = 'S';
86 down_read(&pcmcia_socket_list_rwsem);
87 list_for_each(tmp, &pcmcia_socket_list)
88 socket_count++;
89 up_read(&pcmcia_socket_list_rwsem);
90 info->Count = socket_count;
91 info->Revision = CS_RELEASE_CODE;
92 info->CSLevel = 0x0210;
93 info->VendorString = (char *)release;
94 return CS_SUCCESS;
95} /* get_card_services_info */
96
97
98/* backwards-compatible accessing of driver --- by name! */
99
100static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info)
101{
102 struct device_driver *drv;
103 struct pcmcia_driver *p_drv;
104
105 drv = driver_find((char *) dev_info, &pcmcia_bus_type);
106 if (!drv)
107 return NULL;
108
109 p_drv = container_of(drv, struct pcmcia_driver, drv);
110
111 return (p_drv);
112}
113
114
115#ifdef CONFIG_PROC_FS
116static struct proc_dir_entry *proc_pccard = NULL;
117
118static int proc_read_drivers_callback(struct device_driver *driver, void *d)
119{
120 char **p = d;
121 struct pcmcia_driver *p_drv = container_of(driver,
122 struct pcmcia_driver, drv);
123
124 *p += sprintf(*p, "%-24.24s 1 %d\n", p_drv->drv.name,
125#ifdef CONFIG_MODULE_UNLOAD
126 (p_drv->owner) ? module_refcount(p_drv->owner) : 1
127#else
128 1
129#endif
130 );
131 d = (void *) p;
132
133 return 0;
134}
135
136static int proc_read_drivers(char *buf, char **start, off_t pos,
137 int count, int *eof, void *data)
138{
139 char *p = buf;
140
141 bus_for_each_drv(&pcmcia_bus_type, NULL,
142 (void *) &p, proc_read_drivers_callback);
143
144 return (p - buf);
145}
146#endif
147
148/*======================================================================
149
150 These manage a ring buffer of events pending for one user process
151
152======================================================================*/
153
154
155static int queue_empty(user_info_t *user)
156{
157 return (user->event_head == user->event_tail);
158}
159
160static event_t get_queued_event(user_info_t *user)
161{
162 user->event_tail = (user->event_tail+1) % MAX_EVENTS;
163 return user->event[user->event_tail];
164}
165
166static void queue_event(user_info_t *user, event_t event)
167{
168 user->event_head = (user->event_head+1) % MAX_EVENTS;
169 if (user->event_head == user->event_tail)
170 user->event_tail = (user->event_tail+1) % MAX_EVENTS;
171 user->event[user->event_head] = event;
172}
173
174void handle_event(struct pcmcia_socket *s, event_t event)
175{
176 user_info_t *user;
177 for (user = s->user; user; user = user->next)
178 queue_event(user, event);
179 wake_up_interruptible(&s->queue);
180}
181
182
183/*======================================================================
184
185 bind_request() and bind_device() are merged by now. Register_client()
186 is called right at the end of bind_request(), during the driver's
187 ->attach() call. Individual descriptions:
188
189 bind_request() connects a socket to a particular client driver.
190 It looks up the specified device ID in the list of registered
191 drivers, binds it to the socket, and tries to create an instance
192 of the device. unbind_request() deletes a driver instance.
193
194 Bind_device() associates a device driver with a particular socket.
195 It is normally called by Driver Services after it has identified
196 a newly inserted card. An instance of that driver will then be
197 eligible to register as a client of this socket.
198
199 Register_client() uses the dev_info_t handle to match the
200 caller with a socket. The driver must have already been bound
201 to a socket with bind_device() -- in fact, bind_device()
202 allocates the client structure that will be used.
203
204======================================================================*/
205
206static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info)
207{
208 struct pcmcia_driver *p_drv;
209 struct pcmcia_device *p_dev;
210 int ret = 0;
211 unsigned long flags;
212
213 s = pcmcia_get_socket(s);
214 if (!s)
215 return -EINVAL;
216
217 ds_dbg(2, "bind_request(%d, '%s')\n", s->sock,
218 (char *)bind_info->dev_info);
219
220 p_drv = get_pcmcia_driver(&bind_info->dev_info);
221 if (!p_drv) {
222 ret = -EINVAL;
223 goto err_put;
224 }
225
226 if (!try_module_get(p_drv->owner)) {
227 ret = -EINVAL;
228 goto err_put_driver;
229 }
230
231 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
232 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
233 if (p_dev->func == bind_info->function) {
234 if ((p_dev->dev.driver == &p_drv->drv)) {
235 if (p_dev->cardmgr) {
236 /* if there's already a device
237 * registered, and it was registered
238 * by userspace before, we need to
239 * return the "instance". */
240 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
241 bind_info->instance = p_dev->instance;
242 ret = -EBUSY;
243 goto err_put_module;
244 } else {
245 /* the correct driver managed to bind
246 * itself magically to the correct
247 * device. */
248 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
249 p_dev->cardmgr = p_drv;
250 ret = 0;
251 goto err_put_module;
252 }
253 } else if (!p_dev->dev.driver) {
254 /* there's already a device available where
255 * no device has been bound to yet. So we don't
256 * need to register a device! */
257 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
258 goto rescan;
259 }
260 }
261 }
262 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
263
264 p_dev = pcmcia_device_add(s, bind_info->function);
265 if (!p_dev) {
266 ret = -EIO;
267 goto err_put_module;
268 }
269
270rescan:
271 p_dev->cardmgr = p_drv;
272
273 /* if a driver is already running, we can abort */
274 if (p_dev->dev.driver)
275 goto err_put_module;
276
277 /*
278 * Prevent this racing with a card insertion.
279 */
280 down(&s->skt_sem);
281 bus_rescan_devices(&pcmcia_bus_type);
282 up(&s->skt_sem);
283
284 /* check whether the driver indeed matched. I don't care if this
285 * is racy or not, because it can only happen on cardmgr access
286 * paths...
287 */
288 if (!(p_dev->dev.driver == &p_drv->drv))
289 p_dev->cardmgr = NULL;
290
291 err_put_module:
292 module_put(p_drv->owner);
293 err_put_driver:
294 put_driver(&p_drv->drv);
295 err_put:
296 pcmcia_put_socket(s);
297
298 return (ret);
299} /* bind_request */
300
301#ifdef CONFIG_CARDBUS
302
303static struct pci_bus *pcmcia_lookup_bus(struct pcmcia_socket *s)
304{
305 if (!s || !(s->state & SOCKET_CARDBUS))
306 return NULL;
307
308 return s->cb_dev->subordinate;
309}
310#endif
311
312static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int first)
313{
314 dev_node_t *node;
315 struct pcmcia_device *p_dev;
316 unsigned long flags;
317 int ret = 0;
318
319#ifdef CONFIG_CARDBUS
320 /*
321 * Some unbelievably ugly code to associate the PCI cardbus
322 * device and its driver with the PCMCIA "bind" information.
323 */
324 {
325 struct pci_bus *bus;
326
327 bus = pcmcia_lookup_bus(s);
328 if (bus) {
329 struct list_head *list;
330 struct pci_dev *dev = NULL;
331
332 list = bus->devices.next;
333 while (list != &bus->devices) {
334 struct pci_dev *pdev = pci_dev_b(list);
335 list = list->next;
336
337 if (first) {
338 dev = pdev;
339 break;
340 }
341
342 /* Try to handle "next" here some way? */
343 }
344 if (dev && dev->driver) {
345 strlcpy(bind_info->name, dev->driver->name, DEV_NAME_LEN);
346 bind_info->major = 0;
347 bind_info->minor = 0;
348 bind_info->next = NULL;
349 return 0;
350 }
351 }
352 }
353#endif
354
355 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
356 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
357 if (p_dev->func == bind_info->function) {
358 p_dev = pcmcia_get_dev(p_dev);
359 if (!p_dev)
360 continue;
361 goto found;
362 }
363 }
364 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
365 return -ENODEV;
366
367 found:
368 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
369
370 if ((!p_dev->instance) ||
371 (p_dev->instance->state & DEV_CONFIG_PENDING)) {
372 ret = -EAGAIN;
373 goto err_put;
374 }
375
376 if (first)
377 node = p_dev->instance->dev;
378 else
379 for (node = p_dev->instance->dev; node; node = node->next)
380 if (node == bind_info->next)
381 break;
382 if (!node) {
383 ret = -ENODEV;
384 goto err_put;
385 }
386
387 strlcpy(bind_info->name, node->dev_name, DEV_NAME_LEN);
388 bind_info->major = node->major;
389 bind_info->minor = node->minor;
390 bind_info->next = node->next;
391
392 err_put:
393 pcmcia_put_dev(p_dev);
394 return (ret);
395} /* get_device_info */
396
397
398static int ds_open(struct inode *inode, struct file *file)
399{
400 socket_t i = iminor(inode);
401 struct pcmcia_socket *s;
402 user_info_t *user;
403
404 ds_dbg(0, "ds_open(socket %d)\n", i);
405
406 s = pcmcia_get_socket_by_nr(i);
407 if (!s)
408 return -ENODEV;
409 s = pcmcia_get_socket(s);
410 if (!s)
411 return -ENODEV;
412
413 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
414 if (s->pcmcia_state.busy) {
415 pcmcia_put_socket(s);
416 return -EBUSY;
417 }
418 else
419 s->pcmcia_state.busy = 1;
420 }
421
422 user = kmalloc(sizeof(user_info_t), GFP_KERNEL);
423 if (!user) {
424 pcmcia_put_socket(s);
425 return -ENOMEM;
426 }
427 user->event_tail = user->event_head = 0;
428 user->next = s->user;
429 user->user_magic = USER_MAGIC;
430 user->socket = s;
431 s->user = user;
432 file->private_data = user;
433
434 if (s->pcmcia_state.present)
435 queue_event(user, CS_EVENT_CARD_INSERTION);
436 return 0;
437} /* ds_open */
438
439/*====================================================================*/
440
441static int ds_release(struct inode *inode, struct file *file)
442{
443 struct pcmcia_socket *s;
444 user_info_t *user, **link;
445
446 ds_dbg(0, "ds_release(socket %d)\n", iminor(inode));
447
448 user = file->private_data;
449 if (CHECK_USER(user))
450 goto out;
451
452 s = user->socket;
453
454 /* Unlink user data structure */
455 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
456 s->pcmcia_state.busy = 0;
457 }
458 file->private_data = NULL;
459 for (link = &s->user; *link; link = &(*link)->next)
460 if (*link == user) break;
461 if (link == NULL)
462 goto out;
463 *link = user->next;
464 user->user_magic = 0;
465 kfree(user);
466 pcmcia_put_socket(s);
467out:
468 return 0;
469} /* ds_release */
470
471/*====================================================================*/
472
473static ssize_t ds_read(struct file *file, char __user *buf,
474 size_t count, loff_t *ppos)
475{
476 struct pcmcia_socket *s;
477 user_info_t *user;
478 int ret;
479
480 ds_dbg(2, "ds_read(socket %d)\n", iminor(file->f_dentry->d_inode));
481
482 if (count < 4)
483 return -EINVAL;
484
485 user = file->private_data;
486 if (CHECK_USER(user))
487 return -EIO;
488
489 s = user->socket;
490 if (s->pcmcia_state.dead)
491 return -EIO;
492
493 ret = wait_event_interruptible(s->queue, !queue_empty(user));
494 if (ret == 0)
495 ret = put_user(get_queued_event(user), (int __user *)buf) ? -EFAULT : 4;
496
497 return ret;
498} /* ds_read */
499
500/*====================================================================*/
501
502static ssize_t ds_write(struct file *file, const char __user *buf,
503 size_t count, loff_t *ppos)
504{
505 ds_dbg(2, "ds_write(socket %d)\n", iminor(file->f_dentry->d_inode));
506
507 if (count != 4)
508 return -EINVAL;
509 if ((file->f_flags & O_ACCMODE) == O_RDONLY)
510 return -EBADF;
511
512 return -EIO;
513} /* ds_write */
514
515/*====================================================================*/
516
517/* No kernel lock - fine */
518static u_int ds_poll(struct file *file, poll_table *wait)
519{
520 struct pcmcia_socket *s;
521 user_info_t *user;
522
523 ds_dbg(2, "ds_poll(socket %d)\n", iminor(file->f_dentry->d_inode));
524
525 user = file->private_data;
526 if (CHECK_USER(user))
527 return POLLERR;
528 s = user->socket;
529 /*
530 * We don't check for a dead socket here since that
531 * will send cardmgr into an endless spin.
532 */
533 poll_wait(file, &s->queue, wait);
534 if (!queue_empty(user))
535 return POLLIN | POLLRDNORM;
536 return 0;
537} /* ds_poll */
538
539/*====================================================================*/
540
541extern int pcmcia_adjust_resource_info(adjust_t *adj);
542
543static int ds_ioctl(struct inode * inode, struct file * file,
544 u_int cmd, u_long arg)
545{
546 struct pcmcia_socket *s;
547 void __user *uarg = (char __user *)arg;
548 u_int size;
549 int ret, err;
550 ds_ioctl_arg_t *buf;
551 user_info_t *user;
552
553 ds_dbg(2, "ds_ioctl(socket %d, %#x, %#lx)\n", iminor(inode), cmd, arg);
554
555 user = file->private_data;
556 if (CHECK_USER(user))
557 return -EIO;
558
559 s = user->socket;
560 if (s->pcmcia_state.dead)
561 return -EIO;
562
563 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
564 if (size > sizeof(ds_ioctl_arg_t)) return -EINVAL;
565
566 /* Permission check */
567 if (!(cmd & IOC_OUT) && !capable(CAP_SYS_ADMIN))
568 return -EPERM;
569
570 if (cmd & IOC_IN) {
571 if (!access_ok(VERIFY_READ, uarg, size)) {
572 ds_dbg(3, "ds_ioctl(): verify_read = %d\n", -EFAULT);
573 return -EFAULT;
574 }
575 }
576 if (cmd & IOC_OUT) {
577 if (!access_ok(VERIFY_WRITE, uarg, size)) {
578 ds_dbg(3, "ds_ioctl(): verify_write = %d\n", -EFAULT);
579 return -EFAULT;
580 }
581 }
582 buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
583 if (!buf)
584 return -ENOMEM;
585
586 err = ret = 0;
587
588 if (cmd & IOC_IN) __copy_from_user((char *)buf, uarg, size);
589
590 switch (cmd) {
591 case DS_ADJUST_RESOURCE_INFO:
592 ret = pcmcia_adjust_resource_info(&buf->adjust);
593 break;
594 case DS_GET_CARD_SERVICES_INFO:
595 ret = pcmcia_get_card_services_info(&buf->servinfo);
596 break;
597 case DS_GET_CONFIGURATION_INFO:
598 if (buf->config.Function &&
599 (buf->config.Function >= s->functions))
600 ret = CS_BAD_ARGS;
601 else
602 ret = pccard_get_configuration_info(s,
603 buf->config.Function, &buf->config);
604 break;
605 case DS_GET_FIRST_TUPLE:
606 down(&s->skt_sem);
607 pcmcia_validate_mem(s);
608 up(&s->skt_sem);
609 ret = pccard_get_first_tuple(s, BIND_FN_ALL, &buf->tuple);
610 break;
611 case DS_GET_NEXT_TUPLE:
612 ret = pccard_get_next_tuple(s, BIND_FN_ALL, &buf->tuple);
613 break;
614 case DS_GET_TUPLE_DATA:
615 buf->tuple.TupleData = buf->tuple_parse.data;
616 buf->tuple.TupleDataMax = sizeof(buf->tuple_parse.data);
617 ret = pccard_get_tuple_data(s, &buf->tuple);
618 break;
619 case DS_PARSE_TUPLE:
620 buf->tuple.TupleData = buf->tuple_parse.data;
621 ret = pccard_parse_tuple(&buf->tuple, &buf->tuple_parse.parse);
622 break;
623 case DS_RESET_CARD:
624 ret = pccard_reset_card(s);
625 break;
626 case DS_GET_STATUS:
627 if (buf->status.Function &&
628 (buf->status.Function >= s->functions))
629 ret = CS_BAD_ARGS;
630 else
631 ret = pccard_get_status(s, buf->status.Function, &buf->status);
632 break;
633 case DS_VALIDATE_CIS:
634 down(&s->skt_sem);
635 pcmcia_validate_mem(s);
636 up(&s->skt_sem);
637 ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo);
638 break;
639 case DS_SUSPEND_CARD:
640 ret = pcmcia_suspend_card(s);
641 break;
642 case DS_RESUME_CARD:
643 ret = pcmcia_resume_card(s);
644 break;
645 case DS_EJECT_CARD:
646 err = pcmcia_eject_card(s);
647 break;
648 case DS_INSERT_CARD:
649 err = pcmcia_insert_card(s);
650 break;
651 case DS_ACCESS_CONFIGURATION_REGISTER:
652 if ((buf->conf_reg.Action == CS_WRITE) && !capable(CAP_SYS_ADMIN)) {
653 err = -EPERM;
654 goto free_out;
655 }
656 if (buf->conf_reg.Function &&
657 (buf->conf_reg.Function >= s->functions))
658 ret = CS_BAD_ARGS;
659 else
660 ret = pccard_access_configuration_register(s,
661 buf->conf_reg.Function, &buf->conf_reg);
662 break;
663 case DS_GET_FIRST_REGION:
664 case DS_GET_NEXT_REGION:
665 case DS_BIND_MTD:
666 if (!capable(CAP_SYS_ADMIN)) {
667 err = -EPERM;
668 goto free_out;
669 } else {
670 static int printed = 0;
671 if (!printed) {
672 printk(KERN_WARNING "2.6. kernels use pcmciamtd instead of memory_cs.c and do not require special\n");
673 printk(KERN_WARNING "MTD handling any more.\n");
674 printed++;
675 }
676 }
677 err = -EINVAL;
678 goto free_out;
679 break;
680 case DS_GET_FIRST_WINDOW:
681 ret = pcmcia_get_window(s, &buf->win_info.handle, 0,
682 &buf->win_info.window);
683 break;
684 case DS_GET_NEXT_WINDOW:
685 ret = pcmcia_get_window(s, &buf->win_info.handle,
686 buf->win_info.handle->index + 1, &buf->win_info.window);
687 break;
688 case DS_GET_MEM_PAGE:
689 ret = pcmcia_get_mem_page(buf->win_info.handle,
690 &buf->win_info.map);
691 break;
692 case DS_REPLACE_CIS:
693 ret = pcmcia_replace_cis(s, &buf->cisdump);
694 break;
695 case DS_BIND_REQUEST:
696 if (!capable(CAP_SYS_ADMIN)) {
697 err = -EPERM;
698 goto free_out;
699 }
700 err = bind_request(s, &buf->bind_info);
701 break;
702 case DS_GET_DEVICE_INFO:
703 err = get_device_info(s, &buf->bind_info, 1);
704 break;
705 case DS_GET_NEXT_DEVICE:
706 err = get_device_info(s, &buf->bind_info, 0);
707 break;
708 case DS_UNBIND_REQUEST:
709 err = 0;
710 break;
711 default:
712 err = -EINVAL;
713 }
714
715 if ((err == 0) && (ret != CS_SUCCESS)) {
716 ds_dbg(2, "ds_ioctl: ret = %d\n", ret);
717 switch (ret) {
718 case CS_BAD_SOCKET: case CS_NO_CARD:
719 err = -ENODEV; break;
720 case CS_BAD_ARGS: case CS_BAD_ATTRIBUTE: case CS_BAD_IRQ:
721 case CS_BAD_TUPLE:
722 err = -EINVAL; break;
723 case CS_IN_USE:
724 err = -EBUSY; break;
725 case CS_OUT_OF_RESOURCE:
726 err = -ENOSPC; break;
727 case CS_NO_MORE_ITEMS:
728 err = -ENODATA; break;
729 case CS_UNSUPPORTED_FUNCTION:
730 err = -ENOSYS; break;
731 default:
732 err = -EIO; break;
733 }
734 }
735
736 if (cmd & IOC_OUT) {
737 if (__copy_to_user(uarg, (char *)buf, size))
738 err = -EFAULT;
739 }
740
741free_out:
742 kfree(buf);
743 return err;
744} /* ds_ioctl */
745
746/*====================================================================*/
747
748static struct file_operations ds_fops = {
749 .owner = THIS_MODULE,
750 .open = ds_open,
751 .release = ds_release,
752 .ioctl = ds_ioctl,
753 .read = ds_read,
754 .write = ds_write,
755 .poll = ds_poll,
756};
757
758void __init pcmcia_setup_ioctl(void) {
759 int i;
760
761 /* Set up character device for user mode clients */
762 i = register_chrdev(0, "pcmcia", &ds_fops);
763 if (i < 0)
764 printk(KERN_NOTICE "unable to find a free device # for "
765 "Driver Services (error=%d)\n", i);
766 else
767 major_dev = i;
768
769#ifdef CONFIG_PROC_FS
770 proc_pccard = proc_mkdir("pccard", proc_bus);
771 if (proc_pccard)
772 create_proc_read_entry("drivers",0,proc_pccard,proc_read_drivers,NULL);
773#endif
774}
775
776
777void __exit pcmcia_cleanup_ioctl(void) {
778#ifdef CONFIG_PROC_FS
779 if (proc_pccard) {
780 remove_proc_entry("drivers", proc_pccard);
781 remove_proc_entry("pccard", proc_bus);
782 }
783#endif
784 if (major_dev != -1)
785 unregister_chrdev(major_dev, "pcmcia");
786}
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c
new file mode 100644
index 000000000000..c01dc6bf1526
--- /dev/null
+++ b/drivers/pcmcia/pcmcia_resource.c
@@ -0,0 +1,998 @@
1/*
2 * PCMCIA 16-bit resource management functions
3 *
4 * The initial developer of the original code is David A. Hinds
5 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
6 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
7 *
8 * Copyright (C) 1999 David A. Hinds
9 * Copyright (C) 2004-2005 Dominik Brodowski
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 *
15 */
16
17#include <linux/config.h>
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/interrupt.h>
21#include <linux/delay.h>
22#include <linux/pci.h>
23#include <linux/device.h>
24
25#define IN_CARD_SERVICES
26#include <pcmcia/version.h>
27#include <pcmcia/cs_types.h>
28#include <pcmcia/ss.h>
29#include <pcmcia/cs.h>
30#include <pcmcia/bulkmem.h>
31#include <pcmcia/cistpl.h>
32#include <pcmcia/cisreg.h>
33#include <pcmcia/ds.h>
34
35#include "cs_internal.h"
36#include "ds_internal.h"
37
38
39/* Access speed for IO windows */
40static int io_speed = 0;
41module_param(io_speed, int, 0444);
42
43
44#ifdef CONFIG_PCMCIA_PROBE
45/* mask of IRQs already reserved by other cards, we should avoid using them */
46static u8 pcmcia_used_irq[NR_IRQS];
47#endif
48
49
50#ifdef DEBUG
51extern int ds_pc_debug;
52#define cs_socket_name(skt) ((skt)->dev.class_id)
53
54#define ds_dbg(skt, lvl, fmt, arg...) do { \
55 if (ds_pc_debug >= lvl) \
56 printk(KERN_DEBUG "pcmcia_resource: %s: " fmt, \
57 cs_socket_name(skt) , ## arg); \
58} while (0)
59#else
60#define ds_dbg(lvl, fmt, arg...) do { } while (0)
61#endif
62
63
64
65/** alloc_io_space
66 *
67 * Special stuff for managing IO windows, because they are scarce
68 */
69
70static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
71 ioaddr_t num, u_int lines)
72{
73 int i;
74 kio_addr_t try, align;
75
76 align = (*base) ? (lines ? 1<<lines : 0) : 1;
77 if (align && (align < num)) {
78 if (*base) {
79 ds_dbg(s, 0, "odd IO request: num %#x align %#lx\n",
80 num, align);
81 align = 0;
82 } else
83 while (align && (align < num)) align <<= 1;
84 }
85 if (*base & ~(align-1)) {
86 ds_dbg(s, 0, "odd IO request: base %#x align %#lx\n",
87 *base, align);
88 align = 0;
89 }
90 if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
91 *base = s->io_offset | (*base & 0x0fff);
92 s->io[0].Attributes = attr;
93 return 0;
94 }
95 /* Check for an already-allocated window that must conflict with
96 * what was asked for. It is a hack because it does not catch all
97 * potential conflicts, just the most obvious ones.
98 */
99 for (i = 0; i < MAX_IO_WIN; i++)
100 if ((s->io[i].NumPorts != 0) &&
101 ((s->io[i].BasePort & (align-1)) == *base))
102 return 1;
103 for (i = 0; i < MAX_IO_WIN; i++) {
104 if (s->io[i].NumPorts == 0) {
105 s->io[i].res = pcmcia_find_io_region(*base, num, align, s);
106 if (s->io[i].res) {
107 s->io[i].Attributes = attr;
108 s->io[i].BasePort = *base = s->io[i].res->start;
109 s->io[i].NumPorts = s->io[i].InUse = num;
110 break;
111 } else
112 return 1;
113 } else if (s->io[i].Attributes != attr)
114 continue;
115 /* Try to extend top of window */
116 try = s->io[i].BasePort + s->io[i].NumPorts;
117 if ((*base == 0) || (*base == try))
118 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start,
119 s->io[i].res->end + num, s) == 0) {
120 *base = try;
121 s->io[i].NumPorts += num;
122 s->io[i].InUse += num;
123 break;
124 }
125 /* Try to extend bottom of window */
126 try = s->io[i].BasePort - num;
127 if ((*base == 0) || (*base == try))
128 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num,
129 s->io[i].res->end, s) == 0) {
130 s->io[i].BasePort = *base = try;
131 s->io[i].NumPorts += num;
132 s->io[i].InUse += num;
133 break;
134 }
135 }
136 return (i == MAX_IO_WIN);
137} /* alloc_io_space */
138
139
140static void release_io_space(struct pcmcia_socket *s, ioaddr_t base,
141 ioaddr_t num)
142{
143 int i;
144
145 for (i = 0; i < MAX_IO_WIN; i++) {
146 if ((s->io[i].BasePort <= base) &&
147 (s->io[i].BasePort+s->io[i].NumPorts >= base+num)) {
148 s->io[i].InUse -= num;
149 /* Free the window if no one else is using it */
150 if (s->io[i].InUse == 0) {
151 s->io[i].NumPorts = 0;
152 release_resource(s->io[i].res);
153 kfree(s->io[i].res);
154 s->io[i].res = NULL;
155 }
156 }
157 }
158} /* release_io_space */
159
160
161/** pccard_access_configuration_register
162 *
163 * Access_configuration_register() reads and writes configuration
164 * registers in attribute memory. Memory window 0 is reserved for
165 * this and the tuple reading services.
166 */
167
168int pccard_access_configuration_register(struct pcmcia_socket *s,
169 unsigned int function,
170 conf_reg_t *reg)
171{
172 config_t *c;
173 int addr;
174 u_char val;
175
176 if (!s || !s->config)
177 return CS_NO_CARD;
178
179 c = &s->config[function];
180
181 if (c == NULL)
182 return CS_NO_CARD;
183
184 if (!(c->state & CONFIG_LOCKED))
185 return CS_CONFIGURATION_LOCKED;
186
187 addr = (c->ConfigBase + reg->Offset) >> 1;
188
189 switch (reg->Action) {
190 case CS_READ:
191 pcmcia_read_cis_mem(s, 1, addr, 1, &val);
192 reg->Value = val;
193 break;
194 case CS_WRITE:
195 val = reg->Value;
196 pcmcia_write_cis_mem(s, 1, addr, 1, &val);
197 break;
198 default:
199 return CS_BAD_ARGS;
200 break;
201 }
202 return CS_SUCCESS;
203} /* pccard_access_configuration_register */
204
205int pcmcia_access_configuration_register(client_handle_t handle,
206 conf_reg_t *reg)
207{
208 struct pcmcia_socket *s;
209 if (CHECK_HANDLE(handle))
210 return CS_BAD_HANDLE;
211 s = SOCKET(handle);
212 return pccard_access_configuration_register(s, handle->Function, reg);
213}
214EXPORT_SYMBOL(pcmcia_access_configuration_register);
215
216
217
218int pccard_get_configuration_info(struct pcmcia_socket *s,
219 unsigned int function,
220 config_info_t *config)
221{
222 config_t *c;
223
224 if (!(s->state & SOCKET_PRESENT))
225 return CS_NO_CARD;
226
227 config->Function = function;
228
229#ifdef CONFIG_CARDBUS
230 if (s->state & SOCKET_CARDBUS) {
231 memset(config, 0, sizeof(config_info_t));
232 config->Vcc = s->socket.Vcc;
233 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
234 config->Option = s->cb_dev->subordinate->number;
235 if (s->state & SOCKET_CARDBUS_CONFIG) {
236 config->Attributes = CONF_VALID_CLIENT;
237 config->IntType = INT_CARDBUS;
238 config->AssignedIRQ = s->irq.AssignedIRQ;
239 if (config->AssignedIRQ)
240 config->Attributes |= CONF_ENABLE_IRQ;
241 config->BasePort1 = s->io[0].BasePort;
242 config->NumPorts1 = s->io[0].NumPorts;
243 }
244 return CS_SUCCESS;
245 }
246#endif
247
248 c = (s->config != NULL) ? &s->config[function] : NULL;
249
250 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
251 config->Attributes = 0;
252 config->Vcc = s->socket.Vcc;
253 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
254 return CS_SUCCESS;
255 }
256
257 /* !!! This is a hack !!! */
258 memcpy(&config->Attributes, &c->Attributes, sizeof(config_t));
259 config->Attributes |= CONF_VALID_CLIENT;
260 config->CardValues = c->CardValues;
261 config->IRQAttributes = c->irq.Attributes;
262 config->AssignedIRQ = s->irq.AssignedIRQ;
263 config->BasePort1 = c->io.BasePort1;
264 config->NumPorts1 = c->io.NumPorts1;
265 config->Attributes1 = c->io.Attributes1;
266 config->BasePort2 = c->io.BasePort2;
267 config->NumPorts2 = c->io.NumPorts2;
268 config->Attributes2 = c->io.Attributes2;
269 config->IOAddrLines = c->io.IOAddrLines;
270
271 return CS_SUCCESS;
272} /* pccard_get_configuration_info */
273
274int pcmcia_get_configuration_info(client_handle_t handle,
275 config_info_t *config)
276{
277 struct pcmcia_socket *s;
278
279 if ((CHECK_HANDLE(handle)) || !config)
280 return CS_BAD_HANDLE;
281 s = SOCKET(handle);
282 if (!s)
283 return CS_BAD_HANDLE;
284 return pccard_get_configuration_info(s, handle->Function, config);
285}
286EXPORT_SYMBOL(pcmcia_get_configuration_info);
287
288
289/** pcmcia_get_window
290 */
291int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
292 int idx, win_req_t *req)
293{
294 window_t *win;
295 int w;
296
297 if (!s || !(s->state & SOCKET_PRESENT))
298 return CS_NO_CARD;
299 for (w = idx; w < MAX_WIN; w++)
300 if (s->state & SOCKET_WIN_REQ(w))
301 break;
302 if (w == MAX_WIN)
303 return CS_NO_MORE_ITEMS;
304 win = &s->win[w];
305 req->Base = win->ctl.res->start;
306 req->Size = win->ctl.res->end - win->ctl.res->start + 1;
307 req->AccessSpeed = win->ctl.speed;
308 req->Attributes = 0;
309 if (win->ctl.flags & MAP_ATTRIB)
310 req->Attributes |= WIN_MEMORY_TYPE_AM;
311 if (win->ctl.flags & MAP_ACTIVE)
312 req->Attributes |= WIN_ENABLE;
313 if (win->ctl.flags & MAP_16BIT)
314 req->Attributes |= WIN_DATA_WIDTH_16;
315 if (win->ctl.flags & MAP_USE_WAIT)
316 req->Attributes |= WIN_USE_WAIT;
317 *handle = win;
318 return CS_SUCCESS;
319} /* pcmcia_get_window */
320EXPORT_SYMBOL(pcmcia_get_window);
321
322
323/** pccard_get_status
324 *
325 * Get the current socket state bits. We don't support the latched
326 * SocketState yet: I haven't seen any point for it.
327 */
328
329int pccard_get_status(struct pcmcia_socket *s, unsigned int function,
330 cs_status_t *status)
331{
332 config_t *c;
333 int val;
334
335 s->ops->get_status(s, &val);
336 status->CardState = status->SocketState = 0;
337 status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0;
338 status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0;
339 status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0;
340 status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0;
341 if (s->state & SOCKET_SUSPEND)
342 status->CardState |= CS_EVENT_PM_SUSPEND;
343 if (!(s->state & SOCKET_PRESENT))
344 return CS_NO_CARD;
345
346 c = (s->config != NULL) ? &s->config[function] : NULL;
347 if ((c != NULL) && (c->state & CONFIG_LOCKED) &&
348 (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
349 u_char reg;
350 if (c->Present & PRESENT_PIN_REPLACE) {
351 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg);
352 status->CardState |=
353 (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
354 status->CardState |=
355 (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0;
356 status->CardState |=
357 (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0;
358 status->CardState |=
359 (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0;
360 } else {
361 /* No PRR? Then assume we're always ready */
362 status->CardState |= CS_EVENT_READY_CHANGE;
363 }
364 if (c->Present & PRESENT_EXT_STATUS) {
365 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg);
366 status->CardState |=
367 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
368 }
369 return CS_SUCCESS;
370 }
371 status->CardState |=
372 (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0;
373 status->CardState |=
374 (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0;
375 status->CardState |=
376 (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0;
377 status->CardState |=
378 (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0;
379 return CS_SUCCESS;
380} /* pccard_get_status */
381
382int pcmcia_get_status(client_handle_t handle, cs_status_t *status)
383{
384 struct pcmcia_socket *s;
385 if (CHECK_HANDLE(handle))
386 return CS_BAD_HANDLE;
387 s = SOCKET(handle);
388 return pccard_get_status(s, handle->Function, status);
389}
390EXPORT_SYMBOL(pcmcia_get_status);
391
392
393
394/** pcmcia_get_mem_page
395 *
396 * Change the card address of an already open memory window.
397 */
398int pcmcia_get_mem_page(window_handle_t win, memreq_t *req)
399{
400 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
401 return CS_BAD_HANDLE;
402 req->Page = 0;
403 req->CardOffset = win->ctl.card_start;
404 return CS_SUCCESS;
405} /* pcmcia_get_mem_page */
406EXPORT_SYMBOL(pcmcia_get_mem_page);
407
408
409int pcmcia_map_mem_page(window_handle_t win, memreq_t *req)
410{
411 struct pcmcia_socket *s;
412 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
413 return CS_BAD_HANDLE;
414 if (req->Page != 0)
415 return CS_BAD_PAGE;
416 s = win->sock;
417 win->ctl.card_start = req->CardOffset;
418 if (s->ops->set_mem_map(s, &win->ctl) != 0)
419 return CS_BAD_OFFSET;
420 return CS_SUCCESS;
421} /* pcmcia_map_mem_page */
422EXPORT_SYMBOL(pcmcia_map_mem_page);
423
424
425/** pcmcia_modify_configuration
426 *
427 * Modify a locked socket configuration
428 */
429int pcmcia_modify_configuration(client_handle_t handle,
430 modconf_t *mod)
431{
432 struct pcmcia_socket *s;
433 config_t *c;
434
435 if (CHECK_HANDLE(handle))
436 return CS_BAD_HANDLE;
437 s = SOCKET(handle);
438 c = CONFIG(handle);
439 if (!(s->state & SOCKET_PRESENT))
440 return CS_NO_CARD;
441 if (!(c->state & CONFIG_LOCKED))
442 return CS_CONFIGURATION_LOCKED;
443
444 if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
445 if (mod->Attributes & CONF_ENABLE_IRQ) {
446 c->Attributes |= CONF_ENABLE_IRQ;
447 s->socket.io_irq = s->irq.AssignedIRQ;
448 } else {
449 c->Attributes &= ~CONF_ENABLE_IRQ;
450 s->socket.io_irq = 0;
451 }
452 s->ops->set_socket(s, &s->socket);
453 }
454
455 if (mod->Attributes & CONF_VCC_CHANGE_VALID)
456 return CS_BAD_VCC;
457
458 /* We only allow changing Vpp1 and Vpp2 to the same value */
459 if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
460 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
461 if (mod->Vpp1 != mod->Vpp2)
462 return CS_BAD_VPP;
463 c->Vpp1 = c->Vpp2 = s->socket.Vpp = mod->Vpp1;
464 if (s->ops->set_socket(s, &s->socket))
465 return CS_BAD_VPP;
466 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
467 (mod->Attributes & CONF_VPP2_CHANGE_VALID))
468 return CS_BAD_VPP;
469
470 return CS_SUCCESS;
471} /* modify_configuration */
472EXPORT_SYMBOL(pcmcia_modify_configuration);
473
474
475int pcmcia_release_configuration(client_handle_t handle)
476{
477 pccard_io_map io = { 0, 0, 0, 0, 1 };
478 struct pcmcia_socket *s;
479 int i;
480
481 if (CHECK_HANDLE(handle) ||
482 !(handle->state & CLIENT_CONFIG_LOCKED))
483 return CS_BAD_HANDLE;
484 handle->state &= ~CLIENT_CONFIG_LOCKED;
485 s = SOCKET(handle);
486
487#ifdef CONFIG_CARDBUS
488 if (handle->state & CLIENT_CARDBUS)
489 return CS_SUCCESS;
490#endif
491
492 if (!(handle->state & CLIENT_STALE)) {
493 config_t *c = CONFIG(handle);
494 if (--(s->lock_count) == 0) {
495 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */
496 s->socket.Vpp = 0;
497 s->socket.io_irq = 0;
498 s->ops->set_socket(s, &s->socket);
499 }
500 if (c->state & CONFIG_IO_REQ)
501 for (i = 0; i < MAX_IO_WIN; i++) {
502 if (s->io[i].NumPorts == 0)
503 continue;
504 s->io[i].Config--;
505 if (s->io[i].Config != 0)
506 continue;
507 io.map = i;
508 s->ops->set_io_map(s, &io);
509 }
510 c->state &= ~CONFIG_LOCKED;
511 }
512
513 return CS_SUCCESS;
514} /* pcmcia_release_configuration */
515EXPORT_SYMBOL(pcmcia_release_configuration);
516
517
518/** pcmcia_release_io
519 *
520 * Release_io() releases the I/O ranges allocated by a client. This
521 * may be invoked some time after a card ejection has already dumped
522 * the actual socket configuration, so if the client is "stale", we
523 * don't bother checking the port ranges against the current socket
524 * values.
525 */
526int pcmcia_release_io(client_handle_t handle, io_req_t *req)
527{
528 struct pcmcia_socket *s;
529
530 if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IO_REQ))
531 return CS_BAD_HANDLE;
532 handle->state &= ~CLIENT_IO_REQ;
533 s = SOCKET(handle);
534
535#ifdef CONFIG_CARDBUS
536 if (handle->state & CLIENT_CARDBUS)
537 return CS_SUCCESS;
538#endif
539
540 if (!(handle->state & CLIENT_STALE)) {
541 config_t *c = CONFIG(handle);
542 if (c->state & CONFIG_LOCKED)
543 return CS_CONFIGURATION_LOCKED;
544 if ((c->io.BasePort1 != req->BasePort1) ||
545 (c->io.NumPorts1 != req->NumPorts1) ||
546 (c->io.BasePort2 != req->BasePort2) ||
547 (c->io.NumPorts2 != req->NumPorts2))
548 return CS_BAD_ARGS;
549 c->state &= ~CONFIG_IO_REQ;
550 }
551
552 release_io_space(s, req->BasePort1, req->NumPorts1);
553 if (req->NumPorts2)
554 release_io_space(s, req->BasePort2, req->NumPorts2);
555
556 return CS_SUCCESS;
557} /* pcmcia_release_io */
558EXPORT_SYMBOL(pcmcia_release_io);
559
560
561int pcmcia_release_irq(client_handle_t handle, irq_req_t *req)
562{
563 struct pcmcia_socket *s;
564 if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IRQ_REQ))
565 return CS_BAD_HANDLE;
566 handle->state &= ~CLIENT_IRQ_REQ;
567 s = SOCKET(handle);
568
569 if (!(handle->state & CLIENT_STALE)) {
570 config_t *c = CONFIG(handle);
571 if (c->state & CONFIG_LOCKED)
572 return CS_CONFIGURATION_LOCKED;
573 if (c->irq.Attributes != req->Attributes)
574 return CS_BAD_ATTRIBUTE;
575 if (s->irq.AssignedIRQ != req->AssignedIRQ)
576 return CS_BAD_IRQ;
577 if (--s->irq.Config == 0) {
578 c->state &= ~CONFIG_IRQ_REQ;
579 s->irq.AssignedIRQ = 0;
580 }
581 }
582
583 if (req->Attributes & IRQ_HANDLE_PRESENT) {
584 free_irq(req->AssignedIRQ, req->Instance);
585 }
586
587#ifdef CONFIG_PCMCIA_PROBE
588 pcmcia_used_irq[req->AssignedIRQ]--;
589#endif
590
591 return CS_SUCCESS;
592} /* pcmcia_release_irq */
593EXPORT_SYMBOL(pcmcia_release_irq);
594
595
596int pcmcia_release_window(window_handle_t win)
597{
598 struct pcmcia_socket *s;
599
600 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
601 return CS_BAD_HANDLE;
602 s = win->sock;
603 if (!(win->handle->state & CLIENT_WIN_REQ(win->index)))
604 return CS_BAD_HANDLE;
605
606 /* Shut down memory window */
607 win->ctl.flags &= ~MAP_ACTIVE;
608 s->ops->set_mem_map(s, &win->ctl);
609 s->state &= ~SOCKET_WIN_REQ(win->index);
610
611 /* Release system memory */
612 if (win->ctl.res) {
613 release_resource(win->ctl.res);
614 kfree(win->ctl.res);
615 win->ctl.res = NULL;
616 }
617 win->handle->state &= ~CLIENT_WIN_REQ(win->index);
618
619 win->magic = 0;
620
621 return CS_SUCCESS;
622} /* pcmcia_release_window */
623EXPORT_SYMBOL(pcmcia_release_window);
624
625
626int pcmcia_request_configuration(client_handle_t handle,
627 config_req_t *req)
628{
629 int i;
630 u_int base;
631 struct pcmcia_socket *s;
632 config_t *c;
633 pccard_io_map iomap;
634
635 if (CHECK_HANDLE(handle))
636 return CS_BAD_HANDLE;
637 s = SOCKET(handle);
638 if (!(s->state & SOCKET_PRESENT))
639 return CS_NO_CARD;
640
641#ifdef CONFIG_CARDBUS
642 if (handle->state & CLIENT_CARDBUS)
643 return CS_UNSUPPORTED_MODE;
644#endif
645
646 if (req->IntType & INT_CARDBUS)
647 return CS_UNSUPPORTED_MODE;
648 c = CONFIG(handle);
649 if (c->state & CONFIG_LOCKED)
650 return CS_CONFIGURATION_LOCKED;
651
652 /* Do power control. We don't allow changes in Vcc. */
653 if (s->socket.Vcc != req->Vcc)
654 return CS_BAD_VCC;
655 if (req->Vpp1 != req->Vpp2)
656 return CS_BAD_VPP;
657 s->socket.Vpp = req->Vpp1;
658 if (s->ops->set_socket(s, &s->socket))
659 return CS_BAD_VPP;
660
661 c->Vcc = req->Vcc; c->Vpp1 = c->Vpp2 = req->Vpp1;
662
663 /* Pick memory or I/O card, DMA mode, interrupt */
664 c->IntType = req->IntType;
665 c->Attributes = req->Attributes;
666 if (req->IntType & INT_MEMORY_AND_IO)
667 s->socket.flags |= SS_IOCARD;
668 if (req->IntType & INT_ZOOMED_VIDEO)
669 s->socket.flags |= SS_ZVCARD | SS_IOCARD;
670 if (req->Attributes & CONF_ENABLE_DMA)
671 s->socket.flags |= SS_DMA_MODE;
672 if (req->Attributes & CONF_ENABLE_SPKR)
673 s->socket.flags |= SS_SPKR_ENA;
674 if (req->Attributes & CONF_ENABLE_IRQ)
675 s->socket.io_irq = s->irq.AssignedIRQ;
676 else
677 s->socket.io_irq = 0;
678 s->ops->set_socket(s, &s->socket);
679 s->lock_count++;
680
681 /* Set up CIS configuration registers */
682 base = c->ConfigBase = req->ConfigBase;
683 c->Present = c->CardValues = req->Present;
684 if (req->Present & PRESENT_COPY) {
685 c->Copy = req->Copy;
686 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy);
687 }
688 if (req->Present & PRESENT_OPTION) {
689 if (s->functions == 1) {
690 c->Option = req->ConfigIndex & COR_CONFIG_MASK;
691 } else {
692 c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK;
693 c->Option |= COR_FUNC_ENA|COR_IREQ_ENA;
694 if (req->Present & PRESENT_IOBASE_0)
695 c->Option |= COR_ADDR_DECODE;
696 }
697 if (c->state & CONFIG_IRQ_REQ)
698 if (!(c->irq.Attributes & IRQ_FORCED_PULSE))
699 c->Option |= COR_LEVEL_REQ;
700 pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option);
701 mdelay(40);
702 }
703 if (req->Present & PRESENT_STATUS) {
704 c->Status = req->Status;
705 pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status);
706 }
707 if (req->Present & PRESENT_PIN_REPLACE) {
708 c->Pin = req->Pin;
709 pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin);
710 }
711 if (req->Present & PRESENT_EXT_STATUS) {
712 c->ExtStatus = req->ExtStatus;
713 pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus);
714 }
715 if (req->Present & PRESENT_IOBASE_0) {
716 u_char b = c->io.BasePort1 & 0xff;
717 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
718 b = (c->io.BasePort1 >> 8) & 0xff;
719 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
720 }
721 if (req->Present & PRESENT_IOSIZE) {
722 u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1;
723 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
724 }
725
726 /* Configure I/O windows */
727 if (c->state & CONFIG_IO_REQ) {
728 iomap.speed = io_speed;
729 for (i = 0; i < MAX_IO_WIN; i++)
730 if (s->io[i].NumPorts != 0) {
731 iomap.map = i;
732 iomap.flags = MAP_ACTIVE;
733 switch (s->io[i].Attributes & IO_DATA_PATH_WIDTH) {
734 case IO_DATA_PATH_WIDTH_16:
735 iomap.flags |= MAP_16BIT; break;
736 case IO_DATA_PATH_WIDTH_AUTO:
737 iomap.flags |= MAP_AUTOSZ; break;
738 default:
739 break;
740 }
741 iomap.start = s->io[i].BasePort;
742 iomap.stop = iomap.start + s->io[i].NumPorts - 1;
743 s->ops->set_io_map(s, &iomap);
744 s->io[i].Config++;
745 }
746 }
747
748 c->state |= CONFIG_LOCKED;
749 handle->state |= CLIENT_CONFIG_LOCKED;
750 return CS_SUCCESS;
751} /* pcmcia_request_configuration */
752EXPORT_SYMBOL(pcmcia_request_configuration);
753
754
755/** pcmcia_request_io
756 *
757 * Request_io() reserves ranges of port addresses for a socket.
758 * I have not implemented range sharing or alias addressing.
759 */
760int pcmcia_request_io(client_handle_t handle, io_req_t *req)
761{
762 struct pcmcia_socket *s;
763 config_t *c;
764
765 if (CHECK_HANDLE(handle))
766 return CS_BAD_HANDLE;
767 s = SOCKET(handle);
768 if (!(s->state & SOCKET_PRESENT))
769 return CS_NO_CARD;
770
771 if (handle->state & CLIENT_CARDBUS) {
772#ifdef CONFIG_CARDBUS
773 handle->state |= CLIENT_IO_REQ;
774 return CS_SUCCESS;
775#else
776 return CS_UNSUPPORTED_FUNCTION;
777#endif
778 }
779
780 if (!req)
781 return CS_UNSUPPORTED_MODE;
782 c = CONFIG(handle);
783 if (c->state & CONFIG_LOCKED)
784 return CS_CONFIGURATION_LOCKED;
785 if (c->state & CONFIG_IO_REQ)
786 return CS_IN_USE;
787 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))
788 return CS_BAD_ATTRIBUTE;
789 if ((req->NumPorts2 > 0) &&
790 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)))
791 return CS_BAD_ATTRIBUTE;
792
793 if (alloc_io_space(s, req->Attributes1, &req->BasePort1,
794 req->NumPorts1, req->IOAddrLines))
795 return CS_IN_USE;
796
797 if (req->NumPorts2) {
798 if (alloc_io_space(s, req->Attributes2, &req->BasePort2,
799 req->NumPorts2, req->IOAddrLines)) {
800 release_io_space(s, req->BasePort1, req->NumPorts1);
801 return CS_IN_USE;
802 }
803 }
804
805 c->io = *req;
806 c->state |= CONFIG_IO_REQ;
807 handle->state |= CLIENT_IO_REQ;
808 return CS_SUCCESS;
809} /* pcmcia_request_io */
810EXPORT_SYMBOL(pcmcia_request_io);
811
812
813/** pcmcia_request_irq
814 *
815 * Request_irq() reserves an irq for this client.
816 *
817 * Also, since Linux only reserves irq's when they are actually
818 * hooked, we don't guarantee that an irq will still be available
819 * when the configuration is locked. Now that I think about it,
820 * there might be a way to fix this using a dummy handler.
821 */
822
823#ifdef CONFIG_PCMCIA_PROBE
824static irqreturn_t test_action(int cpl, void *dev_id, struct pt_regs *regs)
825{
826 return IRQ_NONE;
827}
828#endif
829
830int pcmcia_request_irq(client_handle_t handle, irq_req_t *req)
831{
832 struct pcmcia_socket *s;
833 config_t *c;
834 int ret = CS_IN_USE, irq = 0;
835 struct pcmcia_device *p_dev = handle_to_pdev(handle);
836
837 if (CHECK_HANDLE(handle))
838 return CS_BAD_HANDLE;
839 s = SOCKET(handle);
840 if (!(s->state & SOCKET_PRESENT))
841 return CS_NO_CARD;
842 c = CONFIG(handle);
843 if (c->state & CONFIG_LOCKED)
844 return CS_CONFIGURATION_LOCKED;
845 if (c->state & CONFIG_IRQ_REQ)
846 return CS_IN_USE;
847
848#ifdef CONFIG_PCMCIA_PROBE
849 if (s->irq.AssignedIRQ != 0) {
850 /* If the interrupt is already assigned, it must be the same */
851 irq = s->irq.AssignedIRQ;
852 } else {
853 int try;
854 u32 mask = s->irq_mask;
855 void *data = NULL;
856
857 for (try = 0; try < 64; try++) {
858 irq = try % 32;
859
860 /* marked as available by driver, and not blocked by userspace? */
861 if (!((mask >> irq) & 1))
862 continue;
863
864 /* avoid an IRQ which is already used by a PCMCIA card */
865 if ((try < 32) && pcmcia_used_irq[irq])
866 continue;
867
868 /* register the correct driver, if possible, of check whether
869 * registering a dummy handle works, i.e. if the IRQ isn't
870 * marked as used by the kernel resource management core */
871 ret = request_irq(irq,
872 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action,
873 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
874 (s->functions > 1) ||
875 (irq == s->pci_irq)) ? SA_SHIRQ : 0,
876 p_dev->dev.bus_id,
877 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data);
878 if (!ret) {
879 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
880 free_irq(irq, data);
881 break;
882 }
883 }
884 }
885#endif
886 if (ret) {
887 if (!s->pci_irq)
888 return ret;
889 irq = s->pci_irq;
890 }
891
892 if (ret && req->Attributes & IRQ_HANDLE_PRESENT) {
893 if (request_irq(irq, req->Handler,
894 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
895 (s->functions > 1) ||
896 (irq == s->pci_irq)) ? SA_SHIRQ : 0,
897 p_dev->dev.bus_id, req->Instance))
898 return CS_IN_USE;
899 }
900
901 c->irq.Attributes = req->Attributes;
902 s->irq.AssignedIRQ = req->AssignedIRQ = irq;
903 s->irq.Config++;
904
905 c->state |= CONFIG_IRQ_REQ;
906 handle->state |= CLIENT_IRQ_REQ;
907
908#ifdef CONFIG_PCMCIA_PROBE
909 pcmcia_used_irq[irq]++;
910#endif
911
912 return CS_SUCCESS;
913} /* pcmcia_request_irq */
914EXPORT_SYMBOL(pcmcia_request_irq);
915
916
917/** pcmcia_request_window
918 *
919 * Request_window() establishes a mapping between card memory space
920 * and system memory space.
921 */
922int pcmcia_request_window(client_handle_t *handle, win_req_t *req, window_handle_t *wh)
923{
924 struct pcmcia_socket *s;
925 window_t *win;
926 u_long align;
927 int w;
928
929 if (CHECK_HANDLE(*handle))
930 return CS_BAD_HANDLE;
931 s = (*handle)->Socket;
932 if (!(s->state & SOCKET_PRESENT))
933 return CS_NO_CARD;
934 if (req->Attributes & (WIN_PAGED | WIN_SHARED))
935 return CS_BAD_ATTRIBUTE;
936
937 /* Window size defaults to smallest available */
938 if (req->Size == 0)
939 req->Size = s->map_size;
940 align = (((s->features & SS_CAP_MEM_ALIGN) ||
941 (req->Attributes & WIN_STRICT_ALIGN)) ?
942 req->Size : s->map_size);
943 if (req->Size & (s->map_size-1))
944 return CS_BAD_SIZE;
945 if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) ||
946 (req->Base & (align-1)))
947 return CS_BAD_BASE;
948 if (req->Base)
949 align = 0;
950
951 /* Allocate system memory window */
952 for (w = 0; w < MAX_WIN; w++)
953 if (!(s->state & SOCKET_WIN_REQ(w))) break;
954 if (w == MAX_WIN)
955 return CS_OUT_OF_RESOURCE;
956
957 win = &s->win[w];
958 win->magic = WINDOW_MAGIC;
959 win->index = w;
960 win->handle = *handle;
961 win->sock = s;
962
963 if (!(s->features & SS_CAP_STATIC_MAP)) {
964 win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align,
965 (req->Attributes & WIN_MAP_BELOW_1MB), s);
966 if (!win->ctl.res)
967 return CS_IN_USE;
968 }
969 (*handle)->state |= CLIENT_WIN_REQ(w);
970
971 /* Configure the socket controller */
972 win->ctl.map = w+1;
973 win->ctl.flags = 0;
974 win->ctl.speed = req->AccessSpeed;
975 if (req->Attributes & WIN_MEMORY_TYPE)
976 win->ctl.flags |= MAP_ATTRIB;
977 if (req->Attributes & WIN_ENABLE)
978 win->ctl.flags |= MAP_ACTIVE;
979 if (req->Attributes & WIN_DATA_WIDTH_16)
980 win->ctl.flags |= MAP_16BIT;
981 if (req->Attributes & WIN_USE_WAIT)
982 win->ctl.flags |= MAP_USE_WAIT;
983 win->ctl.card_start = 0;
984 if (s->ops->set_mem_map(s, &win->ctl) != 0)
985 return CS_BAD_ARGS;
986 s->state |= SOCKET_WIN_REQ(w);
987
988 /* Return window handle */
989 if (s->features & SS_CAP_STATIC_MAP) {
990 req->Base = win->ctl.static_start;
991 } else {
992 req->Base = win->ctl.res->start;
993 }
994 *wh = win;
995
996 return CS_SUCCESS;
997} /* pcmcia_request_window */
998EXPORT_SYMBOL(pcmcia_request_window);
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c
index b6843f8d300d..0668384ebc8b 100644
--- a/drivers/pcmcia/rsrc_mgr.c
+++ b/drivers/pcmcia/rsrc_mgr.c
@@ -72,7 +72,7 @@ int pcmcia_adjust_resource_info(adjust_t *adj)
72 /* you can't use the old interface if the new 72 /* you can't use the old interface if the new
73 * one was used before */ 73 * one was used before */
74 spin_lock_irqsave(&s->lock, flags); 74 spin_lock_irqsave(&s->lock, flags);
75 if ((s->resource_setup_done) && 75 if ((s->resource_setup_new) &&
76 !(s->resource_setup_old)) { 76 !(s->resource_setup_old)) {
77 spin_unlock_irqrestore(&s->lock, flags); 77 spin_unlock_irqrestore(&s->lock, flags);
78 continue; 78 continue;
@@ -105,29 +105,32 @@ void pcmcia_validate_mem(struct pcmcia_socket *s)
105} 105}
106EXPORT_SYMBOL(pcmcia_validate_mem); 106EXPORT_SYMBOL(pcmcia_validate_mem);
107 107
108int adjust_io_region(struct resource *res, unsigned long r_start, 108int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start,
109 unsigned long r_end, struct pcmcia_socket *s) 109 unsigned long r_end, struct pcmcia_socket *s)
110{ 110{
111 if (s->resource_ops->adjust_io_region) 111 if (s->resource_ops->adjust_io_region)
112 return s->resource_ops->adjust_io_region(res, r_start, r_end, s); 112 return s->resource_ops->adjust_io_region(res, r_start, r_end, s);
113 return -ENOMEM; 113 return -ENOMEM;
114} 114}
115EXPORT_SYMBOL(pcmcia_adjust_io_region);
115 116
116struct resource *find_io_region(unsigned long base, int num, 117struct resource *pcmcia_find_io_region(unsigned long base, int num,
117 unsigned long align, struct pcmcia_socket *s) 118 unsigned long align, struct pcmcia_socket *s)
118{ 119{
119 if (s->resource_ops->find_io) 120 if (s->resource_ops->find_io)
120 return s->resource_ops->find_io(base, num, align, s); 121 return s->resource_ops->find_io(base, num, align, s);
121 return NULL; 122 return NULL;
122} 123}
124EXPORT_SYMBOL(pcmcia_find_io_region);
123 125
124struct resource *find_mem_region(u_long base, u_long num, u_long align, 126struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
125 int low, struct pcmcia_socket *s) 127 int low, struct pcmcia_socket *s)
126{ 128{
127 if (s->resource_ops->find_mem) 129 if (s->resource_ops->find_mem)
128 return s->resource_ops->find_mem(base, num, align, low, s); 130 return s->resource_ops->find_mem(base, num, align, low, s);
129 return NULL; 131 return NULL;
130} 132}
133EXPORT_SYMBOL(pcmcia_find_mem_region);
131 134
132void release_resource_db(struct pcmcia_socket *s) 135void release_resource_db(struct pcmcia_socket *s)
133{ 136{
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index 5876bab7c14c..c42455d20eb6 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -372,6 +372,9 @@ static int do_mem_probe(u_long base, u_long num, struct pcmcia_socket *s)
372 base, base+num-1); 372 base, base+num-1);
373 bad = fail = 0; 373 bad = fail = 0;
374 step = (num < 0x20000) ? 0x2000 : ((num>>4) & ~0x1fff); 374 step = (num < 0x20000) ? 0x2000 : ((num>>4) & ~0x1fff);
375 /* don't allow too large steps */
376 if (step > 0x800000)
377 step = 0x800000;
375 /* cis_readable wants to map 2x map_size */ 378 /* cis_readable wants to map 2x map_size */
376 if (step < 2 * s->map_size) 379 if (step < 2 * s->map_size)
377 step = 2 * s->map_size; 380 step = 2 * s->map_size;
@@ -465,8 +468,7 @@ static void validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
465 468
466 for (m = s_data->mem_db.next; m != &s_data->mem_db; m = mm.next) { 469 for (m = s_data->mem_db.next; m != &s_data->mem_db; m = mm.next) {
467 mm = *m; 470 mm = *m;
468 if (do_mem_probe(mm.base, mm.num, s)) 471 do_mem_probe(mm.base, mm.num, s);
469 break;
470 } 472 }
471} 473}
472 474
@@ -601,7 +603,7 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star
601 603
602======================================================================*/ 604======================================================================*/
603 605
604struct resource *nonstatic_find_io_region(unsigned long base, int num, 606static struct resource *nonstatic_find_io_region(unsigned long base, int num,
605 unsigned long align, struct pcmcia_socket *s) 607 unsigned long align, struct pcmcia_socket *s)
606{ 608{
607 struct resource *res = make_resource(0, num, IORESOURCE_IO, s->dev.class_id); 609 struct resource *res = make_resource(0, num, IORESOURCE_IO, s->dev.class_id);
@@ -635,8 +637,8 @@ struct resource *nonstatic_find_io_region(unsigned long base, int num,
635 return res; 637 return res;
636} 638}
637 639
638struct resource * nonstatic_find_mem_region(u_long base, u_long num, u_long align, 640static struct resource * nonstatic_find_mem_region(u_long base, u_long num,
639 int low, struct pcmcia_socket *s) 641 u_long align, int low, struct pcmcia_socket *s)
640{ 642{
641 struct resource *res = make_resource(0, num, IORESOURCE_MEM, s->dev.class_id); 643 struct resource *res = make_resource(0, num, IORESOURCE_MEM, s->dev.class_id);
642 struct socket_data *s_data = s->resource_data; 644 struct socket_data *s_data = s->resource_data;
@@ -683,27 +685,23 @@ struct resource * nonstatic_find_mem_region(u_long base, u_long num, u_long alig
683} 685}
684 686
685 687
686static int adjust_memory(struct pcmcia_socket *s, adjust_t *adj) 688static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned long start, unsigned long end)
687{ 689{
688 u_long base, num;
689 struct socket_data *data = s->resource_data; 690 struct socket_data *data = s->resource_data;
690 int ret; 691 unsigned long size = end - start + 1;
691 692 int ret = 0;
692 base = adj->resource.memory.Base;
693 num = adj->resource.memory.Size;
694 if ((num == 0) || (base+num-1 < base))
695 return CS_BAD_SIZE;
696 693
697 ret = CS_SUCCESS; 694 if (end <= start)
695 return -EINVAL;
698 696
699 down(&rsrc_sem); 697 down(&rsrc_sem);
700 switch (adj->Action) { 698 switch (action) {
701 case ADD_MANAGED_RESOURCE: 699 case ADD_MANAGED_RESOURCE:
702 ret = add_interval(&data->mem_db, base, num); 700 ret = add_interval(&data->mem_db, start, size);
703 break; 701 break;
704 case REMOVE_MANAGED_RESOURCE: 702 case REMOVE_MANAGED_RESOURCE:
705 ret = sub_interval(&data->mem_db, base, num); 703 ret = sub_interval(&data->mem_db, start, size);
706 if (ret == CS_SUCCESS) { 704 if (!ret) {
707 struct pcmcia_socket *socket; 705 struct pcmcia_socket *socket;
708 down_read(&pcmcia_socket_list_rwsem); 706 down_read(&pcmcia_socket_list_rwsem);
709 list_for_each_entry(socket, &pcmcia_socket_list, socket_list) 707 list_for_each_entry(socket, &pcmcia_socket_list, socket_list)
@@ -712,7 +710,7 @@ static int adjust_memory(struct pcmcia_socket *s, adjust_t *adj)
712 } 710 }
713 break; 711 break;
714 default: 712 default:
715 ret = CS_UNSUPPORTED_FUNCTION; 713 ret = -EINVAL;
716 } 714 }
717 up(&rsrc_sem); 715 up(&rsrc_sem);
718 716
@@ -720,36 +718,35 @@ static int adjust_memory(struct pcmcia_socket *s, adjust_t *adj)
720} 718}
721 719
722 720
723static int adjust_io(struct pcmcia_socket *s, adjust_t *adj) 721static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long start, unsigned long end)
724{ 722{
725 struct socket_data *data = s->resource_data; 723 struct socket_data *data = s->resource_data;
726 kio_addr_t base, num; 724 unsigned long size = end - start + 1;
727 int ret = CS_SUCCESS; 725 int ret = 0;
728 726
729 base = adj->resource.io.BasePort; 727 if (end <= start)
730 num = adj->resource.io.NumPorts; 728 return -EINVAL;
731 if ((base < 0) || (base > 0xffff)) 729
732 return CS_BAD_BASE; 730 if (end > IO_SPACE_LIMIT)
733 if ((num <= 0) || (base+num > 0x10000) || (base+num <= base)) 731 return -EINVAL;
734 return CS_BAD_SIZE;
735 732
736 down(&rsrc_sem); 733 down(&rsrc_sem);
737 switch (adj->Action) { 734 switch (action) {
738 case ADD_MANAGED_RESOURCE: 735 case ADD_MANAGED_RESOURCE:
739 if (add_interval(&data->io_db, base, num) != 0) { 736 if (add_interval(&data->io_db, start, size) != 0) {
740 ret = CS_IN_USE; 737 ret = -EBUSY;
741 break; 738 break;
742 } 739 }
743#ifdef CONFIG_PCMCIA_PROBE 740#ifdef CONFIG_PCMCIA_PROBE
744 if (probe_io) 741 if (probe_io)
745 do_io_probe(s, base, num); 742 do_io_probe(s, start, size);
746#endif 743#endif
747 break; 744 break;
748 case REMOVE_MANAGED_RESOURCE: 745 case REMOVE_MANAGED_RESOURCE:
749 sub_interval(&data->io_db, base, num); 746 sub_interval(&data->io_db, start, size);
750 break; 747 break;
751 default: 748 default:
752 ret = CS_UNSUPPORTED_FUNCTION; 749 ret = -EINVAL;
753 break; 750 break;
754 } 751 }
755 up(&rsrc_sem); 752 up(&rsrc_sem);
@@ -760,15 +757,82 @@ static int adjust_io(struct pcmcia_socket *s, adjust_t *adj)
760 757
761static int nonstatic_adjust_resource_info(struct pcmcia_socket *s, adjust_t *adj) 758static int nonstatic_adjust_resource_info(struct pcmcia_socket *s, adjust_t *adj)
762{ 759{
760 unsigned long end;
761
763 switch (adj->Resource) { 762 switch (adj->Resource) {
764 case RES_MEMORY_RANGE: 763 case RES_MEMORY_RANGE:
765 return adjust_memory(s, adj); 764 end = adj->resource.memory.Base + adj->resource.memory.Size - 1;
765 return adjust_memory(s, adj->Action, adj->resource.memory.Base, end);
766 case RES_IO_RANGE: 766 case RES_IO_RANGE:
767 return adjust_io(s, adj); 767 end = adj->resource.io.BasePort + adj->resource.io.NumPorts - 1;
768 return adjust_io(s, adj->Action, adj->resource.io.BasePort, end);
768 } 769 }
769 return CS_UNSUPPORTED_FUNCTION; 770 return CS_UNSUPPORTED_FUNCTION;
770} 771}
771 772
773#ifdef CONFIG_PCI
774static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
775{
776 struct resource *res;
777 int i, done = 0;
778
779 if (!s->cb_dev || !s->cb_dev->bus)
780 return -ENODEV;
781
782#if defined(CONFIG_X86) || defined(CONFIG_X86_64)
783 /* If this is the root bus, the risk of hitting
784 * some strange system devices which aren't protected
785 * by either ACPI resource tables or properly requested
786 * resources is too big. Therefore, don't do auto-adding
787 * of resources at the moment.
788 */
789 if (s->cb_dev->bus->number == 0)
790 return -EINVAL;
791#endif
792
793 for (i=0; i < PCI_BUS_NUM_RESOURCES; i++) {
794 res = s->cb_dev->bus->resource[i];
795 if (!res)
796 continue;
797
798 if (res->flags & IORESOURCE_IO) {
799 if (res == &ioport_resource)
800 continue;
801 printk(KERN_INFO "pcmcia: parent PCI bridge I/O window: 0x%lx - 0x%lx\n",
802 res->start, res->end);
803 if (!adjust_io(s, ADD_MANAGED_RESOURCE, res->start, res->end))
804 done |= IORESOURCE_IO;
805
806 }
807
808 if (res->flags & IORESOURCE_MEM) {
809 if (res == &iomem_resource)
810 continue;
811 printk(KERN_INFO "pcmcia: parent PCI bridge Memory window: 0x%lx - 0x%lx\n",
812 res->start, res->end);
813 if (!adjust_memory(s, ADD_MANAGED_RESOURCE, res->start, res->end))
814 done |= IORESOURCE_MEM;
815 }
816 }
817
818 /* if we got at least one of IO, and one of MEM, we can be glad and
819 * activate the PCMCIA subsystem */
820 if (done & (IORESOURCE_MEM | IORESOURCE_IO))
821 s->resource_setup_done = 1;
822
823 return 0;
824}
825
826#else
827
828static inline int nonstatic_autoadd_resources(struct pcmcia_socket *s)
829{
830 return -ENODEV;
831}
832
833#endif
834
835
772static int nonstatic_init(struct pcmcia_socket *s) 836static int nonstatic_init(struct pcmcia_socket *s)
773{ 837{
774 struct socket_data *data; 838 struct socket_data *data;
@@ -783,6 +847,8 @@ static int nonstatic_init(struct pcmcia_socket *s)
783 847
784 s->resource_data = (void *) data; 848 s->resource_data = (void *) data;
785 849
850 nonstatic_autoadd_resources(s);
851
786 return 0; 852 return 0;
787} 853}
788 854
@@ -845,17 +911,16 @@ static ssize_t store_io_db(struct class_device *class_dev, const char *buf, size
845{ 911{
846 struct pcmcia_socket *s = class_get_devdata(class_dev); 912 struct pcmcia_socket *s = class_get_devdata(class_dev);
847 unsigned long start_addr, end_addr; 913 unsigned long start_addr, end_addr;
848 unsigned int add = 1; 914 unsigned int add = ADD_MANAGED_RESOURCE;
849 adjust_t adj;
850 ssize_t ret = 0; 915 ssize_t ret = 0;
851 916
852 ret = sscanf (buf, "+ 0x%lx - 0x%lx", &start_addr, &end_addr); 917 ret = sscanf (buf, "+ 0x%lx - 0x%lx", &start_addr, &end_addr);
853 if (ret != 2) { 918 if (ret != 2) {
854 ret = sscanf (buf, "- 0x%lx - 0x%lx", &start_addr, &end_addr); 919 ret = sscanf (buf, "- 0x%lx - 0x%lx", &start_addr, &end_addr);
855 add = 0; 920 add = REMOVE_MANAGED_RESOURCE;
856 if (ret != 2) { 921 if (ret != 2) {
857 ret = sscanf (buf, "0x%lx - 0x%lx", &start_addr, &end_addr); 922 ret = sscanf (buf, "0x%lx - 0x%lx", &start_addr, &end_addr);
858 add = 1; 923 add = ADD_MANAGED_RESOURCE;
859 if (ret != 2) 924 if (ret != 2)
860 return -EINVAL; 925 return -EINVAL;
861 } 926 }
@@ -863,12 +928,9 @@ static ssize_t store_io_db(struct class_device *class_dev, const char *buf, size
863 if (end_addr <= start_addr) 928 if (end_addr <= start_addr)
864 return -EINVAL; 929 return -EINVAL;
865 930
866 adj.Action = add ? ADD_MANAGED_RESOURCE : REMOVE_MANAGED_RESOURCE; 931 ret = adjust_io(s, add, start_addr, end_addr);
867 adj.Resource = RES_IO_RANGE; 932 if (!ret)
868 adj.resource.io.BasePort = start_addr; 933 s->resource_setup_new = 1;
869 adj.resource.io.NumPorts = end_addr - start_addr + 1;
870
871 ret = adjust_io(s, &adj);
872 934
873 return ret ? ret : count; 935 return ret ? ret : count;
874} 936}
@@ -901,17 +963,16 @@ static ssize_t store_mem_db(struct class_device *class_dev, const char *buf, siz
901{ 963{
902 struct pcmcia_socket *s = class_get_devdata(class_dev); 964 struct pcmcia_socket *s = class_get_devdata(class_dev);
903 unsigned long start_addr, end_addr; 965 unsigned long start_addr, end_addr;
904 unsigned int add = 1; 966 unsigned int add = ADD_MANAGED_RESOURCE;
905 adjust_t adj;
906 ssize_t ret = 0; 967 ssize_t ret = 0;
907 968
908 ret = sscanf (buf, "+ 0x%lx - 0x%lx", &start_addr, &end_addr); 969 ret = sscanf (buf, "+ 0x%lx - 0x%lx", &start_addr, &end_addr);
909 if (ret != 2) { 970 if (ret != 2) {
910 ret = sscanf (buf, "- 0x%lx - 0x%lx", &start_addr, &end_addr); 971 ret = sscanf (buf, "- 0x%lx - 0x%lx", &start_addr, &end_addr);
911 add = 0; 972 add = REMOVE_MANAGED_RESOURCE;
912 if (ret != 2) { 973 if (ret != 2) {
913 ret = sscanf (buf, "0x%lx - 0x%lx", &start_addr, &end_addr); 974 ret = sscanf (buf, "0x%lx - 0x%lx", &start_addr, &end_addr);
914 add = 1; 975 add = ADD_MANAGED_RESOURCE;
915 if (ret != 2) 976 if (ret != 2)
916 return -EINVAL; 977 return -EINVAL;
917 } 978 }
@@ -919,12 +980,9 @@ static ssize_t store_mem_db(struct class_device *class_dev, const char *buf, siz
919 if (end_addr <= start_addr) 980 if (end_addr <= start_addr)
920 return -EINVAL; 981 return -EINVAL;
921 982
922 adj.Action = add ? ADD_MANAGED_RESOURCE : REMOVE_MANAGED_RESOURCE; 983 ret = adjust_memory(s, add, start_addr, end_addr);
923 adj.Resource = RES_MEMORY_RANGE; 984 if (!ret)
924 adj.resource.memory.Base = start_addr; 985 s->resource_setup_new = 1;
925 adj.resource.memory.Size = end_addr - start_addr + 1;
926
927 ret = adjust_memory(s, &adj);
928 986
929 return ret ? ret : count; 987 return ret ? ret : count;
930} 988}
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c
index 8eed03938214..fcef54c1c2da 100644
--- a/drivers/pcmcia/socket_sysfs.c
+++ b/drivers/pcmcia/socket_sysfs.c
@@ -163,28 +163,164 @@ static ssize_t pccard_store_resource(struct class_device *dev, const char *buf,
163 return -EINVAL; 163 return -EINVAL;
164 164
165 spin_lock_irqsave(&s->lock, flags); 165 spin_lock_irqsave(&s->lock, flags);
166 if (!s->resource_setup_done) { 166 if (!s->resource_setup_done)
167 s->resource_setup_done = 1; 167 s->resource_setup_done = 1;
168 spin_unlock_irqrestore(&s->lock, flags); 168 spin_unlock_irqrestore(&s->lock, flags);
169
170 down(&s->skt_sem);
171 if ((s->callback) &&
172 (s->state & SOCKET_PRESENT) &&
173 !(s->state & SOCKET_CARDBUS)) {
174 if (try_module_get(s->callback->owner)) {
175 s->callback->requery(s);
176 module_put(s->callback->owner);
177 }
178 }
179 up(&s->skt_sem);
180
181 return count;
182}
183static CLASS_DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource);
184
185
186static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, loff_t off, size_t count)
187{
188 tuple_t tuple;
189 int status, i;
190 loff_t pointer = 0;
191 ssize_t ret = 0;
192 u_char *tuplebuffer;
193 u_char *tempbuffer;
194
195 tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL);
196 if (!tuplebuffer)
197 return -ENOMEM;
198
199 tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL);
200 if (!tempbuffer) {
201 ret = -ENOMEM;
202 goto free_tuple;
203 }
204
205 memset(&tuple, 0, sizeof(tuple_t));
206
207 tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON;
208 tuple.DesiredTuple = RETURN_FIRST_TUPLE;
209 tuple.TupleOffset = 0;
210
211 status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple);
212 while (!status) {
213 tuple.TupleData = tuplebuffer;
214 tuple.TupleDataMax = 255;
215 memset(tuplebuffer, 0, sizeof(u_char) * 255);
169 216
217 status = pccard_get_tuple_data(s, &tuple);
218 if (status)
219 break;
220
221 if (off < (pointer + 2 + tuple.TupleDataLen)) {
222 tempbuffer[0] = tuple.TupleCode & 0xff;
223 tempbuffer[1] = tuple.TupleLink & 0xff;
224 for (i = 0; i < tuple.TupleDataLen; i++)
225 tempbuffer[i + 2] = tuplebuffer[i] & 0xff;
226
227 for (i = 0; i < (2 + tuple.TupleDataLen); i++) {
228 if (((i + pointer) >= off) &&
229 (i + pointer) < (off + count)) {
230 buf[ret] = tempbuffer[i];
231 ret++;
232 }
233 }
234 }
235
236 pointer += 2 + tuple.TupleDataLen;
237
238 if (pointer >= (off + count))
239 break;
240
241 if (tuple.TupleCode == CISTPL_END)
242 break;
243 status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple);
244 }
245
246 kfree(tempbuffer);
247 free_tuple:
248 kfree(tuplebuffer);
249
250 return (ret);
251}
252
253static ssize_t pccard_show_cis(struct kobject *kobj, char *buf, loff_t off, size_t count)
254{
255 unsigned int size = 0x200;
256
257 if (off >= size)
258 count = 0;
259 else {
260 struct pcmcia_socket *s;
261 cisinfo_t cisinfo;
262
263 if (off + count > size)
264 count = size - off;
265
266 s = to_socket(container_of(kobj, struct class_device, kobj));
267
268 if (!(s->state & SOCKET_PRESENT))
269 return -ENODEV;
270 if (pccard_validate_cis(s, BIND_FN_ALL, &cisinfo))
271 return -EIO;
272 if (!cisinfo.Chains)
273 return -ENODATA;
274
275 count = pccard_extract_cis(s, buf, off, count);
276 }
277
278 return (count);
279}
280
281static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, size_t count)
282{
283 struct pcmcia_socket *s = to_socket(container_of(kobj, struct class_device, kobj));
284 cisdump_t *cis;
285 ssize_t ret = count;
286
287 if (off)
288 return -EINVAL;
289
290 if (count >= 0x200)
291 return -EINVAL;
292
293 if (!(s->state & SOCKET_PRESENT))
294 return -ENODEV;
295
296 cis = kmalloc(sizeof(cisdump_t), GFP_KERNEL);
297 if (!cis)
298 return -ENOMEM;
299 memset(cis, 0, sizeof(cisdump_t));
300
301 cis->Length = count + 1;
302 memcpy(cis->Data, buf, count);
303
304 if (pcmcia_replace_cis(s, cis))
305 ret = -EIO;
306
307 kfree(cis);
308
309 if (!ret) {
170 down(&s->skt_sem); 310 down(&s->skt_sem);
171 if ((s->callback) && 311 if ((s->callback) && (s->state & SOCKET_PRESENT) &&
172 (s->state & SOCKET_PRESENT) &&
173 !(s->state & SOCKET_CARDBUS)) { 312 !(s->state & SOCKET_CARDBUS)) {
174 if (try_module_get(s->callback->owner)) { 313 if (try_module_get(s->callback->owner)) {
175 s->callback->resources_done(s); 314 s->callback->requery(s);
176 module_put(s->callback->owner); 315 module_put(s->callback->owner);
177 } 316 }
178 } 317 }
179 up(&s->skt_sem); 318 up(&s->skt_sem);
180
181 return count;
182 } 319 }
183 spin_unlock_irqrestore(&s->lock, flags);
184 320
185 return count; 321
322 return (ret);
186} 323}
187static CLASS_DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource);
188 324
189 325
190static struct class_device_attribute *pccard_socket_attributes[] = { 326static struct class_device_attribute *pccard_socket_attributes[] = {
@@ -199,6 +335,13 @@ static struct class_device_attribute *pccard_socket_attributes[] = {
199 NULL, 335 NULL,
200}; 336};
201 337
338static struct bin_attribute pccard_cis_attr = {
339 .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR, .owner = THIS_MODULE},
340 .size = 0x200,
341 .read = pccard_show_cis,
342 .write = pccard_store_cis,
343};
344
202static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev) 345static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev)
203{ 346{
204 struct class_device_attribute **attr; 347 struct class_device_attribute **attr;
@@ -209,6 +352,8 @@ static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev)
209 if (ret) 352 if (ret)
210 break; 353 break;
211 } 354 }
355 if (!ret)
356 ret = sysfs_create_bin_file(&class_dev->kobj, &pccard_cis_attr);
212 357
213 return ret; 358 return ret;
214} 359}
@@ -217,6 +362,7 @@ static void __devexit pccard_sysfs_remove_socket(struct class_device *class_dev)
217{ 362{
218 struct class_device_attribute **attr; 363 struct class_device_attribute **attr;
219 364
365 sysfs_remove_bin_file(&class_dev->kobj, &pccard_cis_attr);
220 for (attr = pccard_socket_attributes; *attr; attr++) 366 for (attr = pccard_socket_attributes; *attr; attr++)
221 class_device_remove_file(class_dev, *attr); 367 class_device_remove_file(class_dev, *attr);
222} 368}
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
index bee05362fd24..02b23abc2df1 100644
--- a/drivers/pcmcia/yenta_socket.c
+++ b/drivers/pcmcia/yenta_socket.c
@@ -549,6 +549,11 @@ static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned typ
549 unsigned offset; 549 unsigned offset;
550 unsigned mask; 550 unsigned mask;
551 551
552 res = socket->dev->resource + PCI_BRIDGE_RESOURCES + nr;
553 /* Already allocated? */
554 if (res->parent)
555 return 0;
556
552 /* The granularity of the memory limit is 4kB, on IO it's 4 bytes */ 557 /* The granularity of the memory limit is 4kB, on IO it's 4 bytes */
553 mask = ~0xfff; 558 mask = ~0xfff;
554 if (type & IORESOURCE_IO) 559 if (type & IORESOURCE_IO)
@@ -556,7 +561,6 @@ static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned typ
556 561
557 offset = 0x1c + 8*nr; 562 offset = 0x1c + 8*nr;
558 bus = socket->dev->subordinate; 563 bus = socket->dev->subordinate;
559 res = socket->dev->resource + PCI_BRIDGE_RESOURCES + nr;
560 res->name = bus->name; 564 res->name = bus->name;
561 res->flags = type; 565 res->flags = type;
562 res->start = 0; 566 res->start = 0;
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 34dbc37a79d4..bc6e4627c7a1 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -1916,9 +1916,9 @@ static void __twa_shutdown(TW_Device_Extension *tw_dev)
1916} /* End __twa_shutdown() */ 1916} /* End __twa_shutdown() */
1917 1917
1918/* Wrapper for __twa_shutdown */ 1918/* Wrapper for __twa_shutdown */
1919static void twa_shutdown(struct device *dev) 1919static void twa_shutdown(struct pci_dev *pdev)
1920{ 1920{
1921 struct Scsi_Host *host = pci_get_drvdata(to_pci_dev(dev)); 1921 struct Scsi_Host *host = pci_get_drvdata(pdev);
1922 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; 1922 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
1923 1923
1924 __twa_shutdown(tw_dev); 1924 __twa_shutdown(tw_dev);
@@ -2140,9 +2140,7 @@ static struct pci_driver twa_driver = {
2140 .id_table = twa_pci_tbl, 2140 .id_table = twa_pci_tbl,
2141 .probe = twa_probe, 2141 .probe = twa_probe,
2142 .remove = twa_remove, 2142 .remove = twa_remove,
2143 .driver = { 2143 .shutdown = twa_shutdown
2144 .shutdown = twa_shutdown
2145 }
2146}; 2144};
2147 2145
2148/* This function is called on driver initialization */ 2146/* This function is called on driver initialization */
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index b6dc576da430..973c51fb0fe2 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -2264,9 +2264,9 @@ static void __tw_shutdown(TW_Device_Extension *tw_dev)
2264} /* End __tw_shutdown() */ 2264} /* End __tw_shutdown() */
2265 2265
2266/* Wrapper for __tw_shutdown */ 2266/* Wrapper for __tw_shutdown */
2267static void tw_shutdown(struct device *dev) 2267static void tw_shutdown(struct pci_dev *pdev)
2268{ 2268{
2269 struct Scsi_Host *host = pci_get_drvdata(to_pci_dev(dev)); 2269 struct Scsi_Host *host = pci_get_drvdata(pdev);
2270 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; 2270 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2271 2271
2272 __tw_shutdown(tw_dev); 2272 __tw_shutdown(tw_dev);
@@ -2451,9 +2451,7 @@ static struct pci_driver tw_driver = {
2451 .id_table = tw_pci_tbl, 2451 .id_table = tw_pci_tbl,
2452 .probe = tw_probe, 2452 .probe = tw_probe,
2453 .remove = tw_remove, 2453 .remove = tw_remove,
2454 .driver = { 2454 .shutdown = tw_shutdown,
2455 .shutdown = tw_shutdown
2456 }
2457}; 2455};
2458 2456
2459/* This function is called on driver initialization */ 2457/* This function is called on driver initialization */
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index 9a547ca9c864..c5623694d10f 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -304,26 +304,19 @@ static int ahci_port_start(struct ata_port *ap)
304 struct device *dev = ap->host_set->dev; 304 struct device *dev = ap->host_set->dev;
305 struct ahci_host_priv *hpriv = ap->host_set->private_data; 305 struct ahci_host_priv *hpriv = ap->host_set->private_data;
306 struct ahci_port_priv *pp; 306 struct ahci_port_priv *pp;
307 int rc;
308 void *mem, *mmio = ap->host_set->mmio_base; 307 void *mem, *mmio = ap->host_set->mmio_base;
309 void *port_mmio = ahci_port_base(mmio, ap->port_no); 308 void *port_mmio = ahci_port_base(mmio, ap->port_no);
310 dma_addr_t mem_dma; 309 dma_addr_t mem_dma;
311 310
312 rc = ata_port_start(ap);
313 if (rc)
314 return rc;
315
316 pp = kmalloc(sizeof(*pp), GFP_KERNEL); 311 pp = kmalloc(sizeof(*pp), GFP_KERNEL);
317 if (!pp) { 312 if (!pp)
318 rc = -ENOMEM; 313 return -ENOMEM;
319 goto err_out;
320 }
321 memset(pp, 0, sizeof(*pp)); 314 memset(pp, 0, sizeof(*pp));
322 315
323 mem = dma_alloc_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, &mem_dma, GFP_KERNEL); 316 mem = dma_alloc_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, &mem_dma, GFP_KERNEL);
324 if (!mem) { 317 if (!mem) {
325 rc = -ENOMEM; 318 kfree(pp);
326 goto err_out_kfree; 319 return -ENOMEM;
327 } 320 }
328 memset(mem, 0, AHCI_PORT_PRIV_DMA_SZ); 321 memset(mem, 0, AHCI_PORT_PRIV_DMA_SZ);
329 322
@@ -373,12 +366,6 @@ static int ahci_port_start(struct ata_port *ap)
373 readl(port_mmio + PORT_CMD); /* flush */ 366 readl(port_mmio + PORT_CMD); /* flush */
374 367
375 return 0; 368 return 0;
376
377err_out_kfree:
378 kfree(pp);
379err_out:
380 ata_port_stop(ap);
381 return rc;
382} 369}
383 370
384 371
@@ -404,7 +391,6 @@ static void ahci_port_stop(struct ata_port *ap)
404 dma_free_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, 391 dma_free_coherent(dev, AHCI_PORT_PRIV_DMA_SZ,
405 pp->cmd_slot, pp->cmd_slot_dma); 392 pp->cmd_slot, pp->cmd_slot_dma);
406 kfree(pp); 393 kfree(pp);
407 ata_port_stop(ap);
408} 394}
409 395
410static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in) 396static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in)
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 80d022625c82..babd48363402 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -6012,7 +6012,7 @@ static int __devinit ipr_probe(struct pci_dev *pdev,
6012 6012
6013/** 6013/**
6014 * ipr_shutdown - Shutdown handler. 6014 * ipr_shutdown - Shutdown handler.
6015 * @dev: device struct 6015 * @pdev: pci device struct
6016 * 6016 *
6017 * This function is invoked upon system shutdown/reboot. It will issue 6017 * This function is invoked upon system shutdown/reboot. It will issue
6018 * an adapter shutdown to the adapter to flush the write cache. 6018 * an adapter shutdown to the adapter to flush the write cache.
@@ -6020,9 +6020,9 @@ static int __devinit ipr_probe(struct pci_dev *pdev,
6020 * Return value: 6020 * Return value:
6021 * none 6021 * none
6022 **/ 6022 **/
6023static void ipr_shutdown(struct device *dev) 6023static void ipr_shutdown(struct pci_dev *pdev)
6024{ 6024{
6025 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(to_pci_dev(dev)); 6025 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6026 unsigned long lock_flags = 0; 6026 unsigned long lock_flags = 0;
6027 6027
6028 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 6028 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
@@ -6068,9 +6068,7 @@ static struct pci_driver ipr_driver = {
6068 .id_table = ipr_pci_table, 6068 .id_table = ipr_pci_table,
6069 .probe = ipr_probe, 6069 .probe = ipr_probe,
6070 .remove = ipr_remove, 6070 .remove = ipr_remove,
6071 .driver = { 6071 .shutdown = ipr_shutdown,
6072 .shutdown = ipr_shutdown,
6073 },
6074}; 6072};
6075 6073
6076/** 6074/**
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 36b401fee1f1..cb535fa185b9 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -1408,7 +1408,9 @@ void __sata_phy_reset(struct ata_port *ap)
1408 if (ap->flags & ATA_FLAG_SATA_RESET) { 1408 if (ap->flags & ATA_FLAG_SATA_RESET) {
1409 /* issue phy wake/reset */ 1409 /* issue phy wake/reset */
1410 scr_write_flush(ap, SCR_CONTROL, 0x301); 1410 scr_write_flush(ap, SCR_CONTROL, 0x301);
1411 udelay(400); /* FIXME: a guess */ 1411 /* Couldn't find anything in SATA I/II specs, but
1412 * AHCI-1.1 10.4.2 says at least 1 ms. */
1413 mdelay(1);
1412 } 1414 }
1413 scr_write_flush(ap, SCR_CONTROL, 0x300); /* phy wake/clear reset */ 1415 scr_write_flush(ap, SCR_CONTROL, 0x300); /* phy wake/clear reset */
1414 1416
@@ -1920,6 +1922,7 @@ static const char * ata_dma_blacklist [] = {
1920 "HITACHI CDR-8335", 1922 "HITACHI CDR-8335",
1921 "HITACHI CDR-8435", 1923 "HITACHI CDR-8435",
1922 "Toshiba CD-ROM XM-6202B", 1924 "Toshiba CD-ROM XM-6202B",
1925 "TOSHIBA CD-ROM XM-1702BC",
1923 "CD-532E-A", 1926 "CD-532E-A",
1924 "E-IDE CD-ROM CR-840", 1927 "E-IDE CD-ROM CR-840",
1925 "CD-ROM Drive/F5A", 1928 "CD-ROM Drive/F5A",
@@ -1927,7 +1930,6 @@ static const char * ata_dma_blacklist [] = {
1927 "SAMSUNG CD-ROM SC-148C", 1930 "SAMSUNG CD-ROM SC-148C",
1928 "SAMSUNG CD-ROM SC", 1931 "SAMSUNG CD-ROM SC",
1929 "SanDisk SDP3B-64", 1932 "SanDisk SDP3B-64",
1930 "SAMSUNG CD-ROM SN-124",
1931 "ATAPI CD-ROM DRIVE 40X MAXIMUM", 1933 "ATAPI CD-ROM DRIVE 40X MAXIMUM",
1932 "_NEC DV5800A", 1934 "_NEC DV5800A",
1933}; 1935};
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 7a4adc4c8f09..794fb559efb0 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -1176,8 +1176,12 @@ unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf,
1176 n_sectors = ata_id_u32(args->id, 60); 1176 n_sectors = ata_id_u32(args->id, 60);
1177 n_sectors--; /* ATA TotalUserSectors - 1 */ 1177 n_sectors--; /* ATA TotalUserSectors - 1 */
1178 1178
1179 tmp = n_sectors; /* note: truncates, if lba48 */
1180 if (args->cmd->cmnd[0] == READ_CAPACITY) { 1179 if (args->cmd->cmnd[0] == READ_CAPACITY) {
1180 if( n_sectors >= 0xffffffffULL )
1181 tmp = 0xffffffff ; /* Return max count on overflow */
1182 else
1183 tmp = n_sectors ;
1184
1181 /* sector count, 32-bit */ 1185 /* sector count, 32-bit */
1182 rbuf[0] = tmp >> (8 * 3); 1186 rbuf[0] = tmp >> (8 * 3);
1183 rbuf[1] = tmp >> (8 * 2); 1187 rbuf[1] = tmp >> (8 * 2);
@@ -1191,10 +1195,12 @@ unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf,
1191 1195
1192 } else { 1196 } else {
1193 /* sector count, 64-bit */ 1197 /* sector count, 64-bit */
1194 rbuf[2] = n_sectors >> (8 * 7); 1198 tmp = n_sectors >> (8 * 4);
1195 rbuf[3] = n_sectors >> (8 * 6); 1199 rbuf[2] = tmp >> (8 * 3);
1196 rbuf[4] = n_sectors >> (8 * 5); 1200 rbuf[3] = tmp >> (8 * 2);
1197 rbuf[5] = n_sectors >> (8 * 4); 1201 rbuf[4] = tmp >> (8 * 1);
1202 rbuf[5] = tmp;
1203 tmp = n_sectors;
1198 rbuf[6] = tmp >> (8 * 3); 1204 rbuf[6] = tmp >> (8 * 3);
1199 rbuf[7] = tmp >> (8 * 2); 1205 rbuf[7] = tmp >> (8 * 2);
1200 rbuf[8] = tmp >> (8 * 1); 1206 rbuf[8] = tmp >> (8 * 1);
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index ec81532eb845..a70cdf31311c 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -5036,9 +5036,9 @@ megaraid_remove_one(struct pci_dev *pdev)
5036} 5036}
5037 5037
5038static void 5038static void
5039megaraid_shutdown(struct device *dev) 5039megaraid_shutdown(struct pci_dev *pdev)
5040{ 5040{
5041 struct Scsi_Host *host = pci_get_drvdata(to_pci_dev(dev)); 5041 struct Scsi_Host *host = pci_get_drvdata(pdev);
5042 adapter_t *adapter = (adapter_t *)host->hostdata; 5042 adapter_t *adapter = (adapter_t *)host->hostdata;
5043 5043
5044 __megaraid_shutdown(adapter); 5044 __megaraid_shutdown(adapter);
@@ -5070,9 +5070,7 @@ static struct pci_driver megaraid_pci_driver = {
5070 .id_table = megaraid_pci_tbl, 5070 .id_table = megaraid_pci_tbl,
5071 .probe = megaraid_probe_one, 5071 .probe = megaraid_probe_one,
5072 .remove = __devexit_p(megaraid_remove_one), 5072 .remove = __devexit_p(megaraid_remove_one),
5073 .driver = { 5073 .shutdown = megaraid_shutdown,
5074 .shutdown = megaraid_shutdown,
5075 },
5076}; 5074};
5077 5075
5078static int __init megaraid_init(void) 5076static int __init megaraid_init(void)
diff --git a/drivers/scsi/pcmcia/aha152x_stub.c b/drivers/scsi/pcmcia/aha152x_stub.c
index e60b4c0a8427..f1f6bf596dc9 100644
--- a/drivers/scsi/pcmcia/aha152x_stub.c
+++ b/drivers/scsi/pcmcia/aha152x_stub.c
@@ -318,6 +318,16 @@ static int aha152x_event(event_t event, int priority,
318 return 0; 318 return 0;
319} 319}
320 320
321static struct pcmcia_device_id aha152x_ids[] = {
322 PCMCIA_DEVICE_PROD_ID123("New Media", "SCSI", "Bus Toaster", 0xcdf7e4cc, 0x35f26476, 0xa8851d6e),
323 PCMCIA_DEVICE_PROD_ID123("NOTEWORTHY", "SCSI", "Bus Toaster", 0xad89c6e8, 0x35f26476, 0xa8851d6e),
324 PCMCIA_DEVICE_PROD_ID12("Adaptec, Inc.", "APA-1460 SCSI Host Adapter", 0x24ba9738, 0x3a3c3d20),
325 PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "Multimedia Sound/SCSI", 0x085a850b, 0x80a6535c),
326 PCMCIA_DEVICE_PROD_ID12("NOTEWORTHY", "NWCOMB02 SCSI/AUDIO COMBO CARD", 0xad89c6e8, 0x5f9a615b),
327 PCMCIA_DEVICE_NULL,
328};
329MODULE_DEVICE_TABLE(pcmcia, aha152x_ids);
330
321static struct pcmcia_driver aha152x_cs_driver = { 331static struct pcmcia_driver aha152x_cs_driver = {
322 .owner = THIS_MODULE, 332 .owner = THIS_MODULE,
323 .drv = { 333 .drv = {
@@ -325,6 +335,7 @@ static struct pcmcia_driver aha152x_cs_driver = {
325 }, 335 },
326 .attach = aha152x_attach, 336 .attach = aha152x_attach,
327 .detach = aha152x_detach, 337 .detach = aha152x_detach,
338 .id_table = aha152x_ids,
328}; 339};
329 340
330static int __init init_aha152x_cs(void) 341static int __init init_aha152x_cs(void)
diff --git a/drivers/scsi/pcmcia/fdomain_stub.c b/drivers/scsi/pcmcia/fdomain_stub.c
index 3df7bc72e354..853e6ee9b71a 100644
--- a/drivers/scsi/pcmcia/fdomain_stub.c
+++ b/drivers/scsi/pcmcia/fdomain_stub.c
@@ -299,6 +299,15 @@ static int fdomain_event(event_t event, int priority,
299 return 0; 299 return 0;
300} /* fdomain_event */ 300} /* fdomain_event */
301 301
302
303static struct pcmcia_device_id fdomain_ids[] = {
304 PCMCIA_DEVICE_PROD_ID12("IBM Corp.", "SCSI PCMCIA Card", 0xe3736c88, 0x859cad20),
305 PCMCIA_DEVICE_PROD_ID1("SCSI PCMCIA Adapter Card", 0x8dacb57e),
306 PCMCIA_DEVICE_PROD_ID12(" SIMPLE TECHNOLOGY Corporation", "SCSI PCMCIA Credit Card Controller", 0x182bdafe, 0xc80d106f),
307 PCMCIA_DEVICE_NULL,
308};
309MODULE_DEVICE_TABLE(pcmcia, fdomain_ids);
310
302static struct pcmcia_driver fdomain_cs_driver = { 311static struct pcmcia_driver fdomain_cs_driver = {
303 .owner = THIS_MODULE, 312 .owner = THIS_MODULE,
304 .drv = { 313 .drv = {
@@ -306,6 +315,7 @@ static struct pcmcia_driver fdomain_cs_driver = {
306 }, 315 },
307 .attach = fdomain_attach, 316 .attach = fdomain_attach,
308 .detach = fdomain_detach, 317 .detach = fdomain_detach,
318 .id_table = fdomain_ids,
309}; 319};
310 320
311static int __init init_fdomain_cs(void) 321static int __init init_fdomain_cs(void)
diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index 3dddb323e718..91b3f28e7a19 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -2125,6 +2125,18 @@ static int nsp_cs_event(event_t event,
2125 * module entry point 2125 * module entry point
2126 *====================================================================*/ 2126 *====================================================================*/
2127#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,68)) 2127#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,68))
2128static struct pcmcia_device_id nsp_cs_ids[] = {
2129 PCMCIA_DEVICE_PROD_ID123("IO DATA", "CBSC16 ", "1", 0x547e66dc, 0x0d63a3fd, 0x51de003a),
2130 PCMCIA_DEVICE_PROD_ID123("KME ", "SCSI-CARD-001", "1", 0x534c02bc, 0x52008408, 0x51de003a),
2131 PCMCIA_DEVICE_PROD_ID123("KME ", "SCSI-CARD-002", "1", 0x534c02bc, 0xcb09d5b2, 0x51de003a),
2132 PCMCIA_DEVICE_PROD_ID123("KME ", "SCSI-CARD-003", "1", 0x534c02bc, 0xbc0ee524, 0x51de003a),
2133 PCMCIA_DEVICE_PROD_ID123("KME ", "SCSI-CARD-004", "1", 0x534c02bc, 0x226a7087, 0x51de003a),
2134 PCMCIA_DEVICE_PROD_ID123("WBT", "NinjaSCSI-3", "R1.0", 0xc7ba805f, 0xfdc7c97d, 0x6973710e),
2135 PCMCIA_DEVICE_PROD_ID123("WORKBIT", "UltraNinja-16", "1", 0x28191418, 0xb70f4b09, 0x51de003a),
2136 PCMCIA_DEVICE_NULL
2137};
2138MODULE_DEVICE_TABLE(pcmcia, nsp_cs_ids);
2139
2128static struct pcmcia_driver nsp_driver = { 2140static struct pcmcia_driver nsp_driver = {
2129 .owner = THIS_MODULE, 2141 .owner = THIS_MODULE,
2130 .drv = { 2142 .drv = {
@@ -2132,6 +2144,7 @@ static struct pcmcia_driver nsp_driver = {
2132 }, 2144 },
2133 .attach = nsp_cs_attach, 2145 .attach = nsp_cs_attach,
2134 .detach = nsp_cs_detach, 2146 .detach = nsp_cs_detach,
2147 .id_table = nsp_cs_ids,
2135}; 2148};
2136#endif 2149#endif
2137 2150
diff --git a/drivers/scsi/pcmcia/qlogic_stub.c b/drivers/scsi/pcmcia/qlogic_stub.c
index a0175f5d11cd..0dcf41102abf 100644
--- a/drivers/scsi/pcmcia/qlogic_stub.c
+++ b/drivers/scsi/pcmcia/qlogic_stub.c
@@ -395,6 +395,27 @@ static int qlogic_event(event_t event, int priority, event_callback_args_t * arg
395 return 0; 395 return 0;
396} /* qlogic_event */ 396} /* qlogic_event */
397 397
398static struct pcmcia_device_id qlogic_ids[] = {
399 PCMCIA_DEVICE_PROD_ID12("EIger Labs", "PCMCIA-to-SCSI Adapter", 0x88395fa7, 0x33b7a5e6),
400 PCMCIA_DEVICE_PROD_ID12("EPSON", "SCSI-2 PC Card SC200", 0xd361772f, 0x299d1751),
401 PCMCIA_DEVICE_PROD_ID12("MACNICA", "MIRACLE SCSI-II mPS110", 0x20841b68, 0xab3c3b6d),
402 PCMCIA_DEVICE_PROD_ID12("MIDORI ELECTRONICS ", "CN-SC43", 0x6534382a, 0xd67eee79),
403 PCMCIA_DEVICE_PROD_ID12("NEC", "PC-9801N-J03R", 0x18df0ba0, 0x24662e8a),
404 PCMCIA_DEVICE_PROD_ID12("KME ", "KXLC003", 0x82375a27, 0xf68e5bf7),
405 PCMCIA_DEVICE_PROD_ID12("KME ", "KXLC004", 0x82375a27, 0x68eace54),
406 PCMCIA_DEVICE_PROD_ID12("KME", "KXLC101", 0x3faee676, 0x194250ec),
407 PCMCIA_DEVICE_PROD_ID12("QLOGIC CORPORATION", "pc05", 0xd77b2930, 0xa85b2735),
408 PCMCIA_DEVICE_PROD_ID12("QLOGIC CORPORATION", "pc05 rev 1.10", 0xd77b2930, 0x70f8b5f8),
409 PCMCIA_DEVICE_PROD_ID123("KME", "KXLC002", "00", 0x3faee676, 0x81896b61, 0xf99f065f),
410 PCMCIA_DEVICE_PROD_ID12("RATOC System Inc.", "SCSI2 CARD 37", 0x85c10e17, 0x1a2640c1),
411 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "SCSC200A PC CARD SCSI", 0xb4585a1a, 0xa6f06ebe),
412 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "SCSC200B PC CARD SCSI-10", 0xb4585a1a, 0x0a88dea0),
413 /* these conflict with other cards! */
414 /* PCMCIA_DEVICE_PROD_ID123("MACNICA", "MIRACLE SCSI", "mPS100", 0x20841b68, 0xf8dedaeb, 0x89f7fafb), */
415 /* PCMCIA_DEVICE_PROD_ID123("MACNICA", "MIRACLE SCSI", "mPS100", 0x20841b68, 0xf8dedaeb, 0x89f7fafb), */
416 PCMCIA_DEVICE_NULL,
417};
418MODULE_DEVICE_TABLE(pcmcia, qlogic_ids);
398 419
399static struct pcmcia_driver qlogic_cs_driver = { 420static struct pcmcia_driver qlogic_cs_driver = {
400 .owner = THIS_MODULE, 421 .owner = THIS_MODULE,
@@ -403,6 +424,7 @@ static struct pcmcia_driver qlogic_cs_driver = {
403 }, 424 },
404 .attach = qlogic_attach, 425 .attach = qlogic_attach,
405 .detach = qlogic_detach, 426 .detach = qlogic_detach,
427 .id_table = qlogic_ids,
406}; 428};
407 429
408static int __init init_qlogic_cs(void) 430static int __init init_qlogic_cs(void)
diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c
index 1667da9508b4..7d4b16b6797d 100644
--- a/drivers/scsi/pcmcia/sym53c500_cs.c
+++ b/drivers/scsi/pcmcia/sym53c500_cs.c
@@ -999,6 +999,14 @@ MODULE_AUTHOR("Bob Tracy <rct@frus.com>");
999MODULE_DESCRIPTION("SYM53C500 PCMCIA SCSI driver"); 999MODULE_DESCRIPTION("SYM53C500 PCMCIA SCSI driver");
1000MODULE_LICENSE("GPL"); 1000MODULE_LICENSE("GPL");
1001 1001
1002static struct pcmcia_device_id sym53c500_ids[] = {
1003 PCMCIA_DEVICE_PROD_ID12("BASICS by New Media Corporation", "SCSI Sym53C500", 0x23c78a9d, 0x0099e7f7),
1004 PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "SCSI Bus Toaster Sym53C500", 0x085a850b, 0x45432eb8),
1005 PCMCIA_DEVICE_PROD_ID2("SCSI9000", 0x21648f44),
1006 PCMCIA_DEVICE_NULL,
1007};
1008MODULE_DEVICE_TABLE(pcmcia, sym53c500_ids);
1009
1002static struct pcmcia_driver sym53c500_cs_driver = { 1010static struct pcmcia_driver sym53c500_cs_driver = {
1003 .owner = THIS_MODULE, 1011 .owner = THIS_MODULE,
1004 .drv = { 1012 .drv = {
@@ -1006,6 +1014,7 @@ static struct pcmcia_driver sym53c500_cs_driver = {
1006 }, 1014 },
1007 .attach = SYM53C500_attach, 1015 .attach = SYM53C500_attach,
1008 .detach = SYM53C500_detach, 1016 .detach = SYM53C500_detach,
1017 .id_table = sym53c500_ids,
1009}; 1018};
1010 1019
1011static int __init 1020static int __init
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 621dee8b8cb2..10506f9cd0c9 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -632,7 +632,7 @@ static void scsi_free_sgtable(struct scatterlist *sgl, int index)
632{ 632{
633 struct scsi_host_sg_pool *sgp; 633 struct scsi_host_sg_pool *sgp;
634 634
635 BUG_ON(index > SG_MEMPOOL_NR); 635 BUG_ON(index >= SG_MEMPOOL_NR);
636 636
637 sgp = scsi_sg_pools + index; 637 sgp = scsi_sg_pools + index;
638 mempool_free(sgl, sgp->pool); 638 mempool_free(sgl, sgp->pool);
diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
index feb8e73fc1c9..d27fb4c881d2 100644
--- a/drivers/serial/68328serial.c
+++ b/drivers/serial/68328serial.c
@@ -1497,23 +1497,6 @@ rs68328_init(void)
1497 return 0; 1497 return 0;
1498} 1498}
1499 1499
1500
1501
1502/*
1503 * register_serial and unregister_serial allows for serial ports to be
1504 * configured at run-time, to support PCMCIA modems.
1505 */
1506/* SPARC: Unused at this time, just here to make things link. */
1507int register_serial(struct serial_struct *req)
1508{
1509 return -1;
1510}
1511
1512void unregister_serial(int line)
1513{
1514 return;
1515}
1516
1517module_init(rs68328_init); 1500module_init(rs68328_init);
1518 1501
1519 1502
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index d8b9d2b8c200..9224fc3184ea 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -77,23 +77,9 @@ static unsigned int share_irqs = SERIAL8250_SHARE_IRQS;
77 */ 77 */
78#define is_real_interrupt(irq) ((irq) != 0) 78#define is_real_interrupt(irq) ((irq) != 0)
79 79
80/*
81 * This converts from our new CONFIG_ symbols to the symbols
82 * that asm/serial.h expects. You _NEED_ to comment out the
83 * linux/config.h include contained inside asm/serial.h for
84 * this to work.
85 */
86#undef CONFIG_SERIAL_MANY_PORTS
87#undef CONFIG_SERIAL_DETECT_IRQ
88#undef CONFIG_SERIAL_MULTIPORT
89#undef CONFIG_HUB6
90
91#ifdef CONFIG_SERIAL_8250_DETECT_IRQ 80#ifdef CONFIG_SERIAL_8250_DETECT_IRQ
92#define CONFIG_SERIAL_DETECT_IRQ 1 81#define CONFIG_SERIAL_DETECT_IRQ 1
93#endif 82#endif
94#ifdef CONFIG_SERIAL_8250_MULTIPORT
95#define CONFIG_SERIAL_MULTIPORT 1
96#endif
97#ifdef CONFIG_SERIAL_8250_MANY_PORTS 83#ifdef CONFIG_SERIAL_8250_MANY_PORTS
98#define CONFIG_SERIAL_MANY_PORTS 1 84#define CONFIG_SERIAL_MANY_PORTS 1
99#endif 85#endif
@@ -119,7 +105,7 @@ static struct old_serial_port old_serial_port[] = {
119 SERIAL_PORT_DFNS /* defined in asm/serial.h */ 105 SERIAL_PORT_DFNS /* defined in asm/serial.h */
120}; 106};
121 107
122#define UART_NR (ARRAY_SIZE(old_serial_port) + CONFIG_SERIAL_8250_NR_UARTS) 108#define UART_NR CONFIG_SERIAL_8250_NR_UARTS
123 109
124#ifdef CONFIG_SERIAL_8250_RSA 110#ifdef CONFIG_SERIAL_8250_RSA
125 111
@@ -1007,21 +993,24 @@ static void autoconfig_irq(struct uart_8250_port *up)
1007 up->port.irq = (irq > 0) ? irq : 0; 993 up->port.irq = (irq > 0) ? irq : 0;
1008} 994}
1009 995
996static inline void __stop_tx(struct uart_8250_port *p)
997{
998 if (p->ier & UART_IER_THRI) {
999 p->ier &= ~UART_IER_THRI;
1000 serial_out(p, UART_IER, p->ier);
1001 }
1002}
1003
1010static void serial8250_stop_tx(struct uart_port *port, unsigned int tty_stop) 1004static void serial8250_stop_tx(struct uart_port *port, unsigned int tty_stop)
1011{ 1005{
1012 struct uart_8250_port *up = (struct uart_8250_port *)port; 1006 struct uart_8250_port *up = (struct uart_8250_port *)port;
1013 1007
1014 if (up->ier & UART_IER_THRI) { 1008 __stop_tx(up);
1015 up->ier &= ~UART_IER_THRI;
1016 serial_out(up, UART_IER, up->ier);
1017 }
1018 1009
1019 /* 1010 /*
1020 * We only do this from uart_stop - if we run out of 1011 * We really want to stop the transmitter from sending.
1021 * characters to send, we don't want to prevent the
1022 * FIFO from emptying.
1023 */ 1012 */
1024 if (up->port.type == PORT_16C950 && tty_stop) { 1013 if (up->port.type == PORT_16C950) {
1025 up->acr |= UART_ACR_TXDIS; 1014 up->acr |= UART_ACR_TXDIS;
1026 serial_icr_write(up, UART_ACR, up->acr); 1015 serial_icr_write(up, UART_ACR, up->acr);
1027 } 1016 }
@@ -1045,10 +1034,11 @@ static void serial8250_start_tx(struct uart_port *port, unsigned int tty_start)
1045 transmit_chars(up); 1034 transmit_chars(up);
1046 } 1035 }
1047 } 1036 }
1037
1048 /* 1038 /*
1049 * We only do this from uart_start 1039 * Re-enable the transmitter if we disabled it.
1050 */ 1040 */
1051 if (tty_start && up->port.type == PORT_16C950) { 1041 if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) {
1052 up->acr &= ~UART_ACR_TXDIS; 1042 up->acr &= ~UART_ACR_TXDIS;
1053 serial_icr_write(up, UART_ACR, up->acr); 1043 serial_icr_write(up, UART_ACR, up->acr);
1054 } 1044 }
@@ -1169,7 +1159,7 @@ static _INLINE_ void transmit_chars(struct uart_8250_port *up)
1169 return; 1159 return;
1170 } 1160 }
1171 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) { 1161 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
1172 serial8250_stop_tx(&up->port, 0); 1162 __stop_tx(up);
1173 return; 1163 return;
1174 } 1164 }
1175 1165
@@ -1188,7 +1178,7 @@ static _INLINE_ void transmit_chars(struct uart_8250_port *up)
1188 DEBUG_INTR("THRE..."); 1178 DEBUG_INTR("THRE...");
1189 1179
1190 if (uart_circ_empty(xmit)) 1180 if (uart_circ_empty(xmit))
1191 serial8250_stop_tx(&up->port, 0); 1181 __stop_tx(up);
1192} 1182}
1193 1183
1194static _INLINE_ void check_modem_status(struct uart_8250_port *up) 1184static _INLINE_ void check_modem_status(struct uart_8250_port *up)
@@ -1390,13 +1380,10 @@ static unsigned int serial8250_tx_empty(struct uart_port *port)
1390static unsigned int serial8250_get_mctrl(struct uart_port *port) 1380static unsigned int serial8250_get_mctrl(struct uart_port *port)
1391{ 1381{
1392 struct uart_8250_port *up = (struct uart_8250_port *)port; 1382 struct uart_8250_port *up = (struct uart_8250_port *)port;
1393 unsigned long flags;
1394 unsigned char status; 1383 unsigned char status;
1395 unsigned int ret; 1384 unsigned int ret;
1396 1385
1397 spin_lock_irqsave(&up->port.lock, flags);
1398 status = serial_in(up, UART_MSR); 1386 status = serial_in(up, UART_MSR);
1399 spin_unlock_irqrestore(&up->port.lock, flags);
1400 1387
1401 ret = 0; 1388 ret = 0;
1402 if (status & UART_MSR_DCD) 1389 if (status & UART_MSR_DCD)
@@ -2323,10 +2310,11 @@ static int __devinit serial8250_probe(struct device *dev)
2323{ 2310{
2324 struct plat_serial8250_port *p = dev->platform_data; 2311 struct plat_serial8250_port *p = dev->platform_data;
2325 struct uart_port port; 2312 struct uart_port port;
2313 int ret, i;
2326 2314
2327 memset(&port, 0, sizeof(struct uart_port)); 2315 memset(&port, 0, sizeof(struct uart_port));
2328 2316
2329 for (; p && p->flags != 0; p++) { 2317 for (i = 0; p && p->flags != 0; p++, i++) {
2330 port.iobase = p->iobase; 2318 port.iobase = p->iobase;
2331 port.membase = p->membase; 2319 port.membase = p->membase;
2332 port.irq = p->irq; 2320 port.irq = p->irq;
@@ -2335,10 +2323,16 @@ static int __devinit serial8250_probe(struct device *dev)
2335 port.iotype = p->iotype; 2323 port.iotype = p->iotype;
2336 port.flags = p->flags; 2324 port.flags = p->flags;
2337 port.mapbase = p->mapbase; 2325 port.mapbase = p->mapbase;
2326 port.hub6 = p->hub6;
2338 port.dev = dev; 2327 port.dev = dev;
2339 if (share_irqs) 2328 if (share_irqs)
2340 port.flags |= UPF_SHARE_IRQ; 2329 port.flags |= UPF_SHARE_IRQ;
2341 serial8250_register_port(&port); 2330 ret = serial8250_register_port(&port);
2331 if (ret < 0) {
2332 dev_err(dev, "unable to register port at index %d "
2333 "(IO%lx MEM%lx IRQ%d): %d\n", i,
2334 p->iobase, p->mapbase, p->irq, ret);
2335 }
2342 } 2336 }
2343 return 0; 2337 return 0;
2344} 2338}
diff --git a/drivers/serial/8250_accent.c b/drivers/serial/8250_accent.c
new file mode 100644
index 000000000000..1f2c276063ef
--- /dev/null
+++ b/drivers/serial/8250_accent.c
@@ -0,0 +1,47 @@
1/*
2 * linux/drivers/serial/8250_accent.c
3 *
4 * Copyright (C) 2005 Russell King.
5 * Data taken from include/asm-i386/serial.h
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/serial_8250.h>
14
15#define PORT(_base,_irq) \
16 { \
17 .iobase = _base, \
18 .irq = _irq, \
19 .uartclk = 1843200, \
20 .iotype = UPIO_PORT, \
21 .flags = UPF_BOOT_AUTOCONF, \
22 }
23
24static struct plat_serial8250_port accent_data[] = {
25 PORT(0x330, 4),
26 PORT(0x338, 4),
27 { },
28};
29
30static struct platform_device accent_device = {
31 .name = "serial8250",
32 .id = 2,
33 .dev = {
34 .platform_data = accent_data,
35 },
36};
37
38static int __init accent_init(void)
39{
40 return platform_device_register(&accent_device);
41}
42
43module_init(accent_init);
44
45MODULE_AUTHOR("Russell King");
46MODULE_DESCRIPTION("8250 serial probe module for Accent Async cards");
47MODULE_LICENSE("GPL");
diff --git a/drivers/serial/8250_boca.c b/drivers/serial/8250_boca.c
new file mode 100644
index 000000000000..465c9ea1e7a3
--- /dev/null
+++ b/drivers/serial/8250_boca.c
@@ -0,0 +1,61 @@
1/*
2 * linux/drivers/serial/8250_boca.c
3 *
4 * Copyright (C) 2005 Russell King.
5 * Data taken from include/asm-i386/serial.h
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/serial_8250.h>
14
15#define PORT(_base,_irq) \
16 { \
17 .iobase = _base, \
18 .irq = _irq, \
19 .uartclk = 1843200, \
20 .iotype = UPIO_PORT, \
21 .flags = UPF_BOOT_AUTOCONF, \
22 }
23
24static struct plat_serial8250_port boca_data[] = {
25 PORT(0x100, 12),
26 PORT(0x108, 12),
27 PORT(0x110, 12),
28 PORT(0x118, 12),
29 PORT(0x120, 12),
30 PORT(0x128, 12),
31 PORT(0x130, 12),
32 PORT(0x138, 12),
33 PORT(0x140, 12),
34 PORT(0x148, 12),
35 PORT(0x150, 12),
36 PORT(0x158, 12),
37 PORT(0x160, 12),
38 PORT(0x168, 12),
39 PORT(0x170, 12),
40 PORT(0x178, 12),
41 { },
42};
43
44static struct platform_device boca_device = {
45 .name = "serial8250",
46 .id = 3,
47 .dev = {
48 .platform_data = boca_data,
49 },
50};
51
52static int __init boca_init(void)
53{
54 return platform_device_register(&boca_device);
55}
56
57module_init(boca_init);
58
59MODULE_AUTHOR("Russell King");
60MODULE_DESCRIPTION("8250 serial probe module for Boca cards");
61MODULE_LICENSE("GPL");
diff --git a/drivers/serial/8250_fourport.c b/drivers/serial/8250_fourport.c
new file mode 100644
index 000000000000..e9b4d908ef42
--- /dev/null
+++ b/drivers/serial/8250_fourport.c
@@ -0,0 +1,53 @@
1/*
2 * linux/drivers/serial/8250_fourport.c
3 *
4 * Copyright (C) 2005 Russell King.
5 * Data taken from include/asm-i386/serial.h
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/serial_8250.h>
14
15#define PORT(_base,_irq) \
16 { \
17 .iobase = _base, \
18 .irq = _irq, \
19 .uartclk = 1843200, \
20 .iotype = UPIO_PORT, \
21 .flags = UPF_BOOT_AUTOCONF | UPF_FOURPORT, \
22 }
23
24static struct plat_serial8250_port fourport_data[] = {
25 PORT(0x1a0, 9),
26 PORT(0x1a8, 9),
27 PORT(0x1b0, 9),
28 PORT(0x1b8, 9),
29 PORT(0x2a0, 5),
30 PORT(0x2a8, 5),
31 PORT(0x2b0, 5),
32 PORT(0x2b8, 5),
33 { },
34};
35
36static struct platform_device fourport_device = {
37 .name = "serial8250",
38 .id = 1,
39 .dev = {
40 .platform_data = fourport_data,
41 },
42};
43
44static int __init fourport_init(void)
45{
46 return platform_device_register(&fourport_device);
47}
48
49module_init(fourport_init);
50
51MODULE_AUTHOR("Russell King");
52MODULE_DESCRIPTION("8250 serial probe module for AST Fourport cards");
53MODULE_LICENSE("GPL");
diff --git a/drivers/serial/8250_hub6.c b/drivers/serial/8250_hub6.c
new file mode 100644
index 000000000000..77f396f84b4c
--- /dev/null
+++ b/drivers/serial/8250_hub6.c
@@ -0,0 +1,58 @@
1/*
2 * linux/drivers/serial/8250_hub6.c
3 *
4 * Copyright (C) 2005 Russell King.
5 * Data taken from include/asm-i386/serial.h
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/serial_8250.h>
14
15#define HUB6(card,port) \
16 { \
17 .iobase = 0x302, \
18 .irq = 3, \
19 .uartclk = 1843200, \
20 .iotype = UPIO_HUB6, \
21 .flags = UPF_BOOT_AUTOCONF, \
22 .hub6 = (card) << 6 | (port) << 3 | 1, \
23 }
24
25static struct plat_serial8250_port hub6_data[] = {
26 HUB6(0,0),
27 HUB6(0,1),
28 HUB6(0,2),
29 HUB6(0,3),
30 HUB6(0,4),
31 HUB6(0,5),
32 HUB6(1,0),
33 HUB6(1,1),
34 HUB6(1,2),
35 HUB6(1,3),
36 HUB6(1,4),
37 HUB6(1,5),
38 { },
39};
40
41static struct platform_device hub6_device = {
42 .name = "serial8250",
43 .id = 4,
44 .dev = {
45 .platform_data = hub6_data,
46 },
47};
48
49static int __init hub6_init(void)
50{
51 return platform_device_register(&hub6_device);
52}
53
54module_init(hub6_init);
55
56MODULE_AUTHOR("Russell King");
57MODULE_DESCRIPTION("8250 serial probe module for Hub6 cards");
58MODULE_LICENSE("GPL");
diff --git a/drivers/serial/8250_mca.c b/drivers/serial/8250_mca.c
new file mode 100644
index 000000000000..f0c40d68b8c1
--- /dev/null
+++ b/drivers/serial/8250_mca.c
@@ -0,0 +1,64 @@
1/*
2 * linux/drivers/serial/8250_mca.c
3 *
4 * Copyright (C) 2005 Russell King.
5 * Data taken from include/asm-i386/serial.h
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/config.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/mca.h>
15#include <linux/serial_8250.h>
16
17/*
18 * FIXME: Should we be doing AUTO_IRQ here?
19 */
20#ifdef CONFIG_SERIAL_8250_DETECT_IRQ
21#define MCA_FLAGS UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_AUTO_IRQ
22#else
23#define MCA_FLAGS UPF_BOOT_AUTOCONF | UPF_SKIP_TEST
24#endif
25
26#define PORT(_base,_irq) \
27 { \
28 .iobase = _base, \
29 .irq = _irq, \
30 .uartclk = 1843200, \
31 .iotype = UPIO_PORT, \
32 .flags = MCA_FLAGS, \
33 }
34
35static struct plat_serial8250_port mca_data[] = {
36 PORT(0x3220, 3),
37 PORT(0x3228, 3),
38 PORT(0x4220, 3),
39 PORT(0x4228, 3),
40 PORT(0x5220, 3),
41 PORT(0x5228, 3),
42 { },
43};
44
45static struct platform_device mca_device = {
46 .name = "serial8250",
47 .id = 5,
48 .dev = {
49 .platform_data = mca_data,
50 },
51};
52
53static int __init mca_init(void)
54{
55 if (!MCA_bus)
56 return -ENODEV;
57 return platform_device_register(&mca_device);
58}
59
60module_init(mca_init);
61
62MODULE_AUTHOR("Russell King");
63MODULE_DESCRIPTION("8250 serial probe module for MCA ports");
64MODULE_LICENSE("GPL");
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 25fcef2c42de..e0d0a470ddfc 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -86,14 +86,14 @@ config SERIAL_8250_ACPI
86 namespace, say Y here. If unsure, say N. 86 namespace, say Y here. If unsure, say N.
87 87
88config SERIAL_8250_NR_UARTS 88config SERIAL_8250_NR_UARTS
89 int "Maximum number of non-legacy 8250/16550 serial ports" 89 int "Maximum number of 8250/16550 serial ports"
90 depends on SERIAL_8250 90 depends on SERIAL_8250
91 default "4" 91 default "4"
92 ---help--- 92 help
93 Set this to the number of non-legacy serial ports you want 93 Set this to the number of serial ports you want the driver
94 the driver to support. This includes any ports discovered 94 to support. This includes any ports discovered via ACPI or
95 via ACPI or PCI enumeration and any ports that may be added 95 PCI enumeration and any ports that may be added at run-time
96 at run-time via hot-plug. 96 via hot-plug, or any ISA multi-port serial cards.
97 97
98config SERIAL_8250_EXTENDED 98config SERIAL_8250_EXTENDED
99 bool "Extended 8250/16550 serial driver options" 99 bool "Extended 8250/16550 serial driver options"
@@ -141,31 +141,74 @@ config SERIAL_8250_DETECT_IRQ
141 141
142 If unsure, say N. 142 If unsure, say N.
143 143
144config SERIAL_8250_MULTIPORT
145 bool "Support special multiport boards"
146 depends on SERIAL_8250_EXTENDED
147 help
148 Some multiport serial ports have special ports which are used to
149 signal when there are any serial ports on the board which need
150 servicing. Say Y here to enable the serial driver to take advantage
151 of those special I/O ports.
152
153config SERIAL_8250_RSA 144config SERIAL_8250_RSA
154 bool "Support RSA serial ports" 145 bool "Support RSA serial ports"
155 depends on SERIAL_8250_EXTENDED 146 depends on SERIAL_8250_EXTENDED
156 help 147 help
157 ::: To be written ::: 148 ::: To be written :::
158 149
159comment "Non-8250 serial port support" 150#
151# Multi-port serial cards
152#
153
154config SERIAL_8250_FOURPORT
155 tristate "Support Fourport cards"
156 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
157 help
158 Say Y here if you have an AST FourPort serial board.
159
160 To compile this driver as a module, choose M here: the module
161 will be called 8250_fourport.
162
163config SERIAL_8250_ACCENT
164 tristate "Support Accent cards"
165 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
166 help
167 Say Y here if you have an Accent Async serial board.
168
169 To compile this driver as a module, choose M here: the module
170 will be called 8250_accent.
171
172
173config SERIAL_8250_BOCA
174 tristate "Support Boca cards"
175 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
176 help
177 Say Y here if you have a Boca serial board. Please read the Boca
178 mini-HOWTO, avaialble from <http://www.tldp.org/docs.html#howto>
179
180 To compile this driver as a module, choose M here: the module
181 will be called 8250_boca.
182
183
184config SERIAL_8250_HUB6
185 tristate "Support Hub6 cards"
186 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
187 help
188 Say Y here if you have a HUB6 serial board.
189
190 To compile this driver as a module, choose M here: the module
191 will be called 8250_hub6.
192
193config SERIAL_8250_MCA
194 tristate "Support 8250-type ports on MCA buses"
195 depends on SERIAL_8250 != n && MCA
196 help
197 Say Y here if you have a MCA serial ports.
198
199 To compile this driver as a module, choose M here: the module
200 will be called 8250_mca.
160 201
161config SERIAL_8250_ACORN 202config SERIAL_8250_ACORN
162 tristate "Acorn expansion card serial port support" 203 tristate "Acorn expansion card serial port support"
163 depends on ARM && ARCH_ACORN && SERIAL_8250 204 depends on ARCH_ACORN && SERIAL_8250
164 help 205 help
165 If you have an Atomwide Serial card or Serial Port card for an Acorn 206 If you have an Atomwide Serial card or Serial Port card for an Acorn
166 system, say Y to this option. The driver can handle 1, 2, or 3 port 207 system, say Y to this option. The driver can handle 1, 2, or 3 port
167 cards. If unsure, say N. 208 cards. If unsure, say N.
168 209
210comment "Non-8250 serial port support"
211
169config SERIAL_AMBA_PL010 212config SERIAL_AMBA_PL010
170 tristate "ARM AMBA PL010 serial port support" 213 tristate "ARM AMBA PL010 serial port support"
171 depends on ARM_AMBA 214 depends on ARM_AMBA
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index 8f1cdde7dbed..65bd4381685e 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -17,6 +17,11 @@ obj-$(CONFIG_SERIAL_8250) += 8250.o $(serial-8250-y)
17obj-$(CONFIG_SERIAL_8250_CS) += serial_cs.o 17obj-$(CONFIG_SERIAL_8250_CS) += serial_cs.o
18obj-$(CONFIG_SERIAL_8250_ACORN) += 8250_acorn.o 18obj-$(CONFIG_SERIAL_8250_ACORN) += 8250_acorn.o
19obj-$(CONFIG_SERIAL_8250_CONSOLE) += 8250_early.o 19obj-$(CONFIG_SERIAL_8250_CONSOLE) += 8250_early.o
20obj-$(CONFIG_SERIAL_8250_FOURPORT) += 8250_fourport.o
21obj-$(CONFIG_SERIAL_8250_ACCENT) += 8250_accent.o
22obj-$(CONFIG_SERIAL_8250_BOCA) += 8250_boca.o
23obj-$(CONFIG_SERIAL_8250_HUB6) += 8250_hub6.o
24obj-$(CONFIG_SERIAL_8250_MCA) += 8250_mca.o
20obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o 25obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o
21obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o 26obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o
22obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o 27obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o
diff --git a/drivers/serial/au1x00_uart.c b/drivers/serial/au1x00_uart.c
index 5400dc2c087e..6104aeef1243 100644
--- a/drivers/serial/au1x00_uart.c
+++ b/drivers/serial/au1x00_uart.c
@@ -556,13 +556,10 @@ static unsigned int serial8250_tx_empty(struct uart_port *port)
556static unsigned int serial8250_get_mctrl(struct uart_port *port) 556static unsigned int serial8250_get_mctrl(struct uart_port *port)
557{ 557{
558 struct uart_8250_port *up = (struct uart_8250_port *)port; 558 struct uart_8250_port *up = (struct uart_8250_port *)port;
559 unsigned long flags;
560 unsigned char status; 559 unsigned char status;
561 unsigned int ret; 560 unsigned int ret;
562 561
563 spin_lock_irqsave(&up->port.lock, flags);
564 status = serial_in(up, UART_MSR); 562 status = serial_in(up, UART_MSR);
565 spin_unlock_irqrestore(&up->port.lock, flags);
566 563
567 ret = 0; 564 ret = 0;
568 if (status & UART_MSR_DCD) 565 if (status & UART_MSR_DCD)
diff --git a/drivers/serial/ip22zilog.c b/drivers/serial/ip22zilog.c
index 3ea46c069f6f..ea5bf4d4daa3 100644
--- a/drivers/serial/ip22zilog.c
+++ b/drivers/serial/ip22zilog.c
@@ -518,27 +518,28 @@ static irqreturn_t ip22zilog_interrupt(int irq, void *dev_id, struct pt_regs *re
518static __inline__ unsigned char ip22zilog_read_channel_status(struct uart_port *port) 518static __inline__ unsigned char ip22zilog_read_channel_status(struct uart_port *port)
519{ 519{
520 struct zilog_channel *channel; 520 struct zilog_channel *channel;
521 unsigned long flags;
522 unsigned char status; 521 unsigned char status;
523 522
524 spin_lock_irqsave(&port->lock, flags);
525
526 channel = ZILOG_CHANNEL_FROM_PORT(port); 523 channel = ZILOG_CHANNEL_FROM_PORT(port);
527 status = readb(&channel->control); 524 status = readb(&channel->control);
528 ZSDELAY(); 525 ZSDELAY();
529 526
530 spin_unlock_irqrestore(&port->lock, flags);
531
532 return status; 527 return status;
533} 528}
534 529
535/* The port lock is not held. */ 530/* The port lock is not held. */
536static unsigned int ip22zilog_tx_empty(struct uart_port *port) 531static unsigned int ip22zilog_tx_empty(struct uart_port *port)
537{ 532{
533 unsigned long flags;
538 unsigned char status; 534 unsigned char status;
539 unsigned int ret; 535 unsigned int ret;
540 536
537 spin_lock_irqsave(&port->lock, flags);
538
541 status = ip22zilog_read_channel_status(port); 539 status = ip22zilog_read_channel_status(port);
540
541 spin_unlock_irqrestore(&port->lock, flags);
542
542 if (status & Tx_BUF_EMP) 543 if (status & Tx_BUF_EMP)
543 ret = TIOCSER_TEMT; 544 ret = TIOCSER_TEMT;
544 else 545 else
@@ -547,7 +548,7 @@ static unsigned int ip22zilog_tx_empty(struct uart_port *port)
547 return ret; 548 return ret;
548} 549}
549 550
550/* The port lock is not held. */ 551/* The port lock is held and interrupts are disabled. */
551static unsigned int ip22zilog_get_mctrl(struct uart_port *port) 552static unsigned int ip22zilog_get_mctrl(struct uart_port *port)
552{ 553{
553 unsigned char status; 554 unsigned char status;
diff --git a/drivers/serial/mpsc.c b/drivers/serial/mpsc.c
index a2a643318002..e43276c6a954 100644
--- a/drivers/serial/mpsc.c
+++ b/drivers/serial/mpsc.c
@@ -1058,12 +1058,9 @@ mpsc_get_mctrl(struct uart_port *port)
1058{ 1058{
1059 struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1059 struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1060 u32 mflags, status; 1060 u32 mflags, status;
1061 ulong iflags;
1062 1061
1063 spin_lock_irqsave(&pi->port.lock, iflags);
1064 status = (pi->mirror_regs) ? pi->MPSC_CHR_10_m : 1062 status = (pi->mirror_regs) ? pi->MPSC_CHR_10_m :
1065 readl(pi->mpsc_base + MPSC_CHR_10); 1063 readl(pi->mpsc_base + MPSC_CHR_10);
1066 spin_unlock_irqrestore(&pi->port.lock, iflags);
1067 1064
1068 mflags = 0; 1065 mflags = 0;
1069 if (status & 0x1) 1066 if (status & 0x1)
diff --git a/drivers/serial/pmac_zilog.c b/drivers/serial/pmac_zilog.c
index 85abd8a045e0..1c9f71617123 100644
--- a/drivers/serial/pmac_zilog.c
+++ b/drivers/serial/pmac_zilog.c
@@ -604,7 +604,7 @@ static void pmz_set_mctrl(struct uart_port *port, unsigned int mctrl)
604/* 604/*
605 * Get Modem Control bits (only the input ones, the core will 605 * Get Modem Control bits (only the input ones, the core will
606 * or that with a cached value of the control ones) 606 * or that with a cached value of the control ones)
607 * The port lock is not held. 607 * The port lock is held and interrupts are disabled.
608 */ 608 */
609static unsigned int pmz_get_mctrl(struct uart_port *port) 609static unsigned int pmz_get_mctrl(struct uart_port *port)
610{ 610{
@@ -615,7 +615,7 @@ static unsigned int pmz_get_mctrl(struct uart_port *port)
615 if (ZS_IS_ASLEEP(uap) || uap->node == NULL) 615 if (ZS_IS_ASLEEP(uap) || uap->node == NULL)
616 return 0; 616 return 0;
617 617
618 status = pmz_peek_status(to_pmz(port)); 618 status = read_zsreg(uap, R0);
619 619
620 ret = 0; 620 ret = 0;
621 if (status & DCD) 621 if (status & DCD)
diff --git a/drivers/serial/pxa.c b/drivers/serial/pxa.c
index 08b08d6ae904..461c81c93207 100644
--- a/drivers/serial/pxa.c
+++ b/drivers/serial/pxa.c
@@ -274,14 +274,11 @@ static unsigned int serial_pxa_tx_empty(struct uart_port *port)
274static unsigned int serial_pxa_get_mctrl(struct uart_port *port) 274static unsigned int serial_pxa_get_mctrl(struct uart_port *port)
275{ 275{
276 struct uart_pxa_port *up = (struct uart_pxa_port *)port; 276 struct uart_pxa_port *up = (struct uart_pxa_port *)port;
277 unsigned long flags;
278 unsigned char status; 277 unsigned char status;
279 unsigned int ret; 278 unsigned int ret;
280 279
281return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; 280return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
282 spin_lock_irqsave(&up->port.lock, flags);
283 status = serial_in(up, UART_MSR); 281 status = serial_in(up, UART_MSR);
284 spin_unlock_irqrestore(&up->port.lock, flags);
285 282
286 ret = 0; 283 ret = 0;
287 if (status & UART_MSR_DCD) 284 if (status & UART_MSR_DCD)
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 36b1ae083fb7..139863a787f3 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -182,6 +182,13 @@ static int uart_startup(struct uart_state *state, int init_hw)
182 uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR); 182 uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR);
183 } 183 }
184 184
185 if (info->flags & UIF_CTS_FLOW) {
186 spin_lock_irq(&port->lock);
187 if (!(port->ops->get_mctrl(port) & TIOCM_CTS))
188 info->tty->hw_stopped = 1;
189 spin_unlock_irq(&port->lock);
190 }
191
185 info->flags |= UIF_INITIALIZED; 192 info->flags |= UIF_INITIALIZED;
186 193
187 clear_bit(TTY_IO_ERROR, &info->tty->flags); 194 clear_bit(TTY_IO_ERROR, &info->tty->flags);
@@ -828,7 +835,10 @@ static int uart_tiocmget(struct tty_struct *tty, struct file *file)
828 if ((!file || !tty_hung_up_p(file)) && 835 if ((!file || !tty_hung_up_p(file)) &&
829 !(tty->flags & (1 << TTY_IO_ERROR))) { 836 !(tty->flags & (1 << TTY_IO_ERROR))) {
830 result = port->mctrl; 837 result = port->mctrl;
838
839 spin_lock_irq(&port->lock);
831 result |= port->ops->get_mctrl(port); 840 result |= port->ops->get_mctrl(port);
841 spin_unlock_irq(&port->lock);
832 } 842 }
833 up(&state->sem); 843 up(&state->sem);
834 844
@@ -1131,6 +1141,16 @@ static void uart_set_termios(struct tty_struct *tty, struct termios *old_termios
1131 spin_unlock_irqrestore(&state->port->lock, flags); 1141 spin_unlock_irqrestore(&state->port->lock, flags);
1132 } 1142 }
1133 1143
1144 /* Handle turning on CRTSCTS */
1145 if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) {
1146 spin_lock_irqsave(&state->port->lock, flags);
1147 if (!(state->port->ops->get_mctrl(state->port) & TIOCM_CTS)) {
1148 tty->hw_stopped = 1;
1149 state->port->ops->stop_tx(state->port, 0);
1150 }
1151 spin_unlock_irqrestore(&state->port->lock, flags);
1152 }
1153
1134#if 0 1154#if 0
1135 /* 1155 /*
1136 * No need to wake up processes in open wait, since they 1156 * No need to wake up processes in open wait, since they
@@ -1369,6 +1389,7 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
1369 DECLARE_WAITQUEUE(wait, current); 1389 DECLARE_WAITQUEUE(wait, current);
1370 struct uart_info *info = state->info; 1390 struct uart_info *info = state->info;
1371 struct uart_port *port = state->port; 1391 struct uart_port *port = state->port;
1392 unsigned int mctrl;
1372 1393
1373 info->blocked_open++; 1394 info->blocked_open++;
1374 state->count--; 1395 state->count--;
@@ -1416,7 +1437,10 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
1416 * and wait for the carrier to indicate that the 1437 * and wait for the carrier to indicate that the
1417 * modem is ready for us. 1438 * modem is ready for us.
1418 */ 1439 */
1419 if (port->ops->get_mctrl(port) & TIOCM_CAR) 1440 spin_lock_irq(&port->lock);
1441 mctrl = port->ops->get_mctrl(port);
1442 spin_unlock_irq(&port->lock);
1443 if (mctrl & TIOCM_CAR)
1420 break; 1444 break;
1421 1445
1422 up(&state->sem); 1446 up(&state->sem);
@@ -1618,7 +1642,9 @@ static int uart_line_info(char *buf, struct uart_driver *drv, int i)
1618 1642
1619 if(capable(CAP_SYS_ADMIN)) 1643 if(capable(CAP_SYS_ADMIN))
1620 { 1644 {
1645 spin_lock_irq(&port->lock);
1621 status = port->ops->get_mctrl(port); 1646 status = port->ops->get_mctrl(port);
1647 spin_unlock_irq(&port->lock);
1622 1648
1623 ret += sprintf(buf + ret, " tx:%d rx:%d", 1649 ret += sprintf(buf + ret, " tx:%d rx:%d",
1624 port->icount.tx, port->icount.rx); 1650 port->icount.tx, port->icount.rx);
diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
index 0d7b65f93e8d..73a34b18866f 100644
--- a/drivers/serial/serial_cs.c
+++ b/drivers/serial/serial_cs.c
@@ -772,6 +772,111 @@ serial_event(event_t event, int priority, event_callback_args_t * args)
772 return 0; 772 return 0;
773} 773}
774 774
775static struct pcmcia_device_id serial_ids[] = {
776 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0057, 0x0021),
777 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0089, 0x110a),
778 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0104, 0x000a),
779 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0105, 0xea15),
780 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0109, 0x0501),
781 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0138, 0x110a),
782 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0140, 0x000a),
783 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0143, 0x3341),
784 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0143, 0xc0ab),
785 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x016c, 0x0081),
786 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x021b, 0x0101),
787 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x08a1, 0xc0ab),
788 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0105, 0x0d0a),
789 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0105, 0x0e0a),
790 PCMCIA_PFC_DEVICE_PROD_ID123(1, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
791 PCMCIA_PFC_DEVICE_PROD_ID123(1, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
792 PCMCIA_PFC_DEVICE_PROD_ID123(1, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
793 PCMCIA_PFC_DEVICE_PROD_ID123(1, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
794 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea),
795 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "CEM33", 0x2e3ee845, 0x80609023),
796 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
797 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
798 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
799 PCMCIA_PFC_DEVICE_PROD_ID12(1, "AnyCom", "Fast Ethernet ", 0x578ba6e7, 0x02d92d1e),
800 PCMCIA_PFC_DEVICE_PROD_ID12(1, "D-Link", "DME336T", 0x1a424a1c, 0xb23897ff),
801 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
802 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Grey Cell", "GCS3000", 0x2a151fac, 0x48b932ae),
803 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Linksys", "EtherFast 10&100 + 56K PC Card (PCMLM56)", 0x0733cc81, 0xb3765033),
804 PCMCIA_PFC_DEVICE_PROD_ID12(1, "LINKSYS", "PCMLM336", 0xf7cb0b07, 0x7a821b58),
805 PCMCIA_PFC_DEVICE_PROD_ID12(1, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
806 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
807 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
808 PCMCIA_PFC_DEVICE_PROD_ID12(1, "PCMCIAs", "ComboCard", 0xdcfe12d3, 0xcd8906cc),
809 PCMCIA_PFC_DEVICE_PROD_ID12(1, "PCMCIAs", "LanModem", 0xdcfe12d3, 0xc67c648f),
810 PCMCIA_PFC_DEVICE_PROD_ID12(1, "TDK", "GlobalNetworker 3410/3412", 0x1eae9475, 0xd9a93bed),
811 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Xircom", "CreditCard Ethernet", 0x2e3ee845, 0xc0e778c2),
812 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x0104, 0x0070),
813 PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x0101, 0x0562),
814 PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x0104, 0x0070),
815 PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x016c, 0x0020),
816 PCMCIA_MFC_DEVICE_PROD_ID123(1, "APEX DATA", "MULTICARD", "ETHERNET-MODEM", 0x11c2da09, 0x7289dc5d, 0xaad95e1f),
817 PCMCIA_MFC_DEVICE_PROD_ID12(1, "IBM", "Home and Away 28.8 PC Card ", 0xb569a6e5, 0x5bd4ff2c),
818 PCMCIA_MFC_DEVICE_PROD_ID12(1, "IBM", "Home and Away Credit Card Adapter", 0xb569a6e5, 0x4bdf15c3),
819 PCMCIA_MFC_DEVICE_PROD_ID12(1, "IBM", "w95 Home and Away Credit Card ", 0xb569a6e5, 0xae911c15),
820 PCMCIA_MFC_DEVICE_PROD_ID1(1, "Motorola MARQUIS", 0xf03e4e77),
821 PCMCIA_MFC_DEVICE_PROD_ID2(1, "FAX/Modem/Ethernet Combo Card ", 0x1ed59302),
822 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0301),
823 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0039),
824 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0006),
825 PCMCIA_DEVICE_MANF_CARD(0x0105, 0x410a),
826 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0d50),
827 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0d51),
828 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0d52),
829 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0d53),
830 PCMCIA_DEVICE_MANF_CARD(0x010b, 0xd180),
831 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x000e),
832 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x001b),
833 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0025),
834 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0045),
835 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0052),
836 PCMCIA_DEVICE_PROD_ID134("ADV", "TECH", "COMpad-32/85", 0x67459937, 0x916d02ba, 0x8fbe92ae),
837 PCMCIA_DEVICE_PROD_ID124("GATEWAY2000", "CC3144", "PCMCIA MODEM", 0x506bccae, 0xcb3685f1, 0xbd6c43ef),
838 PCMCIA_DEVICE_PROD_ID14("MEGAHERTZ", "PCMCIA MODEM", 0xf510db04, 0xbd6c43ef),
839 PCMCIA_DEVICE_PROD_ID124("TOSHIBA", "T144PF", "PCMCIA MODEM", 0xb4585a1a, 0x7271409c, 0xbd6c43ef),
840 PCMCIA_DEVICE_PROD_ID123("FUJITSU", "FC14F ", "MBH10213", 0x6ee5a3d8, 0x30ead12b, 0xb00f05a0),
841 PCMCIA_DEVICE_PROD_ID13("MEGAHERTZ", "V.34 PCMCIA MODEM", 0xf510db04, 0xbb2cce4a),
842 PCMCIA_DEVICE_PROD_ID12("Brain Boxes", "Bluetooth PC Card", 0xee138382, 0xd4ce9b02),
843 PCMCIA_DEVICE_PROD_ID12("CIRRUS LOGIC", "FAX MODEM", 0xe625f451, 0xcecd6dfa),
844 PCMCIA_DEVICE_PROD_ID12("COMPAQ", "PCMCIA 28800 FAX/DATA MODEM", 0xa3a3062c, 0x8cbd7c76),
845 PCMCIA_DEVICE_PROD_ID12("COMPAQ", "PCMCIA 33600 FAX/DATA MODEM", 0xa3a3062c, 0x5a00ce95),
846 PCMCIA_DEVICE_PROD_ID12("Computerboards, Inc.", "PCM-COM422", 0xd0b78f51, 0x7e2d49ed),
847 PCMCIA_DEVICE_PROD_ID12("Dr. Neuhaus", "FURY CARD 14K4", 0x76942813, 0x8b96ce65),
848 PCMCIA_DEVICE_PROD_ID12("Intelligent", "ANGIA FAX/MODEM", 0xb496e65e, 0xf31602a6),
849 PCMCIA_DEVICE_PROD_ID12("Intel", "MODEM 2400", 0x816cc815, 0x23539b80),
850 PCMCIA_DEVICE_PROD_ID12("IOTech Inc ", "PCMCIA Dual RS-232 Serial Port Card", 0x3bd2d898, 0x92abc92f),
851 PCMCIA_DEVICE_PROD_ID12("MACRONIX", "FAX/MODEM", 0x668388b3, 0x3f9bdf2f),
852 PCMCIA_DEVICE_PROD_ID12("Multi-Tech", "MT1432LT", 0x5f73be51, 0x0b3e2383),
853 PCMCIA_DEVICE_PROD_ID12("Multi-Tech", "MT2834LT", 0x5f73be51, 0x4cd7c09e),
854 PCMCIA_DEVICE_PROD_ID12("OEM ", "C288MX ", 0xb572d360, 0xd2385b7a),
855 PCMCIA_DEVICE_PROD_ID12("PCMCIA ", "C336MX ", 0x99bcafe9, 0xaa25bcab),
856 PCMCIA_DEVICE_PROD_ID12("Quatech Inc", "PCMCIA Dual RS-232 Serial Port Card", 0xc4420b35, 0x92abc92f),
857 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "EN2218-LAN/MODEM", 0x281f1c5d, 0x570f348e, "PCMLM28.cis"),
858 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "UE2218-LAN/MODEM", 0x281f1c5d, 0x6fdcacee, "PCMLM28.cis"),
859 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "Psion Dacom", "Gold Card V34 Ethernet", 0xf5f025c2, 0x338e8155, "PCMLM28.cis"),
860 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "Psion Dacom", "Gold Card V34 Ethernet GSM", 0xf5f025c2, 0x4ae85d35, "PCMLM28.cis"),
861 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "LINKSYS", "PCMLM28", 0xf7cb0b07, 0x66881874, "PCMLM28.cis"),
862 PCMCIA_MFC_DEVICE_CIS_PROD_ID12(1, "DAYNA COMMUNICATIONS", "LAN AND MODEM MULTIFUNCTION", 0x8fdf8f89, 0xdd5ed9e8, "DP83903.cis"),
863 PCMCIA_MFC_DEVICE_CIS_PROD_ID4(1, "NSC MF LAN/Modem", 0x58fc6056, "DP83903.cis"),
864 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(1, 0x0101, 0x0556, "3CCFEM556.cis"),
865 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(1, 0x0175, 0x0000, "DP83903.cis"),
866 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(1, 0x0101, 0x0035, "3CXEM556.cis"),
867 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(1, 0x0101, 0x003d, "3CXEM556.cis"),
868 PCMCIA_DEVICE_CIS_PROD_ID12("MultiTech", "PCMCIA 56K DataFax", 0x842047ee, 0xc2efcf03, "MT5634ZLX.cis"),
869 PCMCIA_DEVICE_CIS_PROD_ID12("ADVANTECH", "COMpad-32/85B-4", 0x96913a85, 0xcec8f102, "COMpad4.cis"),
870 PCMCIA_DEVICE_CIS_PROD_ID123("ADVANTECH", "COMpad-32/85", "1.0", 0x96913a85, 0x8fbe92ae, 0x0877b627, "COMpad2.cis"),
871 PCMCIA_DEVICE_CIS_PROD_ID2("RS-COM 2P", 0xad20b156, "RS-COM-2P.cis"),
872 /* too generic */
873 /* PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x0160, 0x0002), */
874 /* PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x0160, 0x0002), */
875 PCMCIA_DEVICE_FUNC_ID(2),
876 PCMCIA_DEVICE_NULL,
877};
878MODULE_DEVICE_TABLE(pcmcia, serial_ids);
879
775static struct pcmcia_driver serial_cs_driver = { 880static struct pcmcia_driver serial_cs_driver = {
776 .owner = THIS_MODULE, 881 .owner = THIS_MODULE,
777 .drv = { 882 .drv = {
@@ -779,6 +884,7 @@ static struct pcmcia_driver serial_cs_driver = {
779 }, 884 },
780 .attach = serial_attach, 885 .attach = serial_attach,
781 .detach = serial_detach, 886 .detach = serial_detach,
887 .id_table = serial_ids,
782}; 888};
783 889
784static int __init init_serial_cs(void) 890static int __init init_serial_cs(void)
diff --git a/drivers/serial/serial_txx9.c b/drivers/serial/serial_txx9.c
index 3f1051a4a13f..d085030df70b 100644
--- a/drivers/serial/serial_txx9.c
+++ b/drivers/serial/serial_txx9.c
@@ -442,13 +442,10 @@ static unsigned int serial_txx9_tx_empty(struct uart_port *port)
442static unsigned int serial_txx9_get_mctrl(struct uart_port *port) 442static unsigned int serial_txx9_get_mctrl(struct uart_port *port)
443{ 443{
444 struct uart_txx9_port *up = (struct uart_txx9_port *)port; 444 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
445 unsigned long flags;
446 unsigned int ret; 445 unsigned int ret;
447 446
448 spin_lock_irqsave(&up->port.lock, flags);
449 ret = ((sio_in(up, TXX9_SIFLCR) & TXX9_SIFLCR_RTSSC) ? 0 : TIOCM_RTS) 447 ret = ((sio_in(up, TXX9_SIFLCR) & TXX9_SIFLCR_RTSSC) ? 0 : TIOCM_RTS)
450 | ((sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS) ? 0 : TIOCM_CTS); 448 | ((sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS) ? 0 : TIOCM_CTS);
451 spin_unlock_irqrestore(&up->port.lock, flags);
452 449
453 return ret; 450 return ret;
454} 451}
diff --git a/drivers/serial/sunsab.c b/drivers/serial/sunsab.c
index 10e2990a40d4..8d198880756a 100644
--- a/drivers/serial/sunsab.c
+++ b/drivers/serial/sunsab.c
@@ -426,18 +426,15 @@ static void sunsab_set_mctrl(struct uart_port *port, unsigned int mctrl)
426 sunsab_tx_idle(up); 426 sunsab_tx_idle(up);
427} 427}
428 428
429/* port->lock is not held. */ 429/* port->lock is held by caller and interrupts are disabled. */
430static unsigned int sunsab_get_mctrl(struct uart_port *port) 430static unsigned int sunsab_get_mctrl(struct uart_port *port)
431{ 431{
432 struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 432 struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
433 unsigned long flags;
434 unsigned char val; 433 unsigned char val;
435 unsigned int result; 434 unsigned int result;
436 435
437 result = 0; 436 result = 0;
438 437
439 spin_lock_irqsave(&up->port.lock, flags);
440
441 val = readb(&up->regs->r.pvr); 438 val = readb(&up->regs->r.pvr);
442 result |= (val & up->pvr_dsr_bit) ? 0 : TIOCM_DSR; 439 result |= (val & up->pvr_dsr_bit) ? 0 : TIOCM_DSR;
443 440
@@ -447,8 +444,6 @@ static unsigned int sunsab_get_mctrl(struct uart_port *port)
447 val = readb(&up->regs->r.star); 444 val = readb(&up->regs->r.star);
448 result |= (val & SAB82532_STAR_CTS) ? TIOCM_CTS : 0; 445 result |= (val & SAB82532_STAR_CTS) ? TIOCM_CTS : 0;
449 446
450 spin_unlock_irqrestore(&up->port.lock, flags);
451
452 return result; 447 return result;
453} 448}
454 449
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index ddc97c905e14..d57a3553aea3 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -572,13 +572,10 @@ static unsigned int sunsu_tx_empty(struct uart_port *port)
572static unsigned int sunsu_get_mctrl(struct uart_port *port) 572static unsigned int sunsu_get_mctrl(struct uart_port *port)
573{ 573{
574 struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 574 struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
575 unsigned long flags;
576 unsigned char status; 575 unsigned char status;
577 unsigned int ret; 576 unsigned int ret;
578 577
579 spin_lock_irqsave(&up->port.lock, flags);
580 status = serial_in(up, UART_MSR); 578 status = serial_in(up, UART_MSR);
581 spin_unlock_irqrestore(&up->port.lock, flags);
582 579
583 ret = 0; 580 ret = 0;
584 if (status & UART_MSR_DCD) 581 if (status & UART_MSR_DCD)
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index 8e65206d3d76..bff42a7b89d0 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -610,27 +610,28 @@ static irqreturn_t sunzilog_interrupt(int irq, void *dev_id, struct pt_regs *reg
610static __inline__ unsigned char sunzilog_read_channel_status(struct uart_port *port) 610static __inline__ unsigned char sunzilog_read_channel_status(struct uart_port *port)
611{ 611{
612 struct zilog_channel __iomem *channel; 612 struct zilog_channel __iomem *channel;
613 unsigned long flags;
614 unsigned char status; 613 unsigned char status;
615 614
616 spin_lock_irqsave(&port->lock, flags);
617
618 channel = ZILOG_CHANNEL_FROM_PORT(port); 615 channel = ZILOG_CHANNEL_FROM_PORT(port);
619 status = sbus_readb(&channel->control); 616 status = sbus_readb(&channel->control);
620 ZSDELAY(); 617 ZSDELAY();
621 618
622 spin_unlock_irqrestore(&port->lock, flags);
623
624 return status; 619 return status;
625} 620}
626 621
627/* The port lock is not held. */ 622/* The port lock is not held. */
628static unsigned int sunzilog_tx_empty(struct uart_port *port) 623static unsigned int sunzilog_tx_empty(struct uart_port *port)
629{ 624{
625 unsigned long flags;
630 unsigned char status; 626 unsigned char status;
631 unsigned int ret; 627 unsigned int ret;
632 628
629 spin_lock_irqsave(&port->lock, flags);
630
633 status = sunzilog_read_channel_status(port); 631 status = sunzilog_read_channel_status(port);
632
633 spin_unlock_irqrestore(&port->lock, flags);
634
634 if (status & Tx_BUF_EMP) 635 if (status & Tx_BUF_EMP)
635 ret = TIOCSER_TEMT; 636 ret = TIOCSER_TEMT;
636 else 637 else
@@ -639,7 +640,7 @@ static unsigned int sunzilog_tx_empty(struct uart_port *port)
639 return ret; 640 return ret;
640} 641}
641 642
642/* The port lock is not held. */ 643/* The port lock is held and interrupts are disabled. */
643static unsigned int sunzilog_get_mctrl(struct uart_port *port) 644static unsigned int sunzilog_get_mctrl(struct uart_port *port)
644{ 645{
645 unsigned char status; 646 unsigned char status;
diff --git a/drivers/telephony/ixj_pcmcia.c b/drivers/telephony/ixj_pcmcia.c
index e1ef0d7ee8d1..ce5ebfe4af2b 100644
--- a/drivers/telephony/ixj_pcmcia.c
+++ b/drivers/telephony/ixj_pcmcia.c
@@ -295,6 +295,12 @@ static int ixj_event(event_t event, int priority, event_callback_args_t * args)
295 return 0; 295 return 0;
296} 296}
297 297
298static struct pcmcia_device_id ixj_ids[] = {
299 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
300 PCMCIA_DEVICE_NULL
301};
302MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
303
298static struct pcmcia_driver ixj_driver = { 304static struct pcmcia_driver ixj_driver = {
299 .owner = THIS_MODULE, 305 .owner = THIS_MODULE,
300 .drv = { 306 .drv = {
@@ -302,6 +308,7 @@ static struct pcmcia_driver ixj_driver = {
302 }, 308 },
303 .attach = ixj_attach, 309 .attach = ixj_attach,
304 .detach = ixj_detach, 310 .detach = ixj_detach,
311 .id_table = ixj_ids,
305}; 312};
306 313
307static int __init ixj_pcmcia_init(void) 314static int __init ixj_pcmcia_init(void)
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index a61d4433a989..d79cd218a551 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_USB) += core/
9obj-$(CONFIG_USB_MON) += mon/ 9obj-$(CONFIG_USB_MON) += mon/
10 10
11obj-$(CONFIG_USB_EHCI_HCD) += host/ 11obj-$(CONFIG_USB_EHCI_HCD) += host/
12obj-$(CONFIG_USB_ISP116X_HCD) += host/
12obj-$(CONFIG_USB_OHCI_HCD) += host/ 13obj-$(CONFIG_USB_OHCI_HCD) += host/
13obj-$(CONFIG_USB_UHCI_HCD) += host/ 14obj-$(CONFIG_USB_UHCI_HCD) += host/
14obj-$(CONFIG_USB_SL811_HCD) += host/ 15obj-$(CONFIG_USB_SL811_HCD) += host/
@@ -31,6 +32,7 @@ obj-$(CONFIG_USB_MOUSE) += input/
31obj-$(CONFIG_USB_MTOUCH) += input/ 32obj-$(CONFIG_USB_MTOUCH) += input/
32obj-$(CONFIG_USB_POWERMATE) += input/ 33obj-$(CONFIG_USB_POWERMATE) += input/
33obj-$(CONFIG_USB_WACOM) += input/ 34obj-$(CONFIG_USB_WACOM) += input/
35obj-$(CONFIG_USB_ACECAD) += input/
34obj-$(CONFIG_USB_XPAD) += input/ 36obj-$(CONFIG_USB_XPAD) += input/
35 37
36obj-$(CONFIG_USB_DABUSB) += media/ 38obj-$(CONFIG_USB_DABUSB) += media/
diff --git a/drivers/usb/atm/Kconfig b/drivers/usb/atm/Kconfig
index 0d9f5379b8cf..f429862e0974 100644
--- a/drivers/usb/atm/Kconfig
+++ b/drivers/usb/atm/Kconfig
@@ -1,30 +1,60 @@
1# 1#
2# USB ATM driver configuration 2# USB/ATM DSL configuration
3# 3#
4comment "USB ATM/DSL drivers" 4
5menu "USB DSL modem support"
5 depends on USB 6 depends on USB
6 7
7config USB_ATM 8config USB_ATM
8 tristate "Generic USB ATM/DSL core I/O support" 9 tristate "USB DSL modem support"
9 depends on USB && ATM 10 depends on USB && ATM
10 select CRC32 11 select CRC32
11 default n 12 default n
12 help 13 help
13 This provides a library which is used for packet I/O by USB DSL 14 Say Y here if you want to connect a USB Digital Subscriber Line (DSL)
14 modems, such as the SpeedTouch driver below. 15 modem to your computer's USB port. You will then need to choose your
16 modem from the list below.
15 17
16 To compile this driver as a module, choose M here: the 18 To compile this driver as a module, choose M here: the
17 module will be called usb_atm. 19 module will be called usbatm.
18 20
19config USB_SPEEDTOUCH 21config USB_SPEEDTOUCH
20 tristate "Alcatel Speedtouch USB support" 22 tristate "Speedtouch USB support"
21 depends on USB && ATM 23 depends on USB_ATM
22 select USB_ATM 24 select FW_LOADER
23 help 25 help
24 Say Y here if you have an Alcatel SpeedTouch USB or SpeedTouch 330 26 Say Y here if you have an SpeedTouch USB or SpeedTouch 330
25 modem. In order to use your modem you will need to install the 27 modem. In order to use your modem you will need to install the
26 two parts of the firmware, extracted by the user space tools; see 28 two parts of the firmware, extracted by the user space tools; see
27 <http://www.linux-usb.org/SpeedTouch/> for details. 29 <http://www.linux-usb.org/SpeedTouch/> for details.
28 30
29 To compile this driver as a module, choose M here: the 31 To compile this driver as a module, choose M here: the
30 module will be called speedtch. 32 module will be called speedtch.
33
34config USB_CXACRU
35 tristate "Conexant AccessRunner USB support"
36 depends on USB_ATM
37 select FW_LOADER
38 help
39 Say Y here if you have an ADSL USB modem based on the Conexant
40 AccessRunner chipset. In order to use your modem you will need to
41 install the firmware, extracted by the user space tools; see
42 <http://accessrunner.sourceforge.net/> for details.
43
44 To compile this driver as a module, choose M here: the
45 module will be called cxacru.
46
47config USB_XUSBATM
48 tristate "Other USB DSL modem support"
49 depends on USB_ATM
50 help
51 Say Y here if you have a DSL USB modem not explicitly supported by
52 another USB DSL drivers. In order to use your modem you will need to
53 pass the vendor ID, product ID, and endpoint numbers for transmission
54 and reception as module parameters. You may need to initialize the
55 the modem using a user space utility (a firmware loader for example).
56
57 To compile this driver as a module, choose M here: the
58 module will be called xusbatm.
59
60endmenu
diff --git a/drivers/usb/atm/Makefile b/drivers/usb/atm/Makefile
index 9213b8b97587..751f297be2ef 100644
--- a/drivers/usb/atm/Makefile
+++ b/drivers/usb/atm/Makefile
@@ -1,7 +1,8 @@
1# 1#
2# Makefile for the rest of the USB drivers 2# Makefile for USB ATM/xDSL drivers
3# (the ones that don't fit into any other categories)
4# 3#
5 4
6obj-$(CONFIG_USB_ATM) += usb_atm.o 5obj-$(CONFIG_USB_CXACRU) += cxacru.o
7obj-$(CONFIG_USB_SPEEDTOUCH) += speedtch.o 6obj-$(CONFIG_USB_SPEEDTOUCH) += speedtch.o
7obj-$(CONFIG_USB_ATM) += usbatm.o
8obj-$(CONFIG_USB_XUSBATM) += xusbatm.o
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
new file mode 100644
index 000000000000..cbd4a7d25d0b
--- /dev/null
+++ b/drivers/usb/atm/cxacru.c
@@ -0,0 +1,878 @@
1/******************************************************************************
2 * cxacru.c - driver for USB ADSL modems based on
3 * Conexant AccessRunner chipset
4 *
5 * Copyright (C) 2004 David Woodhouse, Duncan Sands, Roman Kagan
6 * Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru)
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 ******************************************************************************/
23
24/*
25 * Credit is due for Josep Comas, who created the original patch to speedtch.c
26 * to support the different padding used by the AccessRunner (now generalized
27 * into usbatm), and the userspace firmware loading utility.
28 */
29
30#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/kernel.h>
33#include <linux/timer.h>
34#include <linux/errno.h>
35#include <linux/slab.h>
36#include <linux/init.h>
37#include <linux/device.h> /* FIXME: linux/firmware.h should include it itself */
38#include <linux/firmware.h>
39
40#include "usbatm.h"
41
42#define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands"
43#define DRIVER_VERSION "0.2"
44#define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver"
45
46static const char cxacru_driver_name[] = "cxacru";
47
48#define CXACRU_EP_CMD 0x01 /* Bulk/interrupt in/out */
49#define CXACRU_EP_DATA 0x02 /* Bulk in/out */
50
51#define CMD_PACKET_SIZE 64 /* Should be maxpacket(ep)? */
52
53/* Addresses */
54#define PLLFCLK_ADDR 0x00350068
55#define PLLBCLK_ADDR 0x0035006c
56#define SDRAMEN_ADDR 0x00350010
57#define FW_ADDR 0x00801000
58#define BR_ADDR 0x00180600
59#define SIG_ADDR 0x00180500
60#define BR_STACK_ADDR 0x00187f10
61
62/* Values */
63#define SDRAM_ENA 0x1
64
65#define CMD_TIMEOUT 2000 /* msecs */
66#define POLL_INTERVAL 5000 /* msecs */
67
68/* commands for interaction with the modem through the control channel before
69 * firmware is loaded */
70enum cxacru_fw_request {
71 FW_CMD_ERR,
72 FW_GET_VER,
73 FW_READ_MEM,
74 FW_WRITE_MEM,
75 FW_RMW_MEM,
76 FW_CHECKSUM_MEM,
77 FW_GOTO_MEM,
78};
79
80/* commands for interaction with the modem through the control channel once
81 * firmware is loaded */
82enum cxacru_cm_request {
83 CM_REQUEST_UNDEFINED = 0x80,
84 CM_REQUEST_TEST,
85 CM_REQUEST_CHIP_GET_MAC_ADDRESS,
86 CM_REQUEST_CHIP_GET_DP_VERSIONS,
87 CM_REQUEST_CHIP_ADSL_LINE_START,
88 CM_REQUEST_CHIP_ADSL_LINE_STOP,
89 CM_REQUEST_CHIP_ADSL_LINE_GET_STATUS,
90 CM_REQUEST_CHIP_ADSL_LINE_GET_SPEED,
91 CM_REQUEST_CARD_INFO_GET,
92 CM_REQUEST_CARD_DATA_GET,
93 CM_REQUEST_CARD_DATA_SET,
94 CM_REQUEST_COMMAND_HW_IO,
95 CM_REQUEST_INTERFACE_HW_IO,
96 CM_REQUEST_CARD_SERIAL_DATA_PATH_GET,
97 CM_REQUEST_CARD_SERIAL_DATA_PATH_SET,
98 CM_REQUEST_CARD_CONTROLLER_VERSION_GET,
99 CM_REQUEST_CARD_GET_STATUS,
100 CM_REQUEST_CARD_GET_MAC_ADDRESS,
101 CM_REQUEST_CARD_GET_DATA_LINK_STATUS,
102 CM_REQUEST_MAX,
103};
104
105/* reply codes to the commands above */
106enum cxacru_cm_status {
107 CM_STATUS_UNDEFINED,
108 CM_STATUS_SUCCESS,
109 CM_STATUS_ERROR,
110 CM_STATUS_UNSUPPORTED,
111 CM_STATUS_UNIMPLEMENTED,
112 CM_STATUS_PARAMETER_ERROR,
113 CM_STATUS_DBG_LOOPBACK,
114 CM_STATUS_MAX,
115};
116
117/* indices into CARD_INFO_GET return array */
118enum cxacru_info_idx {
119 CXINF_DOWNSTREAM_RATE,
120 CXINF_UPSTREAM_RATE,
121 CXINF_LINK_STATUS,
122 CXINF_LINE_STATUS,
123 CXINF_MAC_ADDRESS_HIGH,
124 CXINF_MAC_ADDRESS_LOW,
125 CXINF_UPSTREAM_SNR_MARGIN,
126 CXINF_DOWNSTREAM_SNR_MARGIN,
127 CXINF_UPSTREAM_ATTENUATION,
128 CXINF_DOWNSTREAM_ATTENUATION,
129 CXINF_TRANSMITTER_POWER,
130 CXINF_UPSTREAM_BITS_PER_FRAME,
131 CXINF_DOWNSTREAM_BITS_PER_FRAME,
132 CXINF_STARTUP_ATTEMPTS,
133 CXINF_UPSTREAM_CRC_ERRORS,
134 CXINF_DOWNSTREAM_CRC_ERRORS,
135 CXINF_UPSTREAM_FEC_ERRORS,
136 CXINF_DOWNSTREAM_FEC_ERRORS,
137 CXINF_UPSTREAM_HEC_ERRORS,
138 CXINF_DOWNSTREAM_HEC_ERRORS,
139 CXINF_LINE_STARTABLE,
140 CXINF_MODULATION,
141 CXINF_ADSL_HEADEND,
142 CXINF_ADSL_HEADEND_ENVIRONMENT,
143 CXINF_CONTROLLER_VERSION,
144 /* dunno what the missing two mean */
145 CXINF_MAX = 0x1c,
146};
147
148struct cxacru_modem_type {
149 u32 pll_f_clk;
150 u32 pll_b_clk;
151 int boot_rom_patch;
152};
153
154struct cxacru_data {
155 struct usbatm_data *usbatm;
156
157 const struct cxacru_modem_type *modem_type;
158
159 int line_status;
160 struct work_struct poll_work;
161
162 /* contol handles */
163 struct semaphore cm_serialize;
164 u8 *rcv_buf;
165 u8 *snd_buf;
166 struct urb *rcv_urb;
167 struct urb *snd_urb;
168 struct completion rcv_done;
169 struct completion snd_done;
170};
171
172/* the following three functions are stolen from drivers/usb/core/message.c */
173static void cxacru_blocking_completion(struct urb *urb, struct pt_regs *regs)
174{
175 complete((struct completion *)urb->context);
176}
177
178static void cxacru_timeout_kill(unsigned long data)
179{
180 usb_unlink_urb((struct urb *) data);
181}
182
183static int cxacru_start_wait_urb(struct urb *urb, struct completion *done,
184 int* actual_length)
185{
186 struct timer_list timer;
187 int status;
188
189 init_timer(&timer);
190 timer.expires = jiffies + msecs_to_jiffies(CMD_TIMEOUT);
191 timer.data = (unsigned long) urb;
192 timer.function = cxacru_timeout_kill;
193 add_timer(&timer);
194 wait_for_completion(done);
195 status = urb->status;
196 if (status == -ECONNRESET)
197 status = -ETIMEDOUT;
198 del_timer_sync(&timer);
199
200 if (actual_length)
201 *actual_length = urb->actual_length;
202 return status;
203}
204
205static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
206 u8 *wdata, int wsize, u8 *rdata, int rsize)
207{
208 int ret, actlen;
209 int offb, offd;
210 const int stride = CMD_PACKET_SIZE - 4;
211 u8 *wbuf = instance->snd_buf;
212 u8 *rbuf = instance->rcv_buf;
213 int wbuflen = ((wsize - 1) / stride + 1) * CMD_PACKET_SIZE;
214 int rbuflen = ((rsize - 1) / stride + 1) * CMD_PACKET_SIZE;
215
216 if (wbuflen > PAGE_SIZE || rbuflen > PAGE_SIZE) {
217 dbg("too big transfer requested");
218 ret = -ENOMEM;
219 goto fail;
220 }
221
222 down(&instance->cm_serialize);
223
224 /* submit reading urb before the writing one */
225 init_completion(&instance->rcv_done);
226 ret = usb_submit_urb(instance->rcv_urb, GFP_KERNEL);
227 if (ret < 0) {
228 dbg("submitting read urb for cm %#x failed", cm);
229 ret = ret;
230 goto fail;
231 }
232
233 memset(wbuf, 0, wbuflen);
234 /* handle wsize == 0 */
235 wbuf[0] = cm;
236 for (offb = offd = 0; offd < wsize; offd += stride, offb += CMD_PACKET_SIZE) {
237 wbuf[offb] = cm;
238 memcpy(wbuf + offb + 4, wdata + offd, min_t(int, stride, wsize - offd));
239 }
240
241 instance->snd_urb->transfer_buffer_length = wbuflen;
242 init_completion(&instance->snd_done);
243 ret = usb_submit_urb(instance->snd_urb, GFP_KERNEL);
244 if (ret < 0) {
245 dbg("submitting write urb for cm %#x failed", cm);
246 ret = ret;
247 goto fail;
248 }
249
250 ret = cxacru_start_wait_urb(instance->snd_urb, &instance->snd_done, NULL);
251 if (ret < 0) {
252 dbg("sending cm %#x failed", cm);
253 ret = ret;
254 goto fail;
255 }
256
257 ret = cxacru_start_wait_urb(instance->rcv_urb, &instance->rcv_done, &actlen);
258 if (ret < 0) {
259 dbg("receiving cm %#x failed", cm);
260 ret = ret;
261 goto fail;
262 }
263 if (actlen % CMD_PACKET_SIZE || !actlen) {
264 dbg("response is not a positive multiple of %d: %#x",
265 CMD_PACKET_SIZE, actlen);
266 ret = -EIO;
267 goto fail;
268 }
269
270 /* check the return status and copy the data to the output buffer, if needed */
271 for (offb = offd = 0; offd < rsize && offb < actlen; offb += CMD_PACKET_SIZE) {
272 if (rbuf[offb] != cm) {
273 dbg("wrong cm %#x in response", rbuf[offb]);
274 ret = -EIO;
275 goto fail;
276 }
277 if (rbuf[offb + 1] != CM_STATUS_SUCCESS) {
278 dbg("response failed: %#x", rbuf[offb + 1]);
279 ret = -EIO;
280 goto fail;
281 }
282 if (offd >= rsize)
283 break;
284 memcpy(rdata + offd, rbuf + offb + 4, min_t(int, stride, rsize - offd));
285 offd += stride;
286 }
287
288 ret = offd;
289 dbg("cm %#x", cm);
290fail:
291 up(&instance->cm_serialize);
292 return ret;
293}
294
295static int cxacru_cm_get_array(struct cxacru_data *instance, enum cxacru_cm_request cm,
296 u32 *data, int size)
297{
298 int ret, len;
299 u32 *buf;
300 int offb, offd;
301 const int stride = CMD_PACKET_SIZE / (4 * 2) - 1;
302 int buflen = ((size - 1) / stride + 1 + size * 2) * 4;
303
304 buf = kmalloc(buflen, GFP_KERNEL);
305 if (!buf)
306 return -ENOMEM;
307
308 ret = cxacru_cm(instance, cm, NULL, 0, (u8 *) buf, buflen);
309 if (ret < 0)
310 goto cleanup;
311
312 /* len > 0 && len % 4 == 0 guaranteed by cxacru_cm() */
313 len = ret / 4;
314 for (offb = 0; offb < len; ) {
315 int l = le32_to_cpu(buf[offb++]);
316 if (l > stride || l > (len - offb) / 2) {
317 dbg("wrong data length %#x in response", l);
318 ret = -EIO;
319 goto cleanup;
320 }
321 while (l--) {
322 offd = le32_to_cpu(buf[offb++]);
323 if (offd >= size) {
324 dbg("wrong index %#x in response", offd);
325 ret = -EIO;
326 goto cleanup;
327 }
328 data[offd] = le32_to_cpu(buf[offb++]);
329 }
330 }
331
332 ret = 0;
333
334cleanup:
335 kfree(buf);
336 return ret;
337}
338
339static int cxacru_card_status(struct cxacru_data *instance)
340{
341 int ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
342 if (ret < 0) { /* firmware not loaded */
343 dbg("cxacru_adsl_start: CARD_GET_STATUS returned %d", ret);
344 return ret;
345 }
346 return 0;
347}
348
349static void cxacru_poll_status(struct cxacru_data *instance);
350
351static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
352 struct atm_dev *atm_dev)
353{
354 struct cxacru_data *instance = usbatm_instance->driver_data;
355 struct device *dev = &usbatm_instance->usb_intf->dev;
356 /*
357 struct atm_dev *atm_dev = usbatm_instance->atm_dev;
358 */
359 int ret;
360
361 dbg("cxacru_atm_start");
362
363 /* Read MAC address */
364 ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_MAC_ADDRESS, NULL, 0,
365 atm_dev->esi, sizeof(atm_dev->esi));
366 if (ret < 0) {
367 dev_err(dev, "cxacru_atm_start: CARD_GET_MAC_ADDRESS returned %d\n", ret);
368 return ret;
369 }
370
371 /* start ADSL */
372 ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
373 if (ret < 0) {
374 dev_err(dev, "cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret);
375 return ret;
376 }
377
378 /* Start status polling */
379 cxacru_poll_status(instance);
380 return 0;
381}
382
383static void cxacru_poll_status(struct cxacru_data *instance)
384{
385 u32 buf[CXINF_MAX] = {};
386 struct device *dev = &instance->usbatm->usb_intf->dev;
387 struct atm_dev *atm_dev = instance->usbatm->atm_dev;
388 int ret;
389
390 ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX);
391 if (ret < 0) {
392 dev_warn(dev, "poll status: error %d\n", ret);
393 goto reschedule;
394 }
395
396 if (instance->line_status == buf[CXINF_LINE_STATUS])
397 goto reschedule;
398
399 instance->line_status = buf[CXINF_LINE_STATUS];
400 switch (instance->line_status) {
401 case 0:
402 atm_dev->signal = ATM_PHY_SIG_LOST;
403 dev_info(dev, "ADSL line: down\n");
404 break;
405
406 case 1:
407 atm_dev->signal = ATM_PHY_SIG_LOST;
408 dev_info(dev, "ADSL line: attemtping to activate\n");
409 break;
410
411 case 2:
412 atm_dev->signal = ATM_PHY_SIG_LOST;
413 dev_info(dev, "ADSL line: training\n");
414 break;
415
416 case 3:
417 atm_dev->signal = ATM_PHY_SIG_LOST;
418 dev_info(dev, "ADSL line: channel analysis\n");
419 break;
420
421 case 4:
422 atm_dev->signal = ATM_PHY_SIG_LOST;
423 dev_info(dev, "ADSL line: exchange\n");
424 break;
425
426 case 5:
427 atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424;
428 atm_dev->signal = ATM_PHY_SIG_FOUND;
429
430 dev_info(dev, "ADSL line: up (%d Kib/s down | %d Kib/s up)\n",
431 buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]);
432 break;
433
434 case 6:
435 atm_dev->signal = ATM_PHY_SIG_LOST;
436 dev_info(dev, "ADSL line: waiting\n");
437 break;
438
439 case 7:
440 atm_dev->signal = ATM_PHY_SIG_LOST;
441 dev_info(dev, "ADSL line: initializing\n");
442 break;
443
444 default:
445 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
446 dev_info(dev, "Unknown line state %02x\n", instance->line_status);
447 break;
448 }
449reschedule:
450 schedule_delayed_work(&instance->poll_work, msecs_to_jiffies(POLL_INTERVAL));
451}
452
453static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw,
454 u8 code1, u8 code2, u32 addr, u8 *data, int size)
455{
456 int ret;
457 u8 *buf;
458 int offd, offb;
459 const int stride = CMD_PACKET_SIZE - 8;
460
461 buf = (u8 *) __get_free_page(GFP_KERNEL);
462 if (!buf)
463 return -ENOMEM;
464
465 offb = offd = 0;
466 do {
467 int l = min_t(int, stride, size - offd);
468 buf[offb++] = fw;
469 buf[offb++] = l;
470 buf[offb++] = code1;
471 buf[offb++] = code2;
472 *((u32 *) (buf + offb)) = cpu_to_le32(addr);
473 offb += 4;
474 addr += l;
475 if(l)
476 memcpy(buf + offb, data + offd, l);
477 if (l < stride)
478 memset(buf + offb + l, 0, stride - l);
479 offb += stride;
480 offd += stride;
481 if ((offb >= PAGE_SIZE) || (offd >= size)) {
482 ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD),
483 buf, offb, NULL, CMD_TIMEOUT);
484 if (ret < 0) {
485 dbg("sending fw %#x failed", fw);
486 goto cleanup;
487 }
488 offb = 0;
489 }
490 } while(offd < size);
491 dbg("sent fw %#x", fw);
492
493 ret = 0;
494
495cleanup:
496 free_page((unsigned long) buf);
497 return ret;
498}
499
500static void cxacru_upload_firmware(struct cxacru_data *instance,
501 const struct firmware *fw,
502 const struct firmware *bp,
503 const struct firmware *cf)
504{
505 int ret;
506 int off;
507 struct usb_device *usb_dev = instance->usbatm->usb_dev;
508 struct device *dev = &instance->usbatm->usb_intf->dev;
509 u16 signature[] = { usb_dev->descriptor.idVendor, usb_dev->descriptor.idProduct };
510 u32 val;
511
512 dbg("cxacru_upload_firmware");
513
514 /* FirmwarePllFClkValue */
515 val = cpu_to_le32(instance->modem_type->pll_f_clk);
516 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4);
517 if (ret) {
518 dev_err(dev, "FirmwarePllFClkValue failed: %d\n", ret);
519 return;
520 }
521
522 /* FirmwarePllBClkValue */
523 val = cpu_to_le32(instance->modem_type->pll_b_clk);
524 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4);
525 if (ret) {
526 dev_err(dev, "FirmwarePllBClkValue failed: %d\n", ret);
527 return;
528 }
529
530 /* Enable SDRAM */
531 val = cpu_to_le32(SDRAM_ENA);
532 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4);
533 if (ret) {
534 dev_err(dev, "Enable SDRAM failed: %d\n", ret);
535 return;
536 }
537
538 /* Firmware */
539 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size);
540 if (ret) {
541 dev_err(dev, "Firmware upload failed: %d\n", ret);
542 return;
543 }
544
545 /* Boot ROM patch */
546 if (instance->modem_type->boot_rom_patch) {
547 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size);
548 if (ret) {
549 dev_err(dev, "Boot ROM patching failed: %d\n", ret);
550 return;
551 }
552 }
553
554 /* Signature */
555 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) signature, 4);
556 if (ret) {
557 dev_err(dev, "Signature storing failed: %d\n", ret);
558 return;
559 }
560
561 if (instance->modem_type->boot_rom_patch) {
562 val = cpu_to_le32(BR_ADDR);
563 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4);
564 }
565 else {
566 ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0);
567 }
568 if (ret) {
569 dev_err(dev, "Passing control to firmware failed: %d\n", ret);
570 return;
571 }
572
573 /* Delay to allow firmware to start up. */
574 msleep_interruptible(1000);
575
576 usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD));
577 usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_CMD));
578 usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_DATA));
579 usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_DATA));
580
581 ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
582 if (ret < 0) {
583 dev_err(dev, "modem failed to initialize: %d\n", ret);
584 return;
585 }
586
587 /* Load config data (le32), doing one packet at a time */
588 if (cf)
589 for (off = 0; off < cf->size / 4; ) {
590 u32 buf[CMD_PACKET_SIZE / 4 - 1];
591 int i, len = min_t(int, cf->size / 4 - off, CMD_PACKET_SIZE / 4 / 2 - 1);
592 buf[0] = cpu_to_le32(len);
593 for (i = 0; i < len; i++, off++) {
594 buf[i * 2 + 1] = cpu_to_le32(off);
595 memcpy(buf + i * 2 + 2, cf->data + off * 4, 4);
596 }
597 ret = cxacru_cm(instance, CM_REQUEST_CARD_DATA_SET,
598 (u8 *) buf, len, NULL, 0);
599 if (ret < 0) {
600 dev_err(dev, "load config data failed: %d\n", ret);
601 return;
602 }
603 }
604
605 msleep_interruptible(4000);
606}
607
608static int cxacru_find_firmware(struct cxacru_data *instance,
609 char* phase, const struct firmware **fw_p)
610{
611 struct device *dev = &instance->usbatm->usb_intf->dev;
612 char buf[16];
613
614 sprintf(buf, "cxacru-%s.bin", phase);
615 dbg("cxacru_find_firmware: looking for %s", buf);
616
617 if (request_firmware(fw_p, buf, dev)) {
618 dev_dbg(dev, "no stage %s firmware found\n", phase);
619 return -ENOENT;
620 }
621
622 dev_info(dev, "found firmware %s\n", buf);
623
624 return 0;
625}
626
627static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
628 struct usb_interface *usb_intf)
629{
630 struct device *dev = &usbatm_instance->usb_intf->dev;
631 const struct firmware *fw, *bp, *cf;
632 struct cxacru_data *instance = usbatm_instance->driver_data;
633
634 int ret = cxacru_find_firmware(instance, "fw", &fw);
635 if (ret) {
636 dev_warn(dev, "firmware (cxacru-fw.bin) unavailable (hotplug misconfiguration?)\n");
637 return ret;
638 }
639
640 if (instance->modem_type->boot_rom_patch) {
641 ret = cxacru_find_firmware(instance, "bp", &bp);
642 if (ret) {
643 dev_warn(dev, "boot ROM patch (cxacru-bp.bin) unavailable (hotplug misconfiguration?)\n");
644 release_firmware(fw);
645 return ret;
646 }
647 }
648
649 if (cxacru_find_firmware(instance, "cf", &cf)) /* optional */
650 cf = NULL;
651
652 cxacru_upload_firmware(instance, fw, bp, cf);
653
654 if (cf)
655 release_firmware(cf);
656 if (instance->modem_type->boot_rom_patch)
657 release_firmware(bp);
658 release_firmware(fw);
659
660 ret = cxacru_card_status(instance);
661 if (ret)
662 dbg("modem initialisation failed");
663 else
664 dbg("done setting up the modem");
665
666 return ret;
667}
668
669static int cxacru_bind(struct usbatm_data *usbatm_instance,
670 struct usb_interface *intf, const struct usb_device_id *id,
671 int *need_heavy_init)
672{
673 struct cxacru_data *instance;
674 struct usb_device *usb_dev = interface_to_usbdev(intf);
675 int ret;
676
677 /* instance init */
678 instance = kmalloc(sizeof(*instance), GFP_KERNEL);
679 if (!instance) {
680 dbg("cxacru_bind: no memory for instance data");
681 return -ENOMEM;
682 }
683
684 memset(instance, 0, sizeof(*instance));
685
686 instance->usbatm = usbatm_instance;
687 instance->modem_type = (struct cxacru_modem_type *) id->driver_info;
688
689 instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL);
690 if (!instance->rcv_buf) {
691 dbg("cxacru_bind: no memory for rcv_buf");
692 ret = -ENOMEM;
693 goto fail;
694 }
695 instance->snd_buf = (u8 *) __get_free_page(GFP_KERNEL);
696 if (!instance->snd_buf) {
697 dbg("cxacru_bind: no memory for snd_buf");
698 ret = -ENOMEM;
699 goto fail;
700 }
701 instance->rcv_urb = usb_alloc_urb(0, GFP_KERNEL);
702 if (!instance->rcv_urb) {
703 dbg("cxacru_bind: no memory for rcv_urb");
704 ret = -ENOMEM;
705 goto fail;
706 }
707 instance->snd_urb = usb_alloc_urb(0, GFP_KERNEL);
708 if (!instance->snd_urb) {
709 dbg("cxacru_bind: no memory for snd_urb");
710 ret = -ENOMEM;
711 goto fail;
712 }
713
714 usb_fill_int_urb(instance->rcv_urb,
715 usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD),
716 instance->rcv_buf, PAGE_SIZE,
717 cxacru_blocking_completion, &instance->rcv_done, 1);
718 instance->rcv_urb->transfer_flags |= URB_ASYNC_UNLINK;
719
720 usb_fill_int_urb(instance->snd_urb,
721 usb_dev, usb_sndintpipe(usb_dev, CXACRU_EP_CMD),
722 instance->snd_buf, PAGE_SIZE,
723 cxacru_blocking_completion, &instance->snd_done, 4);
724 instance->snd_urb->transfer_flags |= URB_ASYNC_UNLINK;
725
726 init_MUTEX(&instance->cm_serialize);
727
728 INIT_WORK(&instance->poll_work, (void *)cxacru_poll_status, instance);
729
730 usbatm_instance->driver_data = instance;
731
732 *need_heavy_init = cxacru_card_status(instance);
733
734 return 0;
735
736 fail:
737 free_page((unsigned long) instance->snd_buf);
738 free_page((unsigned long) instance->rcv_buf);
739 usb_free_urb(instance->snd_urb);
740 usb_free_urb(instance->rcv_urb);
741 kfree(instance);
742
743 return ret;
744}
745
746static void cxacru_unbind(struct usbatm_data *usbatm_instance,
747 struct usb_interface *intf)
748{
749 struct cxacru_data *instance = usbatm_instance->driver_data;
750
751 dbg("cxacru_unbind entered");
752
753 if (!instance) {
754 dbg("cxacru_unbind: NULL instance!");
755 return;
756 }
757
758 while (!cancel_delayed_work(&instance->poll_work))
759 flush_scheduled_work();
760
761 usb_kill_urb(instance->snd_urb);
762 usb_kill_urb(instance->rcv_urb);
763 usb_free_urb(instance->snd_urb);
764 usb_free_urb(instance->rcv_urb);
765
766 free_page((unsigned long) instance->snd_buf);
767 free_page((unsigned long) instance->rcv_buf);
768 kfree(instance);
769
770 usbatm_instance->driver_data = NULL;
771}
772
773static const struct cxacru_modem_type cxacru_cafe = {
774 .pll_f_clk = 0x02d874df,
775 .pll_b_clk = 0x0196a51a,
776 .boot_rom_patch = 1,
777};
778
779static const struct cxacru_modem_type cxacru_cb00 = {
780 .pll_f_clk = 0x5,
781 .pll_b_clk = 0x3,
782 .boot_rom_patch = 0,
783};
784
785static const struct usb_device_id cxacru_usb_ids[] = {
786 { /* V = Conexant P = ADSL modem (Euphrates project) */
787 USB_DEVICE(0x0572, 0xcafe), .driver_info = (unsigned long) &cxacru_cafe
788 },
789 { /* V = Conexant P = ADSL modem (Hasbani project) */
790 USB_DEVICE(0x0572, 0xcb00), .driver_info = (unsigned long) &cxacru_cb00
791 },
792 { /* V = Conexant P = ADSL modem */
793 USB_DEVICE(0x0572, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
794 },
795 { /* V = Conexant P = ADSL modem */
796 USB_DEVICE(0x0572, 0xcb06), .driver_info = (unsigned long) &cxacru_cb00
797 },
798 { /* V = Olitec P = ADSL modem version 2 */
799 USB_DEVICE(0x08e3, 0x0100), .driver_info = (unsigned long) &cxacru_cafe
800 },
801 { /* V = Olitec P = ADSL modem version 3 */
802 USB_DEVICE(0x08e3, 0x0102), .driver_info = (unsigned long) &cxacru_cb00
803 },
804 { /* V = Trust/Amigo Technology Co. P = AMX-CA86U */
805 USB_DEVICE(0x0eb0, 0x3457), .driver_info = (unsigned long) &cxacru_cafe
806 },
807 { /* V = Zoom P = 5510 */
808 USB_DEVICE(0x1803, 0x5510), .driver_info = (unsigned long) &cxacru_cb00
809 },
810 { /* V = Draytek P = Vigor 318 */
811 USB_DEVICE(0x0675, 0x0200), .driver_info = (unsigned long) &cxacru_cb00
812 },
813 { /* V = Zyxel P = 630-C1 aka OMNI ADSL USB (Annex A) */
814 USB_DEVICE(0x0586, 0x330a), .driver_info = (unsigned long) &cxacru_cb00
815 },
816 { /* V = Zyxel P = 630-C3 aka OMNI ADSL USB (Annex B) */
817 USB_DEVICE(0x0586, 0x330b), .driver_info = (unsigned long) &cxacru_cb00
818 },
819 { /* V = Aethra P = Starmodem UM1020 */
820 USB_DEVICE(0x0659, 0x0020), .driver_info = (unsigned long) &cxacru_cb00
821 },
822 { /* V = Aztech Systems P = ? AKA Pirelli AUA-010 */
823 USB_DEVICE(0x0509, 0x0812), .driver_info = (unsigned long) &cxacru_cb00
824 },
825 { /* V = Netopia P = Cayman 3341(Annex A)/3351(Annex B) */
826 USB_DEVICE(0x100d, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
827 },
828 { /* V = Netopia P = Cayman 3342(Annex A)/3352(Annex B) */
829 USB_DEVICE(0x100d, 0x3342), .driver_info = (unsigned long) &cxacru_cb00
830 },
831 {}
832};
833
834MODULE_DEVICE_TABLE(usb, cxacru_usb_ids);
835
836static struct usbatm_driver cxacru_driver = {
837 .owner = THIS_MODULE,
838 .driver_name = cxacru_driver_name,
839 .bind = cxacru_bind,
840 .heavy_init = cxacru_heavy_init,
841 .unbind = cxacru_unbind,
842 .atm_start = cxacru_atm_start,
843 .in = CXACRU_EP_DATA,
844 .out = CXACRU_EP_DATA,
845 .rx_padding = 3,
846 .tx_padding = 11,
847};
848
849static int cxacru_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
850{
851 return usbatm_usb_probe(intf, id, &cxacru_driver);
852}
853
854static struct usb_driver cxacru_usb_driver = {
855 .owner = THIS_MODULE,
856 .name = cxacru_driver_name,
857 .probe = cxacru_usb_probe,
858 .disconnect = usbatm_usb_disconnect,
859 .id_table = cxacru_usb_ids
860};
861
862static int __init cxacru_init(void)
863{
864 return usb_register(&cxacru_usb_driver);
865}
866
867static void __exit cxacru_cleanup(void)
868{
869 usb_deregister(&cxacru_usb_driver);
870}
871
872module_init(cxacru_init);
873module_exit(cxacru_cleanup);
874
875MODULE_AUTHOR(DRIVER_AUTHOR);
876MODULE_DESCRIPTION(DRIVER_DESC);
877MODULE_LICENSE("GPL");
878MODULE_VERSION(DRIVER_VERSION);
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c
index 2a1697bfd695..6a6eaa2a3b1c 100644
--- a/drivers/usb/atm/speedtch.c
+++ b/drivers/usb/atm/speedtch.c
@@ -5,6 +5,8 @@
5 * Copyright (C) 2003, Duncan Sands 5 * Copyright (C) 2003, Duncan Sands
6 * Copyright (C) 2004, David Woodhouse 6 * Copyright (C) 2004, David Woodhouse
7 * 7 *
8 * Based on "modem_run.c", copyright (C) 2001, Benoit Papillault
9 *
8 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free 11 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option) 12 * Software Foundation; either version 2 of the License, or (at your option)
@@ -21,821 +23,798 @@
21 * 23 *
22 ******************************************************************************/ 24 ******************************************************************************/
23 25
24#include <linux/module.h> 26#include <asm/page.h>
25#include <linux/moduleparam.h> 27#include <linux/device.h>
28#include <linux/errno.h>
29#include <linux/firmware.h>
26#include <linux/gfp.h> 30#include <linux/gfp.h>
31#include <linux/init.h>
27#include <linux/kernel.h> 32#include <linux/kernel.h>
28#include <linux/sched.h> 33#include <linux/module.h>
29#include <linux/timer.h> 34#include <linux/moduleparam.h>
30#include <linux/errno.h>
31#include <linux/proc_fs.h>
32#include <linux/slab.h> 35#include <linux/slab.h>
33#include <linux/wait.h> 36#include <linux/stat.h>
34#include <linux/list.h> 37#include <linux/timer.h>
35#include <asm/processor.h> 38#include <linux/workqueue.h>
36#include <asm/uaccess.h>
37#include <linux/smp_lock.h>
38#include <linux/interrupt.h>
39#include <linux/atm.h>
40#include <linux/atmdev.h>
41#include <linux/crc32.h>
42#include <linux/init.h>
43#include <linux/firmware.h>
44
45#include "usb_atm.h"
46 39
47#if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE) 40#include "usbatm.h"
48# define USE_FW_LOADER
49#endif
50 41
51#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" 42#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
52#define DRIVER_VERSION "1.8" 43#define DRIVER_VERSION "1.9"
53#define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION 44#define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION
54 45
55static const char speedtch_driver_name[] = "speedtch"; 46static const char speedtch_driver_name[] = "speedtch";
56 47
57#define SPEEDTOUCH_VENDORID 0x06b9 48#define CTRL_TIMEOUT 2000 /* milliseconds */
58#define SPEEDTOUCH_PRODUCTID 0x4061 49#define DATA_TIMEOUT 2000 /* milliseconds */
59 50
60/* Timeout in jiffies */ 51#define OFFSET_7 0 /* size 1 */
61#define CTRL_TIMEOUT 2000 52#define OFFSET_b 1 /* size 8 */
62#define DATA_TIMEOUT 2000 53#define OFFSET_d 9 /* size 4 */
54#define OFFSET_e 13 /* size 1 */
55#define OFFSET_f 14 /* size 1 */
56#define TOTAL 15
63 57
64#define OFFSET_7 0 /* size 1 */ 58#define SIZE_7 1
65#define OFFSET_b 1 /* size 8 */ 59#define SIZE_b 8
66#define OFFSET_d 9 /* size 4 */ 60#define SIZE_d 4
67#define OFFSET_e 13 /* size 1 */ 61#define SIZE_e 1
68#define OFFSET_f 14 /* size 1 */ 62#define SIZE_f 1
69#define TOTAL 15
70 63
71#define SIZE_7 1 64#define MIN_POLL_DELAY 5000 /* milliseconds */
72#define SIZE_b 8 65#define MAX_POLL_DELAY 60000 /* milliseconds */
73#define SIZE_d 4
74#define SIZE_e 1
75#define SIZE_f 1
76 66
77static int dl_512_first = 0; 67#define RESUBMIT_DELAY 1000 /* milliseconds */
78static int sw_buffering = 0;
79 68
80module_param(dl_512_first, bool, 0444); 69#define DEFAULT_ALTSETTING 1
81MODULE_PARM_DESC(dl_512_first, "Read 512 bytes before sending firmware"); 70#define DEFAULT_DL_512_FIRST 0
71#define DEFAULT_SW_BUFFERING 0
82 72
83module_param(sw_buffering, uint, 0444); 73static int altsetting = DEFAULT_ALTSETTING;
84MODULE_PARM_DESC(sw_buffering, "Enable software buffering"); 74static int dl_512_first = DEFAULT_DL_512_FIRST;
75static int sw_buffering = DEFAULT_SW_BUFFERING;
85 76
86#define UDSL_IOCTL_LINE_UP 1 77module_param(altsetting, int, S_IRUGO | S_IWUSR);
87#define UDSL_IOCTL_LINE_DOWN 2 78MODULE_PARM_DESC(altsetting,
79 "Alternative setting for data interface (default: "
80 __MODULE_STRING(DEFAULT_ALTSETTING) ")");
88 81
89#define SPEEDTCH_ENDPOINT_INT 0x81 82module_param(dl_512_first, bool, S_IRUGO | S_IWUSR);
90#define SPEEDTCH_ENDPOINT_DATA 0x07 83MODULE_PARM_DESC(dl_512_first,
91#define SPEEDTCH_ENDPOINT_FIRMWARE 0x05 84 "Read 512 bytes before sending firmware (default: "
85 __MODULE_STRING(DEFAULT_DL_512_FIRST) ")");
92 86
93#define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) ) 87module_param(sw_buffering, bool, S_IRUGO | S_IWUSR);
88MODULE_PARM_DESC(sw_buffering,
89 "Enable software buffering (default: "
90 __MODULE_STRING(DEFAULT_SW_BUFFERING) ")");
94 91
95static struct usb_device_id speedtch_usb_ids[] = { 92#define ENDPOINT_INT 0x81
96 {USB_DEVICE(SPEEDTOUCH_VENDORID, SPEEDTOUCH_PRODUCTID)}, 93#define ENDPOINT_DATA 0x07
97 {} 94#define ENDPOINT_FIRMWARE 0x05
98};
99 95
100MODULE_DEVICE_TABLE(usb, speedtch_usb_ids); 96#define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) )
101 97
102struct speedtch_instance_data { 98struct speedtch_instance_data {
103 struct udsl_instance_data u; 99 struct usbatm_data *usbatm;
100
101 struct work_struct status_checker;
104 102
105 /* Status */ 103 int poll_delay; /* milliseconds */
104
105 struct timer_list resubmit_timer;
106 struct urb *int_urb; 106 struct urb *int_urb;
107 unsigned char int_data[16]; 107 unsigned char int_data[16];
108 struct work_struct poll_work;
109 struct timer_list poll_timer;
110};
111/* USB */
112
113static int speedtch_usb_probe(struct usb_interface *intf,
114 const struct usb_device_id *id);
115static void speedtch_usb_disconnect(struct usb_interface *intf);
116static int speedtch_usb_ioctl(struct usb_interface *intf, unsigned int code,
117 void *user_data);
118static void speedtch_handle_int(struct urb *urb, struct pt_regs *regs);
119static void speedtch_poll_status(struct speedtch_instance_data *instance);
120 108
121static struct usb_driver speedtch_usb_driver = { 109 unsigned char scratch_buffer[TOTAL];
122 .owner = THIS_MODULE,
123 .name = speedtch_driver_name,
124 .probe = speedtch_usb_probe,
125 .disconnect = speedtch_usb_disconnect,
126 .ioctl = speedtch_usb_ioctl,
127 .id_table = speedtch_usb_ids,
128}; 110};
129 111
130/*************** 112/***************
131** firmware ** 113** firmware **
132***************/ 114***************/
133 115
134static void speedtch_got_firmware(struct speedtch_instance_data *instance, 116static void speedtch_set_swbuff(struct speedtch_instance_data *instance, int state)
135 int got_it)
136{ 117{
137 int err; 118 struct usbatm_data *usbatm = instance->usbatm;
138 struct usb_interface *intf; 119 struct usb_device *usb_dev = usbatm->usb_dev;
139
140 down(&instance->u.serialize); /* vs self, speedtch_firmware_start */
141 if (instance->u.status == UDSL_LOADED_FIRMWARE)
142 goto out;
143 if (!got_it) {
144 instance->u.status = UDSL_NO_FIRMWARE;
145 goto out;
146 }
147 if ((err = usb_set_interface(instance->u.usb_dev, 1, 1)) < 0) {
148 dbg("speedtch_got_firmware: usb_set_interface returned %d!", err);
149 instance->u.status = UDSL_NO_FIRMWARE;
150 goto out;
151 }
152
153 /* Set up interrupt endpoint */
154 intf = usb_ifnum_to_if(instance->u.usb_dev, 0);
155 if (intf && !usb_driver_claim_interface(&speedtch_usb_driver, intf, NULL)) {
156
157 instance->int_urb = usb_alloc_urb(0, GFP_KERNEL);
158 if (instance->int_urb) {
159
160 usb_fill_int_urb(instance->int_urb, instance->u.usb_dev,
161 usb_rcvintpipe(instance->u.usb_dev, SPEEDTCH_ENDPOINT_INT),
162 instance->int_data,
163 sizeof(instance->int_data),
164 speedtch_handle_int, instance, 50);
165 err = usb_submit_urb(instance->int_urb, GFP_KERNEL);
166 if (err) {
167 /* Doesn't matter; we'll poll anyway */
168 dbg("speedtch_got_firmware: Submission of interrupt URB failed %d", err);
169 usb_free_urb(instance->int_urb);
170 instance->int_urb = NULL;
171 usb_driver_release_interface(&speedtch_usb_driver, intf);
172 }
173 }
174 }
175 /* Start status polling */
176 mod_timer(&instance->poll_timer, jiffies + (1 * HZ));
177
178 instance->u.status = UDSL_LOADED_FIRMWARE;
179 tasklet_schedule(&instance->u.receive_tasklet);
180 out:
181 up(&instance->u.serialize);
182 wake_up_interruptible(&instance->u.firmware_waiters);
183}
184
185static int speedtch_set_swbuff(struct speedtch_instance_data *instance,
186 int state)
187{
188 struct usb_device *dev = instance->u.usb_dev;
189 int ret; 120 int ret;
190 121
191 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 122 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
192 0x32, 0x40, state ? 0x01 : 0x00, 123 0x32, 0x40, state ? 0x01 : 0x00, 0x00, NULL, 0, CTRL_TIMEOUT);
193 0x00, NULL, 0, 100); 124 if (ret < 0)
194 if (ret < 0) { 125 usb_warn(usbatm,
195 printk("Warning: %sabling SW buffering: usb_control_msg returned %d\n", 126 "%sabling SW buffering: usb_control_msg returned %d\n",
196 state ? "En" : "Dis", ret); 127 state ? "En" : "Dis", ret);
197 return ret; 128 else
198 } 129 dbg("speedtch_set_swbuff: %sbled SW buffering", state ? "En" : "Dis");
199
200 dbg("speedtch_set_swbuff: %sbled SW buffering", state ? "En" : "Dis");
201 return 0;
202} 130}
203 131
204static void speedtch_test_sequence(struct speedtch_instance_data *instance) 132static void speedtch_test_sequence(struct speedtch_instance_data *instance)
205{ 133{
206 struct usb_device *dev = instance->u.usb_dev; 134 struct usbatm_data *usbatm = instance->usbatm;
207 unsigned char buf[10]; 135 struct usb_device *usb_dev = usbatm->usb_dev;
136 unsigned char *buf = instance->scratch_buffer;
208 int ret; 137 int ret;
209 138
210 /* URB 147 */ 139 /* URB 147 */
211 buf[0] = 0x1c; 140 buf[0] = 0x1c;
212 buf[1] = 0x50; 141 buf[1] = 0x50;
213 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 142 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
214 0x01, 0x40, 0x0b, 0x00, buf, 2, 100); 143 0x01, 0x40, 0x0b, 0x00, buf, 2, CTRL_TIMEOUT);
215 if (ret < 0) 144 if (ret < 0)
216 printk(KERN_WARNING "%s failed on URB147: %d\n", __func__, ret); 145 usb_warn(usbatm, "%s failed on URB147: %d\n", __func__, ret);
217 146
218 /* URB 148 */ 147 /* URB 148 */
219 buf[0] = 0x32; 148 buf[0] = 0x32;
220 buf[1] = 0x00; 149 buf[1] = 0x00;
221 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 150 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
222 0x01, 0x40, 0x02, 0x00, buf, 2, 100); 151 0x01, 0x40, 0x02, 0x00, buf, 2, CTRL_TIMEOUT);
223 if (ret < 0) 152 if (ret < 0)
224 printk(KERN_WARNING "%s failed on URB148: %d\n", __func__, ret); 153 usb_warn(usbatm, "%s failed on URB148: %d\n", __func__, ret);
225 154
226 /* URB 149 */ 155 /* URB 149 */
227 buf[0] = 0x01; 156 buf[0] = 0x01;
228 buf[1] = 0x00; 157 buf[1] = 0x00;
229 buf[2] = 0x01; 158 buf[2] = 0x01;
230 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 159 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
231 0x01, 0x40, 0x03, 0x00, buf, 3, 100); 160 0x01, 0x40, 0x03, 0x00, buf, 3, CTRL_TIMEOUT);
232 if (ret < 0) 161 if (ret < 0)
233 printk(KERN_WARNING "%s failed on URB149: %d\n", __func__, ret); 162 usb_warn(usbatm, "%s failed on URB149: %d\n", __func__, ret);
234 163
235 /* URB 150 */ 164 /* URB 150 */
236 buf[0] = 0x01; 165 buf[0] = 0x01;
237 buf[1] = 0x00; 166 buf[1] = 0x00;
238 buf[2] = 0x01; 167 buf[2] = 0x01;
239 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 168 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
240 0x01, 0x40, 0x04, 0x00, buf, 3, 100); 169 0x01, 0x40, 0x04, 0x00, buf, 3, CTRL_TIMEOUT);
241 if (ret < 0) 170 if (ret < 0)
242 printk(KERN_WARNING "%s failed on URB150: %d\n", __func__, ret); 171 usb_warn(usbatm, "%s failed on URB150: %d\n", __func__, ret);
243} 172}
244 173
245static int speedtch_start_synchro(struct speedtch_instance_data *instance) 174static int speedtch_upload_firmware(struct speedtch_instance_data *instance,
175 const struct firmware *fw1,
176 const struct firmware *fw2)
246{ 177{
247 struct usb_device *dev = instance->u.usb_dev; 178 unsigned char *buffer;
248 unsigned char buf[2]; 179 struct usbatm_data *usbatm = instance->usbatm;
249 int ret; 180 struct usb_interface *intf;
181 struct usb_device *usb_dev = usbatm->usb_dev;
182 int actual_length;
183 int ret = 0;
184 int offset;
185
186 usb_dbg(usbatm, "%s entered\n", __func__);
187
188 if (!(buffer = (unsigned char *)__get_free_page(GFP_KERNEL))) {
189 ret = -ENOMEM;
190 usb_dbg(usbatm, "%s: no memory for buffer!\n", __func__);
191 goto out;
192 }
193
194 if (!(intf = usb_ifnum_to_if(usb_dev, 2))) {
195 ret = -ENODEV;
196 usb_dbg(usbatm, "%s: interface not found!\n", __func__);
197 goto out_free;
198 }
199
200 /* URB 7 */
201 if (dl_512_first) { /* some modems need a read before writing the firmware */
202 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
203 buffer, 0x200, &actual_length, 2000);
204
205 if (ret < 0 && ret != -ETIMEDOUT)
206 usb_dbg(usbatm, "%s: read BLOCK0 from modem failed (%d)!\n", __func__, ret);
207 else
208 usb_dbg(usbatm, "%s: BLOCK0 downloaded (%d bytes)\n", __func__, ret);
209 }
210
211 /* URB 8 : both leds are static green */
212 for (offset = 0; offset < fw1->size; offset += PAGE_SIZE) {
213 int thislen = min_t(int, PAGE_SIZE, fw1->size - offset);
214 memcpy(buffer, fw1->data + offset, thislen);
215
216 ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
217 buffer, thislen, &actual_length, DATA_TIMEOUT);
218
219 if (ret < 0) {
220 usb_dbg(usbatm, "%s: write BLOCK1 to modem failed (%d)!\n", __func__, ret);
221 goto out_free;
222 }
223 usb_dbg(usbatm, "%s: BLOCK1 uploaded (%zu bytes)\n", __func__, fw1->size);
224 }
225
226 /* USB led blinking green, ADSL led off */
227
228 /* URB 11 */
229 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
230 buffer, 0x200, &actual_length, DATA_TIMEOUT);
250 231
251 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
252 0x12, 0xc0, 0x04, 0x00,
253 buf, sizeof(buf), CTRL_TIMEOUT);
254 if (ret < 0) { 232 if (ret < 0) {
255 printk(KERN_WARNING "SpeedTouch: Failed to start ADSL synchronisation: %d\n", ret); 233 usb_dbg(usbatm, "%s: read BLOCK2 from modem failed (%d)!\n", __func__, ret);
256 return ret; 234 goto out_free;
257 } 235 }
236 usb_dbg(usbatm, "%s: BLOCK2 downloaded (%d bytes)\n", __func__, actual_length);
258 237
259 dbg("speedtch_start_synchro: modem prodded. %d Bytes returned: %02x %02x", ret, buf[0], buf[1]); 238 /* URBs 12 to 139 - USB led blinking green, ADSL led off */
260 return 0; 239 for (offset = 0; offset < fw2->size; offset += PAGE_SIZE) {
240 int thislen = min_t(int, PAGE_SIZE, fw2->size - offset);
241 memcpy(buffer, fw2->data + offset, thislen);
242
243 ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
244 buffer, thislen, &actual_length, DATA_TIMEOUT);
245
246 if (ret < 0) {
247 usb_dbg(usbatm, "%s: write BLOCK3 to modem failed (%d)!\n", __func__, ret);
248 goto out_free;
249 }
250 }
251 usb_dbg(usbatm, "%s: BLOCK3 uploaded (%zu bytes)\n", __func__, fw2->size);
252
253 /* USB led static green, ADSL led static red */
254
255 /* URB 142 */
256 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
257 buffer, 0x200, &actual_length, DATA_TIMEOUT);
258
259 if (ret < 0) {
260 usb_dbg(usbatm, "%s: read BLOCK4 from modem failed (%d)!\n", __func__, ret);
261 goto out_free;
262 }
263
264 /* success */
265 usb_dbg(usbatm, "%s: BLOCK4 downloaded (%d bytes)\n", __func__, actual_length);
266
267 /* Delay to allow firmware to start up. We can do this here
268 because we're in our own kernel thread anyway. */
269 msleep_interruptible(1000);
270
271 /* Enable software buffering, if requested */
272 if (sw_buffering)
273 speedtch_set_swbuff(instance, 1);
274
275 /* Magic spell; don't ask us what this does */
276 speedtch_test_sequence(instance);
277
278 ret = 0;
279
280out_free:
281 free_page((unsigned long)buffer);
282out:
283 return ret;
261} 284}
262 285
263static void speedtch_handle_int(struct urb *urb, struct pt_regs *regs) 286static int speedtch_find_firmware(struct usb_interface *intf, int phase,
287 const struct firmware **fw_p)
264{ 288{
265 struct speedtch_instance_data *instance = urb->context; 289 struct device *dev = &intf->dev;
266 unsigned int count = urb->actual_length; 290 const u16 bcdDevice = le16_to_cpu(interface_to_usbdev(intf)->descriptor.bcdDevice);
267 int ret; 291 const u8 major_revision = bcdDevice >> 8;
292 const u8 minor_revision = bcdDevice & 0xff;
293 char buf[24];
268 294
269 /* The magic interrupt for "up state" */ 295 sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision);
270 const static unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 }; 296 dev_dbg(dev, "%s: looking for %s\n", __func__, buf);
271 /* The magic interrupt for "down state" */
272 const static unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 };
273 297
274 switch (urb->status) { 298 if (request_firmware(fw_p, buf, dev)) {
275 case 0: 299 sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision);
276 /* success */ 300 dev_dbg(dev, "%s: looking for %s\n", __func__, buf);
277 break;
278 case -ECONNRESET:
279 case -ENOENT:
280 case -ESHUTDOWN:
281 /* this urb is terminated; clean up */
282 dbg("%s - urb shutting down with status: %d", __func__, urb->status);
283 return;
284 default:
285 dbg("%s - nonzero urb status received: %d", __func__, urb->status);
286 goto exit;
287 }
288 301
289 if (count < 6) { 302 if (request_firmware(fw_p, buf, dev)) {
290 dbg("%s - int packet too short", __func__); 303 sprintf(buf, "speedtch-%d.bin", phase);
291 goto exit; 304 dev_dbg(dev, "%s: looking for %s\n", __func__, buf);
305
306 if (request_firmware(fw_p, buf, dev)) {
307 dev_warn(dev, "no stage %d firmware found!\n", phase);
308 return -ENOENT;
309 }
310 }
292 } 311 }
293 312
294 if (!memcmp(up_int, instance->int_data, 6)) { 313 dev_info(dev, "found stage %d firmware %s\n", phase, buf);
295 del_timer(&instance->poll_timer);
296 printk(KERN_NOTICE "DSL line goes up\n");
297 } else if (!memcmp(down_int, instance->int_data, 6)) {
298 printk(KERN_NOTICE "DSL line goes down\n");
299 } else {
300 int i;
301 314
302 printk(KERN_DEBUG "Unknown interrupt packet of %d bytes:", count); 315 return 0;
303 for (i = 0; i < count; i++) 316}
304 printk(" %02x", instance->int_data[i]); 317
305 printk("\n"); 318static int speedtch_heavy_init(struct usbatm_data *usbatm, struct usb_interface *intf)
319{
320 const struct firmware *fw1, *fw2;
321 struct speedtch_instance_data *instance = usbatm->driver_data;
322 int ret;
323
324 if ((ret = speedtch_find_firmware(intf, 1, &fw1)) < 0)
325 return ret;
326
327 if ((ret = speedtch_find_firmware(intf, 2, &fw2)) < 0) {
328 release_firmware(fw1);
329 return ret;
306 } 330 }
307 schedule_work(&instance->poll_work);
308 331
309 exit: 332 ret = speedtch_upload_firmware(instance, fw1, fw2);
310 rmb(); 333
311 if (!instance->int_urb) 334 release_firmware(fw2);
312 return; 335 release_firmware(fw1);
313 336
314 ret = usb_submit_urb(urb, GFP_ATOMIC); 337 return ret;
315 if (ret)
316 err("%s - usb_submit_urb failed with result %d", __func__, ret);
317} 338}
318 339
319static int speedtch_get_status(struct speedtch_instance_data *instance, 340
320 unsigned char *buf) 341/**********
342** ATM **
343**********/
344
345static int speedtch_read_status(struct speedtch_instance_data *instance)
321{ 346{
322 struct usb_device *dev = instance->u.usb_dev; 347 struct usbatm_data *usbatm = instance->usbatm;
348 struct usb_device *usb_dev = usbatm->usb_dev;
349 unsigned char *buf = instance->scratch_buffer;
323 int ret; 350 int ret;
324 351
325 memset(buf, 0, TOTAL); 352 memset(buf, 0, TOTAL);
326 353
327 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 354 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
328 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7, 355 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7,
329 CTRL_TIMEOUT); 356 CTRL_TIMEOUT);
330 if (ret < 0) { 357 if (ret < 0) {
331 dbg("MSG 7 failed"); 358 atm_dbg(usbatm, "%s: MSG 7 failed\n", __func__);
332 return ret; 359 return ret;
333 } 360 }
334 361
335 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 362 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
336 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b, 363 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b,
337 CTRL_TIMEOUT); 364 CTRL_TIMEOUT);
338 if (ret < 0) { 365 if (ret < 0) {
339 dbg("MSG B failed"); 366 atm_dbg(usbatm, "%s: MSG B failed\n", __func__);
340 return ret; 367 return ret;
341 } 368 }
342 369
343 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 370 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
344 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d, 371 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d,
345 CTRL_TIMEOUT); 372 CTRL_TIMEOUT);
346 if (ret < 0) { 373 if (ret < 0) {
347 dbg("MSG D failed"); 374 atm_dbg(usbatm, "%s: MSG D failed\n", __func__);
348 return ret; 375 return ret;
349 } 376 }
350 377
351 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 378 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
352 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e, 379 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e,
353 CTRL_TIMEOUT); 380 CTRL_TIMEOUT);
354 if (ret < 0) { 381 if (ret < 0) {
355 dbg("MSG E failed"); 382 atm_dbg(usbatm, "%s: MSG E failed\n", __func__);
356 return ret; 383 return ret;
357 } 384 }
358 385
359 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 386 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
360 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f, 387 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f,
361 CTRL_TIMEOUT); 388 CTRL_TIMEOUT);
362 if (ret < 0) { 389 if (ret < 0) {
363 dbg("MSG F failed"); 390 atm_dbg(usbatm, "%s: MSG F failed\n", __func__);
364 return ret; 391 return ret;
365 } 392 }
366 393
367 return 0; 394 return 0;
368} 395}
369 396
370static void speedtch_poll_status(struct speedtch_instance_data *instance) 397static int speedtch_start_synchro(struct speedtch_instance_data *instance)
371{ 398{
372 unsigned char buf[TOTAL]; 399 struct usbatm_data *usbatm = instance->usbatm;
400 struct usb_device *usb_dev = usbatm->usb_dev;
401 unsigned char *buf = instance->scratch_buffer;
373 int ret; 402 int ret;
374 403
375 ret = speedtch_get_status(instance, buf); 404 atm_dbg(usbatm, "%s entered\n", __func__);
376 if (ret) { 405
377 printk(KERN_WARNING 406 memset(buf, 0, 2);
378 "SpeedTouch: Error %d fetching device status\n", ret); 407
408 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
409 0x12, 0xc0, 0x04, 0x00,
410 buf, 2, CTRL_TIMEOUT);
411
412 if (ret < 0)
413 atm_warn(usbatm, "failed to start ADSL synchronisation: %d\n", ret);
414 else
415 atm_dbg(usbatm, "%s: modem prodded. %d bytes returned: %02x %02x\n",
416 __func__, ret, buf[0], buf[1]);
417
418 return ret;
419}
420
421static void speedtch_check_status(struct speedtch_instance_data *instance)
422{
423 struct usbatm_data *usbatm = instance->usbatm;
424 struct atm_dev *atm_dev = usbatm->atm_dev;
425 unsigned char *buf = instance->scratch_buffer;
426 int ret;
427
428 atm_dbg(usbatm, "%s entered\n", __func__);
429
430 ret = speedtch_read_status(instance);
431 if (ret < 0) {
432 atm_warn(usbatm, "error %d fetching device status\n", ret);
433 if (instance->poll_delay < MAX_POLL_DELAY)
434 instance->poll_delay *= 2;
379 return; 435 return;
380 } 436 }
381 437
382 dbg("Line state %02x", buf[OFFSET_7]); 438 if (instance->poll_delay > MIN_POLL_DELAY)
439 instance->poll_delay /= 2;
440
441 atm_dbg(usbatm, "%s: line state %02x\n", __func__, buf[OFFSET_7]);
383 442
384 switch (buf[OFFSET_7]) { 443 switch (buf[OFFSET_7]) {
385 case 0: 444 case 0:
386 if (instance->u.atm_dev->signal != ATM_PHY_SIG_LOST) { 445 if (atm_dev->signal != ATM_PHY_SIG_LOST) {
387 instance->u.atm_dev->signal = ATM_PHY_SIG_LOST; 446 atm_dev->signal = ATM_PHY_SIG_LOST;
388 printk(KERN_NOTICE "ADSL line is down\n"); 447 atm_info(usbatm, "ADSL line is down\n");
389 /* It'll never resync again unless we ask it to... */ 448 /* It'll never resync again unless we ask it to... */
390 speedtch_start_synchro(instance); 449 ret = speedtch_start_synchro(instance);
391 } 450 }
392 break; 451 break;
393 452
394 case 0x08: 453 case 0x08:
395 if (instance->u.atm_dev->signal != ATM_PHY_SIG_UNKNOWN) { 454 if (atm_dev->signal != ATM_PHY_SIG_UNKNOWN) {
396 instance->u.atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 455 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
397 printk(KERN_NOTICE "ADSL line is blocked?\n"); 456 atm_info(usbatm, "ADSL line is blocked?\n");
398 } 457 }
399 break; 458 break;
400 459
401 case 0x10: 460 case 0x10:
402 if (instance->u.atm_dev->signal != ATM_PHY_SIG_LOST) { 461 if (atm_dev->signal != ATM_PHY_SIG_LOST) {
403 instance->u.atm_dev->signal = ATM_PHY_SIG_LOST; 462 atm_dev->signal = ATM_PHY_SIG_LOST;
404 printk(KERN_NOTICE "ADSL line is synchronising\n"); 463 atm_info(usbatm, "ADSL line is synchronising\n");
405 } 464 }
406 break; 465 break;
407 466
408 case 0x20: 467 case 0x20:
409 if (instance->u.atm_dev->signal != ATM_PHY_SIG_FOUND) { 468 if (atm_dev->signal != ATM_PHY_SIG_FOUND) {
410 int down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8) 469 int down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8)
411 | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24); 470 | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24);
412 int up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8) 471 int up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8)
413 | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24); 472 | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24);
414 473
415 if (!(down_speed & 0x0000ffff) && 474 if (!(down_speed & 0x0000ffff) && !(up_speed & 0x0000ffff)) {
416 !(up_speed & 0x0000ffff)) {
417 down_speed >>= 16; 475 down_speed >>= 16;
418 up_speed >>= 16; 476 up_speed >>= 16;
419 } 477 }
420 instance->u.atm_dev->link_rate = down_speed * 1000 / 424;
421 instance->u.atm_dev->signal = ATM_PHY_SIG_FOUND;
422 478
423 printk(KERN_NOTICE 479 atm_dev->link_rate = down_speed * 1000 / 424;
424 "ADSL line is up (%d Kib/s down | %d Kib/s up)\n", 480 atm_dev->signal = ATM_PHY_SIG_FOUND;
425 down_speed, up_speed); 481
482 atm_info(usbatm,
483 "ADSL line is up (%d Kib/s down | %d Kib/s up)\n",
484 down_speed, up_speed);
426 } 485 }
427 break; 486 break;
428 487
429 default: 488 default:
430 if (instance->u.atm_dev->signal != ATM_PHY_SIG_UNKNOWN) { 489 if (atm_dev->signal != ATM_PHY_SIG_UNKNOWN) {
431 instance->u.atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 490 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
432 printk(KERN_NOTICE "Unknown line state %02x\n", buf[OFFSET_7]); 491 atm_info(usbatm, "Unknown line state %02x\n", buf[OFFSET_7]);
433 } 492 }
434 break; 493 break;
435 } 494 }
436} 495}
437 496
438static void speedtch_timer_poll(unsigned long data) 497static void speedtch_status_poll(unsigned long data)
439{ 498{
440 struct speedtch_instance_data *instance = (void *)data; 499 struct speedtch_instance_data *instance = (void *)data;
441 500
442 schedule_work(&instance->poll_work); 501 schedule_work(&instance->status_checker);
443 mod_timer(&instance->poll_timer, jiffies + (5 * HZ)); 502
503 /* The following check is racy, but the race is harmless */
504 if (instance->poll_delay < MAX_POLL_DELAY)
505 mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(instance->poll_delay));
506 else
507 atm_warn(instance->usbatm, "Too many failures - disabling line status polling\n");
444} 508}
445 509
446#ifdef USE_FW_LOADER 510static void speedtch_resubmit_int(unsigned long data)
447static void speedtch_upload_firmware(struct speedtch_instance_data *instance,
448 const struct firmware *fw1,
449 const struct firmware *fw2)
450{ 511{
451 unsigned char *buffer; 512 struct speedtch_instance_data *instance = (void *)data;
452 struct usb_device *usb_dev = instance->u.usb_dev; 513 struct urb *int_urb = instance->int_urb;
453 struct usb_interface *intf; 514 int ret;
454 int actual_length, ret;
455 int offset;
456
457 dbg("speedtch_upload_firmware");
458
459 if (!(intf = usb_ifnum_to_if(usb_dev, 2))) {
460 dbg("speedtch_upload_firmware: interface not found!");
461 goto fail;
462 }
463
464 if (!(buffer = (unsigned char *)__get_free_page(GFP_KERNEL))) {
465 dbg("speedtch_upload_firmware: no memory for buffer!");
466 goto fail;
467 }
468
469 /* A user-space firmware loader may already have claimed interface #2 */
470 if ((ret =
471 usb_driver_claim_interface(&speedtch_usb_driver, intf, NULL)) < 0) {
472 dbg("speedtch_upload_firmware: interface in use (%d)!", ret);
473 goto fail_free;
474 }
475
476 /* URB 7 */
477 if (dl_512_first) { /* some modems need a read before writing the firmware */
478 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE),
479 buffer, 0x200, &actual_length, 2000);
480
481 if (ret < 0 && ret != -ETIMEDOUT)
482 dbg("speedtch_upload_firmware: read BLOCK0 from modem failed (%d)!", ret);
483 else
484 dbg("speedtch_upload_firmware: BLOCK0 downloaded (%d bytes)", ret);
485 }
486
487 /* URB 8 : both leds are static green */
488 for (offset = 0; offset < fw1->size; offset += PAGE_SIZE) {
489 int thislen = min_t(int, PAGE_SIZE, fw1->size - offset);
490 memcpy(buffer, fw1->data + offset, thislen);
491 515
492 ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), 516 atm_dbg(instance->usbatm, "%s entered\n", __func__);
493 buffer, thislen, &actual_length, DATA_TIMEOUT);
494 517
495 if (ret < 0) { 518 if (int_urb) {
496 dbg("speedtch_upload_firmware: write BLOCK1 to modem failed (%d)!", ret); 519 ret = usb_submit_urb(int_urb, GFP_ATOMIC);
497 goto fail_release; 520 if (!ret)
521 schedule_work(&instance->status_checker);
522 else {
523 atm_dbg(instance->usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret);
524 mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY));
498 } 525 }
499 dbg("speedtch_upload_firmware: BLOCK1 uploaded (%zu bytes)", fw1->size);
500 } 526 }
527}
501 528
502 /* USB led blinking green, ADSL led off */ 529static void speedtch_handle_int(struct urb *int_urb, struct pt_regs *regs)
530{
531 struct speedtch_instance_data *instance = int_urb->context;
532 struct usbatm_data *usbatm = instance->usbatm;
533 unsigned int count = int_urb->actual_length;
534 int ret = int_urb->status;
503 535
504 /* URB 11 */ 536 /* The magic interrupt for "up state" */
505 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), 537 const static unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 };
506 buffer, 0x200, &actual_length, DATA_TIMEOUT); 538 /* The magic interrupt for "down state" */
539 const static unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 };
540
541 atm_dbg(usbatm, "%s entered\n", __func__);
507 542
508 if (ret < 0) { 543 if (ret < 0) {
509 dbg("speedtch_upload_firmware: read BLOCK2 from modem failed (%d)!", ret); 544 atm_dbg(usbatm, "%s: nonzero urb status %d!\n", __func__, ret);
510 goto fail_release; 545 goto fail;
511 } 546 }
512 dbg("speedtch_upload_firmware: BLOCK2 downloaded (%d bytes)", actual_length);
513 547
514 /* URBs 12 to 139 - USB led blinking green, ADSL led off */ 548 if ((count == 6) && !memcmp(up_int, instance->int_data, 6)) {
515 for (offset = 0; offset < fw2->size; offset += PAGE_SIZE) { 549 del_timer(&instance->status_checker.timer);
516 int thislen = min_t(int, PAGE_SIZE, fw2->size - offset); 550 atm_info(usbatm, "DSL line goes up\n");
517 memcpy(buffer, fw2->data + offset, thislen); 551 } else if ((count == 6) && !memcmp(down_int, instance->int_data, 6)) {
552 atm_info(usbatm, "DSL line goes down\n");
553 } else {
554 int i;
518 555
519 ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), 556 atm_dbg(usbatm, "%s: unknown interrupt packet of length %d:", __func__, count);
520 buffer, thislen, &actual_length, DATA_TIMEOUT); 557 for (i = 0; i < count; i++)
558 printk(" %02x", instance->int_data[i]);
559 printk("\n");
560 goto fail;
561 }
521 562
563 if ((int_urb = instance->int_urb)) {
564 ret = usb_submit_urb(int_urb, GFP_ATOMIC);
565 schedule_work(&instance->status_checker);
522 if (ret < 0) { 566 if (ret < 0) {
523 dbg("speedtch_upload_firmware: write BLOCK3 to modem failed (%d)!", ret); 567 atm_dbg(usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret);
524 goto fail_release; 568 goto fail;
525 } 569 }
526 } 570 }
527 dbg("speedtch_upload_firmware: BLOCK3 uploaded (%zu bytes)", fw2->size);
528
529 /* USB led static green, ADSL led static red */
530
531 /* URB 142 */
532 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE),
533 buffer, 0x200, &actual_length, DATA_TIMEOUT);
534
535 if (ret < 0) {
536 dbg("speedtch_upload_firmware: read BLOCK4 from modem failed (%d)!", ret);
537 goto fail_release;
538 }
539
540 /* success */
541 dbg("speedtch_upload_firmware: BLOCK4 downloaded (%d bytes)", actual_length);
542
543 /* Delay to allow firmware to start up. We can do this here
544 because we're in our own kernel thread anyway. */
545 msleep(1000);
546
547 /* Enable software buffering, if requested */
548 if (sw_buffering)
549 speedtch_set_swbuff(instance, 1);
550
551 /* Magic spell; don't ask us what this does */
552 speedtch_test_sequence(instance);
553
554 /* Start modem synchronisation */
555 if (speedtch_start_synchro(instance))
556 dbg("speedtch_start_synchro: failed");
557
558 speedtch_got_firmware(instance, 1);
559 571
560 free_page((unsigned long)buffer);
561 return; 572 return;
562 573
563 fail_release: 574fail:
564 /* Only release interface #2 if uploading failed; we don't release it 575 if ((int_urb = instance->int_urb))
565 we succeeded. This prevents the userspace tools from trying to load 576 mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY));
566 the firmware themselves */
567 usb_driver_release_interface(&speedtch_usb_driver, intf);
568 fail_free:
569 free_page((unsigned long)buffer);
570 fail:
571 speedtch_got_firmware(instance, 0);
572} 577}
573 578
574static int speedtch_find_firmware(struct speedtch_instance_data 579static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
575 *instance, int phase,
576 const struct firmware **fw_p)
577{ 580{
578 char buf[24]; 581 struct usb_device *usb_dev = usbatm->usb_dev;
579 const u16 bcdDevice = le16_to_cpu(instance->u.usb_dev->descriptor.bcdDevice); 582 struct speedtch_instance_data *instance = usbatm->driver_data;
580 const u8 major_revision = bcdDevice >> 8; 583 int i, ret;
581 const u8 minor_revision = bcdDevice & 0xff; 584 unsigned char mac_str[13];
582
583 sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision);
584 dbg("speedtch_find_firmware: looking for %s", buf);
585
586 if (request_firmware(fw_p, buf, &instance->u.usb_dev->dev)) {
587 sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision);
588 dbg("speedtch_find_firmware: looking for %s", buf);
589 585
590 if (request_firmware(fw_p, buf, &instance->u.usb_dev->dev)) { 586 atm_dbg(usbatm, "%s entered\n", __func__);
591 sprintf(buf, "speedtch-%d.bin", phase);
592 dbg("speedtch_find_firmware: looking for %s", buf);
593 587
594 if (request_firmware(fw_p, buf, &instance->u.usb_dev->dev)) { 588 if ((ret = usb_set_interface(usb_dev, 1, altsetting)) < 0) {
595 dev_warn(&instance->u.usb_dev->dev, "no stage %d firmware found!", phase); 589 atm_dbg(usbatm, "%s: usb_set_interface returned %d!\n", __func__, ret);
596 return -ENOENT; 590 return ret;
597 }
598 }
599 } 591 }
600 592
601 dev_info(&instance->u.usb_dev->dev, "found stage %d firmware %s\n", phase, buf); 593 /* Set MAC address, it is stored in the serial number */
602 594 memset(atm_dev->esi, 0, sizeof(atm_dev->esi));
603 return 0; 595 if (usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) {
604} 596 for (i = 0; i < 6; i++)
605 597 atm_dev->esi[i] = (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1]));
606static int speedtch_load_firmware(void *arg) 598 }
607{
608 const struct firmware *fw1, *fw2;
609 struct speedtch_instance_data *instance = arg;
610
611 BUG_ON(!instance);
612 599
613 daemonize("firmware/speedtch"); 600 /* Start modem synchronisation */
601 ret = speedtch_start_synchro(instance);
614 602
615 if (!speedtch_find_firmware(instance, 1, &fw1)) { 603 /* Set up interrupt endpoint */
616 if (!speedtch_find_firmware(instance, 2, &fw2)) { 604 if (instance->int_urb) {
617 speedtch_upload_firmware(instance, fw1, fw2); 605 ret = usb_submit_urb(instance->int_urb, GFP_KERNEL);
618 release_firmware(fw2); 606 if (ret < 0) {
607 /* Doesn't matter; we'll poll anyway */
608 atm_dbg(usbatm, "%s: submission of interrupt URB failed (%d)!\n", __func__, ret);
609 usb_free_urb(instance->int_urb);
610 instance->int_urb = NULL;
619 } 611 }
620 release_firmware(fw1);
621 } 612 }
622 613
623 /* In case we failed, set state back to NO_FIRMWARE so that 614 /* Start status polling */
624 another later attempt may work. Otherwise, we never actually 615 mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(1000));
625 manage to recover if, for example, the firmware is on /usr and
626 we look for it too early. */
627 speedtch_got_firmware(instance, 0);
628 616
629 module_put(THIS_MODULE);
630 udsl_put_instance(&instance->u);
631 return 0; 617 return 0;
632} 618}
633#endif /* USE_FW_LOADER */
634 619
635static void speedtch_firmware_start(struct speedtch_instance_data *instance) 620static void speedtch_atm_stop(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
636{ 621{
637#ifdef USE_FW_LOADER 622 struct speedtch_instance_data *instance = usbatm->driver_data;
638 int ret; 623 struct urb *int_urb = instance->int_urb;
639#endif 624
640 625 atm_dbg(usbatm, "%s entered\n", __func__);
641 dbg("speedtch_firmware_start"); 626
642 627 del_timer_sync(&instance->status_checker.timer);
643 down(&instance->u.serialize); /* vs self, speedtch_got_firmware */ 628
644 629 /*
645 if (instance->u.status >= UDSL_LOADING_FIRMWARE) { 630 * Since resubmit_timer and int_urb can schedule themselves and
646 up(&instance->u.serialize); 631 * each other, shutting them down correctly takes some care
647 return; 632 */
648 } 633 instance->int_urb = NULL; /* signal shutdown */
634 mb();
635 usb_kill_urb(int_urb);
636 del_timer_sync(&instance->resubmit_timer);
637 /*
638 * At this point, speedtch_handle_int and speedtch_resubmit_int
639 * can run or be running, but instance->int_urb == NULL means that
640 * they will not reschedule
641 */
642 usb_kill_urb(int_urb);
643 del_timer_sync(&instance->resubmit_timer);
644 usb_free_urb(int_urb);
649 645
650 instance->u.status = UDSL_LOADING_FIRMWARE; 646 flush_scheduled_work();
651 up(&instance->u.serialize); 647}
652 648
653#ifdef USE_FW_LOADER
654 udsl_get_instance(&instance->u);
655 try_module_get(THIS_MODULE);
656 649
657 ret = kernel_thread(speedtch_load_firmware, instance, 650/**********
658 CLONE_FS | CLONE_FILES); 651** USB **
652**********/
659 653
660 if (ret >= 0) 654static struct usb_device_id speedtch_usb_ids[] = {
661 return; /* OK */ 655 {USB_DEVICE(0x06b9, 0x4061)},
656 {}
657};
662 658
663 dbg("speedtch_firmware_start: kernel_thread failed (%d)!", ret); 659MODULE_DEVICE_TABLE(usb, speedtch_usb_ids);
664 660
665 module_put(THIS_MODULE); 661static int speedtch_usb_probe(struct usb_interface *, const struct usb_device_id *);
666 udsl_put_instance(&instance->u);
667 /* Just pretend it never happened... hope modem_run happens */
668#endif /* USE_FW_LOADER */
669 662
670 speedtch_got_firmware(instance, 0); 663static struct usb_driver speedtch_usb_driver = {
671} 664 .owner = THIS_MODULE,
672 665 .name = speedtch_driver_name,
673static int speedtch_firmware_wait(struct udsl_instance_data *instance) 666 .probe = speedtch_usb_probe,
674{ 667 .disconnect = usbatm_usb_disconnect,
675 speedtch_firmware_start((void *)instance); 668 .id_table = speedtch_usb_ids
669};
676 670
677 if (wait_event_interruptible(instance->firmware_waiters, instance->status != UDSL_LOADING_FIRMWARE) < 0) 671static void speedtch_release_interfaces(struct usb_device *usb_dev, int num_interfaces) {
678 return -ERESTARTSYS; 672 struct usb_interface *cur_intf;
673 int i;
679 674
680 return (instance->status == UDSL_LOADED_FIRMWARE) ? 0 : -EAGAIN; 675 for(i = 0; i < num_interfaces; i++)
676 if ((cur_intf = usb_ifnum_to_if(usb_dev, i))) {
677 usb_set_intfdata(cur_intf, NULL);
678 usb_driver_release_interface(&speedtch_usb_driver, cur_intf);
679 }
681} 680}
682 681
683/********** 682static int speedtch_bind(struct usbatm_data *usbatm,
684** USB ** 683 struct usb_interface *intf,
685**********/ 684 const struct usb_device_id *id,
686 685 int *need_heavy_init)
687static int speedtch_usb_ioctl(struct usb_interface *intf, unsigned int code,
688 void *user_data)
689{ 686{
690 struct speedtch_instance_data *instance = usb_get_intfdata(intf); 687 struct usb_device *usb_dev = interface_to_usbdev(intf);
688 struct usb_interface *cur_intf;
689 struct speedtch_instance_data *instance;
690 int ifnum = intf->altsetting->desc.bInterfaceNumber;
691 int num_interfaces = usb_dev->actconfig->desc.bNumInterfaces;
692 int i, ret;
691 693
692 dbg("speedtch_usb_ioctl entered"); 694 usb_dbg(usbatm, "%s entered\n", __func__);
693 695
694 if (!instance) { 696 if (usb_dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) {
695 dbg("speedtch_usb_ioctl: NULL instance!"); 697 usb_dbg(usbatm, "%s: wrong device class %d\n", __func__, usb_dev->descriptor.bDeviceClass);
696 return -ENODEV; 698 return -ENODEV;
697 } 699 }
698 700
699 switch (code) { 701 /* claim all interfaces */
700 case UDSL_IOCTL_LINE_UP:
701 instance->u.atm_dev->signal = ATM_PHY_SIG_FOUND;
702 speedtch_got_firmware(instance, 1);
703 return (instance->u.status == UDSL_LOADED_FIRMWARE) ? 0 : -EIO;
704 case UDSL_IOCTL_LINE_DOWN:
705 instance->u.atm_dev->signal = ATM_PHY_SIG_LOST;
706 return 0;
707 default:
708 return -ENOTTY;
709 }
710}
711 702
712static int speedtch_usb_probe(struct usb_interface *intf, 703 for (i=0; i < num_interfaces; i++) {
713 const struct usb_device_id *id) 704 cur_intf = usb_ifnum_to_if(usb_dev, i);
714{
715 struct usb_device *dev = interface_to_usbdev(intf);
716 int ifnum = intf->altsetting->desc.bInterfaceNumber;
717 struct speedtch_instance_data *instance;
718 unsigned char mac_str[13];
719 int ret, i;
720 char buf7[SIZE_7];
721 705
722 dbg("speedtch_usb_probe: trying device with vendor=0x%x, product=0x%x, ifnum %d", 706 if ((i != ifnum) && cur_intf) {
723 le16_to_cpu(dev->descriptor.idVendor), 707 ret = usb_driver_claim_interface(&speedtch_usb_driver, cur_intf, usbatm);
724 le16_to_cpu(dev->descriptor.idProduct), ifnum);
725 708
726 if ((dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) || 709 if (ret < 0) {
727 (ifnum != 1)) 710 usb_dbg(usbatm, "%s: failed to claim interface %d (%d)\n", __func__, i, ret);
728 return -ENODEV; 711 speedtch_release_interfaces(usb_dev, i);
729 712 return ret;
730 dbg("speedtch_usb_probe: device accepted"); 713 }
714 }
715 }
731 716
732 /* instance init */
733 instance = kmalloc(sizeof(*instance), GFP_KERNEL); 717 instance = kmalloc(sizeof(*instance), GFP_KERNEL);
718
734 if (!instance) { 719 if (!instance) {
735 dbg("speedtch_usb_probe: no memory for instance data!"); 720 usb_dbg(usbatm, "%s: no memory for instance data!\n", __func__);
736 return -ENOMEM; 721 ret = -ENOMEM;
722 goto fail_release;
737 } 723 }
738 724
739 memset(instance, 0, sizeof(struct speedtch_instance_data)); 725 memset(instance, 0, sizeof(struct speedtch_instance_data));
740 726
741 if ((ret = usb_set_interface(dev, 0, 0)) < 0) 727 instance->usbatm = usbatm;
742 goto fail;
743 728
744 if ((ret = usb_set_interface(dev, 2, 0)) < 0) 729 INIT_WORK(&instance->status_checker, (void *)speedtch_check_status, instance);
745 goto fail;
746 730
747 instance->u.data_endpoint = SPEEDTCH_ENDPOINT_DATA; 731 instance->status_checker.timer.function = speedtch_status_poll;
748 instance->u.firmware_wait = speedtch_firmware_wait; 732 instance->status_checker.timer.data = (unsigned long)instance;
749 instance->u.driver_name = speedtch_driver_name; 733 instance->poll_delay = MIN_POLL_DELAY;
750 734
751 ret = udsl_instance_setup(dev, &instance->u); 735 init_timer(&instance->resubmit_timer);
752 if (ret) 736 instance->resubmit_timer.function = speedtch_resubmit_int;
753 goto fail; 737 instance->resubmit_timer.data = (unsigned long)instance;
754 738
755 init_timer(&instance->poll_timer); 739 instance->int_urb = usb_alloc_urb(0, GFP_KERNEL);
756 instance->poll_timer.function = speedtch_timer_poll;
757 instance->poll_timer.data = (unsigned long)instance;
758 740
759 INIT_WORK(&instance->poll_work, (void *)speedtch_poll_status, instance); 741 if (instance->int_urb)
742 usb_fill_int_urb(instance->int_urb, usb_dev,
743 usb_rcvintpipe(usb_dev, ENDPOINT_INT),
744 instance->int_data, sizeof(instance->int_data),
745 speedtch_handle_int, instance, 50);
746 else
747 usb_dbg(usbatm, "%s: no memory for interrupt urb!\n", __func__);
760 748
761 /* set MAC address, it is stored in the serial number */ 749 /* check whether the modem already seems to be alive */
762 memset(instance->u.atm_dev->esi, 0, sizeof(instance->u.atm_dev->esi)); 750 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
763 if (usb_string(dev, dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) { 751 0x12, 0xc0, 0x07, 0x00,
764 for (i = 0; i < 6; i++) 752 instance->scratch_buffer + OFFSET_7, SIZE_7, 500);
765 instance->u.atm_dev->esi[i] =
766 (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1]));
767 }
768 753
769 /* First check whether the modem already seems to be alive */ 754 *need_heavy_init = (ret != SIZE_7);
770 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
771 0x12, 0xc0, 0x07, 0x00, buf7, SIZE_7, 500);
772 755
773 if (ret == SIZE_7) { 756 usb_dbg(usbatm, "%s: firmware %s loaded\n", __func__, need_heavy_init ? "not" : "already");
774 dbg("firmware appears to be already loaded"); 757
775 speedtch_got_firmware(instance, 1); 758 if (*need_heavy_init)
776 speedtch_poll_status(instance); 759 if ((ret = usb_reset_device(usb_dev)) < 0)
777 } else { 760 goto fail_free;
778 speedtch_firmware_start(instance);
779 }
780 761
781 usb_set_intfdata(intf, instance); 762 usbatm->driver_data = instance;
782 763
783 return 0; 764 return 0;
784 765
785 fail: 766fail_free:
767 usb_free_urb(instance->int_urb);
786 kfree(instance); 768 kfree(instance);
787 769fail_release:
788 return -ENOMEM; 770 speedtch_release_interfaces(usb_dev, num_interfaces);
771 return ret;
789} 772}
790 773
791static void speedtch_usb_disconnect(struct usb_interface *intf) 774static void speedtch_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
792{ 775{
793 struct speedtch_instance_data *instance = usb_get_intfdata(intf); 776 struct usb_device *usb_dev = interface_to_usbdev(intf);
794 777 struct speedtch_instance_data *instance = usbatm->driver_data;
795 dbg("speedtch_usb_disconnect entered");
796
797 if (!instance) {
798 dbg("speedtch_usb_disconnect: NULL instance!");
799 return;
800 }
801 778
802/*QQ need to handle disconnects on interface #2 while uploading firmware */ 779 usb_dbg(usbatm, "%s entered\n", __func__);
803/*QQ and what about interface #1? */
804
805 if (instance->int_urb) {
806 struct urb *int_urb = instance->int_urb;
807 instance->int_urb = NULL;
808 wmb();
809 usb_unlink_urb(int_urb);
810 usb_free_urb(int_urb);
811 }
812 780
813 instance->int_data[0] = 1; 781 speedtch_release_interfaces(usb_dev, usb_dev->actconfig->desc.bNumInterfaces);
814 del_timer_sync(&instance->poll_timer); 782 usb_free_urb(instance->int_urb);
815 wmb(); 783 kfree(instance);
816 flush_scheduled_work();
817
818 udsl_instance_disconnect(&instance->u);
819
820 /* clean up */
821 usb_set_intfdata(intf, NULL);
822 udsl_put_instance(&instance->u);
823} 784}
824 785
786
825/*********** 787/***********
826** init ** 788** init **
827***********/ 789***********/
828 790
791static struct usbatm_driver speedtch_usbatm_driver = {
792 .owner = THIS_MODULE,
793 .driver_name = speedtch_driver_name,
794 .bind = speedtch_bind,
795 .heavy_init = speedtch_heavy_init,
796 .unbind = speedtch_unbind,
797 .atm_start = speedtch_atm_start,
798 .atm_stop = speedtch_atm_stop,
799 .in = ENDPOINT_DATA,
800 .out = ENDPOINT_DATA
801};
802
803static int speedtch_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
804{
805 return usbatm_usb_probe(intf, id, &speedtch_usbatm_driver);
806}
807
829static int __init speedtch_usb_init(void) 808static int __init speedtch_usb_init(void)
830{ 809{
831 dbg("speedtch_usb_init: driver version " DRIVER_VERSION); 810 dbg("%s: driver version %s", __func__, DRIVER_VERSION);
832 811
833 return usb_register(&speedtch_usb_driver); 812 return usb_register(&speedtch_usb_driver);
834} 813}
835 814
836static void __exit speedtch_usb_cleanup(void) 815static void __exit speedtch_usb_cleanup(void)
837{ 816{
838 dbg("speedtch_usb_cleanup entered"); 817 dbg("%s", __func__);
839 818
840 usb_deregister(&speedtch_usb_driver); 819 usb_deregister(&speedtch_usb_driver);
841} 820}
diff --git a/drivers/usb/atm/usb_atm.c b/drivers/usb/atm/usb_atm.c
deleted file mode 100644
index a4cd4476d49a..000000000000
--- a/drivers/usb/atm/usb_atm.c
+++ /dev/null
@@ -1,1188 +0,0 @@
1/******************************************************************************
2 * usb_atm.c - Generic USB xDSL driver core
3 *
4 * Copyright (C) 2001, Alcatel
5 * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
6 * Copyright (C) 2004, David Woodhouse
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 ******************************************************************************/
23
24/*
25 * Written by Johan Verrept, maintained by Duncan Sands (duncan.sands@free.fr)
26 *
27 * 1.7+: - See the check-in logs
28 *
29 * 1.6: - No longer opens a connection if the firmware is not loaded
30 * - Added support for the speedtouch 330
31 * - Removed the limit on the number of devices
32 * - Module now autoloads on device plugin
33 * - Merged relevant parts of sarlib
34 * - Replaced the kernel thread with a tasklet
35 * - New packet transmission code
36 * - Changed proc file contents
37 * - Fixed all known SMP races
38 * - Many fixes and cleanups
39 * - Various fixes by Oliver Neukum (oliver@neukum.name)
40 *
41 * 1.5A: - Version for inclusion in 2.5 series kernel
42 * - Modifications by Richard Purdie (rpurdie@rpsys.net)
43 * - made compatible with kernel 2.5.6 onwards by changing
44 * udsl_usb_send_data_context->urb to a pointer and adding code
45 * to alloc and free it
46 * - remove_wait_queue() added to udsl_atm_processqueue_thread()
47 *
48 * 1.5: - fixed memory leak when atmsar_decode_aal5 returned NULL.
49 * (reported by stephen.robinson@zen.co.uk)
50 *
51 * 1.4: - changed the spin_lock() under interrupt to spin_lock_irqsave()
52 * - unlink all active send urbs of a vcc that is being closed.
53 *
54 * 1.3.1: - added the version number
55 *
56 * 1.3: - Added multiple send urb support
57 * - fixed memory leak and vcc->tx_inuse starvation bug
58 * when not enough memory left in vcc.
59 *
60 * 1.2: - Fixed race condition in udsl_usb_send_data()
61 * 1.1: - Turned off packet debugging
62 *
63 */
64
65#include <linux/module.h>
66#include <linux/moduleparam.h>
67#include <linux/kernel.h>
68#include <linux/sched.h>
69#include <linux/timer.h>
70#include <linux/errno.h>
71#include <linux/proc_fs.h>
72#include <linux/slab.h>
73#include <linux/wait.h>
74#include <linux/list.h>
75#include <asm/uaccess.h>
76#include <linux/smp_lock.h>
77#include <linux/interrupt.h>
78#include <linux/atm.h>
79#include <linux/atmdev.h>
80#include <linux/crc32.h>
81#include <linux/init.h>
82#include <linux/firmware.h>
83
84#include "usb_atm.h"
85
86#ifdef VERBOSE_DEBUG
87static int udsl_print_packet(const unsigned char *data, int len);
88#define PACKETDEBUG(arg...) udsl_print_packet (arg)
89#define vdbg(arg...) dbg (arg)
90#else
91#define PACKETDEBUG(arg...)
92#define vdbg(arg...)
93#endif
94
95#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
96#define DRIVER_VERSION "1.8"
97#define DRIVER_DESC "Generic USB ATM/DSL I/O, version " DRIVER_VERSION
98
99static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS;
100static unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS;
101static unsigned int num_rcv_bufs = UDSL_DEFAULT_RCV_BUFS;
102static unsigned int num_snd_bufs = UDSL_DEFAULT_SND_BUFS;
103static unsigned int rcv_buf_size = UDSL_DEFAULT_RCV_BUF_SIZE;
104static unsigned int snd_buf_size = UDSL_DEFAULT_SND_BUF_SIZE;
105
106module_param(num_rcv_urbs, uint, 0444);
107MODULE_PARM_DESC(num_rcv_urbs,
108 "Number of urbs used for reception (range: 0-"
109 __MODULE_STRING(UDSL_MAX_RCV_URBS) ", default: "
110 __MODULE_STRING(UDSL_DEFAULT_RCV_URBS) ")");
111
112module_param(num_snd_urbs, uint, 0444);
113MODULE_PARM_DESC(num_snd_urbs,
114 "Number of urbs used for transmission (range: 0-"
115 __MODULE_STRING(UDSL_MAX_SND_URBS) ", default: "
116 __MODULE_STRING(UDSL_DEFAULT_SND_URBS) ")");
117
118module_param(num_rcv_bufs, uint, 0444);
119MODULE_PARM_DESC(num_rcv_bufs,
120 "Number of buffers used for reception (range: 0-"
121 __MODULE_STRING(UDSL_MAX_RCV_BUFS) ", default: "
122 __MODULE_STRING(UDSL_DEFAULT_RCV_BUFS) ")");
123
124module_param(num_snd_bufs, uint, 0444);
125MODULE_PARM_DESC(num_snd_bufs,
126 "Number of buffers used for transmission (range: 0-"
127 __MODULE_STRING(UDSL_MAX_SND_BUFS) ", default: "
128 __MODULE_STRING(UDSL_DEFAULT_SND_BUFS) ")");
129
130module_param(rcv_buf_size, uint, 0444);
131MODULE_PARM_DESC(rcv_buf_size,
132 "Size of the buffers used for reception (range: 0-"
133 __MODULE_STRING(UDSL_MAX_RCV_BUF_SIZE) ", default: "
134 __MODULE_STRING(UDSL_DEFAULT_RCV_BUF_SIZE) ")");
135
136module_param(snd_buf_size, uint, 0444);
137MODULE_PARM_DESC(snd_buf_size,
138 "Size of the buffers used for transmission (range: 0-"
139 __MODULE_STRING(UDSL_MAX_SND_BUF_SIZE) ", default: "
140 __MODULE_STRING(UDSL_DEFAULT_SND_BUF_SIZE) ")");
141
142/* ATM */
143
144static void udsl_atm_dev_close(struct atm_dev *dev);
145static int udsl_atm_open(struct atm_vcc *vcc);
146static void udsl_atm_close(struct atm_vcc *vcc);
147static int udsl_atm_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg);
148static int udsl_atm_send(struct atm_vcc *vcc, struct sk_buff *skb);
149static int udsl_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page);
150
151static struct atmdev_ops udsl_atm_devops = {
152 .dev_close = udsl_atm_dev_close,
153 .open = udsl_atm_open,
154 .close = udsl_atm_close,
155 .ioctl = udsl_atm_ioctl,
156 .send = udsl_atm_send,
157 .proc_read = udsl_atm_proc_read,
158 .owner = THIS_MODULE,
159};
160
161/***********
162** misc **
163***********/
164
165static inline void udsl_pop(struct atm_vcc *vcc, struct sk_buff *skb)
166{
167 if (vcc->pop)
168 vcc->pop(vcc, skb);
169 else
170 dev_kfree_skb(skb);
171}
172
173/*************
174** decode **
175*************/
176
177static inline struct udsl_vcc_data *udsl_find_vcc(struct udsl_instance_data *instance,
178 short vpi, int vci)
179{
180 struct udsl_vcc_data *vcc;
181
182 list_for_each_entry(vcc, &instance->vcc_list, list)
183 if ((vcc->vci == vci) && (vcc->vpi == vpi))
184 return vcc;
185 return NULL;
186}
187
188static void udsl_extract_cells(struct udsl_instance_data *instance,
189 unsigned char *source, unsigned int howmany)
190{
191 struct udsl_vcc_data *cached_vcc = NULL;
192 struct atm_vcc *vcc;
193 struct sk_buff *sarb;
194 struct udsl_vcc_data *vcc_data;
195 int cached_vci = 0;
196 unsigned int i;
197 int pti;
198 int vci;
199 short cached_vpi = 0;
200 short vpi;
201
202 for (i = 0; i < howmany;
203 i++, source += ATM_CELL_SIZE + instance->rcv_padding) {
204 vpi = ((source[0] & 0x0f) << 4) | (source[1] >> 4);
205 vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4);
206 pti = (source[3] & 0x2) != 0;
207
208 vdbg("udsl_extract_cells: vpi %hd, vci %d, pti %d", vpi, vci, pti);
209
210 if (cached_vcc && (vci == cached_vci) && (vpi == cached_vpi))
211 vcc_data = cached_vcc;
212 else if ((vcc_data = udsl_find_vcc(instance, vpi, vci))) {
213 cached_vcc = vcc_data;
214 cached_vpi = vpi;
215 cached_vci = vci;
216 } else {
217 dbg("udsl_extract_cells: unknown vpi/vci (%hd/%d)!", vpi, vci);
218 continue;
219 }
220
221 vcc = vcc_data->vcc;
222 sarb = vcc_data->sarb;
223
224 if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) {
225 dbg("udsl_extract_cells: buffer overrun (sarb->len %u, vcc: 0x%p)!", sarb->len, vcc);
226 /* discard cells already received */
227 skb_trim(sarb, 0);
228 }
229
230 memcpy(sarb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD);
231 __skb_put(sarb, ATM_CELL_PAYLOAD);
232
233 if (pti) {
234 struct sk_buff *skb;
235 unsigned int length;
236 unsigned int pdu_length;
237
238 length = (source[ATM_CELL_SIZE - 6] << 8) + source[ATM_CELL_SIZE - 5];
239
240 /* guard against overflow */
241 if (length > ATM_MAX_AAL5_PDU) {
242 dbg("udsl_extract_cells: bogus length %u (vcc: 0x%p)!", length, vcc);
243 atomic_inc(&vcc->stats->rx_err);
244 goto out;
245 }
246
247 pdu_length = UDSL_NUM_CELLS(length) * ATM_CELL_PAYLOAD;
248
249 if (sarb->len < pdu_length) {
250 dbg("udsl_extract_cells: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!", pdu_length, sarb->len, vcc);
251 atomic_inc(&vcc->stats->rx_err);
252 goto out;
253 }
254
255 if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) {
256 dbg("udsl_extract_cells: packet failed crc check (vcc: 0x%p)!", vcc);
257 atomic_inc(&vcc->stats->rx_err);
258 goto out;
259 }
260
261 vdbg("udsl_extract_cells: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", length, pdu_length, vcc);
262
263 if (!(skb = dev_alloc_skb(length))) {
264 dbg("udsl_extract_cells: no memory for skb (length: %u)!", length);
265 atomic_inc(&vcc->stats->rx_drop);
266 goto out;
267 }
268
269 vdbg("udsl_extract_cells: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", skb, skb->truesize);
270
271 if (!atm_charge(vcc, skb->truesize)) {
272 dbg("udsl_extract_cells: failed atm_charge (skb->truesize: %u)!", skb->truesize);
273 dev_kfree_skb(skb);
274 goto out; /* atm_charge increments rx_drop */
275 }
276
277 memcpy(skb->data, sarb->tail - pdu_length, length);
278 __skb_put(skb, length);
279
280 vdbg("udsl_extract_cells: sending skb 0x%p, skb->len %u, skb->truesize %u", skb, skb->len, skb->truesize);
281
282 PACKETDEBUG(skb->data, skb->len);
283
284 vcc->push(vcc, skb);
285
286 atomic_inc(&vcc->stats->rx);
287 out:
288 skb_trim(sarb, 0);
289 }
290 }
291}
292
293/*************
294** encode **
295*************/
296
297static inline void udsl_fill_cell_header(unsigned char *target, struct atm_vcc *vcc)
298{
299 target[0] = vcc->vpi >> 4;
300 target[1] = (vcc->vpi << 4) | (vcc->vci >> 12);
301 target[2] = vcc->vci >> 4;
302 target[3] = vcc->vci << 4;
303 target[4] = 0xec;
304}
305
306static const unsigned char zeros[ATM_CELL_PAYLOAD];
307
308static void udsl_groom_skb(struct atm_vcc *vcc, struct sk_buff *skb)
309{
310 struct udsl_control *ctrl = UDSL_SKB(skb);
311 unsigned int zero_padding;
312 u32 crc;
313
314 ctrl->atm_data.vcc = vcc;
315
316 ctrl->num_cells = UDSL_NUM_CELLS(skb->len);
317 ctrl->num_entire = skb->len / ATM_CELL_PAYLOAD;
318
319 zero_padding = ctrl->num_cells * ATM_CELL_PAYLOAD - skb->len - ATM_AAL5_TRAILER;
320
321 if (ctrl->num_entire + 1 < ctrl->num_cells)
322 ctrl->pdu_padding = zero_padding - (ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER);
323 else
324 ctrl->pdu_padding = zero_padding;
325
326 ctrl->aal5_trailer[0] = 0; /* UU = 0 */
327 ctrl->aal5_trailer[1] = 0; /* CPI = 0 */
328 ctrl->aal5_trailer[2] = skb->len >> 8;
329 ctrl->aal5_trailer[3] = skb->len;
330
331 crc = crc32_be(~0, skb->data, skb->len);
332 crc = crc32_be(crc, zeros, zero_padding);
333 crc = crc32_be(crc, ctrl->aal5_trailer, 4);
334 crc = ~crc;
335
336 ctrl->aal5_trailer[4] = crc >> 24;
337 ctrl->aal5_trailer[5] = crc >> 16;
338 ctrl->aal5_trailer[6] = crc >> 8;
339 ctrl->aal5_trailer[7] = crc;
340}
341
342static unsigned int udsl_write_cells(struct udsl_instance_data *instance,
343 unsigned int howmany, struct sk_buff *skb,
344 unsigned char **target_p)
345{
346 struct udsl_control *ctrl = UDSL_SKB(skb);
347 unsigned char *target = *target_p;
348 unsigned int nc, ne, i;
349
350 vdbg("udsl_write_cells: howmany=%u, skb->len=%d, num_cells=%u, num_entire=%u, pdu_padding=%u", howmany, skb->len, ctrl->num_cells, ctrl->num_entire, ctrl->pdu_padding);
351
352 nc = ctrl->num_cells;
353 ne = min(howmany, ctrl->num_entire);
354
355 for (i = 0; i < ne; i++) {
356 udsl_fill_cell_header(target, ctrl->atm_data.vcc);
357 target += ATM_CELL_HEADER;
358 memcpy(target, skb->data, ATM_CELL_PAYLOAD);
359 target += ATM_CELL_PAYLOAD;
360 if (instance->snd_padding) {
361 memset(target, 0, instance->snd_padding);
362 target += instance->snd_padding;
363 }
364 __skb_pull(skb, ATM_CELL_PAYLOAD);
365 }
366
367 ctrl->num_entire -= ne;
368
369 if (!(ctrl->num_cells -= ne) || !(howmany -= ne))
370 goto out;
371
372 udsl_fill_cell_header(target, ctrl->atm_data.vcc);
373 target += ATM_CELL_HEADER;
374 memcpy(target, skb->data, skb->len);
375 target += skb->len;
376 __skb_pull(skb, skb->len);
377 memset(target, 0, ctrl->pdu_padding);
378 target += ctrl->pdu_padding;
379
380 if (--ctrl->num_cells) {
381 if (!--howmany) {
382 ctrl->pdu_padding = ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER;
383 goto out;
384 }
385
386 if (instance->snd_padding) {
387 memset(target, 0, instance->snd_padding);
388 target += instance->snd_padding;
389 }
390 udsl_fill_cell_header(target, ctrl->atm_data.vcc);
391 target += ATM_CELL_HEADER;
392 memset(target, 0, ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER);
393 target += ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER;
394
395 --ctrl->num_cells;
396 UDSL_ASSERT(!ctrl->num_cells);
397 }
398
399 memcpy(target, ctrl->aal5_trailer, ATM_AAL5_TRAILER);
400 target += ATM_AAL5_TRAILER;
401 /* set pti bit in last cell */
402 *(target + 3 - ATM_CELL_SIZE) |= 0x2;
403 if (instance->snd_padding) {
404 memset(target, 0, instance->snd_padding);
405 target += instance->snd_padding;
406 }
407 out:
408 *target_p = target;
409 return nc - ctrl->num_cells;
410}
411
412/**************
413** receive **
414**************/
415
416static void udsl_complete_receive(struct urb *urb, struct pt_regs *regs)
417{
418 struct udsl_receive_buffer *buf;
419 struct udsl_instance_data *instance;
420 struct udsl_receiver *rcv;
421 unsigned long flags;
422
423 if (!urb || !(rcv = urb->context)) {
424 dbg("udsl_complete_receive: bad urb!");
425 return;
426 }
427
428 instance = rcv->instance;
429 buf = rcv->buffer;
430
431 buf->filled_cells = urb->actual_length / (ATM_CELL_SIZE + instance->rcv_padding);
432
433 vdbg("udsl_complete_receive: urb 0x%p, status %d, actual_length %d, filled_cells %u, rcv 0x%p, buf 0x%p", urb, urb->status, urb->actual_length, buf->filled_cells, rcv, buf);
434
435 UDSL_ASSERT(buf->filled_cells <= rcv_buf_size);
436
437 /* may not be in_interrupt() */
438 spin_lock_irqsave(&instance->receive_lock, flags);
439 list_add(&rcv->list, &instance->spare_receivers);
440 list_add_tail(&buf->list, &instance->filled_receive_buffers);
441 if (likely(!urb->status))
442 tasklet_schedule(&instance->receive_tasklet);
443 spin_unlock_irqrestore(&instance->receive_lock, flags);
444}
445
446static void udsl_process_receive(unsigned long data)
447{
448 struct udsl_receive_buffer *buf;
449 struct udsl_instance_data *instance = (struct udsl_instance_data *)data;
450 struct udsl_receiver *rcv;
451 int err;
452
453 made_progress:
454 while (!list_empty(&instance->spare_receive_buffers)) {
455 spin_lock_irq(&instance->receive_lock);
456 if (list_empty(&instance->spare_receivers)) {
457 spin_unlock_irq(&instance->receive_lock);
458 break;
459 }
460 rcv = list_entry(instance->spare_receivers.next,
461 struct udsl_receiver, list);
462 list_del(&rcv->list);
463 spin_unlock_irq(&instance->receive_lock);
464
465 buf = list_entry(instance->spare_receive_buffers.next,
466 struct udsl_receive_buffer, list);
467 list_del(&buf->list);
468
469 rcv->buffer = buf;
470
471 usb_fill_bulk_urb(rcv->urb, instance->usb_dev,
472 usb_rcvbulkpipe(instance->usb_dev, instance->data_endpoint),
473 buf->base,
474 rcv_buf_size * (ATM_CELL_SIZE + instance->rcv_padding),
475 udsl_complete_receive, rcv);
476
477 vdbg("udsl_process_receive: sending urb 0x%p, rcv 0x%p, buf 0x%p",
478 rcv->urb, rcv, buf);
479
480 if ((err = usb_submit_urb(rcv->urb, GFP_ATOMIC)) < 0) {
481 dbg("udsl_process_receive: urb submission failed (%d)!", err);
482 list_add(&buf->list, &instance->spare_receive_buffers);
483 spin_lock_irq(&instance->receive_lock);
484 list_add(&rcv->list, &instance->spare_receivers);
485 spin_unlock_irq(&instance->receive_lock);
486 break;
487 }
488 }
489
490 spin_lock_irq(&instance->receive_lock);
491 if (list_empty(&instance->filled_receive_buffers)) {
492 spin_unlock_irq(&instance->receive_lock);
493 return; /* done - no more buffers */
494 }
495 buf = list_entry(instance->filled_receive_buffers.next,
496 struct udsl_receive_buffer, list);
497 list_del(&buf->list);
498 spin_unlock_irq(&instance->receive_lock);
499
500 vdbg("udsl_process_receive: processing buf 0x%p", buf);
501 udsl_extract_cells(instance, buf->base, buf->filled_cells);
502 list_add(&buf->list, &instance->spare_receive_buffers);
503 goto made_progress;
504}
505
506/***********
507** send **
508***********/
509
510static void udsl_complete_send(struct urb *urb, struct pt_regs *regs)
511{
512 struct udsl_instance_data *instance;
513 struct udsl_sender *snd;
514 unsigned long flags;
515
516 if (!urb || !(snd = urb->context) || !(instance = snd->instance)) {
517 dbg("udsl_complete_send: bad urb!");
518 return;
519 }
520
521 vdbg("udsl_complete_send: urb 0x%p, status %d, snd 0x%p, buf 0x%p", urb,
522 urb->status, snd, snd->buffer);
523
524 /* may not be in_interrupt() */
525 spin_lock_irqsave(&instance->send_lock, flags);
526 list_add(&snd->list, &instance->spare_senders);
527 list_add(&snd->buffer->list, &instance->spare_send_buffers);
528 tasklet_schedule(&instance->send_tasklet);
529 spin_unlock_irqrestore(&instance->send_lock, flags);
530}
531
532static void udsl_process_send(unsigned long data)
533{
534 struct udsl_send_buffer *buf;
535 struct udsl_instance_data *instance = (struct udsl_instance_data *)data;
536 struct sk_buff *skb;
537 struct udsl_sender *snd;
538 int err;
539 unsigned int num_written;
540
541 made_progress:
542 spin_lock_irq(&instance->send_lock);
543 while (!list_empty(&instance->spare_senders)) {
544 if (!list_empty(&instance->filled_send_buffers)) {
545 buf = list_entry(instance->filled_send_buffers.next,
546 struct udsl_send_buffer, list);
547 list_del(&buf->list);
548 } else if ((buf = instance->current_buffer)) {
549 instance->current_buffer = NULL;
550 } else /* all buffers empty */
551 break;
552
553 snd = list_entry(instance->spare_senders.next,
554 struct udsl_sender, list);
555 list_del(&snd->list);
556 spin_unlock_irq(&instance->send_lock);
557
558 snd->buffer = buf;
559 usb_fill_bulk_urb(snd->urb, instance->usb_dev,
560 usb_sndbulkpipe(instance->usb_dev, instance->data_endpoint),
561 buf->base,
562 (snd_buf_size - buf->free_cells) * (ATM_CELL_SIZE + instance->snd_padding),
563 udsl_complete_send, snd);
564
565 vdbg("udsl_process_send: submitting urb 0x%p (%d cells), snd 0x%p, buf 0x%p",
566 snd->urb, snd_buf_size - buf->free_cells, snd, buf);
567
568 if ((err = usb_submit_urb(snd->urb, GFP_ATOMIC)) < 0) {
569 dbg("udsl_process_send: urb submission failed (%d)!", err);
570 spin_lock_irq(&instance->send_lock);
571 list_add(&snd->list, &instance->spare_senders);
572 spin_unlock_irq(&instance->send_lock);
573 list_add(&buf->list, &instance->filled_send_buffers);
574 return; /* bail out */
575 }
576
577 spin_lock_irq(&instance->send_lock);
578 } /* while */
579 spin_unlock_irq(&instance->send_lock);
580
581 if (!instance->current_skb)
582 instance->current_skb = skb_dequeue(&instance->sndqueue);
583 if (!instance->current_skb)
584 return; /* done - no more skbs */
585
586 skb = instance->current_skb;
587
588 if (!(buf = instance->current_buffer)) {
589 spin_lock_irq(&instance->send_lock);
590 if (list_empty(&instance->spare_send_buffers)) {
591 instance->current_buffer = NULL;
592 spin_unlock_irq(&instance->send_lock);
593 return; /* done - no more buffers */
594 }
595 buf = list_entry(instance->spare_send_buffers.next,
596 struct udsl_send_buffer, list);
597 list_del(&buf->list);
598 spin_unlock_irq(&instance->send_lock);
599
600 buf->free_start = buf->base;
601 buf->free_cells = snd_buf_size;
602
603 instance->current_buffer = buf;
604 }
605
606 num_written = udsl_write_cells(instance, buf->free_cells, skb, &buf->free_start);
607
608 vdbg("udsl_process_send: wrote %u cells from skb 0x%p to buffer 0x%p",
609 num_written, skb, buf);
610
611 if (!(buf->free_cells -= num_written)) {
612 list_add_tail(&buf->list, &instance->filled_send_buffers);
613 instance->current_buffer = NULL;
614 }
615
616 vdbg("udsl_process_send: buffer contains %d cells, %d left",
617 snd_buf_size - buf->free_cells, buf->free_cells);
618
619 if (!UDSL_SKB(skb)->num_cells) {
620 struct atm_vcc *vcc = UDSL_SKB(skb)->atm_data.vcc;
621
622 udsl_pop(vcc, skb);
623 instance->current_skb = NULL;
624
625 atomic_inc(&vcc->stats->tx);
626 }
627
628 goto made_progress;
629}
630
631static void udsl_cancel_send(struct udsl_instance_data *instance,
632 struct atm_vcc *vcc)
633{
634 struct sk_buff *skb, *n;
635
636 dbg("udsl_cancel_send entered");
637 spin_lock_irq(&instance->sndqueue.lock);
638 for (skb = instance->sndqueue.next, n = skb->next;
639 skb != (struct sk_buff *)&instance->sndqueue;
640 skb = n, n = skb->next)
641 if (UDSL_SKB(skb)->atm_data.vcc == vcc) {
642 dbg("udsl_cancel_send: popping skb 0x%p", skb);
643 __skb_unlink(skb, &instance->sndqueue);
644 udsl_pop(vcc, skb);
645 }
646 spin_unlock_irq(&instance->sndqueue.lock);
647
648 tasklet_disable(&instance->send_tasklet);
649 if ((skb = instance->current_skb) && (UDSL_SKB(skb)->atm_data.vcc == vcc)) {
650 dbg("udsl_cancel_send: popping current skb (0x%p)", skb);
651 instance->current_skb = NULL;
652 udsl_pop(vcc, skb);
653 }
654 tasklet_enable(&instance->send_tasklet);
655 dbg("udsl_cancel_send done");
656}
657
658static int udsl_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
659{
660 struct udsl_instance_data *instance = vcc->dev->dev_data;
661 int err;
662
663 vdbg("udsl_atm_send called (skb 0x%p, len %u)", skb, skb->len);
664
665 if (!instance) {
666 dbg("udsl_atm_send: NULL data!");
667 err = -ENODEV;
668 goto fail;
669 }
670
671 if (vcc->qos.aal != ATM_AAL5) {
672 dbg("udsl_atm_send: unsupported ATM type %d!", vcc->qos.aal);
673 err = -EINVAL;
674 goto fail;
675 }
676
677 if (skb->len > ATM_MAX_AAL5_PDU) {
678 dbg("udsl_atm_send: packet too long (%d vs %d)!", skb->len,
679 ATM_MAX_AAL5_PDU);
680 err = -EINVAL;
681 goto fail;
682 }
683
684 PACKETDEBUG(skb->data, skb->len);
685
686 udsl_groom_skb(vcc, skb);
687 skb_queue_tail(&instance->sndqueue, skb);
688 tasklet_schedule(&instance->send_tasklet);
689
690 return 0;
691
692 fail:
693 udsl_pop(vcc, skb);
694 return err;
695}
696
697/********************
698** bean counting **
699********************/
700
701static void udsl_destroy_instance(struct kref *kref)
702{
703 struct udsl_instance_data *instance =
704 container_of(kref, struct udsl_instance_data, refcount);
705
706 tasklet_kill(&instance->receive_tasklet);
707 tasklet_kill(&instance->send_tasklet);
708 usb_put_dev(instance->usb_dev);
709 kfree(instance);
710}
711
712void udsl_get_instance(struct udsl_instance_data *instance)
713{
714 kref_get(&instance->refcount);
715}
716
717void udsl_put_instance(struct udsl_instance_data *instance)
718{
719 kref_put(&instance->refcount, udsl_destroy_instance);
720}
721
722/**********
723** ATM **
724**********/
725
726static void udsl_atm_dev_close(struct atm_dev *dev)
727{
728 struct udsl_instance_data *instance = dev->dev_data;
729
730 dev->dev_data = NULL;
731 udsl_put_instance(instance);
732}
733
734static int udsl_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page)
735{
736 struct udsl_instance_data *instance = atm_dev->dev_data;
737 int left = *pos;
738
739 if (!instance) {
740 dbg("udsl_atm_proc_read: NULL instance!");
741 return -ENODEV;
742 }
743
744 if (!left--)
745 return sprintf(page, "%s\n", instance->description);
746
747 if (!left--)
748 return sprintf(page, "MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
749 atm_dev->esi[0], atm_dev->esi[1],
750 atm_dev->esi[2], atm_dev->esi[3],
751 atm_dev->esi[4], atm_dev->esi[5]);
752
753 if (!left--)
754 return sprintf(page,
755 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
756 atomic_read(&atm_dev->stats.aal5.tx),
757 atomic_read(&atm_dev->stats.aal5.tx_err),
758 atomic_read(&atm_dev->stats.aal5.rx),
759 atomic_read(&atm_dev->stats.aal5.rx_err),
760 atomic_read(&atm_dev->stats.aal5.rx_drop));
761
762 if (!left--) {
763 switch (atm_dev->signal) {
764 case ATM_PHY_SIG_FOUND:
765 sprintf(page, "Line up");
766 break;
767 case ATM_PHY_SIG_LOST:
768 sprintf(page, "Line down");
769 break;
770 default:
771 sprintf(page, "Line state unknown");
772 break;
773 }
774
775 if (instance->usb_dev->state == USB_STATE_NOTATTACHED)
776 strcat(page, ", disconnected\n");
777 else {
778 if (instance->status == UDSL_LOADED_FIRMWARE)
779 strcat(page, ", firmware loaded\n");
780 else if (instance->status == UDSL_LOADING_FIRMWARE)
781 strcat(page, ", firmware loading\n");
782 else
783 strcat(page, ", no firmware\n");
784 }
785
786 return strlen(page);
787 }
788
789 return 0;
790}
791
792static int udsl_atm_open(struct atm_vcc *vcc)
793{
794 struct udsl_instance_data *instance = vcc->dev->dev_data;
795 struct udsl_vcc_data *new;
796 unsigned int max_pdu;
797 int vci = vcc->vci;
798 short vpi = vcc->vpi;
799 int err;
800
801 dbg("udsl_atm_open: vpi %hd, vci %d", vpi, vci);
802
803 if (!instance) {
804 dbg("udsl_atm_open: NULL data!");
805 return -ENODEV;
806 }
807
808 /* only support AAL5 */
809 if ((vcc->qos.aal != ATM_AAL5) || (vcc->qos.rxtp.max_sdu < 0)
810 || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) {
811 dbg("udsl_atm_open: unsupported ATM type %d!", vcc->qos.aal);
812 return -EINVAL;
813 }
814
815 if (instance->firmware_wait &&
816 (err = instance->firmware_wait(instance)) < 0) {
817 dbg("udsl_atm_open: firmware not loaded (%d)!", err);
818 return err;
819 }
820
821 down(&instance->serialize); /* vs self, udsl_atm_close */
822
823 if (udsl_find_vcc(instance, vpi, vci)) {
824 dbg("udsl_atm_open: %hd/%d already in use!", vpi, vci);
825 up(&instance->serialize);
826 return -EADDRINUSE;
827 }
828
829 if (!(new = kmalloc(sizeof(struct udsl_vcc_data), GFP_KERNEL))) {
830 dbg("udsl_atm_open: no memory for vcc_data!");
831 up(&instance->serialize);
832 return -ENOMEM;
833 }
834
835 memset(new, 0, sizeof(struct udsl_vcc_data));
836 new->vcc = vcc;
837 new->vpi = vpi;
838 new->vci = vci;
839
840 /* udsl_extract_cells requires at least one cell */
841 max_pdu = max(1, UDSL_NUM_CELLS(vcc->qos.rxtp.max_sdu)) * ATM_CELL_PAYLOAD;
842 if (!(new->sarb = alloc_skb(max_pdu, GFP_KERNEL))) {
843 dbg("udsl_atm_open: no memory for SAR buffer!");
844 kfree(new);
845 up(&instance->serialize);
846 return -ENOMEM;
847 }
848
849 vcc->dev_data = new;
850
851 tasklet_disable(&instance->receive_tasklet);
852 list_add(&new->list, &instance->vcc_list);
853 tasklet_enable(&instance->receive_tasklet);
854
855 set_bit(ATM_VF_ADDR, &vcc->flags);
856 set_bit(ATM_VF_PARTIAL, &vcc->flags);
857 set_bit(ATM_VF_READY, &vcc->flags);
858
859 up(&instance->serialize);
860
861 tasklet_schedule(&instance->receive_tasklet);
862
863 dbg("udsl_atm_open: allocated vcc data 0x%p (max_pdu: %u)", new, max_pdu);
864
865 return 0;
866}
867
868static void udsl_atm_close(struct atm_vcc *vcc)
869{
870 struct udsl_instance_data *instance = vcc->dev->dev_data;
871 struct udsl_vcc_data *vcc_data = vcc->dev_data;
872
873 dbg("udsl_atm_close called");
874
875 if (!instance || !vcc_data) {
876 dbg("udsl_atm_close: NULL data!");
877 return;
878 }
879
880 dbg("udsl_atm_close: deallocating vcc 0x%p with vpi %d vci %d",
881 vcc_data, vcc_data->vpi, vcc_data->vci);
882
883 udsl_cancel_send(instance, vcc);
884
885 down(&instance->serialize); /* vs self, udsl_atm_open */
886
887 tasklet_disable(&instance->receive_tasklet);
888 list_del(&vcc_data->list);
889 tasklet_enable(&instance->receive_tasklet);
890
891 kfree_skb(vcc_data->sarb);
892 vcc_data->sarb = NULL;
893
894 kfree(vcc_data);
895 vcc->dev_data = NULL;
896
897 vcc->vpi = ATM_VPI_UNSPEC;
898 vcc->vci = ATM_VCI_UNSPEC;
899 clear_bit(ATM_VF_READY, &vcc->flags);
900 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
901 clear_bit(ATM_VF_ADDR, &vcc->flags);
902
903 up(&instance->serialize);
904
905 dbg("udsl_atm_close successful");
906}
907
908static int udsl_atm_ioctl(struct atm_dev *dev, unsigned int cmd,
909 void __user * arg)
910{
911 switch (cmd) {
912 case ATM_QUERYLOOP:
913 return put_user(ATM_LM_NONE, (int __user *)arg) ? -EFAULT : 0;
914 default:
915 return -ENOIOCTLCMD;
916 }
917}
918
919/**********
920** USB **
921**********/
922
923int udsl_instance_setup(struct usb_device *dev,
924 struct udsl_instance_data *instance)
925{
926 char *buf;
927 int i, length;
928
929 kref_init(&instance->refcount); /* one for USB */
930 udsl_get_instance(instance); /* one for ATM */
931
932 init_MUTEX(&instance->serialize);
933
934 instance->usb_dev = dev;
935
936 INIT_LIST_HEAD(&instance->vcc_list);
937
938 instance->status = UDSL_NO_FIRMWARE;
939 init_waitqueue_head(&instance->firmware_waiters);
940
941 spin_lock_init(&instance->receive_lock);
942 INIT_LIST_HEAD(&instance->spare_receivers);
943 INIT_LIST_HEAD(&instance->filled_receive_buffers);
944
945 tasklet_init(&instance->receive_tasklet, udsl_process_receive, (unsigned long)instance);
946 INIT_LIST_HEAD(&instance->spare_receive_buffers);
947
948 skb_queue_head_init(&instance->sndqueue);
949
950 spin_lock_init(&instance->send_lock);
951 INIT_LIST_HEAD(&instance->spare_senders);
952 INIT_LIST_HEAD(&instance->spare_send_buffers);
953
954 tasklet_init(&instance->send_tasklet, udsl_process_send,
955 (unsigned long)instance);
956 INIT_LIST_HEAD(&instance->filled_send_buffers);
957
958 /* receive init */
959 for (i = 0; i < num_rcv_urbs; i++) {
960 struct udsl_receiver *rcv = &(instance->receivers[i]);
961
962 if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) {
963 dbg("udsl_usb_probe: no memory for receive urb %d!", i);
964 goto fail;
965 }
966
967 rcv->instance = instance;
968
969 list_add(&rcv->list, &instance->spare_receivers);
970 }
971
972 for (i = 0; i < num_rcv_bufs; i++) {
973 struct udsl_receive_buffer *buf =
974 &(instance->receive_buffers[i]);
975
976 buf->base = kmalloc(rcv_buf_size * (ATM_CELL_SIZE + instance->rcv_padding),
977 GFP_KERNEL);
978 if (!buf->base) {
979 dbg("udsl_usb_probe: no memory for receive buffer %d!", i);
980 goto fail;
981 }
982
983 list_add(&buf->list, &instance->spare_receive_buffers);
984 }
985
986 /* send init */
987 for (i = 0; i < num_snd_urbs; i++) {
988 struct udsl_sender *snd = &(instance->senders[i]);
989
990 if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) {
991 dbg("udsl_usb_probe: no memory for send urb %d!", i);
992 goto fail;
993 }
994
995 snd->instance = instance;
996
997 list_add(&snd->list, &instance->spare_senders);
998 }
999
1000 for (i = 0; i < num_snd_bufs; i++) {
1001 struct udsl_send_buffer *buf = &(instance->send_buffers[i]);
1002
1003 buf->base = kmalloc(snd_buf_size * (ATM_CELL_SIZE + instance->snd_padding),
1004 GFP_KERNEL);
1005 if (!buf->base) {
1006 dbg("udsl_usb_probe: no memory for send buffer %d!", i);
1007 goto fail;
1008 }
1009
1010 list_add(&buf->list, &instance->spare_send_buffers);
1011 }
1012
1013 /* ATM init */
1014 instance->atm_dev = atm_dev_register(instance->driver_name,
1015 &udsl_atm_devops, -1, NULL);
1016 if (!instance->atm_dev) {
1017 dbg("udsl_usb_probe: failed to register ATM device!");
1018 goto fail;
1019 }
1020
1021 instance->atm_dev->ci_range.vpi_bits = ATM_CI_MAX;
1022 instance->atm_dev->ci_range.vci_bits = ATM_CI_MAX;
1023 instance->atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
1024
1025 /* temp init ATM device, set to 128kbit */
1026 instance->atm_dev->link_rate = 128 * 1000 / 424;
1027
1028 /* device description */
1029 buf = instance->description;
1030 length = sizeof(instance->description);
1031
1032 if ((i = usb_string(dev, dev->descriptor.iProduct, buf, length)) < 0)
1033 goto finish;
1034
1035 buf += i;
1036 length -= i;
1037
1038 i = scnprintf(buf, length, " (");
1039 buf += i;
1040 length -= i;
1041
1042 if (length <= 0 || (i = usb_make_path(dev, buf, length)) < 0)
1043 goto finish;
1044
1045 buf += i;
1046 length -= i;
1047
1048 snprintf(buf, length, ")");
1049
1050 finish:
1051 /* ready for ATM callbacks */
1052 wmb();
1053 instance->atm_dev->dev_data = instance;
1054
1055 usb_get_dev(dev);
1056
1057 return 0;
1058
1059 fail:
1060 for (i = 0; i < num_snd_bufs; i++)
1061 kfree(instance->send_buffers[i].base);
1062
1063 for (i = 0; i < num_snd_urbs; i++)
1064 usb_free_urb(instance->senders[i].urb);
1065
1066 for (i = 0; i < num_rcv_bufs; i++)
1067 kfree(instance->receive_buffers[i].base);
1068
1069 for (i = 0; i < num_rcv_urbs; i++)
1070 usb_free_urb(instance->receivers[i].urb);
1071
1072 return -ENOMEM;
1073}
1074
1075void udsl_instance_disconnect(struct udsl_instance_data *instance)
1076{
1077 int i;
1078
1079 dbg("udsl_instance_disconnect entered");
1080
1081 if (!instance) {
1082 dbg("udsl_instance_disconnect: NULL instance!");
1083 return;
1084 }
1085
1086 /* receive finalize */
1087 tasklet_disable(&instance->receive_tasklet);
1088
1089 for (i = 0; i < num_rcv_urbs; i++)
1090 usb_kill_urb(instance->receivers[i].urb);
1091
1092 /* no need to take the spinlock */
1093 INIT_LIST_HEAD(&instance->filled_receive_buffers);
1094 INIT_LIST_HEAD(&instance->spare_receive_buffers);
1095
1096 tasklet_enable(&instance->receive_tasklet);
1097
1098 for (i = 0; i < num_rcv_urbs; i++)
1099 usb_free_urb(instance->receivers[i].urb);
1100
1101 for (i = 0; i < num_rcv_bufs; i++)
1102 kfree(instance->receive_buffers[i].base);
1103
1104 /* send finalize */
1105 tasklet_disable(&instance->send_tasklet);
1106
1107 for (i = 0; i < num_snd_urbs; i++)
1108 usb_kill_urb(instance->senders[i].urb);
1109
1110 /* no need to take the spinlock */
1111 INIT_LIST_HEAD(&instance->spare_senders);
1112 INIT_LIST_HEAD(&instance->spare_send_buffers);
1113 instance->current_buffer = NULL;
1114
1115 tasklet_enable(&instance->send_tasklet);
1116
1117 for (i = 0; i < num_snd_urbs; i++)
1118 usb_free_urb(instance->senders[i].urb);
1119
1120 for (i = 0; i < num_snd_bufs; i++)
1121 kfree(instance->send_buffers[i].base);
1122
1123 /* ATM finalize */
1124 shutdown_atm_dev(instance->atm_dev);
1125}
1126
1127EXPORT_SYMBOL_GPL(udsl_get_instance);
1128EXPORT_SYMBOL_GPL(udsl_put_instance);
1129EXPORT_SYMBOL_GPL(udsl_instance_setup);
1130EXPORT_SYMBOL_GPL(udsl_instance_disconnect);
1131
1132/***********
1133** init **
1134***********/
1135
1136static int __init udsl_usb_init(void)
1137{
1138 dbg("udsl_usb_init: driver version " DRIVER_VERSION);
1139
1140 if (sizeof(struct udsl_control) > sizeof(((struct sk_buff *) 0)->cb)) {
1141 printk(KERN_ERR __FILE__ ": unusable with this kernel!\n");
1142 return -EIO;
1143 }
1144
1145 if ((num_rcv_urbs > UDSL_MAX_RCV_URBS)
1146 || (num_snd_urbs > UDSL_MAX_SND_URBS)
1147 || (num_rcv_bufs > UDSL_MAX_RCV_BUFS)
1148 || (num_snd_bufs > UDSL_MAX_SND_BUFS)
1149 || (rcv_buf_size > UDSL_MAX_RCV_BUF_SIZE)
1150 || (snd_buf_size > UDSL_MAX_SND_BUF_SIZE))
1151 return -EINVAL;
1152
1153 return 0;
1154}
1155
1156static void __exit udsl_usb_exit(void)
1157{
1158}
1159
1160module_init(udsl_usb_init);
1161module_exit(udsl_usb_exit);
1162
1163MODULE_AUTHOR(DRIVER_AUTHOR);
1164MODULE_DESCRIPTION(DRIVER_DESC);
1165MODULE_LICENSE("GPL");
1166MODULE_VERSION(DRIVER_VERSION);
1167
1168/************
1169** debug **
1170************/
1171
1172#ifdef VERBOSE_DEBUG
1173static int udsl_print_packet(const unsigned char *data, int len)
1174{
1175 unsigned char buffer[256];
1176 int i = 0, j = 0;
1177
1178 for (i = 0; i < len;) {
1179 buffer[0] = '\0';
1180 sprintf(buffer, "%.3d :", i);
1181 for (j = 0; (j < 16) && (i < len); j++, i++) {
1182 sprintf(buffer, "%s %2.2x", buffer, data[i]);
1183 }
1184 dbg("%s", buffer);
1185 }
1186 return i;
1187}
1188#endif
diff --git a/drivers/usb/atm/usb_atm.h b/drivers/usb/atm/usb_atm.h
deleted file mode 100644
index cf8c53283530..000000000000
--- a/drivers/usb/atm/usb_atm.h
+++ /dev/null
@@ -1,176 +0,0 @@
1/******************************************************************************
2 * usb_atm.h - Generic USB xDSL driver core
3 *
4 * Copyright (C) 2001, Alcatel
5 * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
6 * Copyright (C) 2004, David Woodhouse
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 ******************************************************************************/
23
24#include <linux/config.h>
25#include <linux/list.h>
26#include <linux/kref.h>
27#include <linux/atm.h>
28#include <linux/atmdev.h>
29#include <asm/semaphore.h>
30
31/*
32#define DEBUG
33#define VERBOSE_DEBUG
34*/
35
36#if !defined (DEBUG) && defined (CONFIG_USB_DEBUG)
37# define DEBUG
38#endif
39
40#include <linux/usb.h>
41
42#ifdef DEBUG
43#define UDSL_ASSERT(x) BUG_ON(!(x))
44#else
45#define UDSL_ASSERT(x) do { if (!(x)) warn("failed assertion '" #x "' at line %d", __LINE__); } while(0)
46#endif
47
48#define UDSL_MAX_RCV_URBS 4
49#define UDSL_MAX_SND_URBS 4
50#define UDSL_MAX_RCV_BUFS 8
51#define UDSL_MAX_SND_BUFS 8
52#define UDSL_MAX_RCV_BUF_SIZE 1024 /* ATM cells */
53#define UDSL_MAX_SND_BUF_SIZE 1024 /* ATM cells */
54#define UDSL_DEFAULT_RCV_URBS 2
55#define UDSL_DEFAULT_SND_URBS 2
56#define UDSL_DEFAULT_RCV_BUFS 4
57#define UDSL_DEFAULT_SND_BUFS 4
58#define UDSL_DEFAULT_RCV_BUF_SIZE 64 /* ATM cells */
59#define UDSL_DEFAULT_SND_BUF_SIZE 64 /* ATM cells */
60
61#define ATM_CELL_HEADER (ATM_CELL_SIZE - ATM_CELL_PAYLOAD)
62#define UDSL_NUM_CELLS(x) (((x) + ATM_AAL5_TRAILER + ATM_CELL_PAYLOAD - 1) / ATM_CELL_PAYLOAD)
63
64/* receive */
65
66struct udsl_receive_buffer {
67 struct list_head list;
68 unsigned char *base;
69 unsigned int filled_cells;
70};
71
72struct udsl_receiver {
73 struct list_head list;
74 struct udsl_receive_buffer *buffer;
75 struct urb *urb;
76 struct udsl_instance_data *instance;
77};
78
79struct udsl_vcc_data {
80 /* vpi/vci lookup */
81 struct list_head list;
82 short vpi;
83 int vci;
84 struct atm_vcc *vcc;
85
86 /* raw cell reassembly */
87 struct sk_buff *sarb;
88};
89
90/* send */
91
92struct udsl_send_buffer {
93 struct list_head list;
94 unsigned char *base;
95 unsigned char *free_start;
96 unsigned int free_cells;
97};
98
99struct udsl_sender {
100 struct list_head list;
101 struct udsl_send_buffer *buffer;
102 struct urb *urb;
103 struct udsl_instance_data *instance;
104};
105
106struct udsl_control {
107 struct atm_skb_data atm_data;
108 unsigned int num_cells;
109 unsigned int num_entire;
110 unsigned int pdu_padding;
111 unsigned char aal5_trailer[ATM_AAL5_TRAILER];
112};
113
114#define UDSL_SKB(x) ((struct udsl_control *)(x)->cb)
115
116/* main driver data */
117
118enum udsl_status {
119 UDSL_NO_FIRMWARE,
120 UDSL_LOADING_FIRMWARE,
121 UDSL_LOADED_FIRMWARE
122};
123
124struct udsl_instance_data {
125 struct kref refcount;
126 struct semaphore serialize;
127
128 /* USB device part */
129 struct usb_device *usb_dev;
130 char description[64];
131 int data_endpoint;
132 int snd_padding;
133 int rcv_padding;
134 const char *driver_name;
135
136 /* ATM device part */
137 struct atm_dev *atm_dev;
138 struct list_head vcc_list;
139
140 /* firmware */
141 int (*firmware_wait) (struct udsl_instance_data *);
142 enum udsl_status status;
143 wait_queue_head_t firmware_waiters;
144
145 /* receive */
146 struct udsl_receiver receivers[UDSL_MAX_RCV_URBS];
147 struct udsl_receive_buffer receive_buffers[UDSL_MAX_RCV_BUFS];
148
149 spinlock_t receive_lock;
150 struct list_head spare_receivers;
151 struct list_head filled_receive_buffers;
152
153 struct tasklet_struct receive_tasklet;
154 struct list_head spare_receive_buffers;
155
156 /* send */
157 struct udsl_sender senders[UDSL_MAX_SND_URBS];
158 struct udsl_send_buffer send_buffers[UDSL_MAX_SND_BUFS];
159
160 struct sk_buff_head sndqueue;
161
162 spinlock_t send_lock;
163 struct list_head spare_senders;
164 struct list_head spare_send_buffers;
165
166 struct tasklet_struct send_tasklet;
167 struct sk_buff *current_skb; /* being emptied */
168 struct udsl_send_buffer *current_buffer; /* being filled */
169 struct list_head filled_send_buffers;
170};
171
172extern int udsl_instance_setup(struct usb_device *dev,
173 struct udsl_instance_data *instance);
174extern void udsl_instance_disconnect(struct udsl_instance_data *instance);
175extern void udsl_get_instance(struct udsl_instance_data *instance);
176extern void udsl_put_instance(struct udsl_instance_data *instance);
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
new file mode 100644
index 000000000000..bb1db1959854
--- /dev/null
+++ b/drivers/usb/atm/usbatm.c
@@ -0,0 +1,1230 @@
1/******************************************************************************
2 * usbatm.c - Generic USB xDSL driver core
3 *
4 * Copyright (C) 2001, Alcatel
5 * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
6 * Copyright (C) 2004, David Woodhouse, Roman Kagan
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 ******************************************************************************/
23
24/*
25 * Written by Johan Verrept, Duncan Sands (duncan.sands@free.fr) and David Woodhouse
26 *
27 * 1.7+: - See the check-in logs
28 *
29 * 1.6: - No longer opens a connection if the firmware is not loaded
30 * - Added support for the speedtouch 330
31 * - Removed the limit on the number of devices
32 * - Module now autoloads on device plugin
33 * - Merged relevant parts of sarlib
34 * - Replaced the kernel thread with a tasklet
35 * - New packet transmission code
36 * - Changed proc file contents
37 * - Fixed all known SMP races
38 * - Many fixes and cleanups
39 * - Various fixes by Oliver Neukum (oliver@neukum.name)
40 *
41 * 1.5A: - Version for inclusion in 2.5 series kernel
42 * - Modifications by Richard Purdie (rpurdie@rpsys.net)
43 * - made compatible with kernel 2.5.6 onwards by changing
44 * usbatm_usb_send_data_context->urb to a pointer and adding code
45 * to alloc and free it
46 * - remove_wait_queue() added to usbatm_atm_processqueue_thread()
47 *
48 * 1.5: - fixed memory leak when atmsar_decode_aal5 returned NULL.
49 * (reported by stephen.robinson@zen.co.uk)
50 *
51 * 1.4: - changed the spin_lock() under interrupt to spin_lock_irqsave()
52 * - unlink all active send urbs of a vcc that is being closed.
53 *
54 * 1.3.1: - added the version number
55 *
56 * 1.3: - Added multiple send urb support
57 * - fixed memory leak and vcc->tx_inuse starvation bug
58 * when not enough memory left in vcc.
59 *
60 * 1.2: - Fixed race condition in usbatm_usb_send_data()
61 * 1.1: - Turned off packet debugging
62 *
63 */
64
65#include "usbatm.h"
66
67#include <asm/uaccess.h>
68#include <linux/crc32.h>
69#include <linux/errno.h>
70#include <linux/init.h>
71#include <linux/interrupt.h>
72#include <linux/kernel.h>
73#include <linux/module.h>
74#include <linux/moduleparam.h>
75#include <linux/proc_fs.h>
76#include <linux/sched.h>
77#include <linux/signal.h>
78#include <linux/slab.h>
79#include <linux/smp_lock.h>
80#include <linux/stat.h>
81#include <linux/timer.h>
82#include <linux/wait.h>
83
84#ifdef VERBOSE_DEBUG
85static int usbatm_print_packet(const unsigned char *data, int len);
86#define PACKETDEBUG(arg...) usbatm_print_packet (arg)
87#define vdbg(arg...) dbg (arg)
88#else
89#define PACKETDEBUG(arg...)
90#define vdbg(arg...)
91#endif
92
93#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
94#define DRIVER_VERSION "1.9"
95#define DRIVER_DESC "Generic USB ATM/DSL I/O, version " DRIVER_VERSION
96
97static const char usbatm_driver_name[] = "usbatm";
98
99#define UDSL_MAX_RCV_URBS 16
100#define UDSL_MAX_SND_URBS 16
101#define UDSL_MAX_RCV_BUF_SIZE 1024 /* ATM cells */
102#define UDSL_MAX_SND_BUF_SIZE 1024 /* ATM cells */
103#define UDSL_DEFAULT_RCV_URBS 4
104#define UDSL_DEFAULT_SND_URBS 4
105#define UDSL_DEFAULT_RCV_BUF_SIZE 64 /* ATM cells */
106#define UDSL_DEFAULT_SND_BUF_SIZE 64 /* ATM cells */
107
108#define ATM_CELL_HEADER (ATM_CELL_SIZE - ATM_CELL_PAYLOAD)
109
110#define THROTTLE_MSECS 100 /* delay to recover processing after urb submission fails */
111
112static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS;
113static unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS;
114static unsigned int rcv_buf_size = UDSL_DEFAULT_RCV_BUF_SIZE;
115static unsigned int snd_buf_size = UDSL_DEFAULT_SND_BUF_SIZE;
116
117module_param(num_rcv_urbs, uint, S_IRUGO);
118MODULE_PARM_DESC(num_rcv_urbs,
119 "Number of urbs used for reception (range: 0-"
120 __MODULE_STRING(UDSL_MAX_RCV_URBS) ", default: "
121 __MODULE_STRING(UDSL_DEFAULT_RCV_URBS) ")");
122
123module_param(num_snd_urbs, uint, S_IRUGO);
124MODULE_PARM_DESC(num_snd_urbs,
125 "Number of urbs used for transmission (range: 0-"
126 __MODULE_STRING(UDSL_MAX_SND_URBS) ", default: "
127 __MODULE_STRING(UDSL_DEFAULT_SND_URBS) ")");
128
129module_param(rcv_buf_size, uint, S_IRUGO);
130MODULE_PARM_DESC(rcv_buf_size,
131 "Size of the buffers used for reception in ATM cells (range: 1-"
132 __MODULE_STRING(UDSL_MAX_RCV_BUF_SIZE) ", default: "
133 __MODULE_STRING(UDSL_DEFAULT_RCV_BUF_SIZE) ")");
134
135module_param(snd_buf_size, uint, S_IRUGO);
136MODULE_PARM_DESC(snd_buf_size,
137 "Size of the buffers used for transmission in ATM cells (range: 1-"
138 __MODULE_STRING(UDSL_MAX_SND_BUF_SIZE) ", default: "
139 __MODULE_STRING(UDSL_DEFAULT_SND_BUF_SIZE) ")");
140
141
142/* receive */
143
144struct usbatm_vcc_data {
145 /* vpi/vci lookup */
146 struct list_head list;
147 short vpi;
148 int vci;
149 struct atm_vcc *vcc;
150
151 /* raw cell reassembly */
152 struct sk_buff *sarb;
153};
154
155
156/* send */
157
158struct usbatm_control {
159 struct atm_skb_data atm;
160 u32 len;
161 u32 crc;
162};
163
164#define UDSL_SKB(x) ((struct usbatm_control *)(x)->cb)
165
166
167/* ATM */
168
169static void usbatm_atm_dev_close(struct atm_dev *dev);
170static int usbatm_atm_open(struct atm_vcc *vcc);
171static void usbatm_atm_close(struct atm_vcc *vcc);
172static int usbatm_atm_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg);
173static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb);
174static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page);
175
176static struct atmdev_ops usbatm_atm_devops = {
177 .dev_close = usbatm_atm_dev_close,
178 .open = usbatm_atm_open,
179 .close = usbatm_atm_close,
180 .ioctl = usbatm_atm_ioctl,
181 .send = usbatm_atm_send,
182 .proc_read = usbatm_atm_proc_read,
183 .owner = THIS_MODULE,
184};
185
186
187/***********
188** misc **
189***********/
190
191static inline unsigned int usbatm_pdu_length(unsigned int length)
192{
193 length += ATM_CELL_PAYLOAD - 1 + ATM_AAL5_TRAILER;
194 return length - length % ATM_CELL_PAYLOAD;
195}
196
197static inline void usbatm_pop(struct atm_vcc *vcc, struct sk_buff *skb)
198{
199 if (vcc->pop)
200 vcc->pop(vcc, skb);
201 else
202 dev_kfree_skb(skb);
203}
204
205
206/***********
207** urbs **
208************/
209
210static inline struct urb *usbatm_pop_urb(struct usbatm_channel *channel)
211{
212 struct urb *urb;
213
214 spin_lock_irq(&channel->lock);
215 if (list_empty(&channel->list)) {
216 spin_unlock_irq(&channel->lock);
217 return NULL;
218 }
219
220 urb = list_entry(channel->list.next, struct urb, urb_list);
221 list_del(&urb->urb_list);
222 spin_unlock_irq(&channel->lock);
223
224 return urb;
225}
226
227static inline int usbatm_submit_urb(struct urb *urb)
228{
229 struct usbatm_channel *channel = urb->context;
230 int ret;
231
232 vdbg("%s: submitting urb 0x%p, size %u",
233 __func__, urb, urb->transfer_buffer_length);
234
235 ret = usb_submit_urb(urb, GFP_ATOMIC);
236 if (ret) {
237 atm_dbg(channel->usbatm, "%s: urb 0x%p submission failed (%d)!\n",
238 __func__, urb, ret);
239
240 /* consider all errors transient and return the buffer back to the queue */
241 urb->status = -EAGAIN;
242 spin_lock_irq(&channel->lock);
243
244 /* must add to the front when sending; doesn't matter when receiving */
245 list_add(&urb->urb_list, &channel->list);
246
247 spin_unlock_irq(&channel->lock);
248
249 /* make sure the channel doesn't stall */
250 mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS));
251 }
252
253 return ret;
254}
255
256static void usbatm_complete(struct urb *urb, struct pt_regs *regs)
257{
258 struct usbatm_channel *channel = urb->context;
259 unsigned long flags;
260
261 vdbg("%s: urb 0x%p, status %d, actual_length %d",
262 __func__, urb, urb->status, urb->actual_length);
263
264 /* usually in_interrupt(), but not always */
265 spin_lock_irqsave(&channel->lock, flags);
266
267 /* must add to the back when receiving; doesn't matter when sending */
268 list_add_tail(&urb->urb_list, &channel->list);
269
270 spin_unlock_irqrestore(&channel->lock, flags);
271
272 if (unlikely(urb->status))
273 /* throttle processing in case of an error */
274 mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS));
275 else
276 tasklet_schedule(&channel->tasklet);
277}
278
279
280/*************
281** decode **
282*************/
283
284static inline struct usbatm_vcc_data *usbatm_find_vcc(struct usbatm_data *instance,
285 short vpi, int vci)
286{
287 struct usbatm_vcc_data *vcc;
288
289 list_for_each_entry(vcc, &instance->vcc_list, list)
290 if ((vcc->vci == vci) && (vcc->vpi == vpi))
291 return vcc;
292 return NULL;
293}
294
295static void usbatm_extract_cells(struct usbatm_data *instance,
296 unsigned char *source, unsigned int avail_data)
297{
298 struct usbatm_vcc_data *cached_vcc = NULL;
299 struct atm_vcc *vcc;
300 struct sk_buff *sarb;
301 unsigned int stride = instance->rx_channel.stride;
302 int vci, cached_vci = 0;
303 short vpi, cached_vpi = 0;
304 u8 pti;
305
306 for (; avail_data >= stride; avail_data -= stride, source += stride) {
307 vpi = ((source[0] & 0x0f) << 4) | (source[1] >> 4);
308 vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4);
309 pti = ((source[3] & 0xe) >> 1);
310
311 vdbg("%s: vpi %hd, vci %d, pti %d", __func__, vpi, vci, pti);
312
313 if ((vci != cached_vci) || (vpi != cached_vpi)) {
314 cached_vpi = vpi;
315 cached_vci = vci;
316
317 cached_vcc = usbatm_find_vcc(instance, vpi, vci);
318
319 if (!cached_vcc)
320 atm_dbg(instance, "%s: unknown vpi/vci (%hd/%d)!\n", __func__, vpi, vci);
321 }
322
323 if (!cached_vcc)
324 continue;
325
326 vcc = cached_vcc->vcc;
327
328 /* OAM F5 end-to-end */
329 if (pti == ATM_PTI_E2EF5) {
330 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n", __func__, vpi, vci);
331 atomic_inc(&vcc->stats->rx_err);
332 continue;
333 }
334
335 sarb = cached_vcc->sarb;
336
337 if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) {
338 atm_dbg(instance, "%s: buffer overrun (sarb->len %u, vcc: 0x%p)!\n",
339 __func__, sarb->len, vcc);
340 /* discard cells already received */
341 skb_trim(sarb, 0);
342 UDSL_ASSERT(sarb->tail + ATM_CELL_PAYLOAD <= sarb->end);
343 }
344
345 memcpy(sarb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD);
346 __skb_put(sarb, ATM_CELL_PAYLOAD);
347
348 if (pti & 1) {
349 struct sk_buff *skb;
350 unsigned int length;
351 unsigned int pdu_length;
352
353 length = (source[ATM_CELL_SIZE - 6] << 8) + source[ATM_CELL_SIZE - 5];
354
355 /* guard against overflow */
356 if (length > ATM_MAX_AAL5_PDU) {
357 atm_dbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
358 __func__, length, vcc);
359 atomic_inc(&vcc->stats->rx_err);
360 goto out;
361 }
362
363 pdu_length = usbatm_pdu_length(length);
364
365 if (sarb->len < pdu_length) {
366 atm_dbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
367 __func__, pdu_length, sarb->len, vcc);
368 atomic_inc(&vcc->stats->rx_err);
369 goto out;
370 }
371
372 if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) {
373 atm_dbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
374 __func__, vcc);
375 atomic_inc(&vcc->stats->rx_err);
376 goto out;
377 }
378
379 vdbg("%s: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", __func__, length, pdu_length, vcc);
380
381 if (!(skb = dev_alloc_skb(length))) {
382 atm_dbg(instance, "%s: no memory for skb (length: %u)!\n", __func__, length);
383 atomic_inc(&vcc->stats->rx_drop);
384 goto out;
385 }
386
387 vdbg("%s: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", __func__, skb, skb->truesize);
388
389 if (!atm_charge(vcc, skb->truesize)) {
390 atm_dbg(instance, "%s: failed atm_charge (skb->truesize: %u)!\n", __func__, skb->truesize);
391 dev_kfree_skb(skb);
392 goto out; /* atm_charge increments rx_drop */
393 }
394
395 memcpy(skb->data, sarb->tail - pdu_length, length);
396 __skb_put(skb, length);
397
398 vdbg("%s: sending skb 0x%p, skb->len %u, skb->truesize %u",
399 __func__, skb, skb->len, skb->truesize);
400
401 PACKETDEBUG(skb->data, skb->len);
402
403 vcc->push(vcc, skb);
404
405 atomic_inc(&vcc->stats->rx);
406 out:
407 skb_trim(sarb, 0);
408 }
409 }
410}
411
412
413/*************
414** encode **
415*************/
416
417static unsigned int usbatm_write_cells(struct usbatm_data *instance,
418 struct sk_buff *skb,
419 u8 *target, unsigned int avail_space)
420{
421 struct usbatm_control *ctrl = UDSL_SKB(skb);
422 struct atm_vcc *vcc = ctrl->atm.vcc;
423 unsigned int num_written;
424 unsigned int stride = instance->tx_channel.stride;
425
426 vdbg("%s: skb->len=%d, avail_space=%u", __func__, skb->len, avail_space);
427 UDSL_ASSERT(!(avail_space % stride));
428
429 for (num_written = 0; num_written < avail_space && ctrl->len;
430 num_written += stride, target += stride) {
431 unsigned int data_len = min_t(unsigned int, skb->len, ATM_CELL_PAYLOAD);
432 unsigned int left = ATM_CELL_PAYLOAD - data_len;
433 u8 *ptr = target;
434
435 ptr[0] = vcc->vpi >> 4;
436 ptr[1] = (vcc->vpi << 4) | (vcc->vci >> 12);
437 ptr[2] = vcc->vci >> 4;
438 ptr[3] = vcc->vci << 4;
439 ptr[4] = 0xec;
440 ptr += ATM_CELL_HEADER;
441
442 memcpy(ptr, skb->data, data_len);
443 ptr += data_len;
444 __skb_pull(skb, data_len);
445
446 if(!left)
447 continue;
448
449 memset(ptr, 0, left);
450
451 if (left >= ATM_AAL5_TRAILER) { /* trailer will go in this cell */
452 u8 *trailer = target + ATM_CELL_SIZE - ATM_AAL5_TRAILER;
453 /* trailer[0] = 0; UU = 0 */
454 /* trailer[1] = 0; CPI = 0 */
455 trailer[2] = ctrl->len >> 8;
456 trailer[3] = ctrl->len;
457
458 ctrl->crc = ~ crc32_be(ctrl->crc, ptr, left - 4);
459
460 trailer[4] = ctrl->crc >> 24;
461 trailer[5] = ctrl->crc >> 16;
462 trailer[6] = ctrl->crc >> 8;
463 trailer[7] = ctrl->crc;
464
465 target[3] |= 0x2; /* adjust PTI */
466
467 ctrl->len = 0; /* tag this skb finished */
468 }
469 else
470 ctrl->crc = crc32_be(ctrl->crc, ptr, left);
471 }
472
473 return num_written;
474}
475
476
477/**************
478** receive **
479**************/
480
481static void usbatm_rx_process(unsigned long data)
482{
483 struct usbatm_data *instance = (struct usbatm_data *)data;
484 struct urb *urb;
485
486 while ((urb = usbatm_pop_urb(&instance->rx_channel))) {
487 vdbg("%s: processing urb 0x%p", __func__, urb);
488
489 if (usb_pipeisoc(urb->pipe)) {
490 int i;
491 for (i = 0; i < urb->number_of_packets; i++)
492 if (!urb->iso_frame_desc[i].status)
493 usbatm_extract_cells(instance,
494 (u8 *)urb->transfer_buffer + urb->iso_frame_desc[i].offset,
495 urb->iso_frame_desc[i].actual_length);
496 }
497 else
498 if (!urb->status)
499 usbatm_extract_cells(instance, urb->transfer_buffer, urb->actual_length);
500
501 if (usbatm_submit_urb(urb))
502 return;
503 }
504}
505
506
507/***********
508** send **
509***********/
510
511static void usbatm_tx_process(unsigned long data)
512{
513 struct usbatm_data *instance = (struct usbatm_data *)data;
514 struct sk_buff *skb = instance->current_skb;
515 struct urb *urb = NULL;
516 const unsigned int buf_size = instance->tx_channel.buf_size;
517 unsigned int num_written = 0;
518 u8 *buffer = NULL;
519
520 if (!skb)
521 skb = skb_dequeue(&instance->sndqueue);
522
523 while (skb) {
524 if (!urb) {
525 urb = usbatm_pop_urb(&instance->tx_channel);
526 if (!urb)
527 break; /* no more senders */
528 buffer = urb->transfer_buffer;
529 num_written = (urb->status == -EAGAIN) ?
530 urb->transfer_buffer_length : 0;
531 }
532
533 num_written += usbatm_write_cells(instance, skb,
534 buffer + num_written,
535 buf_size - num_written);
536
537 vdbg("%s: wrote %u bytes from skb 0x%p to urb 0x%p",
538 __func__, num_written, skb, urb);
539
540 if (!UDSL_SKB(skb)->len) {
541 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
542
543 usbatm_pop(vcc, skb);
544 atomic_inc(&vcc->stats->tx);
545
546 skb = skb_dequeue(&instance->sndqueue);
547 }
548
549 if (num_written == buf_size || (!skb && num_written)) {
550 urb->transfer_buffer_length = num_written;
551
552 if (usbatm_submit_urb(urb))
553 break;
554 urb = NULL;
555 }
556 }
557
558 instance->current_skb = skb;
559}
560
561static void usbatm_cancel_send(struct usbatm_data *instance,
562 struct atm_vcc *vcc)
563{
564 struct sk_buff *skb, *n;
565
566 atm_dbg(instance, "%s entered\n", __func__);
567 spin_lock_irq(&instance->sndqueue.lock);
568 for (skb = instance->sndqueue.next, n = skb->next;
569 skb != (struct sk_buff *)&instance->sndqueue;
570 skb = n, n = skb->next)
571 if (UDSL_SKB(skb)->atm.vcc == vcc) {
572 atm_dbg(instance, "%s: popping skb 0x%p\n", __func__, skb);
573 __skb_unlink(skb, &instance->sndqueue);
574 usbatm_pop(vcc, skb);
575 }
576 spin_unlock_irq(&instance->sndqueue.lock);
577
578 tasklet_disable(&instance->tx_channel.tasklet);
579 if ((skb = instance->current_skb) && (UDSL_SKB(skb)->atm.vcc == vcc)) {
580 atm_dbg(instance, "%s: popping current skb (0x%p)\n", __func__, skb);
581 instance->current_skb = NULL;
582 usbatm_pop(vcc, skb);
583 }
584 tasklet_enable(&instance->tx_channel.tasklet);
585 atm_dbg(instance, "%s done\n", __func__);
586}
587
588static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
589{
590 struct usbatm_data *instance = vcc->dev->dev_data;
591 struct usbatm_control *ctrl = UDSL_SKB(skb);
592 int err;
593
594 vdbg("%s called (skb 0x%p, len %u)", __func__, skb, skb->len);
595
596 if (!instance) {
597 dbg("%s: NULL data!", __func__);
598 err = -ENODEV;
599 goto fail;
600 }
601
602 if (vcc->qos.aal != ATM_AAL5) {
603 atm_dbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
604 err = -EINVAL;
605 goto fail;
606 }
607
608 if (skb->len > ATM_MAX_AAL5_PDU) {
609 atm_dbg(instance, "%s: packet too long (%d vs %d)!\n",
610 __func__, skb->len, ATM_MAX_AAL5_PDU);
611 err = -EINVAL;
612 goto fail;
613 }
614
615 PACKETDEBUG(skb->data, skb->len);
616
617 /* initialize the control block */
618 ctrl->atm.vcc = vcc;
619 ctrl->len = skb->len;
620 ctrl->crc = crc32_be(~0, skb->data, skb->len);
621
622 skb_queue_tail(&instance->sndqueue, skb);
623 tasklet_schedule(&instance->tx_channel.tasklet);
624
625 return 0;
626
627 fail:
628 usbatm_pop(vcc, skb);
629 return err;
630}
631
632
633/********************
634** bean counting **
635********************/
636
637static void usbatm_destroy_instance(struct kref *kref)
638{
639 struct usbatm_data *instance = container_of(kref, struct usbatm_data, refcount);
640
641 dbg("%s", __func__);
642
643 tasklet_kill(&instance->rx_channel.tasklet);
644 tasklet_kill(&instance->tx_channel.tasklet);
645 usb_put_dev(instance->usb_dev);
646 kfree(instance);
647}
648
649void usbatm_get_instance(struct usbatm_data *instance)
650{
651 dbg("%s", __func__);
652
653 kref_get(&instance->refcount);
654}
655
656void usbatm_put_instance(struct usbatm_data *instance)
657{
658 dbg("%s", __func__);
659
660 kref_put(&instance->refcount, usbatm_destroy_instance);
661}
662
663
664/**********
665** ATM **
666**********/
667
668static void usbatm_atm_dev_close(struct atm_dev *dev)
669{
670 struct usbatm_data *instance = dev->dev_data;
671
672 dbg("%s", __func__);
673
674 if (!instance)
675 return;
676
677 dev->dev_data = NULL;
678 usbatm_put_instance(instance); /* taken in usbatm_atm_init */
679}
680
681static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page)
682{
683 struct usbatm_data *instance = atm_dev->dev_data;
684 int left = *pos;
685
686 if (!instance) {
687 dbg("%s: NULL instance!", __func__);
688 return -ENODEV;
689 }
690
691 if (!left--)
692 return sprintf(page, "%s\n", instance->description);
693
694 if (!left--)
695 return sprintf(page, "MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
696 atm_dev->esi[0], atm_dev->esi[1],
697 atm_dev->esi[2], atm_dev->esi[3],
698 atm_dev->esi[4], atm_dev->esi[5]);
699
700 if (!left--)
701 return sprintf(page,
702 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
703 atomic_read(&atm_dev->stats.aal5.tx),
704 atomic_read(&atm_dev->stats.aal5.tx_err),
705 atomic_read(&atm_dev->stats.aal5.rx),
706 atomic_read(&atm_dev->stats.aal5.rx_err),
707 atomic_read(&atm_dev->stats.aal5.rx_drop));
708
709 if (!left--)
710 switch (atm_dev->signal) {
711 case ATM_PHY_SIG_FOUND:
712 return sprintf(page, "Line up\n");
713 case ATM_PHY_SIG_LOST:
714 return sprintf(page, "Line down\n");
715 default:
716 return sprintf(page, "Line state unknown\n");
717 }
718
719 return 0;
720}
721
722static int usbatm_atm_open(struct atm_vcc *vcc)
723{
724 struct usbatm_data *instance = vcc->dev->dev_data;
725 struct usbatm_vcc_data *new = NULL;
726 int ret;
727 int vci = vcc->vci;
728 short vpi = vcc->vpi;
729
730 if (!instance) {
731 dbg("%s: NULL data!", __func__);
732 return -ENODEV;
733 }
734
735 atm_dbg(instance, "%s: vpi %hd, vci %d\n", __func__, vpi, vci);
736
737 /* only support AAL5 */
738 if ((vcc->qos.aal != ATM_AAL5) || (vcc->qos.rxtp.max_sdu < 0)
739 || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) {
740 atm_dbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
741 return -EINVAL;
742 }
743
744 down(&instance->serialize); /* vs self, usbatm_atm_close */
745
746 if (usbatm_find_vcc(instance, vpi, vci)) {
747 atm_dbg(instance, "%s: %hd/%d already in use!\n", __func__, vpi, vci);
748 ret = -EADDRINUSE;
749 goto fail;
750 }
751
752 if (!(new = kmalloc(sizeof(struct usbatm_vcc_data), GFP_KERNEL))) {
753 atm_dbg(instance, "%s: no memory for vcc_data!\n", __func__);
754 ret = -ENOMEM;
755 goto fail;
756 }
757
758 memset(new, 0, sizeof(struct usbatm_vcc_data));
759 new->vcc = vcc;
760 new->vpi = vpi;
761 new->vci = vci;
762
763 new->sarb = alloc_skb(usbatm_pdu_length(vcc->qos.rxtp.max_sdu), GFP_KERNEL);
764 if (!new->sarb) {
765 atm_dbg(instance, "%s: no memory for SAR buffer!\n", __func__);
766 ret = -ENOMEM;
767 goto fail;
768 }
769
770 vcc->dev_data = new;
771
772 tasklet_disable(&instance->rx_channel.tasklet);
773 list_add(&new->list, &instance->vcc_list);
774 tasklet_enable(&instance->rx_channel.tasklet);
775
776 set_bit(ATM_VF_ADDR, &vcc->flags);
777 set_bit(ATM_VF_PARTIAL, &vcc->flags);
778 set_bit(ATM_VF_READY, &vcc->flags);
779
780 up(&instance->serialize);
781
782 atm_dbg(instance, "%s: allocated vcc data 0x%p\n", __func__, new);
783
784 return 0;
785
786fail:
787 kfree(new);
788 up(&instance->serialize);
789 return ret;
790}
791
792static void usbatm_atm_close(struct atm_vcc *vcc)
793{
794 struct usbatm_data *instance = vcc->dev->dev_data;
795 struct usbatm_vcc_data *vcc_data = vcc->dev_data;
796
797 if (!instance || !vcc_data) {
798 dbg("%s: NULL data!", __func__);
799 return;
800 }
801
802 atm_dbg(instance, "%s entered\n", __func__);
803
804 atm_dbg(instance, "%s: deallocating vcc 0x%p with vpi %d vci %d\n",
805 __func__, vcc_data, vcc_data->vpi, vcc_data->vci);
806
807 usbatm_cancel_send(instance, vcc);
808
809 down(&instance->serialize); /* vs self, usbatm_atm_open */
810
811 tasklet_disable(&instance->rx_channel.tasklet);
812 list_del(&vcc_data->list);
813 tasklet_enable(&instance->rx_channel.tasklet);
814
815 kfree_skb(vcc_data->sarb);
816 vcc_data->sarb = NULL;
817
818 kfree(vcc_data);
819 vcc->dev_data = NULL;
820
821 vcc->vpi = ATM_VPI_UNSPEC;
822 vcc->vci = ATM_VCI_UNSPEC;
823 clear_bit(ATM_VF_READY, &vcc->flags);
824 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
825 clear_bit(ATM_VF_ADDR, &vcc->flags);
826
827 up(&instance->serialize);
828
829 atm_dbg(instance, "%s successful\n", __func__);
830}
831
832static int usbatm_atm_ioctl(struct atm_dev *dev, unsigned int cmd,
833 void __user * arg)
834{
835 switch (cmd) {
836 case ATM_QUERYLOOP:
837 return put_user(ATM_LM_NONE, (int __user *)arg) ? -EFAULT : 0;
838 default:
839 return -ENOIOCTLCMD;
840 }
841}
842
843static int usbatm_atm_init(struct usbatm_data *instance)
844{
845 struct atm_dev *atm_dev;
846 int ret, i;
847
848 /* ATM init */
849 atm_dev = atm_dev_register(instance->driver_name, &usbatm_atm_devops, -1, NULL);
850 if (!atm_dev) {
851 usb_dbg(instance, "%s: failed to register ATM device!\n", __func__);
852 return -1;
853 }
854
855 instance->atm_dev = atm_dev;
856
857 atm_dev->ci_range.vpi_bits = ATM_CI_MAX;
858 atm_dev->ci_range.vci_bits = ATM_CI_MAX;
859 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
860
861 /* temp init ATM device, set to 128kbit */
862 atm_dev->link_rate = 128 * 1000 / 424;
863
864 if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) {
865 atm_dbg(instance, "%s: atm_start failed: %d!\n", __func__, ret);
866 goto fail;
867 }
868
869 /* ready for ATM callbacks */
870 usbatm_get_instance(instance); /* dropped in usbatm_atm_dev_close */
871 mb();
872 atm_dev->dev_data = instance;
873
874 /* submit all rx URBs */
875 for (i = 0; i < num_rcv_urbs; i++)
876 usbatm_submit_urb(instance->urbs[i]);
877
878 return 0;
879
880 fail:
881 instance->atm_dev = NULL;
882 shutdown_atm_dev(atm_dev); /* usbatm_atm_dev_close will eventually be called */
883 return ret;
884}
885
886
887/**********
888** USB **
889**********/
890
891static int usbatm_do_heavy_init(void *arg)
892{
893 struct usbatm_data *instance = arg;
894 int ret;
895
896 daemonize(instance->driver->driver_name);
897 allow_signal(SIGTERM);
898
899 complete(&instance->thread_started);
900
901 ret = instance->driver->heavy_init(instance, instance->usb_intf);
902
903 if (!ret)
904 ret = usbatm_atm_init(instance);
905
906 down(&instance->serialize);
907 instance->thread_pid = -1;
908 up(&instance->serialize);
909
910 complete_and_exit(&instance->thread_exited, ret);
911}
912
913static int usbatm_heavy_init(struct usbatm_data *instance)
914{
915 int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_KERNEL);
916
917 if (ret < 0) {
918 usb_dbg(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret);
919 return ret;
920 }
921
922 down(&instance->serialize);
923 instance->thread_pid = ret;
924 up(&instance->serialize);
925
926 wait_for_completion(&instance->thread_started);
927
928 return 0;
929}
930
931static void usbatm_tasklet_schedule(unsigned long data)
932{
933 tasklet_schedule((struct tasklet_struct *) data);
934}
935
936static inline void usbatm_init_channel(struct usbatm_channel *channel)
937{
938 spin_lock_init(&channel->lock);
939 INIT_LIST_HEAD(&channel->list);
940 channel->delay.function = usbatm_tasklet_schedule;
941 channel->delay.data = (unsigned long) &channel->tasklet;
942 init_timer(&channel->delay);
943}
944
945int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
946 struct usbatm_driver *driver)
947{
948 struct device *dev = &intf->dev;
949 struct usb_device *usb_dev = interface_to_usbdev(intf);
950 struct usbatm_data *instance;
951 char *buf;
952 int error = -ENOMEM;
953 int i, length;
954 int need_heavy;
955
956 dev_dbg(dev, "%s: trying driver %s with vendor=0x%x, product=0x%x, ifnum %d\n",
957 __func__, driver->driver_name,
958 le16_to_cpu(usb_dev->descriptor.idVendor),
959 le16_to_cpu(usb_dev->descriptor.idProduct),
960 intf->altsetting->desc.bInterfaceNumber);
961
962 /* instance init */
963 instance = kcalloc(1, sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL);
964 if (!instance) {
965 dev_dbg(dev, "%s: no memory for instance data!\n", __func__);
966 return -ENOMEM;
967 }
968
969 /* public fields */
970
971 instance->driver = driver;
972 snprintf(instance->driver_name, sizeof(instance->driver_name), driver->driver_name);
973
974 instance->usb_dev = usb_dev;
975 instance->usb_intf = intf;
976
977 buf = instance->description;
978 length = sizeof(instance->description);
979
980 if ((i = usb_string(usb_dev, usb_dev->descriptor.iProduct, buf, length)) < 0)
981 goto bind;
982
983 buf += i;
984 length -= i;
985
986 i = scnprintf(buf, length, " (");
987 buf += i;
988 length -= i;
989
990 if (length <= 0 || (i = usb_make_path(usb_dev, buf, length)) < 0)
991 goto bind;
992
993 buf += i;
994 length -= i;
995
996 snprintf(buf, length, ")");
997
998 bind:
999 need_heavy = 1;
1000 if (driver->bind && (error = driver->bind(instance, intf, id, &need_heavy)) < 0) {
1001 dev_dbg(dev, "%s: bind failed: %d!\n", __func__, error);
1002 goto fail_free;
1003 }
1004
1005 /* private fields */
1006
1007 kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */
1008 init_MUTEX(&instance->serialize);
1009
1010 instance->thread_pid = -1;
1011 init_completion(&instance->thread_started);
1012 init_completion(&instance->thread_exited);
1013
1014 INIT_LIST_HEAD(&instance->vcc_list);
1015
1016 usbatm_init_channel(&instance->rx_channel);
1017 usbatm_init_channel(&instance->tx_channel);
1018 tasklet_init(&instance->rx_channel.tasklet, usbatm_rx_process, (unsigned long)instance);
1019 tasklet_init(&instance->tx_channel.tasklet, usbatm_tx_process, (unsigned long)instance);
1020 instance->rx_channel.endpoint = usb_rcvbulkpipe(usb_dev, driver->in);
1021 instance->tx_channel.endpoint = usb_sndbulkpipe(usb_dev, driver->out);
1022 instance->rx_channel.stride = ATM_CELL_SIZE + driver->rx_padding;
1023 instance->tx_channel.stride = ATM_CELL_SIZE + driver->tx_padding;
1024 instance->rx_channel.buf_size = rcv_buf_size * instance->rx_channel.stride;
1025 instance->tx_channel.buf_size = snd_buf_size * instance->tx_channel.stride;
1026 instance->rx_channel.usbatm = instance->tx_channel.usbatm = instance;
1027
1028 skb_queue_head_init(&instance->sndqueue);
1029
1030 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
1031 struct urb *urb;
1032 u8 *buffer;
1033 unsigned int iso_packets = 0, iso_size = 0;
1034 struct usbatm_channel *channel = i < num_rcv_urbs ?
1035 &instance->rx_channel : &instance->tx_channel;
1036
1037 if (usb_pipeisoc(channel->endpoint)) {
1038 /* don't expect iso out endpoints */
1039 iso_size = usb_maxpacket(instance->usb_dev, channel->endpoint, 0);
1040 iso_size -= iso_size % channel->stride; /* alignment */
1041 BUG_ON(!iso_size);
1042 iso_packets = (channel->buf_size - 1) / iso_size + 1;
1043 }
1044
1045 urb = usb_alloc_urb(iso_packets, GFP_KERNEL);
1046 if (!urb) {
1047 dev_dbg(dev, "%s: no memory for urb %d!\n", __func__, i);
1048 goto fail_unbind;
1049 }
1050
1051 instance->urbs[i] = urb;
1052
1053 buffer = kmalloc(channel->buf_size, GFP_KERNEL);
1054 if (!buffer) {
1055 dev_dbg(dev, "%s: no memory for buffer %d!\n", __func__, i);
1056 goto fail_unbind;
1057 }
1058 memset(buffer, 0, channel->buf_size);
1059
1060 usb_fill_bulk_urb(urb, instance->usb_dev, channel->endpoint,
1061 buffer, channel->buf_size, usbatm_complete, channel);
1062 if (iso_packets) {
1063 int j;
1064 urb->interval = 1;
1065 urb->transfer_flags = URB_ISO_ASAP;
1066 urb->number_of_packets = iso_packets;
1067 for (j = 0; j < iso_packets; j++) {
1068 urb->iso_frame_desc[j].offset = iso_size * j;
1069 urb->iso_frame_desc[j].length = min_t(int, iso_size,
1070 channel->buf_size - urb->iso_frame_desc[j].offset);
1071 }
1072 }
1073
1074 /* put all tx URBs on the list of spares */
1075 if (i >= num_rcv_urbs)
1076 list_add_tail(&urb->urb_list, &channel->list);
1077
1078 vdbg("%s: alloced buffer 0x%p buf size %u urb 0x%p",
1079 __func__, urb->transfer_buffer, urb->transfer_buffer_length, urb);
1080 }
1081
1082 if (need_heavy && driver->heavy_init) {
1083 error = usbatm_heavy_init(instance);
1084 } else {
1085 complete(&instance->thread_exited); /* pretend that heavy_init was run */
1086 error = usbatm_atm_init(instance);
1087 }
1088
1089 if (error < 0)
1090 goto fail_unbind;
1091
1092 usb_get_dev(usb_dev);
1093 usb_set_intfdata(intf, instance);
1094
1095 return 0;
1096
1097 fail_unbind:
1098 if (instance->driver->unbind)
1099 instance->driver->unbind(instance, intf);
1100 fail_free:
1101 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
1102 if (instance->urbs[i])
1103 kfree(instance->urbs[i]->transfer_buffer);
1104 usb_free_urb(instance->urbs[i]);
1105 }
1106
1107 kfree (instance);
1108
1109 return error;
1110}
1111EXPORT_SYMBOL_GPL(usbatm_usb_probe);
1112
1113void usbatm_usb_disconnect(struct usb_interface *intf)
1114{
1115 struct device *dev = &intf->dev;
1116 struct usbatm_data *instance = usb_get_intfdata(intf);
1117 int i;
1118
1119 dev_dbg(dev, "%s entered\n", __func__);
1120
1121 if (!instance) {
1122 dev_dbg(dev, "%s: NULL instance!\n", __func__);
1123 return;
1124 }
1125
1126 usb_set_intfdata(intf, NULL);
1127
1128 down(&instance->serialize);
1129 if (instance->thread_pid >= 0)
1130 kill_proc(instance->thread_pid, SIGTERM, 1);
1131 up(&instance->serialize);
1132
1133 wait_for_completion(&instance->thread_exited);
1134
1135 tasklet_disable(&instance->rx_channel.tasklet);
1136 tasklet_disable(&instance->tx_channel.tasklet);
1137
1138 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++)
1139 usb_kill_urb(instance->urbs[i]);
1140
1141 del_timer_sync(&instance->rx_channel.delay);
1142 del_timer_sync(&instance->tx_channel.delay);
1143
1144 if (instance->atm_dev && instance->driver->atm_stop)
1145 instance->driver->atm_stop(instance, instance->atm_dev);
1146
1147 if (instance->driver->unbind)
1148 instance->driver->unbind(instance, intf);
1149
1150 instance->driver_data = NULL;
1151
1152 /* turn usbatm_[rt]x_process into noop */
1153 /* no need to take the spinlock */
1154 INIT_LIST_HEAD(&instance->rx_channel.list);
1155 INIT_LIST_HEAD(&instance->tx_channel.list);
1156
1157 tasklet_enable(&instance->rx_channel.tasklet);
1158 tasklet_enable(&instance->tx_channel.tasklet);
1159
1160 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
1161 kfree(instance->urbs[i]->transfer_buffer);
1162 usb_free_urb(instance->urbs[i]);
1163 }
1164
1165 /* ATM finalize */
1166 if (instance->atm_dev)
1167 shutdown_atm_dev(instance->atm_dev);
1168
1169 usbatm_put_instance(instance); /* taken in usbatm_usb_probe */
1170}
1171EXPORT_SYMBOL_GPL(usbatm_usb_disconnect);
1172
1173
1174/***********
1175** init **
1176***********/
1177
1178static int __init usbatm_usb_init(void)
1179{
1180 dbg("%s: driver version %s", __func__, DRIVER_VERSION);
1181
1182 if (sizeof(struct usbatm_control) > sizeof(((struct sk_buff *) 0)->cb)) {
1183 printk(KERN_ERR "%s unusable with this kernel!\n", usbatm_driver_name);
1184 return -EIO;
1185 }
1186
1187 if ((num_rcv_urbs > UDSL_MAX_RCV_URBS)
1188 || (num_snd_urbs > UDSL_MAX_SND_URBS)
1189 || (rcv_buf_size < 1)
1190 || (rcv_buf_size > UDSL_MAX_RCV_BUF_SIZE)
1191 || (snd_buf_size < 1)
1192 || (snd_buf_size > UDSL_MAX_SND_BUF_SIZE))
1193 return -EINVAL;
1194
1195 return 0;
1196}
1197module_init(usbatm_usb_init);
1198
1199static void __exit usbatm_usb_exit(void)
1200{
1201 dbg("%s", __func__);
1202}
1203module_exit(usbatm_usb_exit);
1204
1205MODULE_AUTHOR(DRIVER_AUTHOR);
1206MODULE_DESCRIPTION(DRIVER_DESC);
1207MODULE_LICENSE("GPL");
1208MODULE_VERSION(DRIVER_VERSION);
1209
1210/************
1211** debug **
1212************/
1213
1214#ifdef VERBOSE_DEBUG
1215static int usbatm_print_packet(const unsigned char *data, int len)
1216{
1217 unsigned char buffer[256];
1218 int i = 0, j = 0;
1219
1220 for (i = 0; i < len;) {
1221 buffer[0] = '\0';
1222 sprintf(buffer, "%.3d :", i);
1223 for (j = 0; (j < 16) && (i < len); j++, i++) {
1224 sprintf(buffer, "%s %2.2x", buffer, data[i]);
1225 }
1226 dbg("%s", buffer);
1227 }
1228 return i;
1229}
1230#endif
diff --git a/drivers/usb/atm/usbatm.h b/drivers/usb/atm/usbatm.h
new file mode 100644
index 000000000000..936646457935
--- /dev/null
+++ b/drivers/usb/atm/usbatm.h
@@ -0,0 +1,184 @@
1/******************************************************************************
2 * usbatm.h - Generic USB xDSL driver core
3 *
4 * Copyright (C) 2001, Alcatel
5 * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
6 * Copyright (C) 2004, David Woodhouse
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 ******************************************************************************/
23
24#ifndef _USBATM_H_
25#define _USBATM_H_
26
27#include <linux/config.h>
28
29/*
30#define DEBUG
31#define VERBOSE_DEBUG
32*/
33
34#if !defined (DEBUG) && defined (CONFIG_USB_DEBUG)
35# define DEBUG
36#endif
37
38#include <asm/semaphore.h>
39#include <linux/atm.h>
40#include <linux/atmdev.h>
41#include <linux/completion.h>
42#include <linux/device.h>
43#include <linux/kref.h>
44#include <linux/list.h>
45#include <linux/stringify.h>
46#include <linux/usb.h>
47
48#ifdef DEBUG
49#define UDSL_ASSERT(x) BUG_ON(!(x))
50#else
51#define UDSL_ASSERT(x) do { if (!(x)) warn("failed assertion '%s' at line %d", __stringify(x), __LINE__); } while(0)
52#endif
53
54#define usb_err(instance, format, arg...) \
55 dev_err(&(instance)->usb_intf->dev , format , ## arg)
56#define usb_info(instance, format, arg...) \
57 dev_info(&(instance)->usb_intf->dev , format , ## arg)
58#define usb_warn(instance, format, arg...) \
59 dev_warn(&(instance)->usb_intf->dev , format , ## arg)
60#define usb_dbg(instance, format, arg...) \
61 dev_dbg(&(instance)->usb_intf->dev , format , ## arg)
62
63/* FIXME: move to dev_* once ATM is driver model aware */
64#define atm_printk(level, instance, format, arg...) \
65 printk(level "ATM dev %d: " format , \
66 (instance)->atm_dev->number , ## arg)
67
68#define atm_err(instance, format, arg...) \
69 atm_printk(KERN_ERR, instance , format , ## arg)
70#define atm_info(instance, format, arg...) \
71 atm_printk(KERN_INFO, instance , format , ## arg)
72#define atm_warn(instance, format, arg...) \
73 atm_printk(KERN_WARNING, instance , format , ## arg)
74#ifdef DEBUG
75#define atm_dbg(instance, format, arg...) \
76 atm_printk(KERN_DEBUG, instance , format , ## arg)
77#else
78#define atm_dbg(instance, format, arg...) \
79 do {} while (0)
80#endif
81
82
83/* mini driver */
84
85struct usbatm_data;
86
87/*
88* Assuming all methods exist and succeed, they are called in this order:
89*
90* bind, heavy_init, atm_start, ..., atm_stop, unbind
91*/
92
93struct usbatm_driver {
94 struct module *owner;
95
96 const char *driver_name;
97
98 /*
99 * init device ... can sleep, or cause probe() failure. Drivers with a heavy_init
100 * method can avoid having it called by setting need_heavy_init to zero.
101 */
102 int (*bind) (struct usbatm_data *, struct usb_interface *,
103 const struct usb_device_id *id, int *need_heavy_init);
104
105 /* additional device initialization that is too slow to be done in probe() */
106 int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
107
108 /* cleanup device ... can sleep, but can't fail */
109 void (*unbind) (struct usbatm_data *, struct usb_interface *);
110
111 /* init ATM device ... can sleep, or cause ATM initialization failure */
112 int (*atm_start) (struct usbatm_data *, struct atm_dev *);
113
114 /* cleanup ATM device ... can sleep, but can't fail */
115 void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
116
117 int in; /* rx endpoint */
118 int out; /* tx endpoint */
119
120 unsigned rx_padding;
121 unsigned tx_padding;
122};
123
124extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
125 struct usbatm_driver *driver);
126extern void usbatm_usb_disconnect(struct usb_interface *intf);
127
128
129struct usbatm_channel {
130 int endpoint; /* usb pipe */
131 unsigned int stride; /* ATM cell size + padding */
132 unsigned int buf_size; /* urb buffer size */
133 spinlock_t lock;
134 struct list_head list;
135 struct tasklet_struct tasklet;
136 struct timer_list delay;
137 struct usbatm_data *usbatm;
138};
139
140/* main driver data */
141
142struct usbatm_data {
143 /******************
144 * public fields *
145 ******************/
146
147 /* mini driver */
148 struct usbatm_driver *driver;
149 void *driver_data;
150 char driver_name[16];
151
152 /* USB device */
153 struct usb_device *usb_dev;
154 struct usb_interface *usb_intf;
155 char description[64];
156
157 /* ATM device */
158 struct atm_dev *atm_dev;
159
160 /********************************
161 * private fields - do not use *
162 ********************************/
163
164 struct kref refcount;
165 struct semaphore serialize;
166
167 /* heavy init */
168 int thread_pid;
169 struct completion thread_started;
170 struct completion thread_exited;
171
172 /* ATM device */
173 struct list_head vcc_list;
174
175 struct usbatm_channel rx_channel;
176 struct usbatm_channel tx_channel;
177
178 struct sk_buff_head sndqueue;
179 struct sk_buff *current_skb; /* being emptied */
180
181 struct urb *urbs[0];
182};
183
184#endif /* _USBATM_H_ */
diff --git a/drivers/usb/atm/xusbatm.c b/drivers/usb/atm/xusbatm.c
new file mode 100644
index 000000000000..7fe7fb484d10
--- /dev/null
+++ b/drivers/usb/atm/xusbatm.c
@@ -0,0 +1,196 @@
1/******************************************************************************
2 * xusbatm.c - dumb usbatm-based driver for modems initialized in userspace
3 *
4 * Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru)
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
20 ******************************************************************************/
21
22#include <linux/module.h>
23#include <linux/netdevice.h> /* FIXME: required by linux/etherdevice.h */
24#include <linux/etherdevice.h> /* for random_ether_addr() */
25
26#include "usbatm.h"
27
28
29#define XUSBATM_DRIVERS_MAX 8
30
31#define XUSBATM_PARM(name, type, parmtype, desc) \
32 static type name[XUSBATM_DRIVERS_MAX]; \
33 static int num_##name; \
34 module_param_array(name, parmtype, &num_##name, 0444); \
35 MODULE_PARM_DESC(name, desc)
36
37XUSBATM_PARM(vendor, unsigned short, ushort, "USB device vendor");
38XUSBATM_PARM(product, unsigned short, ushort, "USB device product");
39
40XUSBATM_PARM(rx_endpoint, unsigned char, byte, "rx endpoint number");
41XUSBATM_PARM(tx_endpoint, unsigned char, byte, "tx endpoint number");
42XUSBATM_PARM(rx_padding, unsigned char, byte, "rx padding (default 0)");
43XUSBATM_PARM(tx_padding, unsigned char, byte, "tx padding (default 0)");
44
45static const char xusbatm_driver_name[] = "xusbatm";
46
47static struct usbatm_driver xusbatm_drivers[XUSBATM_DRIVERS_MAX];
48static struct usb_device_id xusbatm_usb_ids[XUSBATM_DRIVERS_MAX + 1];
49static struct usb_driver xusbatm_usb_driver;
50
51static int usb_intf_has_ep(const struct usb_interface *intf, u8 ep)
52{
53 int i, j;
54
55 for (i = 0; i < intf->num_altsetting; i++) {
56 struct usb_host_interface *alt = intf->altsetting;
57 for (j = 0; j < alt->desc.bNumEndpoints; j++)
58 if ((alt->endpoint[i].desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) == ep)
59 return 1;
60 }
61 return 0;
62}
63
64static int xusbatm_bind(struct usbatm_data *usbatm_instance,
65 struct usb_interface *intf, const struct usb_device_id *id,
66 int *need_heavy_init)
67{
68 struct usb_device *usb_dev = interface_to_usbdev(intf);
69 int drv_ix = id - xusbatm_usb_ids;
70 int rx_ep_present = usb_intf_has_ep(intf, rx_endpoint[drv_ix]);
71 int tx_ep_present = usb_intf_has_ep(intf, tx_endpoint[drv_ix]);
72 u8 searched_ep = rx_ep_present ? tx_endpoint[drv_ix] : rx_endpoint[drv_ix];
73 int i, ret;
74
75 usb_dbg(usbatm_instance, "%s: binding driver %d: vendor %#x product %#x"
76 " rx: ep %#x padd %d tx: ep %#x padd %d\n",
77 __func__, drv_ix, vendor[drv_ix], product[drv_ix],
78 rx_endpoint[drv_ix], rx_padding[drv_ix],
79 tx_endpoint[drv_ix], tx_padding[drv_ix]);
80
81 if (!rx_ep_present && !tx_ep_present) {
82 usb_dbg(usbatm_instance, "%s: intf #%d has neither rx (%#x) nor tx (%#x) endpoint\n",
83 __func__, intf->altsetting->desc.bInterfaceNumber,
84 rx_endpoint[drv_ix], tx_endpoint[drv_ix]);
85 return -ENODEV;
86 }
87
88 if (rx_ep_present && tx_ep_present)
89 return 0;
90
91 for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) {
92 struct usb_interface *cur_if = usb_dev->actconfig->interface[i];
93
94 if (cur_if != intf && usb_intf_has_ep(cur_if, searched_ep)) {
95 ret = usb_driver_claim_interface(&xusbatm_usb_driver,
96 cur_if, usbatm_instance);
97 if (!ret)
98 usb_err(usbatm_instance, "%s: failed to claim interface #%d (%d)\n",
99 __func__, cur_if->altsetting->desc.bInterfaceNumber, ret);
100 return ret;
101 }
102 }
103
104 usb_err(usbatm_instance, "%s: no interface has endpoint %#x\n",
105 __func__, searched_ep);
106 return -ENODEV;
107}
108
109static void xusbatm_unbind(struct usbatm_data *usbatm_instance,
110 struct usb_interface *intf)
111{
112 struct usb_device *usb_dev = interface_to_usbdev(intf);
113 int i;
114 usb_dbg(usbatm_instance, "%s entered\n", __func__);
115
116 for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) {
117 struct usb_interface *cur_if = usb_dev->actconfig->interface[i];
118 usb_set_intfdata(cur_if, NULL);
119 usb_driver_release_interface(&xusbatm_usb_driver, cur_if);
120 }
121}
122
123static int xusbatm_atm_start(struct usbatm_data *usbatm_instance,
124 struct atm_dev *atm_dev)
125{
126 atm_dbg(usbatm_instance, "%s entered\n", __func__);
127
128 /* use random MAC as we've no way to get it from the device */
129 random_ether_addr(atm_dev->esi);
130
131 return 0;
132}
133
134
135static int xusbatm_usb_probe(struct usb_interface *intf,
136 const struct usb_device_id *id)
137{
138 return usbatm_usb_probe(intf, id,
139 xusbatm_drivers + (id - xusbatm_usb_ids));
140}
141
142static struct usb_driver xusbatm_usb_driver = {
143 .owner = THIS_MODULE,
144 .name = xusbatm_driver_name,
145 .probe = xusbatm_usb_probe,
146 .disconnect = usbatm_usb_disconnect,
147 .id_table = xusbatm_usb_ids
148};
149
150static int __init xusbatm_init(void)
151{
152 int i;
153
154 dbg("xusbatm_init");
155
156 if (!num_vendor ||
157 num_vendor != num_product ||
158 num_vendor != num_rx_endpoint ||
159 num_vendor != num_tx_endpoint) {
160 warn("malformed module parameters");
161 return -EINVAL;
162 }
163
164 for (i = 0; i < num_vendor; i++) {
165 xusbatm_usb_ids[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
166 xusbatm_usb_ids[i].idVendor = vendor[i];
167 xusbatm_usb_ids[i].idProduct = product[i];
168
169
170 xusbatm_drivers[i].owner = THIS_MODULE;
171 xusbatm_drivers[i].driver_name = xusbatm_driver_name;
172 xusbatm_drivers[i].bind = xusbatm_bind;
173 xusbatm_drivers[i].unbind = xusbatm_unbind;
174 xusbatm_drivers[i].atm_start = xusbatm_atm_start;
175 xusbatm_drivers[i].in = rx_endpoint[i];
176 xusbatm_drivers[i].out = tx_endpoint[i];
177 xusbatm_drivers[i].rx_padding = rx_padding[i];
178 xusbatm_drivers[i].tx_padding = tx_padding[i];
179 }
180
181 return usb_register(&xusbatm_usb_driver);
182}
183module_init(xusbatm_init);
184
185static void __exit xusbatm_exit(void)
186{
187 dbg("xusbatm_exit entered");
188
189 usb_deregister(&xusbatm_usb_driver);
190}
191module_exit(xusbatm_exit);
192
193MODULE_AUTHOR("Roman Kagan, Duncan Sands");
194MODULE_DESCRIPTION("Driver for USB ADSL modems initialized in userspace");
195MODULE_LICENSE("GPL");
196MODULE_VERSION("0.1");
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 6d1f9b6aecff..69e859e0f51d 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -106,6 +106,111 @@ static int acm_ctrl_msg(struct acm *acm, int request, int value, void *buf, int
106 acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0) 106 acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0)
107 107
108/* 108/*
109 * Write buffer management.
110 * All of these assume proper locks taken by the caller.
111 */
112
113static int acm_wb_alloc(struct acm *acm)
114{
115 int i, wbn;
116 struct acm_wb *wb;
117
118 wbn = acm->write_current;
119 i = 0;
120 for (;;) {
121 wb = &acm->wb[wbn];
122 if (!wb->use) {
123 wb->use = 1;
124 return wbn;
125 }
126 wbn = (wbn + 1) % ACM_NWB;
127 if (++i >= ACM_NWB)
128 return -1;
129 }
130}
131
132static void acm_wb_free(struct acm *acm, int wbn)
133{
134 acm->wb[wbn].use = 0;
135}
136
137static int acm_wb_is_avail(struct acm *acm)
138{
139 int i, n;
140
141 n = 0;
142 for (i = 0; i < ACM_NWB; i++) {
143 if (!acm->wb[i].use)
144 n++;
145 }
146 return n;
147}
148
149static inline int acm_wb_is_used(struct acm *acm, int wbn)
150{
151 return acm->wb[wbn].use;
152}
153
154/*
155 * Finish write.
156 */
157static void acm_write_done(struct acm *acm)
158{
159 unsigned long flags;
160 int wbn;
161
162 spin_lock_irqsave(&acm->write_lock, flags);
163 acm->write_ready = 1;
164 wbn = acm->write_current;
165 acm_wb_free(acm, wbn);
166 acm->write_current = (wbn + 1) % ACM_NWB;
167 spin_unlock_irqrestore(&acm->write_lock, flags);
168}
169
170/*
171 * Poke write.
172 */
173static int acm_write_start(struct acm *acm)
174{
175 unsigned long flags;
176 int wbn;
177 struct acm_wb *wb;
178 int rc;
179
180 spin_lock_irqsave(&acm->write_lock, flags);
181 if (!acm->dev) {
182 spin_unlock_irqrestore(&acm->write_lock, flags);
183 return -ENODEV;
184 }
185
186 if (!acm->write_ready) {
187 spin_unlock_irqrestore(&acm->write_lock, flags);
188 return 0; /* A white lie */
189 }
190
191 wbn = acm->write_current;
192 if (!acm_wb_is_used(acm, wbn)) {
193 spin_unlock_irqrestore(&acm->write_lock, flags);
194 return 0;
195 }
196 wb = &acm->wb[wbn];
197
198 acm->write_ready = 0;
199 spin_unlock_irqrestore(&acm->write_lock, flags);
200
201 acm->writeurb->transfer_buffer = wb->buf;
202 acm->writeurb->transfer_dma = wb->dmah;
203 acm->writeurb->transfer_buffer_length = wb->len;
204 acm->writeurb->dev = acm->dev;
205
206 if ((rc = usb_submit_urb(acm->writeurb, GFP_ATOMIC)) < 0) {
207 dbg("usb_submit_urb(write bulk) failed: %d", rc);
208 acm_write_done(acm);
209 }
210 return rc;
211}
212
213/*
109 * Interrupt handlers for various ACM device responses 214 * Interrupt handlers for various ACM device responses
110 */ 215 */
111 216
@@ -237,17 +342,13 @@ static void acm_rx_tasklet(unsigned long _acm)
237static void acm_write_bulk(struct urb *urb, struct pt_regs *regs) 342static void acm_write_bulk(struct urb *urb, struct pt_regs *regs)
238{ 343{
239 struct acm *acm = (struct acm *)urb->context; 344 struct acm *acm = (struct acm *)urb->context;
240 dbg("Entering acm_write_bulk with status %d\n", urb->status);
241
242 if (!ACM_READY(acm))
243 goto out;
244 345
245 if (urb->status) 346 dbg("Entering acm_write_bulk with status %d\n", urb->status);
246 dbg("nonzero write bulk status received: %d", urb->status);
247 347
248 schedule_work(&acm->work); 348 acm_write_done(acm);
249out: 349 acm_write_start(acm);
250 acm->ready_for_write = 1; 350 if (ACM_READY(acm))
351 schedule_work(&acm->work);
251} 352}
252 353
253static void acm_softint(void *private) 354static void acm_softint(void *private)
@@ -351,32 +452,33 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c
351{ 452{
352 struct acm *acm = tty->driver_data; 453 struct acm *acm = tty->driver_data;
353 int stat; 454 int stat;
455 unsigned long flags;
456 int wbn;
457 struct acm_wb *wb;
458
354 dbg("Entering acm_tty_write to write %d bytes,\n", count); 459 dbg("Entering acm_tty_write to write %d bytes,\n", count);
355 460
356 if (!ACM_READY(acm)) 461 if (!ACM_READY(acm))
357 return -EINVAL; 462 return -EINVAL;
358 if (!acm->ready_for_write)
359 return 0;
360 if (!count) 463 if (!count)
361 return 0; 464 return 0;
362 465
363 count = (count > acm->writesize) ? acm->writesize : count; 466 spin_lock_irqsave(&acm->write_lock, flags);
467 if ((wbn = acm_wb_alloc(acm)) < 0) {
468 spin_unlock_irqrestore(&acm->write_lock, flags);
469 acm_write_start(acm);
470 return 0;
471 }
472 wb = &acm->wb[wbn];
364 473
474 count = (count > acm->writesize) ? acm->writesize : count;
365 dbg("Get %d bytes...", count); 475 dbg("Get %d bytes...", count);
366 memcpy(acm->write_buffer, buf, count); 476 memcpy(wb->buf, buf, count);
367 dbg(" Successfully copied.\n"); 477 wb->len = count;
478 spin_unlock_irqrestore(&acm->write_lock, flags);
368 479
369 acm->writeurb->transfer_buffer_length = count; 480 if ((stat = acm_write_start(acm)) < 0)
370 acm->writeurb->dev = acm->dev;
371
372 acm->ready_for_write = 0;
373 stat = usb_submit_urb(acm->writeurb, GFP_ATOMIC);
374 if (stat < 0) {
375 dbg("usb_submit_urb(write bulk) failed");
376 acm->ready_for_write = 1;
377 return stat; 481 return stat;
378 }
379
380 return count; 482 return count;
381} 483}
382 484
@@ -385,7 +487,11 @@ static int acm_tty_write_room(struct tty_struct *tty)
385 struct acm *acm = tty->driver_data; 487 struct acm *acm = tty->driver_data;
386 if (!ACM_READY(acm)) 488 if (!ACM_READY(acm))
387 return -EINVAL; 489 return -EINVAL;
388 return !acm->ready_for_write ? 0 : acm->writesize; 490 /*
491 * Do not let the line discipline to know that we have a reserve,
492 * or it might get too enthusiastic.
493 */
494 return (acm->write_ready && acm_wb_is_avail(acm)) ? acm->writesize : 0;
389} 495}
390 496
391static int acm_tty_chars_in_buffer(struct tty_struct *tty) 497static int acm_tty_chars_in_buffer(struct tty_struct *tty)
@@ -393,7 +499,10 @@ static int acm_tty_chars_in_buffer(struct tty_struct *tty)
393 struct acm *acm = tty->driver_data; 499 struct acm *acm = tty->driver_data;
394 if (!ACM_READY(acm)) 500 if (!ACM_READY(acm))
395 return -EINVAL; 501 return -EINVAL;
396 return !acm->ready_for_write ? acm->writeurb->transfer_buffer_length : 0; 502 /*
503 * This is inaccurate (overcounts), but it works.
504 */
505 return (ACM_NWB - acm_wb_is_avail(acm)) * acm->writesize;
397} 506}
398 507
399static void acm_tty_throttle(struct tty_struct *tty) 508static void acm_tty_throttle(struct tty_struct *tty)
@@ -526,6 +635,39 @@ static void acm_tty_set_termios(struct tty_struct *tty, struct termios *termios_
526 * USB probe and disconnect routines. 635 * USB probe and disconnect routines.
527 */ 636 */
528 637
638/* Little helper: write buffers free */
639static void acm_write_buffers_free(struct acm *acm)
640{
641 int i;
642 struct acm_wb *wb;
643
644 for (wb = &acm->wb[0], i = 0; i < ACM_NWB; i++, wb++) {
645 usb_buffer_free(acm->dev, acm->writesize, wb->buf, wb->dmah);
646 }
647}
648
649/* Little helper: write buffers allocate */
650static int acm_write_buffers_alloc(struct acm *acm)
651{
652 int i;
653 struct acm_wb *wb;
654
655 for (wb = &acm->wb[0], i = 0; i < ACM_NWB; i++, wb++) {
656 wb->buf = usb_buffer_alloc(acm->dev, acm->writesize, GFP_KERNEL,
657 &wb->dmah);
658 if (!wb->buf) {
659 while (i != 0) {
660 --i;
661 --wb;
662 usb_buffer_free(acm->dev, acm->writesize,
663 wb->buf, wb->dmah);
664 }
665 return -ENOMEM;
666 }
667 }
668 return 0;
669}
670
529static int acm_probe (struct usb_interface *intf, 671static int acm_probe (struct usb_interface *intf,
530 const struct usb_device_id *id) 672 const struct usb_device_id *id)
531{ 673{
@@ -700,7 +842,8 @@ skip_normal_probe:
700 acm->bh.data = (unsigned long) acm; 842 acm->bh.data = (unsigned long) acm;
701 INIT_WORK(&acm->work, acm_softint, acm); 843 INIT_WORK(&acm->work, acm_softint, acm);
702 spin_lock_init(&acm->throttle_lock); 844 spin_lock_init(&acm->throttle_lock);
703 acm->ready_for_write = 1; 845 spin_lock_init(&acm->write_lock);
846 acm->write_ready = 1;
704 847
705 buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); 848 buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
706 if (!buf) { 849 if (!buf) {
@@ -716,12 +859,10 @@ skip_normal_probe:
716 } 859 }
717 acm->read_buffer = buf; 860 acm->read_buffer = buf;
718 861
719 buf = usb_buffer_alloc(usb_dev, acm->writesize, GFP_KERNEL, &acm->write_dma); 862 if (acm_write_buffers_alloc(acm) < 0) {
720 if (!buf) {
721 dev_dbg(&intf->dev, "out of memory (write buffer alloc)\n"); 863 dev_dbg(&intf->dev, "out of memory (write buffer alloc)\n");
722 goto alloc_fail4; 864 goto alloc_fail4;
723 } 865 }
724 acm->write_buffer = buf;
725 866
726 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); 867 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL);
727 if (!acm->ctrlurb) { 868 if (!acm->ctrlurb) {
@@ -750,9 +891,9 @@ skip_normal_probe:
750 acm->readurb->transfer_dma = acm->read_dma; 891 acm->readurb->transfer_dma = acm->read_dma;
751 892
752 usb_fill_bulk_urb(acm->writeurb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), 893 usb_fill_bulk_urb(acm->writeurb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
753 acm->write_buffer, acm->writesize, acm_write_bulk, acm); 894 NULL, acm->writesize, acm_write_bulk, acm);
754 acm->writeurb->transfer_flags |= URB_NO_FSBR | URB_NO_TRANSFER_DMA_MAP; 895 acm->writeurb->transfer_flags |= URB_NO_FSBR | URB_NO_TRANSFER_DMA_MAP;
755 acm->writeurb->transfer_dma = acm->write_dma; 896 /* acm->writeurb->transfer_dma = 0; */
756 897
757 dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); 898 dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor);
758 899
@@ -775,7 +916,7 @@ alloc_fail7:
775alloc_fail6: 916alloc_fail6:
776 usb_free_urb(acm->ctrlurb); 917 usb_free_urb(acm->ctrlurb);
777alloc_fail5: 918alloc_fail5:
778 usb_buffer_free(usb_dev, acm->writesize, acm->write_buffer, acm->write_dma); 919 acm_write_buffers_free(acm);
779alloc_fail4: 920alloc_fail4:
780 usb_buffer_free(usb_dev, readsize, acm->read_buffer, acm->read_dma); 921 usb_buffer_free(usb_dev, readsize, acm->read_buffer, acm->read_dma);
781alloc_fail3: 922alloc_fail3:
@@ -806,7 +947,7 @@ static void acm_disconnect(struct usb_interface *intf)
806 947
807 flush_scheduled_work(); /* wait for acm_softint */ 948 flush_scheduled_work(); /* wait for acm_softint */
808 949
809 usb_buffer_free(usb_dev, acm->writesize, acm->write_buffer, acm->write_dma); 950 acm_write_buffers_free(acm);
810 usb_buffer_free(usb_dev, acm->readsize, acm->read_buffer, acm->read_dma); 951 usb_buffer_free(usb_dev, acm->readsize, acm->read_buffer, acm->read_dma);
811 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); 952 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
812 953
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
index 9009114e311b..963a5dfd2096 100644
--- a/drivers/usb/class/cdc-acm.h
+++ b/drivers/usb/class/cdc-acm.h
@@ -51,14 +51,34 @@
51 * Internal driver structures. 51 * Internal driver structures.
52 */ 52 */
53 53
54/*
55 * The only reason to have several buffers is to accomodate assumptions
56 * in line disciplines. They ask for empty space amount, receive our URB size,
57 * and proceed to issue several 1-character writes, assuming they will fit.
58 * The very first write takes a complete URB. Fortunately, this only happens
59 * when processing onlcr, so we only need 2 buffers.
60 */
61#define ACM_NWB 2
62struct acm_wb {
63 unsigned char *buf;
64 dma_addr_t dmah;
65 int len;
66 int use;
67};
68
54struct acm { 69struct acm {
55 struct usb_device *dev; /* the corresponding usb device */ 70 struct usb_device *dev; /* the corresponding usb device */
56 struct usb_interface *control; /* control interface */ 71 struct usb_interface *control; /* control interface */
57 struct usb_interface *data; /* data interface */ 72 struct usb_interface *data; /* data interface */
58 struct tty_struct *tty; /* the corresponding tty */ 73 struct tty_struct *tty; /* the corresponding tty */
59 struct urb *ctrlurb, *readurb, *writeurb; /* urbs */ 74 struct urb *ctrlurb, *readurb, *writeurb; /* urbs */
60 u8 *ctrl_buffer, *read_buffer, *write_buffer; /* buffers of urbs */ 75 u8 *ctrl_buffer, *read_buffer; /* buffers of urbs */
61 dma_addr_t ctrl_dma, read_dma, write_dma; /* dma handles of buffers */ 76 dma_addr_t ctrl_dma, read_dma; /* dma handles of buffers */
77 struct acm_wb wb[ACM_NWB];
78 int write_current; /* current write buffer */
79 int write_used; /* number of non-empty write buffers */
80 int write_ready; /* write urb is not running */
81 spinlock_t write_lock;
62 struct usb_cdc_line_coding line; /* bits, stop, parity */ 82 struct usb_cdc_line_coding line; /* bits, stop, parity */
63 struct work_struct work; /* work queue entry for line discipline waking up */ 83 struct work_struct work; /* work queue entry for line discipline waking up */
64 struct tasklet_struct bh; /* rx processing */ 84 struct tasklet_struct bh; /* rx processing */
@@ -71,7 +91,6 @@ struct acm {
71 unsigned int minor; /* acm minor number */ 91 unsigned int minor; /* acm minor number */
72 unsigned char throttle; /* throttled by tty layer */ 92 unsigned char throttle; /* throttled by tty layer */
73 unsigned char clocal; /* termios CLOCAL */ 93 unsigned char clocal; /* termios CLOCAL */
74 unsigned char ready_for_write; /* write urb can be used */
75 unsigned char resubmit_to_unthrottle; /* throtteling has disabled the read urb */ 94 unsigned char resubmit_to_unthrottle; /* throtteling has disabled the read urb */
76 unsigned int ctrl_caps; /* control capabilities from the class specific header */ 95 unsigned int ctrl_caps; /* control capabilities from the class specific header */
77}; 96};
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index bba22e97ea0f..7ce43fb8118a 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -379,6 +379,8 @@ static int usblp_open(struct inode *inode, struct file *file)
379 usblp->writeurb->transfer_buffer_length = 0; 379 usblp->writeurb->transfer_buffer_length = 0;
380 usblp->wcomplete = 1; /* we begin writeable */ 380 usblp->wcomplete = 1; /* we begin writeable */
381 usblp->rcomplete = 0; 381 usblp->rcomplete = 0;
382 usblp->writeurb->status = 0;
383 usblp->readurb->status = 0;
382 384
383 if (usblp->bidir) { 385 if (usblp->bidir) {
384 usblp->readcount = 0; 386 usblp->readcount = 0;
@@ -751,6 +753,7 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t count,
751 schedule(); 753 schedule();
752 } else { 754 } else {
753 set_current_state(TASK_RUNNING); 755 set_current_state(TASK_RUNNING);
756 down(&usblp->sem);
754 break; 757 break;
755 } 758 }
756 down (&usblp->sem); 759 down (&usblp->sem);
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 6bfab4bcaa9e..787c27a63c51 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -784,16 +784,16 @@ static int proc_setconfig(struct dev_state *ps, void __user *arg)
784 for (i = 0; i < actconfig->desc.bNumInterfaces; ++i) { 784 for (i = 0; i < actconfig->desc.bNumInterfaces; ++i) {
785 if (usb_interface_claimed(actconfig->interface[i])) { 785 if (usb_interface_claimed(actconfig->interface[i])) {
786 dev_warn (&ps->dev->dev, 786 dev_warn (&ps->dev->dev,
787 "usbfs: interface %d claimed " 787 "usbfs: interface %d claimed by %s "
788 "while '%s' sets config #%d\n", 788 "while '%s' sets config #%d\n",
789 actconfig->interface[i] 789 actconfig->interface[i]
790 ->cur_altsetting 790 ->cur_altsetting
791 ->desc.bInterfaceNumber, 791 ->desc.bInterfaceNumber,
792 actconfig->interface[i]
793 ->dev.driver->name,
792 current->comm, u); 794 current->comm, u);
793#if 0 /* FIXME: enable in 2.6.10 or so */
794 status = -EBUSY; 795 status = -EBUSY;
795 break; 796 break;
796#endif
797 } 797 }
798 } 798 }
799 } 799 }
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 0da23732e807..83e732a0d64a 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -519,119 +519,120 @@ error:
519/*-------------------------------------------------------------------------*/ 519/*-------------------------------------------------------------------------*/
520 520
521/* 521/*
522 * Root Hub interrupt transfers are synthesized with a timer. 522 * Root Hub interrupt transfers are polled using a timer if the
523 * Completions are called in_interrupt() but not in_irq(). 523 * driver requests it; otherwise the driver is responsible for
524 * calling usb_hcd_poll_rh_status() when an event occurs.
524 * 525 *
525 * Note: some root hubs (including common UHCI based designs) can't 526 * Completions are called in_interrupt(), but they may or may not
526 * correctly issue port change IRQs. They're the ones that _need_ a 527 * be in_irq().
527 * timer; most other root hubs don't. Some systems could save a
528 * lot of battery power by eliminating these root hub timer IRQs.
529 */ 528 */
529void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
530{
531 struct urb *urb;
532 int length;
533 unsigned long flags;
534 char buffer[4]; /* Any root hubs with > 31 ports? */
530 535
531static void rh_report_status (unsigned long ptr); 536 if (!hcd->uses_new_polling && !hcd->status_urb)
537 return;
532 538
533static int rh_status_urb (struct usb_hcd *hcd, struct urb *urb) 539 length = hcd->driver->hub_status_data(hcd, buffer);
534{ 540 if (length > 0) {
535 int len = 1 + (urb->dev->maxchild / 8);
536 541
537 /* rh_timer protected by hcd_data_lock */ 542 /* try to complete the status urb */
538 if (hcd->rh_timer.data || urb->transfer_buffer_length < len) { 543 local_irq_save (flags);
539 dev_dbg (hcd->self.controller, 544 spin_lock(&hcd_root_hub_lock);
540 "not queuing rh status urb, stat %d\n", 545 urb = hcd->status_urb;
541 urb->status); 546 if (urb) {
542 return -EINVAL; 547 spin_lock(&urb->lock);
548 if (urb->status == -EINPROGRESS) {
549 hcd->poll_pending = 0;
550 hcd->status_urb = NULL;
551 urb->status = 0;
552 urb->hcpriv = NULL;
553 urb->actual_length = length;
554 memcpy(urb->transfer_buffer, buffer, length);
555 } else /* urb has been unlinked */
556 length = 0;
557 spin_unlock(&urb->lock);
558 } else
559 length = 0;
560 spin_unlock(&hcd_root_hub_lock);
561
562 /* local irqs are always blocked in completions */
563 if (length > 0)
564 usb_hcd_giveback_urb (hcd, urb, NULL);
565 else
566 hcd->poll_pending = 1;
567 local_irq_restore (flags);
543 } 568 }
544 569
545 init_timer (&hcd->rh_timer); 570 /* The USB 2.0 spec says 256 ms. This is close enough and won't
546 hcd->rh_timer.function = rh_report_status; 571 * exceed that limit if HZ is 100. */
547 hcd->rh_timer.data = (unsigned long) urb; 572 if (hcd->uses_new_polling ? hcd->poll_rh :
548 /* USB 2.0 spec says 256msec; this is close enough */ 573 (length == 0 && hcd->status_urb != NULL))
549 hcd->rh_timer.expires = jiffies + HZ/4; 574 mod_timer (&hcd->rh_timer, jiffies + msecs_to_jiffies(250));
550 add_timer (&hcd->rh_timer);
551 urb->hcpriv = hcd; /* nonzero to indicate it's queued */
552 return 0;
553} 575}
576EXPORT_SYMBOL_GPL(usb_hcd_poll_rh_status);
554 577
555/* timer callback */ 578/* timer callback */
579static void rh_timer_func (unsigned long _hcd)
580{
581 usb_hcd_poll_rh_status((struct usb_hcd *) _hcd);
582}
556 583
557static void rh_report_status (unsigned long ptr) 584/*-------------------------------------------------------------------------*/
585
586static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb)
558{ 587{
559 struct urb *urb; 588 int retval;
560 struct usb_hcd *hcd;
561 int length = 0;
562 unsigned long flags; 589 unsigned long flags;
590 int len = 1 + (urb->dev->maxchild / 8);
563 591
564 urb = (struct urb *) ptr; 592 spin_lock_irqsave (&hcd_root_hub_lock, flags);
565 local_irq_save (flags); 593 if (urb->status != -EINPROGRESS) /* already unlinked */
566 spin_lock (&urb->lock); 594 retval = urb->status;
595 else if (hcd->status_urb || urb->transfer_buffer_length < len) {
596 dev_dbg (hcd->self.controller, "not queuing rh status urb\n");
597 retval = -EINVAL;
598 } else {
599 hcd->status_urb = urb;
600 urb->hcpriv = hcd; /* indicate it's queued */
567 601
568 /* do nothing if the urb's been unlinked */ 602 if (!hcd->uses_new_polling)
569 if (!urb->dev 603 mod_timer (&hcd->rh_timer, jiffies +
570 || urb->status != -EINPROGRESS 604 msecs_to_jiffies(250));
571 || (hcd = urb->dev->bus->hcpriv) == NULL) {
572 spin_unlock (&urb->lock);
573 local_irq_restore (flags);
574 return;
575 }
576 605
577 /* complete the status urb, or retrigger the timer */ 606 /* If a status change has already occurred, report it ASAP */
578 spin_lock (&hcd_data_lock); 607 else if (hcd->poll_pending)
579 if (urb->dev->state == USB_STATE_CONFIGURED) { 608 mod_timer (&hcd->rh_timer, jiffies);
580 length = hcd->driver->hub_status_data ( 609 retval = 0;
581 hcd, urb->transfer_buffer);
582 if (length > 0) {
583 hcd->rh_timer.data = 0;
584 urb->actual_length = length;
585 urb->status = 0;
586 urb->hcpriv = NULL;
587 } else
588 mod_timer (&hcd->rh_timer, jiffies + HZ/4);
589 } 610 }
590 spin_unlock (&hcd_data_lock); 611 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
591 spin_unlock (&urb->lock); 612 return retval;
592
593 /* local irqs are always blocked in completions */
594 if (length > 0)
595 usb_hcd_giveback_urb (hcd, urb, NULL);
596 local_irq_restore (flags);
597} 613}
598 614
599/*-------------------------------------------------------------------------*/
600
601static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb) 615static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb)
602{ 616{
603 if (usb_pipeint (urb->pipe)) { 617 if (usb_pipeint (urb->pipe))
604 int retval; 618 return rh_queue_status (hcd, urb);
605 unsigned long flags;
606
607 spin_lock_irqsave (&hcd_data_lock, flags);
608 retval = rh_status_urb (hcd, urb);
609 spin_unlock_irqrestore (&hcd_data_lock, flags);
610 return retval;
611 }
612 if (usb_pipecontrol (urb->pipe)) 619 if (usb_pipecontrol (urb->pipe))
613 return rh_call_control (hcd, urb); 620 return rh_call_control (hcd, urb);
614 else 621 return -EINVAL;
615 return -EINVAL;
616} 622}
617 623
618/*-------------------------------------------------------------------------*/ 624/*-------------------------------------------------------------------------*/
619 625
626/* Asynchronous unlinks of root-hub control URBs are legal, but they
627 * don't do anything. Status URB unlinks must be made in process context
628 * with interrupts enabled.
629 */
620static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 630static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
621{ 631{
622 unsigned long flags; 632 if (usb_pipeendpoint(urb->pipe) == 0) { /* Control URB */
633 if (in_interrupt())
634 return 0; /* nothing to do */
623 635
624 /* note: always a synchronous unlink */
625 if ((unsigned long) urb == hcd->rh_timer.data) {
626 del_timer_sync (&hcd->rh_timer);
627 hcd->rh_timer.data = 0;
628
629 local_irq_save (flags);
630 urb->hcpriv = NULL;
631 usb_hcd_giveback_urb (hcd, urb, NULL);
632 local_irq_restore (flags);
633
634 } else if (usb_pipeendpoint(urb->pipe) == 0) {
635 spin_lock_irq(&urb->lock); /* from usb_kill_urb */ 636 spin_lock_irq(&urb->lock); /* from usb_kill_urb */
636 ++urb->reject; 637 ++urb->reject;
637 spin_unlock_irq(&urb->lock); 638 spin_unlock_irq(&urb->lock);
@@ -642,8 +643,22 @@ static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
642 spin_lock_irq(&urb->lock); 643 spin_lock_irq(&urb->lock);
643 --urb->reject; 644 --urb->reject;
644 spin_unlock_irq(&urb->lock); 645 spin_unlock_irq(&urb->lock);
645 } else 646
646 return -EINVAL; 647 } else { /* Status URB */
648 if (!hcd->uses_new_polling)
649 del_timer_sync (&hcd->rh_timer);
650 local_irq_disable ();
651 spin_lock (&hcd_root_hub_lock);
652 if (urb == hcd->status_urb) {
653 hcd->status_urb = NULL;
654 urb->hcpriv = NULL;
655 } else
656 urb = NULL; /* wasn't fully queued */
657 spin_unlock (&hcd_root_hub_lock);
658 if (urb)
659 usb_hcd_giveback_urb (hcd, urb, NULL);
660 local_irq_enable ();
661 }
647 662
648 return 0; 663 return 0;
649} 664}
@@ -817,30 +832,22 @@ static void usb_deregister_bus (struct usb_bus *bus)
817} 832}
818 833
819/** 834/**
820 * usb_hcd_register_root_hub - called by HCD to register its root hub 835 * register_root_hub - called by usb_add_hcd() to register a root hub
821 * @usb_dev: the usb root hub device to be registered. 836 * @usb_dev: the usb root hub device to be registered.
822 * @hcd: host controller for this root hub 837 * @hcd: host controller for this root hub
823 * 838 *
824 * The USB host controller calls this function to register the root hub 839 * This function registers the root hub with the USB subsystem. It sets up
825 * properly with the USB subsystem. It sets up the device properly in 840 * the device properly in the device tree and stores the root_hub pointer
826 * the device tree and stores the root_hub pointer in the bus structure, 841 * in the bus structure, then calls usb_new_device() to register the usb
827 * then calls usb_new_device() to register the usb device. It also 842 * device. It also assigns the root hub's USB address (always 1).
828 * assigns the root hub's USB address (always 1).
829 */ 843 */
830int usb_hcd_register_root_hub (struct usb_device *usb_dev, struct usb_hcd *hcd) 844static int register_root_hub (struct usb_device *usb_dev,
845 struct usb_hcd *hcd)
831{ 846{
832 struct device *parent_dev = hcd->self.controller; 847 struct device *parent_dev = hcd->self.controller;
833 const int devnum = 1; 848 const int devnum = 1;
834 int retval; 849 int retval;
835 850
836 /* hcd->driver->start() reported can_wakeup, probably with
837 * assistance from board's boot firmware.
838 * NOTE: normal devices won't enable wakeup by default.
839 */
840 if (hcd->can_wakeup)
841 dev_dbg (parent_dev, "supports USB remote wakeup\n");
842 hcd->remote_wakeup = hcd->can_wakeup;
843
844 usb_dev->devnum = devnum; 851 usb_dev->devnum = devnum;
845 usb_dev->bus->devnum_next = devnum + 1; 852 usb_dev->bus->devnum_next = devnum + 1;
846 memset (&usb_dev->bus->devmap.devicemap, 0, 853 memset (&usb_dev->bus->devmap.devicemap, 0,
@@ -883,7 +890,16 @@ int usb_hcd_register_root_hub (struct usb_device *usb_dev, struct usb_hcd *hcd)
883 890
884 return retval; 891 return retval;
885} 892}
886EXPORT_SYMBOL_GPL(usb_hcd_register_root_hub); 893
894void usb_enable_root_hub_irq (struct usb_bus *bus)
895{
896 struct usb_hcd *hcd;
897
898 hcd = container_of (bus, struct usb_hcd, self);
899 if (hcd->driver->hub_irq_enable && !hcd->poll_rh &&
900 hcd->state != HC_STATE_HALT)
901 hcd->driver->hub_irq_enable (hcd);
902}
887 903
888 904
889/*-------------------------------------------------------------------------*/ 905/*-------------------------------------------------------------------------*/
@@ -1348,7 +1364,8 @@ hcd_endpoint_disable (struct usb_device *udev, struct usb_host_endpoint *ep)
1348 1364
1349 hcd = udev->bus->hcpriv; 1365 hcd = udev->bus->hcpriv;
1350 1366
1351 WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT); 1367 WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT &&
1368 udev->state != USB_STATE_NOTATTACHED);
1352 1369
1353 local_irq_disable (); 1370 local_irq_disable ();
1354 1371
@@ -1612,6 +1629,8 @@ void usb_hc_died (struct usb_hcd *hcd)
1612 1629
1613 spin_lock_irqsave (&hcd_root_hub_lock, flags); 1630 spin_lock_irqsave (&hcd_root_hub_lock, flags);
1614 if (hcd->rh_registered) { 1631 if (hcd->rh_registered) {
1632 hcd->poll_rh = 0;
1633 del_timer(&hcd->rh_timer);
1615 1634
1616 /* make khubd clean up old urbs and devices */ 1635 /* make khubd clean up old urbs and devices */
1617 usb_set_device_state (hcd->self.root_hub, 1636 usb_set_device_state (hcd->self.root_hub,
@@ -1665,6 +1684,8 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
1665 hcd->self.bus_name = bus_name; 1684 hcd->self.bus_name = bus_name;
1666 1685
1667 init_timer(&hcd->rh_timer); 1686 init_timer(&hcd->rh_timer);
1687 hcd->rh_timer.function = rh_timer_func;
1688 hcd->rh_timer.data = (unsigned long) hcd;
1668 1689
1669 hcd->driver = driver; 1690 hcd->driver = driver;
1670 hcd->product_desc = (driver->product_desc) ? driver->product_desc : 1691 hcd->product_desc = (driver->product_desc) ? driver->product_desc :
@@ -1694,7 +1715,8 @@ EXPORT_SYMBOL (usb_put_hcd);
1694int usb_add_hcd(struct usb_hcd *hcd, 1715int usb_add_hcd(struct usb_hcd *hcd,
1695 unsigned int irqnum, unsigned long irqflags) 1716 unsigned int irqnum, unsigned long irqflags)
1696{ 1717{
1697 int retval; 1718 int retval;
1719 struct usb_device *rhdev;
1698 1720
1699 dev_info(hcd->self.controller, "%s\n", hcd->product_desc); 1721 dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
1700 1722
@@ -1710,7 +1732,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
1710 } 1732 }
1711 1733
1712 if ((retval = usb_register_bus(&hcd->self)) < 0) 1734 if ((retval = usb_register_bus(&hcd->self)) < 0)
1713 goto err1; 1735 goto err_register_bus;
1714 1736
1715 if (hcd->driver->irq) { 1737 if (hcd->driver->irq) {
1716 char buf[8], *bufp = buf; 1738 char buf[8], *bufp = buf;
@@ -1727,7 +1749,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
1727 hcd->irq_descr, hcd)) != 0) { 1749 hcd->irq_descr, hcd)) != 0) {
1728 dev_err(hcd->self.controller, 1750 dev_err(hcd->self.controller,
1729 "request interrupt %s failed\n", bufp); 1751 "request interrupt %s failed\n", bufp);
1730 goto err2; 1752 goto err_request_irq;
1731 } 1753 }
1732 hcd->irq = irqnum; 1754 hcd->irq = irqnum;
1733 dev_info(hcd->self.controller, "irq %s, %s 0x%08llx\n", bufp, 1755 dev_info(hcd->self.controller, "irq %s, %s 0x%08llx\n", bufp,
@@ -1743,19 +1765,55 @@ int usb_add_hcd(struct usb_hcd *hcd,
1743 (unsigned long long)hcd->rsrc_start); 1765 (unsigned long long)hcd->rsrc_start);
1744 } 1766 }
1745 1767
1768 /* Allocate the root hub before calling hcd->driver->start(),
1769 * but don't register it until afterward so that the hardware
1770 * is running.
1771 */
1772 if ((rhdev = usb_alloc_dev(NULL, &hcd->self, 0)) == NULL) {
1773 dev_err(hcd->self.controller, "unable to allocate root hub\n");
1774 retval = -ENOMEM;
1775 goto err_allocate_root_hub;
1776 }
1777 rhdev->speed = (hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH :
1778 USB_SPEED_FULL;
1779
1780 /* Although in principle hcd->driver->start() might need to use rhdev,
1781 * none of the current drivers do.
1782 */
1746 if ((retval = hcd->driver->start(hcd)) < 0) { 1783 if ((retval = hcd->driver->start(hcd)) < 0) {
1747 dev_err(hcd->self.controller, "startup error %d\n", retval); 1784 dev_err(hcd->self.controller, "startup error %d\n", retval);
1748 goto err3; 1785 goto err_hcd_driver_start;
1749 } 1786 }
1750 1787
1788 /* hcd->driver->start() reported can_wakeup, probably with
1789 * assistance from board's boot firmware.
1790 * NOTE: normal devices won't enable wakeup by default.
1791 */
1792 if (hcd->can_wakeup)
1793 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n");
1794 hcd->remote_wakeup = hcd->can_wakeup;
1795
1796 if ((retval = register_root_hub(rhdev, hcd)) != 0)
1797 goto err_register_root_hub;
1798
1799 if (hcd->uses_new_polling && hcd->poll_rh)
1800 usb_hcd_poll_rh_status(hcd);
1751 return retval; 1801 return retval;
1752 1802
1753 err3: 1803 err_register_root_hub:
1804 hcd->driver->stop(hcd);
1805
1806 err_hcd_driver_start:
1807 usb_put_dev(rhdev);
1808
1809 err_allocate_root_hub:
1754 if (hcd->irq >= 0) 1810 if (hcd->irq >= 0)
1755 free_irq(irqnum, hcd); 1811 free_irq(irqnum, hcd);
1756 err2: 1812
1813 err_request_irq:
1757 usb_deregister_bus(&hcd->self); 1814 usb_deregister_bus(&hcd->self);
1758 err1: 1815
1816 err_register_bus:
1759 hcd_buffer_destroy(hcd); 1817 hcd_buffer_destroy(hcd);
1760 return retval; 1818 return retval;
1761} 1819}
@@ -1782,6 +1840,9 @@ void usb_remove_hcd(struct usb_hcd *hcd)
1782 spin_unlock_irq (&hcd_root_hub_lock); 1840 spin_unlock_irq (&hcd_root_hub_lock);
1783 usb_disconnect(&hcd->self.root_hub); 1841 usb_disconnect(&hcd->self.root_hub);
1784 1842
1843 hcd->poll_rh = 0;
1844 del_timer_sync(&hcd->rh_timer);
1845
1785 hcd->driver->stop(hcd); 1846 hcd->driver->stop(hcd);
1786 hcd->state = HC_STATE_HALT; 1847 hcd->state = HC_STATE_HALT;
1787 1848
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 325a51656c3f..8dc13cde2f73 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -65,7 +65,8 @@ struct usb_hcd { /* usb_bus.hcpriv points to this */
65 const char *product_desc; /* product/vendor string */ 65 const char *product_desc; /* product/vendor string */
66 char irq_descr[24]; /* driver + bus # */ 66 char irq_descr[24]; /* driver + bus # */
67 67
68 struct timer_list rh_timer; /* drives root hub */ 68 struct timer_list rh_timer; /* drives root-hub polling */
69 struct urb *status_urb; /* the current status urb */
69 70
70 /* 71 /*
71 * hardware info/state 72 * hardware info/state
@@ -76,10 +77,17 @@ struct usb_hcd { /* usb_bus.hcpriv points to this */
76 unsigned remote_wakeup:1;/* sw should use wakeup? */ 77 unsigned remote_wakeup:1;/* sw should use wakeup? */
77 unsigned rh_registered:1;/* is root hub registered? */ 78 unsigned rh_registered:1;/* is root hub registered? */
78 79
80 /* The next flag is a stopgap, to be removed when all the HCDs
81 * support the new root-hub polling mechanism. */
82 unsigned uses_new_polling:1;
83 unsigned poll_rh:1; /* poll for rh status? */
84 unsigned poll_pending:1; /* status has changed? */
85
79 int irq; /* irq allocated */ 86 int irq; /* irq allocated */
80 void __iomem *regs; /* device memory/io */ 87 void __iomem *regs; /* device memory/io */
81 u64 rsrc_start; /* memory/io resource start */ 88 u64 rsrc_start; /* memory/io resource start */
82 u64 rsrc_len; /* memory/io resource length */ 89 u64 rsrc_len; /* memory/io resource length */
90 unsigned power_budget; /* in mA, 0 = no limit */
83 91
84#define HCD_BUFFER_POOLS 4 92#define HCD_BUFFER_POOLS 4
85 struct dma_pool *pool [HCD_BUFFER_POOLS]; 93 struct dma_pool *pool [HCD_BUFFER_POOLS];
@@ -207,6 +215,8 @@ struct hc_driver {
207 int (*hub_suspend)(struct usb_hcd *); 215 int (*hub_suspend)(struct usb_hcd *);
208 int (*hub_resume)(struct usb_hcd *); 216 int (*hub_resume)(struct usb_hcd *);
209 int (*start_port_reset)(struct usb_hcd *, unsigned port_num); 217 int (*start_port_reset)(struct usb_hcd *, unsigned port_num);
218 void (*hub_irq_enable)(struct usb_hcd *);
219 /* Needed only if port-change IRQs are level-triggered */
210}; 220};
211 221
212extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, struct pt_regs *regs); 222extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, struct pt_regs *regs);
@@ -243,7 +253,9 @@ void hcd_buffer_free (struct usb_bus *bus, size_t size,
243 253
244/* generic bus glue, needed for host controllers that don't use PCI */ 254/* generic bus glue, needed for host controllers that don't use PCI */
245extern irqreturn_t usb_hcd_irq (int irq, void *__hcd, struct pt_regs *r); 255extern irqreturn_t usb_hcd_irq (int irq, void *__hcd, struct pt_regs *r);
256
246extern void usb_hc_died (struct usb_hcd *hcd); 257extern void usb_hc_died (struct usb_hcd *hcd);
258extern void usb_hcd_poll_rh_status(struct usb_hcd *hcd);
247 259
248/* -------------------------------------------------------------------------- */ 260/* -------------------------------------------------------------------------- */
249 261
@@ -341,9 +353,6 @@ extern long usb_calc_bus_time (int speed, int is_input,
341 353
342extern struct usb_bus *usb_alloc_bus (struct usb_operations *); 354extern struct usb_bus *usb_alloc_bus (struct usb_operations *);
343 355
344extern int usb_hcd_register_root_hub (struct usb_device *usb_dev,
345 struct usb_hcd *hcd);
346
347extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd); 356extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd);
348 357
349extern void usb_set_device_state(struct usb_device *udev, 358extern void usb_set_device_state(struct usb_device *udev,
@@ -360,6 +369,8 @@ extern wait_queue_head_t usb_kill_urb_queue;
360extern struct usb_bus *usb_bus_get (struct usb_bus *bus); 369extern struct usb_bus *usb_bus_get (struct usb_bus *bus);
361extern void usb_bus_put (struct usb_bus *bus); 370extern void usb_bus_put (struct usb_bus *bus);
362 371
372extern void usb_enable_root_hub_irq (struct usb_bus *bus);
373
363extern int usb_find_interface_driver (struct usb_device *dev, 374extern int usb_find_interface_driver (struct usb_device *dev,
364 struct usb_interface *interface); 375 struct usb_interface *interface);
365 376
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index a8d879a85d04..32ff32181852 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -643,15 +643,21 @@ static int hub_configure(struct usb_hub *hub,
643 message = "can't get hub status"; 643 message = "can't get hub status";
644 goto fail; 644 goto fail;
645 } 645 }
646 cpu_to_le16s(&hubstatus); 646 le16_to_cpus(&hubstatus);
647 if ((hubstatus & (1 << USB_DEVICE_SELF_POWERED)) == 0) { 647 if (hdev == hdev->bus->root_hub) {
648 struct usb_hcd *hcd =
649 container_of(hdev->bus, struct usb_hcd, self);
650
651 hub->power_budget = min(500u, hcd->power_budget) / 2;
652 } else if ((hubstatus & (1 << USB_DEVICE_SELF_POWERED)) == 0) {
648 dev_dbg(hub_dev, "hub controller current requirement: %dmA\n", 653 dev_dbg(hub_dev, "hub controller current requirement: %dmA\n",
649 hub->descriptor->bHubContrCurrent); 654 hub->descriptor->bHubContrCurrent);
650 hub->power_budget = (501 - hub->descriptor->bHubContrCurrent) 655 hub->power_budget = (501 - hub->descriptor->bHubContrCurrent)
651 / 2; 656 / 2;
657 }
658 if (hub->power_budget)
652 dev_dbg(hub_dev, "%dmA bus power budget for children\n", 659 dev_dbg(hub_dev, "%dmA bus power budget for children\n",
653 hub->power_budget * 2); 660 hub->power_budget * 2);
654 }
655 661
656 662
657 ret = hub_hub_status(hub, &hubstatus, &hubchange); 663 ret = hub_hub_status(hub, &hubstatus, &hubchange);
@@ -1727,7 +1733,7 @@ static int finish_port_resume(struct usb_device *udev)
1727 struct usb_driver *driver; 1733 struct usb_driver *driver;
1728 1734
1729 intf = udev->actconfig->interface[i]; 1735 intf = udev->actconfig->interface[i];
1730 if (intf->dev.power.power_state == PMSG_SUSPEND) 1736 if (intf->dev.power.power_state == PMSG_ON)
1731 continue; 1737 continue;
1732 if (!intf->dev.driver) { 1738 if (!intf->dev.driver) {
1733 /* FIXME maybe force to alt 0 */ 1739 /* FIXME maybe force to alt 0 */
@@ -2787,6 +2793,11 @@ static void hub_events(void)
2787 2793
2788 hub->activating = 0; 2794 hub->activating = 0;
2789 2795
2796 /* If this is a root hub, tell the HCD it's okay to
2797 * re-enable port-change interrupts now. */
2798 if (!hdev->parent)
2799 usb_enable_root_hub_irq(hdev->bus);
2800
2790loop: 2801loop:
2791 usb_unlock_device(hdev); 2802 usb_unlock_device(hdev);
2792 usb_put_intf(intf); 2803 usb_put_intf(intf);
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index d114b847d56f..53bf5649621e 100644
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -224,15 +224,4 @@ struct usb_hub {
224 struct work_struct leds; 224 struct work_struct leds;
225}; 225};
226 226
227/* use this for low-powered root hubs */
228static inline void
229hub_set_power_budget (struct usb_device *hubdev, unsigned mA)
230{
231 struct usb_hub *hub;
232
233 hub = (struct usb_hub *)
234 usb_get_intfdata (hubdev->actconfig->interface[0]);
235 hub->power_budget = min(mA,(unsigned)500)/2;
236}
237
238#endif /* __LINUX_HUB_H */ 227#endif /* __LINUX_HUB_H */
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 3b24f9f2c234..ff075a53c8d6 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -53,6 +53,9 @@ config USB_GADGET_DEBUG_FILES
53 driver on a new board. Enable these files by choosing "Y" 53 driver on a new board. Enable these files by choosing "Y"
54 here. If in doubt, or to conserve kernel memory, say "N". 54 here. If in doubt, or to conserve kernel memory, say "N".
55 55
56config USB_GADGET_SELECTED
57 boolean
58
56# 59#
57# USB Peripheral Controller Support 60# USB Peripheral Controller Support
58# 61#
@@ -85,6 +88,7 @@ config USB_NET2280
85 tristate 88 tristate
86 depends on USB_GADGET_NET2280 89 depends on USB_GADGET_NET2280
87 default USB_GADGET 90 default USB_GADGET
91 select USB_GADGET_SELECTED
88 92
89config USB_GADGET_PXA2XX 93config USB_GADGET_PXA2XX
90 boolean "PXA 25x or IXP 4xx" 94 boolean "PXA 25x or IXP 4xx"
@@ -105,6 +109,7 @@ config USB_PXA2XX
105 tristate 109 tristate
106 depends on USB_GADGET_PXA2XX 110 depends on USB_GADGET_PXA2XX
107 default USB_GADGET 111 default USB_GADGET
112 select USB_GADGET_SELECTED
108 113
109# if there's only one gadget driver, using only two bulk endpoints, 114# if there's only one gadget driver, using only two bulk endpoints,
110# don't waste memory for the other endpoints 115# don't waste memory for the other endpoints
@@ -134,6 +139,7 @@ config USB_GOKU
134 tristate 139 tristate
135 depends on USB_GADGET_GOKU 140 depends on USB_GADGET_GOKU
136 default USB_GADGET 141 default USB_GADGET
142 select USB_GADGET_SELECTED
137 143
138 144
139config USB_GADGET_LH7A40X 145config USB_GADGET_LH7A40X
@@ -146,6 +152,7 @@ config USB_LH7A40X
146 tristate 152 tristate
147 depends on USB_GADGET_LH7A40X 153 depends on USB_GADGET_LH7A40X
148 default USB_GADGET 154 default USB_GADGET
155 select USB_GADGET_SELECTED
149 156
150 157
151config USB_GADGET_OMAP 158config USB_GADGET_OMAP
@@ -167,6 +174,7 @@ config USB_OMAP
167 tristate 174 tristate
168 depends on USB_GADGET_OMAP 175 depends on USB_GADGET_OMAP
169 default USB_GADGET 176 default USB_GADGET
177 select USB_GADGET_SELECTED
170 178
171config USB_OTG 179config USB_OTG
172 boolean "OTG Support" 180 boolean "OTG Support"
@@ -207,6 +215,7 @@ config USB_DUMMY_HCD
207 tristate 215 tristate
208 depends on USB_GADGET_DUMMY_HCD 216 depends on USB_GADGET_DUMMY_HCD
209 default USB_GADGET 217 default USB_GADGET
218 select USB_GADGET_SELECTED
210 219
211# NOTE: Please keep dummy_hcd LAST so that "real hardware" appears 220# NOTE: Please keep dummy_hcd LAST so that "real hardware" appears
212# first and will be selected by default. 221# first and will be selected by default.
@@ -226,7 +235,7 @@ config USB_GADGET_DUALSPEED
226# 235#
227choice 236choice
228 tristate "USB Gadget Drivers" 237 tristate "USB Gadget Drivers"
229 depends on USB_GADGET 238 depends on USB_GADGET && USB_GADGET_SELECTED
230 default USB_ETH 239 default USB_ETH
231 help 240 help
232 A Linux "Gadget Driver" talks to the USB Peripheral Controller 241 A Linux "Gadget Driver" talks to the USB Peripheral Controller
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index c039d2fbe7ab..4d692670f288 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -65,7 +65,7 @@
65 65
66 66
67#define DRIVER_DESC "USB Host+Gadget Emulator" 67#define DRIVER_DESC "USB Host+Gadget Emulator"
68#define DRIVER_VERSION "17 Dec 2004" 68#define DRIVER_VERSION "02 May 2005"
69 69
70static const char driver_name [] = "dummy_hcd"; 70static const char driver_name [] = "dummy_hcd";
71static const char driver_desc [] = "USB Host+Gadget Emulator"; 71static const char driver_desc [] = "USB Host+Gadget Emulator";
@@ -141,6 +141,8 @@ static const char *const ep_name [] = {
141}; 141};
142#define DUMMY_ENDPOINTS (sizeof(ep_name)/sizeof(char *)) 142#define DUMMY_ENDPOINTS (sizeof(ep_name)/sizeof(char *))
143 143
144/*-------------------------------------------------------------------------*/
145
144#define FIFO_SIZE 64 146#define FIFO_SIZE 64
145 147
146struct urbp { 148struct urbp {
@@ -148,6 +150,13 @@ struct urbp {
148 struct list_head urbp_list; 150 struct list_head urbp_list;
149}; 151};
150 152
153
154enum dummy_rh_state {
155 DUMMY_RH_RESET,
156 DUMMY_RH_SUSPENDED,
157 DUMMY_RH_RUNNING
158};
159
151struct dummy { 160struct dummy {
152 spinlock_t lock; 161 spinlock_t lock;
153 162
@@ -161,12 +170,18 @@ struct dummy {
161 struct dummy_request fifo_req; 170 struct dummy_request fifo_req;
162 u8 fifo_buf [FIFO_SIZE]; 171 u8 fifo_buf [FIFO_SIZE];
163 u16 devstatus; 172 u16 devstatus;
173 unsigned udc_suspended:1;
174 unsigned pullup:1;
175 unsigned active:1;
176 unsigned old_active:1;
164 177
165 /* 178 /*
166 * MASTER/HOST side support 179 * MASTER/HOST side support
167 */ 180 */
181 enum dummy_rh_state rh_state;
168 struct timer_list timer; 182 struct timer_list timer;
169 u32 port_status; 183 u32 port_status;
184 u32 old_status;
170 unsigned resuming:1; 185 unsigned resuming:1;
171 unsigned long re_timeout; 186 unsigned long re_timeout;
172 187
@@ -189,6 +204,11 @@ static inline struct device *dummy_dev (struct dummy *dum)
189 return dummy_to_hcd(dum)->self.controller; 204 return dummy_to_hcd(dum)->self.controller;
190} 205}
191 206
207static inline struct device *udc_dev (struct dummy *dum)
208{
209 return dum->gadget.dev.parent;
210}
211
192static inline struct dummy *ep_to_dummy (struct dummy_ep *ep) 212static inline struct dummy *ep_to_dummy (struct dummy_ep *ep)
193{ 213{
194 return container_of (ep->gadget, struct dummy, gadget); 214 return container_of (ep->gadget, struct dummy, gadget);
@@ -208,16 +228,98 @@ static struct dummy *the_controller;
208 228
209/*-------------------------------------------------------------------------*/ 229/*-------------------------------------------------------------------------*/
210 230
211/* 231/* SLAVE/GADGET SIDE UTILITY ROUTINES */
212 * This "hardware" may look a bit odd in diagnostics since it's got both
213 * host and device sides; and it binds different drivers to each side.
214 */
215static struct platform_device the_pdev;
216 232
217static struct device_driver dummy_driver = { 233/* called with spinlock held */
218 .name = (char *) driver_name, 234static void nuke (struct dummy *dum, struct dummy_ep *ep)
219 .bus = &platform_bus_type, 235{
220}; 236 while (!list_empty (&ep->queue)) {
237 struct dummy_request *req;
238
239 req = list_entry (ep->queue.next, struct dummy_request, queue);
240 list_del_init (&req->queue);
241 req->req.status = -ESHUTDOWN;
242
243 spin_unlock (&dum->lock);
244 req->req.complete (&ep->ep, &req->req);
245 spin_lock (&dum->lock);
246 }
247}
248
249/* caller must hold lock */
250static void
251stop_activity (struct dummy *dum)
252{
253 struct dummy_ep *ep;
254
255 /* prevent any more requests */
256 dum->address = 0;
257
258 /* The timer is left running so that outstanding URBs can fail */
259
260 /* nuke any pending requests first, so driver i/o is quiesced */
261 list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list)
262 nuke (dum, ep);
263
264 /* driver now does any non-usb quiescing necessary */
265}
266
267/* caller must hold lock */
268static void
269set_link_state (struct dummy *dum)
270{
271 dum->active = 0;
272 if ((dum->port_status & USB_PORT_STAT_POWER) == 0)
273 dum->port_status = 0;
274
275 /* UDC suspend must cause a disconnect */
276 else if (!dum->pullup || dum->udc_suspended) {
277 dum->port_status &= ~(USB_PORT_STAT_CONNECTION |
278 USB_PORT_STAT_ENABLE |
279 USB_PORT_STAT_LOW_SPEED |
280 USB_PORT_STAT_HIGH_SPEED |
281 USB_PORT_STAT_SUSPEND);
282 if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0)
283 dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16);
284 } else {
285 dum->port_status |= USB_PORT_STAT_CONNECTION;
286 if ((dum->old_status & USB_PORT_STAT_CONNECTION) == 0)
287 dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16);
288 if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0)
289 dum->port_status &= ~USB_PORT_STAT_SUSPEND;
290 else if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 &&
291 dum->rh_state != DUMMY_RH_SUSPENDED)
292 dum->active = 1;
293 }
294
295 if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0 || dum->active)
296 dum->resuming = 0;
297
298 if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0 ||
299 (dum->port_status & USB_PORT_STAT_RESET) != 0) {
300 if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0 &&
301 (dum->old_status & USB_PORT_STAT_RESET) == 0 &&
302 dum->driver) {
303 stop_activity (dum);
304 spin_unlock (&dum->lock);
305 dum->driver->disconnect (&dum->gadget);
306 spin_lock (&dum->lock);
307 }
308 } else if (dum->active != dum->old_active) {
309 if (dum->old_active && dum->driver->suspend) {
310 spin_unlock (&dum->lock);
311 dum->driver->suspend (&dum->gadget);
312 spin_lock (&dum->lock);
313 } else if (!dum->old_active && dum->driver->resume) {
314 spin_unlock (&dum->lock);
315 dum->driver->resume (&dum->gadget);
316 spin_lock (&dum->lock);
317 }
318 }
319
320 dum->old_status = dum->port_status;
321 dum->old_active = dum->active;
322}
221 323
222/*-------------------------------------------------------------------------*/ 324/*-------------------------------------------------------------------------*/
223 325
@@ -324,7 +426,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
324 _ep->maxpacket = max; 426 _ep->maxpacket = max;
325 ep->desc = desc; 427 ep->desc = desc;
326 428
327 dev_dbg (dummy_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d\n", 429 dev_dbg (udc_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d\n",
328 _ep->name, 430 _ep->name,
329 desc->bEndpointAddress & 0x0f, 431 desc->bEndpointAddress & 0x0f,
330 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 432 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
@@ -345,22 +447,6 @@ done:
345 return retval; 447 return retval;
346} 448}
347 449
348/* called with spinlock held */
349static void nuke (struct dummy *dum, struct dummy_ep *ep)
350{
351 while (!list_empty (&ep->queue)) {
352 struct dummy_request *req;
353
354 req = list_entry (ep->queue.next, struct dummy_request, queue);
355 list_del_init (&req->queue);
356 req->req.status = -ESHUTDOWN;
357
358 spin_unlock (&dum->lock);
359 req->req.complete (&ep->ep, &req->req);
360 spin_lock (&dum->lock);
361 }
362}
363
364static int dummy_disable (struct usb_ep *_ep) 450static int dummy_disable (struct usb_ep *_ep)
365{ 451{
366 struct dummy_ep *ep; 452 struct dummy_ep *ep;
@@ -379,7 +465,7 @@ static int dummy_disable (struct usb_ep *_ep)
379 nuke (dum, ep); 465 nuke (dum, ep);
380 spin_unlock_irqrestore (&dum->lock, flags); 466 spin_unlock_irqrestore (&dum->lock, flags);
381 467
382 dev_dbg (dummy_dev(dum), "disabled %s\n", _ep->name); 468 dev_dbg (udc_dev(dum), "disabled %s\n", _ep->name);
383 return retval; 469 return retval;
384} 470}
385 471
@@ -474,7 +560,7 @@ dummy_queue (struct usb_ep *_ep, struct usb_request *_req, int mem_flags)
474 return -ESHUTDOWN; 560 return -ESHUTDOWN;
475 561
476#if 0 562#if 0
477 dev_dbg (dummy_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n", 563 dev_dbg (udc_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n",
478 ep, _req, _ep->name, _req->length, _req->buf); 564 ep, _req, _ep->name, _req->length, _req->buf);
479#endif 565#endif
480 566
@@ -537,7 +623,7 @@ static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req)
537 spin_unlock_irqrestore (&dum->lock, flags); 623 spin_unlock_irqrestore (&dum->lock, flags);
538 624
539 if (retval == 0) { 625 if (retval == 0) {
540 dev_dbg (dummy_dev(dum), 626 dev_dbg (udc_dev(dum),
541 "dequeued req %p from %s, len %d buf %p\n", 627 "dequeued req %p from %s, len %d buf %p\n",
542 req, _ep->name, _req->length, _req->buf); 628 req, _ep->name, _req->length, _req->buf);
543 _req->complete (_ep, _req); 629 _req->complete (_ep, _req);
@@ -601,13 +687,21 @@ static int dummy_wakeup (struct usb_gadget *_gadget)
601 struct dummy *dum; 687 struct dummy *dum;
602 688
603 dum = gadget_to_dummy (_gadget); 689 dum = gadget_to_dummy (_gadget);
604 if ((dum->devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) == 0 690 if (!(dum->devstatus & ( (1 << USB_DEVICE_B_HNP_ENABLE)
605 || !(dum->port_status & (1 << USB_PORT_FEAT_SUSPEND))) 691 | (1 << USB_DEVICE_REMOTE_WAKEUP))))
606 return -EINVAL; 692 return -EINVAL;
693 if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0)
694 return -ENOLINK;
695 if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 &&
696 dum->rh_state != DUMMY_RH_SUSPENDED)
697 return -EIO;
698
699 /* FIXME: What if the root hub is suspended but the port isn't? */
607 700
608 /* hub notices our request, issues downstream resume, etc */ 701 /* hub notices our request, issues downstream resume, etc */
609 dum->resuming = 1; 702 dum->resuming = 1;
610 dum->port_status |= (1 << USB_PORT_FEAT_C_SUSPEND); 703 dum->re_timeout = jiffies + msecs_to_jiffies(20);
704 mod_timer (&dummy_to_hcd (dum)->rh_timer, dum->re_timeout);
611 return 0; 705 return 0;
612} 706}
613 707
@@ -623,10 +717,26 @@ static int dummy_set_selfpowered (struct usb_gadget *_gadget, int value)
623 return 0; 717 return 0;
624} 718}
625 719
720static int dummy_pullup (struct usb_gadget *_gadget, int value)
721{
722 struct dummy *dum;
723 unsigned long flags;
724
725 dum = gadget_to_dummy (_gadget);
726 spin_lock_irqsave (&dum->lock, flags);
727 dum->pullup = (value != 0);
728 set_link_state (dum);
729 spin_unlock_irqrestore (&dum->lock, flags);
730
731 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
732 return 0;
733}
734
626static const struct usb_gadget_ops dummy_ops = { 735static const struct usb_gadget_ops dummy_ops = {
627 .get_frame = dummy_g_get_frame, 736 .get_frame = dummy_g_get_frame,
628 .wakeup = dummy_wakeup, 737 .wakeup = dummy_wakeup,
629 .set_selfpowered = dummy_set_selfpowered, 738 .set_selfpowered = dummy_set_selfpowered,
739 .pullup = dummy_pullup,
630}; 740};
631 741
632/*-------------------------------------------------------------------------*/ 742/*-------------------------------------------------------------------------*/
@@ -641,7 +751,7 @@ show_function (struct device *dev, struct device_attribute *attr, char *buf)
641 return 0; 751 return 0;
642 return scnprintf (buf, PAGE_SIZE, "%s\n", dum->driver->function); 752 return scnprintf (buf, PAGE_SIZE, "%s\n", dum->driver->function);
643} 753}
644DEVICE_ATTR (function, S_IRUGO, show_function, NULL); 754static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
645 755
646/*-------------------------------------------------------------------------*/ 756/*-------------------------------------------------------------------------*/
647 757
@@ -659,38 +769,6 @@ DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
659 * for each driver that registers: just add to a big root hub. 769 * for each driver that registers: just add to a big root hub.
660 */ 770 */
661 771
662static void
663dummy_udc_release (struct device *dev)
664{
665}
666
667static void
668dummy_pdev_release (struct device *dev)
669{
670}
671
672static int
673dummy_register_udc (struct dummy *dum)
674{
675 int rc;
676
677 strcpy (dum->gadget.dev.bus_id, "udc");
678 dum->gadget.dev.parent = dummy_dev(dum);
679 dum->gadget.dev.release = dummy_udc_release;
680
681 rc = device_register (&dum->gadget.dev);
682 if (rc == 0)
683 device_create_file (&dum->gadget.dev, &dev_attr_function);
684 return rc;
685}
686
687static void
688dummy_unregister_udc (struct dummy *dum)
689{
690 device_remove_file (&dum->gadget.dev, &dev_attr_function);
691 device_unregister (&dum->gadget.dev);
692}
693
694int 772int
695usb_gadget_register_driver (struct usb_gadget_driver *driver) 773usb_gadget_register_driver (struct usb_gadget_driver *driver)
696{ 774{
@@ -709,12 +787,8 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
709 * SLAVE side init ... the layer above hardware, which 787 * SLAVE side init ... the layer above hardware, which
710 * can't enumerate without help from the driver we're binding. 788 * can't enumerate without help from the driver we're binding.
711 */ 789 */
712 dum->gadget.name = gadget_name;
713 dum->gadget.ops = &dummy_ops;
714 dum->gadget.is_dualspeed = 1;
715 790
716 dum->devstatus = 0; 791 dum->devstatus = 0;
717 dum->resuming = 0;
718 792
719 INIT_LIST_HEAD (&dum->gadget.ep_list); 793 INIT_LIST_HEAD (&dum->gadget.ep_list);
720 for (i = 0; i < DUMMY_ENDPOINTS; i++) { 794 for (i = 0; i < DUMMY_ENDPOINTS; i++) {
@@ -740,7 +814,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
740 814
741 dum->driver = driver; 815 dum->driver = driver;
742 dum->gadget.dev.driver = &driver->driver; 816 dum->gadget.dev.driver = &driver->driver;
743 dev_dbg (dummy_dev(dum), "binding gadget driver '%s'\n", 817 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n",
744 driver->driver.name); 818 driver->driver.name);
745 if ((retval = driver->bind (&dum->gadget)) != 0) { 819 if ((retval = driver->bind (&dum->gadget)) != 0) {
746 dum->driver = NULL; 820 dum->driver = NULL;
@@ -748,42 +822,21 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
748 return retval; 822 return retval;
749 } 823 }
750 824
751 // FIXME: Check these calls for errors and re-order
752 driver->driver.bus = dum->gadget.dev.parent->bus; 825 driver->driver.bus = dum->gadget.dev.parent->bus;
753 driver_register (&driver->driver); 826 driver_register (&driver->driver);
754
755 device_bind_driver (&dum->gadget.dev); 827 device_bind_driver (&dum->gadget.dev);
756 828
757 /* khubd will enumerate this in a while */ 829 /* khubd will enumerate this in a while */
758 dum->port_status |= USB_PORT_STAT_CONNECTION 830 spin_lock_irq (&dum->lock);
759 | (1 << USB_PORT_FEAT_C_CONNECTION); 831 dum->pullup = 1;
832 set_link_state (dum);
833 spin_unlock_irq (&dum->lock);
834
835 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
760 return 0; 836 return 0;
761} 837}
762EXPORT_SYMBOL (usb_gadget_register_driver); 838EXPORT_SYMBOL (usb_gadget_register_driver);
763 839
764/* caller must hold lock */
765static void
766stop_activity (struct dummy *dum, struct usb_gadget_driver *driver)
767{
768 struct dummy_ep *ep;
769
770 /* prevent any more requests */
771 dum->address = 0;
772
773 /* The timer is left running so that outstanding URBs can fail */
774
775 /* nuke any pending requests first, so driver i/o is quiesced */
776 list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list)
777 nuke (dum, ep);
778
779 /* driver now does any non-usb quiescing necessary */
780 if (driver) {
781 spin_unlock (&dum->lock);
782 driver->disconnect (&dum->gadget);
783 spin_lock (&dum->lock);
784 }
785}
786
787int 840int
788usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 841usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
789{ 842{
@@ -795,35 +848,138 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
795 if (!driver || driver != dum->driver) 848 if (!driver || driver != dum->driver)
796 return -EINVAL; 849 return -EINVAL;
797 850
798 dev_dbg (dummy_dev(dum), "unregister gadget driver '%s'\n", 851 dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n",
799 driver->driver.name); 852 driver->driver.name);
800 853
801 spin_lock_irqsave (&dum->lock, flags); 854 spin_lock_irqsave (&dum->lock, flags);
802 stop_activity (dum, driver); 855 dum->pullup = 0;
803 dum->port_status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | 856 set_link_state (dum);
804 USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED);
805 dum->port_status |= (1 << USB_PORT_FEAT_C_CONNECTION);
806 spin_unlock_irqrestore (&dum->lock, flags); 857 spin_unlock_irqrestore (&dum->lock, flags);
807 858
808 driver->unbind (&dum->gadget); 859 driver->unbind (&dum->gadget);
809 dum->driver = NULL; 860 dum->driver = NULL;
810 861
811 device_release_driver (&dum->gadget.dev); 862 device_release_driver (&dum->gadget.dev);
812
813 driver_unregister (&driver->driver); 863 driver_unregister (&driver->driver);
814 864
865 spin_lock_irqsave (&dum->lock, flags);
866 dum->pullup = 0;
867 set_link_state (dum);
868 spin_unlock_irqrestore (&dum->lock, flags);
869
870 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
815 return 0; 871 return 0;
816} 872}
817EXPORT_SYMBOL (usb_gadget_unregister_driver); 873EXPORT_SYMBOL (usb_gadget_unregister_driver);
818 874
819#undef is_enabled 875#undef is_enabled
820 876
877/* just declare this in any driver that really need it */
878extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode);
879
821int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode) 880int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode)
822{ 881{
823 return -ENOSYS; 882 return -ENOSYS;
824} 883}
825EXPORT_SYMBOL (net2280_set_fifo_mode); 884EXPORT_SYMBOL (net2280_set_fifo_mode);
826 885
886
887/* The gadget structure is stored inside the hcd structure and will be
888 * released along with it. */
889static void
890dummy_gadget_release (struct device *dev)
891{
892#if 0 /* usb_bus_put isn't EXPORTed! */
893 struct dummy *dum = gadget_dev_to_dummy (dev);
894
895 usb_bus_put (&dummy_to_hcd (dum)->self);
896#endif
897}
898
899static int dummy_udc_probe (struct device *dev)
900{
901 struct dummy *dum = the_controller;
902 int rc;
903
904 dum->gadget.name = gadget_name;
905 dum->gadget.ops = &dummy_ops;
906 dum->gadget.is_dualspeed = 1;
907
908 /* maybe claim OTG support, though we won't complete HNP */
909 dum->gadget.is_otg = (dummy_to_hcd(dum)->self.otg_port != 0);
910
911 strcpy (dum->gadget.dev.bus_id, "gadget");
912 dum->gadget.dev.parent = dev;
913 dum->gadget.dev.release = dummy_gadget_release;
914 rc = device_register (&dum->gadget.dev);
915 if (rc < 0)
916 return rc;
917
918#if 0 /* usb_bus_get isn't EXPORTed! */
919 usb_bus_get (&dummy_to_hcd (dum)->self);
920#endif
921
922 dev_set_drvdata (dev, dum);
923 device_create_file (&dum->gadget.dev, &dev_attr_function);
924 return rc;
925}
926
927static int dummy_udc_remove (struct device *dev)
928{
929 struct dummy *dum = dev_get_drvdata (dev);
930
931 dev_set_drvdata (dev, NULL);
932 device_remove_file (&dum->gadget.dev, &dev_attr_function);
933 device_unregister (&dum->gadget.dev);
934 return 0;
935}
936
937static int dummy_udc_suspend (struct device *dev, pm_message_t state,
938 u32 level)
939{
940 struct dummy *dum = dev_get_drvdata(dev);
941
942 if (level != SUSPEND_DISABLE)
943 return 0;
944
945 dev_dbg (dev, "%s\n", __FUNCTION__);
946 spin_lock_irq (&dum->lock);
947 dum->udc_suspended = 1;
948 set_link_state (dum);
949 spin_unlock_irq (&dum->lock);
950
951 dev->power.power_state = state;
952 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
953 return 0;
954}
955
956static int dummy_udc_resume (struct device *dev, u32 level)
957{
958 struct dummy *dum = dev_get_drvdata(dev);
959
960 if (level != RESUME_ENABLE)
961 return 0;
962
963 dev_dbg (dev, "%s\n", __FUNCTION__);
964 spin_lock_irq (&dum->lock);
965 dum->udc_suspended = 0;
966 set_link_state (dum);
967 spin_unlock_irq (&dum->lock);
968
969 dev->power.power_state = PMSG_ON;
970 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
971 return 0;
972}
973
974static struct device_driver dummy_udc_driver = {
975 .name = (char *) gadget_name,
976 .bus = &platform_bus_type,
977 .probe = dummy_udc_probe,
978 .remove = dummy_udc_remove,
979 .suspend = dummy_udc_suspend,
980 .resume = dummy_udc_resume,
981};
982
827/*-------------------------------------------------------------------------*/ 983/*-------------------------------------------------------------------------*/
828 984
829/* MASTER/HOST SIDE DRIVER 985/* MASTER/HOST SIDE DRIVER
@@ -880,7 +1036,16 @@ static int dummy_urb_enqueue (
880 1036
881static int dummy_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 1037static int dummy_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
882{ 1038{
883 /* giveback happens automatically in timer callback */ 1039 struct dummy *dum;
1040 unsigned long flags;
1041
1042 /* giveback happens automatically in timer callback,
1043 * so make sure the callback happens */
1044 dum = hcd_to_dummy (hcd);
1045 spin_lock_irqsave (&dum->lock, flags);
1046 if (dum->rh_state != DUMMY_RH_RUNNING && !list_empty(&dum->urbp_list))
1047 mod_timer (&dum->timer, jiffies);
1048 spin_unlock_irqrestore (&dum->lock, flags);
884 return 0; 1049 return 0;
885} 1050}
886 1051
@@ -1025,7 +1190,6 @@ static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep)
1025 1190
1026 /* high bandwidth mode */ 1191 /* high bandwidth mode */
1027 tmp = le16_to_cpu(ep->desc->wMaxPacketSize); 1192 tmp = le16_to_cpu(ep->desc->wMaxPacketSize);
1028 tmp = le16_to_cpu (tmp);
1029 tmp = (tmp >> 11) & 0x03; 1193 tmp = (tmp >> 11) & 0x03;
1030 tmp *= 8 /* applies to entire frame */; 1194 tmp *= 8 /* applies to entire frame */;
1031 limit += limit * tmp; 1195 limit += limit * tmp;
@@ -1123,7 +1287,8 @@ restart:
1123 if (urb->status != -EINPROGRESS) { 1287 if (urb->status != -EINPROGRESS) {
1124 /* likely it was just unlinked */ 1288 /* likely it was just unlinked */
1125 goto return_urb; 1289 goto return_urb;
1126 } 1290 } else if (dum->rh_state != DUMMY_RH_RUNNING)
1291 continue;
1127 type = usb_pipetype (urb->pipe); 1292 type = usb_pipetype (urb->pipe);
1128 1293
1129 /* used up this frame's non-periodic bandwidth? 1294 /* used up this frame's non-periodic bandwidth?
@@ -1168,12 +1333,14 @@ restart:
1168 struct usb_ctrlrequest setup; 1333 struct usb_ctrlrequest setup;
1169 int value = 1; 1334 int value = 1;
1170 struct dummy_ep *ep2; 1335 struct dummy_ep *ep2;
1336 unsigned w_index;
1337 unsigned w_value;
1171 1338
1172 setup = *(struct usb_ctrlrequest*) urb->setup_packet; 1339 setup = *(struct usb_ctrlrequest*) urb->setup_packet;
1173 le16_to_cpus (&setup.wIndex); 1340 w_index = le16_to_cpu(setup.wIndex);
1174 le16_to_cpus (&setup.wValue); 1341 w_value = le16_to_cpu(setup.wValue);
1175 le16_to_cpus (&setup.wLength); 1342 if (le16_to_cpu(setup.wLength) !=
1176 if (setup.wLength != urb->transfer_buffer_length) { 1343 urb->transfer_buffer_length) {
1177 maybe_set_status (urb, -EOVERFLOW); 1344 maybe_set_status (urb, -EOVERFLOW);
1178 goto return_urb; 1345 goto return_urb;
1179 } 1346 }
@@ -1182,7 +1349,7 @@ restart:
1182 list_for_each_entry (req, &ep->queue, queue) { 1349 list_for_each_entry (req, &ep->queue, queue) {
1183 list_del_init (&req->queue); 1350 list_del_init (&req->queue);
1184 req->req.status = -EOVERFLOW; 1351 req->req.status = -EOVERFLOW;
1185 dev_dbg (dummy_dev(dum), "stale req = %p\n", 1352 dev_dbg (udc_dev(dum), "stale req = %p\n",
1186 req); 1353 req);
1187 1354
1188 spin_unlock (&dum->lock); 1355 spin_unlock (&dum->lock);
@@ -1203,31 +1370,40 @@ restart:
1203 case USB_REQ_SET_ADDRESS: 1370 case USB_REQ_SET_ADDRESS:
1204 if (setup.bRequestType != Dev_Request) 1371 if (setup.bRequestType != Dev_Request)
1205 break; 1372 break;
1206 dum->address = setup.wValue; 1373 dum->address = w_value;
1207 maybe_set_status (urb, 0); 1374 maybe_set_status (urb, 0);
1208 dev_dbg (dummy_dev(dum), "set_address = %d\n", 1375 dev_dbg (udc_dev(dum), "set_address = %d\n",
1209 setup.wValue); 1376 w_value);
1210 value = 0; 1377 value = 0;
1211 break; 1378 break;
1212 case USB_REQ_SET_FEATURE: 1379 case USB_REQ_SET_FEATURE:
1213 if (setup.bRequestType == Dev_Request) { 1380 if (setup.bRequestType == Dev_Request) {
1214 value = 0; 1381 value = 0;
1215 switch (setup.wValue) { 1382 switch (w_value) {
1216 case USB_DEVICE_REMOTE_WAKEUP: 1383 case USB_DEVICE_REMOTE_WAKEUP:
1217 break; 1384 break;
1385 case USB_DEVICE_B_HNP_ENABLE:
1386 dum->gadget.b_hnp_enable = 1;
1387 break;
1388 case USB_DEVICE_A_HNP_SUPPORT:
1389 dum->gadget.a_hnp_support = 1;
1390 break;
1391 case USB_DEVICE_A_ALT_HNP_SUPPORT:
1392 dum->gadget.a_alt_hnp_support
1393 = 1;
1394 break;
1218 default: 1395 default:
1219 value = -EOPNOTSUPP; 1396 value = -EOPNOTSUPP;
1220 } 1397 }
1221 if (value == 0) { 1398 if (value == 0) {
1222 dum->devstatus |= 1399 dum->devstatus |=
1223 (1 << setup.wValue); 1400 (1 << w_value);
1224 maybe_set_status (urb, 0); 1401 maybe_set_status (urb, 0);
1225 } 1402 }
1226 1403
1227 } else if (setup.bRequestType == Ep_Request) { 1404 } else if (setup.bRequestType == Ep_Request) {
1228 // endpoint halt 1405 // endpoint halt
1229 ep2 = find_endpoint (dum, 1406 ep2 = find_endpoint (dum, w_index);
1230 setup.wIndex);
1231 if (!ep2) { 1407 if (!ep2) {
1232 value = -EOPNOTSUPP; 1408 value = -EOPNOTSUPP;
1233 break; 1409 break;
@@ -1239,7 +1415,7 @@ restart:
1239 break; 1415 break;
1240 case USB_REQ_CLEAR_FEATURE: 1416 case USB_REQ_CLEAR_FEATURE:
1241 if (setup.bRequestType == Dev_Request) { 1417 if (setup.bRequestType == Dev_Request) {
1242 switch (setup.wValue) { 1418 switch (w_value) {
1243 case USB_DEVICE_REMOTE_WAKEUP: 1419 case USB_DEVICE_REMOTE_WAKEUP:
1244 dum->devstatus &= ~(1 << 1420 dum->devstatus &= ~(1 <<
1245 USB_DEVICE_REMOTE_WAKEUP); 1421 USB_DEVICE_REMOTE_WAKEUP);
@@ -1252,8 +1428,7 @@ restart:
1252 } 1428 }
1253 } else if (setup.bRequestType == Ep_Request) { 1429 } else if (setup.bRequestType == Ep_Request) {
1254 // endpoint halt 1430 // endpoint halt
1255 ep2 = find_endpoint (dum, 1431 ep2 = find_endpoint (dum, w_index);
1256 setup.wIndex);
1257 if (!ep2) { 1432 if (!ep2) {
1258 value = -EOPNOTSUPP; 1433 value = -EOPNOTSUPP;
1259 break; 1434 break;
@@ -1279,7 +1454,7 @@ restart:
1279 if (urb->transfer_buffer_length > 0) { 1454 if (urb->transfer_buffer_length > 0) {
1280 if (setup.bRequestType == 1455 if (setup.bRequestType ==
1281 Ep_InRequest) { 1456 Ep_InRequest) {
1282 ep2 = find_endpoint (dum, setup.wIndex); 1457 ep2 = find_endpoint (dum, w_index);
1283 if (!ep2) { 1458 if (!ep2) {
1284 value = -EOPNOTSUPP; 1459 value = -EOPNOTSUPP;
1285 break; 1460 break;
@@ -1321,7 +1496,7 @@ restart:
1321 1496
1322 if (value < 0) { 1497 if (value < 0) {
1323 if (value != -EOPNOTSUPP) 1498 if (value != -EOPNOTSUPP)
1324 dev_dbg (dummy_dev(dum), 1499 dev_dbg (udc_dev(dum),
1325 "setup --> %d\n", 1500 "setup --> %d\n",
1326 value); 1501 value);
1327 maybe_set_status (urb, -EPIPE); 1502 maybe_set_status (urb, -EPIPE);
@@ -1377,12 +1552,12 @@ return_urb:
1377 goto restart; 1552 goto restart;
1378 } 1553 }
1379 1554
1380 /* want a 1 msec delay here */ 1555 if (list_empty (&dum->urbp_list)) {
1381 if (!list_empty (&dum->urbp_list))
1382 mod_timer (&dum->timer, jiffies + msecs_to_jiffies(1));
1383 else {
1384 usb_put_dev (dum->udev); 1556 usb_put_dev (dum->udev);
1385 dum->udev = NULL; 1557 dum->udev = NULL;
1558 } else if (dum->rh_state == DUMMY_RH_RUNNING) {
1559 /* want a 1 msec delay here */
1560 mod_timer (&dum->timer, jiffies + msecs_to_jiffies(1));
1386 } 1561 }
1387 1562
1388 spin_unlock_irqrestore (&dum->lock, flags); 1563 spin_unlock_irqrestore (&dum->lock, flags);
@@ -1391,29 +1566,39 @@ return_urb:
1391/*-------------------------------------------------------------------------*/ 1566/*-------------------------------------------------------------------------*/
1392 1567
1393#define PORT_C_MASK \ 1568#define PORT_C_MASK \
1394 ((1 << USB_PORT_FEAT_C_CONNECTION) \ 1569 ((USB_PORT_STAT_C_CONNECTION \
1395 | (1 << USB_PORT_FEAT_C_ENABLE) \ 1570 | USB_PORT_STAT_C_ENABLE \
1396 | (1 << USB_PORT_FEAT_C_SUSPEND) \ 1571 | USB_PORT_STAT_C_SUSPEND \
1397 | (1 << USB_PORT_FEAT_C_OVER_CURRENT) \ 1572 | USB_PORT_STAT_C_OVERCURRENT \
1398 | (1 << USB_PORT_FEAT_C_RESET)) 1573 | USB_PORT_STAT_C_RESET) << 16)
1399 1574
1400static int dummy_hub_status (struct usb_hcd *hcd, char *buf) 1575static int dummy_hub_status (struct usb_hcd *hcd, char *buf)
1401{ 1576{
1402 struct dummy *dum; 1577 struct dummy *dum;
1403 unsigned long flags; 1578 unsigned long flags;
1404 int retval; 1579 int retval = 0;
1405 1580
1406 dum = hcd_to_dummy (hcd); 1581 dum = hcd_to_dummy (hcd);
1407 1582
1408 spin_lock_irqsave (&dum->lock, flags); 1583 spin_lock_irqsave (&dum->lock, flags);
1409 if (!(dum->port_status & PORT_C_MASK)) 1584 if (hcd->state != HC_STATE_RUNNING)
1410 retval = 0; 1585 goto done;
1411 else { 1586
1587 if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) {
1588 dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16);
1589 dum->port_status &= ~USB_PORT_STAT_SUSPEND;
1590 set_link_state (dum);
1591 }
1592
1593 if ((dum->port_status & PORT_C_MASK) != 0) {
1412 *buf = (1 << 1); 1594 *buf = (1 << 1);
1413 dev_dbg (dummy_dev(dum), "port status 0x%08x has changes\n", 1595 dev_dbg (dummy_dev(dum), "port status 0x%08x has changes\n",
1414 dum->port_status); 1596 dum->port_status);
1415 retval = 1; 1597 retval = 1;
1598 if (dum->rh_state == DUMMY_RH_SUSPENDED)
1599 usb_hcd_resume_root_hub (hcd);
1416 } 1600 }
1601done:
1417 spin_unlock_irqrestore (&dum->lock, flags); 1602 spin_unlock_irqrestore (&dum->lock, flags);
1418 return retval; 1603 return retval;
1419} 1604}
@@ -1424,7 +1609,8 @@ hub_descriptor (struct usb_hub_descriptor *desc)
1424 memset (desc, 0, sizeof *desc); 1609 memset (desc, 0, sizeof *desc);
1425 desc->bDescriptorType = 0x29; 1610 desc->bDescriptorType = 0x29;
1426 desc->bDescLength = 9; 1611 desc->bDescLength = 9;
1427 desc->wHubCharacteristics = __constant_cpu_to_le16 (0x0001); 1612 desc->wHubCharacteristics = (__force __u16)
1613 (__constant_cpu_to_le16 (0x0001));
1428 desc->bNbrPorts = 1; 1614 desc->bNbrPorts = 1;
1429 desc->bitmap [0] = 0xff; 1615 desc->bitmap [0] = 0xff;
1430 desc->bitmap [1] = 0xff; 1616 desc->bitmap [1] = 0xff;
@@ -1442,6 +1628,9 @@ static int dummy_hub_control (
1442 int retval = 0; 1628 int retval = 0;
1443 unsigned long flags; 1629 unsigned long flags;
1444 1630
1631 if (hcd->state != HC_STATE_RUNNING)
1632 return -ETIMEDOUT;
1633
1445 dum = hcd_to_dummy (hcd); 1634 dum = hcd_to_dummy (hcd);
1446 spin_lock_irqsave (&dum->lock, flags); 1635 spin_lock_irqsave (&dum->lock, flags);
1447 switch (typeReq) { 1636 switch (typeReq) {
@@ -1450,27 +1639,27 @@ static int dummy_hub_control (
1450 case ClearPortFeature: 1639 case ClearPortFeature:
1451 switch (wValue) { 1640 switch (wValue) {
1452 case USB_PORT_FEAT_SUSPEND: 1641 case USB_PORT_FEAT_SUSPEND:
1453 if (dum->port_status & (1 << USB_PORT_FEAT_SUSPEND)) { 1642 if (dum->port_status & USB_PORT_STAT_SUSPEND) {
1454 /* 20msec resume signaling */ 1643 /* 20msec resume signaling */
1455 dum->resuming = 1; 1644 dum->resuming = 1;
1456 dum->re_timeout = jiffies + 1645 dum->re_timeout = jiffies +
1457 msecs_to_jiffies(20); 1646 msecs_to_jiffies(20);
1458 } 1647 }
1459 break; 1648 break;
1460 case USB_PORT_FEAT_POWER: 1649 case USB_PORT_FEAT_POWER:
1461 dum->port_status = 0; 1650 if (dum->port_status & USB_PORT_STAT_POWER)
1462 dum->resuming = 0; 1651 dev_dbg (dummy_dev(dum), "power-off\n");
1463 stop_activity(dum, dum->driver); 1652 /* FALLS THROUGH */
1464 break;
1465 default: 1653 default:
1466 dum->port_status &= ~(1 << wValue); 1654 dum->port_status &= ~(1 << wValue);
1655 set_link_state (dum);
1467 } 1656 }
1468 break; 1657 break;
1469 case GetHubDescriptor: 1658 case GetHubDescriptor:
1470 hub_descriptor ((struct usb_hub_descriptor *) buf); 1659 hub_descriptor ((struct usb_hub_descriptor *) buf);
1471 break; 1660 break;
1472 case GetHubStatus: 1661 case GetHubStatus:
1473 *(u32 *) buf = __constant_cpu_to_le32 (0); 1662 *(__le32 *) buf = __constant_cpu_to_le32 (0);
1474 break; 1663 break;
1475 case GetPortStatus: 1664 case GetPortStatus:
1476 if (wIndex != 1) 1665 if (wIndex != 1)
@@ -1479,23 +1668,16 @@ static int dummy_hub_control (
1479 /* whoever resets or resumes must GetPortStatus to 1668 /* whoever resets or resumes must GetPortStatus to
1480 * complete it!! 1669 * complete it!!
1481 */ 1670 */
1482 if (dum->resuming && time_after (jiffies, dum->re_timeout)) { 1671 if (dum->resuming &&
1483 dum->port_status |= (1 << USB_PORT_FEAT_C_SUSPEND); 1672 time_after_eq (jiffies, dum->re_timeout)) {
1484 dum->port_status &= ~(1 << USB_PORT_FEAT_SUSPEND); 1673 dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16);
1485 dum->resuming = 0; 1674 dum->port_status &= ~USB_PORT_STAT_SUSPEND;
1486 dum->re_timeout = 0;
1487 if (dum->driver && dum->driver->resume) {
1488 spin_unlock (&dum->lock);
1489 dum->driver->resume (&dum->gadget);
1490 spin_lock (&dum->lock);
1491 }
1492 } 1675 }
1493 if ((dum->port_status & (1 << USB_PORT_FEAT_RESET)) != 0 1676 if ((dum->port_status & USB_PORT_STAT_RESET) != 0 &&
1494 && time_after (jiffies, dum->re_timeout)) { 1677 time_after_eq (jiffies, dum->re_timeout)) {
1495 dum->port_status |= (1 << USB_PORT_FEAT_C_RESET); 1678 dum->port_status |= (USB_PORT_STAT_C_RESET << 16);
1496 dum->port_status &= ~(1 << USB_PORT_FEAT_RESET); 1679 dum->port_status &= ~USB_PORT_STAT_RESET;
1497 dum->re_timeout = 0; 1680 if (dum->pullup) {
1498 if (dum->driver) {
1499 dum->port_status |= USB_PORT_STAT_ENABLE; 1681 dum->port_status |= USB_PORT_STAT_ENABLE;
1500 /* give it the best speed we agree on */ 1682 /* give it the best speed we agree on */
1501 dum->gadget.speed = dum->driver->speed; 1683 dum->gadget.speed = dum->driver->speed;
@@ -1516,8 +1698,9 @@ static int dummy_hub_control (
1516 } 1698 }
1517 } 1699 }
1518 } 1700 }
1519 ((u16 *) buf)[0] = cpu_to_le16 (dum->port_status); 1701 set_link_state (dum);
1520 ((u16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16); 1702 ((__le16 *) buf)[0] = cpu_to_le16 (dum->port_status);
1703 ((__le16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16);
1521 break; 1704 break;
1522 case SetHubFeature: 1705 case SetHubFeature:
1523 retval = -EPIPE; 1706 retval = -EPIPE;
@@ -1525,36 +1708,37 @@ static int dummy_hub_control (
1525 case SetPortFeature: 1708 case SetPortFeature:
1526 switch (wValue) { 1709 switch (wValue) {
1527 case USB_PORT_FEAT_SUSPEND: 1710 case USB_PORT_FEAT_SUSPEND:
1528 if ((dum->port_status & (1 << USB_PORT_FEAT_SUSPEND)) 1711 if (dum->active) {
1529 == 0) { 1712 dum->port_status |= USB_PORT_STAT_SUSPEND;
1530 dum->port_status |= 1713
1531 (1 << USB_PORT_FEAT_SUSPEND); 1714 /* HNP would happen here; for now we
1532 if (dum->driver && dum->driver->suspend) { 1715 * assume b_bus_req is always true.
1533 spin_unlock (&dum->lock); 1716 */
1534 dum->driver->suspend (&dum->gadget); 1717 set_link_state (dum);
1535 spin_lock (&dum->lock); 1718 if (((1 << USB_DEVICE_B_HNP_ENABLE)
1536 } 1719 & dum->devstatus) != 0)
1720 dev_dbg (dummy_dev(dum),
1721 "no HNP yet!\n");
1537 } 1722 }
1538 break; 1723 break;
1724 case USB_PORT_FEAT_POWER:
1725 dum->port_status |= USB_PORT_STAT_POWER;
1726 set_link_state (dum);
1727 break;
1539 case USB_PORT_FEAT_RESET: 1728 case USB_PORT_FEAT_RESET:
1540 /* if it's already running, disconnect first */ 1729 /* if it's already enabled, disable */
1541 if (dum->port_status & USB_PORT_STAT_ENABLE) { 1730 dum->port_status &= ~(USB_PORT_STAT_ENABLE
1542 dum->port_status &= ~(USB_PORT_STAT_ENABLE 1731 | USB_PORT_STAT_LOW_SPEED
1543 | USB_PORT_STAT_LOW_SPEED 1732 | USB_PORT_STAT_HIGH_SPEED);
1544 | USB_PORT_STAT_HIGH_SPEED); 1733 dum->devstatus = 0;
1545 if (dum->driver) {
1546 dev_dbg (dummy_dev(dum),
1547 "disconnect\n");
1548 stop_activity (dum, dum->driver);
1549 }
1550
1551 /* FIXME test that code path! */
1552 }
1553 /* 50msec reset signaling */ 1734 /* 50msec reset signaling */
1554 dum->re_timeout = jiffies + msecs_to_jiffies(50); 1735 dum->re_timeout = jiffies + msecs_to_jiffies(50);
1555 /* FALLTHROUGH */ 1736 /* FALLS THROUGH */
1556 default: 1737 default:
1557 dum->port_status |= (1 << wValue); 1738 if ((dum->port_status & USB_PORT_STAT_POWER) != 0) {
1739 dum->port_status |= (1 << wValue);
1740 set_link_state (dum);
1741 }
1558 } 1742 }
1559 break; 1743 break;
1560 1744
@@ -1567,9 +1751,35 @@ static int dummy_hub_control (
1567 retval = -EPIPE; 1751 retval = -EPIPE;
1568 } 1752 }
1569 spin_unlock_irqrestore (&dum->lock, flags); 1753 spin_unlock_irqrestore (&dum->lock, flags);
1754
1755 if ((dum->port_status & PORT_C_MASK) != 0)
1756 usb_hcd_poll_rh_status (hcd);
1570 return retval; 1757 return retval;
1571} 1758}
1572 1759
1760static int dummy_hub_suspend (struct usb_hcd *hcd)
1761{
1762 struct dummy *dum = hcd_to_dummy (hcd);
1763
1764 spin_lock_irq (&dum->lock);
1765 dum->rh_state = DUMMY_RH_SUSPENDED;
1766 set_link_state (dum);
1767 spin_unlock_irq (&dum->lock);
1768 return 0;
1769}
1770
1771static int dummy_hub_resume (struct usb_hcd *hcd)
1772{
1773 struct dummy *dum = hcd_to_dummy (hcd);
1774
1775 spin_lock_irq (&dum->lock);
1776 dum->rh_state = DUMMY_RH_RUNNING;
1777 set_link_state (dum);
1778 if (!list_empty(&dum->urbp_list))
1779 mod_timer (&dum->timer, jiffies);
1780 spin_unlock_irq (&dum->lock);
1781 return 0;
1782}
1573 1783
1574/*-------------------------------------------------------------------------*/ 1784/*-------------------------------------------------------------------------*/
1575 1785
@@ -1625,8 +1835,6 @@ static DEVICE_ATTR (urbs, S_IRUGO, show_urbs, NULL);
1625static int dummy_start (struct usb_hcd *hcd) 1835static int dummy_start (struct usb_hcd *hcd)
1626{ 1836{
1627 struct dummy *dum; 1837 struct dummy *dum;
1628 struct usb_device *root;
1629 int retval;
1630 1838
1631 dum = hcd_to_dummy (hcd); 1839 dum = hcd_to_dummy (hcd);
1632 1840
@@ -1639,38 +1847,22 @@ static int dummy_start (struct usb_hcd *hcd)
1639 init_timer (&dum->timer); 1847 init_timer (&dum->timer);
1640 dum->timer.function = dummy_timer; 1848 dum->timer.function = dummy_timer;
1641 dum->timer.data = (unsigned long) dum; 1849 dum->timer.data = (unsigned long) dum;
1850 dum->rh_state = DUMMY_RH_RUNNING;
1642 1851
1643 INIT_LIST_HEAD (&dum->urbp_list); 1852 INIT_LIST_HEAD (&dum->urbp_list);
1644 1853
1645 root = usb_alloc_dev (NULL, &hcd->self, 0);
1646 if (!root)
1647 return -ENOMEM;
1648
1649 /* root hub enters addressed state... */
1650 hcd->state = HC_STATE_RUNNING;
1651 root->speed = USB_SPEED_HIGH;
1652
1653 /* ...then configured, so khubd sees us. */
1654 if ((retval = usb_hcd_register_root_hub (root, hcd)) != 0) {
1655 goto err1;
1656 }
1657
1658 /* only show a low-power port: just 8mA */ 1854 /* only show a low-power port: just 8mA */
1659 hub_set_power_budget (root, 8); 1855 hcd->power_budget = 8;
1856 hcd->state = HC_STATE_RUNNING;
1857 hcd->uses_new_polling = 1;
1660 1858
1661 if ((retval = dummy_register_udc (dum)) != 0) 1859#ifdef CONFIG_USB_OTG
1662 goto err2; 1860 hcd->self.otg_port = 1;
1861#endif
1663 1862
1664 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */ 1863 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */
1665 device_create_file (dummy_dev(dum), &dev_attr_urbs); 1864 device_create_file (dummy_dev(dum), &dev_attr_urbs);
1666 return 0; 1865 return 0;
1667
1668 err2:
1669 usb_disconnect (&hcd->self.root_hub);
1670 err1:
1671 usb_put_dev (root);
1672 hcd->state = HC_STATE_QUIESCING;
1673 return retval;
1674} 1866}
1675 1867
1676static void dummy_stop (struct usb_hcd *hcd) 1868static void dummy_stop (struct usb_hcd *hcd)
@@ -1680,10 +1872,7 @@ static void dummy_stop (struct usb_hcd *hcd)
1680 dum = hcd_to_dummy (hcd); 1872 dum = hcd_to_dummy (hcd);
1681 1873
1682 device_remove_file (dummy_dev(dum), &dev_attr_urbs); 1874 device_remove_file (dummy_dev(dum), &dev_attr_urbs);
1683
1684 usb_gadget_unregister_driver (dum->driver); 1875 usb_gadget_unregister_driver (dum->driver);
1685 dummy_unregister_udc (dum);
1686
1687 dev_info (dummy_dev(dum), "stopped\n"); 1876 dev_info (dummy_dev(dum), "stopped\n");
1688} 1877}
1689 1878
@@ -1711,9 +1900,11 @@ static const struct hc_driver dummy_hcd = {
1711 1900
1712 .hub_status_data = dummy_hub_status, 1901 .hub_status_data = dummy_hub_status,
1713 .hub_control = dummy_hub_control, 1902 .hub_control = dummy_hub_control,
1903 .hub_suspend = dummy_hub_suspend,
1904 .hub_resume = dummy_hub_resume,
1714}; 1905};
1715 1906
1716static int dummy_probe (struct device *dev) 1907static int dummy_hcd_probe (struct device *dev)
1717{ 1908{
1718 struct usb_hcd *hcd; 1909 struct usb_hcd *hcd;
1719 int retval; 1910 int retval;
@@ -1733,7 +1924,7 @@ static int dummy_probe (struct device *dev)
1733 return retval; 1924 return retval;
1734} 1925}
1735 1926
1736static void dummy_remove (struct device *dev) 1927static int dummy_hcd_remove (struct device *dev)
1737{ 1928{
1738 struct usb_hcd *hcd; 1929 struct usb_hcd *hcd;
1739 1930
@@ -1741,53 +1932,127 @@ static void dummy_remove (struct device *dev)
1741 usb_remove_hcd (hcd); 1932 usb_remove_hcd (hcd);
1742 usb_put_hcd (hcd); 1933 usb_put_hcd (hcd);
1743 the_controller = NULL; 1934 the_controller = NULL;
1935 return 0;
1744} 1936}
1745 1937
1746/*-------------------------------------------------------------------------*/ 1938static int dummy_hcd_suspend (struct device *dev, pm_message_t state,
1747 1939 u32 level)
1748static int dummy_pdev_detect (void)
1749{ 1940{
1750 int retval; 1941 struct usb_hcd *hcd;
1751 1942
1752 retval = driver_register (&dummy_driver); 1943 if (level != SUSPEND_DISABLE)
1753 if (retval < 0) 1944 return 0;
1754 return retval; 1945
1946 dev_dbg (dev, "%s\n", __FUNCTION__);
1947 hcd = dev_get_drvdata (dev);
1755 1948
1756 the_pdev.name = "hc"; 1949#ifndef CONFIG_USB_SUSPEND
1757 the_pdev.dev.driver = &dummy_driver; 1950 /* Otherwise this would never happen */
1758 the_pdev.dev.release = dummy_pdev_release; 1951 usb_lock_device (hcd->self.root_hub);
1952 dummy_hub_suspend (hcd);
1953 usb_unlock_device (hcd->self.root_hub);
1954#endif
1759 1955
1760 retval = platform_device_register (&the_pdev); 1956 hcd->state = HC_STATE_SUSPENDED;
1761 if (retval < 0) 1957 return 0;
1762 driver_unregister (&dummy_driver);
1763 return retval;
1764} 1958}
1765 1959
1766static void dummy_pdev_remove (void) 1960static int dummy_hcd_resume (struct device *dev, u32 level)
1767{ 1961{
1768 platform_device_unregister (&the_pdev); 1962 struct usb_hcd *hcd;
1769 driver_unregister (&dummy_driver); 1963
1964 if (level != RESUME_ENABLE)
1965 return 0;
1966
1967 dev_dbg (dev, "%s\n", __FUNCTION__);
1968 hcd = dev_get_drvdata (dev);
1969 hcd->state = HC_STATE_RUNNING;
1970
1971#ifndef CONFIG_USB_SUSPEND
1972 /* Otherwise this would never happen */
1973 usb_lock_device (hcd->self.root_hub);
1974 dummy_hub_resume (hcd);
1975 usb_unlock_device (hcd->self.root_hub);
1976#endif
1977
1978 usb_hcd_poll_rh_status (hcd);
1979 return 0;
1770} 1980}
1771 1981
1982static struct device_driver dummy_hcd_driver = {
1983 .name = (char *) driver_name,
1984 .bus = &platform_bus_type,
1985 .probe = dummy_hcd_probe,
1986 .remove = dummy_hcd_remove,
1987 .suspend = dummy_hcd_suspend,
1988 .resume = dummy_hcd_resume,
1989};
1990
1772/*-------------------------------------------------------------------------*/ 1991/*-------------------------------------------------------------------------*/
1773 1992
1993/* These don't need to do anything because the pdev structures are
1994 * statically allocated. */
1995static void
1996dummy_udc_release (struct device *dev) {}
1997
1998static void
1999dummy_hcd_release (struct device *dev) {}
2000
2001static struct platform_device the_udc_pdev = {
2002 .name = (char *) gadget_name,
2003 .id = -1,
2004 .dev = {
2005 .release = dummy_udc_release,
2006 },
2007};
2008
2009static struct platform_device the_hcd_pdev = {
2010 .name = (char *) driver_name,
2011 .id = -1,
2012 .dev = {
2013 .release = dummy_hcd_release,
2014 },
2015};
2016
1774static int __init init (void) 2017static int __init init (void)
1775{ 2018{
1776 int retval; 2019 int retval;
1777 2020
1778 if (usb_disabled ()) 2021 if (usb_disabled ())
1779 return -ENODEV; 2022 return -ENODEV;
1780 if ((retval = dummy_pdev_detect ()) != 0) 2023
2024 retval = driver_register (&dummy_hcd_driver);
2025 if (retval < 0)
1781 return retval; 2026 return retval;
1782 if ((retval = dummy_probe (&the_pdev.dev)) != 0) 2027
1783 dummy_pdev_remove (); 2028 retval = driver_register (&dummy_udc_driver);
2029 if (retval < 0)
2030 goto err_register_udc_driver;
2031
2032 retval = platform_device_register (&the_hcd_pdev);
2033 if (retval < 0)
2034 goto err_register_hcd;
2035
2036 retval = platform_device_register (&the_udc_pdev);
2037 if (retval < 0)
2038 goto err_register_udc;
2039 return retval;
2040
2041err_register_udc:
2042 platform_device_unregister (&the_hcd_pdev);
2043err_register_hcd:
2044 driver_unregister (&dummy_udc_driver);
2045err_register_udc_driver:
2046 driver_unregister (&dummy_hcd_driver);
1784 return retval; 2047 return retval;
1785} 2048}
1786module_init (init); 2049module_init (init);
1787 2050
1788static void __exit cleanup (void) 2051static void __exit cleanup (void)
1789{ 2052{
1790 dummy_remove (&the_pdev.dev); 2053 platform_device_unregister (&the_udc_pdev);
1791 dummy_pdev_remove (); 2054 platform_device_unregister (&the_hcd_pdev);
2055 driver_unregister (&dummy_udc_driver);
2056 driver_unregister (&dummy_hcd_driver);
1792} 2057}
1793module_exit (cleanup); 2058module_exit (cleanup);
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 3f783cbdc7c3..5bb53ae88969 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -84,18 +84,19 @@
84 */ 84 */
85 85
86#define DRIVER_DESC "Ethernet Gadget" 86#define DRIVER_DESC "Ethernet Gadget"
87#define DRIVER_VERSION "Equinox 2004" 87#define DRIVER_VERSION "May Day 2005"
88 88
89static const char shortname [] = "ether"; 89static const char shortname [] = "ether";
90static const char driver_desc [] = DRIVER_DESC; 90static const char driver_desc [] = DRIVER_DESC;
91 91
92#define RX_EXTRA 20 /* guard against rx overflows */ 92#define RX_EXTRA 20 /* guard against rx overflows */
93 93
94#ifdef CONFIG_USB_ETH_RNDIS
95#include "rndis.h" 94#include "rndis.h"
96#else 95
97#define rndis_init() 0 96#ifndef CONFIG_USB_ETH_RNDIS
98#define rndis_exit() do{}while(0) 97#define rndis_uninit(x) do{}while(0)
98#define rndis_deregister(c) do{}while(0)
99#define rndis_exit() do{}while(0)
99#endif 100#endif
100 101
101/* CDC and RNDIS support the same host-chosen outgoing packet filters. */ 102/* CDC and RNDIS support the same host-chosen outgoing packet filters. */
@@ -140,9 +141,6 @@ struct eth_dev {
140 * It also ASSUMES a self-powered device, without remote wakeup, 141 * It also ASSUMES a self-powered device, without remote wakeup,
141 * although remote wakeup support would make sense. 142 * although remote wakeup support would make sense.
142 */ 143 */
143static const char *EP_IN_NAME;
144static const char *EP_OUT_NAME;
145static const char *EP_STATUS_NAME;
146 144
147/*-------------------------------------------------------------------------*/ 145/*-------------------------------------------------------------------------*/
148 146
@@ -312,6 +310,7 @@ static inline int rndis_active(struct eth_dev *dev)
312#define FS_BPS (19 * 64 * 1 * 1000 * 8) 310#define FS_BPS (19 * 64 * 1 * 1000 * 8)
313 311
314#ifdef CONFIG_USB_GADGET_DUALSPEED 312#ifdef CONFIG_USB_GADGET_DUALSPEED
313#define DEVSPEED USB_SPEED_HIGH
315 314
316static unsigned qmult = 5; 315static unsigned qmult = 5;
317module_param (qmult, uint, S_IRUGO|S_IWUSR); 316module_param (qmult, uint, S_IRUGO|S_IWUSR);
@@ -330,6 +329,8 @@ static inline int BITRATE(struct usb_gadget *g)
330} 329}
331 330
332#else /* full speed (low speed doesn't do bulk) */ 331#else /* full speed (low speed doesn't do bulk) */
332#define DEVSPEED USB_SPEED_FULL
333
333#define qlen(gadget) DEFAULT_QLEN 334#define qlen(gadget) DEFAULT_QLEN
334 335
335static inline int BITRATE(struct usb_gadget *g) 336static inline int BITRATE(struct usb_gadget *g)
@@ -395,7 +396,8 @@ static inline int BITRATE(struct usb_gadget *g)
395#define STRING_SUBSET 8 396#define STRING_SUBSET 8
396#define STRING_RNDIS 9 397#define STRING_RNDIS 9
397 398
398#define USB_BUFSIZ 256 /* holds our biggest descriptor */ 399/* holds our biggest descriptor (or RNDIS response) */
400#define USB_BUFSIZ 256
399 401
400/* 402/*
401 * This device advertises one configuration, eth_config, unless RNDIS 403 * This device advertises one configuration, eth_config, unless RNDIS
@@ -538,7 +540,7 @@ static const struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor = {
538 .bDataInterface = 0x01, 540 .bDataInterface = 0x01,
539}; 541};
540 542
541static struct usb_cdc_acm_descriptor acm_descriptor = { 543static const struct usb_cdc_acm_descriptor acm_descriptor = {
542 .bLength = sizeof acm_descriptor, 544 .bLength = sizeof acm_descriptor,
543 .bDescriptorType = USB_DT_CS_INTERFACE, 545 .bDescriptorType = USB_DT_CS_INTERFACE,
544 .bDescriptorSubType = USB_CDC_ACM_TYPE, 546 .bDescriptorSubType = USB_CDC_ACM_TYPE,
@@ -846,7 +848,7 @@ static const struct usb_descriptor_header *hs_rndis_function [] = {
846#else 848#else
847 849
848/* if there's no high speed support, maxpacket doesn't change. */ 850/* if there's no high speed support, maxpacket doesn't change. */
849#define ep_desc(g,hs,fs) fs 851#define ep_desc(g,hs,fs) (((void)(g)), (fs))
850 852
851static inline void __init hs_subset_descriptors(void) 853static inline void __init hs_subset_descriptors(void)
852{ 854{
@@ -946,10 +948,31 @@ config_buf (enum usb_device_speed speed,
946static void eth_start (struct eth_dev *dev, int gfp_flags); 948static void eth_start (struct eth_dev *dev, int gfp_flags);
947static int alloc_requests (struct eth_dev *dev, unsigned n, int gfp_flags); 949static int alloc_requests (struct eth_dev *dev, unsigned n, int gfp_flags);
948 950
949#ifdef DEV_CONFIG_CDC 951static int
950static inline int ether_alt_ep_setup (struct eth_dev *dev, struct usb_ep *ep) 952set_ether_config (struct eth_dev *dev, int gfp_flags)
951{ 953{
952 const struct usb_endpoint_descriptor *d; 954 int result = 0;
955 struct usb_gadget *gadget = dev->gadget;
956
957 /* status endpoint used for RNDIS and (optionally) CDC */
958 if (!subset_active(dev) && dev->status_ep) {
959 dev->status = ep_desc (gadget, &hs_status_desc,
960 &fs_status_desc);
961 dev->status_ep->driver_data = dev;
962
963 result = usb_ep_enable (dev->status_ep, dev->status);
964 if (result != 0) {
965 DEBUG (dev, "enable %s --> %d\n",
966 dev->status_ep->name, result);
967 goto done;
968 }
969 }
970
971 dev->in = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc);
972 dev->in_ep->driver_data = dev;
973
974 dev->out = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc);
975 dev->out_ep->driver_data = dev;
953 976
954 /* With CDC, the host isn't allowed to use these two data 977 /* With CDC, the host isn't allowed to use these two data
955 * endpoints in the default altsetting for the interface. 978 * endpoints in the default altsetting for the interface.
@@ -959,135 +982,33 @@ static inline int ether_alt_ep_setup (struct eth_dev *dev, struct usb_ep *ep)
959 * a side effect of setting a packet filter. Deactivation is 982 * a side effect of setting a packet filter. Deactivation is
960 * from REMOTE_NDIS_HALT_MSG, reset from REMOTE_NDIS_RESET_MSG. 983 * from REMOTE_NDIS_HALT_MSG, reset from REMOTE_NDIS_RESET_MSG.
961 */ 984 */
962 985 if (!cdc_active(dev)) {
963 /* one endpoint writes data back IN to the host */ 986 result = usb_ep_enable (dev->in_ep, dev->in);
964 if (strcmp (ep->name, EP_IN_NAME) == 0) { 987 if (result != 0) {
965 d = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc); 988 DEBUG(dev, "enable %s --> %d\n",
966 ep->driver_data = dev; 989 dev->in_ep->name, result);
967 dev->in = d; 990 goto done;
968
969 /* one endpoint just reads OUT packets */
970 } else if (strcmp (ep->name, EP_OUT_NAME) == 0) {
971 d = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc);
972 ep->driver_data = dev;
973 dev->out = d;
974
975 /* optional status/notification endpoint */
976 } else if (EP_STATUS_NAME &&
977 strcmp (ep->name, EP_STATUS_NAME) == 0) {
978 int result;
979
980 d = ep_desc (dev->gadget, &hs_status_desc, &fs_status_desc);
981 result = usb_ep_enable (ep, d);
982 if (result < 0)
983 return result;
984
985 ep->driver_data = dev;
986 dev->status = d;
987 }
988 return 0;
989}
990#endif
991
992#if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS)
993static inline int ether_ep_setup (struct eth_dev *dev, struct usb_ep *ep)
994{
995 int result;
996 const struct usb_endpoint_descriptor *d;
997
998 /* CDC subset is simpler: if the device is there,
999 * it's live with rx and tx endpoints.
1000 *
1001 * Do this as a shortcut for RNDIS too.
1002 */
1003
1004 /* one endpoint writes data back IN to the host */
1005 if (strcmp (ep->name, EP_IN_NAME) == 0) {
1006 d = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc);
1007 result = usb_ep_enable (ep, d);
1008 if (result < 0)
1009 return result;
1010
1011 ep->driver_data = dev;
1012 dev->in = d;
1013
1014 /* one endpoint just reads OUT packets */
1015 } else if (strcmp (ep->name, EP_OUT_NAME) == 0) {
1016 d = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc);
1017 result = usb_ep_enable (ep, d);
1018 if (result < 0)
1019 return result;
1020
1021 ep->driver_data = dev;
1022 dev->out = d;
1023 }
1024
1025 return 0;
1026}
1027#endif
1028
1029static int
1030set_ether_config (struct eth_dev *dev, int gfp_flags)
1031{
1032 int result = 0;
1033 struct usb_ep *ep;
1034 struct usb_gadget *gadget = dev->gadget;
1035
1036 gadget_for_each_ep (ep, gadget) {
1037#ifdef DEV_CONFIG_CDC
1038 if (!dev->rndis && dev->cdc) {
1039 result = ether_alt_ep_setup (dev, ep);
1040 if (result == 0)
1041 continue;
1042 } 991 }
1043#endif
1044
1045#ifdef CONFIG_USB_ETH_RNDIS
1046 if (dev->rndis && strcmp (ep->name, EP_STATUS_NAME) == 0) {
1047 const struct usb_endpoint_descriptor *d;
1048 d = ep_desc (gadget, &hs_status_desc, &fs_status_desc);
1049 result = usb_ep_enable (ep, d);
1050 if (result == 0) {
1051 ep->driver_data = dev;
1052 dev->status = d;
1053 continue;
1054 }
1055 } else
1056#endif
1057 992
1058 { 993 result = usb_ep_enable (dev->out_ep, dev->out);
1059#if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) 994 if (result != 0) {
1060 result = ether_ep_setup (dev, ep); 995 DEBUG (dev, "enable %s --> %d\n",
1061 if (result == 0) 996 dev->in_ep->name, result);
1062 continue; 997 goto done;
1063#endif
1064 } 998 }
1065
1066 /* stop on error */
1067 ERROR (dev, "can't enable %s, result %d\n", ep->name, result);
1068 break;
1069 } 999 }
1070 if (!result && (!dev->in_ep || !dev->out_ep))
1071 result = -ENODEV;
1072 1000
1001done:
1073 if (result == 0) 1002 if (result == 0)
1074 result = alloc_requests (dev, qlen (gadget), gfp_flags); 1003 result = alloc_requests (dev, qlen (gadget), gfp_flags);
1075 1004
1076 /* on error, disable any endpoints */ 1005 /* on error, disable any endpoints */
1077 if (result < 0) { 1006 if (result < 0) {
1078#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 1007 if (!subset_active(dev))
1079 if (dev->status)
1080 (void) usb_ep_disable (dev->status_ep); 1008 (void) usb_ep_disable (dev->status_ep);
1081#endif
1082 dev->status = NULL; 1009 dev->status = NULL;
1083#if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) 1010 (void) usb_ep_disable (dev->in_ep);
1084 if (dev->rndis || !dev->cdc) { 1011 (void) usb_ep_disable (dev->out_ep);
1085 if (dev->in)
1086 (void) usb_ep_disable (dev->in_ep);
1087 if (dev->out)
1088 (void) usb_ep_disable (dev->out_ep);
1089 }
1090#endif
1091 dev->in = NULL; 1012 dev->in = NULL;
1092 dev->out = NULL; 1013 dev->out = NULL;
1093 } else 1014 } else
@@ -1095,8 +1016,7 @@ set_ether_config (struct eth_dev *dev, int gfp_flags)
1095 /* activate non-CDC configs right away 1016 /* activate non-CDC configs right away
1096 * this isn't strictly according to the RNDIS spec 1017 * this isn't strictly according to the RNDIS spec
1097 */ 1018 */
1098#if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) 1019 if (!cdc_active (dev)) {
1099 if (dev->rndis || !dev->cdc) {
1100 netif_carrier_on (dev->net); 1020 netif_carrier_on (dev->net);
1101 if (netif_running (dev->net)) { 1021 if (netif_running (dev->net)) {
1102 spin_unlock (&dev->lock); 1022 spin_unlock (&dev->lock);
@@ -1104,7 +1024,6 @@ set_ether_config (struct eth_dev *dev, int gfp_flags)
1104 spin_lock (&dev->lock); 1024 spin_lock (&dev->lock);
1105 } 1025 }
1106 } 1026 }
1107#endif
1108 1027
1109 if (result == 0) 1028 if (result == 0)
1110 DEBUG (dev, "qlen %d\n", qlen (gadget)); 1029 DEBUG (dev, "qlen %d\n", qlen (gadget));
@@ -1124,6 +1043,7 @@ static void eth_reset_config (struct eth_dev *dev)
1124 1043
1125 netif_stop_queue (dev->net); 1044 netif_stop_queue (dev->net);
1126 netif_carrier_off (dev->net); 1045 netif_carrier_off (dev->net);
1046 rndis_uninit(dev->rndis_config);
1127 1047
1128 /* disable endpoints, forcing (synchronous) completion of 1048 /* disable endpoints, forcing (synchronous) completion of
1129 * pending i/o. then free the requests. 1049 * pending i/o. then free the requests.
@@ -1150,6 +1070,8 @@ static void eth_reset_config (struct eth_dev *dev)
1150 if (dev->status) { 1070 if (dev->status) {
1151 usb_ep_disable (dev->status_ep); 1071 usb_ep_disable (dev->status_ep);
1152 } 1072 }
1073 dev->rndis = 0;
1074 dev->cdc_filter = 0;
1153 dev->config = 0; 1075 dev->config = 0;
1154} 1076}
1155 1077
@@ -1162,9 +1084,6 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags)
1162 int result = 0; 1084 int result = 0;
1163 struct usb_gadget *gadget = dev->gadget; 1085 struct usb_gadget *gadget = dev->gadget;
1164 1086
1165 if (number == dev->config)
1166 return 0;
1167
1168 if (gadget_is_sa1100 (gadget) 1087 if (gadget_is_sa1100 (gadget)
1169 && dev->config 1088 && dev->config
1170 && atomic_read (&dev->tx_qlen) != 0) { 1089 && atomic_read (&dev->tx_qlen) != 0) {
@@ -1174,12 +1093,8 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags)
1174 } 1093 }
1175 eth_reset_config (dev); 1094 eth_reset_config (dev);
1176 1095
1177 /* default: pass all packets, no multicast filtering */
1178 dev->cdc_filter = DEFAULT_FILTER;
1179
1180 switch (number) { 1096 switch (number) {
1181 case DEV_CONFIG_VALUE: 1097 case DEV_CONFIG_VALUE:
1182 dev->rndis = 0;
1183 result = set_ether_config (dev, gfp_flags); 1098 result = set_ether_config (dev, gfp_flags);
1184 break; 1099 break;
1185#ifdef CONFIG_USB_ETH_RNDIS 1100#ifdef CONFIG_USB_ETH_RNDIS
@@ -1218,9 +1133,9 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags)
1218 dev->config = number; 1133 dev->config = number;
1219 INFO (dev, "%s speed config #%d: %d mA, %s, using %s\n", 1134 INFO (dev, "%s speed config #%d: %d mA, %s, using %s\n",
1220 speed, number, power, driver_desc, 1135 speed, number, power, driver_desc,
1221 dev->rndis 1136 rndis_active(dev)
1222 ? "RNDIS" 1137 ? "RNDIS"
1223 : (dev->cdc 1138 : (cdc_active(dev)
1224 ? "CDC Ethernet" 1139 ? "CDC Ethernet"
1225 : "CDC Ethernet Subset")); 1140 : "CDC Ethernet Subset"));
1226 } 1141 }
@@ -1231,6 +1146,13 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags)
1231 1146
1232#ifdef DEV_CONFIG_CDC 1147#ifdef DEV_CONFIG_CDC
1233 1148
1149/* The interrupt endpoint is used in CDC networking models (Ethernet, ATM)
1150 * only to notify the host about link status changes (which we support) or
1151 * report completion of some encapsulated command (as used in RNDIS). Since
1152 * we want this CDC Ethernet code to be vendor-neutral, we don't use that
1153 * command mechanism; and only one status request is ever queued.
1154 */
1155
1234static void eth_status_complete (struct usb_ep *ep, struct usb_request *req) 1156static void eth_status_complete (struct usb_ep *ep, struct usb_request *req)
1235{ 1157{
1236 struct usb_cdc_notification *event = req->buf; 1158 struct usb_cdc_notification *event = req->buf;
@@ -1259,7 +1181,7 @@ static void eth_status_complete (struct usb_ep *ep, struct usb_request *req)
1259 } else if (value != -ECONNRESET) 1181 } else if (value != -ECONNRESET)
1260 DEBUG (dev, "event %02x --> %d\n", 1182 DEBUG (dev, "event %02x --> %d\n",
1261 event->bNotificationType, value); 1183 event->bNotificationType, value);
1262 event->bmRequestType = 0xff; 1184 req->context = NULL;
1263} 1185}
1264 1186
1265static void issue_start_status (struct eth_dev *dev) 1187static void issue_start_status (struct eth_dev *dev)
@@ -1276,6 +1198,8 @@ static void issue_start_status (struct eth_dev *dev)
1276 * a "cancel the whole queue" primitive since any 1198 * a "cancel the whole queue" primitive since any
1277 * unlink-one primitive has way too many error modes. 1199 * unlink-one primitive has way too many error modes.
1278 * here, we "know" toggle is already clear... 1200 * here, we "know" toggle is already clear...
1201 *
1202 * FIXME iff req->context != null just dequeue it
1279 */ 1203 */
1280 usb_ep_disable (dev->status_ep); 1204 usb_ep_disable (dev->status_ep);
1281 usb_ep_enable (dev->status_ep, dev->status); 1205 usb_ep_enable (dev->status_ep, dev->status);
@@ -1292,6 +1216,8 @@ static void issue_start_status (struct eth_dev *dev)
1292 1216
1293 req->length = sizeof *event; 1217 req->length = sizeof *event;
1294 req->complete = eth_status_complete; 1218 req->complete = eth_status_complete;
1219 req->context = dev;
1220
1295 value = usb_ep_queue (dev->status_ep, req, GFP_ATOMIC); 1221 value = usb_ep_queue (dev->status_ep, req, GFP_ATOMIC);
1296 if (value < 0) 1222 if (value < 0)
1297 DEBUG (dev, "status buf queue --> %d\n", value); 1223 DEBUG (dev, "status buf queue --> %d\n", value);
@@ -1351,9 +1277,9 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1351 struct eth_dev *dev = get_gadget_data (gadget); 1277 struct eth_dev *dev = get_gadget_data (gadget);
1352 struct usb_request *req = dev->req; 1278 struct usb_request *req = dev->req;
1353 int value = -EOPNOTSUPP; 1279 int value = -EOPNOTSUPP;
1354 u16 wIndex = (__force u16) ctrl->wIndex; 1280 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1355 u16 wValue = (__force u16) ctrl->wValue; 1281 u16 wValue = le16_to_cpu(ctrl->wValue);
1356 u16 wLength = (__force u16) ctrl->wLength; 1282 u16 wLength = le16_to_cpu(ctrl->wLength);
1357 1283
1358 /* descriptors just go into the pre-allocated ep0 buffer, 1284 /* descriptors just go into the pre-allocated ep0 buffer,
1359 * while config change events may enable network traffic. 1285 * while config change events may enable network traffic.
@@ -1424,7 +1350,7 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1424 || !dev->config 1350 || !dev->config
1425 || wIndex > 1) 1351 || wIndex > 1)
1426 break; 1352 break;
1427 if (!dev->cdc && wIndex != 0) 1353 if (!cdc_active(dev) && wIndex != 0)
1428 break; 1354 break;
1429 spin_lock (&dev->lock); 1355 spin_lock (&dev->lock);
1430 1356
@@ -1456,9 +1382,11 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1456 1382
1457 /* CDC requires the data transfers not be done from 1383 /* CDC requires the data transfers not be done from
1458 * the default interface setting ... also, setting 1384 * the default interface setting ... also, setting
1459 * the non-default interface clears filters etc. 1385 * the non-default interface resets filters etc.
1460 */ 1386 */
1461 if (wValue == 1) { 1387 if (wValue == 1) {
1388 if (!cdc_active (dev))
1389 break;
1462 usb_ep_enable (dev->in_ep, dev->in); 1390 usb_ep_enable (dev->in_ep, dev->in);
1463 usb_ep_enable (dev->out_ep, dev->out); 1391 usb_ep_enable (dev->out_ep, dev->out);
1464 dev->cdc_filter = DEFAULT_FILTER; 1392 dev->cdc_filter = DEFAULT_FILTER;
@@ -1492,11 +1420,11 @@ done_set_intf:
1492 || !dev->config 1420 || !dev->config
1493 || wIndex > 1) 1421 || wIndex > 1)
1494 break; 1422 break;
1495 if (!(dev->cdc || dev->rndis) && wIndex != 0) 1423 if (!(cdc_active(dev) || rndis_active(dev)) && wIndex != 0)
1496 break; 1424 break;
1497 1425
1498 /* for CDC, iff carrier is on, data interface is active. */ 1426 /* for CDC, iff carrier is on, data interface is active. */
1499 if (dev->rndis || wIndex != 1) 1427 if (rndis_active(dev) || wIndex != 1)
1500 *(u8 *)req->buf = 0; 1428 *(u8 *)req->buf = 0;
1501 else 1429 else
1502 *(u8 *)req->buf = netif_carrier_ok (dev->net) ? 1 : 0; 1430 *(u8 *)req->buf = netif_carrier_ok (dev->net) ? 1 : 0;
@@ -1509,8 +1437,7 @@ done_set_intf:
1509 * wValue = packet filter bitmap 1437 * wValue = packet filter bitmap
1510 */ 1438 */
1511 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE) 1439 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1512 || !dev->cdc 1440 || !cdc_active(dev)
1513 || dev->rndis
1514 || wLength != 0 1441 || wLength != 0
1515 || wIndex > 1) 1442 || wIndex > 1)
1516 break; 1443 break;
@@ -1534,7 +1461,7 @@ done_set_intf:
1534 */ 1461 */
1535 case USB_CDC_SEND_ENCAPSULATED_COMMAND: 1462 case USB_CDC_SEND_ENCAPSULATED_COMMAND:
1536 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE) 1463 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1537 || !dev->rndis 1464 || !rndis_active(dev)
1538 || wLength > USB_BUFSIZ 1465 || wLength > USB_BUFSIZ
1539 || wValue 1466 || wValue
1540 || rndis_control_intf.bInterfaceNumber 1467 || rndis_control_intf.bInterfaceNumber
@@ -1549,7 +1476,7 @@ done_set_intf:
1549 case USB_CDC_GET_ENCAPSULATED_RESPONSE: 1476 case USB_CDC_GET_ENCAPSULATED_RESPONSE:
1550 if ((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE) 1477 if ((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1551 == ctrl->bRequestType 1478 == ctrl->bRequestType
1552 && dev->rndis 1479 && rndis_active(dev)
1553 // && wLength >= 0x0400 1480 // && wLength >= 0x0400
1554 && !wValue 1481 && !wValue
1555 && rndis_control_intf.bInterfaceNumber 1482 && rndis_control_intf.bInterfaceNumber
@@ -1688,10 +1615,8 @@ rx_submit (struct eth_dev *dev, struct usb_request *req, int gfp_flags)
1688 */ 1615 */
1689 size = (sizeof (struct ethhdr) + dev->net->mtu + RX_EXTRA); 1616 size = (sizeof (struct ethhdr) + dev->net->mtu + RX_EXTRA);
1690 size += dev->out_ep->maxpacket - 1; 1617 size += dev->out_ep->maxpacket - 1;
1691#ifdef CONFIG_USB_ETH_RNDIS 1618 if (rndis_active(dev))
1692 if (dev->rndis)
1693 size += sizeof (struct rndis_packet_msg_type); 1619 size += sizeof (struct rndis_packet_msg_type);
1694#endif
1695 size -= size % dev->out_ep->maxpacket; 1620 size -= size % dev->out_ep->maxpacket;
1696 1621
1697 if ((skb = alloc_skb (size + NET_IP_ALIGN, gfp_flags)) == 0) { 1622 if ((skb = alloc_skb (size + NET_IP_ALIGN, gfp_flags)) == 0) {
@@ -1735,11 +1660,9 @@ static void rx_complete (struct usb_ep *ep, struct usb_request *req)
1735 /* normal completion */ 1660 /* normal completion */
1736 case 0: 1661 case 0:
1737 skb_put (skb, req->actual); 1662 skb_put (skb, req->actual);
1738#ifdef CONFIG_USB_ETH_RNDIS
1739 /* we know MaxPacketsPerTransfer == 1 here */ 1663 /* we know MaxPacketsPerTransfer == 1 here */
1740 if (dev->rndis) 1664 if (rndis_active(dev))
1741 status = rndis_rm_hdr (skb); 1665 status = rndis_rm_hdr (skb);
1742#endif
1743 if (status < 0 1666 if (status < 0
1744 || ETH_HLEN > skb->len 1667 || ETH_HLEN > skb->len
1745 || skb->len > ETH_FRAME_LEN) { 1668 || skb->len > ETH_FRAME_LEN) {
@@ -1859,8 +1782,6 @@ static void rx_fill (struct eth_dev *dev, int gfp_flags)
1859 struct usb_request *req; 1782 struct usb_request *req;
1860 unsigned long flags; 1783 unsigned long flags;
1861 1784
1862 clear_bit (WORK_RX_MEMORY, &dev->todo);
1863
1864 /* fill unused rxq slots with some skb */ 1785 /* fill unused rxq slots with some skb */
1865 spin_lock_irqsave (&dev->lock, flags); 1786 spin_lock_irqsave (&dev->lock, flags);
1866 while (!list_empty (&dev->rx_reqs)) { 1787 while (!list_empty (&dev->rx_reqs)) {
@@ -1883,11 +1804,9 @@ static void eth_work (void *_dev)
1883{ 1804{
1884 struct eth_dev *dev = _dev; 1805 struct eth_dev *dev = _dev;
1885 1806
1886 if (test_bit (WORK_RX_MEMORY, &dev->todo)) { 1807 if (test_and_clear_bit (WORK_RX_MEMORY, &dev->todo)) {
1887 if (netif_running (dev->net)) 1808 if (netif_running (dev->net))
1888 rx_fill (dev, GFP_KERNEL); 1809 rx_fill (dev, GFP_KERNEL);
1889 else
1890 clear_bit (WORK_RX_MEMORY, &dev->todo);
1891 } 1810 }
1892 1811
1893 if (dev->todo) 1812 if (dev->todo)
@@ -1971,8 +1890,7 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
1971 * or the hardware can't use skb buffers. 1890 * or the hardware can't use skb buffers.
1972 * or there's not enough space for any RNDIS headers we need 1891 * or there's not enough space for any RNDIS headers we need
1973 */ 1892 */
1974#ifdef CONFIG_USB_ETH_RNDIS 1893 if (rndis_active(dev)) {
1975 if (dev->rndis) {
1976 struct sk_buff *skb_rndis; 1894 struct sk_buff *skb_rndis;
1977 1895
1978 skb_rndis = skb_realloc_headroom (skb, 1896 skb_rndis = skb_realloc_headroom (skb,
@@ -1985,7 +1903,6 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
1985 rndis_add_hdr (skb); 1903 rndis_add_hdr (skb);
1986 length = skb->len; 1904 length = skb->len;
1987 } 1905 }
1988#endif
1989 req->buf = skb->data; 1906 req->buf = skb->data;
1990 req->context = skb; 1907 req->context = skb;
1991 req->complete = tx_complete; 1908 req->complete = tx_complete;
@@ -2018,9 +1935,7 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
2018 } 1935 }
2019 1936
2020 if (retval) { 1937 if (retval) {
2021#ifdef CONFIG_USB_ETH_RNDIS
2022drop: 1938drop:
2023#endif
2024 dev->stats.tx_dropped++; 1939 dev->stats.tx_dropped++;
2025 dev_kfree_skb_any (skb); 1940 dev_kfree_skb_any (skb);
2026 spin_lock_irqsave (&dev->lock, flags); 1941 spin_lock_irqsave (&dev->lock, flags);
@@ -2036,27 +1951,31 @@ drop:
2036 1951
2037#ifdef CONFIG_USB_ETH_RNDIS 1952#ifdef CONFIG_USB_ETH_RNDIS
2038 1953
2039static void rndis_send_media_state (struct eth_dev *dev, int connect) 1954/* The interrupt endpoint is used in RNDIS to notify the host when messages
2040{ 1955 * other than data packets are available ... notably the REMOTE_NDIS_*_CMPLT
2041 if (!dev) 1956 * messages, but also REMOTE_NDIS_INDICATE_STATUS_MSG and potentially even
2042 return; 1957 * REMOTE_NDIS_KEEPALIVE_MSG.
2043 1958 *
2044 if (connect) { 1959 * The RNDIS control queue is processed by GET_ENCAPSULATED_RESPONSE, and
2045 if (rndis_signal_connect (dev->rndis_config)) 1960 * normally just one notification will be queued.
2046 return; 1961 */
2047 } else { 1962
2048 if (rndis_signal_disconnect (dev->rndis_config)) 1963static struct usb_request *eth_req_alloc (struct usb_ep *, unsigned, unsigned);
2049 return; 1964static void eth_req_free (struct usb_ep *ep, struct usb_request *req);
2050 }
2051}
2052 1965
2053static void 1966static void
2054rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *req) 1967rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *req)
2055{ 1968{
1969 struct eth_dev *dev = ep->driver_data;
1970
2056 if (req->status || req->actual != req->length) 1971 if (req->status || req->actual != req->length)
2057 DEBUG ((struct eth_dev *) ep->driver_data, 1972 DEBUG (dev,
2058 "rndis control ack complete --> %d, %d/%d\n", 1973 "rndis control ack complete --> %d, %d/%d\n",
2059 req->status, req->actual, req->length); 1974 req->status, req->actual, req->length);
1975 req->context = NULL;
1976
1977 if (req != dev->stat_req)
1978 eth_req_free(ep, req);
2060} 1979}
2061 1980
2062static int rndis_control_ack (struct net_device *net) 1981static int rndis_control_ack (struct net_device *net)
@@ -2071,11 +1990,19 @@ static int rndis_control_ack (struct net_device *net)
2071 return -ENODEV; 1990 return -ENODEV;
2072 } 1991 }
2073 1992
1993 /* in case queue length > 1 */
1994 if (resp->context) {
1995 resp = eth_req_alloc (dev->status_ep, 8, GFP_ATOMIC);
1996 if (!resp)
1997 return -ENOMEM;
1998 }
1999
2074 /* Send RNDIS RESPONSE_AVAILABLE notification; 2000 /* Send RNDIS RESPONSE_AVAILABLE notification;
2075 * USB_CDC_NOTIFY_RESPONSE_AVAILABLE should work too 2001 * USB_CDC_NOTIFY_RESPONSE_AVAILABLE should work too
2076 */ 2002 */
2077 resp->length = 8; 2003 resp->length = 8;
2078 resp->complete = rndis_control_ack_complete; 2004 resp->complete = rndis_control_ack_complete;
2005 resp->context = dev;
2079 2006
2080 *((__le32 *) resp->buf) = __constant_cpu_to_le32 (1); 2007 *((__le32 *) resp->buf) = __constant_cpu_to_le32 (1);
2081 *((__le32 *) resp->buf + 1) = __constant_cpu_to_le32 (0); 2008 *((__le32 *) resp->buf + 1) = __constant_cpu_to_le32 (0);
@@ -2089,6 +2016,10 @@ static int rndis_control_ack (struct net_device *net)
2089 return 0; 2016 return 0;
2090} 2017}
2091 2018
2019#else
2020
2021#define rndis_control_ack NULL
2022
2092#endif /* RNDIS */ 2023#endif /* RNDIS */
2093 2024
2094static void eth_start (struct eth_dev *dev, int gfp_flags) 2025static void eth_start (struct eth_dev *dev, int gfp_flags)
@@ -2101,14 +2032,12 @@ static void eth_start (struct eth_dev *dev, int gfp_flags)
2101 /* and open the tx floodgates */ 2032 /* and open the tx floodgates */
2102 atomic_set (&dev->tx_qlen, 0); 2033 atomic_set (&dev->tx_qlen, 0);
2103 netif_wake_queue (dev->net); 2034 netif_wake_queue (dev->net);
2104#ifdef CONFIG_USB_ETH_RNDIS 2035 if (rndis_active(dev)) {
2105 if (dev->rndis) {
2106 rndis_set_param_medium (dev->rndis_config, 2036 rndis_set_param_medium (dev->rndis_config,
2107 NDIS_MEDIUM_802_3, 2037 NDIS_MEDIUM_802_3,
2108 BITRATE(dev->gadget)/100); 2038 BITRATE(dev->gadget)/100);
2109 rndis_send_media_state (dev, 1); 2039 (void) rndis_signal_connect (dev->rndis_config);
2110 } 2040 }
2111#endif
2112} 2041}
2113 2042
2114static int eth_open (struct net_device *net) 2043static int eth_open (struct net_device *net)
@@ -2149,28 +2078,27 @@ static int eth_stop (struct net_device *net)
2149 } 2078 }
2150 } 2079 }
2151 2080
2152#ifdef CONFIG_USB_ETH_RNDIS 2081 if (rndis_active(dev)) {
2153 if (dev->rndis) {
2154 rndis_set_param_medium (dev->rndis_config, 2082 rndis_set_param_medium (dev->rndis_config,
2155 NDIS_MEDIUM_802_3, 0); 2083 NDIS_MEDIUM_802_3, 0);
2156 rndis_send_media_state (dev, 0); 2084 (void) rndis_signal_disconnect (dev->rndis_config);
2157 } 2085 }
2158#endif
2159 2086
2160 return 0; 2087 return 0;
2161} 2088}
2162 2089
2163/*-------------------------------------------------------------------------*/ 2090/*-------------------------------------------------------------------------*/
2164 2091
2165static struct usb_request *eth_req_alloc (struct usb_ep *ep, unsigned size) 2092static struct usb_request *
2093eth_req_alloc (struct usb_ep *ep, unsigned size, unsigned gfp_flags)
2166{ 2094{
2167 struct usb_request *req; 2095 struct usb_request *req;
2168 2096
2169 req = usb_ep_alloc_request (ep, GFP_KERNEL); 2097 req = usb_ep_alloc_request (ep, gfp_flags);
2170 if (!req) 2098 if (!req)
2171 return NULL; 2099 return NULL;
2172 2100
2173 req->buf = kmalloc (size, GFP_KERNEL); 2101 req->buf = kmalloc (size, gfp_flags);
2174 if (!req->buf) { 2102 if (!req->buf) {
2175 usb_ep_free_request (ep, req); 2103 usb_ep_free_request (ep, req);
2176 req = NULL; 2104 req = NULL;
@@ -2192,10 +2120,8 @@ eth_unbind (struct usb_gadget *gadget)
2192 struct eth_dev *dev = get_gadget_data (gadget); 2120 struct eth_dev *dev = get_gadget_data (gadget);
2193 2121
2194 DEBUG (dev, "unbind\n"); 2122 DEBUG (dev, "unbind\n");
2195#ifdef CONFIG_USB_ETH_RNDIS
2196 rndis_deregister (dev->rndis_config); 2123 rndis_deregister (dev->rndis_config);
2197 rndis_exit (); 2124 rndis_exit ();
2198#endif
2199 2125
2200 /* we've already been disconnected ... no i/o is active */ 2126 /* we've already been disconnected ... no i/o is active */
2201 if (dev->req) { 2127 if (dev->req) {
@@ -2368,13 +2294,11 @@ autoconf_fail:
2368 gadget->name); 2294 gadget->name);
2369 return -ENODEV; 2295 return -ENODEV;
2370 } 2296 }
2371 EP_IN_NAME = in_ep->name;
2372 in_ep->driver_data = in_ep; /* claim */ 2297 in_ep->driver_data = in_ep; /* claim */
2373 2298
2374 out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc); 2299 out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc);
2375 if (!out_ep) 2300 if (!out_ep)
2376 goto autoconf_fail; 2301 goto autoconf_fail;
2377 EP_OUT_NAME = out_ep->name;
2378 out_ep->driver_data = out_ep; /* claim */ 2302 out_ep->driver_data = out_ep; /* claim */
2379 2303
2380#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 2304#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
@@ -2384,7 +2308,6 @@ autoconf_fail:
2384 if (cdc || rndis) { 2308 if (cdc || rndis) {
2385 status_ep = usb_ep_autoconfig (gadget, &fs_status_desc); 2309 status_ep = usb_ep_autoconfig (gadget, &fs_status_desc);
2386 if (status_ep) { 2310 if (status_ep) {
2387 EP_STATUS_NAME = status_ep->name;
2388 status_ep->driver_data = status_ep; /* claim */ 2311 status_ep->driver_data = status_ep; /* claim */
2389 } else if (rndis) { 2312 } else if (rndis) {
2390 dev_err (&gadget->dev, 2313 dev_err (&gadget->dev,
@@ -2426,7 +2349,7 @@ autoconf_fail:
2426 hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress; 2349 hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
2427 hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress; 2350 hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
2428#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 2351#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
2429 if (EP_STATUS_NAME) 2352 if (status_ep)
2430 hs_status_desc.bEndpointAddress = 2353 hs_status_desc.bEndpointAddress =
2431 fs_status_desc.bEndpointAddress; 2354 fs_status_desc.bEndpointAddress;
2432#endif 2355#endif
@@ -2499,20 +2422,23 @@ autoconf_fail:
2499 SET_ETHTOOL_OPS(net, &ops); 2422 SET_ETHTOOL_OPS(net, &ops);
2500 2423
2501 /* preallocate control message data and buffer */ 2424 /* preallocate control message data and buffer */
2502 dev->req = eth_req_alloc (gadget->ep0, USB_BUFSIZ); 2425 dev->req = eth_req_alloc (gadget->ep0, USB_BUFSIZ, GFP_KERNEL);
2503 if (!dev->req) 2426 if (!dev->req)
2504 goto fail; 2427 goto fail;
2505 dev->req->complete = eth_setup_complete; 2428 dev->req->complete = eth_setup_complete;
2506 2429
2507 /* ... and maybe likewise for status transfer */ 2430 /* ... and maybe likewise for status transfer */
2431#ifdef DEV_CONFIG_CDC
2508 if (dev->status_ep) { 2432 if (dev->status_ep) {
2509 dev->stat_req = eth_req_alloc (dev->status_ep, 2433 dev->stat_req = eth_req_alloc (dev->status_ep,
2510 STATUS_BYTECOUNT); 2434 STATUS_BYTECOUNT, GFP_KERNEL);
2511 if (!dev->stat_req) { 2435 if (!dev->stat_req) {
2512 eth_req_free (gadget->ep0, dev->req); 2436 eth_req_free (gadget->ep0, dev->req);
2513 goto fail; 2437 goto fail;
2514 } 2438 }
2439 dev->stat_req->context = NULL;
2515 } 2440 }
2441#endif
2516 2442
2517 /* finish hookup to lower layer ... */ 2443 /* finish hookup to lower layer ... */
2518 dev->gadget = gadget; 2444 dev->gadget = gadget;
@@ -2526,16 +2452,16 @@ autoconf_fail:
2526 netif_stop_queue (dev->net); 2452 netif_stop_queue (dev->net);
2527 netif_carrier_off (dev->net); 2453 netif_carrier_off (dev->net);
2528 2454
2529 // SET_NETDEV_DEV (dev->net, &gadget->dev); 2455 SET_NETDEV_DEV (dev->net, &gadget->dev);
2530 status = register_netdev (dev->net); 2456 status = register_netdev (dev->net);
2531 if (status < 0) 2457 if (status < 0)
2532 goto fail1; 2458 goto fail1;
2533 2459
2534 INFO (dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); 2460 INFO (dev, "%s, version: " DRIVER_VERSION "\n", driver_desc);
2535 INFO (dev, "using %s, OUT %s IN %s%s%s\n", gadget->name, 2461 INFO (dev, "using %s, OUT %s IN %s%s%s\n", gadget->name,
2536 EP_OUT_NAME, EP_IN_NAME, 2462 out_ep->name, in_ep->name,
2537 EP_STATUS_NAME ? " STATUS " : "", 2463 status_ep ? " STATUS " : "",
2538 EP_STATUS_NAME ? EP_STATUS_NAME : "" 2464 status_ep ? status_ep->name : ""
2539 ); 2465 );
2540 INFO (dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n", 2466 INFO (dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
2541 net->dev_addr [0], net->dev_addr [1], 2467 net->dev_addr [0], net->dev_addr [1],
@@ -2548,7 +2474,6 @@ autoconf_fail:
2548 dev->host_mac [2], dev->host_mac [3], 2474 dev->host_mac [2], dev->host_mac [3],
2549 dev->host_mac [4], dev->host_mac [5]); 2475 dev->host_mac [4], dev->host_mac [5]);
2550 2476
2551#ifdef CONFIG_USB_ETH_RNDIS
2552 if (rndis) { 2477 if (rndis) {
2553 u32 vendorID = 0; 2478 u32 vendorID = 0;
2554 2479
@@ -2565,7 +2490,7 @@ fail0:
2565 /* these set up a lot of the OIDs that RNDIS needs */ 2490 /* these set up a lot of the OIDs that RNDIS needs */
2566 rndis_set_host_mac (dev->rndis_config, dev->host_mac); 2491 rndis_set_host_mac (dev->rndis_config, dev->host_mac);
2567 if (rndis_set_param_dev (dev->rndis_config, dev->net, 2492 if (rndis_set_param_dev (dev->rndis_config, dev->net,
2568 &dev->stats)) 2493 &dev->stats, &dev->cdc_filter))
2569 goto fail0; 2494 goto fail0;
2570 if (rndis_set_param_vendor (dev->rndis_config, vendorID, 2495 if (rndis_set_param_vendor (dev->rndis_config, vendorID,
2571 manufacturer)) 2496 manufacturer))
@@ -2576,7 +2501,6 @@ fail0:
2576 goto fail0; 2501 goto fail0;
2577 INFO (dev, "RNDIS ready\n"); 2502 INFO (dev, "RNDIS ready\n");
2578 } 2503 }
2579#endif
2580 2504
2581 return status; 2505 return status;
2582 2506
@@ -2610,11 +2534,8 @@ eth_resume (struct usb_gadget *gadget)
2610/*-------------------------------------------------------------------------*/ 2534/*-------------------------------------------------------------------------*/
2611 2535
2612static struct usb_gadget_driver eth_driver = { 2536static struct usb_gadget_driver eth_driver = {
2613#ifdef CONFIG_USB_GADGET_DUALSPEED 2537 .speed = DEVSPEED,
2614 .speed = USB_SPEED_HIGH, 2538
2615#else
2616 .speed = USB_SPEED_FULL,
2617#endif
2618 .function = (char *) driver_desc, 2539 .function = (char *) driver_desc,
2619 .bind = eth_bind, 2540 .bind = eth_bind,
2620 .unbind = eth_unbind, 2541 .unbind = eth_unbind,
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index a9be85103d23..4f57085619b4 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -81,6 +81,10 @@
81 * removable Default false, boolean for removable media 81 * removable Default false, boolean for removable media
82 * luns=N Default N = number of filenames, number of 82 * luns=N Default N = number of filenames, number of
83 * LUNs to support 83 * LUNs to support
84 * stall Default determined according to the type of
85 * USB device controller (usually true),
86 * boolean to permit the driver to halt
87 * bulk endpoints
84 * transport=XXX Default BBB, transport name (CB, CBI, or BBB) 88 * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
85 * protocol=YYY Default SCSI, protocol name (RBC, 8020 or 89 * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
86 * ATAPI, QIC, UFI, 8070, or SCSI; 90 * ATAPI, QIC, UFI, 8070, or SCSI;
@@ -91,14 +95,10 @@
91 * buflen=N Default N=16384, buffer size used (will be 95 * buflen=N Default N=16384, buffer size used (will be
92 * rounded down to a multiple of 96 * rounded down to a multiple of
93 * PAGE_CACHE_SIZE) 97 * PAGE_CACHE_SIZE)
94 * stall Default determined according to the type of
95 * USB device controller (usually true),
96 * boolean to permit the driver to halt
97 * bulk endpoints
98 * 98 *
99 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", 99 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro",
100 * "removable", and "luns" options are available; default values are used 100 * "removable", "luns", and "stall" options are available; default values
101 * for everything else. 101 * are used for everything else.
102 * 102 *
103 * The pathnames of the backing files and the ro settings are available in 103 * The pathnames of the backing files and the ro settings are available in
104 * the attribute files "file" and "ro" in the lun<n> subdirectory of the 104 * the attribute files "file" and "ro" in the lun<n> subdirectory of the
@@ -342,14 +342,15 @@ static struct {
342 int num_ros; 342 int num_ros;
343 unsigned int nluns; 343 unsigned int nluns;
344 344
345 int removable;
346 int can_stall;
347
345 char *transport_parm; 348 char *transport_parm;
346 char *protocol_parm; 349 char *protocol_parm;
347 int removable;
348 unsigned short vendor; 350 unsigned short vendor;
349 unsigned short product; 351 unsigned short product;
350 unsigned short release; 352 unsigned short release;
351 unsigned int buflen; 353 unsigned int buflen;
352 int can_stall;
353 354
354 int transport_type; 355 int transport_type;
355 char *transport_name; 356 char *transport_name;
@@ -360,11 +361,11 @@ static struct {
360 .transport_parm = "BBB", 361 .transport_parm = "BBB",
361 .protocol_parm = "SCSI", 362 .protocol_parm = "SCSI",
362 .removable = 0, 363 .removable = 0,
364 .can_stall = 1,
363 .vendor = DRIVER_VENDOR_ID, 365 .vendor = DRIVER_VENDOR_ID,
364 .product = DRIVER_PRODUCT_ID, 366 .product = DRIVER_PRODUCT_ID,
365 .release = 0xffff, // Use controller chip type 367 .release = 0xffff, // Use controller chip type
366 .buflen = 16384, 368 .buflen = 16384,
367 .can_stall = 1,
368 }; 369 };
369 370
370 371
@@ -380,6 +381,9 @@ MODULE_PARM_DESC(luns, "number of LUNs");
380module_param_named(removable, mod_data.removable, bool, S_IRUGO); 381module_param_named(removable, mod_data.removable, bool, S_IRUGO);
381MODULE_PARM_DESC(removable, "true to simulate removable media"); 382MODULE_PARM_DESC(removable, "true to simulate removable media");
382 383
384module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
385MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
386
383 387
384/* In the non-TEST version, only the module parameters listed above 388/* In the non-TEST version, only the module parameters listed above
385 * are available. */ 389 * are available. */
@@ -404,9 +408,6 @@ MODULE_PARM_DESC(release, "USB release number");
404module_param_named(buflen, mod_data.buflen, uint, S_IRUGO); 408module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
405MODULE_PARM_DESC(buflen, "I/O buffer size"); 409MODULE_PARM_DESC(buflen, "I/O buffer size");
406 410
407module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
408MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
409
410#endif /* CONFIG_USB_FILE_STORAGE_TEST */ 411#endif /* CONFIG_USB_FILE_STORAGE_TEST */
411 412
412 413
@@ -818,7 +819,7 @@ static void inline put_be32(u8 *buf, u32 val)
818 buf[0] = val >> 24; 819 buf[0] = val >> 24;
819 buf[1] = val >> 16; 820 buf[1] = val >> 16;
820 buf[2] = val >> 8; 821 buf[2] = val >> 8;
821 buf[3] = val; 822 buf[3] = val & 0xff;
822} 823}
823 824
824 825
@@ -1276,8 +1277,8 @@ static int class_setup_req(struct fsg_dev *fsg,
1276{ 1277{
1277 struct usb_request *req = fsg->ep0req; 1278 struct usb_request *req = fsg->ep0req;
1278 int value = -EOPNOTSUPP; 1279 int value = -EOPNOTSUPP;
1279 u16 w_index = ctrl->wIndex; 1280 u16 w_index = le16_to_cpu(ctrl->wIndex);
1280 u16 w_length = ctrl->wLength; 1281 u16 w_length = le16_to_cpu(ctrl->wLength);
1281 1282
1282 if (!fsg->config) 1283 if (!fsg->config)
1283 return value; 1284 return value;
@@ -1312,7 +1313,7 @@ static int class_setup_req(struct fsg_dev *fsg,
1312 } 1313 }
1313 VDBG(fsg, "get max LUN\n"); 1314 VDBG(fsg, "get max LUN\n");
1314 *(u8 *) req->buf = fsg->nluns - 1; 1315 *(u8 *) req->buf = fsg->nluns - 1;
1315 value = min(w_length, (u16) 1); 1316 value = 1;
1316 break; 1317 break;
1317 } 1318 }
1318 } 1319 }
@@ -1344,7 +1345,7 @@ static int class_setup_req(struct fsg_dev *fsg,
1344 "unknown class-specific control req " 1345 "unknown class-specific control req "
1345 "%02x.%02x v%04x i%04x l%u\n", 1346 "%02x.%02x v%04x i%04x l%u\n",
1346 ctrl->bRequestType, ctrl->bRequest, 1347 ctrl->bRequestType, ctrl->bRequest,
1347 ctrl->wValue, w_index, w_length); 1348 le16_to_cpu(ctrl->wValue), w_index, w_length);
1348 return value; 1349 return value;
1349} 1350}
1350 1351
@@ -1358,9 +1359,8 @@ static int standard_setup_req(struct fsg_dev *fsg,
1358{ 1359{
1359 struct usb_request *req = fsg->ep0req; 1360 struct usb_request *req = fsg->ep0req;
1360 int value = -EOPNOTSUPP; 1361 int value = -EOPNOTSUPP;
1361 u16 w_index = ctrl->wIndex; 1362 u16 w_index = le16_to_cpu(ctrl->wIndex);
1362 u16 w_value = ctrl->wValue; 1363 u16 w_value = le16_to_cpu(ctrl->wValue);
1363 u16 w_length = ctrl->wLength;
1364 1364
1365 /* Usually this just stores reply data in the pre-allocated ep0 buffer, 1365 /* Usually this just stores reply data in the pre-allocated ep0 buffer,
1366 * but config change events will also reconfigure hardware. */ 1366 * but config change events will also reconfigure hardware. */
@@ -1374,7 +1374,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
1374 1374
1375 case USB_DT_DEVICE: 1375 case USB_DT_DEVICE:
1376 VDBG(fsg, "get device descriptor\n"); 1376 VDBG(fsg, "get device descriptor\n");
1377 value = min(w_length, (u16) sizeof device_desc); 1377 value = sizeof device_desc;
1378 memcpy(req->buf, &device_desc, value); 1378 memcpy(req->buf, &device_desc, value);
1379 break; 1379 break;
1380#ifdef CONFIG_USB_GADGET_DUALSPEED 1380#ifdef CONFIG_USB_GADGET_DUALSPEED
@@ -1382,7 +1382,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
1382 VDBG(fsg, "get device qualifier\n"); 1382 VDBG(fsg, "get device qualifier\n");
1383 if (!fsg->gadget->is_dualspeed) 1383 if (!fsg->gadget->is_dualspeed)
1384 break; 1384 break;
1385 value = min(w_length, (u16) sizeof dev_qualifier); 1385 value = sizeof dev_qualifier;
1386 memcpy(req->buf, &dev_qualifier, value); 1386 memcpy(req->buf, &dev_qualifier, value);
1387 break; 1387 break;
1388 1388
@@ -1401,8 +1401,6 @@ static int standard_setup_req(struct fsg_dev *fsg,
1401 req->buf, 1401 req->buf,
1402 w_value >> 8, 1402 w_value >> 8,
1403 w_value & 0xff); 1403 w_value & 0xff);
1404 if (value >= 0)
1405 value = min(w_length, (u16) value);
1406 break; 1404 break;
1407 1405
1408 case USB_DT_STRING: 1406 case USB_DT_STRING:
@@ -1411,8 +1409,6 @@ static int standard_setup_req(struct fsg_dev *fsg,
1411 /* wIndex == language code */ 1409 /* wIndex == language code */
1412 value = usb_gadget_get_string(&stringtab, 1410 value = usb_gadget_get_string(&stringtab,
1413 w_value & 0xff, req->buf); 1411 w_value & 0xff, req->buf);
1414 if (value >= 0)
1415 value = min(w_length, (u16) value);
1416 break; 1412 break;
1417 } 1413 }
1418 break; 1414 break;
@@ -1438,7 +1434,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
1438 break; 1434 break;
1439 VDBG(fsg, "get configuration\n"); 1435 VDBG(fsg, "get configuration\n");
1440 *(u8 *) req->buf = fsg->config; 1436 *(u8 *) req->buf = fsg->config;
1441 value = min(w_length, (u16) 1); 1437 value = 1;
1442 break; 1438 break;
1443 1439
1444 case USB_REQ_SET_INTERFACE: 1440 case USB_REQ_SET_INTERFACE:
@@ -1466,14 +1462,14 @@ static int standard_setup_req(struct fsg_dev *fsg,
1466 } 1462 }
1467 VDBG(fsg, "get interface\n"); 1463 VDBG(fsg, "get interface\n");
1468 *(u8 *) req->buf = 0; 1464 *(u8 *) req->buf = 0;
1469 value = min(w_length, (u16) 1); 1465 value = 1;
1470 break; 1466 break;
1471 1467
1472 default: 1468 default:
1473 VDBG(fsg, 1469 VDBG(fsg,
1474 "unknown control req %02x.%02x v%04x i%04x l%u\n", 1470 "unknown control req %02x.%02x v%04x i%04x l%u\n",
1475 ctrl->bRequestType, ctrl->bRequest, 1471 ctrl->bRequestType, ctrl->bRequest,
1476 w_value, w_index, w_length); 1472 w_value, w_index, le16_to_cpu(ctrl->wLength));
1477 } 1473 }
1478 1474
1479 return value; 1475 return value;
@@ -1485,6 +1481,7 @@ static int fsg_setup(struct usb_gadget *gadget,
1485{ 1481{
1486 struct fsg_dev *fsg = get_gadget_data(gadget); 1482 struct fsg_dev *fsg = get_gadget_data(gadget);
1487 int rc; 1483 int rc;
1484 int w_length = le16_to_cpu(ctrl->wLength);
1488 1485
1489 ++fsg->ep0_req_tag; // Record arrival of a new request 1486 ++fsg->ep0_req_tag; // Record arrival of a new request
1490 fsg->ep0req->context = NULL; 1487 fsg->ep0req->context = NULL;
@@ -1498,9 +1495,9 @@ static int fsg_setup(struct usb_gadget *gadget,
1498 1495
1499 /* Respond with data/status or defer until later? */ 1496 /* Respond with data/status or defer until later? */
1500 if (rc >= 0 && rc != DELAYED_STATUS) { 1497 if (rc >= 0 && rc != DELAYED_STATUS) {
1498 rc = min(rc, w_length);
1501 fsg->ep0req->length = rc; 1499 fsg->ep0req->length = rc;
1502 fsg->ep0req->zero = (rc < ctrl->wLength && 1500 fsg->ep0req->zero = rc < w_length;
1503 (rc % gadget->ep0->maxpacket) == 0);
1504 fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ? 1501 fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
1505 "ep0-in" : "ep0-out"); 1502 "ep0-in" : "ep0-out");
1506 rc = ep0_queue(fsg); 1503 rc = ep0_queue(fsg);
@@ -2660,7 +2657,7 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2660 } 2657 }
2661 } 2658 }
2662 2659
2663 /* Check that the LUN values are oonsistent */ 2660 /* Check that the LUN values are consistent */
2664 if (transport_is_bbb()) { 2661 if (transport_is_bbb()) {
2665 if (fsg->lun != lun) 2662 if (fsg->lun != lun)
2666 DBG(fsg, "using LUN %d from CBW, " 2663 DBG(fsg, "using LUN %d from CBW, "
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 005db7cca292..ed773a9111de 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -70,7 +70,7 @@ MODULE_LICENSE("GPL");
70 * seem to behave quite as expected. Used by default. 70 * seem to behave quite as expected. Used by default.
71 * 71 *
72 * OUT dma documents design problems handling the common "short packet" 72 * OUT dma documents design problems handling the common "short packet"
73 * transfer termination policy; it couldn't enabled by default, even 73 * transfer termination policy; it couldn't be enabled by default, even
74 * if the OUT-dma abort problems had a resolution. 74 * if the OUT-dma abort problems had a resolution.
75 */ 75 */
76static unsigned use_dma = 1; 76static unsigned use_dma = 1;
@@ -313,7 +313,7 @@ goku_free_request(struct usb_ep *_ep, struct usb_request *_req)
313#if defined(CONFIG_X86) 313#if defined(CONFIG_X86)
314#define USE_KMALLOC 314#define USE_KMALLOC
315 315
316#elif defined(CONFIG_MIPS) && !defined(CONFIG_NONCOHERENT_IO) 316#elif defined(CONFIG_MIPS) && !defined(CONFIG_DMA_NONCOHERENT)
317#define USE_KMALLOC 317#define USE_KMALLOC
318 318
319#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE) 319#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)
@@ -1524,9 +1524,12 @@ static void ep0_setup(struct goku_udc *dev)
1524 /* read SETUP packet and enter DATA stage */ 1524 /* read SETUP packet and enter DATA stage */
1525 ctrl.bRequestType = readl(&regs->bRequestType); 1525 ctrl.bRequestType = readl(&regs->bRequestType);
1526 ctrl.bRequest = readl(&regs->bRequest); 1526 ctrl.bRequest = readl(&regs->bRequest);
1527 ctrl.wValue = (readl(&regs->wValueH) << 8) | readl(&regs->wValueL); 1527 ctrl.wValue = cpu_to_le16((readl(&regs->wValueH) << 8)
1528 ctrl.wIndex = (readl(&regs->wIndexH) << 8) | readl(&regs->wIndexL); 1528 | readl(&regs->wValueL));
1529 ctrl.wLength = (readl(&regs->wLengthH) << 8) | readl(&regs->wLengthL); 1529 ctrl.wIndex = cpu_to_le16((readl(&regs->wIndexH) << 8)
1530 | readl(&regs->wIndexL));
1531 ctrl.wLength = cpu_to_le16((readl(&regs->wLengthH) << 8)
1532 | readl(&regs->wLengthL));
1530 writel(0, &regs->SetupRecv); 1533 writel(0, &regs->SetupRecv);
1531 1534
1532 nuke(&dev->ep[0], 0); 1535 nuke(&dev->ep[0], 0);
@@ -1548,18 +1551,20 @@ static void ep0_setup(struct goku_udc *dev)
1548 case USB_REQ_CLEAR_FEATURE: 1551 case USB_REQ_CLEAR_FEATURE:
1549 switch (ctrl.bRequestType) { 1552 switch (ctrl.bRequestType) {
1550 case USB_RECIP_ENDPOINT: 1553 case USB_RECIP_ENDPOINT:
1551 tmp = ctrl.wIndex & 0x0f; 1554 tmp = le16_to_cpu(ctrl.wIndex) & 0x0f;
1552 /* active endpoint */ 1555 /* active endpoint */
1553 if (tmp > 3 || (!dev->ep[tmp].desc && tmp != 0)) 1556 if (tmp > 3 || (!dev->ep[tmp].desc && tmp != 0))
1554 goto stall; 1557 goto stall;
1555 if (ctrl.wIndex & USB_DIR_IN) { 1558 if (ctrl.wIndex & __constant_cpu_to_le16(
1559 USB_DIR_IN)) {
1556 if (!dev->ep[tmp].is_in) 1560 if (!dev->ep[tmp].is_in)
1557 goto stall; 1561 goto stall;
1558 } else { 1562 } else {
1559 if (dev->ep[tmp].is_in) 1563 if (dev->ep[tmp].is_in)
1560 goto stall; 1564 goto stall;
1561 } 1565 }
1562 if (ctrl.wValue != USB_ENDPOINT_HALT) 1566 if (ctrl.wValue != __constant_cpu_to_le16(
1567 USB_ENDPOINT_HALT))
1563 goto stall; 1568 goto stall;
1564 if (tmp) 1569 if (tmp)
1565 goku_clear_halt(&dev->ep[tmp]); 1570 goku_clear_halt(&dev->ep[tmp]);
@@ -1571,7 +1576,7 @@ succeed:
1571 return; 1576 return;
1572 case USB_RECIP_DEVICE: 1577 case USB_RECIP_DEVICE:
1573 /* device remote wakeup: always clear */ 1578 /* device remote wakeup: always clear */
1574 if (ctrl.wValue != 1) 1579 if (ctrl.wValue != __constant_cpu_to_le16(1))
1575 goto stall; 1580 goto stall;
1576 VDBG(dev, "clear dev remote wakeup\n"); 1581 VDBG(dev, "clear dev remote wakeup\n");
1577 goto succeed; 1582 goto succeed;
@@ -1589,14 +1594,15 @@ succeed:
1589#ifdef USB_TRACE 1594#ifdef USB_TRACE
1590 VDBG(dev, "SETUP %02x.%02x v%04x i%04x l%04x\n", 1595 VDBG(dev, "SETUP %02x.%02x v%04x i%04x l%04x\n",
1591 ctrl.bRequestType, ctrl.bRequest, 1596 ctrl.bRequestType, ctrl.bRequest,
1592 ctrl.wValue, ctrl.wIndex, ctrl.wLength); 1597 le16_to_cpu(ctrl.wValue), le16_to_cpu(ctrl.wIndex),
1598 le16_to_cpu(ctrl.wLength));
1593#endif 1599#endif
1594 1600
1595 /* hw wants to know when we're configured (or not) */ 1601 /* hw wants to know when we're configured (or not) */
1596 dev->req_config = (ctrl.bRequest == USB_REQ_SET_CONFIGURATION 1602 dev->req_config = (ctrl.bRequest == USB_REQ_SET_CONFIGURATION
1597 && ctrl.bRequestType == USB_RECIP_DEVICE); 1603 && ctrl.bRequestType == USB_RECIP_DEVICE);
1598 if (unlikely(dev->req_config)) 1604 if (unlikely(dev->req_config))
1599 dev->configured = (ctrl.wValue != 0); 1605 dev->configured = (ctrl.wValue != __constant_cpu_to_le16(0));
1600 1606
1601 /* delegate everything to the gadget driver. 1607 /* delegate everything to the gadget driver.
1602 * it may respond after this irq handler returns. 1608 * it may respond after this irq handler returns.
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 1e5e6ddef787..020815397a49 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -417,8 +417,8 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
417 goto free1; 417 goto free1;
418 418
419 value = ep_io (data, kbuf, len); 419 value = ep_io (data, kbuf, len);
420 VDEBUG (data->dev, "%s read %d OUT, status %d\n", 420 VDEBUG (data->dev, "%s read %zu OUT, status %d\n",
421 data->name, len, value); 421 data->name, len, (int) value);
422 if (value >= 0 && copy_to_user (buf, kbuf, value)) 422 if (value >= 0 && copy_to_user (buf, kbuf, value))
423 value = -EFAULT; 423 value = -EFAULT;
424 424
@@ -465,8 +465,8 @@ ep_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
465 } 465 }
466 466
467 value = ep_io (data, kbuf, len); 467 value = ep_io (data, kbuf, len);
468 VDEBUG (data->dev, "%s write %d IN, status %d\n", 468 VDEBUG (data->dev, "%s write %zu IN, status %d\n",
469 data->name, len, value); 469 data->name, len, (int) value);
470free1: 470free1:
471 up (&data->lock); 471 up (&data->lock);
472 kfree (kbuf); 472 kfree (kbuf);
@@ -1318,8 +1318,8 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1318 struct usb_request *req = dev->req; 1318 struct usb_request *req = dev->req;
1319 int value = -EOPNOTSUPP; 1319 int value = -EOPNOTSUPP;
1320 struct usb_gadgetfs_event *event; 1320 struct usb_gadgetfs_event *event;
1321 u16 w_value = ctrl->wValue; 1321 u16 w_value = le16_to_cpu(ctrl->wValue);
1322 u16 w_length = ctrl->wLength; 1322 u16 w_length = le16_to_cpu(ctrl->wLength);
1323 1323
1324 spin_lock (&dev->lock); 1324 spin_lock (&dev->lock);
1325 dev->setup_abort = 0; 1325 dev->setup_abort = 0;
diff --git a/drivers/usb/gadget/ndis.h b/drivers/usb/gadget/ndis.h
index c553bbf68cab..09e3ee4eeae1 100644
--- a/drivers/usb/gadget/ndis.h
+++ b/drivers/usb/gadget/ndis.h
@@ -47,17 +47,17 @@ struct NDIS_PM_WAKE_UP_CAPABILITIES {
47#define NDIS_DEVICE_WAKE_ON_MAGIC_PACKET_ENABLE 0x00000004 47#define NDIS_DEVICE_WAKE_ON_MAGIC_PACKET_ENABLE 0x00000004
48 48
49struct NDIS_PNP_CAPABILITIES { 49struct NDIS_PNP_CAPABILITIES {
50 u32 Flags; 50 __le32 Flags;
51 struct NDIS_PM_WAKE_UP_CAPABILITIES WakeUpCapabilities; 51 struct NDIS_PM_WAKE_UP_CAPABILITIES WakeUpCapabilities;
52}; 52};
53 53
54struct NDIS_PM_PACKET_PATTERN { 54struct NDIS_PM_PACKET_PATTERN {
55 u32 Priority; 55 __le32 Priority;
56 u32 Reserved; 56 __le32 Reserved;
57 u32 MaskSize; 57 __le32 MaskSize;
58 u32 PatternOffset; 58 __le32 PatternOffset;
59 u32 PatternSize; 59 __le32 PatternSize;
60 u32 PatternFlags; 60 __le32 PatternFlags;
61}; 61};
62 62
63 63
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index e47e398daeb5..13a3dbc9949b 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -448,7 +448,7 @@ net2280_free_request (struct usb_ep *_ep, struct usb_request *_req)
448#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE) 448#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)
449#define USE_KMALLOC 449#define USE_KMALLOC
450 450
451#elif defined(CONFIG_MIPS) && !defined(CONFIG_NONCOHERENT_IO) 451#elif defined(CONFIG_MIPS) && !defined(CONFIG_DMA_NONCOHERENT)
452#define USE_KMALLOC 452#define USE_KMALLOC
453 453
454/* FIXME there are other cases, including an x86-64 one ... */ 454/* FIXME there are other cases, including an x86-64 one ... */
@@ -1113,7 +1113,7 @@ static void restart_dma (struct net2280_ep *ep)
1113 if (ep->in_fifo_validate) 1113 if (ep->in_fifo_validate)
1114 dmactl |= (1 << DMA_FIFO_VALIDATE); 1114 dmactl |= (1 << DMA_FIFO_VALIDATE);
1115 list_for_each_entry (entry, &ep->queue, queue) { 1115 list_for_each_entry (entry, &ep->queue, queue) {
1116 u32 dmacount; 1116 __le32 dmacount;
1117 1117
1118 if (entry == req) 1118 if (entry == req)
1119 continue; 1119 continue;
@@ -1238,7 +1238,7 @@ static int net2280_dequeue (struct usb_ep *_ep, struct usb_request *_req)
1238 &ep->dma->dmadesc); 1238 &ep->dma->dmadesc);
1239 if (req->td->dmacount & dma_done_ie) 1239 if (req->td->dmacount & dma_done_ie)
1240 writel (readl (&ep->dma->dmacount) 1240 writel (readl (&ep->dma->dmacount)
1241 | dma_done_ie, 1241 | le32_to_cpu(dma_done_ie),
1242 &ep->dma->dmacount); 1242 &ep->dma->dmacount);
1243 } else { 1243 } else {
1244 struct net2280_request *prev; 1244 struct net2280_request *prev;
@@ -1779,6 +1779,9 @@ static void set_fifo_mode (struct net2280 *dev, int mode)
1779 list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list); 1779 list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list);
1780} 1780}
1781 1781
1782/* just declare this in any driver that really need it */
1783extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode);
1784
1782/** 1785/**
1783 * net2280_set_fifo_mode - change allocation of fifo buffers 1786 * net2280_set_fifo_mode - change allocation of fifo buffers
1784 * @gadget: access to the net2280 device that will be updated 1787 * @gadget: access to the net2280 device that will be updated
@@ -2382,9 +2385,9 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2382 cpu_to_le32s (&u.raw [0]); 2385 cpu_to_le32s (&u.raw [0]);
2383 cpu_to_le32s (&u.raw [1]); 2386 cpu_to_le32s (&u.raw [1]);
2384 2387
2385 le16_to_cpus (&u.r.wValue); 2388#define w_value le16_to_cpup (&u.r.wValue)
2386 le16_to_cpus (&u.r.wIndex); 2389#define w_index le16_to_cpup (&u.r.wIndex)
2387 le16_to_cpus (&u.r.wLength); 2390#define w_length le16_to_cpup (&u.r.wLength)
2388 2391
2389 /* ack the irq */ 2392 /* ack the irq */
2390 writel (1 << SETUP_PACKET_INTERRUPT, &dev->regs->irqstat0); 2393 writel (1 << SETUP_PACKET_INTERRUPT, &dev->regs->irqstat0);
@@ -2413,25 +2416,25 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2413 switch (u.r.bRequest) { 2416 switch (u.r.bRequest) {
2414 case USB_REQ_GET_STATUS: { 2417 case USB_REQ_GET_STATUS: {
2415 struct net2280_ep *e; 2418 struct net2280_ep *e;
2416 u16 status; 2419 __le32 status;
2417 2420
2418 /* hw handles device and interface status */ 2421 /* hw handles device and interface status */
2419 if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) 2422 if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT))
2420 goto delegate; 2423 goto delegate;
2421 if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0 2424 if ((e = get_ep_by_addr (dev, w_index)) == 0
2422 || u.r.wLength > 2) 2425 || w_length > 2)
2423 goto do_stall; 2426 goto do_stall;
2424 2427
2425 if (readl (&e->regs->ep_rsp) 2428 if (readl (&e->regs->ep_rsp)
2426 & (1 << SET_ENDPOINT_HALT)) 2429 & (1 << SET_ENDPOINT_HALT))
2427 status = __constant_cpu_to_le16 (1); 2430 status = __constant_cpu_to_le32 (1);
2428 else 2431 else
2429 status = __constant_cpu_to_le16 (0); 2432 status = __constant_cpu_to_le32 (0);
2430 2433
2431 /* don't bother with a request object! */ 2434 /* don't bother with a request object! */
2432 writel (0, &dev->epregs [0].ep_irqenb); 2435 writel (0, &dev->epregs [0].ep_irqenb);
2433 set_fifo_bytecount (ep, u.r.wLength); 2436 set_fifo_bytecount (ep, w_length);
2434 writel (status, &dev->epregs [0].ep_data); 2437 writel ((__force u32)status, &dev->epregs [0].ep_data);
2435 allow_status (ep); 2438 allow_status (ep);
2436 VDEBUG (dev, "%s stat %02x\n", ep->ep.name, status); 2439 VDEBUG (dev, "%s stat %02x\n", ep->ep.name, status);
2437 goto next_endpoints; 2440 goto next_endpoints;
@@ -2443,10 +2446,10 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2443 /* hw handles device features */ 2446 /* hw handles device features */
2444 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 2447 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
2445 goto delegate; 2448 goto delegate;
2446 if (u.r.wValue != USB_ENDPOINT_HALT 2449 if (w_value != USB_ENDPOINT_HALT
2447 || u.r.wLength != 0) 2450 || w_length != 0)
2448 goto do_stall; 2451 goto do_stall;
2449 if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0) 2452 if ((e = get_ep_by_addr (dev, w_index)) == 0)
2450 goto do_stall; 2453 goto do_stall;
2451 clear_halt (e); 2454 clear_halt (e);
2452 allow_status (ep); 2455 allow_status (ep);
@@ -2460,10 +2463,10 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2460 /* hw handles device features */ 2463 /* hw handles device features */
2461 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 2464 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
2462 goto delegate; 2465 goto delegate;
2463 if (u.r.wValue != USB_ENDPOINT_HALT 2466 if (w_value != USB_ENDPOINT_HALT
2464 || u.r.wLength != 0) 2467 || w_length != 0)
2465 goto do_stall; 2468 goto do_stall;
2466 if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0) 2469 if ((e = get_ep_by_addr (dev, w_index)) == 0)
2467 goto do_stall; 2470 goto do_stall;
2468 set_halt (e); 2471 set_halt (e);
2469 allow_status (ep); 2472 allow_status (ep);
@@ -2473,10 +2476,10 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2473 break; 2476 break;
2474 default: 2477 default:
2475delegate: 2478delegate:
2476 VDEBUG (dev, "setup %02x.%02x v%04x i%04x " 2479 VDEBUG (dev, "setup %02x.%02x v%04x i%04x l%04x"
2477 "ep_cfg %08x\n", 2480 "ep_cfg %08x\n",
2478 u.r.bRequestType, u.r.bRequest, 2481 u.r.bRequestType, u.r.bRequest,
2479 u.r.wValue, u.r.wIndex, 2482 w_value, w_index, w_length,
2480 readl (&ep->regs->ep_cfg)); 2483 readl (&ep->regs->ep_cfg));
2481 spin_unlock (&dev->lock); 2484 spin_unlock (&dev->lock);
2482 tmp = dev->driver->setup (&dev->gadget, &u.r); 2485 tmp = dev->driver->setup (&dev->gadget, &u.r);
@@ -2497,6 +2500,10 @@ do_stall:
2497 */ 2500 */
2498 } 2501 }
2499 2502
2503#undef w_value
2504#undef w_index
2505#undef w_length
2506
2500next_endpoints: 2507next_endpoints:
2501 /* endpoint data irq ? */ 2508 /* endpoint data irq ? */
2502 scratch = stat & 0x7f; 2509 scratch = stat & 0x7f;
@@ -2653,7 +2660,7 @@ static void handle_stat1_irqs (struct net2280 *dev, u32 stat)
2653 restart_dma (ep); 2660 restart_dma (ep);
2654 else if (ep->is_in && use_dma_chaining) { 2661 else if (ep->is_in && use_dma_chaining) {
2655 struct net2280_request *req; 2662 struct net2280_request *req;
2656 u32 dmacount; 2663 __le32 dmacount;
2657 2664
2658 /* the descriptor at the head of the chain 2665 /* the descriptor at the head of the chain
2659 * may still have VALID_BIT clear; that's 2666 * may still have VALID_BIT clear; that's
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 98cbcbc16cc1..a2b812af6e66 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -52,7 +52,6 @@
52#include <asm/mach-types.h> 52#include <asm/mach-types.h>
53 53
54#include <asm/arch/dma.h> 54#include <asm/arch/dma.h>
55#include <asm/arch/mux.h>
56#include <asm/arch/usb.h> 55#include <asm/arch/usb.h>
57 56
58#include "omap_udc.h" 57#include "omap_udc.h"
@@ -167,7 +166,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
167 maxp = le16_to_cpu (desc->wMaxPacketSize); 166 maxp = le16_to_cpu (desc->wMaxPacketSize);
168 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK 167 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
169 && maxp != ep->maxpacket) 168 && maxp != ep->maxpacket)
170 || desc->wMaxPacketSize > ep->maxpacket 169 || le16_to_cpu(desc->wMaxPacketSize) > ep->maxpacket
171 || !desc->wMaxPacketSize) { 170 || !desc->wMaxPacketSize) {
172 DBG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name); 171 DBG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name);
173 return -ERANGE; 172 return -ERANGE;
@@ -214,7 +213,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
214 ep->has_dma = 0; 213 ep->has_dma = 0;
215 ep->lch = -1; 214 ep->lch = -1;
216 use_ep(ep, UDC_EP_SEL); 215 use_ep(ep, UDC_EP_SEL);
217 UDC_CTRL_REG = UDC_RESET_EP; 216 UDC_CTRL_REG = udc->clr_halt;
218 ep->ackwait = 0; 217 ep->ackwait = 0;
219 deselect_ep(); 218 deselect_ep();
220 219
@@ -253,7 +252,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
253 } 252 }
254 253
255 spin_lock_irqsave(&ep->udc->lock, flags); 254 spin_lock_irqsave(&ep->udc->lock, flags);
256 ep->desc = 0; 255 ep->desc = NULL;
257 nuke (ep, -ESHUTDOWN); 256 nuke (ep, -ESHUTDOWN);
258 ep->ep.maxpacket = ep->maxpacket; 257 ep->ep.maxpacket = ep->maxpacket;
259 ep->has_dma = 0; 258 ep->has_dma = 0;
@@ -388,8 +387,8 @@ done(struct omap_ep *ep, struct omap_req *req, int status)
388 387
389/*-------------------------------------------------------------------------*/ 388/*-------------------------------------------------------------------------*/
390 389
391#define FIFO_FULL (UDC_NON_ISO_FIFO_FULL | UDC_ISO_FIFO_FULL) 390#define UDC_FIFO_FULL (UDC_NON_ISO_FIFO_FULL | UDC_ISO_FIFO_FULL)
392#define FIFO_UNWRITABLE (UDC_EP_HALTED | FIFO_FULL) 391#define UDC_FIFO_UNWRITABLE (UDC_EP_HALTED | UDC_FIFO_FULL)
393 392
394#define FIFO_EMPTY (UDC_NON_ISO_FIFO_EMPTY | UDC_ISO_FIFO_EMPTY) 393#define FIFO_EMPTY (UDC_NON_ISO_FIFO_EMPTY | UDC_ISO_FIFO_EMPTY)
395#define FIFO_UNREADABLE (UDC_EP_HALTED | FIFO_EMPTY) 394#define FIFO_UNREADABLE (UDC_EP_HALTED | FIFO_EMPTY)
@@ -433,7 +432,7 @@ static int write_fifo(struct omap_ep *ep, struct omap_req *req)
433 432
434 /* PIO-IN isn't double buffered except for iso */ 433 /* PIO-IN isn't double buffered except for iso */
435 ep_stat = UDC_STAT_FLG_REG; 434 ep_stat = UDC_STAT_FLG_REG;
436 if (ep_stat & FIFO_UNWRITABLE) 435 if (ep_stat & UDC_FIFO_UNWRITABLE)
437 return 0; 436 return 0;
438 437
439 count = ep->ep.maxpacket; 438 count = ep->ep.maxpacket;
@@ -504,7 +503,7 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
504 if (ep_stat & UDC_EP_HALTED) 503 if (ep_stat & UDC_EP_HALTED)
505 break; 504 break;
506 505
507 if (ep_stat & FIFO_FULL) 506 if (ep_stat & UDC_FIFO_FULL)
508 avail = ep->ep.maxpacket; 507 avail = ep->ep.maxpacket;
509 else { 508 else {
510 avail = UDC_RXFSTAT_REG; 509 avail = UDC_RXFSTAT_REG;
@@ -538,6 +537,32 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
538 537
539/*-------------------------------------------------------------------------*/ 538/*-------------------------------------------------------------------------*/
540 539
540static inline dma_addr_t dma_csac(unsigned lch)
541{
542 dma_addr_t csac;
543
544 /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
545 * read before the DMA controller finished disabling the channel.
546 */
547 csac = omap_readw(OMAP_DMA_CSAC(lch));
548 if (csac == 0)
549 csac = omap_readw(OMAP_DMA_CSAC(lch));
550 return csac;
551}
552
553static inline dma_addr_t dma_cdac(unsigned lch)
554{
555 dma_addr_t cdac;
556
557 /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
558 * read before the DMA controller finished disabling the channel.
559 */
560 cdac = omap_readw(OMAP_DMA_CDAC(lch));
561 if (cdac == 0)
562 cdac = omap_readw(OMAP_DMA_CDAC(lch));
563 return cdac;
564}
565
541static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start) 566static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
542{ 567{
543 dma_addr_t end; 568 dma_addr_t end;
@@ -548,7 +573,7 @@ static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
548 if (cpu_is_omap15xx()) 573 if (cpu_is_omap15xx())
549 return 0; 574 return 0;
550 575
551 end = omap_readw(OMAP_DMA_CSAC(ep->lch)); 576 end = dma_csac(ep->lch);
552 if (end == ep->dma_counter) 577 if (end == ep->dma_counter)
553 return 0; 578 return 0;
554 579
@@ -559,14 +584,14 @@ static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
559} 584}
560 585
561#define DMA_DEST_LAST(x) (cpu_is_omap15xx() \ 586#define DMA_DEST_LAST(x) (cpu_is_omap15xx() \
562 ? OMAP_DMA_CSAC(x) /* really: CPC */ \ 587 ? omap_readw(OMAP_DMA_CSAC(x)) /* really: CPC */ \
563 : OMAP_DMA_CDAC(x)) 588 : dma_cdac(x))
564 589
565static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start) 590static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start)
566{ 591{
567 dma_addr_t end; 592 dma_addr_t end;
568 593
569 end = omap_readw(DMA_DEST_LAST(ep->lch)); 594 end = DMA_DEST_LAST(ep->lch);
570 if (end == ep->dma_counter) 595 if (end == ep->dma_counter)
571 return 0; 596 return 0;
572 597
@@ -593,7 +618,7 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
593 : OMAP_DMA_SYNC_ELEMENT; 618 : OMAP_DMA_SYNC_ELEMENT;
594 619
595 /* measure length in either bytes or packets */ 620 /* measure length in either bytes or packets */
596 if ((cpu_is_omap16xx() && length <= (UDC_TXN_TSC + 1)) 621 if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC)
597 || (cpu_is_omap15xx() && length < ep->maxpacket)) { 622 || (cpu_is_omap15xx() && length < ep->maxpacket)) {
598 txdma_ctrl = UDC_TXN_EOT | length; 623 txdma_ctrl = UDC_TXN_EOT | length;
599 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 624 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8,
@@ -602,15 +627,15 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
602 length = min(length / ep->maxpacket, 627 length = min(length / ep->maxpacket,
603 (unsigned) UDC_TXN_TSC + 1); 628 (unsigned) UDC_TXN_TSC + 1);
604 txdma_ctrl = length; 629 txdma_ctrl = length;
605 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 630 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
606 ep->ep.maxpacket, length, sync_mode); 631 ep->ep.maxpacket >> 1, length, sync_mode);
607 length *= ep->maxpacket; 632 length *= ep->maxpacket;
608 } 633 }
609 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF, 634 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF,
610 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); 635 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual);
611 636
612 omap_start_dma(ep->lch); 637 omap_start_dma(ep->lch);
613 ep->dma_counter = omap_readw(OMAP_DMA_CSAC(ep->lch)); 638 ep->dma_counter = dma_csac(ep->lch);
614 UDC_DMA_IRQ_EN_REG |= UDC_TX_DONE_IE(ep->dma_channel); 639 UDC_DMA_IRQ_EN_REG |= UDC_TX_DONE_IE(ep->dma_channel);
615 UDC_TXDMA_REG(ep->dma_channel) = UDC_TXN_START | txdma_ctrl; 640 UDC_TXDMA_REG(ep->dma_channel) = UDC_TXN_START | txdma_ctrl;
616 req->dma_bytes = length; 641 req->dma_bytes = length;
@@ -650,12 +675,12 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
650 packets = (req->req.length - req->req.actual) / ep->ep.maxpacket; 675 packets = (req->req.length - req->req.actual) / ep->ep.maxpacket;
651 packets = min(packets, (unsigned)UDC_RXN_TC + 1); 676 packets = min(packets, (unsigned)UDC_RXN_TC + 1);
652 req->dma_bytes = packets * ep->ep.maxpacket; 677 req->dma_bytes = packets * ep->ep.maxpacket;
653 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 678 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
654 ep->ep.maxpacket, packets, 679 ep->ep.maxpacket >> 1, packets,
655 OMAP_DMA_SYNC_ELEMENT); 680 OMAP_DMA_SYNC_ELEMENT);
656 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, 681 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF,
657 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); 682 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual);
658 ep->dma_counter = omap_readw(DMA_DEST_LAST(ep->lch)); 683 ep->dma_counter = DMA_DEST_LAST(ep->lch);
659 684
660 UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1); 685 UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1);
661 UDC_DMA_IRQ_EN_REG |= UDC_RX_EOT_IE(ep->dma_channel); 686 UDC_DMA_IRQ_EN_REG |= UDC_RX_EOT_IE(ep->dma_channel);
@@ -763,7 +788,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
763 reg = UDC_TXDMA_CFG_REG; 788 reg = UDC_TXDMA_CFG_REG;
764 else 789 else
765 reg = UDC_RXDMA_CFG_REG; 790 reg = UDC_RXDMA_CFG_REG;
766 reg |= 1 << 12; /* "pulse" activated */ 791 reg |= UDC_DMA_REQ; /* "pulse" activated */
767 792
768 ep->dma_channel = 0; 793 ep->dma_channel = 0;
769 ep->lch = -1; 794 ep->lch = -1;
@@ -787,6 +812,11 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
787 ep->ep.name, dma_error, ep, &ep->lch); 812 ep->ep.name, dma_error, ep, &ep->lch);
788 if (status == 0) { 813 if (status == 0) {
789 UDC_TXDMA_CFG_REG = reg; 814 UDC_TXDMA_CFG_REG = reg;
815 /* EMIFF */
816 omap_set_dma_src_burst_mode(ep->lch,
817 OMAP_DMA_DATA_BURST_4);
818 omap_set_dma_src_data_pack(ep->lch, 1);
819 /* TIPB */
790 omap_set_dma_dest_params(ep->lch, 820 omap_set_dma_dest_params(ep->lch,
791 OMAP_DMA_PORT_TIPB, 821 OMAP_DMA_PORT_TIPB,
792 OMAP_DMA_AMODE_CONSTANT, 822 OMAP_DMA_AMODE_CONSTANT,
@@ -797,10 +827,15 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
797 ep->ep.name, dma_error, ep, &ep->lch); 827 ep->ep.name, dma_error, ep, &ep->lch);
798 if (status == 0) { 828 if (status == 0) {
799 UDC_RXDMA_CFG_REG = reg; 829 UDC_RXDMA_CFG_REG = reg;
830 /* TIPB */
800 omap_set_dma_src_params(ep->lch, 831 omap_set_dma_src_params(ep->lch,
801 OMAP_DMA_PORT_TIPB, 832 OMAP_DMA_PORT_TIPB,
802 OMAP_DMA_AMODE_CONSTANT, 833 OMAP_DMA_AMODE_CONSTANT,
803 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG)); 834 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG));
835 /* EMIFF */
836 omap_set_dma_dest_burst_mode(ep->lch,
837 OMAP_DMA_DATA_BURST_4);
838 omap_set_dma_dest_data_pack(ep->lch, 1);
804 } 839 }
805 } 840 }
806 if (status) 841 if (status)
@@ -856,7 +891,7 @@ static void dma_channel_release(struct omap_ep *ep)
856 if (!list_empty(&ep->queue)) 891 if (!list_empty(&ep->queue))
857 req = container_of(ep->queue.next, struct omap_req, queue); 892 req = container_of(ep->queue.next, struct omap_req, queue);
858 else 893 else
859 req = 0; 894 req = NULL;
860 895
861 active = ((1 << 7) & omap_readl(OMAP_DMA_CCR(ep->lch))) != 0; 896 active = ((1 << 7) & omap_readl(OMAP_DMA_CCR(ep->lch))) != 0;
862 897
@@ -865,9 +900,13 @@ static void dma_channel_release(struct omap_ep *ep)
865 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r', 900 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r',
866 ep->dma_channel - 1, req); 901 ep->dma_channel - 1, req);
867 902
903 /* NOTE: re-setting RX_REQ/TX_REQ because of a chip bug (before
904 * OMAP 1710 ES2.0) where reading the DMA_CFG can clear them.
905 */
906
868 /* wait till current packet DMA finishes, and fifo empties */ 907 /* wait till current packet DMA finishes, and fifo empties */
869 if (ep->bEndpointAddress & USB_DIR_IN) { 908 if (ep->bEndpointAddress & USB_DIR_IN) {
870 UDC_TXDMA_CFG_REG &= ~mask; 909 UDC_TXDMA_CFG_REG = (UDC_TXDMA_CFG_REG & ~mask) | UDC_DMA_REQ;
871 910
872 if (req) { 911 if (req) {
873 finish_in_dma(ep, req, -ECONNRESET); 912 finish_in_dma(ep, req, -ECONNRESET);
@@ -880,7 +919,7 @@ static void dma_channel_release(struct omap_ep *ep)
880 while (UDC_TXDMA_CFG_REG & mask) 919 while (UDC_TXDMA_CFG_REG & mask)
881 udelay(10); 920 udelay(10);
882 } else { 921 } else {
883 UDC_RXDMA_CFG_REG &= ~mask; 922 UDC_RXDMA_CFG_REG = (UDC_RXDMA_CFG_REG & ~mask) | UDC_DMA_REQ;
884 923
885 /* dma empties the fifo */ 924 /* dma empties the fifo */
886 while (UDC_RXDMA_CFG_REG & mask) 925 while (UDC_RXDMA_CFG_REG & mask)
@@ -997,18 +1036,19 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
997 UDC_IRQ_EN_REG = irq_en; 1036 UDC_IRQ_EN_REG = irq_en;
998 } 1037 }
999 1038
1000 /* STATUS is reverse direction */ 1039 /* STATUS for zero length DATA stages is
1001 UDC_EP_NUM_REG = is_in 1040 * always an IN ... even for IN transfers,
1002 ? UDC_EP_SEL 1041 * a wierd case which seem to stall OMAP.
1003 : (UDC_EP_SEL|UDC_EP_DIR); 1042 */
1043 UDC_EP_NUM_REG = (UDC_EP_SEL|UDC_EP_DIR);
1004 UDC_CTRL_REG = UDC_CLR_EP; 1044 UDC_CTRL_REG = UDC_CLR_EP;
1005 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1045 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1006 UDC_EP_NUM_REG = udc->ep0_in ? 0 : UDC_EP_DIR; 1046 UDC_EP_NUM_REG = UDC_EP_DIR;
1007 1047
1008 /* cleanup */ 1048 /* cleanup */
1009 udc->ep0_pending = 0; 1049 udc->ep0_pending = 0;
1010 done(ep, req, 0); 1050 done(ep, req, 0);
1011 req = 0; 1051 req = NULL;
1012 1052
1013 /* non-empty DATA stage */ 1053 /* non-empty DATA stage */
1014 } else if (is_in) { 1054 } else if (is_in) {
@@ -1029,7 +1069,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
1029 (is_in ? next_in_dma : next_out_dma)(ep, req); 1069 (is_in ? next_in_dma : next_out_dma)(ep, req);
1030 else if (req) { 1070 else if (req) {
1031 if ((is_in ? write_fifo : read_fifo)(ep, req) == 1) 1071 if ((is_in ? write_fifo : read_fifo)(ep, req) == 1)
1032 req = 0; 1072 req = NULL;
1033 deselect_ep(); 1073 deselect_ep();
1034 if (!is_in) { 1074 if (!is_in) {
1035 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1075 UDC_CTRL_REG = UDC_SET_FIFO_EN;
@@ -1041,7 +1081,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
1041 1081
1042irq_wait: 1082irq_wait:
1043 /* irq handler advances the queue */ 1083 /* irq handler advances the queue */
1044 if (req != 0) 1084 if (req != NULL)
1045 list_add_tail(&req->queue, &ep->queue); 1085 list_add_tail(&req->queue, &ep->queue);
1046 spin_unlock_irqrestore(&udc->lock, flags); 1086 spin_unlock_irqrestore(&udc->lock, flags);
1047 1087
@@ -1140,7 +1180,7 @@ static int omap_ep_set_halt(struct usb_ep *_ep, int value)
1140 dma_channel_claim(ep, channel); 1180 dma_channel_claim(ep, channel);
1141 } else { 1181 } else {
1142 use_ep(ep, 0); 1182 use_ep(ep, 0);
1143 UDC_CTRL_REG = UDC_RESET_EP; 1183 UDC_CTRL_REG = ep->udc->clr_halt;
1144 ep->ackwait = 0; 1184 ep->ackwait = 0;
1145 if (!(ep->bEndpointAddress & USB_DIR_IN)) { 1185 if (!(ep->bEndpointAddress & USB_DIR_IN)) {
1146 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1186 UDC_CTRL_REG = UDC_SET_FIFO_EN;
@@ -1238,6 +1278,8 @@ static int can_pullup(struct omap_udc *udc)
1238 1278
1239static void pullup_enable(struct omap_udc *udc) 1279static void pullup_enable(struct omap_udc *udc)
1240{ 1280{
1281 udc->gadget.dev.parent->power.power_state = PMSG_ON;
1282 udc->gadget.dev.power.power_state = PMSG_ON;
1241 UDC_SYSCON1_REG |= UDC_PULLUP_EN; 1283 UDC_SYSCON1_REG |= UDC_PULLUP_EN;
1242#ifndef CONFIG_USB_OTG 1284#ifndef CONFIG_USB_OTG
1243 if (!cpu_is_omap15xx()) 1285 if (!cpu_is_omap15xx())
@@ -1382,7 +1424,7 @@ static void update_otg(struct omap_udc *udc)
1382static void ep0_irq(struct omap_udc *udc, u16 irq_src) 1424static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1383{ 1425{
1384 struct omap_ep *ep0 = &udc->ep[0]; 1426 struct omap_ep *ep0 = &udc->ep[0];
1385 struct omap_req *req = 0; 1427 struct omap_req *req = NULL;
1386 1428
1387 ep0->irqs++; 1429 ep0->irqs++;
1388 1430
@@ -1438,7 +1480,7 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1438 if (req) 1480 if (req)
1439 done(ep0, req, 0); 1481 done(ep0, req, 0);
1440 } 1482 }
1441 req = 0; 1483 req = NULL;
1442 } else if (stat & UDC_STALL) { 1484 } else if (stat & UDC_STALL) {
1443 UDC_CTRL_REG = UDC_CLR_HALT; 1485 UDC_CTRL_REG = UDC_CLR_HALT;
1444 UDC_EP_NUM_REG = UDC_EP_DIR; 1486 UDC_EP_NUM_REG = UDC_EP_DIR;
@@ -1511,9 +1553,10 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1511 u.word[3] = UDC_DATA_REG; 1553 u.word[3] = UDC_DATA_REG;
1512 UDC_EP_NUM_REG = 0; 1554 UDC_EP_NUM_REG = 0;
1513 } while (UDC_IRQ_SRC_REG & UDC_SETUP); 1555 } while (UDC_IRQ_SRC_REG & UDC_SETUP);
1514 le16_to_cpus (&u.r.wValue); 1556
1515 le16_to_cpus (&u.r.wIndex); 1557#define w_value le16_to_cpup (&u.r.wValue)
1516 le16_to_cpus (&u.r.wLength); 1558#define w_index le16_to_cpup (&u.r.wIndex)
1559#define w_length le16_to_cpup (&u.r.wLength)
1517 1560
1518 /* Delegate almost all control requests to the gadget driver, 1561 /* Delegate almost all control requests to the gadget driver,
1519 * except for a handful of ch9 status/feature requests that 1562 * except for a handful of ch9 status/feature requests that
@@ -1529,11 +1572,11 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1529 /* udc needs to know when ep != 0 is valid */ 1572 /* udc needs to know when ep != 0 is valid */
1530 if (u.r.bRequestType != USB_RECIP_DEVICE) 1573 if (u.r.bRequestType != USB_RECIP_DEVICE)
1531 goto delegate; 1574 goto delegate;
1532 if (u.r.wLength != 0) 1575 if (w_length != 0)
1533 goto do_stall; 1576 goto do_stall;
1534 udc->ep0_set_config = 1; 1577 udc->ep0_set_config = 1;
1535 udc->ep0_reset_config = (u.r.wValue == 0); 1578 udc->ep0_reset_config = (w_value == 0);
1536 VDBG("set config %d\n", u.r.wValue); 1579 VDBG("set config %d\n", w_value);
1537 1580
1538 /* update udc NOW since gadget driver may start 1581 /* update udc NOW since gadget driver may start
1539 * queueing requests immediately; clear config 1582 * queueing requests immediately; clear config
@@ -1549,23 +1592,28 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1549 /* clear endpoint halt */ 1592 /* clear endpoint halt */
1550 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 1593 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
1551 goto delegate; 1594 goto delegate;
1552 if (u.r.wValue != USB_ENDPOINT_HALT 1595 if (w_value != USB_ENDPOINT_HALT
1553 || u.r.wLength != 0) 1596 || w_length != 0)
1554 goto do_stall; 1597 goto do_stall;
1555 ep = &udc->ep[u.r.wIndex & 0xf]; 1598 ep = &udc->ep[w_index & 0xf];
1556 if (ep != ep0) { 1599 if (ep != ep0) {
1557 if (u.r.wIndex & USB_DIR_IN) 1600 if (w_index & USB_DIR_IN)
1558 ep += 16; 1601 ep += 16;
1559 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC 1602 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
1560 || !ep->desc) 1603 || !ep->desc)
1561 goto do_stall; 1604 goto do_stall;
1562 use_ep(ep, 0); 1605 use_ep(ep, 0);
1563 UDC_CTRL_REG = UDC_RESET_EP; 1606 UDC_CTRL_REG = udc->clr_halt;
1564 ep->ackwait = 0; 1607 ep->ackwait = 0;
1565 if (!(ep->bEndpointAddress & USB_DIR_IN)) { 1608 if (!(ep->bEndpointAddress & USB_DIR_IN)) {
1566 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1609 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1567 ep->ackwait = 1 + ep->double_buf; 1610 ep->ackwait = 1 + ep->double_buf;
1568 } 1611 }
1612 /* NOTE: assumes the host behaves sanely,
1613 * only clearing real halts. Else we may
1614 * need to kill pending transfers and then
1615 * restart the queue... very messy for DMA!
1616 */
1569 } 1617 }
1570 VDBG("%s halt cleared by host\n", ep->name); 1618 VDBG("%s halt cleared by host\n", ep->name);
1571 goto ep0out_status_stage; 1619 goto ep0out_status_stage;
@@ -1573,11 +1621,11 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1573 /* set endpoint halt */ 1621 /* set endpoint halt */
1574 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 1622 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
1575 goto delegate; 1623 goto delegate;
1576 if (u.r.wValue != USB_ENDPOINT_HALT 1624 if (w_value != USB_ENDPOINT_HALT
1577 || u.r.wLength != 0) 1625 || w_length != 0)
1578 goto do_stall; 1626 goto do_stall;
1579 ep = &udc->ep[u.r.wIndex & 0xf]; 1627 ep = &udc->ep[w_index & 0xf];
1580 if (u.r.wIndex & USB_DIR_IN) 1628 if (w_index & USB_DIR_IN)
1581 ep += 16; 1629 ep += 16;
1582 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC 1630 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
1583 || ep == ep0 || !ep->desc) 1631 || ep == ep0 || !ep->desc)
@@ -1615,13 +1663,13 @@ ep0out_status_stage:
1615 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1663 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1616 UDC_EP_NUM_REG = UDC_EP_DIR; 1664 UDC_EP_NUM_REG = UDC_EP_DIR;
1617 status = 0; 1665 status = 0;
1618 VDBG("GET_STATUS, interface %d\n", u.r.wIndex); 1666 VDBG("GET_STATUS, interface %d\n", w_index);
1619 /* next, status stage */ 1667 /* next, status stage */
1620 break; 1668 break;
1621 default: 1669 default:
1622delegate: 1670delegate:
1623 /* activate the ep0out fifo right away */ 1671 /* activate the ep0out fifo right away */
1624 if (!udc->ep0_in && u.r.wLength) { 1672 if (!udc->ep0_in && w_length) {
1625 UDC_EP_NUM_REG = 0; 1673 UDC_EP_NUM_REG = 0;
1626 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1674 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1627 } 1675 }
@@ -1632,7 +1680,11 @@ delegate:
1632 */ 1680 */
1633 VDBG("SETUP %02x.%02x v%04x i%04x l%04x\n", 1681 VDBG("SETUP %02x.%02x v%04x i%04x l%04x\n",
1634 u.r.bRequestType, u.r.bRequest, 1682 u.r.bRequestType, u.r.bRequest,
1635 u.r.wValue, u.r.wIndex, u.r.wLength); 1683 w_value, w_index, w_length);
1684
1685#undef w_value
1686#undef w_index
1687#undef w_length
1636 1688
1637 /* The gadget driver may return an error here, 1689 /* The gadget driver may return an error here,
1638 * causing an immediate protocol stall. 1690 * causing an immediate protocol stall.
@@ -2013,7 +2065,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2013 udc->softconnect = 1; 2065 udc->softconnect = 1;
2014 2066
2015 /* hook up the driver */ 2067 /* hook up the driver */
2016 driver->driver.bus = 0; 2068 driver->driver.bus = NULL;
2017 udc->driver = driver; 2069 udc->driver = driver;
2018 udc->gadget.dev.driver = &driver->driver; 2070 udc->gadget.dev.driver = &driver->driver;
2019 spin_unlock_irqrestore(&udc->lock, flags); 2071 spin_unlock_irqrestore(&udc->lock, flags);
@@ -2021,8 +2073,8 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2021 status = driver->bind (&udc->gadget); 2073 status = driver->bind (&udc->gadget);
2022 if (status) { 2074 if (status) {
2023 DBG("bind to %s --> %d\n", driver->driver.name, status); 2075 DBG("bind to %s --> %d\n", driver->driver.name, status);
2024 udc->gadget.dev.driver = 0; 2076 udc->gadget.dev.driver = NULL;
2025 udc->driver = 0; 2077 udc->driver = NULL;
2026 goto done; 2078 goto done;
2027 } 2079 }
2028 DBG("bound to driver %s\n", driver->driver.name); 2080 DBG("bound to driver %s\n", driver->driver.name);
@@ -2035,8 +2087,8 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2035 if (status < 0) { 2087 if (status < 0) {
2036 ERR("can't bind to transceiver\n"); 2088 ERR("can't bind to transceiver\n");
2037 driver->unbind (&udc->gadget); 2089 driver->unbind (&udc->gadget);
2038 udc->gadget.dev.driver = 0; 2090 udc->gadget.dev.driver = NULL;
2039 udc->driver = 0; 2091 udc->driver = NULL;
2040 goto done; 2092 goto done;
2041 } 2093 }
2042 } else { 2094 } else {
@@ -2071,7 +2123,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2071 omap_vbus_session(&udc->gadget, 0); 2123 omap_vbus_session(&udc->gadget, 0);
2072 2124
2073 if (udc->transceiver) 2125 if (udc->transceiver)
2074 (void) otg_set_peripheral(udc->transceiver, 0); 2126 (void) otg_set_peripheral(udc->transceiver, NULL);
2075 else 2127 else
2076 pullup_disable(udc); 2128 pullup_disable(udc);
2077 2129
@@ -2080,9 +2132,8 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2080 spin_unlock_irqrestore(&udc->lock, flags); 2132 spin_unlock_irqrestore(&udc->lock, flags);
2081 2133
2082 driver->unbind(&udc->gadget); 2134 driver->unbind(&udc->gadget);
2083 udc->gadget.dev.driver = 0; 2135 udc->gadget.dev.driver = NULL;
2084 udc->driver = 0; 2136 udc->driver = NULL;
2085
2086 2137
2087 DBG("unregistered driver '%s'\n", driver->driver.name); 2138 DBG("unregistered driver '%s'\n", driver->driver.name);
2088 return status; 2139 return status;
@@ -2178,14 +2229,14 @@ static int proc_otg_show(struct seq_file *s)
2178 2229
2179 tmp = OTG_REV_REG; 2230 tmp = OTG_REV_REG;
2180 trans = USB_TRANSCEIVER_CTRL_REG; 2231 trans = USB_TRANSCEIVER_CTRL_REG;
2181 seq_printf(s, "OTG rev %d.%d, transceiver_ctrl %03x\n", 2232 seq_printf(s, "\nOTG rev %d.%d, transceiver_ctrl %05x\n",
2182 tmp >> 4, tmp & 0xf, trans); 2233 tmp >> 4, tmp & 0xf, trans);
2183 tmp = OTG_SYSCON_1_REG; 2234 tmp = OTG_SYSCON_1_REG;
2184 seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s," 2235 seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s,"
2185 FOURBITS "\n", tmp, 2236 FOURBITS "\n", tmp,
2186 trx_mode(USB2_TRX_MODE(tmp), trans & CONF_USB2_UNI_R), 2237 trx_mode(USB2_TRX_MODE(tmp), trans & CONF_USB2_UNI_R),
2187 trx_mode(USB1_TRX_MODE(tmp), trans & CONF_USB1_UNI_R), 2238 trx_mode(USB1_TRX_MODE(tmp), trans & CONF_USB1_UNI_R),
2188 (USB0_TRX_MODE(tmp) == 0) 2239 (USB0_TRX_MODE(tmp) == 0 && !cpu_is_omap1710())
2189 ? "internal" 2240 ? "internal"
2190 : trx_mode(USB0_TRX_MODE(tmp), 1), 2241 : trx_mode(USB0_TRX_MODE(tmp), 1),
2191 (tmp & OTG_IDLE_EN) ? " !otg" : "", 2242 (tmp & OTG_IDLE_EN) ? " !otg" : "",
@@ -2235,6 +2286,7 @@ static int proc_otg_show(struct seq_file *s)
2235 seq_printf(s, "otg_outctrl %04x" "\n", tmp); 2286 seq_printf(s, "otg_outctrl %04x" "\n", tmp);
2236 tmp = OTG_TEST_REG; 2287 tmp = OTG_TEST_REG;
2237 seq_printf(s, "otg_test %04x" "\n", tmp); 2288 seq_printf(s, "otg_test %04x" "\n", tmp);
2289 return 0;
2238} 2290}
2239 2291
2240static int proc_udc_show(struct seq_file *s, void *_) 2292static int proc_udc_show(struct seq_file *s, void *_)
@@ -2378,7 +2430,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
2378 2430
2379static int proc_udc_open(struct inode *inode, struct file *file) 2431static int proc_udc_open(struct inode *inode, struct file *file)
2380{ 2432{
2381 return single_open(file, proc_udc_show, 0); 2433 return single_open(file, proc_udc_show, NULL);
2382} 2434}
2383 2435
2384static struct file_operations proc_ops = { 2436static struct file_operations proc_ops = {
@@ -2399,7 +2451,7 @@ static void create_proc_file(void)
2399 2451
2400static void remove_proc_file(void) 2452static void remove_proc_file(void)
2401{ 2453{
2402 remove_proc_entry(proc_filename, 0); 2454 remove_proc_entry(proc_filename, NULL);
2403} 2455}
2404 2456
2405#else 2457#else
@@ -2414,6 +2466,10 @@ static inline void remove_proc_file(void) {}
2414/* Before this controller can enumerate, we need to pick an endpoint 2466/* Before this controller can enumerate, we need to pick an endpoint
2415 * configuration, or "fifo_mode" That involves allocating 2KB of packet 2467 * configuration, or "fifo_mode" That involves allocating 2KB of packet
2416 * buffer space among the endpoints we'll be operating. 2468 * buffer space among the endpoints we'll be operating.
2469 *
2470 * NOTE: as of OMAP 1710 ES2.0, writing a new endpoint config when
2471 * UDC_SYSCON_1_REG.CFG_LOCK is set can now work. We won't use that
2472 * capability yet though.
2417 */ 2473 */
2418static unsigned __init 2474static unsigned __init
2419omap_ep_setup(char *name, u8 addr, u8 type, 2475omap_ep_setup(char *name, u8 addr, u8 type,
@@ -2505,7 +2561,7 @@ static void omap_udc_release(struct device *dev)
2505{ 2561{
2506 complete(udc->done); 2562 complete(udc->done);
2507 kfree (udc); 2563 kfree (udc);
2508 udc = 0; 2564 udc = NULL;
2509} 2565}
2510 2566
2511static int __init 2567static int __init
@@ -2577,23 +2633,33 @@ omap_udc_setup(struct platform_device *odev, struct otg_transceiver *xceiv)
2577 case 1: 2633 case 1:
2578 OMAP_BULK_EP("ep1in", USB_DIR_IN | 1); 2634 OMAP_BULK_EP("ep1in", USB_DIR_IN | 1);
2579 OMAP_BULK_EP("ep2out", USB_DIR_OUT | 2); 2635 OMAP_BULK_EP("ep2out", USB_DIR_OUT | 2);
2636 OMAP_INT_EP("ep9in", USB_DIR_IN | 9, 16);
2637
2580 OMAP_BULK_EP("ep3in", USB_DIR_IN | 3); 2638 OMAP_BULK_EP("ep3in", USB_DIR_IN | 3);
2581 OMAP_BULK_EP("ep4out", USB_DIR_OUT | 4); 2639 OMAP_BULK_EP("ep4out", USB_DIR_OUT | 4);
2640 OMAP_INT_EP("ep10in", USB_DIR_IN | 10, 16);
2582 2641
2583 OMAP_BULK_EP("ep5in", USB_DIR_IN | 5); 2642 OMAP_BULK_EP("ep5in", USB_DIR_IN | 5);
2584 OMAP_BULK_EP("ep5out", USB_DIR_OUT | 5); 2643 OMAP_BULK_EP("ep5out", USB_DIR_OUT | 5);
2644 OMAP_INT_EP("ep11in", USB_DIR_IN | 11, 16);
2645
2585 OMAP_BULK_EP("ep6in", USB_DIR_IN | 6); 2646 OMAP_BULK_EP("ep6in", USB_DIR_IN | 6);
2586 OMAP_BULK_EP("ep6out", USB_DIR_OUT | 6); 2647 OMAP_BULK_EP("ep6out", USB_DIR_OUT | 6);
2648 OMAP_INT_EP("ep12in", USB_DIR_IN | 12, 16);
2587 2649
2588 OMAP_BULK_EP("ep7in", USB_DIR_IN | 7); 2650 OMAP_BULK_EP("ep7in", USB_DIR_IN | 7);
2589 OMAP_BULK_EP("ep7out", USB_DIR_OUT | 7); 2651 OMAP_BULK_EP("ep7out", USB_DIR_OUT | 7);
2652 OMAP_INT_EP("ep13in", USB_DIR_IN | 13, 16);
2653 OMAP_INT_EP("ep13out", USB_DIR_OUT | 13, 16);
2654
2590 OMAP_BULK_EP("ep8in", USB_DIR_IN | 8); 2655 OMAP_BULK_EP("ep8in", USB_DIR_IN | 8);
2591 OMAP_BULK_EP("ep8out", USB_DIR_OUT | 8); 2656 OMAP_BULK_EP("ep8out", USB_DIR_OUT | 8);
2657 OMAP_INT_EP("ep14in", USB_DIR_IN | 14, 16);
2658 OMAP_INT_EP("ep14out", USB_DIR_OUT | 14, 16);
2659
2660 OMAP_BULK_EP("ep15in", USB_DIR_IN | 15);
2661 OMAP_BULK_EP("ep15out", USB_DIR_OUT | 15);
2592 2662
2593 OMAP_INT_EP("ep9in", USB_DIR_IN | 9, 16);
2594 OMAP_INT_EP("ep10out", USB_DIR_IN | 10, 16);
2595 OMAP_INT_EP("ep11in", USB_DIR_IN | 9, 16);
2596 OMAP_INT_EP("ep12out", USB_DIR_IN | 10, 16);
2597 break; 2663 break;
2598 2664
2599#ifdef USE_ISO 2665#ifdef USE_ISO
@@ -2640,8 +2706,8 @@ static int __init omap_udc_probe(struct device *dev)
2640 struct platform_device *odev = to_platform_device(dev); 2706 struct platform_device *odev = to_platform_device(dev);
2641 int status = -ENODEV; 2707 int status = -ENODEV;
2642 int hmc; 2708 int hmc;
2643 struct otg_transceiver *xceiv = 0; 2709 struct otg_transceiver *xceiv = NULL;
2644 const char *type = 0; 2710 const char *type = NULL;
2645 struct omap_usb_config *config = dev->platform_data; 2711 struct omap_usb_config *config = dev->platform_data;
2646 2712
2647 /* NOTE: "knows" the order of the resources! */ 2713 /* NOTE: "knows" the order of the resources! */
@@ -2676,54 +2742,78 @@ static int __init omap_udc_probe(struct device *dev)
2676 FUNC_MUX_CTRL_0_REG = tmp; 2742 FUNC_MUX_CTRL_0_REG = tmp;
2677 } 2743 }
2678 } else { 2744 } else {
2745 /* The transceiver may package some GPIO logic or handle
2746 * loopback and/or transceiverless setup; if we find one,
2747 * use it. Except for OTG, we don't _need_ to talk to one;
2748 * but not having one probably means no VBUS detection.
2749 */
2750 xceiv = otg_get_transceiver();
2751 if (xceiv)
2752 type = xceiv->label;
2753 else if (config->otg) {
2754 DBG("OTG requires external transceiver!\n");
2755 goto cleanup0;
2756 }
2757
2679 hmc = HMC_1610; 2758 hmc = HMC_1610;
2680 switch (hmc) { 2759 switch (hmc) {
2760 case 0: /* POWERUP DEFAULT == 0 */
2761 case 4:
2762 case 12:
2763 case 20:
2764 if (!cpu_is_omap1710()) {
2765 type = "integrated";
2766 break;
2767 }
2768 /* FALL THROUGH */
2681 case 3: 2769 case 3:
2682 case 11: 2770 case 11:
2683 case 16: 2771 case 16:
2684 case 19: 2772 case 19:
2685 case 25: 2773 case 25:
2686 xceiv = otg_get_transceiver();
2687 if (!xceiv) { 2774 if (!xceiv) {
2688 DBG("external transceiver not registered!\n"); 2775 DBG("external transceiver not registered!\n");
2689 if (config->otg) 2776 type = "unknown";
2690 goto cleanup0; 2777 }
2691 type = "(unknown external)";
2692 } else
2693 type = xceiv->label;
2694 break;
2695 case 0: /* POWERUP DEFAULT == 0 */
2696 case 4:
2697 case 12:
2698 case 20:
2699 type = "INTEGRATED";
2700 break; 2778 break;
2701 case 21: /* internal loopback */ 2779 case 21: /* internal loopback */
2702 type = "(loopback)"; 2780 type = "loopback";
2703 break; 2781 break;
2704 case 14: /* transceiverless */ 2782 case 14: /* transceiverless */
2705 type = "(none)"; 2783 if (cpu_is_omap1710())
2784 goto bad_on_1710;
2785 /* FALL THROUGH */
2786 case 13:
2787 case 15:
2788 type = "no";
2706 break; 2789 break;
2707 2790
2708 default: 2791 default:
2792bad_on_1710:
2709 ERR("unrecognized UDC HMC mode %d\n", hmc); 2793 ERR("unrecognized UDC HMC mode %d\n", hmc);
2710 return -ENODEV; 2794 goto cleanup0;
2711 } 2795 }
2712 } 2796 }
2713 INFO("hmc mode %d, transceiver %s\n", hmc, type); 2797 INFO("hmc mode %d, %s transceiver\n", hmc, type);
2714 2798
2715 /* a "gadget" abstracts/virtualizes the controller */ 2799 /* a "gadget" abstracts/virtualizes the controller */
2716 status = omap_udc_setup(odev, xceiv); 2800 status = omap_udc_setup(odev, xceiv);
2717 if (status) { 2801 if (status) {
2718 goto cleanup0; 2802 goto cleanup0;
2719 } 2803 }
2720 xceiv = 0; 2804 xceiv = NULL;
2721 // "udc" is now valid 2805 // "udc" is now valid
2722 pullup_disable(udc); 2806 pullup_disable(udc);
2723#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) 2807#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
2724 udc->gadget.is_otg = (config->otg != 0); 2808 udc->gadget.is_otg = (config->otg != 0);
2725#endif 2809#endif
2726 2810
2811 /* starting with omap1710 es2.0, clear toggle is a separate bit */
2812 if (UDC_REV_REG >= 0x61)
2813 udc->clr_halt = UDC_RESET_EP | UDC_CLRDATA_TOGGLE;
2814 else
2815 udc->clr_halt = UDC_RESET_EP;
2816
2727 /* USB general purpose IRQ: ep0, state changes, dma, etc */ 2817 /* USB general purpose IRQ: ep0, state changes, dma, etc */
2728 status = request_irq(odev->resource[1].start, omap_udc_irq, 2818 status = request_irq(odev->resource[1].start, omap_udc_irq,
2729 SA_SAMPLE_RANDOM, driver_name, udc); 2819 SA_SAMPLE_RANDOM, driver_name, udc);
@@ -2765,7 +2855,7 @@ cleanup2:
2765 2855
2766cleanup1: 2856cleanup1:
2767 kfree (udc); 2857 kfree (udc);
2768 udc = 0; 2858 udc = NULL;
2769 2859
2770cleanup0: 2860cleanup0:
2771 if (xceiv) 2861 if (xceiv)
@@ -2788,7 +2878,7 @@ static int __exit omap_udc_remove(struct device *dev)
2788 pullup_disable(udc); 2878 pullup_disable(udc);
2789 if (udc->transceiver) { 2879 if (udc->transceiver) {
2790 put_device(udc->transceiver->dev); 2880 put_device(udc->transceiver->dev);
2791 udc->transceiver = 0; 2881 udc->transceiver = NULL;
2792 } 2882 }
2793 UDC_SYSCON1_REG = 0; 2883 UDC_SYSCON1_REG = 0;
2794 2884
@@ -2809,13 +2899,32 @@ static int __exit omap_udc_remove(struct device *dev)
2809 return 0; 2899 return 0;
2810} 2900}
2811 2901
2812static int omap_udc_suspend(struct device *dev, pm_message_t state, u32 level) 2902/* suspend/resume/wakeup from sysfs (echo > power/state) or when the
2903 * system is forced into deep sleep
2904 *
2905 * REVISIT we should probably reject suspend requests when there's a host
2906 * session active, rather than disconnecting, at least on boards that can
2907 * report VBUS irqs (UDC_DEVSTAT_REG.UDC_ATT). And in any case, we need to
2908 * make host resumes and VBUS detection trigger OMAP wakeup events; that
2909 * may involve talking to an external transceiver (e.g. isp1301).
2910 */
2911static int omap_udc_suspend(struct device *dev, pm_message_t message, u32 level)
2813{ 2912{
2814 if (level != 0) 2913 u32 devstat;
2914
2915 if (level != SUSPEND_POWER_DOWN)
2815 return 0; 2916 return 0;
2917 devstat = UDC_DEVSTAT_REG;
2918
2919 /* we're requesting 48 MHz clock if the pullup is enabled
2920 * (== we're attached to the host) and we're not suspended,
2921 * which would prevent entry to deep sleep...
2922 */
2923 if ((devstat & UDC_ATT) != 0 && (devstat & UDC_SUS) == 0) {
2924 WARN("session active; suspend requires disconnect\n");
2925 omap_pullup(&udc->gadget, 0);
2926 }
2816 2927
2817 DBG("suspend, state %d\n", state);
2818 omap_pullup(&udc->gadget, 0);
2819 udc->gadget.dev.power.power_state = PMSG_SUSPEND; 2928 udc->gadget.dev.power.power_state = PMSG_SUSPEND;
2820 udc->gadget.dev.parent->power.power_state = PMSG_SUSPEND; 2929 udc->gadget.dev.parent->power.power_state = PMSG_SUSPEND;
2821 return 0; 2930 return 0;
@@ -2823,7 +2932,7 @@ static int omap_udc_suspend(struct device *dev, pm_message_t state, u32 level)
2823 2932
2824static int omap_udc_resume(struct device *dev, u32 level) 2933static int omap_udc_resume(struct device *dev, u32 level)
2825{ 2934{
2826 if (level != 0) 2935 if (level != RESUME_POWER_ON)
2827 return 0; 2936 return 0;
2828 2937
2829 DBG("resume + wakeup/SRP\n"); 2938 DBG("resume + wakeup/SRP\n");
diff --git a/drivers/usb/gadget/omap_udc.h b/drivers/usb/gadget/omap_udc.h
index c9e68541622c..652ee4627344 100644
--- a/drivers/usb/gadget/omap_udc.h
+++ b/drivers/usb/gadget/omap_udc.h
@@ -20,6 +20,7 @@
20#define UDC_CTRL_REG UDC_REG(0x0C) /* Endpoint control */ 20#define UDC_CTRL_REG UDC_REG(0x0C) /* Endpoint control */
21# define UDC_CLR_HALT (1 << 7) 21# define UDC_CLR_HALT (1 << 7)
22# define UDC_SET_HALT (1 << 6) 22# define UDC_SET_HALT (1 << 6)
23# define UDC_CLRDATA_TOGGLE (1 << 3)
23# define UDC_SET_FIFO_EN (1 << 2) 24# define UDC_SET_FIFO_EN (1 << 2)
24# define UDC_CLR_EP (1 << 1) 25# define UDC_CLR_EP (1 << 1)
25# define UDC_RESET_EP (1 << 0) 26# define UDC_RESET_EP (1 << 0)
@@ -99,6 +100,7 @@
99 100
100/* DMA configuration registers: up to three channels in each direction. */ 101/* DMA configuration registers: up to three channels in each direction. */
101#define UDC_RXDMA_CFG_REG UDC_REG(0x40) /* 3 eps for RX DMA */ 102#define UDC_RXDMA_CFG_REG UDC_REG(0x40) /* 3 eps for RX DMA */
103# define UDC_DMA_REQ (1 << 12)
102#define UDC_TXDMA_CFG_REG UDC_REG(0x44) /* 3 eps for TX DMA */ 104#define UDC_TXDMA_CFG_REG UDC_REG(0x44) /* 3 eps for TX DMA */
103#define UDC_DATA_DMA_REG UDC_REG(0x48) /* rx/tx fifo addr */ 105#define UDC_DATA_DMA_REG UDC_REG(0x48) /* rx/tx fifo addr */
104 106
@@ -162,6 +164,7 @@ struct omap_udc {
162 spinlock_t lock; 164 spinlock_t lock;
163 struct omap_ep ep[32]; 165 struct omap_ep ep[32];
164 u16 devstat; 166 u16 devstat;
167 u16 clr_halt;
165 struct otg_transceiver *transceiver; 168 struct otg_transceiver *transceiver;
166 struct list_head iso; 169 struct list_head iso;
167 unsigned softconnect:1; 170 unsigned softconnect:1;
@@ -171,7 +174,6 @@ struct omap_udc {
171 unsigned ep0_set_config:1; 174 unsigned ep0_set_config:1;
172 unsigned ep0_reset_config:1; 175 unsigned ep0_reset_config:1;
173 unsigned ep0_setup:1; 176 unsigned ep0_setup:1;
174
175 struct completion *done; 177 struct completion *done;
176}; 178};
177 179
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index b8b4524ed746..6a0b957af335 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * linux/drivers/usb/gadget/pxa2xx_udc.c 2 * linux/drivers/usb/gadget/pxa2xx_udc.c
3 * Intel PXA2xx and IXP4xx on-chip full speed USB device controllers 3 * Intel PXA25x and IXP4xx on-chip full speed USB device controllers
4 * 4 *
5 * Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker) 5 * Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker)
6 * Copyright (C) 2003 Robert Schwebel, Pengutronix 6 * Copyright (C) 2003 Robert Schwebel, Pengutronix
@@ -63,7 +63,7 @@
63 63
64 64
65/* 65/*
66 * This driver handles the USB Device Controller (UDC) in Intel's PXA 2xx 66 * This driver handles the USB Device Controller (UDC) in Intel's PXA 25x
67 * series processors. The UDC for the IXP 4xx series is very similar. 67 * series processors. The UDC for the IXP 4xx series is very similar.
68 * There are fifteen endpoints, in addition to ep0. 68 * There are fifteen endpoints, in addition to ep0.
69 * 69 *
@@ -79,8 +79,8 @@
79 * pxa250 a0/a1 b0/b1/b2 sure act like they're still there. 79 * pxa250 a0/a1 b0/b1/b2 sure act like they're still there.
80 */ 80 */
81 81
82#define DRIVER_VERSION "14-Dec-2003" 82#define DRIVER_VERSION "4-May-2005"
83#define DRIVER_DESC "PXA 2xx USB Device Controller driver" 83#define DRIVER_DESC "PXA 25x USB Device Controller driver"
84 84
85 85
86static const char driver_name [] = "pxa2xx_udc"; 86static const char driver_name [] = "pxa2xx_udc";
@@ -290,6 +290,7 @@ static int pxa2xx_ep_enable (struct usb_ep *_ep,
290static int pxa2xx_ep_disable (struct usb_ep *_ep) 290static int pxa2xx_ep_disable (struct usb_ep *_ep)
291{ 291{
292 struct pxa2xx_ep *ep; 292 struct pxa2xx_ep *ep;
293 unsigned long flags;
293 294
294 ep = container_of (_ep, struct pxa2xx_ep, ep); 295 ep = container_of (_ep, struct pxa2xx_ep, ep);
295 if (!_ep || !ep->desc) { 296 if (!_ep || !ep->desc) {
@@ -297,6 +298,8 @@ static int pxa2xx_ep_disable (struct usb_ep *_ep)
297 _ep ? ep->ep.name : NULL); 298 _ep ? ep->ep.name : NULL);
298 return -EINVAL; 299 return -EINVAL;
299 } 300 }
301 local_irq_save(flags);
302
300 nuke (ep, -ESHUTDOWN); 303 nuke (ep, -ESHUTDOWN);
301 304
302#ifdef USE_DMA 305#ifdef USE_DMA
@@ -313,6 +316,7 @@ static int pxa2xx_ep_disable (struct usb_ep *_ep)
313 ep->desc = NULL; 316 ep->desc = NULL;
314 ep->stopped = 1; 317 ep->stopped = 1;
315 318
319 local_irq_restore(flags);
316 DBG(DBG_VERBOSE, "%s disabled\n", _ep->name); 320 DBG(DBG_VERBOSE, "%s disabled\n", _ep->name);
317 return 0; 321 return 0;
318} 322}
@@ -971,10 +975,10 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
971 kick_dma(ep, req); 975 kick_dma(ep, req);
972#endif 976#endif
973 /* can the FIFO can satisfy the request immediately? */ 977 /* can the FIFO can satisfy the request immediately? */
974 } else if ((ep->bEndpointAddress & USB_DIR_IN) != 0 978 } else if ((ep->bEndpointAddress & USB_DIR_IN) != 0) {
975 && (*ep->reg_udccs & UDCCS_BI_TFS) != 0 979 if ((*ep->reg_udccs & UDCCS_BI_TFS) != 0
976 && write_fifo(ep, req)) { 980 && write_fifo(ep, req))
977 req = NULL; 981 req = NULL;
978 } else if ((*ep->reg_udccs & UDCCS_BO_RFS) != 0 982 } else if ((*ep->reg_udccs & UDCCS_BO_RFS) != 0
979 && read_fifo(ep, req)) { 983 && read_fifo(ep, req)) {
980 req = NULL; 984 req = NULL;
@@ -1290,7 +1294,7 @@ udc_proc_read(char *page, char **start, off_t off, int count,
1290 "%s version: %s\nGadget driver: %s\nHost %s\n\n", 1294 "%s version: %s\nGadget driver: %s\nHost %s\n\n",
1291 driver_name, DRIVER_VERSION SIZE_STR DMASTR, 1295 driver_name, DRIVER_VERSION SIZE_STR DMASTR,
1292 dev->driver ? dev->driver->driver.name : "(none)", 1296 dev->driver ? dev->driver->driver.name : "(none)",
1293 is_usb_connected() ? "full speed" : "disconnected"); 1297 is_vbus_present() ? "full speed" : "disconnected");
1294 size -= t; 1298 size -= t;
1295 next += t; 1299 next += t;
1296 1300
@@ -1339,7 +1343,7 @@ udc_proc_read(char *page, char **start, off_t off, int count,
1339 next += t; 1343 next += t;
1340 } 1344 }
1341 1345
1342 if (!is_usb_connected() || !dev->driver) 1346 if (!is_vbus_present() || !dev->driver)
1343 goto done; 1347 goto done;
1344 1348
1345 t = scnprintf(next, size, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n", 1349 t = scnprintf(next, size, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
@@ -1454,7 +1458,7 @@ static void udc_disable(struct pxa2xx_udc *dev)
1454 UFNRH = UFNRH_SIM; 1458 UFNRH = UFNRH_SIM;
1455 1459
1456 /* if hardware supports it, disconnect from usb */ 1460 /* if hardware supports it, disconnect from usb */
1457 make_usb_disappear(); 1461 pullup_off();
1458 1462
1459 udc_clear_mask_UDCCR(UDCCR_UDE); 1463 udc_clear_mask_UDCCR(UDCCR_UDE);
1460 1464
@@ -1567,7 +1571,7 @@ static void udc_enable (struct pxa2xx_udc *dev)
1567 UICR0 &= ~UICR0_IM0; 1571 UICR0 &= ~UICR0_IM0;
1568 1572
1569 /* if hardware supports it, pullup D+ and wait for reset */ 1573 /* if hardware supports it, pullup D+ and wait for reset */
1570 let_usb_appear(); 1574 pullup_on();
1571} 1575}
1572 1576
1573 1577
@@ -2052,10 +2056,10 @@ pxa2xx_udc_irq(int irq, void *_dev, struct pt_regs *r)
2052 if (unlikely(udccr & UDCCR_SUSIR)) { 2056 if (unlikely(udccr & UDCCR_SUSIR)) {
2053 udc_ack_int_UDCCR(UDCCR_SUSIR); 2057 udc_ack_int_UDCCR(UDCCR_SUSIR);
2054 handled = 1; 2058 handled = 1;
2055 DBG(DBG_VERBOSE, "USB suspend%s\n", is_usb_connected() 2059 DBG(DBG_VERBOSE, "USB suspend%s\n", is_vbus_present()
2056 ? "" : "+disconnect"); 2060 ? "" : "+disconnect");
2057 2061
2058 if (!is_usb_connected()) 2062 if (!is_vbus_present())
2059 stop_activity(dev, dev->driver); 2063 stop_activity(dev, dev->driver);
2060 else if (dev->gadget.speed != USB_SPEED_UNKNOWN 2064 else if (dev->gadget.speed != USB_SPEED_UNKNOWN
2061 && dev->driver 2065 && dev->driver
@@ -2073,7 +2077,7 @@ pxa2xx_udc_irq(int irq, void *_dev, struct pt_regs *r)
2073 if (dev->gadget.speed != USB_SPEED_UNKNOWN 2077 if (dev->gadget.speed != USB_SPEED_UNKNOWN
2074 && dev->driver 2078 && dev->driver
2075 && dev->driver->resume 2079 && dev->driver->resume
2076 && is_usb_connected()) 2080 && is_vbus_present())
2077 dev->driver->resume(&dev->gadget); 2081 dev->driver->resume(&dev->gadget);
2078 } 2082 }
2079 2083
@@ -2509,7 +2513,7 @@ static int __init pxa2xx_udc_probe(struct device *_dev)
2509 udc_disable(dev); 2513 udc_disable(dev);
2510 udc_reinit(dev); 2514 udc_reinit(dev);
2511 2515
2512 dev->vbus = is_usb_connected(); 2516 dev->vbus = is_vbus_present();
2513 2517
2514 /* irq setup after old hardware state is cleaned up */ 2518 /* irq setup after old hardware state is cleaned up */
2515 retval = request_irq(IRQ_USB, pxa2xx_udc_irq, 2519 retval = request_irq(IRQ_USB, pxa2xx_udc_irq,
@@ -2555,6 +2559,12 @@ lubbock_fail0:
2555 2559
2556 return 0; 2560 return 0;
2557} 2561}
2562
2563static void pxa2xx_udc_shutdown(struct device *_dev)
2564{
2565 pullup_off();
2566}
2567
2558static int __exit pxa2xx_udc_remove(struct device *_dev) 2568static int __exit pxa2xx_udc_remove(struct device *_dev)
2559{ 2569{
2560 struct pxa2xx_udc *dev = dev_get_drvdata(_dev); 2570 struct pxa2xx_udc *dev = dev_get_drvdata(_dev);
@@ -2624,6 +2634,7 @@ static struct device_driver udc_driver = {
2624 .name = "pxa2xx-udc", 2634 .name = "pxa2xx-udc",
2625 .bus = &platform_bus_type, 2635 .bus = &platform_bus_type,
2626 .probe = pxa2xx_udc_probe, 2636 .probe = pxa2xx_udc_probe,
2637 .shutdown = pxa2xx_udc_shutdown,
2627 .remove = __exit_p(pxa2xx_udc_remove), 2638 .remove = __exit_p(pxa2xx_udc_remove),
2628 .suspend = pxa2xx_udc_suspend, 2639 .suspend = pxa2xx_udc_suspend,
2629 .resume = pxa2xx_udc_resume, 2640 .resume = pxa2xx_udc_resume,
diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h
index 1f3a7d999da7..d0bc396a85d5 100644
--- a/drivers/usb/gadget/pxa2xx_udc.h
+++ b/drivers/usb/gadget/pxa2xx_udc.h
@@ -177,23 +177,23 @@ struct pxa2xx_udc {
177 177
178static struct pxa2xx_udc *the_controller; 178static struct pxa2xx_udc *the_controller;
179 179
180/* one GPIO should be used to detect host disconnect */ 180/* one GPIO should be used to detect VBUS from the host */
181static inline int is_usb_connected(void) 181static inline int is_vbus_present(void)
182{ 182{
183 if (!the_controller->mach->udc_is_connected) 183 if (!the_controller->mach->udc_is_connected)
184 return 1; 184 return 1;
185 return the_controller->mach->udc_is_connected(); 185 return the_controller->mach->udc_is_connected();
186} 186}
187 187
188/* one GPIO should force the host to see this device (or not) */ 188/* one GPIO should control a D+ pullup, so host sees this device (or not) */
189static inline void make_usb_disappear(void) 189static inline void pullup_off(void)
190{ 190{
191 if (!the_controller->mach->udc_command) 191 if (!the_controller->mach->udc_command)
192 return; 192 return;
193 the_controller->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); 193 the_controller->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
194} 194}
195 195
196static inline void let_usb_appear(void) 196static inline void pullup_on(void)
197{ 197{
198 if (!the_controller->mach->udc_command) 198 if (!the_controller->mach->udc_command)
199 return; 199 return;
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 7457268d5f28..06b6eba925b5 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -41,6 +41,7 @@
41 41
42 42
43#undef RNDIS_PM 43#undef RNDIS_PM
44#undef RNDIS_WAKEUP
44#undef VERBOSE 45#undef VERBOSE
45 46
46#include "rndis.h" 47#include "rndis.h"
@@ -60,7 +61,7 @@
60 } while (0) 61 } while (0)
61static int rndis_debug = 0; 62static int rndis_debug = 0;
62 63
63module_param (rndis_debug, bool, 0); 64module_param (rndis_debug, int, 0);
64MODULE_PARM_DESC (rndis_debug, "enable debugging"); 65MODULE_PARM_DESC (rndis_debug, "enable debugging");
65 66
66#else 67#else
@@ -78,22 +79,103 @@ static rndis_params rndis_per_dev_params [RNDIS_MAX_CONFIGS];
78static const __le32 rndis_driver_version = __constant_cpu_to_le32 (1); 79static const __le32 rndis_driver_version = __constant_cpu_to_le32 (1);
79 80
80/* Function Prototypes */ 81/* Function Prototypes */
81static int rndis_init_response (int configNr, rndis_init_msg_type *buf);
82static int rndis_query_response (int configNr, rndis_query_msg_type *buf);
83static int rndis_set_response (int configNr, rndis_set_msg_type *buf);
84static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf);
85static int rndis_keepalive_response (int configNr,
86 rndis_keepalive_msg_type *buf);
87
88static rndis_resp_t *rndis_add_response (int configNr, u32 length); 82static rndis_resp_t *rndis_add_response (int configNr, u32 length);
89 83
90 84
85/* supported OIDs */
86static const u32 oid_supported_list [] =
87{
88 /* the general stuff */
89 OID_GEN_SUPPORTED_LIST,
90 OID_GEN_HARDWARE_STATUS,
91 OID_GEN_MEDIA_SUPPORTED,
92 OID_GEN_MEDIA_IN_USE,
93 OID_GEN_MAXIMUM_FRAME_SIZE,
94 OID_GEN_LINK_SPEED,
95 OID_GEN_TRANSMIT_BLOCK_SIZE,
96 OID_GEN_RECEIVE_BLOCK_SIZE,
97 OID_GEN_VENDOR_ID,
98 OID_GEN_VENDOR_DESCRIPTION,
99 OID_GEN_VENDOR_DRIVER_VERSION,
100 OID_GEN_CURRENT_PACKET_FILTER,
101 OID_GEN_MAXIMUM_TOTAL_SIZE,
102 OID_GEN_MEDIA_CONNECT_STATUS,
103 OID_GEN_PHYSICAL_MEDIUM,
104#if 0
105 OID_GEN_RNDIS_CONFIG_PARAMETER,
106#endif
107
108 /* the statistical stuff */
109 OID_GEN_XMIT_OK,
110 OID_GEN_RCV_OK,
111 OID_GEN_XMIT_ERROR,
112 OID_GEN_RCV_ERROR,
113 OID_GEN_RCV_NO_BUFFER,
114#ifdef RNDIS_OPTIONAL_STATS
115 OID_GEN_DIRECTED_BYTES_XMIT,
116 OID_GEN_DIRECTED_FRAMES_XMIT,
117 OID_GEN_MULTICAST_BYTES_XMIT,
118 OID_GEN_MULTICAST_FRAMES_XMIT,
119 OID_GEN_BROADCAST_BYTES_XMIT,
120 OID_GEN_BROADCAST_FRAMES_XMIT,
121 OID_GEN_DIRECTED_BYTES_RCV,
122 OID_GEN_DIRECTED_FRAMES_RCV,
123 OID_GEN_MULTICAST_BYTES_RCV,
124 OID_GEN_MULTICAST_FRAMES_RCV,
125 OID_GEN_BROADCAST_BYTES_RCV,
126 OID_GEN_BROADCAST_FRAMES_RCV,
127 OID_GEN_RCV_CRC_ERROR,
128 OID_GEN_TRANSMIT_QUEUE_LENGTH,
129#endif /* RNDIS_OPTIONAL_STATS */
130
131 /* mandatory 802.3 */
132 /* the general stuff */
133 OID_802_3_PERMANENT_ADDRESS,
134 OID_802_3_CURRENT_ADDRESS,
135 OID_802_3_MULTICAST_LIST,
136 OID_802_3_MAC_OPTIONS,
137 OID_802_3_MAXIMUM_LIST_SIZE,
138
139 /* the statistical stuff */
140 OID_802_3_RCV_ERROR_ALIGNMENT,
141 OID_802_3_XMIT_ONE_COLLISION,
142 OID_802_3_XMIT_MORE_COLLISIONS,
143#ifdef RNDIS_OPTIONAL_STATS
144 OID_802_3_XMIT_DEFERRED,
145 OID_802_3_XMIT_MAX_COLLISIONS,
146 OID_802_3_RCV_OVERRUN,
147 OID_802_3_XMIT_UNDERRUN,
148 OID_802_3_XMIT_HEARTBEAT_FAILURE,
149 OID_802_3_XMIT_TIMES_CRS_LOST,
150 OID_802_3_XMIT_LATE_COLLISIONS,
151#endif /* RNDIS_OPTIONAL_STATS */
152
153#ifdef RNDIS_PM
154 /* PM and wakeup are mandatory for USB: */
155
156 /* power management */
157 OID_PNP_CAPABILITIES,
158 OID_PNP_QUERY_POWER,
159 OID_PNP_SET_POWER,
160
161#ifdef RNDIS_WAKEUP
162 /* wake up host */
163 OID_PNP_ENABLE_WAKE_UP,
164 OID_PNP_ADD_WAKE_UP_PATTERN,
165 OID_PNP_REMOVE_WAKE_UP_PATTERN,
166#endif /* RNDIS_WAKEUP */
167#endif /* RNDIS_PM */
168};
169
170
91/* NDIS Functions */ 171/* NDIS Functions */
92static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r) 172static int
173gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
174 rndis_resp_t *r)
93{ 175{
94 int retval = -ENOTSUPP; 176 int retval = -ENOTSUPP;
95 u32 length = 0; 177 u32 length = 4; /* usually */
96 __le32 *tmp; 178 __le32 *outbuf;
97 int i, count; 179 int i, count;
98 rndis_query_cmplt_type *resp; 180 rndis_query_cmplt_type *resp;
99 181
@@ -101,7 +183,22 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
101 resp = (rndis_query_cmplt_type *) r->buf; 183 resp = (rndis_query_cmplt_type *) r->buf;
102 184
103 if (!resp) return -ENOMEM; 185 if (!resp) return -ENOMEM;
104 186
187 if (buf_len && rndis_debug > 1) {
188 DEBUG("query OID %08x value, len %d:\n", OID, buf_len);
189 for (i = 0; i < buf_len; i += 16) {
190 DEBUG ("%03d: %08x %08x %08x %08x\n", i,
191 le32_to_cpup((__le32 *)&buf[i]),
192 le32_to_cpup((__le32 *)&buf[i + 4]),
193 le32_to_cpup((__le32 *)&buf[i + 8]),
194 le32_to_cpup((__le32 *)&buf[i + 12]));
195 }
196 }
197
198 /* response goes here, right after the header */
199 outbuf = (__le32 *) &resp[1];
200 resp->InformationBufferOffset = __constant_cpu_to_le32 (16);
201
105 switch (OID) { 202 switch (OID) {
106 203
107 /* general oids (table 4-1) */ 204 /* general oids (table 4-1) */
@@ -111,42 +208,36 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
111 DEBUG ("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__); 208 DEBUG ("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__);
112 length = sizeof (oid_supported_list); 209 length = sizeof (oid_supported_list);
113 count = length / sizeof (u32); 210 count = length / sizeof (u32);
114 tmp = (__le32 *) ((u8 *)resp + 24);
115 for (i = 0; i < count; i++) 211 for (i = 0; i < count; i++)
116 tmp[i] = cpu_to_le32 (oid_supported_list[i]); 212 outbuf[i] = cpu_to_le32 (oid_supported_list[i]);
117 retval = 0; 213 retval = 0;
118 break; 214 break;
119 215
120 /* mandatory */ 216 /* mandatory */
121 case OID_GEN_HARDWARE_STATUS: 217 case OID_GEN_HARDWARE_STATUS:
122 DEBUG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__); 218 DEBUG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__);
123 length = 4;
124 /* Bogus question! 219 /* Bogus question!
125 * Hardware must be ready to receive high level protocols. 220 * Hardware must be ready to receive high level protocols.
126 * BTW: 221 * BTW:
127 * reddite ergo quae sunt Caesaris Caesari 222 * reddite ergo quae sunt Caesaris Caesari
128 * et quae sunt Dei Deo! 223 * et quae sunt Dei Deo!
129 */ 224 */
130 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 225 *outbuf = __constant_cpu_to_le32 (0);
131 retval = 0; 226 retval = 0;
132 break; 227 break;
133 228
134 /* mandatory */ 229 /* mandatory */
135 case OID_GEN_MEDIA_SUPPORTED: 230 case OID_GEN_MEDIA_SUPPORTED:
136 DEBUG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__); 231 DEBUG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__);
137 length = 4; 232 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
138 *((__le32 *) resp + 6) = cpu_to_le32 (
139 rndis_per_dev_params [configNr].medium);
140 retval = 0; 233 retval = 0;
141 break; 234 break;
142 235
143 /* mandatory */ 236 /* mandatory */
144 case OID_GEN_MEDIA_IN_USE: 237 case OID_GEN_MEDIA_IN_USE:
145 DEBUG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__); 238 DEBUG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__);
146 length = 4;
147 /* one medium, one transport... (maybe you do it better) */ 239 /* one medium, one transport... (maybe you do it better) */
148 *((__le32 *) resp + 6) = cpu_to_le32 ( 240 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
149 rndis_per_dev_params [configNr].medium);
150 retval = 0; 241 retval = 0;
151 break; 242 break;
152 243
@@ -154,25 +245,21 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
154 case OID_GEN_MAXIMUM_FRAME_SIZE: 245 case OID_GEN_MAXIMUM_FRAME_SIZE:
155 DEBUG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__); 246 DEBUG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__);
156 if (rndis_per_dev_params [configNr].dev) { 247 if (rndis_per_dev_params [configNr].dev) {
157 length = 4; 248 *outbuf = cpu_to_le32 (
158 *((__le32 *) resp + 6) = cpu_to_le32 (
159 rndis_per_dev_params [configNr].dev->mtu); 249 rndis_per_dev_params [configNr].dev->mtu);
160 retval = 0; 250 retval = 0;
161 } else {
162 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
163 retval = 0;
164 } 251 }
165 break; 252 break;
166 253
167 /* mandatory */ 254 /* mandatory */
168 case OID_GEN_LINK_SPEED: 255 case OID_GEN_LINK_SPEED:
169// DEBUG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__); 256 if (rndis_debug > 1)
170 length = 4; 257 DEBUG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__);
171 if (rndis_per_dev_params [configNr].media_state 258 if (rndis_per_dev_params [configNr].media_state
172 == NDIS_MEDIA_STATE_DISCONNECTED) 259 == NDIS_MEDIA_STATE_DISCONNECTED)
173 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 260 *outbuf = __constant_cpu_to_le32 (0);
174 else 261 else
175 *((__le32 *) resp + 6) = cpu_to_le32 ( 262 *outbuf = cpu_to_le32 (
176 rndis_per_dev_params [configNr].speed); 263 rndis_per_dev_params [configNr].speed);
177 retval = 0; 264 retval = 0;
178 break; 265 break;
@@ -181,8 +268,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
181 case OID_GEN_TRANSMIT_BLOCK_SIZE: 268 case OID_GEN_TRANSMIT_BLOCK_SIZE:
182 DEBUG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__); 269 DEBUG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__);
183 if (rndis_per_dev_params [configNr].dev) { 270 if (rndis_per_dev_params [configNr].dev) {
184 length = 4; 271 *outbuf = cpu_to_le32 (
185 *((__le32 *) resp + 6) = cpu_to_le32 (
186 rndis_per_dev_params [configNr].dev->mtu); 272 rndis_per_dev_params [configNr].dev->mtu);
187 retval = 0; 273 retval = 0;
188 } 274 }
@@ -192,8 +278,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
192 case OID_GEN_RECEIVE_BLOCK_SIZE: 278 case OID_GEN_RECEIVE_BLOCK_SIZE:
193 DEBUG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__); 279 DEBUG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__);
194 if (rndis_per_dev_params [configNr].dev) { 280 if (rndis_per_dev_params [configNr].dev) {
195 length = 4; 281 *outbuf = cpu_to_le32 (
196 *((__le32 *) resp + 6) = cpu_to_le32 (
197 rndis_per_dev_params [configNr].dev->mtu); 282 rndis_per_dev_params [configNr].dev->mtu);
198 retval = 0; 283 retval = 0;
199 } 284 }
@@ -202,8 +287,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
202 /* mandatory */ 287 /* mandatory */
203 case OID_GEN_VENDOR_ID: 288 case OID_GEN_VENDOR_ID:
204 DEBUG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__); 289 DEBUG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__);
205 length = 4; 290 *outbuf = cpu_to_le32 (
206 *((__le32 *) resp + 6) = cpu_to_le32 (
207 rndis_per_dev_params [configNr].vendorID); 291 rndis_per_dev_params [configNr].vendorID);
208 retval = 0; 292 retval = 0;
209 break; 293 break;
@@ -212,51 +296,44 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
212 case OID_GEN_VENDOR_DESCRIPTION: 296 case OID_GEN_VENDOR_DESCRIPTION:
213 DEBUG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__); 297 DEBUG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__);
214 length = strlen (rndis_per_dev_params [configNr].vendorDescr); 298 length = strlen (rndis_per_dev_params [configNr].vendorDescr);
215 memcpy ((u8 *) resp + 24, 299 memcpy (outbuf,
216 rndis_per_dev_params [configNr].vendorDescr, length); 300 rndis_per_dev_params [configNr].vendorDescr, length);
217 retval = 0; 301 retval = 0;
218 break; 302 break;
219 303
220 case OID_GEN_VENDOR_DRIVER_VERSION: 304 case OID_GEN_VENDOR_DRIVER_VERSION:
221 DEBUG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__); 305 DEBUG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__);
222 length = 4;
223 /* Created as LE */ 306 /* Created as LE */
224 *((__le32 *) resp + 6) = rndis_driver_version; 307 *outbuf = rndis_driver_version;
225 retval = 0; 308 retval = 0;
226 break; 309 break;
227 310
228 /* mandatory */ 311 /* mandatory */
229 case OID_GEN_CURRENT_PACKET_FILTER: 312 case OID_GEN_CURRENT_PACKET_FILTER:
230 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__); 313 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__);
231 length = 4; 314 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter);
232 *((__le32 *) resp + 6) = cpu_to_le32 (
233 rndis_per_dev_params[configNr].filter);
234 retval = 0; 315 retval = 0;
235 break; 316 break;
236 317
237 /* mandatory */ 318 /* mandatory */
238 case OID_GEN_MAXIMUM_TOTAL_SIZE: 319 case OID_GEN_MAXIMUM_TOTAL_SIZE:
239 DEBUG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__); 320 DEBUG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__);
240 length = 4; 321 *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
241 *((__le32 *) resp + 6) = __constant_cpu_to_le32(
242 RNDIS_MAX_TOTAL_SIZE);
243 retval = 0; 322 retval = 0;
244 break; 323 break;
245 324
246 /* mandatory */ 325 /* mandatory */
247 case OID_GEN_MEDIA_CONNECT_STATUS: 326 case OID_GEN_MEDIA_CONNECT_STATUS:
248 DEBUG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__); 327 if (rndis_debug > 1)
249 length = 4; 328 DEBUG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__);
250 *((__le32 *) resp + 6) = cpu_to_le32 ( 329 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
251 rndis_per_dev_params [configNr]
252 .media_state); 330 .media_state);
253 retval = 0; 331 retval = 0;
254 break; 332 break;
255 333
256 case OID_GEN_PHYSICAL_MEDIUM: 334 case OID_GEN_PHYSICAL_MEDIUM:
257 DEBUG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__); 335 DEBUG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__);
258 length = 4; 336 *outbuf = __constant_cpu_to_le32 (0);
259 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
260 retval = 0; 337 retval = 0;
261 break; 338 break;
262 339
@@ -266,8 +343,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
266 */ 343 */
267 case OID_GEN_MAC_OPTIONS: /* from WinME */ 344 case OID_GEN_MAC_OPTIONS: /* from WinME */
268 DEBUG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__); 345 DEBUG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__);
269 length = 4; 346 *outbuf = __constant_cpu_to_le32(
270 *((__le32 *) resp + 6) = __constant_cpu_to_le32(
271 NDIS_MAC_OPTION_RECEIVE_SERIALIZED 347 NDIS_MAC_OPTION_RECEIVE_SERIALIZED
272 | NDIS_MAC_OPTION_FULL_DUPLEX); 348 | NDIS_MAC_OPTION_FULL_DUPLEX);
273 retval = 0; 349 retval = 0;
@@ -277,62 +353,49 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
277 353
278 /* mandatory */ 354 /* mandatory */
279 case OID_GEN_XMIT_OK: 355 case OID_GEN_XMIT_OK:
280 DEBUG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__); 356 if (rndis_debug > 1)
357 DEBUG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__);
281 if (rndis_per_dev_params [configNr].stats) { 358 if (rndis_per_dev_params [configNr].stats) {
282 length = 4; 359 *outbuf = cpu_to_le32 (
283 *((__le32 *) resp + 6) = cpu_to_le32 (
284 rndis_per_dev_params [configNr].stats->tx_packets - 360 rndis_per_dev_params [configNr].stats->tx_packets -
285 rndis_per_dev_params [configNr].stats->tx_errors - 361 rndis_per_dev_params [configNr].stats->tx_errors -
286 rndis_per_dev_params [configNr].stats->tx_dropped); 362 rndis_per_dev_params [configNr].stats->tx_dropped);
287 retval = 0; 363 retval = 0;
288 } else {
289 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
290 retval = 0;
291 } 364 }
292 break; 365 break;
293 366
294 /* mandatory */ 367 /* mandatory */
295 case OID_GEN_RCV_OK: 368 case OID_GEN_RCV_OK:
296 DEBUG("%s: OID_GEN_RCV_OK\n", __FUNCTION__); 369 if (rndis_debug > 1)
370 DEBUG("%s: OID_GEN_RCV_OK\n", __FUNCTION__);
297 if (rndis_per_dev_params [configNr].stats) { 371 if (rndis_per_dev_params [configNr].stats) {
298 length = 4; 372 *outbuf = cpu_to_le32 (
299 *((__le32 *) resp + 6) = cpu_to_le32 (
300 rndis_per_dev_params [configNr].stats->rx_packets - 373 rndis_per_dev_params [configNr].stats->rx_packets -
301 rndis_per_dev_params [configNr].stats->rx_errors - 374 rndis_per_dev_params [configNr].stats->rx_errors -
302 rndis_per_dev_params [configNr].stats->rx_dropped); 375 rndis_per_dev_params [configNr].stats->rx_dropped);
303 retval = 0; 376 retval = 0;
304 } else {
305 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
306 retval = 0;
307 } 377 }
308 break; 378 break;
309 379
310 /* mandatory */ 380 /* mandatory */
311 case OID_GEN_XMIT_ERROR: 381 case OID_GEN_XMIT_ERROR:
312 DEBUG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__); 382 if (rndis_debug > 1)
383 DEBUG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__);
313 if (rndis_per_dev_params [configNr].stats) { 384 if (rndis_per_dev_params [configNr].stats) {
314 length = 4; 385 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
315 *((__le32 *) resp + 6) = cpu_to_le32 (
316 rndis_per_dev_params [configNr]
317 .stats->tx_errors); 386 .stats->tx_errors);
318 retval = 0; 387 retval = 0;
319 } else {
320 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
321 retval = 0;
322 } 388 }
323 break; 389 break;
324 390
325 /* mandatory */ 391 /* mandatory */
326 case OID_GEN_RCV_ERROR: 392 case OID_GEN_RCV_ERROR:
327 DEBUG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__); 393 if (rndis_debug > 1)
394 DEBUG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__);
328 if (rndis_per_dev_params [configNr].stats) { 395 if (rndis_per_dev_params [configNr].stats) {
329 *((__le32 *) resp + 6) = cpu_to_le32 ( 396 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
330 rndis_per_dev_params [configNr]
331 .stats->rx_errors); 397 .stats->rx_errors);
332 retval = 0; 398 retval = 0;
333 } else {
334 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
335 retval = 0;
336 } 399 }
337 break; 400 break;
338 401
@@ -340,13 +403,9 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
340 case OID_GEN_RCV_NO_BUFFER: 403 case OID_GEN_RCV_NO_BUFFER:
341 DEBUG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__); 404 DEBUG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__);
342 if (rndis_per_dev_params [configNr].stats) { 405 if (rndis_per_dev_params [configNr].stats) {
343 *((__le32 *) resp + 6) = cpu_to_le32 ( 406 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
344 rndis_per_dev_params [configNr]
345 .stats->rx_dropped); 407 .stats->rx_dropped);
346 retval = 0; 408 retval = 0;
347 } else {
348 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
349 retval = 0;
350 } 409 }
351 break; 410 break;
352 411
@@ -359,8 +418,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
359 * divided by weight of Alpha Centauri 418 * divided by weight of Alpha Centauri
360 */ 419 */
361 if (rndis_per_dev_params [configNr].stats) { 420 if (rndis_per_dev_params [configNr].stats) {
362 length = 4; 421 *outbuf = cpu_to_le32 (
363 *((__le32 *) resp + 6) = cpu_to_le32 (
364 (rndis_per_dev_params [configNr] 422 (rndis_per_dev_params [configNr]
365 .stats->tx_packets - 423 .stats->tx_packets -
366 rndis_per_dev_params [configNr] 424 rndis_per_dev_params [configNr]
@@ -369,9 +427,6 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
369 .stats->tx_dropped) 427 .stats->tx_dropped)
370 * 123); 428 * 123);
371 retval = 0; 429 retval = 0;
372 } else {
373 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
374 retval = 0;
375 } 430 }
376 break; 431 break;
377 432
@@ -379,8 +434,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
379 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__); 434 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__);
380 /* dito */ 435 /* dito */
381 if (rndis_per_dev_params [configNr].stats) { 436 if (rndis_per_dev_params [configNr].stats) {
382 length = 4; 437 *outbuf = cpu_to_le32 (
383 *((__le32 *) resp + 6) = cpu_to_le32 (
384 (rndis_per_dev_params [configNr] 438 (rndis_per_dev_params [configNr]
385 .stats->tx_packets - 439 .stats->tx_packets -
386 rndis_per_dev_params [configNr] 440 rndis_per_dev_params [configNr]
@@ -389,144 +443,105 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
389 .stats->tx_dropped) 443 .stats->tx_dropped)
390 / 123); 444 / 123);
391 retval = 0; 445 retval = 0;
392 } else {
393 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
394 retval = 0;
395 } 446 }
396 break; 447 break;
397 448
398 case OID_GEN_MULTICAST_BYTES_XMIT: 449 case OID_GEN_MULTICAST_BYTES_XMIT:
399 DEBUG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__); 450 DEBUG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__);
400 if (rndis_per_dev_params [configNr].stats) { 451 if (rndis_per_dev_params [configNr].stats) {
401 *((__le32 *) resp + 6) = cpu_to_le32 ( 452 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
402 rndis_per_dev_params [configNr]
403 .stats->multicast*1234); 453 .stats->multicast*1234);
404 retval = 0; 454 retval = 0;
405 } else {
406 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
407 retval = 0;
408 } 455 }
409 break; 456 break;
410 457
411 case OID_GEN_MULTICAST_FRAMES_XMIT: 458 case OID_GEN_MULTICAST_FRAMES_XMIT:
412 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__); 459 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__);
413 if (rndis_per_dev_params [configNr].stats) { 460 if (rndis_per_dev_params [configNr].stats) {
414 *((__le32 *) resp + 6) = cpu_to_le32 ( 461 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
415 rndis_per_dev_params [configNr]
416 .stats->multicast); 462 .stats->multicast);
417 retval = 0; 463 retval = 0;
418 } else {
419 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
420 retval = 0;
421 } 464 }
422 break; 465 break;
423 466
424 case OID_GEN_BROADCAST_BYTES_XMIT: 467 case OID_GEN_BROADCAST_BYTES_XMIT:
425 DEBUG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__); 468 DEBUG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__);
426 if (rndis_per_dev_params [configNr].stats) { 469 if (rndis_per_dev_params [configNr].stats) {
427 *((__le32 *) resp + 6) = cpu_to_le32 ( 470 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
428 rndis_per_dev_params [configNr]
429 .stats->tx_packets/42*255); 471 .stats->tx_packets/42*255);
430 retval = 0; 472 retval = 0;
431 } else {
432 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
433 retval = 0;
434 } 473 }
435 break; 474 break;
436 475
437 case OID_GEN_BROADCAST_FRAMES_XMIT: 476 case OID_GEN_BROADCAST_FRAMES_XMIT:
438 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__); 477 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__);
439 if (rndis_per_dev_params [configNr].stats) { 478 if (rndis_per_dev_params [configNr].stats) {
440 *((__le32 *) resp + 6) = cpu_to_le32 ( 479 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
441 rndis_per_dev_params [configNr]
442 .stats->tx_packets/42); 480 .stats->tx_packets/42);
443 retval = 0; 481 retval = 0;
444 } else {
445 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
446 retval = 0;
447 } 482 }
448 break; 483 break;
449 484
450 case OID_GEN_DIRECTED_BYTES_RCV: 485 case OID_GEN_DIRECTED_BYTES_RCV:
451 DEBUG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__); 486 DEBUG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__);
452 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 487 *outbuf = __constant_cpu_to_le32 (0);
453 retval = 0; 488 retval = 0;
454 break; 489 break;
455 490
456 case OID_GEN_DIRECTED_FRAMES_RCV: 491 case OID_GEN_DIRECTED_FRAMES_RCV:
457 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__); 492 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__);
458 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 493 *outbuf = __constant_cpu_to_le32 (0);
459 retval = 0; 494 retval = 0;
460 break; 495 break;
461 496
462 case OID_GEN_MULTICAST_BYTES_RCV: 497 case OID_GEN_MULTICAST_BYTES_RCV:
463 DEBUG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__); 498 DEBUG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__);
464 if (rndis_per_dev_params [configNr].stats) { 499 if (rndis_per_dev_params [configNr].stats) {
465 *((__le32 *) resp + 6) = cpu_to_le32 ( 500 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
466 rndis_per_dev_params [configNr]
467 .stats->multicast * 1111); 501 .stats->multicast * 1111);
468 retval = 0; 502 retval = 0;
469 } else {
470 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
471 retval = 0;
472 } 503 }
473 break; 504 break;
474 505
475 case OID_GEN_MULTICAST_FRAMES_RCV: 506 case OID_GEN_MULTICAST_FRAMES_RCV:
476 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__); 507 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__);
477 if (rndis_per_dev_params [configNr].stats) { 508 if (rndis_per_dev_params [configNr].stats) {
478 *((__le32 *) resp + 6) = cpu_to_le32 ( 509 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
479 rndis_per_dev_params [configNr]
480 .stats->multicast); 510 .stats->multicast);
481 retval = 0; 511 retval = 0;
482 } else {
483 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
484 retval = 0;
485 } 512 }
486 break; 513 break;
487 514
488 case OID_GEN_BROADCAST_BYTES_RCV: 515 case OID_GEN_BROADCAST_BYTES_RCV:
489 DEBUG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__); 516 DEBUG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__);
490 if (rndis_per_dev_params [configNr].stats) { 517 if (rndis_per_dev_params [configNr].stats) {
491 *((__le32 *) resp + 6) = cpu_to_le32 ( 518 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
492 rndis_per_dev_params [configNr]
493 .stats->rx_packets/42*255); 519 .stats->rx_packets/42*255);
494 retval = 0; 520 retval = 0;
495 } else {
496 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
497 retval = 0;
498 } 521 }
499 break; 522 break;
500 523
501 case OID_GEN_BROADCAST_FRAMES_RCV: 524 case OID_GEN_BROADCAST_FRAMES_RCV:
502 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__); 525 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__);
503 if (rndis_per_dev_params [configNr].stats) { 526 if (rndis_per_dev_params [configNr].stats) {
504 *((__le32 *) resp + 6) = cpu_to_le32 ( 527 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
505 rndis_per_dev_params [configNr]
506 .stats->rx_packets/42); 528 .stats->rx_packets/42);
507 retval = 0; 529 retval = 0;
508 } else {
509 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
510 retval = 0;
511 } 530 }
512 break; 531 break;
513 532
514 case OID_GEN_RCV_CRC_ERROR: 533 case OID_GEN_RCV_CRC_ERROR:
515 DEBUG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__); 534 DEBUG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__);
516 if (rndis_per_dev_params [configNr].stats) { 535 if (rndis_per_dev_params [configNr].stats) {
517 *((__le32 *) resp + 6) = cpu_to_le32 ( 536 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
518 rndis_per_dev_params [configNr]
519 .stats->rx_crc_errors); 537 .stats->rx_crc_errors);
520 retval = 0; 538 retval = 0;
521 } else {
522 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
523 retval = 0;
524 } 539 }
525 break; 540 break;
526 541
527 case OID_GEN_TRANSMIT_QUEUE_LENGTH: 542 case OID_GEN_TRANSMIT_QUEUE_LENGTH:
528 DEBUG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__); 543 DEBUG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__);
529 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 544 *outbuf = __constant_cpu_to_le32 (0);
530 retval = 0; 545 retval = 0;
531 break; 546 break;
532#endif /* RNDIS_OPTIONAL_STATS */ 547#endif /* RNDIS_OPTIONAL_STATS */
@@ -538,13 +553,10 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
538 DEBUG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__); 553 DEBUG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__);
539 if (rndis_per_dev_params [configNr].dev) { 554 if (rndis_per_dev_params [configNr].dev) {
540 length = ETH_ALEN; 555 length = ETH_ALEN;
541 memcpy ((u8 *) resp + 24, 556 memcpy (outbuf,
542 rndis_per_dev_params [configNr].host_mac, 557 rndis_per_dev_params [configNr].host_mac,
543 length); 558 length);
544 retval = 0; 559 retval = 0;
545 } else {
546 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
547 retval = 0;
548 } 560 }
549 break; 561 break;
550 562
@@ -553,7 +565,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
553 DEBUG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__); 565 DEBUG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__);
554 if (rndis_per_dev_params [configNr].dev) { 566 if (rndis_per_dev_params [configNr].dev) {
555 length = ETH_ALEN; 567 length = ETH_ALEN;
556 memcpy ((u8 *) resp + 24, 568 memcpy (outbuf,
557 rndis_per_dev_params [configNr].host_mac, 569 rndis_per_dev_params [configNr].host_mac,
558 length); 570 length);
559 retval = 0; 571 retval = 0;
@@ -563,18 +575,16 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
563 /* mandatory */ 575 /* mandatory */
564 case OID_802_3_MULTICAST_LIST: 576 case OID_802_3_MULTICAST_LIST:
565 DEBUG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__); 577 DEBUG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__);
566 length = 4;
567 /* Multicast base address only */ 578 /* Multicast base address only */
568 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0xE0000000); 579 *outbuf = __constant_cpu_to_le32 (0xE0000000);
569 retval = 0; 580 retval = 0;
570 break; 581 break;
571 582
572 /* mandatory */ 583 /* mandatory */
573 case OID_802_3_MAXIMUM_LIST_SIZE: 584 case OID_802_3_MAXIMUM_LIST_SIZE:
574 DEBUG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__); 585 DEBUG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__);
575 length = 4;
576 /* Multicast base address only */ 586 /* Multicast base address only */
577 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (1); 587 *outbuf = __constant_cpu_to_le32 (1);
578 retval = 0; 588 retval = 0;
579 break; 589 break;
580 590
@@ -587,11 +597,8 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
587 /* mandatory */ 597 /* mandatory */
588 case OID_802_3_RCV_ERROR_ALIGNMENT: 598 case OID_802_3_RCV_ERROR_ALIGNMENT:
589 DEBUG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__); 599 DEBUG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__);
590 if (rndis_per_dev_params [configNr].stats) 600 if (rndis_per_dev_params [configNr].stats) {
591 { 601 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
592 length = 4;
593 *((__le32 *) resp + 6) = cpu_to_le32 (
594 rndis_per_dev_params [configNr]
595 .stats->rx_frame_errors); 602 .stats->rx_frame_errors);
596 retval = 0; 603 retval = 0;
597 } 604 }
@@ -600,16 +607,14 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
600 /* mandatory */ 607 /* mandatory */
601 case OID_802_3_XMIT_ONE_COLLISION: 608 case OID_802_3_XMIT_ONE_COLLISION:
602 DEBUG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__); 609 DEBUG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__);
603 length = 4; 610 *outbuf = __constant_cpu_to_le32 (0);
604 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
605 retval = 0; 611 retval = 0;
606 break; 612 break;
607 613
608 /* mandatory */ 614 /* mandatory */
609 case OID_802_3_XMIT_MORE_COLLISIONS: 615 case OID_802_3_XMIT_MORE_COLLISIONS:
610 DEBUG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__); 616 DEBUG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__);
611 length = 4; 617 *outbuf = __constant_cpu_to_le32 (0);
612 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
613 retval = 0; 618 retval = 0;
614 break; 619 break;
615 620
@@ -655,27 +660,18 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
655 case OID_PNP_CAPABILITIES: 660 case OID_PNP_CAPABILITIES:
656 DEBUG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__); 661 DEBUG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__);
657 662
658 /* just PM, and remote wakeup on link status change 663 /* for now, no wakeup capabilities */
659 * (not magic packet or pattern match)
660 */
661 length = sizeof (struct NDIS_PNP_CAPABILITIES); 664 length = sizeof (struct NDIS_PNP_CAPABILITIES);
662 memset (resp, 0, length); 665 memset(outbuf, 0, length);
663 {
664 struct NDIS_PNP_CAPABILITIES *caps = (void *) resp;
665
666 caps->Flags = NDIS_DEVICE_WAKE_UP_ENABLE;
667 caps->WakeUpCapabilities.MinLinkChangeWakeUp
668 = NdisDeviceStateD3;
669
670 /* FIXME then use usb_gadget_wakeup(), and
671 * set USB_CONFIG_ATT_WAKEUP in config desc
672 */
673 }
674 retval = 0; 666 retval = 0;
675 break; 667 break;
676 case OID_PNP_QUERY_POWER: 668 case OID_PNP_QUERY_POWER:
677 DEBUG("%s: OID_PNP_QUERY_POWER\n", __FUNCTION__); 669 DEBUG("%s: OID_PNP_QUERY_POWER D%d\n", __FUNCTION__,
678 /* sure, handle any power state that maps to USB suspend */ 670 le32_to_cpup((__le32 *) buf) - 1);
671 /* only suspend is a real power state, and
672 * it can't be entered by OID_PNP_SET_POWER...
673 */
674 length = 0;
679 retval = 0; 675 retval = 0;
680 break; 676 break;
681#endif 677#endif
@@ -684,11 +680,12 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
684 printk (KERN_WARNING "%s: query unknown OID 0x%08X\n", 680 printk (KERN_WARNING "%s: query unknown OID 0x%08X\n",
685 __FUNCTION__, OID); 681 __FUNCTION__, OID);
686 } 682 }
683 if (retval < 0)
684 length = 0;
687 685
688 resp->InformationBufferOffset = __constant_cpu_to_le32 (16);
689 resp->InformationBufferLength = cpu_to_le32 (length); 686 resp->InformationBufferLength = cpu_to_le32 (length);
690 resp->MessageLength = cpu_to_le32 (24 + length); 687 r->length = length + sizeof *resp;
691 r->length = 24 + length; 688 resp->MessageLength = cpu_to_le32 (r->length);
692 return retval; 689 return retval;
693} 690}
694 691
@@ -705,45 +702,40 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
705 if (!resp) 702 if (!resp)
706 return -ENOMEM; 703 return -ENOMEM;
707 704
708 DEBUG("set OID %08x value, len %d:\n", OID, buf_len); 705 if (buf_len && rndis_debug > 1) {
709 for (i = 0; i < buf_len; i += 16) { 706 DEBUG("set OID %08x value, len %d:\n", OID, buf_len);
710 DEBUG ("%03d: " 707 for (i = 0; i < buf_len; i += 16) {
711 " %02x %02x %02x %02x" 708 DEBUG ("%03d: %08x %08x %08x %08x\n", i,
712 " %02x %02x %02x %02x" 709 le32_to_cpup((__le32 *)&buf[i]),
713 " %02x %02x %02x %02x" 710 le32_to_cpup((__le32 *)&buf[i + 4]),
714 " %02x %02x %02x %02x" 711 le32_to_cpup((__le32 *)&buf[i + 8]),
715 "\n", 712 le32_to_cpup((__le32 *)&buf[i + 12]));
716 i, 713 }
717 buf[i], buf [i+1],
718 buf[i+2], buf[i+3],
719 buf[i+4], buf [i+5],
720 buf[i+6], buf[i+7],
721 buf[i+8], buf [i+9],
722 buf[i+10], buf[i+11],
723 buf[i+12], buf [i+13],
724 buf[i+14], buf[i+15]);
725 } 714 }
726 715
716 params = &rndis_per_dev_params [configNr];
727 switch (OID) { 717 switch (OID) {
728 case OID_GEN_CURRENT_PACKET_FILTER: 718 case OID_GEN_CURRENT_PACKET_FILTER:
729 params = &rndis_per_dev_params [configNr];
730 retval = 0;
731 719
732 /* FIXME use these NDIS_PACKET_TYPE_* bitflags to 720 /* these NDIS_PACKET_TYPE_* bitflags are shared with
733 * set the cdc_filter; it's not RNDIS-specific 721 * cdc_filter; it's not RNDIS-specific
734 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in: 722 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in:
735 * PROMISCUOUS, DIRECTED, 723 * PROMISCUOUS, DIRECTED,
736 * MULTICAST, ALL_MULTICAST, BROADCAST 724 * MULTICAST, ALL_MULTICAST, BROADCAST
737 */ 725 */
738 params->filter = le32_to_cpup((__le32 *)buf); 726 *params->filter = (u16) le32_to_cpup((__le32 *)buf);
739 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n", 727 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n",
740 __FUNCTION__, params->filter); 728 __FUNCTION__, *params->filter);
741 729
742 /* this call has a significant side effect: it's 730 /* this call has a significant side effect: it's
743 * what makes the packet flow start and stop, like 731 * what makes the packet flow start and stop, like
744 * activating the CDC Ethernet altsetting. 732 * activating the CDC Ethernet altsetting.
745 */ 733 */
746 if (params->filter) { 734#ifdef RNDIS_PM
735update_linkstate:
736#endif
737 retval = 0;
738 if (*params->filter) {
747 params->state = RNDIS_DATA_INITIALIZED; 739 params->state = RNDIS_DATA_INITIALIZED;
748 netif_carrier_on(params->dev); 740 netif_carrier_on(params->dev);
749 if (netif_running(params->dev)) 741 if (netif_running(params->dev))
@@ -776,21 +768,34 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
776 768
777#ifdef RNDIS_PM 769#ifdef RNDIS_PM
778 case OID_PNP_SET_POWER: 770 case OID_PNP_SET_POWER:
779 DEBUG ("OID_PNP_SET_POWER\n"); 771 /* The only real power state is USB suspend, and RNDIS requests
780 /* sure, handle any power state that maps to USB suspend */ 772 * can't enter it; this one isn't really about power. After
781 retval = 0; 773 * resuming, Windows forces a reset, and then SET_POWER D0.
782 break; 774 * FIXME ... then things go batty; Windows wedges itself.
783 775 */
784 case OID_PNP_ENABLE_WAKE_UP: 776 i = le32_to_cpup((__force __le32 *)buf);
785 /* always-connected ... */ 777 DEBUG("%s: OID_PNP_SET_POWER D%d\n", __FUNCTION__, i - 1);
786 DEBUG ("OID_PNP_ENABLE_WAKE_UP\n"); 778 switch (i) {
787 retval = 0; 779 case NdisDeviceStateD0:
780 *params->filter = params->saved_filter;
781 goto update_linkstate;
782 case NdisDeviceStateD3:
783 case NdisDeviceStateD2:
784 case NdisDeviceStateD1:
785 params->saved_filter = *params->filter;
786 retval = 0;
787 break;
788 }
788 break; 789 break;
789 790
790 // no PM resume patterns supported (specified where?) 791#ifdef RNDIS_WAKEUP
791 // so OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN always fails 792 // no wakeup support advertised, so wakeup OIDs always fail:
793 // - OID_PNP_ENABLE_WAKE_UP
794 // - OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN
792#endif 795#endif
793 796
797#endif /* RNDIS_PM */
798
794 default: 799 default:
795 printk (KERN_WARNING "%s: set unknown OID 0x%08X, size %d\n", 800 printk (KERN_WARNING "%s: set unknown OID 0x%08X, size %d\n",
796 __FUNCTION__, OID, buf_len); 801 __FUNCTION__, OID, buf_len);
@@ -811,13 +816,10 @@ static int rndis_init_response (int configNr, rndis_init_msg_type *buf)
811 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP; 816 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP;
812 817
813 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type)); 818 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type));
814 819 if (!r)
815 if (!r) return -ENOMEM; 820 return -ENOMEM;
816
817 resp = (rndis_init_cmplt_type *) r->buf; 821 resp = (rndis_init_cmplt_type *) r->buf;
818 822
819 if (!resp) return -ENOMEM;
820
821 resp->MessageType = __constant_cpu_to_le32 ( 823 resp->MessageType = __constant_cpu_to_le32 (
822 REMOTE_NDIS_INITIALIZE_CMPLT); 824 REMOTE_NDIS_INITIALIZE_CMPLT);
823 resp->MessageLength = __constant_cpu_to_le32 (52); 825 resp->MessageLength = __constant_cpu_to_le32 (52);
@@ -857,20 +859,22 @@ static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
857 * oid_supported_list is the largest answer 859 * oid_supported_list is the largest answer
858 */ 860 */
859 r = rndis_add_response (configNr, sizeof (oid_supported_list)); 861 r = rndis_add_response (configNr, sizeof (oid_supported_list));
860 862 if (!r)
861 if (!r) return -ENOMEM; 863 return -ENOMEM;
862 resp = (rndis_query_cmplt_type *) r->buf; 864 resp = (rndis_query_cmplt_type *) r->buf;
863 865
864 if (!resp) return -ENOMEM;
865
866 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT); 866 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT);
867 resp->MessageLength = __constant_cpu_to_le32 (24);
868 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 867 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
869 868
870 if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID), r)) { 869 if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID),
870 le32_to_cpu(buf->InformationBufferOffset)
871 + 8 + (u8 *) buf,
872 le32_to_cpu(buf->InformationBufferLength),
873 r)) {
871 /* OID not supported */ 874 /* OID not supported */
872 resp->Status = __constant_cpu_to_le32 ( 875 resp->Status = __constant_cpu_to_le32 (
873 RNDIS_STATUS_NOT_SUPPORTED); 876 RNDIS_STATUS_NOT_SUPPORTED);
877 resp->MessageLength = __constant_cpu_to_le32 (sizeof *resp);
874 resp->InformationBufferLength = __constant_cpu_to_le32 (0); 878 resp->InformationBufferLength = __constant_cpu_to_le32 (0);
875 resp->InformationBufferOffset = __constant_cpu_to_le32 (0); 879 resp->InformationBufferOffset = __constant_cpu_to_le32 (0);
876 } else 880 } else
@@ -889,10 +893,9 @@ static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
889 rndis_resp_t *r; 893 rndis_resp_t *r;
890 894
891 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type)); 895 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type));
892 896 if (!r)
893 if (!r) return -ENOMEM; 897 return -ENOMEM;
894 resp = (rndis_set_cmplt_type *) r->buf; 898 resp = (rndis_set_cmplt_type *) r->buf;
895 if (!resp) return -ENOMEM;
896 899
897 BufLength = le32_to_cpu (buf->InformationBufferLength); 900 BufLength = le32_to_cpu (buf->InformationBufferLength);
898 BufOffset = le32_to_cpu (buf->InformationBufferOffset); 901 BufOffset = le32_to_cpu (buf->InformationBufferOffset);
@@ -930,10 +933,9 @@ static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf)
930 rndis_resp_t *r; 933 rndis_resp_t *r;
931 934
932 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type)); 935 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type));
933 936 if (!r)
934 if (!r) return -ENOMEM; 937 return -ENOMEM;
935 resp = (rndis_reset_cmplt_type *) r->buf; 938 resp = (rndis_reset_cmplt_type *) r->buf;
936 if (!resp) return -ENOMEM;
937 939
938 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT); 940 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT);
939 resp->MessageLength = __constant_cpu_to_le32 (16); 941 resp->MessageLength = __constant_cpu_to_le32 (16);
@@ -957,8 +959,9 @@ static int rndis_keepalive_response (int configNr,
957 /* host "should" check only in RNDIS_DATA_INITIALIZED state */ 959 /* host "should" check only in RNDIS_DATA_INITIALIZED state */
958 960
959 r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type)); 961 r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type));
962 if (!r)
963 return -ENOMEM;
960 resp = (rndis_keepalive_cmplt_type *) r->buf; 964 resp = (rndis_keepalive_cmplt_type *) r->buf;
961 if (!resp) return -ENOMEM;
962 965
963 resp->MessageType = __constant_cpu_to_le32 ( 966 resp->MessageType = __constant_cpu_to_le32 (
964 REMOTE_NDIS_KEEPALIVE_CMPLT); 967 REMOTE_NDIS_KEEPALIVE_CMPLT);
@@ -987,10 +990,9 @@ static int rndis_indicate_status_msg (int configNr, u32 status)
987 990
988 r = rndis_add_response (configNr, 991 r = rndis_add_response (configNr,
989 sizeof (rndis_indicate_status_msg_type)); 992 sizeof (rndis_indicate_status_msg_type));
990 if (!r) return -ENOMEM; 993 if (!r)
991 994 return -ENOMEM;
992 resp = (rndis_indicate_status_msg_type *) r->buf; 995 resp = (rndis_indicate_status_msg_type *) r->buf;
993 if (!resp) return -ENOMEM;
994 996
995 resp->MessageType = __constant_cpu_to_le32 ( 997 resp->MessageType = __constant_cpu_to_le32 (
996 REMOTE_NDIS_INDICATE_STATUS_MSG); 998 REMOTE_NDIS_INDICATE_STATUS_MSG);
@@ -1021,6 +1023,21 @@ int rndis_signal_disconnect (int configNr)
1021 RNDIS_STATUS_MEDIA_DISCONNECT); 1023 RNDIS_STATUS_MEDIA_DISCONNECT);
1022} 1024}
1023 1025
1026void rndis_uninit (int configNr)
1027{
1028 u8 *buf;
1029 u32 length;
1030
1031 if (configNr >= RNDIS_MAX_CONFIGS)
1032 return;
1033 rndis_per_dev_params [configNr].used = 0;
1034 rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED;
1035
1036 /* drain the response queue */
1037 while ((buf = rndis_get_next_response(configNr, &length)))
1038 rndis_free_response(configNr, buf);
1039}
1040
1024void rndis_set_host_mac (int configNr, const u8 *addr) 1041void rndis_set_host_mac (int configNr, const u8 *addr)
1025{ 1042{
1026 rndis_per_dev_params [configNr].host_mac = addr; 1043 rndis_per_dev_params [configNr].host_mac = addr;
@@ -1046,9 +1063,13 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1046 return -ENOTSUPP; 1063 return -ENOTSUPP;
1047 params = &rndis_per_dev_params [configNr]; 1064 params = &rndis_per_dev_params [configNr];
1048 1065
1066 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
1067 * rx/tx statistics and link status, in addition to KEEPALIVE traffic
1068 * and normal HC level polling to see if there's any IN traffic.
1069 */
1070
1049 /* For USB: responses may take up to 10 seconds */ 1071 /* For USB: responses may take up to 10 seconds */
1050 switch (MsgType) 1072 switch (MsgType) {
1051 {
1052 case REMOTE_NDIS_INITIALIZE_MSG: 1073 case REMOTE_NDIS_INITIALIZE_MSG:
1053 DEBUG("%s: REMOTE_NDIS_INITIALIZE_MSG\n", 1074 DEBUG("%s: REMOTE_NDIS_INITIALIZE_MSG\n",
1054 __FUNCTION__ ); 1075 __FUNCTION__ );
@@ -1082,10 +1103,9 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1082 1103
1083 case REMOTE_NDIS_KEEPALIVE_MSG: 1104 case REMOTE_NDIS_KEEPALIVE_MSG:
1084 /* For USB: host does this every 5 seconds */ 1105 /* For USB: host does this every 5 seconds */
1085#ifdef VERBOSE 1106 if (rndis_debug > 1)
1086 DEBUG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", 1107 DEBUG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n",
1087 __FUNCTION__ ); 1108 __FUNCTION__ );
1088#endif
1089 return rndis_keepalive_response (configNr, 1109 return rndis_keepalive_response (configNr,
1090 (rndis_keepalive_msg_type *) 1110 (rndis_keepalive_msg_type *)
1091 buf); 1111 buf);
@@ -1152,7 +1172,8 @@ void rndis_deregister (int configNr)
1152} 1172}
1153 1173
1154int rndis_set_param_dev (u8 configNr, struct net_device *dev, 1174int rndis_set_param_dev (u8 configNr, struct net_device *dev,
1155 struct net_device_stats *stats) 1175 struct net_device_stats *stats,
1176 u16 *cdc_filter)
1156{ 1177{
1157 DEBUG("%s:\n", __FUNCTION__ ); 1178 DEBUG("%s:\n", __FUNCTION__ );
1158 if (!dev || !stats) return -1; 1179 if (!dev || !stats) return -1;
@@ -1160,6 +1181,7 @@ int rndis_set_param_dev (u8 configNr, struct net_device *dev,
1160 1181
1161 rndis_per_dev_params [configNr].dev = dev; 1182 rndis_per_dev_params [configNr].dev = dev;
1162 rndis_per_dev_params [configNr].stats = stats; 1183 rndis_per_dev_params [configNr].stats = stats;
1184 rndis_per_dev_params [configNr].filter = cdc_filter;
1163 1185
1164 return 0; 1186 return 0;
1165} 1187}
@@ -1178,7 +1200,7 @@ int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr)
1178 1200
1179int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) 1201int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed)
1180{ 1202{
1181 DEBUG("%s:\n", __FUNCTION__ ); 1203 DEBUG("%s: %u %u\n", __FUNCTION__, medium, speed);
1182 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 1204 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1183 1205
1184 rndis_per_dev_params [configNr].medium = medium; 1206 rndis_per_dev_params [configNr].medium = medium;
@@ -1242,6 +1264,7 @@ static rndis_resp_t *rndis_add_response (int configNr, u32 length)
1242{ 1264{
1243 rndis_resp_t *r; 1265 rndis_resp_t *r;
1244 1266
1267 /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
1245 r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC); 1268 r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC);
1246 if (!r) return NULL; 1269 if (!r) return NULL;
1247 1270
diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h
index 2b5b55df3cfd..95b4c6326100 100644
--- a/drivers/usb/gadget/rndis.h
+++ b/drivers/usb/gadget/rndis.h
@@ -69,90 +69,6 @@
69#define OID_PNP_ENABLE_WAKE_UP 0xFD010106 69#define OID_PNP_ENABLE_WAKE_UP 0xFD010106
70 70
71 71
72/* supported OIDs */
73static const u32 oid_supported_list [] =
74{
75 /* the general stuff */
76 OID_GEN_SUPPORTED_LIST,
77 OID_GEN_HARDWARE_STATUS,
78 OID_GEN_MEDIA_SUPPORTED,
79 OID_GEN_MEDIA_IN_USE,
80 OID_GEN_MAXIMUM_FRAME_SIZE,
81 OID_GEN_LINK_SPEED,
82 OID_GEN_TRANSMIT_BLOCK_SIZE,
83 OID_GEN_RECEIVE_BLOCK_SIZE,
84 OID_GEN_VENDOR_ID,
85 OID_GEN_VENDOR_DESCRIPTION,
86 OID_GEN_VENDOR_DRIVER_VERSION,
87 OID_GEN_CURRENT_PACKET_FILTER,
88 OID_GEN_MAXIMUM_TOTAL_SIZE,
89 OID_GEN_MEDIA_CONNECT_STATUS,
90 OID_GEN_PHYSICAL_MEDIUM,
91#if 0
92 OID_GEN_RNDIS_CONFIG_PARAMETER,
93#endif
94
95 /* the statistical stuff */
96 OID_GEN_XMIT_OK,
97 OID_GEN_RCV_OK,
98 OID_GEN_XMIT_ERROR,
99 OID_GEN_RCV_ERROR,
100 OID_GEN_RCV_NO_BUFFER,
101#ifdef RNDIS_OPTIONAL_STATS
102 OID_GEN_DIRECTED_BYTES_XMIT,
103 OID_GEN_DIRECTED_FRAMES_XMIT,
104 OID_GEN_MULTICAST_BYTES_XMIT,
105 OID_GEN_MULTICAST_FRAMES_XMIT,
106 OID_GEN_BROADCAST_BYTES_XMIT,
107 OID_GEN_BROADCAST_FRAMES_XMIT,
108 OID_GEN_DIRECTED_BYTES_RCV,
109 OID_GEN_DIRECTED_FRAMES_RCV,
110 OID_GEN_MULTICAST_BYTES_RCV,
111 OID_GEN_MULTICAST_FRAMES_RCV,
112 OID_GEN_BROADCAST_BYTES_RCV,
113 OID_GEN_BROADCAST_FRAMES_RCV,
114 OID_GEN_RCV_CRC_ERROR,
115 OID_GEN_TRANSMIT_QUEUE_LENGTH,
116#endif /* RNDIS_OPTIONAL_STATS */
117
118 /* mandatory 802.3 */
119 /* the general stuff */
120 OID_802_3_PERMANENT_ADDRESS,
121 OID_802_3_CURRENT_ADDRESS,
122 OID_802_3_MULTICAST_LIST,
123 OID_802_3_MAC_OPTIONS,
124 OID_802_3_MAXIMUM_LIST_SIZE,
125
126 /* the statistical stuff */
127 OID_802_3_RCV_ERROR_ALIGNMENT,
128 OID_802_3_XMIT_ONE_COLLISION,
129 OID_802_3_XMIT_MORE_COLLISIONS,
130#ifdef RNDIS_OPTIONAL_STATS
131 OID_802_3_XMIT_DEFERRED,
132 OID_802_3_XMIT_MAX_COLLISIONS,
133 OID_802_3_RCV_OVERRUN,
134 OID_802_3_XMIT_UNDERRUN,
135 OID_802_3_XMIT_HEARTBEAT_FAILURE,
136 OID_802_3_XMIT_TIMES_CRS_LOST,
137 OID_802_3_XMIT_LATE_COLLISIONS,
138#endif /* RNDIS_OPTIONAL_STATS */
139
140#ifdef RNDIS_PM
141 /* PM and wakeup are mandatory for USB: */
142
143 /* power management */
144 OID_PNP_CAPABILITIES,
145 OID_PNP_QUERY_POWER,
146 OID_PNP_SET_POWER,
147
148 /* wake up host */
149 OID_PNP_ENABLE_WAKE_UP,
150 OID_PNP_ADD_WAKE_UP_PATTERN,
151 OID_PNP_REMOVE_WAKE_UP_PATTERN,
152#endif
153};
154
155
156typedef struct rndis_init_msg_type 72typedef struct rndis_init_msg_type
157{ 73{
158 __le32 MessageType; 74 __le32 MessageType;
@@ -309,15 +225,18 @@ typedef struct rndis_resp_t
309typedef struct rndis_params 225typedef struct rndis_params
310{ 226{
311 u8 confignr; 227 u8 confignr;
312 int used; 228 u8 used;
229 u16 saved_filter;
313 enum rndis_state state; 230 enum rndis_state state;
314 u32 filter;
315 u32 medium; 231 u32 medium;
316 u32 speed; 232 u32 speed;
317 u32 media_state; 233 u32 media_state;
234
318 const u8 *host_mac; 235 const u8 *host_mac;
236 u16 *filter;
319 struct net_device *dev; 237 struct net_device *dev;
320 struct net_device_stats *stats; 238 struct net_device_stats *stats;
239
321 u32 vendorID; 240 u32 vendorID;
322 const char *vendorDescr; 241 const char *vendorDescr;
323 int (*ack) (struct net_device *); 242 int (*ack) (struct net_device *);
@@ -329,7 +248,8 @@ int rndis_msg_parser (u8 configNr, u8 *buf);
329int rndis_register (int (*rndis_control_ack) (struct net_device *)); 248int rndis_register (int (*rndis_control_ack) (struct net_device *));
330void rndis_deregister (int configNr); 249void rndis_deregister (int configNr);
331int rndis_set_param_dev (u8 configNr, struct net_device *dev, 250int rndis_set_param_dev (u8 configNr, struct net_device *dev,
332 struct net_device_stats *stats); 251 struct net_device_stats *stats,
252 u16 *cdc_filter);
333int rndis_set_param_vendor (u8 configNr, u32 vendorID, 253int rndis_set_param_vendor (u8 configNr, u32 vendorID,
334 const char *vendorDescr); 254 const char *vendorDescr);
335int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed); 255int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed);
@@ -338,6 +258,7 @@ int rndis_rm_hdr (struct sk_buff *skb);
338u8 *rndis_get_next_response (int configNr, u32 *length); 258u8 *rndis_get_next_response (int configNr, u32 *length);
339void rndis_free_response (int configNr, u8 *buf); 259void rndis_free_response (int configNr, u8 *buf);
340 260
261void rndis_uninit (int configNr);
341int rndis_signal_connect (int configNr); 262int rndis_signal_connect (int configNr);
342int rndis_signal_disconnect (int configNr); 263int rndis_signal_disconnect (int configNr);
343int rndis_state (int configNr); 264int rndis_state (int configNr);
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 4d591c764e38..9e4f1c6935a5 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -300,18 +300,18 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed,
300 u8 type, unsigned int index, int is_otg); 300 u8 type, unsigned int index, int is_otg);
301 301
302static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, 302static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len,
303 int kmalloc_flags); 303 unsigned kmalloc_flags);
304static void gs_free_req(struct usb_ep *ep, struct usb_request *req); 304static void gs_free_req(struct usb_ep *ep, struct usb_request *req);
305 305
306static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len, 306static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len,
307 int kmalloc_flags); 307 unsigned kmalloc_flags);
308static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req); 308static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req);
309 309
310static int gs_alloc_ports(struct gs_dev *dev, int kmalloc_flags); 310static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags);
311static void gs_free_ports(struct gs_dev *dev); 311static void gs_free_ports(struct gs_dev *dev);
312 312
313/* circular buffer */ 313/* circular buffer */
314static struct gs_buf *gs_buf_alloc(unsigned int size, int kmalloc_flags); 314static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags);
315static void gs_buf_free(struct gs_buf *gb); 315static void gs_buf_free(struct gs_buf *gb);
316static void gs_buf_clear(struct gs_buf *gb); 316static void gs_buf_clear(struct gs_buf *gb);
317static unsigned int gs_buf_data_avail(struct gs_buf *gb); 317static unsigned int gs_buf_data_avail(struct gs_buf *gb);
@@ -1607,9 +1607,9 @@ static int gs_setup(struct usb_gadget *gadget,
1607 int ret = -EOPNOTSUPP; 1607 int ret = -EOPNOTSUPP;
1608 struct gs_dev *dev = get_gadget_data(gadget); 1608 struct gs_dev *dev = get_gadget_data(gadget);
1609 struct usb_request *req = dev->dev_ctrl_req; 1609 struct usb_request *req = dev->dev_ctrl_req;
1610 u16 wIndex = ctrl->wIndex; 1610 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1611 u16 wValue = ctrl->wValue; 1611 u16 wValue = le16_to_cpu(ctrl->wValue);
1612 u16 wLength = ctrl->wLength; 1612 u16 wLength = le16_to_cpu(ctrl->wLength);
1613 1613
1614 switch (ctrl->bRequestType & USB_TYPE_MASK) { 1614 switch (ctrl->bRequestType & USB_TYPE_MASK) {
1615 case USB_TYPE_STANDARD: 1615 case USB_TYPE_STANDARD:
@@ -1651,9 +1651,9 @@ static int gs_setup_standard(struct usb_gadget *gadget,
1651 int ret = -EOPNOTSUPP; 1651 int ret = -EOPNOTSUPP;
1652 struct gs_dev *dev = get_gadget_data(gadget); 1652 struct gs_dev *dev = get_gadget_data(gadget);
1653 struct usb_request *req = dev->dev_ctrl_req; 1653 struct usb_request *req = dev->dev_ctrl_req;
1654 u16 wIndex = ctrl->wIndex; 1654 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1655 u16 wValue = ctrl->wValue; 1655 u16 wValue = le16_to_cpu(ctrl->wValue);
1656 u16 wLength = ctrl->wLength; 1656 u16 wLength = le16_to_cpu(ctrl->wLength);
1657 1657
1658 switch (ctrl->bRequest) { 1658 switch (ctrl->bRequest) {
1659 case USB_REQ_GET_DESCRIPTOR: 1659 case USB_REQ_GET_DESCRIPTOR:
@@ -1782,9 +1782,9 @@ static int gs_setup_class(struct usb_gadget *gadget,
1782 struct gs_dev *dev = get_gadget_data(gadget); 1782 struct gs_dev *dev = get_gadget_data(gadget);
1783 struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */ 1783 struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */
1784 struct usb_request *req = dev->dev_ctrl_req; 1784 struct usb_request *req = dev->dev_ctrl_req;
1785 u16 wIndex = ctrl->wIndex; 1785 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1786 u16 wValue = ctrl->wValue; 1786 u16 wValue = le16_to_cpu(ctrl->wValue);
1787 u16 wLength = ctrl->wLength; 1787 u16 wLength = le16_to_cpu(ctrl->wLength);
1788 1788
1789 switch (ctrl->bRequest) { 1789 switch (ctrl->bRequest) {
1790 case USB_CDC_REQ_SET_LINE_CODING: 1790 case USB_CDC_REQ_SET_LINE_CODING:
@@ -2119,7 +2119,8 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed,
2119 * Allocate a usb_request and its buffer. Returns a pointer to the 2119 * Allocate a usb_request and its buffer. Returns a pointer to the
2120 * usb_request or NULL if there is an error. 2120 * usb_request or NULL if there is an error.
2121 */ 2121 */
2122static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, int kmalloc_flags) 2122static struct usb_request *
2123gs_alloc_req(struct usb_ep *ep, unsigned int len, unsigned kmalloc_flags)
2123{ 2124{
2124 struct usb_request *req; 2125 struct usb_request *req;
2125 2126
@@ -2159,7 +2160,8 @@ static void gs_free_req(struct usb_ep *ep, struct usb_request *req)
2159 * Allocates a request and its buffer, using the given 2160 * Allocates a request and its buffer, using the given
2160 * endpoint, buffer len, and kmalloc flags. 2161 * endpoint, buffer len, and kmalloc flags.
2161 */ 2162 */
2162static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len, int kmalloc_flags) 2163static struct gs_req_entry *
2164gs_alloc_req_entry(struct usb_ep *ep, unsigned len, unsigned kmalloc_flags)
2163{ 2165{
2164 struct gs_req_entry *req; 2166 struct gs_req_entry *req;
2165 2167
@@ -2200,7 +2202,7 @@ static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req)
2200 * 2202 *
2201 * The device lock is normally held when calling this function. 2203 * The device lock is normally held when calling this function.
2202 */ 2204 */
2203static int gs_alloc_ports(struct gs_dev *dev, int kmalloc_flags) 2205static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags)
2204{ 2206{
2205 int i; 2207 int i;
2206 struct gs_port *port; 2208 struct gs_port *port;
@@ -2282,7 +2284,7 @@ static void gs_free_ports(struct gs_dev *dev)
2282 * 2284 *
2283 * Allocate a circular buffer and all associated memory. 2285 * Allocate a circular buffer and all associated memory.
2284 */ 2286 */
2285static struct gs_buf *gs_buf_alloc(unsigned int size, int kmalloc_flags) 2287static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags)
2286{ 2288{
2287 struct gs_buf *gb; 2289 struct gs_buf *gb;
2288 2290
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 6e49432071a1..a6e035e24479 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -919,9 +919,9 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
919 struct zero_dev *dev = get_gadget_data (gadget); 919 struct zero_dev *dev = get_gadget_data (gadget);
920 struct usb_request *req = dev->req; 920 struct usb_request *req = dev->req;
921 int value = -EOPNOTSUPP; 921 int value = -EOPNOTSUPP;
922 u16 w_index = ctrl->wIndex; 922 u16 w_index = le16_to_cpu(ctrl->wIndex);
923 u16 w_value = ctrl->wValue; 923 u16 w_value = le16_to_cpu(ctrl->wValue);
924 u16 w_length = ctrl->wLength; 924 u16 w_length = le16_to_cpu(ctrl->wLength);
925 925
926 /* usually this stores reply data in the pre-allocated ep0 buffer, 926 /* usually this stores reply data in the pre-allocated ep0 buffer,
927 * but config change events will reconfigure hardware. 927 * but config change events will reconfigure hardware.
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 19e598c9641f..ed1899d307db 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -49,6 +49,19 @@ config USB_EHCI_ROOT_HUB_TT
49 49
50 This supports the EHCI implementation from TransDimension Inc. 50 This supports the EHCI implementation from TransDimension Inc.
51 51
52config USB_ISP116X_HCD
53 tristate "ISP116X HCD support"
54 depends on USB
55 default N
56 ---help---
57 The ISP1160 and ISP1161 chips are USB host controllers. Enable this
58 option if your board has this chip. If unsure, say N.
59
60 This driver does not support isochronous transfers.
61
62 To compile this driver as a module, choose M here: the
63 module will be called isp116x-hcd.
64
52config USB_OHCI_HCD 65config USB_OHCI_HCD
53 tristate "OHCI HCD support" 66 tristate "OHCI HCD support"
54 depends on USB && USB_ARCH_HAS_OHCI 67 depends on USB && USB_ARCH_HAS_OHCI
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 5dbd3e7a27c7..350d14fc1cc9 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -4,6 +4,7 @@
4# 4#
5 5
6obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o 6obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o
7obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o
7obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o 8obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o
8obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o 9obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
9obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o 10obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 2ff11d53567b..50cb01831075 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -254,7 +254,7 @@ dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status)
254 } 254 }
255 255
256 return scnprintf (buf, len, 256 return scnprintf (buf, len,
257 "%s%sport %d status %06x%s%s sig=%s %s%s%s%s%s%s%s%s%s", 257 "%s%sport %d status %06x%s%s sig=%s%s%s%s%s%s%s%s%s%s",
258 label, label [0] ? " " : "", port, status, 258 label, label [0] ? " " : "", port, status,
259 (status & PORT_POWER) ? " POWER" : "", 259 (status & PORT_POWER) ? " POWER" : "",
260 (status & PORT_OWNER) ? " OWNER" : "", 260 (status & PORT_OWNER) ? " OWNER" : "",
@@ -644,9 +644,11 @@ show_registers (struct class_device *class_dev, char *buf)
644 if (bus->controller->power.power_state) { 644 if (bus->controller->power.power_state) {
645 size = scnprintf (next, size, 645 size = scnprintf (next, size,
646 "bus %s, device %s (driver " DRIVER_VERSION ")\n" 646 "bus %s, device %s (driver " DRIVER_VERSION ")\n"
647 "%s\n"
647 "SUSPENDED (no register access)\n", 648 "SUSPENDED (no register access)\n",
648 hcd->self.controller->bus->name, 649 hcd->self.controller->bus->name,
649 hcd->self.controller->bus_id); 650 hcd->self.controller->bus_id,
651 hcd->product_desc);
650 goto done; 652 goto done;
651 } 653 }
652 654
@@ -654,13 +656,53 @@ show_registers (struct class_device *class_dev, char *buf)
654 i = HC_VERSION(readl (&ehci->caps->hc_capbase)); 656 i = HC_VERSION(readl (&ehci->caps->hc_capbase));
655 temp = scnprintf (next, size, 657 temp = scnprintf (next, size,
656 "bus %s, device %s (driver " DRIVER_VERSION ")\n" 658 "bus %s, device %s (driver " DRIVER_VERSION ")\n"
659 "%s\n"
657 "EHCI %x.%02x, hcd state %d\n", 660 "EHCI %x.%02x, hcd state %d\n",
658 hcd->self.controller->bus->name, 661 hcd->self.controller->bus->name,
659 hcd->self.controller->bus_id, 662 hcd->self.controller->bus_id,
663 hcd->product_desc,
660 i >> 8, i & 0x0ff, hcd->state); 664 i >> 8, i & 0x0ff, hcd->state);
661 size -= temp; 665 size -= temp;
662 next += temp; 666 next += temp;
663 667
668#ifdef CONFIG_PCI
669 /* EHCI 0.96 and later may have "extended capabilities" */
670 if (hcd->self.controller->bus == &pci_bus_type) {
671 struct pci_dev *pdev;
672 u32 offset, cap, cap2;
673 unsigned count = 256/4;
674
675 pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
676 offset = HCC_EXT_CAPS (readl (&ehci->caps->hcc_params));
677 while (offset && count--) {
678 pci_read_config_dword (pdev, offset, &cap);
679 switch (cap & 0xff) {
680 case 1:
681 temp = scnprintf (next, size,
682 "ownership %08x%s%s\n", cap,
683 (cap & (1 << 24)) ? " linux" : "",
684 (cap & (1 << 16)) ? " firmware" : "");
685 size -= temp;
686 next += temp;
687
688 offset += 4;
689 pci_read_config_dword (pdev, offset, &cap2);
690 temp = scnprintf (next, size,
691 "SMI sts/enable 0x%08x\n", cap2);
692 size -= temp;
693 next += temp;
694 break;
695 case 0: /* illegal reserved capability */
696 cap = 0;
697 /* FALLTHROUGH */
698 default: /* unknown */
699 break;
700 }
701 temp = (cap >> 8) & 0xff;
702 }
703 }
704#endif
705
664 // FIXME interpret both types of params 706 // FIXME interpret both types of params
665 i = readl (&ehci->caps->hcs_params); 707 i = readl (&ehci->caps->hcs_params);
666 temp = scnprintf (next, size, "structural params 0x%08x\n", i); 708 temp = scnprintf (next, size, "structural params 0x%08x\n", i);
@@ -696,12 +738,19 @@ show_registers (struct class_device *class_dev, char *buf)
696 size -= temp; 738 size -= temp;
697 next += temp; 739 next += temp;
698 740
699 for (i = 0; i < HCS_N_PORTS (ehci->hcs_params); i++) { 741 for (i = 1; i <= HCS_N_PORTS (ehci->hcs_params); i++) {
700 temp = dbg_port_buf (scratch, sizeof scratch, label, i + 1, 742 temp = dbg_port_buf (scratch, sizeof scratch, label, i,
701 readl (&ehci->regs->port_status [i])); 743 readl (&ehci->regs->port_status [i - 1]));
702 temp = scnprintf (next, size, fmt, temp, scratch); 744 temp = scnprintf (next, size, fmt, temp, scratch);
703 size -= temp; 745 size -= temp;
704 next += temp; 746 next += temp;
747 if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) {
748 temp = scnprintf (next, size,
749 " debug control %08x\n",
750 readl (&ehci->debug->control));
751 size -= temp;
752 next += temp;
753 }
705 } 754 }
706 755
707 if (ehci->reclaim) { 756 if (ehci->reclaim) {
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index bc69bd7acebe..35248a37b717 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -304,30 +304,31 @@ static void ehci_watchdog (unsigned long param)
304 */ 304 */
305static int bios_handoff (struct ehci_hcd *ehci, int where, u32 cap) 305static int bios_handoff (struct ehci_hcd *ehci, int where, u32 cap)
306{ 306{
307 struct pci_dev *pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
308
309 /* always say Linux will own the hardware */
310 pci_write_config_byte(pdev, where + 3, 1);
311
312 /* maybe wait a while for BIOS to respond */
307 if (cap & (1 << 16)) { 313 if (cap & (1 << 16)) {
308 int msec = 5000; 314 int msec = 5000;
309 struct pci_dev *pdev =
310 to_pci_dev(ehci_to_hcd(ehci)->self.controller);
311 315
312 /* request handoff to OS */
313 cap |= 1 << 24;
314 pci_write_config_dword(pdev, where, cap);
315
316 /* and wait a while for it to happen */
317 do { 316 do {
318 msleep(10); 317 msleep(10);
319 msec -= 10; 318 msec -= 10;
320 pci_read_config_dword(pdev, where, &cap); 319 pci_read_config_dword(pdev, where, &cap);
321 } while ((cap & (1 << 16)) && msec); 320 } while ((cap & (1 << 16)) && msec);
322 if (cap & (1 << 16)) { 321 if (cap & (1 << 16)) {
323 ehci_err (ehci, "BIOS handoff failed (%d, %04x)\n", 322 ehci_err(ehci, "BIOS handoff failed (%d, %08x)\n",
324 where, cap); 323 where, cap);
325 // some BIOS versions seem buggy... 324 // some BIOS versions seem buggy...
326 // return 1; 325 // return 1;
327 ehci_warn (ehci, "continuing after BIOS bug...\n"); 326 ehci_warn (ehci, "continuing after BIOS bug...\n");
328 return 0; 327 /* disable all SMIs, and clear "BIOS owns" flag */
329 } 328 pci_write_config_dword(pdev, where + 4, 0);
330 ehci_dbg (ehci, "BIOS handoff succeeded\n"); 329 pci_write_config_byte(pdev, where + 2, 0);
330 } else
331 ehci_dbg(ehci, "BIOS handoff succeeded\n");
331 } 332 }
332 return 0; 333 return 0;
333} 334}
@@ -492,8 +493,6 @@ static int ehci_start (struct usb_hcd *hcd)
492{ 493{
493 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 494 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
494 u32 temp; 495 u32 temp;
495 struct usb_device *udev;
496 struct usb_bus *bus;
497 int retval; 496 int retval;
498 u32 hcc_params; 497 u32 hcc_params;
499 u8 sbrn = 0; 498 u8 sbrn = 0;
@@ -588,8 +587,8 @@ static int ehci_start (struct usb_hcd *hcd)
588 writel (0, &ehci->regs->segment); 587 writel (0, &ehci->regs->segment);
589#if 0 588#if 0
590// this is deeply broken on almost all architectures 589// this is deeply broken on almost all architectures
591 if (!pci_set_dma_mask (to_pci_dev(hcd->self.controller), 0xffffffffffffffffULL)) 590 if (!dma_set_mask (hcd->self.controller, DMA_64BIT_MASK))
592 ehci_info (ehci, "enabled 64bit PCI DMA\n"); 591 ehci_info (ehci, "enabled 64bit DMA\n");
593#endif 592#endif
594 } 593 }
595 594
@@ -631,17 +630,6 @@ static int ehci_start (struct usb_hcd *hcd)
631 630
632 /* set async sleep time = 10 us ... ? */ 631 /* set async sleep time = 10 us ... ? */
633 632
634 /* wire up the root hub */
635 bus = hcd_to_bus (hcd);
636 udev = first ? usb_alloc_dev (NULL, bus, 0) : bus->root_hub;
637 if (!udev) {
638done2:
639 ehci_mem_cleanup (ehci);
640 return -ENOMEM;
641 }
642 udev->speed = USB_SPEED_HIGH;
643 udev->state = first ? USB_STATE_ATTACHED : USB_STATE_CONFIGURED;
644
645 /* 633 /*
646 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices 634 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
647 * are explicitly handed to companion controller(s), so no TT is 635 * are explicitly handed to companion controller(s), so no TT is
@@ -664,24 +652,6 @@ done2:
664 first ? "initialized" : "restarted", 652 first ? "initialized" : "restarted",
665 temp >> 8, temp & 0xff, DRIVER_VERSION); 653 temp >> 8, temp & 0xff, DRIVER_VERSION);
666 654
667 /*
668 * From here on, khubd concurrently accesses the root
669 * hub; drivers will be talking to enumerated devices.
670 * (On restart paths, khubd already knows about the root
671 * hub and could find work as soon as we wrote FLAG_CF.)
672 *
673 * Before this point the HC was idle/ready. After, khubd
674 * and device drivers may start it running.
675 */
676 if (first && usb_hcd_register_root_hub (udev, hcd) != 0) {
677 if (hcd->state == HC_STATE_RUNNING)
678 ehci_quiesce (ehci);
679 ehci_reset (ehci);
680 usb_put_dev (udev);
681 retval = -ENODEV;
682 goto done2;
683 }
684
685 writel (INTR_MASK, &ehci->regs->intr_enable); /* Turn On Interrupts */ 655 writel (INTR_MASK, &ehci->regs->intr_enable); /* Turn On Interrupts */
686 656
687 if (first) 657 if (first)
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index d7b4f7939ded..36cc1f2218d5 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2001-2002 by David Brownell 2 * Copyright (C) 2001-2004 by David Brownell
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 the GNU General Public License as published by the 5 * under the terms of the GNU General Public License as published by the
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 7df9b9af54f6..45d89a7083b1 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2001-2002 by David Brownell 2 * Copyright (C) 2001-2004 by David Brownell
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 the GNU General Public License as published by the 5 * under the terms of the GNU General Public License as published by the
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 2fa1ffee5ff3..c2104cad4033 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -637,9 +637,8 @@ iso_stream_alloc (int mem_flags)
637{ 637{
638 struct ehci_iso_stream *stream; 638 struct ehci_iso_stream *stream;
639 639
640 stream = kmalloc(sizeof *stream, mem_flags); 640 stream = kcalloc(1, sizeof *stream, mem_flags);
641 if (likely (stream != NULL)) { 641 if (likely (stream != NULL)) {
642 memset (stream, 0, sizeof(*stream));
643 INIT_LIST_HEAD(&stream->td_list); 642 INIT_LIST_HEAD(&stream->td_list);
644 INIT_LIST_HEAD(&stream->free_list); 643 INIT_LIST_HEAD(&stream->free_list);
645 stream->next_uframe = -1; 644 stream->next_uframe = -1;
@@ -894,7 +893,7 @@ itd_sched_init (
894 trans |= length << 16; 893 trans |= length << 16;
895 uframe->transaction = cpu_to_le32 (trans); 894 uframe->transaction = cpu_to_le32 (trans);
896 895
897 /* might need to cross a buffer page within a td */ 896 /* might need to cross a buffer page within a uframe */
898 uframe->bufp = (buf & ~(u64)0x0fff); 897 uframe->bufp = (buf & ~(u64)0x0fff);
899 buf += length; 898 buf += length;
900 if (unlikely ((uframe->bufp != (buf & ~(u64)0x0fff)))) 899 if (unlikely ((uframe->bufp != (buf & ~(u64)0x0fff))))
@@ -1194,6 +1193,7 @@ itd_init (struct ehci_iso_stream *stream, struct ehci_itd *itd)
1194{ 1193{
1195 int i; 1194 int i;
1196 1195
1196 /* it's been recently zeroed */
1197 itd->hw_next = EHCI_LIST_END; 1197 itd->hw_next = EHCI_LIST_END;
1198 itd->hw_bufp [0] = stream->buf0; 1198 itd->hw_bufp [0] = stream->buf0;
1199 itd->hw_bufp [1] = stream->buf1; 1199 itd->hw_bufp [1] = stream->buf1;
@@ -1210,8 +1210,7 @@ itd_patch (
1210 struct ehci_itd *itd, 1210 struct ehci_itd *itd,
1211 struct ehci_iso_sched *iso_sched, 1211 struct ehci_iso_sched *iso_sched,
1212 unsigned index, 1212 unsigned index,
1213 u16 uframe, 1213 u16 uframe
1214 int first
1215) 1214)
1216{ 1215{
1217 struct ehci_iso_packet *uf = &iso_sched->packet [index]; 1216 struct ehci_iso_packet *uf = &iso_sched->packet [index];
@@ -1228,7 +1227,7 @@ itd_patch (
1228 itd->hw_bufp_hi [pg] |= cpu_to_le32 ((u32)(uf->bufp >> 32)); 1227 itd->hw_bufp_hi [pg] |= cpu_to_le32 ((u32)(uf->bufp >> 32));
1229 1228
1230 /* iso_frame_desc[].offset must be strictly increasing */ 1229 /* iso_frame_desc[].offset must be strictly increasing */
1231 if (unlikely (!first && uf->cross)) { 1230 if (unlikely (uf->cross)) {
1232 u64 bufp = uf->bufp + 4096; 1231 u64 bufp = uf->bufp + 4096;
1233 itd->pg = ++pg; 1232 itd->pg = ++pg;
1234 itd->hw_bufp [pg] |= cpu_to_le32 (bufp & ~(u32)0); 1233 itd->hw_bufp [pg] |= cpu_to_le32 (bufp & ~(u32)0);
@@ -1257,7 +1256,7 @@ itd_link_urb (
1257 struct ehci_iso_stream *stream 1256 struct ehci_iso_stream *stream
1258) 1257)
1259{ 1258{
1260 int packet, first = 1; 1259 int packet;
1261 unsigned next_uframe, uframe, frame; 1260 unsigned next_uframe, uframe, frame;
1262 struct ehci_iso_sched *iso_sched = urb->hcpriv; 1261 struct ehci_iso_sched *iso_sched = urb->hcpriv;
1263 struct ehci_itd *itd; 1262 struct ehci_itd *itd;
@@ -1290,7 +1289,6 @@ itd_link_urb (
1290 list_move_tail (&itd->itd_list, &stream->td_list); 1289 list_move_tail (&itd->itd_list, &stream->td_list);
1291 itd->stream = iso_stream_get (stream); 1290 itd->stream = iso_stream_get (stream);
1292 itd->urb = usb_get_urb (urb); 1291 itd->urb = usb_get_urb (urb);
1293 first = 1;
1294 itd_init (stream, itd); 1292 itd_init (stream, itd);
1295 } 1293 }
1296 1294
@@ -1298,8 +1296,7 @@ itd_link_urb (
1298 frame = next_uframe >> 3; 1296 frame = next_uframe >> 3;
1299 1297
1300 itd->usecs [uframe] = stream->usecs; 1298 itd->usecs [uframe] = stream->usecs;
1301 itd_patch (itd, iso_sched, packet, uframe, first); 1299 itd_patch (itd, iso_sched, packet, uframe);
1302 first = 0;
1303 1300
1304 next_uframe += stream->interval; 1301 next_uframe += stream->interval;
1305 stream->depth += stream->interval; 1302 stream->depth += stream->interval;
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
new file mode 100644
index 000000000000..ff0a168e8eed
--- /dev/null
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -0,0 +1,1875 @@
1/*
2 * ISP116x HCD (Host Controller Driver) for USB.
3 *
4 * Derived from the SL811 HCD, rewritten for ISP116x.
5 * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
6 *
7 * Portions:
8 * Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
9 * Copyright (C) 2004 David Brownell
10 *
11 * Periodic scheduling is based on Roman's OHCI code
12 * Copyright (C) 1999 Roman Weissgaerber
13 *
14 */
15
16/*
17 * The driver basically works. A number of people have used it with a range
18 * of devices.
19 *
20 *The driver passes all usbtests 1-14.
21 *
22 * Suspending/resuming of root hub via sysfs works. Remote wakeup works too.
23 * And suspending/resuming of platform device works too. Suspend/resume
24 * via HCD operations vector is not implemented.
25 *
26 * Iso transfer support is not implemented. Adding this would include
27 * implementing recovery from the failure to service the processed ITL
28 * fifo ram in time, which will involve chip reset.
29 *
30 * TODO:
31 + More testing of suspend/resume.
32*/
33
34/*
35 ISP116x chips require certain delays between accesses to its
36 registers. The following timing options exist.
37
38 1. Configure your memory controller (the best)
39 2. Implement platform-specific delay function possibly
40 combined with configuring the memory controller; see
41 include/linux/usb-isp116x.h for more info. Some broken
42 memory controllers line LH7A400 SMC need this. Also,
43 uncomment for that to work the following
44 USE_PLATFORM_DELAY macro.
45 3. Use ndelay (easiest, poorest). For that, uncomment
46 the following USE_NDELAY macro.
47*/
48#define USE_PLATFORM_DELAY
49//#define USE_NDELAY
50
51//#define DEBUG
52//#define VERBOSE
53/* Transfer descriptors. See dump_ptd() for printout format */
54//#define PTD_TRACE
55/* enqueuing/finishing log of urbs */
56//#define URB_TRACE
57
58#include <linux/config.h>
59#include <linux/module.h>
60#include <linux/moduleparam.h>
61#include <linux/kernel.h>
62#include <linux/delay.h>
63#include <linux/ioport.h>
64#include <linux/sched.h>
65#include <linux/slab.h>
66#include <linux/smp_lock.h>
67#include <linux/errno.h>
68#include <linux/init.h>
69#include <linux/list.h>
70#include <linux/interrupt.h>
71#include <linux/usb.h>
72#include <linux/usb_isp116x.h>
73
74#include <asm/io.h>
75#include <asm/irq.h>
76#include <asm/system.h>
77#include <asm/byteorder.h>
78
79#ifndef DEBUG
80# define STUB_DEBUG_FILE
81#endif
82
83#include "../core/hcd.h"
84#include "isp116x.h"
85
86#define DRIVER_VERSION "08 Apr 2005"
87#define DRIVER_DESC "ISP116x USB Host Controller Driver"
88
89MODULE_DESCRIPTION(DRIVER_DESC);
90MODULE_LICENSE("GPL");
91
92static const char hcd_name[] = "isp116x-hcd";
93
94/*-----------------------------------------------------------------*/
95
96/*
97 Write len bytes to fifo, pad till 32-bit boundary
98 */
99static void write_ptddata_to_fifo(struct isp116x *isp116x, void *buf, int len)
100{
101 u8 *dp = (u8 *) buf;
102 u16 *dp2 = (u16 *) buf;
103 u16 w;
104 int quot = len % 4;
105
106 if ((unsigned long)dp2 & 1) {
107 /* not aligned */
108 for (; len > 1; len -= 2) {
109 w = *dp++;
110 w |= *dp++ << 8;
111 isp116x_raw_write_data16(isp116x, w);
112 }
113 if (len)
114 isp116x_write_data16(isp116x, (u16) * dp);
115 } else {
116 /* aligned */
117 for (; len > 1; len -= 2)
118 isp116x_raw_write_data16(isp116x, *dp2++);
119 if (len)
120 isp116x_write_data16(isp116x, 0xff & *((u8 *) dp2));
121 }
122 if (quot == 1 || quot == 2)
123 isp116x_raw_write_data16(isp116x, 0);
124}
125
126/*
127 Read len bytes from fifo and then read till 32-bit boundary.
128 */
129static void read_ptddata_from_fifo(struct isp116x *isp116x, void *buf, int len)
130{
131 u8 *dp = (u8 *) buf;
132 u16 *dp2 = (u16 *) buf;
133 u16 w;
134 int quot = len % 4;
135
136 if ((unsigned long)dp2 & 1) {
137 /* not aligned */
138 for (; len > 1; len -= 2) {
139 w = isp116x_raw_read_data16(isp116x);
140 *dp++ = w & 0xff;
141 *dp++ = (w >> 8) & 0xff;
142 }
143 if (len)
144 *dp = 0xff & isp116x_read_data16(isp116x);
145 } else {
146 /* aligned */
147 for (; len > 1; len -= 2)
148 *dp2++ = isp116x_raw_read_data16(isp116x);
149 if (len)
150 *(u8 *) dp2 = 0xff & isp116x_read_data16(isp116x);
151 }
152 if (quot == 1 || quot == 2)
153 isp116x_raw_read_data16(isp116x);
154}
155
156/*
157 Write ptd's and data for scheduled transfers into
158 the fifo ram. Fifo must be empty and ready.
159*/
160static void pack_fifo(struct isp116x *isp116x)
161{
162 struct isp116x_ep *ep;
163 struct ptd *ptd;
164 int buflen = isp116x->atl_last_dir == PTD_DIR_IN
165 ? isp116x->atl_bufshrt : isp116x->atl_buflen;
166 int ptd_count = 0;
167
168 isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
169 isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
170 isp116x_write_addr(isp116x, HCATLPORT | ISP116x_WRITE_OFFSET);
171 for (ep = isp116x->atl_active; ep; ep = ep->active) {
172 ++ptd_count;
173 ptd = &ep->ptd;
174 dump_ptd(ptd);
175 dump_ptd_out_data(ptd, ep->data);
176 isp116x_write_data16(isp116x, ptd->count);
177 isp116x_write_data16(isp116x, ptd->mps);
178 isp116x_write_data16(isp116x, ptd->len);
179 isp116x_write_data16(isp116x, ptd->faddr);
180 buflen -= sizeof(struct ptd);
181 /* Skip writing data for last IN PTD */
182 if (ep->active || (isp116x->atl_last_dir != PTD_DIR_IN)) {
183 write_ptddata_to_fifo(isp116x, ep->data, ep->length);
184 buflen -= ALIGN(ep->length, 4);
185 }
186 }
187 BUG_ON(buflen);
188}
189
190/*
191 Read the processed ptd's and data from fifo ram back to
192 URBs' buffers. Fifo must be full and done
193*/
194static void unpack_fifo(struct isp116x *isp116x)
195{
196 struct isp116x_ep *ep;
197 struct ptd *ptd;
198 int buflen = isp116x->atl_last_dir == PTD_DIR_IN
199 ? isp116x->atl_buflen : isp116x->atl_bufshrt;
200
201 isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
202 isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
203 isp116x_write_addr(isp116x, HCATLPORT);
204 for (ep = isp116x->atl_active; ep; ep = ep->active) {
205 ptd = &ep->ptd;
206 ptd->count = isp116x_read_data16(isp116x);
207 ptd->mps = isp116x_read_data16(isp116x);
208 ptd->len = isp116x_read_data16(isp116x);
209 ptd->faddr = isp116x_read_data16(isp116x);
210 buflen -= sizeof(struct ptd);
211 /* Skip reading data for last Setup or Out PTD */
212 if (ep->active || (isp116x->atl_last_dir == PTD_DIR_IN)) {
213 read_ptddata_from_fifo(isp116x, ep->data, ep->length);
214 buflen -= ALIGN(ep->length, 4);
215 }
216 dump_ptd(ptd);
217 dump_ptd_in_data(ptd, ep->data);
218 }
219 BUG_ON(buflen);
220}
221
222/*---------------------------------------------------------------*/
223
224/*
225 Set up PTD's.
226*/
227static void preproc_atl_queue(struct isp116x *isp116x)
228{
229 struct isp116x_ep *ep;
230 struct urb *urb;
231 struct ptd *ptd;
232 u16 toggle, dir, len;
233
234 for (ep = isp116x->atl_active; ep; ep = ep->active) {
235 BUG_ON(list_empty(&ep->hep->urb_list));
236 urb = container_of(ep->hep->urb_list.next,
237 struct urb, urb_list);
238 ptd = &ep->ptd;
239 len = ep->length;
240 spin_lock(&urb->lock);
241 ep->data = (unsigned char *)urb->transfer_buffer
242 + urb->actual_length;
243
244 switch (ep->nextpid) {
245 case USB_PID_IN:
246 toggle = usb_gettoggle(urb->dev, ep->epnum, 0);
247 dir = PTD_DIR_IN;
248 break;
249 case USB_PID_OUT:
250 toggle = usb_gettoggle(urb->dev, ep->epnum, 1);
251 dir = PTD_DIR_OUT;
252 break;
253 case USB_PID_SETUP:
254 toggle = 0;
255 dir = PTD_DIR_SETUP;
256 len = sizeof(struct usb_ctrlrequest);
257 ep->data = urb->setup_packet;
258 break;
259 case USB_PID_ACK:
260 toggle = 1;
261 len = 0;
262 dir = (urb->transfer_buffer_length
263 && usb_pipein(urb->pipe))
264 ? PTD_DIR_OUT : PTD_DIR_IN;
265 break;
266 default:
267 /* To please gcc */
268 toggle = dir = 0;
269 ERR("%s %d: ep->nextpid %d\n", __func__, __LINE__,
270 ep->nextpid);
271 BUG_ON(1);
272 }
273
274 ptd->count = PTD_CC_MSK | PTD_ACTIVE_MSK | PTD_TOGGLE(toggle);
275 ptd->mps = PTD_MPS(ep->maxpacket)
276 | PTD_SPD(urb->dev->speed == USB_SPEED_LOW)
277 | PTD_EP(ep->epnum);
278 ptd->len = PTD_LEN(len) | PTD_DIR(dir);
279 ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe));
280 spin_unlock(&urb->lock);
281 if (!ep->active) {
282 ptd->mps |= PTD_LAST_MSK;
283 isp116x->atl_last_dir = dir;
284 }
285 isp116x->atl_bufshrt = sizeof(struct ptd) + isp116x->atl_buflen;
286 isp116x->atl_buflen = isp116x->atl_bufshrt + ALIGN(len, 4);
287 }
288}
289
290/*
291 Analyze transfer results, handle partial transfers and errors
292*/
293static void postproc_atl_queue(struct isp116x *isp116x)
294{
295 struct isp116x_ep *ep;
296 struct urb *urb;
297 struct usb_device *udev;
298 struct ptd *ptd;
299 int short_not_ok;
300 u8 cc;
301
302 for (ep = isp116x->atl_active; ep; ep = ep->active) {
303 BUG_ON(list_empty(&ep->hep->urb_list));
304 urb =
305 container_of(ep->hep->urb_list.next, struct urb, urb_list);
306 udev = urb->dev;
307 ptd = &ep->ptd;
308 cc = PTD_GET_CC(ptd);
309
310 spin_lock(&urb->lock);
311 short_not_ok = 1;
312
313 /* Data underrun is special. For allowed underrun
314 we clear the error and continue as normal. For
315 forbidden underrun we finish the DATA stage
316 immediately while for control transfer,
317 we do a STATUS stage. */
318 if (cc == TD_DATAUNDERRUN) {
319 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) {
320 DBG("Allowed data underrun\n");
321 cc = TD_CC_NOERROR;
322 short_not_ok = 0;
323 } else {
324 ep->error_count = 1;
325 if (usb_pipecontrol(urb->pipe))
326 ep->nextpid = USB_PID_ACK;
327 else
328 usb_settoggle(udev, ep->epnum,
329 ep->nextpid ==
330 USB_PID_OUT,
331 PTD_GET_TOGGLE(ptd) ^ 1);
332 urb->status = cc_to_error[TD_DATAUNDERRUN];
333 spin_unlock(&urb->lock);
334 continue;
335 }
336 }
337 /* Keep underrun error through the STATUS stage */
338 if (urb->status == cc_to_error[TD_DATAUNDERRUN])
339 cc = TD_DATAUNDERRUN;
340
341 if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED
342 && (++ep->error_count >= 3 || cc == TD_CC_STALL
343 || cc == TD_DATAOVERRUN)) {
344 if (urb->status == -EINPROGRESS)
345 urb->status = cc_to_error[cc];
346 if (ep->nextpid == USB_PID_ACK)
347 ep->nextpid = 0;
348 spin_unlock(&urb->lock);
349 continue;
350 }
351 /* According to usb spec, zero-length Int transfer signals
352 finishing of the urb. Hey, does this apply only
353 for IN endpoints? */
354 if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) {
355 if (urb->status == -EINPROGRESS)
356 urb->status = 0;
357 spin_unlock(&urb->lock);
358 continue;
359 }
360
361 /* Relax after previously failed, but later succeeded
362 or correctly NAK'ed retransmission attempt */
363 if (ep->error_count
364 && (cc == TD_CC_NOERROR || cc == TD_NOTACCESSED))
365 ep->error_count = 0;
366
367 /* Take into account idiosyncracies of the isp116x chip
368 regarding toggle bit for failed transfers */
369 if (ep->nextpid == USB_PID_OUT)
370 usb_settoggle(udev, ep->epnum, 1, PTD_GET_TOGGLE(ptd)
371 ^ (ep->error_count > 0));
372 else if (ep->nextpid == USB_PID_IN)
373 usb_settoggle(udev, ep->epnum, 0, PTD_GET_TOGGLE(ptd)
374 ^ (ep->error_count > 0));
375
376 switch (ep->nextpid) {
377 case USB_PID_IN:
378 case USB_PID_OUT:
379 urb->actual_length += PTD_GET_COUNT(ptd);
380 if (PTD_GET_ACTIVE(ptd)
381 || (cc != TD_CC_NOERROR && cc < 0x0E))
382 break;
383 if (urb->transfer_buffer_length != urb->actual_length) {
384 if (short_not_ok)
385 break;
386 } else {
387 if (urb->transfer_flags & URB_ZERO_PACKET
388 && ep->nextpid == USB_PID_OUT
389 && !(PTD_GET_COUNT(ptd) % ep->maxpacket)) {
390 DBG("Zero packet requested\n");
391 break;
392 }
393 }
394 /* All data for this URB is transferred, let's finish */
395 if (usb_pipecontrol(urb->pipe))
396 ep->nextpid = USB_PID_ACK;
397 else if (urb->status == -EINPROGRESS)
398 urb->status = 0;
399 break;
400 case USB_PID_SETUP:
401 if (PTD_GET_ACTIVE(ptd)
402 || (cc != TD_CC_NOERROR && cc < 0x0E))
403 break;
404 if (urb->transfer_buffer_length == urb->actual_length)
405 ep->nextpid = USB_PID_ACK;
406 else if (usb_pipeout(urb->pipe)) {
407 usb_settoggle(udev, 0, 1, 1);
408 ep->nextpid = USB_PID_OUT;
409 } else {
410 usb_settoggle(udev, 0, 0, 1);
411 ep->nextpid = USB_PID_IN;
412 }
413 break;
414 case USB_PID_ACK:
415 if (PTD_GET_ACTIVE(ptd)
416 || (cc != TD_CC_NOERROR && cc < 0x0E))
417 break;
418 if (urb->status == -EINPROGRESS)
419 urb->status = 0;
420 ep->nextpid = 0;
421 break;
422 default:
423 BUG_ON(1);
424 }
425 spin_unlock(&urb->lock);
426 }
427}
428
429/*
430 Take done or failed requests out of schedule. Give back
431 processed urbs.
432*/
433static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep,
434 struct urb *urb, struct pt_regs *regs)
435__releases(isp116x->lock) __acquires(isp116x->lock)
436{
437 unsigned i;
438
439 urb->hcpriv = NULL;
440 ep->error_count = 0;
441
442 if (usb_pipecontrol(urb->pipe))
443 ep->nextpid = USB_PID_SETUP;
444
445 urb_dbg(urb, "Finish");
446
447 spin_unlock(&isp116x->lock);
448 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb, regs);
449 spin_lock(&isp116x->lock);
450
451 /* take idle endpoints out of the schedule */
452 if (!list_empty(&ep->hep->urb_list))
453 return;
454
455 /* async deschedule */
456 if (!list_empty(&ep->schedule)) {
457 list_del_init(&ep->schedule);
458 return;
459 }
460
461 /* periodic deschedule */
462 DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
463 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
464 struct isp116x_ep *temp;
465 struct isp116x_ep **prev = &isp116x->periodic[i];
466
467 while (*prev && ((temp = *prev) != ep))
468 prev = &temp->next;
469 if (*prev)
470 *prev = ep->next;
471 isp116x->load[i] -= ep->load;
472 }
473 ep->branch = PERIODIC_SIZE;
474 isp116x_to_hcd(isp116x)->self.bandwidth_allocated -=
475 ep->load / ep->period;
476
477 /* switch irq type? */
478 if (!--isp116x->periodic_count) {
479 isp116x->irqenb &= ~HCuPINT_SOF;
480 isp116x->irqenb |= HCuPINT_ATL;
481 }
482}
483
484/*
485 Scan transfer lists, schedule transfers, send data off
486 to chip.
487 */
488static void start_atl_transfers(struct isp116x *isp116x)
489{
490 struct isp116x_ep *last_ep = NULL, *ep;
491 struct urb *urb;
492 u16 load = 0;
493 int len, index, speed, byte_time;
494
495 if (atomic_read(&isp116x->atl_finishing))
496 return;
497
498 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state))
499 return;
500
501 /* FIFO not empty? */
502 if (isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_FULL)
503 return;
504
505 isp116x->atl_active = NULL;
506 isp116x->atl_buflen = isp116x->atl_bufshrt = 0;
507
508 /* Schedule int transfers */
509 if (isp116x->periodic_count) {
510 isp116x->fmindex = index =
511 (isp116x->fmindex + 1) & (PERIODIC_SIZE - 1);
512 if ((load = isp116x->load[index])) {
513 /* Bring all int transfers for this frame
514 into the active queue */
515 isp116x->atl_active = last_ep =
516 isp116x->periodic[index];
517 while (last_ep->next)
518 last_ep = (last_ep->active = last_ep->next);
519 last_ep->active = NULL;
520 }
521 }
522
523 /* Schedule control/bulk transfers */
524 list_for_each_entry(ep, &isp116x->async, schedule) {
525 urb = container_of(ep->hep->urb_list.next,
526 struct urb, urb_list);
527 speed = urb->dev->speed;
528 byte_time = speed == USB_SPEED_LOW
529 ? BYTE_TIME_LOWSPEED : BYTE_TIME_FULLSPEED;
530
531 if (ep->nextpid == USB_PID_SETUP) {
532 len = sizeof(struct usb_ctrlrequest);
533 } else if (ep->nextpid == USB_PID_ACK) {
534 len = 0;
535 } else {
536 /* Find current free length ... */
537 len = (MAX_LOAD_LIMIT - load) / byte_time;
538
539 /* ... then limit it to configured max size ... */
540 len = min(len, speed == USB_SPEED_LOW ?
541 MAX_TRANSFER_SIZE_LOWSPEED :
542 MAX_TRANSFER_SIZE_FULLSPEED);
543
544 /* ... and finally cut to the multiple of MaxPacketSize,
545 or to the real length if there's enough room. */
546 if (len <
547 (urb->transfer_buffer_length -
548 urb->actual_length)) {
549 len -= len % ep->maxpacket;
550 if (!len)
551 continue;
552 } else
553 len = urb->transfer_buffer_length -
554 urb->actual_length;
555 BUG_ON(len < 0);
556 }
557
558 load += len * byte_time;
559 if (load > MAX_LOAD_LIMIT)
560 break;
561
562 ep->active = NULL;
563 ep->length = len;
564 if (last_ep)
565 last_ep->active = ep;
566 else
567 isp116x->atl_active = ep;
568 last_ep = ep;
569 }
570
571 /* Avoid starving of endpoints */
572 if ((&isp116x->async)->next != (&isp116x->async)->prev)
573 list_move(&isp116x->async, (&isp116x->async)->next);
574
575 if (isp116x->atl_active) {
576 preproc_atl_queue(isp116x);
577 pack_fifo(isp116x);
578 }
579}
580
581/*
582 Finish the processed transfers
583*/
584static void finish_atl_transfers(struct isp116x *isp116x, struct pt_regs *regs)
585{
586 struct isp116x_ep *ep;
587 struct urb *urb;
588
589 if (!isp116x->atl_active)
590 return;
591 /* Fifo not ready? */
592 if (!(isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_DONE))
593 return;
594
595 atomic_inc(&isp116x->atl_finishing);
596 unpack_fifo(isp116x);
597 postproc_atl_queue(isp116x);
598 for (ep = isp116x->atl_active; ep; ep = ep->active) {
599 urb =
600 container_of(ep->hep->urb_list.next, struct urb, urb_list);
601 /* USB_PID_ACK check here avoids finishing of
602 control transfers, for which TD_DATAUNDERRUN
603 occured, while URB_SHORT_NOT_OK was set */
604 if (urb && urb->status != -EINPROGRESS
605 && ep->nextpid != USB_PID_ACK)
606 finish_request(isp116x, ep, urb, regs);
607 }
608 atomic_dec(&isp116x->atl_finishing);
609}
610
611static irqreturn_t isp116x_irq(struct usb_hcd *hcd, struct pt_regs *regs)
612{
613 struct isp116x *isp116x = hcd_to_isp116x(hcd);
614 u16 irqstat;
615 irqreturn_t ret = IRQ_NONE;
616
617 spin_lock(&isp116x->lock);
618 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
619 irqstat = isp116x_read_reg16(isp116x, HCuPINT);
620 isp116x_write_reg16(isp116x, HCuPINT, irqstat);
621
622 if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
623 ret = IRQ_HANDLED;
624 finish_atl_transfers(isp116x, regs);
625 }
626
627 if (irqstat & HCuPINT_OPR) {
628 u32 intstat = isp116x_read_reg32(isp116x, HCINTSTAT);
629 isp116x_write_reg32(isp116x, HCINTSTAT, intstat);
630 if (intstat & HCINT_UE) {
631 ERR("Unrecoverable error\n");
632 /* What should we do here? Reset? */
633 }
634 if (intstat & HCINT_RHSC) {
635 isp116x->rhstatus =
636 isp116x_read_reg32(isp116x, HCRHSTATUS);
637 isp116x->rhport[0] =
638 isp116x_read_reg32(isp116x, HCRHPORT1);
639 isp116x->rhport[1] =
640 isp116x_read_reg32(isp116x, HCRHPORT2);
641 }
642 if (intstat & HCINT_RD) {
643 DBG("---- remote wakeup\n");
644 schedule_work(&isp116x->rh_resume);
645 ret = IRQ_HANDLED;
646 }
647 irqstat &= ~HCuPINT_OPR;
648 ret = IRQ_HANDLED;
649 }
650
651 if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
652 start_atl_transfers(isp116x);
653 }
654
655 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
656 spin_unlock(&isp116x->lock);
657 return ret;
658}
659
660/*-----------------------------------------------------------------*/
661
662/* usb 1.1 says max 90% of a frame is available for periodic transfers.
663 * this driver doesn't promise that much since it's got to handle an
664 * IRQ per packet; irq handling latencies also use up that time.
665 */
666
667/* out of 1000 us */
668#define MAX_PERIODIC_LOAD 600
669static int balance(struct isp116x *isp116x, u16 period, u16 load)
670{
671 int i, branch = -ENOSPC;
672
673 /* search for the least loaded schedule branch of that period
674 which has enough bandwidth left unreserved. */
675 for (i = 0; i < period; i++) {
676 if (branch < 0 || isp116x->load[branch] > isp116x->load[i]) {
677 int j;
678
679 for (j = i; j < PERIODIC_SIZE; j += period) {
680 if ((isp116x->load[j] + load)
681 > MAX_PERIODIC_LOAD)
682 break;
683 }
684 if (j < PERIODIC_SIZE)
685 continue;
686 branch = i;
687 }
688 }
689 return branch;
690}
691
692/* NB! ALL the code above this point runs with isp116x->lock
693 held, irqs off
694*/
695
696/*-----------------------------------------------------------------*/
697
698static int isp116x_urb_enqueue(struct usb_hcd *hcd,
699 struct usb_host_endpoint *hep, struct urb *urb,
700 int mem_flags)
701{
702 struct isp116x *isp116x = hcd_to_isp116x(hcd);
703 struct usb_device *udev = urb->dev;
704 unsigned int pipe = urb->pipe;
705 int is_out = !usb_pipein(pipe);
706 int type = usb_pipetype(pipe);
707 int epnum = usb_pipeendpoint(pipe);
708 struct isp116x_ep *ep = NULL;
709 unsigned long flags;
710 int i;
711 int ret = 0;
712
713 urb_dbg(urb, "Enqueue");
714
715 if (type == PIPE_ISOCHRONOUS) {
716 ERR("Isochronous transfers not supported\n");
717 urb_dbg(urb, "Refused to enqueue");
718 return -ENXIO;
719 }
720 /* avoid all allocations within spinlocks: request or endpoint */
721 if (!hep->hcpriv) {
722 ep = kcalloc(1, sizeof *ep, (__force unsigned)mem_flags);
723 if (!ep)
724 return -ENOMEM;
725 }
726
727 spin_lock_irqsave(&isp116x->lock, flags);
728 if (!HC_IS_RUNNING(hcd->state)) {
729 ret = -ENODEV;
730 goto fail;
731 }
732
733 if (hep->hcpriv)
734 ep = hep->hcpriv;
735 else {
736 INIT_LIST_HEAD(&ep->schedule);
737 ep->udev = usb_get_dev(udev);
738 ep->epnum = epnum;
739 ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
740 usb_settoggle(udev, epnum, is_out, 0);
741
742 if (type == PIPE_CONTROL) {
743 ep->nextpid = USB_PID_SETUP;
744 } else if (is_out) {
745 ep->nextpid = USB_PID_OUT;
746 } else {
747 ep->nextpid = USB_PID_IN;
748 }
749
750 if (urb->interval) {
751 /*
752 With INT URBs submitted, the driver works with SOF
753 interrupt enabled and ATL interrupt disabled. After
754 the PTDs are written to fifo ram, the chip starts
755 fifo processing and usb transfers after the next
756 SOF and continues until the transfers are finished
757 (succeeded or failed) or the frame ends. Therefore,
758 the transfers occur only in every second frame,
759 while fifo reading/writing and data processing
760 occur in every other second frame. */
761 if (urb->interval < 2)
762 urb->interval = 2;
763 if (urb->interval > 2 * PERIODIC_SIZE)
764 urb->interval = 2 * PERIODIC_SIZE;
765 ep->period = urb->interval >> 1;
766 ep->branch = PERIODIC_SIZE;
767 ep->load = usb_calc_bus_time(udev->speed,
768 !is_out,
769 (type == PIPE_ISOCHRONOUS),
770 usb_maxpacket(udev, pipe,
771 is_out)) /
772 1000;
773 }
774 hep->hcpriv = ep;
775 ep->hep = hep;
776 }
777
778 /* maybe put endpoint into schedule */
779 switch (type) {
780 case PIPE_CONTROL:
781 case PIPE_BULK:
782 if (list_empty(&ep->schedule))
783 list_add_tail(&ep->schedule, &isp116x->async);
784 break;
785 case PIPE_INTERRUPT:
786 urb->interval = ep->period;
787 ep->length = min((int)ep->maxpacket,
788 urb->transfer_buffer_length);
789
790 /* urb submitted for already existing endpoint */
791 if (ep->branch < PERIODIC_SIZE)
792 break;
793
794 ret = ep->branch = balance(isp116x, ep->period, ep->load);
795 if (ret < 0)
796 goto fail;
797 ret = 0;
798
799 urb->start_frame = (isp116x->fmindex & (PERIODIC_SIZE - 1))
800 + ep->branch;
801
802 /* sort each schedule branch by period (slow before fast)
803 to share the faster parts of the tree without needing
804 dummy/placeholder nodes */
805 DBG("schedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
806 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
807 struct isp116x_ep **prev = &isp116x->periodic[i];
808 struct isp116x_ep *here = *prev;
809
810 while (here && ep != here) {
811 if (ep->period > here->period)
812 break;
813 prev = &here->next;
814 here = *prev;
815 }
816 if (ep != here) {
817 ep->next = here;
818 *prev = ep;
819 }
820 isp116x->load[i] += ep->load;
821 }
822 hcd->self.bandwidth_allocated += ep->load / ep->period;
823
824 /* switch over to SOFint */
825 if (!isp116x->periodic_count++) {
826 isp116x->irqenb &= ~HCuPINT_ATL;
827 isp116x->irqenb |= HCuPINT_SOF;
828 isp116x_write_reg16(isp116x, HCuPINTENB,
829 isp116x->irqenb);
830 }
831 }
832
833 /* in case of unlink-during-submit */
834 spin_lock(&urb->lock);
835 if (urb->status != -EINPROGRESS) {
836 spin_unlock(&urb->lock);
837 finish_request(isp116x, ep, urb, NULL);
838 ret = 0;
839 goto fail;
840 }
841 urb->hcpriv = hep;
842 spin_unlock(&urb->lock);
843 start_atl_transfers(isp116x);
844
845 fail:
846 spin_unlock_irqrestore(&isp116x->lock, flags);
847 return ret;
848}
849
850/*
851 Dequeue URBs.
852*/
853static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
854{
855 struct isp116x *isp116x = hcd_to_isp116x(hcd);
856 struct usb_host_endpoint *hep;
857 struct isp116x_ep *ep, *ep_act;
858 unsigned long flags;
859
860 spin_lock_irqsave(&isp116x->lock, flags);
861 hep = urb->hcpriv;
862 /* URB already unlinked (or never linked)? */
863 if (!hep) {
864 spin_unlock_irqrestore(&isp116x->lock, flags);
865 return 0;
866 }
867 ep = hep->hcpriv;
868 WARN_ON(hep != ep->hep);
869
870 /* In front of queue? */
871 if (ep->hep->urb_list.next == &urb->urb_list)
872 /* active? */
873 for (ep_act = isp116x->atl_active; ep_act;
874 ep_act = ep_act->active)
875 if (ep_act == ep) {
876 VDBG("dequeue, urb %p active; wait for irq\n",
877 urb);
878 urb = NULL;
879 break;
880 }
881
882 if (urb)
883 finish_request(isp116x, ep, urb, NULL);
884
885 spin_unlock_irqrestore(&isp116x->lock, flags);
886 return 0;
887}
888
889static void isp116x_endpoint_disable(struct usb_hcd *hcd,
890 struct usb_host_endpoint *hep)
891{
892 int i;
893 struct isp116x_ep *ep = hep->hcpriv;;
894
895 if (!ep)
896 return;
897
898 /* assume we'd just wait for the irq */
899 for (i = 0; i < 100 && !list_empty(&hep->urb_list); i++)
900 msleep(3);
901 if (!list_empty(&hep->urb_list))
902 WARN("ep %p not empty?\n", ep);
903
904 usb_put_dev(ep->udev);
905 kfree(ep);
906 hep->hcpriv = NULL;
907}
908
909static int isp116x_get_frame(struct usb_hcd *hcd)
910{
911 struct isp116x *isp116x = hcd_to_isp116x(hcd);
912 u32 fmnum;
913 unsigned long flags;
914
915 spin_lock_irqsave(&isp116x->lock, flags);
916 fmnum = isp116x_read_reg32(isp116x, HCFMNUM);
917 spin_unlock_irqrestore(&isp116x->lock, flags);
918 return (int)fmnum;
919}
920
921/*----------------------------------------------------------------*/
922
923/*
924 Adapted from ohci-hub.c. Currently we don't support autosuspend.
925*/
926static int isp116x_hub_status_data(struct usb_hcd *hcd, char *buf)
927{
928 struct isp116x *isp116x = hcd_to_isp116x(hcd);
929 int ports, i, changed = 0;
930
931 if (!HC_IS_RUNNING(hcd->state))
932 return -ESHUTDOWN;
933
934 ports = isp116x->rhdesca & RH_A_NDP;
935
936 /* init status */
937 if (isp116x->rhstatus & (RH_HS_LPSC | RH_HS_OCIC))
938 buf[0] = changed = 1;
939 else
940 buf[0] = 0;
941
942 for (i = 0; i < ports; i++) {
943 u32 status = isp116x->rhport[i];
944
945 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
946 | RH_PS_OCIC | RH_PS_PRSC)) {
947 changed = 1;
948 buf[0] |= 1 << (i + 1);
949 continue;
950 }
951 }
952 return changed;
953}
954
955static void isp116x_hub_descriptor(struct isp116x *isp116x,
956 struct usb_hub_descriptor *desc)
957{
958 u32 reg = isp116x->rhdesca;
959
960 desc->bDescriptorType = 0x29;
961 desc->bDescLength = 9;
962 desc->bHubContrCurrent = 0;
963 desc->bNbrPorts = (u8) (reg & 0x3);
964 /* Power switching, device type, overcurrent. */
965 desc->wHubCharacteristics =
966 (__force __u16) cpu_to_le16((u16) ((reg >> 8) & 0x1f));
967 desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff);
968 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
969 desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1;
970 desc->bitmap[1] = ~0;
971}
972
973/* Perform reset of a given port.
974 It would be great to just start the reset and let the
975 USB core to clear the reset in due time. However,
976 root hub ports should be reset for at least 50 ms, while
977 our chip stays in reset for about 10 ms. I.e., we must
978 repeatedly reset it ourself here.
979*/
980static inline void root_port_reset(struct isp116x *isp116x, unsigned port)
981{
982 u32 tmp;
983 unsigned long flags, t;
984
985 /* Root hub reset should be 50 ms, but some devices
986 want it even longer. */
987 t = jiffies + msecs_to_jiffies(100);
988
989 while (time_before(jiffies, t)) {
990 spin_lock_irqsave(&isp116x->lock, flags);
991 /* spin until any current reset finishes */
992 for (;;) {
993 tmp = isp116x_read_reg32(isp116x, port ?
994 HCRHPORT2 : HCRHPORT1);
995 if (!(tmp & RH_PS_PRS))
996 break;
997 udelay(500);
998 }
999 /* Don't reset a disconnected port */
1000 if (!(tmp & RH_PS_CCS)) {
1001 spin_unlock_irqrestore(&isp116x->lock, flags);
1002 break;
1003 }
1004 /* Reset lasts 10ms (claims datasheet) */
1005 isp116x_write_reg32(isp116x, port ? HCRHPORT2 :
1006 HCRHPORT1, (RH_PS_PRS));
1007 spin_unlock_irqrestore(&isp116x->lock, flags);
1008 msleep(10);
1009 }
1010}
1011
1012/* Adapted from ohci-hub.c */
1013static int isp116x_hub_control(struct usb_hcd *hcd,
1014 u16 typeReq,
1015 u16 wValue, u16 wIndex, char *buf, u16 wLength)
1016{
1017 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1018 int ret = 0;
1019 unsigned long flags;
1020 int ports = isp116x->rhdesca & RH_A_NDP;
1021 u32 tmp = 0;
1022
1023 switch (typeReq) {
1024 case ClearHubFeature:
1025 DBG("ClearHubFeature: ");
1026 switch (wValue) {
1027 case C_HUB_OVER_CURRENT:
1028 DBG("C_HUB_OVER_CURRENT\n");
1029 spin_lock_irqsave(&isp116x->lock, flags);
1030 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_OCIC);
1031 spin_unlock_irqrestore(&isp116x->lock, flags);
1032 case C_HUB_LOCAL_POWER:
1033 DBG("C_HUB_LOCAL_POWER\n");
1034 break;
1035 default:
1036 goto error;
1037 }
1038 break;
1039 case SetHubFeature:
1040 DBG("SetHubFeature: ");
1041 switch (wValue) {
1042 case C_HUB_OVER_CURRENT:
1043 case C_HUB_LOCAL_POWER:
1044 DBG("C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
1045 break;
1046 default:
1047 goto error;
1048 }
1049 break;
1050 case GetHubDescriptor:
1051 DBG("GetHubDescriptor\n");
1052 isp116x_hub_descriptor(isp116x,
1053 (struct usb_hub_descriptor *)buf);
1054 break;
1055 case GetHubStatus:
1056 DBG("GetHubStatus\n");
1057 *(__le32 *) buf = cpu_to_le32(0);
1058 break;
1059 case GetPortStatus:
1060 DBG("GetPortStatus\n");
1061 if (!wIndex || wIndex > ports)
1062 goto error;
1063 tmp = isp116x->rhport[--wIndex];
1064 *(__le32 *) buf = cpu_to_le32(tmp);
1065 DBG("GetPortStatus: port[%d] %08x\n", wIndex + 1, tmp);
1066 break;
1067 case ClearPortFeature:
1068 DBG("ClearPortFeature: ");
1069 if (!wIndex || wIndex > ports)
1070 goto error;
1071 wIndex--;
1072
1073 switch (wValue) {
1074 case USB_PORT_FEAT_ENABLE:
1075 DBG("USB_PORT_FEAT_ENABLE\n");
1076 tmp = RH_PS_CCS;
1077 break;
1078 case USB_PORT_FEAT_C_ENABLE:
1079 DBG("USB_PORT_FEAT_C_ENABLE\n");
1080 tmp = RH_PS_PESC;
1081 break;
1082 case USB_PORT_FEAT_SUSPEND:
1083 DBG("USB_PORT_FEAT_SUSPEND\n");
1084 tmp = RH_PS_POCI;
1085 break;
1086 case USB_PORT_FEAT_C_SUSPEND:
1087 DBG("USB_PORT_FEAT_C_SUSPEND\n");
1088 tmp = RH_PS_PSSC;
1089 break;
1090 case USB_PORT_FEAT_POWER:
1091 DBG("USB_PORT_FEAT_POWER\n");
1092 tmp = RH_PS_LSDA;
1093 break;
1094 case USB_PORT_FEAT_C_CONNECTION:
1095 DBG("USB_PORT_FEAT_C_CONNECTION\n");
1096 tmp = RH_PS_CSC;
1097 break;
1098 case USB_PORT_FEAT_C_OVER_CURRENT:
1099 DBG("USB_PORT_FEAT_C_OVER_CURRENT\n");
1100 tmp = RH_PS_OCIC;
1101 break;
1102 case USB_PORT_FEAT_C_RESET:
1103 DBG("USB_PORT_FEAT_C_RESET\n");
1104 tmp = RH_PS_PRSC;
1105 break;
1106 default:
1107 goto error;
1108 }
1109 spin_lock_irqsave(&isp116x->lock, flags);
1110 isp116x_write_reg32(isp116x, wIndex
1111 ? HCRHPORT2 : HCRHPORT1, tmp);
1112 isp116x->rhport[wIndex] =
1113 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1114 spin_unlock_irqrestore(&isp116x->lock, flags);
1115 break;
1116 case SetPortFeature:
1117 DBG("SetPortFeature: ");
1118 if (!wIndex || wIndex > ports)
1119 goto error;
1120 wIndex--;
1121 switch (wValue) {
1122 case USB_PORT_FEAT_SUSPEND:
1123 DBG("USB_PORT_FEAT_SUSPEND\n");
1124 spin_lock_irqsave(&isp116x->lock, flags);
1125 isp116x_write_reg32(isp116x, wIndex
1126 ? HCRHPORT2 : HCRHPORT1, RH_PS_PSS);
1127 break;
1128 case USB_PORT_FEAT_POWER:
1129 DBG("USB_PORT_FEAT_POWER\n");
1130 spin_lock_irqsave(&isp116x->lock, flags);
1131 isp116x_write_reg32(isp116x, wIndex
1132 ? HCRHPORT2 : HCRHPORT1, RH_PS_PPS);
1133 break;
1134 case USB_PORT_FEAT_RESET:
1135 DBG("USB_PORT_FEAT_RESET\n");
1136 root_port_reset(isp116x, wIndex);
1137 spin_lock_irqsave(&isp116x->lock, flags);
1138 break;
1139 default:
1140 goto error;
1141 }
1142 isp116x->rhport[wIndex] =
1143 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1144 spin_unlock_irqrestore(&isp116x->lock, flags);
1145 break;
1146
1147 default:
1148 error:
1149 /* "protocol stall" on error */
1150 DBG("PROTOCOL STALL\n");
1151 ret = -EPIPE;
1152 }
1153 return ret;
1154}
1155
1156#ifdef CONFIG_PM
1157
1158static int isp116x_hub_suspend(struct usb_hcd *hcd)
1159{
1160 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1161 unsigned long flags;
1162 u32 val;
1163 int ret = 0;
1164
1165 spin_lock_irqsave(&isp116x->lock, flags);
1166
1167 val = isp116x_read_reg32(isp116x, HCCONTROL);
1168 switch (val & HCCONTROL_HCFS) {
1169 case HCCONTROL_USB_OPER:
1170 hcd->state = HC_STATE_QUIESCING;
1171 val &= (~HCCONTROL_HCFS & ~HCCONTROL_RWE);
1172 val |= HCCONTROL_USB_SUSPEND;
1173 if (hcd->remote_wakeup)
1174 val |= HCCONTROL_RWE;
1175 /* Wait for usb transfers to finish */
1176 mdelay(2);
1177 isp116x_write_reg32(isp116x, HCCONTROL, val);
1178 hcd->state = HC_STATE_SUSPENDED;
1179 /* Wait for devices to suspend */
1180 mdelay(5);
1181 case HCCONTROL_USB_SUSPEND:
1182 break;
1183 case HCCONTROL_USB_RESUME:
1184 isp116x_write_reg32(isp116x, HCCONTROL,
1185 (val & ~HCCONTROL_HCFS) |
1186 HCCONTROL_USB_RESET);
1187 case HCCONTROL_USB_RESET:
1188 ret = -EBUSY;
1189 break;
1190 default:
1191 ret = -EINVAL;
1192 }
1193
1194 spin_unlock_irqrestore(&isp116x->lock, flags);
1195 return ret;
1196}
1197
1198static int isp116x_hub_resume(struct usb_hcd *hcd)
1199{
1200 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1201 u32 val;
1202 int ret = -EINPROGRESS;
1203
1204 msleep(5);
1205 spin_lock_irq(&isp116x->lock);
1206
1207 val = isp116x_read_reg32(isp116x, HCCONTROL);
1208 switch (val & HCCONTROL_HCFS) {
1209 case HCCONTROL_USB_SUSPEND:
1210 val &= ~HCCONTROL_HCFS;
1211 val |= HCCONTROL_USB_RESUME;
1212 isp116x_write_reg32(isp116x, HCCONTROL, val);
1213 case HCCONTROL_USB_RESUME:
1214 break;
1215 case HCCONTROL_USB_OPER:
1216 /* Without setting power_state here the
1217 SUSPENDED state won't be removed from
1218 sysfs/usbN/power.state as a response to remote
1219 wakeup. Maybe in the future. */
1220 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1221 ret = 0;
1222 break;
1223 default:
1224 ret = -EBUSY;
1225 }
1226
1227 if (ret != -EINPROGRESS) {
1228 spin_unlock_irq(&isp116x->lock);
1229 return ret;
1230 }
1231
1232 val = isp116x->rhdesca & RH_A_NDP;
1233 while (val--) {
1234 u32 stat =
1235 isp116x_read_reg32(isp116x, val ? HCRHPORT2 : HCRHPORT1);
1236 /* force global, not selective, resume */
1237 if (!(stat & RH_PS_PSS))
1238 continue;
1239 DBG("%s: Resuming port %d\n", __func__, val);
1240 isp116x_write_reg32(isp116x, RH_PS_POCI, val
1241 ? HCRHPORT2 : HCRHPORT1);
1242 }
1243 spin_unlock_irq(&isp116x->lock);
1244
1245 hcd->state = HC_STATE_RESUMING;
1246 mdelay(20);
1247
1248 /* Go operational */
1249 spin_lock_irq(&isp116x->lock);
1250 val = isp116x_read_reg32(isp116x, HCCONTROL);
1251 isp116x_write_reg32(isp116x, HCCONTROL,
1252 (val & ~HCCONTROL_HCFS) | HCCONTROL_USB_OPER);
1253 spin_unlock_irq(&isp116x->lock);
1254 /* see analogous comment above */
1255 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1256 hcd->state = HC_STATE_RUNNING;
1257
1258 return 0;
1259}
1260
1261static void isp116x_rh_resume(void *_hcd)
1262{
1263 struct usb_hcd *hcd = _hcd;
1264
1265 usb_resume_device(hcd->self.root_hub);
1266}
1267
1268#else
1269
1270#define isp116x_hub_suspend NULL
1271#define isp116x_hub_resume NULL
1272
1273static void isp116x_rh_resume(void *_hcd)
1274{
1275}
1276
1277#endif
1278
1279/*-----------------------------------------------------------------*/
1280
1281#ifdef STUB_DEBUG_FILE
1282
1283static inline void create_debug_file(struct isp116x *isp116x)
1284{
1285}
1286
1287static inline void remove_debug_file(struct isp116x *isp116x)
1288{
1289}
1290
1291#else
1292
1293#include <linux/proc_fs.h>
1294#include <linux/seq_file.h>
1295
1296static void dump_irq(struct seq_file *s, char *label, u16 mask)
1297{
1298 seq_printf(s, "%s %04x%s%s%s%s%s%s\n", label, mask,
1299 mask & HCuPINT_CLKRDY ? " clkrdy" : "",
1300 mask & HCuPINT_SUSP ? " susp" : "",
1301 mask & HCuPINT_OPR ? " opr" : "",
1302 mask & HCuPINT_AIIEOT ? " eot" : "",
1303 mask & HCuPINT_ATL ? " atl" : "",
1304 mask & HCuPINT_SOF ? " sof" : "");
1305}
1306
1307static void dump_int(struct seq_file *s, char *label, u32 mask)
1308{
1309 seq_printf(s, "%s %08x%s%s%s%s%s%s%s\n", label, mask,
1310 mask & HCINT_MIE ? " MIE" : "",
1311 mask & HCINT_RHSC ? " rhsc" : "",
1312 mask & HCINT_FNO ? " fno" : "",
1313 mask & HCINT_UE ? " ue" : "",
1314 mask & HCINT_RD ? " rd" : "",
1315 mask & HCINT_SF ? " sof" : "", mask & HCINT_SO ? " so" : "");
1316}
1317
1318static int proc_isp116x_show(struct seq_file *s, void *unused)
1319{
1320 struct isp116x *isp116x = s->private;
1321 struct isp116x_ep *ep;
1322 struct urb *urb;
1323 unsigned i;
1324 char *str;
1325
1326 seq_printf(s, "%s\n%s version %s\n",
1327 isp116x_to_hcd(isp116x)->product_desc, hcd_name,
1328 DRIVER_VERSION);
1329
1330 if (HC_IS_SUSPENDED(isp116x_to_hcd(isp116x)->state)) {
1331 seq_printf(s, "HCD is suspended\n");
1332 return 0;
1333 }
1334 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state)) {
1335 seq_printf(s, "HCD not running\n");
1336 return 0;
1337 }
1338
1339 spin_lock_irq(&isp116x->lock);
1340
1341 dump_irq(s, "hc_irq_enable", isp116x_read_reg16(isp116x, HCuPINTENB));
1342 dump_irq(s, "hc_irq_status", isp116x_read_reg16(isp116x, HCuPINT));
1343 dump_int(s, "hc_int_enable", isp116x_read_reg32(isp116x, HCINTENB));
1344 dump_int(s, "hc_int_status", isp116x_read_reg32(isp116x, HCINTSTAT));
1345
1346 list_for_each_entry(ep, &isp116x->async, schedule) {
1347
1348 switch (ep->nextpid) {
1349 case USB_PID_IN:
1350 str = "in";
1351 break;
1352 case USB_PID_OUT:
1353 str = "out";
1354 break;
1355 case USB_PID_SETUP:
1356 str = "setup";
1357 break;
1358 case USB_PID_ACK:
1359 str = "status";
1360 break;
1361 default:
1362 str = "?";
1363 break;
1364 };
1365 seq_printf(s, "%p, ep%d%s, maxpacket %d:\n", ep,
1366 ep->epnum, str, ep->maxpacket);
1367 list_for_each_entry(urb, &ep->hep->urb_list, urb_list) {
1368 seq_printf(s, " urb%p, %d/%d\n", urb,
1369 urb->actual_length,
1370 urb->transfer_buffer_length);
1371 }
1372 }
1373 if (!list_empty(&isp116x->async))
1374 seq_printf(s, "\n");
1375
1376 seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
1377
1378 for (i = 0; i < PERIODIC_SIZE; i++) {
1379 ep = isp116x->periodic[i];
1380 if (!ep)
1381 continue;
1382 seq_printf(s, "%2d [%3d]:\n", i, isp116x->load[i]);
1383
1384 /* DUMB: prints shared entries multiple times */
1385 do {
1386 seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n",
1387 ep->period, ep,
1388 (ep->udev->speed ==
1389 USB_SPEED_FULL) ? "" : "ls ",
1390 ep->udev->devnum, ep->epnum,
1391 (ep->epnum ==
1392 0) ? "" : ((ep->nextpid ==
1393 USB_PID_IN) ? "in" : "out"),
1394 ep->maxpacket);
1395 ep = ep->next;
1396 } while (ep);
1397 }
1398 spin_unlock_irq(&isp116x->lock);
1399 seq_printf(s, "\n");
1400
1401 return 0;
1402}
1403
1404static int proc_isp116x_open(struct inode *inode, struct file *file)
1405{
1406 return single_open(file, proc_isp116x_show, PDE(inode)->data);
1407}
1408
1409static struct file_operations proc_ops = {
1410 .open = proc_isp116x_open,
1411 .read = seq_read,
1412 .llseek = seq_lseek,
1413 .release = single_release,
1414};
1415
1416/* expect just one isp116x per system */
1417static const char proc_filename[] = "driver/isp116x";
1418
1419static void create_debug_file(struct isp116x *isp116x)
1420{
1421 struct proc_dir_entry *pde;
1422
1423 pde = create_proc_entry(proc_filename, 0, NULL);
1424 if (pde == NULL)
1425 return;
1426
1427 pde->proc_fops = &proc_ops;
1428 pde->data = isp116x;
1429 isp116x->pde = pde;
1430}
1431
1432static void remove_debug_file(struct isp116x *isp116x)
1433{
1434 if (isp116x->pde)
1435 remove_proc_entry(proc_filename, NULL);
1436}
1437
1438#endif
1439
1440/*-----------------------------------------------------------------*/
1441
1442/*
1443 Software reset - can be called from any contect.
1444*/
1445static int isp116x_sw_reset(struct isp116x *isp116x)
1446{
1447 int retries = 15;
1448 unsigned long flags;
1449 int ret = 0;
1450
1451 spin_lock_irqsave(&isp116x->lock, flags);
1452 isp116x_write_reg16(isp116x, HCSWRES, HCSWRES_MAGIC);
1453 isp116x_write_reg32(isp116x, HCCMDSTAT, HCCMDSTAT_HCR);
1454 while (--retries) {
1455 /* It usually resets within 1 ms */
1456 mdelay(1);
1457 if (!(isp116x_read_reg32(isp116x, HCCMDSTAT) & HCCMDSTAT_HCR))
1458 break;
1459 }
1460 if (!retries) {
1461 ERR("Software reset timeout\n");
1462 ret = -ETIME;
1463 }
1464 spin_unlock_irqrestore(&isp116x->lock, flags);
1465 return ret;
1466}
1467
1468/*
1469 Reset. Tries to perform platform-specific hardware
1470 reset first; falls back to software reset.
1471*/
1472static int isp116x_reset(struct usb_hcd *hcd)
1473{
1474 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1475 unsigned long t;
1476 u16 clkrdy = 0;
1477 int ret = 0, timeout = 15 /* ms */ ;
1478
1479 if (isp116x->board && isp116x->board->reset) {
1480 /* Hardware reset */
1481 isp116x->board->reset(hcd->self.controller, 1);
1482 msleep(10);
1483 if (isp116x->board->clock)
1484 isp116x->board->clock(hcd->self.controller, 1);
1485 msleep(1);
1486 isp116x->board->reset(hcd->self.controller, 0);
1487 } else
1488 ret = isp116x_sw_reset(isp116x);
1489
1490 if (ret)
1491 return ret;
1492
1493 t = jiffies + msecs_to_jiffies(timeout);
1494 while (time_before_eq(jiffies, t)) {
1495 msleep(4);
1496 spin_lock_irq(&isp116x->lock);
1497 clkrdy = isp116x_read_reg16(isp116x, HCuPINT) & HCuPINT_CLKRDY;
1498 spin_unlock_irq(&isp116x->lock);
1499 if (clkrdy)
1500 break;
1501 }
1502 if (!clkrdy) {
1503 ERR("Clock not ready after 20ms\n");
1504 /* After sw_reset the clock won't report to be ready, if
1505 H_WAKEUP pin is high. */
1506 if (!isp116x->board || !isp116x->board->reset)
1507 ERR("The driver does not support hardware wakeup.\n");
1508 ERR("Please make sure that the H_WAKEUP pin "
1509 "is pulled low!\n");
1510 ret = -ENODEV;
1511 }
1512 return ret;
1513}
1514
1515static void isp116x_stop(struct usb_hcd *hcd)
1516{
1517 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1518 unsigned long flags;
1519 u32 val;
1520
1521 spin_lock_irqsave(&isp116x->lock, flags);
1522 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1523
1524 /* Switch off ports' power, some devices don't come up
1525 after next 'insmod' without this */
1526 val = isp116x_read_reg32(isp116x, HCRHDESCA);
1527 val &= ~(RH_A_NPS | RH_A_PSM);
1528 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1529 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPS);
1530 spin_unlock_irqrestore(&isp116x->lock, flags);
1531
1532 /* Put the chip into reset state */
1533 if (isp116x->board && isp116x->board->reset)
1534 isp116x->board->reset(hcd->self.controller, 0);
1535 else
1536 isp116x_sw_reset(isp116x);
1537
1538 /* Stop the clock */
1539 if (isp116x->board && isp116x->board->clock)
1540 isp116x->board->clock(hcd->self.controller, 0);
1541}
1542
1543/*
1544 Configure the chip. The chip must be successfully reset by now.
1545*/
1546static int isp116x_start(struct usb_hcd *hcd)
1547{
1548 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1549 struct isp116x_platform_data *board = isp116x->board;
1550 u32 val;
1551 unsigned long flags;
1552
1553 spin_lock_irqsave(&isp116x->lock, flags);
1554
1555 /* clear interrupt status and disable all interrupt sources */
1556 isp116x_write_reg16(isp116x, HCuPINT, 0xff);
1557 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1558
1559 val = isp116x_read_reg16(isp116x, HCCHIPID);
1560 if ((val & HCCHIPID_MASK) != HCCHIPID_MAGIC) {
1561 ERR("Invalid chip ID %04x\n", val);
1562 spin_unlock_irqrestore(&isp116x->lock, flags);
1563 return -ENODEV;
1564 }
1565
1566 isp116x_write_reg16(isp116x, HCITLBUFLEN, ISP116x_ITL_BUFSIZE);
1567 isp116x_write_reg16(isp116x, HCATLBUFLEN, ISP116x_ATL_BUFSIZE);
1568
1569 /* ----- HW conf */
1570 val = HCHWCFG_INT_ENABLE | HCHWCFG_DBWIDTH(1);
1571 if (board->sel15Kres)
1572 val |= HCHWCFG_15KRSEL;
1573 /* Remote wakeup won't work without working clock */
1574 if (board->clknotstop || board->remote_wakeup_enable)
1575 val |= HCHWCFG_CLKNOTSTOP;
1576 if (board->oc_enable)
1577 val |= HCHWCFG_ANALOG_OC;
1578 if (board->int_act_high)
1579 val |= HCHWCFG_INT_POL;
1580 if (board->int_edge_triggered)
1581 val |= HCHWCFG_INT_TRIGGER;
1582 isp116x_write_reg16(isp116x, HCHWCFG, val);
1583
1584 /* ----- Root hub conf */
1585 val = 0;
1586 /* AN10003_1.pdf recommends NPS to be always 1 */
1587 if (board->no_power_switching)
1588 val |= RH_A_NPS;
1589 if (board->power_switching_mode)
1590 val |= RH_A_PSM;
1591 if (board->potpg)
1592 val |= (board->potpg << 24) & RH_A_POTPGT;
1593 else
1594 val |= (25 << 24) & RH_A_POTPGT;
1595 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1596 isp116x->rhdesca = isp116x_read_reg32(isp116x, HCRHDESCA);
1597
1598 val = RH_B_PPCM;
1599 isp116x_write_reg32(isp116x, HCRHDESCB, val);
1600 isp116x->rhdescb = isp116x_read_reg32(isp116x, HCRHDESCB);
1601
1602 val = 0;
1603 if (board->remote_wakeup_enable) {
1604 hcd->can_wakeup = 1;
1605 val |= RH_HS_DRWE;
1606 }
1607 isp116x_write_reg32(isp116x, HCRHSTATUS, val);
1608 isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
1609
1610 isp116x_write_reg32(isp116x, HCFMINTVL, 0x27782edf);
1611
1612 hcd->state = HC_STATE_RUNNING;
1613
1614 /* Set up interrupts */
1615 isp116x->intenb = HCINT_MIE | HCINT_RHSC | HCINT_UE;
1616 if (board->remote_wakeup_enable)
1617 isp116x->intenb |= HCINT_RD;
1618 isp116x->irqenb = HCuPINT_ATL | HCuPINT_OPR; /* | HCuPINT_SUSP; */
1619 isp116x_write_reg32(isp116x, HCINTENB, isp116x->intenb);
1620 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
1621
1622 /* Go operational */
1623 val = HCCONTROL_USB_OPER;
1624 /* Remote wakeup connected - NOT SUPPORTED */
1625 /* if (board->remote_wakeup_connected)
1626 val |= HCCONTROL_RWC; */
1627 if (board->remote_wakeup_enable)
1628 val |= HCCONTROL_RWE;
1629 isp116x_write_reg32(isp116x, HCCONTROL, val);
1630
1631 /* Disable ports to avoid race in device enumeration */
1632 isp116x_write_reg32(isp116x, HCRHPORT1, RH_PS_CCS);
1633 isp116x_write_reg32(isp116x, HCRHPORT2, RH_PS_CCS);
1634
1635 isp116x_show_regs(isp116x);
1636 spin_unlock_irqrestore(&isp116x->lock, flags);
1637 return 0;
1638}
1639
1640/*-----------------------------------------------------------------*/
1641
1642static struct hc_driver isp116x_hc_driver = {
1643 .description = hcd_name,
1644 .product_desc = "ISP116x Host Controller",
1645 .hcd_priv_size = sizeof(struct isp116x),
1646
1647 .irq = isp116x_irq,
1648 .flags = HCD_USB11,
1649
1650 .reset = isp116x_reset,
1651 .start = isp116x_start,
1652 .stop = isp116x_stop,
1653
1654 .urb_enqueue = isp116x_urb_enqueue,
1655 .urb_dequeue = isp116x_urb_dequeue,
1656 .endpoint_disable = isp116x_endpoint_disable,
1657
1658 .get_frame_number = isp116x_get_frame,
1659
1660 .hub_status_data = isp116x_hub_status_data,
1661 .hub_control = isp116x_hub_control,
1662 .hub_suspend = isp116x_hub_suspend,
1663 .hub_resume = isp116x_hub_resume,
1664};
1665
1666/*----------------------------------------------------------------*/
1667
1668static int __init_or_module isp116x_remove(struct device *dev)
1669{
1670 struct usb_hcd *hcd = dev_get_drvdata(dev);
1671 struct isp116x *isp116x;
1672 struct platform_device *pdev;
1673 struct resource *res;
1674
1675 if(!hcd)
1676 return 0;
1677 isp116x = hcd_to_isp116x(hcd);
1678 pdev = container_of(dev, struct platform_device, dev);
1679 remove_debug_file(isp116x);
1680 usb_remove_hcd(hcd);
1681
1682 iounmap(isp116x->data_reg);
1683 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1684 release_mem_region(res->start, 2);
1685 iounmap(isp116x->addr_reg);
1686 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1687 release_mem_region(res->start, 2);
1688
1689 usb_put_hcd(hcd);
1690 return 0;
1691}
1692
1693#define resource_len(r) (((r)->end - (r)->start) + 1)
1694
1695static int __init isp116x_probe(struct device *dev)
1696{
1697 struct usb_hcd *hcd;
1698 struct isp116x *isp116x;
1699 struct platform_device *pdev;
1700 struct resource *addr, *data;
1701 void __iomem *addr_reg;
1702 void __iomem *data_reg;
1703 int irq;
1704 int ret = 0;
1705
1706 pdev = container_of(dev, struct platform_device, dev);
1707 if (pdev->num_resources < 3) {
1708 ret = -ENODEV;
1709 goto err1;
1710 }
1711
1712 data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1713 addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1714 irq = platform_get_irq(pdev, 0);
1715 if (!addr || !data || irq < 0) {
1716 ret = -ENODEV;
1717 goto err1;
1718 }
1719
1720 if (dev->dma_mask) {
1721 DBG("DMA not supported\n");
1722 ret = -EINVAL;
1723 goto err1;
1724 }
1725
1726 if (!request_mem_region(addr->start, 2, hcd_name)) {
1727 ret = -EBUSY;
1728 goto err1;
1729 }
1730 addr_reg = ioremap(addr->start, resource_len(addr));
1731 if (addr_reg == NULL) {
1732 ret = -ENOMEM;
1733 goto err2;
1734 }
1735 if (!request_mem_region(data->start, 2, hcd_name)) {
1736 ret = -EBUSY;
1737 goto err3;
1738 }
1739 data_reg = ioremap(data->start, resource_len(data));
1740 if (data_reg == NULL) {
1741 ret = -ENOMEM;
1742 goto err4;
1743 }
1744
1745 /* allocate and initialize hcd */
1746 hcd = usb_create_hcd(&isp116x_hc_driver, dev, dev->bus_id);
1747 if (!hcd) {
1748 ret = -ENOMEM;
1749 goto err5;
1750 }
1751 /* this rsrc_start is bogus */
1752 hcd->rsrc_start = addr->start;
1753 isp116x = hcd_to_isp116x(hcd);
1754 isp116x->data_reg = data_reg;
1755 isp116x->addr_reg = addr_reg;
1756 spin_lock_init(&isp116x->lock);
1757 INIT_LIST_HEAD(&isp116x->async);
1758 INIT_WORK(&isp116x->rh_resume, isp116x_rh_resume, hcd);
1759 isp116x->board = dev->platform_data;
1760
1761 if (!isp116x->board) {
1762 ERR("Platform data structure not initialized\n");
1763 ret = -ENODEV;
1764 goto err6;
1765 }
1766 if (isp116x_check_platform_delay(isp116x)) {
1767 ERR("USE_PLATFORM_DELAY defined, but delay function not "
1768 "implemented.\n");
1769 ERR("See comments in drivers/usb/host/isp116x-hcd.c\n");
1770 ret = -ENODEV;
1771 goto err6;
1772 }
1773
1774 ret = usb_add_hcd(hcd, irq, SA_INTERRUPT);
1775 if (ret != 0)
1776 goto err6;
1777
1778 create_debug_file(isp116x);
1779 return 0;
1780
1781 err6:
1782 usb_put_hcd(hcd);
1783 err5:
1784 iounmap(data_reg);
1785 err4:
1786 release_mem_region(data->start, 2);
1787 err3:
1788 iounmap(addr_reg);
1789 err2:
1790 release_mem_region(addr->start, 2);
1791 err1:
1792 ERR("init error, %d\n", ret);
1793 return ret;
1794}
1795
1796#ifdef CONFIG_PM
1797/*
1798 Suspend of platform device
1799*/
1800static int isp116x_suspend(struct device *dev, pm_message_t state, u32 phase)
1801{
1802 int ret = 0;
1803 struct usb_hcd *hcd = dev_get_drvdata(dev);
1804
1805 VDBG("%s: state %x, phase %x\n", __func__, state, phase);
1806
1807 if (phase != SUSPEND_DISABLE && phase != SUSPEND_POWER_DOWN)
1808 return 0;
1809
1810 ret = usb_suspend_device(hcd->self.root_hub, state);
1811 if (!ret) {
1812 dev->power.power_state = state;
1813 INFO("%s suspended\n", (char *)hcd_name);
1814 } else
1815 ERR("%s suspend failed\n", (char *)hcd_name);
1816
1817 return ret;
1818}
1819
1820/*
1821 Resume platform device
1822*/
1823static int isp116x_resume(struct device *dev, u32 phase)
1824{
1825 int ret = 0;
1826 struct usb_hcd *hcd = dev_get_drvdata(dev);
1827
1828 VDBG("%s: state %x, phase %x\n", __func__, dev->power.power_state,
1829 phase);
1830 if (phase != RESUME_POWER_ON)
1831 return 0;
1832
1833 ret = usb_resume_device(hcd->self.root_hub);
1834 if (!ret) {
1835 dev->power.power_state = PMSG_ON;
1836 VDBG("%s resumed\n", (char *)hcd_name);
1837 }
1838 return ret;
1839}
1840
1841#else
1842
1843#define isp116x_suspend NULL
1844#define isp116x_resume NULL
1845
1846#endif
1847
1848static struct device_driver isp116x_driver = {
1849 .name = (char *)hcd_name,
1850 .bus = &platform_bus_type,
1851 .probe = isp116x_probe,
1852 .remove = isp116x_remove,
1853 .suspend = isp116x_suspend,
1854 .resume = isp116x_resume,
1855};
1856
1857/*-----------------------------------------------------------------*/
1858
1859static int __init isp116x_init(void)
1860{
1861 if (usb_disabled())
1862 return -ENODEV;
1863
1864 INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
1865 return driver_register(&isp116x_driver);
1866}
1867
1868module_init(isp116x_init);
1869
1870static void __exit isp116x_cleanup(void)
1871{
1872 driver_unregister(&isp116x_driver);
1873}
1874
1875module_exit(isp116x_cleanup);
diff --git a/drivers/usb/host/isp116x.h b/drivers/usb/host/isp116x.h
new file mode 100644
index 000000000000..58873470dcf5
--- /dev/null
+++ b/drivers/usb/host/isp116x.h
@@ -0,0 +1,583 @@
1/*
2 * ISP116x register declarations and HCD data structures
3 *
4 * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
5 * Portions:
6 * Copyright (C) 2004 Lothar Wassmann
7 * Copyright (C) 2004 Psion Teklogix
8 * Copyright (C) 2004 David Brownell
9 */
10
11/* us of 1ms frame */
12#define MAX_LOAD_LIMIT 850
13
14/* Full speed: max # of bytes to transfer for a single urb
15 at a time must be < 1024 && must be multiple of 64.
16 832 allows transfering 4kiB within 5 frames. */
17#define MAX_TRANSFER_SIZE_FULLSPEED 832
18
19/* Low speed: there is no reason to schedule in very big
20 chunks; often the requested long transfers are for
21 string descriptors containing short strings. */
22#define MAX_TRANSFER_SIZE_LOWSPEED 64
23
24/* Bytetime (us), a rough indication of how much time it
25 would take to transfer a byte of useful data over USB */
26#define BYTE_TIME_FULLSPEED 1
27#define BYTE_TIME_LOWSPEED 20
28
29/* Buffer sizes */
30#define ISP116x_BUF_SIZE 4096
31#define ISP116x_ITL_BUFSIZE 0
32#define ISP116x_ATL_BUFSIZE ((ISP116x_BUF_SIZE) - 2*(ISP116x_ITL_BUFSIZE))
33
34#define ISP116x_WRITE_OFFSET 0x80
35
36/*------------ ISP116x registers/bits ------------*/
37#define HCREVISION 0x00
38#define HCCONTROL 0x01
39#define HCCONTROL_HCFS (3 << 6) /* host controller
40 functional state */
41#define HCCONTROL_USB_RESET (0 << 6)
42#define HCCONTROL_USB_RESUME (1 << 6)
43#define HCCONTROL_USB_OPER (2 << 6)
44#define HCCONTROL_USB_SUSPEND (3 << 6)
45#define HCCONTROL_RWC (1 << 9) /* remote wakeup connected */
46#define HCCONTROL_RWE (1 << 10) /* remote wakeup enable */
47#define HCCMDSTAT 0x02
48#define HCCMDSTAT_HCR (1 << 0) /* host controller reset */
49#define HCCMDSTAT_SOC (3 << 16) /* scheduling overrun count */
50#define HCINTSTAT 0x03
51#define HCINT_SO (1 << 0) /* scheduling overrun */
52#define HCINT_WDH (1 << 1) /* writeback of done_head */
53#define HCINT_SF (1 << 2) /* start frame */
54#define HCINT_RD (1 << 3) /* resume detect */
55#define HCINT_UE (1 << 4) /* unrecoverable error */
56#define HCINT_FNO (1 << 5) /* frame number overflow */
57#define HCINT_RHSC (1 << 6) /* root hub status change */
58#define HCINT_OC (1 << 30) /* ownership change */
59#define HCINT_MIE (1 << 31) /* master interrupt enable */
60#define HCINTENB 0x04
61#define HCINTDIS 0x05
62#define HCFMINTVL 0x0d
63#define HCFMREM 0x0e
64#define HCFMNUM 0x0f
65#define HCLSTHRESH 0x11
66#define HCRHDESCA 0x12
67#define RH_A_NDP (0x3 << 0) /* # downstream ports */
68#define RH_A_PSM (1 << 8) /* power switching mode */
69#define RH_A_NPS (1 << 9) /* no power switching */
70#define RH_A_DT (1 << 10) /* device type (mbz) */
71#define RH_A_OCPM (1 << 11) /* overcurrent protection
72 mode */
73#define RH_A_NOCP (1 << 12) /* no overcurrent protection */
74#define RH_A_POTPGT (0xff << 24) /* power on -> power good
75 time */
76#define HCRHDESCB 0x13
77#define RH_B_DR (0xffff << 0) /* device removable flags */
78#define RH_B_PPCM (0xffff << 16) /* port power control mask */
79#define HCRHSTATUS 0x14
80#define RH_HS_LPS (1 << 0) /* local power status */
81#define RH_HS_OCI (1 << 1) /* over current indicator */
82#define RH_HS_DRWE (1 << 15) /* device remote wakeup
83 enable */
84#define RH_HS_LPSC (1 << 16) /* local power status change */
85#define RH_HS_OCIC (1 << 17) /* over current indicator
86 change */
87#define RH_HS_CRWE (1 << 31) /* clear remote wakeup
88 enable */
89#define HCRHPORT1 0x15
90#define RH_PS_CCS (1 << 0) /* current connect status */
91#define RH_PS_PES (1 << 1) /* port enable status */
92#define RH_PS_PSS (1 << 2) /* port suspend status */
93#define RH_PS_POCI (1 << 3) /* port over current
94 indicator */
95#define RH_PS_PRS (1 << 4) /* port reset status */
96#define RH_PS_PPS (1 << 8) /* port power status */
97#define RH_PS_LSDA (1 << 9) /* low speed device attached */
98#define RH_PS_CSC (1 << 16) /* connect status change */
99#define RH_PS_PESC (1 << 17) /* port enable status change */
100#define RH_PS_PSSC (1 << 18) /* port suspend status
101 change */
102#define RH_PS_OCIC (1 << 19) /* over current indicator
103 change */
104#define RH_PS_PRSC (1 << 20) /* port reset status change */
105#define HCRHPORT_CLRMASK (0x1f << 16)
106#define HCRHPORT2 0x16
107#define HCHWCFG 0x20
108#define HCHWCFG_15KRSEL (1 << 12)
109#define HCHWCFG_CLKNOTSTOP (1 << 11)
110#define HCHWCFG_ANALOG_OC (1 << 10)
111#define HCHWCFG_DACK_MODE (1 << 8)
112#define HCHWCFG_EOT_POL (1 << 7)
113#define HCHWCFG_DACK_POL (1 << 6)
114#define HCHWCFG_DREQ_POL (1 << 5)
115#define HCHWCFG_DBWIDTH_MASK (0x03 << 3)
116#define HCHWCFG_DBWIDTH(n) (((n) << 3) & HCHWCFG_DBWIDTH_MASK)
117#define HCHWCFG_INT_POL (1 << 2)
118#define HCHWCFG_INT_TRIGGER (1 << 1)
119#define HCHWCFG_INT_ENABLE (1 << 0)
120#define HCDMACFG 0x21
121#define HCDMACFG_BURST_LEN_MASK (0x03 << 5)
122#define HCDMACFG_BURST_LEN(n) (((n) << 5) & HCDMACFG_BURST_LEN_MASK)
123#define HCDMACFG_BURST_LEN_1 HCDMACFG_BURST_LEN(0)
124#define HCDMACFG_BURST_LEN_4 HCDMACFG_BURST_LEN(1)
125#define HCDMACFG_BURST_LEN_8 HCDMACFG_BURST_LEN(2)
126#define HCDMACFG_DMA_ENABLE (1 << 4)
127#define HCDMACFG_BUF_TYPE_MASK (0x07 << 1)
128#define HCDMACFG_CTR_SEL (1 << 2)
129#define HCDMACFG_ITLATL_SEL (1 << 1)
130#define HCDMACFG_DMA_RW_SELECT (1 << 0)
131#define HCXFERCTR 0x22
132#define HCuPINT 0x24
133#define HCuPINT_SOF (1 << 0)
134#define HCuPINT_ATL (1 << 1)
135#define HCuPINT_AIIEOT (1 << 2)
136#define HCuPINT_OPR (1 << 4)
137#define HCuPINT_SUSP (1 << 5)
138#define HCuPINT_CLKRDY (1 << 6)
139#define HCuPINTENB 0x25
140#define HCCHIPID 0x27
141#define HCCHIPID_MASK 0xff00
142#define HCCHIPID_MAGIC 0x6100
143#define HCSCRATCH 0x28
144#define HCSWRES 0x29
145#define HCSWRES_MAGIC 0x00f6
146#define HCITLBUFLEN 0x2a
147#define HCATLBUFLEN 0x2b
148#define HCBUFSTAT 0x2c
149#define HCBUFSTAT_ITL0_FULL (1 << 0)
150#define HCBUFSTAT_ITL1_FULL (1 << 1)
151#define HCBUFSTAT_ATL_FULL (1 << 2)
152#define HCBUFSTAT_ITL0_DONE (1 << 3)
153#define HCBUFSTAT_ITL1_DONE (1 << 4)
154#define HCBUFSTAT_ATL_DONE (1 << 5)
155#define HCRDITL0LEN 0x2d
156#define HCRDITL1LEN 0x2e
157#define HCITLPORT 0x40
158#define HCATLPORT 0x41
159
160/* Philips transfer descriptor */
161struct ptd {
162 u16 count;
163#define PTD_COUNT_MSK (0x3ff << 0)
164#define PTD_TOGGLE_MSK (1 << 10)
165#define PTD_ACTIVE_MSK (1 << 11)
166#define PTD_CC_MSK (0xf << 12)
167 u16 mps;
168#define PTD_MPS_MSK (0x3ff << 0)
169#define PTD_SPD_MSK (1 << 10)
170#define PTD_LAST_MSK (1 << 11)
171#define PTD_EP_MSK (0xf << 12)
172 u16 len;
173#define PTD_LEN_MSK (0x3ff << 0)
174#define PTD_DIR_MSK (3 << 10)
175#define PTD_DIR_SETUP (0)
176#define PTD_DIR_OUT (1)
177#define PTD_DIR_IN (2)
178#define PTD_B5_5_MSK (1 << 13)
179 u16 faddr;
180#define PTD_FA_MSK (0x7f << 0)
181#define PTD_FMT_MSK (1 << 7)
182} __attribute__ ((packed, aligned(2)));
183
184/* PTD accessor macros. */
185#define PTD_GET_COUNT(p) (((p)->count & PTD_COUNT_MSK) >> 0)
186#define PTD_COUNT(v) (((v) << 0) & PTD_COUNT_MSK)
187#define PTD_GET_TOGGLE(p) (((p)->count & PTD_TOGGLE_MSK) >> 10)
188#define PTD_TOGGLE(v) (((v) << 10) & PTD_TOGGLE_MSK)
189#define PTD_GET_ACTIVE(p) (((p)->count & PTD_ACTIVE_MSK) >> 11)
190#define PTD_ACTIVE(v) (((v) << 11) & PTD_ACTIVE_MSK)
191#define PTD_GET_CC(p) (((p)->count & PTD_CC_MSK) >> 12)
192#define PTD_CC(v) (((v) << 12) & PTD_CC_MSK)
193#define PTD_GET_MPS(p) (((p)->mps & PTD_MPS_MSK) >> 0)
194#define PTD_MPS(v) (((v) << 0) & PTD_MPS_MSK)
195#define PTD_GET_SPD(p) (((p)->mps & PTD_SPD_MSK) >> 10)
196#define PTD_SPD(v) (((v) << 10) & PTD_SPD_MSK)
197#define PTD_GET_LAST(p) (((p)->mps & PTD_LAST_MSK) >> 11)
198#define PTD_LAST(v) (((v) << 11) & PTD_LAST_MSK)
199#define PTD_GET_EP(p) (((p)->mps & PTD_EP_MSK) >> 12)
200#define PTD_EP(v) (((v) << 12) & PTD_EP_MSK)
201#define PTD_GET_LEN(p) (((p)->len & PTD_LEN_MSK) >> 0)
202#define PTD_LEN(v) (((v) << 0) & PTD_LEN_MSK)
203#define PTD_GET_DIR(p) (((p)->len & PTD_DIR_MSK) >> 10)
204#define PTD_DIR(v) (((v) << 10) & PTD_DIR_MSK)
205#define PTD_GET_B5_5(p) (((p)->len & PTD_B5_5_MSK) >> 13)
206#define PTD_B5_5(v) (((v) << 13) & PTD_B5_5_MSK)
207#define PTD_GET_FA(p) (((p)->faddr & PTD_FA_MSK) >> 0)
208#define PTD_FA(v) (((v) << 0) & PTD_FA_MSK)
209#define PTD_GET_FMT(p) (((p)->faddr & PTD_FMT_MSK) >> 7)
210#define PTD_FMT(v) (((v) << 7) & PTD_FMT_MSK)
211
212/* Hardware transfer status codes -- CC from ptd->count */
213#define TD_CC_NOERROR 0x00
214#define TD_CC_CRC 0x01
215#define TD_CC_BITSTUFFING 0x02
216#define TD_CC_DATATOGGLEM 0x03
217#define TD_CC_STALL 0x04
218#define TD_DEVNOTRESP 0x05
219#define TD_PIDCHECKFAIL 0x06
220#define TD_UNEXPECTEDPID 0x07
221#define TD_DATAOVERRUN 0x08
222#define TD_DATAUNDERRUN 0x09
223 /* 0x0A, 0x0B reserved for hardware */
224#define TD_BUFFEROVERRUN 0x0C
225#define TD_BUFFERUNDERRUN 0x0D
226 /* 0x0E, 0x0F reserved for HCD */
227#define TD_NOTACCESSED 0x0F
228
229/* map PTD status codes (CC) to errno values */
230static const int cc_to_error[16] = {
231 /* No Error */ 0,
232 /* CRC Error */ -EILSEQ,
233 /* Bit Stuff */ -EPROTO,
234 /* Data Togg */ -EILSEQ,
235 /* Stall */ -EPIPE,
236 /* DevNotResp */ -ETIMEDOUT,
237 /* PIDCheck */ -EPROTO,
238 /* UnExpPID */ -EPROTO,
239 /* DataOver */ -EOVERFLOW,
240 /* DataUnder */ -EREMOTEIO,
241 /* (for hw) */ -EIO,
242 /* (for hw) */ -EIO,
243 /* BufferOver */ -ECOMM,
244 /* BuffUnder */ -ENOSR,
245 /* (for HCD) */ -EALREADY,
246 /* (for HCD) */ -EALREADY
247};
248
249/*--------------------------------------------------------------*/
250
251#define LOG2_PERIODIC_SIZE 5 /* arbitrary; this matches OHCI */
252#define PERIODIC_SIZE (1 << LOG2_PERIODIC_SIZE)
253
254struct isp116x {
255 spinlock_t lock;
256 struct work_struct rh_resume;
257
258 void __iomem *addr_reg;
259 void __iomem *data_reg;
260
261 struct isp116x_platform_data *board;
262
263 struct proc_dir_entry *pde;
264 unsigned long stat1, stat2, stat4, stat8, stat16;
265
266 /* HC registers */
267 u32 intenb; /* "OHCI" interrupts */
268 u16 irqenb; /* uP interrupts */
269
270 /* Root hub registers */
271 u32 rhdesca;
272 u32 rhdescb;
273 u32 rhstatus;
274 u32 rhport[2];
275
276 /* async schedule: control, bulk */
277 struct list_head async;
278
279 /* periodic schedule: int */
280 u16 load[PERIODIC_SIZE];
281 struct isp116x_ep *periodic[PERIODIC_SIZE];
282 unsigned periodic_count;
283 u16 fmindex;
284
285 /* Schedule for the current frame */
286 struct isp116x_ep *atl_active;
287 int atl_buflen;
288 int atl_bufshrt;
289 int atl_last_dir;
290 atomic_t atl_finishing;
291};
292
293static inline struct isp116x *hcd_to_isp116x(struct usb_hcd *hcd)
294{
295 return (struct isp116x *)(hcd->hcd_priv);
296}
297
298static inline struct usb_hcd *isp116x_to_hcd(struct isp116x *isp116x)
299{
300 return container_of((void *)isp116x, struct usb_hcd, hcd_priv);
301}
302
303struct isp116x_ep {
304 struct usb_host_endpoint *hep;
305 struct usb_device *udev;
306 struct ptd ptd;
307
308 u8 maxpacket;
309 u8 epnum;
310 u8 nextpid;
311 u16 error_count;
312 u16 length; /* of current packet */
313 unsigned char *data; /* to databuf */
314 /* queue of active EP's (the ones scheduled for the
315 current frame) */
316 struct isp116x_ep *active;
317
318 /* periodic schedule */
319 u16 period;
320 u16 branch;
321 u16 load;
322 struct isp116x_ep *next;
323
324 /* async schedule */
325 struct list_head schedule;
326};
327
328/*-------------------------------------------------------------------------*/
329
330#ifdef DEBUG
331#define DBG(stuff...) printk(KERN_DEBUG "116x: " stuff)
332#else
333#define DBG(stuff...) do{}while(0)
334#endif
335
336#ifdef VERBOSE
337# define VDBG DBG
338#else
339# define VDBG(stuff...) do{}while(0)
340#endif
341
342#define ERR(stuff...) printk(KERN_ERR "116x: " stuff)
343#define WARN(stuff...) printk(KERN_WARNING "116x: " stuff)
344#define INFO(stuff...) printk(KERN_INFO "116x: " stuff)
345
346/* ------------------------------------------------- */
347
348#if defined(USE_PLATFORM_DELAY)
349#if defined(USE_NDELAY)
350#error USE_PLATFORM_DELAY and USE_NDELAY simultaneously defined.
351#endif
352#define isp116x_delay(h,d) (h)->board->delay( \
353 isp116x_to_hcd(h)->self.controller,d)
354#define isp116x_check_platform_delay(h) ((h)->board->delay == NULL)
355#elif defined(USE_NDELAY)
356#define isp116x_delay(h,d) ndelay(d)
357#define isp116x_check_platform_delay(h) 0
358#else
359#define isp116x_delay(h,d) do{}while(0)
360#define isp116x_check_platform_delay(h) 0
361#endif
362
363#if defined(DEBUG)
364#define IRQ_TEST() BUG_ON(!irqs_disabled())
365#else
366#define IRQ_TEST() do{}while(0)
367#endif
368
369static inline void isp116x_write_addr(struct isp116x *isp116x, unsigned reg)
370{
371 IRQ_TEST();
372 writew(reg & 0xff, isp116x->addr_reg);
373 isp116x_delay(isp116x, 300);
374}
375
376static inline void isp116x_write_data16(struct isp116x *isp116x, u16 val)
377{
378 writew(val, isp116x->data_reg);
379 isp116x_delay(isp116x, 150);
380}
381
382static inline void isp116x_raw_write_data16(struct isp116x *isp116x, u16 val)
383{
384 __raw_writew(val, isp116x->data_reg);
385 isp116x_delay(isp116x, 150);
386}
387
388static inline u16 isp116x_read_data16(struct isp116x *isp116x)
389{
390 u16 val;
391
392 val = readw(isp116x->data_reg);
393 isp116x_delay(isp116x, 150);
394 return val;
395}
396
397static inline u16 isp116x_raw_read_data16(struct isp116x *isp116x)
398{
399 u16 val;
400
401 val = __raw_readw(isp116x->data_reg);
402 isp116x_delay(isp116x, 150);
403 return val;
404}
405
406static inline void isp116x_write_data32(struct isp116x *isp116x, u32 val)
407{
408 writew(val & 0xffff, isp116x->data_reg);
409 isp116x_delay(isp116x, 150);
410 writew(val >> 16, isp116x->data_reg);
411 isp116x_delay(isp116x, 150);
412}
413
414static inline u32 isp116x_read_data32(struct isp116x *isp116x)
415{
416 u32 val;
417
418 val = (u32) readw(isp116x->data_reg);
419 isp116x_delay(isp116x, 150);
420 val |= ((u32) readw(isp116x->data_reg)) << 16;
421 isp116x_delay(isp116x, 150);
422 return val;
423}
424
425/* Let's keep register access functions out of line. Hint:
426 we wait at least 150 ns at every access.
427*/
428static u16 isp116x_read_reg16(struct isp116x *isp116x, unsigned reg)
429{
430 isp116x_write_addr(isp116x, reg);
431 return isp116x_read_data16(isp116x);
432}
433
434static u32 isp116x_read_reg32(struct isp116x *isp116x, unsigned reg)
435{
436 isp116x_write_addr(isp116x, reg);
437 return isp116x_read_data32(isp116x);
438}
439
440static void isp116x_write_reg16(struct isp116x *isp116x, unsigned reg,
441 unsigned val)
442{
443 isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET);
444 isp116x_write_data16(isp116x, (u16) (val & 0xffff));
445}
446
447static void isp116x_write_reg32(struct isp116x *isp116x, unsigned reg,
448 unsigned val)
449{
450 isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET);
451 isp116x_write_data32(isp116x, (u32) val);
452}
453
454#define isp116x_show_reg(d,r) { \
455 if ((r) < 0x20) { \
456 DBG("%-12s[%02x]: %08x\n", #r, \
457 r, isp116x_read_reg32(d, r)); \
458 } else { \
459 DBG("%-12s[%02x]: %04x\n", #r, \
460 r, isp116x_read_reg16(d, r)); \
461 } \
462}
463
464static inline void isp116x_show_regs(struct isp116x *isp116x)
465{
466 isp116x_show_reg(isp116x, HCREVISION);
467 isp116x_show_reg(isp116x, HCCONTROL);
468 isp116x_show_reg(isp116x, HCCMDSTAT);
469 isp116x_show_reg(isp116x, HCINTSTAT);
470 isp116x_show_reg(isp116x, HCINTENB);
471 isp116x_show_reg(isp116x, HCFMINTVL);
472 isp116x_show_reg(isp116x, HCFMREM);
473 isp116x_show_reg(isp116x, HCFMNUM);
474 isp116x_show_reg(isp116x, HCLSTHRESH);
475 isp116x_show_reg(isp116x, HCRHDESCA);
476 isp116x_show_reg(isp116x, HCRHDESCB);
477 isp116x_show_reg(isp116x, HCRHSTATUS);
478 isp116x_show_reg(isp116x, HCRHPORT1);
479 isp116x_show_reg(isp116x, HCRHPORT2);
480 isp116x_show_reg(isp116x, HCHWCFG);
481 isp116x_show_reg(isp116x, HCDMACFG);
482 isp116x_show_reg(isp116x, HCXFERCTR);
483 isp116x_show_reg(isp116x, HCuPINT);
484 isp116x_show_reg(isp116x, HCuPINTENB);
485 isp116x_show_reg(isp116x, HCCHIPID);
486 isp116x_show_reg(isp116x, HCSCRATCH);
487 isp116x_show_reg(isp116x, HCITLBUFLEN);
488 isp116x_show_reg(isp116x, HCATLBUFLEN);
489 isp116x_show_reg(isp116x, HCBUFSTAT);
490 isp116x_show_reg(isp116x, HCRDITL0LEN);
491 isp116x_show_reg(isp116x, HCRDITL1LEN);
492}
493
494#if defined(URB_TRACE)
495
496#define PIPETYPE(pipe) ({ char *__s; \
497 if (usb_pipecontrol(pipe)) __s = "ctrl"; \
498 else if (usb_pipeint(pipe)) __s = "int"; \
499 else if (usb_pipebulk(pipe)) __s = "bulk"; \
500 else __s = "iso"; \
501 __s;})
502#define PIPEDIR(pipe) ({ usb_pipein(pipe) ? "in" : "out"; })
503#define URB_NOTSHORT(urb) ({ (urb)->transfer_flags & URB_SHORT_NOT_OK ? \
504 "short_not_ok" : ""; })
505
506/* print debug info about the URB */
507static void urb_dbg(struct urb *urb, char *msg)
508{
509 unsigned int pipe;
510
511 if (!urb) {
512 DBG("%s: zero urb\n", msg);
513 return;
514 }
515 pipe = urb->pipe;
516 DBG("%s: FA %d ep%d%s %s: len %d/%d %s\n", msg,
517 usb_pipedevice(pipe), usb_pipeendpoint(pipe),
518 PIPEDIR(pipe), PIPETYPE(pipe),
519 urb->transfer_buffer_length, urb->actual_length, URB_NOTSHORT(urb));
520}
521
522#else
523
524#define urb_dbg(urb,msg) do{}while(0)
525
526#endif /* ! defined(URB_TRACE) */
527
528#if defined(PTD_TRACE)
529
530#define PTD_DIR_STR(ptd) ({char __c; \
531 switch(PTD_GET_DIR(ptd)){ \
532 case 0: __c = 's'; break; \
533 case 1: __c = 'o'; break; \
534 default: __c = 'i'; break; \
535 }; __c;})
536
537/*
538 Dump PTD info. The code documents the format
539 perfectly, right :)
540*/
541static inline void dump_ptd(struct ptd *ptd)
542{
543 printk("td: %x %d%c%d %d,%d,%d %x %x%x%x\n",
544 PTD_GET_CC(ptd), PTD_GET_FA(ptd),
545 PTD_DIR_STR(ptd), PTD_GET_EP(ptd),
546 PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd),
547 PTD_GET_TOGGLE(ptd), PTD_GET_ACTIVE(ptd),
548 PTD_GET_SPD(ptd), PTD_GET_LAST(ptd));
549}
550
551static inline void dump_ptd_out_data(struct ptd *ptd, u8 * buf)
552{
553 int k;
554
555 if (PTD_GET_DIR(ptd) != PTD_DIR_IN && PTD_GET_LEN(ptd)) {
556 printk("-> ");
557 for (k = 0; k < PTD_GET_LEN(ptd); ++k)
558 printk("%02x ", ((u8 *) buf)[k]);
559 printk("\n");
560 }
561}
562
563static inline void dump_ptd_in_data(struct ptd *ptd, u8 * buf)
564{
565 int k;
566
567 if (PTD_GET_DIR(ptd) == PTD_DIR_IN && PTD_GET_COUNT(ptd)) {
568 printk("<- ");
569 for (k = 0; k < PTD_GET_COUNT(ptd); ++k)
570 printk("%02x ", ((u8 *) buf)[k]);
571 printk("\n");
572 }
573 if (PTD_GET_LAST(ptd))
574 printk("-\n");
575}
576
577#else
578
579#define dump_ptd(ptd) do{}while(0)
580#define dump_ptd_in_data(ptd,buf) do{}while(0)
581#define dump_ptd_out_data(ptd,buf) do{}while(0)
582
583#endif /* ! defined(PTD_TRACE) */
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 1e27f10c1592..13cd2177b557 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -95,12 +95,11 @@
95#include <linux/init.h> 95#include <linux/init.h>
96#include <linux/timer.h> 96#include <linux/timer.h>
97#include <linux/list.h> 97#include <linux/list.h>
98#include <linux/interrupt.h> /* for in_interrupt () */
99#include <linux/usb.h> 98#include <linux/usb.h>
100#include <linux/usb_otg.h> 99#include <linux/usb_otg.h>
101#include "../core/hcd.h"
102#include <linux/dma-mapping.h> 100#include <linux/dma-mapping.h>
103#include <linux/dmapool.h> /* needed by ohci-mem.c when no PCI */ 101#include <linux/dmapool.h>
102#include <linux/reboot.h>
104 103
105#include <asm/io.h> 104#include <asm/io.h>
106#include <asm/irq.h> 105#include <asm/irq.h>
@@ -108,8 +107,9 @@
108#include <asm/unaligned.h> 107#include <asm/unaligned.h>
109#include <asm/byteorder.h> 108#include <asm/byteorder.h>
110 109
110#include "../core/hcd.h"
111 111
112#define DRIVER_VERSION "2004 Nov 08" 112#define DRIVER_VERSION "2005 April 22"
113#define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell" 113#define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
114#define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver" 114#define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
115 115
@@ -141,6 +141,7 @@ static const char hcd_name [] = "ohci_hcd";
141static void ohci_dump (struct ohci_hcd *ohci, int verbose); 141static void ohci_dump (struct ohci_hcd *ohci, int verbose);
142static int ohci_init (struct ohci_hcd *ohci); 142static int ohci_init (struct ohci_hcd *ohci);
143static void ohci_stop (struct usb_hcd *hcd); 143static void ohci_stop (struct usb_hcd *hcd);
144static int ohci_reboot (struct notifier_block *, unsigned long , void *);
144 145
145#include "ohci-hub.c" 146#include "ohci-hub.c"
146#include "ohci-dbg.c" 147#include "ohci-dbg.c"
@@ -420,6 +421,23 @@ static void ohci_usb_reset (struct ohci_hcd *ohci)
420 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 421 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
421} 422}
422 423
424/* reboot notifier forcibly disables IRQs and DMA, helping kexec and
425 * other cases where the next software may expect clean state from the
426 * "firmware". this is bus-neutral, unlike shutdown() methods.
427 */
428static int
429ohci_reboot (struct notifier_block *block, unsigned long code, void *null)
430{
431 struct ohci_hcd *ohci;
432
433 ohci = container_of (block, struct ohci_hcd, reboot_notifier);
434 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
435 ohci_usb_reset (ohci);
436 /* flush the writes */
437 (void) ohci_readl (ohci, &ohci->regs->control);
438 return 0;
439}
440
423/*-------------------------------------------------------------------------* 441/*-------------------------------------------------------------------------*
424 * HC functions 442 * HC functions
425 *-------------------------------------------------------------------------*/ 443 *-------------------------------------------------------------------------*/
@@ -487,13 +505,10 @@ static int ohci_init (struct ohci_hcd *ohci)
487/* Start an OHCI controller, set the BUS operational 505/* Start an OHCI controller, set the BUS operational
488 * resets USB and controller 506 * resets USB and controller
489 * enable interrupts 507 * enable interrupts
490 * connect the virtual root hub
491 */ 508 */
492static int ohci_run (struct ohci_hcd *ohci) 509static int ohci_run (struct ohci_hcd *ohci)
493{ 510{
494 u32 mask, temp; 511 u32 mask, temp;
495 struct usb_device *udev;
496 struct usb_bus *bus;
497 int first = ohci->fminterval == 0; 512 int first = ohci->fminterval == 0;
498 513
499 disable (ohci); 514 disable (ohci);
@@ -654,37 +669,13 @@ retry:
654 669
655 // POTPGT delay is bits 24-31, in 2 ms units. 670 // POTPGT delay is bits 24-31, in 2 ms units.
656 mdelay ((temp >> 23) & 0x1fe); 671 mdelay ((temp >> 23) & 0x1fe);
657 bus = &ohci_to_hcd(ohci)->self;
658 ohci_to_hcd(ohci)->state = HC_STATE_RUNNING; 672 ohci_to_hcd(ohci)->state = HC_STATE_RUNNING;
659 673
660 ohci_dump (ohci, 1); 674 ohci_dump (ohci, 1);
661 675
662 udev = bus->root_hub; 676 if (ohci_to_hcd(ohci)->self.root_hub == NULL)
663 if (udev) { 677 create_debug_files (ohci);
664 return 0;
665 }
666
667 /* connect the virtual root hub */
668 udev = usb_alloc_dev (NULL, bus, 0);
669 if (!udev) {
670 disable (ohci);
671 ohci->hc_control &= ~OHCI_CTRL_HCFS;
672 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
673 return -ENOMEM;
674 }
675
676 udev->speed = USB_SPEED_FULL;
677 if (usb_hcd_register_root_hub (udev, ohci_to_hcd(ohci)) != 0) {
678 usb_put_dev (udev);
679 disable (ohci);
680 ohci->hc_control &= ~OHCI_CTRL_HCFS;
681 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
682 return -ENODEV;
683 }
684 if (ohci->power_budget)
685 hub_set_power_budget(udev, ohci->power_budget);
686 678
687 create_debug_files (ohci);
688 return 0; 679 return 0;
689} 680}
690 681
@@ -781,6 +772,7 @@ static void ohci_stop (struct usb_hcd *hcd)
781 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 772 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
782 773
783 remove_debug_files (ohci); 774 remove_debug_files (ohci);
775 unregister_reboot_notifier (&ohci->reboot_notifier);
784 ohci_mem_cleanup (ohci); 776 ohci_mem_cleanup (ohci);
785 if (ohci->hcca) { 777 if (ohci->hcca) {
786 dma_free_coherent (hcd->self.controller, 778 dma_free_coherent (hcd->self.controller,
diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
index e55682b4919d..23735a36af00 100644
--- a/drivers/usb/host/ohci-mem.c
+++ b/drivers/usb/host/ohci-mem.c
@@ -29,6 +29,7 @@ static void ohci_hcd_init (struct ohci_hcd *ohci)
29 spin_lock_init (&ohci->lock); 29 spin_lock_init (&ohci->lock);
30 INIT_LIST_HEAD (&ohci->pending); 30 INIT_LIST_HEAD (&ohci->pending);
31 INIT_WORK (&ohci->rh_resume, ohci_rh_resume, ohci_to_hcd(ohci)); 31 INIT_WORK (&ohci->rh_resume, ohci_rh_resume, ohci_to_hcd(ohci));
32 ohci->reboot_notifier.notifier_call = ohci_reboot;
32} 33}
33 34
34/*-------------------------------------------------------------------------*/ 35/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 8aab5907afe9..b62d69937694 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -181,7 +181,7 @@ static int omap_start_hc(struct ohci_hcd *ohci, struct platform_device *pdev)
181 if (config->otg) { 181 if (config->otg) {
182 ohci_to_hcd(ohci)->self.otg_port = config->otg; 182 ohci_to_hcd(ohci)->self.otg_port = config->otg;
183 /* default/minimum OTG power budget: 8 mA */ 183 /* default/minimum OTG power budget: 8 mA */
184 ohci->power_budget = 8; 184 ohci_to_hcd(ohci)->power_budget = 8;
185 } 185 }
186 186
187 /* boards can use OTG transceivers in non-OTG modes */ 187 /* boards can use OTG transceivers in non-OTG modes */
@@ -230,7 +230,7 @@ static int omap_start_hc(struct ohci_hcd *ohci, struct platform_device *pdev)
230 230
231 /* TPS2045 switch for internal transceiver (port 1) */ 231 /* TPS2045 switch for internal transceiver (port 1) */
232 if (machine_is_omap_osk()) { 232 if (machine_is_omap_osk()) {
233 ohci->power_budget = 250; 233 ohci_to_hcd(ohci)->power_budget = 250;
234 234
235 rh &= ~RH_A_NOCP; 235 rh &= ~RH_A_NOCP;
236 236
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index 57fd07d00549..eede6be098d2 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -14,14 +14,11 @@
14 * This file is licenced under the GPL. 14 * This file is licenced under the GPL.
15 */ 15 */
16 16
17#ifdef CONFIG_PMAC_PBOOK 17#ifdef CONFIG_PPC_PMAC
18#include <asm/machdep.h> 18#include <asm/machdep.h>
19#include <asm/pmac_feature.h> 19#include <asm/pmac_feature.h>
20#include <asm/pci-bridge.h> 20#include <asm/pci-bridge.h>
21#include <asm/prom.h> 21#include <asm/prom.h>
22#ifndef CONFIG_PM
23# define CONFIG_PM
24#endif
25#endif 22#endif
26 23
27#ifndef CONFIG_PCI 24#ifndef CONFIG_PCI
@@ -132,7 +129,7 @@ static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message)
132 /* let things settle down a bit */ 129 /* let things settle down a bit */
133 msleep (100); 130 msleep (100);
134 131
135#ifdef CONFIG_PMAC_PBOOK 132#ifdef CONFIG_PPC_PMAC
136 if (_machine == _MACH_Pmac) { 133 if (_machine == _MACH_Pmac) {
137 struct device_node *of_node; 134 struct device_node *of_node;
138 135
@@ -141,7 +138,7 @@ static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message)
141 if (of_node) 138 if (of_node)
142 pmac_call_feature(PMAC_FTR_USB_ENABLE, of_node, 0, 0); 139 pmac_call_feature(PMAC_FTR_USB_ENABLE, of_node, 0, 0);
143 } 140 }
144#endif /* CONFIG_PMAC_PBOOK */ 141#endif /* CONFIG_PPC_PMAC */
145 return 0; 142 return 0;
146} 143}
147 144
@@ -151,7 +148,7 @@ static int ohci_pci_resume (struct usb_hcd *hcd)
151 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 148 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
152 int retval = 0; 149 int retval = 0;
153 150
154#ifdef CONFIG_PMAC_PBOOK 151#ifdef CONFIG_PPC_PMAC
155 if (_machine == _MACH_Pmac) { 152 if (_machine == _MACH_Pmac) {
156 struct device_node *of_node; 153 struct device_node *of_node;
157 154
@@ -160,7 +157,7 @@ static int ohci_pci_resume (struct usb_hcd *hcd)
160 if (of_node) 157 if (of_node)
161 pmac_call_feature (PMAC_FTR_USB_ENABLE, of_node, 0, 1); 158 pmac_call_feature (PMAC_FTR_USB_ENABLE, of_node, 0, 1);
162 } 159 }
163#endif /* CONFIG_PMAC_PBOOK */ 160#endif /* CONFIG_PPC_PMAC */
164 161
165 /* resume root hub */ 162 /* resume root hub */
166 if (time_before (jiffies, ohci->next_statechange)) 163 if (time_before (jiffies, ohci->next_statechange))
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index 22e1ac138ac0..71cdd2262860 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -371,7 +371,6 @@ struct ohci_hcd {
371 * other external transceivers should be software-transparent 371 * other external transceivers should be software-transparent
372 */ 372 */
373 struct otg_transceiver *transceiver; 373 struct otg_transceiver *transceiver;
374 unsigned power_budget;
375 374
376 /* 375 /*
377 * memory management for queue data structures 376 * memory management for queue data structures
@@ -390,6 +389,7 @@ struct ohci_hcd {
390 u32 fminterval; /* saved register */ 389 u32 fminterval; /* saved register */
391 390
392 struct work_struct rh_resume; 391 struct work_struct rh_resume;
392 struct notifier_block reboot_notifier;
393 393
394 unsigned long flags; /* for HC bugs */ 394 unsigned long flags; /* for HC bugs */
395#define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */ 395#define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 99d43f758ad0..6c3f910bc307 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -1563,29 +1563,15 @@ static int
1563sl811h_start(struct usb_hcd *hcd) 1563sl811h_start(struct usb_hcd *hcd)
1564{ 1564{
1565 struct sl811 *sl811 = hcd_to_sl811(hcd); 1565 struct sl811 *sl811 = hcd_to_sl811(hcd);
1566 struct usb_device *udev;
1567 1566
1568 /* chip has been reset, VBUS power is off */ 1567 /* chip has been reset, VBUS power is off */
1569
1570 udev = usb_alloc_dev(NULL, &hcd->self, 0);
1571 if (!udev)
1572 return -ENOMEM;
1573
1574 udev->speed = USB_SPEED_FULL;
1575 hcd->state = HC_STATE_RUNNING; 1568 hcd->state = HC_STATE_RUNNING;
1576 1569
1577 if (sl811->board) 1570 if (sl811->board) {
1578 hcd->can_wakeup = sl811->board->can_wakeup; 1571 hcd->can_wakeup = sl811->board->can_wakeup;
1579 1572 hcd->power_budget = sl811->board->power * 2;
1580 if (usb_hcd_register_root_hub(udev, hcd) != 0) {
1581 usb_put_dev(udev);
1582 sl811h_stop(hcd);
1583 return -ENODEV;
1584 } 1573 }
1585 1574
1586 if (sl811->board && sl811->board->power)
1587 hub_set_power_budget(udev, sl811->board->power * 2);
1588
1589 /* enable power and interupts */ 1575 /* enable power and interupts */
1590 port_power(sl811, 1); 1576 port_power(sl811, 1);
1591 1577
diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c
index 6e173265095c..269d8ef01459 100644
--- a/drivers/usb/host/sl811_cs.c
+++ b/drivers/usb/host/sl811_cs.c
@@ -68,13 +68,6 @@ static const char driver_name[DEV_NAME_LEN] = "sl811_cs";
68 68
69static dev_link_t *dev_list = NULL; 69static dev_link_t *dev_list = NULL;
70 70
71static int irq_list[4] = { -1 };
72static int irq_list_count;
73
74module_param_array(irq_list, int, &irq_list_count, 0444);
75
76INT_MODULE_PARM(irq_mask, 0xdeb8);
77
78typedef struct local_info_t { 71typedef struct local_info_t {
79 dev_link_t link; 72 dev_link_t link;
80 dev_node_t node; 73 dev_node_t node;
@@ -373,7 +366,7 @@ static dev_link_t *sl811_cs_attach(void)
373 local_info_t *local; 366 local_info_t *local;
374 dev_link_t *link; 367 dev_link_t *link;
375 client_reg_t client_reg; 368 client_reg_t client_reg;
376 int ret, i; 369 int ret;
377 370
378 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 371 local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
379 if (!local) 372 if (!local)
@@ -385,11 +378,6 @@ static dev_link_t *sl811_cs_attach(void)
385 /* Initialize */ 378 /* Initialize */
386 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 379 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
387 link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID; 380 link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
388 if (irq_list[0] == -1)
389 link->irq.IRQInfo2 = irq_mask;
390 else
391 for (i = 0; i < irq_list_count; i++)
392 link->irq.IRQInfo2 |= 1 << irq_list[i];
393 link->irq.Handler = NULL; 381 link->irq.Handler = NULL;
394 382
395 link->conf.Attributes = 0; 383 link->conf.Attributes = 0;
@@ -418,6 +406,12 @@ static dev_link_t *sl811_cs_attach(void)
418 return link; 406 return link;
419} 407}
420 408
409static struct pcmcia_device_id sl811_ids[] = {
410 PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
411 PCMCIA_DEVICE_NULL,
412};
413MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
414
421static struct pcmcia_driver sl811_cs_driver = { 415static struct pcmcia_driver sl811_cs_driver = {
422 .owner = THIS_MODULE, 416 .owner = THIS_MODULE,
423 .drv = { 417 .drv = {
@@ -425,6 +419,7 @@ static struct pcmcia_driver sl811_cs_driver = {
425 }, 419 },
426 .attach = sl811_cs_attach, 420 .attach = sl811_cs_attach,
427 .detach = sl811_cs_detach, 421 .detach = sl811_cs_detach,
422 .id_table = sl811_ids,
428}; 423};
429 424
430/*====================================================================*/ 425/*====================================================================*/
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index 24c73c5a3435..4538a98b6f9d 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -237,6 +237,37 @@ static int uhci_show_sc(int port, unsigned short status, char *buf, int len)
237 return out - buf; 237 return out - buf;
238} 238}
239 239
240static int uhci_show_root_hub_state(struct uhci_hcd *uhci, char *buf, int len)
241{
242 char *out = buf;
243 char *rh_state;
244
245 /* Try to make sure there's enough memory */
246 if (len < 60)
247 return 0;
248
249 switch (uhci->rh_state) {
250 case UHCI_RH_RESET:
251 rh_state = "reset"; break;
252 case UHCI_RH_SUSPENDED:
253 rh_state = "suspended"; break;
254 case UHCI_RH_AUTO_STOPPED:
255 rh_state = "auto-stopped"; break;
256 case UHCI_RH_RESUMING:
257 rh_state = "resuming"; break;
258 case UHCI_RH_SUSPENDING:
259 rh_state = "suspending"; break;
260 case UHCI_RH_RUNNING:
261 rh_state = "running"; break;
262 case UHCI_RH_RUNNING_NODEVS:
263 rh_state = "running, no devs"; break;
264 default:
265 rh_state = "?"; break;
266 }
267 out += sprintf(out, "Root-hub state: %s\n", rh_state);
268 return out - buf;
269}
270
240static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len) 271static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len)
241{ 272{
242 char *out = buf; 273 char *out = buf;
@@ -408,6 +439,7 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
408 439
409 spin_lock_irqsave(&uhci->lock, flags); 440 spin_lock_irqsave(&uhci->lock, flags);
410 441
442 out += uhci_show_root_hub_state(uhci, out, len - (out - buf));
411 out += sprintf(out, "HC status\n"); 443 out += sprintf(out, "HC status\n");
412 out += uhci_show_status(uhci, out, len - (out - buf)); 444 out += uhci_show_status(uhci, out, len - (out - buf));
413 445
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 49bd83ee0c75..0d5d2545bf07 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -13,18 +13,13 @@
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 * Intel documents this fairly well, and as far as I know there 18 * Intel documents this fairly well, and as far as I know there
19 * are no royalties or anything like that, but even so there are 19 * are no royalties or anything like that, but even so there are
20 * people who decided that they want to do the same thing in a 20 * people who decided that they want to do the same thing in a
21 * completely different way. 21 * completely different way.
22 * 22 *
23 * WARNING! The USB documentation is downright evil. Most of it
24 * is just crap, written by a committee. You're better off ignoring
25 * most of it, the important stuff is:
26 * - the low-level protocol (fairly simple but lots of small details)
27 * - working around the horridness of the rest
28 */ 23 */
29 24
30#include <linux/config.h> 25#include <linux/config.h>
@@ -64,7 +59,7 @@
64/* 59/*
65 * Version Information 60 * Version Information
66 */ 61 */
67#define DRIVER_VERSION "v2.2" 62#define DRIVER_VERSION "v2.3"
68#define DRIVER_AUTHOR "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, \ 63#define DRIVER_AUTHOR "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, \
69Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, \ 64Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, \
70Alan Stern" 65Alan Stern"
@@ -89,8 +84,9 @@ static char *errbuf;
89 84
90static kmem_cache_t *uhci_up_cachep; /* urb_priv */ 85static kmem_cache_t *uhci_up_cachep; /* urb_priv */
91 86
87static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state);
88static void wakeup_rh(struct uhci_hcd *uhci);
92static void uhci_get_current_frame_number(struct uhci_hcd *uhci); 89static void uhci_get_current_frame_number(struct uhci_hcd *uhci);
93static void hc_state_transitions(struct uhci_hcd *uhci);
94 90
95/* If a transfer is still active after this much time, turn off FSBR */ 91/* If a transfer is still active after this much time, turn off FSBR */
96#define IDLE_TIMEOUT msecs_to_jiffies(50) 92#define IDLE_TIMEOUT msecs_to_jiffies(50)
@@ -101,308 +97,352 @@ static void hc_state_transitions(struct uhci_hcd *uhci);
101/* to make sure it doesn't hog all of the bandwidth */ 97/* to make sure it doesn't hog all of the bandwidth */
102#define DEPTH_INTERVAL 5 98#define DEPTH_INTERVAL 5
103 99
100static inline void restart_timer(struct uhci_hcd *uhci)
101{
102 mod_timer(&uhci->stall_timer, jiffies + msecs_to_jiffies(100));
103}
104
104#include "uhci-hub.c" 105#include "uhci-hub.c"
105#include "uhci-debug.c" 106#include "uhci-debug.c"
106#include "uhci-q.c" 107#include "uhci-q.c"
107 108
108static int init_stall_timer(struct usb_hcd *hcd); 109/*
109 110 * Make sure the controller is completely inactive, unable to
110static void stall_callback(unsigned long ptr) 111 * generate interrupts or do DMA.
112 */
113static void reset_hc(struct uhci_hcd *uhci)
111{ 114{
112 struct usb_hcd *hcd = (struct usb_hcd *)ptr; 115 int port;
113 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
114 struct urb_priv *up;
115 unsigned long flags;
116 116
117 spin_lock_irqsave(&uhci->lock, flags); 117 /* Turn off PIRQ enable and SMI enable. (This also turns off the
118 uhci_scan_schedule(uhci, NULL); 118 * BIOS's USB Legacy Support.) Turn off all the R/WC bits too.
119 119 */
120 list_for_each_entry(up, &uhci->urb_list, urb_list) { 120 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP,
121 struct urb *u = up->urb; 121 USBLEGSUP_RWC);
122
123 spin_lock(&u->lock);
124
125 /* Check if the FSBR timed out */
126 if (up->fsbr && !up->fsbr_timeout && time_after_eq(jiffies, up->fsbrtime + IDLE_TIMEOUT))
127 uhci_fsbr_timeout(uhci, u);
128 122
129 spin_unlock(&u->lock); 123 /* Reset the HC - this will force us to get a
130 } 124 * new notification of any already connected
125 * ports due to the virtual disconnect that it
126 * implies.
127 */
128 outw(USBCMD_HCRESET, uhci->io_addr + USBCMD);
129 mb();
130 udelay(5);
131 if (inw(uhci->io_addr + USBCMD) & USBCMD_HCRESET)
132 dev_warn(uhci_dev(uhci), "HCRESET not completed yet!\n");
131 133
132 /* Really disable FSBR */ 134 /* Just to be safe, disable interrupt requests and
133 if (!uhci->fsbr && uhci->fsbrtimeout && time_after_eq(jiffies, uhci->fsbrtimeout)) { 135 * make sure the controller is stopped.
134 uhci->fsbrtimeout = 0; 136 */
135 uhci->skel_term_qh->link = UHCI_PTR_TERM; 137 outw(0, uhci->io_addr + USBINTR);
136 } 138 outw(0, uhci->io_addr + USBCMD);
137 139
138 /* Poll for and perform state transitions */ 140 /* HCRESET doesn't affect the Suspend, Reset, and Resume Detect
139 hc_state_transitions(uhci); 141 * bits in the port status and control registers.
140 if (unlikely(uhci->suspended_ports && uhci->state != UHCI_SUSPENDED)) 142 * We have to clear them by hand.
141 uhci_check_ports(uhci); 143 */
144 for (port = 0; port < uhci->rh_numports; ++port)
145 outw(0, uhci->io_addr + USBPORTSC1 + (port * 2));
142 146
143 init_stall_timer(hcd); 147 uhci->port_c_suspend = uhci->suspended_ports =
144 spin_unlock_irqrestore(&uhci->lock, flags); 148 uhci->resuming_ports = 0;
149 uhci->rh_state = UHCI_RH_RESET;
150 uhci->is_stopped = UHCI_IS_STOPPED;
151 uhci_to_hcd(uhci)->state = HC_STATE_HALT;
152 uhci_to_hcd(uhci)->poll_rh = 0;
145} 153}
146 154
147static int init_stall_timer(struct usb_hcd *hcd) 155/*
156 * Last rites for a defunct/nonfunctional controller
157 * or one we don't want to use any more.
158 */
159static void hc_died(struct uhci_hcd *uhci)
148{ 160{
149 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 161 reset_hc(uhci);
150 162 uhci->hc_inaccessible = 1;
151 init_timer(&uhci->stall_timer); 163 del_timer(&uhci->stall_timer);
152 uhci->stall_timer.function = stall_callback;
153 uhci->stall_timer.data = (unsigned long)hcd;
154 uhci->stall_timer.expires = jiffies + msecs_to_jiffies(100);
155 add_timer(&uhci->stall_timer);
156
157 return 0;
158} 164}
159 165
160static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs) 166/*
167 * Initialize a controller that was newly discovered or has just been
168 * resumed. In either case we can't be sure of its previous state.
169 */
170static void check_and_reset_hc(struct uhci_hcd *uhci)
161{ 171{
162 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 172 u16 legsup;
163 unsigned long io_addr = uhci->io_addr; 173 unsigned int cmd, intr;
164 unsigned short status;
165 174
166 /* 175 /*
167 * Read the interrupt status, and write it back to clear the 176 * When restarting a suspended controller, we expect all the
168 * interrupt cause. Contrary to the UHCI specification, the 177 * settings to be the same as we left them:
169 * "HC Halted" status bit is persistent: it is RO, not R/WC. 178 *
179 * PIRQ and SMI disabled, no R/W bits set in USBLEGSUP;
180 * Controller is stopped and configured with EGSM set;
181 * No interrupts enabled except possibly Resume Detect.
182 *
183 * If any of these conditions are violated we do a complete reset.
170 */ 184 */
171 status = inw(io_addr + USBSTS); 185 pci_read_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, &legsup);
172 if (!(status & ~USBSTS_HCH)) /* shared interrupt, not mine */ 186 if (legsup & ~(USBLEGSUP_RO | USBLEGSUP_RWC)) {
173 return IRQ_NONE; 187 dev_dbg(uhci_dev(uhci), "%s: legsup = 0x%04x\n",
174 outw(status, io_addr + USBSTS); /* Clear it */ 188 __FUNCTION__, legsup);
175 189 goto reset_needed;
176 if (status & ~(USBSTS_USBINT | USBSTS_ERROR | USBSTS_RD)) {
177 if (status & USBSTS_HSE)
178 dev_err(uhci_dev(uhci), "host system error, "
179 "PCI problems?\n");
180 if (status & USBSTS_HCPE)
181 dev_err(uhci_dev(uhci), "host controller process "
182 "error, something bad happened!\n");
183 if ((status & USBSTS_HCH) && uhci->state > 0) {
184 dev_err(uhci_dev(uhci), "host controller halted, "
185 "very bad!\n");
186 /* FIXME: Reset the controller, fix the offending TD */
187 }
188 } 190 }
189 191
190 if (status & USBSTS_RD) 192 cmd = inw(uhci->io_addr + USBCMD);
191 uhci->resume_detect = 1; 193 if ((cmd & USBCMD_RS) || !(cmd & USBCMD_CF) || !(cmd & USBCMD_EGSM)) {
194 dev_dbg(uhci_dev(uhci), "%s: cmd = 0x%04x\n",
195 __FUNCTION__, cmd);
196 goto reset_needed;
197 }
192 198
193 spin_lock(&uhci->lock); 199 intr = inw(uhci->io_addr + USBINTR);
194 uhci_scan_schedule(uhci, regs); 200 if (intr & (~USBINTR_RESUME)) {
195 spin_unlock(&uhci->lock); 201 dev_dbg(uhci_dev(uhci), "%s: intr = 0x%04x\n",
202 __FUNCTION__, intr);
203 goto reset_needed;
204 }
205 return;
196 206
197 return IRQ_HANDLED; 207reset_needed:
208 dev_dbg(uhci_dev(uhci), "Performing full reset\n");
209 reset_hc(uhci);
198} 210}
199 211
200static void reset_hc(struct uhci_hcd *uhci) 212/*
213 * Store the basic register settings needed by the controller.
214 */
215static void configure_hc(struct uhci_hcd *uhci)
201{ 216{
202 unsigned long io_addr = uhci->io_addr; 217 /* Set the frame length to the default: 1 ms exactly */
218 outb(USBSOF_DEFAULT, uhci->io_addr + USBSOF);
203 219
204 /* Turn off PIRQ, SMI, and all interrupts. This also turns off 220 /* Store the frame list base address */
205 * the BIOS's USB Legacy Support. 221 outl(uhci->fl->dma_handle, uhci->io_addr + USBFLBASEADD);
206 */
207 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0);
208 outw(0, uhci->io_addr + USBINTR);
209 222
210 /* Global reset for 50ms */ 223 /* Set the current frame number */
211 uhci->state = UHCI_RESET; 224 outw(uhci->frame_number, uhci->io_addr + USBFRNUM);
212 outw(USBCMD_GRESET, io_addr + USBCMD);
213 msleep(50);
214 outw(0, io_addr + USBCMD);
215 225
216 /* Another 10ms delay */ 226 /* Mark controller as running before we enable interrupts */
217 msleep(10); 227 uhci_to_hcd(uhci)->state = HC_STATE_RUNNING;
218 uhci->resume_detect = 0; 228 mb();
219 uhci->is_stopped = UHCI_IS_STOPPED; 229
230 /* Enable PIRQ */
231 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP,
232 USBLEGSUP_DEFAULT);
220} 233}
221 234
222static void suspend_hc(struct uhci_hcd *uhci) 235
236static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci)
223{ 237{
224 unsigned long io_addr = uhci->io_addr; 238 int port;
225 239
226 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); 240 switch (to_pci_dev(uhci_dev(uhci))->vendor) {
227 uhci->state = UHCI_SUSPENDED; 241 default:
228 uhci->resume_detect = 0; 242 break;
229 outw(USBCMD_EGSM, io_addr + USBCMD);
230 243
231 /* FIXME: Wait for the controller to actually stop */ 244 case PCI_VENDOR_ID_GENESYS:
232 uhci_get_current_frame_number(uhci); 245 /* Genesys Logic's GL880S controllers don't generate
233 uhci->is_stopped = UHCI_IS_STOPPED; 246 * resume-detect interrupts.
247 */
248 return 1;
234 249
235 uhci_scan_schedule(uhci, NULL); 250 case PCI_VENDOR_ID_INTEL:
251 /* Some of Intel's USB controllers have a bug that causes
252 * resume-detect interrupts if any port has an over-current
253 * condition. To make matters worse, some motherboards
254 * hardwire unused USB ports' over-current inputs active!
255 * To prevent problems, we will not enable resume-detect
256 * interrupts if any ports are OC.
257 */
258 for (port = 0; port < uhci->rh_numports; ++port) {
259 if (inw(uhci->io_addr + USBPORTSC1 + port * 2) &
260 USBPORTSC_OC)
261 return 1;
262 }
263 break;
264 }
265 return 0;
236} 266}
237 267
238static void wakeup_hc(struct uhci_hcd *uhci) 268static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state)
269__releases(uhci->lock)
270__acquires(uhci->lock)
239{ 271{
240 unsigned long io_addr = uhci->io_addr; 272 int auto_stop;
273 int int_enable;
241 274
242 switch (uhci->state) { 275 auto_stop = (new_state == UHCI_RH_AUTO_STOPPED);
243 case UHCI_SUSPENDED: /* Start the resume */ 276 dev_dbg(uhci_dev(uhci), "%s%s\n", __FUNCTION__,
244 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); 277 (auto_stop ? " (auto-stop)" : ""));
245
246 /* Global resume for >= 20ms */
247 outw(USBCMD_FGR | USBCMD_EGSM, io_addr + USBCMD);
248 uhci->state = UHCI_RESUMING_1;
249 uhci->state_end = jiffies + msecs_to_jiffies(20);
250 uhci->is_stopped = 0;
251 break;
252 278
253 case UHCI_RESUMING_1: /* End global resume */ 279 /* If we get a suspend request when we're already auto-stopped
254 uhci->state = UHCI_RESUMING_2; 280 * then there's nothing to do.
255 outw(0, io_addr + USBCMD); 281 */
256 /* Falls through */ 282 if (uhci->rh_state == UHCI_RH_AUTO_STOPPED) {
257 283 uhci->rh_state = new_state;
258 case UHCI_RESUMING_2: /* Wait for EOP to be sent */ 284 return;
259 if (inw(io_addr + USBCMD) & USBCMD_FGR) 285 }
260 break;
261
262 /* Run for at least 1 second, and
263 * mark it configured with a 64-byte max packet */
264 uhci->state = UHCI_RUNNING_GRACE;
265 uhci->state_end = jiffies + HZ;
266 outw(USBCMD_RS | USBCMD_CF | USBCMD_MAXP,
267 io_addr + USBCMD);
268 break;
269 286
270 case UHCI_RUNNING_GRACE: /* Now allowed to suspend */ 287 /* Enable resume-detect interrupts if they work.
271 uhci->state = UHCI_RUNNING; 288 * Then enter Global Suspend mode, still configured.
272 break; 289 */
290 int_enable = (resume_detect_interrupts_are_broken(uhci) ?
291 0 : USBINTR_RESUME);
292 outw(int_enable, uhci->io_addr + USBINTR);
293 outw(USBCMD_EGSM | USBCMD_CF, uhci->io_addr + USBCMD);
294 mb();
295 udelay(5);
273 296
274 default: 297 /* If we're auto-stopping then no devices have been attached
275 break; 298 * for a while, so there shouldn't be any active URBs and the
299 * controller should stop after a few microseconds. Otherwise
300 * we will give the controller one frame to stop.
301 */
302 if (!auto_stop && !(inw(uhci->io_addr + USBSTS) & USBSTS_HCH)) {
303 uhci->rh_state = UHCI_RH_SUSPENDING;
304 spin_unlock_irq(&uhci->lock);
305 msleep(1);
306 spin_lock_irq(&uhci->lock);
307 if (uhci->hc_inaccessible) /* Died */
308 return;
276 } 309 }
277} 310 if (!(inw(uhci->io_addr + USBSTS) & USBSTS_HCH))
311 dev_warn(uhci_dev(uhci), "Controller not stopped yet!\n");
278 312
279static int ports_active(struct uhci_hcd *uhci) 313 uhci_get_current_frame_number(uhci);
280{ 314 smp_wmb();
281 unsigned long io_addr = uhci->io_addr;
282 int connection = 0;
283 int i;
284 315
285 for (i = 0; i < uhci->rh_numports; i++) 316 uhci->rh_state = new_state;
286 connection |= (inw(io_addr + USBPORTSC1 + i * 2) & USBPORTSC_CCS); 317 uhci->is_stopped = UHCI_IS_STOPPED;
318 del_timer(&uhci->stall_timer);
319 uhci_to_hcd(uhci)->poll_rh = !int_enable;
287 320
288 return connection; 321 uhci_scan_schedule(uhci, NULL);
289} 322}
290 323
291static int suspend_allowed(struct uhci_hcd *uhci) 324static void start_rh(struct uhci_hcd *uhci)
292{ 325{
293 unsigned long io_addr = uhci->io_addr; 326 uhci->is_stopped = 0;
294 int i; 327 smp_wmb();
295
296 if (to_pci_dev(uhci_dev(uhci))->vendor != PCI_VENDOR_ID_INTEL)
297 return 1;
298 328
299 /* Some of Intel's USB controllers have a bug that causes false 329 /* Mark it configured and running with a 64-byte max packet.
300 * resume indications if any port has an over current condition. 330 * All interrupts are enabled, even though RESUME won't do anything.
301 * To prevent problems, we will not allow a global suspend if
302 * any ports are OC.
303 *
304 * Some motherboards using Intel's chipsets (but not using all
305 * the USB ports) appear to hardwire the over current inputs active
306 * to disable the USB ports.
307 */ 331 */
308 332 outw(USBCMD_RS | USBCMD_CF | USBCMD_MAXP, uhci->io_addr + USBCMD);
309 /* check for over current condition on any port */ 333 outw(USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP,
310 for (i = 0; i < uhci->rh_numports; i++) { 334 uhci->io_addr + USBINTR);
311 if (inw(io_addr + USBPORTSC1 + i * 2) & USBPORTSC_OC) 335 mb();
312 return 0; 336 uhci->rh_state = UHCI_RH_RUNNING;
313 } 337 uhci_to_hcd(uhci)->poll_rh = 1;
314 338 restart_timer(uhci);
315 return 1;
316} 339}
317 340
318static void hc_state_transitions(struct uhci_hcd *uhci) 341static void wakeup_rh(struct uhci_hcd *uhci)
342__releases(uhci->lock)
343__acquires(uhci->lock)
319{ 344{
320 switch (uhci->state) { 345 dev_dbg(uhci_dev(uhci), "%s%s\n", __FUNCTION__,
321 case UHCI_RUNNING: 346 uhci->rh_state == UHCI_RH_AUTO_STOPPED ?
347 " (auto-start)" : "");
322 348
323 /* global suspend if nothing connected for 1 second */ 349 /* If we are auto-stopped then no devices are attached so there's
324 if (!ports_active(uhci) && suspend_allowed(uhci)) { 350 * no need for wakeup signals. Otherwise we send Global Resume
325 uhci->state = UHCI_SUSPENDING_GRACE; 351 * for 20 ms.
326 uhci->state_end = jiffies + HZ; 352 */
327 } 353 if (uhci->rh_state == UHCI_RH_SUSPENDED) {
328 break; 354 uhci->rh_state = UHCI_RH_RESUMING;
329 355 outw(USBCMD_FGR | USBCMD_EGSM | USBCMD_CF,
330 case UHCI_SUSPENDING_GRACE: 356 uhci->io_addr + USBCMD);
331 if (ports_active(uhci)) 357 spin_unlock_irq(&uhci->lock);
332 uhci->state = UHCI_RUNNING; 358 msleep(20);
333 else if (time_after_eq(jiffies, uhci->state_end)) 359 spin_lock_irq(&uhci->lock);
334 suspend_hc(uhci); 360 if (uhci->hc_inaccessible) /* Died */
335 break; 361 return;
336 362
337 case UHCI_SUSPENDED: 363 /* End Global Resume and wait for EOP to be sent */
338 364 outw(USBCMD_CF, uhci->io_addr + USBCMD);
339 /* wakeup if requested by a device */ 365 mb();
340 if (uhci->resume_detect) 366 udelay(4);
341 wakeup_hc(uhci); 367 if (inw(uhci->io_addr + USBCMD) & USBCMD_FGR)
342 break; 368 dev_warn(uhci_dev(uhci), "FGR not stopped yet!\n");
369 }
343 370
344 case UHCI_RESUMING_1: 371 start_rh(uhci);
345 case UHCI_RESUMING_2:
346 case UHCI_RUNNING_GRACE:
347 if (time_after_eq(jiffies, uhci->state_end))
348 wakeup_hc(uhci);
349 break;
350 372
351 default: 373 /* Restart root hub polling */
352 break; 374 mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies);
353 }
354} 375}
355 376
356/* 377static void stall_callback(unsigned long _uhci)
357 * Store the current frame number in uhci->frame_number if the controller
358 * is runnning
359 */
360static void uhci_get_current_frame_number(struct uhci_hcd *uhci)
361{ 378{
379 struct uhci_hcd *uhci = (struct uhci_hcd *) _uhci;
380 unsigned long flags;
381
382 spin_lock_irqsave(&uhci->lock, flags);
383 uhci_scan_schedule(uhci, NULL);
384 check_fsbr(uhci);
385
362 if (!uhci->is_stopped) 386 if (!uhci->is_stopped)
363 uhci->frame_number = inw(uhci->io_addr + USBFRNUM); 387 restart_timer(uhci);
388 spin_unlock_irqrestore(&uhci->lock, flags);
364} 389}
365 390
366static int start_hc(struct uhci_hcd *uhci) 391static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs)
367{ 392{
368 unsigned long io_addr = uhci->io_addr; 393 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
369 int timeout = 10; 394 unsigned short status;
395 unsigned long flags;
370 396
371 /* 397 /*
372 * Reset the HC - this will force us to get a 398 * Read the interrupt status, and write it back to clear the
373 * new notification of any already connected 399 * interrupt cause. Contrary to the UHCI specification, the
374 * ports due to the virtual disconnect that it 400 * "HC Halted" status bit is persistent: it is RO, not R/WC.
375 * implies.
376 */ 401 */
377 outw(USBCMD_HCRESET, io_addr + USBCMD); 402 status = inw(uhci->io_addr + USBSTS);
378 while (inw(io_addr + USBCMD) & USBCMD_HCRESET) { 403 if (!(status & ~USBSTS_HCH)) /* shared interrupt, not mine */
379 if (--timeout < 0) { 404 return IRQ_NONE;
380 dev_err(uhci_dev(uhci), "USBCMD_HCRESET timed out!\n"); 405 outw(status, uhci->io_addr + USBSTS); /* Clear it */
381 return -ETIMEDOUT; 406
407 if (status & ~(USBSTS_USBINT | USBSTS_ERROR | USBSTS_RD)) {
408 if (status & USBSTS_HSE)
409 dev_err(uhci_dev(uhci), "host system error, "
410 "PCI problems?\n");
411 if (status & USBSTS_HCPE)
412 dev_err(uhci_dev(uhci), "host controller process "
413 "error, something bad happened!\n");
414 if (status & USBSTS_HCH) {
415 spin_lock_irqsave(&uhci->lock, flags);
416 if (uhci->rh_state >= UHCI_RH_RUNNING) {
417 dev_err(uhci_dev(uhci),
418 "host controller halted, "
419 "very bad!\n");
420 hc_died(uhci);
421 spin_unlock_irqrestore(&uhci->lock, flags);
422 return IRQ_HANDLED;
423 }
424 spin_unlock_irqrestore(&uhci->lock, flags);
382 } 425 }
383 msleep(1);
384 } 426 }
385 427
386 /* Mark controller as running before we enable interrupts */ 428 if (status & USBSTS_RD)
387 uhci_to_hcd(uhci)->state = HC_STATE_RUNNING; 429 usb_hcd_poll_rh_status(hcd);
388
389 /* Turn on PIRQ and all interrupts */
390 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP,
391 USBLEGSUP_DEFAULT);
392 outw(USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP,
393 io_addr + USBINTR);
394 430
395 /* Start at frame 0 */ 431 spin_lock_irqsave(&uhci->lock, flags);
396 outw(0, io_addr + USBFRNUM); 432 uhci_scan_schedule(uhci, regs);
397 outl(uhci->fl->dma_handle, io_addr + USBFLBASEADD); 433 spin_unlock_irqrestore(&uhci->lock, flags);
398 434
399 /* Run and mark it configured with a 64-byte max packet */ 435 return IRQ_HANDLED;
400 uhci->state = UHCI_RUNNING_GRACE; 436}
401 uhci->state_end = jiffies + HZ;
402 outw(USBCMD_RS | USBCMD_CF | USBCMD_MAXP, io_addr + USBCMD);
403 uhci->is_stopped = 0;
404 437
405 return 0; 438/*
439 * Store the current frame number in uhci->frame_number if the controller
440 * is runnning
441 */
442static void uhci_get_current_frame_number(struct uhci_hcd *uhci)
443{
444 if (!uhci->is_stopped)
445 uhci->frame_number = inw(uhci->io_addr + USBFRNUM);
406} 446}
407 447
408/* 448/*
@@ -448,16 +488,58 @@ static void release_uhci(struct uhci_hcd *uhci)
448static int uhci_reset(struct usb_hcd *hcd) 488static int uhci_reset(struct usb_hcd *hcd)
449{ 489{
450 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 490 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
491 unsigned io_size = (unsigned) hcd->rsrc_len;
492 int port;
451 493
452 uhci->io_addr = (unsigned long) hcd->rsrc_start; 494 uhci->io_addr = (unsigned long) hcd->rsrc_start;
453 495
454 /* Kick BIOS off this hardware and reset, so we won't get 496 /* The UHCI spec says devices must have 2 ports, and goes on to say
455 * interrupts from any previous setup. 497 * they may have more but gives no way to determine how many there
498 * are. However according to the UHCI spec, Bit 7 of the port
499 * status and control register is always set to 1. So we try to
500 * use this to our advantage. Another common failure mode when
501 * a nonexistent register is addressed is to return all ones, so
502 * we test for that also.
456 */ 503 */
457 reset_hc(uhci); 504 for (port = 0; port < (io_size - USBPORTSC1) / 2; port++) {
505 unsigned int portstatus;
506
507 portstatus = inw(uhci->io_addr + USBPORTSC1 + (port * 2));
508 if (!(portstatus & 0x0080) || portstatus == 0xffff)
509 break;
510 }
511 if (debug)
512 dev_info(uhci_dev(uhci), "detected %d ports\n", port);
513
514 /* Anything greater than 7 is weird so we'll ignore it. */
515 if (port > UHCI_RH_MAXCHILD) {
516 dev_info(uhci_dev(uhci), "port count misdetected? "
517 "forcing to 2 ports\n");
518 port = 2;
519 }
520 uhci->rh_numports = port;
521
522 /* Kick BIOS off this hardware and reset if the controller
523 * isn't already safely quiescent.
524 */
525 check_and_reset_hc(uhci);
458 return 0; 526 return 0;
459} 527}
460 528
529/* Make sure the controller is quiescent and that we're not using it
530 * any more. This is mainly for the benefit of programs which, like kexec,
531 * expect the hardware to be idle: not doing DMA or generating IRQs.
532 *
533 * This routine may be called in a damaged or failing kernel. Hence we
534 * do not acquire the spinlock before shutting down the controller.
535 */
536static void uhci_shutdown(struct pci_dev *pdev)
537{
538 struct usb_hcd *hcd = (struct usb_hcd *) pci_get_drvdata(pdev);
539
540 hc_died(hcd_to_uhci(hcd));
541}
542
461/* 543/*
462 * Allocate a frame list, and then setup the skeleton 544 * Allocate a frame list, and then setup the skeleton
463 * 545 *
@@ -478,17 +560,20 @@ static int uhci_start(struct usb_hcd *hcd)
478{ 560{
479 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 561 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
480 int retval = -EBUSY; 562 int retval = -EBUSY;
481 int i, port; 563 int i;
482 unsigned io_size;
483 dma_addr_t dma_handle; 564 dma_addr_t dma_handle;
484 struct usb_device *udev;
485 struct dentry *dentry; 565 struct dentry *dentry;
486 566
487 io_size = (unsigned) hcd->rsrc_len; 567 hcd->uses_new_polling = 1;
568 if (pci_find_capability(to_pci_dev(uhci_dev(uhci)), PCI_CAP_ID_PM))
569 hcd->can_wakeup = 1; /* Assume it supports PME# */
488 570
489 dentry = debugfs_create_file(hcd->self.bus_name, S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root, uhci, &uhci_debug_operations); 571 dentry = debugfs_create_file(hcd->self.bus_name,
572 S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root, uhci,
573 &uhci_debug_operations);
490 if (!dentry) { 574 if (!dentry) {
491 dev_err(uhci_dev(uhci), "couldn't create uhci debugfs entry\n"); 575 dev_err(uhci_dev(uhci),
576 "couldn't create uhci debugfs entry\n");
492 retval = -ENOMEM; 577 retval = -ENOMEM;
493 goto err_create_debug_entry; 578 goto err_create_debug_entry;
494 } 579 }
@@ -510,6 +595,10 @@ static int uhci_start(struct usb_hcd *hcd)
510 595
511 init_waitqueue_head(&uhci->waitqh); 596 init_waitqueue_head(&uhci->waitqh);
512 597
598 init_timer(&uhci->stall_timer);
599 uhci->stall_timer.function = stall_callback;
600 uhci->stall_timer.data = (unsigned long) uhci;
601
513 uhci->fl = dma_alloc_coherent(uhci_dev(uhci), sizeof(*uhci->fl), 602 uhci->fl = dma_alloc_coherent(uhci_dev(uhci), sizeof(*uhci->fl),
514 &dma_handle, 0); 603 &dma_handle, 0);
515 if (!uhci->fl) { 604 if (!uhci->fl) {
@@ -536,46 +625,14 @@ static int uhci_start(struct usb_hcd *hcd)
536 goto err_create_qh_pool; 625 goto err_create_qh_pool;
537 } 626 }
538 627
539 /* Initialize the root hub */ 628 uhci->term_td = uhci_alloc_td(uhci);
540
541 /* UHCI specs says devices must have 2 ports, but goes on to say */
542 /* they may have more but give no way to determine how many they */
543 /* have. However, according to the UHCI spec, Bit 7 is always set */
544 /* to 1. So we try to use this to our advantage */
545 for (port = 0; port < (io_size - 0x10) / 2; port++) {
546 unsigned int portstatus;
547
548 portstatus = inw(uhci->io_addr + 0x10 + (port * 2));
549 if (!(portstatus & 0x0080))
550 break;
551 }
552 if (debug)
553 dev_info(uhci_dev(uhci), "detected %d ports\n", port);
554
555 /* This is experimental so anything less than 2 or greater than 8 is */
556 /* something weird and we'll ignore it */
557 if (port < 2 || port > UHCI_RH_MAXCHILD) {
558 dev_info(uhci_dev(uhci), "port count misdetected? "
559 "forcing to 2 ports\n");
560 port = 2;
561 }
562
563 uhci->rh_numports = port;
564
565 udev = usb_alloc_dev(NULL, &hcd->self, 0);
566 if (!udev) {
567 dev_err(uhci_dev(uhci), "unable to allocate root hub\n");
568 goto err_alloc_root_hub;
569 }
570
571 uhci->term_td = uhci_alloc_td(uhci, udev);
572 if (!uhci->term_td) { 629 if (!uhci->term_td) {
573 dev_err(uhci_dev(uhci), "unable to allocate terminating TD\n"); 630 dev_err(uhci_dev(uhci), "unable to allocate terminating TD\n");
574 goto err_alloc_term_td; 631 goto err_alloc_term_td;
575 } 632 }
576 633
577 for (i = 0; i < UHCI_NUM_SKELQH; i++) { 634 for (i = 0; i < UHCI_NUM_SKELQH; i++) {
578 uhci->skelqh[i] = uhci_alloc_qh(uhci, udev); 635 uhci->skelqh[i] = uhci_alloc_qh(uhci);
579 if (!uhci->skelqh[i]) { 636 if (!uhci->skelqh[i]) {
580 dev_err(uhci_dev(uhci), "unable to allocate QH\n"); 637 dev_err(uhci_dev(uhci), "unable to allocate QH\n");
581 goto err_alloc_skelqh; 638 goto err_alloc_skelqh;
@@ -641,32 +698,17 @@ static int uhci_start(struct usb_hcd *hcd)
641 698
642 /* 699 /*
643 * Some architectures require a full mb() to enforce completion of 700 * Some architectures require a full mb() to enforce completion of
644 * the memory writes above before the I/O transfers in start_hc(). 701 * the memory writes above before the I/O transfers in configure_hc().
645 */ 702 */
646 mb(); 703 mb();
647 if ((retval = start_hc(uhci)) != 0)
648 goto err_alloc_skelqh;
649
650 init_stall_timer(hcd);
651
652 udev->speed = USB_SPEED_FULL;
653
654 if (usb_hcd_register_root_hub(udev, hcd) != 0) {
655 dev_err(uhci_dev(uhci), "unable to start root hub\n");
656 retval = -ENOMEM;
657 goto err_start_root_hub;
658 }
659 704
705 configure_hc(uhci);
706 start_rh(uhci);
660 return 0; 707 return 0;
661 708
662/* 709/*
663 * error exits: 710 * error exits:
664 */ 711 */
665err_start_root_hub:
666 reset_hc(uhci);
667
668 del_timer_sync(&uhci->stall_timer);
669
670err_alloc_skelqh: 712err_alloc_skelqh:
671 for (i = 0; i < UHCI_NUM_SKELQH; i++) 713 for (i = 0; i < UHCI_NUM_SKELQH; i++)
672 if (uhci->skelqh[i]) { 714 if (uhci->skelqh[i]) {
@@ -678,9 +720,6 @@ err_alloc_skelqh:
678 uhci->term_td = NULL; 720 uhci->term_td = NULL;
679 721
680err_alloc_term_td: 722err_alloc_term_td:
681 usb_put_dev(udev);
682
683err_alloc_root_hub:
684 dma_pool_destroy(uhci->qh_pool); 723 dma_pool_destroy(uhci->qh_pool);
685 uhci->qh_pool = NULL; 724 uhci->qh_pool = NULL;
686 725
@@ -705,73 +744,114 @@ static void uhci_stop(struct usb_hcd *hcd)
705{ 744{
706 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 745 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
707 746
708 del_timer_sync(&uhci->stall_timer);
709 reset_hc(uhci);
710
711 spin_lock_irq(&uhci->lock); 747 spin_lock_irq(&uhci->lock);
748 reset_hc(uhci);
712 uhci_scan_schedule(uhci, NULL); 749 uhci_scan_schedule(uhci, NULL);
713 spin_unlock_irq(&uhci->lock); 750 spin_unlock_irq(&uhci->lock);
714 751
752 del_timer_sync(&uhci->stall_timer);
715 release_uhci(uhci); 753 release_uhci(uhci);
716} 754}
717 755
718#ifdef CONFIG_PM 756#ifdef CONFIG_PM
757static int uhci_rh_suspend(struct usb_hcd *hcd)
758{
759 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
760
761 spin_lock_irq(&uhci->lock);
762 if (!uhci->hc_inaccessible) /* Not dead */
763 suspend_rh(uhci, UHCI_RH_SUSPENDED);
764 spin_unlock_irq(&uhci->lock);
765 return 0;
766}
767
768static int uhci_rh_resume(struct usb_hcd *hcd)
769{
770 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
771 int rc = 0;
772
773 spin_lock_irq(&uhci->lock);
774 if (uhci->hc_inaccessible) {
775 if (uhci->rh_state == UHCI_RH_SUSPENDED) {
776 dev_warn(uhci_dev(uhci), "HC isn't running!\n");
777 rc = -ENODEV;
778 }
779 /* Otherwise the HC is dead */
780 } else
781 wakeup_rh(uhci);
782 spin_unlock_irq(&uhci->lock);
783 return rc;
784}
785
719static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message) 786static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message)
720{ 787{
721 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 788 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
789 int rc = 0;
790
791 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__);
722 792
723 spin_lock_irq(&uhci->lock); 793 spin_lock_irq(&uhci->lock);
794 if (uhci->hc_inaccessible) /* Dead or already suspended */
795 goto done;
724 796
725 /* Don't try to suspend broken motherboards, reset instead */ 797#ifndef CONFIG_USB_SUSPEND
726 if (suspend_allowed(uhci)) 798 /* Otherwise this would never happen */
727 suspend_hc(uhci); 799 suspend_rh(uhci, UHCI_RH_SUSPENDED);
728 else { 800#endif
729 spin_unlock_irq(&uhci->lock); 801
730 reset_hc(uhci); 802 if (uhci->rh_state > UHCI_RH_SUSPENDED) {
731 spin_lock_irq(&uhci->lock); 803 dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n");
732 uhci_scan_schedule(uhci, NULL); 804 hcd->state = HC_STATE_RUNNING;
733 } 805 rc = -EBUSY;
806 goto done;
807 };
734 808
809 /* All PCI host controllers are required to disable IRQ generation
810 * at the source, so we must turn off PIRQ.
811 */
812 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0);
813 uhci->hc_inaccessible = 1;
814
815 /* FIXME: Enable non-PME# remote wakeup? */
816
817done:
735 spin_unlock_irq(&uhci->lock); 818 spin_unlock_irq(&uhci->lock);
736 return 0; 819 if (rc == 0)
820 del_timer_sync(&hcd->rh_timer);
821 return rc;
737} 822}
738 823
739static int uhci_resume(struct usb_hcd *hcd) 824static int uhci_resume(struct usb_hcd *hcd)
740{ 825{
741 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 826 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
742 int rc;
743 827
744 pci_set_master(to_pci_dev(uhci_dev(uhci))); 828 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__);
745 829
830 if (uhci->rh_state == UHCI_RH_RESET) /* Dead */
831 return 0;
746 spin_lock_irq(&uhci->lock); 832 spin_lock_irq(&uhci->lock);
747 833
748 if (uhci->state == UHCI_SUSPENDED) { 834 /* FIXME: Disable non-PME# remote wakeup? */
749 835
750 /* 836 uhci->hc_inaccessible = 0;
751 * Some systems don't maintain the UHCI register values 837
752 * during a PM suspend/resume cycle, so reinitialize 838 /* The BIOS may have changed the controller settings during a
753 * the Frame Number, Framelist Base Address, Interrupt 839 * system wakeup. Check it and reconfigure to avoid problems.
754 * Enable, and Legacy Support registers. 840 */
755 */ 841 check_and_reset_hc(uhci);
756 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 842 configure_hc(uhci);
757 0); 843
758 outw(uhci->frame_number, uhci->io_addr + USBFRNUM); 844#ifndef CONFIG_USB_SUSPEND
759 outl(uhci->fl->dma_handle, uhci->io_addr + USBFLBASEADD); 845 /* Otherwise this would never happen */
760 outw(USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | 846 wakeup_rh(uhci);
761 USBINTR_SP, uhci->io_addr + USBINTR); 847#endif
762 uhci->resume_detect = 1; 848 if (uhci->rh_state == UHCI_RH_RESET)
763 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 849 suspend_rh(uhci, UHCI_RH_SUSPENDED);
764 USBLEGSUP_DEFAULT);
765 } else {
766 spin_unlock_irq(&uhci->lock);
767 reset_hc(uhci);
768 if ((rc = start_hc(uhci)) != 0)
769 return rc;
770 spin_lock_irq(&uhci->lock);
771 }
772 hcd->state = HC_STATE_RUNNING;
773 850
774 spin_unlock_irq(&uhci->lock); 851 spin_unlock_irq(&uhci->lock);
852
853 if (hcd->poll_rh)
854 usb_hcd_poll_rh_status(hcd);
775 return 0; 855 return 0;
776} 856}
777#endif 857#endif
@@ -788,13 +868,15 @@ static void uhci_hcd_endpoint_disable(struct usb_hcd *hcd,
788static int uhci_hcd_get_frame_number(struct usb_hcd *hcd) 868static int uhci_hcd_get_frame_number(struct usb_hcd *hcd)
789{ 869{
790 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 870 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
791 int frame_number;
792 unsigned long flags; 871 unsigned long flags;
872 int is_stopped;
873 int frame_number;
793 874
794 /* Minimize latency by avoiding the spinlock */ 875 /* Minimize latency by avoiding the spinlock */
795 local_irq_save(flags); 876 local_irq_save(flags);
796 rmb(); 877 is_stopped = uhci->is_stopped;
797 frame_number = (uhci->is_stopped ? uhci->frame_number : 878 smp_rmb();
879 frame_number = (is_stopped ? uhci->frame_number :
798 inw(uhci->io_addr + USBFRNUM)); 880 inw(uhci->io_addr + USBFRNUM));
799 local_irq_restore(flags); 881 local_irq_restore(flags);
800 return frame_number; 882 return frame_number;
@@ -817,6 +899,8 @@ static const struct hc_driver uhci_driver = {
817#ifdef CONFIG_PM 899#ifdef CONFIG_PM
818 .suspend = uhci_suspend, 900 .suspend = uhci_suspend,
819 .resume = uhci_resume, 901 .resume = uhci_resume,
902 .hub_suspend = uhci_rh_suspend,
903 .hub_resume = uhci_rh_resume,
820#endif 904#endif
821 .stop = uhci_stop, 905 .stop = uhci_stop,
822 906
@@ -845,6 +929,7 @@ static struct pci_driver uhci_pci_driver = {
845 929
846 .probe = usb_hcd_pci_probe, 930 .probe = usb_hcd_pci_probe,
847 .remove = usb_hcd_pci_remove, 931 .remove = usb_hcd_pci_remove,
932 .shutdown = uhci_shutdown,
848 933
849#ifdef CONFIG_PM 934#ifdef CONFIG_PM
850 .suspend = usb_hcd_pci_suspend, 935 .suspend = usb_hcd_pci_suspend,
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index 02255d69e1fe..bf9c5f9b508b 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -41,6 +41,7 @@
41#define USBFRNUM 6 41#define USBFRNUM 6
42#define USBFLBASEADD 8 42#define USBFLBASEADD 8
43#define USBSOF 12 43#define USBSOF 12
44#define USBSOF_DEFAULT 64 /* Frame length is exactly 1 ms */
44 45
45/* USB port status and control registers */ 46/* USB port status and control registers */
46#define USBPORTSC1 16 47#define USBPORTSC1 16
@@ -66,6 +67,8 @@
66/* Legacy support register */ 67/* Legacy support register */
67#define USBLEGSUP 0xc0 68#define USBLEGSUP 0xc0
68#define USBLEGSUP_DEFAULT 0x2000 /* only PIRQ enable set */ 69#define USBLEGSUP_DEFAULT 0x2000 /* only PIRQ enable set */
70#define USBLEGSUP_RWC 0x8f00 /* the R/WC bits */
71#define USBLEGSUP_RO 0x5040 /* R/O and reserved bits */
69 72
70#define UHCI_NULL_DATA_SIZE 0x7FF /* for UHCI controller TD */ 73#define UHCI_NULL_DATA_SIZE 0x7FF /* for UHCI controller TD */
71 74
@@ -111,7 +114,6 @@ struct uhci_qh {
111 /* Software fields */ 114 /* Software fields */
112 dma_addr_t dma_handle; 115 dma_addr_t dma_handle;
113 116
114 struct usb_device *dev;
115 struct urb_priv *urbp; 117 struct urb_priv *urbp;
116 118
117 struct list_head list; /* P: uhci->frame_list_lock */ 119 struct list_head list; /* P: uhci->frame_list_lock */
@@ -203,7 +205,6 @@ struct uhci_td {
203 /* Software fields */ 205 /* Software fields */
204 dma_addr_t dma_handle; 206 dma_addr_t dma_handle;
205 207
206 struct usb_device *dev;
207 struct urb *urb; 208 struct urb *urb;
208 209
209 struct list_head list; /* P: urb->lock */ 210 struct list_head list; /* P: urb->lock */
@@ -314,26 +315,32 @@ static inline int __interval_to_skel(int interval)
314} 315}
315 316
316/* 317/*
317 * Device states for the host controller. 318 * States for the root hub.
318 * 319 *
319 * To prevent "bouncing" in the presence of electrical noise, 320 * To prevent "bouncing" in the presence of electrical noise,
320 * we insist on a 1-second "grace" period, before switching to 321 * when there are no devices attached we delay for 1 second in the
321 * the RUNNING or SUSPENDED states, during which the state is 322 * RUNNING_NODEVS state before switching to the AUTO_STOPPED state.
322 * not allowed to change. 323 *
323 * 324 * (Note that the AUTO_STOPPED state won't be necessary once the hub
324 * The resume process is divided into substates in order to avoid 325 * driver learns to autosuspend.)
325 * potentially length delays during the timer handler.
326 *
327 * States in which the host controller is halted must have values <= 0.
328 */ 326 */
329enum uhci_state { 327enum uhci_rh_state {
330 UHCI_RESET, 328 /* In the following states the HC must be halted.
331 UHCI_RUNNING_GRACE, /* Before RUNNING */ 329 * These two must come first */
332 UHCI_RUNNING, /* The normal state */ 330 UHCI_RH_RESET,
333 UHCI_SUSPENDING_GRACE, /* Before SUSPENDED */ 331 UHCI_RH_SUSPENDED,
334 UHCI_SUSPENDED = -10, /* When no devices are attached */ 332
335 UHCI_RESUMING_1, 333 UHCI_RH_AUTO_STOPPED,
336 UHCI_RESUMING_2 334 UHCI_RH_RESUMING,
335
336 /* In this state the HC changes from running to halted,
337 * so it can legally appear either way. */
338 UHCI_RH_SUSPENDING,
339
340 /* In the following states it's an error if the HC is halted.
341 * These two must come last */
342 UHCI_RH_RUNNING, /* The normal state */
343 UHCI_RH_RUNNING_NODEVS, /* Running with no devices attached */
337}; 344};
338 345
339/* 346/*
@@ -363,15 +370,16 @@ struct uhci_hcd {
363 int fsbr; /* Full-speed bandwidth reclamation */ 370 int fsbr; /* Full-speed bandwidth reclamation */
364 unsigned long fsbrtimeout; /* FSBR delay */ 371 unsigned long fsbrtimeout; /* FSBR delay */
365 372
366 enum uhci_state state; /* FIXME: needs a spinlock */ 373 enum uhci_rh_state rh_state;
367 unsigned long state_end; /* Time of next transition */ 374 unsigned long auto_stop_time; /* When to AUTO_STOP */
375
368 unsigned int frame_number; /* As of last check */ 376 unsigned int frame_number; /* As of last check */
369 unsigned int is_stopped; 377 unsigned int is_stopped;
370#define UHCI_IS_STOPPED 9999 /* Larger than a frame # */ 378#define UHCI_IS_STOPPED 9999 /* Larger than a frame # */
371 379
372 unsigned int scan_in_progress:1; /* Schedule scan is running */ 380 unsigned int scan_in_progress:1; /* Schedule scan is running */
373 unsigned int need_rescan:1; /* Redo the schedule scan */ 381 unsigned int need_rescan:1; /* Redo the schedule scan */
374 unsigned int resume_detect:1; /* Need a Global Resume */ 382 unsigned int hc_inaccessible:1; /* HC is suspended or dead */
375 383
376 /* Support for port suspend/resume/reset */ 384 /* Support for port suspend/resume/reset */
377 unsigned long port_c_suspend; /* Bit-arrays of ports */ 385 unsigned long port_c_suspend; /* Bit-arrays of ports */
@@ -451,4 +459,11 @@ struct urb_priv {
451 * #2 urb->lock 459 * #2 urb->lock
452 */ 460 */
453 461
462
463/* Some special IDs */
464
465#define PCI_VENDOR_ID_GENESYS 0x17a0
466#define PCI_DEVICE_ID_GL880S_UHCI 0x8083
467#define PCI_DEVICE_ID_GL880S_EHCI 0x8084
468
454#endif 469#endif
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index 4c45ba8390f8..4eace2b19ddb 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -33,9 +33,24 @@ static __u8 root_hub_hub_des[] =
33/* status change bits: nonzero writes will clear */ 33/* status change bits: nonzero writes will clear */
34#define RWC_BITS (USBPORTSC_OCC | USBPORTSC_PEC | USBPORTSC_CSC) 34#define RWC_BITS (USBPORTSC_OCC | USBPORTSC_PEC | USBPORTSC_CSC)
35 35
36static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf) 36/* A port that either is connected or has a changed-bit set will prevent
37 * us from AUTO_STOPPING.
38 */
39static int any_ports_active(struct uhci_hcd *uhci)
40{
41 int port;
42
43 for (port = 0; port < uhci->rh_numports; ++port) {
44 if ((inw(uhci->io_addr + USBPORTSC1 + port * 2) &
45 (USBPORTSC_CCS | RWC_BITS)) ||
46 test_bit(port, &uhci->port_c_suspend))
47 return 1;
48 }
49 return 0;
50}
51
52static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf)
37{ 53{
38 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
39 int port; 54 int port;
40 55
41 *buf = 0; 56 *buf = 0;
@@ -44,8 +59,6 @@ static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf)
44 test_bit(port, &uhci->port_c_suspend)) 59 test_bit(port, &uhci->port_c_suspend))
45 *buf |= (1 << (port + 1)); 60 *buf |= (1 << (port + 1));
46 } 61 }
47 if (*buf && uhci->state == UHCI_SUSPENDED)
48 uhci->resume_detect = 1;
49 return !!*buf; 62 return !!*buf;
50} 63}
51 64
@@ -115,6 +128,11 @@ static void uhci_check_ports(struct uhci_hcd *uhci)
115 set_bit(port, &uhci->resuming_ports); 128 set_bit(port, &uhci->resuming_ports);
116 uhci->ports_timeout = jiffies + 129 uhci->ports_timeout = jiffies +
117 msecs_to_jiffies(20); 130 msecs_to_jiffies(20);
131
132 /* Make sure we see the port again
133 * after the resuming period is over. */
134 mod_timer(&uhci_to_hcd(uhci)->rh_timer,
135 uhci->ports_timeout);
118 } else if (time_after_eq(jiffies, 136 } else if (time_after_eq(jiffies,
119 uhci->ports_timeout)) { 137 uhci->ports_timeout)) {
120 uhci_finish_suspend(uhci, port, port_addr); 138 uhci_finish_suspend(uhci, port, port_addr);
@@ -123,6 +141,60 @@ static void uhci_check_ports(struct uhci_hcd *uhci)
123 } 141 }
124} 142}
125 143
144static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf)
145{
146 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
147 unsigned long flags;
148 int status;
149
150 spin_lock_irqsave(&uhci->lock, flags);
151 if (uhci->hc_inaccessible) {
152 status = 0;
153 goto done;
154 }
155
156 uhci_check_ports(uhci);
157 status = get_hub_status_data(uhci, buf);
158
159 switch (uhci->rh_state) {
160 case UHCI_RH_SUSPENDING:
161 case UHCI_RH_SUSPENDED:
162 /* if port change, ask to be resumed */
163 if (status)
164 usb_hcd_resume_root_hub(hcd);
165 break;
166
167 case UHCI_RH_AUTO_STOPPED:
168 /* if port change, auto start */
169 if (status)
170 wakeup_rh(uhci);
171 break;
172
173 case UHCI_RH_RUNNING:
174 /* are any devices attached? */
175 if (!any_ports_active(uhci)) {
176 uhci->rh_state = UHCI_RH_RUNNING_NODEVS;
177 uhci->auto_stop_time = jiffies + HZ;
178 }
179 break;
180
181 case UHCI_RH_RUNNING_NODEVS:
182 /* auto-stop if nothing connected for 1 second */
183 if (any_ports_active(uhci))
184 uhci->rh_state = UHCI_RH_RUNNING;
185 else if (time_after_eq(jiffies, uhci->auto_stop_time))
186 suspend_rh(uhci, UHCI_RH_AUTO_STOPPED);
187 break;
188
189 default:
190 break;
191 }
192
193done:
194 spin_unlock_irqrestore(&uhci->lock, flags);
195 return status;
196}
197
126/* size of returned buffer is part of USB spec */ 198/* size of returned buffer is part of USB spec */
127static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 199static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
128 u16 wIndex, char *buf, u16 wLength) 200 u16 wIndex, char *buf, u16 wLength)
@@ -134,6 +206,9 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
134 u16 wPortChange, wPortStatus; 206 u16 wPortChange, wPortStatus;
135 unsigned long flags; 207 unsigned long flags;
136 208
209 if (uhci->hc_inaccessible)
210 return -ETIMEDOUT;
211
137 spin_lock_irqsave(&uhci->lock, flags); 212 spin_lock_irqsave(&uhci->lock, flags);
138 switch (typeReq) { 213 switch (typeReq) {
139 214
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 2a7c19501f24..5f18084a116d 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -32,6 +32,8 @@ static void uhci_free_pending_tds(struct uhci_hcd *uhci);
32 */ 32 */
33static inline void uhci_set_next_interrupt(struct uhci_hcd *uhci) 33static inline void uhci_set_next_interrupt(struct uhci_hcd *uhci)
34{ 34{
35 if (uhci->is_stopped)
36 mod_timer(&uhci->stall_timer, jiffies);
35 uhci->term_td->status |= cpu_to_le32(TD_CTRL_IOC); 37 uhci->term_td->status |= cpu_to_le32(TD_CTRL_IOC);
36} 38}
37 39
@@ -46,7 +48,7 @@ static inline void uhci_moveto_complete(struct uhci_hcd *uhci,
46 list_move_tail(&urbp->urb_list, &uhci->complete_list); 48 list_move_tail(&urbp->urb_list, &uhci->complete_list);
47} 49}
48 50
49static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci, struct usb_device *dev) 51static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci)
50{ 52{
51 dma_addr_t dma_handle; 53 dma_addr_t dma_handle;
52 struct uhci_td *td; 54 struct uhci_td *td;
@@ -61,14 +63,11 @@ static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci, struct usb_device *d
61 td->buffer = 0; 63 td->buffer = 0;
62 64
63 td->frame = -1; 65 td->frame = -1;
64 td->dev = dev;
65 66
66 INIT_LIST_HEAD(&td->list); 67 INIT_LIST_HEAD(&td->list);
67 INIT_LIST_HEAD(&td->remove_list); 68 INIT_LIST_HEAD(&td->remove_list);
68 INIT_LIST_HEAD(&td->fl_list); 69 INIT_LIST_HEAD(&td->fl_list);
69 70
70 usb_get_dev(dev);
71
72 return td; 71 return td;
73} 72}
74 73
@@ -168,13 +167,10 @@ static void uhci_free_td(struct uhci_hcd *uhci, struct uhci_td *td)
168 if (!list_empty(&td->fl_list)) 167 if (!list_empty(&td->fl_list))
169 dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td); 168 dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td);
170 169
171 if (td->dev)
172 usb_put_dev(td->dev);
173
174 dma_pool_free(uhci->td_pool, td, td->dma_handle); 170 dma_pool_free(uhci->td_pool, td, td->dma_handle);
175} 171}
176 172
177static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, struct usb_device *dev) 173static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci)
178{ 174{
179 dma_addr_t dma_handle; 175 dma_addr_t dma_handle;
180 struct uhci_qh *qh; 176 struct uhci_qh *qh;
@@ -188,14 +184,11 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, struct usb_device *d
188 qh->element = UHCI_PTR_TERM; 184 qh->element = UHCI_PTR_TERM;
189 qh->link = UHCI_PTR_TERM; 185 qh->link = UHCI_PTR_TERM;
190 186
191 qh->dev = dev;
192 qh->urbp = NULL; 187 qh->urbp = NULL;
193 188
194 INIT_LIST_HEAD(&qh->list); 189 INIT_LIST_HEAD(&qh->list);
195 INIT_LIST_HEAD(&qh->remove_list); 190 INIT_LIST_HEAD(&qh->remove_list);
196 191
197 usb_get_dev(dev);
198
199 return qh; 192 return qh;
200} 193}
201 194
@@ -206,9 +199,6 @@ static void uhci_free_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
206 if (!list_empty(&qh->remove_list)) 199 if (!list_empty(&qh->remove_list))
207 dev_warn(uhci_dev(uhci), "qh %p still in remove_list!\n", qh); 200 dev_warn(uhci_dev(uhci), "qh %p still in remove_list!\n", qh);
208 201
209 if (qh->dev)
210 usb_put_dev(qh->dev);
211
212 dma_pool_free(uhci->qh_pool, qh, qh->dma_handle); 202 dma_pool_free(uhci->qh_pool, qh, qh->dma_handle);
213} 203}
214 204
@@ -597,7 +587,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, struct ur
597 /* 587 /*
598 * Build the TD for the control request setup packet 588 * Build the TD for the control request setup packet
599 */ 589 */
600 td = uhci_alloc_td(uhci, urb->dev); 590 td = uhci_alloc_td(uhci);
601 if (!td) 591 if (!td)
602 return -ENOMEM; 592 return -ENOMEM;
603 593
@@ -626,7 +616,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, struct ur
626 if (pktsze > maxsze) 616 if (pktsze > maxsze)
627 pktsze = maxsze; 617 pktsze = maxsze;
628 618
629 td = uhci_alloc_td(uhci, urb->dev); 619 td = uhci_alloc_td(uhci);
630 if (!td) 620 if (!td)
631 return -ENOMEM; 621 return -ENOMEM;
632 622
@@ -644,7 +634,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, struct ur
644 /* 634 /*
645 * Build the final TD for control status 635 * Build the final TD for control status
646 */ 636 */
647 td = uhci_alloc_td(uhci, urb->dev); 637 td = uhci_alloc_td(uhci);
648 if (!td) 638 if (!td)
649 return -ENOMEM; 639 return -ENOMEM;
650 640
@@ -666,7 +656,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, struct ur
666 uhci_fill_td(td, status | TD_CTRL_IOC, 656 uhci_fill_td(td, status | TD_CTRL_IOC,
667 destination | uhci_explen(UHCI_NULL_DATA_SIZE), 0); 657 destination | uhci_explen(UHCI_NULL_DATA_SIZE), 0);
668 658
669 qh = uhci_alloc_qh(uhci, urb->dev); 659 qh = uhci_alloc_qh(uhci);
670 if (!qh) 660 if (!qh)
671 return -ENOMEM; 661 return -ENOMEM;
672 662
@@ -865,7 +855,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, struct urb
865 status &= ~TD_CTRL_SPD; 855 status &= ~TD_CTRL_SPD;
866 } 856 }
867 857
868 td = uhci_alloc_td(uhci, urb->dev); 858 td = uhci_alloc_td(uhci);
869 if (!td) 859 if (!td)
870 return -ENOMEM; 860 return -ENOMEM;
871 861
@@ -891,7 +881,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, struct urb
891 */ 881 */
892 if (usb_pipeout(urb->pipe) && (urb->transfer_flags & URB_ZERO_PACKET) && 882 if (usb_pipeout(urb->pipe) && (urb->transfer_flags & URB_ZERO_PACKET) &&
893 !len && urb->transfer_buffer_length) { 883 !len && urb->transfer_buffer_length) {
894 td = uhci_alloc_td(uhci, urb->dev); 884 td = uhci_alloc_td(uhci);
895 if (!td) 885 if (!td)
896 return -ENOMEM; 886 return -ENOMEM;
897 887
@@ -913,7 +903,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, struct urb
913 * flag setting. */ 903 * flag setting. */
914 td->status |= cpu_to_le32(TD_CTRL_IOC); 904 td->status |= cpu_to_le32(TD_CTRL_IOC);
915 905
916 qh = uhci_alloc_qh(uhci, urb->dev); 906 qh = uhci_alloc_qh(uhci);
917 if (!qh) 907 if (!qh)
918 return -ENOMEM; 908 return -ENOMEM;
919 909
@@ -1096,7 +1086,7 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb)
1096 if (!urb->iso_frame_desc[i].length) 1086 if (!urb->iso_frame_desc[i].length)
1097 continue; 1087 continue;
1098 1088
1099 td = uhci_alloc_td(uhci, urb->dev); 1089 td = uhci_alloc_td(uhci);
1100 if (!td) 1090 if (!td)
1101 return -ENOMEM; 1091 return -ENOMEM;
1102 1092
@@ -1497,6 +1487,7 @@ static void uhci_scan_schedule(struct uhci_hcd *uhci, struct pt_regs *regs)
1497 rescan: 1487 rescan:
1498 uhci->need_rescan = 0; 1488 uhci->need_rescan = 0;
1499 1489
1490 uhci_clear_next_interrupt(uhci);
1500 uhci_get_current_frame_number(uhci); 1491 uhci_get_current_frame_number(uhci);
1501 1492
1502 if (uhci->frame_number + uhci->is_stopped != uhci->qh_remove_age) 1493 if (uhci->frame_number + uhci->is_stopped != uhci->qh_remove_age)
@@ -1537,3 +1528,26 @@ static void uhci_scan_schedule(struct uhci_hcd *uhci, struct pt_regs *regs)
1537 /* Wake up anyone waiting for an URB to complete */ 1528 /* Wake up anyone waiting for an URB to complete */
1538 wake_up_all(&uhci->waitqh); 1529 wake_up_all(&uhci->waitqh);
1539} 1530}
1531
1532static void check_fsbr(struct uhci_hcd *uhci)
1533{
1534 struct urb_priv *up;
1535
1536 list_for_each_entry(up, &uhci->urb_list, urb_list) {
1537 struct urb *u = up->urb;
1538
1539 spin_lock(&u->lock);
1540
1541 /* Check if the FSBR timed out */
1542 if (up->fsbr && !up->fsbr_timeout && time_after_eq(jiffies, up->fsbrtime + IDLE_TIMEOUT))
1543 uhci_fsbr_timeout(uhci, u);
1544
1545 spin_unlock(&u->lock);
1546 }
1547
1548 /* Really disable FSBR */
1549 if (!uhci->fsbr && uhci->fsbrtimeout && time_after_eq(jiffies, uhci->fsbrtimeout)) {
1550 uhci->fsbrtimeout = 0;
1551 uhci->skel_term_qh->link = UHCI_PTR_TERM;
1552 }
1553}
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index d28e7eab6f98..fd59f6bdd67f 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -151,6 +151,18 @@ config USB_WACOM
151 To compile this driver as a module, choose M here: the 151 To compile this driver as a module, choose M here: the
152 module will be called wacom. 152 module will be called wacom.
153 153
154config USB_ACECAD
155 tristate "Acecad Flair tablet support"
156 depends on USB && INPUT
157 help
158 Say Y here if you want to use the USB version of the Acecad Flair
159 tablet. Make sure to say Y to "Mouse support"
160 (CONFIG_INPUT_MOUSEDEV) and/or "Event interface support"
161 (CONFIG_INPUT_EVDEV) as well.
162
163 To compile this driver as a module, choose M here: the
164 module will be called acecad.
165
154config USB_KBTAB 166config USB_KBTAB
155 tristate "KB Gear JamStudio tablet support" 167 tristate "KB Gear JamStudio tablet support"
156 depends on USB && INPUT 168 depends on USB && INPUT
@@ -190,6 +202,18 @@ config USB_MTOUCH
190 To compile this driver as a module, choose M here: the 202 To compile this driver as a module, choose M here: the
191 module will be called mtouchusb. 203 module will be called mtouchusb.
192 204
205config USB_ITMTOUCH
206 tristate "ITM Touch USB Touchscreen Driver"
207 depends on USB && INPUT
208 ---help---
209 Say Y here if you want to use a ITM Touch USB
210 Touchscreen controller.
211
212 This touchscreen is used in LG 1510SF monitors.
213
214 To compile this driver as a module, choose M here: the
215 module will be called itmtouch.
216
193config USB_EGALAX 217config USB_EGALAX
194 tristate "eGalax TouchKit USB Touchscreen Driver" 218 tristate "eGalax TouchKit USB Touchscreen Driver"
195 depends on USB && INPUT 219 depends on USB && INPUT
diff --git a/drivers/usb/input/Makefile b/drivers/usb/input/Makefile
index 6bcedd16b0a1..831b2b0f1f05 100644
--- a/drivers/usb/input/Makefile
+++ b/drivers/usb/input/Makefile
@@ -33,7 +33,9 @@ obj-$(CONFIG_USB_KBD) += usbkbd.o
33obj-$(CONFIG_USB_KBTAB) += kbtab.o 33obj-$(CONFIG_USB_KBTAB) += kbtab.o
34obj-$(CONFIG_USB_MOUSE) += usbmouse.o 34obj-$(CONFIG_USB_MOUSE) += usbmouse.o
35obj-$(CONFIG_USB_MTOUCH) += mtouchusb.o 35obj-$(CONFIG_USB_MTOUCH) += mtouchusb.o
36obj-$(CONFIG_USB_ITMTOUCH) += itmtouch.o
36obj-$(CONFIG_USB_EGALAX) += touchkitusb.o 37obj-$(CONFIG_USB_EGALAX) += touchkitusb.o
37obj-$(CONFIG_USB_POWERMATE) += powermate.o 38obj-$(CONFIG_USB_POWERMATE) += powermate.o
38obj-$(CONFIG_USB_WACOM) += wacom.o 39obj-$(CONFIG_USB_WACOM) += wacom.o
40obj-$(CONFIG_USB_ACECAD) += acecad.o
39obj-$(CONFIG_USB_XPAD) += xpad.o 41obj-$(CONFIG_USB_XPAD) += xpad.o
diff --git a/drivers/usb/input/acecad.c b/drivers/usb/input/acecad.c
new file mode 100644
index 000000000000..ebcf7c955800
--- /dev/null
+++ b/drivers/usb/input/acecad.c
@@ -0,0 +1,285 @@
1/*
2 * Copyright (c) 2001-2005 Edouard TISSERANT <edouard.tisserant@wanadoo.fr>
3 * Copyright (c) 2004-2005 Stephane VOLTZ <svoltz@numericable.fr>
4 *
5 * USB Acecad "Acecad Flair" tablet support
6 *
7 * Changelog:
8 * v3.2 - Added sysfs support
9 */
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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28#include <linux/kernel.h>
29#include <linux/slab.h>
30#include <linux/input.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/usb.h>
34
35/*
36 * Version Information
37 */
38#define DRIVER_VERSION "v3.2"
39#define DRIVER_DESC "USB Acecad Flair tablet driver"
40#define DRIVER_LICENSE "GPL"
41#define DRIVER_AUTHOR "Edouard TISSERANT <edouard.tisserant@wanadoo.fr>"
42
43MODULE_AUTHOR(DRIVER_AUTHOR);
44MODULE_DESCRIPTION(DRIVER_DESC);
45MODULE_LICENSE(DRIVER_LICENSE);
46
47#define USB_VENDOR_ID_ACECAD 0x0460
48#define USB_DEVICE_ID_FLAIR 0x0004
49#define USB_DEVICE_ID_302 0x0008
50
51struct usb_acecad {
52 char name[128];
53 char phys[64];
54 struct usb_device *usbdev;
55 struct input_dev dev;
56 struct urb *irq;
57
58 signed char *data;
59 dma_addr_t data_dma;
60};
61
62static void usb_acecad_irq(struct urb *urb, struct pt_regs *regs)
63{
64 struct usb_acecad *acecad = urb->context;
65 unsigned char *data = acecad->data;
66 struct input_dev *dev = &acecad->dev;
67 int prox, status;
68
69 switch (urb->status) {
70 case 0:
71 /* success */
72 break;
73 case -ECONNRESET:
74 case -ENOENT:
75 case -ESHUTDOWN:
76 /* this urb is terminated, clean up */
77 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
78 return;
79 default:
80 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
81 goto resubmit;
82 }
83
84 prox = (data[0] & 0x04) >> 2;
85 input_report_key(dev, BTN_TOOL_PEN, prox);
86
87 if (prox) {
88 int x = data[1] | (data[2] << 8);
89 int y = data[3] | (data[4] << 8);
90 /*Pressure should compute the same way for flair and 302*/
91 int pressure = data[5] | ((int)data[6] << 8);
92 int touch = data[0] & 0x01;
93 int stylus = (data[0] & 0x10) >> 4;
94 int stylus2 = (data[0] & 0x20) >> 5;
95 input_report_abs(dev, ABS_X, x);
96 input_report_abs(dev, ABS_Y, y);
97 input_report_abs(dev, ABS_PRESSURE, pressure);
98 input_report_key(dev, BTN_TOUCH, touch);
99 input_report_key(dev, BTN_STYLUS, stylus);
100 input_report_key(dev, BTN_STYLUS2, stylus2);
101 }
102
103 /* event termination */
104 input_sync(dev);
105
106resubmit:
107 status = usb_submit_urb (urb, GFP_ATOMIC);
108 if (status)
109 err ("can't resubmit intr, %s-%s/input0, status %d",
110 acecad->usbdev->bus->bus_name, acecad->usbdev->devpath, status);
111}
112
113static int usb_acecad_open(struct input_dev *dev)
114{
115 struct usb_acecad *acecad = dev->private;
116
117 acecad->irq->dev = acecad->usbdev;
118 if (usb_submit_urb(acecad->irq, GFP_KERNEL))
119 return -EIO;
120
121 return 0;
122}
123
124static void usb_acecad_close(struct input_dev *dev)
125{
126 struct usb_acecad *acecad = dev->private;
127
128 usb_kill_urb(acecad->irq);
129}
130
131static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_id *id)
132{
133 struct usb_device *dev = interface_to_usbdev(intf);
134 struct usb_host_interface *interface = intf->cur_altsetting;
135 struct usb_endpoint_descriptor *endpoint;
136 struct usb_acecad *acecad;
137 int pipe, maxp;
138 char path[64];
139
140 if (interface->desc.bNumEndpoints != 1)
141 return -ENODEV;
142
143 endpoint = &interface->endpoint[0].desc;
144
145 if (!(endpoint->bEndpointAddress & 0x80))
146 return -ENODEV;
147
148 if ((endpoint->bmAttributes & 3) != 3)
149 return -ENODEV;
150
151 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
152 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
153
154 acecad = kcalloc(1, sizeof(struct usb_acecad), GFP_KERNEL);
155 if (!acecad)
156 return -ENOMEM;
157
158 acecad->data = usb_buffer_alloc(dev, 8, SLAB_KERNEL, &acecad->data_dma);
159 if (!acecad->data)
160 goto fail1;
161
162 acecad->irq = usb_alloc_urb(0, GFP_KERNEL);
163 if (!acecad->irq)
164 goto fail2;
165
166 if (dev->manufacturer)
167 strlcpy(acecad->name, dev->manufacturer, sizeof(acecad->name));
168
169 if (dev->product) {
170 if (dev->manufacturer)
171 strlcat(acecad->name, " ", sizeof(acecad->name));
172 strlcat(acecad->name, dev->product, sizeof(acecad->name));
173 }
174
175 usb_make_path(dev, path, sizeof(path));
176 snprintf(acecad->phys, sizeof(acecad->phys), "%s/input0", path);
177
178 acecad->usbdev = dev;
179
180 acecad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
181 acecad->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
182 acecad->dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
183 acecad->dev.keybit[LONG(BTN_DIGI)] = BIT(BTN_TOOL_PEN) |BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2);
184
185 switch (id->driver_info) {
186 case 0:
187 acecad->dev.absmax[ABS_X] = 5000;
188 acecad->dev.absmax[ABS_Y] = 3750;
189 acecad->dev.absmax[ABS_PRESSURE] = 512;
190 if (!strlen(acecad->name))
191 snprintf(acecad->name, sizeof(acecad->name),
192 "USB Acecad Flair Tablet %04x:%04x",
193 dev->descriptor.idVendor, dev->descriptor.idProduct);
194 break;
195 case 1:
196 acecad->dev.absmax[ABS_X] = 3000;
197 acecad->dev.absmax[ABS_Y] = 2250;
198 acecad->dev.absmax[ABS_PRESSURE] = 1024;
199 if (!strlen(acecad->name))
200 snprintf(acecad->name, sizeof(acecad->name),
201 "USB Acecad 302 Tablet %04x:%04x",
202 dev->descriptor.idVendor, dev->descriptor.idProduct);
203 break;
204 }
205
206 acecad->dev.absfuzz[ABS_X] = 4;
207 acecad->dev.absfuzz[ABS_Y] = 4;
208
209 acecad->dev.private = acecad;
210 acecad->dev.open = usb_acecad_open;
211 acecad->dev.close = usb_acecad_close;
212
213 acecad->dev.name = acecad->name;
214 acecad->dev.phys = acecad->phys;
215 acecad->dev.id.bustype = BUS_USB;
216 acecad->dev.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
217 acecad->dev.id.product = le16_to_cpu(dev->descriptor.idProduct);
218 acecad->dev.id.version = le16_to_cpu(dev->descriptor.bcdDevice);
219 acecad->dev.dev = &intf->dev;
220
221 usb_fill_int_urb(acecad->irq, dev, pipe,
222 acecad->data, maxp > 8 ? 8 : maxp,
223 usb_acecad_irq, acecad, endpoint->bInterval);
224 acecad->irq->transfer_dma = acecad->data_dma;
225 acecad->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
226
227 input_register_device(&acecad->dev);
228
229 printk(KERN_INFO "input: %s with packet size %d on %s\n",
230 acecad->name, maxp, path);
231
232 usb_set_intfdata(intf, acecad);
233
234 return 0;
235
236 fail2: usb_buffer_free(dev, 8, acecad->data, acecad->data_dma);
237 fail1: kfree(acecad);
238 return -ENOMEM;
239}
240
241static void usb_acecad_disconnect(struct usb_interface *intf)
242{
243 struct usb_acecad *acecad = usb_get_intfdata(intf);
244
245 usb_set_intfdata(intf, NULL);
246 if (acecad) {
247 usb_kill_urb(acecad->irq);
248 input_unregister_device(&acecad->dev);
249 usb_free_urb(acecad->irq);
250 usb_buffer_free(interface_to_usbdev(intf), 10, acecad->data, acecad->data_dma);
251 kfree(acecad);
252 }
253}
254
255static struct usb_device_id usb_acecad_id_table [] = {
256 { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_FLAIR), .driver_info = 0 },
257 { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_302), .driver_info = 1 },
258 { }
259};
260
261MODULE_DEVICE_TABLE(usb, usb_acecad_id_table);
262
263static struct usb_driver usb_acecad_driver = {
264 .owner = THIS_MODULE,
265 .name = "usb_acecad",
266 .probe = usb_acecad_probe,
267 .disconnect = usb_acecad_disconnect,
268 .id_table = usb_acecad_id_table,
269};
270
271static int __init usb_acecad_init(void)
272{
273 int result = usb_register(&usb_acecad_driver);
274 if (result == 0)
275 info(DRIVER_VERSION ":" DRIVER_DESC);
276 return result;
277}
278
279static void __exit usb_acecad_exit(void)
280{
281 usb_deregister(&usb_acecad_driver);
282}
283
284module_init(usb_acecad_init);
285module_exit(usb_acecad_exit);
diff --git a/drivers/usb/input/aiptek.c b/drivers/usb/input/aiptek.c
index e991f7ed7330..6bb0f25e8e93 100644
--- a/drivers/usb/input/aiptek.c
+++ b/drivers/usb/input/aiptek.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Native support for the Aiptek HyperPen USB Tablets 2 * Native support for the Aiptek HyperPen USB Tablets
3 * (4000U/5000U/6000U/8000U/12000U) 3 * (4000U/5000U/6000U/8000U/12000U)
4 * 4 *
5 * Copyright (c) 2001 Chris Atenasio <chris@crud.net> 5 * Copyright (c) 2001 Chris Atenasio <chris@crud.net>
6 * Copyright (c) 2002-2004 Bryan W. Headley <bwheadley@earthlink.net> 6 * Copyright (c) 2002-2004 Bryan W. Headley <bwheadley@earthlink.net>
7 * 7 *
@@ -31,7 +31,7 @@
31 * - Added support for the sysfs interface, deprecating the 31 * - Added support for the sysfs interface, deprecating the
32 * procfs interface for 2.5.x kernel. Also added support for 32 * procfs interface for 2.5.x kernel. Also added support for
33 * Wheel command. Bryan W. Headley July-15-2003. 33 * Wheel command. Bryan W. Headley July-15-2003.
34 * v1.2 - Reworked jitter timer as a kernel thread. 34 * v1.2 - Reworked jitter timer as a kernel thread.
35 * Bryan W. Headley November-28-2003/Jan-10-2004. 35 * Bryan W. Headley November-28-2003/Jan-10-2004.
36 * v1.3 - Repaired issue of kernel thread going nuts on single-processor 36 * v1.3 - Repaired issue of kernel thread going nuts on single-processor
37 * machines, introduced programmableDelay as a command line 37 * machines, introduced programmableDelay as a command line
@@ -49,10 +49,10 @@
49 * NOTE: 49 * NOTE:
50 * This kernel driver is augmented by the "Aiptek" XFree86 input 50 * This kernel driver is augmented by the "Aiptek" XFree86 input
51 * driver for your X server, as well as the Gaiptek GUI Front-end 51 * driver for your X server, as well as the Gaiptek GUI Front-end
52 * "Tablet Manager". 52 * "Tablet Manager".
53 * These three products are highly interactive with one another, 53 * These three products are highly interactive with one another,
54 * so therefore it's easier to document them all as one subsystem. 54 * so therefore it's easier to document them all as one subsystem.
55 * Please visit the project's "home page", located at, 55 * Please visit the project's "home page", located at,
56 * http://aiptektablet.sourceforge.net. 56 * http://aiptektablet.sourceforge.net.
57 * 57 *
58 * This program is free software; you can redistribute it and/or modify 58 * This program is free software; you can redistribute it and/or modify
@@ -156,7 +156,7 @@
156 * Command/Data Description Return Bytes Return Value 156 * Command/Data Description Return Bytes Return Value
157 * 0x10/0x00 SwitchToMouse 0 157 * 0x10/0x00 SwitchToMouse 0
158 * 0x10/0x01 SwitchToTablet 0 158 * 0x10/0x01 SwitchToTablet 0
159 * 0x18/0x04 SetResolution 0 159 * 0x18/0x04 SetResolution 0
160 * 0x12/0xFF AutoGainOn 0 160 * 0x12/0xFF AutoGainOn 0
161 * 0x17/0x00 FilterOn 0 161 * 0x17/0x00 FilterOn 0
162 * 0x01/0x00 GetXExtension 2 MaxX 162 * 0x01/0x00 GetXExtension 2 MaxX
@@ -247,7 +247,7 @@
247#define AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE 2 247#define AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE 2
248#define AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED 3 248#define AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED 3
249 249
250 /* Time to wait (in ms) to help mask hand jittering 250 /* Time to wait (in ms) to help mask hand jittering
251 * when pressing the stylus buttons. 251 * when pressing the stylus buttons.
252 */ 252 */
253#define AIPTEK_JITTER_DELAY_DEFAULT 50 253#define AIPTEK_JITTER_DELAY_DEFAULT 50
@@ -324,7 +324,6 @@ struct aiptek {
324 struct aiptek_settings curSetting; /* tablet's current programmable */ 324 struct aiptek_settings curSetting; /* tablet's current programmable */
325 struct aiptek_settings newSetting; /* ... and new param settings */ 325 struct aiptek_settings newSetting; /* ... and new param settings */
326 unsigned int ifnum; /* interface number for IO */ 326 unsigned int ifnum; /* interface number for IO */
327 int openCount; /* module use counter */
328 int diagnostic; /* tablet diagnostic codes */ 327 int diagnostic; /* tablet diagnostic codes */
329 unsigned long eventCount; /* event count */ 328 unsigned long eventCount; /* event count */
330 int inDelay; /* jitter: in jitter delay? */ 329 int inDelay; /* jitter: in jitter delay? */
@@ -791,7 +790,7 @@ exit:
791 * specific Aiptek model numbers, because there has been overlaps, 790 * specific Aiptek model numbers, because there has been overlaps,
792 * use, and reuse of id's in existing models. Certain models have 791 * use, and reuse of id's in existing models. Certain models have
793 * been known to use more than one ID, indicative perhaps of 792 * been known to use more than one ID, indicative perhaps of
794 * manufacturing revisions. In any event, we consider these 793 * manufacturing revisions. In any event, we consider these
795 * IDs to not be model-specific nor unique. 794 * IDs to not be model-specific nor unique.
796 */ 795 */
797static const struct usb_device_id aiptek_ids[] = { 796static const struct usb_device_id aiptek_ids[] = {
@@ -814,15 +813,9 @@ static int aiptek_open(struct input_dev *inputdev)
814{ 813{
815 struct aiptek *aiptek = inputdev->private; 814 struct aiptek *aiptek = inputdev->private;
816 815
817 if (aiptek->openCount++ > 0) {
818 return 0;
819 }
820
821 aiptek->urb->dev = aiptek->usbdev; 816 aiptek->urb->dev = aiptek->usbdev;
822 if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0) { 817 if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0)
823 aiptek->openCount--;
824 return -EIO; 818 return -EIO;
825 }
826 819
827 return 0; 820 return 0;
828} 821}
@@ -834,13 +827,11 @@ static void aiptek_close(struct input_dev *inputdev)
834{ 827{
835 struct aiptek *aiptek = inputdev->private; 828 struct aiptek *aiptek = inputdev->private;
836 829
837 if (--aiptek->openCount == 0) { 830 usb_kill_urb(aiptek->urb);
838 usb_kill_urb(aiptek->urb);
839 }
840} 831}
841 832
842/*********************************************************************** 833/***********************************************************************
843 * aiptek_set_report and aiptek_get_report() are borrowed from Linux 2.4.x, 834 * aiptek_set_report and aiptek_get_report() are borrowed from Linux 2.4.x,
844 * where they were known as usb_set_report and usb_get_report. 835 * where they were known as usb_set_report and usb_get_report.
845 */ 836 */
846static int 837static int
@@ -2252,7 +2243,6 @@ static void aiptek_disconnect(struct usb_interface *intf)
2252 AIPTEK_PACKET_LENGTH, 2243 AIPTEK_PACKET_LENGTH,
2253 aiptek->data, aiptek->data_dma); 2244 aiptek->data, aiptek->data_dma);
2254 kfree(aiptek); 2245 kfree(aiptek);
2255 aiptek = NULL;
2256 } 2246 }
2257} 2247}
2258 2248
diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c
index 860df26323b1..654ac454744d 100644
--- a/drivers/usb/input/ati_remote.c
+++ b/drivers/usb/input/ati_remote.c
@@ -1,15 +1,15 @@
1/* 1/*
2 * USB ATI Remote support 2 * USB ATI Remote support
3 * 3 *
4 * Version 2.2.0 Copyright (c) 2004 Torrey Hoffman <thoffman@arnor.net> 4 * Version 2.2.0 Copyright (c) 2004 Torrey Hoffman <thoffman@arnor.net>
5 * Version 2.1.1 Copyright (c) 2002 Vladimir Dergachev 5 * Version 2.1.1 Copyright (c) 2002 Vladimir Dergachev
6 * 6 *
7 * This 2.2.0 version is a rewrite / cleanup of the 2.1.1 driver, including 7 * This 2.2.0 version is a rewrite / cleanup of the 2.1.1 driver, including
8 * porting to the 2.6 kernel interfaces, along with other modification 8 * porting to the 2.6 kernel interfaces, along with other modification
9 * to better match the style of the existing usb/input drivers. However, the 9 * to better match the style of the existing usb/input drivers. However, the
10 * protocol and hardware handling is essentially unchanged from 2.1.1. 10 * protocol and hardware handling is essentially unchanged from 2.1.1.
11 * 11 *
12 * The 2.1.1 driver was derived from the usbati_remote and usbkbd drivers by 12 * The 2.1.1 driver was derived from the usbati_remote and usbkbd drivers by
13 * Vojtech Pavlik. 13 * Vojtech Pavlik.
14 * 14 *
15 * Changes: 15 * Changes:
@@ -23,64 +23,64 @@
23 * Added support for the "Lola" remote contributed by: 23 * Added support for the "Lola" remote contributed by:
24 * Seth Cohn <sethcohn@yahoo.com> 24 * Seth Cohn <sethcohn@yahoo.com>
25 * 25 *
26 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 26 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
27 * 27 *
28 * This program is free software; you can redistribute it and/or modify 28 * This program is free software; you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by 29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation; either version 2 of the License, or 30 * the Free Software Foundation; either version 2 of the License, or
31 * (at your option) any later version. 31 * (at your option) any later version.
32 * 32 *
33 * This program is distributed in the hope that it will be useful, 33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of 34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details. 36 * GNU General Public License for more details.
37 * 37 *
38 * You should have received a copy of the GNU General Public License 38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software 39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 40 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 * 41 *
42 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 42 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
43 * 43 *
44 * Hardware & software notes 44 * Hardware & software notes
45 * 45 *
46 * These remote controls are distributed by ATI as part of their 46 * These remote controls are distributed by ATI as part of their
47 * "All-In-Wonder" video card packages. The receiver self-identifies as a 47 * "All-In-Wonder" video card packages. The receiver self-identifies as a
48 * "USB Receiver" with manufacturer "X10 Wireless Technology Inc". 48 * "USB Receiver" with manufacturer "X10 Wireless Technology Inc".
49 * 49 *
50 * The "Lola" remote is available from X10. See: 50 * The "Lola" remote is available from X10. See:
51 * http://www.x10.com/products/lola_sg1.htm 51 * http://www.x10.com/products/lola_sg1.htm
52 * The Lola is similar to the ATI remote but has no mouse support, and slightly 52 * The Lola is similar to the ATI remote but has no mouse support, and slightly
53 * different keys. 53 * different keys.
54 * 54 *
55 * It is possible to use multiple receivers and remotes on multiple computers 55 * It is possible to use multiple receivers and remotes on multiple computers
56 * simultaneously by configuring them to use specific channels. 56 * simultaneously by configuring them to use specific channels.
57 * 57 *
58 * The RF protocol used by the remote supports 16 distinct channels, 1 to 16. 58 * The RF protocol used by the remote supports 16 distinct channels, 1 to 16.
59 * Actually, it may even support more, at least in some revisions of the 59 * Actually, it may even support more, at least in some revisions of the
60 * hardware. 60 * hardware.
61 * 61 *
62 * Each remote can be configured to transmit on one channel as follows: 62 * Each remote can be configured to transmit on one channel as follows:
63 * - Press and hold the "hand icon" button. 63 * - Press and hold the "hand icon" button.
64 * - When the red LED starts to blink, let go of the "hand icon" button. 64 * - When the red LED starts to blink, let go of the "hand icon" button.
65 * - When it stops blinking, input the channel code as two digits, from 01 65 * - When it stops blinking, input the channel code as two digits, from 01
66 * to 16, and press the hand icon again. 66 * to 16, and press the hand icon again.
67 * 67 *
68 * The timing can be a little tricky. Try loading the module with debug=1 68 * The timing can be a little tricky. Try loading the module with debug=1
69 * to have the kernel print out messages about the remote control number 69 * to have the kernel print out messages about the remote control number
70 * and mask. Note: debugging prints remote numbers as zero-based hexadecimal. 70 * and mask. Note: debugging prints remote numbers as zero-based hexadecimal.
71 * 71 *
72 * The driver has a "channel_mask" parameter. This bitmask specifies which 72 * The driver has a "channel_mask" parameter. This bitmask specifies which
73 * channels will be ignored by the module. To mask out channels, just add 73 * channels will be ignored by the module. To mask out channels, just add
74 * all the 2^channel_number values together. 74 * all the 2^channel_number values together.
75 * 75 *
76 * For instance, set channel_mask = 2^4 = 16 (binary 10000) to make ati_remote 76 * For instance, set channel_mask = 2^4 = 16 (binary 10000) to make ati_remote
77 * ignore signals coming from remote controls transmitting on channel 4, but 77 * ignore signals coming from remote controls transmitting on channel 4, but
78 * accept all other channels. 78 * accept all other channels.
79 * 79 *
80 * Or, set channel_mask = 65533, (0xFFFD), and all channels except 1 will be 80 * Or, set channel_mask = 65533, (0xFFFD), and all channels except 1 will be
81 * ignored. 81 * ignored.
82 * 82 *
83 * The default is 0 (respond to all channels). Bit 0 and bits 17-32 of this 83 * The default is 0 (respond to all channels). Bit 0 and bits 17-32 of this
84 * parameter are unused. 84 * parameter are unused.
85 * 85 *
86 */ 86 */
@@ -99,13 +99,13 @@
99/* 99/*
100 * Module and Version Information, Module Parameters 100 * Module and Version Information, Module Parameters
101 */ 101 */
102 102
103#define ATI_REMOTE_VENDOR_ID 0x0bc7 103#define ATI_REMOTE_VENDOR_ID 0x0bc7
104#define ATI_REMOTE_PRODUCT_ID 0x004 104#define ATI_REMOTE_PRODUCT_ID 0x004
105#define LOLA_REMOTE_PRODUCT_ID 0x002 105#define LOLA_REMOTE_PRODUCT_ID 0x002
106#define MEDION_REMOTE_PRODUCT_ID 0x006 106#define MEDION_REMOTE_PRODUCT_ID 0x006
107 107
108#define DRIVER_VERSION "2.2.1" 108#define DRIVER_VERSION "2.2.1"
109#define DRIVER_AUTHOR "Torrey Hoffman <thoffman@arnor.net>" 109#define DRIVER_AUTHOR "Torrey Hoffman <thoffman@arnor.net>"
110#define DRIVER_DESC "ATI/X10 RF USB Remote Control" 110#define DRIVER_DESC "ATI/X10 RF USB Remote Control"
111 111
@@ -113,18 +113,18 @@
113#define DATA_BUFSIZE 63 /* size of URB data buffers */ 113#define DATA_BUFSIZE 63 /* size of URB data buffers */
114#define ATI_INPUTNUM 1 /* Which input device to register as */ 114#define ATI_INPUTNUM 1 /* Which input device to register as */
115 115
116static unsigned long channel_mask = 0; 116static unsigned long channel_mask;
117module_param(channel_mask, ulong, 0444); 117module_param(channel_mask, ulong, 0444);
118MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore"); 118MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore");
119 119
120static int debug = 0; 120static int debug;
121module_param(debug, int, 0444); 121module_param(debug, int, 0444);
122MODULE_PARM_DESC(debug, "Enable extra debug messages and information"); 122MODULE_PARM_DESC(debug, "Enable extra debug messages and information");
123 123
124#define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0) 124#define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0)
125#undef err 125#undef err
126#define err(format, arg...) printk(KERN_ERR format , ## arg) 126#define err(format, arg...) printk(KERN_ERR format , ## arg)
127 127
128static struct usb_device_id ati_remote_table[] = { 128static struct usb_device_id ati_remote_table[] = {
129 { USB_DEVICE(ATI_REMOTE_VENDOR_ID, ATI_REMOTE_PRODUCT_ID) }, 129 { USB_DEVICE(ATI_REMOTE_VENDOR_ID, ATI_REMOTE_PRODUCT_ID) },
130 { USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA_REMOTE_PRODUCT_ID) }, 130 { USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA_REMOTE_PRODUCT_ID) },
@@ -148,7 +148,7 @@ static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 };
148/* Acceleration curve for directional control pad */ 148/* Acceleration curve for directional control pad */
149static char accel[] = { 1, 2, 4, 6, 9, 13, 20 }; 149static char accel[] = { 1, 2, 4, 6, 9, 13, 20 };
150 150
151/* Duplicate event filtering time. 151/* Duplicate event filtering time.
152 * Sequential, identical KIND_FILTERED inputs with less than 152 * Sequential, identical KIND_FILTERED inputs with less than
153 * FILTER_TIME jiffies between them are considered as repeat 153 * FILTER_TIME jiffies between them are considered as repeat
154 * events. The hardware generates 5 events for the first keypress 154 * events. The hardware generates 5 events for the first keypress
@@ -161,10 +161,10 @@ static char accel[] = { 1, 2, 4, 6, 9, 13, 20 };
161static DECLARE_MUTEX(disconnect_sem); 161static DECLARE_MUTEX(disconnect_sem);
162 162
163struct ati_remote { 163struct ati_remote {
164 struct input_dev idev; 164 struct input_dev idev;
165 struct usb_device *udev; 165 struct usb_device *udev;
166 struct usb_interface *interface; 166 struct usb_interface *interface;
167 167
168 struct urb *irq_urb; 168 struct urb *irq_urb;
169 struct urb *out_urb; 169 struct urb *out_urb;
170 struct usb_endpoint_descriptor *endpoint_in; 170 struct usb_endpoint_descriptor *endpoint_in;
@@ -174,13 +174,11 @@ struct ati_remote {
174 dma_addr_t inbuf_dma; 174 dma_addr_t inbuf_dma;
175 dma_addr_t outbuf_dma; 175 dma_addr_t outbuf_dma;
176 176
177 int open; /* open counter */
178
179 unsigned char old_data[2]; /* Detect duplicate events */ 177 unsigned char old_data[2]; /* Detect duplicate events */
180 unsigned long old_jiffies; 178 unsigned long old_jiffies;
181 unsigned long acc_jiffies; /* handle acceleration */ 179 unsigned long acc_jiffies; /* handle acceleration */
182 unsigned int repeat_count; 180 unsigned int repeat_count;
183 181
184 char name[NAME_BUFSIZE]; 182 char name[NAME_BUFSIZE];
185 char phys[NAME_BUFSIZE]; 183 char phys[NAME_BUFSIZE];
186 184
@@ -206,14 +204,14 @@ static struct
206 int type; 204 int type;
207 unsigned int code; 205 unsigned int code;
208 int value; 206 int value;
209} ati_remote_tbl[] = 207} ati_remote_tbl[] =
210{ 208{
211 /* Directional control pad axes */ 209 /* Directional control pad axes */
212 {KIND_ACCEL, 0x35, 0x70, EV_REL, REL_X, -1}, /* left */ 210 {KIND_ACCEL, 0x35, 0x70, EV_REL, REL_X, -1}, /* left */
213 {KIND_ACCEL, 0x36, 0x71, EV_REL, REL_X, 1}, /* right */ 211 {KIND_ACCEL, 0x36, 0x71, EV_REL, REL_X, 1}, /* right */
214 {KIND_ACCEL, 0x37, 0x72, EV_REL, REL_Y, -1}, /* up */ 212 {KIND_ACCEL, 0x37, 0x72, EV_REL, REL_Y, -1}, /* up */
215 {KIND_ACCEL, 0x38, 0x73, EV_REL, REL_Y, 1}, /* down */ 213 {KIND_ACCEL, 0x38, 0x73, EV_REL, REL_Y, 1}, /* down */
216 /* Directional control pad diagonals */ 214 /* Directional control pad diagonals */
217 {KIND_LU, 0x39, 0x74, EV_REL, 0, 0}, /* left up */ 215 {KIND_LU, 0x39, 0x74, EV_REL, 0, 0}, /* left up */
218 {KIND_RU, 0x3a, 0x75, EV_REL, 0, 0}, /* right up */ 216 {KIND_RU, 0x3a, 0x75, EV_REL, 0, 0}, /* right up */
219 {KIND_LD, 0x3c, 0x77, EV_REL, 0, 0}, /* left down */ 217 {KIND_LD, 0x3c, 0x77, EV_REL, 0, 0}, /* left down */
@@ -225,7 +223,7 @@ static struct
225 {KIND_LITERAL, 0x41, 0x7c, EV_KEY, BTN_RIGHT, 1},/* right btn down */ 223 {KIND_LITERAL, 0x41, 0x7c, EV_KEY, BTN_RIGHT, 1},/* right btn down */
226 {KIND_LITERAL, 0x42, 0x7d, EV_KEY, BTN_RIGHT, 0},/* right btn up */ 224 {KIND_LITERAL, 0x42, 0x7d, EV_KEY, BTN_RIGHT, 0},/* right btn up */
227 225
228 /* Artificial "doubleclick" events are generated by the hardware. 226 /* Artificial "doubleclick" events are generated by the hardware.
229 * They are mapped to the "side" and "extra" mouse buttons here. */ 227 * They are mapped to the "side" and "extra" mouse buttons here. */
230 {KIND_FILTERED, 0x3f, 0x7a, EV_KEY, BTN_SIDE, 1}, /* left dblclick */ 228 {KIND_FILTERED, 0x3f, 0x7a, EV_KEY, BTN_SIDE, 1}, /* left dblclick */
231 {KIND_FILTERED, 0x43, 0x7e, EV_KEY, BTN_EXTRA, 1},/* right dblclick */ 229 {KIND_FILTERED, 0x43, 0x7e, EV_KEY, BTN_EXTRA, 1},/* right dblclick */
@@ -273,15 +271,15 @@ static struct
273 {KIND_FILTERED, 0xea, 0x25, EV_KEY, KEY_PLAY, 1}, /* ( >) */ 271 {KIND_FILTERED, 0xea, 0x25, EV_KEY, KEY_PLAY, 1}, /* ( >) */
274 {KIND_FILTERED, 0xe9, 0x24, EV_KEY, KEY_REWIND, 1}, /* (<<) */ 272 {KIND_FILTERED, 0xe9, 0x24, EV_KEY, KEY_REWIND, 1}, /* (<<) */
275 {KIND_FILTERED, 0xeb, 0x26, EV_KEY, KEY_FORWARD, 1}, /* (>>) */ 273 {KIND_FILTERED, 0xeb, 0x26, EV_KEY, KEY_FORWARD, 1}, /* (>>) */
276 {KIND_FILTERED, 0xed, 0x28, EV_KEY, KEY_STOP, 1}, /* ([]) */ 274 {KIND_FILTERED, 0xed, 0x28, EV_KEY, KEY_STOP, 1}, /* ([]) */
277 {KIND_FILTERED, 0xee, 0x29, EV_KEY, KEY_PAUSE, 1}, /* ('') */ 275 {KIND_FILTERED, 0xee, 0x29, EV_KEY, KEY_PAUSE, 1}, /* ('') */
278 {KIND_FILTERED, 0xf0, 0x2b, EV_KEY, KEY_PREVIOUS, 1}, /* (<-) */ 276 {KIND_FILTERED, 0xf0, 0x2b, EV_KEY, KEY_PREVIOUS, 1}, /* (<-) */
279 {KIND_FILTERED, 0xef, 0x2a, EV_KEY, KEY_NEXT, 1}, /* (>+) */ 277 {KIND_FILTERED, 0xef, 0x2a, EV_KEY, KEY_NEXT, 1}, /* (>+) */
280 {KIND_FILTERED, 0xf2, 0x2D, EV_KEY, KEY_INFO, 1}, /* PLAYING */ 278 {KIND_FILTERED, 0xf2, 0x2D, EV_KEY, KEY_INFO, 1}, /* PLAYING */
281 {KIND_FILTERED, 0xf3, 0x2E, EV_KEY, KEY_HOME, 1}, /* TOP */ 279 {KIND_FILTERED, 0xf3, 0x2E, EV_KEY, KEY_HOME, 1}, /* TOP */
282 {KIND_FILTERED, 0xf4, 0x2F, EV_KEY, KEY_END, 1}, /* END */ 280 {KIND_FILTERED, 0xf4, 0x2F, EV_KEY, KEY_END, 1}, /* END */
283 {KIND_FILTERED, 0xf5, 0x30, EV_KEY, KEY_SELECT, 1}, /* SELECT */ 281 {KIND_FILTERED, 0xf5, 0x30, EV_KEY, KEY_SELECT, 1}, /* SELECT */
284 282
285 {KIND_END, 0x00, 0x00, EV_MAX + 1, 0, 0} 283 {KIND_END, 0x00, 0x00, EV_MAX + 1, 0, 0}
286}; 284};
287 285
@@ -315,7 +313,7 @@ static void ati_remote_dump(unsigned char *data, unsigned int len)
315 if ((len == 1) && (data[0] != (unsigned char)0xff) && (data[0] != 0x00)) 313 if ((len == 1) && (data[0] != (unsigned char)0xff) && (data[0] != 0x00))
316 warn("Weird byte 0x%02x", data[0]); 314 warn("Weird byte 0x%02x", data[0]);
317 else if (len == 4) 315 else if (len == 4)
318 warn("Weird key %02x %02x %02x %02x", 316 warn("Weird key %02x %02x %02x %02x",
319 data[0], data[1], data[2], data[3]); 317 data[0], data[1], data[2], data[3]);
320 else 318 else
321 warn("Weird data, len=%d %02x %02x %02x %02x %02x %02x ...", 319 warn("Weird data, len=%d %02x %02x %02x %02x %02x %02x ...",
@@ -328,25 +326,16 @@ static void ati_remote_dump(unsigned char *data, unsigned int len)
328static int ati_remote_open(struct input_dev *inputdev) 326static int ati_remote_open(struct input_dev *inputdev)
329{ 327{
330 struct ati_remote *ati_remote = inputdev->private; 328 struct ati_remote *ati_remote = inputdev->private;
331 int retval = 0;
332
333 down(&disconnect_sem);
334
335 if (ati_remote->open++)
336 goto exit;
337 329
338 /* On first open, submit the read urb which was set up previously. */ 330 /* On first open, submit the read urb which was set up previously. */
339 ati_remote->irq_urb->dev = ati_remote->udev; 331 ati_remote->irq_urb->dev = ati_remote->udev;
340 if (usb_submit_urb(ati_remote->irq_urb, GFP_KERNEL)) { 332 if (usb_submit_urb(ati_remote->irq_urb, GFP_KERNEL)) {
341 dev_err(&ati_remote->interface->dev, 333 dev_err(&ati_remote->interface->dev,
342 "%s: usb_submit_urb failed!\n", __FUNCTION__); 334 "%s: usb_submit_urb failed!\n", __FUNCTION__);
343 ati_remote->open--; 335 return -EIO;
344 retval = -EIO;
345 } 336 }
346 337
347exit: 338 return 0;
348 up(&disconnect_sem);
349 return retval;
350} 339}
351 340
352/* 341/*
@@ -355,9 +344,8 @@ exit:
355static void ati_remote_close(struct input_dev *inputdev) 344static void ati_remote_close(struct input_dev *inputdev)
356{ 345{
357 struct ati_remote *ati_remote = inputdev->private; 346 struct ati_remote *ati_remote = inputdev->private;
358 347
359 if (!--ati_remote->open) 348 usb_kill_urb(ati_remote->irq_urb);
360 usb_kill_urb(ati_remote->irq_urb);
361} 349}
362 350
363/* 351/*
@@ -366,13 +354,13 @@ static void ati_remote_close(struct input_dev *inputdev)
366static void ati_remote_irq_out(struct urb *urb, struct pt_regs *regs) 354static void ati_remote_irq_out(struct urb *urb, struct pt_regs *regs)
367{ 355{
368 struct ati_remote *ati_remote = urb->context; 356 struct ati_remote *ati_remote = urb->context;
369 357
370 if (urb->status) { 358 if (urb->status) {
371 dev_dbg(&ati_remote->interface->dev, "%s: status %d\n", 359 dev_dbg(&ati_remote->interface->dev, "%s: status %d\n",
372 __FUNCTION__, urb->status); 360 __FUNCTION__, urb->status);
373 return; 361 return;
374 } 362 }
375 363
376 ati_remote->send_flags |= SEND_FLAG_COMPLETE; 364 ati_remote->send_flags |= SEND_FLAG_COMPLETE;
377 wmb(); 365 wmb();
378 wake_up(&ati_remote->wait); 366 wake_up(&ati_remote->wait);
@@ -380,16 +368,16 @@ static void ati_remote_irq_out(struct urb *urb, struct pt_regs *regs)
380 368
381/* 369/*
382 * ati_remote_sendpacket 370 * ati_remote_sendpacket
383 * 371 *
384 * Used to send device initialization strings 372 * Used to send device initialization strings
385 */ 373 */
386static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd, unsigned char *data) 374static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd, unsigned char *data)
387{ 375{
388 int retval = 0; 376 int retval = 0;
389 377
390 /* Set up out_urb */ 378 /* Set up out_urb */
391 memcpy(ati_remote->out_urb->transfer_buffer + 1, data, LO(cmd)); 379 memcpy(ati_remote->out_urb->transfer_buffer + 1, data, LO(cmd));
392 ((char *) ati_remote->out_urb->transfer_buffer)[0] = HI(cmd); 380 ((char *) ati_remote->out_urb->transfer_buffer)[0] = HI(cmd);
393 381
394 ati_remote->out_urb->transfer_buffer_length = LO(cmd) + 1; 382 ati_remote->out_urb->transfer_buffer_length = LO(cmd) + 1;
395 ati_remote->out_urb->dev = ati_remote->udev; 383 ati_remote->out_urb->dev = ati_remote->udev;
@@ -397,17 +385,17 @@ static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd, unsigne
397 385
398 retval = usb_submit_urb(ati_remote->out_urb, GFP_ATOMIC); 386 retval = usb_submit_urb(ati_remote->out_urb, GFP_ATOMIC);
399 if (retval) { 387 if (retval) {
400 dev_dbg(&ati_remote->interface->dev, 388 dev_dbg(&ati_remote->interface->dev,
401 "sendpacket: usb_submit_urb failed: %d\n", retval); 389 "sendpacket: usb_submit_urb failed: %d\n", retval);
402 return retval; 390 return retval;
403 } 391 }
404 392
405 wait_event_timeout(ati_remote->wait, 393 wait_event_timeout(ati_remote->wait,
406 ((ati_remote->out_urb->status != -EINPROGRESS) || 394 ((ati_remote->out_urb->status != -EINPROGRESS) ||
407 (ati_remote->send_flags & SEND_FLAG_COMPLETE)), 395 (ati_remote->send_flags & SEND_FLAG_COMPLETE)),
408 HZ); 396 HZ);
409 usb_kill_urb(ati_remote->out_urb); 397 usb_kill_urb(ati_remote->out_urb);
410 398
411 return retval; 399 return retval;
412} 400}
413 401
@@ -419,15 +407,15 @@ static int ati_remote_event_lookup(int rem, unsigned char d1, unsigned char d2)
419 int i; 407 int i;
420 408
421 for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) { 409 for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) {
422 /* 410 /*
423 * Decide if the table entry matches the remote input. 411 * Decide if the table entry matches the remote input.
424 */ 412 */
425 if ((((ati_remote_tbl[i].data1 & 0x0f) == (d1 & 0x0f))) && 413 if ((((ati_remote_tbl[i].data1 & 0x0f) == (d1 & 0x0f))) &&
426 ((((ati_remote_tbl[i].data1 >> 4) - 414 ((((ati_remote_tbl[i].data1 >> 4) -
427 (d1 >> 4) + rem) & 0x0f) == 0x0f) && 415 (d1 >> 4) + rem) & 0x0f) == 0x0f) &&
428 (ati_remote_tbl[i].data2 == d2)) 416 (ati_remote_tbl[i].data2 == d2))
429 return i; 417 return i;
430 418
431 } 419 }
432 return -1; 420 return -1;
433} 421}
@@ -435,16 +423,16 @@ static int ati_remote_event_lookup(int rem, unsigned char d1, unsigned char d2)
435/* 423/*
436 * ati_remote_report_input 424 * ati_remote_report_input
437 */ 425 */
438static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs) 426static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
439{ 427{
440 struct ati_remote *ati_remote = urb->context; 428 struct ati_remote *ati_remote = urb->context;
441 unsigned char *data= ati_remote->inbuf; 429 unsigned char *data= ati_remote->inbuf;
442 struct input_dev *dev = &ati_remote->idev; 430 struct input_dev *dev = &ati_remote->idev;
443 int index, acc; 431 int index, acc;
444 int remote_num; 432 int remote_num;
445 433
446 /* Deal with strange looking inputs */ 434 /* Deal with strange looking inputs */
447 if ( (urb->actual_length != 4) || (data[0] != 0x14) || 435 if ( (urb->actual_length != 4) || (data[0] != 0x14) ||
448 ((data[3] & 0x0f) != 0x00) ) { 436 ((data[3] & 0x0f) != 0x00) ) {
449 ati_remote_dump(data, urb->actual_length); 437 ati_remote_dump(data, urb->actual_length);
450 return; 438 return;
@@ -453,7 +441,7 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
453 /* Mask unwanted remote channels. */ 441 /* Mask unwanted remote channels. */
454 /* note: remote_num is 0-based, channel 1 on remote == 0 here */ 442 /* note: remote_num is 0-based, channel 1 on remote == 0 here */
455 remote_num = (data[3] >> 4) & 0x0f; 443 remote_num = (data[3] >> 4) & 0x0f;
456 if (channel_mask & (1 << (remote_num + 1))) { 444 if (channel_mask & (1 << (remote_num + 1))) {
457 dbginfo(&ati_remote->interface->dev, 445 dbginfo(&ati_remote->interface->dev,
458 "Masked input from channel 0x%02x: data %02x,%02x, mask= 0x%02lx\n", 446 "Masked input from channel 0x%02x: data %02x,%02x, mask= 0x%02lx\n",
459 remote_num, data[1], data[2], channel_mask); 447 remote_num, data[1], data[2], channel_mask);
@@ -463,37 +451,36 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
463 /* Look up event code index in translation table */ 451 /* Look up event code index in translation table */
464 index = ati_remote_event_lookup(remote_num, data[1], data[2]); 452 index = ati_remote_event_lookup(remote_num, data[1], data[2]);
465 if (index < 0) { 453 if (index < 0) {
466 dev_warn(&ati_remote->interface->dev, 454 dev_warn(&ati_remote->interface->dev,
467 "Unknown input from channel 0x%02x: data %02x,%02x\n", 455 "Unknown input from channel 0x%02x: data %02x,%02x\n",
468 remote_num, data[1], data[2]); 456 remote_num, data[1], data[2]);
469 return; 457 return;
470 } 458 }
471 dbginfo(&ati_remote->interface->dev, 459 dbginfo(&ati_remote->interface->dev,
472 "channel 0x%02x; data %02x,%02x; index %d; keycode %d\n", 460 "channel 0x%02x; data %02x,%02x; index %d; keycode %d\n",
473 remote_num, data[1], data[2], index, ati_remote_tbl[index].code); 461 remote_num, data[1], data[2], index, ati_remote_tbl[index].code);
474 462
475 if (ati_remote_tbl[index].kind == KIND_LITERAL) { 463 if (ati_remote_tbl[index].kind == KIND_LITERAL) {
476 input_regs(dev, regs); 464 input_regs(dev, regs);
477 input_event(dev, ati_remote_tbl[index].type, 465 input_event(dev, ati_remote_tbl[index].type,
478 ati_remote_tbl[index].code, 466 ati_remote_tbl[index].code,
479 ati_remote_tbl[index].value); 467 ati_remote_tbl[index].value);
480 input_sync(dev); 468 input_sync(dev);
481 469
482 ati_remote->old_jiffies = jiffies; 470 ati_remote->old_jiffies = jiffies;
483 return; 471 return;
484 } 472 }
485 473
486 if (ati_remote_tbl[index].kind == KIND_FILTERED) { 474 if (ati_remote_tbl[index].kind == KIND_FILTERED) {
487 /* Filter duplicate events which happen "too close" together. */ 475 /* Filter duplicate events which happen "too close" together. */
488 if ((ati_remote->old_data[0] == data[1]) && 476 if ((ati_remote->old_data[0] == data[1]) &&
489 (ati_remote->old_data[1] == data[2]) && 477 (ati_remote->old_data[1] == data[2]) &&
490 ((ati_remote->old_jiffies + FILTER_TIME) > jiffies)) { 478 ((ati_remote->old_jiffies + FILTER_TIME) > jiffies)) {
491 ati_remote->repeat_count++; 479 ati_remote->repeat_count++;
492 } 480 } else {
493 else {
494 ati_remote->repeat_count = 0; 481 ati_remote->repeat_count = 0;
495 } 482 }
496 483
497 ati_remote->old_data[0] = data[1]; 484 ati_remote->old_data[0] = data[1];
498 ati_remote->old_data[1] = data[2]; 485 ati_remote->old_data[1] = data[2];
499 ati_remote->old_jiffies = jiffies; 486 ati_remote->old_jiffies = jiffies;
@@ -501,7 +488,7 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
501 if ((ati_remote->repeat_count > 0) 488 if ((ati_remote->repeat_count > 0)
502 && (ati_remote->repeat_count < 5)) 489 && (ati_remote->repeat_count < 5))
503 return; 490 return;
504 491
505 492
506 input_regs(dev, regs); 493 input_regs(dev, regs);
507 input_event(dev, ati_remote_tbl[index].type, 494 input_event(dev, ati_remote_tbl[index].type,
@@ -511,13 +498,13 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
511 input_sync(dev); 498 input_sync(dev);
512 499
513 return; 500 return;
514 } 501 }
515 502
516 /* 503 /*
517 * Other event kinds are from the directional control pad, and have an 504 * Other event kinds are from the directional control pad, and have an
518 * acceleration factor applied to them. Without this acceleration, the 505 * acceleration factor applied to them. Without this acceleration, the
519 * control pad is mostly unusable. 506 * control pad is mostly unusable.
520 * 507 *
521 * If elapsed time since last event is > 1/4 second, user "stopped", 508 * If elapsed time since last event is > 1/4 second, user "stopped",
522 * so reset acceleration. Otherwise, user is probably holding the control 509 * so reset acceleration. Otherwise, user is probably holding the control
523 * pad down, so we increase acceleration, ramping up over two seconds to 510 * pad down, so we increase acceleration, ramping up over two seconds to
@@ -559,7 +546,7 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
559 input_report_rel(dev, REL_Y, acc); 546 input_report_rel(dev, REL_Y, acc);
560 break; 547 break;
561 default: 548 default:
562 dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n", 549 dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n",
563 ati_remote_tbl[index].kind); 550 ati_remote_tbl[index].kind);
564 } 551 }
565 input_sync(dev); 552 input_sync(dev);
@@ -586,12 +573,12 @@ static void ati_remote_irq_in(struct urb *urb, struct pt_regs *regs)
586 case -ESHUTDOWN: 573 case -ESHUTDOWN:
587 dev_dbg(&ati_remote->interface->dev, "%s: urb error status, unlink? \n", 574 dev_dbg(&ati_remote->interface->dev, "%s: urb error status, unlink? \n",
588 __FUNCTION__); 575 __FUNCTION__);
589 return; 576 return;
590 default: /* error */ 577 default: /* error */
591 dev_dbg(&ati_remote->interface->dev, "%s: Nonzero urb status %d\n", 578 dev_dbg(&ati_remote->interface->dev, "%s: Nonzero urb status %d\n",
592 __FUNCTION__, urb->status); 579 __FUNCTION__, urb->status);
593 } 580 }
594 581
595 retval = usb_submit_urb(urb, SLAB_ATOMIC); 582 retval = usb_submit_urb(urb, SLAB_ATOMIC);
596 if (retval) 583 if (retval)
597 dev_err(&ati_remote->interface->dev, "%s: usb_submit_urb()=%d\n", 584 dev_err(&ati_remote->interface->dev, "%s: usb_submit_urb()=%d\n",
@@ -603,8 +590,6 @@ static void ati_remote_irq_in(struct urb *urb, struct pt_regs *regs)
603 */ 590 */
604static void ati_remote_delete(struct ati_remote *ati_remote) 591static void ati_remote_delete(struct ati_remote *ati_remote)
605{ 592{
606 if (!ati_remote) return;
607
608 if (ati_remote->irq_urb) 593 if (ati_remote->irq_urb)
609 usb_kill_urb(ati_remote->irq_urb); 594 usb_kill_urb(ati_remote->irq_urb);
610 595
@@ -614,16 +599,16 @@ static void ati_remote_delete(struct ati_remote *ati_remote)
614 input_unregister_device(&ati_remote->idev); 599 input_unregister_device(&ati_remote->idev);
615 600
616 if (ati_remote->inbuf) 601 if (ati_remote->inbuf)
617 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE, 602 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE,
618 ati_remote->inbuf, ati_remote->inbuf_dma); 603 ati_remote->inbuf, ati_remote->inbuf_dma);
619 604
620 if (ati_remote->outbuf) 605 if (ati_remote->outbuf)
621 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE, 606 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE,
622 ati_remote->outbuf, ati_remote->outbuf_dma); 607 ati_remote->outbuf, ati_remote->outbuf_dma);
623 608
624 if (ati_remote->irq_urb) 609 if (ati_remote->irq_urb)
625 usb_free_urb(ati_remote->irq_urb); 610 usb_free_urb(ati_remote->irq_urb);
626 611
627 if (ati_remote->out_urb) 612 if (ati_remote->out_urb)
628 usb_free_urb(ati_remote->out_urb); 613 usb_free_urb(ati_remote->out_urb);
629 614
@@ -636,51 +621,52 @@ static void ati_remote_input_init(struct ati_remote *ati_remote)
636 int i; 621 int i;
637 622
638 idev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 623 idev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
639 idev->keybit[LONG(BTN_MOUSE)] = ( BIT(BTN_LEFT) | BIT(BTN_RIGHT) | 624 idev->keybit[LONG(BTN_MOUSE)] = ( BIT(BTN_LEFT) | BIT(BTN_RIGHT) |
640 BIT(BTN_SIDE) | BIT(BTN_EXTRA) ); 625 BIT(BTN_SIDE) | BIT(BTN_EXTRA) );
641 idev->relbit[0] = BIT(REL_X) | BIT(REL_Y); 626 idev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
642 for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) 627 for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++)
643 if (ati_remote_tbl[i].type == EV_KEY) 628 if (ati_remote_tbl[i].type == EV_KEY)
644 set_bit(ati_remote_tbl[i].code, idev->keybit); 629 set_bit(ati_remote_tbl[i].code, idev->keybit);
645 630
646 idev->private = ati_remote; 631 idev->private = ati_remote;
647 idev->open = ati_remote_open; 632 idev->open = ati_remote_open;
648 idev->close = ati_remote_close; 633 idev->close = ati_remote_close;
649 634
650 idev->name = ati_remote->name; 635 idev->name = ati_remote->name;
651 idev->phys = ati_remote->phys; 636 idev->phys = ati_remote->phys;
652 637
653 idev->id.bustype = BUS_USB; 638 idev->id.bustype = BUS_USB;
654 idev->id.vendor = le16_to_cpu(ati_remote->udev->descriptor.idVendor); 639 idev->id.vendor = le16_to_cpu(ati_remote->udev->descriptor.idVendor);
655 idev->id.product = le16_to_cpu(ati_remote->udev->descriptor.idProduct); 640 idev->id.product = le16_to_cpu(ati_remote->udev->descriptor.idProduct);
656 idev->id.version = le16_to_cpu(ati_remote->udev->descriptor.bcdDevice); 641 idev->id.version = le16_to_cpu(ati_remote->udev->descriptor.bcdDevice);
642 idev->dev = &(ati_remote->udev->dev);
657} 643}
658 644
659static int ati_remote_initialize(struct ati_remote *ati_remote) 645static int ati_remote_initialize(struct ati_remote *ati_remote)
660{ 646{
661 struct usb_device *udev = ati_remote->udev; 647 struct usb_device *udev = ati_remote->udev;
662 int pipe, maxp; 648 int pipe, maxp;
663 649
664 init_waitqueue_head(&ati_remote->wait); 650 init_waitqueue_head(&ati_remote->wait);
665 651
666 /* Set up irq_urb */ 652 /* Set up irq_urb */
667 pipe = usb_rcvintpipe(udev, ati_remote->endpoint_in->bEndpointAddress); 653 pipe = usb_rcvintpipe(udev, ati_remote->endpoint_in->bEndpointAddress);
668 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); 654 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
669 maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp; 655 maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp;
670 656
671 usb_fill_int_urb(ati_remote->irq_urb, udev, pipe, ati_remote->inbuf, 657 usb_fill_int_urb(ati_remote->irq_urb, udev, pipe, ati_remote->inbuf,
672 maxp, ati_remote_irq_in, ati_remote, 658 maxp, ati_remote_irq_in, ati_remote,
673 ati_remote->endpoint_in->bInterval); 659 ati_remote->endpoint_in->bInterval);
674 ati_remote->irq_urb->transfer_dma = ati_remote->inbuf_dma; 660 ati_remote->irq_urb->transfer_dma = ati_remote->inbuf_dma;
675 ati_remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 661 ati_remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
676 662
677 /* Set up out_urb */ 663 /* Set up out_urb */
678 pipe = usb_sndintpipe(udev, ati_remote->endpoint_out->bEndpointAddress); 664 pipe = usb_sndintpipe(udev, ati_remote->endpoint_out->bEndpointAddress);
679 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); 665 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
680 maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp; 666 maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp;
681 667
682 usb_fill_int_urb(ati_remote->out_urb, udev, pipe, ati_remote->outbuf, 668 usb_fill_int_urb(ati_remote->out_urb, udev, pipe, ati_remote->outbuf,
683 maxp, ati_remote_irq_out, ati_remote, 669 maxp, ati_remote_irq_out, ati_remote,
684 ati_remote->endpoint_out->bInterval); 670 ati_remote->endpoint_out->bInterval);
685 ati_remote->out_urb->transfer_dma = ati_remote->outbuf_dma; 671 ati_remote->out_urb->transfer_dma = ati_remote->outbuf_dma;
686 ati_remote->out_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 672 ati_remote->out_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
@@ -688,11 +674,11 @@ static int ati_remote_initialize(struct ati_remote *ati_remote)
688 /* send initialization strings */ 674 /* send initialization strings */
689 if ((ati_remote_sendpacket(ati_remote, 0x8004, init1)) || 675 if ((ati_remote_sendpacket(ati_remote, 0x8004, init1)) ||
690 (ati_remote_sendpacket(ati_remote, 0x8007, init2))) { 676 (ati_remote_sendpacket(ati_remote, 0x8007, init2))) {
691 dev_err(&ati_remote->interface->dev, 677 dev_err(&ati_remote->interface->dev,
692 "Initializing ati_remote hardware failed.\n"); 678 "Initializing ati_remote hardware failed.\n");
693 return 1; 679 return 1;
694 } 680 }
695 681
696 return 0; 682 return 0;
697} 683}
698 684
@@ -769,7 +755,7 @@ static int ati_remote_probe(struct usb_interface *interface, const struct usb_de
769 755
770 if (!strlen(ati_remote->name)) 756 if (!strlen(ati_remote->name))
771 sprintf(ati_remote->name, DRIVER_DESC "(%04x,%04x)", 757 sprintf(ati_remote->name, DRIVER_DESC "(%04x,%04x)",
772 le16_to_cpu(ati_remote->udev->descriptor.idVendor), 758 le16_to_cpu(ati_remote->udev->descriptor.idVendor),
773 le16_to_cpu(ati_remote->udev->descriptor.idProduct)); 759 le16_to_cpu(ati_remote->udev->descriptor.idProduct));
774 760
775 /* Device Hardware Initialization - fills in ati_remote->idev from udev. */ 761 /* Device Hardware Initialization - fills in ati_remote->idev from udev. */
@@ -781,11 +767,11 @@ static int ati_remote_probe(struct usb_interface *interface, const struct usb_de
781 ati_remote_input_init(ati_remote); 767 ati_remote_input_init(ati_remote);
782 input_register_device(&ati_remote->idev); 768 input_register_device(&ati_remote->idev);
783 769
784 dev_info(&ati_remote->interface->dev, "Input registered: %s on %s\n", 770 dev_info(&ati_remote->interface->dev, "Input registered: %s on %s\n",
785 ati_remote->name, path); 771 ati_remote->name, path);
786 772
787 usb_set_intfdata(interface, ati_remote); 773 usb_set_intfdata(interface, ati_remote);
788 774
789error: 775error:
790 if (retval) 776 if (retval)
791 ati_remote_delete(ati_remote); 777 ati_remote_delete(ati_remote);
@@ -800,18 +786,14 @@ static void ati_remote_disconnect(struct usb_interface *interface)
800{ 786{
801 struct ati_remote *ati_remote; 787 struct ati_remote *ati_remote;
802 788
803 down(&disconnect_sem);
804
805 ati_remote = usb_get_intfdata(interface); 789 ati_remote = usb_get_intfdata(interface);
806 usb_set_intfdata(interface, NULL); 790 usb_set_intfdata(interface, NULL);
807 if (!ati_remote) { 791 if (!ati_remote) {
808 warn("%s - null device?\n", __FUNCTION__); 792 warn("%s - null device?\n", __FUNCTION__);
809 return; 793 return;
810 } 794 }
811
812 ati_remote_delete(ati_remote);
813 795
814 up(&disconnect_sem); 796 ati_remote_delete(ati_remote);
815} 797}
816 798
817/* 799/*
@@ -820,7 +802,7 @@ static void ati_remote_disconnect(struct usb_interface *interface)
820static int __init ati_remote_init(void) 802static int __init ati_remote_init(void)
821{ 803{
822 int result; 804 int result;
823 805
824 result = usb_register(&ati_remote_driver); 806 result = usb_register(&ati_remote_driver);
825 if (result) 807 if (result)
826 err("usb_register error #%d\n", result); 808 err("usb_register error #%d\n", result);
@@ -838,8 +820,8 @@ static void __exit ati_remote_exit(void)
838 usb_deregister(&ati_remote_driver); 820 usb_deregister(&ati_remote_driver);
839} 821}
840 822
841/* 823/*
842 * module specification 824 * module specification
843 */ 825 */
844 826
845module_init(ati_remote_init); 827module_init(ati_remote_init);
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 740dec1f521d..100b49bd1d3e 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -232,7 +232,7 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign
232 report->size += parser->global.report_size * parser->global.report_count; 232 report->size += parser->global.report_size * parser->global.report_count;
233 233
234 if (!parser->local.usage_index) /* Ignore padding fields */ 234 if (!parser->local.usage_index) /* Ignore padding fields */
235 return 0; 235 return 0;
236 236
237 usages = max_t(int, parser->local.usage_index, parser->global.report_count); 237 usages = max_t(int, parser->local.usage_index, parser->global.report_count);
238 238
@@ -765,7 +765,7 @@ static __inline__ __u32 s32ton(__s32 value, unsigned n)
765static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n) 765static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
766{ 766{
767 report += (offset >> 5) << 2; offset &= 31; 767 report += (offset >> 5) << 2; offset &= 31;
768 return (le64_to_cpu(get_unaligned((__le64*)report)) >> offset) & ((1 << n) - 1); 768 return (le64_to_cpu(get_unaligned((__le64*)report)) >> offset) & ((1ULL << n) - 1);
769} 769}
770 770
771static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value) 771static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value)
@@ -1233,6 +1233,13 @@ int hid_wait_io(struct hid_device *hid)
1233 return 0; 1233 return 0;
1234} 1234}
1235 1235
1236static int hid_set_idle(struct usb_device *dev, int ifnum, int report, int idle)
1237{
1238 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1239 HID_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, (idle << 8) | report,
1240 ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT);
1241}
1242
1236static int hid_get_class_descriptor(struct usb_device *dev, int ifnum, 1243static int hid_get_class_descriptor(struct usb_device *dev, int ifnum,
1237 unsigned char type, void *buf, int size) 1244 unsigned char type, void *buf, int size)
1238{ 1245{
@@ -1301,10 +1308,6 @@ void hid_init_reports(struct hid_device *hid)
1301 1308
1302 if (err) 1309 if (err)
1303 warn("timeout initializing reports\n"); 1310 warn("timeout initializing reports\n");
1304
1305 usb_control_msg(hid->dev, usb_sndctrlpipe(hid->dev, 0),
1306 HID_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0,
1307 hid->ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT);
1308} 1311}
1309 1312
1310#define USB_VENDOR_ID_WACOM 0x056a 1313#define USB_VENDOR_ID_WACOM 0x056a
@@ -1318,6 +1321,10 @@ void hid_init_reports(struct hid_device *hid)
1318#define USB_DEVICE_ID_WACOM_INTUOS3 0x00B0 1321#define USB_DEVICE_ID_WACOM_INTUOS3 0x00B0
1319#define USB_DEVICE_ID_WACOM_CINTIQ 0x003F 1322#define USB_DEVICE_ID_WACOM_CINTIQ 0x003F
1320 1323
1324#define USB_VENDOR_ID_ACECAD 0x0460
1325#define USB_DEVICE_ID_ACECAD_FLAIR 0x0004
1326#define USB_DEVICE_ID_ACECAD_302 0x0008
1327
1321#define USB_VENDOR_ID_KBGEAR 0x084e 1328#define USB_VENDOR_ID_KBGEAR 0x084e
1322#define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001 1329#define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001
1323 1330
@@ -1502,6 +1509,9 @@ static struct hid_blacklist {
1502 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, 1509 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1503 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, 1510 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1504 1511
1512 { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR, HID_QUIRK_IGNORE },
1513 { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302, HID_QUIRK_IGNORE },
1514
1505 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET }, 1515 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET },
1506 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET }, 1516 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET },
1507 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, 1517 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET },
@@ -1590,6 +1600,8 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1590 return NULL; 1600 return NULL;
1591 } 1601 }
1592 1602
1603 hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0);
1604
1593 if ((n = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize)) < 0) { 1605 if ((n = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize)) < 0) {
1594 dbg("reading report descriptor failed"); 1606 dbg("reading report descriptor failed");
1595 kfree(rdesc); 1607 kfree(rdesc);
@@ -1635,7 +1647,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1635 /* Change the polling interval of mice. */ 1647 /* Change the polling interval of mice. */
1636 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0) 1648 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
1637 interval = hid_mousepoll_interval; 1649 interval = hid_mousepoll_interval;
1638 1650
1639 if (endpoint->bEndpointAddress & USB_DIR_IN) { 1651 if (endpoint->bEndpointAddress & USB_DIR_IN) {
1640 if (hid->urbin) 1652 if (hid->urbin)
1641 continue; 1653 continue;
diff --git a/drivers/usb/input/hid-debug.h b/drivers/usb/input/hid-debug.h
index 2b91705740a7..52437e5e2e78 100644
--- a/drivers/usb/input/hid-debug.h
+++ b/drivers/usb/input/hid-debug.h
@@ -67,7 +67,7 @@ static const struct hid_usage_entry hid_usage_table[] = {
67 {0, 0x44, "Vbry"}, 67 {0, 0x44, "Vbry"},
68 {0, 0x45, "Vbrz"}, 68 {0, 0x45, "Vbrz"},
69 {0, 0x46, "Vno"}, 69 {0, 0x46, "Vno"},
70 {0, 0x80, "SystemControl"}, 70 {0, 0x80, "SystemControl"},
71 {0, 0x81, "SystemPowerDown"}, 71 {0, 0x81, "SystemPowerDown"},
72 {0, 0x82, "SystemSleep"}, 72 {0, 0x82, "SystemSleep"},
73 {0, 0x83, "SystemWakeUp"}, 73 {0, 0x83, "SystemWakeUp"},
@@ -347,7 +347,7 @@ __inline__ static void tab(int n) {
347 347
348static void hid_dump_field(struct hid_field *field, int n) { 348static void hid_dump_field(struct hid_field *field, int n) {
349 int j; 349 int j;
350 350
351 if (field->physical) { 351 if (field->physical) {
352 tab(n); 352 tab(n);
353 printk("Physical("); 353 printk("Physical(");
@@ -408,7 +408,7 @@ static void hid_dump_field(struct hid_field *field, int n) {
408 printk("%s", units[sys][i]); 408 printk("%s", units[sys][i]);
409 if(nibble != 1) { 409 if(nibble != 1) {
410 /* This is a _signed_ nibble(!) */ 410 /* This is a _signed_ nibble(!) */
411 411
412 int val = nibble & 0x7; 412 int val = nibble & 0x7;
413 if(nibble & 0x08) 413 if(nibble & 0x08)
414 val = -((0x7 & ~val) +1); 414 val = -((0x7 & ~val) +1);
@@ -443,7 +443,7 @@ static void __attribute__((unused)) hid_dump_device(struct hid_device *device) {
443 struct list_head *list; 443 struct list_head *list;
444 unsigned i,k; 444 unsigned i,k;
445 static char *table[] = {"INPUT", "OUTPUT", "FEATURE"}; 445 static char *table[] = {"INPUT", "OUTPUT", "FEATURE"};
446 446
447 for (i = 0; i < HID_REPORT_TYPES; i++) { 447 for (i = 0; i < HID_REPORT_TYPES; i++) {
448 report_enum = device->report_enum + i; 448 report_enum = device->report_enum + i;
449 list = report_enum->report_list.next; 449 list = report_enum->report_list.next;
@@ -664,8 +664,8 @@ static char *keys[KEY_MAX + 1] = {
664static char *relatives[REL_MAX + 1] = { 664static char *relatives[REL_MAX + 1] = {
665 [REL_X] = "X", [REL_Y] = "Y", 665 [REL_X] = "X", [REL_Y] = "Y",
666 [REL_Z] = "Z", [REL_HWHEEL] = "HWheel", 666 [REL_Z] = "Z", [REL_HWHEEL] = "HWheel",
667 [REL_DIAL] = "Dial", [REL_WHEEL] = "Wheel", 667 [REL_DIAL] = "Dial", [REL_WHEEL] = "Wheel",
668 [REL_MISC] = "Misc", 668 [REL_MISC] = "Misc",
669}; 669};
670 670
671static char *absolutes[ABS_MAX + 1] = { 671static char *absolutes[ABS_MAX + 1] = {
@@ -690,9 +690,9 @@ static char *misc[MSC_MAX + 1] = {
690}; 690};
691 691
692static char *leds[LED_MAX + 1] = { 692static char *leds[LED_MAX + 1] = {
693 [LED_NUML] = "NumLock", [LED_CAPSL] = "CapsLock", 693 [LED_NUML] = "NumLock", [LED_CAPSL] = "CapsLock",
694 [LED_SCROLLL] = "ScrollLock", [LED_COMPOSE] = "Compose", 694 [LED_SCROLLL] = "ScrollLock", [LED_COMPOSE] = "Compose",
695 [LED_KANA] = "Kana", [LED_SLEEP] = "Sleep", 695 [LED_KANA] = "Kana", [LED_SLEEP] = "Sleep",
696 [LED_SUSPEND] = "Suspend", [LED_MUTE] = "Mute", 696 [LED_SUSPEND] = "Suspend", [LED_MUTE] = "Mute",
697 [LED_MISC] = "Misc", 697 [LED_MISC] = "Misc",
698}; 698};
diff --git a/drivers/usb/input/hid-input.c b/drivers/usb/input/hid-input.c
index 5553c3553e9d..9ac1e9095334 100644
--- a/drivers/usb/input/hid-input.c
+++ b/drivers/usb/input/hid-input.c
@@ -164,7 +164,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
164 case HID_GD_X: case HID_GD_Y: case HID_GD_Z: 164 case HID_GD_X: case HID_GD_Y: case HID_GD_Z:
165 case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ: 165 case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ:
166 case HID_GD_SLIDER: case HID_GD_DIAL: case HID_GD_WHEEL: 166 case HID_GD_SLIDER: case HID_GD_DIAL: case HID_GD_WHEEL:
167 if (field->flags & HID_MAIN_ITEM_RELATIVE) 167 if (field->flags & HID_MAIN_ITEM_RELATIVE)
168 map_rel(usage->hid & 0xf); 168 map_rel(usage->hid & 0xf);
169 else 169 else
170 map_abs(usage->hid & 0xf); 170 map_abs(usage->hid & 0xf);
@@ -297,7 +297,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
297 case HID_UP_MSVENDOR: 297 case HID_UP_MSVENDOR:
298 298
299 goto ignore; 299 goto ignore;
300 300
301 case HID_UP_PID: 301 case HID_UP_PID:
302 302
303 set_bit(EV_FF, input->evbit); 303 set_bit(EV_FF, input->evbit);
@@ -349,7 +349,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
349 goto ignore; 349 goto ignore;
350 350
351 if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 | HID_QUIRK_2WHEEL_MOUSE_HACK_5)) && 351 if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 | HID_QUIRK_2WHEEL_MOUSE_HACK_5)) &&
352 (usage->type == EV_REL) && (usage->code == REL_WHEEL)) 352 (usage->type == EV_REL) && (usage->code == REL_WHEEL))
353 set_bit(REL_HWHEEL, bit); 353 set_bit(REL_HWHEEL, bit);
354 354
355 if (((device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_5) && (usage->hid == 0x00090005)) 355 if (((device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_5) && (usage->hid == 0x00090005))
@@ -365,11 +365,11 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
365 a = field->logical_minimum = 0; 365 a = field->logical_minimum = 0;
366 b = field->logical_maximum = 255; 366 b = field->logical_maximum = 255;
367 } 367 }
368 368
369 if (field->application == HID_GD_GAMEPAD || field->application == HID_GD_JOYSTICK) 369 if (field->application == HID_GD_GAMEPAD || field->application == HID_GD_JOYSTICK)
370 input_set_abs_params(input, usage->code, a, b, (b - a) >> 8, (b - a) >> 4); 370 input_set_abs_params(input, usage->code, a, b, (b - a) >> 8, (b - a) >> 4);
371 else input_set_abs_params(input, usage->code, a, b, 0, 0); 371 else input_set_abs_params(input, usage->code, a, b, 0, 0);
372 372
373 } 373 }
374 374
375 if (usage->hat_min < usage->hat_max || usage->hat_dir) { 375 if (usage->hat_min < usage->hat_max || usage->hat_dir) {
@@ -420,7 +420,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
420 return; 420 return;
421 } 421 }
422 422
423 if (usage->hat_min < usage->hat_max || usage->hat_dir) { 423 if (usage->hat_min < usage->hat_max || usage->hat_dir) {
424 int hat_dir = usage->hat_dir; 424 int hat_dir = usage->hat_dir;
425 if (!hat_dir) 425 if (!hat_dir)
426 hat_dir = (value - usage->hat_min) * 8 / (usage->hat_max - usage->hat_min + 1) + 1; 426 hat_dir = (value - usage->hat_min) * 8 / (usage->hat_max - usage->hat_min + 1) + 1;
@@ -551,7 +551,7 @@ int hidinput_connect(struct hid_device *hid)
551 for (i = 0; i < hid->maxcollection; i++) 551 for (i = 0; i < hid->maxcollection; i++)
552 if (hid->collection[i].type == HID_COLLECTION_APPLICATION || 552 if (hid->collection[i].type == HID_COLLECTION_APPLICATION ||
553 hid->collection[i].type == HID_COLLECTION_PHYSICAL) 553 hid->collection[i].type == HID_COLLECTION_PHYSICAL)
554 if (IS_INPUT_APPLICATION(hid->collection[i].usage)) 554 if (IS_INPUT_APPLICATION(hid->collection[i].usage))
555 break; 555 break;
556 556
557 if (i == hid->maxcollection) 557 if (i == hid->maxcollection)
@@ -592,7 +592,7 @@ int hidinput_connect(struct hid_device *hid)
592 for (j = 0; j < report->field[i]->maxusage; j++) 592 for (j = 0; j < report->field[i]->maxusage; j++)
593 hidinput_configure_usage(hidinput, report->field[i], 593 hidinput_configure_usage(hidinput, report->field[i],
594 report->field[i]->usage + j); 594 report->field[i]->usage + j);
595 595
596 if (hid->quirks & HID_QUIRK_MULTI_INPUT) { 596 if (hid->quirks & HID_QUIRK_MULTI_INPUT) {
597 /* This will leave hidinput NULL, so that it 597 /* This will leave hidinput NULL, so that it
598 * allocates another one if we have more inputs on 598 * allocates another one if we have more inputs on
diff --git a/drivers/usb/input/hid-lgff.c b/drivers/usb/input/hid-lgff.c
index 0d7404bab92f..0c4c77aa31ea 100644
--- a/drivers/usb/input/hid-lgff.c
+++ b/drivers/usb/input/hid-lgff.c
@@ -94,7 +94,7 @@ struct lgff_device {
94 isn't really necessary */ 94 isn't really necessary */
95 95
96 unsigned long flags[1]; /* Contains various information about the 96 unsigned long flags[1]; /* Contains various information about the
97 state of the driver for this device */ 97 state of the driver for this device */
98 98
99 struct timer_list timer; 99 struct timer_list timer;
100}; 100};
@@ -234,7 +234,7 @@ static struct hid_report* hid_lgff_duplicate_report(struct hid_report* report)
234 kfree(ret); 234 kfree(ret);
235 return NULL; 235 return NULL;
236 } 236 }
237 memset(ret->field[0]->value, 0, sizeof(s32[8])); 237 memset(ret->field[0]->value, 0, sizeof(s32[8]));
238 238
239 return ret; 239 return ret;
240} 240}
@@ -295,11 +295,11 @@ static int hid_lgff_event(struct hid_device *hid, struct input_dev* input,
295 unsigned long flags; 295 unsigned long flags;
296 296
297 if (type != EV_FF) return -EINVAL; 297 if (type != EV_FF) return -EINVAL;
298 if (!LGFF_CHECK_OWNERSHIP(code, lgff)) return -EACCES; 298 if (!LGFF_CHECK_OWNERSHIP(code, lgff)) return -EACCES;
299 if (value < 0) return -EINVAL; 299 if (value < 0) return -EINVAL;
300 300
301 spin_lock_irqsave(&lgff->lock, flags); 301 spin_lock_irqsave(&lgff->lock, flags);
302 302
303 if (value > 0) { 303 if (value > 0) {
304 if (test_bit(EFFECT_STARTED, effect->flags)) { 304 if (test_bit(EFFECT_STARTED, effect->flags)) {
305 spin_unlock_irqrestore(&lgff->lock, flags); 305 spin_unlock_irqrestore(&lgff->lock, flags);
@@ -345,7 +345,7 @@ static int hid_lgff_flush(struct input_dev *dev, struct file *file)
345 and perform ioctls on the same fd all at the same time */ 345 and perform ioctls on the same fd all at the same time */
346 if ( current->pid == lgff->effects[i].owner 346 if ( current->pid == lgff->effects[i].owner
347 && test_bit(EFFECT_USED, lgff->effects[i].flags)) { 347 && test_bit(EFFECT_USED, lgff->effects[i].flags)) {
348 348
349 if (hid_lgff_erase(dev, i)) 349 if (hid_lgff_erase(dev, i))
350 warn("erase effect %d failed", i); 350 warn("erase effect %d failed", i);
351 } 351 }
@@ -378,7 +378,7 @@ static int hid_lgff_upload_effect(struct input_dev* input,
378 struct lgff_effect new; 378 struct lgff_effect new;
379 int id; 379 int id;
380 unsigned long flags; 380 unsigned long flags;
381 381
382 dbg("ioctl rumble"); 382 dbg("ioctl rumble");
383 383
384 if (!test_bit(effect->type, input->ffbit)) return -EINVAL; 384 if (!test_bit(effect->type, input->ffbit)) return -EINVAL;
@@ -441,7 +441,7 @@ static void hid_lgff_timer(unsigned long timer_data)
441 441
442 spin_lock_irqsave(&lgff->lock, flags); 442 spin_lock_irqsave(&lgff->lock, flags);
443 443
444 for (i=0; i<LGFF_EFFECTS; ++i) { 444 for (i=0; i<LGFF_EFFECTS; ++i) {
445 struct lgff_effect* effect = lgff->effects +i; 445 struct lgff_effect* effect = lgff->effects +i;
446 446
447 if (test_bit(EFFECT_PLAYING, effect->flags)) { 447 if (test_bit(EFFECT_PLAYING, effect->flags)) {
@@ -491,7 +491,7 @@ static void hid_lgff_timer(unsigned long timer_data)
491 set_bit(EFFECT_PLAYING, lgff->effects[i].flags); 491 set_bit(EFFECT_PLAYING, lgff->effects[i].flags);
492 } 492 }
493 } 493 }
494 } 494 }
495 495
496#define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff 496#define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff
497 497
@@ -524,5 +524,5 @@ static void hid_lgff_timer(unsigned long timer_data)
524 add_timer(&lgff->timer); 524 add_timer(&lgff->timer);
525 } 525 }
526 526
527 spin_unlock_irqrestore(&lgff->lock, flags); 527 spin_unlock_irqrestore(&lgff->lock, flags);
528} 528}
diff --git a/drivers/usb/input/hid.h b/drivers/usb/input/hid.h
index 6d9329c698d9..c1b6b69bc4a4 100644
--- a/drivers/usb/input/hid.h
+++ b/drivers/usb/input/hid.h
@@ -118,7 +118,7 @@ struct hid_item {
118#define HID_MAIN_ITEM_CONSTANT 0x001 118#define HID_MAIN_ITEM_CONSTANT 0x001
119#define HID_MAIN_ITEM_VARIABLE 0x002 119#define HID_MAIN_ITEM_VARIABLE 0x002
120#define HID_MAIN_ITEM_RELATIVE 0x004 120#define HID_MAIN_ITEM_RELATIVE 0x004
121#define HID_MAIN_ITEM_WRAP 0x008 121#define HID_MAIN_ITEM_WRAP 0x008
122#define HID_MAIN_ITEM_NONLINEAR 0x010 122#define HID_MAIN_ITEM_NONLINEAR 0x010
123#define HID_MAIN_ITEM_NO_PREFERRED 0x020 123#define HID_MAIN_ITEM_NO_PREFERRED 0x020
124#define HID_MAIN_ITEM_NULL_STATE 0x040 124#define HID_MAIN_ITEM_NULL_STATE 0x040
@@ -172,14 +172,14 @@ struct hid_item {
172#define HID_USAGE_PAGE 0xffff0000 172#define HID_USAGE_PAGE 0xffff0000
173 173
174#define HID_UP_UNDEFINED 0x00000000 174#define HID_UP_UNDEFINED 0x00000000
175#define HID_UP_GENDESK 0x00010000 175#define HID_UP_GENDESK 0x00010000
176#define HID_UP_KEYBOARD 0x00070000 176#define HID_UP_KEYBOARD 0x00070000
177#define HID_UP_LED 0x00080000 177#define HID_UP_LED 0x00080000
178#define HID_UP_BUTTON 0x00090000 178#define HID_UP_BUTTON 0x00090000
179#define HID_UP_ORDINAL 0x000a0000 179#define HID_UP_ORDINAL 0x000a0000
180#define HID_UP_CONSUMER 0x000c0000 180#define HID_UP_CONSUMER 0x000c0000
181#define HID_UP_DIGITIZER 0x000d0000 181#define HID_UP_DIGITIZER 0x000d0000
182#define HID_UP_PID 0x000f0000 182#define HID_UP_PID 0x000f0000
183#define HID_UP_HPVENDOR 0xff7f0000 183#define HID_UP_HPVENDOR 0xff7f0000
184#define HID_UP_MSVENDOR 0xff000000 184#define HID_UP_MSVENDOR 0xff000000
185 185
@@ -406,7 +406,7 @@ struct hid_device { /* device report descriptor */
406 dma_addr_t outbuf_dma; /* Output buffer dma */ 406 dma_addr_t outbuf_dma; /* Output buffer dma */
407 spinlock_t outlock; /* Output fifo spinlock */ 407 spinlock_t outlock; /* Output fifo spinlock */
408 408
409 unsigned claimed; /* Claimed by hidinput, hiddev? */ 409 unsigned claimed; /* Claimed by hidinput, hiddev? */
410 unsigned quirks; /* Various quirks the device can pull on us */ 410 unsigned quirks; /* Various quirks the device can pull on us */
411 411
412 struct list_head inputs; /* The list of inputs */ 412 struct list_head inputs; /* The list of inputs */
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
index 96b7c9067951..4c13331b5f41 100644
--- a/drivers/usb/input/hiddev.c
+++ b/drivers/usb/input/hiddev.c
@@ -95,7 +95,7 @@ hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo)
95 return NULL; 95 return NULL;
96 rinfo->report_id = ((struct hid_report *) list)->id; 96 rinfo->report_id = ((struct hid_report *) list)->id;
97 break; 97 break;
98 98
99 case HID_REPORT_ID_NEXT: 99 case HID_REPORT_ID_NEXT:
100 list = (struct list_head *) 100 list = (struct list_head *)
101 report_enum->report_id_hash[rinfo->report_id & HID_REPORT_ID_MASK]; 101 report_enum->report_id_hash[rinfo->report_id & HID_REPORT_ID_MASK];
@@ -106,7 +106,7 @@ hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo)
106 return NULL; 106 return NULL;
107 rinfo->report_id = ((struct hid_report *) list)->id; 107 rinfo->report_id = ((struct hid_report *) list)->id;
108 break; 108 break;
109 109
110 default: 110 default:
111 return NULL; 111 return NULL;
112 } 112 }
@@ -158,7 +158,7 @@ static void hiddev_send_event(struct hid_device *hid,
158 if (uref->field_index != HID_FIELD_INDEX_NONE || 158 if (uref->field_index != HID_FIELD_INDEX_NONE ||
159 (list->flags & HIDDEV_FLAG_REPORT) != 0) { 159 (list->flags & HIDDEV_FLAG_REPORT) != 0) {
160 list->buffer[list->head] = *uref; 160 list->buffer[list->head] = *uref;
161 list->head = (list->head + 1) & 161 list->head = (list->head + 1) &
162 (HIDDEV_BUFFER_SIZE - 1); 162 (HIDDEV_BUFFER_SIZE - 1);
163 kill_fasync(&list->fasync, SIGIO, POLL_IN); 163 kill_fasync(&list->fasync, SIGIO, POLL_IN);
164 } 164 }
@@ -179,9 +179,9 @@ void hiddev_hid_event(struct hid_device *hid, struct hid_field *field,
179 unsigned type = field->report_type; 179 unsigned type = field->report_type;
180 struct hiddev_usage_ref uref; 180 struct hiddev_usage_ref uref;
181 181
182 uref.report_type = 182 uref.report_type =
183 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : 183 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT :
184 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : 184 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT :
185 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE:0)); 185 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE:0));
186 uref.report_id = field->report->id; 186 uref.report_id = field->report->id;
187 uref.field_index = field->index; 187 uref.field_index = field->index;
@@ -199,9 +199,9 @@ void hiddev_report_event(struct hid_device *hid, struct hid_report *report)
199 struct hiddev_usage_ref uref; 199 struct hiddev_usage_ref uref;
200 200
201 memset(&uref, 0, sizeof(uref)); 201 memset(&uref, 0, sizeof(uref));
202 uref.report_type = 202 uref.report_type =
203 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : 203 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT :
204 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : 204 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT :
205 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE:0)); 205 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE:0));
206 uref.report_id = report->id; 206 uref.report_id = report->id;
207 uref.field_index = HID_FIELD_INDEX_NONE; 207 uref.field_index = HID_FIELD_INDEX_NONE;
@@ -236,7 +236,7 @@ static int hiddev_release(struct inode * inode, struct file * file)
236 *listptr = (*listptr)->next; 236 *listptr = (*listptr)->next;
237 237
238 if (!--list->hiddev->open) { 238 if (!--list->hiddev->open) {
239 if (list->hiddev->exist) 239 if (list->hiddev->exist)
240 hid_close(list->hiddev->hid); 240 hid_close(list->hiddev->hid);
241 else 241 else
242 kfree(list->hiddev); 242 kfree(list->hiddev);
@@ -303,7 +303,7 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
303 if (list->head == list->tail) { 303 if (list->head == list->tail) {
304 add_wait_queue(&list->hiddev->wait, &wait); 304 add_wait_queue(&list->hiddev->wait, &wait);
305 set_current_state(TASK_INTERRUPTIBLE); 305 set_current_state(TASK_INTERRUPTIBLE);
306 306
307 while (list->head == list->tail) { 307 while (list->head == list->tail) {
308 if (file->f_flags & O_NONBLOCK) { 308 if (file->f_flags & O_NONBLOCK) {
309 retval = -EAGAIN; 309 retval = -EAGAIN;
@@ -317,7 +317,7 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
317 retval = -EIO; 317 retval = -EIO;
318 break; 318 break;
319 } 319 }
320 320
321 schedule(); 321 schedule();
322 } 322 }
323 323
@@ -329,7 +329,7 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
329 return retval; 329 return retval;
330 330
331 331
332 while (list->head != list->tail && 332 while (list->head != list->tail &&
333 retval + event_size <= count) { 333 retval + event_size <= count) {
334 if ((list->flags & HIDDEV_FLAG_UREF) == 0) { 334 if ((list->flags & HIDDEV_FLAG_UREF) == 0) {
335 if (list->buffer[list->tail].field_index != 335 if (list->buffer[list->tail].field_index !=
@@ -405,10 +405,10 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
405 return -EINVAL; 405 return -EINVAL;
406 406
407 for (i = 0; i < hid->maxcollection; i++) 407 for (i = 0; i < hid->maxcollection; i++)
408 if (hid->collection[i].type == 408 if (hid->collection[i].type ==
409 HID_COLLECTION_APPLICATION && arg-- == 0) 409 HID_COLLECTION_APPLICATION && arg-- == 0)
410 break; 410 break;
411 411
412 if (i == hid->maxcollection) 412 if (i == hid->maxcollection)
413 return -EINVAL; 413 return -EINVAL;
414 414
@@ -562,7 +562,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
562 if (!uref_multi) 562 if (!uref_multi)
563 return -ENOMEM; 563 return -ENOMEM;
564 uref = &uref_multi->uref; 564 uref = &uref_multi->uref;
565 if (copy_from_user(uref, user_arg, sizeof(*uref))) 565 if (copy_from_user(uref, user_arg, sizeof(*uref)))
566 goto fault; 566 goto fault;
567 567
568 rinfo.report_type = uref->report_type; 568 rinfo.report_type = uref->report_type;
@@ -595,7 +595,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
595 return -ENOMEM; 595 return -ENOMEM;
596 uref = &uref_multi->uref; 596 uref = &uref_multi->uref;
597 if (cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) { 597 if (cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) {
598 if (copy_from_user(uref_multi, user_arg, 598 if (copy_from_user(uref_multi, user_arg,
599 sizeof(*uref_multi))) 599 sizeof(*uref_multi)))
600 goto fault; 600 goto fault;
601 } else { 601 } else {
@@ -603,7 +603,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
603 goto fault; 603 goto fault;
604 } 604 }
605 605
606 if (cmd != HIDIOCGUSAGE && 606 if (cmd != HIDIOCGUSAGE &&
607 cmd != HIDIOCGUSAGES && 607 cmd != HIDIOCGUSAGES &&
608 uref->report_type == HID_REPORT_TYPE_INPUT) 608 uref->report_type == HID_REPORT_TYPE_INPUT)
609 goto inval; 609 goto inval;
@@ -651,16 +651,16 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
651 return field->usage[uref->usage_index].collection_index; 651 return field->usage[uref->usage_index].collection_index;
652 case HIDIOCGUSAGES: 652 case HIDIOCGUSAGES:
653 for (i = 0; i < uref_multi->num_values; i++) 653 for (i = 0; i < uref_multi->num_values; i++)
654 uref_multi->values[i] = 654 uref_multi->values[i] =
655 field->value[uref->usage_index + i]; 655 field->value[uref->usage_index + i];
656 if (copy_to_user(user_arg, uref_multi, 656 if (copy_to_user(user_arg, uref_multi,
657 sizeof(*uref_multi))) 657 sizeof(*uref_multi)))
658 goto fault; 658 goto fault;
659 goto goodreturn; 659 goto goodreturn;
660 case HIDIOCSUSAGES: 660 case HIDIOCSUSAGES:
661 for (i = 0; i < uref_multi->num_values; i++) 661 for (i = 0; i < uref_multi->num_values; i++)
662 field->value[uref->usage_index + i] = 662 field->value[uref->usage_index + i] =
663 uref_multi->values[i]; 663 uref_multi->values[i];
664 goto goodreturn; 664 goto goodreturn;
665 } 665 }
666 666
@@ -670,7 +670,7 @@ goodreturn:
670fault: 670fault:
671 kfree(uref_multi); 671 kfree(uref_multi);
672 return -EFAULT; 672 return -EFAULT;
673inval: 673inval:
674 kfree(uref_multi); 674 kfree(uref_multi);
675 return -EINVAL; 675 return -EINVAL;
676 676
@@ -734,7 +734,7 @@ static struct usb_class_driver hiddev_class = {
734 .name = "usb/hid/hiddev%d", 734 .name = "usb/hid/hiddev%d",
735 .fops = &hiddev_fops, 735 .fops = &hiddev_fops,
736 .mode = S_IFCHR | S_IRUGO | S_IWUSR, 736 .mode = S_IFCHR | S_IRUGO | S_IWUSR,
737 .minor_base = HIDDEV_MINOR_BASE, 737 .minor_base = HIDDEV_MINOR_BASE,
738}; 738};
739 739
740/* 740/*
@@ -747,7 +747,7 @@ int hiddev_connect(struct hid_device *hid)
747 int retval; 747 int retval;
748 748
749 for (i = 0; i < hid->maxcollection; i++) 749 for (i = 0; i < hid->maxcollection; i++)
750 if (hid->collection[i].type == 750 if (hid->collection[i].type ==
751 HID_COLLECTION_APPLICATION && 751 HID_COLLECTION_APPLICATION &&
752 !IS_INPUT_APPLICATION(hid->collection[i].usage)) 752 !IS_INPUT_APPLICATION(hid->collection[i].usage))
753 break; 753 break;
@@ -755,11 +755,11 @@ int hiddev_connect(struct hid_device *hid)
755 if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDDEV) == 0) 755 if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDDEV) == 0)
756 return -1; 756 return -1;
757 757
758 if (!(hiddev = kmalloc(sizeof(struct hiddev), GFP_KERNEL))) 758 if (!(hiddev = kmalloc(sizeof(struct hiddev), GFP_KERNEL)))
759 return -1; 759 return -1;
760 memset(hiddev, 0, sizeof(struct hiddev)); 760 memset(hiddev, 0, sizeof(struct hiddev));
761 761
762 retval = usb_register_dev(hid->intf, &hiddev_class); 762 retval = usb_register_dev(hid->intf, &hiddev_class);
763 if (retval) { 763 if (retval) {
764 err("Not able to get a minor for this device."); 764 err("Not able to get a minor for this device.");
765 kfree(hiddev); 765 kfree(hiddev);
@@ -768,12 +768,12 @@ int hiddev_connect(struct hid_device *hid)
768 768
769 init_waitqueue_head(&hiddev->wait); 769 init_waitqueue_head(&hiddev->wait);
770 770
771 hiddev_table[hid->intf->minor - HIDDEV_MINOR_BASE] = hiddev; 771 hiddev_table[hid->intf->minor - HIDDEV_MINOR_BASE] = hiddev;
772 772
773 hiddev->hid = hid; 773 hiddev->hid = hid;
774 hiddev->exist = 1; 774 hiddev->exist = 1;
775 775
776 hid->minor = hid->intf->minor; 776 hid->minor = hid->intf->minor;
777 hid->hiddev = hiddev; 777 hid->hiddev = hiddev;
778 778
779 return 0; 779 return 0;
@@ -818,7 +818,7 @@ void hiddev_disconnect(struct hid_device *hid)
818/* We never attach in this manner, and rely on HID to connect us. This 818/* We never attach in this manner, and rely on HID to connect us. This
819 * is why there is no disconnect routine defined in the usb_driver either. 819 * is why there is no disconnect routine defined in the usb_driver either.
820 */ 820 */
821static int hiddev_usbd_probe(struct usb_interface *intf, 821static int hiddev_usbd_probe(struct usb_interface *intf,
822 const struct usb_device_id *hiddev_info) 822 const struct usb_device_id *hiddev_info)
823{ 823{
824 return -ENODEV; 824 return -ENODEV;
diff --git a/drivers/usb/input/itmtouch.c b/drivers/usb/input/itmtouch.c
new file mode 100644
index 000000000000..47dec6a1b344
--- /dev/null
+++ b/drivers/usb/input/itmtouch.c
@@ -0,0 +1,268 @@
1/******************************************************************************
2 * itmtouch.c -- Driver for ITM touchscreen panel
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 as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your 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
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 * Based upon original work by Chris Collins <xfire-itmtouch@xware.cx>.
19 *
20 * Kudos to ITM for providing me with the datasheet for the panel,
21 * even though it was a day later than I had finished writing this
22 * driver.
23 *
24 * It has meant that I've been able to correct my interpretation of the
25 * protocol packets however.
26 *
27 * CC -- 2003/9/29
28 *
29 * History
30 * 1.0 & 1.1 2003 (CC) vojtech@suse.cz
31 * Original version for 2.4.x kernels
32 *
33 * 1.2 02/03/2005 (HCE) hc@mivu.no
34 * Complete rewrite to support Linux 2.6.10, thanks to mtouchusb.c for hints.
35 * Unfortunately no calibration support at this time.
36 *
37 * 1.2.1 09/03/2005 (HCE) hc@mivu.no
38 * Code cleanup and adjusting syntax to start matching kernel standards
39 *
40 *****************************************************************************/
41
42#include <linux/config.h>
43
44#ifdef CONFIG_USB_DEBUG
45 #define DEBUG
46#else
47 #undef DEBUG
48#endif
49
50#include <linux/kernel.h>
51#include <linux/slab.h>
52#include <linux/input.h>
53#include <linux/module.h>
54#include <linux/init.h>
55#include <linux/usb.h>
56
57/* only an 8 byte buffer necessary for a single packet */
58#define ITM_BUFSIZE 8
59#define PATH_SIZE 64
60
61#define USB_VENDOR_ID_ITMINC 0x0403
62#define USB_PRODUCT_ID_TOUCHPANEL 0xf9e9
63
64#define DRIVER_AUTHOR "Hans-Christian Egtvedt <hc@mivu.no>"
65#define DRIVER_VERSION "v1.2.1"
66#define DRIVER_DESC "USB ITM Inc Touch Panel Driver"
67#define DRIVER_LICENSE "GPL"
68
69MODULE_AUTHOR( DRIVER_AUTHOR );
70MODULE_DESCRIPTION( DRIVER_DESC );
71MODULE_LICENSE( DRIVER_LICENSE );
72
73struct itmtouch_dev {
74 struct usb_device *usbdev; /* usb device */
75 struct input_dev inputdev; /* input device */
76 struct urb *readurb; /* urb */
77 char rbuf[ITM_BUFSIZE]; /* data */
78 int users;
79 char name[128];
80 char phys[64];
81};
82
83static struct usb_device_id itmtouch_ids [] = {
84 { USB_DEVICE(USB_VENDOR_ID_ITMINC, USB_PRODUCT_ID_TOUCHPANEL) },
85 { }
86};
87
88static void itmtouch_irq(struct urb *urb, struct pt_regs *regs)
89{
90 struct itmtouch_dev * itmtouch = urb->context;
91 unsigned char *data = urb->transfer_buffer;
92 struct input_dev *dev = &itmtouch->inputdev;
93 int retval;
94
95 switch (urb->status) {
96 case 0:
97 /* success */
98 break;
99 case -ETIMEDOUT:
100 /* this urb is timing out */
101 dbg("%s - urb timed out - was the device unplugged?",
102 __FUNCTION__);
103 return;
104 case -ECONNRESET:
105 case -ENOENT:
106 case -ESHUTDOWN:
107 /* this urb is terminated, clean up */
108 dbg("%s - urb shutting down with status: %d",
109 __FUNCTION__, urb->status);
110 return;
111 default:
112 dbg("%s - nonzero urb status received: %d",
113 __FUNCTION__, urb->status);
114 goto exit;
115 }
116
117 input_regs(dev, regs);
118
119 /* if pressure has been released, then don't report X/Y */
120 if (data[7] & 0x20) {
121 input_report_abs(dev, ABS_X, (data[0] & 0x1F) << 7 | (data[3] & 0x7F));
122 input_report_abs(dev, ABS_Y, (data[1] & 0x1F) << 7 | (data[4] & 0x7F));
123 }
124
125 input_report_abs(dev, ABS_PRESSURE, (data[2] & 1) << 7 | (data[5] & 0x7F));
126 input_report_key(dev, BTN_TOUCH, ~data[7] & 0x20);
127 input_sync(dev);
128
129exit:
130 retval = usb_submit_urb (urb, GFP_ATOMIC);
131 if (retval)
132 printk(KERN_ERR "%s - usb_submit_urb failed with result: %d",
133 __FUNCTION__, retval);
134}
135
136static int itmtouch_open(struct input_dev *input)
137{
138 struct itmtouch_dev *itmtouch = input->private;
139
140 itmtouch->readurb->dev = itmtouch->usbdev;
141
142 if (usb_submit_urb(itmtouch->readurb, GFP_KERNEL))
143 return -EIO;
144
145 return 0;
146}
147
148static void itmtouch_close(struct input_dev *input)
149{
150 struct itmtouch_dev *itmtouch = input->private;
151
152 usb_kill_urb(itmtouch->readurb);
153}
154
155static int itmtouch_probe(struct usb_interface *intf, const struct usb_device_id *id)
156{
157 struct itmtouch_dev *itmtouch;
158 struct usb_host_interface *interface;
159 struct usb_endpoint_descriptor *endpoint;
160 struct usb_device *udev = interface_to_usbdev(intf);
161 unsigned int pipe;
162 unsigned int maxp;
163 char path[PATH_SIZE];
164
165 interface = intf->cur_altsetting;
166 endpoint = &interface->endpoint[0].desc;
167
168 if (!(itmtouch = kcalloc(1, sizeof(struct itmtouch_dev), GFP_KERNEL))) {
169 err("%s - Out of memory.", __FUNCTION__);
170 return -ENOMEM;
171 }
172
173 itmtouch->usbdev = udev;
174
175 itmtouch->inputdev.private = itmtouch;
176 itmtouch->inputdev.open = itmtouch_open;
177 itmtouch->inputdev.close = itmtouch_close;
178
179 usb_make_path(udev, path, PATH_SIZE);
180
181 itmtouch->inputdev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
182 itmtouch->inputdev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
183 itmtouch->inputdev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
184
185 itmtouch->inputdev.name = itmtouch->name;
186 itmtouch->inputdev.phys = itmtouch->phys;
187 itmtouch->inputdev.id.bustype = BUS_USB;
188 itmtouch->inputdev.id.vendor = udev->descriptor.idVendor;
189 itmtouch->inputdev.id.product = udev->descriptor.idProduct;
190 itmtouch->inputdev.id.version = udev->descriptor.bcdDevice;
191 itmtouch->inputdev.dev = &intf->dev;
192
193 if (!strlen(itmtouch->name))
194 sprintf(itmtouch->name, "USB ITM touchscreen");
195
196 /* device limits */
197 /* as specified by the ITM datasheet, X and Y are 12bit,
198 * Z (pressure) is 8 bit. However, the fields are defined up
199 * to 14 bits for future possible expansion.
200 */
201 input_set_abs_params(&itmtouch->inputdev, ABS_X, 0, 0x0FFF, 2, 0);
202 input_set_abs_params(&itmtouch->inputdev, ABS_Y, 0, 0x0FFF, 2, 0);
203 input_set_abs_params(&itmtouch->inputdev, ABS_PRESSURE, 0, 0xFF, 2, 0);
204
205 /* initialise the URB so we can read from the transport stream */
206 pipe = usb_rcvintpipe(itmtouch->usbdev, endpoint->bEndpointAddress);
207 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
208
209 if (maxp > ITM_BUFSIZE)
210 maxp = ITM_BUFSIZE;
211
212 itmtouch->readurb = usb_alloc_urb(0, GFP_KERNEL);
213
214 if (!itmtouch->readurb) {
215 dbg("%s - usb_alloc_urb failed: itmtouch->readurb", __FUNCTION__);
216 kfree(itmtouch);
217 return -ENOMEM;
218 }
219
220 usb_fill_int_urb(itmtouch->readurb, itmtouch->usbdev, pipe, itmtouch->rbuf,
221 maxp, itmtouch_irq, itmtouch, endpoint->bInterval);
222
223 input_register_device(&itmtouch->inputdev);
224
225 printk(KERN_INFO "itmtouch: %s registered on %s\n", itmtouch->name, path);
226 usb_set_intfdata(intf, itmtouch);
227
228 return 0;
229}
230
231static void itmtouch_disconnect(struct usb_interface *intf)
232{
233 struct itmtouch_dev *itmtouch = usb_get_intfdata(intf);
234
235 usb_set_intfdata(intf, NULL);
236
237 if (itmtouch) {
238 input_unregister_device(&itmtouch->inputdev);
239 usb_kill_urb(itmtouch->readurb);
240 usb_free_urb(itmtouch->readurb);
241 kfree(itmtouch);
242 }
243}
244
245MODULE_DEVICE_TABLE(usb, itmtouch_ids);
246
247static struct usb_driver itmtouch_driver = {
248 .owner = THIS_MODULE,
249 .name = "itmtouch",
250 .probe = itmtouch_probe,
251 .disconnect = itmtouch_disconnect,
252 .id_table = itmtouch_ids,
253};
254
255static int __init itmtouch_init(void)
256{
257 info(DRIVER_DESC " " DRIVER_VERSION);
258 info(DRIVER_AUTHOR);
259 return usb_register(&itmtouch_driver);
260}
261
262static void __exit itmtouch_exit(void)
263{
264 usb_deregister(&itmtouch_driver);
265}
266
267module_init(itmtouch_init);
268module_exit(itmtouch_exit);
diff --git a/drivers/usb/input/kbtab.c b/drivers/usb/input/kbtab.c
index a68c5b4e7b37..d2f0f90a9bcd 100644
--- a/drivers/usb/input/kbtab.c
+++ b/drivers/usb/input/kbtab.c
@@ -36,7 +36,6 @@ struct kbtab {
36 struct input_dev dev; 36 struct input_dev dev;
37 struct usb_device *usbdev; 37 struct usb_device *usbdev;
38 struct urb *irq; 38 struct urb *irq;
39 int open;
40 int x, y; 39 int x, y;
41 int button; 40 int button;
42 int pressure; 41 int pressure;
@@ -79,12 +78,12 @@ static void kbtab_irq(struct urb *urb, struct pt_regs *regs)
79 /*input_report_key(dev, BTN_TOUCH , data[0] & 0x01);*/ 78 /*input_report_key(dev, BTN_TOUCH , data[0] & 0x01);*/
80 input_report_key(dev, BTN_RIGHT, data[0] & 0x02); 79 input_report_key(dev, BTN_RIGHT, data[0] & 0x02);
81 80
82 if( -1 == kb_pressure_click){ 81 if (-1 == kb_pressure_click) {
83 input_report_abs(dev, ABS_PRESSURE, kbtab->pressure); 82 input_report_abs(dev, ABS_PRESSURE, kbtab->pressure);
84 } else { 83 } else {
85 input_report_key(dev, BTN_LEFT, (kbtab->pressure > kb_pressure_click) ? 1 : 0); 84 input_report_key(dev, BTN_LEFT, (kbtab->pressure > kb_pressure_click) ? 1 : 0);
86 }; 85 };
87 86
88 input_sync(dev); 87 input_sync(dev);
89 88
90 exit: 89 exit:
@@ -105,14 +104,9 @@ static int kbtab_open(struct input_dev *dev)
105{ 104{
106 struct kbtab *kbtab = dev->private; 105 struct kbtab *kbtab = dev->private;
107 106
108 if (kbtab->open++)
109 return 0;
110
111 kbtab->irq->dev = kbtab->usbdev; 107 kbtab->irq->dev = kbtab->usbdev;
112 if (usb_submit_urb(kbtab->irq, GFP_KERNEL)) { 108 if (usb_submit_urb(kbtab->irq, GFP_KERNEL))
113 kbtab->open--;
114 return -EIO; 109 return -EIO;
115 }
116 110
117 return 0; 111 return 0;
118} 112}
@@ -121,8 +115,7 @@ static void kbtab_close(struct input_dev *dev)
121{ 115{
122 struct kbtab *kbtab = dev->private; 116 struct kbtab *kbtab = dev->private;
123 117
124 if (!--kbtab->open) 118 usb_kill_urb(kbtab->irq);
125 usb_kill_urb(kbtab->irq);
126} 119}
127 120
128static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *id) 121static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *id)
@@ -161,7 +154,7 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i
161 kbtab->dev.absmax[ABS_X] = 0x2000; 154 kbtab->dev.absmax[ABS_X] = 0x2000;
162 kbtab->dev.absmax[ABS_Y] = 0x1750; 155 kbtab->dev.absmax[ABS_Y] = 0x1750;
163 kbtab->dev.absmax[ABS_PRESSURE] = 0xff; 156 kbtab->dev.absmax[ABS_PRESSURE] = 0xff;
164 157
165 kbtab->dev.absfuzz[ABS_X] = 4; 158 kbtab->dev.absfuzz[ABS_X] = 4;
166 kbtab->dev.absfuzz[ABS_Y] = 4; 159 kbtab->dev.absfuzz[ABS_Y] = 4;
167 160
diff --git a/drivers/usb/input/mtouchusb.c b/drivers/usb/input/mtouchusb.c
index ab1a2a30ce7c..09b5cc7c66de 100644
--- a/drivers/usb/input/mtouchusb.c
+++ b/drivers/usb/input/mtouchusb.c
@@ -42,9 +42,9 @@
42#include <linux/config.h> 42#include <linux/config.h>
43 43
44#ifdef CONFIG_USB_DEBUG 44#ifdef CONFIG_USB_DEBUG
45 #define DEBUG 45 #define DEBUG
46#else 46#else
47 #undef DEBUG 47 #undef DEBUG
48#endif 48#endif
49 49
50#include <linux/kernel.h> 50#include <linux/kernel.h>
@@ -93,275 +93,255 @@ module_param(raw_coordinates, bool, S_IRUGO | S_IWUSR);
93MODULE_PARM_DESC(raw_coordinates, "report raw coordinate values (y, default) or hardware-calibrated coordinate values (n)"); 93MODULE_PARM_DESC(raw_coordinates, "report raw coordinate values (y, default) or hardware-calibrated coordinate values (n)");
94 94
95struct mtouch_usb { 95struct mtouch_usb {
96 unsigned char *data; 96 unsigned char *data;
97 dma_addr_t data_dma; 97 dma_addr_t data_dma;
98 struct urb *irq; 98 struct urb *irq;
99 struct usb_device *udev; 99 struct usb_device *udev;
100 struct input_dev input; 100 struct input_dev input;
101 int open; 101 char name[128];
102 char name[128]; 102 char phys[64];
103 char phys[64];
104}; 103};
105 104
106static struct usb_device_id mtouchusb_devices [] = { 105static struct usb_device_id mtouchusb_devices[] = {
107 { USB_DEVICE(0x0596, 0x0001) }, 106 { USB_DEVICE(0x0596, 0x0001) },
108 { } 107 { }
109}; 108};
110 109
111static void mtouchusb_irq(struct urb *urb, struct pt_regs *regs) 110static void mtouchusb_irq(struct urb *urb, struct pt_regs *regs)
112{ 111{
113 struct mtouch_usb *mtouch = urb->context; 112 struct mtouch_usb *mtouch = urb->context;
114 int retval; 113 int retval;
115 114
116 switch (urb->status) { 115 switch (urb->status) {
117 case 0: 116 case 0:
118 /* success */ 117 /* success */
119 break; 118 break;
120 case -ETIMEDOUT: 119 case -ETIMEDOUT:
121 /* this urb is timing out */ 120 /* this urb is timing out */
122 dbg("%s - urb timed out - was the device unplugged?", 121 dbg("%s - urb timed out - was the device unplugged?",
123 __FUNCTION__); 122 __FUNCTION__);
124 return; 123 return;
125 case -ECONNRESET: 124 case -ECONNRESET:
126 case -ENOENT: 125 case -ENOENT:
127 case -ESHUTDOWN: 126 case -ESHUTDOWN:
128 /* this urb is terminated, clean up */ 127 /* this urb is terminated, clean up */
129 dbg("%s - urb shutting down with status: %d", 128 dbg("%s - urb shutting down with status: %d",
130 __FUNCTION__, urb->status); 129 __FUNCTION__, urb->status);
131 return; 130 return;
132 default: 131 default:
133 dbg("%s - nonzero urb status received: %d", 132 dbg("%s - nonzero urb status received: %d",
134 __FUNCTION__, urb->status); 133 __FUNCTION__, urb->status);
135 goto exit; 134 goto exit;
136 } 135 }
137 136
138 input_regs(&mtouch->input, regs); 137 input_regs(&mtouch->input, regs);
139 input_report_key(&mtouch->input, BTN_TOUCH, 138 input_report_key(&mtouch->input, BTN_TOUCH,
140 MTOUCHUSB_GET_TOUCHED(mtouch->data)); 139 MTOUCHUSB_GET_TOUCHED(mtouch->data));
141 input_report_abs(&mtouch->input, ABS_X, 140 input_report_abs(&mtouch->input, ABS_X, MTOUCHUSB_GET_XC(mtouch->data));
142 MTOUCHUSB_GET_XC(mtouch->data)); 141 input_report_abs(&mtouch->input, ABS_Y,
143 input_report_abs(&mtouch->input, ABS_Y,
144 (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC) 142 (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC)
145 - MTOUCHUSB_GET_YC(mtouch->data)); 143 - MTOUCHUSB_GET_YC(mtouch->data));
146 input_sync(&mtouch->input); 144 input_sync(&mtouch->input);
147 145
148exit: 146exit:
149 retval = usb_submit_urb (urb, GFP_ATOMIC); 147 retval = usb_submit_urb(urb, GFP_ATOMIC);
150 if (retval) 148 if (retval)
151 err ("%s - usb_submit_urb failed with result: %d", 149 err("%s - usb_submit_urb failed with result: %d",
152 __FUNCTION__, retval); 150 __FUNCTION__, retval);
153} 151}
154 152
155static int mtouchusb_open (struct input_dev *input) 153static int mtouchusb_open(struct input_dev *input)
156{ 154{
157 struct mtouch_usb *mtouch = input->private; 155 struct mtouch_usb *mtouch = input->private;
158 156
159 if (mtouch->open++) 157 mtouch->irq->dev = mtouch->udev;
160 return 0;
161 158
162 mtouch->irq->dev = mtouch->udev; 159 if (usb_submit_urb(mtouch->irq, GFP_ATOMIC))
160 return -EIO;
163 161
164 if (usb_submit_urb (mtouch->irq, GFP_ATOMIC)) { 162 return 0;
165 mtouch->open--;
166 return -EIO;
167 }
168
169 return 0;
170} 163}
171 164
172static void mtouchusb_close (struct input_dev *input) 165static void mtouchusb_close(struct input_dev *input)
173{ 166{
174 struct mtouch_usb *mtouch = input->private; 167 struct mtouch_usb *mtouch = input->private;
175 168
176 if (!--mtouch->open) 169 usb_kill_urb(mtouch->irq);
177 usb_kill_urb (mtouch->irq);
178} 170}
179 171
180static int mtouchusb_alloc_buffers(struct usb_device *udev, struct mtouch_usb *mtouch) 172static int mtouchusb_alloc_buffers(struct usb_device *udev, struct mtouch_usb *mtouch)
181{ 173{
182 dbg("%s - called", __FUNCTION__); 174 dbg("%s - called", __FUNCTION__);
183 175
184 mtouch->data = usb_buffer_alloc(udev, MTOUCHUSB_REPORT_DATA_SIZE, 176 mtouch->data = usb_buffer_alloc(udev, MTOUCHUSB_REPORT_DATA_SIZE,
185 SLAB_ATOMIC, &mtouch->data_dma); 177 SLAB_ATOMIC, &mtouch->data_dma);
186 178
187 if (!mtouch->data) 179 if (!mtouch->data)
188 return -1; 180 return -1;
189 181
190 return 0; 182 return 0;
191} 183}
192 184
193static void mtouchusb_free_buffers(struct usb_device *udev, struct mtouch_usb *mtouch) 185static void mtouchusb_free_buffers(struct usb_device *udev, struct mtouch_usb *mtouch)
194{ 186{
195 dbg("%s - called", __FUNCTION__); 187 dbg("%s - called", __FUNCTION__);
196 188
197 if (mtouch->data) 189 if (mtouch->data)
198 usb_buffer_free(udev, MTOUCHUSB_REPORT_DATA_SIZE, 190 usb_buffer_free(udev, MTOUCHUSB_REPORT_DATA_SIZE,
199 mtouch->data, mtouch->data_dma); 191 mtouch->data, mtouch->data_dma);
200} 192}
201 193
202static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id) 194static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
203{ 195{
204 struct mtouch_usb *mtouch; 196 struct mtouch_usb *mtouch;
205 struct usb_host_interface *interface; 197 struct usb_host_interface *interface;
206 struct usb_endpoint_descriptor *endpoint; 198 struct usb_endpoint_descriptor *endpoint;
207 struct usb_device *udev = interface_to_usbdev (intf); 199 struct usb_device *udev = interface_to_usbdev(intf);
208 char path[64]; 200 char path[64];
209 int nRet; 201 int nRet;
210 202
211 dbg("%s - called", __FUNCTION__); 203 dbg("%s - called", __FUNCTION__);
212 204
213 dbg("%s - setting interface", __FUNCTION__); 205 dbg("%s - setting interface", __FUNCTION__);
214 interface = intf->cur_altsetting; 206 interface = intf->cur_altsetting;
215 207
216 dbg("%s - setting endpoint", __FUNCTION__); 208 dbg("%s - setting endpoint", __FUNCTION__);
217 endpoint = &interface->endpoint[0].desc; 209 endpoint = &interface->endpoint[0].desc;
218 210
219 if (!(mtouch = kmalloc (sizeof (struct mtouch_usb), GFP_KERNEL))) { 211 if (!(mtouch = kmalloc(sizeof(struct mtouch_usb), GFP_KERNEL))) {
220 err("%s - Out of memory.", __FUNCTION__); 212 err("%s - Out of memory.", __FUNCTION__);
221 return -ENOMEM; 213 return -ENOMEM;
222 } 214 }
223 215
224 memset(mtouch, 0, sizeof(struct mtouch_usb)); 216 memset(mtouch, 0, sizeof(struct mtouch_usb));
225 mtouch->udev = udev; 217 mtouch->udev = udev;
226 218
227 dbg("%s - allocating buffers", __FUNCTION__); 219 dbg("%s - allocating buffers", __FUNCTION__);
228 if (mtouchusb_alloc_buffers(udev, mtouch)) { 220 if (mtouchusb_alloc_buffers(udev, mtouch)) {
229 mtouchusb_free_buffers(udev, mtouch); 221 mtouchusb_free_buffers(udev, mtouch);
230 kfree(mtouch); 222 kfree(mtouch);
231 return -ENOMEM; 223 return -ENOMEM;
232 } 224 }
233 225
234 mtouch->input.private = mtouch; 226 mtouch->input.private = mtouch;
235 mtouch->input.open = mtouchusb_open; 227 mtouch->input.open = mtouchusb_open;
236 mtouch->input.close = mtouchusb_close; 228 mtouch->input.close = mtouchusb_close;
237 229
238 usb_make_path(udev, path, 64); 230 usb_make_path(udev, path, 64);
239 sprintf(mtouch->phys, "%s/input0", path); 231 sprintf(mtouch->phys, "%s/input0", path);
240 232
241 mtouch->input.name = mtouch->name; 233 mtouch->input.name = mtouch->name;
242 mtouch->input.phys = mtouch->phys; 234 mtouch->input.phys = mtouch->phys;
243 mtouch->input.id.bustype = BUS_USB; 235 mtouch->input.id.bustype = BUS_USB;
244 mtouch->input.id.vendor = le16_to_cpu(udev->descriptor.idVendor); 236 mtouch->input.id.vendor = le16_to_cpu(udev->descriptor.idVendor);
245 mtouch->input.id.product = le16_to_cpu(udev->descriptor.idProduct); 237 mtouch->input.id.product = le16_to_cpu(udev->descriptor.idProduct);
246 mtouch->input.id.version = le16_to_cpu(udev->descriptor.bcdDevice); 238 mtouch->input.id.version = le16_to_cpu(udev->descriptor.bcdDevice);
247 mtouch->input.dev = &intf->dev; 239 mtouch->input.dev = &intf->dev;
248 240
249 mtouch->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 241 mtouch->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
250 mtouch->input.absbit[0] = BIT(ABS_X) | BIT(ABS_Y); 242 mtouch->input.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
251 mtouch->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 243 mtouch->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
252 244
253 /* Used to Scale Compensated Data and Flip Y */ 245 /* Used to Scale Compensated Data and Flip Y */
254 mtouch->input.absmin[ABS_X] = MTOUCHUSB_MIN_XC; 246 mtouch->input.absmin[ABS_X] = MTOUCHUSB_MIN_XC;
255 mtouch->input.absmax[ABS_X] = raw_coordinates ? \ 247 mtouch->input.absmax[ABS_X] = raw_coordinates ?
256 MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC; 248 MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC;
257 mtouch->input.absfuzz[ABS_X] = MTOUCHUSB_XC_FUZZ; 249 mtouch->input.absfuzz[ABS_X] = MTOUCHUSB_XC_FUZZ;
258 mtouch->input.absflat[ABS_X] = MTOUCHUSB_XC_FLAT; 250 mtouch->input.absflat[ABS_X] = MTOUCHUSB_XC_FLAT;
259 mtouch->input.absmin[ABS_Y] = MTOUCHUSB_MIN_YC; 251 mtouch->input.absmin[ABS_Y] = MTOUCHUSB_MIN_YC;
260 mtouch->input.absmax[ABS_Y] = raw_coordinates ? \ 252 mtouch->input.absmax[ABS_Y] = raw_coordinates ?
261 MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC; 253 MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC;
262 mtouch->input.absfuzz[ABS_Y] = MTOUCHUSB_YC_FUZZ; 254 mtouch->input.absfuzz[ABS_Y] = MTOUCHUSB_YC_FUZZ;
263 mtouch->input.absflat[ABS_Y] = MTOUCHUSB_YC_FLAT; 255 mtouch->input.absflat[ABS_Y] = MTOUCHUSB_YC_FLAT;
264 256
265 if (udev->manufacturer) 257 if (udev->manufacturer)
266 strcat(mtouch->name, udev->manufacturer); 258 strcat(mtouch->name, udev->manufacturer);
267 if (udev->product) 259 if (udev->product)
268 sprintf(mtouch->name, "%s %s", mtouch->name, udev->product); 260 sprintf(mtouch->name, "%s %s", mtouch->name, udev->product);
269 261
270 if (!strlen(mtouch->name)) 262 if (!strlen(mtouch->name))
271 sprintf(mtouch->name, "USB Touchscreen %04x:%04x", 263 sprintf(mtouch->name, "USB Touchscreen %04x:%04x",
272 mtouch->input.id.vendor, mtouch->input.id.product); 264 mtouch->input.id.vendor, mtouch->input.id.product);
273 265
274 nRet = usb_control_msg(mtouch->udev, 266 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0),
275 usb_rcvctrlpipe(udev, 0), 267 MTOUCHUSB_RESET,
276 MTOUCHUSB_RESET, 268 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
277 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 269 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
278 1, 270 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
279 0, 271 __FUNCTION__, nRet);
280 NULL, 272
281 0, 273 dbg("%s - usb_alloc_urb: mtouch->irq", __FUNCTION__);
282 USB_CTRL_SET_TIMEOUT); 274 mtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
283 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d", 275 if (!mtouch->irq) {
284 __FUNCTION__, nRet); 276 dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__);
285 277 mtouchusb_free_buffers(udev, mtouch);
286 dbg("%s - usb_alloc_urb: mtouch->irq", __FUNCTION__); 278 kfree(mtouch);
287 mtouch->irq = usb_alloc_urb(0, GFP_KERNEL); 279 return -ENOMEM;
288 if (!mtouch->irq) { 280 }
289 dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__); 281
290 mtouchusb_free_buffers(udev, mtouch); 282 dbg("%s - usb_fill_int_urb", __FUNCTION__);
291 kfree(mtouch); 283 usb_fill_int_urb(mtouch->irq, mtouch->udev,
292 return -ENOMEM; 284 usb_rcvintpipe(mtouch->udev, 0x81),
293 } 285 mtouch->data, MTOUCHUSB_REPORT_DATA_SIZE,
294 286 mtouchusb_irq, mtouch, endpoint->bInterval);
295 dbg("%s - usb_fill_int_urb", __FUNCTION__); 287
296 usb_fill_int_urb(mtouch->irq, 288 dbg("%s - input_register_device", __FUNCTION__);
297 mtouch->udev, 289 input_register_device(&mtouch->input);
298 usb_rcvintpipe(mtouch->udev, 0x81), 290
299 mtouch->data, 291 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0),
300 MTOUCHUSB_REPORT_DATA_SIZE, 292 MTOUCHUSB_ASYNC_REPORT,
301 mtouchusb_irq, 293 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
302 mtouch, 294 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
303 endpoint->bInterval); 295 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
304 296 __FUNCTION__, nRet);
305 dbg("%s - input_register_device", __FUNCTION__); 297
306 input_register_device(&mtouch->input); 298 printk(KERN_INFO "input: %s on %s\n", mtouch->name, path);
307 299 usb_set_intfdata(intf, mtouch);
308 nRet = usb_control_msg(mtouch->udev, 300
309 usb_rcvctrlpipe(udev, 0), 301 return 0;
310 MTOUCHUSB_ASYNC_REPORT,
311 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
312 1,
313 1,
314 NULL,
315 0,
316 USB_CTRL_SET_TIMEOUT);
317 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
318 __FUNCTION__, nRet);
319
320 printk(KERN_INFO "input: %s on %s\n", mtouch->name, path);
321 usb_set_intfdata(intf, mtouch);
322
323 return 0;
324} 302}
325 303
326static void mtouchusb_disconnect(struct usb_interface *intf) 304static void mtouchusb_disconnect(struct usb_interface *intf)
327{ 305{
328 struct mtouch_usb *mtouch = usb_get_intfdata (intf); 306 struct mtouch_usb *mtouch = usb_get_intfdata(intf);
329 307
330 dbg("%s - called", __FUNCTION__); 308 dbg("%s - called", __FUNCTION__);
331 usb_set_intfdata(intf, NULL); 309 usb_set_intfdata(intf, NULL);
332 if (mtouch) { 310 if (mtouch) {
333 dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__); 311 dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__);
334 usb_kill_urb(mtouch->irq); 312 usb_kill_urb(mtouch->irq);
335 input_unregister_device(&mtouch->input); 313 input_unregister_device(&mtouch->input);
336 usb_free_urb(mtouch->irq); 314 usb_free_urb(mtouch->irq);
337 mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch); 315 mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch);
338 kfree(mtouch); 316 kfree(mtouch);
339 } 317 }
340} 318}
341 319
342MODULE_DEVICE_TABLE (usb, mtouchusb_devices); 320MODULE_DEVICE_TABLE(usb, mtouchusb_devices);
343 321
344static struct usb_driver mtouchusb_driver = { 322static struct usb_driver mtouchusb_driver = {
345 .owner = THIS_MODULE, 323 .owner = THIS_MODULE,
346 .name = "mtouchusb", 324 .name = "mtouchusb",
347 .probe = mtouchusb_probe, 325 .probe = mtouchusb_probe,
348 .disconnect = mtouchusb_disconnect, 326 .disconnect = mtouchusb_disconnect,
349 .id_table = mtouchusb_devices, 327 .id_table = mtouchusb_devices,
350}; 328};
351 329
352static int __init mtouchusb_init(void) { 330static int __init mtouchusb_init(void)
353 dbg("%s - called", __FUNCTION__); 331{
354 return usb_register(&mtouchusb_driver); 332 dbg("%s - called", __FUNCTION__);
333 return usb_register(&mtouchusb_driver);
355} 334}
356 335
357static void __exit mtouchusb_cleanup(void) { 336static void __exit mtouchusb_cleanup(void)
358 dbg("%s - called", __FUNCTION__); 337{
359 usb_deregister(&mtouchusb_driver); 338 dbg("%s - called", __FUNCTION__);
339 usb_deregister(&mtouchusb_driver);
360} 340}
361 341
362module_init(mtouchusb_init); 342module_init(mtouchusb_init);
363module_exit(mtouchusb_cleanup); 343module_exit(mtouchusb_cleanup);
364 344
365MODULE_AUTHOR( DRIVER_AUTHOR ); 345MODULE_AUTHOR(DRIVER_AUTHOR);
366MODULE_DESCRIPTION( DRIVER_DESC ); 346MODULE_DESCRIPTION(DRIVER_DESC);
367MODULE_LICENSE("GPL"); 347MODULE_LICENSE("GPL");
diff --git a/drivers/usb/input/powermate.c b/drivers/usb/input/powermate.c
index 7fa2f9b9fb69..3975b309d55f 100644
--- a/drivers/usb/input/powermate.c
+++ b/drivers/usb/input/powermate.c
@@ -10,7 +10,7 @@
10 * back to the host when polled by the USB controller. 10 * back to the host when polled by the USB controller.
11 * 11 *
12 * Testing with the knob I have has shown that it measures approximately 94 "clicks" 12 * Testing with the knob I have has shown that it measures approximately 94 "clicks"
13 * for one full rotation. Testing with my High Speed Rotation Actuator (ok, it was 13 * for one full rotation. Testing with my High Speed Rotation Actuator (ok, it was
14 * a variable speed cordless electric drill) has shown that the device can measure 14 * a variable speed cordless electric drill) has shown that the device can measure
15 * speeds of up to 7 clicks either clockwise or anticlockwise between pollings from 15 * speeds of up to 7 clicks either clockwise or anticlockwise between pollings from
16 * the host. If it counts more than 7 clicks before it is polled, it will wrap back 16 * the host. If it counts more than 7 clicks before it is polled, it will wrap back
@@ -120,9 +120,9 @@ exit:
120/* Decide if we need to issue a control message and do so. Must be called with pm->lock taken */ 120/* Decide if we need to issue a control message and do so. Must be called with pm->lock taken */
121static void powermate_sync_state(struct powermate_device *pm) 121static void powermate_sync_state(struct powermate_device *pm)
122{ 122{
123 if (pm->requires_update == 0) 123 if (pm->requires_update == 0)
124 return; /* no updates are required */ 124 return; /* no updates are required */
125 if (pm->config->status == -EINPROGRESS) 125 if (pm->config->status == -EINPROGRESS)
126 return; /* an update is already in progress; it'll issue this update when it completes */ 126 return; /* an update is already in progress; it'll issue this update when it completes */
127 127
128 if (pm->requires_update & UPDATE_PULSE_ASLEEP){ 128 if (pm->requires_update & UPDATE_PULSE_ASLEEP){
@@ -142,7 +142,7 @@ static void powermate_sync_state(struct powermate_device *pm)
142 2: multiply the speed 142 2: multiply the speed
143 the argument only has an effect for operations 0 and 2, and ranges between 143 the argument only has an effect for operations 0 and 2, and ranges between
144 1 (least effect) to 255 (maximum effect). 144 1 (least effect) to 255 (maximum effect).
145 145
146 thus, several states are equivalent and are coalesced into one state. 146 thus, several states are equivalent and are coalesced into one state.
147 147
148 we map this onto a range from 0 to 510, with: 148 we map this onto a range from 0 to 510, with:
@@ -151,7 +151,7 @@ static void powermate_sync_state(struct powermate_device *pm)
151 256 -- 510 -- use multiple (510 = fastest). 151 256 -- 510 -- use multiple (510 = fastest).
152 152
153 Only values of 'arg' quite close to 255 are particularly useful/spectacular. 153 Only values of 'arg' quite close to 255 are particularly useful/spectacular.
154 */ 154 */
155 if (pm->pulse_speed < 255){ 155 if (pm->pulse_speed < 255){
156 op = 0; // divide 156 op = 0; // divide
157 arg = 255 - pm->pulse_speed; 157 arg = 255 - pm->pulse_speed;
@@ -199,14 +199,14 @@ static void powermate_config_complete(struct urb *urb, struct pt_regs *regs)
199 199
200 if (urb->status) 200 if (urb->status)
201 printk(KERN_ERR "powermate: config urb returned %d\n", urb->status); 201 printk(KERN_ERR "powermate: config urb returned %d\n", urb->status);
202 202
203 spin_lock_irqsave(&pm->lock, flags); 203 spin_lock_irqsave(&pm->lock, flags);
204 powermate_sync_state(pm); 204 powermate_sync_state(pm);
205 spin_unlock_irqrestore(&pm->lock, flags); 205 spin_unlock_irqrestore(&pm->lock, flags);
206} 206}
207 207
208/* Set the LED up as described and begin the sync with the hardware if required */ 208/* Set the LED up as described and begin the sync with the hardware if required */
209static void powermate_pulse_led(struct powermate_device *pm, int static_brightness, int pulse_speed, 209static void powermate_pulse_led(struct powermate_device *pm, int static_brightness, int pulse_speed,
210 int pulse_table, int pulse_asleep, int pulse_awake) 210 int pulse_table, int pulse_asleep, int pulse_awake)
211{ 211{
212 unsigned long flags; 212 unsigned long flags;
@@ -229,7 +229,7 @@ static void powermate_pulse_led(struct powermate_device *pm, int static_brightne
229 /* mark state updates which are required */ 229 /* mark state updates which are required */
230 if (static_brightness != pm->static_brightness){ 230 if (static_brightness != pm->static_brightness){
231 pm->static_brightness = static_brightness; 231 pm->static_brightness = static_brightness;
232 pm->requires_update |= UPDATE_STATIC_BRIGHTNESS; 232 pm->requires_update |= UPDATE_STATIC_BRIGHTNESS;
233 } 233 }
234 if (pulse_asleep != pm->pulse_asleep){ 234 if (pulse_asleep != pm->pulse_asleep){
235 pm->pulse_asleep = pulse_asleep; 235 pm->pulse_asleep = pulse_asleep;
@@ -246,7 +246,7 @@ static void powermate_pulse_led(struct powermate_device *pm, int static_brightne
246 } 246 }
247 247
248 powermate_sync_state(pm); 248 powermate_sync_state(pm);
249 249
250 spin_unlock_irqrestore(&pm->lock, flags); 250 spin_unlock_irqrestore(&pm->lock, flags);
251} 251}
252 252
@@ -257,19 +257,19 @@ static int powermate_input_event(struct input_dev *dev, unsigned int type, unsig
257 struct powermate_device *pm = dev->private; 257 struct powermate_device *pm = dev->private;
258 258
259 if (type == EV_MSC && code == MSC_PULSELED){ 259 if (type == EV_MSC && code == MSC_PULSELED){
260 /* 260 /*
261 bits 0- 7: 8 bits: LED brightness 261 bits 0- 7: 8 bits: LED brightness
262 bits 8-16: 9 bits: pulsing speed modifier (0 ... 510); 0-254 = slower, 255 = standard, 256-510 = faster. 262 bits 8-16: 9 bits: pulsing speed modifier (0 ... 510); 0-254 = slower, 255 = standard, 256-510 = faster.
263 bits 17-18: 2 bits: pulse table (0, 1, 2 valid) 263 bits 17-18: 2 bits: pulse table (0, 1, 2 valid)
264 bit 19: 1 bit : pulse whilst asleep? 264 bit 19: 1 bit : pulse whilst asleep?
265 bit 20: 1 bit : pulse constantly? 265 bit 20: 1 bit : pulse constantly?
266 */ 266 */
267 int static_brightness = command & 0xFF; // bits 0-7 267 int static_brightness = command & 0xFF; // bits 0-7
268 int pulse_speed = (command >> 8) & 0x1FF; // bits 8-16 268 int pulse_speed = (command >> 8) & 0x1FF; // bits 8-16
269 int pulse_table = (command >> 17) & 0x3; // bits 17-18 269 int pulse_table = (command >> 17) & 0x3; // bits 17-18
270 int pulse_asleep = (command >> 19) & 0x1; // bit 19 270 int pulse_asleep = (command >> 19) & 0x1; // bit 19
271 int pulse_awake = (command >> 20) & 0x1; // bit 20 271 int pulse_awake = (command >> 20) & 0x1; // bit 20
272 272
273 powermate_pulse_led(pm, static_brightness, pulse_speed, pulse_table, pulse_asleep, pulse_awake); 273 powermate_pulse_led(pm, static_brightness, pulse_speed, pulse_table, pulse_asleep, pulse_awake);
274 } 274 }
275 275
@@ -378,7 +378,7 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i
378 switch (le16_to_cpu(udev->descriptor.idProduct)) { 378 switch (le16_to_cpu(udev->descriptor.idProduct)) {
379 case POWERMATE_PRODUCT_NEW: pm->input.name = pm_name_powermate; break; 379 case POWERMATE_PRODUCT_NEW: pm->input.name = pm_name_powermate; break;
380 case POWERMATE_PRODUCT_OLD: pm->input.name = pm_name_soundknob; break; 380 case POWERMATE_PRODUCT_OLD: pm->input.name = pm_name_soundknob; break;
381 default: 381 default:
382 pm->input.name = pm_name_soundknob; 382 pm->input.name = pm_name_soundknob;
383 printk(KERN_WARNING "powermate: unknown product id %04x\n", 383 printk(KERN_WARNING "powermate: unknown product id %04x\n",
384 le16_to_cpu(udev->descriptor.idProduct)); 384 le16_to_cpu(udev->descriptor.idProduct));
@@ -402,11 +402,11 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i
402 usb_make_path(udev, path, 64); 402 usb_make_path(udev, path, 64);
403 snprintf(pm->phys, 64, "%s/input0", path); 403 snprintf(pm->phys, 64, "%s/input0", path);
404 printk(KERN_INFO "input: %s on %s\n", pm->input.name, pm->input.phys); 404 printk(KERN_INFO "input: %s on %s\n", pm->input.name, pm->input.phys);
405 405
406 /* force an update of everything */ 406 /* force an update of everything */
407 pm->requires_update = UPDATE_PULSE_ASLEEP | UPDATE_PULSE_AWAKE | UPDATE_PULSE_MODE | UPDATE_STATIC_BRIGHTNESS; 407 pm->requires_update = UPDATE_PULSE_ASLEEP | UPDATE_PULSE_AWAKE | UPDATE_PULSE_MODE | UPDATE_STATIC_BRIGHTNESS;
408 powermate_pulse_led(pm, 0x80, 255, 0, 1, 0); // set default pulse parameters 408 powermate_pulse_led(pm, 0x80, 255, 0, 1, 0); // set default pulse parameters
409 409
410 usb_set_intfdata(intf, pm); 410 usb_set_intfdata(intf, pm);
411 return 0; 411 return 0;
412} 412}
diff --git a/drivers/usb/input/touchkitusb.c b/drivers/usb/input/touchkitusb.c
index a71f1bbd0a17..386595ee21c0 100644
--- a/drivers/usb/input/touchkitusb.c
+++ b/drivers/usb/input/touchkitusb.c
@@ -69,7 +69,6 @@ struct touchkit_usb {
69 struct urb *irq; 69 struct urb *irq;
70 struct usb_device *udev; 70 struct usb_device *udev;
71 struct input_dev input; 71 struct input_dev input;
72 int open;
73 char name[128]; 72 char name[128];
74 char phys[64]; 73 char phys[64];
75}; 74};
@@ -134,15 +133,10 @@ static int touchkit_open(struct input_dev *input)
134{ 133{
135 struct touchkit_usb *touchkit = input->private; 134 struct touchkit_usb *touchkit = input->private;
136 135
137 if (touchkit->open++)
138 return 0;
139
140 touchkit->irq->dev = touchkit->udev; 136 touchkit->irq->dev = touchkit->udev;
141 137
142 if (usb_submit_urb(touchkit->irq, GFP_ATOMIC)) { 138 if (usb_submit_urb(touchkit->irq, GFP_ATOMIC))
143 touchkit->open--;
144 return -EIO; 139 return -EIO;
145 }
146 140
147 return 0; 141 return 0;
148} 142}
@@ -151,8 +145,7 @@ static void touchkit_close(struct input_dev *input)
151{ 145{
152 struct touchkit_usb *touchkit = input->private; 146 struct touchkit_usb *touchkit = input->private;
153 147
154 if (!--touchkit->open) 148 usb_kill_urb(touchkit->irq);
155 usb_kill_urb(touchkit->irq);
156} 149}
157 150
158static int touchkit_alloc_buffers(struct usb_device *udev, 151static int touchkit_alloc_buffers(struct usb_device *udev,
diff --git a/drivers/usb/input/usbkbd.c b/drivers/usb/input/usbkbd.c
index 7038fb9d1ced..f35db1974c42 100644
--- a/drivers/usb/input/usbkbd.c
+++ b/drivers/usb/input/usbkbd.c
@@ -9,18 +9,18 @@
9/* 9/*
10 * This program is free software; you can redistribute it and/or modify 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 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 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 * 14 *
15 * This program is distributed in the hope that it will be useful, 15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details. 18 * GNU General Public License for more details.
19 * 19 *
20 * You should have received a copy of the GNU General Public License 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 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * 23 *
24 * Should you need to contact me, the author, you can do so either by 24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: 25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
@@ -72,7 +72,6 @@ struct usb_kbd {
72 unsigned char newleds; 72 unsigned char newleds;
73 char name[128]; 73 char name[128];
74 char phys[64]; 74 char phys[64];
75 int open;
76 75
77 unsigned char *new; 76 unsigned char *new;
78 struct usb_ctrlrequest *cr; 77 struct usb_ctrlrequest *cr;
@@ -166,7 +165,7 @@ static void usb_kbd_led(struct urb *urb, struct pt_regs *regs)
166 165
167 if (urb->status) 166 if (urb->status)
168 warn("led urb status %d received", urb->status); 167 warn("led urb status %d received", urb->status);
169 168
170 if (*(kbd->leds) == kbd->newleds) 169 if (*(kbd->leds) == kbd->newleds)
171 return; 170 return;
172 171
@@ -180,14 +179,9 @@ static int usb_kbd_open(struct input_dev *dev)
180{ 179{
181 struct usb_kbd *kbd = dev->private; 180 struct usb_kbd *kbd = dev->private;
182 181
183 if (kbd->open++)
184 return 0;
185
186 kbd->irq->dev = kbd->usbdev; 182 kbd->irq->dev = kbd->usbdev;
187 if (usb_submit_urb(kbd->irq, GFP_KERNEL)) { 183 if (usb_submit_urb(kbd->irq, GFP_KERNEL))
188 kbd->open--;
189 return -EIO; 184 return -EIO;
190 }
191 185
192 return 0; 186 return 0;
193} 187}
@@ -196,8 +190,7 @@ static void usb_kbd_close(struct input_dev *dev)
196{ 190{
197 struct usb_kbd *kbd = dev->private; 191 struct usb_kbd *kbd = dev->private;
198 192
199 if (!--kbd->open) 193 usb_kill_urb(kbd->irq);
200 usb_kill_urb(kbd->irq);
201} 194}
202 195
203static int usb_kbd_alloc_mem(struct usb_device *dev, struct usb_kbd *kbd) 196static int usb_kbd_alloc_mem(struct usb_device *dev, struct usb_kbd *kbd)
@@ -230,7 +223,7 @@ static void usb_kbd_free_mem(struct usb_device *dev, struct usb_kbd *kbd)
230 usb_buffer_free(dev, 1, kbd->leds, kbd->leds_dma); 223 usb_buffer_free(dev, 1, kbd->leds, kbd->leds_dma);
231} 224}
232 225
233static int usb_kbd_probe(struct usb_interface *iface, 226static int usb_kbd_probe(struct usb_interface *iface,
234 const struct usb_device_id *id) 227 const struct usb_device_id *id)
235{ 228{
236 struct usb_device * dev = interface_to_usbdev(iface); 229 struct usb_device * dev = interface_to_usbdev(iface);
@@ -272,7 +265,7 @@ static int usb_kbd_probe(struct usb_interface *iface,
272 for (i = 0; i < 255; i++) 265 for (i = 0; i < 255; i++)
273 set_bit(usb_kbd_keycode[i], kbd->dev.keybit); 266 set_bit(usb_kbd_keycode[i], kbd->dev.keybit);
274 clear_bit(0, kbd->dev.keybit); 267 clear_bit(0, kbd->dev.keybit);
275 268
276 kbd->dev.private = kbd; 269 kbd->dev.private = kbd;
277 kbd->dev.event = usb_kbd_event; 270 kbd->dev.event = usb_kbd_event;
278 kbd->dev.open = usb_kbd_open; 271 kbd->dev.open = usb_kbd_open;
@@ -294,7 +287,7 @@ static int usb_kbd_probe(struct usb_interface *iface,
294 sprintf(kbd->phys, "%s/input0", path); 287 sprintf(kbd->phys, "%s/input0", path);
295 288
296 kbd->dev.name = kbd->name; 289 kbd->dev.name = kbd->name;
297 kbd->dev.phys = kbd->phys; 290 kbd->dev.phys = kbd->phys;
298 kbd->dev.id.bustype = BUS_USB; 291 kbd->dev.id.bustype = BUS_USB;
299 kbd->dev.id.vendor = le16_to_cpu(dev->descriptor.idVendor); 292 kbd->dev.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
300 kbd->dev.id.product = le16_to_cpu(dev->descriptor.idProduct); 293 kbd->dev.id.product = le16_to_cpu(dev->descriptor.idProduct);
@@ -329,7 +322,7 @@ static int usb_kbd_probe(struct usb_interface *iface,
329static void usb_kbd_disconnect(struct usb_interface *intf) 322static void usb_kbd_disconnect(struct usb_interface *intf)
330{ 323{
331 struct usb_kbd *kbd = usb_get_intfdata (intf); 324 struct usb_kbd *kbd = usb_get_intfdata (intf);
332 325
333 usb_set_intfdata(intf, NULL); 326 usb_set_intfdata(intf, NULL);
334 if (kbd) { 327 if (kbd) {
335 usb_kill_urb(kbd->irq); 328 usb_kill_urb(kbd->irq);
diff --git a/drivers/usb/input/usbmouse.c b/drivers/usb/input/usbmouse.c
index 01155bbddd43..1ec41b5effe6 100644
--- a/drivers/usb/input/usbmouse.c
+++ b/drivers/usb/input/usbmouse.c
@@ -9,18 +9,18 @@
9/* 9/*
10 * This program is free software; you can redistribute it and/or modify 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 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 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 * 14 *
15 * This program is distributed in the hope that it will be useful, 15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details. 18 * GNU General Public License for more details.
19 * 19 *
20 * You should have received a copy of the GNU General Public License 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 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * 23 *
24 * Should you need to contact me, the author, you can do so either by 24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: 25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
@@ -51,7 +51,6 @@ struct usb_mouse {
51 struct usb_device *usbdev; 51 struct usb_device *usbdev;
52 struct input_dev dev; 52 struct input_dev dev;
53 struct urb *irq; 53 struct urb *irq;
54 int open;
55 54
56 signed char *data; 55 signed char *data;
57 dma_addr_t data_dma; 56 dma_addr_t data_dma;
@@ -101,14 +100,9 @@ static int usb_mouse_open(struct input_dev *dev)
101{ 100{
102 struct usb_mouse *mouse = dev->private; 101 struct usb_mouse *mouse = dev->private;
103 102
104 if (mouse->open++)
105 return 0;
106
107 mouse->irq->dev = mouse->usbdev; 103 mouse->irq->dev = mouse->usbdev;
108 if (usb_submit_urb(mouse->irq, GFP_KERNEL)) { 104 if (usb_submit_urb(mouse->irq, GFP_KERNEL))
109 mouse->open--;
110 return -EIO; 105 return -EIO;
111 }
112 106
113 return 0; 107 return 0;
114} 108}
@@ -117,8 +111,7 @@ static void usb_mouse_close(struct input_dev *dev)
117{ 111{
118 struct usb_mouse *mouse = dev->private; 112 struct usb_mouse *mouse = dev->private;
119 113
120 if (!--mouse->open) 114 usb_kill_urb(mouse->irq);
121 usb_kill_urb(mouse->irq);
122} 115}
123 116
124static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_id * id) 117static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_id * id)
@@ -132,19 +125,19 @@ static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_
132 125
133 interface = intf->cur_altsetting; 126 interface = intf->cur_altsetting;
134 127
135 if (interface->desc.bNumEndpoints != 1) 128 if (interface->desc.bNumEndpoints != 1)
136 return -ENODEV; 129 return -ENODEV;
137 130
138 endpoint = &interface->endpoint[0].desc; 131 endpoint = &interface->endpoint[0].desc;
139 if (!(endpoint->bEndpointAddress & 0x80)) 132 if (!(endpoint->bEndpointAddress & 0x80))
140 return -ENODEV; 133 return -ENODEV;
141 if ((endpoint->bmAttributes & 3) != 3) 134 if ((endpoint->bmAttributes & 3) != 3)
142 return -ENODEV; 135 return -ENODEV;
143 136
144 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); 137 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
145 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); 138 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
146 139
147 if (!(mouse = kmalloc(sizeof(struct usb_mouse), GFP_KERNEL))) 140 if (!(mouse = kmalloc(sizeof(struct usb_mouse), GFP_KERNEL)))
148 return -ENOMEM; 141 return -ENOMEM;
149 memset(mouse, 0, sizeof(struct usb_mouse)); 142 memset(mouse, 0, sizeof(struct usb_mouse));
150 143
@@ -209,7 +202,7 @@ static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_
209static void usb_mouse_disconnect(struct usb_interface *intf) 202static void usb_mouse_disconnect(struct usb_interface *intf)
210{ 203{
211 struct usb_mouse *mouse = usb_get_intfdata (intf); 204 struct usb_mouse *mouse = usb_get_intfdata (intf);
212 205
213 usb_set_intfdata(intf, NULL); 206 usb_set_intfdata(intf, NULL);
214 if (mouse) { 207 if (mouse) {
215 usb_kill_urb(mouse->irq); 208 usb_kill_urb(mouse->irq);
@@ -238,7 +231,7 @@ static struct usb_driver usb_mouse_driver = {
238static int __init usb_mouse_init(void) 231static int __init usb_mouse_init(void)
239{ 232{
240 int retval = usb_register(&usb_mouse_driver); 233 int retval = usb_register(&usb_mouse_driver);
241 if (retval == 0) 234 if (retval == 0)
242 info(DRIVER_VERSION ":" DRIVER_DESC); 235 info(DRIVER_VERSION ":" DRIVER_DESC);
243 return retval; 236 return retval;
244} 237}
diff --git a/drivers/usb/input/wacom.c b/drivers/usb/input/wacom.c
index fec04dda088e..f6b34af66b3d 100644
--- a/drivers/usb/input/wacom.c
+++ b/drivers/usb/input/wacom.c
@@ -9,7 +9,7 @@
9 * Copyright (c) 2000 Daniel Egger <egger@suse.de> 9 * Copyright (c) 2000 Daniel Egger <egger@suse.de>
10 * Copyright (c) 2001 Frederic Lepied <flepied@mandrakesoft.com> 10 * Copyright (c) 2001 Frederic Lepied <flepied@mandrakesoft.com>
11 * Copyright (c) 2004 Panagiotis Issaris <panagiotis.issaris@mech.kuleuven.ac.be> 11 * Copyright (c) 2004 Panagiotis Issaris <panagiotis.issaris@mech.kuleuven.ac.be>
12 * Copyright (c) 2002-2004 Ping Cheng <pingc@wacom.com> 12 * Copyright (c) 2002-2005 Ping Cheng <pingc@wacom.com>
13 * 13 *
14 * ChangeLog: 14 * ChangeLog:
15 * v0.1 (vp) - Initial release 15 * v0.1 (vp) - Initial release
@@ -18,7 +18,7 @@
18 * v0.4 (sm) - Support for more Intuos models, menustrip 18 * v0.4 (sm) - Support for more Intuos models, menustrip
19 * relative mode, proximity. 19 * relative mode, proximity.
20 * v0.5 (vp) - Big cleanup, nifty features removed, 20 * v0.5 (vp) - Big cleanup, nifty features removed,
21 * they belong in userspace 21 * they belong in userspace
22 * v1.8 (vp) - Submit URB only when operating, moved to CVS, 22 * v1.8 (vp) - Submit URB only when operating, moved to CVS,
23 * use input_report_key instead of report_btn and 23 * use input_report_key instead of report_btn and
24 * other cleanups 24 * other cleanups
@@ -51,6 +51,9 @@
51 * - Cleanups here and there 51 * - Cleanups here and there
52 * v1.30.1 (pi) - Added Graphire3 support 52 * v1.30.1 (pi) - Added Graphire3 support
53 * v1.40 (pc) - Add support for several new devices, fix eraser reporting, ... 53 * v1.40 (pc) - Add support for several new devices, fix eraser reporting, ...
54 * v1.43 (pc) - Added support for Cintiq 21UX
55 - Fixed a Graphire bug
56 - Merged wacom_intuos3_irq into wacom_intuos_irq
54 */ 57 */
55 58
56/* 59/*
@@ -72,7 +75,7 @@
72/* 75/*
73 * Version Information 76 * Version Information
74 */ 77 */
75#define DRIVER_VERSION "v1.40" 78#define DRIVER_VERSION "v1.43"
76#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>" 79#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
77#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver" 80#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver"
78#define DRIVER_LICENSE "GPL" 81#define DRIVER_LICENSE "GPL"
@@ -83,6 +86,16 @@ MODULE_LICENSE(DRIVER_LICENSE);
83 86
84#define USB_VENDOR_ID_WACOM 0x056a 87#define USB_VENDOR_ID_WACOM 0x056a
85 88
89enum {
90 PENPARTNER = 0,
91 GRAPHIRE,
92 PL,
93 INTUOS,
94 INTUOS3,
95 CINTIQ,
96 MAX_TYPE
97};
98
86struct wacom_features { 99struct wacom_features {
87 char *name; 100 char *name;
88 int pktlen; 101 int pktlen;
@@ -102,7 +115,6 @@ struct wacom {
102 struct urb *irq; 115 struct urb *irq;
103 struct wacom_features *features; 116 struct wacom_features *features;
104 int tool[2]; 117 int tool[2];
105 int open;
106 __u32 serial[2]; 118 __u32 serial[2];
107 char phys[32]; 119 char phys[32];
108}; 120};
@@ -149,7 +161,7 @@ static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
149 prox = data[1] & 0x40; 161 prox = data[1] & 0x40;
150 162
151 input_regs(dev, regs); 163 input_regs(dev, regs);
152 164
153 if (prox) { 165 if (prox) {
154 166
155 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1)); 167 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
@@ -166,8 +178,7 @@ static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
166 if (!wacom->tool[0]) { 178 if (!wacom->tool[0]) {
167 /* Going into proximity select tool */ 179 /* Going into proximity select tool */
168 wacom->tool[1] = (data[4] & 0x20)? BTN_TOOL_RUBBER : BTN_TOOL_PEN; 180 wacom->tool[1] = (data[4] & 0x20)? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
169 } 181 } else {
170 else {
171 /* was entered with stylus2 pressed */ 182 /* was entered with stylus2 pressed */
172 if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20) ) { 183 if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20) ) {
173 /* report out proximity for previous tool */ 184 /* report out proximity for previous tool */
@@ -182,16 +193,15 @@ static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
182 wacom->tool[1] = BTN_TOOL_PEN; 193 wacom->tool[1] = BTN_TOOL_PEN;
183 } 194 }
184 input_report_key(dev, wacom->tool[1], prox); /* report in proximity for tool */ 195 input_report_key(dev, wacom->tool[1], prox); /* report in proximity for tool */
185 input_report_abs(dev, ABS_X, data[3] | ((__u32)data[2] << 7) | ((__u32)(data[1] & 0x03) << 14)); 196 input_report_abs(dev, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
186 input_report_abs(dev, ABS_Y, data[6] | ((__u32)data[5] << 7) | ((__u32)(data[4] & 0x03) << 14)); 197 input_report_abs(dev, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
187 input_report_abs(dev, ABS_PRESSURE, pressure); 198 input_report_abs(dev, ABS_PRESSURE, pressure);
188 199
189 input_report_key(dev, BTN_TOUCH, data[4] & 0x08); 200 input_report_key(dev, BTN_TOUCH, data[4] & 0x08);
190 input_report_key(dev, BTN_STYLUS, data[4] & 0x10); 201 input_report_key(dev, BTN_STYLUS, data[4] & 0x10);
191 /* Only allow the stylus2 button to be reported for the pen tool. */ 202 /* Only allow the stylus2 button to be reported for the pen tool. */
192 input_report_key(dev, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20)); 203 input_report_key(dev, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
193 } 204 } else {
194 else {
195 /* report proximity-out of a (valid) tool */ 205 /* report proximity-out of a (valid) tool */
196 if (wacom->tool[1] != BTN_TOOL_RUBBER) { 206 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
197 /* Unknown tool selected default to pen tool */ 207 /* Unknown tool selected default to pen tool */
@@ -203,7 +213,7 @@ static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
203 wacom->tool[0] = prox; /* Save proximity state */ 213 wacom->tool[0] = prox; /* Save proximity state */
204 input_sync(dev); 214 input_sync(dev);
205 215
206exit: 216 exit:
207 retval = usb_submit_urb (urb, GFP_ATOMIC); 217 retval = usb_submit_urb (urb, GFP_ATOMIC);
208 if (retval) 218 if (retval)
209 err ("%s - usb_submit_urb failed with result %d", 219 err ("%s - usb_submit_urb failed with result %d",
@@ -232,20 +242,16 @@ static void wacom_ptu_irq(struct urb *urb, struct pt_regs *regs)
232 goto exit; 242 goto exit;
233 } 243 }
234 244
235 if (data[0] != 2) 245 if (data[0] != 2) {
236 {
237 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]); 246 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
238 goto exit; 247 goto exit;
239 } 248 }
240 249
241 input_regs(dev, regs); 250 input_regs(dev, regs);
242 if (data[1] & 0x04) 251 if (data[1] & 0x04) {
243 {
244 input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x20); 252 input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x20);
245 input_report_key(dev, BTN_TOUCH, data[1] & 0x08); 253 input_report_key(dev, BTN_TOUCH, data[1] & 0x08);
246 } 254 } else {
247 else
248 {
249 input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x20); 255 input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x20);
250 input_report_key(dev, BTN_TOUCH, data[1] & 0x01); 256 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
251 } 257 }
@@ -257,7 +263,7 @@ static void wacom_ptu_irq(struct urb *urb, struct pt_regs *regs)
257 263
258 input_sync(dev); 264 input_sync(dev);
259 265
260exit: 266 exit:
261 retval = usb_submit_urb (urb, GFP_ATOMIC); 267 retval = usb_submit_urb (urb, GFP_ATOMIC);
262 if (retval) 268 if (retval)
263 err ("%s - usb_submit_urb failed with result %d", 269 err ("%s - usb_submit_urb failed with result %d",
@@ -300,7 +306,7 @@ static void wacom_penpartner_irq(struct urb *urb, struct pt_regs *regs)
300 input_report_key(dev, BTN_STYLUS, (data[5] & 0x40)); 306 input_report_key(dev, BTN_STYLUS, (data[5] & 0x40));
301 input_sync(dev); 307 input_sync(dev);
302 308
303exit: 309 exit:
304 retval = usb_submit_urb (urb, GFP_ATOMIC); 310 retval = usb_submit_urb (urb, GFP_ATOMIC);
305 if (retval) 311 if (retval)
306 err ("%s - usb_submit_urb failed with result %d", 312 err ("%s - usb_submit_urb failed with result %d",
@@ -340,47 +346,47 @@ static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
340 346
341 input_regs(dev, regs); 347 input_regs(dev, regs);
342 348
343 switch ((data[1] >> 5) & 3) { 349 if (data[1] & 0x10) { /* in prox */
344 350
345 case 0: /* Pen */ 351 switch ((data[1] >> 5) & 3) {
346 input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x80);
347 break;
348 352
349 case 1: /* Rubber */ 353 case 0: /* Pen */
350 input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x80); 354 wacom->tool[0] = BTN_TOOL_PEN;
351 break; 355 break;
352
353 case 2: /* Mouse with wheel */
354 input_report_key(dev, BTN_MIDDLE, data[1] & 0x04);
355 input_report_rel(dev, REL_WHEEL, (signed char) data[6]);
356 /* fall through */
357 356
358 case 3: /* Mouse without wheel */ 357 case 1: /* Rubber */
359 input_report_key(dev, BTN_TOOL_MOUSE, data[7] > 24); 358 wacom->tool[0] = BTN_TOOL_RUBBER;
360 input_report_key(dev, BTN_LEFT, data[1] & 0x01); 359 break;
361 input_report_key(dev, BTN_RIGHT, data[1] & 0x02);
362 input_report_abs(dev, ABS_DISTANCE, data[7]);
363 360
364 input_report_abs(dev, ABS_X, x); 361 case 2: /* Mouse with wheel */
365 input_report_abs(dev, ABS_Y, y); 362 input_report_key(dev, BTN_MIDDLE, data[1] & 0x04);
363 input_report_rel(dev, REL_WHEEL, (signed char) data[6]);
364 /* fall through */
366 365
367 input_sync(dev); 366 case 3: /* Mouse without wheel */
368 goto exit; 367 wacom->tool[0] = BTN_TOOL_MOUSE;
368 input_report_key(dev, BTN_LEFT, data[1] & 0x01);
369 input_report_key(dev, BTN_RIGHT, data[1] & 0x02);
370 input_report_abs(dev, ABS_DISTANCE, data[7]);
371 break;
372 }
369 } 373 }
370 374
371 if (data[1] & 0x80) { 375 if (data[1] & 0x80) {
372 input_report_abs(dev, ABS_X, x); 376 input_report_abs(dev, ABS_X, x);
373 input_report_abs(dev, ABS_Y, y); 377 input_report_abs(dev, ABS_Y, y);
374 } 378 }
379 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
380 input_report_abs(dev, ABS_PRESSURE, le16_to_cpu(*(__le16 *) &data[6]));
381 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
382 input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
383 input_report_key(dev, BTN_STYLUS2, data[1] & 0x04);
384 }
375 385
376 input_report_abs(dev, ABS_PRESSURE, le16_to_cpu(*(__le16 *) &data[6])); 386 input_report_key(dev, wacom->tool[0], data[1] & 0x10);
377 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
378 input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
379 input_report_key(dev, BTN_STYLUS2, data[1] & 0x04);
380
381 input_sync(dev); 387 input_sync(dev);
382 388
383exit: 389 exit:
384 retval = usb_submit_urb (urb, GFP_ATOMIC); 390 retval = usb_submit_urb (urb, GFP_ATOMIC);
385 if (retval) 391 if (retval)
386 err ("%s - usb_submit_urb failed with result %d", 392 err ("%s - usb_submit_urb failed with result %d",
@@ -398,14 +404,13 @@ static int wacom_intuos_inout(struct urb *urb)
398 idx = data[1] & 0x01; 404 idx = data[1] & 0x01;
399 405
400 /* Enter report */ 406 /* Enter report */
401 if ((data[1] & 0xfc) == 0xc0) 407 if ((data[1] & 0xfc) == 0xc0) {
402 {
403 /* serial number of the tool */ 408 /* serial number of the tool */
404 wacom->serial[idx] = ((__u32)(data[3] & 0x0f) << 28) + 409 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
405 ((__u32)data[4] << 20) + ((__u32)data[5] << 12) + 410 (data[4] << 20) + (data[5] << 12) +
406 ((__u32)data[6] << 4) + (data[7] >> 4); 411 (data[6] << 4) + (data[7] >> 4);
407 412
408 switch (((__u32)data[2] << 4) | (data[3] >> 4)) { 413 switch ((data[2] << 4) | (data[3] >> 4)) {
409 case 0x812: /* Inking pen */ 414 case 0x812: /* Inking pen */
410 case 0x801: /* Intuos3 Inking pen */ 415 case 0x801: /* Intuos3 Inking pen */
411 case 0x012: 416 case 0x012:
@@ -449,7 +454,7 @@ static int wacom_intuos_inout(struct urb *urb)
449 case 0x112: 454 case 0x112:
450 case 0x913: /* Intuos3 Airbrush */ 455 case 0x913: /* Intuos3 Airbrush */
451 wacom->tool[idx] = BTN_TOOL_AIRBRUSH; 456 wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
452 break; /* Airbrush */ 457 break;
453 default: /* Unknown tool */ 458 default: /* Unknown tool */
454 wacom->tool[idx] = BTN_TOOL_PEN; 459 wacom->tool[idx] = BTN_TOOL_PEN;
455 } 460 }
@@ -478,9 +483,8 @@ static void wacom_intuos_general(struct urb *urb)
478 unsigned int t; 483 unsigned int t;
479 484
480 /* general pen packet */ 485 /* general pen packet */
481 if ((data[1] & 0xb8) == 0xa0) 486 if ((data[1] & 0xb8) == 0xa0) {
482 { 487 t = (data[6] << 2) | ((data[7] >> 6) & 3);
483 t = ((__u32)data[6] << 2) | ((data[7] >> 6) & 3);
484 input_report_abs(dev, ABS_PRESSURE, t); 488 input_report_abs(dev, ABS_PRESSURE, t);
485 input_report_abs(dev, ABS_TILT_X, 489 input_report_abs(dev, ABS_TILT_X,
486 ((data[7] << 1) & 0x7e) | (data[8] >> 7)); 490 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
@@ -491,10 +495,9 @@ static void wacom_intuos_general(struct urb *urb)
491 } 495 }
492 496
493 /* airbrush second packet */ 497 /* airbrush second packet */
494 if ((data[1] & 0xbc) == 0xb4) 498 if ((data[1] & 0xbc) == 0xb4) {
495 {
496 input_report_abs(dev, ABS_WHEEL, 499 input_report_abs(dev, ABS_WHEEL,
497 ((__u32)data[6] << 2) | ((data[7] >> 6) & 3)); 500 (data[6] << 2) | ((data[7] >> 6) & 3));
498 input_report_abs(dev, ABS_TILT_X, 501 input_report_abs(dev, ABS_TILT_X,
499 ((data[7] << 1) & 0x7e) | (data[8] >> 7)); 502 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
500 input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f); 503 input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
@@ -526,7 +529,7 @@ static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
526 goto exit; 529 goto exit;
527 } 530 }
528 531
529 if (data[0] != 2 && data[0] != 5 && data[0] != 6) { 532 if (data[0] != 2 && data[0] != 5 && data[0] != 6 && data[0] != 12) {
530 dbg("wacom_intuos_irq: received unknown report #%d", data[0]); 533 dbg("wacom_intuos_irq: received unknown report #%d", data[0]);
531 goto exit; 534 goto exit;
532 } 535 }
@@ -536,107 +539,10 @@ static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
536 /* tool number */ 539 /* tool number */
537 idx = data[1] & 0x01; 540 idx = data[1] & 0x01;
538 541
539 /* process in/out prox events */
540 if (wacom_intuos_inout(urb)) goto exit;
541
542 input_report_abs(dev, ABS_X, be16_to_cpu(*(__be16 *) &data[2]));
543 input_report_abs(dev, ABS_Y, be16_to_cpu(*(__be16 *) &data[4]));
544 input_report_abs(dev, ABS_DISTANCE, data[9]);
545
546 /* process general packets */
547 wacom_intuos_general(urb);
548
549 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) { /* 4D mouse or Lens cursor packets */
550
551 if (data[1] & 0x02) { /* Rotation packet */
552
553 t = ((__u32)data[6] << 3) | ((data[7] >> 5) & 7);
554 input_report_abs(dev, ABS_RZ, (data[7] & 0x20) ? ((t - 1) / 2) : -t / 2);
555
556 } else {
557
558 if ((data[1] & 0x10) == 0) { /* 4D mouse packets */
559
560 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
561 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
562 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
563
564 input_report_key(dev, BTN_SIDE, data[8] & 0x20);
565 input_report_key(dev, BTN_EXTRA, data[8] & 0x10);
566 t = ((__u32)data[6] << 2) | ((data[7] >> 6) & 3);
567 input_report_abs(dev, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
568
569 } else {
570 if (wacom->tool[idx] == BTN_TOOL_MOUSE) { /* 2D mouse packets */
571 input_report_key(dev, BTN_LEFT, data[8] & 0x04);
572 input_report_key(dev, BTN_MIDDLE, data[8] & 0x08);
573 input_report_key(dev, BTN_RIGHT, data[8] & 0x10);
574 input_report_rel(dev, REL_WHEEL,
575 (-(__u32)(data[8] & 0x01) + (__u32)((data[8] & 0x02) >> 1)));
576 }
577 else { /* Lens cursor packets */
578 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
579 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
580 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
581 input_report_key(dev, BTN_SIDE, data[8] & 0x10);
582 input_report_key(dev, BTN_EXTRA, data[8] & 0x08);
583 }
584 }
585 }
586 }
587
588 input_report_key(dev, wacom->tool[idx], 1);
589 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
590 input_sync(dev);
591
592exit:
593 retval = usb_submit_urb (urb, GFP_ATOMIC);
594 if (retval)
595 err ("%s - usb_submit_urb failed with result %d",
596 __FUNCTION__, retval);
597}
598
599static void wacom_intuos3_irq(struct urb *urb, struct pt_regs *regs)
600{
601 struct wacom *wacom = urb->context;
602 unsigned char *data = wacom->data;
603 struct input_dev *dev = &wacom->dev;
604 unsigned int t;
605 int idx, retval;
606
607 switch (urb->status) {
608 case 0:
609 /* success */
610 break;
611 case -ECONNRESET:
612 case -ENOENT:
613 case -ESHUTDOWN:
614 /* this urb is terminated, clean up */
615 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
616 return;
617 default:
618 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
619 goto exit;
620 }
621
622 /* check for valid report */
623 if (data[0] != 2 && data[0] != 5 && data[0] != 12)
624 {
625 printk(KERN_INFO "wacom_intuos3_irq: received unknown report #%d\n", data[0]);
626 goto exit;
627 }
628
629 input_regs(dev, regs);
630
631 /* tool index is always 0 here since there is no dual input tool */
632 idx = data[1] & 0x01;
633
634 /* pad packets. Works as a second tool and is always in prox */ 542 /* pad packets. Works as a second tool and is always in prox */
635 if (data[0] == 12) 543 if (data[0] == 12) {
636 {
637 /* initiate the pad as a device */ 544 /* initiate the pad as a device */
638 if (wacom->tool[1] != BTN_TOOL_FINGER) 545 if (wacom->tool[1] != BTN_TOOL_FINGER) {
639 {
640 wacom->tool[1] = BTN_TOOL_FINGER; 546 wacom->tool[1] = BTN_TOOL_FINGER;
641 input_report_key(dev, wacom->tool[1], 1); 547 input_report_key(dev, wacom->tool[1], 1);
642 } 548 }
@@ -656,37 +562,78 @@ static void wacom_intuos3_irq(struct urb *urb, struct pt_regs *regs)
656 } 562 }
657 563
658 /* process in/out prox events */ 564 /* process in/out prox events */
659 if (wacom_intuos_inout(urb)) goto exit; 565 if (wacom_intuos_inout(urb))
566 goto exit;
660 567
661 input_report_abs(dev, ABS_X, ((__u32)data[2] << 9) | ((__u32)data[3] << 1) | ((data[9] >> 1) & 1)); 568 /* Cintiq doesn't send data when RDY bit isn't set */
662 input_report_abs(dev, ABS_Y, ((__u32)data[4] << 9) | ((__u32)data[5] << 1) | (data[9] & 1)); 569 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
663 input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 2) & 0x3f)); 570 return;
571
572 if (wacom->features->type >= INTUOS3) {
573 input_report_abs(dev, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
574 input_report_abs(dev, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
575 input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
576 } else {
577 input_report_abs(dev, ABS_X, be16_to_cpu(*(__be16 *) &data[2]));
578 input_report_abs(dev, ABS_Y, be16_to_cpu(*(__be16 *) &data[4]));
579 input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
580 }
664 581
665 /* process general packets */ 582 /* process general packets */
666 wacom_intuos_general(urb); 583 wacom_intuos_general(urb);
667 584
668 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) 585 /* 4D mouse, 2D mouse, marker pen rotation, or Lens cursor packets */
669 { 586 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) {
670 /* Marker pen rotation packet. Reported as wheel due to valuator limitation */ 587
671 if (data[1] & 0x02) 588 if (data[1] & 0x02) {
672 { 589 /* Rotation packet */
673 t = ((__u32)data[6] << 3) | ((data[7] >> 5) & 7); 590 if (wacom->features->type >= INTUOS3) {
674 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) : 591 /* I3 marker pen rotation reported as wheel
675 ((t-1) / 2 + 450)) : (450 - t / 2) ; 592 * due to valuator limitation
676 input_report_abs(dev, ABS_WHEEL, t); 593 */
677 } 594 t = (data[6] << 3) | ((data[7] >> 5) & 7);
595 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
596 ((t-1) / 2 + 450)) : (450 - t / 2) ;
597 input_report_abs(dev, ABS_WHEEL, t);
598 } else {
599 /* 4D mouse rotation packet */
600 t = (data[6] << 3) | ((data[7] >> 5) & 7);
601 input_report_abs(dev, ABS_RZ, (data[7] & 0x20) ?
602 ((t - 1) / 2) : -t / 2);
603 }
678 604
679 /* 2D mouse packets */ 605 } else if (!(data[1] & 0x10) && wacom->features->type < INTUOS3) {
680 if (wacom->tool[idx] == BTN_TOOL_MOUSE) 606 /* 4D mouse packet */
681 { 607 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
608 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
609 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
610
611 input_report_key(dev, BTN_SIDE, data[8] & 0x20);
612 input_report_key(dev, BTN_EXTRA, data[8] & 0x10);
613 t = (data[6] << 2) | ((data[7] >> 6) & 3);
614 input_report_abs(dev, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
615
616 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
617 /* 2D mouse packet */
682 input_report_key(dev, BTN_LEFT, data[8] & 0x04); 618 input_report_key(dev, BTN_LEFT, data[8] & 0x04);
683 input_report_key(dev, BTN_MIDDLE, data[8] & 0x08); 619 input_report_key(dev, BTN_MIDDLE, data[8] & 0x08);
684 input_report_key(dev, BTN_RIGHT, data[8] & 0x10); 620 input_report_key(dev, BTN_RIGHT, data[8] & 0x10);
685 input_report_key(dev, BTN_SIDE, data[8] & 0x40); 621 input_report_rel(dev, REL_WHEEL, ((data[8] & 0x02) >> 1)
686 input_report_key(dev, BTN_EXTRA, data[8] & 0x20); 622 - (data[8] & 0x01));
687 /* mouse wheel is positive when rolled backwards */ 623
688 input_report_rel(dev, REL_WHEEL, ((__u32)((data[8] & 0x02) >> 1) 624 /* I3 2D mouse side buttons */
689 - (__u32)(data[8] & 0x01))); 625 if (wacom->features->type == INTUOS3) {
626 input_report_key(dev, BTN_SIDE, data[8] & 0x40);
627 input_report_key(dev, BTN_EXTRA, data[8] & 0x20);
628 }
629
630 } else if (wacom->features->type < INTUOS3) {
631 /* Lens cursor packets */
632 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
633 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
634 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
635 input_report_key(dev, BTN_SIDE, data[8] & 0x10);
636 input_report_key(dev, BTN_EXTRA, data[8] & 0x08);
690 } 637 }
691 } 638 }
692 639
@@ -702,35 +649,36 @@ exit:
702} 649}
703 650
704static struct wacom_features wacom_features[] = { 651static struct wacom_features wacom_features[] = {
705 { "Wacom Penpartner", 7, 5040, 3780, 255, 32, 0, wacom_penpartner_irq }, 652 { "Wacom Penpartner", 7, 5040, 3780, 255, 32, PENPARTNER, wacom_penpartner_irq },
706 { "Wacom Graphire", 8, 10206, 7422, 511, 32, 1, wacom_graphire_irq }, 653 { "Wacom Graphire", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq },
707 { "Wacom Graphire2 4x5", 8, 10206, 7422, 511, 32, 1, wacom_graphire_irq }, 654 { "Wacom Graphire2 4x5", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq },
708 { "Wacom Graphire2 5x7", 8, 13918, 10206, 511, 32, 1, wacom_graphire_irq }, 655 { "Wacom Graphire2 5x7", 8, 13918, 10206, 511, 32, GRAPHIRE, wacom_graphire_irq },
709 { "Wacom Graphire3", 8, 10208, 7424, 511, 32, 1, wacom_graphire_irq }, 656 { "Wacom Graphire3", 8, 10208, 7424, 511, 32, GRAPHIRE, wacom_graphire_irq },
710 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 32, 1, wacom_graphire_irq }, 657 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 32, GRAPHIRE, wacom_graphire_irq },
711 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 15, 2, wacom_intuos_irq }, 658 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq },
712 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 15, 2, wacom_intuos_irq }, 659 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
713 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 15, 2, wacom_intuos_irq }, 660 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq },
714 { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 15, 2, wacom_intuos_irq }, 661 { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
715 { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 15, 2, wacom_intuos_irq }, 662 { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
716 { "Wacom PL400", 8, 5408, 4056, 255, 32, 3, wacom_pl_irq }, 663 { "Wacom PL400", 8, 5408, 4056, 255, 32, PL, wacom_pl_irq },
717 { "Wacom PL500", 8, 6144, 4608, 255, 32, 3, wacom_pl_irq }, 664 { "Wacom PL500", 8, 6144, 4608, 255, 32, PL, wacom_pl_irq },
718 { "Wacom PL600", 8, 6126, 4604, 255, 32, 3, wacom_pl_irq }, 665 { "Wacom PL600", 8, 6126, 4604, 255, 32, PL, wacom_pl_irq },
719 { "Wacom PL600SX", 8, 6260, 5016, 255, 32, 3, wacom_pl_irq }, 666 { "Wacom PL600SX", 8, 6260, 5016, 255, 32, PL, wacom_pl_irq },
720 { "Wacom PL550", 8, 6144, 4608, 511, 32, 3, wacom_pl_irq }, 667 { "Wacom PL550", 8, 6144, 4608, 511, 32, PL, wacom_pl_irq },
721 { "Wacom PL800", 8, 7220, 5780, 511, 32, 3, wacom_pl_irq }, 668 { "Wacom PL800", 8, 7220, 5780, 511, 32, PL, wacom_pl_irq },
722 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 15, 2, wacom_intuos_irq }, 669 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq },
723 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, 2, wacom_intuos_irq }, 670 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
724 { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 15, 2, wacom_intuos_irq }, 671 { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq },
725 { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 15, 2, wacom_intuos_irq }, 672 { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
726 { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 15, 2, wacom_intuos_irq }, 673 { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
727 { "Wacom Volito", 8, 5104, 3712, 511, 32, 1, wacom_graphire_irq }, 674 { "Wacom Volito", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq },
728 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 32, 3, wacom_ptu_irq }, 675 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 32, PL, wacom_ptu_irq },
729 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 15, 4, wacom_intuos3_irq }, 676 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 15, INTUOS3, wacom_intuos_irq },
730 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 15, 4, wacom_intuos3_irq }, 677 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 15, INTUOS3, wacom_intuos_irq },
731 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 15, 4, wacom_intuos3_irq }, 678 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 15, INTUOS3, wacom_intuos_irq },
732 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, 2, wacom_intuos_irq }, 679 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 15, CINTIQ, wacom_intuos_irq },
733 { } 680 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
681 { }
734}; 682};
735 683
736static struct usb_device_id wacom_ids[] = { 684static struct usb_device_id wacom_ids[] = {
@@ -761,6 +709,7 @@ static struct usb_device_id wacom_ids[] = {
761 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) }, 709 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) },
762 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) }, 710 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) },
763 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) }, 711 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) },
712 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
764 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) }, 713 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
765 { } 714 { }
766}; 715};
@@ -771,14 +720,9 @@ static int wacom_open(struct input_dev *dev)
771{ 720{
772 struct wacom *wacom = dev->private; 721 struct wacom *wacom = dev->private;
773 722
774 if (wacom->open++)
775 return 0;
776
777 wacom->irq->dev = wacom->usbdev; 723 wacom->irq->dev = wacom->usbdev;
778 if (usb_submit_urb(wacom->irq, GFP_KERNEL)) { 724 if (usb_submit_urb(wacom->irq, GFP_KERNEL))
779 wacom->open--;
780 return -EIO; 725 return -EIO;
781 }
782 726
783 return 0; 727 return 0;
784} 728}
@@ -787,8 +731,7 @@ static void wacom_close(struct input_dev *dev)
787{ 731{
788 struct wacom *wacom = dev->private; 732 struct wacom *wacom = dev->private;
789 733
790 if (!--wacom->open) 734 usb_kill_urb(wacom->irq);
791 usb_kill_urb(wacom->irq);
792} 735}
793 736
794static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id) 737static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
@@ -823,32 +766,33 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
823 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS); 766 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS);
824 767
825 switch (wacom->features->type) { 768 switch (wacom->features->type) {
826 case 1: 769 case GRAPHIRE:
827 wacom->dev.evbit[0] |= BIT(EV_REL); 770 wacom->dev.evbit[0] |= BIT(EV_REL);
828 wacom->dev.relbit[0] |= BIT(REL_WHEEL); 771 wacom->dev.relbit[0] |= BIT(REL_WHEEL);
829 wacom->dev.absbit[0] |= BIT(ABS_DISTANCE); 772 wacom->dev.absbit[0] |= BIT(ABS_DISTANCE);
830 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 773 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
831 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2); 774 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2);
832 break; 775 break;
833 776
834 case 4: /* new functions for Intuos3 */ 777 case INTUOS3:
778 case CINTIQ:
835 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER); 779 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
836 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7); 780 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7);
837 wacom->dev.absbit[0] |= BIT(ABS_RX) | BIT(ABS_RY); 781 wacom->dev.absbit[0] |= BIT(ABS_RX) | BIT(ABS_RY);
838 /* fall through */ 782 /* fall through */
839 783
840 case 2: 784 case INTUOS:
841 wacom->dev.evbit[0] |= BIT(EV_MSC) | BIT(EV_REL); 785 wacom->dev.evbit[0] |= BIT(EV_MSC) | BIT(EV_REL);
842 wacom->dev.mscbit[0] |= BIT(MSC_SERIAL); 786 wacom->dev.mscbit[0] |= BIT(MSC_SERIAL);
843 wacom->dev.relbit[0] |= BIT(REL_WHEEL); 787 wacom->dev.relbit[0] |= BIT(REL_WHEEL);
844 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA); 788 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA);
845 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH) 789 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH)
846 | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2); 790 | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2);
847 wacom->dev.absbit[0] |= BIT(ABS_DISTANCE) | BIT(ABS_WHEEL) | BIT(ABS_TILT_X) | BIT(ABS_TILT_Y) | BIT(ABS_RZ) | BIT(ABS_THROTTLE); 791 wacom->dev.absbit[0] |= BIT(ABS_DISTANCE) | BIT(ABS_WHEEL) | BIT(ABS_TILT_X) | BIT(ABS_TILT_Y) | BIT(ABS_RZ) | BIT(ABS_THROTTLE);
848 break; 792 break;
849 793
850 case 3: 794 case PL:
851 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER); 795 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER);
852 break; 796 break;
853 } 797 }
854 798
diff --git a/drivers/usb/input/xpad.c b/drivers/usb/input/xpad.c
index d65edb22e545..a7fa1b17dcfe 100644
--- a/drivers/usb/input/xpad.c
+++ b/drivers/usb/input/xpad.c
@@ -104,13 +104,12 @@ MODULE_DEVICE_TABLE (usb, xpad_table);
104struct usb_xpad { 104struct usb_xpad {
105 struct input_dev dev; /* input device interface */ 105 struct input_dev dev; /* input device interface */
106 struct usb_device *udev; /* usb device */ 106 struct usb_device *udev; /* usb device */
107 107
108 struct urb *irq_in; /* urb for interrupt in report */ 108 struct urb *irq_in; /* urb for interrupt in report */
109 unsigned char *idata; /* input data */ 109 unsigned char *idata; /* input data */
110 dma_addr_t idata_dma; 110 dma_addr_t idata_dma;
111 111
112 char phys[65]; /* physical device path */ 112 char phys[65]; /* physical device path */
113 int open_count; /* reference count */
114}; 113};
115 114
116/* 115/*
@@ -128,35 +127,35 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d
128 struct input_dev *dev = &xpad->dev; 127 struct input_dev *dev = &xpad->dev;
129 128
130 input_regs(dev, regs); 129 input_regs(dev, regs);
131 130
132 /* left stick */ 131 /* left stick */
133 input_report_abs(dev, ABS_X, (__s16) (((__s16)data[13] << 8) | data[12])); 132 input_report_abs(dev, ABS_X, (__s16) (((__s16)data[13] << 8) | data[12]));
134 input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[15] << 8) | data[14])); 133 input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[15] << 8) | data[14]));
135 134
136 /* right stick */ 135 /* right stick */
137 input_report_abs(dev, ABS_RX, (__s16) (((__s16)data[17] << 8) | data[16])); 136 input_report_abs(dev, ABS_RX, (__s16) (((__s16)data[17] << 8) | data[16]));
138 input_report_abs(dev, ABS_RY, (__s16) (((__s16)data[19] << 8) | data[18])); 137 input_report_abs(dev, ABS_RY, (__s16) (((__s16)data[19] << 8) | data[18]));
139 138
140 /* triggers left/right */ 139 /* triggers left/right */
141 input_report_abs(dev, ABS_Z, data[10]); 140 input_report_abs(dev, ABS_Z, data[10]);
142 input_report_abs(dev, ABS_RZ, data[11]); 141 input_report_abs(dev, ABS_RZ, data[11]);
143 142
144 /* digital pad */ 143 /* digital pad */
145 input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 0x04)); 144 input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 0x04));
146 input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 0x01)); 145 input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 0x01));
147 146
148 /* start/back buttons and stick press left/right */ 147 /* start/back buttons and stick press left/right */
149 input_report_key(dev, BTN_START, (data[2] & 0x10) >> 4); 148 input_report_key(dev, BTN_START, (data[2] & 0x10) >> 4);
150 input_report_key(dev, BTN_BACK, (data[2] & 0x20) >> 5); 149 input_report_key(dev, BTN_BACK, (data[2] & 0x20) >> 5);
151 input_report_key(dev, BTN_THUMBL, (data[2] & 0x40) >> 6); 150 input_report_key(dev, BTN_THUMBL, (data[2] & 0x40) >> 6);
152 input_report_key(dev, BTN_THUMBR, data[2] >> 7); 151 input_report_key(dev, BTN_THUMBR, data[2] >> 7);
153 152
154 /* "analog" buttons A, B, X, Y */ 153 /* "analog" buttons A, B, X, Y */
155 input_report_key(dev, BTN_A, data[4]); 154 input_report_key(dev, BTN_A, data[4]);
156 input_report_key(dev, BTN_B, data[5]); 155 input_report_key(dev, BTN_B, data[5]);
157 input_report_key(dev, BTN_X, data[6]); 156 input_report_key(dev, BTN_X, data[6]);
158 input_report_key(dev, BTN_Y, data[7]); 157 input_report_key(dev, BTN_Y, data[7]);
159 158
160 /* "analog" buttons black, white */ 159 /* "analog" buttons black, white */
161 input_report_key(dev, BTN_C, data[8]); 160 input_report_key(dev, BTN_C, data[8]);
162 input_report_key(dev, BTN_Z, data[9]); 161 input_report_key(dev, BTN_Z, data[9]);
@@ -168,7 +167,7 @@ static void xpad_irq_in(struct urb *urb, struct pt_regs *regs)
168{ 167{
169 struct usb_xpad *xpad = urb->context; 168 struct usb_xpad *xpad = urb->context;
170 int retval; 169 int retval;
171 170
172 switch (urb->status) { 171 switch (urb->status) {
173 case 0: 172 case 0:
174 /* success */ 173 /* success */
@@ -183,7 +182,7 @@ static void xpad_irq_in(struct urb *urb, struct pt_regs *regs)
183 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); 182 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
184 goto exit; 183 goto exit;
185 } 184 }
186 185
187 xpad_process_packet(xpad, 0, xpad->idata, regs); 186 xpad_process_packet(xpad, 0, xpad->idata, regs);
188 187
189exit: 188exit:
@@ -196,25 +195,19 @@ exit:
196static int xpad_open (struct input_dev *dev) 195static int xpad_open (struct input_dev *dev)
197{ 196{
198 struct usb_xpad *xpad = dev->private; 197 struct usb_xpad *xpad = dev->private;
199 198
200 if (xpad->open_count++)
201 return 0;
202
203 xpad->irq_in->dev = xpad->udev; 199 xpad->irq_in->dev = xpad->udev;
204 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) { 200 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL))
205 xpad->open_count--;
206 return -EIO; 201 return -EIO;
207 } 202
208
209 return 0; 203 return 0;
210} 204}
211 205
212static void xpad_close (struct input_dev *dev) 206static void xpad_close (struct input_dev *dev)
213{ 207{
214 struct usb_xpad *xpad = dev->private; 208 struct usb_xpad *xpad = dev->private;
215 209
216 if (!--xpad->open_count) 210 usb_kill_urb(xpad->irq_in);
217 usb_kill_urb(xpad->irq_in);
218} 211}
219 212
220static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id) 213static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id)
@@ -224,19 +217,19 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
224 struct usb_endpoint_descriptor *ep_irq_in; 217 struct usb_endpoint_descriptor *ep_irq_in;
225 char path[64]; 218 char path[64];
226 int i; 219 int i;
227 220
228 for (i = 0; xpad_device[i].idVendor; i++) { 221 for (i = 0; xpad_device[i].idVendor; i++) {
229 if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && 222 if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) &&
230 (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct)) 223 (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct))
231 break; 224 break;
232 } 225 }
233 226
234 if ((xpad = kmalloc (sizeof(struct usb_xpad), GFP_KERNEL)) == NULL) { 227 if ((xpad = kmalloc (sizeof(struct usb_xpad), GFP_KERNEL)) == NULL) {
235 err("cannot allocate memory for new pad"); 228 err("cannot allocate memory for new pad");
236 return -ENOMEM; 229 return -ENOMEM;
237 } 230 }
238 memset(xpad, 0, sizeof(struct usb_xpad)); 231 memset(xpad, 0, sizeof(struct usb_xpad));
239 232
240 xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN, 233 xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN,
241 SLAB_ATOMIC, &xpad->idata_dma); 234 SLAB_ATOMIC, &xpad->idata_dma);
242 if (!xpad->idata) { 235 if (!xpad->idata) {
@@ -251,18 +244,18 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
251 kfree(xpad); 244 kfree(xpad);
252 return -ENOMEM; 245 return -ENOMEM;
253 } 246 }
254 247
255 ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; 248 ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;
256 249
257 usb_fill_int_urb(xpad->irq_in, udev, 250 usb_fill_int_urb(xpad->irq_in, udev,
258 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), 251 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
259 xpad->idata, XPAD_PKT_LEN, xpad_irq_in, 252 xpad->idata, XPAD_PKT_LEN, xpad_irq_in,
260 xpad, ep_irq_in->bInterval); 253 xpad, ep_irq_in->bInterval);
261 xpad->irq_in->transfer_dma = xpad->idata_dma; 254 xpad->irq_in->transfer_dma = xpad->idata_dma;
262 xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 255 xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
263 256
264 xpad->udev = udev; 257 xpad->udev = udev;
265 258
266 xpad->dev.id.bustype = BUS_USB; 259 xpad->dev.id.bustype = BUS_USB;
267 xpad->dev.id.vendor = le16_to_cpu(udev->descriptor.idVendor); 260 xpad->dev.id.vendor = le16_to_cpu(udev->descriptor.idVendor);
268 xpad->dev.id.product = le16_to_cpu(udev->descriptor.idProduct); 261 xpad->dev.id.product = le16_to_cpu(udev->descriptor.idProduct);
@@ -273,21 +266,21 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
273 xpad->dev.phys = xpad->phys; 266 xpad->dev.phys = xpad->phys;
274 xpad->dev.open = xpad_open; 267 xpad->dev.open = xpad_open;
275 xpad->dev.close = xpad_close; 268 xpad->dev.close = xpad_close;
276 269
277 usb_make_path(udev, path, 64); 270 usb_make_path(udev, path, 64);
278 snprintf(xpad->phys, 64, "%s/input0", path); 271 snprintf(xpad->phys, 64, "%s/input0", path);
279 272
280 xpad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 273 xpad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
281 274
282 for (i = 0; xpad_btn[i] >= 0; i++) 275 for (i = 0; xpad_btn[i] >= 0; i++)
283 set_bit(xpad_btn[i], xpad->dev.keybit); 276 set_bit(xpad_btn[i], xpad->dev.keybit);
284 277
285 for (i = 0; xpad_abs[i] >= 0; i++) { 278 for (i = 0; xpad_abs[i] >= 0; i++) {
286 279
287 signed short t = xpad_abs[i]; 280 signed short t = xpad_abs[i];
288 281
289 set_bit(t, xpad->dev.absbit); 282 set_bit(t, xpad->dev.absbit);
290 283
291 switch (t) { 284 switch (t) {
292 case ABS_X: 285 case ABS_X:
293 case ABS_Y: 286 case ABS_Y:
@@ -310,11 +303,11 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
310 break; 303 break;
311 } 304 }
312 } 305 }
313 306
314 input_register_device(&xpad->dev); 307 input_register_device(&xpad->dev);
315 308
316 printk(KERN_INFO "input: %s on %s", xpad->dev.name, path); 309 printk(KERN_INFO "input: %s on %s", xpad->dev.name, path);
317 310
318 usb_set_intfdata(intf, xpad); 311 usb_set_intfdata(intf, xpad);
319 return 0; 312 return 0;
320} 313}
@@ -322,7 +315,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
322static void xpad_disconnect(struct usb_interface *intf) 315static void xpad_disconnect(struct usb_interface *intf)
323{ 316{
324 struct usb_xpad *xpad = usb_get_intfdata (intf); 317 struct usb_xpad *xpad = usb_get_intfdata (intf);
325 318
326 usb_set_intfdata(intf, NULL); 319 usb_set_intfdata(intf, NULL);
327 if (xpad) { 320 if (xpad) {
328 usb_kill_urb(xpad->irq_in); 321 usb_kill_urb(xpad->irq_in);
diff --git a/drivers/usb/media/stv680.c b/drivers/usb/media/stv680.c
index ae455c8e3702..7398a7f19c1e 100644
--- a/drivers/usb/media/stv680.c
+++ b/drivers/usb/media/stv680.c
@@ -1375,9 +1375,13 @@ static int stv680_probe (struct usb_interface *intf, const struct usb_device_id
1375 (le16_to_cpu(dev->descriptor.idProduct) == USB_PENCAM_PRODUCT_ID)) { 1375 (le16_to_cpu(dev->descriptor.idProduct) == USB_PENCAM_PRODUCT_ID)) {
1376 camera_name = "STV0680"; 1376 camera_name = "STV0680";
1377 PDEBUG (0, "STV(i): STV0680 camera found."); 1377 PDEBUG (0, "STV(i): STV0680 camera found.");
1378 } else if ((le16_to_cpu(dev->descriptor.idVendor) == USB_CREATIVEGOMINI_VENDOR_ID) &&
1379 (le16_to_cpu(dev->descriptor.idProduct) == USB_CREATIVEGOMINI_PRODUCT_ID)) {
1380 camera_name = "Creative WebCam Go Mini";
1381 PDEBUG (0, "STV(i): Creative WebCam Go Mini found.");
1378 } else { 1382 } else {
1379 PDEBUG (0, "STV(e): Vendor/Product ID do not match STV0680 values."); 1383 PDEBUG (0, "STV(e): Vendor/Product ID do not match STV0680 or Creative WebCam Go Mini values.");
1380 PDEBUG (0, "STV(e): Check that the STV0680 camera is connected to the computer."); 1384 PDEBUG (0, "STV(e): Check that the STV0680 or Creative WebCam Go Mini camera is connected to the computer.");
1381 retval = -ENODEV; 1385 retval = -ENODEV;
1382 goto error; 1386 goto error;
1383 } 1387 }
diff --git a/drivers/usb/media/stv680.h b/drivers/usb/media/stv680.h
index 7e0e314dcf12..445940612603 100644
--- a/drivers/usb/media/stv680.h
+++ b/drivers/usb/media/stv680.h
@@ -41,12 +41,17 @@
41 41
42#define USB_PENCAM_VENDOR_ID 0x0553 42#define USB_PENCAM_VENDOR_ID 0x0553
43#define USB_PENCAM_PRODUCT_ID 0x0202 43#define USB_PENCAM_PRODUCT_ID 0x0202
44
45#define USB_CREATIVEGOMINI_VENDOR_ID 0x041e
46#define USB_CREATIVEGOMINI_PRODUCT_ID 0x4007
47
44#define PENCAM_TIMEOUT 1000 48#define PENCAM_TIMEOUT 1000
45/* fmt 4 */ 49/* fmt 4 */
46#define STV_VIDEO_PALETTE VIDEO_PALETTE_RGB24 50#define STV_VIDEO_PALETTE VIDEO_PALETTE_RGB24
47 51
48static struct usb_device_id device_table[] = { 52static struct usb_device_id device_table[] = {
49 {USB_DEVICE (USB_PENCAM_VENDOR_ID, USB_PENCAM_PRODUCT_ID)}, 53 {USB_DEVICE (USB_PENCAM_VENDOR_ID, USB_PENCAM_PRODUCT_ID)},
54 {USB_DEVICE (USB_CREATIVEGOMINI_VENDOR_ID, USB_CREATIVEGOMINI_PRODUCT_ID)},
50 {} 55 {}
51}; 56};
52MODULE_DEVICE_TABLE (usb, device_table); 57MODULE_DEVICE_TABLE (usb, device_table);
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c
index ce030d1f1c1f..733acc213726 100644
--- a/drivers/usb/misc/idmouse.c
+++ b/drivers/usb/misc/idmouse.c
@@ -1,4 +1,4 @@
1/* Siemens ID Mouse driver v0.5 1/* Siemens ID Mouse driver v0.6
2 2
3 This program is free software; you can redistribute it and/or 3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License as 4 modify it under the terms of the GNU General Public License as
@@ -11,6 +11,9 @@
11 Derived from the USB Skeleton driver 1.1, 11 Derived from the USB Skeleton driver 1.1,
12 Copyright (C) 2003 Greg Kroah-Hartman (greg@kroah.com) 12 Copyright (C) 2003 Greg Kroah-Hartman (greg@kroah.com)
13 13
14 Additional information provided by Martin Reising
15 <Martin.Reising@natural-computing.de>
16
14*/ 17*/
15 18
16#include <linux/config.h> 19#include <linux/config.h>
@@ -25,29 +28,44 @@
25#include <asm/uaccess.h> 28#include <asm/uaccess.h>
26#include <linux/usb.h> 29#include <linux/usb.h>
27 30
31/* image constants */
28#define WIDTH 225 32#define WIDTH 225
29#define HEIGHT 288 33#define HEIGHT 289
30#define HEADER "P5 225 288 255 " 34#define HEADER "P5 225 289 255 "
31#define IMGSIZE ((WIDTH * HEIGHT) + sizeof(HEADER)-1) 35#define IMGSIZE ((WIDTH * HEIGHT) + sizeof(HEADER)-1)
32 36
33/* Version Information */ 37/* version information */
34#define DRIVER_VERSION "0.5" 38#define DRIVER_VERSION "0.6"
35#define DRIVER_SHORT "idmouse" 39#define DRIVER_SHORT "idmouse"
36#define DRIVER_AUTHOR "Florian 'Floe' Echtler <echtler@fs.tum.de>" 40#define DRIVER_AUTHOR "Florian 'Floe' Echtler <echtler@fs.tum.de>"
37#define DRIVER_DESC "Siemens ID Mouse FingerTIP Sensor Driver" 41#define DRIVER_DESC "Siemens ID Mouse FingerTIP Sensor Driver"
38 42
39/* Siemens ID Mouse */ 43/* minor number for misc USB devices */
40#define USB_IDMOUSE_VENDOR_ID 0x0681
41#define USB_IDMOUSE_PRODUCT_ID 0x0005
42
43/* we still need a minor number */
44#define USB_IDMOUSE_MINOR_BASE 132 44#define USB_IDMOUSE_MINOR_BASE 132
45 45
46/* vendor and device IDs */
47#define ID_SIEMENS 0x0681
48#define ID_IDMOUSE 0x0005
49#define ID_CHERRY 0x0010
50
51/* device ID table */
46static struct usb_device_id idmouse_table[] = { 52static struct usb_device_id idmouse_table[] = {
47 {USB_DEVICE(USB_IDMOUSE_VENDOR_ID, USB_IDMOUSE_PRODUCT_ID)}, 53 {USB_DEVICE(ID_SIEMENS, ID_IDMOUSE)}, /* Siemens ID Mouse (Professional) */
48 {} /* null entry at the end */ 54 {USB_DEVICE(ID_SIEMENS, ID_CHERRY )}, /* Cherry FingerTIP ID Board */
55 {} /* terminating null entry */
49}; 56};
50 57
58/* sensor commands */
59#define FTIP_RESET 0x20
60#define FTIP_ACQUIRE 0x21
61#define FTIP_RELEASE 0x22
62#define FTIP_BLINK 0x23 /* LSB of value = blink pulse width */
63#define FTIP_SCROLL 0x24
64
65#define ftip_command(dev, command, value, index) \
66 usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), command, \
67 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, value, index, NULL, 0, 1000)
68
51MODULE_DEVICE_TABLE(usb, idmouse_table); 69MODULE_DEVICE_TABLE(usb, idmouse_table);
52 70
53/* structure to hold all of our device specific stuff */ 71/* structure to hold all of our device specific stuff */
@@ -57,7 +75,8 @@ struct usb_idmouse {
57 struct usb_interface *interface; /* the interface for this device */ 75 struct usb_interface *interface; /* the interface for this device */
58 76
59 unsigned char *bulk_in_buffer; /* the buffer to receive data */ 77 unsigned char *bulk_in_buffer; /* the buffer to receive data */
60 size_t bulk_in_size; /* the size of the receive buffer */ 78 size_t bulk_in_size; /* the maximum bulk packet size */
79 size_t orig_bi_size; /* same as above, but reported by the device */
61 __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ 80 __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */
62 81
63 int open; /* if the port is open or not */ 82 int open; /* if the port is open or not */
@@ -103,7 +122,7 @@ static struct usb_driver idmouse_driver = {
103 .id_table = idmouse_table, 122 .id_table = idmouse_table,
104}; 123};
105 124
106// prevent races between open() and disconnect() 125/* prevent races between open() and disconnect() */
107static DECLARE_MUTEX(disconnect_sem); 126static DECLARE_MUTEX(disconnect_sem);
108 127
109static int idmouse_create_image(struct usb_idmouse *dev) 128static int idmouse_create_image(struct usb_idmouse *dev)
@@ -112,42 +131,34 @@ static int idmouse_create_image(struct usb_idmouse *dev)
112 int bulk_read = 0; 131 int bulk_read = 0;
113 int result = 0; 132 int result = 0;
114 133
115 if (dev->bulk_in_size < sizeof(HEADER)) 134 memcpy(dev->bulk_in_buffer, HEADER, sizeof(HEADER)-1);
116 return -ENOMEM;
117
118 memcpy(dev->bulk_in_buffer,HEADER,sizeof(HEADER)-1);
119 bytes_read += sizeof(HEADER)-1; 135 bytes_read += sizeof(HEADER)-1;
120 136
121 /* Dump the setup packets. Yes, they are uncommented, simply 137 /* reset the device and set a fast blink rate */
122 because they were sniffed under Windows using SnoopyPro. 138 result = ftip_command(dev, FTIP_RELEASE, 0, 0);
123 I _guess_ that 0x22 is a kind of reset command and 0x21
124 means init..
125 */
126 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0),
127 0x21, 0x42, 0x0001, 0x0002, NULL, 0, 1000);
128 if (result < 0)
129 return result;
130 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0),
131 0x20, 0x42, 0x0001, 0x0002, NULL, 0, 1000);
132 if (result < 0) 139 if (result < 0)
133 return result; 140 goto reset;
134 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 141 result = ftip_command(dev, FTIP_BLINK, 1, 0);
135 0x22, 0x42, 0x0000, 0x0002, NULL, 0, 1000);
136 if (result < 0) 142 if (result < 0)
137 return result; 143 goto reset;
138 144
139 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 145 /* initialize the sensor - sending this command twice */
140 0x21, 0x42, 0x0001, 0x0002, NULL, 0, 1000); 146 /* significantly reduces the rate of failed reads */
147 result = ftip_command(dev, FTIP_ACQUIRE, 0, 0);
141 if (result < 0) 148 if (result < 0)
142 return result; 149 goto reset;
143 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 150 result = ftip_command(dev, FTIP_ACQUIRE, 0, 0);
144 0x20, 0x42, 0x0001, 0x0002, NULL, 0, 1000);
145 if (result < 0) 151 if (result < 0)
146 return result; 152 goto reset;
147 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 153
148 0x20, 0x42, 0x0000, 0x0002, NULL, 0, 1000); 154 /* start the readout - sending this command twice */
155 /* presumably enables the high dynamic range mode */
156 result = ftip_command(dev, FTIP_RESET, 0, 0);
149 if (result < 0) 157 if (result < 0)
150 return result; 158 goto reset;
159 result = ftip_command(dev, FTIP_RESET, 0, 0);
160 if (result < 0)
161 goto reset;
151 162
152 /* loop over a blocking bulk read to get data from the device */ 163 /* loop over a blocking bulk read to get data from the device */
153 while (bytes_read < IMGSIZE) { 164 while (bytes_read < IMGSIZE) {
@@ -155,22 +166,40 @@ static int idmouse_create_image(struct usb_idmouse *dev)
155 usb_rcvbulkpipe (dev->udev, dev->bulk_in_endpointAddr), 166 usb_rcvbulkpipe (dev->udev, dev->bulk_in_endpointAddr),
156 dev->bulk_in_buffer + bytes_read, 167 dev->bulk_in_buffer + bytes_read,
157 dev->bulk_in_size, &bulk_read, 5000); 168 dev->bulk_in_size, &bulk_read, 5000);
158 if (result < 0) 169 if (result < 0) {
159 return result; 170 /* Maybe this error was caused by the increased packet size? */
160 if (signal_pending(current)) 171 /* Reset to the original value and tell userspace to retry. */
161 return -EINTR; 172 if (dev->bulk_in_size != dev->orig_bi_size) {
173 dev->bulk_in_size = dev->orig_bi_size;
174 result = -EAGAIN;
175 }
176 break;
177 }
178 if (signal_pending(current)) {
179 result = -EINTR;
180 break;
181 }
162 bytes_read += bulk_read; 182 bytes_read += bulk_read;
163 } 183 }
164 184
165 /* reset the device */ 185 /* reset the device */
166 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 186reset:
167 0x22, 0x42, 0x0000, 0x0002, NULL, 0, 1000); 187 ftip_command(dev, FTIP_RELEASE, 0, 0);
168 if (result < 0) 188
169 return result; 189 /* check for valid image */
190 /* right border should be black (0x00) */
191 for (bytes_read = sizeof(HEADER)-1 + WIDTH-1; bytes_read < IMGSIZE; bytes_read += WIDTH)
192 if (dev->bulk_in_buffer[bytes_read] != 0x00)
193 return -EAGAIN;
170 194
171 /* should be IMGSIZE == 64815 */ 195 /* lower border should be white (0xFF) */
196 for (bytes_read = IMGSIZE-WIDTH; bytes_read < IMGSIZE-1; bytes_read++)
197 if (dev->bulk_in_buffer[bytes_read] != 0xFF)
198 return -EAGAIN;
199
200 /* should be IMGSIZE == 65040 */
172 dbg("read %d bytes fingerprint data", bytes_read); 201 dbg("read %d bytes fingerprint data", bytes_read);
173 return 0; 202 return result;
174} 203}
175 204
176static inline void idmouse_delete(struct usb_idmouse *dev) 205static inline void idmouse_delete(struct usb_idmouse *dev)
@@ -282,10 +311,10 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count
282 311
283 dev = (struct usb_idmouse *) file->private_data; 312 dev = (struct usb_idmouse *) file->private_data;
284 313
285 // lock this object 314 /* lock this object */
286 down (&dev->sem); 315 down (&dev->sem);
287 316
288 // verify that the device wasn't unplugged 317 /* verify that the device wasn't unplugged */
289 if (!dev->present) { 318 if (!dev->present) {
290 up (&dev->sem); 319 up (&dev->sem);
291 return -ENODEV; 320 return -ENODEV;
@@ -296,8 +325,7 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count
296 return 0; 325 return 0;
297 } 326 }
298 327
299 if (count > IMGSIZE - *ppos) 328 count = min ((loff_t)count, IMGSIZE - (*ppos));
300 count = IMGSIZE - *ppos;
301 329
302 if (copy_to_user (buffer, dev->bulk_in_buffer + *ppos, count)) { 330 if (copy_to_user (buffer, dev->bulk_in_buffer + *ppos, count)) {
303 result = -EFAULT; 331 result = -EFAULT;
@@ -306,7 +334,7 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count
306 *ppos += count; 334 *ppos += count;
307 } 335 }
308 336
309 // unlock the device 337 /* unlock the device */
310 up(&dev->sem); 338 up(&dev->sem);
311 return result; 339 return result;
312} 340}
@@ -318,7 +346,6 @@ static int idmouse_probe(struct usb_interface *interface,
318 struct usb_idmouse *dev = NULL; 346 struct usb_idmouse *dev = NULL;
319 struct usb_host_interface *iface_desc; 347 struct usb_host_interface *iface_desc;
320 struct usb_endpoint_descriptor *endpoint; 348 struct usb_endpoint_descriptor *endpoint;
321 size_t buffer_size;
322 int result; 349 int result;
323 350
324 /* check if we have gotten the data or the hid interface */ 351 /* check if we have gotten the data or the hid interface */
@@ -344,11 +371,11 @@ static int idmouse_probe(struct usb_interface *interface,
344 USB_ENDPOINT_XFER_BULK)) { 371 USB_ENDPOINT_XFER_BULK)) {
345 372
346 /* we found a bulk in endpoint */ 373 /* we found a bulk in endpoint */
347 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 374 dev->orig_bi_size = le16_to_cpu(endpoint->wMaxPacketSize);
348 dev->bulk_in_size = buffer_size; 375 dev->bulk_in_size = 0x200; /* works _much_ faster */
349 dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; 376 dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
350 dev->bulk_in_buffer = 377 dev->bulk_in_buffer =
351 kmalloc(IMGSIZE + buffer_size, GFP_KERNEL); 378 kmalloc(IMGSIZE + dev->bulk_in_size, GFP_KERNEL);
352 379
353 if (!dev->bulk_in_buffer) { 380 if (!dev->bulk_in_buffer) {
354 err("Unable to allocate input buffer."); 381 err("Unable to allocate input buffer.");
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 3104f28f6aa8..cda7249a90b2 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -461,7 +461,7 @@ static int perform_sglist (
461 461
462static unsigned realworld = 1; 462static unsigned realworld = 1;
463module_param (realworld, uint, 0); 463module_param (realworld, uint, 0);
464MODULE_PARM_DESC (realworld, "clear to demand stricter ch9 compliance"); 464MODULE_PARM_DESC (realworld, "clear to demand stricter spec compliance");
465 465
466static int get_altsetting (struct usbtest_dev *dev) 466static int get_altsetting (struct usbtest_dev *dev)
467{ 467{
@@ -604,9 +604,8 @@ static int ch9_postconfig (struct usbtest_dev *dev)
604 USB_DIR_IN | USB_RECIP_DEVICE, 604 USB_DIR_IN | USB_RECIP_DEVICE,
605 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT); 605 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT);
606 if (retval != 1 || dev->buf [0] != expected) { 606 if (retval != 1 || dev->buf [0] != expected) {
607 dev_dbg (&iface->dev, 607 dev_dbg (&iface->dev, "get config --> %d %d (1 %d)\n",
608 "get config --> %d (%d)\n", retval, 608 retval, dev->buf[0], expected);
609 expected);
610 return (retval < 0) ? retval : -EDOM; 609 return (retval < 0) ? retval : -EDOM;
611 } 610 }
612 } 611 }
@@ -1243,7 +1242,7 @@ static int ctrl_out (struct usbtest_dev *dev,
1243 char *what = "?"; 1242 char *what = "?";
1244 struct usb_device *udev; 1243 struct usb_device *udev;
1245 1244
1246 if (length > 0xffff || vary >= length) 1245 if (length < 1 || length > 0xffff || vary >= length)
1247 return -EINVAL; 1246 return -EINVAL;
1248 1247
1249 buf = kmalloc(length, SLAB_KERNEL); 1248 buf = kmalloc(length, SLAB_KERNEL);
@@ -1266,6 +1265,11 @@ static int ctrl_out (struct usbtest_dev *dev,
1266 0, 0, buf, len, USB_CTRL_SET_TIMEOUT); 1265 0, 0, buf, len, USB_CTRL_SET_TIMEOUT);
1267 if (retval != len) { 1266 if (retval != len) {
1268 what = "write"; 1267 what = "write";
1268 if (retval >= 0) {
1269 INFO(dev, "ctrl_out, wlen %d (expected %d)\n",
1270 retval, len);
1271 retval = -EBADMSG;
1272 }
1269 break; 1273 break;
1270 } 1274 }
1271 1275
@@ -1275,6 +1279,11 @@ static int ctrl_out (struct usbtest_dev *dev,
1275 0, 0, buf, len, USB_CTRL_GET_TIMEOUT); 1279 0, 0, buf, len, USB_CTRL_GET_TIMEOUT);
1276 if (retval != len) { 1280 if (retval != len) {
1277 what = "read"; 1281 what = "read";
1282 if (retval >= 0) {
1283 INFO(dev, "ctrl_out, rlen %d (expected %d)\n",
1284 retval, len);
1285 retval = -EBADMSG;
1286 }
1278 break; 1287 break;
1279 } 1288 }
1280 1289
@@ -1293,8 +1302,13 @@ static int ctrl_out (struct usbtest_dev *dev,
1293 } 1302 }
1294 1303
1295 len += vary; 1304 len += vary;
1305
1306 /* [real world] the "zero bytes IN" case isn't really used.
1307 * hardware can easily trip up in this wierd case, since its
1308 * status stage is IN, not OUT like other ep0in transfers.
1309 */
1296 if (len > length) 1310 if (len > length)
1297 len = 0; 1311 len = realworld ? 1 : 0;
1298 } 1312 }
1299 1313
1300 if (retval < 0) 1314 if (retval < 0)
@@ -1519,6 +1533,11 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1519 if (down_interruptible (&dev->sem)) 1533 if (down_interruptible (&dev->sem))
1520 return -ERESTARTSYS; 1534 return -ERESTARTSYS;
1521 1535
1536 if (intf->dev.power.power_state != PMSG_ON) {
1537 up (&dev->sem);
1538 return -EHOSTUNREACH;
1539 }
1540
1522 /* some devices, like ez-usb default devices, need a non-default 1541 /* some devices, like ez-usb default devices, need a non-default
1523 * altsetting to have any active endpoints. some tests change 1542 * altsetting to have any active endpoints. some tests change
1524 * altsettings; force a default so most tests don't need to check. 1543 * altsettings; force a default so most tests don't need to check.
@@ -1762,8 +1781,10 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1762 case 14: 1781 case 14:
1763 if (!dev->info->ctrl_out) 1782 if (!dev->info->ctrl_out)
1764 break; 1783 break;
1765 dev_dbg (&intf->dev, "TEST 14: %d ep0out, 0..%d vary %d\n", 1784 dev_dbg (&intf->dev, "TEST 14: %d ep0out, %d..%d vary %d\n",
1766 param->iterations, param->length, param->vary); 1785 param->iterations,
1786 realworld ? 1 : 0, param->length,
1787 param->vary);
1767 retval = ctrl_out (dev, param->iterations, 1788 retval = ctrl_out (dev, param->iterations,
1768 param->length, param->vary); 1789 param->length, param->vary);
1769 break; 1790 break;
@@ -1927,6 +1948,27 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1927 return 0; 1948 return 0;
1928} 1949}
1929 1950
1951static int usbtest_suspend (struct usb_interface *intf, pm_message_t message)
1952{
1953 struct usbtest_dev *dev = usb_get_intfdata (intf);
1954
1955 down (&dev->sem);
1956 intf->dev.power.power_state = PMSG_SUSPEND;
1957 up (&dev->sem);
1958 return 0;
1959}
1960
1961static int usbtest_resume (struct usb_interface *intf)
1962{
1963 struct usbtest_dev *dev = usb_get_intfdata (intf);
1964
1965 down (&dev->sem);
1966 intf->dev.power.power_state = PMSG_ON;
1967 up (&dev->sem);
1968 return 0;
1969}
1970
1971
1930static void usbtest_disconnect (struct usb_interface *intf) 1972static void usbtest_disconnect (struct usb_interface *intf)
1931{ 1973{
1932 struct usbtest_dev *dev = usb_get_intfdata (intf); 1974 struct usbtest_dev *dev = usb_get_intfdata (intf);
@@ -2115,6 +2157,8 @@ static struct usb_driver usbtest_driver = {
2115 .probe = usbtest_probe, 2157 .probe = usbtest_probe,
2116 .ioctl = usbtest_ioctl, 2158 .ioctl = usbtest_ioctl,
2117 .disconnect = usbtest_disconnect, 2159 .disconnect = usbtest_disconnect,
2160 .suspend = usbtest_suspend,
2161 .resume = usbtest_resume,
2118}; 2162};
2119 2163
2120/*-------------------------------------------------------------------------*/ 2164/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/net/pegasus.c b/drivers/usb/net/pegasus.c
index d976790312aa..5f4496d8dbac 100644
--- a/drivers/usb/net/pegasus.c
+++ b/drivers/usb/net/pegasus.c
@@ -1166,7 +1166,7 @@ static void pegasus_set_multicast(struct net_device *net)
1166 pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS; 1166 pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS;
1167 if (netif_msg_link(pegasus)) 1167 if (netif_msg_link(pegasus))
1168 pr_info("%s: Promiscuous mode enabled.\n", net->name); 1168 pr_info("%s: Promiscuous mode enabled.\n", net->name);
1169 } else if ((net->mc_count > multicast_filter_limit) || 1169 } else if (net->mc_count ||
1170 (net->flags & IFF_ALLMULTI)) { 1170 (net->flags & IFF_ALLMULTI)) {
1171 pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST; 1171 pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST;
1172 pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS; 1172 pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
diff --git a/drivers/usb/net/pegasus.h b/drivers/usb/net/pegasus.h
index 13ccedef5c7e..b98f2a833442 100644
--- a/drivers/usb/net/pegasus.h
+++ b/drivers/usb/net/pegasus.h
@@ -249,6 +249,8 @@ PEGASUS_DEV( "Kingston KNU101TX Ethernet", VENDOR_KINGSTON, 0x000a,
249 DEFAULT_GPIO_RESET) 249 DEFAULT_GPIO_RESET)
250PEGASUS_DEV( "LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x4002, 250PEGASUS_DEV( "LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x4002,
251 DEFAULT_GPIO_RESET ) 251 DEFAULT_GPIO_RESET )
252PEGASUS_DEV( "LANEED USB Ethernet LD-USBL/TX", VENDOR_LANEED, 0x4005,
253 DEFAULT_GPIO_RESET | PEGASUS_II)
252PEGASUS_DEV( "LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x400b, 254PEGASUS_DEV( "LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x400b,
253 DEFAULT_GPIO_RESET | PEGASUS_II ) 255 DEFAULT_GPIO_RESET | PEGASUS_II )
254PEGASUS_DEV( "LANEED USB Ethernet LD-USB/T", VENDOR_LANEED, 0xabc1, 256PEGASUS_DEV( "LANEED USB Ethernet LD-USB/T", VENDOR_LANEED, 0xabc1,
diff --git a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c
index 8fb223385f2f..626b016addff 100644
--- a/drivers/usb/net/rtl8150.c
+++ b/drivers/usb/net/rtl8150.c
@@ -667,7 +667,7 @@ static void rtl8150_set_multicast(struct net_device *netdev)
667 if (netdev->flags & IFF_PROMISC) { 667 if (netdev->flags & IFF_PROMISC) {
668 dev->rx_creg |= cpu_to_le16(0x0001); 668 dev->rx_creg |= cpu_to_le16(0x0001);
669 info("%s: promiscuous mode", netdev->name); 669 info("%s: promiscuous mode", netdev->name);
670 } else if ((netdev->mc_count > multicast_filter_limit) || 670 } else if (netdev->mc_count ||
671 (netdev->flags & IFF_ALLMULTI)) { 671 (netdev->flags & IFF_ALLMULTI)) {
672 dev->rx_creg &= cpu_to_le16(0xfffe); 672 dev->rx_creg &= cpu_to_le16(0xfffe);
673 dev->rx_creg |= cpu_to_le16(0x0002); 673 dev->rx_creg |= cpu_to_le16(0x0002);
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
index 4cbb408af727..8a945f4f3693 100644
--- a/drivers/usb/net/usbnet.c
+++ b/drivers/usb/net/usbnet.c
@@ -1429,7 +1429,7 @@ static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1429 info->ether = (void *) buf; 1429 info->ether = (void *) buf;
1430 if (info->ether->bLength != sizeof *info->ether) { 1430 if (info->ether->bLength != sizeof *info->ether) {
1431 dev_dbg (&intf->dev, "CDC ether len %u\n", 1431 dev_dbg (&intf->dev, "CDC ether len %u\n",
1432 info->u->bLength); 1432 info->ether->bLength);
1433 goto bad_desc; 1433 goto bad_desc;
1434 } 1434 }
1435 dev->net->mtu = le16_to_cpup ( 1435 dev->net->mtu = le16_to_cpup (
diff --git a/drivers/usb/net/zd1201.c b/drivers/usb/net/zd1201.c
index 341ae5f732dd..3b387b005739 100644
--- a/drivers/usb/net/zd1201.c
+++ b/drivers/usb/net/zd1201.c
@@ -1884,12 +1884,53 @@ static void zd1201_disconnect(struct usb_interface *interface)
1884 kfree(zd); 1884 kfree(zd);
1885} 1885}
1886 1886
1887#ifdef CONFIG_PM
1888
1889static int zd1201_suspend(struct usb_interface *interface,
1890 pm_message_t message)
1891{
1892 struct zd1201 *zd = usb_get_intfdata(interface);
1893
1894 netif_device_detach(zd->dev);
1895
1896 zd->was_enabled = zd->mac_enabled;
1897
1898 if (zd->was_enabled)
1899 return zd1201_disable(zd);
1900 else
1901 return 0;
1902}
1903
1904static int zd1201_resume(struct usb_interface *interface)
1905{
1906 struct zd1201 *zd = usb_get_intfdata(interface);
1907
1908 if (!zd || !zd->dev)
1909 return -ENODEV;
1910
1911 netif_device_attach(zd->dev);
1912
1913 if (zd->was_enabled)
1914 return zd1201_enable(zd);
1915 else
1916 return 0;
1917}
1918
1919#else
1920
1921#define zd1201_suspend NULL
1922#define zd1201_resume NULL
1923
1924#endif
1925
1887static struct usb_driver zd1201_usb = { 1926static struct usb_driver zd1201_usb = {
1888 .owner = THIS_MODULE, 1927 .owner = THIS_MODULE,
1889 .name = "zd1201", 1928 .name = "zd1201",
1890 .probe = zd1201_probe, 1929 .probe = zd1201_probe,
1891 .disconnect = zd1201_disconnect, 1930 .disconnect = zd1201_disconnect,
1892 .id_table = zd1201_table, 1931 .id_table = zd1201_table,
1932 .suspend = zd1201_suspend,
1933 .resume = zd1201_resume,
1893}; 1934};
1894 1935
1895static int __init zd1201_init(void) 1936static int __init zd1201_init(void)
diff --git a/drivers/usb/net/zd1201.h b/drivers/usb/net/zd1201.h
index 1627c71e8052..235f0ee34b24 100644
--- a/drivers/usb/net/zd1201.h
+++ b/drivers/usb/net/zd1201.h
@@ -46,6 +46,7 @@ struct zd1201 {
46 char essid[IW_ESSID_MAX_SIZE+1]; 46 char essid[IW_ESSID_MAX_SIZE+1];
47 int essidlen; 47 int essidlen;
48 int mac_enabled; 48 int mac_enabled;
49 int was_enabled;
49 int monitor; 50 int monitor;
50 int encode_enabled; 51 int encode_enabled;
51 int encode_restricted; 52 int encode_restricted;
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 46a204cd40e1..b5b431067b08 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -213,10 +213,14 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
213 return (0); 213 return (0);
214 } 214 }
215 215
216 if (port->write_urb->status == -EINPROGRESS) { 216 spin_lock(&port->lock);
217 if (port->write_urb_busy) {
218 spin_unlock(&port->lock);
217 dbg("%s - already writing", __FUNCTION__); 219 dbg("%s - already writing", __FUNCTION__);
218 return (0); 220 return 0;
219 } 221 }
222 port->write_urb_busy = 1;
223 spin_unlock(&port->lock);
220 224
221 spin_lock_irqsave(&priv->lock, flags); 225 spin_lock_irqsave(&priv->lock, flags);
222 226
@@ -224,6 +228,7 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
224 /* To much data for buffer. Reset buffer. */ 228 /* To much data for buffer. Reset buffer. */
225 priv->wrfilled=0; 229 priv->wrfilled=0;
226 spin_unlock_irqrestore(&priv->lock, flags); 230 spin_unlock_irqrestore(&priv->lock, flags);
231 port->write_urb_busy = 0;
227 return (0); 232 return (0);
228 } 233 }
229 234
@@ -268,6 +273,7 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
268 priv->wrfilled=0; 273 priv->wrfilled=0;
269 priv->wrsent=0; 274 priv->wrsent=0;
270 spin_unlock_irqrestore(&priv->lock, flags); 275 spin_unlock_irqrestore(&priv->lock, flags);
276 port->write_urb_busy = 0;
271 return 0; 277 return 0;
272 } 278 }
273 279
@@ -412,7 +418,8 @@ static void cyberjack_write_bulk_callback (struct urb *urb, struct pt_regs *regs
412 struct cyberjack_private *priv = usb_get_serial_port_data(port); 418 struct cyberjack_private *priv = usb_get_serial_port_data(port);
413 419
414 dbg("%s - port %d", __FUNCTION__, port->number); 420 dbg("%s - port %d", __FUNCTION__, port->number);
415 421
422 port->write_urb_busy = 0;
416 if (urb->status) { 423 if (urb->status) {
417 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 424 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
418 return; 425 return;
@@ -424,12 +431,6 @@ static void cyberjack_write_bulk_callback (struct urb *urb, struct pt_regs *regs
424 if( priv->wrfilled ) { 431 if( priv->wrfilled ) {
425 int length, blksize, result; 432 int length, blksize, result;
426 433
427 if (port->write_urb->status == -EINPROGRESS) {
428 dbg("%s - already writing", __FUNCTION__);
429 spin_unlock(&priv->lock);
430 return;
431 }
432
433 dbg("%s - transmitting data (frame n)", __FUNCTION__); 434 dbg("%s - transmitting data (frame n)", __FUNCTION__);
434 435
435 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ? 436 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ?
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 99214aa3cd19..ddde5fb13f6b 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -174,10 +174,14 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
174 174
175 /* only do something if we have a bulk out endpoint */ 175 /* only do something if we have a bulk out endpoint */
176 if (serial->num_bulk_out) { 176 if (serial->num_bulk_out) {
177 if (port->write_urb->status == -EINPROGRESS) { 177 spin_lock(&port->lock);
178 if (port->write_urb_busy) {
179 spin_unlock(&port->lock);
178 dbg("%s - already writing", __FUNCTION__); 180 dbg("%s - already writing", __FUNCTION__);
179 return (0); 181 return 0;
180 } 182 }
183 port->write_urb_busy = 1;
184 spin_unlock(&port->lock);
181 185
182 count = (count > port->bulk_out_size) ? port->bulk_out_size : count; 186 count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
183 187
@@ -195,17 +199,20 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
195 usb_serial_generic_write_bulk_callback), port); 199 usb_serial_generic_write_bulk_callback), port);
196 200
197 /* send the data out the bulk port */ 201 /* send the data out the bulk port */
202 port->write_urb_busy = 1;
198 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 203 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
199 if (result) 204 if (result) {
200 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); 205 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result);
201 else 206 /* don't have to grab the lock here, as we will retry if != 0 */
207 port->write_urb_busy = 0;
208 } else
202 result = count; 209 result = count;
203 210
204 return result; 211 return result;
205 } 212 }
206 213
207 /* no bulk out, so return 0 bytes written */ 214 /* no bulk out, so return 0 bytes written */
208 return (0); 215 return 0;
209} 216}
210 217
211int usb_serial_generic_write_room (struct usb_serial_port *port) 218int usb_serial_generic_write_room (struct usb_serial_port *port)
@@ -214,9 +221,9 @@ int usb_serial_generic_write_room (struct usb_serial_port *port)
214 int room = 0; 221 int room = 0;
215 222
216 dbg("%s - port %d", __FUNCTION__, port->number); 223 dbg("%s - port %d", __FUNCTION__, port->number);
217 224
218 if (serial->num_bulk_out) { 225 if (serial->num_bulk_out) {
219 if (port->write_urb->status != -EINPROGRESS) 226 if (port->write_urb_busy)
220 room = port->bulk_out_size; 227 room = port->bulk_out_size;
221 } 228 }
222 229
@@ -232,7 +239,7 @@ int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port)
232 dbg("%s - port %d", __FUNCTION__, port->number); 239 dbg("%s - port %d", __FUNCTION__, port->number);
233 240
234 if (serial->num_bulk_out) { 241 if (serial->num_bulk_out) {
235 if (port->write_urb->status == -EINPROGRESS) 242 if (port->write_urb_busy)
236 chars = port->write_urb->transfer_buffer_length; 243 chars = port->write_urb->transfer_buffer_length;
237 } 244 }
238 245
@@ -291,6 +298,7 @@ void usb_serial_generic_write_bulk_callback (struct urb *urb, struct pt_regs *re
291 298
292 dbg("%s - port %d", __FUNCTION__, port->number); 299 dbg("%s - port %d", __FUNCTION__, port->number);
293 300
301 port->write_urb_busy = 0;
294 if (urb->status) { 302 if (urb->status) {
295 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 303 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
296 return; 304 return;
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index 3bd69c4ef24b..c05c2a2a0f31 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -818,11 +818,6 @@ static void ipaq_write_gather(struct usb_serial_port *port)
818 struct ipaq_packet *pkt, *tmp; 818 struct ipaq_packet *pkt, *tmp;
819 struct urb *urb = port->write_urb; 819 struct urb *urb = port->write_urb;
820 820
821 if (urb->status == -EINPROGRESS) {
822 /* Should never happen */
823 err("%s - flushing while urb is active !", __FUNCTION__);
824 return;
825 }
826 room = URBDATA_SIZE; 821 room = URBDATA_SIZE;
827 list_for_each_entry_safe(pkt, tmp, &priv->queue, list) { 822 list_for_each_entry_safe(pkt, tmp, &priv->queue, list) {
828 count = min(room, (int)(pkt->len - pkt->written)); 823 count = min(room, (int)(pkt->len - pkt->written));
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index 11105d74f461..85e242459c27 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -399,16 +399,21 @@ static int ipw_write(struct usb_serial_port *port, const unsigned char *buf, int
399 dbg("%s - write request of 0 bytes", __FUNCTION__); 399 dbg("%s - write request of 0 bytes", __FUNCTION__);
400 return 0; 400 return 0;
401 } 401 }
402 402
403 /* Racy and broken, FIXME properly! */ 403 spin_lock(&port->lock);
404 if (port->write_urb->status == -EINPROGRESS) 404 if (port->write_urb_busy) {
405 spin_unlock(&port->lock);
406 dbg("%s - already writing", __FUNCTION__);
405 return 0; 407 return 0;
408 }
409 port->write_urb_busy = 1;
410 spin_unlock(&port->lock);
406 411
407 count = min(count, port->bulk_out_size); 412 count = min(count, port->bulk_out_size);
408 memcpy(port->bulk_out_buffer, buf, count); 413 memcpy(port->bulk_out_buffer, buf, count);
409 414
410 dbg("%s count now:%d", __FUNCTION__, count); 415 dbg("%s count now:%d", __FUNCTION__, count);
411 416
412 usb_fill_bulk_urb(port->write_urb, dev, 417 usb_fill_bulk_urb(port->write_urb, dev,
413 usb_sndbulkpipe(dev, port->bulk_out_endpointAddress), 418 usb_sndbulkpipe(dev, port->bulk_out_endpointAddress),
414 port->write_urb->transfer_buffer, 419 port->write_urb->transfer_buffer,
@@ -418,6 +423,7 @@ static int ipw_write(struct usb_serial_port *port, const unsigned char *buf, int
418 423
419 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC); 424 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
420 if (ret != 0) { 425 if (ret != 0) {
426 port->write_urb_busy = 0;
421 dbg("%s - usb_submit_urb(write bulk) failed with error = %d", __FUNCTION__, ret); 427 dbg("%s - usb_submit_urb(write bulk) failed with error = %d", __FUNCTION__, ret);
422 return ret; 428 return ret;
423 } 429 }
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 59f234df5f89..937b2fdd7171 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -341,10 +341,14 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
341 if (count == 0) 341 if (count == 0)
342 return 0; 342 return 0;
343 343
344 if (port->write_urb->status == -EINPROGRESS) { 344 spin_lock(&port->lock);
345 dbg ("%s - already writing", __FUNCTION__); 345 if (port->write_urb_busy) {
346 spin_unlock(&port->lock);
347 dbg("%s - already writing", __FUNCTION__);
346 return 0; 348 return 0;
347 } 349 }
350 port->write_urb_busy = 1;
351 spin_unlock(&port->lock);
348 352
349 transfer_buffer = port->write_urb->transfer_buffer; 353 transfer_buffer = port->write_urb->transfer_buffer;
350 transfer_size = min(count, port->bulk_out_size - 1); 354 transfer_size = min(count, port->bulk_out_size - 1);
@@ -374,9 +378,10 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
374 port->write_urb->transfer_flags = URB_ZERO_PACKET; 378 port->write_urb->transfer_flags = URB_ZERO_PACKET;
375 379
376 result = usb_submit_urb (port->write_urb, GFP_ATOMIC); 380 result = usb_submit_urb (port->write_urb, GFP_ATOMIC);
377 if (result) 381 if (result) {
382 port->write_urb_busy = 0;
378 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); 383 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result);
379 else 384 } else
380 result = transfer_size; 385 result = transfer_size;
381 386
382 return result; 387 return result;
@@ -387,7 +392,8 @@ static void ir_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
387 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 392 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
388 393
389 dbg("%s - port %d", __FUNCTION__, port->number); 394 dbg("%s - port %d", __FUNCTION__, port->number);
390 395
396 port->write_urb_busy = 0;
391 if (urb->status) { 397 if (urb->status) {
392 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 398 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
393 return; 399 return;
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 7fd0aa9eccf6..635c384cb15a 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -520,9 +520,13 @@ static int keyspan_pda_write(struct usb_serial_port *port,
520 the TX urb is in-flight (wait until it completes) 520 the TX urb is in-flight (wait until it completes)
521 the device is full (wait until it says there is room) 521 the device is full (wait until it says there is room)
522 */ 522 */
523 if (port->write_urb->status == -EINPROGRESS || priv->tx_throttled ) { 523 spin_lock(&port->lock);
524 return( 0 ); 524 if (port->write_urb_busy || priv->tx_throttled) {
525 spin_unlock(&port->lock);
526 return 0;
525 } 527 }
528 port->write_urb_busy = 1;
529 spin_unlock(&port->lock);
526 530
527 /* At this point the URB is in our control, nobody else can submit it 531 /* At this point the URB is in our control, nobody else can submit it
528 again (the only sudden transition was the one from EINPROGRESS to 532 again (the only sudden transition was the one from EINPROGRESS to
@@ -570,7 +574,7 @@ static int keyspan_pda_write(struct usb_serial_port *port,
570 memcpy (port->write_urb->transfer_buffer, buf, count); 574 memcpy (port->write_urb->transfer_buffer, buf, count);
571 /* send the data out the bulk port */ 575 /* send the data out the bulk port */
572 port->write_urb->transfer_buffer_length = count; 576 port->write_urb->transfer_buffer_length = count;
573 577
574 priv->tx_room -= count; 578 priv->tx_room -= count;
575 579
576 port->write_urb->dev = port->serial->dev; 580 port->write_urb->dev = port->serial->dev;
@@ -593,6 +597,8 @@ static int keyspan_pda_write(struct usb_serial_port *port,
593 597
594 rc = count; 598 rc = count;
595exit: 599exit:
600 if (rc < 0)
601 port->write_urb_busy = 0;
596 return rc; 602 return rc;
597} 603}
598 604
@@ -602,6 +608,7 @@ static void keyspan_pda_write_bulk_callback (struct urb *urb, struct pt_regs *re
602 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 608 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
603 struct keyspan_pda_private *priv; 609 struct keyspan_pda_private *priv;
604 610
611 port->write_urb_busy = 0;
605 priv = usb_get_serial_port_data(port); 612 priv = usb_get_serial_port_data(port);
606 613
607 /* queue up a wakeup at scheduler time */ 614 /* queue up a wakeup at scheduler time */
@@ -626,12 +633,12 @@ static int keyspan_pda_write_room (struct usb_serial_port *port)
626static int keyspan_pda_chars_in_buffer (struct usb_serial_port *port) 633static int keyspan_pda_chars_in_buffer (struct usb_serial_port *port)
627{ 634{
628 struct keyspan_pda_private *priv; 635 struct keyspan_pda_private *priv;
629 636
630 priv = usb_get_serial_port_data(port); 637 priv = usb_get_serial_port_data(port);
631 638
632 /* when throttled, return at least WAKEUP_CHARS to tell select() (via 639 /* when throttled, return at least WAKEUP_CHARS to tell select() (via
633 n_tty.c:normal_poll() ) that we're not writeable. */ 640 n_tty.c:normal_poll() ) that we're not writeable. */
634 if( port->write_urb->status == -EINPROGRESS || priv->tx_throttled ) 641 if (port->write_urb_busy || priv->tx_throttled)
635 return 256; 642 return 256;
636 return 0; 643 return 0;
637} 644}
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index b5f2c06d4f3e..6a99ae192df1 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -254,10 +254,15 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
254 dbg("%s - write request of 0 bytes", __FUNCTION__); 254 dbg("%s - write request of 0 bytes", __FUNCTION__);
255 return (0); 255 return (0);
256 } 256 }
257 if (wport->write_urb->status == -EINPROGRESS) { 257
258 spin_lock(&port->lock);
259 if (port->write_urb_busy) {
260 spin_unlock(&port->lock);
258 dbg("%s - already writing", __FUNCTION__); 261 dbg("%s - already writing", __FUNCTION__);
259 return (0); 262 return 0;
260 } 263 }
264 port->write_urb_busy = 1;
265 spin_unlock(&port->lock);
261 266
262 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count; 267 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count;
263 268
@@ -275,9 +280,10 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
275 280
276 wport->write_urb->dev = serial->dev; 281 wport->write_urb->dev = serial->dev;
277 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC); 282 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC);
278 if (result) 283 if (result) {
284 port->write_urb_busy = 0;
279 err("%s - failed submitting write urb, error %d", __FUNCTION__, result); 285 err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
280 else 286 } else
281 result = count; 287 result = count;
282 288
283 return result; 289 return result;
@@ -291,7 +297,7 @@ static int omninet_write_room (struct usb_serial_port *port)
291 297
292 int room = 0; // Default: no room 298 int room = 0; // Default: no room
293 299
294 if (wport->write_urb->status != -EINPROGRESS) 300 if (wport->write_urb_busy)
295 room = wport->bulk_out_size - OMNINET_HEADERLEN; 301 room = wport->bulk_out_size - OMNINET_HEADERLEN;
296 302
297// dbg("omninet_write_room returns %d", room); 303// dbg("omninet_write_room returns %d", room);
@@ -306,6 +312,7 @@ static void omninet_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
306 312
307// dbg("omninet_write_bulk_callback, port %0x\n", port); 313// dbg("omninet_write_bulk_callback, port %0x\n", port);
308 314
315 port->write_urb_busy = 0;
309 if (urb->status) { 316 if (urb->status) {
310 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 317 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
311 return; 318 return;
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 0e85ed6c6c19..96a17568cbf1 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -299,10 +299,14 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
299 dbg ("%s - write request of 0 bytes", __FUNCTION__); 299 dbg ("%s - write request of 0 bytes", __FUNCTION__);
300 return (0); 300 return (0);
301 } 301 }
302 if (port->write_urb->status == -EINPROGRESS) { 302 spin_lock(&port->lock);
303 dbg ("%s - already writing", __FUNCTION__); 303 if (port->write_urb_busy) {
304 return (0); 304 spin_unlock(&port->lock);
305 dbg("%s - already writing", __FUNCTION__);
306 return 0;
305 } 307 }
308 port->write_urb_busy = 1;
309 spin_unlock(&port->lock);
306 310
307 packet_length = port->bulk_out_size; // get max packetsize 311 packet_length = port->bulk_out_size; // get max packetsize
308 312
@@ -354,6 +358,7 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
354#endif 358#endif
355 port->write_urb->dev = port->serial->dev; 359 port->write_urb->dev = port->serial->dev;
356 if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) { 360 if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) {
361 port->write_urb_busy = 0;
357 err ("%s - failed submitting write urb, error %d", __FUNCTION__, result); 362 err ("%s - failed submitting write urb, error %d", __FUNCTION__, result);
358 return 0; 363 return 0;
359 } 364 }
@@ -368,7 +373,7 @@ static int safe_write_room (struct usb_serial_port *port)
368 373
369 dbg ("%s", __FUNCTION__); 374 dbg ("%s", __FUNCTION__);
370 375
371 if (port->write_urb->status != -EINPROGRESS) 376 if (port->write_urb_busy)
372 room = port->bulk_out_size - (safe ? 2 : 0); 377 room = port->bulk_out_size - (safe ? 2 : 0);
373 378
374 if (room) { 379 if (room) {
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 5da76dd8fb28..0267b26dde18 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -1047,6 +1047,7 @@ int usb_serial_probe(struct usb_interface *interface,
1047 memset(port, 0x00, sizeof(struct usb_serial_port)); 1047 memset(port, 0x00, sizeof(struct usb_serial_port));
1048 port->number = i + serial->minor; 1048 port->number = i + serial->minor;
1049 port->serial = serial; 1049 port->serial = serial;
1050 spin_lock_init(&port->lock);
1050 INIT_WORK(&port->work, usb_serial_port_softint, port); 1051 INIT_WORK(&port->work, usb_serial_port_softint, port);
1051 serial->port[i] = port; 1052 serial->port[i] = port;
1052 } 1053 }
diff --git a/drivers/usb/serial/usb-serial.h b/drivers/usb/serial/usb-serial.h
index d1f0c4057fa6..57f92f054c75 100644
--- a/drivers/usb/serial/usb-serial.h
+++ b/drivers/usb/serial/usb-serial.h
@@ -69,6 +69,7 @@
69 * usb_serial_port: structure for the specific ports of a device. 69 * usb_serial_port: structure for the specific ports of a device.
70 * @serial: pointer back to the struct usb_serial owner of this port. 70 * @serial: pointer back to the struct usb_serial owner of this port.
71 * @tty: pointer to the corresponding tty for this port. 71 * @tty: pointer to the corresponding tty for this port.
72 * @lock: spinlock to grab when updating portions of this structure.
72 * @number: the number of the port (the minor number). 73 * @number: the number of the port (the minor number).
73 * @interrupt_in_buffer: pointer to the interrupt in buffer for this port. 74 * @interrupt_in_buffer: pointer to the interrupt in buffer for this port.
74 * @interrupt_in_urb: pointer to the interrupt in struct urb for this port. 75 * @interrupt_in_urb: pointer to the interrupt in struct urb for this port.
@@ -98,6 +99,7 @@
98struct usb_serial_port { 99struct usb_serial_port {
99 struct usb_serial * serial; 100 struct usb_serial * serial;
100 struct tty_struct * tty; 101 struct tty_struct * tty;
102 spinlock_t lock;
101 unsigned char number; 103 unsigned char number;
102 104
103 unsigned char * interrupt_in_buffer; 105 unsigned char * interrupt_in_buffer;
@@ -117,6 +119,7 @@ struct usb_serial_port {
117 unsigned char * bulk_out_buffer; 119 unsigned char * bulk_out_buffer;
118 int bulk_out_size; 120 int bulk_out_size;
119 struct urb * write_urb; 121 struct urb * write_urb;
122 int write_urb_busy;
120 __u8 bulk_out_endpointAddress; 123 __u8 bulk_out_endpointAddress;
121 124
122 wait_queue_head_t write_wait; 125 wait_queue_head_t write_wait;
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index e43eddc3d44b..af294bb68c35 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -155,6 +155,15 @@ static int slave_configure(struct scsi_device *sdev)
155 * If this device makes that mistake, tell the sd driver. */ 155 * If this device makes that mistake, tell the sd driver. */
156 if (us->flags & US_FL_FIX_CAPACITY) 156 if (us->flags & US_FL_FIX_CAPACITY)
157 sdev->fix_capacity = 1; 157 sdev->fix_capacity = 1;
158
159 /* USB-IDE bridges tend to report SK = 0x04 (Non-recoverable
160 * Hardware Error) when any low-level error occurs,
161 * recoverable or not. Setting this flag tells the SCSI
162 * midlayer to retry such commands, which frequently will
163 * succeed and fix the error. The worst this can lead to
164 * is an occasional series of retries that will all fail. */
165 sdev->retry_hwerror = 1;
166
158 } else { 167 } else {
159 168
160 /* Non-disk-type devices don't need to blacklist any pages 169 /* Non-disk-type devices don't need to blacklist any pages
@@ -255,50 +264,23 @@ static int device_reset(struct scsi_cmnd *srb)
255 264
256 /* lock the device pointers and do the reset */ 265 /* lock the device pointers and do the reset */
257 down(&(us->dev_semaphore)); 266 down(&(us->dev_semaphore));
258 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 267 result = us->transport_reset(us);
259 result = FAILED;
260 US_DEBUGP("No reset during disconnect\n");
261 } else
262 result = us->transport_reset(us);
263 up(&(us->dev_semaphore)); 268 up(&(us->dev_semaphore));
264 269
265 return result; 270 return result < 0 ? FAILED : SUCCESS;
266} 271}
267 272
268/* This resets the device's USB port. */ 273/* Simulate a SCSI bus reset by resetting the device's USB port. */
269/* It refuses to work if there's more than one interface in
270 * the device, so that other users are not affected. */
271/* This is always called with scsi_lock(host) held */ 274/* This is always called with scsi_lock(host) held */
272static int bus_reset(struct scsi_cmnd *srb) 275static int bus_reset(struct scsi_cmnd *srb)
273{ 276{
274 struct us_data *us = host_to_us(srb->device->host); 277 struct us_data *us = host_to_us(srb->device->host);
275 int result, rc; 278 int result;
276 279
277 US_DEBUGP("%s called\n", __FUNCTION__); 280 US_DEBUGP("%s called\n", __FUNCTION__);
278 281
279 /* The USB subsystem doesn't handle synchronisation between
280 * a device's several drivers. Therefore we reset only devices
281 * with just one interface, which we of course own. */
282
283 down(&(us->dev_semaphore)); 282 down(&(us->dev_semaphore));
284 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 283 result = usb_stor_port_reset(us);
285 result = -EIO;
286 US_DEBUGP("No reset during disconnect\n");
287 } else if (us->pusb_dev->actconfig->desc.bNumInterfaces != 1) {
288 result = -EBUSY;
289 US_DEBUGP("Refusing to reset a multi-interface device\n");
290 } else {
291 rc = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf);
292 if (rc < 0) {
293 US_DEBUGP("unable to lock device for reset: %d\n", rc);
294 result = rc;
295 } else {
296 result = usb_reset_device(us->pusb_dev);
297 if (rc)
298 usb_unlock_device(us->pusb_dev);
299 US_DEBUGP("usb_reset_device returns %d\n", result);
300 }
301 }
302 up(&(us->dev_semaphore)); 284 up(&(us->dev_semaphore));
303 285
304 /* lock the host for the return */ 286 /* lock the host for the return */
@@ -320,6 +302,14 @@ void usb_stor_report_device_reset(struct us_data *us)
320 } 302 }
321} 303}
322 304
305/* Report a driver-initiated bus reset to the SCSI layer.
306 * Calling this for a SCSI-initiated reset is unnecessary but harmless.
307 * The caller must own the SCSI host lock. */
308void usb_stor_report_bus_reset(struct us_data *us)
309{
310 scsi_report_bus_reset(us_to_host(us), 0);
311}
312
323/*********************************************************************** 313/***********************************************************************
324 * /proc/scsi/ functions 314 * /proc/scsi/ functions
325 ***********************************************************************/ 315 ***********************************************************************/
diff --git a/drivers/usb/storage/scsiglue.h b/drivers/usb/storage/scsiglue.h
index d0a49af026c4..737e4fa6045f 100644
--- a/drivers/usb/storage/scsiglue.h
+++ b/drivers/usb/storage/scsiglue.h
@@ -42,6 +42,7 @@
42#define _SCSIGLUE_H_ 42#define _SCSIGLUE_H_
43 43
44extern void usb_stor_report_device_reset(struct us_data *us); 44extern void usb_stor_report_device_reset(struct us_data *us);
45extern void usb_stor_report_bus_reset(struct us_data *us);
45 46
46extern unsigned char usb_stor_sense_invalidCDB[18]; 47extern unsigned char usb_stor_sense_invalidCDB[18];
47extern struct scsi_host_template usb_stor_host_template; 48extern struct scsi_host_template usb_stor_host_template;
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index 9743e289cd3b..e6b1c6cf07f2 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -266,8 +266,9 @@ int usb_stor_clear_halt(struct us_data *us, unsigned int pipe)
266 NULL, 0, 3*HZ); 266 NULL, 0, 3*HZ);
267 267
268 /* reset the endpoint toggle */ 268 /* reset the endpoint toggle */
269 usb_settoggle(us->pusb_dev, usb_pipeendpoint(pipe), 269 if (result >= 0)
270 usb_pipeout(pipe), 0); 270 usb_settoggle(us->pusb_dev, usb_pipeendpoint(pipe),
271 usb_pipeout(pipe), 0);
271 272
272 US_DEBUGP("%s: result = %d\n", __FUNCTION__, result); 273 US_DEBUGP("%s: result = %d\n", __FUNCTION__, result);
273 return result; 274 return result;
@@ -540,15 +541,15 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
540 */ 541 */
541 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 542 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
542 US_DEBUGP("-- command was aborted\n"); 543 US_DEBUGP("-- command was aborted\n");
543 goto Handle_Abort; 544 srb->result = DID_ABORT << 16;
545 goto Handle_Errors;
544 } 546 }
545 547
546 /* if there is a transport error, reset and don't auto-sense */ 548 /* if there is a transport error, reset and don't auto-sense */
547 if (result == USB_STOR_TRANSPORT_ERROR) { 549 if (result == USB_STOR_TRANSPORT_ERROR) {
548 US_DEBUGP("-- transport indicates error, resetting\n"); 550 US_DEBUGP("-- transport indicates error, resetting\n");
549 us->transport_reset(us);
550 srb->result = DID_ERROR << 16; 551 srb->result = DID_ERROR << 16;
551 return; 552 goto Handle_Errors;
552 } 553 }
553 554
554 /* if the transport provided its own sense data, don't auto-sense */ 555 /* if the transport provided its own sense data, don't auto-sense */
@@ -668,7 +669,8 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
668 669
669 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 670 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
670 US_DEBUGP("-- auto-sense aborted\n"); 671 US_DEBUGP("-- auto-sense aborted\n");
671 goto Handle_Abort; 672 srb->result = DID_ABORT << 16;
673 goto Handle_Errors;
672 } 674 }
673 if (temp_result != USB_STOR_TRANSPORT_GOOD) { 675 if (temp_result != USB_STOR_TRANSPORT_GOOD) {
674 US_DEBUGP("-- auto-sense failure\n"); 676 US_DEBUGP("-- auto-sense failure\n");
@@ -677,9 +679,9 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
677 * multi-target device, since failure of an 679 * multi-target device, since failure of an
678 * auto-sense is perfectly valid 680 * auto-sense is perfectly valid
679 */ 681 */
680 if (!(us->flags & US_FL_SCM_MULT_TARG))
681 us->transport_reset(us);
682 srb->result = DID_ERROR << 16; 682 srb->result = DID_ERROR << 16;
683 if (!(us->flags & US_FL_SCM_MULT_TARG))
684 goto Handle_Errors;
683 return; 685 return;
684 } 686 }
685 687
@@ -720,12 +722,28 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
720 722
721 return; 723 return;
722 724
723 /* abort processing: the bulk-only transport requires a reset 725 /* Error and abort processing: try to resynchronize with the device
724 * following an abort */ 726 * by issuing a port reset. If that fails, try a class-specific
725 Handle_Abort: 727 * device reset. */
726 srb->result = DID_ABORT << 16; 728 Handle_Errors:
727 if (us->protocol == US_PR_BULK) 729
730 /* Let the SCSI layer know we are doing a reset, set the
731 * RESETTING bit, and clear the ABORTING bit so that the reset
732 * may proceed. */
733 scsi_lock(us_to_host(us));
734 usb_stor_report_bus_reset(us);
735 set_bit(US_FLIDX_RESETTING, &us->flags);
736 clear_bit(US_FLIDX_ABORTING, &us->flags);
737 scsi_unlock(us_to_host(us));
738
739 result = usb_stor_port_reset(us);
740 if (result < 0) {
741 scsi_lock(us_to_host(us));
742 usb_stor_report_device_reset(us);
743 scsi_unlock(us_to_host(us));
728 us->transport_reset(us); 744 us->transport_reset(us);
745 }
746 clear_bit(US_FLIDX_RESETTING, &us->flags);
729} 747}
730 748
731/* Stop the current URB transfer */ 749/* Stop the current URB transfer */
@@ -1124,7 +1142,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1124 * It's handy that every transport mechanism uses the control endpoint for 1142 * It's handy that every transport mechanism uses the control endpoint for
1125 * resets. 1143 * resets.
1126 * 1144 *
1127 * Basically, we send a reset with a 20-second timeout, so we don't get 1145 * Basically, we send a reset with a 5-second timeout, so we don't get
1128 * jammed attempting to do the reset. 1146 * jammed attempting to do the reset.
1129 */ 1147 */
1130static int usb_stor_reset_common(struct us_data *us, 1148static int usb_stor_reset_common(struct us_data *us,
@@ -1133,28 +1151,18 @@ static int usb_stor_reset_common(struct us_data *us,
1133{ 1151{
1134 int result; 1152 int result;
1135 int result2; 1153 int result2;
1136 int rc = FAILED;
1137 1154
1138 /* Let the SCSI layer know we are doing a reset, set the 1155 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
1139 * RESETTING bit, and clear the ABORTING bit so that the reset 1156 US_DEBUGP("No reset during disconnect\n");
1140 * may proceed. 1157 return -EIO;
1141 */ 1158 }
1142 scsi_lock(us_to_host(us));
1143 usb_stor_report_device_reset(us);
1144 set_bit(US_FLIDX_RESETTING, &us->flags);
1145 clear_bit(US_FLIDX_ABORTING, &us->flags);
1146 scsi_unlock(us_to_host(us));
1147 1159
1148 /* A 20-second timeout may seem rather long, but a LaCie
1149 * StudioDrive USB2 device takes 16+ seconds to get going
1150 * following a powerup or USB attach event.
1151 */
1152 result = usb_stor_control_msg(us, us->send_ctrl_pipe, 1160 result = usb_stor_control_msg(us, us->send_ctrl_pipe,
1153 request, requesttype, value, index, data, size, 1161 request, requesttype, value, index, data, size,
1154 20*HZ); 1162 5*HZ);
1155 if (result < 0) { 1163 if (result < 0) {
1156 US_DEBUGP("Soft reset failed: %d\n", result); 1164 US_DEBUGP("Soft reset failed: %d\n", result);
1157 goto Done; 1165 return result;
1158 } 1166 }
1159 1167
1160 /* Give the device some time to recover from the reset, 1168 /* Give the device some time to recover from the reset,
@@ -1164,7 +1172,7 @@ static int usb_stor_reset_common(struct us_data *us,
1164 HZ*6); 1172 HZ*6);
1165 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 1173 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
1166 US_DEBUGP("Reset interrupted by disconnect\n"); 1174 US_DEBUGP("Reset interrupted by disconnect\n");
1167 goto Done; 1175 return -EIO;
1168 } 1176 }
1169 1177
1170 US_DEBUGP("Soft reset: clearing bulk-in endpoint halt\n"); 1178 US_DEBUGP("Soft reset: clearing bulk-in endpoint halt\n");
@@ -1173,17 +1181,14 @@ static int usb_stor_reset_common(struct us_data *us,
1173 US_DEBUGP("Soft reset: clearing bulk-out endpoint halt\n"); 1181 US_DEBUGP("Soft reset: clearing bulk-out endpoint halt\n");
1174 result2 = usb_stor_clear_halt(us, us->send_bulk_pipe); 1182 result2 = usb_stor_clear_halt(us, us->send_bulk_pipe);
1175 1183
1176 /* return a result code based on the result of the control message */ 1184 /* return a result code based on the result of the clear-halts */
1177 if (result < 0 || result2 < 0) { 1185 if (result >= 0)
1186 result = result2;
1187 if (result < 0)
1178 US_DEBUGP("Soft reset failed\n"); 1188 US_DEBUGP("Soft reset failed\n");
1179 goto Done; 1189 else
1180 } 1190 US_DEBUGP("Soft reset done\n");
1181 US_DEBUGP("Soft reset done\n"); 1191 return result;
1182 rc = SUCCESS;
1183
1184 Done:
1185 clear_bit(US_FLIDX_RESETTING, &us->flags);
1186 return rc;
1187} 1192}
1188 1193
1189/* This issues a CB[I] Reset to the device in question 1194/* This issues a CB[I] Reset to the device in question
@@ -1213,3 +1218,32 @@ int usb_stor_Bulk_reset(struct us_data *us)
1213 USB_TYPE_CLASS | USB_RECIP_INTERFACE, 1218 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1214 0, us->ifnum, NULL, 0); 1219 0, us->ifnum, NULL, 0);
1215} 1220}
1221
1222/* Issue a USB port reset to the device. But don't do anything if
1223 * there's more than one interface in the device, so that other users
1224 * are not affected. */
1225int usb_stor_port_reset(struct us_data *us)
1226{
1227 int result, rc;
1228
1229 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
1230 result = -EIO;
1231 US_DEBUGP("No reset during disconnect\n");
1232 } else if (us->pusb_dev->actconfig->desc.bNumInterfaces != 1) {
1233 result = -EBUSY;
1234 US_DEBUGP("Refusing to reset a multi-interface device\n");
1235 } else {
1236 result = rc =
1237 usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf);
1238 if (result < 0) {
1239 US_DEBUGP("unable to lock device for reset: %d\n",
1240 result);
1241 } else {
1242 result = usb_reset_device(us->pusb_dev);
1243 if (rc)
1244 usb_unlock_device(us->pusb_dev);
1245 US_DEBUGP("usb_reset_device returns %d\n", result);
1246 }
1247 }
1248 return result;
1249}
diff --git a/drivers/usb/storage/transport.h b/drivers/usb/storage/transport.h
index e25f8d8fc741..8d9e0663f8fe 100644
--- a/drivers/usb/storage/transport.h
+++ b/drivers/usb/storage/transport.h
@@ -171,4 +171,5 @@ extern int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
171extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe, 171extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe,
172 void *buf, unsigned int length, int use_sg, int *residual); 172 void *buf, unsigned int length, int use_sg, int *residual);
173 173
174extern int usb_stor_port_reset(struct us_data *us);
174#endif 175#endif
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 9789115980a5..7bc1d44d8814 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -350,10 +350,8 @@ static int default_vmode __initdata = VMODE_1024_768_60;
350static int default_cmode __initdata = CMODE_8; 350static int default_cmode __initdata = CMODE_8;
351#endif 351#endif
352 352
353#ifdef CONFIG_PMAC_PBOOK
354static int default_crt_on __initdata = 0; 353static int default_crt_on __initdata = 0;
355static int default_lcd_on __initdata = 1; 354static int default_lcd_on __initdata = 1;
356#endif
357 355
358#ifdef CONFIG_MTRR 356#ifdef CONFIG_MTRR
359static int mtrr = 1; 357static int mtrr = 1;
@@ -1249,7 +1247,6 @@ static int aty128_crtc_to_var(const struct aty128_crtc *crtc,
1249 return 0; 1247 return 0;
1250} 1248}
1251 1249
1252#ifdef CONFIG_PMAC_PBOOK
1253static void aty128_set_crt_enable(struct aty128fb_par *par, int on) 1250static void aty128_set_crt_enable(struct aty128fb_par *par, int on)
1254{ 1251{
1255 if (on) { 1252 if (on) {
@@ -1284,7 +1281,6 @@ static void aty128_set_lcd_enable(struct aty128fb_par *par, int on)
1284 aty_st_le32(LVDS_GEN_CNTL, reg); 1281 aty_st_le32(LVDS_GEN_CNTL, reg);
1285 } 1282 }
1286} 1283}
1287#endif /* CONFIG_PMAC_PBOOK */
1288 1284
1289static void aty128_set_pll(struct aty128_pll *pll, const struct aty128fb_par *par) 1285static void aty128_set_pll(struct aty128_pll *pll, const struct aty128fb_par *par)
1290{ 1286{
@@ -1491,12 +1487,10 @@ static int aty128fb_set_par(struct fb_info *info)
1491 info->fix.visual = par->crtc.bpp == 8 ? FB_VISUAL_PSEUDOCOLOR 1487 info->fix.visual = par->crtc.bpp == 8 ? FB_VISUAL_PSEUDOCOLOR
1492 : FB_VISUAL_DIRECTCOLOR; 1488 : FB_VISUAL_DIRECTCOLOR;
1493 1489
1494#ifdef CONFIG_PMAC_PBOOK
1495 if (par->chip_gen == rage_M3) { 1490 if (par->chip_gen == rage_M3) {
1496 aty128_set_crt_enable(par, par->crt_on); 1491 aty128_set_crt_enable(par, par->crt_on);
1497 aty128_set_lcd_enable(par, par->lcd_on); 1492 aty128_set_lcd_enable(par, par->lcd_on);
1498 } 1493 }
1499#endif
1500 if (par->accel_flags & FB_ACCELF_TEXT) 1494 if (par->accel_flags & FB_ACCELF_TEXT)
1501 aty128_init_engine(par); 1495 aty128_init_engine(par);
1502 1496
@@ -1652,7 +1646,6 @@ static int __init aty128fb_setup(char *options)
1652 return 0; 1646 return 0;
1653 1647
1654 while ((this_opt = strsep(&options, ",")) != NULL) { 1648 while ((this_opt = strsep(&options, ",")) != NULL) {
1655#ifdef CONFIG_PMAC_PBOOK
1656 if (!strncmp(this_opt, "lcd:", 4)) { 1649 if (!strncmp(this_opt, "lcd:", 4)) {
1657 default_lcd_on = simple_strtoul(this_opt+4, NULL, 0); 1650 default_lcd_on = simple_strtoul(this_opt+4, NULL, 0);
1658 continue; 1651 continue;
@@ -1660,7 +1653,6 @@ static int __init aty128fb_setup(char *options)
1660 default_crt_on = simple_strtoul(this_opt+4, NULL, 0); 1653 default_crt_on = simple_strtoul(this_opt+4, NULL, 0);
1661 continue; 1654 continue;
1662 } 1655 }
1663#endif
1664#ifdef CONFIG_MTRR 1656#ifdef CONFIG_MTRR
1665 if(!strncmp(this_opt, "nomtrr", 6)) { 1657 if(!strncmp(this_opt, "nomtrr", 6)) {
1666 mtrr = 0; 1658 mtrr = 0;
@@ -1752,10 +1744,8 @@ static int __init aty128_init(struct pci_dev *pdev, const struct pci_device_id *
1752 info->fbops = &aty128fb_ops; 1744 info->fbops = &aty128fb_ops;
1753 info->flags = FBINFO_FLAG_DEFAULT; 1745 info->flags = FBINFO_FLAG_DEFAULT;
1754 1746
1755#ifdef CONFIG_PMAC_PBOOK
1756 par->lcd_on = default_lcd_on; 1747 par->lcd_on = default_lcd_on;
1757 par->crt_on = default_crt_on; 1748 par->crt_on = default_crt_on;
1758#endif
1759 1749
1760 var = default_var; 1750 var = default_var;
1761#ifdef CONFIG_PPC_PMAC 1751#ifdef CONFIG_PPC_PMAC
@@ -2035,12 +2025,10 @@ static int aty128fb_blank(int blank, struct fb_info *fb)
2035 2025
2036 aty_st_8(CRTC_EXT_CNTL+1, state); 2026 aty_st_8(CRTC_EXT_CNTL+1, state);
2037 2027
2038#ifdef CONFIG_PMAC_PBOOK
2039 if (par->chip_gen == rage_M3) { 2028 if (par->chip_gen == rage_M3) {
2040 aty128_set_crt_enable(par, par->crt_on && !blank); 2029 aty128_set_crt_enable(par, par->crt_on && !blank);
2041 aty128_set_lcd_enable(par, par->lcd_on && !blank); 2030 aty128_set_lcd_enable(par, par->lcd_on && !blank);
2042 } 2031 }
2043#endif
2044#ifdef CONFIG_PMAC_BACKLIGHT 2032#ifdef CONFIG_PMAC_BACKLIGHT
2045 if ((_machine == _MACH_Pmac) && !blank) 2033 if ((_machine == _MACH_Pmac) && !blank)
2046 set_backlight_enable(1); 2034 set_backlight_enable(1);
@@ -2124,7 +2112,6 @@ static int aty128fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
2124static int aty128fb_ioctl(struct inode *inode, struct file *file, u_int cmd, 2112static int aty128fb_ioctl(struct inode *inode, struct file *file, u_int cmd,
2125 u_long arg, struct fb_info *info) 2113 u_long arg, struct fb_info *info)
2126{ 2114{
2127#ifdef CONFIG_PMAC_PBOOK
2128 struct aty128fb_par *par = info->par; 2115 struct aty128fb_par *par = info->par;
2129 u32 value; 2116 u32 value;
2130 int rc; 2117 int rc;
@@ -2149,7 +2136,6 @@ static int aty128fb_ioctl(struct inode *inode, struct file *file, u_int cmd,
2149 value = (par->crt_on << 1) | par->lcd_on; 2136 value = (par->crt_on << 1) | par->lcd_on;
2150 return put_user(value, (__u32 __user *)arg); 2137 return put_user(value, (__u32 __user *)arg);
2151 } 2138 }
2152#endif
2153 return -EINVAL; 2139 return -EINVAL;
2154} 2140}
2155 2141
diff --git a/drivers/video/chipsfb.c b/drivers/video/chipsfb.c
index 95e72550d43f..e75a965ec760 100644
--- a/drivers/video/chipsfb.c
+++ b/drivers/video/chipsfb.c
@@ -28,22 +28,17 @@
28#include <linux/fb.h> 28#include <linux/fb.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/pci.h> 30#include <linux/pci.h>
31#include <linux/console.h>
31#include <asm/io.h> 32#include <asm/io.h>
32 33
33#ifdef CONFIG_PMAC_BACKLIGHT 34#ifdef CONFIG_PMAC_BACKLIGHT
34#include <asm/backlight.h> 35#include <asm/backlight.h>
35#endif 36#endif
36#ifdef CONFIG_PMAC_PBOOK
37#include <linux/adb.h>
38#include <linux/pmu.h>
39#endif
40 37
41/* 38/*
42 * Since we access the display with inb/outb to fixed port numbers, 39 * Since we access the display with inb/outb to fixed port numbers,
43 * we can only handle one 6555x chip. -- paulus 40 * we can only handle one 6555x chip. -- paulus
44 */ 41 */
45static struct fb_info chipsfb_info;
46
47#define write_ind(num, val, ap, dp) do { \ 42#define write_ind(num, val, ap, dp) do { \
48 outb((num), (ap)); outb((val), (dp)); \ 43 outb((num), (ap)); outb((val), (dp)); \
49} while (0) 44} while (0)
@@ -74,14 +69,6 @@ static struct fb_info chipsfb_info;
74 inb(0x3da); read_ind(num, var, 0x3c0, 0x3c1); \ 69 inb(0x3da); read_ind(num, var, 0x3c0, 0x3c1); \
75} while (0) 70} while (0)
76 71
77#ifdef CONFIG_PMAC_PBOOK
78static unsigned char *save_framebuffer;
79int chips_sleep_notify(struct pmu_sleep_notifier *self, int when);
80static struct pmu_sleep_notifier chips_sleep_notifier = {
81 chips_sleep_notify, SLEEP_LEVEL_VIDEO,
82};
83#endif
84
85/* 72/*
86 * Exported functions 73 * Exported functions
87 */ 74 */
@@ -356,6 +343,8 @@ static struct fb_var_screeninfo chipsfb_var __initdata = {
356 343
357static void __init init_chips(struct fb_info *p, unsigned long addr) 344static void __init init_chips(struct fb_info *p, unsigned long addr)
358{ 345{
346 memset(p->screen_base, 0, 0x100000);
347
359 p->fix = chipsfb_fix; 348 p->fix = chipsfb_fix;
360 p->fix.smem_start = addr; 349 p->fix.smem_start = addr;
361 350
@@ -366,34 +355,41 @@ static void __init init_chips(struct fb_info *p, unsigned long addr)
366 355
367 fb_alloc_cmap(&p->cmap, 256, 0); 356 fb_alloc_cmap(&p->cmap, 256, 0);
368 357
369 if (register_framebuffer(p) < 0) {
370 printk(KERN_ERR "C&T 65550 framebuffer failed to register\n");
371 return;
372 }
373
374 printk(KERN_INFO "fb%d: Chips 65550 frame buffer (%dK RAM detected)\n",
375 p->node, p->fix.smem_len / 1024);
376
377 chips_hw_init(); 358 chips_hw_init();
378} 359}
379 360
380static int __devinit 361static int __devinit
381chipsfb_pci_init(struct pci_dev *dp, const struct pci_device_id *ent) 362chipsfb_pci_init(struct pci_dev *dp, const struct pci_device_id *ent)
382{ 363{
383 struct fb_info *p = &chipsfb_info; 364 struct fb_info *p;
384 unsigned long addr, size; 365 unsigned long addr, size;
385 unsigned short cmd; 366 unsigned short cmd;
367 int rc = -ENODEV;
368
369 if (pci_enable_device(dp) < 0) {
370 dev_err(&dp->dev, "Cannot enable PCI device\n");
371 goto err_out;
372 }
386 373
387 if ((dp->resource[0].flags & IORESOURCE_MEM) == 0) 374 if ((dp->resource[0].flags & IORESOURCE_MEM) == 0)
388 return -ENODEV; 375 goto err_disable;
389 addr = pci_resource_start(dp, 0); 376 addr = pci_resource_start(dp, 0);
390 size = pci_resource_len(dp, 0); 377 size = pci_resource_len(dp, 0);
391 if (addr == 0) 378 if (addr == 0)
392 return -ENODEV; 379 goto err_disable;
393 if (p->screen_base != 0) 380
394 return -EBUSY; 381 p = framebuffer_alloc(0, &dp->dev);
395 if (!request_mem_region(addr, size, "chipsfb")) 382 if (p == NULL) {
396 return -EBUSY; 383 dev_err(&dp->dev, "Cannot allocate framebuffer structure\n");
384 rc = -ENOMEM;
385 goto err_disable;
386 }
387
388 if (pci_request_region(dp, 0, "chipsfb") != 0) {
389 dev_err(&dp->dev, "Cannot request framebuffer\n");
390 rc = -EBUSY;
391 goto err_release_fb;
392 }
397 393
398#ifdef __BIG_ENDIAN 394#ifdef __BIG_ENDIAN
399 addr += 0x800000; // Use big-endian aperture 395 addr += 0x800000; // Use big-endian aperture
@@ -411,37 +407,89 @@ chipsfb_pci_init(struct pci_dev *dp, const struct pci_device_id *ent)
411 set_backlight_enable(1); 407 set_backlight_enable(1);
412#endif /* CONFIG_PMAC_BACKLIGHT */ 408#endif /* CONFIG_PMAC_BACKLIGHT */
413 409
410#ifdef CONFIG_PPC
414 p->screen_base = __ioremap(addr, 0x200000, _PAGE_NO_CACHE); 411 p->screen_base = __ioremap(addr, 0x200000, _PAGE_NO_CACHE);
412#else
413 p->screen_base = ioremap(addr, 0x200000);
414#endif
415 if (p->screen_base == NULL) { 415 if (p->screen_base == NULL) {
416 release_mem_region(addr, size); 416 dev_err(&dp->dev, "Cannot map framebuffer\n");
417 return -ENOMEM; 417 rc = -ENOMEM;
418 goto err_release_pci;
418 } 419 }
420
421 pci_set_drvdata(dp, p);
419 p->device = &dp->dev; 422 p->device = &dp->dev;
423
420 init_chips(p, addr); 424 init_chips(p, addr);
421 425
422#ifdef CONFIG_PMAC_PBOOK 426 if (register_framebuffer(p) < 0) {
423 pmu_register_sleep_notifier(&chips_sleep_notifier); 427 dev_err(&dp->dev,"C&T 65550 framebuffer failed to register\n");
424#endif /* CONFIG_PMAC_PBOOK */ 428 goto err_unmap;
429 }
430
431 dev_info(&dp->dev,"fb%d: Chips 65550 frame buffer"
432 " (%dK RAM detected)\n",
433 p->node, p->fix.smem_len / 1024);
425 434
426 pci_set_drvdata(dp, p);
427 return 0; 435 return 0;
436
437 err_unmap:
438 iounmap(p->screen_base);
439 err_release_pci:
440 pci_release_region(dp, 0);
441 err_release_fb:
442 framebuffer_release(p);
443 err_disable:
444 err_out:
445 return rc;
428} 446}
429 447
430static void __devexit chipsfb_remove(struct pci_dev *dp) 448static void __devexit chipsfb_remove(struct pci_dev *dp)
431{ 449{
432 struct fb_info *p = pci_get_drvdata(dp); 450 struct fb_info *p = pci_get_drvdata(dp);
433 451
434 if (p != &chipsfb_info || p->screen_base == NULL) 452 if (p->screen_base == NULL)
435 return; 453 return;
436 unregister_framebuffer(p); 454 unregister_framebuffer(p);
437 iounmap(p->screen_base); 455 iounmap(p->screen_base);
438 p->screen_base = NULL; 456 p->screen_base = NULL;
439 release_mem_region(pci_resource_start(dp, 0), pci_resource_len(dp, 0)); 457 pci_release_region(dp, 0);
458}
459
460#ifdef CONFIG_PM
461static int chipsfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
462{
463 struct fb_info *p = pci_get_drvdata(pdev);
464
465 if (state == pdev->dev.power.power_state)
466 return 0;
467 if (state != PM_SUSPEND_MEM)
468 goto done;
469
470 acquire_console_sem();
471 chipsfb_blank(1, p);
472 fb_set_suspend(p, 1);
473 release_console_sem();
474 done:
475 pdev->dev.power.power_state = state;
476 return 0;
477}
478
479static int chipsfb_pci_resume(struct pci_dev *pdev)
480{
481 struct fb_info *p = pci_get_drvdata(pdev);
440 482
441#ifdef CONFIG_PMAC_PBOOK 483 acquire_console_sem();
442 pmu_unregister_sleep_notifier(&chips_sleep_notifier); 484 fb_set_suspend(p, 0);
443#endif /* CONFIG_PMAC_PBOOK */ 485 chipsfb_blank(0, p);
486 release_console_sem();
487
488 pdev->dev.power.power_state = PMSG_ON;
489 return 0;
444} 490}
491#endif /* CONFIG_PM */
492
445 493
446static struct pci_device_id chipsfb_pci_tbl[] = { 494static struct pci_device_id chipsfb_pci_tbl[] = {
447 { PCI_VENDOR_ID_CT, PCI_DEVICE_ID_CT_65550, PCI_ANY_ID, PCI_ANY_ID }, 495 { PCI_VENDOR_ID_CT, PCI_DEVICE_ID_CT_65550, PCI_ANY_ID, PCI_ANY_ID },
@@ -455,6 +503,10 @@ static struct pci_driver chipsfb_driver = {
455 .id_table = chipsfb_pci_tbl, 503 .id_table = chipsfb_pci_tbl,
456 .probe = chipsfb_pci_init, 504 .probe = chipsfb_pci_init,
457 .remove = __devexit_p(chipsfb_remove), 505 .remove = __devexit_p(chipsfb_remove),
506#ifdef CONFIG_PM
507 .suspend = chipsfb_pci_suspend,
508 .resume = chipsfb_pci_resume,
509#endif
458}; 510};
459 511
460int __init chips_init(void) 512int __init chips_init(void)
@@ -472,48 +524,4 @@ static void __exit chipsfb_exit(void)
472 pci_unregister_driver(&chipsfb_driver); 524 pci_unregister_driver(&chipsfb_driver);
473} 525}
474 526
475#ifdef CONFIG_PMAC_PBOOK
476/*
477 * Save the contents of the frame buffer when we go to sleep,
478 * and restore it when we wake up again.
479 */
480int
481chips_sleep_notify(struct pmu_sleep_notifier *self, int when)
482{
483 struct fb_info *p = &chipsfb_info;
484 int nb = p->var.yres * p->fix.line_length;
485
486 if (p->screen_base == NULL)
487 return PBOOK_SLEEP_OK;
488
489 switch (when) {
490 case PBOOK_SLEEP_REQUEST:
491 save_framebuffer = vmalloc(nb);
492 if (save_framebuffer == NULL)
493 return PBOOK_SLEEP_REFUSE;
494 break;
495 case PBOOK_SLEEP_REJECT:
496 if (save_framebuffer) {
497 vfree(save_framebuffer);
498 save_framebuffer = NULL;
499 }
500 break;
501 case PBOOK_SLEEP_NOW:
502 chipsfb_blank(1, p);
503 if (save_framebuffer)
504 memcpy(save_framebuffer, p->screen_base, nb);
505 break;
506 case PBOOK_WAKE:
507 if (save_framebuffer) {
508 memcpy(p->screen_base, save_framebuffer, nb);
509 vfree(save_framebuffer);
510 save_framebuffer = NULL;
511 }
512 chipsfb_blank(0, p);
513 break;
514 }
515 return PBOOK_SLEEP_OK;
516}
517#endif /* CONFIG_PMAC_PBOOK */
518
519MODULE_LICENSE("GPL"); 527MODULE_LICENSE("GPL");
diff --git a/fs/Makefile b/fs/Makefile
index fc92e59e9faf..20edcf28bfd2 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -10,6 +10,7 @@ obj-y := open.o read_write.o file_table.o buffer.o bio.o super.o \
10 ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \ 10 ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \
11 attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \ 11 attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \
12 seq_file.o xattr.o libfs.o fs-writeback.o mpage.o direct-io.o \ 12 seq_file.o xattr.o libfs.o fs-writeback.o mpage.o direct-io.o \
13 ioprio.o
13 14
14obj-$(CONFIG_EPOLL) += eventpoll.o 15obj-$(CONFIG_EPOLL) += eventpoll.o
15obj-$(CONFIG_COMPAT) += compat.o 16obj-$(CONFIG_COMPAT) += compat.o
diff --git a/fs/aio.c b/fs/aio.c
index 7afa222f6802..06d7d4390fe7 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -58,6 +58,7 @@ static DEFINE_SPINLOCK(fput_lock);
58static LIST_HEAD(fput_head); 58static LIST_HEAD(fput_head);
59 59
60static void aio_kick_handler(void *); 60static void aio_kick_handler(void *);
61static void aio_queue_work(struct kioctx *);
61 62
62/* aio_setup 63/* aio_setup
63 * Creates the slab caches used by the aio routines, panic on 64 * Creates the slab caches used by the aio routines, panic on
@@ -747,6 +748,14 @@ out:
747 * has already been kicked */ 748 * has already been kicked */
748 if (kiocbIsKicked(iocb)) { 749 if (kiocbIsKicked(iocb)) {
749 __queue_kicked_iocb(iocb); 750 __queue_kicked_iocb(iocb);
751
752 /*
753 * __queue_kicked_iocb will always return 1 here, because
754 * iocb->ki_run_list is empty at this point so it should
755 * be safe to unconditionally queue the context into the
756 * work queue.
757 */
758 aio_queue_work(ctx);
750 } 759 }
751 } 760 }
752 return ret; 761 return ret;
diff --git a/fs/buffer.c b/fs/buffer.c
index 13e5938a64f6..561e63a14966 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -278,7 +278,7 @@ EXPORT_SYMBOL(thaw_bdev);
278 */ 278 */
279static void do_sync(unsigned long wait) 279static void do_sync(unsigned long wait)
280{ 280{
281 wakeup_bdflush(0); 281 wakeup_pdflush(0);
282 sync_inodes(0); /* All mappings, inodes and their blockdevs */ 282 sync_inodes(0); /* All mappings, inodes and their blockdevs */
283 DQUOT_SYNC(NULL); 283 DQUOT_SYNC(NULL);
284 sync_supers(); /* Write the superblocks */ 284 sync_supers(); /* Write the superblocks */
@@ -497,7 +497,7 @@ static void free_more_memory(void)
497 struct zone **zones; 497 struct zone **zones;
498 pg_data_t *pgdat; 498 pg_data_t *pgdat;
499 499
500 wakeup_bdflush(1024); 500 wakeup_pdflush(1024);
501 yield(); 501 yield();
502 502
503 for_each_pgdat(pgdat) { 503 for_each_pgdat(pgdat) {
diff --git a/fs/char_dev.c b/fs/char_dev.c
index e82aac9cc2f5..a69a5d8a406f 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -150,7 +150,7 @@ __unregister_chrdev_region(unsigned major, unsigned baseminor, int minorct)
150 struct char_device_struct *cd = NULL, **cp; 150 struct char_device_struct *cd = NULL, **cp;
151 int i = major_to_index(major); 151 int i = major_to_index(major);
152 152
153 up(&chrdevs_lock); 153 down(&chrdevs_lock);
154 for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next) 154 for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next)
155 if ((*cp)->major == major && 155 if ((*cp)->major == major &&
156 (*cp)->baseminor == baseminor && 156 (*cp)->baseminor == baseminor &&
diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
index ccd632fcc6d8..e463dca008e4 100644
--- a/fs/ext3/balloc.c
+++ b/fs/ext3/balloc.c
@@ -749,24 +749,24 @@ fail_access:
749 * to find a free region that is of my size and has not 749 * to find a free region that is of my size and has not
750 * been reserved. 750 * been reserved.
751 * 751 *
752 * on succeed, it returns the reservation window to be appended to.
753 * failed, return NULL.
754 */ 752 */
755static struct ext3_reserve_window_node *find_next_reservable_window( 753static int find_next_reservable_window(
756 struct ext3_reserve_window_node *search_head, 754 struct ext3_reserve_window_node *search_head,
757 unsigned long size, int *start_block, 755 struct ext3_reserve_window_node *my_rsv,
756 struct super_block * sb, int start_block,
758 int last_block) 757 int last_block)
759{ 758{
760 struct rb_node *next; 759 struct rb_node *next;
761 struct ext3_reserve_window_node *rsv, *prev; 760 struct ext3_reserve_window_node *rsv, *prev;
762 int cur; 761 int cur;
762 int size = my_rsv->rsv_goal_size;
763 763
764 /* TODO: make the start of the reservation window byte-aligned */ 764 /* TODO: make the start of the reservation window byte-aligned */
765 /* cur = *start_block & ~7;*/ 765 /* cur = *start_block & ~7;*/
766 cur = *start_block; 766 cur = start_block;
767 rsv = search_head; 767 rsv = search_head;
768 if (!rsv) 768 if (!rsv)
769 return NULL; 769 return -1;
770 770
771 while (1) { 771 while (1) {
772 if (cur <= rsv->rsv_end) 772 if (cur <= rsv->rsv_end)
@@ -782,11 +782,11 @@ static struct ext3_reserve_window_node *find_next_reservable_window(
782 * space with expected-size (or more)... 782 * space with expected-size (or more)...
783 */ 783 */
784 if (cur > last_block) 784 if (cur > last_block)
785 return NULL; /* fail */ 785 return -1; /* fail */
786 786
787 prev = rsv; 787 prev = rsv;
788 next = rb_next(&rsv->rsv_node); 788 next = rb_next(&rsv->rsv_node);
789 rsv = list_entry(next, struct ext3_reserve_window_node, rsv_node); 789 rsv = list_entry(next,struct ext3_reserve_window_node,rsv_node);
790 790
791 /* 791 /*
792 * Reached the last reservation, we can just append to the 792 * Reached the last reservation, we can just append to the
@@ -813,8 +813,25 @@ static struct ext3_reserve_window_node *find_next_reservable_window(
813 * return the reservation window that we could append to. 813 * return the reservation window that we could append to.
814 * succeed. 814 * succeed.
815 */ 815 */
816 *start_block = cur; 816
817 return prev; 817 if ((prev != my_rsv) && (!rsv_is_empty(&my_rsv->rsv_window)))
818 rsv_window_remove(sb, my_rsv);
819
820 /*
821 * Let's book the whole avaliable window for now. We will check the
822 * disk bitmap later and then, if there are free blocks then we adjust
823 * the window size if it's larger than requested.
824 * Otherwise, we will remove this node from the tree next time
825 * call find_next_reservable_window.
826 */
827 my_rsv->rsv_start = cur;
828 my_rsv->rsv_end = cur + size - 1;
829 my_rsv->rsv_alloc_hit = 0;
830
831 if (prev != my_rsv)
832 ext3_rsv_window_add(sb, my_rsv);
833
834 return 0;
818} 835}
819 836
820/** 837/**
@@ -852,6 +869,7 @@ static struct ext3_reserve_window_node *find_next_reservable_window(
852 * @sb: the super block 869 * @sb: the super block
853 * @group: the group we are trying to allocate in 870 * @group: the group we are trying to allocate in
854 * @bitmap_bh: the block group block bitmap 871 * @bitmap_bh: the block group block bitmap
872 *
855 */ 873 */
856static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv, 874static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv,
857 int goal, struct super_block *sb, 875 int goal, struct super_block *sb,
@@ -860,10 +878,10 @@ static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv,
860 struct ext3_reserve_window_node *search_head; 878 struct ext3_reserve_window_node *search_head;
861 int group_first_block, group_end_block, start_block; 879 int group_first_block, group_end_block, start_block;
862 int first_free_block; 880 int first_free_block;
863 int reservable_space_start;
864 struct ext3_reserve_window_node *prev_rsv;
865 struct rb_root *fs_rsv_root = &EXT3_SB(sb)->s_rsv_window_root; 881 struct rb_root *fs_rsv_root = &EXT3_SB(sb)->s_rsv_window_root;
866 unsigned long size; 882 unsigned long size;
883 int ret;
884 spinlock_t *rsv_lock = &EXT3_SB(sb)->s_rsv_window_lock;
867 885
868 group_first_block = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) + 886 group_first_block = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) +
869 group * EXT3_BLOCKS_PER_GROUP(sb); 887 group * EXT3_BLOCKS_PER_GROUP(sb);
@@ -875,6 +893,7 @@ static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv,
875 start_block = goal + group_first_block; 893 start_block = goal + group_first_block;
876 894
877 size = my_rsv->rsv_goal_size; 895 size = my_rsv->rsv_goal_size;
896
878 if (!rsv_is_empty(&my_rsv->rsv_window)) { 897 if (!rsv_is_empty(&my_rsv->rsv_window)) {
879 /* 898 /*
880 * if the old reservation is cross group boundary 899 * if the old reservation is cross group boundary
@@ -908,6 +927,8 @@ static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv,
908 my_rsv->rsv_goal_size= size; 927 my_rsv->rsv_goal_size= size;
909 } 928 }
910 } 929 }
930
931 spin_lock(rsv_lock);
911 /* 932 /*
912 * shift the search start to the window near the goal block 933 * shift the search start to the window near the goal block
913 */ 934 */
@@ -921,11 +942,16 @@ static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv,
921 * need to check the bitmap after we found a reservable window. 942 * need to check the bitmap after we found a reservable window.
922 */ 943 */
923retry: 944retry:
924 prev_rsv = find_next_reservable_window(search_head, size, 945 ret = find_next_reservable_window(search_head, my_rsv, sb,
925 &start_block, group_end_block); 946 start_block, group_end_block);
926 if (prev_rsv == NULL) 947
927 goto failed; 948 if (ret == -1) {
928 reservable_space_start = start_block; 949 if (!rsv_is_empty(&my_rsv->rsv_window))
950 rsv_window_remove(sb, my_rsv);
951 spin_unlock(rsv_lock);
952 return -1;
953 }
954
929 /* 955 /*
930 * On success, find_next_reservable_window() returns the 956 * On success, find_next_reservable_window() returns the
931 * reservation window where there is a reservable space after it. 957 * reservation window where there is a reservable space after it.
@@ -937,8 +963,9 @@ retry:
937 * block. Search start from the start block of the reservable space 963 * block. Search start from the start block of the reservable space
938 * we just found. 964 * we just found.
939 */ 965 */
966 spin_unlock(rsv_lock);
940 first_free_block = bitmap_search_next_usable_block( 967 first_free_block = bitmap_search_next_usable_block(
941 reservable_space_start - group_first_block, 968 my_rsv->rsv_start - group_first_block,
942 bitmap_bh, group_end_block - group_first_block + 1); 969 bitmap_bh, group_end_block - group_first_block + 1);
943 970
944 if (first_free_block < 0) { 971 if (first_free_block < 0) {
@@ -946,54 +973,29 @@ retry:
946 * no free block left on the bitmap, no point 973 * no free block left on the bitmap, no point
947 * to reserve the space. return failed. 974 * to reserve the space. return failed.
948 */ 975 */
949 goto failed; 976 spin_lock(rsv_lock);
977 if (!rsv_is_empty(&my_rsv->rsv_window))
978 rsv_window_remove(sb, my_rsv);
979 spin_unlock(rsv_lock);
980 return -1; /* failed */
950 } 981 }
982
951 start_block = first_free_block + group_first_block; 983 start_block = first_free_block + group_first_block;
952 /* 984 /*
953 * check if the first free block is within the 985 * check if the first free block is within the
954 * free space we just found 986 * free space we just reserved
955 */ 987 */
956 if ((start_block >= reservable_space_start) && 988 if (start_block >= my_rsv->rsv_start && start_block < my_rsv->rsv_end)
957 (start_block < reservable_space_start + size)) 989 return 0; /* success */
958 goto found_rsv_window;
959 /* 990 /*
960 * if the first free bit we found is out of the reservable space 991 * if the first free bit we found is out of the reservable space
961 * this means there is no free block on the reservable space 992 * continue search for next reservable space,
962 * we should continue search for next reservable space,
963 * start from where the free block is, 993 * start from where the free block is,
964 * we also shift the list head to where we stopped last time 994 * we also shift the list head to where we stopped last time
965 */ 995 */
966 search_head = prev_rsv; 996 search_head = my_rsv;
997 spin_lock(rsv_lock);
967 goto retry; 998 goto retry;
968
969found_rsv_window:
970 /*
971 * great! the reservable space contains some free blocks.
972 * if the search returns that we should add the new
973 * window just next to where the old window, we don't
974 * need to remove the old window first then add it to the
975 * same place, just update the new start and new end.
976 */
977 if (my_rsv != prev_rsv) {
978 if (!rsv_is_empty(&my_rsv->rsv_window))
979 rsv_window_remove(sb, my_rsv);
980 }
981 my_rsv->rsv_start = reservable_space_start;
982 my_rsv->rsv_end = my_rsv->rsv_start + size - 1;
983 my_rsv->rsv_alloc_hit = 0;
984 if (my_rsv != prev_rsv) {
985 ext3_rsv_window_add(sb, my_rsv);
986 }
987 return 0; /* succeed */
988failed:
989 /*
990 * failed to find a new reservation window in the current
991 * group, remove the current(stale) reservation window
992 * if there is any
993 */
994 if (!rsv_is_empty(&my_rsv->rsv_window))
995 rsv_window_remove(sb, my_rsv);
996 return -1; /* failed */
997} 999}
998 1000
999/* 1001/*
@@ -1023,7 +1025,6 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
1023 int goal, struct ext3_reserve_window_node * my_rsv, 1025 int goal, struct ext3_reserve_window_node * my_rsv,
1024 int *errp) 1026 int *errp)
1025{ 1027{
1026 spinlock_t *rsv_lock;
1027 unsigned long group_first_block; 1028 unsigned long group_first_block;
1028 int ret = 0; 1029 int ret = 0;
1029 int fatal; 1030 int fatal;
@@ -1052,7 +1053,6 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
1052 ret = ext3_try_to_allocate(sb, handle, group, bitmap_bh, goal, NULL); 1053 ret = ext3_try_to_allocate(sb, handle, group, bitmap_bh, goal, NULL);
1053 goto out; 1054 goto out;
1054 } 1055 }
1055 rsv_lock = &EXT3_SB(sb)->s_rsv_window_lock;
1056 /* 1056 /*
1057 * goal is a group relative block number (if there is a goal) 1057 * goal is a group relative block number (if there is a goal)
1058 * 0 < goal < EXT3_BLOCKS_PER_GROUP(sb) 1058 * 0 < goal < EXT3_BLOCKS_PER_GROUP(sb)
@@ -1078,30 +1078,21 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
1078 * then we could go to allocate from the reservation window directly. 1078 * then we could go to allocate from the reservation window directly.
1079 */ 1079 */
1080 while (1) { 1080 while (1) {
1081 struct ext3_reserve_window rsv_copy; 1081 if (rsv_is_empty(&my_rsv->rsv_window) || (ret < 0) ||
1082 1082 !goal_in_my_reservation(&my_rsv->rsv_window, goal, group, sb)) {
1083 rsv_copy._rsv_start = my_rsv->rsv_start;
1084 rsv_copy._rsv_end = my_rsv->rsv_end;
1085
1086 if (rsv_is_empty(&rsv_copy) || (ret < 0) ||
1087 !goal_in_my_reservation(&rsv_copy, goal, group, sb)) {
1088 spin_lock(rsv_lock);
1089 ret = alloc_new_reservation(my_rsv, goal, sb, 1083 ret = alloc_new_reservation(my_rsv, goal, sb,
1090 group, bitmap_bh); 1084 group, bitmap_bh);
1091 rsv_copy._rsv_start = my_rsv->rsv_start;
1092 rsv_copy._rsv_end = my_rsv->rsv_end;
1093 spin_unlock(rsv_lock);
1094 if (ret < 0) 1085 if (ret < 0)
1095 break; /* failed */ 1086 break; /* failed */
1096 1087
1097 if (!goal_in_my_reservation(&rsv_copy, goal, group, sb)) 1088 if (!goal_in_my_reservation(&my_rsv->rsv_window, goal, group, sb))
1098 goal = -1; 1089 goal = -1;
1099 } 1090 }
1100 if ((rsv_copy._rsv_start >= group_first_block + EXT3_BLOCKS_PER_GROUP(sb)) 1091 if ((my_rsv->rsv_start >= group_first_block + EXT3_BLOCKS_PER_GROUP(sb))
1101 || (rsv_copy._rsv_end < group_first_block)) 1092 || (my_rsv->rsv_end < group_first_block))
1102 BUG(); 1093 BUG();
1103 ret = ext3_try_to_allocate(sb, handle, group, bitmap_bh, goal, 1094 ret = ext3_try_to_allocate(sb, handle, group, bitmap_bh, goal,
1104 &rsv_copy); 1095 &my_rsv->rsv_window);
1105 if (ret >= 0) { 1096 if (ret >= 0) {
1106 my_rsv->rsv_alloc_hit++; 1097 my_rsv->rsv_alloc_hit++;
1107 break; /* succeed */ 1098 break; /* succeed */
diff --git a/fs/ext3/file.c b/fs/ext3/file.c
index 5ad8cf0292df..98e78345ead9 100644
--- a/fs/ext3/file.c
+++ b/fs/ext3/file.c
@@ -36,7 +36,11 @@ static int ext3_release_file (struct inode * inode, struct file * filp)
36 /* if we are the last writer on the inode, drop the block reservation */ 36 /* if we are the last writer on the inode, drop the block reservation */
37 if ((filp->f_mode & FMODE_WRITE) && 37 if ((filp->f_mode & FMODE_WRITE) &&
38 (atomic_read(&inode->i_writecount) == 1)) 38 (atomic_read(&inode->i_writecount) == 1))
39 {
40 down(&EXT3_I(inode)->truncate_sem);
39 ext3_discard_reservation(inode); 41 ext3_discard_reservation(inode);
42 up(&EXT3_I(inode)->truncate_sem);
43 }
40 if (is_dx(inode) && filp->private_data) 44 if (is_dx(inode) && filp->private_data)
41 ext3_htree_free_dir_info(filp->private_data); 45 ext3_htree_free_dir_info(filp->private_data);
42 46
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index b4b3e8a39131..a6d1779d7de4 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -944,7 +944,8 @@ clear_qf_name:
944 "for remount\n"); 944 "for remount\n");
945 return 0; 945 return 0;
946 } 946 }
947 match_int(&args[0], &option); 947 if (match_int(&args[0], &option) != 0)
948 return 0;
948 *n_blocks_count = option; 949 *n_blocks_count = option;
949 break; 950 break;
950 case Opt_nobh: 951 case Opt_nobh:
diff --git a/fs/ioprio.c b/fs/ioprio.c
new file mode 100644
index 000000000000..663e420636d6
--- /dev/null
+++ b/fs/ioprio.c
@@ -0,0 +1,172 @@
1/*
2 * fs/ioprio.c
3 *
4 * Copyright (C) 2004 Jens Axboe <axboe@suse.de>
5 *
6 * Helper functions for setting/querying io priorities of processes. The
7 * system calls closely mimmick getpriority/setpriority, see the man page for
8 * those. The prio argument is a composite of prio class and prio data, where
9 * the data argument has meaning within that class. The standard scheduling
10 * classes have 8 distinct prio levels, with 0 being the highest prio and 7
11 * being the lowest.
12 *
13 * IOW, setting BE scheduling class with prio 2 is done ala:
14 *
15 * unsigned int prio = (IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT) | 2;
16 *
17 * ioprio_set(PRIO_PROCESS, pid, prio);
18 *
19 * See also Documentation/block/ioprio.txt
20 *
21 */
22#include <linux/kernel.h>
23#include <linux/ioprio.h>
24#include <linux/blkdev.h>
25
26static int set_task_ioprio(struct task_struct *task, int ioprio)
27{
28 struct io_context *ioc;
29
30 if (task->uid != current->euid &&
31 task->uid != current->uid && !capable(CAP_SYS_NICE))
32 return -EPERM;
33
34 task_lock(task);
35
36 task->ioprio = ioprio;
37
38 ioc = task->io_context;
39 if (ioc && ioc->set_ioprio)
40 ioc->set_ioprio(ioc, ioprio);
41
42 task_unlock(task);
43 return 0;
44}
45
46asmlinkage int sys_ioprio_set(int which, int who, int ioprio)
47{
48 int class = IOPRIO_PRIO_CLASS(ioprio);
49 int data = IOPRIO_PRIO_DATA(ioprio);
50 struct task_struct *p, *g;
51 struct user_struct *user;
52 int ret;
53
54 switch (class) {
55 case IOPRIO_CLASS_RT:
56 if (!capable(CAP_SYS_ADMIN))
57 return -EPERM;
58 /* fall through, rt has prio field too */
59 case IOPRIO_CLASS_BE:
60 if (data >= IOPRIO_BE_NR || data < 0)
61 return -EINVAL;
62
63 break;
64 case IOPRIO_CLASS_IDLE:
65 break;
66 default:
67 return -EINVAL;
68 }
69
70 ret = -ESRCH;
71 read_lock_irq(&tasklist_lock);
72 switch (which) {
73 case IOPRIO_WHO_PROCESS:
74 if (!who)
75 p = current;
76 else
77 p = find_task_by_pid(who);
78 if (p)
79 ret = set_task_ioprio(p, ioprio);
80 break;
81 case IOPRIO_WHO_PGRP:
82 if (!who)
83 who = process_group(current);
84 do_each_task_pid(who, PIDTYPE_PGID, p) {
85 ret = set_task_ioprio(p, ioprio);
86 if (ret)
87 break;
88 } while_each_task_pid(who, PIDTYPE_PGID, p);
89 break;
90 case IOPRIO_WHO_USER:
91 if (!who)
92 user = current->user;
93 else
94 user = find_user(who);
95
96 if (!user)
97 break;
98
99 do_each_thread(g, p) {
100 if (p->uid != who)
101 continue;
102 ret = set_task_ioprio(p, ioprio);
103 if (ret)
104 break;
105 } while_each_thread(g, p);
106
107 if (who)
108 free_uid(user);
109 break;
110 default:
111 ret = -EINVAL;
112 }
113
114 read_unlock_irq(&tasklist_lock);
115 return ret;
116}
117
118asmlinkage int sys_ioprio_get(int which, int who)
119{
120 struct task_struct *g, *p;
121 struct user_struct *user;
122 int ret = -ESRCH;
123
124 read_lock_irq(&tasklist_lock);
125 switch (which) {
126 case IOPRIO_WHO_PROCESS:
127 if (!who)
128 p = current;
129 else
130 p = find_task_by_pid(who);
131 if (p)
132 ret = p->ioprio;
133 break;
134 case IOPRIO_WHO_PGRP:
135 if (!who)
136 who = process_group(current);
137 do_each_task_pid(who, PIDTYPE_PGID, p) {
138 if (ret == -ESRCH)
139 ret = p->ioprio;
140 else
141 ret = ioprio_best(ret, p->ioprio);
142 } while_each_task_pid(who, PIDTYPE_PGID, p);
143 break;
144 case IOPRIO_WHO_USER:
145 if (!who)
146 user = current->user;
147 else
148 user = find_user(who);
149
150 if (!user)
151 break;
152
153 do_each_thread(g, p) {
154 if (p->uid != user->uid)
155 continue;
156 if (ret == -ESRCH)
157 ret = p->ioprio;
158 else
159 ret = ioprio_best(ret, p->ioprio);
160 } while_each_thread(g, p);
161
162 if (who)
163 free_uid(user);
164 break;
165 default:
166 ret = -EINVAL;
167 }
168
169 read_unlock_irq(&tasklist_lock);
170 return ret;
171}
172
diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
index ee3536fc84a3..1b7a3ef2f813 100644
--- a/fs/nfs/nfs3acl.c
+++ b/fs/nfs/nfs3acl.c
@@ -2,7 +2,7 @@
2#include <linux/nfs.h> 2#include <linux/nfs.h>
3#include <linux/nfs3.h> 3#include <linux/nfs3.h>
4#include <linux/nfs_fs.h> 4#include <linux/nfs_fs.h>
5#include <linux/xattr_acl.h> 5#include <linux/posix_acl_xattr.h>
6#include <linux/nfsacl.h> 6#include <linux/nfsacl.h>
7 7
8#define NFSDBG_FACILITY NFSDBG_PROC 8#define NFSDBG_FACILITY NFSDBG_PROC
@@ -53,9 +53,9 @@ ssize_t nfs3_getxattr(struct dentry *dentry, const char *name,
53 struct posix_acl *acl; 53 struct posix_acl *acl;
54 int type, error = 0; 54 int type, error = 0;
55 55
56 if (strcmp(name, XATTR_NAME_ACL_ACCESS) == 0) 56 if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
57 type = ACL_TYPE_ACCESS; 57 type = ACL_TYPE_ACCESS;
58 else if (strcmp(name, XATTR_NAME_ACL_DEFAULT) == 0) 58 else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
59 type = ACL_TYPE_DEFAULT; 59 type = ACL_TYPE_DEFAULT;
60 else 60 else
61 return -EOPNOTSUPP; 61 return -EOPNOTSUPP;
@@ -82,9 +82,9 @@ int nfs3_setxattr(struct dentry *dentry, const char *name,
82 struct posix_acl *acl; 82 struct posix_acl *acl;
83 int type, error; 83 int type, error;
84 84
85 if (strcmp(name, XATTR_NAME_ACL_ACCESS) == 0) 85 if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
86 type = ACL_TYPE_ACCESS; 86 type = ACL_TYPE_ACCESS;
87 else if (strcmp(name, XATTR_NAME_ACL_DEFAULT) == 0) 87 else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
88 type = ACL_TYPE_DEFAULT; 88 type = ACL_TYPE_DEFAULT;
89 else 89 else
90 return -EOPNOTSUPP; 90 return -EOPNOTSUPP;
@@ -103,9 +103,9 @@ int nfs3_removexattr(struct dentry *dentry, const char *name)
103 struct inode *inode = dentry->d_inode; 103 struct inode *inode = dentry->d_inode;
104 int type; 104 int type;
105 105
106 if (strcmp(name, XATTR_NAME_ACL_ACCESS) == 0) 106 if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
107 type = ACL_TYPE_ACCESS; 107 type = ACL_TYPE_ACCESS;
108 else if (strcmp(name, XATTR_NAME_ACL_DEFAULT) == 0) 108 else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
109 type = ACL_TYPE_DEFAULT; 109 type = ACL_TYPE_DEFAULT;
110 else 110 else
111 return -EOPNOTSUPP; 111 return -EOPNOTSUPP;
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index de340ffd33c3..be24ead89d94 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -46,10 +46,9 @@
46#include <linux/nfsd/nfsfh.h> 46#include <linux/nfsd/nfsfh.h>
47#include <linux/quotaops.h> 47#include <linux/quotaops.h>
48#include <linux/dnotify.h> 48#include <linux/dnotify.h>
49#include <linux/xattr_acl.h>
50#include <linux/posix_acl.h> 49#include <linux/posix_acl.h>
51#ifdef CONFIG_NFSD_V4
52#include <linux/posix_acl_xattr.h> 50#include <linux/posix_acl_xattr.h>
51#ifdef CONFIG_NFSD_V4
53#include <linux/xattr.h> 52#include <linux/xattr.h>
54#include <linux/nfs4.h> 53#include <linux/nfs4.h>
55#include <linux/nfs4_acl.h> 54#include <linux/nfs4_acl.h>
@@ -1872,10 +1871,10 @@ nfsd_get_posix_acl(struct svc_fh *fhp, int type)
1872 return ERR_PTR(-EOPNOTSUPP); 1871 return ERR_PTR(-EOPNOTSUPP);
1873 switch(type) { 1872 switch(type) {
1874 case ACL_TYPE_ACCESS: 1873 case ACL_TYPE_ACCESS:
1875 name = XATTR_NAME_ACL_ACCESS; 1874 name = POSIX_ACL_XATTR_ACCESS;
1876 break; 1875 break;
1877 case ACL_TYPE_DEFAULT: 1876 case ACL_TYPE_DEFAULT:
1878 name = XATTR_NAME_ACL_DEFAULT; 1877 name = POSIX_ACL_XATTR_DEFAULT;
1879 break; 1878 break;
1880 default: 1879 default:
1881 return ERR_PTR(-EOPNOTSUPP); 1880 return ERR_PTR(-EOPNOTSUPP);
@@ -1919,17 +1918,17 @@ nfsd_set_posix_acl(struct svc_fh *fhp, int type, struct posix_acl *acl)
1919 return -EOPNOTSUPP; 1918 return -EOPNOTSUPP;
1920 switch(type) { 1919 switch(type) {
1921 case ACL_TYPE_ACCESS: 1920 case ACL_TYPE_ACCESS:
1922 name = XATTR_NAME_ACL_ACCESS; 1921 name = POSIX_ACL_XATTR_ACCESS;
1923 break; 1922 break;
1924 case ACL_TYPE_DEFAULT: 1923 case ACL_TYPE_DEFAULT:
1925 name = XATTR_NAME_ACL_DEFAULT; 1924 name = POSIX_ACL_XATTR_DEFAULT;
1926 break; 1925 break;
1927 default: 1926 default:
1928 return -EOPNOTSUPP; 1927 return -EOPNOTSUPP;
1929 } 1928 }
1930 1929
1931 if (acl && acl->a_count) { 1930 if (acl && acl->a_count) {
1932 size = xattr_acl_size(acl->a_count); 1931 size = posix_acl_xattr_size(acl->a_count);
1933 value = kmalloc(size, GFP_KERNEL); 1932 value = kmalloc(size, GFP_KERNEL);
1934 if (!value) 1933 if (!value)
1935 return -ENOMEM; 1934 return -ENOMEM;
diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c
index 94dc42475a04..76caedf737f2 100644
--- a/fs/reiserfs/ioctl.c
+++ b/fs/reiserfs/ioctl.c
@@ -36,10 +36,16 @@ int reiserfs_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
36 /* following two cases are taken from fs/ext2/ioctl.c by Remy 36 /* following two cases are taken from fs/ext2/ioctl.c by Remy
37 Card (card@masi.ibp.fr) */ 37 Card (card@masi.ibp.fr) */
38 case REISERFS_IOC_GETFLAGS: 38 case REISERFS_IOC_GETFLAGS:
39 if (!reiserfs_attrs (inode->i_sb))
40 return -ENOTTY;
41
39 flags = REISERFS_I(inode) -> i_attrs; 42 flags = REISERFS_I(inode) -> i_attrs;
40 i_attrs_to_sd_attrs( inode, ( __u16 * ) &flags ); 43 i_attrs_to_sd_attrs( inode, ( __u16 * ) &flags );
41 return put_user(flags, (int __user *) arg); 44 return put_user(flags, (int __user *) arg);
42 case REISERFS_IOC_SETFLAGS: { 45 case REISERFS_IOC_SETFLAGS: {
46 if (!reiserfs_attrs (inode->i_sb))
47 return -ENOTTY;
48
43 if (IS_RDONLY(inode)) 49 if (IS_RDONLY(inode))
44 return -EROFS; 50 return -EROFS;
45 51
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index 7b87707acc36..d1bcf0da6728 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -645,18 +645,22 @@ struct buffer_chunk {
645 645
646static void write_chunk(struct buffer_chunk *chunk) { 646static void write_chunk(struct buffer_chunk *chunk) {
647 int i; 647 int i;
648 get_fs_excl();
648 for (i = 0; i < chunk->nr ; i++) { 649 for (i = 0; i < chunk->nr ; i++) {
649 submit_logged_buffer(chunk->bh[i]) ; 650 submit_logged_buffer(chunk->bh[i]) ;
650 } 651 }
651 chunk->nr = 0; 652 chunk->nr = 0;
653 put_fs_excl();
652} 654}
653 655
654static void write_ordered_chunk(struct buffer_chunk *chunk) { 656static void write_ordered_chunk(struct buffer_chunk *chunk) {
655 int i; 657 int i;
658 get_fs_excl();
656 for (i = 0; i < chunk->nr ; i++) { 659 for (i = 0; i < chunk->nr ; i++) {
657 submit_ordered_buffer(chunk->bh[i]) ; 660 submit_ordered_buffer(chunk->bh[i]) ;
658 } 661 }
659 chunk->nr = 0; 662 chunk->nr = 0;
663 put_fs_excl();
660} 664}
661 665
662static int add_to_chunk(struct buffer_chunk *chunk, struct buffer_head *bh, 666static int add_to_chunk(struct buffer_chunk *chunk, struct buffer_head *bh,
@@ -918,6 +922,8 @@ static int flush_commit_list(struct super_block *s, struct reiserfs_journal_list
918 return 0 ; 922 return 0 ;
919 } 923 }
920 924
925 get_fs_excl();
926
921 /* before we can put our commit blocks on disk, we have to make sure everyone older than 927 /* before we can put our commit blocks on disk, we have to make sure everyone older than
922 ** us is on disk too 928 ** us is on disk too
923 */ 929 */
@@ -1055,6 +1061,7 @@ put_jl:
1055 1061
1056 if (retval) 1062 if (retval)
1057 reiserfs_abort (s, retval, "Journal write error in %s", __FUNCTION__); 1063 reiserfs_abort (s, retval, "Journal write error in %s", __FUNCTION__);
1064 put_fs_excl();
1058 return retval; 1065 return retval;
1059} 1066}
1060 1067
@@ -1251,6 +1258,8 @@ static int flush_journal_list(struct super_block *s,
1251 return 0 ; 1258 return 0 ;
1252 } 1259 }
1253 1260
1261 get_fs_excl();
1262
1254 /* if all the work is already done, get out of here */ 1263 /* if all the work is already done, get out of here */
1255 if (atomic_read(&(jl->j_nonzerolen)) <= 0 && 1264 if (atomic_read(&(jl->j_nonzerolen)) <= 0 &&
1256 atomic_read(&(jl->j_commit_left)) <= 0) { 1265 atomic_read(&(jl->j_commit_left)) <= 0) {
@@ -1450,6 +1459,7 @@ flush_older_and_return:
1450 put_journal_list(s, jl); 1459 put_journal_list(s, jl);
1451 if (flushall) 1460 if (flushall)
1452 up(&journal->j_flush_sem); 1461 up(&journal->j_flush_sem);
1462 put_fs_excl();
1453 return err ; 1463 return err ;
1454} 1464}
1455 1465
@@ -2719,6 +2729,7 @@ relock:
2719 th->t_trans_id = journal->j_trans_id ; 2729 th->t_trans_id = journal->j_trans_id ;
2720 unlock_journal(p_s_sb) ; 2730 unlock_journal(p_s_sb) ;
2721 INIT_LIST_HEAD (&th->t_list); 2731 INIT_LIST_HEAD (&th->t_list);
2732 get_fs_excl();
2722 return 0 ; 2733 return 0 ;
2723 2734
2724out_fail: 2735out_fail:
@@ -3526,6 +3537,7 @@ static int do_journal_end(struct reiserfs_transaction_handle *th, struct super_b
3526 BUG_ON (th->t_refcount > 1); 3537 BUG_ON (th->t_refcount > 1);
3527 BUG_ON (!th->t_trans_id); 3538 BUG_ON (!th->t_trans_id);
3528 3539
3540 put_fs_excl();
3529 current->journal_info = th->t_handle_save; 3541 current->journal_info = th->t_handle_save;
3530 reiserfs_check_lock_depth(p_s_sb, "journal end"); 3542 reiserfs_check_lock_depth(p_s_sb, "journal end");
3531 if (journal->j_len == 0) { 3543 if (journal->j_len == 0) {
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index 660aefca1fd2..d50a5cd860ce 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -1066,6 +1066,8 @@ static void handle_attrs( struct super_block *s )
1066 reiserfs_warning(s, "reiserfs: cannot support attributes until flag is set in super-block" ); 1066 reiserfs_warning(s, "reiserfs: cannot support attributes until flag is set in super-block" );
1067 REISERFS_SB(s) -> s_mount_opt &= ~ ( 1 << REISERFS_ATTRS ); 1067 REISERFS_SB(s) -> s_mount_opt &= ~ ( 1 << REISERFS_ATTRS );
1068 } 1068 }
1069 } else if (le32_to_cpu( rs -> s_flags ) & reiserfs_attrs_cleared) {
1070 REISERFS_SB(s)->s_mount_opt |= REISERFS_ATTRS;
1069 } 1071 }
1070} 1072}
1071 1073
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 3f6dc7112bc6..4673157b262f 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -159,7 +159,7 @@ udf_find_entry(struct inode *dir, struct dentry *dentry,
159 char *nameptr; 159 char *nameptr;
160 uint8_t lfi; 160 uint8_t lfi;
161 uint16_t liu; 161 uint16_t liu;
162 loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2; 162 loff_t size;
163 kernel_lb_addr bloc, eloc; 163 kernel_lb_addr bloc, eloc;
164 uint32_t extoffset, elen, offset; 164 uint32_t extoffset, elen, offset;
165 struct buffer_head *bh = NULL; 165 struct buffer_head *bh = NULL;
@@ -167,6 +167,8 @@ udf_find_entry(struct inode *dir, struct dentry *dentry,
167 if (!dir) 167 if (!dir)
168 return NULL; 168 return NULL;
169 169
170 size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
171
170 f_pos = (udf_ext0_offset(dir) >> 2); 172 f_pos = (udf_ext0_offset(dir) >> 2);
171 173
172 fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; 174 fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index c627bc408a6b..9ad142476f33 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -108,6 +108,21 @@ typedef int (*acpi_op_unbind) (struct acpi_device *device);
108typedef int (*acpi_op_match) (struct acpi_device *device, 108typedef int (*acpi_op_match) (struct acpi_device *device,
109 struct acpi_driver *driver); 109 struct acpi_driver *driver);
110 110
111struct acpi_bus_ops {
112 u32 acpi_op_add:1;
113 u32 acpi_op_remove:1;
114 u32 acpi_op_lock:1;
115 u32 acpi_op_start:1;
116 u32 acpi_op_stop:1;
117 u32 acpi_op_suspend:1;
118 u32 acpi_op_resume:1;
119 u32 acpi_op_scan:1;
120 u32 acpi_op_bind:1;
121 u32 acpi_op_unbind:1;
122 u32 acpi_op_match:1;
123 u32 reserved:21;
124};
125
111struct acpi_device_ops { 126struct acpi_device_ops {
112 acpi_op_add add; 127 acpi_op_add add;
113 acpi_op_remove remove; 128 acpi_op_remove remove;
@@ -327,9 +342,9 @@ int acpi_bus_generate_event (struct acpi_device *device, u8 type, int data);
327int acpi_bus_receive_event (struct acpi_bus_event *event); 342int acpi_bus_receive_event (struct acpi_bus_event *event);
328int acpi_bus_register_driver (struct acpi_driver *driver); 343int acpi_bus_register_driver (struct acpi_driver *driver);
329int acpi_bus_unregister_driver (struct acpi_driver *driver); 344int acpi_bus_unregister_driver (struct acpi_driver *driver);
330int acpi_bus_scan (struct acpi_device *start);
331int acpi_bus_add (struct acpi_device **child, struct acpi_device *parent, 345int acpi_bus_add (struct acpi_device **child, struct acpi_device *parent,
332 acpi_handle handle, int type); 346 acpi_handle handle, int type);
347int acpi_bus_start (struct acpi_device *device);
333 348
334 349
335int acpi_match_ids (struct acpi_device *device, char *ids); 350int acpi_match_ids (struct acpi_device *device, char *ids);
diff --git a/include/acpi/acpi_drivers.h b/include/acpi/acpi_drivers.h
index c62e92ec43b2..4ec722d73381 100644
--- a/include/acpi/acpi_drivers.h
+++ b/include/acpi/acpi_drivers.h
@@ -68,6 +68,7 @@ void acpi_pci_irq_del_prt (int segment, int bus);
68 68
69struct pci_bus; 69struct pci_bus;
70 70
71acpi_status acpi_get_pci_id (acpi_handle handle, struct acpi_pci_id *id);
71int acpi_pci_bind (struct acpi_device *device); 72int acpi_pci_bind (struct acpi_device *device);
72int acpi_pci_unbind (struct acpi_device *device); 73int acpi_pci_unbind (struct acpi_device *device);
73int acpi_pci_bind_root (struct acpi_device *device, struct acpi_pci_id *id, struct pci_bus *bus); 74int acpi_pci_bind_root (struct acpi_device *device, struct acpi_pci_id *id, struct pci_bus *bus);
diff --git a/include/asm-alpha/pci.h b/include/asm-alpha/pci.h
index 0c7b57bc043a..b7806aa3785c 100644
--- a/include/asm-alpha/pci.h
+++ b/include/asm-alpha/pci.h
@@ -223,6 +223,25 @@ pci_dac_dma_sync_single_for_device(struct pci_dev *pdev, dma64_addr_t dma_addr,
223 /* Nothing to do. */ 223 /* Nothing to do. */
224} 224}
225 225
226#ifdef CONFIG_PCI
227static inline void pci_dma_burst_advice(struct pci_dev *pdev,
228 enum pci_dma_burst_strategy *strat,
229 unsigned long *strategy_parameter)
230{
231 unsigned long cacheline_size;
232 u8 byte;
233
234 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte);
235 if (byte == 0)
236 cacheline_size = 1024;
237 else
238 cacheline_size = (int) byte * 4;
239
240 *strat = PCI_DMA_BURST_BOUNDARY;
241 *strategy_parameter = cacheline_size;
242}
243#endif
244
226/* TODO: integrate with include/asm-generic/pci.h ? */ 245/* TODO: integrate with include/asm-generic/pci.h ? */
227static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel) 246static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
228{ 247{
diff --git a/include/asm-alpha/serial.h b/include/asm-alpha/serial.h
index 7b2d9ee95a44..7e4b2987d453 100644
--- a/include/asm-alpha/serial.h
+++ b/include/asm-alpha/serial.h
@@ -22,54 +22,9 @@
22#define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF 22#define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF
23#endif 23#endif
24 24
25#ifdef CONFIG_SERIAL_MANY_PORTS 25#define SERIAL_PORT_DFNS \
26#define FOURPORT_FLAGS ASYNC_FOURPORT
27#define ACCENT_FLAGS 0
28#define BOCA_FLAGS 0
29#endif
30
31#define STD_SERIAL_PORT_DEFNS \
32 /* UART CLK PORT IRQ FLAGS */ \ 26 /* UART CLK PORT IRQ FLAGS */ \
33 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \ 27 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \
34 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS }, /* ttyS1 */ \ 28 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS }, /* ttyS1 */ \
35 { 0, BASE_BAUD, 0x3E8, 4, STD_COM_FLAGS }, /* ttyS2 */ \ 29 { 0, BASE_BAUD, 0x3E8, 4, STD_COM_FLAGS }, /* ttyS2 */ \
36 { 0, BASE_BAUD, 0x2E8, 3, STD_COM4_FLAGS }, /* ttyS3 */ 30 { 0, BASE_BAUD, 0x2E8, 3, STD_COM4_FLAGS }, /* ttyS3 */
37
38
39#ifdef CONFIG_SERIAL_MANY_PORTS
40#define EXTRA_SERIAL_PORT_DEFNS \
41 { 0, BASE_BAUD, 0x1A0, 9, FOURPORT_FLAGS }, /* ttyS4 */ \
42 { 0, BASE_BAUD, 0x1A8, 9, FOURPORT_FLAGS }, /* ttyS5 */ \
43 { 0, BASE_BAUD, 0x1B0, 9, FOURPORT_FLAGS }, /* ttyS6 */ \
44 { 0, BASE_BAUD, 0x1B8, 9, FOURPORT_FLAGS }, /* ttyS7 */ \
45 { 0, BASE_BAUD, 0x2A0, 5, FOURPORT_FLAGS }, /* ttyS8 */ \
46 { 0, BASE_BAUD, 0x2A8, 5, FOURPORT_FLAGS }, /* ttyS9 */ \
47 { 0, BASE_BAUD, 0x2B0, 5, FOURPORT_FLAGS }, /* ttyS10 */ \
48 { 0, BASE_BAUD, 0x2B8, 5, FOURPORT_FLAGS }, /* ttyS11 */ \
49 { 0, BASE_BAUD, 0x330, 4, ACCENT_FLAGS }, /* ttyS12 */ \
50 { 0, BASE_BAUD, 0x338, 4, ACCENT_FLAGS }, /* ttyS13 */ \
51 { 0, BASE_BAUD, 0x000, 0, 0 }, /* ttyS14 (spare) */ \
52 { 0, BASE_BAUD, 0x000, 0, 0 }, /* ttyS15 (spare) */ \
53 { 0, BASE_BAUD, 0x100, 12, BOCA_FLAGS }, /* ttyS16 */ \
54 { 0, BASE_BAUD, 0x108, 12, BOCA_FLAGS }, /* ttyS17 */ \
55 { 0, BASE_BAUD, 0x110, 12, BOCA_FLAGS }, /* ttyS18 */ \
56 { 0, BASE_BAUD, 0x118, 12, BOCA_FLAGS }, /* ttyS19 */ \
57 { 0, BASE_BAUD, 0x120, 12, BOCA_FLAGS }, /* ttyS20 */ \
58 { 0, BASE_BAUD, 0x128, 12, BOCA_FLAGS }, /* ttyS21 */ \
59 { 0, BASE_BAUD, 0x130, 12, BOCA_FLAGS }, /* ttyS22 */ \
60 { 0, BASE_BAUD, 0x138, 12, BOCA_FLAGS }, /* ttyS23 */ \
61 { 0, BASE_BAUD, 0x140, 12, BOCA_FLAGS }, /* ttyS24 */ \
62 { 0, BASE_BAUD, 0x148, 12, BOCA_FLAGS }, /* ttyS25 */ \
63 { 0, BASE_BAUD, 0x150, 12, BOCA_FLAGS }, /* ttyS26 */ \
64 { 0, BASE_BAUD, 0x158, 12, BOCA_FLAGS }, /* ttyS27 */ \
65 { 0, BASE_BAUD, 0x160, 12, BOCA_FLAGS }, /* ttyS28 */ \
66 { 0, BASE_BAUD, 0x168, 12, BOCA_FLAGS }, /* ttyS29 */ \
67 { 0, BASE_BAUD, 0x170, 12, BOCA_FLAGS }, /* ttyS30 */ \
68 { 0, BASE_BAUD, 0x178, 12, BOCA_FLAGS }, /* ttyS31 */
69#else
70#define EXTRA_SERIAL_PORT_DEFNS
71#endif
72
73#define SERIAL_PORT_DFNS \
74 STD_SERIAL_PORT_DEFNS \
75 EXTRA_SERIAL_PORT_DEFNS
diff --git a/include/asm-arm/arch-ixp2000/ixdp2x00.h b/include/asm-arm/arch-ixp2000/ixdp2x00.h
index 3a398dfbf125..229381c64283 100644
--- a/include/asm-arm/arch-ixp2000/ixdp2x00.h
+++ b/include/asm-arm/arch-ixp2000/ixdp2x00.h
@@ -21,8 +21,8 @@
21 * On board CPLD memory map 21 * On board CPLD memory map
22 */ 22 */
23#define IXDP2X00_PHYS_CPLD_BASE 0xc7000000 23#define IXDP2X00_PHYS_CPLD_BASE 0xc7000000
24#define IXDP2X00_VIRT_CPLD_BASE 0xfafff000 24#define IXDP2X00_VIRT_CPLD_BASE 0xfe000000
25#define IXDP2X00_CPLD_SIZE 0x00001000 25#define IXDP2X00_CPLD_SIZE 0x00100000
26 26
27 27
28#define IXDP2X00_CPLD_REG(x) \ 28#define IXDP2X00_CPLD_REG(x) \
diff --git a/include/asm-arm/arch-ixp2000/ixdp2x01.h b/include/asm-arm/arch-ixp2000/ixdp2x01.h
index b3a1bcda8d01..b768009c3a51 100644
--- a/include/asm-arm/arch-ixp2000/ixdp2x01.h
+++ b/include/asm-arm/arch-ixp2000/ixdp2x01.h
@@ -18,8 +18,8 @@
18#define __IXDP2X01_H__ 18#define __IXDP2X01_H__
19 19
20#define IXDP2X01_PHYS_CPLD_BASE 0xc6024000 20#define IXDP2X01_PHYS_CPLD_BASE 0xc6024000
21#define IXDP2X01_VIRT_CPLD_BASE 0xfafff000 21#define IXDP2X01_VIRT_CPLD_BASE 0xfe000000
22#define IXDP2X01_CPLD_REGION_SIZE 0x00001000 22#define IXDP2X01_CPLD_REGION_SIZE 0x00100000
23 23
24#define IXDP2X01_CPLD_VIRT_REG(reg) (volatile unsigned long*)(IXDP2X01_VIRT_CPLD_BASE | reg) 24#define IXDP2X01_CPLD_VIRT_REG(reg) (volatile unsigned long*)(IXDP2X01_VIRT_CPLD_BASE | reg)
25#define IXDP2X01_CPLD_PHYS_REG(reg) (volatile u32*)(IXDP2X01_PHYS_CPLD_BASE | reg) 25#define IXDP2X01_CPLD_PHYS_REG(reg) (volatile u32*)(IXDP2X01_PHYS_CPLD_BASE | reg)
diff --git a/include/asm-arm/arch-ixp2000/ixp2000-regs.h b/include/asm-arm/arch-ixp2000/ixp2000-regs.h
index 5eb47d4bfbf6..75623f81ef75 100644
--- a/include/asm-arm/arch-ixp2000/ixp2000-regs.h
+++ b/include/asm-arm/arch-ixp2000/ixp2000-regs.h
@@ -18,6 +18,21 @@
18#ifndef _IXP2000_REGS_H_ 18#ifndef _IXP2000_REGS_H_
19#define _IXP2000_REGS_H_ 19#define _IXP2000_REGS_H_
20 20
21/*
22 * IXP2000 linux memory map:
23 *
24 * virt phys size
25 * fb000000 db000000 16M PCI CFG1
26 * fc000000 da000000 16M PCI CFG0
27 * fd000000 d8000000 16M PCI I/O
28 * fe[0-7]00000 8M per-platform mappings
29 * feb00000 c8000000 1M MSF
30 * fec00000 df000000 1M PCI CSRs
31 * fed00000 de000000 1M PCI CREG
32 * fee00000 d6000000 1M INTCTL
33 * fef00000 c0000000 1M CAP
34 */
35
21/* 36/*
22 * Static I/O regions. 37 * Static I/O regions.
23 * 38 *
@@ -71,6 +86,10 @@
71#define IXP2000_PCI_CSR_VIRT_BASE 0xfec00000 86#define IXP2000_PCI_CSR_VIRT_BASE 0xfec00000
72#define IXP2000_PCI_CSR_SIZE 0x00100000 87#define IXP2000_PCI_CSR_SIZE 0x00100000
73 88
89#define IXP2000_MSF_PHYS_BASE 0xc8000000
90#define IXP2000_MSF_VIRT_BASE 0xfeb00000
91#define IXP2000_MSF_SIZE 0x00100000
92
74#define IXP2000_PCI_IO_PHYS_BASE 0xd8000000 93#define IXP2000_PCI_IO_PHYS_BASE 0xd8000000
75#define IXP2000_PCI_IO_VIRT_BASE 0xfd000000 94#define IXP2000_PCI_IO_VIRT_BASE 0xfd000000
76#define IXP2000_PCI_IO_SIZE 0x01000000 95#define IXP2000_PCI_IO_SIZE 0x01000000
diff --git a/include/asm-arm/arch-ixp2000/vmalloc.h b/include/asm-arm/arch-ixp2000/vmalloc.h
index 473dff4ec561..275136963a0c 100644
--- a/include/asm-arm/arch-ixp2000/vmalloc.h
+++ b/include/asm-arm/arch-ixp2000/vmalloc.h
@@ -17,4 +17,4 @@
17 * The vmalloc() routines leaves a hole of 4kB between each vmalloced 17 * The vmalloc() routines leaves a hole of 4kB between each vmalloced
18 * area for the same reason. ;) 18 * area for the same reason. ;)
19 */ 19 */
20#define VMALLOC_END 0xfaffefff 20#define VMALLOC_END 0xfb000000
diff --git a/include/asm-arm/arch-ixp4xx/debug-macro.S b/include/asm-arm/arch-ixp4xx/debug-macro.S
index 45a6c6cc29d5..2e23651e217f 100644
--- a/include/asm-arm/arch-ixp4xx/debug-macro.S
+++ b/include/asm-arm/arch-ixp4xx/debug-macro.S
@@ -14,8 +14,8 @@
14 mrc p15, 0, \rx, c1, c0 14 mrc p15, 0, \rx, c1, c0
15 tst \rx, #1 @ MMU enabled? 15 tst \rx, #1 @ MMU enabled?
16 moveq \rx, #0xc8000000 16 moveq \rx, #0xc8000000
17 orrne \rx, \rx, #0x00b00000
18 movne \rx, #0xff000000 17 movne \rx, #0xff000000
18 orrne \rx, \rx, #0x00b00000
19 add \rx,\rx,#3 @ Uart regs are at off set of 3 if 19 add \rx,\rx,#3 @ Uart regs are at off set of 3 if
20 @ byte writes used - Big Endian. 20 @ byte writes used - Big Endian.
21 .endm 21 .endm
diff --git a/include/asm-arm/arch-omap/usb.h b/include/asm-arm/arch-omap/usb.h
index 1438c6cef0ca..054fb9a8e0c6 100644
--- a/include/asm-arm/arch-omap/usb.h
+++ b/include/asm-arm/arch-omap/usb.h
@@ -47,6 +47,15 @@
47# define HMC_TLLATTACH (1 << 6) 47# define HMC_TLLATTACH (1 << 6)
48# define OTG_HMC(w) (((w)>>0)&0x3f) 48# define OTG_HMC(w) (((w)>>0)&0x3f)
49#define OTG_CTRL_REG OTG_REG32(0x0c) 49#define OTG_CTRL_REG OTG_REG32(0x0c)
50# define OTG_USB2_EN (1 << 29)
51# define OTG_USB2_DP (1 << 28)
52# define OTG_USB2_DM (1 << 27)
53# define OTG_USB1_EN (1 << 26)
54# define OTG_USB1_DP (1 << 25)
55# define OTG_USB1_DM (1 << 24)
56# define OTG_USB0_EN (1 << 23)
57# define OTG_USB0_DP (1 << 22)
58# define OTG_USB0_DM (1 << 21)
50# define OTG_ASESSVLD (1 << 20) 59# define OTG_ASESSVLD (1 << 20)
51# define OTG_BSESSEND (1 << 19) 60# define OTG_BSESSEND (1 << 19)
52# define OTG_BSESSVLD (1 << 18) 61# define OTG_BSESSVLD (1 << 18)
diff --git a/include/asm-arm/arch-pxa/debug-macro.S b/include/asm-arm/arch-pxa/debug-macro.S
index f288e74b67c2..b6ec68879176 100644
--- a/include/asm-arm/arch-pxa/debug-macro.S
+++ b/include/asm-arm/arch-pxa/debug-macro.S
@@ -11,6 +11,8 @@
11 * 11 *
12*/ 12*/
13 13
14#include "hardware.h"
15
14 .macro addruart,rx 16 .macro addruart,rx
15 mrc p15, 0, \rx, c1, c0 17 mrc p15, 0, \rx, c1, c0
16 tst \rx, #1 @ MMU enabled? 18 tst \rx, #1 @ MMU enabled?
diff --git a/include/asm-arm/arch-s3c2410/audio.h b/include/asm-arm/arch-s3c2410/audio.h
new file mode 100644
index 000000000000..0d276e67f2fb
--- /dev/null
+++ b/include/asm-arm/arch-s3c2410/audio.h
@@ -0,0 +1,49 @@
1/* linux/include/asm-arm/arch-s3c2410/audio.h
2 *
3 * (c) 2004-2005 Simtec Electronics
4 * http://www.simtec.co.uk/products/SWLINUX/
5 * Ben Dooks <ben@simtec.co.uk>
6 *
7 * S3C24XX - Audio platfrom_device info
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * Changelog:
14 * 20-Nov-2004 BJD Created file
15 * 07-Mar-2005 BJD Added suspend/resume calls
16*/
17
18#ifndef __ASM_ARCH_AUDIO_H
19#define __ASM_ARCH_AUDIO_H __FILE__
20
21/* struct s3c24xx_iis_ops
22 *
23 * called from the s3c24xx audio core to deal with the architecture
24 * or the codec's setup and control.
25 *
26 * the pointer to itself is passed through in case the caller wants to
27 * embed this in an larger structure for easy reference to it's context.
28*/
29
30struct s3c24xx_iis_ops {
31 struct module *owner;
32
33 int (*startup)(struct s3c24xx_iis_ops *me);
34 void (*shutdown)(struct s3c24xx_iis_ops *me);
35 int (*suspend)(struct s3c24xx_iis_ops *me);
36 int (*resume)(struct s3c24xx_iis_ops *me);
37
38 int (*open)(struct s3c24xx_iis_ops *me, snd_pcm_substream_t *strm);
39 int (*close)(struct s3c24xx_iis_ops *me, snd_pcm_substream_t *strm);
40 int (*prepare)(struct s3c24xx_iis_ops *me, snd_pcm_substream_t *strm, snd_pcm_runtime_t *rt);
41};
42
43struct s3c24xx_platdata_iis {
44 const char *codec_clk;
45 struct s3c24xx_iis_ops *ops;
46 int (*match_dev)(struct device *dev);
47};
48
49#endif /* __ASM_ARCH_AUDIO_H */
diff --git a/include/asm-arm/hardware/arm_timer.h b/include/asm-arm/hardware/arm_timer.h
new file mode 100644
index 000000000000..04be3bdf46b8
--- /dev/null
+++ b/include/asm-arm/hardware/arm_timer.h
@@ -0,0 +1,21 @@
1#ifndef __ASM_ARM_HARDWARE_ARM_TIMER_H
2#define __ASM_ARM_HARDWARE_ARM_TIMER_H
3
4#define TIMER_LOAD 0x00
5#define TIMER_VALUE 0x04
6#define TIMER_CTRL 0x08
7#define TIMER_CTRL_ONESHOT (1 << 0)
8#define TIMER_CTRL_32BIT (1 << 1)
9#define TIMER_CTRL_DIV1 (0 << 2)
10#define TIMER_CTRL_DIV16 (1 << 2)
11#define TIMER_CTRL_DIV256 (2 << 2)
12#define TIMER_CTRL_IE (1 << 5) /* Interrupt Enable (versatile only) */
13#define TIMER_CTRL_PERIODIC (1 << 6)
14#define TIMER_CTRL_ENABLE (1 << 7)
15
16#define TIMER_INTCLR 0x0c
17#define TIMER_RIS 0x10
18#define TIMER_MIS 0x14
19#define TIMER_BGLOAD 0x18
20
21#endif
diff --git a/include/asm-arm/ide.h b/include/asm-arm/ide.h
index 2114acb3d237..4f68c8a5a199 100644
--- a/include/asm-arm/ide.h
+++ b/include/asm-arm/ide.h
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * This file contains the i386 architecture specific IDE code. 8 * This file contains the ARM architecture specific IDE code.
9 */ 9 */
10 10
11#ifndef __ASMARM_IDE_H 11#ifndef __ASMARM_IDE_H
diff --git a/include/asm-arm/io.h b/include/asm-arm/io.h
index cc4b5f5dbfcf..cfa71a0dffb6 100644
--- a/include/asm-arm/io.h
+++ b/include/asm-arm/io.h
@@ -82,7 +82,7 @@ extern void __readwrite_bug(const char *fn);
82 * only. Their primary purpose is to access PCI and ISA peripherals. 82 * only. Their primary purpose is to access PCI and ISA peripherals.
83 * 83 *
84 * Note that for a big endian machine, this implies that the following 84 * Note that for a big endian machine, this implies that the following
85 * big endian mode connectivity is in place, as described by numerious 85 * big endian mode connectivity is in place, as described by numerous
86 * ARM documents: 86 * ARM documents:
87 * 87 *
88 * PCI: D0-D7 D8-D15 D16-D23 D24-D31 88 * PCI: D0-D7 D8-D15 D16-D23 D24-D31
diff --git a/include/asm-arm/mach/time.h b/include/asm-arm/mach/time.h
index 047980ad18d1..2cf279a44017 100644
--- a/include/asm-arm/mach/time.h
+++ b/include/asm-arm/mach/time.h
@@ -60,6 +60,8 @@ struct dyn_tick_timer {
60}; 60};
61 61
62void timer_dyn_reprogram(void); 62void timer_dyn_reprogram(void);
63#else
64#define timer_dyn_reprogram() do { } while (0)
63#endif 65#endif
64 66
65extern struct sys_timer *system_timer; 67extern struct sys_timer *system_timer;
diff --git a/include/asm-arm/pci.h b/include/asm-arm/pci.h
index 40ffaefbeb1a..e300646fe650 100644
--- a/include/asm-arm/pci.h
+++ b/include/asm-arm/pci.h
@@ -42,6 +42,16 @@ static inline void pcibios_penalize_isa_irq(int irq)
42#define pci_unmap_len(PTR, LEN_NAME) ((PTR)->LEN_NAME) 42#define pci_unmap_len(PTR, LEN_NAME) ((PTR)->LEN_NAME)
43#define pci_unmap_len_set(PTR, LEN_NAME, VAL) (((PTR)->LEN_NAME) = (VAL)) 43#define pci_unmap_len_set(PTR, LEN_NAME, VAL) (((PTR)->LEN_NAME) = (VAL))
44 44
45#ifdef CONFIG_PCI
46static inline void pci_dma_burst_advice(struct pci_dev *pdev,
47 enum pci_dma_burst_strategy *strat,
48 unsigned long *strategy_parameter)
49{
50 *strat = PCI_DMA_BURST_INFINITY;
51 *strategy_parameter = ~0UL;
52}
53#endif
54
45#define HAVE_PCI_MMAP 55#define HAVE_PCI_MMAP
46extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, 56extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
47 enum pci_mmap_state mmap_state, int write_combine); 57 enum pci_mmap_state mmap_state, int write_combine);
diff --git a/include/asm-arm/system.h b/include/asm-arm/system.h
index 3d0d2860b6db..cdf49f442fd2 100644
--- a/include/asm-arm/system.h
+++ b/include/asm-arm/system.h
@@ -290,7 +290,6 @@ do { \
290}) 290})
291 291
292#ifdef CONFIG_SMP 292#ifdef CONFIG_SMP
293#error SMP not supported
294 293
295#define smp_mb() mb() 294#define smp_mb() mb()
296#define smp_rmb() rmb() 295#define smp_rmb() rmb()
@@ -304,6 +303,8 @@ do { \
304#define smp_wmb() barrier() 303#define smp_wmb() barrier()
305#define smp_read_barrier_depends() do { } while(0) 304#define smp_read_barrier_depends() do { } while(0)
306 305
306#endif /* CONFIG_SMP */
307
307#if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110) 308#if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
308/* 309/*
309 * On the StrongARM, "swp" is terminally broken since it bypasses the 310 * On the StrongARM, "swp" is terminally broken since it bypasses the
@@ -316,9 +317,16 @@ do { \
316 * 317 *
317 * We choose (1) since its the "easiest" to achieve here and is not 318 * We choose (1) since its the "easiest" to achieve here and is not
318 * dependent on the processor type. 319 * dependent on the processor type.
320 *
321 * NOTE that this solution won't work on an SMP system, so explcitly
322 * forbid it here.
319 */ 323 */
324#ifdef CONFIG_SMP
325#error SMP is not supported on SA1100/SA110
326#else
320#define swp_is_buggy 327#define swp_is_buggy
321#endif 328#endif
329#endif
322 330
323static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size) 331static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
324{ 332{
@@ -361,8 +369,6 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
361 return ret; 369 return ret;
362} 370}
363 371
364#endif /* CONFIG_SMP */
365
366#endif /* __ASSEMBLY__ */ 372#endif /* __ASSEMBLY__ */
367 373
368#define arch_align_stack(x) (x) 374#define arch_align_stack(x) (x)
diff --git a/include/asm-arm/tlbflush.h b/include/asm-arm/tlbflush.h
index 8a864b118569..9387a5e1ffe0 100644
--- a/include/asm-arm/tlbflush.h
+++ b/include/asm-arm/tlbflush.h
@@ -235,7 +235,7 @@ extern struct cpu_tlb_fns cpu_tlb;
235 235
236#define tlb_flag(f) ((always_tlb_flags & (f)) || (__tlb_flag & possible_tlb_flags & (f))) 236#define tlb_flag(f) ((always_tlb_flags & (f)) || (__tlb_flag & possible_tlb_flags & (f)))
237 237
238static inline void flush_tlb_all(void) 238static inline void local_flush_tlb_all(void)
239{ 239{
240 const int zero = 0; 240 const int zero = 0;
241 const unsigned int __tlb_flag = __cpu_tlb_flags; 241 const unsigned int __tlb_flag = __cpu_tlb_flags;
@@ -253,7 +253,7 @@ static inline void flush_tlb_all(void)
253 asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero)); 253 asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero));
254} 254}
255 255
256static inline void flush_tlb_mm(struct mm_struct *mm) 256static inline void local_flush_tlb_mm(struct mm_struct *mm)
257{ 257{
258 const int zero = 0; 258 const int zero = 0;
259 const int asid = ASID(mm); 259 const int asid = ASID(mm);
@@ -282,7 +282,7 @@ static inline void flush_tlb_mm(struct mm_struct *mm)
282} 282}
283 283
284static inline void 284static inline void
285flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr) 285local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
286{ 286{
287 const int zero = 0; 287 const int zero = 0;
288 const unsigned int __tlb_flag = __cpu_tlb_flags; 288 const unsigned int __tlb_flag = __cpu_tlb_flags;
@@ -313,7 +313,7 @@ flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
313 asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (uaddr)); 313 asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (uaddr));
314} 314}
315 315
316static inline void flush_tlb_kernel_page(unsigned long kaddr) 316static inline void local_flush_tlb_kernel_page(unsigned long kaddr)
317{ 317{
318 const int zero = 0; 318 const int zero = 0;
319 const unsigned int __tlb_flag = __cpu_tlb_flags; 319 const unsigned int __tlb_flag = __cpu_tlb_flags;
@@ -384,8 +384,24 @@ static inline void clean_pmd_entry(pmd_t *pmd)
384/* 384/*
385 * Convert calls to our calling convention. 385 * Convert calls to our calling convention.
386 */ 386 */
387#define flush_tlb_range(vma,start,end) __cpu_flush_user_tlb_range(start,end,vma) 387#define local_flush_tlb_range(vma,start,end) __cpu_flush_user_tlb_range(start,end,vma)
388#define flush_tlb_kernel_range(s,e) __cpu_flush_kern_tlb_range(s,e) 388#define local_flush_tlb_kernel_range(s,e) __cpu_flush_kern_tlb_range(s,e)
389
390#ifndef CONFIG_SMP
391#define flush_tlb_all local_flush_tlb_all
392#define flush_tlb_mm local_flush_tlb_mm
393#define flush_tlb_page local_flush_tlb_page
394#define flush_tlb_kernel_page local_flush_tlb_kernel_page
395#define flush_tlb_range local_flush_tlb_range
396#define flush_tlb_kernel_range local_flush_tlb_kernel_range
397#else
398extern void flush_tlb_all(void);
399extern void flush_tlb_mm(struct mm_struct *mm);
400extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr);
401extern void flush_tlb_kernel_page(unsigned long kaddr);
402extern void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
403extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
404#endif
389 405
390/* 406/*
391 * if PG_dcache_dirty is set for the page, we need to ensure that any 407 * if PG_dcache_dirty is set for the page, we need to ensure that any
diff --git a/include/asm-arm26/serial.h b/include/asm-arm26/serial.h
index 21e1df31f086..5fc747d1b501 100644
--- a/include/asm-arm26/serial.h
+++ b/include/asm-arm26/serial.h
@@ -30,34 +30,16 @@
30#if defined(CONFIG_ARCH_A5K) 30#if defined(CONFIG_ARCH_A5K)
31 /* UART CLK PORT IRQ FLAGS */ 31 /* UART CLK PORT IRQ FLAGS */
32 32
33#define STD_SERIAL_PORT_DEFNS \ 33#define SERIAL_PORT_DFNS \
34 { 0, BASE_BAUD, 0x3F8, 10, STD_COM_FLAGS }, /* ttyS0 */ \ 34 { 0, BASE_BAUD, 0x3F8, 10, STD_COM_FLAGS }, /* ttyS0 */ \
35 { 0, BASE_BAUD, 0x2F8, 10, STD_COM_FLAGS }, /* ttyS1 */ 35 { 0, BASE_BAUD, 0x2F8, 10, STD_COM_FLAGS }, /* ttyS1 */
36 36
37#else 37#else
38 38
39#define STD_SERIAL_PORT_DEFNS \ 39#define SERIAL_PORT_DFNS \
40 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS0 */ \ 40 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS0 */ \
41 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS1 */ 41 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS1 */
42 42
43#endif 43#endif
44 44
45#define EXTRA_SERIAL_PORT_DEFNS \
46 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS2 */ \
47 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS3 */ \
48 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS4 */ \
49 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS5 */ \
50 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS6 */ \
51 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS7 */ \
52 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS8 */ \
53 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS9 */ \
54 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS10 */ \
55 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS11 */ \
56 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS12 */ \
57 { 0, BASE_BAUD, 0 , 0, STD_COM_FLAGS }, /* ttyS13 */
58
59#define SERIAL_PORT_DFNS \
60 STD_SERIAL_PORT_DEFNS \
61 EXTRA_SERIAL_PORT_DEFNS
62
63#endif 45#endif
diff --git a/include/asm-frv/pci.h b/include/asm-frv/pci.h
index a6a469231f62..b4efe5e3591a 100644
--- a/include/asm-frv/pci.h
+++ b/include/asm-frv/pci.h
@@ -57,6 +57,16 @@ extern void pci_free_consistent(struct pci_dev *hwdev, size_t size,
57 */ 57 */
58#define PCI_DMA_BUS_IS_PHYS (1) 58#define PCI_DMA_BUS_IS_PHYS (1)
59 59
60#ifdef CONFIG_PCI
61static inline void pci_dma_burst_advice(struct pci_dev *pdev,
62 enum pci_dma_burst_strategy *strat,
63 unsigned long *strategy_parameter)
64{
65 *strat = PCI_DMA_BURST_INFINITY;
66 *strategy_parameter = ~0UL;
67}
68#endif
69
60/* 70/*
61 * These are pretty much arbitary with the CoMEM implementation. 71 * These are pretty much arbitary with the CoMEM implementation.
62 * We have the whole address space to ourselves. 72 * We have the whole address space to ourselves.
diff --git a/include/asm-i386/ide.h b/include/asm-i386/ide.h
index 859ebf4da632..79dfab87135d 100644
--- a/include/asm-i386/ide.h
+++ b/include/asm-i386/ide.h
@@ -41,13 +41,17 @@ static __inline__ int ide_default_irq(unsigned long base)
41 41
42static __inline__ unsigned long ide_default_io_base(int index) 42static __inline__ unsigned long ide_default_io_base(int index)
43{ 43{
44 if (pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL) == NULL) {
45 switch(index) {
46 case 2: return 0x1e8;
47 case 3: return 0x168;
48 case 4: return 0x1e0;
49 case 5: return 0x160;
50 }
51 }
44 switch (index) { 52 switch (index) {
45 case 0: return 0x1f0; 53 case 0: return 0x1f0;
46 case 1: return 0x170; 54 case 1: return 0x170;
47 case 2: return 0x1e8;
48 case 3: return 0x168;
49 case 4: return 0x1e0;
50 case 5: return 0x160;
51 default: 55 default:
52 return 0; 56 return 0;
53 } 57 }
diff --git a/include/asm-i386/pci.h b/include/asm-i386/pci.h
index fb749b85a739..3561899eb826 100644
--- a/include/asm-i386/pci.h
+++ b/include/asm-i386/pci.h
@@ -99,6 +99,16 @@ static inline void pcibios_add_platform_entries(struct pci_dev *dev)
99{ 99{
100} 100}
101 101
102#ifdef CONFIG_PCI
103static inline void pci_dma_burst_advice(struct pci_dev *pdev,
104 enum pci_dma_burst_strategy *strat,
105 unsigned long *strategy_parameter)
106{
107 *strat = PCI_DMA_BURST_INFINITY;
108 *strategy_parameter = ~0UL;
109}
110#endif
111
102#endif /* __KERNEL__ */ 112#endif /* __KERNEL__ */
103 113
104/* implement the pci_ DMA API in terms of the generic device dma_ one */ 114/* implement the pci_ DMA API in terms of the generic device dma_ one */
diff --git a/include/asm-i386/serial.h b/include/asm-i386/serial.h
index 21ddecc77c77..e1ecfccb743b 100644
--- a/include/asm-i386/serial.h
+++ b/include/asm-i386/serial.h
@@ -22,109 +22,9 @@
22#define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF 22#define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF
23#endif 23#endif
24 24
25#ifdef CONFIG_SERIAL_MANY_PORTS 25#define SERIAL_PORT_DFNS \
26#define FOURPORT_FLAGS ASYNC_FOURPORT
27#define ACCENT_FLAGS 0
28#define BOCA_FLAGS 0
29#define HUB6_FLAGS 0
30#endif
31
32#define MCA_COM_FLAGS (STD_COM_FLAGS|ASYNC_BOOT_ONLYMCA)
33
34/*
35 * The following define the access methods for the HUB6 card. All
36 * access is through two ports for all 24 possible chips. The card is
37 * selected through the high 2 bits, the port on that card with the
38 * "middle" 3 bits, and the register on that port with the bottom
39 * 3 bits.
40 *
41 * While the access port and interrupt is configurable, the default
42 * port locations are 0x302 for the port control register, and 0x303
43 * for the data read/write register. Normally, the interrupt is at irq3
44 * but can be anything from 3 to 7 inclusive. Note that using 3 will
45 * require disabling com2.
46 */
47
48#define C_P(card,port) (((card)<<6|(port)<<3) + 1)
49
50#define STD_SERIAL_PORT_DEFNS \
51 /* UART CLK PORT IRQ FLAGS */ \ 26 /* UART CLK PORT IRQ FLAGS */ \
52 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \ 27 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \
53 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS }, /* ttyS1 */ \ 28 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS }, /* ttyS1 */ \
54 { 0, BASE_BAUD, 0x3E8, 4, STD_COM_FLAGS }, /* ttyS2 */ \ 29 { 0, BASE_BAUD, 0x3E8, 4, STD_COM_FLAGS }, /* ttyS2 */ \
55 { 0, BASE_BAUD, 0x2E8, 3, STD_COM4_FLAGS }, /* ttyS3 */ 30 { 0, BASE_BAUD, 0x2E8, 3, STD_COM4_FLAGS }, /* ttyS3 */
56
57
58#ifdef CONFIG_SERIAL_MANY_PORTS
59#define EXTRA_SERIAL_PORT_DEFNS \
60 { 0, BASE_BAUD, 0x1A0, 9, FOURPORT_FLAGS }, /* ttyS4 */ \
61 { 0, BASE_BAUD, 0x1A8, 9, FOURPORT_FLAGS }, /* ttyS5 */ \
62 { 0, BASE_BAUD, 0x1B0, 9, FOURPORT_FLAGS }, /* ttyS6 */ \
63 { 0, BASE_BAUD, 0x1B8, 9, FOURPORT_FLAGS }, /* ttyS7 */ \
64 { 0, BASE_BAUD, 0x2A0, 5, FOURPORT_FLAGS }, /* ttyS8 */ \
65 { 0, BASE_BAUD, 0x2A8, 5, FOURPORT_FLAGS }, /* ttyS9 */ \
66 { 0, BASE_BAUD, 0x2B0, 5, FOURPORT_FLAGS }, /* ttyS10 */ \
67 { 0, BASE_BAUD, 0x2B8, 5, FOURPORT_FLAGS }, /* ttyS11 */ \
68 { 0, BASE_BAUD, 0x330, 4, ACCENT_FLAGS }, /* ttyS12 */ \
69 { 0, BASE_BAUD, 0x338, 4, ACCENT_FLAGS }, /* ttyS13 */ \
70 { 0, BASE_BAUD, 0x000, 0, 0 }, /* ttyS14 (spare) */ \
71 { 0, BASE_BAUD, 0x000, 0, 0 }, /* ttyS15 (spare) */ \
72 { 0, BASE_BAUD, 0x100, 12, BOCA_FLAGS }, /* ttyS16 */ \
73 { 0, BASE_BAUD, 0x108, 12, BOCA_FLAGS }, /* ttyS17 */ \
74 { 0, BASE_BAUD, 0x110, 12, BOCA_FLAGS }, /* ttyS18 */ \
75 { 0, BASE_BAUD, 0x118, 12, BOCA_FLAGS }, /* ttyS19 */ \
76 { 0, BASE_BAUD, 0x120, 12, BOCA_FLAGS }, /* ttyS20 */ \
77 { 0, BASE_BAUD, 0x128, 12, BOCA_FLAGS }, /* ttyS21 */ \
78 { 0, BASE_BAUD, 0x130, 12, BOCA_FLAGS }, /* ttyS22 */ \
79 { 0, BASE_BAUD, 0x138, 12, BOCA_FLAGS }, /* ttyS23 */ \
80 { 0, BASE_BAUD, 0x140, 12, BOCA_FLAGS }, /* ttyS24 */ \
81 { 0, BASE_BAUD, 0x148, 12, BOCA_FLAGS }, /* ttyS25 */ \
82 { 0, BASE_BAUD, 0x150, 12, BOCA_FLAGS }, /* ttyS26 */ \
83 { 0, BASE_BAUD, 0x158, 12, BOCA_FLAGS }, /* ttyS27 */ \
84 { 0, BASE_BAUD, 0x160, 12, BOCA_FLAGS }, /* ttyS28 */ \
85 { 0, BASE_BAUD, 0x168, 12, BOCA_FLAGS }, /* ttyS29 */ \
86 { 0, BASE_BAUD, 0x170, 12, BOCA_FLAGS }, /* ttyS30 */ \
87 { 0, BASE_BAUD, 0x178, 12, BOCA_FLAGS }, /* ttyS31 */
88#else
89#define EXTRA_SERIAL_PORT_DEFNS
90#endif
91
92/* You can have up to four HUB6's in the system, but I've only
93 * included two cards here for a total of twelve ports.
94 */
95#if (defined(CONFIG_HUB6) && defined(CONFIG_SERIAL_MANY_PORTS))
96#define HUB6_SERIAL_PORT_DFNS \
97 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,0) }, /* ttyS32 */ \
98 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,1) }, /* ttyS33 */ \
99 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,2) }, /* ttyS34 */ \
100 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,3) }, /* ttyS35 */ \
101 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,4) }, /* ttyS36 */ \
102 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,5) }, /* ttyS37 */ \
103 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,0) }, /* ttyS38 */ \
104 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,1) }, /* ttyS39 */ \
105 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,2) }, /* ttyS40 */ \
106 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,3) }, /* ttyS41 */ \
107 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,4) }, /* ttyS42 */ \
108 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,5) }, /* ttyS43 */
109#else
110#define HUB6_SERIAL_PORT_DFNS
111#endif
112
113#ifdef CONFIG_MCA
114#define MCA_SERIAL_PORT_DFNS \
115 { 0, BASE_BAUD, 0x3220, 3, MCA_COM_FLAGS }, \
116 { 0, BASE_BAUD, 0x3228, 3, MCA_COM_FLAGS }, \
117 { 0, BASE_BAUD, 0x4220, 3, MCA_COM_FLAGS }, \
118 { 0, BASE_BAUD, 0x4228, 3, MCA_COM_FLAGS }, \
119 { 0, BASE_BAUD, 0x5220, 3, MCA_COM_FLAGS }, \
120 { 0, BASE_BAUD, 0x5228, 3, MCA_COM_FLAGS },
121#else
122#define MCA_SERIAL_PORT_DFNS
123#endif
124
125#define SERIAL_PORT_DFNS \
126 STD_SERIAL_PORT_DEFNS \
127 EXTRA_SERIAL_PORT_DEFNS \
128 HUB6_SERIAL_PORT_DFNS \
129 MCA_SERIAL_PORT_DFNS
130
diff --git a/include/asm-i386/tlbflush.h b/include/asm-i386/tlbflush.h
index f22fab0cea26..ab216e1370ef 100644
--- a/include/asm-i386/tlbflush.h
+++ b/include/asm-i386/tlbflush.h
@@ -22,16 +22,18 @@
22 */ 22 */
23#define __flush_tlb_global() \ 23#define __flush_tlb_global() \
24 do { \ 24 do { \
25 unsigned int tmpreg; \ 25 unsigned int tmpreg, cr4, cr4_orig; \
26 \ 26 \
27 __asm__ __volatile__( \ 27 __asm__ __volatile__( \
28 "movl %1, %%cr4; # turn off PGE \n" \ 28 "movl %%cr4, %2; # turn off PGE \n" \
29 "movl %2, %1; \n" \
30 "andl %3, %1; \n" \
31 "movl %1, %%cr4; \n" \
29 "movl %%cr3, %0; \n" \ 32 "movl %%cr3, %0; \n" \
30 "movl %0, %%cr3; # flush TLB \n" \ 33 "movl %0, %%cr3; # flush TLB \n" \
31 "movl %2, %%cr4; # turn PGE back on \n" \ 34 "movl %2, %%cr4; # turn PGE back on \n" \
32 : "=&r" (tmpreg) \ 35 : "=&r" (tmpreg), "=&r" (cr4), "=&r" (cr4_orig) \
33 : "r" (mmu_cr4_features & ~X86_CR4_PGE), \ 36 : "i" (~X86_CR4_PGE) \
34 "r" (mmu_cr4_features) \
35 : "memory"); \ 37 : "memory"); \
36 } while (0) 38 } while (0)
37 39
diff --git a/include/asm-i386/unistd.h b/include/asm-i386/unistd.h
index 176413fb9ae3..e25e4c71a879 100644
--- a/include/asm-i386/unistd.h
+++ b/include/asm-i386/unistd.h
@@ -294,8 +294,10 @@
294#define __NR_add_key 286 294#define __NR_add_key 286
295#define __NR_request_key 287 295#define __NR_request_key 287
296#define __NR_keyctl 288 296#define __NR_keyctl 288
297#define __NR_ioprio_set 289
298#define __NR_ioprio_get 290
297 299
298#define NR_syscalls 289 300#define NR_syscalls 291
299 301
300/* 302/*
301 * user-visible error numbers are in the range -1 - -128: see 303 * user-visible error numbers are in the range -1 - -128: see
diff --git a/include/asm-ia64/iosapic.h b/include/asm-ia64/iosapic.h
index 38a7a72791cc..1093f35b3b90 100644
--- a/include/asm-ia64/iosapic.h
+++ b/include/asm-ia64/iosapic.h
@@ -71,8 +71,11 @@ static inline void iosapic_eoi(char __iomem *iosapic, u32 vector)
71} 71}
72 72
73extern void __init iosapic_system_init (int pcat_compat); 73extern void __init iosapic_system_init (int pcat_compat);
74extern void __init iosapic_init (unsigned long address, 74extern int __devinit iosapic_init (unsigned long address,
75 unsigned int gsi_base); 75 unsigned int gsi_base);
76#ifdef CONFIG_HOTPLUG
77extern int iosapic_remove (unsigned int gsi_base);
78#endif /* CONFIG_HOTPLUG */
76extern int gsi_to_vector (unsigned int gsi); 79extern int gsi_to_vector (unsigned int gsi);
77extern int gsi_to_irq (unsigned int gsi); 80extern int gsi_to_irq (unsigned int gsi);
78extern void iosapic_enable_intr (unsigned int vector); 81extern void iosapic_enable_intr (unsigned int vector);
@@ -94,11 +97,14 @@ extern unsigned int iosapic_version (char __iomem *addr);
94 97
95extern void iosapic_pci_fixup (int); 98extern void iosapic_pci_fixup (int);
96#ifdef CONFIG_NUMA 99#ifdef CONFIG_NUMA
97extern void __init map_iosapic_to_node (unsigned int, int); 100extern void __devinit map_iosapic_to_node (unsigned int, int);
98#endif 101#endif
99#else 102#else
100#define iosapic_system_init(pcat_compat) do { } while (0) 103#define iosapic_system_init(pcat_compat) do { } while (0)
101#define iosapic_init(address,gsi_base) do { } while (0) 104#define iosapic_init(address,gsi_base) (-EINVAL)
105#ifdef CONFIG_HOTPLUG
106#define iosapic_remove(gsi_base) (-ENODEV)
107#endif /* CONFIG_HOTPLUG */
102#define iosapic_register_intr(gsi,polarity,trigger) (gsi) 108#define iosapic_register_intr(gsi,polarity,trigger) (gsi)
103#define iosapic_unregister_intr(irq) do { } while (0) 109#define iosapic_unregister_intr(irq) do { } while (0)
104#define iosapic_override_isa_irq(isa_irq,gsi,polarity,trigger) do { } while (0) 110#define iosapic_override_isa_irq(isa_irq,gsi,polarity,trigger) do { } while (0)
diff --git a/include/asm-ia64/kprobes.h b/include/asm-ia64/kprobes.h
index 7b700035e36d..bf36a32e37e4 100644
--- a/include/asm-ia64/kprobes.h
+++ b/include/asm-ia64/kprobes.h
@@ -28,6 +28,7 @@
28#include <linux/ptrace.h> 28#include <linux/ptrace.h>
29#include <asm/break.h> 29#include <asm/break.h>
30 30
31#define MAX_INSN_SIZE 16
31#define BREAK_INST (long)(__IA64_BREAK_KPROBE << 6) 32#define BREAK_INST (long)(__IA64_BREAK_KPROBE << 6)
32 33
33typedef union cmp_inst { 34typedef union cmp_inst {
@@ -63,6 +64,8 @@ typedef struct _bundle {
63 64
64#define JPROBE_ENTRY(pentry) (kprobe_opcode_t *)pentry 65#define JPROBE_ENTRY(pentry) (kprobe_opcode_t *)pentry
65 66
67#define ARCH_SUPPORTS_KRETPROBES
68
66#define SLOT0_OPCODE_SHIFT (37) 69#define SLOT0_OPCODE_SHIFT (37)
67#define SLOT1_p1_OPCODE_SHIFT (37 - (64-46)) 70#define SLOT1_p1_OPCODE_SHIFT (37 - (64-46))
68#define SLOT2_OPCODE_SHIFT (37) 71#define SLOT2_OPCODE_SHIFT (37)
@@ -94,11 +97,6 @@ struct arch_specific_insn {
94}; 97};
95 98
96/* ia64 does not need this */ 99/* ia64 does not need this */
97static inline void jprobe_return(void)
98{
99}
100
101/* ia64 does not need this */
102static inline void arch_copy_kprobe(struct kprobe *p) 100static inline void arch_copy_kprobe(struct kprobe *p)
103{ 101{
104} 102}
@@ -106,6 +104,12 @@ static inline void arch_copy_kprobe(struct kprobe *p)
106#ifdef CONFIG_KPROBES 104#ifdef CONFIG_KPROBES
107extern int kprobe_exceptions_notify(struct notifier_block *self, 105extern int kprobe_exceptions_notify(struct notifier_block *self,
108 unsigned long val, void *data); 106 unsigned long val, void *data);
107
108/* ia64 does not need this */
109static inline void jprobe_return(void)
110{
111}
112
109#else /* !CONFIG_KPROBES */ 113#else /* !CONFIG_KPROBES */
110static inline int kprobe_exceptions_notify(struct notifier_block *self, 114static inline int kprobe_exceptions_notify(struct notifier_block *self,
111 unsigned long val, void *data) 115 unsigned long val, void *data)
diff --git a/include/asm-ia64/mmu_context.h b/include/asm-ia64/mmu_context.h
index 0096e7e05012..e3e5fededb04 100644
--- a/include/asm-ia64/mmu_context.h
+++ b/include/asm-ia64/mmu_context.h
@@ -132,6 +132,9 @@ reload_context (mm_context_t context)
132 ia64_srlz_i(); /* srlz.i implies srlz.d */ 132 ia64_srlz_i(); /* srlz.i implies srlz.d */
133} 133}
134 134
135/*
136 * Must be called with preemption off
137 */
135static inline void 138static inline void
136activate_context (struct mm_struct *mm) 139activate_context (struct mm_struct *mm)
137{ 140{
diff --git a/include/asm-ia64/pci.h b/include/asm-ia64/pci.h
index a8314ee4e7d2..0c4c5d801d3f 100644
--- a/include/asm-ia64/pci.h
+++ b/include/asm-ia64/pci.h
@@ -82,6 +82,25 @@ extern int pcibios_prep_mwi (struct pci_dev *);
82#define sg_dma_len(sg) ((sg)->dma_length) 82#define sg_dma_len(sg) ((sg)->dma_length)
83#define sg_dma_address(sg) ((sg)->dma_address) 83#define sg_dma_address(sg) ((sg)->dma_address)
84 84
85#ifdef CONFIG_PCI
86static inline void pci_dma_burst_advice(struct pci_dev *pdev,
87 enum pci_dma_burst_strategy *strat,
88 unsigned long *strategy_parameter)
89{
90 unsigned long cacheline_size;
91 u8 byte;
92
93 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte);
94 if (byte == 0)
95 cacheline_size = 1024;
96 else
97 cacheline_size = (int) byte * 4;
98
99 *strat = PCI_DMA_BURST_MULTIPLE;
100 *strategy_parameter = cacheline_size;
101}
102#endif
103
85#define HAVE_PCI_MMAP 104#define HAVE_PCI_MMAP
86extern int pci_mmap_page_range (struct pci_dev *dev, struct vm_area_struct *vma, 105extern int pci_mmap_page_range (struct pci_dev *dev, struct vm_area_struct *vma,
87 enum pci_mmap_state mmap_state, int write_combine); 106 enum pci_mmap_state mmap_state, int write_combine);
diff --git a/include/asm-ia64/sections.h b/include/asm-ia64/sections.h
index 8e3dbde1b429..e9eb7f62d32b 100644
--- a/include/asm-ia64/sections.h
+++ b/include/asm-ia64/sections.h
@@ -17,6 +17,7 @@ extern char __start_gate_vtop_patchlist[], __end_gate_vtop_patchlist[];
17extern char __start_gate_fsyscall_patchlist[], __end_gate_fsyscall_patchlist[]; 17extern char __start_gate_fsyscall_patchlist[], __end_gate_fsyscall_patchlist[];
18extern char __start_gate_brl_fsys_bubble_down_patchlist[], __end_gate_brl_fsys_bubble_down_patchlist[]; 18extern char __start_gate_brl_fsys_bubble_down_patchlist[], __end_gate_brl_fsys_bubble_down_patchlist[];
19extern char __start_unwind[], __end_unwind[]; 19extern char __start_unwind[], __end_unwind[];
20extern char __start_ivt_text[], __end_ivt_text[];
20 21
21#endif /* _ASM_IA64_SECTIONS_H */ 22#endif /* _ASM_IA64_SECTIONS_H */
22 23
diff --git a/include/asm-ia64/sn/addrs.h b/include/asm-ia64/sn/addrs.h
index 1bfdfb4d7b01..103d745dc5f2 100644
--- a/include/asm-ia64/sn/addrs.h
+++ b/include/asm-ia64/sn/addrs.h
@@ -216,6 +216,10 @@
216#define TIO_SWIN_WIDGETNUM(x) (((x) >> TIO_SWIN_SIZE_BITS) & TIO_SWIN_WIDGET_MASK) 216#define TIO_SWIN_WIDGETNUM(x) (((x) >> TIO_SWIN_SIZE_BITS) & TIO_SWIN_WIDGET_MASK)
217 217
218 218
219#define TIO_IOSPACE_ADDR(n,x) \
220 /* Move in the Chiplet ID for TIO Local Block MMR */ \
221 (REMOTE_ADDR(n,x) | 1UL << (NASID_SHIFT - 2))
222
219/* 223/*
220 * The following macros produce the correct base virtual address for 224 * The following macros produce the correct base virtual address for
221 * the hub registers. The REMOTE_HUB_* macro produce 225 * the hub registers. The REMOTE_HUB_* macro produce
@@ -233,13 +237,16 @@
233#define REMOTE_HUB_ADDR(n,x) \ 237#define REMOTE_HUB_ADDR(n,x) \
234 ((n & 1) ? \ 238 ((n & 1) ? \
235 /* TIO: */ \ 239 /* TIO: */ \
236 ((volatile u64 *)(GLOBAL_MMR_ADDR(n,x))) \ 240 (is_shub2() ? \
237 : /* SHUB: */ \ 241 /* TIO on Shub2 */ \
238 (((x) & BWIN_TOP) ? ((volatile u64 *)(GLOBAL_MMR_ADDR(n,x)))\ 242 (volatile u64 *)(TIO_IOSPACE_ADDR(n,x)) \
243 : /* TIO on shub1 */ \
244 (volatile u64 *)(GLOBAL_MMR_ADDR(n,x))) \
245 \
246 : /* SHUB1 and SHUB2 MMRs: */ \
247 (((x) & BWIN_TOP) ? ((volatile u64 *)(GLOBAL_MMR_ADDR(n,x))) \
239 : ((volatile u64 *)(NODE_SWIN_BASE(n,1) + 0x800000 + (x))))) 248 : ((volatile u64 *)(NODE_SWIN_BASE(n,1) + 0x800000 + (x)))))
240 249
241
242
243#define HUB_L(x) (*((volatile typeof(*x) *)x)) 250#define HUB_L(x) (*((volatile typeof(*x) *)x))
244#define HUB_S(x,d) (*((volatile typeof(*x) *)x) = (d)) 251#define HUB_S(x,d) (*((volatile typeof(*x) *)x) = (d))
245 252
diff --git a/include/asm-ia64/sn/l1.h b/include/asm-ia64/sn/l1.h
index 08050d37b662..2e5f0aa38889 100644
--- a/include/asm-ia64/sn/l1.h
+++ b/include/asm-ia64/sn/l1.h
@@ -33,5 +33,6 @@
33#define L1_BRICKTYPE_PA 0x6a /* j */ 33#define L1_BRICKTYPE_PA 0x6a /* j */
34#define L1_BRICKTYPE_IA 0x6b /* k */ 34#define L1_BRICKTYPE_IA 0x6b /* k */
35#define L1_BRICKTYPE_ATHENA 0x2b /* + */ 35#define L1_BRICKTYPE_ATHENA 0x2b /* + */
36#define L1_BRICKTYPE_DAYTONA 0x7a /* z */
36 37
37#endif /* _ASM_IA64_SN_L1_H */ 38#endif /* _ASM_IA64_SN_L1_H */
diff --git a/include/asm-ia64/sn/shub_mmr.h b/include/asm-ia64/sn/shub_mmr.h
index 323fa0cd8d83..7de1d1d4b71a 100644
--- a/include/asm-ia64/sn/shub_mmr.h
+++ b/include/asm-ia64/sn/shub_mmr.h
@@ -14,96 +14,98 @@
14/* Register "SH_IPI_INT" */ 14/* Register "SH_IPI_INT" */
15/* SHub Inter-Processor Interrupt Registers */ 15/* SHub Inter-Processor Interrupt Registers */
16/* ==================================================================== */ 16/* ==================================================================== */
17#define SH1_IPI_INT 0x0000000110000380 17#define SH1_IPI_INT __IA64_UL_CONST(0x0000000110000380)
18#define SH2_IPI_INT 0x0000000010000380 18#define SH2_IPI_INT __IA64_UL_CONST(0x0000000010000380)
19 19
20/* SH_IPI_INT_TYPE */ 20/* SH_IPI_INT_TYPE */
21/* Description: Type of Interrupt: 0=INT, 2=PMI, 4=NMI, 5=INIT */ 21/* Description: Type of Interrupt: 0=INT, 2=PMI, 4=NMI, 5=INIT */
22#define SH_IPI_INT_TYPE_SHFT 0 22#define SH_IPI_INT_TYPE_SHFT 0
23#define SH_IPI_INT_TYPE_MASK 0x0000000000000007 23#define SH_IPI_INT_TYPE_MASK __IA64_UL_CONST(0x0000000000000007)
24 24
25/* SH_IPI_INT_AGT */ 25/* SH_IPI_INT_AGT */
26/* Description: Agent, must be 0 for SHub */ 26/* Description: Agent, must be 0 for SHub */
27#define SH_IPI_INT_AGT_SHFT 3 27#define SH_IPI_INT_AGT_SHFT 3
28#define SH_IPI_INT_AGT_MASK 0x0000000000000008 28#define SH_IPI_INT_AGT_MASK __IA64_UL_CONST(0x0000000000000008)
29 29
30/* SH_IPI_INT_PID */ 30/* SH_IPI_INT_PID */
31/* Description: Processor ID, same setting as on targeted McKinley */ 31/* Description: Processor ID, same setting as on targeted McKinley */
32#define SH_IPI_INT_PID_SHFT 4 32#define SH_IPI_INT_PID_SHFT 4
33#define SH_IPI_INT_PID_MASK 0x00000000000ffff0 33#define SH_IPI_INT_PID_MASK __IA64_UL_CONST(0x00000000000ffff0)
34 34
35/* SH_IPI_INT_BASE */ 35/* SH_IPI_INT_BASE */
36/* Description: Optional interrupt vector area, 2MB aligned */ 36/* Description: Optional interrupt vector area, 2MB aligned */
37#define SH_IPI_INT_BASE_SHFT 21 37#define SH_IPI_INT_BASE_SHFT 21
38#define SH_IPI_INT_BASE_MASK 0x0003ffffffe00000 38#define SH_IPI_INT_BASE_MASK __IA64_UL_CONST(0x0003ffffffe00000)
39 39
40/* SH_IPI_INT_IDX */ 40/* SH_IPI_INT_IDX */
41/* Description: Targeted McKinley interrupt vector */ 41/* Description: Targeted McKinley interrupt vector */
42#define SH_IPI_INT_IDX_SHFT 52 42#define SH_IPI_INT_IDX_SHFT 52
43#define SH_IPI_INT_IDX_MASK 0x0ff0000000000000 43#define SH_IPI_INT_IDX_MASK __IA64_UL_CONST(0x0ff0000000000000)
44 44
45/* SH_IPI_INT_SEND */ 45/* SH_IPI_INT_SEND */
46/* Description: Send Interrupt Message to PI, This generates a puls */ 46/* Description: Send Interrupt Message to PI, This generates a puls */
47#define SH_IPI_INT_SEND_SHFT 63 47#define SH_IPI_INT_SEND_SHFT 63
48#define SH_IPI_INT_SEND_MASK 0x8000000000000000 48#define SH_IPI_INT_SEND_MASK __IA64_UL_CONST(0x8000000000000000)
49 49
50/* ==================================================================== */ 50/* ==================================================================== */
51/* Register "SH_EVENT_OCCURRED" */ 51/* Register "SH_EVENT_OCCURRED" */
52/* SHub Interrupt Event Occurred */ 52/* SHub Interrupt Event Occurred */
53/* ==================================================================== */ 53/* ==================================================================== */
54#define SH1_EVENT_OCCURRED 0x0000000110010000 54#define SH1_EVENT_OCCURRED __IA64_UL_CONST(0x0000000110010000)
55#define SH1_EVENT_OCCURRED_ALIAS 0x0000000110010008 55#define SH1_EVENT_OCCURRED_ALIAS __IA64_UL_CONST(0x0000000110010008)
56#define SH2_EVENT_OCCURRED 0x0000000010010000 56#define SH2_EVENT_OCCURRED __IA64_UL_CONST(0x0000000010010000)
57#define SH2_EVENT_OCCURRED_ALIAS 0x0000000010010008 57#define SH2_EVENT_OCCURRED_ALIAS __IA64_UL_CONST(0x0000000010010008)
58 58
59/* ==================================================================== */ 59/* ==================================================================== */
60/* Register "SH_PI_CAM_CONTROL" */ 60/* Register "SH_PI_CAM_CONTROL" */
61/* CRB CAM MMR Access Control */ 61/* CRB CAM MMR Access Control */
62/* ==================================================================== */ 62/* ==================================================================== */
63#define SH1_PI_CAM_CONTROL 0x0000000120050300 63#define SH1_PI_CAM_CONTROL __IA64_UL_CONST(0x0000000120050300)
64 64
65/* ==================================================================== */ 65/* ==================================================================== */
66/* Register "SH_SHUB_ID" */ 66/* Register "SH_SHUB_ID" */
67/* SHub ID Number */ 67/* SHub ID Number */
68/* ==================================================================== */ 68/* ==================================================================== */
69#define SH1_SHUB_ID 0x0000000110060580 69#define SH1_SHUB_ID __IA64_UL_CONST(0x0000000110060580)
70#define SH1_SHUB_ID_REVISION_SHFT 28 70#define SH1_SHUB_ID_REVISION_SHFT 28
71#define SH1_SHUB_ID_REVISION_MASK 0x00000000f0000000 71#define SH1_SHUB_ID_REVISION_MASK __IA64_UL_CONST(0x00000000f0000000)
72 72
73/* ==================================================================== */ 73/* ==================================================================== */
74/* Register "SH_RTC" */ 74/* Register "SH_RTC" */
75/* Real-time Clock */ 75/* Real-time Clock */
76/* ==================================================================== */ 76/* ==================================================================== */
77#define SH1_RTC 0x00000001101c0000 77#define SH1_RTC __IA64_UL_CONST(0x00000001101c0000)
78#define SH2_RTC 0x00000002101c0000 78#define SH2_RTC __IA64_UL_CONST(0x00000002101c0000)
79#define SH_RTC_MASK 0x007fffffffffffff 79#define SH_RTC_MASK __IA64_UL_CONST(0x007fffffffffffff)
80 80
81/* ==================================================================== */ 81/* ==================================================================== */
82/* Register "SH_PIO_WRITE_STATUS_0|1" */ 82/* Register "SH_PIO_WRITE_STATUS_0|1" */
83/* PIO Write Status for CPU 0 & 1 */ 83/* PIO Write Status for CPU 0 & 1 */
84/* ==================================================================== */ 84/* ==================================================================== */
85#define SH1_PIO_WRITE_STATUS_0 0x0000000120070200 85#define SH1_PIO_WRITE_STATUS_0 __IA64_UL_CONST(0x0000000120070200)
86#define SH1_PIO_WRITE_STATUS_1 0x0000000120070280 86#define SH1_PIO_WRITE_STATUS_1 __IA64_UL_CONST(0x0000000120070280)
87#define SH2_PIO_WRITE_STATUS_0 0x0000000020070200 87#define SH2_PIO_WRITE_STATUS_0 __IA64_UL_CONST(0x0000000020070200)
88#define SH2_PIO_WRITE_STATUS_1 0x0000000020070280 88#define SH2_PIO_WRITE_STATUS_1 __IA64_UL_CONST(0x0000000020070280)
89#define SH2_PIO_WRITE_STATUS_2 0x0000000020070300 89#define SH2_PIO_WRITE_STATUS_2 __IA64_UL_CONST(0x0000000020070300)
90#define SH2_PIO_WRITE_STATUS_3 0x0000000020070380 90#define SH2_PIO_WRITE_STATUS_3 __IA64_UL_CONST(0x0000000020070380)
91 91
92/* SH_PIO_WRITE_STATUS_0_WRITE_DEADLOCK */ 92/* SH_PIO_WRITE_STATUS_0_WRITE_DEADLOCK */
93/* Description: Deadlock response detected */ 93/* Description: Deadlock response detected */
94#define SH_PIO_WRITE_STATUS_WRITE_DEADLOCK_SHFT 1 94#define SH_PIO_WRITE_STATUS_WRITE_DEADLOCK_SHFT 1
95#define SH_PIO_WRITE_STATUS_WRITE_DEADLOCK_MASK 0x0000000000000002 95#define SH_PIO_WRITE_STATUS_WRITE_DEADLOCK_MASK \
96 __IA64_UL_CONST(0x0000000000000002)
96 97
97/* SH_PIO_WRITE_STATUS_0_PENDING_WRITE_COUNT */ 98/* SH_PIO_WRITE_STATUS_0_PENDING_WRITE_COUNT */
98/* Description: Count of currently pending PIO writes */ 99/* Description: Count of currently pending PIO writes */
99#define SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_SHFT 56 100#define SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_SHFT 56
100#define SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK 0x3f00000000000000 101#define SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK \
102 __IA64_UL_CONST(0x3f00000000000000)
101 103
102/* ==================================================================== */ 104/* ==================================================================== */
103/* Register "SH_PIO_WRITE_STATUS_0_ALIAS" */ 105/* Register "SH_PIO_WRITE_STATUS_0_ALIAS" */
104/* ==================================================================== */ 106/* ==================================================================== */
105#define SH1_PIO_WRITE_STATUS_0_ALIAS 0x0000000120070208 107#define SH1_PIO_WRITE_STATUS_0_ALIAS __IA64_UL_CONST(0x0000000120070208)
106#define SH2_PIO_WRITE_STATUS_0_ALIAS 0x0000000020070208 108#define SH2_PIO_WRITE_STATUS_0_ALIAS __IA64_UL_CONST(0x0000000020070208)
107 109
108/* ==================================================================== */ 110/* ==================================================================== */
109/* Register "SH_EVENT_OCCURRED" */ 111/* Register "SH_EVENT_OCCURRED" */
@@ -111,33 +113,33 @@
111/* ==================================================================== */ 113/* ==================================================================== */
112/* SH_EVENT_OCCURRED_UART_INT */ 114/* SH_EVENT_OCCURRED_UART_INT */
113/* Description: Pending Junk Bus UART Interrupt */ 115/* Description: Pending Junk Bus UART Interrupt */
114#define SH_EVENT_OCCURRED_UART_INT_SHFT 20 116#define SH_EVENT_OCCURRED_UART_INT_SHFT 20
115#define SH_EVENT_OCCURRED_UART_INT_MASK 0x0000000000100000 117#define SH_EVENT_OCCURRED_UART_INT_MASK __IA64_UL_CONST(0x0000000000100000)
116 118
117/* SH_EVENT_OCCURRED_IPI_INT */ 119/* SH_EVENT_OCCURRED_IPI_INT */
118/* Description: Pending IPI Interrupt */ 120/* Description: Pending IPI Interrupt */
119#define SH_EVENT_OCCURRED_IPI_INT_SHFT 28 121#define SH_EVENT_OCCURRED_IPI_INT_SHFT 28
120#define SH_EVENT_OCCURRED_IPI_INT_MASK 0x0000000010000000 122#define SH_EVENT_OCCURRED_IPI_INT_MASK __IA64_UL_CONST(0x0000000010000000)
121 123
122/* SH_EVENT_OCCURRED_II_INT0 */ 124/* SH_EVENT_OCCURRED_II_INT0 */
123/* Description: Pending II 0 Interrupt */ 125/* Description: Pending II 0 Interrupt */
124#define SH_EVENT_OCCURRED_II_INT0_SHFT 29 126#define SH_EVENT_OCCURRED_II_INT0_SHFT 29
125#define SH_EVENT_OCCURRED_II_INT0_MASK 0x0000000020000000 127#define SH_EVENT_OCCURRED_II_INT0_MASK __IA64_UL_CONST(0x0000000020000000)
126 128
127/* SH_EVENT_OCCURRED_II_INT1 */ 129/* SH_EVENT_OCCURRED_II_INT1 */
128/* Description: Pending II 1 Interrupt */ 130/* Description: Pending II 1 Interrupt */
129#define SH_EVENT_OCCURRED_II_INT1_SHFT 30 131#define SH_EVENT_OCCURRED_II_INT1_SHFT 30
130#define SH_EVENT_OCCURRED_II_INT1_MASK 0x0000000040000000 132#define SH_EVENT_OCCURRED_II_INT1_MASK __IA64_UL_CONST(0x0000000040000000)
131 133
132/* SH2_EVENT_OCCURRED_EXTIO_INT2 */ 134/* SH2_EVENT_OCCURRED_EXTIO_INT2 */
133/* Description: Pending SHUB 2 EXT IO INT2 */ 135/* Description: Pending SHUB 2 EXT IO INT2 */
134#define SH2_EVENT_OCCURRED_EXTIO_INT2_SHFT 33 136#define SH2_EVENT_OCCURRED_EXTIO_INT2_SHFT 33
135#define SH2_EVENT_OCCURRED_EXTIO_INT2_MASK 0x0000000200000000 137#define SH2_EVENT_OCCURRED_EXTIO_INT2_MASK __IA64_UL_CONST(0x0000000200000000)
136 138
137/* SH2_EVENT_OCCURRED_EXTIO_INT3 */ 139/* SH2_EVENT_OCCURRED_EXTIO_INT3 */
138/* Description: Pending SHUB 2 EXT IO INT3 */ 140/* Description: Pending SHUB 2 EXT IO INT3 */
139#define SH2_EVENT_OCCURRED_EXTIO_INT3_SHFT 34 141#define SH2_EVENT_OCCURRED_EXTIO_INT3_SHFT 34
140#define SH2_EVENT_OCCURRED_EXTIO_INT3_MASK 0x0000000400000000 142#define SH2_EVENT_OCCURRED_EXTIO_INT3_MASK __IA64_UL_CONST(0x0000000400000000)
141 143
142#define SH_ALL_INT_MASK \ 144#define SH_ALL_INT_MASK \
143 (SH_EVENT_OCCURRED_UART_INT_MASK | SH_EVENT_OCCURRED_IPI_INT_MASK | \ 145 (SH_EVENT_OCCURRED_UART_INT_MASK | SH_EVENT_OCCURRED_IPI_INT_MASK | \
@@ -149,310 +151,310 @@
149/* ==================================================================== */ 151/* ==================================================================== */
150/* LEDS */ 152/* LEDS */
151/* ==================================================================== */ 153/* ==================================================================== */
152#define SH1_REAL_JUNK_BUS_LED0 0x7fed00000UL 154#define SH1_REAL_JUNK_BUS_LED0 0x7fed00000UL
153#define SH1_REAL_JUNK_BUS_LED1 0x7fed10000UL 155#define SH1_REAL_JUNK_BUS_LED1 0x7fed10000UL
154#define SH1_REAL_JUNK_BUS_LED2 0x7fed20000UL 156#define SH1_REAL_JUNK_BUS_LED2 0x7fed20000UL
155#define SH1_REAL_JUNK_BUS_LED3 0x7fed30000UL 157#define SH1_REAL_JUNK_BUS_LED3 0x7fed30000UL
156 158
157#define SH2_REAL_JUNK_BUS_LED0 0xf0000000UL 159#define SH2_REAL_JUNK_BUS_LED0 0xf0000000UL
158#define SH2_REAL_JUNK_BUS_LED1 0xf0010000UL 160#define SH2_REAL_JUNK_BUS_LED1 0xf0010000UL
159#define SH2_REAL_JUNK_BUS_LED2 0xf0020000UL 161#define SH2_REAL_JUNK_BUS_LED2 0xf0020000UL
160#define SH2_REAL_JUNK_BUS_LED3 0xf0030000UL 162#define SH2_REAL_JUNK_BUS_LED3 0xf0030000UL
161 163
162/* ==================================================================== */ 164/* ==================================================================== */
163/* Register "SH1_PTC_0" */ 165/* Register "SH1_PTC_0" */
164/* Puge Translation Cache Message Configuration Information */ 166/* Puge Translation Cache Message Configuration Information */
165/* ==================================================================== */ 167/* ==================================================================== */
166#define SH1_PTC_0 0x00000001101a0000 168#define SH1_PTC_0 __IA64_UL_CONST(0x00000001101a0000)
167 169
168/* SH1_PTC_0_A */ 170/* SH1_PTC_0_A */
169/* Description: Type */ 171/* Description: Type */
170#define SH1_PTC_0_A_SHFT 0 172#define SH1_PTC_0_A_SHFT 0
171 173
172/* SH1_PTC_0_PS */ 174/* SH1_PTC_0_PS */
173/* Description: Page Size */ 175/* Description: Page Size */
174#define SH1_PTC_0_PS_SHFT 2 176#define SH1_PTC_0_PS_SHFT 2
175 177
176/* SH1_PTC_0_RID */ 178/* SH1_PTC_0_RID */
177/* Description: Region ID */ 179/* Description: Region ID */
178#define SH1_PTC_0_RID_SHFT 8 180#define SH1_PTC_0_RID_SHFT 8
179 181
180/* SH1_PTC_0_START */ 182/* SH1_PTC_0_START */
181/* Description: Start */ 183/* Description: Start */
182#define SH1_PTC_0_START_SHFT 63 184#define SH1_PTC_0_START_SHFT 63
183 185
184/* ==================================================================== */ 186/* ==================================================================== */
185/* Register "SH1_PTC_1" */ 187/* Register "SH1_PTC_1" */
186/* Puge Translation Cache Message Configuration Information */ 188/* Puge Translation Cache Message Configuration Information */
187/* ==================================================================== */ 189/* ==================================================================== */
188#define SH1_PTC_1 0x00000001101a0080 190#define SH1_PTC_1 __IA64_UL_CONST(0x00000001101a0080)
189 191
190/* SH1_PTC_1_START */ 192/* SH1_PTC_1_START */
191/* Description: PTC_1 Start */ 193/* Description: PTC_1 Start */
192#define SH1_PTC_1_START_SHFT 63 194#define SH1_PTC_1_START_SHFT 63
193
194 195
195/* ==================================================================== */ 196/* ==================================================================== */
196/* Register "SH2_PTC" */ 197/* Register "SH2_PTC" */
197/* Puge Translation Cache Message Configuration Information */ 198/* Puge Translation Cache Message Configuration Information */
198/* ==================================================================== */ 199/* ==================================================================== */
199#define SH2_PTC 0x0000000170000000 200#define SH2_PTC __IA64_UL_CONST(0x0000000170000000)
200 201
201/* SH2_PTC_A */ 202/* SH2_PTC_A */
202/* Description: Type */ 203/* Description: Type */
203#define SH2_PTC_A_SHFT 0 204#define SH2_PTC_A_SHFT 0
204 205
205/* SH2_PTC_PS */ 206/* SH2_PTC_PS */
206/* Description: Page Size */ 207/* Description: Page Size */
207#define SH2_PTC_PS_SHFT 2 208#define SH2_PTC_PS_SHFT 2
208 209
209/* SH2_PTC_RID */ 210/* SH2_PTC_RID */
210/* Description: Region ID */ 211/* Description: Region ID */
211#define SH2_PTC_RID_SHFT 4 212#define SH2_PTC_RID_SHFT 4
212 213
213/* SH2_PTC_START */ 214/* SH2_PTC_START */
214/* Description: Start */ 215/* Description: Start */
215#define SH2_PTC_START_SHFT 63 216#define SH2_PTC_START_SHFT 63
216 217
217/* SH2_PTC_ADDR_RID */ 218/* SH2_PTC_ADDR_RID */
218/* Description: Region ID */ 219/* Description: Region ID */
219#define SH2_PTC_ADDR_SHFT 4 220#define SH2_PTC_ADDR_SHFT 4
220#define SH2_PTC_ADDR_MASK 0x1ffffffffffff000 221#define SH2_PTC_ADDR_MASK __IA64_UL_CONST(0x1ffffffffffff000)
221 222
222/* ==================================================================== */ 223/* ==================================================================== */
223/* Register "SH_RTC1_INT_CONFIG" */ 224/* Register "SH_RTC1_INT_CONFIG" */
224/* SHub RTC 1 Interrupt Config Registers */ 225/* SHub RTC 1 Interrupt Config Registers */
225/* ==================================================================== */ 226/* ==================================================================== */
226 227
227#define SH1_RTC1_INT_CONFIG 0x0000000110001480 228#define SH1_RTC1_INT_CONFIG __IA64_UL_CONST(0x0000000110001480)
228#define SH2_RTC1_INT_CONFIG 0x0000000010001480 229#define SH2_RTC1_INT_CONFIG __IA64_UL_CONST(0x0000000010001480)
229#define SH_RTC1_INT_CONFIG_MASK 0x0ff3ffffffefffff 230#define SH_RTC1_INT_CONFIG_MASK __IA64_UL_CONST(0x0ff3ffffffefffff)
230#define SH_RTC1_INT_CONFIG_INIT 0x0000000000000000 231#define SH_RTC1_INT_CONFIG_INIT __IA64_UL_CONST(0x0000000000000000)
231 232
232/* SH_RTC1_INT_CONFIG_TYPE */ 233/* SH_RTC1_INT_CONFIG_TYPE */
233/* Description: Type of Interrupt: 0=INT, 2=PMI, 4=NMI, 5=INIT */ 234/* Description: Type of Interrupt: 0=INT, 2=PMI, 4=NMI, 5=INIT */
234#define SH_RTC1_INT_CONFIG_TYPE_SHFT 0 235#define SH_RTC1_INT_CONFIG_TYPE_SHFT 0
235#define SH_RTC1_INT_CONFIG_TYPE_MASK 0x0000000000000007 236#define SH_RTC1_INT_CONFIG_TYPE_MASK __IA64_UL_CONST(0x0000000000000007)
236 237
237/* SH_RTC1_INT_CONFIG_AGT */ 238/* SH_RTC1_INT_CONFIG_AGT */
238/* Description: Agent, must be 0 for SHub */ 239/* Description: Agent, must be 0 for SHub */
239#define SH_RTC1_INT_CONFIG_AGT_SHFT 3 240#define SH_RTC1_INT_CONFIG_AGT_SHFT 3
240#define SH_RTC1_INT_CONFIG_AGT_MASK 0x0000000000000008 241#define SH_RTC1_INT_CONFIG_AGT_MASK __IA64_UL_CONST(0x0000000000000008)
241 242
242/* SH_RTC1_INT_CONFIG_PID */ 243/* SH_RTC1_INT_CONFIG_PID */
243/* Description: Processor ID, same setting as on targeted McKinley */ 244/* Description: Processor ID, same setting as on targeted McKinley */
244#define SH_RTC1_INT_CONFIG_PID_SHFT 4 245#define SH_RTC1_INT_CONFIG_PID_SHFT 4
245#define SH_RTC1_INT_CONFIG_PID_MASK 0x00000000000ffff0 246#define SH_RTC1_INT_CONFIG_PID_MASK __IA64_UL_CONST(0x00000000000ffff0)
246 247
247/* SH_RTC1_INT_CONFIG_BASE */ 248/* SH_RTC1_INT_CONFIG_BASE */
248/* Description: Optional interrupt vector area, 2MB aligned */ 249/* Description: Optional interrupt vector area, 2MB aligned */
249#define SH_RTC1_INT_CONFIG_BASE_SHFT 21 250#define SH_RTC1_INT_CONFIG_BASE_SHFT 21
250#define SH_RTC1_INT_CONFIG_BASE_MASK 0x0003ffffffe00000 251#define SH_RTC1_INT_CONFIG_BASE_MASK __IA64_UL_CONST(0x0003ffffffe00000)
251 252
252/* SH_RTC1_INT_CONFIG_IDX */ 253/* SH_RTC1_INT_CONFIG_IDX */
253/* Description: Targeted McKinley interrupt vector */ 254/* Description: Targeted McKinley interrupt vector */
254#define SH_RTC1_INT_CONFIG_IDX_SHFT 52 255#define SH_RTC1_INT_CONFIG_IDX_SHFT 52
255#define SH_RTC1_INT_CONFIG_IDX_MASK 0x0ff0000000000000 256#define SH_RTC1_INT_CONFIG_IDX_MASK __IA64_UL_CONST(0x0ff0000000000000)
256 257
257/* ==================================================================== */ 258/* ==================================================================== */
258/* Register "SH_RTC1_INT_ENABLE" */ 259/* Register "SH_RTC1_INT_ENABLE" */
259/* SHub RTC 1 Interrupt Enable Registers */ 260/* SHub RTC 1 Interrupt Enable Registers */
260/* ==================================================================== */ 261/* ==================================================================== */
261 262
262#define SH1_RTC1_INT_ENABLE 0x0000000110001500 263#define SH1_RTC1_INT_ENABLE __IA64_UL_CONST(0x0000000110001500)
263#define SH2_RTC1_INT_ENABLE 0x0000000010001500 264#define SH2_RTC1_INT_ENABLE __IA64_UL_CONST(0x0000000010001500)
264#define SH_RTC1_INT_ENABLE_MASK 0x0000000000000001 265#define SH_RTC1_INT_ENABLE_MASK __IA64_UL_CONST(0x0000000000000001)
265#define SH_RTC1_INT_ENABLE_INIT 0x0000000000000000 266#define SH_RTC1_INT_ENABLE_INIT __IA64_UL_CONST(0x0000000000000000)
266 267
267/* SH_RTC1_INT_ENABLE_RTC1_ENABLE */ 268/* SH_RTC1_INT_ENABLE_RTC1_ENABLE */
268/* Description: Enable RTC 1 Interrupt */ 269/* Description: Enable RTC 1 Interrupt */
269#define SH_RTC1_INT_ENABLE_RTC1_ENABLE_SHFT 0 270#define SH_RTC1_INT_ENABLE_RTC1_ENABLE_SHFT 0
270#define SH_RTC1_INT_ENABLE_RTC1_ENABLE_MASK 0x0000000000000001 271#define SH_RTC1_INT_ENABLE_RTC1_ENABLE_MASK \
272 __IA64_UL_CONST(0x0000000000000001)
271 273
272/* ==================================================================== */ 274/* ==================================================================== */
273/* Register "SH_RTC2_INT_CONFIG" */ 275/* Register "SH_RTC2_INT_CONFIG" */
274/* SHub RTC 2 Interrupt Config Registers */ 276/* SHub RTC 2 Interrupt Config Registers */
275/* ==================================================================== */ 277/* ==================================================================== */
276 278
277#define SH1_RTC2_INT_CONFIG 0x0000000110001580 279#define SH1_RTC2_INT_CONFIG __IA64_UL_CONST(0x0000000110001580)
278#define SH2_RTC2_INT_CONFIG 0x0000000010001580 280#define SH2_RTC2_INT_CONFIG __IA64_UL_CONST(0x0000000010001580)
279#define SH_RTC2_INT_CONFIG_MASK 0x0ff3ffffffefffff 281#define SH_RTC2_INT_CONFIG_MASK __IA64_UL_CONST(0x0ff3ffffffefffff)
280#define SH_RTC2_INT_CONFIG_INIT 0x0000000000000000 282#define SH_RTC2_INT_CONFIG_INIT __IA64_UL_CONST(0x0000000000000000)
281 283
282/* SH_RTC2_INT_CONFIG_TYPE */ 284/* SH_RTC2_INT_CONFIG_TYPE */
283/* Description: Type of Interrupt: 0=INT, 2=PMI, 4=NMI, 5=INIT */ 285/* Description: Type of Interrupt: 0=INT, 2=PMI, 4=NMI, 5=INIT */
284#define SH_RTC2_INT_CONFIG_TYPE_SHFT 0 286#define SH_RTC2_INT_CONFIG_TYPE_SHFT 0
285#define SH_RTC2_INT_CONFIG_TYPE_MASK 0x0000000000000007 287#define SH_RTC2_INT_CONFIG_TYPE_MASK __IA64_UL_CONST(0x0000000000000007)
286 288
287/* SH_RTC2_INT_CONFIG_AGT */ 289/* SH_RTC2_INT_CONFIG_AGT */
288/* Description: Agent, must be 0 for SHub */ 290/* Description: Agent, must be 0 for SHub */
289#define SH_RTC2_INT_CONFIG_AGT_SHFT 3 291#define SH_RTC2_INT_CONFIG_AGT_SHFT 3
290#define SH_RTC2_INT_CONFIG_AGT_MASK 0x0000000000000008 292#define SH_RTC2_INT_CONFIG_AGT_MASK __IA64_UL_CONST(0x0000000000000008)
291 293
292/* SH_RTC2_INT_CONFIG_PID */ 294/* SH_RTC2_INT_CONFIG_PID */
293/* Description: Processor ID, same setting as on targeted McKinley */ 295/* Description: Processor ID, same setting as on targeted McKinley */
294#define SH_RTC2_INT_CONFIG_PID_SHFT 4 296#define SH_RTC2_INT_CONFIG_PID_SHFT 4
295#define SH_RTC2_INT_CONFIG_PID_MASK 0x00000000000ffff0 297#define SH_RTC2_INT_CONFIG_PID_MASK __IA64_UL_CONST(0x00000000000ffff0)
296 298
297/* SH_RTC2_INT_CONFIG_BASE */ 299/* SH_RTC2_INT_CONFIG_BASE */
298/* Description: Optional interrupt vector area, 2MB aligned */ 300/* Description: Optional interrupt vector area, 2MB aligned */
299#define SH_RTC2_INT_CONFIG_BASE_SHFT 21 301#define SH_RTC2_INT_CONFIG_BASE_SHFT 21
300#define SH_RTC2_INT_CONFIG_BASE_MASK 0x0003ffffffe00000 302#define SH_RTC2_INT_CONFIG_BASE_MASK __IA64_UL_CONST(0x0003ffffffe00000)
301 303
302/* SH_RTC2_INT_CONFIG_IDX */ 304/* SH_RTC2_INT_CONFIG_IDX */
303/* Description: Targeted McKinley interrupt vector */ 305/* Description: Targeted McKinley interrupt vector */
304#define SH_RTC2_INT_CONFIG_IDX_SHFT 52 306#define SH_RTC2_INT_CONFIG_IDX_SHFT 52
305#define SH_RTC2_INT_CONFIG_IDX_MASK 0x0ff0000000000000 307#define SH_RTC2_INT_CONFIG_IDX_MASK __IA64_UL_CONST(0x0ff0000000000000)
306 308
307/* ==================================================================== */ 309/* ==================================================================== */
308/* Register "SH_RTC2_INT_ENABLE" */ 310/* Register "SH_RTC2_INT_ENABLE" */
309/* SHub RTC 2 Interrupt Enable Registers */ 311/* SHub RTC 2 Interrupt Enable Registers */
310/* ==================================================================== */ 312/* ==================================================================== */
311 313
312#define SH1_RTC2_INT_ENABLE 0x0000000110001600 314#define SH1_RTC2_INT_ENABLE __IA64_UL_CONST(0x0000000110001600)
313#define SH2_RTC2_INT_ENABLE 0x0000000010001600 315#define SH2_RTC2_INT_ENABLE __IA64_UL_CONST(0x0000000010001600)
314#define SH_RTC2_INT_ENABLE_MASK 0x0000000000000001 316#define SH_RTC2_INT_ENABLE_MASK __IA64_UL_CONST(0x0000000000000001)
315#define SH_RTC2_INT_ENABLE_INIT 0x0000000000000000 317#define SH_RTC2_INT_ENABLE_INIT __IA64_UL_CONST(0x0000000000000000)
316 318
317/* SH_RTC2_INT_ENABLE_RTC2_ENABLE */ 319/* SH_RTC2_INT_ENABLE_RTC2_ENABLE */
318/* Description: Enable RTC 2 Interrupt */ 320/* Description: Enable RTC 2 Interrupt */
319#define SH_RTC2_INT_ENABLE_RTC2_ENABLE_SHFT 0 321#define SH_RTC2_INT_ENABLE_RTC2_ENABLE_SHFT 0
320#define SH_RTC2_INT_ENABLE_RTC2_ENABLE_MASK 0x0000000000000001 322#define SH_RTC2_INT_ENABLE_RTC2_ENABLE_MASK \
323 __IA64_UL_CONST(0x0000000000000001)
321 324
322/* ==================================================================== */ 325/* ==================================================================== */
323/* Register "SH_RTC3_INT_CONFIG" */ 326/* Register "SH_RTC3_INT_CONFIG" */
324/* SHub RTC 3 Interrupt Config Registers */ 327/* SHub RTC 3 Interrupt Config Registers */
325/* ==================================================================== */ 328/* ==================================================================== */
326 329
327#define SH1_RTC3_INT_CONFIG 0x0000000110001680 330#define SH1_RTC3_INT_CONFIG __IA64_UL_CONST(0x0000000110001680)
328#define SH2_RTC3_INT_CONFIG 0x0000000010001680 331#define SH2_RTC3_INT_CONFIG __IA64_UL_CONST(0x0000000010001680)
329#define SH_RTC3_INT_CONFIG_MASK 0x0ff3ffffffefffff 332#define SH_RTC3_INT_CONFIG_MASK __IA64_UL_CONST(0x0ff3ffffffefffff)
330#define SH_RTC3_INT_CONFIG_INIT 0x0000000000000000 333#define SH_RTC3_INT_CONFIG_INIT __IA64_UL_CONST(0x0000000000000000)
331 334
332/* SH_RTC3_INT_CONFIG_TYPE */ 335/* SH_RTC3_INT_CONFIG_TYPE */
333/* Description: Type of Interrupt: 0=INT, 2=PMI, 4=NMI, 5=INIT */ 336/* Description: Type of Interrupt: 0=INT, 2=PMI, 4=NMI, 5=INIT */
334#define SH_RTC3_INT_CONFIG_TYPE_SHFT 0 337#define SH_RTC3_INT_CONFIG_TYPE_SHFT 0
335#define SH_RTC3_INT_CONFIG_TYPE_MASK 0x0000000000000007 338#define SH_RTC3_INT_CONFIG_TYPE_MASK __IA64_UL_CONST(0x0000000000000007)
336 339
337/* SH_RTC3_INT_CONFIG_AGT */ 340/* SH_RTC3_INT_CONFIG_AGT */
338/* Description: Agent, must be 0 for SHub */ 341/* Description: Agent, must be 0 for SHub */
339#define SH_RTC3_INT_CONFIG_AGT_SHFT 3 342#define SH_RTC3_INT_CONFIG_AGT_SHFT 3
340#define SH_RTC3_INT_CONFIG_AGT_MASK 0x0000000000000008 343#define SH_RTC3_INT_CONFIG_AGT_MASK __IA64_UL_CONST(0x0000000000000008)
341 344
342/* SH_RTC3_INT_CONFIG_PID */ 345/* SH_RTC3_INT_CONFIG_PID */
343/* Description: Processor ID, same setting as on targeted McKinley */ 346/* Description: Processor ID, same setting as on targeted McKinley */
344#define SH_RTC3_INT_CONFIG_PID_SHFT 4 347#define SH_RTC3_INT_CONFIG_PID_SHFT 4
345#define SH_RTC3_INT_CONFIG_PID_MASK 0x00000000000ffff0 348#define SH_RTC3_INT_CONFIG_PID_MASK __IA64_UL_CONST(0x00000000000ffff0)
346 349
347/* SH_RTC3_INT_CONFIG_BASE */ 350/* SH_RTC3_INT_CONFIG_BASE */
348/* Description: Optional interrupt vector area, 2MB aligned */ 351/* Description: Optional interrupt vector area, 2MB aligned */
349#define SH_RTC3_INT_CONFIG_BASE_SHFT 21 352#define SH_RTC3_INT_CONFIG_BASE_SHFT 21
350#define SH_RTC3_INT_CONFIG_BASE_MASK 0x0003ffffffe00000 353#define SH_RTC3_INT_CONFIG_BASE_MASK __IA64_UL_CONST(0x0003ffffffe00000)
351 354
352/* SH_RTC3_INT_CONFIG_IDX */ 355/* SH_RTC3_INT_CONFIG_IDX */
353/* Description: Targeted McKinley interrupt vector */ 356/* Description: Targeted McKinley interrupt vector */
354#define SH_RTC3_INT_CONFIG_IDX_SHFT 52 357#define SH_RTC3_INT_CONFIG_IDX_SHFT 52
355#define SH_RTC3_INT_CONFIG_IDX_MASK 0x0ff0000000000000 358#define SH_RTC3_INT_CONFIG_IDX_MASK __IA64_UL_CONST(0x0ff0000000000000)
356 359
357/* ==================================================================== */ 360/* ==================================================================== */
358/* Register "SH_RTC3_INT_ENABLE" */ 361/* Register "SH_RTC3_INT_ENABLE" */
359/* SHub RTC 3 Interrupt Enable Registers */ 362/* SHub RTC 3 Interrupt Enable Registers */
360/* ==================================================================== */ 363/* ==================================================================== */
361 364
362#define SH1_RTC3_INT_ENABLE 0x0000000110001700 365#define SH1_RTC3_INT_ENABLE __IA64_UL_CONST(0x0000000110001700)
363#define SH2_RTC3_INT_ENABLE 0x0000000010001700 366#define SH2_RTC3_INT_ENABLE __IA64_UL_CONST(0x0000000010001700)
364#define SH_RTC3_INT_ENABLE_MASK 0x0000000000000001 367#define SH_RTC3_INT_ENABLE_MASK __IA64_UL_CONST(0x0000000000000001)
365#define SH_RTC3_INT_ENABLE_INIT 0x0000000000000000 368#define SH_RTC3_INT_ENABLE_INIT __IA64_UL_CONST(0x0000000000000000)
366 369
367/* SH_RTC3_INT_ENABLE_RTC3_ENABLE */ 370/* SH_RTC3_INT_ENABLE_RTC3_ENABLE */
368/* Description: Enable RTC 3 Interrupt */ 371/* Description: Enable RTC 3 Interrupt */
369#define SH_RTC3_INT_ENABLE_RTC3_ENABLE_SHFT 0 372#define SH_RTC3_INT_ENABLE_RTC3_ENABLE_SHFT 0
370#define SH_RTC3_INT_ENABLE_RTC3_ENABLE_MASK 0x0000000000000001 373#define SH_RTC3_INT_ENABLE_RTC3_ENABLE_MASK \
374 __IA64_UL_CONST(0x0000000000000001)
371 375
372/* SH_EVENT_OCCURRED_RTC1_INT */ 376/* SH_EVENT_OCCURRED_RTC1_INT */
373/* Description: Pending RTC 1 Interrupt */ 377/* Description: Pending RTC 1 Interrupt */
374#define SH_EVENT_OCCURRED_RTC1_INT_SHFT 24 378#define SH_EVENT_OCCURRED_RTC1_INT_SHFT 24
375#define SH_EVENT_OCCURRED_RTC1_INT_MASK 0x0000000001000000 379#define SH_EVENT_OCCURRED_RTC1_INT_MASK __IA64_UL_CONST(0x0000000001000000)
376 380
377/* SH_EVENT_OCCURRED_RTC2_INT */ 381/* SH_EVENT_OCCURRED_RTC2_INT */
378/* Description: Pending RTC 2 Interrupt */ 382/* Description: Pending RTC 2 Interrupt */
379#define SH_EVENT_OCCURRED_RTC2_INT_SHFT 25 383#define SH_EVENT_OCCURRED_RTC2_INT_SHFT 25
380#define SH_EVENT_OCCURRED_RTC2_INT_MASK 0x0000000002000000 384#define SH_EVENT_OCCURRED_RTC2_INT_MASK __IA64_UL_CONST(0x0000000002000000)
381 385
382/* SH_EVENT_OCCURRED_RTC3_INT */ 386/* SH_EVENT_OCCURRED_RTC3_INT */
383/* Description: Pending RTC 3 Interrupt */ 387/* Description: Pending RTC 3 Interrupt */
384#define SH_EVENT_OCCURRED_RTC3_INT_SHFT 26 388#define SH_EVENT_OCCURRED_RTC3_INT_SHFT 26
385#define SH_EVENT_OCCURRED_RTC3_INT_MASK 0x0000000004000000 389#define SH_EVENT_OCCURRED_RTC3_INT_MASK __IA64_UL_CONST(0x0000000004000000)
386 390
387/* ==================================================================== */ 391/* ==================================================================== */
388/* Register "SH_IPI_ACCESS" */ 392/* Register "SH_IPI_ACCESS" */
389/* CPU interrupt Access Permission Bits */ 393/* CPU interrupt Access Permission Bits */
390/* ==================================================================== */ 394/* ==================================================================== */
391 395
392#define SH1_IPI_ACCESS 0x0000000110060480 396#define SH1_IPI_ACCESS __IA64_UL_CONST(0x0000000110060480)
393#define SH2_IPI_ACCESS0 0x0000000010060c00 397#define SH2_IPI_ACCESS0 __IA64_UL_CONST(0x0000000010060c00)
394#define SH2_IPI_ACCESS1 0x0000000010060c80 398#define SH2_IPI_ACCESS1 __IA64_UL_CONST(0x0000000010060c80)
395#define SH2_IPI_ACCESS2 0x0000000010060d00 399#define SH2_IPI_ACCESS2 __IA64_UL_CONST(0x0000000010060d00)
396#define SH2_IPI_ACCESS3 0x0000000010060d80 400#define SH2_IPI_ACCESS3 __IA64_UL_CONST(0x0000000010060d80)
397 401
398/* ==================================================================== */ 402/* ==================================================================== */
399/* Register "SH_INT_CMPB" */ 403/* Register "SH_INT_CMPB" */
400/* RTC Compare Value for Processor B */ 404/* RTC Compare Value for Processor B */
401/* ==================================================================== */ 405/* ==================================================================== */
402 406
403#define SH1_INT_CMPB 0x00000001101b0080 407#define SH1_INT_CMPB __IA64_UL_CONST(0x00000001101b0080)
404#define SH2_INT_CMPB 0x00000000101b0080 408#define SH2_INT_CMPB __IA64_UL_CONST(0x00000000101b0080)
405#define SH_INT_CMPB_MASK 0x007fffffffffffff 409#define SH_INT_CMPB_MASK __IA64_UL_CONST(0x007fffffffffffff)
406#define SH_INT_CMPB_INIT 0x0000000000000000 410#define SH_INT_CMPB_INIT __IA64_UL_CONST(0x0000000000000000)
407 411
408/* SH_INT_CMPB_REAL_TIME_CMPB */ 412/* SH_INT_CMPB_REAL_TIME_CMPB */
409/* Description: Real Time Clock Compare */ 413/* Description: Real Time Clock Compare */
410#define SH_INT_CMPB_REAL_TIME_CMPB_SHFT 0 414#define SH_INT_CMPB_REAL_TIME_CMPB_SHFT 0
411#define SH_INT_CMPB_REAL_TIME_CMPB_MASK 0x007fffffffffffff 415#define SH_INT_CMPB_REAL_TIME_CMPB_MASK __IA64_UL_CONST(0x007fffffffffffff)
412 416
413/* ==================================================================== */ 417/* ==================================================================== */
414/* Register "SH_INT_CMPC" */ 418/* Register "SH_INT_CMPC" */
415/* RTC Compare Value for Processor C */ 419/* RTC Compare Value for Processor C */
416/* ==================================================================== */ 420/* ==================================================================== */
417 421
418#define SH1_INT_CMPC 0x00000001101b0100 422#define SH1_INT_CMPC __IA64_UL_CONST(0x00000001101b0100)
419#define SH2_INT_CMPC 0x00000000101b0100 423#define SH2_INT_CMPC __IA64_UL_CONST(0x00000000101b0100)
420#define SH_INT_CMPC_MASK 0x007fffffffffffff 424#define SH_INT_CMPC_MASK __IA64_UL_CONST(0x007fffffffffffff)
421#define SH_INT_CMPC_INIT 0x0000000000000000 425#define SH_INT_CMPC_INIT __IA64_UL_CONST(0x0000000000000000)
422 426
423/* SH_INT_CMPC_REAL_TIME_CMPC */ 427/* SH_INT_CMPC_REAL_TIME_CMPC */
424/* Description: Real Time Clock Compare */ 428/* Description: Real Time Clock Compare */
425#define SH_INT_CMPC_REAL_TIME_CMPC_SHFT 0 429#define SH_INT_CMPC_REAL_TIME_CMPC_SHFT 0
426#define SH_INT_CMPC_REAL_TIME_CMPC_MASK 0x007fffffffffffff 430#define SH_INT_CMPC_REAL_TIME_CMPC_MASK __IA64_UL_CONST(0x007fffffffffffff)
427 431
428/* ==================================================================== */ 432/* ==================================================================== */
429/* Register "SH_INT_CMPD" */ 433/* Register "SH_INT_CMPD" */
430/* RTC Compare Value for Processor D */ 434/* RTC Compare Value for Processor D */
431/* ==================================================================== */ 435/* ==================================================================== */
432 436
433#define SH1_INT_CMPD 0x00000001101b0180 437#define SH1_INT_CMPD __IA64_UL_CONST(0x00000001101b0180)
434#define SH2_INT_CMPD 0x00000000101b0180 438#define SH2_INT_CMPD __IA64_UL_CONST(0x00000000101b0180)
435#define SH_INT_CMPD_MASK 0x007fffffffffffff 439#define SH_INT_CMPD_MASK __IA64_UL_CONST(0x007fffffffffffff)
436#define SH_INT_CMPD_INIT 0x0000000000000000 440#define SH_INT_CMPD_INIT __IA64_UL_CONST(0x0000000000000000)
437 441
438/* SH_INT_CMPD_REAL_TIME_CMPD */ 442/* SH_INT_CMPD_REAL_TIME_CMPD */
439/* Description: Real Time Clock Compare */ 443/* Description: Real Time Clock Compare */
440#define SH_INT_CMPD_REAL_TIME_CMPD_SHFT 0 444#define SH_INT_CMPD_REAL_TIME_CMPD_SHFT 0
441#define SH_INT_CMPD_REAL_TIME_CMPD_MASK 0x007fffffffffffff 445#define SH_INT_CMPD_REAL_TIME_CMPD_MASK __IA64_UL_CONST(0x007fffffffffffff)
442 446
443/* ==================================================================== */ 447/* ==================================================================== */
444/* Register "SH_MD_DQLP_MMR_DIR_PRIVEC0" */ 448/* Register "SH_MD_DQLP_MMR_DIR_PRIVEC0" */
445/* privilege vector for acc=0 */ 449/* privilege vector for acc=0 */
446/* ==================================================================== */ 450/* ==================================================================== */
447 451#define SH1_MD_DQLP_MMR_DIR_PRIVEC0 __IA64_UL_CONST(0x0000000100030300)
448#define SH1_MD_DQLP_MMR_DIR_PRIVEC0 0x0000000100030300
449 452
450/* ==================================================================== */ 453/* ==================================================================== */
451/* Register "SH_MD_DQRP_MMR_DIR_PRIVEC0" */ 454/* Register "SH_MD_DQRP_MMR_DIR_PRIVEC0" */
452/* privilege vector for acc=0 */ 455/* privilege vector for acc=0 */
453/* ==================================================================== */ 456/* ==================================================================== */
454 457#define SH1_MD_DQRP_MMR_DIR_PRIVEC0 __IA64_UL_CONST(0x0000000100050300)
455#define SH1_MD_DQRP_MMR_DIR_PRIVEC0 0x0000000100050300
456 458
457/* ==================================================================== */ 459/* ==================================================================== */
458/* Some MMRs are functionally identical (or close enough) on both SHUB1 */ 460/* Some MMRs are functionally identical (or close enough) on both SHUB1 */
@@ -484,17 +486,17 @@
484/* Engine 0 Control and Status Register */ 486/* Engine 0 Control and Status Register */
485/* ========================================================================== */ 487/* ========================================================================== */
486 488
487#define SH2_BT_ENG_CSR_0 0x0000000030040000 489#define SH2_BT_ENG_CSR_0 __IA64_UL_CONST(0x0000000030040000)
488#define SH2_BT_ENG_SRC_ADDR_0 0x0000000030040080 490#define SH2_BT_ENG_SRC_ADDR_0 __IA64_UL_CONST(0x0000000030040080)
489#define SH2_BT_ENG_DEST_ADDR_0 0x0000000030040100 491#define SH2_BT_ENG_DEST_ADDR_0 __IA64_UL_CONST(0x0000000030040100)
490#define SH2_BT_ENG_NOTIF_ADDR_0 0x0000000030040180 492#define SH2_BT_ENG_NOTIF_ADDR_0 __IA64_UL_CONST(0x0000000030040180)
491 493
492/* ========================================================================== */ 494/* ========================================================================== */
493/* BTE interfaces 1-3 */ 495/* BTE interfaces 1-3 */
494/* ========================================================================== */ 496/* ========================================================================== */
495 497
496#define SH2_BT_ENG_CSR_1 0x0000000030050000 498#define SH2_BT_ENG_CSR_1 __IA64_UL_CONST(0x0000000030050000)
497#define SH2_BT_ENG_CSR_2 0x0000000030060000 499#define SH2_BT_ENG_CSR_2 __IA64_UL_CONST(0x0000000030060000)
498#define SH2_BT_ENG_CSR_3 0x0000000030070000 500#define SH2_BT_ENG_CSR_3 __IA64_UL_CONST(0x0000000030070000)
499 501
500#endif /* _ASM_IA64_SN_SHUB_MMR_H */ 502#endif /* _ASM_IA64_SN_SHUB_MMR_H */
diff --git a/include/asm-ia64/sn/simulator.h b/include/asm-ia64/sn/simulator.h
index 78eb4f869c8b..cf770e246af5 100644
--- a/include/asm-ia64/sn/simulator.h
+++ b/include/asm-ia64/sn/simulator.h
@@ -10,16 +10,17 @@
10 10
11#include <linux/config.h> 11#include <linux/config.h>
12 12
13#ifdef CONFIG_IA64_SGI_SN_SIM
14
15#define SNMAGIC 0xaeeeeeee8badbeefL 13#define SNMAGIC 0xaeeeeeee8badbeefL
16#define IS_RUNNING_ON_SIMULATOR() ({long sn; asm("mov %0=cpuid[%1]" : "=r"(sn) : "r"(2)); sn == SNMAGIC;}) 14#define IS_MEDUSA() ({long sn; asm("mov %0=cpuid[%1]" : "=r"(sn) : "r"(2)); sn == SNMAGIC;})
17
18#define SIMULATOR_SLEEP() asm("nop.i 0x8beef")
19 15
16#ifdef CONFIG_IA64_SGI_SN_SIM
17#define SIMULATOR_SLEEP() asm("nop.i 0x8beef")
18#define IS_RUNNING_ON_SIMULATOR() (sn_prom_type)
19#define IS_RUNNING_ON_FAKE_PROM() (sn_prom_type == 2)
20extern int sn_prom_type; /* 0=hardware, 1=medusa/realprom, 2=medusa/fakeprom */
20#else 21#else
21
22#define IS_RUNNING_ON_SIMULATOR() (0) 22#define IS_RUNNING_ON_SIMULATOR() (0)
23#define IS_RUNNING_ON_FAKE_PROM() (0)
23#define SIMULATOR_SLEEP() 24#define SIMULATOR_SLEEP()
24 25
25#endif 26#endif
diff --git a/include/asm-ia64/sn/sn2/sn_hwperf.h b/include/asm-ia64/sn/sn2/sn_hwperf.h
index b0c4d6dd77ba..df75f4c4aec3 100644
--- a/include/asm-ia64/sn/sn2/sn_hwperf.h
+++ b/include/asm-ia64/sn/sn2/sn_hwperf.h
@@ -223,4 +223,6 @@ struct sn_hwperf_ioctl_args {
223#define SN_HWPERF_OP_RECONFIGURE 253 223#define SN_HWPERF_OP_RECONFIGURE 253
224#define SN_HWPERF_OP_INVAL 254 224#define SN_HWPERF_OP_INVAL 254
225 225
226int sn_topology_open(struct inode *inode, struct file *file);
227int sn_topology_release(struct inode *inode, struct file *file);
226#endif /* SN_HWPERF_H */ 228#endif /* SN_HWPERF_H */
diff --git a/include/asm-ia64/sn/sn_sal.h b/include/asm-ia64/sn/sn_sal.h
index eb0395ad0d6a..1455375d2ce4 100644
--- a/include/asm-ia64/sn/sn_sal.h
+++ b/include/asm-ia64/sn/sn_sal.h
@@ -132,6 +132,8 @@
132#define SALRET_INVALID_ARG (-2) 132#define SALRET_INVALID_ARG (-2)
133#define SALRET_ERROR (-3) 133#define SALRET_ERROR (-3)
134 134
135#define SN_SAL_FAKE_PROM 0x02009999
136
135 137
136/** 138/**
137 * sn_sal_rev_major - get the major SGI SAL revision number 139 * sn_sal_rev_major - get the major SGI SAL revision number
@@ -1105,4 +1107,12 @@ ia64_sn_bte_recovery(nasid_t nasid)
1105 return (int) rv.status; 1107 return (int) rv.status;
1106} 1108}
1107 1109
1110static inline int
1111ia64_sn_is_fake_prom(void)
1112{
1113 struct ia64_sal_retval rv;
1114 SAL_CALL_NOLOCK(rv, SN_SAL_FAKE_PROM, 0, 0, 0, 0, 0, 0, 0);
1115 return (rv.status == 0);
1116}
1117
1108#endif /* _ASM_IA64_SN_SN_SAL_H */ 1118#endif /* _ASM_IA64_SN_SN_SAL_H */
diff --git a/include/asm-ia64/sn/tioca_provider.h b/include/asm-ia64/sn/tioca_provider.h
index b6acc22ab239..5ccec608d325 100644
--- a/include/asm-ia64/sn/tioca_provider.h
+++ b/include/asm-ia64/sn/tioca_provider.h
@@ -201,6 +201,7 @@ tioca_tlbflush(struct tioca_kernel *tioca_kernel)
201} 201}
202 202
203extern uint32_t tioca_gart_found; 203extern uint32_t tioca_gart_found;
204extern struct list_head tioca_list;
204extern int tioca_init_provider(void); 205extern int tioca_init_provider(void);
205extern void tioca_fastwrite_enable(struct tioca_kernel *tioca_kern); 206extern void tioca_fastwrite_enable(struct tioca_kernel *tioca_kern);
206#endif /* _ASM_IA64_SN_TIO_CA_AGP_PROVIDER_H */ 207#endif /* _ASM_IA64_SN_TIO_CA_AGP_PROVIDER_H */
diff --git a/include/asm-ia64/unistd.h b/include/asm-ia64/unistd.h
index f7f43ec2483a..517f1649ee64 100644
--- a/include/asm-ia64/unistd.h
+++ b/include/asm-ia64/unistd.h
@@ -263,6 +263,8 @@
263#define __NR_add_key 1271 263#define __NR_add_key 1271
264#define __NR_request_key 1272 264#define __NR_request_key 1272
265#define __NR_keyctl 1273 265#define __NR_keyctl 1273
266#define __NR_ioprio_set 1274
267#define __NR_ioprio_get 1275
266#define __NR_set_zone_reclaim 1276 268#define __NR_set_zone_reclaim 1276
267 269
268#ifdef __KERNEL__ 270#ifdef __KERNEL__
diff --git a/include/asm-ia64/vga.h b/include/asm-ia64/vga.h
index 1f446d6841f6..bc3349ffc505 100644
--- a/include/asm-ia64/vga.h
+++ b/include/asm-ia64/vga.h
@@ -14,7 +14,10 @@
14 * videoram directly without any black magic. 14 * videoram directly without any black magic.
15 */ 15 */
16 16
17#define VGA_MAP_MEM(x) ((unsigned long) ioremap((x), 0)) 17extern unsigned long vga_console_iobase;
18extern unsigned long vga_console_membase;
19
20#define VGA_MAP_MEM(x) ((unsigned long) ioremap(vga_console_membase + (x), 0))
18 21
19#define vga_readb(x) (*(x)) 22#define vga_readb(x) (*(x))
20#define vga_writeb(x,y) (*(y) = (x)) 23#define vga_writeb(x,y) (*(y) = (x))
diff --git a/include/asm-m68k/serial.h b/include/asm-m68k/serial.h
index 9f5bcdc105fc..3fe29f8b0194 100644
--- a/include/asm-m68k/serial.h
+++ b/include/asm-m68k/serial.h
@@ -26,54 +26,9 @@
26#define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF 26#define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF
27#endif 27#endif
28 28
29#ifdef CONFIG_SERIAL_MANY_PORTS 29#define SERIAL_PORT_DFNS \
30#define FOURPORT_FLAGS ASYNC_FOURPORT
31#define ACCENT_FLAGS 0
32#define BOCA_FLAGS 0
33#endif
34
35#define STD_SERIAL_PORT_DEFNS \
36 /* UART CLK PORT IRQ FLAGS */ \ 30 /* UART CLK PORT IRQ FLAGS */ \
37 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \ 31 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \
38 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS }, /* ttyS1 */ \ 32 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS }, /* ttyS1 */ \
39 { 0, BASE_BAUD, 0x3E8, 4, STD_COM_FLAGS }, /* ttyS2 */ \ 33 { 0, BASE_BAUD, 0x3E8, 4, STD_COM_FLAGS }, /* ttyS2 */ \
40 { 0, BASE_BAUD, 0x2E8, 3, STD_COM4_FLAGS }, /* ttyS3 */ 34 { 0, BASE_BAUD, 0x2E8, 3, STD_COM4_FLAGS }, /* ttyS3 */
41
42
43#ifdef CONFIG_SERIAL_MANY_PORTS
44#define EXTRA_SERIAL_PORT_DEFNS \
45 { 0, BASE_BAUD, 0x1A0, 9, FOURPORT_FLAGS }, /* ttyS4 */ \
46 { 0, BASE_BAUD, 0x1A8, 9, FOURPORT_FLAGS }, /* ttyS5 */ \
47 { 0, BASE_BAUD, 0x1B0, 9, FOURPORT_FLAGS }, /* ttyS6 */ \
48 { 0, BASE_BAUD, 0x1B8, 9, FOURPORT_FLAGS }, /* ttyS7 */ \
49 { 0, BASE_BAUD, 0x2A0, 5, FOURPORT_FLAGS }, /* ttyS8 */ \
50 { 0, BASE_BAUD, 0x2A8, 5, FOURPORT_FLAGS }, /* ttyS9 */ \
51 { 0, BASE_BAUD, 0x2B0, 5, FOURPORT_FLAGS }, /* ttyS10 */ \
52 { 0, BASE_BAUD, 0x2B8, 5, FOURPORT_FLAGS }, /* ttyS11 */ \
53 { 0, BASE_BAUD, 0x330, 4, ACCENT_FLAGS }, /* ttyS12 */ \
54 { 0, BASE_BAUD, 0x338, 4, ACCENT_FLAGS }, /* ttyS13 */ \
55 { 0, BASE_BAUD, 0x000, 0, 0 }, /* ttyS14 (spare) */ \
56 { 0, BASE_BAUD, 0x000, 0, 0 }, /* ttyS15 (spare) */ \
57 { 0, BASE_BAUD, 0x100, 12, BOCA_FLAGS }, /* ttyS16 */ \
58 { 0, BASE_BAUD, 0x108, 12, BOCA_FLAGS }, /* ttyS17 */ \
59 { 0, BASE_BAUD, 0x110, 12, BOCA_FLAGS }, /* ttyS18 */ \
60 { 0, BASE_BAUD, 0x118, 12, BOCA_FLAGS }, /* ttyS19 */ \
61 { 0, BASE_BAUD, 0x120, 12, BOCA_FLAGS }, /* ttyS20 */ \
62 { 0, BASE_BAUD, 0x128, 12, BOCA_FLAGS }, /* ttyS21 */ \
63 { 0, BASE_BAUD, 0x130, 12, BOCA_FLAGS }, /* ttyS22 */ \
64 { 0, BASE_BAUD, 0x138, 12, BOCA_FLAGS }, /* ttyS23 */ \
65 { 0, BASE_BAUD, 0x140, 12, BOCA_FLAGS }, /* ttyS24 */ \
66 { 0, BASE_BAUD, 0x148, 12, BOCA_FLAGS }, /* ttyS25 */ \
67 { 0, BASE_BAUD, 0x150, 12, BOCA_FLAGS }, /* ttyS26 */ \
68 { 0, BASE_BAUD, 0x158, 12, BOCA_FLAGS }, /* ttyS27 */ \
69 { 0, BASE_BAUD, 0x160, 12, BOCA_FLAGS }, /* ttyS28 */ \
70 { 0, BASE_BAUD, 0x168, 12, BOCA_FLAGS }, /* ttyS29 */ \
71 { 0, BASE_BAUD, 0x170, 12, BOCA_FLAGS }, /* ttyS30 */ \
72 { 0, BASE_BAUD, 0x178, 12, BOCA_FLAGS }, /* ttyS31 */
73#else
74#define EXTRA_SERIAL_PORT_DEFNS
75#endif
76
77#define SERIAL_PORT_DFNS \
78 STD_SERIAL_PORT_DEFNS \
79 EXTRA_SERIAL_PORT_DEFNS
diff --git a/include/asm-mips/pci.h b/include/asm-mips/pci.h
index c9c576b48556..2d323b6e147d 100644
--- a/include/asm-mips/pci.h
+++ b/include/asm-mips/pci.h
@@ -130,6 +130,16 @@ extern void pci_dac_dma_sync_single_for_cpu(struct pci_dev *pdev,
130extern void pci_dac_dma_sync_single_for_device(struct pci_dev *pdev, 130extern void pci_dac_dma_sync_single_for_device(struct pci_dev *pdev,
131 dma64_addr_t dma_addr, size_t len, int direction); 131 dma64_addr_t dma_addr, size_t len, int direction);
132 132
133#ifdef CONFIG_PCI
134static inline void pci_dma_burst_advice(struct pci_dev *pdev,
135 enum pci_dma_burst_strategy *strat,
136 unsigned long *strategy_parameter)
137{
138 *strat = PCI_DMA_BURST_INFINITY;
139 *strategy_parameter = ~0UL;
140}
141#endif
142
133extern void pcibios_resource_to_bus(struct pci_dev *dev, 143extern void pcibios_resource_to_bus(struct pci_dev *dev,
134 struct pci_bus_region *region, struct resource *res); 144 struct pci_bus_region *region, struct resource *res);
135 145
diff --git a/include/asm-mips/serial.h b/include/asm-mips/serial.h
index 8a70ff58f760..4eed8e2acdc3 100644
--- a/include/asm-mips/serial.h
+++ b/include/asm-mips/serial.h
@@ -29,32 +29,6 @@
29#define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF 29#define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF
30#endif 30#endif
31 31
32#ifdef CONFIG_SERIAL_MANY_PORTS
33#define FOURPORT_FLAGS ASYNC_FOURPORT
34#define ACCENT_FLAGS 0
35#define BOCA_FLAGS 0
36#define HUB6_FLAGS 0
37#define RS_TABLE_SIZE 64
38#else
39#define RS_TABLE_SIZE
40#endif
41
42/*
43 * The following define the access methods for the HUB6 card. All
44 * access is through two ports for all 24 possible chips. The card is
45 * selected through the high 2 bits, the port on that card with the
46 * "middle" 3 bits, and the register on that port with the bottom
47 * 3 bits.
48 *
49 * While the access port and interrupt is configurable, the default
50 * port locations are 0x302 for the port control register, and 0x303
51 * for the data read/write register. Normally, the interrupt is at irq3
52 * but can be anything from 3 to 7 inclusive. Note that using 3 will
53 * require disabling com2.
54 */
55
56#define C_P(card,port) (((card)<<6|(port)<<3) + 1)
57
58#ifdef CONFIG_MACH_JAZZ 32#ifdef CONFIG_MACH_JAZZ
59#include <asm/jazz.h> 33#include <asm/jazz.h>
60 34
@@ -240,66 +214,10 @@
240 { 0, BASE_BAUD, 0x3E8, 4, STD_COM_FLAGS }, /* ttyS2 */ \ 214 { 0, BASE_BAUD, 0x3E8, 4, STD_COM_FLAGS }, /* ttyS2 */ \
241 { 0, BASE_BAUD, 0x2E8, 3, STD_COM4_FLAGS }, /* ttyS3 */ 215 { 0, BASE_BAUD, 0x2E8, 3, STD_COM4_FLAGS }, /* ttyS3 */
242 216
243#ifdef CONFIG_SERIAL_MANY_PORTS
244#define EXTRA_SERIAL_PORT_DEFNS \
245 { 0, BASE_BAUD, 0x1A0, 9, FOURPORT_FLAGS }, /* ttyS4 */ \
246 { 0, BASE_BAUD, 0x1A8, 9, FOURPORT_FLAGS }, /* ttyS5 */ \
247 { 0, BASE_BAUD, 0x1B0, 9, FOURPORT_FLAGS }, /* ttyS6 */ \
248 { 0, BASE_BAUD, 0x1B8, 9, FOURPORT_FLAGS }, /* ttyS7 */ \
249 { 0, BASE_BAUD, 0x2A0, 5, FOURPORT_FLAGS }, /* ttyS8 */ \
250 { 0, BASE_BAUD, 0x2A8, 5, FOURPORT_FLAGS }, /* ttyS9 */ \
251 { 0, BASE_BAUD, 0x2B0, 5, FOURPORT_FLAGS }, /* ttyS10 */ \
252 { 0, BASE_BAUD, 0x2B8, 5, FOURPORT_FLAGS }, /* ttyS11 */ \
253 { 0, BASE_BAUD, 0x330, 4, ACCENT_FLAGS }, /* ttyS12 */ \
254 { 0, BASE_BAUD, 0x338, 4, ACCENT_FLAGS }, /* ttyS13 */ \
255 { 0, BASE_BAUD, 0x000, 0, 0 }, /* ttyS14 (spare) */ \
256 { 0, BASE_BAUD, 0x000, 0, 0 }, /* ttyS15 (spare) */ \
257 { 0, BASE_BAUD, 0x100, 12, BOCA_FLAGS }, /* ttyS16 */ \
258 { 0, BASE_BAUD, 0x108, 12, BOCA_FLAGS }, /* ttyS17 */ \
259 { 0, BASE_BAUD, 0x110, 12, BOCA_FLAGS }, /* ttyS18 */ \
260 { 0, BASE_BAUD, 0x118, 12, BOCA_FLAGS }, /* ttyS19 */ \
261 { 0, BASE_BAUD, 0x120, 12, BOCA_FLAGS }, /* ttyS20 */ \
262 { 0, BASE_BAUD, 0x128, 12, BOCA_FLAGS }, /* ttyS21 */ \
263 { 0, BASE_BAUD, 0x130, 12, BOCA_FLAGS }, /* ttyS22 */ \
264 { 0, BASE_BAUD, 0x138, 12, BOCA_FLAGS }, /* ttyS23 */ \
265 { 0, BASE_BAUD, 0x140, 12, BOCA_FLAGS }, /* ttyS24 */ \
266 { 0, BASE_BAUD, 0x148, 12, BOCA_FLAGS }, /* ttyS25 */ \
267 { 0, BASE_BAUD, 0x150, 12, BOCA_FLAGS }, /* ttyS26 */ \
268 { 0, BASE_BAUD, 0x158, 12, BOCA_FLAGS }, /* ttyS27 */ \
269 { 0, BASE_BAUD, 0x160, 12, BOCA_FLAGS }, /* ttyS28 */ \
270 { 0, BASE_BAUD, 0x168, 12, BOCA_FLAGS }, /* ttyS29 */ \
271 { 0, BASE_BAUD, 0x170, 12, BOCA_FLAGS }, /* ttyS30 */ \
272 { 0, BASE_BAUD, 0x178, 12, BOCA_FLAGS }, /* ttyS31 */
273#else /* CONFIG_SERIAL_MANY_PORTS */
274#define EXTRA_SERIAL_PORT_DEFNS
275#endif /* CONFIG_SERIAL_MANY_PORTS */
276
277#else /* CONFIG_HAVE_STD_PC_SERIAL_PORTS */ 217#else /* CONFIG_HAVE_STD_PC_SERIAL_PORTS */
278#define STD_SERIAL_PORT_DEFNS 218#define STD_SERIAL_PORT_DEFNS
279#define EXTRA_SERIAL_PORT_DEFNS
280#endif /* CONFIG_HAVE_STD_PC_SERIAL_PORTS */ 219#endif /* CONFIG_HAVE_STD_PC_SERIAL_PORTS */
281 220
282/* You can have up to four HUB6's in the system, but I've only
283 * included two cards here for a total of twelve ports.
284 */
285#if (defined(CONFIG_HUB6) && defined(CONFIG_SERIAL_MANY_PORTS))
286#define HUB6_SERIAL_PORT_DFNS \
287 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,0) }, /* ttyS32 */ \
288 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,1) }, /* ttyS33 */ \
289 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,2) }, /* ttyS34 */ \
290 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,3) }, /* ttyS35 */ \
291 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,4) }, /* ttyS36 */ \
292 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,5) }, /* ttyS37 */ \
293 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,0) }, /* ttyS38 */ \
294 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,1) }, /* ttyS39 */ \
295 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,2) }, /* ttyS40 */ \
296 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,3) }, /* ttyS41 */ \
297 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,4) }, /* ttyS42 */ \
298 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,5) }, /* ttyS43 */
299#else
300#define HUB6_SERIAL_PORT_DFNS
301#endif
302
303#ifdef CONFIG_MOMENCO_JAGUAR_ATX 221#ifdef CONFIG_MOMENCO_JAGUAR_ATX
304/* Ordinary NS16552 duart with a 20MHz crystal. */ 222/* Ordinary NS16552 duart with a 20MHz crystal. */
305#define JAGUAR_ATX_UART_CLK 20000000 223#define JAGUAR_ATX_UART_CLK 20000000
@@ -427,8 +345,6 @@
427 COBALT_SERIAL_PORT_DEFNS \ 345 COBALT_SERIAL_PORT_DEFNS \
428 DDB5477_SERIAL_PORT_DEFNS \ 346 DDB5477_SERIAL_PORT_DEFNS \
429 EV96100_SERIAL_PORT_DEFNS \ 347 EV96100_SERIAL_PORT_DEFNS \
430 EXTRA_SERIAL_PORT_DEFNS \
431 HUB6_SERIAL_PORT_DFNS \
432 IP32_SERIAL_PORT_DEFNS \ 348 IP32_SERIAL_PORT_DEFNS \
433 ITE_SERIAL_PORT_DEFNS \ 349 ITE_SERIAL_PORT_DEFNS \
434 IVR_SERIAL_PORT_DEFNS \ 350 IVR_SERIAL_PORT_DEFNS \
diff --git a/include/asm-parisc/pci.h b/include/asm-parisc/pci.h
index 0763c2982fb0..ee741c150176 100644
--- a/include/asm-parisc/pci.h
+++ b/include/asm-parisc/pci.h
@@ -230,6 +230,25 @@ extern inline void pcibios_register_hba(struct pci_hba_data *x)
230/* export the pci_ DMA API in terms of the dma_ one */ 230/* export the pci_ DMA API in terms of the dma_ one */
231#include <asm-generic/pci-dma-compat.h> 231#include <asm-generic/pci-dma-compat.h>
232 232
233#ifdef CONFIG_PCI
234static inline void pci_dma_burst_advice(struct pci_dev *pdev,
235 enum pci_dma_burst_strategy *strat,
236 unsigned long *strategy_parameter)
237{
238 unsigned long cacheline_size;
239 u8 byte;
240
241 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte);
242 if (byte == 0)
243 cacheline_size = 1024;
244 else
245 cacheline_size = (int) byte * 4;
246
247 *strat = PCI_DMA_BURST_MULTIPLE;
248 *strategy_parameter = cacheline_size;
249}
250#endif
251
233extern void 252extern void
234pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region, 253pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
235 struct resource *res); 254 struct resource *res);
diff --git a/include/asm-parisc/serial.h b/include/asm-parisc/serial.h
index 239c5dcab7e6..82fd820d684f 100644
--- a/include/asm-parisc/serial.h
+++ b/include/asm-parisc/serial.h
@@ -19,18 +19,4 @@
19 * A500 w/ PCI serial cards: 5 + 4 * card ~= 17 19 * A500 w/ PCI serial cards: 5 + 4 * card ~= 17
20 */ 20 */
21 21
22#define STD_SERIAL_PORT_DEFNS \ 22#define SERIAL_PORT_DFNS
23 { 0, }, /* ttyS0 */ \
24 { 0, }, /* ttyS1 */ \
25 { 0, }, /* ttyS2 */ \
26 { 0, }, /* ttyS3 */ \
27 { 0, }, /* ttyS4 */ \
28 { 0, }, /* ttyS5 */ \
29 { 0, }, /* ttyS6 */ \
30 { 0, }, /* ttyS7 */ \
31 { 0, }, /* ttyS8 */
32
33
34#define SERIAL_PORT_DFNS \
35 STD_SERIAL_PORT_DEFNS
36
diff --git a/include/asm-ppc/open_pic.h b/include/asm-ppc/open_pic.h
index dbe853319741..7848aa610c05 100644
--- a/include/asm-ppc/open_pic.h
+++ b/include/asm-ppc/open_pic.h
@@ -25,6 +25,11 @@
25#define OPENPIC_VEC_IPI 118 /* and up */ 25#define OPENPIC_VEC_IPI 118 /* and up */
26#define OPENPIC_VEC_SPURIOUS 255 26#define OPENPIC_VEC_SPURIOUS 255
27 27
28/* Priorities */
29#define OPENPIC_PRIORITY_IPI_BASE 10
30#define OPENPIC_PRIORITY_DEFAULT 4
31#define OPENPIC_PRIORITY_NMI 9
32
28/* OpenPIC IRQ controller structure */ 33/* OpenPIC IRQ controller structure */
29extern struct hw_interrupt_type open_pic; 34extern struct hw_interrupt_type open_pic;
30 35
@@ -42,6 +47,7 @@ extern int epic_serial_mode;
42extern void openpic_set_sources(int first_irq, int num_irqs, void __iomem *isr); 47extern void openpic_set_sources(int first_irq, int num_irqs, void __iomem *isr);
43extern void openpic_init(int linux_irq_offset); 48extern void openpic_init(int linux_irq_offset);
44extern void openpic_init_nmi_irq(u_int irq); 49extern void openpic_init_nmi_irq(u_int irq);
50extern void openpic_set_irq_priority(u_int irq, u_int pri);
45extern void openpic_hookup_cascade(u_int irq, char *name, 51extern void openpic_hookup_cascade(u_int irq, char *name,
46 int (*cascade_fn)(struct pt_regs *)); 52 int (*cascade_fn)(struct pt_regs *));
47extern u_int openpic_irq(void); 53extern u_int openpic_irq(void);
diff --git a/include/asm-ppc/pc_serial.h b/include/asm-ppc/pc_serial.h
index fa9cbb67ce3e..8f994f9f8857 100644
--- a/include/asm-ppc/pc_serial.h
+++ b/include/asm-ppc/pc_serial.h
@@ -35,93 +35,9 @@
35#define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF 35#define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF
36#endif 36#endif
37 37
38#ifdef CONFIG_SERIAL_MANY_PORTS 38#define SERIAL_PORT_DFNS \
39#define FOURPORT_FLAGS ASYNC_FOURPORT
40#define ACCENT_FLAGS 0
41#define BOCA_FLAGS 0
42#define HUB6_FLAGS 0
43#endif
44
45/*
46 * The following define the access methods for the HUB6 card. All
47 * access is through two ports for all 24 possible chips. The card is
48 * selected through the high 2 bits, the port on that card with the
49 * "middle" 3 bits, and the register on that port with the bottom
50 * 3 bits.
51 *
52 * While the access port and interrupt is configurable, the default
53 * port locations are 0x302 for the port control register, and 0x303
54 * for the data read/write register. Normally, the interrupt is at irq3
55 * but can be anything from 3 to 7 inclusive. Note that using 3 will
56 * require disabling com2.
57 */
58
59#define C_P(card,port) (((card)<<6|(port)<<3) + 1)
60
61#define STD_SERIAL_PORT_DEFNS \
62 /* UART CLK PORT IRQ FLAGS */ \ 39 /* UART CLK PORT IRQ FLAGS */ \
63 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \ 40 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \
64 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS }, /* ttyS1 */ \ 41 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS }, /* ttyS1 */ \
65 { 0, BASE_BAUD, 0x3E8, 4, STD_COM_FLAGS }, /* ttyS2 */ \ 42 { 0, BASE_BAUD, 0x3E8, 4, STD_COM_FLAGS }, /* ttyS2 */ \
66 { 0, BASE_BAUD, 0x2E8, 3, STD_COM4_FLAGS }, /* ttyS3 */ 43 { 0, BASE_BAUD, 0x2E8, 3, STD_COM4_FLAGS }, /* ttyS3 */
67
68
69#ifdef CONFIG_SERIAL_MANY_PORTS
70#define EXTRA_SERIAL_PORT_DEFNS \
71 { 0, BASE_BAUD, 0x1A0, 9, FOURPORT_FLAGS }, /* ttyS4 */ \
72 { 0, BASE_BAUD, 0x1A8, 9, FOURPORT_FLAGS }, /* ttyS5 */ \
73 { 0, BASE_BAUD, 0x1B0, 9, FOURPORT_FLAGS }, /* ttyS6 */ \
74 { 0, BASE_BAUD, 0x1B8, 9, FOURPORT_FLAGS }, /* ttyS7 */ \
75 { 0, BASE_BAUD, 0x2A0, 5, FOURPORT_FLAGS }, /* ttyS8 */ \
76 { 0, BASE_BAUD, 0x2A8, 5, FOURPORT_FLAGS }, /* ttyS9 */ \
77 { 0, BASE_BAUD, 0x2B0, 5, FOURPORT_FLAGS }, /* ttyS10 */ \
78 { 0, BASE_BAUD, 0x2B8, 5, FOURPORT_FLAGS }, /* ttyS11 */ \
79 { 0, BASE_BAUD, 0x330, 4, ACCENT_FLAGS }, /* ttyS12 */ \
80 { 0, BASE_BAUD, 0x338, 4, ACCENT_FLAGS }, /* ttyS13 */ \
81 { 0, BASE_BAUD, 0x000, 0, 0 }, /* ttyS14 (spare) */ \
82 { 0, BASE_BAUD, 0x000, 0, 0 }, /* ttyS15 (spare) */ \
83 { 0, BASE_BAUD, 0x100, 12, BOCA_FLAGS }, /* ttyS16 */ \
84 { 0, BASE_BAUD, 0x108, 12, BOCA_FLAGS }, /* ttyS17 */ \
85 { 0, BASE_BAUD, 0x110, 12, BOCA_FLAGS }, /* ttyS18 */ \
86 { 0, BASE_BAUD, 0x118, 12, BOCA_FLAGS }, /* ttyS19 */ \
87 { 0, BASE_BAUD, 0x120, 12, BOCA_FLAGS }, /* ttyS20 */ \
88 { 0, BASE_BAUD, 0x128, 12, BOCA_FLAGS }, /* ttyS21 */ \
89 { 0, BASE_BAUD, 0x130, 12, BOCA_FLAGS }, /* ttyS22 */ \
90 { 0, BASE_BAUD, 0x138, 12, BOCA_FLAGS }, /* ttyS23 */ \
91 { 0, BASE_BAUD, 0x140, 12, BOCA_FLAGS }, /* ttyS24 */ \
92 { 0, BASE_BAUD, 0x148, 12, BOCA_FLAGS }, /* ttyS25 */ \
93 { 0, BASE_BAUD, 0x150, 12, BOCA_FLAGS }, /* ttyS26 */ \
94 { 0, BASE_BAUD, 0x158, 12, BOCA_FLAGS }, /* ttyS27 */ \
95 { 0, BASE_BAUD, 0x160, 12, BOCA_FLAGS }, /* ttyS28 */ \
96 { 0, BASE_BAUD, 0x168, 12, BOCA_FLAGS }, /* ttyS29 */ \
97 { 0, BASE_BAUD, 0x170, 12, BOCA_FLAGS }, /* ttyS30 */ \
98 { 0, BASE_BAUD, 0x178, 12, BOCA_FLAGS }, /* ttyS31 */
99#else
100#define EXTRA_SERIAL_PORT_DEFNS
101#endif
102
103/* You can have up to four HUB6's in the system, but I've only
104 * included two cards here for a total of twelve ports.
105 */
106#if (defined(CONFIG_HUB6) && defined(CONFIG_SERIAL_MANY_PORTS))
107#define HUB6_SERIAL_PORT_DFNS \
108 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,0) }, /* ttyS32 */ \
109 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,1) }, /* ttyS33 */ \
110 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,2) }, /* ttyS34 */ \
111 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,3) }, /* ttyS35 */ \
112 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,4) }, /* ttyS36 */ \
113 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,5) }, /* ttyS37 */ \
114 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,0) }, /* ttyS38 */ \
115 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,1) }, /* ttyS39 */ \
116 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,2) }, /* ttyS40 */ \
117 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,3) }, /* ttyS41 */ \
118 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,4) }, /* ttyS42 */ \
119 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,5) }, /* ttyS43 */
120#else
121#define HUB6_SERIAL_PORT_DFNS
122#endif
123
124#define SERIAL_PORT_DFNS \
125 STD_SERIAL_PORT_DEFNS \
126 EXTRA_SERIAL_PORT_DEFNS \
127 HUB6_SERIAL_PORT_DFNS
diff --git a/include/asm-ppc/pci.h b/include/asm-ppc/pci.h
index ce5ae6d048f5..db0a2a0ec74d 100644
--- a/include/asm-ppc/pci.h
+++ b/include/asm-ppc/pci.h
@@ -69,6 +69,16 @@ extern unsigned long pci_bus_to_phys(unsigned int ba, int busnr);
69#define pci_unmap_len(PTR, LEN_NAME) (0) 69#define pci_unmap_len(PTR, LEN_NAME) (0)
70#define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0) 70#define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)
71 71
72#ifdef CONFIG_PCI
73static inline void pci_dma_burst_advice(struct pci_dev *pdev,
74 enum pci_dma_burst_strategy *strat,
75 unsigned long *strategy_parameter)
76{
77 *strat = PCI_DMA_BURST_INFINITY;
78 *strategy_parameter = ~0UL;
79}
80#endif
81
72/* 82/*
73 * At present there are very few 32-bit PPC machines that can have 83 * At present there are very few 32-bit PPC machines that can have
74 * memory above the 4GB point, and we don't support that. 84 * memory above the 4GB point, and we don't support that.
@@ -103,6 +113,12 @@ extern pgprot_t pci_phys_mem_access_prot(struct file *file,
103 unsigned long size, 113 unsigned long size,
104 pgprot_t prot); 114 pgprot_t prot);
105 115
116#define HAVE_ARCH_PCI_RESOURCE_TO_USER
117extern void pci_resource_to_user(const struct pci_dev *dev, int bar,
118 const struct resource *rsrc,
119 u64 *start, u64 *end);
120
121
106#endif /* __KERNEL__ */ 122#endif /* __KERNEL__ */
107 123
108#endif /* __PPC_PCI_H */ 124#endif /* __PPC_PCI_H */
diff --git a/include/asm-ppc/unistd.h b/include/asm-ppc/unistd.h
index cc51e5c9acc2..e8b79220b29c 100644
--- a/include/asm-ppc/unistd.h
+++ b/include/asm-ppc/unistd.h
@@ -277,8 +277,10 @@
277#define __NR_request_key 270 277#define __NR_request_key 270
278#define __NR_keyctl 271 278#define __NR_keyctl 271
279#define __NR_waitid 272 279#define __NR_waitid 272
280#define __NR_ioprio_set 273
281#define __NR_ioprio_get 274
280 282
281#define __NR_syscalls 273 283#define __NR_syscalls 275
282 284
283#define __NR(n) #n 285#define __NR(n) #n
284 286
diff --git a/include/asm-ppc64/byteorder.h b/include/asm-ppc64/byteorder.h
index 80327532de64..8b57da62b674 100644
--- a/include/asm-ppc64/byteorder.h
+++ b/include/asm-ppc64/byteorder.h
@@ -40,7 +40,6 @@ static __inline__ void st_le32(volatile __u32 *addr, const __u32 val)
40 __asm__ __volatile__ ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr)); 40 __asm__ __volatile__ ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
41} 41}
42 42
43#if 0
44static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 value) 43static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 value)
45{ 44{
46 __u16 result; 45 __u16 result;
@@ -63,17 +62,8 @@ static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 value)
63 return result; 62 return result;
64} 63}
65 64
66static __inline__ __attribute_const__ __u64 ___arch__swab64(__u64 value)
67{
68 __u64 result;
69#error implement me
70}
71
72#define __arch__swab16(x) ___arch__swab16(x) 65#define __arch__swab16(x) ___arch__swab16(x)
73#define __arch__swab32(x) ___arch__swab32(x) 66#define __arch__swab32(x) ___arch__swab32(x)
74#define __arch__swab64(x) ___arch__swab64(x)
75
76#endif
77 67
78/* The same, but returns converted value from the location pointer by addr. */ 68/* The same, but returns converted value from the location pointer by addr. */
79#define __arch__swab16p(addr) ld_le16(addr) 69#define __arch__swab16p(addr) ld_le16(addr)
diff --git a/include/asm-ppc64/kprobes.h b/include/asm-ppc64/kprobes.h
index 19b468bed059..0802919c3235 100644
--- a/include/asm-ppc64/kprobes.h
+++ b/include/asm-ppc64/kprobes.h
@@ -42,10 +42,13 @@ typedef unsigned int kprobe_opcode_t;
42 42
43#define JPROBE_ENTRY(pentry) (kprobe_opcode_t *)((func_descr_t *)pentry) 43#define JPROBE_ENTRY(pentry) (kprobe_opcode_t *)((func_descr_t *)pentry)
44 44
45#define ARCH_SUPPORTS_KRETPROBES
46void kretprobe_trampoline(void);
47
45/* Architecture specific copy of original instruction */ 48/* Architecture specific copy of original instruction */
46struct arch_specific_insn { 49struct arch_specific_insn {
47 /* copy of original instruction */ 50 /* copy of original instruction */
48 kprobe_opcode_t insn[MAX_INSN_SIZE]; 51 kprobe_opcode_t *insn;
49}; 52};
50 53
51#ifdef CONFIG_KPROBES 54#ifdef CONFIG_KPROBES
diff --git a/include/asm-ppc64/pci.h b/include/asm-ppc64/pci.h
index 6cd593f660a0..d12dfce21e20 100644
--- a/include/asm-ppc64/pci.h
+++ b/include/asm-ppc64/pci.h
@@ -78,6 +78,25 @@ static inline int pci_dac_dma_supported(struct pci_dev *hwdev,u64 mask)
78 return 0; 78 return 0;
79} 79}
80 80
81#ifdef CONFIG_PCI
82static inline void pci_dma_burst_advice(struct pci_dev *pdev,
83 enum pci_dma_burst_strategy *strat,
84 unsigned long *strategy_parameter)
85{
86 unsigned long cacheline_size;
87 u8 byte;
88
89 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte);
90 if (byte == 0)
91 cacheline_size = 1024;
92 else
93 cacheline_size = (int) byte * 4;
94
95 *strat = PCI_DMA_BURST_MULTIPLE;
96 *strategy_parameter = cacheline_size;
97}
98#endif
99
81extern int pci_domain_nr(struct pci_bus *bus); 100extern int pci_domain_nr(struct pci_bus *bus);
82 101
83/* Decide whether to display the domain number in /proc */ 102/* Decide whether to display the domain number in /proc */
@@ -136,6 +155,13 @@ extern pgprot_t pci_phys_mem_access_prot(struct file *file,
136 unsigned long size, 155 unsigned long size,
137 pgprot_t prot); 156 pgprot_t prot);
138 157
158#ifdef CONFIG_PPC_MULTIPLATFORM
159#define HAVE_ARCH_PCI_RESOURCE_TO_USER
160extern void pci_resource_to_user(const struct pci_dev *dev, int bar,
161 const struct resource *rsrc,
162 u64 *start, u64 *end);
163#endif /* CONFIG_PPC_MULTIPLATFORM */
164
139 165
140#endif /* __KERNEL__ */ 166#endif /* __KERNEL__ */
141 167
diff --git a/include/asm-sh/bigsur/serial.h b/include/asm-sh/bigsur/serial.h
index 540f12205923..7233af42f755 100644
--- a/include/asm-sh/bigsur/serial.h
+++ b/include/asm-sh/bigsur/serial.h
@@ -14,13 +14,10 @@
14#define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST) 14#define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
15 15
16 16
17#define STD_SERIAL_PORT_DEFNS \ 17#define SERIAL_PORT_DFNS \
18 /* UART CLK PORT IRQ FLAGS */ \ 18 /* UART CLK PORT IRQ FLAGS */ \
19 { 0, BASE_BAUD, 0x3F8, HD64465_IRQ_UART, STD_COM_FLAGS } /* ttyS0 */ 19 { 0, BASE_BAUD, 0x3F8, HD64465_IRQ_UART, STD_COM_FLAGS } /* ttyS0 */
20 20
21
22#define SERIAL_PORT_DFNS STD_SERIAL_PORT_DEFNS
23
24/* XXX: This should be moved ino irq.h */ 21/* XXX: This should be moved ino irq.h */
25#define irq_cannonicalize(x) (x) 22#define irq_cannonicalize(x) (x)
26 23
diff --git a/include/asm-sh/ec3104/serial.h b/include/asm-sh/ec3104/serial.h
index f8eb16312ed9..cfe4d78ec1ee 100644
--- a/include/asm-sh/ec3104/serial.h
+++ b/include/asm-sh/ec3104/serial.h
@@ -10,13 +10,11 @@
10 * it's got the keyboard controller behind it so we can't really use it 10 * it's got the keyboard controller behind it so we can't really use it
11 * (without moving the keyboard driver to userspace, which doesn't sound 11 * (without moving the keyboard driver to userspace, which doesn't sound
12 * like a very good idea) */ 12 * like a very good idea) */
13#define STD_SERIAL_PORT_DEFNS \ 13#define SERIAL_PORT_DFNS \
14 /* UART CLK PORT IRQ FLAGS */ \ 14 /* UART CLK PORT IRQ FLAGS */ \
15 { 0, BASE_BAUD, 0x11C00, EC3104_IRQBASE+7, STD_COM_FLAGS }, /* ttyS0 */ \ 15 { 0, BASE_BAUD, 0x11C00, EC3104_IRQBASE+7, STD_COM_FLAGS }, /* ttyS0 */ \
16 { 0, BASE_BAUD, 0x12000, EC3104_IRQBASE+8, STD_COM_FLAGS }, /* ttyS1 */ \ 16 { 0, BASE_BAUD, 0x12000, EC3104_IRQBASE+8, STD_COM_FLAGS }, /* ttyS1 */ \
17 { 0, BASE_BAUD, 0x12400, EC3104_IRQBASE+9, STD_COM_FLAGS }, /* ttyS2 */ 17 { 0, BASE_BAUD, 0x12400, EC3104_IRQBASE+9, STD_COM_FLAGS }, /* ttyS2 */
18 18
19#define SERIAL_PORT_DFNS STD_SERIAL_PORT_DEFNS
20
21/* XXX: This should be moved ino irq.h */ 19/* XXX: This should be moved ino irq.h */
22#define irq_cannonicalize(x) (x) 20#define irq_cannonicalize(x) (x)
diff --git a/include/asm-sh/pci.h b/include/asm-sh/pci.h
index 9c3b63d0105e..26044889c770 100644
--- a/include/asm-sh/pci.h
+++ b/include/asm-sh/pci.h
@@ -96,6 +96,16 @@ static inline void pcibios_penalize_isa_irq(int irq)
96#define sg_dma_address(sg) (virt_to_bus((sg)->dma_address)) 96#define sg_dma_address(sg) (virt_to_bus((sg)->dma_address))
97#define sg_dma_len(sg) ((sg)->length) 97#define sg_dma_len(sg) ((sg)->length)
98 98
99#ifdef CONFIG_PCI
100static inline void pci_dma_burst_advice(struct pci_dev *pdev,
101 enum pci_dma_burst_strategy *strat,
102 unsigned long *strategy_parameter)
103{
104 *strat = PCI_DMA_BURST_INFINITY;
105 *strategy_parameter = ~0UL;
106}
107#endif
108
99/* Board-specific fixup routines. */ 109/* Board-specific fixup routines. */
100extern void pcibios_fixup(void); 110extern void pcibios_fixup(void);
101extern void pcibios_fixup_irqs(void); 111extern void pcibios_fixup_irqs(void);
diff --git a/include/asm-sh/serial.h b/include/asm-sh/serial.h
index 5474dbdbaa86..f51e232d5cd9 100644
--- a/include/asm-sh/serial.h
+++ b/include/asm-sh/serial.h
@@ -29,20 +29,18 @@
29#ifdef CONFIG_HD64465 29#ifdef CONFIG_HD64465
30#include <asm/hd64465.h> 30#include <asm/hd64465.h>
31 31
32#define STD_SERIAL_PORT_DEFNS \ 32#define SERIAL_PORT_DFNS \
33 /* UART CLK PORT IRQ FLAGS */ \ 33 /* UART CLK PORT IRQ FLAGS */ \
34 { 0, BASE_BAUD, 0x3F8, HD64465_IRQ_UART, STD_COM_FLAGS } /* ttyS0 */ 34 { 0, BASE_BAUD, 0x3F8, HD64465_IRQ_UART, STD_COM_FLAGS } /* ttyS0 */
35 35
36#else 36#else
37 37
38#define STD_SERIAL_PORT_DEFNS \ 38#define SERIAL_PORT_DFNS \
39 /* UART CLK PORT IRQ FLAGS */ \ 39 /* UART CLK PORT IRQ FLAGS */ \
40 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \ 40 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \
41 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS } /* ttyS1 */ 41 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS } /* ttyS1 */
42 42
43#endif 43#endif
44 44
45#define SERIAL_PORT_DFNS STD_SERIAL_PORT_DEFNS
46
47#endif 45#endif
48#endif /* _ASM_SERIAL_H */ 46#endif /* _ASM_SERIAL_H */
diff --git a/include/asm-sh64/pci.h b/include/asm-sh64/pci.h
index 8cc14e139750..c68870e02d91 100644
--- a/include/asm-sh64/pci.h
+++ b/include/asm-sh64/pci.h
@@ -86,6 +86,16 @@ static inline void pcibios_penalize_isa_irq(int irq)
86#define sg_dma_address(sg) ((sg)->dma_address) 86#define sg_dma_address(sg) ((sg)->dma_address)
87#define sg_dma_len(sg) ((sg)->length) 87#define sg_dma_len(sg) ((sg)->length)
88 88
89#ifdef CONFIG_PCI
90static inline void pci_dma_burst_advice(struct pci_dev *pdev,
91 enum pci_dma_burst_strategy *strat,
92 unsigned long *strategy_parameter)
93{
94 *strat = PCI_DMA_BURST_INFINITY;
95 *strategy_parameter = ~0UL;
96}
97#endif
98
89/* Board-specific fixup routines. */ 99/* Board-specific fixup routines. */
90extern void pcibios_fixup(void); 100extern void pcibios_fixup(void);
91extern void pcibios_fixup_irqs(void); 101extern void pcibios_fixup_irqs(void);
diff --git a/include/asm-sh64/serial.h b/include/asm-sh64/serial.h
index 8e39b4e90c76..29c9be15112b 100644
--- a/include/asm-sh64/serial.h
+++ b/include/asm-sh64/serial.h
@@ -20,13 +20,11 @@
20 20
21#define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST) 21#define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
22 22
23#define STD_SERIAL_PORT_DEFNS \ 23#define SERIAL_PORT_DFNS \
24 /* UART CLK PORT IRQ FLAGS */ \ 24 /* UART CLK PORT IRQ FLAGS */ \
25 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \ 25 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \
26 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS } /* ttyS1 */ 26 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS } /* ttyS1 */
27 27
28#define SERIAL_PORT_DFNS STD_SERIAL_PORT_DEFNS
29
30/* XXX: This should be moved ino irq.h */ 28/* XXX: This should be moved ino irq.h */
31#define irq_cannonicalize(x) (x) 29#define irq_cannonicalize(x) (x)
32 30
diff --git a/include/asm-sparc/pci.h b/include/asm-sparc/pci.h
index d200a25a7373..44bb38758c96 100644
--- a/include/asm-sparc/pci.h
+++ b/include/asm-sparc/pci.h
@@ -144,6 +144,16 @@ extern inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
144 144
145#define pci_dac_dma_supported(dev, mask) (0) 145#define pci_dac_dma_supported(dev, mask) (0)
146 146
147#ifdef CONFIG_PCI
148static inline void pci_dma_burst_advice(struct pci_dev *pdev,
149 enum pci_dma_burst_strategy *strat,
150 unsigned long *strategy_parameter)
151{
152 *strat = PCI_DMA_BURST_INFINITY;
153 *strategy_parameter = ~0UL;
154}
155#endif
156
147static inline void pcibios_add_platform_entries(struct pci_dev *dev) 157static inline void pcibios_add_platform_entries(struct pci_dev *dev)
148{ 158{
149} 159}
diff --git a/include/asm-sparc64/auxio.h b/include/asm-sparc64/auxio.h
index 5eb01dd47150..81a590a50a1f 100644
--- a/include/asm-sparc64/auxio.h
+++ b/include/asm-sparc64/auxio.h
@@ -75,6 +75,8 @@
75 75
76#ifndef __ASSEMBLY__ 76#ifndef __ASSEMBLY__
77 77
78extern void __iomem *auxio_register;
79
78#define AUXIO_LTE_ON 1 80#define AUXIO_LTE_ON 1
79#define AUXIO_LTE_OFF 0 81#define AUXIO_LTE_OFF 0
80 82
diff --git a/include/asm-sparc64/floppy.h b/include/asm-sparc64/floppy.h
index e071b4b4edfd..49d49a285943 100644
--- a/include/asm-sparc64/floppy.h
+++ b/include/asm-sparc64/floppy.h
@@ -159,7 +159,7 @@ static void sun_82077_fd_outb(unsigned char value, unsigned long port)
159 * underruns. If non-zero, doing_pdma encodes the direction of 159 * underruns. If non-zero, doing_pdma encodes the direction of
160 * the transfer for debugging. 1=read 2=write 160 * the transfer for debugging. 1=read 2=write
161 */ 161 */
162char *pdma_vaddr; 162unsigned char *pdma_vaddr;
163unsigned long pdma_size; 163unsigned long pdma_size;
164volatile int doing_pdma = 0; 164volatile int doing_pdma = 0;
165 165
@@ -209,8 +209,7 @@ static void sun_fd_enable_dma(void)
209 pdma_areasize = pdma_size; 209 pdma_areasize = pdma_size;
210} 210}
211 211
212/* Our low-level entry point in arch/sparc/kernel/entry.S */ 212extern irqreturn_t sparc_floppy_irq(int, void *, struct pt_regs *);
213extern irqreturn_t floppy_hardint(int irq, void *unused, struct pt_regs *regs);
214 213
215static int sun_fd_request_irq(void) 214static int sun_fd_request_irq(void)
216{ 215{
@@ -220,8 +219,8 @@ static int sun_fd_request_irq(void)
220 if(!once) { 219 if(!once) {
221 once = 1; 220 once = 1;
222 221
223 error = request_fast_irq(FLOPPY_IRQ, floppy_hardint, 222 error = request_irq(FLOPPY_IRQ, sparc_floppy_irq,
224 SA_INTERRUPT, "floppy", NULL); 223 SA_INTERRUPT, "floppy", NULL);
225 224
226 return ((error == 0) ? 0 : -1); 225 return ((error == 0) ? 0 : -1);
227 } 226 }
@@ -615,7 +614,7 @@ static unsigned long __init sun_floppy_init(void)
615 struct linux_ebus *ebus; 614 struct linux_ebus *ebus;
616 struct linux_ebus_device *edev = NULL; 615 struct linux_ebus_device *edev = NULL;
617 unsigned long config = 0; 616 unsigned long config = 0;
618 unsigned long auxio_reg; 617 void __iomem *auxio_reg;
619 618
620 for_each_ebus(ebus) { 619 for_each_ebus(ebus) {
621 for_each_ebusdev(edev, ebus) { 620 for_each_ebusdev(edev, ebus) {
@@ -642,7 +641,7 @@ static unsigned long __init sun_floppy_init(void)
642 /* Make sure the high density bit is set, some systems 641 /* Make sure the high density bit is set, some systems
643 * (most notably Ultra5/Ultra10) come up with it clear. 642 * (most notably Ultra5/Ultra10) come up with it clear.
644 */ 643 */
645 auxio_reg = edev->resource[2].start; 644 auxio_reg = (void __iomem *) edev->resource[2].start;
646 writel(readl(auxio_reg)|0x2, auxio_reg); 645 writel(readl(auxio_reg)|0x2, auxio_reg);
647 646
648 sun_pci_ebus_dev = ebus->self; 647 sun_pci_ebus_dev = ebus->self;
@@ -650,7 +649,8 @@ static unsigned long __init sun_floppy_init(void)
650 spin_lock_init(&sun_pci_fd_ebus_dma.lock); 649 spin_lock_init(&sun_pci_fd_ebus_dma.lock);
651 650
652 /* XXX ioremap */ 651 /* XXX ioremap */
653 sun_pci_fd_ebus_dma.regs = edev->resource[1].start; 652 sun_pci_fd_ebus_dma.regs = (void __iomem *)
653 edev->resource[1].start;
654 if (!sun_pci_fd_ebus_dma.regs) 654 if (!sun_pci_fd_ebus_dma.regs)
655 return 0; 655 return 0;
656 656
diff --git a/include/asm-sparc64/irq.h b/include/asm-sparc64/irq.h
index 3aef0ca67750..018e2e46082b 100644
--- a/include/asm-sparc64/irq.h
+++ b/include/asm-sparc64/irq.h
@@ -19,7 +19,7 @@
19/* You should not mess with this directly. That's the job of irq.c. 19/* You should not mess with this directly. That's the job of irq.c.
20 * 20 *
21 * If you make changes here, please update hand coded assembler of 21 * If you make changes here, please update hand coded assembler of
22 * SBUS/floppy interrupt handler in entry.S -DaveM 22 * the vectored interrupt trap handler in entry.S -DaveM
23 * 23 *
24 * This is currently one DCACHE line, two buckets per L2 cache 24 * This is currently one DCACHE line, two buckets per L2 cache
25 * line. Keep this in mind please. 25 * line. Keep this in mind please.
@@ -122,11 +122,6 @@ extern void enable_irq(unsigned int);
122extern unsigned int build_irq(int pil, int inofixup, unsigned long iclr, unsigned long imap); 122extern unsigned int build_irq(int pil, int inofixup, unsigned long iclr, unsigned long imap);
123extern unsigned int sbus_build_irq(void *sbus, unsigned int ino); 123extern unsigned int sbus_build_irq(void *sbus, unsigned int ino);
124 124
125extern int request_fast_irq(unsigned int irq,
126 irqreturn_t (*handler)(int, void *, struct pt_regs *),
127 unsigned long flags, __const__ char *devname,
128 void *dev_id);
129
130static __inline__ void set_softint(unsigned long bits) 125static __inline__ void set_softint(unsigned long bits)
131{ 126{
132 __asm__ __volatile__("wr %0, 0x0, %%set_softint" 127 __asm__ __volatile__("wr %0, 0x0, %%set_softint"
diff --git a/include/asm-sparc64/pci.h b/include/asm-sparc64/pci.h
index 2a0c85cd1c11..84e41c1ef3f8 100644
--- a/include/asm-sparc64/pci.h
+++ b/include/asm-sparc64/pci.h
@@ -220,6 +220,25 @@ static inline int pci_dma_mapping_error(dma_addr_t dma_addr)
220 return (dma_addr == PCI_DMA_ERROR_CODE); 220 return (dma_addr == PCI_DMA_ERROR_CODE);
221} 221}
222 222
223#ifdef CONFIG_PCI
224static inline void pci_dma_burst_advice(struct pci_dev *pdev,
225 enum pci_dma_burst_strategy *strat,
226 unsigned long *strategy_parameter)
227{
228 unsigned long cacheline_size;
229 u8 byte;
230
231 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte);
232 if (byte == 0)
233 cacheline_size = 1024;
234 else
235 cacheline_size = (int) byte * 4;
236
237 *strat = PCI_DMA_BURST_BOUNDARY;
238 *strategy_parameter = cacheline_size;
239}
240#endif
241
223/* Return the index of the PCI controller for device PDEV. */ 242/* Return the index of the PCI controller for device PDEV. */
224 243
225extern int pci_domain_nr(struct pci_bus *bus); 244extern int pci_domain_nr(struct pci_bus *bus);
diff --git a/include/asm-sparc64/rwsem.h b/include/asm-sparc64/rwsem.h
index bf2ae90ed3df..a1cc94f95984 100644
--- a/include/asm-sparc64/rwsem.h
+++ b/include/asm-sparc64/rwsem.h
@@ -55,8 +55,9 @@ static __inline__ int rwsem_atomic_update(int delta, struct rw_semaphore *sem)
55 "add %%g1, %1, %%g7\n\t" 55 "add %%g1, %1, %%g7\n\t"
56 "cas [%2], %%g1, %%g7\n\t" 56 "cas [%2], %%g1, %%g7\n\t"
57 "cmp %%g1, %%g7\n\t" 57 "cmp %%g1, %%g7\n\t"
58 "membar #StoreLoad | #StoreStore\n\t"
58 "bne,pn %%icc, 1b\n\t" 59 "bne,pn %%icc, 1b\n\t"
59 " membar #StoreLoad | #StoreStore\n\t" 60 " nop\n\t"
60 "mov %%g7, %0\n\t" 61 "mov %%g7, %0\n\t"
61 : "=&r" (tmp) 62 : "=&r" (tmp)
62 : "0" (tmp), "r" (sem) 63 : "0" (tmp), "r" (sem)
diff --git a/include/asm-sparc64/spinlock.h b/include/asm-sparc64/spinlock.h
index db7581bdb531..9cb93a5c2b4f 100644
--- a/include/asm-sparc64/spinlock.h
+++ b/include/asm-sparc64/spinlock.h
@@ -52,12 +52,14 @@ static inline void _raw_spin_lock(spinlock_t *lock)
52 52
53 __asm__ __volatile__( 53 __asm__ __volatile__(
54"1: ldstub [%1], %0\n" 54"1: ldstub [%1], %0\n"
55" membar #StoreLoad | #StoreStore\n"
55" brnz,pn %0, 2f\n" 56" brnz,pn %0, 2f\n"
56" membar #StoreLoad | #StoreStore\n" 57" nop\n"
57" .subsection 2\n" 58" .subsection 2\n"
58"2: ldub [%1], %0\n" 59"2: ldub [%1], %0\n"
60" membar #LoadLoad\n"
59" brnz,pt %0, 2b\n" 61" brnz,pt %0, 2b\n"
60" membar #LoadLoad\n" 62" nop\n"
61" ba,a,pt %%xcc, 1b\n" 63" ba,a,pt %%xcc, 1b\n"
62" .previous" 64" .previous"
63 : "=&r" (tmp) 65 : "=&r" (tmp)
@@ -95,16 +97,18 @@ static inline void _raw_spin_lock_flags(spinlock_t *lock, unsigned long flags)
95 97
96 __asm__ __volatile__( 98 __asm__ __volatile__(
97"1: ldstub [%2], %0\n" 99"1: ldstub [%2], %0\n"
98" brnz,pn %0, 2f\n"
99" membar #StoreLoad | #StoreStore\n" 100" membar #StoreLoad | #StoreStore\n"
101" brnz,pn %0, 2f\n"
102" nop\n"
100" .subsection 2\n" 103" .subsection 2\n"
101"2: rdpr %%pil, %1\n" 104"2: rdpr %%pil, %1\n"
102" wrpr %3, %%pil\n" 105" wrpr %3, %%pil\n"
103"3: ldub [%2], %0\n" 106"3: ldub [%2], %0\n"
104" brnz,pt %0, 3b\n"
105" membar #LoadLoad\n" 107" membar #LoadLoad\n"
108" brnz,pt %0, 3b\n"
109" nop\n"
106" ba,pt %%xcc, 1b\n" 110" ba,pt %%xcc, 1b\n"
107" wrpr %1, %%pil\n" 111" wrpr %1, %%pil\n"
108" .previous" 112" .previous"
109 : "=&r" (tmp1), "=&r" (tmp2) 113 : "=&r" (tmp1), "=&r" (tmp2)
110 : "r"(lock), "r"(flags) 114 : "r"(lock), "r"(flags)
@@ -162,12 +166,14 @@ static void inline __read_lock(rwlock_t *lock)
162"4: add %0, 1, %1\n" 166"4: add %0, 1, %1\n"
163" cas [%2], %0, %1\n" 167" cas [%2], %0, %1\n"
164" cmp %0, %1\n" 168" cmp %0, %1\n"
169" membar #StoreLoad | #StoreStore\n"
165" bne,pn %%icc, 1b\n" 170" bne,pn %%icc, 1b\n"
166" membar #StoreLoad | #StoreStore\n" 171" nop\n"
167" .subsection 2\n" 172" .subsection 2\n"
168"2: ldsw [%2], %0\n" 173"2: ldsw [%2], %0\n"
174" membar #LoadLoad\n"
169" brlz,pt %0, 2b\n" 175" brlz,pt %0, 2b\n"
170" membar #LoadLoad\n" 176" nop\n"
171" ba,a,pt %%xcc, 4b\n" 177" ba,a,pt %%xcc, 4b\n"
172" .previous" 178" .previous"
173 : "=&r" (tmp1), "=&r" (tmp2) 179 : "=&r" (tmp1), "=&r" (tmp2)
@@ -204,12 +210,14 @@ static void inline __write_lock(rwlock_t *lock)
204"4: or %0, %3, %1\n" 210"4: or %0, %3, %1\n"
205" cas [%2], %0, %1\n" 211" cas [%2], %0, %1\n"
206" cmp %0, %1\n" 212" cmp %0, %1\n"
213" membar #StoreLoad | #StoreStore\n"
207" bne,pn %%icc, 1b\n" 214" bne,pn %%icc, 1b\n"
208" membar #StoreLoad | #StoreStore\n" 215" nop\n"
209" .subsection 2\n" 216" .subsection 2\n"
210"2: lduw [%2], %0\n" 217"2: lduw [%2], %0\n"
218" membar #LoadLoad\n"
211" brnz,pt %0, 2b\n" 219" brnz,pt %0, 2b\n"
212" membar #LoadLoad\n" 220" nop\n"
213" ba,a,pt %%xcc, 4b\n" 221" ba,a,pt %%xcc, 4b\n"
214" .previous" 222" .previous"
215 : "=&r" (tmp1), "=&r" (tmp2) 223 : "=&r" (tmp1), "=&r" (tmp2)
@@ -240,8 +248,9 @@ static int inline __write_trylock(rwlock_t *lock)
240" or %0, %4, %1\n" 248" or %0, %4, %1\n"
241" cas [%3], %0, %1\n" 249" cas [%3], %0, %1\n"
242" cmp %0, %1\n" 250" cmp %0, %1\n"
251" membar #StoreLoad | #StoreStore\n"
243" bne,pn %%icc, 1b\n" 252" bne,pn %%icc, 1b\n"
244" membar #StoreLoad | #StoreStore\n" 253" nop\n"
245" mov 1, %2\n" 254" mov 1, %2\n"
246"2:" 255"2:"
247 : "=&r" (tmp1), "=&r" (tmp2), "=&r" (result) 256 : "=&r" (tmp1), "=&r" (tmp2), "=&r" (result)
diff --git a/include/asm-sparc64/spitfire.h b/include/asm-sparc64/spitfire.h
index 9d7613eea812..1aa932773af8 100644
--- a/include/asm-sparc64/spitfire.h
+++ b/include/asm-sparc64/spitfire.h
@@ -111,7 +111,6 @@ static __inline__ void spitfire_put_dcache_tag(unsigned long addr, unsigned long
111 "membar #Sync" 111 "membar #Sync"
112 : /* No outputs */ 112 : /* No outputs */
113 : "r" (tag), "r" (addr), "i" (ASI_DCACHE_TAG)); 113 : "r" (tag), "r" (addr), "i" (ASI_DCACHE_TAG));
114 __asm__ __volatile__ ("membar #Sync" : : : "memory");
115} 114}
116 115
117/* The instruction cache lines are flushed with this, but note that 116/* The instruction cache lines are flushed with this, but note that
diff --git a/include/asm-v850/pci.h b/include/asm-v850/pci.h
index e41941447b49..8e79be0fe99d 100644
--- a/include/asm-v850/pci.h
+++ b/include/asm-v850/pci.h
@@ -81,6 +81,16 @@ extern void
81pci_free_consistent (struct pci_dev *pdev, size_t size, void *cpu_addr, 81pci_free_consistent (struct pci_dev *pdev, size_t size, void *cpu_addr,
82 dma_addr_t dma_addr); 82 dma_addr_t dma_addr);
83 83
84#ifdef CONFIG_PCI
85static inline void pci_dma_burst_advice(struct pci_dev *pdev,
86 enum pci_dma_burst_strategy *strat,
87 unsigned long *strategy_parameter)
88{
89 *strat = PCI_DMA_BURST_INFINITY;
90 *strategy_parameter = ~0UL;
91}
92#endif
93
84static inline void pcibios_add_platform_entries(struct pci_dev *dev) 94static inline void pcibios_add_platform_entries(struct pci_dev *dev)
85{ 95{
86} 96}
diff --git a/include/asm-x86_64/pci.h b/include/asm-x86_64/pci.h
index 8712520ca47f..c1961db88fac 100644
--- a/include/asm-x86_64/pci.h
+++ b/include/asm-x86_64/pci.h
@@ -123,6 +123,16 @@ pci_dac_dma_sync_single_for_device(struct pci_dev *pdev, dma64_addr_t dma_addr,
123 flush_write_buffers(); 123 flush_write_buffers();
124} 124}
125 125
126#ifdef CONFIG_PCI
127static inline void pci_dma_burst_advice(struct pci_dev *pdev,
128 enum pci_dma_burst_strategy *strat,
129 unsigned long *strategy_parameter)
130{
131 *strat = PCI_DMA_BURST_INFINITY;
132 *strategy_parameter = ~0UL;
133}
134#endif
135
126#define HAVE_PCI_MMAP 136#define HAVE_PCI_MMAP
127extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, 137extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
128 enum pci_mmap_state mmap_state, int write_combine); 138 enum pci_mmap_state mmap_state, int write_combine);
diff --git a/include/asm-x86_64/serial.h b/include/asm-x86_64/serial.h
index dbab232044cd..dc752eafa681 100644
--- a/include/asm-x86_64/serial.h
+++ b/include/asm-x86_64/serial.h
@@ -22,109 +22,9 @@
22#define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF 22#define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF
23#endif 23#endif
24 24
25#ifdef CONFIG_SERIAL_MANY_PORTS 25#define SERIAL_PORT_DFNS \
26#define FOURPORT_FLAGS ASYNC_FOURPORT
27#define ACCENT_FLAGS 0
28#define BOCA_FLAGS 0
29#define HUB6_FLAGS 0
30#endif
31
32#define MCA_COM_FLAGS (STD_COM_FLAGS|ASYNC_BOOT_ONLYMCA)
33
34/*
35 * The following define the access methods for the HUB6 card. All
36 * access is through two ports for all 24 possible chips. The card is
37 * selected through the high 2 bits, the port on that card with the
38 * "middle" 3 bits, and the register on that port with the bottom
39 * 3 bits.
40 *
41 * While the access port and interrupt is configurable, the default
42 * port locations are 0x302 for the port control register, and 0x303
43 * for the data read/write register. Normally, the interrupt is at irq3
44 * but can be anything from 3 to 7 inclusive. Note that using 3 will
45 * require disabling com2.
46 */
47
48#define C_P(card,port) (((card)<<6|(port)<<3) + 1)
49
50#define STD_SERIAL_PORT_DEFNS \
51 /* UART CLK PORT IRQ FLAGS */ \ 26 /* UART CLK PORT IRQ FLAGS */ \
52 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \ 27 { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS }, /* ttyS0 */ \
53 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS }, /* ttyS1 */ \ 28 { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS }, /* ttyS1 */ \
54 { 0, BASE_BAUD, 0x3E8, 4, STD_COM_FLAGS }, /* ttyS2 */ \ 29 { 0, BASE_BAUD, 0x3E8, 4, STD_COM_FLAGS }, /* ttyS2 */ \
55 { 0, BASE_BAUD, 0x2E8, 3, STD_COM4_FLAGS }, /* ttyS3 */ 30 { 0, BASE_BAUD, 0x2E8, 3, STD_COM4_FLAGS }, /* ttyS3 */
56
57
58#ifdef CONFIG_SERIAL_MANY_PORTS
59#define EXTRA_SERIAL_PORT_DEFNS \
60 { 0, BASE_BAUD, 0x1A0, 9, FOURPORT_FLAGS }, /* ttyS4 */ \
61 { 0, BASE_BAUD, 0x1A8, 9, FOURPORT_FLAGS }, /* ttyS5 */ \
62 { 0, BASE_BAUD, 0x1B0, 9, FOURPORT_FLAGS }, /* ttyS6 */ \
63 { 0, BASE_BAUD, 0x1B8, 9, FOURPORT_FLAGS }, /* ttyS7 */ \
64 { 0, BASE_BAUD, 0x2A0, 5, FOURPORT_FLAGS }, /* ttyS8 */ \
65 { 0, BASE_BAUD, 0x2A8, 5, FOURPORT_FLAGS }, /* ttyS9 */ \
66 { 0, BASE_BAUD, 0x2B0, 5, FOURPORT_FLAGS }, /* ttyS10 */ \
67 { 0, BASE_BAUD, 0x2B8, 5, FOURPORT_FLAGS }, /* ttyS11 */ \
68 { 0, BASE_BAUD, 0x330, 4, ACCENT_FLAGS }, /* ttyS12 */ \
69 { 0, BASE_BAUD, 0x338, 4, ACCENT_FLAGS }, /* ttyS13 */ \
70 { 0, BASE_BAUD, 0x000, 0, 0 }, /* ttyS14 (spare) */ \
71 { 0, BASE_BAUD, 0x000, 0, 0 }, /* ttyS15 (spare) */ \
72 { 0, BASE_BAUD, 0x100, 12, BOCA_FLAGS }, /* ttyS16 */ \
73 { 0, BASE_BAUD, 0x108, 12, BOCA_FLAGS }, /* ttyS17 */ \
74 { 0, BASE_BAUD, 0x110, 12, BOCA_FLAGS }, /* ttyS18 */ \
75 { 0, BASE_BAUD, 0x118, 12, BOCA_FLAGS }, /* ttyS19 */ \
76 { 0, BASE_BAUD, 0x120, 12, BOCA_FLAGS }, /* ttyS20 */ \
77 { 0, BASE_BAUD, 0x128, 12, BOCA_FLAGS }, /* ttyS21 */ \
78 { 0, BASE_BAUD, 0x130, 12, BOCA_FLAGS }, /* ttyS22 */ \
79 { 0, BASE_BAUD, 0x138, 12, BOCA_FLAGS }, /* ttyS23 */ \
80 { 0, BASE_BAUD, 0x140, 12, BOCA_FLAGS }, /* ttyS24 */ \
81 { 0, BASE_BAUD, 0x148, 12, BOCA_FLAGS }, /* ttyS25 */ \
82 { 0, BASE_BAUD, 0x150, 12, BOCA_FLAGS }, /* ttyS26 */ \
83 { 0, BASE_BAUD, 0x158, 12, BOCA_FLAGS }, /* ttyS27 */ \
84 { 0, BASE_BAUD, 0x160, 12, BOCA_FLAGS }, /* ttyS28 */ \
85 { 0, BASE_BAUD, 0x168, 12, BOCA_FLAGS }, /* ttyS29 */ \
86 { 0, BASE_BAUD, 0x170, 12, BOCA_FLAGS }, /* ttyS30 */ \
87 { 0, BASE_BAUD, 0x178, 12, BOCA_FLAGS }, /* ttyS31 */
88#else
89#define EXTRA_SERIAL_PORT_DEFNS
90#endif
91
92/* You can have up to four HUB6's in the system, but I've only
93 * included two cards here for a total of twelve ports.
94 */
95#if (defined(CONFIG_HUB6) && defined(CONFIG_SERIAL_MANY_PORTS))
96#define HUB6_SERIAL_PORT_DFNS \
97 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,0) }, /* ttyS32 */ \
98 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,1) }, /* ttyS33 */ \
99 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,2) }, /* ttyS34 */ \
100 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,3) }, /* ttyS35 */ \
101 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,4) }, /* ttyS36 */ \
102 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,5) }, /* ttyS37 */ \
103 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,0) }, /* ttyS38 */ \
104 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,1) }, /* ttyS39 */ \
105 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,2) }, /* ttyS40 */ \
106 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,3) }, /* ttyS41 */ \
107 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,4) }, /* ttyS42 */ \
108 { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,5) }, /* ttyS43 */
109#else
110#define HUB6_SERIAL_PORT_DFNS
111#endif
112
113#ifdef CONFIG_MCA
114#define MCA_SERIAL_PORT_DFNS \
115 { 0, BASE_BAUD, 0x3220, 3, MCA_COM_FLAGS }, \
116 { 0, BASE_BAUD, 0x3228, 3, MCA_COM_FLAGS }, \
117 { 0, BASE_BAUD, 0x4220, 3, MCA_COM_FLAGS }, \
118 { 0, BASE_BAUD, 0x4228, 3, MCA_COM_FLAGS }, \
119 { 0, BASE_BAUD, 0x5220, 3, MCA_COM_FLAGS }, \
120 { 0, BASE_BAUD, 0x5228, 3, MCA_COM_FLAGS },
121#else
122#define MCA_SERIAL_PORT_DFNS
123#endif
124
125#define SERIAL_PORT_DFNS \
126 STD_SERIAL_PORT_DEFNS \
127 EXTRA_SERIAL_PORT_DEFNS \
128 HUB6_SERIAL_PORT_DFNS \
129 MCA_SERIAL_PORT_DFNS
130
diff --git a/include/asm-x86_64/tlbflush.h b/include/asm-x86_64/tlbflush.h
index 2e811ac262af..061742382520 100644
--- a/include/asm-x86_64/tlbflush.h
+++ b/include/asm-x86_64/tlbflush.h
@@ -22,16 +22,18 @@
22 */ 22 */
23#define __flush_tlb_global() \ 23#define __flush_tlb_global() \
24 do { \ 24 do { \
25 unsigned long tmpreg; \ 25 unsigned long tmpreg, cr4, cr4_orig; \
26 \ 26 \
27 __asm__ __volatile__( \ 27 __asm__ __volatile__( \
28 "movq %1, %%cr4; # turn off PGE \n" \ 28 "movq %%cr4, %2; # turn off PGE \n" \
29 "movq %2, %1; \n" \
30 "andq %3, %1; \n" \
31 "movq %1, %%cr4; \n" \
29 "movq %%cr3, %0; # flush TLB \n" \ 32 "movq %%cr3, %0; # flush TLB \n" \
30 "movq %0, %%cr3; \n" \ 33 "movq %0, %%cr3; \n" \
31 "movq %2, %%cr4; # turn PGE back on \n" \ 34 "movq %2, %%cr4; # turn PGE back on \n" \
32 : "=&r" (tmpreg) \ 35 : "=&r" (tmpreg), "=&r" (cr4), "=&r" (cr4_orig) \
33 : "r" (mmu_cr4_features & ~X86_CR4_PGE), \ 36 : "i" (~X86_CR4_PGE) \
34 "r" (mmu_cr4_features) \
35 : "memory"); \ 37 : "memory"); \
36 } while (0) 38 } while (0)
37 39
diff --git a/include/asm-x86_64/unistd.h b/include/asm-x86_64/unistd.h
index d767adcbf0ff..6560439a83e4 100644
--- a/include/asm-x86_64/unistd.h
+++ b/include/asm-x86_64/unistd.h
@@ -561,8 +561,12 @@ __SYSCALL(__NR_add_key, sys_add_key)
561__SYSCALL(__NR_request_key, sys_request_key) 561__SYSCALL(__NR_request_key, sys_request_key)
562#define __NR_keyctl 250 562#define __NR_keyctl 250
563__SYSCALL(__NR_keyctl, sys_keyctl) 563__SYSCALL(__NR_keyctl, sys_keyctl)
564#define __NR_ioprio_set 251
565__SYSCALL(__NR_ioprio_set, sys_ioprio_set)
566#define __NR_ioprio_get 252
567__SYSCALL(__NR_ioprio_get, sys_ioprio_get)
564 568
565#define __NR_syscall_max __NR_keyctl 569#define __NR_syscall_max __NR_ioprio_get
566#ifndef __NO_STUBS 570#ifndef __NO_STUBS
567 571
568/* user-visible error numbers are in the range -1 - -4095 */ 572/* user-visible error numbers are in the range -1 - -4095 */
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index b123cc08773d..ef8483673aa3 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -342,11 +342,19 @@ struct acpi_table_ecdt {
342 342
343/* PCI MMCONFIG */ 343/* PCI MMCONFIG */
344 344
345/* Defined in PCI Firmware Specification 3.0 */
346struct acpi_table_mcfg_config {
347 u32 base_address;
348 u32 base_reserved;
349 u16 pci_segment_group_number;
350 u8 start_bus_number;
351 u8 end_bus_number;
352 u8 reserved[4];
353} __attribute__ ((packed));
345struct acpi_table_mcfg { 354struct acpi_table_mcfg {
346 struct acpi_table_header header; 355 struct acpi_table_header header;
347 u8 reserved[8]; 356 u8 reserved[8];
348 u32 base_address; 357 struct acpi_table_mcfg_config config[0];
349 u32 base_reserved;
350} __attribute__ ((packed)); 358} __attribute__ ((packed));
351 359
352/* Table Handlers */ 360/* Table Handlers */
@@ -391,6 +399,7 @@ int acpi_table_parse (enum acpi_table_id id, acpi_table_handler handler);
391int acpi_get_table_header_early (enum acpi_table_id id, struct acpi_table_header **header); 399int acpi_get_table_header_early (enum acpi_table_id id, struct acpi_table_header **header);
392int acpi_table_parse_madt (enum acpi_madt_entry_id id, acpi_madt_entry_handler handler, unsigned int max_entries); 400int acpi_table_parse_madt (enum acpi_madt_entry_id id, acpi_madt_entry_handler handler, unsigned int max_entries);
393int acpi_table_parse_srat (enum acpi_srat_entry_id id, acpi_madt_entry_handler handler, unsigned int max_entries); 401int acpi_table_parse_srat (enum acpi_srat_entry_id id, acpi_madt_entry_handler handler, unsigned int max_entries);
402int acpi_parse_mcfg (unsigned long phys_addr, unsigned long size);
394void acpi_table_print (struct acpi_table_header *header, unsigned long phys_addr); 403void acpi_table_print (struct acpi_table_header *header, unsigned long phys_addr);
395void acpi_table_print_madt_entry (acpi_table_entry_header *madt); 404void acpi_table_print_madt_entry (acpi_table_entry_header *madt);
396void acpi_table_print_srat_entry (acpi_table_entry_header *srat); 405void acpi_table_print_srat_entry (acpi_table_entry_header *srat);
@@ -407,9 +416,13 @@ int acpi_map_lsapic(acpi_handle handle, int *pcpu);
407int acpi_unmap_lsapic(int cpu); 416int acpi_unmap_lsapic(int cpu);
408#endif /* CONFIG_ACPI_HOTPLUG_CPU */ 417#endif /* CONFIG_ACPI_HOTPLUG_CPU */
409 418
419int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base);
420int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base);
421
410extern int acpi_mp_config; 422extern int acpi_mp_config;
411 423
412extern u32 pci_mmcfg_base_addr; 424extern struct acpi_table_mcfg_config *pci_mmcfg_config;
425extern int pci_mmcfg_config_num;
413 426
414extern int sbf_port ; 427extern int sbf_port ;
415 428
diff --git a/include/linux/atalk.h b/include/linux/atalk.h
index 09a1451c1159..911c09cb9bf9 100644
--- a/include/linux/atalk.h
+++ b/include/linux/atalk.h
@@ -1,6 +1,8 @@
1#ifndef __LINUX_ATALK_H__ 1#ifndef __LINUX_ATALK_H__
2#define __LINUX_ATALK_H__ 2#define __LINUX_ATALK_H__
3 3
4#include <asm/byteorder.h>
5
4/* 6/*
5 * AppleTalk networking structures 7 * AppleTalk networking structures
6 * 8 *
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 038022763f09..36ef29fa0d8b 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -22,6 +22,7 @@
22 22
23#include <linux/highmem.h> 23#include <linux/highmem.h>
24#include <linux/mempool.h> 24#include <linux/mempool.h>
25#include <linux/ioprio.h>
25 26
26/* Platforms may set this to teach the BIO layer about IOMMU hardware. */ 27/* Platforms may set this to teach the BIO layer about IOMMU hardware. */
27#include <asm/io.h> 28#include <asm/io.h>
@@ -150,6 +151,19 @@ struct bio {
150#define BIO_RW_SYNC 4 151#define BIO_RW_SYNC 4
151 152
152/* 153/*
154 * upper 16 bits of bi_rw define the io priority of this bio
155 */
156#define BIO_PRIO_SHIFT (8 * sizeof(unsigned long) - IOPRIO_BITS)
157#define bio_prio(bio) ((bio)->bi_rw >> BIO_PRIO_SHIFT)
158#define bio_prio_valid(bio) ioprio_valid(bio_prio(bio))
159
160#define bio_set_prio(bio, prio) do { \
161 WARN_ON(prio >= (1 << IOPRIO_BITS)); \
162 (bio)->bi_rw &= ((1UL << BIO_PRIO_SHIFT) - 1); \
163 (bio)->bi_rw |= ((unsigned long) (prio) << BIO_PRIO_SHIFT); \
164} while (0)
165
166/*
153 * various member access, note that bio_data should of course not be used 167 * various member access, note that bio_data should of course not be used
154 * on highmem page vectors 168 * on highmem page vectors
155 */ 169 */
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index b54a0348a890..0881b5cdee3d 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -54,16 +54,23 @@ struct as_io_context {
54 54
55struct cfq_queue; 55struct cfq_queue;
56struct cfq_io_context { 56struct cfq_io_context {
57 void (*dtor)(struct cfq_io_context *);
58 void (*exit)(struct cfq_io_context *);
59
60 struct io_context *ioc;
61
62 /* 57 /*
63 * circular list of cfq_io_contexts belonging to a process io context 58 * circular list of cfq_io_contexts belonging to a process io context
64 */ 59 */
65 struct list_head list; 60 struct list_head list;
66 struct cfq_queue *cfqq; 61 struct cfq_queue *cfqq;
62 void *key;
63
64 struct io_context *ioc;
65
66 unsigned long last_end_request;
67 unsigned long last_queue;
68 unsigned long ttime_total;
69 unsigned long ttime_samples;
70 unsigned long ttime_mean;
71
72 void (*dtor)(struct cfq_io_context *);
73 void (*exit)(struct cfq_io_context *);
67}; 74};
68 75
69/* 76/*
@@ -73,7 +80,9 @@ struct cfq_io_context {
73 */ 80 */
74struct io_context { 81struct io_context {
75 atomic_t refcount; 82 atomic_t refcount;
76 pid_t pid; 83 struct task_struct *task;
84
85 int (*set_ioprio)(struct io_context *, unsigned int);
77 86
78 /* 87 /*
79 * For request batching 88 * For request batching
@@ -81,14 +90,13 @@ struct io_context {
81 unsigned long last_waited; /* Time last woken after wait for request */ 90 unsigned long last_waited; /* Time last woken after wait for request */
82 int nr_batch_requests; /* Number of requests left in the batch */ 91 int nr_batch_requests; /* Number of requests left in the batch */
83 92
84 spinlock_t lock;
85
86 struct as_io_context *aic; 93 struct as_io_context *aic;
87 struct cfq_io_context *cic; 94 struct cfq_io_context *cic;
88}; 95};
89 96
90void put_io_context(struct io_context *ioc); 97void put_io_context(struct io_context *ioc);
91void exit_io_context(void); 98void exit_io_context(void);
99struct io_context *current_io_context(int gfp_flags);
92struct io_context *get_io_context(int gfp_flags); 100struct io_context *get_io_context(int gfp_flags);
93void copy_io_context(struct io_context **pdst, struct io_context **psrc); 101void copy_io_context(struct io_context **pdst, struct io_context **psrc);
94void swap_io_context(struct io_context **ioc1, struct io_context **ioc2); 102void swap_io_context(struct io_context **ioc1, struct io_context **ioc2);
@@ -134,6 +142,8 @@ struct request {
134 142
135 void *elevator_private; 143 void *elevator_private;
136 144
145 unsigned short ioprio;
146
137 int rq_status; /* should split this into a few status bits */ 147 int rq_status; /* should split this into a few status bits */
138 struct gendisk *rq_disk; 148 struct gendisk *rq_disk;
139 int errors; 149 int errors;
diff --git a/include/linux/byteorder/swabb.h b/include/linux/byteorder/swabb.h
index d28d9a804d3b..d5f2a3205109 100644
--- a/include/linux/byteorder/swabb.h
+++ b/include/linux/byteorder/swabb.h
@@ -92,29 +92,32 @@
92#endif /* OPTIMIZE */ 92#endif /* OPTIMIZE */
93 93
94 94
95static __inline__ __const__ __u32 __fswahw32(__u32 x) 95static inline __u32 __fswahw32(__u32 x)
96{ 96{
97 return __arch__swahw32(x); 97 return __arch__swahw32(x);
98} 98}
99static __inline__ __u32 __swahw32p(__u32 *x) 99
100static inline __u32 __swahw32p(__u32 *x)
100{ 101{
101 return __arch__swahw32p(x); 102 return __arch__swahw32p(x);
102} 103}
103static __inline__ void __swahw32s(__u32 *addr) 104
105static inline void __swahw32s(__u32 *addr)
104{ 106{
105 __arch__swahw32s(addr); 107 __arch__swahw32s(addr);
106} 108}
107 109
108 110static inline __u32 __fswahb32(__u32 x)
109static __inline__ __const__ __u32 __fswahb32(__u32 x)
110{ 111{
111 return __arch__swahb32(x); 112 return __arch__swahb32(x);
112} 113}
113static __inline__ __u32 __swahb32p(__u32 *x) 114
115static inline __u32 __swahb32p(__u32 *x)
114{ 116{
115 return __arch__swahb32p(x); 117 return __arch__swahb32p(x);
116} 118}
117static __inline__ void __swahb32s(__u32 *addr) 119
120static inline void __swahb32s(__u32 *addr)
118{ 121{
119 __arch__swahb32s(addr); 122 __arch__swahb32s(addr);
120} 123}
diff --git a/include/linux/cciss_ioctl.h b/include/linux/cciss_ioctl.h
index ee0c6e8995da..424d5e622b43 100644
--- a/include/linux/cciss_ioctl.h
+++ b/include/linux/cciss_ioctl.h
@@ -10,6 +10,7 @@
10typedef struct _cciss_pci_info_struct 10typedef struct _cciss_pci_info_struct
11{ 11{
12 unsigned char bus; 12 unsigned char bus;
13 unsigned short domain;
13 unsigned char dev_fn; 14 unsigned char dev_fn;
14 __u32 board_id; 15 __u32 board_id;
15} cciss_pci_info_struct; 16} cciss_pci_info_struct;
diff --git a/include/linux/elevator.h b/include/linux/elevator.h
index ee54f81faad5..ea6bbc2d7407 100644
--- a/include/linux/elevator.h
+++ b/include/linux/elevator.h
@@ -16,9 +16,9 @@ typedef void (elevator_remove_req_fn) (request_queue_t *, struct request *);
16typedef void (elevator_requeue_req_fn) (request_queue_t *, struct request *); 16typedef void (elevator_requeue_req_fn) (request_queue_t *, struct request *);
17typedef struct request *(elevator_request_list_fn) (request_queue_t *, struct request *); 17typedef struct request *(elevator_request_list_fn) (request_queue_t *, struct request *);
18typedef void (elevator_completed_req_fn) (request_queue_t *, struct request *); 18typedef void (elevator_completed_req_fn) (request_queue_t *, struct request *);
19typedef int (elevator_may_queue_fn) (request_queue_t *, int); 19typedef int (elevator_may_queue_fn) (request_queue_t *, int, struct bio *);
20 20
21typedef int (elevator_set_req_fn) (request_queue_t *, struct request *, int); 21typedef int (elevator_set_req_fn) (request_queue_t *, struct request *, struct bio *, int);
22typedef void (elevator_put_req_fn) (request_queue_t *, struct request *); 22typedef void (elevator_put_req_fn) (request_queue_t *, struct request *);
23typedef void (elevator_deactivate_req_fn) (request_queue_t *, struct request *); 23typedef void (elevator_deactivate_req_fn) (request_queue_t *, struct request *);
24 24
@@ -96,9 +96,9 @@ extern struct request *elv_former_request(request_queue_t *, struct request *);
96extern struct request *elv_latter_request(request_queue_t *, struct request *); 96extern struct request *elv_latter_request(request_queue_t *, struct request *);
97extern int elv_register_queue(request_queue_t *q); 97extern int elv_register_queue(request_queue_t *q);
98extern void elv_unregister_queue(request_queue_t *q); 98extern void elv_unregister_queue(request_queue_t *q);
99extern int elv_may_queue(request_queue_t *, int); 99extern int elv_may_queue(request_queue_t *, int, struct bio *);
100extern void elv_completed_request(request_queue_t *, struct request *); 100extern void elv_completed_request(request_queue_t *, struct request *);
101extern int elv_set_request(request_queue_t *, struct request *, int); 101extern int elv_set_request(request_queue_t *, struct request *, struct bio *, int);
102extern void elv_put_request(request_queue_t *, struct request *); 102extern void elv_put_request(request_queue_t *, struct request *);
103 103
104/* 104/*
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index a1478258d002..cf3847edc50f 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -25,6 +25,7 @@
25#define _LINUX_ETHERDEVICE_H 25#define _LINUX_ETHERDEVICE_H
26 26
27#include <linux/if_ether.h> 27#include <linux/if_ether.h>
28#include <linux/netdevice.h>
28#include <linux/random.h> 29#include <linux/random.h>
29 30
30#ifdef __KERNEL__ 31#ifdef __KERNEL__
@@ -65,7 +66,7 @@ static inline int is_zero_ether_addr(const u8 *addr)
65 */ 66 */
66static inline int is_multicast_ether_addr(const u8 *addr) 67static inline int is_multicast_ether_addr(const u8 *addr)
67{ 68{
68 return addr[0] & 0x01; 69 return ((addr[0] != 0xff) && (0x01 & addr[0]));
69} 70}
70 71
71/** 72/**
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 3ae8e37bdfc8..047bde30836a 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -213,6 +213,7 @@ extern int dir_notify_enable;
213#include <linux/radix-tree.h> 213#include <linux/radix-tree.h>
214#include <linux/prio_tree.h> 214#include <linux/prio_tree.h>
215#include <linux/init.h> 215#include <linux/init.h>
216#include <linux/sched.h>
216 217
217#include <asm/atomic.h> 218#include <asm/atomic.h>
218#include <asm/semaphore.h> 219#include <asm/semaphore.h>
@@ -822,16 +823,34 @@ enum {
822#define vfs_check_frozen(sb, level) \ 823#define vfs_check_frozen(sb, level) \
823 wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level))) 824 wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level)))
824 825
826static inline void get_fs_excl(void)
827{
828 atomic_inc(&current->fs_excl);
829}
830
831static inline void put_fs_excl(void)
832{
833 atomic_dec(&current->fs_excl);
834}
835
836static inline int has_fs_excl(void)
837{
838 return atomic_read(&current->fs_excl);
839}
840
841
825/* 842/*
826 * Superblock locking. 843 * Superblock locking.
827 */ 844 */
828static inline void lock_super(struct super_block * sb) 845static inline void lock_super(struct super_block * sb)
829{ 846{
847 get_fs_excl();
830 down(&sb->s_lock); 848 down(&sb->s_lock);
831} 849}
832 850
833static inline void unlock_super(struct super_block * sb) 851static inline void unlock_super(struct super_block * sb)
834{ 852{
853 put_fs_excl();
835 up(&sb->s_lock); 854 up(&sb->s_lock);
836} 855}
837 856
diff --git a/include/linux/i2c-dev.h b/include/linux/i2c-dev.h
index d228230ffe5d..541695679762 100644
--- a/include/linux/i2c-dev.h
+++ b/include/linux/i2c-dev.h
@@ -25,6 +25,7 @@
25#define _LINUX_I2C_DEV_H 25#define _LINUX_I2C_DEV_H
26 26
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/compiler.h>
28 29
29/* Some IOCTL commands are defined in <linux/i2c.h> */ 30/* Some IOCTL commands are defined in <linux/i2c.h> */
30/* Note: 10-bit addresses are NOT supported! */ 31/* Note: 10-bit addresses are NOT supported! */
diff --git a/include/linux/if_bonding.h b/include/linux/if_bonding.h
index 57024ce2c74f..84598fa2e9de 100644
--- a/include/linux/if_bonding.h
+++ b/include/linux/if_bonding.h
@@ -35,6 +35,9 @@
35 * 35 *
36 * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com> 36 * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
37 * - Code cleanup and style changes 37 * - Code cleanup and style changes
38 *
39 * 2005/05/05 - Jason Gabler <jygabler at lbl dot gov>
40 * - added definitions for various XOR hashing policies
38 */ 41 */
39 42
40#ifndef _LINUX_IF_BONDING_H 43#ifndef _LINUX_IF_BONDING_H
@@ -80,6 +83,10 @@
80 83
81#define BOND_DEFAULT_MAX_BONDS 1 /* Default maximum number of devices to support */ 84#define BOND_DEFAULT_MAX_BONDS 1 /* Default maximum number of devices to support */
82 85
86/* hashing types */
87#define BOND_XMIT_POLICY_LAYER2 0 /* layer 2 (MAC only), default */
88#define BOND_XMIT_POLICY_LAYER34 1 /* layer 3+4 (IP ^ MAC) */
89
83typedef struct ifbond { 90typedef struct ifbond {
84 __s32 bond_mode; 91 __s32 bond_mode;
85 __s32 num_slaves; 92 __s32 num_slaves;
diff --git a/include/linux/in6.h b/include/linux/in6.h
index f8256c582845..dcf5720ffcbb 100644
--- a/include/linux/in6.h
+++ b/include/linux/in6.h
@@ -156,7 +156,7 @@ struct in6_flowlabel_req
156#define IPV6_CHECKSUM 7 156#define IPV6_CHECKSUM 7
157#define IPV6_HOPLIMIT 8 157#define IPV6_HOPLIMIT 8
158#define IPV6_NEXTHOP 9 158#define IPV6_NEXTHOP 9
159#define IPV6_AUTHHDR 10 159#define IPV6_AUTHHDR 10 /* obsolete */
160#define IPV6_FLOWINFO 11 160#define IPV6_FLOWINFO 11
161 161
162#define IPV6_UNICAST_HOPS 16 162#define IPV6_UNICAST_HOPS 16
diff --git a/include/linux/init_task.h b/include/linux/init_task.h
index 03206a425d7a..c727c195a91a 100644
--- a/include/linux/init_task.h
+++ b/include/linux/init_task.h
@@ -81,6 +81,7 @@ extern struct group_info init_groups;
81 .mm = NULL, \ 81 .mm = NULL, \
82 .active_mm = &init_mm, \ 82 .active_mm = &init_mm, \
83 .run_list = LIST_HEAD_INIT(tsk.run_list), \ 83 .run_list = LIST_HEAD_INIT(tsk.run_list), \
84 .ioprio = 0, \
84 .time_slice = HZ, \ 85 .time_slice = HZ, \
85 .tasks = LIST_HEAD_INIT(tsk.tasks), \ 86 .tasks = LIST_HEAD_INIT(tsk.tasks), \
86 .ptrace_children= LIST_HEAD_INIT(tsk.ptrace_children), \ 87 .ptrace_children= LIST_HEAD_INIT(tsk.ptrace_children), \
@@ -110,6 +111,7 @@ extern struct group_info init_groups;
110 .proc_lock = SPIN_LOCK_UNLOCKED, \ 111 .proc_lock = SPIN_LOCK_UNLOCKED, \
111 .journal_info = NULL, \ 112 .journal_info = NULL, \
112 .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ 113 .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
114 .fs_excl = ATOMIC_INIT(0), \
113} 115}
114 116
115 117
diff --git a/include/linux/input.h b/include/linux/input.h
index 9d9598ed760d..b9cc0ac71f44 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -859,6 +859,10 @@ struct input_dev {
859 int (*erase_effect)(struct input_dev *dev, int effect_id); 859 int (*erase_effect)(struct input_dev *dev, int effect_id);
860 860
861 struct input_handle *grab; 861 struct input_handle *grab;
862
863 struct semaphore sem; /* serializes open and close operations */
864 unsigned int users;
865
862 struct device *dev; 866 struct device *dev;
863 867
864 struct list_head h_list; 868 struct list_head h_list;
diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h
new file mode 100644
index 000000000000..8a453a0b5e4b
--- /dev/null
+++ b/include/linux/ioprio.h
@@ -0,0 +1,88 @@
1#ifndef IOPRIO_H
2#define IOPRIO_H
3
4#include <linux/sched.h>
5
6/*
7 * Gives us 8 prio classes with 13-bits of data for each class
8 */
9#define IOPRIO_BITS (16)
10#define IOPRIO_CLASS_SHIFT (13)
11#define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1)
12
13#define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)
14#define IOPRIO_PRIO_DATA(mask) ((mask) & IOPRIO_PRIO_MASK)
15#define IOPRIO_PRIO_VALUE(class, data) (((class) << IOPRIO_CLASS_SHIFT) | data)
16
17#define ioprio_valid(mask) (IOPRIO_PRIO_CLASS((mask)) != IOPRIO_CLASS_NONE)
18
19/*
20 * These are the io priority groups as implemented by CFQ. RT is the realtime
21 * class, it always gets premium service. BE is the best-effort scheduling
22 * class, the default for any process. IDLE is the idle scheduling class, it
23 * is only served when no one else is using the disk.
24 */
25enum {
26 IOPRIO_CLASS_NONE,
27 IOPRIO_CLASS_RT,
28 IOPRIO_CLASS_BE,
29 IOPRIO_CLASS_IDLE,
30};
31
32/*
33 * 8 best effort priority levels are supported
34 */
35#define IOPRIO_BE_NR (8)
36
37asmlinkage int sys_ioprio_set(int, int, int);
38asmlinkage int sys_ioprio_get(int, int);
39
40enum {
41 IOPRIO_WHO_PROCESS = 1,
42 IOPRIO_WHO_PGRP,
43 IOPRIO_WHO_USER,
44};
45
46/*
47 * if process has set io priority explicitly, use that. if not, convert
48 * the cpu scheduler nice value to an io priority
49 */
50#define IOPRIO_NORM (4)
51static inline int task_ioprio(struct task_struct *task)
52{
53 WARN_ON(!ioprio_valid(task->ioprio));
54 return IOPRIO_PRIO_DATA(task->ioprio);
55}
56
57static inline int task_nice_ioprio(struct task_struct *task)
58{
59 return (task_nice(task) + 20) / 5;
60}
61
62/*
63 * For inheritance, return the highest of the two given priorities
64 */
65static inline int ioprio_best(unsigned short aprio, unsigned short bprio)
66{
67 unsigned short aclass = IOPRIO_PRIO_CLASS(aprio);
68 unsigned short bclass = IOPRIO_PRIO_CLASS(bprio);
69
70 if (!ioprio_valid(aprio))
71 return bprio;
72 if (!ioprio_valid(bprio))
73 return aprio;
74
75 if (aclass == IOPRIO_CLASS_NONE)
76 aclass = IOPRIO_CLASS_BE;
77 if (bclass == IOPRIO_CLASS_NONE)
78 bclass = IOPRIO_CLASS_BE;
79
80 if (aclass == bclass)
81 return min(aprio, bprio);
82 if (aclass > bclass)
83 return bprio;
84 else
85 return aprio;
86}
87
88#endif
diff --git a/include/linux/irq.h b/include/linux/irq.h
index 12277799c007..069d3b84d311 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -85,9 +85,10 @@ extern int no_irq_affinity;
85extern int noirqdebug_setup(char *str); 85extern int noirqdebug_setup(char *str);
86 86
87extern fastcall int handle_IRQ_event(unsigned int irq, struct pt_regs *regs, 87extern fastcall int handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
88 struct irqaction *action); 88 struct irqaction *action);
89extern fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs); 89extern fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs);
90extern void note_interrupt(unsigned int irq, irq_desc_t *desc, int action_ret); 90extern void note_interrupt(unsigned int irq, irq_desc_t *desc,
91 int action_ret, struct pt_regs *regs);
91extern int can_request_irq(unsigned int irq, unsigned long irqflags); 92extern int can_request_irq(unsigned int irq, unsigned long irqflags);
92 93
93extern void init_irq_proc(void); 94extern void init_irq_proc(void);
diff --git a/include/linux/joystick.h b/include/linux/joystick.h
index b7e0ab622cd7..06b9af77eb7f 100644
--- a/include/linux/joystick.h
+++ b/include/linux/joystick.h
@@ -111,18 +111,35 @@ struct js_corr {
111#define JS_SET_ALL 8 111#define JS_SET_ALL 8
112 112
113struct JS_DATA_TYPE { 113struct JS_DATA_TYPE {
114 int buttons; 114 __s32 buttons;
115 int x; 115 __s32 x;
116 int y; 116 __s32 y;
117}; 117};
118 118
119struct JS_DATA_SAVE_TYPE { 119struct JS_DATA_SAVE_TYPE_32 {
120 int JS_TIMEOUT; 120 __s32 JS_TIMEOUT;
121 int BUSY; 121 __s32 BUSY;
122 long JS_EXPIRETIME; 122 __s32 JS_EXPIRETIME;
123 long JS_TIMELIMIT; 123 __s32 JS_TIMELIMIT;
124 struct JS_DATA_TYPE JS_SAVE; 124 struct JS_DATA_TYPE JS_SAVE;
125 struct JS_DATA_TYPE JS_CORR; 125 struct JS_DATA_TYPE JS_CORR;
126}; 126};
127 127
128struct JS_DATA_SAVE_TYPE_64 {
129 __s32 JS_TIMEOUT;
130 __s32 BUSY;
131 __s64 JS_EXPIRETIME;
132 __s64 JS_TIMELIMIT;
133 struct JS_DATA_TYPE JS_SAVE;
134 struct JS_DATA_TYPE JS_CORR;
135};
136
137#if BITS_PER_LONG == 64
138#define JS_DATA_SAVE_TYPE JS_DATA_SAVE_TYPE_64
139#elif BITS_PER_LONG == 32
140#define JS_DATA_SAVE_TYPE JS_DATA_SAVE_TYPE_32
141#else
142#error Unexpected BITS_PER_LONG
143#endif
144
128#endif /* _LINUX_JOYSTICK_H */ 145#endif /* _LINUX_JOYSTICK_H */
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 5e1a7b0d7b3f..b7a194c4362a 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -104,33 +104,12 @@ struct jprobe {
104}; 104};
105 105
106#ifdef ARCH_SUPPORTS_KRETPROBES 106#ifdef ARCH_SUPPORTS_KRETPROBES
107extern int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs);
108extern void trampoline_post_handler(struct kprobe *p, struct pt_regs *regs,
109 unsigned long flags);
110extern struct task_struct *arch_get_kprobe_task(void *ptr);
111extern void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs); 107extern void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs);
112extern void arch_kprobe_flush_task(struct task_struct *tk);
113#else /* ARCH_SUPPORTS_KRETPROBES */ 108#else /* ARCH_SUPPORTS_KRETPROBES */
114static inline void kretprobe_trampoline(void)
115{
116}
117static inline int trampoline_probe_handler(struct kprobe *p,
118 struct pt_regs *regs)
119{
120 return 0;
121}
122static inline void trampoline_post_handler(struct kprobe *p,
123 struct pt_regs *regs, unsigned long flags)
124{
125}
126static inline void arch_prepare_kretprobe(struct kretprobe *rp, 109static inline void arch_prepare_kretprobe(struct kretprobe *rp,
127 struct pt_regs *regs) 110 struct pt_regs *regs)
128{ 111{
129} 112}
130static inline void arch_kprobe_flush_task(struct task_struct *tk)
131{
132}
133#define arch_get_kprobe_task(ptr) ((struct task_struct *)NULL)
134#endif /* ARCH_SUPPORTS_KRETPROBES */ 113#endif /* ARCH_SUPPORTS_KRETPROBES */
135/* 114/*
136 * Function-return probe - 115 * Function-return probe -
@@ -155,8 +134,8 @@ struct kretprobe_instance {
155 struct hlist_node uflist; /* either on free list or used list */ 134 struct hlist_node uflist; /* either on free list or used list */
156 struct hlist_node hlist; 135 struct hlist_node hlist;
157 struct kretprobe *rp; 136 struct kretprobe *rp;
158 void *ret_addr; 137 kprobe_opcode_t *ret_addr;
159 void *stack_addr; 138 struct task_struct *task;
160}; 139};
161 140
162#ifdef CONFIG_KPROBES 141#ifdef CONFIG_KPROBES
@@ -176,7 +155,10 @@ extern void arch_copy_kprobe(struct kprobe *p);
176extern void arch_arm_kprobe(struct kprobe *p); 155extern void arch_arm_kprobe(struct kprobe *p);
177extern void arch_disarm_kprobe(struct kprobe *p); 156extern void arch_disarm_kprobe(struct kprobe *p);
178extern void arch_remove_kprobe(struct kprobe *p); 157extern void arch_remove_kprobe(struct kprobe *p);
158extern int arch_init(void);
179extern void show_registers(struct pt_regs *regs); 159extern void show_registers(struct pt_regs *regs);
160extern kprobe_opcode_t *get_insn_slot(void);
161extern void free_insn_slot(kprobe_opcode_t *slot);
180 162
181/* Get the kprobe at this addr (if any). Must have called lock_kprobes */ 163/* Get the kprobe at this addr (if any). Must have called lock_kprobes */
182struct kprobe *get_kprobe(void *addr); 164struct kprobe *get_kprobe(void *addr);
@@ -194,8 +176,6 @@ int register_kretprobe(struct kretprobe *rp);
194void unregister_kretprobe(struct kretprobe *rp); 176void unregister_kretprobe(struct kretprobe *rp);
195 177
196struct kretprobe_instance *get_free_rp_inst(struct kretprobe *rp); 178struct kretprobe_instance *get_free_rp_inst(struct kretprobe *rp);
197struct kretprobe_instance *get_rp_inst(void *sara);
198struct kretprobe_instance *get_rp_inst_tsk(struct task_struct *tk);
199void add_rp_inst(struct kretprobe_instance *ri); 179void add_rp_inst(struct kretprobe_instance *ri);
200void kprobe_flush_task(struct task_struct *tk); 180void kprobe_flush_task(struct task_struct *tk);
201void recycle_rp_inst(struct kretprobe_instance *ri); 181void recycle_rp_inst(struct kretprobe_instance *ri);
diff --git a/include/linux/libps2.h b/include/linux/libps2.h
index 923bdbc6d9e4..a710bddda4eb 100644
--- a/include/linux/libps2.h
+++ b/include/linux/libps2.h
@@ -41,6 +41,7 @@ struct ps2dev {
41 41
42void ps2_init(struct ps2dev *ps2dev, struct serio *serio); 42void ps2_init(struct ps2dev *ps2dev, struct serio *serio);
43int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout); 43int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout);
44void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout);
44int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command); 45int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command);
45int ps2_schedule_command(struct ps2dev *ps2dev, unsigned char *param, int command); 46int ps2_schedule_command(struct ps2dev *ps2dev, unsigned char *param, int command);
46int ps2_handle_ack(struct ps2dev *ps2dev, unsigned char data); 47int ps2_handle_ack(struct ps2dev *ps2dev, unsigned char data);
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index d6eb7b2efc04..9b6d05172ed4 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -175,4 +175,50 @@ struct serio_device_id {
175}; 175};
176 176
177 177
178/* PCMCIA */
179
180struct pcmcia_device_id {
181 __u16 match_flags;
182
183 __u16 manf_id;
184 __u16 card_id;
185
186 __u8 func_id;
187
188 /* for real multi-function devices */
189 __u8 function;
190
191 /* for pseude multi-function devices */
192 __u8 device_no;
193
194 __u32 prod_id_hash[4];
195
196 /* not matched against in kernelspace*/
197#ifdef __KERNEL__
198 const char * prod_id[4];
199#else
200 kernel_ulong_t prod_id[4];
201#endif
202
203 /* not matched against */
204 kernel_ulong_t driver_info;
205#ifdef __KERNEL__
206 char * cisfile;
207#else
208 kernel_ulong_t cisfile;
209#endif
210};
211
212#define PCMCIA_DEV_ID_MATCH_MANF_ID 0x0001
213#define PCMCIA_DEV_ID_MATCH_CARD_ID 0x0002
214#define PCMCIA_DEV_ID_MATCH_FUNC_ID 0x0004
215#define PCMCIA_DEV_ID_MATCH_FUNCTION 0x0008
216#define PCMCIA_DEV_ID_MATCH_PROD_ID1 0x0010
217#define PCMCIA_DEV_ID_MATCH_PROD_ID2 0x0020
218#define PCMCIA_DEV_ID_MATCH_PROD_ID3 0x0040
219#define PCMCIA_DEV_ID_MATCH_PROD_ID4 0x0080
220#define PCMCIA_DEV_ID_MATCH_DEVICE_NO 0x0100
221#define PCMCIA_DEV_ID_MATCH_FAKE_CIS 0x0200
222#define PCMCIA_DEV_ID_MATCH_ANONYMOUS 0x0400
223
178#endif /* LINUX_MOD_DEVICETABLE_H */ 224#endif /* LINUX_MOD_DEVICETABLE_H */
diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 3029cad63a01..27e4d164a108 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -168,6 +168,7 @@ __nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len, int flags)
168 nlh->nlmsg_flags = flags; 168 nlh->nlmsg_flags = flags;
169 nlh->nlmsg_pid = pid; 169 nlh->nlmsg_pid = pid;
170 nlh->nlmsg_seq = seq; 170 nlh->nlmsg_seq = seq;
171 memset(NLMSG_DATA(nlh) + len, 0, NLMSG_ALIGN(size) - size);
171 return nlh; 172 return nlh;
172} 173}
173 174
diff --git a/include/linux/pci.h b/include/linux/pci.h
index b5238bd18830..66798b46f308 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -734,16 +734,20 @@ void pcibios_update_irq(struct pci_dev *, int irq);
734/* Generic PCI functions used internally */ 734/* Generic PCI functions used internally */
735 735
736extern struct pci_bus *pci_find_bus(int domain, int busnr); 736extern struct pci_bus *pci_find_bus(int domain, int busnr);
737void pci_bus_add_devices(struct pci_bus *bus);
737struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus, struct pci_ops *ops, void *sysdata); 738struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus, struct pci_ops *ops, void *sysdata);
738static inline struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata) 739static inline struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata)
739{ 740{
740 return pci_scan_bus_parented(NULL, bus, ops, sysdata); 741 struct pci_bus *root_bus;
742 root_bus = pci_scan_bus_parented(NULL, bus, ops, sysdata);
743 if (root_bus)
744 pci_bus_add_devices(root_bus);
745 return root_bus;
741} 746}
742int pci_scan_slot(struct pci_bus *bus, int devfn); 747int pci_scan_slot(struct pci_bus *bus, int devfn);
743struct pci_dev * pci_scan_single_device(struct pci_bus *bus, int devfn); 748struct pci_dev * pci_scan_single_device(struct pci_bus *bus, int devfn);
744unsigned int pci_scan_child_bus(struct pci_bus *bus); 749unsigned int pci_scan_child_bus(struct pci_bus *bus);
745void pci_bus_add_device(struct pci_dev *dev); 750void pci_bus_add_device(struct pci_dev *dev);
746void pci_bus_add_devices(struct pci_bus *bus);
747void pci_name_device(struct pci_dev *dev); 751void pci_name_device(struct pci_dev *dev);
748char *pci_class_name(u32 class); 752char *pci_class_name(u32 class);
749void pci_read_bridge_bases(struct pci_bus *child); 753void pci_read_bridge_bases(struct pci_bus *child);
@@ -870,6 +874,15 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max, int pass
870#define pci_pool_alloc(pool, flags, handle) dma_pool_alloc(pool, flags, handle) 874#define pci_pool_alloc(pool, flags, handle) dma_pool_alloc(pool, flags, handle)
871#define pci_pool_free(pool, vaddr, addr) dma_pool_free(pool, vaddr, addr) 875#define pci_pool_free(pool, vaddr, addr) dma_pool_free(pool, vaddr, addr)
872 876
877enum pci_dma_burst_strategy {
878 PCI_DMA_BURST_INFINITY, /* make bursts as large as possible,
879 strategy_parameter is N/A */
880 PCI_DMA_BURST_BOUNDARY, /* disconnect at every strategy_parameter
881 byte boundaries */
882 PCI_DMA_BURST_MULTIPLE, /* disconnect at some multiple of
883 strategy_parameter byte boundaries */
884};
885
873#if defined(CONFIG_ISA) || defined(CONFIG_EISA) 886#if defined(CONFIG_ISA) || defined(CONFIG_EISA)
874extern struct pci_dev *isa_bridge; 887extern struct pci_dev *isa_bridge;
875#endif 888#endif
@@ -972,6 +985,8 @@ static inline int pci_proc_domain(struct pci_bus *bus)
972} 985}
973#endif 986#endif
974 987
988#define pci_dma_burst_advice(pdev, strat, strategy_parameter) do { } while (0)
989
975#endif /* !CONFIG_PCI */ 990#endif /* !CONFIG_PCI */
976 991
977/* these helpers provide future and backwards compatibility 992/* these helpers provide future and backwards compatibility
@@ -1016,6 +1031,20 @@ static inline char *pci_name(struct pci_dev *pdev)
1016#define pci_pretty_name(dev) "" 1031#define pci_pretty_name(dev) ""
1017#endif 1032#endif
1018 1033
1034
1035/* Some archs don't want to expose struct resource to userland as-is
1036 * in sysfs and /proc
1037 */
1038#ifndef HAVE_ARCH_PCI_RESOURCE_TO_USER
1039static inline void pci_resource_to_user(const struct pci_dev *dev, int bar,
1040 const struct resource *rsrc, u64 *start, u64 *end)
1041{
1042 *start = rsrc->start;
1043 *end = rsrc->end;
1044}
1045#endif /* HAVE_ARCH_PCI_RESOURCE_TO_USER */
1046
1047
1019/* 1048/*
1020 * The world is not perfect and supplies us with broken PCI devices. 1049 * The world is not perfect and supplies us with broken PCI devices.
1021 * For at least a part of these bugs we need a work-around, so both 1050 * For at least a part of these bugs we need a work-around, so both
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index bf608808a60c..c3ee1ae4545a 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -62,6 +62,8 @@
62 62
63#define PCI_BASE_CLASS_SYSTEM 0x08 63#define PCI_BASE_CLASS_SYSTEM 0x08
64#define PCI_CLASS_SYSTEM_PIC 0x0800 64#define PCI_CLASS_SYSTEM_PIC 0x0800
65#define PCI_CLASS_SYSTEM_PIC_IOAPIC 0x080010
66#define PCI_CLASS_SYSTEM_PIC_IOXAPIC 0x080020
65#define PCI_CLASS_SYSTEM_DMA 0x0801 67#define PCI_CLASS_SYSTEM_DMA 0x0801
66#define PCI_CLASS_SYSTEM_TIMER 0x0802 68#define PCI_CLASS_SYSTEM_TIMER 0x0802
67#define PCI_CLASS_SYSTEM_RTC 0x0803 69#define PCI_CLASS_SYSTEM_RTC 0x0803
@@ -712,8 +714,9 @@
712#define PCI_DEVICE_ID_HP_DIVA_AUX 0x1290 714#define PCI_DEVICE_ID_HP_DIVA_AUX 0x1290
713#define PCI_DEVICE_ID_HP_DIVA_RMP3 0x1301 715#define PCI_DEVICE_ID_HP_DIVA_RMP3 0x1301
714#define PCI_DEVICE_ID_HP_CISSA 0x3220 716#define PCI_DEVICE_ID_HP_CISSA 0x3220
715#define PCI_DEVICE_ID_HP_CISSB 0x3230 717#define PCI_DEVICE_ID_HP_CISSB 0x3222
716#define PCI_DEVICE_ID_HP_ZX2_IOC 0x4031 718#define PCI_DEVICE_ID_HP_ZX2_IOC 0x4031
719#define PCI_DEVICE_ID_HP_CISSC 0x3230
717 720
718#define PCI_VENDOR_ID_PCTECH 0x1042 721#define PCI_VENDOR_ID_PCTECH 0x1042
719#define PCI_DEVICE_ID_PCTECH_RZ1000 0x1000 722#define PCI_DEVICE_ID_PCTECH_RZ1000 0x1000
@@ -1284,6 +1287,8 @@
1284#define PCI_DEVICE_ID_NVIDIA_GEFORCE_FX_GO5700_2 0x0348 1287#define PCI_DEVICE_ID_NVIDIA_GEFORCE_FX_GO5700_2 0x0348
1285#define PCI_DEVICE_ID_NVIDIA_QUADRO_FX_GO1000 0x034C 1288#define PCI_DEVICE_ID_NVIDIA_QUADRO_FX_GO1000 0x034C
1286#define PCI_DEVICE_ID_NVIDIA_QUADRO_FX_1100 0x034E 1289#define PCI_DEVICE_ID_NVIDIA_QUADRO_FX_1100 0x034E
1290#define PCI_DEVICE_ID_NVIDIA_NVENET_14 0x0372
1291#define PCI_DEVICE_ID_NVIDIA_NVENET_15 0x0373
1287 1292
1288#define PCI_VENDOR_ID_IMS 0x10e0 1293#define PCI_VENDOR_ID_IMS 0x10e0
1289#define PCI_DEVICE_ID_IMS_8849 0x8849 1294#define PCI_DEVICE_ID_IMS_8849 0x8849
@@ -1812,6 +1817,8 @@
1812#define PCI_VENDOR_ID_ITE 0x1283 1817#define PCI_VENDOR_ID_ITE 0x1283
1813#define PCI_DEVICE_ID_ITE_IT8172G 0x8172 1818#define PCI_DEVICE_ID_ITE_IT8172G 0x8172
1814#define PCI_DEVICE_ID_ITE_IT8172G_AUDIO 0x0801 1819#define PCI_DEVICE_ID_ITE_IT8172G_AUDIO 0x0801
1820#define PCI_DEVICE_ID_ITE_8211 0x8211
1821#define PCI_DEVICE_ID_ITE_8212 0x8212
1815#define PCI_DEVICE_ID_ITE_8872 0x8872 1822#define PCI_DEVICE_ID_ITE_8872 0x8872
1816#define PCI_DEVICE_ID_ITE_IT8330G_0 0xe886 1823#define PCI_DEVICE_ID_ITE_IT8330G_0 0xe886
1817 1824
diff --git a/include/linux/pkt_cls.h b/include/linux/pkt_cls.h
index 25d2d67c1faf..bd2c5a2bbbf5 100644
--- a/include/linux/pkt_cls.h
+++ b/include/linux/pkt_cls.h
@@ -276,6 +276,7 @@ struct tc_rsvp_pinfo
276 __u8 protocol; 276 __u8 protocol;
277 __u8 tunnelid; 277 __u8 tunnelid;
278 __u8 tunnelhdr; 278 __u8 tunnelhdr;
279 __u8 pad;
279}; 280};
280 281
281/* ROUTE filter */ 282/* ROUTE filter */
diff --git a/include/linux/pkt_sched.h b/include/linux/pkt_sched.h
index 1d9da36eb9db..60ffcb9c5791 100644
--- a/include/linux/pkt_sched.h
+++ b/include/linux/pkt_sched.h
@@ -221,9 +221,11 @@ struct tc_gred_qopt
221/* gred setup */ 221/* gred setup */
222struct tc_gred_sopt 222struct tc_gred_sopt
223{ 223{
224 __u32 DPs; 224 __u32 DPs;
225 __u32 def_DP; 225 __u32 def_DP;
226 __u8 grio; 226 __u8 grio;
227 __u8 pad1;
228 __u16 pad2;
227}; 229};
228 230
229/* HTB section */ 231/* HTB section */
@@ -351,6 +353,7 @@ struct tc_cbq_ovl
351#define TC_CBQ_OVL_DROP 3 353#define TC_CBQ_OVL_DROP 3
352#define TC_CBQ_OVL_RCLASSIC 4 354#define TC_CBQ_OVL_RCLASSIC 4
353 unsigned char priority2; 355 unsigned char priority2;
356 __u16 pad;
354 __u32 penalty; 357 __u32 penalty;
355}; 358};
356 359
diff --git a/include/linux/pmu.h b/include/linux/pmu.h
index 6d73eada277e..373bd3b9b330 100644
--- a/include/linux/pmu.h
+++ b/include/linux/pmu.h
@@ -166,7 +166,7 @@ extern int pmu_i2c_simple_read(int bus, int addr, u8* data, int len);
166extern int pmu_i2c_simple_write(int bus, int addr, u8* data, int len); 166extern int pmu_i2c_simple_write(int bus, int addr, u8* data, int len);
167 167
168 168
169#ifdef CONFIG_PMAC_PBOOK 169#ifdef CONFIG_PM
170/* 170/*
171 * Stuff for putting the powerbook to sleep and waking it again. 171 * Stuff for putting the powerbook to sleep and waking it again.
172 * 172 *
@@ -208,6 +208,8 @@ struct pmu_sleep_notifier
208int pmu_register_sleep_notifier(struct pmu_sleep_notifier* notifier); 208int pmu_register_sleep_notifier(struct pmu_sleep_notifier* notifier);
209int pmu_unregister_sleep_notifier(struct pmu_sleep_notifier* notifier); 209int pmu_unregister_sleep_notifier(struct pmu_sleep_notifier* notifier);
210 210
211#endif /* CONFIG_PM */
212
211#define PMU_MAX_BATTERIES 2 213#define PMU_MAX_BATTERIES 2
212 214
213/* values for pmu_power_flags */ 215/* values for pmu_power_flags */
@@ -235,6 +237,4 @@ extern int pmu_battery_count;
235extern struct pmu_battery_info pmu_batteries[PMU_MAX_BATTERIES]; 237extern struct pmu_battery_info pmu_batteries[PMU_MAX_BATTERIES];
236extern unsigned int pmu_power_flags; 238extern unsigned int pmu_power_flags;
237 239
238#endif /* CONFIG_PMAC_PBOOK */
239
240#endif /* __KERNEL__ */ 240#endif /* __KERNEL__ */
diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index d021888b58f1..657c05ab8f9e 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -363,6 +363,8 @@ enum
363struct rta_session 363struct rta_session
364{ 364{
365 __u8 proto; 365 __u8 proto;
366 __u8 pad1;
367 __u16 pad2;
366 368
367 union { 369 union {
368 struct { 370 struct {
@@ -635,10 +637,13 @@ struct ifinfomsg
635struct prefixmsg 637struct prefixmsg
636{ 638{
637 unsigned char prefix_family; 639 unsigned char prefix_family;
640 unsigned char prefix_pad1;
641 unsigned short prefix_pad2;
638 int prefix_ifindex; 642 int prefix_ifindex;
639 unsigned char prefix_type; 643 unsigned char prefix_type;
640 unsigned char prefix_len; 644 unsigned char prefix_len;
641 unsigned char prefix_flags; 645 unsigned char prefix_flags;
646 unsigned char prefix_pad3;
642}; 647};
643 648
644enum 649enum
@@ -898,7 +903,9 @@ extern void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const voi
898 memcpy(skb_put(skb, attrlen), data, attrlen); }) 903 memcpy(skb_put(skb, attrlen), data, attrlen); })
899 904
900#define RTA_PUT_NOHDR(skb, attrlen, data) \ 905#define RTA_PUT_NOHDR(skb, attrlen, data) \
901 RTA_APPEND(skb, RTA_ALIGN(attrlen), data) 906({ RTA_APPEND(skb, RTA_ALIGN(attrlen), data); \
907 memset(skb->tail - (RTA_ALIGN(attrlen) - attrlen), 0, \
908 RTA_ALIGN(attrlen) - attrlen); })
902 909
903#define RTA_PUT_U8(skb, attrtype, value) \ 910#define RTA_PUT_U8(skb, attrtype, value) \
904({ u8 _tmp = (value); \ 911({ u8 _tmp = (value); \
@@ -978,6 +985,7 @@ __rta_reserve(struct sk_buff *skb, int attrtype, int attrlen)
978 rta = (struct rtattr*)skb_put(skb, RTA_ALIGN(size)); 985 rta = (struct rtattr*)skb_put(skb, RTA_ALIGN(size));
979 rta->rta_type = attrtype; 986 rta->rta_type = attrtype;
980 rta->rta_len = size; 987 rta->rta_len = size;
988 memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size);
981 return rta; 989 return rta;
982} 990}
983 991
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 9530b1903160..ff48815bd3a2 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -608,6 +608,8 @@ struct task_struct {
608 struct list_head run_list; 608 struct list_head run_list;
609 prio_array_t *array; 609 prio_array_t *array;
610 610
611 unsigned short ioprio;
612
611 unsigned long sleep_avg; 613 unsigned long sleep_avg;
612 unsigned long long timestamp, last_ran; 614 unsigned long long timestamp, last_ran;
613 unsigned long long sched_time; /* sched_clock time spent running */ 615 unsigned long long sched_time; /* sched_clock time spent running */
@@ -763,6 +765,7 @@ struct task_struct {
763 nodemask_t mems_allowed; 765 nodemask_t mems_allowed;
764 int cpuset_mems_generation; 766 int cpuset_mems_generation;
765#endif 767#endif
768 atomic_t fs_excl; /* holding fs exclusive resources */
766}; 769};
767 770
768static inline pid_t process_group(struct task_struct *tsk) 771static inline pid_t process_group(struct task_struct *tsk)
@@ -1112,7 +1115,8 @@ extern void unhash_process(struct task_struct *p);
1112 1115
1113/* 1116/*
1114 * Protects ->fs, ->files, ->mm, ->ptrace, ->group_info, ->comm, keyring 1117 * Protects ->fs, ->files, ->mm, ->ptrace, ->group_info, ->comm, keyring
1115 * subscriptions and synchronises with wait4(). Also used in procfs. 1118 * subscriptions and synchronises with wait4(). Also used in procfs. Also
1119 * pins the final release of task.io_context.
1116 * 1120 *
1117 * Nests both inside and outside of read_lock(&tasklist_lock). 1121 * Nests both inside and outside of read_lock(&tasklist_lock).
1118 * It must not be nested with write_lock_irq(&tasklist_lock), 1122 * It must not be nested with write_lock_irq(&tasklist_lock),
diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h
index 3a2702bbb1d6..dc89116bb1ca 100644
--- a/include/linux/seccomp.h
+++ b/include/linux/seccomp.h
@@ -19,6 +19,11 @@ static inline void secure_computing(int this_syscall)
19 __secure_computing(this_syscall); 19 __secure_computing(this_syscall);
20} 20}
21 21
22static inline int has_secure_computing(struct thread_info *ti)
23{
24 return unlikely(test_ti_thread_flag(ti, TIF_SECCOMP));
25}
26
22#else /* CONFIG_SECCOMP */ 27#else /* CONFIG_SECCOMP */
23 28
24#if (__GNUC__ > 2) 29#if (__GNUC__ > 2)
@@ -28,6 +33,11 @@ static inline void secure_computing(int this_syscall)
28#endif 33#endif
29 34
30#define secure_computing(x) do { } while (0) 35#define secure_computing(x) do { } while (0)
36/* static inline to preserve typechecking */
37static inline int has_secure_computing(struct thread_info *ti)
38{
39 return 0;
40}
31 41
32#endif /* CONFIG_SECCOMP */ 42#endif /* CONFIG_SECCOMP */
33 43
diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h
index 823181af6ddf..3e3c1fa35b06 100644
--- a/include/linux/serial_8250.h
+++ b/include/linux/serial_8250.h
@@ -22,6 +22,7 @@ struct plat_serial8250_port {
22 unsigned int uartclk; /* UART clock rate */ 22 unsigned int uartclk; /* UART clock rate */
23 unsigned char regshift; /* register shift */ 23 unsigned char regshift; /* register shift */
24 unsigned char iotype; /* UPIO_* */ 24 unsigned char iotype; /* UPIO_* */
25 unsigned char hub6;
25 unsigned int flags; /* UPF_* flags */ 26 unsigned int flags; /* UPF_* flags */
26}; 27};
27 28
diff --git a/include/linux/serio.h b/include/linux/serio.h
index a2d3b9ae06f4..aa4d6493a034 100644
--- a/include/linux/serio.h
+++ b/include/linux/serio.h
@@ -83,6 +83,7 @@ static inline void serio_register_port(struct serio *serio)
83} 83}
84 84
85void serio_unregister_port(struct serio *serio); 85void serio_unregister_port(struct serio *serio);
86void serio_unregister_child_port(struct serio *serio);
86void __serio_unregister_port_delayed(struct serio *serio, struct module *owner); 87void __serio_unregister_port_delayed(struct serio *serio, struct module *owner);
87static inline void serio_unregister_port_delayed(struct serio *serio) 88static inline void serio_unregister_port_delayed(struct serio *serio)
88{ 89{
@@ -153,6 +154,11 @@ static inline int serio_pin_driver(struct serio *serio)
153 return down_interruptible(&serio->drv_sem); 154 return down_interruptible(&serio->drv_sem);
154} 155}
155 156
157static inline void serio_pin_driver_uninterruptible(struct serio *serio)
158{
159 down(&serio->drv_sem);
160}
161
156static inline void serio_unpin_driver(struct serio *serio) 162static inline void serio_unpin_driver(struct serio *serio)
157{ 163{
158 up(&serio->drv_sem); 164 up(&serio->drv_sem);
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index ebfe1250f0a4..5b5f434ac9a0 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -641,6 +641,7 @@ enum {
641 NET_SCTP_ADDIP_ENABLE = 13, 641 NET_SCTP_ADDIP_ENABLE = 13,
642 NET_SCTP_PRSCTP_ENABLE = 14, 642 NET_SCTP_PRSCTP_ENABLE = 14,
643 NET_SCTP_SNDBUF_POLICY = 15, 643 NET_SCTP_SNDBUF_POLICY = 15,
644 NET_SCTP_SACK_TIMEOUT = 16,
644}; 645};
645 646
646/* /proc/sys/net/bridge */ 647/* /proc/sys/net/bridge */
diff --git a/include/linux/usb_ch9.h b/include/linux/usb_ch9.h
index f5fe94e09a03..ee21e6bf3867 100644
--- a/include/linux/usb_ch9.h
+++ b/include/linux/usb_ch9.h
@@ -6,17 +6,20 @@
6 * 6 *
7 * - the master/host side Linux-USB kernel driver API; 7 * - the master/host side Linux-USB kernel driver API;
8 * - the "usbfs" user space API; and 8 * - the "usbfs" user space API; and
9 * - (eventually) a Linux "gadget" slave/device side driver API. 9 * - the Linux "gadget" slave/device/peripheral side driver API.
10 * 10 *
11 * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems 11 * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems
12 * act either as a USB master/host or as a USB slave/device. That means 12 * act either as a USB master/host or as a USB slave/device. That means
13 * the master and slave side APIs will benefit from working well together. 13 * the master and slave side APIs benefit from working well together.
14 *
15 * There's also "Wireless USB", using low power short range radios for
16 * peripheral interconnection but otherwise building on the USB framework.
14 */ 17 */
15 18
16#ifndef __LINUX_USB_CH9_H 19#ifndef __LINUX_USB_CH9_H
17#define __LINUX_USB_CH9_H 20#define __LINUX_USB_CH9_H
18 21
19#include <asm/types.h> /* __u8 etc */ 22#include <linux/types.h> /* __u8 etc */
20 23
21/*-------------------------------------------------------------------------*/ 24/*-------------------------------------------------------------------------*/
22 25
@@ -68,6 +71,18 @@
68#define USB_REQ_SET_INTERFACE 0x0B 71#define USB_REQ_SET_INTERFACE 0x0B
69#define USB_REQ_SYNCH_FRAME 0x0C 72#define USB_REQ_SYNCH_FRAME 0x0C
70 73
74#define USB_REQ_SET_ENCRYPTION 0x0D /* Wireless USB */
75#define USB_REQ_GET_ENCRYPTION 0x0E
76#define USB_REQ_SET_HANDSHAKE 0x0F
77#define USB_REQ_GET_HANDSHAKE 0x10
78#define USB_REQ_SET_CONNECTION 0x11
79#define USB_REQ_SET_SECURITY_DATA 0x12
80#define USB_REQ_GET_SECURITY_DATA 0x13
81#define USB_REQ_SET_WUSB_DATA 0x14
82#define USB_REQ_LOOPBACK_DATA_WRITE 0x15
83#define USB_REQ_LOOPBACK_DATA_READ 0x16
84#define USB_REQ_SET_INTERFACE_DS 0x17
85
71/* 86/*
72 * USB feature flags are written using USB_REQ_{CLEAR,SET}_FEATURE, and 87 * USB feature flags are written using USB_REQ_{CLEAR,SET}_FEATURE, and
73 * are read as a bit array returned by USB_REQ_GET_STATUS. (So there 88 * are read as a bit array returned by USB_REQ_GET_STATUS. (So there
@@ -75,10 +90,12 @@
75 */ 90 */
76#define USB_DEVICE_SELF_POWERED 0 /* (read only) */ 91#define USB_DEVICE_SELF_POWERED 0 /* (read only) */
77#define USB_DEVICE_REMOTE_WAKEUP 1 /* dev may initiate wakeup */ 92#define USB_DEVICE_REMOTE_WAKEUP 1 /* dev may initiate wakeup */
78#define USB_DEVICE_TEST_MODE 2 /* (high speed only) */ 93#define USB_DEVICE_TEST_MODE 2 /* (wired high speed only) */
79#define USB_DEVICE_B_HNP_ENABLE 3 /* dev may initiate HNP */ 94#define USB_DEVICE_BATTERY 2 /* (wireless) */
80#define USB_DEVICE_A_HNP_SUPPORT 4 /* RH port supports HNP */ 95#define USB_DEVICE_B_HNP_ENABLE 3 /* (otg) dev may initiate HNP */
81#define USB_DEVICE_A_ALT_HNP_SUPPORT 5 /* other RH port does */ 96#define USB_DEVICE_WUSB_DEVICE 3 /* (wireless)*/
97#define USB_DEVICE_A_HNP_SUPPORT 4 /* (otg) RH port supports HNP */
98#define USB_DEVICE_A_ALT_HNP_SUPPORT 5 /* (otg) other RH port does */
82#define USB_DEVICE_DEBUG_MODE 6 /* (special devices only) */ 99#define USB_DEVICE_DEBUG_MODE 6 /* (special devices only) */
83 100
84#define USB_ENDPOINT_HALT 0 /* IN/OUT will STALL */ 101#define USB_ENDPOINT_HALT 0 /* IN/OUT will STALL */
@@ -135,6 +152,13 @@ struct usb_ctrlrequest {
135#define USB_DT_OTG 0x09 152#define USB_DT_OTG 0x09
136#define USB_DT_DEBUG 0x0a 153#define USB_DT_DEBUG 0x0a
137#define USB_DT_INTERFACE_ASSOCIATION 0x0b 154#define USB_DT_INTERFACE_ASSOCIATION 0x0b
155/* these are from the Wireless USB spec */
156#define USB_DT_SECURITY 0x0c
157#define USB_DT_KEY 0x0d
158#define USB_DT_ENCRYPTION_TYPE 0x0e
159#define USB_DT_BOS 0x0f
160#define USB_DT_DEVICE_CAPABILITY 0x10
161#define USB_DT_WIRELESS_ENDPOINT_COMP 0x11
138 162
139/* conventional codes for class-specific descriptors */ 163/* conventional codes for class-specific descriptors */
140#define USB_DT_CS_DEVICE 0x21 164#define USB_DT_CS_DEVICE 0x21
@@ -192,6 +216,7 @@ struct usb_device_descriptor {
192#define USB_CLASS_CSCID 0x0b /* chip+ smart card */ 216#define USB_CLASS_CSCID 0x0b /* chip+ smart card */
193#define USB_CLASS_CONTENT_SEC 0x0d /* content security */ 217#define USB_CLASS_CONTENT_SEC 0x0d /* content security */
194#define USB_CLASS_VIDEO 0x0e 218#define USB_CLASS_VIDEO 0x0e
219#define USB_CLASS_WIRELESS_CONTROLLER 0xe0
195#define USB_CLASS_APP_SPEC 0xfe 220#define USB_CLASS_APP_SPEC 0xfe
196#define USB_CLASS_VENDOR_SPEC 0xff 221#define USB_CLASS_VENDOR_SPEC 0xff
197 222
@@ -223,6 +248,7 @@ struct usb_config_descriptor {
223#define USB_CONFIG_ATT_ONE (1 << 7) /* must be set */ 248#define USB_CONFIG_ATT_ONE (1 << 7) /* must be set */
224#define USB_CONFIG_ATT_SELFPOWER (1 << 6) /* self powered */ 249#define USB_CONFIG_ATT_SELFPOWER (1 << 6) /* self powered */
225#define USB_CONFIG_ATT_WAKEUP (1 << 5) /* can wakeup */ 250#define USB_CONFIG_ATT_WAKEUP (1 << 5) /* can wakeup */
251#define USB_CONFIG_ATT_BATTERY (1 << 4) /* battery powered */
226 252
227/*-------------------------------------------------------------------------*/ 253/*-------------------------------------------------------------------------*/
228 254
@@ -268,8 +294,8 @@ struct usb_endpoint_descriptor {
268 __le16 wMaxPacketSize; 294 __le16 wMaxPacketSize;
269 __u8 bInterval; 295 __u8 bInterval;
270 296
271 // NOTE: these two are _only_ in audio endpoints. 297 /* NOTE: these two are _only_ in audio endpoints. */
272 // use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. 298 /* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
273 __u8 bRefresh; 299 __u8 bRefresh;
274 __u8 bSynchAddress; 300 __u8 bSynchAddress;
275} __attribute__ ((packed)); 301} __attribute__ ((packed));
@@ -289,6 +315,7 @@ struct usb_endpoint_descriptor {
289#define USB_ENDPOINT_XFER_ISOC 1 315#define USB_ENDPOINT_XFER_ISOC 1
290#define USB_ENDPOINT_XFER_BULK 2 316#define USB_ENDPOINT_XFER_BULK 2
291#define USB_ENDPOINT_XFER_INT 3 317#define USB_ENDPOINT_XFER_INT 3
318#define USB_ENDPOINT_MAX_ADJUSTABLE 0x80
292 319
293 320
294/*-------------------------------------------------------------------------*/ 321/*-------------------------------------------------------------------------*/
@@ -352,12 +379,154 @@ struct usb_interface_assoc_descriptor {
352 379
353/*-------------------------------------------------------------------------*/ 380/*-------------------------------------------------------------------------*/
354 381
382/* USB_DT_SECURITY: group of wireless security descriptors, including
383 * encryption types available for setting up a CC/association.
384 */
385struct usb_security_descriptor {
386 __u8 bLength;
387 __u8 bDescriptorType;
388
389 __le16 wTotalLength;
390 __u8 bNumEncryptionTypes;
391};
392
393/*-------------------------------------------------------------------------*/
394
395/* USB_DT_KEY: used with {GET,SET}_SECURITY_DATA; only public keys
396 * may be retrieved.
397 */
398struct usb_key_descriptor {
399 __u8 bLength;
400 __u8 bDescriptorType;
401
402 __u8 tTKID[3];
403 __u8 bReserved;
404 __u8 bKeyData[0];
405};
406
407/*-------------------------------------------------------------------------*/
408
409/* USB_DT_ENCRYPTION_TYPE: bundled in DT_SECURITY groups */
410struct usb_encryption_descriptor {
411 __u8 bLength;
412 __u8 bDescriptorType;
413
414 __u8 bEncryptionType;
415#define USB_ENC_TYPE_UNSECURE 0
416#define USB_ENC_TYPE_WIRED 1 /* non-wireless mode */
417#define USB_ENC_TYPE_CCM_1 2 /* aes128/cbc session */
418#define USB_ENC_TYPE_RSA_1 3 /* rsa3072/sha1 auth */
419 __u8 bEncryptionValue; /* use in SET_ENCRYPTION */
420 __u8 bAuthKeyIndex;
421};
422
423
424/*-------------------------------------------------------------------------*/
425
426/* USB_DT_BOS: group of wireless capabilities */
427struct usb_bos_descriptor {
428 __u8 bLength;
429 __u8 bDescriptorType;
430
431 __le16 wTotalLength;
432 __u8 bNumDeviceCaps;
433};
434
435/*-------------------------------------------------------------------------*/
436
437/* USB_DT_DEVICE_CAPABILITY: grouped with BOS */
438struct usb_dev_cap_header {
439 __u8 bLength;
440 __u8 bDescriptorType;
441 __u8 bDevCapabilityType;
442};
443
444#define USB_CAP_TYPE_WIRELESS_USB 1
445
446struct usb_wireless_cap_descriptor { /* Ultra Wide Band */
447 __u8 bLength;
448 __u8 bDescriptorType;
449 __u8 bDevCapabilityType;
450
451 __u8 bmAttributes;
452#define USB_WIRELESS_P2P_DRD (1 << 1)
453#define USB_WIRELESS_BEACON_MASK (3 << 2)
454#define USB_WIRELESS_BEACON_SELF (1 << 2)
455#define USB_WIRELESS_BEACON_DIRECTED (2 << 2)
456#define USB_WIRELESS_BEACON_NONE (3 << 2)
457 __le16 wPHYRates; /* bit rates, Mbps */
458#define USB_WIRELESS_PHY_53 (1 << 0) /* always set */
459#define USB_WIRELESS_PHY_80 (1 << 1)
460#define USB_WIRELESS_PHY_107 (1 << 2) /* always set */
461#define USB_WIRELESS_PHY_160 (1 << 3)
462#define USB_WIRELESS_PHY_200 (1 << 4) /* always set */
463#define USB_WIRELESS_PHY_320 (1 << 5)
464#define USB_WIRELESS_PHY_400 (1 << 6)
465#define USB_WIRELESS_PHY_480 (1 << 7)
466 __u8 bmTFITXPowerInfo; /* TFI power levels */
467 __u8 bmFFITXPowerInfo; /* FFI power levels */
468 __le16 bmBandGroup;
469 __u8 bReserved;
470};
471
472/*-------------------------------------------------------------------------*/
473
474/* USB_DT_WIRELESS_ENDPOINT_COMP: companion descriptor associated with
475 * each endpoint descriptor for a wireless device
476 */
477struct usb_wireless_ep_comp_descriptor {
478 __u8 bLength;
479 __u8 bDescriptorType;
480
481 __u8 bMaxBurst;
482 __u8 bMaxSequence;
483 __le16 wMaxStreamDelay;
484 __le16 wOverTheAirPacketSize;
485 __u8 bOverTheAirInterval;
486 __u8 bmCompAttributes;
487#define USB_ENDPOINT_SWITCH_MASK 0x03 /* in bmCompAttributes */
488#define USB_ENDPOINT_SWITCH_NO 0
489#define USB_ENDPOINT_SWITCH_SWITCH 1
490#define USB_ENDPOINT_SWITCH_SCALE 2
491};
492
493/*-------------------------------------------------------------------------*/
494
495/* USB_REQ_SET_HANDSHAKE is a four-way handshake used between a wireless
496 * host and a device for connection set up, mutual authentication, and
497 * exchanging short lived session keys. The handshake depends on a CC.
498 */
499struct usb_handshake {
500 __u8 bMessageNumber;
501 __u8 bStatus;
502 __u8 tTKID[3];
503 __u8 bReserved;
504 __u8 CDID[16];
505 __u8 nonce[16];
506 __u8 MIC[8];
507};
508
509/*-------------------------------------------------------------------------*/
510
511/* USB_REQ_SET_CONNECTION modifies or revokes a connection context (CC).
512 * A CC may also be set up using non-wireless secure channels (including
513 * wired USB!), and some devices may support CCs with multiple hosts.
514 */
515struct usb_connection_context {
516 __u8 CHID[16]; /* persistent host id */
517 __u8 CDID[16]; /* device id (unique w/in host context) */
518 __u8 CK[16]; /* connection key */
519};
520
521/*-------------------------------------------------------------------------*/
522
355/* USB 2.0 defines three speeds, here's how Linux identifies them */ 523/* USB 2.0 defines three speeds, here's how Linux identifies them */
356 524
357enum usb_device_speed { 525enum usb_device_speed {
358 USB_SPEED_UNKNOWN = 0, /* enumerating */ 526 USB_SPEED_UNKNOWN = 0, /* enumerating */
359 USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */ 527 USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
360 USB_SPEED_HIGH /* usb 2.0 */ 528 USB_SPEED_HIGH, /* usb 2.0 */
529 USB_SPEED_VARIABLE, /* wireless (usb 2.5) */
361}; 530};
362 531
363enum usb_device_state { 532enum usb_device_state {
diff --git a/include/linux/usb_gadget.h b/include/linux/usb_gadget.h
index 9bba9997947b..b00f127cb447 100644
--- a/include/linux/usb_gadget.h
+++ b/include/linux/usb_gadget.h
@@ -711,7 +711,7 @@ usb_gadget_disconnect (struct usb_gadget *gadget)
711 * the hardware level driver. Most calls must be handled by 711 * the hardware level driver. Most calls must be handled by
712 * the gadget driver, including descriptor and configuration 712 * the gadget driver, including descriptor and configuration
713 * management. The 16 bit members of the setup data are in 713 * management. The 16 bit members of the setup data are in
714 * cpu order. Called in_interrupt; this may not sleep. Driver 714 * USB byte order. Called in_interrupt; this may not sleep. Driver
715 * queues a response to ep0, or returns negative to stall. 715 * queues a response to ep0, or returns negative to stall.
716 * @disconnect: Invoked after all transfers have been stopped, 716 * @disconnect: Invoked after all transfers have been stopped,
717 * when the host is disconnected. May be called in_interrupt; this 717 * when the host is disconnected. May be called in_interrupt; this
diff --git a/include/linux/usb_isp116x.h b/include/linux/usb_isp116x.h
new file mode 100644
index 000000000000..5f5a9d9bd6c2
--- /dev/null
+++ b/include/linux/usb_isp116x.h
@@ -0,0 +1,47 @@
1
2/*
3 * Board initialization code should put one of these into dev->platform_data
4 * and place the isp116x onto platform_bus.
5 */
6
7struct isp116x_platform_data {
8 /* Enable internal resistors on downstream ports */
9 unsigned sel15Kres:1;
10 /* Chip's internal clock won't be stopped in suspended state.
11 Setting/unsetting this bit takes effect only if
12 'remote_wakeup_enable' below is not set. */
13 unsigned clknotstop:1;
14 /* On-chip overcurrent protection */
15 unsigned oc_enable:1;
16 /* INT output polarity */
17 unsigned int_act_high:1;
18 /* INT edge or level triggered */
19 unsigned int_edge_triggered:1;
20 /* WAKEUP pin connected - NOT SUPPORTED */
21 /* unsigned remote_wakeup_connected:1; */
22 /* Wakeup by devices on usb bus enabled */
23 unsigned remote_wakeup_enable:1;
24 /* Switch or not to switch (keep always powered) */
25 unsigned no_power_switching:1;
26 /* Ganged port power switching (0) or individual port
27 power switching (1) */
28 unsigned power_switching_mode:1;
29 /* Given port_power, msec/2 after power on till power good */
30 u8 potpg;
31 /* Hardware reset set/clear. If implemented, this function must:
32 if set == 0, deassert chip's HW reset pin
33 otherwise, assert chip's HW reset pin */
34 void (*reset) (struct device * dev, int set);
35 /* Hardware clock start/stop. If implemented, this function must:
36 if start == 0, stop the external clock
37 otherwise, start the external clock
38 */
39 void (*clock) (struct device * dev, int start);
40 /* Inter-io delay (ns). The chip is picky about access timings; it
41 expects at least:
42 150ns delay between consecutive accesses to DATA_REG,
43 300ns delay between access to ADDR_REG and DATA_REG
44 OE, WE MUST NOT be changed during these intervals
45 */
46 void (*delay) (struct device * dev, int delay);
47};
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index 4e0edce53760..acbfc525576d 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -221,6 +221,8 @@ struct v4l2_pix_format
221/* Vendor-specific formats */ 221/* Vendor-specific formats */
222#define V4L2_PIX_FMT_WNVA v4l2_fourcc('W','N','V','A') /* Winnov hw compress */ 222#define V4L2_PIX_FMT_WNVA v4l2_fourcc('W','N','V','A') /* Winnov hw compress */
223#define V4L2_PIX_FMT_SN9C10X v4l2_fourcc('S','9','1','0') /* SN9C10x compression */ 223#define V4L2_PIX_FMT_SN9C10X v4l2_fourcc('S','9','1','0') /* SN9C10x compression */
224#define V4L2_PIX_FMT_PWC1 v4l2_fourcc('P','W','C','1') /* pwc older webcam */
225#define V4L2_PIX_FMT_PWC2 v4l2_fourcc('P','W','C','2') /* pwc newer webcam */
224 226
225/* 227/*
226 * F O R M A T E N U M E R A T I O N 228 * F O R M A T E N U M E R A T I O N
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index 1262cb43c3ab..542dbaee6512 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -14,11 +14,13 @@ extern struct list_head inode_unused;
14 * Yes, writeback.h requires sched.h 14 * Yes, writeback.h requires sched.h
15 * No, sched.h is not included from here. 15 * No, sched.h is not included from here.
16 */ 16 */
17static inline int current_is_pdflush(void) 17static inline int task_is_pdflush(struct task_struct *task)
18{ 18{
19 return current->flags & PF_FLUSHER; 19 return task->flags & PF_FLUSHER;
20} 20}
21 21
22#define current_is_pdflush() task_is_pdflush(current)
23
22/* 24/*
23 * fs/fs-writeback.c 25 * fs/fs-writeback.c
24 */ 26 */
@@ -83,7 +85,7 @@ static inline void wait_on_inode(struct inode *inode)
83/* 85/*
84 * mm/page-writeback.c 86 * mm/page-writeback.c
85 */ 87 */
86int wakeup_bdflush(long nr_pages); 88int wakeup_pdflush(long nr_pages);
87void laptop_io_completion(void); 89void laptop_io_completion(void);
88void laptop_sync_completion(void); 90void laptop_sync_completion(void);
89void throttle_vm_writeout(void); 91void throttle_vm_writeout(void);
diff --git a/include/linux/xattr_acl.h b/include/linux/xattr_acl.h
deleted file mode 100644
index 7a1f9b93a45f..000000000000
--- a/include/linux/xattr_acl.h
+++ /dev/null
@@ -1,50 +0,0 @@
1/*
2 File: linux/xattr_acl.h
3
4 (extended attribute representation of access control lists)
5
6 (C) 2000 Andreas Gruenbacher, <a.gruenbacher@computer.org>
7*/
8
9#ifndef _LINUX_XATTR_ACL_H
10#define _LINUX_XATTR_ACL_H
11
12#include <linux/posix_acl.h>
13
14#define XATTR_NAME_ACL_ACCESS "system.posix_acl_access"
15#define XATTR_NAME_ACL_DEFAULT "system.posix_acl_default"
16
17#define XATTR_ACL_VERSION 0x0002
18
19typedef struct {
20 __u16 e_tag;
21 __u16 e_perm;
22 __u32 e_id;
23} xattr_acl_entry;
24
25typedef struct {
26 __u32 a_version;
27 xattr_acl_entry a_entries[0];
28} xattr_acl_header;
29
30static inline size_t xattr_acl_size(int count)
31{
32 return sizeof(xattr_acl_header) + count * sizeof(xattr_acl_entry);
33}
34
35static inline int xattr_acl_count(size_t size)
36{
37 if (size < sizeof(xattr_acl_header))
38 return -1;
39 size -= sizeof(xattr_acl_header);
40 if (size % sizeof(xattr_acl_entry))
41 return -1;
42 return size / sizeof(xattr_acl_entry);
43}
44
45struct posix_acl * posix_acl_from_xattr(const void *value, size_t size);
46int posix_acl_to_xattr(const struct posix_acl *acl, void *buffer, size_t size);
47
48
49
50#endif /* _LINUX_XATTR_ACL_H */
diff --git a/include/media/tuner.h b/include/media/tuner.h
index 2dd8310901e8..4794c5632360 100644
--- a/include/media/tuner.h
+++ b/include/media/tuner.h
@@ -1,5 +1,6 @@
1 1
2/* 2/* $Id: tuner.h,v 1.33 2005/06/21 14:58:08 mkrufky Exp $
3 *
3 tuner.h - definition for different tuners 4 tuner.h - definition for different tuners
4 5
5 Copyright (C) 1997 Markus Schroeder (schroedm@uni-duesseldorf.de) 6 Copyright (C) 1997 Markus Schroeder (schroedm@uni-duesseldorf.de)
@@ -23,6 +24,8 @@
23#ifndef _TUNER_H 24#ifndef _TUNER_H
24#define _TUNER_H 25#define _TUNER_H
25 26
27#include <linux/videodev2.h>
28
26#include "id.h" 29#include "id.h"
27 30
28#define ADDR_UNSET (255) 31#define ADDR_UNSET (255)
@@ -88,7 +91,7 @@
88#define TUNER_LG_NTSC_TAPE 47 91#define TUNER_LG_NTSC_TAPE 47
89 92
90#define TUNER_TNF_8831BGFF 48 93#define TUNER_TNF_8831BGFF 48
91#define TUNER_MICROTUNE_4042FI5 49 /* FusionHDTV 3 Gold - 4042 FI5 (3X 8147) */ 94#define TUNER_MICROTUNE_4042FI5 49 /* DViCO FusionHDTV 3 Gold-Q - 4042 FI5 (3X 8147) */
92#define TUNER_TCL_2002N 50 95#define TUNER_TCL_2002N 50
93#define TUNER_PHILIPS_FM1256_IH3 51 96#define TUNER_PHILIPS_FM1256_IH3 51
94 97
@@ -98,18 +101,18 @@
98#define TUNER_LG_PAL_TAPE 55 /* Hauppauge PVR-150 PAL */ 101#define TUNER_LG_PAL_TAPE 55 /* Hauppauge PVR-150 PAL */
99 102
100#define TUNER_PHILIPS_FQ1216AME_MK4 56 /* Hauppauge PVR-150 PAL */ 103#define TUNER_PHILIPS_FQ1216AME_MK4 56 /* Hauppauge PVR-150 PAL */
101#define TUNER_PHILIPS_FQ1236A_MK4 57 /* Hauppauge PVR-500MCE NTSC */ 104#define TUNER_PHILIPS_FQ1236A_MK4 57 /* Hauppauge PVR-500MCE NTSC */
102 105
103#define TUNER_YMEC_TVF_8531MF 58 106#define TUNER_YMEC_TVF_8531MF 58
104#define TUNER_YMEC_TVF_5533MF 59 /* Pixelview Pro Ultra NTSC */ 107#define TUNER_YMEC_TVF_5533MF 59 /* Pixelview Pro Ultra NTSC */
105#define TUNER_THOMSON_DTT7611 60 108#define TUNER_THOMSON_DTT7611 60 /* DViCO FusionHDTV 3 Gold-T */
106#define TUNER_TENA_9533_DI 61 109#define TUNER_TENA_9533_DI 61
110
107#define TUNER_TEA5767 62 /* Only FM Radio Tuner */ 111#define TUNER_TEA5767 62 /* Only FM Radio Tuner */
112#define TUNER_PHILIPS_FMD1216ME_MK3 63
108 113
109#define TEA5767_TUNER_NAME "Philips TEA5767HN FM Radio" 114#define TEA5767_TUNER_NAME "Philips TEA5767HN FM Radio"
110 115
111#define TUNER_THOMSON_DTT7611 60
112
113#define NOTUNER 0 116#define NOTUNER 0
114#define PAL 1 /* PAL_BG */ 117#define PAL 1 /* PAL_BG */
115#define PAL_I 2 118#define PAL_I 2
@@ -194,11 +197,15 @@ struct tuner {
194 unsigned char i2c_easy_mode[2]; 197 unsigned char i2c_easy_mode[2];
195 unsigned char i2c_set_freq[8]; 198 unsigned char i2c_set_freq[8];
196 199
200 /* used to keep track of audmode */
201 unsigned int audmode;
202
197 /* function ptrs */ 203 /* function ptrs */
198 void (*tv_freq)(struct i2c_client *c, unsigned int freq); 204 void (*tv_freq)(struct i2c_client *c, unsigned int freq);
199 void (*radio_freq)(struct i2c_client *c, unsigned int freq); 205 void (*radio_freq)(struct i2c_client *c, unsigned int freq);
200 int (*has_signal)(struct i2c_client *c); 206 int (*has_signal)(struct i2c_client *c);
201 int (*is_stereo)(struct i2c_client *c); 207 int (*is_stereo)(struct i2c_client *c);
208 int (*set_tuner)(struct i2c_client *c, struct v4l2_tuner *v);
202}; 209};
203 210
204extern unsigned int tuner_debug; 211extern unsigned int tuner_debug;
@@ -206,6 +213,7 @@ extern unsigned const int tuner_count;
206 213
207extern int microtune_init(struct i2c_client *c); 214extern int microtune_init(struct i2c_client *c);
208extern int tda8290_init(struct i2c_client *c); 215extern int tda8290_init(struct i2c_client *c);
216extern int tea5767_tuner_init(struct i2c_client *c);
209extern int default_tuner_init(struct i2c_client *c); 217extern int default_tuner_init(struct i2c_client *c);
210 218
211#define tuner_warn(fmt, arg...) \ 219#define tuner_warn(fmt, arg...) \
diff --git a/include/net/ieee80211.h b/include/net/ieee80211.h
new file mode 100644
index 000000000000..db09580ad14b
--- /dev/null
+++ b/include/net/ieee80211.h
@@ -0,0 +1,856 @@
1/*
2 * Merged with mainline ieee80211.h in Aug 2004. Original ieee802_11
3 * remains copyright by the original authors
4 *
5 * Portions of the merged code are based on Host AP (software wireless
6 * LAN access point) driver for Intersil Prism2/2.5/3.
7 *
8 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
9 * <jkmaline@cc.hut.fi>
10 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
11 *
12 * Adaption to a generic IEEE 802.11 stack by James Ketrenos
13 * <jketreno@linux.intel.com>
14 * Copyright (c) 2004, Intel Corporation
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as
18 * published by the Free Software Foundation. See README and COPYING for
19 * more details.
20 */
21#ifndef IEEE80211_H
22#define IEEE80211_H
23
24#include <linux/if_ether.h> /* ETH_ALEN */
25#include <linux/kernel.h> /* ARRAY_SIZE */
26
27#if WIRELESS_EXT < 17
28#define IW_QUAL_QUAL_INVALID 0x10
29#define IW_QUAL_LEVEL_INVALID 0x20
30#define IW_QUAL_NOISE_INVALID 0x40
31#define IW_QUAL_QUAL_UPDATED 0x1
32#define IW_QUAL_LEVEL_UPDATED 0x2
33#define IW_QUAL_NOISE_UPDATED 0x4
34#endif
35
36#define IEEE80211_DATA_LEN 2304
37/* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
38 6.2.1.1.2.
39
40 The figure in section 7.1.2 suggests a body size of up to 2312
41 bytes is allowed, which is a bit confusing, I suspect this
42 represents the 2304 bytes of real data, plus a possible 8 bytes of
43 WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
44
45
46#define IEEE80211_HLEN 30
47#define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
48
49struct ieee80211_hdr {
50 u16 frame_ctl;
51 u16 duration_id;
52 u8 addr1[ETH_ALEN];
53 u8 addr2[ETH_ALEN];
54 u8 addr3[ETH_ALEN];
55 u16 seq_ctl;
56 u8 addr4[ETH_ALEN];
57} __attribute__ ((packed));
58
59struct ieee80211_hdr_3addr {
60 u16 frame_ctl;
61 u16 duration_id;
62 u8 addr1[ETH_ALEN];
63 u8 addr2[ETH_ALEN];
64 u8 addr3[ETH_ALEN];
65 u16 seq_ctl;
66} __attribute__ ((packed));
67
68enum eap_type {
69 EAP_PACKET = 0,
70 EAPOL_START,
71 EAPOL_LOGOFF,
72 EAPOL_KEY,
73 EAPOL_ENCAP_ASF_ALERT
74};
75
76static const char *eap_types[] = {
77 [EAP_PACKET] = "EAP-Packet",
78 [EAPOL_START] = "EAPOL-Start",
79 [EAPOL_LOGOFF] = "EAPOL-Logoff",
80 [EAPOL_KEY] = "EAPOL-Key",
81 [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert"
82};
83
84static inline const char *eap_get_type(int type)
85{
86 return (type >= ARRAY_SIZE(eap_types)) ? "Unknown" : eap_types[type];
87}
88
89struct eapol {
90 u8 snap[6];
91 u16 ethertype;
92 u8 version;
93 u8 type;
94 u16 length;
95} __attribute__ ((packed));
96
97#define IEEE80211_1ADDR_LEN 10
98#define IEEE80211_2ADDR_LEN 16
99#define IEEE80211_3ADDR_LEN 24
100#define IEEE80211_4ADDR_LEN 30
101#define IEEE80211_FCS_LEN 4
102
103#define MIN_FRAG_THRESHOLD 256U
104#define MAX_FRAG_THRESHOLD 2346U
105
106/* Frame control field constants */
107#define IEEE80211_FCTL_VERS 0x0002
108#define IEEE80211_FCTL_FTYPE 0x000c
109#define IEEE80211_FCTL_STYPE 0x00f0
110#define IEEE80211_FCTL_TODS 0x0100
111#define IEEE80211_FCTL_FROMDS 0x0200
112#define IEEE80211_FCTL_MOREFRAGS 0x0400
113#define IEEE80211_FCTL_RETRY 0x0800
114#define IEEE80211_FCTL_PM 0x1000
115#define IEEE80211_FCTL_MOREDATA 0x2000
116#define IEEE80211_FCTL_WEP 0x4000
117#define IEEE80211_FCTL_ORDER 0x8000
118
119#define IEEE80211_FTYPE_MGMT 0x0000
120#define IEEE80211_FTYPE_CTL 0x0004
121#define IEEE80211_FTYPE_DATA 0x0008
122
123/* management */
124#define IEEE80211_STYPE_ASSOC_REQ 0x0000
125#define IEEE80211_STYPE_ASSOC_RESP 0x0010
126#define IEEE80211_STYPE_REASSOC_REQ 0x0020
127#define IEEE80211_STYPE_REASSOC_RESP 0x0030
128#define IEEE80211_STYPE_PROBE_REQ 0x0040
129#define IEEE80211_STYPE_PROBE_RESP 0x0050
130#define IEEE80211_STYPE_BEACON 0x0080
131#define IEEE80211_STYPE_ATIM 0x0090
132#define IEEE80211_STYPE_DISASSOC 0x00A0
133#define IEEE80211_STYPE_AUTH 0x00B0
134#define IEEE80211_STYPE_DEAUTH 0x00C0
135
136/* control */
137#define IEEE80211_STYPE_PSPOLL 0x00A0
138#define IEEE80211_STYPE_RTS 0x00B0
139#define IEEE80211_STYPE_CTS 0x00C0
140#define IEEE80211_STYPE_ACK 0x00D0
141#define IEEE80211_STYPE_CFEND 0x00E0
142#define IEEE80211_STYPE_CFENDACK 0x00F0
143
144/* data */
145#define IEEE80211_STYPE_DATA 0x0000
146#define IEEE80211_STYPE_DATA_CFACK 0x0010
147#define IEEE80211_STYPE_DATA_CFPOLL 0x0020
148#define IEEE80211_STYPE_DATA_CFACKPOLL 0x0030
149#define IEEE80211_STYPE_NULLFUNC 0x0040
150#define IEEE80211_STYPE_CFACK 0x0050
151#define IEEE80211_STYPE_CFPOLL 0x0060
152#define IEEE80211_STYPE_CFACKPOLL 0x0070
153
154#define IEEE80211_SCTL_FRAG 0x000F
155#define IEEE80211_SCTL_SEQ 0xFFF0
156
157
158/* debug macros */
159
160#ifdef CONFIG_IEEE80211_DEBUG
161extern u32 ieee80211_debug_level;
162#define IEEE80211_DEBUG(level, fmt, args...) \
163do { if (ieee80211_debug_level & (level)) \
164 printk(KERN_DEBUG "ieee80211: %c %s " fmt, \
165 in_interrupt() ? 'I' : 'U', __FUNCTION__ , ## args); } while (0)
166#else
167#define IEEE80211_DEBUG(level, fmt, args...) do {} while (0)
168#endif /* CONFIG_IEEE80211_DEBUG */
169
170/*
171 * To use the debug system;
172 *
173 * If you are defining a new debug classification, simply add it to the #define
174 * list here in the form of:
175 *
176 * #define IEEE80211_DL_xxxx VALUE
177 *
178 * shifting value to the left one bit from the previous entry. xxxx should be
179 * the name of the classification (for example, WEP)
180 *
181 * You then need to either add a IEEE80211_xxxx_DEBUG() macro definition for your
182 * classification, or use IEEE80211_DEBUG(IEEE80211_DL_xxxx, ...) whenever you want
183 * to send output to that classification.
184 *
185 * To add your debug level to the list of levels seen when you perform
186 *
187 * % cat /proc/net/ipw/debug_level
188 *
189 * you simply need to add your entry to the ipw_debug_levels array.
190 *
191 * If you do not see debug_level in /proc/net/ipw then you do not have
192 * CONFIG_IEEE80211_DEBUG defined in your kernel configuration
193 *
194 */
195
196#define IEEE80211_DL_INFO (1<<0)
197#define IEEE80211_DL_WX (1<<1)
198#define IEEE80211_DL_SCAN (1<<2)
199#define IEEE80211_DL_STATE (1<<3)
200#define IEEE80211_DL_MGMT (1<<4)
201#define IEEE80211_DL_FRAG (1<<5)
202#define IEEE80211_DL_EAP (1<<6)
203#define IEEE80211_DL_DROP (1<<7)
204
205#define IEEE80211_DL_TX (1<<8)
206#define IEEE80211_DL_RX (1<<9)
207
208#define IEEE80211_ERROR(f, a...) printk(KERN_ERR "ieee80211: " f, ## a)
209#define IEEE80211_WARNING(f, a...) printk(KERN_WARNING "ieee80211: " f, ## a)
210#define IEEE80211_DEBUG_INFO(f, a...) IEEE80211_DEBUG(IEEE80211_DL_INFO, f, ## a)
211
212#define IEEE80211_DEBUG_WX(f, a...) IEEE80211_DEBUG(IEEE80211_DL_WX, f, ## a)
213#define IEEE80211_DEBUG_SCAN(f, a...) IEEE80211_DEBUG(IEEE80211_DL_SCAN, f, ## a)
214#define IEEE80211_DEBUG_STATE(f, a...) IEEE80211_DEBUG(IEEE80211_DL_STATE, f, ## a)
215#define IEEE80211_DEBUG_MGMT(f, a...) IEEE80211_DEBUG(IEEE80211_DL_MGMT, f, ## a)
216#define IEEE80211_DEBUG_FRAG(f, a...) IEEE80211_DEBUG(IEEE80211_DL_FRAG, f, ## a)
217#define IEEE80211_DEBUG_EAP(f, a...) IEEE80211_DEBUG(IEEE80211_DL_EAP, f, ## a)
218#define IEEE80211_DEBUG_DROP(f, a...) IEEE80211_DEBUG(IEEE80211_DL_DROP, f, ## a)
219#define IEEE80211_DEBUG_TX(f, a...) IEEE80211_DEBUG(IEEE80211_DL_TX, f, ## a)
220#define IEEE80211_DEBUG_RX(f, a...) IEEE80211_DEBUG(IEEE80211_DL_RX, f, ## a)
221#include <linux/netdevice.h>
222#include <linux/wireless.h>
223#include <linux/if_arp.h> /* ARPHRD_ETHER */
224
225#ifndef WIRELESS_SPY
226#define WIRELESS_SPY // enable iwspy support
227#endif
228#include <net/iw_handler.h> // new driver API
229
230#ifndef ETH_P_PAE
231#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
232#endif /* ETH_P_PAE */
233
234#define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
235
236#ifndef ETH_P_80211_RAW
237#define ETH_P_80211_RAW (ETH_P_ECONET + 1)
238#endif
239
240/* IEEE 802.11 defines */
241
242#define P80211_OUI_LEN 3
243
244struct ieee80211_snap_hdr {
245
246 u8 dsap; /* always 0xAA */
247 u8 ssap; /* always 0xAA */
248 u8 ctrl; /* always 0x03 */
249 u8 oui[P80211_OUI_LEN]; /* organizational universal id */
250
251} __attribute__ ((packed));
252
253#define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
254
255#define WLAN_FC_GET_TYPE(fc) ((fc) & IEEE80211_FCTL_FTYPE)
256#define WLAN_FC_GET_STYPE(fc) ((fc) & IEEE80211_FCTL_STYPE)
257
258#define WLAN_GET_SEQ_FRAG(seq) ((seq) & IEEE80211_SCTL_FRAG)
259#define WLAN_GET_SEQ_SEQ(seq) ((seq) & IEEE80211_SCTL_SEQ)
260
261/* Authentication algorithms */
262#define WLAN_AUTH_OPEN 0
263#define WLAN_AUTH_SHARED_KEY 1
264
265#define WLAN_AUTH_CHALLENGE_LEN 128
266
267#define WLAN_CAPABILITY_BSS (1<<0)
268#define WLAN_CAPABILITY_IBSS (1<<1)
269#define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
270#define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
271#define WLAN_CAPABILITY_PRIVACY (1<<4)
272#define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
273#define WLAN_CAPABILITY_PBCC (1<<6)
274#define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
275
276/* Status codes */
277#define WLAN_STATUS_SUCCESS 0
278#define WLAN_STATUS_UNSPECIFIED_FAILURE 1
279#define WLAN_STATUS_CAPS_UNSUPPORTED 10
280#define WLAN_STATUS_REASSOC_NO_ASSOC 11
281#define WLAN_STATUS_ASSOC_DENIED_UNSPEC 12
282#define WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG 13
283#define WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION 14
284#define WLAN_STATUS_CHALLENGE_FAIL 15
285#define WLAN_STATUS_AUTH_TIMEOUT 16
286#define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
287#define WLAN_STATUS_ASSOC_DENIED_RATES 18
288/* 802.11b */
289#define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
290#define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
291#define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
292
293/* Reason codes */
294#define WLAN_REASON_UNSPECIFIED 1
295#define WLAN_REASON_PREV_AUTH_NOT_VALID 2
296#define WLAN_REASON_DEAUTH_LEAVING 3
297#define WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY 4
298#define WLAN_REASON_DISASSOC_AP_BUSY 5
299#define WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
300#define WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7
301#define WLAN_REASON_DISASSOC_STA_HAS_LEFT 8
302#define WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
303
304
305#define IEEE80211_STATMASK_SIGNAL (1<<0)
306#define IEEE80211_STATMASK_RSSI (1<<1)
307#define IEEE80211_STATMASK_NOISE (1<<2)
308#define IEEE80211_STATMASK_RATE (1<<3)
309#define IEEE80211_STATMASK_WEMASK 0x7
310
311
312#define IEEE80211_CCK_MODULATION (1<<0)
313#define IEEE80211_OFDM_MODULATION (1<<1)
314
315#define IEEE80211_24GHZ_BAND (1<<0)
316#define IEEE80211_52GHZ_BAND (1<<1)
317
318#define IEEE80211_CCK_RATE_1MB 0x02
319#define IEEE80211_CCK_RATE_2MB 0x04
320#define IEEE80211_CCK_RATE_5MB 0x0B
321#define IEEE80211_CCK_RATE_11MB 0x16
322#define IEEE80211_OFDM_RATE_6MB 0x0C
323#define IEEE80211_OFDM_RATE_9MB 0x12
324#define IEEE80211_OFDM_RATE_12MB 0x18
325#define IEEE80211_OFDM_RATE_18MB 0x24
326#define IEEE80211_OFDM_RATE_24MB 0x30
327#define IEEE80211_OFDM_RATE_36MB 0x48
328#define IEEE80211_OFDM_RATE_48MB 0x60
329#define IEEE80211_OFDM_RATE_54MB 0x6C
330#define IEEE80211_BASIC_RATE_MASK 0x80
331
332#define IEEE80211_CCK_RATE_1MB_MASK (1<<0)
333#define IEEE80211_CCK_RATE_2MB_MASK (1<<1)
334#define IEEE80211_CCK_RATE_5MB_MASK (1<<2)
335#define IEEE80211_CCK_RATE_11MB_MASK (1<<3)
336#define IEEE80211_OFDM_RATE_6MB_MASK (1<<4)
337#define IEEE80211_OFDM_RATE_9MB_MASK (1<<5)
338#define IEEE80211_OFDM_RATE_12MB_MASK (1<<6)
339#define IEEE80211_OFDM_RATE_18MB_MASK (1<<7)
340#define IEEE80211_OFDM_RATE_24MB_MASK (1<<8)
341#define IEEE80211_OFDM_RATE_36MB_MASK (1<<9)
342#define IEEE80211_OFDM_RATE_48MB_MASK (1<<10)
343#define IEEE80211_OFDM_RATE_54MB_MASK (1<<11)
344
345#define IEEE80211_CCK_RATES_MASK 0x0000000F
346#define IEEE80211_CCK_BASIC_RATES_MASK (IEEE80211_CCK_RATE_1MB_MASK | \
347 IEEE80211_CCK_RATE_2MB_MASK)
348#define IEEE80211_CCK_DEFAULT_RATES_MASK (IEEE80211_CCK_BASIC_RATES_MASK | \
349 IEEE80211_CCK_RATE_5MB_MASK | \
350 IEEE80211_CCK_RATE_11MB_MASK)
351
352#define IEEE80211_OFDM_RATES_MASK 0x00000FF0
353#define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
354 IEEE80211_OFDM_RATE_12MB_MASK | \
355 IEEE80211_OFDM_RATE_24MB_MASK)
356#define IEEE80211_OFDM_DEFAULT_RATES_MASK (IEEE80211_OFDM_BASIC_RATES_MASK | \
357 IEEE80211_OFDM_RATE_9MB_MASK | \
358 IEEE80211_OFDM_RATE_18MB_MASK | \
359 IEEE80211_OFDM_RATE_36MB_MASK | \
360 IEEE80211_OFDM_RATE_48MB_MASK | \
361 IEEE80211_OFDM_RATE_54MB_MASK)
362#define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
363 IEEE80211_CCK_DEFAULT_RATES_MASK)
364
365#define IEEE80211_NUM_OFDM_RATES 8
366#define IEEE80211_NUM_CCK_RATES 4
367#define IEEE80211_OFDM_SHIFT_MASK_A 4
368
369
370
371
372/* NOTE: This data is for statistical purposes; not all hardware provides this
373 * information for frames received. Not setting these will not cause
374 * any adverse affects. */
375struct ieee80211_rx_stats {
376 u32 mac_time;
377 s8 rssi;
378 u8 signal;
379 u8 noise;
380 u16 rate; /* in 100 kbps */
381 u8 received_channel;
382 u8 control;
383 u8 mask;
384 u8 freq;
385 u16 len;
386};
387
388/* IEEE 802.11 requires that STA supports concurrent reception of at least
389 * three fragmented frames. This define can be increased to support more
390 * concurrent frames, but it should be noted that each entry can consume about
391 * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
392#define IEEE80211_FRAG_CACHE_LEN 4
393
394struct ieee80211_frag_entry {
395 unsigned long first_frag_time;
396 unsigned int seq;
397 unsigned int last_frag;
398 struct sk_buff *skb;
399 u8 src_addr[ETH_ALEN];
400 u8 dst_addr[ETH_ALEN];
401};
402
403struct ieee80211_stats {
404 unsigned int tx_unicast_frames;
405 unsigned int tx_multicast_frames;
406 unsigned int tx_fragments;
407 unsigned int tx_unicast_octets;
408 unsigned int tx_multicast_octets;
409 unsigned int tx_deferred_transmissions;
410 unsigned int tx_single_retry_frames;
411 unsigned int tx_multiple_retry_frames;
412 unsigned int tx_retry_limit_exceeded;
413 unsigned int tx_discards;
414 unsigned int rx_unicast_frames;
415 unsigned int rx_multicast_frames;
416 unsigned int rx_fragments;
417 unsigned int rx_unicast_octets;
418 unsigned int rx_multicast_octets;
419 unsigned int rx_fcs_errors;
420 unsigned int rx_discards_no_buffer;
421 unsigned int tx_discards_wrong_sa;
422 unsigned int rx_discards_undecryptable;
423 unsigned int rx_message_in_msg_fragments;
424 unsigned int rx_message_in_bad_msg_fragments;
425};
426
427struct ieee80211_device;
428
429#if 0 /* for later */
430#include "ieee80211_crypt.h"
431#endif
432
433#define SEC_KEY_1 (1<<0)
434#define SEC_KEY_2 (1<<1)
435#define SEC_KEY_3 (1<<2)
436#define SEC_KEY_4 (1<<3)
437#define SEC_ACTIVE_KEY (1<<4)
438#define SEC_AUTH_MODE (1<<5)
439#define SEC_UNICAST_GROUP (1<<6)
440#define SEC_LEVEL (1<<7)
441#define SEC_ENABLED (1<<8)
442
443#define SEC_LEVEL_0 0 /* None */
444#define SEC_LEVEL_1 1 /* WEP 40 and 104 bit */
445#define SEC_LEVEL_2 2 /* Level 1 + TKIP */
446#define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
447#define SEC_LEVEL_3 4 /* Level 2 + CCMP */
448
449#define WEP_KEYS 4
450#define WEP_KEY_LEN 13
451
452struct ieee80211_security {
453 u16 active_key:2,
454 enabled:1,
455 auth_mode:2,
456 auth_algo:4,
457 unicast_uses_group:1;
458 u8 key_sizes[WEP_KEYS];
459 u8 keys[WEP_KEYS][WEP_KEY_LEN];
460 u8 level;
461 u16 flags;
462} __attribute__ ((packed));
463
464
465/*
466
467 802.11 data frame from AP
468
469 ,-------------------------------------------------------------------.
470Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 |
471 |------|------|---------|---------|---------|------|---------|------|
472Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | frame | fcs |
473 | | tion | (BSSID) | | | ence | data | |
474 `-------------------------------------------------------------------'
475
476Total: 28-2340 bytes
477
478*/
479
480#define BEACON_PROBE_SSID_ID_POSITION 12
481
482/* Management Frame Information Element Types */
483#define MFIE_TYPE_SSID 0
484#define MFIE_TYPE_RATES 1
485#define MFIE_TYPE_FH_SET 2
486#define MFIE_TYPE_DS_SET 3
487#define MFIE_TYPE_CF_SET 4
488#define MFIE_TYPE_TIM 5
489#define MFIE_TYPE_IBSS_SET 6
490#define MFIE_TYPE_CHALLENGE 16
491#define MFIE_TYPE_RSN 48
492#define MFIE_TYPE_RATES_EX 50
493#define MFIE_TYPE_GENERIC 221
494
495struct ieee80211_info_element_hdr {
496 u8 id;
497 u8 len;
498} __attribute__ ((packed));
499
500struct ieee80211_info_element {
501 u8 id;
502 u8 len;
503 u8 data[0];
504} __attribute__ ((packed));
505
506/*
507 * These are the data types that can make up management packets
508 *
509 u16 auth_algorithm;
510 u16 auth_sequence;
511 u16 beacon_interval;
512 u16 capability;
513 u8 current_ap[ETH_ALEN];
514 u16 listen_interval;
515 struct {
516 u16 association_id:14, reserved:2;
517 } __attribute__ ((packed));
518 u32 time_stamp[2];
519 u16 reason;
520 u16 status;
521*/
522
523struct ieee80211_authentication {
524 struct ieee80211_hdr_3addr header;
525 u16 algorithm;
526 u16 transaction;
527 u16 status;
528 struct ieee80211_info_element info_element;
529} __attribute__ ((packed));
530
531
532struct ieee80211_probe_response {
533 struct ieee80211_hdr_3addr header;
534 u32 time_stamp[2];
535 u16 beacon_interval;
536 u16 capability;
537 struct ieee80211_info_element info_element;
538} __attribute__ ((packed));
539
540struct ieee80211_assoc_request_frame {
541 u16 capability;
542 u16 listen_interval;
543 u8 current_ap[ETH_ALEN];
544 struct ieee80211_info_element info_element;
545} __attribute__ ((packed));
546
547struct ieee80211_assoc_response_frame {
548 struct ieee80211_hdr_3addr header;
549 u16 capability;
550 u16 status;
551 u16 aid;
552 struct ieee80211_info_element info_element; /* supported rates */
553} __attribute__ ((packed));
554
555
556struct ieee80211_txb {
557 u8 nr_frags;
558 u8 encrypted;
559 u16 reserved;
560 u16 frag_size;
561 u16 payload_size;
562 struct sk_buff *fragments[0];
563};
564
565
566/* SWEEP TABLE ENTRIES NUMBER*/
567#define MAX_SWEEP_TAB_ENTRIES 42
568#define MAX_SWEEP_TAB_ENTRIES_PER_PACKET 7
569/* MAX_RATES_LENGTH needs to be 12. The spec says 8, and many APs
570 * only use 8, and then use extended rates for the remaining supported
571 * rates. Other APs, however, stick all of their supported rates on the
572 * main rates information element... */
573#define MAX_RATES_LENGTH ((u8)12)
574#define MAX_RATES_EX_LENGTH ((u8)16)
575#define MAX_NETWORK_COUNT 128
576
577#define CRC_LENGTH 4U
578
579#define MAX_WPA_IE_LEN 64
580
581#define NETWORK_EMPTY_ESSID (1<<0)
582#define NETWORK_HAS_OFDM (1<<1)
583#define NETWORK_HAS_CCK (1<<2)
584
585struct ieee80211_network {
586 /* These entries are used to identify a unique network */
587 u8 bssid[ETH_ALEN];
588 u8 channel;
589 /* Ensure null-terminated for any debug msgs */
590 u8 ssid[IW_ESSID_MAX_SIZE + 1];
591 u8 ssid_len;
592
593 /* These are network statistics */
594 struct ieee80211_rx_stats stats;
595 u16 capability;
596 u8 rates[MAX_RATES_LENGTH];
597 u8 rates_len;
598 u8 rates_ex[MAX_RATES_EX_LENGTH];
599 u8 rates_ex_len;
600 unsigned long last_scanned;
601 u8 mode;
602 u8 flags;
603 u32 last_associate;
604 u32 time_stamp[2];
605 u16 beacon_interval;
606 u16 listen_interval;
607 u16 atim_window;
608 u8 wpa_ie[MAX_WPA_IE_LEN];
609 size_t wpa_ie_len;
610 u8 rsn_ie[MAX_WPA_IE_LEN];
611 size_t rsn_ie_len;
612 struct list_head list;
613};
614
615enum ieee80211_state {
616 IEEE80211_UNINITIALIZED = 0,
617 IEEE80211_INITIALIZED,
618 IEEE80211_ASSOCIATING,
619 IEEE80211_ASSOCIATED,
620 IEEE80211_AUTHENTICATING,
621 IEEE80211_AUTHENTICATED,
622 IEEE80211_SHUTDOWN
623};
624
625#define DEFAULT_MAX_SCAN_AGE (15 * HZ)
626#define DEFAULT_FTS 2346
627#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
628#define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
629
630
631#define CFG_IEEE80211_RESERVE_FCS (1<<0)
632#define CFG_IEEE80211_COMPUTE_FCS (1<<1)
633
634struct ieee80211_device {
635 struct net_device *dev;
636
637 /* Bookkeeping structures */
638 struct net_device_stats stats;
639 struct ieee80211_stats ieee_stats;
640
641 /* Probe / Beacon management */
642 struct list_head network_free_list;
643 struct list_head network_list;
644 struct ieee80211_network *networks;
645 int scans;
646 int scan_age;
647
648 int iw_mode; /* operating mode (IW_MODE_*) */
649
650 spinlock_t lock;
651
652 int tx_headroom; /* Set to size of any additional room needed at front
653 * of allocated Tx SKBs */
654 u32 config;
655
656 /* WEP and other encryption related settings at the device level */
657 int open_wep; /* Set to 1 to allow unencrypted frames */
658
659 int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
660 * WEP key changes */
661
662 /* If the host performs {en,de}cryption, then set to 1 */
663 int host_encrypt;
664 int host_decrypt;
665 int ieee802_1x; /* is IEEE 802.1X used */
666
667 /* WPA data */
668 int wpa_enabled;
669 int drop_unencrypted;
670 int tkip_countermeasures;
671 int privacy_invoked;
672 size_t wpa_ie_len;
673 u8 *wpa_ie;
674
675 struct list_head crypt_deinit_list;
676 struct ieee80211_crypt_data *crypt[WEP_KEYS];
677 int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
678 struct timer_list crypt_deinit_timer;
679
680 int bcrx_sta_key; /* use individual keys to override default keys even
681 * with RX of broad/multicast frames */
682
683 /* Fragmentation structures */
684 struct ieee80211_frag_entry frag_cache[IEEE80211_FRAG_CACHE_LEN];
685 unsigned int frag_next_idx;
686 u16 fts; /* Fragmentation Threshold */
687
688 /* Association info */
689 u8 bssid[ETH_ALEN];
690
691 enum ieee80211_state state;
692
693 int mode; /* A, B, G */
694 int modulation; /* CCK, OFDM */
695 int freq_band; /* 2.4Ghz, 5.2Ghz, Mixed */
696 int abg_ture; /* ABG flag */
697
698 /* Callback functions */
699 void (*set_security)(struct net_device *dev,
700 struct ieee80211_security *sec);
701 int (*hard_start_xmit)(struct ieee80211_txb *txb,
702 struct net_device *dev);
703 int (*reset_port)(struct net_device *dev);
704
705 /* This must be the last item so that it points to the data
706 * allocated beyond this structure by alloc_ieee80211 */
707 u8 priv[0];
708};
709
710#define IEEE_A (1<<0)
711#define IEEE_B (1<<1)
712#define IEEE_G (1<<2)
713#define IEEE_MODE_MASK (IEEE_A|IEEE_B|IEEE_G)
714
715extern inline void *ieee80211_priv(struct net_device *dev)
716{
717 return ((struct ieee80211_device *)netdev_priv(dev))->priv;
718}
719
720extern inline int ieee80211_is_empty_essid(const char *essid, int essid_len)
721{
722 /* Single white space is for Linksys APs */
723 if (essid_len == 1 && essid[0] == ' ')
724 return 1;
725
726 /* Otherwise, if the entire essid is 0, we assume it is hidden */
727 while (essid_len) {
728 essid_len--;
729 if (essid[essid_len] != '\0')
730 return 0;
731 }
732
733 return 1;
734}
735
736extern inline int ieee80211_is_valid_mode(struct ieee80211_device *ieee, int mode)
737{
738 /*
739 * It is possible for both access points and our device to support
740 * combinations of modes, so as long as there is one valid combination
741 * of ap/device supported modes, then return success
742 *
743 */
744 if ((mode & IEEE_A) &&
745 (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
746 (ieee->freq_band & IEEE80211_52GHZ_BAND))
747 return 1;
748
749 if ((mode & IEEE_G) &&
750 (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
751 (ieee->freq_band & IEEE80211_24GHZ_BAND))
752 return 1;
753
754 if ((mode & IEEE_B) &&
755 (ieee->modulation & IEEE80211_CCK_MODULATION) &&
756 (ieee->freq_band & IEEE80211_24GHZ_BAND))
757 return 1;
758
759 return 0;
760}
761
762extern inline int ieee80211_get_hdrlen(u16 fc)
763{
764 int hdrlen = IEEE80211_3ADDR_LEN;
765
766 switch (WLAN_FC_GET_TYPE(fc)) {
767 case IEEE80211_FTYPE_DATA:
768 if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
769 hdrlen = IEEE80211_4ADDR_LEN;
770 break;
771 case IEEE80211_FTYPE_CTL:
772 switch (WLAN_FC_GET_STYPE(fc)) {
773 case IEEE80211_STYPE_CTS:
774 case IEEE80211_STYPE_ACK:
775 hdrlen = IEEE80211_1ADDR_LEN;
776 break;
777 default:
778 hdrlen = IEEE80211_2ADDR_LEN;
779 break;
780 }
781 break;
782 }
783
784 return hdrlen;
785}
786
787
788
789/* ieee80211.c */
790extern void free_ieee80211(struct net_device *dev);
791extern struct net_device *alloc_ieee80211(int sizeof_priv);
792
793extern int ieee80211_set_encryption(struct ieee80211_device *ieee);
794
795/* ieee80211_tx.c */
796
797
798extern int ieee80211_xmit(struct sk_buff *skb,
799 struct net_device *dev);
800extern void ieee80211_txb_free(struct ieee80211_txb *);
801
802
803/* ieee80211_rx.c */
804extern int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
805 struct ieee80211_rx_stats *rx_stats);
806extern void ieee80211_rx_mgt(struct ieee80211_device *ieee,
807 struct ieee80211_hdr *header,
808 struct ieee80211_rx_stats *stats);
809
810/* iee80211_wx.c */
811extern int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
812 struct iw_request_info *info,
813 union iwreq_data *wrqu, char *key);
814extern int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
815 struct iw_request_info *info,
816 union iwreq_data *wrqu, char *key);
817extern int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
818 struct iw_request_info *info,
819 union iwreq_data *wrqu, char *key);
820
821
822extern inline void ieee80211_increment_scans(struct ieee80211_device *ieee)
823{
824 ieee->scans++;
825}
826
827extern inline int ieee80211_get_scans(struct ieee80211_device *ieee)
828{
829 return ieee->scans;
830}
831
832static inline const char *escape_essid(const char *essid, u8 essid_len) {
833 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
834 const char *s = essid;
835 char *d = escaped;
836
837 if (ieee80211_is_empty_essid(essid, essid_len)) {
838 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
839 return escaped;
840 }
841
842 essid_len = min(essid_len, (u8)IW_ESSID_MAX_SIZE);
843 while (essid_len--) {
844 if (*s == '\0') {
845 *d++ = '\\';
846 *d++ = '0';
847 s++;
848 } else {
849 *d++ = *s++;
850 }
851 }
852 *d = '\0';
853 return escaped;
854}
855
856#endif /* IEEE80211_H */
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index 771b47e30f86..69324465e8b3 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -183,7 +183,6 @@ struct ipv6_txoptions
183 struct ipv6_opt_hdr *hopopt; 183 struct ipv6_opt_hdr *hopopt;
184 struct ipv6_opt_hdr *dst0opt; 184 struct ipv6_opt_hdr *dst0opt;
185 struct ipv6_rt_hdr *srcrt; /* Routing Header */ 185 struct ipv6_rt_hdr *srcrt; /* Routing Header */
186 struct ipv6_opt_hdr *auth;
187 struct ipv6_opt_hdr *dst1opt; 186 struct ipv6_opt_hdr *dst1opt;
188 187
189 /* Option buffer, as read by IPV6_PKTOPTIONS, starts here. */ 188 /* Option buffer, as read by IPV6_PKTOPTIONS, starts here. */
diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index 4868c7f7749d..5999e5684bbf 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -263,23 +263,11 @@ enum { SCTP_MIN_PMTU = 576 };
263enum { SCTP_MAX_DUP_TSNS = 16 }; 263enum { SCTP_MAX_DUP_TSNS = 16 };
264enum { SCTP_MAX_GABS = 16 }; 264enum { SCTP_MAX_GABS = 16 };
265 265
266/* Here we define the default timers. */ 266/* Heartbeat interval - 30 secs */
267#define SCTP_DEFAULT_TIMEOUT_HEARTBEAT (30 * HZ)
267 268
268/* cookie timer def = ? seconds */ 269/* Delayed sack timer - 200ms */
269#define SCTP_DEFAULT_TIMEOUT_T1_COOKIE (3 * HZ)
270
271/* init timer def = 3 seconds */
272#define SCTP_DEFAULT_TIMEOUT_T1_INIT (3 * HZ)
273
274/* shutdown timer def = 300 ms */
275#define SCTP_DEFAULT_TIMEOUT_T2_SHUTDOWN ((300 * HZ) / 1000)
276
277/* 0 seconds + RTO */
278#define SCTP_DEFAULT_TIMEOUT_HEARTBEAT (10 * HZ)
279
280/* recv timer def = 200ms (in usec) */
281#define SCTP_DEFAULT_TIMEOUT_SACK ((200 * HZ) / 1000) 270#define SCTP_DEFAULT_TIMEOUT_SACK ((200 * HZ) / 1000)
282#define SCTP_DEFAULT_TIMEOUT_SACK_MAX ((500 * HZ) / 1000) /* 500 ms */
283 271
284/* RTO.Initial - 3 seconds 272/* RTO.Initial - 3 seconds
285 * RTO.Min - 1 second 273 * RTO.Min - 1 second
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index dfad4d3c581c..47727c7cc628 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -161,6 +161,9 @@ extern struct sctp_globals {
161 */ 161 */
162 int sndbuf_policy; 162 int sndbuf_policy;
163 163
164 /* Delayed SACK timeout 200ms default*/
165 int sack_timeout;
166
164 /* HB.interval - 30 seconds */ 167 /* HB.interval - 30 seconds */
165 int hb_interval; 168 int hb_interval;
166 169
@@ -217,6 +220,7 @@ extern struct sctp_globals {
217#define sctp_sndbuf_policy (sctp_globals.sndbuf_policy) 220#define sctp_sndbuf_policy (sctp_globals.sndbuf_policy)
218#define sctp_max_retrans_path (sctp_globals.max_retrans_path) 221#define sctp_max_retrans_path (sctp_globals.max_retrans_path)
219#define sctp_max_retrans_init (sctp_globals.max_retrans_init) 222#define sctp_max_retrans_init (sctp_globals.max_retrans_init)
223#define sctp_sack_timeout (sctp_globals.sack_timeout)
220#define sctp_hb_interval (sctp_globals.hb_interval) 224#define sctp_hb_interval (sctp_globals.hb_interval)
221#define sctp_max_instreams (sctp_globals.max_instreams) 225#define sctp_max_instreams (sctp_globals.max_instreams)
222#define sctp_max_outstreams (sctp_globals.max_outstreams) 226#define sctp_max_outstreams (sctp_globals.max_outstreams)
diff --git a/include/pcmcia/ciscode.h b/include/pcmcia/ciscode.h
index 2000b43ece91..da19c297dd65 100644
--- a/include/pcmcia/ciscode.h
+++ b/include/pcmcia/ciscode.h
@@ -112,6 +112,8 @@
112 112
113#define MANFID_TDK 0x0105 113#define MANFID_TDK 0x0105
114#define PRODID_TDK_CF010 0x0900 114#define PRODID_TDK_CF010 0x0900
115#define PRODID_TDK_NP9610 0x0d0a
116#define PRODID_TDK_MN3200 0x0e0a
115#define PRODID_TDK_GN3410 0x4815 117#define PRODID_TDK_GN3410 0x4815
116 118
117#define MANFID_TOSHIBA 0x0098 119#define MANFID_TOSHIBA 0x0098
diff --git a/include/pcmcia/cs.h b/include/pcmcia/cs.h
index 8d8643adc786..b42ddc0c1143 100644
--- a/include/pcmcia/cs.h
+++ b/include/pcmcia/cs.h
@@ -396,7 +396,6 @@ struct pcmcia_socket;
396int pcmcia_access_configuration_register(client_handle_t handle, conf_reg_t *reg); 396int pcmcia_access_configuration_register(client_handle_t handle, conf_reg_t *reg);
397int pcmcia_deregister_client(client_handle_t handle); 397int pcmcia_deregister_client(client_handle_t handle);
398int pcmcia_get_configuration_info(client_handle_t handle, config_info_t *config); 398int pcmcia_get_configuration_info(client_handle_t handle, config_info_t *config);
399int pcmcia_get_card_services_info(servinfo_t *info);
400int pcmcia_get_first_window(window_handle_t *win, win_req_t *req); 399int pcmcia_get_first_window(window_handle_t *win, win_req_t *req);
401int pcmcia_get_next_window(window_handle_t *win, win_req_t *req); 400int pcmcia_get_next_window(window_handle_t *win, win_req_t *req);
402int pcmcia_get_status(client_handle_t handle, cs_status_t *status); 401int pcmcia_get_status(client_handle_t handle, cs_status_t *status);
@@ -417,7 +416,6 @@ int pcmcia_suspend_card(struct pcmcia_socket *skt);
417int pcmcia_resume_card(struct pcmcia_socket *skt); 416int pcmcia_resume_card(struct pcmcia_socket *skt);
418int pcmcia_eject_card(struct pcmcia_socket *skt); 417int pcmcia_eject_card(struct pcmcia_socket *skt);
419int pcmcia_insert_card(struct pcmcia_socket *skt); 418int pcmcia_insert_card(struct pcmcia_socket *skt);
420int pcmcia_report_error(client_handle_t handle, error_info_t *err);
421 419
422struct pcmcia_socket * pcmcia_get_socket(struct pcmcia_socket *skt); 420struct pcmcia_socket * pcmcia_get_socket(struct pcmcia_socket *skt);
423void pcmcia_put_socket(struct pcmcia_socket *skt); 421void pcmcia_put_socket(struct pcmcia_socket *skt);
diff --git a/include/pcmcia/device_id.h b/include/pcmcia/device_id.h
new file mode 100644
index 000000000000..346d81ece287
--- /dev/null
+++ b/include/pcmcia/device_id.h
@@ -0,0 +1,249 @@
1/*
2 * Copyright (2003-2004) Dominik Brodowski <linux@brodo.de>
3 * David Woodhouse
4 *
5 * License: GPL v2
6 */
7
8#define PCMCIA_DEVICE_MANF_CARD(manf, card) { \
9 .match_flags = PCMCIA_DEV_ID_MATCH_MANF_ID| \
10 PCMCIA_DEV_ID_MATCH_CARD_ID, \
11 .manf_id = (manf), \
12 .card_id = (card), }
13
14#define PCMCIA_DEVICE_FUNC_ID(func) { \
15 .match_flags = PCMCIA_DEV_ID_MATCH_FUNC_ID, \
16 .func_id = (func), }
17
18#define PCMCIA_DEVICE_PROD_ID1(v1, vh1) { \
19 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1, \
20 .prod_id = { (v1), NULL, NULL, NULL }, \
21 .prod_id_hash = { (vh1), 0, 0, 0 }, }
22
23#define PCMCIA_DEVICE_PROD_ID2(v2, vh2) { \
24 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID2, \
25 .prod_id = { NULL, (v2), NULL, NULL }, \
26 .prod_id_hash = { 0, (vh2), 0, 0 }, }
27
28#define PCMCIA_DEVICE_PROD_ID12(v1, v2, vh1, vh2) { \
29 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
30 PCMCIA_DEV_ID_MATCH_PROD_ID2, \
31 .prod_id = { (v1), (v2), NULL, NULL }, \
32 .prod_id_hash = { (vh1), (vh2), 0, 0 }, }
33
34#define PCMCIA_DEVICE_PROD_ID13(v1, v3, vh1, vh3) { \
35 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
36 PCMCIA_DEV_ID_MATCH_PROD_ID3, \
37 .prod_id = { (v1), NULL, (v3), NULL }, \
38 .prod_id_hash = { (vh1), 0, (vh3), 0 }, }
39
40#define PCMCIA_DEVICE_PROD_ID14(v1, v4, vh1, vh4) { \
41 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
42 PCMCIA_DEV_ID_MATCH_PROD_ID4, \
43 .prod_id = { (v1), NULL, NULL, (v4) }, \
44 .prod_id_hash = { (vh1), 0, 0, (vh4) }, }
45
46#define PCMCIA_DEVICE_PROD_ID123(v1, v2, v3, vh1, vh2, vh3) { \
47 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
48 PCMCIA_DEV_ID_MATCH_PROD_ID2| \
49 PCMCIA_DEV_ID_MATCH_PROD_ID3, \
50 .prod_id = { (v1), (v2), (v3), NULL },\
51 .prod_id_hash = { (vh1), (vh2), (vh3), 0 }, }
52
53#define PCMCIA_DEVICE_PROD_ID124(v1, v2, v4, vh1, vh2, vh4) { \
54 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
55 PCMCIA_DEV_ID_MATCH_PROD_ID2| \
56 PCMCIA_DEV_ID_MATCH_PROD_ID4, \
57 .prod_id = { (v1), (v2), NULL, (v4) }, \
58 .prod_id_hash = { (vh1), (vh2), 0, (vh4) }, }
59
60#define PCMCIA_DEVICE_PROD_ID134(v1, v3, v4, vh1, vh3, vh4) { \
61 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
62 PCMCIA_DEV_ID_MATCH_PROD_ID3| \
63 PCMCIA_DEV_ID_MATCH_PROD_ID4, \
64 .prod_id = { (v1), NULL, (v3), (v4) }, \
65 .prod_id_hash = { (vh1), 0, (vh3), (vh4) }, }
66
67#define PCMCIA_DEVICE_PROD_ID1234(v1, v2, v3, v4, vh1, vh2, vh3, vh4) { \
68 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
69 PCMCIA_DEV_ID_MATCH_PROD_ID2| \
70 PCMCIA_DEV_ID_MATCH_PROD_ID3| \
71 PCMCIA_DEV_ID_MATCH_PROD_ID4, \
72 .prod_id = { (v1), (v2), (v3), (v4) }, \
73 .prod_id_hash = { (vh1), (vh2), (vh3), (vh4) }, }
74
75
76/* multi-function devices */
77
78#define PCMCIA_MFC_DEVICE_MANF_CARD(mfc, manf, card) { \
79 .match_flags = PCMCIA_DEV_ID_MATCH_MANF_ID| \
80 PCMCIA_DEV_ID_MATCH_CARD_ID| \
81 PCMCIA_DEV_ID_MATCH_FUNCTION, \
82 .manf_id = (manf), \
83 .card_id = (card), \
84 .function = (mfc), }
85
86#define PCMCIA_MFC_DEVICE_PROD_ID1(mfc, v1, vh1) { \
87 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
88 PCMCIA_DEV_ID_MATCH_FUNCTION, \
89 .prod_id = { (v1), NULL, NULL, NULL }, \
90 .prod_id_hash = { (vh1), 0, 0, 0 }, \
91 .function = (mfc), }
92
93#define PCMCIA_MFC_DEVICE_PROD_ID2(mfc, v2, vh2) { \
94 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID2| \
95 PCMCIA_DEV_ID_MATCH_FUNCTION, \
96 .prod_id = { NULL, (v2), NULL, NULL }, \
97 .prod_id_hash = { 0, (vh2), 0, 0 }, \
98 .function = (mfc), }
99
100#define PCMCIA_MFC_DEVICE_PROD_ID12(mfc, v1, v2, vh1, vh2) { \
101 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
102 PCMCIA_DEV_ID_MATCH_PROD_ID2| \
103 PCMCIA_DEV_ID_MATCH_FUNCTION, \
104 .prod_id = { (v1), (v2), NULL, NULL }, \
105 .prod_id_hash = { (vh1), (vh2), 0, 0 }, \
106 .function = (mfc), }
107
108#define PCMCIA_MFC_DEVICE_PROD_ID13(mfc, v1, v3, vh1, vh3) { \
109 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
110 PCMCIA_DEV_ID_MATCH_PROD_ID3| \
111 PCMCIA_DEV_ID_MATCH_FUNCTION, \
112 .prod_id = { (v1), NULL, (v3), NULL }, \
113 .prod_id_hash = { (vh1), 0, (vh3), 0 }, \
114 .function = (mfc), }
115
116#define PCMCIA_MFC_DEVICE_PROD_ID123(mfc, v1, v2, v3, vh1, vh2, vh3) { \
117 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
118 PCMCIA_DEV_ID_MATCH_PROD_ID2| \
119 PCMCIA_DEV_ID_MATCH_PROD_ID3| \
120 PCMCIA_DEV_ID_MATCH_FUNCTION, \
121 .prod_id = { (v1), (v2), (v3), NULL },\
122 .prod_id_hash = { (vh1), (vh2), (vh3), 0 }, \
123 .function = (mfc), }
124
125/* pseudo multi-function devices */
126
127#define PCMCIA_PFC_DEVICE_MANF_CARD(mfc, manf, card) { \
128 .match_flags = PCMCIA_DEV_ID_MATCH_MANF_ID| \
129 PCMCIA_DEV_ID_MATCH_CARD_ID| \
130 PCMCIA_DEV_ID_MATCH_DEVICE_NO, \
131 .manf_id = (manf), \
132 .card_id = (card), \
133 .device_no = (mfc), }
134
135#define PCMCIA_PFC_DEVICE_PROD_ID1(mfc, v1, vh1) { \
136 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
137 PCMCIA_DEV_ID_MATCH_DEVICE_NO, \
138 .prod_id = { (v1), NULL, NULL, NULL }, \
139 .prod_id_hash = { (vh1), 0, 0, 0 }, \
140 .device_no = (mfc), }
141
142#define PCMCIA_PFC_DEVICE_PROD_ID2(mfc, v2, vh2) { \
143 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID2| \
144 PCMCIA_DEV_ID_MATCH_DEVICE_NO, \
145 .prod_id = { NULL, (v2), NULL, NULL }, \
146 .prod_id_hash = { 0, (vh2), 0, 0 }, \
147 .device_no = (mfc), }
148
149#define PCMCIA_PFC_DEVICE_PROD_ID12(mfc, v1, v2, vh1, vh2) { \
150 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
151 PCMCIA_DEV_ID_MATCH_PROD_ID2| \
152 PCMCIA_DEV_ID_MATCH_DEVICE_NO, \
153 .prod_id = { (v1), (v2), NULL, NULL }, \
154 .prod_id_hash = { (vh1), (vh2), 0, 0 }, \
155 .device_no = (mfc), }
156
157#define PCMCIA_PFC_DEVICE_PROD_ID13(mfc, v1, v3, vh1, vh3) { \
158 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
159 PCMCIA_DEV_ID_MATCH_PROD_ID3| \
160 PCMCIA_DEV_ID_MATCH_DEVICE_NO, \
161 .prod_id = { (v1), NULL, (v3), NULL }, \
162 .prod_id_hash = { (vh1), 0, (vh3), 0 }, \
163 .device_no = (mfc), }
164
165#define PCMCIA_PFC_DEVICE_PROD_ID123(mfc, v1, v2, v3, vh1, vh2, vh3) { \
166 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
167 PCMCIA_DEV_ID_MATCH_PROD_ID2| \
168 PCMCIA_DEV_ID_MATCH_PROD_ID3| \
169 PCMCIA_DEV_ID_MATCH_DEVICE_NO, \
170 .prod_id = { (v1), (v2), (v3), NULL },\
171 .prod_id_hash = { (vh1), (vh2), (vh3), 0 }, \
172 .device_no = (mfc), }
173
174/* cards needing a CIS override */
175
176#define PCMCIA_DEVICE_CIS_MANF_CARD(manf, card, _cisfile) { \
177 .match_flags = PCMCIA_DEV_ID_MATCH_FAKE_CIS | \
178 PCMCIA_DEV_ID_MATCH_MANF_ID| \
179 PCMCIA_DEV_ID_MATCH_CARD_ID, \
180 .manf_id = (manf), \
181 .card_id = (card), \
182 .cisfile = (_cisfile)}
183
184#define PCMCIA_DEVICE_CIS_PROD_ID12(v1, v2, vh1, vh2, _cisfile) { \
185 .match_flags = PCMCIA_DEV_ID_MATCH_FAKE_CIS | \
186 PCMCIA_DEV_ID_MATCH_PROD_ID1| \
187 PCMCIA_DEV_ID_MATCH_PROD_ID2, \
188 .prod_id = { (v1), (v2), NULL, NULL }, \
189 .prod_id_hash = { (vh1), (vh2), 0, 0 }, \
190 .cisfile = (_cisfile)}
191
192#define PCMCIA_DEVICE_CIS_PROD_ID123(v1, v2, v3, vh1, vh2, vh3, _cisfile) { \
193 .match_flags = PCMCIA_DEV_ID_MATCH_FAKE_CIS | \
194 PCMCIA_DEV_ID_MATCH_PROD_ID1| \
195 PCMCIA_DEV_ID_MATCH_PROD_ID2| \
196 PCMCIA_DEV_ID_MATCH_PROD_ID3, \
197 .prod_id = { (v1), (v2), (v3), NULL },\
198 .prod_id_hash = { (vh1), (vh2), (vh3), 0 }, \
199 .cisfile = (_cisfile)}
200
201
202#define PCMCIA_DEVICE_CIS_PROD_ID2(v2, vh2, _cisfile) { \
203 .match_flags = PCMCIA_DEV_ID_MATCH_FAKE_CIS | \
204 PCMCIA_DEV_ID_MATCH_PROD_ID2, \
205 .prod_id = { NULL, (v2), NULL, NULL }, \
206 .prod_id_hash = { 0, (vh2), 0, 0 }, \
207 .cisfile = (_cisfile)}
208
209#define PCMCIA_PFC_DEVICE_CIS_PROD_ID12(mfc, v1, v2, vh1, vh2, _cisfile) { \
210 .match_flags = PCMCIA_DEV_ID_MATCH_FAKE_CIS | \
211 PCMCIA_DEV_ID_MATCH_PROD_ID1| \
212 PCMCIA_DEV_ID_MATCH_PROD_ID2| \
213 PCMCIA_DEV_ID_MATCH_DEVICE_NO, \
214 .prod_id = { (v1), (v2), NULL, NULL }, \
215 .prod_id_hash = { (vh1), (vh2), 0, 0 },\
216 .device_no = (mfc), \
217 .cisfile = (_cisfile)}
218
219#define PCMCIA_MFC_DEVICE_CIS_MANF_CARD(mfc, manf, card, _cisfile) { \
220 .match_flags = PCMCIA_DEV_ID_MATCH_FAKE_CIS | \
221 PCMCIA_DEV_ID_MATCH_MANF_ID| \
222 PCMCIA_DEV_ID_MATCH_CARD_ID| \
223 PCMCIA_DEV_ID_MATCH_FUNCTION, \
224 .manf_id = (manf), \
225 .card_id = (card), \
226 .function = (mfc), \
227 .cisfile = (_cisfile)}
228
229#define PCMCIA_MFC_DEVICE_CIS_PROD_ID12(mfc, v1, v2, vh1, vh2, _cisfile) { \
230 .match_flags = PCMCIA_DEV_ID_MATCH_FAKE_CIS | \
231 PCMCIA_DEV_ID_MATCH_PROD_ID1| \
232 PCMCIA_DEV_ID_MATCH_PROD_ID2| \
233 PCMCIA_DEV_ID_MATCH_FUNCTION, \
234 .prod_id = { (v1), (v2), NULL, NULL }, \
235 .prod_id_hash = { (vh1), (vh2), 0, 0 }, \
236 .function = (mfc), \
237 .cisfile = (_cisfile)}
238
239#define PCMCIA_MFC_DEVICE_CIS_PROD_ID4(mfc, v4, vh4, _cisfile) { \
240 .match_flags = PCMCIA_DEV_ID_MATCH_FAKE_CIS | \
241 PCMCIA_DEV_ID_MATCH_PROD_ID4| \
242 PCMCIA_DEV_ID_MATCH_FUNCTION, \
243 .prod_id = { NULL, NULL, NULL, (v4) }, \
244 .prod_id_hash = { 0, 0, 0, (vh4) }, \
245 .function = (mfc), \
246 .cisfile = (_cisfile)}
247
248
249#define PCMCIA_DEVICE_NULL { .match_flags = 0, }
diff --git a/include/pcmcia/ds.h b/include/pcmcia/ds.h
index 312fd958c901..2b52553f2d94 100644
--- a/include/pcmcia/ds.h
+++ b/include/pcmcia/ds.h
@@ -18,6 +18,8 @@
18 18
19#include <pcmcia/bulkmem.h> 19#include <pcmcia/bulkmem.h>
20#include <pcmcia/cs_types.h> 20#include <pcmcia/cs_types.h>
21#include <pcmcia/device_id.h>
22#include <linux/mod_devicetable.h>
21 23
22typedef struct tuple_parse_t { 24typedef struct tuple_parse_t {
23 tuple_t tuple; 25 tuple_t tuple;
@@ -129,12 +131,11 @@ typedef struct dev_link_t {
129 131
130struct pcmcia_socket; 132struct pcmcia_socket;
131 133
132extern struct bus_type pcmcia_bus_type;
133
134struct pcmcia_driver { 134struct pcmcia_driver {
135 dev_link_t *(*attach)(void); 135 dev_link_t *(*attach)(void);
136 void (*detach)(dev_link_t *); 136 void (*detach)(dev_link_t *);
137 struct module *owner; 137 struct module *owner;
138 struct pcmcia_device_id *id_table;
138 struct device_driver drv; 139 struct device_driver drv;
139}; 140};
140 141
@@ -173,7 +174,9 @@ struct pcmcia_device {
173 u8 has_manf_id:1; 174 u8 has_manf_id:1;
174 u8 has_card_id:1; 175 u8 has_card_id:1;
175 u8 has_func_id:1; 176 u8 has_func_id:1;
176 u8 reserved:5; 177
178 u8 allow_func_id_match:1;
179 u8 reserved:4;
177 180
178 u8 func_id; 181 u8 func_id;
179 u16 manf_id; 182 u16 manf_id;
diff --git a/include/pcmcia/ss.h b/include/pcmcia/ss.h
index 67b867f31fe4..0f7aacc33fe9 100644
--- a/include/pcmcia/ss.h
+++ b/include/pcmcia/ss.h
@@ -15,10 +15,12 @@
15#ifndef _LINUX_SS_H 15#ifndef _LINUX_SS_H
16#define _LINUX_SS_H 16#define _LINUX_SS_H
17 17
18#include <linux/config.h>
19#include <linux/device.h>
20
18#include <pcmcia/cs_types.h> 21#include <pcmcia/cs_types.h>
19#include <pcmcia/cs.h> 22#include <pcmcia/cs.h>
20#include <pcmcia/bulkmem.h> 23#include <pcmcia/bulkmem.h>
21#include <linux/device.h>
22 24
23/* Definitions for card status flags for GetStatus */ 25/* Definitions for card status flags for GetStatus */
24#define SS_WRPROT 0x0001 26#define SS_WRPROT 0x0001
@@ -171,7 +173,7 @@ typedef struct window_t {
171 173
172struct config_t; 174struct config_t;
173struct pcmcia_callback; 175struct pcmcia_callback;
174 176struct user_info_t;
175 177
176struct pcmcia_socket { 178struct pcmcia_socket {
177 struct module *owner; 179 struct module *owner;
@@ -216,8 +218,9 @@ struct pcmcia_socket {
216 218
217 /* is set to one if resource setup is done using adjust_resource_info() */ 219 /* is set to one if resource setup is done using adjust_resource_info() */
218 u8 resource_setup_old:1; 220 u8 resource_setup_old:1;
221 u8 resource_setup_new:1;
219 222
220 u8 reserved:6; 223 u8 reserved:5;
221 224
222 /* socket operations */ 225 /* socket operations */
223 struct pccard_operations * ops; 226 struct pccard_operations * ops;
@@ -241,9 +244,32 @@ struct pcmcia_socket {
241 unsigned int thread_events; 244 unsigned int thread_events;
242 245
243 /* pcmcia (16-bit) */ 246 /* pcmcia (16-bit) */
244 struct pcmcia_bus_socket *pcmcia;
245 struct pcmcia_callback *callback; 247 struct pcmcia_callback *callback;
246 248
249#if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
250 struct list_head devices_list; /* PCMCIA devices */
251 u8 device_count; /* the number of devices, used
252 * only internally and subject
253 * to incorrectness and change */
254
255 struct {
256 u8 present:1, /* PCMCIA card is present in socket */
257 busy:1, /* "master" ioctl is used */
258 dead:1, /* pcmcia module is being unloaded */
259 device_add_pending:1, /* a pseudo-multifunction-device
260 * add event is pending */
261 reserved:4;
262 } pcmcia_state;
263
264 struct work_struct device_add; /* for adding further pseudo-multifunction
265 * devices */
266
267#ifdef CONFIG_PCMCIA_IOCTL
268 struct user_info_t *user;
269 wait_queue_head_t queue;
270#endif
271#endif
272
247 /* cardbus (32-bit) */ 273 /* cardbus (32-bit) */
248#ifdef CONFIG_CARDBUS 274#ifdef CONFIG_CARDBUS
249 struct resource * cb_cis_res; 275 struct resource * cb_cis_res;
diff --git a/init/main.c b/init/main.c
index d324801729ba..b5e421e39ede 100644
--- a/init/main.c
+++ b/init/main.c
@@ -383,6 +383,13 @@ static void noinline rest_init(void)
383 numa_default_policy(); 383 numa_default_policy();
384 unlock_kernel(); 384 unlock_kernel();
385 preempt_enable_no_resched(); 385 preempt_enable_no_resched();
386
387 /*
388 * The boot idle thread must execute schedule()
389 * at least one to get things moving:
390 */
391 schedule();
392
386 cpu_idle(); 393 cpu_idle();
387} 394}
388 395
diff --git a/kernel/exit.c b/kernel/exit.c
index 3ebcd60a19c6..9d1b10ed0135 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -784,6 +784,8 @@ fastcall NORET_TYPE void do_exit(long code)
784 784
785 profile_task_exit(tsk); 785 profile_task_exit(tsk);
786 786
787 WARN_ON(atomic_read(&tsk->fs_excl));
788
787 if (unlikely(in_interrupt())) 789 if (unlikely(in_interrupt()))
788 panic("Aiee, killing interrupt handler!"); 790 panic("Aiee, killing interrupt handler!");
789 if (unlikely(!tsk->pid)) 791 if (unlikely(!tsk->pid))
diff --git a/kernel/fork.c b/kernel/fork.c
index 2c7806873bfd..cdef6cea8900 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1090,6 +1090,11 @@ static task_t *copy_process(unsigned long clone_flags,
1090 spin_unlock(&current->sighand->siglock); 1090 spin_unlock(&current->sighand->siglock);
1091 } 1091 }
1092 1092
1093 /*
1094 * inherit ioprio
1095 */
1096 p->ioprio = current->ioprio;
1097
1093 SET_LINKS(p); 1098 SET_LINKS(p);
1094 if (unlikely(p->ptrace & PT_PTRACED)) 1099 if (unlikely(p->ptrace & PT_PTRACED))
1095 __ptrace_link(p, current->parent); 1100 __ptrace_link(p, current->parent);
diff --git a/kernel/irq/autoprobe.c b/kernel/irq/autoprobe.c
index 98d62d8efeaf..3467097ca61a 100644
--- a/kernel/irq/autoprobe.c
+++ b/kernel/irq/autoprobe.c
@@ -9,6 +9,7 @@
9#include <linux/irq.h> 9#include <linux/irq.h>
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/interrupt.h> 11#include <linux/interrupt.h>
12#include <linux/delay.h>
12 13
13/* 14/*
14 * Autodetection depends on the fact that any interrupt that 15 * Autodetection depends on the fact that any interrupt that
@@ -26,7 +27,7 @@ static DECLARE_MUTEX(probe_sem);
26 */ 27 */
27unsigned long probe_irq_on(void) 28unsigned long probe_irq_on(void)
28{ 29{
29 unsigned long val, delay; 30 unsigned long val;
30 irq_desc_t *desc; 31 irq_desc_t *desc;
31 unsigned int i; 32 unsigned int i;
32 33
@@ -45,8 +46,7 @@ unsigned long probe_irq_on(void)
45 } 46 }
46 47
47 /* Wait for longstanding interrupts to trigger. */ 48 /* Wait for longstanding interrupts to trigger. */
48 for (delay = jiffies + HZ/50; time_after(delay, jiffies); ) 49 msleep(20);
49 /* about 20ms delay */ barrier();
50 50
51 /* 51 /*
52 * enable any unassigned irqs 52 * enable any unassigned irqs
@@ -68,8 +68,7 @@ unsigned long probe_irq_on(void)
68 /* 68 /*
69 * Wait for spurious interrupts to trigger 69 * Wait for spurious interrupts to trigger
70 */ 70 */
71 for (delay = jiffies + HZ/10; time_after(delay, jiffies); ) 71 msleep(100);
72 /* about 100ms delay */ barrier();
73 72
74 /* 73 /*
75 * Now filter out any obviously spurious interrupts 74 * Now filter out any obviously spurious interrupts
diff --git a/kernel/irq/handle.c b/kernel/irq/handle.c
index 436c7d93c00a..c29f83c16497 100644
--- a/kernel/irq/handle.c
+++ b/kernel/irq/handle.c
@@ -172,7 +172,7 @@ fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
172 172
173 spin_lock(&desc->lock); 173 spin_lock(&desc->lock);
174 if (!noirqdebug) 174 if (!noirqdebug)
175 note_interrupt(irq, desc, action_ret); 175 note_interrupt(irq, desc, action_ret, regs);
176 if (likely(!(desc->status & IRQ_PENDING))) 176 if (likely(!(desc->status & IRQ_PENDING)))
177 break; 177 break;
178 desc->status &= ~IRQ_PENDING; 178 desc->status &= ~IRQ_PENDING;
diff --git a/kernel/irq/spurious.c b/kernel/irq/spurious.c
index ba039e827d58..7df9abd5ec86 100644
--- a/kernel/irq/spurious.c
+++ b/kernel/irq/spurious.c
@@ -11,6 +11,83 @@
11#include <linux/kallsyms.h> 11#include <linux/kallsyms.h>
12#include <linux/interrupt.h> 12#include <linux/interrupt.h>
13 13
14static int irqfixup;
15
16/*
17 * Recovery handler for misrouted interrupts.
18 */
19
20static int misrouted_irq(int irq, struct pt_regs *regs)
21{
22 int i;
23 irq_desc_t *desc;
24 int ok = 0;
25 int work = 0; /* Did we do work for a real IRQ */
26
27 for(i = 1; i < NR_IRQS; i++) {
28 struct irqaction *action;
29
30 if (i == irq) /* Already tried */
31 continue;
32 desc = &irq_desc[i];
33 spin_lock(&desc->lock);
34 action = desc->action;
35 /* Already running on another processor */
36 if (desc->status & IRQ_INPROGRESS) {
37 /*
38 * Already running: If it is shared get the other
39 * CPU to go looking for our mystery interrupt too
40 */
41 if (desc->action && (desc->action->flags & SA_SHIRQ))
42 desc->status |= IRQ_PENDING;
43 spin_unlock(&desc->lock);
44 continue;
45 }
46 /* Honour the normal IRQ locking */
47 desc->status |= IRQ_INPROGRESS;
48 spin_unlock(&desc->lock);
49 while (action) {
50 /* Only shared IRQ handlers are safe to call */
51 if (action->flags & SA_SHIRQ) {
52 if (action->handler(i, action->dev_id, regs) ==
53 IRQ_HANDLED)
54 ok = 1;
55 }
56 action = action->next;
57 }
58 local_irq_disable();
59 /* Now clean up the flags */
60 spin_lock(&desc->lock);
61 action = desc->action;
62
63 /*
64 * While we were looking for a fixup someone queued a real
65 * IRQ clashing with our walk
66 */
67
68 while ((desc->status & IRQ_PENDING) && action) {
69 /*
70 * Perform real IRQ processing for the IRQ we deferred
71 */
72 work = 1;
73 spin_unlock(&desc->lock);
74 handle_IRQ_event(i, regs, action);
75 spin_lock(&desc->lock);
76 desc->status &= ~IRQ_PENDING;
77 }
78 desc->status &= ~IRQ_INPROGRESS;
79 /*
80 * If we did actual work for the real IRQ line we must let the
81 * IRQ controller clean up too
82 */
83 if(work)
84 desc->handler->end(i);
85 spin_unlock(&desc->lock);
86 }
87 /* So the caller can adjust the irq error counts */
88 return ok;
89}
90
14/* 91/*
15 * If 99,900 of the previous 100,000 interrupts have not been handled 92 * If 99,900 of the previous 100,000 interrupts have not been handled
16 * then assume that the IRQ is stuck in some manner. Drop a diagnostic 93 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
@@ -31,7 +108,8 @@ __report_bad_irq(unsigned int irq, irq_desc_t *desc, irqreturn_t action_ret)
31 printk(KERN_ERR "irq event %d: bogus return value %x\n", 108 printk(KERN_ERR "irq event %d: bogus return value %x\n",
32 irq, action_ret); 109 irq, action_ret);
33 } else { 110 } else {
34 printk(KERN_ERR "irq %d: nobody cared!\n", irq); 111 printk(KERN_ERR "irq %d: nobody cared (try booting with "
112 "the \"irqpoll\" option)\n", irq);
35 } 113 }
36 dump_stack(); 114 dump_stack();
37 printk(KERN_ERR "handlers:\n"); 115 printk(KERN_ERR "handlers:\n");
@@ -55,7 +133,8 @@ static void report_bad_irq(unsigned int irq, irq_desc_t *desc, irqreturn_t actio
55 } 133 }
56} 134}
57 135
58void note_interrupt(unsigned int irq, irq_desc_t *desc, irqreturn_t action_ret) 136void note_interrupt(unsigned int irq, irq_desc_t *desc, irqreturn_t action_ret,
137 struct pt_regs *regs)
59{ 138{
60 if (action_ret != IRQ_HANDLED) { 139 if (action_ret != IRQ_HANDLED) {
61 desc->irqs_unhandled++; 140 desc->irqs_unhandled++;
@@ -63,6 +142,15 @@ void note_interrupt(unsigned int irq, irq_desc_t *desc, irqreturn_t action_ret)
63 report_bad_irq(irq, desc, action_ret); 142 report_bad_irq(irq, desc, action_ret);
64 } 143 }
65 144
145 if (unlikely(irqfixup)) {
146 /* Don't punish working computers */
147 if ((irqfixup == 2 && irq == 0) || action_ret == IRQ_NONE) {
148 int ok = misrouted_irq(irq, regs);
149 if (action_ret == IRQ_NONE)
150 desc->irqs_unhandled -= ok;
151 }
152 }
153
66 desc->irq_count++; 154 desc->irq_count++;
67 if (desc->irq_count < 100000) 155 if (desc->irq_count < 100000)
68 return; 156 return;
@@ -94,3 +182,24 @@ int __init noirqdebug_setup(char *str)
94 182
95__setup("noirqdebug", noirqdebug_setup); 183__setup("noirqdebug", noirqdebug_setup);
96 184
185static int __init irqfixup_setup(char *str)
186{
187 irqfixup = 1;
188 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
189 printk(KERN_WARNING "This may impact system performance.\n");
190 return 1;
191}
192
193__setup("irqfixup", irqfixup_setup);
194
195static int __init irqpoll_setup(char *str)
196{
197 irqfixup = 2;
198 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
199 "enabled\n");
200 printk(KERN_WARNING "This may significantly impact system "
201 "performance\n");
202 return 1;
203}
204
205__setup("irqpoll", irqpoll_setup);
diff --git a/kernel/itimer.c b/kernel/itimer.c
index 1dc988e0d2c7..a72cb0e5aa4b 100644
--- a/kernel/itimer.c
+++ b/kernel/itimer.c
@@ -153,11 +153,15 @@ int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
153 153
154 switch (which) { 154 switch (which) {
155 case ITIMER_REAL: 155 case ITIMER_REAL:
156again:
156 spin_lock_irq(&tsk->sighand->siglock); 157 spin_lock_irq(&tsk->sighand->siglock);
157 interval = tsk->signal->it_real_incr; 158 interval = tsk->signal->it_real_incr;
158 val = it_real_value(tsk->signal); 159 val = it_real_value(tsk->signal);
159 if (val) 160 /* We are sharing ->siglock with it_real_fn() */
160 del_timer_sync(&tsk->signal->real_timer); 161 if (try_to_del_timer_sync(&tsk->signal->real_timer) < 0) {
162 spin_unlock_irq(&tsk->sighand->siglock);
163 goto again;
164 }
161 tsk->signal->it_real_incr = 165 tsk->signal->it_real_incr =
162 timeval_to_jiffies(&value->it_interval); 166 timeval_to_jiffies(&value->it_interval);
163 it_real_arm(tsk, timeval_to_jiffies(&value->it_value)); 167 it_real_arm(tsk, timeval_to_jiffies(&value->it_value));
diff --git a/kernel/kexec.c b/kernel/kexec.c
index 7843548cf2d9..cdd4dcd8fb63 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -241,7 +241,7 @@ static int kimage_normal_alloc(struct kimage **rimage, unsigned long entry,
241 241
242static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry, 242static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry,
243 unsigned long nr_segments, 243 unsigned long nr_segments,
244 struct kexec_segment *segments) 244 struct kexec_segment __user *segments)
245{ 245{
246 int result; 246 int result;
247 struct kimage *image; 247 struct kimage *image;
@@ -650,7 +650,7 @@ static kimage_entry_t *kimage_dst_used(struct kimage *image,
650 } 650 }
651 } 651 }
652 652
653 return 0; 653 return NULL;
654} 654}
655 655
656static struct page *kimage_alloc_page(struct kimage *image, 656static struct page *kimage_alloc_page(struct kimage *image,
@@ -696,7 +696,7 @@ static struct page *kimage_alloc_page(struct kimage *image,
696 /* Allocate a page, if we run out of memory give up */ 696 /* Allocate a page, if we run out of memory give up */
697 page = kimage_alloc_pages(gfp_mask, 0); 697 page = kimage_alloc_pages(gfp_mask, 0);
698 if (!page) 698 if (!page)
699 return 0; 699 return NULL;
700 /* If the page cannot be used file it away */ 700 /* If the page cannot be used file it away */
701 if (page_to_pfn(page) > 701 if (page_to_pfn(page) >
702 (KEXEC_SOURCE_MEMORY_LIMIT >> PAGE_SHIFT)) { 702 (KEXEC_SOURCE_MEMORY_LIMIT >> PAGE_SHIFT)) {
@@ -754,7 +754,7 @@ static int kimage_load_normal_segment(struct kimage *image,
754 unsigned long maddr; 754 unsigned long maddr;
755 unsigned long ubytes, mbytes; 755 unsigned long ubytes, mbytes;
756 int result; 756 int result;
757 unsigned char *buf; 757 unsigned char __user *buf;
758 758
759 result = 0; 759 result = 0;
760 buf = segment->buf; 760 buf = segment->buf;
@@ -818,7 +818,7 @@ static int kimage_load_crash_segment(struct kimage *image,
818 unsigned long maddr; 818 unsigned long maddr;
819 unsigned long ubytes, mbytes; 819 unsigned long ubytes, mbytes;
820 int result; 820 int result;
821 unsigned char *buf; 821 unsigned char __user *buf;
822 822
823 result = 0; 823 result = 0;
824 buf = segment->buf; 824 buf = segment->buf;
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 334f37472c56..90c0e82b650c 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -36,6 +36,7 @@
36#include <linux/hash.h> 36#include <linux/hash.h>
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/moduleloader.h>
39#include <asm/cacheflush.h> 40#include <asm/cacheflush.h>
40#include <asm/errno.h> 41#include <asm/errno.h>
41#include <asm/kdebug.h> 42#include <asm/kdebug.h>
@@ -50,6 +51,106 @@ unsigned int kprobe_cpu = NR_CPUS;
50static DEFINE_SPINLOCK(kprobe_lock); 51static DEFINE_SPINLOCK(kprobe_lock);
51static struct kprobe *curr_kprobe; 52static struct kprobe *curr_kprobe;
52 53
54/*
55 * kprobe->ainsn.insn points to the copy of the instruction to be
56 * single-stepped. x86_64, POWER4 and above have no-exec support and
57 * stepping on the instruction on a vmalloced/kmalloced/data page
58 * is a recipe for disaster
59 */
60#define INSNS_PER_PAGE (PAGE_SIZE/(MAX_INSN_SIZE * sizeof(kprobe_opcode_t)))
61
62struct kprobe_insn_page {
63 struct hlist_node hlist;
64 kprobe_opcode_t *insns; /* Page of instruction slots */
65 char slot_used[INSNS_PER_PAGE];
66 int nused;
67};
68
69static struct hlist_head kprobe_insn_pages;
70
71/**
72 * get_insn_slot() - Find a slot on an executable page for an instruction.
73 * We allocate an executable page if there's no room on existing ones.
74 */
75kprobe_opcode_t *get_insn_slot(void)
76{
77 struct kprobe_insn_page *kip;
78 struct hlist_node *pos;
79
80 hlist_for_each(pos, &kprobe_insn_pages) {
81 kip = hlist_entry(pos, struct kprobe_insn_page, hlist);
82 if (kip->nused < INSNS_PER_PAGE) {
83 int i;
84 for (i = 0; i < INSNS_PER_PAGE; i++) {
85 if (!kip->slot_used[i]) {
86 kip->slot_used[i] = 1;
87 kip->nused++;
88 return kip->insns + (i * MAX_INSN_SIZE);
89 }
90 }
91 /* Surprise! No unused slots. Fix kip->nused. */
92 kip->nused = INSNS_PER_PAGE;
93 }
94 }
95
96 /* All out of space. Need to allocate a new page. Use slot 0.*/
97 kip = kmalloc(sizeof(struct kprobe_insn_page), GFP_KERNEL);
98 if (!kip) {
99 return NULL;
100 }
101
102 /*
103 * Use module_alloc so this page is within +/- 2GB of where the
104 * kernel image and loaded module images reside. This is required
105 * so x86_64 can correctly handle the %rip-relative fixups.
106 */
107 kip->insns = module_alloc(PAGE_SIZE);
108 if (!kip->insns) {
109 kfree(kip);
110 return NULL;
111 }
112 INIT_HLIST_NODE(&kip->hlist);
113 hlist_add_head(&kip->hlist, &kprobe_insn_pages);
114 memset(kip->slot_used, 0, INSNS_PER_PAGE);
115 kip->slot_used[0] = 1;
116 kip->nused = 1;
117 return kip->insns;
118}
119
120void free_insn_slot(kprobe_opcode_t *slot)
121{
122 struct kprobe_insn_page *kip;
123 struct hlist_node *pos;
124
125 hlist_for_each(pos, &kprobe_insn_pages) {
126 kip = hlist_entry(pos, struct kprobe_insn_page, hlist);
127 if (kip->insns <= slot &&
128 slot < kip->insns + (INSNS_PER_PAGE * MAX_INSN_SIZE)) {
129 int i = (slot - kip->insns) / MAX_INSN_SIZE;
130 kip->slot_used[i] = 0;
131 kip->nused--;
132 if (kip->nused == 0) {
133 /*
134 * Page is no longer in use. Free it unless
135 * it's the last one. We keep the last one
136 * so as not to have to set it up again the
137 * next time somebody inserts a probe.
138 */
139 hlist_del(&kip->hlist);
140 if (hlist_empty(&kprobe_insn_pages)) {
141 INIT_HLIST_NODE(&kip->hlist);
142 hlist_add_head(&kip->hlist,
143 &kprobe_insn_pages);
144 } else {
145 module_free(NULL, kip->insns);
146 kfree(kip);
147 }
148 }
149 return;
150 }
151 }
152}
153
53/* Locks kprobe: irqs must be disabled */ 154/* Locks kprobe: irqs must be disabled */
54void lock_kprobes(void) 155void lock_kprobes(void)
55{ 156{
@@ -139,12 +240,6 @@ static int aggr_break_handler(struct kprobe *p, struct pt_regs *regs)
139 return 0; 240 return 0;
140} 241}
141 242
142struct kprobe trampoline_p = {
143 .addr = (kprobe_opcode_t *) &kretprobe_trampoline,
144 .pre_handler = trampoline_probe_handler,
145 .post_handler = trampoline_post_handler
146};
147
148struct kretprobe_instance *get_free_rp_inst(struct kretprobe *rp) 243struct kretprobe_instance *get_free_rp_inst(struct kretprobe *rp)
149{ 244{
150 struct hlist_node *node; 245 struct hlist_node *node;
@@ -163,35 +258,18 @@ static struct kretprobe_instance *get_used_rp_inst(struct kretprobe *rp)
163 return NULL; 258 return NULL;
164} 259}
165 260
166struct kretprobe_instance *get_rp_inst(void *sara)
167{
168 struct hlist_head *head;
169 struct hlist_node *node;
170 struct task_struct *tsk;
171 struct kretprobe_instance *ri;
172
173 tsk = arch_get_kprobe_task(sara);
174 head = &kretprobe_inst_table[hash_ptr(tsk, KPROBE_HASH_BITS)];
175 hlist_for_each_entry(ri, node, head, hlist) {
176 if (ri->stack_addr == sara)
177 return ri;
178 }
179 return NULL;
180}
181
182void add_rp_inst(struct kretprobe_instance *ri) 261void add_rp_inst(struct kretprobe_instance *ri)
183{ 262{
184 struct task_struct *tsk;
185 /* 263 /*
186 * Remove rp inst off the free list - 264 * Remove rp inst off the free list -
187 * Add it back when probed function returns 265 * Add it back when probed function returns
188 */ 266 */
189 hlist_del(&ri->uflist); 267 hlist_del(&ri->uflist);
190 tsk = arch_get_kprobe_task(ri->stack_addr); 268
191 /* Add rp inst onto table */ 269 /* Add rp inst onto table */
192 INIT_HLIST_NODE(&ri->hlist); 270 INIT_HLIST_NODE(&ri->hlist);
193 hlist_add_head(&ri->hlist, 271 hlist_add_head(&ri->hlist,
194 &kretprobe_inst_table[hash_ptr(tsk, KPROBE_HASH_BITS)]); 272 &kretprobe_inst_table[hash_ptr(ri->task, KPROBE_HASH_BITS)]);
195 273
196 /* Also add this rp inst to the used list. */ 274 /* Also add this rp inst to the used list. */
197 INIT_HLIST_NODE(&ri->uflist); 275 INIT_HLIST_NODE(&ri->uflist);
@@ -218,34 +296,25 @@ struct hlist_head * kretprobe_inst_table_head(struct task_struct *tsk)
218 return &kretprobe_inst_table[hash_ptr(tsk, KPROBE_HASH_BITS)]; 296 return &kretprobe_inst_table[hash_ptr(tsk, KPROBE_HASH_BITS)];
219} 297}
220 298
221struct kretprobe_instance *get_rp_inst_tsk(struct task_struct *tk)
222{
223 struct task_struct *tsk;
224 struct hlist_head *head;
225 struct hlist_node *node;
226 struct kretprobe_instance *ri;
227
228 head = &kretprobe_inst_table[hash_ptr(tk, KPROBE_HASH_BITS)];
229
230 hlist_for_each_entry(ri, node, head, hlist) {
231 tsk = arch_get_kprobe_task(ri->stack_addr);
232 if (tsk == tk)
233 return ri;
234 }
235 return NULL;
236}
237
238/* 299/*
239 * This function is called from do_exit or do_execv when task tk's stack is 300 * This function is called from exit_thread or flush_thread when task tk's
240 * about to be recycled. Recycle any function-return probe instances 301 * stack is being recycled so that we can recycle any function-return probe
241 * associated with this task. These represent probed functions that have 302 * instances associated with this task. These left over instances represent
242 * been called but may never return. 303 * probed functions that have been called but will never return.
243 */ 304 */
244void kprobe_flush_task(struct task_struct *tk) 305void kprobe_flush_task(struct task_struct *tk)
245{ 306{
307 struct kretprobe_instance *ri;
308 struct hlist_head *head;
309 struct hlist_node *node, *tmp;
246 unsigned long flags = 0; 310 unsigned long flags = 0;
311
247 spin_lock_irqsave(&kprobe_lock, flags); 312 spin_lock_irqsave(&kprobe_lock, flags);
248 arch_kprobe_flush_task(tk); 313 head = kretprobe_inst_table_head(current);
314 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
315 if (ri->task == tk)
316 recycle_rp_inst(ri);
317 }
249 spin_unlock_irqrestore(&kprobe_lock, flags); 318 spin_unlock_irqrestore(&kprobe_lock, flags);
250} 319}
251 320
@@ -505,9 +574,10 @@ static int __init init_kprobes(void)
505 INIT_HLIST_HEAD(&kretprobe_inst_table[i]); 574 INIT_HLIST_HEAD(&kretprobe_inst_table[i]);
506 } 575 }
507 576
508 err = register_die_notifier(&kprobe_exceptions_nb); 577 err = arch_init();
509 /* Register the trampoline probe for return probe */ 578 if (!err)
510 register_kprobe(&trampoline_p); 579 err = register_die_notifier(&kprobe_exceptions_nb);
580
511 return err; 581 return err;
512} 582}
513 583
diff --git a/kernel/sched.c b/kernel/sched.c
index a07cff90d849..5f2182d42241 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -3448,15 +3448,7 @@ int task_nice(const task_t *p)
3448{ 3448{
3449 return TASK_NICE(p); 3449 return TASK_NICE(p);
3450} 3450}
3451
3452/*
3453 * The only users of task_nice are binfmt_elf and binfmt_elf32.
3454 * binfmt_elf is no longer modular, but binfmt_elf32 still is.
3455 * Therefore, task_nice is needed if there is a compat_mode.
3456 */
3457#ifdef CONFIG_COMPAT
3458EXPORT_SYMBOL_GPL(task_nice); 3451EXPORT_SYMBOL_GPL(task_nice);
3459#endif
3460 3452
3461/** 3453/**
3462 * idle_cpu - is a given cpu idle currently? 3454 * idle_cpu - is a given cpu idle currently?
@@ -4174,6 +4166,14 @@ void show_state(void)
4174 read_unlock(&tasklist_lock); 4166 read_unlock(&tasklist_lock);
4175} 4167}
4176 4168
4169/**
4170 * init_idle - set up an idle thread for a given CPU
4171 * @idle: task in question
4172 * @cpu: cpu the idle task belongs to
4173 *
4174 * NOTE: this function does not set the idle thread's NEED_RESCHED
4175 * flag, to make booting more robust.
4176 */
4177void __devinit init_idle(task_t *idle, int cpu) 4177void __devinit init_idle(task_t *idle, int cpu)
4178{ 4178{
4179 runqueue_t *rq = cpu_rq(cpu); 4179 runqueue_t *rq = cpu_rq(cpu);
@@ -4191,7 +4191,6 @@ void __devinit init_idle(task_t *idle, int cpu)
4191#if defined(CONFIG_SMP) && defined(__ARCH_WANT_UNLOCKED_CTXSW) 4191#if defined(CONFIG_SMP) && defined(__ARCH_WANT_UNLOCKED_CTXSW)
4192 idle->oncpu = 1; 4192 idle->oncpu = 1;
4193#endif 4193#endif
4194 set_tsk_need_resched(idle);
4195 spin_unlock_irqrestore(&rq->lock, flags); 4194 spin_unlock_irqrestore(&rq->lock, flags);
4196 4195
4197 /* Set the preempt count _outside_ the spinlocks! */ 4196 /* Set the preempt count _outside_ the spinlocks! */
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 613b99a55917..a6329fa8f862 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -354,7 +354,7 @@ static void background_writeout(unsigned long _min_pages)
354 * the whole world. Returns 0 if a pdflush thread was dispatched. Returns 354 * the whole world. Returns 0 if a pdflush thread was dispatched. Returns
355 * -1 if all pdflush threads were busy. 355 * -1 if all pdflush threads were busy.
356 */ 356 */
357int wakeup_bdflush(long nr_pages) 357int wakeup_pdflush(long nr_pages)
358{ 358{
359 if (nr_pages == 0) { 359 if (nr_pages == 0) {
360 struct writeback_state wbs; 360 struct writeback_state wbs;
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 7ee675ad101e..3c9f7f881125 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1667,9 +1667,8 @@ void __init memmap_init_zone(unsigned long size, int nid, unsigned long zone,
1667#ifdef WANT_PAGE_VIRTUAL 1667#ifdef WANT_PAGE_VIRTUAL
1668 /* The shift won't overflow because ZONE_NORMAL is below 4G. */ 1668 /* The shift won't overflow because ZONE_NORMAL is below 4G. */
1669 if (!is_highmem_idx(zone)) 1669 if (!is_highmem_idx(zone))
1670 set_page_address(page, __va(start_pfn << PAGE_SHIFT)); 1670 set_page_address(page, __va(pfn << PAGE_SHIFT));
1671#endif 1671#endif
1672 start_pfn++;
1673 } 1672 }
1674} 1673}
1675 1674
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 1fa312a8db77..cfffe5098d53 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -972,7 +972,7 @@ int try_to_free_pages(struct zone **zones, unsigned int gfp_mask)
972 * writeout. So in laptop mode, write out the whole world. 972 * writeout. So in laptop mode, write out the whole world.
973 */ 973 */
974 if (total_scanned > sc.swap_cluster_max + sc.swap_cluster_max/2) { 974 if (total_scanned > sc.swap_cluster_max + sc.swap_cluster_max/2) {
975 wakeup_bdflush(laptop_mode ? 0 : total_scanned); 975 wakeup_pdflush(laptop_mode ? 0 : total_scanned);
976 sc.may_writepage = 1; 976 sc.may_writepage = 1;
977 } 977 }
978 978
diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
index 03ae4edddac3..2d52fee63a8c 100644
--- a/net/bridge/br_netfilter.c
+++ b/net/bridge/br_netfilter.c
@@ -844,7 +844,7 @@ static unsigned int ip_sabotage_out(unsigned int hook, struct sk_buff **pskb,
844 * doesn't use the bridge parent of the indev by using 844 * doesn't use the bridge parent of the indev by using
845 * the BRNF_DONT_TAKE_PARENT mask. */ 845 * the BRNF_DONT_TAKE_PARENT mask. */
846 if (hook == NF_IP_FORWARD && nf_bridge->physindev == NULL) { 846 if (hook == NF_IP_FORWARD && nf_bridge->physindev == NULL) {
847 nf_bridge->mask &= BRNF_DONT_TAKE_PARENT; 847 nf_bridge->mask |= BRNF_DONT_TAKE_PARENT;
848 nf_bridge->physindev = (struct net_device *)in; 848 nf_bridge->physindev = (struct net_device *)in;
849 } 849 }
850#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) 850#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
diff --git a/net/bridge/netfilter/ebt_log.c b/net/bridge/netfilter/ebt_log.c
index e4ae34b88925..662975be3d1d 100644
--- a/net/bridge/netfilter/ebt_log.c
+++ b/net/bridge/netfilter/ebt_log.c
@@ -61,8 +61,6 @@ static void ebt_log(const struct sk_buff *skb, unsigned int hooknr,
61{ 61{
62 struct ebt_log_info *info = (struct ebt_log_info *)data; 62 struct ebt_log_info *info = (struct ebt_log_info *)data;
63 char level_string[4] = "< >"; 63 char level_string[4] = "< >";
64 union {struct iphdr iph; struct tcpudphdr ports;
65 struct arphdr arph; struct arppayload arpp;} u;
66 64
67 level_string[1] = '0' + info->loglevel; 65 level_string[1] = '0' + info->loglevel;
68 spin_lock_bh(&ebt_log_lock); 66 spin_lock_bh(&ebt_log_lock);
@@ -88,7 +86,7 @@ static void ebt_log(const struct sk_buff *skb, unsigned int hooknr,
88 } 86 }
89 printk(" IP SRC=%u.%u.%u.%u IP DST=%u.%u.%u.%u,", 87 printk(" IP SRC=%u.%u.%u.%u IP DST=%u.%u.%u.%u,",
90 NIPQUAD(ih->saddr), NIPQUAD(ih->daddr)); 88 NIPQUAD(ih->saddr), NIPQUAD(ih->daddr));
91 printk(" IP tos=0x%02X, IP proto=%d", u.iph.tos, 89 printk(" IP tos=0x%02X, IP proto=%d", ih->tos,
92 ih->protocol); 90 ih->protocol);
93 if (ih->protocol == IPPROTO_TCP || 91 if (ih->protocol == IPPROTO_TCP ||
94 ih->protocol == IPPROTO_UDP) { 92 ih->protocol == IPPROTO_UDP) {
@@ -127,7 +125,7 @@ static void ebt_log(const struct sk_buff *skb, unsigned int hooknr,
127 ah->ar_pln == sizeof(uint32_t)) { 125 ah->ar_pln == sizeof(uint32_t)) {
128 struct arppayload _arpp, *ap; 126 struct arppayload _arpp, *ap;
129 127
130 ap = skb_header_pointer(skb, sizeof(u.arph), 128 ap = skb_header_pointer(skb, sizeof(_arph),
131 sizeof(_arpp), &_arpp); 129 sizeof(_arpp), &_arpp);
132 if (ap == NULL) { 130 if (ap == NULL) {
133 printk(" INCOMPLETE ARP payload"); 131 printk(" INCOMPLETE ARP payload");
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 851eb927ed97..1beb782ac41b 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1598,6 +1598,8 @@ static int neightbl_fill_info(struct neigh_table *tbl, struct sk_buff *skb,
1598 1598
1599 read_lock_bh(&tbl->lock); 1599 read_lock_bh(&tbl->lock);
1600 ndtmsg->ndtm_family = tbl->family; 1600 ndtmsg->ndtm_family = tbl->family;
1601 ndtmsg->ndtm_pad1 = 0;
1602 ndtmsg->ndtm_pad2 = 0;
1601 1603
1602 RTA_PUT_STRING(skb, NDTA_NAME, tbl->id); 1604 RTA_PUT_STRING(skb, NDTA_NAME, tbl->id);
1603 RTA_PUT_MSECS(skb, NDTA_GC_INTERVAL, tbl->gc_interval); 1605 RTA_PUT_MSECS(skb, NDTA_GC_INTERVAL, tbl->gc_interval);
@@ -1683,6 +1685,8 @@ static int neightbl_fill_param_info(struct neigh_table *tbl,
1683 1685
1684 read_lock_bh(&tbl->lock); 1686 read_lock_bh(&tbl->lock);
1685 ndtmsg->ndtm_family = tbl->family; 1687 ndtmsg->ndtm_family = tbl->family;
1688 ndtmsg->ndtm_pad1 = 0;
1689 ndtmsg->ndtm_pad2 = 0;
1686 RTA_PUT_STRING(skb, NDTA_NAME, tbl->id); 1690 RTA_PUT_STRING(skb, NDTA_NAME, tbl->id);
1687 1691
1688 if (neightbl_fill_parms(skb, parms) < 0) 1692 if (neightbl_fill_parms(skb, parms) < 0)
@@ -1872,6 +1876,8 @@ static int neigh_fill_info(struct sk_buff *skb, struct neighbour *n,
1872 struct ndmsg *ndm = NLMSG_DATA(nlh); 1876 struct ndmsg *ndm = NLMSG_DATA(nlh);
1873 1877
1874 ndm->ndm_family = n->ops->family; 1878 ndm->ndm_family = n->ops->family;
1879 ndm->ndm_pad1 = 0;
1880 ndm->ndm_pad2 = 0;
1875 ndm->ndm_flags = n->flags; 1881 ndm->ndm_flags = n->flags;
1876 ndm->ndm_type = n->type; 1882 ndm->ndm_type = n->type;
1877 ndm->ndm_ifindex = n->dev->ifindex; 1883 ndm->ndm_ifindex = n->dev->ifindex;
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index c57b06bc79f3..975d651312dc 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -151,7 +151,7 @@
151#include <asm/timex.h> 151#include <asm/timex.h>
152 152
153 153
154#define VERSION "pktgen v2.61: Packet Generator for packet performance testing.\n" 154#define VERSION "pktgen v2.62: Packet Generator for packet performance testing.\n"
155 155
156/* #define PG_DEBUG(a) a */ 156/* #define PG_DEBUG(a) a */
157#define PG_DEBUG(a) 157#define PG_DEBUG(a)
@@ -1921,6 +1921,11 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
1921 struct iphdr *iph; 1921 struct iphdr *iph;
1922 struct pktgen_hdr *pgh = NULL; 1922 struct pktgen_hdr *pgh = NULL;
1923 1923
1924 /* Update any of the values, used when we're incrementing various
1925 * fields.
1926 */
1927 mod_cur_headers(pkt_dev);
1928
1924 skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + 16, GFP_ATOMIC); 1929 skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + 16, GFP_ATOMIC);
1925 if (!skb) { 1930 if (!skb) {
1926 sprintf(pkt_dev->result, "No memory"); 1931 sprintf(pkt_dev->result, "No memory");
@@ -1934,11 +1939,6 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
1934 iph = (struct iphdr *)skb_put(skb, sizeof(struct iphdr)); 1939 iph = (struct iphdr *)skb_put(skb, sizeof(struct iphdr));
1935 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr)); 1940 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
1936 1941
1937 /* Update any of the values, used when we're incrementing various
1938 * fields.
1939 */
1940 mod_cur_headers(pkt_dev);
1941
1942 memcpy(eth, pkt_dev->hh, 12); 1942 memcpy(eth, pkt_dev->hh, 12);
1943 *(u16*)&eth[12] = __constant_htons(ETH_P_IP); 1943 *(u16*)&eth[12] = __constant_htons(ETH_P_IP);
1944 1944
@@ -2192,7 +2192,12 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2192 int datalen; 2192 int datalen;
2193 struct ipv6hdr *iph; 2193 struct ipv6hdr *iph;
2194 struct pktgen_hdr *pgh = NULL; 2194 struct pktgen_hdr *pgh = NULL;
2195 2195
2196 /* Update any of the values, used when we're incrementing various
2197 * fields.
2198 */
2199 mod_cur_headers(pkt_dev);
2200
2196 skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + 16, GFP_ATOMIC); 2201 skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + 16, GFP_ATOMIC);
2197 if (!skb) { 2202 if (!skb) {
2198 sprintf(pkt_dev->result, "No memory"); 2203 sprintf(pkt_dev->result, "No memory");
@@ -2206,17 +2211,9 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2206 iph = (struct ipv6hdr *)skb_put(skb, sizeof(struct ipv6hdr)); 2211 iph = (struct ipv6hdr *)skb_put(skb, sizeof(struct ipv6hdr));
2207 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr)); 2212 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
2208 2213
2209
2210 /* Update any of the values, used when we're incrementing various
2211 * fields.
2212 */
2213 mod_cur_headers(pkt_dev);
2214
2215
2216 memcpy(eth, pkt_dev->hh, 12); 2214 memcpy(eth, pkt_dev->hh, 12);
2217 *(u16*)&eth[12] = __constant_htons(ETH_P_IPV6); 2215 *(u16*)&eth[12] = __constant_htons(ETH_P_IPV6);
2218 2216
2219
2220 datalen = pkt_dev->cur_pkt_size-14- 2217 datalen = pkt_dev->cur_pkt_size-14-
2221 sizeof(struct ipv6hdr)-sizeof(struct udphdr); /* Eth + IPh + UDPh */ 2218 sizeof(struct ipv6hdr)-sizeof(struct udphdr); /* Eth + IPh + UDPh */
2222 2219
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index e013d836a7ab..4b1bb30e6381 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -126,6 +126,7 @@ void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data
126 rta->rta_type = attrtype; 126 rta->rta_type = attrtype;
127 rta->rta_len = size; 127 rta->rta_len = size;
128 memcpy(RTA_DATA(rta), data, attrlen); 128 memcpy(RTA_DATA(rta), data, attrlen);
129 memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size);
129} 130}
130 131
131size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size) 132size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size)
@@ -188,6 +189,7 @@ static int rtnetlink_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
188 nlh = NLMSG_NEW(skb, pid, seq, type, sizeof(*r), flags); 189 nlh = NLMSG_NEW(skb, pid, seq, type, sizeof(*r), flags);
189 r = NLMSG_DATA(nlh); 190 r = NLMSG_DATA(nlh);
190 r->ifi_family = AF_UNSPEC; 191 r->ifi_family = AF_UNSPEC;
192 r->__ifi_pad = 0;
191 r->ifi_type = dev->type; 193 r->ifi_type = dev->type;
192 r->ifi_index = dev->ifindex; 194 r->ifi_index = dev->ifindex;
193 r->ifi_flags = dev_get_flags(dev); 195 r->ifi_flags = dev_get_flags(dev);
diff --git a/net/core/wireless.c b/net/core/wireless.c
index b2fe378dfbf8..3ff5639c0b78 100644
--- a/net/core/wireless.c
+++ b/net/core/wireless.c
@@ -1102,6 +1102,7 @@ static inline int rtnetlink_fill_iwinfo(struct sk_buff * skb,
1102 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(*r)); 1102 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(*r));
1103 r = NLMSG_DATA(nlh); 1103 r = NLMSG_DATA(nlh);
1104 r->ifi_family = AF_UNSPEC; 1104 r->ifi_family = AF_UNSPEC;
1105 r->__ifi_pad = 0;
1105 r->ifi_type = dev->type; 1106 r->ifi_type = dev->type;
1106 r->ifi_index = dev->ifindex; 1107 r->ifi_index = dev->ifindex;
1107 r->ifi_flags = dev->flags; 1108 r->ifi_flags = dev->flags;
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index 6617ea47d365..ab60ea63688e 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -92,10 +92,9 @@ int eth_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
92 * Set the source hardware address. 92 * Set the source hardware address.
93 */ 93 */
94 94
95 if(saddr) 95 if(!saddr)
96 memcpy(eth->h_source,saddr,dev->addr_len); 96 saddr = dev->dev_addr;
97 else 97 memcpy(eth->h_source,saddr,dev->addr_len);
98 memcpy(eth->h_source,dev->dev_addr,dev->addr_len);
99 98
100 /* 99 /*
101 * Anyway, the loopback-device should never use this function... 100 * Anyway, the loopback-device should never use this function...
diff --git a/net/ipv4/Kconfig b/net/ipv4/Kconfig
index 347083433120..3e63123f7bbd 100644
--- a/net/ipv4/Kconfig
+++ b/net/ipv4/Kconfig
@@ -448,7 +448,6 @@ config IP_TCPDIAG_IPV6
448config TCP_CONG_ADVANCED 448config TCP_CONG_ADVANCED
449 bool "TCP: advanced congestion control" 449 bool "TCP: advanced congestion control"
450 depends on INET 450 depends on INET
451 default y
452 ---help--- 451 ---help---
453 Support for selection of various TCP congestion control 452 Support for selection of various TCP congestion control
454 modules. 453 modules.
@@ -549,7 +548,7 @@ config TCP_CONG_SCALABLE
549endmenu 548endmenu
550 549
551config TCP_CONG_BIC 550config TCP_CONG_BIC
552 boolean 551 tristate
553 depends on !TCP_CONG_ADVANCED 552 depends on !TCP_CONG_ADVANCED
554 default y 553 default y
555 554
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 0671569ee6f0..b56e88edf1b3 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -43,7 +43,7 @@
43 * 2 of the License, or (at your option) any later version. 43 * 2 of the License, or (at your option) any later version.
44 */ 44 */
45 45
46#define VERSION "0.323" 46#define VERSION "0.324"
47 47
48#include <linux/config.h> 48#include <linux/config.h>
49#include <asm/uaccess.h> 49#include <asm/uaccess.h>
@@ -341,8 +341,10 @@ static struct leaf *leaf_new(void)
341static struct leaf_info *leaf_info_new(int plen) 341static struct leaf_info *leaf_info_new(int plen)
342{ 342{
343 struct leaf_info *li = kmalloc(sizeof(struct leaf_info), GFP_KERNEL); 343 struct leaf_info *li = kmalloc(sizeof(struct leaf_info), GFP_KERNEL);
344 li->plen = plen; 344 if(li) {
345 INIT_LIST_HEAD(&li->falh); 345 li->plen = plen;
346 INIT_LIST_HEAD(&li->falh);
347 }
346 return li; 348 return li;
347} 349}
348 350
@@ -879,8 +881,8 @@ static struct node *trie_rebalance(struct trie *t, struct tnode *tn)
879 return (struct node*) tn; 881 return (struct node*) tn;
880} 882}
881 883
882static struct list_head * 884static struct list_head *
883fib_insert_node(struct trie *t, u32 key, int plen) 885fib_insert_node(struct trie *t, int *err, u32 key, int plen)
884{ 886{
885 int pos, newpos; 887 int pos, newpos;
886 struct tnode *tp = NULL, *tn = NULL; 888 struct tnode *tp = NULL, *tn = NULL;
@@ -940,7 +942,6 @@ fib_insert_node(struct trie *t, u32 key, int plen)
940 if(tp && IS_LEAF(tp)) 942 if(tp && IS_LEAF(tp))
941 BUG(); 943 BUG();
942 944
943 t->revision++;
944 945
945 /* Case 1: n is a leaf. Compare prefixes */ 946 /* Case 1: n is a leaf. Compare prefixes */
946 947
@@ -949,8 +950,10 @@ fib_insert_node(struct trie *t, u32 key, int plen)
949 950
950 li = leaf_info_new(plen); 951 li = leaf_info_new(plen);
951 952
952 if(! li) 953 if(! li) {
953 BUG(); 954 *err = -ENOMEM;
955 goto err;
956 }
954 957
955 fa_head = &li->falh; 958 fa_head = &li->falh;
956 insert_leaf_info(&l->list, li); 959 insert_leaf_info(&l->list, li);
@@ -959,14 +962,19 @@ fib_insert_node(struct trie *t, u32 key, int plen)
959 t->size++; 962 t->size++;
960 l = leaf_new(); 963 l = leaf_new();
961 964
962 if(! l) 965 if(! l) {
963 BUG(); 966 *err = -ENOMEM;
967 goto err;
968 }
964 969
965 l->key = key; 970 l->key = key;
966 li = leaf_info_new(plen); 971 li = leaf_info_new(plen);
967 972
968 if(! li) 973 if(! li) {
969 BUG(); 974 tnode_free((struct tnode *) l);
975 *err = -ENOMEM;
976 goto err;
977 }
970 978
971 fa_head = &li->falh; 979 fa_head = &li->falh;
972 insert_leaf_info(&l->list, li); 980 insert_leaf_info(&l->list, li);
@@ -1003,9 +1011,14 @@ fib_insert_node(struct trie *t, u32 key, int plen)
1003 newpos = 0; 1011 newpos = 0;
1004 tn = tnode_new(key, newpos, 1); /* First tnode */ 1012 tn = tnode_new(key, newpos, 1); /* First tnode */
1005 } 1013 }
1006 if(!tn)
1007 trie_bug("tnode_pfx_new failed");
1008 1014
1015 if(!tn) {
1016 free_leaf_info(li);
1017 tnode_free((struct tnode *) l);
1018 *err = -ENOMEM;
1019 goto err;
1020 }
1021
1009 NODE_SET_PARENT(tn, tp); 1022 NODE_SET_PARENT(tn, tp);
1010 1023
1011 missbit=tkey_extract_bits(key, newpos, 1); 1024 missbit=tkey_extract_bits(key, newpos, 1);
@@ -1027,7 +1040,9 @@ fib_insert_node(struct trie *t, u32 key, int plen)
1027 } 1040 }
1028 /* Rebalance the trie */ 1041 /* Rebalance the trie */
1029 t->trie = trie_rebalance(t, tp); 1042 t->trie = trie_rebalance(t, tp);
1030done:; 1043done:
1044 t->revision++;
1045err:;
1031 return fa_head; 1046 return fa_head;
1032} 1047}
1033 1048
@@ -1156,8 +1171,12 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
1156 * Insert new entry to the list. 1171 * Insert new entry to the list.
1157 */ 1172 */
1158 1173
1159 if(!fa_head) 1174 if(!fa_head) {
1160 fa_head = fib_insert_node(t, key, plen); 1175 fa_head = fib_insert_node(t, &err, key, plen);
1176 err = 0;
1177 if(err)
1178 goto out_free_new_fa;
1179 }
1161 1180
1162 write_lock_bh(&fib_lock); 1181 write_lock_bh(&fib_lock);
1163 1182
@@ -1170,6 +1189,9 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
1170 rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, tb->tb_id, nlhdr, req); 1189 rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, tb->tb_id, nlhdr, req);
1171succeeded: 1190succeeded:
1172 return 0; 1191 return 0;
1192
1193out_free_new_fa:
1194 kmem_cache_free(fn_alias_kmem, new_fa);
1173out: 1195out:
1174 fib_release_info(fi); 1196 fib_release_info(fi);
1175err:; 1197err:;
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index af2ec88bbb2f..c703528e0bcd 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -283,14 +283,18 @@ static inline int ip_rcv_finish(struct sk_buff *skb)
283{ 283{
284 struct net_device *dev = skb->dev; 284 struct net_device *dev = skb->dev;
285 struct iphdr *iph = skb->nh.iph; 285 struct iphdr *iph = skb->nh.iph;
286 int err;
286 287
287 /* 288 /*
288 * Initialise the virtual path cache for the packet. It describes 289 * Initialise the virtual path cache for the packet. It describes
289 * how the packet travels inside Linux networking. 290 * how the packet travels inside Linux networking.
290 */ 291 */
291 if (skb->dst == NULL) { 292 if (skb->dst == NULL) {
292 if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev)) 293 if ((err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))) {
294 if (err == -EHOSTUNREACH)
295 IP_INC_STATS_BH(IPSTATS_MIB_INADDRERRORS);
293 goto drop; 296 goto drop;
297 }
294 } 298 }
295 299
296#ifdef CONFIG_NET_CLS_ROUTE 300#ifdef CONFIG_NET_CLS_ROUTE
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index ee07aec215a0..6ce5c3292f9f 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -188,7 +188,13 @@ static inline int ip_finish_output2(struct sk_buff *skb)
188 skb = skb2; 188 skb = skb2;
189 } 189 }
190 190
191 nf_reset(skb); 191#ifdef CONFIG_BRIDGE_NETFILTER
192 /* bridge-netfilter defers calling some IP hooks to the bridge layer
193 * and still needs the conntrack reference.
194 */
195 if (skb->nf_bridge == NULL)
196#endif
197 nf_reset(skb);
192 198
193 if (hh) { 199 if (hh) {
194 int hh_alen; 200 int hh_alen;
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index f2509034ce72..d2bf8e1930a3 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -1149,8 +1149,10 @@ static int __init ic_dynamic(void)
1149 ic_rarp_cleanup(); 1149 ic_rarp_cleanup();
1150#endif 1150#endif
1151 1151
1152 if (!ic_got_reply) 1152 if (!ic_got_reply) {
1153 ic_myaddr = INADDR_NONE;
1153 return -1; 1154 return -1;
1155 }
1154 1156
1155 printk("IP-Config: Got %s answer from %u.%u.%u.%u, ", 1157 printk("IP-Config: Got %s answer from %u.%u.%u.%u, ",
1156 ((ic_got_reply & IC_RARP) ? "RARP" 1158 ((ic_got_reply & IC_RARP) ? "RARP"
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index e4f809a93f47..7833d920bdba 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -297,6 +297,7 @@ static int vif_delete(int vifi)
297static void ipmr_destroy_unres(struct mfc_cache *c) 297static void ipmr_destroy_unres(struct mfc_cache *c)
298{ 298{
299 struct sk_buff *skb; 299 struct sk_buff *skb;
300 struct nlmsgerr *e;
300 301
301 atomic_dec(&cache_resolve_queue_len); 302 atomic_dec(&cache_resolve_queue_len);
302 303
@@ -306,7 +307,9 @@ static void ipmr_destroy_unres(struct mfc_cache *c)
306 nlh->nlmsg_type = NLMSG_ERROR; 307 nlh->nlmsg_type = NLMSG_ERROR;
307 nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct nlmsgerr)); 308 nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct nlmsgerr));
308 skb_trim(skb, nlh->nlmsg_len); 309 skb_trim(skb, nlh->nlmsg_len);
309 ((struct nlmsgerr*)NLMSG_DATA(nlh))->error = -ETIMEDOUT; 310 e = NLMSG_DATA(nlh);
311 e->error = -ETIMEDOUT;
312 memset(&e->msg, 0, sizeof(e->msg));
310 netlink_unicast(rtnl, skb, NETLINK_CB(skb).dst_pid, MSG_DONTWAIT); 313 netlink_unicast(rtnl, skb, NETLINK_CB(skb).dst_pid, MSG_DONTWAIT);
311 } else 314 } else
312 kfree_skb(skb); 315 kfree_skb(skb);
@@ -499,6 +502,7 @@ static struct mfc_cache *ipmr_cache_alloc_unres(void)
499static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c) 502static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c)
500{ 503{
501 struct sk_buff *skb; 504 struct sk_buff *skb;
505 struct nlmsgerr *e;
502 506
503 /* 507 /*
504 * Play the pending entries through our router 508 * Play the pending entries through our router
@@ -515,7 +519,9 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c)
515 nlh->nlmsg_type = NLMSG_ERROR; 519 nlh->nlmsg_type = NLMSG_ERROR;
516 nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct nlmsgerr)); 520 nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct nlmsgerr));
517 skb_trim(skb, nlh->nlmsg_len); 521 skb_trim(skb, nlh->nlmsg_len);
518 ((struct nlmsgerr*)NLMSG_DATA(nlh))->error = -EMSGSIZE; 522 e = NLMSG_DATA(nlh);
523 e->error = -EMSGSIZE;
524 memset(&e->msg, 0, sizeof(e->msg));
519 } 525 }
520 err = netlink_unicast(rtnl, skb, NETLINK_CB(skb).dst_pid, MSG_DONTWAIT); 526 err = netlink_unicast(rtnl, skb, NETLINK_CB(skb).dst_pid, MSG_DONTWAIT);
521 } else 527 } else
diff --git a/net/ipv4/ipvs/ip_vs_conn.c b/net/ipv4/ipvs/ip_vs_conn.c
index fd6feb5499fe..9f16ab309106 100644
--- a/net/ipv4/ipvs/ip_vs_conn.c
+++ b/net/ipv4/ipvs/ip_vs_conn.c
@@ -548,7 +548,6 @@ void ip_vs_conn_expire_now(struct ip_vs_conn *cp)
548{ 548{
549 if (del_timer(&cp->timer)) 549 if (del_timer(&cp->timer))
550 mod_timer(&cp->timer, jiffies); 550 mod_timer(&cp->timer, jiffies);
551 __ip_vs_conn_put(cp);
552} 551}
553 552
554 553
@@ -764,7 +763,6 @@ void ip_vs_random_dropentry(void)
764{ 763{
765 int idx; 764 int idx;
766 struct ip_vs_conn *cp; 765 struct ip_vs_conn *cp;
767 struct ip_vs_conn *ct;
768 766
769 /* 767 /*
770 * Randomly scan 1/32 of the whole table every second 768 * Randomly scan 1/32 of the whole table every second
@@ -801,21 +799,12 @@ void ip_vs_random_dropentry(void)
801 continue; 799 continue;
802 } 800 }
803 801
804 /*
805 * Drop the entry, and drop its ct if not referenced
806 */
807 atomic_inc(&cp->refcnt);
808 ct_write_unlock(hash);
809
810 if ((ct = cp->control))
811 atomic_inc(&ct->refcnt);
812 IP_VS_DBG(4, "del connection\n"); 802 IP_VS_DBG(4, "del connection\n");
813 ip_vs_conn_expire_now(cp); 803 ip_vs_conn_expire_now(cp);
814 if (ct) { 804 if (cp->control) {
815 IP_VS_DBG(4, "del conn template\n"); 805 IP_VS_DBG(4, "del conn template\n");
816 ip_vs_conn_expire_now(ct); 806 ip_vs_conn_expire_now(cp->control);
817 } 807 }
818 ct_write_lock(hash);
819 } 808 }
820 ct_write_unlock(hash); 809 ct_write_unlock(hash);
821 } 810 }
@@ -829,7 +818,6 @@ static void ip_vs_conn_flush(void)
829{ 818{
830 int idx; 819 int idx;
831 struct ip_vs_conn *cp; 820 struct ip_vs_conn *cp;
832 struct ip_vs_conn *ct;
833 821
834 flush_again: 822 flush_again:
835 for (idx=0; idx<IP_VS_CONN_TAB_SIZE; idx++) { 823 for (idx=0; idx<IP_VS_CONN_TAB_SIZE; idx++) {
@@ -839,18 +827,13 @@ static void ip_vs_conn_flush(void)
839 ct_write_lock_bh(idx); 827 ct_write_lock_bh(idx);
840 828
841 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) { 829 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) {
842 atomic_inc(&cp->refcnt);
843 ct_write_unlock(idx);
844 830
845 if ((ct = cp->control))
846 atomic_inc(&ct->refcnt);
847 IP_VS_DBG(4, "del connection\n"); 831 IP_VS_DBG(4, "del connection\n");
848 ip_vs_conn_expire_now(cp); 832 ip_vs_conn_expire_now(cp);
849 if (ct) { 833 if (cp->control) {
850 IP_VS_DBG(4, "del conn template\n"); 834 IP_VS_DBG(4, "del conn template\n");
851 ip_vs_conn_expire_now(ct); 835 ip_vs_conn_expire_now(cp->control);
852 } 836 }
853 ct_write_lock(idx);
854 } 837 }
855 ct_write_unlock_bh(idx); 838 ct_write_unlock_bh(idx);
856 } 839 }
diff --git a/net/ipv4/ipvs/ip_vs_ctl.c b/net/ipv4/ipvs/ip_vs_ctl.c
index 218d9701036e..12a82e91d22a 100644
--- a/net/ipv4/ipvs/ip_vs_ctl.c
+++ b/net/ipv4/ipvs/ip_vs_ctl.c
@@ -2059,7 +2059,7 @@ ip_vs_copy_service(struct ip_vs_service_entry *dst, struct ip_vs_service *src)
2059 dst->addr = src->addr; 2059 dst->addr = src->addr;
2060 dst->port = src->port; 2060 dst->port = src->port;
2061 dst->fwmark = src->fwmark; 2061 dst->fwmark = src->fwmark;
2062 strcpy(dst->sched_name, src->scheduler->name); 2062 strlcpy(dst->sched_name, src->scheduler->name, sizeof(dst->sched_name));
2063 dst->flags = src->flags; 2063 dst->flags = src->flags;
2064 dst->timeout = src->timeout / HZ; 2064 dst->timeout = src->timeout / HZ;
2065 dst->netmask = src->netmask; 2065 dst->netmask = src->netmask;
@@ -2080,6 +2080,7 @@ __ip_vs_get_service_entries(const struct ip_vs_get_services *get,
2080 list_for_each_entry(svc, &ip_vs_svc_table[idx], s_list) { 2080 list_for_each_entry(svc, &ip_vs_svc_table[idx], s_list) {
2081 if (count >= get->num_services) 2081 if (count >= get->num_services)
2082 goto out; 2082 goto out;
2083 memset(&entry, 0, sizeof(entry));
2083 ip_vs_copy_service(&entry, svc); 2084 ip_vs_copy_service(&entry, svc);
2084 if (copy_to_user(&uptr->entrytable[count], 2085 if (copy_to_user(&uptr->entrytable[count],
2085 &entry, sizeof(entry))) { 2086 &entry, sizeof(entry))) {
@@ -2094,6 +2095,7 @@ __ip_vs_get_service_entries(const struct ip_vs_get_services *get,
2094 list_for_each_entry(svc, &ip_vs_svc_fwm_table[idx], f_list) { 2095 list_for_each_entry(svc, &ip_vs_svc_fwm_table[idx], f_list) {
2095 if (count >= get->num_services) 2096 if (count >= get->num_services)
2096 goto out; 2097 goto out;
2098 memset(&entry, 0, sizeof(entry));
2097 ip_vs_copy_service(&entry, svc); 2099 ip_vs_copy_service(&entry, svc);
2098 if (copy_to_user(&uptr->entrytable[count], 2100 if (copy_to_user(&uptr->entrytable[count],
2099 &entry, sizeof(entry))) { 2101 &entry, sizeof(entry))) {
@@ -2304,12 +2306,12 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
2304 memset(&d, 0, sizeof(d)); 2306 memset(&d, 0, sizeof(d));
2305 if (ip_vs_sync_state & IP_VS_STATE_MASTER) { 2307 if (ip_vs_sync_state & IP_VS_STATE_MASTER) {
2306 d[0].state = IP_VS_STATE_MASTER; 2308 d[0].state = IP_VS_STATE_MASTER;
2307 strcpy(d[0].mcast_ifn, ip_vs_master_mcast_ifn); 2309 strlcpy(d[0].mcast_ifn, ip_vs_master_mcast_ifn, sizeof(d[0].mcast_ifn));
2308 d[0].syncid = ip_vs_master_syncid; 2310 d[0].syncid = ip_vs_master_syncid;
2309 } 2311 }
2310 if (ip_vs_sync_state & IP_VS_STATE_BACKUP) { 2312 if (ip_vs_sync_state & IP_VS_STATE_BACKUP) {
2311 d[1].state = IP_VS_STATE_BACKUP; 2313 d[1].state = IP_VS_STATE_BACKUP;
2312 strcpy(d[1].mcast_ifn, ip_vs_backup_mcast_ifn); 2314 strlcpy(d[1].mcast_ifn, ip_vs_backup_mcast_ifn, sizeof(d[1].mcast_ifn));
2313 d[1].syncid = ip_vs_backup_syncid; 2315 d[1].syncid = ip_vs_backup_syncid;
2314 } 2316 }
2315 if (copy_to_user(user, &d, sizeof(d)) != 0) 2317 if (copy_to_user(user, &d, sizeof(d)) != 0)
diff --git a/net/ipv4/ipvs/ip_vs_sync.c b/net/ipv4/ipvs/ip_vs_sync.c
index 25c479550a32..574d1f509b46 100644
--- a/net/ipv4/ipvs/ip_vs_sync.c
+++ b/net/ipv4/ipvs/ip_vs_sync.c
@@ -839,10 +839,10 @@ int start_sync_thread(int state, char *mcast_ifn, __u8 syncid)
839 839
840 ip_vs_sync_state |= state; 840 ip_vs_sync_state |= state;
841 if (state == IP_VS_STATE_MASTER) { 841 if (state == IP_VS_STATE_MASTER) {
842 strcpy(ip_vs_master_mcast_ifn, mcast_ifn); 842 strlcpy(ip_vs_master_mcast_ifn, mcast_ifn, sizeof(ip_vs_master_mcast_ifn));
843 ip_vs_master_syncid = syncid; 843 ip_vs_master_syncid = syncid;
844 } else { 844 } else {
845 strcpy(ip_vs_backup_mcast_ifn, mcast_ifn); 845 strlcpy(ip_vs_backup_mcast_ifn, mcast_ifn, sizeof(ip_vs_backup_mcast_ifn));
846 ip_vs_backup_syncid = syncid; 846 ip_vs_backup_syncid = syncid;
847 } 847 }
848 848
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index 9cde8c61f525..6706d3a1bc4f 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -30,7 +30,7 @@
30#include <linux/netfilter_ipv4/ipt_CLUSTERIP.h> 30#include <linux/netfilter_ipv4/ipt_CLUSTERIP.h>
31#include <linux/netfilter_ipv4/ip_conntrack.h> 31#include <linux/netfilter_ipv4/ip_conntrack.h>
32 32
33#define CLUSTERIP_VERSION "0.6" 33#define CLUSTERIP_VERSION "0.7"
34 34
35#define DEBUG_CLUSTERIP 35#define DEBUG_CLUSTERIP
36 36
@@ -524,8 +524,9 @@ arp_mangle(unsigned int hook,
524 || arp->ar_pln != 4 || arp->ar_hln != ETH_ALEN) 524 || arp->ar_pln != 4 || arp->ar_hln != ETH_ALEN)
525 return NF_ACCEPT; 525 return NF_ACCEPT;
526 526
527 /* we only want to mangle arp replies */ 527 /* we only want to mangle arp requests and replies */
528 if (arp->ar_op != htons(ARPOP_REPLY)) 528 if (arp->ar_op != htons(ARPOP_REPLY)
529 && arp->ar_op != htons(ARPOP_REQUEST))
529 return NF_ACCEPT; 530 return NF_ACCEPT;
530 531
531 payload = (void *)(arp+1); 532 payload = (void *)(arp+1);
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 80cf633d9f4a..12a1cf306f67 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1909,7 +1909,7 @@ static int ip_route_input_slow(struct sk_buff *skb, u32 daddr, u32 saddr,
1909 */ 1909 */
1910 if ((err = fib_lookup(&fl, &res)) != 0) { 1910 if ((err = fib_lookup(&fl, &res)) != 0) {
1911 if (!IN_DEV_FORWARD(in_dev)) 1911 if (!IN_DEV_FORWARD(in_dev))
1912 goto e_inval; 1912 goto e_hostunreach;
1913 goto no_route; 1913 goto no_route;
1914 } 1914 }
1915 free_res = 1; 1915 free_res = 1;
@@ -1933,7 +1933,7 @@ static int ip_route_input_slow(struct sk_buff *skb, u32 daddr, u32 saddr,
1933 } 1933 }
1934 1934
1935 if (!IN_DEV_FORWARD(in_dev)) 1935 if (!IN_DEV_FORWARD(in_dev))
1936 goto e_inval; 1936 goto e_hostunreach;
1937 if (res.type != RTN_UNICAST) 1937 if (res.type != RTN_UNICAST)
1938 goto martian_destination; 1938 goto martian_destination;
1939 1939
@@ -2025,6 +2025,11 @@ martian_destination:
2025 "%u.%u.%u.%u, dev %s\n", 2025 "%u.%u.%u.%u, dev %s\n",
2026 NIPQUAD(daddr), NIPQUAD(saddr), dev->name); 2026 NIPQUAD(daddr), NIPQUAD(saddr), dev->name);
2027#endif 2027#endif
2028
2029e_hostunreach:
2030 err = -EHOSTUNREACH;
2031 goto done;
2032
2028e_inval: 2033e_inval:
2029 err = -EINVAL; 2034 err = -EINVAL;
2030 goto done; 2035 goto done;
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index a54d4ef3fd35..77004b9456c0 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -2777,7 +2777,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
2777 read_lock_bh(&idev->lock); 2777 read_lock_bh(&idev->lock);
2778 switch (type) { 2778 switch (type) {
2779 case UNICAST_ADDR: 2779 case UNICAST_ADDR:
2780 /* unicast address */ 2780 /* unicast address incl. temp addr */
2781 for (ifa = idev->addr_list; ifa; 2781 for (ifa = idev->addr_list; ifa;
2782 ifa = ifa->if_next, ip_idx++) { 2782 ifa = ifa->if_next, ip_idx++) {
2783 if (ip_idx < s_ip_idx) 2783 if (ip_idx < s_ip_idx)
@@ -2788,19 +2788,6 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
2788 NLM_F_MULTI)) <= 0) 2788 NLM_F_MULTI)) <= 0)
2789 goto done; 2789 goto done;
2790 } 2790 }
2791 /* temp addr */
2792#ifdef CONFIG_IPV6_PRIVACY
2793 for (ifa = idev->tempaddr_list; ifa;
2794 ifa = ifa->tmp_next, ip_idx++) {
2795 if (ip_idx < s_ip_idx)
2796 continue;
2797 if ((err = inet6_fill_ifaddr(skb, ifa,
2798 NETLINK_CB(cb->skb).pid,
2799 cb->nlh->nlmsg_seq, RTM_NEWADDR,
2800 NLM_F_MULTI)) <= 0)
2801 goto done;
2802 }
2803#endif
2804 break; 2791 break;
2805 case MULTICAST_ADDR: 2792 case MULTICAST_ADDR:
2806 /* multicast address */ 2793 /* multicast address */
@@ -2923,6 +2910,7 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,
2923 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*r), flags); 2910 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*r), flags);
2924 r = NLMSG_DATA(nlh); 2911 r = NLMSG_DATA(nlh);
2925 r->ifi_family = AF_INET6; 2912 r->ifi_family = AF_INET6;
2913 r->__ifi_pad = 0;
2926 r->ifi_type = dev->type; 2914 r->ifi_type = dev->type;
2927 r->ifi_index = dev->ifindex; 2915 r->ifi_index = dev->ifindex;
2928 r->ifi_flags = dev_get_flags(dev); 2916 r->ifi_flags = dev_get_flags(dev);
@@ -3030,9 +3018,12 @@ static int inet6_fill_prefix(struct sk_buff *skb, struct inet6_dev *idev,
3030 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*pmsg), flags); 3018 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*pmsg), flags);
3031 pmsg = NLMSG_DATA(nlh); 3019 pmsg = NLMSG_DATA(nlh);
3032 pmsg->prefix_family = AF_INET6; 3020 pmsg->prefix_family = AF_INET6;
3021 pmsg->prefix_pad1 = 0;
3022 pmsg->prefix_pad2 = 0;
3033 pmsg->prefix_ifindex = idev->dev->ifindex; 3023 pmsg->prefix_ifindex = idev->dev->ifindex;
3034 pmsg->prefix_len = pinfo->prefix_len; 3024 pmsg->prefix_len = pinfo->prefix_len;
3035 pmsg->prefix_type = pinfo->type; 3025 pmsg->prefix_type = pinfo->type;
3026 pmsg->prefix_pad3 = 0;
3036 3027
3037 pmsg->prefix_flags = 0; 3028 pmsg->prefix_flags = 0;
3038 if (pinfo->onlink) 3029 if (pinfo->onlink)
diff --git a/net/ipv6/ip6_flowlabel.c b/net/ipv6/ip6_flowlabel.c
index 0e5f7499debb..b6c73da5ff35 100644
--- a/net/ipv6/ip6_flowlabel.c
+++ b/net/ipv6/ip6_flowlabel.c
@@ -244,7 +244,6 @@ struct ipv6_txoptions *fl6_merge_options(struct ipv6_txoptions * opt_space,
244 opt_space->opt_nflen = 0; 244 opt_space->opt_nflen = 0;
245 } 245 }
246 opt_space->dst1opt = fopt->dst1opt; 246 opt_space->dst1opt = fopt->dst1opt;
247 opt_space->auth = fopt->auth;
248 opt_space->opt_flen = fopt->opt_flen; 247 opt_space->opt_flen = fopt->opt_flen;
249 return opt_space; 248 return opt_space;
250} 249}
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 70bcd4744d93..fc456a7aaec3 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -315,8 +315,8 @@ err:
315static void netlink_remove(struct sock *sk) 315static void netlink_remove(struct sock *sk)
316{ 316{
317 netlink_table_grab(); 317 netlink_table_grab();
318 nl_table[sk->sk_protocol].hash.entries--; 318 if (sk_del_node_init(sk))
319 sk_del_node_init(sk); 319 nl_table[sk->sk_protocol].hash.entries--;
320 if (nlk_sk(sk)->groups) 320 if (nlk_sk(sk)->groups)
321 __sk_del_bind_node(sk); 321 __sk_del_bind_node(sk);
322 netlink_table_ungrab(); 322 netlink_table_ungrab();
@@ -429,7 +429,12 @@ retry:
429 err = netlink_insert(sk, pid); 429 err = netlink_insert(sk, pid);
430 if (err == -EADDRINUSE) 430 if (err == -EADDRINUSE)
431 goto retry; 431 goto retry;
432 return 0; 432
433 /* If 2 threads race to autobind, that is fine. */
434 if (err == -EBUSY)
435 err = 0;
436
437 return err;
433} 438}
434 439
435static inline int netlink_capable(struct socket *sock, unsigned int flag) 440static inline int netlink_capable(struct socket *sock, unsigned int flag)
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 9594206e6035..249c61936ea0 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -439,6 +439,8 @@ tca_get_fill(struct sk_buff *skb, struct tc_action *a, u32 pid, u32 seq,
439 439
440 t = NLMSG_DATA(nlh); 440 t = NLMSG_DATA(nlh);
441 t->tca_family = AF_UNSPEC; 441 t->tca_family = AF_UNSPEC;
442 t->tca__pad1 = 0;
443 t->tca__pad2 = 0;
442 444
443 x = (struct rtattr*) skb->tail; 445 x = (struct rtattr*) skb->tail;
444 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL); 446 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL);
@@ -580,6 +582,8 @@ static int tca_action_flush(struct rtattr *rta, struct nlmsghdr *n, u32 pid)
580 nlh = NLMSG_PUT(skb, pid, n->nlmsg_seq, RTM_DELACTION, sizeof(*t)); 582 nlh = NLMSG_PUT(skb, pid, n->nlmsg_seq, RTM_DELACTION, sizeof(*t));
581 t = NLMSG_DATA(nlh); 583 t = NLMSG_DATA(nlh);
582 t->tca_family = AF_UNSPEC; 584 t->tca_family = AF_UNSPEC;
585 t->tca__pad1 = 0;
586 t->tca__pad2 = 0;
583 587
584 x = (struct rtattr *) skb->tail; 588 x = (struct rtattr *) skb->tail;
585 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL); 589 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL);
@@ -687,7 +691,9 @@ static int tcf_add_notify(struct tc_action *a, u32 pid, u32 seq, int event,
687 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*t), flags); 691 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*t), flags);
688 t = NLMSG_DATA(nlh); 692 t = NLMSG_DATA(nlh);
689 t->tca_family = AF_UNSPEC; 693 t->tca_family = AF_UNSPEC;
690 694 t->tca__pad1 = 0;
695 t->tca__pad2 = 0;
696
691 x = (struct rtattr*) skb->tail; 697 x = (struct rtattr*) skb->tail;
692 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL); 698 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL);
693 699
@@ -842,6 +848,8 @@ tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
842 cb->nlh->nlmsg_type, sizeof(*t)); 848 cb->nlh->nlmsg_type, sizeof(*t));
843 t = NLMSG_DATA(nlh); 849 t = NLMSG_DATA(nlh);
844 t->tca_family = AF_UNSPEC; 850 t->tca_family = AF_UNSPEC;
851 t->tca__pad1 = 0;
852 t->tca__pad2 = 0;
845 853
846 x = (struct rtattr *) skb->tail; 854 x = (struct rtattr *) skb->tail;
847 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL); 855 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL);
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 1616bf5c9627..3b5714ef4d1a 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -331,6 +331,8 @@ tcf_fill_node(struct sk_buff *skb, struct tcf_proto *tp, unsigned long fh,
331 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*tcm), flags); 331 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*tcm), flags);
332 tcm = NLMSG_DATA(nlh); 332 tcm = NLMSG_DATA(nlh);
333 tcm->tcm_family = AF_UNSPEC; 333 tcm->tcm_family = AF_UNSPEC;
334 tcm->tcm__pad1 = 0;
335 tcm->tcm__pad1 = 0;
334 tcm->tcm_ifindex = tp->q->dev->ifindex; 336 tcm->tcm_ifindex = tp->q->dev->ifindex;
335 tcm->tcm_parent = tp->classid; 337 tcm->tcm_parent = tp->classid;
336 tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol); 338 tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol);
diff --git a/net/sched/cls_rsvp.h b/net/sched/cls_rsvp.h
index 232fb9196810..006168d69376 100644
--- a/net/sched/cls_rsvp.h
+++ b/net/sched/cls_rsvp.h
@@ -618,6 +618,7 @@ static int rsvp_dump(struct tcf_proto *tp, unsigned long fh,
618 pinfo.protocol = s->protocol; 618 pinfo.protocol = s->protocol;
619 pinfo.tunnelid = s->tunnelid; 619 pinfo.tunnelid = s->tunnelid;
620 pinfo.tunnelhdr = f->tunnelhdr; 620 pinfo.tunnelhdr = f->tunnelhdr;
621 pinfo.pad = 0;
621 RTA_PUT(skb, TCA_RSVP_PINFO, sizeof(pinfo), &pinfo); 622 RTA_PUT(skb, TCA_RSVP_PINFO, sizeof(pinfo), &pinfo);
622 if (f->res.classid) 623 if (f->res.classid)
623 RTA_PUT(skb, TCA_RSVP_CLASSID, 4, &f->res.classid); 624 RTA_PUT(skb, TCA_RSVP_CLASSID, 4, &f->res.classid);
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 97c1c75d5c78..05e6e0a799da 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -770,6 +770,8 @@ static int tc_fill_qdisc(struct sk_buff *skb, struct Qdisc *q, u32 clid,
770 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*tcm), flags); 770 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*tcm), flags);
771 tcm = NLMSG_DATA(nlh); 771 tcm = NLMSG_DATA(nlh);
772 tcm->tcm_family = AF_UNSPEC; 772 tcm->tcm_family = AF_UNSPEC;
773 tcm->tcm__pad1 = 0;
774 tcm->tcm__pad2 = 0;
773 tcm->tcm_ifindex = q->dev->ifindex; 775 tcm->tcm_ifindex = q->dev->ifindex;
774 tcm->tcm_parent = clid; 776 tcm->tcm_parent = clid;
775 tcm->tcm_handle = q->handle; 777 tcm->tcm_handle = q->handle;
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
index d43e3b8cbf6a..09453f997d8c 100644
--- a/net/sched/sch_cbq.c
+++ b/net/sched/sch_cbq.c
@@ -1528,6 +1528,7 @@ static __inline__ int cbq_dump_ovl(struct sk_buff *skb, struct cbq_class *cl)
1528 1528
1529 opt.strategy = cl->ovl_strategy; 1529 opt.strategy = cl->ovl_strategy;
1530 opt.priority2 = cl->priority2+1; 1530 opt.priority2 = cl->priority2+1;
1531 opt.pad = 0;
1531 opt.penalty = (cl->penalty*1000)/HZ; 1532 opt.penalty = (cl->penalty*1000)/HZ;
1532 RTA_PUT(skb, TCA_CBQ_OVL_STRATEGY, sizeof(opt), &opt); 1533 RTA_PUT(skb, TCA_CBQ_OVL_STRATEGY, sizeof(opt), &opt);
1533 return skb->len; 1534 return skb->len;
@@ -1563,6 +1564,8 @@ static __inline__ int cbq_dump_police(struct sk_buff *skb, struct cbq_class *cl)
1563 1564
1564 if (cl->police) { 1565 if (cl->police) {
1565 opt.police = cl->police; 1566 opt.police = cl->police;
1567 opt.__res1 = 0;
1568 opt.__res2 = 0;
1566 RTA_PUT(skb, TCA_CBQ_POLICE, sizeof(opt), &opt); 1569 RTA_PUT(skb, TCA_CBQ_POLICE, sizeof(opt), &opt);
1567 } 1570 }
1568 return skb->len; 1571 return skb->len;
diff --git a/net/sctp/endpointola.c b/net/sctp/endpointola.c
index 2ec0320fac3b..c44bf4165c6e 100644
--- a/net/sctp/endpointola.c
+++ b/net/sctp/endpointola.c
@@ -102,9 +102,9 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
102 /* Set up the base timeout information. */ 102 /* Set up the base timeout information. */
103 ep->timeouts[SCTP_EVENT_TIMEOUT_NONE] = 0; 103 ep->timeouts[SCTP_EVENT_TIMEOUT_NONE] = 0;
104 ep->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] = 104 ep->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] =
105 SCTP_DEFAULT_TIMEOUT_T1_COOKIE; 105 msecs_to_jiffies(sp->rtoinfo.srto_initial);
106 ep->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] = 106 ep->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] =
107 SCTP_DEFAULT_TIMEOUT_T1_INIT; 107 msecs_to_jiffies(sp->rtoinfo.srto_initial);
108 ep->timeouts[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN] = 108 ep->timeouts[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN] =
109 msecs_to_jiffies(sp->rtoinfo.srto_initial); 109 msecs_to_jiffies(sp->rtoinfo.srto_initial);
110 ep->timeouts[SCTP_EVENT_TIMEOUT_T3_RTX] = 0; 110 ep->timeouts[SCTP_EVENT_TIMEOUT_T3_RTX] = 0;
@@ -117,12 +117,9 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
117 ep->timeouts[SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD] 117 ep->timeouts[SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD]
118 = 5 * msecs_to_jiffies(sp->rtoinfo.srto_max); 118 = 5 * msecs_to_jiffies(sp->rtoinfo.srto_max);
119 119
120 ep->timeouts[SCTP_EVENT_TIMEOUT_HEARTBEAT] = 120 ep->timeouts[SCTP_EVENT_TIMEOUT_HEARTBEAT] = 0;
121 SCTP_DEFAULT_TIMEOUT_HEARTBEAT; 121 ep->timeouts[SCTP_EVENT_TIMEOUT_SACK] = sctp_sack_timeout;
122 ep->timeouts[SCTP_EVENT_TIMEOUT_SACK] = 122 ep->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE] = sp->autoclose * HZ;
123 SCTP_DEFAULT_TIMEOUT_SACK;
124 ep->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE] =
125 sp->autoclose * HZ;
126 123
127 /* Use SCTP specific send buffer space queues. */ 124 /* Use SCTP specific send buffer space queues. */
128 ep->sndbuf_policy = sctp_sndbuf_policy; 125 ep->sndbuf_policy = sctp_sndbuf_policy;
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 5135e1a25d25..e7f37faba7c0 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -1050,7 +1050,10 @@ SCTP_STATIC __init int sctp_init(void)
1050 sctp_sndbuf_policy = 0; 1050 sctp_sndbuf_policy = 0;
1051 1051
1052 /* HB.interval - 30 seconds */ 1052 /* HB.interval - 30 seconds */
1053 sctp_hb_interval = 30 * HZ; 1053 sctp_hb_interval = SCTP_DEFAULT_TIMEOUT_HEARTBEAT;
1054
1055 /* delayed SACK timeout */
1056 sctp_sack_timeout = SCTP_DEFAULT_TIMEOUT_SACK;
1054 1057
1055 /* Implementation specific variables. */ 1058 /* Implementation specific variables. */
1056 1059
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index 7fc31849312b..dc4893474f18 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -47,6 +47,8 @@
47static ctl_handler sctp_sysctl_jiffies_ms; 47static ctl_handler sctp_sysctl_jiffies_ms;
48static long rto_timer_min = 1; 48static long rto_timer_min = 1;
49static long rto_timer_max = 86400000; /* One day */ 49static long rto_timer_max = 86400000; /* One day */
50static long sack_timer_min = 1;
51static long sack_timer_max = 500;
50 52
51static ctl_table sctp_table[] = { 53static ctl_table sctp_table[] = {
52 { 54 {
@@ -187,6 +189,17 @@ static ctl_table sctp_table[] = {
187 .mode = 0644, 189 .mode = 0644,
188 .proc_handler = &proc_dointvec 190 .proc_handler = &proc_dointvec
189 }, 191 },
192 {
193 .ctl_name = NET_SCTP_SACK_TIMEOUT,
194 .procname = "sack_timeout",
195 .data = &sctp_sack_timeout,
196 .maxlen = sizeof(long),
197 .mode = 0644,
198 .proc_handler = &proc_doulongvec_ms_jiffies_minmax,
199 .strategy = &sctp_sysctl_jiffies_ms,
200 .extra1 = &sack_timer_min,
201 .extra2 = &sack_timer_max,
202 },
190 { .ctl_name = 0 } 203 { .ctl_name = 0 }
191}; 204};
192 205
diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index 0ec0fde6e6c5..a63b69179607 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -103,7 +103,6 @@ static struct sctp_transport *sctp_transport_init(struct sctp_transport *peer,
103 103
104 /* Set up the heartbeat timer. */ 104 /* Set up the heartbeat timer. */
105 init_timer(&peer->hb_timer); 105 init_timer(&peer->hb_timer);
106 peer->hb_interval = SCTP_DEFAULT_TIMEOUT_HEARTBEAT;
107 peer->hb_timer.function = sctp_generate_heartbeat_event; 106 peer->hb_timer.function = sctp_generate_heartbeat_event;
108 peer->hb_timer.data = (unsigned long)peer; 107 peer->hb_timer.data = (unsigned long)peer;
109 108
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 32197efe67ed..908bff6d1eef 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -287,6 +287,42 @@ static int do_pnp_card_entry(const char *filename,
287 return 1; 287 return 1;
288} 288}
289 289
290/* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */
291static int do_pcmcia_entry(const char *filename,
292 struct pcmcia_device_id *id, char *alias)
293{
294 unsigned int i;
295
296 id->manf_id = TO_NATIVE(id->manf_id);
297 id->card_id = TO_NATIVE(id->card_id);
298 id->func_id = TO_NATIVE(id->func_id);
299 id->function = TO_NATIVE(id->function);
300 id->device_no = TO_NATIVE(id->device_no);
301 for (i=0; i<4; i++) {
302 id->prod_id_hash[i] = TO_NATIVE(id->prod_id_hash[i]);
303 }
304
305 strcpy(alias, "pcmcia:");
306 ADD(alias, "m", id->match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID,
307 id->manf_id);
308 ADD(alias, "c", id->match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID,
309 id->card_id);
310 ADD(alias, "f", id->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID,
311 id->func_id);
312 ADD(alias, "fn", id->match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION,
313 id->function);
314 ADD(alias, "pfn", id->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO,
315 id->device_no);
316 ADD(alias, "pa", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1, id->prod_id_hash[0]);
317 ADD(alias, "pb", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2, id->prod_id_hash[1]);
318 ADD(alias, "pc", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3, id->prod_id_hash[2]);
319 ADD(alias, "pd", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4, id->prod_id_hash[3]);
320
321 return 1;
322}
323
324
325
290/* Ignore any prefix, eg. v850 prepends _ */ 326/* Ignore any prefix, eg. v850 prepends _ */
291static inline int sym_is(const char *symbol, const char *name) 327static inline int sym_is(const char *symbol, const char *name)
292{ 328{
@@ -362,6 +398,9 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
362 else if (sym_is(symname, "__mod_pnp_card_device_table")) 398 else if (sym_is(symname, "__mod_pnp_card_device_table"))
363 do_table(symval, sym->st_size, sizeof(struct pnp_card_device_id), 399 do_table(symval, sym->st_size, sizeof(struct pnp_card_device_id),
364 do_pnp_card_entry, mod); 400 do_pnp_card_entry, mod);
401 else if (sym_is(symname, "__mod_pcmcia_device_table"))
402 do_table(symval, sym->st_size, sizeof(struct pcmcia_device_id),
403 do_pcmcia_entry, mod);
365} 404}
366 405
367/* Now add out buffered information to the generated C source */ 406/* Now add out buffered information to the generated C source */
diff --git a/sound/oss/Kconfig b/sound/oss/Kconfig
index 3b1fafc8f4f5..7bd95ceab7cc 100644
--- a/sound/oss/Kconfig
+++ b/sound/oss/Kconfig
@@ -52,7 +52,7 @@ config SOUND_CMPCI_MIDI
52 52
53config SOUND_CMPCI_JOYSTICK 53config SOUND_CMPCI_JOYSTICK
54 bool "Enable joystick" 54 bool "Enable joystick"
55 depends on SOUND_CMPCI && X86 55 depends on SOUND_CMPCI && X86 && (GAMEPORT=y || SOUND_CMPCI=GAMEPORT)
56 help 56 help
57 Say Y here in order to enable the joystick port on a sound card using 57 Say Y here in order to enable the joystick port on a sound card using
58 the CMI8338 or the CMI8738 chipset. You need to config the 58 the CMI8338 or the CMI8738 chipset. You need to config the
diff --git a/sound/oss/dmasound/dmasound_awacs.c b/sound/oss/dmasound/dmasound_awacs.c
index 33108661e671..2704e1598add 100644
--- a/sound/oss/dmasound/dmasound_awacs.c
+++ b/sound/oss/dmasound/dmasound_awacs.c
@@ -255,7 +255,7 @@ static int awacs_burgundy_read_mvolume(unsigned address);
255 255
256static volatile struct dbdma_cmd *emergency_dbdma_cmd; 256static volatile struct dbdma_cmd *emergency_dbdma_cmd;
257 257
258#ifdef CONFIG_PMAC_PBOOK 258#ifdef CONFIG_PM
259/* 259/*
260 * Stuff for restoring after a sleep. 260 * Stuff for restoring after a sleep.
261 */ 261 */
@@ -263,7 +263,7 @@ static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when);
263struct pmu_sleep_notifier awacs_sleep_notifier = { 263struct pmu_sleep_notifier awacs_sleep_notifier = {
264 awacs_sleep_notify, SLEEP_LEVEL_SOUND, 264 awacs_sleep_notify, SLEEP_LEVEL_SOUND,
265}; 265};
266#endif /* CONFIG_PMAC_PBOOK */ 266#endif /* CONFIG_PM */
267 267
268/* for (soft) sample rate translations */ 268/* for (soft) sample rate translations */
269int expand_bal; /* Balance factor for expanding (not volume!) */ 269int expand_bal; /* Balance factor for expanding (not volume!) */
@@ -675,7 +675,7 @@ static void PMacIrqCleanup(void)
675 kfree(awacs_rx_cmd_space); 675 kfree(awacs_rx_cmd_space);
676 kfree(beep_dbdma_cmd_space); 676 kfree(beep_dbdma_cmd_space);
677 kfree(beep_buf); 677 kfree(beep_buf);
678#ifdef CONFIG_PMAC_PBOOK 678#ifdef CONFIG_PM
679 pmu_unregister_sleep_notifier(&awacs_sleep_notifier); 679 pmu_unregister_sleep_notifier(&awacs_sleep_notifier);
680#endif 680#endif
681} 681}
@@ -1415,7 +1415,7 @@ load_awacs(void)
1415 } 1415 }
1416} 1416}
1417 1417
1418#ifdef CONFIG_PMAC_PBOOK 1418#ifdef CONFIG_PM
1419/* 1419/*
1420 * Save state when going to sleep, restore it afterwards. 1420 * Save state when going to sleep, restore it afterwards.
1421 */ 1421 */
@@ -1551,7 +1551,7 @@ static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when)
1551 } 1551 }
1552 return PBOOK_SLEEP_OK; 1552 return PBOOK_SLEEP_OK;
1553} 1553}
1554#endif /* CONFIG_PMAC_PBOOK */ 1554#endif /* CONFIG_PM */
1555 1555
1556 1556
1557/* All the burgundy functions: */ 1557/* All the burgundy functions: */
@@ -3053,9 +3053,9 @@ printk("dmasound_pmac: Awacs/Screamer Codec Mfct: %d Rev %d\n", mfg, rev);
3053 if ((res=setup_beep())) 3053 if ((res=setup_beep()))
3054 return res ; 3054 return res ;
3055 3055
3056#ifdef CONFIG_PMAC_PBOOK 3056#ifdef CONFIG_PM
3057 pmu_register_sleep_notifier(&awacs_sleep_notifier); 3057 pmu_register_sleep_notifier(&awacs_sleep_notifier);
3058#endif /* CONFIG_PMAC_PBOOK */ 3058#endif /* CONFIG_PM */
3059 3059
3060 /* Powerbooks have odd ways of enabling inputs such as 3060 /* Powerbooks have odd ways of enabling inputs such as
3061 an expansion-bay CD or sound from an internal modem 3061 an expansion-bay CD or sound from an internal modem
diff --git a/sound/oss/es1370.c b/sound/oss/es1370.c
index 886f61c1c34a..8538085086e7 100644
--- a/sound/oss/es1370.c
+++ b/sound/oss/es1370.c
@@ -162,6 +162,10 @@
162#include <asm/page.h> 162#include <asm/page.h>
163#include <asm/uaccess.h> 163#include <asm/uaccess.h>
164 164
165#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
166#define SUPPORT_JOYSTICK
167#endif
168
165/* --------------------------------------------------------------------- */ 169/* --------------------------------------------------------------------- */
166 170
167#undef OSS_DOCUMENTED_MIXER_SEMANTICS 171#undef OSS_DOCUMENTED_MIXER_SEMANTICS
@@ -385,7 +389,10 @@ struct es1370_state {
385 unsigned char obuf[MIDIOUTBUF]; 389 unsigned char obuf[MIDIOUTBUF];
386 } midi; 390 } midi;
387 391
392#ifdef SUPPORT_JOYSTICK
388 struct gameport *gameport; 393 struct gameport *gameport;
394#endif
395
389 struct semaphore sem; 396 struct semaphore sem;
390}; 397};
391 398
@@ -2554,10 +2561,55 @@ static struct initvol {
2554 { SOUND_MIXER_WRITE_OGAIN, 0x4040 } 2561 { SOUND_MIXER_WRITE_OGAIN, 0x4040 }
2555}; 2562};
2556 2563
2564#ifdef SUPPORT_JOYSTICK
2565
2566static int __devinit es1370_register_gameport(struct es1370_state *s)
2567{
2568 struct gameport *gp;
2569
2570 if (!request_region(0x200, JOY_EXTENT, "es1370")) {
2571 printk(KERN_ERR "es1370: joystick io port 0x200 in use\n");
2572 return -EBUSY;
2573 }
2574
2575 s->gameport = gp = gameport_allocate_port();
2576 if (!gp) {
2577 printk(KERN_ERR "es1370: can not allocate memory for gameport\n");
2578 release_region(0x200, JOY_EXTENT);
2579 return -ENOMEM;
2580 }
2581
2582 gameport_set_name(gp, "ESS1370");
2583 gameport_set_phys(gp, "pci%s/gameport0", pci_name(s->dev));
2584 gp->dev.parent = &s->dev->dev;
2585 gp->io = 0x200;
2586
2587 s->ctrl |= CTRL_JYSTK_EN;
2588 outl(s->ctrl, s->io + ES1370_REG_CONTROL);
2589
2590 gameport_register_port(gp);
2591
2592 return 0;
2593}
2594
2595static inline void es1370_unregister_gameport(struct es1370_state *s)
2596{
2597 if (s->gameport) {
2598 int gpio = s->gameport->io;
2599 gameport_unregister_port(s->gameport);
2600 release_region(gpio, JOY_EXTENT);
2601
2602 }
2603}
2604
2605#else
2606static inline int es1370_register_gameport(struct es1370_state *s) { return -ENOSYS; }
2607static inline void es1370_unregister_gameport(struct es1370_state *s) { }
2608#endif /* SUPPORT_JOYSTICK */
2609
2557static int __devinit es1370_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid) 2610static int __devinit es1370_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
2558{ 2611{
2559 struct es1370_state *s; 2612 struct es1370_state *s;
2560 struct gameport *gp = NULL;
2561 mm_segment_t fs; 2613 mm_segment_t fs;
2562 int i, val, ret; 2614 int i, val, ret;
2563 2615
@@ -2606,28 +2658,14 @@ static int __devinit es1370_probe(struct pci_dev *pcidev, const struct pci_devic
2606 /* note: setting CTRL_SERR_DIS is reported to break 2658 /* note: setting CTRL_SERR_DIS is reported to break
2607 * mic bias setting (by Kim.Berts@fisub.mail.abb.com) */ 2659 * mic bias setting (by Kim.Berts@fisub.mail.abb.com) */
2608 s->ctrl = CTRL_CDC_EN | (DAC2_SRTODIV(8000) << CTRL_SH_PCLKDIV) | (1 << CTRL_SH_WTSRSEL); 2660 s->ctrl = CTRL_CDC_EN | (DAC2_SRTODIV(8000) << CTRL_SH_PCLKDIV) | (1 << CTRL_SH_WTSRSEL);
2609 if (!request_region(0x200, JOY_EXTENT, "es1370")) {
2610 printk(KERN_ERR "es1370: joystick io port 0x200 in use\n");
2611 } else if (!(s->gameport = gp = gameport_allocate_port())) {
2612 printk(KERN_ERR "es1370: can not allocate memory for gameport\n");
2613 release_region(0x200, JOY_EXTENT);
2614 } else {
2615 gameport_set_name(gp, "ESS1370");
2616 gameport_set_phys(gp, "pci%s/gameport0", pci_name(s->dev));
2617 gp->dev.parent = &s->dev->dev;
2618 gp->io = 0x200;
2619 s->ctrl |= CTRL_JYSTK_EN;
2620 }
2621 if (lineout[devindex]) 2661 if (lineout[devindex])
2622 s->ctrl |= CTRL_XCTL0; 2662 s->ctrl |= CTRL_XCTL0;
2623 if (micbias[devindex]) 2663 if (micbias[devindex])
2624 s->ctrl |= CTRL_XCTL1; 2664 s->ctrl |= CTRL_XCTL1;
2625 s->sctrl = 0; 2665 s->sctrl = 0;
2626 printk(KERN_INFO "es1370: found adapter at io %#lx irq %u\n" 2666 printk(KERN_INFO "es1370: adapter at io %#lx irq %u, line %s, mic impedance %s\n",
2627 KERN_INFO "es1370: features: joystick %s, line %s, mic impedance %s\n", 2667 s->io, s->irq, (s->ctrl & CTRL_XCTL0) ? "out" : "in",
2628 s->io, s->irq, (s->ctrl & CTRL_JYSTK_EN) ? "on" : "off", 2668 (s->ctrl & CTRL_XCTL1) ? "1" : "0");
2629 (s->ctrl & CTRL_XCTL0) ? "out" : "in",
2630 (s->ctrl & CTRL_XCTL1) ? "1" : "0");
2631 /* register devices */ 2669 /* register devices */
2632 if ((s->dev_audio = register_sound_dsp(&es1370_audio_fops, -1)) < 0) { 2670 if ((s->dev_audio = register_sound_dsp(&es1370_audio_fops, -1)) < 0) {
2633 ret = s->dev_audio; 2671 ret = s->dev_audio;
@@ -2673,9 +2711,7 @@ static int __devinit es1370_probe(struct pci_dev *pcidev, const struct pci_devic
2673 } 2711 }
2674 set_fs(fs); 2712 set_fs(fs);
2675 2713
2676 /* register gameport */ 2714 es1370_register_gameport(s);
2677 if (gp)
2678 gameport_register_port(gp);
2679 2715
2680 /* store it in the driver field */ 2716 /* store it in the driver field */
2681 pci_set_drvdata(pcidev, s); 2717 pci_set_drvdata(pcidev, s);
@@ -2697,10 +2733,6 @@ static int __devinit es1370_probe(struct pci_dev *pcidev, const struct pci_devic
2697 err_dev1: 2733 err_dev1:
2698 printk(KERN_ERR "es1370: cannot register misc device\n"); 2734 printk(KERN_ERR "es1370: cannot register misc device\n");
2699 free_irq(s->irq, s); 2735 free_irq(s->irq, s);
2700 if (s->gameport) {
2701 release_region(s->gameport->io, JOY_EXTENT);
2702 gameport_free_port(s->gameport);
2703 }
2704 err_irq: 2736 err_irq:
2705 release_region(s->io, ES1370_EXTENT); 2737 release_region(s->io, ES1370_EXTENT);
2706 err_region: 2738 err_region:
@@ -2719,11 +2751,7 @@ static void __devexit es1370_remove(struct pci_dev *dev)
2719 outl(0, s->io+ES1370_REG_SERIAL_CONTROL); /* clear serial interrupts */ 2751 outl(0, s->io+ES1370_REG_SERIAL_CONTROL); /* clear serial interrupts */
2720 synchronize_irq(s->irq); 2752 synchronize_irq(s->irq);
2721 free_irq(s->irq, s); 2753 free_irq(s->irq, s);
2722 if (s->gameport) { 2754 es1370_unregister_gameport(s);
2723 int gpio = s->gameport->io;
2724 gameport_unregister_port(s->gameport);
2725 release_region(gpio, JOY_EXTENT);
2726 }
2727 release_region(s->io, ES1370_EXTENT); 2755 release_region(s->io, ES1370_EXTENT);
2728 unregister_sound_dsp(s->dev_audio); 2756 unregister_sound_dsp(s->dev_audio);
2729 unregister_sound_mixer(s->dev_mixer); 2757 unregister_sound_mixer(s->dev_mixer);
diff --git a/sound/oss/es1371.c b/sound/oss/es1371.c
index 9266b777387b..12a56d5ab498 100644
--- a/sound/oss/es1371.c
+++ b/sound/oss/es1371.c
@@ -134,6 +134,10 @@
134#include <asm/page.h> 134#include <asm/page.h>
135#include <asm/uaccess.h> 135#include <asm/uaccess.h>
136 136
137#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
138#define SUPPORT_JOYSTICK
139#endif
140
137/* --------------------------------------------------------------------- */ 141/* --------------------------------------------------------------------- */
138 142
139#undef OSS_DOCUMENTED_MIXER_SEMANTICS 143#undef OSS_DOCUMENTED_MIXER_SEMANTICS
@@ -454,7 +458,10 @@ struct es1371_state {
454 unsigned char obuf[MIDIOUTBUF]; 458 unsigned char obuf[MIDIOUTBUF];
455 } midi; 459 } midi;
456 460
461#ifdef SUPPORT_JOYSTICK
457 struct gameport *gameport; 462 struct gameport *gameport;
463#endif
464
458 struct semaphore sem; 465 struct semaphore sem;
459}; 466};
460 467
@@ -2787,12 +2794,63 @@ static struct
2787 { PCI_ANY_ID, PCI_ANY_ID } 2794 { PCI_ANY_ID, PCI_ANY_ID }
2788}; 2795};
2789 2796
2797#ifdef SUPPORT_JOYSTICK
2798
2799static int __devinit es1371_register_gameport(struct es1371_state *s)
2800{
2801 struct gameport *gp;
2802 int gpio;
2803
2804 for (gpio = 0x218; gpio >= 0x200; gpio -= 0x08)
2805 if (request_region(gpio, JOY_EXTENT, "es1371"))
2806 break;
2807
2808 if (gpio < 0x200) {
2809 printk(KERN_ERR PFX "no free joystick address found\n");
2810 return -EBUSY;
2811 }
2812
2813 s->gameport = gp = gameport_allocate_port();
2814 if (!gp) {
2815 printk(KERN_ERR PFX "can not allocate memory for gameport\n");
2816 release_region(gpio, JOY_EXTENT);
2817 return -ENOMEM;
2818 }
2819
2820 gameport_set_name(gp, "ESS1371 Gameport");
2821 gameport_set_phys(gp, "isa%04x/gameport0", gpio);
2822 gp->dev.parent = &s->dev->dev;
2823 gp->io = gpio;
2824
2825 s->ctrl |= CTRL_JYSTK_EN | (((gpio >> 3) & CTRL_JOY_MASK) << CTRL_JOY_SHIFT);
2826 outl(s->ctrl, s->io + ES1371_REG_CONTROL);
2827
2828 gameport_register_port(gp);
2829
2830 return 0;
2831}
2832
2833static inline void es1371_unregister_gameport(struct es1371_state *s)
2834{
2835 if (s->gameport) {
2836 int gpio = s->gameport->io;
2837 gameport_unregister_port(s->gameport);
2838 release_region(gpio, JOY_EXTENT);
2839
2840 }
2841}
2842
2843#else
2844static inline int es1371_register_gameport(struct es1371_state *s) { return -ENOSYS; }
2845static inline void es1371_unregister_gameport(struct es1371_state *s) { }
2846#endif /* SUPPORT_JOYSTICK */
2847
2848
2790static int __devinit es1371_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid) 2849static int __devinit es1371_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
2791{ 2850{
2792 struct es1371_state *s; 2851 struct es1371_state *s;
2793 struct gameport *gp;
2794 mm_segment_t fs; 2852 mm_segment_t fs;
2795 int i, gpio, val, res = -1; 2853 int i, val, res = -1;
2796 int idx; 2854 int idx;
2797 unsigned long tmo; 2855 unsigned long tmo;
2798 signed long tmo2; 2856 signed long tmo2;
@@ -2883,23 +2941,6 @@ static int __devinit es1371_probe(struct pci_dev *pcidev, const struct pci_devic
2883 } 2941 }
2884 } 2942 }
2885 2943
2886 for (gpio = 0x218; gpio >= 0x200; gpio -= 0x08)
2887 if (request_region(gpio, JOY_EXTENT, "es1371"))
2888 break;
2889
2890 if (gpio < 0x200) {
2891 printk(KERN_ERR PFX "no free joystick address found\n");
2892 } else if (!(s->gameport = gp = gameport_allocate_port())) {
2893 printk(KERN_ERR PFX "can not allocate memory for gameport\n");
2894 release_region(gpio, JOY_EXTENT);
2895 } else {
2896 gameport_set_name(gp, "ESS1371 Gameport");
2897 gameport_set_phys(gp, "isa%04x/gameport0", gpio);
2898 gp->dev.parent = &s->dev->dev;
2899 gp->io = gpio;
2900 s->ctrl |= CTRL_JYSTK_EN | (((gpio >> 3) & CTRL_JOY_MASK) << CTRL_JOY_SHIFT);
2901 }
2902
2903 s->sctrl = 0; 2944 s->sctrl = 0;
2904 cssr = 0; 2945 cssr = 0;
2905 s->spdif_volume = -1; 2946 s->spdif_volume = -1;
@@ -2969,9 +3010,7 @@ static int __devinit es1371_probe(struct pci_dev *pcidev, const struct pci_devic
2969 /* turn on S/PDIF output driver if requested */ 3010 /* turn on S/PDIF output driver if requested */
2970 outl(cssr, s->io+ES1371_REG_STATUS); 3011 outl(cssr, s->io+ES1371_REG_STATUS);
2971 3012
2972 /* register gameport */ 3013 es1371_register_gameport(s);
2973 if (s->gameport)
2974 gameport_register_port(s->gameport);
2975 3014
2976 /* store it in the driver field */ 3015 /* store it in the driver field */
2977 pci_set_drvdata(pcidev, s); 3016 pci_set_drvdata(pcidev, s);
@@ -2980,13 +3019,9 @@ static int __devinit es1371_probe(struct pci_dev *pcidev, const struct pci_devic
2980 /* increment devindex */ 3019 /* increment devindex */
2981 if (devindex < NR_DEVICE-1) 3020 if (devindex < NR_DEVICE-1)
2982 devindex++; 3021 devindex++;
2983 return 0; 3022 return 0;
2984 3023
2985 err_gp: 3024 err_gp:
2986 if (s->gameport) {
2987 release_region(s->gameport->io, JOY_EXTENT);
2988 gameport_free_port(s->gameport);
2989 }
2990#ifdef ES1371_DEBUG 3025#ifdef ES1371_DEBUG
2991 if (s->ps) 3026 if (s->ps)
2992 remove_proc_entry("es1371", NULL); 3027 remove_proc_entry("es1371", NULL);
@@ -3025,11 +3060,7 @@ static void __devexit es1371_remove(struct pci_dev *dev)
3025 outl(0, s->io+ES1371_REG_SERIAL_CONTROL); /* clear serial interrupts */ 3060 outl(0, s->io+ES1371_REG_SERIAL_CONTROL); /* clear serial interrupts */
3026 synchronize_irq(s->irq); 3061 synchronize_irq(s->irq);
3027 free_irq(s->irq, s); 3062 free_irq(s->irq, s);
3028 if (s->gameport) { 3063 es1371_unregister_gameport(s);
3029 int gpio = s->gameport->io;
3030 gameport_unregister_port(s->gameport);
3031 release_region(gpio, JOY_EXTENT);
3032 }
3033 release_region(s->io, ES1371_EXTENT); 3064 release_region(s->io, ES1371_EXTENT);
3034 unregister_sound_dsp(s->dev_audio); 3065 unregister_sound_dsp(s->dev_audio);
3035 unregister_sound_mixer(s->codec->dev_mixer); 3066 unregister_sound_mixer(s->codec->dev_mixer);
diff --git a/sound/oss/esssolo1.c b/sound/oss/esssolo1.c
index fb09065d07c8..a4ecab2f0522 100644
--- a/sound/oss/esssolo1.c
+++ b/sound/oss/esssolo1.c
@@ -150,6 +150,10 @@
150 150
151#define FMODE_DMFM 0x10 151#define FMODE_DMFM 0x10
152 152
153#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
154#define SUPPORT_JOYSTICK 1
155#endif
156
153static struct pci_driver solo1_driver; 157static struct pci_driver solo1_driver;
154 158
155/* --------------------------------------------------------------------- */ 159/* --------------------------------------------------------------------- */
@@ -227,7 +231,9 @@ struct solo1_state {
227 unsigned char obuf[MIDIOUTBUF]; 231 unsigned char obuf[MIDIOUTBUF];
228 } midi; 232 } midi;
229 233
234#if SUPPORT_JOYSTICK
230 struct gameport *gameport; 235 struct gameport *gameport;
236#endif
231}; 237};
232 238
233/* --------------------------------------------------------------------- */ 239/* --------------------------------------------------------------------- */
@@ -2281,6 +2287,7 @@ solo1_resume(struct pci_dev *pci_dev) {
2281 return 0; 2287 return 0;
2282} 2288}
2283 2289
2290#ifdef SUPPORT_JOYSTICK
2284static int __devinit solo1_register_gameport(struct solo1_state *s, int io_port) 2291static int __devinit solo1_register_gameport(struct solo1_state *s, int io_port)
2285{ 2292{
2286 struct gameport *gp; 2293 struct gameport *gp;
@@ -2307,6 +2314,19 @@ static int __devinit solo1_register_gameport(struct solo1_state *s, int io_port)
2307 return 0; 2314 return 0;
2308} 2315}
2309 2316
2317static inline void solo1_unregister_gameport(struct solo1_state *s)
2318{
2319 if (s->gameport) {
2320 int gpio = s->gameport->io;
2321 gameport_unregister_port(s->gameport);
2322 release_region(gpio, GAMEPORT_EXTENT);
2323 }
2324}
2325#else
2326static inline int solo1_register_gameport(struct solo1_state *s, int io_port) { return -ENOSYS; }
2327static inline void solo1_unregister_gameport(struct solo1_state *s) { }
2328#endif /* SUPPORT_JOYSTICK */
2329
2310static int __devinit solo1_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid) 2330static int __devinit solo1_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
2311{ 2331{
2312 struct solo1_state *s; 2332 struct solo1_state *s;
@@ -2438,11 +2458,7 @@ static void __devexit solo1_remove(struct pci_dev *dev)
2438 synchronize_irq(s->irq); 2458 synchronize_irq(s->irq);
2439 pci_write_config_word(s->dev, 0x60, 0); /* turn off DDMA controller address space */ 2459 pci_write_config_word(s->dev, 0x60, 0); /* turn off DDMA controller address space */
2440 free_irq(s->irq, s); 2460 free_irq(s->irq, s);
2441 if (s->gameport) { 2461 solo1_unregister_gameport(s);
2442 int gpio = s->gameport->io;
2443 gameport_unregister_port(s->gameport);
2444 release_region(gpio, GAMEPORT_EXTENT);
2445 }
2446 release_region(s->iobase, IOBASE_EXTENT); 2462 release_region(s->iobase, IOBASE_EXTENT);
2447 release_region(s->sbbase+FMSYNTH_EXTENT, SBBASE_EXTENT-FMSYNTH_EXTENT); 2463 release_region(s->sbbase+FMSYNTH_EXTENT, SBBASE_EXTENT-FMSYNTH_EXTENT);
2448 release_region(s->ddmabase, DDMABASE_EXTENT); 2464 release_region(s->ddmabase, DDMABASE_EXTENT);
diff --git a/sound/oss/mad16.c b/sound/oss/mad16.c
index a7067f169919..aa3c50db66c4 100644
--- a/sound/oss/mad16.c
+++ b/sound/oss/mad16.c
@@ -50,9 +50,12 @@
50#include "sb.h" 50#include "sb.h"
51#include "mpu401.h" 51#include "mpu401.h"
52 52
53#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
54#define SUPPORT_JOYSTICK 1
55#endif
56
53static int mad16_conf; 57static int mad16_conf;
54static int mad16_cdsel; 58static int mad16_cdsel;
55static struct gameport *gameport;
56static DEFINE_SPINLOCK(lock); 59static DEFINE_SPINLOCK(lock);
57 60
58#define C928 1 61#define C928 1
@@ -902,6 +905,10 @@ static int __initdata irq_map[16] =
902 -1, -1, -1, -1 905 -1, -1, -1, -1
903}; 906};
904 907
908#ifdef SUPPORT_JOYSTICK
909
910static struct gameport *gameport;
911
905static int __devinit mad16_register_gameport(int io_port) 912static int __devinit mad16_register_gameport(int io_port)
906{ 913{
907 if (!request_region(io_port, 1, "mad16 gameport")) { 914 if (!request_region(io_port, 1, "mad16 gameport")) {
@@ -925,6 +932,20 @@ static int __devinit mad16_register_gameport(int io_port)
925 return 0; 932 return 0;
926} 933}
927 934
935static inline void mad16_unregister_gameport(void)
936{
937 if (gameport) {
938 /* the gameport was initialized so we must free it up */
939 gameport_unregister_port(gameport);
940 gameport = NULL;
941 release_region(0x201, 1);
942 }
943}
944#else
945static inline int mad16_register_gameport(int io_port) { return -ENOSYS; }
946static inline void mad16_unregister_gameport(void) { }
947#endif
948
928static int __devinit init_mad16(void) 949static int __devinit init_mad16(void)
929{ 950{
930 int dmatype = 0; 951 int dmatype = 0;
@@ -1060,12 +1081,7 @@ static void __exit cleanup_mad16(void)
1060{ 1081{
1061 if (found_mpu) 1082 if (found_mpu)
1062 unload_mad16_mpu(&cfg_mpu); 1083 unload_mad16_mpu(&cfg_mpu);
1063 if (gameport) { 1084 mad16_unregister_gameport();
1064 /* the gameport was initialized so we must free it up */
1065 gameport_unregister_port(gameport);
1066 gameport = NULL;
1067 release_region(0x201, 1);
1068 }
1069 unload_mad16(&cfg); 1085 unload_mad16(&cfg);
1070 release_region(MC0_PORT, 12); 1086 release_region(MC0_PORT, 12);
1071} 1087}
diff --git a/sound/oss/sonicvibes.c b/sound/oss/sonicvibes.c
index 06047e7979af..17d0e461f8d8 100644
--- a/sound/oss/sonicvibes.c
+++ b/sound/oss/sonicvibes.c
@@ -122,6 +122,9 @@
122 122
123#include "dm.h" 123#include "dm.h"
124 124
125#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
126#define SUPPORT_JOYSTICK 1
127#endif
125 128
126/* --------------------------------------------------------------------- */ 129/* --------------------------------------------------------------------- */
127 130
@@ -365,7 +368,9 @@ struct sv_state {
365 unsigned char obuf[MIDIOUTBUF]; 368 unsigned char obuf[MIDIOUTBUF];
366 } midi; 369 } midi;
367 370
371#if SUPPORT_JOYSTICK
368 struct gameport *gameport; 372 struct gameport *gameport;
373#endif
369}; 374};
370 375
371/* --------------------------------------------------------------------- */ 376/* --------------------------------------------------------------------- */
@@ -2485,6 +2490,7 @@ static struct initvol {
2485#define RSRCISIOREGION(dev,num) (pci_resource_start((dev), (num)) != 0 && \ 2490#define RSRCISIOREGION(dev,num) (pci_resource_start((dev), (num)) != 0 && \
2486 (pci_resource_flags((dev), (num)) & IORESOURCE_IO)) 2491 (pci_resource_flags((dev), (num)) & IORESOURCE_IO))
2487 2492
2493#ifdef SUPPORT_JOYSTICK
2488static int __devinit sv_register_gameport(struct sv_state *s, int io_port) 2494static int __devinit sv_register_gameport(struct sv_state *s, int io_port)
2489{ 2495{
2490 struct gameport *gp; 2496 struct gameport *gp;
@@ -2511,6 +2517,19 @@ static int __devinit sv_register_gameport(struct sv_state *s, int io_port)
2511 return 0; 2517 return 0;
2512} 2518}
2513 2519
2520static inline void sv_unregister_gameport(struct sv_state *s)
2521{
2522 if (s->gameport) {
2523 int gpio = s->gameport->io;
2524 gameport_unregister_port(s->gameport);
2525 release_region(gpio, SV_EXTENT_GAME);
2526 }
2527}
2528#else
2529static inline int sv_register_gameport(struct sv_state *s, int io_port) { return -ENOSYS; }
2530static inline void sv_unregister_gameport(struct sv_state *s) { }
2531#endif /* SUPPORT_JOYSTICK */
2532
2514static int __devinit sv_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid) 2533static int __devinit sv_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
2515{ 2534{
2516 static char __devinitdata sv_ddma_name[] = "S3 Inc. SonicVibes DDMA Controller"; 2535 static char __devinitdata sv_ddma_name[] = "S3 Inc. SonicVibes DDMA Controller";
@@ -2711,11 +2730,7 @@ static void __devexit sv_remove(struct pci_dev *dev)
2711 /*outb(0, s->iodmaa + SV_DMA_RESET);*/ 2730 /*outb(0, s->iodmaa + SV_DMA_RESET);*/
2712 /*outb(0, s->iodmac + SV_DMA_RESET);*/ 2731 /*outb(0, s->iodmac + SV_DMA_RESET);*/
2713 free_irq(s->irq, s); 2732 free_irq(s->irq, s);
2714 if (s->gameport) { 2733 sv_unregister_gameport(s);
2715 int gpio = s->gameport->io;
2716 gameport_unregister_port(s->gameport);
2717 release_region(gpio, SV_EXTENT_GAME);
2718 }
2719 release_region(s->iodmac, SV_EXTENT_DMA); 2734 release_region(s->iodmac, SV_EXTENT_DMA);
2720 release_region(s->iodmaa, SV_EXTENT_DMA); 2735 release_region(s->iodmaa, SV_EXTENT_DMA);
2721 release_region(s->ioenh, SV_EXTENT_ENH); 2736 release_region(s->ioenh, SV_EXTENT_ENH);
diff --git a/sound/oss/trident.c b/sound/oss/trident.c
index 47537f0a5b05..5f0ad6bb43b9 100644
--- a/sound/oss/trident.c
+++ b/sound/oss/trident.c
@@ -228,6 +228,10 @@
228 228
229#define DRIVER_VERSION "0.14.10j-2.6" 229#define DRIVER_VERSION "0.14.10j-2.6"
230 230
231#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
232#define SUPPORT_JOYSTICK 1
233#endif
234
231/* magic numbers to protect our data structures */ 235/* magic numbers to protect our data structures */
232#define TRIDENT_CARD_MAGIC 0x5072696E /* "Prin" */ 236#define TRIDENT_CARD_MAGIC 0x5072696E /* "Prin" */
233#define TRIDENT_STATE_MAGIC 0x63657373 /* "cess" */ 237#define TRIDENT_STATE_MAGIC 0x63657373 /* "cess" */
@@ -4252,24 +4256,25 @@ trident_ac97_init(struct trident_card *card)
4252 return num_ac97 + 1; 4256 return num_ac97 + 1;
4253} 4257}
4254 4258
4259#ifdef SUPPORT_JOYSTICK
4255/* Gameport functions for the cards ADC gameport */ 4260/* Gameport functions for the cards ADC gameport */
4256 4261
4257static unsigned char 4262static unsigned char trident_game_read(struct gameport *gameport)
4258trident_game_read(struct gameport *gameport)
4259{ 4263{
4260 struct trident_card *card = gameport->port_data; 4264 struct trident_card *card = gameport->port_data;
4265
4261 return inb(TRID_REG(card, T4D_GAME_LEG)); 4266 return inb(TRID_REG(card, T4D_GAME_LEG));
4262} 4267}
4263 4268
4264static void 4269static void trident_game_trigger(struct gameport *gameport)
4265trident_game_trigger(struct gameport *gameport)
4266{ 4270{
4267 struct trident_card *card = gameport->port_data; 4271 struct trident_card *card = gameport->port_data;
4272
4268 outb(0xff, TRID_REG(card, T4D_GAME_LEG)); 4273 outb(0xff, TRID_REG(card, T4D_GAME_LEG));
4269} 4274}
4270 4275
4271static int 4276static int trident_game_cooked_read(struct gameport *gameport,
4272trident_game_cooked_read(struct gameport *gameport, int *axes, int *buttons) 4277 int *axes, int *buttons)
4273{ 4278{
4274 struct trident_card *card = gameport->port_data; 4279 struct trident_card *card = gameport->port_data;
4275 int i; 4280 int i;
@@ -4285,8 +4290,7 @@ trident_game_cooked_read(struct gameport *gameport, int *axes, int *buttons)
4285 return 0; 4290 return 0;
4286} 4291}
4287 4292
4288static int 4293static int trident_game_open(struct gameport *gameport, int mode)
4289trident_game_open(struct gameport *gameport, int mode)
4290{ 4294{
4291 struct trident_card *card = gameport->port_data; 4295 struct trident_card *card = gameport->port_data;
4292 4296
@@ -4305,8 +4309,7 @@ trident_game_open(struct gameport *gameport, int mode)
4305 return 0; 4309 return 0;
4306} 4310}
4307 4311
4308static int __devinit 4312static int __devinit trident_register_gameport(struct trident_card *card)
4309trident_register_gameport(struct trident_card *card)
4310{ 4313{
4311 struct gameport *gp; 4314 struct gameport *gp;
4312 4315
@@ -4330,6 +4333,17 @@ trident_register_gameport(struct trident_card *card)
4330 return 0; 4333 return 0;
4331} 4334}
4332 4335
4336static inline void trident_unregister_gameport(struct trident_card *card)
4337{
4338 if (card->gameport)
4339 gameport_unregister_port(card->gameport);
4340}
4341
4342#else
4343static inline int trident_register_gameport(struct trident_card *card) { return -ENOSYS; }
4344static inline void trident_unregister_gameport(struct trident_card *card) { }
4345#endif /* SUPPORT_JOYSTICK */
4346
4333/* install the driver, we do not allocate hardware channel nor DMA buffer */ 4347/* install the driver, we do not allocate hardware channel nor DMA buffer */
4334/* now, they are defered until "ACCESS" time (in prog_dmabuf called by */ 4348/* now, they are defered until "ACCESS" time (in prog_dmabuf called by */
4335/* open/read/write/ioctl/mmap) */ 4349/* open/read/write/ioctl/mmap) */
@@ -4569,8 +4583,7 @@ trident_remove(struct pci_dev *pci_dev)
4569 } 4583 }
4570 4584
4571 /* Unregister gameport */ 4585 /* Unregister gameport */
4572 if (card->gameport) 4586 trident_unregister_gameport(card);
4573 gameport_unregister_port(card->gameport);
4574 4587
4575 /* Kill interrupts, and SP/DIF */ 4588 /* Kill interrupts, and SP/DIF */
4576 trident_disable_loop_interrupts(card); 4589 trident_disable_loop_interrupts(card);
diff --git a/sound/oss/via82cxxx_audio.c b/sound/oss/via82cxxx_audio.c
index b387e1e52485..83edda93f0b4 100644
--- a/sound/oss/via82cxxx_audio.c
+++ b/sound/oss/via82cxxx_audio.c
@@ -35,6 +35,7 @@
35#include <linux/smp_lock.h> 35#include <linux/smp_lock.h>
36#include <linux/ioport.h> 36#include <linux/ioport.h>
37#include <linux/delay.h> 37#include <linux/delay.h>
38#include <linux/dma-mapping.h>
38#include <asm/io.h> 39#include <asm/io.h>
39#include <asm/uaccess.h> 40#include <asm/uaccess.h>
40#include <asm/semaphore.h> 41#include <asm/semaphore.h>
@@ -3391,10 +3392,10 @@ static int __devinit via_init_one (struct pci_dev *pdev, const struct pci_device
3391 if (rc) 3392 if (rc)
3392 goto err_out_disable; 3393 goto err_out_disable;
3393 3394
3394 rc = pci_set_dma_mask(pdev, 0xffffffffULL); 3395 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
3395 if (rc) 3396 if (rc)
3396 goto err_out_res; 3397 goto err_out_res;
3397 rc = pci_set_consistent_dma_mask(pdev, 0xffffffffULL); 3398 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
3398 if (rc) 3399 if (rc)
3399 goto err_out_res; 3400 goto err_out_res;
3400 3401
diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c
index b6e1854e9389..eb3c52b03af3 100644
--- a/sound/pci/cs4281.c
+++ b/sound/pci/cs4281.c
@@ -1338,11 +1338,6 @@ static inline int snd_cs4281_create_gameport(cs4281_t *chip) { return -ENOSYS; }
1338static inline void snd_cs4281_free_gameport(cs4281_t *chip) { } 1338static inline void snd_cs4281_free_gameport(cs4281_t *chip) { }
1339#endif /* CONFIG_GAMEPORT || (MODULE && CONFIG_GAMEPORT_MODULE) */ 1339#endif /* CONFIG_GAMEPORT || (MODULE && CONFIG_GAMEPORT_MODULE) */
1340 1340
1341
1342/*
1343
1344 */
1345
1346static int snd_cs4281_free(cs4281_t *chip) 1341static int snd_cs4281_free(cs4281_t *chip)
1347{ 1342{
1348 snd_cs4281_free_gameport(chip); 1343 snd_cs4281_free_gameport(chip);
diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf.c b/sound/pcmcia/pdaudiocf/pdaudiocf.c
index f72c81cc9952..2d4f8e28478b 100644
--- a/sound/pcmcia/pdaudiocf/pdaudiocf.c
+++ b/sound/pcmcia/pdaudiocf/pdaudiocf.c
@@ -380,13 +380,20 @@ static int pdacf_event(event_t event, int priority, event_callback_args_t *args)
380/* 380/*
381 * Module entry points 381 * Module entry points
382 */ 382 */
383static struct pcmcia_device_id snd_pdacf_ids[] = {
384 PCMCIA_DEVICE_MANF_CARD(0x015d, 0x4c45),
385 PCMCIA_DEVICE_NULL
386};
387MODULE_DEVICE_TABLE(pcmcia, snd_pdacf_ids);
388
383static struct pcmcia_driver pdacf_cs_driver = { 389static struct pcmcia_driver pdacf_cs_driver = {
384 .owner = THIS_MODULE, 390 .owner = THIS_MODULE,
385 .drv = { 391 .drv = {
386 .name = "snd-pdaudiocf", 392 .name = "snd-pdaudiocf",
387 }, 393 },
388 .attach = snd_pdacf_attach, 394 .attach = snd_pdacf_attach,
389 .detach = snd_pdacf_detach 395 .detach = snd_pdacf_detach,
396 .id_table = snd_pdacf_ids,
390}; 397};
391 398
392static int __init init_pdacf(void) 399static int __init init_pdacf(void)
diff --git a/sound/pcmcia/vx/vxpocket.c b/sound/pcmcia/vx/vxpocket.c
index fce2ad04fd8b..5f4c13264159 100644
--- a/sound/pcmcia/vx/vxpocket.c
+++ b/sound/pcmcia/vx/vxpocket.c
@@ -18,17 +18,6 @@
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20 20
21/*
22 please add the following as /etc/pcmcia/vxpocket.conf:
23
24 device "snd-vxpocket"
25 class "audio" module "snd-vxpocket"
26
27 card "Digigram VX-POCKET"
28 manfid 0x01f1, 0x0100
29 bind "snd-vxpocket"
30
31 */
32 21
33#include <sound/driver.h> 22#include <sound/driver.h>
34#include <linux/init.h> 23#include <linux/init.h>
@@ -140,13 +129,20 @@ static void vxp_detach(dev_link_t *link)
140 * Module entry points 129 * Module entry points
141 */ 130 */
142 131
132static struct pcmcia_device_id vxp_ids[] = {
133 PCMCIA_DEVICE_MANF_CARD(0x01f1, 0x0100),
134 PCMCIA_DEVICE_NULL
135};
136MODULE_DEVICE_TABLE(pcmcia, vxp_ids);
137
143static struct pcmcia_driver vxp_cs_driver = { 138static struct pcmcia_driver vxp_cs_driver = {
144 .owner = THIS_MODULE, 139 .owner = THIS_MODULE,
145 .drv = { 140 .drv = {
146 .name = DEV_INFO, 141 .name = DEV_INFO,
147 }, 142 },
148 .attach = vxp_attach, 143 .attach = vxp_attach,
149 .detach = vxp_detach 144 .detach = vxp_detach,
145 .id_table = vxp_ids,
150}; 146};
151 147
152static int __init init_vxpocket(void) 148static int __init init_vxpocket(void)
diff --git a/sound/ppc/awacs.c b/sound/ppc/awacs.c
index e052bd071e5b..061e52d3d771 100644
--- a/sound/ppc/awacs.c
+++ b/sound/ppc/awacs.c
@@ -90,7 +90,7 @@ snd_pmac_awacs_write_noreg(pmac_t *chip, int reg, int val)
90 snd_pmac_awacs_write(chip, val | (reg << 12)); 90 snd_pmac_awacs_write(chip, val | (reg << 12));
91} 91}
92 92
93#ifdef CONFIG_PMAC_PBOOK 93#ifdef CONFIG_PM
94/* Recalibrate chip */ 94/* Recalibrate chip */
95static void screamer_recalibrate(pmac_t *chip) 95static void screamer_recalibrate(pmac_t *chip)
96{ 96{
@@ -642,7 +642,7 @@ static void awacs_restore_all_regs(pmac_t *chip)
642 } 642 }
643} 643}
644 644
645#ifdef CONFIG_PMAC_PBOOK 645#ifdef CONFIG_PM
646static void snd_pmac_awacs_suspend(pmac_t *chip) 646static void snd_pmac_awacs_suspend(pmac_t *chip)
647{ 647{
648 snd_pmac_awacs_write_noreg(chip, 1, (chip->awacs_reg[1] 648 snd_pmac_awacs_write_noreg(chip, 1, (chip->awacs_reg[1]
@@ -676,7 +676,7 @@ static void snd_pmac_awacs_resume(pmac_t *chip)
676 } 676 }
677#endif 677#endif
678} 678}
679#endif /* CONFIG_PMAC_PBOOK */ 679#endif /* CONFIG_PM */
680 680
681#ifdef PMAC_SUPPORT_AUTOMUTE 681#ifdef PMAC_SUPPORT_AUTOMUTE
682/* 682/*
@@ -883,7 +883,7 @@ snd_pmac_awacs_init(pmac_t *chip)
883 * set lowlevel callbacks 883 * set lowlevel callbacks
884 */ 884 */
885 chip->set_format = snd_pmac_awacs_set_format; 885 chip->set_format = snd_pmac_awacs_set_format;
886#ifdef CONFIG_PMAC_PBOOK 886#ifdef CONFIG_PM
887 chip->suspend = snd_pmac_awacs_suspend; 887 chip->suspend = snd_pmac_awacs_suspend;
888 chip->resume = snd_pmac_awacs_resume; 888 chip->resume = snd_pmac_awacs_resume;
889#endif 889#endif
diff --git a/sound/ppc/daca.c b/sound/ppc/daca.c
index f24a91693616..a737f298e77d 100644
--- a/sound/ppc/daca.c
+++ b/sound/ppc/daca.c
@@ -218,7 +218,7 @@ static snd_kcontrol_new_t daca_mixers[] = {
218}; 218};
219 219
220 220
221#ifdef CONFIG_PMAC_PBOOK 221#ifdef CONFIG_PM
222static void daca_resume(pmac_t *chip) 222static void daca_resume(pmac_t *chip)
223{ 223{
224 pmac_daca_t *mix = chip->mixer_data; 224 pmac_daca_t *mix = chip->mixer_data;
@@ -227,7 +227,7 @@ static void daca_resume(pmac_t *chip)
227 mix->amp_on ? 0x05 : 0x04); 227 mix->amp_on ? 0x05 : 0x04);
228 daca_set_volume(mix); 228 daca_set_volume(mix);
229} 229}
230#endif /* CONFIG_PMAC_PBOOK */ 230#endif /* CONFIG_PM */
231 231
232 232
233static void daca_cleanup(pmac_t *chip) 233static void daca_cleanup(pmac_t *chip)
@@ -275,7 +275,7 @@ int __init snd_pmac_daca_init(pmac_t *chip)
275 return err; 275 return err;
276 } 276 }
277 277
278#ifdef CONFIG_PMAC_PBOOK 278#ifdef CONFIG_PM
279 chip->resume = daca_resume; 279 chip->resume = daca_resume;
280#endif 280#endif
281 281
diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index 080ef3928465..75b8b7423036 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -36,7 +36,7 @@
36#include <asm/pci-bridge.h> 36#include <asm/pci-bridge.h>
37 37
38 38
39#if defined(CONFIG_PM) && defined(CONFIG_PMAC_PBOOK) 39#ifdef CONFIG_PM
40static int snd_pmac_register_sleep_notifier(pmac_t *chip); 40static int snd_pmac_register_sleep_notifier(pmac_t *chip);
41static int snd_pmac_unregister_sleep_notifier(pmac_t *chip); 41static int snd_pmac_unregister_sleep_notifier(pmac_t *chip);
42static int snd_pmac_suspend(snd_card_t *card, pm_message_t state); 42static int snd_pmac_suspend(snd_card_t *card, pm_message_t state);
@@ -782,7 +782,7 @@ static int snd_pmac_free(pmac_t *chip)
782 } 782 }
783 783
784 snd_pmac_sound_feature(chip, 0); 784 snd_pmac_sound_feature(chip, 0);
785#if defined(CONFIG_PM) && defined(CONFIG_PMAC_PBOOK) 785#ifdef CONFIG_PM
786 snd_pmac_unregister_sleep_notifier(chip); 786 snd_pmac_unregister_sleep_notifier(chip);
787#endif 787#endif
788 788
@@ -1292,7 +1292,7 @@ int __init snd_pmac_new(snd_card_t *card, pmac_t **chip_return)
1292 /* Reset dbdma channels */ 1292 /* Reset dbdma channels */
1293 snd_pmac_dbdma_reset(chip); 1293 snd_pmac_dbdma_reset(chip);
1294 1294
1295#if defined(CONFIG_PM) && defined(CONFIG_PMAC_PBOOK) 1295#ifdef CONFIG_PM
1296 /* add sleep notifier */ 1296 /* add sleep notifier */
1297 if (! snd_pmac_register_sleep_notifier(chip)) 1297 if (! snd_pmac_register_sleep_notifier(chip))
1298 snd_card_set_pm_callback(chip->card, snd_pmac_suspend, snd_pmac_resume, chip); 1298 snd_card_set_pm_callback(chip->card, snd_pmac_suspend, snd_pmac_resume, chip);
@@ -1316,7 +1316,7 @@ int __init snd_pmac_new(snd_card_t *card, pmac_t **chip_return)
1316 * sleep notify for powerbook 1316 * sleep notify for powerbook
1317 */ 1317 */
1318 1318
1319#if defined(CONFIG_PM) && defined(CONFIG_PMAC_PBOOK) 1319#ifdef CONFIG_PM
1320 1320
1321/* 1321/*
1322 * Save state when going to sleep, restore it afterwards. 1322 * Save state when going to sleep, restore it afterwards.
@@ -1414,4 +1414,5 @@ static int snd_pmac_unregister_sleep_notifier(pmac_t *chip)
1414 return 0; 1414 return 0;
1415} 1415}
1416 1416
1417#endif /* CONFIG_PM && CONFIG_PMAC_PBOOK */ 1417#endif /* CONFIG_PM */
1418
diff --git a/sound/ppc/pmac.h b/sound/ppc/pmac.h
index 0a84c05f714b..582db5220119 100644
--- a/sound/ppc/pmac.h
+++ b/sound/ppc/pmac.h
@@ -167,7 +167,7 @@ struct snd_pmac {
167 void (*set_format)(pmac_t *chip); 167 void (*set_format)(pmac_t *chip);
168 void (*update_automute)(pmac_t *chip, int do_notify); 168 void (*update_automute)(pmac_t *chip, int do_notify);
169 int (*detect_headphone)(pmac_t *chip); 169 int (*detect_headphone)(pmac_t *chip);
170#ifdef CONFIG_PMAC_PBOOK 170#ifdef CONFIG_PM
171 void (*suspend)(pmac_t *chip); 171 void (*suspend)(pmac_t *chip);
172 void (*resume)(pmac_t *chip); 172 void (*resume)(pmac_t *chip);
173#endif 173#endif
diff --git a/sound/ppc/tumbler.c b/sound/ppc/tumbler.c
index 9332237cb6a4..36c5d5d45bb1 100644
--- a/sound/ppc/tumbler.c
+++ b/sound/ppc/tumbler.c
@@ -1128,7 +1128,7 @@ static void tumbler_reset_audio(pmac_t *chip)
1128 } 1128 }
1129} 1129}
1130 1130
1131#ifdef CONFIG_PMAC_PBOOK 1131#ifdef CONFIG_PM
1132/* suspend mixer */ 1132/* suspend mixer */
1133static void tumbler_suspend(pmac_t *chip) 1133static void tumbler_suspend(pmac_t *chip)
1134{ 1134{
@@ -1370,7 +1370,7 @@ int __init snd_pmac_tumbler_init(pmac_t *chip)
1370 if ((err = snd_ctl_add(chip->card, chip->drc_sw_ctl)) < 0) 1370 if ((err = snd_ctl_add(chip->card, chip->drc_sw_ctl)) < 0)
1371 return err; 1371 return err;
1372 1372
1373#ifdef CONFIG_PMAC_PBOOK 1373#ifdef CONFIG_PM
1374 chip->suspend = tumbler_suspend; 1374 chip->suspend = tumbler_suspend;
1375 chip->resume = tumbler_resume; 1375 chip->resume = tumbler_resume;
1376#endif 1376#endif